"use strict";
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 use_bi_helpers_exports = {};
__export(use_bi_helpers_exports, {
  useBiHelpers: () => useBiHelpers
});
module.exports = __toCommonJS(use_bi_helpers_exports);
var import_react = require("react");
var import_next_schema = require("./../../ricos-schema/next-schema/index.js");
var import_parse_instance = require("./../request-service-provider/parse-instance.js");
const useBiHelpers = ({
  instance,
  biSettings,
  msid = ""
}) => {
  const shouldLoadBi = !!instance && !!biSettings;
  const [state, setState] = (0, import_react.useState)({
    helpers: {},
    loading: shouldLoadBi
  });
  const { appDefId, metaSiteId: instanceMsid } = (0, import_react.useMemo)(
    () => instance ? (0, import_parse_instance.parseInstance)(instance) : { appDefId: "", metaSiteId: "" },
    [instance]
  );
  const metaSiteId = instanceMsid || msid;
  const [biLoadDeferred] = (0, import_react.useState)(() => {
    if (!shouldLoadBi) {
      return { promise: Promise.resolve({}), resolve: (_h) => {
      } };
    }
    let resolve;
    const promise = new Promise((r) => {
      resolve = r;
    });
    return { promise, resolve };
  });
  (0, import_react.useEffect)(() => {
    if (!shouldLoadBi || !biSettings) {
      setState({ helpers: {}, loading: false });
      return;
    }
    Promise.resolve().then(() => __toESM(require("./index.js"))).then(
      ({ createBiHelpers }) => createBiHelpers({
        appDefId,
        metaSiteId,
        biSettings,
        wixRicosVersion: import_next_schema.RICOS_VERSION,
        ricosVersion: import_next_schema.RICOS_VERSION
      })
    ).then((result) => {
      setState({
        helpers: result.helpers,
        biLogger: result.biLogger,
        loading: false
      });
      biLoadDeferred.resolve(result.helpers);
    }).catch((error) => {
      console.error("[useBiHelpers] Failed to load BI helpers:", error);
      setState({ helpers: {}, loading: false });
      biLoadDeferred.resolve({});
    });
  }, [shouldLoadBi, appDefId, metaSiteId, biSettings, biLoadDeferred]);
  return { ...state, biLoadPromise: biLoadDeferred.promise };
};
//# sourceMappingURL=use-bi-helpers.js.map
