<?php
$mkt = $mkt ?? [];
$title = $title ?? 'Marketing Snapshot';
$wide = !empty($wide);
$items = [
    ['bi-send', '#2563eb', '#dbeafe', number_format((int) ($mkt['campaigns_sent'] ?? 0)), 'Campaigns sent'],
    ['bi-envelope-check', '#16a34a', '#dcfce7', number_format((int) ($mkt['delivered'] ?? 0)), 'Delivered'],
    ['bi-eye', '#7c3aed', '#f3e8ff', number_format((int) ($mkt['opened'] ?? 0)), 'Opens (' . ($mkt['open_pct'] ?? 0) . '%)'],
    ['bi-cursor', '#ea580c', '#ffedd5', number_format((int) ($mkt['clicked'] ?? 0)), 'Clicks (' . ($mkt['click_pct'] ?? 0) . '%)'],
    ['bi-person-dash', '#db2777', '#fce7f3', number_format((int) ($mkt['unsubscribed'] ?? 0)), 'Unsubscribed'],
    ['bi-exclamation-triangle', '#d97706', '#fef3c7', number_format((int) ($mkt['bounced'] ?? 0)), 'Bounced (' . ($mkt['bounce_pct'] ?? 0) . '%)'],
];
$sent = (int) ($mkt['campaigns_sent'] ?? 0);
$sub = $sent ? $sent . ' campaign' . ($sent === 1 ? '' : 's') . ' this month' : 'This month’s campaign results';
?>
<div class="card-soft hm-card h-100<?= $wide ? ' hm-wide' : '' ?>">
  <div class="hm-head">
    <div class="hm-head-icon"><i class="bi bi-megaphone"></i></div>
    <div class="min-w-0 flex-grow-1">
      <h2><?= e($title) ?></h2>
      <p><?= e($sub) ?></p>
    </div>
    <?php if (can_see('campaign_reports')): ?>
      <a href="<?= e(url('campaigns/reports')) ?>">Marketing</a>
    <?php endif; ?>
  </div>
  <div class="hm-grid">
    <?php foreach ($items as $item): ?>
      <div class="hm-stat">
        <div class="hm-icon" style="background:<?= e($item[2]) ?>;color:<?= e($item[1]) ?>"><i class="bi <?= e($item[0]) ?>"></i></div>
        <div class="min-w-0">
          <div class="hm-n"><?= e($item[3]) ?></div>
          <div class="hm-l"><?= e($item[4]) ?></div>
        </div>
      </div>
    <?php endforeach; ?>
  </div>
</div>
