<?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.GeneratorHistoryPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    xmlns:domain="clr-namespace:Bit.Core.Models.Domain"
    xmlns:core="clr-namespace:Bit.Core"
    x:DataType="pages:GeneratorHistoryPageViewModel"
    x:Name="_page"
    Title="{Binding PageTitle}">

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

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <u:DateTimeConverter x:Key="dateTime" />
            <u:ColoredPasswordConverter x:Key="coloredPassword" />
            <ToolbarItem Text="{u:I18n Close}" Clicked="Close_Clicked" Order="Primary" Priority="-1"
                         x:Name="_closeItem" x:Key="closeItem" />
            <ToolbarItem Text="{u:I18n Clear}"
                         Clicked="Clear_Clicked"
                         Order="Secondary"
                         x:Name="_clearItem"
                         x:Key="clearItem"
                         AutomationId="ClearPasswordList" />
            <ToolbarItem IconImageSource="more_vert.png"
                         SemanticProperties.Description="{u:I18n Options}"
                         Clicked="More_Clicked"
                         x:Name="_moreItem"
                         x:Key="moreItem" />
        </ResourceDictionary>
    </ContentPage.Resources>

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

                        <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}}"
                            AutomationId="GeneratedPasswordValue" />
                        <Label LineBreakMode="TailTruncation"
                            Grid.Column="0"
                            Grid.Row="1"
                            StyleClass="list-subtitle, list-subtitle-platform"
                            Text="{Binding Date, Mode=OneWay, Converter={StaticResource dateTime}}"
                            AutomationId="GeneratedPasswordDateLabel" />
                        <controls:IconButton
                            StyleClass="list-row-button, list-row-button-platform"
                            Text="{Binding Source={x:Static core:BitwardenIcons.Paste}}"
                            Command="{Binding BindingContext.CopyCommand, Source={x:Reference _page}}"
                            CommandParameter="{Binding .}"
                            Grid.Row="0"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            SemanticProperties.Description="{u:I18n CopyPassword}"
                            AutomationId="CopyPasswordValueButton" />
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </controls:ExtendedCollectionView>
    </StackLayout>

</pages:BaseContentPage>
