"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

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

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

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

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

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

var _Dialog = _interopRequireDefault(require("./Dialog"));

var _Portal = _interopRequireDefault(require("../util/Portal"));

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

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

  function DialogWrap() {
    var _this;

    (0, _classCallCheck2["default"])(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["default"].createElement(_Dialog["default"], (0, _extends2["default"])({
        ref: _this.saveDialog
      }, _this.props, extra, {
        key: "dialog"
      }));
    };

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

      if (getContainer) {
        return getContainer((0, _assertThisInitialized2["default"])(_this));
      }

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

    return _this;
  }

  (0, _createClass2["default"])(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["default"].createElement(_Portal["default"], {
          getContainer: this.getContainer
        }, this.getComponent());
      }

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

DialogWrap.defaultProps = {
  visible: false
};
var _default = DialogWrap;
exports["default"] = _default;
//# sourceMappingURL=DialogWrap.js.map
