export const walkFields = (fields, visit) => {
    for (const field of fields) {
        visit(field);
        if (field.type === 'section') {
            walkFields(field.fields, visit);
        }
    }
};
export const findField = (fields, predicate) => {
    for (const field of fields) {
        if (predicate(field))
            return field;
        if (field.type === 'section') {
            const nested = findField(field.fields, predicate);
            if (nested)
                return nested;
        }
    }
    return null;
};
export const transformAtId = (fields, id, handler, parent = null) => {
    const index = fields.findIndex((field) => field.id === id);
    if (index !== -1) {
        return handler(fields, index, parent);
    }
    for (let i = 0; i < fields.length; i += 1) {
        const field = fields[i];
        if (field.type === 'section') {
            const result = transformAtId(field.fields, id, handler, field);
            if (result !== null) {
                const next = [...fields];
                next[i] = { ...field, fields: result };
                return next;
            }
        }
    }
    return null;
};
//# sourceMappingURL=treeWalk.js.map
