import { getFlattenedDOMTree as e } from "../utils/dom.js";
//#region src/internal/controllers/type-interest.controller.ts
function t() {
	return (e) => e.addInitializer((e) => new n(e));
}
var n = class {
	#e = !1;
	constructor(e) {
		this.host = e, this.host.addController(this);
	}
	async hostConnected() {
		await this.#t();
	}
	async hostUpdated() {
		await this.#t();
	}
	hostDisconnected() {
		this.#n();
	}
	async #t() {
		await this.host.updateComplete, this.#e || (this.#e = !0, this.host.addEventListener("mouseenter", this.#r), this.host.addEventListener("mouseleave", this.#i), this.host.addEventListener("focus", this.#r), this.host.addEventListener("blur", this.#i));
	}
	#n() {
		this.#e = !1, this.host.removeEventListener("mouseenter", this.#r), this.host.removeEventListener("mouseleave", this.#i), this.host.removeEventListener("focus", this.#r), this.host.removeEventListener("blur", this.#i);
	}
	#r = () => {
		if (this.#a(), this.host.interestForElement) {
			let e = new Event("interest", { cancelable: !0 });
			e.source = this.host, this.host.interestForElement.dispatchEvent(e);
		}
	};
	#i = () => {
		if (this.#a(), this.host.interestForElement) {
			let e = new Event("loseinterest", { cancelable: !0 });
			e.source = this.host, this.host.interestForElement.dispatchEvent(e);
		}
	};
	#a() {
		let t = this.host.getAttribute("interestfor");
		t && !this.host.interestForElement && (this.host.interestForElement = e(this.host.getRootNode()).find((e) => e.id === t));
		let n = this.host.getAttribute("popovertarget");
		if (n && !t) {
			let t = e(this.host.getRootNode()).find((e) => e.id === n);
			t && t.popover === "hint" && (this.host.interestForElement = t);
		}
	}
};
//#endregion
export { n as TypeInterestController, t as typeInterest };

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