<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:Ursa.Themes.Semi.Converters"
    xmlns:u="https://irihi.tech/ursa">
    <!--  Add Resources Here  -->
    <converters:BooleansToOpacityConverter x:Key="OpacityConverter" />
    <ControlTheme x:Key="{x:Type u:IconButton}" TargetType="u:IconButton">
        <Setter Property="Background" Value="{DynamicResource ButtonDefaultBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultPrimaryForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ButtonDefaultBorderBrush}" />
        <Setter Property="CornerRadius" Value="{DynamicResource ButtonCornerRadius}" />
        <Setter Property="BorderThickness" Value="{DynamicResource ButtonBorderThickness}" />
        <Setter Property="Padding" Value="{DynamicResource ButtonDefaultPadding}" />
        <Setter Property="RenderTransform" Value="none" />
        <Setter Property="FontSize" Value="{DynamicResource ButtonDefaultFontSize}" />
        <Setter Property="FontWeight" Value="{DynamicResource ButtonDefaultFontWeight}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="MinHeight" Value="12" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Template">
            <ControlTemplate TargetType="u:IconButton">
                <Border
                    Padding="{TemplateBinding Padding}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding CornerRadius}"
                    TextElement.FontSize="{TemplateBinding FontSize}"
                    TextElement.FontWeight="{TemplateBinding FontWeight}"
                    UseLayoutRounding="False">
                    <Grid
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        ColumnDefinitions="Auto, Auto"
                        RowDefinitions="Auto, Auto">
                        <Panel
                            Name="PART_IconRoot"
                            Grid.Column="0">
                            <Panel.IsVisible>
                                <MultiBinding Converter="{x:Static BoolConverters.Or}">
                                    <Binding Path="IsLoading" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding
                                        Converter="{x:Static ObjectConverters.IsNotNull}"
                                        Path="Icon"
                                        RelativeSource="{RelativeSource TemplatedParent}" />
                                </MultiBinding>
                            </Panel.IsVisible>
                            <ContentPresenter
                                Content="{TemplateBinding Icon}"
                                ContentTemplate="{TemplateBinding IconTemplate}"
                                Opacity="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=!IsLoading, Converter={StaticResource OpacityConverter}}" />
                            <u:LoadingIcon
                                Classes="Small"
                                Foreground="{TemplateBinding Foreground}"
                                IsVisible="{TemplateBinding IsLoading}" />
                        </Panel>
                        <ContentPresenter
                            Name="PART_ContentPresenter"
                            Grid.Column="1"
                            Margin="8 0 0 0"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Content="{TemplateBinding Content}" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter>

        <Style Selector="^:pressed">
            <Setter Property="RenderTransform" Value="scale(0.98)" />
        </Style>

        <Style Selector="^.Primary">
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultPrimaryForeground}" />
        </Style>
        <Style Selector="^.Secondary">
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultSecondaryForeground}" />
        </Style>
        <Style Selector="^.Tertiary">
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultTertiaryForeground}" />
        </Style>
        <Style Selector="^.Success">
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultSuccessForeground}" />
        </Style>
        <Style Selector="^.Warning">
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultWarningForeground}" />
        </Style>
        <Style Selector="^.Danger">
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultDangerForeground}" />
        </Style>

        <Style Selector="^:pointerover">
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonDefaultPointeroverBorderBrush}" />
            <Setter Property="Background" Value="{DynamicResource ButtonDefaultPointeroverBackground}" />
        </Style>

        <Style Selector="^:pressed">
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonDefaultPressedBorderBrush}" />
            <Setter Property="Background" Value="{DynamicResource ButtonDefaultPressedBackground}" />
        </Style>

        <Style Selector="^:disabled">
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonDefaultDisabledBorderBrush}" />
            <Setter Property="Background" Value="{DynamicResource ButtonDefaultDisabledBackground}" />
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultDisabledForeground}" />
        </Style>
        
        <Style Selector="^:empty[IsLoading=False] /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Margin" Value="0"></Setter>
        </Style>

        <Style Selector="^:right">
            <Style Selector="^ /template/ Panel#PART_IconRoot">
                <Setter Property="Grid.Column" Value="1" />
                <Setter Property="Grid.Row" Value="0" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Grid.Column" Value="0" />
                <Setter Property="Grid.Row" Value="0" />
                <Setter Property="Margin" Value="0 0 8 0" />
            </Style>
        </Style>

        <Style Selector="^:left">
            <Style Selector="^ /template/ Panel#PART_IconRoot">
                <Setter Property="Grid.Column" Value="0" />
                <Setter Property="Grid.Row" Value="0" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Grid.Column" Value="1" />
                <Setter Property="Grid.Row" Value="0" />
                <Setter Property="Margin" Value="8 0 0 0" />
            </Style>
        </Style>

        <Style Selector="^:top">
            <Style Selector="^ /template/ Panel#PART_IconRoot">
                <Setter Property="Grid.Column" Value="0" />
                <Setter Property="Grid.Row" Value="0" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Grid.Column" Value="0" />
                <Setter Property="Grid.Row" Value="1" />
                <Setter Property="Margin" Value="0 4 0 0" />
            </Style>
        </Style>

        <Style Selector="^:bottom">
            <Style Selector="^ /template/ Panel#PART_IconRoot">
                <Setter Property="Grid.Column" Value="0" />
                <Setter Property="Grid.Row" Value="1" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Grid.Column" Value="0" />
                <Setter Property="Grid.Row" Value="0" />
                <Setter Property="Margin" Value="0 0 0 4" />
            </Style>
        </Style>

        <Style Selector="^.Large">
            <Setter Property="Padding" Value="{DynamicResource ButtonLargePadding}" />
        </Style>
        <Style Selector="^.Small">
            <Setter Property="Padding" Value="{DynamicResource ButtonSmallPadding}" />
        </Style>
    </ControlTheme>

    <ControlTheme
        x:Key="SolidIconButton"
        BasedOn="{StaticResource {x:Type u:IconButton}}"
        TargetType="u:IconButton">
        <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
        <Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryBorderBrush}" />

        <Style Selector="^:pointerover">
            <Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryPointeroverBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryPointeroverBorderBrush}" />
        </Style>
        <Style Selector="^:pressed">
            <Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryPressedBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryPressedBorderBrush}" />
        </Style>

        <Style Selector="^.Primary">
            <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
            <Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryBorderBrush}" />
            <Style Selector="^:pointerover">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryPressedBorderBrush}" />
            </Style>
        </Style>
        <Style Selector="^.Secondary">
            <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
            <Setter Property="Background" Value="{DynamicResource ButtonSolidSecondaryBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidSecondaryBorderBrush}" />
            <Style Selector="^:pointerover">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidSecondaryPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidSecondaryPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidSecondaryPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidSecondaryPressedBorderBrush}" />
            </Style>
        </Style>
        <Style Selector="^.Tertiary">
            <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
            <Setter Property="Background" Value="{DynamicResource ButtonSolidTertiaryBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidTertiaryBorderBrush}" />
            <Style Selector="^:pointerover">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidTertiaryPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidTertiaryPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidTertiaryPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidTertiaryPressedBorderBrush}" />
            </Style>
        </Style>
        <Style Selector="^.Success">
            <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
            <Setter Property="Background" Value="{DynamicResource ButtonSolidSuccessBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidSuccessBorderBrush}" />
            <Style Selector="^:pointerover">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidSuccessPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidSuccessPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidSuccessPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidSuccessPressedBorderBrush}" />
            </Style>
        </Style>
        <Style Selector="^.Warning">
            <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
            <Setter Property="Background" Value="{DynamicResource ButtonSolidWarningBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidWarningBorderBrush}" />
            <Style Selector="^:pointerover">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidWarningPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidWarningPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidWarningPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidWarningPressedBorderBrush}" />
            </Style>
        </Style>
        <Style Selector="^.Danger">
            <Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
            <Setter Property="Background" Value="{DynamicResource ButtonSolidDangerBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidDangerBorderBrush}" />
            <Style Selector="^:pointerover">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidDangerPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidDangerPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed">
                <Setter Property="Background" Value="{DynamicResource ButtonSolidDangerPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidDangerPressedBorderBrush}" />
            </Style>
        </Style>

        <Style Selector="^:disabled">
            <Setter Property="BorderBrush" Value="{DynamicResource ButtonDefaultDisabledBorderBrush}" />
            <Setter Property="Background" Value="{DynamicResource ButtonDefaultDisabledBackground}" />
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultDisabledForeground}" />
        </Style>
    </ControlTheme>

    <ControlTheme
        x:Key="BorderlessIconButton"
        BasedOn="{StaticResource {x:Type u:IconButton}}"
        TargetType="u:IconButton">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Style Selector="^:disabled">
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Foreground" Value="{DynamicResource ButtonDefaultDisabledForeground}" />
        </Style>

    </ControlTheme>
</ResourceDictionary>
