"use strict";

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

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

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

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

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 _tooltip = _interopRequireDefault(require("../tooltip"));

var _icon = _interopRequireDefault(require("../icon"));

var _button = _interopRequireDefault(require("../button"));

var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));

var _default = _interopRequireDefault(require("../locale-provider/default"));

var _enum = require("../_util/enum");

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _excluded = ["placement"];

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

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

  function Popconfirm(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Popconfirm);
    _this = _super.call(this, props);

    _this.onConfirm = function (e) {
      _this.setVisible(false);

      var onConfirm = _this.props.onConfirm;

      if (onConfirm) {
        onConfirm.call((0, _assertThisInitialized2["default"])(_this), e);
      }
    };

    _this.onCancel = function (e) {
      _this.setVisible(false);

      var onCancel = _this.props.onCancel;

      if (onCancel) {
        onCancel.call((0, _assertThisInitialized2["default"])(_this), e);
      }
    };

    _this.onVisibleChange = function (visible) {
      _this.setVisible(visible);
    };

    _this.saveTooltip = function (node) {
      _this.tooltip = node;
    };

    _this.renderOverlayWithLocale = function (popconfirmLocale) {
      var _this$props = _this.props,
          title = _this$props.title,
          cancelText = _this$props.cancelText,
          okText = _this$props.okText,
          okType = _this$props.okType,
          iconType = _this$props.iconType,
          okButtonProps = _this$props.okButtonProps,
          cancelButtonProps = _this$props.cancelButtonProps;

      var prefixCls = _this.getPrefixCls();

      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-inner-content")
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-message")
      }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
        type: iconType
      }), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-message-title")
      }, typeof title === 'function' ? title() : title)), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-buttons")
      }, /*#__PURE__*/_react["default"].createElement(_button["default"], (0, _extends2["default"])({}, okButtonProps, {
        onClick: _this.onCancel,
        size: _enum.Size.small
      }), cancelText || popconfirmLocale.cancelText), /*#__PURE__*/_react["default"].createElement(_button["default"], (0, _extends2["default"])({}, cancelButtonProps, {
        onClick: _this.onConfirm,
        type: okType,
        size: _enum.Size.small
      }), okText || popconfirmLocale.okText)));
    };

    _this.renderLocale = function () {
      return /*#__PURE__*/_react["default"].createElement(_LocaleReceiver["default"], {
        componentName: "Popconfirm",
        defaultLocale: _default["default"].Popconfirm
      }, _this.renderOverlayWithLocale);
    };

    _this.state = {
      visible: props.visible
    };
    return _this;
  }

  (0, _createClass2["default"])(Popconfirm, [{
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      if ('visible' in nextProps) {
        this.setState({
          visible: nextProps.visible
        });
      }
    }
  }, {
    key: "getPopupDomNode",
    value: function getPopupDomNode() {
      return this.tooltip.getPopupDomNode();
    }
  }, {
    key: "setVisible",
    value: function setVisible(visible) {
      var props = this.props;

      if (!('visible' in props)) {
        this.setState({
          visible: visible
        });
      }

      var onVisibleChange = props.onVisibleChange;

      if (onVisibleChange) {
        onVisibleChange(visible);
      }
    }
  }, {
    key: "getPrefixCls",
    value: function getPrefixCls() {
      var prefixCls = this.props.prefixCls;
      var getPrefixCls = this.context.getPrefixCls;
      return getPrefixCls('popover', prefixCls);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          placement = _this$props2.placement,
          restProps = (0, _objectWithoutProperties2["default"])(_this$props2, _excluded);
      var visible = this.state.visible;
      return /*#__PURE__*/_react["default"].createElement(_tooltip["default"], (0, _extends2["default"])({}, restProps, {
        prefixCls: this.getPrefixCls(),
        placement: placement,
        onVisibleChange: this.onVisibleChange,
        visible: visible,
        overlay: this.renderLocale,
        ref: this.saveTooltip
      }));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Popconfirm;
}(_react.Component);

exports["default"] = Popconfirm;
Popconfirm.displayName = 'Popconfirm';
Popconfirm.defaultProps = {
  transitionName: 'zoom-big',
  placement: 'top',
  trigger: 'click',
  okType: 'primary',
  iconType: 'warning'
};
//# sourceMappingURL=index.js.map
