<ContentDialog
    x:Class="JumpPoint.Uwp.Dialogs.AddToWorkspaceDialog"
    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:items="using:JumpPoint.Platform.Items"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:converters="using:JumpPoint.Uwp.Converters"
    xmlns:ngconv="using:NittyGritty.Uwp.Converters"
    mc:Ignorable="d"
    Title="Add to Workspace"
    PrimaryButtonText="Save"
    CloseButtonText="Cancel"
    DefaultButton="Primary">

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

    <Grid>
        <ProgressRing IsActive="{x:Bind ViewModel.IsLoading, Mode=OneWay}"
                      Visibility="{x:Bind ViewModel.IsLoading, Mode=OneWay, Converter={StaticResource VisibleWhenTrueConverter}}"
                      Margin="0,12"
                      HorizontalAlignment="Center"
                      Height="40"
                      Width="40"/>
        <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" />
        </StackPanel>
        <winui:ItemsRepeater ItemsSource="{x:Bind ViewModel.Workspaces, Mode=OneWay}">
            <winui:ItemsRepeater.ItemTemplate>
                <DataTemplate x:DataType="items:SelectableWorkspace">
                    <CheckBox IsChecked="{x:Bind IsSelected, Mode=TwoWay}"
                              Margin="0,4">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock FontFamily="Segoe UI Emoji" FontSize="20"
                                       IsColorFontEnabled="True" Margin="0,0,8,0"
                                       TextLineBounds="Tight"
                                       VerticalAlignment="Center"
                                       Text="{x:Bind converters:IconConverter.GetWorkspaceGlyph(Item.Template)}"/>
                            <TextBlock VerticalAlignment="Center" Grid.Column="1"
                                       Text="{x:Bind Item.Name}" FontSize="16"/>
                        </Grid>
                    </CheckBox>
                </DataTemplate>
            </winui:ItemsRepeater.ItemTemplate>
        </winui:ItemsRepeater>
    </Grid>
</ContentDialog>
