<?xml version="1.0" encoding="utf-8"?>
<featurebase:FeaturePage
    x:Class="was.droidtransfer.features.contacts.ContactsFeaturePage"
    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.contacts"
    xmlns:contactsdata="using:was.std.android.contacts.data"
    xmlns:converters="using:was.droidtransfer.features.contacts.converters"
    xmlns:commonconverters="using:was.droidtransfer.features.converters"
    xmlns:commoncontrols="using:was.droidtransfer.features.controls"
    xmlns:iocontrols="using:was.droidtransfer.features.contacts.io.controls"
    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>
        <converters:ContactGroupToTitleStringConverter x:Key="ContactGroupToTitleStringConverter" />
        <commonconverters:ListCountToVisibilityConverter x:Key="ListCountToVisibilityConverter" />
        <commonconverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
    </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="appBarButtonBackupRestore" x:Uid="appBarButtonBackupRestore" Label=" XX Backup &amp; Restore" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonBackupRestore_Click" IsEnabled="{x:Bind IsImportAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE8AB;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonSaveVCard" x:Uid="appBarButtonSaveVCard" Label="XX Save as VCard" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveVCard_Click" IsEnabled="{x:Bind IsExportAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE779;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonSaveCSV" x:Uid="appBarButtonSaveCSV" Label="XX Save as CSV" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveCSV_Click" IsEnabled="{x:Bind IsExportAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE9F9;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonAdd" x:Uid="appBarButtonAddContacts" Label="XX Add Contacts to Device" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonAddContactsToDevice_Click" IsEnabled="{x:Bind IsImportAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE898;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonDelete" x:Uid="DeleteSelectionButton"  Label="XX Delete Selection" Style="{ThemeResource AppBarButtonStyle}" Click="_deleteSelectionAppBarButton_Click" IsEnabled="{x:Bind IsDeleteAvailable, Mode=OneWay}" >
                            <AppBarButton.Icon>
                                <SymbolIcon Symbol="Delete" Foreground="{ThemeResource AccentFillColorDefaultBrush}" Visibility="{x:Bind appBarButtonDelete.IsEnabled, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}"/>
                            </AppBarButton.Icon>
                        </AppBarButton>
                    </CommandBar>
                    <TextBlock Text="{x:Bind PageTitle, Mode=OneWay}" Style="{ThemeResource PageHeaderTitleStyle}"/>
                </Grid>
            </Border>
            <SplitView x:Name="splitViewContacts" Grid.Row="1" OpenPaneLength="300" Style="{ThemeResource FeatureSplitViewStyle}" AllowDrop="True" DragOver="_grid_DragOver" Drop="_grid_Drop" Visibility="{x:Bind AreContactsAvailable, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}">
                <SplitView.Pane>
                    <Grid Margin="0,10,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBox x:Name="textBoxContactsFilter" x:Uid="textBoxContactsFilter" Margin="10,5" PlaceholderText="XX Search Contacts" TextChanged="_textBoxContactsFilter_TextChanged" />
                        <ComboBox x:Name="comboBoxContactGroups" Grid.Row="1" Margin="10,0,10,5" HorizontalAlignment="Stretch" Visibility="{Binding ItemsSource, ElementName=comboBoxContactGroups, Converter={StaticResource ListCountToVisibilityConverter}, ConverterParameter='2', Mode=OneWay}" SelectionChanged="_comboBoxContactGroups_SelectionChanged">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Converter={StaticResource ContactGroupToTitleStringConverter}}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                        <ListView Grid.Row="2" x:Name="listViewContacts" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" SelectionChanged="_listViewContacts_SelectionChanged" SelectionMode="Extended" IsItemClickEnabled="True" ItemsSource="{x:Bind ContactsViewSource.View, Mode=OneWay}">
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="contactsdata:VCardContent">
                                    <StackPanel Orientation="Horizontal" Margin="0,2">
                                        <PersonPicture DisplayName="{x:Bind Initials}" PreferSmallImage="True" ProfilePicture="{x:Bind PictureBitmapImage, Mode=OneWay}" MaxWidth="40" Margin="0,0,5,0"/>
                                        <TextBlock Text="{x:Bind DisplayName}" VerticalAlignment="Center" Margin="0,0,0,5"/>
                                    </StackPanel>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                            <ListView.ContextFlyout>
                                <MenuFlyout Opening="_menuFlyoutContacts_Opening">
                                    <MenuFlyoutItem x:Name="menuFlyoutItemSortByFirstName" x:Uid="FlyoutItemSortByFirstName" Text="XX Sort by First Name" Click="_menuFlyoutItemSortByFirstName_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE779;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Name="menuFlyoutItemSortByLastName" x:Uid="FlyoutItemSortByLastName" Text="XX Sort by Last Name" Click="_menuFlyoutItemSortByLastName_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE779;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutSeparator />
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveVCard" Text="XX Save As VCard" Click="_menuFlyoutItemSaveVCard_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE78C;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveCSV" Text="XX Save As CSV" Click="_menuFlyoutItemSaveCSV_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE9F9;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutSeparator />
                                    <MenuFlyoutItem x:Name="menuFlyoutItemDelete" x:Uid="FlyoutItemDelete" Text="XX Delete" Click="_menuFlyoutItemDelete_Click" IsEnabled="{x:Bind IsDeleteAvailable, Mode=OneWay}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE74D;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </ListView.ContextFlyout>
                        </ListView>
                        <commoncontrols:ResizeSplitterHandle Grid.RowSpan="3" Grid.Column="1" Margin="0"/>
                    </Grid>
                </SplitView.Pane>
                <Grid x:Name="gridContent">
                    <featurebase:ContactsContentPage x:Name="contactsContentPage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Contact="{x:Bind SelectedContact, Mode=OneWay}"/>
                </Grid>
            </SplitView>
            <Grid x:Name="gridNoContacts" Grid.Row="1" VerticalAlignment="Center" RowSpacing="10" MaxWidth="600" Margin="10" Visibility="{x:Bind AreContactsAvailable, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='invert', Mode=OneWay}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Border CornerRadius="8" BorderThickness="2" BorderBrush="{ThemeResource TextBoxForegroundThemeBrush}" HorizontalAlignment="Center" Padding="10" Margin="10">
                    <FontIcon Glyph="&#xE8FA;" FontSize="32" Foreground="{ThemeResource TextBoxForegroundThemeBrush}"/>
                </Border>
                <TextBlock Grid.Row="1" Style="{ThemeResource TitleTextBlockStyle}" FontSize="18" x:Uid="TextBlockNoContactsFoundOnDevice" Text="XX No contacts were found on the connected device." HorizontalAlignment="Center" Margin="0,0,0,24" />
                <Button Grid.Row="2" x:Name="buttonBackup" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Click="_appBarButtonAddContactsToDevice_Click">
                    <StackPanel Spacing="5" Padding="5,10">
                        <TextBlock x:Uid="textBlockAddContactsToDevice" Text="XX Add Contacts to Device" Style="{ThemeResource BodyTextBlockStyle}" FontWeight="Bold" />
                        <TextBlock x:Uid="TextBlockAddContactsToDeviceDescription" Text="XX Add contacts from vCard or CSV files stored on your PC to your Android device. Alternatively, restore contacts from a contacts backup file." Style="{ThemeResource BodyTextBlockStyle}" TextWrapping="Wrap"/>
                    </StackPanel>
                </Button>
            </Grid>
        </Grid>
        <Grid x:Name="gridBackupRestore" Visibility="Collapsed">
            <iocontrols:ContactsBackupRestorePage x:Name="contactsBackupRestorePage" DeviceContactsRequested="_contactsBackupRestorePage_DeviceContactsRequested"  Finished="_contactsBackupRestorePage_Finished" />
        </Grid>
        <Grid x:Name="gridAddToDevice" Visibility="Collapsed">
            <iocontrols:ContactsUploadPage x:Name="contactsUploadPage" DeviceContactsRequested="_contactsBackupRestorePage_DeviceContactsRequested"  Finished="_contactsBackupRestorePage_Finished" />
        </Grid>
        <ContentDialog x:Name="contentDialogRequestWritePermissions" x:Uid="ContentDialogRequestWritePermissions" Title="XX Additional Permissions Required" PrimaryButtonText="XX Retry" CloseButtonText="XX Cancel" DefaultButton="Primary">
            <StackPanel>
                <TextBlock x:Uid="TextBlockRequestWritePermissionsLineOne" Text="XX Transfer Companion requires write permissions to perform this task. Your Android device is waiting for you to give Transfer Companion this permission." Style="{ThemeResource BodyTextBlockStyle}" />
                <TextBlock x:Uid="TextBlockRequestWritePermissionsLineTwo" Text="XX Tap the Allow button on your Android device and then click the Retry button below to continue." Style="{ThemeResource BodyTextBlockStyle}" />
            </StackPanel>
        </ContentDialog>
        <ContentDialog x:Name="contentDialogConfirmDelete" x:Uid="ContentDialogConfirmDelete" Title="XX Are you sure that you wish to delete the selected contacts?" PrimaryButtonText="XX Delete" CloseButtonText="XX Cancel" DefaultButton="Close">
            <TextBlock x:Uid="TextBlockConfirmDeleteWarning" Style="{ThemeResource BodyTextBlockStyle}" Foreground="{ThemeResource SystemErrorTextColor}" Text="XX The contacts will be deleted from the device an dconnect be recovered once deleted." />
        </ContentDialog>
    </Grid>
</featurebase:FeaturePage>
