<UserControl x:Class="MainShell.ParaSetting.View.ProduceControlView"
             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:local="clr-namespace:MainShell.ParaSetting.View"
             xmlns:mw="http://www.maxwell-gp.com/"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <!-- ToggleButton样式 - 金属光泽开关样式 -->
        <Style x:Key="MetallicToggleStyle" TargetType="ToggleButton">
            <Setter Property="Width" Value="60"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Grid>
                            <!-- 外部方形区域（金属边框效果） -->
                            <Border x:Name="OuterBorder" 
                                    Width="60" 
                                    Height="30" 
                                    CornerRadius="4"
                                    Background="White"
                                    BorderBrush="#C0C0C0"
                                    BorderThickness="2">
                                <Border.Effect>
                                    <DropShadowEffect ShadowDepth="1" 
                                                      BlurRadius="2" 
                                                      Opacity="0.3"/>
                                </Border.Effect>
                            </Border>

                            <!-- 内部轨道 -->
                            <Border x:Name="Track" 
                                    Width="54" 
                                    Height="24" 
                                    CornerRadius="3"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Background="#F0F0F0"
                                    BorderBrush="#D0D0D0"
                                    BorderThickness="1">
                                <!--<Border.Effect>
                                    --><!--<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#E8E8E8" Offset="0"/>
                                        <GradientStop Color="#F8F8F8" Offset="1"/>
                                    </LinearGradientBrush>--><!--
                                </Border.Effect>-->
                            </Border>

                            <!-- 圆形开关按钮 -->
                            <Border x:Name="Knob" 
                                    Width="28" 
                                    Height="28" 
                                    CornerRadius="14"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center"
                                    Margin="1,0,0,0">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop x:Name="KnobGradient1" Color="#D0D0D0" Offset="0"/>
                                        <GradientStop x:Name="KnobGradient2" Color="#E0E0E0" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                                <Border.Effect>
                                    <DropShadowEffect ShadowDepth="2" 
                                                      BlurRadius="3" 
                                                      Opacity="0.3"/>
                                </Border.Effect>
                                <Border.BorderBrush>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#B0B0B0" Offset="0"/>
                                        <GradientStop Color="#C0C0C0" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                                <Border.BorderThickness>
                                    1
                                </Border.BorderThickness>
                            </Border>
                        </Grid>

                        <ControlTemplate.Triggers>
                            <!-- 开状态 -->
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="Knob" Property="HorizontalAlignment" Value="Right"/>
                                <Setter TargetName="Knob" Property="Margin" Value="0,0,1,0"/>
                                <Setter TargetName="Track" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#E0F7E0" Offset="0"/>
                                            <GradientStop Color="#F0FFF0" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="Knob" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#4CAF50" Offset="0"/>
                                            <GradientStop Color="#66BB6A" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="Knob" Property="BorderBrush">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#388E3C" Offset="0"/>
                                            <GradientStop Color="#4CAF50" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>

                            <!-- 悬停效果 -->
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="OuterBorder" Property="BorderBrush" Value="#A0A0A0"/>
                                <Setter TargetName="OuterBorder" Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect ShadowDepth="1.5" 
                                                          BlurRadius="3" 
                                                          Opacity="0.4"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>

                            <!-- 禁用状态 -->
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="OuterBorder" Property="Opacity" Value="0.6"/>
                                <Setter TargetName="Knob" Property="Opacity" Value="0.6"/>
                                <Setter TargetName="Track" Property="Opacity" Value="0.6"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Border Background="White" CornerRadius="8" BorderBrush="#E0E0E0" BorderThickness="1" Padding="10">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="60"/>
            </Grid.RowDefinitions>
            <!-- 开关控制区域 -->
            <ItemsControl Grid.Row="1" ItemsSource="{Binding SubProcesses}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="6" Rows="4" HorizontalAlignment="Center"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border Width="140" 
                                Height="90" 
                                Margin="5" 
                                Background="#F9F9F9"
                                CornerRadius="6"
                                BorderBrush="#E8E8E8"
                                BorderThickness="1"
                                Padding="5">
                            <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
                                <!-- 流程名称 -->
                                <TextBlock Text="{Binding ProcessName}" 
                                           FontSize="13"
                                           FontWeight="SemiBold"
                                           Foreground="#34495E"
                                           HorizontalAlignment="Center"
                                           Margin="0,0,0,8"
                                           TextWrapping="Wrap"/>

                                <!-- 开关控件 -->
                                <ToggleButton x:Name="ProcessToggle"
                                              IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                                              Style="{StaticResource MetallicToggleStyle}"
                                              HorizontalAlignment="Center"
                                              Cursor="Hand"
                                              ToolTip="{Binding ToolTipText}"/>

                                <!-- 状态文本 -->
                                <TextBlock Text="{Binding StatusText}" 
                                           FontSize="11"
                                           Foreground="#7F8C8D"
                                           HorizontalAlignment="Center"
                                           Margin="0,5,0,0"/>
                            </StackPanel>

                            <!-- 边框悬停效果 -->
                            <Border.Style>
                                <Style TargetType="Border">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsEnabled}" Value="True">
                                            <Setter Property="BorderBrush" Value="#4CAF50"/>
                                            <Setter Property="Background">
                                                <Setter.Value>
                                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                        <GradientStop Color="#F1F8E9" Offset="0"/>
                                                        <GradientStop Color="#FFFFFF" Offset="1"/>
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="BorderBrush" Value="#BDC3C7"/>
                                            <Setter Property="Effect">
                                                <Setter.Value>
                                                    <DropShadowEffect ShadowDepth="1" 
                                                                      BlurRadius="5" 
                                                                      Opacity="0.2"/>
                                                </Setter.Value>
                                            </Setter>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
 
            <Button Content="保存" Click="{mw:Action BtnSave}" Grid.Row="2" Style="{StaticResource SaveButtonStyle}" HorizontalAlignment="Right"/>
        </Grid>
    </Border>
</UserControl>
