<?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.UpdateTempPasswordPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    x:DataType="pages:UpdateTempPasswordPageViewModel"
    HideSoftInputOnTapped="True"
    Title="{Binding PageTitle}">
    
    <ContentPage.BindingContext>
        <pages:UpdateTempPasswordPageViewModel />
    </ContentPage.BindingContext>

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

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n LogOut}" Clicked="LogOut_Clicked" Order="Primary" Priority="-1" />
        <ToolbarItem Text="{u:I18n Submit}" Clicked="Submit_Clicked" />
    </ContentPage.ToolbarItems>

    <ScrollView>
        <StackLayout 
            x:Name="_mainLayout"
            Spacing="20">
            <StackLayout StyleClass="box">
                <Grid Margin="0, 12, 0, 0"
                      RowSpacing="0"
                      ColumnSpacing="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Frame Padding="10"
                           Margin="0"
                           HasShadow="False"
                           BackgroundColor="Transparent"
                           BorderColor="{DynamicResource PrimaryColor}">
                        <Label
                            Text="{Binding UpdateMasterPasswordWarningText }"
                            StyleClass="text-muted, text-sm, text-bold"
                            HorizontalTextAlignment="Center"
                            AutomationId="UpdatePasswordWarningLabel" />
                    </Frame>
                </Grid>
                <Grid IsVisible="{Binding IsPolicyInEffect}"
                      Margin="0, 12, 0, 0"
                      RowSpacing="0"
                      ColumnSpacing="0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Frame Padding="10"
                           Margin="0"
                           HasShadow="False"
                           BackgroundColor="Transparent"
                           BorderColor="{DynamicResource PrimaryColor}">
                        <Label
                            Text="{Binding PolicySummary}"
                            StyleClass="text-muted, text-sm, text-bold"
                            HorizontalTextAlignment="Start"
                            AutomationId="PolicySummaryLabel" />
                    </Frame>
                </Grid>
                <Grid StyleClass="box-row" IsVisible="{Binding RequireCurrentPassword }">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label
                        Text="{u:I18n CurrentMasterPassword}"
                        StyleClass="box-label" 
                        Grid.Row="0"
                        Grid.Column="0" />
                    <controls:MonoEntry
                        x:Name="_currentMasterPassword"
                        Text="{Binding CurrentMasterPassword}"
                        StyleClass="box-value"
                        IsSpellCheckEnabled="False"
                        IsTextPredictionEnabled="False"
                        IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                        Grid.Row="1"
                        Grid.Column="0"
                        AutomationId="MasterPasswordField" />
                    <controls:IconButton
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding ShowPasswordIcon}"
                        Command="{Binding TogglePasswordCommand}"
                        Grid.Row="0"
                        Grid.Column="1"
                        Grid.RowSpan="2"
                        SemanticProperties.Description="{u:I18n ToggleVisibility}"
                        SemanticProperties.Hint="{Binding PasswordVisibilityAccessibilityText}"
                        AutomationId="ToggleMasterPasswordVisibilityButton" />
                </Grid>
                <Grid StyleClass="box-row">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label
                        Text="{u:I18n MasterPassword}"
                        StyleClass="box-label"
                        Grid.Row="0"
                        Grid.Column="0" />
                    <controls:MonoEntry
                        x:Name="_masterPassword"
                        Text="{Binding MasterPassword}"
                        StyleClass="box-value"
                        IsSpellCheckEnabled="False"
                        IsTextPredictionEnabled="False"
                        IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                        Grid.Row="1"
                        Grid.Column="0"
                        AutomationId="NewPasswordField" />
                    <controls:IconButton
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding ShowPasswordIcon}"
                        Command="{Binding TogglePasswordCommand}"
                        Grid.Row="0"
                        Grid.Column="1"
                        Grid.RowSpan="2"
                        SemanticProperties.Description="{u:I18n ToggleVisibility}"
                        SemanticProperties.Hint="{Binding PasswordVisibilityAccessibilityText}"
                        AutomationId="NewPasswordVisibilityButton" />
                </Grid>
            </StackLayout>
            <StackLayout StyleClass="box">
                <Grid StyleClass="box-row">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label
                        Text="{u:I18n RetypeMasterPassword}"
                        StyleClass="box-label"
                        Grid.Row="0"
                        Grid.Column="0" />
                    <controls:MonoEntry
                        x:Name="_confirmMasterPassword"
                        Text="{Binding ConfirmMasterPassword}"
                        StyleClass="box-value"
                        IsSpellCheckEnabled="False"
                        IsTextPredictionEnabled="False"
                        IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                        Grid.Row="1"
                        Grid.Column="0"
                        AutomationId="RetypePasswordField" />
                    <controls:IconButton
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding ShowPasswordIcon}"
                        Command="{Binding ToggleConfirmPasswordCommand}"
                        Grid.Row="0"
                        Grid.Column="1"
                        Grid.RowSpan="2"
                        SemanticProperties.Description="{u:I18n ToggleVisibility}"
                        SemanticProperties.Hint="{Binding PasswordVisibilityAccessibilityText}"
                        AutomationId="ToggleRetypePasswordVisibilityButton" />
                </Grid>
                <StackLayout StyleClass="box-row">
                    <Label
                        Text="{u:I18n MasterPasswordHint}"
                        StyleClass="box-label" />
                    <Entry
                        x:Name="_hint"
                        Text="{Binding Hint}"
                        StyleClass="box-value"
                        ReturnType="Go"
                        ReturnCommand="{Binding SubmitCommand}"
                        AutomationId="MasterPasswordHintLabel" />
                </StackLayout>
                <Label
                    Text="{u:I18n MasterPasswordHintDescription}"
                    StyleClass="box-footer-label" />
            </StackLayout>
        </StackLayout>
    </ScrollView>

</pages:BaseContentPage>
