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

import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { createPortal } from 'react-dom';
import { usePortal } from './usePortal.js';
/**
 * This component renders its children outside the current DOM hierarchy.
 *
 * React [doesn't support](https://github.com/facebook/react/issues/13097) portal API in SSR, so, if you want to
 * render a Portal in SSR, use prop `disabled`.
 *
 * By default, Portal's children render under the `<Root />` component.
 *
 * ***Important***: Since React doesn't support portals on SSR, `<Portal />` children renders in the next tick.
 * If you need to make some computations, use the `onMount` callback
 *
 * @see https://reactjs.org/docs/portals.html
 *
 * @example ```jsx
 *  <div>
 *    Portal will be rendered outside me!
 *
 *    <Portal>
 *      <div>some content will be shown outside the parent container</div>
 *    </Portal>
 *  </div>
 * ```
 */
export function Portal(props) {
    const { children, mountRoot, isDisabled } = usePortal(props);
    if (isDisabled)
        return _jsx(_Fragment, { children: children });
    // Render inline until mountRoot is available (fixes timing issues in tests and SSR)
    if (!mountRoot)
        return _jsx(_Fragment, { children: children });
    return createPortal(children, mountRoot);
}

        