import { __extends as v, __assign as d, __read as y } from "../../../../../../tslib/tslib.es6.es.js";
import h from "../../../../../../framesync/dist/es/index.es.js";
import c, { useContext as f } from "react";
import { usePresence as R } from "../../../components/AnimatePresence/use-presence.es.js";
import { LayoutGroupContext as g } from "../../../context/LayoutGroupContext.es.js";
import { SwitchLayoutGroupContext as L } from "../../../context/SwitchLayoutGroupContext.es.js";
import { globalProjectionState as T } from "../../../projection/node/state.es.js";
import { correctBorderRadius as p } from "../../../projection/styles/scale-border-radius.es.js";
import { correctBoxShadow as _ } from "../../../projection/styles/scale-box-shadow.es.js";
import { addScaleCorrector as b } from "../../../projection/styles/scale-correction.es.js";
var C = function(s) {
  v(r, s);
  function r() {
    return s !== null && s.apply(this, arguments) || this;
  }
  return r.prototype.componentDidMount = function() {
    var o = this, a = this.props, e = a.visualElement, t = a.layoutGroup, i = a.switchLayoutGroup, l = a.layoutId, n = e.projection;
    b(G), n && (t != null && t.group && t.group.add(n), (i == null ? void 0 : i.register) && l && i.register(n), n.root.didUpdate(), n.addEventListener("animationComplete", function() {
      o.safeToRemove();
    }), n.setOptions(d(d({}, n.options), { onExitComplete: function() {
      return o.safeToRemove();
    } }))), T.hasEverUpdated = !0;
  }, r.prototype.getSnapshotBeforeUpdate = function(o) {
    var a = this, e = this.props, t = e.layoutDependency, i = e.visualElement, l = e.drag, n = e.isPresent, u = i.projection;
    return u && (u.isPresent = n, l || o.layoutDependency !== t || t === void 0 ? u.willUpdate() : this.safeToRemove(), o.isPresent !== n && (n ? u.promote() : u.relegate() || h.postRender(function() {
      var m;
      !((m = u.getStack()) === null || m === void 0) && m.members.length || a.safeToRemove();
    }))), null;
  }, r.prototype.componentDidUpdate = function() {
    var o = this.props.visualElement.projection;
    o && (o.root.didUpdate(), !o.currentAnimation && o.isLead() && this.safeToRemove());
  }, r.prototype.componentWillUnmount = function() {
    var o = this.props, a = o.visualElement, e = o.layoutGroup, t = o.switchLayoutGroup, i = a.projection;
    i && (i.scheduleCheckAfterUnmount(), e != null && e.group && e.group.remove(i), t != null && t.deregister && t.deregister(i));
  }, r.prototype.safeToRemove = function() {
    var o = this.props.safeToRemove;
    o == null || o();
  }, r.prototype.render = function() {
    return null;
  }, r;
}(c.Component);
function W(s) {
  var r = y(R(), 2), o = r[0], a = r[1], e = f(g);
  return c.createElement(C, d({}, s, { layoutGroup: e, switchLayoutGroup: f(L), isPresent: o, safeToRemove: a }));
}
var G = {
  borderRadius: d(d({}, p), { applyTo: [
    "borderTopLeftRadius",
    "borderTopRightRadius",
    "borderBottomLeftRadius",
    "borderBottomRightRadius"
  ] }),
  borderTopLeftRadius: p,
  borderTopRightRadius: p,
  borderBottomLeftRadius: p,
  borderBottomRightRadius: p,
  boxShadow: _
};
export {
  W as MeasureLayout
};
//# sourceMappingURL=MeasureLayout.es.js.map
