<?php $rep = $rep ?? []; ?>
<div class="enterprise-settings-fields enterprise-settings-fields--single">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Name <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control" value="<?= esc(old('name', $rep['name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Code</label>
        <input type="text" name="code" class="form-control text-uppercase" maxlength="30" value="<?= esc(old('code', $rep['code'] ?? '')) ?>">
    </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', $rep['territory_id'] ?? '') === (string) $t['id'] ? 'selected' : '' ?>>
                    <?= esc($t['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Email</label>
        <input type="email" name="email" class="form-control" value="<?= esc(old('email', $rep['email'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Phone</label>
        <input type="text" name="phone" class="form-control" value="<?= esc(old('phone', $rep['phone'] ?? '')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['active', 'inactive'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $rep['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', $rep['notes'] ?? '')) ?></textarea>
    </div>
</div>
