import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import { SizeControlContext } from "../SizeControlContext";
import { defaultSizeValue } from "../constants";
export function withSize(constructor) {
  var SizeDecorator = /*#__PURE__*/function (_constructor) {
    function SizeDecorator() {
      var _this;
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
      _this = _constructor.call.apply(_constructor, [this].concat(args)) || this;
      _this.size = defaultSizeValue;
      return _this;
    }
    _inheritsLoose(SizeDecorator, _constructor);
    var _proto = SizeDecorator.prototype;
    _proto.render = function render() {
      var _this2 = this;
      return /*#__PURE__*/(
        React.createElement(SizeControlContext.Consumer, null, function (context) {
          var _this2$props$size;
          _this2.size = (_this2$props$size = _this2.props.size) != null ? _this2$props$size : context.size;
          var originalRender = _constructor.prototype.render;
          if (typeof originalRender === 'function') {
            return originalRender.call(_this2);
          }
          return null;
        })
      );
    };
    return SizeDecorator;
  }(constructor);
  var nameDescriptor = Object.getOwnPropertyDescriptor(SizeDecorator, 'name');
  if (!nameDescriptor || nameDescriptor.configurable) {
    Object.defineProperty(SizeDecorator, 'name', {
      value: constructor.name
    });
  }
  return SizeDecorator;
}