<UserControl x:Class="DeviceEditModule.Views.IT7800EView"
             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:prism="http://prismlibrary.com/"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
             mc:Ignorable="d"
             prism:ViewModelLocator.AutoWireViewModel="False"
             d:DesignHeight="760" d:DesignWidth="860">

    <UserControl.Resources>
        <converters:BooleanToVisibilityConverter x:Key="BoolToVis"/>

      
    </UserControl.Resources>

    <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
        <StackPanel Margin="12">

            <!-- ═══ 设备信息头 ═══ -->
            <materialDesign:Card Margin="0,0,0,8" Padding="12,8">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <materialDesign:PackIcon Kind="Flash" Width="22" Height="22"
                                                 Foreground="#1565C0" Margin="0,0,8,0"
                                                 VerticalAlignment="Center"/>
                        <TextBlock Text="IT7800E  交直流可编程电源"
                                   FontSize="15" FontWeight="Bold"
                                   VerticalAlignment="Center"/>
                        <TextBlock Text="{Binding DeviceName, StringFormat=' [{0}]'}"
                                   FontSize="13" Foreground="#757575"
                                   VerticalAlignment="Center" Margin="4,0,0,0"/>
                    </StackPanel>

                    <!-- 连接状态指示 -->
                    <StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center">
                        <Border Width="10" Height="10" CornerRadius="5" Margin="0,0,6,0">
                            <Border.Style>
                                <Style TargetType="Border">
                                    <Setter Property="Background" Value="#F44336"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsConnected}" Value="True">
                                            <Setter Property="Background" Value="#4CAF50"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                        </Border>
                        <TextBlock VerticalAlignment="Center" FontSize="12">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Text"       Value="未连接"/>
                                    <Setter Property="Foreground" Value="#F44336"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsConnected}" Value="True">
                                            <Setter Property="Text"       Value="已连接"/>
                                            <Setter Property="Foreground" Value="#4CAF50"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                        <!-- 忙碌指示 -->
                        <ProgressBar IsIndeterminate="True" Width="80" Height="4"
                                     Margin="12,0,0,0"
                                     Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}"/>
                    </StackPanel>
                </Grid>
            </materialDesign:Card>

            <!-- ═══ 主体 2 列 ═══ -->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <!-- ─── 左列 ─── -->
                <StackPanel Grid.Column="0" Margin="0,0,4,0">

                    <!-- 输出控制 -->
                    <GroupBox Header="输出控制" Margin="0,0,0,8"
                              materialDesign:ColorZoneAssist.Mode="PrimaryLight">
                        <StackPanel Margin="4,4,4,4">
                            <!-- 开关输出 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="主输出" Style="{StaticResource ParamLabel}"/>
                                <Button Content="开启输出" Command="{Binding OutputOnCommand}"
                                        Style="{StaticResource MaterialDesignRaisedButton}"
                                        Background="#388E3C" Foreground="White"
                                        Height="32" Padding="12,0" FontSize="12" Margin="4,0"/>
                                <Button Content="关闭输出" Command="{Binding OutputOffCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                            </StackPanel>
                            <!-- 工作模式 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="工作模式" Style="{StaticResource ParamLabel}"/>
                                <ComboBox Width="90" Height="32" Margin="4,0"
                                          materialDesign:HintAssist.Hint=""
                                          SelectedItem="{Binding SelectedMode}"
                                          VerticalContentAlignment="Center" FontSize="12">
                                    <ComboBoxItem Content="AC"/>
                                    <ComboBoxItem Content="DC"/>
                                    <ComboBoxItem Content="ACDC"/>
                                </ComboBox>
                                <Button Content="设置模式" Command="{Binding SetModeCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <!-- 远程/本地 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="控制模式" Style="{StaticResource ParamLabel}"/>
                                <Button Content="远程控制" Command="{Binding SetRemoteModeCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="本地控制" Command="{Binding SetLocalModeCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <!-- 清除 / 重置 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="系统操作" Style="{StaticResource ParamLabel}"/>
                                <Button Content="清除告警" Command="{Binding ClearAlarmCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                                <Button Content="清除错误" Command="{Binding ClearErrorCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                                <Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>

                    <!-- 参数设置 -->
                    <GroupBox Header="参数设置" Margin="0,0,0,8"
                              materialDesign:ColorZoneAssist.Mode="PrimaryLight">
                        <StackPanel Margin="4,4,4,4">
                            <!-- AC 电压 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="AC电压 (V)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding AcVoltage, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetAcVoltageCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <!-- DC 偏置 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="DC偏置 (V)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding DcVoltage, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetDcVoltageCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <!-- 频率 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="频率 (Hz)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding Frequency, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetFrequencyCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <!-- 限流 -->
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="限流 (A)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding CurrentLimit, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetCurrentCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>

                    <!-- 保护设置 -->
                    <GroupBox Header="保护设置" Margin="0,0,0,8"
                              materialDesign:ColorZoneAssist.Mode="PrimaryLight">
                        <StackPanel Margin="4,4,4,4">
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="OVP (V)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding OvpValue, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置 OVP" Command="{Binding SetOvpCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="OCP (A)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding OcpValue, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置 OCP" Command="{Binding SetOcpCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>
                </StackPanel>

                <!-- ─── 右列 ─── -->
                <StackPanel Grid.Column="1" Margin="4,0,0,0">

                    <!-- 实时测量 -->
                    <GroupBox Header="实时测量" Margin="0,0,0,8"
                              materialDesign:ColorZoneAssist.Mode="PrimaryLight">
                        <StackPanel Margin="4,4,4,4">
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="实际电压" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding MeasuredVoltage, Mode=OneWay}"/>
                                <TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="实际电流" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding MeasuredCurrent, Mode=OneWay}"/>
                                <TextBlock Text="A" VerticalAlignment="Center" Margin="2,0,8,0"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="实际功率" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding MeasuredPower, Mode=OneWay}"/>
                                <TextBlock Text="W" VerticalAlignment="Center" Margin="2,0,8,0"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="输出频率" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         materialDesign:HintAssist.Hint=""
                                         Text="{Binding MeasuredFrequency, Mode=OneWay}"/>
                                <TextBlock Text="Hz" VerticalAlignment="Center" Margin="2,0,8,0"/>
                            </StackPanel>
                            <Button Content="刷新全部测量" Command="{Binding QueryAllMeasureCommand}"
                                    Style="{StaticResource CmdBtn}"
                                    HorizontalAlignment="Left" Margin="0,4,0,0"/>
                        </StackPanel>
                    </GroupBox>

                    <!-- 设备信息 -->
                    <GroupBox Header="设备信息" Margin="0,0,0,8"
                              materialDesign:ColorZoneAssist.Mode="PrimaryLight">
                        <StackPanel Orientation="Horizontal" Margin="4,8">
                            <Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
                                    Style="{StaticResource CmdBtn}"/>
                        </StackPanel>
                    </GroupBox>

                    <!-- 响应日志 -->
                    <GroupBox Header="响应日志" Margin="0,0,0,8"
                              materialDesign:ColorZoneAssist.Mode="PrimaryLight">
                        <ScrollViewer Height="260" VerticalScrollBarVisibility="Auto">
                            <TextBox Text="{Binding ResponseLog, Mode=OneWay}"
                                     materialDesign:HintAssist.Hint=""
                                     IsReadOnly="True"
                                     TextWrapping="Wrap"
                                     FontSize="11"
                                     FontFamily="Consolas"
                                     Background="#FAFAFA"
                                     BorderThickness="0"
                                     VerticalAlignment="Top"/>
                        </ScrollViewer>
                    </GroupBox>
                </StackPanel>
            </Grid>
        </StackPanel>
    </ScrollViewer>
</UserControl>
