<UserControl x:Class="ConeCalorimeter.Views.TestPageView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:oxy="http://oxyplot.org/wpf">
    <UserControl.Resources>
        <Style x:Key="PanelBorderStyle" TargetType="Border">
            <Setter Property="Background" Value="#FFFFFF" />
            <Setter Property="BorderBrush" Value="#C9D0CC" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="CornerRadius" Value="6" />
        </Style>

        <Style x:Key="MetricValueStyle" TargetType="TextBlock">
            <Setter Property="Foreground" Value="#071614" />
            <Setter Property="FontFamily" Value="Consolas" />
            <Setter Property="FontSize" Value="24" />
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="HorizontalAlignment" Value="Center" />
        </Style>

        <Style x:Key="StatusDeviceActionButtonStyle"
               TargetType="Button"
               BasedOn="{StaticResource InstrumentButtonStyle}">
            <Setter Property="Background" Value="#EEF1EF" />
            <Setter Property="BorderBrush" Value="#A9B1AD" />
            <Setter Property="Foreground" Value="#172320" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="ButtonBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="6"
                                SnapsToDevicePixels="True">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              RecognizesAccessKey="True" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="ButtonBorder" Property="Opacity" Value="0.86" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="ButtonBorder" Property="Opacity" Value="0.62" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsActive}" Value="True">
                    <Setter Property="Background" Value="#2F8F5B" />
                    <Setter Property="BorderBrush" Value="#236A45" />
                    <Setter Property="Foreground" Value="#FFFFFF" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsStatusKnown}" Value="False">
                    <Setter Property="Background" Value="#E5E7E6" />
                    <Setter Property="BorderBrush" Value="#B8BFBB" />
                    <Setter Property="Foreground" Value="#68736E" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <DataTemplate x:Key="TopMetricTemplate">
            <Border Margin="8,10"
                    Padding="10,8"
                    Background="#EAF0ED"
                    BorderBrush="#AEB8B3"
                    BorderThickness="1"
                    CornerRadius="6">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Label}"
                               FontSize="18"
                               FontWeight="SemiBold"
                               Foreground="#172321"
                               HorizontalAlignment="Center" />
                    <StackPanel Grid.Row="1"
                                Orientation="Horizontal"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center">
                        <TextBlock Text="{Binding ValueText}"
                                   Style="{StaticResource MetricValueStyle}" />
                        <TextBlock Text="{Binding Unit}"
                                   Margin="8,6,0,0"
                                   FontSize="14"
                                   Foreground="#36413E" />
                    </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>

        <DataTemplate x:Key="SideMetricTemplate">
            <Border Margin="0,3"
                    Padding="8,5"
                    Background="#F8FAF9"
                    BorderBrush="#E1E6E3"
                    BorderThickness="1"
                    CornerRadius="4">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="112" />
                    <ColumnDefinition Width="64" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Label}"
                           FontSize="16"
                           FontWeight="SemiBold"
                           Foreground="#1B2826"
                           VerticalAlignment="Center" />
                <TextBlock Grid.Column="1"
                           Text="{Binding ValueText}"
                           FontFamily="Consolas"
                           FontSize="19"
                           FontWeight="SemiBold"
                           HorizontalAlignment="Right"
                           VerticalAlignment="Center" />
                <TextBlock Grid.Column="2"
                           Text="{Binding Unit}"
                           Margin="10,0,0,0"
                           FontSize="16"
                           Foreground="#34423E"
                           VerticalAlignment="Center" />
            </Grid>
            </Border>
        </DataTemplate>
    </UserControl.Resources>

    <Grid Background="#F4F6F5">
        <Grid.RowDefinitions>
            <RowDefinition Height="112" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Border Grid.Row="0"
                Background="#F9FAF9"
                BorderBrush="#CDD4D0"
                BorderThickness="0,0,0,1">
            <Grid Margin="18,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="190" />
                </Grid.ColumnDefinitions>

                <ItemsControl ItemsSource="{Binding TopMetrics}"
                              ItemTemplate="{StaticResource TopMetricTemplate}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Rows="1" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>

                <Border Grid.Column="1"
                        Margin="12,10"
                        Padding="12"
                        Background="#FFFFFF"
                        BorderBrush="#BFC7C2"
                        BorderThickness="1"
                        CornerRadius="6">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="42" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Ellipse Width="34"
                                 Height="34"
                                 Stroke="#7B8580"
                                 StrokeThickness="1"
                                 VerticalAlignment="Center">
                            <Ellipse.Style>
                                <Style TargetType="Ellipse">
                                    <Setter Property="Fill" Value="#929A96" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding FlameDetected}" Value="True">
                                            <Setter Property="Fill" Value="#E41F2C" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Ellipse.Style>
                        </Ellipse>
                        <StackPanel Grid.Column="1"
                                    VerticalAlignment="Center">
                            <TextBlock Text="M3火焰监测"
                                       FontSize="18"
                                       FontWeight="SemiBold"
                                       Foreground="#162321" />
                            <TextBlock Text="{Binding FlameStatus}"
                                       FontSize="16">
                                <TextBlock.Style>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="Foreground" Value="#40504B" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding FlameDetected}" Value="True">
                                                <Setter Property="Foreground" Value="#E41F2C" />
                                                <Setter Property="FontWeight" Value="SemiBold" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                        </StackPanel>
                    </Grid>
                </Border>
            </Grid>
        </Border>

        <Grid Grid.Row="1" Margin="12">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="360" />
                <ColumnDefinition Width="12" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Border Grid.Column="0"
                    Style="{StaticResource PanelBorderStyle}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="280" />
                    </Grid.RowDefinitions>

                    <ScrollViewer Grid.Row="0"
                                  Padding="12,12,12,8"
                                  VerticalScrollBarVisibility="Auto">
                        <StackPanel>
                            <ItemsControl ItemsSource="{Binding GasMetrics}"
                                          ItemTemplate="{StaticResource SideMetricTemplate}" />

                            <Border Margin="0,16,0,14"
                                    BorderBrush="#D4DBD7"
                                    BorderThickness="0,1,0,0" />

                            <ItemsControl ItemsSource="{Binding HeatMetrics}"
                                          ItemTemplate="{StaticResource SideMetricTemplate}" />

                            <Border Margin="0,16,0,14"
                                    BorderBrush="#D4DBD7"
                                    BorderThickness="0,1,0,0" />

                            <ItemsControl ItemsSource="{Binding TimerMetrics}"
                                          ItemTemplate="{StaticResource SideMetricTemplate}" />

                            <TextBlock Text="{Binding LastAction, StringFormat=最近操作：{0}}"
                                       Margin="0,16,0,0"
                                       FontSize="15"
                                       Foreground="#53615C" />
                        </StackPanel>
                    </ScrollViewer>

                    <Border Grid.Row="1"
                            Padding="10"
                            Background="#F8FAF9"
                            BorderBrush="#D3DAD6"
                            BorderThickness="0,1,0,0"
                            CornerRadius="0,0,6,6">
                        <ItemsControl ItemsSource="{Binding DeviceActions}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid Columns="2" Rows="4" />
                                </ItemsPanelTemplate>
                             </ItemsControl.ItemsPanel>
                             <ItemsControl.ItemTemplate>
                                 <DataTemplate>
                                    <Button Content="{Binding DisplayText}"
                                            Command="{Binding Command}"
                                            CommandParameter="{Binding Label}"
                                            Margin="5,3"
                                            MinHeight="40"
                                            Style="{StaticResource StatusDeviceActionButtonStyle}" />
                                 </DataTemplate>
                             </ItemsControl.ItemTemplate>
                         </ItemsControl>
                    </Border>
                </Grid>
            </Border>

            <GridSplitter Grid.Column="1"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          Background="#DDE3DF"
                          ShowsPreview="True" />

            <Border Grid.Column="2"
                    Style="{StaticResource PanelBorderStyle}">
                <oxy:PlotView Model="{Binding HeatReleasePlot}"
                              Background="White"
                              Margin="8" />
            </Border>
        </Grid>
    </Grid>
</UserControl>
