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

require_once '/home12/fiberule/public_html/kartikthanaweddingdinner/config/db.php';

$rsvps = $pdo->query("SELECT * FROM rsvps ORDER BY created_at DESC")->fetchAll();
$wishes = $pdo->query("SELECT * FROM wishes ORDER BY created_at DESC")->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Wedding Admin Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{margin:0;font-family:Arial;background:#f4f6f9;}
.header{background:#0b1b33;color:#fff;padding:20px;font-size:22px}
.container{padding:24px}
.card{background:#fff;border-radius:10px;padding:20px;margin-bottom:30px;box-shadow:0 8px 25px rgba(0,0,0,.08)}

table{width:100%;border-collapse:collapse}
th,td{padding:12px;border-bottom:1px solid #eee;text-align:left}
th{background:#fafafa}

.go{color:#2e7d32;font-weight:600}
.actions a{
text-decoration:none;
margin-right:10px;
font-size:18px;
}
.delete{color:#c62828}
.tick{color:#2e7d32}
</style>
</head>
<body>

<div class="header">Wedding Admin Dashboard</div>

<div class="container">

<!-- RSVP -->
<div class="card">
<h3>RSVP Responses</h3>

<table>
<tr>
<th>#</th>
<th>Name</th>
<th>Status</th>
<th>Pax</th>
<th>Date</th>
<th>Action</th>
</tr>

<?php foreach($rsvps as $r): ?>
<tr>
<td><?= $r['id'] ?></td>
<td><?= htmlspecialchars($r['name']) ?></td>
<td class="go">✔ <?= $r['status'] ?></td>
<td><?= $r['pax'] ?></td>
<td><?= $r['created_at'] ?></td>
<td class="actions">
  <span class="tick">✔</span>
  <a class="delete" href="delete.php?type=rsvp&id=<?= $r['id'] ?>"
     onclick="return confirm('Delete this RSVP?')">🗑</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>

<!-- WISHES -->
<div class="card">
<h3>Guest Wishes</h3>

<table>
<tr>
<th>#</th>
<th>Name</th>
<th>Message</th>
<th>Date</th>
<th>Action</th>
</tr>

<?php foreach($wishes as $w): ?>
<tr>
<td><?= $w['id'] ?></td>
<td><?= htmlspecialchars($w['name']) ?></td>
<td><?= htmlspecialchars($w['message']) ?></td>
<td><?= $w['created_at'] ?></td>
<td class="actions">
  <span class="tick">✔</span>
  <a class="delete" href="delete.php?type=wish&id=<?= $w['id'] ?>"
     onclick="return confirm('Delete this wish?')">🗑</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>

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