<?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.LoginPage"
    xmlns:pages="clr-namespace:Bit.App.Pages"
    xmlns:core="clr-namespace:Bit.Core;assembly=BitwardenCore"
    xmlns:controls="clr-namespace:Bit.App.Controls"
    xmlns:u="clr-namespace:Bit.App.Utilities"
    x:DataType="pages:LoginPageViewModel"
    x:Name="_page"
    Title="{Binding PageTitle}">
    
    <ContentPage.BindingContext>
        <pages:LoginPageViewModel />
    </ContentPage.BindingContext>

    <ContentPage.ToolbarItems>
        <controls:ExtendedToolbarItem
                x:Name="_accountAvatar"
                x:Key="accountAvatar"
                IconImageSource="{Binding AvatarImageSource}"
                Command="{Binding Source={x:Reference _accountListOverlay}, Path=ToggleVisibililtyCommand}"
                Order="Primary"
                Priority="-1"
                UseOriginalImage="True"
                AutomationProperties.IsInAccessibleTree="True"
                AutomationProperties.Name="{u:I18n Account}" />
    </ContentPage.ToolbarItems>

    <ContentPage.Resources>
        <ResourceDictionary>
            <u:InverseBoolConverter x:Key="inverseBool" />
            <ToolbarItem Icon="more_vert.png" Clicked="More_Clicked" Order="Primary"
                x:Name="_moreItem" x:Key="moreItem"
                 AutomationProperties.IsInAccessibleTree="True"
                 AutomationProperties.Name="{u:I18n Options}" />
            <ToolbarItem Text="{u:I18n GetPasswordHint}"
                x:Key="getPasswordHint"
                x:Name="_getPasswordHint"
                Clicked="Hint_Clicked" 
                Order="Secondary" />
            <ToolbarItem Text="{u:I18n RemoveAccount}"
                x:Key="removeAccount"
                x:Name="_removeAccount"
                Clicked="RemoveAccount_Clicked" 
                Order="Secondary" />

            <ScrollView x:Name="_mainLayout" x:Key="mainLayout">
                <StackLayout Spacing="0">
                    <StackLayout StyleClass="box">
                        <Grid StyleClass="box-row">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Label
                                Text="{u:I18n MasterPassword}"
                                StyleClass="box-label"
                                Padding="0, 10, 0, 0"
                                Grid.Row="0"
                                Grid.Column="0" />
                            <controls:MonoEntry
                                x:Name="_masterPassword"
                                Text="{Binding MasterPassword}"
                                StyleClass="box-value"
                                IsSpellCheckEnabled="False"
                                IsTextPredictionEnabled="False"
                                IsPassword="{Binding ShowPassword, Converter={StaticResource inverseBool}}"
                                Grid.Row="1"
                                Grid.Column="0"
                                ReturnType="Go"
                                ReturnCommand="{Binding LogInCommand}" />
                            <controls:IconButton
                                StyleClass="box-row-button, box-row-button-platform"
                                Text="{Binding ShowPasswordIcon}"
                                Command="{Binding TogglePasswordCommand}"
                                Grid.Row="1"
                                Grid.Column="1"
                                Grid.RowSpan="1"
                                AutomationProperties.IsInAccessibleTree="True"
                                AutomationProperties.Name="{u:I18n ToggleVisibility}"
                                AutomationProperties.HelpText="{Binding PasswordVisibilityAccessibilityText}"/>
                            <Label
                                Text="{u:I18n GetMasterPasswordwordHint}"
                                StyleClass="box-footer-label"
                                TextColor="{DynamicResource HyperlinkColor}"
                                Padding="0,5,0,0"
                                Grid.Row="2"
                                Grid.Column="0"
                                Grid.ColumnSpan="2">
                                <Label.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="Hint_Clicked" />
                                </Label.GestureRecognizers>
                            </Label>
                        </Grid>
                    </StackLayout>
                    <StackLayout Padding="10, 10">
                        <Button x:Name="_loginWithMasterPassword"
                            Text="{u:I18n LogInWithMasterPassword}" 
                                StyleClass="btn-primary"
                                Clicked="LogIn_Clicked" />
                        <controls:IconLabelButton
                            HorizontalOptions="Fill"
                            VerticalOptions="CenterAndExpand"
                            Icon="{Binding Source={x:Static core:BitwardenIcons.Device}}"
                            Label="{u:I18n LogInWithAnotherDevice}"
                            ButtonCommand="{Binding LogInWithDeviceCommand}"
                            IsVisible="{Binding IsKnownDevice}"/>
                        <controls:IconLabelButton
                            HorizontalOptions="Fill"
                            VerticalOptions="CenterAndExpand"
                            Icon="{Binding Source={x:Static core:BitwardenIcons.Suitcase}}"
                            Label="{u:I18n LogInSso}">
                            <controls:IconLabelButton.GestureRecognizers>
                                <TapGestureRecognizer Tapped="LogInSSO_Clicked" />
                            </controls:IconLabelButton.GestureRecognizers>
                        </controls:IconLabelButton>
                        <Label
                            Text="{Binding LoggingInAsText}"
                            StyleClass="text-sm"
                            Margin="0,40,0,0"/>
                        <Label
                            Text="{u:I18n NotYou}"
                            StyleClass="text-md"
                            HorizontalOptions="Start"
                            TextColor="{DynamicResource HyperlinkColor}">
                            <Label.GestureRecognizers>
                                <TapGestureRecognizer Tapped="Cancel_Clicked" />
                            </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>

        <controls:AccountSwitchingOverlayView
            x:Name="_accountListOverlay"
            AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
            AbsoluteLayout.LayoutFlags="All"
            MainPage="{Binding Source={x:Reference _page}}"
            BindingContext="{Binding AccountSwitchingOverlayViewModel}"/>
    </AbsoluteLayout>

</pages:BaseContentPage>
