"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const field_1 = require("../../../../../client/field");
const processNumberValue_1 = require("../../../../../client/processNumberValue");
class NumberField extends field_1.Field {
    constructor($props, $system) {
        const { flags: { defaultInputModeNone }, } = $system;
        const defaultStyle = $system.style['numberfield'];
        super($props, $system, $system.api.document.createElement('input'), {
            valueKey: 'value',
            defaultStyle,
            defaultValue: '0',
            defaultAttr: {
                type: 'number',
                // Chrome inputmode 'none' not working on mobile for input type number
                inputmode: defaultInputModeNone ? 'none' : 'number',
            },
            processValue: processNumberValue_1.processNumberValue,
            propHandlers: {
                min: (min) => {
                    if (min === undefined) {
                        this.$element.removeAttribute('min');
                    }
                    else {
                        this.$element.min = `${min}`;
                    }
                },
                max: (max) => {
                    if (max === undefined) {
                        this.$element.removeAttribute('max');
                    }
                    else {
                        this.$element.max = `${max}`;
                    }
                },
            },
        });
        const { min, max } = $props;
        if (min !== undefined) {
            this.$element.min = `${min}`;
        }
        if (max !== undefined) {
            this.$element.max = `${max}`;
        }
    }
    setSelectionRange(start, end, direction) {
        this.$element.setSelectionRange(start, end, direction);
    }
    getValue({}, callback) {
        const value = Number.parseFloat(this.$element.value || '0');
        callback(value);
    }
    setValue({ value }, callback) {
        this.$element.value = value.toString();
        callback(value);
    }
}
exports.default = NumberField;
//# sourceMappingURL=Component.js.map