<UserControl
    x:Class="XplorePlane.Views.ImageProcessingPanelView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:ImageProcessing.Controls;assembly=ImageProcessing.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:roi="clr-namespace:ImageROIControl.Controls;assembly=ImageROIControl"
    d:DesignHeight="700"
    d:DesignWidth="1000"
    mc:Ignorable="d">

    <UserControl.Resources>

        <SolidColorBrush x:Key="PanelBg" Color="White" />
        <SolidColorBrush x:Key="PanelBorder" Color="#cdcbcb" />
        <SolidColorBrush x:Key="SeparatorBrush" Color="#E0E0E0" />
        <SolidColorBrush x:Key="StatusBarBg" Color="#F5F5F5" />
        <SolidColorBrush x:Key="BtnDefaultFg" Color="#1c1c1b" />
        <SolidColorBrush x:Key="BtnHoverFg" Color="#1c3866" />
        <SolidColorBrush x:Key="BtnDisabledFg" Color="#cdcbcb" />

        <FontFamily x:Key="CsdFont">Microsoft YaHei UI</FontFamily>

        <Style x:Key="PanelBorderStyle" TargetType="Border">
            <Setter Property="Background" Value="{StaticResource PanelBg}" />
            <Setter Property="BorderBrush" Value="{StaticResource PanelBorder}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="CornerRadius" Value="4" />
        </Style>

        <Style x:Key="MenuBtn" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Height="{TemplateBinding Height}" Background="White">
                            <ContentPresenter
                                x:Name="cp"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                TextBlock.FontFamily="{StaticResource CsdFont}"
                                TextBlock.FontSize="15"
                                TextBlock.FontWeight="Bold"
                                TextBlock.Foreground="{StaticResource BtnDefaultFg}" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Cursor" Value="Hand" />
                                <Setter TargetName="cp" Property="TextBlock.Foreground" Value="{StaticResource BtnHoverFg}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="cp" Property="TextBlock.Foreground" Value="{StaticResource BtnDisabledFg}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="GroupBox">
            <Setter Property="FontFamily" Value="{StaticResource CsdFont}" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Foreground" Value="#1c1c1b" />
            <Setter Property="BorderBrush" Value="#cdcbcb" />
            <Setter Property="Padding" Value="4,6,4,4" />
        </Style>

    </UserControl.Resources>

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

        <!--  主内容区：左侧操作栏 | 中间图像 | 右侧参数配置  -->
        <Grid Grid.Row="0" Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition
                    Width="160"
                    MinWidth="140"
                    MaxWidth="200" />

                <ColumnDefinition Width="*" MinWidth="300" />

                <ColumnDefinition
                    Width="320"
                    MinWidth="280"
                    MaxWidth="420" />
            </Grid.ColumnDefinitions>

            <!--  左侧操作栏  -->
            <Border Grid.Column="0" Style="{StaticResource PanelBorderStyle}">
                <ScrollViewer VerticalScrollBarVisibility="Auto">
                    <StackPanel>
                        <Button
                            Height="70"
                            Command="{Binding LoadImageCommand}"
                            Content="加载图像"
                            Style="{StaticResource MenuBtn}" />
                        <Rectangle Height="1" Fill="{StaticResource SeparatorBrush}" />
                        <Button
                            Height="70"
                            Command="{Binding ApplyProcessingCommand}"
                            Content="处理图像"
                            Style="{StaticResource MenuBtn}" />
                        <Rectangle Height="1" Fill="{StaticResource SeparatorBrush}" />
                        <Button
                            Height="70"
                            Command="{Binding ResetImageCommand}"
                            Content="重置图像"
                            Style="{StaticResource MenuBtn}" />
                        <Rectangle Height="1" Fill="{StaticResource SeparatorBrush}" />
                        <Button
                            Height="70"
                            Command="{Binding SaveResultCommand}"
                            Content="保存结果"
                            Style="{StaticResource MenuBtn}" />
                    </StackPanel>
                </ScrollViewer>
            </Border>

            <!--  中间：原始图像 + 处理结果  -->
            <Grid Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="8*" />
                    <RowDefinition Height="18*" />
                    <RowDefinition Height="301*" />
                    <RowDefinition Height="327*" />
                </Grid.RowDefinitions>

                <GroupBox
                    Grid.Row="0"
                    Grid.RowSpan="3"
                    Margin="0,0,0,3"
                    Header="原始图像">
                    <roi:PolygonRoiCanvas Background="Black" ImageSource="{Binding OriginalImage}" />
                </GroupBox>

                <GroupBox Grid.Row="3" Header="处理结果">
                    <roi:PolygonRoiCanvas Background="Black" ImageSource="{Binding CurrentImage}" />
                </GroupBox>
            </Grid>

            <!--  右侧：算子选择 + 参数配置  -->
            <Border Grid.Column="3" Style="{StaticResource PanelBorderStyle}">
                <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                    <StackPanel Margin="10,8,10,10">

                        <GroupBox Margin="0,0,0,8" Header="选择算子">
                            <ComboBox
                                x:Name="cmbProcessors"
                                Height="30"
                                Padding="6,0,0,0"
                                VerticalContentAlignment="Center"
                                FontFamily="{StaticResource CsdFont}"
                                FontSize="12"
                                ItemsSource="{Binding AvailableProcessors}"
                                SelectedItem="{Binding SelectedProcessorItem}"
                                SelectionChanged="OnProcessorComboChanged" />
                        </GroupBox>

                        <GroupBox Header="参数配置">
                            <controls:ProcessorParameterControl
                                x:Name="parameterControl"
                                MinHeight="200"
                                ParameterChanged="OnParameterChanged" />
                        </GroupBox>

                    </StackPanel>
                </ScrollViewer>
            </Border>
        </Grid>

        <!--  状态栏  -->
        <Border
            Grid.Row="1"
            Padding="12,0"
            Background="{StaticResource StatusBarBg}"
            BorderBrush="{StaticResource PanelBorder}"
            BorderThickness="0,1,0,0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="180" />
                </Grid.ColumnDefinitions>

                <TextBlock
                    Grid.Column="0"
                    VerticalAlignment="Center"
                    FontFamily="{StaticResource CsdFont}"
                    FontSize="12"
                    Foreground="#333333">
                    <Run FontWeight="Bold" Text="状态：" /><Run Text="{Binding StatusMessage}" />
                </TextBlock>

                <ProgressBar
                    Grid.Column="2"
                    Height="10"
                    Margin="0,0,8,0"
                    VerticalAlignment="Center"
                    Maximum="1"
                    Minimum="0"
                    Value="{Binding ProcessingProgress}" />
            </Grid>
        </Border>

    </Grid>
</UserControl>
