{#
SPDX-FileCopyrightText: 2026 Martin Kirchgessner

SPDX-License-Identifier: AGPL-3.0-or-later
#}

{% extends 'layout.jinja' %}
{% block title %}Users{% endblock title %}

{% block content %}
<section class="content">
<div class="container">
<h1>
    Users
</h1>
<p>
    <a
        class="button is-primary"
        href="{{ url_for('users.add_form')}}"
        aria-label="Create user"
        >
        Create user
    </a>
</p>

<table class="table is-fullwidth is-striped is-hoverable" aria-label="Users list">
    <thead>
        <tr>
            <th scope="col">Username</th>
            <th scope="col">Notes</th>
            <th scole="col">Roles</th>
            <th scope="col">Created</th>
            <th scope="col">Modified</th>
            <th scope="col">Actions</th>
        </tr>
    </thead>
    <tbody id="usersrows">
        {% for user in users %}
            <tr class="fade-in fade-out">
                <td>
                    <a title="Edit" href="{{ url_for('users.get', user_id=user.id) }}">
                        {{ user.username }}
                    </a>
                </td>
                <td>{{ user.notes }}</td>
                <td>
                    {{ ', '.join(user.roles.keys()) }}
                </td>
                <td>{{ date_span(user.created) }}</td>
                <td>{{ date_span(user.modified) }}</td>
                <td>
                    <a title="Edit" href="{{ url_for('users.get', user_id=user.id) }}">
                        {{ icon('✏️') }}
                    </a>
                    <button title="Delete"
                        hx-delete="{{ url_for('users.delete', user_id=user.id) }}"
                        hx-on::confirm="confirmWithMessage(`Really delete user account for {{user.username}}?`)"
                        hx-swap="outerHTML"
                        hx-target="closest tr"
                    >
                        {{ icon('❌') }}
                    </button>
                </td>
            </tr>
        {% endfor %}
    </tbody>
</table>
</div>
</section>
{% endblock content %}
