<?php $commission = $commission ?? []; ?>
<div class="enterprise-settings-fields enterprise-settings-fields--single">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Sales Representative <span class="text-danger">*</span></label>
        <select name="sales_rep_id" class="form-select" required>
            <option value="">— Select —</option>
            <?php foreach ($reps as $r): ?>
                <option value="<?= $r['id'] ?>" <?= (string) old('sales_rep_id', $commission['sales_rep_id'] ?? '') === (string) $r['id'] ? 'selected' : '' ?>>
                    <?= esc($r['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Period Start <span class="text-danger">*</span></label>
        <input type="date" name="period_start" class="form-control" value="<?= esc(old('period_start', $commission['period_start'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Period End <span class="text-danger">*</span></label>
        <input type="date" name="period_end" class="form-control" value="<?= esc(old('period_end', $commission['period_end'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Base Amount <span class="text-danger">*</span></label>
        <input type="number" name="base_amount" class="form-control" step="0.01" min="0" value="<?= esc(old('base_amount', $commission['base_amount'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Rate % <span class="text-danger">*</span></label>
        <input type="number" name="rate_percent" class="form-control" step="0.01" min="0" value="<?= esc(old('rate_percent', $commission['rate_percent'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Commission Amount</label>
        <input type="number" name="commission_amount" class="form-control" step="0.01" min="0" placeholder="Auto-calculated if blank"
               value="<?= esc(old('commission_amount', $commission['commission_amount'] ?? '')) ?>">
        <p class="form-text small text-muted mb-0">Leave blank to compute as base × rate ÷ 100.</p>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $commission['notes'] ?? '')) ?></textarea>
    </div>
</div>
