"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; 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); }

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

var _vue = _interopRequireWildcard(require("vue"));

var _CloseOutlined = _interopRequireDefault(require("@ant-design/icons-vue/CloseOutlined"));

var _CheckCircleOutlined = _interopRequireDefault(require("@ant-design/icons-vue/CheckCircleOutlined"));

var _ExclamationCircleOutlined = _interopRequireDefault(require("@ant-design/icons-vue/ExclamationCircleOutlined"));

var _InfoCircleOutlined = _interopRequireDefault(require("@ant-design/icons-vue/InfoCircleOutlined"));

var _CloseCircleOutlined = _interopRequireDefault(require("@ant-design/icons-vue/CloseCircleOutlined"));

var _CheckCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/CheckCircleFilled"));

var _ExclamationCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/ExclamationCircleFilled"));

var _InfoCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/InfoCircleFilled"));

var _CloseCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/CloseCircleFilled"));

var _classNames2 = _interopRequireDefault(require("../_util/classNames"));

var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _getTransitionProps = _interopRequireDefault(require("../_util/getTransitionProps"));

var _propsUtil = require("../_util/props-util");

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

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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; }

function noop() {}

var iconMapFilled = {
  success: _CheckCircleFilled.default,
  info: _InfoCircleFilled.default,
  error: _CloseCircleFilled.default,
  warning: _ExclamationCircleFilled.default
};
var iconMapOutlined = {
  success: _CheckCircleOutlined.default,
  info: _InfoCircleOutlined.default,
  error: _CloseCircleOutlined.default,
  warning: _ExclamationCircleOutlined.default
};
var AlertProps = {
  /**
   * Type of Alert styles, options:`success`, `info`, `warning`, `error`
   */
  type: _vueTypes.default.oneOf(['success', 'info', 'warning', 'error']),

  /** Whether Alert can be closed */
  closable: _vueTypes.default.bool,

  /** Close text to show */
  closeText: _vueTypes.default.any,

  /** Content of Alert */
  message: _vueTypes.default.any,

  /** Additional content of Alert */
  description: _vueTypes.default.any,

  /** Callback when close Alert */
  // onClose?: React.MouseEventHandler<HTMLAnchorElement>;

  /** Trigger when animation ending of Alert */
  afterClose: _vueTypes.default.func.def(noop),

  /** Whether to show icon */
  showIcon: _vueTypes.default.bool,
  prefixCls: _vueTypes.default.string,
  banner: _vueTypes.default.bool,
  icon: _vueTypes.default.any,
  onClose: _vueTypes.default.func
};
exports.AlertProps = AlertProps;
var Alert = {
  name: 'AAlert',
  props: AlertProps,
  mixins: [_BaseMixin.default],
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  data: function data() {
    return {
      closing: false,
      closed: false
    };
  },
  methods: {
    handleClose: function handleClose(e) {
      e.preventDefault();
      var dom = (0, _propsUtil.findDOMNode)(this);
      dom.style.height = "".concat(dom.offsetHeight, "px"); // Magic code
      // 重复一次后才能正确设置 height

      dom.style.height = "".concat(dom.offsetHeight, "px");
      this.setState({
        closing: true
      });
      this.$emit('close', e);
    },
    animationEnd: function animationEnd() {
      this.setState({
        closing: false,
        closed: true
      });
      this.afterClose();
    }
  },
  render: function render() {
    var _classNames;

    var customizePrefixCls = this.prefixCls,
        banner = this.banner,
        closing = this.closing,
        closed = this.closed;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('alert', customizePrefixCls);
    var closable = this.closable,
        type = this.type,
        showIcon = this.showIcon;
    var closeText = (0, _propsUtil.getComponent)(this, 'closeText');
    var description = (0, _propsUtil.getComponent)(this, 'description');
    var message = (0, _propsUtil.getComponent)(this, 'message');
    var icon = (0, _propsUtil.getComponent)(this, 'icon'); // banner模式默认有 Icon

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

    type = banner && type === undefined ? 'warning' : type || 'info';
    var IconType = (description ? iconMapOutlined : iconMapFilled)[type] || null; // closeable when closeText is assigned

    if (closeText) {
      closable = true;
    }

    var alertCls = (0, _classNames2.default)(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type), true), _defineProperty(_classNames, "".concat(prefixCls, "-closing"), 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), _classNames));
    var closeIcon = closable ? _vue.createVNode("a", {
      "type": "button",
      "onClick": this.handleClose,
      "class": "".concat(prefixCls, "-close-icon"),
      "tabindex": 0
    }, [closeText ? _vue.createVNode("span", {
      "class": "".concat(prefixCls, "-close-text")
    }, [closeText]) : _vue.createVNode(_CloseOutlined.default, null, null)]) : null;

    var iconNode = icon && ((0, _propsUtil.isValidElement)(icon) ? (0, _vue.cloneVNode)(icon, {
      class: "".concat(prefixCls, "-icon")
    }) : _vue.createVNode("span", {
      "class": "".concat(prefixCls, "-icon")
    }, [icon])) || _vue.createVNode(IconType, {
      "class": "".concat(prefixCls, "-icon")
    }, null); // h(iconType, { class: `${prefixCls}-icon` });


    var transitionProps = (0, _getTransitionProps.default)("".concat(prefixCls, "-slide-up"), {
      appear: false,
      onAfterLeave: this.animationEnd
    });
    return closed ? null : _vue.createVNode(_vue.Transition, transitionProps, {
      default: function _default() {
        return [_vue.withDirectives(_vue.createVNode("div", {
          "class": alertCls,
          "data-show": !closing
        }, [showIcon ? iconNode : null, _vue.createVNode("span", {
          "class": "".concat(prefixCls, "-message")
        }, [message]), _vue.createVNode("span", {
          "class": "".concat(prefixCls, "-description")
        }, [description]), closeIcon]), [[_vue.vShow, !closing]])];
      }
    });
  }
};
/* istanbul ignore next */

Alert.install = function (app) {
  app.component(Alert.name, Alert);
};

var _default2 = Alert;
exports.default = _default2;