const require_fill_formatAutoFilledFilePath = require('./formatAutoFilledFilePath.cjs');

//#region src/fill/formatFillData.ts
const formatFillData = (autoFillField, localeList, filePath, dictionaryKey, configuration) => {
	const outputContentDeclarationFile = [];
	const baseDir = configuration.content.baseDir;
	if (!autoFillField) return outputContentDeclarationFile;
	if (typeof autoFillField === "string") {
		if (autoFillField.includes("{{locale}}")) {
			const output = localeList.map((locale) => {
				const formattedFilePath = require_fill_formatAutoFilledFilePath.formatAutoFilledFilePath(autoFillField, dictionaryKey, filePath, baseDir, locale);
				return {
					localeList: [locale],
					filePath: formattedFilePath,
					isPerLocale: true
				};
			});
			outputContentDeclarationFile.push(...output);
		} else {
			const formattedFilePath = require_fill_formatAutoFilledFilePath.formatAutoFilledFilePath(autoFillField, dictionaryKey, filePath, baseDir);
			outputContentDeclarationFile.push({
				localeList,
				filePath: formattedFilePath,
				isPerLocale: false
			});
		}
		return outputContentDeclarationFile;
	}
	if (typeof autoFillField === "object") {
		const groupedByFilePath = Object.keys(autoFillField).filter((locale) => typeof autoFillField[locale] === "string").filter((locale) => Boolean(autoFillField[locale])).map((locale) => {
			const formattedFilePath = require_fill_formatAutoFilledFilePath.formatAutoFilledFilePath(autoFillField[locale], dictionaryKey, filePath, baseDir, locale);
			return {
				localeList: [locale],
				filePath: formattedFilePath,
				isPerLocale: true
			};
		}).reduce((acc, curr) => {
			const existing = acc.find((item) => item.filePath === curr.filePath);
			if (existing) existing.localeList.push(...curr.localeList);
			else acc.push(curr);
			return acc;
		}, []);
		outputContentDeclarationFile.push(...groupedByFilePath);
	}
	return outputContentDeclarationFile;
};

//#endregion
exports.formatFillData = formatFillData;
//# sourceMappingURL=formatFillData.cjs.map