<Page
    x:Class="NixExampleWinUI.Views.SettingsPage"
    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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:helpers="using:NixExampleWinUI.Helpers"
    xmlns:xaml="using:Microsoft.UI.Xaml"
    mc:Ignorable="d">
    <Page.Resources>
        <helpers:EnumToBooleanConverter x:Key="EnumToBooleanConverter"/>
        <helpers:NullableBooleanToBooleanConverter x:Key="NullableBooleanToBooleanConverter"/>
        <helpers:NullableBooleanToVisibilityConverter x:Key="NullableBooleanToVisibilityConverter"/>
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ScrollViewer Grid.Row="0"
                      VerticalScrollBarVisibility="Auto"
                      VerticalScrollMode="Enabled">
            <StackPanel x:Name="ContentArea">
                <StackPanel x:Name="LicenseArea"
                            Orientation="Vertical">
                    <TextBlock x:Uid="Settings_License"
                               Style="{ThemeResource SubtitleTextBlockStyle}"
                               Margin="{StaticResource SmallTopBottomMargin}"/>
                    <StackPanel x:Name="LicenseButtonsArea"
                                Orientation="Horizontal">
                        <Button x:Uid="Settings_DisplayLicenseInfo"
                                x:Name="LicenseInfoButton"
                                MinWidth="150"
                                Margin="{StaticResource SmallRightMargin}"
                                Click="LicenseInfoButton_Click"/>
                        <Button x:Uid="Settings_ChangeLicense"
                                x:Name="LicenseChangeButton"
                                Margin="{StaticResource SmallRightMargin}"
                                Click="LicenseChangeButton_Click"/>
                    </StackPanel>
                </StackPanel>
                
                <TextBlock x:Uid="Settings_Personalization" 
                           Style="{ThemeResource SubtitleTextBlockStyle}"
                           Margin="{StaticResource SmallTopMargin}"/>
                <StackPanel Margin="{StaticResource SmallTopBottomMargin}">

                    <TextBlock x:Uid="Settings_Theme" />

                    <StackPanel Margin="{StaticResource XSmallTopMargin}">
                        <RadioButton x:Uid="Settings_Theme_Light"
                                     Command="{x:Bind ViewModel.SwitchThemeCommand}"
                                     IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Light, Mode=OneWay}"
                                     FontSize="15"
                                     GroupName="AppTheme">
                            <RadioButton.CommandParameter>
                                <xaml:ElementTheme>Light</xaml:ElementTheme>
                            </RadioButton.CommandParameter>
                        </RadioButton>
                        <RadioButton x:Uid="Settings_Theme_Dark"
                                     Command="{x:Bind ViewModel.SwitchThemeCommand}"
                                     IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Dark, Mode=OneWay}"
                                     FontSize="15"
                                     GroupName="AppTheme">
                            <RadioButton.CommandParameter>
                                <xaml:ElementTheme>Dark</xaml:ElementTheme>
                            </RadioButton.CommandParameter>
                        </RadioButton>
                        <RadioButton x:Uid="Settings_Theme_Default"
                                     Command="{x:Bind ViewModel.SwitchThemeCommand}"
                                     IsChecked="{x:Bind ViewModel.ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Default, Mode=OneWay}"
                                     FontSize="15"
                                     GroupName="AppTheme">
                            <RadioButton.CommandParameter>
                                <xaml:ElementTheme>Default</xaml:ElementTheme>
                            </RadioButton.CommandParameter>
                        </RadioButton>
                    </StackPanel>
                </StackPanel>
                
                <StackPanel x:Name="DeviceArea"
                            Orientation="Vertical"
                            Visibility="{x:Bind ViewModel.IsDeviceInfoAvailable, Mode=OneWay, Converter={StaticResource NullableBooleanToVisibilityConverter}}">
                    <TextBlock x:Uid="Settings_Device"
                               Style="{ThemeResource SubtitleTextBlockStyle}" />

                    <ToggleSwitch x:Uid="Settings_RgbFeedback"
                                  x:Name="RgbToggle"
                                  Visibility="{x:Bind ViewModel.Device.SupportsRgbFeedback, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                                  IsOn="{x:Bind ViewModel.IsRgbEnabled, Mode=OneWay}"
                                  Toggled="RgbToggle_Toggled"/>
                    <ToggleSwitch x:Uid="Settings_HapticFeedback"
                                  x:Name="HapticToggle"
                                  Visibility="{x:Bind ViewModel.Device.SupportsHapticFeedback, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                                  IsOn="{x:Bind ViewModel.IsHapticEnabled, Mode=OneWay, Converter={StaticResource NullableBooleanToBooleanConverter}}"
                                  Toggled="HapticToggle_Toggled"/>
                    <ToggleSwitch x:Uid="Settings_TileNormalization"
                                  x:Name="TileNormalizationToggle"
                                  Visibility="{x:Bind ViewModel.Device.SupportsFieldCalibration, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                                  IsOn="{x:Bind ViewModel.IsTileEnabled, Mode=OneWay, Converter={StaticResource NullableBooleanToBooleanConverter}}"
                                  Toggled="TileNormalizationToggle_Toggled"/>
                    <ToggleSwitch x:Uid="Settings_TemperatureCompensation"
                                  x:Name="TemperatureCompensationToggle"
                                  Visibility="{x:Bind ViewModel.Device.SupportsTemperatureCompensation, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                                  IsOn="{x:Bind ViewModel.IsTempCompEnabled, Mode=OneWay, Converter={StaticResource NullableBooleanToBooleanConverter}}"
                                  Toggled="TemperatureCompensationToggle_Toggled"/>
                    <Button x:Uid="Settings_Calibrate"
                            x:Name="CalibrateButton"
                            MinWidth="150"
                            Margin="{StaticResource SmallTopMargin}"
                            Visibility="{x:Bind ViewModel.Device.SupportsFieldCalibration, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                            Click="CalibrateButton_Click"/>
                    <Button x:Uid="Settings_DeviceDetails"
                            x:Name="DeviceDetailsButton"
                            MinWidth="150"
                            Margin="{StaticResource SmallTopMargin}"
                            Click="DeviceDetailsButton_Click"/>
                    <Button x:Uid="Settings_Disconnect"
                            x:Name="DisconnectButton"
                            MinWidth="150"
                            Margin="{StaticResource SmallTopBottomMargin}">
                        <Button.Flyout>
                            <Flyout>
                                <StackPanel>
                                    <TextBlock x:Uid="Settings_DisconnectConfirmText"
                                               Style="{ThemeResource BaseTextBlockStyle}"/>
                                    <Button x:Uid="Settings_DisconnectConfirmButton"
                                            x:Name="DisconnectConfirmButton"
                                            Margin="{StaticResource SmallTopMargin}"
                                            Click="DisconnectConfirmButton_Click"/>
                                </StackPanel>
                            </Flyout>
                        </Button.Flyout>
                    </Button>
                </StackPanel>                

                <StackPanel>
                    <TextBlock x:Uid="Settings_About" 
                               Style="{ThemeResource SubtitleTextBlockStyle}"
                               Margin="{StaticResource SmallTopBottomMargin}"/>
                    <TextBlock Text="{x:Bind ViewModel.VersionDescription, Mode=OneWay}"
                               Margin="{StaticResource XSmallTopMargin}"
                               Style="{ThemeResource BodyTextBlockStyle}" />

                    <TextBlock x:Uid="Settings_AboutDescription"
                               Margin="{StaticResource XSmallTopMargin}"
                               Style="{ThemeResource BodyTextBlockStyle}" />
                    <HyperlinkButton x:Uid="SettingsPage_SdkDocLink" 
                                     Margin="{StaticResource SettingsPageHyperlinkButtonMargin}" />
                </StackPanel>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>
