int endIndex(int totalItems) { if (!enabled) return totalItems; return math.min(startIndex(totalItems) + pageSize, totalItems); }