import { Component, EventEmitter, Output } from '@angular/core';
import { LinkedCasesPages } from '../../enums';
import { LinkedCasesService } from '../../services/linked-cases.service';
import { AbstractJourneyComponent } from '../../../base-field';
import { MultipageComponentStateService } from '../../../../../services';
import * as i0 from "@angular/core";
import * as i1 from "../../services/linked-cases.service";
import * as i2 from "../../../../../services";
function CheckYourAnswersComponent_table_4_tr_9_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "tr", 7)(1, "td", 14);
    i0.ɵɵtext(2);
    i0.ɵɵelement(3, "br");
    i0.ɵɵtext(4);
    i0.ɵɵpipe(5, "ccdCaseReference");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(6, "td", 14)(7, "a", 15);
    i0.ɵɵlistener("click", function CheckYourAnswersComponent_table_4_tr_9_Template_a_click_7_listener($event) { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(2); ctx_r1.onChange(); return i0.ɵɵresetView($event.preventDefault()); });
    i0.ɵɵtext(8, "Change");
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const case_r3 = ctx.$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", case_r3.caseName, " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(5, 2, case_r3.caseReference), " ");
} }
function CheckYourAnswersComponent_table_4_tr_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "tr", 7)(1, "td", 16);
    i0.ɵɵtext(2, " None ");
    i0.ɵɵelementEnd()();
} }
function CheckYourAnswersComponent_table_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "table", 13)(1, "caption", 5);
    i0.ɵɵtext(2, "Cases to unlink");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "thead", 6)(4, "tr", 7)(5, "th", 8);
    i0.ɵɵtext(6, "Case name and number");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(7, "th", 8);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(8, "tbody", 10);
    i0.ɵɵtemplate(9, CheckYourAnswersComponent_table_4_tr_9_Template, 9, 4, "tr", 11)(10, CheckYourAnswersComponent_table_4_tr_10_Template, 3, 0, "tr", 12);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(9);
    i0.ɵɵproperty("ngForOf", ctx_r1.casesToUnlink);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", !ctx_r1.casesToUnlink.length);
} }
function CheckYourAnswersComponent_th_15_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "th", 8);
} }
function CheckYourAnswersComponent_tr_17_span_8_span_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "ccdLinkCasesReasonValue");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const reason_r4 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(2, 1, reason_r4), " ");
} }
function CheckYourAnswersComponent_tr_17_span_8_span_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "ccdLinkCasesReasonValue");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const reason_r4 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(2, 1, reason_r4.Reason.value), " ");
} }
function CheckYourAnswersComponent_tr_17_span_8_br_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "br");
} }
function CheckYourAnswersComponent_tr_17_span_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtemplate(1, CheckYourAnswersComponent_tr_17_span_8_span_1_Template, 3, 3, "span", 19)(2, CheckYourAnswersComponent_tr_17_span_8_span_2_Template, 3, 3, "span", 19)(3, CheckYourAnswersComponent_tr_17_span_8_br_3_Template, 1, 0, "br", 19);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const isLast_r5 = ctx.last;
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.isLinkCasesJourney);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", !ctx_r1.isLinkCasesJourney);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", !isLast_r5);
} }
function CheckYourAnswersComponent_tr_17_td_10_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "td", 14)(1, "a", 15);
    i0.ɵɵlistener("click", function CheckYourAnswersComponent_tr_17_td_10_Template_a_click_1_listener($event) { i0.ɵɵrestoreView(_r6); const ctx_r1 = i0.ɵɵnextContext(2); ctx_r1.onChange(); return i0.ɵɵresetView($event.preventDefault()); });
    i0.ɵɵtext(2, "Change");
    i0.ɵɵelementEnd()();
} }
function CheckYourAnswersComponent_tr_17_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "tr", 7)(1, "td", 14)(2, "span");
    i0.ɵɵtext(3);
    i0.ɵɵelement(4, "br");
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "ccdCaseReference");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(7, "td", 14);
    i0.ɵɵtemplate(8, CheckYourAnswersComponent_tr_17_span_8_Template, 4, 3, "span", 17);
    i0.ɵɵelementEnd();
    i0.ɵɵelement(9, "td", 14);
    i0.ɵɵtemplate(10, CheckYourAnswersComponent_tr_17_td_10_Template, 3, 0, "td", 18);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const case_r7 = ctx.$implicit;
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1("", case_r7.caseName, " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(6, 4, case_r7.caseReference), " ");
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("ngForOf", case_r7.reasons);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", ctx_r1.isLinkCasesJourney);
} }
function CheckYourAnswersComponent_tr_18_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "tr", 7)(1, "td", 20);
    i0.ɵɵtext(2, " None ");
    i0.ɵɵelementEnd()();
} }
export class CheckYourAnswersComponent extends AbstractJourneyComponent {
    linkedCasesService;
    linkedCasesStateEmitter = new EventEmitter();
    linkedCases;
    casesToUnlink;
    isLinkCasesJourney;
    linkedCasesTableCaption;
    constructor(linkedCasesService, multipageComponentStateService) {
        super(multipageComponentStateService);
        this.linkedCasesService = linkedCasesService;
    }
    ngOnInit() {
        this.ensureDataIntegrity();
        this.isLinkCasesJourney = this.linkedCasesService.isLinkedCasesEventTrigger;
        this.linkedCasesTableCaption = this.linkedCasesService.isLinkedCasesEventTrigger ? 'Proposed case links' : 'Linked cases';
        this.linkedCases = this.linkedCasesService.linkedCases.filter(linkedCase => !linkedCase.unlink);
        this.casesToUnlink = this.linkedCasesService.linkedCases.filter(linkedCase => linkedCase.unlink && linkedCase.unlink === true);
    }
    ensureDataIntegrity() {
        for (const link in this.linkedCasesService.casesToUnlink) {
            this.linkedCasesService.linkedCases?.forEach((linkedCase) => {
                if (linkedCase?.caseReference === this.linkedCasesService.casesToUnlink[link]) {
                    linkedCase.unlink = true;
                }
            });
        }
    }
    onChange() {
        this.linkedCasesService.editMode = true;
        this.linkedCasesStateEmitter.emit({
            currentLinkedCasesPage: LinkedCasesPages.CHECK_YOUR_ANSWERS,
            navigateToPreviousPage: true,
            navigateToNextPage: true
        });
    }
    next() {
        this.linkedCasesStateEmitter.emit({
            currentLinkedCasesPage: LinkedCasesPages.CHECK_YOUR_ANSWERS,
            navigateToPreviousPage: false,
            navigateToNextPage: true
        });
        super.next();
    }
    static ɵfac = function CheckYourAnswersComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CheckYourAnswersComponent)(i0.ɵɵdirectiveInject(i1.LinkedCasesService), i0.ɵɵdirectiveInject(i2.MultipageComponentStateService)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CheckYourAnswersComponent, selectors: [["ccd-linked-cases-check-your-answers"]], outputs: { linkedCasesStateEmitter: "linkedCasesStateEmitter" }, features: [i0.ɵɵInheritDefinitionFeature], decls: 19, vars: 5, consts: [[1, "govuk-grid-row"], [1, "govuk-grid-column-full"], [1, "govuk-heading-xl"], ["id", "cases-to-unlink-table", "class", "govuk-table", 4, "ngIf"], ["id", "linked-cases-table", 1, "govuk-table"], [1, "govuk-table__caption", "govuk-table__caption--m"], [1, "govuk-table__head"], [1, "govuk-table__row"], ["scope", "col", 1, "govuk-table__header"], ["scope", "col", "class", "govuk-table__header", 4, "ngIf"], [1, "govuk-table__body"], ["class", "govuk-table__row", 4, "ngFor", "ngForOf"], ["class", "govuk-table__row", 4, "ngIf"], ["id", "cases-to-unlink-table", 1, "govuk-table"], [1, "govuk-table__cell"], ["href", "#", 1, "govuk-link", "govuk-link--no-visited-state", "float-right", 3, "click"], ["colspan", "2", 1, "govuk-table__cell"], [4, "ngFor", "ngForOf"], ["class", "govuk-table__cell", 4, "ngIf"], [4, "ngIf"], ["colspan", "4", 1, "govuk-table__cell"]], template: function CheckYourAnswersComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "h1", 2);
            i0.ɵɵtext(3, "Check your answers");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(4, CheckYourAnswersComponent_table_4_Template, 11, 2, "table", 3);
            i0.ɵɵelementStart(5, "table", 4)(6, "caption", 5);
            i0.ɵɵtext(7);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(8, "thead", 6)(9, "tr", 7)(10, "th", 8);
            i0.ɵɵtext(11, "Case name and number");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(12, "th", 8);
            i0.ɵɵtext(13, "Reasons for case link");
            i0.ɵɵelementEnd();
            i0.ɵɵelement(14, "td", 8);
            i0.ɵɵtemplate(15, CheckYourAnswersComponent_th_15_Template, 1, 0, "th", 9);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(16, "tbody", 10);
            i0.ɵɵtemplate(17, CheckYourAnswersComponent_tr_17_Template, 11, 6, "tr", 11)(18, CheckYourAnswersComponent_tr_18_Template, 3, 0, "tr", 12);
            i0.ɵɵelementEnd()()()();
        } if (rf & 2) {
            i0.ɵɵadvance(4);
            i0.ɵɵproperty("ngIf", !ctx.isLinkCasesJourney);
            i0.ɵɵadvance(3);
            i0.ɵɵtextInterpolate(ctx.linkedCasesTableCaption);
            i0.ɵɵadvance(8);
            i0.ɵɵproperty("ngIf", ctx.isLinkCasesJourney);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngForOf", ctx.linkedCases);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", !ctx.linkedCases.length);
        } }, styles: [".float-right[_ngcontent-%COMP%]{float:right}"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CheckYourAnswersComponent, [{
        type: Component,
        args: [{ selector: 'ccd-linked-cases-check-your-answers', template: "<div class=\"govuk-grid-row\">\n  <div class=\"govuk-grid-column-full\">\n    <h1 class=\"govuk-heading-xl\">Check your answers</h1>\n    <!-- Top table for manage link cases journey -->\n    <table id=\"cases-to-unlink-table\" class=\"govuk-table\" *ngIf=\"!isLinkCasesJourney\">\n      <caption class=\"govuk-table__caption govuk-table__caption--m\">Cases to unlink</caption>\n      <thead class=\"govuk-table__head\">\n        <tr class=\"govuk-table__row\">\n          <th scope=\"col\" class=\"govuk-table__header\">Case name and number</th>\n          <th scope=\"col\" class=\"govuk-table__header\"></th>\n        </tr>\n      </thead>\n      <tbody class=\"govuk-table__body\">\n        <tr class=\"govuk-table__row\" *ngFor=\"let case of casesToUnlink\">\n          <td class=\"govuk-table__cell\">\n            {{case.caseName}}  <br> {{case.caseReference | ccdCaseReference}}\n          </td>\n          <td class=\"govuk-table__cell\">\n            <a href=\"#\" class=\"govuk-link govuk-link--no-visited-state float-right\" (click)=\"onChange(); $event.preventDefault()\">Change</a>\n          </td>\n        </tr>\n        <tr class=\"govuk-table__row\" *ngIf=\"!casesToUnlink.length\">\n          <td class=\"govuk-table__cell\" colspan=\"2\">\n            None\n          </td>\n        </tr>\n      </tbody>\n    </table>\n    <!-- Table for both link case and manage link case journeys -->\n    <table id=\"linked-cases-table\" class=\"govuk-table\">\n      <caption class=\"govuk-table__caption govuk-table__caption--m\">{{linkedCasesTableCaption}}</caption>\n      <thead class=\"govuk-table__head\">\n        <tr class=\"govuk-table__row\">\n          <th scope=\"col\" class=\"govuk-table__header\">Case name and number</th>\n          <th scope=\"col\" class=\"govuk-table__header\">Reasons for case link</th>\n          <td scope=\"col\" class=\"govuk-table__header\"></td>\n          <th scope=\"col\" class=\"govuk-table__header\" *ngIf=\"isLinkCasesJourney\"></th>\n        </tr>\n      </thead>\n      <tbody class=\"govuk-table__body\">\n        <tr class=\"govuk-table__row\" *ngFor=\"let case of linkedCases\">\n          <td class=\"govuk-table__cell\">\n            <span>{{case.caseName}}  <br> {{case.caseReference | ccdCaseReference}} </span>\n          </td>\n          <td class=\"govuk-table__cell\">\n            <span *ngFor=\"let reason of case.reasons; last as isLast\">\n              <span *ngIf=\"isLinkCasesJourney\">\n                {{reason | ccdLinkCasesReasonValue}}\n              </span>\n              <span *ngIf=\"!isLinkCasesJourney\">\n                {{reason.Reason.value | ccdLinkCasesReasonValue}}\n              </span>\n              <br *ngIf=\"!isLast\">\n            </span>\n          </td>\n          <td class=\"govuk-table__cell\"></td>\n          <td class=\"govuk-table__cell\" *ngIf=\"isLinkCasesJourney\">\n            <a href=\"#\" class=\"govuk-link govuk-link--no-visited-state float-right\" (click)=\"onChange(); $event.preventDefault()\">Change</a>\n          </td>\n        </tr>\n        <tr class=\"govuk-table__row\" *ngIf=\"!linkedCases.length\">\n          <td class=\"govuk-table__cell\" colspan=\"4\">\n            None\n          </td>\n        </tr>\n      </tbody>\n    </table>\n  </div>\n</div>\n", styles: [".float-right{float:right}\n"] }]
    }], () => [{ type: i1.LinkedCasesService }, { type: i2.MultipageComponentStateService }], { linkedCasesStateEmitter: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CheckYourAnswersComponent, { className: "CheckYourAnswersComponent", filePath: "lib/shared/components/palette/linked-cases/components/check-your-answers/check-your-answers.component.ts", lineNumber: 14 }); })();
//# sourceMappingURL=data:application/json;base64, 