import { c as normalizeOptionalString, s as normalizeOptionalLowercaseString } from "./string-coerce-DKw2K5wM.js";
import { r as normalizeChatChannelId } from "./ids-COH3O_8T.js";
import "./chat-meta-C5d7GbI0.js";
import { n as getActivePluginChannelRegistrySnapshotFromState } from "./runtime-channel-state-QZcfYbLu.js";
//#region src/channels/registry-lookup.ts
let registeredChannelPluginLookup;
function setLookupEntry(map, key, entry) {
	if (key && !map.has(key)) map.set(key, entry);
}
function buildRegisteredChannelPluginLookup() {
	const { registry, version } = getActivePluginChannelRegistrySnapshotFromState();
	const channels = Array.isArray(registry?.channels) ? registry.channels : void 0;
	const channelCount = channels?.length ?? 0;
	const cached = registeredChannelPluginLookup;
	if (cached && cached.registry === registry && cached.channels === channels && cached.channelCount === channelCount && cached.version === version) return cached;
	const entries = channelCount > 0 ? channels : [];
	const byKey = /* @__PURE__ */ new Map();
	const byId = /* @__PURE__ */ new Map();
	for (const entry of entries) {
		const id = normalizeOptionalLowercaseString(entry.plugin.id ?? "");
		setLookupEntry(byKey, id, entry);
		setLookupEntry(byId, id, entry);
		for (const alias of entry.plugin.meta?.aliases ?? []) setLookupEntry(byKey, normalizeOptionalLowercaseString(alias), entry);
	}
	registeredChannelPluginLookup = {
		registry,
		channels,
		channelCount,
		version,
		entries,
		byKey,
		byId
	};
	return registeredChannelPluginLookup;
}
function listRegisteredChannelPluginEntries() {
	return buildRegisteredChannelPluginLookup().entries;
}
function findRegisteredChannelPluginEntry(normalizedKey) {
	return buildRegisteredChannelPluginLookup().byKey.get(normalizedKey);
}
function findRegisteredChannelPluginEntryById(id) {
	const normalizedId = normalizeOptionalLowercaseString(id);
	if (!normalizedId) return;
	return buildRegisteredChannelPluginLookup().byId.get(normalizedId);
}
//#endregion
//#region src/channels/registry.ts
function normalizeChannelId(raw) {
	return normalizeChatChannelId(raw);
}
function normalizeAnyChannelId(raw) {
	const key = normalizeOptionalLowercaseString(raw);
	if (!key) return null;
	return findRegisteredChannelPluginEntry(key)?.plugin.id ?? null;
}
function listRegisteredChannelPluginIds() {
	return listRegisteredChannelPluginEntries().flatMap((entry) => {
		const id = normalizeOptionalString(entry.plugin.id);
		return id ? [id] : [];
	});
}
function getRegisteredChannelPluginMeta(id) {
	return findRegisteredChannelPluginEntryById(id)?.plugin.meta ?? null;
}
function formatChannelPrimerLine(meta) {
	return `${meta.label}: ${meta.blurb}`;
}
function formatChannelSelectionLine(meta, docsLink) {
	const docsPrefix = meta.selectionDocsPrefix ?? "Docs:";
	const docsLabel = meta.docsLabel ?? meta.id;
	const docs = meta.selectionDocsOmitLabel ? docsLink(meta.docsPath) : docsLink(meta.docsPath, docsLabel);
	const extras = (meta.selectionExtras ?? []).filter(Boolean).join(" ");
	return `${meta.label} — ${meta.blurb} ${docsPrefix ? `${docsPrefix} ` : ""}${docs}${extras ? ` ${extras}` : ""}`;
}
//#endregion
export { normalizeAnyChannelId as a, listRegisteredChannelPluginIds as i, formatChannelSelectionLine as n, normalizeChannelId as o, getRegisteredChannelPluginMeta as r, findRegisteredChannelPluginEntry as s, formatChannelPrimerLine as t };
