<?php $rule = $rule ?? []; ?>
<div class="enterprise-settings-fields enterprise-settings-fields--single">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Rule Name <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control" value="<?= esc(old('name', $rule['name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Lead Source</label>
        <select name="lead_source_id" class="form-select">
            <option value="">All sources</option>
            <?php foreach ($sources as $s): ?>
                <option value="<?= $s['id'] ?>" <?= (string) old('lead_source_id', $rule['lead_source_id'] ?? '') === (string) $s['id'] ? 'selected' : '' ?>>
                    <?= esc($s['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
        <div class="form-text">Leave blank to match any lead source.</div>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Assign To <span class="text-danger">*</span></label>
        <select name="assign_to_user_id" class="form-select" required>
            <option value="">— Select user —</option>
            <?php foreach ($users as $u): ?>
                <option value="<?= $u->id ?>" <?= (string) old('assign_to_user_id', $rule['assign_to_user_id'] ?? '') === (string) $u->id ? 'selected' : '' ?>>
                    <?= esc($u->getFullName()) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Priority</label>
        <input type="number" name="priority" class="form-control" min="0" value="<?= esc(old('priority', $rule['priority'] ?? 0)) ?>">
        <div class="form-text">Lower numbers are evaluated first.</div>
    </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', $rule['status'] ?? 'active') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
</div>
