{{define "users.html"}}
{{template "partials/header.html" .}}

<style>
    .users-table {
        width: 100%;
    }
    .users-table th, .users-table td {
        text-align: left;
        padding: 0.75rem;
    }
    .badge {
        display: inline-block;
        padding: 0.25rem 0.5rem;
        border-radius: 4px;
        font-size: 0.8rem;
        font-weight: 500;
    }
    .badge-success {
        background: #dcfce7;
        color: #166534;
    }
    .badge-warning {
        background: #fef3c7;
        color: #92400e;
    }
    .badge-role {
        background: #e0e7ff;
        color: #3730a3;
    }
    .btn-danger {
        background: #dc2626;
        border-color: #dc2626;
    }
    .btn-danger:hover {
        background: #b91c1c;
        border-color: #b91c1c;
    }
</style>

<h1>Utilisateurs Admin</h1>

<p class="user-info">
    Gestion des utilisateurs de l'interface d'administration.
</p>

{{if eq .Flash "success"}}
<div style="background:#f0fdf4;border:1px solid #bbf7d0;color:#16a34a;padding:0.75rem 1rem;border-radius:var(--pico-border-radius);margin-bottom:1rem;">
    {{.FlashMessage}}
</div>
{{end}}

{{if eq .Flash "error"}}
<div style="background:#fef2f2;border:1px solid #fecaca;color:#dc2626;padding:0.75rem 1rem;border-radius:var(--pico-border-radius);margin-bottom:1rem;">
    {{.FlashMessage}}
</div>
{{end}}

<article>
    <table class="users-table">
        <thead>
            <tr>
                <th>Utilisateur</th>
                <th>Email</th>
                <th>Rôle</th>
                <th>2FA</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {{range .Users}}
            <tr>
                <td><strong>{{.Username}}</strong></td>
                <td>{{.Email}}</td>
                <td><span class="badge badge-role">{{.Role}}</span></td>
                <td>
                    {{if .TwoFAEnabled}}
                    <span class="badge badge-success">Activé</span>
                    <small style="color:var(--pico-muted-color);">({{.BackupCount}} codes)</small>
                    {{else}}
                    <span class="badge badge-warning">Désactivé</span>
                    {{end}}
                </td>
                <td>
                    {{if .TwoFAEnabled}}
                    <form action="/admin/users/reset-2fa" method="post" style="display:inline;"
                          onsubmit="return confirm('Réinitialiser le 2FA pour {{.Username}} ?');">
                        <input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
                        <input type="hidden" name="username" value="{{.Username}}">
                        <button type="submit" class="btn-danger" style="padding:0.4rem 0.75rem;font-size:0.85rem;">
                            Reset 2FA
                        </button>
                    </form>
                    {{else}}
                    <span style="color:var(--pico-muted-color);font-size:0.85rem;">-</span>
                    {{end}}
                </td>
            </tr>
            {{end}}
        </tbody>
    </table>
</article>

{{template "partials/footer.html" .}}
{{end}}
