<?xml version="1.0" encoding="utf-8" ?>
<pages:BaseContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    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;assembly=BitwardenCore"
    xmlns:behaviors="clr-namespace:Bit.App.Behaviors"
    xmlns:effects="clr-namespace:Bit.App.Effects"
    xmlns:core="clr-namespace:Bit.Core;assembly=BitwardenCore"
    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" />
            <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 Icon="more_vert.png" Clicked="More_Clicked" Order="Primary" x:Name="_moreItem"
                         x:Key="moreItem"
                         AutomationProperties.IsInAccessibleTree="True"
                         AutomationProperties.Name="{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" />
        </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="Accent">
                        <Label
                            Text="{u:I18n PersonalOwnershipPolicyInEffect}"
                            StyleClass="text-muted, text-sm, text-bold"
                            HorizontalTextAlignment="Center" />
                    </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 EditMode, 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" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-input">
                    <Label
                        Text="{u:I18n Name}"
                        StyleClass="box-label" />
                    <Entry
                        x:Name="_nameEntry"
                        Text="{Binding Cipher.Name}"
                        StyleClass="box-value" />
                </StackLayout>
                <StackLayout IsVisible="{Binding IsLogin}" Spacing="0" Padding="0">
                    <StackLayout StyleClass="box-row, box-row-input">
                        <Label
                            Text="{u:I18n Username}"
                            StyleClass="box-label" />
                        <Entry
                            x:Name="_loginUsernameEntry"
                            Text="{Binding Cipher.Login.Username}"
                            StyleClass="box-value" />
                    </StackLayout>
                    <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}"
                            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}"/>
                        <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"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{u:I18n CheckPassword}"
                            IsVisible="{Binding Cipher.ViewPassword}" />
                        <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"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{u:I18n ToggleVisibility}"
                            AutomationProperties.HelpText="{Binding PasswordVisibilityAccessibilityText}"
                            IsVisible="{Binding Cipher.ViewPassword}" />
                        <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"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{u:I18n GeneratePassword}"
                            IsVisible="{Binding Cipher.ViewPassword}" />
                    </Grid>

                    <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 AuthenticatorKey}"
                            StyleClass="box-label"
                            Grid.Row="0"
                            Grid.Column="0" />
                        <controls:MonoEntry
                            x:Name="_loginTotpEntry"
                            Text="{Binding Cipher.Login.Totp}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False"
                            IsPassword="{Binding Cipher.ViewPassword, Converter={StaticResource inverseBool}}"
                            IsEnabled="{Binding Cipher.ViewPassword}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            Grid.ColumnSpan="{Binding TotpColumnSpan}" />
                        <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="1"
                            Grid.RowSpan="2"
                            IsVisible="{Binding Cipher.ViewPassword}"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            IsPassword="{Binding ShowCardNumber, Converter={StaticResource inverseBool}}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False" />
                        <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"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{u:I18n ToggleVisibility}" />
                    </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" />
                    </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" />
                    </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}"
                            StyleClass="box-value"
                            Keyboard="Numeric" />
                    </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}"
                            StyleClass="box-value"
                            Grid.Row="1"
                            Grid.Column="0"
                            Keyboard="Numeric"
                            IsPassword="{Binding ShowCardCode, Converter={StaticResource inverseBool}}"
                            IsSpellCheckEnabled="False"
                            IsTextPredictionEnabled="False" />
                        <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"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{u:I18n ToggleVisibility}" />
                    </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" />
                    </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}"
                            StyleClass="box-value,capitalize-word-input"/>
                    </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}"
                            StyleClass="box-value,capitalize-word-input" />
                    </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}"
                            StyleClass="box-value,capitalize-word-input" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            Keyboard="Telephone"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value,capitalize-sentence-input" />
                    </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}"
                            StyleClass="box-value,capitalize-sentence-input" />
                    </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}"
                            StyleClass="box-value" />
                    </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}"
                            StyleClass="box-value,capitalize-sentence-input" />
                    </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>
                <controls:RepeaterView ItemsSource="{Binding Uris}">
                    <controls:RepeaterView.ItemTemplate>
                        <DataTemplate x:DataType="views:LoginUriView">
                            <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 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" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    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"
                                    AutomationProperties.IsInAccessibleTree="True"
                                    AutomationProperties.Name="{u:I18n Options}" />
                            </Grid>
                        </DataTemplate>
                    </controls:RepeaterView.ItemTemplate>
                </controls:RepeaterView>
                <Button Text="{u:I18n NewUri}" StyleClass="box-button-row"
                        Clicked="NewUri_Clicked"></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" />
                </StackLayout>
                <StackLayout StyleClass="box-row, box-row-switch">
                    <Label
                        Text="{u:I18n Favorite}"
                        StyleClass="box-label-regular"
                        HorizontalOptions="StartAndExpand" />
                    <Switch
                        IsToggled="{Binding Cipher.Favorite}"
                        StyleClass="box-value"
                        HorizontalOptions="End" />
                </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}"
                        AutomationProperties.IsInAccessibleTree="True"
                        AutomationProperties.Name="{u:I18n ToggleVisibility}"
                        HorizontalOptions="StartAndExpand" />
                    <Switch
                        IsToggled="{Binding PasswordPrompt}"
                        Toggled="PasswordPrompt_Toggled"
                        StyleClass="box-value"
                        HorizontalOptions="End" />
                </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}">
                        <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>
                <controls:RepeaterView ItemsSource="{Binding Fields}">
                    <controls:RepeaterView.ItemTemplate>
                        <DataTemplate x:DataType="pages:CipherAddEditPageFieldViewModel">
                            <StackLayout Spacing="0" Padding="0">
                                <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" />
                                    </Grid.ColumnDefinitions>
                                    <Label
                                        Text="{Binding Field.Name, Mode=OneWay}"
                                        IsVisible="{Binding IsBooleanType, Mode=OneWay, Converter={StaticResource inverseBool}}"
                                        StyleClass="box-label"
                                        Grid.Row="0"
                                        Grid.Column="0" />
                                    <Label
                                        Text="{Binding Field.Name, Mode=OneWay}"
                                        IsVisible="{Binding IsBooleanType, Mode=OneWay}"
                                        StyleClass="box-value"
                                        VerticalOptions="FillAndExpand"
                                        VerticalTextAlignment="Center"
                                        Grid.Row="0"
                                        Grid.Column="0"
                                        Grid.RowSpan="2" />
                                    <Entry
                                        Text="{Binding Field.Value}"
                                        StyleClass="box-value"
                                        Grid.Row="1"
                                        Grid.Column="0"
                                        IsVisible="{Binding IsTextType}" />
                                    <controls:MonoEntry
                                        Text="{Binding Field.Value}"
                                        StyleClass="box-value"
                                        Grid.Row="1"
                                        Grid.Column="0"
                                        IsVisible="{Binding IsHiddenType}"
                                        IsPassword="{Binding ShowHiddenValue, Converter={StaticResource inverseBool}}"
                                        IsEnabled="{Binding ShowViewHidden}"
                                        IsSpellCheckEnabled="False"
                                        IsTextPredictionEnabled="False">
                                        <Entry.Keyboard>
                                            <Keyboard x:FactoryMethod="Create">
                                                <x:Arguments>
                                                    <KeyboardFlags>None</KeyboardFlags>
                                                </x:Arguments>
                                            </Keyboard>
                                        </Entry.Keyboard>
                                    </controls:MonoEntry>
                                    <StackLayout
                                        StyleClass="box-row, box-row-input"
                                        IsVisible="{Binding IsLinkedType}">
                                        <Picker
                                            x:Name="_linkedFieldOptionPicker"
                                            ItemsSource="{Binding LinkedFieldOptions, Mode=OneTime}"
                                            SelectedIndex="{Binding LinkedFieldOptionSelectedIndex}"
                                            ItemDisplayBinding="{Binding Key}"
                                            StyleClass="box-value" />
                                    </StackLayout>
                                    <Switch
                                        IsToggled="{Binding BooleanValue}"
                                        Grid.Row="0"
                                        Grid.Column="1"
                                        Grid.RowSpan="2"
                                        IsVisible="{Binding IsBooleanType}" />
                                    <controls:IconButton 
                                        StyleClass="box-row-button, box-row-button-platform"
                                        Text="{Binding ShowHiddenValueIcon}"
                                        Command="{Binding ToggleHiddenValueCommand}"
                                        IsVisible="{Binding ShowViewHidden}"
                                        Grid.Row="0"
                                        Grid.Column="1"
                                        Grid.RowSpan="2"
                                        AutomationProperties.IsInAccessibleTree="True"
                                        AutomationProperties.Name="{u:I18n ToggleVisibility}" />
                                    <controls:IconButton 
                                        StyleClass="box-row-button, box-row-button-platform"
                                        Text="{Binding Source={x:Static core:BitwardenIcons.Cog}}"
                                        Command="{Binding BindingContext.FieldOptionsCommand, Source={x:Reference _page}}"
                                        CommandParameter="{Binding .}"
                                        Grid.Row="0"
                                        Grid.Column="2"
                                        Grid.RowSpan="2"
                                        AutomationProperties.IsInAccessibleTree="True"
                                        AutomationProperties.Name="{u:I18n Options}" />
                                </Grid>
                                <BoxView StyleClass="box-row-separator" IsVisible="{Binding IsBooleanType}" />
                            </StackLayout>
                        </DataTemplate>
                    </controls:RepeaterView.ItemTemplate>
                </controls:RepeaterView>
                <Button Text="{u:I18n NewCustomField}" StyleClass="box-button-row"
                        Clicked="NewField_Clicked"></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=OneTime}"
                        SelectedIndex="{Binding OwnershipSelectedIndex}"
                        StyleClass="box-value" />
                </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}" />
                    </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">
                                    <Label
                                        Text="{Binding Collection.Name}"
                                        StyleClass="box-label-regular"
                                        HorizontalOptions="StartAndExpand" />
                                    <Switch
                                        IsToggled="{Binding Checked}"
                                        StyleClass="box-value"
                                        HorizontalOptions="End" />
                                </StackLayout>
                                <BoxView StyleClass="box-row-separator" />
                            </StackLayout>
                        </DataTemplate>
                    </controls:RepeaterView.ItemTemplate>
                </controls:RepeaterView>
            </StackLayout>
        </StackLayout>
    </ScrollView>

</pages:BaseContentPage>
