import { Component, computed, Input, viewChild, } from '@angular/core';
import { currencies } from '@seniorsistemas/angular-components/currency';
import { InputMask } from 'primeng/inputmask';
import { first } from 'rxjs/operators';
import { BaseFieldComponent } from '../base-field-component';
import * as i0 from "@angular/core";
import * as i1 from "@seniorsistemas/angular-components/currency";
import * as i2 from "@seniorsistemas/angular-components/locale";
import * as i3 from "@angular/common";
import * as i4 from "@angular/forms";
import * as i5 from "primeng/inputmask";
import * as i6 from "@seniorsistemas/angular-components/tooltip";
import * as i7 from "@seniorsistemas/angular-components/number-input";
import * as i8 from "../../../components/field-label/field-label.component";
/**
 * @deprecated Should use bignumber instead
 */
export class CurrencyFieldComponent extends BaseFieldComponent {
    currencyService;
    localeService;
    changeDetectorRef;
    inputRefComponent = viewChild('inputRef');
    field;
    formControl;
    currencies = currencies;
    mask;
    inputRef = computed(() => {
        const inputRef = this.inputRefComponent();
        if (!inputRef) {
            return undefined;
        }
        if (inputRef instanceof InputMask) {
            return inputRef.input;
        }
        else {
            return inputRef.nativeElement;
        }
    });
    constructor(currencyService, localeService, changeDetectorRef) {
        super();
        this.currencyService = currencyService;
        this.localeService = localeService;
        this.changeDetectorRef = changeDetectorRef;
    }
    ngOnInit() {
        this.onLocaleService();
        this.mask = typeof this.field.mask === 'function' ? this.field.mask() : this.field.mask;
    }
    ngAfterViewInit() {
        this.changeDetectorRef.detectChanges();
    }
    onLocaleService() {
        this.localeService
            .getLocale()
            .pipe(first())
            .subscribe({
            next: () => {
                if (!this.field.numberLocaleOptions?.decimalSeparator) {
                    this.field.numberLocaleOptions = {
                        currencySymbol: this.field.numberLocaleOptions?.currencySymbol,
                        thousandsSeparator: this.field.numberLocaleOptions?.thousandsSeparator,
                        decimalSeparator: this.localeService.getDecimalSeparator(),
                    };
                }
                if (!this.field.numberLocaleOptions?.thousandsSeparator) {
                    this.field.numberLocaleOptions = {
                        currencySymbol: this.field.numberLocaleOptions.currencySymbol,
                        decimalSeparator: this.field.numberLocaleOptions.decimalSeparator,
                        thousandsSeparator: this.localeService.getGroupingSeparator(),
                    };
                }
                if (!this.field.numberLocaleOptions?.currencySymbol) {
                    this.field.numberLocaleOptions = {
                        decimalSeparator: this.field.numberLocaleOptions.decimalSeparator,
                        thousandsSeparator: this.field.numberLocaleOptions.thousandsSeparator,
                        currencySymbol: 'R$',
                    };
                }
            },
            error: () => (this.field.numberLocaleOptions = this.field.numberLocaleOptions ?? {
                thousandsSeparator: '.',
                decimalSeparator: ',',
                currencySymbol: 'R$',
            }),
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CurrencyFieldComponent, deps: [{ token: i1.CurrencyService }, { token: i2.LocaleService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: CurrencyFieldComponent, selector: "ng-component", inputs: { field: "field", formControl: "formControl" }, viewQueries: [{ propertyName: "inputRefComponent", first: true, predicate: ["inputRef"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0, template: "@if (inputRef()) {\n    <s-field-label\n        [field]=\"field\"\n        [fieldContainerRef]=\"inputRef()\"\n    ></s-field-label>\n}\n@let hasMask = !!field.mask;\n<div\n    class=\"[input-is-invalid>.button-container>.button-container]:border-[1px] [input-is-invalid>.button-container>.button-container]:border-r-0 [input-is-invalid>.button-container>.button-container]:border-criticality-red [input-is-invalid>.button-container>input]:border-[1px] [input-is-invalid>.button-container>input]:border-criticality-red [input-has-focus>.button-container]:border-[1px] [input-has-focus>.button-container]:border-r-0 [input-has-focus>.button-container]:border-primary flex h-[35px] w-full\"\n    [ngClass]=\"{\n        '[&:has(.input-mask.ng-invalid.ng-dirty)>.button-container]:border-[1px] [&:has(.input-mask.ng-invalid.ng-dirty)>.button-container]:border-r-0 [&:has(.input-mask.ng-invalid.ng-dirty)>.button-container]:border-criticality-red [&:has(.input-mask.ng-invalid.ng-dirty)>input]:border-[1px] [&:has(.input-mask.ng-invalid.ng-dirty)>input]:border-criticality-red':\n            hasMask,\n    }\"\n>\n    @if (field.currency || field.numberLocaleOptions?.currencySymbol) {\n        <div\n            class=\"button-container flex h-full min-w-10 items-center justify-center rounded-l-[3px] border border-r-0 border-[#c1c1cc] px-[8px]\"\n        >\n            <span class=\"text-[#212533]\">\n                {{\n                    field.currency\n                        ? currencyService.getCurrencySymbol({ currency: field.currency() })\n                        : field.numberLocaleOptions?.currencySymbol\n                }}\n            </span>\n        </div>\n    }\n\n    @if (hasMask) {\n        <p-inputMask\n            class=\"input-mask\"\n            #inputRef\n            type=\"text\"\n            [inputId]=\"field.id || field.name\"\n            [name]=\"field.name\"\n            [formControl]=\"formControl\"\n            [mask]=\"mask\"\n            [placeholder]=\"field.placeholder\"\n            slotChar=\"_\"\n            [sTooltip]=\"field.tooltip\"\n            tooltipPosition=\"top\"\n            [showDelay]=\"500\"\n            styleClass=\"mousetrap !rounded-l-[0px]\"\n            (onBlur)=\"field.onBlur ? field.onBlur($event) : null\"\n            (onFocus)=\"field.onFocus ? field.onFocus($event) : null\"\n            (onComplete)=\"field.onComplete ? field.onComplete($event) : null\"\n            (onInput)=\"field.onInput ? field.onInput($event) : null\"\n        ></p-inputMask>\n    } @else if (!hasMask) {\n        <input\n            #inputRef\n            type=\"text\"\n            [id]=\"field.id || field.name\"\n            class=\"h-full w-full rounded-r-[3px] border border-[#c1c1cc] p-2 outline-none focus:border-[1px] focus:border-primary\"\n            [name]=\"field.name\"\n            [formControl]=\"formControl\"\n            sNumberInput\n            [precision]=\"\n                field.precision\n                    ? isFunction(field.precision)\n                        ? trigger(field.precision)\n                        : field.precision\n                    : field.currency && field.currency()\n                      ? currencies[field.currency()].precision\n                      : 15\n            \"\n            [scale]=\"\n                field.scale\n                    ? isFunction(field.scale)\n                        ? trigger(field.scale)\n                        : field.scale\n                    : field.currency && field.currency()\n                      ? currencies[field.currency()].scale\n                      : 2\n            \"\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            [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n            [ngClass]=\"'mousetrap'\"\n            (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n            (focus)=\"field.onFocus ? field.onFocus($event) : null\"\n        />\n    }\n</div>\n", dependencies: [{ kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.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: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "component", type: i5.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: i4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i6.TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "directive", type: i7.NumberInputDirective, selector: "input[sNumberInput]", inputs: ["precision", "scale", "decimalSeparator", "thousandsSeparator", "alignTo", "allowNegative", "placeholder"], outputs: ["pasteRejected"] }, { kind: "component", type: i8.FieldLabelComponent, selector: "s-field-label", inputs: ["field", "fieldContainerRef"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CurrencyFieldComponent, decorators: [{
            type: Component,
            args: [{ template: "@if (inputRef()) {\n    <s-field-label\n        [field]=\"field\"\n        [fieldContainerRef]=\"inputRef()\"\n    ></s-field-label>\n}\n@let hasMask = !!field.mask;\n<div\n    class=\"[input-is-invalid>.button-container>.button-container]:border-[1px] [input-is-invalid>.button-container>.button-container]:border-r-0 [input-is-invalid>.button-container>.button-container]:border-criticality-red [input-is-invalid>.button-container>input]:border-[1px] [input-is-invalid>.button-container>input]:border-criticality-red [input-has-focus>.button-container]:border-[1px] [input-has-focus>.button-container]:border-r-0 [input-has-focus>.button-container]:border-primary flex h-[35px] w-full\"\n    [ngClass]=\"{\n        '[&:has(.input-mask.ng-invalid.ng-dirty)>.button-container]:border-[1px] [&:has(.input-mask.ng-invalid.ng-dirty)>.button-container]:border-r-0 [&:has(.input-mask.ng-invalid.ng-dirty)>.button-container]:border-criticality-red [&:has(.input-mask.ng-invalid.ng-dirty)>input]:border-[1px] [&:has(.input-mask.ng-invalid.ng-dirty)>input]:border-criticality-red':\n            hasMask,\n    }\"\n>\n    @if (field.currency || field.numberLocaleOptions?.currencySymbol) {\n        <div\n            class=\"button-container flex h-full min-w-10 items-center justify-center rounded-l-[3px] border border-r-0 border-[#c1c1cc] px-[8px]\"\n        >\n            <span class=\"text-[#212533]\">\n                {{\n                    field.currency\n                        ? currencyService.getCurrencySymbol({ currency: field.currency() })\n                        : field.numberLocaleOptions?.currencySymbol\n                }}\n            </span>\n        </div>\n    }\n\n    @if (hasMask) {\n        <p-inputMask\n            class=\"input-mask\"\n            #inputRef\n            type=\"text\"\n            [inputId]=\"field.id || field.name\"\n            [name]=\"field.name\"\n            [formControl]=\"formControl\"\n            [mask]=\"mask\"\n            [placeholder]=\"field.placeholder\"\n            slotChar=\"_\"\n            [sTooltip]=\"field.tooltip\"\n            tooltipPosition=\"top\"\n            [showDelay]=\"500\"\n            styleClass=\"mousetrap !rounded-l-[0px]\"\n            (onBlur)=\"field.onBlur ? field.onBlur($event) : null\"\n            (onFocus)=\"field.onFocus ? field.onFocus($event) : null\"\n            (onComplete)=\"field.onComplete ? field.onComplete($event) : null\"\n            (onInput)=\"field.onInput ? field.onInput($event) : null\"\n        ></p-inputMask>\n    } @else if (!hasMask) {\n        <input\n            #inputRef\n            type=\"text\"\n            [id]=\"field.id || field.name\"\n            class=\"h-full w-full rounded-r-[3px] border border-[#c1c1cc] p-2 outline-none focus:border-[1px] focus:border-primary\"\n            [name]=\"field.name\"\n            [formControl]=\"formControl\"\n            sNumberInput\n            [precision]=\"\n                field.precision\n                    ? isFunction(field.precision)\n                        ? trigger(field.precision)\n                        : field.precision\n                    : field.currency && field.currency()\n                      ? currencies[field.currency()].precision\n                      : 15\n            \"\n            [scale]=\"\n                field.scale\n                    ? isFunction(field.scale)\n                        ? trigger(field.scale)\n                        : field.scale\n                    : field.currency && field.currency()\n                      ? currencies[field.currency()].scale\n                      : 2\n            \"\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            [autocomplete]=\"field.browserAutocomplete ? 'on' : 'off'\"\n            [ngClass]=\"'mousetrap'\"\n            (blur)=\"field.onBlur ? field.onBlur($event) : null\"\n            (focus)=\"field.onFocus ? field.onFocus($event) : null\"\n        />\n    }\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.CurrencyService }, { type: i2.LocaleService }, { type: i0.ChangeDetectorRef }], propDecorators: { field: [{
                type: Input,
                args: [{ required: true }]
            }], formControl: [{
                type: Input,
                args: [{ required: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 