import { Component, forwardRef, inject, Input } from '@angular/core';
import { FormBuilder, FormsModule, NG_VALUE_ACCESSOR, ReactiveFormsModule, Validators } from '@angular/forms';
import { NgmDSCoreService } from '@metad/ocap-angular/core';
import { CompareToEnum } from '@metad/ocap-core';
import { PropertyCapacity } from '../types';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select';
import { NgmPropertySelectComponent } from '../property-select/property-select.component';
import { NgmCompareMemberSelectComponent } from '../compare-member-select/member-select.component';
import { MatCheckboxModule } from '@angular/material/checkbox';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "@ngx-translate/core";
import * as i4 from "@angular/material/form-field";
import * as i5 from "@angular/material/select";
import * as i6 from "@angular/material/core";
import * as i7 from "@angular/material/checkbox";
export class NgmCalculationVarianceComponent {
    constructor() {
        this.PropertyCapacity = PropertyCapacity;
        this.COMPARE_TO_ENUM = CompareToEnum;
        this.formBuilder = inject(FormBuilder);
        this.formGroup = this.formBuilder.group({
            measure: [null, Validators.required],
            baseDimension: [null, Validators.required],
            compareA: null,
            toB: null,
            asZero: null,
            asPercentage: null,
            directDivide: null,
            absBaseValue: null,
            divideBy: null
        });
        this.valueSub = this.formGroup.valueChanges.subscribe((value) => {
            this._onChange?.(value);
        });
    }
    get asPercentage() {
        return this.formGroup.value.asPercentage;
    }
    get directDivide() {
        return this.formGroup.value.directDivide;
    }
    get baseDimension() {
        return this.formGroup.value.baseDimension;
    }
    get divideBy() {
        return this.formGroup.value.divideBy;
    }
    get absBaseValue() {
        return this.formGroup.value.absBaseValue;
    }
    get expression() {
        if (this.asPercentage) {
            let divideBy = this.divideBy || 'B';
            if (this.absBaseValue) {
                divideBy = `abs(${divideBy})`;
            }
            if (this.directDivide) {
                return `A / ${divideBy}`;
            }
            return `(A - B) / ${divideBy}`;
        }
        return `(A - B)`;
    }
    writeValue(obj) {
        this.formGroup.patchValue(obj || {});
    }
    registerOnChange(fn) {
        this._onChange = fn;
    }
    registerOnTouched(fn) { }
    setDisabledState(isDisabled) { }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.10", ngImport: i0, type: NgmCalculationVarianceComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.10", type: NgmCalculationVarianceComponent, isStandalone: true, selector: "ngm-calculation-variance", inputs: { dsCoreService: "dsCoreService", dataSettings: "dataSettings", entityType: "entityType" }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                multi: true,
                useExisting: forwardRef(() => NgmCalculationVarianceComponent)
            }
        ], ngImport: i0, template: "<div class=\"text-lg font-medium mb-4\"> {{ 'Ngm.Calculation.VARIANCE_MEASURE' | translate: {Default: \"Variance Measure\"} }} </div>\n\n<form [formGroup]=\"formGroup\" class=\"flex flex-col justify-start items-stretch\">\n\n    <div class=\"flex justify-between items-center gap-4\">\n        <ngm-property-select class=\"flex-1 w-5/12\" displayDensity=\"compact\"\n            [label]=\" 'Ngm.Calculation.Measure' | translate: {Default: 'Measure'} \"\n            [dsCoreService]=\"dsCoreService\"\n            [dataSettings]=\"dataSettings\"\n            [entityType]=\"entityType\"\n            [capacities]=\"[PropertyCapacity.Measure]\"\n            [editable]=\"false\"\n            formControlName=\"measure\"\n        >\n        </ngm-property-select>\n\n        <ngm-property-select class=\"flex-1 w-5/12\" displayDensity=\"compact\"\n            [label]=\" 'Ngm.Calculation.BaseDimension' | translate: {Default: 'Base Dimension'} \"\n            [dsCoreService]=\"dsCoreService\"\n            [dataSettings]=\"dataSettings\"\n            [entityType]=\"entityType\"\n            [capacities]=\"[PropertyCapacity.Dimension]\"\n            [editable]=\"false\"\n            formControlName=\"baseDimension\"\n        >\n        </ngm-property-select>\n    </div>\n\n    <div class=\"text-base my-2\">{{expression}}</div>\n\n    <ngm-compare-member-select label=\"{{ 'Ngm.Calculation.Compare' | translate: {Default: 'Compare'} }} (A)\"\n        [dataSettings]=\"dataSettings\"\n        [entityType]=\"entityType\"\n        [dimension]=\"baseDimension\"\n        formControlName=\"compareA\"\n    />\n\n    <ngm-compare-member-select label=\"{{ 'Ngm.Calculation.To' | translate: {Default: 'To'} }} (B)\"\n        [dataSettings]=\"dataSettings\"\n        [entityType]=\"entityType\"\n        [dimension]=\"baseDimension\"\n        formControlName=\"toB\"\n    />\n\n    <mat-checkbox formControlName=\"asZero\" class=\"my-2\">\n        {{ 'Ngm.Calculation.SetNoDataasZero' | translate: {Default: \"Set No Data as Zero\"} }}\n    </mat-checkbox>\n\n    <mat-checkbox formControlName=\"asPercentage\" class=\"my-2\">\n        {{ 'Ngm.Calculation.CalculateasPercentage' | translate: {Default: \"Calculate as Percentage\"} }}\n    </mat-checkbox>\n\n    <mat-checkbox formControlName=\"directDivide\" class=\"my-2\">\n        {{ 'Ngm.Calculation.DirectDivide' | translate: {Default: \"Direct Divide\"} }}\n    </mat-checkbox>\n\n    <div *ngIf=\"asPercentage && !directDivide\" class=\"flex justify-between items-center\">\n        <mat-checkbox formControlName=\"absBaseValue\">\n            {{ 'Ngm.Calculation.AbsoluteBaseValue' | translate: {Default: \"Absolute Base Value\"} }}\n        </mat-checkbox>\n        <mat-form-field appearance=\"fill\" class=\"w-5/12\">\n            <mat-label>{{ 'Ngm.Calculation.DivideBy' | translate: {Default: \"Divide By\"} }}</mat-label>\n            <mat-select formControlName=\"divideBy\">\n              <mat-option value=\"A\">\n                {{ 'Ngm.Calculation.CompareValueA' | translate: {Default: \"Compare Value (A)\"} }}\n              </mat-option>\n              <mat-option value=\"B\">{{ 'Ngm.Calculation.ToValueB' | translate: {Default: \"To Value (B)\"} }}\n              </mat-option>\n            </mat-select>\n        </mat-form-field>\n    </div>\n\n</form>\n", styles: [":host{display:flex;flex-direction:column}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i2.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i3.TranslatePipe, name: "translate" }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i4.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i4.MatLabel, selector: "mat-label" }, { kind: "ngmodule", type: MatSelectModule }, { kind: "component", type: i5.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: i6.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "ngmodule", type: MatCheckboxModule }, { kind: "component", type: i7.MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "component", type: NgmPropertySelectComponent, selector: "ngm-property-select", inputs: ["label", "capacities", "required", "editable", "showAttributes", "dataSettings", "entityType", "restrictedDimensions", "dsCoreService", "syntax", "disabled", "displayDensity"], outputs: ["valueChange", "calculationChange"] }, { kind: "component", type: NgmCompareMemberSelectComponent, selector: "ngm-compare-member-select", inputs: ["appearance", "label", "dataSettings", "entityType", "dimension", "disabled"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.10", ngImport: i0, type: NgmCalculationVarianceComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, imports: [
                        CommonModule,
                        FormsModule,
                        ReactiveFormsModule,
                        TranslateModule,
                        MatFormFieldModule,
                        MatSelectModule,
                        MatCheckboxModule,
                        NgmPropertySelectComponent,
                        NgmCompareMemberSelectComponent
                    ], selector: 'ngm-calculation-variance', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            multi: true,
                            useExisting: forwardRef(() => NgmCalculationVarianceComponent)
                        }
                    ], template: "<div class=\"text-lg font-medium mb-4\"> {{ 'Ngm.Calculation.VARIANCE_MEASURE' | translate: {Default: \"Variance Measure\"} }} </div>\n\n<form [formGroup]=\"formGroup\" class=\"flex flex-col justify-start items-stretch\">\n\n    <div class=\"flex justify-between items-center gap-4\">\n        <ngm-property-select class=\"flex-1 w-5/12\" displayDensity=\"compact\"\n            [label]=\" 'Ngm.Calculation.Measure' | translate: {Default: 'Measure'} \"\n            [dsCoreService]=\"dsCoreService\"\n            [dataSettings]=\"dataSettings\"\n            [entityType]=\"entityType\"\n            [capacities]=\"[PropertyCapacity.Measure]\"\n            [editable]=\"false\"\n            formControlName=\"measure\"\n        >\n        </ngm-property-select>\n\n        <ngm-property-select class=\"flex-1 w-5/12\" displayDensity=\"compact\"\n            [label]=\" 'Ngm.Calculation.BaseDimension' | translate: {Default: 'Base Dimension'} \"\n            [dsCoreService]=\"dsCoreService\"\n            [dataSettings]=\"dataSettings\"\n            [entityType]=\"entityType\"\n            [capacities]=\"[PropertyCapacity.Dimension]\"\n            [editable]=\"false\"\n            formControlName=\"baseDimension\"\n        >\n        </ngm-property-select>\n    </div>\n\n    <div class=\"text-base my-2\">{{expression}}</div>\n\n    <ngm-compare-member-select label=\"{{ 'Ngm.Calculation.Compare' | translate: {Default: 'Compare'} }} (A)\"\n        [dataSettings]=\"dataSettings\"\n        [entityType]=\"entityType\"\n        [dimension]=\"baseDimension\"\n        formControlName=\"compareA\"\n    />\n\n    <ngm-compare-member-select label=\"{{ 'Ngm.Calculation.To' | translate: {Default: 'To'} }} (B)\"\n        [dataSettings]=\"dataSettings\"\n        [entityType]=\"entityType\"\n        [dimension]=\"baseDimension\"\n        formControlName=\"toB\"\n    />\n\n    <mat-checkbox formControlName=\"asZero\" class=\"my-2\">\n        {{ 'Ngm.Calculation.SetNoDataasZero' | translate: {Default: \"Set No Data as Zero\"} }}\n    </mat-checkbox>\n\n    <mat-checkbox formControlName=\"asPercentage\" class=\"my-2\">\n        {{ 'Ngm.Calculation.CalculateasPercentage' | translate: {Default: \"Calculate as Percentage\"} }}\n    </mat-checkbox>\n\n    <mat-checkbox formControlName=\"directDivide\" class=\"my-2\">\n        {{ 'Ngm.Calculation.DirectDivide' | translate: {Default: \"Direct Divide\"} }}\n    </mat-checkbox>\n\n    <div *ngIf=\"asPercentage && !directDivide\" class=\"flex justify-between items-center\">\n        <mat-checkbox formControlName=\"absBaseValue\">\n            {{ 'Ngm.Calculation.AbsoluteBaseValue' | translate: {Default: \"Absolute Base Value\"} }}\n        </mat-checkbox>\n        <mat-form-field appearance=\"fill\" class=\"w-5/12\">\n            <mat-label>{{ 'Ngm.Calculation.DivideBy' | translate: {Default: \"Divide By\"} }}</mat-label>\n            <mat-select formControlName=\"divideBy\">\n              <mat-option value=\"A\">\n                {{ 'Ngm.Calculation.CompareValueA' | translate: {Default: \"Compare Value (A)\"} }}\n              </mat-option>\n              <mat-option value=\"B\">{{ 'Ngm.Calculation.ToValueB' | translate: {Default: \"To Value (B)\"} }}\n              </mat-option>\n            </mat-select>\n        </mat-form-field>\n    </div>\n\n</form>\n", styles: [":host{display:flex;flex-direction:column}\n"] }]
        }], propDecorators: { dsCoreService: [{
                type: Input
            }], dataSettings: [{
                type: Input
            }], entityType: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 