<?xml version="1.0" encoding="utf-8"?>
<featurebase:FeaturePage
    x:Class="was.droidtransfer.features.calllogs.CallLogsFeaturePage"
    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.calllogs"
    xmlns:data="using:was.droidtransfer.features.calllogs.data"
    xmlns:converters="using:was.droidtransfer.features.calllogs.converters"
    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:CallLogsFeaturePage}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <converters:CallLogToFontIconGlyphConverter x:Key="CallLogToFontIconGlyphConverter" />
        <converters:EnumerableHasItemsConverter x:Key="EnumerableHasItemsConverter" />
        <commonconverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
    </Page.Resources>
    <Grid>
        <Grid x:Name="gridMain" Visibility="Collapsed">
            <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="appBarButtonSavePDF" x:Uid="AppBarButtonSavePDF" Label="XX Save as PDF" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSavePDF_Click" IsEnabled="{x:Bind IsExportAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xEA90;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarButton x:Name="appBarButtonSaveHTML" x:Uid="AppBarButtonSaveHTML" Label="XX Save as HTML" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveHTML_Click" IsEnabled="{x:Bind IsExportAvailable, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE78C;" 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="appBarButtonPrint" x:Uid="AppBarButtonPrint" Label="XX Print" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonPrint_Click" IsEnabled="{x:Bind SelectedCallLog, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE749;" Foreground="{ThemeResource AccentFillColorDefaultBrush}" Visibility="{x:Bind appBarButtonPrint.IsEnabled, Converter={StaticResource ValueToVisibilityConverter}, Mode=OneWay}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                        <AppBarSeparator/>
                        <AppBarButton x:Name="appBarButtonFilterDates" x:Uid="AppBarButtonFilterDates" Label="Filter Dates" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonFilterDates_Click">
                            <AppBarButton.Content>
                                <FontIcon Glyph="&#xE787;" Foreground="{ThemeResource AccentFillColorDefaultBrush}"/>
                            </AppBarButton.Content>
                        </AppBarButton>
                    </CommandBar>
                    <TextBlock Text="{x:Bind PageTitle}" Style="{ThemeResource PageHeaderTitleStyle}"/>
                </Grid>
            </Border>
            <SplitView Grid.Row="1" OpenPaneLength="300" Style="{ThemeResource FeatureSplitViewStyle}">
                <SplitView.Pane>
                    <Grid Margin="0,10,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBox x:Name="textBoxCallLogsFilter" x:Uid="CallLogsFilterTextBox" Margin="10,5" PlaceholderText="XX Search Call Logs" 
                     TextChanged="_textBoxCallLogsFilter_TextChanged" />
                        <ListView x:Name="listViewCallLogs" Grid.Row="1" SelectionMode="Extended" ItemsSource="{x:Bind CallLogsViewSource.View, Mode=OneWay}"
                          SelectionChanged="_listViewCallLogs_SelectionChanged">
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="data:CallLog">
                                    <Grid ColumnSpacing="8">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="auto" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <FontIcon Glyph="{x:Bind Converter={StaticResource CallLogToFontIconGlyphConverter}}" />
                                        <TextBlock Grid.Column="1" Text="{x:Bind DisplayName}" TextTrimming="CharacterEllipsis" />
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                            <ListView.ContextFlyout>
                                <MenuFlyout Opening="_menuFlyoutCallLogs_Opening">
                                    <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>
                                    <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="MenuFlyoutItemSaveCSV" Text="XX Save As CSV" Click="_menuFlyoutItemSaveCSV_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE9F9;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutSeparator />
                                    <MenuFlyoutItem x:Uid="MenuFlyoutItemPrint" Text="XX Print" Click="_menuFlyoutItemPrint_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE749;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </ListView.ContextFlyout>
                        </ListView>
                        <commoncontrols:ResizeSplitterHandle Grid.RowSpan="2" Grid.Column="1" Margin="0"/>
                    </Grid>
                </SplitView.Pane>
                <Grid x:Name="gridContent">
                    <local:CallLogsContentPage x:Name="callLogsContentPage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CallLog="{x:Bind SelectedCallLog, Mode=OneWay}" DateFilterOptions="{x:Bind DateFilterOptions, Mode=OneWay}" SearchTerm="{x:Bind textBoxCallLogsFilter.Text, Mode=OneWay}" HasCallLogs="{x:Bind CallLogsViewSource.View, Converter={StaticResource EnumerableHasItemsConverter}, Mode=OneWay}"  ClearDateFilterRequested="_callLogsContentPage_ClearDateFilterRequested" ClearSearchTermRequested="_callLogsContentPage_ClearSearchTermRequested" />
                </Grid>
            </SplitView>
            <commondialogs:DateFilterContentDialog x:Name="dialogDateFilter" />
        </Grid>
        <!-- WebView for use when exporting -->
        <Grid x:Name="gridPrinting" Visibility="Collapsed">
            <commoncontrols:WebViewPDFConverterUserControl x:Name="webView" Visibility="Collapsed" />
        </Grid>
        <commoncontrols:WebViewPrintUserControl x:Name="webViewPrintUserControl" Grid.RowSpan="2" Visibility="Collapsed" />
    </Grid>
</featurebase:FeaturePage>
