<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:CompileBindings="True">
    <Design.PreviewWith>
        <StackPanel Margin="20" Spacing="20">
            <ButtonSpinner Content="Hello World" />
        </StackPanel>
    </Design.PreviewWith>
    <ControlTheme x:Key="ButtonSpinnerRepeatButton" TargetType="RepeatButton">
        <Setter Property="RepeatButton.Background" Value="{DynamicResource ButtonSpinnerRepeatButtonBackground}" />
        <Setter Property="RepeatButton.Cursor" Value="Hand" />
        <Setter Property="RepeatButton.Template">
            <ControlTemplate>
                <ContentPresenter
                    x:Name="PART_ContentPresenter"
                    Padding="{TemplateBinding Padding}"
                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}" />
            </ControlTemplate>
        </Setter>
        <Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource ButtonSpinnerRepeatButtonPointeroverBackground}" />
        </Style>

        <Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource ButtonSpinnerRepeatButtonPressedBackground}" />
        </Style>

        <Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource ButtonSpinnerRepeatButtonDisabledBackground}" />
            <Setter Property="Foreground" Value="{DynamicResource ButtonSpinnerRepeatButtonDisabledForeground}" />
        </Style>
    </ControlTheme>

    <ControlTheme x:Key="{x:Type ButtonSpinner}" TargetType="ButtonSpinner">
        <Setter Property="ButtonSpinner.BorderBrush" Value="{DynamicResource ButtonSpinnerRepeatButtonBorderBrush}" />
        <Setter Property="ButtonSpinner.BorderThickness" Value="0" />
        <Setter Property="ButtonSpinner.MinWidth" Value="300" />
        <!--  Add Resource  -->
        <Setter Property="ButtonSpinner.Template">
            <ControlTemplate TargetType="ButtonSpinner">
                <Grid ColumnDefinitions="Auto, *, Auto">
                    <Border
                        Grid.Column="1"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="{TemplateBinding CornerRadius}"
                        UseLayoutRounding="False">
                        <ContentPresenter
                            Name="PART_ContentPresenter"
                            Padding="{TemplateBinding Padding}"
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}" />
                    </Border>
                    <Border
                        Name="ButtonGroup"
                        Grid.Column="2"
                        MinWidth="16"
                        Margin="4,0,0,0"
                        BorderBrush="{DynamicResource ButtonSpinnerRepeatButtonBorderBrush}"
                        BorderThickness="{DynamicResource ButtonSpinnerButtonGroupBorderThickness}"
                        CornerRadius="{DynamicResource ButtonSpinnerButtonGroupCornerRadius}"
                        IsVisible="{TemplateBinding ShowButtonSpinner}"
                        UseLayoutRounding="False">
                        <Grid RowDefinitions="*, *">
                            <RepeatButton
                                Name="PART_IncreaseButton"
                                Grid.Row="0"
                                Theme="{StaticResource ButtonSpinnerRepeatButton}">
                                <PathIcon
                                    Width="8"
                                    Height="8"
                                    Data="{DynamicResource ButtonSpinnerIncreaseButtonGlyph}"
                                    Foreground="{DynamicResource ButtonSpinnerRepeatButtonForeground}" />
                            </RepeatButton>
                            <RepeatButton
                                Name="PART_DecreaseButton"
                                Grid.Row="1"
                                Theme="{StaticResource ButtonSpinnerRepeatButton}">
                                <PathIcon
                                    Width="8"
                                    Height="8"
                                    Data="{DynamicResource ButtonSpinnerDecreaseButtonGlyph}"
                                    Foreground="{DynamicResource ButtonSpinnerRepeatButtonForeground}" />
                            </RepeatButton>
                        </Grid>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter>
        <Style Selector="^[ButtonSpinnerLocation=Left] /template/ Border#ButtonGroup">
            <Setter Property="Grid.Column" Value="0" />
            <Setter Property="Border.Margin" Value="0 0 4 0" />
        </Style>
    </ControlTheme>
</ResourceDictionary>
