{% extends "authentic2/base-page.html" %}
{% load i18n %}
{% load breadcrumbs %}

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

{% block breadcrumbs %}
    {{ block.super }}
    {% breadcrumb_url 'Register' %}
{% endblock %}

{% block content %}
    {% if users and not create %}
        <h2>{% trans "Login" %}</h2>
        <p>
            {% blocktrans count accounts_number=accounts|length %}An account already exists for this email. Please click on the account name to log in with.{% plural %}More accounts are associated to this email.  Please choose the account you want to log in with:{% endblocktrans %}
        </p>

        <ul>
          {% for user in users %}
              <li>
                  <form method="post" name="user-{{ user.id }}">
                      {% csrf_token %}
                      <input type="hidden" name="uid" value="{{ user.id }}">
                      <a href="#" onclick="document.forms['user-{{ user.id }}'].submit()">
                      {% blocktrans with fullname=user.get_full_name c=forloop.counter %}Account #{{ c }}: {{ fullname }}{% endblocktrans %}
                    </a>
                    <div>
                    {% blocktrans with creation_date=user.date_joined|date:'SHORT_DATETIME_FORMAT'%}created on {{ creation_date }}
                    {% endblocktrans %}
                    {% if user.last_login %}
                        {% blocktrans with login_date=user.last_login|date:'SHORT_DATETIME_FORMAT' %}last login on {{ login_date }}{% endblocktrans %}
                    {% endif %}
                    </div>
                  </form>
              </li>
          {% endfor %}
        </ul>
        {% if not email_is_unique %}
          <p>
            {% trans "or" %}
            <a href="?create">
              {% trans "create a new account" %}
            </a>
          </p>
        {% endif %}
    {% else %}
        <div class="columns small-12 text-center greybox">
            <h3>{% trans "Registration" %}</h3>
        </div>
        <div class="columns small-12 loginbox">
            <div class="columns small-10 small-centered text-center">
                <p>{% trans "Please fill the form to complete your registration" %}</p>
            </div>
            <div class="columns small-12 loginform">
                <form method="post">
                    {% csrf_token %}
                    {% for hidden in form.hidden_fields %}
                        {{ hidden }}
                    {% endfor %}
                    {% if form.errors %}
                        <div class="row">
                            <div class="columns small-12 medium-10 small-centered">
                                {% for error in form.non_field_errors %}
                                    <small class="error">{{ error }}</small>
                                {% endfor %}
                            </div>
                        </div>
                    {% endif %}
                    <div class="row">
                        <div class="columns small-10 small-centered">
                            {% if form.password1.help_text %}
                                <div class="columns small-12 text-justify panel callout radius">
                                    <p>{{ form.password1.help_text }}</p>
                                </div>
                            {% endif %}
                            <div class="columns small-12 medium-4">{{ form.password1.label_tag }}</div>
                            <div class="columns small-12 medium-8">
                                {{ form.password1 }}
                                {% for error in form.password1.errors %}
                                    <small class="error">{{ error }}</small>
                                {% endfor %}
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="columns small-10 small-centered">
                            <div class="columns small-12 medium-4">{{ form.password2.label_tag }}</div>
                            <div class="columns small-12 medium-8">
                                {{ form.password2 }}
                                {% for error in form.password2.errors %}
                                    <small class="error">{{ error }}</small>
                                {% endfor %}
                            </div>
                        </div>
                    </div>
                    <div class="columns small-12 text-center">
                        <button type="submit" class="submit radius large inverted-button" name="{{ submit_name }}" value="{%  trans 'Submit' %}"><span class="text">{%  trans "SOUMETTRE" %}</span></button>
                    </div>
                </form>
            </div>
        </div>
    {% endif %}
{% endblock %}
