/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseIcon, InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, HelpCircleFilledIcon } from '@ldesign/icons-vue';
import { Loading } from '../loading/index.js';
import { THEME_LIST } from './const.js';
import { renderLNodeJSX, renderContent } from '../../utils/render-node.js';
import props from './props.js';
import { fadeIn, fadeOut } from './animation.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import 'vue';
import '../../chunks/defineProperty-28395935.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/slicedToArray';
import '../../config.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/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/with-install.js';
import '../loading/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 classPrefixMixins = getClassPrefixMixins("message");
var _Message = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
  name: "LMessage",
  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(_this.classPrefix, "-is-").concat(t)] = _this.theme === t;
      });
      return [this.componentName, status, _defineProperty({}, "".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;
    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;
        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: CloseIcon
      }),
          CloseIcon$1 = _this$useGlobalIcon.CloseIcon;

      var defaultClose = h(CloseIcon$1);
      return h("span", {
        "class": "".concat(this.componentName, "__close"),
        "on": {
          "click": this.close
        }
      }, [renderLNodeJSX(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: InfoCircleFilledIcon,
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        HelpCircleFilledIcon: HelpCircleFilledIcon
      }),
          InfoCircleFilledIcon$1 = _this$useGlobalIcon2.InfoCircleFilledIcon,
          CheckCircleFilledIcon$1 = _this$useGlobalIcon2.CheckCircleFilledIcon,
          ErrorCircleFilledIcon$1 = _this$useGlobalIcon2.ErrorCircleFilledIcon,
          HelpCircleFilledIcon$1 = _this$useGlobalIcon2.HelpCircleFilledIcon;

      var component = {
        info: InfoCircleFilledIcon$1,
        success: CheckCircleFilledIcon$1,
        warning: ErrorCircleFilledIcon$1,
        error: ErrorCircleFilledIcon$1,
        question: HelpCircleFilledIcon$1,
        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
