<?php

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

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

?>
<style>
    .btn-primary {
        background-color: #07357e !important;
        border-color: #07357e !important;
    }
</style>
<div style="padding-top:120px;">
    <div class="container py-5">

        <div class="text-center mb-5">

            <h1 class="section-title">
                Galeri
            </h1>

            <p class="text-muted">
                Dokumentasi kegiatan Dinas Perpustakaan dan Kearsipan
                Kabupaten Banyuwangi.
            </p>

        </div>

        <div class="row g-4">

            <?php

            $query = mysqli_query(
                $koneksi,
                "SELECT * FROM galeri ORDER BY id DESC"
            );

            if (mysqli_num_rows($query) > 0) {

                while ($data = mysqli_fetch_assoc($query)) {

            ?>

                    <div class="col-lg-4 col-md-6">

                        <div class="card shadow-sm h-100">

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

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

                            <?php } ?>

                            <div class="card-body">

                                <h5 class="card-title">

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

                                </h5>

                                <p class="card-text">

                                    <?= !empty($data['deskripsi']) ? htmlspecialchars($data['deskripsi']) : 'Dokumentasi kegiatan DISPUSIP Kabupaten Banyuwangi.'; ?>

                                </p>

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

                                    <a
                                        href="<?= htmlspecialchars($data['link']); ?>"
                                        target="_blank"
                                        class="btn btn-primary">

                                        Lihat di Instagram

                                    </a>

                                <?php } ?>

                            </div>

                        </div>

                    </div>

                <?php

                }
            } else {

                ?>

                <div class="col-12">

                    <div class="alert alert-info text-center">

                        Belum ada foto galeri.

                    </div>

                </div>

            <?php

            }

            ?>

        </div>

    </div>

    <?php

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

    ?>