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

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

{% block content %}
    <div class="col-lg-12">
        <br>
        {% include 'groupmanagement/menu.html' %}
        
        <div class="panel panel-default">
            <div class="panel-heading">
                {{ group.name }} - {% trans 'Members' %}
            </div>
            <div class="panel-body">                
                <p>                    
                    <a class="btn btn-default" href="{% url 'groupmanagement:membership' %}" role="button">
                        {% trans "Back" %}
                    </a>
                </p>                
                {% if group.user_set %}                    
                    <div class="table-responsive">
                        <table class="table table-aa" id="tab_group_members">
                            <thead>
                                <tr>                                                        
                                    <th class="text-right">{% trans "Portrait" %}</th>
                                    <th class="text-center">{% trans "Character" %}</th>
                                    <th class="text-center">{% trans "Organization" %}</th>                                    
                                    <th class="text-center"></th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for member in members %}
                                    <tr>                                                                
                                        <td class="text-right">
                                            {% if member.is_leader %}
                                                <i class="fas fa-star"></i>&nbsp;
                                            {% endif %}
                                            <img src="{{ member.main_char|character_portrait_url:32 }}" class="img-circle">                                            
                                        </td>
                                        <td class="text-center">
                                            {% if member.main_char %}
                                                <a href="{{ member.main_char|evewho_character_url }}" target="_blank">
                                                    {{ member.main_char.character_name }}
                                                </a>
                                            {% else %}
                                                {{ member.user.username }}
                                            {% endif %}
                                        </td>
                                        <td class="text-center">
                                            {% 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 %}
                                                (unknown)
                                            {% endif %}
                                        </td>                                                                
                                        <td class="text-center">
                                            <a href="{% url 'groupmanagement:membership_remove' group.id member.user.id %}" class="btn btn-danger"
                                                title="{% trans "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>: Group leader</p>
                    </div>
                {% else %}
                    <div class="alert alert-warning text-center">
                        {% trans "No group members to list." %}
                    </div>
                {% endif %}
            </div>
            
        </div>
    </div>
{% endblock content %}

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

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

{% block extra_script %}
    $(document).ready(function(){
        $('#tab_group_members').DataTable({
            order: [ [ 1, "asc" ] ],
            columnDefs: [
                { "sortable": false, "targets": [0, 3] },
            ]
        });
    });
{% endblock %}