{% extends "registration/base.html" %}

{% load i18n richmin %}
{% get_richmin_settings request as richmin_settings %}
{% get_richmin_ui_tweaks as richmin_ui %}

{% block content %}
  <p class="login-box-msg">{{ richmin_settings.welcome_sign }}</p>
  <form action="{{ app_path }}" method="post">
    {% csrf_token %}
    {% if user.is_authenticated %}
      <p class="errornote">
      <div class="callout callout-danger">
        <p>
          {% blocktrans trimmed %}
            You are authenticated as {{ username }}, but are not authorized to
            access this page. Would you like to login to a different account?
          {% endblocktrans %}
        </p>
      </div>
      </p>
    {% endif %}
    {% if form.errors %}
      {% if form.username.errors %}
        <div class="callout callout-danger">
          <p>{{ form.username.label }}: {{ form.username.errors|join:', ' }}</p>
        </div>
      {% endif %}
      {% if form.password.errors %}
        <div class="callout callout-danger">
          <p>{{ form.password.label }}: {{ form.password.errors|join:', ' }}</p>
        </div>
      {% endif %}
      {% if form.non_field_errors %}
        <div class="callout callout-danger">
          {% for error in form.non_field_errors %}
            <p>{{ error }}</p>
          {% endfor %}
        </div>
      {% endif %}
    {% endif %}
    <div class="input-group mb-3">
      <input type="text" name="username" class="form-control" placeholder="{{ form.username.label }}" required>
      <div class="input-group-append">
        <div class="input-group-text">
          <span class="fas fa-user"></span>
        </div>
      </div>
    </div>
    <div class="input-group mb-3">
      <input type="password" name="password" class="form-control" placeholder="{{ form.password.label }}" required>
      <div class="input-group-append">
        <div class="input-group-text">
          <span class="fas fa-lock"></span>
        </div>
      </div>
    </div>
    {% url 'admin_password_reset' as password_reset_url %}
    {% if password_reset_url %}
      <div class="mb-3">
        <div class="password-reset-link" style="text-align: center;">
          <a href="{{ password_reset_url }}">
            {% trans 'Forgotten your password or username?' %}
          </a>
        </div>
      </div>
    {% endif %}
    <div class="row">
      <div class="col-12">
        <button type="submit" class="btn {{ richmin_ui.button_classes.primary }} btn-block">
          {% trans "Log in" %}
        </button>
      </div>
    </div>
  </form>
{% endblock %}
