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