<!--
NavisworksTransport 碰撞检测报告对话框 - 采用与主界面一致的Navisworks 2026风格

功能说明：
1. 显示详细的碰撞检测报告，包括统计信息和具体碰撞项目
2. 支持按类型分组显示碰撞（动画、独立检测、其他）
3. 提供导出、刷新、高亮等操作功能
4. 结构化展示，替代原来的简单TextBox显示

设计原则：参考HelpDialog的布局和样式，使用统一的蓝色主题
-->
<Window x:Class="NavisworksTransport.UI.WPF.Views.CollisionReportDialog"
        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"
        xmlns:local="clr-namespace:NavisworksTransport.UI.WPF.Converters"
        mc:Ignorable="d"
        Title="碰撞检测报告" 
        Height="700" 
        Width="900"
        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"/>
            <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
            <local:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
            <local:CountToVisibilityConverter x:Key="CountToVisibilityConverter"/>
            
            <!-- 碰撞报告专用样式 -->
            <Style x:Key="StatisticItemStyle" TargetType="Border">
                <Setter Property="Background" Value="#FFF8FBFF"/>
                <Setter Property="BorderBrush" Value="#FFD4E7FF"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="3"/>
                <Setter Property="Padding" Value="10,8"/>
                <Setter Property="Margin" Value="0,2"/>
            </Style>
            
            <Style x:Key="StatisticLabelStyle" TargetType="TextBlock">
                <Setter Property="FontWeight" Value="Normal"/>
                <Setter Property="FontSize" Value="11"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksSecondaryBrush}"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            
            <Style x:Key="StatisticValueStyle" TargetType="TextBlock">
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksPrimaryBrush}"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="HorizontalAlignment" Value="Right"/>
            </Style>
            
            <Style x:Key="CollisionItemStyle" TargetType="Border">
                <Setter Property="Background" Value="White"/>
                <Setter Property="BorderBrush" Value="#FFEEEEEE"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="2"/>
                <Setter Property="Padding" Value="8"/>
                <Setter Property="Margin" Value="0,1"/>
                <Setter Property="Cursor" Value="Hand"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#FFF8FBFF"/>
                        <Setter Property="BorderBrush" Value="#FFD4E7FF"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
            
            <Style x:Key="CollisionTitleStyle" TargetType="TextBlock">
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="FontSize" Value="11"/>
                <Setter Property="Foreground" Value="#FF333333"/>
                <Setter Property="TextWrapping" Value="Wrap"/>
            </Style>
            
            <Style x:Key="CollisionDescriptionStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="10"/>
                <Setter Property="Foreground" Value="#FF666666"/>
                <Setter Property="TextWrapping" Value="Wrap"/>
                <Setter Property="Margin" Value="0,2,0,0"/>
            </Style>
            
            <Style x:Key="StatusTagStyle" TargetType="Border">
                <Setter Property="CornerRadius" Value="8"/>
                <Setter Property="Padding" Value="6,2"/>
                <Setter Property="Margin" Value="0,0,0,3"/>
                <Setter Property="HorizontalAlignment" Value="Left"/>
            </Style>
            
            <Style x:Key="StatusTextStyle" TargetType="TextBlock">
                <Setter Property="FontSize" Value="9"/>
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="Foreground" Value="White"/>
            </Style>
            
            <Style x:Key="SectionHeaderStyle" TargetType="Label">
                <Setter Property="FontWeight" Value="SemiBold"/>
                <Setter Property="FontSize" Value="13"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksPrimaryBrush}"/>
                <Setter Property="Padding" Value="0,8,0,4"/>
            </Style>
            
            <Style x:Key="ProgressStyle" TargetType="ProgressBar">
                <Setter Property="Height" Value="4"/>
                <Setter Property="Margin" Value="0,5"/>
                <Setter Property="Foreground" Value="{StaticResource NavisworksPrimaryBrush}"/>
                <Setter Property="Background" Value="#FFEEEEEE"/>
            </Style>

            <!-- 数据模板：碰撞项目 -->
            <DataTemplate x:Key="CollisionItemTemplate">
                <Border Style="{StaticResource CollisionItemStyle}">
                    <Border.InputBindings>
                        <MouseBinding MouseAction="LeftClick" 
                                      Command="{Binding DataContext.HighlightCollisionCommand, RelativeSource={RelativeSource AncestorType=Window}}" 
                                      CommandParameter="{Binding}"/>
                    </Border.InputBindings>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        
                        <TextBlock Grid.Row="0" Text="{Binding Title}" Style="{StaticResource CollisionDescriptionStyle}" FontWeight="SemiBold"/>
                        
                        <Border Grid.Row="1" Style="{StaticResource StatusTagStyle}" Background="{Binding StatusColor}">
                            <TextBlock Text="{Binding StatusText}" Style="{StaticResource StatusTextStyle}"/>
                        </Border>
                        
                        <TextBlock Grid.Row="2" Text="{Binding Description}" Style="{StaticResource CollisionDescriptionStyle}"/>
                        
                        <TextBlock Grid.Row="3" Text="{Binding Details}" Style="{StaticResource CollisionDescriptionStyle}" Margin="0,3,0,0"/>
                    </Grid>
                </Border>
            </DataTemplate>
            
        </ResourceDictionary>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <!-- 主内容区域 -->
        <Border Grid.Row="0" 
                BorderBrush="#FFD4E7FF" 
                BorderThickness="1" 
                CornerRadius="0" 
                Background="White"
                Margin="15,15,15,10">
            <Grid>
                <!-- 加载进度指示 -->
                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" 
                            Visibility="{Binding IsGenerating, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <TextBlock Text="正在生成碰撞报告..." HorizontalAlignment="Center" 
                               Style="{StaticResource DialogContentTextStyle}" Margin="0,0,0,10"/>
                    <ProgressBar Value="{Binding ProgressPercentage}" Maximum="100" Width="300" Style="{StaticResource ProgressStyle}"/>
                    <TextBlock Text="{Binding ProgressMessage}" HorizontalAlignment="Center" 
                               Style="{StaticResource DialogContentTextStyle}" Margin="0,5,0,0"/>
                </StackPanel>
                
                <!-- 报告内容 -->
                <ScrollViewer VerticalScrollBarVisibility="Auto" 
                              Padding="15"
                              Visibility="{Binding IsGenerating, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
                    <StackPanel>
                        
                        <!-- 报告标题 -->
                        <Label Content="{Binding ReportTitle}" 
                               FontSize="16"
                               FontWeight="SemiBold"
                               Foreground="{StaticResource NavisworksPrimaryBrush}"
                               HorizontalAlignment="Center"
                               Margin="0,0,0,15"/>
                        
                        <!-- 总体统计信息 -->
                        <Label Content="总体统计" Style="{StaticResource SectionHeaderStyle}"/>
                        <UniformGrid Columns="3" Margin="0,0,0,15">
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="总碰撞数" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding Statistics.TotalCollisions}" Style="{StaticResource StatisticValueStyle}" FontSize="16"/>
                                </Grid>
                            </Border>
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="碰撞构件" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding UniqueCollidedObjectsCount}" Style="{StaticResource StatisticValueStyle}"/>
                                </Grid>
                            </Border>
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="检测点" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding Statistics.AnimationCollisions}" Style="{StaticResource StatisticValueStyle}"/>
                                </Grid>
                            </Border>
                        </UniformGrid>

                        <!-- 检测参数信息 -->
                        <Label Content="检测参数" Style="{StaticResource SectionHeaderStyle}"/>
                        <UniformGrid Columns="4" Margin="0,0,0,15">
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="路径名称" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding PathName}" Style="{StaticResource StatisticValueStyle}" FontSize="11"/>
                                </Grid>
                            </Border>
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="帧率(FPS)" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding FrameRate}" Style="{StaticResource StatisticValueStyle}"/>
                                </Grid>
                            </Border>
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="时长(秒)" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding Duration}" Style="{StaticResource StatisticValueStyle}"/>
                                </Grid>
                            </Border>
                            <Border Style="{StaticResource StatisticItemStyle}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.Row="0" Text="检测间隙(米)" Style="{StaticResource StatisticLabelStyle}"/>
                                    <TextBlock Grid.Row="1" Text="{Binding DetectionGap, StringFormat={}{0:F2}}" Style="{StaticResource StatisticValueStyle}"/>
                                </Grid>
                            </Border>
                        </UniformGrid>

                        <!-- 运动构件信息 -->
                        <Border Style="{StaticResource StatisticItemStyle}"
                                Margin="0,0,0,10"
                                Background="#FFF0F8FF"
                                BorderBrush="#FFB0D4F1">
                            <StackPanel HorizontalAlignment="Center">
                                <TextBlock Text="🚛 运动构件信息"
                                           FontSize="11"
                                           FontWeight="SemiBold"
                                           Foreground="{StaticResource NavisworksPrimaryBrush}"
                                           HorizontalAlignment="Center"
                                           Margin="0,0,0,5"/>
                                <TextBlock Text="{Binding MovingObjectInfo}"
                                           FontSize="12"
                                           FontWeight="Normal"
                                           Foreground="#FF333333"
                                           HorizontalAlignment="Center"
                                           TextWrapping="Wrap"/>
                            </StackPanel>
                        </Border>

                        <!-- 碰撞构件清单 -->
                        <StackPanel Visibility="{Binding CollidedObjectsList.Count, Converter={StaticResource CountToVisibilityConverter}}" Margin="0,0,0,15">
                            <Label Content="碰撞构件清单" Style="{StaticResource SectionHeaderStyle}"/>
                            <Border Style="{StaticResource StatisticItemStyle}" MaxHeight="150">
                                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                                    <ItemsControl ItemsSource="{Binding CollidedObjectsList}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal" Margin="5,2">
                                                    <TextBlock Text="•" FontWeight="Bold" Foreground="{StaticResource NavisworksPrimaryBrush}" Margin="0,0,8,0"/>
                                                    <TextBlock Text="{Binding}"
                                                               Style="{StaticResource DialogContentTextStyle}"
                                                               TextWrapping="Wrap"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </ScrollViewer>
                            </Border>
                        </StackPanel>

                        <!-- 总结信息 -->
                        <Label Content="总结与建议" Style="{StaticResource SectionHeaderStyle}"/>
                        <Border Style="{StaticResource StatisticItemStyle}" Margin="0,0,0,10">
                            <StackPanel>
                                <TextBlock Text="{Binding SummaryMessage}" 
                                           FontWeight="SemiBold"
                                           FontSize="12"
                                           Foreground="{StaticResource NavisworksPrimaryBrush}"
                                           TextWrapping="Wrap"/>
                                <TextBlock Text="{Binding RecommendationMessage}" 
                                           Style="{StaticResource DialogContentTextStyle}"
                                           Margin="0,8,0,0"
                                           TextWrapping="Wrap"/>
                            </StackPanel>
                        </Border>
                        
                        <!-- 详细碰撞信息 -->
                        <StackPanel Visibility="{Binding HasCollisions, Converter={StaticResource BooleanToVisibilityConverter}}">

                            <!-- 碰撞详情 -->
                            <StackPanel Visibility="{Binding AnimationCollisions.Count, Converter={StaticResource CountToVisibilityConverter}}">
                                <Label Content="碰撞详情" Style="{StaticResource SectionHeaderStyle}"/>
                                <ItemsControl ItemsSource="{Binding AnimationCollisions}"
                                              ItemTemplate="{StaticResource CollisionItemTemplate}"
                                              Margin="0,0,0,10"/>
                            </StackPanel>

                        </StackPanel>
                        
                        <!-- 无碰撞提示 -->
                        <Border Style="{StaticResource StatisticItemStyle}" 
                                Visibility="{Binding HasCollisions, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
                                Background="#FFF0F8FF" 
                                BorderBrush="#FFB0D4F1">
                            <StackPanel HorizontalAlignment="Center" Margin="20">
                                <TextBlock Text="✅ 未发现碰撞问题" 
                                           FontSize="14" 
                                           FontWeight="SemiBold"
                                           Foreground="#FF28A745"
                                           HorizontalAlignment="Center"/>
                                <TextBlock Text="当前路径规划良好，无需调整。" 
                                           Style="{StaticResource DialogContentTextStyle}"
                                           HorizontalAlignment="Center"
                                           Margin="0,5,0,0"/>
                            </StackPanel>
                        </Border>
                        
                    </StackPanel>
                </ScrollViewer>
            </Grid>
        </Border>
        
        <!-- 底部按钮区域 -->
        <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="导出报告" 
                        Command="{Binding ExportReportCommand}"
                        Style="{StaticResource SecondaryButtonStyle}" 
                        Margin="0,0,10,0"
                        Visibility="{Binding HasCollisions, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                
                <Button Content="关闭" 
                        Click="CloseButton_Click" 
                        Style="{StaticResource ActionButtonStyle}"/>
                        
            </StackPanel>
        </Border>
    </Grid>
</Window>