{{- $pag := $.Paginator -}}
{{- if gt $pag.TotalPages 1 -}}
<nav class="pagination" role="navigation" aria-label="pagination">
    {{- /* Previous page button */ -}}
    <a class="page-link {{ if not $pag.Prev }}disabled{{ end }}"
        {{- if $pag.Prev -}}href="{{ $pag.Prev.URL }}" {{- end -}}
        aria-label="Previous page" 
        {{- if not $pag.Prev -}}aria-disabled="true"{{- end -}}>
        {{ partial "helper/icon" "chevron-left" }}
    </a>

    {{- /* Page numbers logic */ -}}
    {{- $window := 4 -}}
    {{- $showFirst := true -}}
    {{- $showLast := true -}}

    {{- /* First page */ -}}
    <a class="page-link {{ if eq $pag.PageNumber 1 }}current{{ end }}" aria-label="Page 1"
        {{- if eq $pag.PageNumber 1 -}}aria-current="page" {{- end -}}
        {{- if ne $pag.PageNumber 1 -}}href="{{ $pag.First.URL }}"{{- end -}}>
        1
    </a>

    {{- /* Left ellipsis - show if current page is > 3 */ -}}
    {{- if gt $pag.PageNumber 3 -}}
    <span class="page-link pagination-link">
        {{ partial "helper/icon" "dots" }}
    </span>
    {{- end -}}

    {{- /* Middle pages - show current and neighbors */ -}}
    {{- range $pag.Pagers -}}
        {{- if and (gt .PageNumber 1) (lt .PageNumber $pag.TotalPages) -}}
            {{- if and (ge .PageNumber (sub $pag.PageNumber $window)) (le .PageNumber (add $pag.PageNumber $window)) -}}
            <a class="page-link {{ if eq .PageNumber $pag.PageNumber }}current{{ end }}"
                {{- if eq .PageNumber $pag.PageNumber -}}aria-current="page" {{- end -}} href="{{ .URL }}"
                aria-label="Page {{ .PageNumber }}">
                {{ .PageNumber }}
            </a>
            {{- end -}}
        {{- end -}}
    {{- end -}}

    {{- /* Right ellipsis - show if current page is < last-2 */ -}}
    {{- if lt $pag.PageNumber (sub $pag.TotalPages 2) -}}
    <span class="page-link pagination-link">
        {{ partial "helper/icon" "dots" }}
    </span>
    {{- end -}}

    {{- /* Last page (if more than 1 page total) */ -}}

    {{- if gt $pag.TotalPages 1 -}}
    <a class="page-link {{ if eq $pag.PageNumber $pag.TotalPages }}current{{ end }}"
        {{- if ne $pag.PageNumber $pag.TotalPages -}}href="{{ $pag.Last.URL }}" {{- end -}}
        aria-label="Page {{ $pag.TotalPages }}" 
        {{- if eq $pag.PageNumber $pag.TotalPages -}}aria-current="page"{{- end -}}>
        {{ $pag.TotalPages }}
    </a>
    {{- end -}}

    {{- /* Next page button */ -}}
    <a class="page-link {{ if not $pag.Next }}disabled{{ end }}"
        {{- if $pag.Next -}}href="{{ $pag.Next.URL }}" {{- end -}} 
        aria-label="Next page"
        {{- if not $pag.Next -}}aria-disabled="true"{{- end -}}>
        {{ partial "helper/icon" "chevron-right" }}
    </a>
</nav>
{{- end -}}