"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [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 = require("./isArguments.js");
const isArray = require("./isArray.js");
const isArrayLikeObject = require("./isArrayLikeObject.js");
const isBuffer = require("./isBuffer.js");
const isFunction = require("./isFunction.js");
const isObject = require("./isObject.js");
const isPlainObject = require("./isPlainObject.js");
const isTypedArray = require("./isTypedArray.js");
const _safeGet = require("./_safeGet.js");
const toPlainObject = require("./toPlainObject.js");
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  var objValue = _safeGet.default(object, key), srcValue = _safeGet.default(source, key), stacked = stack.get(srcValue);
  if (stacked) {
    _assignMergeValue.default(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.default(srcValue), isBuff = !isArr && isBuffer.default(srcValue), isTyped = !isArr && !isBuff && isTypedArray.default(srcValue);
    newValue = srcValue;
    if (isArr || isBuff || isTyped) {
      if (isArray.default(objValue)) {
        newValue = objValue;
      } else if (isArrayLikeObject.default(objValue)) {
        newValue = _copyArray.default(objValue);
      } else if (isBuff) {
        isCommon = false;
        newValue = _cloneBuffer.default(srcValue, true);
      } else if (isTyped) {
        isCommon = false;
        newValue = _cloneTypedArray.default(srcValue, true);
      } else {
        newValue = [];
      }
    } else if (isPlainObject.default(srcValue) || isArguments.default(srcValue)) {
      newValue = objValue;
      if (isArguments.default(objValue)) {
        newValue = toPlainObject.default(objValue);
      } else if (!isObject.default(objValue) || isFunction.default(objValue)) {
        newValue = _initCloneObject.default(srcValue);
      }
    } else {
      isCommon = false;
    }
  }
  if (isCommon) {
    stack.set(srcValue, newValue);
    mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
    stack["delete"](srcValue);
  }
  _assignMergeValue.default(object, key, newValue);
}
exports.default = baseMergeDeep;
