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

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

{% load event_tags %}
{% load i18n %}
{% load rules %}
{% load static %}

{% block extra_title %}
    {% block submission_title %}{% endblock submission_title %}
    {% has_perm "person.orga_list_speakerprofile" request.user request.event as can_view_speakers %}
    {% if can_view_speakers %}{{ submission.title }}{% else %}{{ submission.anonymised.title|default:submission.title }}{% endif %} ::
{% endblock extra_title %}

{% block alternate_link %}
    <link rel="alternate" type="application/json" title="{{ request.event.name }} API" href="{{ request.event.api_urls.talks.full }}{{ submission.code }}" />
{% endblock alternate_link %}

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

{% block content %}
    {% if submission %}
        {% has_perm "submission.update_submission" request.user submission as can_edit_submission %}
        {% has_perm "submission.view_reviews_submission" request.user submission as can_view_reviews %}
        {% has_perm "submission.review_submission" request.user submission as can_review %}
        {% has_perm "person.orga_list_speakerprofile" request.user request.event as can_view_speakers %}
        {% has_perm "mail.send_queuedmail" request.user request.event as can_send_mails %}
        <h2>
            <span>
                {{ quotation_open }}{% if can_view_speakers %}{{ submission.title }}{% else %}{{ submission.anonymised.title|default:submission.title }}{% endif %}{{ quotation_close }}
                {% if submission.speakers.exists and can_view_speakers %}
                    – {% include "orga/includes/submission_speaker_names.html" with lightbox=True %}
                {% endif %}
                {% if can_edit_submission %}
                    {% include "orga/submission/state_dropdown.html" with submission=submission %}

                    {% if submission.pending_state and can_edit_submission %}
                        <form action="{{ submission.orga_urls.apply_pending }}" method="post" class="d-inline">
                            {% csrf_token %}
                            <button type="submit" class="btn btn-info" href="{{ request.event.orga_urls.apply_pending }}">
                                {% translate "Apply pending changes" %}
                            </button>
                        </form>
                    {% endif %}
                {% else %}
                    {% include "cfp/event/fragment_state.html" with state=submission.state as_badge=True %}
                {% endif %}
            </span>
        </h2>

        <div role="tablist" class="mb-4">
            <a role="tab" href="{{ submission.orga_urls.base }}" {% if "submissions.content" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                {% translate "Content" %}
            </a>
            {% if can_view_speakers %}
                <a role="tab" href="{{ submission.orga_urls.speakers }}" {% if "submissions.speakers" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                    {{ phrases.schedule.speakers }}
                </a>
            {% endif %}
            {% if can_edit_submission and has_anonymised_review %}
                <a role="tab" href="{{ submission.orga_urls.anonymise }}" {% if "submissions.anonymise" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                    {% translate "Anonymisation" %}
                </a>
            {% endif %}
            {% if submission.feedback.count and request.event|get_feature_flag:"use_feedback" %}
                <a role="tab" href="{{ submission.orga_urls.feedback }}" {% if "submissions.feedback" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                    {% translate "Feedback" %}
                </a>
            {% endif %}
            {% if can_view_reviews or can_review %}
                <a role="tab" href="{{ submission.orga_urls.reviews }}" {% if "submissions.reviews" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                    {% translate "Reviews" %}
                </a>
            {% endif %}
            {% if request.event|get_feature_flag:"use_submission_comments" %}
                <a role="tab" href="{{ submission.orga_urls.comments }}" {% if "submissions.comments" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                    {% translate "Comments" %}
                    {% with submission.comments.count as comment_count %}
                        {% if comment_count %}
                            <span class="submission-comment-count">{{ comment_count }}</span>
                        {% endif %}
                    {% endwith %}
                </a>
            {% endif %}
            {% if can_view_speakers %}
                <a role="tab" href="{{ submission.orga_urls.history }}" {% if "submissions.history" in url_name %}aria-selected="true"{% else %}aria-selected="false"{% endif %}>
                    {% translate "History" %}
                </a>
            {% endif %}
            <div class="ml-auto flip d-flex">
                {% if can_send_mails %}
                    <a class="btn btn-outline-info mr-2 mb-1" href="{{ request.event.orga_urls.compose_mails_sessions }}?submissions={{ submission.code }}">
                        <i class="fa fa-envelope"></i>
                        {% translate "Send email to speakers" %}
                    </a>
                {% endif %}
                {% if submission.state == "confirmed" or can_view_speakers %}
                    <details class="dropdown" aria-haspopup="menu" role="menu">
                        <summary class="color-primary" role="button">
                            {% translate "Links" %} <i class="fa fa-caret-down"></i>
                        </summary>
                        <div class="dropdown-content dropdown-content-s{% if rtl %}e{% else %}w{% endif %}">
                            {% if is_publicly_visible or submission.state == "accepted" or submission.state == "confirmed" %}
                                <a href="{{ submission.urls.public.full }}" class="dropdown-item" target=_blank role="menuitem" tabindex="-1">
                                    <i class="fa fa-link"></i>
                                    {% translate "Public link" %}
                                    {% if not is_publicly_visible %}
                                        ({% translate "not public yet" %})
                                    {% endif %}
                                </a>
                            {% endif %}
                            {% if can_view_speakers and request.event|get_feature_flag:"submission_public_review" %}
                                <a href="{{ submission.urls.review.full }}" class="dropdown-item" target="_blank" role="menuitem" tabindex="-1">
                                    <i class="fa fa-eye"></i>
                                    {% translate "Secret public link" %}
                                </a>
                            {% endif %}
                        </div>
                    </details>
                {% endif %}
            </div>
        </div>
    {% endif %}
    {% block submission_content %}{% endblock submission_content %}
{% endblock content %}
