<Page
    x:Class="was.touchcopy.features.notes.NotesContentPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.touchcopy.features.notes"
    xmlns:data="using:was.touchcopy.features.notes.data"
    xmlns:featurebase="using:was.touchcopy.features"
    xmlns:featurecontrols="using:was.touchcopy.features.controls"
    xmlns:converters="using:was.touchcopy.features.notes.converters"
    xmlns:fconverters="using:was.touchcopy.features.converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" >
    <Page.Resources>
        <ResourceDictionary>
            <converters:VisualNoteContentToMaxDimensionConverter x:Key="VisualNoteContentToMaxDimensionConverter" />
            <fconverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
            
            <!-- Text -->
            <DataTemplate x:Key="TextDataTemplate" x:DataType="data:TextNoteContent">
                <Grid Margin="0,0,0,2">
                    <featurecontrols:HyperlinkTextBlock Text="{x:Bind Text}" TextWrapping="Wrap" />
                </Grid>
            </DataTemplate>

            <!-- Checkbox -->
            <DataTemplate x:Key="CheckBoxDataTemplate" x:DataType="data:TextNoteContent">
                <Grid Margin="0,0,0,2">
                    <local:RichTextBlockAndCheckBoxes Text="{x:Bind Text}" />
                </Grid>
            </DataTemplate>
            
            <!-- Image -->
            <DataTemplate x:Key="ImageDataTemplate" x:DataType="data:VisualNoteContent">
                <Grid Margin="30,0,30,0">
                    <Border CornerRadius="8" MaxWidth="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=width, Mode=OneWay}"
 MaxHeight="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=height, Mode=OneWay}" HorizontalAlignment="Left">
                        <Image Source="{Binding ContentBitmapImage, Mode=OneWay}" HorizontalAlignment="Left"
                           MaxWidth="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=width, Mode=OneWay}"
                           MaxHeight="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=height, Mode=OneWay}"
                           IsDoubleTapEnabled="True" DoubleTapped="_image_DoubleTapped">
                        </Image>
                        <Border.ContextFlyout>
                            <MenuFlyout>
                                <MenuFlyoutItem x:Uid="ImageSaveToPCMenuItem" Text="XX Save to PC" Click="_saveVisualContent_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE78C;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem x:Uid="ImagePreviewMenuItem" Text="XX Preview" Click="_previewVisualContent_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE890;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </Border.ContextFlyout>
                    </Border>
                </Grid>
            </DataTemplate>
            
            <!-- Scanned Document (PDF) -->
            <DataTemplate x:Key="ScannedDocumentTemplate" x:DataType="data:VisualNoteContent">
                <!--<Grid Margin="30,0,30,0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock x:Uid="TextBlockPDFDocumentHeader" Text="XX PDF Document..." FontSize="{ThemeResource CaptionTextBlockFontSize}" 
                               Foreground="{ThemeResource TextBoxButtonForegroundThemeBrush}"
                               Margin="0,0,0,5"/>
                    <Border Grid.Row="1" CornerRadius="8" MaxWidth="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=width, Mode=OneWay}"
