import { __decorate } from "tslib";
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { LayoutEditorMetadata } from '@anglr/dynamic/layout-editor';
import { CastPipesModule, HostDisplayBlockStyle } from '@anglr/common';
import { FormPipesModule } from '@anglr/common/forms';
import { FormComponentBase, FormComponentControlSAPipe } from '@anglr/dynamic/form';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { isPresent } from '@jscrpt/common';
import { NumberFieldLayoutMetadataLoader, NumberFieldRelationsMetadataLoader } from './numberField.metadata';
import * as i0 from "@angular/core";
import * as i1 from "@anglr/common/forms";
import * as i2 from "@anglr/common";
import * as i3 from "@angular/forms";
/**
 * Component used for displaying text field
 */
let NumberFieldSAComponent = class NumberFieldSAComponent extends FormComponentBase {
    constructor() {
        super(...arguments);
        //######################### protected properties - template bindings #########################
        /**
         * Input number step value
         */
        this.step = '1';
    }
    //######################### protected methods #########################
    /**
     * @inheritdoc
     */
    onOptionsSet() {
        this.step = !this.options || !isPresent(this.options?.decimalPlaces) || this.options?.decimalPlaces == 0 ? '1' : '0.' + '0'.repeat(this.options.decimalPlaces - 1) + '1';
        super.onOptionsSet();
    }
    /**
     * Registers component-specific validators
     */
    _registerValidations() {
        if (this.options) {
            if (isPresent(this.options?.min)) {
                this.control?.addValidators(Validators.min(this.options.min));
            }
            if (isPresent(this.options?.max)) {
                this.control?.addValidators(Validators.max(this.options.max));
            }
        }
    }
};
NumberFieldSAComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NumberFieldSAComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
NumberFieldSAComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.4", type: NumberFieldSAComponent, isStandalone: true, selector: "form-number-field", usesInheritance: true, ngImport: i0, template: "<label>{{options?.label}}</label>\n<input type=\"number\" [attr.placeholder]=\"options?.placeholder\" [step]=\"step\" [formControl]=\"control|asFormControl|asRequired\"/>", styles: [":host{display: block;}"], dependencies: [{ kind: "ngmodule", type: FormPipesModule }, { kind: "pipe", type: i1.AsFormControlPipe, name: "asFormControl" }, { kind: "ngmodule", type: CastPipesModule }, { kind: "pipe", type: i2.AsRequiredTypePipe, name: "asRequired" }, { kind: "ngmodule", type: ReactiveFormsModule }, { 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.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
NumberFieldSAComponent = __decorate([
    RelationsEditorMetadata(NumberFieldRelationsMetadataLoader),
    LayoutEditorMetadata(NumberFieldLayoutMetadataLoader)
], NumberFieldSAComponent);
export { NumberFieldSAComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.4", ngImport: i0, type: NumberFieldSAComponent, decorators: [{
            type: Component,
            args: [{ selector: 'form-number-field', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [
                        FormPipesModule,
                        CastPipesModule,
                        FormComponentControlSAPipe,
                        ReactiveFormsModule,
                    ], template: "<label>{{options?.label}}</label>\n<input type=\"number\" [attr.placeholder]=\"options?.placeholder\" [step]=\"step\" [formControl]=\"control|asFormControl|asRequired\"/>", styles: [":host{display: block;}"] }]
        }] });
//# sourceMappingURL=numberField.component.js.map