<Page x:Class="AutoDarkModeApp.Pages.PageSwitchModes"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="clr-namespace:AutoDarkModeApp.Pages"
      xmlns:ui="http://schemas.modernwpf.com/2019"
      xmlns:uc="clr-namespace:AutoDarkModeApp.Controls"
      xmlns:p="clr-namespace:AutoDarkModeLib.Properties;assembly=AutoDarkModeLib"
      mc:Ignorable="d"
      d:DesignHeight="1450"
      d:DesignWidth="800"
      Title="PageSwitchModes"
      Height="Auto"
      Width="Auto">

    <Page.DataContext>
        <uc:PageSwitchModesViewModel />
    </Page.DataContext>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.4*" />
            <ColumnDefinition Width="10*"
                              MaxWidth="1000"
                              MinWidth="450" />
            <ColumnDefinition Width="0.4*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="20" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="20" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>

        <!-- Page Title -->
        <TextBlock Grid.Row="1"
                   Grid.Column="1"
                   Margin="0,0,0,0"
                   Text="{x:Static p:Resources.NavbarSwitchModes}"
                   FontFamily="Segoe UI Semilight"
                   FontSize="30" />

        <ui:SimpleStackPanel Grid.Row="3"
                             Grid.Column="1"
                             Margin="0,0,0,0"
                             Orientation="Vertical">

            <TextBlock Name="TextBlockConditions"
                       Margin="0,10,0,10"
                       Text="{x:Static p:Resources.SwitchModesTextBlockHeaderConditions}"
                       FontFamily="Segoe UI Semibold"
                       FontSize="14" />


            <uc:Card Padding="30,15,15,15">
                <ui:SimpleStackPanel>
                    <CheckBox Name="CheckBoxGPUMonitoring"
                              Content="{x:Static p:Resources.SwitchModesCheckBoxGPUMonitoring}"
                              Margin="0,0,0,0"
                              Click="CheckBoxGPUMonitoring_Click" />



                    <ui:SimpleStackPanel Name="StackPanelGPUMonitoring"
                                         Orientation="Vertical">
                        <Separator Margin="-30,10,-15,0"
                                   Background="{DynamicResource Win11Border}" />

                        <DockPanel LastChildFill="false"
                                   Margin="0,10,0,10">
                            <TextBlock Margin="0,0,0,0"
                                       VerticalAlignment="Center"
                                       Text="{x:Static p:Resources.SwitchModesTextBlockMinimumUsage}"
                                       FontSize="14" />

                            <ui:NumberBox Name="NumberBoxGPUThreshold"
                                          Margin="0,5,0,0"
                                          DockPanel.Dock="Right"
                                          MinWidth="170"
                                          Minimum="0"
                                          Maximum="100"
                                          SpinButtonPlacementMode="Inline"
                                          SmallChange="5"
                                          LargeChange="5"
                                          ValueChanged="NumberBoxGPUThreshold_ValueChanged" />
                        </DockPanel>

                        <Separator Margin="-30,0,-15,0"
                                   Background="{DynamicResource Win11Border}" />

                        <DockPanel LastChildFill="false"
                                   Margin="0,5,0,10">
                            <TextBlock Margin="0,10,0,0"
                                       VerticalAlignment="Center"
                                       Text="{x:Static p:Resources.SwitchModesTextBlockGPUUsageDetectionSpeed}"
                                       FontSize="14" />

                            <ComboBox Name="ComboBoxGPUSamples"
                                      Margin="0,10,0,0"
                                      DockPanel.Dock="Right"
                                      MinWidth="170"
                                      SelectionChanged="ComboBoxGPUSamples_SelectionChanged">

                                <ComboBoxItem Tag="1"
                                              Content="{x:Static p:Resources.SwitchModesComboBoxItemSamplesFast}" />
                                <ComboBoxItem Tag="2"
                                              Content="{x:Static p:Resources.SwitchModesComboBoxItemSamplesMedium}" />
                                <ComboBoxItem Tag="3"
                                              Content="{x:Static p:Resources.SwitchModesComboBoxItemSamplesSlow}" />
                            </ComboBox>
                        </DockPanel>

                    </ui:SimpleStackPanel>
                </ui:SimpleStackPanel>
            </uc:Card>

            <uc:Card Padding="30,15,15,0"
                     Margin="0,2,0,0">
                <ui:SimpleStackPanel>
                    <CheckBox Click="CheckBoxProcessBlockList_Click"
                              Content="{x:Static p:Resources.SwitchModesCheckBoxProcessBlockList}"
                              Margin="0,0,0,15"
                              Name="CheckBoxBlockList" />

                    <Separator Margin="-30,0,-15,0"
                               DockPanel.Dock="Top"
                               Name="BlockListOptionsSeparator"
                               Background="{DynamicResource Win11Border}" />

                    <ui:SimpleStackPanel Name="SimpleStackPanelProcessBlockList">
                        <DockPanel Margin="0,10,0,0">
                            <Expander DockPanel.Dock="Bottom"
                                      FlowDirection="RightToLeft"
                                      Header="{x:Static p:Resources.SwitchModesExpanderHeaderBlockedProcesses}"
                                      HorizontalAlignment="Stretch"
                                      Margin="0,15,0,10">
                                <Expander.HeaderTemplate>
                                    <DataTemplate>
                                        <ui:SimpleStackPanel Cursor="Hand">
                                            <!--Unsure why the negative left margin is necessary here, 
                                            removing it cuts off the leading character-->
                                            <TextBlock FlowDirection="LeftToRight"
                                                       Margin="-23,0,0,5"
                                                       Text="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=Header}"
                                                       Width="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=ActualWidth}">
                                            </TextBlock>
                                        </ui:SimpleStackPanel>
                                    </DataTemplate>
                                </Expander.HeaderTemplate>

                                <ItemsControl Margin="0,10,0,0"
                                              FlowDirection="LeftToRight"
                                              Name="ItemsControlProcessBlockList">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <ui:SimpleStackPanel>
                                                <Separator Margin="-29,5,-14,5"
                                                           Background="{DynamicResource Win11Border}" />

                                                <DockPanel FlowDirection="LeftToRight"
                                                           HorizontalAlignment="Stretch"
                                                           LastChildFill="False"
                                                           Margin="3,5,0,5"
                                                           VerticalAlignment="Center">
                                                    <TextBlock Text="{Binding}"
                                                               VerticalAlignment="Center" />
                                                    <Button Click="SwitchModesRemoveProcess_OnClick"
                                                            Content="{x:Static p:Resources.SwitchModesButtonRemoveProcess}"
                                                            DockPanel.Dock="Right"
                                                            Tag="{Binding}" />
                                                </DockPanel>
                                            </ui:SimpleStackPanel>

                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </Expander>

                            <Button Click="SwitchModesAddSelectedProcess_OnClick"
                                    Content="{x:Static p:Resources.SwitchModesButtonAddProcess}"
                                    DockPanel.Dock="Right"
                                    HorizontalAlignment="Right"
                                    MinWidth="80"
                                    Margin="0,5,0,0"
                                    VerticalAlignment="Center" />

                            <ComboBox DockPanel.Dock="Right"
                                      HorizontalAlignment="Left"
                                      IsReadOnly="True"
                                      Margin="0,5,10,0"
                                      Width="300"
                                      ItemsSource="{Binding FilteredProcesses}"
                                      DropDownOpened="ComboBoxProcessBlockList_DropDownOpened"
                                      Name="ComboBoxProcessBlockList"
                                      VerticalAlignment="Center">
                            </ComboBox>
                        </DockPanel>
                    </ui:SimpleStackPanel>
                </ui:SimpleStackPanel>
            </uc:Card>

            <uc:Card Padding="30,15,15,15"
                     Margin="0,2,0,0">
                <ui:SimpleStackPanel>
                    <CheckBox Name="CheckBoxIdleTimer"
                              Content="{x:Static p:Resources.SwitchModesCheckBoxIdleTimer}"
                              Margin="0,0,0,0"
                              Click="CheckBoxIdleTimer_Click" />


                    <DockPanel Name="StackPanelIdleTimer"
                               LastChildFill="false">

                        <Separator Margin="-30,10,-15,0"
                                   DockPanel.Dock="Top"
                                   Background="{DynamicResource Win11Border}" />

                        <TextBlock Margin="0,15,0,0"
                                   VerticalAlignment="Center"
                                   Text="{x:Static p:Resources.SwitchModesTextBlockIdleTimerDescription}"
                                   FontSize="14" />
                        <ui:NumberBox Name="NumberBoxIdleTimer"
                                      Margin="0,15,0,0"
                                      DockPanel.Dock="Right"
                                      HorizontalAlignment="Left"
                                      MinWidth="170"
                                      Minimum="1"
                                      SpinButtonPlacementMode="Inline"
                                      SmallChange="1"
                                      LargeChange="1"
                                      ValueChanged="NumberBoxIdleTimer_ValueChanged" />
                    </DockPanel>
                </ui:SimpleStackPanel>
            </uc:Card>


            <uc:Card Padding="30,15,15,15"
                     Margin="0,2,0,0">
                <ui:SimpleStackPanel>
                    <CheckBox Name="CheckBoxAutoSwitchNotify"
                              Content="{x:Static p:Resources.SwitchModesCheckBoxAutoSwitchNotification}"
                              Margin="0,0,0,0"
                              Click="CheckBoxAutoSwitchNotify_Click" />

                    <DockPanel Name="StackPanelAutoSwitchNotify"
                               LastChildFill="False">


                        <Separator Margin="-30,10,-15,0"
                                   DockPanel.Dock="Top"
                                   Background="{DynamicResource Win11Border}" />

                        <TextBlock Margin="0,15,0,0"
                                   VerticalAlignment="Center"
                                   Text="{x:Static p:Resources.SwitchModesTextBlockAutoSwitchGracePeriod}"
                                   FontSize="14" />

                        <ui:NumberBox Name="NumberBoxAutoSwitchNotifyGracePeriod"
                                      Margin="0,15,0,0"
                                      HorizontalAlignment="Left"
                                      MinWidth="170"
                                      DockPanel.Dock="Right"
                                      Minimum="1"
                                      SpinButtonPlacementMode="Inline"
                                      SmallChange="1"
                                      LargeChange="1"
                                      ValueChanged="NumberBoxAutoSwitchNotifyGracePeriod_ValueChanged" />
                    </DockPanel>
                </ui:SimpleStackPanel>
            </uc:Card>


            <TextBlock Name="TextBlockBatteryPowered"
                       Margin="0,40,0,10"
                       Text="{x:Static p:Resources.SwitchModesTextBlockHeaderBatteryPowered}"
                       FontFamily="Segoe UI Semibold"
                       FontSize="14" />

            <uc:Card Padding="30,15,15,15">
                <CheckBox Name="CheckBoxBatteryDarkMode"
                          Content="{x:Static p:Resources.cbSettingsBatteryDarkMode}"
                          Margin="0,0,0,0"
                          Click="CheckBoxBatteryDarkMode_Click" />
            </uc:Card>


            <TextBlock Name="TextBlockHotkeys"
                       Margin="0,40,0,10"
                       Text="{x:Static p:Resources.SwitchModesTextBlockHeaderHotkeys}"
                       FontFamily="Segoe UI Semibold"
                       FontSize="14" />

            <uc:Card Padding="30,15,15,15">
                <ui:SimpleStackPanel>

                    <DockPanel LastChildFill="false">
                        <TextBlock Margin="0,0,0,0"
                                   VerticalAlignment="Center"
                                   Text="{x:Static p:Resources.SwitchModesToggleHeaderHotkey}"
                                   FontSize="14" />
                        <ui:ToggleSwitch Name="ToggleHotkeys"
                                         DockPanel.Dock="Right"
                                         OffContent="{x:Static p:Resources.ToggleSwitchOff}"
                                         OnContent="{x:Static p:Resources.ToggleSwitchOn}"
                                         HorizontalAlignment="Right"
                                         Margin="0,0,0,0"
                                         Toggled="ToggleHotkeys_Toggled" />
                    </DockPanel>

                    <TextBlock Name="TextBlockHotkeyEditHint"
                               Foreground="#999999"
                               Margin="0,2,0,0"
                               TextWrapping="Wrap"
                               DockPanel.Dock="Bottom"
                               Text="{x:Static p:Resources.SwitchModesHotkeyEditHint}"
                               FontSize="14" />
                </ui:SimpleStackPanel>
            </uc:Card>




            <Grid Name="GridHotkeys">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <uc:Card Padding="30,15,15,15"
                         Margin="0,2,0,0"
                         Grid.Row="0">
                    <Grid Margin="0,0,0,0">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock FontSize="14"
                                   Grid.Column="0"
                                   Margin="0,0,10,0"
                                   TextWrapping="Wrap"
                                   VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} {1}">
                                    <Binding Source="{x:Static p:Resources.SwitchModesTextBlockHeaderForceLight}" />
                                    <Binding Source="{x:Static p:Resources.SwitchModesHotkey}" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBox HorizontalAlignment="Left"
                                 ui:TextBoxHelper.IsDeleteButtonVisible="false"
                                 Width="240"
                                 Margin="0,5,0,0"
                                 Grid.Column="1"
                                 Name="HotkeyTextboxForceLight"
                                 PreviewKeyDown="HotkeyTextboxForceLight_PreviewKeyDown" />
                    </Grid>
                </uc:Card>

                <uc:Card Padding="30,15,15,15"
                         Margin="0,2,0,0"
                         Grid.Row="1">
                    <Grid Margin="0,0,0,0">


                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock FontSize="14"
                                   TextWrapping="Wrap"
                                   Margin="0,0,10,0"
                                   Grid.Column="0"
                                   VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} {1}">
                                    <Binding Source="{x:Static p:Resources.SwitchModesTextBlockHeaderForceDark}" />
                                    <Binding Source="{x:Static p:Resources.SwitchModesHotkey}" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBox HorizontalAlignment="Left"
                                 ui:TextBoxHelper.IsDeleteButtonVisible="false"
                                 Width="240"
                                 Margin="0,5,0,0"
                                 Grid.Column="1"
                                 Name="HotkeyTextboxForceDark"
                                 PreviewKeyDown="HotkeyTextboxForceDark_PreviewKeyDown" />
                    </Grid>
                </uc:Card>

                <uc:Card Padding="30,15,15,15"
                         Margin="0,2,0,0"
                         Grid.Row="2">
                    <Grid Margin="0,0,0,0">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock FontSize="14"
                                   TextWrapping="Wrap"
                                   Margin="0,0,10,0"
                                   Grid.Column="0"
                                   VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} {1}">
                                    <Binding Source="{x:Static p:Resources.SwitchModesTextBlockHeaderNoForce}" />
                                    <Binding Source="{x:Static p:Resources.SwitchModesHotkey}" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBox HorizontalAlignment="Left"
                                 ui:TextBoxHelper.IsDeleteButtonVisible="false"
                                 Width="240"
                                 Margin="0,5,0,0"
                                 Grid.Column="1"
                                 Name="HotkeyTextboxNoForce"
                                 PreviewKeyDown="HotkeyTextboxNoForce_PreviewKeyDown" />
                    </Grid>
                </uc:Card>
                <uc:Card Padding="30,15,15,15"
                         Margin="0,2,0,0"
                         Grid.Row="3">
                    <Grid Margin="0,00,0,0">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>


                        <TextBlock FontSize="14"
                                   Grid.Column="0"
                                   Margin="0,0,10,0"
                                   TextWrapping="Wrap"
                                   VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}{0} {1}">
                                    <Binding Source="{x:Static p:Resources.ToggleTheme}" />
                                    <Binding Source="{x:Static p:Resources.SwitchModesHotkey}" />
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                        <TextBox HorizontalAlignment="Left"
                                 ui:TextBoxHelper.IsDeleteButtonVisible="false"
                                 Width="240"
                                 Margin="0,5,0,0"
                                 Grid.Column="1"
                                 Name="HotkeyTextboxToggleTheme"
                                 PreviewKeyDown="HotkeyTextboxToggleTheme_PreviewKeyDown" />
                    </Grid>
                </uc:Card>

                <uc:Card Padding="30,15,15,15"
                         Margin="0,2,0,0"
                         Grid.Row="4">
                    <ui:SimpleStackPanel Margin="0,0,0,0">
                        <Grid>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBlock FontSize="14"
                                       Grid.Column="0"
                                       Margin="0,0,10,0"
                                       TextWrapping="Wrap"
                                       VerticalAlignment="Center">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}{0} {1}">
                                        <Binding Source="{x:Static p:Resources.SwitchModesTextBlockHeaderToggleAutomaticThemeSwitch}" />
                                        <Binding Source="{x:Static p:Resources.SwitchModesHotkey}" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                            <TextBox HorizontalAlignment="Left"
                                     Grid.Column="1"
                                     ui:TextBoxHelper.IsDeleteButtonVisible="false"
                                     Width="240"
                                     DockPanel.Dock="Right"
                                     Margin="0,5,0,5"
                                     Name="HotkeyTextboxToggleAutomaticThemeSwitch"
                                     PreviewKeyDown="HotkeyTextToggleAutomaticThemeSwitch_PreviewKeyDown" />
                        </Grid>

                        <Separator Margin="-30,10,-15,15"
                                   Background="{DynamicResource Win11Border}" />

                        <CheckBox Name="HotkeyCheckboxToggleAutomaticThemeSwitchNotification"
                                  Content="{x:Static p:Resources.HotkeyCheckboxToggleAutomaticThemeSwitchNotification}"
                                  Click="HotkeyCheckboxToggleAutomaticThemeSwitchNotification_Click"></CheckBox>
                    </ui:SimpleStackPanel>
                </uc:Card>

                <uc:Card Padding="30,15,15,15"
                         Margin="0,2,0,0"
                         Grid.Row="5">
                    <ui:SimpleStackPanel Margin="0,5,0,0">
                        <Grid>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>


                            <TextBlock FontSize="14"
                                       VerticalAlignment="Center"
                                       Margin="0,0,10,0"
                                       Grid.Column="0"
                                       TextWrapping="Wrap">
                                <TextBlock.Text>
                                    <MultiBinding StringFormat="{}{0} {1}">
                                        <Binding Source="{x:Static p:Resources.SwitchModesTextBlockHeaderTogglePostpone}" />
                                        <Binding Source="{x:Static p:Resources.SwitchModesHotkey}" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                            <TextBox HorizontalAlignment="Left"
                                     ui:TextBoxHelper.IsDeleteButtonVisible="false"
                                     Width="240"
                                     Margin="0,0,0,5"
                                     DockPanel.Dock="Right"
                                     Grid.Column="1"
                                     Name="HotkeyTextboxTogglePostpone"
                                     PreviewKeyDown="HotkeyTextboxTogglePostpone_PreviewKeyDown" />
                        </Grid>

                        <Separator Margin="-30,10,-15,15"
                                   Background="{DynamicResource Win11Border}" />

                        <CheckBox Name="HotkeyCheckboxTogglePostpone"
                                  Content="{x:Static p:Resources.HotkeyCheckboxToggleAutomaticThemeSwitchNotification}"
                                  Click="HotkeyCheckboxTogglePostpone_Click"></CheckBox>
                    </ui:SimpleStackPanel>
                </uc:Card>

            </Grid>
        </ui:SimpleStackPanel>

    </Grid>
</Page>
