<?php $target = $target ?? []; ?>
<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', $target['sales_rep_id'] ?? '') === (string) $r['id'] ? 'selected' : '' ?>>
                    <?= esc($r['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Territory</label>
        <select name="territory_id" class="form-select">
            <option value="">— None —</option>
            <?php foreach ($territories as $t): ?>
                <option value="<?= $t['id'] ?>" <?= (string) old('territory_id', $target['territory_id'] ?? '') === (string) $t['id'] ? 'selected' : '' ?>>
                    <?= esc($t['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', $target['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', $target['period_end'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Target Amount <span class="text-danger">*</span></label>
        <input type="number" name="target_amount" class="form-control" step="0.01" min="0" value="<?= esc(old('target_amount', $target['target_amount'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Achieved Amount</label>
        <input type="number" name="achieved_amount" class="form-control" step="0.01" min="0" value="<?= esc(old('achieved_amount', $target['achieved_amount'] ?? '0')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['active', 'completed', 'cancelled'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $target['status'] ?? 'active') === $s ? 'selected' : '' ?>><?= ucfirst($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', $target['notes'] ?? '')) ?></textarea>
    </div>
</div>
