<?php include __DIR__ . '/../includes/header.php'; require_admin(); ?>
<div class="table-wrap">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h4>Usuarios</h4>
    <a class="btn btn-primary" href="<?= e(base_url('users/create.php')) ?>">Nuevo usuario</a>
  </div>
  <table class="table table-bordered table-hover">
    <thead><tr><th>Nombre</th><th>Correo</th><th>Rol</th><th>Estado</th><th width="140">Acciones</th></tr></thead>
    <tbody>
      <?php foreach (db()->query("SELECT * FROM users ORDER BY id DESC") as $row): ?>
      <tr>
        <td><?= e($row['full_name']) ?></td>
        <td><?= e($row['email']) ?></td>
        <td><?= e($row['role']) ?></td>
        <td><?= e($row['status']) ?></td>
        <td>
          <a class="btn btn-sm btn-warning" href="<?= e(base_url('users/edit.php?id=' . $row['id'])) ?>">Editar</a>
          <a class="btn btn-sm btn-danger" href="<?= e(base_url('users/delete.php?id=' . $row['id'])) ?>" onclick="return confirm('¿Eliminar usuario?')">Eliminar</a>
        </td>
      </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
