@page "/login"
@using Models.Identity
@inject NavigationManager NavigationManager
@layout LayoutWithoutMenu

<div class="form">
    <h3>Login</h3>
    <EditForm Model="@LoginModel" OnValidSubmit="RequestLogin">
        
        <div class="row">
            <div class="col">
                <input type="text" class="form-control" placeholder="ٍEmail" @bind="LoginModel.Username" />

                <ValidationMessage For="@(() => LoginModel.Username)" />

            </div>
        </div>
        <div class="row">
            <div class="col">
                <input type="password" class="form-control" placeholder="Password" @bind="LoginModel.Password" />
                <ValidationMessage For="@(() => LoginModel.Password)" />
            </div>
        </div>
        <div class="row">
            <div class="col">
                <button class="btn btn-primary " type="submit">Login</button>

            </div>
        </div>

    </EditForm>

</div>
<style>
    .form {
        display: flex;
        flex-direction: column;
        align-items: center;
        align-content: center;
    }

    .form-control {
        margin: 5px 5px;
    }
</style>
@code {
    private bool WaitForOtpMode { get; set; } = true;
    protected OTPLoginModel OtpLoginModel { get; set; } = new();
    protected LoginModel LoginModel { get; set; } = new();



    protected async Task RequestLogin()
    {
        var response = await _userUtils.Login(LoginModel);
        if (response.IsSuccessStatusCode)
        {
            var result = await response.Content.ReadFromJsonAsync<Models.Identity.PlainToken>();
            await LocalStorage.SetItemAsync(Statics.LoginTokenKey, result.AccessToken);
            NavManager.NavigateTo("/");

        }
    }

}