<UserControl x:Class="UniGetUI.Avalonia.Views.Pages.SettingsPages.Administrator"
             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:AdministratorViewModel">

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

            <!-- Warning banner -->
            <Border Classes="warning-banner"
                    CornerRadius="8"
                    Padding="12,10">
                <Grid ColumnDefinitions="Auto,*">
                    <!-- Icon -->
                    <Border Grid.Column="0"
                            Width="26" Height="26"
                            CornerRadius="13"
                            Background="{DynamicResource WarningBannerIconBackground}"
                            VerticalAlignment="Top"
                            Margin="0,1,12,0">
                        <TextBlock Text="!"
                                   FontWeight="Bold"
                                   FontSize="15"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"/>
                    </Border>
                    <!-- Text -->
                    <StackPanel Grid.Column="1" Orientation="Vertical">
                        <TextBlock Text="{Binding WarningTitle}"
                                   FontWeight="SemiBold"
                                   FontSize="14"
                                   TextWrapping="Wrap"
                                   Margin="0,0,0,4"/>
                        <TextBlock Text="{Binding WarningBody1}"
                                   FontSize="14"
                                   TextWrapping="Wrap"
                                   Foreground="{DynamicResource WarningBannerSubtext}"
                                   Margin="0,0,0,6"/>
                        <TextBlock Text="{Binding WarningBody2}"
                                   FontSize="14"
                                   TextWrapping="Wrap"
                                   Foreground="{DynamicResource WarningBannerSubtext}"/>
                    </StackPanel>
                </Grid>
            </Border>

            <!-- Elevation settings (Windows-only) -->
            <StackPanel Orientation="Vertical" IsVisible="{Binding IsWindows}">
                <settings:TranslatedTextBlock Text="Change how operations request administrator rights"
                                              FontSize="14"
                                              FontWeight="SemiBold"
                                              Margin="44,32,4,8"
                                          automation:AutomationProperties.HeadingLevel="2"/>

                <settings:CheckboxCard x:Name="AdminElevationCard"
                                       SettingName="DoCacheAdminRightsForBatches"
                                       Text="{t:Translate Ask for administrator privileges once for each batch of operations}"
                                       StateChangedCommand="{Binding RestartCacheCommand}"
                                       BorderThickness="1,1,1,0"
                                       CornerRadius="8,8,0,0"
                                       IsEnabled="{Binding IsElevationEnabled}"/>

                <settings:CheckboxCard x:Name="CacheAdminOnceCard"
                                       SettingName="DoCacheAdminRights"
                                       Text="{t:Translate Ask only once for administrator privileges}"
                                       StateChangedCommand="{Binding RestartCacheCommand}"
                                       CornerRadius="0,0,8,8"
                                       IsEnabled="{Binding IsElevationEnabled}"/>

                <UserControl Height="16"/>

                <settings:CheckboxCard x:Name="ProhibitElevationCard"
                                       SettingName="ProhibitElevation"
                                       Text="{t:Translate Prohibit any kind of Elevation via UniGetUI Elevator or GSudo}"
                                       WarningText="{t:Translate Text='This option WILL cause issues. Any operation incapable of elevating itself WILL FAIL. Install/update/uninstall as administrator will NOT WORK.'}"
                                       StateChangedCommand="{Binding RefreshElevationStateCommand}"
                                       CornerRadius="8"/>

                <UserControl Height="16"/>

                <settings:CheckboxCard x:Name="UseAgentBrokerCard"
                                       SettingName="UseAgentBroker"
                                       Text="{t:Translate Delegate package operations to the Devolutions Agent broker}"
                                       WarningText="{t:Translate Text='When enabled, install, update and uninstall operations for supported package managers will be performed by the Devolutions Agent service instead of requesting UAC elevation. Operations will fail unless the agent is installed and running.'}"
                                       CornerRadius="8"/>
            </StackPanel>

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

            <settings:SecureCheckboxCard x:Name="AdminRestrictionsOpsCard"
                                         SettingName="AllowCLIArguments"
                                         Text="{t:Translate Allow custom command-line arguments}"
                                         WarningText="{t:Translate Text='Custom command-line arguments can change the way in which programs are installed, upgraded or uninstalled, in a way UniGetUI cannot control. Using custom command-lines can break packages. Proceed with caution.'}"
                                         StateChangedCommand="{Binding RefreshCLIStateCommand}"
                                         CornerRadius="8,8,0,0"/>

            <settings:SecureCheckboxCard x:Name="PrePostCommandCard"
                                         SettingName="AllowPrePostOpCommand"
                                         Text="{t:Translate Text='Ignore custom pre-install and post-install commands when importing packages from a bundle'}"
                                         WarningText="{t:Translate Text='Pre and post install commands will be run before and after a package gets installed, upgraded or uninstalled. Be aware that they may break things unless used carefully'}"
                                         StateChangedCommand="{Binding RefreshPrePostStateCommand}"
                                         BorderThickness="1,0,1,1"
                                         CornerRadius="0,0,8,8"/>

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

            <settings:SecureCheckboxCard x:Name="AdminManagerPathsCard"
                                         SettingName="AllowCustomManagerPaths"
                                         Text="{t:Translate Allow changing the paths for package manager executables}"
                                         WarningText="{t:Translate Text='Turning this on enables changing the executable file used to interact with package managers. While this allows finer-grained customization of your install processes, it may also be dangerous'}"
                                         StateChangedCommand="{Binding ShowRestartRequiredCommand}"
                                         CornerRadius="8"/>

            <settings:TranslatedTextBlock Text="Restrictions when importing package bundles"
                                          FontSize="14"
                                          FontWeight="SemiBold"
                                          Margin="44,32,4,8"
                                          automation:AutomationProperties.HeadingLevel="2"/>

            <settings:SecureCheckboxCard x:Name="ImportCLIArgsCard"
                                         SettingName="AllowImportingCLIArguments"
                                         Text="{t:Translate Allow importing custom command-line arguments when importing packages from a bundle}"
                                         WarningText="{t:Translate Text='Malformed command-line arguments can break packages, or even allow a malicious actor to gain privileged execution. Therefore, importing custom command-line arguments is disabled by default'}"
                                         IsEnabled="{Binding IsCLIArgumentsEnabled}"
                                         CornerRadius="8,8,0,0"/>

            <settings:SecureCheckboxCard x:Name="ImportPrePostCard"
                                         SettingName="AllowImportPrePostOpCommands"
                                         Text="{t:Translate Allow importing custom pre-install and post-install commands when importing packages from a bundle}"
                                         WarningText="{t:Translate Text='Pre and post install commands can do very nasty things to your device, if designed to do so. It can be very dangerous to import the commands from a bundle, unless you trust the source of that package bundle'}"
                                         IsEnabled="{Binding IsPrePostCommandsEnabled}"
                                         BorderThickness="1,0,1,1"
                                         CornerRadius="0,0,8,8"/>

        </StackPanel>
    </ScrollViewer>

</UserControl>
