var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Injectable } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { publish } from 'rxjs/operators';
var AlertService = /** @class */ (function () {
    function AlertService(router) {
        var _this = this;
        this.router = router;
        this.preserveAlerts = false;
        this.alerts = new Observable(function (observer) {
            _this.observer = observer;
        }).pipe(publish());
        this.alerts.connect();
        this.router
            .events
            .subscribe(function (event) {
            if (event instanceof NavigationStart) {
                if (!_this.preserveAlerts) {
                    _this.clear();
                }
                _this.setPreserveAlerts(false);
            }
        });
    }
    AlertService.prototype.push = function (alert) {
        this.observer.next(alert);
    };
    AlertService.prototype.clear = function () {
        this.observer.next(null);
    };
    AlertService.prototype.error = function (message) {
        this.push({
            level: 'error',
            message: message
        });
    };
    AlertService.prototype.warning = function (message) {
        this.push({
            level: 'warning',
            message: message
        });
    };
    AlertService.prototype.success = function (message) {
        this.push({
            level: 'success',
            message: message
        });
    };
    AlertService.prototype.setPreserveAlerts = function (preserve) {
        this.preserveAlerts = preserve;
    };
    AlertService.prototype.isPreserveAlerts = function () {
        return this.preserveAlerts;
    };
    AlertService.prototype.message = function (message) {
        this.push({
            level: 'message',
            message: message
        });
    };
    AlertService = __decorate([
        Injectable(),
        __metadata("design:paramtypes", [Router])
    ], AlertService);
    return AlertService;
}());
export { AlertService };
//# sourceMappingURL=alert.service.js.map