import { s as resolveInstalledPluginIndexStorePath } from "./installed-plugin-index-record-reader-e7XHE5Hd.js";
import { a as refreshPersistedInstalledPluginIndex, o as refreshPersistedInstalledPluginIndexSync } from "./installed-plugin-index-store-BnP9CO7m.js";
import { n as recordPluginInstall } from "./installs-D0ay9p2v.js";
//#region src/plugins/installed-plugin-index-records.ts
/** Config path for legacy plugin install records kept for migration/doctor flows. */
const PLUGIN_INSTALLS_CONFIG_PATH = ["plugins", "installs"];
/** Resolves the installed plugin index record store path. */
function resolveInstalledPluginIndexRecordsStorePath(options = {}) {
	return resolveInstalledPluginIndexStorePath(options);
}
/** Refreshes persisted installed plugin index records asynchronously. */
async function writePersistedInstalledPluginIndexInstallRecords(records, options = {}) {
	await refreshPersistedInstalledPluginIndex({
		...options,
		reason: "source-changed",
		installRecords: records
	});
	return resolveInstalledPluginIndexRecordsStorePath(options);
}
/** Refreshes persisted installed plugin index records synchronously. */
function writePersistedInstalledPluginIndexInstallRecordsSync(records, options = {}) {
	refreshPersistedInstalledPluginIndexSync({
		...options,
		reason: "source-changed",
		installRecords: records
	});
	return resolveInstalledPluginIndexRecordsStorePath(options);
}
/** Returns config with plugin install records attached at the canonical config path. */
function withPluginInstallRecords(config, records) {
	return {
		...config,
		plugins: {
			...config.plugins,
			installs: records
		}
	};
}
/** Returns config with legacy plugin install records removed. */
function withoutPluginInstallRecords(config, options = {}) {
	if (!config.plugins?.installs) return config;
	const { installs: _installs, ...plugins } = config.plugins;
	if (Object.keys(plugins).length === 0) {
		if (options.preserveEmptyPlugins) return {
			...config,
			plugins: {}
		};
		const { plugins: _plugins, ...rest } = config;
		return rest;
	}
	return {
		...config,
		plugins
	};
}
/** Applies one install update to an in-memory install record map. */
function recordPluginInstallInRecords(records, update) {
	return recordPluginInstall({ plugins: { installs: records } }, update).plugins?.installs ?? {};
}
/** Removes one plugin install record from an in-memory record map. */
function removePluginInstallRecordFromRecords(records, pluginId) {
	const { [pluginId]: _removed, ...rest } = records;
	return rest;
}
//#endregion
export { withPluginInstallRecords as a, writePersistedInstalledPluginIndexInstallRecordsSync as c, resolveInstalledPluginIndexRecordsStorePath as i, recordPluginInstallInRecords as n, withoutPluginInstallRecords as o, removePluginInstallRecordFromRecords as r, writePersistedInstalledPluginIndexInstallRecords as s, PLUGIN_INSTALLS_CONFIG_PATH as t };
