{% macro table(users) %}

    <table class="table table-results">

        <thead class="table-light">

        <tr>
            <th scope="col">Status</th>
            <th scope="col">ID</th>
            <th scope="col">First name</th>
            <th scope="col">Last name</th>
            <th scope="col">E-Mail</th>
            <th scope="col"></th>
        </tr>

        </thead>

        <tbody id="table-results-body">

        {% for user in users %}
            <tr>
                <td class="text-center">
                    {% if not user.is_active %}
                        <strong>Inactive</strong>
                    {% elif user.is_admin %}
                        <strong>Admin</strong>
                    {% endif %}
                </td>
                <td>{{ user.id }}</td>
                <td>{{ user.first_name }}</td>
                <td>{{ user.last_name }}</td>
                <td>{{ user.email }}</td>
                <td>
                    {% if not user.is_active %}
                        <a type="button"
                           href="{{ url_for('auth.change_active_status', id_=user.id) }}"
                           class="btn btn-sm btn-secondary">
                            Activate
                        </a>
                    {% elif current_user.is_admin or current_user.has_permission('register-user') %}
                        <div class="dropdown">
                            <button class="btn btn-sm btn-primary dropdown-toggle"
                                    type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                Actions
                            </button>

                            <ul class="dropdown-menu">
                                <li>
                                    <a class="dropdown-item"
                                       href="{{ url_for('auth.change_groups', id_=user.id) }}">
                                        Manage groups
                                    </a>
                                </li>
                                <li>
                                    <a class="dropdown-item"
                                       href="{{ url_for('auth.change_active_status', id_=user.id) }}">
                                        Inactivate user
                                    </a>
                                </li>
                                <li>
                                    <a class="dropdown-item"
                                       href="{{ url_for('auth.create_password_reset', id_=user.id) }}">
                                        Reset password
                                    </a>
                                </li>
                            </ul>

                        </div>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}

        </tbody>
    </table>

{% endmacro %}


{% macro table_groups(groups) %}

    <table class="table table-results">

        <thead class="table-light">

        <tr>
            <th scope="col">Name</th>
            <th scope="col">Description</th>
            <th scope="col"></th>
        </tr>

        </thead>

        <tbody id="table-results-body">

        {% for group in groups %}
            <tr>
                <td>{{ group.name }}</td>
                <td>
                    {{ group.description }}
                    <hr>
                    {% for permission in group.permissions %}
                        <span class="badge rounded-pill bg-primary">{{ permission.name }}</span>
                    {% endfor %}
                </td>
                <td>
                    <a class="btn btn-sm btn-primary" href="{{ url_for('auth.edit_group', id_=group.name) }}">
                        Edit
                    </a>
                </td>
            </tr>
        {% endfor %}

        </tbody>
    </table>

{% endmacro %}