<?php require __DIR__ . '/../layouts/header.php'; $lang=current_lang(); ?>
<div class="container">
  <div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-2">
    <h4 class="mb-0"><i class="fa-solid fa-pen-nib me-2"></i><?= e($lang==='ar'?'لوحة المؤلف':'Author Board') ?></h4>
    <a class="btn btn-primary btn-rounded" href="<?= e(base_path('submit')) ?>"><i class="fa-solid fa-plus me-2"></i><?= e($lang==='ar'?'تقديم بحث جديد':'New Submission') ?></a>
  </div>

  <div class="card shadow-sm border-0">
    <div class="card-body">
      <div class="table-responsive">
        <table class="table align-middle">
          <thead>
            <tr>
              <th>#</th>
              <th><?= e($lang==='ar'?'العنوان':'Title') ?></th>
              <th><?= e($lang==='ar'?'المؤتمر':'Conference') ?></th>
              <th><?= e($lang==='ar'?'الحالة':'Status') ?></th>
              <th><?= e($lang==='ar'?'تاريخ':'Created') ?></th>
              <th><?= e($lang==='ar'?'رفع ملف':'Upload') ?></th>
              <th><?= e($lang==='ar'?'الملفات':'Files') ?></th>
            </tr>
          </thead>
          <tbody>
          <?php foreach (($rows ?? []) as $r): ?>
            <?php
              $sid = (int)$r['id'];
              $title = (string)($lang==='ar' ? ($r['title_ar'] ?? $r['title_en'] ?? '') : ($r['title_en'] ?? $r['title_ar'] ?? ''));
              $conf  = (string)($lang==='ar' ? ($r['conf_title_ar'] ?? '') : ($r['conf_title_en'] ?? ''));
              $files = $filesMap[$sid] ?? [];
            ?>
            <tr>
              <td><?= e((string)$sid) ?></td>
              <td class="fw-bold"><?= e($title) ?></td>
              <td><?= e($conf) ?></td>
              <td><span class="badge bg-secondary"><?= e((string)($r['status'] ?? '')) ?></span></td>
              <td class="text-muted"><?= e((string)($r['created_at'] ?? '')) ?></td>

              <td>
                
              </td>

              <td>
                <?php if (!empty($files)): ?>
                  <div class="small">
                    <?php foreach ($files as $f): ?>
                      <div class="mb-1">
                        <span class="badge bg-light text-dark"><?= e((string)$f['file_category']) ?></span>
                        <a href="<?= e(base_path((string)$f['file_path'])) ?>" target="_blank"><?= e((string)($f['original_name'] ?? 'file')) ?></a>
                      </div>
                    <?php endforeach; ?>
                  </div>
                <?php else: ?>
                  <span class="text-muted small"><?= e($lang==='ar'?'لا يوجد ملفات':'No files') ?></span>
                <?php endif; ?>
              </td>
            </tr>
          <?php endforeach; ?>

          <?php if (empty($rows)): ?>
            <tr><td colspan="7" class="text-center text-muted py-4"><?= e($lang==='ar'?'لا يوجد تقديمات بعد.':'No submissions yet.') ?></td></tr>
          <?php endif; ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<?php require __DIR__ . '/../layouts/footer.php'; ?>
