<UserControl x:Class="VIZ.Package.Module.PageGroupView"
             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:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:fcore="clr-namespace:VIZ.Framework.Core;assembly=VIZ.Framework.Core"
             xmlns:fcommon="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
             xmlns:common="clr-namespace:VIZ.Package.Common;assembly=VIZ.Package.Common"
             xmlns:storage="clr-namespace:VIZ.Package.Storage;assembly=VIZ.Package.Storage"
             xmlns:resource="clr-namespace:VIZ.Package.Module.Resource;assembly=VIZ.Package.Module.Resource"
             xmlns:local="clr-namespace:VIZ.Package.Module"
             xmlns:domain="clr-namespace:VIZ.Package.Domain;assembly=VIZ.Package.Domain"
             d:DataContext="{d:DesignInstance Type=local:PageGroupViewModel}" 
             x:Name="uc"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VIZ.Package.Module.Resource;component/Style/IconButton/IconButton_Default.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>

            <resource:RowHandleConverter x:Key="RowHandleConverter"></resource:RowHandleConverter>
            <fcore:Bitmap2ImageSourceConverter x:Key="Bitmap2ImageSourceConverter"></fcore:Bitmap2ImageSourceConverter>
            <fcore:Enum2EnumDescriptionConverter x:Key="Enum2EnumDescriptionConverter" EnumType="{x:Type storage:PageType}"></fcore:Enum2EnumDescriptionConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid IsEnabled="{Binding IsEnabled}">
        <Grid.RowDefinitions>
            <RowDefinition Height="35"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <!-- 按钮组 -->
        <Border Background="#11FFFFFF">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                <!-- 清理 -->
                <fcommon:IconButton Icon="/VIZ.Package.Module.Resource;component/Icons/icon_clear_32x32.png"
                                    Style="{StaticResource IconButton_Menu_Mask}"
                                    ToolTip="清理内存" Margin="5,0,0,0" 
                                    IconWidth="24" IconHeight="24" Width="24" Height="24"
                                    Command="{Binding TakeClearCommand}"></fcommon:IconButton>
            </StackPanel>
        </Border>

        <dx:DXTabControl Grid.Row="1" Margin="0,5,0,0" Padding="0,5,0,0"
                         ItemsSource="{Binding Path=PageGroupModels}"
                         SelectedItem="{Binding Path=SelectedPageGroupModel,Mode=TwoWay}">
            <dx:DXTabControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="打开" Command="{Binding Path=PlacementTarget.DataContext.OpenPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="新建分组" Command="{Binding Path=PlacementTarget.DataContext.AddGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="重命名分组" Command="{Binding Path=PlacementTarget.DataContext.RenameGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="更新页" Command="{Binding Path=PlacementTarget.DataContext.UpdateCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="初始化页" Command="{Binding Path=PlacementTarget.DataContext.TakeInitCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="删除分组" Command="{Binding Path=PlacementTarget.DataContext.DeleteGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="删除节目单项" Command="{Binding Path=PlacementTarget.DataContext.DeleteItemCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                </ContextMenu>
            </dx:DXTabControl.ContextMenu>
            <dx:DXTabControl.View>
                <dx:TabControlStretchView Tag="Stretch"
                                          HeaderLocation="Top"
                                          NewButtonShowMode="InTabPanel"
                                          HideButtonShowMode="InAllTabs"
                                          PinnedTabSize="100">

                </dx:TabControlStretchView>
            </dx:DXTabControl.View>

            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand EventName="TabAdding" Command="{Binding TabAddGroupCommand}" PassEventArgsToCommand="True" />
            </dxmvvm:Interaction.Behaviors>
            <dx:DXTabControl.ItemContainerStyle>
                <Style TargetType="dx:DXTabItem">
                    <Setter Property="Content" Value="{Binding .}" />
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <dxg:GridControl ItemsSource="{Binding Path=Pages}" ShowBorder="False" IsFilterEnabled="False" SelectionMode="Row"
                                                 SelectedItems="{Binding Path=SelectedPages,Mode=OneWayToSource}">
                                    <dxg:GridControl.Columns>
                                        <dxg:GridColumn Header="编号" AllowSorting="False" AllowColumnFiltering="False" AllowResizing="True"
                                                        FieldName="PageNum">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"
                                                               Text="{Binding Row.PageNum,StringFormat={}{0:D4}}"></TextBlock>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                            <dxg:GridColumn.CellEditTemplate>
                                                <DataTemplate>
                                                    <local:PageNumberEdit></local:PageNumberEdit>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellEditTemplate>
                                        </dxg:GridColumn>
                                        <common:GridColumnResizeMinHeight Header="缩略图" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                                          AllowEditing="False" Width="120" MinWidth="40" MaxWidth="300" AllowResizing="True">
                                            <common:GridColumnResizeMinHeight.CellTemplate>
                                                <DataTemplate>
                                                    <fcommon:ResizeImageControl ImageSource="{Binding Path=Row.ThumbnailBitmap,Converter={StaticResource Bitmap2ImageSourceConverter}}"
                                                                                IconSource="/VIZ.Package.Module.Resource;component/Icons/image_20x20.png"
                                                                                ShowImageMinWidth="50" ShowImageMinHeight="50">
                                                    </fcommon:ResizeImageControl>
                                                </DataTemplate>
                                            </common:GridColumnResizeMinHeight.CellTemplate>
                                        </common:GridColumnResizeMinHeight>
                                        <dxg:GridColumn Header="场景名" FieldName="Scene" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"></dxg:GridColumn>
                                        <dxg:GridColumn Header="备注" FieldName="Remark" AllowSorting="False" AllowColumnFiltering="False">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:TextEditSettings TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxLength="50"></dxe:TextEditSettings>
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="层" FieldName="Layer" AllowSorting="False" AllowColumnFiltering="False">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:ComboBoxEditSettings ItemsSource="{Binding Source={x:Static domain:ApplicationConstants.VIZ_LAYERS}}"
                                                                          IsTextEditable="False"></dxe:ComboBoxEditSettings>
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="连接" FieldName="ConnGroupID" AllowSorting="False" AllowColumnFiltering="False">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:ComboBoxEditSettings ItemsSource="{Binding ElementName=uc, Path=DataContext.ConnGroups,Mode=TwoWay}"
                                                                          DisplayMember="Name" ValueMember="GroupID" IsTextEditable="False"></dxe:ComboBoxEditSettings>
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="加载" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False" AllowEditing="False"
                                                        Binding="{Binding Path=SceneInfo.TakeInitedProgress}">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:ProgressBarEditSettings ContentDisplayMode="Value" Minimum="0" Maximum="1" />
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="引擎类型" FieldName="EngineType" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"></dxg:GridColumn>
                                        <dxg:GridColumn Header="模板类型" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                        Binding="{Binding Path=PageType,Converter={StaticResource Enum2EnumDescriptionConverter}}">
                                        </dxg:GridColumn>
                                        <dxg:GridColumn Header="插件" FieldName="PluginName" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"></dxg:GridColumn>
                                    </dxg:GridControl.Columns>
                                    <dxg:GridControl.View>
                                        <dxg:TableView IsColumnMenuEnabled="False"
                                                       AllowEditing="True" ShowIndicator="False" RowMinHeight="69.5"
                                                       NavigationStyle="Cell" ShowVerticalLines="False"
                                                       ShowGroupPanel="False" EditorShowMode="MouseDown"
                                                       AllowDragDrop="True"
                                                       ShowBandsPanel="False"
                                                       ShowTotalSummary="False"
                                                       ShowFixedTotalSummary="False"
                                                       ShowDragDropHint="False"
                                                       ShowTargetInfoInDragDropHint="false">
                                            <dxmvvm:Interaction.Behaviors>
                                                <dxmvvm:EventToCommand EventName="RowDoubleClick" Command="{Binding ElementName=uc, Path=DataContext.OpenPageCommand,Mode=TwoWay}"></dxmvvm:EventToCommand>
                                            </dxmvvm:Interaction.Behaviors>
                                        </dxg:TableView>
                                    </dxg:GridControl.View>
                                </dxg:GridControl>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Header" Value="{Binding GroupName}" />
                    <Setter Property="dx:TabControlStretchView.PinMode" Value="Left" />
                </Style>
            </dx:DXTabControl.ItemContainerStyle>
        </dx:DXTabControl>

        <dx:WaitIndicator DeferedVisibility="{Binding IsLoading}" Content="Loading..." Grid.Row="1" />
    </Grid>
</UserControl>
