text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  exports.__esModule = true;
  exports.default = void 0;
  
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  
  var _react = _interopRequireDefault(require("react"));
  
  var _reactDom = _interopRequireDefault(require("react-dom"));
  
  var _warning = _interopRequireDefault(require("warning"));
  
  var _propTypes = _interopRequireDefault(require("prop-types"));
  
  var _ScrollBehaviorContext = require("./ScrollBehaviorContext");
  
  var propTypes = {
    scrollKey: _propTypes.default.string.isRequired,
    shouldUpdateScroll: _propTypes.default.func,
    children: _propTypes.default.element.isRequired
  };
  
  var ScrollContainer = /*#__PURE__*/function (_React$Component) {
    (0, _inheritsLoose2.default)(ScrollContainer, _React$Component);
  
    function ScrollContainer(props) {
      var _this;
  
      _this = _React$Component.call(this, props) || this; // We don't re-register if the scroll key changes, so make sure we
      // unregister with the initial scroll key just in case the user changes it.
  
      _this.shouldUpdateScroll = function (prevRouterProps, routerProps) {
        var shouldUpdateScroll = _this.props.shouldUpdateScroll;
  
        if (!shouldUpdateScroll) {
          return true;
        } // Hack to allow accessing scrollBehavior._stateStorage.
  
  
        return shouldUpdateScroll.call(_this.props.context.scrollBehavior, prevRouterProps, routerProps);
      };
  
      _this.scrollKey = props.scrollKey;
      return _this;
    }
  
    var _proto = ScrollContainer.prototype;
  
    _proto.componentDidMount = function componentDidMount() {
      this.props.context.registerElement(this.props.scrollKey, _reactDom.default.findDOMNode(this), // eslint-disable-line react/no-find-dom-node
      this.shouldUpdateScroll); // Only keep around the current DOM node in development, as this is only
      // for emitting the appropriate warning.
  
      if (process.env.NODE_ENV !== "production") {
        this.domNode = _reactDom.default.findDOMNode(this); // eslint-disable-line react/no-find-dom-node
      }
    };
  
    _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
      (0, _warning.default)(prevProps.scrollKey === this.props.scrollKey, "<ScrollContainer> does not support changing scrollKey.");
  
      if (process.env.NODE_ENV !== "production") {
        var prevDomNode = this.domNode;
        this.domNode = _reactDom.default.findDOMNode(this); // eslint-disable-line react/no-find-dom-node
  
        (0, _warning.default)(this.domNode === prevDomNode, "<ScrollContainer> does not support changing DOM node.");
      }
    };
  
    _proto.componentWillUnmount = function componentWillUnmount() {
      this.props.context.unregisterElement(this.scrollKey);
    };
  
    _proto.render = function render() {
      return this.props.children;
    };
  
    return ScrollContainer;
  }(_react.default.Component);
  
  var ScrollContainerConsumer = function ScrollContainerConsumer(props) {
    return /*#__PURE__*/_react.default.createElement(_ScrollBehaviorContext.ScrollBehaviorContext.Consumer, null, function (context) {
      return /*#__PURE__*/_react.default.createElement(ScrollContainer, (0, _extends2.default)({}, props, {
        context: context
      }));
    });
  };
  
  ScrollContainerConsumer.propTypes = propTypes;
  var _default = ScrollContainerConsumer;
  exports.default = _default;