import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/primitives/field/index.ts
var n = class {
	el;
	labelEl = null;
	labelTextNode = null;
	requiredEl = null;
	contentEl;
	hintEl;
	errorEl;
	hintId;
	errorId;
	constructor(n) {
		let r = e("cmm-field");
		this.hintId = `${r}-hint`, this.errorId = `${r}-error`, this.el = document.createElement("div"), this.el.className = "cmm-field", n.className && this.el.classList.add(n.className), n.label !== void 0 && (this.labelEl = document.createElement("label"), this.labelEl.className = "cmm-field__label", n.htmlFor !== void 0 && (this.labelEl.htmlFor = n.htmlFor), this.labelTextNode = document.createTextNode(n.label), this.labelEl.appendChild(this.labelTextNode), n.required === !0 && this.appendRequiredIndicator(), this.el.appendChild(this.labelEl)), this.contentEl = document.createElement("div"), this.contentEl.className = "cmm-field__content", this.el.appendChild(this.contentEl), this.hintEl = document.createElement("div"), this.hintEl.className = "cmm-field__hint", this.hintEl.id = this.hintId, n.hint !== void 0 && (this.hintEl.textContent = n.hint), this.el.appendChild(this.hintEl), this.errorEl = document.createElement("div"), this.errorEl.className = "cmm-field__error", this.errorEl.id = this.errorId, this.errorEl.setAttribute("role", "alert"), n.error !== void 0 && (this.errorEl.textContent = n.error, this.el.classList.add("cmm-field--error")), this.el.appendChild(this.errorEl), n.container !== void 0 && t(n.container).appendChild(this.el);
	}
	setLabel(e) {
		this.labelEl !== null && this.labelTextNode !== null && (this.labelTextNode.textContent = e);
	}
	setError(e) {
		e === null ? (this.errorEl.textContent = "", this.el.classList.remove("cmm-field--error")) : (this.errorEl.textContent = e, this.el.classList.add("cmm-field--error"));
	}
	setHint(e) {
		e === null ? this.hintEl.textContent = "" : this.hintEl.textContent = e;
	}
	setRequired(e) {
		e && this.requiredEl === null ? this.appendRequiredIndicator() : !e && this.requiredEl !== null && (this.requiredEl.remove(), this.requiredEl = null);
	}
	getContentEl() {
		return this.contentEl;
	}
	getHintId() {
		return this.hintId;
	}
	getErrorId() {
		return this.errorId;
	}
	connect(t) {
		let n = `${this.hintId} ${this.errorId}`;
		t.setAttribute("aria-describedby", n);
		let r = t.getAttribute("id");
		if (r !== null && this.labelEl !== null && (this.labelEl.htmlFor = r), r === null && this.labelEl !== null) {
			let n = e("cmm-field-input");
			t.setAttribute("id", n), this.labelEl.htmlFor = n;
		}
	}
	disconnect(e) {
		e.removeAttribute("aria-describedby");
	}
	destroy() {
		this.el.remove();
	}
	appendRequiredIndicator() {
		this.labelEl !== null && (this.requiredEl = document.createElement("span"), this.requiredEl.className = "cmm-field__required", this.requiredEl.setAttribute("aria-hidden", "true"), this.requiredEl.textContent = "*", this.labelEl.appendChild(this.requiredEl));
	}
};
//#endregion
export { n as Field };

//# sourceMappingURL=index.js.map