<?php require __DIR__ . '/../layouts/header.php'; $lang=current_lang(); ?>
<div class="container">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h4 class="mb-0"><i class="fa-solid fa-bell me-2"></i><?= e($lang==='ar'?'الإشعارات':'Notifications') ?></h4>
    <form method="post" action="<?= e(base_path('author/notifications/read-all')) ?>">
      <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
      <button class="btn btn-outline-secondary btn-rounded"><?= e($lang==='ar'?'تحديد الكل كمقروء':'Mark all read') ?></button>
    </form>
  </div>

  <div class="card border-0 shadow-sm">
    <div class="card-body">
      <?php foreach(($rows??[]) as $n): ?>
        <div class="p-3 rounded-4 border mb-2 <?= ((int)$n['is_read']===0?'bg-light':'') ?>">
          <div class="d-flex justify-content-between gap-2">
            <div>
              <div class="fw-bold"><?= e((string)($n['title']??'')) ?></div>
              <div class="text-muted"><?= e((string)($n['body']??'')) ?></div>
              <div class="text-muted small"><?= e((string)($n['created_at']??'')) ?></div>
            </div>
            <?php if((int)$n['is_read']===0): ?>
              <form method="post" action="<?= e(base_path('author/notifications/read')) ?>">
                <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                <input type="hidden" name="id" value="<?= e((string)$n['id']) ?>">
                <button class="btn btn-sm btn-primary"><?= e($lang==='ar'?'تم':'Read') ?></button>
              </form>
            <?php endif; ?>
          </div>
        </div>
      <?php endforeach; ?>
      <?php if(empty($rows)): ?><div class="text-center text-muted py-4">—</div><?php endif; ?>
    </div>
  </div>
</div>
<?php require __DIR__ . '/../layouts/footer.php'; ?>
