<!--
    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.MainPage"
      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:mtu="using:Microsoft.Terminal.UI"
      xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
      xmlns:tsm="using:Microsoft.Terminal.Settings.Model"
      mc:Ignorable="d">

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

                        <!--
                            These two values are "SolidBackgroundFillColorTertiary".
                            We can't just put those here though as
                            StaticResources, because XAML will evaluate their
                            values when the App is first loaded, and we'll
                            always use the value from the OS theme, regardless
                            of the requested theme. Kinda the same thing we've
                            had to do with TabViewBackground in the past.
                        -->

                        <ResourceDictionary x:Key="Dark">
                            <Color x:Key="SettingsPageBackground">#282828</Color>
                            <Color x:Key="SettingsPageMicaBackground">#00000000</Color>
                        </ResourceDictionary>

                        <ResourceDictionary x:Key="Light">
                            <Color x:Key="SettingsPageBackground">#F9F9F9</Color>
                            <Color x:Key="SettingsPageMicaBackground">#00000000</Color>
                        </ResourceDictionary>

                        <ResourceDictionary x:Key="HighContrast">
                            <!--  Define resources for HighContrast mode here  -->
                            <StaticResource x:Key="SettingsPageBackground"
                                            ResourceKey="SystemColorWindowBrush" />
                            <StaticResource x:Key="SettingsPageMicaBackground"
                                            ResourceKey="SystemColorWindowBrush" />
                        </ResourceDictionary>
                    </ResourceDictionary.ThemeDictionaries>
                </ResourceDictionary>

            </ResourceDictionary.MergedDictionaries>

            <SolidColorBrush x:Key="NavigationViewExpandedPaneBackground"
                             Color="Transparent" />
            <SolidColorBrush x:Key="NavigationViewContentBackground"
                             Color="Transparent" />

            <Thickness x:Key="NavigationViewContentGridBorderThickness">0</Thickness>
            <Thickness x:Key="NavigationViewMinimalContentGridBorderThickness">0</Thickness>
        </ResourceDictionary>
    </Page.Resources>

    <muxc:NavigationView x:Name="SettingsNav"
                         Background="{ThemeResource SettingsPageBackground}"
                         IsBackButtonVisible="Collapsed"
                         IsSettingsVisible="False"
                         ItemInvoked="SettingsNav_ItemInvoked"
                         Loaded="SettingsNav_Loaded"
                         TabFocusNavigation="Cycle">
        <muxc:NavigationView.Resources>
            <ResourceDictionary>
                <Thickness x:Key="NavigationViewHeaderMargin">0,4,0,0</Thickness>
            </ResourceDictionary>
        </muxc:NavigationView.Resources>
        <muxc:NavigationView.Header>
            <Grid Padding="16,0">
                <!--  Wrapping the BreadcrumbBar in a Grid to avoid the title to drift (and no longer being aligned with the content of the page) when resizing the window. It's weird, I know. I believe it has to do with https://github.com/microsoft/microsoft-ui-xaml/issues/3842 doing funky things when setting a MaxWidth  -->
                <muxc:BreadcrumbBar x:Name="NavigationBreadcrumbBar"
                                    MaxWidth="1000"
                                    ItemClicked="BreadcrumbBar_ItemClicked"
                                    ItemsSource="{x:Bind Breadcrumbs}">
                    <muxc:BreadcrumbBar.ItemTemplate>
                        <DataTemplate x:DataType="local:Breadcrumb">
                            <TextBlock Text="{x:Bind Label}" />
                        </DataTemplate>
                    </muxc:BreadcrumbBar.ItemTemplate>
                    <muxc:BreadcrumbBar.Resources>
                        <ResourceDictionary>
                            <x:Double x:Key="BreadcrumbBarItemThemeFontSize">20</x:Double>
                            <Thickness x:Key="BreadcrumbBarChevronPadding">8,4,8,0</Thickness>
                            <FontWeight x:Key="BreadcrumbBarItemFontWeight">SemiBold</FontWeight>
                            <x:Double x:Key="BreadcrumbBarChevronFontSize">16</x:Double>
                        </ResourceDictionary>
                    </muxc:BreadcrumbBar.Resources>
                </muxc:BreadcrumbBar>

            </Grid>
        </muxc:NavigationView.Header>

        <muxc:NavigationView.AutoSuggestBox>
            <AutoSuggestBox x:Name="SettingsSearchBox"
                            x:Uid="Nav_SearchBox"
                            QueryIcon="Find"
                            QuerySubmitted="SettingsSearchBox_QuerySubmitted"
                            SuggestionChosen="SettingsSearchBox_SuggestionChosen"
                            TextChanged="SettingsSearchBox_TextChanged">
                <AutoSuggestBox.ItemTemplate>
                    <DataTemplate x:DataType="local:FilteredSearchResult">
                        <Grid HorizontalAlignment="Stretch"
                              ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <ContentPresenter Grid.Column="0"
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Center"
                                              Content="{x:Bind Icon}" />
                            <StackPanel Grid.Column="1"
                                        VerticalAlignment="Center">
                                <TextBlock FontSize="{ThemeResource BodyTextBlockFontSize}"
                                           Foreground="{ThemeResource TextFillColorPrimary}"
                                           Text="{x:Bind Label}"
                                           TextTrimming="CharacterEllipsis" />
                                <TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
                                           Foreground="{ThemeResource TextFillColorSecondary}"
                                           Text="{x:Bind SecondaryLabel}"
                                           TextTrimming="CharacterEllipsis"
                                           Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SecondaryLabel)}" />
                            </StackPanel>

                            <ToolTipService.ToolTip>
                                <StackPanel>
                                    <TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
                                               Foreground="{ThemeResource TextFillColorPrimary}"
                                               Text="{x:Bind Label}" />
                                    <TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
                                               Foreground="{ThemeResource TextFillColorSecondary}"
                                               Text="{x:Bind SecondaryLabel}"
                                               Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SecondaryLabel)}" />
                                </StackPanel>
                            </ToolTipService.ToolTip>
                        </Grid>
                    </DataTemplate>
                </AutoSuggestBox.ItemTemplate>
            </AutoSuggestBox>
        </muxc:NavigationView.AutoSuggestBox>

        <muxc:NavigationView.MenuItems>
            <muxc:NavigationViewItem x:Name="LaunchNavItem"
                                     x:Uid="Nav_Launch"
                                     Tag="Launch_Nav" />

            <muxc:NavigationViewItem x:Name="InteractionNavItem"
                                     x:Uid="Nav_Interaction"
                                     Tag="Interaction_Nav" />

            <muxc:NavigationViewItem x:Name="AppearanceNavItem"
                                     x:Uid="Nav_Appearance"
                                     Tag="GlobalAppearance_Nav" />

            <muxc:NavigationViewItem x:Name="ColorSchemesNavItem"
                                     x:Uid="Nav_ColorSchemes"
                                     Tag="ColorSchemes_Nav" />


            <muxc:NavigationViewItem x:Name="RenderingNavItem"
                                     x:Uid="Nav_Rendering"
                                     Tag="Rendering_Nav" />

            <muxc:NavigationViewItem x:Name="CompatibilityNavItem"
                                     x:Uid="Nav_Compatibility"
                                     Tag="Compatibility_Nav" />

            <muxc:NavigationViewItem x:Name="ActionsNavItem"
                                     x:Uid="Nav_Actions"
                                     Tag="Actions_Nav">
                <muxc:NavigationViewItem.InfoBadge>
                    <muxc:InfoBadge Style="{StaticResource NewInfoBadge}"
                                    Visibility="{x:Bind ActionsVM.DisplayBadge, Mode=OneWay}" />
                </muxc:NavigationViewItem.InfoBadge>
            </muxc:NavigationViewItem>

            <muxc:NavigationViewItem x:Name="NewTabMenuNavItem"
                                     x:Uid="Nav_NewTabMenu"
                                     Tag="NewTabMenu_Nav" />

            <muxc:NavigationViewItem x:Name="ExtensionsNavItem"
                                     x:Uid="Nav_Extensions"
                                     Tag="Extensions_Nav" />

            <muxc:NavigationViewItemHeader x:Uid="Nav_Profiles" />

            <muxc:NavigationViewItem x:Name="BaseLayerMenuItem"
                                     x:Uid="Nav_ProfileDefaults"
                                     Tag="GlobalProfile_Nav" />
        </muxc:NavigationView.MenuItems>

        <muxc:NavigationView.FooterMenuItems>
            <muxc:NavigationViewItem x:Name="OpenJsonNavItem"
                                     x:Uid="Nav_OpenJSON"
                                     SelectsOnInvoked="False"
                                     Tag="OpenJson_Nav" />
        </muxc:NavigationView.FooterMenuItems>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ScrollViewer x:Name="SettingsMainPage_ScrollViewer"
                          Grid.Row="0">
                <Frame x:Name="contentFrame"
                       Grid.Row="0"
                       Padding="16,0,16,48">
                    <Frame.ContentTransitions>
                        <TransitionCollection>
                            <NavigationThemeTransition>
                                <NavigationThemeTransition.DefaultNavigationTransitionInfo>
                                    <DrillInNavigationTransitionInfo />
                                </NavigationThemeTransition.DefaultNavigationTransitionInfo>
                            </NavigationThemeTransition>
                        </TransitionCollection>
                    </Frame.ContentTransitions>
                </Frame>
            </ScrollViewer>
            <!--  Explicitly set the background color on grid to prevent the navigation animation from overflowing it  -->
            <Grid Grid.Row="1"
                  Height="56"
                  BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
                  BorderThickness="0,1,0,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <StackPanel Margin="32,0,0,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Orientation="Vertical">
                    <TextBlock x:Uid="Settings_UnsavedSettingsWarning"
                               Foreground="Goldenrod"
                               TextAlignment="Left"
                               Visibility="Collapsed" />
                    <StackPanel VerticalAlignment="Center"
                                Orientation="Horizontal"
                                Spacing="4"
                                Visibility="{x:Bind tsm:CascadiaSettings.IsPortableMode, Mode=OneTime}">
                        <FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}"
                                  Foreground="SlateBlue"
                                  Glyph="&#xE946;" />
                        <TextBlock Foreground="SlateBlue">
                            <Run x:Uid="Settings_PortableModeNote" />
                            <Hyperlink x:Uid="Settings_PortableModeInfoLink">
                                <Run x:Uid="Settings_PortableModeInfoLinkTextRun" />
                            </Hyperlink>
                        </TextBlock>
                    </StackPanel>
                </StackPanel>
                <StackPanel Margin="0,0,32,0"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <Button x:Name="SaveButton"
                            x:Uid="Settings_SaveSettingsButton"
                            Click="SaveButton_Click"
                            Style="{StaticResource AccentButtonStyle}" />
                    <Button x:Name="ResetButton"
                            x:Uid="Settings_ResetSettingsButton"
                            Margin="8,0,0,0"
                            Click="ResetButton_Click" />
                </StackPanel>
            </Grid>
        </Grid>
    </muxc:NavigationView>
</Page>
