import { _ as _assignMergeValue } from "./_assignMergeValue.mjs";
import { _ as _cloneBufferExports } from "./_cloneBuffer.mjs";
import { _ as _cloneTypedArray } from "./_cloneTypedArray.mjs";
import { _ as _copyArray } from "./_copyArray.mjs";
import { _ as _initCloneObject } from "./_initCloneObject.mjs";
import { i as isArguments_1 } from "./isArguments.mjs";
import { i as isArray_1 } from "./isArray.mjs";
import { i as isArrayLikeObject_1 } from "./isArrayLikeObject.mjs";
import { i as isBufferExports } from "./isBuffer.mjs";
import { i as isFunction_1 } from "./isFunction.mjs";
import { i as isObject_1 } from "./isObject.mjs";
import { i as isPlainObject_1 } from "./isPlainObject.mjs";
import { i as isTypedArray_1 } from "./isTypedArray.mjs";
import { _ as _safeGet } from "./_safeGet.mjs";
import { t as toPlainObject_1 } from "./toPlainObject.mjs";
var assignMergeValue = _assignMergeValue, cloneBuffer = _cloneBufferExports, cloneTypedArray = _cloneTypedArray, copyArray = _copyArray, initCloneObject = _initCloneObject, isArguments = isArguments_1, isArray = isArray_1, isArrayLikeObject = isArrayLikeObject_1, isBuffer = isBufferExports, isFunction = isFunction_1, isObject = isObject_1, isPlainObject = isPlainObject_1, isTypedArray = isTypedArray_1, safeGet = _safeGet, toPlainObject = 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;
export {
  _baseMergeDeep as _
};
