"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 componentsDefaultTheme_1 = require("../componentsDefaultTheme");
var BusyComponent = (function () {
    function BusyComponent(defaultTheme) {
        this.useDefaultTheme = defaultTheme.useDefaultTheme;
    }
    /*
     * Public API for triggering the rlBusy to wait on a promise
     */
    //*************************************************************************
    // Generic one to be used when you don't know the type
    // defaults to waiting for the first next when using Observable or promise
    //*************************************************************************
    BusyComponent.prototype.waitOn = function (waitOn) {
        //handle if its null
        if (waitOn == null) {
            return rxjs_1.Observable.empty();
        }
        var returnObservable = rxjs_1.Observable.empty();
        //check the type and handle it properly
        switch (typeof waitOn) {
            case 'object':
                returnObservable = this.waitOnObservableCompletion(rxjs_1.Observable.from(waitOn));
                break;
            case 'boolean':
                this.setBusy(waitOn);
                break;
        }
        return returnObservable;
    };
    //**************************************************************
    // used to stop the spinner on every emission through the stream
    //**************************************************************
    BusyComponent.prototype.waitOnObservableNext = function (waitOn) {
        var _this = this;
        this.loading = true;
        return waitOn.do(function () { return _this.loading = false; }, function () { return _this.loading = false; });
    };
    //**************************************************************
    // used to stop the spinner when the stream is completed
    //**************************************************************
    BusyComponent.prototype.waitOnObservableCompletion = function (waitOn) {
        var _this = this;
        this.loading = true;
        return waitOn.do(null, function () { return _this.loading = false; }, function () { return _this.loading = false; });
    };
    //**************************************************************
    // used to force the spinner to stop and start on command
    //**************************************************************
    BusyComponent.prototype.setBusy = function (waitOn) {
        this.loading = waitOn;
    };
    return BusyComponent;
}());
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], BusyComponent.prototype, "loading", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", String)
], BusyComponent.prototype, "size", void 0);
BusyComponent = __decorate([
    core_1.Component({
        selector: 'rlBusy',
        template: require('./busy.html'),
    }),
    __metadata("design:paramtypes", [componentsDefaultTheme_1.DefaultTheme])
], BusyComponent);
exports.BusyComponent = BusyComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVzeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImJ1c3kudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLHNDQUFpRDtBQUVqRCw2QkFBa0M7QUFFbEMsb0VBQXlEO0FBVXpELElBQWEsYUFBYTtJQU16Qix1QkFBWSxZQUEwQjtRQUNyQyxJQUFJLENBQUMsZUFBZSxHQUFHLFlBQVksQ0FBQyxlQUFlLENBQUM7SUFDckQsQ0FBQztJQUVEOztPQUVHO0lBR0gsMkVBQTJFO0lBQzNFLHNEQUFzRDtJQUN0RCwwRUFBMEU7SUFDMUUsMkVBQTJFO0lBQzNFLDhCQUFNLEdBQU4sVUFBVSxNQUE0QztRQUNyRCxvQkFBb0I7UUFDcEIsRUFBRSxDQUFDLENBQUMsTUFBTSxJQUFJLElBQUksQ0FBQyxDQUFDLENBQUM7WUFDcEIsTUFBTSxDQUFDLGlCQUFVLENBQUMsS0FBSyxFQUFLLENBQUM7UUFDOUIsQ0FBQztRQUVELElBQUksZ0JBQWdCLEdBQWtCLGlCQUFVLENBQUMsS0FBSyxFQUFLLENBQUM7UUFFNUQsdUNBQXVDO1FBQ3ZDLE1BQU0sQ0FBQyxDQUFDLE9BQU8sTUFBTSxDQUFDLENBQUMsQ0FBQztZQUN2Q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