import * as tslib_1 from "tslib";
import { Injectable } from '@angular/core';
import { Overlay } from '@angular/cdk/overlay';
import { ComponentPortal } from '@angular/cdk/portal';
import { ToastComponent } from './toast';
var ToastService = /** @class */ (function () {
    function ToastService(overlay) {
        this.counter = 0;
        this.idPrefix = 'toast';
        this.component = overlay.create().attach(new ComponentPortal(ToastComponent)).instance;
    }
    ToastService.prototype._createToast = function (toastData, options) {
        var componentOptions = Object.assign(toastData, {
            toastId: this._generateComponentId(),
            options: options,
            createdAt: new Date()
        });
        this.component.createToast(componentOptions);
        return componentOptions;
    };
    ToastService.prototype._generateComponentId = function () {
        return this.idPrefix + "-" + this.counter++;
    };
    /**
     * create a success toast
     * @default false
     */
    ToastService.prototype.success = function (content, options) {
        this._createToast({ type: 'success', content: content }, options);
    };
    /**
     * create a error toast
     * @default false
     */
    ToastService.prototype.error = function (content, options) {
        this._createToast({ type: 'error', content: content }, options);
    };
    /**
     * create a info toast
     * @default false
     */
    ToastService.prototype.info = function (content, options) {
        this._createToast({ type: 'info', content: content }, options);
    };
    /**
     * create a warn toast
     * @default false
     */
    ToastService.prototype.warn = function (content, options) {
        this._createToast({ type: 'warning', content: content }, options);
    };
    /**
     * create a toast
     * @default false
     */
    ToastService.prototype.create = function (type, content, options) {
        this._createToast({ type: type, content: content }, options);
    };
    ToastService = tslib_1.__decorate([
        Injectable(),
        tslib_1.__metadata("design:paramtypes", [Overlay])
    ], ToastService);
    return ToastService;
}());
export { ToastService };
//# sourceMappingURL=toast.service.js.map