<Window x:Class="Ink_Canvas.ScreenshotSelectorWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:props="clr-namespace:Ink_Canvas.Properties"
        xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
        xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
        Title="{x:Static props:MainWindowStrings.Main_Screenshot_WindowTitle}"
        WindowStyle="None" 
        AllowsTransparency="True" 
        Background="Transparent"
        WindowState="Maximized"
        Topmost="True"
        ShowInTaskbar="False"
        Cursor="Cross"
        KeyDown="Window_KeyDown"
        MouseLeftButtonDown="Window_MouseLeftButtonDown"
        MouseRightButtonDown="Window_MouseRightButtonDown"
        MouseMove="Window_MouseMove"
        MouseLeftButtonUp="Window_MouseLeftButtonUp">
    <Window.Resources>
        <SolidColorBrush x:Key="ScreenshotBarBackgroundBrush" Color="#F21F1F1F" />
        <SolidColorBrush x:Key="ScreenshotBarPrimaryBrush" Color="#0F9F7A" />
        <SolidColorBrush x:Key="ScreenshotBarPrimaryHoverBrush" Color="#10B981" />
        <SolidColorBrush x:Key="ScreenshotBarPrimaryPressedBrush" Color="#047857" />
        <SolidColorBrush x:Key="ScreenshotBarAccentBrush" Color="#2563EB" />
        <SolidColorBrush x:Key="ScreenshotBarAccentHoverBrush" Color="#3B82F6" />
        <SolidColorBrush x:Key="ScreenshotBarAccentPressedBrush" Color="#1D4ED8" />
        <SolidColorBrush x:Key="ScreenshotBarDangerBrush" Color="#DC2626" />
        <SolidColorBrush x:Key="ScreenshotBarDangerHoverBrush" Color="#EF4444" />
        <SolidColorBrush x:Key="ScreenshotBarDangerPressedBrush" Color="#B91C1C" />

        <DropShadowEffect x:Key="ScreenshotBarShadow"
                          BlurRadius="26"
                          ShadowDepth="8"
                          Direction="270"
                          Opacity="0.35"
                          Color="#000000" />

        <Style x:Key="ScreenshotBarModeButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Static ui:ThemeKeys.DefaultButtonStyleKey}}">
            <Setter Property="Height" Value="36" />
            <Setter Property="MinWidth" Value="0" />
            <Setter Property="Padding" Value="14,0" />
            <Setter Property="FontSize" Value="14" />
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="Cursor" Value="Hand" />
        </Style>

        <Style x:Key="ScreenshotBarActionButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Static ui:ThemeKeys.DefaultButtonStyleKey}}">
            <Setter Property="Height" Value="36" />
            <Setter Property="MinWidth" Value="0" />
            <Setter Property="Padding" Value="16,0" />
            <Setter Property="FontSize" Value="14" />
            <Setter Property="FontWeight" Value="SemiBold" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Cursor" Value="Hand" />
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonForegroundKey}" Color="White" />
                <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonForegroundPointerOverKey}" Color="White" />
                <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonForegroundPressedKey}" Color="White" />
            </Style.Resources>
        </Style>
    </Window.Resources>

    <Grid Name="MainGrid">
        <!-- 半透明遮罩 -->
        <Rectangle Name="OverlayRectangle"
                   Fill="Black"
                   Opacity="0.3" />
        <Rectangle Name="TransparentSelectionMask"
                   Fill="Black"
                   Opacity="0.3"
                   Visibility="Collapsed">
            <Rectangle.Clip>
                <CombinedGeometry GeometryCombineMode="Exclude">
                    <CombinedGeometry.Geometry1>
                        <RectangleGeometry Rect="0,0,10000,10000" />
                    </CombinedGeometry.Geometry1>
                    <CombinedGeometry.Geometry2>
                        <RectangleGeometry x:Name="SelectionClipGeometry" Rect="0,0,0,0" />
                    </CombinedGeometry.Geometry2>
                </CombinedGeometry>
            </Rectangle.Clip>
        </Rectangle>

        <!-- 墨迹预览层（用于“包含墨迹”预览） -->
        <Image Name="InkPreviewImage"
               Stretch="Fill"
               IsHitTestVisible="False"
               Visibility="Collapsed"
               Panel.ZIndex="950" />

        <!-- 选择区域容器 -->
        <Canvas Name="SelectionCanvas" Panel.ZIndex="1000">
            <!-- 矩形选择模式 -->
            <Rectangle Name="SelectionRectangle"
                       Stroke="White"
                       StrokeThickness="1"
                       Fill="#01000000"
                       Visibility="Collapsed"
                       Panel.ZIndex="1001"
                       MouseLeftButtonDown="SelectionRectangle_MouseLeftButtonDown"
                       MouseLeftButtonUp="SelectionRectangle_MouseLeftButtonUp"
                       MouseMove="SelectionRectangle_MouseMove"
                       Cursor="SizeAll" />

            <!-- 任意形状选择模式 -->
            <Path Name="SelectionPath"
                  Stroke="White"
                  StrokeThickness="1"
                  Fill="Transparent"
                  Visibility="Collapsed" />

            <!-- 控制点容器 -->
            <Canvas Name="ControlPointsCanvas" Visibility="Collapsed" Panel.ZIndex="1002">
                <!-- 四个角控制点 -->
                <Ellipse Name="TopLeftControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNWSE" />
                <Ellipse Name="TopRightControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNESW" />
                <Ellipse Name="BottomLeftControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNESW" />
                <Ellipse Name="BottomRightControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNWSE" />
                
                <!-- 四个边控制点 -->
                <Ellipse Name="TopControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNS" />
                <Ellipse Name="BottomControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeNS" />
                <Ellipse Name="LeftControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeWE" />
                <Ellipse Name="RightControl" Width="8" Height="8" Fill="White" Stroke="White" StrokeThickness="1" Cursor="SizeWE" />
            </Canvas>

            <!-- 尺寸信息显示 -->
            <Border Name="SizeInfoBorder"
                    Background="#1a1a1a"
                    Opacity="0.9"
                    CornerRadius="4"
                    Padding="8,4"
                    Visibility="Collapsed">
                <TextBlock Name="SizeInfoText"
                           Foreground="White"
                           FontSize="12"
                           FontWeight="Medium"
                           Text="0 x 0" />
            </Border>
        </Canvas>

        <!-- 底部工具栏 -->
        <Border Background="{StaticResource ScreenshotBarBackgroundBrush}"
                BorderBrush="{DynamicResource {x:Static ui:ThemeKeys.CardStrokeColorDefaultBrushKey}}"
                BorderThickness="1"
                CornerRadius="12"
                Padding="10"
                HorizontalAlignment="Center"
                VerticalAlignment="Bottom"
                Margin="0,0,0,80"
                Effect="{StaticResource ScreenshotBarShadow}"
                Panel.ZIndex="1000"
                ui:ThemeManager.RequestedTheme="Dark">
            <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="10">
                <!-- 模式切换按钮 -->
                <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="8">
                    <Button Name="RectangleModeButton"
                            Style="{StaticResource ScreenshotBarModeButtonStyle}"
                            Content="{x:Static props:MainWindowStrings.Main_Screenshot_RectangleMode}"
                            Click="RectangleModeButton_Click" />
                    <Button Name="FreehandModeButton"
                            Style="{StaticResource ScreenshotBarModeButtonStyle}"
                            Content="{x:Static props:MainWindowStrings.Main_Screenshot_FreehandMode}"
                            Click="FreehandModeButton_Click" />
                    <Button Name="FullScreenButton"
                            Style="{StaticResource ScreenshotBarModeButtonStyle}"
                            Content="{x:Static props:MainWindowStrings.Main_Screenshot_FullScreenMode}"
                            Click="FullScreenButton_Click" />
                    <Button Name="CameraModeButton"
                            Style="{StaticResource ScreenshotBarModeButtonStyle}"
                            Content="{x:Static props:MainWindowStrings.Main_Screenshot_CameraCaptureMode}"
                            Click="CameraModeButton_Click" />
                </ikw:SimpleStackPanel>

                <Rectangle Width="1"
                           Height="32"
                           Fill="{DynamicResource {x:Static ui:ThemeKeys.DividerStrokeColorDefaultBrushKey}}"
                           Margin="4,0" />

                <!-- 操作按钮 -->
                <CheckBox Name="IncludeInkCheckBox"
                          Content="{x:Static props:MainWindowStrings.Main_Screenshot_IncludeInk}"
                          Margin="4,0"
                          VerticalAlignment="Center"
                          Foreground="White"
                          FontSize="14"
                          FontWeight="SemiBold"
                          Checked="IncludeInkCheckBox_Checked"
                          Unchecked="IncludeInkCheckBox_Unchecked" />
                <Rectangle Name="ToolbarDividerRectangle"
                           Width="1"
                           Height="32"
                           Fill="{DynamicResource {x:Static ui:ThemeKeys.DividerStrokeColorDefaultBrushKey}}"
                           Margin="4,0" />
                <Button Name="ConfirmButton"
                        Style="{StaticResource ScreenshotBarActionButtonStyle}"
                        Content="{x:Static props:MainWindowStrings.Main_Screenshot_ConfirmCapture}"
                        Background="{StaticResource ScreenshotBarPrimaryBrush}"
                        BorderBrush="{StaticResource ScreenshotBarPrimaryBrush}"
                        Click="ConfirmButton_Click">
                    <Button.Resources>
                        <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonBackgroundPointerOverKey}" Color="#10B981" />
                        <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonBackgroundPressedKey}" Color="#047857" />
                    </Button.Resources>
                </Button>
                <Button Name="AddToWhiteboardButton"
                        Style="{StaticResource ScreenshotBarActionButtonStyle}"
                        Content="{x:Static props:MainWindowStrings.Main_Screenshot_AddToWhiteboard}"
                        Background="{StaticResource ScreenshotBarAccentBrush}"
                        BorderBrush="{StaticResource ScreenshotBarAccentBrush}"
                        Click="AddToWhiteboardButton_Click">
                    <Button.Resources>
                        <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonBackgroundPointerOverKey}" Color="#3B82F6" />
                        <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonBackgroundPressedKey}" Color="#1D4ED8" />
                    </Button.Resources>
                </Button>
                <Button Name="CancelButton"
                        Style="{StaticResource ScreenshotBarActionButtonStyle}"
                        Content="{x:Static props:CommonStrings.Common_Cancel}"
                        Background="{StaticResource ScreenshotBarDangerBrush}"
                        BorderBrush="{StaticResource ScreenshotBarDangerBrush}"
                        Click="CancelButton_Click">
                    <Button.Resources>
                        <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonBackgroundPointerOverKey}" Color="#EF4444" />
                        <SolidColorBrush x:Key="{x:Static ui:ThemeKeys.ButtonBackgroundPressedKey}" Color="#B91C1C" />
                    </Button.Resources>
                </Button>
            </ikw:SimpleStackPanel>
        </Border>

        <!-- 摄像头预览区域 -->
        <Border Name="CameraPreviewBorder"
                Background="#1a1a1a"
                Opacity="0.95"
                CornerRadius="8"
                Padding="8"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="640"
                Height="480"
                Visibility="Collapsed"
                Panel.ZIndex="1000">
            <Grid>
                <!-- 摄像头预览画面 -->
                <Image Name="CameraPreviewImage"
                       Stretch="Uniform"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center" />
                
                <!-- 摄像头控制面板 -->
                <StackPanel Orientation="Vertical"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Bottom"
                           Margin="0,0,0,8">
                    <!-- 第一行：摄像头选择和切换 -->
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                        <!-- 摄像头选择下拉框 -->
                        <ComboBox Name="CameraSelectionComboBox"
                                 Width="200"
                                 Margin="4,0"
                                 Background="#2d2d2d"
                                 Foreground="White"
                                 BorderBrush="#404040"
                                 SelectionChanged="CameraSelectionComboBox_SelectionChanged" />
                        
                        <!-- 切换摄像头按钮 -->
                        <Button Name="SwitchCameraButton"
                               Content="{x:Static props:MainWindowStrings.Main_Screenshot_SwitchCamera}"
                               Margin="4,0"
                               Padding="8,4"
                               Background="#3b82f6"
                               Foreground="White"
                               BorderThickness="0"
                               FontWeight="Medium"
                               Click="SwitchCameraButton_Click" />
                    </StackPanel>
                    
                    <!-- 第二行：旋转和分辨率控制 -->
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,4,0,0">
                        <!-- 旋转控制 -->
                        <StackPanel Orientation="Horizontal" Margin="4,0">
                            <TextBlock Text="{x:Static props:MainWindowStrings.Main_Screenshot_Rotation}" Foreground="White" VerticalAlignment="Center" Margin="0,0,4,0" FontSize="12"/>
                            <Button Name="RotateLeftButton" Content="⟲" Width="30" Height="30" Margin="2,0" 
                                   Background="#4b5563" Foreground="White" BorderThickness="0" 
                                   Click="RotateLeftButton_Click" FontSize="10" FontWeight="10"/>
                            <TextBlock Name="RotationAngleText" Text="0°" Foreground="White" VerticalAlignment="Center" 
                                      Margin="4,0" FontSize="12" MinWidth="30" TextAlignment="Center"/>
                            <Button Name="RotateRightButton" Content="⟳" Width="30" Height="30" Margin="2,0" 
                                   Background="#4b5563" Foreground="White" BorderThickness="0" 
                                   Click="RotateRightButton_Click" FontSize="10" FontWeight="10"/>
                        </StackPanel>
                        
                        <!-- 分隔线 -->
                        <Rectangle Width="1" Height="20" Fill="#404040" Margin="8,0"/>
                        
                        <!-- 分辨率控制 -->
                        <StackPanel Orientation="Horizontal" Margin="4,0">
                            <TextBlock Text="{x:Static props:MainWindowStrings.Main_Screenshot_Resolution}" Foreground="White" VerticalAlignment="Center" Margin="0,0,4,0" FontSize="12"/>
                            <ComboBox Name="ResolutionComboBox" Margin="2,0"
                                     Background="#2d2d2d" Foreground="White" BorderBrush="#404040"
                                     SelectionChanged="ResolutionComboBox_SelectionChanged" />
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
                
                <!-- 摄像头状态指示 -->
                <Border Background="#1a1a1a"
                       Opacity="0.9"
                       CornerRadius="4"
                       Padding="8,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Top"
                       Margin="8">
                    <TextBlock Name="CameraStatusText"
                              Foreground="White"
                              FontSize="12"
                              FontWeight="Medium"
                              Text="{x:Static props:MainWindowStrings.Main_Screenshot_CameraNotConnected}" />
                </Border>
            </Grid>
        </Border>

        <!-- 统一提示文字区域 -->
        <Border Name="HintTextBorder"
                Background="#1a1a1a"
                Opacity="0.9"
                CornerRadius="6"
                Padding="16,10"
                HorizontalAlignment="Center"
                VerticalAlignment="Bottom"
                Margin="0,0,0,140"
                Panel.ZIndex="1000">
            <TextBlock Name="HintText"
                       Text="{x:Static props:MainWindowStrings.Main_Screenshot_DefaultHint}"
                       Foreground="White"
                       FontSize="14"
                       FontWeight="Medium" />
        </Border>
    </Grid>
</Window>
