<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<?php $t=fn($ar,$en)=>($lang==='ar'?$ar:$en); $rows=$rows??[]; ?>

<div class="container py-3">
  <h4 class="mb-3"><i class="fa-solid fa-shield-halved"></i> <?= e($t('إدارة صلاحيات المؤسسة','Organization RBAC')) ?></h4>

  <div class="card border-0 shadow-sm">
    <div class="table-responsive">
      <table class="table table-hover mb-0">
        <thead class="table-light">
          <tr>
            <th>#</th>
            <th><?= e($t('المستخدم','User')) ?></th>
            <th><?= e($t('الدور داخل المؤسسة','Org Role')) ?></th>
            <th><?= e($t('الحالة','Active')) ?></th>
            <th><?= e($t('تاريخ','Created')) ?></th>
          </tr>
        </thead>
        <tbody>
        <?php foreach($rows as $r): ?>
          <tr>
            <td class="text-muted"><?= e((string)$r['id']) ?></td>
            <td><?= e((string)$r['email']) ?> <span class="text-muted small">(#<?= e((string)$r['user_id']) ?>)</span></td>
            <td><span class="badge bg-secondary"><?= e((string)$r['role_code']) ?></span></td>
            <td><?= ((int)$r['is_active']===1) ? '<span class="badge bg-success">ON</span>' : '<span class="badge bg-danger">OFF</span>' ?></td>
            <td class="text-muted"><?= e((string)$r['created_at']) ?></td>
          </tr>
        <?php endforeach; ?>
        <?php if(empty($rows)): ?><tr><td colspan="5" class="text-center text-muted py-4">—</td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

<?php require __DIR__ . '/../../layouts/footer.php'; ?>
