<?php require BASE_PATH . '/app/Views/layouts/header.php'; ?>

<section class="page-hero">
  <div class="container">
    <span class="eyebrow">Berita</span>
    <h1>Kabar &amp; Informasi Fakultas</h1>
  </div>
</section>

<section class="berita-page">
  <div class="container">
    <?php if (empty($daftarBerita)): ?>
      <p style="color:var(--text-muted); text-align:center; padding:40px 0;">Belum ada berita yang dipublikasikan.</p>
    <?php else: ?>
      <div class="berita-grid">
        <?php foreach ($daftarBerita as $item): ?>
          <a href="<?= APP_URL ?>/berita/<?= htmlspecialchars($item['slug']) ?>" class="news-card">
            <div class="news-card-thumb">
              <?php if (!empty($item['thumbnail'])): ?>
                <img src="<?= APP_URL . '/uploads/berita/' . htmlspecialchars($item['thumbnail']) ?>" alt="<?= htmlspecialchars($item['judul']) ?>">
              <?php else: ?>
                <div class="news-card-thumb-placeholder"></div>
              <?php endif; ?>
            </div>
            <div class="news-card-body">
              <span class="tag"><?= htmlspecialchars($item['kategori'] ?? 'Berita') ?> &middot; <?= date('d M Y', strtotime($item['tanggal'])) ?></span>
              <h3><?= htmlspecialchars($item['judul']) ?></h3>
              <span class="read-more">Baca Selengkapnya</span>
            </div>
          </a>
        <?php endforeach; ?>
      </div>

      <?php if ($totalPage > 1): ?>
        <div class="pagination">
          <?php if ($page > 1): ?>
            <a href="<?= APP_URL ?>/berita?page=<?= $page - 1 ?>">&laquo;</a>
          <?php endif; ?>

          <?php for ($p = 1; $p <= $totalPage; $p++): ?>
            <?php if ($p === $page): ?>
              <span class="current"><?= $p ?></span>
            <?php else: ?>
              <a href="<?= APP_URL ?>/berita?page=<?= $p ?>"><?= $p ?></a>
            <?php endif; ?>
          <?php endfor; ?>

          <?php if ($page < $totalPage): ?>
            <a href="<?= APP_URL ?>/berita?page=<?= $page + 1 ?>">&raquo;</a>
          <?php endif; ?>
        </div>
      <?php endif; ?>
    <?php endif; ?>
  </div>
</section>

<?php require BASE_PATH . '/app/Views/layouts/footer.php'; ?>
