{#
    Altered login form that includes the 2FA authentication.
#}

{% import 'macros/form.html' as form %}

{% set username_error = true if error_summary %}
{% set password_error = true if error_summary %}
{% set is_2fa_enabled = h.is_2fa_enabled() %}

<form id="mfa-login-form" action="{{ action }}" method="post"
    data-module="auth-login-form"
    data-module-enabled="{{ h.is_2fa_enabled() | tojson }}"
    data-module-mfa-method="{{ h.get_2fa_method() }}">
    {{ h.csrf_input() }}
    {{ form.errors(errors=error_summary) }}

    <div id="mfa-error-container" class="alert alert-error" style="display: none;">
        <p>{{ _('The form contains invalid entries:') }}</p>
        <ul>
            <li class="mfa-error-message"></li>
        </ul>
    </div>

    <div id="login-form">
        {{ form.input('login', label=_("Username or Email"), id='field-login', value="", error=username_error, classes=["control-medium"]) }}

        {{ form.input('password', label=_("Password"), id='field-password', type="password", value="", error=password_error, classes=["control-medium"]) }}

        {{ form.checkbox('remember', label=_("Remember me"), id='field-remember', checked=true, value="63072000") }}

        {% if g.recaptcha_publickey %}
            {% snippet "user/snippets/recaptcha.html", public_key=g.recaptcha_publickey %}
        {% endif %}

        <div class="form-actions">
            {% block login_button %}
                {% if is_2fa_enabled %}
                    <button class="btn btn-primary" id="mfa-next">{{ _('Next') }}</button>
                {% else %}
                    <button class="btn btn-primary" type="submit">{{ _('Login') }}</button>
                {% endif %}
            {% endblock %}
        </div>
    </div>

    {% if is_2fa_enabled %}
        <input id="mfa-type" name="mfa_type" type="hidden" value="{{ h.get_2fa_method() }}" />

        {% if h.is_totp_2fa_enabled() %}
            {% snippet "auth/snippets/2fa_authenticator.html" %}
        {% else %}
            {% snippet "auth/snippets/2fa_email.html" %}
        {% endif %}
    {% endif %}
</form>
