(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var Store = /** @class */ (function () {
        function Store() {
            this.subscribes = [];
            this.items = [];
        }
        Store.prototype.subscribe = function (callback) {
            this.subscribes.push(callback);
        };
        Store.prototype.unsubscribe = function (callback) {
            this.subscribes = this.subscribes.filter(function (subscriber) {
                return subscriber === callback ? undefined : subscriber;
            });
        };
        Store.prototype.notify = function () {
            this.subscribes.forEach(function (subscriber) { return subscriber(); });
        };
        Store.prototype.add = function (item) {
            var _this = this;
            var index = this.items.findIndex(function (i) { return i.message === item.message; });
            if (index === -1) {
                this.items.push(item);
            }
            else {
                var count = this.items[index].count;
                this.items[index] = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, item), { id: this.items[index].id, count: count ? count + 1 : 2 });
            }
            setTimeout(function () {
                _this.remove(item.id);
                _this.notify();
            }, item.duration || 3000);
            this.notify();
        };
        Store.prototype.remove = function (id) {
            this.items = this.items.filter(function (storeItem) {
                return storeItem.id === id ? undefined : storeItem;
            });
            this.notify();
        };
        Object.defineProperty(Store.prototype, "data", {
            get: function () {
                return this.items;
            },
            enumerable: false,
            configurable: true
        });
        return Store;
    }());
    exports.default = new Store();
});
