import { Component, Input } from "@angular/core";
import { FormGroup } from "@angular/forms";
import { first } from "rxjs/operators";
import * as i0 from "@angular/core";
import * as i1 from "@seniorsistemas/angular-components/locale";
import * as i2 from "@angular/common";
import * as i3 from "@angular/forms";
import * as i4 from "@seniorsistemas/angular-components/bignumber-input";
import * as i5 from "@seniorsistemas/angular-components/button";
import * as i6 from "@seniorsistemas/angular-components/tooltip";
import * as i7 from "primeng/inputmask";
import * as i8 from "primeng/inputtext";
export class InlineEditNumberComponent {
    localeService;
    field;
    formGroup = new FormGroup({});
    tempValue = '';
    constructor(localeService) {
        this.localeService = localeService;
    }
    ngOnInit() {
        this._onLocaleService();
        if (this.formGroup && this.field) {
            this.tempValue = this.formGroup.get(this.field.name)?.value || '';
        }
    }
    saveValue() {
        if (this.formGroup && this.field) {
            this.formGroup.get(this.field.name)?.setValue(this.tempValue);
        }
    }
    get mask() {
        return typeof this.field.mask === 'function' ? this.field.mask() : this.field.mask;
    }
    get leftAddonDisabled() {
        return typeof this.field.leftAddon?.disabled === 'function' ? this.field.leftAddon.disabled() : this.field.leftAddon?.disabled;
    }
    get rightAddonDisabled() {
        return typeof this.field.rightAddon?.disabled === 'function' ? this.field.rightAddon.disabled() : this.field.rightAddon?.disabled;
    }
    get precision() {
        return typeof this.field.precision === 'function' ? this.field.precision() : this.field.precision;
    }
    get scale() {
        return typeof this.field.scale === 'function' ? this.field.scale() : this.field.scale;
    }
    _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(),
                    };
                }
            },
            error: () => (this.field.numberLocaleOptions = {
                thousandsSeparator: ".",
                decimalSeparator: ",",
                currencySymbol: "",
            }),
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InlineEditNumberComponent, deps: [{ token: i1.LocaleService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: InlineEditNumberComponent, selector: "ng-component", inputs: { field: "field", formGroup: "formGroup" }, ngImport: i0, template: "<p-inputMask\n    *ngIf=\"field.mask; else noMask\"\n    type=\"text\"\n    [inputId]=\"field.name\"\n    [name]=\"field.name\"\n    [mask]=\"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)=\"field.onFocus ? field.onFocus($event) : null\"\n    (onComplete)=\"field.onComplete ? field.onComplete($event) : null\"\n    (onInput)=\"field.onInput ? field.onInput($event) : null\"\n    [autoClear]=\"field.autoClear\"\n    [(ngModel)]=\"tempValue\">\n</p-inputMask>\n\n<ng-template #noMask>\n    <ng-container>\n        <div class=\"ui-inputgroup\">\n            <ng-container *ngIf=\"field.leftAddon\">\n                <span *ngIf=\"field.leftAddon.callback\" 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]=\"leftAddonDisabled\"\n                        (clicked)=\"field.leftAddon.callback()\">\n                    </s-button>\n                </span>\n                <span *ngIf=\"!field.leftAddon.callback\" class=\"ui-inputgroup-addon\">\n                    <span *ngIf=\"field.leftAddon.label\">{{ field.leftAddon.label }}</span>\n                    <span *ngIf=\"!field.leftAddon.label\" [ngClass]=\"field.leftAddon.icon\"></span>\n                </span>\n            </ng-container>\n\n            <input\n                [id]=\"field.name\"\n                type=\"text\"\n                [name]=\"field.name\"\n                sBignumberInput\n                [allowNegative]=\"field.allowNegative ?? false\"\n                [precision]=\"precision\"\n                [scale]=\"scale\"\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)=\"field.onFocus ? field.onFocus($event) : null\"\n                [(ngModel)]=\"tempValue\"/>\n            <ng-container *ngIf=\"field.rightAddon\">\n                <span *ngIf=\"field.rightAddon.callback\" 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]=\"rightAddonDisabled\"\n                        (clicked)=\"field.rightAddon.callback()\">\n                    </s-button>\n                </span>\n                <span *ngIf=\"!field.rightAddon.callback\" class=\"ui-inputgroup-addon\">\n                    <span *ngIf=\"field.rightAddon.label\">{{ field.rightAddon.label }}</span>\n                    <span *ngIf=\"!field.rightAddon.label\" [ngClass]=\"field.rightAddon.icon\"></span>\n                </span>\n            </ng-container>\n        </div>\n    </ng-container>\n</ng-template>\n", styles: [""], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.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: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i4.BignumberInputDirective, selector: "input[sBignumberInput]", inputs: ["precision", "scale", "decimalSeparator", "thousandsSeparator", "alignTo", "allowNegative", "placeholder"], outputs: ["pasteRejected"] }, { kind: "component", type: i5.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: i6.TooltipDirective, selector: "[sTooltip]", inputs: ["sTooltip", "tooltipPosition", "showDelay", "displayTime", "tooltipEvent", "escape", "visible", "mobileBehavior", "focusedInputRef", "checkTruncatedText"] }, { kind: "component", type: i7.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: i8.InputText, selector: "[pInputText]", inputs: ["variant", "fluid", "pSize"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InlineEditNumberComponent, decorators: [{
            type: Component,
            args: [{ template: "<p-inputMask\n    *ngIf=\"field.mask; else noMask\"\n    type=\"text\"\n    [inputId]=\"field.name\"\n    [name]=\"field.name\"\n    [mask]=\"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)=\"field.onFocus ? field.onFocus($event) : null\"\n    (onComplete)=\"field.onComplete ? field.onComplete($event) : null\"\n    (onInput)=\"field.onInput ? field.onInput($event) : null\"\n    [autoClear]=\"field.autoClear\"\n    [(ngModel)]=\"tempValue\">\n</p-inputMask>\n\n<ng-template #noMask>\n    <ng-container>\n        <div class=\"ui-inputgroup\">\n            <ng-container *ngIf=\"field.leftAddon\">\n                <span *ngIf=\"field.leftAddon.callback\" 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]=\"leftAddonDisabled\"\n                        (clicked)=\"field.leftAddon.callback()\">\n                    </s-button>\n                </span>\n                <span *ngIf=\"!field.leftAddon.callback\" class=\"ui-inputgroup-addon\">\n                    <span *ngIf=\"field.leftAddon.label\">{{ field.leftAddon.label }}</span>\n                    <span *ngIf=\"!field.leftAddon.label\" [ngClass]=\"field.leftAddon.icon\"></span>\n                </span>\n            </ng-container>\n\n            <input\n                [id]=\"field.name\"\n                type=\"text\"\n                [name]=\"field.name\"\n                sBignumberInput\n                [allowNegative]=\"field.allowNegative ?? false\"\n                [precision]=\"precision\"\n                [scale]=\"scale\"\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)=\"field.onFocus ? field.onFocus($event) : null\"\n                [(ngModel)]=\"tempValue\"/>\n            <ng-container *ngIf=\"field.rightAddon\">\n                <span *ngIf=\"field.rightAddon.callback\" 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]=\"rightAddonDisabled\"\n                        (clicked)=\"field.rightAddon.callback()\">\n                    </s-button>\n                </span>\n                <span *ngIf=\"!field.rightAddon.callback\" class=\"ui-inputgroup-addon\">\n                    <span *ngIf=\"field.rightAddon.label\">{{ field.rightAddon.label }}</span>\n                    <span *ngIf=\"!field.rightAddon.label\" [ngClass]=\"field.rightAddon.icon\"></span>\n                </span>\n            </ng-container>\n        </div>\n    </ng-container>\n</ng-template>\n" }]
        }], ctorParameters: () => [{ type: i1.LocaleService }], propDecorators: { field: [{
                type: Input,
                args: [{ required: true }]
            }], formGroup: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 