{% extends "pages/base.html" %}
{% load i18n %}

{% block title %}{% trans "Login" %}{% endblock %}

{% block content %}
<div class="d-flex justify-content-center">
  <div class="card p-4" style="max-width: 400px; width: 100%;">
    <h1 class="text-center mb-4">{% trans "Login" %}</h1>
    {% if request.user.is_authenticated %}
    <div class="mb-3 text-center">
      <a href="{% url 'pages:logout' %}?next={{ request.get_full_path|urlencode }}">{% trans "Log out" %}</a>
    </div>
    {% endif %}
    {% if restricted_notice %}
    <div class="alert alert-info" role="alert">
      {{ restricted_notice }}
    </div>
    {% endif %}
    <form method="post" novalidate data-auth-form>
      {% csrf_token %}
      {% if login_check_mode %}
      <input type="hidden" name="check" value="1">
      {% endif %}
      {% if form.non_field_errors %}
      <div class="alert alert-danger" role="alert">
        {% for error in form.non_field_errors %}{{ error }}{% if not forloop.last %}<br>{% endif %}{% endfor %}
      </div>
      {% endif %}
      <div class="mb-3">
        <label for="{{ form.username.id_for_label }}" class="form-label">{{ form.username.label }}</label>
        <input
          type="text"
          name="{{ form.username.html_name }}"
          class="form-control{% if form.username.errors %} is-invalid{% endif %}"
          id="{{ form.username.id_for_label }}"
          value="{{ form.username.value|default_if_none:'' }}"
          autocomplete="username"
          required
          autofocus
          {% if username_readonly %}readonly aria-readonly="true"{% endif %}
        >
        {% for error in form.username.errors %}
        <div class="invalid-feedback">{{ error }}</div>
        {% endfor %}
      </div>
      <div class="mb-3">
        <label for="{{ form.password.id_for_label }}" class="form-label">{{ form.password.label }}</label>
        <input
          type="password"
          name="{{ form.password.html_name }}"
          class="form-control{% if form.password.errors %} is-invalid{% endif %}"
          id="{{ form.password.id_for_label }}"
          autocomplete="current-password"
          required
        >
        {% for error in form.password.errors %}
        <div class="invalid-feedback">{{ error }}</div>
        {% endfor %}
      </div>
      {% if next %}<input type="hidden" name="next" value="{{ next }}">{% endif %}
      <div data-submit-group>
        <button type="submit" class="btn btn-primary w-100">{% trans "Log in" %}</button>
      </div>
    </form>
    {% if show_rfid_login %}
    <div class="mt-3 text-center">
      <a href="{% if rfid_login_url %}{{ rfid_login_url }}{% else %}{% url 'pages:rfid-login' %}{% endif %}">{% trans "Login with RF Card" %}</a>
    </div>
    {% endif %}
    {% if can_request_invite %}
    <div class="mt-3 text-center">
      <a href="{% url 'pages:request-invite' %}">{% trans "Request email invitation" %}</a>
    </div>
    {% endif %}
  </div>
</div>
{% endblock %}
