<UserControl x:Class="PixiEditor.Views.UserControls.Palettes.PaletteColorControl"
             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:converters="clr-namespace:PixiEditor.Helpers.Converters"
             xmlns:palettes="clr-namespace:PixiEditor.Views.UserControls.Palettes"
             mc:Ignorable="d" 
             d:DesignHeight="45" d:DesignWidth="45" 
             x:Name="uc" 
             MouseDown="PaletteColor_OnMouseDown"
             MouseMove="PaletteColor_OnMouseMove"
             MouseUp="PaletteColor_OnMouseUp">
    <UserControl.Resources>
        <converters:GenericColorToMediaColorConverter x:Key="GenericColorToMediaColorConverter" />
        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    </UserControl.Resources>
    <UserControl.Style>
        <Style TargetType="{x:Type palettes:PaletteColorControl}">
            <Setter Property="Width" Value="36"/>
            <Setter Property="Height" Value="36"/>
        </Style>
    </UserControl.Style>
    <Grid Width="{Binding ElementName=uc, Path=Width}" Height="{Binding ElementName=uc, Path=Height}">
        <Border CornerRadius="{Binding ElementName=uc, Path=CornerRadius}" Width="{Binding ElementName=uc, Path=Width}" Height="{Binding ElementName=uc, Path=Height}" RenderOptions.BitmapScalingMode="NearestNeighbor">
            <Border.Background>
                <VisualBrush>
                    <VisualBrush.Visual>
                        <Image Source="/Images/CheckerTile.png" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
                    </VisualBrush.Visual>
                </VisualBrush>
            </Border.Background>
        </Border>
        <Border CornerRadius="{Binding ElementName=uc, Path=CornerRadius}" BorderThickness="0 0 0 0.1" BorderBrush="White">
            <Border.Background>
                <SolidColorBrush Color="{Binding Color, Converter={StaticResource GenericColorToMediaColorConverter}, ElementName=uc}" />
            </Border.Background>
        </Border>
        <Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="15" Margin="0 0 0 -1"
                Visibility="{Binding ElementName=uc, Path=AssociatedKey, Converter={converters:NotNullToVisibilityConverter}}"
                Background="{StaticResource AccentColor}" CornerRadius="3.5 0 3.5 0">
            <TextBlock Foreground="White" FontSize="16" HorizontalAlignment="Center" Margin="1 0 0 0"
                                        Text="{Binding AssociatedKey, ElementName=uc}"/>
        </Border>
    </Grid>
</UserControl>
