<Window x:Class="DragonISO.App.Views.IsoOverrideDialog"
        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"
        xmlns:vm="clr-namespace:DragonISO.App.ViewModels"
        xmlns:conv="clr-namespace:DragonISO.App.Converters"
        mc:Ignorable="d"
        Title="Output settings"
        Icon="/Assets/DragonISO.ico"
        Width="420" Height="360"
        ResizeMode="NoResize"
        WindowStartupLocation="CenterOwner"
        ShowInTaskbar="False"
        Background="{DynamicResource Wd.Canvas}"
        Foreground="{DynamicResource Wd.Text.Primary}"
        UseLayoutRounding="True"
        SnapsToDevicePixels="True"
        TextOptions.TextRenderingMode="ClearType"
        TextOptions.TextFormattingMode="Display"
        d:DataContext="{d:DesignInstance Type=vm:IsoOverrideDialogViewModel}">
    <!--
        Per-ISO override editor — opened from the participant row's gear button.
        Default Windows chrome (no chromeless) per the shape brief: this is a
        utility dialog, not part of the main shell's design language, and it
        benefits from the OS's native close affordance.

        Four enums (framerate / resolution / aspect / audio), an indicator that
        tells the operator whether the participant currently overrides globals,
        and a footer with Apply + Cancel. "Reset to global" appears as a Ghost
        button next to the indicator when an override is currently set.
    -->
    <Window.Resources>
        <conv:BoolToVisibilityConverter x:Key="BoolToVis"
                                        TrueValue="Visible"
                                        FalseValue="Collapsed"/>
        <conv:EnumDescriptionConverter x:Key="EnumDesc"/>
    </Window.Resources>

    <Grid Margin="20,16,20,16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Title row: participant display name + caption -->
        <StackPanel Grid.Row="0">
            <TextBlock Text="{Binding DisplayName}"
                       Style="{StaticResource Wd.Text.Title}"
                       FontSize="16"
                       TextTrimming="CharacterEllipsis"/>
            <TextBlock Text="Output settings"
                       Style="{StaticResource Wd.Text.Subtle}"
                       Foreground="{DynamicResource Wd.Text.Tertiary}"
                       Margin="0,2,0,0"/>
        </StackPanel>

        <!-- "Following global settings" pill + Reset to global button.
             Only visible when an override is currently active on the engine.
             When hidden, the row collapses so the editor area shifts up. -->
        <Border Grid.Row="1"
                Margin="0,12,0,0"
                Padding="10,6"
                CornerRadius="{StaticResource Radius.S}"
                Background="{DynamicResource Wd.Accent.CyanMuted}"
                BorderBrush="{DynamicResource Wd.Accent.Cyan}"
                BorderThickness="1"
                Visibility="{Binding FollowingGlobalsVisible, Converter={StaticResource BoolToVis}}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Ellipse Grid.Column="0"
                         Width="7" Height="7"
                         Fill="{DynamicResource Wd.Accent.Cyan}"
                         VerticalAlignment="Center"
                         Margin="0,0,8,0"/>
                <TextBlock Grid.Column="1"
                           Text="Overriding global settings"
                           FontFamily="{StaticResource Wd.Font.Sans}"
                           FontSize="11"
                           Foreground="{DynamicResource Wd.Accent.CyanText}"
                           VerticalAlignment="Center"/>
                <Button Grid.Column="2"
                        Style="{StaticResource Wd.Button.Ghost}"
                        Content="Reset to global"
                        Command="{Binding ClearCommand}"
                        Padding="10,3"
                        FontSize="11"
                        ToolTip="Clear this participant's override and follow global output settings"/>
            </Grid>
        </Border>

        <!-- The four labeled ComboBoxes -->
        <StackPanel Grid.Row="2" Margin="0,12,0,0">
            <TextBlock Text="Framerate"
                       Style="{StaticResource Wd.Text.Subtle}"
                       Margin="0,0,0,4"/>
            <ComboBox ItemsSource="{Binding Settings.AvailableFramerates}"
                      SelectedItem="{Binding Framerate}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EnumDesc}}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <TextBlock Text="Resolution"
                       Style="{StaticResource Wd.Text.Subtle}"
                       Margin="0,10,0,4"/>
            <ComboBox ItemsSource="{Binding Settings.AvailableResolutions}"
                      SelectedItem="{Binding Resolution}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EnumDesc}}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <TextBlock Text="Aspect"
                       Style="{StaticResource Wd.Text.Subtle}"
                       Margin="0,10,0,4"/>
            <ComboBox ItemsSource="{Binding Settings.AvailableAspectModes}"
                      SelectedItem="{Binding Aspect}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EnumDesc}}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <TextBlock Text="Audio"
                       Style="{StaticResource Wd.Text.Subtle}"
                       Margin="0,10,0,4"/>
            <ComboBox ItemsSource="{Binding Settings.AvailableAudioModes}"
                      SelectedItem="{Binding Audio}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EnumDesc}}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </StackPanel>

        <!-- Spacer divider above the footer -->
        <Border Grid.Row="3"
                Height="1"
                Margin="0,16,0,12"
                Background="{DynamicResource Wd.Border}"/>

        <!-- Footer: Cancel + Apply -->
        <StackPanel Grid.Row="4"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Style="{StaticResource Wd.Button.Ghost}"
                    Content="Cancel"
                    Command="{Binding CancelCommand}"
                    Padding="16,6"
                    Margin="0,0,8,0"
                    IsCancel="True"/>
            <Button Style="{StaticResource Wd.Button.Primary}"
                    Content="Apply"
                    Command="{Binding ApplyCommand}"
                    Padding="16,6"
                    IsDefault="True"/>
        </StackPanel>
    </Grid>
</Window>
