<featurebase:FeaturePage
    x:Class="was.touchcopy.features.notes.NotesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:featurebase="using:was.touchcopy.features"
    xmlns:coreconverters="using:was.touchcopy.features.converters"
    xmlns:dialogs="using:was.touchcopy.features.dialogs"
    xmlns:local="using:was.touchcopy.features.notes"
    xmlns:commoncontrols="using:was.touchcopy.features.controls"
    xmlns:converters="using:was.touchcopy.features.notes.converters"
    xmlns:data="using:was.touchcopy.features.notes.data"
    xmlns:utilities="using:was.touchcopy.features.utilities"
    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:NotesPage}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <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="appBarButtonSavePDF" x:Uid="SavePDFAppBarButton" Label="XX Save as PDF" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSavePDF_Click" IsEnabled="{x:Bind local:NotesPage.IsExportingEnabled(notesContentPage.NotesItem, NotesItems), Mode=OneWay}">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xEA90;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSavePDF.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                    <AppBarButton x:Name="appBarButtonSaveHTML" x:Uid="SaveHTMLAppBarButton" Label="XX Save as HTML" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveHTML_Click" IsEnabled="{x:Bind appBarButtonSavePDF.IsEnabled, Mode=OneWay}">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE78C;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSaveHTML.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                    <AppBarButton x:Name="appBarButtonSaveTXT" x:Uid="SaveTXTAppBarButton" Label="XX Save as Text" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonSaveText_Click" IsEnabled="{x:Bind appBarButtonSavePDF.IsEnabled, Mode=OneWay}">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xF000;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonSaveTXT.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                    <AppBarButton x:Name="appBarButtonPrint" x:Uid="AppBarButtonPrint" Label="XX Print" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonPrint_Click" IsEnabled="{x:Bind local:NotesPage.IsPrintingEnabledForItem(notesContentPage.NotesItem), Mode=OneWay}">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE749;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonPrint.IsEnabled), Mode=OneWay}" />
                        </AppBarButton.Content>
                    </AppBarButton>
                    <AppBarSeparator/>
                    <AppBarButton x:Name="appBarButtonFilterDates" x:Uid="FilterDatesAppBarButton" Label="XX Filter Dates" Style="{ThemeResource AppBarButtonStyle}" Click="_appBarButtonFilterDates_Click">
                        <AppBarButton.Content>
                            <FontIcon Glyph="&#xE787;" Foreground="{x:Bind utilities:AppBarUtilities.BrushForAppBarIcon(appBarButtonFilterDates.IsEnabled), Mode=OneWay}"/>
                        </AppBarButton.Content>
                    </AppBarButton>
                </CommandBar>
                <TextBlock Text="{Binding PageTitle, Mode=OneWay}" Style="{ThemeResource PageHeaderTitleStyle}"/>
            </Grid>
        </Border>
        <SplitView Grid.Row="1" Style="{ThemeResource FeatureSplitViewStyle}" OpenPaneLength="400">
            <SplitView.Pane>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="textBoxNotesFilter" x:Uid="NotesFilterTextBox" Margin="10,5" PlaceholderText="XX Search Notes" 
                             TextChanged="_textBoxNotesFilter_TextChanged" />
                    <ScrollViewer Grid.Row="1" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Disabled" Margin="0,0,4,0">
                        <TreeView x:Name="treeViewItems" ItemsSource="{x:Bind NotesItems, Mode=OneWay}" SelectionMode="Multiple" 
                                  KeyUp="_treeViewItems_KeyUp" Margin="0,10,0,0" Tapped="_treeViewItems_Tapped" HorizontalContentAlignment="Stretch"
                                  RightTapped="_treeViewItems_RightTapped" DoubleTapped="_treeViewItems_DoubleTapped"
                                  IsDoubleTapEnabled="True">
                            <TreeView.ItemTemplate>
                                <DataTemplate x:DataType="data:INotesItem">
                                    <data:NotesTreeViewItem x:Name="treeViewItem">
                                        <Grid  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <FontIcon Glyph="{Binding Path=Glyph, ElementName=treeViewItem, Mode=OneWay}" Margin="-5,0,10,0" />
                                            <TextBlock Text="{x:Bind Title}" Grid.Column="1"  ToolTipService.ToolTip="{x:Bind Title}" 
                                                       TextTrimming="CharacterEllipsis"  VerticalAlignment="Center" />
                                        </Grid>
                                    </data:NotesTreeViewItem>
                                </DataTemplate>
                            </TreeView.ItemTemplate>
                            <TreeView.ContextFlyout>
                                <MenuFlyout>
                                    <MenuFlyoutItem x:Uid="SaveHTMLFlyoutItem" Text="XX Save as HTML" Click="_appBarButtonSaveHTML_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE78C;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="SavePDFFlyoutItem" Text="XX Save as PDF" Click="_appBarButtonSavePDF_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xEA90;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="SaveTXTFlyoutItem" Text="XX Save as Text" Click="_appBarButtonSaveText_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xF000;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutSeparator />
                                    <MenuFlyoutItem x:Uid="SortByNameFlyoutItem" Text="Sort by Name" Click="_sortByNameMenuFlyoutItem_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE84B;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="SortByLastUpdatedFlyoutItem" Text="Sort by Last Updated" Click="_sortByLastUpdatedMenuFlyoutItem_Click">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE787;" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </TreeView.ContextFlyout>
                        </TreeView>
                    </ScrollViewer>
                    <commoncontrols:ResizeSplitterHandle Grid.Column="1" Grid.RowSpan="2" />
                </Grid>
            </SplitView.Pane>
            <Grid  x:Name="gridContent">
                <local:NotesContentPage x:Name="notesContentPage" SaveMediaRequested="_notesContentPage_SaveMediaRequested"/>
            </Grid>
        </SplitView>

        <dialogs:DateFilterContentDialog x:Name="dialogDateFilter" />
        <commoncontrols:WebViewPrintUserControl x:Name="webViewPrintUserControl" Grid.RowSpan="2" Visibility="Collapsed" />
    </Grid>
</featurebase:FeaturePage>
