import * as tslib_1 from "tslib";
import { Injectable, ViewContainerRef } from '@angular/core';
import { AlertComponent } from './alert';
import { ConfirmComponent } from './confirm';
import { DynamicComponentService } from '../overlay/dynamic-component.service';
var DialogService = /** @class */ (function () {
    function DialogService(viewContainerRef, dynamicComponentService) {
        this.viewContainerRef = viewContainerRef;
        this.dynamicComponentService = dynamicComponentService;
    }
    DialogService.prototype.createOverlay = function (type, content, title) {
        var _this = this;
        var componentRef = this.dynamicComponentService.createDynamicComponent(this.viewContainerRef, AlertComponent, '', window.document.body);
        this.dialogInstance = componentRef.instance;
        var config = {
            type: type,
            title: title,
            content: content
        };
        Object.keys(config).forEach(function (key) { return _this.dialogInstance[key] = config[key]; });
        this.dialogInstance.open();
        return new Promise(function (resolve) {
            _this.dialogInstance.confirmEvent.subscribe(function () {
                resolve(_this.dialogInstance);
                _this.dynamicComponentService.dispose();
            });
        });
    };
    DialogService.prototype.createConfirmOverlay = function (content, title) {
        var _this = this;
        var componentRef = this.dynamicComponentService.createDynamicComponent(this.viewContainerRef, ConfirmComponent, '', window.document.body);
        this.dialogInstance = componentRef.instance;
        var config = {
            title: title,
            content: content
        };
        Object.keys(config).forEach(function (key) { return _this.dialogInstance[key] = config[key]; });
        this.dialogInstance.open();
        return new Promise(function (resolve, reject) {
            _this.dialogInstance.confirmEvent.subscribe(function () {
                resolve(_this.dialogInstance);
                _this.dynamicComponentService.dispose();
            });
            _this.dialogInstance.cancelEvent.subscribe(function () {
                reject(_this.dialogInstance);
                _this.dynamicComponentService.dispose();
            });
        });
    };
    DialogService.prototype.info = function (content, title) {
        return this.createOverlay('info', content, title);
    };
    DialogService.prototype.error = function (content, title) {
        return this.createOverlay('error', content, title);
    };
    DialogService.prototype.success = function (content, title) {
        return this.createOverlay('success', content, title);
    };
    DialogService.prototype.confirm = function (content, title) {
        return this.createConfirmOverlay(content, title);
    };
    DialogService.prototype.dispose = function () {
        this.dynamicComponentService.dispose();
    };
    DialogService = tslib_1.__decorate([
        Injectable(),
        tslib_1.__metadata("design:paramtypes", [ViewContainerRef,
            DynamicComponentService])
    ], DialogService);
    return DialogService;
}());
export { DialogService };
//# sourceMappingURL=dialog.service.js.map