import { DragDropModule } from '@angular/cdk/drag-drop';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { CommonModule } from '@angular/common';
import { Component, inject, model, signal } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatRadioModule } from '@angular/material/radio';
import { MatTooltipModule } from '@angular/material/tooltip';
import { NgmDisplayBehaviourComponent, NgmSearchComponent } from '@metad/ocap-angular/common';
import { ButtonGroupDirective } from '@metad/ocap-angular/core';
import { nonNullable } from '@metad/ocap-core';
import { TranslateModule } from '@ngx-translate/core';
import { NGXLogger } from 'ngx-logger';
import { combineLatestWith, distinctUntilChanged, filter, map, startWith, switchMap, tap } from 'rxjs';
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 "@ngx-translate/core";
import * as i5 from "@angular/cdk/scrolling";
import * as i6 from "@angular/material/button";
import * as i7 from "@angular/material/dialog";
import * as i8 from "@angular/material/icon";
import * as i9 from "@angular/material/radio";
import * as i10 from "@angular/material/list";
import * as i11 from "@angular/material/progress-spinner";
import * as i12 from "@angular/material/tooltip";
export class NgmEntityDialogComponent {
    #logger;
    constructor() {
        this.data = inject(MAT_DIALOG_DATA);
        this.dialogRef = inject(MatDialogRef);
        this.#logger = inject(NGXLogger);
        this.modelKey = model(null);
        this.search = new FormControl('');
        this.loading = signal(false);
        this.entities$ = toObservable(this.modelKey).pipe(distinctUntilChanged(), filter(nonNullable), tap((modelKey) => {
            this.loading.set(true);
            this.data.registerModel?.(modelKey);
            this.entities.set([]);
        }), switchMap((dataSource) => this.data.dsCoreService.getDataSource(dataSource)), switchMap((dataSource) => dataSource.discoverMDCubes()), map((entitySets) => entitySets.map((item) => ({
            value: item,
            key: item.name,
            caption: item.caption
        }))), tap((entities) => {
            this.loading.set(false);
            if (!this.entities().length && entities.length) {
                this.entities.set([entities[0].key]);
            }
            if (this.data.dataSources.length === 1 && entities.length === 1) {
                this.onApply();
            }
        }), combineLatestWith(this.search.valueChanges.pipe(startWith(''), map((text) => text.trim().toLowerCase()))), map(([entities, text]) => text ? entities.filter((item) => item.caption?.toLowerCase().includes(text) || item.key?.toLowerCase().includes(text)) : entities));
        // Selected entity keys
        this.entities = model([]);
        if (this.data.dataSources.length === 1) {
            this.modelKey.set(this.data.dataSources[0].key);
        }
    }
    onApply() {
        this.dialogRef.close({
            modelId: this.data.dataSources.find((item) => item.key === this.modelKey())?.value,
            dataSource: this.modelKey(),
            entities: this.entities()
        });
    }
    trackByKey(index, item) {
        return item.key;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.10", ngImport: i0, type: NgmEntityDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.10", type: NgmEntityDialogComponent, isStandalone: true, selector: "ngm-entity-dialog", inputs: { modelKey: { classPropertyName: "modelKey", publicName: "modelKey", isSignal: true, isRequired: false, transformFunction: null }, entities: { classPropertyName: "entities", publicName: "entities", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { modelKey: "modelKeyChange", entities: "entitiesChange" }, ngImport: i0, template: "<div class=\"ngm-theme-dark dark w-[300px] shrink-0 flex flex-col justify-start overflow-auto bg-bluegray-700 text-white p-4 group\">\n    <div class=\"w-full flex justify-start items-center my-2\" cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragHandle>\n        <mat-icon displayDensity=\"cosy\" class=\"-ml-2 opacity-0 group-hover:opacity-80\">drag_indicator</mat-icon>\n        <span class=\"text-lg pointer-events-none\">{{ 'Ngm.Entity.SelectEntities' | translate: {Default: 'Select Entities'} }}</span>\n    </div>\n\n    <div class=\"flex-1 flex flex-col\">\n      <label class=\"text-lg p-2\">{{ 'Ngm.Entity.SemanticModel' | translate: {Default: 'Semantic Model'} }}</label>\n      <mat-radio-group [(ngModel)]=\"modelKey\">\n        @for (item of data.dataSources; track item.key) {\n          <mat-radio-button [value]=\"item.key\">{{item.caption}}</mat-radio-button>\n        }\n      </mat-radio-group>\n    </div>\n\n    <div class=\"flex justify-between\">\n      <div ngmButtonGroup>\n        <button mat-raised-button color=\"accent\" cdkFocusInitial (click)=\"onApply()\">\n          {{ 'Ngm.Common.Apply' | translate: {Default: \"Apply\"} }}\n        </button>\n        <button mat-button mat-dialog-close>\n          {{ 'Ngm.Common.Cancel' | translate: {Default: \"Cancel\"} }}\n        </button>\n      </div>\n    </div>\n</div>\n  \n<div class=\"w-[500px] h-[50vh] relative flex flex-col justify-start items-stretch\">\n    <label class=\"text-lg p-2\">{{ 'Ngm.Entity.Cube' | translate: {Default: 'Cube'} }}</label>\n    <ngm-search class=\"m-2\" [formControl]=\"search\"></ngm-search>\n  @if (loading()) {\n    <div class=\"absolute w-full h-full top-0 left-0 flex justify-center items-center z-10\">\n      <mat-spinner mode=\"indeterminate\" diameter=\"30\" class=\"m-2\"></mat-spinner>\n    </div>\n  }\n\n  <cdk-virtual-scroll-viewport class=\"flex-1 h-full overflow-hidden hover:overflow-y-auto\"\n    itemSize=\"30\" minBufferPx=\"360\" maxBufferPx=\"1000\">\n    <mat-selection-list [(ngModel)]=\"entities\" [multiple]=\"false\" class=\"overflow-auto\">\n      <mat-list-option *cdkVirtualFor=\"let entity of entities$ | async; trackBy: trackByKey\" [value]=\"entity.key\">\n        @if (entity.value.annotated) {\n          <mat-icon matListItemIcon fontSet=\"material-icons-round\" class=\"opacity-60\"\n            [matTooltip]=\"'Ngm.Entity.AnnotatedCube' | translate: {Default: 'Annotated Cube'}\"\n            matTooltipPosition=\"before\"\n          >tips_and_updates</mat-icon>\n        }\n        <ngm-display-behaviour [option]=\"entity\" [highlight]=\"search.value\" />\n      </mat-list-option>\n    </mat-selection-list>\n  </cdk-virtual-scroll-viewport>\n</div>", styles: [":host{display:flex;overflow:hidden}.cdk-virtual-scrollable{overflow-x:hidden}:host::ng-deep .cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper{max-width:100%}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: DragDropModule }, { 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: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i4.TranslatePipe, name: "translate" }, { kind: "ngmodule", type: ScrollingModule }, { kind: "directive", type: i5.CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }, { kind: "directive", type: i5.CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }, { kind: "component", type: i5.CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation", "appendOnly"], outputs: ["scrolledIndexChange"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i6.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "ngmodule", type: MatDialogModule }, { kind: "directive", type: i7.MatDialogClose, selector: "[mat-dialog-close], [matDialogClose]", inputs: ["aria-label", "type", "mat-dialog-close", "matDialogClose"], exportAs: ["matDialogClose"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i8.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: MatRadioModule }, { kind: "directive", type: i9.MatRadioGroup, selector: "mat-radio-group", inputs: ["color", "name", "labelPosition", "value", "selected", "disabled", "required"], outputs: ["change"], exportAs: ["matRadioGroup"] }, { kind: "component", type: i9.MatRadioButton, selector: "mat-radio-button", inputs: ["id", "name", "aria-label", "aria-labelledby", "aria-describedby", "disableRipple", "tabIndex", "checked", "value", "labelPosition", "disabled", "required", "color"], outputs: ["change"], exportAs: ["matRadioButton"] }, { kind: "ngmodule", type: MatListModule }, { kind: "component", type: i10.MatSelectionList, selector: "mat-selection-list", inputs: ["color", "compareWith", "multiple", "hideSingleSelectionIndicator", "disabled"], outputs: ["selectionChange"], exportAs: ["matSelectionList"] }, { kind: "component", type: i10.MatListOption, selector: "mat-list-option", inputs: ["togglePosition", "checkboxPosition", "color", "value", "selected"], outputs: ["selectedChange"], exportAs: ["matListOption"] }, { kind: "directive", type: i10.MatListItemIcon, selector: "[matListItemIcon]" }, { kind: "ngmodule", type: MatProgressSpinnerModule }, { kind: "component", type: i11.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "mode", "value", "diameter", "strokeWidth"], exportAs: ["matProgressSpinner"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "directive", type: i12.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: NgmSearchComponent, selector: "ngm-search", inputs: ["formControl", "disabled", "displayDensity"] }, { kind: "directive", type: ButtonGroupDirective, selector: "[ngmButtonGroup]" }, { kind: "component", type: NgmDisplayBehaviourComponent, selector: "ngm-display-behaviour", inputs: ["displayBehaviour", "excludeSelected", "option", "highlight"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.10", ngImport: i0, type: NgmEntityDialogComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, selector: 'ngm-entity-dialog', imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        DragDropModule,
                        TranslateModule,
                        ScrollingModule,
                        MatButtonModule,
                        MatDialogModule,
                        MatIconModule,
                        MatRadioModule,
                        MatListModule,
                        MatProgressSpinnerModule,
                        MatTooltipModule,
                        NgmSearchComponent,
                        ButtonGroupDirective,
                        NgmDisplayBehaviourComponent
                    ], template: "<div class=\"ngm-theme-dark dark w-[300px] shrink-0 flex flex-col justify-start overflow-auto bg-bluegray-700 text-white p-4 group\">\n    <div class=\"w-full flex justify-start items-center my-2\" cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragHandle>\n        <mat-icon displayDensity=\"cosy\" class=\"-ml-2 opacity-0 group-hover:opacity-80\">drag_indicator</mat-icon>\n        <span class=\"text-lg pointer-events-none\">{{ 'Ngm.Entity.SelectEntities' | translate: {Default: 'Select Entities'} }}</span>\n    </div>\n\n    <div class=\"flex-1 flex flex-col\">\n      <label class=\"text-lg p-2\">{{ 'Ngm.Entity.SemanticModel' | translate: {Default: 'Semantic Model'} }}</label>\n      <mat-radio-group [(ngModel)]=\"modelKey\">\n        @for (item of data.dataSources; track item.key) {\n          <mat-radio-button [value]=\"item.key\">{{item.caption}}</mat-radio-button>\n        }\n      </mat-radio-group>\n    </div>\n\n    <div class=\"flex justify-between\">\n      <div ngmButtonGroup>\n        <button mat-raised-button color=\"accent\" cdkFocusInitial (click)=\"onApply()\">\n          {{ 'Ngm.Common.Apply' | translate: {Default: \"Apply\"} }}\n        </button>\n        <button mat-button mat-dialog-close>\n          {{ 'Ngm.Common.Cancel' | translate: {Default: \"Cancel\"} }}\n        </button>\n      </div>\n    </div>\n</div>\n  \n<div class=\"w-[500px] h-[50vh] relative flex flex-col justify-start items-stretch\">\n    <label class=\"text-lg p-2\">{{ 'Ngm.Entity.Cube' | translate: {Default: 'Cube'} }}</label>\n    <ngm-search class=\"m-2\" [formControl]=\"search\"></ngm-search>\n  @if (loading()) {\n    <div class=\"absolute w-full h-full top-0 left-0 flex justify-center items-center z-10\">\n      <mat-spinner mode=\"indeterminate\" diameter=\"30\" class=\"m-2\"></mat-spinner>\n    </div>\n  }\n\n  <cdk-virtual-scroll-viewport class=\"flex-1 h-full overflow-hidden hover:overflow-y-auto\"\n    itemSize=\"30\" minBufferPx=\"360\" maxBufferPx=\"1000\">\n    <mat-selection-list [(ngModel)]=\"entities\" [multiple]=\"false\" class=\"overflow-auto\">\n      <mat-list-option *cdkVirtualFor=\"let entity of entities$ | async; trackBy: trackByKey\" [value]=\"entity.key\">\n        @if (entity.value.annotated) {\n          <mat-icon matListItemIcon fontSet=\"material-icons-round\" class=\"opacity-60\"\n            [matTooltip]=\"'Ngm.Entity.AnnotatedCube' | translate: {Default: 'Annotated Cube'}\"\n            matTooltipPosition=\"before\"\n          >tips_and_updates</mat-icon>\n        }\n        <ngm-display-behaviour [option]=\"entity\" [highlight]=\"search.value\" />\n      </mat-list-option>\n    </mat-selection-list>\n  </cdk-virtual-scroll-viewport>\n</div>", styles: [":host{display:flex;overflow:hidden}.cdk-virtual-scrollable{overflow-x:hidden}:host::ng-deep .cdk-virtual-scroll-orientation-vertical .cdk-virtual-scroll-content-wrapper{max-width:100%}\n"] }]
        }], ctorParameters: () => [] });
//# sourceMappingURL=data:application/json;base64, 