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

This file contains Apache-2.0 licensed contributions copyrighted by the following contributors:
SPDX-FileContributor: Florian Mösch
-->

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

{% load history_sidebar %}
{% load i18n %}
{% load rules %}
{% load static %}

{% block extra_title %}{{ form.instance.user.get_display_name }} :: {% endblock extra_title %}

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

{% block scripts %}
    {{ block.super }}
    <script defer src="{% static "vendored/htmx.min.js" %}"></script>
    <script defer src="{% static "common/js/ui/dialog.js" %}"></script>
    <script defer src="{% static "common/js/ui/history-dialog.js" %}"></script>
{% endblock scripts %}

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

{% block content %}
    {% has_perm "person.update_speakerprofile" request.user form.instance as can_edit_speaker %}
    {% has_perm "mail.send_queuedmail" request.user request.event as can_send_mails %}
    {% has_perm "person.mark_arrived_speakerprofile" request.user request.event as can_mark_speaker %}
    <h2 class="d-flex justify-content-between align-items-baseline">
        {% include "orga/includes/user_name.html" with user=form.instance.user lightbox=True %}
        <span class="ml-2">
            ({{ submissions.count }}
            {% blocktranslate asvar proposal_title trimmed count count=submissions.count %}
                proposal
            {% plural %}
                proposals
            {% endblocktranslate %}
            {{ proposal_title }})
        </span>
        <div class="ml-auto mb-1">
            {% if can_mark_speaker and accepted_submissions.exists %}
                {% include "orga/includes/mark_speakers_arrived.html" with speaker=form.instance %}
            {% endif %}
            <a href="{{ form.instance.orga_urls.password_reset }}" class="btn btn-info flip">{{ phrases.base.password_reset_heading }}</a>
            {% if can_send_mails %}
                <a class="btn btn-outline-info ml-2" href="{{ form.instance.orga_urls.send_mail }}">
                    <i class="fa fa-envelope"></i>
                    {% translate "Send email" %}
                </a>
            {% endif %}
        </div>
    </h2>
    {% if can_edit_speaker %}
        <div class="form-history-container">
            <div class="form-container">
    {% endif %}
    <div class="alert alert-info">
        <span>
            <h5>
                {{ proposal_title|capfirst }}
            </h5>
            <ul>
                {% for submission in submissions %}
                    <li>
                        <a href="{{ submission.orga_urls.base }}">
                            {{ submission.title }}
                            ({% include "cfp/event/fragment_state.html" with state=submission.state %}{% if submission.pending_state %}, {% translate "pending" %}{% include "cfp/event/fragment_state.html" with state=submission.pending_state %}{% endif %})
                        </a>
                    </li>
                {% endfor %}
            </ul>
        </span>
    </div>
    <form method="post" enctype="multipart/form-data">
        {% csrf_token %}
        {% include "common/forms/errors.html" %}

        {{ form.name.as_field_group }}
        {{ form.email.as_field_group }}
        {% if form.avatar %}
            {% include "common/avatar.html" with user=form.instance.user form=form %}
        {% endif %}

        {{ form.biography.as_field_group }}
        {{ form.availabilities.as_field_group }}
        {{ form.internal_notes.as_field_group }}

        {{ questions_form }}

        {% for extra_form in extra_forms %}
            <fieldset>
                {% if extra_form.label %}<legend>{{ extra_form.label }}</legend>{% endif %}
                {{ extra_form }}
            </fieldset>
        {% endfor %}

        {% include "orga/includes/submit_row.html" %}

    </form>

    <h3>{% translate "Emails" %}</h3>
    {% if mails %}
        {% include "common/mail_log.html" %}
    {% else %}
        {% translate "No mails were sent to this speaker yet." %}
    {% endif %}
    {% if can_edit_speaker %}
        </div>
        <div class="sidebar-container mt-4 pt-4">
            {% history_sidebar form.instance %}
        </div>
        </div>
    {% endif %}
{% endblock content %}
