/**** Import should have relative path in common lib ****/
import { Component, HostListener, Input, ViewEncapsulation } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';
import { ScreenType } from '../enlighten-lib/filters/condition-type';
import { DrillThroughService } from './drill-through.service';
import { EnlightenReportType } from '../enlighten-lib/report/ireport';
import * as i0 from "@angular/core";
import * as i1 from "./drill-through.service";
import * as i2 from "@angular/router";
import * as i3 from "@angular/common";
import * as i4 from "../enlighten-lib/report/graphical-report/graphical-report.component";
import * as i5 from "../enlighten-lib/report/tabular-report/tabular-report.component";
function DrillThroughComponent_graphical_report_2_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "graphical-report", 4);
    i0.ɵɵlistener("nextPageClicked", function DrillThroughComponent_graphical_report_2_Template_graphical_report_nextPageClicked_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r2 = i0.ɵɵnextContext(); return ctx_r2.nextPage(); })("previousPageClicked", function DrillThroughComponent_graphical_report_2_Template_graphical_report_previousPageClicked_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r4 = i0.ɵɵnextContext(); return ctx_r4.previousPage(); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("page", ctx_r0.page)("drillThroughFilterInput", ctx_r0.filter)("screenType", ctx_r0.screenTypes.drillThrough)("drillThroughParentType", ctx_r0.drillThroughParentType)("hasNextPage", ctx_r0.hasNextPage)("appVersionId", ctx_r0.appVersionId);
} }
function DrillThroughComponent_tabular_report_3_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "tabular-report", 5);
    i0.ɵɵlistener("nextPageClicked", function DrillThroughComponent_tabular_report_3_Template_tabular_report_nextPageClicked_0_listener() { i0.ɵɵrestoreView(_r6); const ctx_r5 = i0.ɵɵnextContext(); return ctx_r5.nextPage(); })("previousPageClicked", function DrillThroughComponent_tabular_report_3_Template_tabular_report_previousPageClicked_0_listener() { i0.ɵɵrestoreView(_r6); const ctx_r7 = i0.ɵɵnextContext(); return ctx_r7.previousPage(); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("page", ctx_r1.page)("drillThroughFilterInput", ctx_r1.filter)("screenType", ctx_r1.screenTypes.drillThrough)("drillThroughParentType", ctx_r1.drillThroughParentType)("hasNextPage", ctx_r1.hasNextPage)("appVersionId", ctx_r1.appVersionId);
} }
const _c0 = function (a0, a1) { return { "graphical-drill-parent": a0, "h-full": a1 }; };
export class DrillThroughComponent {
    /**
     * Constructor
     * Inject all required services here.
     */
    constructor(_drillThroughService, _router) {
        this._drillThroughService = _drillThroughService;
        this._router = _router;
        /*
        * Subject object which helps unsubscribe all the subscribed objects in the component
        */
        this._unsubscribeAll = new Subject();
    }
    get screenTypes() {
        return ScreenType;
    }
    get enlightenReportTypes() {
        return EnlightenReportType;
    }
    beforeUnload(event) {
        this._drillThroughService.saveStates();
    }
    /**
     * OnInit life cycle hook ..
     */
    ngOnInit() {
        this.setDrillThrough();
        this.subscribers();
    }
    ngOnDestroy() {
        this._drillThroughService.destroy();
    }
    /**
     * Subscribers should be written here.
     */
    subscribers() {
        this._drillThroughService.onPageChanged
            .pipe(takeUntil(this._unsubscribeAll))
            .subscribe((event) => {
            if (event) {
                this.setDrillThrough();
            }
        });
        this._router.events
            .pipe(filter((rs) => rs instanceof NavigationEnd))
            .subscribe((event) => {
            if (event.id === 1 && event.url === event.urlAfterRedirects) {
                this._drillThroughService.restoreStates();
            }
        });
    }
    /**
     * Set drill through initial data
     */
    setDrillThrough() {
        const drillPageState = this._drillThroughService.GetCurrentDrillThroughState();
        if (this.enlightenReportTypes[drillPageState.page.elements[0].type] === this.enlightenReportTypes.tabular) {
            this.reportType = this.enlightenReportTypes[drillPageState.page.elements[0].type];
        }
        else {
            this.reportType = this.enlightenReportTypes.graphical;
        }
        this.page = drillPageState.page;
        this.filter = drillPageState.filter;
        this._drillThroughService.setBreadCrumbs();
        this.hasNextPage = this._drillThroughService.hasNextPage();
    }
    /**
     * called on click of next arrow on drill through page
     */
    nextPage() {
        const drillPageState = this._drillThroughService.PageNext();
        if (drillPageState) {
            this._router.navigate([this._drillThroughService.getParentData().url + '/drill-through/' + drillPageState.page.id]);
        }
    }
    /**
     * called on click of next arrow on drill through page
     */
    previousPage() {
        const drillPageState = this._drillThroughService.PageBack();
        if (drillPageState) {
            this._router.navigate([this._drillThroughService.getParentData().url + '/drill-through/' + drillPageState.page.id]);
        }
        else {
            this._router.navigate([this._drillThroughService.getParentData().url]);
        }
    }
}
DrillThroughComponent.ɵfac = function DrillThroughComponent_Factory(t) { return new (t || DrillThroughComponent)(i0.ɵɵdirectiveInject(i1.DrillThroughService), i0.ɵɵdirectiveInject(i2.Router)); };
DrillThroughComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: DrillThroughComponent, selectors: [["drill-through"]], hostBindings: function DrillThroughComponent_HostBindings(rf, ctx) { if (rf & 1) {
        i0.ɵɵlistener("beforeunload", function DrillThroughComponent_beforeunload_HostBindingHandler($event) { return ctx.beforeUnload($event); }, false, i0.ɵɵresolveWindow);
    } }, inputs: { drillThroughParentType: "drillThroughParentType", appVersionId: "appVersionId" }, decls: 4, vars: 7, consts: [[3, "ngClass"], [3, "ngSwitch"], ["class", "report-page graphical-report-page customscroll", 3, "page", "drillThroughFilterInput", "screenType", "drillThroughParentType", "hasNextPage", "appVersionId", "nextPageClicked", "previousPageClicked", 4, "ngSwitchCase"], ["class", "report-page tabular-report-page h-full", 3, "page", "drillThroughFilterInput", "screenType", "drillThroughParentType", "hasNextPage", "appVersionId", "nextPageClicked", "previousPageClicked", 4, "ngSwitchCase"], [1, "report-page", "graphical-report-page", "customscroll", 3, "page", "drillThroughFilterInput", "screenType", "drillThroughParentType", "hasNextPage", "appVersionId", "nextPageClicked", "previousPageClicked"], [1, "report-page", "tabular-report-page", "h-full", 3, "page", "drillThroughFilterInput", "screenType", "drillThroughParentType", "hasNextPage", "appVersionId", "nextPageClicked", "previousPageClicked"]], template: function DrillThroughComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "div", 0);
        i0.ɵɵelementContainerStart(1, 1);
        i0.ɵɵtemplate(2, DrillThroughComponent_graphical_report_2_Template, 1, 6, "graphical-report", 2);
        i0.ɵɵtemplate(3, DrillThroughComponent_tabular_report_3_Template, 1, 6, "tabular-report", 3);
        i0.ɵɵelementContainerEnd();
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction2(4, _c0, ctx.reportType === ctx.enlightenReportTypes.graphical, ctx.reportType === ctx.enlightenReportTypes.tabular));
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngSwitch", ctx.reportType);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngSwitchCase", ctx.enlightenReportTypes.graphical);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngSwitchCase", ctx.enlightenReportTypes.tabular);
    } }, directives: [i3.NgClass, i3.NgSwitch, i3.NgSwitchCase, i4.GraphicalReportComponent, i5.TabularReportComponent], styles: ["drill-through .graphical-drill-parent{width:100%;display:flex;justify-content:center;max-height:calc(100vh - 92px)}drill-through #central-page{padding:1rem;min-height:100%;border:none!important;box-shadow:none!important;height:100%;max-height:100%}drill-through #central-page .back-btn{min-width:1.5rem!important;max-width:1.5rem!important;cursor:pointer}drill-through #central-page .next-btn{min-width:1.5rem!important;max-width:1.5rem!important;cursor:pointer;transform:rotate(180deg);float:right}drill-through graphical-report{width:100%}drill-through tabular-report{min-height:100%!important;height:100%!important;max-height:100%!important;box-shadow:none!important}drill-through tabular-report .tableContainer{max-width:100%;min-width:100%;height:calc(100% - .5rem)!important;max-height:calc(100% - .5rem)!important;min-height:calc(100% - .5rem)!important}drill-through tabular-report .tableContainer table{width:auto!important}drill-through .tabular-report{min-height:400px!important;height:100%!important;max-height:calc(100% - 2rem)!important;min-width:400px!important;width:100%!important;max-width:100%;border:1px solid #80808033!important}drill-through h1:has(+ p){margin-bottom:0}drill-through .tabular-report:has(.loader-spinner){width:100%!important}\n"], encapsulation: 2 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DrillThroughComponent, [{
        type: Component,
        args: [{ selector: 'drill-through', encapsulation: ViewEncapsulation.None, template: "<div [ngClass]=\"{'graphical-drill-parent': reportType === enlightenReportTypes.graphical, 'h-full': reportType === enlightenReportTypes.tabular}\">\n    <ng-container [ngSwitch]=\"reportType\">\n        <graphical-report\n            *ngSwitchCase=\"enlightenReportTypes.graphical\"\n            class=\"report-page graphical-report-page customscroll\"\n            [page]=\"page\"\n            [drillThroughFilterInput]=\"filter\"\n            [screenType]=\"screenTypes.drillThrough\"\n            (nextPageClicked)=\"nextPage()\"\n            (previousPageClicked)=\"previousPage()\"\n            [drillThroughParentType]=\"drillThroughParentType\"\n            [hasNextPage]=\"hasNextPage\"\n            [appVersionId]=\"appVersionId\">\n        </graphical-report>\n        <tabular-report\n            *ngSwitchCase=\"enlightenReportTypes.tabular\"\n            class=\"report-page tabular-report-page h-full\"\n            [page]=\"page\"\n            [drillThroughFilterInput]=\"filter\"\n            [screenType]=\"screenTypes.drillThrough\"\n            (nextPageClicked)=\"nextPage()\"\n            (previousPageClicked)=\"previousPage()\"\n            [drillThroughParentType]=\"drillThroughParentType\"\n            [hasNextPage]=\"hasNextPage\"\n            [appVersionId]=\"appVersionId\">\n        </tabular-report>\n    </ng-container>\n</div>\n\t\n", styles: ["drill-through .graphical-drill-parent{width:100%;display:flex;justify-content:center;max-height:calc(100vh - 92px)}drill-through #central-page{padding:1rem;min-height:100%;border:none!important;box-shadow:none!important;height:100%;max-height:100%}drill-through #central-page .back-btn{min-width:1.5rem!important;max-width:1.5rem!important;cursor:pointer}drill-through #central-page .next-btn{min-width:1.5rem!important;max-width:1.5rem!important;cursor:pointer;transform:rotate(180deg);float:right}drill-through graphical-report{width:100%}drill-through tabular-report{min-height:100%!important;height:100%!important;max-height:100%!important;box-shadow:none!important}drill-through tabular-report .tableContainer{max-width:100%;min-width:100%;height:calc(100% - .5rem)!important;max-height:calc(100% - .5rem)!important;min-height:calc(100% - .5rem)!important}drill-through tabular-report .tableContainer table{width:auto!important}drill-through .tabular-report{min-height:400px!important;height:100%!important;max-height:calc(100% - 2rem)!important;min-width:400px!important;width:100%!important;max-width:100%;border:1px solid #80808033!important}drill-through h1:has(+ p){margin-bottom:0}drill-through .tabular-report:has(.loader-spinner){width:100%!important}\n"] }]
    }], function () { return [{ type: i1.DrillThroughService }, { type: i2.Router }]; }, { drillThroughParentType: [{
            type: Input
        }], appVersionId: [{
            type: Input
        }], beforeUnload: [{
            type: HostListener,
            args: ['window:beforeunload', ['$event']]
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 