<UserControl x:Class="CalculatorApp.GraphingSettings"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="using:CalculatorApp"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <SolidColorBrush x:Key="GraphSettingsErrorBackgroundBrush" Color="#33EB5757"/>
                    <SolidColorBrush x:Key="GraphSettingsErrorBorderBrush" Color="#FFEB5757"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="Light">
                    <SolidColorBrush x:Key="GraphSettingsErrorBackgroundBrush" Color="#33EB5757"/>
                    <SolidColorBrush x:Key="GraphSettingsErrorBorderBrush" Color="#FFEB5757"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <SolidColorBrush x:Key="GraphSettingsErrorBackgroundBrush" Color="{ThemeResource SystemColorButtonFaceColor}"/>
                    <SolidColorBrush x:Key="GraphSettingsErrorBorderBrush" Color="Red"/>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
            <Style x:Key="TrigUnitsRadioButtonStyle" TargetType="RadioButton">
                <Setter Property="MinHeight" Value="38"/>
                <Setter Property="MinWidth" Value="90"/>
                <Setter Property="Padding" Value="4,0"/>
                <Setter Property="FocusVisualMargin" Value="0"/>
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="RadioButton">
                            <Grid Name="LayoutRoot" Background="{ThemeResource ToggleButtonBackground}">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="PointerOver">
                                            <VisualState.Setters>
                                                <Setter Target="LayoutRoot.Background" Value="{ThemeResource ToggleButtonBackgroundPointerOver}"/>
                                                <Setter Target="AccessibilityBorder.BorderBrush" Value="{ThemeResource ToggleButtonBorderBrushPointerOver}"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="Pressed">
                                            <VisualState.Setters>
                                                <Setter Target="LayoutRoot.Background" Value="{ThemeResource ToggleButtonBackgroundPressed}"/>
                                                <Setter Target="AccessibilityBorder.BorderBrush" Value="{ThemeResource ToggleButtonBorderBrushPressed}"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="CheckStates">
                                        <VisualState x:Name="Checked">
                                            <VisualState.Setters>
                                                <Setter Target="SelectedBackgroundRectangle.Opacity" Value="1"/>
                                                <Setter Target="ContentPresenter.Foreground" Value="{ThemeResource ToggleButtonForegroundChecked}"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="Unchecked"/>
                                        <VisualState x:Name="Indeterminate"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border Name="AccessibilityBorder"
                                        BorderBrush="{ThemeResource ToggleButtonBorderBrush}"
                                        BorderThickness="1"/>
                                <Rectangle Name="SelectedBackgroundRectangle"
                                           Fill="{ThemeResource ToggleButtonBackgroundChecked}"
                                           Opacity="0"/>
                                <ContentPresenter Name="ContentPresenter"
                                                  Grid.Column="1"
                                                  Margin="{TemplateBinding Padding}"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  Foreground="{TemplateBinding Foreground}"
                                                  AutomationProperties.AccessibilityView="Raw"
                                                  Content="{TemplateBinding Content}"
                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                  ContentTransitions="{TemplateBinding ContentTransitions}"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="SubTitleTextBoxStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="16"/>
                <Setter Property="FontWeight" Value="Medium"/>
            </Style>

            <Style x:Key="ErrorTextBoxStyle" TargetType="TextBox">
                <Setter Property="BorderBrush" Value="{ThemeResource GraphSettingsErrorBorderBrush}"/>
                <Setter Property="Background" Value="{ThemeResource GraphSettingsErrorBackgroundBrush}"/>
            </Style>
            <DataTemplate x:Key="XYTextBoxHeaderTemplate" x:DataType="x:String">
                <TextBlock FontSize="14" Text="{x:Bind}"/>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <StackPanel Margin="4,0,4,4">
            <TextBlock x:Name="GraphOptionsHeading"
                       x:Uid="GraphOptionsHeading"
                       FontSize="20"
                       FontWeight="Medium"
                       AutomationProperties.HeadingLevel="Level1"/>
            <TextBlock x:Name="GridHeading"
                       x:Uid="GridHeading"
                       Margin="0,12,0,6"
                       Style="{StaticResource SubTitleTextBoxStyle}"
                       AutomationProperties.HeadingLevel="Level2"/>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="10"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBox x:Name="SettingsXMin"
                         x:Uid="GraphSettingsXMin"
                         MaxWidth="160"
                         Style="{x:Bind SelectTextBoxStyle(ViewModel.XError, ViewModel.XMinError), Mode=OneWay}"
                         HeaderTemplate="{StaticResource XYTextBoxHeaderTemplate}"
                         PreviewKeyDown="GridSettingsTextBox_PreviewKeyDown"
                         Text="{x:Bind ViewModel.XMin, Mode=TwoWay}"/>
                <TextBox x:Name="SettingsXMax"
                         x:Uid="GraphSettingsXMax"
                         Grid.Column="2"
                         MaxWidth="160"
                         Style="{x:Bind SelectTextBoxStyle(ViewModel.XError, ViewModel.XMaxError), Mode=OneWay}"
                         HeaderTemplate="{StaticResource XYTextBoxHeaderTemplate}"
                         PreviewKeyDown="GridSettingsTextBox_PreviewKeyDown"
                         Text="{x:Bind ViewModel.XMax, Mode=TwoWay}"/>

                <TextBox x:Name="SettingsYMin"
                         x:Uid="GraphSettingsYMin"
                         Grid.Row="2"
                         MaxWidth="160"
                         Style="{x:Bind SelectTextBoxStyle(ViewModel.YError, ViewModel.YMinError), Mode=OneWay}"
                         HeaderTemplate="{StaticResource XYTextBoxHeaderTemplate}"
                         PreviewKeyDown="GridSettingsTextBox_PreviewKeyDown"
                         Text="{x:Bind ViewModel.YMin, Mode=TwoWay}"/>
                <TextBox x:Name="SettingsYMax"
                         x:Uid="GraphSettingsYMax"
                         Grid.Row="2"
                         Grid.Column="2"
                         MaxWidth="160"
                         Style="{x:Bind SelectTextBoxStyle(ViewModel.YError, ViewModel.YMaxError), Mode=OneWay}"
                         HeaderTemplate="{StaticResource XYTextBoxHeaderTemplate}"
                         PreviewKeyDown="GridSettingsTextBox_PreviewKeyDown"
                         Text="{x:Bind ViewModel.YMax, Mode=TwoWay}"/>
            </Grid>

            <TextBlock x:Name="UnitsHeading"
                       x:Uid="UnitsHeading"
                       Margin="0,16,0,6"
                       Style="{StaticResource SubTitleTextBoxStyle}"
                       AutomationProperties.HeadingLevel="Level2"/>

            <StackPanel Orientation="Horizontal">
                <RadioButton x:Name="Radians"
                             x:Uid="TrigModeRadians"
                             Style="{StaticResource TrigUnitsRadioButtonStyle}"
                             IsChecked="{x:Bind ViewModel.TrigModeRadians, Mode=TwoWay}"/>
                <RadioButton x:Name="Degrees"
                             x:Uid="TrigModeDegrees"
                             Margin="1,0"
                             Style="{StaticResource TrigUnitsRadioButtonStyle}"
                             IsChecked="{x:Bind ViewModel.TrigModeDegrees, Mode=TwoWay}"/>
                <RadioButton x:Name="Gradians"
                             x:Uid="TrigModeGradians"
                             Style="{StaticResource TrigUnitsRadioButtonStyle}"
                             IsChecked="{x:Bind ViewModel.TrigModeGradians, Mode=TwoWay}"/>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>
