import { Component, Input } from '@angular/core';
import { throwError } from 'rxjs';
import { map } from 'rxjs/operators';
import { AlertService } from '../../services/alert/alert.service';
import { CaseNotifier, CasesService } from '../case-editor';
import * as i0 from "@angular/core";
import * as i1 from "../case-editor";
import * as i2 from "../../services/alert/alert.service";
function CaseTimelineComponent_div_0_ng_container_2_ccd_event_log_1_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "ccd-event-log", 4);
    i0.ɵɵlistener("onCaseHistory", function CaseTimelineComponent_div_0_ng_container_2_ccd_event_log_1_Template_ccd_event_log_onCaseHistory_0_listener($event) { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(3); return i0.ɵɵresetView(ctx_r1.caseHistoryClicked($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(3);
    i0.ɵɵproperty("events", ctx_r1.events);
} }
function CaseTimelineComponent_div_0_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, CaseTimelineComponent_div_0_ng_container_2_ccd_event_log_1_Template, 1, 1, "ccd-event-log", 3);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.displayMode === ctx_r1.dspMode.TIMELINE);
} }
function CaseTimelineComponent_div_0_ng_container_3_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "div", 5)(2, "ol", 6)(3, "li", 7)(4, "a", 8);
    i0.ɵɵlistener("click", function CaseTimelineComponent_div_0_ng_container_3_Template_a_click_4_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(2); ctx_r1.goToCaseTimeline(); return i0.ɵɵresetView($event.preventDefault()); });
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "rpxTranslate");
    i0.ɵɵelementEnd()()()();
    i0.ɵɵelement(7, "ccd-case-history", 9);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(6, 2, "Back to case timeline"), " ");
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("event", ctx_r1.selectedEventId);
} }
function CaseTimelineComponent_div_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementContainerStart(1, 1);
    i0.ɵɵtemplate(2, CaseTimelineComponent_div_0_ng_container_2_Template, 2, 1, "ng-container", 2)(3, CaseTimelineComponent_div_0_ng_container_3_Template, 8, 4, "ng-container", 2);
    i0.ɵɵelementContainerEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitch", ctx_r1.displayMode);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", ctx_r1.dspMode.TIMELINE);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngSwitchCase", ctx_r1.dspMode.DETAILS);
} }
export var CaseTimelineDisplayMode;
(function (CaseTimelineDisplayMode) {
    CaseTimelineDisplayMode[CaseTimelineDisplayMode["TIMELINE"] = 0] = "TIMELINE";
    CaseTimelineDisplayMode[CaseTimelineDisplayMode["DETAILS"] = 1] = "DETAILS";
})(CaseTimelineDisplayMode || (CaseTimelineDisplayMode = {}));
export class CaseTimelineComponent {
    caseNotifier;
    casesService;
    alertService;
    case;
    events;
    selectedEventId;
    dspMode = CaseTimelineDisplayMode;
    displayMode = CaseTimelineDisplayMode.TIMELINE;
    constructor(caseNotifier, casesService, alertService) {
        this.caseNotifier = caseNotifier;
        this.casesService = casesService;
        this.alertService = alertService;
    }
    ngOnInit() {
        this.casesService
            .getCaseViewV2(this.case)
            .pipe(map(caseView => {
            this.events = caseView.events;
            this.caseNotifier.announceCase(caseView);
        }))
            .toPromise()
            .catch((error) => {
            this.alertService.error({ phrase: error.message });
            return throwError(error);
        });
    }
    isDataLoaded() {
        return this.events ? true : false;
    }
    caseHistoryClicked(eventId) {
        this.displayMode = CaseTimelineDisplayMode.DETAILS;
        this.selectedEventId = eventId;
    }
    goToCaseTimeline() {
        this.displayMode = CaseTimelineDisplayMode.TIMELINE;
    }
    static ɵfac = function CaseTimelineComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || CaseTimelineComponent)(i0.ɵɵdirectiveInject(i1.CaseNotifier), i0.ɵɵdirectiveInject(i1.CasesService), i0.ɵɵdirectiveInject(i2.AlertService)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: CaseTimelineComponent, selectors: [["ccd-case-timeline"]], inputs: { case: "case" }, decls: 1, vars: 1, consts: [[4, "ngIf"], [3, "ngSwitch"], [4, "ngSwitchCase"], [3, "events", "onCaseHistory", 4, "ngIf"], [3, "onCaseHistory", "events"], [1, "govuk-breadcrumbs"], [1, "govuk-breadcrumbs__list"], [1, "govuk-breadcrumbs__list-item"], ["href", "#", 1, "govuk-back-link", 3, "click"], [3, "event"]], template: function CaseTimelineComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵtemplate(0, CaseTimelineComponent_div_0_Template, 4, 3, "div", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("ngIf", ctx.isDataLoaded());
        } }, encapsulation: 2 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CaseTimelineComponent, [{
        type: Component,
        args: [{ selector: 'ccd-case-timeline', template: "<div *ngIf=\"isDataLoaded()\">\n    <ng-container [ngSwitch]=\"displayMode\">\n        <ng-container *ngSwitchCase=\"dspMode.TIMELINE\">\n            <ccd-event-log [events]=\"events\" (onCaseHistory)=\"caseHistoryClicked($event)\" *ngIf=\"displayMode === dspMode.TIMELINE\">\n            </ccd-event-log>\n        </ng-container>\n        <ng-container *ngSwitchCase=\"dspMode.DETAILS\">\n            <div class=\"govuk-breadcrumbs\">\n                <ol class=\"govuk-breadcrumbs__list\">\n                    <li class=\"govuk-breadcrumbs__list-item\">\n                        <a href=\"#\" (click)=\"goToCaseTimeline(); $event.preventDefault()\" class=\"govuk-back-link\">\n                          {{'Back to case timeline' | rpxTranslate}}\n                        </a>\n                    </li>\n                </ol>\n            </div>\n            <ccd-case-history [event]=\"selectedEventId\"></ccd-case-history>\n        </ng-container>\n    </ng-container>\n</div>\n" }]
    }], () => [{ type: i1.CaseNotifier }, { type: i1.CasesService }, { type: i2.AlertService }], { case: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(CaseTimelineComponent, { className: "CaseTimelineComponent", filePath: "lib/shared/components/case-timeline/case-timeline.component.ts", lineNumber: 17 }); })();
//# sourceMappingURL=data:application/json;base64, 