import{r as e}from"./index.d8a7997a.js";import{u as M,s as v,a as $,P as b,L as U,b as A}from"./235a11b8.js";function I(){const n=e.exports.useRef(!1);return M(()=>(n.current=!0,()=>{n.current=!1}),[]),n}function K(){const n=I(),[o,t]=e.exports.useState(0),r=e.exports.useCallback(()=>{n.current&&t(o+1)},[o]);return[e.exports.useCallback(()=>v.postRender(r),[r]),o]}class O extends e.exports.Component{getSnapshotBeforeUpdate(o){const t=this.props.childRef.current;if(t&&o.isPresent&&!this.props.isPresent){const r=this.props.sizeRef.current;r.height=t.offsetHeight||0,r.width=t.offsetWidth||0,r.top=t.offsetTop,r.left=t.offsetLeft}return null}componentDidUpdate(){}render(){return this.props.children}}function S({children:n,isPresent:o}){const t=e.exports.useId(),r=e.exports.useRef(null),x=e.exports.useRef({width:0,height:0,top:0,left:0});return e.exports.useInsertionEffect(()=>{const{width:f,height:i,top:u,left:m}=x.current;if(o||!r.current||!f||!i)return;r.current.dataset.motionPopId=t;const a=document.createElement("style");return document.head.appendChild(a),a.sheet&&a.sheet.insertRule(` [data-motion-pop-id="${t}"] { position: absolute !important; width: ${f}px !important; height: ${i}px !important; top: ${u}px !important; left: ${m}px !important; } `),()=>{document.head.removeChild(a)}},[o]),e.exports.createElement(O,{isPresent:o,childRef:r,sizeRef:x},e.exports.cloneElement(n,{ref:r}))}const g=({children:n,initial:o,isPresent:t,onExitComplete:r,custom:x,presenceAffectsLayout:f,mode:i})=>{const u=$(G),m=e.exports.useId(),a=e.exports.useMemo(()=>({id:m,initial:o,isPresent:t,custom:x,onExitComplete:p=>{u.set(p,!0);for(const c of u.values())if(!c)return;r&&r()},register:p=>(u.set(p,!1),()=>u.delete(p))}),f?void 0:[t]);return e.exports.useMemo(()=>{u.forEach((p,c)=>u.set(c,!1))},[t]),e.exports.useEffect(()=>{!t&&!u.size&&r&&r()},[t]),i==="popLayout"&&(n=e.exports.createElement(S,{isPresent:t},n)),e.exports.createElement(b.Provider,{value:a},n)};function G(){return new Map}const h=n=>n.key||"";function T(n,o){n.forEach(t=>{const r=h(t);o.set(r,t)})}function B(n){const o=[];return e.exports.Children.forEach(n,t=>{e.exports.isValidElement(t)&&o.push(t)}),o}const V=({children:n,custom:o,initial:t=!0,onExitComplete:r,exitBeforeEnter:x,presenceAffectsLayout:f=!0,mode:i="sync"})=>{x&&(i="wait");let[u]=K();const m=e.exports.useContext(U).forceRender;m&&(u=m);const a=I(),p=B(n);let c=p;const d=new Set,R=e.exports.useRef(c),C=e.exports.useRef(new Map).current,E=e.exports.useRef(!0);if(M(()=>{E.current=!1,T(p,C),R.current=c}),A(()=>{E.current=!0,C.clear(),d.clear()}),E.current)return e.exports.createElement(e.exports.Fragment,null,c.map(s=>e.exports.createElement(g,{key:h(s),isPresent:!0,initial:t?void 0:!1,presenceAffectsLayout:f,mode:i},s)));c=[...c];const y=R.current.map(h),w=p.map(h),P=y.length;for(let s=0;s<P;s++){const l=y[s];w.indexOf(l)===-1&&d.add(l)}return i==="wait"&&d.size&&(c=[]),d.forEach(s=>{if(w.indexOf(s)!==-1)return;const l=C.get(s);if(!l)return;const z=y.indexOf(s),L=()=>{C.delete(s),d.delete(s);const k=R.current.findIndex(F=>F.key===s);if(R.current.splice(k,1),!d.size){if(R.current=p,a.current===!1)return;u(),r&&r()}};c.splice(z,0,e.exports.createElement(g,{key:h(l),isPresent:!1,onExitComplete:L,custom:o,presenceAffectsLayout:f,mode:i},l))}),c=c.map(s=>{const l=s.key;return d.has(l)?s:e.exports.createElement(g,{key:h(s),isPresent:!0,presenceAffectsLayout:f,mode:i},s)}),e.exports.createElement(e.exports.Fragment,null,d.size?c:c.map(s=>e.exports.cloneElement(s)))};export{V as A}; //# sourceMappingURL=1b011c46.js.map