<UserControl
    x:Class="MECF.Framework.UI.Client.CenterViews.Configs.Roles.RoleView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:command="clr-namespace:OpenSEMI.ClientBase.Command"
    xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:lex="http://wpflocalizeextension.codeplex.com"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:micro="clr-namespace:Caliburn.Micro"
    lex:LocalizeDictionary.DesignCulture="zh"
    lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
    lex:ResxLocalizationProvider.DefaultDictionary="lang_config">
    <UserControl.Resources>
        <Style
            x:Key="ViewEnabledBtn"
            BasedOn="{StaticResource ResourceKey={x:Type Button}}"
            TargetType="{x:Type Button}">
            <Setter Property="Button.IsEnabled" Value="False" />
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Permission}" Value="2" />
                        <Condition Binding="{Binding ControlMode}" Value="VIEW" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Button.IsEnabled" Value="True" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
        <Style
            x:Key="EditEnabledBtn"
            BasedOn="{StaticResource ResourceKey={x:Type Button}}"
            TargetType="{x:Type Button}">
            <Setter Property="Button.IsEnabled" Value="False" />
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Permission}" Value="2" />
                        <Condition Binding="{Binding ControlMode}" Value="EDIT" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Button.IsEnabled" Value="True" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid
        x:Name="MainTable"
        Width="1900"
        MinWidth="1200"
        MinHeight="450"
        HorizontalAlignment="Left">
        <Grid x:Name="MainField">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="250" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="40" />
            </Grid.RowDefinitions>
            <GridSplitter
                Grid.Column="1"
                Width="5"
                HorizontalAlignment="Left"
                BorderThickness="0,8">
                <GridSplitter.Background>
                    <SolidColorBrush />
                </GridSplitter.Background>
            </GridSplitter>
            <Border
                Margin="0,20,0,0"
                Padding="12"
                Background="{DynamicResource Tab_BG}"
                BorderBrush="{DynamicResource Tab_BD}"
                BorderThickness="1"
                SnapsToDevicePixels="True">
                <TreeView
                    Name="RolesTree"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top">
                    <TreeView.Style>
                        <Style BasedOn="{StaticResource ResourceKey={x:Type TreeView}}" TargetType="{x:Type TreeView}">
                            <Setter Property="TreeView.IsEnabled" Value="False" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ControlMode}" Value="VIEW">
                                    <Setter Property="TreeView.IsEnabled" Value="True" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TreeView.Style>
                    <TreeViewItem
                        Header="{lex:Loc ID_TXT_Role}"
                        IsExpanded="True"
                        ItemsSource="{Binding RoleList}">
                        <TreeViewItem.ItemContainerStyle>
                            <Style
                                x:Name="RoleTreeViewItem"
                                BasedOn="{StaticResource ResourceKey={x:Type TreeViewItem}}"
                                TargetType="{x:Type TreeViewItem}">
                                <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
                                <Style.Triggers>
                                    <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                                        <Setter Property="ItemsPanel">
                                            <Setter.Value>
                                                <ItemsPanelTemplate>
                                                    <VirtualizingStackPanel />
                                                </ItemsPanelTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TreeViewItem.ItemContainerStyle>
                        <TreeViewItem.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DisplayRoleName}" />
                            </DataTemplate>
                        </TreeViewItem.ItemTemplate>
                    </TreeViewItem>
                    <command:CommandSource.Trigger>
                        <command:CommandTriggerGroup>
                            <command:EventCommandTrigger
                                Command="{Binding DataContext.RoleTreeSelectChangedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                CustomParameter="{Binding ElementName=RolesTree, Path=SelectedItem}"
                                RoutedEvent="TreeView.SelectedItemChanged" />
                        </command:CommandTriggerGroup>
                    </command:CommandSource.Trigger>
                </TreeView>
            </Border>
            <Grid Grid.Column="1" Margin="10,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="20" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock
                    Margin="5,0,0,0"
                    VerticalAlignment="Top"
                    FontFamily="Arial"
                    FontSize="14"
                    FontWeight="Bold"
                    Foreground="{DynamicResource FG_Black}"
                    Text="{lex:Loc ID_TXT_Role_Property}"
                    TextWrapping="Wrap" />
                <Grid
                    x:Name="Role_Property"
                    Grid.Row="1"
                    Margin="0,0,0,5"
                    IsEnabled="{Binding IsPermission}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                    </Grid.RowDefinitions>
                    <Grid x:Name="Role_Name" Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Border
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Title}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="1">
                            <TextBlock
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{lex:Loc ID_TXT_Name}"
                                TextWrapping="Wrap" />
                        </Border>
                        <Border
                            Grid.Column="1"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Content}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,1,1,1">
                            <controls:TextBoxEx
                                x:Name="textBox1"
                                Width="150"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                HorizontalContentAlignment="Stretch"
                                IsEnabled="{Binding IsEnabledRoleName}"
                                Text="{Binding TreeSelectedRole.DisplayRoleName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                TextSaved="{Binding Mode=TwoWay, Path=TreeSelectedRole.RoleNameTextSaved}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="TextChanged">
                                        <micro:ActionMessage MethodName="OnRoleChanged" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </controls:TextBoxEx>
                        </Border>
                    </Grid>
                    <Grid x:Name="Is_Auto_Logout" Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Border
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Title}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="1,0,1,1">
                            <TextBlock
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{lex:Loc ID_TXT_Is_Auto_Logout}"
                                TextWrapping="Wrap" />
                        </Border>
                        <Border
                            Grid.Column="1"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Content}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,0,1,1">
                            <CheckBox
                                Name="checkBox1"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Content=""
                                IsChecked="{Binding TreeSelectedRole.DisplayIsAutoLogout}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <micro:ActionMessage MethodName="OnAutoLogoutTimeChecked">
                                            <micro:Parameter Value="$source" />
                                        </micro:ActionMessage>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </CheckBox>
                        </Border>
                    </Grid>
                    <Grid x:Name="Time" Grid.Row="2">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Border
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Title}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="1,0,1,1">
                            <TextBlock
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{lex:Loc ID_TXT_Time(minutes)}"
                                TextWrapping="Wrap" />
                        </Border>
                        <Border
                            Grid.Column="1"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Content}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,0,1,1">
                            <controls:TextBoxEx
                                x:Name="textBox2"
                                Width="150"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                HorizontalContentAlignment="Stretch"
                                EditBoxMode="UnSignInteger"
                                PreviewTextInput="TextBox2_PreviewTextInput"
                                Text="{Binding TreeSelectedRole.DisplayAutoLogoutTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                TextSaved="{Binding Mode=TwoWay, Path=TreeSelectedRole.TimeTextSaved}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="TextChanged">
                                        <micro:ActionMessage MethodName="OnRoleChanged" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </controls:TextBoxEx>
                        </Border>
                    </Grid>
                    <Grid x:Name="Description" Grid.Row="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Border
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Title}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="1,0,1,1">
                            <TextBlock
                                VerticalAlignment="Center"
                                FontFamily="Arial"
                                FontSize="12"
                                Foreground="{DynamicResource FG_Black}"
                                Text="{lex:Loc ID_TXT_Description}"
                                TextWrapping="Wrap" />
                        </Border>
                        <Border
                            Grid.Column="1"
                            Padding="5,1"
                            Background="{DynamicResource Table_BG_Content}"
                            BorderBrush="{DynamicResource Table_BD}"
                            BorderThickness="0,1,1,1">
                            <controls:TextBoxEx
                                x:Name="textBox3"
                                MinWidth="150"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                HorizontalContentAlignment="Stretch"
                                Text="{Binding TreeSelectedRole.DisplayDescription, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                TextSaved="{Binding Mode=TwoWay, Path=TreeSelectedRole.DescriptionTextSaved}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="TextChanged">
                                        <micro:ActionMessage MethodName="OnRoleChanged" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </controls:TextBoxEx>
                        </Border>
                    </Grid>
                </Grid>
                <TabControl Grid.Row="2">
                    <TabItem>
                        <TabItem.Header>
                            <TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Page_Access_Permission}" />
                        </TabItem.Header>
                        <ListView
                            Name="RolesList"
                            VerticalAlignment="Top"
                            AlternationCount="2"
                            IsEnabled="{Binding IsPermission}"
                            ItemsSource="{Binding Path=TreeSelectedRole.MenuPermCollection}"
                            ScrollViewer.CanContentScroll="True"
                            ScrollViewer.HorizontalScrollBarVisibility="Auto"
                            ScrollViewer.VerticalScrollBarVisibility="Auto">

                            <ListView.View>
                                <GridView>
                                    <GridViewColumn
                                        Width="200"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        DisplayMemberBinding="{Binding Name}"
                                        Header="{lex:Loc ID_TXT_Name}" />
                                    <GridViewColumn
                                        Width="200"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        Header="{lex:Loc ID_TXT_Permission_Configuration}">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <ComboBox
                                                    x:Name="combPermission"
                                                    Width="140"
                                                    DisplayMemberPath="StringPermission"
                                                    ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                                    SelectedItem="{Binding Permission}">
                                                    <i:Interaction.Triggers>
                                                        <i:EventTrigger EventName="SelectionChanged">
                                                            <micro:ActionMessage MethodName="OnRoleChanged" />
                                                        </i:EventTrigger>
                                                    </i:Interaction.Triggers>
                                                </ComboBox>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </TabItem>

                    <TabItem Visibility="Collapsed">
                        <TabItem.Header>
                            <TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Recipe_Parameter_Permission}" />
                        </TabItem.Header>
                        <ListView
                            Name="RecipeList"
                            VerticalAlignment="Top"
                            AlternationCount="2"
                            IsEnabled="{Binding IsPermission}"
                            ItemsSource="{Binding Path=TreeSelectedRole.RecipePermCollection}"
                            ScrollViewer.CanContentScroll="True"
                            ScrollViewer.HorizontalScrollBarVisibility="Auto"
                            ScrollViewer.VerticalScrollBarVisibility="Auto">

                            <ListView.View>
                                <GridView>
                                    <GridViewColumn
                                        Width="300"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        DisplayMemberBinding="{Binding Name}"
                                        Header="{lex:Loc ID_TXT_Name}" />
                                    <GridViewColumn
                                        Width="200"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        Header="{lex:Loc ID_TXT_Permission_Configuration}">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <ComboBox
                                                    x:Name="combPermission"
                                                    Width="140"
                                                    DisplayMemberPath="StringPermission"
                                                    ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                                    SelectedItem="{Binding Permission}">
                                                    <i:Interaction.Triggers>
                                                        <i:EventTrigger EventName="SelectionChanged">
                                                            <micro:ActionMessage MethodName="OnRoleChanged" />
                                                        </i:EventTrigger>
                                                    </i:Interaction.Triggers>
                                                </ComboBox>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </TabItem>

                    <TabItem>
                        <TabItem.Header>
                            <TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Recipe_Step_Permission}" />
                        </TabItem.Header>
                        <ListView
                            Name="RecipeStepList"
                            VerticalAlignment="Top"
                            AlternationCount="2"
                            IsEnabled="{Binding IsPermission}"
                            ItemsSource="{Binding Path=TreeSelectedRole.RecipeStepPermCollection}"
                            ScrollViewer.CanContentScroll="True"
                            ScrollViewer.HorizontalScrollBarVisibility="Auto"
                            ScrollViewer.VerticalScrollBarVisibility="Auto">

                            <ListView.View>
                                <GridView>
                                    <GridViewColumn
                                        Width="300"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        DisplayMemberBinding="{Binding Name}"
                                        Header="{lex:Loc ID_TXT_Name}" />
                                    <GridViewColumn
                                        Width="200"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        Header="{lex:Loc ID_TXT_Permission_Configuration}">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <ComboBox
                                                    x:Name="combPermission"
                                                    Width="140"
                                                    DisplayMemberPath="StringPermission"
                                                    ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                                    SelectedItem="{Binding Permission}">
                                                    <i:Interaction.Triggers>
                                                        <i:EventTrigger EventName="SelectionChanged">
                                                            <micro:ActionMessage MethodName="OnRoleChanged" />
                                                        </i:EventTrigger>
                                                    </i:Interaction.Triggers>
                                                </ComboBox>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </TabItem>

                    <TabItem>
                        <TabItem.Header>
                            <TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Content_Access_Permission}" />
                        </TabItem.Header>
                        <ListView
                            Name="ContentList"
                            VerticalAlignment="Top"
                            lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                            AlternationCount="2"
                            IsEnabled="{Binding IsPermission}"
                            ItemsSource="{Binding Path=TreeSelectedRole.ContentPermCollection}"
                            ScrollViewer.CanContentScroll="True"
                            ScrollViewer.HorizontalScrollBarVisibility="Auto"
                            ScrollViewer.VerticalScrollBarVisibility="Auto">
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn
                                        Width="300"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        DisplayMemberBinding="{Binding Name}"
                                        Header="{lex:Loc ID_TXT_Name}" />
                                    <GridViewColumn
                                        Width="200"
                                        lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
                                        Header="{lex:Loc ID_TXT_Permission_Configuration}">
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <ComboBox
                                                    x:Name="combPermission"
                                                    Width="140"
                                                    DisplayMemberPath="StringPermission"
                                                    ItemsSource="{Binding DataContext.PermissionTrueFalseDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                                                    SelectedItem="{Binding Permission}">
                                                    <i:Interaction.Triggers>
                                                        <i:EventTrigger EventName="SelectionChanged">
                                                            <micro:ActionMessage MethodName="OnRoleChanged" />
                                                        </i:EventTrigger>
                                                    </i:Interaction.Triggers>
                                                </ComboBox>
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn DisplayMemberBinding="{Binding Description}" Header="{lex:Loc ID_TXT_Description}" />
                                </GridView>
                            </ListView.View>
                        </ListView>
                    </TabItem>

                </TabControl>
            </Grid>
            <StackPanel
                Grid.Row="1"
                Grid.ColumnSpan="2"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
                Orientation="Horizontal">
                <Button
                    x:Name="ID_BTN_Create_Content"
                    Width="80"
                    Height="25"
                    Command="{Binding BtnAddRoleCommand}"
                    Content="{lex:Loc}"
                    Style="{StaticResource ViewEnabledBtn}"
                    ToolTip="{lex:Loc}" />
                <Button
                    x:Name="ID_BTN_Delete_Content"
                    Width="80"
                    Height="25"
                    Margin="10,0,0,0"
                    Command="{Binding BtnDeleteRoleCommand}"
                    Content="{lex:Loc}"
                    Style="{StaticResource ViewEnabledBtn}"
                    ToolTip="{lex:Loc}" />
                <Button
                    x:Name="ID_BTN_Clone_Content"
                    Width="80"
                    Height="25"
                    Margin="10,0,0,0"
                    Command="{Binding BtnCloneRoleCommand}"
                    Content="{lex:Loc}"
                    Style="{StaticResource ViewEnabledBtn}"
                    ToolTip="{lex:Loc}" />
                <Button
                    x:Name="ID_BTN_Save_Content"
                    Width="80"
                    Height="25"
                    Margin="10,0,0,0"
                    Command="{Binding BtnSaveCommand}"
                    Content="{lex:Loc}"
                    Style="{StaticResource EditEnabledBtn}"
                    ToolTip="{lex:Loc}" />
                <Button
                    x:Name="ID_BTN_Cancel_Content"
                    Width="80"
                    Height="25"
                    Margin="10,0,0,0"
                    Command="{Binding BtnCancelRoleCommand}"
                    Content="{lex:Loc}"
                    Style="{StaticResource EditEnabledBtn}"
                    ToolTip="{lex:Loc}" />
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>
