<?php $pageTitle='Trucks'; ?>
<div class="panel">
<?php $title='Power Unit Network';$eyebrow='Carrier Equipment';$searchAction=url('/trucks');$createUrl=url('/trucks/create');$createText='Add Truck';require app_path('Views/components/search_header.php'); ?>
<div class="table-wrap"><table><thead><tr><th>Unit</th><th>Carrier / Ownership</th><th>Vehicle</th><th>Plate / VIN</th><th>Compliance</th><th>Status</th><th class="text-right">Actions</th></tr></thead><tbody>
<?php foreach($trucks as $truck): ?><tr>
<td><strong><?= e($truck['unit_number']) ?></strong><br><small><?= number_format((int)$truck['current_mileage']) ?> miles</small></td>
<td><strong><?= e($truck['carrier_name']??'Company / Unlinked') ?></strong><br><small><?= e(readable_status($truck['ownership_type']??'carrier_owned')) ?></small></td>
<td><?= e(trim(($truck['year']??'').' '.($truck['make']??'').' '.($truck['model']??''))?:'-') ?></td>
<td><?= e($truck['plate_number']??'-') ?><br><small><?= e($truck['vin']??'') ?></small></td>
<td><small>Insurance <?= e(date_display($truck['insurance_expiry']??null)) ?><br>Registration <?= e(date_display($truck['registration_expiry']??null)) ?><br>Inspection <?= e(date_display($truck['inspection_expiry']??null)) ?></small></td>
<td><span class="badge badge-<?= status_class($truck['status']) ?>"><?= e(readable_status($truck['status'])) ?></span></td>
<td class="text-right table-actions"><a class="btn btn-light btn-sm" href="<?= url('/trucks/edit?id='.$truck['id']) ?>">Edit</a><form method="post" action="<?= url('/trucks/delete') ?>" onsubmit="return confirm('Delete this truck?')"><?= csrf_field() ?><input type="hidden" name="id" value="<?= e((string)$truck['id']) ?>"><button class="btn btn-danger btn-sm" type="submit">Delete</button></form></td>
</tr><?php endforeach; ?><?php if(!$trucks): ?><tr><td colspan="7" class="empty">No trucks found.</td></tr><?php endif; ?></tbody></table></div>
</div>
