<?php
/** Renders a compact "Recent trips" card from $this->data['feed_trips']. */
$trips = $this->data['feed_trips'] ?? [];
$badge = ['dispatched'=>'primary','in_transit'=>'info','delivered'=>'warning','closed'=>'success','draft'=>'secondary'];
?>
<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">Recent trips</h6>
      <a href="<?= PROOT; ?>Trips" class="small text-decoration-none">All &rarr;</a>
    </div>
    <?php if (empty($trips)): ?>
      <div class="text-center text-muted small py-4">No trips yet.</div>
    <?php else: ?>
      <table class="table table-sm mb-0">
        <tbody>
          <?php foreach ($trips as $t): $col = $badge[$t['status']] ?? 'light'; ?>
            <tr>
              <td>
                <a href="<?= PROOT; ?>Trips/view/<?= (int)$t['c0d']; ?>" class="text-decoration-none">
                  <div class="font-monospace small"><?= htmlspecialchars($t['trip_no']); ?></div>
                  <div class="small text-muted"><?= htmlspecialchars($t['customer_name'] ?: '—'); ?> &middot;
                    <?= htmlspecialchars($t['truck_reg'] ?: '—'); ?> &middot;
                    <?= htmlspecialchars($t['driver_name'] ?: '—'); ?>
                  </div>
                </a>
              </td>
              <td class="text-end"><span class="badge bg-<?= $col; ?>"><?= htmlspecialchars(str_replace('_', ' ', $t['status'])); ?></span></td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    <?php endif; ?>
  </div>
</div>
