import { stopEvent as e } from "../utils/events.js";
import { onKeys as t } from "../utils/keynav.js";
//#region src/internal/controllers/type-submit.controller.ts
function n() {
	return (e) => e.addInitializer((e) => new r(e));
}
var r = class {
	constructor(e) {
		this.host = e, this.host.addController(this);
	}
	async hostUpdated() {
		await this.host.updateComplete, this.#e(), this.#t();
	}
	hostDisconnected() {
		this.#n();
	}
	#e() {
		!this.host.type && !this.host.hasAttribute("type") && this.host.closest("form") && (this.host.type = "submit");
	}
	#t() {
		this.#n(), !this.host.readOnly && !this.host.disabled && (this.host.addEventListener("click", this.#i), this.host.addEventListener("keyup", this.#r));
	}
	#n() {
		this.host.removeEventListener("click", this.#i), this.host.removeEventListener("keyup", this.#r);
	}
	#r = (e) => {
		t(["Enter", "Space"], e, () => this.host.click());
	};
	#i = (t) => {
		if (this.host.disabled) {
			e(t);
			return;
		}
		this.host.type === "submit" && this.host.form ? this.#a() : this.host.type === "reset" && this.host.form?.reset();
	};
	#a() {
		this.#s(), this.host.form.addEventListener("submit", () => {
			setTimeout(() => this.#o.remove(), 0);
		}, { once: !0 }), this.host.form.appendChild(this.#o), this.host.form.requestSubmit(this.#o);
	}
	#o;
	#s() {
		this.#o || (this.#o = globalThis.document.createElement("button"), this.#o.type = "submit", this.#o.name = this.host.name ?? "", this.#o.value = this.host.value ?? "", this.#o.style.display = "none");
	}
};
//#endregion
export { r as TypeSubmitController, n as typeSubmit };

//# sourceMappingURL=type-submit.controller.js.map