<?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.PasswordHistoryPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    xmlns:views="clr-namespace:Bit.Core.Models.View;assembly=BitwardenCore"
    xmlns:core="clr-namespace:Bit.Core;assembly=BitwardenCore"
    x:DataType="pages:PasswordHistoryPageViewModel"
    x:Name="_page"
    Title="{Binding PageTitle}">

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

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="{u:I18n Close}" Clicked="Close_Clicked" Order="Primary" Priority="-1" />
    </ContentPage.ToolbarItems>

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <u:DateTimeConverter x:Key="dateTime" />
            <u:ColoredPasswordConverter x:Key="coloredPassword" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <StackLayout x:Name="_mainLayout">
        <Label IsVisible="{Binding ShowNoData}"
               Text="{u:I18n NoPasswordsToList}"
               Margin="20, 0"
               VerticalOptions="CenterAndExpand"
               HorizontalOptions="CenterAndExpand"
               HorizontalTextAlignment="Center"></Label>
        <controls:ExtendedCollectionView
                  IsVisible="{Binding ShowNoData, Converter={StaticResource inverseBool}}"
                  ItemsSource="{Binding History}"
                  VerticalOptions="FillAndExpand"
                  StyleClass="list, list-platform"
                  ExtraDataForLogging="Password History Page">
            <CollectionView.ItemTemplate>
                <DataTemplate x:DataType="views:PasswordHistoryView">
                    <Grid
                        StyleClass="list-row, list-row-platform"
                        Padding="10"
                        RowSpacing="0"
                        ColumnSpacing="10">

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <controls:MonoLabel LineBreakMode="CharacterWrap"
                            Grid.Column="0"
                            Grid.Row="0"
                            StyleClass="list-title, list-title-platform, text-html"
                            Text="{Binding Password, Mode=OneWay, Converter={StaticResource coloredPassword}}" />
                        <Label LineBreakMode="TailTruncation"
                            Grid.Column="0"
                            Grid.Row="1"
                            StyleClass="list-subtitle, list-subtitle-platform"
                            Text="{Binding LastUsedDate, Mode=OneWay, Converter={StaticResource dateTime}}" />
                        <controls:IconButton
                            StyleClass="list-row-button, list-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.Clone}}"
                            Command="{Binding BindingContext.CopyCommand, Source={x:Reference _page}}"
                            CommandParameter="{Binding .}"
                            Grid.Row="0"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            AutomationProperties.IsInAccessibleTree="True"
                            AutomationProperties.Name="{u:I18n CopyPassword}" />
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </controls:ExtendedCollectionView>
    </StackLayout>

</pages:BaseContentPage>
