import { useTransformedModel as e } from "../../composition/useTransformedModel.js";
import t from "./pl-editable-title.module.js";
import { computed as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o, mergeModels as s, normalizeClass as c, normalizeStyle as l, onMounted as u, openBlock as d, ref as f, toDisplayString as p, unref as m, useModel as h, vModelText as g, withDirectives as _, withKeys as v } from "vue";
var y = { key: 0 }, b = ["placeholder"], x = /* @__PURE__ */ o({
	__name: "PlEditableTitle",
	props: /* @__PURE__ */ s({
		placeholder: { default: "Title" },
		maxWidth: { default: "80%" },
		prefix: { default: void 0 },
		maxLength: { default: 1e3 },
		minLength: { default: void 0 },
		autofocus: { type: Boolean },
		validate: {
			type: Function,
			default: void 0
		}
	}, {
		modelValue: {},
		modelModifiers: {}
	}),
	emits: ["update:modelValue"],
	setup(o) {
		let s = h(o, "modelValue"), x = o, S = e(s, {
			update() {
				return !1;
			},
			parse: (e) => {
				if (typeof e != "string") throw Error("value should be a string");
				if (x.maxLength && e.length > x.maxLength) throw Error(`Max title length is ${x.maxLength} characters`);
				if (x.minLength && e.length < x.minLength) throw Error(`Min title length is ${x.minLength} characters`);
				return typeof x.validate == "function" && x.validate(e), e.trim();
			}
		}), C = f(), w = n(() => ({ maxWidth: x.maxWidth ?? "80%" })), T = () => {
			s.value = S.value && !S.error ? S.value : s.value, S.reset();
		};
		return u(() => {
			x.autofocus && C.value?.focus();
		}), (e, n) => (d(), i("div", {
			class: c(["pl-editable-title", m(t).component]),
			style: l(w.value)
		}, [a("div", {
			class: c(m(t).container),
			onClick: n[3] ||= () => C.value?.focus()
		}, [o.prefix ? (d(), i("span", y, p(o.prefix.trim()) + "\xA0", 1)) : r("", !0), _(a("input", {
			ref_key: "inputRef",
			ref: C,
			"onUpdate:modelValue": n[0] ||= (e) => m(S).value = e,
			placeholder: o.placeholder,
			onFocusout: T,
			onKeydown: [n[1] ||= v((...e) => m(S).reset && m(S).reset(...e), ["escape"]), n[2] ||= v((e) => e.target?.blur(), ["enter"])]
		}, null, 40, b), [[g, m(S).value]])], 2), m(S).error ? (d(), i("div", {
			key: 0,
			class: c(m(t).error)
		}, p(m(S).error), 3)) : r("", !0)], 6));
	}
});
export { x as default };

//# sourceMappingURL=PlEditableTitle.vue2.js.map