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

{% block page_title %}{% translate "Group Members" %}{% endblock page_title %}
{% block header_nav_brand %}{% translate "Group Members" %} - {{ group.name }}{% endblock header_nav_brand %}

{% block header_nav_collapse_left %}
<li class="nav-item ">
    <a class="nav-link {% navactive request 'groupmanagement:management' %}" href="{% url 'groupmanagement:management' %}">{% translate "Back" %}</a>
</li>
{% endblock %}

{% block content %}
    {% if group.user_set %}
        <div class="table-responsive">
            <table class="table table-aa" 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>
                                <img src="{{ member.main_char|character_portrait_url:32 }}" class="rounded-circle" style="margin-right: 1rem;" alt="{{ member.main_char.character_name }}">
                                {% 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 %}

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

                            <td>
                                {% 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-end">
                                <a href="{% url 'groupmanagement:membership_remove' group.id member.user.id %}" class="btn btn-danger" title="{% translate "Remove from group" %}">
                                    <i class="fa-solid fa-xmark"></i>
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>

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

{% endblock content %}

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

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

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