/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var notification_notification = require('./notification.js');
var notification_const = require('./const.js');
require('lodash/isFunction');
require('tdesign-icons-vue');
require('../config.js');
require('../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('./props.js');

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

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

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 NotificationList = Vue__default["default"].extend({
  components: {
    Notification: notification_notification["default"]
  },
  props: {
    placement: {
      type: String,
      "default": "top-right",
      validator: function validator(v) {
        return ["top-left", "top-right", "bottom-left", "bottom-right"].indexOf(v) > -1;
      }
    }
  },
  data: function data() {
    return {
      list: []
    };
  },
  computed: {
    styles: function styles() {
      return _objectSpread({
        zIndex: notification_const.DEFAULT_Z_INDEX
      }, notification_const.PLACEMENT_OFFSET[this.placement]);
    }
  },
  methods: {
    add: function add(options) {
      this.list.push(options);
      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");
    },
    notificationStyles: function notificationStyles(item) {
      var styles = {
        marginBottom: 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: 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": "t-notification__show--".concat(this.placement),
      "style": this.styles
    }, [this.list.map(function (item, index) {
      return h("t-notification", {
        "key": item.id,
        "style": _this2.notificationStyles(item),
        "props": _objectSpread({}, item),
        "on": _objectSpread({}, _this2.getListeners(index))
      });
    })]);
  }
});

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