<?php
require_once __DIR__ . '/admin/inc/config.php';
require_once __DIR__ . '/data/site.php';
require_once __DIR__ . '/data/contact.php';

$statement = $pdo->prepare("
    SELECT id, caption, photo
    FROM tbl_photo
    ORDER BY id DESC
");
$statement->execute();

$photos = $statement->fetchAll(PDO::FETCH_ASSOC);
?>

<?php require_once __DIR__ . '/includes/header.php'; ?>

<style>
.gallery-section {
    width: 100%;
    padding: 80px 0;
    background: #fff;
    overflow: hidden;
    position: relative;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 28px;
}

.gallery-card {
    position: relative;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    transition: transform .4s ease, box-shadow .4s ease;
}

.gallery-card:hover {
    transform: translateY(-7px);
    box-shadow: 0 18px 40px rgba(0,0,0,.12);
}

.gallery-image {
    width: 100%;
    height: 300px;
    overflow: hidden;
    background: #f3f3f3;
}

.gallery-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .6s ease;
}

.gallery-card:hover .gallery-image img {
    transform: scale(1.06);
}

.gallery-caption {
    padding: 20px 22px;
    background: #fff;
}

.gallery-caption h3 {
    margin: 0;
    color: #171717;
    font-size: 20px;
    line-height: 1.4;
    font-weight: 700;
}

.gallery-empty {
    padding: 60px 20px;
    text-align: center;
    background: #f7f7f7;
    border-radius: 10px;
}

.gallery-empty h3 {
    margin: 0 0 10px;
    font-size: 26px;
}

.gallery-empty p {
    margin: 0;
    color: #666;
}

@media (max-width: 991px) {
    .gallery-section {
        padding: 60px 0;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 22px;
    }

    .gallery-image {
        height: 260px;
    }
}

@media (max-width: 767px) {
    .gallery-section {
        padding: 45px 0;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .gallery-image {
        height: 250px;
    }

    .gallery-caption {
        padding: 18px;
    }

    .gallery-caption h3 {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .gallery-image {
        height: 220px;
    }
}
</style>

<section
    class="contact-hero"
    style="background-image:url('<?= htmlspecialchars($contact_page['banner_image'] ?? '', ENT_QUOTES, 'UTF-8') ?>');">

    <div class="contact-hero-overlay"></div>

    <div class="container-fluid px-lg-5">

        <div class="contact-hero-content">

            <span class="contact-hero-eyebrow">
                Our Work
            </span>

            <h1>Gallery</h1>

            <div class="contact-breadcrumb">

                <a href="index.php">Home</a>

                <i class="bi bi-chevron-right"></i>

                <strong>Gallery</strong>

            </div>

        </div>

    </div>

</section>

<section class="gallery-section">

    <div class="container-fluid px-lg-5">

        <!-- <div class="row mb-5">

            <div class="col-lg-8">

                <span class="contact-hero-eyebrow">
                    Our Gallery
                </span>

                <h2>
                    Manufacturing, Machinery &amp; Industrial Work
                </h2>

                <p>
                    Explore our manufacturing facilities, advanced machinery,
                    production processes and industrial work at MVSK Industries.
                </p>

            </div>

        </div> -->

        <?php if (!empty($photos)): ?>

            <div class="gallery-grid">

                <?php foreach ($photos as $photo): ?>

                    <?php
                    $photoFile = trim($photo['photo'] ?? '');

                    $imageUrl = rtrim($site['base_url'], '/') . '/assets/images/gallery/' . rawurlencode($photoFile);
                    ?>

                    <article class="gallery-card">

                        <div class="gallery-image">

                            <img
                                src="<?= htmlspecialchars($imageUrl, ENT_QUOTES, 'UTF-8') ?>"
                                alt="<?= htmlspecialchars($photo['caption'] ?? 'Gallery image', ENT_QUOTES, 'UTF-8') ?>"
                                loading="lazy">

                        </div>

                        <?php if (!empty($photo['caption'])): ?>

                            <div class="gallery-caption">

                                <h3>
                                    <?= htmlspecialchars(
                                        $photo['caption'],
                                        ENT_QUOTES,
                                        'UTF-8'
                                    ) ?>
                                </h3>

                            </div>

                        <?php endif; ?>

                    </article>

                <?php endforeach; ?>

            </div>

        <?php else: ?>

            <div class="gallery-empty">

                <h3>No Gallery Images Found</h3>

                <p>
                    There are currently no gallery images available.
                </p>

            </div>

        <?php endif; ?>

    </div>

</section>

<?php require_once __DIR__ . '/includes/footer.php'; ?>