<?php
/**
 * IBVTE Portal - Notification / Blog Detail
 */
require_once __DIR__ . '/includes/db_config.php';

$id = intval($_GET['id'] ?? 0);

try {
    $stmt = $pdo->prepare("SELECT * FROM notifications WHERE id = ? AND status = 'active'");
    $stmt->execute([$id]);
    $notif = $stmt->fetch();
} catch (Exception $e) {
    $notif = null;
}

if (!$notif) {
    die("Notification not found or has been removed.");
}
$pageTitle = htmlspecialchars($notif['title']) . ' | IBVTE Notification';
$pageDesc  = htmlspecialchars(mb_strimwidth(strip_tags($notif['content']), 0, 160, "..."));
include 'includes/header.php';
?>
<section class="py-5 bg-light min-vh-100">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8">
                <div class="bg-white p-5 rounded-4 shadow-sm border-top border-primary border-4">
                    <a href="index.php" class="btn btn-sm btn-outline-secondary mb-4"><i class="fas fa-arrow-left me-1"></i> Back to Home</a>
                    
                    <h1 class="fw-bold text-primary mb-3"><?= htmlspecialchars($notif['title']) ?></h1>
                    
                    <div class="d-flex align-items-center text-muted small mb-4 pb-3 border-bottom">
                        <span class="me-3"><i class="far fa-calendar-alt me-1"></i> <?= date('F d, Y', strtotime($notif['created_at'])) ?></span>
                        <span><i class="fas fa-user-circle me-1"></i> IBVTE Admin</span>
                    </div>

                    <?php if ($notif['image_path']): ?>
                        <div class="mb-4 rounded overflow-hidden shadow-sm">
                            <img src="<?= htmlspecialchars($notif['image_path']) ?>" class="img-fluid w-100" alt="Notification Image" style="max-height: 400px; object-fit: cover;">
                        </div>
                    <?php endif; ?>

                    <div class="notification-content fs-5" style="line-height: 1.8;">
                        <?= nl2br(htmlspecialchars($notif['content'])) ?>
                    </div>
                    
                    <?php if ($notif['pdf_path']): ?>
                        <div class="mt-5 p-4 bg-light rounded border border-danger">
                            <div class="d-flex align-items-center">
                                <i class="fas fa-file-pdf fa-3x text-danger me-3"></i>
                                <div>
                                    <h5 class="fw-bold mb-1">Attached Document</h5>
                                    <a href="<?= htmlspecialchars($notif['pdf_path']) ?>" target="_blank" class="btn btn-danger mt-2"><i class="fas fa-download me-1"></i> View / Download PDF</a>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</section>
<?php include 'includes/footer.php'; ?>
