<?php require __DIR__ . '/../../layouts/header.php'; $page_title = trans('review_rounds'); ?>

<h3 class="mb-3"><i class="fa-solid fa-layer-group me-2"></i><?= e(trans('review_rounds')) ?></h3>

<div class="card shadow-sm border-0 mb-3">
  <div class="card-body">
    <form method="get" class="row g-2">
      <div class="col-md-8">
        <label class="form-label"><?= e(trans('conference')) ?></label>
        <select name="conference_id" class="form-select" onchange="this.form.submit()">
          <?php foreach ($conferences as $c): ?>
            <option value="<?= e((string)$c['id']) ?>" <?= ((int)$conference_id===(int)$c['id'])?'selected':'' ?>>
              <?= e(current_lang()==='ar' ? (string)($c['title_ar']??'') : (string)($c['title_en']??'')) ?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-4 d-grid align-items-end">
        <a class="btn btn-outline-primary btn-rounded" href="<?= e(base_path('admin/review-assignments?conference_id='.(int)$conference_id)) ?>">
          <i class="fa-solid fa-user-check me-2"></i><?= e(trans('assign_reviewers')) ?>
        </a>
      </div>
    </form>
  </div>
</div>

<div class="card shadow-sm border-0">
  <div class="card-body">
    <form method="post" action="<?= e(base_path('admin/review-rounds/save')) ?>" class="row g-3">
      <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
      <input type="hidden" name="conference_id" value="<?= e((string)$conference_id) ?>">

      <div class="col-md-2">
        <label class="form-label"><?= e(trans('round_no')) ?></label>
        <input type="number" name="round_no" class="form-control" min="1" value="1" required>
      </div>
      <div class="col-md-5">
        <label class="form-label">Title EN</label>
        <input name="title_en" class="form-control" placeholder="Round 1">
      </div>
      <div class="col-md-5">
        <label class="form-label">Title AR</label>
        <input name="title_ar" class="form-control" placeholder="الجولة الأولى">
      </div>

      <div class="col-md-6">
        <label class="form-label"><?= e(trans('instructions')) ?> EN</label>
        <textarea name="instructions_en" class="form-control" rows="4"></textarea>
      </div>
      <div class="col-md-6">
        <label class="form-label"><?= e(trans('instructions')) ?> AR</label>
        <textarea name="instructions_ar" class="form-control" rows="4"></textarea>
      </div>

      <div class="col-md-3">
        <label class="form-label">Default Due Days</label>
        <input type="number" name="default_due_days" class="form-control" value="14">
      </div>

      <div class="col-md-3 d-flex align-items-end">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" name="is_active" checked>
          <label class="form-check-label"><?= e(trans('enabled')) ?></label>
        </div>
      </div>

      <div class="col-12">
        <button class="btn btn-success btn-rounded"><i class="fa-solid fa-check me-2"></i><?= e(trans('save')) ?></button>
      </div>
    </form>

    <hr>

    <div class="table-responsive">
      <table class="table table-hover align-middle mb-0">
        <thead><tr><th><?= e(trans('round_no')) ?></th><th>Title</th><th><?= e(trans('enabled')) ?></th></tr></thead>
        <tbody>
          <?php foreach ($rows as $r): ?>
            <tr>
              <td><?= e((string)$r['round_no']) ?></td>
              <td><?= e(current_lang()==='ar' ? (string)($r['title_ar']??'') : (string)($r['title_en']??'')) ?></td>
              <td><span class="badge <?= !empty($r['is_active'])?'bg-success':'bg-secondary' ?>"><?= !empty($r['is_active'])?'ON':'OFF' ?></span></td>
            </tr>
          <?php endforeach; ?>
          <?php if (empty($rows)): ?><tr><td colspan="3" class="text-center text-muted py-4"><?= e(trans('no_data')) ?></td></tr><?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

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