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

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

    <form method="post">{% csrf_token %}
    <table class="table table-sm table-hover table-responsive-md">
        <thead>
            <tr>
                <th>{% translate "Name" %}</th>
                <th>{% translate "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"
                    >
                        {% translate "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="{% 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="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></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">
        {% 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 form layout='event' %}
        {% include "orga/submit_row.html" with submit_value="team" submit_name="form" %}
    </form>
</div>
{% endblock %}
