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

'use strict';

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

var isFunction = require('lodash/isFunction');
var iconsVue = require('@ldesign/icons-vue');
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_notification_props = require('./props.js');
require('vue');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("notification");
var _Notification = utils_mixins["default"](classPrefixMixins, components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LNotification",
  props: {
    ...components_notification_props["default"]
  },
  data() {
    return {
      timer: null
    };
  },
  created() {
    this.duration && this.setTimer();
  },
  methods: {
    setTimer() {
      if (!this.duration) return;
      this.timer = Number(setTimeout(() => {
        this.clearTimer();
        this.$emit("duration-end");
        if (this.onDurationEnd) this.onDurationEnd();
      }, this.duration));
    },
    clearTimer() {
      this.duration && clearTimeout(this.timer);
    },
    close(e) {
      this.$emit("close-btn-click", {
        e
      });
      if (this.onCloseBtnClick) this.onCloseBtnClick({
        e
      });
    },
    renderIcon(h) {
      let icon;
      if (this.icon === false) return null;
      if (isFunction__default["default"](this.icon)) {
        icon = this.icon(h);
      } else if (this.$scopedSlots.icon) {
        icon = this.$scopedSlots.icon(null);
      } else if (this.theme) {
        const {
          InfoCircleFilledIcon,
          CheckCircleFilledIcon
        } = this.useGlobalIcon({
          InfoCircleFilledIcon: iconsVue.InfoCircleFilledIcon,
          CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon
        });
        const iconType = this.theme === "success" ? h(CheckCircleFilledIcon, {
          "class": `${this.classPrefix}-is-${this.theme}`
        }) : h(InfoCircleFilledIcon, {
          "class": `${this.classPrefix}-is-${this.theme}`
        });
        icon = h("div", {
          "class": `${this.componentName}__icon`
        }, [iconType]);
      }
      return icon;
    },
    renderClose() {
      const h = this.$createElement;
      const {
        CloseIcon
      } = this.useGlobalIcon({
        CloseIcon: iconsVue.CloseIcon
      });
      const defaultClose = h(CloseIcon);
      return h("span", {
        "class": `${this.classPrefix}-message__close`,
        "on": {
          "click": this.close
        }
      }, [utils_renderNode.renderLNodeJSX(this, "closeBtn", defaultClose)]);
    },
    renderContent() {
      const h = this.$createElement;
      return h("div", {
        "class": `${this.componentName}__content`
      }, [utils_renderNode.renderContent(this, "default", "content")]);
    }
  },
  render(h) {
    const icon = this.renderIcon(h);
    const close = this.renderClose();
    const content = this.renderContent();
    const footer = utils_renderNode.renderLNodeJSX(this, "footer");
    const title = utils_renderNode.renderLNodeJSX(this, "title");
    return h("div", {
      "class": `${this.componentName}`,
      "on": {
        "mouseenter": this.clearTimer,
        "mouseleave": this.setTimer
      }
    }, [icon, h("div", {
      "class": `${this.componentName}__main`
    }, [h("div", {
      "class": `${this.componentName}__title__wrap`
    }, [h("span", {
      "class": `${this.componentName}__title`
    }, [title]), close]), content, footer])]);
  }
});

exports["default"] = _Notification;
//# sourceMappingURL=notification.js.map
