<?xml version="1.0" encoding="utf-8" ?>
<Page
    x:Class="AmiReel.MainPage"
    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">

    <Grid x:Name="RootGrid" Padding="20" RowSpacing="16" Background="{ThemeResource PageBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" ColumnSpacing="16">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Border Grid.Column="0" Padding="18" Style="{StaticResource CardBorderStyle}">
                <StackPanel Spacing="12">
                    <TextBlock Text="Source recordings" Style="{StaticResource SectionTitleStyle}" />
                    <StackPanel Orientation="Horizontal" Spacing="10">
                        <Button Content="Add video files..." Click="AddInputs_Click" />
                        <Button Content="Clear" Click="ClearInputs_Click" />
                    </StackPanel>
                    <ListView x:Name="InputList"
                              Height="130"
                              SelectionMode="Single"
                              SelectionChanged="InputList_SelectionChanged"
                              AllowDrop="True"
                              DragOver="InputList_DragOver"
                              Drop="InputList_Drop"
                              ToolTipService.ToolTip="Drag and drop video files here to add them" />
                    <Button x:Name="PreviewSourceButton"
                            Content="Preview selected"
                            Click="PreviewSource_Click"
                            HorizontalAlignment="Left"
                            IsEnabled="False" />
                </StackPanel>
            </Border>

            <Border Grid.Column="1" Padding="18" Style="{StaticResource CardBorderStyle}">
                <StackPanel Spacing="12">
                    <TextBlock Text="End card and output" Style="{StaticResource SectionTitleStyle}" />
                    <TextBlock Text="Leave blank to use a built-in black end card." Style="{StaticResource MutedTextStyle}" />

                    <Grid ColumnSpacing="10" RowSpacing="10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBox x:Name="EndCardBox" Grid.Row="0" MinHeight="40" />
                        <Button Grid.Row="0" Grid.Column="1" Content="Browse..." Click="BrowseEndCard_Click" VerticalAlignment="Stretch" MinWidth="120" />

                        <TextBox x:Name="OutputFolderBox" Grid.Row="1" MinHeight="40" />
                        <Button Grid.Row="1" Grid.Column="1" Content="Browse..." Click="BrowseOutput_Click" VerticalAlignment="Stretch" MinWidth="120" />

                        <TextBox x:Name="OutputNameBox" Grid.Row="2" Grid.ColumnSpan="2" MinHeight="40" />
                    </Grid>
                </StackPanel>
            </Border>
        </Grid>

        <Border Grid.Row="1" Padding="18" Style="{StaticResource CardBorderStyle}">
            <StackPanel Spacing="12">
                <TextBlock Text="Render progress" Style="{StaticResource SectionTitleStyle}" />
                <StackPanel Orientation="Horizontal" Spacing="6">
                    <TextBlock x:Name="StageText" Text="Ready" FontSize="15" FontWeight="SemiBold" />
                    <TextBlock x:Name="PercentText" Text="0%" FontSize="15" FontWeight="SemiBold" Foreground="{ThemeResource AccentBrush}" />
                </StackPanel>
                <ProgressBar x:Name="RenderProgressBar" Minimum="0" Maximum="100" Height="8" />
                <TextBlock x:Name="StatusText" Text="Select the recordings and start the render. The end card is optional." TextWrapping="WrapWholeWords" Style="{StaticResource MutedTextStyle}" />
            </StackPanel>
        </Border>

        <Border Grid.Row="2" Padding="18" Style="{StaticResource CardBorderStyle}">
            <StackPanel Spacing="12">
                <TextBlock Text="FFmpeg log" Style="{StaticResource SectionTitleStyle}" />
                <TextBox x:Name="LogBox"
                         IsReadOnly="True"
                         AcceptsReturn="True"
                         TextWrapping="NoWrap"
                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                         FontFamily="Consolas"
                         FontSize="12"
                         VerticalAlignment="Stretch"
                         Height="260" />
            </StackPanel>
        </Border>

        <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <StackPanel Grid.Column="0" Orientation="Horizontal" Spacing="10">
                <Button x:Name="OpenOutputButton" Content="Open output folder" Click="OpenOutput_Click" IsEnabled="False" HorizontalAlignment="Left" />
                <Button x:Name="PreviewRenderedButton" Content="Preview render" Click="PreviewRendered_Click" IsEnabled="False" />
            </StackPanel>

            <StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="10">
                <Button x:Name="OpenSettingsButton" Content="&#xE713;" FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets"
                        Click="OpenSettings_Click" Style="{StaticResource IconButtonStyle}" ToolTipService.ToolTip="Settings" />
                <Button x:Name="CancelButton" Content="Cancel" Click="Cancel_Click" IsEnabled="False" />
                <Button x:Name="RenderButton" Content="Start render" Click="Render_Click" Style="{StaticResource PrimaryButtonStyle}" />
            </StackPanel>
        </Grid>

        <ContentDialog x:Name="SettingsDialog"
                       Title="Settings"
                       PrimaryButtonText="Done"
                       CloseButtonText="Close"
                       DefaultButton="Primary"
                       Background="{ThemeResource PanelBrush}"
                       Foreground="{ThemeResource TextBrush}"
                       BorderBrush="{ThemeResource HeroBorderBrush}"
                       BorderThickness="1.5"
                       CornerRadius="18"
                       PrimaryButtonStyle="{StaticResource DialogPrimaryButtonStyle}"
                       CloseButtonStyle="{StaticResource DialogCloseButtonStyle}">
            <ScrollViewer MaxHeight="560" VerticalScrollBarVisibility="Auto">
                <StackPanel Spacing="16">
                    <Border Padding="14" Background="{ThemeResource PanelAltBrush}" BorderBrush="{ThemeResource BorderBrush}" BorderThickness="1" CornerRadius="12">
                        <StackPanel Spacing="10">
                            <TextBlock Text="Appearance" Style="{StaticResource SectionTitleStyle}" />
                            <ComboBox x:Name="ThemeBox" Header="Theme" SelectionChanged="ThemeBox_SelectionChanged">
                                <ComboBoxItem Content="Dark" Tag="Dark" />
                                <ComboBoxItem Content="Light" Tag="Light" />
                            </ComboBox>
                        </StackPanel>
                    </Border>

                    <Border Padding="14" Background="{ThemeResource PanelAltBrush}" BorderBrush="{ThemeResource BorderBrush}" BorderThickness="1" CornerRadius="12">
                        <StackPanel Spacing="10">
                            <TextBlock Text="Timing and screenshots" Style="{StaticResource SectionTitleStyle}" />
                            <Grid ColumnSpacing="10" RowSpacing="10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBox x:Name="TrimBox" Grid.Row="0" Grid.Column="0" Header="Trim start (seconds)" />
                                <TextBox x:Name="FadeBox" Grid.Row="0" Grid.Column="1" Header="Fade (seconds)" />
                                <TextBox x:Name="HoldBox" Grid.Row="1" Grid.Column="0" Header="End-card hold (seconds)" />
                                <TextBox x:Name="IntervalBox" Grid.Row="1" Grid.Column="1" Header="Thumbnail interval (seconds)" />
                            </Grid>
                        </StackPanel>
                    </Border>

                    <Border Padding="14" Background="{ThemeResource PanelAltBrush}" BorderBrush="{ThemeResource BorderBrush}" BorderThickness="1" CornerRadius="12">
                        <StackPanel Spacing="10">
                            <TextBlock Text="Video encoding" Style="{StaticResource SectionTitleStyle}" />
                            <ComboBox x:Name="EncoderBox" Header="Encoder">
                                <ComboBoxItem Content="Auto (NVENC → CPU fallback)" Tag="Auto" />
                                <ComboBoxItem Content="NVIDIA NVENC" Tag="NvidiaNvenc" />
                                <ComboBoxItem Content="CPU libx264" Tag="CpuX264" />
                            </ComboBox>
                            <TextBlock Text="Output: 3840 × 2160 · 50 FPS" Style="{StaticResource MutedTextStyle}" />
                        </StackPanel>
                    </Border>

                    <Border Padding="14" Background="{ThemeResource PanelAltBrush}" BorderBrush="{ThemeResource BorderBrush}" BorderThickness="1" CornerRadius="12">
                        <StackPanel Spacing="10">
                            <TextBlock Text="Source files" Style="{StaticResource SectionTitleStyle}" />
                            <CheckBox x:Name="MoveSourcesBox"
                                      Content="Move source videos to destination\originals"
                                      IsChecked="True" />
                            <TextBlock Text="After a successful render, original recordings are moved into an originals subfolder of the output folder. Uncheck to leave them where they are."
                                       TextWrapping="WrapWholeWords"
                                       Style="{StaticResource MutedTextStyle}" />
                        </StackPanel>
                    </Border>

                    <Border Padding="14" Background="{ThemeResource PanelAltBrush}" BorderBrush="{ThemeResource BorderBrush}" BorderThickness="1" CornerRadius="12">
                        <StackPanel Spacing="10">
                            <TextBlock Text="FFmpeg tools" Style="{StaticResource SectionTitleStyle}" />
                            <TextBlock Text="Optional override. Leave blank to auto-detect FFmpeg and FFprobe from PATH, then use the embedded fallback." TextWrapping="WrapWholeWords" Style="{StaticResource MutedTextStyle}" />
                            <Grid ColumnSpacing="10" RowSpacing="10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBox x:Name="FfmpegPathBox" Grid.Row="0" Header="ffmpeg.exe path" />
                                <Button Grid.Row="0" Grid.Column="1" Content="Browse..." Click="BrowseFfmpeg_Click" VerticalAlignment="Bottom" />
                                <TextBox x:Name="FfprobePathBox" Grid.Row="1" Header="ffprobe.exe path" />
                                <Button Grid.Row="1" Grid.Column="1" Content="Browse..." Click="BrowseFfprobe_Click" VerticalAlignment="Bottom" />
                                <TextBox x:Name="PreviewPlayerPathBox" Grid.Row="2" Header="Preview player path (optional, e.g. mpv.exe)" />
                                <Button Grid.Row="2" Grid.Column="1" Content="Browse..." Click="BrowsePreviewPlayer_Click" VerticalAlignment="Bottom" />
                            </Grid>
                        </StackPanel>
                    </Border>
                </StackPanel>
            </ScrollViewer>
        </ContentDialog>
    </Grid>
</Page>
