<?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">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h4 class="mb-0"><i class="fa-solid fa-user-check"></i> <?= e($t('محكّمو المؤسسة','Organization Reviewers')) ?></h4>
  </div>

  <div class="card border-0 shadow-sm mb-3">
    <div class="card-body">
      <form method="post" action="<?= e(base_path('admin/reviewers/add')) ?>" class="row g-2">
        <div class="col-md-8">
          <input class="form-control" name="email" placeholder="<?= e($t('أدخل بريد المستخدم لإضافته كمحكّم','Enter user email to add as reviewer')) ?>" required>
        </div>
        <div class="col-md-4 d-grid">
          <button class="btn btn-success"><i class="fa-solid fa-plus"></i> <?= e($t('إضافة','Add')) ?></button>
        </div>
      </form>
      <div class="text-muted small mt-2">
        <i class="fa-solid fa-circle-info"></i> <?= e($t('هذه القائمة معزولة حسب المؤسسة عبر org_users مثل منطق EasyChair.','This list is isolated per organization via org_users (EasyChair-style).')) ?>
      </div>
    </div>
  </div>

  <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('البريد','Email')) ?></th><th><?= e($t('الاسم','Name')) ?></th><th><?= e($t('إجراء','Action')) ?></th></tr>
        </thead>
        <tbody>
          <?php foreach($rows as $r): ?>
            <tr>
              <td class="text-muted"><?= e((string)$r['user_id']) ?></td>
              <td><?= e((string)$r['email']) ?></td>
              <td><?= e(trim((string)($r['first_name'].' '.$r['last_name']))) ?></td>
              <td>
                <a class="btn btn-sm btn-outline-danger" href="<?= e(base_path('admin/reviewers/remove?user_id='.(int)$r['user_id'])) ?>">
                  <i class="fa-solid fa-trash"></i> <?= e($t('إزالة','Remove')) ?>
                </a>
              </td>
            </tr>
          <?php endforeach; ?>
          <?php if(empty($rows)): ?><tr><td colspan="4" class="text-center text-muted py-4">—</td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

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