<UserControl
    x:Class="PDF_Office.Views.ViewContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Viewer="clr-namespace:ComPDFKitViewer.PdfViewer;assembly=ComPDFKit.Viewer"
    xmlns:convert="clr-namespace:PDF_Office.DataConvert"
    xmlns:cus="clr-namespace:PDF_Office.CustomControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:local="clr-namespace:PDF_Office.Views"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:prism="http://prismlibrary.com/"
    xmlns:viewmodels="clr-namespace:PDF_Office.ViewModels"
    d:DataContext="{d:DesignInstance Type=viewmodels:ViewContentViewModel}"
    d:DesignHeight="450"
    d:DesignWidth="800"
    prism:ViewModelLocator.AutoWireViewModel="True"
    KeyDown="UserControl_KeyDown"
    mc:Ignorable="d">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <prism:InvokeCommandAction Command="{Binding Load}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Styles/ButtonStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="MenuButtonStyle" TargetType="{x:Type Button}">
                <Setter Property="Width" Value="20" />
                <Setter Property="Height" Value="20" />
            </Style>
            <convert:BoolToVisible x:Key="BoolToVisibleConvert" />
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid Background="{StaticResource color.sys.layout.mg}">
        <Grid.RowDefinitions>
            <RowDefinition Name="HeadRow" Height="40" />
            <RowDefinition Name="ToolRow" Height="40" />

            <RowDefinition Height="*" />
            <RowDefinition Height="32" />
        </Grid.RowDefinitions>
        <Grid Visibility="{Binding GridVisibility}">
            <!--  左边菜单按钮  -->
            <StackPanel
                Margin="16,6,0,6"
                HorizontalAlignment="Left"
                Orientation="Horizontal"
                Visibility="{Binding IsReadMode}">
                <Button
                    Content="Files"
                    Style="{StaticResource subToolBar}"
                    ToolTip="File">
                    <Button.ContextMenu>
                        <ContextMenu>
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                            <MenuItem />
                        </ContextMenu>
                    </Button.ContextMenu>
                </Button>
                <Separator
                    Width="1"
                    Height="12"
                    Margin="8,0"
                    Background="{StaticResource color.sys.layout.divider}"
                    Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
                <Button
                    Command="{Binding SaveFile}"
                    IsEnabled="{Binding CanSave}"
                    Style="{StaticResource subToolBar}"
                    ToolTip="Save">
                    <Path
                        Width="20"
                        Height="20"
                        Data="M16 16V6.82843L13.1716 4H12V8C12 9.10457 11.1046 10 10 10H7C5.89543 10 5 9.10457 5 8V4H4V16H16ZM7 4H10V8H7V4ZM13.1716 2H12H10H7H5H4C2.89543 2 2 2.89543 2 4V16C2 17.1046 2.89543 18 4 18H16C17.1046 18 18 17.1046 18 16V6.82843C18 6.29799 17.7893 5.78929 17.4142 5.41421L14.5858 2.58579C14.2107 2.21071 13.702 2 13.1716 2ZM9.25 5H7.75V7H9.25V5Z"
                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                </Button>
                <Button
                    Margin="2,0"
                    Command="{Binding UndoCommand}"
                    IsEnabled="{Binding CanUndo}"
                    Style="{StaticResource subToolBar}"
                    ToolTip="Undo">
                    <Path
                        Width="20"
                        Height="20"
                        Data="M5.75766 8.00008L6.70741 8.94982L5.2932 10.364L2.46477 7.53561C2.07424 7.14508 2.07424 6.51192 2.46477 6.1214L5.2932 3.29297L6.70741 4.70718L5.41451 6.00008H12.5001C15.5377 6.00008 18.0001 8.46251 18.0001 11.5001C18.0001 14.5376 15.5377 17.0001 12.5001 17.0001H3.00012V15.0001H12.5001C14.4331 15.0001 16.0001 13.4331 16.0001 11.5001C16.0001 9.56708 14.4331 8.00008 12.5001 8.00008H5.75766Z"
                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                </Button>
                <Button
                    Command="{Binding RedoCommand}"
                    IsEnabled="{Binding CanRedo}"
                    Style="{StaticResource subToolBar}"
                    ToolTip="Redo">
                    <Path
                        Width="20"
                        Height="20"
                        Data="M14.2424 8.00006L13.2926 8.94982L14.7068 10.364L17.5352 7.53561C17.9258 7.14508 17.9258 6.51192 17.5352 6.1214L14.7068 3.29297L13.2926 4.70718L14.5855 6.00006H7.49969C4.46213 6.00006 1.9997 8.46249 1.9997 11.5001C1.9997 14.5376 4.46213 17.0001 7.4997 17.0001H16.9997V15.0001H7.4997C5.5667 15.0001 3.9997 13.4331 3.9997 11.5001C3.9997 9.56706 5.5667 8.00006 7.49969 8.00006H14.2424Z"
                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                </Button>
            </StackPanel>
            <!--  右边菜单按钮  -->
            <StackPanel
                Margin="0,6,16,6"
                HorizontalAlignment="Right"
                Orientation="Horizontal"
                Visibility="{Binding IsReadMode}">
                <Button Style="{StaticResource subToolBar}" ToolTip="Print">
                    <Path
                        Width="20"
                        Height="20"
                        Data="M17 6.99999H14.8203C14.7973 7.00126 14.7741 7.0019 14.7508 7.0019L10.0008 7.00254L5.25081 7.00319C5.22047 7.00319 5.19038 7.00211 5.16058 6.99999H3C2.44772 6.99999 2 7.44771 2 7.99999V13.75C2 13.8881 2.11193 14 2.25 14H4V13.25C4 12.5596 4.55964 12 5.25 12H14.75C15.4404 12 16 12.5596 16 13.25V14H17.75C17.8881 14 18 13.8881 18 13.75V7.99999C18 7.44771 17.5523 6.99999 17 6.99999ZM16 16H17.75C18.9926 16 20 14.9926 20 13.75V7.99999C20 6.34314 18.6569 4.99999 17 4.99999H16.0005L16.0002 2.24837C16.0001 1.55801 15.4404 0.998442 14.75 0.998535L5.25 0.999822C4.55964 0.999916 4.00008 1.55964 4.00017 2.24999L4.00054 4.99999H3C1.34315 4.99999 0 6.34314 0 7.99999V13.75C0 14.9926 1.00736 16 2.25 16H4V17.75C4 18.4403 4.55964 19 5.25 19H14.75C15.4404 19 16 18.4403 16 17.75V16ZM6.00027 2.99972L6.00054 4.99999H14.0005L14.0003 2.99864L6.00027 2.99972ZM14 8.49999V10.5H16V8.49999H14ZM6 17V14H14V17H6Z"
                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                </Button>
                <Button
                    Margin="2,0"
                    Style="{StaticResource subToolBar}"
                    ToolTip="Share">
                    <Path
                        Width="20"
                        Height="20"
                        Data="M15.0858 3.5H11.25V1.5H16.6395C17.667 1.5 18.5 2.33298 18.5 3.36051V8.75H16.5V4.91421L11.136 10.2782L9.72183 8.86396L15.0858 3.5ZM4.25 4C4.11193 4 4 4.11193 4 4.25V15.75C4 15.8881 4.11193 16 4.25 16H15.75C15.8881 16 16 15.8881 16 15.75V10.875H18V15.75C18 16.9926 16.9926 18 15.75 18H4.25C3.00736 18 2 16.9926 2 15.75V4.25C2 3.00736 3.00736 2 4.25 2H9.125V4H4.25Z"
                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                </Button>
                <ToggleButton
                    Name="TbtnProperty"
                    Width="28"
                    Height="28"
                    BorderThickness="0"
                    IsChecked="{Binding IsPropertyOpen}"
                    Style="{StaticResource SubToolbarTgb}"
                    ToolTip="Property">
                    <Path
                        Width="20"
                        Height="20"
                        Data="M2 4V7H18V4H2ZM2 16V9H13V16H2ZM15 16H18V9H15V16ZM1.72101 2C0.770524 2 0 2.77052 0 3.72101V16.279C0 17.2295 0.770524 18 1.72101 18H18.279C19.2295 18 20 17.2295 20 16.279V3.72101C20 2.77052 19.2295 2 18.279 2H1.72101Z"
                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                </ToggleButton>
            </StackPanel>
            <TabControl
                x:Name="ToolTabControl"
                Grid.Row="0"
                Grid.RowSpan="2"
                HorizontalAlignment="Center"
                VerticalAlignment="Top"
                BorderThickness="0"
                SelectedIndex="{Binding TabSelectedIndex, Mode=TwoWay}"
                Style="{StaticResource TabControlWithUnderLineStyle}"
                Visibility="{Binding IsReadMode}">
                <cus:IconAndTextTabItem
                    x:Name="TabItemAnnotation"
                    Header="注释"
                    Style="{StaticResource ToolbarTabs}">
                    <Grid Grid.Row="1" Height="40" />
                </cus:IconAndTextTabItem>
                <cus:IconAndTextTabItem
                    x:Name="TabItemPageEdit"
                    Header="页面"
                    Style="{StaticResource ToolbarTabs}" />
                <cus:IconAndTextTabItem
                    x:Name="TabItemConvert"
                    Header="转换"
                    Style="{StaticResource ToolbarTabs}" />
                <cus:IconAndTextTabItem
                    x:Name="TabItemScan"
                    Header="扫描和OCR"
                    Style="{StaticResource ToolbarTabs}">
                    <Grid Grid.Row="1" Height="40" />
                </cus:IconAndTextTabItem>
                <cus:IconAndTextTabItem
                    x:Name="TabItemEdit"
                    Height="40"
                    Header="编辑"
                    Style="{StaticResource ToolbarTabs}">
                    <Grid Grid.Row="1" Height="40" />
                </cus:IconAndTextTabItem>
                <cus:IconAndTextTabItem
                    x:Name="TabItemForm"
                    Height="40"
                    Header="表单"
                    Style="{StaticResource ToolbarTabs}">
                    <Grid Grid.Row="1" Height="40" />
                </cus:IconAndTextTabItem>
                <cus:IconAndTextTabItem
                    x:Name="TabItemFill"
                    Height="40"
                    Header="填写与签名"
                    Style="{StaticResource ToolbarTabs}"
                    Visibility="Collapsed">
                    <Grid Grid.Row="1" Height="40" />
                </cus:IconAndTextTabItem>
                <cus:IconAndTextTabItem
                    x:Name="TabItemTool"
                    Height="40"
                    Header="工具"
                    Style="{StaticResource ToolbarTabs}">
                    <Grid Grid.Row="1" Height="40" />
                </cus:IconAndTextTabItem>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding TabControlSelectionChangedCommand}" PassEventArgsToCommand="True" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </TabControl>
        </Grid>

        <!--  底部工具栏  -->
        <ContentControl Grid.Row="3" prism:RegionManager.RegionName="{Binding BottomToolRegionName}" />

        <!--  专门用来显示菜单二级工具栏  -->
        <!--  调整工具栏的显示图层，方便阅读模式处理  -->
        <ContentControl
            Name="ContentToolsBar"
            Grid.Row="{Binding GridToolRow}"
            prism:RegionManager.RegionName="{Binding ToolsBarContentRegionName}"
            Visibility="{Binding ToolsBarContentVisible}" />

        <ContentControl
            Name="ContentConverterBar"
            Grid.Row="{Binding GridToolRow}"
            prism:RegionManager.RegionName="{Binding ConverterBarContentRegionName}"
            Visibility="{Binding ConverterBarContentVisible}" />

        <ContentControl
            Name="TextEditContentBar"
            Grid.Row="{Binding GridToolRow}"
            prism:RegionManager.RegionName="{Binding TextEditContentRegionName}"
            Visibility="{Binding TextEditToolContentVisible}" />

        <Grid Name="DocumentView" Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition
                    x:Name="BOTACloumn"
                    Width="{Binding BOTAWidth, Mode=TwoWay}"
                    MinWidth="48"
                    MaxWidth="400" />
                <ColumnDefinition Width="auto" />
                <ColumnDefinition
                    Name="ViewerColumn"
                    Width="*"
                    MinWidth="200" />
                <ColumnDefinition Name="PropertyColumn" MinWidth="0">
                    <ColumnDefinition.Style>
                        <Style TargetType="{x:Type ColumnDefinition}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=TbtnProperty, Path=IsChecked}" Value="True">
                                    <Setter Property="Width" Value="260" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding ElementName=TbtnProperty, Path=IsChecked}" Value="False">
                                    <Setter Property="Width" Value="0" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ColumnDefinition.Style>
                </ColumnDefinition>
            </Grid.ColumnDefinitions>

            <ContentControl prism:RegionManager.RegionName="{Binding BOTARegionName}" />
            <GridSplitter
                Grid.Column="1"
                Width="0"
                FocusVisualStyle="{x:Null}"
                ResizeBehavior="PreviousAndNext"
                ShowsPreview="True" />
            <ContentControl
                x:Name="PDFViewerContent"
                Grid.Column="2"
                HorizontalAlignment="Stretch"
                prism:RegionManager.RegionName="{Binding ViwerRegionName}" />
            <ScrollViewer
                Name="Scroller"
                Grid.Column="4"
                Focusable="False"
                VerticalScrollBarVisibility="Auto">
                <ContentControl Height="{Binding ElementName=Scroller, Path=ViewportHeight}" prism:RegionManager.RegionName="{Binding PropertyRegionName}" />
            </ScrollViewer>
            <Border
                Name="ViewContentTipPanel"
                Grid.Column="2"
                Width="{Binding ElementName=PDFViewerContent, Path=Width}"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Top"
                Background=" #BDDFFD"
                Visibility="Collapsed">
                <TextBlock
                    x:Name="DrawTipsText"
                    Margin="12,4"
                    Padding="4,2,4,2"
                    FontSize="14"
                    Foreground="#252629"
                    Text="Please use the scroll bar, thumbnail tool to locate the target page, click or box the area to select the target range" />
            </Border>
        </Grid>

        <!--  用于显示页面编辑、水印、背景、标记密文等功能的区域  -->
        <Border
            Grid.Row="{Binding GridToolRow}"
            Grid.RowSpan="{Binding GridToolRowSpan}"
            BorderBrush="{StaticResource color.sys.layout.divider}"
            BorderThickness="0,1"
            Visibility="{Binding ToolContentVisible}">
            <ContentControl Name="ContentTool" prism:RegionManager.RegionName="{Binding ToolContentRegionName}" />
        </Border>
        <cus:LoadingControl Grid.RowSpan="3" Visibility="{Binding IsLoading}" />
    </Grid>
</UserControl>