<!--
    Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
    the MIT License. See LICENSE in the project root for license information.
-->
<Page x:Class="TerminalApp.TerminalPage"
      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:TerminalApp"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:mtu="using:Microsoft.Terminal.UI"
      xmlns:mux="using:Microsoft.UI.Xaml.Controls"
      Background="Transparent"
      mc:Ignorable="d">

    <Grid x:Name="Root"
          Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <local:TabRowControl x:Name="TabRow"
                             Grid.Row="0"
                             KeyUp="_KeyDownHandler" />

        <StackPanel Grid.Row="1"
                    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <mux:InfoBar x:Name="KeyboardServiceWarningInfoBar"
                         x:Load="False"
                         CornerRadius="0"
                         IsClosable="True"
                         IsIconVisible="True"
                         IsOpen="False"
                         Message="{x:Bind KeyboardServiceDisabledText, Mode=OneWay}"
                         Severity="Warning">
                <mux:InfoBar.ActionButton>
                    <Button x:Uid="InfoBarDismissButton"
                            Click="_KeyboardServiceWarningInfoDismissHandler" />
                </mux:InfoBar.ActionButton>
            </mux:InfoBar>

            <mux:InfoBar x:Name="CloseOnExitInfoBar"
                         x:Uid="CloseOnExitInfoBar"
                         x:Load="False"
                         CornerRadius="0"
                         IsClosable="True"
                         IsIconVisible="True"
                         IsOpen="False"
                         Severity="Informational">
                <mux:InfoBar.ActionButton>
                    <Button x:Uid="InfoBarDismissButton"
                            Click="_CloseOnExitInfoDismissHandler" />
                </mux:InfoBar.ActionButton>
            </mux:InfoBar>
        </StackPanel>

        <Grid x:Name="TabContent"
              Grid.Row="2"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch">
            <Grid.Background>
                <ImageBrush />
            </Grid.Background>
        </Grid>

        <!--
            GH#12775 et. al: After switching to ControlsV2, it seems that
            delay-loading a dialog causes the ContentDialog to be assigned a
            Height equal to its content size. If we DON'T assign the
            ContentDialog a Row, I believe it's assigned Row 0 by default. So,
            when the dialog gets opened, the dialog seemingly causes a giant
            hole to appear in the body of the app.
            
            Assigning all the dialogs to Row 2 (where the rest of the content
            is) makes the "hole" appear in the same space as the rest of the
            TabContent, fixing the issue.
            
            Note that the actual content in a content dialog gets parented to
            the PopupRoot, so it actually always appeared in the correct place, it's
            just this weird hole that appeared in Row 0.
        -->

        <local:AboutDialog x:Name="AboutDialog"
                           Grid.Row="2"
                           x:Load="False" />

        <ContentDialog x:Name="QuitDialog"
                       x:Uid="QuitDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Primary" />

        <ContentDialog x:Name="CloseAllDialog"
                       x:Uid="CloseAllDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Primary" />

        <ContentDialog x:Name="CloseReadOnlyDialog"
                       x:Uid="CloseReadOnlyDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Close" />

        <ContentDialog x:Name="MultiLinePasteDialog"
                       x:Uid="MultiLinePasteDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Primary">
            <StackPanel>
                <TextBlock x:Uid="MultiLineWarningText"
                           TextWrapping="Wrap" />
                <TextBlock x:Uid="ClipboardTextHeader"
                           Margin="0,16,0,0" />
                <ScrollViewer x:Name="ClipboardContentScrollViewer"
                              MaxHeight="100"
                              Margin="0,8,0,0">
                    <TextBlock x:Name="ClipboardText"
                               FontFamily="Cascadia Mono"
                               TextWrapping="Wrap" />
                </ScrollViewer>
            </StackPanel>
        </ContentDialog>

        <ContentDialog x:Name="LargePasteDialog"
                       x:Uid="LargePasteDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Primary" />

        <ContentDialog x:Name="ControlNoticeDialog"
                       x:Uid="ControlNoticeDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Primary">
            <TextBlock IsTextSelectionEnabled="True"
                       TextWrapping="WrapWholeWords">
                <TextBlock.ContextFlyout>
                    <mtu:TextMenuFlyout />
                </TextBlock.ContextFlyout>
                <Run x:Name="NoticeMessage" />
            </TextBlock>
        </ContentDialog>

        <ContentDialog x:Name="CouldNotOpenUriDialog"
                       x:Uid="CouldNotOpenUriDialog"
                       Grid.Row="2"
                       x:Load="False"
                       DefaultButton="Primary">
            <TextBlock IsTextSelectionEnabled="True"
                       TextWrapping="WrapWholeWords">
                <TextBlock.ContextFlyout>
                    <mtu:TextMenuFlyout />
                </TextBlock.ContextFlyout>
                <Run x:Name="CouldNotOpenUriReason" /> <LineBreak />
                <Run x:Name="UnopenedUri"
                     FontFamily="Cascadia Mono" />
            </TextBlock>
        </ContentDialog>

        <local:CommandPalette x:Name="CommandPaletteElement"
                              Grid.Row="2"
                              VerticalAlignment="Stretch"
                              x:Load="False"
                              PreviewKeyDown="_KeyDownHandler"
                              Visibility="Collapsed" />

        <local:SuggestionsControl x:Name="SuggestionsElement"
                                  Grid.Row="2"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Top"
                                  x:Load="False"
                                  PreviewKeyDown="_KeyDownHandler"
                                  Visibility="Collapsed" />

        <!--
            A TeachingTip with IsLightDismissEnabled="True" will immediately
            dismiss itself if the window is unfocused (In Xaml Islands). This is
            tracked by MUX#4382
        -->
        <mux:TeachingTip x:Name="WindowIdToast"
                         Title="{x:Bind WindowProperties.WindowIdForDisplay}"
                         x:Load="False"
                         IsLightDismissEnabled="True"
                         Subtitle="{x:Bind WindowProperties.WindowNameForDisplay, Mode=OneWay}" />

        <mux:TeachingTip x:Name="WindowRenamer"
                         x:Uid="WindowRenamer"
                         Title="{x:Bind WindowProperties.WindowIdForDisplay}"
                         x:Load="False"
                         ActionButtonClick="_WindowRenamerActionClick"
                         ActionButtonStyle="{ThemeResource AccentButtonStyle}"
                         IsLightDismissEnabled="True">
            <mux:TeachingTip.Content>
                <TextBox x:Name="WindowRenamerTextBox"
                         KeyDown="_WindowRenamerKeyDown"
                         KeyUp="_WindowRenamerKeyUp"
                         Text="{x:Bind WindowProperties.WindowName, Mode=OneWay}">
                    <TextBox.ContextFlyout>
                        <mtu:TextMenuFlyout />
                    </TextBox.ContextFlyout>
                </TextBox>
            </mux:TeachingTip.Content>
        </mux:TeachingTip>

        <mux:TeachingTip x:Name="WindowCwdToast"
                         x:Uid="WindowCwdToast"
                         Title="{x:Bind WindowProperties.VirtualWorkingDirectory, Mode=OneWay}"
                         x:Load="False"
                         IsLightDismissEnabled="True" />

        <mux:TeachingTip x:Name="ActionSavedToast"
                         x:Uid="ActionSavedToast"
                         Title="Action Saved"
                         HorizontalAlignment="Stretch"
                         x:Load="False"
                         IsLightDismissEnabled="True">
            <mux:TeachingTip.Content>
                <StackPanel HorizontalAlignment="Stretch"
                            Orientation="Vertical">
                    <TextBlock x:Name="ActionSavedNameText"
                               Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SavedActionName), Mode=OneWay}">
                        <Run Text="Name: " />
                        <Run Text="{x:Bind SavedActionName, Mode=OneWay}" />
                    </TextBlock>
                    <TextBlock x:Name="ActionSavedKeyChordText"
                               Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SavedActionKeyChord), Mode=OneWay}">
                        <Run Text="Key Chord: " />
                        <Run Text="{x:Bind SavedActionKeyChord, Mode=OneWay}" />
                    </TextBlock>
                    <TextBlock x:Name="ActionSavedCommandLineText"
                               Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SavedActionCommandLine), Mode=OneWay}">
                        <Run Text="Input: " />
                        <Run Text="{x:Bind SavedActionCommandLine, Mode=OneWay}" />
                    </TextBlock>
                </StackPanel>
            </mux:TeachingTip.Content>
        </mux:TeachingTip>
        <mux:TeachingTip x:Name="ActionSaveFailedToast"
                         x:Uid="ActionSaveFailedToast"
                         Title="Action Save Failed"
                         x:Load="False"
                         IsLightDismissEnabled="True">
            <mux:TeachingTip.Content>
                <TextBlock x:Name="ActionSaveFailedMessage"
                           Text="" />
            </mux:TeachingTip.Content>
        </mux:TeachingTip>
    </Grid>
</Page>
