﻿<Window x:Class="OpenTapEditor.StepWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:OpenTapEditor"
        mc:Ignorable="d"
        xmlns:pu="https://opensource.panuon.com/wpf-ui"
        WindowStartupLocation="CenterOwner"
        FontSize="{DynamicResource GlobalFontSize}"
        Title="{DynamicResource 自定义测试步骤}" Height="800" Width="1200">
    <Window.Resources>
        <Style x:Key="itemstyle" TargetType="{x:Type ListViewItem}">
            <EventSetter Event="MouseDoubleClick" Handler="HandleDoubleClick" />
        </Style>

        <CollectionViewSource x:Key="GroupFilter" Source="{Binding CustomSteps}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="GroupBy" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <GroupBox Header="{DynamicResource 原型}">
            <ListView ItemsSource="{Binding Steps}" SelectedItem="{Binding TargetType}"
                       AlternationCount="2"
                       ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border x:Name="border" Padding="3" BorderThickness="0,0,0,1"
                                                BorderBrush="{StaticResource BorderBrush}">
                                        <DockPanel Background="Transparent" x:Name="dock" Margin="3">
                                            <Button DockPanel.Dock="Right" 
                                                    Style="{StaticResource LinkButton}" Click="Button_Click"
                                                    DataContext="{Binding }"
                                                    Content="{DynamicResource 创建}"
                                                    Tag="Create"/>
                                            <TextBlock Text="{Binding Name}"/>
                                        </DockPanel>
                                    </Border>
                                    
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                            <Setter TargetName="border" Property="Background" Value="#e9eef5"/>
                                        </Trigger>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="border" Property="Background" Value="#e5f3fb"/>
                                        </Trigger>
                                        <Trigger Property="ListViewItem.IsSelected" Value="True">
                                            <Setter TargetName="border" Property="Background" Value="#cbe8f6"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListView.ItemContainerStyle>
            </ListView>
        </GroupBox>
        <GroupBox Grid.Column="1" Header="{DynamicResource 自定义测试步骤}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ListView Grid.Row="1" SelectedItem="{Binding TargetType}"
                          ItemsSource="{Binding Source={StaticResource GroupFilter}}"
                          AlternationCount="2">
                    <ListView.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.ContainerStyle>
                                <Style TargetType="{x:Type GroupItem}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                                <Expander pu:ExpanderHelper.CornerRadius="0"
                                                          BorderBrush="White" BorderThickness="0,0,0,1"
                                                          Background="{DynamicResource PrimaryBrush}"
                                      IsExpanded="True">
                                                    <Expander.Header>
                                                        <TextBlock Text="{Binding Name}" Margin="8" Foreground="#FFF"/>
                                                    </Expander.Header>
                                                    <Border Background="#FFF">
                                                        <ItemsPresenter />
                                                    </Border>
                                                </Expander>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </GroupStyle.ContainerStyle>
                        </GroupStyle>
                    </ListView.GroupStyle>


                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Border x:Name="border" Padding="3" BorderThickness="0,0,0,1"
                                                BorderBrush="{StaticResource BorderBrush}">
                                            <DockPanel Background="Transparent" x:Name="dock" Margin="3">
                                                <Button DockPanel.Dock="Right" Margin="10,0,0,0"
                                                        Style="{StaticResource LinkButton}"
                                                        Click="Button_Click" DataContext="{Binding }" Foreground="{DynamicResource ErrorBrush}" 
                                                        Tag="Delete" Content="{DynamicResource 删除}"/>
                                                <Button DockPanel.Dock="Right" Margin="10,0,0,0"
                                                        Style="{StaticResource LinkButton}"
                                                        Click="Button_Click" DataContext="{Binding }" Tag="Edit" Content="{DynamicResource 编辑}"/>
                                                <Button DockPanel.Dock="Right" 
                                                        Style="{StaticResource LinkButton}" 
                                                        Click="Button_Click" DataContext="{Binding }" Tag="Copy" Content="{DynamicResource 复制}"/>
                                                <TextBlock Text="{Binding Name}"/>
                                            </DockPanel>
                                        </Border>

                                        <ControlTemplate.Triggers>
                                            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                                                <Setter TargetName="border" Property="Background" Value="#e9eef5"/>
                                            </Trigger>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="border" Property="Background" Value="#e5f3fb"/>
                                            </Trigger>
                                            <Trigger Property="ListViewItem.IsSelected" Value="True">
                                                <Setter TargetName="border" Property="Background" Value="#cbe8f6"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListView.ItemContainerStyle>
                </ListView>
            </Grid>
        </GroupBox>
    </Grid>
</Window>
