{% extends "sakai/base.html" %}{% load molly_sakai %}{% load i18n %}

{% block content %}

{% regroup polls by siteId as polls_by_siteId %}

{% for poll_set in polls_by_siteId %}
<div class="section">
    <div class="header">
        <h2>{{ poll_set.list.0.siteTitle }}</h2>
    </div>

    <table class="content">
        <thead>
            <tr>
                <th>{% trans "Question" %}</th>
                <th>{% trans "Status" %}</th>
                <th></th>
            </tr>
        </thead>
        
        <tbody>
        {% for poll in poll_set.list %}
            <tr>
                <td>{{ poll.text }}</td>
                <td>
                  {% if poll.hasOpened %}
                      {% blocktrans with poll.voteClose|timeuntil as timeuntilclose %}Closes in <strong>{{ timeuntilclose }}</strong>.{% endblocktrans %}
                  {% else %}
                      {% blocktrans with poll.voteOpen|timeuntil as time_until_open and poll.voteClose|timeuntil:poll.voteOpen as time_open %}Opens in <strong>{{ time_until_open }}</strong> for <strong>{{ time_open }}</strong>.{% endblocktrans %}
                  {% endif %}
                </td>
                <td>
                    <div class="button">
                        <a href="{% url sakai:poll-detail poll.pollId %}">{% if poll.mayVote %}{% trans "Vote!" %}{% else %}{% trans "View" %}{% endif %}</a>
                    </div>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>

{% empty %}
    <div class="section">
        <div class="header">
            <h2>{% trans "Polls" %}</h2>
        </div>
        <div class="section-content">
            {% trans "There aren't currently any polls." %}
        </div>
    </div>
{% endfor %}

{% endblock %}
