<Page x:Class="SWRIS.Pages.RecordPage"
      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"
      FontFamily="{StaticResource PuHuiTiRegular}"
      xmlns:pu="https://opensource.panuon.com/wpf-ui"
      xmlns:cvt="clr-namespace:SWRIS.Converters"
      mc:Ignorable="d"  Foreground="#FFFFFF"
      Height="1020" Width="1920" FontSize="20" KeepAlive="True"
      Title="RecordPage">
    <Page.Resources>
        <cvt:RiskLevelToColorConverter x:Key="RiskLevelToColorConverter"/>
        <cvt:RiskLevelToTextConverter x:Key="RiskLevelToTextConverter"/>
    </Page.Resources>
    <Grid  Margin="25,20,25,7">
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Vertical" Grid.Row="0" VerticalAlignment="Center">
            <StackPanel Orientation="Horizontal">
                <Label Content="钢丝绳" VerticalAlignment="Center" Foreground="#7886B2" Margin="5,0"/>
                <ComboBox ItemsSource="{Binding ViewModel.Ropes}" DisplayMemberPath="Value" SelectedValuePath="Key"
                      SelectedValue="{Binding ViewModel.SearchInput.RopeNumber,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Margin="5,0"/>
                <Label Content="时间范围" VerticalAlignment="Center" Foreground="#7886B2"/>
                <pu:DateTimePicker SelectedDateTime="{Binding ViewModel.SearchInput.StartTime,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
                               Margin="10,0,5,0" />
                <Rectangle Width="12" Height="3" Fill="#3B3B7B"/>
                <pu:DateTimePicker Margin="5,0" SelectedDateTime="{Binding ViewModel.SearchInput.EndTime,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"/>
                <Label Content="风险等级" VerticalAlignment="Center" Foreground="#7886B2" Margin="50,0,5,0"/>
                <ComboBox ItemsSource="{Binding ViewModel.RiskLevels}" DisplayMemberPath="Value" SelectedValuePath="Key"
                      SelectedValue="{Binding ViewModel.SearchInput.RiskLevel,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Margin="5,0"/>
                <Button Content="查询"  pu:ButtonHelper.CornerRadius="15" Margin="25,0" Click="Search_Click">
                    <Button.Background>
                        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                            <GradientStop Color="#4E38F0 " Offset="0.6"/>
                            <GradientStop Color="#736AFA " Offset="1.2"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
            </StackPanel>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5,5">
                <Button Content="生成报告" Margin="5,0" Height="35" FontSize="18" pu:ButtonHelper.CornerRadius="12" Click="Batch_Report"/>
                <Button Content="批量删除" Margin="5,0" Height="35" FontSize="18" pu:ButtonHelper.CornerRadius="12" Click="Batch_Delete"/>
                <Button Content="批量导出" Margin="5,0" Height="35" FontSize="18" pu:ButtonHelper.CornerRadius="12" Click="Batch_Export"/>
            </StackPanel>
        </StackPanel>
        <StackPanel Grid.Row="1" Orientation="Vertical">
            <DataGrid Name="RecordDataGrid" Height="810" ItemsSource="{Binding ViewModel.Records,IsAsync=True}"
                      AlternationCount="2" MouseDoubleClick="RecordDataGrid_MouseDoubleClick" 
                      pu:DataGridHelper.RowHeaderHoverBackground="Transparent">
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <Style.Triggers>
                            <Trigger Property="AlternationIndex" Value="0">
                                <Setter Property="Background" Value="#19183A"/>
                            </Trigger>
                            <Trigger Property="AlternationIndex" Value="1">
                                <Setter Property="Background" Value="#202045"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#29297b"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="#272771"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <!-- 添加复选框列 -->
                    <DataGridTemplateColumn Width="50" IsReadOnly="True">
                        <DataGridTemplateColumn.HeaderTemplate>
                            <DataTemplate>
                                <CheckBox x:Name="SelectAllCheckBox" HorizontalAlignment="Center" VerticalAlignment="Center" 
                                          IsChecked="{Binding Path=DataContext.ViewModel.IsAllSelected,RelativeSource={RelativeSource AncestorType={x:Type DataGrid}},Mode=TwoWay}"
                                          ToolTip="全选"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.HeaderTemplate>
                        <DataGridTemplateColumn.HeaderStyle>
                            <Style TargetType="DataGridColumnHeader">
                                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                <Setter Property="Background" Value="Transparent"/>
                                <Setter Property="Height" Value="26"/>
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Cursor" Value="Hand"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGridTemplateColumn.HeaderStyle>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding IsSelected,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Width="250" IsReadOnly="True">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="钢丝绳名称" />
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular" Text="{Binding RopeName}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Width="220" IsReadOnly="True">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="开始时间"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular"
                                            Text="{Binding StartTime,StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Width="220" IsReadOnly="True">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="结束时间"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular" 
                                            Text="{Binding EndTime,StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn  Width="140" SortMemberPath="RiskLevel">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="风险等级"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" 
                                            Text="{Binding RiskLevel,Converter={StaticResource RiskLevelToTextConverter}}"
                                            Foreground="{Binding RiskLevel,Converter={StaticResource RiskLevelToColorConverter}}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn   Width="150" SortMemberPath="StartPoint">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="检测起点"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular">
                                    <Run Text="{Binding StartPoint,StringFormat=#0.00}"/>
                                    <Run>米</Run>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn  Width="150" SortMemberPath="DetectionLength">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="检测长度"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular">
                                    <Run Text="{Binding DetectionLength,StringFormat=#0.00}" />
                                    <Run>米</Run>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn  Width="150" SortMemberPath="LightAlarmCount">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="检测速度" />
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular">
                                    <Run Text="{Binding DetectedSpeed,StringFormat=#0.00}" />
                                    <Run>m/s</Run>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn  Width="150" SortMemberPath="HeavyAlarmCount">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="损伤数量"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  HorizontalAlignment="Center" Margin="0,0,10,0" FontWeight="Regular">
                                    <Run Text="{Binding DamageCount}" />
                                    <Run>处</Run>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn  Width="350">
                        <DataGridTemplateColumn.Header>
                            <TextBlock Text="操作"/>
                        </DataGridTemplateColumn.Header>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Button Content="生成报告" Background="Transparent" Tag="{Binding}" Foreground="#615CDD" Width="130" 
                                            Click="Report_Click" FontWeight="Medium"  FontFamily="{StaticResource PuHuiTiRegular}"  
                                            VerticalAlignment="Center" pu:ButtonHelper.Icon="&#xe9c4;" 
                                            pu:IconHelper.FontSize="17" pu:IconHelper.FontFamily="{StaticResource PanuonIconFont}"/>
                                    <Button Content="删除" Background="Transparent" Tag="{Binding Id}" Foreground="#615CDD"  Width="80"  
                                            Click="Delete_Click" Margin="10,0,0,0" FontWeight="Medium"  FontFamily="{StaticResource PuHuiTiRegular}" 
                                            VerticalAlignment="Center" pu:ButtonHelper.Icon="&#xe934;" pu:IconHelper.FontSize="17" 
                                            pu:IconHelper.FontFamily="{StaticResource PanuonIconFont}"/>
                                    <Button Content="导出" Background="Transparent" Tag="{Binding}" Foreground="#615CDD"  Width="80"
                                            Click="Export_Click" Margin="10,0,0,0" FontWeight="Medium"  FontFamily="{StaticResource PuHuiTiRegular}"
                                            VerticalAlignment="Center" pu:ButtonHelper.Icon="&#xe9E2;" pu:IconHelper.FontSize="17"
                                            pu:IconHelper.FontFamily="{StaticResource PanuonIconFont}"/>
                                </StackPanel>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
        </StackPanel>
    </Grid>
</Page>
