import n, { Suspense as c, useMemo as u, useRef as i } from "react";
import { useStateOverrides as p } from "@wix/builder-state-react";
const m = (t) => {
  if (!(t instanceof Promise))
    return;
  const e = t;
  switch (e.status) {
    case "pending":
      throw e;
    case "fulfilled":
      return;
    case "rejected":
      throw e.reason;
    default:
      throw e.status = "pending", e.then((r) => {
        e.status = "fulfilled", e.value = r;
      }, (r) => {
        e.status = "rejected", e.reason = r;
      }), e;
  }
}, d = ({ onReadyPromise: t, children: e }) => (m(t), n.createElement(n.Fragment, null, e)), f = ({ fallback: t, onReadyPromise: e, children: r }) => n.createElement(
  c,
  { fallback: t },
  n.createElement(d, { onReadyPromise: e }, r)
), h = (t, e) => {
  const r = Object.keys(t);
  return r.length === Object.keys(e).length && r.every((s) => t[s] === e[s]);
}, P = n.memo(({ props: t, onPropsChanged: e }) => {
  const r = i(null);
  return r.current && e(r.current, t), r.current = t, null;
}, (t, e) => h(t.props, e.props)), w = ({ children: t, fallback: e, appDefinitionId: r, invokeOnPropsChanged: s, invokeOnReady: o, ...a }) => {
  const l = u(() => o(), []);
  return n.createElement(
    f,
    { onReadyPromise: l, fallback: e },
    n.createElement(P, { onPropsChanged: s, props: a }),
    t
  );
}, R = (t) => (e) => {
  const [r = {}, s] = p(e.nickname);
  return s ? null : n.createElement(t, { ...e, ...r });
};
export {
  f as SuspenseWrapper,
  w as VeloRuntime,
  R as withVelo
};
//# sourceMappingURL=builder-velo-react.mjs.map