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;
}
import React, { forwardRef } from "react";
// TODO: Поправить типы, если внутри услвовия типы не совпадают
export function createConditionalComponent(defaultComponent, mappings) {
    return /*#__PURE__*/ forwardRef(function(props, ref) {
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = mappings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var mapping = _step.value;
                var conditions = mapping.conditions, component = mapping.component;
                var conditionsArray = Array.isArray(conditions) ? conditions : [
                    conditions
                ];
                var allConditionsMatch = conditionsArray.every(function(param) {
                    var prop = param.prop, value = param.value;
                    return props[prop] === value;
                });
                if (allConditionsMatch) {
                    var Component = component;
                    return /*#__PURE__*/ React.createElement(Component, _object_spread({
                        ref: ref
                    }, props));
                }
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        var DefaultComponent = defaultComponent;
        return /*#__PURE__*/ React.createElement(DefaultComponent, _object_spread({
            ref: ref
        }, props));
    });
}
