<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"
                    xmlns:controls="clr-namespace:PixiEditor.Views.UserControls"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:views="clr-namespace:PixiEditor.Views"
                    xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions">

    <SolidColorBrush x:Key="ComboBox.Static.Background" Color="#252525" />
    <SolidColorBrush x:Key="ComboBox.Static.Border" Color="#2F2F37" />
    <SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#FF606060" />
    <SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="#333333" />
    <SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#2F2F37" />
    <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent" />
    <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Background" Color="White" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF0000" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#007ACC" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#333333" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#007ACC" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" Color="#333333" />
    <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Background" Color="#333333" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#007ACC" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#007ACC" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="#202020" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#007ACC" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Background" Color="#007ACC" />
    <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#FF569DE5" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#FFF0F0F0" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent" />
    <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent" />
    <Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="Focusable" Value="false" />
        <Setter Property="ClickMode" Value="Press" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border x:Name="templateRoot" Background="{StaticResource AccentColor}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{StaticResource ComboBox.Static.Border}" SnapsToDevicePixels="true">
                        <Path x:Name="arrow"
                            Data="M 0 3 L 3 6 L 6 3 L 6 0 L 3 3 L 0 0 L 0 3 Z"
                            Fill="{StaticResource BrighterAccentColor}" HorizontalAlignment="Right" Margin="5"
                            VerticalAlignment="Center" />
                        <Border.Style>
                            <Style TargetType="Border">
                                <Setter Property="CornerRadius" Value="5"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}}" Value="true">
                                        <Setter Property="CornerRadius" Value="5,5,0,0"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Border.Style>
                    </Border>
                    <ControlTemplate.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
                                           Value="false" />
                                <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}"
                                           Value="false" />
                                <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}"
                                           Value="true" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" TargetName="templateRoot"
                                    Value="{StaticResource AccentColor}" />
                            <Setter Property="BorderBrush" TargetName="templateRoot"
                                    Value="{StaticResource BrighterAccentColor}" />
                            <Setter Property="Fill" TargetName="arrow" 
                                    Value="{StaticResource BrighterAccentColor}" />
                        </MultiDataTrigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Fill" TargetName="arrow" Value="{StaticResource AccentColor}" />
                            <Setter Property="Background" TargetName="templateRoot"
                                    Value="{StaticResource DarkerAccentColor}" />
                            <Setter Property="BorderBrush" TargetName="templateRoot"
                                    Value="{StaticResource AccentColor}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Fill" TargetName="arrow"
                                    Value="{StaticResource AlmostLightModeAccentColor}" />
                            <Setter Property="Background" TargetName="templateRoot"
                                    Value="{StaticResource DarkerAccentColor}" />
                            <Setter Property="BorderBrush" TargetName="templateRoot"
                                    Value="{StaticResource AlmostLightModeAccentColor}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Fill" TargetName="arrow" Value="{StaticResource AlmostLightModeAccentColor}" />
                            <Setter Property="Background" TargetName="templateRoot"
                                    Value="{StaticResource DarkerAccentColor}" />
                            <Setter Property="BorderBrush" TargetName="templateRoot"
                                    Value="{StaticResource AlmostLightModeAccentColor}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <ControlTemplate x:Key="DarkComboBox" TargetType="{x:Type ComboBox}">
        <Grid x:Name="templateRoot" SnapsToDevicePixels="true">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition MinWidth="13"
                                  Width="0" />
            </Grid.ColumnDefinitions>
            <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2"
                   IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                   Margin="1" Placement="Bottom">
                <theme:SystemDropShadowChrome x:Name="shadow" Color="Transparent" CornerRadius="0,0,5,5"
                                              MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
                                              MaxHeight="{TemplateBinding MaxDropDownHeight}">
                    <Border x:Name="dropDownBorder" CornerRadius="0,0,5,5"
                            Background="{StaticResource DarkerAccentColor}" BorderThickness="1"
                            BorderBrush="{StaticResource BrighterAccentColor}">
                        <ScrollViewer x:Name="DropDownScrollViewer" Margin="1">
                            <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
                                <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top"
                                        Width="0">
                                    <Rectangle x:Name="opaqueRect"
                                               Fill="{Binding Background, ElementName=dropDownBorder}"
                                               Height="{Binding ActualHeight, ElementName=dropDownBorder}"
                                               Width="{Binding ActualWidth, ElementName=dropDownBorder}" />
                                </Canvas>
                                <ItemsPresenter x:Name="ItemsPresenter"
                                                KeyboardNavigation.DirectionalNavigation="Contained"
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Grid>
                        </ScrollViewer>
                    </Border>
                </theme:SystemDropShadowChrome>
            </Popup>
            <ToggleButton x:Name="toggleButton" Background="{TemplateBinding Background}"
                          BorderThickness="{TemplateBinding BorderThickness}"
                          BorderBrush="{TemplateBinding BorderBrush}" Grid.ColumnSpan="2"
                          IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                          Style="{StaticResource ComboBoxToggleButton}" />
            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                              Content="{TemplateBinding SelectionBoxItem}"
                              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                              ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              IsHitTestVisible="false" Margin="{TemplateBinding Padding}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                <Setter Property="Margin" TargetName="shadow" Value="0,0,5,5" />
                <Setter Property="Color" TargetName="shadow" Value="#71000000" />
            </Trigger>
            <Trigger Property="HasItems" Value="false">
                <Setter Property="Height" TargetName="dropDownBorder" Value="95" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsGrouping" Value="true" />
                    <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" />
                </MultiTrigger.Conditions>
                <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
            </MultiTrigger>
            <Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
                <Setter Property="Canvas.Top" TargetName="opaqueRect"
                        Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
                <Setter Property="Canvas.Left" TargetName="opaqueRect"
                        Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="ComboBox">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template" Value="{DynamicResource DarkComboBox}" />
    </Style>

    <Style TargetType="controls:BlendModeComboBox">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template" Value="{DynamicResource DarkComboBox}" />
    </Style>

    <Style TargetType="ComboBoxItem">
        <Setter Property="Background" Value="{StaticResource DarkerAccentColor}" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBoxItem">
                    <Border Name="Bd" Background="{TemplateBinding Background}" BorderThickness="0,1">
                        <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Stretch"
                                          VerticalAlignment="Center" Margin="4,2"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="BorderBrush" TargetName="Bd" Value="Transparent" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource MainColor}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource MainColor}" />
                            <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource AlmostLightModeAccentColor}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{StaticResource MainColor}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Separator">
        <Setter Property="Height"
                Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Separator">
                    <Border BorderThickness="1">
                        <Border.BorderBrush>
                            <SolidColorBrush Color="#FF4D4D4D" />
                        </Border.BorderBrush>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="ComboBox" x:Key="TranslatedEnum">
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock ui:Translator.Enum="{Binding}"/>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ComboBoxItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                                <Border x:Name="Bd" Background="{TemplateBinding Background}" BorderThickness="0,1">
                                    <TextBlock ui:Translator.Enum="{Binding}" />
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="False">
                                        <Setter Property="BorderBrush" TargetName="Bd" Value="Transparent" />
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="Background" TargetName="Bd" Value="{StaticResource MainColor}" />
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" TargetName="Bd" Value="{StaticResource MainColor}" />
                                        <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource AlmostLightModeAccentColor}" />
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="False">
                                        <Setter Property="Foreground" Value="{StaticResource MainColor}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template" Value="{DynamicResource DarkComboBox}" />
    </Style>
</ResourceDictionary>