import { CurrencyHelper } from './CurrencyHelper.js';
import { CursorHelper } from './CursorHelper.js';
var CurrencyInputHelper = /** @class */ (function () {
    function CurrencyInputHelper() {
    }
    CurrencyInputHelper.moveCursor = function (value, selection, step) {
        if (selection.start === selection.end) {
            return CursorHelper.calculatePosition(CurrencyHelper.getInfo(value).cursorMap, selection.start, step);
        }
        else if (step < 0) {
            return selection.start;
        }
        return selection.end;
    };
    CurrencyInputHelper.extendSelection = function (value, selection, step) {
        var info = CurrencyHelper.getInfo(value);
        return CursorHelper.extendSelection(info.cursorMap, selection, step);
    };
    CurrencyInputHelper.normalizeSelection = function (value, selection) {
        var info = CurrencyHelper.getInfo(value);
        return CursorHelper.normalizeSelection(info.cursorMap, selection);
    };
    CurrencyInputHelper.safeInsert = function (value, start, end, input, options) {
        if (input && start === 0 && end === value.length) {
            var extracted = CurrencyHelper.extractValid(input, options);
            if (!extracted) {
                return null;
            }
            return CurrencyInputHelper.insert(value, start, end, extracted);
        }
        var prefix = value.substring(0, start);
        var suffix = value.substring(end);
        var combined = prefix + input + suffix;
        if (CurrencyHelper.isValidString(combined, options)) {
            return CurrencyInputHelper.insert(value, start, end, input);
        }
        return null;
    };
    CurrencyInputHelper.insert = function (value, start, end, input) {
        var prefix = value.substring(0, start);
        var suffix = value.substring(end);
        var info = CurrencyHelper.getInfo(value);
        var raw = CursorHelper.toRawPosition(info.cursorMap, start);
        var info2 = CurrencyHelper.getInfo(prefix + input + suffix);
        var formattedPosition = CursorHelper.toFormattedPosition(info2.cursorMap, raw + input.length);
        return { value: info2.formatted, position: formattedPosition };
    };
    return CurrencyInputHelper;
}());
export { CurrencyInputHelper };
//# sourceMappingURL=CurrencyInputHelper.js.map