<UserControl x:Class="SmartAquaViewer.View.MonitoringView"
             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:SmartAquaViewer.View"
             xmlns:control="clr-namespace:SmartAquaViewer.Controls"
             xmlns:helper="clr-namespace:SmartAquaViewer.Helper"
             xmlns:model="clr-namespace:SmartAquaViewer.Model"
             xmlns:classes="clr-namespace:SmartAquaViewer.Classes"
             xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
             mc:Ignorable="d" 
             d:DesignHeight="940" d:DesignWidth="1650">

    <UserControl.Resources>
        <classes:EnumEqualsConverter x:Key="EnumEqualsConverter"/>
        <classes:BoolToPowerConverter x:Key="BoolToPowerConverter"/>
    </UserControl.Resources>

    <Border BorderBrush="#2d374c" BorderThickness="2">
        <md:DrawerHost BottomDrawerBackground="Transparent" IsBottomDrawerOpen="{Binding IsOpenMode}" OpenMode="Standard">
            <Grid Background="Transparent">
                <Grid.RowDefinitions>
                    <RowDefinition Height="70"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid>
                    <!--<Grid.Background>
                        <ImageBrush ImageSource="/Resources/Images/top_bg.png" Stretch="Fill"/>
                    </Grid.Background>-->
                    <control:SegmentedControl x:Name="segmentedControl" Margin="15 10"
                                              SelectedTab="{Binding SelectedTab, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </Grid>

                <DataGrid x:Name="dgTanks" ItemsSource="{Binding TanksByTimes}"
                          Style="{StaticResource DataGridStyle}"
                          RowStyle="{StaticResource DataGridRowStyle}"
                          ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
                          Grid.Row="1" Margin="15 0 15 40"
                          ColumnWidth="*"
                          Background="Transparent"
                          HorizontalAlignment="Stretch">
                    <DataGrid.Columns>
                        <!-- 측정 시각 -->
                        <DataGridTextColumn 
                                Header="시간" Width="80"
                                Binding="{Binding RecordedTime, StringFormat=\{0:HH:mm:ss\}}"
                                ElementStyle="{StaticResource DataGridElmenetStyle}"/>

                        <!-- Tank 값들 -->
                        <DataGridTextColumn Header="번호" Binding="{Binding Tanks[0].Number}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Binding="{Binding Tanks[0].DOValue, StringFormat=\{0:F2\}}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="DO" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(mg/L)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="pH" Binding="{Binding Tanks[0].PH, StringFormat=\{0:F2\}}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Binding="{Binding Tanks[0].ORP, StringFormat=\{0:F0\}}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="ORP" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(mV)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Tanks[0].Temperature, StringFormat=\{0:F1\}}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="온도" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(℃)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Tanks[0].FlowRate, StringFormat=\{0:F2\}}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="유량" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(m³/s)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>

                        <DataGridTextColumn Width="5"/>

                        <DataGridTextColumn Header="번호" Binding="{Binding Tanks[1].Number}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Binding="{Binding Tanks[1].DOValue, StringFormat=\{0:F2\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="DO" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(mg/L)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="pH" Binding="{Binding Tanks[1].PH, StringFormat=\{0:F2\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Binding="{Binding Tanks[1].ORP, StringFormat=\{0:F0\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="ORP" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(mV)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Tanks[1].Temperature, StringFormat=\{0:F1\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="온도" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(℃)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Tanks[1].FlowRate, StringFormat=\{0:F2\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="유량" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(m³/s)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Width="5"/>

                        <DataGridTextColumn Header="번호" Binding="{Binding Tanks[2].Number}"
                                                ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Binding="{Binding Tanks[2].DOValue, StringFormat=\{0:F2\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="DO" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(mg/L)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Header="pH" Binding="{Binding Tanks[2].PH, StringFormat=\{0:F2\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Binding="{Binding Tanks[2].ORP, StringFormat=\{0:F0\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="ORP" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(mV)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Tanks[2].Temperature, StringFormat=\{0:F1\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="온도" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(℃)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Tanks[2].FlowRate, StringFormat=\{0:F2\}}"
                        ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="유량" HorizontalAlignment="Center"/>
                                    <TextBlock Text="(m³/s)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>

                <DataGrid ItemsSource="{Binding WaterQualityList}" x:Name="dgFilter"
                          Style="{StaticResource DataGridStyle}" ColumnWidth="*"
                          Grid.Row="1" Margin="15 0 15 40" 
                          Background="Transparent"
                          RowStyle="{StaticResource DataGridRowStyle}" 
                          ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
                    <DataGrid.Columns>
                        <DataGridTextColumn 
                            Header="시간"
                            Binding="{Binding RecordedTime, StringFormat=\{0:HH:mm:ss\}}"
                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>

                        <DataGridTextColumn Binding="{Binding Filtering.SandFilterPower, Converter={StaticResource BoolToPowerConverter}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="모래여과기" HorizontalAlignment="Center"/>
                                    <TextBlock Text="전원" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.SumpPH}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="섬프탱크" HorizontalAlignment="Center"/>
                                    <TextBlock Text="pH" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.SumpORP, StringFormat=\{0:F2\}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="섬프탱크" HorizontalAlignment="Center"/>
                                    <TextBlock Text="ORP(mV)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.SumpWaterLevel, StringFormat=\{0:F0\}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="섬프탱크" HorizontalAlignment="Center"/>
                                    <TextBlock Text="수위(m)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.SumpFlowRate, StringFormat=\{0:F1\}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="섬프탱크" HorizontalAlignment="Center"/>
                                    <TextBlock Text="유량(m³/s)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.SumpTemperature, StringFormat=\{0:F2\}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="섬프탱크" HorizontalAlignment="Center"/>
                                    <TextBlock Text="수온(°C)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.CirculationPumpPower, Converter={StaticResource BoolToPowerConverter}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="순환펌프" HorizontalAlignment="Center"/>
                                    <TextBlock Text="전원" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.InverterControllerStatus}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="인버터 제어기" HorizontalAlignment="Center"/>
                                    <TextBlock Text="상태" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.FlowRate, StringFormat=\{0:F2\}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="순환펌프" HorizontalAlignment="Center"/>
                                    <TextBlock Text="유량(m³/s)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.HeatPumpPower, Converter={StaticResource BoolToPowerConverter}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="히트펌프" HorizontalAlignment="Center"/>
                                    <TextBlock Text="전원" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.HeatPumpTemperature, StringFormat=\{0:F2\}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="히트펌프" HorizontalAlignment="Center"/>
                                    <TextBlock Text="온도(°C)" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                        <DataGridTextColumn Binding="{Binding Filtering.AirBlowerPower, Converter={StaticResource BoolToPowerConverter}}" 
                                            ElementStyle="{StaticResource DataGridElmenetStyle}">
                            <DataGridTextColumn.Header>
                                <StackPanel>
                                    <TextBlock Text="에어브로와" HorizontalAlignment="Center"/>
                                    <TextBlock Text="전원" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </DataGridTextColumn.Header>
                        </DataGridTextColumn>
                    </DataGrid.Columns>
                </DataGrid>

                <DataGrid ItemsSource="{Binding WaterQualityList}" x:Name="dgSterilizer"
                          Style="{StaticResource DataGridStyle}" ColumnWidth="*"
                          Grid.Row="1" Margin="15 0 15 40" 
                          Background="Transparent"
                          VerticalScrollBarVisibility="Auto"
                          RowStyle="{StaticResource DataGridRowStyle}" 
                          ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
                    <DataGrid.Columns>
                        <DataGridTextColumn 
                            Header="시간"
                            Binding="{Binding RecordedTime, StringFormat=\{0:HH:mm:ss\}}"
                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>

                        <DataGridTextColumn Header="오존 발생기 전원" Binding="{Binding Sterilizing.OzoneGeneratorPower, Converter={StaticResource BoolToPowerConverter}}"
                                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Header="자외선 살균기 ID" Binding="{Binding Sterilizing.UVSterilizerId}"
                                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Header="자외선 살균기 전원" Binding="{Binding Sterilizing.UVSterilizerPower, Converter={StaticResource BoolToPowerConverter}}"
                                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Header="오존용해장치 전원" Binding="{Binding Sterilizing.OzoneDissolverPower, Converter={StaticResource BoolToPowerConverter}}"
                                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Header="오존용해장치 압력(kPa)" Binding="{Binding Sterilizing.OzoneDissolverPressure, StringFormat=\{0:F1\}}"
                                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                        <DataGridTextColumn Header="배오존장치 전원" Binding="{Binding Sterilizing.ExcessOzoneDestroyerPower, Converter={StaticResource BoolToPowerConverter}}"
                                            ElementStyle="{StaticResource DataGridElmenetStyle}"/>
                    </DataGrid.Columns>
                </DataGrid>

                <Grid Grid.Row="1" VerticalAlignment="Bottom">
                    <Button Name="btnVisibilityDown" Tag="down" 
                            Style="{StaticResource ImageButtonStyle}" Height="33" Command="{Binding ChangeDrawerStatusCommand}"
                            VerticalAlignment="Bottom" HorizontalAlignment="Center" Visibility="{Binding BtnVisibilityDown}"
                            helper:ImageButtonHelper.ImageSource="/Resources/Images/arrow_down.png"/>

                    <Button Name="btnVisibilityUp" Tag="up"
                            Style="{StaticResource ImageButtonStyle}" Height="33" Command="{Binding ChangeDrawerStatusCommand}"
                            VerticalAlignment="Bottom" HorizontalAlignment="Center" Visibility="{Binding BtnVisibilityUp}"
                            helper:ImageButtonHelper.ImageSource="/Resources/Images/arrow_up.png"/>
                </Grid>
            </Grid>
            <md:DrawerHost.BottomDrawerContent>
                <Border Height="450" BorderThickness="0 3 0 0" BorderBrush="#455569">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="550"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Border Margin="15"
                                Background="#384659" BorderBrush="#404F63" BorderThickness="1" CornerRadius="10">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition Height="50"/>
                                </Grid.RowDefinitions>
                                <Grid.Resources>
                                    <Style TargetType="FrameworkElement">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </Style>
                                    <Style x:Key="VisibleWhenTank" TargetType="FrameworkElement" BasedOn="{StaticResource {x:Type FrameworkElement}}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding SelectedTab}" Value="Tank">
                                                <Setter Property="Visibility" Value="Visible"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Grid.Resources>
                                <StackPanel>
                                    <Grid Margin="15 15 15 10">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="80"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="그래프" VerticalAlignment="Center"
                                                   FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>

                                        <ComboBox Margin="15 0 0 0" Height="40" Grid.Column="1"
                                                  Style="{StaticResource ComboBoxStyle}"
                                                  ItemsSource="{Binding GraphTypes}"
                                                  SelectedIndex="{Binding SelectedGraphIndex, Mode=TwoWay}"
                                                  helper:ComboBoxHelper.SelectFirstOnItemsChange="True"
                                                  IsEditable="False" IsTextSearchEnabled="False"/>
                                    </Grid>
                                    <Grid Margin="15 0 15 10">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="80"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="X축" VerticalAlignment="Center"
                                                   FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                        <ComboBox Margin="15 0 0 0" Height="40" Grid.Column="1"
                                                  Style="{StaticResource ComboBoxStyle}"
                                                  ItemsSource="{Binding XFieldCandidates}"
                                                  SelectedItem="{Binding SelectedXField}"
                                                  DisplayMemberPath="Display"/>
                                    </Grid>

                                    <StackPanel Margin="15 0" Style="{StaticResource VisibleWhenTank}">
                                        <TextBlock Text="수조 (복수 선택)" VerticalAlignment="Center"
                                                   FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>

                                        <Border CornerRadius="10" Background="White" Margin="0 5 0 10">
                                            <ListBox ItemsSource="{Binding TankGroups}"
                                                     DisplayMemberPath="Key"
                                                     SelectionMode="Extended"
                                                     helper:MultiSelectBehavior.SelectedDictionary="{Binding SelectedWaterTanks, Mode=OneWay}"
                                                     helper:MultiSelectBehavior.KeyPath="Key"
                                                     helper:MultiSelectBehavior.ValuePath="Value"
                                                     Height="Auto" Background="White"
                                                     FontSize="16" FontWeight="Bold"
                                                     Style="{StaticResource MaterialDesignFilterChipListBox}"/>
                                        </Border>
                                    </StackPanel>

                                    <Grid Margin="15 0">
                                        <Grid.Resources>
                                            <Style TargetType="FrameworkElement">
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                            </Style>
                                            <!-- 보이기 토글용 스타일 -->
                                            <Style x:Key="VisibleWhenLine" TargetType="FrameworkElement" BasedOn="{StaticResource {x:Type FrameworkElement}}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="LINE">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                            <Style x:Key="VisibleWhenStep" TargetType="FrameworkElement" BasedOn="{StaticResource {x:Type FrameworkElement}}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="STEP">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                            <Style x:Key="VisibleWhenScatter" TargetType="FrameworkElement" BasedOn="{StaticResource {x:Type FrameworkElement}}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="SCATTER">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                            <Style x:Key="VisibleWhenBox" TargetType="FrameworkElement" BasedOn="{StaticResource {x:Type FrameworkElement}}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="BOX">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                            <Style x:Key="VisibleWhenTime" TargetType="FrameworkElement" BasedOn="{StaticResource {x:Type FrameworkElement}}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedXField.Name}" Value="RecordedTime">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Grid.Resources>

                                        <!-- LINE -->
                                        <StackPanel Style="{StaticResource VisibleWhenLine}">
                                            <Grid Style="{StaticResource VisibleWhenLine}">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="Y축" VerticalAlignment="Center" Style="{StaticResource VisibleWhenLine}"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <ComboBox ItemsSource="{Binding YFieldCandidates}"
                                                          SelectedItem="{Binding SelectedYField, Mode=TwoWay}"
                                                          Grid.Column="1"
                                                          DisplayMemberPath="Display" Margin="15 0 0 0"
                                                          Height="40" Style="{StaticResource ComboBoxStyle}"/>
                                            </Grid>
                                        </StackPanel>

                                        <!--STEP-->
                                        <StackPanel Style="{StaticResource VisibleWhenStep}">
                                            <Grid Margin="0 5 0 10">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="100"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="필드 종류" VerticalAlignment="Center"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Center">
                                                    <RadioButton x:Name="rbStatus" Content="전원/상태" 
                                                                 GroupName="strpPlot" Margin="0 0 30 0"
                                                                 Foreground="White" FontSize="20"
                                                                 Style="{StaticResource MaterialDesignUserForegroundRadioButton}"
                                                                 IsChecked="{Binding SelectedKind, Mode=TwoWay,
                                                                                     Converter={StaticResource EnumEqualsConverter},
                                                                                     ConverterParameter={x:Static model:StepFieldKind.Status}}"/>
                                                    <RadioButton x:Name="rbValue" Content="센서 값" 
                                                                 GroupName="strpPlot" Grid.Column="1" 
                                                                 Foreground="White" FontSize="20"
                                                                 Style="{StaticResource MaterialDesignUserForegroundRadioButton}"
                                                                 IsChecked="{Binding SelectedKind, Mode=TwoWay,
                                                                                     Converter={StaticResource EnumEqualsConverter},
                                                                                     ConverterParameter={x:Static model:StepFieldKind.Sensor}}"/>
                                                </StackPanel>
                                            </Grid>

                                            <StackPanel Margin="0 5 0 0">
                                                <TextBlock Text="Y축 (복수 선택)" VerticalAlignment="Center" 
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <!-- SelectedItems 바인딩을 위한 간단 Behavior는 아래 3) 참고 -->
                                                <Border CornerRadius="10" Background="White" Margin="0 5">
                                                    <ListBox ItemsSource="{Binding YFieldCandidates}"
                                                             DisplayMemberPath="Display"
                                                             SelectionMode="Extended"
                                                             helper:MultiSelectBehavior.SelectedItems="{Binding SelectedYFields, Mode=OneWay}"
                                                             Height="Auto" Background="White"
                                                             FontSize="14" FontWeight="Bold"
                                                             Style="{StaticResource MaterialDesignFilterChipListBox}"/>
                                                </Border>
                                            </StackPanel>
                                        </StackPanel>

                                        <!-- SCATTER: 단일 Y + 옵션 -->
                                        <StackPanel Style="{StaticResource VisibleWhenScatter}">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="Y축" VerticalAlignment="Center" Width="80"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <ComboBox ItemsSource="{Binding YFieldCandidates}"
                                                          SelectedItem="{Binding SelectedYField}"
                                                          DisplayMemberPath="Display" Height="40"
                                                          Grid.Column="1" Grid.ColumnSpan="3" Margin="15 0 0 0"
                                                          Style="{StaticResource ComboBoxStyle}"/>
                                            </Grid>

                                            <Grid Margin="0 10">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="마커 크기" Grid.Row="1" VerticalAlignment="Center"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <Slider Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="15 0 0 0"
                                                        Minimum="1" Maximum="15" Value="{Binding ScatterMarkerSize}" Width="280" IsSnapToTickEnabled="True" TickFrequency="1"/>
                                                <TextBlock Text="{Binding ScatterMarkerSize}" Margin="15 0"
                                                           Grid.Row="1" Grid.Column="2" VerticalAlignment="Center"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                            </Grid>
                                        </StackPanel>

                                        <!-- BOX: 값 필드 + 그룹 필드 + 옵션 -->
                                        <StackPanel Style="{StaticResource VisibleWhenBox}">
                                            <Grid Style="{StaticResource VisibleWhenTime}" Margin="0 10 0 15">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="시간 범위" VerticalAlignment="Center"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <Slider Margin="15 0 0 0" Grid.Column="1"
                                                        VerticalAlignment="Center" HorizontalAlignment="Left"
                                                        Minimum="1" Maximum="24" TickFrequency="1" IsSnapToTickEnabled="True"
                                                        Value="{Binding BoxTimeSpan}" Width="310"/>
                                                <TextBlock Text="{Binding BoxTimeSpan}" 
                                                           Margin="15 0" Grid.Column="2"
                                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                                           FontSize="18" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                            </Grid>

                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="값 필드" VerticalAlignment="Center"
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <ComboBox ItemsSource="{Binding YFieldCandidates}"
                                                          SelectedItem="{Binding SelectedYField}"
                                                          DisplayMemberPath="Display" Height="40"
                                                          Grid.Column="1" Margin="15 0 0 0"
                                                          Style="{StaticResource ComboBoxStyle}"/>
                                            </Grid>

                                            <Grid Margin="0 15 0 0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <TextBlock Text="박스 너비" VerticalAlignment="Center" 
                                                           FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                                <Slider Margin="15 0 0 0" Grid.Column="1"
                                                        VerticalAlignment="Center" HorizontalAlignment="Left"
                                                        Minimum="0.1" Maximum="1.0" TickFrequency="0.05" IsSnapToTickEnabled="True"
                                                        Value="{Binding BoxWidth}" Width="310"/>
                                                <TextBlock Text="{Binding BoxWidth, StringFormat=F2}" 
                                                           Margin="15 0" Grid.Column="2"
                                                           VerticalAlignment="Center" HorizontalAlignment="Right"
                                                           FontSize="18" FontFamily="{StaticResource SCDream4}" Foreground="White"/>
                                            </Grid>
                                        </StackPanel>
                                    </Grid>
                                </StackPanel>

                                <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="15 0">
                                    <CheckBox Content="범례 표시" IsChecked="{Binding ShowLegends}"
                                              FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"
                                              Margin="0 0 15 0" VerticalContentAlignment="Center"
                                              Style="{StaticResource MaterialDesignUserForegroundCheckBox}"/>
                                    <CheckBox Content="마커 표시" IsChecked="{Binding ShowMarkers}"
                                              FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"
                                              Margin="0 0 15 0" VerticalContentAlignment="Center">
                                        <CheckBox.Style>
                                            <Style TargetType="CheckBox" BasedOn="{StaticResource MaterialDesignUserForegroundCheckBox}">
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="LINE">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="STEP">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </CheckBox.Style>
                                    </CheckBox>
                                    <CheckBox Content="회귀선" IsChecked="{Binding ShowRegression}"
                                              FontSize="20" FontFamily="{StaticResource SCDream4}" Foreground="White"
                                              Margin="0 0 15 0" VerticalContentAlignment="Center">
                                        <CheckBox.Style>
                                            <Style TargetType="CheckBox" BasedOn="{StaticResource MaterialDesignUserForegroundCheckBox}">
                                                <Setter Property="Visibility" Value="Collapsed"/>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding SelectedGraphType}" Value="SCATTER">
                                                        <Setter Property="Visibility" Value="Visible"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </CheckBox.Style>
                                    </CheckBox>
                                </StackPanel>

                                <StackPanel Orientation="Horizontal" Margin="15 0" Grid.Row="1" HorizontalAlignment="Right">
                                    <Button Content="그래프 생성" Style="{StaticResource MaterialDesignFlatLightBgButton}"
                                            FontWeight="Bold" Command="{Binding DrawGraphCommand}"/>
                                </StackPanel>
                            </Grid>
                        </Border>

                        <Border Grid.Column="1" Margin="0 15 15 15"
                                Background="#384659" CornerRadius="10">
                            <control:GraphControl x:Name="graphControl"
                                                  Margin="10" DataContext="{Binding GraphControlVM}"
                                                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                        </Border>
                    </Grid>
                </Border>
            </md:DrawerHost.BottomDrawerContent>
        </md:DrawerHost>
    </Border>
</UserControl>
