/**
 * DevExtreme (cjs/core/utils/extend.js)
 * Version: 24.1.7-build-24272-1937
 * Build date: Sat Sep 28 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.extendFromObject = exports.extend = void 0;
var _type = require("./type");
const extendFromObject = function(target, source, overrideExistingValues) {
    target = target || {};
    for (const prop in source) {
        if (Object.prototype.hasOwnProperty.call(source, prop)) {
            const value = source[prop];
            if (!(prop in target) || overrideExistingValues) {
                target[prop] = value
            }
        }
    }
    return target
};
exports.extendFromObject = extendFromObject;
const extend = function(target) {
    target = target || {};
    let i = 1;
    let deep = false;
    if ("boolean" === typeof target) {
        deep = target;
        target = arguments[1] || {};
        i++
    }
    for (; i < arguments.length; i++) {
        const source = arguments[i];
        if (null == source) {
            continue
        }
        for (const key in source) {
            const targetValue = target[key];
            const sourceValue = source[key];
            let sourceValueIsArray = false;
            let clone;
            if ("__proto__" === key || "constructor" === key || target === sourceValue) {
                continue
            }
            if (deep && sourceValue && ((0, _type.isPlainObject)(sourceValue) || (sourceValueIsArray = Array.isArray(sourceValue)))) {
                if (sourceValueIsArray) {
                    clone = targetValue && Array.isArray(targetValue) ? targetValue : []
                } else {
                    clone = targetValue && (0, _type.isPlainObject)(targetValue) ? targetValue : {}
                }
                target[key] = extend(deep, clone, sourceValue)
            } else if (void 0 !== sourceValue) {
                target[key] = sourceValue
            }
        }
    }
    return target
};
exports.extend = extend;
