/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isFunction from 'lodash/isFunction';
import { InfoCircleFilledIcon, CheckCircleFilledIcon, CloseIcon } from 'tdesign-icons-vue';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import props from './props.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = getClassPrefixMixins("notification");
var _Notification = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
  name: "TNotification",
  props: _objectSpread({}, props),
  data: function data() {
    return {
      timer: null
    };
  },
  created: function created() {
    this.duration && this.setTimer();
  },
  methods: {
    setTimer: function setTimer() {
      var _this = this;

      if (!this.duration) {
        return;
      }

      this.timer = Number(setTimeout(function () {
        _this.clearTimer();

        _this.$emit("duration-end");

        if (_this.onDurationEnd) {
          _this.onDurationEnd();
        }
      }, this.duration));
    },
    clearTimer: function clearTimer() {
      this.duration && clearTimeout(this.timer);
    },
    close: function close(e) {
      this.$emit("close-btn-click", {
        e: e
      });

      if (this.onCloseBtnClick) {
        this.onCloseBtnClick({
          e: e
        });
      }
    },
    renderIcon: function renderIcon(h) {
      var 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) {
        var _this$useGlobalIcon = this.useGlobalIcon({
          InfoCircleFilledIcon: InfoCircleFilledIcon,
          CheckCircleFilledIcon: CheckCircleFilledIcon
        }),
            InfoCircleFilledIcon$1 = _this$useGlobalIcon.InfoCircleFilledIcon,
            CheckCircleFilledIcon$1 = _this$useGlobalIcon.CheckCircleFilledIcon;

        var iconType = this.theme === "success" ? h(CheckCircleFilledIcon$1, {
          "class": "".concat(this.classPrefix, "-is-").concat(this.theme)
        }) : h(InfoCircleFilledIcon$1, {
          "class": "".concat(this.classPrefix, "-is-").concat(this.theme)
        });
        icon = h("div", {
          "class": "".concat(this.componentName, "__icon")
        }, [iconType]);
      }

      return icon;
    },
    renderClose: function renderClose() {
      var h = this.$createElement;

      var _this$useGlobalIcon2 = this.useGlobalIcon({
        CloseIcon: CloseIcon
      }),
          CloseIcon$1 = _this$useGlobalIcon2.CloseIcon;

      var defaultClose = h(CloseIcon$1);
      return h("span", {
        "class": "".concat(this.classPrefix, "-message__close"),
        "on": {
          "click": this.close
        }
      }, [renderTNodeJSX(this, "closeBtn", defaultClose)]);
    },
    renderContent: function renderContent$1() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.componentName, "__content")
      }, [renderContent(this, "default", "content")]);
    }
  },
  render: function render(h) {
    var icon = this.renderIcon(h);
    var close = this.renderClose();
    var content = this.renderContent();
    var footer = renderTNodeJSX(this, "footer");
    var title = renderTNodeJSX(this, "title");
    return h("div", {
      "class": "".concat(this.componentName),
      "on": {
        "mouseenter": this.clearTimer,
        "mouseleave": this.setTimer
      }
    }, [icon, h("div", {
      "class": "".concat(this.componentName, "__main")
    }, [h("div", {
      "class": "".concat(this.componentName, "__title__wrap")
    }, [h("span", {
      "class": "".concat(this.componentName, "__title")
    }, [title]), close]), content, footer])]);
  }
});

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