<!--
SPDX-FileCopyrightText: 2017-present Tobias Kunze
SPDX-License-Identifier: AGPL-3.0-only WITH LicenseRef-Pretalx-AGPL-3.0-Terms
-->

{% extends "orga/submission/base.html" %}

{% load i18n %}
{% load rich_text %}
{% load rules %}
{% load static %}

{% block submission_title %}{% translate "Reviews" %} :: {% endblock submission_title %}

{% block stylesheets %}
    {{ block.super }}
    <link rel="stylesheet" href="{% static "common/css/ui/tooltip.css" %}" />
    <link rel="stylesheet" href="{% static "orga/css/ui/review.css" %}" />
{% endblock stylesheets %}

{% block submission_content %}
    {% has_perm "submission.view_all_reviews_submission" request.user submission as can_view_other_reviews %}
    {% has_perm "submission.list_reviewers_review" request.user submission as can_view_reviewer_names %}
    {% has_perm "person.reviewer_list_speakerprofile" request.user submission as no_anonymisation %}
    {% if request.user in submission.speakers.all %}
        <div class="alert alert-error">
            <span>
                {% blocktranslate trimmed %}
                    You’re not allowed to review or see reviews for your own proposals.
                {% endblocktranslate %}
            </span>
        </div>
    {% else %}
        {% if not read_only %}
            {% if request.event.settings.review_help_text %}
                <div class="alert alert-info">
                    <div>
                        <p>{{ request.event.settings.review_help_text|rich_text }}</p>
                    </div>
                </div>
            {% elif not form.instance.pk and not can_view_other_reviews and request.event.active_review_phase and request.event.active_review_phase.can_see_other_reviews == "after_review" %}
                <div class="alert alert-info">
                    <p>
                        {% blocktranslate trimmed %}
                            You will be able to see other reviews once you have given yours.
                        {% endblocktranslate %}
                    </p>
                </div>
            {% endif %}
        {% endif %}

        <form method="post" id="review-form">
            {% csrf_token %}
            {% include "common/forms/errors.html" %}
            <div class="form-group row">
                <label class="col-md-3 col-form-label">{% translate "Title" %}</label>
                <div class="col-md-9 mt-2">
                    {% if no_anonymisation %}
                        {{ submission.title|default:"-" }}
                    {% else %}
                        {{ submission.anonymised.title|default:submission.title|default:"-" }}
                    {% endif %}
                </div>
            </div>
            <div class="form-group row">
                <label class="col-md-3 col-form-label">{% translate "Session type" %}</label>
                <div class="col-md-9 mt-2">{{ submission.submission_type }}</div>
            </div>
            {% if submission.track %}
                <div class="form-group row">
                    <label class="col-md-3 col-form-label">{% translate "Track" %}</label>
                    <div class="col-md-9 mt-2">{{ submission.track.name|default:"-" }}</div>
                </div>
            {% endif %}
            {% if request.event.cfp.request_abstract %}
                <div class="form-group row">
                    <label class="col-md-3 col-form-label">{% translate "Abstract" %}</label>
                    <div class="col-md-9 mt-2 markdown-mt-0">
                        {% if no_anonymisation %}
                            {{ submission.abstract|rich_text|default:"-" }}
                        {% else %}
                            {{ submission.anonymised.abstract|default:submission.abstract|rich_text|default:"-" }}
                        {% endif %}
                    </div>
                </div>
            {% endif %}
            {% if request.event.cfp.request_description %}
                <div class="form-group row">
                    <label class="col-md-3 col-form-label">{% translate "Description" %}</label>
                    <div class="col-md-9 mt-2 markdown-mt-0">
                        {% if no_anonymisation %}
                            {{ submission.description|rich_text|default:"-" }}
                        {% else %}
                            {{ submission.anonymised.description|default:submission.description|rich_text|default:"-" }}
                        {% endif %}
                    </div>
                </div>
            {% endif %}
            {% if request.event.cfp.request_notes %}
                <div class="form-group row">
                    <label class="col-md-3 col-form-label">{% translate "Notes" %}</label>
                    <div class="col-md-9 mt-2 markdown-mt-0">
                        {% if no_anonymisation %}
                            {{ submission.notes|rich_text|default:"-" }}
                        {% else %}
                            {{ submission.anonymised.notes|default:submission.notes|rich_text|default:"-" }}
                        {% endif %}
                    </div>
                </div>
            {% endif %}
            {% for answer in filtered_reviewer_answers %}
                <div class="form-group row">
                    <label class="col-md-3 col-form-label">{{ answer.question.question }}</label>
                    <div class="col-md-9 mt-2">

                        {% include "common/question_answer.html" with answer=answer %}

                    </div>
                </div>
            {% endfor %}
            {% if no_anonymisation %}
                {% if submission.public_resources %}
                    <div class="form-group row">
                        <label class="col-md-3 col-form-label">{% translate "Resources" %}</label>
                        <div class="col-md-9 mt-2">
                            {% for resource in submission.public_resources %}

                                {% include "agenda/includes/submission_resource.html" %}

                                {% if not forloop.last %}<br>{% endif %}
                            {% endfor %}
                        </div>
                    </div>
                {% endif %}
                {% if submission.private_resources %}
                    <div class="form-group row">
                        <label class="col-md-3 col-form-label">{% translate "Non-public resources" %}
                        </label>
                        <div class="col-md-9 mt-2">
                            {% for resource in submission.private_resources %}

                                {% include "agenda/includes/submission_resource.html" %} <i class="fa fa-lock"></i>

                                {% if not forloop.last %}<br>{% endif %}
                            {% endfor %}
                        </div>
                    </div>
                {% endif %}
            {% endif %}
            {% if no_anonymisation %}
                {% for speaker in profiles %}
                    <div class="form-group row">
                        <label class="col-md-3 col-form-label">
                            {% translate "Biography" %}{% if profiles|length > 1 %}: {% include "orga/includes/user_name.html" with user=speaker.user lightbox=True %}{% endif %}
                        </label>
                        <div class="col-md-9 mt-2 markdown-mt-0">
                            {% if request.event.cfp.request_biography %}
                                {{ speaker.biography|default:"-"|rich_text }}
                            {% endif %}
                            {% if speaker.submissions.count > 1 %}<br><strong>{% translate "Other proposals" %}:</strong>
                                <ul class="mt-0 mb-0">
                                    {% for other_submission in speaker.submissions %}{% if other_submission != submission %}
                                        <li>
                                            <a href="{{ other_submission.orga_urls.reviews }}">{{ other_submission.title }}</a>
                                            {% include "cfp/event/fragment_state.html" with state=other_submission.state as_badge=True %}
                                        </li>
                                    {% endif %}{% endfor %}
                                </ul>
                            {% endif %}
                        </div>
                    </div>
                {% endfor %}
            {% endif %}

            {% if not read_only %}
                {% if tags_form %}{{ tags_form }}{% endif %}

                <div id="own-review" {% if form.instance.pk %}class="d-none"{% endif %}>
                    {% for score_field in form.get_score_fields %}
                        {{ score_field.as_field_group }}
                    {% endfor %}
                    {{ qform }}
                    {{ form.text.as_field_group }}
                </div>
            {% endif %}
            {% for extra_form in extra_forms %}
                <fieldset>
                    {% if extra_form.label %}<legend>{{ extra_form.label }}</legend>{% endif %}
                    {{ extra_form }}
                </fieldset>
            {% endfor %}

            {% if can_view_other_reviews or form.instance.pk %}
                <div class="table-responsive-always">
                    <table class="table review-table table-flip table-sticky">
                        <thead>
                            <tr>
                                <th>{% translate "Score" %}</th>
                                {% if score_categories|length > 1 %}
                                    {% for cat in score_categories %}<th>{{ cat.name }}</th>{% endfor %}
                                {% endif %}
                                {% for field in qform %}<th>{{ field.label }}</th>{% endfor %}
                                <th class="review-text">{% translate "Review" %}</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            {% if form.instance.pk and review_display %}

                                {% include "orga/submission/review_fragment.html" with review=review_display read_only=read_only show_reviewer_name=False %}

                            {% endif %}
                            {% if can_view_other_reviews %}
                                {% for review in reviews %}

                                    {% include "orga/submission/review_fragment.html" with review=review read_only=True show_reviewer_name=can_view_reviewer_names %}

                                {% empty %}
                                    <tr>
                                        <td colspan="100">{% translate "Nobody else has submitted a review yet." %}</td>
                                    </tr>
                                {% endfor %}
                            {% endif %}
                        </tbody>
                    </table>
                </div>
            {% endif %}
            {% if not read_only %}
                {% if done != total_reviews %}
                    <div class="progress" title="{% translate "Review progress" %}: {{ done }} / {{ total_reviews }}">
                        <div class="progress-bar bg-success" role="progressbar" style="width: {{ percentage }}%" aria-valuenow="{{ done }}" aria-valuemin="0" aria-valuemax="{{ total_reviews }}" title="{% translate "Review progress" %}: {{ done }} / {{ total_reviews }}">
                        </div>
                    </div>
                {% endif %}
                <div class="submit-group pb-0 d-flex flex-row-reverse">
                    <div>
                        <div class="d-flex flex-row-reverse">
                            <button type="submit" class="btn btn-lg btn-success ml-1" name="review_submit" value="save_and_next" data-toggle="tooltip" data-placement="bottom" title="{% translate "Go to random next unreviewed proposal" %}">{% translate "Save and next" %}</button>
                            {% if not request.event.review_settings.score_mandatory and not request.event.review_settings.text_mandatory %}
                                <button type="submit" class="btn btn-lg btn-info ml-1" name="review_submit" value="abstain" data-toggle="tooltip" data-placement="bottom" title="{% translate "Go to random next unreviewed proposal" %}">{% translate "Abstain" %}</button>
                            {% endif %}
                            <button type="submit" class="btn btn-lg btn-info" name="review_submit" value="skip_for_now" data-toggle="tooltip" data-placement="bottom" title="{% translate "Go to random next unreviewed proposal, mark this one as skipped" %}">{% translate "Skip for now" %}</button>
                        </div>
                        <div class="text-right">
                            <small><a href="{{ request.event.orga_urls.reviews }}bulk/">
                                {% translate "Or review all proposals at once." %}
                            </a></small>
                        </div>
                    </div>
                    <div>
                        {% if form.instance.pk %}
                            <a href="{{ form.instance.urls.delete }}" class="btn btn-lg btn-outline-danger mr-1">{% translate "Delete review" %}</a>
                        {% endif %}
                        <button type="submit" class="btn btn-lg btn-outline-success" name="review_submit" value="save">
                            {{ phrases.base.save }}
                        </button>
                    </div>
                </div>
            {% endif %}
        </form>
    {% endif %}  {# endif: request.user in submission.speakers #}
{% endblock submission_content %}
