<featurebase:FeaturePage 
    x:Class="was.touchcopy.features.contacts.ContactsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:featurebase="using:was.touchcopy.features"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.touchcopy.features.contacts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:contactdb="using:was.mobiledevice.contactsdatabase" 
    xmlns:controls="using:was.touchcopy.features.controls"
    xmlns:converters="using:was.touchcopy.features.contacts.converters"
    xmlns:commonconverters="using:was.touchcopy.features.converters"
    xmlns:utilities="using:was.touchcopy.features.utilities"
    mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=local:ContactsPage}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <commonconverters:ByteArrayToBitmapImageConverter x:Key="ByteArrayToBitmapImageConverter"/>
            <converters:ContactNameToDisplayStringConverter x:Key="ContactNameToDisplayStringConverter" />
            <converters:ContactAccountsToComboBoxListSourceConverter x:Key="ContactAccountsToComboBoxListSourceConverter" />
            <converters:ContactAccountsToComboListVisibilityConverter x:Key="ContactAccountsToComboListVisibilityConverter" />
            <converters:ContactListToComboListItemLabelConverter x:Key="ContactListToComboListItemLabelConverter" />
        </ResourceDictionary>
    </Page.Resources>
    <Grid>
        <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="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="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSaveVCard.IsEnabled), Mode=OneWay}"/>
                        </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="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSaveCSV.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                </CommandBar>
                <TextBlock Text="{Binding PageTitle }" Style="{ThemeResource PageHeaderTitleStyle}"/>
            </Grid>
        </Border>

        <SplitView Grid.Row="1" Style="{ThemeResource FeatureSplitViewStyle}" OpenPaneLength="300">
            <SplitView.Pane>
                <Grid>
                    <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 Grid.Row="1" x:Name="comboBoxLists"  Margin="10,0,10,5" ItemsSource="{Binding ContactAccounts, Converter={StaticResource ContactAccountsToComboBoxListSourceConverter}}" SelectionChanged="ComboBoxLists_SelectionChanged" Visibility="{Binding ContactAccounts, Converter={StaticResource ContactAccountsToComboListVisibilityConverter} }" HorizontalAlignment="Stretch">
                        <ComboBox.ItemTemplate>
                            <DataTemplate x:DataType="contactdb:ContactList">
                                <TextBlock Text="{Binding Converter={StaticResource ContactListToComboListItemLabelConverter}}"/>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                    <ListView Grid.Row="2" x:Name="listViewContacts"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                          SelectionChanged="ListViewContacts_SelectionChanged" 
                          SelectionMode="Extended" IsItemClickEnabled="True" ItemsSource="{Binding ContactCards}">
                        <ListView.ItemTemplate>
                            <DataTemplate x:DataType="contactdb:VCardContent">
                                <StackPanel Orientation="Horizontal" Margin="0,2">
                                    <PersonPicture DisplayName="{Binding Text, ElementName=textBlockName}" PreferSmallImage="True" ProfilePicture="{x:Bind PictureData, Converter={StaticResource ByteArrayToBitmapImageConverter}}" MaxWidth="40" Margin="0,0,5,0"/>
                                    <TextBlock x:Name="textBlockName" Text="{x:Bind Converter={StaticResource ContactNameToDisplayStringConverter}}" VerticalAlignment="Center" Margin="0,0,0,5"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.ContextFlyout>
                            <MenuFlyout>
                                <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>
                            </MenuFlyout>
                        </ListView.ContextFlyout>
                    </ListView>
                    <controls:ResizeSplitterHandle Grid.Column="1" Grid.RowSpan="3"/>
                </Grid>
            </SplitView.Pane>
            <Grid  x:Name="gridContent">
                <featurebase:ContactsContentPage x:Name="contactsContentPage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
            </Grid>
        </SplitView>
     
    </Grid>
</featurebase:FeaturePage>
