/**
 * 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 _Notification from './notification.js';
import { DEFAULT_Z_INDEX, PLACEMENT_OFFSET, DISTANCE } from './const.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import 'lodash/isFunction';
import '@ldesign/icons-vue';
import '../../utils/render-node.js';
import './props.js';

const classPrefixMixins = getClassPrefixMixins("notification");
var NotificationList = mixins(classPrefixMixins).extend({
  components: {
    LNotification: _Notification
  },
  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: DEFAULT_Z_INDEX,
        ...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: 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)
      }
    }))]);
  }
});

export { NotificationList as default };
//# sourceMappingURL=list.js.map
