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

'use strict';

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

var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_message_const = require('./const.js');
var components_message_message = require('./message.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('@ldesign/icons-vue');
require('../loading/index.js');
require('../../utils/with-install.js');
require('../../config.js');
require('../loading/loading.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-838e4192.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../loading/plugin.js');
require('./animation.js');
require('./props.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("message__list");
const DEFAULT_Z_INDEX = 5e3;
const getUniqueId = (() => {
  let id = 0;
  return () => {
    id += 1;
    return id;
  };
})();
const MessageList = utils_mixins["default"](classPrefixMixins).extend({
  name: "LMessageList",
  components: {
    TMessage: components_message_message["default"]
  },
  props: {
    zIndex: Number,
    placement: String
  },
  data() {
    return {
      list: []
    };
  },
  computed: {
    styles() {
      return {
        ...components_message_const.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)
      }
    }))]);
  }
});

exports.DEFAULT_Z_INDEX = DEFAULT_Z_INDEX;
exports.MessageList = MessageList;
exports["default"] = MessageList;
//# sourceMappingURL=list.js.map
