<UserControl
    x:Class="DMS.WPF.Views.VariableHistoryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="http://schemas.inkore.net/lib/ui/wpf/modern"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:enums="clr-namespace:DMS.Core.Enums;assembly=DMS.Core"
    xmlns:ex="clr-namespace:DMS.Extensions"
    xmlns:hc="https://handyorg.github.io/handycontrol"
    xmlns:helper="clr-namespace:DMS.WPF.Helper"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
    xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
    xmlns:vm="clr-namespace:DMS.WPF.ViewModels"
    xmlns:converters="clr-namespace:DMS.WPF.Converters"
    xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
    d:DataContext="{d:DesignInstance vm:VariableHistoryViewModel}"
    d:DesignHeight="600"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <UserControl.Resources>
        <!-- <ex:BindingProxy x:Key="proxy" Data="{Binding}" /> -->
        <!-- <valueConverts:EnumDescriptionConverter x:Key="EnumDescriptionConverter" /> -->
        <!-- <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> -->
        <!-- -->
        <!-- ~1~ 添加需要的转换器 @1@ -->
        <!-- <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" /> -->
        <!-- <converters:CountToVisibilityConverter x:Key="CountToVisibilityConverter" /> -->
        <!-- <converters:BoolToStringConverter x:Key="BoolToStringConverter" /> -->
        <!-- <converters:BoolToColorConverter x:Key="BoolToColorConverter" /> -->
        <!-- <converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" /> -->
    </UserControl.Resources>

    <DockPanel>
        <Border DockPanel.Dock="Top" Margin="20,10" Padding="15">
            
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                
                <!-- 返回变量表按钮 -->
                <Button Grid.Column="0" 
                        Command="{Binding NavigateToVariableTableCommand}"
                        Style="{StaticResource ButtonDefault}"
                        ToolTip="返回变量表"
                        Margin="0,0,10,0">
                    <Button.Content>
                        <StackPanel Orientation="Horizontal">
                            <ui:FontIcon
                                Icon="{x:Static ui:SegoeFluentIcons.ArrowLeft8}" />
                        </StackPanel>
                    </Button.Content>
                </Button>
                
                <!-- 操作菜单栏 -->
                <ui:CommandBar Grid.Column="1" 
                               DefaultLabelPosition="Right" 
                               IsOpen="False"
                               HorizontalAlignment="Right">
                    <!-- 重新加载 -->
                    <ui:AppBarButton Command="{Binding ReloadCommand}" Label="重新加载">
                        <ui:AppBarButton.Icon>
                            <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Refresh}" />
                        </ui:AppBarButton.Icon>
                    </ui:AppBarButton>
                    
                    <ui:AppBarButton x:Name="ExportButton" Label="导出">
                        <ui:AppBarButton.Icon>
                            <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Save}" />
                        </ui:AppBarButton.Icon>
                    </ui:AppBarButton>
                    
                    <ui:AppBarButton x:Name="ShareButton" Label="分享">
                        <ui:AppBarButton.Icon>
                            <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Share}" />
                        </ui:AppBarButton.Icon>
                    </ui:AppBarButton>
                    
                    <ui:CommandBar.SecondaryCommands>
                        <ui:AppBarButton
                            x:Name="SettingsButton"
                            Icon="Setting"
                            Label="设置" />
                    </ui:CommandBar.SecondaryCommands>
                </ui:CommandBar>
            </Grid>
        </Border>

        <!-- 时间范围选择器和详细信息区域 -->
        <Border DockPanel.Dock="Top" 
                Background="White" 
                BorderBrush="#E0E0E0" 
                BorderThickness="1" 
                CornerRadius="8"
                Margin="20,10"
                Padding="15">
            <Border.Effect>
                <DropShadowEffect ShadowDepth="2" 
                                  BlurRadius="5" 
                                  Opacity="0.1" 
                                  Color="#888888"/>
            </Border.Effect>
            
            <ikw:SimpleStackPanel Spacing="15">
                <!-- 时间范围选择 -->
                <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
                    <TextBlock Text="开始时间:" 
                               VerticalAlignment="Center"
                               Foreground="#666666"
                               FontSize="14"/>
                    <hc:DateTimePicker Width="200" SelectedDateTime="{Binding StartTime}" />
                    
                    <TextBlock Text="结束时间:" 
                               VerticalAlignment="Center"
                               Foreground="#666666"
                               FontSize="14"
                               Margin="10,0,0,0"/>
                    <hc:DateTimePicker Width="200" SelectedDateTime="{Binding EndTime}" />
                    
                    <Button Content="重新加载" 
                            Command="{Binding ReloadCommand}"
                            Style="{StaticResource ButtonPrimary}"
                            Margin="10,0,0,0"/>
                </ikw:SimpleStackPanel>
                
      
            </ikw:SimpleStackPanel>
        </Border>

        <!-- 变量历史记录列表和图表 -->
        <TabControl Margin="20">
            <TabItem Header="数据表格">
                <ui:TabItemHelper.Icon>
                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Settings}"/>
                </ui:TabItemHelper.Icon>
                <DataGrid
                    AutoGenerateColumns="False"
                    CanUserDeleteRows="False"
                    CanUserSortColumns="True"
                    IsReadOnly="True"
                    ItemsSource="{Binding VariableHistories}"
                    SelectionMode="Single"
                    Style="{StaticResource DataGridBaseStyle}">
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding Value}" Header="{Binding DataContext.CurrentVariable.Name, RelativeSource={RelativeSource AncestorType=UserControl}, FallbackValue='值'}" />
                        <DataGridTextColumn
                            Binding="{Binding Timestamp, StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}"
                            Header="时间戳"
                            IsReadOnly="True" />
                    </DataGrid.Columns>
                </DataGrid>
            </TabItem>
            <TabItem Header="数据图表">
                <ui:TabItemHelper.Icon>
                    <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Settings}"/>
                </ui:TabItemHelper.Icon>
                <lvc:CartesianChart ZoomMode="X" Series="{Binding LineSeriesCollection}" 
                     XAxes="{Binding LineAxisX}" 
                     YAxes="{Binding LineAxisY}"
                     Margin="10"/>
            </TabItem>
        </TabControl>
    </DockPanel>
</UserControl>