<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="GMCabsDriverAssistantSolution.Views.AdminPasswordPage"
             xmlns:vm="clr-namespace:GMCabsDriverAssistantSolution.ViewModels"
             xmlns:custom="clr-namespace:GMCabsDriverAssistantSolution.CustomControls"
             Shell.FlyoutBehavior="Disabled"
             Shell.NavBarIsVisible="False">
    <ContentPage.BindingContext>
        <vm:AdminPasswordViewModel />
    </ContentPage.BindingContext>
    <ContentPage.Resources>
        <ResourceDictionary>
            <Style x:Key="EntryStyle" TargetType="Entry">
                <Setter Property="TextColor" Value="#000"></Setter>
                <Setter Property="PlaceholderColor" Value="#9999"></Setter>
                <Setter Property="TranslationY"  Value="1" />
                <Setter Property="MinimumHeightRequest" Value="36" />
            </Style>
            <Style x:Key="NoUnderlineEntryFrameStyle" TargetType="Frame">
                <Setter Property="Padding">
                    <OnPlatform x:TypeArguments="Thickness">
                        <On Platform="Android">16,4</On>
                        <On Platform="iOS">16</On>
                    </OnPlatform>
                </Setter>
                <Setter Property="CornerRadius" Value="12"></Setter>
                <Setter Property="Margin" Value="4,8,4,4"></Setter>
                <Setter Property="HasShadow" Value="True"></Setter>
                <Setter Property="MinimumHeightRequest" Value="50" />
                <Setter Property="BackgroundColor" Value="White" />
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>

    <ContentPage.Content>
        <StackLayout Orientation="Vertical" 
                     BackgroundColor="#DCDCDC">
            <StackLayout.Padding>
                <OnPlatform x:TypeArguments="Thickness">
                    <On Platform="Android">20</On>
                    <On Platform="iOS">20,60</On>
                </OnPlatform>
            </StackLayout.Padding>
            <Image Source="{OnIdiom Phone='gmlogo.png',Tablet='gmlogo_tablet.png'}" 
                   Margin="{OnIdiom Phone='48,30,48,12',Tablet='48,-40,48,-30'}" 
                   Scale="{OnIdiom Phone='1.2',Tablet='0.4'}"/>
            <Frame Style="{StaticResource NoUnderlineEntryFrameStyle}" Margin="{OnIdiom Tablet='270,0,270,0'}">
                <Grid MinimumHeightRequest="50">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <custom:NoUnderlineEntry x:Name="Pin"
                                             Grid.Column="0"                                             
                                             FontSize="20"
                                             Keyboard="Text"                                             
                                             Text="{Binding AdminPassword}"
                                             Placeholder="Admin Password"
                                             IsPassword="True"
                                             Style="{StaticResource EntryStyle}"/>
                </Grid>
            </Frame>
            <Grid Margin="20,30,20,0"
                  MinimumHeightRequest="40">
                <ActivityIndicator IsRunning="True" IsVisible="{Binding IsBusy}"/>
                <Button Text="Continue" 
                        FontSize="20"
                        Command="{Binding ContinueCommand}"
                        IsVisible="{Binding IsBusy}"
                        MinimumHeightRequest="40"
                        Margin="{OnIdiom Tablet='270,0,270,0'}">
                    <Button.Triggers>
                        <DataTrigger TargetType="Button" Binding="{Binding IsBusy}" Value="False">
                            <Setter Property="IsVisible" Value="True" />
                        </DataTrigger>
                        <DataTrigger TargetType="Button" Binding="{Binding IsBusy}" Value="True">
                            <Setter Property="IsVisible" Value="False" />
                        </DataTrigger>
                    </Button.Triggers>
                </Button>
            </Grid>
            <Label Text="{Binding ErrorMessage}" 
                   HorizontalTextAlignment="Center" 
                   FontSize="20" 
                   TextColor="Red"/>

            <Button Text="Back"
                    FontSize="20"
                    Margin="{OnIdiom Phone='20,16,20,0',Tablet='270,0,270,0'}"
                    CharacterSpacing="5"
                    Command="{Binding BackCommand}"
                    VerticalOptions="EndAndExpand"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>