import { useActiveEntities } from "../../store/active-entities.js";
import { useWorkspace } from "../../store/store.js";
import CommandActionForm_default from "./CommandActionForm.vue.js";
import CommandActionInput_default from "./CommandActionInput.vue.js";
import { computed, createBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, toDisplayString, unref, withCtx } from "vue";
import { ScalarButton, ScalarIcon, ScalarListbox } from "@scalar/components";
import { useToasts } from "@scalar/use-toasts";
//#region src/components/CommandPalette/CommandPaletteTag.vue?vue&type=script&setup=true&lang.ts
var CommandPaletteTag_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "CommandPaletteTag",
	emits: ["close", "back"],
	setup(__props, { emit: __emit }) {
		const emits = __emit;
		const { activeWorkspaceCollections, activeCollection } = useActiveEntities();
		const { tagMutators } = useWorkspace();
		const { toast } = useToasts();
		const availableCollections = computed(() => activeWorkspaceCollections.value.map((collection) => ({
			id: collection.uid,
			label: collection.info?.title ?? ""
		})));
		const name = ref("");
		const selectedCollection = ref(availableCollections.value.find((option) => option.id === activeCollection.value?.uid));
		const handleSubmit = () => {
			if (!name.value) {
				toast("Please enter a name before creating a tag.", "error");
				return;
			}
			if (!name.value || !selectedCollection.value) return;
			if (tagMutators.add({ name: name.value }, selectedCollection.value.id)) emits("close");
		};
		return (_ctx, _cache) => {
			return openBlock(), createBlock(CommandActionForm_default, {
				disabled: !name.value.trim(),
				onSubmit: handleSubmit
			}, {
				options: withCtx(() => [createVNode(unref(ScalarListbox), {
					modelValue: selectedCollection.value,
					"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => selectedCollection.value = $event),
					options: availableCollections.value
				}, {
					default: withCtx(() => [createVNode(unref(ScalarButton), {
						class: "hover:bg-b-2 max-h-8 w-fit justify-between gap-1 p-2 text-xs",
						variant: "outlined"
					}, {
						default: withCtx(() => [createElementVNode("span", { class: normalizeClass(selectedCollection.value ? "text-c-1" : "text-c-3") }, toDisplayString(selectedCollection.value ? selectedCollection.value.label : "Select Collection"), 3), createVNode(unref(ScalarIcon), {
							class: "text-c-3",
							icon: "ChevronDown",
							size: "md"
						})]),
						_: 1
					})]),
					_: 1
				}, 8, ["modelValue", "options"])]),
				submit: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode(" Create Tag ", -1)])]),
				default: withCtx(() => [createVNode(CommandActionInput_default, {
					modelValue: name.value,
					"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => name.value = $event),
					label: "Tag Name",
					placeholder: "Tag Name",
					onOnDelete: _cache[1] || (_cache[1] = ($event) => emits("back", $event))
				}, null, 8, ["modelValue"])]),
				_: 1
			}, 8, ["disabled"]);
		};
	}
});
//#endregion
export { CommandPaletteTag_vue_vue_type_script_setup_true_lang_default as default };

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