import { t as DEFAULT_ACCOUNT_ID } from "./session-key-DIUsVZjU.js";
import { t as formatCliCommand } from "./command-format-Dh6J8CvS.js";

//#region src/web/active-listener.ts
const STATE_KEY = Symbol.for("minion.activeWebListeners");
const state = (() => {
	const g = globalThis;
	if (!g[STATE_KEY]) g[STATE_KEY] = {
		listeners: /* @__PURE__ */ new Map(),
		currentListener: null
	};
	return g[STATE_KEY];
})();
function resolveWebAccountId(accountId) {
	return (accountId ?? "").trim() || DEFAULT_ACCOUNT_ID;
}
function requireActiveWebListener(accountId) {
	const id = resolveWebAccountId(accountId);
	const listener = state.listeners.get(id) ?? null;
	if (!listener) throw new Error(`No active WhatsApp Web listener (account: ${id}). Start the gateway, then link WhatsApp with: ${formatCliCommand(`minion channels login --channel whatsapp --account ${id}`)}.`);
	return {
		accountId: id,
		listener
	};
}
function setActiveWebListener(accountIdOrListener, maybeListener) {
	const { accountId, listener } = typeof accountIdOrListener === "string" ? {
		accountId: accountIdOrListener,
		listener: maybeListener ?? null
	} : {
		accountId: DEFAULT_ACCOUNT_ID,
		listener: accountIdOrListener ?? null
	};
	const id = resolveWebAccountId(accountId);
	if (!listener) state.listeners.delete(id);
	else state.listeners.set(id, listener);
	if (id === DEFAULT_ACCOUNT_ID) state.currentListener = listener;
}
function getActiveWebListener(accountId) {
	const id = resolveWebAccountId(accountId);
	return state.listeners.get(id) ?? null;
}

//#endregion
export { requireActiveWebListener as n, setActiveWebListener as r, getActiveWebListener as t };