import { mergeProps as _mergeProps, withDirectives as _withDirectives, vShow as _vShow, createVNode as _createVNode } from "vue";
//@ts-nocheck
import { defineComponent, onBeforeUnmount, ref, onMounted } from "vue";
import ExpandTransition from "../expand-transition";
import { getComponent, render } from "../_util/props-util";
import Icon from "../icon";
const messageProps = {
  prefixCls: String,
  default: [String, Number, Object, Function],
  content: [String, Number, Object, Function],
  closable: Boolean,
  closeIcon: [String, Object],
  duration: {
    default: 3000
  },
  onAfterLeave: Function,
  key: [String, Number],
  transitionProps: Object
};
export default defineComponent({
  props: messageProps,

  setup(props, {
    expose
  }) {
    const show = ref(true);

    function close() {
      show.value = false;
      clearCloseTimer();
    }

    let timer;

    function startCloseTimer() {
      clearCloseTimer();
      const {
        duration
      } = props;

      if (duration) {
        timer = setTimeout(close, duration);
      }
    }

    function clearCloseTimer() {
      clearTimeout(timer);
    }

    onMounted(() => {
      startCloseTimer();
    });
    onBeforeUnmount(() => {
      clearCloseTimer();
    });
    expose({
      close
    });
    return vm => {
      const {
        prefixCls,
        closable
      } = props;

      const closeNode = closable && _createVNode("a", {
        "class": `${prefixCls}_close`,
        "onClick": close
      }, [getComponent(vm, 'closeIcon') || _createVNode(Icon, {
        "type": "cross"
      }, null)]);

      const content = render(props.default) || [_createVNode("div", {
        "class": `${prefixCls}_content`
      }, [getComponent(vm, 'content')]), closeNode];
      return _createVNode(ExpandTransition, _mergeProps({
        "appear": true,
        "onAfterLeave": props.onAfterLeave
      }, props.transitionProps), {
        default: () => [_withDirectives(_createVNode("div", {
          "class": `${prefixCls}-wrapper`,
          "onMouseenter": clearCloseTimer,
          "onMouseleave": startCloseTimer
        }, [_createVNode("div", {
          "class": prefixCls
        }, [content])]), [[_vShow, show.value]])]
      });
    };
  }

});