<?php $batch = $batch ?? []; ?>
<div class="enterprise-settings-fields">
    <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', $batch['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">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', $batch['warehouse_id'] ?? '') === (string) $w['id'] ? 'selected' : '' ?>>
                    <?= esc($w['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Batch Number <span class="text-danger">*</span></label>
        <input type="text" name="batch_number" class="form-control" maxlength="80" value="<?= esc(old('batch_number', $batch['batch_number'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Quantity <span class="text-danger">*</span></label>
        <input type="number" step="0.001" min="0" name="quantity" class="form-control" value="<?= esc(old('quantity', $batch['quantity'] ?? '0')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Manufactured Date</label>
        <input type="date" name="manufactured_date" class="form-control" value="<?= esc(old('manufactured_date', $batch['manufactured_date'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Expiry Date</label>
        <input type="date" name="expiry_date" class="form-control" value="<?= esc(old('expiry_date', $batch['expiry_date'] ?? '')) ?>">
    </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 (['active', 'expired', 'depleted'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $batch['status'] ?? 'active') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field enterprise-field--full">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $batch['notes'] ?? '')) ?></textarea>
    </div>
</div>
