import * as tslib_1 from "tslib";
import { Optional, Component, ChangeDetectionStrategy, ChangeDetectorRef, ViewEncapsulation } from '@angular/core';
import { ToastConfig } from './toast.config';
var ToastComponent = /** @class */ (function () {
    function ToastComponent(config, cd) {
        this.cd = cd;
        this.toasts = [];
        this.config = Object.assign({}, config);
    }
    // Create a new toast
    ToastComponent.prototype.createToast = function (toastData) {
        toastData.options = this._mergeOptions(toastData.options);
        // prevent duplicate
        var existToast = this.toasts.find(function (toast) {
            return toast.type === toastData.type && toast.content === toastData.content;
        });
        if (existToast) {
            return;
        }
        this.toasts.push(toastData);
        this.cd.markForCheck();
    };
    // Remove a toastData by toastId
    ToastComponent.prototype.removeToast = function (toastId) {
        var _this = this;
        this.toasts.some(function (toastData, index) {
            if (toastData.toastId === toastId) {
                _this.toasts.splice(index, 1);
                _this.cd.markForCheck();
                return true;
            }
        });
    };
    // Remove all toasts
    ToastComponent.prototype.removeToastAll = function () {
        this.toasts = [];
        this.cd.markForCheck();
    };
    // Merge default options and cutom toast options
    ToastComponent.prototype._mergeOptions = function (options) {
        var defaultOptions = {
            duration: this.config.duration,
            animate: this.config.animate
        };
        return Object.assign(defaultOptions, options);
    };
    ToastComponent = tslib_1.__decorate([
        Component({
            selector: 'nb-toast',
            template: "<nb-toast-item *ngFor=\"let toast of toasts;\" [toast]=\"toast\"></nb-toast-item>",
            encapsulation: ViewEncapsulation.None,
            changeDetection: ChangeDetectionStrategy.OnPush,
            preserveWhitespaces: false,
            host: {
                'class': 'nb-widget nb-toast'
            },
            exportAs: 'nbToast'
        }),
        tslib_1.__param(0, Optional()),
        tslib_1.__metadata("design:paramtypes", [ToastConfig,
            ChangeDetectorRef])
    ], ToastComponent);
    return ToastComponent;
}());
export { ToastComponent };
//# sourceMappingURL=toast.js.map