<?php

header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");

require_once("../config/db.php");

$village_id = intval($_GET['village_id'] ?? 0);

if (!$village_id) {
    echo json_encode([
        "status" => false,
        "message" => "Village ID required"
    ]);
    exit;
}

$query = "SELECT name, mobile 
FROM users 
WHERE role = 'village_admin' 
AND village_id = '$village_id' 
AND status = 'approved'
LIMIT 1";

$result = $conn->query($query);

if ($result->num_rows > 0) {
    echo json_encode([
        "status" => true,
        "data" => $result->fetch_assoc()
    ]);
} else {
    echo json_encode([
        "status" => false,
        "message" => "No admin found"
    ]);
}