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

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

    <form method="post">{% csrf_token %}
    <table class="table table-sm table-hover table-responsive-md">
        <thead>
            <tr>
                <th>{% trans "Name" %}</th>
                <th>{% trans "Email" %}</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {% for member in team.members.all %}
            <tr>
                <td>{{ member.get_display_name }}</td>
                <td><a href="mailto:{{ member.email }}">{{ member.email }}</a></td>
                <td class="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"
                    >
                        {% trans "Reset password" %}
                    </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="{% trans "Remove team member" %}"
                    >
                        <i class="fa fa-trash"></i>
                    </a>
                </td>
            </tr>
            {% endfor %}
            {% for member in team.invites.all %}
            <tr>
                <td>
                    <em>({% trans "pending Invitation" %})</em>
                </td>
                <td>
                    {{ member.email }}
                    <a href="{{ member.urls.invitation }}">
                        <i class="fa fa-link"></i>
                    </a>
                </td>
                <td class="text-right">
                    <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>{% trans "Add member" %}</strong></td>
                <td>{% csrf_token %}{% bootstrap_field invite_form.email layout='inline' %}</td>
                <td class="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>
    </form>
    <h3 id="permissions">
        {% trans "Team" %} {{ quotation_open }}{{ team.name }}{{ quotation_close }}: {% trans "Permissions" %}
    </h3>
    {% else %}
    <h2>{% trans "New team" %}</h2>
    {% endif %}

    <form method="post">
        {% csrf_token %}
        {% bootstrap_form form layout='event' %}
        {% include "orga/submit_row.html" with submit_value="team" submit_name="form" %}
    </form>
</div>
{% endblock %}
