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

<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
  <h3 class="mb-0"><i class="fa-solid fa-paperclip me-2"></i><?= e(trans('submission_files')) ?></h3>
  <a class="btn btn-outline-secondary btn-rounded" href="<?= e(base_path('author/dashboard')) ?>"><i class="fa-solid fa-arrow-left me-2"></i><?= e(trans('back')) ?></a>
</div>

<div class="card shadow-sm border-0 mb-3">
  <div class="card-body">
    <div class="fw-bold"><?= e((string)($sub['submission_no']??'')) ?> — <?= e((string)($sub['title']??'')) ?></div>
    <div class="small text-muted mt-1">Status: <?= e((string)($sub['status']??'')) ?></div>
  </div>
</div>

<div class="card shadow-sm border-0 mb-3">
  <div class="card-body">
    <form method="post" action="<?= e(base_path('author/submission/files/upload')) ?>" enctype="multipart/form-data" class="row g-2 align-items-end">
      <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
      <input type="hidden" name="submission_id" value="<?= e((string)$sub['id']) ?>">

      <div class="col-md-4">
        <label class="form-label"><?= e(trans('file_category')) ?></label>
        <select name="file_category" class="form-select">
          <?php foreach (['abstract','full_paper','receipt','supplement'] as $c): ?>
            <option value="<?= e($c) ?>"><?= e($c) ?></option>
          <?php endforeach; ?>
        </select>
      </div>

      <div class="col-md-6">
        <label class="form-label"><?= e(trans('upload_file')) ?></label>
        <input type="file" name="file" class="form-control" required>
      </div>

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

<div class="card shadow-sm border-0">
  <div class="card-body">
    <div class="table-responsive">
      <table class="table table-hover align-middle mb-0">
        <thead><tr><th><?= e(trans('file_category')) ?></th><th>File</th><th>Date</th></tr></thead>
        <tbody>
          <?php foreach ($files as $f): ?>
            <tr>
              <td><span class="badge bg-secondary"><?= e((string)$f['file_category']) ?></span></td>
              <td>
                <a href="<?= e(base_path('storage/'.$f['file_path'])) ?>" target="_blank">
                  <i class="fa-solid fa-download me-2"></i><?= e((string)($f['original_name'] ?? $f['file_path'])) ?>
                </a>
              </td>
              <td class="text-muted small"><?= e((string)($f['uploaded_at'] ?? '')) ?></td>
            </tr>
          <?php endforeach; ?>
          <?php if (empty($files)): ?><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'; ?>
