/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

require("../../_virtual/_rolldown/runtime.js");
const require_useIsomorphicEffect = require("../../global/js/hooks/useIsomorphicEffect.js");
let react = require("react");
//#region src/components/ScrollGradient/constants.js
/**
* Copyright IBM Corp. 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const ScrollStates = {
	NONE: "NONE",
	INITIAL: "INITIAL",
	STARTED: "STARTED",
	END: "END"
};
const useIsOverflow = (ref) => {
	const [isHorizontallyScrollable, setIsHorizontallyScrollable] = (0, react.useState)();
	const [isVerticallyScrollable, setIsVerticallyScrollable] = (0, react.useState)();
	const [mutationObserver, setMutationObserver] = (0, react.useState)();
	const [resizeObserver, setResizeObserver] = (0, react.useState)();
	const checkOverflow = (0, react.useCallback)(() => {
		if (!ref.current) return;
		setIsHorizontallyScrollable(ref.current.scrollWidth > ref.current.clientWidth);
		setIsVerticallyScrollable(ref.current.scrollHeight > ref.current.clientHeight);
	}, [ref]);
	(0, react.useEffect)(() => {
		if (!mutationObserver) return;
		return () => {
			if (mutationObserver) mutationObserver.disconnect();
			if (resizeObserver) resizeObserver.disconnect();
		};
	});
	require_useIsomorphicEffect.useIsomorphicEffect(() => {
		const { current } = ref;
		if (current) {
			if ("ResizeObserver" in window && !resizeObserver) setResizeObserver(new ResizeObserver(checkOverflow).observe(current));
			if ("MutationObserver" in window && !mutationObserver) setMutationObserver(new MutationObserver(checkOverflow).observe(current, {
				attributes: false,
				childList: true,
				subtree: false
			}));
			checkOverflow();
		}
	}, [
		ref,
		checkOverflow,
		mutationObserver,
		resizeObserver
	]);
	return {
		xScrollable: isHorizontallyScrollable,
		yScrollable: isVerticallyScrollable
	};
};
//#endregion
exports.ScrollStates = ScrollStates;
exports.useIsOverflow = useIsOverflow;
