"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const errors = require("../motion-utils/dist-es-errors.cjs");
const React = require("react");
const LayoutGroupContext = require("./dist-es-context-LayoutGroupContext.cjs");
const LazyContext = require("./dist-es-context-LazyContext.cjs");
const MotionConfigContext = require("./dist-es-context-MotionConfigContext.cjs");
const index = require("./dist-es-context-MotionContext-index.cjs");
const create = require("./dist-es-context-MotionContext-create.cjs");
const isBrowser = require("./dist-es-utils-is-browser.cjs");
const definitions = require("./dist-es-motion-features-definitions.cjs");
const loadFeatures = require("./dist-es-motion-features-load-features.cjs");
const symbol = require("./dist-es-motion-utils-symbol.cjs");
const useMotionRef = require("./dist-es-motion-utils-use-motion-ref.cjs");
const useVisualElement = require("./dist-es-motion-utils-use-visual-element.cjs");
function createRendererMotionComponent({ preloadedFeatures, createVisualElement, useRender, useVisualState, Component }) {
  var _a, _b;
  preloadedFeatures && loadFeatures.loadFeatures(preloadedFeatures);
  function MotionComponent(props, externalRef) {
    let MeasureLayout;
    const configAndProps = {
      ...React.useContext(MotionConfigContext.MotionConfigContext),
      ...props,
      layoutId: useLayoutId(props)
    };
    const { isStatic } = configAndProps;
    const context = create.useCreateMotionContext(props);
    const visualState = useVisualState(props, isStatic);
    if (!isStatic && isBrowser.isBrowser) {
      useStrictMode(configAndProps, preloadedFeatures);
      const layoutProjection = getProjectionFunctionality(configAndProps);
      MeasureLayout = layoutProjection.MeasureLayout;
      context.visualElement = useVisualElement.useVisualElement(Component, visualState, configAndProps, createVisualElement, layoutProjection.ProjectionNode);
    }
    return jsxRuntime.jsxs(index.MotionContext.Provider, { value: context, children: [MeasureLayout && context.visualElement ? jsxRuntime.jsx(MeasureLayout, { visualElement: context.visualElement, ...configAndProps }) : null, useRender(Component, props, useMotionRef.useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement)] });
  }
  MotionComponent.displayName = `motion.${typeof Component === "string" ? Component : `create(${(_b = (_a = Component.displayName) !== null && _a !== void 0 ? _a : Component.name) !== null && _b !== void 0 ? _b : ""})`}`;
  const ForwardRefMotionComponent = React.forwardRef(MotionComponent);
  ForwardRefMotionComponent[symbol.motionComponentSymbol] = Component;
  return ForwardRefMotionComponent;
}
function useLayoutId({ layoutId }) {
  const layoutGroupId = React.useContext(LayoutGroupContext.LayoutGroupContext).id;
  return layoutGroupId && layoutId !== void 0 ? layoutGroupId + "-" + layoutId : layoutId;
}
function useStrictMode(configAndProps, preloadedFeatures) {
  const isStrict = React.useContext(LazyContext.LazyContext).strict;
  if (process.env.NODE_ENV !== "production" && preloadedFeatures && isStrict) {
    const strictMessage = "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.";
    configAndProps.ignoreStrict ? errors.warning(false, strictMessage) : errors.invariant(false, strictMessage);
  }
}
function getProjectionFunctionality(props) {
  const { drag, layout } = definitions.featureDefinitions;
  if (!drag && !layout)
    return {};
  const combined = { ...drag, ...layout };
  return {
    MeasureLayout: (drag === null || drag === void 0 ? void 0 : drag.isEnabled(props)) || (layout === null || layout === void 0 ? void 0 : layout.isEnabled(props)) ? combined.MeasureLayout : void 0,
    ProjectionNode: combined.ProjectionNode
  };
}
exports.createRendererMotionComponent = createRendererMotionComponent;
//# sourceMappingURL=dist-es-motion-index.cjs.map
