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

//#region ../chokidar/dist/esm/core/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs
const filterTranslationsPlugin = (locales) => ({
	id: "filter-translations-plugin",
	canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
	transform: (node, props, deepTransformNode$1) => {
		const translationMap = node.translation;
		const filteredTranslationMap = Object.fromEntries(Object.entries(translationMap).filter(([key]) => locales.includes(key)));
		return {
			...node,
			translation: deepTransformNode$1(filteredTranslationMap, {
				...props,
				keyPath: [...props.keyPath, {
					type: NodeType.Object,
					key: NodeType.Translation
				}]
			})
		};
	}
});
const getFilteredLocalesContent = (node, locales, nodeProps) => {
	const plugins = [filterTranslationsPlugin(Array.isArray(locales) ? locales : [locales]), ...nodeProps.plugins ?? []];
	return deepTransformNode(node, {
		...nodeProps,
		plugins
	});
};
const getFilteredLocalesDictionary = (dictionary, locale) => {
	const localesArray = Array.isArray(locale) ? locale : [locale];
	return {
		...dictionary,
		content: getFilteredLocalesContent(dictionary.content, localesArray, {
			dictionaryKey: dictionary.key,
			keyPath: []
		})
	};
};

//#endregion
export { getFilteredLocalesDictionary };
//# sourceMappingURL=getFilteredLocalesContent.mjs.map