/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-a795c5b | Cube Dev Team */
import { useEffect, useState } from "react";

//#region src/utils/react/useViewportSize.ts
let visualViewport = typeof window !== "undefined" && window.visualViewport;
function useViewportSize(params = {}) {
	const { isDisabled } = params;
	let [size, setSize] = useState(() => getViewportSize());
	useEffect(() => {
		if (isDisabled) return;
		let onResize = () => {
			setSize((size) => {
				let newSize = getViewportSize();
				if (newSize.width === size.width && newSize.height === size.height) return size;
				return newSize;
			});
		};
		if (!visualViewport) window.addEventListener("resize", onResize);
		else visualViewport.addEventListener("resize", onResize);
		return () => {
			if (!visualViewport) window.removeEventListener("resize", onResize);
			else visualViewport.removeEventListener("resize", onResize);
		};
	}, [isDisabled]);
	return size;
}
function getViewportSize() {
	return {
		width: visualViewport && visualViewport.width || (typeof window !== "undefined" ? window.innerWidth : 0),
		height: visualViewport && visualViewport.height || (typeof window !== "undefined" ? window.innerHeight : 0)
	};
}

//#endregion
export { useViewportSize };
//# sourceMappingURL=useViewportSize.js.map