import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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, { PureComponent } from 'react';
import { findDOMNode } from 'react-dom';
import classNames from 'classnames';
import Icon from '../icon';
import Animate from '../animate';
import getDataOrAriaProps from '../_util/getDataOrAriaProps';
import ConfigContext from '../config-provider/ConfigContext';

var Alert = /*#__PURE__*/function (_PureComponent) {
  _inherits(Alert, _PureComponent);

  var _super = _createSuper(Alert);

  function Alert() {
    var _this;

    _classCallCheck(this, Alert);

    _this = _super.apply(this, arguments);
    _this.state = {
      closing: true,
      closed: false
    };

    _this.handleClose = function (e) {
      e.preventDefault();
      var dom = findDOMNode(_assertThisInitialized(_this));
      dom.style.height = "".concat(dom.offsetHeight, "px"); // Magic code
      // 重复一次后才能正确设置 height

      dom.style.height = "".concat(dom.offsetHeight, "px");

      _this.setState({
        closing: false
      });

      var onClose = _this.props.onClose;

      if (onClose) {
        onClose(e);
      }
    };

    _this.animationEnd = function () {
      _this.setState({
        closed: true,
        closing: true
      });

      var afterClose = _this.props.afterClose;

      if (afterClose) {
        afterClose();
      }
    };

    return _this;
  }

  _createClass(Alert, [{
    key: "render",
    value: function render() {
      var _classNames;

      var props = this.props;
      var iconOutline = props.iconOutline,
          description = props.description,
          customizePrefixCls = props.prefixCls,
          message = props.message,
          closeText = props.closeText,
          banner = props.banner,
          _props$className = props.className,
          className = _props$className === void 0 ? '' : _props$className,
          style = props.style;
      var closable = props.closable,
          showIcon = props.showIcon,
          type = props.type,
          iconType = props.iconType;
      var _this$state = this.state,
          closing = _this$state.closing,
          closed = _this$state.closed;
      var getPrefixCls = this.context.getPrefixCls;
      var prefixCls = getPrefixCls('alert', customizePrefixCls); // banner模式默认有 Icon

      showIcon = banner && showIcon === undefined ? true : showIcon; // banner模式默认为警告

      type = banner && type === undefined ? 'warning' : type || 'info';

      if (!iconType) {
        // use outline icon in alert with description
        if (iconOutline) {
          switch (type) {
            case 'success':
              iconType = 'check_circle_outline-o';
              break;

            case 'info':
              iconType = 'info-o';
              break;

            case 'error':
              iconType = 'error_outline';
              break;

            case 'warning':
              iconType = 'warning_amber-o-2';
              break;

            default:
              iconType = 'default';
          }
        } else {
          switch (type) {
            case 'success':
              iconType = 'check_circle';
              break;

            case 'info':
              iconType = 'info';
              break;

            case 'error':
              iconType = 'error';
              break;

            case 'warning':
              iconType = 'warning';
              break;

            default:
              iconType = 'default';
          }
        }
      }

      var alertCls = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type), true), _defineProperty(_classNames, "".concat(prefixCls, "-close"), !closing), _defineProperty(_classNames, "".concat(prefixCls, "-with-description"), !!description), _defineProperty(_classNames, "".concat(prefixCls, "-no-icon"), !showIcon), _defineProperty(_classNames, "".concat(prefixCls, "-banner"), !!banner), _defineProperty(_classNames, "".concat(prefixCls, "-closable"), closable || closeText), _classNames), className); // closeable when closeText is assigned

      if (closeText) {
        closable = true;
      }

      var closeIcon = closable ? /*#__PURE__*/React.createElement("button", {
        type: "button",
        className: "".concat(prefixCls, "-close-wrapper")
      }, /*#__PURE__*/React.createElement("a", {
        onClick: this.handleClose,
        className: "".concat(prefixCls, "-close-icon")
      }, closeText || /*#__PURE__*/React.createElement(Icon, {
        type: "close"
      }))) : null;
      var dataOrAriaProps = getDataOrAriaProps(this.props);
      return closed ? null : /*#__PURE__*/React.createElement(Animate, {
        component: "",
        hiddenProp: "hidden",
        transitionName: "".concat(prefixCls, "-slide-up"),
        onEnd: this.animationEnd
      }, /*#__PURE__*/React.createElement("div", _extends({
        hidden: !closing,
        className: alertCls,
        style: style
      }, dataOrAriaProps), showIcon ? /*#__PURE__*/React.createElement(Icon, {
        className: "".concat(prefixCls, "-icon"),
        type: iconType
      }) : null, /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-content")
      }, /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-message")
      }, message), /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-description")
      }, description)), closeIcon));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return ConfigContext;
    }
  }]);

  return Alert;
}(PureComponent);

export { Alert as default };
Alert.displayName = 'Alert';
//# sourceMappingURL=index.js.map
