<?php
require_once("auth.php");
require_once("../api/config/db.php");

$q = $conn->query("
SELECT u.*, v.village_name, b.name AS block_name, d.name AS district_name
FROM users u
LEFT JOIN villages v ON u.village_id = v.id
LEFT JOIN blocks b ON v.block_id = b.id
LEFT JOIN districts d ON b.district_id = d.id
WHERE u.id='$admin_id'
LIMIT 1
");

$data = $q->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Profile</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../assets/css/mobile-premium.css">
<style>
*{box-sizing:border-box}
body{margin:0;font-family:Arial;background:#f1f5f9;color:#0f172a}
.app{max-width:520px;margin:0 auto;min-height:100vh;background:#f8fafc;padding-bottom:90px}
.header{background:linear-gradient(135deg,#052e16,#15803d,#22c55e);color:white;padding:24px 18px 34px;border-bottom-left-radius:30px;border-bottom-right-radius:30px}
.card{background:white;margin:16px;padding:18px;border-radius:24px;box-shadow:0 10px 30px rgba(15,23,42,.08)}
.avatar{width:90px;height:90px;border-radius:30px;background:linear-gradient(135deg,#16a34a,#22c55e);color:white;display:grid;place-items:center;font-size:42px;font-weight:900;margin:0 auto 14px}
.center{text-align:center}
.row{display:flex;justify-content:space-between;gap:15px;padding:14px 0;border-bottom:1px solid #e5e7eb}
.row span{color:#64748b}
.logout{display:block;text-align:center;background:#ef4444;color:white;padding:15px;border-radius:18px;font-weight:900;text-decoration:none;margin-top:18px}
.nav{position:fixed;bottom:0;left:50%;transform:translateX(-50%);max-width:520px;width:100%;background:white;display:grid;grid-template-columns:repeat(5,1fr);padding:10px 4px 12px;box-shadow:0 -10px 30px rgba(0,0,0,.08)}
.nav a{text-align:center;text-decoration:none;color:#64748b;font-size:20px}.nav span{display:block;font-size:11px;font-weight:700}
</style>
<link rel="stylesheet" href="../assets/css/mobile-premium.css">
</head>
<body>
<div class="app">

<div class="header">
    <h2>Profile</h2>
</div>

<div class="profile-message">
    <h3>Welcome To Gram Rakshak</h3>
    <p>Your Village Admin profile manages Villagers, visitors, and security alerts.</p>
</div>

<div class="card center">
    <div class="avatar"><?= strtoupper(substr($data['name'],0,1)) ?></div>
    <h2><?= htmlspecialchars($data['name']) ?></h2>
    <p>Village Admin</p>
</div>

<div class="card">
    <div class="row"><span>Mobile</span><b><?= htmlspecialchars($data['mobile']) ?></b></div>
    <div class="row"><span>Father Name</span><b><?= htmlspecialchars($data['father_name'] ?? '-') ?></b></div>
    <div class="row"><span>Village</span><b><?= htmlspecialchars($data['village_name'] ?? '-') ?></b></div>
    <div class="row"><span>Block</span><b><?= htmlspecialchars($data['block_name'] ?? '-') ?></b></div>
    <div class="row"><span>District</span><b><?= htmlspecialchars($data['district_name'] ?? '-') ?></b></div>
    <div class="row"><span>Status</span><b><?= htmlspecialchars($data['status']) ?></b></div>

    <a href="logout.php" class="logout">Logout</a>
</div>

<?php require_once("includes/bottom-nav.php"); ?>

</div>
<script src="../assets/js/mobile-app.js"></script>
</body>
</html>
