{% extends "sentry/teams/manage.html" %}

{% load i18n %}
{% load sentry_helpers %}
{% load sentry_permissions %}

{% block bodyclass %} with-sidebar{% endblock %}

{% block sidebar %}
    <h6>{% trans "About Memberships" %}</h6>
    {% url 'sentry-manage-team-access-groups' team.slug as link %}
    <p>{% blocktrans %}This page lists team-wide memberships whom have access to all projects owned by this team. If you wish to add memberships bound to individual projects, you can do so with <a href="{{ link }}">Access Groups</a>.{% endblocktrans %}</p>
{% endblock %}

{% block inner %}
    <div class="page-header">
        {% if user|can_add_team_member:team %}
            <a href="{% url 'sentry-new-team-member' team.slug %}" class="btn pull-right btn-primary">{% trans "New Member" %}</a>
        {% endif %}
        <h2>{% trans "Members" %}</h2>
    </div>
    <table class="table table-striped">
        <colgroup>
            <col/>
            <col width="100px"/>
            <col width="90px"/>
        </colgroup>
        <thead>
            <tr>
                <th>{% trans "User" %}</th>
                <th style="text-align:center;">{% trans "Access" %}</th>
                <th style="text-align:center">{% trans "Actions" %}</th>
            </tr>
        </thead>
        <tbody>
            {% for member, user in member_list %}
                {% if user == team.owner %}
                    <tr>
                        <td>
                            {% if user.first_name %}{{ user.first_name }} &mdash; {% endif %}{{ user.username }}</a><br>
                            {{ user.email }}
                        </td>
                        <td style="text-align:center;">
                            {% trans "Owner" %}
                        </td>
                        <td style="text-align:center;">
                            <em>{% trans "unavailable for owner" %}</em>
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td>
                            <a href="{% url 'sentry-edit-team-member' team.slug member.pk %}">{% if user.first_name %}{{ user.first_name }} &mdash; {% endif %}{{ user.username }}</a><br>
                            {{ user.email }}
                        </td>
                        <td style="text-align:center;">
                            {{ member.get_type_display }}
                        </td>
                        <td style="text-align:center;">
                            <a href="{% url 'sentry-remove-team-member' team.slug member.pk %}" class="btn btn-danger btn-small">{% trans "Remove" %}</a>
                        </td>
                    </tr>
                {% endif %}
            {% endfor %}
        </tbody>
    </table>
    {% if pending_member_list %}
        <div class="page-header">
            <h3>{% trans "Pending Members" %}</h3>
        </div>
        <table class="table table-bordered table-striped">
            <colgroup>
                <col/>
                <col width="100px"/>
                <col width="90px"/>
                <col width="90px"/>
            </colgroup>
            <thead>
                <tr>
                    <th>{% trans "User" %}</th>
                    <th style="text-align:center">{% trans "Access" %}</th>
                    <th style="text-align:center" colspan="2">{% trans "Actions" %}</th>
                </tr>
            </thead>
            <tbody>
                {% for member, email in pending_member_list %}
                    <tr>
                        <td>
                            {{ email }}
                        </td>
                        <td style="text-align:center;">
                            {{ member.get_type_display }}
                        </td>
                        <td style="text-align:center;">
                            <a href="{% url 'sentry-remove-pending-team-member' team.slug member.pk %}" class="btn btn-small btn-danger">{% trans "Remove" %}</a>
                        </td>
                        <td style="text-align:center;">
                            <a href="{% url 'sentry-reinvite-pending-team-member' team.slug member.pk %}" class="btn btn-small">{% trans "Resend" %}</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
{% endblock %}
