<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-inbox me-2 text-primary"></i>Raise a Work Request</h5>
    <a href="<?= url('/WorkRequests') ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i>Back</a>
</div>

<p class="text-muted small">
    Use a request when you've noticed a problem but shouldn't (or can't) create a full Work Order.
    A PM will review and either convert it into a WO, or reject it with a note.
</p>

<div class="rs-card p-3">
<form method="post" action="<?= url('/WorkRequests/save') ?>">
    <input type="hidden" name="_csrf" value="<?= e($csrf) ?>">
    <div class="row g-2">
        <div class="col-md-8"><label class="form-label">Title *</label>
            <input type="text" class="form-control form-control-sm" name="title" required placeholder="e.g. Generator 2 making unusual noise">
        </div>
        <div class="col-md-2"><label class="form-label">Priority</label>
            <select name="priority" class="form-select form-select-sm">
                <?php foreach (\App\Models\WorkRequest::PRIORITIES as $p): ?>
                    <option value="<?= $p ?>" <?= $p === 'medium' ? 'selected' : '' ?>><?= $p ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="col-md-2"><label class="form-label">Code (optional)</label>
            <input type="text" class="form-control form-control-sm" name="code">
        </div>
        <div class="col-md-6"><label class="form-label">Asset</label>
            <select name="asset_id" class="form-select form-select-sm">
                <option value="">— none —</option>
                <?php foreach ($assets as $a): ?><option value="<?= (int) $a['asset_id'] ?>"><?= e($a['name']) ?></option><?php endforeach; ?>
            </select>
        </div>
        <div class="col-md-6"><label class="form-label">Site</label>
            <select name="site_id" class="form-select form-select-sm">
                <option value="">— none —</option>
                <?php foreach ($sites as $s): ?><option value="<?= (int) $s['site_id'] ?>"><?= e($s['name']) ?></option><?php endforeach; ?>
            </select>
        </div>
        <div class="col-12"><label class="form-label">Description</label>
            <textarea class="form-control form-control-sm" name="description" rows="4" placeholder="What did you observe? When? Any other context…"></textarea>
        </div>
    </div>
    <div class="mt-3">
        <button type="submit" class="btn btn-sm btn-primary"><i class="fas fa-paper-plane me-1"></i>Submit Request</button>
    </div>
</form>
</div>
