<?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"
    xmlns:xct="http://xamarin.com/schemas/2020/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;assembly=BitwardenCore"
    xmlns:core="clr-namespace:Bit.Core;assembly=BitwardenCore"
    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" />
            <xct:ItemSelectedEventArgsConverter x:Key="ItemSelectedEventArgsConverter" />
            <controls:SelectionChangedEventArgsConverter x:Key="SelectionChangedEventArgsConverter" />
            <DataTemplate
                x:Key="loginRequestTemplate"
                x:DataType="models:PasswordlessLoginResponse">
                    <Grid
                        Padding="10, 0"
                        RowSpacing="0"
                        RowDefinitions="*, Auto, *, 10"
                        ColumnDefinitions="*, *">
                        <Label
                            Text="{u:I18n FingerprintPhrase}"
                            FontSize="Small"
                            Padding="0, 10, 0 ,0"
                            FontAttributes="Bold"/>
                        <controls:MonoLabel
                            FormattedText="{Binding FingerprintPhrase}"
                            Grid.Row="1"
                            Grid.ColumnSpan="2"
                            FontSize="Small"
                            Padding="0, 5, 0, 10"
                            VerticalTextAlignment="Center"
                            TextColor="{DynamicResource FingerprintPhrase}"/>
                        <Label
                            Grid.Row="2"
                            HorizontalOptions="Start"
                            HorizontalTextAlignment="Start"
                            Text="{Binding RequestDeviceType}"
                            StyleClass="list-header-sub" />
                        <Label
                            Grid.Row="2"
                            Grid.Column="1"
                            HorizontalOptions="End"
                            HorizontalTextAlignment="End"
                            Text="{Binding CreationDate, Converter={StaticResource dateTime}}"
                            StyleClass="list-header-sub" />
                        <BoxView
                            StyleClass="list-section-separator-top, list-section-separator-top-platform"
                            VerticalOptions="End"
                            Grid.Row="3"
                            Grid.ColumnSpan="2"/>
                    </Grid>
	        </DataTemplate>

            <StackLayout
                x:Key="mainLayout"
                x:Name="_mainLayout"
                Padding="0, 10">
                <RefreshView
                    IsRefreshing="{Binding IsRefreshing}"
                    Command="{Binding RefreshCommand}"
                    VerticalOptions="FillAndExpand"
                    BackgroundColor="{DynamicResource BackgroundColor}">
                    <controls:ExtendedCollectionView
                        ItemsSource="{Binding LoginRequests}"
                        ItemTemplate="{StaticResource loginRequestTemplate}"
                        SelectionMode="Single"
                        ExtraDataForLogging="Login requests page" >
                        <controls:ExtendedCollectionView.Behaviors>
                            <xct:EventToCommandBehavior
                                EventName="SelectionChanged"
                                Command="{Binding AnswerRequestCommand}"
                                EventArgsConverter="{StaticResource SelectionChangedEventArgsConverter}" />
                        </controls:ExtendedCollectionView.Behaviors>
                    </controls:ExtendedCollectionView>
                </RefreshView>
                <controls:IconLabelButton
                        VerticalOptions="End"
                        Margin="10,0"
                        Icon="{Binding Source={x:Static core:BitwardenIcons.Trash}}"
                        Label="{u:I18n DeclineAllRequests}"
                        ButtonCommand="{Binding DeclineAllRequestsCommand}"/>
            </StackLayout>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentView 
        x:Name="_mainContent">
    </ContentView>

</pages:BaseContentPage>

