import { NodeType } from "../../types/dist/esm/nodeType.mjs";
import { getTranslation } from "../getTranslation.mjs";

//#region ../chokidar/dist/esm/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 === NodeType.Translation,
	transform: (node, props, deepTransformNode) => {
		const result = structuredClone(node[NodeType.Translation]);
		for (const key in result) {
			const childProps = {
				...props,
				children: result[key],
				keyPath: [...props.keyPath, {
					type: NodeType.Translation,
					key
				}]
			};
			result[key] = deepTransformNode(result[key], childProps);
		}
		return getTranslation(result, locale, fallback);
	}
});

//#endregion
export { translationPlugin };
//# sourceMappingURL=plugins.mjs.map