import { DEFAULT_COLUMN_WIDTH, CELL_PADDING } from './constants.js';

const getColumnLeftPosition = (index, columns, freezeColumns) => {
    if (index === 0)
        return '0px';
    let leftPosition = 0;
    for (let i = 0; i < index; i++) {
        const width = columns[i]?.width;
        leftPosition += width ? parseInt(width.toString(), 10) : DEFAULT_COLUMN_WIDTH;
        if (freezeColumns && i < freezeColumns - 1) {
            leftPosition += CELL_PADDING;
        }
    }
    return `${leftPosition}px`;
};
const calculateFrozenWidth = (columnData, freezeColumns) => {
    return (columnData
        .slice(0, freezeColumns)
        .reduce((acc, col) => acc +
        parseInt(col.width?.toString() || `${DEFAULT_COLUMN_WIDTH}`, 10), 1) +
        CELL_PADDING * (freezeColumns - 0.17));
};
// Utility: Simple binary search to find the index where cumulativeHeights[i] > target
// Returns the index of the first element greater than or equal to the target.
const binarySearch = (arr, target) => {
    let low = 0;
    let high = arr.length - 1;
    let result = arr.length; // Default to size if target is greater than all elements
    while (low <= high) {
        const mid = Math.floor((low + high) / 2);
        // FIX: Use the non-null assertion operator '!'
        if (arr[mid] >= target) {
            result = mid;
            high = mid - 1;
        }
        else {
            low = mid + 1;
        }
    }
    return result;
};

export { binarySearch, calculateFrozenWidth, getColumnLeftPosition };
//# sourceMappingURL=virtualization.js.map
