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

<div class="container-fluid py-3">
  <div class="d-flex align-items-center justify-content-between flex-wrap gap-2 mb-3">
    <h4 class="mb-0"><?= e(t('galley') ?? 'Galley') ?></h4>

    <div class="d-flex gap-2">
      <form method="get" action="<?= e(base_path('admin/galley')) ?>" class="d-flex gap-2">
        <select name="conference_id" class="form-select" onchange="this.form.submit()">
          <?php foreach(($confs??[]) as $c): ?>
            <option value="<?= (int)$c['id'] ?>" <?= ((int)$confId===(int)$c['id'])?'selected':'' ?>>
              <?= e(($c['title_ar']??'') ?: ($c['title_en']??('Conference #'.$c['id']))) ?>
            </option>
          <?php endforeach; ?>
        </select>
      </form>

      <a class="btn btn-outline-secondary" href="<?= e(base_path('admin/production?conference_id='.(int)$confId)) ?>">
        <i class="fa fa-arrow-left"></i> <?= e(t('back') ?? 'Back') ?>
      </a>
    </div>
  </div>

  <div class="card shadow-sm border-0 mb-3">
    <div class="card-body">
      <?php if(!$filesExist): ?>
        <div class="alert alert-warning mb-0">submission_files table not found.</div>
      <?php else: ?>
        <form method="post" action="<?= e(base_path('action/galley/upload')) ?>" enctype="multipart/form-data" class="row g-2">
          <div class="col-md-3">
            <label class="form-label"><?= e(t('submission_id') ?? 'Submission ID') ?></label>
            <input type="number" name="submission_id" class="form-control" required>
          </div>
          <div class="col-md-6">
            <label class="form-label"><?= e(t('file') ?? 'File') ?></label>
            <input type="file" name="file" class="form-control" required>
          </div>
          <div class="col-md-3 d-flex align-items-end">
            <button class="btn btn-primary w-100">
              <i class="fa fa-upload"></i> <?= e(t('upload') ?? 'Upload') ?>
            </button>
          </div>
        </form>
      <?php endif; ?>
    </div>
  </div>

  <div class="card shadow-sm border-0">
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-hover align-middle">
          <thead>
            <tr>
              <th>#</th>
              <th><?= e(t('submission_id') ?? 'Submission') ?></th>
              <th><?= e(t('path') ?? 'Path') ?></th>
            </tr>
          </thead>
          <tbody>
            <?php if(empty($files)): ?>
              <tr><td colspan="3" class="text-center text-muted py-4">—</td></tr>
            <?php else: foreach($files as $f): ?>
              <tr>
                <td><?= (int)$f['id'] ?></td>
                <td><?= (int)$f['submission_id'] ?></td>
                <td class="small text-muted"><?= e((string)($f['file_path'] ?? ($f['path'] ?? ''))) ?></td>
              </tr>
            <?php endforeach; endif; ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

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