<?php $structure = $structure ?? []; ?>
<div class="enterprise-settings-fields">
    <?php if (empty($employee) && ! empty($employees)): ?>
        <div class="enterprise-field enterprise-settings-fields--single" style="grid-column:1/-1;">
            <label class="enterprise-field-label">Employee <span class="text-danger">*</span></label>
            <select name="employee_id" class="form-select" required>
                <option value="">— Select —</option>
                <?php foreach ($employees as $e): ?>
                    <option value="<?= $e['id'] ?>" <?= (string) old('employee_id') === (string) $e['id'] ? 'selected' : '' ?>>
                        <?= esc($e['full_name']) ?> (<?= esc($e['employee_number']) ?>)
                    </option>
                <?php endforeach; ?>
            </select>
        </div>
    <?php elseif (! empty($employee)): ?>
        <div class="enterprise-field enterprise-settings-fields--single" style="grid-column:1/-1;">
            <label class="enterprise-field-label">Employee</label>
            <input type="text" class="form-control" value="<?= esc($employee['full_name'] . ' (' . $employee['employee_number'] . ')') ?>" readonly>
        </div>
    <?php endif; ?>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Effective From <span class="text-danger">*</span></label>
        <input type="date" name="effective_from" class="form-control" required
               value="<?= esc(old('effective_from', $structure['effective_from'] ?? date('Y-m-d'))) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Payment Method</label>
        <select name="payment_method" class="form-select">
            <?php foreach (['bank', 'cash'] as $m): ?>
                <option value="<?= $m ?>" <?= old('payment_method', $structure['payment_method'] ?? 'bank') === $m ? 'selected' : '' ?>><?= ucfirst($m) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Basic Salary (BHD) <span class="text-danger">*</span></label>
        <input type="number" name="basic_salary" class="form-control" step="0.001" min="0" required
               value="<?= esc(old('basic_salary', $structure['basic_salary'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Social Allowance (BHD)</label>
        <input type="number" name="social_allowance" class="form-control" step="0.001" min="0"
               value="<?= esc(old('social_allowance', $structure['social_allowance'] ?? 0)) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Housing Allowance (BHD)</label>
        <input type="number" name="housing_allowance" class="form-control" step="0.001" min="0"
               value="<?= esc(old('housing_allowance', $structure['housing_allowance'] ?? 0)) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Transport Allowance (BHD)</label>
        <input type="number" name="transport_allowance" class="form-control" step="0.001" min="0"
               value="<?= esc(old('transport_allowance', $structure['transport_allowance'] ?? 0)) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Other Allowances (BHD)</label>
        <input type="number" name="other_allowances" class="form-control" step="0.001" min="0"
               value="<?= esc(old('other_allowances', $structure['other_allowances'] ?? 0)) ?>">
    </div>
    <div class="enterprise-field enterprise-settings-fields--single" style="grid-column:1/-1;">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="2"><?= esc(old('notes', $structure['notes'] ?? '')) ?></textarea>
    </div>
</div>
