import SidebarListElementActions_default from "./SidebarListElementActions.vue.js";
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, resolveComponent, toDisplayString, unref, withCtx, withModifiers } from "vue";
import { ScalarIcon } from "@scalar/components";
import { useRouter } from "vue-router";
import { Draggable } from "@scalar/draggable";
//#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" };
var SidebarListElement_vue_vue_type_script_setup_true_lang_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"
			])]);
		};
	}
});
//#endregion
export { SidebarListElement_vue_vue_type_script_setup_true_lang_default as default };

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