@if (! empty($paginator) && $paginator->hasPages())
    <nav class="imt-catalog-pages-nav d-flex justify-content-center" aria-label="{{ trans('catalog.pagination_nav_aria') }}">
        <ul class="imt-catalog-pages-nav__list list-unstyled d-flex align-items-center justify-content-center flex-wrap mb-0">
            @if ($paginator->onFirstPage())
                <li class="imt-catalog-pages-nav__item imt-catalog-pages-nav__item--edge is-disabled">
                    <span class="imt-catalog-pages-nav__btn imt-catalog-pages-nav__btn--arrow" aria-disabled="true">
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" aria-hidden="true"><path d="M15 18l-6-6 6-6"/></svg>
                    </span>
                </li>
            @else
                <li class="imt-catalog-pages-nav__item imt-catalog-pages-nav__item--edge">
                    <a href="{{ $paginator->previousPageUrl() }}" class="imt-catalog-pages-nav__btn imt-catalog-pages-nav__btn--arrow" rel="prev" aria-label="{{ trans('pagination.previous') }}">
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" aria-hidden="true"><path d="M15 18l-6-6 6-6"/></svg>
                    </a>
                </li>
            @endif

            @foreach ($elements as $element)
                @php $separate = false; @endphp
                @if (is_array($element))
                    @foreach ($element as $page => $url)
                        @if(($page < 2) || ($page + 1 > $paginator->lastPage()) || (($page < $paginator->currentPage() + 2) && ($page > $paginator->currentPage() - 2)))
                            @php $separate = true; @endphp
                            @if ($page == $paginator->currentPage())
                                <li class="imt-catalog-pages-nav__item">
                                    <span class="imt-catalog-pages-nav__btn imt-catalog-pages-nav__btn--num is-current" aria-current="page">{{ $page }}</span>
                                </li>
                            @else
                                <li class="imt-catalog-pages-nav__item">
                                    <a href="{{ $url }}" class="imt-catalog-pages-nav__btn imt-catalog-pages-nav__btn--num">{{ $page }}</a>
                                </li>
                            @endif
                        @elseif($separate)
                            <li class="imt-catalog-pages-nav__item" aria-disabled="true"><span class="imt-catalog-pages-nav__ellipsis">…</span></li>
                            @php $separate = false; @endphp
                        @endif
                    @endforeach
                @endif
            @endforeach

            @if ($paginator->hasMorePages())
                <li class="imt-catalog-pages-nav__item imt-catalog-pages-nav__item--edge">
                    <a href="{{ $paginator->nextPageUrl() }}" class="imt-catalog-pages-nav__btn imt-catalog-pages-nav__btn--arrow" rel="next" aria-label="{{ trans('pagination.next') }}">
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" aria-hidden="true"><path d="M9 18l6-6-6-6"/></svg>
                    </a>
                </li>
            @else
                <li class="imt-catalog-pages-nav__item imt-catalog-pages-nav__item--edge is-disabled">
                    <span class="imt-catalog-pages-nav__btn imt-catalog-pages-nav__btn--arrow" aria-disabled="true">
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" aria-hidden="true"><path d="M9 18l6-6-6-6"/></svg>
                    </span>
                </li>
            @endif
        </ul>
    </nav>
@endif
