<ui:Page
    x:Class="ModernWpf.SampleApp.ControlPages.ThemesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="http://schemas.modernwpf.com/2019"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:presets="clr-namespace:ModernWpf.SampleApp.Presets"
    xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d">

    <Page.Resources>
        <sys:Double x:Key="ItemWidth">280</sys:Double>
        <sc:AppThemeConverter x:Key="AppThemeConverter" />
    </Page.Resources>

    <ScrollViewer>
        <ui:SimpleStackPanel
            Spacing="24"
            Margin="{StaticResource ControlPageContentMargin}">

            <ui:RadioButtons
                Header="Theme Mode"
                SelectedItem="{Binding Source={x:Static sc:ThemeManagerProxy.Current}, Path=ApplicationTheme, Converter={StaticResource AppThemeConverter}}">
                <ui:RadioButtons.ItemsSource>
                    <sc:AppThemes />
                </ui:RadioButtons.ItemsSource>
            </ui:RadioButtons>

            <ComboBox
                x:Name="ColorPresetsComboBox"
                MinWidth="{StaticResource ItemWidth}"
                ui:ControlHelper.Header="Color Presets"
                SelectedItem="{Binding ColorPreset, Source={x:Static presets:PresetManager.Current}}">
                <sys:String>Default</sys:String>
                <sys:String>Forest</sys:String>
                <sys:String>Lavender</sys:String>
                <sys:String>Nighttime</sys:String>
            </ComboBox>

            <ComboBox
                x:Name="ShapePresetsComboBox"
                MinWidth="{StaticResource ItemWidth}"
                ui:ControlHelper.Header="Shape Presets"
                DisplayMemberPath="DisplayName"
                SelectedValuePath="Value"
                SelectedValue="{Binding ShapePreset, Source={x:Static presets:PresetManager.Current}}" />

            <sc:AccentColorPicker x:Name="AccentColorPicker" />

            <StackPanel>
                <TextBlock
                    Text="App-level custom theme brush"
                    Style="{StaticResource BodyTextBlockStyle}"
                    Margin="0,0,0,4" />
                <Rectangle
                    Width="{StaticResource ItemWidth}"
                    Height="50"
                    HorizontalAlignment="Left"
                    Fill="{DynamicResource CustomThemeBrush}" />
            </StackPanel>

            <StackPanel>
                <TextBlock
                    Text="App-level custom theme brush overriden at element level"
                    Style="{StaticResource BodyTextBlockStyle}"
                    Margin="0,0,0,4" />
                <Rectangle
                    Width="{StaticResource ItemWidth}"
                    Height="50"
                    HorizontalAlignment="Left"
                    Fill="{DynamicResource CustomThemeBrush}"
                    ui:ThemeManager.HasThemeResources="True">
                    <Rectangle.Resources>
                        <ui:ResourceDictionaryEx>
                            <ui:ResourceDictionaryEx.ThemeDictionaries>
                                <ResourceDictionary x:Key="Light">
                                    <SolidColorBrush x:Key="CustomThemeBrush" Color="DarkRed" />
                                </ResourceDictionary>
                                <ResourceDictionary x:Key="Dark">
                                    <SolidColorBrush x:Key="CustomThemeBrush" Color="Orange" />
                                </ResourceDictionary>
                                <ResourceDictionary x:Key="HighContrast">
                                    <SolidColorBrush x:Key="CustomThemeBrush" Color="DarkBlue" />
                                </ResourceDictionary>
                            </ui:ResourceDictionaryEx.ThemeDictionaries>
                        </ui:ResourceDictionaryEx>
                    </Rectangle.Resources>
                </Rectangle>
            </StackPanel>

            <GroupBox
                x:Name="InverseAppThemeGroupBox"
                Header="Inverse app theme"
                Background="{DynamicResource SystemControlPageBackgroundAltHighBrush}"
                Margin="-24,0,-24,0"
                Padding="24,0,24,15"
                ui:ThemeManager.RequestedTheme="{Binding Source={x:Static sc:ThemeManagerProxy.Current}, Path=ActualApplicationTheme, Converter={StaticResource InverseAppThemeConverter}}">
                <GroupBox.Resources>
                    <Thickness x:Key="GroupBoxHeaderMargin">24,4,24,20</Thickness>
                </GroupBox.Resources>
                <ui:SimpleStackPanel Spacing="24">
                    <TextBox
                        Width="{StaticResource ItemWidth}"
                        HorizontalAlignment="Left"
                        ui:ControlHelper.Header="Actual application theme"
                        Text="{Binding Source={x:Static sc:ThemeManagerProxy.Current}, Path=ActualApplicationTheme, Mode=OneWay}"
                        IsReadOnly="True" />

                    <TextBox
                        Width="{StaticResource ItemWidth}"
                        HorizontalAlignment="Left"
                        ui:ControlHelper.Header="Actual window theme"
                        Text="{Binding Path=(ui:ThemeManager.ActualTheme), RelativeSource={RelativeSource AncestorType=Window}, Mode=OneWay}"
                        IsReadOnly="True" />

                    <TextBox
                        x:Name="AET"
                        Width="{StaticResource ItemWidth}"
                        HorizontalAlignment="Left"
                        ui:ControlHelper.Header="Actual element theme"
                        Text="{Binding ElementName=InverseAppThemeGroupBox, Path=(ui:ThemeManager.ActualTheme), Mode=OneWay}"
                        IsReadOnly="True" />

                    <TextBox
                        Width="{StaticResource ItemWidth}"
                        HorizontalAlignment="Left"
                        ui:ControlHelper.Header="Actual accent color"
                        Text="{Binding Source={x:Static sc:ThemeManagerProxy.Current}, Path=ActualAccentColor, Mode=OneWay}"
                        IsReadOnly="True" />

                    <ui:ToggleSwitch
                        Header="High contrast"
                        IsOn="{Binding Path=(SystemParameters.HighContrast), Mode=OneWay}"
                        IsEnabled="False" />
                </ui:SimpleStackPanel>
            </GroupBox>
        </ui:SimpleStackPanel>
    </ScrollViewer>
</ui:Page>
