<?php
/** Trip requests needing attention for the Ops / Dispatcher dashboard. */
$rows = $this->data['feed_requests'] ?? [];
?>
<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">Requests needing attention</h6>
      <a href="<?= PROOT; ?>TripRequests" class="small text-decoration-none">All &rarr;</a>
    </div>
    <?php if (empty($rows)): ?>
      <div class="text-center text-muted small py-4">Nothing pending review or dispatch.</div>
    <?php else: ?>
      <table class="table table-sm mb-0">
        <tbody>
          <?php foreach ($rows as $r): $bg = $r['status'] === 'pending_review' ? 'warning text-dark' : 'primary'; ?>
            <tr>
              <td>
                <a href="<?= PROOT; ?>TripRequests/view/<?= (int)$r['c0d']; ?>" class="text-decoration-none">
                  <div class="font-monospace small"><?= htmlspecialchars($r['request_no']); ?></div>
                  <div class="small text-muted">
                    <?= htmlspecialchars($r['customer_name'] ?: '—'); ?> &middot;
                    <?= htmlspecialchars($r['origin_city'] ?: '—'); ?> &rarr;
                    <?= htmlspecialchars($r['destination_city'] ?: '—'); ?>
                  </div>
                </a>
              </td>
              <td class="text-end">
                <div class="small text-muted"><?= $r['planned_pickup'] ? humanDate($r['planned_pickup']) : ''; ?></div>
                <div class="badge bg-<?= $bg; ?> small"><?= htmlspecialchars(str_replace('_', ' ', $r['status'])); ?></div>
              </td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    <?php endif; ?>
  </div>
</div>
