{% extends "layout/2-columns-left.html" %}
{% load i18n waffle_tags %}

{% block subtitle %}
  {% if active_training %}
    {{ active_training.name }}: {% trans 'Sessions list' %}
  {% else %}
    {% trans 'Sessions list' %}
  {% endif %}
{% endblock %}

{% block actions %}
  {% if user.is_staff %}
    {% if active_training %}
      <a href="{% url 'trainings:session_add' training_id=active_training.id%}" class="btn btn-primary">
        <i class="fa fa-plus"></i> {% trans 'Create a session' %}
      </a>
    {% else %}
      <a href="{% url 'trainings:session_add' %}" class="btn btn-primary">
        <i class="fa fa-plus"></i> {% trans 'Create a session' %}
      </a>
    {% endif %}
  {% endif %}
{% endblock %}

{% block column_left %}
  <div class="list-group">
    <a class="list-group-item {% if not active_training %}active{% endif %}" href="{% url 'trainings:sessions_list' %}">
      {% trans 'All formations' %}
    </a>
    {% for training in trainings %}
      <a class="list-group-item {% if active_training == training %}active{% endif %}" href="{% url 'trainings:sessions_list' training_id=training.id %}">
        {{ training.name }}
        <span class="badge">{{ training.num_sessions }}</span>
      </a>
    {% endfor %}
  </div>
{% endblock %}

{% block column_main %}
  {% if sessions %}
    <div class="panel panel-default">
      <table class="table table-hover table-bordered">
        <thead>
          <tr>
            <th>{% trans 'Training' %}</th>
            <th>{% trans 'Trainer' %}</th>
            <th>{% trans 'Date' %}</th>
            <th>{% trans 'Date end' %}</th>
            <th>{% trans 'Participants' %}</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {% for session in sessions %}
            {% spaceless %}
              <tr class="
                {% if session.state = session.SESSION_STATE_CHOICES.CLOSED %}
                  danger
                {% elif session.state = session.SESSION_STATE_CHOICES.DURING %}
                  success
                {% elif session.state != session.SESSION_STATE_CHOICES.NOT_OPEN %}
                  info
                {% endif %}
              ">
            {% endspaceless %}
            <td>
              {% if user.is_staff %}
                <a href="{% url 'trainings:session_detail' session_id=session.id %}">
                  {{session.training.name}}
                </a>
              {% else %}
                {{session.training.name}}
              {% endif %}
            </td>
            <td>{{session.trainer.last_name}}</td>
            <td>{{session.date}}</td>
            <td>{{session.date_end}}</td>
            <td>{{session.users.all.count}}</td>
            <td>
              <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                  {% trans "Actions" %}
                  <span class="caret"></span>
                </button>
                <ul class="dropdown-menu pull-right">
                  {% if user.is_staff %}
                    <li>
                      <a href="{% url 'accounts:users_import' session_id=session.id %}">
                        <i class="fa fa-file"></i> {% trans 'Import trainees' %}</a>
                    </li>
                    <li>
                      <a href="{% url 'trainings:session_stats' session_id=session.id %}">
                        <i class="fa fa-arrow-down"></i> {% trans 'Export quizz' %}</a>
                    </li>
                    <li>
                      <a href="{% url 'trainings:session_stats_eval' session_id=session.id %}">
                        <i class="fa fa-arrow-down"></i> {% trans 'Export eval' %}</a>
                    </li>
                    {% if session.challengesession_set.all.0 %}
                      <li>
                        <a href="{% url 'challenges:trainee_podium' challenge_session_id=session.challengesession_set.all.0.id %}">
                          <i class="fa fa-signal"></i> {% trans 'Challenge' %}
                        </a>
                      </li>
                    {% endif %}
                    <li>
                      <a href="{% url 'trainings:session_whoswho' session_id=session.id %}">
                        <i class="fa fa-th"></i> {% trans 'Whoswho' %}
                      </a>
                    </li>
                    <li>
                      <a href="{% url 'metaplans:list_by_session' session_id=session.id %}">
                        <i class="fa fa-th-large"></i> {% trans 'Metaplan' %}
                      </a>
                    </li>
                    <li>
                      <a href="{% url 'brainstormers:list_by_session' session_uuid=session.id %}">
                        <i class="fa fa-cogs"></i> {% trans 'Brainstormers' %}
                      </a>
                    </li>
                    {% if user.is_superuser or session.trainer == user %}

                      {% switch 'enable_assessments' %}
                        <li>
                          <a href="{% url 'assessments:session_scores' session_uuid=session.id %}">
                            <i class="fa fa-arrow-down"></i> {% trans 'Export assessment scores' %}</a>
                          </a>
                        </li>
                      {% endswitch %}

                      {% if session.state != session.SESSION_STATE_CHOICES.CLOSED %}
                        <li>
                          <a href="{% url 'trainings:session_close' session_id=session.id %}">
                            <i class="fa fa-close"></i> {% trans 'Close' %}
                          </a>
                        </li>
                      {% endif %}
                    {% endif %}
                  {% endif %}
                </ul>
              </div>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      <div class="panel-footer">
        {% pagination with items=sessions %}
      </div>
    </div>
    {% else %}
      <div class="alert alert-info">
        {% trans 'No sessions to show.' %}
      </div>
    {% endif %}
{% endblock %}
