<!--
    Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
    the MIT License. See LICENSE in the project root for license information.
-->
<StackPanel x:Class="TerminalApp.MinMaxCloseControl"
            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"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            d:DesignHeight="40"
            d:DesignWidth="400"
            Background="Transparent"
            Orientation="Horizontal"
            mc:Ignorable="d">

    <StackPanel.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Light">
                    <Color x:Key="CloseButtonColor">#C42B1C</Color>
                    <StaticResource x:Key="CaptionButtonBackgroundPointerOver"
                                    ResourceKey="SubtleFillColorSecondary" />
                    <StaticResource x:Key="CaptionButtonBackgroundPressed"
                                    ResourceKey="SubtleFillColorTertiary" />
                    <StaticResource x:Key="CaptionButtonForeground"
                                    ResourceKey="SystemControlForegroundBaseHighBrush" />
                    <StaticResource x:Key="CaptionButtonForegroundColor"
                                    ResourceKey="SystemBaseHighColor" />
                    <StaticResource x:Key="CaptionButtonForegroundPointerOver"
                                    ResourceKey="SystemControlForegroundBaseHighBrush" />
                    <StaticResource x:Key="CaptionButtonForegroundPressed"
                                    ResourceKey="SystemControlForegroundBaseHighBrush" />
                    <SolidColorBrush x:Key="CaptionButtonBackground"
                                     Color="Transparent" />
                    <Color x:Key="CaptionButtonBackgroundColor">Transparent</Color>
                    <SolidColorBrush x:Key="CloseButtonBackgroundPointerOver"
                                     Color="{ThemeResource CloseButtonColor}" />
                    <SolidColorBrush x:Key="CloseButtonForegroundPointerOver"
                                     Color="White" />
                    <SolidColorBrush x:Key="CloseButtonBackgroundPressed"
                                     Opacity="0.9"
                                     Color="{ThemeResource CloseButtonColor}" />
                    <SolidColorBrush x:Key="CloseButtonForegroundPressed"
                                     Opacity="0.7"
                                     Color="White" />
                    <SolidColorBrush x:Key="CloseButtonBackground"
                                     Color="#00C42B1C" />
                    <Color x:Key="CloseButtonBackgroundColor">#00C42B1C</Color>

                    <StaticResource x:Key="RestoreButtonGlyph"
                                    ResourceKey="RestoreGlyph" />
                </ResourceDictionary>
                <ResourceDictionary x:Key="Dark">
                    <Color x:Key="CloseButtonColor">#C42B1C</Color>
                    <StaticResource x:Key="CaptionButtonBackgroundPointerOver"
                                    ResourceKey="SubtleFillColorSecondary" />
                    <StaticResource x:Key="CaptionButtonBackgroundPressed"
                                    ResourceKey="SubtleFillColorTertiary" />
                    <StaticResource x:Key="CaptionButtonForeground"
                                    ResourceKey="SystemControlForegroundBaseHighBrush" />
                    <StaticResource x:Key="CaptionButtonForegroundColor"
                                    ResourceKey="SystemBaseHighColor" />
                    <StaticResource x:Key="CaptionButtonForegroundPointerOver"
                                    ResourceKey="SystemControlForegroundBaseHighBrush" />
                    <StaticResource x:Key="CaptionButtonForegroundPressed"
                                    ResourceKey="SystemControlForegroundBaseHighBrush" />
                    <SolidColorBrush x:Key="CaptionButtonBackground"
                                     Color="Transparent" />
                    <Color x:Key="CaptionButtonBackgroundColor">Transparent</Color>
                    <SolidColorBrush x:Key="CloseButtonBackgroundPointerOver"
                                     Color="{ThemeResource CloseButtonColor}" />
                    <SolidColorBrush x:Key="CloseButtonForegroundPointerOver"
                                     Color="White" />
                    <SolidColorBrush x:Key="CloseButtonBackgroundPressed"
                                     Opacity="0.9"
                                     Color="{ThemeResource CloseButtonColor}" />
                    <SolidColorBrush x:Key="CloseButtonForegroundPressed"
                                     Opacity="0.7"
                                     Color="White" />
                    <SolidColorBrush x:Key="CloseButtonBackground"
                                     Color="#00C42B1C" />
                    <Color x:Key="CloseButtonBackgroundColor">#00C42B1C</Color>

                    <StaticResource x:Key="RestoreButtonGlyph"
                                    ResourceKey="RestoreGlyph" />
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <SolidColorBrush x:Key="CaptionButtonBackground"
                                     Color="{ThemeResource SystemColorButtonFaceColor}" />
                    <StaticResource x:Key="CaptionButtonBackgroundColor"
                                    ResourceKey="SystemColorButtonFaceColor" />
                    <SolidColorBrush x:Key="CaptionButtonBackgroundPointerOver"
                                     Color="{ThemeResource SystemColorHighlightColor}" />
                    <SolidColorBrush x:Key="CaptionButtonBackgroundPressed"
                                     Color="{ThemeResource SystemColorHighlightColor}" />
                    <SolidColorBrush x:Key="CaptionButtonForeground"
                                     Color="{ThemeResource SystemColorButtonTextColor}" />
                    <StaticResource x:Key="CaptionButtonForegroundColor"
                                    ResourceKey="SystemColorButtonTextColor" />
                    <SolidColorBrush x:Key="CaptionButtonForegroundPointerOver"
                                     Color="{ThemeResource SystemColorHighlightTextColor}" />
                    <SolidColorBrush x:Key="CaptionButtonForegroundPressed"
                                     Color="{ThemeResource SystemColorHighlightTextColor}" />
                    <SolidColorBrush x:Key="CloseButtonBackgroundPointerOver"
                                     Color="{ThemeResource SystemColorHighlightColor}" />
                    <SolidColorBrush x:Key="CloseButtonForegroundPointerOver"
                                     Color="{ThemeResource SystemColorHighlightTextColor}" />
                    <SolidColorBrush x:Key="CloseButtonBackgroundPressed"
                                     Color="{ThemeResource SystemColorHighlightColor}" />
                    <SolidColorBrush x:Key="CloseButtonForegroundPressed"
                                     Color="{ThemeResource SystemColorHighlightTextColor}" />

                    <StaticResource x:Key="RestoreButtonGlyph"
                                    ResourceKey="RestoreGlyphContrast" />
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>

            <!--
                Initializes the string to the close button glyph.
                Each specific button overrides it as needed.
            -->
            <x:String x:Key="CaptionButtonGlyph">&#xE8BB;</x:String>

            <x:String x:Key="MinimizeGlyph">&#xE921;</x:String>
            <x:String x:Key="MaximizeGlyph">&#xE922;</x:String>
            <x:String x:Key="RestoreGlyph">&#xE923;</x:String>
            <x:String x:Key="CloseGlyph">&#xE8BB;</x:String>

            <x:String x:Key="MinimizeGlyphContrast">&#xEF2D;</x:String>
            <x:String x:Key="MaximizeGlyphContrast">&#xEF2E;</x:String>
            <x:String x:Key="RestoreGlyphContrast">&#xEF2F;</x:String>
            <x:String x:Key="CloseGlyphContrast">&#xEF2C;</x:String>

            <!--
                "CaptionButtonHeightWindowed" and
                "CaptionButtonHeightMaximized" define the size we should use
                for the caption buttons height for the windowed and maximized
                states, respectively.
                
                32 was chosen for the Maximized height to match the height of
                the TabRowControl. This way, when the window is maximized, the
                tabs will be flush with the top of the window. See GH#2541 for
                details.
            -->
            <x:Double x:Key="CaptionButtonHeightWindowed">40.0</x:Double>
            <!--  32 + (1 to compensate for GH#10746) + (-1 for GH#15164)  -->
            <x:Double x:Key="CaptionButtonHeightMaximized">32.0</x:Double>

            <Style x:Key="CaptionButton"
                   TargetType="Button">
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="Background" Value="{ThemeResource CaptionButtonBackground}" />
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">

                            <Border x:Name="ButtonBaseElement"
                                    Padding="{TemplateBinding Padding}"
                                    AutomationProperties.AccessibilityView="Raw"
                                    Background="{TemplateBinding Background}"
                                    BackgroundSizing="{TemplateBinding BackgroundSizing}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{TemplateBinding CornerRadius}">
                                <Viewbox Width="10"
                                         Height="10">
                                    <FontIcon x:Name="ButtonIcon"
                                              FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                              Foreground="{ThemeResource CaptionButtonForeground}"
                                              Glyph="{ThemeResource CaptionButtonGlyph}" />
                                </Viewbox>

                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition From="PointerOver"
                                                              To="Normal">
                                                <Storyboard>
                                                    <ColorAnimation Storyboard.TargetName="ButtonBaseElement"
                                                                    Storyboard.TargetProperty="(UIElement.Background).(SolidColorBrush.Color)"
                                                                    To="{ThemeResource CaptionButtonBackgroundColor}"
                                                                    Duration="0:0:0.15" />
                                                    <ColorAnimation Storyboard.TargetName="ButtonIcon"
                                                                    Storyboard.TargetProperty="(UIElement.Foreground).(SolidColorBrush.Color)"
                                                                    To="{ThemeResource CaptionButtonForegroundColor}"
                                                                    Duration="0:0:0.1" />
                                                </Storyboard>
                                            </VisualTransition>
                                        </VisualStateGroup.Transitions>

                                        <VisualState x:Name="Normal">
                                            <VisualState.Setters>
                                                <Setter Target="ButtonBaseElement.Background" Value="{ThemeResource CaptionButtonBackground}" />
                                                <Setter Target="ButtonIcon.Foreground" Value="{ThemeResource CaptionButtonForeground}" />
                                            </VisualState.Setters>
                                        </VisualState>

                                        <VisualState x:Name="PointerOver">
                                            <VisualState.Setters>
                                                <Setter Target="ButtonBaseElement.Background" Value="{ThemeResource CaptionButtonBackgroundPointerOver}" />
                                                <Setter Target="ButtonIcon.Foreground" Value="{ThemeResource CaptionButtonForegroundPointerOver}" />
                                            </VisualState.Setters>
                                        </VisualState>

                                        <VisualState x:Name="Pressed">
                                            <VisualState.Setters>
                                                <Setter Target="ButtonBaseElement.Background" Value="{ThemeResource CaptionButtonBackgroundPressed}" />
                                                <Setter Target="ButtonIcon.Foreground" Value="{ThemeResource CaptionButtonForegroundPressed}" />
                                            </VisualState.Setters>
                                        </VisualState>

                                        <VisualState x:Name="Disabled" />
                                    </VisualStateGroup>

                                    <VisualStateGroup x:Name="MinMaxStates">
                                        <VisualState x:Name="WindowStateNormal" />

                                        <VisualState x:Name="WindowStateMaximized">
                                            <VisualState.Setters>
                                                <Setter Target="ButtonIcon.Glyph" Value="{ThemeResource RestoreButtonGlyph}" />
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>

                                </VisualStateManager.VisualStateGroups>
                            </Border>

                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

        </ResourceDictionary>
    </StackPanel.Resources>

    <Button x:Name="MinimizeButton"
            x:Uid="MinimizeButton"
            Width="46.0"
            Height="{StaticResource CaptionButtonHeightWindowed}"
            MinWidth="46.0"
            AutomationProperties.AccessibilityView="Raw"
            Click="_MinimizeClick"
            Style="{StaticResource CaptionButton}">
        <Button.Resources>
            <ResourceDictionary>
                <ResourceDictionary.ThemeDictionaries>
                    <ResourceDictionary x:Key="Light">
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="MinimizeGlyph" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="Dark">
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="MinimizeGlyph" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="HighContrast">
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="MinimizeGlyphContrast" />
                    </ResourceDictionary>
                </ResourceDictionary.ThemeDictionaries>
            </ResourceDictionary>
        </Button.Resources>
        <ToolTipService.ToolTip>
            <ToolTip>
                <TextBlock x:Uid="WindowMinimizeButtonToolTip" />
            </ToolTip>
        </ToolTipService.ToolTip>
    </Button>
    <Button x:Name="MaximizeButton"
            x:Uid="MaximizeButton"
            Width="46.0"
            Height="{StaticResource CaptionButtonHeightWindowed}"
            MinWidth="46.0"
            AutomationProperties.AccessibilityView="Raw"
            Click="_MaximizeClick"
            Style="{StaticResource CaptionButton}">
        <Button.Resources>
            <ResourceDictionary>
                <ResourceDictionary.ThemeDictionaries>
                    <ResourceDictionary x:Key="Light">
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="MaximizeGlyph" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="Dark">
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="MaximizeGlyph" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="HighContrast">
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="MaximizeGlyphContrast" />
                    </ResourceDictionary>
                </ResourceDictionary.ThemeDictionaries>
            </ResourceDictionary>
        </Button.Resources>
        <ToolTipService.ToolTip>
            <ToolTip>
                <TextBlock>
                    <Run x:Name="MaximizeToolTip" />
                </TextBlock>
            </ToolTip>
        </ToolTipService.ToolTip>
    </Button>
    <Button x:Name="CloseButton"
            x:Uid="CloseButton"
            Width="46.0"
            Height="{StaticResource CaptionButtonHeightWindowed}"
            MinWidth="46.0"
            AutomationProperties.AccessibilityView="Raw"
            Click="_CloseClick"
            Style="{StaticResource CaptionButton}">
        <Button.Resources>
            <ResourceDictionary>
                <ResourceDictionary.ThemeDictionaries>
                    <ResourceDictionary x:Key="Light">
                        <StaticResource x:Key="CaptionButtonBackgroundPointerOver"
                                        ResourceKey="CloseButtonBackgroundPointerOver" />
                        <StaticResource x:Key="CaptionButtonBackgroundPressed"
                                        ResourceKey="CloseButtonBackgroundPressed" />
                        <StaticResource x:Key="CaptionButtonForegroundPointerOver"
                                        ResourceKey="CloseButtonForegroundPointerOver" />
                        <StaticResource x:Key="CaptionButtonForegroundPressed"
                                        ResourceKey="CloseButtonForegroundPressed" />
                        <StaticResource x:Key="CaptionButtonBackground"
                                        ResourceKey="CloseButtonBackground" />
                        <StaticResource x:Key="CaptionButtonBackgroundColor"
                                        ResourceKey="CloseButtonBackgroundColor" />
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="CloseGlyph" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="Dark">
                        <StaticResource x:Key="CaptionButtonBackgroundPointerOver"
                                        ResourceKey="CloseButtonBackgroundPointerOver" />
                        <StaticResource x:Key="CaptionButtonBackgroundPressed"
                                        ResourceKey="CloseButtonBackgroundPressed" />
                        <StaticResource x:Key="CaptionButtonForegroundPointerOver"
                                        ResourceKey="CloseButtonForegroundPointerOver" />
                        <StaticResource x:Key="CaptionButtonForegroundPressed"
                                        ResourceKey="CloseButtonForegroundPressed" />
                        <StaticResource x:Key="CaptionButtonBackground"
                                        ResourceKey="CloseButtonBackground" />
                        <StaticResource x:Key="CaptionButtonBackgroundColor"
                                        ResourceKey="CloseButtonBackgroundColor" />
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="CloseGlyph" />
                    </ResourceDictionary>
                    <ResourceDictionary x:Key="HighContrast">
                        <StaticResource x:Key="CaptionButtonBackgroundPointerOver"
                                        ResourceKey="CloseButtonBackgroundPointerOver" />
                        <StaticResource x:Key="CaptionButtonBackgroundPressed"
                                        ResourceKey="CloseButtonBackgroundPressed" />
                        <StaticResource x:Key="CaptionButtonForegroundPointerOver"
                                        ResourceKey="CloseButtonForegroundPointerOver" />
                        <StaticResource x:Key="CaptionButtonForegroundPressed"
                                        ResourceKey="CloseButtonForegroundPressed" />
                        <StaticResource x:Key="CaptionButtonGlyph"
                                        ResourceKey="CloseGlyphContrast" />
                    </ResourceDictionary>
                </ResourceDictionary.ThemeDictionaries>
            </ResourceDictionary>
        </Button.Resources>
        <ToolTipService.ToolTip>
            <ToolTip>
                <TextBlock x:Uid="WindowCloseButtonToolTip" />
            </ToolTip>
        </ToolTipService.ToolTip>
    </Button>
</StackPanel>
