{% extends 'stdgrid.html.twig' %}

{% block stylesheets %}
    {{ parent() }}
    <link rel='stylesheet' type='text/css' href="{{ asset('assets/css/security/security.css') }}">
{% endblock %}

{% block title %}{{ "Log in!" | trans }}{% endblock %}

{% block body %}
    <div class='content'>
        <section class="section-widget">
            <form class="section-widget-form" method="post">
                <fieldset>
                    <legend class="section-form-legend"><h1>{{ "Login" | trans }}</h1></legend>

                    {% if error %}
                        <ul>
                            {% for flashError in app.flashes('verify_email_error') %}
                                <li class="alert alert-danger">{{ error.messageKey | trans(error.messageData, 'security') }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}

                    {% if app.user %}
                        <h1 class="mb-3">
                            {{ "You are logged in as" | trans }} {{ app.user.username }}.
                            <button class="btn btn-lg btn-primary">
                                <a href="{{ path('app_logout') }}">{{ "Logout" | trans }}</a>
                            </button>
                        </h1>
                    {% else %}
                        {# TODO: Login can be done with email, so the id's and stuff should reflect that, along with using the translation facilities #}
                        <div>
                            <label class="section-form-label" for="inputNickname">{{ "Nickname or Email" | trans }}</label>
                            <input type="text" value="{{ last_login_id }}" name="nickname" id="inputNickname" class="form-control" required autofocus>
                            <p class="help-text">{{ "Your nickname." | trans }}</p>
                        </div>
                        <div>
                            <label class="section-form-label" for="inputPassword">{{ "Password" | trans }}</label>
                            <input type="password" name="password" id="inputPassword" class="form-control" required>
                            <p class="help-text">{{ "Your account's password." | trans }}</p>
                        </div>

                        <span class="checkbox mb-3">
                            <label>{{ "Remember me" | trans }}</label>
                            <input type="checkbox" name="_remember_me">
                        </span>

                        <div>
                            <button class="btn btn-lg btn-primary" type="submit">Sign in</button>
                        </div>
                        <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
                    {% endif %}
                </fieldset>
            </form>
        </section>
    </div>
{% endblock body %}

{% block javascripts %}{% endblock %}
