
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php $view='admin/users.php'; ?>
<div class="d-flex justify-content-between align-items-center mb-2">
  <h4 class="mb-0">Users</h4>
  <a class="btn btn-primary" href="<?= e(base_url($config, '/index.php?r=admin/user_create')) ?>">Create User</a>
</div>

<div class="card shadow-sm">
  <div class="table-responsive">
    <table class="table table-striped mb-0 align-middle">
      <thead>
        <tr>
          <th>#</th><th>Name</th><th>Email</th><th>Mobile</th><th>Role</th><th>Branch</th><th>Status</th><th style="width:220px;">Actions</th>
        </tr>
      </thead>
      <tbody>
      <?php foreach ($rows as $r): ?>
        <tr>
          <td><?= (int)$r['id'] ?></td>
          <td><?= e($r['name']) ?></td>
          <td><?= e($r['email']) ?></td>
          <td><?= e($r['mobile']) ?></td>
          <td><?= e($r['role_code']) ?></td>
          <td><?= e(is_rtl() ? ($r['branch_name_ar'] ?? '-') : ($r['branch_name_en'] ?? '-')) ?></td>
          <td><?= (int)$r['is_active']===1 ? 'Active' : 'Inactive' ?></td>
          <td class="d-flex gap-2">
            <a class="btn btn-sm btn-outline-primary" href="<?= e(base_url($config, '/index.php?r=admin/user_edit&id='.(int)$r['id'])) ?>">Edit</a>
            <form method="post" action="<?= e(base_url($config, '/index.php?r=admin/user_reset_password')) ?>" class="d-flex gap-1">
              <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
              <input type="hidden" name="id" value="<?= (int)$r['id'] ?>">
              <input class="form-control form-control-sm" name="new_password" placeholder="New password" style="max-width:120px;">
              <button class="btn btn-sm btn-outline-danger">Reset</button>
            </form>
          </td>
        </tr>
      <?php endforeach; ?>
      </tbody>
    </table>
  </div>
</div>
