import*as e from"react";import{createPortal as r}from"react-dom";import{usePortalManager as t}from"./portal-manager.js";import{useForceUpdate as n}from"../../../hooks/dist/esm/use-force-update.js";import{useSafeLayoutEffect as a}from"../../../hooks/dist/esm/use-safe-layout-effect.js";import{createContext as o}from"../../../react-utils/dist/esm/context.js";import{__DEV__ as l}from"../../../utils/dist/esm/assertion.js";import{isBrowser as c}from"../../../utils/dist/esm/dom.js";function i(){return(i=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var[s,u]=o({strict:!1,name:"PortalContext"}),m=r=>e.createElement("div",{className:"chakra-portal-zIndex",style:{position:"absolute",zIndex:r.zIndex,top:0,left:0,right:0}},r.children),d=o=>{var{appendToParentPortal:l,children:c}=o,i=e.useRef(null),d=e.useRef(null),p=n(),f=u(),v=t();a((()=>{if(i.current){var e=i.current.ownerDocument,r=l&&null!=f?f:e.body;if(r){d.current=e.createElement("div"),d.current.className="chakra-portal",r.appendChild(d.current),p();var t=d.current;return()=>{r.contains(t)&&r.removeChild(t)}}}}),[]);var h=null!=v&&v.zIndex?e.createElement(m,{zIndex:null==v?void 0:v.zIndex},c):c;return d.current?r(e.createElement(s,{value:d.current},h),d.current):e.createElement("span",{ref:i})},p=t=>{var{children:o,containerRef:l,appendToParentPortal:i}=t,u=l.current,m=null!=u?u:c?document.body:void 0,d=e.useMemo((()=>{var e=null==u?void 0:u.ownerDocument.createElement("div");return e&&(e.className="chakra-portal"),e}),[u]),p=n();return a((()=>{p()}),[]),a((()=>{if(d&&m)return m.appendChild(d),()=>{m.removeChild(d)}}),[d,m]),m&&d?r(e.createElement(s,{value:i?d:null},o),d):null};function f(r){var{containerRef:t}=r,n=function(e,r){if(null==e)return{};var t,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t=o[n],r.indexOf(t)>=0||(a[t]=e[t]);return a}(r,["containerRef"]);return t?e.createElement(p,i({containerRef:t},n)):e.createElement(d,n)}f.defaultProps={appendToParentPortal:!0},f.className="chakra-portal",f.selector=".chakra-portal",l&&(f.displayName="Portal");export{f as Portal};
//# sourceMappingURL=portal.js.map
