<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:APKInstaller.Controls"
    xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Setting.ThemeResources.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style BasedOn="{StaticResource DefaultSettingCardStyle}" TargetType="controls:Setting" />

    <Style x:Key="DefaultSettingCardStyle" TargetType="controls:Setting">
        <Style.Setters>
            <Setter Property="Background" Value="{ThemeResource SettingCardBackground}" />
            <Setter Property="Foreground" Value="{ThemeResource SettingCardForeground}" />
            <Setter Property="BorderBrush" Value="{ThemeResource SettingCardBorderBrush}" />
            <Setter Property="BorderThickness" Value="{ThemeResource SettingCardBorderThickness}" />
            <Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
            <Setter Property="MinHeight" Value="{ThemeResource SettingCardMinHeight}" />
            <Setter Property="MinWidth" Value="{ThemeResource SettingCardMinWidth}" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="HorizontalContentAlignment" Value="Right" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
            <Setter Property="Padding" Value="{ThemeResource SettingCardPadding}" />
            <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
            <Setter Property="FontWeight" Value="Normal" />
            <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
            <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
            <Setter Property="FocusVisualMargin" Value="-3" />
            <Setter Property="ActionIcon" Value="{StaticResource SettingCardChevronRightGlyph}" />
            <Setter Property="WrapThreshold" Value="{StaticResource SettingCardWrapThreshold}" />
            <Setter Property="WrapNoIconThreshold" Value="{StaticResource SettingCardWrapNoIconThreshold}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="controls:Setting">
                        <Grid
                            x:Name="PART_RootGrid"
                            MinWidth="{TemplateBinding MinWidth}"
                            MinHeight="{TemplateBinding MinHeight}"
                            MaxWidth="{TemplateBinding MaxWidth}"
                            Padding="{TemplateBinding Padding}"
                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalAlignment}"
                            AnimatedIcon.State="Normal"
                            Background="{TemplateBinding Background}"
                            BackgroundSizing="{TemplateBinding BackgroundSizing}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{TemplateBinding CornerRadius}">
                            <Grid.BackgroundTransition>
                                <BrushTransition Duration="0:0:0.083" />
                            </Grid.BackgroundTransition>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" MinWidth="{ThemeResource SettingCardLeftIndention}" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Viewbox
                                x:Name="PART_HeaderIconPresenterHolder"
                                Grid.RowSpan="1"
                                MaxWidth="{ThemeResource SettingCardHeaderIconMaxSize}"
                                MaxHeight="{ThemeResource SettingCardHeaderIconMaxSize}"
                                Margin="{ThemeResource SettingCardHeaderIconMargin}">
                                <ContentPresenter
                                    x:Name="PART_HeaderIconPresenter"
                                    Content="{TemplateBinding Icon}"
                                    FontFamily="{StaticResource SymbolThemeFontFamily}"
                                    HighContrastAdjustment="None" />
                            </Viewbox>

                            <StackPanel
                                x:Name="HeaderPanel"
                                Grid.Column="1"
                                Margin="0,0,24,0"
                                VerticalAlignment="Center"
                                Orientation="Vertical">
                                <ContentPresenter
                                    x:Name="PART_HeaderPresenter"
                                    Grid.Column="1"
                                    HorizontalAlignment="Left"
                                    Content="{TemplateBinding Header}"
                                    HighContrastAdjustment="None"
                                    TextWrapping="Wrap" />

                                <ContentPresenter
                                    x:Name="PART_DescriptionPresenter"
                                    Content="{TemplateBinding Description}"
                                    FontSize="{ThemeResource SettingCardDescriptionFontSize}"
                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                    TextWrapping="Wrap">
                                    <ContentPresenter.Resources>
                                        <Style BasedOn="{StaticResource CaptionTextBlockStyle}" TargetType="TextBlock">
                                            <Style.Setters>
                                                <Setter Property="TextWrapping" Value="Wrap" />
                                            </Style.Setters>
                                        </Style>
                                        <Style BasedOn="{StaticResource TextButtonStyle}" TargetType="HyperlinkButton">
                                            <Style.Setters>
                                                <Setter Property="FontSize" Value="{ThemeResource SettingCardDescriptionFontSize}" />
                                                <Setter Property="Padding" Value="0,0,0,-1" />
                                                <Setter Property="FontWeight" Value="SemiBold" />
                                            </Style.Setters>
                                        </Style>
                                        <Style TargetType="Hyperlink">
                                            <Style.Setters>
                                                <Setter Property="UnderlineStyle" Value="None" />
                                                <Setter Property="TextDecorations" Value="None" />
                                                <Setter Property="FontWeight" Value="SemiBold" />
                                            </Style.Setters>
                                        </Style>
                                    </ContentPresenter.Resources>
                                </ContentPresenter>
                            </StackPanel>

                            <ContentPresenter
                                x:Name="PART_ContentPresenter"
                                Grid.Column="2"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                Content="{TemplateBinding Content}">
                                <ContentPresenter.Resources>
                                    <Style BasedOn="{StaticResource ToggleSwitchSettingStyle}" TargetType="ToggleButton" />
                                </ContentPresenter.Resources>
                            </ContentPresenter>

                            <ContentControl
                                x:Name="PART_ActionIconPresenter"
                                Grid.RowSpan="2"
                                Grid.Column="3"
                                Width="{ThemeResource SettingCardActionButtonWidth}"
                                Height="{ThemeResource SettingCardActionButtonHeight}"
                                Margin="4,0,-8,0"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                HorizontalContentAlignment="Center"
                                VerticalContentAlignment="Center"
                                AutomationProperties.LocalizedControlType="button"
                                AutomationProperties.Name="{TemplateBinding ActionIconToolTip}"
                                CornerRadius="{ThemeResource ControlCornerRadius}"
                                FocusVisualMargin="-3"
                                FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                HighContrastAdjustment="None"
                                IsTabStop="True"
                                ToolTipService.ToolTip="{TemplateBinding ActionIconToolTip}"
                                UseSystemFocusVisuals="True"
                                Visibility="Collapsed">
                                <Viewbox MaxWidth="{ThemeResource SettingCardActionIconMaxSize}" MaxHeight="{ThemeResource SettingCardActionIconMaxSize}">
                                    <ContentPresenter
                                        Content="{TemplateBinding ActionIcon}"
                                        FontFamily="{StaticResource SymbolThemeFontFamily}"
                                        HighContrastAdjustment="None" />
                                </Viewbox>
                            </ContentControl>

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RootGrid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardBackgroundPointerOver}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RootGrid" Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardBorderBrushPointerOver}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundPointerOver}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderIconPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundPointerOver}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                        <VisualState.Setters>
                                            <Setter Target="PART_RootGrid.(AnimatedIcon.State)" Value="PointerOver" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RootGrid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardBackgroundPressed}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_RootGrid" Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardBorderBrushPressed}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderIconPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundPressed}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundPressed}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_DescriptionPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundPressed}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                        <VisualState.Setters>
                                            <Setter Target="PART_RootGrid.(AnimatedIcon.State)" Value="Pressed" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ActionIconPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundDisabled}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderIconPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundDisabled}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HeaderPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundDisabled}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_DescriptionPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SettingCardForegroundDisabled}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                        <VisualState.Setters>
                                            <!--  DisabledVisual Should be handled by the control, not the animated icon.  -->
                                            <Setter Target="PART_RootGrid.(AnimatedIcon.State)" Value="Normal" />
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ContentAlignmentStates">
                                    <VisualState x:Name="Right" />
                                    <VisualState x:Name="Left">
                                        <VisualState.StateTriggers>
                                            <triggers:IsEqualStateTrigger Value="{Binding ContentAlignment, RelativeSource={RelativeSource TemplatedParent}}" To="Left" />
                                        </VisualState.StateTriggers>
                                        <VisualState.Setters>
                                            <Setter Target="PART_HeaderIconPresenterHolder.Visibility" Value="Collapsed" />
                                            <Setter Target="PART_DescriptionPresenter.Visibility" Value="Collapsed" />
                                            <Setter Target="PART_HeaderPresenter.Visibility" Value="Collapsed" />
                                            <Setter Target="PART_ContentPresenter.(Grid.Row)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.(Grid.Column)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.HorizontalAlignment" Value="Left" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="RightWrapped">
                                        <VisualState.StateTriggers>
                                            <triggers:ControlSizeTrigger
                                                MinWidth="{Binding WrapNoIconThreshold, RelativeSource={RelativeSource TemplatedParent}}"
                                                MaxWidth="{Binding WrapThreshold, RelativeSource={RelativeSource TemplatedParent}}"
                                                TargetElement="{Binding ElementName=PART_RootGrid}" />
                                        </VisualState.StateTriggers>
                                        <VisualState.Setters>
                                            <Setter Target="PART_ContentPresenter.(Grid.Row)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.(Grid.Column)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.HorizontalAlignment" Value="Stretch" />
                                            <Setter Target="PART_ContentPresenter.HorizontalContentAlignment" Value="Left" />
                                            <Setter Target="PART_ContentPresenter.Margin" Value="{ThemeResource SettingCardVerticalHeaderContentSpacing}" />
                                            <Setter Target="HeaderPanel.Margin" Value="0" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="RightWrappedNoIcon">
                                        <VisualState.StateTriggers>
                                            <triggers:ControlSizeTrigger MaxWidth="{Binding WrapNoIconThreshold, RelativeSource={RelativeSource TemplatedParent}}" TargetElement="{Binding ElementName=PART_RootGrid}" />
                                        </VisualState.StateTriggers>
                                        <VisualState.Setters>
                                            <Setter Target="PART_HeaderIconPresenterHolder.Visibility" Value="Collapsed" />
                                            <Setter Target="PART_ContentPresenter.(Grid.Row)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.(Grid.Column)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.HorizontalAlignment" Value="Stretch" />
                                            <Setter Target="PART_ContentPresenter.HorizontalContentAlignment" Value="Left" />
                                            <Setter Target="PART_ContentPresenter.Margin" Value="{ThemeResource SettingCardVerticalHeaderContentSpacing}" />
                                            <Setter Target="HeaderPanel.Margin" Value="0" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="Vertical">
                                        <VisualState.StateTriggers>
                                            <triggers:IsEqualStateTrigger Value="{Binding ContentAlignment, RelativeSource={RelativeSource TemplatedParent}}" To="Vertical" />
                                        </VisualState.StateTriggers>
                                        <VisualState.Setters>
                                            <Setter Target="PART_ContentPresenter.(Grid.Row)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.(Grid.Column)" Value="1" />
                                            <Setter Target="PART_ContentPresenter.HorizontalAlignment" Value="Stretch" />
                                            <Setter Target="PART_ContentPresenter.HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource TemplatedParent}}" />
                                            <Setter Target="PART_ContentPresenter.Margin" Value="{ThemeResource SettingCardVerticalHeaderContentSpacing}" />
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="HeaderVisibilityGroup">
                                    <VisualState x:Name="HeaderVisible" />
                                    <VisualState x:Name="HeaderCollapsed">
                                        <VisualState.Setters>
                                            <Setter Target="PART_HeaderPresenter.Visibility" Value="Collapsed" />
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ActionIconVisibilityGroup">
                                    <VisualState x:Name="ActionIconVisible">
                                        <VisualState.Setters>
                                            <Setter Target="PART_ActionIconPresenter.Visibility" Value="Visible" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState x:Name="ActionIconCollapsed" />
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="DescriptionVisibilityGroup">
                                    <VisualState x:Name="DescriptionVisible" />
                                    <VisualState x:Name="DescriptionCollapsed">
                                        <VisualState.Setters>
                                            <Setter Target="PART_DescriptionPresenter.Visibility" Value="Collapsed" />
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>
</ResourceDictionary>
