"use strict";
const React = require("react");
var __extends = globalThis && globalThis.__extends || function() {
  var extendStatics = function(d, b) {
    extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
      d2.__proto__ = b2;
    } || function(d2, b2) {
      for (var p in b2)
        if (Object.prototype.hasOwnProperty.call(b2, p))
          d2[p] = b2[p];
    };
    return extendStatics(d, b);
  };
  return function(d, b) {
    if (typeof b !== "function" && b !== null)
      throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
    extendStatics(d, b);
    function __() {
      this.constructor = d;
    }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
function getId(noticeProps) {
  if (noticeProps === null || noticeProps === void 0 ? void 0 : noticeProps.id) {
    return noticeProps === null || noticeProps === void 0 ? void 0 : noticeProps.id;
  }
  return "arco_notice_id_" + Math.random().toFixed(10).slice(2);
}
var BaseNotice = function(_super) {
  __extends(BaseNotice2, _super);
  function BaseNotice2(props) {
    var _this = _super.call(this, props) || this;
    _this.add = function(noticeProps) {
      var id = getId(noticeProps);
      _this.setState(function(prevState) {
        var oldNotices = prevState.notices;
        if (noticeProps.id && ~oldNotices.findIndex(function(notice) {
          return notice.id === noticeProps.id;
        })) {
          _this.update(noticeProps);
          return prevState;
        }
        return {
          notices: oldNotices.concat(__assign(__assign({}, noticeProps), { id })),
          position: noticeProps.position
        };
      });
      return id;
    };
    _this.update = function(newNotice) {
      var updatedNotices = _this.state.notices.map(function(oldNotice) {
        if (newNotice.id === oldNotice.id) {
          newNotice.update = true;
          return newNotice;
        }
        return oldNotice;
      });
      _this.setState({
        notices: updatedNotices
      }, function() {
        var notices = _this.state.notices.map(function(oldNotice) {
          if (newNotice.id === oldNotice.id && oldNotice.update) {
            delete oldNotice.update;
          }
          return oldNotice;
        });
        _this.setState({ notices });
      });
    };
    _this.clear = function() {
      _this.setState({
        notices: []
      });
    };
    _this.state = {
      notices: [],
      position: "topRight"
    };
    _this.remove = _this.remove.bind(_this);
    return _this;
  }
  BaseNotice2.prototype.remove = function(id) {
    var newNotices = this.state.notices.filter(function(notice) {
      return notice.id !== id;
    });
    this.setState({
      notices: newNotices
    });
  };
  return BaseNotice2;
}(React.Component);
const BaseNotification = BaseNotice;
module.exports = BaseNotification;
//# sourceMappingURL=notification.js.map
