<!--  Copyright (c) Microsoft Corporation and Contributors.  -->
<!--  Licensed under the MIT License.  -->

<UserControl
    x:Class="Peek.UI.Views.TitleBar"
    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"
    mc:Ignorable="d">

    <Grid x:Name="TitleBarRootContainer" Height="48">
        <Grid.ColumnDefinitions>
            <ColumnDefinition x:Name="SystemLeftPaddingColumn" Width="0" />
            <ColumnDefinition x:Name="DraggableColumn" Width="*" />
            <ColumnDefinition x:Name="LaunchAppButtonColumn" Width="Auto" />
            <ColumnDefinition x:Name="AppRightPaddingColumn" Width="8" />
            <ColumnDefinition x:Name="PinButtonColumn" Width="Auto" />
            <ColumnDefinition x:Name="SystemRightPaddingColumn" Width="180" />
        </Grid.ColumnDefinitions>
        <Grid
            x:Name="AppIconAndFileTitleContainer"
            Grid.Column="1"
            HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="AppIconColumn" Width="Auto" />
                <ColumnDefinition x:Name="FileTitleColumn" Width="*" />
            </Grid.ColumnDefinitions>

            <Image
                x:Name="PeekLogo"
                x:Uid="PeekLogo"
                Grid.Column="0"
                Width="16"
                Height="16"
                Margin="16,0"
                Source="../../Assets/Peek/Icon.ico"
                Stretch="UniformToFill" />

            <Grid
                x:Name="FileCountAndNameContainer"
                Grid.Column="1"
                VerticalAlignment="Center">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Name="FileCountColumn" Width="Auto" />
                    <ColumnDefinition x:Name="FileNameColumn" Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock
                    x:Name="AppTitle_FileCount"
                    Grid.Column="0"
                    Margin="0,0,8,0"
                    FontWeight="SemiBold"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{x:Bind FileCountText, Mode=OneWay}"
                    Visibility="{x:Bind IsMultiSelection, Mode=OneWay}" />

                <TextBlock
                    x:Name="AppTitle_FileName"
                    Grid.Column="1"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{x:Bind FileName, Mode=OneWay}"
                    TextWrapping="NoWrap" />
            </Grid>
        </Grid>

        <Button
            x:Name="LaunchAppButton"
            Grid.Column="2"
            VerticalAlignment="Center"
            Command="{x:Bind LaunchDefaultAppButtonCommand, Mode=OneWay}"
            ToolTipService.ToolTip="{x:Bind OpenWithAppToolTip, Mode=OneWay}"
            Visibility="{x:Bind IsLaunchDefaultAppButtonVisible(DefaultAppName), Mode=OneWay}">
            <Button.Content>
                <StackPanel Orientation="Horizontal" Spacing="4">
                    <FontIcon
                        x:Name="LaunchAppButton_Icon"
                        FontSize="16"
                        Glyph="&#xE8E5;" />
                    <TextBlock
                        x:Name="LaunchAppButton_Text"
                        Style="{StaticResource CaptionTextBlockStyle}"
                        Text="{x:Bind OpenWithAppText, Mode=OneWay}" />
                </StackPanel>
            </Button.Content>
            <Button.KeyboardAccelerators>
                <KeyboardAccelerator Key="Enter" />
            </Button.KeyboardAccelerators>
        </Button>

        <Button
            x:Name="PinButton"
            Grid.Column="4"
            VerticalAlignment="Center"
            Command="{x:Bind PinCommand, Mode=OneWay}"
            Style="{StaticResource SubtleButtonStyle}"
            ToolTipService.ToolTip="{x:Bind PinToolTip(Pinned), Mode=OneWay}">
            <Button.Content>
                <FontIcon
                    x:Name="PinButton_Icon"
                    FontSize="16"
                    Glyph="{x:Bind PinGlyph(Pinned), Mode=OneWay}" />
            </Button.Content>
        </Button>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="AdaptiveWidth">
                <VisualState x:Name="MaximumLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="560" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="LaunchAppButton_Text.Visibility" Value="Visible" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="MediumLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="340" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="LaunchAppButton_Text.Visibility" Value="Collapsed" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="MinimumLayout">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="LaunchAppButton_Text.Visibility" Value="Collapsed" />
                        <Setter Target="LaunchAppButton.Visibility" Value="Collapsed" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</UserControl>
