{{ define "fragments/pagination" }} {{/* Params: Page (pagination.Page), BasePath (string), QueryParams (url.Values), TotalCount (int)|HasMore (bool) */}} {{/* Cursor mode when HasMore is provided */}} {{ $page := .Page }} {{ $totalCount := .TotalCount }} {{ $basePath := .BasePath }} {{ $queryParams := safeUrl .QueryParams.Encode }} {{ $cursor := mapContains . "HasMore" }} {{ $prev := $page.Previous.Offset }} {{ $next := $page.Next.Offset }} {{ $hasNext := false }} {{ if $cursor }} {{ $hasNext = .HasMore }} {{ else }} {{ $hasNext = lt $next $totalCount }} {{ end }}
{{ i "chevron-left" "w-4 h-4" }} Prev {{ if not $cursor }} {{ $lastPage := sub $totalCount (mod $totalCount $page.Limit) }} {{ if gt $page.Offset 0 }} 1 {{ end }} {{ if gt $prev $page.Limit }} {{ end }} {{ if gt $prev 0 }} {{ add (div $prev $page.Limit) 1 }} {{ end }} {{ add (div $page.Offset $page.Limit) 1 }} {{ if lt $next $lastPage }} {{ add (div $next $page.Limit) 1 }} {{ end }} {{ if lt $next (sub $totalCount (mul 2 $page.Limit)) }} {{ end }} {{ if lt $page.Offset $lastPage }} {{ add (div $lastPage $page.Limit) 1 }} {{ end }} {{ end }} Next {{ i "chevron-right" "w-4 h-4" }}
{{ end }}