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

<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-rotate me-2"></i><?= e(trans('revision_window')) ?></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 class="small mt-1">
      <?= e(trans('revision_open_until')) ?>: <b><?= e((string)($sub['revision_open_until'] ?? '-')) ?></b>
      <?php if ($is_open): ?>
        <span class="badge bg-success ms-2">OPEN</span>
      <?php else: ?>
        <span class="badge bg-danger ms-2">CLOSED</span>
      <?php endif; ?>
    </div>
  </div>
</div>

<div class="card shadow-sm border-0 mb-3">
  <div class="card-body">
    <?php if (!$is_open): ?>
      <div class="alert alert-warning mb-0"><?= e(current_lang()==='ar' ? 'نافذة التعديل مغلقة.' : 'Revision window is closed.') ?></div>
    <?php else: ?>
      <form method="post" action="<?= e(base_path('author/submission/revision/submit')) ?>" enctype="multipart/form-data" class="row g-3">
        <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
        <input type="hidden" name="submission_id" value="<?= e((string)$sub['id']) ?>">

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

        <div class="col-md-6">
          <label class="form-label"><?= e(trans('response_letter')) ?></label>
          <input type="file" name="response_letter" class="form-control">
        </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>
    <?php endif; ?>
  </div>
</div>

<div class="card shadow-sm border-0">
  <div class="card-body">
    <div class="fw-bold mb-2"><?= e(trans('submission_files')) ?></div>
    <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'; ?>
