/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var components_message_const = require('./const.js');
var components_message_message = require('./message.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
require('@ldesign/icons-vue');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('vue');
require('../../chunks/defineProperty-28395935.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/with-install.js');
require('../loading/plugin.js');
require('./props.js');
require('./animation.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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 classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("message__list");
var DEFAULT_Z_INDEX = 5e3;

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

var MessageList = utils_mixins["default"](classPrefixMixins).extend({
  name: "LMessageList",
  components: {
    TMessage: components_message_message["default"]
  },
  props: {
    zIndex: Number,
    placement: String
  },
  data: function data() {
    return {
      list: []
    };
  },
  computed: {
    styles: function styles() {
      return _objectSpread(_objectSpread({}, components_message_const.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))
      });
    })]);
  }
});

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