<?php $pageTitle = 'Add Maintenance'; ?>
<div class="panel form-panel">
    <div class="panel-header"><div><p class="eyebrow">Fleet</p><h2>Add Maintenance Record</h2></div></div>
    <form method="post" action="<?= url('/maintenance/store') ?>" class="form-grid">
        <?= csrf_field() ?>
        <label>
            <span>Truck</span>
            <select name="truck_id"><option value="">No truck</option><?php foreach ($trucks as $truck): ?><option value="<?= e((string) $truck['id']) ?>"><?= e($truck['unit_number']) ?></option><?php endforeach; ?></select>
        </label>
        <label>
            <span>Trailer</span>
            <select name="trailer_id"><option value="">No trailer</option><?php foreach ($trailers as $trailer): ?><option value="<?= e((string) $trailer['id']) ?>"><?= e($trailer['trailer_number']) ?></option><?php endforeach; ?></select>
        </label>
        <label><span>Service Type *</span><input name="service_type" value="<?= e(old('service_type')) ?>" placeholder="Oil Change, Inspection, Repair" required></label>
        <label><span>Service Date *</span><input type="date" name="service_date" value="<?= e(old('service_date', date('Y-m-d'))) ?>" required></label>
        <label><span>Next Service Date</span><input type="date" name="next_service_date" value="<?= e(old('next_service_date')) ?>"></label>
        <label><span>Mileage</span><input type="number" name="mileage" value="<?= e(old('mileage')) ?>"></label>
        <label><span>Cost</span><input type="number" step="0.01" name="cost" value="<?= e(old('cost', '0')) ?>"></label>
        <label><span>Status</span><select name="status"><option value="completed">Completed</option><option value="scheduled">Scheduled</option><option value="pending">Pending</option></select></label>
        <label class="span-2"><span>Notes</span><textarea name="notes" rows="4"><?= e(old('notes')) ?></textarea></label>
        <div class="form-actions span-2"><button class="btn btn-primary" type="submit">Save Record</button><a class="btn btn-light" href="<?= url('/maintenance') ?>">Cancel</a></div>
    </form>
</div>
