/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-f1f3d22 | Cube Dev Team */
import { Provider, useProviderProps } from "../../../provider.js";
import { OpenTransition } from "./OpenTransition.js";
import { forwardRef, useCallback, useState } from "react";
import { jsx } from "react/jsx-runtime";
import { createPortal } from "react-dom";

//#region src/components/overlays/Modal/Overlay.tsx
function Overlay(props, ref) {
	let { children, isOpen, container = null, onEnter, onEntering, onEntered, onExit, onExiting, onExited, hideOnClose = false } = props;
	let [exited, setExited] = useState(!isOpen);
	let { root } = useProviderProps({});
	let handleEntered = useCallback(() => {
		setExited(false);
		onEntered?.();
	}, [onEntered]);
	let handleExited = useCallback(() => {
		setExited(true);
		onExited?.();
	}, [onExited]);
	if (!(isOpen || !exited)) {
		if (!hideOnClose) return null;
	}
	return createPortal(/* @__PURE__ */ jsx(Provider, {
		ref,
		children: /* @__PURE__ */ jsx(OpenTransition, {
			appear: true,
			in: isOpen,
			onExit,
			onExiting,
			onExited: handleExited,
			onEnter,
			onEntering,
			onEntered: handleEntered,
			children
		})
	}), container || root || document.body);
}
let _Overlay = forwardRef(Overlay);
_Overlay.displayName = "Overlay";

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