<form method="post" action="<?= e($action) ?>" class="form-stack">
<?= csrf_field() ?><?php if(!empty($driver['id'])): ?><input type="hidden" name="id" value="<?= e((string)$driver['id']) ?>"><?php endif; ?>
<section class="form-section"><div class="form-section-head"><div><p class="eyebrow">Driver Profile</p><h3>Identity & Carrier Relationship</h3></div></div><div class="form-grid three">
<label><span>Driver Name *</span><input name="name" value="<?= e(old('name',$driver['name']??'')) ?>" required></label>
<label><span>Carrier Company</span><select name="carrier_id"><option value="">Independent / not assigned</option><?php foreach($carriers as $carrier): ?><option value="<?= e((string)$carrier['id']) ?>" <?= (string)old('carrier_id',$driver['carrier_id']??'')===(string)$carrier['id']?'selected':'' ?>><?= e($carrier['company_name']) ?></option><?php endforeach; ?></select></label>
<label><span>Driver Type</span><select name="employment_type"><?php foreach(['carrier_driver'=>'Carrier Driver','owner_operator'=>'Owner-Operator','company_driver'=>'Company Driver','leased_driver'=>'Leased Driver'] as $value=>$label): ?><option value="<?= e($value) ?>" <?= old('employment_type',$driver['employment_type']??'carrier_driver')===$value?'selected':'' ?>><?= e($label) ?></option><?php endforeach; ?></select></label>
<label><span>Email</span><input type="email" name="email" value="<?= e(old('email',$driver['email']??'')) ?>"></label>
<label><span>Phone</span><input name="phone" value="<?= e(old('phone',$driver['phone']??'')) ?>"></label>
<label><span>Status</span><select name="status"><?php foreach(['available','on_load','inactive'] as $status): ?><option value="<?= e($status) ?>" <?= old('status',$driver['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">Compliance</p><h3>License & Medical</h3></div></div><div class="form-grid three">
<label><span>License Number</span><input name="license_number" value="<?= e(old('license_number',$driver['license_number']??'')) ?>"></label>
<label><span>License Expiry</span><input type="date" name="license_expiry" value="<?= e(old('license_expiry',$driver['license_expiry']??'')) ?>"></label>
<label><span>Medical Card Expiry</span><input type="date" name="medical_card_expiry" value="<?= e(old('medical_card_expiry',$driver['medical_card_expiry']??'')) ?>"></label>
<label><span>Pay Type</span><select name="pay_type"><?php foreach(['percentage'=>'Percentage','per_mile'=>'Per Mile','fixed'=>'Fixed'] as $value=>$label): ?><option value="<?= e($value) ?>" <?= old('pay_type',$driver['pay_type']??'percentage')===$value?'selected':'' ?>><?= e($label) ?></option><?php endforeach; ?></select></label>
<label><span>Pay Rate</span><input type="number" step="0.01" name="rate" value="<?= e(old('rate',$driver['rate']??'0')) ?>"></label>
<label class="field-full"><span>Address</span><input name="address" value="<?= e(old('address',$driver['address']??'')) ?>"></label>
<label class="field-full"><span>Notes</span><textarea name="notes" rows="4"><?= e(old('notes',$driver['notes']??'')) ?></textarea></label>
</div></section>
<div class="form-actions sticky-form-actions"><button class="btn btn-primary" type="submit">Save Driver</button><a class="btn btn-light" href="<?= url('/drivers') ?>">Cancel</a></div>
</form>
