{% extends "base.html" %}
{% block title %}Utilisateurs — GMAO{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1><i class="bi bi-people"></i> Utilisateurs</h1>
        <a href="{{ url_for('admin.user_new') }}" class="btn btn-primary">
            <i class="bi bi-plus-circle"></i> Nouvel utilisateur
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            {% if users.items %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Nom</th>
                            <th>Email</th>
                            <th>Rôle</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for user in users.items %}
                        <tr>
                            <td>{{ user.full_name or user.username }}</td>
                            <td>{{ user.email or '-' }}</td>
                            <td>
                                <span class="badge bg-{{ 'danger' if user.is_admin() else 'secondary' }}">
                                    {{ user.role_label }}
                                </span>
                            </td>
                            <td>
                                <a href="{{ url_for('admin.user_edit', user_id=user.id) }}" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-pencil"></i>
                                </a>
                                <a href="{{ url_for('admin.user_access', user_id=user.id) }}" class="btn btn-sm btn-outline-secondary">Accès</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <p class="text-muted text-center mb-0">Aucun utilisateur.</p>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
