import { n as ROUTES } from "./CommandPalette-CL8k4CoN.js";
import { D as routes, O as saveActiveWorkspace, _ as createApiClient, d as handleHotKeyDown, l as DEFAULT_HOTKEYS, r as useWorkspace, w as useActiveEntities } from "./store-DpSUVhjp.js";
import { r as useSidebar } from "./useSidebar-DLTwHDI-.js";
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BmmBcIzD.js";
import { t as MainLayout_default } from "./MainLayout-BEFMl1ud.js";
import { t as analytics } from "./analytics-BZimCWcw.js";
import { Fragment, KeepAlive, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, onBeforeMount, onBeforeUnmount, onMounted, openBlock, reactive, ref, renderList, resolveDynamicComponent, toDisplayString, unref, watch, withCtx } from "vue";
import { ScalarContextMenu, ScalarDropdownButton, ScalarDropdownDivider, ScalarDropdownMenu, ScalarFloating, ScalarHotkey, ScalarIcon, ScalarTeleportRoot, ScalarTooltip, 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, useRouter } from "vue-router";
import { LibraryIcon } from "@scalar/icons/library";
import { useClipboard } from "@scalar/use-hooks/useClipboard";
import { isMacOS } from "@scalar/helpers/general/is-mac-os";
//#region src/components/TopNav/TopNavItem.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1$2 = { class: "nav-item-icon-copy flex flex-1 items-center justify-center gap-1.5" };
var _hoisted_2$2 = { class: "custom-scroll nav-item-copy text-sm" };
//#endregion
//#region src/components/TopNav/TopNavItem.vue
var TopNavItem_default = /* @__PURE__ */ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
	__name: "TopNavItem",
	props: {
		hotkey: {},
		active: { type: Boolean },
		label: {},
		icon: {},
		isCollection: { type: Boolean }
	},
	emits: [
		"click",
		"close",
		"newTab",
		"copyUrl",
		"closeOtherTabs"
	],
	setup(__props) {
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(ScalarContextMenu), { triggerClass: "overflow-hidden w-full" }, {
				trigger: withCtx(() => [createVNode(unref(ScalarTooltip), {
					content: `${unref(isMacOS)() ? "⌘" : "^"} ${__props.hotkey}`,
					placement: "bottom"
				}, {
					default: withCtx(() => [createElementVNode("div", {
						class: normalizeClass(["nav-item app-no-drag-region", { "nav-item__active": __props.active }]),
						onClick: _cache[1] || (_cache[1] = ($event) => _ctx.$emit("click"))
					}, [createElementVNode("div", _hoisted_1$2, [__props.isCollection ? (openBlock(), createBlock(unref(LibraryIcon), {
						key: 0,
						class: "size-3.5 min-w-3.5 stroke-2",
						src: __props.icon
					}, null, 8, ["src"])) : (openBlock(), createBlock(unref(ScalarIcon), {
						key: 1,
						icon: __props.icon,
						size: "xs",
						thickness: "2.5"
					}, null, 8, ["icon"])), createElementVNode("span", _hoisted_2$2, toDisplayString(__props.label), 1)]), createElementVNode("button", {
						class: "nav-item-close",
						type: "button",
						onClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("close"))
					}, [createVNode(unref(ScalarIcon), {
						icon: "Close",
						thickness: "1.75"
					})])], 2)]),
					_: 1
				}, 8, ["content"])]),
				content: withCtx(() => [createVNode(unref(ScalarFloating), { placement: "right-start" }, {
					floating: withCtx(() => [createVNode(unref(ScalarDropdownMenu), { class: "scalar-app scalar-client" }, {
						default: withCtx(() => [
							createVNode(unref(ScalarDropdownButton), {
								class: "flex items-center gap-1.5",
								onClick: _cache[2] || (_cache[2] = ($event) => _ctx.$emit("newTab"))
							}, {
								default: withCtx(() => [
									createVNode(unref(ScalarIcon), {
										icon: "AddTab",
										size: "sm",
										thickness: "1.5"
									}),
									_cache[6] || (_cache[6] = createTextVNode(" New Tab ", -1)),
									createVNode(unref(ScalarHotkey), {
										class: "bg-b-2 ml-auto",
										hotkey: "T"
									})
								]),
								_: 1
							}),
							createVNode(unref(ScalarDropdownButton), {
								class: "flex items-center gap-1.5",
								onClick: _cache[3] || (_cache[3] = ($event) => _ctx.$emit("copyUrl"))
							}, {
								default: withCtx(() => [createVNode(unref(ScalarIcon), {
									icon: "Link",
									size: "sm",
									thickness: "1.5"
								}), _cache[7] || (_cache[7] = createTextVNode(" Copy URL ", -1))]),
								_: 1
							}),
							createVNode(unref(ScalarDropdownDivider)),
							createVNode(unref(ScalarDropdownButton), {
								class: "flex items-center gap-1.5",
								onClick: _cache[4] || (_cache[4] = ($event) => _ctx.$emit("close"))
							}, {
								default: withCtx(() => [
									createVNode(unref(ScalarIcon), {
										icon: "CloseTab",
										size: "sm",
										thickness: "1.5"
									}),
									_cache[8] || (_cache[8] = createTextVNode(" Close Tab ", -1)),
									createVNode(unref(ScalarHotkey), {
										class: "bg-b-2 ml-auto",
										hotkey: "W"
									})
								]),
								_: 1
							}),
							createVNode(unref(ScalarDropdownButton), {
								class: "flex items-center gap-1.5",
								onClick: _cache[5] || (_cache[5] = ($event) => _ctx.$emit("closeOtherTabs"))
							}, {
								default: withCtx(() => [createVNode(unref(ScalarIcon), {
									icon: "CloseTabs",
									size: "sm",
									thickness: "1.5"
								}), _cache[9] || (_cache[9] = createTextVNode(" Close Other Tabs ", -1))]),
								_: 1
							})
						]),
						_: 1
					})]),
					_: 1
				})]),
				_: 1
			});
		};
	}
}), [["__scopeId", "data-v-507381a3"]]);
//#endregion
//#region src/components/TopNav/TopNav.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1$1 = { class: "mac:pl-[72px] t-app__top-nav relative flex h-10 pl-2" };
var _hoisted_2$1 = { class: "relative flex h-10 flex-1 items-center gap-1.5 overflow-hidden pr-2.5 text-base font-medium" };
var _hoisted_3 = {
	key: 0,
	class: "h-full w-full overflow-hidden"
};
//#endregion
//#region src/components/TopNav/TopNav.vue
var TopNav_default = /* @__PURE__ */ defineComponent({
	__name: "TopNav",
	props: { openNewTab: {} },
	setup(__props) {
		const props = __props;
		const { activeRequest, activeCollection } = useActiveEntities();
		const router = useRouter();
		const { events } = useWorkspace();
		const { copyToClipboard } = useClipboard();
		/** Nav Items list */
		const topNavItems = reactive([{
			label: "",
			path: "",
			icon: "Add",
			isCollection: false
		}]);
		const activeNavItemIdx = ref(0);
		const activeNavItemIdxValue = computed(() => activeNavItemIdx.value);
		/**
		* Check if the current route is a collection
		*/
		const isCollection = computed(() => {
			return router.currentRoute.value.name?.toString().startsWith("collection.");
		});
		/**
		* Logic to handle adding a nav item
		* based on the current route
		*/
		function handleNavLabelAdd() {
			if (isCollection.value) {
				topNavItems[activeNavItemIdx.value] = {
					label: activeCollection.value?.info?.title || "Untitled Collection",
					path: router.currentRoute.value.path,
					icon: activeCollection.value?.["x-scalar-icon"] || "Collection",
					isCollection: true
				};
				return;
			}
			if (router.currentRoute.value.name?.toString().startsWith("request")) {
				topNavItems[activeNavItemIdx.value] = {
					label: activeRequest.value?.summary || "",
					path: router.currentRoute.value.path,
					icon: "ExternalLink",
					isCollection: false
				};
				return;
			}
			const activeRoute = ROUTES.find((route) => {
				return route.to.name.startsWith(router.currentRoute.value.name?.toString() ?? "");
			});
			if (activeRoute) {
				topNavItems[activeNavItemIdx.value] = {
					label: activeRoute.displayName,
					path: router.currentRoute.value.path,
					icon: activeRoute.icon,
					isCollection: false
				};
				return;
			}
		}
		function handleNavRoute() {
			const path = topNavItems[activeNavItemIdx.value]?.path;
			if (path) router.push(path);
		}
		/**
		* adding a nav item sets the new index and nav item
		* based on the route
		*/
		function addNavItem() {
			topNavItems.push({
				label: "",
				path: "",
				icon: "Add",
				isCollection: false
			});
			activeNavItemIdx.value = topNavItems.length - 1;
			handleNavLabelAdd();
		}
		function setNavItemIdx(idx) {
			activeNavItemIdx.value = idx;
			handleNavRoute();
		}
		watch(() => router.currentRoute.value.path, () => {
			handleNavLabelAdd();
		}, { immediate: true });
		function removeNavItem(idx) {
			topNavItems.splice(idx, 1);
			activeNavItemIdx.value = Math.min(activeNavItemIdx.value, topNavItems.length - 1);
			handleNavRoute();
		}
		const copyUrl = async (idx) => {
			if (!topNavItems[idx]?.path) return;
			const fullUrl = new URL(window.location.href);
			fullUrl.pathname = topNavItems[idx].path;
			await copyToClipboard(fullUrl.toString());
		};
		const closeOtherTabs = (idx) => {
			topNavItems.splice(0, idx);
			topNavItems.splice(1);
			activeNavItemIdx.value = 0;
			handleNavRoute();
		};
		/** Handle hotkeys */
		const handleHotKey = (event) => {
			if (!event) return;
			if (event.addTopNav) addNavItem();
			if (event.closeTopNav) removeNavItem(activeNavItemIdx.value);
			if (event.navigateTopNavLeft) setNavItemIdx(Math.max(activeNavItemIdx.value - 1, 0));
			if (event.navigateTopNavRight) setNavItemIdx(Math.min(activeNavItemIdx.value + 1, topNavItems.length - 1));
			if (event.jumpToTab) {
				const tabIndex = Number(event.jumpToTab.key) - 1;
				if (tabIndex >= 0 && tabIndex < topNavItems.length) setNavItemIdx(tabIndex);
			}
			if (event.jumpToLastTab) setNavItemIdx(topNavItems.length - 1);
		};
		const addTopNavTab = (item) => {
			topNavItems.push({
				label: item.name,
				path: item.uid,
				icon: "ExternalLink",
				isCollection: false
			});
		};
		watch(() => props.openNewTab, (openNewTab) => {
			if (openNewTab) addTopNavTab(openNewTab);
		}, { immediate: true });
		onMounted(() => events.hotKeys.on(handleHotKey));
		onBeforeUnmount(() => events.hotKeys.off(handleHotKey));
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock("nav", _hoisted_1$1, [_cache[3] || (_cache[3] = createElementVNode("div", { class: "app-drag-region absolute inset-0" }, null, -1)), createElementVNode("div", _hoisted_2$1, [topNavItems.length === 1 ? (openBlock(), createElementBlock("div", _hoisted_3, [createVNode(unref(ScalarContextMenu), { triggerClass: "flex custom-scroll gap-1.5 h-full items-center justify-center w-full whitespace-nowrap" }, {
				trigger: withCtx(() => [isCollection.value ? (openBlock(), createBlock(unref(LibraryIcon), {
					key: 0,
					class: "size-3.5 min-w-3.5 stroke-2",
					src: unref(activeCollection)?.["x-scalar-icon"] || "Collection"
				}, null, 8, ["src"])) : topNavItems[0]?.icon ? (openBlock(), createBlock(unref(ScalarIcon), {
					key: 1,
					icon: topNavItems[0]?.icon,
					size: "xs",
					thickness: "2.5"
				}, null, 8, ["icon"])) : createCommentVNode("", true), createElementVNode("span", null, toDisplayString(topNavItems[0]?.label), 1)]),
				content: withCtx(() => [createVNode(unref(ScalarFloating), { placement: "right-start" }, {
					floating: withCtx(() => [createVNode(unref(ScalarDropdownMenu), { class: "scalar-app scalar-client" }, {
						default: withCtx(() => [createVNode(unref(ScalarDropdownButton), {
							class: "flex items-center gap-1.5",
							onClick: addNavItem
						}, {
							default: withCtx(() => [
								createVNode(unref(ScalarIcon), {
									icon: "AddTab",
									size: "sm",
									thickness: "1.5"
								}),
								_cache[1] || (_cache[1] = createTextVNode(" New Tab ", -1)),
								createVNode(unref(ScalarHotkey), {
									class: "bg-b-2 ml-auto",
									hotkey: "T"
								})
							]),
							_: 1
						}), createVNode(unref(ScalarDropdownButton), {
							class: "flex items-center gap-1.5",
							onClick: _cache[0] || (_cache[0] = ($event) => copyUrl(activeNavItemIdxValue.value))
						}, {
							default: withCtx(() => [createVNode(unref(ScalarIcon), {
								icon: "Link",
								size: "sm",
								thickness: "1.5"
							}), _cache[2] || (_cache[2] = createTextVNode(" Copy URL ", -1))]),
							_: 1
						})]),
						_: 1
					})]),
					_: 1
				})]),
				_: 1
			})])) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(topNavItems, (topNavItem, index) => {
				return openBlock(), createBlock(TopNavItem_default, {
					key: topNavItem.path,
					active: index === activeNavItemIdxValue.value,
					hotkey: (index + 1).toString(),
					icon: topNavItem.isCollection ? unref(activeCollection)?.["x-scalar-icon"] || "Collection" : topNavItem.icon,
					isCollection: topNavItem.isCollection || false,
					label: topNavItem.label,
					onClick: ($event) => setNavItemIdx(index),
					onClose: ($event) => removeNavItem(index),
					onCloseOtherTabs: ($event) => closeOtherTabs(index),
					onCopyUrl: ($event) => copyUrl(index),
					onNewTab: addNavItem
				}, null, 8, [
					"active",
					"hotkey",
					"icon",
					"isCollection",
					"label",
					"onClick",
					"onClose",
					"onCloseOtherTabs",
					"onCopyUrl"
				]);
			}), 128)), createElementVNode("button", {
				class: "text-c-3 hover:bg-b-3 app-no-drag-region rounded p-1.5",
				type: "button",
				onClick: addNavItem
			}, [createVNode(unref(ScalarIcon), {
				icon: "Add",
				size: "sm",
				thickness: "2.5"
			})])])]);
		};
	}
});
//#endregion
//#region src/layouts/App/hotkeys.ts
/**
* Default set of keybindings for the client app
*/
var APP_HOTKEYS = {
	t: {
		event: "addTopNav",
		modifiers: ["default"]
	},
	w: {
		event: "closeTopNav",
		modifiers: ["default"]
	},
	ArrowLeft: {
		event: "navigateTopNavLeft",
		modifiers: ["default", "Alt"]
	},
	ArrowRight: {
		event: "navigateTopNavRight",
		modifiers: ["default", "Alt"]
	},
	l: {
		event: "focusAddressBar",
		modifiers: ["default"]
	},
	1: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	2: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	3: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	4: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	5: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	6: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	7: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	8: {
		event: "jumpToTab",
		modifiers: ["default"]
	},
	9: {
		event: "jumpToLastTab",
		modifiers: ["default"]
	},
	f: {
		event: "focusRequestSearch",
		modifiers: ["default"]
	},
	n: {
		event: "createNew",
		modifiers: ["default"]
	}
};
//#endregion
//#region src/layouts/App/ApiClientApp.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = {
	id: "scalar-client-app",
	class: "contents"
};
var _hoisted_2 = ["innerHTML"];
//#endregion
//#region src/layouts/App/ApiClientApp.vue
var ApiClientApp_default = /* @__PURE__ */ defineComponent({
	__name: "ApiClientApp",
	emits: ["newTab"],
	setup(__props) {
		const hotKeys = {
			...DEFAULT_HOTKEYS,
			...APP_HOTKEYS
		};
		const newTab = ref(null);
		const handleNewTab = (item) => {
			newTab.value = item;
		};
		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, { 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(() => [createElementVNode("div", _hoisted_1, [
					createElementVNode("div", { innerHTML: themeStyleTag.value }, null, 8, _hoisted_2),
					createVNode(TopNav_default, { openNewTab: newTab.value }, null, 8, ["openNewTab"]),
					unref(activeWorkspace)?.uid ? (openBlock(), createBlock(MainLayout_default, { key: 0 }, {
						default: withCtx(() => [createVNode(unref(RouterView), { onNewTab: handleNewTab }, {
							default: withCtx(({ Component }) => [(openBlock(), createBlock(KeepAlive, null, [(openBlock(), createBlock(resolveDynamicComponent(Component)))], 1024))]),
							_: 1
						})]),
						_: 1
					})) : createCommentVNode("", true),
					createVNode(unref(ScalarToasts))
				])]),
				_: 1
			});
		};
	}
});
//#endregion
//#region src/layouts/App/create-api-client-app.ts
/**
* Mount the full-blown API Client modal to a given element.
*/
var createApiClientApp = async (el, configuration = {}, mountOnInitialize = true) => {
	const router = createRouter({
		history: createWebHistory(),
		routes
	});
	const client = createApiClient({
		el,
		appComponent: ApiClientApp_default,
		configuration,
		mountOnInitialize,
		router,
		layout: "desktop"
	});
	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,
		router
	};
};
//#endregion
export { ApiClientApp_default as n, createApiClientApp as t };

//# sourceMappingURL=App-BVH4lIe8.js.map