"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_STYLE = void 0;
const field_1 = require("../../../../../client/field");
const processNumberValue_1 = require("../../../../../client/processNumberValue");
exports.DEFAULT_STYLE = {
    height: 'fit-content',
    width: '100%',
    color: 'inherit',
    backgroundColor: '#00000000',
    textAlign: 'center',
    padding: '0',
    fontSize: '18px',
    // outline: 'none',
    border: 'none',
    borderRadius: '0',
};
class NumberField extends field_1.Field {
    constructor($props, $system) {
        super($props, $system, $system.api.document.createElement('input'), {
            valueKey: 'value',
            defaultStyle: exports.DEFAULT_STYLE,
            defaultValue: '0',
            processValue: processNumberValue_1.processNumberValue,
        });
        const { min, max } = $props;
        this.$element.type = 'number';
        // BUG
        // Chrome
        // inputMode 'none' not working on mobile for input type number
        this.$element.inputMode = 'none';
        if (min !== undefined) {
            this.$element.min = `${min}`;
        }
        if (max !== undefined) {
            this.$element.max = `${max}`;
        }
    }
    onPropChanged(prop, current) {
        super.onPropChanged(prop, current);
        if (prop === 'min') {
            if (current === undefined) {
                this.$element.removeAttribute('min');
            }
            else {
                this.$element.min = `${current}`;
            }
        }
        else if (prop === 'max') {
            if (current === undefined) {
                this.$element.removeAttribute('max');
            }
            else {
                this.$element.max = `${current}`;
            }
        }
    }
    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