<UserControl x:Class="NebulaAuth.View.SetAccountPasswordsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:other="clr-namespace:NebulaAuth.ViewModel.Other"
             xmlns:nebulaAuth="clr-namespace:NebulaAuth"
             mc:Ignorable="d"
             d:DesignHeight="500" d:DesignWidth="400"
             d:DataContext="{d:DesignInstance other:SetAccountPasswordsVM}"
             d:Background="#141119"
             d:Foreground="White"
             FontFamily="{md:MaterialDesignFont}"
             MinHeight="500"
             MaxHeight="500"
             MinWidth="400"
             MaxWidth="400"
             Background="Transparent"
             FontSize="16">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- ===== HEADER ===== -->
        <Grid Margin="10,10,10,5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal">
                <md:PackIcon Kind="ShieldKey" Width="20" Height="20"
                             Margin="0,0,5,0" VerticalAlignment="Center"
                             Foreground="{DynamicResource PrimaryContentBrush}" />
                <TextBlock Text="{Tr SetAccountPasswordsView.Title}"
                           FontSize="18"
                           VerticalAlignment="Center"
                           Foreground="{DynamicResource BaseContentBrush}" />
            </StackPanel>

            <Button Grid.Column="1" Width="30" Height="30"
                    Style="{StaticResource MaterialDesignIconForegroundButton}"
                    HorizontalAlignment="Right"
                    Command="{x:Static md:DialogHost.CloseDialogCommand}"
                    IsCancel="True">
                <md:PackIcon Kind="Close" Width="24" Height="24" Foreground="IndianRed" />
            </Button>
        </Grid>

        <Separator Grid.Row="1" />

        <!-- ===== ENCRYPTION PASSWORD SECTION ===== -->
        <Grid Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <md:Card Margin="15,15,15,15" BorderThickness="1" BorderBrush="Gray" Padding="12">
                <StackPanel>
                    <TextBlock Text="{Tr SetAccountPasswordsView.EncryptionPassword}" FontSize="16"
                               Margin="0,0,0,5"
                               Foreground="{DynamicResource PrimaryContentBrush}" />

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <TextBox
                            md:HintAssist.Hint="{Tr SetAccountPasswordsView.EnterPassword}"
                            md:HintAssist.IsFloating="False"
                            Margin="0,0,10,0"
                            Text="{Binding EncryptionPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                        <Button Grid.Column="1" Command="{Binding SetEncryptionPasswordCommand}">
                            <md:PackIcon Kind="ContentSave" />
                        </Button>

                    </Grid>
                    <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                        <StackPanel.Resources>
                            <x:Array x:Key="BoolToIcon" Type="{x:Type md:PackIconKind}">
                                <md:PackIconKind>CheckBox</md:PackIconKind>
                                <md:PackIconKind>CloseBox</md:PackIconKind>
                            </x:Array>
                            <x:Array x:Key="BoolToColor" Type="{x:Type SolidColorBrush}">
                                <SolidColorBrush Color="{DynamicResource SuccessColor}" />
                                <SolidColorBrush Color="{DynamicResource ErrorColor}" />
                            </x:Array>

                        </StackPanel.Resources>
                        <TextBlock Text="{Tr SetAccountPasswordsView.Status}" VerticalAlignment="Center" />
                        <md:PackIcon Width="20" Height="20"
                                     VerticalAlignment="Center"
                                     Foreground="{Binding IsEncryptionPasswordSet, Converter={StaticResource BoolToValueConverter}, ConverterParameter={StaticResource BoolToColor}}"
                                     Kind="{Binding IsEncryptionPasswordSet, Converter={StaticResource BoolToValueConverter}, ConverterParameter={StaticResource BoolToIcon}}" />
                    </StackPanel>
                </StackPanel>
            </md:Card>
        </Grid>


        <!-- ===== ACCOUNTS INPUT ===== -->
        <TextBox Grid.Row="3"
                 Margin="15,0,15,10"
                 Text="{Binding AccountsPasswords, UpdateSourceTrigger=PropertyChanged}"
                 FontSize="13"
                 AcceptsReturn="True"

                 VerticalScrollBarVisibility="Auto"
                 Style="{StaticResource MaterialDesignOutlinedTextBox}"
                 md:TextFieldAssist.HasClearButton="True"
                 md:HintAssist.IsFloating="False"
                 md:HintAssist.Hint="{Tr SetAccountPasswordsView.InputFormat}"
                 md:TextFieldAssist.TextBoxIsMultiLine="True"
                 md:TextFieldAssist.TextBoxViewVerticalAlignment="Top"
                 VerticalContentAlignment="Top" />
        <!-- ===== INFO TEXT ===== -->
        <TextBlock Grid.Row="4"
                   Margin="20,0,20,15"
                   TextWrapping="Wrap"
                   FontSize="12"
                   Foreground="{DynamicResource BaseContentBrush}"
                   Text="{Tr SetAccountPasswordsView.EncryptionHint}" />

        <Button Grid.Row="5"
                Margin="10,0,0,10"
                Width="120"
                Content="{Tr Common.Save}"
                Command="{Binding SetPasswordsCommand}"
                Style="{StaticResource MaterialDesignOutlinedButton}" Cursor="Hand" />

        <!-- ===== HINT / RESULT BOX ===== -->
        <nebulaAuth:HintBox Grid.Row="6"
                            Margin="15,0,15,10"
                            Visibility="{Binding Tip, Converter={StaticResource NullableToVisibilityConverter}}"
                            CloseCommand="{Binding ClearTipCommand}"
                            Text="{Binding Tip}"
                            FontSize="13"
                            Severity="Info"
                            ShowCloseButton="True" />
    </Grid>

</UserControl>