"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const _assignMergeValue = require("./_assignMergeValue.js");
const _cloneBuffer = require("./_cloneBuffer.js");
const _cloneTypedArray = require("./_cloneTypedArray.js");
const _copyArray = require("./_copyArray.js");
const _initCloneObject = require("./_initCloneObject.js");
const isArguments$1 = require("./isArguments.js");
const isArray$1 = require("./isArray.js");
const isArrayLikeObject$1 = require("./isArrayLikeObject.js");
const isBuffer$1 = require("./isBuffer.js");
const isFunction$1 = require("./isFunction.js");
const isObject$1 = require("./isObject.js");
const isPlainObject$1 = require("./isPlainObject.js");
const isTypedArray$1 = require("./isTypedArray.js");
const _safeGet = require("./_safeGet.js");
const toPlainObject$1 = require("./toPlainObject.js");
var assignMergeValue = _assignMergeValue._assignMergeValue, cloneBuffer = _cloneBuffer._cloneBufferExports, cloneTypedArray = _cloneTypedArray._cloneTypedArray, copyArray = _copyArray._copyArray, initCloneObject = _initCloneObject._initCloneObject, isArguments = isArguments$1.isArguments_1, isArray = isArray$1.isArray_1, isArrayLikeObject = isArrayLikeObject$1.isArrayLikeObject_1, isBuffer = isBuffer$1.isBufferExports, isFunction = isFunction$1.isFunction_1, isObject = isObject$1.isObject_1, isPlainObject = isPlainObject$1.isPlainObject_1, isTypedArray = isTypedArray$1.isTypedArray_1, safeGet = _safeGet._safeGet, toPlainObject = toPlainObject$1.toPlainObject_1;
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  var objValue = safeGet(object, key), srcValue = safeGet(source, key), stacked = stack.get(srcValue);
  if (stacked) {
    assignMergeValue(object, key, stacked);
    return;
  }
  var newValue = customizer ? customizer(objValue, srcValue, key + "", object, source, stack) : void 0;
  var isCommon = newValue === void 0;
  if (isCommon) {
    var isArr = isArray(srcValue), isBuff = !isArr && isBuffer(srcValue), isTyped = !isArr && !isBuff && isTypedArray(srcValue);
    newValue = srcValue;
    if (isArr || isBuff || isTyped) {
      if (isArray(objValue)) {
        newValue = objValue;
      } else if (isArrayLikeObject(objValue)) {
        newValue = copyArray(objValue);
      } else if (isBuff) {
        isCommon = false;
        newValue = cloneBuffer(srcValue, true);
      } else if (isTyped) {
        isCommon = false;
        newValue = cloneTypedArray(srcValue, true);
      } else {
        newValue = [];
      }
    } else if (isPlainObject(srcValue) || isArguments(srcValue)) {
      newValue = objValue;
      if (isArguments(objValue)) {
        newValue = toPlainObject(objValue);
      } else if (!isObject(objValue) || isFunction(objValue)) {
        newValue = initCloneObject(srcValue);
      }
    } else {
      isCommon = false;
    }
  }
  if (isCommon) {
    stack.set(srcValue, newValue);
    mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
    stack["delete"](srcValue);
  }
  assignMergeValue(object, key, newValue);
}
var _baseMergeDeep = baseMergeDeep;
exports._baseMergeDeep = _baseMergeDeep;
