<!--
NavisworksTransport 路径规划分析对话框 V2
支持多维度评分和同终点组分析
-->
<Window x:Class="NavisworksTransport.UI.WPF.Views.PathAnalysisDialog"
        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.Views"
        xmlns:vm="clr-namespace:NavisworksTransport.UI.WPF.ViewModels"
        xmlns:cmd="clr-namespace:NavisworksTransport.UI.WPF.Commands"
        mc:Ignorable="d"
        Title="路径规划分析 - 多路径对比" 
        Height="850" 
        Width="1300"
        ResizeMode="CanResize" 
        WindowStartupLocation="CenterOwner"
        MinHeight="700"
        MinWidth="1100">
    
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/TransportPlugin;component/src/UI/WPF/Resources/NavisworksStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            
            <!-- 颜色定义 -->
            <SolidColorBrush x:Key="PrimaryBrush" Color="#2C5AA0"/>
            <SolidColorBrush x:Key="SuccessBrush" Color="#28A745"/>
            <SolidColorBrush x:Key="WarningBrush" Color="#FFC107"/>
            <SolidColorBrush x:Key="DangerBrush" Color="#DC3545"/>
            <SolidColorBrush x:Key="InfoBrush" Color="#17A2B8"/>
            
            <!-- 卡片样式 -->
            <Style x:Key="CardStyle" TargetType="Border">
                <Setter Property="Background" Value="White"/>
                <Setter Property="BorderBrush" Value="#FFE0E0E0"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="6"/>
                <Setter Property="Padding" Value="15"/>
                <Setter Property="Margin" Value="5"/>
                <Setter Property="Effect">
                    <Setter.Value>
                        <DropShadowEffect Color="Gray" Direction="315" ShadowDepth="1" Opacity="0.2" BlurRadius="3"/>
                    </Setter.Value>
                </Setter>
            </Style>
            
            <!-- 最佳路径卡片样式 -->
            <Style x:Key="BestPathCardStyle" TargetType="Border">
                <Setter Property="Background" Value="#FFF0F8FF"/>
                <Setter Property="BorderBrush" Value="#FF28A745"/>
                <Setter Property="BorderThickness" Value="2"/>
                <Setter Property="CornerRadius" Value="8"/>
                <Setter Property="Padding" Value="20"/>
            </Style>
            
            <!-- 维度分数条样式 -->
            <Style x:Key="ScoreBarStyle" TargetType="ProgressBar">
                <Setter Property="Height" Value="20"/>
                <Setter Property="Maximum" Value="100"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="Background" Value="#FFE9ECEF"/>
                <Setter Property="Foreground" Value="{StaticResource PrimaryBrush}"/>
            </Style>
            
            <!-- 建议项样式 -->
            <Style x:Key="SuggestionItemStyle" TargetType="Border">
                <Setter Property="Background" Value="White"/>
                <Setter Property="BorderBrush" Value="#FFE0E0E0"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="4"/>
                <Setter Property="Padding" Value="12"/>
                <Setter Property="Margin" Value="0,4"/>
            </Style>
            
            <!-- 组项样式 -->
            <Style x:Key="GroupItemStyle" TargetType="Border">
                <Setter Property="Background" Value="#FFF8F9FA"/>
                <Setter Property="BorderBrush" Value="#FFDEE2E6"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="CornerRadius" Value="4"/>
                <Setter Property="Padding" Value="12"/>
                <Setter Property="Margin" Value="0,4"/>
            </Style>
            
            <!-- 值转换器 -->
            <local:ScoreToColorConverter x:Key="ScoreToColorConverter"/>
            <local:PriorityToColorConverter x:Key="PriorityToColorConverter"/>
            <local:StrategyDescriptionConverter x:Key="StrategyDescriptionConverter"/>
            <local:BoolToBackgroundConverter x:Key="BoolToBackgroundConverter"/>
            <local:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
            <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        </ResourceDictionary>
    </Window.Resources>

    <Grid Background="#FFF5F5F5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <!-- 头部标题 -->
        <Border Grid.Row="0" Background="{StaticResource PrimaryBrush}" Padding="20,15">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <TextBlock Text="📊 路径规划分析" FontSize="20" FontWeight="Bold" Foreground="White"/>
                    <TextBlock Text="| 多维度对比分析" FontSize="14" Foreground="#FFCCCCCC" Margin="15,3,0,0"/>
                </StackPanel>
                <TextBlock Grid.Column="1" Text="{Binding AnalysisStatus}" FontSize="12" Foreground="#FFCCCCCC" VerticalAlignment="Center"/>
            </Grid>
        </Border>
        
        <!-- 主内容区域 -->
        <Grid Grid.Row="1" Margin="15">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="280"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="350"/>
            </Grid.ColumnDefinitions>
            
            <!-- 左侧面板：路径选择和策略 -->
            <StackPanel Grid.Column="0">
                <!-- 路径选择卡片 -->
                <Border Style="{StaticResource CardStyle}">
                    <StackPanel>
                        <TextBlock Text="📋 路径选择" FontSize="14" FontWeight="Bold" Foreground="{StaticResource PrimaryBrush}" Margin="0,0,0,10"/>
                        
                        <ScrollViewer Height="250" VerticalScrollBarVisibility="Auto">
                            <ItemsControl ItemsSource="{Binding AvailablePaths}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Background="#FFF8F9FA" BorderBrush="#FFDEE2E6" BorderThickness="1" 
                                                CornerRadius="4" Padding="10" Margin="0,3">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <CheckBox Grid.Column="0" IsChecked="{Binding IsSelected, Mode=TwoWay}" 
                                                          VerticalAlignment="Center" Margin="0,0,8,0"/>
                                                <StackPanel Grid.Column="1">
                                                    <TextBlock Text="{Binding Name}" FontWeight="SemiBold" FontSize="12"/>
                                                    <TextBlock FontSize="10" Foreground="#FF6C757D">
                                                        <Run Text="长度: "/>
                                                        <Run Text="{Binding Length, StringFormat={}{0:F1}m}"/>
                                                        <Run Text=" | 碰撞: "/>
                                                        <Run Text="{Binding CollisionCount}"/>
                                                    </TextBlock>
                                                </StackPanel>
                                            </Grid>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ScrollViewer>
                        
                        <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                            <Button Content="全选" Command="{Binding SelectAllCommand}" 
                                    Style="{StaticResource SecondaryButtonStyle}" Width="65" Margin="0,0,8,0"/>
                            <Button Content="清空" Command="{Binding ClearSelectionCommand}" 
                                    Style="{StaticResource SecondaryButtonStyle}" Width="65"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
                
                <!-- 策略选择卡片 -->
                <Border Style="{StaticResource CardStyle}" Margin="0,10,0,0">
                    <StackPanel>
                        <TextBlock Text="🎯 分析策略" FontSize="14" FontWeight="Bold" Foreground="{StaticResource PrimaryBrush}" Margin="0,0,0,10"/>
                        
                        <ComboBox ItemsSource="{Binding AvailableStrategies}" 
                                  SelectedItem="{Binding AnalysisStrategy}"
                                  Height="32" Margin="0,5"/>
                        
                        <TextBlock Text="{Binding AnalysisStrategy, Converter={StaticResource StrategyDescriptionConverter}}" 
                                   FontSize="11" Foreground="#FF6C757D" TextWrapping="Wrap" Margin="0,5,0,0"/>
                        
                        <Button Content="开始分析" Command="{Binding StartAnalysisCommand}" 
                                Style="{StaticResource ActionButtonStyle}" Height="38" Margin="0,15,0,0"/>
                    </StackPanel>
                </Border>
            </StackPanel>
            
            <!-- 中间面板：分析结果和组列表 -->
            <ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Auto">
                <StackPanel>
                    <!-- 最佳路径卡片 -->
                    <Border Style="{StaticResource BestPathCardStyle}" 
                            Visibility="{Binding RecommendedPath, Converter={StaticResource NullToVisibilityConverter}}">
                        <StackPanel>
                            <TextBlock FontSize="12" Foreground="#FF28A745" FontWeight="SemiBold">
                                🏆 推荐最佳路径
                            </TextBlock>
                            <TextBlock Text="{Binding RecommendedPath.Name}" FontSize="18" FontWeight="Bold" 
                                       Foreground="#FF2C3E50" Margin="0,5"/>
                            <TextBlock FontSize="12" Foreground="#FF6C757D">
                                <Run Text="长度: "/>
                                <Run Text="{Binding RecommendedPath.Length, StringFormat={}{0:F1}m}"/>
                                <Run Text=" | 评分: "/>
                                <Run Text="{Binding RecommendedPath.Score, StringFormat={}{0:F1}}"/>
                            </TextBlock>
                        </StackPanel>
                    </Border>
                    
                    <!-- 同终点组列表 -->
                    <Border Style="{StaticResource CardStyle}" Margin="0,10,0,0">
                        <StackPanel>
                            <TextBlock Text="🎯 同终点路径组" FontSize="14" FontWeight="Bold" 
                                       Foreground="{StaticResource PrimaryBrush}" Margin="0,0,0,10"/>
                            
                            <ItemsControl ItemsSource="{Binding EndpointGroups}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Style="{StaticResource GroupItemStyle}" 
                                                Background="{Binding IsSelected, Converter={StaticResource BoolToBackgroundConverter}}">
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>
                                                <StackPanel Grid.Row="0" Orientation="Horizontal">
                                                    <TextBlock Text="{Binding GroupName}" FontWeight="SemiBold" FontSize="12"/>
                                                    <TextBlock Text="{Binding RouteCount, StringFormat=({0}条路径)}" 
                                                               FontSize="11" Foreground="#FF6C757D" Margin="8,0,0,0"/>
                                                    <Border Background="#FF28A745" CornerRadius="3" Padding="5,2" Margin="8,0,0,0"
                                                            Visibility="{Binding BestPath.IsBestInGroup, Converter={StaticResource BoolToVisibilityConverter}}">
                                                        <TextBlock Text="最佳" FontSize="9" Foreground="White"/>
                                                    </Border>
                                                </StackPanel>
                                                <TextBlock Grid.Row="1" Text="{Binding EndPointDescription}" 
                                                           FontSize="10" Foreground="#FF6C757D" Margin="0,3,0,0"/>
                                            </Grid>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </StackPanel>
                    </Border>
                    
                    <!-- 图表展示区域 -->
                    <Border Style="{StaticResource CardStyle}" Margin="0,10,0,0" 
                            Visibility="{Binding HasAnalysisResults, Converter={StaticResource BoolToVisibilityConverter}}">
                        <StackPanel>
                            <TextBlock Text="📊 多路径对比图表" FontSize="14" FontWeight="Bold" 
                                       Foreground="{StaticResource PrimaryBrush}" Margin="0,0,0,10"/>
                            
                            <!-- 柱状图 -->
                            <Border BorderBrush="#FFE0E0E0" BorderThickness="1" CornerRadius="4" Height="280" Margin="0,0,0,10">
                                <Grid>
                                    <TextBlock Text="各维度分数对比" FontSize="12" FontWeight="Bold" 
                                               Foreground="#2C5AA0" HorizontalAlignment="Center" Margin="0,5"/>
                                    <Canvas x:Name="BarChartCanvas" Margin="10,30,10,10"
                                            Width="530" Height="240"/>
                                </Grid>
                            </Border>
                            
                            <!-- 雷达图 -->
                            <Border BorderBrush="#FFE0E0E0" BorderThickness="1" CornerRadius="4" Height="200">
                                <Grid>
                                    <TextBlock Text="雷达图对比" FontSize="12" FontWeight="Bold" 
                                               Foreground="#2C5AA0" HorizontalAlignment="Center" Margin="0,5"/>
                                    <Canvas x:Name="RadarChartCanvas" Margin="10,30,10,10"
                                            Width="530" Height="160"/>
                                </Grid>
                            </Border>
                            
                            <TextBlock Text="提示：柱形图对比各路径维度得分，雷达图展示选中组内所有路径的四维度表现" 
                                       FontSize="10" Foreground="#FF6C757D" Margin="0,8,0,0" TextWrapping="Wrap"/>
                        </StackPanel>
                    </Border>
                </StackPanel>
            </ScrollViewer>
            
            <!-- 右侧面板：建议列表 -->
            <Border Grid.Column="2" Style="{StaticResource CardStyle}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    
                    <TextBlock Grid.Row="0" Text="💡 优化建议" FontSize="14" FontWeight="Bold" 
                               Foreground="{StaticResource PrimaryBrush}" Margin="0,0,0,10"/>
                    
                    <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                        <ItemsControl ItemsSource="{Binding CategorizedSuggestions}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border Style="{StaticResource SuggestionItemStyle}">
                                        <StackPanel>
                                            <StackPanel Orientation="Horizontal" Margin="0,0,0,5">
                                                <Border Background="{Binding Priority, Converter={StaticResource PriorityToColorConverter}}" 
                                                        CornerRadius="3" Padding="4,2">
                                                    <TextBlock Text="{Binding CategoryName}" FontSize="9" Foreground="White"/>
                                                </Border>
                                                <TextBlock Text="{Binding RelatedRouteName}" FontSize="10" 
                                                           Foreground="#FF6C757D" Margin="8,0,0,0" FontStyle="Italic"/>
                                            </StackPanel>
                                            <TextBlock Text="{Binding Title}" FontSize="12" FontWeight="SemiBold" 
                                                       TextWrapping="Wrap"/>
                                            <TextBlock Text="{Binding Description}" FontSize="11" Foreground="#FF6C757D" 
                                                       TextWrapping="Wrap" Margin="0,3,0,0"/>
                                        </StackPanel>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ScrollViewer>
                </Grid>
            </Border>
        </Grid>
        
        <!-- 底部按钮 -->
        <Border Grid.Row="2" Background="White" BorderBrush="#FFE0E0E0" BorderThickness="0,1,0,0" 
                Padding="20,12">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Content="导出报告" Command="{Binding ExportReportCommand}" 
                        Style="{StaticResource ActionButtonStyle}" Width="100" Margin="0,0,10,0"/>
                <Button Content="关闭" Click="CloseButton_Click" Style="{StaticResource SecondaryButtonStyle}" Width="80"/>
            </StackPanel>
        </Border>
    </Grid>
</Window>

