import { T as PathId, r as useWorkspace, w as useActiveEntities } from "./store-DpSUVhjp.js";
import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BmmBcIzD.js";
import { n as CommandActionForm_default, t as CommandActionInput_default } from "./CommandActionInput-TkcAx6E8.js";
import "./HttpMethod-rnWEgC3T.js";
import "./CodeInput-C-igR77V.js";
import "./Server-DnA_BzPS.js";
import "./AddressBar-B4xnl66I.js";
import "./components-ChixwQhN.js";
import { t as Sidebar_default } from "./Sidebar-C6AdX6-N.js";
import "./DataTableInput-yaU5g-kP.js";
import { t as ViewLayout_default } from "./ViewLayout-BOXN0IYo.js";
import { t as ViewLayoutContent_default } from "./ViewLayoutContent-CvMoJYPF.js";
import { t as ViewLayoutSection_default } from "./ViewLayoutSection-mUqKbQry.js";
import "./ScalarAsciiArt-BjuSnj8e.js";
import { t as EmptyState_default } from "./EmptyState-Cnm7hGW5.js";
import { t as Form_default } from "./Form-CSKzyHGO.js";
import { t as SidebarButton_default } from "./SidebarButton-BAagdMDe.js";
import { n as SidebarList_default, t as SidebarListElement_default } from "./SidebarListElement-BfTPiihc.js";
import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, onBeforeUnmount, onMounted, openBlock, ref, renderList, unref, watch, withCtx, withModifiers } from "vue";
import { ScalarModal, useModal } from "@scalar/components";
import { useToasts } from "@scalar/use-toasts";
import { useRoute, useRouter } from "vue-router";
import { cookieSchema } from "@scalar/oas-utils/entities/cookie";
//#endregion
//#region src/views/Cookies/CookieForm.vue
var CookieForm_default = /* @__PURE__ */ defineComponent({
	__name: "CookieForm",
	setup(__props) {
		const { activeCookieId } = useActiveEntities();
		const { cookies, cookieMutators } = useWorkspace();
		const fields = [
			{
				label: "Name",
				key: "name",
				placeholder: "session_id"
			},
			{
				label: "Value",
				key: "value",
				placeholder: "my-cookie-session-id"
			},
			{
				label: "Domain",
				key: "domain",
				placeholder: "example.com"
			}
		];
		const activeCookie = computed(() => cookies[activeCookieId.value] || cookieSchema.parse({
			name: "",
			value: "",
			domain: "",
			path: ""
		}));
		const updateCookie = (key, value) => {
			cookieMutators.edit(activeCookieId.value, key, value);
		};
		return (_ctx, _cache) => {
			return openBlock(), createBlock(Form_default, {
				data: activeCookie.value,
				onUpdate: updateCookie,
				options: fields
			}, null, 8, ["data"]);
		};
	}
});
//#endregion
//#region src/views/Cookies/CookieModal.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1$1 = { class: "flex h-8 items-start gap-2 text-sm" };
var _hoisted_2$1 = { class: "flex h-8 items-start gap-2 text-sm" };
var _hoisted_3 = { class: "flex h-8 items-start gap-2 text-sm" };
//#endregion
//#region src/views/Cookies/CookieModal.vue
var CookieModal_default = /* @__PURE__ */ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
	__name: "CookieModal",
	props: { state: {} },
	emits: ["cancel", "submit"],
	setup(__props, { emit: __emit }) {
		const props = __props;
		const emit = __emit;
		const cookieData = ref({
			name: "",
			value: "",
			domain: ""
		});
		const { toast } = useToasts();
		const handleSubmit = () => {
			if (!cookieData.value.name || !cookieData.value.value) {
				toast("Please fill in all fields before adding a cookie.", "error");
				return;
			}
			emit("submit", cookieData.value);
			props.state.hide();
		};
		watch(() => props.state.open, (isOpen) => {
			if (isOpen) cookieData.value = {
				name: "",
				value: "",
				domain: ""
			};
		});
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(ScalarModal), {
				size: "xs",
				state: __props.state,
				title: "Add Cookie"
			}, {
				default: withCtx(() => [createVNode(CommandActionForm_default, {
					disabled: !cookieData.value.name || !cookieData.value.value,
					onCancel: _cache[3] || (_cache[3] = ($event) => emit("cancel")),
					onSubmit: handleSubmit
				}, {
					submit: withCtx(() => [..._cache[7] || (_cache[7] = [createTextVNode("Add Cookie", -1)])]),
					default: withCtx(() => [
						createElementVNode("div", _hoisted_1$1, [_cache[4] || (_cache[4] = createTextVNode(" Name: ", -1)), createVNode(CommandActionInput_default, {
							modelValue: cookieData.value.name,
							"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => cookieData.value.name = $event),
							autofocus: "",
							class: "!p-0",
							placeholder: "session_id"
						}, null, 8, ["modelValue"])]),
						createElementVNode("div", _hoisted_2$1, [_cache[5] || (_cache[5] = createTextVNode(" Value: ", -1)), createVNode(CommandActionInput_default, {
							modelValue: cookieData.value.value,
							"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => cookieData.value.value = $event),
							autofocus: "",
							class: "!p-0",
							placeholder: "my-cookie-session-id"
						}, null, 8, ["modelValue"])]),
						createElementVNode("div", _hoisted_3, [_cache[6] || (_cache[6] = createTextVNode(" Domain: ", -1)), createVNode(CommandActionInput_default, {
							modelValue: cookieData.value.domain,
							"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => cookieData.value.domain = $event),
							autofocus: "",
							class: "!p-0",
							placeholder: "example.com"
						}, null, 8, ["modelValue"])])
					]),
					_: 1
				}, 8, ["disabled"])]),
				_: 1
			}, 8, ["state"]);
		};
	}
}), [["__scopeId", "data-v-694018d6"]]);
//#endregion
//#region src/views/Cookies/Cookies.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "flex-1" };
var _hoisted_2 = { class: "relative mb-[.5px] last:mb-0" };
//#endregion
//#region src/views/Cookies/Cookies.vue
var Cookies_default = /* @__PURE__ */ defineComponent({
	__name: "Cookies",
	setup(__props) {
		const { cookies, cookieMutators, events, workspaceMutators } = useWorkspace();
		const { activeWorkspace, activeCookieId } = useActiveEntities();
		const router = useRouter();
		const route = useRoute();
		const cookieModal = useModal();
		const addCookieHandler = (cookieData) => {
			const cookie = cookieSchema.parse({
				name: cookieData.name,
				value: cookieData.value,
				domain: cookieData.domain,
				path: "/"
			});
			cookieMutators.add(cookie);
			workspaceMutators.edit(activeWorkspace.value?.uid, "cookies", [...activeWorkspace.value?.cookies ?? [], cookie.uid]);
			router.push({
				name: "cookies",
				params: { cookies: cookie.uid }
			});
		};
		const removeCookie = (uid) => {
			cookieMutators.delete(uid);
			workspaceMutators.edit(activeWorkspace.value?.uid, "cookies", [...(activeWorkspace.value?.cookies ?? []).filter((c) => c !== uid)]);
			const remainingCookies = Object.values(cookies).filter((cookie) => cookie.uid !== uid);
			if (remainingCookies.length > 0) {
				const lastCookie = remainingCookies[remainingCookies.length - 1];
				if (lastCookie) router.push(lastCookie.uid);
			} else router.push({
				name: "cookies",
				params: { [PathId.Cookies]: "default" }
			});
		};
		const openCookieModal = () => {
			cookieModal.show();
		};
		const handleHotKey = (event) => {
			if (event?.createNew && route.name === "cookies") openCookieModal();
		};
		/**
		* Navigate to specific cookies
		*/
		const handleNavigation = (event, uid) => {
			const to = {
				name: "cookies",
				params: {
					workspace: activeWorkspace.value?.uid ?? "default",
					cookies: uid
				}
			};
			if (event.metaKey) {
				const path = router.resolve(to).href;
				window.open(path, "_blank");
				return;
			}
			router.push(to);
		};
		/** Bind keyboard shortcuts */
		onMounted(() => events.hotKeys.on(handleHotKey));
		/** Unbind keyboard shortcuts */
		onBeforeUnmount(() => events.hotKeys.off(handleHotKey));
		const activeCookie = computed(() => cookies[activeCookieId.value]);
		const hasCookies = computed(() => Object.keys(cookies).length > 0 && activeCookie.value);
		watch(() => route.query.openCookieModal, (newVal) => {
			if (newVal === "true") openCookieModal();
		}, { immediate: true });
		return (_ctx, _cache) => {
			return openBlock(), createBlock(ViewLayout_default, null, {
				default: withCtx(() => [
					createVNode(unref(Sidebar_default), { title: "Cookies" }, {
						content: withCtx(() => [createElementVNode("div", _hoisted_1, [createVNode(SidebarList_default, null, {
							default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(Object.values(unref(cookies)), (cookie) => {
								return openBlock(), createElementBlock("li", {
									key: cookie.uid,
									class: "gap-1/2 flex flex-col"
								}, [createElementVNode("div", _hoisted_2, [(openBlock(), createBlock(SidebarListElement_default, {
									key: cookie.uid,
									class: "text-xs",
									isDeletable: "",
									to: {
										name: "cookies",
										params: { [unref(PathId).Cookies]: cookie.uid }
									},
									type: "cookies",
									variable: {
										name: cookie.name,
										uid: cookie.uid
									},
									warningMessage: `Are you sure you want to delete this cookie?`,
									onClick: withModifiers(($event) => handleNavigation($event, cookie.uid), ["prevent"]),
									onDelete: ($event) => removeCookie(cookie.uid)
								}, null, 8, [
									"to",
									"variable",
									"onClick",
									"onDelete"
								]))])]);
							}), 128))]),
							_: 1
						})])]),
						button: withCtx(() => [createVNode(SidebarButton_default, {
							click: openCookieModal,
							hotkey: "N"
						}, {
							title: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode(" Add Cookie ", -1)])]),
							_: 1
						})]),
						_: 1
					}),
					createVNode(ViewLayoutContent_default, { class: "flex-1" }, {
						default: withCtx(() => [hasCookies.value ? (openBlock(), createBlock(ViewLayoutSection_default, {
							key: 0,
							class: "*:border-b-0"
						}, {
							title: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("Edit Cookie", -1)])]),
							default: withCtx(() => [createVNode(CookieForm_default)]),
							_: 1
						})) : (openBlock(), createBlock(EmptyState_default, { key: 1 }))]),
						_: 1
					}),
					createVNode(CookieModal_default, {
						state: unref(cookieModal),
						onCancel: _cache[0] || (_cache[0] = ($event) => unref(cookieModal).hide()),
						onSubmit: addCookieHandler
					}, null, 8, ["state"])
				]),
				_: 1
			});
		};
	}
});
//#endregion
export { Cookies_default as default };

//# sourceMappingURL=Cookies-DbOKTi1f.js.map