/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isFunction = require('lodash/isFunction');
var iconsVue = require('@ldesign/icons-vue');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
var notification_props = require('./props.js');
require('@babel/runtime/helpers/typeof');
require('vue');
require('@vue/composition-api');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');

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

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

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__default["default"](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 = configProvider_configReceiver.getClassPrefixMixins("notification");
var _Notification = utils_mixins["default"](classPrefixMixins, configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TNotification",
  props: _objectSpread({}, notification_props["default"]),
  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__default["default"](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: iconsVue.InfoCircleFilledIcon,
            CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon
          }),
          InfoCircleFilledIcon = _this$useGlobalIcon.InfoCircleFilledIcon,
          CheckCircleFilledIcon = _this$useGlobalIcon.CheckCircleFilledIcon;
        var iconType = this.theme === "success" ? h(CheckCircleFilledIcon, {
          "class": "".concat(this.classPrefix, "-is-").concat(this.theme)
        }) : h(InfoCircleFilledIcon, {
          "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: iconsVue.CloseIcon
        }),
        CloseIcon = _this$useGlobalIcon2.CloseIcon;
      var defaultClose = h(CloseIcon);
      return h("span", {
        "class": "".concat(this.classPrefix, "-message__close"),
        "on": {
          "click": this.close
        }
      }, [utils_renderTnode.renderTNodeJSX(this, "closeBtn", defaultClose)]);
    },
    renderContent: function renderContent() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.componentName, "__content")
      }, [utils_renderTnode.renderContent(this, "default", "content")]);
    }
  },
  render: function render(h) {
    var icon = this.renderIcon(h);
    var close = this.renderClose();
    var content = this.renderContent();
    var footer = utils_renderTnode.renderTNodeJSX(this, "footer");
    var title = utils_renderTnode.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])]);
  }
});

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