<?php

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

/* ==========================
   CURRENT SARPANCH
========================== */

$sarpanch = mysqli_query($conn,"
SELECT *
FROM village_sarpanches
WHERE village_id='$village_id'
ORDER BY id DESC
LIMIT 1
");

$sarpanch_data = mysqli_fetch_assoc($sarpanch);

/* ==========================
   MEMBERS LIST
========================== */

$members = mysqli_query($conn,"
SELECT *
FROM village_members
WHERE village_id='$village_id'
ORDER BY id DESC
");

?>

<div class="container">

<!-- ==========================
   SARPANCH SECTION
========================== -->

<div class="sarpanch-section">

<h2 class="section-title">
सरपंच के बारे में जानकारी
</h2>

<?php if($sarpanch_data){ ?>

<div class="sarpanch-box">

<div class="sarpanch-image">

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

<img src="/digital_panchayat/uploads/sarpanches/<?php echo $sarpanch_data['image']; ?>">

<?php } ?>

</div>

<div class="sarpanch-text">

<h3><?php echo htmlspecialchars($sarpanch_data['name']); ?></h3>

<p style="color:#777;">
<?php echo htmlspecialchars($sarpanch_data['duration']); ?>
</p>

<p>
<?php echo nl2br(substr($sarpanch_data['description'],0,250)); ?>...
<br><br>

<a href="sarpanch_detail.php?id=<?php echo $sarpanch_data['id']; ?>" class="view-btn">
पूरा पढ़ें →
</a>
</p>

</div>

</div>

<?php } else { ?>

<p>सरपंच की जानकारी उपलब्ध नहीं है</p>

<?php } ?>

</div>

<!-- ==========================
   MEMBERS SECTION
========================== -->

<h2 class="section-title" style="margin-top:30px;">
पंचायत सदस्य
</h2>

<div class="member-grid">

<?php if(mysqli_num_rows($members) > 0){ ?>

<?php while($m = mysqli_fetch_assoc($members)){ ?>

<div class="member-card">

<?php if(!empty($m['image'])){ ?>
<img src="/digital_panchayat/uploads/members/<?php echo $m['image']; ?>">
<?php } ?>

<h3><?php echo htmlspecialchars($m['name']); ?></h3>

<?php if(!empty($m['designation'])){ ?>
<p class="designation"><?php echo htmlspecialchars($m['designation']); ?></p>
<?php } ?>

<?php if(!empty($m['mobile'])){ ?>
<p class="mobile">📞 <?php echo htmlspecialchars($m['mobile']); ?></p>
<?php } ?>

</div>

<?php } ?>

<?php } else { ?>

<p>कोई सदस्य उपलब्ध नहीं है</p>

<?php } ?>

</div>

</div>

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