namespace CanYouBuildIt.Views;
using CanYouBuildIt.Model;

public partial class Login : ContentPage
{
    public Manager manager => (App.Current as App).manager;
    public Login()
    {
        InitializeComponent();
    }

    private async void BoutonValider(object sender, EventArgs e)
    {
        error.IsVisible = false;
        wrong.IsVisible = false;
        //recupérer les valeurs d'entrées
        string MdpUlti = Mdp.Text;
        string Name = Nom.Text;

        if (Name == null || MdpUlti == null)
            error.IsVisible = true;
        else
        {
            int idname = manager.rechercheUsername(Name);
            int idmdp = manager.recherchePwd(MdpUlti);

            if (idname == -1 && idmdp == -1)
                wrong.IsVisible = true;
            else if (idname != -1 && idmdp != -1)
            {
                valide.IsVisible = true;
                await Task.Delay(1000);
                valide.IsVisible = false;
                await Navigation.PushAsync(new Acceuil(idname));
            }
        }
    }
    
    private async void BackHome(object sender, EventArgs e)
    {
        await Navigation.PopAsync();
    }
}