<?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.CipherDetailsPage"
    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:dts="clr-namespace:Bit.App.Lists.DataTemplateSelectors"
    xmlns:il="clr-namespace:Bit.App.Lists.ItemLayouts.CustomFields"
    xmlns:core="clr-namespace:Bit.Core" 
    xmlns:localization="clr-namespace:Bit.Core.Resources.Localization"
    x:DataType="pages:CipherDetailsPageViewModel"
    HideSoftInputOnTapped="True"
    x:Name="_page"
    Title="{Binding PageTitle}">
    <ContentPage.BindingContext>
        <pages:CipherDetailsPageViewModel />
    </ContentPage.BindingContext>

    <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 localization:AppResources.CreatedXY}" />
            <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 Text="{u:I18n Close}" Clicked="Close_Clicked" Order="Primary" Priority="-1"
                         x:Name="_closeItem" x:Key="closeItem" />
            <ToolbarItem Clicked="EditToolbarItem_Clicked" Order="Primary"
                         x:Name="_editItem" x:Key="editItem" />
            <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" />
            <ToolbarItem Text="{u:I18n Clone}" Command="{Binding CloneCommand}" Order="Secondary"
                         x:Name="_cloneItem" x:Key="cloneItem" />

            <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}"/>

            <ScrollView x:Key="scrollView" x:Name="_scrollView">
                <StackLayout Spacing="20" x:Name="_mainLayout">
                    <StackLayout StyleClass="box" AutomationId="ItemInformationSection">
                        <StackLayout StyleClass="box-row-header">
                            <Label Text="{u:I18n ItemInformation, Header=True}"
                                   StyleClass="box-header, box-header-platform" />
                        </StackLayout>
                        <StackLayout StyleClass="box-row" AutomationId="ItemRow">
                            <Label
                                Text="{u:I18n Name}"
                                StyleClass="box-label"
                                AutomationId="ItemName" />
                            <Label
                                Text="{Binding Cipher.Name, Mode=OneWay}"
                                StyleClass="box-value"
                                AutomationId="ItemValue" />
                        </StackLayout>
                        <BoxView StyleClass="box-row-separator" />
                        <StackLayout IsVisible="{Binding IsLogin}" Spacing="0" Padding="0">
                            <Grid StyleClass="box-row"
                                  IsVisible="{Binding Cipher.Login.Username, Converter={StaticResource stringHasValue}}"
                                  AutomationId="ItemRow">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Label
                                    Text="{u:I18n Username}"
                                    StyleClass="box-label"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Login.Username, Mode=OneWay}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    AutomationId="ItemValue" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                                    Command="{Binding CopyCommand}"
                                    CommandParameter="LoginUsername"
                                    Grid.Row="0"
                                    Grid.Column="1"
                                    Grid.RowSpan="2"
                                    SemanticProperties.Description="{u:I18n CopyUsername}"
                                    AutomationId="CopyValueButton" />
                            </Grid>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Login.Username, Converter={StaticResource stringHasValue}}" />
                            <Grid StyleClass="box-row"
                                  IsVisible="{Binding Cipher.Login.Password, Converter={StaticResource stringHasValue}}"
                                  AutomationId="ItemRow">
                                <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"
                                    AutomationId="ItemName" />
                                <controls:MonoLabel
                                    Text="{Binding Cipher.Login.MaskedPassword, Mode=OneWay}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    IsVisible="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                                    AutomationId="ItemValue" />
                                <controls:MonoLabel
                                    Text="{Binding ColoredPassword, Mode=OneWay}"
                                    StyleClass="box-value, text-html"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    LineBreakMode="CharacterWrap"
                                    IsVisible="{Binding ShowPassword}"
                                    AutomationId="ItemValue" />
                                <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}"
                                    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}"
                                    AutomationId="ShowValueButton" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                                    Command="{Binding CopyCommand}"
                                    CommandParameter="LoginPassword"
                                    Grid.Row="0"
                                    Grid.Column="3"
                                    Grid.RowSpan="2"
                                    SemanticProperties.Description="{u:I18n CopyPassword}"
                                    IsVisible="{Binding Cipher.ViewPassword}"
                                    AutomationId="CopyValueButton" />
                            </Grid>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Login.Password, Converter={StaticResource stringHasValue}}" />
                            <Label
                                Text="{u:I18n Passkey}"
                                StyleClass="box-label"
                                Margin="0,10,0,0"
                                IsVisible="{Binding Cipher.Login.MainFido2Credential, Converter={StaticResource notNull}}"/>
                            <Entry
                                Text="{Binding Cipher.Login.MainFido2Credential.CreationDate, Mode=OneWay, Converter={StaticResource dateTime}, FallbackValue=''}"
                                IsEnabled="False"
                                StyleClass="box-value,text-muted"
                                IsVisible="{Binding Cipher.Login.MainFido2Credential, Converter={StaticResource notNull}, FallbackValue=False}" />
                            <Grid StyleClass="box-row"
                                  IsVisible="{Binding ShowTotp}"
                                  AutomationId="ItemRow">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="40" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Label
                                    Text="{u:I18n VerificationCodeTotp}"
                                    StyleClass="box-label"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    AutomationId="ItemName" />
                                <controls:MonoLabel
                                    Text="{Binding TotpCodeFormatted, Mode=OneWay}"
                                    IsVisible="{Binding ShowUpgradePremiumTotpText, Converter={StaticResource inverseBool}}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    VerticalTextAlignment="Start"
                                    VerticalOptions="Start"
                                    AutomationId="ItemValue" />
                                <controls:CircularProgressbarView
                                    Progress="{Binding TotpProgress}"
                                    Grid.Row="0"
                                    Grid.Column="1"
                                    Grid.RowSpan="2"
                                    HorizontalOptions="FillAndExpand"
                                    VerticalOptions="FillAndExpand"
                                    AutomationId="LoginTotpProgressBar" />
                                <Label
                                    Text="{Binding TotpSec, Mode=OneWay}"
                                    Style="{DynamicResource textTotp}"
                                    Grid.Row="0"
                                    Grid.Column="1"
                                    Grid.RowSpan="2"
                                    StyleClass="text-sm"
                                    VerticalTextAlignment="Center"
                                    HorizontalTextAlignment="Center"
                                    HorizontalOptions="FillAndExpand"
                                    VerticalOptions="FillAndExpand" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                                    Command="{Binding CopyCommand}"
                                    IsVisible="{Binding CanAccessPremium}"
                                    CommandParameter="LoginTotp"
                                    Grid.Row="0"
                                    Grid.Column="2"
                                    Grid.RowSpan="2"
                                    SemanticProperties.Description="{u:I18n CopyTotp}"
                                    AutomationId="CopyValueButton" />
                                <Label
                                    Text="{u:I18n PremiumSubscriptionRequired}"
                                    StyleClass="box-footer-label"
                                    IsVisible="{Binding ShowUpgradePremiumTotpText}"
                                    Margin="0,5,0,2"
                                    Grid.Column="0"
                                    Grid.Row="1"
                                    HorizontalOptions="FillAndExpand"
                                    AutomationId="ShowUpgradePremiumTotpLabel" />
                            </Grid>
                            <BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowTotp}" />
                        </StackLayout>
                        <StackLayout IsVisible="{Binding IsCard}" Spacing="0" Padding="0">
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Card.CardholderName, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n CardholderName}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Card.CardholderName, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Card.CardholderName, Converter={StaticResource stringHasValue}}" />
                            <Grid StyleClass="box-row"
                                  IsVisible="{Binding Cipher.Card.Number, Converter={StaticResource stringHasValue}}"
                                  AutomationId="ItemRow">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Label
                                    Text="{u:I18n Number}"
                                    StyleClass="box-label"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    AutomationId="ItemName" />
                                <controls:MonoLabel
                                    Text="{Binding Cipher.Card.MaskedNumber, Mode=OneWay}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    IsVisible="{Binding ShowCardNumber, Converter={StaticResource inverseBool}}"
                                    AutomationId="ItemValue" />
                                <controls:MonoLabel
                                    Text="{Binding Cipher.Card.Number, Mode=OneWay}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    IsVisible="{Binding ShowCardNumber}"
                                    AutomationId="ItemValue" />
                                <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="ShowValueButton" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                                    Command="{Binding CopyCommand}"
                                    CommandParameter="CardNumber"
                                    Grid.Row="0"
                                    Grid.Column="2"
                                    Grid.RowSpan="2"
                                    SemanticProperties.Description="{u:I18n CopyNumber}"
                                    AutomationId="CopyValueButton" />
                            </Grid>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Card.Number, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Card.Brand, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n Brand}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Card.Brand, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Card.Brand, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Card.Expiration, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n Expiration}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Card.Expiration, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Card.Expiration, Converter={StaticResource stringHasValue}}" />
                            <Grid StyleClass="box-row"
                                  IsVisible="{Binding Cipher.Card.Code, Converter={StaticResource stringHasValue}}"
                                  AutomationId="ItemRow">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Label
                                    Text="{u:I18n SecurityCode}"
                                    StyleClass="box-label"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    AutomationId="ItemName" />
                                <controls:MonoLabel
                                    Text="{Binding Cipher.Card.MaskedCode, Mode=OneWay}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    IsVisible="{Binding ShowCardCode, Converter={StaticResource inverseBool}}"
                                    AutomationId="ItemValue" />
                                <controls:MonoLabel
                                    Text="{Binding Cipher.Card.Code, Mode=OneWay}"
                                    StyleClass="box-value"
                                    Grid.Row="1"
                                    Grid.Column="0"
                                    IsVisible="{Binding ShowCardCode}"
                                    AutomationId="ItemValue" />
                                <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="ShowValueButton" />
                                <controls:IconButton
                                    StyleClass="box-row-button, box-row-button-platform"
                                    Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                                    Command="{Binding CopyCommand}"
                                    CommandParameter="CardCode"
                                    Grid.Row="0"
                                    Grid.Column="2"
                                    Grid.RowSpan="2"
                                    SemanticProperties.Description="{u:I18n CopySecurityCode}"
                                    AutomationId="CopyValueButton" />
                            </Grid>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Card.Code, Converter={StaticResource stringHasValue}}" />
                        </StackLayout>
                        <StackLayout IsVisible="{Binding IsIdentity}" Spacing="0" Padding="0">
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.FullName, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n IdentityName}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.FullName, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.FullName, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.Username, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n Username}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.Username, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.Username, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.Company, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n Company}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.Company, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.Company, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.SSN, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n SSN}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.SSN, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.SSN, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.PassportNumber, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n PassportNumber}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.PassportNumber, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.PassportNumber, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.LicenseNumber, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n LicenseNumber}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.LicenseNumber, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.LicenseNumber, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.Email, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n Email}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.Email, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.Email, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row"
                                         IsVisible="{Binding Cipher.Identity.Phone, Converter={StaticResource stringHasValue}}"
                                         AutomationId="ItemRow" >
                                <Label
                                    Text="{u:I18n Phone}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.Phone, Mode=OneWay}"
                                    StyleClass="box-value"
                                    AutomationId="ItemValue" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator"
                                     IsVisible="{Binding Cipher.Identity.Phone, Converter={StaticResource stringHasValue}}" />
                            <StackLayout StyleClass="box-row" IsVisible="{Binding ShowIdentityAddress}"
                                         AutomationId="ItemRow">
                                <Label
                                    Text="{u:I18n Address}"
                                    StyleClass="box-label"
                                    AutomationId="ItemName" />
                                <Label
                                    Text="{Binding Cipher.Identity.Address1, Mode=OneWay}"
                                    IsVisible="{Binding Cipher.Identity.Address1, Converter={StaticResource stringHasValue}}"
                                    StyleClass="box-value"
                                    AutomationId="IdentityAddressOneLabel" />
                                <Label
                                    Text="{Binding Cipher.Identity.Address2, Mode=OneWay}"
                                    IsVisible="{Binding Cipher.Identity.Address2, Converter={StaticResource stringHasValue}}"
                                    StyleClass="box-value"
                                    AutomationId="IdentityAddressTwoLabel" />
                                <Label
                                    Text="{Binding Cipher.Identity.Address3, Mode=OneWay}"
                                    IsVisible="{Binding Cipher.Identity.Address3, Converter={StaticResource stringHasValue}}"
                                    StyleClass="box-value"
                                    AutomationId="IdentityAddressThreeLabel" />
                                <Label
                                    Text="{Binding Cipher.Identity.FullAddressPart2, Mode=OneWay}"
                                    IsVisible="{Binding Cipher.Identity.FullAddressPart2, Converter={StaticResource stringHasValue}}"
                                    StyleClass="box-value"
                                    AutomationId="IdentityFullAddressPartTwoLabel" />
                                <Label
                                    Text="{Binding Cipher.Identity.Country, Mode=OneWay}"
                                    IsVisible="{Binding Cipher.Identity.Country, Converter={StaticResource stringHasValue}}"
                                    StyleClass="box-value"
                                    AutomationId="IdentityCountryLabel" />
                            </StackLayout>
                            <BoxView StyleClass="box-row-separator" IsVisible="{Binding ShowIdentityAddress}" />
                        </StackLayout>
                    </StackLayout>
                    <StackLayout StyleClass="box" IsVisible="{Binding ShowUris}">
                        <StackLayout StyleClass="box-row-header">
                            <Label Text="{u:I18n URIs, Header=True}"
                                   StyleClass="box-header, box-header-platform" />
                        </StackLayout>
                        <controls:RepeaterView ItemsSource="{Binding Cipher.Login.Uris}" AutomationId="CipherUriContainer">
                            <controls:RepeaterView.ItemTemplate>
                                <DataTemplate x:DataType="views:LoginUriView">
                                    <StackLayout Spacing="0" Padding="0">
                                        <Grid StyleClass="box-row" AutomationId="UriRow">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <Label
                                                Text="{u:I18n URI}"
                                                StyleClass="box-label"
                                                Grid.Row="0"
                                                Grid.Column="0"
                                                IsVisible="{Binding IsWebsite, Mode=OneWay, Converter={StaticResource inverseBool}}" />
                                            <Label
                                                Text="{u:I18n Website}"
                                                StyleClass="box-label"
                                                Grid.Row="0"
                                                Grid.Column="0"
                                                IsVisible="{Binding IsWebsite, Mode=OneWay}" />
                                            <Label
                                                Text="{Binding HostOrUri, Mode=OneWay}"
                                                StyleClass="box-value"
                                                Grid.Row="1"
                                                Grid.Column="0"
                                                AutomationId="UriValue" />
                                            <controls:IconButton
                                                StyleClass="box-row-button, box-row-button-platform"
                                                Text="{Binding Source={x:Static core:BitwardenIcons.ShareSquare}}"
                                                Command="{Binding BindingContext.LaunchUriCommand, Source={x:Reference _page}}"
                                                CommandParameter="{Binding .}"
                                                Grid.Row="0"
                                                Grid.Column="1"
                                                Grid.RowSpan="2"
                                                IsVisible="{Binding CanLaunch, Mode=OneWay}"
                                                SemanticProperties.Description="{u:I18n Launch}"
                                                AutomationId="LaunchUriButton" />
                                            <controls:IconButton
                                                StyleClass="box-row-button, box-row-button-platform"
                                                Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                                                Command="{Binding BindingContext.CopyUriCommand, Source={x:Reference _page}}"
                                                CommandParameter="{Binding .}"
                                                Grid.Row="0"
                                                Grid.Column="2"
                                                Grid.RowSpan="2"
                                                SemanticProperties.Description="{u:I18n Copy}"
                                                AutomationId="CopyUriButton" />
                                        </Grid>
                                        <BoxView StyleClass="box-row-separator" />
                                    </StackLayout>
                                </DataTemplate>
                            </controls:RepeaterView.ItemTemplate>
                        </controls:RepeaterView>
                    </StackLayout>
                    <StackLayout StyleClass="box"
                                 IsVisible="{Binding Cipher.Notes, Converter={StaticResource stringHasValue}}">
                        <StackLayout StyleClass="box-row-header">
                            <Label Text="{u:I18n Notes, Header=True}"
                                   StyleClass="box-header, box-header-platform" />
                        </StackLayout>
                        <StackLayout StyleClass="box-row" AutomationId="NotesRow">
                            <controls:SelectableLabel
                                Text="{Binding Cipher.Notes, Mode=OneWay}"
                                StyleClass="box-value"
                                AutomationId="CipherNotesLabel" />
                        </StackLayout>
                        <BoxView StyleClass="box-row-separator" />
                    </StackLayout>
                    <StackLayout StyleClass="box" IsVisible="{Binding Cipher.HasFields}" AutomationId="CustomFieldsContainer">
                        <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}" />
                    </StackLayout>
                    <StackLayout StyleClass="box" IsVisible="{Binding ShowAttachments}">
                        <StackLayout StyleClass="box-row-header">
                            <Label Text="{u:I18n Attachments, Header=True}"
                                   StyleClass="box-header, box-header-platform" />
                        </StackLayout>
                        <controls:RepeaterView ItemsSource="{Binding Cipher.Attachments}" AutomationId="CipherAttachmentsContainer">
                            <controls:RepeaterView.ItemTemplate>
                                <DataTemplate x:DataType="views:AttachmentView">
                                    <StackLayout Spacing="0" Padding="0">
                                        <StackLayout Orientation="Horizontal" StyleClass="box-row" Spacing="10" AutomationId="CipherAttachment">
                                            <Label
                                                Text="{Binding FileName, Mode=OneWay}"
                                                StyleClass="box-value"
                                                VerticalTextAlignment="Center"
                                                HorizontalOptions="StartAndExpand"
                                                AutomationId="CipherAttachmentFileNameLabel" />
                                            <Label
                                                Text="{Binding SizeName, Mode=OneWay}"
                                                StyleClass="box-sub-label"
                                                HorizontalTextAlignment="End"
                                                VerticalTextAlignment="Center"
                                                AutomationId="CipherAttachmentFileSizeLabel" />
                                            <controls:IconButton
                                                StyleClass="box-row-button, box-row-button-platform"
                                                Text="{Binding Source={x:Static core:BitwardenIcons.Download}}"
                                                Command="{Binding BindingContext.DownloadAttachmentCommand, Source={x:Reference _page}}"
                                                CommandParameter="{Binding .}"
                                                VerticalOptions="Center"
                                                SemanticProperties.Description="{u:I18n Download}"
                                                AutomationId="CipherAttachmentDownloadButton" />
                                        </StackLayout>
                                        <BoxView StyleClass="box-row-separator" />
                                    </StackLayout>
                                </DataTemplate>
                            </controls:RepeaterView.ItemTemplate>
                        </controls:RepeaterView>
                    </StackLayout>
                    <StackLayout StyleClass="box-bottom">
                        <Label FormattedText="{Binding UpdatedText}"
                               StyleClass="box-footer-label"
                               AutomationId="CipherUpdatedDateLabel" />
                        <Label FormattedText="{Binding PasswordUpdatedText}"
                               StyleClass="box-footer-label"
                               IsVisible="{Binding Cipher.PasswordRevisionDisplayDate, Converter={StaticResource notNull}}"
                               AutomationId="CipherUpdatedPasswordDateLabel">
                            <Label.GestureRecognizers>
                                <TapGestureRecognizer Tapped="PasswordHistory_Tapped" />
                            </Label.GestureRecognizers>
                        </Label>
                        <Label FormattedText="{Binding PasswordHistoryText}"
                               StyleClass="box-footer-label"
                               IsVisible="{Binding Cipher.HasPasswordHistory}"
                               AutomationId="CipherPasswordHistoryLabel">
                            <Label.GestureRecognizers>
                                <TapGestureRecognizer Tapped="PasswordHistory_Tapped" />
                            </Label.GestureRecognizers>
                        </Label>
                    </StackLayout>
                </StackLayout>
            </ScrollView>

        </ResourceDictionary>
    </ContentPage.Resources>

    <AbsoluteLayout
        x:Name="_absLayout"
        VerticalOptions="FillAndExpand"
        HorizontalOptions="FillAndExpand">
        <ContentView
            x:Name="_mainContent"
            AbsoluteLayout.LayoutFlags="All"
            AbsoluteLayout.LayoutBounds="0, 0, 1, 1">
        </ContentView>
        <Button
            x:Name="_fab"
            ImageSource="pencil.png"
            Clicked="EditButton_Clicked"
            Style="{StaticResource btn-fab}"
            AbsoluteLayout.LayoutFlags="PositionProportional"
            AbsoluteLayout.LayoutBounds="1, 1, AutoSize, AutoSize"
            SemanticProperties.Description="{u:I18n EditItem}"
            AutomationId="CipherEditButton"
            IsVisible="{Binding CanEdit}"/>
    </AbsoluteLayout>

</pages:BaseContentPage>