<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"
        xmlns:viewModels="clr-namespace:Jellyfin2Samsung.ViewModels"
        mc:Ignorable="d"
        d:DesignWidth="480"
        d:DesignHeight="420"
        x:Class="Jellyfin2Samsung.Views.UpdateDialog"
        x:DataType="viewModels:UpdateDialogViewModel"
        Width="480"
        MinHeight="360"
        SizeToContent="Height"
        Title="{Binding DialogTitle}"
        WindowStartupLocation="CenterOwner"
        CanResize="False"
        CornerRadius="12">

    <Window.Styles>
        <StyleInclude Source="avares://Avalonia.Themes.Fluent/FluentTheme.xaml"/>
    </Window.Styles>

    <Border Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
            Padding="24"
            CornerRadius="12"
            Margin="10"
            BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
            BorderThickness="1">
        <Border.Effect>
            <DropShadowEffect BlurRadius="20"
                              OffsetX="2"
                              OffsetY="2"
                              Color="#00000020"
                              Opacity="0.2"/>
        </Border.Effect>

        <StackPanel Spacing="16">

            <!-- Header with Icon -->
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Center"
                        Spacing="12">
                <PathIcon Data="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
                          Width="28"
                          Height="28"
                          Foreground="#22c55e"/>
                <TextBlock Text="{Binding DialogTitle}"
                           FontSize="20"
                           FontWeight="Bold"
                           Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}"
                           VerticalAlignment="Center"/>
            </StackPanel>

            <!-- Version Info -->
            <Border Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}"
                    CornerRadius="8"
                    Padding="16">
                <Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto,Auto" RowSpacing="8" ColumnSpacing="12">

                    <!-- Current Version -->
                    <TextBlock Grid.Row="0" Grid.Column="0"
                               Text="{Binding CurrentVersionLabel}"
                               FontWeight="SemiBold"
                               Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
                               VerticalAlignment="Center"/>
                    <TextBlock Grid.Row="0" Grid.Column="1"
                               Text="{Binding CurrentVersion}"
                               Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}"
                               VerticalAlignment="Center"/>

                    <!-- Latest Version -->
                    <TextBlock Grid.Row="1" Grid.Column="0"
                               Text="{Binding LatestVersionLabel}"
                               FontWeight="SemiBold"
                               Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
                               VerticalAlignment="Center"/>
                    <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Spacing="8">
                        <TextBlock Text="{Binding LatestVersion}"
                                   Foreground="#22c55e"
                                   FontWeight="Bold"
                                   VerticalAlignment="Center"/>
                        <Border Background="#22c55e"
                                CornerRadius="4"
                                Padding="6,2">
                            <TextBlock Text="NEW"
                                       FontSize="10"
                                       FontWeight="Bold"
                                       Foreground="White"/>
                        </Border>
                    </StackPanel>

                    <!-- Release Title -->
                    <TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
                               Text="{Binding ReleaseTitle}"
                               FontSize="13"
                               FontStyle="Italic"
                               Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
                               TextTrimming="CharacterEllipsis"
                               IsVisible="{Binding ReleaseTitle, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
                </Grid>
            </Border>

            <!-- Release Notes -->
            <StackPanel Spacing="8"
                        IsVisible="{Binding ReleaseNotes, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
                <TextBlock Text="{Binding ReleaseNotesLabel}"
                           FontWeight="SemiBold"
                           FontSize="13"
                           Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"/>
                <ScrollViewer MaxHeight="120"
                              HorizontalScrollBarVisibility="Disabled"
                              VerticalScrollBarVisibility="Auto">
                    <TextBlock Text="{Binding ReleaseNotes}"
                               TextWrapping="Wrap"
                               FontSize="12"
                               Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}"
                               LineHeight="18"/>
                </ScrollViewer>
            </StackPanel>

            <!-- Download Progress (shown during download) -->
            <StackPanel Spacing="8" IsVisible="{Binding IsDownloading}">
                <TextBlock Text="{Binding DownloadStatus}"
                           FontSize="13"
                           Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
                           HorizontalAlignment="Center"/>
                <ProgressBar Value="{Binding DownloadProgress}"
                             Minimum="0"
                             Maximum="100"
                             Height="8"
                             CornerRadius="4"
                             Foreground="#2563eb"/>
                <TextBlock Text="{Binding DownloadProgress, StringFormat={}{0}%}"
                           FontSize="12"
                           Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
                           HorizontalAlignment="Center"/>
            </StackPanel>

            <!-- Buttons -->
            <StackPanel Spacing="12" IsVisible="{Binding !IsDownloading}">

                <!-- Primary Actions -->
                <StackPanel Orientation="Horizontal"
                            HorizontalAlignment="Center"
                            Spacing="12">

                    <!-- Manual Button -->
                    <Button MinWidth="140"
                            Height="40"
                            Background="#6366f1"
                            Foreground="White"
                            CornerRadius="8"
                            HorizontalContentAlignment="Center"
                            VerticalContentAlignment="Center"
                            Command="{Binding SelectManualCommand}">
                        <StackPanel Orientation="Horizontal" Spacing="8">
                            <PathIcon Data="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z"
                                      Width="16"
                                      Height="16"
                                      Foreground="White"/>
                            <TextBlock Text="{Binding ManualButtonText}"
                                       VerticalAlignment="Center"/>
                        </StackPanel>
                    </Button>

                    <!-- Automatic Button -->
                    <Button MinWidth="140"
                            Height="40"
                            Background="#22c55e"
                            Foreground="White"
                            CornerRadius="8"
                            HorizontalContentAlignment="Center"
                            VerticalContentAlignment="Center"
                            Command="{Binding SelectAutomaticCommand}"
                            IsEnabled="{Binding HasDownloadUrl}">
                        <StackPanel Orientation="Horizontal" Spacing="8">
                            <PathIcon Data="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"
                                      Width="16"
                                      Height="16"
                                      Foreground="White"/>
                            <TextBlock Text="{Binding AutomaticButtonText}"
                                       VerticalAlignment="Center"/>
                        </StackPanel>
                    </Button>
                </StackPanel>

                <!-- Skip Button -->
                <Button HorizontalAlignment="Center"
                        MinWidth="100"
                        Height="32"
                        Background="Transparent"
                        Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
                        BorderThickness="0"
                        Command="{Binding SelectSkipCommand}">
                    <TextBlock Text="{Binding SkipButtonText}"
                               FontSize="12"
                               TextDecorations="Underline"/>
                </Button>
            </StackPanel>

            <!-- Tooltip for disabled automatic button -->
            <TextBlock Text="(Automatic download unavailable - GitHub API rate limited)"
                       FontSize="11"
                       FontStyle="Italic"
                       Foreground="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
                       HorizontalAlignment="Center"
                       IsVisible="{Binding !HasDownloadUrl}"/>

        </StackPanel>
    </Border>
</Window>
