<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

session_start();
include "../config/db.php";

/* Check Login */
if(!isset($_SESSION['user_id'])){
    header("Location: ../admin/login.php");
    exit;
}

$village_id = $_SESSION['village_id'];

/* Stats */
$families = mysqli_fetch_assoc(mysqli_query($conn,"SELECT COUNT(*) as total FROM families WHERE village_id='$village_id'"))['total'];
$members = mysqli_fetch_assoc(mysqli_query($conn,"SELECT COUNT(*) as total FROM family_members WHERE village_id='$village_id'"))['total'];

include "operator_header.php";
?>

<h3>Welcome 👋</h3>
<p style="color:#666;font-size:14px;">Select what you want to manage</p>

<!-- ===== CATEGORY BUTTONS ===== -->

<div style="display:grid;grid-template-columns:repeat(2,1fr);gap:15px;margin-top:15px;">

<a href="family.php" style="background:#3498db;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-home"></i><br><br>Family
</a>

<a href="panchayat.php" style="background:#27ae60;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-user-tie" style="font-size:22px;"></i>
<br><br>
Panchayat
</a>

<a href="works.php" style="background:#f39c12;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-tools"></i><br><br>Works
</a>

<a href="news.php" style="background:#e74c3c;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-bullhorn"></i><br><br>News
</a>

<a href="buildings.php" style="background:#16a085;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-building"></i><br><br>Buildings
</a>

<a href="donations.php" style="background:#9b59b6;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-hand-holding-heart"></i><br><br>Donations
</a>

<a href="media.php" style="background:#2c3e50;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-image"></i><br><br>Media
</a>

<a href="../admin/villages/about_village.php" style="background:#34495e;color:white;padding:20px;border-radius:8px;text-align:center;text-decoration:none;">
<i class="fa fa-info-circle"></i><br><br>About Village
</a>

</div>

<!-- ===== STATS ===== -->

<div style="margin-top:25px;">
<h4>Village Stats</h4>

<div style="display:flex;gap:10px;">

<div style="flex:1;background:#fff;padding:15px;border-radius:6px;text-align:center;">
<h3><?php echo $families; ?></h3>
<p>Families</p>
</div>

<div style="flex:1;background:#fff;padding:15px;border-radius:6px;text-align:center;">
<h3><?php echo $members; ?></h3>
<p>Members</p>
</div>

</div>
</div>

<!-- ===== BOTTOM NAV ===== -->

<div class="bottom-nav">

<a href="operator_dashboard.php" class="active">
<i class="fa fa-home"></i>
Home
</a>

<a href="family.php">
<i class="fa fa-users"></i>
Family
</a>

<a href="members.php">
<i class="fa fa-user"></i>
Members
</a>

<a href="../admin/families/add_member.php">
<i class="fa fa-user-plus"></i>
Add
</a>

<a href="../admin/logout.php">
<i class="fa fa-sign-out-alt"></i>
Logout
</a>

</div>

</div>
</body>
</html>