import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-BmmBcIzD.js";
import { t as DeleteSidebarListElement_default } from "./DeleteSidebarListElement-C-p87d03.js";
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, renderSlot, resolveComponent, toDisplayString, unref, withCtx, withModifiers } from "vue";
import { ScalarIcon, ScalarModal, useModal } from "@scalar/components";
import { useRouter } from "vue-router";
import { useClipboard } from "@scalar/use-hooks/useClipboard";
import { Draggable } from "@scalar/draggable";
//#region src/components/Sidebar/SidebarList.vue
var _sfc_main = {};
var _hoisted_1$2 = { class: "gap-1/2 flex flex-col px-3 pb-[75px]" };
function _sfc_render(_ctx, _cache) {
	return openBlock(), createElementBlock("ul", _hoisted_1$2, [renderSlot(_ctx.$slots, "default")]);
}
var SidebarList_default = /* @__PURE__ */ _plugin_vue_export_helper_default(_sfc_main, [["render", _sfc_render]]);
//#endregion
//#region src/components/Sidebar/SidebarListElementActions.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1$1 = { class: "absolute right-1 flex opacity-0 group-hover:opacity-100" };
var ModalAction = /* @__PURE__ */ function(ModalAction) {
	ModalAction["Delete"] = "Delete";
	ModalAction["None"] = "None";
	return ModalAction;
}(ModalAction || {});
//#endregion
//#region src/components/Sidebar/SidebarListElementActions.vue
var SidebarListElementActions_default = /* @__PURE__ */ defineComponent({
	__name: "SidebarListElementActions",
	props: {
		variable: {},
		warningMessage: {},
		isCopyable: { type: Boolean },
		isDeletable: { type: Boolean },
		isRenameable: { type: Boolean }
	},
	emits: ["delete", "rename"],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const currentAction = ref({
			action: ModalAction.None,
			name: ""
		});
		const modalState = useModal();
		const { copyToClipboard } = useClipboard();
		function startActionFlow(action) {
			currentAction.value = {
				action,
				name: __props.variable.name
			};
			modalState.show();
		}
		function handleModalClose() {
			modalState.hide();
			currentAction.value = {
				action: ModalAction.None,
				name: ""
			};
		}
		function handleDelete(id) {
			emit("delete", id);
			handleModalClose();
		}
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock(Fragment, null, [createElementVNode("div", _hoisted_1$1, [
				__props.isCopyable ? (openBlock(), createElementBlock("button", {
					key: 0,
					class: "text-c-3 hover:bg-b-3 hover:text-c-1 rounded p-[5px]",
					type: "button",
					onClick: _cache[0] || (_cache[0] = ($event) => unref(copyToClipboard)(__props.variable.name))
				}, [createVNode(unref(ScalarIcon), {
					class: "h-3 w-3",
					icon: "Clipboard"
				})])) : createCommentVNode("", true),
				__props.isRenameable ? (openBlock(), createElementBlock("button", {
					key: 1,
					class: "text-c-3 hover:bg-b-3 hover:text-c-1 rounded p-[5px]",
					type: "button",
					onClick: _cache[1] || (_cache[1] = ($event) => emit("rename", __props.variable.uid))
				}, [createVNode(unref(ScalarIcon), {
					class: "h-3 w-3",
					icon: "Edit"
				})])) : createCommentVNode("", true),
				!__props.variable.isDefault && __props.isDeletable ? (openBlock(), createElementBlock("button", {
					key: 2,
					class: "text-c-3 hover:bg-b-3 hover:text-c-1 rounded p-1",
					type: "button",
					onClick: _cache[2] || (_cache[2] = withModifiers(($event) => startActionFlow(ModalAction.Delete), ["prevent"]))
				}, [createVNode(unref(ScalarIcon), {
					class: "h-3.5 w-3.5",
					icon: "Close"
				})])) : createCommentVNode("", true)
			]), createVNode(unref(ScalarModal), {
				size: "sm",
				state: unref(modalState),
				title: `${currentAction.value.action} ${currentAction.value.name}`
			}, {
				default: withCtx(() => [currentAction.value.action === ModalAction.Delete ? (openBlock(), createBlock(DeleteSidebarListElement_default, {
					key: 0,
					variableName: currentAction.value.name,
					warningMessage: __props.warningMessage,
					onClose: handleModalClose,
					onDelete: _cache[3] || (_cache[3] = ($event) => handleDelete(__props.variable.uid))
				}, null, 8, ["variableName", "warningMessage"])) : createCommentVNode("", true)]),
				_: 1
			}, 8, ["state", "title"])], 64);
		};
	}
});
//#endregion
//#region src/components/Sidebar/SidebarListElement.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "empty-variable-name line-clamp-1 text-sm break-all group-hover:pr-5" };
//#endregion
//#region src/components/Sidebar/SidebarListElement.vue
var SidebarListElement_default = /* @__PURE__ */ _plugin_vue_export_helper_default(/* @__PURE__ */ defineComponent({
	__name: "SidebarListElement",
	props: {
		variable: {},
		warningMessage: {},
		to: {},
		isDeletable: { type: Boolean },
		isCopyable: { type: Boolean },
		isRenameable: { type: Boolean },
		isDraggable: {
			type: Boolean,
			default: false
		},
		isDroppable: {
			type: [Boolean, Function],
			default: false
		},
		collectionId: {}
	},
	emits: [
		"delete",
		"colorModal",
		"rename",
		"onDragEnd"
	],
	setup(__props, { emit: __emit }) {
		const emit = __emit;
		const router = useRouter();
		const handleNavigation = (event) => {
			if (event.metaKey) window.open(router.resolve(__props.to).href, "_blank");
			else router.push(__props.to);
		};
		const handleDelete = (id) => {
			emit("delete", id);
		};
		const handleColorClick = (uid) => {
			emit("colorModal", uid);
		};
		const handleRename = (id) => {
			emit("rename", id);
		};
		/** The draggable component (bound in template via ref="_draggableRef") */
		const _draggableRef = ref(null);
		/** Calculate offsets for drag and drop */
		const getDraggableOffsets = computed(() => ({
			ceiling: .5,
			floor: .5
		}));
		return (_ctx, _cache) => {
			const _component_router_link = resolveComponent("router-link");
			return openBlock(), createElementBlock("li", null, [createVNode(unref(Draggable), {
				id: __props.variable.uid,
				ref_key: "_draggableRef",
				ref: _draggableRef,
				ceiling: getDraggableOffsets.value.ceiling,
				floor: getDraggableOffsets.value.floor,
				isDraggable: __props.isDraggable,
				isDroppable: __props.isDroppable,
				parentIds: __props.collectionId ? [__props.collectionId] : [],
				onOnDragEnd: _cache[2] || (_cache[2] = (...args) => _ctx.$emit("onDragEnd", ...args))
			}, {
				default: withCtx(() => [createVNode(_component_router_link, {
					class: normalizeClass(["text-c-2 hover:bg-b-2 group relative flex h-8 items-center gap-1.5 rounded py-1 pr-1.5 font-medium no-underline", [__props.variable.color ? "pl-5" : "pl-1.5"]]),
					exactActiveClass: "bg-b-2 !text-c-1",
					role: "button",
					to: __props.to,
					onClick: _cache[1] || (_cache[1] = withModifiers(($event) => handleNavigation($event), ["prevent"]))
				}, {
					default: withCtx(() => [
						__props.variable.color ? (openBlock(), createElementBlock("button", {
							key: 0,
							class: "hover:bg-b-3 rounded p-1.5",
							type: "button",
							onClick: _cache[0] || (_cache[0] = ($event) => handleColorClick(__props.variable.uid))
						}, [createElementVNode("div", {
							class: "h-2.5 w-2.5 rounded-xl",
							style: normalizeStyle({ backgroundColor: __props.variable.color })
						}, null, 4)])) : createCommentVNode("", true),
						__props.variable.icon ? (openBlock(), createBlock(unref(ScalarIcon), {
							key: 1,
							class: "text-sidebar-c-2 size-3.5 stroke-[2.25]",
							icon: __props.variable.icon
						}, null, 8, ["icon"])) : createCommentVNode("", true),
						createElementVNode("span", _hoisted_1, toDisplayString(__props.variable.name), 1),
						createVNode(SidebarListElementActions_default, {
							isCopyable: Boolean(__props.isCopyable),
							isDeletable: Boolean(__props.isDeletable),
							isRenameable: Boolean(__props.isRenameable),
							variable: {
								...__props.variable,
								isDefault: __props.variable.isDefault ?? false
							},
							warningMessage: __props.warningMessage,
							onDelete: handleDelete,
							onRename: handleRename
						}, null, 8, [
							"isCopyable",
							"isDeletable",
							"isRenameable",
							"variable",
							"warningMessage"
						])
					]),
					_: 1
				}, 8, ["class", "to"])]),
				_: 1
			}, 8, [
				"id",
				"ceiling",
				"floor",
				"isDraggable",
				"isDroppable",
				"parentIds"
			])]);
		};
	}
}), [["__scopeId", "data-v-298ba76d"]]);
//#endregion
export { SidebarList_default as n, SidebarListElement_default as t };

//# sourceMappingURL=SidebarListElement-BfTPiihc.js.map