<?php $pageTitle = 'Drivers'; ?>
<div class="panel">
    <?php $title='Driver Network';$eyebrow='Carrier Operations';$searchAction=url('/drivers');$createUrl=url('/drivers/create');$createText='Add Driver';require app_path('Views/components/search_header.php'); ?>
    <div class="table-wrap"><table><thead><tr><th>Driver</th><th>Carrier / Type</th><th>Contact</th><th>Compliance</th><th>Pay</th><th>Status</th><th class="text-right">Actions</th></tr></thead><tbody>
    <?php foreach ($drivers as $driver): ?>
        <tr>
            <td><strong><?= e($driver['name']) ?></strong><br><small><?= e($driver['address'] ?? '') ?></small></td>
            <td><strong><?= e($driver['carrier_name'] ?? 'Company / Unlinked') ?></strong><br><small><?= e(readable_status($driver['employment_type'] ?? 'carrier_driver')) ?></small></td>
            <td><?= e($driver['phone'] ?? '-') ?><br><small><?= e($driver['email'] ?? '') ?></small></td>
            <td><?= e($driver['license_number'] ?? '-') ?><br><small>License <?= e(date_display($driver['license_expiry'] ?? null)) ?> · Medical <?= e(date_display($driver['medical_card_expiry'] ?? null)) ?></small></td>
            <td><?= e(readable_status($driver['pay_type'])) ?><br><small><?= e((string)$driver['rate']) ?></small></td>
            <td><span class="badge badge-<?= status_class($driver['status']) ?>"><?= e(readable_status($driver['status'])) ?></span></td>
            <td class="text-right table-actions"><a class="btn btn-light btn-sm" href="<?= url('/drivers/edit?id='.$driver['id']) ?>">Edit</a><form method="post" action="<?= url('/drivers/delete') ?>" onsubmit="return confirm('Delete this driver?')"><?= csrf_field() ?><input type="hidden" name="id" value="<?= e((string)$driver['id']) ?>"><button class="btn btn-danger btn-sm" type="submit">Delete</button></form></td>
        </tr>
    <?php endforeach; ?>
    <?php if (!$drivers): ?><tr><td colspan="7" class="empty">No drivers found.</td></tr><?php endif; ?>
    </tbody></table></div>
</div>
