import { useActiveEntities } from "../../store/active-entities.js";
import { useWorkspace } from "../../store/store.js";
import { Fragment, createBlock, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, renderList, toDisplayString, unref, vModelText, withCtx, withDirectives, withModifiers } from "vue";
import { ScalarButton, ScalarDropdown, ScalarDropdownDivider, ScalarDropdownItem, ScalarIcon, ScalarModal, useModal } from "@scalar/components";
import { useToasts } from "@scalar/use-toasts";
import { useRouter } from "vue-router";
//#region src/components/ImportCollection/WorkspaceSelector.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "flex w-[inherit] items-center text-base" };
var _hoisted_2 = { class: "m-0 flex items-center gap-1 text-sm font-medium" };
var _hoisted_3 = { class: "line-clamp-1 w-[calc(100%-10px)] text-left text-xs" };
var _hoisted_4 = { class: "overflow-hidden text-ellipsis" };
var _hoisted_5 = { class: "flex h-4 w-4 items-center justify-center" };
var WorkspaceSelector_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "WorkspaceSelector",
	setup(__props) {
		const { activeWorkspace } = useActiveEntities();
		const { workspaces, workspaceMutators } = useWorkspace();
		const { push } = useRouter();
		const modal = useModal();
		const { toast } = useToasts();
		const workspaceName = ref("");
		const updateSelected = (uid) => {
			if (uid === activeWorkspace.value?.uid) return;
			push({
				name: "workspace",
				params: { workspace: uid }
			});
		};
		const handleCreateWorkspace = () => {
			if (!workspaceName.value.trim()) {
				toast("Please enter a name before creating a workspace.", "error");
				return;
			}
			const newWorkspace = workspaceMutators.add({ name: workspaceName.value });
			toast(`Created new workspace '${newWorkspace.name}'`);
			push({
				name: "workspace",
				params: { workspace: newWorkspace.uid }
			});
			workspaceName.value = "";
			modal.hide();
		};
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock(Fragment, null, [createElementVNode("div", _hoisted_1, [createVNode(unref(ScalarDropdown), null, {
				items: withCtx(() => [
					(openBlock(true), createElementBlock(Fragment, null, renderList(unref(workspaces), (workspace, uid) => {
						return openBlock(), createBlock(unref(ScalarDropdownItem), {
							key: uid,
							class: "group/item flex w-full items-center gap-1.5 overflow-hidden text-ellipsis whitespace-nowrap",
							onClick: withModifiers(($event) => updateSelected(uid), ["stop"])
						}, {
							default: withCtx(() => [createElementVNode("div", { class: normalizeClass(["flex h-4 w-4 items-center justify-center rounded-full p-[3px]", unref(activeWorkspace)?.uid === uid ? "bg-c-accent text-b-1" : "shadow-border text-transparent"]) }, [createVNode(unref(ScalarIcon), {
								class: "size-2.5",
								icon: "Checkmark",
								thickness: "3"
							})], 2), createElementVNode("span", _hoisted_4, toDisplayString(workspace.name), 1)]),
							_: 2
						}, 1032, ["onClick"]);
					}), 128)),
					createVNode(unref(ScalarDropdownDivider)),
					createVNode(unref(ScalarDropdownItem), {
						class: "flex items-center gap-1.5",
						onClick: _cache[0] || (_cache[0] = ($event) => unref(modal).show())
					}, {
						default: withCtx(() => [createElementVNode("div", _hoisted_5, [createVNode(unref(ScalarIcon), {
							icon: "Add",
							size: "sm"
						})]), _cache[2] || (_cache[2] = createElementVNode("span", null, "New Workspace", -1))]),
						_: 1
					})
				]),
				default: withCtx(() => [createVNode(unref(ScalarButton), {
					class: "hover:bg-b-2 text-c-3 line-clamp-1 h-full w-fit justify-start px-1.5 py-1 font-normal",
					variant: "ghost"
				}, {
					default: withCtx(() => [createElementVNode("div", _hoisted_2, [createElementVNode("h2", _hoisted_3, toDisplayString(unref(activeWorkspace)?.name), 1), createVNode(unref(ScalarIcon), {
						icon: "ChevronDown",
						size: "md"
					})])]),
					_: 1
				})]),
				_: 1
			})]), createVNode(unref(ScalarModal), {
				bodyClass: "m-0 p-1 rounded-lg border-t-0",
				class: "z-overlay absolute",
				size: "xxs",
				state: unref(modal),
				variant: "form"
			}, {
				default: withCtx(() => [createElementVNode("form", {
					class: "flex gap-1",
					onSubmit: withModifiers(handleCreateWorkspace, ["prevent"])
				}, [withDirectives(createElementVNode("input", {
					"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => workspaceName.value = $event),
					class: "min-h-8 w-full flex-1 border-none p-1.5 text-sm outline-none",
					placeholder: "New Workspace",
					type: "text"
				}, null, 512), [[vModelText, workspaceName.value]]), createVNode(unref(ScalarButton), {
					class: "max-h-8 p-0 px-3 text-xs",
					disabled: !workspaceName.value.trim(),
					type: "submit"
				}, {
					default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode(" Continue ", -1)])]),
					_: 1
				}, 8, ["disabled"])], 32)]),
				_: 1
			}, 8, ["state"])], 64);
		};
	}
});
//#endregion
export { WorkspaceSelector_vue_vue_type_script_setup_true_lang_default as default };

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