<?xml version="1.0" encoding="utf-8"?>
<pages:BaseContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Bit.App.Pages.ExportVaultPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    x:DataType="pages:ExportVaultPageViewModel"
    HideSoftInputOnTapped="True"
    Title="{Binding PageTitle}">

    <ContentPage.BindingContext>
        <pages:ExportVaultPageViewModel />
    </ContentPage.BindingContext>

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <u:UpperCaseConverter x:Key="toUpper" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n Cancel}" Clicked="Close_Clicked" />
    </ContentPage.ToolbarItems>

    <ScrollView>
        <StackLayout
            StyleClass="box"
            Spacing="20">
            <Frame
                IsVisible="{Binding DisablePrivateVaultPolicyEnabled}"
                Padding="10"
                Margin="0, 12, 0, 0"
                HasShadow="False"
                BackgroundColor="Transparent"
                BorderColor="{DynamicResource PrimaryColor}">
                <Label
                    Text="{u:I18n DisablePersonalVaultExportPolicyInEffect}"
                    StyleClass="text-muted, text-sm, text-bold"
                    HorizontalTextAlignment="Center"
                    AutomationId="DisablePrivateVaultPolicyLabel" />
            </Frame>
            <Grid
                RowSpacing="10"
                RowDefinitions="70, Auto, Auto">
                <StackLayout
                    StyleClass="box-row"
                    Grid.Row="0">
                    <Label
                        Text="{u:I18n FileFormat}"
                        StyleClass="box-label" />
                    <Picker
                        x:Name="_fileFormatPicker"
                        ItemsSource="{Binding FileFormatOptions, Mode=OneTime}"
                        SelectedIndex="{Binding FileFormatSelectedIndex}"
                        SelectedIndexChanged="FileFormat_Changed"
                        StyleClass="box-value"
                        IsEnabled="{Binding DisablePrivateVaultPolicyEnabled, Converter={StaticResource inverseBool}}"
                        AutomationId="FileFormatPicker" />
                </StackLayout>
                <StackLayout
                    StyleClass="box-row"
                    Grid.Row="1"
                    IsVisible="{Binding UseOTPVerification}">
                    <Label
                        Text="{u:I18n SendVerificationCodeToEmail}"
                        StyleClass="box-label"
                        LineBreakMode="WordWrap"
                        Margin="0,0,0,10" />
                    <Button x:Name="_requestOTP"
                        Text="{u:I18n SendCode}"
                        Clicked="RequestOTP_Clicked"
                        HorizontalOptions="Fill"
                        VerticalOptions="End"
                        IsEnabled="{Binding DisablePrivateVaultPolicyEnabled, Converter={StaticResource inverseBool}}"
                        Margin="0,0,0,10"
                        AutomationId="SendTOTPCodeButton" />
                </StackLayout>
                <Grid
                    StyleClass="box-row"
                    Grid.Row="2"
                    RowDefinitions="Auto,Auto,Auto"
                    ColumnDefinitions="*,Auto"
                    Padding="0">
                    <Label
                        Text="{Binding SecretName}"
                        StyleClass="box-label"
                        Grid.Row="0"
                        Grid.ColumnSpan="2" />
                    <controls:MonoEntry
                        x:Name="_secret"
                        Text="{Binding Secret}"
                        StyleClass="box-value"
                        IsSpellCheckEnabled="False"
                        IsTextPredictionEnabled="False"
                        IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                        IsEnabled="{Binding DisablePrivateVaultPolicyEnabled, Converter={StaticResource inverseBool}}"
                        Grid.Row="1"
                        Grid.Column="0"
                        ReturnType="Go"
                        ReturnCommand="{Binding ExportVaultCommand}"
                        AutomationId="MasterPasswordEntry" />
                    <controls:IconButton
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding ShowPasswordIcon}"
                        Command="{Binding TogglePasswordCommand}"
                        Grid.Row="1"
                        Grid.Column="1"
                        SemanticProperties.Description="{u:I18n ToggleVisibility}"
                        SemanticProperties.Hint="{Binding PasswordVisibilityAccessibilityText}"
                        IsVisible="{Binding UseOTPVerification, Converter={StaticResource inverseBool}}"
                        AutomationId="TogglePasswordVisibilityButton" />
                    <Label
                        Text="{u:I18n ConfirmYourIdentity}"
                        StyleClass="box-footer-label"
                        LineBreakMode="WordWrap"
                        Grid.Row="2"
                        Margin="0,10,0,0"
                        IsVisible="{Binding UseOTPVerification}" />
                </Grid>
                
            </Grid>
            <StackLayout
                StyleClass="box-row">
                <Label
                    Text="{u:I18n ExportVaultMasterPasswordDescription}"
                    StyleClass="box-footer-label, box-footer-label-switch"
                    IsVisible="{Binding UseOTPVerification, Converter={StaticResource inverseBool}}"/>
                <Button
                    Text="{u:I18n ExportVault}"
                    Clicked="ExportVault_Clicked"
                    HorizontalOptions="Fill"
                    VerticalOptions="End"
                    IsEnabled="{Binding DisablePrivateVaultPolicyEnabled, Converter={StaticResource inverseBool}}"
                    AutomationId="ExportVaultButton" />
            </StackLayout>
        </StackLayout>
    </ScrollView>

</pages:BaseContentPage>