{% extends "orga/base.html" %}
{% load bootstrap4 %}
{% load compress %}
{% load i18n %}
{% load review_score %}
{% load rules %}
{% load url_replace %}
{% load static %}

{% block scripts %}
{% compress js %}
    <script src="{% static 'orga/js/review.js' %}" defer></script>
{% endcompress %}
{% endblock %}

{% block content %}
{% has_perm 'orga.perform_reviews' request.user request.event as can_review %}
{% has_perm 'orga.view_speakers' request.user request.event as can_view_speakers %}
<div class="alert alert-info">
    {% if can_review and next_submission %}
        <a href="{{ next_submission.orga_urls.reviews }}">
        {{ missing_reviews }}
        {% blocktrans trimmed count count=missing_reviews %}
        submission is waiting for your review.
        {% plural %}
        submissions are waiting for your review.
        {% endblocktrans %}
        {% trans "Click here to get started!" %}
        </a>
    {% elif can_review %}
        {% trans "You've got no submissions left to review!" %}
    {% else %}
        {% trans "Reviews are currently closed." %}
    {% endif %}
</div>

<div class="submit-group">
    <form class="search-form">
        {% bootstrap_form search_form %}
        {% bootstrap_field filter_form.submission_type %}
        {% bootstrap_field filter_form.state layout='inline' %}
        {% if request.event.settings.use_tracks %}
            {% bootstrap_field filter_form.track %}
        {% endif %}
        <button class="btn btn-success" type="submit">{% trans "Search" %}</button>
    </form>
        <div class="dropdown ml-auto">
          <a class="btn btn-info dropdown-toggle" href="#" role="button" id="schedule-actions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              {% trans "Actions" %}
          </a>

          <div class="dropdown-menu dropdown-menu-right" aria-labelledby="schedule-actions">
            <a class="dropdown-item" href="{{ request.event.orga_urls.reviews }}regenerate">
                <i class="fa fa-link"></i> {% trans "Regenerate decision emails" %}
            </a>
          </div>
        </div>
</div>

<form method="post">{% csrf_token %}
<table class="table review-table table-hover table-responsive-md">
    <colgroup>
        <col class="nowrap">
        <col class="nowrap">
        <col class="w-75">
        {% if can_view_speakers %}<col class="w-25">{% endif %}
        <col class="nowrap">
        <col class="nowrap">
        <col class="nowrap">
    </colgroup>
    <thead>
        <tr>
            <th>
                {% if can_see_all_reviews %}
                    {% trans "Median score" %}
                {% else %}
                    {% trans "Score" %}
                {% endif %}
                <a href="?{% url_replace request 'sort' 'score' %}"><i class="fa fa-caret-down" title="{% trans "Sort by score (highest first)" %}"></i></a>
                <a href="?{% url_replace request 'sort' '-score' %}"><i class="fa fa-caret-up" title="{% trans "Sort by score (lowest first)" %}"></i></a>
            </th>
            <th>
                {% trans "Reviews" %}
                <a href="?{% url_replace request 'sort' 'count' %}"><i class="fa fa-caret-down" title="{% trans "Sort by review count (highest first)" %}"></i></a>
                <a href="?{% url_replace request 'sort' '-count' %}"><i class="fa fa-caret-up" title="{% trans "Sort by review count (lowest first)" %}"></i></a>
            </th>
            <th>{% trans "Title" %}</th>
            {% if can_view_speakers %}<th>{% trans "Speakers" %}</th>{% endif %}
            <th>{% trans "Type" %}</th>
            <th>{% trans "State" %}</th>
            <th><span class="action-row d-flex justify-space-around">
                {% if can_accept_submissions %}
                <div class="radio form-radio accept">
                    <input type="radio" id="a-all" name="s-all" value="accept" class="radio">
                    <label for="a-all" title="{% trans "Accept all" %}"></label>
                </div>
                <div class="radio form-radio reject">
                    <input type="radio" id="r-all" name="s-all" value="reject" class="radio">
                    <label for="r-all" title="{% trans "Reject all" %}"></label>
                </div>
                <div class="unmark-radio always-active" id="u-all" title="{% trans "Unset accept/reject vote for all" %}"><i class="fa fa-ban"></i></div>
                {% endif %}
            </span></th>
        </tr>
    </thead>
    <tbody>
    {% for submission in submissions %}
        <tr class="{{ submission.state }}">
            <td>
                {% review_score submission %}
            </td>
            <td>
                {{ submission.reviews.all|length|default:'-' }}
                {% if submission.pk in submissions_reviewed %}
                    <i class="fa fa-check text-success" title="{% trans "You have reviewed this submission" %}"></i>
                {% endif %}
            </td>
            <td>
                <a href="{% if can_review %}{{ submission.orga_urls.reviews }}{% else %}{{ submission.orga_urls.base }}{% endif %}">
                    {{ submission.title }}
                </a>
            </td>
            {% if can_view_speakers %}<td>{{ submission.display_speaker_names }}</td>{% endif %}
            <td>{{ submission.submission_type.name }}</td>
            <td class="nowrap">
                {% include "cfp/event/fragment_state.html" with state=submission.state %}
            </td>
            <td class="action-row d-flex justify-space-around">
                {% if submission.state == 'submitted' and can_accept_submissions %}
                <div class="radio form-radio accept">
                    <input type="radio" id="a-{{ submission.pk }}" name="s-{{ submission.pk }}" value="accept" class="radio">
                    <label for="a-{{ submission.pk }}" title="{% trans "Accept" %}"></label>
                </div>
                <div class="radio form-radio reject">
                    <input type="radio" id="r-{{ submission.pk }}" name="s-{{ submission.pk }}" value="reject" class="radio">
                    <label for="r-{{ submission.pk }}" title="{% trans "Reject" %}"></label>
                </div>
                <div class="unmark-radio" title="{% trans "Unset accept/reject vote" %}"><i class="fa fa-ban"></i></div>
                {% endif %}
            </td>
        </tr>
    {% empty %}
        <tr>
            <td>{% trans "You don't seem to have any submissions yet." %}</td>
        </tr>
    {% endfor %}
    </tbody>
</table>
<div id="submitBar">
    <span id="submitText" class="d-none">
        {% trans "Accept" %}: <span id="acceptCount" class="text-success"></span>
        {% trans "Reject" %}: <span id="rejectCount" class="text-danger"></span>
    </span>
    <button type="submit" class="btn btn-success">{% trans "Go!" %}</button>
</div>
</form>
{% endblock %}
