<!--
NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Navisworks 2026风格

功能说明：
1. 数据管理：备份、恢复、修复数据库
2. 日志管理：查看、清空、导出日志，设置日志级别
3. 插件设置：设置选项、重置设置、导入配置、启用选项
4. 系统信息：插件版本、Navisworks版本、内存使用、运行时间
5. 功能测试：测试新功能和实验性特性

设计原则：与Navisworks 2026风格一致，480像素宽度，现代化UI布局，采用Border分组
-->
<UserControl x:Class="NavisworksTransport.UI.WPF.Views.SystemManagementView"
             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="800" d:DesignWidth="480">
    
    <UserControl.Resources>
        <!-- 引用共享的Navisworks 2026样式资源 -->
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/TransportPlugin;component/src/UI/WPF/Resources/NavisworksStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            
            <!-- 系统管理页面特有的样式 -->
            <Style x:Key="StatusLabelStyle" TargetType="Label">
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="FontWeight" Value="Normal"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksPrimaryBrush}"/>
                <Setter Property="Padding" Value="0,2"/>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <ScrollViewer VerticalScrollBarVisibility="Auto" Padding="10">
        <StackPanel>
            <!-- 区域0: 数据管理 -->
            <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12"
                    Background="#FFF8FBFF">
                <StackPanel>
                    <Label Content="📦 数据管理" Style="{StaticResource SectionHeaderStyle}"/>
                    
                    <!-- 数据库状态信息 -->
                    <Grid Margin="0,5,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        
                        <Label Grid.Row="0" Grid.Column="0" Content="数据库版本:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="0" Grid.Column="1" Content="{Binding DatabaseVersion}" Style="{StaticResource InfoTextStyle}"/>
                        
                        <Label Grid.Row="1" Grid.Column="0" Content="路径数量:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="1" Grid.Column="1" Content="{Binding PathCount}" Style="{StaticResource InfoTextStyle}"/>
                        
                        <Label Grid.Row="2" Grid.Column="0" Content="检测记录:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="2" Grid.Column="1" Content="{Binding DetectionRecordCount}" Style="{StaticResource InfoTextStyle}"/>
                    </Grid>

                    <!-- 数据操作按钮 -->
                    <StackPanel Orientation="Horizontal" Margin="0,5,0,5">
                        <Button Content="💾 备份数据"
                                Command="{Binding BackupDataCommand}"
                                Style="{StaticResource ActionButtonStyle}"
                                ToolTip="导出所有路径、检测记录和截图到备份文件"/>
                        
                        <Button Content="📂 恢复数据"
                                Command="{Binding RestoreDataCommand}"
                                Style="{StaticResource SecondaryButtonStyle}"
                                ToolTip="从备份文件恢复数据"/>
                        
                        <Button Content="🔧 修复数据库"
                                Command="{Binding RepairDatabaseCommand}"
                                Style="{StaticResource SecondaryButtonStyle}"
                                ToolTip="检查并修复数据库完整性"/>
                        
                        <Button Content="🗑️ 清空数据"
                                Command="{Binding ClearAllDataCommand}"
                                Style="{StaticResource SecondaryButtonStyle}"
                                ToolTip="清空所有路径和检测记录（谨慎使用）"/>
                    </StackPanel>
                    
                    <!-- 自动备份设置 -->
                    <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                        <CheckBox Content="启用自动备份" 
                                  IsChecked="{Binding AutoBackupEnabled}"
                                  VerticalAlignment="Center"
                                  Margin="0,0,10,0"/>
                        <TextBlock Text="保留最近" VerticalAlignment="Center" FontSize="10"/>
                        <ComboBox ItemsSource="{Binding BackupKeepCountOptions}"
                                  SelectedItem="{Binding SelectedBackupKeepCount}"
                                  Width="50"
                                  Margin="5,0"/>
                        <TextBlock Text="个备份" VerticalAlignment="Center" FontSize="10"/>
                    </StackPanel>
                    
                    <!-- 上次备份信息 -->
                    <TextBlock Text="{Binding LastBackupInfo}"
                               FontSize="10"
                               Foreground="{StaticResource NavisworksDarkBrush}"
                               Margin="0,5,0,0"
                               TextWrapping="Wrap"/>
                </StackPanel>
            </Border>

            <!-- 区域1: 日志管理 -->
            <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
                <StackPanel>
                    <Label Content="日志管理" Style="{StaticResource SectionHeaderStyle}"/>

                    <!-- 日志操作按钮 -->
                    <StackPanel Orientation="Horizontal" Margin="0,10,0,10">
                        <Button Content="查看日志"
                                Command="{Binding ViewLogCommand}"
                                Style="{StaticResource ActionButtonStyle}"/>
                    </StackPanel>

                    <!-- 日志级别设置 -->
                    <Grid Margin="0,5,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <Label Grid.Column="0" Content="日志级别:" Style="{StaticResource ParameterLabelStyle}" Width="80"/>
                        <ComboBox Grid.Column="1"
                                  ItemsSource="{Binding LogLevels}"
                                  SelectedItem="{Binding SelectedLogLevel}"
                                  Width="100"
                                  Margin="5,0,0,0"
                                  ToolTip="选择要记录的最低日志级别"/>
                    </Grid>
                </StackPanel>
            </Border>
            
            <!-- 区域2: 插件设置 -->
            <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
                <StackPanel>
                    <Label Content="插件设置" Style="{StaticResource SectionHeaderStyle}"/>

                    <!-- 设置操作按钮 -->
                    <StackPanel Orientation="Horizontal" Margin="0,10,0,10">
                        <Button Content="参数设置"
                                Command="{Binding OpenSettingsCommand}"
                                Style="{StaticResource ActionButtonStyle}"/>
                    </StackPanel>
                </StackPanel>
            </Border>

            <!-- 区域2.5: 坐标系设置 -->
            <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
                <StackPanel>
                    <Label Content="坐标系设置" Style="{StaticResource SectionHeaderStyle}"/>

                    <!-- 坐标系选择 -->
                    <Grid Margin="0,5,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <Label Grid.Column="0" Content="坐标系类型:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <ComboBox Grid.Column="1"
                                  ItemsSource="{Binding CoordinateSystemOptions}"
                                  SelectedItem="{Binding SelectedCoordinateSystem}"
                                  Width="120"
                                  HorizontalAlignment="Left"
                                  Margin="5,0,0,0"
                                  ToolTip="AutoDetect: 自动检测, ZUp: Z轴向上, YUp: Y轴向上"/>
                    </Grid>

                    <!-- 当前坐标系信息 -->
                    <TextBlock Text="{Binding CurrentCoordinateSystemInfo}"
                               FontSize="10"
                               Foreground="{StaticResource NavisworksPrimaryBrush}"
                               Margin="0,5,0,5"
                               TextWrapping="Wrap"/>
                </StackPanel>
            </Border>
            
            <!-- 区域3: 系统信息 -->
            <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
                <StackPanel>
                    <Label Content="系统信息" Style="{StaticResource SectionHeaderStyle}"/>
                    
                    <!-- 系统信息表格 -->
                    <Grid Margin="0,10,0,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        
                        <Label Grid.Row="0" Grid.Column="0" Content="插件版本:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="0" Grid.Column="1" Content="{Binding PluginVersion}" Style="{StaticResource InfoTextStyle}"/>
                        
                        <Label Grid.Row="1" Grid.Column="0" Content="Navisworks版本:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="1" Grid.Column="1" Content="{Binding NavisworksVersion}" Style="{StaticResource InfoTextStyle}"/>
                        
                        
                        <Label Grid.Row="3" Grid.Column="0" Content="内存使用:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="3" Grid.Column="1" Content="{Binding MemoryUsage}" Style="{StaticResource InfoTextStyle}"/>
                        
                        <Label Grid.Row="4" Grid.Column="0" Content="运行时间:" Style="{StaticResource ParameterLabelStyle}" Width="100"/>
                        <Label Grid.Row="4" Grid.Column="1" Content="{Binding RunningTime}" Style="{StaticResource InfoTextStyle}"/>
                    </Grid>
                    
                    <!-- 系统操作按钮 -->
                    <StackPanel Orientation="Horizontal" Margin="0,5,0,5">
                        <Button Content="环境检查"
                                Style="{StaticResource SecondaryButtonStyle}"
                                Command="{Binding DiagnosticCommand}"
                                ToolTip="检查运行环境和线程状态"/>
                    </StackPanel>
                </StackPanel>
            </Border>

            <!-- 区域4: 功能测试 -->
            <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
                <StackPanel>
                    <Expander IsExpanded="False">
                        <Expander.Header>
                            <Label Content="实验特性" Style="{StaticResource SectionHeaderStyle}" Padding="0"/>
                        </Expander.Header>
                        <StackPanel Margin="0,8,0,0">

                            <Grid Margin="0,5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <Button Grid.Row="0" Grid.Column="0" Content="体素网格 SDF"
                                        Command="{Binding TestVoxelGridSDFCommand}"
                                        Style="{StaticResource ActionButtonStyle}"
                                        ToolTip="使用 MeshSignedDistanceGrid 进行精确体素化，计算距离场"
                                        Margin="0,0,2,2"/>

                                <Button Grid.Row="0" Grid.Column="1" Content="体素路径规划 3D A*"
                                        Command="{Binding TestVoxelPathFindingCommand}"
                                        Style="{StaticResource ActionButtonStyle}"
                                        ToolTip="使用3D A*算法在体素网格中规划路径，支持楼梯、坡道等垂直移动"
                                        Margin="2,0,2,2"/>

                                <Button Grid.Row="0" Grid.Column="2" Content="读取 Transform"
                                        Command="{Binding ReadTransformTestCommand}"
                                        Style="{StaticResource ActionButtonStyle}"
                                        ToolTip="读取选中对象的Transform信息（包括旋转角度）"
                                        Margin="2,0,0,2"/>

                                <Button Grid.Row="1" Grid.Column="0" Content="捕获真实物体位姿"
                                        Command="{Binding CaptureRealObjectTransformCommand}"
                                        Style="{StaticResource ActionButtonStyle}"
                                        ToolTip="读取选中真实物体的原始Transform，并在3D视图中可视化X/Y/Z三轴"
                                        Margin="0,2,2,0"/>


                                <Button Grid.Row="1" Grid.Column="1" Content="坐标系检测"
                                        Command="{Binding CoordinateSystemExplorerCommand}"
                                        Style="{StaticResource ActionButtonStyle}"
                                        ToolTip="检测当前文档的坐标系信息（用于适配Y-up坐标系模型）"
                                        Margin="2,2,0,0"/>
                            </Grid>

                        </StackPanel>
                    </Expander>
                </StackPanel>
            </Border>
        </StackPanel>
    </ScrollViewer>
</UserControl>
