<ContentDialog
    x:Class="AppControlManager.CustomUIElements.SigningDetailsDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AppControlManager.CustomUIElements"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="using:CommunityToolkit.WinUI"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    mc:Ignorable="d"
    Title="Signing Details"
    PrimaryButtonText="Submit"
    CloseButtonText="Cancel"
    IsPrimaryButtonEnabled="False"
    DefaultButton="Primary"
    BorderThickness="1"
    CornerRadius="8"
    Style="{ThemeResource DefaultContentDialogStyle}"
    BorderBrush="{ThemeResource AccentFillColorDefaultBrush}">

    <ContentDialog.Resources>
        <!--  These styles can be referenced to create a consistent SettingsPage layout  -->

        <!--  Spacing between cards  -->
        <x:Double x:Key="SettingsCardSpacing">4</x:Double>

        <!--  Style (inc. the correct spacing) of a section header  -->
        <Style x:Key="SettingsSectionHeaderTextBlockStyle"
     BasedOn="{StaticResource BodyStrongTextBlockStyle}"
     TargetType="TextBlock">
            <Style.Setters>
                <Setter Property="Margin" Value="1,30,0,6" />
            </Style.Setters>
        </Style>

        <!-- https://github.com/microsoft/microsoft-ui-xaml/issues/424 -->
        <x:Double x:Key="ContentDialogMaxWidth">2000</x:Double>
    </ContentDialog.Resources>

    <ScrollView>

        <Grid>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <TextBlock IsTextSelectionEnabled="True" Grid.Row="0" TextWrapping="Wrap" VerticalAlignment="Top" Text="Please provide the required details that will be used to sign the XML App Control Policies." />

            <InfoBar
                Margin="15"
                Grid.Row="1"
                BorderThickness="0"
                CornerRadius="0"
                IsIconVisible="True"
                IsOpen="True"
                IsClosable="False"
                Message="You can configure the following details in the app settings once, eliminating the need to enter them repeatedly"
                Severity="Informational">
                <InfoBar.ActionButton>
                    <Button Content="Go to Settings" Click="OpenAppSettingsButton_Click" />
                </InfoBar.ActionButton>
            </InfoBar>


            <StackPanel HorizontalAlignment="Stretch"
            Spacing="{StaticResource SettingsCardSpacing}" Grid.Row="2">

                <win:StackPanel.ChildrenTransitions>
                    <win:EntranceThemeTransition FromVerticalOffset="50" />
                    <win:RepositionThemeTransition IsStaggeringEnabled="False" />
                </win:StackPanel.ChildrenTransitions>


                <controls:SettingsCard Header="Certificate File"
                 Description="Its details will be added to the policy file"
                 HeaderIcon="{ui:FontIcon Glyph=&#xEA86;}">

                    <controls:WrapPanel Orientation="Vertical" VerticalSpacing="10" HorizontalSpacing="10">

                        <Button x:Name="CertFileBrowseButton" HorizontalAlignment="Center" Click="CertFileBrowseButton_Click" Content="Browse"/>
                        <TextBox MaxWidth="700" x:Name="CertFilePathTextBox" TextWrapping="Wrap" PlaceholderText=".cer file path" />

                    </controls:WrapPanel>

                </controls:SettingsCard>

                <controls:SettingsCard Header="Certificate Common Name"
                 Description="Used during the signing operation"                      
                 HeaderIcon="{ui:FontIcon Glyph=&#xEA86;}">

                    <controls:WrapPanel Orientation="Vertical" HorizontalSpacing="10" VerticalSpacing="10">

                        <AutoSuggestBox x:Name="CertificateCommonNameAutoSuggestBox"
                           MaxWidth="700"
                            QueryIcon="Find"
                            GotFocus="CertificateCommonNameAutoSuggestBox_GotFocus"
                            TextChanged="CertificateCNAutoSuggestBox_TextChanged"
                            PlaceholderText="Find Certificate Common Names"/>

                    </controls:WrapPanel>

                </controls:SettingsCard>



                <controls:SettingsCard Header="SignTool Path"
                Description="Used to sign the policy CIP file"
                HeaderIcon="{ui:FontIcon Glyph=&#xEA86;}">

                    <controls:WrapPanel VerticalSpacing="10" HorizontalSpacing="10" Orientation="Vertical">

                        <StackPanel Orientation="Horizontal" Spacing="10" HorizontalAlignment="Center" Margin="0,0,0,5" ToolTipService.ToolTip="Automatically downloads the signtool.exe from Microsoft servers">
                            <ToggleSwitch x:Name="AutoAcquireSignTool" Toggled="AutoAcquireSignTool_Toggled" />
                            <TextBlock Text="Auto Acquire" Margin="0,8.7,0,0" />
                        </StackPanel>

                        <Button x:Name="SignToolBrowseButton" Click="SignToolBrowseButton_Click" HorizontalAlignment="Center" Content="Browse"/>
                        <TextBox MaxWidth="700" x:Name="SignToolPathTextBox" PlaceholderText="SignTool.exe Path" TextWrapping="Wrap"/>

                    </controls:WrapPanel>


                </controls:SettingsCard>


            </StackPanel>

            <controls:WrapPanel Grid.Row="3" Orientation="Vertical" HorizontalSpacing="10" VerticalSpacing="10" Margin="10,15,10,0" HorizontalAlignment="Center">

                <Button HorizontalAlignment="Center" ToolTipService.ToolTip="Verify the settings before submitting them"
            Click="VerifyButton_Click"
            x:Name="VerifyButton">

                    <Button.Content>
                        <StackPanel Orientation="Horizontal" Padding="10,5,10,5">
                            <ProgressRing VerticalAlignment="Center" x:Name="VerifyButtonProgressRing" Margin="0,0,10,0" Visibility="Collapsed" IsIndeterminate="True"/>
                            <TextBlock x:Name="VerifyButtonContentTextBlock" VerticalAlignment="Center" FontWeight="SemiBold" Text="Verify"/>
                        </StackPanel>
                    </Button.Content>
                    
                </Button>


                <TeachingTip x:Name="VerifyButtonTeachingTip"
                            Target="{x:Bind VerifyButton}"
                            Title="Error">
                </TeachingTip>

            </controls:WrapPanel>

        </Grid>

    </ScrollView>



</ContentDialog>
