<Page
    x:Class="Microsoft.PowerToys.Settings.UI.Views.AwakePage"
    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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c="using:Microsoft.PowerToys.Settings.UI.Converters"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
    mc:Ignorable="d"
    AutomationProperties.LandmarkType="Main">

    <Page.Resources>
        <c:AwakeModeToBoolConverter x:Key="AwakeModeToBoolConverter" />
    </Page.Resources>

    <controls:SettingsPageControl x:Uid="Awake" IsTabStop="False"
                                  ModuleImageSource="ms-appx:///Assets/Modules/Awake.png">
        <controls:SettingsPageControl.ModuleContent>
            <StackPanel Orientation="Vertical">

                <controls:Setting x:Uid="Awake_EnableAwake">
                    <controls:Setting.Icon>
                        <BitmapIcon UriSource="ms-appx:///Assets/FluentIcons/FluentIconsAwake.png" ShowAsMonochrome="False" />
                    </controls:Setting.Icon>
                    <controls:Setting.ActionContent>
                        <ToggleSwitch IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" HorizontalAlignment="Right"/>
                    </controls:Setting.ActionContent>
                </controls:Setting>

                <controls:SettingsGroup x:Uid="Awake_Behavior_GroupSettings" IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
                    <controls:Setting x:Uid="Awake_EnableDisplayKeepAwake" Icon="&#xE7FB;">
                        <controls:Setting.ActionContent>
                            <ToggleSwitch IsOn="{x:Bind ViewModel.KeepDisplayOn, Mode=TwoWay}" />
                        </controls:Setting.ActionContent>
                    </controls:Setting>

                    <controls:SettingExpander IsExpanded="True">
                        <controls:SettingExpander.Header>
                            <controls:Setting x:Uid="Awake_Mode"
                                              Icon="&#xEC4E;"
                                              Style="{StaticResource ExpanderHeaderSettingStyle}" />
                        </controls:SettingExpander.Header>
                        <controls:SettingExpander.Content>
                            <StackPanel Padding="56,16,16,24"
                                        Spacing="12">
                                <RadioButton x:Uid="Awake_NoKeepAwake"
                                             IsChecked="{x:Bind Path=ViewModel.Mode, Mode=TwoWay, Converter={StaticResource AwakeModeToBoolConverter}, ConverterParameter=0}">
                                    <RadioButton.Content>
                                        <TextBlock TextWrapping="WrapWholeWords"
                                                   LineHeight="20">
                                            <Run x:Uid="Awake_NoKeepAwakeContent"/>
                                            <LineBreak/>
                                            <Run Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                x:Uid="Awake_NoKeepAwakeDescription"/>
                                        </TextBlock>
                                    </RadioButton.Content>
                                </RadioButton>
                                <RadioButton x:Uid="Awake_IndefiniteKeepAwake"
                                             IsChecked="{x:Bind Path=ViewModel.Mode, Mode=TwoWay, Converter={StaticResource AwakeModeToBoolConverter}, ConverterParameter=1}">
                                    <RadioButton.Content>
                                        <TextBlock TextWrapping="WrapWholeWords"
                                                   LineHeight="20">
                                            <Run x:Uid="Awake_IndefiniteKeepAwakeContent"/>
                                            <LineBreak/>
                                            <Run Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                 x:Uid="Awake_IndefiniteKeepAwakeDescription"/>
                                        </TextBlock>
                                    </RadioButton.Content>
                                </RadioButton>
                                <RadioButton x:Uid="Awake_TemporaryKeepAwake"
                                            IsChecked="{x:Bind Path=ViewModel.Mode, Mode=TwoWay, Converter={StaticResource AwakeModeToBoolConverter}, ConverterParameter=2}">
                                    <RadioButton.Content>
                                        <TextBlock TextWrapping="WrapWholeWords"
                                                   LineHeight="20">
                                            <Run x:Uid="Awake_TemporaryKeepAwakeContent"/>
                                            <LineBreak/>
                                            <Run Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                 x:Uid="Awake_TemporaryKeepAwakeDescription"/>
                                        </TextBlock>
                                    </RadioButton.Content>
                                </RadioButton>
                                <StackPanel AutomationProperties.LabeledBy="{Binding ElementName=ModeTitleLabel}"
                                            Margin="0,-8,0,0">

                                    <StackPanel Margin="28,8,0,0"
                                                Orientation="Horizontal">
                                        <muxc:NumberBox x:Uid="Awake_TemporaryKeepAwake_Hours"
                                                        Value="{x:Bind ViewModel.Hours, Mode=TwoWay}"
                                                        IsEnabled="{x:Bind ViewModel.IsTimeConfigurationEnabled, Mode=OneWay}"
                                                        Minimum="0"
                                                        SpinButtonPlacementMode="Compact"
                                                        HorizontalAlignment="Left"
                                                        MinWidth="90"
                                                        SmallChange="1" 
                                                        LargeChange="5"/>
                                        <muxc:NumberBox x:Uid="Awake_TemporaryKeepAwake_Minutes"
                                                        Value="{x:Bind ViewModel.Minutes, Mode=TwoWay}"
                                                        IsEnabled="{x:Bind ViewModel.IsTimeConfigurationEnabled, Mode=OneWay}"
                                                        Minimum="0"
                                                        SpinButtonPlacementMode="Compact"
                                                        Margin="8,0,0,0"
                                                        HorizontalAlignment="Left"
                                                        MinWidth="90"
                                                        SmallChange="1" 
                                                        LargeChange="5"/>
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>
                        </controls:SettingExpander.Content>
                    </controls:SettingExpander>
                </controls:SettingsGroup>
            </StackPanel>
        </controls:SettingsPageControl.ModuleContent>

        <controls:SettingsPageControl.PrimaryLinks>
            <controls:PageLink x:Uid="LearnMore_Awake" Link="https://aka.ms/PowerToysOverview_Awake"/>
        </controls:SettingsPageControl.PrimaryLinks>
        <controls:SettingsPageControl.SecondaryLinks>
            <controls:PageLink Text="Den Delimarsky's Awake" Link="https://Awake.den.dev"/>
        </controls:SettingsPageControl.SecondaryLinks>
    </controls:SettingsPageControl>
</Page>