//#region src/channels/plugins/registry.ts
let cacheVersion = 0;
let sorted = [];
const byId = /* @__PURE__ */ new Map();
let lastPluginIdSignature = "";
function sortPlugins(plugins) {
	return plugins.toSorted((a, b) => {
		const orderA = a.meta.order ?? 999;
		const orderB = b.meta.order ?? 999;
		if (orderA !== orderB) return orderA - orderB;
		return a.id.localeCompare(b.id);
	});
}
function syncChannelPluginsFromManager(plugins) {
	const dedup = /* @__PURE__ */ new Map();
	for (const p of plugins) dedup.set(p.id, p);
	const nextSorted = sortPlugins(Array.from(dedup.values()));
	const signature = nextSorted.map((p) => p.id).join("\0");
	if (signature !== lastPluginIdSignature) {
		lastPluginIdSignature = signature;
		cacheVersion++;
	}
	sorted = nextSorted;
	byId.clear();
	for (const p of sorted) byId.set(p.id, p);
}
function getChannelRegistryVersion() {
	return cacheVersion;
}
function listChannelPlugins() {
	return sorted;
}
function getChannelPlugin(id) {
	return byId.get(id);
}
//#endregion
export { getChannelPlugin, getChannelRegistryVersion, listChannelPlugins, syncChannelPluginsFromManager };

//# sourceMappingURL=registry.js.map