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

{% extends "cfp/event/base.html" %}

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

{% block title %}{{ submission.title }} :: {% endblock title %}

{% block scripts %}{% form_media %}{% endblock scripts %}

{% block content %}
    {% has_perm "submission.add_speaker_submission" request.user submission as can_invite_speakers %}

    {% include "cfp/includes/user_submission_header.html" %}

    <p>
        {% if submission.state == "accepted" %}
            <a href="{{ submission.urls.confirm }}" class="btn btn-sm btn-success">
                <i class="fa fa-check"></i> {% translate "Confirm your attendance" %}
            </a>
        {% elif submission.state == "confirmed" and request.event|get_feature_flag:"use_feedback" %}
            <a href="{{ submission.urls.feedback }}">
                {% if submission.does_accept_feedback %}
                    {% translate "Audience feedback" %}
                {% else %}
                    {% translate "Attendees can leave feedback here after your session has taken place." %}
                {% endif %}
            </a>
        {% endif %}
    </p>
    <h5>
        <form class="add-speaker" action="{{ submission.urls.invite }}">
            <div class="form-group form-inline flex-row">
                <div class="mt-1">
                    {% if submission.state == "confirmed" %}
                        {% blocktranslate trimmed count count=submission.speakers.count %}Speaker{% plural %}Speakers{% endblocktranslate %}:
                    {% else %}
                        {% blocktranslate trimmed count count=submission.speakers.count %}Submitter{% plural %}Submitters{% endblocktranslate %}:
                    {% endif %}
                    {{ submission.display_speaker_names }}{% if can_invite_speakers %},
                        </div>
                        <div class="input-group pl-2 w-auto">
                            <input name="email" class="form-control form-control-sm" placeholder="mail@example.org">
                            <span class="input-group-btn input-group-append">
                                <button class="btn btn-success btn-sm">
                                    <i class="fa fa-plus"></i>
                                </button>
                            </span>
                    {% endif %}
                </div>
            </div>
        </form>
    </h5>
    <form method="post" enctype="multipart/form-data">
        {% include "common/forms/errors.html" %}
        {% include "common/forms/errors.html" with form=qform %}
        {% csrf_token %}
        {% if not can_edit %}
            <div class="alert alert-info">
                {{ phrases.cfp.submission_uneditable }}
            </div>
        {% endif %}
        {{ form }}
        {{ qform }}
        {% if can_edit %}
            {% include "cfp/includes/submission_resources_form.html" %}
        {% elif form.instance.active_resources.count %}
            <ul>
                {% for resource in form.instance.active_resources %}
                    <li>{% include "agenda/includes/submission_resource.html" %}</li>
                {% endfor %}
            </ul>
        {% endif %}
        {% if can_edit %}
            <div class="row mt-4">
                {% if submission.state == "draft" %}
                    <div class="col-md-6 flip ml-auto">
                        <div class="d-flex align-items-start">
                            <button type="submit" class="btn btn-block btn-outline-success btn-lg" name="action" value="submit">
                                {% translate "Save draft" %}
                            </button>
                            <button type="submit" class="btn btn-block btn-success btn-lg mt-0 ml-2" name="action" value="dedraft">
                                {% translate "Submit proposal" %}
                            </button>
                        </div>
                    </div>
                {% else %}
                    <div class="col-md-3 flip ml-auto">
                        <button type="submit" class="btn btn-block btn-success btn-lg" name="action" value="submit">
                            {{ phrases.base.save }}
                        </button>
                    </div>
                {% endif %}
            </div>
        {% endif %}
    </form>

    {% if submission.review_code and request.event|get_feature_flag:"submission_public_review" %}
        <h3 id="share-proposal">{% translate "Share proposal" %}</h3>
        <p>
            {% blocktranslate trimmed %}
                If you need a review from a colleague or a friend here’s a link that you can send out for viewing your proposal:
            {% endblocktranslate %}
            <a target="_blank" rel="noopener" href="{{ submission.urls.review.full }}">{{ submission.urls.review.full }}</a>
        </p>
    {% endif %}

    {% if submission.state == "submitted" or submission.state == "accepted" %}
        <h3>{% translate "Withdraw proposal" %}</h3>
        <p>
            {% blocktranslate trimmed %}
                You can withdraw your proposal from the selection process here. You cannot undo this - if you are
                just uncertain if you can or should hold your session, please contact the organiser instead.
            {% endblocktranslate %}
        </p>
        <div class="row">
            <div class="col-md-3 flip ml-auto">
                <a href="{{ submission.urls.withdraw }}"
                   class="btn float-right btn-danger btn-block">
                    {% translate "Withdraw" %}
                </a>
            </div>
        </div>
    {% elif submission.state == "draft" %}
        <h3>{% translate "Discard draft proposal" %}</h3>
        <p>
            {% blocktranslate trimmed %}
                You can discard your draft proposal here. You cannot undo this - if you are
                just uncertain if you can or should submit your proposal, please contact the organiser instead.
            {% endblocktranslate %}
        </p>
        <div class="row">
            <div class="col-md-3 flip ml-auto">
                <a href="{{ submission.urls.discard }}"
                   class="btn float-right btn-danger btn-block">
                    {% translate "Discard" %}
                </a>
            </div>
        </div>
    {% elif submission.state == "confirmed" %}
        <h3>{% translate "Cancel proposal" %}</h3>
        <p>
            {% blocktranslate trimmed %}
                As your proposal has been accepted already, please contact the event’s organising team to cancel
                it. The best way to reach out would be an answer to your acceptance mail.
            {% endblocktranslate %}
        </p>
    {% endif %}
{% endblock content %}
