"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const isRefObject = require("../../utils/is-ref-object.js");
const React = require("react");
const SwitchLayoutGroupContext = require("../../context/SwitchLayoutGroupContext.js");
function useProjection(projectionId, _a, visualElement, ProjectionNodeConstructor) {
  var _b;
  var layoutId = _a.layoutId, layout = _a.layout, drag = _a.drag, dragConstraints = _a.dragConstraints, layoutScroll = _a.layoutScroll;
  var initialPromotionConfig = React.useContext(SwitchLayoutGroupContext.SwitchLayoutGroupContext);
  if (!ProjectionNodeConstructor || !visualElement || (visualElement === null || visualElement === void 0 ? void 0 : visualElement.projection)) {
    return;
  }
  visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_b = visualElement.parent) === null || _b === void 0 ? void 0 : _b.projection);
  visualElement.projection.setOptions({
    layoutId,
    layout,
    alwaysMeasureLayout: Boolean(drag) || dragConstraints && isRefObject.isRefObject(dragConstraints),
    visualElement,
    scheduleRender: function() {
      return visualElement.scheduleRender();
    },
    /**
     * TODO: Update options in an effect. This could be tricky as it'll be too late
     * to update by the time layout animations run.
     * We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
     * ensuring it gets called if there's no potential layout animations.
     *
     */
    animationType: typeof layout === "string" ? layout : "both",
    initialPromotionConfig,
    layoutScroll
  });
}
exports.useProjection = useProjection;
//# sourceMappingURL=use-projection.js.map
