<?php
$db = Database::getInstance();
$sentToday = (int)$db->fetchColumn("SELECT COUNT(*) FROM notifications_sent WHERE DATE(sent_at) = CURDATE()");
$byChannel = $db->fetchAll("SELECT nc.name_en, COUNT(*) AS cnt FROM notifications_sent ns LEFT JOIN notification_channels nc ON ns.channel_id = nc.id WHERE DATE(ns.sent_at) = CURDATE() GROUP BY nc.name_en ORDER BY cnt DESC LIMIT 5");
?>
<div class="card border-success h-100">
    <div class="card-body">
        <div class="d-flex justify-content-between">
            <div>
                <h6 class="text-muted mb-1"><?= lang('comm.sent_today') ?></h6>
                <h3 class="mb-0"><?= number_format($sentToday) ?></h3>
            </div>
            <div class="align-self-center"><i class="fas fa-paper-plane fa-2x text-success opacity-50"></i></div>
        </div>
        <?php if (!empty($byChannel)): ?>
        <hr class="my-2">
        <small class="text-muted">
            <?php foreach ($byChannel as $ch): ?>
            <?= e($ch['name_en']) ?>: <strong><?= $ch['cnt'] ?></strong><?= $ch !== end($byChannel) ? ' | ' : '' ?>
            <?php endforeach; ?>
        </small>
        <?php endif; ?>
    </div>
</div>