/* Copyright © 2020 Splunk Inc.
SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
in part without a valid written license from Splunk Inc. is PROHIBITED. */
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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);

// src/utils/deepMergeWithArrayPrimitiveOverrides.ts
var deepMergeWithArrayPrimitiveOverrides_exports = {};
__export(deepMergeWithArrayPrimitiveOverrides_exports, {
  deepMergeWithArrayPrimitiveOverrides: () => deepMergeWithArrayPrimitiveOverrides
});
module.exports = __toCommonJS(deepMergeWithArrayPrimitiveOverrides_exports);

// esm-externals:lodash
var lodash_exports = {};
__export(lodash_exports, {
  default: () => lodash_default
});
var defaultImport = __toESM(require("lodash"));
__reExport(lodash_exports, require("lodash"));
var lodash_default = "default" in defaultImport ? defaultImport.default : defaultImport;

// src/utils/findClosestMatchFromDefaultList.ts
var findClosestMatchFromDefaultList = (searchList, inputObj) => {
  if (!Array.isArray(searchList) || searchList.length === 0) {
    return -1;
  }
  const keys = Object.keys(inputObj);
  let maxMatchCnt = 0;
  let maxMatchIdx = 0;
  searchList.forEach((item, idx) => {
    let matchCnt = 0;
    keys.forEach((key) => {
      if (item[key] === inputObj[key]) {
        matchCnt += 1;
      }
    });
    if (Math.max(maxMatchCnt, matchCnt) > maxMatchCnt) {
      maxMatchCnt = matchCnt;
      maxMatchIdx = idx;
    }
  });
  return maxMatchIdx;
};

// src/utils/deepMergeWithArrayPrimitiveOverrides.ts
var deepMergeWithArrayPrimitiveOverrides = (initial, ...sources) => {
  const clone = (0, lodash_exports.cloneDeep)(initial);
  sources.forEach((sourceToApply) => {
    Object.keys(sourceToApply).forEach((sourceKey) => {
      if (!Object.prototype.hasOwnProperty.call(clone, sourceKey)) {
        clone[sourceKey] = (0, lodash_exports.cloneDeep)(sourceToApply[sourceKey]);
      }
      if (clone[sourceKey] && typeof clone[sourceKey] === "object" && !Array.isArray(clone[sourceKey]) && typeof sourceToApply[sourceKey] === "object") {
        clone[sourceKey] = deepMergeWithArrayPrimitiveOverrides(
          clone[sourceKey],
          sourceToApply[sourceKey]
        );
      } else if (Array.isArray(clone[sourceKey]) && typeof clone[sourceKey][0] === "object" && !Array.isArray(clone[sourceKey][0])) {
        for (let i = 0; i < clone[sourceKey].length; i += 1) {
          if (typeof clone[sourceKey][i] === "object") {
            const closestMatchIdx = findClosestMatchFromDefaultList(
              sourceToApply[sourceKey],
              clone[sourceKey][i]
            );
            if (closestMatchIdx > -1) {
              clone[sourceKey][i] = deepMergeWithArrayPrimitiveOverrides(
                clone[sourceKey][i],
                sourceToApply[sourceKey][closestMatchIdx]
              );
            }
          }
        }
      }
    });
  });
  return clone;
};
//# sourceMappingURL=deepMergeWithArrayPrimitiveOverrides.js.map
