<?xml version="1.0" encoding="utf-8"?>
<messaging:MessagingFeaturePage
    x:Class="was.droidtransfer.features.messaging.messages.MessagesFeaturePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.droidtransfer.features.messaging.messages"
    xmlns:messaging="using:was.droidtransfer.features.messaging"
    xmlns:messagingdata="using:was.droidtransfer.features.messaging.data"
    xmlns:messagingux="using:was.droidtransfer.features.messaging.ux"
    xmlns:commonconverters="using:was.droidtransfer.features.converters"
    xmlns:commoncontrols="using:was.droidtransfer.features.controls"
    xmlns:commondialogs="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" d:DataContext="{d:DesignInstance Type=local:MessagesFeaturePage}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <ResourceDictionary>
            <commonconverters:ByteArrayToBitmapImageConverter x:Key="ByteArrayToBitmapImageConverter"/>
            <commonconverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
            <commonconverters:CollectionToHasItemsBoolConverter x:Key="CollectionToHasItemsBoolConverter" />
        </ResourceDictionary>
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border Style="{ThemeResource PageHeaderBorderStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <messagingux:MessagingAppBarControl x:Name="messagingAppBarControl" Grid.Column="1" CancelOperation="_copyProgressUserControl_OnCancelTapped" SavePdf="_appBarButtonSavePDF_Click" SaveHtml="_appBarButtonSaveWeb_Click" SaveStandardCsv="_appBarButtonSaveStandardCSV_Click" SaveForensicCsv="_appBarButtonSaveForensicCSV_Click" SavePlainText="_appBarButtonSavePlainText_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>
                    <Grid Margin="10,5">
                        <TextBox x:Name="textBoxConversationFilter" x:Uid="textBoxConversationFilter" PlaceholderText="XX Search Messages" TextChanged="_textBoxConversationFilter_TextChanged" />
                        <ProgressBar x:Name="progressBarSearch" IsIndeterminate="True" Height="4" HorizontalContentAlignment="Stretch" VerticalAlignment="Bottom" Visibility="{x:Bind IsSearchInProgress, Mode=OneWay}" />
                    </Grid>

                    <ListView Grid.Row="1" x:Name="listViewConversations" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                       SelectionChanged="_listViewConversations_SelectionChanged" ScrollViewer.HorizontalScrollBarVisibility="Auto"
                       SelectionMode="Extended" IsItemClickEnabled="True" ItemsSource="{Binding Conversations}" ContainerContentChanging="_listViewConversations_ContainerContentChanging">
                        <ListView.ItemTemplate>
                            <DataTemplate x:DataType="messagingdata:IMessageConversation">
                                <StackPanel Orientation="Horizontal" Margin="0,2">
                                    <PersonPicture DisplayName="{x:Bind Title}" PreferSmallImage="True" ProfilePicture="{x:Bind PictureData, Converter={StaticResource ByteArrayToBitmapImageConverter}, Mode=OneWay}" Height="40" Margin="0,0,5,0" x:Phase="1"/>
                                    <TextBlock Text="{x:Bind Title}" VerticalAlignment="Center" TextWrapping="Wrap" Margin="5,0,0,5" HorizontalAlignment="Center" x:Phase="0"  ToolTipService.ToolTip="{x:Bind Title}"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.ContextFlyout>
                            <MenuFlyout Opening="_menuFlyout_Opening">
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemSortByName" Text="XX Sort by Name" Click="_menuFlyoutItemSortByName_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE779;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemSortByLastUpdated" Text="XX Sort by Last Updated" Click="_menuFlyoutItemSortByLastUpdated_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE787;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutSeparator />
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemSavePDF" Text="XX Save As PDF" Click="_menuFlyoutItemSavePDF_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xEA90;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveHTML" Text="XX Save As HTML" Click="_menuFlyoutItemSaveHTML_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE78C;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemSavePlainText" Text="XX Save As Text" Click="_menuFlyoutItemSavePlainText_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xF000;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutSubItem x:Uid="MenuFlyoutItemSaveCSV" Text="XX Save As CSV">
                                    <MenuFlyoutSubItem.Icon>
                                        <FontIcon Glyph="&#xE9F9;" />
                                    </MenuFlyoutSubItem.Icon>
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveStandardCSV" Text="XX Standard" Click="_menuFlyoutItemSaveStandardCSV_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE9F9;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemSaveForensicCSV" Text="XX Forensic" Click="_menuFlyoutItemSaveForensicCSV_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE928;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyoutSubItem>
                                <MenuFlyoutSeparator />
                                <MenuFlyoutItem x:Uid="MenuFlyoutItemPrint" Text="XX Print" Click="_menuFlyoutItemPrint_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE749;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </ListView.ContextFlyout>
                    </ListView>
                    <Grid Grid.Row="1" Visibility="{Binding ItemsSource, ElementName=listViewConversations, Converter={StaticResource CollectionToHasItemsBoolConverter}, ConverterParameter='invert', Mode=OneWay}">
                        <Border Background="{ThemeResource TextFillColorDisabled}" Opacity=".5" />
                        <Border VerticalAlignment="Center" HorizontalAlignment="Center" Background="{ThemeResource TextFillColorInverse}" Padding="20,20,20,20" CornerRadius="8">
                            <StackPanel Spacing="10">
                                <FontIcon Glyph="&#xE8BD;" FontSize="18" />
                                <TextBlock x:Uid="TextBlockNoConversationsFound" Text="No Matches Found" Style="{ThemeResource BodyStrongTextBlockStyle}" Margin="0,0,0,20" />
                                <Button x:Uid="ButtonClearSearch" Content="XX Clear Search" HorizontalAlignment="Stretch" Style="{ThemeResource AccentButtonStyle}" Click="_buttonClearSearch_Click" Visibility="{Binding Text, ElementName=textBoxConversationFilter, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}" />
                                <Button x:Uid="ButtonClearDateFilter" Content="XX Clear Date Filter" HorizontalAlignment="Stretch" Style="{ThemeResource AccentButtonStyle}" Visibility="{Binding DateFilterOptions, ElementName=dialogDateFilter, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}" Click="_buttonClearDateFilter_Click" />
                            </StackPanel>
                        </Border>
                    </Grid>
                    <Grid Grid.Row="1" Visibility="{x:Bind IsSearchInProgress, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}">
                        <Border Background="{ThemeResource TextFillColorDisabled}" Opacity=".5" />
                        <Border VerticalAlignment="Center" HorizontalAlignment="Center" Background="{ThemeResource TextFillColorInverse}" Padding="20,20,20,20" CornerRadius="8">
                            <StackPanel Spacing="10">
                                <ProgressRing IsActive="True" Height="50" Width="50" />
                                <TextBlock x:Uid="TextBlockSearchInProgress" Text="XX Searching..." Style="{ThemeResource BodyStrongTextBlockStyle}" />
                                <TextBlock Text="{x:Bind SearchProgress, Mode=OneWay}" Style="{ThemeResource CaptionTextBlockStyle}" TextAlignment="Center" />
                            </StackPanel>
                        </Border>
                    </Grid>
                    <commoncontrols:ResizeSplitterHandle Grid.RowSpan="2" Grid.Column="1" Margin="0"/>
                </Grid>
            </SplitView.Pane>
            <Grid x:Name="gridContent">
                <messagingux:MessagingThreadContentPage x:Name="messagingThreadPage" AppBarControl="{x:Bind messagingAppBarControl}" OnRequestClearDateFilter="_messagingThreadPage_OnRequestClearDateFilter"/>
            </Grid>
        </SplitView>
        <!-- WebView for use when exporting -->
        <Grid x:Name="gridPrinting" Visibility="Collapsed">
            <commoncontrols:WebViewPDFConverterUserControl x:Name="webViewPdfConverter" />
        </Grid>
        <commoncontrols:WebViewPrintUserControl x:Name="webViewPrintUserControl" Grid.RowSpan="2" Visibility="Collapsed" />
        <commondialogs:DateFilterContentDialog x:Name="dialogDateFilter" />
    </Grid>
</messaging:MessagingFeaturePage>
