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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var isFunction = require('lodash/isFunction');
var loading_index = require('../loading/index.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_tnode = require('../hooks/tnode.js');
var message_const = require('./const.js');
var message_props = require('./props.js');
var message_animation = require('./animation.js');
require('../utils/withInstall.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../utils/dom.js');
require('../_chunks/dep-f4db2590.js');
require('lodash/isString');
require('lodash/isArray');
require('../utils/easing.js');
require('../loading/loading.js');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/useTeleport.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('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
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 _Message = vue.defineComponent({
  name: "TMessage",
  props: _objectSpread(_objectSpread({}, message_props["default"]), {}, {
    placement: String
  }),
  setup: function setup(props2, _ref) {
    var slots = _ref.slots,
      expose = _ref.expose;
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("message");
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        InfoCircleFilledIcon: iconsVueNext.InfoCircleFilledIcon,
        CheckCircleFilledIcon: iconsVueNext.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon,
        HelpCircleFilledIcon: iconsVueNext.HelpCircleFilledIcon,
        CloseIcon: iconsVueNext.CloseIcon
      }),
      InfoCircleFilledIcon = _useGlobalIcon.InfoCircleFilledIcon,
      CheckCircleFilledIcon = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon = _useGlobalIcon.ErrorCircleFilledIcon,
      HelpCircleFilledIcon = _useGlobalIcon.HelpCircleFilledIcon,
      CloseIcon = _useGlobalIcon.CloseIcon;
    var classPrefix = hooks_useConfig.usePrefixClass();
    var renderTNode = hooks_tnode.useTNodeJSX();
    var renderContent = hooks_tnode.useContent();
    var msgRef = vue.ref(null);
    var timer = vue.ref(null);
    var classes = vue.computed(function () {
      var status = {};
      message_const.THEME_LIST.forEach(function (t) {
        return status["".concat(classPrefix.value, "-is-").concat(t)] = props2.theme === t;
      });
      return [COMPONENT_NAME.value, status, _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-closable"), props2.closeBtn || slots.closeBtn)];
    });
    var close = function close(e) {
      var _props2$onCloseBtnCli;
      (_props2$onCloseBtnCli = props2.onCloseBtnClick) === null || _props2$onCloseBtnCli === void 0 ? void 0 : _props2$onCloseBtnCli.call(props2, {
        e: e
      });
    };
    var clearTimer = function clearTimer() {
      props2.duration && clearTimeout(timer.value);
    };
    var setTimer = function setTimer() {
      if (!props2.duration) return;
      timer.value = Number(setTimeout(function () {
        clearTimer();
        var msgDom = msgRef.value;
        message_animation.fadeOut(msgDom, props2.placement, function () {
          var _props2$onDurationEnd;
          (_props2$onDurationEnd = props2.onDurationEnd) === null || _props2$onDurationEnd === void 0 ? void 0 : _props2$onDurationEnd.call(props2);
        });
      }, props2.duration));
    };
    var renderClose = function renderClose() {
      var defaultClose = vue.createVNode(CloseIcon, null, null);
      return vue.createVNode("span", {
        "class": "".concat(COMPONENT_NAME.value, "__close"),
        "onClick": close
      }, [renderTNode("closeBtn", defaultClose)]);
    };
    var renderIcon = function renderIcon() {
      if (props2.icon === false) return;
      if (isFunction__default["default"](props2.icon)) return props2.icon(vue.h);
      if (slots.icon) return slots.icon(null);
      var Icon = {
        info: InfoCircleFilledIcon,
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: ErrorCircleFilledIcon,
        question: HelpCircleFilledIcon,
        loading: loading_index.Loading
      }[props2.theme];
      return vue.createVNode(Icon, null, null);
    };
    vue.onBeforeMount(function () {
      props2.duration && setTimer();
    });
    vue.onMounted(function () {
      var msgDom = msgRef.value;
      message_animation.fadeIn(msgDom, props2.placement);
    });
    expose({
      close: close
    });
    return function () {
      return vue.createVNode("div", {
        "ref": msgRef,
        "class": classes.value,
        "onMouseenter": clearTimer,
        "onMouseleave": setTimer
      }, [renderIcon(), renderContent("content", "default"), renderClose()]);
    };
  }
});

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