"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    assign: ()=>assign_rslib_entry_assign,
    mergeStrategies: ()=>mergeStrategies
});
const client_namespaceObject = require("@tachybase/utils/client");
const external_deepmerge_namespaceObject = require("deepmerge");
var external_deepmerge_default = /*#__PURE__*/ __webpack_require__.n(external_deepmerge_namespaceObject);
const external_lodash_namespaceObject = require("lodash");
function getEnumerableOwnPropertySymbols(target) {
    return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter((symbol)=>target.propertyIsEnumerable(symbol)) : [];
}
function getKeys(target) {
    return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
}
const mergeStrategies = new Map();
mergeStrategies.set('overwrite', (_, y)=>y);
mergeStrategies.set('andMerge', (x, y)=>{
    if (!x && !y) return;
    if (!x) return y;
    if (!y) return x;
    return {
        $and: [
            x,
            y
        ]
    };
});
mergeStrategies.set('orMerge', (x, y)=>{
    if (!x && !y) return;
    if (!x) return y;
    if (!y) return x;
    return {
        $or: [
            x,
            y
        ]
    };
});
mergeStrategies.set('deepMerge', (x, y)=>(0, client_namespaceObject.isPlainObject)(x) && (0, client_namespaceObject.isPlainObject)(y) ? external_deepmerge_default()(x, y, {
        arrayMerge: (x, y)=>y
    }) : y);
mergeStrategies.set('merge', (x, y)=>(0, client_namespaceObject.isPlainObject)(x) && (0, client_namespaceObject.isPlainObject)(y) ? Object.assign(x, y) : y);
mergeStrategies.set('union', (x, y)=>{
    if ('string' == typeof x) x = x.split(',');
    if ('string' == typeof y) y = y.split(',');
    return (0, external_lodash_namespaceObject.uniq)((x || []).concat(y || []));
});
mergeStrategies.set('intersect', (x, y)=>{
    if ('string' == typeof x) x = x.split(',');
    if ('string' == typeof y) y = y.split(',');
    if (!Array.isArray(x) || 0 === x.length) return y || [];
    if (!Array.isArray(y) || 0 === y.length) return x || [];
    return x.filter((v)=>y.includes(v));
});
function assign_rslib_entry_assign(target, source) {
    let strategies = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
    getKeys(source).forEach((sourceKey)=>{
        const strategy = strategies[sourceKey];
        let func = mergeStrategies.get('deepMerge');
        if ('function' == typeof strategy) func = strategy;
        else if ('string' == typeof strategy && mergeStrategies.has(strategy)) func = mergeStrategies.get(strategy);
        target[sourceKey] = func(target[sourceKey], source[sourceKey]);
    });
    return target;
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
