<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<?php $t=fn($ar,$en)=>($lang==='ar'?$ar:$en); ?>
<div class="container py-3">

  <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
    <h4 class="mb-0"><i class="fa-solid fa-file-lines"></i> <?= e($t('الأبحاث المقدمة','Submissions')) ?></h4>
    <a class="btn btn-outline-secondary" href="<?= e(base_path('dashboard')) ?>"><i class="fa-solid fa-gauge"></i> <?= e($t('لوحة التحكم','Dashboard')) ?></a>
  </div>

  <div class="card border-0 shadow-sm mb-3">
    <div class="card-body">
      <form class="row g-2" method="get">
        <div class="col-md-6">
          <input class="form-control" name="q" value="<?= e((string)($q??'')) ?>" placeholder="<?= e($t('بحث بالعنوان...','Search by title...')) ?>">
        </div>
        <div class="col-md-4">
          <select class="form-select" name="status">
            <option value=""><?= e($t('كل الحالات','All statuses')) ?></option>
            <?php foreach(($statuses??[]) as $s): ?>
              <option value="<?= e($s) ?>" <?= ($status??'')===$s?'selected':'' ?>><?= e($s) ?></option>
            <?php endforeach; ?>
          </select>
        </div>
        <div class="col-md-2 d-grid">
          <button class="btn btn-primary"><i class="fa-solid fa-filter"></i> <?= e($t('تصفية','Filter')) ?></button>
        </div>
      </form>
    </div>
  </div>

  <div class="card border-0 shadow-sm">
    <div class="card-body p-0">
      <div class="table-responsive">
        <table class="table table-hover mb-0">
          <thead class="table-light">
            <tr>
              <th style="width:90px">#</th>
              <th><?= e($t('العنوان','Title')) ?></th>
              <th style="width:160px"><?= e($t('الحالة','Status')) ?></th>
              <th style="width:200px"><?= e($t('التاريخ','Date')) ?></th>
            </tr>
          </thead>
          <tbody>
            <?php foreach(($rows??[]) as $r): ?>
              <?php
                $id = (int)($r['id'] ?? 0);
                $title = '';
                if (!empty($titleAr) && $lang==='ar') $title = (string)($r[$titleAr] ?? '');
                if ($title==='' && !empty($titleEn)) $title = (string)($r[$titleEn] ?? '');
                if ($title==='') $title = '—';
                $st = $stCol ? (string)($r[$stCol] ?? '') : '';
                $dt = (string)($r['created_at'] ?? $r['id'] ?? '');
              ?>
              <tr>
                <td class="text-muted"><?= e((string)$id) ?></td>
                <td><?= e($title) ?></td>
                <td><span class="badge bg-secondary"><?= e($st) ?></span></td>
                <td class="text-muted"><?= e($dt) ?></td>
              </tr>
            <?php endforeach; ?>
            <?php if(empty($rows)): ?>
              <tr><td colspan="4" class="text-center text-muted py-4">—</td></tr>
            <?php endif; ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>

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