const require_logger = require('../../../../../../config/dist/esm/logger.cjs');
const require_formatter = require('./utils/formatter.cjs');
const require_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
const require_getBuiltDictionariesPath = require('./createDictionaryEntryPoint/getBuiltDictionariesPath.cjs');
const require_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
const require_createModuleAugmentation = require('./createType/createModuleAugmentation.cjs');
const require_createType = require('./createType/createType.cjs');
const require_loadLocalDictionaries = require('./loadDictionaries/loadLocalDictionaries.cjs');

//#region ../@intlayer/cli/dist/esm/chokidar/dist/esm/handleContentDeclarationFileChange.mjs
const handleContentDeclarationFileChange = async (filePath, config) => {
	const appLogger = require_logger.getAppLogger(config);
	appLogger(`Change detected: ${require_formatter.formatPath(filePath)}`, { isVerbose: true });
	const dictionariesOutput = await require_buildIntlayerDictionary.buildDictionary(await require_loadLocalDictionaries.loadLocalDictionaries(filePath, config), config);
	const updatedDictionariesPaths = Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath);
	const allDictionariesPaths = await require_getBuiltDictionariesPath.getBuiltDictionariesPath(config);
	require_createType.createTypes(updatedDictionariesPaths, config);
	appLogger("TypeScript types built", { isVerbose: true });
	if (updatedDictionariesPaths.some((updatedDictionaryPath) => !allDictionariesPaths.includes(updatedDictionaryPath))) {
		await require_createDictionaryEntryPoint.createDictionaryEntryPoint(config);
		appLogger("Dictionary list built", { isVerbose: true });
	}
	require_createModuleAugmentation.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
exports.handleContentDeclarationFileChange = handleContentDeclarationFileChange;
//# sourceMappingURL=handleContentDeclarationFileChange.cjs.map