import * as e from "react";
import * as y from "react-dom";
import p from "./index-_virtual16.js";
import { jsx as s } from "react/jsx-runtime";
import P from "./index-useForkRef.js";
import T from "./index-getReactElementRef.js";
import f from "./index-useEnhancedEffect2.js";
import c from "./index-setRef.js";
import h from "./index-HTMLElementType.js";
import N from "./index-exactProp.js";
function R(n) {
  return typeof n == "function" ? n() : n;
}
const l = /* @__PURE__ */ e.forwardRef(function(a, i) {
  const {
    children: o,
    container: m,
    disablePortal: r = !1
  } = a, [t, u] = e.useState(null), d = P(/* @__PURE__ */ e.isValidElement(o) ? T(o) : null, i);
  if (f(() => {
    r || u(R(m) || document.body);
  }, [m, r]), f(() => {
    if (t && !r)
      return c(i, t), () => {
        c(i, null);
      };
  }, [i, t, r]), r) {
    if (/* @__PURE__ */ e.isValidElement(o)) {
      const E = {
        ref: d
      };
      return /* @__PURE__ */ e.cloneElement(o, E);
    }
    return /* @__PURE__ */ s(e.Fragment, {
      children: o
    });
  }
  return /* @__PURE__ */ s(e.Fragment, {
    children: t && /* @__PURE__ */ y.createPortal(o, t)
  });
});
process.env.NODE_ENV !== "production" && (l.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * The children to render into the `container`.
   */
  children: p.node,
  /**
   * An HTML element or function that returns one.
   * The `container` will have the portal children appended to it.
   *
   * You can also provide a callback, which is called in a React layout effect.
   * This lets you set the container from a ref, and also makes server-side rendering possible.
   *
   * By default, it uses the body of the top-level document object,
   * so it's simply `document.body` most of the time.
   */
  container: p.oneOfType([h, p.func]),
  /**
   * The `children` will be under the DOM hierarchy of the parent component.
   * @default false
   */
  disablePortal: p.bool
});
process.env.NODE_ENV !== "production" && (l.propTypes = N(l.propTypes));
export {
  l as default
};
