<?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.CipherAddEditPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:views="clr-namespace:Bit.Core.Models.View"
    xmlns:behaviors="clr-namespace:Bit.App.Behaviors"
    xmlns:effects="clr-namespace:Bit.App.Effects"
    xmlns:dts="clr-namespace:Bit.App.Lists.DataTemplateSelectors"
    xmlns:il="clr-namespace:Bit.App.Lists.ItemLayouts.CustomFields"
    HideSoftInputOnTapped="True"
    xmlns:core="clr-namespace:Bit.Core" 
    xmlns:appResources="clr-namespace:Bit.Core.Resources.Localization"
    x:DataType="pages:CipherAddEditPageViewModel"
    x:Name="_page"
    Title="{Binding PageTitle}">
    <ContentPage.BindingContext>
        <pages:CipherAddEditPageViewModel />
    </ContentPage.BindingContext>

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n Save}" Clicked="Save_Clicked" Order="Primary" />
    </ContentPage.ToolbarItems>

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <u:StringHasValueConverter x:Key="stringHasValue" />
            <u:IsNotNullConverter x:Key="notNull" />
            <u:DateTimeConverter x:Key="dateTime" Format="{x:Static appResources:AppResources.CreatedXY}" />

            <ToolbarItem Text="{u:I18n Cancel}" Clicked="Close_Clicked" Order="Primary" Priority="-1"
                         x:Key="closeItem" x:Name="_closeItem" />
            <ToolbarItem Text="{u:I18n Collections}"
                         x:Key="collectionsItem"
                         x:Name="_collectionsItem"
                         Clicked="Collections_Clicked"
                         Order="Secondary" />
            <ToolbarItem Text="{u:I18n MoveToOrganization}"
                         x:Key="shareItem"
                         x:Name="_shareItem"
                         Clicked="Share_Clicked"
                         Order="Secondary" />
            <ToolbarItem IconImageSource="more_vert.png" Clicked="More_Clicked" Order="Primary" x:Name="_moreItem"
                         x:Key="moreItem"
                         SemanticProperties.Description="{u:I18n Options}" />
            <ToolbarItem Text="{u:I18n Attachments}"
                         Clicked="Attachments_Clicked"
                         Order="Secondary"
                         x:Name="_attachmentsItem"
                         x:Key="attachmentsItem" />
            <ToolbarItem Text="{u:I18n Delete}"
                         Clicked="Delete_Clicked"
                         Order="Secondary"
                         IsDestructive="True"
                         x:Name="_deleteItem"
                         x:Key="deleteItem" />
            
            <DataTemplate x:Key="TextCustomFieldDataTemplate">
                <il:TextCustomFieldItemLayout AutomationId="TextCustomFieldItem" />
            </DataTemplate>
            <DataTemplate x:Key="BooleanCustomFieldDataTemplate">
                <il:BooleanCustomFieldItemLayout AutomationId="BooleanCustomFieldItem" />
            </DataTemplate>
            <DataTemplate x:Key="HiddenCustomFieldDataTemplate">
                <il:HiddenCustomFieldItemLayout AutomationId="HiddenCustomFieldItem" />
            </DataTemplate>
            <DataTemplate x:Key="LinkedCustomFieldDataTemplate">
                <il:LinkedCustomFieldItemLayout AutomationId="LinkedCustomFieldItem" />
            </DataTemplate>

            <dts:CustomFieldItemTemplateSelector x:Key="CustomFieldItemTemplateSelector"
                TextTemplate="{StaticResource TextCustomFieldDataTemplate}"
                BooleanTemplate="{StaticResource BooleanCustomFieldDataTemplate}"
                HiddenTemplate="{StaticResource HiddenCustomFieldDataTemplate}"
                LinkedTemplate="{StaticResource LinkedCustomFieldDataTemplate}"/>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ScrollView x:Name="_scrollView" Padding="0, 0, 0, 20">
        <StackLayout Spacing="20">
            <StackLayout StyleClass="box">
                <Grid IsVisible="{Binding OwnershipPolicyInEffect}"
                      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="{u:I18n PersonalOwnershipPolicyInEffect}"
                            StyleClass="text-muted, text-sm, text-bold"
                            HorizontalTextAlignment="Center"
                            AutomationId="PersonalOwnershipPolicyLabel"/>
                    </Frame>
                </Grid>
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n ItemInformation, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-input"
                             IsVisible="{Binding TypeEditMode, Converter={StaticResource inverseBool}}">
                    <Label
                        Text="{u:I18n Type}"
                        StyleClass="box-label" />
                    <Picker
                        x:Name="_typePicker"
                        ItemsSource="{Binding TypeOptions, Mode=OneTime}"
                        SelectedIndex="{Binding TypeSelectedIndex}"
                        StyleClass="box-value"
                        AutomationId="ItemTypePicker" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-input">
                    <Label
                        Text="{u:I18n Name}"
                        StyleClass="box-label" />
                    <Entry
                        x:Name="_nameEntry"
                        Text="{Binding Cipher.Name, FallbackValue=''}"
                        StyleClass="box-value"
                        SemanticProperties.Description="{u:I18n Name}"
                        AutomationId="ItemNameEntry" />
                </StackLayout>
                <StackLayout IsVisible="{Binding IsLogin}" Spacing="0" Padding="0">
                    <Grid StyleClass="box-row, box-row-input"
                        RowDefinitions="Auto,*"
                        ColumnDefinitions="*,Auto">
                         <Label
                            Text="{u:I18n Username}"
                            StyleClass="box-label"/>
                        <Entry
                            x:Name="_loginUsernameEntry"
                            Text="{Binding Cipher.Login.Username, FallbackValue=''}"
                            StyleClass="box-value" 
                            Grid.Row="1"
                            SemanticProperties.Description="{u:I18n Username}"
                            AutomationId="LoginUsernameEntry" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.Generate}}"
                            Command="{Binding GenerateUsernameCommand}"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n GenerateUsername}"
                            AutomationId="GenerateUsernameButton" />
                    </Grid>
                    <Grid StyleClass="box-row, box-row-input">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label
                            Text="{u:I18n Password}"
                            StyleClass="box-label"
                            Grid.Row="0"
                            Grid.Column="0" />
                        <controls:MonoEntry
                            x:Name="_loginPasswordEntry"
                            Text="{Binding Cipher.Login.Password, FallbackValue=''}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            Grid.ColumnSpan="{Binding PasswordFieldColSpan}"
                            IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False"
                            IsEnabled="{Binding Cipher.ViewPassword, FallbackValue=False}"
                            SemanticProperties.Description="{u:I18n Password}"
                            AutomationId="LoginPasswordEntry" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.CheckCircle}}"
                            Command="{Binding CheckPasswordCommand}"
                            Grid.Row="0"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n CheckPassword}"
                            IsVisible="{Binding Cipher.ViewPassword, FallbackValue=False}"
                            AutomationId="CheckPasswordButton" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding ShowPasswordIcon}"
                            Command="{Binding TogglePasswordCommand}"
                            Grid.Row="0"
                            Grid.Column="2"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n ToggleVisibility}"
                            SemanticProperties.Hint="{Binding PasswordVisibilityAccessibilityText}"
                            IsVisible="{Binding Cipher.ViewPassword, FallbackValue=False}"
                            AutomationId="ViewPasswordButton" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.Generate}}"
                            Command="{Binding GeneratePasswordCommand}"
                            Grid.Row="0"
                            Grid.Column="3"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n GeneratePassword}"
                            IsVisible="{Binding Cipher.ViewPassword, FallbackValue=False}"
                            AutomationId="RegeneratePasswordButton" />
                    </Grid>

                    <Label
                        Text="{u:I18n Passkey}"
                        StyleClass="box-label"
                        Margin="0,10,0,0"
                        IsVisible="{Binding ShowPasskeyInfo}"/>
                    <Entry
                        Text="{Binding Cipher.Login.MainFido2Credential.CreationDate, Mode=OneWay, Converter={StaticResource dateTime}, FallbackValue=''}"
                        IsEnabled="False"
                        StyleClass="box-value,text-muted" 
                        IsVisible="{Binding ShowPasskeyInfo}" />

                    <Grid StyleClass="box-row, box-row-input">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label
                            Text="{u:I18n AuthenticatorKey}"
                            StyleClass="box-label"
                            Grid.Row="0"
                            Grid.Column="0" />
                        <Frame 
                            IsVisible="{Binding HasTotpValue, Converter={StaticResource inverseBool}}" 
                            Margin="0,5,0,0"
                            StyleClass="btn-icon-row"
                            Padding="0"
                            Grid.Row="1"
                            Grid.Column="0"
                            Grid.ColumnSpan="3">
                            <Frame.GestureRecognizers>
                                <TapGestureRecognizer Tapped="ScanTotp_Clicked" />
                            </Frame.GestureRecognizers>
                            <controls:IconLabel 
                                Text="{Binding SetupTotpText}" 
                                Padding="0,15"
                                HorizontalOptions="Center"
                                VerticalOptions="FillAndExpand"
                                VerticalTextAlignment="Center"
                                AutomationId="SetupTotpButton" />
                        </Frame>
                        <controls:MonoEntry
                            x:Name="_loginTotpEntry"
                            Text="{Binding Cipher.Login.Totp, FallbackValue=''}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False"
                            IsVisible="{Binding HasTotpValue}"
                            IsPassword="{Binding Cipher.ViewPassword, Converter={StaticResource inverseBool}, FallbackValue=False}"
                            IsEnabled="{Binding Cipher.ViewPassword, FallbackValue=False}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            Grid.ColumnSpan="{Binding TotpColumnSpan}"
                            SemanticProperties.Description="{u:I18n AuthenticatorKey}"
                            AutomationId="LoginTotpEntry" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                            Command="{Binding CopyCommand}"
                            IsVisible="{Binding AllowTotpCopy}"
                            Grid.Row="0"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n CopyTotp}"
                            AutomationId="CopyTotpValueButton" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.Camera}}"
                            Clicked="ScanTotp_Clicked"
                            Grid.Row="0"
                            Grid.Column="2"
                            Grid.RowSpan="2"
                            IsVisible="{Binding HasTotpValue}"
                            SemanticProperties.Description="{u:I18n ScanQrTitle}"
                            />
                    </Grid>
                </StackLayout>
                <StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0">
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n CardholderName}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_cardholderNameEntry"
                            Text="{Binding Cipher.Card.CardholderName, FallbackValue=''}"
                            StyleClass="box-value"
                            AutomationId="CardholderNameEntry" />
                    </StackLayout>
                    <Grid StyleClass="box-row, box-row-input">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label
                            Text="{u:I18n Number}"
                            StyleClass="box-label"
                            Grid.Row="0"
                            Grid.Column="0" />
                        <controls:MonoEntry
                            x:Name="_cardNumberEntry"
                            Text="{Binding Cipher.Card.Number, FallbackValue=''}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            IsPassword="{Binding ShowCardNumber, Converter={StaticResource inverseBool}}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False"
                            SemanticProperties.Description="{u:I18n Number}"
                            AutomationId="CardNumberEntry" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding ShowCardNumberIcon}"
                            Command="{Binding ToggleCardNumberCommand}"
                            Grid.Row="0"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n ToggleVisibility}"
                            AutomationId="ShowCardNumberButton" />
                    </Grid>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Brand}"
                            StyleClass="box-label" />
                        <Picker
                            x:Name="_cardBrandPicker"
                            ItemsSource="{Binding CardBrandOptions, Mode=OneTime}"
                            SelectedIndex="{Binding CardBrandSelectedIndex}"
                            StyleClass="box-value"
                            AutomationId="CardBrandPicker" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n ExpirationMonth}"
                            StyleClass="box-label" />
                        <Picker
                            x:Name="_cardExpMonthPicker"
                            ItemsSource="{Binding CardExpMonthOptions, Mode=OneTime}"
                            SelectedIndex="{Binding CardExpMonthSelectedIndex}"
                            StyleClass="box-value"
                            AutomationId="CardExpirationMonthPicker" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n ExpirationYear}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_cardExpYearEntry"
                            Text="{Binding Cipher.Card.ExpYear, FallbackValue=''}"
                            StyleClass="box-value"
                            Keyboard="Numeric"
                            SemanticProperties.Description="{u:I18n ExpirationYear}"
                            AutomationId="CardExpirationYearEntry" />
                    </StackLayout>
                    <Grid StyleClass="box-row, box-row-input">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Label
                            Text="{u:I18n SecurityCode}"
                            StyleClass="box-label"
                            Grid.Row="0"
                            Grid.Column="0" />
                        <controls:MonoEntry
                            x:Name="_cardCodeEntry"
                            Text="{Binding Cipher.Card.Code, FallbackValue=''}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            Keyboard="Numeric"
                            IsPassword="{Binding ShowCardCode, Converter={StaticResource inverseBool}}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False"
                            SemanticProperties.Description="{u:I18n SecurityCode}"
                            AutomationId="CardSecurityCodeEntry" />
                        <controls:IconButton 
                            StyleClass="box-row-button, box-row-button-platform"
                            Text="{Binding ShowCardCodeIcon}"
                            Command="{Binding ToggleCardCodeCommand}"
                            Grid.Row="0"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n ToggleVisibility}"
                            AutomationId="CardShowSecurityCodeButton" />
                    </Grid>
                </StackLayout>
                <StackLayout IsVisible="{Binding IsIdentity}" Spacing="0" Padding="0">
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Title}"
                            StyleClass="box-label" />
                        <Picker
                            x:Name="_identityTitlePicker"
                            ItemsSource="{Binding IdentityTitleOptions, Mode=OneTime}"
                            SelectedIndex="{Binding IdentityTitleSelectedIndex}"
                            StyleClass="box-value"
                            AutomationId="IdentityTitlePicker" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n FirstName}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityFirstNameEntry"
                            Text="{Binding Cipher.Identity.FirstName, FallbackValue=''}"
                            StyleClass="box-value,capitalize-word-input"
                            SemanticProperties.Description="{u:I18n FirstName}"
                            AutomationId="IdentityFirstNameEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n MiddleName}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityMiddleNameEntry"
                            Text="{Binding Cipher.Identity.MiddleName, FallbackValue=''}"
                            StyleClass="box-value,capitalize-word-input"
                            SemanticProperties.Description="{u:I18n MiddleName}"
                            AutomationId="IdentityMiddleNameEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n LastName}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityLastNameEntry"
                            Text="{Binding Cipher.Identity.LastName, FallbackValue=''}"
                            StyleClass="box-value,capitalize-word-input"
                            SemanticProperties.Description="{u:I18n LastName}"
                            AutomationId="IdentityLastNameEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Username}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityUsernameEntry"
                            Text="{Binding Cipher.Identity.Username, FallbackValue=''}"
                            StyleClass="box-value"
                            SemanticProperties.Description="{u:I18n Username}"
                            AutomationId="IdentityUsernameEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Company}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityCompanyEntry"
                            Text="{Binding Cipher.Identity.Company, FallbackValue=''}"
                            StyleClass="box-value" 
                            SemanticProperties.Description="{u:I18n Company}"
                            AutomationId="IdentityCompanyEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n SSN}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identitySsnEntry"
                            Text="{Binding Cipher.Identity.SSN, FallbackValue=''}"
                            StyleClass="box-value" 
                            SemanticProperties.Description="{u:I18n SSN}"
                            AutomationId="IdentitySsnEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n PassportNumber}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityPassportNumberEntry"
                            Text="{Binding Cipher.Identity.PassportNumber, FallbackValue=''}"
                            StyleClass="box-value" 
                            SemanticProperties.Description="{u:I18n PassportNumber}"
                            AutomationId="IdentityPassportNumberEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n LicenseNumber}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityLicenseNumberEntry"
                            Text="{Binding Cipher.Identity.LicenseNumber, FallbackValue=''}"
                            StyleClass="box-value"
                            SemanticProperties.Description="{u:I18n LicenseNumber}"
                            AutomationId="IdentityLicenseNumberEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Email}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityEmailEntry"
                            Keyboard="Email"
                            Text="{Binding Cipher.Identity.Email, FallbackValue=''}"
                            StyleClass="box-value" 
                            SemanticProperties.Description="{u:I18n Email}"
                            AutomationId="IdentityEmailEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Phone}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityPhoneEntry"
                            Text="{Binding Cipher.Identity.Phone, FallbackValue=''}"
                            Keyboard="Telephone"
                            StyleClass="box-value"
                            SemanticProperties.Description="{u:I18n Phone}"
                            AutomationId="IdentityPhoneEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Address1}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityAddress1Entry"
                            Text="{Binding Cipher.Identity.Address1, FallbackValue=''}"
                            StyleClass="box-value" 
                            SemanticProperties.Description="{u:I18n Address1}"
                            AutomationId="IdentityAddressOneEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Address2}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityAddress2Entry"
                            Text="{Binding Cipher.Identity.Address2, FallbackValue=''}"
                            StyleClass="box-value"
                            SemanticProperties.Description="{u:I18n Address2}"
                            AutomationId="IdentityAddressTwoEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Address3}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityAddress3Entry"
                            Text="{Binding Cipher.Identity.Address3, FallbackValue=''}"
                            StyleClass="box-value"
                            SemanticProperties.Description="{u:I18n Address3}"
                            AutomationId="IdentityAddressThreeEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n CityTown}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityCityEntry"
                            Text="{Binding Cipher.Identity.City, FallbackValue=''}"
                            StyleClass="box-value,capitalize-sentence-input"
                            SemanticProperties.Description="{u:I18n CityTown}"
                            AutomationId="IdentityCityEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n StateProvince}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityStateEntry"
                            Text="{Binding Cipher.Identity.State, FallbackValue=''}"
                            StyleClass="box-value,capitalize-sentence-input"
                            SemanticProperties.Description="{u:I18n StateProvince}"
                            AutomationId="IdentityStateEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n ZipPostalCode}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityPostalCodeEntry"
                            Text="{Binding Cipher.Identity.PostalCode, FallbackValue=''}"
                            StyleClass="box-value"
                            SemanticProperties.Description="{u:I18n ZipPostalCode}"
                            AutomationId="IdentityPostalCodeEntry" />
                    </StackLayout>
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Country}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_identityCountryEntry"
                            Text="{Binding Cipher.Identity.Country, FallbackValue=''}"
                            StyleClass="box-value,capitalize-sentence-input"
                            SemanticProperties.Description="{u:I18n Country}"
                            AutomationId="IdentityCountryEntry" />
                    </StackLayout>
                </StackLayout>
            </StackLayout>
            <StackLayout StyleClass="box" IsVisible="{Binding IsLogin}">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n URIs, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout BindableLayout.ItemsSource="{Binding Uris}">
                    <BindableLayout.ItemTemplate>
                        <DataTemplate x:DataType="views:LoginUriView">
                            <Grid StyleClass="box-row, box-row-input" AutomationId="UriListGrid" >
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Label
                                    Text="{u:I18n URI}"
                                    StyleClass="box-label"
                                    Grid.Row="0"
                                    Grid.Column="0" />
                                <Entry
                                    Text="{Binding Uri}"
                                    Keyboard="Url"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    SemanticProperties.Description="{u:I18n URI}"
                                    IsEnabled="{Binding BindingContext.IsFromFido2Framework, Source={x:Reference _page}, Converter={StaticResource inverseBool}}"
                                    AutomationId="LoginUriEntry" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    IsVisible="{Binding BindingContext.IsFromFido2Framework, Source={x:Reference _page}, Converter={StaticResource inverseBool}}"
                                    Text="{Binding Source={x:Static core:BitwardenIcons.Cog}}"
                                    Command="{Binding BindingContext.UriOptionsCommand, Source={x:Reference _page}}"
                                    CommandParameter="{Binding .}"
                                    Grid.Row="0"
                                    Grid.Column="1"
                                    Grid.RowSpan="2"
                                    SemanticProperties.Description="{u:I18n Options}"
                                    AutomationId="LoginUriOptionsButton" />
                            </Grid>
                        </DataTemplate>
                    </BindableLayout.ItemTemplate>
                </StackLayout>
                <Button Text="{u:I18n NewUri}" StyleClass="box-button-row"
                        IsVisible="{Binding IsFromFido2Framework, Converter={StaticResource inverseBool}}"
                        Clicked="NewUri_Clicked"
                        AutomationId="LoginAddNewUriButton"></Button>
            </StackLayout>
            <StackLayout StyleClass="box">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n Miscellaneous, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-input">
                    <Label
                        Text="{u:I18n Folder}"
                        StyleClass="box-label" />
                    <Picker
                        x:Name="_folderPicker"
                        ItemsSource="{Binding FolderOptions, Mode=OneTime}"
                        SelectedIndex="{Binding FolderSelectedIndex}"
                        StyleClass="box-value"
                        AutomationId="FolderPicker" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-switch">
                    <Label
                        Text="{u:I18n Favorite}"
                        StyleClass="box-label-regular"
                        HorizontalOptions="StartAndExpand" />
                    <Switch
                        IsToggled="{Binding Cipher.Favorite, FallbackValue=False}"
                        StyleClass="box-value"
                        HorizontalOptions="End"
                        AutomationId="ItemFavoriteToggle" />
                </StackLayout>
                <StackLayout x:Name="_passwordPrompt" StyleClass="box-row, box-row-switch">
                    <Label
                        Text="{u:I18n PasswordPrompt}"
                        StyleClass="box-label-regular" />
                    <controls:IconButton 
                        StyleClass="box-row-button, box-row-button-platform"
                        Text="{Binding Source={x:Static core:BitwardenIcons.QuestionCircle}}"
                        Command="{Binding PasswordPromptHelpCommand}"
                        TextColor="{DynamicResource MutedColor}"
                        SemanticProperties.Description="{u:I18n MasterPasswordRePromptHelp}"
                        HorizontalOptions="StartAndExpand" />
                    <Switch
                        IsToggled="{Binding PasswordPrompt, Mode=OneWay}"
                        Toggled="PasswordPrompt_Toggled"
                        StyleClass="box-value"
                        HorizontalOptions="End"
                        AutomationId="MasterPasswordRepromptToggle" />
                </StackLayout>
                <BoxView StyleClass="box-row-separator" />
            </StackLayout>
            <StackLayout StyleClass="box">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n Notes, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-input">
                    <Editor
                        x:Name="_notesEditor"
                        AutoSize="TextChanges"
                        StyleClass="box-value"
                        effects:ScrollEnabledEffect.IsScrollEnabled="false"
                        Text="{Binding Cipher.Notes, FallbackValue=''}"
                        SemanticProperties.Description="{u:I18n Notes}"
                        AutomationId="ItemNotesEntry">
                        <Editor.Behaviors>
                            <behaviors:EditorPreventAutoBottomScrollingOnFocusedBehavior ParentScrollView="{x:Reference _scrollView}" />
                        </Editor.Behaviors>
                        <Editor.Effects>
                            <effects:ScrollEnabledEffect />
                        </Editor.Effects>
                    </Editor>
                </StackLayout>
                <BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowNotesSeparator}" />
            </StackLayout>
            <StackLayout StyleClass="box">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n CustomFields, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout
                    Spacing="0"
                    BindableLayout.ItemsSource="{Binding Fields}"
                    BindableLayout.ItemTemplateSelector="{StaticResource CustomFieldItemTemplateSelector}"
                    AutomationId="CustomFieldsList" />
                <Button Text="{u:I18n NewCustomField}" StyleClass="box-button-row"
                        Clicked="NewField_Clicked"
                        AutomationId="NewCustomFieldButton"></Button>
            </StackLayout>
            <StackLayout StyleClass="box" IsVisible="{Binding ShowOwnershipOptions}">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n Ownership, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-input">
                    <Label
                        Text="{u:I18n WhoOwnsThisItem}"
                        StyleClass="box-label" />
                    <Picker
                        x:Name="_ownershipPicker"
                        ItemsSource="{Binding OwnershipOptions, Mode=OneWay}"
                        SelectedIndex="{Binding OwnershipSelectedIndex}"
                        StyleClass="box-value"
                        AutomationId="ItemOwnershipPicker" />
                </StackLayout>
            </StackLayout>
            <StackLayout StyleClass="box" IsVisible="{Binding ShowCollections}">
                <StackLayout StyleClass="box-row-header">
                    <Label Text="{u:I18n Collections, Header=True}"
                           StyleClass="box-header, box-header-platform" />
                </StackLayout>
                <StackLayout Spacing="0" Padding="0"
                                IsVisible="{Binding HasCollections, Converter={StaticResource inverseBool}}">
                    <StackLayout StyleClass="box-row, box-row-switch">
                        <Label Text="{u:I18n NoCollectionsToList}"
                               AutomationId="NoCollectionsToListLabel" />
                    </StackLayout>
                    <BoxView StyleClass="box-row-separator" />
                </StackLayout>
                <controls:RepeaterView 
                    ItemsSource="{Binding Collections}"
                    IsVisible="{Binding HasCollections}">
                    <controls:RepeaterView.ItemTemplate>
                        <DataTemplate x:DataType="pages:CollectionViewModel">
                            <StackLayout Spacing="0" Padding="0">
                                <StackLayout StyleClass="box-row, box-row-switch" AutomationId="CollectionItemCell">
                                    <Label
                                        Text="{Binding Collection.Name}"
                                        StyleClass="box-label-regular"
                                        HorizontalOptions="StartAndExpand"
                                        AutomationId="CollectionItemNameLabel" />
                                    <Switch
                                        IsToggled="{Binding Checked}"
                                        StyleClass="box-value"
                                        HorizontalOptions="End"
                                        AutomationId="CollectionItemSwitch" />
                                </StackLayout>
                                <BoxView StyleClass="box-row-separator" />
                            </StackLayout>
                        </DataTemplate>
                    </controls:RepeaterView.ItemTemplate>
                </controls:RepeaterView>
            </StackLayout>
        </StackLayout>
    </ScrollView>
</pages:BaseContentPage>
