"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useMemo, lazy } from "react";
import { MakeswiftHostApiClient } from "../../../api/react";
import { ReactRuntimeContext } from "../hooks/use-react-runtime";
import { MakeswiftHostApiClientProvider } from "../host-api-client";
import { PreviewSwitcher } from "./preview-switcher/preview-switcher";
import { useBuilderConnectionPing } from "./hooks/use-builder-connection-ping";
import { useFrameworkContext } from "./hooks/use-framework-context";
const LiveProvider = lazy(() => import("./LiveProvider"));
const PreviewProvider = lazy(() => import("./PreviewProvider"));
function RuntimeProvider({
  children,
  runtime,
  siteVersion,
  appOrigin = "https://app.makeswift.com",
  apiOrigin = "https://api.makeswift.com",
  locale = void 0
}) {
  const { versionedFetch } = useFrameworkContext();
  const client = useMemo(
    () => new MakeswiftHostApiClient({
      uri: new URL("graphql", apiOrigin).href,
      locale,
      fetch: versionedFetch(siteVersion)
    }),
    [apiOrigin, locale, siteVersion, versionedFetch]
  );
  const isPreview = siteVersion != null;
  const StoreProvider = isPreview ? PreviewProvider : LiveProvider;
  useBuilderConnectionPing({ appOrigin });
  return /* @__PURE__ */ jsx(ReactRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ jsx(MakeswiftHostApiClientProvider, { client, children: /* @__PURE__ */ jsxs(StoreProvider, { appOrigin, children: [
    children,
    /* @__PURE__ */ jsx(PreviewSwitcher, { isPreview })
  ] }) }) });
}
export {
  RuntimeProvider
};
//# sourceMappingURL=RuntimeProvider.js.map