import { Component, EventEmitter, HostBinding, Inject, Input, Optional, Output } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { DisplayBehaviour, Syntax, getEntityDimensions, getPropertyName, nonNullable } from '@metad/ocap-core';
import { BehaviorSubject, filter, map } from 'rxjs';
import { BaseSlicersComponent } from '../base-slicers';
import { SlicersCapacity } from '../types';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "@angular/cdk/drag-drop";
import * as i4 from "@angular/material/dialog";
import * as i5 from "@angular/material/icon";
import * as i6 from "@angular/material/button";
import * as i7 from "@angular/material/divider";
import * as i8 from "@angular/material/menu";
import * as i9 from "@metad/ocap-angular/core";
import * as i10 from "@metad/ocap-angular/common";
import * as i11 from "@metad/ocap-angular/entity";
import * as i12 from "../slicer/slicer.component";
import * as i13 from "@ngx-translate/core";
export class SlicerBarComponent extends BaseSlicersComponent {
    get slicers() {
        return this.slicers$.value;
    }
    set slicers(value) {
        this.slicers$.next(value);
    }
    get showCombinationSlicer() {
        return this.entityType?.syntax === Syntax.SQL && this.capacities?.includes(SlicersCapacity.CombinationSlicer);
    }
    get showAdvancedSlicer() {
        return this.entityType?.syntax === Syntax.MDX && this.capacities?.includes(SlicersCapacity.AdvancedSlicer);
    }
    get highlight() {
        return this.searchControl.value;
    }
    constructor(data) {
        super();
        this.data = data;
        this.DisplayBehaviour = DisplayBehaviour;
        this.SlicersCapacity = SlicersCapacity;
        this.isDialogContainer = true;
        this.slicers$ = new BehaviorSubject([]);
        this.removed = new EventEmitter();
        this.valueChange = new EventEmitter();
        this.dimensions$ = this.entityType$.pipe(filter(nonNullable), map(getEntityDimensions));
        this.dateVariables = this.coreService.getDateVariables().filter((variable) => !!variable.dateRange);
        this.searchControl = new FormControl('');
    }
    ngOnInit() {
        if (this.data) {
            this.slicers = this.data.value;
            this.entityType = this.data.entityType;
            this.dataSettings = this.data.dataSettings;
            this.capacities = this.data.capacities;
        }
    }
    removeSelectOption(member) {
        this.removed.emit(member);
    }
    update(value, index) {
        this.slicers = [...this.slicers];
        this.slicers[index] = value;
    }
    remove(index) {
        this.slicers = [...this.slicers];
        this.slicers.splice(index, 1);
    }
    async addSlicer(slicer) {
        this.slicers = this.slicers ?? [];
        const index = this.slicers.findIndex((item) => getPropertyName(item.dimension) === getPropertyName(slicer.dimension));
        if (index > -1) {
            this.update(slicer, index);
        }
        else {
            this.slicers = [...this.slicers, slicer];
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.10", ngImport: i0, type: SlicerBarComponent, deps: [{ token: MAT_DIALOG_DATA, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.10", type: SlicerBarComponent, selector: "ngm-slicer-bar", inputs: { slicers: "slicers", capacities: "capacities" }, outputs: { removed: "removed", valueChange: "valueChange" }, host: { properties: { "class.ngm-dialog-container": "this.isDialogContainer" } }, usesInheritance: true, ngImport: i0, template: "<header mat-dialog-title cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragHandle>\n  <h4 style=\"pointer-events: none;\">\n    {{ 'Ngm.Selection.Slicers' | translate: {Default: \"Slicers\"} }}\n  </h4>\n</header>\n\n<mat-dialog-content class=\"mat-typography\">\n  <ng-container *ngFor=\"let slicer of slicers$ | async; index as i\">\n    <ngm-slicer [slicer]=\"slicer\"\n      [dataSettings]=\"dataSettings\"\n      [entityType]=\"entityType\"\n      [editable]=\"editable()\"\n      (slicerChange)=\"update($event, i)\"\n      (removed)=\"remove(i)\">\n    </ngm-slicer>\n    <mat-divider></mat-divider>\n  </ng-container>\n</mat-dialog-content>\n\n<mat-dialog-actions style=\"display: flex; justify-content: space-between; align-items: center;\">\n  <button mat-button color=\"primary\" ngmAppearance=\"dashed\" [matMenuTriggerFor]=\"menu\">\n    <mat-icon>add</mat-icon>\n    {{ 'Ngm.Common.ADD' | translate: {Default: \"Add\"} }}\n  </button>\n\n  <div ngmButtonGroup>\n    <button mat-button mat-dialog-close cdkFocusInitial>\n      {{ 'Ngm.Common.Cancel' | translate: {Default: 'Cancel'} }}\n    </button>\n    <button mat-raised-button color=\"accent\" cdkFocusInitial [mat-dialog-close]=\"slicers\">\n      {{ 'Ngm.Common.Apply' | translate: {Default: 'Apply'} }}\n    </button>\n  </div>\n</mat-dialog-actions>\n\n<mat-menu #menu=\"matMenu\" class=\"ngm-density__compact\">\n  <ngm-search class=\"px-1\" [formControl]=\"searchControl\" (click)=\"$event.stopPropagation()\"></ngm-search>\n\n  <ng-container *ngFor=\"let property of dimensions$ | async\">\n    <button mat-menu-item *ngIf=\"isSemanticCalendar(property); else menuItem\" (click)=\"openSlicerCreator(property)\"\n      [matMenuTriggerFor]=\"calendarMenu\"\n      [matMenuTriggerData]=\"{property: property}\"\n    >\n      <ngm-entity-property [property]=\"property\" [displayBehaviour]=\"DisplayBehaviour.auto\"\n        [highlight]=\"highlight\">\n      </ngm-entity-property>\n    </button>\n\n    <ng-template #menuItem>\n      <button mat-menu-item (click)=\"openValueHelp(property)\">\n        <ngm-entity-property [property]=\"property\" [displayBehaviour]=\"DisplayBehaviour.auto\"\n          [highlight]=\"highlight\">\n        </ngm-entity-property>\n      </button>\n    </ng-template>\n  </ng-container>\n\n  <button mat-menu-item *ngIf=\"showCombinationSlicer\"\n    (click)=\"$event.preventDefault();openSlicerCreator(SlicersCapacity.CombinationSlicer)\">\n    <mat-icon>tune</mat-icon>\n    {{ 'Ngm.Selection.CombinationSlicer' | translate: {Default: 'Combination Slicer'} }}\n  </button>\n\n  <button mat-menu-item *ngIf=\"showAdvancedSlicer\"\n    (click)=\"$event.preventDefault();openSlicerCreator(SlicersCapacity.AdvancedSlicer)\">\n    <mat-icon>data_array</mat-icon>\n    {{ 'Ngm.Selection.AdvancedSlicer' | translate: {Default: 'Advanced Slicer'} }}\n  </button>\n</mat-menu>\n\n<mat-menu #calendarMenu=\"matMenu\" class=\"ngm-density__compact\">\n  <ng-template matMenuContent let-property=\"property\">\n    <button mat-menu-item (click)=\"openValueHelp(property)\">\n      <mat-icon fontSet=\"material-icons-outlined\">people_outline</mat-icon>\n      {{ 'Ngm.Selection.DimensionMembers' | translate: {Default: 'Dimension Members'} }}\n    </button>\n\n    <button mat-menu-item *ngFor=\"let variable of dateVariables\"\n      (click)=\"openDynamicDateHelp(property, variable.dateRange)\">\n      {{variable.name}}\n    </button>\n    \n  </ng-template>\n</mat-menu>\n", styles: [""], dependencies: [{ kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: i3.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "directive", type: i4.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }, { kind: "directive", type: i4.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i4.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i4.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "component", type: i5.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i6.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "component", type: i7.MatDivider, selector: "mat-divider", inputs: ["vertical", "inset"] }, { kind: "component", type: i8.MatMenu, selector: "mat-menu", inputs: ["backdropClass", "aria-label", "aria-labelledby", "aria-describedby", "xPosition", "yPosition", "overlapTrigger", "hasBackdrop", "class", "classList"], outputs: ["closed", "close"], exportAs: ["matMenu"] }, { kind: "component", type: i8.MatMenuItem, selector: "[mat-menu-item]", inputs: ["role", "disabled", "disableRipple"], exportAs: ["matMenuItem"] }, { kind: "directive", type: i8.MatMenuContent, selector: "ng-template[matMenuContent]" }, { kind: "directive", type: i8.MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", inputs: ["mat-menu-trigger-for", "matMenuTriggerFor", "matMenuTriggerData", "matMenuTriggerRestoreFocus"], outputs: ["menuOpened", "onMenuOpen", "menuClosed", "onMenuClose"], exportAs: ["matMenuTrigger"] }, { kind: "directive", type: i9.AppearanceDirective, selector: "[ngmAppearance]", inputs: ["color", "ngmAppearance", "outline", "hero", "acrylic", "opacity", "dashed", "danger"] }, { kind: "directive", type: i9.ButtonGroupDirective, selector: "[ngmButtonGroup]" }, { kind: "component", type: i10.NgmSearchComponent, selector: "ngm-search", inputs: ["formControl", "disabled", "displayDensity"] }, { kind: "component", type: i11.NgmEntityPropertyComponent, selector: "ngm-entity-property", inputs: ["property", "displayBehaviour", "displayDensity", "hiddenIcon", "highlight", "role"] }, { kind: "component", type: i12.SlicerComponent, selector: "ngm-slicer", inputs: ["slicer", "disabled", "limit"], outputs: ["removed", "slicerChange"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "pipe", type: i13.TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.10", ngImport: i0, type: SlicerBarComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ngm-slicer-bar', template: "<header mat-dialog-title cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragHandle>\n  <h4 style=\"pointer-events: none;\">\n    {{ 'Ngm.Selection.Slicers' | translate: {Default: \"Slicers\"} }}\n  </h4>\n</header>\n\n<mat-dialog-content class=\"mat-typography\">\n  <ng-container *ngFor=\"let slicer of slicers$ | async; index as i\">\n    <ngm-slicer [slicer]=\"slicer\"\n      [dataSettings]=\"dataSettings\"\n      [entityType]=\"entityType\"\n      [editable]=\"editable()\"\n      (slicerChange)=\"update($event, i)\"\n      (removed)=\"remove(i)\">\n    </ngm-slicer>\n    <mat-divider></mat-divider>\n  </ng-container>\n</mat-dialog-content>\n\n<mat-dialog-actions style=\"display: flex; justify-content: space-between; align-items: center;\">\n  <button mat-button color=\"primary\" ngmAppearance=\"dashed\" [matMenuTriggerFor]=\"menu\">\n    <mat-icon>add</mat-icon>\n    {{ 'Ngm.Common.ADD' | translate: {Default: \"Add\"} }}\n  </button>\n\n  <div ngmButtonGroup>\n    <button mat-button mat-dialog-close cdkFocusInitial>\n      {{ 'Ngm.Common.Cancel' | translate: {Default: 'Cancel'} }}\n    </button>\n    <button mat-raised-button color=\"accent\" cdkFocusInitial [mat-dialog-close]=\"slicers\">\n      {{ 'Ngm.Common.Apply' | translate: {Default: 'Apply'} }}\n    </button>\n  </div>\n</mat-dialog-actions>\n\n<mat-menu #menu=\"matMenu\" class=\"ngm-density__compact\">\n  <ngm-search class=\"px-1\" [formControl]=\"searchControl\" (click)=\"$event.stopPropagation()\"></ngm-search>\n\n  <ng-container *ngFor=\"let property of dimensions$ | async\">\n    <button mat-menu-item *ngIf=\"isSemanticCalendar(property); else menuItem\" (click)=\"openSlicerCreator(property)\"\n      [matMenuTriggerFor]=\"calendarMenu\"\n      [matMenuTriggerData]=\"{property: property}\"\n    >\n      <ngm-entity-property [property]=\"property\" [displayBehaviour]=\"DisplayBehaviour.auto\"\n        [highlight]=\"highlight\">\n      </ngm-entity-property>\n    </button>\n\n    <ng-template #menuItem>\n      <button mat-menu-item (click)=\"openValueHelp(property)\">\n        <ngm-entity-property [property]=\"property\" [displayBehaviour]=\"DisplayBehaviour.auto\"\n          [highlight]=\"highlight\">\n        </ngm-entity-property>\n      </button>\n    </ng-template>\n  </ng-container>\n\n  <button mat-menu-item *ngIf=\"showCombinationSlicer\"\n    (click)=\"$event.preventDefault();openSlicerCreator(SlicersCapacity.CombinationSlicer)\">\n    <mat-icon>tune</mat-icon>\n    {{ 'Ngm.Selection.CombinationSlicer' | translate: {Default: 'Combination Slicer'} }}\n  </button>\n\n  <button mat-menu-item *ngIf=\"showAdvancedSlicer\"\n    (click)=\"$event.preventDefault();openSlicerCreator(SlicersCapacity.AdvancedSlicer)\">\n    <mat-icon>data_array</mat-icon>\n    {{ 'Ngm.Selection.AdvancedSlicer' | translate: {Default: 'Advanced Slicer'} }}\n  </button>\n</mat-menu>\n\n<mat-menu #calendarMenu=\"matMenu\" class=\"ngm-density__compact\">\n  <ng-template matMenuContent let-property=\"property\">\n    <button mat-menu-item (click)=\"openValueHelp(property)\">\n      <mat-icon fontSet=\"material-icons-outlined\">people_outline</mat-icon>\n      {{ 'Ngm.Selection.DimensionMembers' | translate: {Default: 'Dimension Members'} }}\n    </button>\n\n    <button mat-menu-item *ngFor=\"let variable of dateVariables\"\n      (click)=\"openDynamicDateHelp(property, variable.dateRange)\">\n      {{variable.name}}\n    </button>\n    \n  </ng-template>\n</mat-menu>\n" }]
        }], ctorParameters: () => [{ type: undefined, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }], propDecorators: { isDialogContainer: [{
                type: HostBinding,
                args: ['class.ngm-dialog-container']
            }], slicers: [{
                type: Input
            }], capacities: [{
                type: Input
            }], removed: [{
                type: Output
            }], valueChange: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 