import { a as normalizePluginsConfig, n as createPluginActivationSource } from "./config-state-Bu2SAEXj.js";
import { n as withBundledPluginEnablementCompat, r as withBundledPluginVitestCompat, t as withBundledPluginAllowlistCompat } from "./bundled-compat-DfA-VDij.js";
import { t as applyPluginAutoEnable } from "./plugin-auto-enable-CGAF5F6F.js";
//#region src/plugins/activation-context.ts
function withActivatedPluginIds(params) {
	if (params.pluginIds.length === 0) return params.config;
	const allow = new Set(params.config?.plugins?.allow ?? []);
	const entries = { ...params.config?.plugins?.entries };
	for (const pluginId of params.pluginIds) {
		const normalized = pluginId.trim();
		if (!normalized) continue;
		allow.add(normalized);
		entries[normalized] = {
			...entries[normalized],
			enabled: true
		};
	}
	const forcePluginsEnabled = params.config?.plugins?.enabled === false;
	return {
		...params.config,
		plugins: {
			...params.config?.plugins,
			...forcePluginsEnabled ? { enabled: true } : {},
			...allow.size > 0 ? { allow: [...allow] } : {},
			entries
		}
	};
}
function applyPluginCompatibilityOverrides(params) {
	const allowlistCompat = params.compat?.allowlistPluginIds?.length ? withBundledPluginAllowlistCompat({
		config: params.config,
		pluginIds: params.compat.allowlistPluginIds
	}) : params.config;
	const enablementCompat = params.compat?.enablementPluginIds?.length ? withBundledPluginEnablementCompat({
		config: allowlistCompat,
		pluginIds: params.compat.enablementPluginIds
	}) : allowlistCompat;
	return params.compat?.vitestPluginIds?.length ? withBundledPluginVitestCompat({
		config: enablementCompat,
		pluginIds: params.compat.vitestPluginIds,
		env: params.env
	}) : enablementCompat;
}
function resolvePluginActivationSnapshot(params) {
	const env = params.env ?? process.env;
	const rawConfig = params.rawConfig ?? params.resolvedConfig;
	let resolvedConfig = params.resolvedConfig ?? params.rawConfig;
	let autoEnabledReasons = params.autoEnabledReasons;
	if (params.applyAutoEnable && rawConfig !== void 0) {
		const autoEnabled = applyPluginAutoEnable({
			config: rawConfig,
			env
		});
		resolvedConfig = autoEnabled.config;
		autoEnabledReasons = autoEnabled.autoEnabledReasons;
	}
	return {
		rawConfig,
		config: resolvedConfig,
		normalized: normalizePluginsConfig(resolvedConfig?.plugins),
		activationSourceConfig: rawConfig,
		activationSource: createPluginActivationSource({ config: rawConfig }),
		autoEnabledReasons: autoEnabledReasons ?? {}
	};
}
function resolvePluginActivationInputs(params) {
	const env = params.env ?? process.env;
	const snapshot = resolvePluginActivationSnapshot({
		rawConfig: params.rawConfig,
		resolvedConfig: params.resolvedConfig,
		autoEnabledReasons: params.autoEnabledReasons,
		env,
		applyAutoEnable: params.applyAutoEnable
	});
	const config = applyPluginCompatibilityOverrides({
		config: snapshot.config,
		compat: params.compat,
		env
	});
	return {
		rawConfig: snapshot.rawConfig,
		config,
		normalized: normalizePluginsConfig(config?.plugins),
		activationSourceConfig: snapshot.activationSourceConfig,
		activationSource: snapshot.activationSource,
		autoEnabledReasons: snapshot.autoEnabledReasons
	};
}
function resolveBundledPluginCompatibleActivationInputs(params) {
	const snapshot = resolvePluginActivationSnapshot({
		rawConfig: params.rawConfig,
		resolvedConfig: params.resolvedConfig,
		autoEnabledReasons: params.autoEnabledReasons,
		env: params.env,
		applyAutoEnable: params.applyAutoEnable
	});
	const allowlistCompatEnabled = params.compatMode.allowlist === true;
	const compatPluginIds = allowlistCompatEnabled || params.compatMode.enablement === "always" || params.compatMode.enablement === "allowlist" && allowlistCompatEnabled || params.compatMode.vitest === true ? params.resolveCompatPluginIds({
		config: snapshot.config,
		workspaceDir: params.workspaceDir,
		env: params.env,
		onlyPluginIds: params.onlyPluginIds
	}) : [];
	return {
		...resolvePluginActivationInputs({
			rawConfig: snapshot.rawConfig,
			resolvedConfig: snapshot.config,
			autoEnabledReasons: snapshot.autoEnabledReasons,
			env: params.env,
			compat: {
				allowlistPluginIds: allowlistCompatEnabled ? compatPluginIds : void 0,
				enablementPluginIds: params.compatMode.enablement === "always" || params.compatMode.enablement === "allowlist" && allowlistCompatEnabled ? compatPluginIds : void 0,
				vitestPluginIds: params.compatMode.vitest ? compatPluginIds : void 0
			}
		}),
		compatPluginIds
	};
}
//#endregion
export { withActivatedPluginIds as n, resolveBundledPluginCompatibleActivationInputs as t };
