<div class="admin-page-actions">
    <p><strong><?= (int) $recipientCount ?></strong> active users are currently opted in.</p>
</div>

<div class="admin-detail-grid newsletter-grid">
    <section class="admin-panel">
        <div class="admin-panel-heading"><div><span class="eyebrow">Send an update</span><h2>New Newsletter</h2></div></div>
        <form class="form-stack" action="<?= e(url('/admin/newsletters/send')) ?>" method="post">
            <?= csrf_field() ?>
            <label>Subject line<input type="text" name="subject" maxlength="140" required placeholder="This weekend at Fat Bottom Grille"></label>
            <label>Message<textarea name="content" rows="12" required placeholder="Share a new special, schedule update, or note from the kitchen..."></textarea></label>
            <div class="notice">Every email includes an unsubscribe link. Users can also opt out from My Account.</div>
            <button class="button button-large button-block" type="submit" data-confirm="Send this newsletter to every opted-in user?">Send to <?= (int) $recipientCount ?> Subscribers</button>
        </form>
    </section>
    <section class="admin-panel">
        <div class="admin-panel-heading"><div><span class="eyebrow">Delivery history</span><h2>Past Sends</h2></div></div>
        <div class="newsletter-history">
            <?php if (!$newsletters): ?><p class="muted">No newsletters have been sent yet.</p><?php endif; ?>
            <?php foreach ($newsletters as $newsletter): ?>
                <article>
                    <div><strong><?= e($newsletter['subject']) ?></strong><span><?= e(store_datetime((string) ($newsletter['sent_at'] ?: $newsletter['created_at']))) ?></span></div>
                    <span class="role-badge"><?= (int) $newsletter['recipient_count'] ?> sent</span>
                    <small>by <?= e($newsletter['author'] ?: 'System') ?></small>
                </article>
            <?php endforeach; ?>
        </div>
    </section>
</div>
