"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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
var wjcViewer = require("wijmo/wijmo.viewer");
// Angular
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var platform_browser_dynamic_1 = require("@angular/platform-browser-dynamic");
var http_1 = require("@angular/common/http");
var platform_browser_1 = require("@angular/platform-browser");
var wijmo_angular2_viewer_1 = require("wijmo/wijmo.angular2.viewer");
'use strict';
// The application root component.
var AppCmp = /** @class */ (function () {
    function AppCmp(http) {
        var _this = this;
        this._arReportInfo = '';
        this._flexReportInfo = '';
        this._ssrsReportInfo = '';
        this._arServiceUrl = 'http://ardemos.grapecity.com/AR12-ReportsGallery/ActiveReports.ReportService.asmx';
        this._c1WebApiServiceUrl = 'http://demos.componentone.com/ASPNET/c1webapi/4.0.20172.105/api/report';
        // Loading ActiveReports reports.
        http.get("arReport.config.json").subscribe(function (res) {
            var arReports = res;
            _this.arItems = arReports.categories;
            _this.arReportInfo = _this._getSelectedArReport(arReports);
        });
        // Loading FlexReport reports.
        http.get("flexReport.config.json").subscribe(function (res) {
            _this.flexItems = res.categories;
        });
        // Loading SSRS reports.
        http.get("ssrsReport.config.json").subscribe(function (res) {
            _this.ssrsItems = res.categories;
        });
    }
    AppCmp_1 = AppCmp;
    AppCmp.prototype.ngAfterViewInit = function () {
        var _this = this;
        var resize = function () {
            if (_this.reportViewer) {
                _this.reportViewer.hostElement.style.height = (Math.max(window.innerHeight * 0.95, 300)) + 'px';
            }
        };
        resize();
        window.addEventListener('resize', resize);
    };
    Object.defineProperty(AppCmp.prototype, "arReportInfo", {
        get: function () {
            return this._arReportInfo;
        },
        set: function (value) {
            if (this._arReportInfo !== value) {
                this._loadArReport(this._arReportInfo = value);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AppCmp.prototype, "flexReportInfo", {
        get: function () {
            return this._flexReportInfo;
        },
        set: function (value) {
            if (this._flexReportInfo !== value) {
                this._loadFlexReport(this._flexReportInfo = value);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AppCmp.prototype, "ssrsReportInfo", {
        get: function () {
            return this._ssrsReportInfo;
        },
        set: function (value) {
            if (this._ssrsReportInfo != value) {
                this._loadSsrsReport(this._ssrsReportInfo = value);
            }
        },
        enumerable: true,
        configurable: true
    });
    AppCmp.prototype._getSelectedArReport = function (json) {
        var res = null;
        for (var i = 0; i < json.categories.length && !res; i++) {
            var category = json.categories[i];
            for (var j = 0; j < category.reports.length && !res; j++) {
                var report = category.reports[j];
                if (category.name === json.selectedReport.categoryName && report.reportName === json.selectedReport.reportName) {
                    res = report.fileName;
                }
            }
        }
        return res;
    };
    AppCmp.prototype._getSelectedFlexReport = function (flexReports) {
        var selectedReport = flexReports.selectedReport, selectedCategoryName = selectedReport.categoryName, selectedReportName = selectedReport.reportName;
        return 'ReportsRoot/' + selectedCategoryName + '/' + selectedReportName + '.flxr' + '*' + selectedReportName;
    };
    AppCmp.prototype._loadArReport = function (info) {
        if (this.reportViewer && info && info !== AppCmp_1.None) {
            this.flexReportInfo = AppCmp_1.None;
            this.ssrsReportInfo = AppCmp_1.None;
            this.filePath = info;
            this.reportName = '';
            this.serviceUrl = this._arServiceUrl;
            this.paginated = false;
        }
    };
    AppCmp.prototype._loadFlexReport = function (info) {
        if (this.reportViewer && info && info !== AppCmp_1.None) {
            this.arReportInfo = AppCmp_1.None;
            this.ssrsReportInfo = AppCmp_1.None;
            var reportInfo = info.split('*');
            this.filePath = reportInfo[0];
            this.reportName = reportInfo[1];
            this.serviceUrl = this._c1WebApiServiceUrl;
            this.paginated = true;
        }
    };
    AppCmp.prototype._loadSsrsReport = function (info) {
        if (this.reportViewer && info && info !== AppCmp_1.None) {
            this.arReportInfo = AppCmp_1.None;
            this.flexReportInfo = AppCmp_1.None;
            this.filePath = info;
            this.reportName = '';
            this.serviceUrl = this._c1WebApiServiceUrl;
            this.paginated = false;
        }
    };
    AppCmp.None = 'None';
    __decorate([
        core_1.ViewChild('reportViewer'),
        __metadata("design:type", wjcViewer.ReportViewer)
    ], AppCmp.prototype, "reportViewer", void 0);
    AppCmp = AppCmp_1 = __decorate([
        core_1.Component({
            selector: 'app-cmp',
            templateUrl: 'src/app.html'
        }),
        __param(0, core_1.Inject(http_1.HttpClient)),
        __metadata("design:paramtypes", [http_1.HttpClient])
    ], AppCmp);
    return AppCmp;
    var AppCmp_1;
}());
exports.AppCmp = AppCmp;
var AppModule = /** @class */ (function () {
    function AppModule() {
    }
    AppModule = __decorate([
        core_1.NgModule({
            imports: [wijmo_angular2_viewer_1.WjViewerModule, platform_browser_1.BrowserModule, forms_1.FormsModule, http_1.HttpClientModule],
            declarations: [AppCmp],
            bootstrap: [AppCmp]
        })
    ], AppModule);
    return AppModule;
}());
exports.AppModule = AppModule;
core_1.enableProdMode();
// Bootstrap application with hash style navigation and global services.
platform_browser_dynamic_1.platformBrowserDynamic().bootstrapModule(AppModule);
//# sourceMappingURL=app.js.map