<Window xmlns="https://github.com/avaloniaui"
        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" d:DesignWidth="520" d:DesignHeight="360"
        x:Class="PhotoboothUploader.MainWindow"
        Width="560" Height="420"
        MinWidth="520" MinHeight="400"
        Title="Die Fotospiel.App - Photobooth Uploader">
    <Grid Margin="24,32,24,24" RowDefinitions="Auto,*">
        <StackPanel Grid.Row="0" Orientation="Horizontal" Spacing="12" VerticalAlignment="Center">
            <Border Width="40" Height="40" Classes="card accent" VerticalAlignment="Center" HorizontalAlignment="Left">
                <Image Source="avares://PhotoboothUploader/Assets/logo.png" Width="28" Height="28" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Border>
            <StackPanel Spacing="2">
                <TextBlock x:Name="TitleText"
                           Text="Die Fotospiel.App - Photobooth Uploader"
                           Classes="title"
                           PointerPressed="TitleText_PointerPressed" />
                <TextBlock Text="Sicherer Upload der Fotobox-Fotos ins Event." Classes="subtitle" />
            </StackPanel>
        </StackPanel>

        <Grid Grid.Row="1" ColumnDefinitions="*,16,*">
            <StackPanel Grid.Column="0" Spacing="16" MaxWidth="420">

            <Border Padding="14" Classes="card">
                <StackPanel Spacing="6">
                    <TextBlock Text="Schritte" FontWeight="SemiBold" />
                    <TextBlock x:Name="StepCodeText" Text="1. Code eingeben" />
                    <TextBlock x:Name="StepFolderText" Text="2. Upload-Ordner wählen" />
                    <TextBlock x:Name="StepReadyText" Text="3. Upload läuft" />
                </StackPanel>
            </Border>

            <Border Padding="14" Classes="card">
                <StackPanel Spacing="10">
                    <TextBlock Text="Verbindungscode" FontWeight="SemiBold" />
                    <TextBlock Text="Gib den 6-stelligen Verbindungscode ein." TextWrapping="Wrap" Classes="subtitle" />
                    <TextBox x:Name="CodeBox" MaxLength="6" Watermark="123456" TextChanged="CodeBox_TextChanged" />
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <Button x:Name="ConnectButton" Content="Verbinden" Click="ConnectButton_Click" Classes="primary" />
                        <Button x:Name="ReconnectButton" Content="Erneut verbinden" Click="ReconnectButton_Click" IsEnabled="False" Classes="secondary" />
                    </StackPanel>
                </StackPanel>
            </Border>

            <Border Padding="14" Classes="card">
                <StackPanel Spacing="8">
                    <TextBlock Text="Upload-Ordner" FontWeight="SemiBold" />
                    <TextBlock x:Name="FolderText" Text="Noch nicht ausgewählt." TextWrapping="Wrap" Classes="subtitle" />
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <Button x:Name="DslrBoothPresetButton" Content="DSLrBooth" Click="DslrBoothPresetButton_Click" Classes="secondary" IsVisible="False" />
                        <Button x:Name="SparkboothPresetButton" Content="Sparkbooth" Click="SparkboothPresetButton_Click" Classes="secondary" IsVisible="False" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <Button x:Name="PickFolderButton" Content="Ordner auswählen" Click="PickFolderButton_Click" IsEnabled="False" Classes="primary" />
                        <Button x:Name="TestUploadButton" Content="Test-Upload senden" Click="TestUploadButton_Click" IsEnabled="False" Classes="secondary" />
                    </StackPanel>
                </StackPanel>
            </Border>

            <ToggleSwitch x:Name="QuietToggle" Content="Ruhiger Modus (nur Fehler anzeigen)" />

            <Border x:Name="AdvancedPanel" Padding="12" Classes="card accent" IsVisible="False">
                <StackPanel Spacing="6">
                    <TextBlock Text="Erweiterte Einstellungen" FontWeight="SemiBold" />
                    <ToggleSwitch x:Name="SettingsUnlockToggle" Content="Einstellungen entsperren" Checked="SettingsUnlockToggle_Changed" Unchecked="SettingsUnlockToggle_Changed" />
                    <TextBlock Text="Profile" />
                    <ComboBox x:Name="ProfilesBox" />
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <Button x:Name="LoadProfileButton" Content="Profil laden" Click="LoadProfileButton_Click" Classes="secondary" />
                        <Button x:Name="SaveProfileButton" Content="Profil speichern" Click="SaveProfileButton_Click" Classes="secondary" />
                    </StackPanel>
                    <TextBlock Text="Basis-URL" />
                    <TextBox x:Name="BaseUrlBox" Watermark="https://fotospiel.app" />
                    <TextBlock Text="Max. parallele Uploads" />
                    <TextBox x:Name="MaxUploadsBox" Watermark="2" />
                    <TextBlock Text="Upload-Tempo" />
                    <ComboBox x:Name="UploadTempoBox" SelectedIndex="1">
                        <ComboBoxItem Content="Schnell (ohne Pause)" />
                        <ComboBoxItem Content="Normal" />
                        <ComboBoxItem Content="Sanft (schont Netzwerk)" />
                    </ComboBox>
                    <TextBlock Text="Nur diese Dateien (optional)" />
                    <TextBox x:Name="IncludePatternsBox" Watermark="*.jpg;*.jpeg;*.png" />
                    <TextBlock Text="Dateien ausschliessen (optional)" />
                    <TextBox x:Name="ExcludePatternsBox" Watermark="*_preview*;*.tmp" />
                    <TextBlock Text="Antwort-Format (optional)" />
                    <ComboBox x:Name="ResponseFormatBox" SelectedIndex="0">
                        <ComboBoxItem Content="Auto" />
                        <ComboBoxItem Content="JSON" />
                        <ComboBoxItem Content="XML" />
                    </ComboBox>
                    <TextBlock Text="Manuelle Zugangsdaten (optional)" FontWeight="SemiBold" Margin="0,8,0,0" />
                    <TextBlock Text="Diese Felder ueberschreiben den Verbindungscode." Classes="subtitle" TextWrapping="Wrap" />
                    <TextBlock Text="Upload-URL" />
                    <TextBox x:Name="ManualUploadUrlBox" Watermark="https://fotospiel.app/api/v1/photobooth/upload" />
                    <TextBlock Text="Benutzername" />
                    <TextBox x:Name="ManualUsernameBox" />
                    <TextBlock Text="Passwort" />
                    <TextBox x:Name="ManualPasswordBox" PasswordChar="•" />
                    <Button x:Name="TestConnectionButton" Content="Verbindung testen" Click="TestConnectionButton_Click" Classes="secondary" />
                    <Button x:Name="SaveAdvancedButton" Content="Speichern" Click="SaveAdvancedButton_Click" Classes="primary" />
                </StackPanel>
            </Border>
        </StackPanel>

            <StackPanel Grid.Column="2" Spacing="16" MaxWidth="380" Margin="0,6,0,0">
            <Border Padding="14" Classes="card accent">
                <StackPanel Spacing="6">
                    <TextBlock Text="Status" FontWeight="SemiBold" />
                    <TextBlock x:Name="StatusText" Text="Nicht verbunden." TextWrapping="Wrap" />
                    <TextBlock x:Name="LastUploadText" Text="Letzter Upload: —" />
                    <TextBlock x:Name="QueueStatusText" Text="Warteschlange: 0 · Läuft: 0 · Fehlgeschlagen: 0" />
                    <TextBlock x:Name="LiveStatusText" Text="Live: —" />
                </StackPanel>
            </Border>

            <Border Padding="14" Classes="card">
                <StackPanel Spacing="6">
                    <TextBlock Text="Details" FontWeight="SemiBold" />
                    <TextBlock x:Name="EventNameText" Text="Event: —" TextWrapping="Wrap" />
                    <TextBlock x:Name="BaseUrlText" Text="Basis-URL: —" TextWrapping="Wrap" />
                    <TextBlock x:Name="VersionText" Text="App-Version: —" />
                    <TextBlock x:Name="ConnectExpiryText" Text="Verbindungscode: —" TextWrapping="Wrap" />
                    <TextBlock x:Name="FolderHealthText" Text="Ordner: —" TextWrapping="Wrap" />
                    <TextBlock x:Name="DiskFreeText" Text="Freier Speicher: —" TextWrapping="Wrap" />
                    <TextBlock x:Name="LastSeenText" Text="Letzte Datei: —" TextWrapping="Wrap" />
                    <TextBlock x:Name="LastErrorText" Text="Letzter Fehler: —" TextWrapping="Wrap" />
                    <Button x:Name="LogCopyButton" Content="Log kopieren" Click="LogCopyButton_Click" Classes="secondary" />
                </StackPanel>
            </Border>

            <Border Padding="14" Classes="card">
                <StackPanel Spacing="8">
                    <TextBlock Text="Letzte Uploads" FontWeight="SemiBold" />
                    <ItemsControl x:Name="RecentUploadsList" ItemsSource="{Binding RecentUploads}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Background="#14FFFFFF" Padding="10" CornerRadius="8" Margin="0,0,0,8">
                                    <Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,Auto">
                                        <TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding FileName}" />
                                        <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding StatusLabel}" />
                                        <TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding UpdatedLabel}" Opacity="0.7" FontSize="11" />
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <Button x:Name="RetryFailedButton" Content="Fehlgeschlagene erneut senden" Click="RetryFailedButton_Click" IsEnabled="False" Classes="secondary" />
                        <Button x:Name="ClearFailedButton" Content="Fehlerliste leeren" Click="ClearFailedButton_Click" IsEnabled="False" Classes="secondary" />
                    </StackPanel>
                </StackPanel>
            </Border>
            </StackPanel>
        </Grid>
    </Grid>
</Window>
