import { endOfScrollBox as e } from "../utils/dom.js";
import { attachInternals as t } from "../utils/a11y.js";
//#region src/internal/controllers/state-scroll.controller.ts
function n() {
	return (e) => e.addInitializer((e) => new r(e));
}
var r = class {
	#e;
	get #t() {
		return this.host.stateScrollConfig?.target || this.host;
	}
	get #n() {
		return this.host.stateScrollConfig?.scrollOffset ?? 0;
	}
	constructor(e) {
		this.host = e, this.host.addController(this);
	}
	async hostConnected() {
		await this.host.updateComplete, t(this.host), this.#r();
	}
	hostUpdated() {
		this.#r();
	}
	hostDisconnected() {
		this.#s();
	}
	#r() {
		let e = this.#t;
		this.#e !== e && (this.#s(), this.#e = e, this.#e.addEventListener("scrollend", this.#i), this.#o());
	}
	#i = () => {
		this.host._internals.states.delete("scrolling"), this.#e && e(this.#e, this.#n) && this.host.dispatchEvent(new CustomEvent("scrollboxend", {
			bubbles: !0,
			composed: !0
		})), this.#o();
	};
	#a = () => {
		this.host._internals.states.add("scrolling");
	};
	#o() {
		this.#e?.removeEventListener("scroll", this.#a), this.#e?.addEventListener("scroll", this.#a, { once: !0 });
	}
	#s() {
		this.#e?.removeEventListener("scroll", this.#a), this.#e?.removeEventListener("scrollend", this.#i), this.#e = void 0;
	}
};
//#endregion
export { r as StateScrollController, n as stateScroll };

//# sourceMappingURL=state-scroll.controller.js.map