<messaging:MessagingFeaturePage
    x:Class="was.touchcopy.features.messaging.messages.MessagesPage"
    xmlns:featurebase="using:was.touchcopy.features"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.touchcopy.features.messaging.messages"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:messaging="using:was.touchcopy.features.messaging"
    xmlns:commonconverters="using:was.touchcopy.features.converters"
    xmlns:commoncontrols="using:was.touchcopy.features.controls"  
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:messagingUX="using:was.touchcopy.features.messaging.ux"
    mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=local:MessagesPage}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
   <Page.Resources>
        <ResourceDictionary>
            <commonconverters:ByteArrayToBitmapImageConverter x:Key="ByteArrayToBitmapImageConverter"/>
        </ResourceDictionary>
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border Style="{ThemeResource PageHeaderBorderStyle}" Background="{ThemeResource AppBarBackgroundThemeBrush}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <messagingUX:MessagingAppBarControl Grid.Column="1" x:Name="messagingAppBarControl" CancelOperation="CopyProgressUserControl_OnCancelTapped" SavePdf="AppBarButtonSavePDF_Click" SaveHtml="AppBarButtonSaveWeb_Click" SavePlainText="AppBarButtonSavePlainText_Click" SaveCsv="AppBarButtonSaveCsv_Click" SaveAttachments="AppBarButtonSaveAttachments_Click" ViewAttachments="AppBarButtonViewAttachments_Click" Print="AppBarButtonPrint_Click" FilterDates="AppBarButtonFilterDates_Click" />
                <TextBlock Text="{Binding PageTitle }" Style="{ThemeResource PageHeaderTitleStyle}" />
            </Grid>
        </Border>

        <SplitView Grid.Row="1" OpenPaneLength="300" Style="{ThemeResource FeatureSplitViewStyle}">
            <SplitView.Pane>
                <Grid Margin="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="textBoxConversationFilter" x:Uid="textBoxConversationFilter" Margin="10,5" PlaceholderText="XX Search Messages" 
                             TextChanged="TextBoxConversationFilter_TextChanged" />
                    <ListView Grid.Row="1" x:Name="listViewConversations" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                          SelectionChanged="ListViewConversations_SelectionChanged" ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="0,0,2,0"
                          SelectionMode="Extended" IsItemClickEnabled="True" ItemsSource="{Binding ConversationGroups.View}">
                        <ListView.GroupStyle>
                            <GroupStyle HidesIfEmpty="True">
                                <GroupStyle.HeaderTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Header}" Margin="0,5,0,0" />
                                    </DataTemplate>
                                </GroupStyle.HeaderTemplate>
                            </GroupStyle>
                        </ListView.GroupStyle>
                        <ListView.ItemTemplate>
                            <DataTemplate x:DataType="messaging:MessageConversation">
                                <Grid Margin="0,2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="auto"/>
                                    </Grid.ColumnDefinitions>
                                    <PersonPicture DisplayName="{x:Bind Title}" PreferSmallImage="True" ProfilePicture="{x:Bind HeaderBitmapImageTask.Result, Mode=OneWay}" Height="40" Margin="0,0,5,0"/>
                                    <TextBlock HorizontalAlignment="Left" Grid.Column="1" TextAlignment="Left" Text="{x:Bind Title}" VerticalAlignment="Center"  
                                               TextTrimming="CharacterEllipsis" Margin="5,0,0,5" ToolTipService.ToolTip="{x:Bind Title}"/>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.ContextFlyout>
                            <MenuFlyout>
                                <MenuFlyoutItem x:Name="menuFlyoutItemSortByName" x:Uid="FlyoutItemSortByName" Text="XX Sort by Name" Click="_menuFlyoutItemSortByName_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE779;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem x:Name="menuFlyoutItemSortByLastUpdated" x:Uid="FlyoutItemSortByLastUpdated" Text="XX Sort by Last Updated" Click="_menuFlyoutItemSortByLastUpdated_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE787;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </ListView.ContextFlyout>
                    </ListView>
                    <commoncontrols:ResizeSplitterHandle Grid.RowSpan="2" Grid.Column="1" Margin="0"/>
                </Grid>
                
            </SplitView.Pane>
            <Grid x:Name="gridContent" CornerRadius="{ThemeResource GridViewItemCornerRadius}">
                <messagingUX:MessagingThreadContentPage x:Name="messagingThreadPage" AppBarControl="{x:Bind messagingAppBarControl}" Background="Transparent"/>
            </Grid>
        </SplitView>
        <!-- WebView for use when printing -->
        <commoncontrols:WebViewPrintUserControl x:Name="webViewPrintUserControl" Grid.RowSpan="2" Visibility="Collapsed" />
    </Grid>
</messaging:MessagingFeaturePage>
