@use validator::ValidationErrors;
@use crate::template_utils::*;
@use crate::templates::base;
@use crate::routes::session::LoginForm;
@use crate::routes::*;

@(ctx: BaseContext, message: Option<String>, form: &LoginForm, errors: ValidationErrors)

@:base(ctx, i18n!(ctx.1, "Log in"), {}, {}, {
    <h1>@i18n!(ctx.1, "Log in")</h1>
    @if let Some(message) = message {
        <p>@message</p>
    }
    <form method="post" action="@uri!(session::create)">
        @(Input::new("email_or_name", i18n!(ctx.1, "Username, or email"))
            .default(&form.email_or_name)
            .error(&errors)
            .set_prop("minlenght", 1)
            .html(ctx.1))
        @(Input::new("password", i18n!(ctx.1, "Password"))
            .default(&form.password)
            .error(&errors)
            .set_prop("minlenght", 8)
            .input_type("password")
            .html(ctx.1))
        <input type="submit" value="@i18n!(ctx.1, "Log in")" />
    </form>
    <a href="@uri!(session::password_reset_request_form)">Forgot your password?</a>
})
