import { getAttributeChanges as e, getAttributeListChanges as t, getElementUpdate as n, matchesElementName as r } from "../../internal/utils/dom.js";
import { ControlMessage as i } from "../control-message/control-message2.js";
//#region src/forms/utils/states.ts
var a = "input, select, selectmenu, textarea, [nve-control]";
function o(e, t) {
	let n = [];
	if (!e.input.form?.noValidate && !e.input.formNoValidate && !e.input.hasAttribute("formnovalidate")) {
		m(t);
		let r = () => {
			e.input.validity?.valid && (e._internals.states.delete("invalid"), e._internals.states.add("valid"), e.status = null), g(e, t);
		}, i = () => {
			e.status = null, e._internals.states.delete("valid"), e._internals.states.delete("invalid"), m(t);
		};
		n.push(f(e.input, "blur", () => {
			e.input.checkValidity(), r();
		}), f(e.input, "input", () => {
			r();
		}), f(e.input, "invalid", () => {
			t.find((e) => e.error) && (m(t), h(e, t)), e.status = "error", e._internals.states.delete("valid"), e._internals.states.add("invalid");
		}), f(e, "reset", i)), e.input.form && n.push(f(e.input.form, "reset", i));
	}
	return n.push(f(e.shadowRoot, "slotchange", () => {
		let t = Array.from(e.querySelectorAll(i.metadata.tag));
		e._internals.states.delete("valid"), e._internals.states.delete("invalid"), t.find((e) => !e.hidden && (e.status === "error" || e.error)) ? e._internals.states.add("invalid") : e._internals.states.add("valid");
	})), n;
}
function s(e) {
	let t = [], r = e._internals.states;
	return e.input.checked ? r.add("checked") : r.delete("checked"), e.input.indeterminate ? r.add("indeterminate") : r.delete("indeterminate"), t.push(...c(e)), t.push(n(e.input, "readonly", (e) => e === "" || e ? r.add("readonly") : r.delete("readonly")), n(e.input, "checked", () => e.input.checked ? r.add("checked") : r.delete("checked")), n(e.input, "disabled", (e) => e === "" || e ? r.add("disabled") : r.delete("disabled")), n(e.input, "indeterminate", () => e.input.indeterminate ? r.add("indeterminate") : r.delete("indeterminate"))), t;
}
function c(e) {
	let t = [], n = e._internals.states;
	return t.push(f(e.input, "focus", () => e._internals.states.add("focus")), f(e.input, "input", () => e._internals.states.add("dirty")), f(e.input, "blur", () => {
		e._internals.states.add("touched"), e._internals.states.delete("focus");
	}), f(e.input.getRootNode(), "change", (t) => {
		t.target.name === e.input?.name && (e.input.checked ? n.add("checked") : n.delete("checked"));
	})), e.input.form && t.push(f(e.input.form, "reset", () => {
		e._internals.states.delete("touched"), e._internals.states.delete("dirty"), e._internals.states.delete("error"), e._internals.states.delete("success"), e.requestUpdate();
	})), t;
}
function l(t) {
	return u(t), e(t, "disabled", () => u(t));
}
function u(e) {
	Array.from(e.inputs).find((e) => e.disabled) ? e._internals.states.add("disabled") : e._internals.states.delete("disabled");
}
function d(e, n) {
	p(e, n.find((e) => !e.hidden));
	let a = [];
	return a.push(t(e, ["hidden", "status"], (t) => {
		let n = t.target;
		r(n, i) && p(e, n);
	})), a.push(f(e.shadowRoot, "slotchange", () => {
		let t = Array.from(e.querySelectorAll(i.metadata.tag)).find((e) => e.status && !e.hidden);
		e._internals.states.delete("error"), e._internals.states.delete("success"), t && e._internals.states.add(t.status);
	})), a;
}
function f(e, t, n) {
	return e.addEventListener(t, n), { disconnect: () => e.removeEventListener(t, n) };
}
function p(e, t) {
	e._internals.states.delete("error"), e._internals.states.delete("success"), t?.status?.length && !t?.hidden && e._internals.states.add(t.status);
}
function m(e) {
	e.filter((e) => e.hasAttribute("error")).forEach((e) => e.setAttribute("hidden", ""));
}
function h(e, t) {
	t.find((t) => t.error && e.input.validity[t.error])?.removeAttribute("hidden");
}
function g(e, t) {
	t.find((e) => e.error) && e.input.validity.valid && t.filter((t) => t.error && !e.input.validity[t.error]).forEach((e) => e.setAttribute("hidden", ""));
}
//#endregion
export { a as inputQuery, l as setupControlGroupStates, s as setupControlStates, d as setupControlStatusStates, o as setupControlValidationStates };

//# sourceMappingURL=states.js.map