import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Component } from 'react';
import Dialog from './Dialog';
import Portal from '../util/Portal';

var DialogWrap = /*#__PURE__*/function (_Component) {
  _inherits(DialogWrap, _Component);

  var _super = _createSuper(DialogWrap);

  function DialogWrap() {
    var _this;

    _classCallCheck(this, DialogWrap);

    _this = _super.apply(this, arguments);

    _this.saveDialog = function (node) {
      _this._component = node;
    };

    _this.getComponent = function () {
      var extra = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return /*#__PURE__*/React.createElement(Dialog, _extends({
        ref: _this.saveDialog
      }, _this.props, extra, {
        key: "dialog"
      }));
    };

    _this.getContainer = function () {
      var getContainer = _this.props.getContainer;

      if (getContainer) {
        return getContainer(_assertThisInitialized(_this));
      }

      var container = document.createElement('div');
      document.body.appendChild(container);
      return container;
    };

    return _this;
  }

  _createClass(DialogWrap, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(_ref) {
      var visible = _ref.visible;
      var props = this.props;
      return !!(props.visible || visible);
    }
  }, {
    key: "render",
    value: function render() {
      var visible = this.props.visible;

      if (visible || this._component) {
        return /*#__PURE__*/React.createElement(Portal, {
          getContainer: this.getContainer
        }, this.getComponent());
      }

      return null;
    }
  }]);

  return DialogWrap;
}(Component);

DialogWrap.defaultProps = {
  visible: false
};
export default DialogWrap;
//# sourceMappingURL=DialogWrap.js.map
