import { getFlattenedDOMTree as e } from "../utils/dom.js";
import { getHostAnchor as t } from "./type-native-popover.utils.js";
//#region src/internal/controllers/type-native-popover-trigger.controller.ts
function n() {
	return (e) => e.addInitializer((e) => new r(e));
}
var r = class {
	constructor(e) {
		this.host = e, this.host.addController(this);
	}
	hostConnected() {
		this.host.addEventListener("click", this.#e);
	}
	hostDisconnected() {
		this.host.removeEventListener("click", this.#e);
	}
	#e = () => {
		let n = this.host, r = this.host.popoverTargetElement;
		!r && this.host.popovertarget && (r = e(this.host.getRootNode()).find((e) => e.id === this.host.popovertarget), this.host.popoverTargetElement = r ?? null), r?.anchor && (n = t(r)), r && !this.host.disabled && (this.host.popoverTargetAction === "hide" ? r.hidePopover() : this.host.popoverTargetAction === "show" ? r.showPopover({ source: n }) : r.togglePopover({ source: n }));
	};
};
//#endregion
export { r as TypeNativePopoverTriggerController, n as typeNativePopoverTrigger };

//# sourceMappingURL=type-native-popover-trigger.controller.js.map