<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<div class="container">
  <h4 class="mb-3"><i class="fa-solid fa-user-check me-2"></i><?= e($lang==='ar'?'توزيع المحكمين':'Reviewer Assignments') ?></h4>

  <div class="card border-0 shadow-sm mb-3"><div class="card-body">
    <form method="post" action="<?= e(base_path('admin/review-assignments/assign')) ?>" class="row g-2">
      <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
      <div class="col-md-5">
        <select class="form-select" name="submission_id" required>
          <option value=""><?= e($lang==='ar'?'اختر بحث':'Select submission') ?></option>
          <?php foreach(($submissions??[]) as $s): ?>
            <option value="<?= e((string)$s['id']) ?>">#<?= e((string)$s['id']) ?> — <?= e($lang==='ar'?(string)$s['title_ar']:(string)$s['title_en']) ?></option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-4">
        <select class="form-select" name="reviewer_id" required>
          <option value=""><?= e($lang==='ar'?'اختر محكم':'Select reviewer') ?></option>
          <?php foreach(($reviewers??[]) as $r): ?>
            <option value="<?= e((string)$r['id']) ?>">#<?= e((string)$r['id']) ?> — <?= e((string)$r['email']) ?></option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-1"><input class="form-control" type="number" min="1" name="round_no" value="1"></div>
      <div class="col-md-2 d-grid"><button class="btn btn-primary"><?= e($lang==='ar'?'توزيع':'Assign') ?></button></div>
    </form>
  </div></div>

  <div class="card border-0 shadow-sm"><div class="card-body">
    <div class="table-responsive">
      <table class="table align-middle">
        <thead><tr><th>#</th><th><?= e($lang==='ar'?'بحث':'Submission') ?></th><th>Email</th><th>round</th><th><?= e($lang==='ar'?'الحالة':'Status') ?></th></tr></thead>
        <tbody>
          <?php foreach(($assignments??[]) as $a): ?>
            <tr>
              <td><?= e((string)$a['id']) ?></td>
              <td><?= e($lang==='ar'?(string)$a['title_ar']:(string)$a['title_en']) ?></td>
              <td><?= e((string)$a['email']) ?></td>
              <td><?= e((string)($a['round_no']??1)) ?></td>
              <td><span class="badge bg-secondary"><?= e((string)$a['status']) ?></span></td>
            </tr>
          <?php endforeach; ?>
          <?php if(empty($assignments)): ?><tr><td colspan="5" class="text-center text-muted py-4">—</td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div></div>
</div>
<?php require __DIR__ . '/../../layouts/footer.php'; ?>
