{% extends "layouts/base-auth.html" %}
{% load i18n static admin_datta %}

{% block title %}Login{% endblock title %}

{% block content %}

  <div class="auth-main">
    <div class="auth-wrapper v1">
      <div class="auth-form">
        <div class="position-relative my-5">
          <div class="auth-bg">
            <span class="r"></span>
            <span class="r s"></span>
            <span class="r s"></span>
            <span class="r"></span>
          </div>
          <div class="card mb-0">
            <form method="post" class="card-body">
              {% csrf_token %}

              <div class="text-center">
                <a href="{% url "index" %}">
                  <div>
                    <img src="{% static "assets/images/logo-dark.svg" %}" alt="img">
                  </div>
                </a>
              </div>
              <h4 class="text-center f-w-500 mt-4 mb-3">Login</h4>

              {% if form.non_field_errors %}
                {% for error in form.non_field_errors %}
                  <span class="d-block text-danger mb-3">{{ error }}</span>
                {% endfor %}
              {% endif %}

              <div class="form-group mb-3">
                <input 
                  type="text" 
                  class="form-control"
                  name="{{ form.username.name }}" 
                  id="{{ form.username.id_for_label }}"
                  placeholder="{{ form.username.label }}"
                >
              </div>

              <div class="form-group mb-3">
                <input 
                  type="password" 
                  class="form-control"
                  name="{{ form.password.name }}" 
                  id="{{ form.password.id_for_label }}"
                  placeholder="{{ form.password.label }}"
                >
              </div>
              <div class="text-center mt-4">
                <button type="submit" class="btn btn-primary shadow px-sm-4">Login</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>

{% endblock content %}


{% block extra_js %}

<script type="application/javascript">
  {% if form.username.errors %}
      notification.danger("{{ form.username.errors }}", 'top', 'right');
  {% endif %}
  {% if form.password.errors %}
      notification.danger("{{ form.password.errors }}", 'top', 'right');
  {% endif %}

  {% if user.is_authenticated %}
      var msg = "You are authenticated as {{ username }}, but are not authorized to " +
          "access this page.Would you like to login to a different account ?"
      notification.warning(msg, 'top', 'right');
  {% endif %}

  {% if form.errors and not form.non_field_errors %}
      {% if form.errors.items|length == 1 %}
          notification.warning("{% trans "Please correct the error below." %}", 'top', 'right');
      {% else %}
          notification.warning("{% trans "Please correct the errors below." %}", 'top', 'right');
      {% endif %}
  {% endif %}

  {% if form.non_field_errors %}
      {% for error in form.non_field_errors %}
          notification.warning("{{ error|clean_text }}", 'top', 'right');
      {% endfor %}
  {% endif %}
</script>

{% endblock extra_js %}