<!--
NavisworksTransport 时间标签设置对话框 - 采用与主界面一致的Navisworks 2026风格

功能说明：
1. 路径时间标签设置，支持分段时间计算和速度调整
2. 支持默认速度设置、元素限速优先配置
3. 提供估算、应用写回等操作功能
4. 可视化时间分段展示和累计时间计算

设计原则：参考PathAnalysisDialog的现代化布局和样式，使用统一的蓝色主题
-->
<Window x:Class="NavisworksTransport.UI.WPF.Views.TimeTagDialog"
        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="时间标签设置 - Route_A1" 
        Height="700" 
        Width="950"
        ResizeMode="CanResize" 
        WindowStartupLocation="CenterOwner"
        MinHeight="500"
        MinWidth="700">
        
    <Window.Resources>
        <!-- 引用共享的Navisworks 2026样式资源 -->
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/NavisworksTransportPlugin;component/src/UI/WPF/Resources/NavisworksStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            
            <!-- 转换器定义 -->
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            
            <!-- 时间标签专用样式 -->
            <Style x:Key="SettingsCardStyle" TargetType="Border">
                <Setter Property="Background" Value="White"/>
                <Setter Property="BorderBrush" Value="#FFD4E7FF"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="4"/>
                <Setter Property="Padding" Value="15"/>
                <Setter Property="Margin" Value="5"/>
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect Color="Gray" Direction="315" ShadowDepth="2" Opacity="0.3" BlurRadius="4"/>
                    </Setter.Value>
                </Setter>
            </Style>
            
            <Style x:Key="SectionHeaderStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksPrimaryBrush}"/>
                <Setter Property="Margin" Value="0,0,0,10"/>
            </Style>
            
            <Style x:Key="ParameterGroupStyle" TargetType="StackPanel">
                <Setter Property="Orientation" Value="Horizontal"/>
                <Setter Property="Margin" Value="0,5"/>
            </Style>
            
            <Style x:Key="ParameterLabelStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="11"/>
                <Setter Property="Foreground" Value="#FF666666"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Width" Value="100"/>
            </Style>
            
            <Style x:Key="ParameterInputStyle" TargetType="TextBox">
                <Setter Property="Width" Value="80"/>
                <Setter Property="Height" Value="25"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="BorderBrush" Value="#FFCCCCCC"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Padding" Value="5,0"/>
            </Style>
            
            <Style x:Key="ResultValueStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="14"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksPrimaryBrush}"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            
        </ResourceDictionary>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <!-- 主内容区域 -->
        <Grid Grid.Row="0" Margin="15">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="300"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <!-- 左侧：设置面板 -->
            <StackPanel Grid.Column="0">
                <!-- 基本设置卡片 -->
                <Border Style="{StaticResource SettingsCardStyle}">
                    <StackPanel>
                        <TextBlock Text="⚙️ 基本设置" Style="{StaticResource SectionHeaderStyle}"/>
                        
                        <StackPanel Style="{StaticResource ParameterGroupStyle}">
                            <TextBlock Text="默认速度:" Style="{StaticResource ParameterLabelStyle}"/>
                            <TextBox Text="{Binding DefaultSpeed, StringFormat=0.0###}" Style="{StaticResource ParameterInputStyle}"/>
                            <TextBlock Text="m/s" FontSize="10" Foreground="#FF666666" VerticalAlignment="Center" Margin="5,0,0,0"/>
                        </StackPanel>
                        
                        <CheckBox Content="使用元素限速优先" IsChecked="{Binding UseElementSpeedLimit}" Margin="0,10,0,5" FontSize="11"/>
                        
                        <StackPanel Style="{StaticResource ParameterGroupStyle}" Margin="0,15,0,5">
                            <TextBlock Text="总时长:" Style="{StaticResource ParameterLabelStyle}"/>
                            <TextBlock Text="{Binding TotalDurationText}" Style="{StaticResource ResultValueStyle}"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
                
                <!-- 操作按钮卡片 -->
                <Border Style="{StaticResource SettingsCardStyle}">
                    <StackPanel>
                        <TextBlock Text="🔧 操作" Style="{StaticResource SectionHeaderStyle}"/>
                        
                        <Button Content="重新估算" 
                                Style="{StaticResource ActionButtonStyle}" 
                                Height="32" 
                                Margin="0,5"/>
                        
                        <Button Content="应用写回" 
                                Style="{StaticResource ActionButtonStyle}" 
                                Height="32" 
                                Background="#FF4CAF50"
                                BorderBrush="#FF4CAF50"
                                Margin="0,5"/>
                        
                        <Button Content="导出时标" 
                                Style="{StaticResource SecondaryButtonStyle}" 
                                Height="32" 
                                Margin="0,5"/>
                    </StackPanel>
                </Border>
                
                <!-- 说明卡片 -->
                <Border Style="{StaticResource SettingsCardStyle}">
                    <StackPanel>
                        <TextBlock Text="💡 说明" Style="{StaticResource SectionHeaderStyle}"/>
                        
                        <TextBlock Text="• 单位：米/秒 与 秒" FontSize="10" Margin="0,2" Foreground="#FF666666"/>
                        <TextBlock Text="• 点击「应用写回」将累计时标写入路径点" FontSize="10" Margin="0,2" Foreground="#FF666666" TextWrapping="Wrap"/>
                        <TextBlock Text="• 元素限速优先时使用模型中设置的最高速度" FontSize="10" Margin="0,2" Foreground="#FF666666" TextWrapping="Wrap"/>
                        <TextBlock Text="• 等待事件段时长可手动调整" FontSize="10" Margin="0,2" Foreground="#FF666666"/>
                    </StackPanel>
                </Border>
            </StackPanel>
            
            <!-- 右侧：时间分段表格 -->
            <Border Grid.Column="1" Style="{StaticResource SettingsCardStyle}">
                <StackPanel>
                    <TextBlock Text="📊 路径时间分段" Style="{StaticResource SectionHeaderStyle}"/>
                    
                    <!-- 现代化DataGrid -->
                    <DataGrid AutoGenerateColumns="False" 
                              HeadersVisibility="Column" 
                              CanUserReorderColumns="False" 
                              CanUserResizeColumns="True" 
                              CanUserSortColumns="False"
                              BorderBrush="#FFD4E7FF" 
                              BorderThickness="1" 
                              GridLinesVisibility="Horizontal"
                              HorizontalGridLinesBrush="#FFEEEEEE" 
                              RowBackground="White" 
                              AlternatingRowBackground="#FFF8FBFF"
                              Height="240"
                              ItemsSource="{Binding TimeSegments}">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="#" Width="40" IsReadOnly="True" Binding="{Binding Index}"/>
                            <DataGridTextColumn Header="长度(m)" Width="80" IsReadOnly="True" Binding="{Binding Length, StringFormat=F2}"/>
                            <DataGridTextColumn Header="速度(m/s)" Width="90" Binding="{Binding Speed, StringFormat=F2}"/>
                            <DataGridTextColumn Header="段耗时(s)" Width="90" Binding="{Binding Duration, StringFormat=F1}"/>
                            <DataGridTextColumn Header="累计(s)" Width="80" IsReadOnly="True" Binding="{Binding CumulativeTime, StringFormat=F1}"/>
                            <DataGridTextColumn Header="备注" Width="*" IsReadOnly="True" Binding="{Binding Remarks}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                    
                    <!-- 时间轴可视化 -->
                    <TextBlock Text="📈 时间轴预览" Style="{StaticResource SectionHeaderStyle}" Margin="0,20,0,10"/>
                    
                    <StackPanel>
                        <!-- 动态时间轴段（绑定到TimelineItems集合） -->
                        <ItemsControl ItemsSource="{Binding TimelineItems}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="#FFF0F8FF" BorderBrush="#FFB0D4F1" BorderThickness="1" CornerRadius="3" Padding="8" Margin="0,2">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="120"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="80"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0" Text="{Binding Name}" FontWeight="SemiBold" FontSize="10" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"/>
                                            <Rectangle Grid.Column="1" Height="8" Fill="{Binding Color}" Margin="5,0" VerticalAlignment="Center"/>
                                            <TextBlock Grid.Column="2" Text="{Binding Duration, StringFormat='{}{0:F1}s'}" FontSize="10" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                                        </Grid>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <!-- 总计（绑定到ViewModel） -->
                        <Border Background="#FFE8F5E8" BorderBrush="#FF4CAF50" BorderThickness="2" CornerRadius="4" Padding="10" Margin="0,10,0,0">
                            <Grid>
                                <TextBlock Text="总计用时" FontWeight="Bold" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                                <TextBlock Text="{Binding TotalDurationText}" FontWeight="Bold" FontSize="14" Foreground="#FF4CAF50" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                            </Grid>
                        </Border>
                    </StackPanel>
                </StackPanel>
            </Border>
        </Grid>
        
        <!-- 底部按钮区域 -->
        <Border Grid.Row="1" 
                BorderBrush="#FFD4E7FF" 
                BorderThickness="1" 
                CornerRadius="0" 
                Background="#FFF8FBFF"
                Margin="15,0,15,15" 
                Padding="15,10">
            <StackPanel Orientation="Horizontal" 
                        HorizontalAlignment="Right">
                
                <Button Content="重置参数" 
                        Style="{StaticResource SecondaryButtonStyle}" 
                        Margin="0,0,10,0"/>
                
                <Button Content="预览动画" 
                        Style="{StaticResource ActionButtonStyle}" 
                        Margin="0,0,10,0"/>
                
                <Button Content="关闭" 
                        Click="CloseButton_Click" 
                        Style="{StaticResource SecondaryButtonStyle}"/>
                        
            </StackPanel>
        </Border>
    </Grid>
</Window>