import { createBlock, createCommentVNode, createElementVNode, createTextVNode, createVNode, defineComponent, nextTick, openBlock, ref, unref, watch, withCtx } from "vue";
import { ScalarDropdown, ScalarDropdownDivider, ScalarDropdownItem, ScalarIcon } from "@scalar/components";
import { ScalarIconPencil } from "@scalar/icons";
import { getParentEntry } from "@scalar/workspace-store/navigation";
//#region src/v2/features/app/components/SidebarItemMenu.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "flex items-center gap-2" };
var _hoisted_2 = { class: "flex items-center gap-2" };
var _hoisted_3 = { class: "flex items-center gap-2" };
var _hoisted_4 = { class: "flex items-center gap-2" };
var _hoisted_5 = { class: "flex items-center gap-2" };
var _hoisted_6 = { class: "text-red flex items-center gap-2" };
var SidebarItemMenu_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "SidebarItemMenu",
	props: {
		item: {},
		eventBus: {},
		sidebarState: {},
		target: {}
	},
	emits: ["closeMenu", "showDeleteModal"],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const open = ref(false);
		watch(open, async (newValue, oldValue) => {
			if (!newValue && oldValue) {
				await nextTick();
				emit("closeMenu");
			}
		});
		/** Returns whether the item supports adding operations */
		const canAddOperation = () => __props.item.type === "document" || __props.item.type === "tag";
		/** Returns whether the item supports adding tags */
		const canAddTag = () => __props.item.type === "document";
		/** Returns whether the item supports editing tags */
		const canEditTag = () => __props.item.type === "tag";
		/** Returns whether the item supports editing examples */
		const canEditExample = () => __props.item.type === "example";
		/** Returns whether the item supports adding examples */
		const canAddExample = () => __props.item.type === "operation";
		/** Returns whether the item supports deletion */
		const canDelete = () => __props.item.type === "document" && __props.item.id !== "drafts" || __props.item.type === "tag" || __props.item.type === "operation" || __props.item.type === "example";
		const handleAddOperation = () => {
			if (__props.item.type === "document") __props.eventBus.emit("ui:open:command-palette", {
				action: "create-request",
				payload: { documentName: __props.item.name }
			});
			if (__props.item.type === "tag") {
				const itemWithParent = __props.sidebarState.getEntryById(__props.item.id);
				__props.eventBus.emit("ui:open:command-palette", {
					action: "create-request",
					payload: {
						documentName: getParentEntry("document", itemWithParent)?.name,
						tagId: __props.item.name
					}
				});
			}
		};
		const handleAddTag = () => {
			if (__props.item.type === "document") __props.eventBus.emit("ui:open:command-palette", {
				action: "add-tag",
				payload: { documentName: __props.item.name }
			});
		};
		const handleEditTag = () => {
			if (__props.item.type === "tag") {
				const itemWithParent = __props.sidebarState.getEntryById(__props.item.id);
				__props.eventBus.emit("ui:open:command-palette", {
					action: "edit-tag",
					payload: {
						tag: __props.item,
						documentName: getParentEntry("document", itemWithParent)?.name ?? ""
					}
				}, { skipUnpackProxy: true });
			}
		};
		const handleAddExample = () => {
			if (__props.item.type === "operation") {
				const itemWithParent = __props.sidebarState.getEntryById(__props.item.id);
				__props.eventBus.emit("ui:open:command-palette", {
					action: "add-example",
					payload: {
						documentName: getParentEntry("document", itemWithParent)?.name,
						operationId: __props.item.id
					}
				});
			}
		};
		const handleEditExample = () => {
			if (__props.item.type === "example") {
				const itemWithParent = __props.sidebarState.getEntryById(__props.item.id);
				const parentOperation = getParentEntry("operation", itemWithParent);
				__props.eventBus.emit("ui:open:command-palette", {
					action: "edit-example",
					payload: {
						example: __props.item,
						documentName: getParentEntry("document", itemWithParent)?.name ?? "",
						operationId: parentOperation?.id ?? ""
					}
				}, { skipUnpackProxy: true });
			}
		};
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(ScalarDropdown), {
				open: open.value,
				"onUpdate:open": _cache[6] || (_cache[6] = ($event) => open.value = $event),
				placement: "bottom-end",
				target: __props.target,
				teleport: ""
			}, {
				items: withCtx(() => [
					canAddOperation() ? (openBlock(), createBlock(unref(ScalarDropdownItem), {
						key: 0,
						onClick: _cache[0] || (_cache[0] = ($event) => handleAddOperation())
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_1, [createVNode(unref(ScalarIcon), {
							icon: "Add",
							size: "sm"
						}), _cache[7] || (_cache[7] = createTextVNode(" Add Operation ", -1))])]),
						_: 1
					})) : createCommentVNode("", true),
					canAddTag() ? (openBlock(), createBlock(unref(ScalarDropdownItem), {
						key: 1,
						onClick: _cache[1] || (_cache[1] = ($event) => handleAddTag())
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_2, [createVNode(unref(ScalarIcon), {
							icon: "Add",
							size: "sm"
						}), _cache[8] || (_cache[8] = createTextVNode(" Add Tag ", -1))])]),
						_: 1
					})) : createCommentVNode("", true),
					canEditTag() ? (openBlock(), createBlock(unref(ScalarDropdownItem), {
						key: 2,
						onClick: _cache[2] || (_cache[2] = ($event) => handleEditTag())
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_3, [createVNode(unref(ScalarIconPencil), { size: "sm" }), _cache[9] || (_cache[9] = createTextVNode(" Rename Tag ", -1))])]),
						_: 1
					})) : createCommentVNode("", true),
					canEditExample() ? (openBlock(), createBlock(unref(ScalarDropdownItem), {
						key: 3,
						onClick: _cache[3] || (_cache[3] = ($event) => handleEditExample())
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_4, [createVNode(unref(ScalarIconPencil), { size: "sm" }), _cache[10] || (_cache[10] = createTextVNode(" Rename Example ", -1))])]),
						_: 1
					})) : createCommentVNode("", true),
					canAddExample() ? (openBlock(), createBlock(unref(ScalarDropdownItem), {
						key: 4,
						onClick: _cache[4] || (_cache[4] = ($event) => handleAddExample())
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_5, [createVNode(unref(ScalarIcon), {
							icon: "Add",
							size: "sm"
						}), _cache[11] || (_cache[11] = createTextVNode(" Add Example ", -1))])]),
						_: 1
					})) : createCommentVNode("", true),
					(canAddExample() || canAddOperation() || canAddTag() || canEditExample()) && canDelete() ? (openBlock(), createBlock(unref(ScalarDropdownDivider), { key: 5 })) : createCommentVNode("", true),
					canDelete() ? (openBlock(), createBlock(unref(ScalarDropdownItem), {
						key: 6,
						onClick: _cache[5] || (_cache[5] = ($event) => emit("showDeleteModal"))
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_6, [createVNode(unref(ScalarIcon), {
							icon: "Delete",
							size: "sm"
						}), _cache[12] || (_cache[12] = createTextVNode(" Delete ", -1))])]),
						_: 1
					})) : createCommentVNode("", true)
				]),
				_: 1
			}, 8, ["open", "target"]);
		};
	}
});
//#endregion
export { SidebarItemMenu_vue_vue_type_script_setup_true_lang_default as default };

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