<UserControl x:Class="PixiEditor.Views.UserControls.SwatchesView"
             x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:PixiEditor.Views.UserControls" 
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:conv="clr-namespace:PixiEditor.Helpers.Converters" 
             xmlns:palettes="clr-namespace:PixiEditor.Views.UserControls.Palettes"
             xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML"
             mc:Ignorable="d" Name="swatchesView"
             d:DesignHeight="450" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <conv:GenericColorToMediaColorConverter x:Key="BackendColorToMediaColorConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
        <ItemsControl ItemsSource="{Binding Swatches, ElementName=swatchesView}">
            <d:ItemsControl.ItemsSource>
                <x:Array Type="{x:Type Color}">
                    <Color R="0" G="0" B="0" A="255"/>
                    <Color R="255" G="255" B="255" A="255"/>
                    <Color R="255" G="255" B="255" A="150"/>
                    <Color R="255" G="255" B="255" A="0"/>
                    <Color R="255" G="0" B="0" A="255"/>
                    <Color R="0" G="255" B="0" A="255"/>
                    <Color R="0" G="0" B="255" A="255"/>
                </x:Array>
            </d:ItemsControl.ItemsSource>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Margin="10,10,0,10" Orientation="Horizontal"
                               HorizontalAlignment="Left" VerticalAlignment="Top"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <palettes:PaletteColorControl Cursor="Hand" Color="{Binding}" Margin="0 5 5 5">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseLeftButtonUp">
                                <i:InvokeCommandAction
                                    Command="{Binding SelectSwatchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SwatchesView}}}"
                                    CommandParameter="{Binding}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                        <palettes:PaletteColorControl.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Remove" Foreground="White"
                                          Command="{cmds:Command PixiEditor.Colors.RemoveSwatch, UseProvided=True}"
                                          CommandParameter="{Binding}" />
                            </ContextMenu>
                        </palettes:PaletteColorControl.ContextMenu>
                    </palettes:PaletteColorControl>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>
</UserControl>
