<form method="post" action="<?= e($action) ?>" class="form-stack">
<?= csrf_field() ?><?php if(!empty($truck['id'])): ?><input type="hidden" name="id" value="<?= e((string)$truck['id']) ?>"><?php endif; ?>
<section class="form-section"><div class="form-section-head"><div><p class="eyebrow">Power Unit</p><h3>Ownership & Identification</h3></div></div><div class="form-grid three">
<label><span>Unit Number *</span><input name="unit_number" value="<?= e(old('unit_number',$truck['unit_number']??'')) ?>" required></label>
<label><span>Carrier Company</span><select name="carrier_id"><option value="">Company / unassigned equipment</option><?php foreach($carriers as $carrier): ?><option value="<?= e((string)$carrier['id']) ?>" <?= (string)old('carrier_id',$truck['carrier_id']??'')===(string)$carrier['id']?'selected':'' ?>><?= e($carrier['company_name']) ?></option><?php endforeach; ?></select></label>
<label><span>Ownership Type</span><select name="ownership_type"><?php foreach(['carrier_owned'=>'Carrier Owned','company_owned'=>'Company Owned','leased'=>'Leased','rental'=>'Rental'] as $value=>$label): ?><option value="<?= e($value) ?>" <?= old('ownership_type',$truck['ownership_type']??'carrier_owned')===$value?'selected':'' ?>><?= e($label) ?></option><?php endforeach; ?></select></label>
<label><span>VIN</span><input name="vin" value="<?= e(old('vin',$truck['vin']??'')) ?>"></label>
<label><span>Plate Number</span><input name="plate_number" value="<?= e(old('plate_number',$truck['plate_number']??'')) ?>"></label>
<label><span>Status</span><select name="status"><?php foreach(['available','on_load','maintenance','inactive'] as $status): ?><option value="<?= e($status) ?>" <?= old('status',$truck['status']??'available')===$status?'selected':'' ?>><?= e(readable_status($status)) ?></option><?php endforeach; ?></select></label>
</div></section>
<section class="form-section"><div class="form-section-head"><div><p class="eyebrow">Vehicle</p><h3>Specifications & Compliance</h3></div></div><div class="form-grid three">
<label><span>Make</span><input name="make" value="<?= e(old('make',$truck['make']??'')) ?>"></label>
<label><span>Model</span><input name="model" value="<?= e(old('model',$truck['model']??'')) ?>"></label>
<label><span>Year</span><input type="number" min="1950" max="2100" name="year" value="<?= e(old('year',$truck['year']??'')) ?>"></label>
<label><span>Current Mileage</span><input type="number" min="0" name="current_mileage" value="<?= e(old('current_mileage',$truck['current_mileage']??'0')) ?>"></label>
<label><span>Insurance Expiry</span><input type="date" name="insurance_expiry" value="<?= e(old('insurance_expiry',$truck['insurance_expiry']??'')) ?>"></label>
<label><span>Registration Expiry</span><input type="date" name="registration_expiry" value="<?= e(old('registration_expiry',$truck['registration_expiry']??'')) ?>"></label>
<label><span>Inspection Expiry</span><input type="date" name="inspection_expiry" value="<?= e(old('inspection_expiry',$truck['inspection_expiry']??'')) ?>"></label>
</div></section>
<div class="form-actions sticky-form-actions"><button class="btn btn-primary" type="submit">Save Truck</button><a class="btn btn-light" href="<?= url('/trucks') ?>">Cancel</a></div>
</form>
