"use strict";
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 rxjs_1 = require("rxjs");
var rl_http_1 = require("rl-http");
var busy_1 = require("../../source/components/busy/busy");
var form_1 = require("../../source/components/form/form");
var autosaveAction_service_1 = require("../../source/services/autosaveAction/autosaveAction.service");
var FormsBootstrapper = (function () {
    function FormsBootstrapper(autosaveAction, http) {
        var _this = this;
        this.waitCallback = function (data) {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    console.log(data);
                    resolve();
                }, 1000);
            });
        };
        this.saveRequest = function (data) {
            var request = _this.http.post('http://localhost:8000/test', data).delay(1000);
            _this.testBusy.waitOn(request).subscribe(function (response) { return console.log(response); });
        };
        this.saveTestForm = function (data) {
            if (_this.testForm.form.dirty) {
                return _this.waitCallback(data);
            }
            return false;
        };
        this.autosaveAction = autosaveAction;
        this.http = http;
        this.rating$ = new rxjs_1.BehaviorSubject(null);
        this.validator = {
            validate: function () { return _this.rating$.map(function (rating) { return rating >= 3 ? null : 'You must give at least 3 stars'; }); },
        };
        this.brokenValidator = {
            validate: function () { return rxjs_1.Observable.of('error'); },
        };
    }
    FormsBootstrapper.prototype.setRating = function (rating) {
        this.rating = rating;
        this.rating$.next(rating);
    };
    return FormsBootstrapper;
}());
__decorate([
    core_1.ViewChild('testForm'),
    __metadata("design:type", form_1.FormComponent)
], FormsBootstrapper.prototype, "testForm", void 0);
__decorate([
    core_1.ViewChild('testBusy'),
    __metadata("design:type", busy_1.BusyComponent)
], FormsBootstrapper.prototype, "testBusy", void 0);
FormsBootstrapper = __decorate([
    core_1.Component({
        selector: 'tsFormsBootstrapper',
        template: require('./formsNg2.html'),
    }),
    __metadata("design:paramtypes", [autosaveAction_service_1.AutosaveActionService,
        rl_http_1.HttpUtility])
], FormsBootstrapper);
exports.FormsBootstrapper = FormsBootstrapper;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybXNOZzJCb290c3RyYXBwZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJmb3Jtc05nMkJvb3RzdHJhcHBlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsc0NBQXFEO0FBQ3JELDZCQUFtRDtBQUNuRCxtQ0FBc0M7QUFFdEMsMERBQWtFO0FBQ2xFLDBEQUFrRTtBQUNsRSxzR0FBb0c7QUFNcEcsSUFBYSxpQkFBaUI7SUFhN0IsMkJBQVksY0FBcUMsRUFDN0MsSUFBaUI7UUFEckIsaUJBYUM7UUFPRCxpQkFBWSxHQUFtQyxVQUFDLElBQVM7WUFDeEQsTUFBTSxDQUFDLElBQUksT0FBTyxDQUFPLFVBQUMsT0FBaUIsRUFBRSxNQUFnQjtnQkFDNUQsVUFBVSxDQUFDO29CQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUM7b0JBQ2xCLE9BQU8sRUFBRSxDQUFDO2dCQUNYLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQztZQUNWLENBQUMsQ0FBQyxDQUFDO1FBQ0osQ0FBQyxDQUFBO1FBRUQsZ0JBQVcsR0FBRyxVQUFBLElBQUk7WUFDakIsSUFBTSxPQUFPLEdBQUcsS0FBSSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsNEJBQTRCLEVBQUUsSUFBSSxDQUFDLENBQUMsS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