import { NodeType } from "../types/dist/esm/nodeType.mjs";
import { deepTransformNode } from "../interpreter/getContent/deepTransform.mjs";
import { built_default } from "../config/dist/esm/built.mjs";

//#region ../@intlayer/cli/dist/esm/core/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
const checkMissingLocalesPlugin = (locales, onMissingLocale) => ({
	id: "check-missing-locales-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
	transform: (node, props, deepTransformNode$1) => {
		for (const locale of locales) if (!node[NodeType.Translation][locale]) onMissingLocale(locale);
		const translations = node[NodeType.Translation];
		for (const key in translations) {
			const child = translations[key];
			deepTransformNode$1(child, {
				...props,
				children: child
			});
		}
		return node;
	}
});
/**
* Return the content of a node with only the translation plugin.
*
* @param node The node to transform.
* @param locales The locales to check for missing translations.
*/
const getMissingLocalesContent = (node, locales = built_default?.internationalization?.locales, nodeProps) => {
	const missingLocales = /* @__PURE__ */ new Set();
	const plugins = [checkMissingLocalesPlugin(locales, (locale) => missingLocales.add(locale)), ...nodeProps.plugins ?? []];
	deepTransformNode(node, {
		...nodeProps,
		plugins
	});
	return Array.from(missingLocales);
};
const getMissingLocalesContentFromDictionary = (dictionary, locales = built_default?.internationalization?.locales) => getMissingLocalesContent(dictionary.content, locales, {
	dictionaryKey: dictionary.key,
	keyPath: []
});

//#endregion
export { getMissingLocalesContentFromDictionary };
//# sourceMappingURL=getMissingLocalesContent.mjs.map