{% extends "allianceauth/base.html" %}
{% load static %}
{% load i18n %}

{% block page_title %}{% translate "Groups Membership" %}{% endblock page_title %}

{% block content %}
    <div class="clearfix">
        <br>
        {% include 'groupmanagement/menu.html' %}

        <div class="panel panel-default">
            <div class="panel-heading">
                {% translate "Groups" %}
            </div>

            <div class="panel-body">
                {% if groups %}
                    <table class="table table-striped" id="group-membership-overview">
                        <thead>
                            <tr>
                                <th>{% translate "Name" %}</th>
                                <th>{% translate "Description" %}</th>
                                <th>{% translate "Status" %}</th>
                                <th style="white-space: nowrap;">{% translate "Member Count" %}</th>
                                <th style="min-width: 170px;"></th>
                            </tr>
                        </thead>

                        <tbody>
                            {% for group in groups %}
                                <tr>
                                    <td>
                                        <a href="{% url 'groupmanagement:membership' group.id %}">{{ group.name }}</a>
                                    </td>

                                    <td>{{ group.authgroup.description|linebreaks|urlize }}</td>

                                    <td>
                                        {% if group.authgroup.hidden %}
                                            <span class="label label-info">{% translate "Hidden" %}</span>
                                        {% elif group.authgroup.open %}
                                            <span class="label label-success">{% translate "Open" %}</span>
                                        {% else %}
                                            <span class="label label-default">{% translate "Requestable" %}</span>
                                        {% endif %}
                                    </td>

                                    <td class="text-right">
                                        {{ group.num_members }}
                                    </td>

                                    <td class="text-right">
                                        <a href="{% url 'groupmanagement:membership' group.id %}" class="btn btn-primary" title="{% translate "View Members" %}">
                                            <i class="glyphicon glyphicon-eye-open"></i>
                                        </a>

                                        <a href="{% url "groupmanagement:audit_log" group.id %}" class="btn btn-info" title="{% translate "Audit Members" %}">
                                            <i class="glyphicon glyphicon-list-alt"></i>
                                        </a>

                                        <a id="clipboard-copy" data-clipboard-text="{{ request.scheme }}://{{request.get_host}}{% url 'groupmanagement:request_add' group.id %}" class="btn btn-warning" title="{% translate "Copy Direct Join Link" %}">
                                            <i class="glyphicon glyphicon-copy"></i>
                                        </a>
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                {% else %}
                    <div class="alert alert-warning text-center">
                        {% translate "No groups to list." %}
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
{% endblock content %}

{% block extra_css %}
    {% include 'bundles/datatables-css.html' %}
{% endblock extra_css %}

{% block extra_javascript %}
    {% include 'bundles/datatables-js.html' %}
    {% include 'bundles/clipboard-js.html' %}

    <script>
        $(document).ready(function() {
            {% if groups %}
                $('#group-membership-overview').DataTable({
                    paging: false,
                    info: false,
                    order: [
                        [0, 'asc']
                    ],
                    columnDefs: [
                        {
                            width: '250px',
                            targets: [0]
                        },
                        {
                            width: '150px',
                            targets: [4]
                        },
                        {
                            orderable: false,
                            targets: [1,2,3,4]
                        }
                    ],
                });
            {% endif %}

            new ClipboardJS('#clipboard-copy');
        });
    </script>
{% endblock %}
