<?php
include_once('include/header.php');

$cats = mysqli_query($con, "SELECT * FROM gallery_categories");
?>

<style>
    .gallery-img {
    width: 100%;
    height: 220px;
    object-fit: cover;
    border-radius: 10px;
}

.gallery-video {
    width: 100%;
    height: 220px;
    border-radius: 10px;
}

    </style>


<div class="page-header parallaxie">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="page-header-box">
                    <h1 class="text-anime">
                       Gallery
                    </h1>

                    <nav class="wow fadeInUp" data-wow-delay="0.25s">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?php path() ?>">Home ></a></li>
                            <li class="breadcrumb-item">
                                <a href="<?php path() ?>gallery.php">
                                    Gallery
                                </a>
                            </li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>


 

<div class="container py-5">

<?php while ($cat = mysqli_fetch_assoc($cats)): ?>

<h3 class="mb-4"><?php echo $cat['title']; ?></h3>

<div class="row mb-5">

<?php
$items = mysqli_query($con,
    "SELECT * FROM gallery_items WHERE category_id={$cat['id']} ORDER BY id DESC"
);
while ($item = mysqli_fetch_assoc($items)):
?>

<div class="col-md-4 mb-4">

<?php if ($item['type'] === 'image' && !empty($item['file'])): ?>

    <img src="<?php path(); ?>admin/assets/images/gallery/<?php echo htmlspecialchars($item['file']); ?>"
         class="gallery-img"
         alt="Gallery Image">

<?php elseif ($item['type'] === 'video'): ?>

    <?php if (!empty($item['video_url'])): ?>
        <!-- YouTube / Vimeo -->
        <iframe class="gallery-video"
                src="<?php echo htmlspecialchars($item['video_url']); ?>"
                frameborder="0"
                allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                allowfullscreen>
        </iframe>

    <?php elseif (!empty($item['file'])): ?>
        <!-- Uploaded video -->
        <video class="gallery-video" controls>
            <source src="<?php path(); ?>admin/assets/videos/gallery/<?php echo htmlspecialchars($item['file']); ?>"
                    type="video/mp4">
            Your browser does not support the video tag.
        </video>
    <?php endif; ?>

<?php endif; ?>

</div>


<?php endwhile; ?>
</div>

<?php endwhile; ?>

</div>

<?php include_once('include/footer.php'); ?>
