/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var tdesignIconsVue = require('tdesign-icons-vue');
var loading_index = require('../loading/index.js');
var config = require('../config.js');
var message_const = require('./const.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var message_props = require('./props.js');
var message_animation = require('./animation.js');
require('../loading/loading.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/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/classnames.js');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isObject');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

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 name = "".concat(config.prefix, "-message");
var _Message = Vue__default["default"].extend({
  name: "TMessage",
  components: {
    InfoCircleFilledIcon: tdesignIconsVue.InfoCircleFilledIcon,
    CheckCircleFilledIcon: tdesignIconsVue.CheckCircleFilledIcon,
    ErrorCircleFilledIcon: tdesignIconsVue.ErrorCircleFilledIcon,
    HelpCircleFilledIcon: tdesignIconsVue.HelpCircleFilledIcon,
    CloseIcon: tdesignIconsVue.CloseIcon,
    Loading: loading_index.Loading
  },
  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(config.prefix, "-is-").concat(t)] = _this.theme === t;
      });
      return [name, status, _defineProperty__default["default"]({}, "".concat(config.prefix, "-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 () {
        _this2.clearTimer();

        var msgDom = _this2.$refs.msg;
        message_animation.fadeOut(msgDom, _this2.$props.placement, function () {
          _this2.$emit("duration-end");
        });

        if (_this2.onDurationEnd) {
          _this2.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
        });
      }
    },
    renderClose: function renderClose() {
      var h = this.$createElement;
      var defaultClose = h("close-icon");
      return h("span", {
        "class": "".concat(name, "__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 component = {
        info: tdesignIconsVue.InfoCircleFilledIcon,
        success: tdesignIconsVue.CheckCircleFilledIcon,
        warning: tdesignIconsVue.ErrorCircleFilledIcon,
        error: tdesignIconsVue.ErrorCircleFilledIcon,
        question: tdesignIconsVue.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
