<abstract:SignatureAndEncryptionPageAbstract
    x:Class="Wino.Views.Settings.SignatureAndEncryptionPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:abstract="using:Wino.Views.Abstract"
    xmlns:crypt="using:System.Security.Cryptography.X509Certificates"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:domain="using:Wino.Core.Domain"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <ScrollViewer>
        <StackPanel Spacing="{StaticResource SettingsCardSpacing}">
            <StackPanel.ChildrenTransitions>
                <TransitionCollection>
                    <RepositionThemeTransition IsStaggeringEnabled="False" />
                </TransitionCollection>
            </StackPanel.ChildrenTransitions>
            <controls:SettingsExpander
                Description="{x:Bind domain:Translator.SettingsSignatureAndEncryption_MyCertificatesDescription, Mode=OneTime}"
                Header="{x:Bind domain:Translator.SettingsSignatureAndEncryption_MyCertificatesHeader, Mode=OneTime}"
                IsExpanded="True">
                <controls:SettingsExpander.Items>
                    <controls:SettingsCard>
                        <!--TODO: Not working
                        <TextBlock Visibility="{Binding ViewModel.PersonalCertificatesEmpty, Mode=OneWay}">
                            <Run Text="There are no items." />
                        </TextBlock>-->

                        <ListView
                            x:Name="PersonalCertList"
                            MaxHeight="180"
                            ItemsSource="{x:Bind ViewModel.PersonalCertificates, Mode=OneWay}"
                            SelectionChanged="PersonalCertList_SelectionChanged"
                            SelectionMode="Multiple">
                            <ListView.Header>
                                <Grid Padding="16,12" ColumnSpacing="16">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="26" />
                                        <ColumnDefinition Width="300" />
                                        <ColumnDefinition Width="120" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock
                                        Grid.Column="1"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{x:Bind domain:Translator.SettingsSignatureAndEncryption_NameColumn, Mode=OneTime}" />
                                    <TextBlock
                                        Grid.Column="2"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{x:Bind domain:Translator.SettingsSignatureAndEncryption_ExpiresColumn, Mode=OneTime}" />
                                    <TextBlock
                                        Grid.Column="3"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{x:Bind domain:Translator.SettingsSignatureAndEncryption_ThumbprintColumn, Mode=OneTime}" />
                                </Grid>
                            </ListView.Header>
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="crypt:X509Certificate2">
                                    <Grid ColumnSpacing="16">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="0" />
                                            <ColumnDefinition Width="300" />
                                            <ColumnDefinition Width="120" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="1" Text="{x:Bind Subject}" />
                                        <TextBlock
                                            Grid.Column="2"
                                            FontSize="10"
                                            Foreground="Gray"
                                            Text="{x:Bind NotAfter}" />
                                        <TextBlock
                                            Grid.Column="3"
                                            FontSize="10"
                                            Foreground="Gray"
                                            Text="{x:Bind Thumbprint}" />
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>

                            <ListView.ItemContainerStyle>
                                <Style BasedOn="{StaticResource DefaultListViewItemStyle}" TargetType="ListViewItem">
                                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                </Style>
                            </ListView.ItemContainerStyle>
                        </ListView>
                    </controls:SettingsCard>
                    <controls:SettingsCard>
                        <StackPanel Orientation="Horizontal" Spacing="12">
                            <Button Command="{x:Bind ViewModel.RemovePersonalCertificatesCommand}" Content="{x:Bind domain:Translator.Buttons_Remove}" />
                            <Button Command="{x:Bind ViewModel.ExportPersonalCertificatesCommand}" Content="{x:Bind domain:Translator.Buttons_Export}" />
                            <Button Command="{x:Bind ViewModel.ImportPersonalCertificatesCommand}" Content="{x:Bind domain:Translator.Buttons_Import}" />
                        </StackPanel>
                    </controls:SettingsCard>
                </controls:SettingsExpander.Items>
            </controls:SettingsExpander>
            <controls:SettingsExpander
                Description="{x:Bind domain:Translator.SettingsSignatureAndEncryption_RecipientCertificatesDescription, Mode=OneTime}"
                Header="{x:Bind domain:Translator.SettingsSignatureAndEncryption_RecipientCertificatesHeader, Mode=OneTime}"
                IsExpanded="False">
                <controls:SettingsExpander.Items>
                    <!--<StackPanel Padding="12" Spacing="12">-->

                    <!--TODO: Not working
                     <TextBlock Visibility="{Binding ViewModel.RecipientCertificatesEmpty, Mode=OneWay}">
                         <Run Text="There are no items." />
                     </TextBlock>-->

                    <controls:SettingsCard>
                        <ListView
                            x:Name="RecipientCertList"
                            Height="180"
                            ItemsSource="{x:Bind ViewModel.RecipientCertificates, Mode=OneWay}"
                            SelectionChanged="RecipientCertList_SelectionChanged"
                            SelectionMode="Multiple">
                            <ListView.Header>
                                <Grid Padding="16,12" ColumnSpacing="16">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="26" />
                                        <ColumnDefinition Width="300" />
                                        <ColumnDefinition Width="120" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock
                                        Grid.Column="1"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{x:Bind domain:Translator.SettingsSignatureAndEncryption_NameColumn, Mode=OneTime}" />
                                    <TextBlock
                                        Grid.Column="2"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{x:Bind domain:Translator.SettingsSignatureAndEncryption_ExpiresColumn, Mode=OneTime}" />
                                    <TextBlock
                                        Grid.Column="3"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{x:Bind domain:Translator.SettingsSignatureAndEncryption_ThumbprintColumn, Mode=OneTime}" />
                                </Grid>
                            </ListView.Header>
                            <ListView.ItemTemplate>
                                <DataTemplate x:DataType="crypt:X509Certificate2">
                                    <Grid ColumnSpacing="16">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="0" />
                                            <ColumnDefinition Width="300" />
                                            <ColumnDefinition Width="120" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="1" Text="{x:Bind Subject}" />
                                        <TextBlock
                                            Grid.Column="2"
                                            FontSize="10"
                                            Foreground="Gray"
                                            Text="{x:Bind NotAfter}" />
                                        <TextBlock
                                            Grid.Column="3"
                                            FontSize="10"
                                            Foreground="Gray"
                                            Text="{x:Bind Thumbprint}" />
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>

                            <ListView.ItemContainerStyle>
                                <Style BasedOn="{StaticResource DefaultListViewItemStyle}" TargetType="ListViewItem">
                                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                </Style>
                            </ListView.ItemContainerStyle>
                        </ListView>
                    </controls:SettingsCard>
                    <controls:SettingsCard>
                        <StackPanel
                            HorizontalAlignment="Right"
                            Orientation="Horizontal"
                            Spacing="12">
                            <Button Command="{x:Bind ViewModel.RemoveRecipientCertificatesCommand}" Content="{x:Bind domain:Translator.Buttons_Remove}" />
                            <Button Command="{x:Bind ViewModel.ExportRecipientCertificatesCommand}" Content="{x:Bind domain:Translator.Buttons_Export}" />
                            <Button Command="{x:Bind ViewModel.ImportRecipientCertificatesCommand}" Content="{x:Bind domain:Translator.Buttons_Import}" />
                        </StackPanel>
                    </controls:SettingsCard>
                </controls:SettingsExpander.Items>
            </controls:SettingsExpander>
        </StackPanel>
    </ScrollViewer>
</abstract:SignatureAndEncryptionPageAbstract>
