/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-e980ce7
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef, useCallback, useState } from 'react';
import { createPortal } from 'react-dom';
import { Provider, useProviderProps } from '../../../provider.js';
import { OpenTransition } from './OpenTransition.js';
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]);
    // Don't un-render the overlay while it's transitioning out.
    let mountOverlay = isOpen || !exited;
    if (!mountOverlay) {
        // Don't bother showing anything if we don't have to.
        if (!hideOnClose) {
            return null;
        }
    }
    let contents = (_jsx(Provider, { ref: ref, children: _jsx(OpenTransition, { appear: true, in: isOpen, onExit: onExit, onExiting: onExiting, onExited: handleExited, onEnter: onEnter, onEntering: onEntering, onEntered: handleEntered, children: children }) }));
    return createPortal(contents, container || root || document.body);
}
let _Overlay = forwardRef(Overlay);
_Overlay.displayName = 'Overlay';
export { _Overlay as Overlay };

        