<ResourceDictionary
    x:ClassModifier="internal"
    xmlns="https://github.com/avaloniaui"
    xmlns:converters="using:Avalonia.Controls.Converters"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <x:Double x:Key="SplitButtonPrimaryButtonSize">24</x:Double>
    <x:Double x:Key="SplitButtonSecondaryButtonSize">24</x:Double>
    <x:Double x:Key="SplitButtonSeparatorWidth">1</x:Double>
    <x:Double x:Key="SplitButtonMinHeight">24</x:Double>
    <Thickness x:Key="SplitButtonBorderThemeThickness">1</Thickness>

    <converters:MarginMultiplierConverter
        Bottom="True"
        Indent="1"
        Left="True"
        Top="True"
        x:Key="PrimaryButtonBorderMultiplier" />
    <converters:MarginMultiplierConverter
        Bottom="True"
        Indent="1"
        Right="True"
        Top="True"
        x:Key="SecondaryButtonBorderMultiplier" />
    <converters:MarginMultiplierConverter
        Bottom="True"
        Indent="1"
        Top="True"
        x:Key="SeparatorBorderMultiplier" />
    <converters:CornerRadiusFilterConverter Filter="TopLeft, TopRight" x:Key="TopCornerRadiusFilterConverter" />
    <converters:CornerRadiusFilterConverter Filter="TopRight, BottomRight" x:Key="RightCornerRadiusFilterConverter" />
    <converters:CornerRadiusFilterConverter Filter="BottomLeft, BottomRight" x:Key="BottomCornerRadiusFilterConverter" />
    <converters:CornerRadiusFilterConverter Filter="TopLeft, BottomLeft" x:Key="LeftCornerRadiusFilterConverter" />

    <ControlTheme TargetType="Button" x:Key="SimpleSplitButtonComponent">
        <Setter Property="Template">
            <ControlTemplate>
                <ContentPresenter
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    CornerRadius="{TemplateBinding CornerRadius}"
                    Foreground="{TemplateBinding Foreground}"
                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                    Padding="{TemplateBinding Padding}"
                    RecognizesAccessKey="True"
                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                    x:Name="PART_ContentPresenter" />
            </ControlTemplate>
        </Setter>

    </ControlTheme>

    <ControlTheme TargetType="SplitButton" x:Key="{x:Type SplitButton}">
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
        <Setter Property="Focusable" Value="True" />
        <Setter Property="Padding" Value="4" />
        <Setter Property="Template">
            <ControlTemplate>
                <Grid ColumnDefinitions="*,Auto,Auto">

                    <Button
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness,
                                                          Converter={StaticResource PrimaryButtonBorderMultiplier}}"
                        Command="{TemplateBinding Command}"
                        CommandParameter="{TemplateBinding CommandParameter}"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}"
                        CornerRadius="{TemplateBinding CornerRadius,
                                                       Converter={StaticResource LeftCornerRadiusFilterConverter}}"
                        Focusable="False"
                        FontFamily="{TemplateBinding FontFamily}"
                        FontSize="{TemplateBinding FontSize}"
                        FontWeight="{TemplateBinding FontWeight}"
                        Foreground="{TemplateBinding Foreground}"
                        Grid.Column="0"
                        HorizontalAlignment="Stretch"
                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                        KeyboardNavigation.IsTabStop="False"
                        MinWidth="{DynamicResource SplitButtonPrimaryButtonSize}"
                        Padding="{TemplateBinding Padding}"
                        Theme="{StaticResource SimpleSplitButtonComponent}"
                        VerticalAlignment="Stretch"
                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                        x:Name="PART_PrimaryButton" />

                    <Border
                        Background="Transparent"
                        BorderBrush="{DynamicResource MainBorderColor}"
                        BorderThickness="1,0,0,0"
                        Grid.Column="1"
                        x:Name="SeparatorBorder" />

                    <Button
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness,
                                                          Converter={StaticResource SecondaryButtonBorderMultiplier}}"
                        CornerRadius="{TemplateBinding CornerRadius,
                                                       Converter={StaticResource RightCornerRadiusFilterConverter}}"
                        Focusable="False"
                        Foreground="{TemplateBinding Foreground}"
                        Grid.Column="2"
                        HorizontalAlignment="Stretch"
                        HorizontalContentAlignment="Center"
                        KeyboardNavigation.IsTabStop="False"
                        MinWidth="{DynamicResource SplitButtonSecondaryButtonSize}"
                        Padding="0"
                        Theme="{StaticResource SimpleSplitButtonComponent}"
                        VerticalAlignment="Stretch"
                        VerticalContentAlignment="Center"
                        x:Name="PART_SecondaryButton">
                        <PathIcon
                            Data="{StaticResource ChevronDownGeometry}"
                            Foreground="{TemplateBinding Foreground}"
                            Height="12"
                            Width="12"
                            x:Name="PART_ChevronIcon" />
                    </Button>
                </Grid>
            </ControlTemplate>
        </Setter>

        <Style Selector="^.hover:pointerover /template/ Button#PART_PrimaryButton">
            <Style.Animations>
                <Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
                    <KeyFrame>
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="{DynamicResource MainTextColor}" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryBackgroundColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource MainBorderColor}" />
                        </Setter>
                    </KeyFrame>
                    <KeyFrame Cue="1">
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="{StaticResource SecondaryTextColor}" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource AccentColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource AccentColor}" />
                        </Setter>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
            <Setter Property="Background" Value="{DynamicResource AccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
        </Style>
        <Style Selector="^.hover:pointerover /template/ Button#PART_SecondaryButton">
            <Style.Animations>
                <Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
                    <KeyFrame>
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="{DynamicResource MainTextColor}" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryBackgroundColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource MainBorderColor}" />
                        </Setter>
                    </KeyFrame>
                    <KeyFrame Cue="1">
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="{StaticResource SecondaryTextColor}" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
                        </Setter>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>

        <Style Selector="^.altHover:pointerover /template/ Button#PART_PrimaryButton">
            <Style.Animations>
                <Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
                    <KeyFrame>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryBackgroundColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource MainBorderColor}" />
                        </Setter>
                    </KeyFrame>
                    <KeyFrame Cue="1">
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource AltBackgroundHoverColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource SecondaryBorderColor}" />
                        </Setter>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Background" Value="{DynamicResource AltBackgroundHoverColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>
        <Style Selector="^.altHover:pointerover /template/ Button#PART_SecondaryButton">
            <Style.Animations>
                <Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
                    <KeyFrame>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryBackgroundColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource MainBorderColor}" />
                        </Setter>
                    </KeyFrame>
                    <KeyFrame Cue="1">
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource AltBackgroundHoverColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource SecondaryBorderColor}" />
                        </Setter>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Background" Value="{DynamicResource AltBackgroundHoverColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
        </Style>


        <Style Selector="^.accentHover:pointerover /template/ Button#PART_PrimaryButton">
            <Style.Animations>
                <Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
                    <KeyFrame>
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="{StaticResource SecondaryTextColor}" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource AccentColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource MainBorderColor}" />
                        </Setter>
                    </KeyFrame>
                    <KeyFrame Cue="1">
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="#fff" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
                        </Setter>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Foreground" Value="#fff" />
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>
        <Style Selector="^.accentHover:pointerover /template/ Button#PART_SecondaryButton">
            <Style.Animations>
                <Animation Duration="{StaticResource ButtonHoverAnimationDuration}" IterationCount="1">
                    <KeyFrame>
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="{StaticResource SecondaryTextColor}" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource AccentColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource MainBorderColor}" />
                        </Setter>
                    </KeyFrame>
                    <KeyFrame Cue="1">
                        <Setter Property="Foreground">
                            <SolidColorBrush Color="#fff" />
                        </Setter>
                        <Setter Property="Background">
                            <SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
                        </Setter>
                        <Setter Property="BorderBrush">
                            <SolidColorBrush Color="{DynamicResource SecondaryAccentColor}" />
                        </Setter>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
            <Setter Property="Foreground" Value="#fff" />
            <Setter Property="Background" Value="{DynamicResource SecondaryAccentColor}" />
            <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentColor}" />
        </Style>

        <Style Selector="^:flyout-open /template/ Button">
            <Setter Property="Tag" Value="flyout-open" />
        </Style>

        <Style Selector="^:checked /template/ Button">
            <Setter Property="Tag" Value="checked" />
        </Style>

        <Style Selector="^:checked:flyout-open /template/ Button">
            <Setter Property="Tag" Value="checked-flyout-open" />
        </Style>

        <Style Selector="^:disabled">
            <Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}" />
        </Style>

        <Style Selector="^.up /template/ PathIcon#PART_ChevronIcon">
            <Setter Property="Data" Value="{StaticResource ChevronUpGeometry}" />
        </Style>
        <Style Selector="^.up:pointerover /template/ PathIcon#PART_ChevronIcon">
            <Setter Property="Foreground" Value="{StaticResource SecondaryTextColor}" />
        </Style>
    </ControlTheme>
</ResourceDictionary>