<?php include "head.php"; ?>

<style>
/* ===== INLINE STYLES (GUARANTEED LOAD) ===== */
.projects-page { padding: 80px 20px; font-family: inherit; }

.hero-testimonial {
    max-width: 420px;
    margin: auto;
    text-align: center;
}
.hero-testimonial h1 {
    font-size: 2.1rem;
    margin-bottom: 12px;
}
.hero-testimonial p {
    color: #555;
    margin-bottom: 20px;
}

.hero-testimonial video {
    width: 100%;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0,0,0,.18);
}

/* PROJECT SECTIONS */
.project-category {
    margin-top: 90px;
}
.project-category h2 {
    text-align: center;
    margin-bottom: 10px;
}
.project-category p {
    text-align: center;
    max-width: 720px;
    margin: auto;
    color: #555;
}

/* CAROUSEL */
.carousel {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 30px 10px;
}
.carousel::-webkit-scrollbar { height: 6px; }
.carousel::-webkit-scrollbar-thumb {
    background: #0d6efd;
    border-radius: 10px;
}

.carousel-item {
    min-width: 280px;
    max-width: 360px;
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,.08);
}
.carousel-item img,
.carousel-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* PAGINATION */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
}
.controls button {
    padding: 8px 16px;
    border: none;
    background: #0d6efd;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
}

@media(max-width:768px){
    .hero-testimonial h1 { font-size: 1.7rem; }
}
</style>

<div class="projects-page">

<!-- AD COPY + TESTIMONIAL VIDEO -->
<section class="hero-testimonial">
    <h1>Trusted Electrical & Solar Experts</h1>
    <p>
        Hear directly from one of our satisfied clients about their experience
        working with FEMTECH WAVES LIMITED.
    </p>
    <video controls preload="metadata" playsinline>
        <source src="/uploads/projects/femtechwaves-solar-and-electical-company-Abuja.mp4" type="video/mp4">
    </video>
</section>

<?php
$basePath = __DIR__ . "/uploads/projects/";
$jsonFile = $basePath . "categories.json";

if (file_exists($jsonFile)) {
    $categories = json_decode(file_get_contents($jsonFile), true);
} else {
    $categories = [];
}

$index = 0;
foreach ($categories as $title => $slug):
    $mediaDir = $basePath . $slug . "/media/";
    if (!is_dir($mediaDir)) continue;

    $files = glob($mediaDir . "*.{jpg,jpeg,png,webp,mp4,webm}", GLOB_BRACE);
    if (!$files) continue;
?>

<section class="project-category">
    <h2><?= htmlspecialchars($title) ?></h2>
    <p>Completed projects showcasing quality workmanship and excellence.</p>

    <div class="carousel" id="carousel<?= $index ?>">
        <?php foreach ($files as $file):
            $url = "/uploads/projects/$slug/media/" . basename($file);
        ?>
            <div class="carousel-item">
                <?php if (preg_match('/\.(mp4|webm)$/i', $file)): ?>
                    <video controls loading="lazy" playsinline>
                        <source src="<?= $url ?>">
                    </video>
                <?php else: ?>
                    <img src="<?= $url ?>" loading="lazy"
                         alt="<?= htmlspecialchars($title) ?> project image">
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>

    <div class="controls">
        <button onclick="scrollC('carousel<?= $index ?>', -1)">‹ Prev</button>
        <button onclick="scrollC('carousel<?= $index ?>', 1)">Next ›</button>
    </div>
</section>

<?php $index++; endforeach; ?>

</div>

<script>
function scrollC(id, dir){
    document.getElementById(id).scrollLeft += dir * 320;
}
</script>

<?php include "footer.php"; ?>
