<?xml version="1.0" encoding="utf-8"?>
<Window x:Class="MainShell.Recipe.View.MarkCoordinatePreviewWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="{DynamicResource MarkCoordinatePreviewWindowTitle}"
        Width="940"
        Height="720"
        MinWidth="860"
        MinHeight="620"
        WindowStartupLocation="CenterOwner"
        Background="#F3F6FB">
    <Window.Resources>
        <SolidColorBrush x:Key="PageBackgroundBrush" Color="#F3F6FB"/>
        <SolidColorBrush x:Key="PanelBorderBrush" Color="#D8E0EC"/>
        <SolidColorBrush x:Key="PanelHeaderBrush" Color="#F7FAFD"/>
        <SolidColorBrush x:Key="PrimaryBrush" Color="#2F5DAA"/>
        <SolidColorBrush x:Key="PrimaryDarkBrush" Color="#244C8D"/>
        <SolidColorBrush x:Key="PrimaryLightBrush" Color="#EAF1FF"/>
        <SolidColorBrush x:Key="BodyTextBrush" Color="#26415E"/>
        <SolidColorBrush x:Key="MutedTextBrush" Color="#6E7F96"/>
        <SolidColorBrush x:Key="DangerBrush" Color="#D95B69"/>
        <SolidColorBrush x:Key="DangerPanelBrush" Color="#FFF8F8"/>
        <SolidColorBrush x:Key="DangerBorderBrush" Color="#FFD8D8"/>

        <Style x:Key="CardBorderStyle" TargetType="Border">
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="{StaticResource PanelBorderBrush}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="CornerRadius" Value="3"/>
            <Setter Property="SnapsToDevicePixels" Value="True"/>
        </Style>

        <Style x:Key="HeaderTitleStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="22"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="Foreground" Value="{StaticResource PrimaryBrush}"/>
        </Style>

        <Style x:Key="HeaderSubtitleStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="Foreground" Value="{StaticResource MutedTextBrush}"/>
        </Style>

        <Style x:Key="SectionTitleStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="Foreground" Value="{StaticResource PrimaryBrush}"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>

        <Style x:Key="MetricLabelStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Foreground" Value="{StaticResource MutedTextBrush}"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
        </Style>

        <Style x:Key="MetricValueStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="28"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="Foreground" Value="{StaticResource PrimaryBrush}"/>
        </Style>

        <Style x:Key="PrimaryActionButtonStyle" TargetType="Button">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="Background" Value="{StaticResource PrimaryBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource PrimaryBrush}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Padding" Value="18,8"/>
            <Setter Property="Height" Value="40"/>
            <Setter Property="MinWidth" Value="112"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="3"
                                SnapsToDevicePixels="True">
                            <ContentPresenter HorizontalAlignment="Center"
                                              VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="{StaticResource PrimaryDarkBrush}"/>
                                <Setter Property="BorderBrush" Value="{StaticResource PrimaryDarkBrush}"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background" Value="#1D3F74"/>
                                <Setter Property="BorderBrush" Value="#1D3F74"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.55"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="GhostActionButtonStyle" TargetType="Button" BasedOn="{StaticResource PrimaryActionButtonStyle}">
            <Setter Property="Foreground" Value="{StaticResource PrimaryBrush}"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="{StaticResource PanelBorderBrush}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="3"
                                SnapsToDevicePixels="True">
                            <ContentPresenter HorizontalAlignment="Center"
                                              VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="{StaticResource PrimaryLightBrush}"/>
                                <Setter Property="BorderBrush" Value="{StaticResource PrimaryBrush}"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background" Value="#DDE9FF"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.55"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="DataGrid">
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="{StaticResource PanelBorderBrush}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{StaticResource BodyTextBrush}"/>
            <Setter Property="RowBackground" Value="White"/>
            <Setter Property="AlternatingRowBackground" Value="#FAFCFF"/>
            <Setter Property="GridLinesVisibility" Value="Horizontal"/>
            <Setter Property="HorizontalGridLinesBrush" Value="#E4E9F2"/>
            <Setter Property="VerticalGridLinesBrush" Value="#E4E9F2"/>
            <Setter Property="HeadersVisibility" Value="Column"/>
            <Setter Property="CanUserAddRows" Value="False"/>
            <Setter Property="CanUserDeleteRows" Value="False"/>
            <Setter Property="CanUserResizeRows" Value="False"/>
            <Setter Property="CanUserReorderColumns" Value="False"/>
            <Setter Property="CanUserSortColumns" Value="False"/>
            <Setter Property="IsReadOnly" Value="True"/>
            <Setter Property="RowHeaderWidth" Value="0"/>
            <Setter Property="AutoGenerateColumns" Value="False"/>
            <Setter Property="SelectionMode" Value="Single"/>
            <Setter Property="SelectionUnit" Value="FullRow"/>
            <Setter Property="RowHeight" Value="42"/>
            <Setter Property="ColumnHeaderHeight" Value="46"/>
        </Style>

        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Foreground" Value="{StaticResource PrimaryBrush}"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Background" Value="{StaticResource PanelHeaderBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource PanelBorderBrush}"/>
            <Setter Property="BorderThickness" Value="0,0,0,1"/>
        </Style>

        <Style TargetType="DataGridCell">
            <Setter Property="Padding" Value="8,4"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="TextBlock.TextAlignment" Value="Center"/>
        </Style>
    </Window.Resources>

    <Grid Background="{StaticResource PageBackgroundBrush}" Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Border Grid.Row="0" Style="{StaticResource CardBorderStyle}" Padding="18,16">
            <DockPanel LastChildFill="True">
                <Button DockPanel.Dock="Right"
                        Content="{DynamicResource MarkCoordinatePreviewClose}"
                        Style="{StaticResource GhostActionButtonStyle}"
                        Command="{Binding CloseCommand}"
                        CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"/>

                <StackPanel>
                    <TextBlock Text="{DynamicResource MarkCoordinatePreviewWindowTitle}"
                               Style="{StaticResource HeaderTitleStyle}"/>
                    <TextBlock Text="Preview"
                               Style="{StaticResource HeaderSubtitleStyle}"
                               Margin="0,4,0,0"/>
                </StackPanel>
            </DockPanel>
        </Border>

        <Grid Grid.Row="1" Margin="0,14,0,14">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="260"/>
                <ColumnDefinition Width="12"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Border Grid.Column="0" Style="{StaticResource CardBorderStyle}" Padding="18,16">
                <StackPanel>
                    <TextBlock Text="{DynamicResource MarkCoordinatePreviewPointCountLabel}"
                               Style="{StaticResource MetricLabelStyle}"/>
                    <TextBlock Text="{Binding PointCount}"
                               Style="{StaticResource MetricValueStyle}"
                               Margin="0,6,0,0"/>
                </StackPanel>
            </Border>

            <Border Grid.Column="2" Style="{StaticResource CardBorderStyle}" Padding="18,16">
                <StackPanel>
                    <TextBlock Text="Read-only data view"
                               Style="{StaticResource SectionTitleStyle}"/>
                    <TextBlock Text="The table below mirrors the generated or imported coordinate set and does not edit source data."
                               Foreground="{StaticResource BodyTextBrush}"
                               TextWrapping="Wrap"
                               Margin="0,8,0,0"/>
                </StackPanel>
            </Border>
        </Grid>

        <Border Grid.Row="2" Style="{StaticResource CardBorderStyle}" Padding="0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <DockPanel Grid.Row="0" Background="{StaticResource PanelHeaderBrush}" LastChildFill="False">
                    <TextBlock Margin="18,12"
                               Text="{DynamicResource MarkCoordinatePreviewWindowTitle}"
                               Style="{StaticResource SectionTitleStyle}"/>
                    <TextBlock Margin="0,12,18,12"
                               DockPanel.Dock="Right"
                               Foreground="{StaticResource MutedTextBrush}"
                               VerticalAlignment="Center"
                               Text="{Binding PointCount, StringFormat=Total: {0}}"/>
                </DockPanel>

                <DataGrid Grid.Row="1"
                          Margin="16"
                          ItemsSource="{Binding Points}"
                          HorizontalScrollBarVisibility="Auto"
                          VerticalScrollBarVisibility="Auto">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="{DynamicResource MarkCoordinatePreviewIndex}" Width="90" Binding="{Binding Index}"/>
                        <DataGridTextColumn Header="{DynamicResource MarkCoordinatePreviewPointName}" Width="2*" Binding="{Binding PointName}"/>
                        <DataGridTextColumn Header="{DynamicResource MarkCoordinatePreviewRow}" Width="*" Binding="{Binding Row}"/>
                        <DataGridTextColumn Header="{DynamicResource MarkCoordinatePreviewCol}" Width="*" Binding="{Binding Col}"/>
                        <DataGridTextColumn Header="{DynamicResource MarkCoordinatePreviewTheoryX}" Width="*" Binding="{Binding TheoryX, StringFormat={}{0:F4}}"/>
                        <DataGridTextColumn Header="{DynamicResource MarkCoordinatePreviewTheoryY}" Width="*" Binding="{Binding TheoryY, StringFormat={}{0:F4}}"/>
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </Border>

        <Border Grid.Row="3"
                Margin="0,14,0,0"
                Padding="14,10"
                Background="{StaticResource DangerPanelBrush}"
                BorderBrush="{StaticResource DangerBorderBrush}"
                BorderThickness="1"
                CornerRadius="3">
            <DockPanel LastChildFill="True">
                <Button DockPanel.Dock="Right"
                        Content="{DynamicResource MarkCoordinatePreviewClose}"
                        Style="{StaticResource GhostActionButtonStyle}"
                        Margin="12,0,0,0"
                        Command="{Binding CloseCommand}"
                        CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"/>
                <TextBlock Text="{DynamicResource MarkCoordinatePreviewReadOnlyTip}"
                           VerticalAlignment="Center"
                           Foreground="{StaticResource DangerBrush}"
                           TextWrapping="Wrap"/>
            </DockPanel>
        </Border>
    </Grid>
</Window>
