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

{% block page_title %}{% translate "Group Members" %}{% endblock page_title %}

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

        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="panel-title">{{ group.name }} - {% translate 'Members' %}</div>
            </div>

            <div class="panel-body">
                <p>
                    <a class="btn btn-default" href="{% url 'groupmanagement:membership' %}" role="button">
                        {% translate "Back" %}
                    </a>
                </p>

                {% if group.user_set %}
                    <div class="table-responsive">
                        <table class="table table-striped table-hover" id="tab_group_members">
                            <thead>
                                <tr>
                                    <th>{% translate "Character" %}</th>
                                    <th>{% translate "Organization" %}</th>
                                    <th></th>
                                </tr>
                            </thead>

                            <tbody>
                                {% for member in members %}
                                    <tr>
                                        <td class="valign-middle">
                                            {% if member.main_char %}
                                                <img src="{{ member.main_char|character_portrait_url:32 }}" class="img-rounded" style="margin-right: 0.25rem;">

                                                <a href="{{ member.main_char|evewho_character_url }}" target="_blank">
                                                    {{ member.main_char.character_name }}
                                                </a>
                                            {% else %}
                                                {{ member.user.username }}
                                            {% endif %}

                                            {% if member.is_leader %}
                                                <i class="fas fa-star" title="{% translate "Group leader" %}" style="margin-left: 1rem;"></i>&nbsp;
                                            {% endif %}
                                        </td>

                                        <td class="valign-middle">
                                            {% if member.main_char %}
                                                <a href="{{ member.main_char|dotlan_corporation_url }}" target="_blank">
                                                    {{ member.main_char.corporation_name }}
                                                </a>
                                                <br>
                                                {{ member.main_char.alliance_name|default_if_none:"" }}
                                            {% else %}
                                                {% translate "(unknown)" %}
                                            {% endif %}
                                        </td>

                                        <td class="text-right valign-middle">
                                            <a href="{% url 'groupmanagement:membership_remove' group.id member.user.id %}" class="btn btn-danger" title="{% translate "Remove from group" %}">
                                                <i class="glyphicon glyphicon-remove"></i>
                                            </a>
                                        </td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>

                        <p class="text-muted">
                            <i class="fas fa-star"></i>: {% translate "Group leader" %}
                        </p>
                    </div>
                {% else %}
                    <div class="alert alert-warning text-center">
                        {% translate "No group members to list." %}
                    </div>
                {% endif %}
            </div>

        </div>
    </div>
{% endblock content %}

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

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

    <script type="application/javascript">
        $(document).ready(function() {
            {% if group.user_set %}
                $('#tab_group_members').DataTable({
                    order: [[0, "asc"]],
                    columnDefs: [
                        {
                            width: '250px',
                            targets: [0]
                        },
                        {
                            width: '150px',
                            targets: [2]
                        },
                        {
                            orderable: false,
                            targets: [2]
                        }
                    ]
                });
            {% endif %}
        });
    </script>
{% endblock %}

{% block extra_script %}
{% endblock %}
