<controls:PageBase
    xmlns:nguwp="using:NittyGritty.Uwp"
    x:Class="JumpPoint.Uwp.Views.DashboardPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:JumpPoint.Uwp.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:JumpPoint.Uwp.Controls"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:ngmodels="using:NittyGritty.Models"
    xmlns:conv="using:JumpPoint.Uwp.Converters"
    xmlns:platform="using:JumpPoint.Platform"
    xmlns:grouper="using:JumpPoint.Platform.Items.Arrangers.Groupers"
    xmlns:i="using:Microsoft.Xaml.Interactivity"
    xmlns:icore="using:Microsoft.Xaml.Interactions.Core"
    xmlns:actions="using:NittyGritty.Uwp.Interactivity.Actions"
    mc:Ignorable="d">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <controls:JumpPointViewer Grid.Row="1"
                                  Context="{x:Bind ViewModel, Mode=OneWay}"
                                  SortBy="{x:Bind ViewModel.Settings.SortBy, Mode=OneWay}"
                                  IsSortAscending="{x:Bind ViewModel.Settings.IsSortAscending, Mode=OneWay}"
                                  GroupBy="Custom"
                                  IsGroupAscending="{x:Bind ViewModel.Settings.IsGroupAscending, Mode=OneWay}"
                                  CustomGrouper="{x:Bind grouper:Grouper.Dashboard}"
                                  IsLoading="{x:Bind ViewModel.IsLoading, Mode=OneWay}"
                                  SelectedItems="{x:Bind ViewModel.SelectedItems, Mode=OneWay}"
                                  ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}">
            <controls:JumpPointViewer.Header>
                <ScrollViewer VerticalScrollMode="Disabled"
                              VerticalScrollBarVisibility="Hidden"
                              HorizontalScrollMode="Enabled"
                              HorizontalScrollBarVisibility="Auto">
                    <winui:ItemsRepeater ItemsSource="{x:Bind ViewModel.QuickLinks, Mode=OneWay}"
                                         Margin="4,4,4,16">
                        <winui:ItemsRepeater.Layout>
                            <winui:StackLayout Orientation="Horizontal"
                                               Spacing="4" />
                            <!--<winui:UniformGridLayout Orientation="Horizontal"
                                                     MinColumnSpacing="4"
                                                     MinRowSpacing="4"
                                                     MinItemWidth="100"
                                                     ItemsStretch="Fill"
                                                     ItemsJustification="Center" />-->
                        </winui:ItemsRepeater.Layout>
                        <DataTemplate x:DataType="ngmodels:ShellItem">
                            <Button CommandParameter="{x:Bind Mode=OneWay}"
                                    Command="{Binding Source={StaticResource Locator}, Path=TabbedShell.ShellItemCommand}"
                                    Background="Transparent"
                                    MinWidth="100"
                                    BorderThickness="0"
                                    Padding="0"
                                    HorizontalAlignment="Stretch"
                                    HorizontalContentAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    VerticalContentAlignment="Stretch">
                                <Grid Background="Transparent">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="56" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Image HorizontalAlignment="Center"
                                           VerticalAlignment="Center"
                                           Width="36"
                                           Height="36"
                                           Loaded="OnItemLoaded">
                                        <Image.Source>
                                            <BitmapImage DecodePixelHeight="44"
                                                         DecodePixelWidth="44"
                                                         DecodePixelType="Logical"
                                                         UriSource="{x:Bind conv:IconConverter.GetPathTypeIconUri((platform:AppPath)Tag), Mode=OneWay}" />
                                        </Image.Source>
                                    </Image>

                                    <TextBlock Grid.Row="1"
                                               VerticalAlignment="Top"
                                               HorizontalAlignment="Stretch"
                                               Margin="8,0,8,8"
                                               FontSize="12"
                                               HorizontalTextAlignment="Center"
                                               Text="{x:Bind Content, Mode=OneWay}" />
                                </Grid>
                            </Button>
                        </DataTemplate>
                    </winui:ItemsRepeater>
                </ScrollViewer>
            </controls:JumpPointViewer.Header>
        </controls:JumpPointViewer>
        <Grid Padding="12,8"
              Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
              x:Load="{x:Bind ViewModel.IsSearching, Mode=OneWay}"
              ColumnSpacing="8"
              x:Name="paneSearch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBox Text="{x:Bind ViewModel.Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     PlaceholderText="Search..."
                     HorizontalAlignment="Stretch">
                <i:Interaction.Behaviors>
                    <icore:EventTriggerBehavior EventName="Loaded">
                        <actions:FocusAction />
                    </icore:EventTriggerBehavior>
                </i:Interaction.Behaviors>
            </TextBox>
            <Button Grid.Column="1"
                    Padding="4"
                    BorderThickness="0"
                    Background="Transparent"
                    VerticalAlignment="Center"
                    Click="{x:Bind ViewModel.CloseSearch}">
                <IconSourceElement IconSource="{StaticResource CloseTabIcon}" />
            </Button>
        </Grid>
    </Grid>
</controls:PageBase>
