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 { Component, Input } from '@angular/core';
import { AlertService } from '../../../services/alert';
import { CaseView, Draft } from '../../../domain';
import { CaseService, CasesService } from '../../case-editor';
import { DraftService } from '../../../services';
import { throwError } from 'rxjs';
import { map } from 'rxjs/operators';
import { plainToClassFromExist } from 'class-transformer';
var CaseViewComponent = /** @class */ (function () {
    function CaseViewComponent(caseService, casesService, draftService, alertService) {
        this.caseService = caseService;
        this.casesService = casesService;
        this.draftService = draftService;
        this.alertService = alertService;
        this.hasPrint = true;
        this.hasEventSelector = true;
    }
    CaseViewComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.getCaseView(this.case)
            .pipe(map(function (caseView) {
            _this.caseDetails = plainToClassFromExist(new CaseView(), caseView);
            _this.caseService.announceCase(_this.caseDetails);
        }))
            .toPromise()
            .catch(function (error) { return _this.checkAuthorizationError(error); });
    };
    CaseViewComponent.prototype.isDataLoaded = function () {
        return this.caseDetails ? true : false;
    };
    CaseViewComponent.prototype.getCaseView = function (cid) {
        if (Draft.isDraft(cid)) {
            return this.getDraft(cid);
        }
        else {
            return this.casesService
                .getCaseView(cid);
        }
    };
    CaseViewComponent.prototype.getDraft = function (cid) {
        return this.draftService
            .getDraft(cid);
    };
    CaseViewComponent.prototype.checkAuthorizationError = function (error) {
        // TODO Should be logged to remote logging infrastructure
        console.error(error);
        if (error.status !== 401 && error.status !== 403) {
            this.alertService.error(error.message);
        }
        return throwError(error);
    };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], CaseViewComponent.prototype, "case", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], CaseViewComponent.prototype, "hasPrint", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], CaseViewComponent.prototype, "hasEventSelector", void 0);
    CaseViewComponent = __decorate([
        Component({
            selector: 'ccd-case-view',
            template: "\n    <div *ngIf=\"isDataLoaded()\">\n        <ccd-case-viewer [hasPrint]=\"hasPrint\"\n                         [hasEventSelector]=\"hasEventSelector\"></ccd-case-viewer>\n    </div>\n  "
        }),
        __metadata("design:paramtypes", [CaseService,
            CasesService,
            DraftService,
            AlertService])
    ], CaseViewComponent);
    return CaseViewComponent;
}());
export { CaseViewComponent };
//# sourceMappingURL=case-view.component.js.map