"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
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);
};
var core_1 = require("@angular/core");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __notification = typescript_angular_utilities_1.services.notification;
var dialogRoot_service_1 = require("./dialogRoot.service");
var index_1 = require("./templates/index");
var form_1 = require("../form/form");
var async_service_1 = require("../../services/async/async.service");
var form_service_1 = require("../../services/form/form.service");
var DialogComponent = DialogComponent_1 = (function (_super) {
    __extends(DialogComponent, _super);
    function DialogComponent(notification, asyncHelper, formService, dialogRoot, guidService) {
        var _this = _super.call(this, notification, asyncHelper, formService, guidService, null) || this;
        _this.submitAndClose = function () {
            var waitOn = _this.submitAndWait();
            return _this.asyncHelper.waitAsObservable(waitOn).do(function (result) {
                if (result !== false) {
                    _this.close();
                }
            });
        };
        _this.wrapOnClosing = function () {
            if (_this.autosave) {
                if (_this.dirty) {
                    return _this.submit();
                }
                return true;
            }
            else {
                return _this.onClosing
                    ? _this.onClosing()
                    : true;
            }
        };
        _this.dialogRoot = dialogRoot;
        return _this;
    }
    DialogComponent.prototype.open = function () {
        var _this = this;
        this.dialogRoot.openDialog.next({
            onClosing: this.wrapOnClosing,
            header: this.header,
            content: this.content,
            footer: this.footer,
            autosave: this.autosave,
            submitAndClose: function () { return _this.submitAndClose(); },
            size: this.size,
        });
    };
    DialogComponent.prototype.close = function () {
        this.dialogRoot.closeDialog.next(null);
    };
    DialogComponent.prototype.dismiss = function () {
        this.dialogRoot.dismissing = true;
        this.dialogRoot.closeDialog.next(null);
    };
    return DialogComponent;
}(form_1.FormComponent));
__decorate([
    core_1.Input(),
    __metadata("design:type", Function)
], DialogComponent.prototype, "onClosing", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], DialogComponent.prototype, "autosave", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", String)
], DialogComponent.prototype, "size", void 0);
__decorate([
    core_1.ContentChild(index_1.DialogHeaderTemplate),
    __metadata("design:type", index_1.DialogHeaderTemplate)
], DialogComponent.prototype, "header", void 0);
__decorate([
    core_1.ContentChild(index_1.DialogContentTemplate),
    __metadata("design:type", index_1.DialogContentTemplate)
], DialogComponent.prototype, "content", void 0);
__decorate([
    core_1.ContentChild(index_1.DialogFooterTemplate),
    __metadata("design:type", index_1.DialogFooterTemplate)
], DialogComponent.prototype, "footer", void 0);
DialogComponent = DialogComponent_1 = __decorate([
    core_1.Component({
        selector: 'rlDialog',
        template: '',
        inputs: [form_1.baseInputs.save],
        providers: [
            {
                provide: form_1.FormComponent,
                useExisting: core_1.forwardRef(function () { return DialogComponent_1; }),
            },
        ],
    }),
    __metadata("design:paramtypes", [__notification.NotificationService, async_service_1.AsyncHelper,
        form_service_1.FormService,
        dialogRoot_service_1.DialogRootService, typescript_angular_utilities_1.services.guid.GuidService])
], DialogComponent);
exports.DialogComponent = DialogComponent;
var DialogComponent_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlhbG9nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZGlhbG9nLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7OztBQUNBLHNDQUE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