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, EventEmitter, Input, Output } from '@angular/core';
import { throwError } from 'rxjs';
import { CasesService } from '../services/cases.service';
import { AlertService } from '../../../services/alert';
import { DraftService } from '../../../services/draft/draft.service';
import { EventTriggerService } from '../services/event-trigger.service';
var CaseCreateComponent = /** @class */ (function () {
    function CaseCreateComponent(casesService, alertService, draftService, eventTriggerService) {
        this.casesService = casesService;
        this.alertService = alertService;
        this.draftService = draftService;
        this.eventTriggerService = eventTriggerService;
        this.cancelled = new EventEmitter();
        this.submitted = new EventEmitter();
    }
    CaseCreateComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.casesService.getEventTrigger(this.caseType, this.event).toPromise()
            .then(function (eventTrigger) {
            _this.eventTrigger = eventTrigger;
            _this.eventTriggerService.announceEventTrigger(eventTrigger);
        })
            .catch(function (error) {
            _this.alertService.error(error.message);
            return throwError(error);
        });
    };
    CaseCreateComponent.prototype.submit = function () {
        var _this = this;
        return function (sanitizedEditForm) {
            sanitizedEditForm.draft_id = _this.eventTrigger.case_id;
            return _this.casesService.createCase(_this.caseType, sanitizedEditForm);
        };
    };
    CaseCreateComponent.prototype.validate = function () {
        var _this = this;
        return function (sanitizedEditForm, pageId) { return _this.casesService
            .validateCase(_this.caseType, sanitizedEditForm, pageId); };
    };
    CaseCreateComponent.prototype.saveDraft = function () {
        var _this = this;
        if (this.eventTrigger.can_save_draft) {
            return function (caseEventData) { return _this.draftService.createOrUpdateDraft(_this.caseType, _this.eventTrigger.case_id, caseEventData); };
        }
    };
    CaseCreateComponent.prototype.emitCancelled = function (event) {
        this.cancelled.emit(event);
    };
    CaseCreateComponent.prototype.emitSubmitted = function (event) {
        this.submitted.emit(event);
    };
    CaseCreateComponent.prototype.isDataLoaded = function () {
        return this.eventTrigger ? true : false;
    };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], CaseCreateComponent.prototype, "jurisdiction", void 0);
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], CaseCreateComponent.prototype, "caseType", void 0);
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], CaseCreateComponent.prototype, "event", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], CaseCreateComponent.prototype, "cancelled", void 0);
    __decorate([
        Output(),
        __metadata("design:type", EventEmitter)
    ], CaseCreateComponent.prototype, "submitted", void 0);
    CaseCreateComponent = __decorate([
        Component({
            selector: 'ccd-case-create',
            template: "\n    <div *ngIf=\"isDataLoaded()\">\n        <ccd-case-edit [submit]=\"submit()\"\n                       [validate]=\"validate()\"\n                       [saveDraft]=\"saveDraft()\"\n                       [eventTrigger]=\"eventTrigger\"\n                       (cancelled)=\"emitCancelled($event)\"\n                       (submitted)=\"emitSubmitted($event)\"></ccd-case-edit>\n    </div>\n  "
        }),
        __metadata("design:paramtypes", [CasesService,
            AlertService,
            DraftService,
            EventTriggerService])
    ], CaseCreateComponent);
    return CaseCreateComponent;
}());
export { CaseCreateComponent };
//# sourceMappingURL=case-create.component.js.map