<?php
/** Upcoming compliance expiries feed. */
$rows = $this->data['feed_compliance'] ?? [];
?>
<div class="card border-0 shadow-sm h-100">
  <div class="card-body p-0">
    <div class="p-3 pb-2 d-flex justify-content-between align-items-center">
      <h6 class="text-uppercase text-muted small mb-0">Compliance · nearest expiries</h6>
      <a href="<?= PROOT; ?>DocExpiries" class="small text-decoration-none">All &rarr;</a>
    </div>
    <?php if (empty($rows)): ?>
      <div class="text-center text-muted small py-4">Nothing expiring soon.</div>
    <?php else: ?>
      <table class="table table-sm mb-0">
        <tbody>
          <?php foreach ($rows as $r):
            $d = (int)$r['days'];
            $bg = $d < 0 ? 'danger' : ($d <= 14 ? 'danger' : ($d <= 30 ? 'warning text-dark' : 'success'));
            $lbl = $d < 0 ? abs($d) . 'd overdue' : ($d === 0 ? 'today' : $d . 'd left');
          ?>
            <tr>
              <td>
                <div class="small fw-semibold"><?= htmlspecialchars($r['doc_type'] ?: '—'); ?></div>
                <div class="small text-muted"><?= htmlspecialchars($r['about'] ?: '—'); ?></div>
              </td>
              <td class="text-end">
                <div class="small text-muted"><?= humanDate($r['expires_on']); ?></div>
                <div class="badge bg-<?= $bg; ?> small"><?= $lbl; ?></div>
              </td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    <?php endif; ?>
  </div>
</div>
