import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
//#region src/hooks/useStickToBottom.ts
var i = 60;
function a({ threshold: a = i } = {}) {
	let o = n(null), [s, c] = r(!1), l = n(!0), u = e(() => {
		let e = o.current;
		return e == null ? !0 : e.scrollHeight - e.scrollTop - e.clientHeight <= a;
	}, [a]), d = e(() => {
		let e = o.current;
		e != null && (e.scrollTop = e.scrollHeight, l.current = !0, c(!1));
	}, []), f = e(() => {
		u() ? requestAnimationFrame(d) : c(!0);
	}, [u, d]), p = e(() => {
		let e = u();
		l.current = e, e && c(!1);
	}, [u]);
	return t(() => {
		let e = o.current;
		return e == null ? () => {} : (e.addEventListener("scroll", p), () => {
			e.removeEventListener("scroll", p);
		});
	}, [p]), t(() => {
		let e = o.current;
		if (e == null || typeof ResizeObserver > "u") return () => {};
		let t = new ResizeObserver(() => {
			l.current && requestAnimationFrame(d);
		});
		return t.observe(e), () => {
			t.disconnect();
		};
	}, [d]), t(() => {
		let e = o.current;
		if (e == null || typeof MutationObserver > "u") return () => {};
		let t = new MutationObserver(() => {
			l.current && requestAnimationFrame(d);
		});
		return t.observe(e, {
			childList: !0,
			subtree: !0,
			characterData: !0
		}), () => {
			t.disconnect();
		};
	}, [d]), {
		containerRef: o,
		hasNewItems: s,
		notifyContentChanged: f,
		scrollToBottom: d
	};
}
//#endregion
export { a as useStickToBottom };

//# sourceMappingURL=useStickToBottom.js.map