<UserControl
    x:Class="MECF.Framework.UI.Client.CenterViews.Editors.Recipe.RecipeCompareView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
    xmlns:converters="clr-namespace:MECF.Framework.UI.Client.RecipeEditorLib.Converters"
    xmlns:cv="clr-namespace:MECF.Framework.UI.Core.Converters;assembly=MECF.Framework.UI.Core"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:dgExtension="clr-namespace:MECF.Framework.UI.Client.RecipeEditorLib.DGExtension"
    xmlns:dgExtension1="clr-namespace:MECF.Framework.UI.Client.RecipeEditorLib.DGExtension"
    xmlns:editors="clr-namespace:MECF.Framework.UI.Client.CenterViews.Editors"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:lex="http://wpflocalizeextension.codeplex.com"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:micro="clr-namespace:Caliburn.Micro"
    xmlns:uiClientCtrl="clr-namespace:MECF.Framework.UI.Client.Ctrlib.Controls"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    d:DesignHeight="1000"
    d:DesignWidth="1900"
    lex:LocalizeDictionary.DesignCulture="en"
    lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
    lex:ResxLocalizationProvider.DefaultDictionary="lang_recipeview"
    mc:Ignorable="d">
    <UserControl.Resources>
        <HierarchicalDataTemplate x:Key="FolderTemplate" ItemsSource="{Binding Files}">
            <StackPanel Orientation="Horizontal" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}">
                <Image
                    x:Name="ExpandImage"
                    Width="14"
                    Height="12"
                    Margin="2,0,0,0"
                    VerticalAlignment="Center"
                    Source="/MECF.Framework.UI.Client;component/Resources/Images/Folder_Close.png" />
                <TextBlock
                    Margin="5,0,0,0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    Text="{Binding Name}" />
            </StackPanel>
            <HierarchicalDataTemplate.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter TargetName="ExpandImage" Property="Image.Source" Value="/MECF.Framework.UI.Client;component/Resources/Images/Folder_Unable.png" />
                </Trigger>
            </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="FileTemplate" ItemsSource="{Binding Files}">
            <StackPanel Orientation="Horizontal" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}">
                <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, Delay=10}" />
                <TextBlock
                    Margin="5,0,0,0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    Text="{Binding Name}" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <editors:FolderOrFileTemplateSelector
            x:Key="FolderFileTemplateSelector"
            FileTemplate="{StaticResource FileTemplate}"
            FolderTemplate="{StaticResource FolderTemplate}" />


        <Storyboard
            x:Key="MenuOpen"
            Storyboard.TargetName="border"
            Storyboard.TargetProperty="RenderTransform.X">
            <DoubleAnimation
                From="-370"
                To="0"
                Duration="0:0:1">
                <DoubleAnimation.EasingFunction>
                    <!--  设置缓动模式和振荡次数  -->
                    <BackEase Amplitude="0.5" EasingMode="EaseOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>

        <Storyboard
            x:Key="MenuClose"
            Storyboard.TargetName="border"
            Storyboard.TargetProperty="RenderTransform.X">
            <DoubleAnimation
                From="0"
                To="-370"
                Duration="0:0:0.6" />
        </Storyboard>

    </UserControl.Resources>

    <Grid>
        <Grid Name="rootGrid">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <!--  顶层按钮和Lab标签   Content="Show Menu"  -->
            <StackPanel Orientation="Horizontal">
                <Image
                    Width="40"
                    Height="40"
                    Margin="10,0,0,0"
                    ToolTip="显示菜单">
                    <Image.Triggers>
                        <EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
                            <BeginStoryboard Storyboard="{StaticResource MenuOpen}" />
                        </EventTrigger>
                    </Image.Triggers>
                    <Image.Style>
                        <Style TargetType="{x:Type Image}">
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="False">
                                    <Setter Property="Source" Value="/MECF.Framework.UI.Client;component/Resources/Images/menu1.png" />
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Source" Value="/MECF.Framework.UI.Client;component/Resources/Images/menu2.png" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>

                <TextBlock
                    Margin="20,0"
                    VerticalAlignment="Center"
                    FontSize="16">
                    <Run FontSize="12" Text="{lex:Loc ID_TXT_SelectRecipeName}" /><Run FontSize="12" Text="{Binding LabSelectRecipeNames}" />
                </TextBlock>

            </StackPanel>

            <!--  侧边栏  -->
            <Border
                x:Name="border"
                Grid.Row="1"
                Width="335"
                Margin="10"
                HorizontalAlignment="Left"
                Panel.ZIndex="1000"
                Background="#FF9FBEDE">
                <!--  位移效果  -->
                <Border.RenderTransform>
                    <TranslateTransform X="-370" />
                </Border.RenderTransform>
                <Border.Effect>
                    <DropShadowEffect
                        Direction="300"
                        Opacity="0.6"
                        ShadowDepth="1"
                        Color="Black" />
                </Border.Effect>
                <Border.Triggers>
                    <!--  鼠标的左键按下事件来触发退出动画  -->
                    <EventTrigger RoutedEvent="MouseLeave">
                        <BeginStoryboard>
                            <!--  退出动画  -->
                            <Storyboard Storyboard.TargetProperty="X">
                                <DoubleAnimation
                                    From="0"
                                    To="-370"
                                    Duration="0:0:1" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Border.Triggers>

                <StackPanel
                    Grid.Row="1"
                    Width="330"
                    HorizontalAlignment="Left">
                    <Image
                        Width="40"
                        Height="40"
                        Margin="10,0,0,0"
                        HorizontalAlignment="Right"
                        ToolTip="隐藏">
                        <Image.Triggers>
                            <EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
                                <BeginStoryboard Storyboard="{StaticResource MenuClose}" />
                            </EventTrigger>
                        </Image.Triggers>
                        <Image.Style>
                            <Style TargetType="{x:Type Image}">
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="False">
                                        <Setter Property="Source" Value="/MECF.Framework.UI.Client;component/Resources/Images/return1.png" />
                                    </Trigger>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Source" Value="/MECF.Framework.UI.Client;component/Resources/Images/return2.png" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>

                    <Border
                        Height="500"
                        Background="{DynamicResource Tab_BG}"
                        BorderBrush="Gray"
                        BorderThickness="0,1,0,0">
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            <Border
                                Background="Transparent"
                                BorderBrush="{DynamicResource Table_BD}"
                                BorderThickness="0">
                                <TabControl
                                    Padding="0"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch"
                                    HorizontalContentAlignment="Stretch"
                                    VerticalContentAlignment="Stretch"
                                    ItemsSource="{Binding ProcessTypeFileList}"
                                    SelectedIndex="{Binding ProcessTypeIndexSelection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                                    <TabControl.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding ProcessType}" />
                                        </DataTemplate>
                                    </TabControl.ItemTemplate>
                                    <TabControl.ContentTemplate>
                                        <DataTemplate>
                                            <TreeView
                                                x:Name="RecipeTree1"
                                                Height="{Binding Path=ActualHeight, ElementName=PART_BORDER, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                                Margin="0"
                                                VerticalAlignment="Stretch"
                                                ItemTemplateSelector="{StaticResource FolderFileTemplateSelector}"
                                                ItemsSource="{Binding FileListByProcessType}"
                                                Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext}"
                                                VirtualizingPanel.IsVirtualizing="True"
                                                VirtualizingPanel.VirtualizationMode="Recycling">
                                                <TreeView.ItemContainerStyle>
                                                    <Style BasedOn="{StaticResource TreeViewItemExtend}" TargetType="{x:Type TreeViewItem}">
                                                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                                                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                                                    </Style>
                                                </TreeView.ItemContainerStyle>
                                                <i:Interaction.Triggers>
                                                    <!--<i:EventTrigger EventName="SelectedItemChanged">
                                                        <micro:ActionMessage MethodName="TreeSelectChanged">
                                                            <micro:Parameter Value="{Binding SelectedItem, ElementName=RecipeTree1}" />
                                                        </micro:ActionMessage>
                                                    </i:EventTrigger>-->
                                                    <!--<i:EventTrigger EventName="MouseRightButtonDown">
                                                        <micro:ActionMessage MethodName="TreeRightMouseDown">
                                                            <micro:Parameter Value="$eventargs" />
                                                        </micro:ActionMessage>
                                                    </i:EventTrigger>-->
                                                    <i:EventTrigger EventName="MouseDoubleClick">
                                                        <micro:ActionMessage MethodName="TreeSelectChanged">
                                                            <micro:Parameter Value="{Binding SelectedItem, ElementName=RecipeTree1}" />
                                                        </micro:ActionMessage>
                                                    </i:EventTrigger>
                                                </i:Interaction.Triggers>
                                                <!--<TreeView.ContextMenu>
                                                    <ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
                                                        <MenuItem Command="{Binding RecipeHistoryCommand}" Header="RecipeHistory" />
                                                    </ContextMenu>
                                                </TreeView.ContextMenu>-->
                                            </TreeView>
                                        </DataTemplate>
                                    </TabControl.ContentTemplate>

                                </TabControl>

                            </Border>

                        </Grid>
                    </Border>
                    <Grid>
                        <Button
                            Width="80"
                            Height="35"
                            Margin="10"
                            HorizontalAlignment="Left"
                            lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                            micro:Message.Attach="RefreshRecipe()"
                            Content="{lex:Loc ID_BTN_Refresh_Content}"
                            FontSize="13"
                            IsEnabled="{Binding IsSelectButtonEnable}" />

                        <Button
                            Width="80"
                            Height="35"
                            Margin="10"
                            HorizontalAlignment="Right"
                            micro:Message.Attach="ComperSelectRecipe()"
                            Content="{lex:Loc ID_BTN_Compare_Content}"
                            FontSize="13"
                            IsEnabled="{Binding IsSelectButtonEnable}">
                            <!--<Button.Triggers>
                            -->
                            <!--  用按钮的鼠标进入事件来触发进入动画  -->
                            <!--
        <EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
            <BeginStoryboard Storyboard="{StaticResource MenuClose}" />
        </EventTrigger>
    </Button.Triggers>-->
                        </Button>
                    </Grid>


                </StackPanel>

            </Border>

            <!--  对比内容展示  -->
            <Grid Grid.Row="1" Margin="10">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="335" />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <dgExtension1:DataGridRecipe
                    AllowDragToFill="False"
                    FrozenColumnCount="6"
                    IsEnabled="{Binding IsPermission}"
                    Recipe="{Binding ComparRecipeHeader, Mode=OneWay}"
                    ScrollViewerOffset="{Binding ScrollViewerOffset, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                <dgExtension1:DataGridRecipe
                    Grid.Column="1"
                    AllowDragToFill="False"
                    ComperHeadersVisibility="None"
                    FrozenColumnCount="6"
                    IsEnabled="{Binding IsPermission}"
                    Recipe="{Binding ComparRecipe1, Mode=OneWay}"
                    ScrollViewerOffset="{Binding ScrollViewerOffset, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                <dgExtension1:DataGridRecipe
                    Grid.Column="2"
                    AllowDragToFill="False"
                    ComperHeadersVisibility="None"
                    FrozenColumnCount="6"
                    IsEnabled="{Binding IsPermission}"
                    Recipe="{Binding ComparRecipe2, Mode=OneWay}"
                    ScrollViewerOffset="{Binding ScrollViewerOffset, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
            </Grid>

        </Grid>
        <uiClientCtrl:PanelLocker
            x:Name="editorLocker"
            Grid.RowSpan="2"
            LockTarget="{Binding ElementName=rootGrid}"
            Visibility="Collapsed" />
    </Grid>

</UserControl>
