"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var withStatefulModel = function withStatefulModel(Component) {
  var Stateful = /*#__PURE__*/function (_React$Component) {
    (0, _inherits2["default"])(Stateful, _React$Component);

    var _super = _createSuper(Stateful);

    function Stateful(props) {
      var _this;

      (0, _classCallCheck2["default"])(this, Stateful);
      _this = _super.call(this, props);
      (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (model) {
        _this.setState({
          model: model
        }, function () {
          _this.props.onChange(_this.state.model);
        });
      });
      _this.state = {
        model: props.model
      };
      return _this;
    }

    (0, _createClass2["default"])(Stateful, [{
      key: "UNSAFE_componentWillReceiveProps",
      value: function UNSAFE_componentWillReceiveProps(props) {
        this.setState({
          model: props.model
        });
      }
    }, {
      key: "render",
      value: function render() {
        return /*#__PURE__*/_react["default"].createElement(Component, {
          model: this.state.model,
          onChange: this.onChange
        });
      }
    }]);
    return Stateful;
  }(_react["default"].Component);

  (0, _defineProperty2["default"])(Stateful, "propTypes", {
    model: _propTypes["default"].object.isRequired,
    onChange: _propTypes["default"].func.isRequired
  });
  return Stateful;
};

var _default = withStatefulModel;
exports["default"] = _default;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb2RlL2NvbmZpZy11aS93aXRoLXN0YXRlZnVsLW1vZGVsLmpzeCJdLCJuYW1lcyI6WyJ3aXRoU3RhdGVmdWxNb2RlbCIsIkNvbXBvbmVudCIsIlN0YXRlZnVsIiwicHJvcHMiLCJtb2RlbCIsInNldFN0YXRlIiwib25DaGFuZ2UiLCJzdGF0ZSIsIlJlYWN0IiwiUHJvcFR5cGVzIiwib2JqZWN0IiwiaXNSZXF1aXJlZCIsImZ1bmMiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUE7O0FBQ0E7Ozs7OztBQUVBLElBQU1BLGlCQUFpQixHQUFHLFNBQXBCQSxpQkFBb0IsQ0FBQ0MsU0FBRCxFQUFlO0FBQUEsTUFDakNDLFFBRGlDO0FBQUE7O0FBQUE7O0FBT3JDLHNCQUFZQyxLQUFaLEVBQW1CO0FBQUE7O0FBQUE7QUFDakIsZ0NBQU1BLEtBQU47QUFEaUIsbUdBV1IsVUFBQ0MsS0FBRCxFQUFXO0FBQ3BCLGNBQUtDLFFBQUwsQ0FBYztBQUFFRCxVQUFBQSxLQUFLLEVBQUxBO0FBQUYsU0FBZCxFQUF5QixZQUFNO0FBQzdCLGdCQUFL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