import { formatPath } from "./utils/formatter.mjs";
import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
import { createTypes } from "./createType/createType.mjs";
import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
import { listDictionaries } from "./listDictionariesPath.mjs";
import { getAppLogger } from "@intlayer/config";

//#region ../chokidar/dist/esm/handleUnlinkedContentDeclarationFile.mjs
const handleUnlinkedContentDeclarationFile = async (filePath, config) => {
	const appLogger = getAppLogger(config);
	appLogger(`Unlinked detected: ${formatPath(filePath)}`, { isVerbose: true });
	const dictionariesOutput = await buildDictionary(await loadLocalDictionaries(await listDictionaries(config), config), config);
	await createTypes(Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath), config);
	await createDictionaryEntryPoint();
	appLogger("Dictionaries rebuilt", { isVerbose: true });
	await createModuleAugmentation(config);
	appLogger("Module augmentation built", { isVerbose: true });
	for await (const plugin of config.plugins ?? []) {
		const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;
		await plugin.afterBuild?.({
			dictionaries: {
				unmergedDictionaries,
				mergedDictionaries
			},
			configuration: config
		});
	}
};

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