{% extends "base.html" %}
{% load utils %}
{% load user_extras %}
{% load static %}
{% load i18n %}

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

{% block content %}
    <div class="page-header">
        <h1>{% trans "Users" %}</h1>
    </div>
    {% if perms.core.add_userprofile %}
        <a class="btn btn-secondary mb-3" href="{% url "core:userprofile_create" %}"><span
                class="fa fa-plus"></span> {% trans "Add user" %}</a>
    {% endif %}
    {% with global_preferences.general__relevant_qualification_categories as relevant_qualification_categories %}
        <table id="userprofile_table" class="table table-striped display">
            <thead>
            <tr>
                <th>{% trans "Last name" %}</th>
                <th>{% trans "First name" %}</th>
                <th class="d-none d-md-table-cell">{% trans "Email address" %}</th>
                {% for category in relevant_qualification_categories %}
                    <th class="d-none d-lg-table-cell">{{ category.title }}</th>
                {% endfor %}
                <th class="d-none d-lg-table-cell">{% trans "Information" %}</th>
                <th>{% trans "Action" %}</th>
            </tr>
            </thead>
            <tbody>
            {% for userprofile in userprofile_list %}
                <tr>
                    <td>{{ userprofile.last_name }}</td>
                    <td>{{ userprofile.first_name }}</td>
                    <td class="d-none d-md-table-cell">{{ userprofile.email }}</td>
                    {% for category in relevant_qualification_categories %}
                        <td class="d-none d-lg-table-cell">{{ userprofile|qualifications_for_category:category.pk }}</td>
                    {% endfor %}
                    <td class="d-none d-lg-table-cell">{% include "core/userprofile_badges.html" with userprofile=userprofile %}</td>
                    <td class="d-flex">
                        <a class="btn btn-secondary btn-sm text-nowrap"
                               href="{% url "core:userprofile_detail" userprofile.pk %}"><span
                                    class="fa fa-eye"></span> <span
                                    class="d-none d-md-inline">{% trans "View" %}</span></a>
                        <a class="btn btn-secondary btn-sm text-nowrap ms-1"
                           href="{% url "core:userprofile_edit" userprofile.pk %}"><span
                                class="fa fa-edit"></span> <span
                                class="d-none d-md-inline">{% trans "Edit" %}</span></a>
                        {% if perms.core.delete_userprofile %}
                            <a class="btn btn-secondary btn-sm text-nowrap ms-1"
                               href="{% url "core:userprofile_delete" userprofile.pk %}"><span
                                    class="fa fa-trash-alt"></span> <span
                                    class="d-none d-md-inline">{% trans "Delete" %}</span></a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    {% endwith %}
{% endblock %}
