@page "/password-reset"

@using Moonlight.App.Services.Users
@using Moonlight.App.Models.Forms
@using Moonlight.App.Models.Forms.Auth

@inject UserService UserService

<div class="w-100">
    <div class="card-body">
        @if (HasBeenSend)
        {
            <div class="text-start mb-8">
                <h1 class="text-dark mb-3 fs-3x">
                    Password reset email sent
                </h1>
                <div class="text-gray-400 fw-semibold fs-6">
                    You should receive the email shortly. If you see no email in your inbox, look inside your spam folder
                </div>
            </div>
        }
        else
        {
            <div class="text-start mb-8">
                <h1 class="text-dark mb-3 fs-3x">
                    Reset your password
                </h1>
                <div class="text-gray-400 fw-semibold fs-6">
                    We will sent you an email to reset your account password
                </div>
            </div>

            <SmartForm Model="Form" OnValidSubmit="OnValidSubmit">
                <div class="fv-row mb-8">
                    <input @bind="Form.Email" type="text" placeholder="Email" class="form-control form-control-solid">
                </div>

                <div class="d-flex flex-stack">
                    <button type="submit" class="btn btn-primary me-2 flex-shrink-0">Continue</button>
                </div>
            </SmartForm>
        }
    </div>
</div>

@code
{
    private bool HasBeenSend = false;
    private ResetPasswordForm Form = new();

    private async Task OnValidSubmit()
    {
        await UserService.Auth.SendResetPassword(Form.Email);
        HasBeenSend = true;
        await InvokeAsync(StateHasChanged);
    }
}