import * as i0 from '@angular/core';
import { forwardRef, Component, Input, Pipe, NgModule } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import * as i2 from '@angular/forms';
import { FormGroup, FormControl, FormArray, NG_VALUE_ACCESSOR, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AggregationRole, getEntityDimensionAndHierarchies, slicerAsString, getEntityDimensions } from '@metad/ocap-core';
import { isEqual } from 'lodash-es';
import { BehaviorSubject, map, shareReplay, withLatestFrom, distinctUntilChanged } from 'rxjs';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@angular/material/form-field';
import { MatFormFieldModule } from '@angular/material/form-field';
import * as i4 from '@angular/material/select';
import { MatSelectModule } from '@angular/material/select';
import * as i5 from '@angular/material/core';
import * as i6 from '@angular/material/button';
import { MatButtonModule } from '@angular/material/button';
import * as i7 from '@angular/material/menu';
import { MatMenuModule } from '@angular/material/menu';
import * as i8 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import * as i9 from '@metad/ocap-angular/core';
import { OcapCoreModule } from '@metad/ocap-angular/core';
import { TranslateModule } from '@ngx-translate/core';

class SlicerSelectComponent {
    get entitySet() {
        return this.entitySet$.value;
    }
    set entitySet(value) {
        this.entitySet$.next(value);
    }
    constructor() {
        this.AggregationRole = AggregationRole;
        this.appearance = 'fill';
        this.entitySet$ = new BehaviorSubject(null);
        this.dimensions$ = this.entitySet$.pipe(map((entitySet) => getEntityDimensionAndHierarchies(entitySet?.entityType)), shareReplay(1));
        this.formGroup = new FormGroup({
            dimension: new FormGroup({
                dimension: new FormControl(),
                hierarchy: new FormControl(),
                level: new FormControl()
            }),
            members: new FormArray([])
        });
        this.formControl = new FormControl();
        this.formControl.valueChanges
            .pipe(withLatestFrom(this.dimensions$), map(([id, dimensions]) => {
            const property = dimensions.find((item) => item.__id__ === id);
            if (property.role === AggregationRole.dimension) {
                return { dimension: property.name };
            }
            else if (property.role === AggregationRole.hierarchy) {
                return {
                    dimension: property.dimension,
                    hierarchy: property.name
                };
            }
            return null;
        }), takeUntilDestroyed())
            .subscribe((dimension) => {
            this.formGroup.patchValue({ dimension });
        });
        this.formGroup.valueChanges.pipe(distinctUntilChanged(isEqual), takeUntilDestroyed()).subscribe((value) => {
            this.onChange?.(value);
        });
    }
    writeValue(obj) {
        const value = obj || {};
        // 避免双向绑定的循环更新
        if (!isEqual(value, this.formGroup.value)) {
            this.formGroup.patchValue(value);
        }
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        //
    }
    setDisabledState(isDisabled) {
        //
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SlicerSelectComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: SlicerSelectComponent, selector: "ngm-slicer-select", inputs: { appearance: "appearance", slicer: "slicer", entitySet: "entitySet" }, host: { classAttribute: "ngm-slicer-select" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                multi: true,
                useExisting: forwardRef(() => SlicerSelectComponent)
            }
        ], ngImport: i0, template: "<mat-form-field fxFlex=\"100\" [appearance]=\"appearance\">\n  <mat-label>Select</mat-label>\n  <mat-select [formControl]=\"formControl\">\n    <mat-option *ngFor=\"let property of dimensions$ | async\" [value]=\"property.__id__\">\n        <button *ngIf=\"property.role === AggregationRole.hierarchy\" mat-icon-button displayDensity=\"compact\" disabled></button>\n        {{property.caption || property.name}}\n    </mat-option>\n  </mat-select>\n\n  <div matSuffix>\n    <button mat-icon-button  [matMenuTriggerFor]=\"operatorMenu\"\n        (click)=\"$event.stopPropagation();$event.preventDefault();\">\n        <mat-icon>drag_handle</mat-icon>\n    </button>\n\n    <button mat-icon-button matSuffix [matMenuTriggerFor]=\"slicerMenu\"\n        (click)=\"$event.stopPropagation();$event.preventDefault();\">\n        <mat-icon>more_vert</mat-icon>\n    </button>\n\n    <ng-content></ng-content>\n  </div>\n  \n</mat-form-field>\n\n<mat-menu #operatorMenu=\"matMenu\" class=\"ngm-density__compact\">\n    <button mat-menu-item disableRipple >\n      <mat-icon>dvr</mat-icon>\n      <span>Equal</span>\n    </button>\n    <button mat-menu-item disableRipple >\n        <mat-icon>chevron_left</mat-icon>\n        <span>Less than</span>\n    </button>\n\n    <button mat-menu-item disableRipple >\n        <mat-icon>first_page</mat-icon>\n        <span>Less Equal</span>\n    </button>\n\n    <button mat-menu-item disableRipple >\n        <mat-icon>chevron_right</mat-icon>\n        <span>Greater than</span>\n    </button>\n    \n    <button mat-menu-item disableRipple >\n        <mat-icon>last_page</mat-icon>\n        <span>Greater Equal</span>\n    </button>\n</mat-menu>\n\n<mat-menu #slicerMenu=\"matMenu\" class=\"ngm-density__compact\">\n    <button mat-menu-item disableRipple >\n      <mat-icon>dvr</mat-icon>\n      <span>\u663E\u793A\u4E3A...</span>\n    </button>\n</mat-menu>", 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: "component", type: i3.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i3.MatLabel, selector: "mat-label" }, { kind: "directive", type: i3.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "component", type: i4.MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "component", type: i5.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "component", type: i6.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: i7.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: i7.MatMenuItem, selector: "[mat-menu-item]", inputs: ["role", "disabled", "disableRipple"], exportAs: ["matMenuItem"] }, { kind: "directive", type: i7.MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", inputs: ["mat-menu-trigger-for", "matMenuTriggerFor", "matMenuTriggerData", "matMenuTriggerRestoreFocus"], outputs: ["menuOpened", "onMenuOpen", "menuClosed", "onMenuClose"], exportAs: ["matMenuTrigger"] }, { kind: "component", type: i8.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i9.DensityDirective, selector: "[displayDensity]", inputs: ["displayDensity"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SlicerSelectComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ngm-slicer-select', host: {
                        class: 'ngm-slicer-select'
                    }, providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            multi: true,
                            useExisting: forwardRef(() => SlicerSelectComponent)
                        }
                    ], template: "<mat-form-field fxFlex=\"100\" [appearance]=\"appearance\">\n  <mat-label>Select</mat-label>\n  <mat-select [formControl]=\"formControl\">\n    <mat-option *ngFor=\"let property of dimensions$ | async\" [value]=\"property.__id__\">\n        <button *ngIf=\"property.role === AggregationRole.hierarchy\" mat-icon-button displayDensity=\"compact\" disabled></button>\n        {{property.caption || property.name}}\n    </mat-option>\n  </mat-select>\n\n  <div matSuffix>\n    <button mat-icon-button  [matMenuTriggerFor]=\"operatorMenu\"\n        (click)=\"$event.stopPropagation();$event.preventDefault();\">\n        <mat-icon>drag_handle</mat-icon>\n    </button>\n\n    <button mat-icon-button matSuffix [matMenuTriggerFor]=\"slicerMenu\"\n        (click)=\"$event.stopPropagation();$event.preventDefault();\">\n        <mat-icon>more_vert</mat-icon>\n    </button>\n\n    <ng-content></ng-content>\n  </div>\n  \n</mat-form-field>\n\n<mat-menu #operatorMenu=\"matMenu\" class=\"ngm-density__compact\">\n    <button mat-menu-item disableRipple >\n      <mat-icon>dvr</mat-icon>\n      <span>Equal</span>\n    </button>\n    <button mat-menu-item disableRipple >\n        <mat-icon>chevron_left</mat-icon>\n        <span>Less than</span>\n    </button>\n\n    <button mat-menu-item disableRipple >\n        <mat-icon>first_page</mat-icon>\n        <span>Less Equal</span>\n    </button>\n\n    <button mat-menu-item disableRipple >\n        <mat-icon>chevron_right</mat-icon>\n        <span>Greater than</span>\n    </button>\n    \n    <button mat-menu-item disableRipple >\n        <mat-icon>last_page</mat-icon>\n        <span>Greater Equal</span>\n    </button>\n</mat-menu>\n\n<mat-menu #slicerMenu=\"matMenu\" class=\"ngm-density__compact\">\n    <button mat-menu-item disableRipple >\n      <mat-icon>dvr</mat-icon>\n      <span>\u663E\u793A\u4E3A...</span>\n    </button>\n</mat-menu>" }]
        }], ctorParameters: () => [], propDecorators: { appearance: [{
                type: Input
            }], slicer: [{
                type: Input
            }], entitySet: [{
                type: Input
            }] } });

