"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 extract_uou_params_exports = {};
__export(extract_uou_params_exports, {
  extractUoUParams: () => extractUoUParams
});
module.exports = __toCommonJS(extract_uou_params_exports);
var import_lodash = __toESM(require("lodash"));
function callFunctions(obj) {
  if (typeof obj === "function") {
    return obj();
  }
  return obj;
}
function resolveValues(obj) {
  return Object.entries(obj).reduce(
    (acc, curr) => ({
      ...acc,
      [curr[1] && curr[0]]: callFunctions(curr[1])
    }),
    {}
  );
}
function getCommonFields(obj) {
  if (!obj || Object.keys(obj).length === 0) {
    return {};
  }
  const {
    bsi,
    metaSiteId,
    visitorId,
    visitor_id,
    // (visitorId) multiple variations, same value
    _appId,
    _instanceId,
    _msid,
    // (metaSiteId) multiple variations, same value
    _siteOwnerId
  } = resolveValues(obj);
  return import_lodash.default.pickBy(
    {
      bsi,
      visitorId: visitor_id || visitorId,
      appId: _appId,
      instanceId: _instanceId,
      metaSiteId: _msid || metaSiteId,
      siteOwnerId: _siteOwnerId
    },
    import_lodash.default.identity
  );
}
function fromBiLoggerFactory(biLoggerFactory) {
  const obj = import_lodash.default.merge(
    {},
    biLoggerFactory?.()?.loggerClientFactory?._defaults,
    biLoggerFactory?.()?.loggerClientFactory?._nonEssentialDefaults
  );
  return getCommonFields(obj);
}
function fromBiObject(bi) {
  return getCommonFields(bi);
}
function fromBiLogger(biLogger) {
  const obj = biLogger?.biLoggerClientFactoryInstance?.loggerClientFactory?._defaults;
  return getCommonFields(obj);
}
const extractUoUParams = ({
  bi,
  biLogger,
  biLoggerFactory,
  platformAPIs
} = {}) => {
  return import_lodash.default.merge(
    fromBiObject(bi || platformAPIs?.bi),
    fromBiLogger(biLogger),
    fromBiLoggerFactory(biLoggerFactory || platformAPIs?.biLoggerFactory)
  );
};
//# sourceMappingURL=extract-uou-params.js.map
