/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { PLACEMENT_OFFSET } from './const.js';
import _Message from './message.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import 'tdesign-icons-vue';
import '../loading/index.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/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/dom.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../config.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 classPrefixMixins = getClassPrefixMixins("message__list");
var DEFAULT_Z_INDEX = 5e3;

var getUniqueId = function () {
  var id = 0;
  return function () {
    id += 1;
    return id;
  };
}();

var MessageList = mixins(classPrefixMixins).extend({
  name: "TMessageList",
  components: {
    TMessage: _Message
  },
  props: {
    zIndex: Number,
    placement: String
  },
  data: function data() {
    return {
      list: []
    };
  },
  computed: {
    styles: function styles() {
      return _objectSpread(_objectSpread({}, PLACEMENT_OFFSET[this.placement]), {}, {
        zIndex: this.zIndex !== DEFAULT_Z_INDEX ? this.zIndex : DEFAULT_Z_INDEX
      });
    }
  },
  methods: {
    add: function add(msg) {
      var mg = _objectSpread(_objectSpread({}, msg), {}, {
        key: getUniqueId(),
        placement: this.placement
      });

      this.list.push(mg);
      return this.list.length - 1;
    },
    remove: function remove(index) {
      this.list.splice(index, 1);
    },
    removeAll: function removeAll() {
      this.list = [];
    },
    getOffset: function getOffset(val) {
      if (!val) return;
      return isNaN(Number(val)) ? val : "".concat(val, "px");
    },
    msgStyles: function msgStyles(item) {
      return item.offset && {
        position: "relative",
        left: this.getOffset(item.offset[0]),
        top: this.getOffset(item.offset[1])
      };
    },
    getListeners: function getListeners(index) {
      var _this = this;

      return {
        "close-btn-click": function closeBtnClick() {
          return _this.remove(index);
        },
        "duration-end": function durationEnd() {
          return _this.remove(index);
        }
      };
    }
  },
  render: function render() {
    var _this2 = this;

    var h = arguments[0];
    if (!this.list.length) return;
    return h("div", {
      "class": this.componentName,
      "style": this.styles
    }, [this.list.map(function (item, index) {
      return h("t-message", {
        "key": item.key,
        "style": _this2.msgStyles(item),
        "props": _objectSpread({}, item),
        "on": _objectSpread({}, _this2.getListeners(index))
      });
    })]);
  }
});

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