class NgmSlicerPipe {
    transform(value, ...args) {
        const slicers = Array.isArray(value) ? value : value ? [value] : [];
        return slicers.map((slicer) => slicerAsString(slicer)).join(';');
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgmSlicerPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
    static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: NgmSlicerPipe, isStandalone: true, name: "slicer" }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NgmSlicerPipe, decorators: [{
            type: Pipe,
            args: [{
                    standalone: true,
                    name: 'slicer'
                }]
        }] });

class SortByComponent {
    get entitySet() {
        return this.entitySet$.value;
    }
    set entitySet(value) {
        this.entitySet$.next(value);
    }
    constructor() {
        this.AggregationRole = AggregationRole;
        this.appearance = 'fill';
        this.entitySet$ = new BehaviorSubject(null);
        this.dimensions$ = this.entitySet$.pipe(map((entitySet) => getEntityDimensions(entitySet?.entityType)));
        this.formGroup = new FormGroup({
            by: new FormControl(null),
            order: new FormControl(null)
        });
    }
    ngOnInit() { }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SortByComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: SortByComponent, selector: "ngm-sort-by", inputs: { appearance: "appearance", entitySet: "entitySet" }, ngImport: i0, template: "", styles: [""] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SortByComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ngm-sort-by', template: "" }]
        }], ctorParameters: () => [], propDecorators: { appearance: [{
                type: Input
            }], entitySet: [{
                type: Input
            }] } });

class SlicersModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SlicersModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: SlicersModule, declarations: [SlicerSelectComponent, SortByComponent], imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            TranslateModule,
            MatFormFieldModule,
            MatSelectModule,
            MatButtonModule,
            MatMenuModule,
            MatIconModule,
            OcapCoreModule,
            NgmSlicerPipe], exports: [SlicerSelectComponent, SortByComponent, NgmSlicerPipe] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SlicersModule, imports: [CommonModule,
            FormsModule,
            ReactiveFormsModule,
            TranslateModule,
            MatFormFieldModule,
            MatSelectModule,
            MatButtonModule,
            MatMenuModule,
            MatIconModule,
            OcapCoreModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SlicersModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        TranslateModule,
                        MatFormFieldModule,
                        MatSelectModule,
                        MatButtonModule,
                        MatMenuModule,
                        MatIconModule,
                        OcapCoreModule,
                        NgmSlicerPipe
                    ],
                    exports: [SlicerSelectComponent, SortByComponent, NgmSlicerPipe],
                    declarations: [SlicerSelectComponent, SortByComponent],
                    providers: []
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { NgmSlicerPipe, SlicerSelectComponent, SlicersModule, SortByComponent };
//# sourceMappingURL=metad-ocap-angular-slicers.mjs.map
