using PaklenaBasta.MAUI.Models;
using PaklenaBasta.MAUI.Services;

namespace PaklenaBasta.MAUI.Views;

public partial class LoginPage : ContentPage
{
    private readonly ApiService _api;

    public LoginPage()
    {
        InitializeComponent();
        // configure base URL to your backend
        _api = new ApiService("https://paklenabasta.company/api");
        this.BindingContext = this;
    }

    private async void OnLoginClicked(object sender, EventArgs e)
    {
        StatusLabel.Text = string.Empty;
        var request = new LoginRequestDto { Email = EmailEntry.Text ?? string.Empty, Password = PasswordEntry.Text ?? string.Empty };
        var res = await _api.LoginAsync(request);
        if (res == null)
        {
            StatusLabel.Text = "Login failed";
            return;
        }

        // navigate to home and pass ApiService instance via constructor
        await Navigation.PushAsync(new HomePage(_api));
    }
}
