<?php
/**
 * Single News Article Page — Gmind Institute
 *
 * News article with image, date, branch badge, title, content,
 * and breadcrumb.
 *
 * Expected PHP variables:
 *   $newsItem     — single news record
 *   $csrfToken    — CSRF token string
 *   $currentPage  — string 'news'
 *   $title        — page title
 */

$newsItem = $newsItem ?? [];

$newsTitle   = $newsItem['title']        ?? 'News Not Found';
$newsImage   = $newsItem['image']        ?? '/images/news-default.jpg';
$newsDate    = $newsItem['published_at'] ?? $newsItem['created_at'] ?? '';
$newsContent = $newsItem['content']      ?? '';
$branchName  = $newsItem['branch_name']  ?? '';
?>

<?php include __DIR__ . '/../layouts/header.php'; ?>

<!-- ============================================================
     Breadcrumb
     ============================================================ -->
<nav class="breadcrumb-bar" aria-label="Breadcrumb">
    <div class="container">
        <ol class="breadcrumb-list">
            <li><a href="<?= url('/') ?>">Home</a></li>
            <li><a href="<?= url('/news') ?>">News</a></li>
            <li aria-current="page"><?= htmlspecialchars(mb_substr($newsTitle, 0, 50), ENT_QUOTES, 'UTF-8') ?><?= mb_strlen($newsTitle) > 50 ? '...' : '' ?></li>
        </ol>
    </div>
</nav>

<!-- ============================================================
     News Article Section
     ============================================================ -->
<section class="news-article-section section-white" aria-label="News article">
    <div class="container">
        <article class="news-article">
            <!-- Featured Image -->
            <div class="news-article-image">
                <img
                    src="<?= htmlspecialchars($newsImage, ENT_QUOTES, 'UTF-8') ?>"
                    alt="<?= htmlspecialchars($newsTitle, ENT_QUOTES, 'UTF-8') ?>"
                    loading="lazy"
                >
            </div>

            <!-- Article Header -->
            <header class="news-article-header">
                <div class="news-article-meta">
                    <span class="news-article-date">
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
                        <?= htmlspecialchars(date('F d, Y', strtotime($newsDate)), ENT_QUOTES, 'UTF-8') ?>
                    </span>
                    <?php if (!empty($branchName)): ?>
                    <span class="news-card-branch-badge">
                        <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/><circle cx="12" cy="10" r="3"/></svg>
                        <?= htmlspecialchars($branchName, ENT_QUOTES, 'UTF-8') ?>
                    </span>
                    <?php endif; ?>
                </div>
                <h1><?= htmlspecialchars($newsTitle, ENT_QUOTES, 'UTF-8') ?></h1>
            </header>

            <!-- Article Content -->
            <div class="news-article-content">
                <?= $newsContent // Content may contain HTML from admin ?>
            </div>
        </article>
    </div>
</section>

<?php include __DIR__ . '/../layouts/footer.php'; ?>
