<UserControl
    x:Class="JumpPoint.Uwp.Controls.AppLinkDetails"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:JumpPoint.Uwp.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:gtext="using:Glif.Core.Text"
    xmlns:helpers="using:JumpPoint.Uwp.Helpers"
    xmlns:i="using:Microsoft.Xaml.Interactivity"
    xmlns:behaviors="using:JumpPoint.Uwp.Interactivity.Behaviors"
    xmlns:converters="using:JumpPoint.Uwp.Converters"
    xmlns:items="using:JumpPoint.Platform.Items"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:commands="using:JumpPoint.ViewModels.Commands"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid RowSpacing="4"
          ColumnSpacing="8">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.5*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Border Width="28"
                    Height="28"
                    Background="{x:Bind AppLink.Background, Converter={StaticResource DrawingColorBrushConverter}, Mode=OneWay}">
                <Image Source="{x:Bind AppLink.Logo, Converter={StaticResource AppLinkGridTilesLogoConverter}, Mode=OneWay}"
                       Width="28"
                       Height="28" />
            </Border>

            <TextBlock Text="{x:Bind AppLink.DisplayName, Mode=OneWay}"
                       Grid.Column="1"
                       Margin="8,0"
                       TextTrimming="CharacterEllipsis"
                       VerticalAlignment="Center"
                       FontSize="16"
                       FontWeight="SemiBold"
                       FontStyle="{x:Bind gtext:FontStyleExtensions.ToPlatform(helpers:ServiceLocator.AppSettings.FontStyle), Mode=OneWay}"
                       FontStretch="{x:Bind gtext:FontStretchExtensions.ToPlatform(helpers:ServiceLocator.AppSettings.FontStretch), Mode=OneWay}">
                <i:Interaction.Behaviors>
                    <behaviors:FontFamilyBehavior FontFamily="{x:Bind helpers:ServiceLocator.AppSettings.Font, Mode=OneWay, Converter={StaticResource FontFamilyConverter}}" />
                </i:Interaction.Behaviors>
            </TextBlock>
        </Grid>

        <TextBlock Text="App Name:"
                   Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
                   Grid.Row="1" />
        <TextBlock Text="{x:Bind AppLink.AppName, Converter={StaticResource StringEmptyConverter}, ConverterParameter='Not set', Mode=OneWay}"
                   Grid.Row="1"
                   Grid.Column="1"
                   TextWrapping="Wrap" />

        <TextBlock Text="App Identifier:"
                   Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
                   Grid.Row="2" />
        <TextBlock Text="{x:Bind AppLink.AppId, Converter={StaticResource StringEmptyConverter}, ConverterParameter='Not set', Mode=OneWay}"
                   Grid.Row="2"
                   Grid.Column="1"
                   TextWrapping="Wrap" />

        <TextBlock Text="Link:"
                   Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
                   Grid.Row="3" />
        <TextBlock Text="{x:Bind AppLink.Link, Mode=OneWay}"
                   Grid.Row="3"
                   Grid.Column="1"
                   TextWrapping="Wrap" />

        <TextBlock Text="Launch Types:"
                   Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
                   Grid.Row="4" />
        <StackPanel Grid.Row="4"
                    Grid.Column="1">
            <TextBlock Text="Uri"
                       Visibility="{x:Bind converters:AppLinkUtilityConverter.IsLaunchTypeVisible(AppLink.LaunchTypes, items:AppLinkLaunchTypes.Uri), Mode=OneWay}" />
            <TextBlock Text="Uri for Results"
                       Visibility="{x:Bind converters:AppLinkUtilityConverter.IsLaunchTypeVisible(AppLink.LaunchTypes, items:AppLinkLaunchTypes.UriForResults), Mode=OneWay}" />
        </StackPanel>

        <TextBlock Text="Path:"
                   Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
                   Grid.Row="5" />
        <TextBlock Text="{x:Bind AppLink.Path, Mode=OneWay}"
                   Grid.Row="5"
                   Grid.Column="1"
                   TextWrapping="Wrap" />

        <Grid Grid.Row="6"
              Grid.ColumnSpan="2"
              Margin="0,4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <local:IconButton IsCompact="True"
                              VerticalAlignment="Stretch"
                              IconSource="{StaticResource ItemsPropertiesIcon}"
                              CommandParameter="{x:Bind AppLink, Mode=OneWay}"
                              Command="{Binding Source={StaticResource Locator}, Path=CommandHelper.OpenItemPropertiesCommand}"
                              Visibility="{x:Bind IsInDetailsPane, Mode=OneWay, Converter={StaticResource VisibleWhenTrueConverter}}"
                              Margin="0,0,8,0" />
            <winui:SplitButton Grid.Column="1"
                               HorizontalAlignment="Stretch"
                               CommandParameter="{x:Bind AppLink, Mode=OneWay}"
                               Command="{Binding Source={StaticResource Locator}, Path=CommandHelper.OpenItemInNewWindowCommand}">
                <StackPanel Orientation="Horizontal"
                            Spacing="8">
                    <IconSourceElement IconSource="{StaticResource OpenIcon}" />
                    <TextBlock Text="Launch" />
                </StackPanel>
                <winui:SplitButton.Flyout>
                    <MenuFlyout Placement="BottomEdgeAlignedRight">
                        <MenuFlyoutItem Text="Add to Workspace"
                                        Icon="{converters:IconSourceElement Source={StaticResource AddItemsToWorkspaceIcon}}"
                                        CommandParameter="{x:Bind AppLink, Mode=OneWay}"
                                        Command="{Binding Source={StaticResource Locator}, Path=CommandHelper.AddItemToWorkspaceCommand}"
                                        IsEnabled="{x:Bind commands:DetailsPane.IsAddToWorkspaceEnabled(AppLink), Mode=OneWay}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled}" />
                        <MenuFlyoutItem Text="Add to Favorites"
                                        Icon="{converters:IconSourceElement Source={StaticResource AddItemsToFavoritesIcon}}"
                                        CommandParameter="{x:Bind AppLink, Mode=OneWay}"
                                        Command="{Binding Source={StaticResource Locator}, Path=CommandHelper.AddItemToFavoritesCommand}"
                                        IsEnabled="{x:Bind commands:DetailsPane.IsAddToFavoritesEnabled(AppLink), Mode=OneWay}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled}" />
                        <MenuFlyoutItem Text="Remove from Favorites"
                                        Icon="{converters:IconSourceElement Source={StaticResource RemoveItemsFromFavoritesIcon}}"
                                        CommandParameter="{x:Bind AppLink, Mode=OneWay}"
                                        Command="{Binding Source={StaticResource Locator}, Path=CommandHelper.RemoveItemFromFavoritesCommand}"
                                        IsEnabled="{x:Bind commands:DetailsPane.IsRemoveFromFavoritesEnabled(AppLink), Mode=OneWay}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsEnabled}" />
                        <MenuFlyoutItem Text="More Tools..."
                                        Icon="{converters:IconSourceElement Source={StaticResource MoreToolsIcon}}"
                                        CommandParameter="{x:Bind AppLink, Mode=OneWay}"
                                        Command="{Binding Source={StaticResource Locator}, Path=CommandHelper.ItemMoreToolsCommand}" />
                    </MenuFlyout>
                </winui:SplitButton.Flyout>
            </winui:SplitButton>
        </Grid>

        <MenuFlyoutSeparator Grid.ColumnSpan="2"
                             Grid.Row="7" />
    </Grid>
</UserControl>
