<!--
NavisworksTransport 配置编辑器对话框 - 采用与主界面一致的Navisworks 2026风格

功能说明：
1. 加载和显示 TOML 配置文件
2. 支持直接编辑配置文件内容
3. 提供保存、重载和恢复默认功能
4. 语法高亮和错误提示
5. 与主界面保持一致的视觉风格

设计原则：使用统一的蓝色主题和样式规范，针对配置文件编辑优化
-->
<Window x:Class="NavisworksTransport.UI.WPF.Views.ConfigEditorDialog"
        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"
        Title="系统参数配置"
        Height="700"
        Width="900"
        ResizeMode="CanResize"
        WindowStartupLocation="CenterScreen"
        MinHeight="500"
        MinWidth="700">

    <Window.Resources>
        <!-- 引用共享的Navisworks 2026样式资源 -->
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/TransportPlugin;component/src/UI/WPF/Resources/NavisworksStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <!-- 配置编辑器特有的样式 -->
            <Style x:Key="ConfigTextBoxStyle" TargetType="TextBox">
                <Setter Property="FontFamily" Value="Consolas, Courier New"/>
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="Background" Value="#FFFEFEFE"/>
                <Setter Property="Foreground" Value="#FF333333"/>
                <Setter Property="BorderBrush" Value="#FFD4E7FF"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="IsReadOnly" Value="False"/>
                <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
                <Setter Property="HorizontalScrollBarVisibility" Value="Auto"/>
                <Setter Property="TextWrapping" Value="NoWrap"/>
                <Setter Property="AcceptsReturn" Value="True"/>
                <Setter Property="AcceptsTab" Value="True"/>
                <Setter Property="Padding" Value="10"/>
            </Style>

            <Style x:Key="InfoPanelStyle" TargetType="Border">
                <Setter Property="Background" Value="#FFFFF8DC"/>
                <Setter Property="BorderBrush" Value="#FFFFC107"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="3"/>
                <Setter Property="Padding" Value="12,8"/>
                <Setter Property="Margin" Value="0,0,0,10"/>
            </Style>
        </ResourceDictionary>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- 工具栏区域 -->
        <Border Grid.Row="0"
                BorderBrush="#FFD4E7FF"
                BorderThickness="0,0,0,1"
                Background="#FFF8FBFF"
                Padding="15,10">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!-- 左侧工具按钮 -->
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <Button Content="重新加载"
                            Click="ReloadButton_Click"
                            Style="{StaticResource SecondaryButtonStyle}"
                            Margin="0,0,10,0"
                            ToolTip="放弃当前修改，重新加载配置文件"/>
                    <Button Content="恢复默认"
                            Click="ResetToDefaultButton_Click"
                            Style="{StaticResource SecondaryButtonStyle}"
                            Margin="0,0,10,0"
                            ToolTip="恢复为默认配置"/>

                    <!-- 分隔线 -->
                    <Border Width="1"
                            Background="#FFD4E7FF"
                            Margin="5,2"/>

                    <Button Content="打开配置文件夹"
                            Click="OpenConfigFolderButton_Click"
                            Style="{StaticResource SecondaryButtonStyle}"
                            Margin="10,0,0,0"
                            ToolTip="在资源管理器中打开配置文件所在目录"/>
                </StackPanel>

                <!-- 右侧文件信息 -->
                <StackPanel Grid.Column="1" Orientation="Horizontal">
                    <Label Content="配置文件:"
                           VerticalAlignment="Center"
                           Style="{StaticResource ParameterLabelStyle}"/>
                    <Label Name="ConfigFilePathLabel"
                           Content="config.toml"
                           VerticalAlignment="Center"
                           Style="{StaticResource ParameterLabelStyle}"
                           Foreground="#FF0066CC"
                           Margin="5,0,0,0"/>
                </StackPanel>
            </Grid>
        </Border>

        <!-- 帮助信息面板 -->
        <Border Grid.Row="1"
                Style="{StaticResource InfoPanelStyle}"
                Margin="15,15,15,0">
            <StackPanel>
                <TextBlock FontWeight="SemiBold"
                           Foreground="#FF856404"
                           Margin="0,0,0,5">
                    <Run Text="💡 "/>
                    <Run Text="配置说明"/>
                </TextBlock>
                <TextBlock TextWrapping="Wrap"
                           FontSize="10"
                           Foreground="#FF856404"
                           LineHeight="18">
                    • TOML 格式配置文件，支持注释（#开头）和分组（[section]）<LineBreak/>
                    • 所有长度单位为米(m)，时间单位为秒(s)<LineBreak/>
                    • 修改后点击"保存"按钮生效，建议先备份原配置<LineBreak/>
                    • 语法错误会在保存时提示，请确保格式正确
                </TextBlock>
            </StackPanel>
        </Border>

        <!-- 配置内容编辑区域 -->
        <Border Grid.Row="2"
                BorderBrush="#FFD4E7FF"
                BorderThickness="1"
                Background="White"
                Margin="15,10">
            <TextBox Name="ConfigContentTextBox"
                     Style="{StaticResource ConfigTextBoxStyle}"
                     TextChanged="ConfigContentTextBox_TextChanged"/>
        </Border>

        <!-- 底部状态栏和按钮 -->
        <Border Grid.Row="3"
                BorderBrush="#FFD4E7FF"
                BorderThickness="0,1,0,0"
                Background="#FFF8FBFF"
                Padding="15,10">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!-- 状态信息 -->
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <Label Name="StatusLabel"
                           Content="配置已加载"
                           Style="{StaticResource ParameterLabelStyle}"
                           Foreground="#FF2B8A2B"/>
                    <Label Name="FileSizeLabel"
                           Content="大小: 0 KB"
                           Style="{StaticResource ParameterLabelStyle}"
                           Margin="20,0,0,0"/>
                    <Label Name="LineCountLabel"
                           Content="行数: 0"
                           Style="{StaticResource ParameterLabelStyle}"
                           Margin="20,0,0,0"/>
                    <Label Name="ModifiedLabel"
                           Content=""
                           Style="{StaticResource ParameterLabelStyle}"
                           Foreground="#FFFF6B00"
                           Margin="20,0,0,0"/>
                </StackPanel>

                <!-- 右侧按钮 -->
                <StackPanel Grid.Column="1" Orientation="Horizontal">
                    <Button Content="应用"
                            Click="ApplyButton_Click"
                            Style="{StaticResource ActionButtonStyle}"
                            Margin="0,0,10,0"
                            ToolTip="应用配置并保持窗口打开"/>
                    <Button Content="确定"
                            Click="OkButton_Click"
                            Style="{StaticResource ActionButtonStyle}"
                            Margin="0,0,10,0"
                            ToolTip="保存配置并关闭窗口"/>
                    <Button Content="取消"
                            Click="CancelButton_Click"
                            Style="{StaticResource SecondaryButtonStyle}"
                            ToolTip="放弃修改并关闭窗口"/>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Window>

