/**
 * @class PartiallyVisibleRowsCalculationType
 */ export class PartiallyVisibleRowsCalculationType {
    /**
   * Initializes the calculation.
   */ initialize() {}
    /**
   * Processes the row.
   *
   * @param {number} row The row index.
   * @param {ViewportRowsCalculator} viewportCalculator The viewport calculator object.
   */ process(row, viewportCalculator) {
        const { totalCalculatedHeight, zeroBasedScrollOffset, innerViewportHeight } = viewportCalculator;
        if (totalCalculatedHeight <= zeroBasedScrollOffset) {
            this.startRow = row;
        }
        if (totalCalculatedHeight >= zeroBasedScrollOffset && totalCalculatedHeight <= innerViewportHeight) {
            if (this.startRow === null) {
                this.startRow = row;
            }
        }
        this.endRow = row;
    }
    /**
   * Finalizes the calculation.
   *
   * @param {ViewportRowsCalculator} viewportCalculator The viewport calculator object.
   */ finalize(viewportCalculator) {
        const { scrollOffset, viewportHeight, horizontalScrollbarHeight, totalRows, needReverse, positionCache, rowHeight } = viewportCalculator;
        // If the estimation has reached the last row and there is still some space available in the viewport,
        // we need to render in reverse in order to fill the whole viewport with rows
        if (this.endRow === totalRows - 1 && needReverse) {
            this.startRow = this.endRow;
            while(this.startRow > 0){
                const calculatedViewportHeight = positionCache.getOffset(this.endRow) + rowHeight - positionCache.getOffset(this.startRow - 1);
                this.startRow -= 1;
                if (calculatedViewportHeight >= viewportHeight - horizontalScrollbarHeight) {
                    break;
                }
            }
        }
        this.startPosition = this.startRow !== null ? positionCache.getOffset(this.startRow) : null;
        const mostBottomScrollOffset = scrollOffset + viewportHeight - horizontalScrollbarHeight;
        if (mostBottomScrollOffset < 0 || scrollOffset > positionCache.getOffset(viewportCalculator.lastProcessedIndex) + rowHeight) {
            this.isVisibleInTrimmingContainer = false;
        } else {
            this.isVisibleInTrimmingContainer = true;
        }
        if (totalRows < this.endRow) {
            this.endRow = totalRows - 1;
        }
        if (this.startRow !== null) {
            this.count = this.endRow - this.startRow + 1;
        }
    }
    constructor(){
        /**
   * Total number of partially visible rows in the viewport.
   *
   * @type {number}
   */ this.count = 0;
        /**
   * The row index of the first partially visible row in the viewport.
   *
   * @type {number|null}
   */ this.startRow = null;
        /**
   * The row index of the last partially visible row in the viewport.
   *
   * @type {number|null}
   */ this.endRow = null;
        /**
   * Position of the first partially visible row (in px).
   *
   * @type {number|null}
   */ this.startPosition = null;
        /**
   * Determines if the viewport is visible in the trimming container.
   *
   * @type {boolean}
   */ this.isVisibleInTrimmingContainer = false;
    }
}
