<Page x:Class="SWRIS.Pages.DamagesPage"
      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:SWRIS.Pages"
      xmlns:pu="https://opensource.panuon.com/wpf-ui" 
      xmlns:cvt="clr-namespace:SWRIS.Converters" 
      xmlns:ctr="clr-namespace:SWRIS.Controls" 
      xmlns:vm="clr-namespace:SWRIS.Models.ViewModel" 
      xmlns:sys="clr-namespace:System;assembly=System.Runtime"
      mc:Ignorable="d" Foreground="#FFFFFF"  FontFamily="{StaticResource PuHuiTiRegular}"
      d:DesignHeight="1020" d:DesignWidth="1920" FontSize="24" Loaded="Page_Loaded"
      Title="DamagesPage">
    <Page.DataContext>
        <vm:DamagesViewModel/>
    </Page.DataContext>
    <Page.Resources>
        <cvt:DamageLevelToTextConverter x:Key="DamageLevelToTextConverter"/>
        <cvt:DamageLevelToColorConverter x:Key="DamageLevelToColorConverter"/>
        <cvt:ColorStringToCheckedBackgroundConverter x:Key="ColorToCheckedBackgroundConverter"/>
        <cvt:ColorStringToHoverBackgroundConverter x:Key="ColorToHoverBackgroundConverter"/>
        <cvt:ColorStringToHoverBorderBrushConverter x:Key="ColorToHoverBorderBrushConverter"/>
        <cvt:StringToColorConverter x:Key="StringToColorConverter"/>
    </Page.Resources>
    <Grid  Margin="25,30,25,7">
        <Grid.RowDefinitions>
            <RowDefinition Height="120"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="1376" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button HorizontalAlignment="Left" Grid.Column="0" Click="GoBack_Click">
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/Resources/back.png" Height="30" Margin="0,3"/>
                        <TextBlock Text="返回" FontSize="22" FontWeight="Medium"  FontFamily="{StaticResource PuHuiTiRegular}" Margin="0,5"/>
                    </StackPanel>
                </Button.Content>
            </Button>
            <Grid Grid.Column="1">
                <Grid.Background>
                    <ImageBrush ImageSource="/Resources/top_banner.png"/>
                </Grid.Background>
                <TextBlock Text="检测详情"  FontFamily="{StaticResource PuHuiTiRegular}" 
                           FontWeight="Bold" FontSize="36"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="500"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Vertical">
                <Border Background="#34346A" Height="70" VerticalAlignment="Top" CornerRadius="10" Margin="0,0,0,10">
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="30,0">
                        <TextBlock Text="位置" Foreground="#97A6D4" FontSize="24" Width="130"  FontFamily="{StaticResource PuHuiTiRegular}" FontWeight="Medium" />
                        <TextBlock Text="当量" Foreground="#97A6D4" FontSize="24" Width="130"  FontFamily="{StaticResource PuHuiTiRegular}" FontWeight="Medium"/>
                        <TextBlock Text="损伤级别" Foreground="#97A6D4" FontSize="24" Width="130"  FontFamily="{StaticResource PuHuiTiRegular}" FontWeight="Medium"/>
                        <TextBlock FontSize="24" Width="50"/>
                    </StackPanel>
                </Border>
                <ScrollViewer VerticalScrollBarVisibility="Hidden" MaxHeight="709">
                    <ItemsControl ItemsSource="{Binding Record.Damages}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Background="#202045" Height="70" VerticalAlignment="Top" CornerRadius="10" Margin="0,0,0,10" >
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="30,0">
                                        <TextBlock Text="{Binding DamagePoint,StringFormat='{}{0:N1}m'}" FontFamily="{StaticResource PuHuiTiRegular}"
                                               Foreground="#FFFFFF" FontSize="24" Width="130" FontWeight="Medium"/>
                                        <TextBlock Text="{Binding DamageValue,StringFormat='{}{0:N1}%'}" FontFamily="{StaticResource PuHuiTiRegular}"
                                               Foreground="#FFFFFF" FontSize="24" Width="130" FontWeight="Medium"/>
                                        <TextBlock Text="{Binding DamageLevel,Converter={StaticResource DamageLevelToTextConverter}}"
                                               Foreground="{Binding DamageLevel,Converter={StaticResource DamageLevelToColorConverter}}" 
                                               FontSize="24" Width="130" FontWeight="Medium" FontFamily="{StaticResource PuHuiTiRegular}"/>
                                        <Image Source="/Resources/delete.png" Height="24" Tag="{Binding Id}" Cursor="Hand" MouseDown="Delete_MouseDown"/>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </StackPanel>
            <Grid Grid.Column="1" Margin="20,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="55"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <DockPanel>
                    <StackPanel Orientation="Horizontal">
                        <Rectangle Height="16" Width="4" Fill="#4E38F0" Margin="2" RadiusX="1.5" RadiusY="1.5"/>
                        <Label Content="损伤曲线" FontSize="18" FontWeight="Bold"  FontFamily="{StaticResource PuHuiTiRegular}" Foreground="#CECECE" VerticalAlignment="Center" />
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                        <ToggleButton Width="120" Height="40" pu:ToggleButtonHelper.CornerRadius="10" Margin="5"
                                      BorderBrush="#3B3B7B" Foreground="#97A6D4" Tag="0" 
                                      IsChecked="{Binding IsSummaryActive,Mode=TwoWay}"
                                      pu:ToggleButtonHelper.HoverBackground="#1A9664F3"
                                      pu:ToggleButtonHelper.HoverBorderBrush="#4D9664F3"
                                      pu:ToggleButtonHelper.CheckedBackground="#4C9664F3"
                                      pu:ToggleButtonHelper.CheckedForeground="#9664F3"
                                      Checked="Sensor_Checked" Unchecked="Sensor_UnChecked">
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Fill="#9664F3" Width="16" Height="16" RadiusX="5" RadiusY="5"/>
                                <TextBlock Text="合值" Margin="5" FontSize="16"/>
                            </StackPanel>
                        </ToggleButton>
                        <Rectangle Width="1" Height="40" Fill="#3B3B7B" Margin="35,0"/>
                        <ItemsControl ItemsSource="{Binding Sensors}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <ToggleButton Width="120" Height="40" Margin="5" Tag="{Binding Id}"
                                                  BorderBrush="#3B3B7B" Foreground="#97A6D4"
                                                  pu:ToggleButtonHelper.CornerRadius="10"
                                                  IsChecked="{Binding IsActive, Mode=TwoWay}"
                                                  pu:ToggleButtonHelper.HoverBackground="{Binding Color, Converter={StaticResource ColorToHoverBackgroundConverter}}"
                                                  pu:ToggleButtonHelper.HoverBorderBrush="{Binding Color, Converter={StaticResource ColorToHoverBorderBrushConverter}}"
                                                  pu:ToggleButtonHelper.CheckedBackground="{Binding Color, Converter={StaticResource ColorToCheckedBackgroundConverter}}"
                                                  pu:ToggleButtonHelper.CheckedForeground="{Binding Color, Converter={StaticResource StringToColorConverter}}"
                                                  Checked="Sensor_Checked" Unchecked="Sensor_UnChecked">
                                        <StackPanel Orientation="Horizontal">
                                            <Rectangle Width="16" Height="16" RadiusX="5" RadiusY="5">
                                                <Rectangle.Fill>
                                                    <SolidColorBrush Color="{Binding Color, Converter={StaticResource StringToColorConverter}}"/>
                                                </Rectangle.Fill>
                                            </Rectangle>
                                            <TextBlock Text="{Binding Name}" Margin="5" FontSize="16"/>
                                        </StackPanel>
                                    </ToggleButton>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </StackPanel>
                </DockPanel>
                <Border Grid.Row="1" CornerRadius="5" Background="#202045">
                    <ctr:RecordLineChart x:Name="chartLine" />
                </Border>
            </Grid>
        </Grid>
    </Grid>
</Page>
