<?php include dirname(__DIR__) . '/header.php'; ?>


<section class="py-5 bg-light">
    <div class="container">
        <div class="row mb-5">
            <div class="col-lg-6 mx-auto text-center">
                <h1 class="display-4 fw-bold mb-3">Blog & Articles</h1>
                <p class="lead text-muted">Dapatkan informasi terbaru seputar aplikasi, game, dan tips teknologi di sini.</p>
            </div>
        </div>

        <div class="row g-4">
            <?php foreach ($blogPosts as $item): ?>
            <div class="col-md-6 col-lg-4">
                <article class="card h-100 border-0 shadow-sm overflow-hidden hover-lift transition-all">
                    <?php if ($item['image_path']): ?>
                        <img src="/<?php echo $item['image_path']; ?>" class="card-img-top" alt="<?php echo htmlspecialchars($item['title']); ?>" style="height: 200px; object-fit: cover;">
                    <?php else: ?>
                        <div class="bg-primary bg-opacity-10 d-flex align-items-center justify-content-center" style="height: 200px;">
                            <i class="fas fa-newspaper fa-3x text-primary opacity-25"></i>
                        </div>
                    <?php endif; ?>
                    <div class="card-body p-4">
                        <div class="text-muted small mb-2">
                            <i class="far fa-calendar-alt me-1"></i> <?php echo date('M d, Y', strtotime($item['created_at'])); ?>
                        </div>
                        <h2 class="h5 card-title fw-bold mb-3">
                            <a href="/blog/<?php echo $item['slug']; ?>" class="text-dark text-decoration-none stretched-link">
                                <?php echo htmlspecialchars($item['title']); ?>
                            </a>
                        </h2>
                        <p class="card-text text-muted mb-0">
                            <?php 
                                $excerpt = strip_tags($item['content']);
                                echo strlen($excerpt) > 120 ? substr($excerpt, 0, 120) . '...' : $excerpt; 
                            ?>
                        </p>
                    </div>
                </article>
            </div>
            <?php endforeach; ?>

            <?php if (empty($blogPosts)): ?>
            <div class="col-12 text-center py-5">
                <div class="mb-3">
                    <i class="fas fa-folder-open fa-3x text-muted opacity-25"></i>
                </div>
                <h3 class="text-muted">Belum ada artikel yang diterbitkan.</h3>
                <a href="/" class="btn btn-primary mt-3">Kembali ke Beranda</a>
            </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<?php include dirname(__DIR__) . '/footer.php'; ?>