import { Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation, } from '@angular/core';
import { Subject } from 'rxjs';
import { first, takeUntil } from 'rxjs/operators';
import { isNullOrUndefined } from '@seniorsistemas/angular-components/utils';
import { FieldType } from '../../configurations/field-type';
import { BaseFieldComponent } from '../base-field-component';
import * as i0 from "@angular/core";
import * as i1 from "@seniorsistemas/angular-components/locale";
import * as i2 from "@seniorsistemas/angular-components/bignumber-input";
import * as i3 from "@seniorsistemas/angular-components/button";
import * as i4 from "@angular/common";
import * as i5 from "@angular/forms";
import * as i6 from "primeng/inputmask";
import * as i7 from "primeng/inputtext";
import * as i8 from "@seniorsistemas/angular-components/tooltip";
import * as i9 from "../../../components/field-label/field-label.component";
export class BignumberFieldComponent extends BaseFieldComponent {
    localeService;
    changeDetectorRef;
    field;
    formControl;
    onInput = new EventEmitter();
    onFocus = new EventEmitter();
    onComplete = new EventEmitter();
    inputRef = null;
    ngUnsubscribe = new Subject();
    constructor(localeService, changeDetectorRef) {
        super();
        this.localeService = localeService;
        this.changeDetectorRef = changeDetectorRef;
    }
    ngOnInit() {
        this.onLocaleService();
        this.onFocus.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (this.field.onFocus) {
                this.field.onFocus(event);
            }
        });
        this.onInput.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (this.field.onInput) {
                this.field.onInput(event);
            }
        });
        this.onComplete.pipe(takeUntil(this.ngUnsubscribe)).subscribe((event) => {
            if (this.field.onComplete) {
                this.field.onComplete(event);
            }
        });
        this.onScale();
    }
    ngAfterViewInit() {
        this.changeDetectorRef.detectChanges();
    }
    ngOnDestroy() {
        this.ngUnsubscribe.next();
        this.ngUnsubscribe.complete();
    }
    get fieldType() {
        return FieldType;
    }
    onLocaleService() {
        this.localeService
            .getLocale()
            .pipe(first())
            .subscribe({
            next: () => {
                if (!this.field.numberLocaleOptions?.decimalSeparator) {
                    this.field.numberLocaleOptions = {
                        ...this.field.numberLocaleOptions,
                        decimalSeparator: this.localeService.getDecimalSeparator() ?? '',
                    };
                }
                if (!this.field.numberLocaleOptions?.thousandsSeparator) {
                    this.field.numberLocaleOptions = {
                        ...this.field.numberLocaleOptions,
                        thousandsSeparator: this.localeService.getGroupingSeparator() ?? '',
                    };
                }
                if (!this.field.numberLocaleOptions?.currencySymbol) {
                    this.field.numberLocaleOptions = {
                        ...this.field.numberLocaleOptions,
                        currencySymbol: this.field.type === FieldType.Integer || this.field.type === FieldType.Double
                            ? ''
                            : 'R$',
                    };
                }
            },
            error: () => (this.field.numberLocaleOptions = this.field.numberLocaleOptions ?? {
                thousandsSeparator: '.',
                decimalSeparator: ',',
                currencySymbol: this.field.type === FieldType.Integer || this.field.type === FieldType.Double ? '' : 'R$',
            }),
        });
    }
    onScale() {
        // Currently, this component is used for the following types
        // FieldType.Number, FieldType.Integer and FieldType.Double
        if (isNullOrUndefined(this.field.scale)) {
            this.field.scale = this.field.type === FieldType.Integer ? 0 : 2;
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BignumberFieldComponent, deps: [{ token: i1.LocaleService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: BignumberFieldComponent, selector: "ng-component", inputs: { field: "field", formControl: "formControl" }, outputs: { onInput: "onInput", onFocus: "onFocus", onComplete: "onComplete" }, viewQueries: [{ propertyName: "inputRef", first: true, predicate: ["inputRef"], descendants: true }], usesInheritance: true, ngImport: i0, template: "@if (inputRef) {\n    <s-field-label\n        [field]=\"field\"\n        [fieldContainerRef]=\"inputRef!.nativeElement\"\n    />\n}\n@if (field.mask) {\n    <p-inputMask\n        #inputRef\n        type=\"text\"\n        [inputId]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [mask]=\"getFieldPropertyMask(field.mask)\"\n        [placeholder]=\"field.placeholder\"\n        slotChar=\"_\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [showDelay]=\"500\"\n        styleClass=\"mousetrap\"\n        (onBlur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (onFocus)=\"onFocus.next($event)\"\n        (onComplete)=\"onComplete.next($event)\"\n        (onInput)=\"onInput.next($event)\"\n        [formControl]=\"formControl\"\n        [autoClear]=\"field.autoClear\"\n    >\n    </p-inputMask>\n} @else {\n    <div class=\"ui-inputgroup\">\n        @if (field.leftAddon) {\n            @if (field.leftAddon.callback) {\n                <span class=\"addon-button addon-button--left\">\n                    <s-button\n                        [label]=\"field.leftAddon.label\"\n                        [iconClass]=\"field.leftAddon.icon\"\n                        [priority]=\"field.leftAddon.priority\"\n                        [disabled]=\"fieldPropertyIsDisabled(field.leftAddon)\"\n                        (clicked)=\"field.leftAddon.callback()\"\n                    >\n                    </s-button>\n                </span>\n            }\n            @if (!field.leftAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.leftAddon.label) {\n                        <span>\n                            {{ field.leftAddon.label }}\n                        </span>\n                    }\n                    @if (!field.leftAddon.label) {\n                        <span [ngClass]=\"field.leftAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n        <input\n            #inputRef\n            [id]=\"field.id || field.name\"\n            type=\"text\"\n            [name]=\"field.name\"\n            sBignumberInput\n            [allowNegative]=\"field.allowNegative\"\n            [precision]=\"isFunction(field.precision) ? trigger(field.precision) : field.precision\"\n            [scale]=\"isFunction(field.scale) ? trigger(field.scale) : field.scale\"\n            [decimalSeparator]=\"field.numberLocaleOptions?.decimalSeparator\"\n            [thousandsSeparator]=\"field.numberLocaleOptions?.thousandsSeparator\"\n            [alignTo]=\"field.alignTo\"\n            [sTooltip]=\"field.tooltip\"\n            tooltipPosition=\"top\"\n            [placeholder]=\"field.placeholder\"\n            [showDelay]=\"500\"\n            pInputText\n            [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n            [ngClass]=\"'mousetrap'\"\n            (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n            (focus)=\"onFocus.next($event)\"\n            [formControl]=\"formControl\"\n        />\n        @if (field.rightAddon) {\n            @if (field.rightAddon.callback) {\n                <span class=\"addon-button addon-button--right\">\n                    <s-button\n                        [label]=\"field.rightAddon.label\"\n                        [iconClass]=\"field.rightAddon.icon\"\n                        [priority]=\"field.rightAddon.priority!\"\n                        [disabled]=\"fieldPropertyIsDisabled(field.rightAddon)\"\n                        (clicked)=\"field.rightAddon.callback()\"\n                    >\n                    </s-button>\n                </span>\n            }\n            @if (!field.rightAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.rightAddon.label) {\n                        <span>\n                            {{ field.rightAddon.label }}\n                        </span>\n                    } @else {\n                        <span [ngClass]=\"field.rightAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n    </div>\n}\n", styles: ["s-number-field.ng-dirty.ng-invalid .ui-inputtext{border-color:#c13018}s-number-field.ng-dirty.ng-invalid .ui-inputtext:hover{border-color:highlight(#c13018)}.addon-button{border:1px solid #c1c1cc}.addon-button s-button button,.addon-button s-button .s-button-with-text{height:100%;min-width:40px!important}.addon-button--left{border-radius:5px 0 0 5px;border-right:none}.addon-button--left s-button button{border-bottom-right-radius:0;border-top-right-radius:0}.addon-button--right{border-left:none;border-radius:0 5px 5px 0}.addon-button--right s-button button{border-bottom-left-radius:0;border-top-left-radius:0}\n"], dependencies: [{ kind: "directive", type: i2.BignumberInputDirective, selector: "input[sBignumberInput]", inputs: ["precision", "scale", "decimalSeparator", "thousandsSeparator", "alignTo", "allowNegative", "placeholder"], outputs: ["pasteRejected"] }, { kind: "component", type: i3.ButtonComponent, selector: "s-button", inputs: ["id", "label", "tooltip", "tooltipPosition", "iconClass", "rightIconClass", "caret", "styleClass", "baseZIndex", "disabled", "auxiliary", "type", "priority", "menuOptions", "size", "slide", "animation", "badge", "iconColor"], outputs: ["clicked"] }, { kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i5.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "component", type: i6.InputMask, selector: "p-inputmask, p-inputMask, p-input-mask", inputs: ["type", "slotChar", "autoClear", "showClear", "style", "inputId", "styleClass", "placeholder", "size", "maxlength", "tabindex", "title", "variant", "ariaLabel", "ariaLabelledBy", "ariaRequired", "disabled", "readonly", "unmask", "name", "required", "characterPattern", "autofocus", "autoFocus", "autocomplete", "keepBuffer", "mask"], outputs: ["onComplete", "onFocus", "onBlur", "onInput", "onKeydown", "onClear"] }, { kind: "directive", type: i7.InputText, selector: "[pInputText]", inputs: ["variant", "fluid", "pSize"] }, { kind: "directive", type: i5.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i8.TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "component", type: i9.FieldLabelComponent, selector: "s-field-label", inputs: ["field", "fieldContainerRef"] }], encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: BignumberFieldComponent, decorators: [{
            type: Component,
            args: [{ encapsulation: ViewEncapsulation.None, template: "@if (inputRef) {\n    <s-field-label\n        [field]=\"field\"\n        [fieldContainerRef]=\"inputRef!.nativeElement\"\n    />\n}\n@if (field.mask) {\n    <p-inputMask\n        #inputRef\n        type=\"text\"\n        [inputId]=\"field.id || field.name\"\n        [name]=\"field.name\"\n        [mask]=\"getFieldPropertyMask(field.mask)\"\n        [placeholder]=\"field.placeholder\"\n        slotChar=\"_\"\n        [sTooltip]=\"field.tooltip\"\n        tooltipPosition=\"top\"\n        [showDelay]=\"500\"\n        styleClass=\"mousetrap\"\n        (onBlur)=\"field.onBlur ? field.onBlur($event) : null\"\n        (onFocus)=\"onFocus.next($event)\"\n        (onComplete)=\"onComplete.next($event)\"\n        (onInput)=\"onInput.next($event)\"\n        [formControl]=\"formControl\"\n        [autoClear]=\"field.autoClear\"\n    >\n    </p-inputMask>\n} @else {\n    <div class=\"ui-inputgroup\">\n        @if (field.leftAddon) {\n            @if (field.leftAddon.callback) {\n                <span class=\"addon-button addon-button--left\">\n                    <s-button\n                        [label]=\"field.leftAddon.label\"\n                        [iconClass]=\"field.leftAddon.icon\"\n                        [priority]=\"field.leftAddon.priority\"\n                        [disabled]=\"fieldPropertyIsDisabled(field.leftAddon)\"\n                        (clicked)=\"field.leftAddon.callback()\"\n                    >\n                    </s-button>\n                </span>\n            }\n            @if (!field.leftAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.leftAddon.label) {\n                        <span>\n                            {{ field.leftAddon.label }}\n                        </span>\n                    }\n                    @if (!field.leftAddon.label) {\n                        <span [ngClass]=\"field.leftAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n        <input\n            #inputRef\n            [id]=\"field.id || field.name\"\n            type=\"text\"\n            [name]=\"field.name\"\n            sBignumberInput\n            [allowNegative]=\"field.allowNegative\"\n            [precision]=\"isFunction(field.precision) ? trigger(field.precision) : field.precision\"\n            [scale]=\"isFunction(field.scale) ? trigger(field.scale) : field.scale\"\n            [decimalSeparator]=\"field.numberLocaleOptions?.decimalSeparator\"\n            [thousandsSeparator]=\"field.numberLocaleOptions?.thousandsSeparator\"\n            [alignTo]=\"field.alignTo\"\n            [sTooltip]=\"field.tooltip\"\n            tooltipPosition=\"top\"\n            [placeholder]=\"field.placeholder\"\n            [showDelay]=\"500\"\n            pInputText\n            [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n            [ngClass]=\"'mousetrap'\"\n            (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n            (focus)=\"onFocus.next($event)\"\n            [formControl]=\"formControl\"\n        />\n        @if (field.rightAddon) {\n            @if (field.rightAddon.callback) {\n                <span class=\"addon-button addon-button--right\">\n                    <s-button\n                        [label]=\"field.rightAddon.label\"\n                        [iconClass]=\"field.rightAddon.icon\"\n                        [priority]=\"field.rightAddon.priority!\"\n                        [disabled]=\"fieldPropertyIsDisabled(field.rightAddon)\"\n                        (clicked)=\"field.rightAddon.callback()\"\n                    >\n                    </s-button>\n                </span>\n            }\n            @if (!field.rightAddon.callback) {\n                <span class=\"ui-inputgroup-addon\">\n                    @if (field.rightAddon.label) {\n                        <span>\n                            {{ field.rightAddon.label }}\n                        </span>\n                    } @else {\n                        <span [ngClass]=\"field.rightAddon.icon\"></span>\n                    }\n                </span>\n            }\n        }\n    </div>\n}\n", styles: ["s-number-field.ng-dirty.ng-invalid .ui-inputtext{border-color:#c13018}s-number-field.ng-dirty.ng-invalid .ui-inputtext:hover{border-color:highlight(#c13018)}.addon-button{border:1px solid #c1c1cc}.addon-button s-button button,.addon-button s-button .s-button-with-text{height:100%;min-width:40px!important}.addon-button--left{border-radius:5px 0 0 5px;border-right:none}.addon-button--left s-button button{border-bottom-right-radius:0;border-top-right-radius:0}.addon-button--right{border-left:none;border-radius:0 5px 5px 0}.addon-button--right s-button button{border-bottom-left-radius:0;border-top-left-radius:0}\n"] }]
        }], ctorParameters: () => [{ type: i1.LocaleService }, { type: i0.ChangeDetectorRef }], propDecorators: { field: [{
                type: Input,
                args: [{ required: true }]
            }], formControl: [{
                type: Input,
                args: [{ required: true }]
            }], onInput: [{
                type: Output
            }], onFocus: [{
                type: Output
            }], onComplete: [{
                type: Output
            }], inputRef: [{
                type: ViewChild,
                args: ['inputRef']
            }] } });
//# sourceMappingURL=data:application/json;base64, 