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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, HelpCircleFilledIcon, CloseIcon } from 'tdesign-icons-vue';
import { Loading } from '../loading/index.js';
import { prefix } from '../config.js';
import { THEME_LIST } from './const.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import props from './props.js';
import { fadeIn, fadeOut } from './animation.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/classnames.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/isObject';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.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 name = "".concat(prefix, "-message");
var _Message = Vue.extend({
  name: "TMessage",
  components: {
    InfoCircleFilledIcon: InfoCircleFilledIcon,
    CheckCircleFilledIcon: CheckCircleFilledIcon,
    ErrorCircleFilledIcon: ErrorCircleFilledIcon,
    HelpCircleFilledIcon: HelpCircleFilledIcon,
    CloseIcon: CloseIcon,
    Loading: Loading
  },
  props: _objectSpread(_objectSpread({}, props), {}, {
    placement: String
  }),
  data: function data() {
    return {
      timer: null
    };
  },
  computed: {
    classes: function classes() {
      var _this = this;

      var status = {};
      THEME_LIST.forEach(function (t) {
        status["".concat(prefix, "-is-").concat(t)] = _this.theme === t;
      });
      return [name, status, _defineProperty({}, "".concat(prefix, "-is-closable"), this.closeBtn || this.$scopedSlots.closeBtn)];
    }
  },
  created: function created() {
    this.duration && this.setTimer();
  },
  mounted: function mounted() {
    var msgDom = this.$refs.msg;
    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;
        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
        }
      }, [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: InfoCircleFilledIcon,
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: ErrorCircleFilledIcon,
        question: HelpCircleFilledIcon,
        loading: 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(), renderContent(this, "default", "content"), this.renderClose()]);
  }
});

export { _Message as default };
//# sourceMappingURL=message.js.map
