<UserControl x:Class="ExportModule.Views.ExportView"
             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:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:prism="http://prismlibrary.com/"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:converters="clr-namespace:UIShare.Converters;assembly=UIShare"
             prism:ViewModelLocator.AutoWireViewModel="True"
             mc:Ignorable="d"
             d:DesignHeight="700"
             d:DesignWidth="1200">
    <UserControl.Resources>
        <converters:LessThanConverter x:Key="LessThanConverter"/>
    </UserControl.Resources>

    <Border Background="#F5F7FA">
        <Grid x:Name="RootGrid" Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <!-- ========== 标题 ========== -->
            <TextBlock Grid.Row="0"
                       Text="测试报告导出"
                       FontSize="20" FontWeight="Bold"
                       Margin="4,4,0,12"/>

            <!-- ========== 主内容卡片 ========== -->
            <Border Grid.Row="1"
                    Background="White"
                    BorderBrush="#DDD" BorderThickness="1"
                    CornerRadius="4">
                <Grid>
                    <Grid.RowDefinitions>
                        <!-- 工具栏 -->
                        <RowDefinition Height="Auto"/>
                        <!-- 数据表格 -->
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <!-- ====== 工具栏（筛选条件 + 操作按钮） ====== -->
                    <Border Grid.Row="0"
                            Background="#ECEFF4"
                            Padding="12,8"
                            BorderBrush="#DDD" BorderThickness="0,0,0,1">

                        <!-- 第一行：筛选条件 -->
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="160"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="160"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="120"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <!-- 开始日期 -->
                            <TextBlock Grid.Column="0"
                                       Text="开始日期："
                                       VerticalAlignment="Center"
                                       FontWeight="SemiBold"
                                       Margin="0,0,4,0"/>
                            <DatePicker Grid.Column="1"
                                        materialDesign:HintAssist.Hint=""
                                        SelectedDate="{Binding StartTime}"
                                        VerticalAlignment="Center"
                                        Margin="0,0,16,0"/>

                            <!-- 结束日期 -->
                            <TextBlock Grid.Column="2"
                                       Text="结束日期："
                                       VerticalAlignment="Center"
                                       FontWeight="SemiBold"
                                       Margin="0,0,4,0"/>
                            <DatePicker Grid.Column="3"
                                        materialDesign:HintAssist.Hint=""
                                        SelectedDate="{Binding EndTime}"
                                        VerticalAlignment="Center"
                                        Margin="0,0,16,0"/>

                            <!-- 台架选择 -->
                            <TextBlock Grid.Column="4"
                                       Text="台架："
                                       VerticalAlignment="Center"
                                       FontWeight="SemiBold"
                                       Margin="0,0,4,0"/>
                            <ComboBox Grid.Column="5"
                                      materialDesign:HintAssist.Hint=""
                                      ItemsSource="{Binding ScopeOptions}"
                                      SelectedItem="{Binding SelectedScope}"
                                      VerticalAlignment="Center"
                                      Margin="0,0,16,0"/>

                            <!-- 操作按钮 -->
                            <Button Grid.Column="6"
                                    Content="查询"
                                    Command="{Binding QueryCommand}"
                                    Style="{StaticResource MaterialDesignFlatButton}"
                                    Padding="16,6"
                                    Margin="4,0"
                                    VerticalAlignment="Center"/>
                            <Button Grid.Column="7"
                                    Content="导出 Excel"
                                    Command="{Binding ExportCommand}"
                                    Style="{StaticResource MaterialDesignFlatButton}"
                                    Padding="16,6"
                                    Margin="4,0"
                                    VerticalAlignment="Center"/>
                            <Button Grid.Column="8"
                                    Content="加载全部"
                                    Command="{Binding LoadedCommand}"
                                    Style="{StaticResource MaterialDesignFlatButton}"
                                    Padding="16,6"
                                    Margin="4,0"
                                    VerticalAlignment="Center"/>
                        </Grid>
                    </Border>

                    <!-- ====== 数据展示区 ====== -->
                    <DataGrid Grid.Row="1"
                              ItemsSource="{Binding TestReportModelList}"
                              AutoGenerateColumns="False"
                              IsReadOnly="True"
                              RowHeaderWidth="0"
                              BorderThickness="0"
                              Background="White"
                              AlternatingRowBackground="#F5F7FA"
                              SelectionMode="Single"
                              SelectedItem="{Binding SelectedTestReport}"
                              Margin="8">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="TestRoundId"
                                                Width="280"
                                                Binding="{Binding TestRoundId}"/>
                            <DataGridTextColumn Header="台架名称"
                                                Width="120"
                                                Binding="{Binding Scope}"/>
                            <DataGridTextColumn Header="开始时间"
                                                Width="180"
                                                Binding="{Binding StartTime, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"/>
                            <DataGridTextColumn Header="结束时间"
                                                Width="180"
                                                Binding="{Binding EndTime, StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}"/>
                            <DataGridTextColumn Header="文件名"
                                                Width="*"
                                                Binding="{Binding FileName}"/>
                        </DataGrid.Columns>
                        <DataGrid.Resources>
                            <!-- 标题行样式：与项目风格一致 -->
                            <Style TargetType="DataGridColumnHeader">
                                <Setter Property="Background" Value="#ECEFF4"/>
                                <Setter Property="FontWeight" Value="Bold"/>
                                <Setter Property="BorderBrush" Value="#DDD"/>
                                <Setter Property="BorderThickness" Value="0,0,1,1"/>
                                <Setter Property="Padding" Value="8,6"/>
                            </Style>
                            <Style TargetType="DataGridCell">
                                <Setter Property="BorderThickness" Value="0"/>
                                <Setter Property="Padding" Value="8,4"/>
                                <Setter Property="VerticalAlignment" Value="Center"/>
                            </Style>
                        </DataGrid.Resources>
                    </DataGrid>
                </Grid>
            </Border>

            <!-- ========== 状态栏 ========== -->
            <Border Grid.Row="2"
                    Background="#ECEFF4"
                    Padding="10,6"
                    Margin="0,8,0,0"
                    CornerRadius="2">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0"
                               Text="{Binding StatusMessage}"
                               Foreground="#444"
                               FontSize="12"
                               VerticalAlignment="Center"/>
                    <TextBlock Grid.Column="1"
                               Foreground="#666"
                               FontSize="12"
                               VerticalAlignment="Center"
                               Margin="8,0,0,0">
                        <Run Text="记录数："/>
                        <Run Text="{Binding TotalCount}"/>
                    </TextBlock>
                </Grid>
            </Border>
        </Grid>
    </Border>
</UserControl>
