<?php

require_once "../config/koneksi.php";

include "../includes/header.php";
include "../includes/navbar.php";

if (!isset($_GET['id'])) {
    header("Location: kegiatan.php");
    exit;
}

$id = (int) $_GET['id'];

$query = mysqli_query(
    $koneksi,
    "SELECT * FROM kegiatan WHERE id='$id'"
);

if (mysqli_num_rows($query) == 0) {
    echo "<div class='container py-5'><div class='alert alert-danger'>Data kegiatan tidak ditemukan.</div></div>";
    include "../includes/footer.php";
    exit;
}

$data = mysqli_fetch_assoc($query);

?>

<div class="container py-5">

    <div class="card shadow">

        <?php if (!empty($data['gambar'])) { ?>

            <img
                src="../uploads/kegiatan/<?= htmlspecialchars($data['gambar']); ?>"
                class="card-img-top"
                style="max-height:500px; object-fit:cover;"
                alt="<?= htmlspecialchars($data['judul']); ?>">

        <?php } ?>

        <div class="card-body p-4">

            <h2>

                <?= htmlspecialchars($data['judul']); ?>

            </h2>

            <p class="text-muted">

                <?= date('d F Y', strtotime($data['tanggal'])); ?>

            </p>

            <hr>

            <p style="text-align:justify; line-height:1.8;">

                <?= nl2br(htmlspecialchars($data['deskripsi'])); ?>

            </p>

            <a href="kegiatan.php" class="btn btn-primary mt-3">

                ← Kembali ke Kegiatan

            </a>

        </div>

    </div>

</div>

<?php

include "../includes/footer.php";

?>