import { registerTuiToolRenderer } from "./tool-renderers.js";
//#region src/tui/extension-host/host.ts
function createTuiExtensionHost(deps) {
	const widgetKey = (key) => `${deps.extensionId}:${key}`;
	return {
		extensionId: deps.extensionId,
		setFooterWidget(key, lines) {
			const fullKey = widgetKey(key);
			if (!lines || lines.length === 0) deps.surface.footerWidgets.delete(fullKey);
			else deps.surface.footerWidgets.set(fullKey, lines);
			deps.onInvalidate();
		},
		setHeaderWidget(key, lines) {
			const fullKey = widgetKey(key);
			if (!lines || lines.length === 0) deps.surface.headerWidgets.delete(fullKey);
			else deps.surface.headerWidgets.set(fullKey, lines);
			deps.onInvalidate();
		},
		addAutocompleteProvider(provider) {
			return deps.onAutocompleteProviderAdded(provider);
		},
		registerToolRenderer(toolName, renderer) {
			return registerTuiToolRenderer(toolName, renderer);
		},
		registerSlashCommand(name, description, handler) {
			return deps.onSlashCommandAdded(name, description, handler);
		},
		notify(message, level) {
			deps.notify(message, level);
		},
		showOverlay(component) {
			deps.showOverlay(component);
		},
		hideOverlay() {
			deps.hideOverlay();
		},
		setStatus(key, text) {
			const fullKey = widgetKey(key);
			if (!text) deps.surface.statusSlots.delete(fullKey);
			else deps.surface.statusSlots.set(fullKey, text);
			deps.onInvalidate();
		}
	};
}
async function invokeTuiExtensionRegistrars(registrars, createHost, onError) {
	for (const { extensionId, register } of registrars) try {
		await register(createHost(extensionId));
	} catch (err) {
		const errorMessage = err instanceof Error ? err.message : String(err);
		onError?.(extensionId, errorMessage);
	}
}
//#endregion
export { createTuiExtensionHost, invokeTuiExtensionRegistrars };

//# sourceMappingURL=host.js.map