import { mergeSecurity } from "../../blocks/scalar-auth-selector-block/helpers/merge-security.js";
import SidebarToggle_default from "../../components/sidebar/SidebarToggle.vue.js";
import CreateWorkspaceModal_default from "./components/CreateWorkspaceModal.vue.js";
import SplashScreen_default from "./components/SplashScreen.vue.js";
import { useDocumentWatcher } from "./hooks/use-document-watcher.js";
import TheCommandPalette_default from "../command-palette/TheCommandPalette.vue.js";
import { useMonacoEditorConfiguration } from "../editor/config.js";
import { useColorMode } from "../../hooks/use-color-mode.js";
import { useGlobalHotKeys } from "../../hooks/use-global-hot-keys.js";
import { usePosthog } from "../../posthog.js";
import AppSidebar_default from "./components/AppSidebar.vue.js";
import DesktopTabs_default from "./components/DesktopTabs.vue.js";
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, guardReactiveProps, normalizeProps, openBlock, renderSlot, toValue, unref, withCtx } from "vue";
import { ScalarTeleportRoot, useModal } from "@scalar/components";
import { ScalarToasts } from "@scalar/use-toasts";
import { RouterView } from "vue-router";
import { extensions } from "@scalar/workspace-store/schemas/extensions";
//#region src/v2/features/app/App.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["innerHTML"];
var _hoisted_2 = { key: 0 };
var _hoisted_3 = { class: "relative flex h-dvh w-dvw flex-1 flex-col" };
var _hoisted_4 = { class: "flex min-h-0 flex-1 flex-row" };
var _hoisted_5 = { class: "flex flex-1 flex-col" };
var _hoisted_6 = { class: "bg-b-1 min-h-0 flex-1" };
var _hoisted_7 = { key: 1 };
var App_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "App",
	props: {
		layout: {},
		plugins: { default: () => [] },
		getAppState: { type: Function },
		getCommandPaletteState: { type: Function },
		fetchRegistryDocument: { type: Function }
	},
	setup(__props, { expose: __expose }) {
		__expose({ openCreateWorkspace: () => createWorkspaceModalState.show() });
		const app = __props.getAppState();
		const paletteState = __props.getCommandPaletteState();
		/** Expose workspace store to window for debugging purposes. */
		if (typeof window !== "undefined") {
			window.dataDumpWorkspace = () => app.store.value;
			window.dumpAppState = () => app;
		}
		usePosthog(app.telemetry);
		/** Register global hotkeys for the app, passing the workspace event bus and layout state */
		useGlobalHotKeys(app.eventBus, __props.layout);
		/** Watch the active document for changes and rebase it with its remote source */
		useDocumentWatcher({
			documentName: () => app.store.value?.workspace[extensions.workspace.activeDocument],
			store: app.store,
			initialTimeout: 5e3
		});
		/** Color mode */
		useColorMode({ workspaceStore: app.store });
		/** Setup monaco editor configuration */
		useMonacoEditorConfiguration({
			theme: computed(() => app.theme.styles.value.themeStyles),
			darkMode: computed(() => app.isDarkMode.value)
		});
		const navigateToWorkspaceOverview = (namespace, slug) => {
			app.eventBus.emit("ui:navigate", {
				page: "workspace",
				path: "environment",
				namespace,
				workspaceSlug: slug
			});
		};
		/** Sets the active workspace by ID: finds the workspace in the list and updates app state & navigation. */
		const setActiveWorkspace = (id) => {
			if (!id) return;
			const workspace = app.workspace.workspaceList.value?.find((workspace) => workspace.id === id);
			if (!workspace) return;
			navigateToWorkspaceOverview(workspace.namespace, workspace.slug);
		};
		const createWorkspaceModalState = useModal();
		/** Props to pass to the RouterView component. */
		const routerViewProps = computed(() => {
			/** Ensure we have the auth store */
			const securitySchemes = app.store.value?.auth ? mergeSecurity(app.document.value?.components?.securitySchemes ?? {}, {}, app.store.value.auth, app.activeEntities.documentSlug.value ?? "") : {};
			return {
				documentSlug: app.activeEntities.documentSlug.value ?? "",
				document: app.store.value?.workspace.activeDocument ?? null,
				environment: app.environment.value,
				eventBus: app.eventBus,
				exampleName: app.activeEntities.exampleName.value,
				fetchRegistryDocument: __props.fetchRegistryDocument,
				layout: __props.layout,
				method: app.activeEntities.method.value,
				path: app.activeEntities.path.value,
				workspaceStore: app.store.value,
				activeWorkspace: app.workspace.activeWorkspace.value,
				plugins: __props.plugins,
				securitySchemes,
				isDarkMode: app.isDarkMode.value,
				currentTheme: app.theme.styles.value.themeStyles,
				customThemes: toValue(app.theme.customThemes),
				telemetry: app.telemetry.value,
				onUpdateTelemetry: (value) => {
					app.telemetry.value = value;
				}
			};
		});
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(ScalarTeleportRoot), null, {
				default: withCtx(() => [
					createElementVNode("div", { innerHTML: unref(app).theme.themeStyleTag.value }, null, 8, _hoisted_1),
					createVNode(unref(ScalarToasts)),
					unref(app).store.value !== null && unref(app).workspace.activeWorkspace.value !== null && !unref(app).loading.value ? (openBlock(), createElementBlock("main", _hoisted_2, [
						createElementVNode("div", _hoisted_3, [createVNode(unref(SidebarToggle_default), {
							modelValue: unref(app).sidebar.isOpen.value,
							"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(app).sidebar.isOpen.value = $event),
							class: "absolute top-4 left-3 z-[60] md:hidden"
						}, null, 8, ["modelValue"]), createElementVNode("div", _hoisted_4, [createVNode(AppSidebar_default, {
							isSidebarOpen: unref(app).sidebar.isOpen.value,
							"onUpdate:isSidebarOpen": _cache[1] || (_cache[1] = ($event) => unref(app).sidebar.isOpen.value = $event),
							activeWorkspace: unref(app).workspace.activeWorkspace.value,
							eventBus: unref(app).eventBus,
							isWorkspaceOpen: unref(app).workspace.isOpen.value,
							layout: __props.layout,
							sidebarState: unref(app).sidebar.state,
							sidebarWidth: unref(app).sidebar.width.value,
							store: unref(app).store.value,
							workspaces: unref(app).workspace.workspaceGroups.value,
							"onClick:workspace": navigateToWorkspaceOverview,
							"onCreate:workspace": _cache[2] || (_cache[2] = ($event) => unref(createWorkspaceModalState).show()),
							"onSelect:workspace": setActiveWorkspace,
							onSelectItem: unref(app).sidebar.handleSelectItem,
							"onUpdate:sidebarWidth": unref(app).sidebar.handleSidebarWidthUpdate
						}, {
							sidebarMenuActions: withCtx(() => [renderSlot(_ctx.$slots, "sidebar-menu-actions")]),
							_: 3
						}, 8, [
							"isSidebarOpen",
							"activeWorkspace",
							"eventBus",
							"isWorkspaceOpen",
							"layout",
							"sidebarState",
							"sidebarWidth",
							"store",
							"workspaces",
							"onSelectItem",
							"onUpdate:sidebarWidth"
						]), createElementVNode("div", _hoisted_5, [__props.layout === "desktop" ? (openBlock(), createBlock(DesktopTabs_default, {
							key: 0,
							activeTabIndex: unref(app).tabs.activeTabIndex.value,
							eventBus: unref(app).eventBus,
							tabs: unref(app).tabs.state.value
						}, null, 8, [
							"activeTabIndex",
							"eventBus",
							"tabs"
						])) : createCommentVNode("", true), createElementVNode("div", _hoisted_6, [createVNode(unref(RouterView), normalizeProps(guardReactiveProps(routerViewProps.value)), null, 16)])])])]),
						renderSlot(_ctx.$slots, "create-workspace", { state: unref(createWorkspaceModalState) }, () => [createVNode(CreateWorkspaceModal_default, {
							state: unref(createWorkspaceModalState),
							"onCreate:workspace": _cache[3] || (_cache[3] = (payload) => unref(app).workspace.create(payload))
						}, null, 8, ["state"])]),
						createVNode(TheCommandPalette_default, {
							eventBus: unref(app).eventBus,
							paletteState: unref(paletteState),
							workspaceStore: unref(app).store.value
						}, null, 8, [
							"eventBus",
							"paletteState",
							"workspaceStore"
						])
					])) : (openBlock(), createElementBlock("main", _hoisted_7, [createVNode(SplashScreen_default)]))
				]),
				_: 3
			});
		};
	}
});
//#endregion
export { App_vue_vue_type_script_setup_true_lang_default as default };

//# sourceMappingURL=App.vue.script.js.map