Calculates the total number of pages for totalItems.
totalItems
int totalPages(int totalItems) { if (totalItems == 0) return 1; return math.max(1, (totalItems / pageSize).ceil()); }