/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { CloseIcon, InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, HelpCircleFilledIcon } from '@ldesign/icons-vue';
import { Loading } from '../loading/index.js';
import { renderLNodeJSX, renderContent } from '../../utils/render-node.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { fadeIn, fadeOut } from './animation.js';
import props from './props.js';
import { THEME_LIST } from './const.js';
import '../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../config.js';
import '../loading/loading.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../chunks/defineProperty-838e4192.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../loading/style';
import '../loading/type.js';
import '../loading/plugin.js';

const classPrefixMixins = getClassPrefixMixins("message");
var _Message = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
  name: "LMessage",
  props: {
    ...props,
    placement: String
  },
  data() {
    return {
      timer: null
    };
  },
  computed: {
    classes() {
      const status = {};
      THEME_LIST.forEach(t => {
        status[`${this.classPrefix}-is-${t}`] = this.theme === t;
      });
      return [this.componentName, status, {
        [`${this.classPrefix}-is-closable`]: this.closeBtn || this.$scopedSlots.closeBtn
      }];
    }
  },
  created() {
    this.duration && this.setTimer();
  },
  mounted() {
    const msgDom = this.$refs.msg;
    fadeIn(msgDom, this.$props.placement);
  },
  methods: {
    setTimer() {
      if (!this.duration) return;
      this.timer = Number(setTimeout(() => {
        var _this$onDurationEnd, _this$onClose;
        this.clearTimer();
        const msgDom = this.$refs.msg;
        fadeOut(msgDom, this.$props.placement, () => {
          this.$emit("duration-end");
          this.$emit("close");
        });
        (_this$onDurationEnd = this.onDurationEnd) === null || _this$onDurationEnd === void 0 ? void 0 : _this$onDurationEnd.call(this);
        (_this$onClose = this.onClose) === null || _this$onClose === void 0 ? void 0 : _this$onClose.call(this, {
          trigger: "duration-end"
        });
      }, this.duration));
    },
    clearTimer() {
      this.duration && clearTimeout(this.timer);
    },
    close(e) {
      var _this$onCloseBtnClick, _this$onClose2;
      this.$emit("close-btn-click", {
        e
      });
      this.$emit("close");
      (_this$onCloseBtnClick = this.onCloseBtnClick) === null || _this$onCloseBtnClick === void 0 ? void 0 : _this$onCloseBtnClick.call(this, {
        e
      });
      (_this$onClose2 = this.onClose) === null || _this$onClose2 === void 0 ? void 0 : _this$onClose2.call(this, {
        trigger: "close-click",
        e
      });
    },
    renderClose() {
      const h = this.$createElement;
      const {
        CloseIcon: CloseIcon$1
      } = this.useGlobalIcon({
        CloseIcon: CloseIcon
      });
      const defaultClose = h(CloseIcon$1);
      return h("span", {
        "class": `${this.componentName}__close`,
        "on": {
          "click": this.close
        }
      }, [renderLNodeJSX(this, "closeBtn", defaultClose)]);
    },
    renderIcon() {
      const h = this.$createElement;
      if (this.icon === false) return;
      if (typeof this.icon === "function") return this.icon(this.$createElement);
      if (this.$scopedSlots.icon) return this.$scopedSlots.icon(null);
      const {
        InfoCircleFilledIcon: InfoCircleFilledIcon$1,
        CheckCircleFilledIcon: CheckCircleFilledIcon$1,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon$1,
        HelpCircleFilledIcon: HelpCircleFilledIcon$1
      } = this.useGlobalIcon({
        InfoCircleFilledIcon: InfoCircleFilledIcon,
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        HelpCircleFilledIcon: HelpCircleFilledIcon
      });
      const component = {
        info: InfoCircleFilledIcon$1,
        success: CheckCircleFilledIcon$1,
        warning: ErrorCircleFilledIcon$1,
        error: ErrorCircleFilledIcon$1,
        question: HelpCircleFilledIcon$1,
        loading: Loading
      }[this.theme];
      return h(component);
    }
  },
  render() {
    const h = arguments[0];
    return h("div", {
      "ref": "msg",
      "class": this.classes,
      "on": {
        "mouseenter": this.clearTimer,
        "mouseleave": this.setTimer
      }
    }, [this.renderIcon(), renderContent(this, "default", "content"), this.renderClose()]);
  }
});

export { _Message as default };
//# sourceMappingURL=message.js.map
