<?php
/**
 * Shared KPI-tile strip. Consumes $this->data['kpi_tiles']:
 *   [ ['label', 'value', 'sub'?, 'href'?, 'accent'? => primary|success|danger|warning|info|muted], ... ]
 */
$tiles = $this->data['kpi_tiles'] ?? [];
if (empty($tiles)) return;

$colClass = match (count($tiles)) {
    1, 2       => 'col-6 col-md-6',
    3          => 'col-6 col-md-4',
    4          => 'col-6 col-md-3',
    5          => 'col-6 col-md col-lg',
    default    => 'col-6 col-lg-2',
};
$accentClass = [
    'primary' => 'text-primary', 'success' => 'text-success', 'danger' => 'text-danger',
    'warning' => 'text-warning', 'info'    => 'text-info',    'muted'  => 'text-muted',
];
?>
<div class="row g-2 mb-3">
  <?php foreach ($tiles as $t):
    $cls   = $accentClass[$t['accent'] ?? 'primary'] ?? 'text-primary';
    $inner = '<div class="text-uppercase text-muted small" style="letter-spacing:.05em;">' . htmlspecialchars($t['label']) . '</div>'
           . '<div class="fs-4 fw-bold ' . $cls . '">' . htmlspecialchars($t['value']) . '</div>'
           . (!empty($t['sub']) ? '<div class="small text-muted">' . htmlspecialchars($t['sub']) . '</div>' : '');
  ?>
    <div class="<?= $colClass; ?>">
      <?php if (!empty($t['href'])): ?>
        <a href="<?= PROOT; ?><?= htmlspecialchars($t['href']); ?>" class="card border-0 shadow-sm h-100 text-decoration-none text-reset">
          <div class="card-body py-3"><?= $inner; ?></div>
        </a>
      <?php else: ?>
        <div class="card border-0 shadow-sm h-100"><div class="card-body py-3"><?= $inner; ?></div></div>
      <?php endif; ?>
    </div>
  <?php endforeach; ?>
</div>
