const MIN_WIDTH = 5;
/**
 * Метод расчета новых размеров на основании значения из <input type="range"/>
 */
export const computePositions = (currentTarget, columnsWidths, memoizedSliders) => {
    const value = parseFloat(currentTarget.value);
    const index = parseInt(currentTarget.getAttribute('data-index'));
    if (isNaN(value) ||
        isNaN(index) ||
        !memoizedSliders[index] ||
        columnsWidths.length < 2) {
        return null;
    }
    const currentLeftColumnWidth = columnsWidths[index];
    const currentRightColumnWidth = columnsWidths[index + 1];
    const difference = value - memoizedSliders[index];
    const newLeftColumnWidth = currentLeftColumnWidth + difference;
    const newRightColumnWidth = currentRightColumnWidth - difference;
    if (newLeftColumnWidth < MIN_WIDTH || newRightColumnWidth < MIN_WIDTH) {
        return null;
    }
    const newSliders = memoizedSliders.map((currentValue, sliderIndex) => sliderIndex === index ? value : currentValue);
    const newColumnsWidths = columnsWidths.map((currentValue, columnIndex) => {
        if (columnIndex === index) {
            return newLeftColumnWidth;
        }
        if (columnIndex === index + 1) {
            return newRightColumnWidth;
        }
        return currentValue;
    });
    return {
        newColumnsWidths,
        newSliders,
    };
};
