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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var iconsVue = require('@ldesign/icons-vue');
var components_loading_index = require('../loading/index.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_message_animation = require('./animation.js');
var components_message_props = require('./props.js');
var components_message_const = require('./const.js');
require('../../utils/with-install.js');
require('vue');
require('lodash');
require('../../config.js');
require('../loading/loading.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-838e4192.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../loading/plugin.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("message");
var _Message = utils_mixins["default"](classPrefixMixins, components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LMessage",
  props: {
    ...components_message_props["default"],
    placement: String
  },
  data() {
    return {
      timer: null
    };
  },
  computed: {
    classes() {
      const status = {};
      components_message_const.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;
    components_message_animation.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;
        components_message_animation.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
      } = this.useGlobalIcon({
        CloseIcon: iconsVue.CloseIcon
      });
      const defaultClose = h(CloseIcon);
      return h("span", {
        "class": `${this.componentName}__close`,
        "on": {
          "click": this.close
        }
      }, [utils_renderNode.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,
        CheckCircleFilledIcon,
        ErrorCircleFilledIcon,
        HelpCircleFilledIcon
      } = this.useGlobalIcon({
        InfoCircleFilledIcon: iconsVue.InfoCircleFilledIcon,
        CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon,
        HelpCircleFilledIcon: iconsVue.HelpCircleFilledIcon
      });
      const component = {
        info: InfoCircleFilledIcon,
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: ErrorCircleFilledIcon,
        question: HelpCircleFilledIcon,
        loading: components_loading_index.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(), utils_renderNode.renderContent(this, "default", "content"), this.renderClose()]);
  }
});

exports["default"] = _Message;
//# sourceMappingURL=message.js.map
