@page "/"
@using HealthcareManagerUI.Models
@using HealthcareManagerUI.Services.Authentication
@using HealthcareManagerUI.Components.Layout

@layout AuthLayout

@inject AuthenticationService AuthenticationService

<head>
    <title>Login</title>
</head>
<link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css"/>

<EditForm Model="@userLoginModel" OnValidSubmit="@HandleLogin" class="container mt-5">
    <DataAnnotationsValidator/>
    <ValidationSummary/>

    <div class="card shadow-lg">
        <div class="card-body">
            <h3 class="card-title text-center mb-3">Login</h3>
            <div class="mb-3">
                <InputText id="email" class="form-control" type="email" placeholder="Email" @bind-Value="@userLoginModel.Email"/>
            </div>
            <div class="mb-3">
                <InputText id="password" class="form-control" type="password" placeholder="Password" @bind-Value="@userLoginModel.Password"/>
            </div>
            <button type="submit" class="btn btn-primary w-100 mb-3">Log In</button>
            <button type="button" class="btn btn-secondary w-100" @onclick="HandleSignUp">Sign Up</button>
        </div>
    </div>
</EditForm>

@code {
    private UserLoginModel userLoginModel = new UserLoginModel();

    private async Task HandleLogin()
    {
        var result = await AuthenticationService.Login(userLoginModel);
        if (result)
        {
            // Handle the successful login, e.g., navigate to another page
        }
        else
        {
            // Handle the failed login, e.g., show an error message
        }
    }

    private void HandleSignUp()
    {
        // Logic for handling sign up
    }
}