{% extends "orga/base.html" %}
{% load i18n %}
{% load review_score %}
{% load rules %}

{% block content %}
{% has_perm 'orga.change_settings' request.user request.event as can_see_settings %}
{% has_perm 'orga.perform_reviews' request.user request.event as can_review %}
<div class="dashboard-list">
{% if review_count %}
    <div class="dashboard-block">
        <h1>{{ review_count }}</h1>
        <div class="dashboard-description">
            {% blocktrans trimmed count count=request.event.reviews.count %}
            lonely review
            {% plural %}
            total reviews
            {% endblocktrans %}
            {% if avg_reviews %}
                <br>({% blocktrans with avg=avg_reviews %}{{ avg }} reviews/reviewer{% endblocktrans %})
            {% endif %}
        </div>
    </div>
{% else %}
    <div class="dashboard-block">
        <h1>{% trans "Zero" %}</h1>
        <div class="dashboard-description">
            {% trans "total reviews" %}
            <br>
        </div>
    </div>
{% endif %}
<{% if can_see_settings %}a href="{{ request.event.orga_urls.team_settings }}"{% else %}div{% endif %} class="dashboard-block">
    <h1>{{ active_reviewers }}</h1>
    <div class="dashboard-description">
        {% blocktrans trimmed count count=active_reviewers %}
        lonely active reviewer
        {% plural %}
        total active reviewers
        {% endblocktrans %}
        {% if reviewers != active_reviewers %}
            <br>({% blocktrans with count=reviewers %}{{ count }} total{% endblocktrans %})
        {% endif %}
    </div>
</{% if can_see_settings %}a{% else %}div{% endif %}>
{% if can_see_settings %}
<a href="{{ request.event.cfp.urls.text }}#review" class="dashboard-block">
    <h1>{% trans "Change settings" %}</h1>
    <div class="dashboard-description">
        <ul>
            <li>{% trans "Set a review deadline" %}</li>
            <li>{% trans "Determine the score range" %}</li>
            <li>…</li>
        </ul>
    </div>
</a>
{% endif %}
{% if can_review and next_submission %}
    <a class="dashboard-block" href="{{ next_submission.orga_urls.reviews }}">
        <h1>{% trans "Review!" %}</h1>
        <div class="dashboard-description">
        {% blocktrans with count=missing_reviews.count trimmed %}
                Click here to submit more reviews, there are still {{ count }} missing!
            {% endblocktrans %}
        </div>
    </a>
{% elif can_review %}
    <a class="dashboard-block" href="{{ next_submission.orga_urls.reviews }}">
        <h1>{% trans "Bravo!!" %}</h1>
        <div class="dashboard-description">
            {% trans "There are no submissions left to review!" %}
        </div>
    </a>
{% endif %}
</div>


<table class="table table-sm review-table table-hover table-responsive-md">
    <thead>
        <tr>
            <th>{% trans "Score" %} <i class="fa fa-caret-down"></i></th>
            <th>{% trans "Reviews" %}</th>
            <th>{% trans "Title" %}</th>
            <th>{% trans "Speakers" %}</th>
            <th>{% trans "State" %}</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
    {% for submission in submissions %}
        {% has_perm 'submission.accept_submission' request.user submission as can_accept_submission %}
        {% has_perm 'submission.reject_submission' request.user submission as can_reject_submission %}
        <tr class="{{ submission.state }}">
            <td>
                {% if submission.avg_score != None %}
                    {% review_score submission %}
                {% else %}
                    –
                {% endif %}
            </td>
            <td>
                {% if submission.reviews.all.count %}
                    {{ submission.reviews.all.count }}
                {% else %}
                    –
                {% endif %}
            </td>
            <td>
                <a href="{% if can_review %}{{ submission.orga_urls.reviews }}{% else %}{{ submission.orga_urls.base }}{% endif %}">
                    {{ submission.title }}
                </a>
            </td>
            <td>{{ submission.display_speaker_names }}</td>
            <td>
                {% include "cfp/event/fragment_state.html" with state=submission.state %}
            </td>
            <td class="review-buttons">
                {% if submission.state == 'submitted' %}
                    {% if can_accept_submission %}
                        <a class="btn btn-success btn-sm" href="{{ submission.orga_urls.accept }}?next={{ request.path }}">{% trans "Accept" %}</a>
                    {% endif %}
                    {% if can_reject_submission %}
                        <a class="btn btn-danger btn-sm" href="{{ submission.orga_urls.reject }}">{% trans "Reject" %}</a>
                    {% endif %}
                {% endif %}
            </td>
        </tr>
    {% empty %}
        <tr>
            <td>{% trans "You don't seem to have any submissions yet." %}</td>
        </tr>
    {% endfor %}
    </tbody>
</table>
{% include "orga/pagination.html" %}
{% endblock %}
