<?php
/** Recent driver-truck assignments feed for the HR dashboard. */
$rows = $this->data['feed_assignments'] ?? [];
?>
<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 assignments</h6>
      <a href="<?= PROOT; ?>DriverAssignments" class="small text-decoration-none">All &rarr;</a>
    </div>
    <?php if (empty($rows)): ?>
      <div class="text-center text-muted small py-4">No assignments.</div>
    <?php else: ?>
      <table class="table table-sm mb-0">
        <tbody>
          <?php foreach ($rows as $a): ?>
            <tr>
              <td>
                <div class="small fw-semibold"><?= htmlspecialchars($a['driver_name'] ?: '—'); ?></div>
                <div class="small text-muted"><?= htmlspecialchars($a['truck_reg'] ?: '—'); ?> &middot; <?= htmlspecialchars($a['role_type'] ?? ''); ?></div>
              </td>
              <td class="text-end small">
                <div>from <?= humanDate($a['assigned_from']); ?></div>
                <?php if ($a['assigned_to']): ?>
                  <div class="text-muted">to <?= humanDate($a['assigned_to']); ?></div>
                <?php else: ?>
                  <div class="text-success">current</div>
                <?php endif; ?>
              </td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    <?php endif; ?>
  </div>
</div>
