/**
 * 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 iconsVue = require('@ldesign/icons-vue');
var loading_index = require('../loading/index.js');
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 message_animation = require('./animation.js');
var message_props = require('./props.js');
var message_const = require('./const.js');
require('../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../config.js');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('@babel/runtime/helpers/typeof');
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);

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("message");
var _Message = utils_mixins["default"](classPrefixMixins, configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TMessage",
  props: _objectSpread(_objectSpread({}, message_props["default"]), {}, {
    placement: String
  }),
  data: function data() {
    return {
      timer: null
    };
  },
  computed: {
    classes: function classes() {
      var _this = this;
      var status = {};
      message_const.THEME_LIST.forEach(function (t) {
        status["".concat(_this.classPrefix, "-is-").concat(t)] = _this.theme === t;
      });
      return [this.componentName, status, _defineProperty__default["default"]({}, "".concat(this.classPrefix, "-is-closable"), this.closeBtn || this.$scopedSlots.closeBtn)];
    }
  },
  created: function created() {
    this.duration && this.setTimer();
  },
  mounted: function mounted() {
    var msgDom = this.$refs.msg;
    message_animation.fadeIn(msgDom, this.$props.placement);
  },
  methods: {
    setTimer: function setTimer() {
      var _this2 = this;
      if (!this.duration) return;
      this.timer = Number(setTimeout(function () {
        var _this2$onDurationEnd, _this2$onClose;
        _this2.clearTimer();
        var msgDom = _this2.$refs.msg;
        message_animation.fadeOut(msgDom, _this2.$props.placement, function () {
          _this2.$emit("duration-end");
          _this2.$emit("close");
        });
        (_this2$onDurationEnd = _this2.onDurationEnd) === null || _this2$onDurationEnd === void 0 ? void 0 : _this2$onDurationEnd.call(_this2);
        (_this2$onClose = _this2.onClose) === null || _this2$onClose === void 0 ? void 0 : _this2$onClose.call(_this2, {
          trigger: "duration-end"
        });
      }, this.duration));
    },
    clearTimer: function clearTimer() {
      this.duration && clearTimeout(this.timer);
    },
    close: function close(e) {
      var _this$onCloseBtnClick, _this$onClose;
      this.$emit("close-btn-click", {
        e: e
      });
      this.$emit("close");
      (_this$onCloseBtnClick = this.onCloseBtnClick) === null || _this$onCloseBtnClick === void 0 ? void 0 : _this$onCloseBtnClick.call(this, {
        e: e
      });
      (_this$onClose = this.onClose) === null || _this$onClose === void 0 ? void 0 : _this$onClose.call(this, {
        trigger: "close-click",
        e: e
      });
    },
    renderClose: function renderClose() {
      var h = this.$createElement;
      var _this$useGlobalIcon = this.useGlobalIcon({
          CloseIcon: iconsVue.CloseIcon
        }),
        CloseIcon = _this$useGlobalIcon.CloseIcon;
      var defaultClose = h(CloseIcon);
      return h("span", {
        "class": "".concat(this.componentName, "__close"),
        "on": {
          "click": this.close
        }
      }, [utils_renderTnode.renderTNodeJSX(this, "closeBtn", defaultClose)]);
    },
    renderIcon: function renderIcon() {
      var 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);
      var _this$useGlobalIcon2 = this.useGlobalIcon({
          InfoCircleFilledIcon: iconsVue.InfoCircleFilledIcon,
          CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
          ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon,
          HelpCircleFilledIcon: iconsVue.HelpCircleFilledIcon
        }),
        InfoCircleFilledIcon = _this$useGlobalIcon2.InfoCircleFilledIcon,
        CheckCircleFilledIcon = _this$useGlobalIcon2.CheckCircleFilledIcon,
        ErrorCircleFilledIcon = _this$useGlobalIcon2.ErrorCircleFilledIcon,
        HelpCircleFilledIcon = _this$useGlobalIcon2.HelpCircleFilledIcon;
      var component = {
        info: InfoCircleFilledIcon,
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: ErrorCircleFilledIcon,
        question: HelpCircleFilledIcon,
        loading: loading_index.Loading
      }[this.theme];
      return h(component);
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("div", {
      "ref": "msg",
      "class": this.classes,
      "on": {
        "mouseenter": this.clearTimer,
        "mouseleave": this.setTimer
      }
    }, [this.renderIcon(), utils_renderTnode.renderContent(this, "default", "content"), this.renderClose()]);
  }
});

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