<ContentDialog
    x:Class="JumpPoint.Uwp.Dialogs.AppLinkLaunchDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:JumpPoint.Uwp.Dialogs"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:items="using:JumpPoint.Platform.Items"
    xmlns:extensions="using:JumpPoint.Platform.Models.Extensions"
    mc:Ignorable="d">

    <ContentDialog.Resources>
        <Style TargetType="local:AppLinkLaunchDialog"
               BasedOn="{StaticResource DefaultContentDialogStyle}" />
    </ContentDialog.Resources>

    <ScrollViewer>
        <StackPanel Spacing="8">
            <TextBlock Margin="0,0,0,8"
                       Style="{StaticResource TitleTextBlockStyle}"
                       Text="{x:Bind ViewModel.AppLink.Name, Mode=OneWay}" />
            
            <Grid ColumnSpacing="8"
                  Margin="0,0,0,8">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Border Width="48"
                        Height="48"
                        Background="{x:Bind ViewModel.AppLink.Background, Mode=OneWay, Converter={StaticResource DrawingColorBrushConverter}}">
                    <Image Source="{x:Bind ViewModel.AppLink.Logo, Converter={StaticResource AppLinkGridTilesLogoConverter}, Mode=OneWay}"
                           Width="48"
                           Height="48" />
                </Border>
                <StackPanel Grid.Column="1">
                    <TextBlock Text="{x:Bind ViewModel.AppLink.Link, Mode=OneWay}"
                               Style="{StaticResource SubtitleTextBlockStyle}"
                               TextWrapping="Wrap" />
                    <TextBlock Text="{x:Bind ViewModel.AppLink.Description, Mode=OneWay, Converter={StaticResource StringEmptyConverter}, ConverterParameter='No description'}"
                               Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
                               TextWrapping="WrapWholeWords"/>
                </StackPanel>
            </Grid>

            <TextBlock Text="{x:Bind ViewModel.AppLink.AppName, Mode=OneWay}"
                       FontWeight="SemiBold" />
            <TextBlock Text="{x:Bind ViewModel.AppLink.AppId, Mode=OneWay}"
                       Margin="0,0,0,8" />

            <TextBlock Text="QUERY:"
                       FontWeight="SemiBold"
                       VerticalAlignment="Center" />
            <winui:ItemsRepeater ItemsSource="{x:Bind ViewModel.AppLink.Query, Mode=OneWay}">
                <DataTemplate x:DataType="items:ValueInfo">
                    <StackPanel>
                        <TextBlock FontWeight="SemiBold"
                                   Text="{x:Bind Key}" />
                        <TextBox Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                </DataTemplate>
            </winui:ItemsRepeater>

            <TextBlock Text="INPUT DATA:"
                       FontWeight="SemiBold"
                       VerticalAlignment="Center" />
            <winui:ItemsRepeater ItemsSource="{x:Bind ViewModel.AppLink.InputData, Mode=OneWay}">
                <DataTemplate x:DataType="items:ValueInfo">
                    <StackPanel>
                        <TextBlock FontWeight="SemiBold"
                                   Text="{x:Bind Key}"/>
                        <TextBox Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    </StackPanel>
                </DataTemplate>
            </winui:ItemsRepeater>

            <Button Style="{StaticResource AccentButtonStyle}"
                    HorizontalAlignment="Stretch"
                    HorizontalContentAlignment="Stretch"
                    Click="btnLaunch_Click"
                    x:Name="btnLaunch"
                    x:Load="{x:Bind extensions:AppLinkExtensions.IsLaunchUriAvailable(ViewModel.AppLink.LaunchTypes), Mode=OneWay}">
                <StackPanel>
                    <TextBlock Text="Launch"
                               FontSize="18"
                               FontWeight="SemiBold" />
                    <TextBlock Text="Simply launches the app link."
                               TextWrapping="WrapWholeWords" />
                </StackPanel>
            </Button>

            <Button Style="{StaticResource AccentButtonStyle}"
                    HorizontalAlignment="Stretch"
                    HorizontalContentAlignment="Stretch"
                    Click="btnLaunchForResults_Click"
                    x:Name="btnLaunchForResults"
                    x:Load="{x:Bind extensions:AppLinkExtensions.IsLaunchUriForResultsAvailable(ViewModel.AppLink.LaunchTypes), Mode=OneWay}">
                <StackPanel>
                    <TextBlock Text="Launch for Results"
                               FontSize="18"
                               FontWeight="SemiBold" />
                    <TextBlock Text="Launches the app link and returns the results of the launch."
                               TextWrapping="WrapWholeWords" />
                </StackPanel>
            </Button>

            <Button HorizontalAlignment="Stretch"
                    HorizontalContentAlignment="Stretch"
                    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
                    Click="btnCancel_Click">
                <Grid ColumnSpacing="4">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <SymbolIcon Symbol="Cancel" />
                    <TextBlock Text="Cancel"
                               FontSize="16"
                               FontWeight="SemiBold"
                               TextLineBounds="Tight"
                               VerticalAlignment="Center"
                               Grid.Column="1" />
                </Grid>
            </Button>
        </StackPanel>
    </ScrollViewer>
</ContentDialog>
