{% extends "orga/submission/base.html" %}
{% load compress %}
{% load i18n %}
{% load rich_text %}
{% load rules %}
{% load static %}

{% block submission_content %}
    {% has_perm 'submission.edit_speaker_list' request.user submission as can_edit_speakers %}
    {% if can_edit_speakers %}<div class="alert">
        <form method="POST" action="{{ submission.orga_urls.new_speaker }}" class="form flex-row">
            <label>
                {% trans "Add a speaker – if the email address isn't registered yet, an account will be created for them and an invitation sent." %}:<br>
            </label>
            {% csrf_token %}
            <div class="input-group" id="speaker-typeahead">
                <input type="text" name="speaker" id="id_speaker" class="form-control" placeholder="{% trans "E-mail address" %}"/>
                <input type="text" name="name" id="id_speaker_name" class="form-control" placeholder="{% trans "Name" %}" />
                <button type="submit" class="btn btn-sm btn-success float-right"><i class="fa fa-plus"></i> {% trans "Add speaker" %}</button>
            </div>
        </form>
    </div>{% endif %}

    {% for speaker in speakers %}
    <div class="card"><div class="card-body">
        <h3 class="card-title">
            <a href="{% url "orga:speakers.view" event=request.event.slug pk=speaker.id %}">
                {{ speaker.name }}
            </a>
        </h3>
        {% if request.event.settings.cfp_request_biography %}
            <p class="card-text">
                <h5>{% trans "Biography" %}:</h5>
                {{ speaker.biography|rich_text|default:"-" }}
            </p>
        {% endif %}
        <p class="card-text">
        {% if speaker.other_submissions %}
            <h5>{% trans "Other submissions by this speaker:" %}</h5>
            <ul>
                {% for submission in speaker.other_submissions %}
                <li>
                    <a href="{{ submission.orga_urls.base }}">{{ submission.title }}</a>
                </li>
                {% endfor %}
            </ul>
        {% endif %}
        </p>
        {% if can_edit_speakers %}
        <a href="{% url "orga:speakers.view" event=request.event.slug pk=speaker.id %}"
            class="btn btn-info">
            <i class="fa fa-edit"></i> {% trans "Edit" %}
        </a>
        <a href="{{ submission.orga_urls.delete_speaker }}?id={{ speaker.id }}"
            class="btn btn-danger">
            <i class="fa fa-trash"></i> {% trans "Remove" %}
        </a>
        {% endif %}
    </div></div>
    {% endfor %}


    <span id="vars" remoteUrl="{{ request.event.orga_urls.users }}?search=%QUERY"></span>
    {% compress js %}
    <script defer src="{% static "orga/js/speakers.js" %}"></script>
    {% endcompress %}
{% endblock %}
