<?xml version="1.0" encoding="utf-8"?>
<featurebase:FeaturePage
    x:Class="was.droidtransfer.features.photos.PhotosFeaturePage"
    xmlns:featurebase="using:was.droidtransfer.features"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.droidtransfer.features.photos"
    xmlns:converters="using:was.droidtransfer.features.photos.converters"
    xmlns:data="using:was.droidtransfer.features.photos.data"
    xmlns:commoncontrols="using:was.droidtransfer.features.controls"
    xmlns:dialogs="using:was.droidtransfer.features.dialogs"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <CollectionViewSource x:Key="PhotoAlbumsCVS" IsSourceGrouped="True" />
            <converters:PhotosAlbumTypeToStringConverter x:Key="PhotosAlbumTypeToStringConverter" />
            <converters:PhotosAlbumToFontIconGlyphConverter x:Key="PhotosAlbumToFontIconGlyphConverter" />
        </ResourceDictionary>
    </Page.Resources>
    <Grid>
        <Grid x:Name="gridMain">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Border Style="{ThemeResource PageHeaderBorderStyle}">
                <Grid>
                    <CommandBar Style="{ThemeResource PageHeaderCommandBarStyle}">
                        <featurebase:CopyProgressAppBarUserController x:Name="copyProgressUserControl" Visibility="Collapsed" OnCancelTapped="_copyProgressUserControl_OnCancelTapped" MaxWidth="350" />
                        <AppBarButton x:Name="appBarButtonSave" x:Uid="AppBarButtonSave" Label="XX Save to PC" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSave_Click" IsEnabled="{x:Bind AreFileOperationsAvailable, Mode=OneWay}" Visibility="{x:Bind FileOperationsVisibility, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE78C;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonExport" x:Uid="AppBarButtonExport" Label="XX Export New Photos" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonExport_Click" IsEnabled="{x:Bind AreFileOperationsAvailable, Mode=OneWay}" Visibility="{x:Bind FileOperationsVisibility, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xEB9F;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonAdd" x:Uid="AppBarButtonAdd" Label="XX Add Photos to Device" Style="{ThemeResource AppBarButtonStyle}" IsEnabled="{x:Bind IsFileImportAvailable, Mode=OneWay}" Visibility="{x:Bind FileImportVisibility, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE898;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                            <AppBarButton.Flyout>
                                <MenuFlyout Placement="Bottom">
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemAddFolder" Text="XX Add Folder" Click="_menuFlyoutItemAddFolder_Click" IsEnabled="{x:Bind IsFileImportAvailable, Mode=OneWay}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE8B7;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemAddFiles" Text="XX Add Files" Click="_menuFlyoutItemAddFiles_Click" IsEnabled="{x:Bind IsFileImportAvailable, Mode=OneWay}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE8B9;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </AppBarButton.Flyout>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonDelete" x:Uid="AppBarButtonDelete" Label="XX Delete Selection" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonDelete_Click" IsEnabled="{x:Bind AreFileOperationsAvailable, Mode=OneWay}" Visibility="{x:Bind FileOperationsVisibility, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE74D;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarSeparator />
                        <AppBarButton x:Name="appBarButtonView" x:Uid="AppBarButtonView" Label="XX Preview" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonView_Click" IsEnabled="{x:Bind photosContentPage.IsPreviewAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE890;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                    </CommandBar>
                    <TextBlock Text="{Binding PageTitle}" Style="{ThemeResource PageHeaderTitleStyle}"/>
                </Grid>
            </Border>
            <SplitView Grid.Row="1" OpenPaneLength="280" Style="{ThemeResource FeatureSplitViewStyle}" AllowDrop="True" DragOver="_grid_DragOver" Drop="_grid_Drop">
                <SplitView.Pane>
                    <Grid Margin="0,0,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBox x:Name="textBoxPhotosFilter" x:Uid="PhotosFilterTextBox" Margin="10,5" PlaceholderText="XX Search Photo Albums" 
                         TextChanged="_textBoxPhotosFilter_TextChanged" />
                        <ListView x:Name="listViewPhotoAlbums" Grid.Row="1" SelectionMode="Extended" ItemsSource="{x:Bind PhotoAlbums.View, Mode=OneWay}" SelectionChanged="_listViewPhotoAlbums_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollMode="Auto">
                            <ListView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <ItemsStackPanel AreStickyGroupHeadersEnabled="False"/>
                                </ItemsPanelTemplate>
                            </ListView.ItemsPanel>
                            <ListView.GroupStyle>
                                <GroupStyle>
                                    <GroupStyle.HeaderTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Key, Converter={StaticResource PhotosAlbumTypeToStringConverter}}"/>
                                        </DataTemplate>
                                    </GroupStyle.HeaderTemplate>
                                </GroupStyle>
                            </ListView.GroupStyle>
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="data:PhotosAlbum">
                                    <Grid ColumnSpacing="8">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <FontIcon Glyph="{Binding Converter={StaticResource PhotosAlbumToFontIconGlyphConverter}, Mode=OneWay}" />
                                        <TextBlock Grid.Column="1" Text="{x:Bind Title}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" Margin="0,0,0,2" />
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                            <ListView.ContextFlyout>
                                <MenuFlyout Opening="_menuFlyoutPhotoAlbums_Opening">
                                    <MenuFlyoutItem x:Name="menuFlyoutItemSaveAlbum" x:Uid="MenuFlyoutItemSaveAlbum" Text="XX Save to PC" Click="_menuFlyoutItemSaveAlbum_Click" IsEnabled="{x:Bind AreFileOperationsAvailable, Mode=OneWay}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE78C;" Foreground="{ThemeResource AppBarItemForegroundThemeBrush}"/>
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutSeparator />
                                    <MenuFlyoutItem x:Name="menuFlyoutItemDeleteAlbum" x:Uid="MenuFlyoutItemDeleteAlbum" Text="XX Delete Selected Albums" Click="_menuFlyoutItemDeleteAlbum_Click" IsEnabled="{x:Bind AreUserAlbumsSelected, Mode=OneWay}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE74D;" Foreground="{ThemeResource AppBarItemForegroundThemeBrush}"/>
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </ListView.ContextFlyout>
                        </ListView>
                        <commoncontrols:ResizeSplitterHandle Grid.RowSpan="2" Grid.Column="1" Margin="0"/>
                    </Grid>
                </SplitView.Pane>
                <Grid Margin="0,0,0,0" x:Name="gridContent">
                    <local:PhotosContentPage x:Name="photosContentPage" CopyRequested="_photosContentPage_CopyRequested" DeleteRequested="_photosContentPage_DeleteRequested" />
                </Grid>
            </SplitView>
        </Grid>
        <Grid x:Name="gridExport" Visibility="Collapsed">
            <local:PhotosExportPage x:Name="photosExportPage" Visibility="{Binding Visibility, ElementName=gridExport}" FoundNewItemsForExport="_photosExportPage_FoundNewItemsForExport" HideExportPageRequested="_photosExportPage_HideExportPageRequested" DeleteItemsRequested="_photosExportPage_DeleteRequested" AndroidClient="{x:Bind AndroidClient, Mode=OneWay}" />
        </Grid>
        <ContentDialog x:Name="dialogPickExportDirectory" x:Uid="DialogPickExportDirectory" Title="XX Export New Photos" PrimaryButtonText="XX Browse" IsPrimaryButtonEnabled="True" CloseButtonText="XX Cancel" DefaultButton="Primary">
            <StackPanel>
                <TextBlock x:Uid="DialogPickExportDirectoryLineOne" Text="XX Droid Transfer can automatically detect new photos on your connected device that are not in your chosen export folder on your PC." TextWrapping="Wrap" />
                <TextBlock x:Uid="DialogPickExportDirectoryLineTwo" Text="XX Click 'Browse' to select the export folder you wish to use. This only needs to be done once and can be changed within Settings > Photos." TextWrapping="Wrap" Style="{ThemeResource CaptionTextBlockStyle}" Margin="0,10,0,0" />
            </StackPanel>
        </ContentDialog>
        <ContentDialog x:Name="dialogNewPhotosDetected" x:Uid="DialogNewPhotosDetected" Title="XX New Photos Detected" PrimaryButtonText="XX View New Photos" IsPrimaryButtonEnabled="True" CloseButtonText="XX Close" DefaultButton="Primary">
            <StackPanel>
                <TextBlock x:Uid="DialogNewPhotosDetectedLineOne" Text="XX Droid Transfer detected new photos on your device that are not in your selected export folder." TextWrapping="Wrap" />
                <CheckBox x:Uid="DialogNewPhotosDetectedCheckBox" Content="XX Automatically detect new photos when loading photos." IsChecked="True" Margin="0,15,0,0" />
            </StackPanel>
        </ContentDialog>
        <dialogs:ConfirmDeleteMediaContentDialog x:Name="dialogConfirmDelete" />
        <dialogs:SdCardDetectedContentDialog x:Name="dialogSdCardDetected" />
        <dialogs:ExternalPermissionsRequiredContentDialog x:Name="dialogExternalPermissionsRequired" />
        <dialogs:ExternalPermissionsRequestedContentDialog x:Name="dialogExternalPermissionsRequested" />
        <dialogs:RequestFullFilesPermissionsContentDialog x:Name="dialogFullFilesPermissions" ShowAltText="True" />
    </Grid>
</featurebase:FeaturePage>