MaxHeight="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=height, Mode=OneWay}" HorizontalAlignment="Left">
                        <Grid HorizontalAlignment="Left"
  MaxWidth="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=width, Mode=OneWay}"
  MaxHeight="{Binding Converter={StaticResource VisualNoteContentToMaxDimensionConverter}, ConverterParameter=height, Mode=OneWay}">

                            <Image Source="{Binding ContentBitmapImage, Mode=OneWay}" HorizontalAlignment="Left"
  IsDoubleTapEnabled="False" />

                            <Border x:Name="borderControls"  HorizontalAlignment="Right" VerticalAlignment="Top" 
         Background="{ThemeResource TextFillColorInverse}" Padding="3" Margin="5" CornerRadius="6">

                                <StackPanel Orientation="Horizontal">
                                    <Button Click="_saveVisualContent_Click" BorderThickness="2" BorderBrush="{ThemeResource ButtonBorderThemeBrush}" Background="Transparent" CornerRadius="4,0,0,4" Foreground="{ThemeResource TextFillColorPrimary}">
                                        <FontIcon Glyph="&#xE78C;" />
                                        <ToolTipService.ToolTip>
                                            <ToolTip x:Uid="SaveToPCToolTip" Content="Save to PC" />
                                        </ToolTipService.ToolTip>
                                    </Button>
                                    <AppBarSeparator />
                                </StackPanel>
                            </Border>
                        </Grid>
                        <Border.ContextFlyout>
                            <MenuFlyout>
                                <MenuFlyoutItem x:Uid="ImageSaveToPCMenuItem" Text="XX Save to PC" Click="_saveVisualContent_Click">
                                    <MenuFlyoutItem.Icon>
                                        <FontIcon Glyph="&#xE78C;" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </Border.ContextFlyout>
                    </Border>
                </Grid>-->
                <Border BorderBrush="{StaticResource SystemAccentColorLight1}" BorderThickness="2" CornerRadius="8" HorizontalAlignment="Left" Padding="10">
                    <Grid ColumnSpacing="5" RowSpacing="10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <FontIcon Glyph="&#xEA90;" FontSize="24" VerticalAlignment="Top" />
                        <TextBlock Grid.Column="1" Text="{Binding Title}" Style="{ThemeResource BodyStrongTextBlockStyle}"/>
                        <Button Grid.Row="1" Grid.ColumnSpan="2" x:Uid="ButtonPDFSaveToPC" Click="_saveVisualContent_Click" Style="{ThemeResource AccentButtonStyle}" Content="XX Save to PC" HorizontalAlignment="Left">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Uid="SaveToPCToolTip" Content="XX Save to PC" />
                            </ToolTipService.ToolTip>
                        </Button>
                    </Grid>
                </Border>
            </DataTemplate>
            
            <!-- Video -->
            <DataTemplate x:Key="VideoDataTemplate" x:DataType="data:VisualNoteContent">
                <Border CornerRadius="8" HorizontalAlignment="Left">
                    <featurecontrols:VideoFileViewerControl HorizontalAlignment="Left" Margin="0,0,0,0" BackupFile="{x:Bind File}" Height="480" MaxWidth="600"/>
                </Border>
            </DataTemplate>
            
            <!-- Audio -->
            <DataTemplate x:Key="AudioDataTemplate" x:DataType="data:AudioNoteContent">
                <featurecontrols:MediaPlayerUserControl x:Name="mediaPlayerControl" BackupFile="{x:Bind File}" CreationDate="{x:Bind CreationDateTime}" HorizontalAlignment="Left"
                                                        Width="400" DownloadClicked="_saveVisualContent_Click" DataContext="{x:Bind}" />
            </DataTemplate>
            
            <!-- Shared Text -->
            <DataTemplate x:Key="SharedTextTemplate" x:DataType="data:TextNoteContent">
                <Border Margin="0,0,0,2" Background="{ThemeResource SystemControlBackgroundBaseLowBrush}" Padding="5" CornerRadius="5">
                    <StackPanel Spacing="2">
                        <TextBlock Text="{x:Bind Text}" TextWrapping="Wrap" />
                        <TextBlock Text="{x:Bind ContentLocation}" TextWrapping="Wrap" Foreground="{ThemeResource HyperlinkForegroundThemeBrush}" Visibility="{x:Bind ContentLocation, Converter={StaticResource ValueToVisibilityConverter}}" Tapped="_urlLink_Tapped" PointerEntered="_sharedTextUrl_PointerEntered" PointerExited="_sharedTextUrl_PointerExited" />
                    </StackPanel>
                </Border>
            </DataTemplate>
            
            <!-- URL -->
            <DataTemplate x:Key="UrlDataTemplate" x:DataType="data:VisualNoteContent">
                <Border Margin="0,0,0,2"  Background="{ThemeResource SystemControlBackgroundBaseLowBrush}" Padding="10" CornerRadius="5" HorizontalAlignment="Left">
                    <StackPanel Spacing="2" >
                        <Image Source="{x:Bind ContentBitmapImage, Mode=OneWay}" HorizontalAlignment="Center"
                               Tapped="_urlLink_Tapped" Width="150" Tag="{x:Bind UrlString}">
                        </Image>
                        <TextBlock  Text="{x:Bind UrlString}" TextWrapping="Wrap" Foreground="{ThemeResource HyperlinkForegroundThemeBrush}"  Tapped="_urlLink_Tapped" />
                    </StackPanel>
                </Border>
            </DataTemplate>
            
            
            
            <!-- Unsupported -->
            <DataTemplate x:Key="UnsupportedDataTemplate" x:DataType="data:IMediaNoteContent">
                <Border Margin="0,5,0,5" Padding="8" BorderBrush="{StaticResource SystemAccentColorLight1}" BorderThickness="2" CornerRadius="8" HorizontalAlignment="Left">
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <FontIcon Glyph="&#xE783;" VerticalAlignment="Top" Margin="0,4,0,0"/>
                        <StackPanel>
                            <TextBlock x:Uid="UnsupportedDataTypeLabel" Text="Unsupported data type." VerticalAlignment="Center"  FontWeight="Bold"/>
                            <TextBlock Text="{x:Bind utiType}"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
            </DataTemplate>
            
            <local:NotesContentTemplateSelector x:Key="ContentTemplateSelector" TextDataTemplate="{StaticResource TextDataTemplate}" ImageDataTemplate="{StaticResource ImageDataTemplate}" 
                                                VideoDataTemplate="{StaticResource VideoDataTemplate}" AudioDataTemplate="{StaticResource AudioDataTemplate}" 
                                                SharedTextTemplate="{StaticResource SharedTextTemplate}" UrlDataTemplate="{StaticResource UrlDataTemplate}" 
                                                UnsupportedDataTemplate="{StaticResource UnsupportedDataTemplate}" CheckBoxDataTemplate="{StaticResource CheckBoxDataTemplate}"
                                                ScannedDocumentTemplate="{StaticResource ScannedDocumentTemplate}"/>
        </ResourceDictionary>
    </Page.Resources>
    <Border Style="{ThemeResource FeatureContentPageBorder}" Padding="0">
        <Grid>
            <Grid Visibility="{x:Bind local:NotesContentPage.VisibilityIfNoteSummary(NotesItem), Mode=OneWay}"  Background="{ThemeResource CardBackgroundFillColorDefaultBrush}">
                <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="20,20,20,0">
                    <Grid>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{x:Bind NotesItem.Title, Mode=OneWay}" Style="{ThemeResource TitleTextBlockStyle}" TextTrimming="WordEllipsis" TextWrapping="NoWrap" />
                            <TextBlock Text="{x:Bind local:NotesContentPage.CreateDateString(NotesItem), Mode=OneWay}" Style="{ThemeResource BaseTextBlockStyle}" />
                            <ItemsRepeater ItemsSource="{x:Bind NoteContents, Mode=OneWay}" Margin="0,10,0,0" ItemTemplate="{StaticResource ContentTemplateSelector}">
                                <ItemsRepeater.Layout>
                                    <StackLayout Orientation="Vertical" />
                                </ItemsRepeater.Layout>
                            </ItemsRepeater>
                        </StackPanel>
                    </Grid>
                </ScrollViewer>
                <featurebase:ImagePreviewPage x:Name="imagePreviewPage" Visibility="Collapsed" Padding="30"/>
            </Grid>
            <Grid Visibility="{x:Bind local:NotesContentPage.VisibilityIfNotesFolder(NotesItem), Mode=OneWay}">
                <StackPanel VerticalAlignment="Center">
                    <FontIcon Glyph="&#xED43;" FontSize="42" Margin="0,0,0,10" />
                    <TextBlock Text="{x:Bind NotesItem.Title, Mode=OneWay}" Style="{ThemeResource TitleTextBlockStyle}" TextAlignment="Center" TextWrapping="Wrap" Margin="0,0,0,5" />
                    <TextBlock Text="{x:Bind local:NotesContentPage.CreateNotesCountString(NotesItem), Mode=OneWay}" FontSize="16" TextAlignment="Center" Opacity=".7" />
                </StackPanel>
            </Grid>
        </Grid>
    </Border>
</Page>
