<?php
$db = Database::getInstance();
$failedCount = (int)$db->fetchColumn("SELECT COUNT(*) FROM notification_queue WHERE status = 'failed'");
$recentFailed = $db->fetchAll("SELECT recipient_address, failure_reason, created_at FROM notification_queue WHERE status = 'failed' ORDER BY created_at DESC LIMIT 3");
?>
<div class="card border-danger h-100">
    <div class="card-body">
        <div class="d-flex justify-content-between">
            <div>
                <h6 class="text-muted mb-1"><?= lang('comm.failed_notifications') ?></h6>
                <h3 class="mb-0"><?= number_format($failedCount) ?></h3>
            </div>
            <div class="align-self-center"><i class="fas fa-exclamation-triangle fa-2x text-danger opacity-50"></i></div>
        </div>
        <?php if (!empty($recentFailed)): ?>
        <hr class="my-2">
        <?php foreach ($recentFailed as $f): ?>
        <small class="d-block text-truncate text-muted" title="<?= e($f['failure_reason'] ?? '') ?>"><?= e($f['recipient_address']) ?>: <?= e(str_limit($f['failure_reason'] ?? 'Unknown', 30)) ?></small>
        <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>