<?php $serial = $serial ?? []; ?>
<div class="enterprise-settings-fields enterprise-settings-fields--single">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Product <span class="text-danger">*</span></label>
        <select name="product_id" class="form-select" required>
            <option value="">Select product</option>
            <?php foreach ($products as $p): ?>
                <option value="<?= (int) $p['id'] ?>" <?= (int) old('product_id', $serial['product_id'] ?? 0) === (int) $p['id'] ? 'selected' : '' ?>>
                    <?= esc($p['name']) ?> (<?= esc($p['sku']) ?>)
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Serial Number <span class="text-danger">*</span></label>
        <input type="text" name="serial_number" class="form-control" maxlength="100" value="<?= esc(old('serial_number', $serial['serial_number'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Warehouse</label>
        <select name="warehouse_id" class="form-select">
            <option value="">None</option>
            <?php foreach ($warehouses as $w): ?>
                <option value="<?= (int) $w['id'] ?>" <?= (string) old('warehouse_id', $serial['warehouse_id'] ?? '') === (string) $w['id'] ? 'selected' : '' ?>>
                    <?= esc($w['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status <span class="text-danger">*</span></label>
        <select name="status" class="form-select" required>
            <?php foreach (['in_stock', 'allocated', 'sold', 'scrapped'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $serial['status'] ?? 'in_stock') === $s ? 'selected' : '' ?>><?= ucwords(str_replace('_', ' ', $s)) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $serial['notes'] ?? '')) ?></textarea>
    </div>
</div>
