<?php

include 'config/koneksi.php';

/*
==========================
AMBIL ID BERITA
==========================
*/

if (!isset($_GET['id'])) {
    die("ID berita tidak ditemukan.");
}

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


/*
==========================
AMBIL DATA BERITA
==========================
*/

$query = mysqli_query($conn, "
    SELECT *
    FROM berita
    WHERE id_berita = '$id'
");


if (mysqli_num_rows($query) == 0) {
    die("Berita tidak ditemukan.");
}

$data = mysqli_fetch_assoc($query);

?>

<!DOCTYPE html>
<html lang="id">

<head>

    <meta charset="UTF-8">

    <meta
        name="viewport"
        content="width=device-width, initial-scale=1.0">

    <title>
        <?= htmlspecialchars($data['judul']); ?>
        - Desa Oelomin
    </title>

    <link
        rel="stylesheet"
        href="assets/css/detail_berita.css">

    <link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=Playfair+Display:wght@600;700;800&display=swap"
          rel="stylesheet">

</head>

<body>


<div class="detail-container">

    <!-- ==========================
         ARTIKEL
    =========================== -->

    <article class="detail-berita">


        <!-- KATEGORI -->

        <span class="kategori">

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

        </span>


        <!-- JUDUL -->

        <h1>

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

        </h1>


        <!-- TANGGAL -->

        <div class="detail-tanggal">


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

        </div>


        <!-- ==========================
            FOTO BERITA
        ========================== -->

            <div class="detail-gambar">

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

                    <img
                        src="assets/img/berita/<?= htmlspecialchars($data['gambar']); ?>"
                    >

                <?php } else { ?>

                    <div class="no-image">

                        📰

                        <span>
                            Foto belum tersedia
                        </span>

                    </div>

                <?php } ?>

            </div>

        <!-- ISI BERITA -->

        <div class="detail-isi">

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

        </div>

        <!-- ==========================
         TOMBOL KEMBALI
        =========================== -->

        <a
            href="berita.php"
            class="btn-kembali">

            ← Kembali ke Berita

        </a>


    </article>


</div>

</body>

</html>