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);
};
import { HttpClient } from 'aurelia-fetch-client';
import { noView } from 'aurelia-templating';
import { inject } from 'aurelia-dependency-injection';
import { EventAggregator } from 'aurelia-event-aggregator';
import * as nprogress from 'nprogress';
export var LoadingIndicator = (function () {
    function LoadingIndicator(eventAggregator, httpClient) {
        var _this = this;
        nprogress.configure({ showSpinner: false });
        eventAggregator.subscribe('flow:uploading', function (e) { return _this.start(e, false); });
        eventAggregator.subscribe('flow:progress', this.progress);
        eventAggregator.subscribe('flow:complete', this.done);
        var requestFn = function (message) {
            _this.start(null);
            console.log(message);
            return message;
        };
        var responseFn = function (response) {
            _this.done();
            return response;
        };
        httpClient.configure(function (config) {
            config.withInterceptor({
                request: requestFn,
                response: responseFn
            });
        });
    }
    LoadingIndicator.prototype.start = function (e, random) {
        if (random === void 0) { random = true; }
        nprogress.start();
        if (random)
            nprogress.inc();
    };
    LoadingIndicator.prototype.progress = function (progression) {
        nprogress.set(progression);
    };
    LoadingIndicator.prototype.done = function () {
        nprogress.done();
    };
    LoadingIndicator = __decorate([
        noView(['nprogress/nprogress.css']),
        inject(EventAggregator, HttpClient),
        __metadata("design:paramtypes", [EventAggregator, HttpClient])
    ], LoadingIndicator);
    return LoadingIndicator;
}());

//# sourceMappingURL=loading-indicator.js.map
