<?php include 'views/admin/header.php'; ?>

<div class="container-fluid py-4">
    <div class="row">
        <div class="col-12">
            <div class="card mb-4">
                <div class="card-header pb-0 d-flex justify-content-between align-items-center">
                    <h6>Newsletter Subscribers</h6>
                    <div>
                        <a href="/admin/newsletter/send" class="btn btn-sm btn-primary me-2">
                            <i class="fas fa-paper-plane me-1"></i> Send Email
                        </a>
                        <a href="/admin/newsletter/export" class="btn btn-sm btn-success">
                            <i class="fas fa-file-export me-1"></i> Export CSV
                        </a>
                    </div>
                </div>
                <div class="card-body px-0 pt-0 pb-2">
                    <div class="table-responsive p-0">
                        <table class="table align-items-center mb-0">
                            <thead>
                                <tr>
                                    <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Email</th>
                                    <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Subscribed At</th>
                                    <th class="text-secondary opacity-7"></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($subscribers as $subscriber): ?>
                                <tr>
                                    <td>
                                        <div class="d-flex px-2 py-1">
                                            <div class="d-flex flex-column justify-content-center">
                                                <h6 class="mb-0 text-sm"><?php echo htmlspecialchars($subscriber['email']); ?></h6>
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <p class="text-xs font-weight-bold mb-0"><?php echo $subscriber['created_at']; ?></p>
                                    </td>
                                    <td class="align-middle">
                                        <a href="/admin/newsletter/delete/<?php echo $subscriber['id']; ?>" 
                                           class="text-secondary font-weight-bold text-xs" 
                                           onclick="return confirm('Are you sure you want to delete this subscriber?')">
                                            Delete
                                        </a>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                                <?php if (empty($subscribers)): ?>
                                <tr>
                                    <td colspan="3" class="text-center py-4">
                                        <p class="text-xs font-weight-bold mb-0">No subscribers found.</p>
                                    </td>
                                </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include 'views/admin/footer.php'; ?>