"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var RuntimeProvider_exports = {};
__export(RuntimeProvider_exports, {
  RuntimeProvider: () => RuntimeProvider
});
module.exports = __toCommonJS(RuntimeProvider_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_react2 = require("../../../api/react");
var import_use_react_runtime = require("../hooks/use-react-runtime");
var import_host_api_client = require("../host-api-client");
var import_preview_switcher = require("./preview-switcher/preview-switcher");
var import_use_builder_connection_ping = require("./hooks/use-builder-connection-ping");
var import_use_framework_context = require("./hooks/use-framework-context");
const LiveProvider = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./LiveProvider"))));
const PreviewProvider = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./PreviewProvider"))));
function RuntimeProvider({
  children,
  runtime,
  siteVersion,
  appOrigin = "https://app.makeswift.com",
  apiOrigin = "https://api.makeswift.com",
  locale = void 0
}) {
  const { versionedFetch } = (0, import_use_framework_context.useFrameworkContext)();
  const client = (0, import_react.useMemo)(
    () => new import_react2.MakeswiftHostApiClient({
      uri: new URL("graphql", apiOrigin).href,
      locale,
      fetch: versionedFetch(siteVersion)
    }),
    [apiOrigin, locale, siteVersion, versionedFetch]
  );
  const isPreview = siteVersion != null;
  const StoreProvider = isPreview ? PreviewProvider : LiveProvider;
  (0, import_use_builder_connection_ping.useBuilderConnectionPing)({ appOrigin });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_use_react_runtime.ReactRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_host_api_client.MakeswiftHostApiClientProvider, { client, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(StoreProvider, { appOrigin, children: [
    children,
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview_switcher.PreviewSwitcher, { isPreview })
  ] }) }) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  RuntimeProvider
});
//# sourceMappingURL=RuntimeProvider.js.map