<?php require __DIR__ . '/../../layouts/header.php'; $lang=current_lang(); ?>
<?php $t=fn($ar,$en)=>($lang==='ar'?$ar:$en); ?>
<?php $rows=$rows??[]; $titleEn=$titleEn??null; $titleAr=$titleAr??null; $stCol=$stCol??null; $authorCol=$authorCol??null; ?>

<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-pen-nib"></i> <?= e($t('لوحة المؤلف','Author Dashboard')) ?></h4>
    <div class="d-flex gap-2">
      <a class="btn btn-outline-primary" href="<?= e(base_path('author/submit')) ?>"><i class="fa-solid fa-paper-plane"></i> <?= e($t('تقديم بحث','Submit')) ?></a>
      <a class="btn btn-outline-secondary" href="<?= e(base_path('whoami.php')) ?>"><i class="fa-solid fa-id-badge"></i> <?= e($t('فحص الجلسة','Session')) ?></a>
      <a class="btn btn-outline-danger" href="<?= e(base_path('logout.php')) ?>"><i class="fa-solid fa-right-from-bracket"></i> <?= e($t('خروج','Logout')) ?></a>
    </div>
  </div>

  <div class="card border-0 shadow-sm mb-3">
    <div class="card-body">
      <div class="text-muted">
        <?= e($t('هذه لوحة مؤلف مستقرة. سيتم إعادة ربط تفاصيل المراجعات/النسخ والـ timeline بشكل كامل في الحزم القادمة.',
                 'This is a stable author dashboard. Full review timeline and file/version details will be reconnected in upcoming packs.')) ?>
      </div>
      <?php if(!$authorCol): ?>
        <div class="alert alert-warning mt-3 mb-0">
          <?= e($t('لم يتم العثور على عمود المؤلف داخل جدول submissions (author_id/user_id/created_by).',
                   'Author column not found in submissions (author_id/user_id/created_by).')) ?>
        </div>
      <?php endif; ?>
    </div>
  </div>

  <div class="card border-0 shadow-sm">
    <div class="card-header bg-white">
      <div class="fw-bold"><i class="fa-solid fa-file-lines"></i> <?= e($t('أبحاثي','My Submissions')) ?></div>
    </div>
    <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:140px"><?= e($t('فتح','Open')) ?></th>
            </tr>
          </thead>
          <tbody>
            <?php foreach($rows as $r): ?>
              <?php
                $id=(int)($r['id']??0);
                $title='';
                if($lang==='ar' && $titleAr) $title=(string)($r[$titleAr]??'');
                if($title==='' && $titleEn) $title=(string)($r[$titleEn]??'');
                if($title==='') $title='—';
                $st=$stCol?(string)($r[$stCol]??''):'';
              ?>
              <tr>
                <td class="text-muted"><?= e((string)$id) ?></td>
                <td><?= e($title) ?></td>
                <td><span class="badge bg-secondary"><?= e($st) ?></span></td>
                <td>
                  <a class="btn btn-sm btn-outline-primary" href="<?= e(base_path('author/submissions/view?id='.$id)) ?>">
                    <i class="fa-solid fa-eye"></i> <?= e($t('عرض','View')) ?>
                  </a>
                </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'; ?>
