<controls:PageBase
    x:Class="JumpPoint.Uwp.Hosted.AppLinkProviderPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:JumpPoint.Uwp.Hosted"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:extensions="using:JumpPoint.Extensions.AppLinkProviders"
    xmlns:controls="using:JumpPoint.Uwp.Controls"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:converters="using:JumpPoint.Uwp.Converters"
    mc:Ignorable="d"
    winui:BackdropMaterial.ApplyToRootOrPageBackground="True"
    d:DesignWidth="500"
    d:DesignHeight="500">

    <Grid Padding="12"
          ColumnSpacing="4">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <TextBlock Style="{StaticResource SubtitleTextBlockStyle}"
                   Text="{x:Bind ViewModel.Provider, Mode=OneWay}"
                   Grid.ColumnSpan="2"
                   Margin="0,0,0,8"/>
        <winui:ProgressBar IsIndeterminate="{x:Bind ViewModel.IsLoading, Mode=OneWay}"
                           Visibility="{x:Bind ViewModel.IsLoading, Mode=OneWay}"
                           Grid.Row="1"
                           Grid.ColumnSpan="2"/>
        <GridView Grid.Row="2"
                  Grid.ColumnSpan="2"
                  SelectionMode="Single"
                  Margin="-12,0,-12,8"
                  ItemsSource="{x:Bind ViewModel.AppLinks, Mode=OneWay}"
                  SelectedItem="{x:Bind ViewModel.AppLink, Mode=TwoWay}">
            <GridView.ItemTemplate>
                <DataTemplate x:DataType="extensions:AppLinkPayload">
                    <Grid Width="120"
                          Background="Transparent"
                          Padding="4">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="80" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Border HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Width="48"
                                Height="48"
                                Background="{x:Bind Background, Converter={StaticResource HexBrushConverter}}">
                            <Image Source="{x:Bind converters:IconConverter.GetImageSource(LogoUri, x:Null, Logo, 58, 0)}"
                                   Width="48"
                                   Height="48" />
                        </Border>

                        <StackPanel Grid.Row="1">
                            <TextBlock Text="{x:Bind Name}"
                                       FontSize="14"
                                       HorizontalTextAlignment="Center"
                                       TextTrimming="CharacterEllipsis"
                                       TextWrapping="Wrap"
                                       MaxLines="2" />

                            <TextBlock FontSize="14" />
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>
        <Button Grid.Row="3"
                Style="{StaticResource AccentButtonStyle}"
                Content="Pick"
                HorizontalAlignment="Stretch"
                Command="{x:Bind ViewModel.PickCommand}" />
        <Button Grid.Row="3"
                Grid.Column="1"
                Content="Cancel"
                HorizontalAlignment="Stretch"
                Command="{x:Bind ViewModel.CancelCommand}" />
    </Grid>
</controls:PageBase>
