<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:BehaviorTriggers.Triggers;assembly=BehaviorTriggers"
             xmlns:converters="clr-namespace:BehaviorTriggers.Converters;assembly=BehaviorTriggers"
             xmlns:behaviors="clr-namespace:BehaviorTriggers.Behaviors;assembly=BehaviorTriggers"
             x:Class="BehaviorTriggers.LoginPage">
   <ContentPage.Resources>
      <ResourceDictionary>
         <Style TargetType="Entry">
            <Style.Triggers>
               <Trigger TargetType="Entry" Property="IsFocused" Value="True">
                  <Setter Property="BackgroundColor" Value="Yellow" />
                  <Setter Property="TextColor" Value="Black" />
               </Trigger>
            </Style.Triggers>
         </Style>
         <converters:MultiTriggerConverter x:Key="multiTriggerConverter" />
      </ResourceDictionary>
   </ContentPage.Resources>

   <StackLayout Orientation="Vertical" Spacing="20"
	  Padding="40" HorizontalOptions="Center" VerticalOptions="Start">
      <Entry x:Name="usernameEntry" Placeholder="Nazwa lub e-mail">
         <Entry.Behaviors>
            <behaviors:EmailValidatorBehavior />
         </Entry.Behaviors>
      </Entry>
      <Entry x:Name="passwordEntry" Placeholder="Hasło" IsPassword="true">
         <Entry.Triggers>
            <EventTrigger Event="TextChanged">
               <local:LengthValidationTrigger />
            </EventTrigger>
         </Entry.Triggers>
      </Entry>

      <Button x:Name="loginButton" Text="Zaloguj" IsEnabled="False">
         <Button.Triggers>
            <MultiTrigger TargetType="Button">
               <MultiTrigger.Conditions>
                  <BindingCondition Binding="{Binding Source={x:Reference usernameEntry}, 
                                Path=Text.Length,
                                Converter={StaticResource multiTriggerConverter}}"
                  Value="true" />
                  <BindingCondition Binding="{Binding Source={x:Reference passwordEntry},
                               Path=Text.Length,
                               Converter={StaticResource multiTriggerConverter}}"
                  Value="true" />
               </MultiTrigger.Conditions>
               <Setter Property="IsEnabled" Value="True" />
            </MultiTrigger>
         </Button.Triggers>
      </Button>
   </StackLayout>

</ContentPage>
