<UserControl x:Class="DeviceEditModule.Views.SPAW7000View"
             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:sys="clr-namespace:System;assembly=mscorlib"
             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="ChartLine" Width="22" Height="22"
                                                 Foreground="#1565C0" Margin="0,0,8,0"
                                                 VerticalAlignment="Center"/>
                        <TextBlock Text="SPAW7000  功率分析记录仪"
                                   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}"/>
                                <ComboBox Width="80" Height="32" Margin="4,0"
                                          SelectedItem="{Binding Channel}"
                                          VerticalContentAlignment="Center" FontSize="12">
                                    <sys:Int32>1</sys:Int32>
                                    <sys:Int32>2</sys:Int32>
                                    <sys:Int32>3</sys:Int32>
                                    <sys:Int32>4</sys:Int32>
                                    <sys:Int32>5</sys:Int32>
                                    <sys:Int32>6</sys:Int32>
                                    <sys:Int32>7</sys:Int32>
                                    <sys:Int32>8</sys:Int32>
                                </ComboBox>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="电压量程 (V)" Style="{StaticResource ParamLabel}"/>
                                <ComboBox Width="100" Height="32" Margin="4,0"
                                          ItemsSource="{Binding VoltageRangeOptions}"
                                          SelectedItem="{Binding VoltageRange}"
                                          VerticalContentAlignment="Center" FontSize="12"/>
                                <Button Content="设置" Command="{Binding SetVoltageRangeCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="电流量程 (A)" Style="{StaticResource ParamLabel}"/>
                                <ComboBox Width="100" Height="32" Margin="4,0"
                                          ItemsSource="{Binding CurrentRangeOptions}"
                                          SelectedItem="{Binding CurrentRange}"
                                          VerticalContentAlignment="Center" FontSize="12"/>
                                <Button Content="设置" Command="{Binding SetCurrentRangeCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <!--<StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="耦合模式" Style="{StaticResource ParamLabel}"/>
                                <ComboBox Width="90" Height="32" Margin="4,0"
                                          SelectedItem="{Binding CouplingMode}"
                                           ItemsSource="{Binding InputMeasureModeOptions}"
                                          VerticalContentAlignment="Center" FontSize="12">
                                </ComboBox>
                                <Button Content="设置" Command="{Binding SetCouplingModeCommand}"
                                        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="分辨率" Style="{StaticResource ParamLabel}"/>
                                <ComboBox Width="80" Height="32" Margin="4,0"
                                          SelectedItem="{Binding Resolution}"
                                          VerticalContentAlignment="Center" FontSize="12">
                                    <sys:Int32>5</sys:Int32>
                                    <sys:Int32>6</sys:Int32>
                                </ComboBox>
                                <Button Content="设置" Command="{Binding SetResolutionCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="亮度 (1~10)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}" Width="60"
                                         Text="{Binding Brightness, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetBrightnessCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="触摸锁" Style="{StaticResource ParamLabel}"/>
                                <Button Content="锁定" Command="{Binding SetTouchLockOnCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="解锁" Command="{Binding SetTouchLockOffCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                            </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">
                                <Button Content="查询 IDN" Command="{Binding QueryIdentityCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="重置设备" Command="{Binding ResetDeviceCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <Button Content="查询型号" Command="{Binding QueryModelCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="查询序列号" Command="{Binding QuerySerialCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="查询 STB" Command="{Binding QueryStatusByteCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="型号" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}" Width="281"
                                         Text="{Binding DeviceModel, Mode=OneWay}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="序列号" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}" Width="281"
                                         Text="{Binding DeviceSerial, Mode=OneWay}"/>
                            </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}"
                                         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}"
                                         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}"
                                         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}"
                                         Text="{Binding MeasuredFrequency, Mode=OneWay}"/>
                                <TextBlock Text="Hz" VerticalAlignment="Center" Margin="2,0,8,0"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="功率因数" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         Text="{Binding MeasuredPowerFactor, Mode=OneWay}"/>
                            </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">
                        <ScrollViewer Height="360" 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>
