import { n as e, t } from "./utils-C_mWfcFX.js";
//#region src/primitives/input/input-group.ts
var n = class {
	el;
	prefixEl = null;
	suffixEl = null;
	contentEl;
	constructor(e) {
		this.el = document.createElement("div"), this.el.className = "cmm-input-group", e.className && this.el.classList.add(e.className), this.contentEl = document.createElement("div"), this.contentEl.className = "cmm-input-group__content", this.el.appendChild(this.contentEl), e.container !== void 0 && t(e.container).appendChild(this.el);
	}
	setPrefix(e) {
		this.prefixEl !== null && this.prefixEl.remove(), this.prefixEl = document.createElement("div"), this.prefixEl.className = "cmm-input-group__prefix", typeof e == "string" ? this.prefixEl.textContent = e : this.prefixEl.appendChild(e), this.el.insertBefore(this.prefixEl, this.contentEl);
	}
	setSuffix(e) {
		this.suffixEl !== null && this.suffixEl.remove(), this.suffixEl = document.createElement("div"), this.suffixEl.className = "cmm-input-group__suffix", typeof e == "string" ? this.suffixEl.textContent = e : this.suffixEl.appendChild(e), this.el.appendChild(this.suffixEl);
	}
	getContentEl() {
		return this.contentEl;
	}
	destroy() {
		this.el.remove();
	}
}, r = class {
	el;
	textareaEl;
	textareaId;
	countEl = null;
	maxLength;
	autoResize;
	handlers;
	constructor(n) {
		this.textareaId = e("cmm-textarea"), this.maxLength = n.maxLength, this.autoResize = n.autoResize === !0, this.el = document.createElement("div"), this.el.className = "cmm-textarea-wrapper", n.className && this.el.classList.add(n.className), this.textareaEl = document.createElement("textarea"), this.textareaEl.id = this.textareaId, this.textareaEl.className = "cmm-textarea", n.placeholder !== void 0 && (this.textareaEl.placeholder = n.placeholder), n.value !== void 0 && (this.textareaEl.value = n.value), n.disabled === !0 && (this.textareaEl.disabled = !0), n.readOnly === !0 && (this.textareaEl.readOnly = !0), n.required === !0 && (this.textareaEl.required = !0, this.textareaEl.setAttribute("aria-required", "true")), n.rows !== void 0 && (this.textareaEl.rows = n.rows), this.maxLength !== void 0 && (this.textareaEl.maxLength = this.maxLength), n.name !== void 0 && (this.textareaEl.name = n.name), n.ariaLabel !== void 0 && this.textareaEl.setAttribute("aria-label", n.ariaLabel), this.el.appendChild(this.textareaEl), this.maxLength !== void 0 && (this.countEl = document.createElement("span"), this.countEl.className = "cmm-textarea__count", this.updateCharCount(), this.el.appendChild(this.countEl)), this.handlers = {
			input: () => {
				this.autoResize && this.adjustHeight(), this.countEl !== null && this.updateCharCount(), n.onInput?.(this.textareaEl.value);
			},
			change: () => {
				n.onChange?.(this.textareaEl.value);
			},
			focus: () => {
				n.onFocus?.();
			},
			blur: () => {
				n.onBlur?.();
			}
		}, this.textareaEl.addEventListener("input", this.handlers.input), this.textareaEl.addEventListener("change", this.handlers.change), this.textareaEl.addEventListener("focus", this.handlers.focus), this.textareaEl.addEventListener("blur", this.handlers.blur), this.autoResize && n.value !== void 0 && this.adjustHeight(), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	getValue() {
		return this.textareaEl.value;
	}
	setValue(e) {
		this.textareaEl.value = e, this.autoResize && this.adjustHeight(), this.countEl !== null && this.updateCharCount();
	}
	setDisabled(e) {
		this.textareaEl.disabled = e;
	}
	setError(e) {
		e ? (this.textareaEl.classList.add("cmm-textarea--error"), this.textareaEl.setAttribute("aria-invalid", "true")) : (this.textareaEl.classList.remove("cmm-textarea--error"), this.textareaEl.removeAttribute("aria-invalid"));
	}
	destroy() {
		this.textareaEl.removeEventListener("input", this.handlers.input), this.textareaEl.removeEventListener("change", this.handlers.change), this.textareaEl.removeEventListener("focus", this.handlers.focus), this.textareaEl.removeEventListener("blur", this.handlers.blur), this.el.remove();
	}
	adjustHeight() {
		this.textareaEl.style.height = "auto", this.textareaEl.style.height = `${String(this.textareaEl.scrollHeight)}px`;
	}
	updateCharCount() {
		this.countEl !== null && this.maxLength !== void 0 && (this.countEl.textContent = `${String(this.textareaEl.value.length)}/${String(this.maxLength)}`);
	}
}, i = class {
	el;
	otpId;
	digitInputs = [];
	length;
	isMasked;
	onComplete;
	onChange;
	inputHandlers = /* @__PURE__ */ new Map();
	constructor(n) {
		this.otpId = e("cmm-otp"), this.length = n.length ?? 6, this.isMasked = n.mask === !0, this.onComplete = n.onComplete, this.onChange = n.onChange, this.el = document.createElement("div"), this.el.className = "cmm-input-otp", this.el.setAttribute("role", "group"), n.ariaLabel === void 0 ? this.el.setAttribute("aria-label", "One-time password input") : this.el.setAttribute("aria-label", n.ariaLabel);
		for (let e = 0; e < this.length; e++) {
			let t = document.createElement("input");
			t.type = this.isMasked ? "password" : "text", t.className = "cmm-input-otp__digit", t.maxLength = 1, t.inputMode = "numeric", t.autocomplete = "one-time-code", t.id = `${this.otpId}-${String(e)}`, t.setAttribute("aria-label", `Digit ${String(e + 1)} of ${String(this.length)}`), n.disabled === !0 && (t.disabled = !0);
			let r = {
				input: (t) => {
					this.handleDigitInput(e, t);
				},
				keydown: (t) => {
					this.handleDigitKeydown(e, t);
				},
				paste: (e) => {
					this.handlePaste(e);
				},
				focus: () => {
					t.select();
				}
			};
			if (t.addEventListener("input", r.input), t.addEventListener("keydown", r.keydown), t.addEventListener("paste", r.paste), t.addEventListener("focus", r.focus), this.inputHandlers.set(t, r), this.digitInputs.push(t), e < this.length - 1 && (e + 1) % 3 == 0 && this.length === 6) {
				this.el.appendChild(t);
				let e = document.createElement("span");
				e.className = "cmm-input-otp__separator", e.textContent = "-", e.setAttribute("aria-hidden", "true"), this.el.appendChild(e);
			} else this.el.appendChild(t);
		}
		n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	getValue() {
		return this.digitInputs.map((e) => e.value).join("");
	}
	setValue(e) {
		for (let t = 0; t < this.length; t++) {
			let n = this.digitInputs[t], r = e[t];
			n !== void 0 && (n.value = r ?? "");
		}
		this.notifyChange();
	}
	clear() {
		for (let e of this.digitInputs) e.value = "";
		let e = this.digitInputs[0];
		e !== void 0 && e.focus(), this.notifyChange();
	}
	setDisabled(e) {
		for (let t of this.digitInputs) t.disabled = e;
	}
	destroy() {
		for (let e of this.digitInputs) {
			let t = this.inputHandlers.get(e);
			t !== void 0 && (e.removeEventListener("input", t.input), e.removeEventListener("keydown", t.keydown), e.removeEventListener("paste", t.paste), e.removeEventListener("focus", t.focus));
		}
		this.inputHandlers.clear(), this.el.remove();
	}
	handleDigitInput(e, t) {
		let n = this.digitInputs[e];
		if (n === void 0) return;
		if (n.value.length > 1 && (n.value = n.value.slice(0, 1)), n.value.length === 1) {
			let t = this.digitInputs[e + 1];
			t !== void 0 && t.focus();
		}
		this.notifyChange();
		let r = this.getValue();
		r.length === this.length && this.onComplete?.(r);
	}
	handleDigitKeydown(e, t) {
		let n = this.digitInputs[e];
		if (n !== void 0) {
			if (t.key === "Backspace") {
				if (n.value === "") {
					let t = this.digitInputs[e - 1];
					t !== void 0 && (t.focus(), t.value = "", this.notifyChange());
				}
			} else if (t.key === "ArrowLeft") {
				let t = this.digitInputs[e - 1];
				t !== void 0 && t.focus();
			} else if (t.key === "ArrowRight") {
				let t = this.digitInputs[e + 1];
				t !== void 0 && t.focus();
			}
		}
	}
	handlePaste(e) {
		e.preventDefault();
		let t = (e.clipboardData?.getData("text") ?? "").replace(/\s/g, "").slice(0, this.length);
		for (let e = 0; e < this.length; e++) {
			let n = this.digitInputs[e], r = t[e];
			n !== void 0 && (n.value = r ?? "");
		}
		let n = Math.min(t.length, this.length - 1), r = this.digitInputs[n];
		r !== void 0 && r.focus(), this.notifyChange(), t.length >= this.length && this.onComplete?.(this.getValue());
	}
	notifyChange() {
		this.onChange?.(this.getValue());
	}
}, a = 4, o = 255, s = 8, c = ".", l = ":", u = class {
	el;
	ipId;
	version;
	segmentCount;
	segmentInputs = [];
	separator;
	onChange;
	inputHandlers = /* @__PURE__ */ new Map();
	constructor(n) {
		this.ipId = e("cmm-ip"), this.version = n.version ?? 4, this.segmentCount = this.version === 4 ? a : s, this.separator = this.version === 4 ? c : l, this.onChange = n.onChange, this.el = document.createElement("div"), this.el.className = `cmm-ip-input cmm-ip-input--v${String(this.version)}`, this.el.setAttribute("role", "group"), n.ariaLabel === void 0 ? this.el.setAttribute("aria-label", `IPv${String(this.version)} address input`) : this.el.setAttribute("aria-label", n.ariaLabel);
		for (let e = 0; e < this.segmentCount; e++) {
			let t = document.createElement("input");
			t.type = "text", t.className = "cmm-ip-input__segment", t.id = `${this.ipId}-${String(e)}`, t.inputMode = this.version === 4 ? "numeric" : "text", t.maxLength = this.version === 4 ? 3 : 4, t.placeholder = this.version === 4 ? "0" : "0000", t.setAttribute("aria-label", `Segment ${String(e + 1)} of ${String(this.segmentCount)}`), n.disabled === !0 && (t.disabled = !0);
			let r = {
				input: (t) => {
					this.handleSegmentInput(e);
				},
				keydown: (t) => {
					this.handleSegmentKeydown(e, t);
				},
				focus: () => {
					t.select();
				}
			};
			if (t.addEventListener("input", r.input), t.addEventListener("keydown", r.keydown), t.addEventListener("focus", r.focus), this.inputHandlers.set(t, r), this.segmentInputs.push(t), this.el.appendChild(t), e < this.segmentCount - 1) {
				let e = document.createElement("span");
				e.className = "cmm-ip-input__separator", e.textContent = this.separator, e.setAttribute("aria-hidden", "true"), this.el.appendChild(e);
			}
		}
		n.value !== void 0 && this.setValue(n.value), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	getValue() {
		return this.segmentInputs.map((e) => e.value).join(this.separator);
	}
	setValue(e) {
		let t = e.split(this.separator);
		for (let e = 0; e < this.segmentCount; e++) {
			let n = this.segmentInputs[e], r = t[e];
			n !== void 0 && (n.value = r ?? "");
		}
	}
	setDisabled(e) {
		for (let t of this.segmentInputs) t.disabled = e;
	}
	destroy() {
		for (let e of this.segmentInputs) {
			let t = this.inputHandlers.get(e);
			t !== void 0 && (e.removeEventListener("input", t.input), e.removeEventListener("keydown", t.keydown), e.removeEventListener("focus", t.focus));
		}
		this.inputHandlers.clear(), this.el.remove();
	}
	handleSegmentInput(e) {
		let t = this.segmentInputs[e];
		if (t === void 0) return;
		this.version === 4 ? this.sanitizeIPv4Segment(t) : this.sanitizeIPv6Segment(t);
		let n = this.version === 4 ? 3 : 4;
		if (t.value.length >= n) {
			let t = this.segmentInputs[e + 1];
			t !== void 0 && t.focus();
		}
		this.onChange?.(this.getValue());
	}
	handleSegmentKeydown(e, t) {
		let n = this.segmentInputs[e];
		if (n !== void 0) {
			if (this.version === 4 && t.key === "." || this.version === 6 && t.key === ":") {
				t.preventDefault();
				let n = this.segmentInputs[e + 1];
				n !== void 0 && n.focus();
				return;
			}
			if (t.key === "Backspace" && n.value === "") {
				let t = this.segmentInputs[e - 1];
				t !== void 0 && t.focus();
			} else if (t.key === "ArrowLeft" && n.selectionStart === 0) {
				let t = this.segmentInputs[e - 1];
				t !== void 0 && t.focus();
			} else if (t.key === "ArrowRight" && n.selectionStart === n.value.length) {
				let t = this.segmentInputs[e + 1];
				t !== void 0 && t.focus();
			}
		}
	}
	sanitizeIPv4Segment(e) {
		let t = e.value.replace(/[^0-9]/g, ""), n = parseInt(t, 10);
		t === "" || Number.isNaN(n) ? e.value = "" : n > o ? e.value = String(o) : e.value = t;
	}
	sanitizeIPv6Segment(e) {
		e.value = e.value.replace(/[^0-9a-fA-F]/g, "").slice(0, 4);
	}
}, d = class {
	el;
	inputEl;
	inputId;
	currentSize;
	handlers;
	constructor(n) {
		this.inputId = e("cmm-input"), this.currentSize = n.size ?? "md", this.el = document.createElement("div"), this.el.className = "cmm-input-wrapper", this.inputEl = document.createElement("input"), this.inputEl.id = this.inputId, this.inputEl.type = n.type ?? "text", this.inputEl.className = `cmm-input cmm-input--${this.currentSize}`, n.className && this.el.classList.add(n.className), n.placeholder !== void 0 && (this.inputEl.placeholder = n.placeholder), n.value !== void 0 && (this.inputEl.value = n.value), n.disabled === !0 && (this.inputEl.disabled = !0), n.readOnly === !0 && (this.inputEl.readOnly = !0), n.required === !0 && (this.inputEl.required = !0, this.inputEl.setAttribute("aria-required", "true")), n.name !== void 0 && (this.inputEl.name = n.name), n.ariaLabel !== void 0 && this.inputEl.setAttribute("aria-label", n.ariaLabel), n.maxLength !== void 0 && (this.inputEl.maxLength = n.maxLength), n.pattern !== void 0 && (this.inputEl.pattern = n.pattern), n.autocomplete !== void 0 && this.inputEl.setAttribute("autocomplete", n.autocomplete), this.handlers = {
			input: (e) => {
				n.onInput?.(this.inputEl.value);
			},
			change: (e) => {
				n.onChange?.(this.inputEl.value);
			},
			focus: () => {
				n.onFocus?.();
			},
			blur: () => {
				n.onBlur?.();
			},
			keydown: (e) => {
				n.onKeyDown?.(e);
			}
		}, this.inputEl.addEventListener("input", this.handlers.input), this.inputEl.addEventListener("change", this.handlers.change), this.inputEl.addEventListener("focus", this.handlers.focus), this.inputEl.addEventListener("blur", this.handlers.blur), this.inputEl.addEventListener("keydown", this.handlers.keydown), this.el.appendChild(this.inputEl), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	getValue() {
		return this.inputEl.value;
	}
	setValue(e) {
		this.inputEl.value = e;
	}
	setDisabled(e) {
		this.inputEl.disabled = e;
	}
	setError(e) {
		e ? (this.inputEl.classList.add("cmm-input--error"), this.inputEl.setAttribute("aria-invalid", "true")) : (this.inputEl.classList.remove("cmm-input--error"), this.inputEl.removeAttribute("aria-invalid"));
	}
	focus() {
		this.inputEl.focus();
	}
	blur() {
		this.inputEl.blur();
	}
	destroy() {
		this.inputEl.removeEventListener("input", this.handlers.input), this.inputEl.removeEventListener("change", this.handlers.change), this.inputEl.removeEventListener("focus", this.handlers.focus), this.inputEl.removeEventListener("blur", this.handlers.blur), this.inputEl.removeEventListener("keydown", this.handlers.keydown), this.el.remove();
	}
};
//#endregion
export { n as a, r as i, u as n, i as r, d as t };

//# sourceMappingURL=input-DwHjxF_w.js.map