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

$q = $conn->query("
SELECT v.id,v.name,v.mobile,v.selfie 
FROM visitors v
JOIN visitor_logs vl ON v.id=vl.visitor_id
WHERE vl.village_id='$village_id'
GROUP BY v.id
ORDER BY v.id DESC
");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visitors</title>

<style>
body{margin:0;font-family:Arial;background:#f1f5f9}
.app{max-width:520px;margin:0 auto}
.header{background:#2563eb;color:white;padding:20px;border-radius:0 0 25px 25px}
.card{background:white;margin:14px;padding:14px;border-radius:18px;display:flex;gap:12px;align-items:center}
img{width:60px;height:60px;border-radius:12px;object-fit:cover}
</style>
</head>

<body>
<div class="app">

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

<?php while($row = $q->fetch_assoc()): ?>
<div class="card">
<img src="../<?= $row['selfie'] ?>">
<div>
<b><?= $row['name'] ?></b><br>
<?= $row['mobile'] ?>
</div>
</div>
<?php endwhile; ?>

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