"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyGroupsMap = exports.buildGroupsMap = void 0;
const treeWalk_1 = require("./treeWalk.js");
const buildGroupsMap = (fields) => {
    const groups = { root: fields };
    (0, treeWalk_1.walkFields)(fields, (field) => {
        if (field.type === 'section') {
            groups[`section:${field.id}`] = field.fields;
        }
    });
    return groups;
};
exports.buildGroupsMap = buildGroupsMap;
const applyGroupsMap = (groups) => {
    const transform = (fields) => fields.map((field) => {
        if (field.type === 'section') {
            const childGroup = groups[`section:${field.id}`] ?? field.fields;
            return { ...field, fields: transform(childGroup) };
        }
        return field;
    });
    return transform(groups.root ?? []);
};
exports.applyGroupsMap = applyGroupsMap;
//# sourceMappingURL=fieldGroups.js.map
