<UserControl x:Class="PDF_Office.Views.HomePanel.RecentFiles.RecentFilesContent"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:PDF_Office.Views.HomePanel.RecentFiles"
             xmlns:customControl ="clr-namespace:PDF_Office.CustomControl"
             xmlns:DataConvert ="clr-namespace:PDF_Office.DataConvert"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:prism ="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             mc:Ignorable="d" Loaded="UserControl_Loaded"
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../../Styles/ListViewStyle.xaml" />
                <ResourceDictionary Source="../../../Styles/CustomBtnStyle.xaml" />
                <ResourceDictionary Source="../../../Styles/RadioButtonStyle.xaml" />
                <ResourceDictionary Source="../../../Styles/ButtonStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <DataConvert:BoolToVisible x:Key="BoolToVisible" />
            <DataConvert:InvertBoolToVisibleConvert x:Key="InvertBoolToVisibleConvert" />
            <DataConvert:InvertBoolConvert x:Key="InvertBoolConvert" />

            <DataTemplate x:Key="listviewItem">
                <local:DocItemListViewControl HorizontalAlignment="Stretch"
                                              OpenFileItemHandler ="DocItemListViewControl_OpenFileItemHandler"
                                              DeleteItemHandler="DocItemListViewControl_DeleteItemHandler" />
            </DataTemplate>

            <DataTemplate x:Key="gridviewItem">
                <local:DocItemControl HorizontalAlignment="Stretch" />
            </DataTemplate>

            <ItemsPanelTemplate x:Key="listPanel">
                <StackPanel Orientation="Vertical" />
            </ItemsPanelTemplate>

            <ItemsPanelTemplate x:Key="gridPanel">
                <WrapPanel />
            </ItemsPanelTemplate>

            <ContextMenu x:Key="FlyoutMenu" FontSize="14"
                         Opened="ContextMenu_Opened">
                <ContextMenu.ItemContainerStyle>
                    <Style TargetType="MenuItem">
                        <Setter Property="Padding" Value="0,7,0,7" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                </ContextMenu.ItemContainerStyle>
                <MenuItem Name="FilePathMenuItem" Header="打开文件路径" IsEnabled="True" Click="FilePathMenuItem_Click">
                    <MenuItem.Icon>
                        <Path Fill="Black"
                              Data="M5.24031 1.5H0.5V14.5H15.5V4H7.24031L5.24031 1.5ZM1.5 13.5V2.5H4.75969L6.75969 5H14.5V13.5H1.5ZM4 7.5H12V6.5H4V7.5Z">
                            <Path.RenderTransform>
                                <TranslateTransform X="3.0000" Y="0" />
                            </Path.RenderTransform>
                        </Path>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Name="DeleteMenuItem" Header="从最近列表删除" IsEnabled="True" Click="DeleteMenuItem_Click">
                    <MenuItem.Icon>
                        <Path Fill="Black" Data="M9 0H3V2H0V3H1V14H11V3H12V2H9V0ZM2 13V3H3H4H8H9H10V13H2ZM8 2V1H4V2H8ZM4 12V4H3V12H4ZM6.5 4V12H5.5V4H6.5ZM9 12V4H8V12H9Z">
                            <Path.RenderTransform>
                                <TranslateTransform X="5.0000" Y="0" />
                            </Path.RenderTransform>
                        </Path>
                    </MenuItem.Icon>
                </MenuItem>
            </ContextMenu>

            <Style x:Key="SubFilesListViewItemStyle" BasedOn="{StaticResource FilesListViewItemStyle}" TargetType="{x:Type ListViewItem}">
                <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}" />
                <Setter Property="HorizontalContentAlignment" Value="Center" />
                <Setter Property="Margin" Value="12,0,0,0" />
                <EventSetter Event="PreviewMouseRightButtonDown"
                             Handler="ListViewItem_PreviewMouseRightButtonDown" />
                <EventSetter Event="PreviewMouseDoubleClick"
                             Handler="RecentFilesList_PreviewMouseDoubleClick">
                </EventSetter>
            </Style>

            <Style x:Key="HomeGridViewItemStyle" BasedOn="{StaticResource FilesGridItemStyle}" TargetType="{x:Type ListViewItem}">
                <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}" />
                <Setter Property="HorizontalContentAlignment" Value="Center" />
                <EventSetter Event="PreviewMouseRightButtonDown"
                             Handler="ListViewItem_PreviewMouseRightButtonDown" />
                <EventSetter Event="PreviewMouseDoubleClick"
                             Handler="RecentFilesList_PreviewMouseDoubleClick" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid x:Name="GridRecentFilesTile" Margin="32,38,0,13">
                <TextBlock x:Name="TxbRecentlyTile" Text="Recent" HorizontalAlignment="Left" FontWeight="Semibold" FontSize="20" Padding="0,6,0,0" Margin="0,0,0,0" />
                <StackPanel x:Name="PnlRightBtns" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,0" Orientation="Horizontal" HorizontalAlignment="Right">
                    <Border  Background="#EEF2F3" Height="30" CornerRadius="4" Padding="1,0,1,0">
                        <StackPanel Orientation="Horizontal">
                            <RadioButton x:Name="BtnListMode" GroupName="Mode" Tag="ListMode" Width="40" Height="28" Foreground="#333333"
                                         HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                                         IsChecked="{Binding IsListMode,Mode=OneTime}"
                                         Style="{StaticResource ListModeRadioBtnStyle}">
                                <Grid  Margin="-5,0,0,0" HorizontalAlignment="Center">
                                    <Path Data="M3 5L17 5" Stroke="{Binding ElementName=BtnListMode,Path=Foreground}" StrokeThickness="1.5" StrokeStartLineCap="Round" />
                                    <Path Data="M3 10H17" Stroke="{Binding ElementName=BtnListMode,Path=Foreground}" StrokeThickness="1.5" StrokeStartLineCap="Round" />
                                    <Path Data="M3 15H17" Stroke="{Binding ElementName=BtnListMode,Path=Foreground}" StrokeThickness="1.5" StrokeStartLineCap="Round" />
                                </Grid>
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Checked">
                                        <i:InvokeCommandAction Command="{Binding ListModeCheckedCommand}" CommandParameter="{Binding ElementName=BtnListMode,Path =Tag}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </RadioButton>

                            <RadioButton x:Name="BtnGridMode" GroupName="Mode" Tag="GridMode" Width="40" Height="28" Foreground="#6B869C"
                                         HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                                         IsChecked="{Binding IsListMode,Converter={StaticResource InvertBoolConvert},Mode=OneTime}"
                                         Style="{StaticResource ListModeRadioBtnStyle}">
                                <Grid  Margin="-5,0,0,0" HorizontalAlignment="Center">
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Rectangle Grid.Row="0" Grid.Column="0" Margin="1" Width="5" Height="5" StrokeThickness="1.5" Stroke="{Binding ElementName=BtnGridMode,Path=Foreground}" StrokeDashCap="Round" />
                                    <Rectangle Grid.Row="0" Grid.Column="1"  Margin="1" Width="5" Height="5" StrokeThickness="1.5" Stroke="{Binding ElementName=BtnGridMode,Path=Foreground}" StrokeDashCap="Round" />
                                    <Rectangle Grid.Row="1" Grid.Column="0"  Margin="1" Width="5" Height="5" StrokeThickness="1.5" Stroke="{Binding ElementName=BtnGridMode,Path=Foreground}" StrokeDashCap="Round" />
                                    <Rectangle Grid.Row="1" Grid.Column="1"  Margin="1" Width="5" Height="5" StrokeThickness="1.5" Stroke="{Binding ElementName=BtnGridMode,Path=Foreground}" StrokeDashCap="Round" />
                                </Grid>
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Checked">
                                        <i:InvokeCommandAction Command="{Binding ListModeCheckedCommand}" CommandParameter="{Binding ElementName=BtnGridMode,Path =Tag}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </RadioButton>
                        </StackPanel>
                    </Border>

                    <Separator  Margin="1 0 1 0" Width="1" Height="16" BorderBrush="#1A000000" BorderThickness="1" />

                    <Button x:Name="BtnDelete" Margin="0" Padding="0,0,0,0" MaxHeight="40" Width="28" Height="28" Background="Transparent" BorderThickness="0"
                            IsEnabled="{Binding IsEmpty,Converter={StaticResource InvertBoolConvert},Mode=OneWay}"
                            Command="{Binding RemoveFilesFromContainerCommand}" CommandParameter="{Binding ElementName=RecentFilesList,Path=SelectedItems}"
                            Style="{StaticResource OnlyContentBtn}" Foreground="#6B6F7D">
                        <Grid Width="20" Height="20">
                            <Path Data="M8 2H12" Stroke="{Binding ElementName=BtnDelete,Path=Foreground}" StrokeThickness="2" StrokeDashCap="Round" />
                            <Path Data="M5 5V17H15V5" Stroke="{Binding ElementName=BtnDelete,Path=Foreground}" StrokeThickness="2" StrokeDashCap="Round" />
                            <Path Data="M17 5H3" Stroke="{Binding ElementName=BtnDelete,Path=Foreground}" StrokeThickness="2" StrokeDashCap="Round" />
                            <Path Data="M10 9V13" Stroke="{Binding ElementName=BtnDelete,Path=Foreground}" StrokeThickness="2" StrokeDashCap="Round" />
                        </Grid>
                    </Button>
                </StackPanel>
            </Grid>

            <Grid  Grid.Row="2" Visibility="{Binding IsEmpty,Converter={StaticResource InvertBoolToVisibleConvert}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="799*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Border Visibility="{Binding IsListMode,Converter={StaticResource BoolToVisible}}">
                    <ListView x:Name="RecentFilesList"
                              ItemsSource="{Binding RecentFilesGroup}"
                              Margin="32,0,0,0"
                              VirtualizingPanel.IsVirtualizing="True"
                              VirtualizingPanel.CacheLengthUnit="Page"
                              VirtualizingPanel.CacheLength="1"
                              VirtualizingPanel.ScrollUnit="Pixel"
                              ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                              ScrollViewer.VerticalScrollBarVisibility="Auto"
                              Background="Transparent" BorderThickness="0"
                              Padding="0,0,0,0" MinHeight="216" MinWidth="380"
                              SelectionMode="Multiple"
                              ItemContainerStyle="{StaticResource SubFilesListViewItemStyle}"
                              Style="{StaticResource FilesListViewStyle}"
                              ItemTemplate="{StaticResource listviewItem}"
                              ItemsPanel="{StaticResource listPanel}" Grid.ColumnSpan="2">
                    </ListView>
                </Border>

                <ListView x:Name="GridRecentFilesList"
                          Visibility="{Binding IsListMode,Converter={StaticResource InvertBoolToVisibleConvert}}"
                          ItemsSource="{Binding RecentFilesGroup}"
                          Margin="32,0,0,0"
                          VirtualizingPanel.IsVirtualizing="True"
                          VirtualizingPanel.CacheLengthUnit="Page"
                          VirtualizingPanel.CacheLength="1"
                          VirtualizingPanel.ScrollUnit="Pixel"
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                          ScrollViewer.VerticalScrollBarVisibility="Auto"
                          Background="Transparent" BorderThickness="0"
                          Padding="0,0,0,0" MinHeight="216" MinWidth="380"
                          SelectionMode="Multiple"
                          ItemContainerStyle="{StaticResource HomeGridViewItemStyle}"
                          Style="{StaticResource FilesGridViewStyle}"
                          ItemTemplate="{StaticResource gridviewItem}"
                          ItemsPanel="{StaticResource gridPanel}" Grid.ColumnSpan="2">
                </ListView>
            </Grid>

            <StackPanel x:Name="BlankContentPanel" Grid.Row="1" Grid.RowSpan="2"  HorizontalAlignment="Center" VerticalAlignment="Center"
                        Visibility="{Binding IsEmpty,Converter={StaticResource BoolToVisible}}">
                <!--<Image Source="../../Resources/Image/Home/empty_recent2x.png" Width="140" Height="140" Stretch="Uniform" VerticalAlignment="Center" />-->
                <TextBlock x:Name="NoFilesText" Text="No documents" TextAlignment="Center"  HorizontalAlignment="Center" FontSize="16" LineHeight="22" Foreground="#FF333333" FontFamily="Segoe UI" />
                <StackPanel Orientation="Horizontal" Margin="0,12,0,0">
                    <TextBlock x:Name="clickFileText" Text="Drop documents here or click the '" Foreground="#FF999999" VerticalAlignment="Center" FontSize="14" />
                    <TextBlock  Margin="2,0,2,0" VerticalAlignment="Center" FontSize="15">
                        <Hyperlink  Command="{Binding OpenFilesCommand}">
                            <TextBlock x:Name="OpenFilesLinkText" Text="Open Files" />
                        </Hyperlink>
                    </TextBlock>
                    <TextBlock x:Name="dropFileText" Text="' button in the Sidebar" Foreground="#FF999999" VerticalAlignment="Center" FontSize="14" />
                </StackPanel>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>