@page "/passwordreset"
@using Moonlight.App.Services

@* This is just a "virtual" route/page. The handling for that is
@* MainLayout doing for us. We need to put that here so the router
@* does not return the 404 page
*@

@inject UserService UserService
@inject SmartTranslateService SmartTranslateService

<div class="d-flex flex-center">
    <div class="card rounded-3 w-md-550px">
        <div class="card-body">
            <div class="d-flex flex-center flex-column-fluid pb-15 pb-lg-20">
                @if (Send)
                {
                    <div class="text-center mb-11">
                        <h1 class="text-dark fw-bolder mb-3">
                            <TL>Passwort reset successfull. Check your mail</TL>
                        </h1>
                    </div>
                }
                else
                {
                    <div class="form w-100 fv-plugins-bootstrap5 fv-plugins-framework" novalidate="novalidate">
                        <div class="text-center mb-11">
                            <h1 class="text-dark fw-bolder mb-3">
                                <TL>Password reset</TL>
                            </h1>
                            <div class="text-gray-500 fw-semibold fs-6">
                                <TL>Reset the password of your account</TL>
                            </div>
                        </div>

                        <div class="fv-row mb-8 fv-plugins-icon-container">
                            <input @bind="Email" type="email" placeholder="@(SmartTranslateService.Translate("Email"))" name="email" class="form-control bg-transparent">
                        </div>

                        <div class="d-grid mb-10">
                            <WButton Text="@(SmartTranslateService.Translate("Reset password"))"
                                     WorkingText="@(SmartTranslateService.Translate("Working"))"
                                     CssClasses="btn-primary"
                                     OnClick="Submit">
                            </WButton>
                        </div>

                        <div class="text-gray-500 text-center fw-semibold fs-6">
                            <TL>Wrong here?</TL>

                            <a href="/login" class="link-primary">
                                <TL>Sign in</TL>
                            </a>
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>

@code
{
    private string Email = "";
    private bool Send = false;

    private async Task Submit()
    {
        await UserService.ResetPassword(Email);
        Send = true;
        await InvokeAsync(StateHasChanged);
    }
}