/**
 * Builds a reverse mapping from validation rule IDs to field info.
 *
 * Walks sections -> groups -> fields, reads `validation_rules` arrays,
 * and produces a Record<rule_id, { field_id, field_label }>.
 *
 * Global validation IDs map to { field_id: '__document', field_label: 'Document' }.
 */
/**
 * Recursively walk fields and collect validation_rules mappings.
 */
function walk_fields(fields, map) {
    for (const field of fields) {
        if (field.validation_rules) {
            for (const rule_id of field.validation_rules) {
                map[rule_id] = {
                    field_id: field.id,
                    field_label: field.label ?? field.id,
                };
            }
        }
        if (field.fields) {
            walk_fields(field.fields, map);
        }
    }
}
/**
 * Build a reverse map from validation rule IDs to the fields/groups that reference them.
 *
 * @param sections - Form sections containing groups and fields
 * @param global_validations - Optional array of rule IDs that apply document-wide
 * @returns Record mapping rule_id to { field_id, field_label }
 */
export function build_rule_field_map(sections, global_validations) {
    const map = {};
    // Walk sections -> groups -> fields
    for (const section of sections) {
        if (section.groups) {
            walk_fields(section.groups, map);
        }
    }
    // Add global validations
    if (global_validations) {
        for (const rule_id of global_validations) {
            map[rule_id] = {
                field_id: '__document',
                field_label: 'Document',
            };
        }
    }
    return map;
}
//# sourceMappingURL=build_rule_field_map.js.map