"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "getMaskedValue", {
    enumerable: true,
    get: function() {
        return getMaskedValue;
    }
});
var getMaskedValue = function getMaskedValue(param) {
    var value = param.value, prevValue = param.prevValue, format = param.format, delimiters = param.delimiters, selectionStart = param.selectionStart;
    if (!value) {
        return {
            formattedValue: '',
            selectionStart: 0
        };
    }
    if (!format || !(delimiters === null || delimiters === void 0 ? void 0 : delimiters.length)) {
        return {
            formattedValue: value,
            selectionStart: selectionStart
        };
    }
    var currentSelection = selectionStart || 0;
    var dateRegExp = new RegExp("[^0-9".concat(delimiters.join(''), "]"), 'g');
    var formattedValue = value.replace(dateRegExp, '');
    if (formattedValue.length >= format.length) {
        return {
            formattedValue: formattedValue.slice(0, format.length),
            selectionStart: selectionStart
        };
    }
    if (prevValue && formattedValue.length < prevValue.length) {
        if (delimiters.includes(format[currentSelection])) {
            return {
                formattedValue: formattedValue.slice(0, currentSelection - 1),
                selectionStart: currentSelection - 1
            };
        }
    }
    if (delimiters.includes(format[currentSelection])) {
        return {
            formattedValue: formattedValue + format[currentSelection],
            selectionStart: currentSelection + 1
        };
    }
    return {
        formattedValue: formattedValue,
        selectionStart: currentSelection
    };
};
