<ResourceDictionary
    x:ClassModifier="internal"
    xmlns="https://github.com/avaloniaui"
    xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ControlTheme TargetType="ComboBox" x:Key="{x:Type ComboBox}">
        <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="4" />
        <Setter Property="MinHeight" Value="20" />
        <Setter Property="PlaceholderForeground" Value="{StaticResource MainTextColorFaded}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue" />
        <Setter Property="Template">
            <ControlTemplate>
                <DockPanel LastChildFill="true" Name="Container">
                    <Border
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="1,0,0,0"
                        DockPanel.Dock="Left"
                        Name="LeftBorder" />
                    <Border
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0,1,0,0"
                        DockPanel.Dock="Top"
                        Name="TopBorder" />
                    <Border
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0,0,1,0"
                        DockPanel.Dock="Right"
                        Name="RightBorder" />
                    <Border
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="0,0,0,1"
                        DockPanel.Dock="Bottom"
                        Name="BottomBorder" />
                    <Panel Background="{TemplateBinding Background}">
                        <TextBlock
                            Foreground="{TemplateBinding PlaceholderForeground}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            IsVisible="{TemplateBinding SelectionBoxItem,
                                                        Converter={x:Static ObjectConverters.IsNull}}"
                            Margin="{TemplateBinding Padding}"
                            Name="PlaceholderTextBlock"
                            Text="{TemplateBinding PlaceholderText}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        <RadioButton
                            Background="Transparent"
                            BorderThickness="0"
                            ClickMode="Press"
                            Focusable="False"
                            IsChecked="{TemplateBinding IsDropDownOpen,
                                                        Mode=TwoWay}"
                            Name="toggle"
                            Theme="{StaticResource NoneTemplate}">
                            <Panel>
                                <ContentControl
                                    Content="{TemplateBinding SelectionBoxItem}"
                                    ContentTemplate="{TemplateBinding ItemTemplate}"
                                    HorizontalAlignment="Left"
                                    Margin="{TemplateBinding Padding}"
                                    Width="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}" />
                                <Path
                                    Data="{StaticResource FilledArrowDownGeometry}"
                                    Fill="{TemplateBinding Foreground}"
                                    Height="17"
                                    HorizontalAlignment="Right"
                                    Margin="0,0,5,0"
                                    Stretch="Fill"
                                    VerticalAlignment="Center"
                                    Width="17" />
                            </Panel>
                        </RadioButton>

                        <Popup
                            IsLightDismissEnabled="True"
                            IsOpen="{TemplateBinding IsDropDownOpen,
                                                     Mode=TwoWay}"
                            MaxHeight="{TemplateBinding MaxDropDownHeight}"
                            MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
                            Name="PART_Popup"
                            PlacementTarget="{TemplateBinding}">
                            <Border
                                Background="{DynamicResource DropDownBgColor}"
                                BorderBrush="{DynamicResource SecondaryBorderColor}"
                                BorderThickness="1,0,1,1">
                                <customControls:AutoScrollViewer
                                    HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                    IsDeferredScrollingEnabled="{TemplateBinding (ScrollViewer.IsDeferredScrollingEnabled)}"
                                    Theme="{StaticResource Main}"
                                    VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                                    <ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" Name="PART_ItemsPresenter" />
                                </customControls:AutoScrollViewer>
                            </Border>
                        </Popup>
                    </Panel>
                </DockPanel>
            </ControlTemplate>
        </Setter>

        <Style Selector="^:pointerover /template/ Border#LeftBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^:pointerover /template/ Border#TopBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^:pointerover /template/ Border#RightBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^:pointerover /template/ Border#BottomBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>

        <Style Selector="^:focus /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>
        <Style Selector="^:focus:not(:selected) /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>
        <Style Selector="^:selected:focus /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource AccentColor}" />
        </Style>

        <Style Selector="^:dropdownopen /template/ Border#LeftBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^:dropdownopen /template/ Border#TopBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^:dropdownopen /template/ Border#RightBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^:dropdownopen /template/ Border#BottomBorder">
            <Setter Property="BorderBrush" Value="{DynamicResource TertiaryBorderColor}" />
            <Setter Property="Opacity" Value=".4" />
        </Style>

        <Style Selector="^:disabled /template/ DockPanel#Container">
            <Setter Property="Opacity" Value="{StaticResource ThemeDisabledOpacity}" />
        </Style>
    </ControlTheme>
</ResourceDictionary>