//#region src/hooks/useNumberInput/utils/repositionCursor.ts
/**
* Based on the last key stroke and the cursor position, update the value
* and reposition the cursor to the right place
*/
const repositionCursor = ({ selectionStart, value, lastKeyStroke, stateValue, groupSeparator }) => {
	let cursorPosition = selectionStart;
	let modifiedValue = value;
	if (stateValue && cursorPosition) {
		const splitValue = value.split("");
		if (lastKeyStroke === "Backspace" && stateValue[cursorPosition] === groupSeparator) {
			splitValue.splice(cursorPosition - 1, 1);
			cursorPosition -= 1;
		}
		if (lastKeyStroke === "Delete" && stateValue[cursorPosition] === groupSeparator) {
			splitValue.splice(cursorPosition, 1);
			cursorPosition += 1;
		}
		modifiedValue = splitValue.join("");
		return {
			modifiedValue,
			cursorPosition
		};
	}
	return {
		modifiedValue,
		cursorPosition: selectionStart
	};
};
//#endregion
export { repositionCursor };
