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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, createVNode, mergeProps } from 'vue';
import { usePrefixClass } from '../hooks/useConfig.js';
import { PLACEMENT_OFFSET } from './const.js';
import _Message from './message.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-e041f5b0.js';
import 'dayjs';
import '@ldesign/icons-vue-next';
import '../loading/index.js';
import '../utils/withInstall.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../utils/dom.js';
import '../utils/easing.js';
import '../loading/loading.js';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/useTeleport.js';
import '../loading/props.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/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../hooks/useGlobalIcon.js';
import '../hooks/tnode.js';
import './props.js';
import './animation.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 DEFAULT_Z_INDEX = 6e3;
var getUniqueId = function () {
  var id = 0;
  return function () {
    id += 1;
    return id;
  };
}();
var MessageList = defineComponent({
  name: "TMessageList",
  props: {
    zIndex: {
      type: Number,
      "default": 0
    },
    placement: {
      type: String,
      "default": ""
    }
  },
  setup: function setup(props, _ref) {
    var expose = _ref.expose;
    var COMPONENT_NAME = usePrefixClass("message__list");
    var list = ref([]);
    var messageList = ref([]);
    var styles = computed(function () {
      return _objectSpread(_objectSpread({}, PLACEMENT_OFFSET[props.placement]), {}, {
        zIndex: props.zIndex !== DEFAULT_Z_INDEX ? props.zIndex : DEFAULT_Z_INDEX
      });
    });
    var add = function add(msg) {
      var mg = _objectSpread(_objectSpread({}, msg), {}, {
        key: getUniqueId()
      });
      list.value.push(mg);
      return list.value.length - 1;
    };
    var remove = function remove(index) {
      list.value.splice(index, 1);
    };
    var removeAll = function removeAll() {
      list.value = [];
    };
    var getOffset = function getOffset(val) {
      if (!val) return;
      return isNaN(Number(val)) ? val : "".concat(val, "px");
    };
    var msgStyles = function msgStyles(item) {
      return item.offset && {
        position: "relative",
        left: getOffset(item.offset[0]),
        top: getOffset(item.offset[1])
      };
    };
    var getProps = function getProps(index, item) {
      return _objectSpread(_objectSpread({}, item), {}, {
        onCloseBtnClick: function onCloseBtnClick(e) {
          if (item.onCloseBtnClick) item.onCloseBtnClick(e);
          return remove(index);
        },
        onDurationEnd: function onDurationEnd() {
          if (item.onDurationEnd) item.onDurationEnd();
          return remove(index);
        }
      });
    };
    var addChild = function addChild(el) {
      if (el) messageList.value.push(el);
    };
    expose({
      add: add,
      removeAll: removeAll,
      list: list,
      messageList: messageList
    });
    return function () {
      if (!list.value.length) return;
      return createVNode("div", {
        "class": COMPONENT_NAME.value,
        "style": styles.value
      }, [list.value.map(function (item, index) {
        return createVNode(_Message, mergeProps({
          "key": item.key,
          "style": msgStyles(item),
          "ref": addChild
        }, getProps(index, item)), null);
      })]);
    };
  }
});

export { DEFAULT_Z_INDEX, MessageList, MessageList as default };
//# sourceMappingURL=messageList.js.map
