val totalPages = math.ceil(totalCount.toDouble / totalPerPage).toInt val maxPages = math.min(5, totalPages) val middle = maxPages / 2 val baseMin = math.max(currPage - middle, 0) val baseMax = math.min(baseMin + maxPages, totalPages) val rest = maxPages - (baseMax - baseMin) val min = math