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

<div class="container py-3">
  <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
    <h4 class="mb-0"><i class="fa-solid fa-list-check"></i> <?= e($t('توزيعات التحكيم','Review Assignments')) ?></h4>

    <form class="d-flex gap-2" method="get">
      <input class="form-control" name="q" value="<?= e((string)$q) ?>" placeholder="<?= e($t('بحث بالرقم (assignment/submission/reviewer)','Search by id (assignment/submission/reviewer)')) ?>">
      <button class="btn btn-primary"><i class="fa-solid fa-magnifying-glass"></i> <?= e($t('بحث','Search')) ?></button>
    </form>
  </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('Submission','Submission')) ?></th>
            <th><?= e($t('Reviewer','Reviewer')) ?></th>
            <th><?= e($t('Status','Status')) ?></th>
            <th><?= e($t('Round','Round')) ?></th>
            <th><?= e($t('Rating','Rating')) ?></th>
            <th><?= e($t('Notes','Notes')) ?></th>
            <th><?= e($t('Action','Action')) ?></th>
          </tr>
        </thead>
        <tbody>
          <?php foreach($rows as $r): ?>
            <tr>
              <td class="text-muted"><?= e((string)$r['assignment_id']) ?></td>
              <td><?= e((string)$r['submission_id']) ?></td>
              <td>
                <div class="fw-bold"><?= e((string)($r['reviewer_name']??'')) ?></div>
                <div class="text-muted small"><?= e((string)($r['reviewer_email']??'')) ?></div>
              </td>
              <td><span class="badge bg-secondary"><?= e((string)($r['status']??'')) ?></span></td>
              <td><?= e((string)($r['round_no']??'')) ?></td>

              <td style="min-width:140px;">
                <form method="post" action="<?= e(base_path('admin/review-assignments/rate')) ?>" class="d-flex gap-2 align-items-center">
                  <input type="hidden" name="review_assignment_id" value="<?= e((string)$r['assignment_id']) ?>">
                  <input type="hidden" name="reviewer_id" value="<?= e((string)$r['reviewer_id']) ?>">
                  <input class="form-control form-control-sm" type="number" step="0.1" min="0" max="5"
                         name="rating_score" value="<?= e((string)($r['rating_score']??'0.0')) ?>">
              </td>

              <td style="min-width:240px;">
                  <input class="form-control form-control-sm" name="rating_notes" value="<?= e((string)($r['rating_notes']??'')) ?>" placeholder="<?= e($t('ملاحظة قصيرة','Short note')) ?>">
              </td>

              <td>
                  <button class="btn btn-sm btn-success">
                    <i class="fa-solid fa-floppy-disk"></i> <?= e($t('حفظ','Save')) ?>
                  </button>
                </form>
              </td>
            </tr>
          <?php endforeach; ?>
          <?php if(empty($rows)): ?><tr><td colspan="8" class="text-center text-muted py-4">—</td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

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