<UserControl x:Class="DeviceEditModule.Views.SDS2000X_HDView"
             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:sys="clr-namespace:System;assembly=mscorlib"
             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="Waveform" Width="22" Height="22"
                                                 Foreground="#1565C0" Margin="0,0,8,0"
                                                 VerticalAlignment="Center"/>
                        <TextBlock Text="SDS2000X_HD  数字存储示波器"
                                   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>
                                </ComboBox>
                                <Button Content="开启" Command="{Binding SetChannelOnCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="关闭" Command="{Binding SetChannelOffCommand}"
                                        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="Run" Command="{Binding RunCommand}"
                                        Style="{StaticResource MaterialDesignRaisedButton}"
                                        Background="#388E3C" Foreground="White"
                                        Height="32" Padding="16,0" FontSize="12" Margin="4,0"/>
                                <Button Content="Stop" Command="{Binding StopCommand}"
                                        Style="{StaticResource WarnBtn}"/>
                                <Button Content="Single" Command="{Binding SingleCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="Force Trig" Command="{Binding ForceTriggerCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <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>
                    </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="V/div (V)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         Text="{Binding VoltsPerDiv}"/>
                                <Button Content="设置" Command="{Binding SetVoltsDivCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="Offset (V)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         Text="{Binding Offset, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetOffsetCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="输入阻抗" Style="{StaticResource ParamLabel}"/>
                                <Button Content="50Ω" Command="{Binding SetImpedance50Command}"
                                        Style="{StaticResource CmdBtn}"/>
                                <Button Content="1MΩ" Command="{Binding SetImpedance1MCommand}"
                                        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="时基 (s/div)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         Text="{Binding TimeBase}"/>
                                <Button Content="设置" Command="{Binding SetTimeBaseCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="触发电平 (V)" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}"
                                         Text="{Binding TriggerLevel, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetTriggerLevelCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="触发源" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource NumInput}" Width="80"
                                         Text="{Binding TriggerSource, UpdateSourceTrigger=PropertyChanged}"/>
                                <Button Content="设置" Command="{Binding SetTriggerSourceCommand}"
                                        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="Vpp" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         Text="{Binding MeasuredVpp, Mode=OneWay}"/>
                                <TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
                                <Button Content="刷新" Command="{Binding QueryVppCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </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"/>
                                <Button Content="刷新" Command="{Binding QueryFrequencyCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Margin="0,4">
                                <TextBlock Text="RMS" Style="{StaticResource ParamLabel}"/>
                                <TextBox Style="{StaticResource MeasureBox}"
                                         Text="{Binding MeasuredRms, Mode=OneWay}"/>
                                <TextBlock Text="V" VerticalAlignment="Center" Margin="2,0,8,0"/>
                                <Button Content="刷新" Command="{Binding QueryRmsCommand}"
                                        Style="{StaticResource CmdBtn}"/>
                            </StackPanel>
                            <Button Content="刷新全部测量" Command="{Binding QueryMeasurementsCommand}"
                                    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="460" 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>
