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

import _Notification from './notification.js';
import { DEFAULT_Z_INDEX, PLACEMENT_OFFSET, DISTANCE } from './const.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import 'lodash/isFunction';
import '@ldesign/icons-vue';
import '../../utils/render-node.js';
import 'vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import './props.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-b1584b65.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"].indexOf(v) > -1;
      }

    }
  },

  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
