import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BmmBcIzD.js";
import { t as ServerVariablesForm_default } from "./ServerVariablesForm-BRZ9XC8o.js";
import { t as ValueEmitter_default } from "./ValueEmitter-QYkZ9Hdc.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeProps, normalizeClass, openBlock, renderList, toDisplayString, unref, useId, withCtx, withModifiers } from "vue";
import { ScalarButton, ScalarFloatingBackdrop, ScalarListboxCheckbox, ScalarMarkdown, ScalarPopover } from "@scalar/components";
import { ScalarIconPencilSimple, ScalarIconPlus } from "@scalar/icons";
//#region src/v2/components/server/ServerDropdownItem.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1$1 = ["aria-expanded"];
var _hoisted_2$1 = { class: "overflow-hidden text-ellipsis whitespace-nowrap" };
var _hoisted_3 = ["id"];
var _hoisted_4 = { key: 0 };
var _hoisted_5 = { class: "description text-c-3 px-3 py-1.5" };
//#endregion
//#region src/v2/components/server/ServerDropdownItem.vue
var ServerDropdownItem_default = /* @__PURE__ */ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
	__name: "ServerDropdownItem",
	props: {
		server: {},
		serverOption: {}
	},
	emits: ["update:variable", "update:selectedServer"],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const formId = useId();
		const hasVariables = () => {
			return Object.keys(__props.server?.variables ?? {}).length > 0;
		};
		const isSelectedServer = computed(() => __props.serverOption.id === __props.server?.url);
		const isExpanded = computed(() => isSelectedServer.value && hasVariables());
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock("div", { class: normalizeClass(["group/item flex min-h-fit flex-col rounded border", { "border-transparent": !isSelectedServer.value }]) }, [createElementVNode("button", mergeProps(isExpanded.value ? { "aria-controls": unref(formId) } : {}, {
				"aria-expanded": isExpanded.value,
				class: ["flex min-h-8 cursor-pointer items-center gap-1.5 rounded px-1.5", isSelectedServer.value ? "text-c-1 bg-b-2" : "hover:bg-b-2"],
				type: "button",
				onClick: _cache[0] || (_cache[0] = ($event) => emit("update:selectedServer"))
			}), [createVNode(unref(ScalarListboxCheckbox), { selected: isSelectedServer.value }, null, 8, ["selected"]), createElementVNode("span", _hoisted_2$1, toDisplayString(__props.serverOption.label), 1)], 16, _hoisted_1$1), isExpanded.value ? (openBlock(), createElementBlock("div", {
				key: 0,
				id: unref(formId),
				class: "bg-b-2 divide divide-y rounded-b border-t *:pl-4",
				onClick: _cache[2] || (_cache[2] = withModifiers(() => {}, ["stop"]))
			}, [createVNode(ServerVariablesForm_default, {
				variables: __props.server?.variables,
				"onUpdate:variable": _cache[1] || (_cache[1] = (key, value) => emit("update:variable", key, value))
			}, null, 8, ["variables"]), __props.server?.description ? (openBlock(), createElementBlock("div", _hoisted_4, [createElementVNode("div", _hoisted_5, [createVNode(unref(ScalarMarkdown), { value: __props.server.description }, null, 8, ["value"])])])) : createCommentVNode("", true)], 8, _hoisted_3)) : createCommentVNode("", true)], 2);
		};
	}
}), [["__scopeId", "data-v-1b7a32a4"]]);
//#endregion
//#region src/v2/components/server/ServerDropdown.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["onClick"];
var _hoisted_2 = { class: "flex items-center justify-center" };
//#endregion
//#region src/v2/components/server/ServerDropdown.vue
var ServerDropdown_default = /* @__PURE__ */ defineComponent({
	name: "ServerDropdown",
	props: {
		meta: {},
		servers: {},
		server: {},
		target: {},
		layout: {}
	},
	emits: [
		"update:selectedServer",
		"update:variable",
		"update:servers",
		"update:open"
	],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const requestServerOptions = computed(() => __props.servers.map((s) => ({
			id: s.url,
			label: s.url ?? "Unknown server"
		})));
		const serverUrlWithoutTrailingSlash = computed(() => {
			if (__props.server?.url?.endsWith("/")) return __props.server.url.slice(0, -1);
			return __props.server?.url || "";
		});
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(ScalarPopover), {
				class: "max-h-[inherit] p-0 text-base",
				focus: "",
				offset: 0,
				placement: "bottom",
				resize: "",
				target: __props.target,
				teleport: `#${__props.target}`
			}, {
				popover: withCtx(({ close }) => [createElementVNode("div", {
					class: "custom-scroll flex max-h-[inherit] flex-col gap-1 p-1",
					onClick: close
				}, [(openBlock(true), createElementBlock(Fragment, null, renderList(requestServerOptions.value, (serverOption, index) => {
					return openBlock(), createBlock(ServerDropdownItem_default, {
						key: serverOption.id,
						server: __props.server,
						serverOption,
						type: "request",
						"onUpdate:selectedServer": ($event) => emit("update:selectedServer", {
							url: serverOption.id,
							meta: __props.meta
						}),
						"onUpdate:variable": (key, value) => emit("update:variable", {
							index,
							key,
							value,
							meta: __props.meta
						})
					}, null, 8, [
						"server",
						"serverOption",
						"onUpdate:selectedServer",
						"onUpdate:variable"
					]);
				}), 128)), __props.layout !== "modal" ? (openBlock(), createElementBlock("button", {
					key: 0,
					class: "text-xxs hover:bg-b-2 flex cursor-pointer items-center gap-1.5 rounded p-1.75",
					type: "button",
					onClick: _cache[0] || (_cache[0] = ($event) => emit("update:servers"))
				}, [createElementVNode("div", _hoisted_2, [createVNode(unref(ScalarIconPencilSimple), { class: "size-4" })]), _cache[5] || (_cache[5] = createElementVNode("span", null, "Update Servers", -1))])) : createCommentVNode("", true)], 8, _hoisted_1)]),
				backdrop: withCtx(({ open }) => [createVNode(ValueEmitter_default, {
					value: open,
					onChange: _cache[1] || (_cache[1] = (value) => emit("update:open", value)),
					onUnmount: _cache[2] || (_cache[2] = ($event) => emit("update:open", false))
				}, null, 8, ["value"]), createVNode(unref(ScalarFloatingBackdrop), { class: "inset-x-px rounded-none rounded-b-lg" })]),
				default: withCtx(() => [createVNode(unref(ScalarButton), {
					class: "hover:bg-b-2 font-code text-c-2 ml-0.75 h-auto gap-0.75 rounded border px-1.5 text-base whitespace-nowrap",
					variant: "ghost"
				}, {
					default: withCtx(() => [__props.server ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [_cache[3] || (_cache[3] = createElementVNode("span", { class: "sr-only" }, "Server:", -1)), createTextVNode(" " + toDisplayString(serverUrlWithoutTrailingSlash.value), 1)], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [_cache[4] || (_cache[4] = createElementVNode("span", { class: "sr-only" }, "Add Server", -1)), createVNode(unref(ScalarIconPlus), { class: "size-3" })], 64))]),
					_: 1
				})]),
				_: 1
			}, 8, ["target", "teleport"]);
		};
	}
});
//#endregion
export { ServerDropdown_default as t };

//# sourceMappingURL=server-tcI-OCyx.js.map