"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 router_1 = require("@angular/router");
var rxjs_1 = require("rxjs");
var lodash_1 = require("lodash");
var MultiStepIndicatorComponent = (function () {
    function MultiStepIndicatorComponent(router) {
        this.router = router;
    }
    MultiStepIndicatorComponent.prototype.ngOnInit = function () {
        this.configureSteps();
    };
    MultiStepIndicatorComponent.prototype.onClick = function (step) {
        if (!this.anyLoading()) {
            step.isLoading = true;
            var stream = rxjs_1.Observable.from(step.onClick());
            stream.subscribe({ complete: function () { return step.isLoading = false; } });
            return stream;
        }
        return rxjs_1.Observable.empty();
    };
    MultiStepIndicatorComponent.prototype.anyLoading = function () {
        return lodash_1.some(this.steps, function (step) {
            return step.isLoading;
        });
    };
    MultiStepIndicatorComponent.prototype.configureSteps = function () {
        var _this = this;
        lodash_1.each(this.steps, function (step) {
            step.getCompleted = function () { return _this.getIsCompleted(step); };
            step.getValid = function () { return _this.getIsValid(step); };
            step.isActive = true;
            step.isCurrent = false;
            step.isLoading = false;
            if (!lodash_1.isFunction(step.onClick)) {
                if (step.routerLink) {
                    step.onClick = function () { return _this.redirectToState(step); };
                    if (_this.router.isActive(_this.router.createUrlTree(step.routerLink), false)) {
                        step.isCurrent = true;
                    }
                }
                else {
                    step.isActive = false;
                }
            }
        });
    };
    MultiStepIndicatorComponent.prototype.redirectToState = function (step) {
        var _this = this;
        var stream = rxjs_1.Observable.fromPromise(this.router.navigate(step.routerLink));
        stream.subscribe(function () {
            _this.clearCurrentState();
            step.isCurrent = true;
        });
        return stream.map(function () { return null; });
    };
    MultiStepIndicatorComponent.prototype.clearCurrentState = function () {
        lodash_1.each(this.steps, function (step) {
            step.isCurrent = false;
        });
    };
    MultiStepIndicatorComponent.prototype.getIsCompleted = function (step) {
        return lodash_1.isFunction(step.isCompleted)
            ? step.isCompleted()
            : step.isCompleted;
    };
    MultiStepIndicatorComponent.prototype.setIsCompleted = function (step, isCompleted) {
        if (!lodash_1.isFunction(step.isCompleted)) {
            step.isCompleted = isCompleted;
        }
    };
    MultiStepIndicatorComponent.prototype.getIsValid = function (step) {
        if (lodash_1.isFunction(step.isValid)) {
            return step.isValid();
        }
        else if (!lodash_1.isUndefined(step.isValid != null)) {
            return step.isValid;
        }
        else {
            return true;
        }
    };
    return MultiStepIndicatorComponent;
}());
__decorate([
    core_1.Input(),
    __metadata("design:type", Array)
], MultiStepIndicatorComponent.prototype, "steps", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], MultiStepIndicatorComponent.prototype, "numbered", void 0);
__decorate([
    core_1.Input(),
    __metadata("design:type", Boolean)
], MultiStepIndicatorComponent.prototype, "checked", void 0);
MultiStepIndicatorComponent = __decorate([
    core_1.Component({
        selector: 'rlMultiStepIndicator',
        template: require('./multiStepIndicator.html'),
    }),
    __metadata("design:paramtypes", [router_1.Router])
], MultiStepIndicatorComponent);
exports.MultiStepIndicatorComponent = MultiStepIndicatorComponent;
//# sourceMappingURL=data:application/json;base64, 