import { jsx as m } from "react/jsx-runtime";
import { useContext as d, Component as f } from "react";
import { usePresence as c } from "../../../components/AnimatePresence/use-presence.es.js";
import { LayoutGroupContext as l } from "../../../context/LayoutGroupContext.es.js";
import { SwitchLayoutGroupContext as h } from "../../../context/SwitchLayoutGroupContext.es.js";
import { globalProjectionState as R } from "../../../projection/node/state.es.js";
import { correctBorderRadius as n } from "../../../projection/styles/scale-border-radius.es.js";
import { correctBoxShadow as g } from "../../../projection/styles/scale-box-shadow.es.js";
import { addScaleCorrector as y } from "../../../projection/styles/scale-correction.es.js";
import { frame as T } from "../../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/frameloop/frame.es.js";
import { microtask as v } from "../../../../../../../../motion-dom@12.23.23/node_modules/motion-dom/dist/es/frameloop/microtask.es.js";
let a = !1;
class L extends f {
  /**
   * This only mounts projection nodes for components that
   * need measuring, we might want to do it for all components
   * in order to incorporate transforms
   */
  componentDidMount() {
    const { visualElement: e, layoutGroup: t, switchLayoutGroup: r, layoutId: s } = this.props, { projection: o } = e;
    y(b), o && (t.group && t.group.add(o), r && r.register && s && r.register(o), a && o.root.didUpdate(), o.addEventListener("animationComplete", () => {
      this.safeToRemove();
    }), o.setOptions({
      ...o.options,
      onExitComplete: () => this.safeToRemove()
    })), R.hasEverUpdated = !0;
  }
  getSnapshotBeforeUpdate(e) {
    const { layoutDependency: t, visualElement: r, drag: s, isPresent: o } = this.props, { projection: i } = r;
    return i && (i.isPresent = o, a = !0, s || e.layoutDependency !== t || t === void 0 || e.isPresent !== o ? i.willUpdate() : this.safeToRemove(), e.isPresent !== o && (o ? i.promote() : i.relegate() || T.postRender(() => {
      const u = i.getStack();
      (!u || !u.members.length) && this.safeToRemove();
    }))), null;
  }
  componentDidUpdate() {
    const { projection: e } = this.props.visualElement;
    e && (e.root.didUpdate(), v.postRender(() => {
      !e.currentAnimation && e.isLead() && this.safeToRemove();
    }));
  }
  componentWillUnmount() {
    const { visualElement: e, layoutGroup: t, switchLayoutGroup: r } = this.props, { projection: s } = e;
    a = !0, s && (s.scheduleCheckAfterUnmount(), t && t.group && t.group.remove(s), r && r.deregister && r.deregister(s));
  }
  safeToRemove() {
    const { safeToRemove: e } = this.props;
    e && e();
  }
  render() {
    return null;
  }
}
function D(p) {
  const [e, t] = c(), r = d(l);
  return m(L, { ...p, layoutGroup: r, switchLayoutGroup: d(h), isPresent: e, safeToRemove: t });
}
const b = {
  borderRadius: {
    ...n,
    applyTo: [
      "borderTopLeftRadius",
      "borderTopRightRadius",
      "borderBottomLeftRadius",
      "borderBottomRightRadius"
    ]
  },
  borderTopLeftRadius: n,
  borderTopRightRadius: n,
  borderBottomLeftRadius: n,
  borderBottomRightRadius: n,
  boxShadow: g
};
export {
  D as MeasureLayout
};
//# sourceMappingURL=MeasureLayout.es.js.map
