import test from "node:test";
import assert from "node:assert/strict";
import { shouldVirtualizeThreadRows, virtualThreadRange, VIRTUAL_THREAD_ROW_HEIGHT } from "./virtual-thread-range.js";

test("large chat lists keep only the viewport and overscan rows mounted", () => {
  const first = virtualThreadRange({ count: 348, scrollTop: 0, viewportHeight: 844 });
  const middle = virtualThreadRange({ count: 348, scrollTop: 48 * 150, viewportHeight: 844 });

  assert.equal(VIRTUAL_THREAD_ROW_HEIGHT, 48);
  assert.deepEqual(first, { start: 0, end: 26, offsetTop: 0, totalHeight: 16704 });
  assert.equal(middle.end - middle.start, 34);
  assert.ok(middle.start > 0);
  assert.ok(middle.end < 348);
});

test("small chat lists stay unvirtualized and the final range remains bounded", () => {
  assert.equal(shouldVirtualizeThreadRows(80), false);
  assert.equal(shouldVirtualizeThreadRows(81), true);
  assert.deepEqual(virtualThreadRange({ count: 348, scrollTop: 999999, viewportHeight: 844 }), {
    start: 322,
    end: 348,
    offsetTop: 15456,
    totalHeight: 16704
  });
});
