import { getFlattenedDOMTree as e } from "../utils/dom.js";
//#region src/internal/controllers/type-command.controller.ts
function t() {
	return (e) => e.addInitializer((e) => new n(e));
}
var n = class {
	#e;
	constructor(e, t = {}) {
		this.host = e, this.#e = t.trigger ?? "click", this.host.addController(this);
	}
	get target() {
		return this.host.commandForElement ? this.host.commandForElement : this.host.commandfor ? e(this.host.getRootNode()).find((e) => e.id === this.host.commandfor) ?? null : null;
	}
	async hostUpdated() {
		await this.host.updateComplete, this.#n();
	}
	hostDisconnected() {
		this.host.removeEventListener("click", this.#r);
	}
	get #t() {
		return this.host.readOnly || this.host.readonly === !0;
	}
	#n() {
		this.#e === "manual" || this.#t || this.host.disabled ? this.host.removeEventListener("click", this.#r) : this.host.addEventListener("click", this.#r);
	}
	#r = (e) => {
		e.defaultPrevented || this.dispatchCommand();
	};
	dispatchCommand() {
		if (this.#t || this.host.disabled || !this.host.command) return !1;
		let e = this.target;
		return e ? (e.dispatchEvent(new globalThis.CommandEvent("command", {
			command: this.host.command,
			source: this.host
		})), !0) : ((this.host.commandfor || this.host.commandForElement) && console.warn("commandForElement", this.host.commandfor || this.host.commandForElement, "not found"), !1);
	}
};
//#endregion
export { n as TypeCommandController, t as typeCommand };

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