<?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"
    xmlns:xct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    x:Class="Bit.App.Pages.LoginPasswordlessRequestsListPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    x:DataType="pages:LoginPasswordlessRequestsListViewModel"
    xmlns:models="clr-namespace:Bit.Core.Models.Response"
    xmlns:core="clr-namespace:Bit.Core"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    Title="{Binding PageTitle}">
    
    <ContentPage.BindingContext>
        <pages:LoginPasswordlessRequestsListViewModel />
    </ContentPage.BindingContext>

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

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:DateTimeConverter x:Key="dateTime" />
            <u:InverseBoolConverter x:Key="inverseBool" />
            <controls:SelectionChangedEventArgsConverter x:Key="SelectionChangedEventArgsConverter" />
            <DataTemplate
                x:Key="loginRequestTemplate"
                x:DataType="models:PasswordlessLoginResponse">
                    <Grid
                        Padding="10, 0"
                        RowSpacing="0"
                        RowDefinitions="*, Auto, *, 10"
                        ColumnDefinitions="*, *"
                        AutomationId="LoginRequestCell">
                        <Label
                            Text="{u:I18n FingerprintPhrase}"
                            FontSize="Small"
                            FontAttributes="Bold"/>
                        <controls:MonoLabel
                            Text="{Binding FingerprintPhrase}"
                            Grid.Row="1"
                            Grid.ColumnSpan="2"
                            FontSize="Small"
                            Padding="0, 5, 0, 10"
                            VerticalTextAlignment="Center"
                            TextColor="{DynamicResource FingerprintPhrase}"
                            AutomationId="FingerprintPhraseLabel" />
                        <Label
                            Grid.Row="2"
                            HorizontalOptions="Start"
                            HorizontalTextAlignment="Start"
                            Text="{Binding RequestDeviceType}"
                            StyleClass="list-header-sub"
                            AutomationId="RequestDeviceLabel" />
                        <Label
                            Grid.Row="2"
                            Grid.Column="1"
                            HorizontalOptions="End"
                            HorizontalTextAlignment="End"
                            Text="{Binding CreationDate, Converter={StaticResource dateTime}}"
                            StyleClass="list-header-sub"
                            AutomationId="RequestDateLabel" />
                        <BoxView
                            StyleClass="list-section-separator-top, list-section-separator-top-platform"
                            VerticalOptions="End"
                            Grid.Row="3"
                            Grid.ColumnSpan="2"/>
                    </Grid>
	        </DataTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>

    <Grid
        RowDefinitions="*, Auto"
        Padding="0, 10">
        <RefreshView
            Grid.Row="0"
            IsRefreshing="{Binding IsRefreshing}"
            Command="{Binding RefreshCommand}"
            VerticalOptions="Fill"
            BackgroundColor="{DynamicResource BackgroundColor}">
            <Grid RowDefinitions="Auto, *">
                <VerticalStackLayout Grid.Row="0" 
                                     HorizontalOptions="Center">
                    <Image
                        x:Name="_emptyPlaceholder"
                        Source="empty_login_requests"
                        WidthRequest="160"
                        HeightRequest="160"
                        Margin="0,70,0,0"
                        IsVisible="{Binding HasLoginRequests, Converter={StaticResource inverseBool}}"
                        SemanticProperties.Description="{u:I18n NoPendingRequests}" />
                    <controls:CustomLabel
                        StyleClass="box-label-regular"
                        Text="{u:I18n NoPendingRequests}"
                        IsVisible="{Binding HasLoginRequests, Converter={StaticResource inverseBool}}"
                        FontAttributes="{OnPlatform iOS=Bold}"
                        FontWeight="500"
                        Margin="14,10,14,0"/>
                </VerticalStackLayout>
                <controls:ExtendedCollectionView
                    Grid.Row="1"
                    ItemsSource="{Binding LoginRequests}"
                    ItemTemplate="{StaticResource loginRequestTemplate}"
                    SelectionMode="Single"
                    IsVisible="{Binding HasLoginRequests}"
                    ExtraDataForLogging="Login requests page" >
                    <controls:ExtendedCollectionView.Behaviors>
                        <xct:EventToCommandBehavior
                            EventName="SelectionChanged"
                            Command="{Binding AnswerRequestCommand}"
                            EventArgsConverter="{StaticResource SelectionChangedEventArgsConverter}" />
                    </controls:ExtendedCollectionView.Behaviors>
                </controls:ExtendedCollectionView>
            </Grid>
        </RefreshView>
        
        <controls:IconLabelButton
            Grid.Row="1"
            VerticalOptions="End"
            Margin="10,0"
            Icon="{Binding Source={x:Static core:BitwardenIcons.Trash}}"
            Label="{u:I18n DeclineAllRequests}"
            ButtonCommand="{Binding DeclineAllRequestsCommand}"
            IsVisible="{Binding HasLoginRequests}"
            AutomationId="DeleteAllRequestsButton" />

        <Grid x:Name="_activityIndicatorGrid" Grid.Row="0" Grid.RowSpan="2" BackgroundColor="{DynamicResource BackgroundColor}">
            <ActivityIndicator IsRunning="True"
                               VerticalOptions="Center" 
                               HorizontalOptions="Center" />
        </Grid>
    </Grid>

</pages:BaseContentPage>

