import * as i0 from '@angular/core';
import { input, inject, signal, effect, HostBinding, ViewChild, ChangeDetectionStrategy, Component } from '@angular/core';
import * as i1 from '@angular/forms';
import { NgControl, Validators, FormsModule } from '@angular/forms';
import * as i2 from 'primeng/inputnumber';
import { InputNumberModule } from 'primeng/inputnumber';
import { FieldValidation } from '@masterteam/components/field-validation';
import { isInvalid } from '@masterteam/components';

class NumberField {
    inputNumber;
    field = input(true, ...(ngDevMode ? [{ debugName: "field" }] : []));
    label = input(...(ngDevMode ? [undefined, { debugName: "label" }] : []));
    placeholder = input(...(ngDevMode ? [undefined, { debugName: "placeholder" }] : []));
    class = input('', ...(ngDevMode ? [{ debugName: "class" }] : []));
    readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : []));
    pInputs = input(...(ngDevMode ? [undefined, { debugName: "pInputs" }] : []));
    format = input(false, ...(ngDevMode ? [{ debugName: "format" }] : []));
    maxFractionDigits = input(2, ...(ngDevMode ? [{ debugName: "maxFractionDigits" }] : []));
    // TODO: wait for primeng to allow undefined and remove these numbers
    min = input(-999999999999999, ...(ngDevMode ? [{ debugName: "min" }] : []));
    max = input(999999999999999, ...(ngDevMode ? [{ debugName: "max" }] : []));
    required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : []));
    styleClass;
    ngControl = inject(NgControl, { self: true });
    isInvalid = isInvalid;
    requiredValidator = Validators.required;
    value = signal(null, ...(ngDevMode ? [{ debugName: "value" }] : []));
    disabled = signal(false, ...(ngDevMode ? [{ debugName: "disabled" }] : []));
    onTouched = () => { };
    onModelChange = () => { };
    constructor() {
        if (this.ngControl) {
            this.ngControl.valueAccessor = this;
        }
        effect(() => {
            if (this.ngControl.control && this.required()) {
                this.ngControl.control.addValidators(Validators.required);
                this.ngControl.control.updateValueAndValidity();
            }
        });
    }
    applyInputsToInputNumber() {
        Object.assign(this.inputNumber, this.pInputs());
    }
    ngOnInit() {
        this.styleClass = this.class();
        if (this.pInputs()) {
            this.applyInputsToInputNumber();
        }
    }
    onValueChange(value) {
        this.onModelChange(value);
        this.value.set(value);
    }
    ngOnChanges(changes) {
        if (changes['pInputs']) {
            this.applyInputsToInputNumber();
        }
    }
    writeValue(value) {
        this.value.set(value);
    }
    registerOnChange(fn) {
        this.onModelChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(disabled) {
        this.disabled.set(disabled);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: NumberField, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.3", type: NumberField, isStandalone: true, selector: "mt-number-field", inputs: { field: { classPropertyName: "field", publicName: "field", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, pInputs: { classPropertyName: "pInputs", publicName: "pInputs", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, maxFractionDigits: { classPropertyName: "maxFractionDigits", publicName: "maxFractionDigits", isSignal: true, isRequired: false, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class": "this.styleClass" }, classAttribute: "grid gap-1" }, viewQueries: [{ propertyName: "inputNumber", first: true, predicate: ["inputNumber"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "@if (label()) {\n  <label\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n    [for]=\"ngControl?.name || label()\"\n    >{{ label() }}</label\n  >\n}\n<p-inputnumber\n  #inputNumber\n  [ngModel]=\"value()\"\n  (ngModelChange)=\"onValueChange($event)\"\n  (onBlur)=\"onTouched()\"\n  [disabled]=\"disabled() || readonly()\"\n  [inputId]=\"ngControl?.name ? ngControl?.name?.toString() : label()\"\n  [format]=\"format()\"\n  [min]=\"min()\"\n  [max]=\"max()\"\n  [maxFractionDigits]=\"maxFractionDigits()\"\n  [invalid]=\"isInvalid(ngControl?.control)\"\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\n  styleClass=\"w-full\"\n  inputStyleClass=\"w-full\"\n></p-inputnumber>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n", styles: [":host p-inputNumber{display:block;width:100%}:host p-inputNumber input{width:100%}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: InputNumberModule }, { kind: "component", type: i2.InputNumber, selector: "p-inputNumber, p-inputnumber, p-input-number", inputs: ["showButtons", "format", "buttonLayout", "inputId", "styleClass", "placeholder", "tabindex", "title", "ariaLabelledBy", "ariaDescribedBy", "ariaLabel", "ariaRequired", "autocomplete", "incrementButtonClass", "decrementButtonClass", "incrementButtonIcon", "decrementButtonIcon", "readonly", "allowEmpty", "locale", "localeMatcher", "mode", "currency", "currencyDisplay", "useGrouping", "minFractionDigits", "maxFractionDigits", "prefix", "suffix", "inputStyle", "inputStyleClass", "showClear", "autofocus"], outputs: ["onInput", "onFocus", "onBlur", "onKeyDown", "onClear"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: NumberField, decorators: [{
            type: Component,
            args: [{ selector: 'mt-number-field', standalone: true, imports: [FormsModule, InputNumberModule, FieldValidation], changeDetection: ChangeDetectionStrategy.OnPush, host: {
                        class: 'grid gap-1',
                    }, template: "@if (label()) {\n  <label\n    [class.required]=\"ngControl?.control?.hasValidator(requiredValidator)\"\n    [for]=\"ngControl?.name || label()\"\n    >{{ label() }}</label\n  >\n}\n<p-inputnumber\n  #inputNumber\n  [ngModel]=\"value()\"\n  (ngModelChange)=\"onValueChange($event)\"\n  (onBlur)=\"onTouched()\"\n  [disabled]=\"disabled() || readonly()\"\n  [inputId]=\"ngControl?.name ? ngControl?.name?.toString() : label()\"\n  [format]=\"format()\"\n  [min]=\"min()\"\n  [max]=\"max()\"\n  [maxFractionDigits]=\"maxFractionDigits()\"\n  [invalid]=\"isInvalid(ngControl?.control)\"\n  placeholder=\"{{ placeholder() ?? label() ?? '' }}\"\n  styleClass=\"w-full\"\n  inputStyleClass=\"w-full\"\n></p-inputnumber>\n\n<mt-field-validation [control]=\"ngControl?.control\"></mt-field-validation>\n", styles: [":host p-inputNumber{display:block;width:100%}:host p-inputNumber input{width:100%}\n"] }]
        }], ctorParameters: () => [], propDecorators: { inputNumber: [{
                type: ViewChild,
                args: ['inputNumber', { static: true }]
            }], field: [{ type: i0.Input, args: [{ isSignal: true, alias: "field", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], class: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], pInputs: [{ type: i0.Input, args: [{ isSignal: true, alias: "pInputs", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }], maxFractionDigits: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxFractionDigits", required: false }] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], styleClass: [{
                type: HostBinding,
                args: ['class']
            }] } });

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

export { NumberField };
//# sourceMappingURL=masterteam-components-number-field.mjs.map
