/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { PLACEMENT_OFFSET } from './const.js';
import _Message from './message.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '@ldesign/icons-vue';
import '../loading/index.js';
import '../../utils/with-install.js';
import '../../config.js';
import '../loading/loading.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../chunks/defineProperty-838e4192.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import '../loading/style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import './animation.js';
import './props.js';

const classPrefixMixins = getClassPrefixMixins("message__list");
const DEFAULT_Z_INDEX = 5e3;
const getUniqueId = (() => {
  let id = 0;
  return () => {
    id += 1;
    return id;
  };
})();
const MessageList = mixins(classPrefixMixins).extend({
  name: "LMessageList",
  components: {
    TMessage: _Message
  },
  props: {
    zIndex: Number,
    placement: String
  },
  data() {
    return {
      list: []
    };
  },
  computed: {
    styles() {
      return {
        ...PLACEMENT_OFFSET[this.placement],
        zIndex: this.zIndex !== DEFAULT_Z_INDEX ? this.zIndex : DEFAULT_Z_INDEX
      };
    }
  },
  methods: {
    add(msg) {
      const mg = {
        ...msg,
        key: getUniqueId(),
        placement: this.placement
      };
      this.list.push(mg);
      return this.list.length - 1;
    },
    remove(index) {
      this.list.splice(index, 1);
    },
    removeAll() {
      this.list = [];
    },
    getOffset(val) {
      if (!val) return;
      return isNaN(Number(val)) ? val : `${val}px`;
    },
    msgStyles(item) {
      return item.offset && {
        position: "relative",
        left: this.getOffset(item.offset[0]),
        top: this.getOffset(item.offset[1])
      };
    },
    getListeners(index) {
      return {
        "close-btn-click": () => this.remove(index),
        "duration-end": () => this.remove(index)
      };
    }
  },
  render() {
    const h = arguments[0];
    if (!this.list.length) return;
    return h("div", {
      "class": this.componentName,
      "style": this.styles
    }, [this.list.map((item, index) => h("t-message", {
      "key": item.key,
      "style": this.msgStyles(item),
      "props": {
        ...item
      },
      "on": {
        ...this.getListeners(index)
      }
    }))]);
  }
});

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