<?php
$page_title = "Galeri Proyek Batu Alam";
$page_desc = "Lihat dokumentasi pengaplikasian batu alam andesit, travertine, marmer, dan produk PT Namora Nexa Niaga lainnya pada berbagai proyek arsitektur.";
require_once 'includes/header.php';

if (!isset($settings['menu_gallery_visible']) || $settings['menu_gallery_visible'] == 0) {
    header("Location: index.php");
    exit;
}

// Fetch all gallery items
try {
    $stmt = $pdo->prepare("SELECT * FROM gallery ORDER BY id DESC");
    $stmt->execute();
    $gallery = $stmt->fetchAll();
} catch (Exception $e) {
    $gallery = [];
}
?>

<!-- Page Header Banner -->
<section style="background: linear-gradient(rgba(15, 23, 42, 0.8), rgba(15, 23, 42, 0.8)), url('assets/images/hero_bg.jpg') no-repeat center center/cover; padding: 120px 0 60px; text-align: center; color: var(--text-light);">
    <div class="container">
        <h1 style="font-size: 42px; font-weight: 800; margin-bottom: 10px;">Galeri Proyek</h1>
        <p style="color: var(--primary); font-weight: 600; letter-spacing: 2px; text-transform: uppercase; font-size: 14px;">Inspirasi Keindahan & Pemasangan</p>
    </div>
</section>

<!-- Gallery Grid Section -->
<section class="bg-alt">
    <div class="container">
        <?php if (count($gallery) > 0): ?>
            <div class="gallery-grid">
                <?php foreach ($gallery as $item): ?>
                    <?php 
                    $img_src = '';
                    if (!empty($item['image']) && file_exists('uploads/' . $item['image'])) {
                        $img_src = 'uploads/' . $item['image'];
                    } elseif (!empty($item['image']) && file_exists('assets/images/' . $item['image'])) {
                        $img_src = 'assets/images/' . $item['image'];
                    } else {
                        // General construction / aggregate fallback
                        $img_src = 'https://images.unsplash.com/photo-1541888946425-d81bb19240f5?auto=format&fit=crop&w=600&q=80';
                    }
                    ?>
                    <div class="gallery-item">
                        <img src="<?php echo $img_src; ?>" alt="<?php echo htmlspecialchars($item['title']); ?>">
                        <div class="gallery-overlay">
                            <h4><?php echo htmlspecialchars($item['title']); ?></h4>
                            <p><?php echo htmlspecialchars($item['description']); ?></p>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php else: ?>
            <!-- Default mock gallery when database is fresh and empty -->
            <div class="section-header" style="margin-bottom: 30px;">
                <p class="section-desc">Berikut adalah beberapa referensi pengaplikasian produk material batu split, agregat, terrazzo, dan batu alam kami.</p>
            </div>
            
            <div class="gallery-grid">
                <div class="gallery-item">
                    <img src="https://images.unsplash.com/photo-1541888946425-d81bb19240f5?auto=format&fit=crop&w=600&q=80" alt="Pengecoran Beton">
                    <div class="gallery-overlay">
                        <h4>Pengecoran Slab Beton Gedung</h4>
                        <p>Menggunakan campuran semen & Batu Split 1-2 cm</p>
                    </div>
                </div>
                <div class="gallery-item">
                    <img src="https://images.unsplash.com/photo-1586528116311-ad8dd3c8310d?auto=format&fit=crop&w=600&q=80" alt="Lapisan Pondasi Jalan">
                    <div class="gallery-overlay">
                        <h4>Pengerasan Jalan Lintas Provinsi</h4>
                        <p>Menggunakan perataan material Base Course Grade A</p>
                    </div>
                </div>
                <div class="gallery-item">
                    <img src="https://images.unsplash.com/photo-1590381105924-c72589b9ef3f?auto=format&fit=crop&w=600&q=80" alt="Paving Block Area">
                    <div class="gallery-overlay">
                        <h4>Pabrikasi Paving Block Area Industri</h4>
                        <p>Bahan campuran kokoh dari Abu Batu & Batu Screening</p>
                    </div>
                </div>
                <div class="gallery-item">
                    <img src="https://images.unsplash.com/photo-1600607687939-ce8a6c25118c?auto=format&fit=crop&w=600&q=80" alt="Lantai Terrazo Premium">
                    <div class="gallery-overlay">
                        <h4>Lantai Terrazzo Polished Lobby</h4>
                        <p>Terrazo cor mewah bermotif pecahan marmer alam</p>
                    </div>
                </div>
                <div class="gallery-item">
                    <img src="https://images.unsplash.com/photo-1600585154340-be6161a56a0c?auto=format&fit=crop&w=600&q=80" alt="Dinding Batu Alam">
                    <div class="gallery-overlay">
                        <h4>Fasad Rumah Tinggal Modern</h4>
                        <p>Aksen dinding batu alam andesit RTM presisi</p>
                    </div>
                </div>
                <div class="gallery-item">
                    <img src="https://images.unsplash.com/photo-1515162305285-0293e4767cc2?auto=format&fit=crop&w=600&q=80" alt="Bantalan Rel Kereta">
                    <div class="gallery-overlay">
                        <h4>Lapisan Bantalan Rel Kereta Cepat</h4>
                        <p>Material ballast stabil dari Batu Split 2-3 cm</p>
                    </div>
                </div>
            </div>
            
            <p style="text-align: center; color: var(--text-muted); margin-top: 40px; font-size: 14px; font-style: italic;">
                * Gambar di atas adalah referensi aplikasi produk. Anda dapat menambahkan foto proyek asli melalui dashboard admin.
            </p>
        <?php endif; ?>
    </div>
</section>

<?php require_once 'includes/footer.php'; ?>
