/**
 * @dyna-grid/core - Advanced Data Grid / Data Table supporting Javascript / Web Components
 * @version v1.0.5
 * @link 
 * @license 
 */
"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var dyInputTextField_1 = require("./dyInputTextField");
var dom_1 = require("../utils/dom");
var DyInputNumberField = /** @class */ (function (_super) {
    __extends(DyInputNumberField, _super);
    function DyInputNumberField(config) {
        return _super.call(this, config, 'dy-number-field', 'number') || this;
    }
    DyInputNumberField.prototype.postConstruct = function () {
        var _this = this;
        _super.prototype.postConstruct.call(this);
        this.addManagedListener(this.eInput, 'blur', function () {
            var floatedValue = parseFloat(_this.eInput.value);
            var value = isNaN(floatedValue) ? '' : _this.normalizeValue(floatedValue.toString());
            if (_this.value !== value) {
                _this.setValue(value);
            }
        });
    };
    DyInputNumberField.prototype.normalizeValue = function (value) {
        if (value === '') {
            return '';
        }
        if (this.precision) {
            value = this.adjustPrecision(value);
        }
        var val = parseFloat(value);
        if (this.min != null && val < this.min) {
            value = this.min.toString();
        }
        else if (this.max != null && val > this.max) {
            value = this.max.toString();
        }
        return value;
    };
    DyInputNumberField.prototype.adjustPrecision = function (value) {
        if (this.precision) {
            var floatString = parseFloat(value).toFixed(this.precision);
            value = parseFloat(floatString).toString();
        }
        return value;
    };
    DyInputNumberField.prototype.setMin = function (min) {
        if (this.min === min) {
            return this;
        }
        this.min = min;
        dom_1.addOrRemoveAttribute(this.eInput, 'min', min);
        return this;
    };
    DyInputNumberField.prototype.setMax = function (max) {
        if (this.max === max) {
            return this;
        }
        this.max = max;
        dom_1.addOrRemoveAttribute(this.eInput, 'max', max);
        return this;
    };
    DyInputNumberField.prototype.setPrecision = function (precision) {
        this.precision = precision;
        return this;
    };
    DyInputNumberField.prototype.setStep = function (step) {
        if (this.step === step) {
            return this;
        }
        this.step = step;
        dom_1.addOrRemoveAttribute(this.eInput, 'step', step);
        return this;
    };
    DyInputNumberField.prototype.setValue = function (value, silent) {
        value = this.adjustPrecision(value);
        var normalizedValue = this.normalizeValue(value);
        if (value != normalizedValue) {
            return this;
        }
        return _super.prototype.setValue.call(this, value, silent);
    };
    return DyInputNumberField;
}(dyInputTextField_1.DyInputTextField));
exports.DyInputNumberField = DyInputNumberField;

//# sourceMappingURL=dyInputNumberField.js.map
