import lodash from "lodash";
import { isSSR } from "./../../wix-rich-content-common/index.js";
function paramsToBiFields(essentials) {
  const {
    bsi,
    metaSiteId: msid,
    visitorId: _visitorId,
    appId: _appId,
    instanceId: _instanceId,
    siteOwnerId: _siteOwnerId
  } = essentials;
  return lodash.pickBy(
    { bsi, msid, _visitorId, _appId, _instanceId, _siteOwnerId },
    lodash.identity
  );
}
class RicosBILogger {
  constructor({ logger, webBiLogger, genericParams, essentials = {} }) {
    if (logger) {
      this.newLoggerConfig = { logger, genericParams: lodash.omit(genericParams, "msid") };
      return;
    }
    if (!isSSR()) {
      const biLoggerPromise = Promise.resolve(
        webBiLogger || import(
          /* webpackChunkName: "wix-ricos-bi-logger-fallback" */
          "./../../bundled-dependencies/wix-web-bi-logger.js"
        ).then((result) => result.webBiLogger)
      );
      this.oldLogger = biLoggerPromise.then((result) => {
        const biLogger = result.default?.default ? result.default : result;
        return biLogger.factory().updateDefaults({ ...genericParams, ...paramsToBiFields(essentials) }).logger();
      });
    }
  }
  log(func, params) {
    if (this.newLoggerConfig) {
      const logObject = func(params);
      const { params: eventParams, ...rest } = logObject;
      this.newLoggerConfig.logger.report?.({
        params: { ...this.newLoggerConfig.genericParams, ...eventParams },
        ...rest
      });
    } else if (this.oldLogger) {
      this.oldLogger.then((logger) => logger.report(func(params)));
    } else {
      console.error(`[RicosBILogger.ts:log] RicosBILogger was not initialized`);
    }
  }
  logV2(params) {
    const args = {
      evid: 101,
      src: 116,
      endpoint: "rich-editor",
      params
    };
    if (this.newLoggerConfig) {
      this.newLoggerConfig.logger.report?.(args);
    } else if (this.oldLogger) {
      this.oldLogger.then((logger) => logger.report(args));
    } else {
      console.error(`[RicosBILogger.ts:log] RicosBILogger was not initialized`);
    }
  }
}
export {
  RicosBILogger
};
//# sourceMappingURL=ricos-bi-logger.js.map
