const require_getTranslation = require('../getTranslation.cjs');
const require_nodeType = require('../../types/dist/esm/nodeType.cjs');
const require_getCondition = require('../getCondition.cjs');
const require_getEnumeration = require('../getEnumeration.cjs');
const require_getInsertion = require('../getInsertion.cjs');
const require_getNesting = require('../getNesting.cjs');

//#region ../react-intlayer/dist/esm/@intlayer/core/dist/esm/interpreter/getContent/plugins.mjs
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
const translationPlugin = (locale, fallback) => ({
	id: "translation-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === require_nodeType.NodeType.Translation,
	transform: (node, props, deepTransformNode) => {
		const result = structuredClone(node[require_nodeType.NodeType.Translation]);
		for (const key in result) {
			const childProps = {
				...props,
				children: result[key],
				keyPath: [...props.keyPath, {
					type: require_nodeType.NodeType.Translation,
					key
				}]
			};
			result[key] = deepTransformNode(result[key], childProps);
		}
		return require_getTranslation.getTranslation(result, locale, fallback);
	}
});
/** Enumeration plugin. Replaces node with a function that takes quantity => string. */
const enumerationPlugin = {
	id: "enumeration-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === require_nodeType.NodeType.Enumeration,
	transform: (node, props, deepTransformNode) => {
		const result = structuredClone(node[require_nodeType.NodeType.Enumeration]);
		for (const key in result) {
			const child = result[key];
			result[key] = deepTransformNode(child, {
				...props,
				children: child,
				keyPath: [...props.keyPath, {
					type: require_nodeType.NodeType.Enumeration,
					key
				}]
			});
		}
		return (quantity) => require_getEnumeration.getEnumeration(result, quantity);
	}
};
/** Condition plugin. Replaces node with a function that takes boolean => string. */
const conditionPlugin = {
	id: "condition-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === require_nodeType.NodeType.Condition,
	transform: (node, props, deepTransformNode) => {
		const result = structuredClone(node[require_nodeType.NodeType.Condition]);
		for (const key in result) {
			const child = result[key];
			result[key] = deepTransformNode(child, {
				...props,
				children: child,
				keyPath: [...props.keyPath, {
					type: require_nodeType.NodeType.Condition,
					key
				}]
			});
		}
		return (value) => require_getCondition.getCondition(result, value);
	}
};
const insertionPlugin = {
	id: "insertion-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === require_nodeType.NodeType.Insertion,
	transform: (node, props, deepTransformNode) => {
		const newKeyPath = [...props.keyPath, { type: require_nodeType.NodeType.Insertion }];
		const children = node[require_nodeType.NodeType.Insertion];
		/** Insertion string plugin. Replaces string node with a component that render the insertion. */
		const insertionStringPlugin = {
			id: "insertion-string-plugin",
			canHandle: (node$1) => typeof node$1 === "string",
			transform: (node$1, subProps, deepTransformNode$1) => {
				const transformedResult = deepTransformNode$1(node$1, {
					...subProps,
					children: node$1,
					plugins: [...(props.plugins ?? []).filter((plugin) => plugin.id !== "intlayer-node-plugin")]
				});
				return (values) => {
					const children$1 = require_getInsertion.getInsertion(transformedResult, values);
					return deepTransformNode$1(children$1, {
						...subProps,
						plugins: props.plugins,
						children: children$1
					});
				};
			}
		};
		return deepTransformNode(children, {
			...props,
			children,
			keyPath: newKeyPath,
			plugins: [insertionStringPlugin, ...props.plugins ?? []]
		});
	}
};
/** Nested plugin. Replaces node with the result of `getNesting`. */
const nestedPlugin = {
	id: "nested-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === require_nodeType.NodeType.Nested,
	transform: (node, props) => require_getNesting.getNesting(node.nested.dictionaryKey, node.nested.path, props)
};
/** File plugin. Replaces node with the result of `getNesting`. */
const filePlugin = {
	id: "file-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === require_nodeType.NodeType.File,
	transform: (node, props, deepTransform) => deepTransform(node.content, {
		...props,
		children: node.content
	})
};

//#endregion
exports.conditionPlugin = conditionPlugin;
exports.enumerationPlugin = enumerationPlugin;
exports.filePlugin = filePlugin;
exports.insertionPlugin = insertionPlugin;
exports.nestedPlugin = nestedPlugin;
exports.translationPlugin = translationPlugin;
//# sourceMappingURL=plugins.cjs.map