<?php
require_once __DIR__ . '/includes/auth.php';
require_admin();

$subscribers = db()->query('SELECT * FROM vip_alerts ORDER BY created_at DESC')->fetchAll();
$pageTitle = 'VIP Alert Subscribers';
include __DIR__ . '/includes/layout-header.php';
?>
<div class="flex justify-between items-center mb-6">
  <p class="text-muted"><?= count($subscribers) ?> subscribers</p>
  <a href="/admin/export-vip-csv.php" class="btn btn-outline">Export CSV</a>
</div>
<div class="admin-card" style="padding:0;overflow-x:auto;">
  <table class="admin-table">
    <thead><tr><th>Name</th><th>Contact</th><th>Budget (RWF)</th><th>Type</th><th>District</th><th>Joined</th></tr></thead>
    <tbody>
      <?php foreach ($subscribers as $s): ?>
        <tr>
          <td><?= e($s['name']) ?></td>
          <td><?= e($s['email']) ?><br><span class="text-muted"><?= e($s['phone']) ?></span></td>
          <td><?= $s['budget_min'] ? money((float)$s['budget_min']) : '—' ?> – <?= $s['budget_max'] ? money((float)$s['budget_max']) : '—' ?></td>
          <td><?= e($s['property_type'] ?: 'Any') ?></td>
          <td><?= e($s['district'] ?: 'Any') ?></td>
          <td><?= date('M j, Y', strtotime($s['created_at'])) ?></td>
        </tr>
      <?php endforeach; ?>
      <?php if (empty($subscribers)): ?><tr><td colspan="6" class="text-center text-muted">No subscribers yet.</td></tr><?php endif; ?>
    </tbody>
  </table>
</div>
<?php include __DIR__ . '/includes/layout-footer.php'; ?>
