import { LENGTH_DATE, LENGTH_MONTH, LENGTH_YEAR } from '../../../lib/date/constants.js';
import { InternalDateComponentType } from '../../../lib/date/types.js';
export var inputNumber = function (type, prev, key, inputMode, maxValue) {
    var nextInputMode = false;
    var nextValue;
    var firstDigits = getFirstDigits(type, maxValue);
    var maxLength = getMaxLength(type);
    if (!inputMode) {
        nextValue = key;
        nextInputMode = Number(key) <= firstDigits;
    }
    else {
        nextValue = addKey(prev, key, maxLength);
        nextInputMode = nextValue.length < maxLength;
        if (!isCorrectDate(nextValue, maxValue, maxLength)) {
            nextValue = prev + '';
            nextInputMode = true;
        }
    }
    return { nextValue: nextValue, nextInputMode: nextInputMode };
};
function addKey(prev, key, length) {
    var value = key;
    if (prev !== null) {
        value = "".concat(prev).concat(key);
    }
    return value.slice(-length);
}
function isCorrectDate(value, maxValue, length) {
    return Number(value) <= maxValue && (Number(value) !== 0 || value.length !== length);
}
function getFirstDigits(type, maxValue) {
    var first = 10;
    if (type === InternalDateComponentType.Month) {
        first = 1;
    }
    if (type === InternalDateComponentType.Date) {
        first = Math.floor(maxValue / 10);
    }
    return first;
}
function getMaxLength(type) {
    var length = LENGTH_YEAR;
    if (type === InternalDateComponentType.Month) {
        length = LENGTH_MONTH;
    }
    if (type === InternalDateComponentType.Date) {
        length = LENGTH_DATE;
    }
    return length;
}
//# sourceMappingURL=inputNumber.js.map