import { computed, createElementBlock, defineComponent, mergeProps, nextTick, onMounted, openBlock, ref, vModelText, withDirectives, withKeys } from "vue";
//#region src/components/CommandPalette/CommandActionInput.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = ["placeholder"];
var CommandActionInput_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	inheritAttrs: false,
	__name: "CommandActionInput",
	props: {
		modelValue: {},
		placeholder: {},
		autofocus: { type: Boolean }
	},
	emits: ["update:modelValue", "onDelete"],
	setup(__props, { emit: __emit }) {
		const props = __props;
		const emit = __emit;
		const input = ref(null);
		onMounted(() => nextTick(() => {
			if (props.autofocus) input.value?.focus();
		}));
		const model = computed({
			get: () => props.modelValue ?? "",
			set: (v) => emit("update:modelValue", v)
		});
		/** Re-emits enter as a submit event for the form  */
		function handleEnter(event) {
			if (event.shiftKey || !event.target) return;
			event.preventDefault();
			const target = event.target;
			const submitEvent = new Event("submit", { cancelable: true });
			target.form?.dispatchEvent(submitEvent);
		}
		/** Emits a back event if the input is empty */
		function handleBack(event) {
			if (model.value !== "") return;
			event.preventDefault();
			event.stopPropagation();
			emit("onDelete", event);
		}
		return (_ctx, _cache) => {
			return withDirectives((openBlock(), createElementBlock("textarea", mergeProps({
				id: "command-action-input",
				ref_key: "input",
				ref: input,
				"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => model.value = $event),
				class: "min-h-8 w-full flex-1 resize-none border border-transparent py-1.5 pl-8.5 text-sm outline-none focus:border-b-1",
				placeholder: props.placeholder ?? "",
				wrap: "hard"
			}, _ctx.$attrs, { onKeydown: [_cache[1] || (_cache[1] = withKeys(($event) => handleBack($event), ["delete"])), _cache[2] || (_cache[2] = withKeys(($event) => handleEnter($event), ["enter"]))] }), null, 16, _hoisted_1)), [[vModelText, model.value]]);
		};
	}
});
//#endregion
export { CommandActionInput_vue_vue_type_script_setup_true_lang_default as default };

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