import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Router } from '@angular/router';
import { FieldsUtils } from '../../../services/fields/fields.utils';
import { CaseEditComponent } from '../case-edit/case-edit.component';
import * as i0 from "@angular/core";
import * as i1 from "../case-edit/case-edit.component";
import * as i2 from "@angular/router";
function CaseEditConfirmComponent_div_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div");
} }
function CaseEditConfirmComponent_ng_template_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "ccd-markdown", 8);
    i0.ɵɵpipe(1, "ccdCaseTitle");
    i0.ɵɵpipe(2, "rpxTranslate");
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("content", i0.ɵɵpipeBind1(2, 5, i0.ɵɵpipeBind3(1, 1, ctx_r1.getCaseTitle(), ctx_r1.caseFields, ctx_r1.editForm.controls["data"])));
} }
function CaseEditConfirmComponent_ng_template_6_h2_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "h2", 10);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "ccdCaseReference");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1("#", i0.ɵɵpipeBind1(2, 1, ctx_r1.getCaseId()), "");
} }
function CaseEditConfirmComponent_ng_template_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtemplate(0, CaseEditConfirmComponent_ng_template_6_h2_0_Template, 3, 3, "h2", 9);
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngIf", ctx_r1.getCaseId());
} }
function CaseEditConfirmComponent_div_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 11);
    i0.ɵɵelement(1, "ccd-markdown", 8);
    i0.ɵɵpipe(2, "rpxTranslate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵproperty("content", i0.ɵɵpipeBind1(2, 1, ctx_r1.confirmation.getHeader()));
} }
function CaseEditConfirmComponent_div_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 12);
    i0.ɵɵelement(1, "ccd-markdown", 8);
    i0.ɵɵpipe(2, "rpxTranslate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵproperty("content", i0.ɵɵpipeBind1(2, 1, ctx_r1.confirmation.getBody()));
} }
export class CaseEditConfirmComponent {
    caseEdit;
    router;
    eventTrigger;
    triggerText = 'Close and Return to case details';
    formGroup = new FormControl();
    confirmation;
    caseFields;
    editForm;
    constructor(caseEdit, router) {
        this.caseEdit = caseEdit;
        this.router = router;
        this.eventTrigger = this.caseEdit.eventTrigger;
        this.editForm = this.caseEdit.form;
        this.caseFields = this.getCaseFields();
        if (this.caseEdit.confirmation) {
            this.confirmation = this.caseEdit.confirmation;
        }
        else {
            this.router.navigate(['/']);
        }
    }
    submit() {
        this.caseEdit.submitted.emit({ caseId: this.confirmation.getCaseId(), status: this.confirmation.getStatus() });
    }
    getCaseId() {
        return this.caseEdit?.caseDetails?.case_id || '';
    }
    getCaseTitle() {
        return (this.caseEdit.caseDetails && this.caseEdit.caseDetails.state &&
            this.caseEdit.caseDetails.state.title_display ? this.caseEdit.caseDetails.state.title_display : '');
    }
    getCaseFields() {
        if (this.caseEdit.caseDetails) {
            return FieldsUtils.getCaseFields(this.caseEdit.caseDetails);
        }
        return this.eventTrigger.case_fields;
    }
    static ɵfac = function CaseEditConfirmComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CaseEditConfirmComponent)(i0.ɵɵdirectiveInject(i1.CaseEditComponent), i0.ɵɵdirectiveInject(i2.Router)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CaseEditConfirmComponent, selectors: [["ng-component"]], decls: 14, vars: 12, consts: [["titleBlock", ""], ["idBlock", ""], [1, "heading-h1"], [4, "ngIf", "ngIfThen", "ngIfElse"], [3, "submit", "formGroup"], ["id", "confirmation-header", 4, "ngIf"], ["id", "confirmation-body", 4, "ngIf"], ["type", "submit", "data-ng-click", "submit()", 1, "button"], [3, "content"], ["class", "heading-h2", 4, "ngIf"], [1, "heading-h2"], ["id", "confirmation-header"], ["id", "confirmation-body"]], template: function CaseEditConfirmComponent_Template(rf, ctx) { if (rf & 1) {
            const _r1 = i0.ɵɵgetCurrentView();
            i0.ɵɵelementStart(0, "h1", 2);
            i0.ɵɵtext(1);
            i0.ɵɵpipe(2, "rpxTranslate");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(3, CaseEditConfirmComponent_div_3_Template, 1, 0, "div", 3)(4, CaseEditConfirmComponent_ng_template_4_Template, 3, 7, "ng-template", null, 0, i0.ɵɵtemplateRefExtractor)(6, CaseEditConfirmComponent_ng_template_6_Template, 1, 1, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor);
            i0.ɵɵelementStart(8, "form", 4);
            i0.ɵɵlistener("submit", function CaseEditConfirmComponent_Template_form_submit_8_listener() { i0.ɵɵrestoreView(_r1); return i0.ɵɵresetView(ctx.submit()); });
            i0.ɵɵtemplate(9, CaseEditConfirmComponent_div_9_Template, 3, 3, "div", 5)(10, CaseEditConfirmComponent_div_10_Template, 3, 3, "div", 6);
            i0.ɵɵelementStart(11, "button", 7);
            i0.ɵɵtext(12);
            i0.ɵɵpipe(13, "rpxTranslate");
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            const titleBlock_r3 = i0.ɵɵreference(5);
            const idBlock_r4 = i0.ɵɵreference(7);
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 8, ctx.eventTrigger.name));
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngIf", ctx.getCaseTitle())("ngIfThen", titleBlock_r3)("ngIfElse", idBlock_r4);
            i0.ɵɵadvance(5);
            i0.ɵɵproperty("formGroup", ctx.formGroup);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.confirmation.getHeader());
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.confirmation.getBody());
            i0.ɵɵadvance(2);
            i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(13, 10, ctx.triggerText));
        } }, styles: ["#fieldset-case-data[_ngcontent-%COMP%]{margin-bottom:30px}#fieldset-case-data[_ngcontent-%COMP%]   th[_ngcontent-%COMP%]{width:1%;white-space:nowrap;vertical-align:top}.compound-field[_ngcontent-%COMP%]   td[_ngcontent-%COMP%]{padding:0}#confirmation-header[_ngcontent-%COMP%]{width:630px;background-color:#17958b;border:solid 1px #979797;color:#fff;text-align:center}#confirmation-body[_ngcontent-%COMP%]{width:630px;background-color:#fff}.valign-top[_ngcontent-%COMP%]{vertical-align:top}.summary-fields[_ngcontent-%COMP%]{margin-bottom:30px}.summary-fields[_ngcontent-%COMP%]   tbody[_ngcontent-%COMP%]   tr[_ngcontent-%COMP%]   th[_ngcontent-%COMP%], .summary-fields[_ngcontent-%COMP%]   tbody[_ngcontent-%COMP%]   tr[_ngcontent-%COMP%]   td[_ngcontent-%COMP%]{border-bottom:0px}a.disabled[_ngcontent-%COMP%]{pointer-events:none;cursor:default}.case-field-label[_ngcontent-%COMP%]{width:45%}.case-field-content[_ngcontent-%COMP%]{width:50%}.no-bottom-border[_ngcontent-%COMP%]{border-bottom:none}.case-field-change[_ngcontent-%COMP%]{width:5%}"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CaseEditConfirmComponent, [{
        type: Component,
        args: [{ template: "<!-- Current Page && Event trigger name -->\n<h1 class=\"heading-h1\">{{ eventTrigger.name | rpxTranslate}}</h1>\n\n<!--Case ID or Title -->\n<div *ngIf=\"getCaseTitle(); then titleBlock; else idBlock\"></div>\n<ng-template #titleBlock>\n  <ccd-markdown [content]=\"getCaseTitle() | ccdCaseTitle: caseFields : editForm.controls['data'] | rpxTranslate\"></ccd-markdown>\n</ng-template>\n<ng-template #idBlock>\n  <h2 *ngIf=\"getCaseId()\" class=\"heading-h2\">#{{ getCaseId() | ccdCaseReference }}</h2>\n</ng-template>\n\n<form [formGroup]=\"formGroup\" (submit)=\"submit()\">\n  <div id=\"confirmation-header\" *ngIf=\"confirmation.getHeader()\">\n    <ccd-markdown [content]=\"confirmation.getHeader() | rpxTranslate\"></ccd-markdown>\n  </div>\n  <div id=\"confirmation-body\" *ngIf=\"confirmation.getBody()\">\n    <ccd-markdown [content]=\"confirmation.getBody() | rpxTranslate\"></ccd-markdown>\n  </div>\n  <button type=\"submit\" class=\"button\" data-ng-click=\"submit()\">{{triggerText | rpxTranslate}}</button>\n</form>\n", styles: ["#fieldset-case-data{margin-bottom:30px}#fieldset-case-data th{width:1%;white-space:nowrap;vertical-align:top}.compound-field td{padding:0}#confirmation-header{width:630px;background-color:#17958b;border:solid 1px #979797;color:#fff;text-align:center}#confirmation-body{width:630px;background-color:#fff}.valign-top{vertical-align:top}.summary-fields{margin-bottom:30px}.summary-fields tbody tr th,.summary-fields tbody tr td{border-bottom:0px}a.disabled{pointer-events:none;cursor:default}.case-field-label{width:45%}.case-field-content{width:50%}.no-bottom-border{border-bottom:none}.case-field-change{width:5%}\n"] }]
    }], () => [{ type: i1.CaseEditComponent }, { type: i2.Router }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CaseEditConfirmComponent, { className: "CaseEditConfirmComponent", filePath: "lib/shared/components/case-editor/case-edit-confirm/case-edit-confirm.component.ts", lineNumber: 15 }); })();
//# sourceMappingURL=data:application/json;base64, 