import * as _vue from "vue";

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

import { Transition, inject, cloneVNode } from 'vue';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined';
import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined';
import InfoCircleOutlined from '@ant-design/icons-vue/InfoCircleOutlined';
import CloseCircleOutlined from '@ant-design/icons-vue/CloseCircleOutlined';
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
import InfoCircleFilled from '@ant-design/icons-vue/InfoCircleFilled';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import classNames from '../_util/classNames';
import BaseMixin from '../_util/BaseMixin';
import PropTypes from '../_util/vue-types';
import getTransitionProps from '../_util/getTransitionProps';
import { getComponent, isValidElement, findDOMNode } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';

function noop() {}

var iconMapFilled = {
  success: CheckCircleFilled,
  info: InfoCircleFilled,
  error: CloseCircleFilled,
  warning: ExclamationCircleFilled
};
var iconMapOutlined = {
  success: CheckCircleOutlined,
  info: InfoCircleOutlined,
  error: CloseCircleOutlined,
  warning: ExclamationCircleOutlined
};
export var AlertProps = {
  /**
   * Type of Alert styles, options:`success`, `info`, `warning`, `error`
   */
  type: PropTypes.oneOf(['success', 'info', 'warning', 'error']),

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

  /** Close text to show */
  closeText: PropTypes.any,

  /** Content of Alert */
  message: PropTypes.any,

  /** Additional content of Alert */
  description: PropTypes.any,

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

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

  /** Whether to show icon */
  showIcon: PropTypes.bool,
  prefixCls: PropTypes.string,
  banner: PropTypes.bool,
  icon: PropTypes.any,
  onClose: PropTypes.func
};
var Alert = {
  name: 'AAlert',
  props: AlertProps,
  mixins: [BaseMixin],
  setup: function setup() {
    return {
      configProvider: inject('configProvider', ConfigConsumerProps)
    };
  },
  data: function data() {
    return {
      closing: false,
      closed: false
    };
  },
  methods: {
    handleClose: function handleClose(e) {
      e.preventDefault();
      var dom = 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 = getComponent(this, 'closeText');
    var description = getComponent(this, 'description');
    var message = getComponent(this, 'message');
    var icon = 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 = classNames(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, null, null)]) : null;

    var iconNode = icon && (isValidElement(icon) ? 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 = getTransitionProps("".concat(prefixCls, "-slide-up"), {
      appear: false,
      onAfterLeave: this.animationEnd
    });
    return closed ? null : _vue.createVNode(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);
};

export default Alert;