{% extends "orga/settings/base.html" %}
{% load bootstrap4 %}
{% load compress %}
{% load i18n %}
{% load static %}

{% block settings_content %}
    <div>
        {% if team.pk %}
            <h2>
                {% translate "Team" %} {{ quotation_open }}{{ team.name }}{{ quotation_close }}: {% translate "Members" %}
            </h2>

            <form method="post">{% csrf_token %}
                <div class="table-responsive-sm">
                    <table class="table table-sm table-hover table-flip table-sticky">
                        <thead>
                            <tr>
                                <th>{% translate "Name" %}</th>
                                <th>{% translate "Email" %}</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for member in members %}
                                <tr>
                                    <td>{{ member.get_display_name }}</td>
                                    <td><a href="mailto:{{ member.email }}">{{ member.email }}</a></td>
                                    <td class="flip text-right">
                                        <a
                                            href="{% if request.event %}{{ request.event.orga_urls.team_settings }}{% else %}{{ request.organiser.orga_urls.teams }}{% endif %}{{ team.id }}/reset/{{ member.id }}"
                                            class="btn btn-sm btn-warning"
                                        >
                                            {{ phrases.base.password_reset_heading }}
                                        </a>
                                        <a
                                            href="{% if request.event %}{{ request.event.orga_urls.team_settings }}{% else %}{{ request.organiser.orga_urls.teams }}{% endif %}{{ team.id }}/delete/{{ member.id }}"
                                            class="btn btn-sm btn-danger" title="{% translate "Remove team member" %}"
                                        >
                                            <i class="fa fa-trash"></i>
                                        </a>
                                    </td>
                                </tr>
                            {% endfor %}
                            {% for member in team.invites.all %}
                                <tr>
                                    <td>
                                        <em>({% translate "pending Invitation" %})</em>
                                    </td>
                                    <td>
                                        {{ member.email }}
                                        <a href="{{ member.urls.invitation }}">
                                            <i class="fa fa-link"></i>
                                        </a>
                                    </td>
                                    <td class="flip text-right">
                                        <a
                                            href="{% if request.event %}{{ request.event.orga_urls.team_settings }}{% else %}{{ request.organiser.orga_urls.teams }}{% endif %}{{ member.id }}/resend"
                                            class="btn btn-sm btn-outline-warning"
                                        >
                                            {% translate "Resend invite" %}
                                        </a>
                                        <a
                                            href="{% if request.event %}{{ request.event.orga_urls.team_settings }}{% else %}{{ request.organiser.orga_urls.teams }}{% endif %}{{ member.id }}/uninvite"
                                            class="btn btn-sm btn-danger"
                                        >
                                            <i class="fa fa-trash"></i>
                                        </a>
                                    </td>
                                </tr>
                            {% endfor %}
                            <tr>
                                <td>
                                    <strong>{% translate "Add member" %}</strong><br>
                                    <small><em><a id="bulk-email" href="">{% translate "Add multiple team members?" %}</a></em></small>
                                </td>
                                <td>
                                    {% csrf_token %}
                                    {% bootstrap_field invite_form.email layout='inline' form_group_class="single-email-group" %}
                                    {% bootstrap_field invite_form.bulk_email layout='inline' form_group_class="d-none bulk-email-group" %}
                                    <small class="form-text text-muted bulk-email-help-text d-none">
                                        {{ invite_form.bulk_email.help_text }}
                                    </small>
                                </td>
                                <td class="flip text-right">
                                    <button type="submit" name="form" value="invite" class="btn btn-success btn-sm"><i class="fa fa-check"></i></button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </form>
            <h3 id="permissions">
                {% translate "Team" %} {{ quotation_open }}{{ team.name }}{{ quotation_close }}: {% translate "Permissions" %}
            </h3>
        {% else %}
            <h2>{% translate "New team" %}</h2>
        {% endif %}

        <form method="post">
            {% csrf_token %}
            {% bootstrap_form_errors form %}
            {% bootstrap_field form.name layout='event' %}
            {% bootstrap_field form.all_events layout='event' %}
            {% bootstrap_field form.limit_events layout='event' %}
            {% bootstrap_field form.can_create_events layout='event' %}
            {% bootstrap_field form.can_change_teams layout='event' %}
            {% bootstrap_field form.can_change_organiser_settings layout='event' %}
            {% bootstrap_field form.can_change_event_settings layout='event' %}
            {% bootstrap_field form.can_change_submissions layout='event' %}
            {% bootstrap_field form.is_reviewer layout='event' %}
            <div class="form-group row">
                <div class="col-md-3"></div>
                <div class="col-md-9">
                    <h3 id="review-settings">{% translate "Review settings" %}</h3>
                </div>
            </div>
            {% bootstrap_field form.force_hide_speaker_names layout='event' %}
            {% bootstrap_field form.limit_tracks layout='event' %}
            {% include "orga/includes/submit_row.html" with submit_value="team" submit_name="form" %}
        </form>
    </div>

    <span id="vars" remoteUrl="{{ request.organiser.orga_urls.base }}api/users?orga=true&search=%QUERY"></span>
    {% compress js %}
        <script defer src="{% static "vendored/typeahead.bundle.min.js" %}"></script>
        <script defer src="{% static "orga/js/speakers.js" %}"></script>
        <script defer src="{% static "orga/js/teamSettings.js" %}"></script>
    {% endcompress %}
{% endblock %}
