"use strict";

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

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 _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

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

var _react = require("react");

var _reactDom = _interopRequireDefault(require("react-dom"));

var Portal = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Portal, _Component);

  var _super = (0, _createSuper2["default"])(Portal);

  function Portal() {
    (0, _classCallCheck2["default"])(this, Portal);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Portal, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.createContainer();
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps) {
      var didUpdate = this.props.didUpdate;

      if (didUpdate) {
        didUpdate(prevProps);
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.removeContainer();
    }
  }, {
    key: "createContainer",
    value: function createContainer() {
      this._container = this.props.getContainer();
      this.forceUpdate();
    }
  }, {
    key: "removeContainer",
    value: function removeContainer() {
      if (this._container) {
        this._container.parentNode.removeChild(this._container);
      }
    }
  }, {
    key: "render",
    value: function render() {
      if (this._container) {
        return /*#__PURE__*/_reactDom["default"].createPortal(this.props.children, this._container);
      }

      return null;
    }
  }]);
  return Portal;
}(_react.Component);

exports["default"] = Portal;
//# sourceMappingURL=Portal.js.map
