"use strict";

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

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

var _zhCn = _interopRequireDefault(require("../locale/zh-cn"));

var _balloon = _interopRequireDefault(require("./balloon"));

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

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var iconMap = {
  info: 'info-o-fill',
  success: 'info-o-fill',
  warning: 'warning-o-fill',
  danger: 'remove-o-fill'
};

var noop = function noop() {};

var PopConfirm =
/*#__PURE__*/
function (_React$Component) {
  _inherits(PopConfirm, _React$Component);

  function PopConfirm(props) {
    var _this;

    _classCallCheck(this, PopConfirm);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(PopConfirm).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "onVisibleChange", function (visible) {
      if (!('visible' in _this.props)) {
        _this.setState({
          visible: visible
        });
      }

      _this.props.onVisibleChange(visible);
    });

    _defineProperty(_assertThisInitialized(_this), "renderIcon", function () {
      var _this$props = _this.props,
          type = _this$props.type,
          icon = _this$props.icon;
      return _react["default"].createElement("div", {
        className: (0, _classnames["default"])(_defineProperty({
          'pop-confirm-icon-area': true
        }, "pop-confirm-icon-area-".concat(type), type))
      }, icon || _react["default"].createElement(_icon["default"], {
        type: iconMap[type] || iconMap.info
      }));
    });

    _defineProperty(_assertThisInitialized(_this), "renderTitleAndContent", function () {
      var _this$props2 = _this.props,
          title = _this$props2.title,
          content = _this$props2.content,
          footer = _this$props2.footer;
      return _react["default"].createElement("div", {
        className: (0, _classnames["default"])({
          'title-content-area': true,
          'title-content-area-no-footer': !footer
        })
      }, title ? _react["default"].createElement("div", {
        className: "title-area"
      }, title) : null, _react["default"].createElement("div", {
        className: (0, _classnames["default"])({
          'content-area': true,
          'content-area-no-title': !title
        })
      }, content));
    });

    _defineProperty(_assertThisInitialized(_this), "renderFooter", function () {
      var _this$props3 = _this.props,
          type = _this$props3.type,
          locale = _this$props3.locale,
          footer = _this$props3.footer,
          confirmProps = _this$props3.confirmProps,
          cancelProps = _this$props3.cancelProps,
          onConfirm = _this$props3.onConfirm,
          onCancel = _this$props3.onCancel;
      return footer ? _react["default"].createElement("div", {
        className: "footer-area"
      }, _react["default"].createElement(_button["default"], _extends({}, cancelProps, {
        onClick: onCancel,
        type: "normal",
        size: "small"
      }), locale.cancel), _react["default"].createElement(_button["default"], _extends({}, confirmProps, {
        onClick: onConfirm,
        type: "primary",
        warning: type === 'danger',
        size: "small"
      }), locale.confirm)) : null;
    });

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

  _createClass(PopConfirm, [{
    key: "UNSAFE_componentWillReceiveProps",
    value: function UNSAFE_componentWillReceiveProps(nextProps) {
      if (nextProps.visible !== this.props.visible) {
        this.setState({
          visible: nextProps.visible
        });
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _cls2;

      var _this$props4 = this.props,
          prefix = _this$props4.prefix,
          size = _this$props4.size,
          trigger = _this$props4.trigger,
          align = _this$props4.align,
          alignEdge = _this$props4.alignEdge,
          offset = _this$props4.offset,
          triggerType = _this$props4.triggerType,
          needAdjust = _this$props4.needAdjust,
          shouldUpdatePosition = _this$props4.shouldUpdatePosition,
          safeNode = _this$props4.safeNode,
          safeId = _this$props4.safeId,
          animation = _this$props4.animation,
          cache = _this$props4.cache,
          popupContainer = _this$props4.popupContainer,
          popupStyle = _this$props4.popupStyle,
          popupClassName = _this$props4.popupClassName,
          popupProps = _this$props4.popupProps,
          followTrigger = _this$props4.followTrigger,
          id = _this$props4.id;
      var visible = this.state.visible;
      return _react["default"].createElement(_balloon["default"], {
        autoFocus: false,
        closable: false,
        popupClassName: (0, _classnames["default"])((_cls2 = {}, _defineProperty(_cls2, "".concat(prefix, "pop-confirm"), true), _defineProperty(_cls2, "".concat(prefix, "pop-confirm-").concat(size), true), _cls2), popupClassName),
        prefix: prefix,
        visible: visible,
        onVisibleChange: this.onVisibleChange,
        align: align,
        alignEdge: alignEdge,
        offset: offset,
        trigger: trigger,
        triggerType: triggerType,
        needAdjust: needAdjust,
        shouldUpdatePosition: shouldUpdatePosition,
        safeNode: safeNode,
        safeId: safeId,
        animation: animation,
        cache: cache,
        popupContainer: popupContainer,
        popupStyle: popupStyle,
        popupProps: popupProps,
        followTrigger: followTrigger,
        id: id
      }, _react["default"].createElement("div", {
        className: "".concat(prefix, "pop-confirm-container")
      }, this.renderIcon(), this.renderTitleAndContent(), this.renderFooter()));
    }
  }]);

  return PopConfirm;
}(_react["default"].Component);

_defineProperty(PopConfirm, "displayName", 'PopConfirm');

_defineProperty(PopConfirm, "propTypes", {
  prefix: _propTypes["default"].string,
  locale: _propTypes["default"].object,
  size: _propTypes["default"].oneOf(['small', 'medium', 'large']),
  type: _propTypes["default"].oneOf(['info', 'warning', 'success', 'danger']),
  align: _balloon["default"].propTypes.align,
  alignEdge: _propTypes["default"].bool,
  icon: _propTypes["default"].node,
  title: _propTypes["default"].node,
  content: _propTypes["default"].node,
  footer: _propTypes["default"].bool,
  confirmProps: _propTypes["default"].object,
  cancelProps: _propTypes["default"].object,
  onConfirm: _propTypes["default"].func,
  onCancel: _propTypes["default"].func,
  defaultVisible: _propTypes["default"].bool,
  visible: _propTypes["default"].bool,
  onVisibleChange: _propTypes["default"].func,
  offset: _propTypes["default"].array,
  trigger: _propTypes["default"].node.isRequired,
  triggerType: _propTypes["default"].oneOf(['hover', 'click']),
  needAdjust: _propTypes["default"].bool,
  shouldUpdatePosition: _propTypes["default"].bool,
  safeNode: _propTypes["default"].string,
  safeId: _propTypes["default"].string,
  animation: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].bool]),
  cache: _propTypes["default"].bool,
  popupContainer: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func]),
  popupStyle: _propTypes["default"].object,
  popupClassName: _propTypes["default"].string,
  popupProps: _propTypes["default"].object,
  followTrigger: _propTypes["default"].bool,
  id: _propTypes["default"].string
});

_defineProperty(PopConfirm, "defaultProps", {
  prefix: 'next-',
  size: 'medium',
  locale: _zhCn["default"].Balloon,
  type: 'info',
  align: 'b',
  alignEdge: true,
  footer: true,
  confirmProps: {},
  cancelProps: {},
  onConfirm: noop,
  onCancel: noop,
  defaultVisible: false,
  onVisibleChange: noop,
  offset: [0, 0],
  triggerType: 'hover',
  needAdjust: true,
  animation: {
    "in": 'zoomIn',
    out: 'zoomOut'
  },
  cache: false
});

var _default = _configProvider["default"].config(PopConfirm);

exports["default"] = _default;