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

<h3 class="mb-3"><i class="fa-solid fa-users-gear me-2"></i><?= e(trans('bulk_assign')) ?></h3>

<?php if (!empty($round)): ?>
  <div class="alert alert-info">
    <div class="fw-bold mb-1"><?= e(trans('instructions')) ?>:</div>
    <div><?= nl2br(e(current_lang()==='ar' ? (string)($round['instructions_ar']??'') : (string)($round['instructions_en']??''))) ?></div>
  </div>
<?php endif; ?>

<div class="card shadow-sm border-0 mb-3">
  <div class="card-body">
    <form method="get" class="row g-2">
      <div class="col-md-6">
        <select name="conference_id" class="form-select">
          <?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-2"><input type="number" name="round_no" class="form-control" min="1" value="<?= e((string)$round_no) ?>"></div>
      <div class="col-md-2">
        <select name="status" class="form-select">
          <?php foreach (['submitted','under_review','revision','camera_ready'] as $st): ?>
            <option value="<?= e($st) ?>" <?= ($status===$st)?'selected':'' ?>><?= e($st) ?></option>
          <?php endforeach; ?>
        </select>
      </div>
      <div class="col-md-2 d-grid"><button class="btn btn-primary btn-rounded"><i class="fa-solid fa-filter me-2"></i><?= e(trans('search')) ?></button></div>
    </form>
  </div>
</div>

<?php /* AUTO_ASSIGN_PANEL_PACK39 */ ?>
<div class="card shadow-sm border-0 mb-3">
  <div class="card-body">
    <div class="d-flex justify-content-between align-items-center flex-wrap gap-2">
      <div>
        <div class="fw-bold"><i class="fa-solid fa-wand-magic-sparkles me-2"></i>Auto-Assign (Balanced Load)</div>
        <div class="small text-muted">Assign N reviewers per paper automatically (avoids duplicates, balances reviewer load).</div>
      </div>
      <form method="post" action="<?= e(base_path('admin/review-assignments/auto')) ?>" class="d-flex gap-2 align-items-end">
        <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
        <input type="hidden" name="conference_id" value="<?= e((string)$conference_id) ?>">
        <input type="hidden" name="round_no" value="<?= e((string)$round_no) ?>">
        <div>
          <label class="form-label small mb-1">Per Paper</label>
          <input type="number" name="per_paper" class="form-control" min="1" max="6" value="2" style="width:110px">
        </div>
        <button class="btn btn-success btn-rounded" type="submit">
          <i class="fa-solid fa-bolt me-2"></i>Run Auto-Assign
        </button>
      </form>
    </div>
  </div>
</div>

<form method="post" action="<?= e(base_path('admin/review-assignments/assign')) ?>">
  <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
  <input type="hidden" name="conference_id" value="<?= e((string)$conference_id) ?>">
  <input type="hidden" name="round_no" value="<?= e((string)$round_no) ?>">

  <div class="row g-3">
    <div class="col-lg-6">
      <div class="card shadow-sm border-0">
        <div class="card-body">
          <div class="fw-bold mb-2">Select submissions</div>
          <div style="max-height:420px;overflow:auto">
            <?php foreach ($submissions as $s): ?>
              <label class="d-flex gap-2 align-items-start border rounded-3 p-2 mb-2">
                <input type="checkbox" name="submission_ids[]" value="<?= e((string)$s['id']) ?>">
                <div>
                  <div class="fw-bold"><?= e((string)($s['submission_no']??'')) ?> — <?= e((string)($s['title']??'')) ?></div>
                  <div class="small text-muted"><?= e((string)($s['status']??'')) ?></div>
                </div>
              </label>
            <?php endforeach; ?>
            <?php if (empty($submissions)): ?><div class="text-muted"><?= e(trans('no_data')) ?></div><?php endif; ?>
          </div>
        </div>
      </div>
    </div>

    <div class="col-lg-6">
      <div class="card shadow-sm border-0 mb-3">
        <div class="card-body">
          <div class="fw-bold mb-2">Select reviewers</div>
          <div style="max-height:320px;overflow:auto">
            <?php foreach ($reviewers as $r): ?>
              <label class="d-flex gap-2 align-items-start border rounded-3 p-2 mb-2">
                <input type="checkbox" name="reviewer_ids[]" value="<?= e((string)$r['id']) ?>">
                <div>
                  <div class="fw-bold"><?= e(trim((string)$r['first_name'].' '.(string)$r['last_name'])) ?></div>
                  <div class="small text-muted"><?= e((string)$r['email']) ?></div>
                </div>
              </label>
            <?php endforeach; ?>
            <?php if (empty($reviewers)): ?><div class="text-muted"><?= e(trans('no_data')) ?></div><?php endif; ?>
          </div>

          <hr>
          <label class="form-label"><?= e(trans('due_date')) ?></label>
          <input type="datetime-local" name="due_date" class="form-control">

          <button class="btn btn-success btn-rounded w-100 mt-3">
            <i class="fa-solid fa-check me-2"></i><?= e(trans('assign_reviewers')) ?>
          </button>
        </div>
      </div>
    </div>
  </div>
</form>

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