<!--
    Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
    the MIT License. See LICENSE in the project root for license information.
-->
<Page x:Class="Microsoft.Terminal.Settings.Editor.Launch"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:SettingsModel="using:Microsoft.Terminal.Settings.Model"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="using:Microsoft.Terminal.Settings.Editor"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
      mc:Ignorable="d">

    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="CommonResources.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="EnumComboBoxTemplate"
                          x:DataType="local:EnumEntry">
                <TextBlock Text="{x:Bind EnumName, Mode=OneWay}" />
            </DataTemplate>
            <SettingsModel:IconPathConverter x:Key="IconSourceConverter" />
            <Style x:Key="LaunchSizeNumberBoxStyle"
                   BasedOn="{StaticResource NumberBoxSettingStyle}"
                   TargetType="muxc:NumberBox">
                <Setter Property="SmallChange" Value="1" />
                <Setter Property="LargeChange" Value="10" />
                <Setter Property="Minimum" Value="1" />
            </Style>
            <Style x:Key="LaunchPositionNumberBoxStyle"
                   BasedOn="{StaticResource NumberBoxSettingStyle}"
                   TargetType="muxc:NumberBox">
                <Setter Property="SmallChange" Value="1" />
                <Setter Property="LargeChange" Value="10" />
                <Setter Property="Minimum" Value="-2147483648" />
                <Setter Property="Maximum" Value="2147483647" />
            </Style>
        </ResourceDictionary>
    </Page.Resources>

    <ScrollViewer ViewChanging="ViewChanging">
        <StackPanel>
            <StackPanel Style="{StaticResource SettingsStackStyle}">
                <!--  Default Profile  -->
                <local:SettingContainer x:Uid="Globals_DefaultProfile">
                    <ComboBox x:Name="DefaultProfile"
                              ItemsSource="{x:Bind ViewModel.DefaultProfiles}"
                              SelectedItem="{x:Bind ViewModel.CurrentDefaultProfile, Mode=TwoWay}"
                              Style="{StaticResource ComboBoxSettingStyle}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate x:DataType="SettingsModel:Profile">
                                <Grid HorizontalAlignment="Stretch"
                                      ColumnSpacing="8">

                                    <Grid.ColumnDefinitions>
                                        <!--  icon  -->
                                        <ColumnDefinition Width="16" />
                                        <!--  profile name  -->
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <IconSourceElement Grid.Column="0"
                                                       Width="16"
                                                       Height="16"
                                                       IconSource="{x:Bind Icon, Converter={StaticResource IconSourceConverter}}" />

                                    <TextBlock Grid.Column="1"
                                               Text="{x:Bind Name}" />

                                </Grid>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </local:SettingContainer>

                <!--  Default Terminal  -->
                <local:SettingContainer x:Name="DefaultTerminalDropdown"
                                        x:Uid="Globals_DefaultTerminal"
                                        x:Load="false">
                    <ComboBox x:Name="DefaultTerminal"
                              ItemsSource="{x:Bind ViewModel.DefaultTerminals}"
                              SelectedItem="{x:Bind ViewModel.CurrentDefaultTerminal, Mode=TwoWay}"
                              Style="{StaticResource ComboBoxSettingStyle}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate x:DataType="SettingsModel:DefaultTerminal">
                                <Grid HorizontalAlignment="Stretch"
                                      VerticalAlignment="Stretch"
                                      ColumnSpacing="8">

                                    <Grid.ColumnDefinitions>
                                        <!--  icon  -->
                                        <ColumnDefinition Width="auto" />
                                        <!--  terminal name and author  -->
                                        <ColumnDefinition Width="auto" />
                                        <!--  version  -->
                                        <ColumnDefinition Width="auto" />
                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>
                                        <!--  terminal name  -->
                                        <RowDefinition Height="auto" />
                                        <!--  author and version  -->
                                        <RowDefinition Height="auto" />
                                    </Grid.RowDefinitions>

                                    <IconSourceElement Grid.Row="0"
                                                       Grid.RowSpan="2"
                                                       Grid.Column="0"
                                                       Width="24"
                                                       Height="24"
                                                       VerticalAlignment="Center"
                                                       IconSource="{x:Bind Icon, Converter={StaticResource IconSourceConverter}}" />

                                    <TextBlock Grid.Row="0"
                                               Grid.Column="1"
                                               Grid.ColumnSpan="2"
                                               AutomationProperties.AccessibilityView="Raw"
                                               Text="{x:Bind Name}" />

                                    <TextBlock Grid.Row="1"
                                               Grid.Column="1"
                                               AutomationProperties.AccessibilityView="Raw"
                                               Style="{ThemeResource SecondaryTextBlockStyle}"
                                               Text="{x:Bind Author}"
                                               Visibility="{x:Bind local:Converters.StringNotEmptyToVisibility(Author)}" />

                                    <TextBlock Grid.Row="1"
                                               Grid.Column="2"
                                               AutomationProperties.AccessibilityView="Raw"
                                               Style="{ThemeResource SecondaryTextBlockStyle}"
                                               Text="{x:Bind Version}"
                                               Visibility="{x:Bind local:Converters.StringNotEmptyToVisibility(Version)}" />

                                </Grid>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </local:SettingContainer>

                <!--  Start on User Login  -->
                <local:SettingContainer x:Uid="Globals_StartOnUserLogin">
                    <ToggleSwitch IsOn="{x:Bind ViewModel.StartOnUserLogin, Mode=TwoWay}"
                                  Style="{StaticResource ToggleSwitchInExpanderStyle}" />
                </local:SettingContainer>

                <!--  First Window Behavior  -->
                <local:SettingContainer x:Uid="Globals_FirstWindowPreference">
                    <ComboBox AutomationProperties.AccessibilityView="Content"
                              ItemTemplate="{StaticResource EnumComboBoxTemplate}"
                              ItemsSource="{x:Bind ViewModel.FirstWindowPreferenceList}"
                              SelectedItem="{x:Bind ViewModel.CurrentFirstWindowPreference, Mode=TwoWay}"
                              Style="{StaticResource ComboBoxSettingStyle}" />
                </local:SettingContainer>

                <!--  Windowing Behavior  -->
                <local:SettingContainer x:Uid="Globals_WindowingBehavior">
                    <ComboBox AutomationProperties.AccessibilityView="Content"
                              ItemTemplate="{StaticResource EnumComboBoxTemplate}"
                              ItemsSource="{x:Bind ViewModel.WindowingBehaviorList}"
                              SelectedItem="{x:Bind ViewModel.CurrentWindowingBehavior, Mode=TwoWay}"
                              Style="{StaticResource ComboBoxSettingStyle}" />
                </local:SettingContainer>

                <local:SettingContainer x:Uid="Globals_LaunchSize"
                                        Style="{StaticResource ExpanderSettingContainerStyle}">
                    <Grid ColumnSpacing="10"
                          RowSpacing="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBlock x:Uid="Globals_InitialCols"
                                   Grid.Row="0"
                                   Grid.Column="0"
                                   VerticalAlignment="Center"
                                   Style="{StaticResource SettingsPageItemHeaderStyle}" />
                        <muxc:NumberBox x:Uid="Globals_InitialColsBox"
                                        Grid.Row="0"
                                        Grid.Column="1"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource LaunchSizeNumberBoxStyle}"
                                        Value="{x:Bind ViewModel.InitialCols, Mode=TwoWay}" />
                        <TextBlock x:Uid="Globals_InitialRows"
                                   Grid.Row="1"
                                   Grid.Column="0"
                                   VerticalAlignment="Center"
                                   Style="{StaticResource SettingsPageItemHeaderStyle}" />
                        <muxc:NumberBox x:Uid="Globals_InitialRowsBox"
                                        Grid.Row="1"
                                        Grid.Column="1"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource LaunchSizeNumberBoxStyle}"
                                        Value="{x:Bind ViewModel.InitialRows, Mode=TwoWay}" />
                    </Grid>
                </local:SettingContainer>

                <!--  Launch Parameters  -->
                <local:SettingContainer x:Uid="Globals_LaunchParameters"
                                        CurrentValue="{x:Bind ViewModel.LaunchParametersCurrentValue, Mode=OneWay}"
                                        Style="{StaticResource ExpanderSettingContainerStyle}">
                    <Grid RowSpacing="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBlock x:Uid="Globals_LaunchModeSetting"
                                   Grid.Row="0"
                                   Grid.Column="0"
                                   VerticalAlignment="Center" />
                        <ComboBox x:Name="LaunchModeComboBox"
                                  Grid.Row="0"
                                  Grid.Column="1"
                                  MinWidth="240"
                                  AutomationProperties.AccessibilityView="Content"
                                  ItemTemplate="{StaticResource EnumComboBoxTemplate}"
                                  ItemsSource="{x:Bind ViewModel.LaunchModeList}"
                                  SelectedItem="{x:Bind ViewModel.CurrentLaunchMode, Mode=TwoWay}"
                                  Style="{StaticResource ComboBoxSettingStyle}" />
                        <TextBlock x:Uid="Globals_LaunchPosition"
                                   Grid.Row="1"
                                   Grid.Column="0"
                                   VerticalAlignment="Center" />
                        <Grid Grid.Row="1"
                              Grid.Column="1"
                              ColumnSpacing="4">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <!--  Match the width of these NumberBoxes to the Width of the LaunchModeComboBox above minus the Grid's ColumnSpacing  -->
                            <muxc:NumberBox x:Name="PosXBox"
                                            x:Uid="Globals_InitialPosXBox"
                                            Grid.Row="0"
                                            Grid.Column="0"
                                            Width="118"
                                            IsEnabled="{x:Bind local:Converters.InvertBoolean(ViewModel.UseDefaultLaunchPosition), Mode=OneWay}"
                                            Style="{StaticResource LaunchPositionNumberBoxStyle}"
                                            Value="{x:Bind ViewModel.InitialPosX, Mode=TwoWay}" />
                            <muxc:NumberBox x:Name="PosYBox"
                                            x:Uid="Globals_InitialPosYBox"
                                            Grid.Row="0"
                                            Grid.Column="1"
                                            Width="118"
                                            IsEnabled="{x:Bind local:Converters.InvertBoolean(ViewModel.UseDefaultLaunchPosition), Mode=OneWay}"
                                            Style="{StaticResource LaunchPositionNumberBoxStyle}"
                                            Value="{x:Bind ViewModel.InitialPosY, Mode=TwoWay}" />
                            <CheckBox x:Name="UseDefaultLaunchPositionCheckbox"
                                      x:Uid="Globals_DefaultLaunchPositionCheckbox"
                                      Grid.Row="1"
                                      Grid.Column="0"
                                      Grid.ColumnSpan="2"
                                      IsChecked="{x:Bind ViewModel.UseDefaultLaunchPosition, Mode=TwoWay}" />
                        </Grid>
                        <TextBlock x:Uid="Globals_CenterOnLaunch"
                                   Grid.Row="2"
                                   Grid.Column="0"
                                   VerticalAlignment="Center" />
                        <ToggleSwitch x:Name="CenterOnLaunchToggle"
                                      Grid.Row="2"
                                      Grid.Column="1"
                                      IsOn="{x:Bind ViewModel.CenterOnLaunch, Mode=TwoWay}"
                                      Style="{StaticResource ToggleSwitchInExpanderStyle}" />
                    </Grid>
                </local:SettingContainer>
            </StackPanel>
        </StackPanel>
    </ScrollViewer>
</Page>
