<!--
    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.Profiles_Base"
      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:Microsoft.Terminal.Settings.Editor"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:model="using:Microsoft.Terminal.Settings.Model"
      xmlns:mtu="using:Microsoft.Terminal.UI"
      xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
      mc:Ignorable="d">

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

    <!--  Use a Grid instead of a StackPanel. StackPanel suppresses the inner ScrollViewer.  -->
    <Grid MaxWidth="{StaticResource StandardControlMaxWidth}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock x:Uid="Profile_BaseLayerDisclaimer"
                   Grid.Row="0"
                   Style="{StaticResource DisclaimerStyle}"
                   Visibility="{x:Bind Profile.IsBaseLayer}" />
        <StackPanel Grid.Row="1"
                    Style="{StaticResource SettingsStackStyle}">

            <!--  Name  -->
            <!--
                NOTE: Has/Clear is not bound because we don't want the reset button & override text to appear.
                Additionally, the JSON stubs generated by auto-generated profiles come with a name,
                so the name will always be overridden.
            -->
            <local:SettingContainer x:Uid="Profile_Name"
                                    CurrentValue="{x:Bind Profile.Name, Mode=OneWay}"
                                    Style="{StaticResource ExpanderSettingContainerStyle}"
                                    Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(Profile.IsBaseLayer), Mode=OneWay}">
                <TextBox Style="{StaticResource TextBoxSettingStyle}"
                         Text="{x:Bind Profile.Name, Mode=TwoWay}" />
            </local:SettingContainer>

            <!--  Commandline  -->
            <local:SettingContainer x:Name="CommandlineContainer"
                                    x:Uid="Profile_Commandline"
                                    ClearSettingValue="{x:Bind Profile.ClearCommandline}"
                                    CurrentValue="{x:Bind Profile.Commandline, Mode=OneWay}"
                                    HasSettingValue="{x:Bind Profile.HasCommandline, Mode=OneWay}"
                                    SettingOverrideSource="{x:Bind Profile.CommandlineOverrideSource, Mode=OneWay}"
                                    Style="{StaticResource ExpanderSettingContainerStyle}"
                                    Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(Profile.IsBaseLayer), Mode=OneWay}">
                <StackPanel>
                    <TextBox x:Uid="Profile_CommandlineBox"
                             IsSpellCheckEnabled="False"
                             Style="{StaticResource TextBoxSettingStyle}"
                             Text="{x:Bind Profile.Commandline, Mode=TwoWay}" />
                    <Button x:Uid="Profile_CommandlineBrowse"
                            Margin="0,8,0,0"
                            Click="Commandline_Click"
                            Style="{StaticResource BrowseButtonStyle}" />
                </StackPanel>
            </local:SettingContainer>

            <!--  Starting Directory  -->
            <local:SettingContainer x:Name="StartingDirectoryContainer"
                                    x:Uid="Profile_StartingDirectory"
                                    ClearSettingValue="{x:Bind Profile.ClearStartingDirectory}"
                                    CurrentValue="{x:Bind Profile.CurrentStartingDirectoryPreview, Mode=OneWay}"
                                    HasSettingValue="{x:Bind Profile.HasStartingDirectory, Mode=OneWay}"
                                    SettingOverrideSource="{x:Bind Profile.StartingDirectoryOverrideSource, Mode=OneWay}"
                                    Style="{StaticResource ExpanderSettingContainerStyle}">
                <StackPanel Orientation="Vertical">
                    <TextBox x:Uid="Profile_StartingDirectoryBox"
                             IsEnabled="{x:Bind mtu:Converters.InvertBoolean(Profile.UseParentProcessDirectory), Mode=OneWay}"
                             IsSpellCheckEnabled="False"
                             Style="{StaticResource TextBoxSettingStyle}"
                             Text="{x:Bind Profile.StartingDirectory, Mode=TwoWay}" />
                    <StackPanel Orientation="Horizontal">
                        <Button x:Name="StartingDirectoryBrowse"
                                x:Uid="Profile_StartingDirectoryBrowse"
                                Margin="0,12,12,0"
                                Click="StartingDirectory_Click"
                                IsEnabled="{x:Bind mtu:Converters.InvertBoolean(Profile.UseParentProcessDirectory), Mode=OneWay}"
                                Style="{StaticResource BrowseButtonStyle}" />
                        <CheckBox x:Name="StartingDirectoryUseParentCheckbox"
                                  x:Uid="Profile_StartingDirectoryUseParentCheckbox"
                                  Margin="0,4,0,0"
                                  IsChecked="{x:Bind Profile.UseParentProcessDirectory, Mode=TwoWay}" />
                    </StackPanel>
                </StackPanel>
            </local:SettingContainer>

            <!--  Icon  -->
            <local:SettingContainer x:Uid="Profile_Icon"
                                    ClearSettingValue="{x:Bind Profile.ClearIcon}"
                                    CurrentValueAccessibleName="{x:Bind Profile.LocalizedIcon, Mode=OneWay}"
                                    HasSettingValue="{x:Bind Profile.HasIcon, Mode=OneWay}"
                                    SettingOverrideSource="{x:Bind Profile.IconOverrideSource, Mode=OneWay}"
                                    Style="{StaticResource ExpanderSettingContainerStyleWithComplexPreview}">
                <local:SettingContainer.CurrentValue>
                    <Grid>
                        <ContentControl Width="16"
                                        Height="16"
                                        Content="{x:Bind Profile.IconPreview, Mode=OneWay}"
                                        IsTabStop="False"
                                        Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(Profile.UsingNoIcon), Mode=OneWay}" />
                        <TextBlock Margin="0,0,0,0"
                                   HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   FontFamily="Segoe UI, Segoe Fluent Icons, Segoe MDL2 Assets"
                                   Style="{StaticResource SettingsPageItemDescriptionStyle}"
                                   Text="{x:Bind Profile.LocalizedIcon, Mode=OneWay}"
                                   Visibility="{x:Bind Profile.UsingNoIcon, Mode=OneWay}" />
                    </Grid>
                </local:SettingContainer.CurrentValue>
                <local:SettingContainer.Content>
                    <Grid ColumnSpacing="12">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="auto" />
                        </Grid.ColumnDefinitions>

                        <!--  Icon Type  -->
                        <ComboBox x:Uid="Profile_IconType"
                                  Grid.Column="0"
                                  ItemsSource="{x:Bind Profile.IconTypes}"
                                  SelectedItem="{x:Bind Profile.CurrentIconType, Mode=TwoWay}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate x:DataType="local:EnumEntry">
                                    <TextBlock Text="{x:Bind EnumName}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>

                        <!--  Built-In Icon  -->
                        <AutoSuggestBox x:Uid="Profile_BuiltInIcon"
                                        Grid.Column="1"
                                        GotFocus="BuiltInIconPicker_GotFocus"
                                        ItemsSource="{x:Bind FilteredBuiltInIconList, Mode=OneWay}"
                                        QuerySubmitted="BuiltInIconPicker_QuerySubmitted"
                                        Text="{x:Bind Profile.CurrentBuiltInIcon.EnumName, Mode=OneWay}"
                                        TextBoxStyle="{StaticResource TextBoxSettingStyle}"
                                        TextChanged="BuiltInIconPicker_TextChanged"
                                        Visibility="{x:Bind Profile.UsingBuiltInIcon, Mode=OneWay}">
                            <AutoSuggestBox.ItemTemplate>
                                <DataTemplate x:DataType="local:EnumEntry">
                                    <Grid ColumnSpacing="12">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="16" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>

                                        <IconSourceElement Grid.Column="0"
                                                           Width="16"
                                                           Height="16"
                                                           IconSource="{x:Bind local:Profiles_Base.BuiltInIconConverter(EnumValue), Mode=OneTime}" />
                                        <TextBlock Grid.Column="1"
                                                   Text="{x:Bind EnumName}" />
                                    </Grid>
                                </DataTemplate>
                            </AutoSuggestBox.ItemTemplate>
                        </AutoSuggestBox>

                        <!--  Image (File) Icon  -->
                        <TextBox x:Uid="Profile_IconBox"
                                 Grid.Column="1"
                                 MaxWidth="Infinity"
                                 HorizontalAlignment="Stretch"
                                 FontFamily="Segoe UI, Segoe Fluent Icons, Segoe MDL2 Assets"
                                 IsSpellCheckEnabled="False"
                                 Style="{StaticResource TextBoxSettingStyle}"
                                 Text="{x:Bind Profile.IconPath, Mode=TwoWay}"
                                 Visibility="{x:Bind Profile.UsingImageIcon, Mode=OneWay}" />
                        <Button x:Uid="Profile_IconBrowse"
                                Grid.Column="2"
                                Margin="0"
                                VerticalAlignment="Top"
                                Click="Icon_Click"
                                Style="{StaticResource BrowseButtonStyle}"
                                Visibility="{x:Bind Profile.UsingImageIcon, Mode=OneWay}" />

                        <!--  Emoji Icon  -->
                        <TextBox x:Uid="Profile_IconEmojiBox"
                                 Grid.Column="1"
                                 MaxWidth="Infinity"
                                 FontFamily="Segoe UI, Segoe Fluent Icons, Segoe MDL2 Assets"
                                 IsSpellCheckEnabled="False"
                                 Style="{StaticResource TextBoxSettingStyle}"
                                 Text="{x:Bind Profile.CurrentEmojiIcon, Mode=TwoWay}"
                                 Visibility="{x:Bind Profile.UsingEmojiIcon, Mode=OneWay}" />
                    </Grid>
                </local:SettingContainer.Content>
            </local:SettingContainer>

            <!--  Tab Title  -->
            <local:SettingContainer x:Uid="Profile_TabTitle"
                                    ClearSettingValue="{x:Bind Profile.ClearTabTitle}"
                                    CurrentValue="{x:Bind Profile.TabTitlePreview, Mode=OneWay}"
                                    HasSettingValue="{x:Bind Profile.HasTabTitle, Mode=OneWay}"
                                    SettingOverrideSource="{x:Bind Profile.TabTitleOverrideSource, Mode=OneWay}"
                                    Style="{StaticResource ExpanderSettingContainerStyle}">
                <TextBox Style="{StaticResource TextBoxSettingStyle}"
                         Text="{x:Bind Profile.TabTitle, Mode=TwoWay}" />
            </local:SettingContainer>

            <!--  Tab Color  -->
            <local:SettingContainer x:Name="TabColor"
                                    x:Uid="Profile_TabColor"
                                    ClearSettingValue="{x:Bind Profile.ClearTabColor}"
                                    CurrentValue="{x:Bind Profile.TabColorPreview, Mode=OneWay}"
                                    CurrentValueAccessibleName="{x:Bind Profile.TabColorPreview, Converter={StaticResource ColorToStringConverter}, Mode=OneWay}"
                                    CurrentValueTemplate="{StaticResource ColorPreviewTemplate}"
                                    HasSettingValue="{x:Bind Profile.HasTabColor, Mode=OneWay}"
                                    SettingOverrideSource="{x:Bind Profile.TabColorOverrideSource, Mode=OneWay}"
                                    Style="{StaticResource ExpanderSettingContainerStyleWithComplexPreview}">
                <local:NullableColorPicker x:Uid="Profile_TabColor_NullableColorPicker"
                                           ColorSchemeVM="{x:Bind Profile.DefaultAppearance.CurrentColorScheme, Mode=OneWay}"
                                           CurrentColor="{x:Bind Profile.TabColor, Mode=TwoWay}"
                                           NullColorPreview="{x:Bind Profile.TabThemeColorPreview, Mode=OneWay}" />
            </local:SettingContainer>

            <!--  Elevate  -->
            <local:SettingContainer x:Uid="Profile_Elevate"
                                    ClearSettingValue="{x:Bind Profile.ClearElevate}"
                                    HasSettingValue="{x:Bind Profile.HasElevate, Mode=OneWay}"
                                    SettingOverrideSource="{x:Bind Profile.ElevateOverrideSource, Mode=OneWay}">
                <ToggleSwitch IsOn="{x:Bind Profile.Elevate, Mode=TwoWay}"
                              Style="{StaticResource ToggleSwitchInExpanderStyle}" />
            </local:SettingContainer>

            <!--  Hidden  -->
            <local:SettingContainer x:Uid="Profile_Hidden"
                                    Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(Profile.IsBaseLayer), Mode=OneWay}">
                <ToggleSwitch IsOn="{x:Bind Profile.Hidden, Mode=TwoWay}"
                              Style="{StaticResource ToggleSwitchInExpanderStyle}" />
            </local:SettingContainer>

            <TextBlock x:Uid="Profile_AdditionalSettingsHeader"
                       Margin="0,32,0,4"
                       Style="{StaticResource TextBlockSubHeaderStyle}" />

            <Button x:Name="AppearanceNavigator"
                    Click="Appearance_Click"
                    Style="{StaticResource NavigatorButtonStyle}" />
            <Button x:Name="TerminalNavigator"
                    Click="Terminal_Click"
                    Style="{StaticResource NavigatorButtonStyle}" />
            <Button x:Name="AdvancedNavigator"
                    Click="Advanced_Click"
                    Style="{StaticResource NavigatorButtonStyle}" />
            <!--  Delete Button  -->
            <Border MaxWidth="{StaticResource StandardControlMaxWidth}">
                <Button x:Name="DeleteButton"
                        Margin="{StaticResource StandardControlMargin}"
                        Style="{StaticResource DeleteButtonStyle}"
                        Visibility="{x:Bind Profile.CanDeleteProfile}">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <FontIcon FontSize="{StaticResource StandardIconSize}"
                                      Glyph="&#xE74D;" />
                            <TextBlock x:Uid="Profile_DeleteButton"
                                       Margin="8,0,0,0" />
                        </StackPanel>
                    </Button.Content>
                    <Button.Flyout>
                        <Flyout>
                            <StackPanel>
                                <TextBlock x:Uid="Profile_DeleteConfirmationMessage"
                                           Style="{StaticResource CustomFlyoutTextStyle}" />
                                <Button x:Uid="Profile_DeleteConfirmationButton"
                                        Click="DeleteConfirmation_Click" />
                            </StackPanel>
                        </Flyout>
                    </Button.Flyout>
                </Button>
            </Border>
        </StackPanel>
    </Grid>
</Page>
