import { createEmptyLine } from '../types/grid.js';
/**
 * InfiniteBuffer - Manages the complete conversation history as a list of lines.
 */
export class InfiniteBuffer {
    lines = [];
    addLine(line) {
        this.lines.push(line);
    }
    addLines(lines) {
        this.lines.push(...lines);
    }
    getLineCount() {
        return this.lines.length;
    }
    /**
     * getAllLines - Provides access to the full raw line list.
     */
    getAllLines() {
        return this.lines;
    }
    /**
     * Takes a snapshot of the buffer for a specific viewport window.
     */
    getSnapshot(startLine, height, width) {
        const end = Math.min(this.lines.length, startLine + height);
        const slice = this.lines.slice(startLine, end);
        // Bottom-anchor logic: prepend empty space
        while (slice.length < height) {
            slice.unshift(createEmptyLine(width));
        }
        return slice;
    }
    clear() {
        this.lines = [];
    }
    /** Truncate the buffer to the given line count (remove all lines from lineIndex onward). */
    truncateToLine(lineIndex) {
        if (lineIndex >= 0 && lineIndex < this.lines.length) {
            this.lines.length = lineIndex;
        }
    }
}
