import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { CrossFilterDto } from '../../common-dto/elements-dto';
import { ScopeType, ScreenType } from '../../enlighten-lib/filters/condition-type';
import { ElementService } from '../../enlighten-lib/report/element.service';
import * as i0 from "@angular/core";
import * as i1 from "../../enlighten-lib/report/element.service";
import * as i2 from "@angular/router";
function DashboardFilterComponent_button_2_Template(rf, ctx) { if (rf & 1) {
    const _r2 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "button", 3);
    i0.ɵɵlistener("click", function DashboardFilterComponent_button_2_Template_button_click_0_listener() { i0.ɵɵrestoreView(_r2); const ctx_r1 = i0.ɵɵnextContext(); return ctx_r1.resetCrossFilter(); });
    i0.ɵɵelement(1, "mat-icon", 4);
    i0.ɵɵelementEnd();
} }
const _c0 = function (a0) { return { "widthWithCrossFilter": a0 }; };
export class DashboardFilterComponent {
    constructor(_elementService, activatedRoute) {
        this._elementService = _elementService;
        this.activatedRoute = activatedRoute;
        this.commonFilterArray = [];
        this.dirtyFlowCheckEvent = new EventEmitter();
        this.scopeType = ScopeType.global;
        this.showHeader = true;
    }
    ngOnInit() {
        this.activatedRoute.paramMap.subscribe((params) => {
            const showHeader = params.get('header');
            if (showHeader && showHeader === 'hideHeader') {
                this.showHeader = false;
            }
        });
    }
    /**
     * Reset cross filter
     */
    resetCrossFilter() {
        const crossfilterDto = new CrossFilterDto();
        crossfilterDto.resetFilter = true;
        this._elementService.triggerCrossFilter(crossfilterDto);
    }
    ngOnChanges() {
        this.commonFilterArray = [];
        this.allFilter();
    }
    /**
     * Call dirty flow event emit
     */
    dirtyFlowCheck() {
        this.dirtyFlowCheckEvent.emit();
    }
    /**
     * call when the global filters fields values are selected.
     */
    refreshElementData() {
        this._elementService.refreshElementData();
    }
    allFilter() {
        this.filters.forEach((filter) => {
            //   filter.generalFilterType = 1;
            if (!this.commonFilterArray.includes(filter)) {
                this.commonFilterArray.push(filter);
            }
        });
        this.categories.forEach((category) => {
            category.generalFilterType = 2;
            if (!this.commonFilterArray.includes(category)) {
                this.commonFilterArray.push(category);
            }
        });
    }
}
DashboardFilterComponent.ɵfac = function DashboardFilterComponent_Factory(t) { return new (t || DashboardFilterComponent)(i0.ɵɵdirectiveInject(i1.ElementService), i0.ɵɵdirectiveInject(i2.ActivatedRoute)); };
DashboardFilterComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: DashboardFilterComponent, selectors: [["lib-dashboard-filter"]], inputs: { filters: "filters", categories: "categories", screenType: "screenType", commonFilterArray: "commonFilterArray", crossFilterEnabled: "crossFilterEnabled" }, outputs: { dirtyFlowCheckEvent: "dirtyFlowCheckEvent" }, features: [i0.ɵɵNgOnChangesFeature], decls: 3, vars: 7, consts: [[1, "filter-component", "global-filter"], [1, "flex", "gap-x-2", 3, "commonFilterArray", "screenType", "scopeType", "ngClass", "dirtyFlowCheckEvent", "filterChangeEmit"], ["matTooltip", "Remove cross filter", "mat-icon-button", "", "class", "flex items-center", 3, "click", 4, "ngIf"], ["matTooltip", "Remove cross filter", "mat-icon-button", "", 1, "flex", "items-center", 3, "click"], ["svgIcon", "axo_filter_remove", 1, "filter-icon"]], template: function DashboardFilterComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "div", 0);
        i0.ɵɵelementStart(1, "filters", 1);
        i0.ɵɵlistener("dirtyFlowCheckEvent", function DashboardFilterComponent_Template_filters_dirtyFlowCheckEvent_1_listener() { return ctx.dirtyFlowCheck(); })("filterChangeEmit", function DashboardFilterComponent_Template_filters_filterChangeEmit_1_listener() { return ctx.refreshElementData(); });
        i0.ɵɵelementEnd();
        i0.ɵɵtemplate(2, DashboardFilterComponent_button_2_Template, 2, 0, "button", 2);
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("commonFilterArray", ctx.commonFilterArray)("screenType", ctx.screenType)("scopeType", ctx.scopeType)("ngClass", i0.ɵɵpureFunction1(5, _c0, !ctx.showHeader && ctx.crossFilterEnabled));
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", !ctx.showHeader && ctx.crossFilterEnabled);
    } }, styles: ["lib-dashboard-filter{max-width:100%;width:100%;height:3.7rem;display:flex;align-items:start}lib-dashboard-filter .widthWithCrossFilter{width:calc(100% - 2.563rem);min-width:calc(100% - 2.563rem);max-width:calc(100% - 2.563rem);display:flex;align-items:center}lib-dashboard-filter .global-filter{height:100%;display:flex;align-items:center;max-width:100%}lib-dashboard-filter .global-filter .dash-reset,lib-dashboard-filter .global-filter .reset-section,lib-dashboard-filter .global-filter .reset-btn{border-left:1px solid #c9c9c9c9;white-space:nowrap;width:144px;display:flex;height:2rem;align-items:start;padding-left:.4rem}lib-dashboard-filter .global-filter .dash-reset .reset,lib-dashboard-filter .global-filter .reset-section .reset,lib-dashboard-filter .global-filter .reset-btn .reset{margin:0;font-size:11px}lib-dashboard-filter .global-filter .filter-wrapper{position:inherit;display:inline-block;gap:25px;max-width:calc(100% - 154px);height:2.7rem;line-height:2.7rem;align-items:start!important;overflow-y:hidden;align-self:center}lib-dashboard-filter .global-filter .filter-wrapper .reset{margin:0!important}\n"], encapsulation: 2 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DashboardFilterComponent, [{
        type: Component,
        args: [{ selector: 'lib-dashboard-filter', encapsulation: ViewEncapsulation.None, template: "<div class=\"filter-component global-filter\">\n <filters\n    class=\"flex gap-x-2\"\n    [commonFilterArray]=\"commonFilterArray\"\n    [screenType]=\"screenType\"\n    (dirtyFlowCheckEvent)=\"dirtyFlowCheck()\"\n    (filterChangeEmit)= \"refreshElementData()\"\n    [scopeType]=\"scopeType\"\n    [ngClass]=\"{'widthWithCrossFilter': !showHeader && crossFilterEnabled}\"\n    >\n </filters>\n <button *ngIf=\"!showHeader && crossFilterEnabled\" (click)=\"resetCrossFilter()\" matTooltip=\"Remove cross filter\"  mat-icon-button class=\"flex items-center\">\n   <mat-icon class=\"filter-icon\"svgIcon=\"axo_filter_remove\"></mat-icon>\n </button>\n</div>\n", styles: ["lib-dashboard-filter{max-width:100%;width:100%;height:3.7rem;display:flex;align-items:start}lib-dashboard-filter .widthWithCrossFilter{width:calc(100% - 2.563rem);min-width:calc(100% - 2.563rem);max-width:calc(100% - 2.563rem);display:flex;align-items:center}lib-dashboard-filter .global-filter{height:100%;display:flex;align-items:center;max-width:100%}lib-dashboard-filter .global-filter .dash-reset,lib-dashboard-filter .global-filter .reset-section,lib-dashboard-filter .global-filter .reset-btn{border-left:1px solid #c9c9c9c9;white-space:nowrap;width:144px;display:flex;height:2rem;align-items:start;padding-left:.4rem}lib-dashboard-filter .global-filter .dash-reset .reset,lib-dashboard-filter .global-filter .reset-section .reset,lib-dashboard-filter .global-filter .reset-btn .reset{margin:0;font-size:11px}lib-dashboard-filter .global-filter .filter-wrapper{position:inherit;display:inline-block;gap:25px;max-width:calc(100% - 154px);height:2.7rem;line-height:2.7rem;align-items:start!important;overflow-y:hidden;align-self:center}lib-dashboard-filter .global-filter .filter-wrapper .reset{margin:0!important}\n"] }]
    }], function () { return [{ type: i1.ElementService }, { type: i2.ActivatedRoute }]; }, { filters: [{
            type: Input
        }], categories: [{
            type: Input
        }], screenType: [{
            type: Input
        }], commonFilterArray: [{
            type: Input
        }], crossFilterEnabled: [{
            type: Input
        }], dirtyFlowCheckEvent: [{
            type: Output
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 