{% extends "./base.html" %}
{% load i18n aircox %}

{% block title %}{% translate "Users" %}{% endblock %}


{% block content-container %}
<div class="container">
    {% if user.is_superuser %}
    <div class="message is-info mt-3">
        <div class="message-body">
            {% translate "Group and editors' changes will be visible only after page reload." %}
        </div>
    </div>
    {% endif %}

    <table class="table is-stripped is-fullwidth">
        <thead>
            <td>{% trans "User" %}</td>
            <td>{% trans "Infos" %}</td>
            <td>{% trans "Programs" %}</td>
            <td></td>
        </thead>
        <tbody>
            {% for obj in object_list %}
            <tr>
                <td>
                    <div>
                        {% if obj.first_name or obj.last_name %}
                        <b>{{ obj.first_name }} {{ obj.last_name }}</b>
                        &mdash;
                        {% endif %}
                        {{ obj.username }}
                    </div>
                    {% if obj.email %}
                    <div class="text-light smaller">{{ obj.email }}</div>
                    {% endif %}
                </td>
                <td>
                    {% if not obj.is_active %}
                    <span class="tag is-danger">{% trans "Inactive" %}</span>
                    {% endif %}
                    {% if obj.is_superuser %}
                    <span class="tag is-warning">{% trans "Admin" %}</span>
                    {% elif obj.is_staff %}
                    <span class="tag is-info">{% trans "Staff" %}</span>
                    {% endif %}
                </td>
                <td>
                    {% for p in obj.programs %}
                    <a href="{{ p.get_absolute_url }}">{{ p.title }}</a>
                    {% if not forloop.last %}
                    <br/>
                    {% endif %}
                    {% endfor %}
                </td>
                <td>
                    {% if user.is_superuser %}
                    <button type="button" class="button secondary"
                            @click="$refs['user-groups-modal'].open({id: {{ obj.id }}, username: '{{ obj.username }}' })">
                        {% trans "Groups" %}
                    </button>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

{% include "aircox/widgets/list_pagination.html" %}

{% if user.is_superuser %}
{% include "./widgets/user_groups.html" %}
{% endif %}

{% endblock %}
