"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("../../../../../../react/jsx-runtime.js");var e=require("react"),t=require("../../../components/AnimatePresence/use-presence.mjs.js"),o=require("../../../context/LayoutGroupContext.mjs.js"),s=require("../../../context/SwitchLayoutGroupContext.mjs.js"),r=require("../../../../../../motion-dom/dist/es/projection/node/state.mjs.js"),n=require("../../../../../../motion-dom/dist/es/frameloop/frame.mjs.js"),i=require("../../../../../../motion-dom/dist/es/frameloop/microtask.mjs.js"),u=require("../../../../../../../_virtual/jsx-runtime.js");let a=!1;class p extends e.Component{componentDidMount(){const{visualElement:e,layoutGroup:t,switchLayoutGroup:o,layoutId:s}=this.props,{projection:n}=e;n&&(t.group&&t.group.add(n),o&&o.register&&s&&o.register(n),a&&n.root.didUpdate(),n.addEventListener("animationComplete",(()=>{this.safeToRemove()})),n.setOptions({...n.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),r.globalProjectionState.hasEverUpdated=!0}getSnapshotBeforeUpdate(e){const{layoutDependency:t,visualElement:o,drag:s,isPresent:r}=this.props,{projection:i}=o;return i?(i.isPresent=r,e.layoutDependency!==t&&i.setOptions({...i.options,layoutDependency:t}),a=!0,s||e.layoutDependency!==t||void 0===t||e.isPresent!==r?i.willUpdate():this.safeToRemove(),e.isPresent!==r&&(r?i.promote():i.relegate()||n.frame.postRender((()=>{const e=i.getStack();e&&e.members.length||this.safeToRemove()}))),null):null}componentDidUpdate(){const{visualElement:e,layoutAnchor:t}=this.props,{projection:o}=e;o&&(o.options.layoutAnchor=t,o.root.didUpdate(),i.microtask.postRender((()=>{!o.currentAnimation&&o.isLead()&&this.safeToRemove()})))}componentWillUnmount(){const{visualElement:e,layoutGroup:t,switchLayoutGroup:o}=this.props,{projection:s}=e;a=!0,s&&(s.scheduleCheckAfterUnmount(),t&&t.group&&t.group.remove(s),o&&o.deregister&&o.deregister(s))}safeToRemove(){const{safeToRemove:e}=this.props;e&&e()}render(){return null}}exports.MeasureLayout=function(r){const[n,i]=t.usePresence(),a=e.useContext(o.LayoutGroupContext);return u.exports.jsx(p,{...r,layoutGroup:a,switchLayoutGroup:e.useContext(s.SwitchLayoutGroupContext),isPresent:n,safeToRemove:i})};
//# sourceMappingURL=MeasureLayout.mjs.js.map
