import "../../CommandPalette-CL8k4CoN.js";
import { D as routes, O as saveActiveWorkspace, _ as createApiClient, d as handleHotKeyDown, r as useWorkspace, w as useActiveEntities } from "../../store-DpSUVhjp.js";
import { r as useSidebar } from "../../useSidebar-DLTwHDI-.js";
import "../../HttpMethod-rnWEgC3T.js";
import { t as MainLayout_default } from "../../MainLayout-BEFMl1ud.js";
import { t as analytics } from "../../analytics-BZimCWcw.js";
import { t as ImportCollectionListener_default } from "../../ImportCollection-DfX1UQ5u.js";
import { KeepAlive, computed, createBlock, createCommentVNode, createElementVNode, createVNode, defineComponent, onBeforeMount, onBeforeUnmount, onMounted, openBlock, resolveDynamicComponent, unref, watch, withCtx } from "vue";
import { ScalarTeleportRoot, addScalarClassesToHeadless } from "@scalar/components";
import { getThemeStyles } from "@scalar/themes";
import { useBreakpoints } from "@scalar/use-hooks/useBreakpoints";
import { useColorMode } from "@scalar/use-hooks/useColorMode";
import { ScalarToasts } from "@scalar/use-toasts";
import { RouterView, createRouter, createWebHistory } from "vue-router";
//#region src/layouts/Web/ApiClientWeb.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["innerHTML"];
//#endregion
//#region src/layouts/Web/ApiClientWeb.vue
var ApiClientWeb_default = /* @__PURE__ */ defineComponent({
	__name: "ApiClientWeb",
	setup(__props) {
		useColorMode();
		const { activeWorkspace } = useActiveEntities();
		const { events } = useWorkspace();
		onBeforeMount(() => addScalarClassesToHeadless());
		/** Handles the hotkey events, we will pass in custom hotkeys here */
		const handleKeyDown = (ev) => handleHotKeyDown(ev, events.hotKeys);
		const handleHotKey = (event) => {
			if (!event) return;
			if (event.openCommandPalette) {
				event.openCommandPalette.preventDefault();
				events.commandPalette.emit();
			}
		};
		onMounted(() => {
			window.addEventListener("keydown", handleKeyDown);
			events.hotKeys.on(handleHotKey);
		});
		onBeforeUnmount(() => {
			window.removeEventListener("keydown", handleKeyDown);
			events.hotKeys.off(handleHotKey);
		});
		const { mediaQueries } = useBreakpoints();
		const { setSidebarOpen } = useSidebar();
		watch(mediaQueries.xl, setSidebarOpen, { immediate: true });
		const themeStyleTag = computed(() => activeWorkspace.value && `<style>${getThemeStyles(activeWorkspace.value?.themeId)}</style>`);
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(ScalarTeleportRoot), null, {
				default: withCtx(() => [createVNode(unref(ImportCollectionListener_default), null, {
					default: withCtx(() => [
						createElementVNode("div", { innerHTML: themeStyleTag.value }, null, 8, _hoisted_1),
						unref(activeWorkspace)?.uid ? (openBlock(), createBlock(MainLayout_default, { key: 0 }, {
							default: withCtx(() => [createVNode(unref(RouterView), null, {
								default: withCtx(({ Component }) => [(openBlock(), createBlock(KeepAlive, null, [(openBlock(), createBlock(resolveDynamicComponent(Component)))], 1024))]),
								_: 1
							})]),
							_: 1
						})) : createCommentVNode("", true),
						createVNode(unref(ScalarToasts))
					]),
					_: 1
				})]),
				_: 1
			});
		};
	}
});
//#endregion
//#region src/layouts/Web/create-api-client-web.ts
/**
* Mount the API Client to a given element.
*/
var createApiClientWeb = async (el, configuration = {}, mountOnInitialize = true) => {
	const router = createRouter({
		history: createWebHistory(),
		routes
	});
	const client = createApiClient({
		el,
		appComponent: ApiClientWeb_default,
		configuration,
		mountOnInitialize,
		router,
		layout: "web"
	});
	const { importSpecFile, importSpecFromUrl } = client.store;
	router.afterEach((to, from) => {
		if (configuration.telemetry) analytics?.capture("page-view", {
			hostname: window.location.hostname,
			to: to.path,
			from: from.path
		});
		saveActiveWorkspace(to);
	});
	if (configuration.url) await importSpecFromUrl(configuration.url, "default", { proxyUrl: configuration.proxyUrl });
	else if (configuration.content) await importSpecFile(configuration.content, "default");
	return client;
};
//#endregion
export { ApiClientWeb_default as ApiClientWeb, createApiClientWeb };

//# sourceMappingURL=index.js.map