const require_nodeType = require('../../types/dist/esm/nodeType.cjs');

//#region ../@intlayer/cli/dist/esm/chokidar/dist/esm/core/dist/esm/interpreter/getContent/deepTransform.mjs
/**
* Recursively traverses a node (object/array/primitive).
* Applies the *first* plugin that can transform a node, then stops descending further.
* If no plugin transforms it, it recurses into its children.
*/
const deepTransformNode = (node, props) => {
	for (const plugin of props.plugins ?? []) if (plugin.canHandle(node)) return plugin.transform(node, props, (node$1, props$1) => deepTransformNode(node$1, props$1));
	if (node === null || typeof node !== "object") return node;
	if (Array.isArray(node)) return node.map((child, index) => {
		return deepTransformNode(child, {
			...props,
			children: child,
			keyPath: [...props.keyPath, {
				type: require_nodeType.NodeType.Array,
				key: index
			}]
		});
	});
	const result = {};
	for (const key in node) {
		const childProps = {
			...props,
			children: node[key],
			keyPath: [...props.keyPath, {
				type: require_nodeType.NodeType.Object,
				key
			}]
		};
		result[key] = deepTransformNode(node[key], childProps);
	}
	return result;
};

//#endregion
exports.deepTransformNode = deepTransformNode;
//# sourceMappingURL=deepTransform.cjs.map