/**
 * 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_notification_notification = require('./notification.js');
var components_notification_const = require('./const.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('lodash/isFunction');
require('@ldesign/icons-vue');
require('../../utils/render-node.js');
require('./props.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("notification");
var NotificationList = utils_mixins["default"](classPrefixMixins).extend({
  components: {
    LNotification: components_notification_notification["default"]
  },
  props: {
    placement: {
      type: String,
      default: "top-right",
      validator(v) {
        return ["top-left", "top-right", "bottom-left", "bottom-right"].includes(v);
      }
    }
  },
  data() {
    return {
      list: []
    };
  },
  computed: {
    styles() {
      return {
        zIndex: components_notification_const.DEFAULT_Z_INDEX,
        ...components_notification_const.PLACEMENT_OFFSET[this.placement]
      };
    }
  },
  methods: {
    add(options) {
      this.list.push(options);
      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`;
    },
    notificationStyles(item) {
      const styles = {
        marginBottom: components_notification_const.DISTANCE
      };
      if (item.offset) {
        styles.position = "relative";
        styles.left = this.getOffset(item.offset[0]);
        styles.top = this.getOffset(item.offset[1]);
      }
      if (item.zIndex) styles["z-index"] = item.zIndex;
      return styles;
    },
    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}__show--${this.placement}`,
      "style": this.styles
    }, [this.list.map((item, index) => h("l-notification", {
      "key": item.id,
      "style": this.notificationStyles(item),
      "props": {
        ...item
      },
      "on": {
        ...this.getListeners(index)
      }
    }))]);
  }
});

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