<Page x:Class="头罩视野.Views.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" 
      mc:Ignorable="d" 
      d:DesignHeight="768" d:DesignWidth="1024"
      Background="#F0F2F5" 
      Loaded="Page_Loaded" 
      Title="RecordPage">

    <Page.Resources>
        <!-- 全局字体 -->
        <FontFamily x:Key="DefaultFont">Segoe UI, Microsoft YaHei</FontFamily>

        <!-- 标题样式 -->
        <Style x:Key="MainTitleStyle" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
            <Setter Property="FontSize" Value="26"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Foreground" Value="#2C3E50"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="Margin" Value="0,15,0,15"/>
        </Style>

        <!-- DataGrid 样式 -->
        <Style x:Key="DataGridStyle" TargetType="DataGrid">
            <Setter Property="Background" Value="#FFFFFF"/>
            <Setter Property="BorderBrush" Value="#E5E8E8"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="GridLinesVisibility" Value="Horizontal"/>
            <Setter Property="HorizontalGridLinesBrush" Value="#ECF0F1"/>
            <Setter Property="VerticalGridLinesBrush" Value="#ECF0F1"/>
            <Setter Property="HeadersVisibility" Value="Column"/>
            <Setter Property="CanUserAddRows" Value="False"/>
            <Setter Property="CanUserDeleteRows" Value="False"/>
            <Setter Property="AutoGenerateColumns" Value="False"/>
            <Setter Property="IsReadOnly" Value="True"/>
            <Setter Property="SelectionMode" Value="Single"/>
            <Setter Property="SelectionUnit" Value="FullRow"/>
            <Setter Property="RowHeight" Value="36"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="Foreground" Value="#2C3E50"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        </Style>

        <!-- DataGrid 列头样式 -->
        <Style x:Key="DataGridColumnHeaderStyle" TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="#E5E5E5"/>
            <Setter Property="Foreground" Value="#2C3E50"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="Height" Value="40"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="8,4"/>
            <Setter Property="BorderBrush" Value="#E5E8E8"/>
            <Setter Property="BorderThickness" Value="0,0,1,1"/>
        </Style>

        <!-- DataGrid 行样式 -->
        <Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
            <Setter Property="Background" Value="White"/>
            <Style.Triggers>
                <Trigger Property="AlternationIndex" Value="0">
                    <Setter Property="Background" Value="#FFFFFF"/>
                </Trigger>
                <Trigger Property="AlternationIndex" Value="1">
                    <Setter Property="Background" Value="#F8F9F9"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#EBF5FB"/>
                </Trigger>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="#D6EAF8"/>
                    <Setter Property="BorderBrush" Value="#3498DB"/>
                    <Setter Property="BorderThickness" Value="1"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!-- DataGrid 单元格样式 -->
        <Style x:Key="DataGridCellStyle" TargetType="DataGridCell">
            <Setter Property="BorderBrush" Value="#ECF0F1"/>
            <Setter Property="BorderThickness" Value="0,0,1,1"/>
            <Setter Property="Padding" Value="8,4"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="TextBlock.TextAlignment" Value="Center"/>
        </Style>

        <!-- 底部导航按钮样式（与测试页面一致） -->
        <Style x:Key="TabButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#2C3E50"/>
            <Setter Property="FontFamily" Value="{StaticResource DefaultFont}"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="Foreground" Value="#ECF0F1"/>
            <Setter Property="Height" Value="52"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="BorderBrush" Value="#34495E"/>
            <Setter Property="BorderThickness" Value="0,1,0,0"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#34495E"/>
                    <Setter Property="Foreground" Value="#FFFFFF"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!-- 卡片样式（带阴影） -->
        <Style x:Key="CardStyle" TargetType="Border">
            <Setter Property="Background" Value="#FFFFFF"/>
            <Setter Property="CornerRadius" Value="8"/>
            <Setter Property="Effect">
                <Setter.Value>
                    <DropShadowEffect BlurRadius="12" ShadowDepth="2" Opacity="0.1" Color="#000000"/>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- 按钮样式 -->
        <Style x:Key="ActionButtonStyle" TargetType="Button">
            <Setter Property="Height" Value="40"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="FontSize" Value="15"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Opacity" Value="0.85"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Page.Resources>

    <Grid Margin="20,0,20,10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <!-- 0: 标题栏 -->
            <RowDefinition Height="*"/>
            <!-- 1: 表格区（撑满剩余空间） -->
            <RowDefinition Height="Auto"/>
            <!-- 2: 操作按钮区 -->
            <RowDefinition Height="Auto"/>
            <!-- 3: 底部导航栏（固定在窗口底部） -->
        </Grid.RowDefinitions>

        <!-- 顶部标题栏 -->
        <Grid Grid.Row="0" Margin="0,0,0,15">
            <TextBlock Style="{StaticResource MainTitleStyle}" Text="历史测试记录" HorizontalAlignment="Center"/>
        </Grid>

        <!-- 表格区（卡片样式，占据剩余高度） -->
        <Border Grid.Row="1" Style="{StaticResource CardStyle}" Padding="5" Margin="0,0,0,15">
            <DataGrid x:Name="RecordDataGrid"
                      Style="{StaticResource DataGridStyle}"
                      ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
                      RowStyle="{StaticResource DataGridRowStyle}"
                      CellStyle="{StaticResource DataGridCellStyle}"
                      AlternationCount="2"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column"
                      GridLinesVisibility="All"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                      ScrollViewer.HorizontalScrollBarVisibility="Auto"
                      VerticalAlignment="Stretch">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="编号" Binding="{Binding Id}" Width="60" />
                    <DataGridTextColumn Header="时间" Binding="{Binding Time}" Width="80" />
                    <DataGridTextColumn Header="日期" Binding="{Binding Date}" Width="80" />
                    <DataGridTextColumn Header="左目视野面积" Binding="{Binding LeftEyeArea,StringFormat=F2}" Width="105" />
                    <DataGridTextColumn Header="右目视野面积" Binding="{Binding RightEyeArea,StringFormat=F2}" Width="105" />
                    <DataGridTextColumn Header="双目视野面积" Binding="{Binding BinocularArea,StringFormat=F2}" Width="105" />
                    <DataGridTextColumn Header="下方视野" Binding="{Binding LowerVision,StringFormat=F2}" Width="90" />
                    <DataGridTextColumn Header="总视野面积" Binding="{Binding totalVisionArea,StringFormat=F2}" Width="105" />
                    <DataGridTextColumn Header="双目保存率" Binding="{Binding VisionRetentionRate,StringFormat=F2}" Width="100" />
                    <DataGridTextColumn Header="总保存率" Binding="{Binding GetVisionRetentionRate,StringFormat=F2}" Width="100" />
                </DataGrid.Columns>
            </DataGrid>
        </Border>

        <!-- 操作按钮区 -->
        <Grid Grid.Row="2" Margin="0,0,0,15">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                <Button Content="保存" Style="{StaticResource ActionButtonStyle}" Background="#27AE60" Margin="5" Click="btnSave_Click"/>
                <Button Content="清除" Style="{StaticResource ActionButtonStyle}" Background="#E74C3C" Margin="5" 
                        PreviewMouseLeftButtonDown="btnClear_MouseDown" PreviewMouseLeftButtonUp="btnClear_MouseUp"/>
                <TextBlock Text="长按清除" VerticalAlignment="Center" Margin="15,0,0,0" FontSize="13" Foreground="#E74C3C" FontStyle="Italic"/>
            </StackPanel>
        </Grid>

        <!-- 底部导航栏（固定在窗口底部） -->
        <Grid Grid.Row="3" VerticalAlignment="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Button Style="{StaticResource TabButtonStyle}" Grid.Column="0" Content="主页" Click="GoHome"/>
            <Button Style="{StaticResource TabButtonStyle}" Grid.Column="1" Content="测试界面" Click="GoTest"/>
            <Button Style="{StaticResource TabButtonStyle}" Grid.Column="2" Content="记录画面" Click="GoView"/>
        </Grid>
    </Grid>
</Page>