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

import isFunction from 'lodash/isFunction';
import { InfoCircleFilledIcon, CheckCircleFilledIcon, CloseIcon } from '@ldesign/icons-vue';
import { renderLNodeJSX, renderContent } from '../../utils/render-node.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import props from './props.js';
import 'vue';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

const classPrefixMixins = getClassPrefixMixins("notification");
var _Notification = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
  name: "LNotification",
  props: {
    ...props
  },
  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(this.icon)) {
        icon = this.icon(h);
      } else if (this.$scopedSlots.icon) {
        icon = this.$scopedSlots.icon(null);
      } else if (this.theme) {
        const {
          InfoCircleFilledIcon: InfoCircleFilledIcon$1,
          CheckCircleFilledIcon: CheckCircleFilledIcon$1
        } = this.useGlobalIcon({
          InfoCircleFilledIcon: InfoCircleFilledIcon,
          CheckCircleFilledIcon: CheckCircleFilledIcon
        });
        const iconType = this.theme === "success" ? h(CheckCircleFilledIcon$1, {
          "class": `${this.classPrefix}-is-${this.theme}`
        }) : h(InfoCircleFilledIcon$1, {
          "class": `${this.classPrefix}-is-${this.theme}`
        });
        icon = h("div", {
          "class": `${this.componentName}__icon`
        }, [iconType]);
      }
      return icon;
    },
    renderClose() {
      const h = this.$createElement;
      const {
        CloseIcon: CloseIcon$1
      } = this.useGlobalIcon({
        CloseIcon: CloseIcon
      });
      const defaultClose = h(CloseIcon$1);
      return h("span", {
        "class": `${this.classPrefix}-message__close`,
        "on": {
          "click": this.close
        }
      }, [renderLNodeJSX(this, "closeBtn", defaultClose)]);
    },
    renderContent() {
      const h = this.$createElement;
      return h("div", {
        "class": `${this.componentName}__content`
      }, [renderContent(this, "default", "content")]);
    }
  },
  render(h) {
    const icon = this.renderIcon(h);
    const close = this.renderClose();
    const content = this.renderContent();
    const footer = renderLNodeJSX(this, "footer");
    const title = 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])]);
  }
});

export { _Notification as default };
//# sourceMappingURL=notification.js.map
