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


{% block content %}

<div class="level">
  <div class="level-left">
    {# Titre de l'élection #}
    <div class="level-item">
      <h1 class="title">{{ election.name }}</h1>
    </div>

    <div class="level-item">
      <h3 class="subtitle">{% trans "Liste des votant·e·s" %}</h3>
    </div>
  </div>

  <div class="level-right">
    <div class="level-item">
      <a class="button is-primary" href="{% if can_delete %}{% url 'election.admin' election.pk %}{% else %}{% url 'election.view' election.pk %}{% endif %}">
        <span class="icon is-small">
          <i class="fas fa-undo-alt"></i>
        </span>
        <span>{% trans "Retour" %}</span>
      </a>
    </div>
  </div>
</div>
<hr>

<div class="message is-warning">
  <div class="message-body">
    {% if election.restricted %}
    {% trans "Seules les personnes présentes sur cette liste peuvent voter, vous avez dû recevoir un mail avec vos identifiants de connexion." %}
    {% else %}
    {% trans "Toute personne avec un compte CAS peut voter." %}
    {% endif %}
  </div>
</div>

<div class="columns is-centered">
  <div class="column is-two-thirds">
    <table class="table is-striped is-fullwidth">
      <thead>
        <tr>
          <th>{% trans "Nom" %}</th>
          <th class="has-text-centered">{% trans "Vote enregistré" %}</th>
          {% if can_delete %}
          <th class="has-text-centered">{% trans "Supprimer" %}</th>
          {% endif %}
        <tr>
      </thead>
      <tbody>
        {% with voters=election.voters.all %}
        {% if election.restricted %}
        {% for v in election.registered_voters.all %}
        <tr>
          <td>{{ v.full_name }} ({{ v.get_username }})</td>
          <td class="has-text-centered">
            <span class="icon">
              {% if v in voters %}
              <i class="fas fa-check"></i>
              {% else %}
              <i class="fas fa-times"></i>
              {% endif %}
            </span>
          </td>
        </tr>
        {% endfor %}
        {% else %}
        {% for v in voters %}
        <tr id="v_{{ forloop.counter }}">
          <td>{{ v.full_name }} ({{ v.get_username }})</td>
          <td class="has-text-centered">
            <span class="icon">
              <i class="fas fa-check"></i>
            </span>
          </td>
          {% if can_delete %}
          <td class="has-text-centered">
            <a class="tag is-danger has-tooltip-primary" href="{% url 'election.delete-vote' election.pk v.pk forloop.counter %}" data-tooltip="{% trans "Supprimer le vote de " %}{{ v.full_name }}">
              <span class="icon">
                <i class="fas fa-user-minus"></i>
              </span>
            </a>
            {% endif %}
        </tr>
        {% endfor %}
        {% endif %}
        {% endwith %}
    </table>
  </div>
</div>

{% endblock %}
