<?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-user-pen"></i> <?= e($t('محررو المؤسسة','Organization Editors')) ?></h4>

  <div class="card border-0 shadow-sm mb-3">
    <div class="card-body">
      <form method="post" action="<?= e(base_path('admin/editors/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 editor')) ?>" 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>
  </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/editors/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'; ?>
