'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

// TODO: Поправить типы, если внутри услвовия типы не совпадают
function createConditionalComponent(defaultComponent, mappings) {
  return /*#__PURE__*/React.forwardRef(function (props, ref) {
    var _iterator = _rollupPluginBabelHelpers.createForOfIteratorHelper(mappings),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var mapping = _step.value;
        var conditions = mapping.conditions,
          component = mapping.component;
        var conditionsArray = Array.isArray(conditions) ? conditions : [conditions];
        var allConditionsMatch = conditionsArray.every(function (_ref) {
          var prop = _ref.prop,
            value = _ref.value;
          return props[prop] === value;
        });
        if (allConditionsMatch) {
          var Component = component;
          return /*#__PURE__*/React__default.default.createElement(Component, _rollupPluginBabelHelpers.extends({
            ref: ref
          }, props));
        }
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var DefaultComponent = defaultComponent;
    return /*#__PURE__*/React__default.default.createElement(DefaultComponent, _rollupPluginBabelHelpers.extends({
      ref: ref
    }, props));
  });
}

exports.createConditionalComponent = createConditionalComponent;
//# sourceMappingURL=createConditionalComponent.js.map
