text: import _extends from "@babel/runtime/helpers/extends";
  import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
  import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
  import React from 'react';
  import RootCloseWrapper from "react-overlays/lib/RootCloseWrapper";
  import { getDisplayName } from '../utils';
  import { BACKSPACE } from '../constants';
  
  /**
   * Higher-order component to encapsulate Token behaviors.
   */
  var tokenContainer = function tokenContainer(Component) {
    var WrappedComponent =
    /*#__PURE__*/
    function (_React$Component) {
      _inheritsLoose(WrappedComponent, _React$Component);
  
      function WrappedComponent() {
        var _this;
  
        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }
  
        _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  
        _defineProperty(_assertThisInitialized(_this), "state", {
          active: false
        });
  
        _defineProperty(_assertThisInitialized(_this), "_handleBlur", function (e) {
          _this.setState({
            active: false
          });
        });
  
        _defineProperty(_assertThisInitialized(_this), "_handleKeyDown", function (e) {
          switch (e.keyCode) {
            case BACKSPACE:
              if (_this.state.active) {
                // Prevent backspace keypress from triggering the browser "back"
                // action.
                e.preventDefault();
  
                _this.props.onRemove();
              }
  
              break;
  
            default:
              break;
          }
        });
  
        _defineProperty(_assertThisInitialized(_this), "_handleActive", function (e) {
          e.stopPropagation();
  
          _this.setState({
            active: true
          });
        });
  
        return _this;
      }
  
      var _proto = WrappedComponent.prototype;
  
      _proto.render = function render() {
        return React.createElement(RootCloseWrapper, {
          onRootClose: this._handleBlur
        }, React.createElement(Component, _extends({}, this.props, this.state, {
          onBlur: this._handleBlur,
          onClick: this._handleActive,
          onFocus: this._handleActive,
          onKeyDown: this._handleKeyDown
        })));
      };
  
      return WrappedComponent;
    }(React.Component);
  
    _defineProperty(WrappedComponent, "displayName", "tokenContainer(" + getDisplayName(Component) + ")");
  
    return WrappedComponent;
  };
  
  export default tokenContainer;