<UserControl x:Class="UniGetUI.Avalonia.Views.Pages.SettingsPages.Backup"
             xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:automation="clr-namespace:Avalonia.Automation;assembly=Avalonia.Controls"
             xmlns:vm="using:UniGetUI.Avalonia.ViewModels.Pages.SettingsPages"
             xmlns:settings="using:UniGetUI.Avalonia.Views.Controls.Settings"
             xmlns:t="using:UniGetUI.Avalonia.MarkupExtensions"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:DataType="vm:BackupViewModel">

    <ScrollViewer HorizontalScrollBarVisibility="Disabled">
        <StackPanel Orientation="Vertical">

            <settings:TranslatedTextBlock Text="Package backup"
                                          FontSize="14"
                                          FontWeight="SemiBold"
                                          Margin="44,32,4,8"
                                          automation:AutomationProperties.HeadingLevel="2"/>

            <settings:SettingsCard CornerRadius="8">
                <settings:SettingsCard.Description>
                    <ItemsControl ItemsSource="{Binding InfoLines}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate x:DataType="x:String">
                                <TextBlock Text="{Binding}" FontSize="14" TextWrapping="Wrap"/>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </settings:SettingsCard.Description>
            </settings:SettingsCard>

            <!-- ── Cloud package backup ── -->
            <settings:TranslatedTextBlock Text="Cloud package backup"
                                          FontSize="16"
                                          FontWeight="SemiBold"
                                          Margin="44,32,4,8"
                                          automation:AutomationProperties.HeadingLevel="2"/>

            <!-- GitHub identity card -->
            <Border BorderBrush="{DynamicResource AppBorderBrush}"
                    BorderThickness="1"
                    CornerRadius="8,8,0,0"
                    Padding="16,12"
                    Margin="40,0,40,0"
                    Background="{DynamicResource SettingsCardBackground}">
                <Grid ColumnDefinitions="Auto,*,Auto,Auto" ColumnSpacing="12">

                    <!-- Avatar (circular clip) -->
                    <Border Width="40" Height="40"
                            CornerRadius="20"
                            ClipToBounds="True"
                            VerticalAlignment="Center">
                        <Panel>
                            <Border Background="{DynamicResource SystemControlBackgroundBaseLowBrush}"/>
                            <Image Source="{Binding GitHubAvatarBitmap}"
                                   Stretch="UniformToFill"/>
                        </Panel>
                    </Border>

                    <StackPanel Grid.Column="1" Orientation="Vertical" Spacing="2" VerticalAlignment="Center">
                        <TextBlock Text="{Binding GitHubUserTitle}"
                                   FontSize="14"
                                   FontWeight="SemiBold"
                                   TextWrapping="Wrap"/>
                        <TextBlock Text="{Binding GitHubUserSubtitle}"
                                   FontSize="12"
                                   Opacity="0.8"
                                   TextWrapping="Wrap"/>
                    </StackPanel>

                    <!-- Log in button (shown when not logged in) -->
                    <Button Grid.Column="2"
                            Classes="accent"
                            IsVisible="{Binding !IsLoggedIn}"
                            IsEnabled="{Binding IsLoginButtonEnabled}"
                            Command="{Binding LoginCommand}"
                            VerticalAlignment="Center"
                            automation:AutomationProperties.Name="{t:Translate Log in with GitHub}"
                            Content="{t:Translate Log in with GitHub}"/>

                    <!-- Log out button (shown when logged in) -->
                    <Button Grid.Column="2"
                            IsVisible="{Binding IsLoggedIn}"
                            IsEnabled="{Binding IsLoginButtonEnabled}"
                            Command="{Binding LogoutCommand}"
                            VerticalAlignment="Center"
                            automation:AutomationProperties.Name="{t:Translate Log out from GitHub}"
                            Content="{t:Translate Log out from GitHub}"/>

                    <!-- More details -->
                    <Button Grid.Column="3"
                            Command="{Binding MoreDetailsCommand}"
                            VerticalAlignment="Center"
                            automation:AutomationProperties.Name="{t:Translate More details}"
                            Background="Transparent"
                            BorderThickness="0"
                            Padding="0">
                        <TextBlock Classes="hyperlink"
                                   FontSize="14"
                                   Text="{t:Translate More details}"
                                   automation:AutomationProperties.AccessibilityView="Raw"/>
                    </Button>

                </Grid>
            </Border>

            <!-- Enable cloud backup checkbox -->
            <settings:CheckboxCard x:Name="CloudBackupCard"
                                   SettingName="EnablePackageBackup_CLOUD"
                                   Text="{t:Translate Periodically perform a cloud backup of the installed packages}"
                                   WarningText="{t:Translate Cloud backup uses a private GitHub Gist to store a list of installed packages}"
                                   StateChangedCommand="{Binding EnableCloudBackupChangedCommand}"
                                   IsEnabled="{Binding IsCloudControlsEnabled}"
                                   BorderThickness="1,0,1,1"
                                   CornerRadius="0,0,8,8"/>

            <Border Height="16"/>

            <!-- Cloud backup now -->
            <settings:ButtonCard x:Name="CloudBackupNowCard"
                                 CornerRadius="8,8,0,0"
                                 Text="{t:Translate Perform a cloud backup now}"
                                 ButtonText="{t:Translate Backup}"
                                 IsEnabled="{Binding IsCloudBackupNowEnabled}"
                                 Command="{Binding DoCloudBackupCommand}"
                                 CommandParameter="{Binding $self}"/>

            <!-- Restore from cloud -->
            <settings:ButtonCard x:Name="RestoreCloudCard"
                                 CornerRadius="0,0,8,8"
                                 BorderThickness="1,0,1,1"
                                 Text="{t:Translate Restore a backup from the cloud}"
                                 Description="{t:Translate Begin the process to select a cloud backup and review which packages to restore}"
                                 ButtonText="{t:Translate Select backup}"
                                 IsEnabled="{Binding IsCloudControlsEnabled}"
                                 Command="{Binding RestoreFromCloudCommand}"
                                 CommandParameter="{Binding $self}"/>

            <!-- ── Local package backup ── -->

            <settings:TranslatedTextBlock Text="Local package backup"
                                          FontSize="16"
                                          FontWeight="SemiBold"
                                          Margin="44,32,4,8"
                                          automation:AutomationProperties.HeadingLevel="2"/>

            <settings:CheckboxCard x:Name="LocalBackupCard"
                                   SettingName="EnablePackageBackup_LOCAL"
                                   Text="{t:Translate Periodically perform a local backup of the installed packages}"
                                   StateChangedCommand="{Binding EnableLocalBackupChangedCommand}"
                                   CornerRadius="8,8,0,0"/>

            <settings:ButtonCard x:Name="BackupNowButton_LOCAL"
                                 CornerRadius="0,0,8,8"
                                 BorderThickness="1,0,1,1"
                                 Text="{t:Translate Perform a local backup now}"
                                 ButtonText="{t:Translate Backup}"
                                 IsEnabled="{Binding IsLocalBackupEnabled}"
                                 Command="{Binding DoLocalBackupCommand}"
                                 CommandParameter="{Binding $self}"/>

            <Border Height="16"/>

            <settings:ButtonCard x:Name="BackupDirectoryCard"
                                 CornerRadius="8"
                                 Text="{t:Translate Change backup output directory}"
                                 Description="{Binding BackupDirectoryLabel}"
                                 ButtonText="{t:Translate Select}"
                                 IsEnabled="{Binding IsLocalBackupEnabled}"
                                 Command="{Binding PickBackupDirectoryCommand}"
                                 CommandParameter="{Binding $self}"/>

            <settings:TranslatedTextBlock Text="Local backup advanced options"
                                          FontSize="14"
                                          FontWeight="SemiBold"
                                          Margin="44,32,4,8"
                                          automation:AutomationProperties.HeadingLevel="2"/>

            <settings:TextboxCard x:Name="BackupFileNameCard"
                                  SettingName="ChangeBackupFileName"
                                  Text="{t:Translate Set a custom backup file name}"
                                  Placeholder="{t:Translate Leave empty for default}"
                                  CornerRadius="8,8,0,0"
                                  IsEnabled="{Binding IsLocalBackupEnabled}"/>

            <settings:CheckboxCard x:Name="BackupTimestampCard"
                                   SettingName="EnableBackupTimestamping"
                                   Text="{t:Translate Add a timestamp to the backup file names}"
                                   CornerRadius="0,0,8,8"
                                   BorderThickness="1,0,1,1"
                                   IsEnabled="{Binding IsLocalBackupEnabled}"/>

        </StackPanel>
    </ScrollViewer>

</UserControl>
