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

$subscribers = db()->query('SELECT * FROM newsletter_subscribers ORDER BY created_at DESC')->fetchAll();
$pageTitle = 'Newsletter 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-newsletter-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>Email</th><th>Joined</th></tr></thead>
    <tbody>
      <?php foreach ($subscribers as $s): ?>
        <tr>
          <td><?= e($s['email']) ?></td>
          <td><?= date('M j, Y', strtotime($s['created_at'])) ?></td>
        </tr>
      <?php endforeach; ?>
      <?php if (empty($subscribers)): ?><tr><td colspan="2" class="text-center text-muted">No subscribers yet.</td></tr><?php endif; ?>
    </tbody>
  </table>
</div>
<?php include __DIR__ . '/includes/layout-footer.php'; ?>
