function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
import React from "react";
import { _component } from "./styled-components";
export var mergeConfig = function mergeConfig(baseConfig, userConfig) {
    var res = _object_spread({}, baseConfig, userConfig);
    if (res.variations) {
        // copy variations base css
        // eslint-disable-next-line guard-for-in
        for(var key in res.variations){
            var variant = baseConfig.variations[key];
            res.variations[key].css = variant === null || variant === void 0 ? void 0 : variant.css;
            /* start of bad decision */ if (!res.variations[key].true && (variant === null || variant === void 0 ? void 0 : variant.true)) {
                res.variations[key].true = variant.true;
            }
            /* end of bad decision */ if (variant === null || variant === void 0 ? void 0 : variant.attrs) {
                res.variations[key].attrs = variant.attrs;
            }
        }
    }
    // eslint-disable-next-line guard-for-in
    for(var key1 in baseConfig.defaults || {}){
        if (!(key1 in res.defaults)) {
            res.defaults[key1] = baseConfig.defaults[key1];
        }
    }
    return res;
};
// INFO: Метод, который проводит слияние двух объектов
// INFO: если значение явно указанно как undefined/null/пустая строка, то будет взято значение указанное в default
function mergeWithoutNullable(defaults, componentProps) {
    var props = Object.keys(defaults).reduce(function(acc, key) {
        return _object_spread_props(_object_spread({}, acc), _define_property({}, key, [
            null,
            undefined,
            ''
        ].includes(componentProps[key]) ? defaults[key] : componentProps[key]));
    }, {});
    return _object_spread({}, componentProps, props);
}
export function component(config) {
    var Comp = config.layout(_component(config));
    return /*#__PURE__*/ React.forwardRef(function(props, ref) {
        var mergedProps = mergeWithoutNullable(config === null || config === void 0 ? void 0 : config.defaults, props);
        return /*#__PURE__*/ React.createElement(Comp, _object_spread_props(_object_spread({}, mergedProps), {
            ref: ref
        }));
    });
}
