const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.cjs');
const require_normalizePath = require('../utils/normalizePath.cjs');
const require_build = require('../defaultValues/build.cjs');
const require_content = require('../defaultValues/content.cjs');
const require_dictionary = require('../defaultValues/dictionary.cjs');
const require_editor = require('../defaultValues/editor.cjs');
const require_internationalization = require('../defaultValues/internationalization.cjs');
const require_log = require('../defaultValues/log.cjs');
const require_routing = require('../defaultValues/routing.cjs');
let node_path = require("node:path");

//#region ../unmerged-dictionaries-entry/dist/esm/config/dist/esm/configFile/buildConfigurationFields.mjs
let storedConfiguration;
const buildInternationalizationFields = (customConfiguration) => ({
	locales: customConfiguration?.locales ?? require_internationalization.LOCALES,
	requiredLocales: customConfiguration?.requiredLocales ?? customConfiguration?.locales ?? require_internationalization.REQUIRED_LOCALES,
	strictMode: customConfiguration?.strictMode ?? require_internationalization.STRICT_MODE,
	defaultLocale: customConfiguration?.defaultLocale ?? require_internationalization.DEFAULT_LOCALE
});
const buildRoutingFields = (customConfiguration) => ({
	mode: customConfiguration?.mode ?? require_routing.ROUTING_MODE,
	storage: customConfiguration?.storage ?? require_routing.STORAGE,
	basePath: customConfiguration?.basePath ?? require_routing.BASE_PATH
});
const buildContentFields = (customConfiguration, baseDir) => {
	const notDerivedContentConfig = {
		fileExtensions: customConfiguration?.fileExtensions ?? require_content.FILE_EXTENSIONS,
		baseDir: customConfiguration?.baseDir ?? baseDir ?? process.cwd(),
		excludedPath: customConfiguration?.excludedPath ?? require_content.EXCLUDED_PATHS,
		watch: customConfiguration?.watch ?? require_content.WATCH,
		formatCommand: customConfiguration?.formatCommand
	};
	const optionalJoinBaseDir = (path) => {
		if ((0, node_path.isAbsolute)(path)) return path;
		return (0, node_path.join)(notDerivedContentConfig.baseDir, path);
	};
	const baseDirDerivedConfiguration = {
		contentDir: (customConfiguration?.contentDir ?? require_content.CONTENT_DIR).map(optionalJoinBaseDir),
		moduleAugmentationDir: optionalJoinBaseDir(customConfiguration?.moduleAugmentationDir ?? require_content.MODULE_AUGMENTATION_DIR),
		unmergedDictionariesDir: optionalJoinBaseDir(customConfiguration?.unmergedDictionariesDir ?? require_content.UNMERGED_DICTIONARIES_DIR),
		remoteDictionariesDir: optionalJoinBaseDir(customConfiguration?.remoteDictionariesDir ?? require_content.REMOTE_DICTIONARIES_DIR),
		dictionariesDir: optionalJoinBaseDir(customConfiguration?.dictionariesDir ?? require_content.DICTIONARIES_DIR),
		dynamicDictionariesDir: optionalJoinBaseDir(customConfiguration?.dynamicDictionariesDir ?? require_content.DYNAMIC_DICTIONARIES_DIR),
		fetchDictionariesDir: optionalJoinBaseDir(customConfiguration?.fetchDictionariesDir ?? require_content.FETCH_DICTIONARIES_DIR),
		typesDir: optionalJoinBaseDir(customConfiguration?.typesDir ?? require_content.TYPES_DIR),
		mainDir: optionalJoinBaseDir(customConfiguration?.mainDir ?? require_content.MAIN_DIR),
		configDir: optionalJoinBaseDir(customConfiguration?.configDir ?? require_content.CONFIG_DIR),
		cacheDir: optionalJoinBaseDir(customConfiguration?.cacheDir ?? require_content.CACHE_DIR)
	};
	const patternsConfiguration = {
		watchedFilesPattern: notDerivedContentConfig.fileExtensions.map((ext) => `/**/*${ext}`),
		watchedFilesPatternWithPath: notDerivedContentConfig.fileExtensions.flatMap((ext) => baseDirDerivedConfiguration.contentDir.map((contentDir) => `${require_normalizePath.normalizePath(contentDir)}/**/*${ext}`)),
		outputFilesPatternWithPath: `${require_normalizePath.normalizePath(baseDirDerivedConfiguration.dictionariesDir)}/**/*.json`
	};
	return {
		...notDerivedContentConfig,
		...baseDirDerivedConfiguration,
		...patternsConfiguration
	};
};
const buildEditorFields = (customConfiguration) => ({
	applicationURL: customConfiguration?.applicationURL ?? require_editor.APPLICATION_URL,
	editorURL: customConfiguration?.editorURL ?? require_editor.EDITOR_URL,
	cmsURL: customConfiguration?.cmsURL ?? require_editor.CMS_URL,
	backendURL: customConfiguration?.backendURL ?? require_editor.BACKEND_URL,
	port: customConfiguration?.port ?? require_editor.PORT,
	enabled: customConfiguration?.enabled ?? require_editor.IS_ENABLED,
	clientId: customConfiguration?.clientId ?? void 0,
	clientSecret: customConfiguration?.clientSecret ?? void 0,
	dictionaryPriorityStrategy: customConfiguration?.dictionaryPriorityStrategy ?? require_editor.DICTIONARY_PRIORITY_STRATEGY,
	liveSync: customConfiguration?.liveSync ?? require_editor.LIVE_SYNC,
	liveSyncPort: customConfiguration?.liveSyncPort ?? require_editor.LIVE_SYNC_PORT,
	liveSyncURL: customConfiguration?.liveSyncURL ?? `http://localhost:${customConfiguration?.liveSyncPort ?? require_editor.LIVE_SYNC_PORT}`
});
const buildLogFields = (customConfiguration, logFunctions) => ({
	mode: customConfiguration?.mode ?? require_log.MODE,
	prefix: customConfiguration?.prefix ?? require_log.PREFIX,
	error: logFunctions?.error,
	log: logFunctions?.log,
	info: logFunctions?.info,
	warn: logFunctions?.warn
});
const buildAiFields = (customConfiguration) => ({
	provider: customConfiguration?.provider,
	apiKey: customConfiguration?.apiKey,
	model: customConfiguration?.model,
	temperature: customConfiguration?.temperature,
	applicationContext: customConfiguration?.applicationContext
});
const buildBuildFields = (customConfiguration) => ({
	optimize: customConfiguration?.optimize ?? require_build.OPTIMIZE,
	importMode: customConfiguration?.importMode ?? require_build.IMPORT_MODE,
	traversePattern: customConfiguration?.traversePattern ?? require_build.TRAVERSE_PATTERN,
	outputFormat: customConfiguration?.outputFormat ?? require_build.OUTPUT_FORMAT,
	cache: customConfiguration?.cache ?? require_build.CACHE,
	require: customConfiguration?.require
});
const buildDictionaryFields = (customConfiguration) => ({ fill: customConfiguration?.fill ?? require_dictionary.FILL });
/**
* Build the configuration fields by merging the default values with the custom configuration
*/
const buildConfigurationFields = (customConfiguration, baseDir, logFunctions) => {
	storedConfiguration = {
		internationalization: buildInternationalizationFields(customConfiguration?.internationalization),
		routing: buildRoutingFields(customConfiguration?.routing),
		content: buildContentFields(customConfiguration?.content, baseDir),
		editor: buildEditorFields(customConfiguration?.editor),
		log: buildLogFields(customConfiguration?.log, logFunctions),
		ai: buildAiFields(customConfiguration?.ai),
		build: buildBuildFields(customConfiguration?.build),
		dictionary: buildDictionaryFields(customConfiguration?.dictionary),
		plugins: customConfiguration?.plugins
	};
	return storedConfiguration;
};

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