{% extends "base.html" %}
{% block title %}Journal d'audit — GMAO{% endblock %}
{% block content %}
<div class="container-fluid">
  <h1 class="h3 mb-3"><i class="bi bi-journal-lock"></i> Journal d'audit</h1>
  <p class="text-muted">Écritures HTTP réussies ou refusées. Les mots de passe, jetons, clés et PIN sont masqués.</p>
  <div class="table-responsive"><table class="table table-sm table-hover align-middle">
    <thead><tr><th>Date</th><th>Utilisateur</th><th>Action</th><th>Route</th><th>Résultat</th><th>Données</th></tr></thead>
    <tbody>{% for log in logs.items %}<tr>
      <td class="text-nowrap">{{ log.created_at|datetime_fmt }}</td><td>{{ log.username }}</td>
      <td><span class="badge text-bg-secondary">{{ log.action }}</span></td><td><code>{{ log.path }}</code></td>
      <td><span class="badge {% if log.status_code < 400 %}text-bg-success{% else %}text-bg-warning{% endif %}">{{ log.status_code }}</span></td>
      <td class="small text-break" style="max-width:30rem">{{ log.payload or '—' }}</td>
    </tr>{% else %}<tr><td colspan="6" class="text-center text-muted">Aucune écriture enregistrée.</td></tr>{% endfor %}</tbody>
  </table></div>
  <nav><ul class="pagination">
    {% if logs.has_prev %}<li class="page-item"><a class="page-link" href="{{ url_for('admin.audit_logs', page=logs.prev_num) }}">Précédent</a></li>{% endif %}
    <li class="page-item disabled"><span class="page-link">Page {{ logs.page }} / {{ logs.pages or 1 }}</span></li>
    {% if logs.has_next %}<li class="page-item"><a class="page-link" href="{{ url_for('admin.audit_logs', page=logs.next_num) }}">Suivant</a></li>{% endif %}
  </ul></nav>
</div>
{% endblock %}
