<?php

include "../config/db.php";

$slug = $_GET['village'] ?? '';

$village = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT * FROM villages WHERE slug='$slug'
"));

if(!$village){
echo "Village not found";
exit;
}

$village_id = $village['id'];

include "header.php";

/* FETCH GALLERY CATEGORIES */

$cats = mysqli_query($conn,"
SELECT *
FROM gallery_categories
WHERE village_id='$village_id'
");

?>

<style>

/* GALLERY GRID */

.gallery-categories{
display:grid;
grid-template-columns:repeat(auto-fit,minmax(250px,1fr));
gap:20px;
margin-top:20px;
}

/* CATEGORY BOX */

.gallery-box{
background:#fff;
border-radius:6px;
overflow:hidden;
box-shadow:0 2px 6px rgba(0,0,0,0.1);
text-align:center;
transition:0.3s;
}

.gallery-box:hover{
transform:translateY(-5px);
}

/* IMAGE */

.gallery-box img{
width:100%;
height:180px;
object-fit:cover;
display:block;
}

/* TITLE */

.gallery-box h3{
padding:10px;
font-size:18px;
color:#333;
}

.gallery-box a{
text-decoration:none;
color:inherit;
}

</style>

<div class="container">

<h2 class="section-title">Village Gallery</h2>

<div class="gallery-categories">

<?php while($c=mysqli_fetch_assoc($cats)){ ?>

<div class="gallery-box">

<a href="gallery_images.php?category=<?php echo $c['id']; ?>&village=<?php echo $slug; ?>">

<?php if(!empty($c['image'])){ ?>

<img src="/digital_panchayat/uploads/gallery/<?php echo $c['image']; ?>" alt="gallery">

<?php } ?>

<h3><?php echo $c['category_name']; ?></h3>

</a>

</div>

<?php } ?>

</div>

</div>

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