<?php
$db = getDB();

$subscribers = $db->query("SELECT * FROM newsletter_subscribers ORDER BY created_at DESC")->fetchAll();

include __DIR__ . '/admin_header.php';
?>

<div class="admin-topbar">
    <h2>Newsletter Subscribers</h2>
</div>

<div class="admin-card">
    <h3>All Subscribers</h3>
    <table>
        <thead>
            <tr><th>Email</th><th>Name</th><th>Status</th><th>Date</th></tr>
        </thead>
        <tbody>
        <?php foreach ($subscribers as $s): ?>
            <tr>
                <td><?= htmlspecialchars($s['email']) ?></td>
                <td><?= htmlspecialchars($s['name'] ?? '') ?></td>
                <td><?= $s['active'] ? 'Active' : 'Inactive' ?></td>
                <td><?= htmlspecialchars($s['created_at']) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>

<?php include __DIR__ . '/admin_footer.php'; ?>
