<ContentDialog
    x:Class="JumpPoint.Uwp.Dialogs.AppLinkProviderPicker"
    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:extensions="using:JumpPoint.Platform.Extensions"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:ngconv="using:NittyGritty.Uwp.Converters"
    xmlns:converters="using:JumpPoint.Uwp.Converters"
    mc:Ignorable="d"
    Title="App Link Providers"
    PrimaryButtonText="Pick"
    SecondaryButtonText="Cancel"
    DefaultButton="Primary"
    IsPrimaryButtonEnabled="{x:Bind ViewModel.IsValid, Mode=OneWay}">

    <ContentDialog.Resources>
        <Style TargetType="local:AppLinkProviderPicker"
               BasedOn="{StaticResource DefaultContentDialogStyle}" />
        <converters:NothingToShowConverter x:Name="NothingToShowConverter">
            <ngconv:Binding Value="{x:Bind ViewModel.IsLoading, Mode=OneWay}" />
            <ngconv:Binding Value="{x:Bind ViewModel.Providers.Count, Mode=OneWay}" />
        </converters:NothingToShowConverter>
    </ContentDialog.Resources>

    <GridView ItemsSource="{x:Bind ViewModel.Providers, Mode=OneWay}"
              SelectedItem="{x:Bind ViewModel.Provider, Mode=TwoWay}"
              SelectionMode="Single">
        <GridView.Header>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <winui:ProgressBar IsIndeterminate="{x:Bind ViewModel.IsLoading, Mode=OneWay}"
                                   Visibility="{x:Bind ViewModel.IsLoading, Mode=OneWay}"/>
                <StackPanel Margin="0,12"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"
                            Visibility="{x:Bind NothingToShowConverter.Output, Mode=OneWay}">
                    <Image HorizontalAlignment="Center"
                           Width="96"
                           Height="96">
                        <Image.Source>
                            <BitmapImage DecodePixelHeight="96"
                                         DecodePixelWidth="96"
                                         DecodePixelType="Logical"
                                         UriSource="/Assets/Icons/Empty.png" />
                        </Image.Source>
                    </Image>
                    <TextBlock Text="Nothing to show"
                               Style="{StaticResource SubtitleTextBlockStyle}"
                               HorizontalAlignment="Center" />
                    <TextBlock Text="You can enable them in Settings > Extensions"
                               Style="{StaticResource CaptionTextBlockStyle}"
                               TextWrapping="WrapWholeWords"
                               HorizontalAlignment="Center" />
                </StackPanel>
            </Grid>
        </GridView.Header>
        <GridView.ItemTemplate>
            <DataTemplate x:DataType="extensions:AppLinkProvider">
                <Grid Width="120">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Image Source="{x:Bind Logo, Converter={StaticResource AppLinkGridTilesLogoConverter}, Mode=OneWay}"
                           Width="48"
                           Height="48"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Margin="8"/>

                    <TextBlock Text="{x:Bind Name, Mode=OneWay}"
                               FontSize="14"
                               HorizontalTextAlignment="Center"
                               TextTrimming="CharacterEllipsis"
                               TextWrapping="Wrap"
                               MaxLines="2"
                               VerticalAlignment="Top"
                               Margin="8,0,8,8"
                               Grid.Row="1" />
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
</ContentDialog>
