{{--
    Storefront pagination — brand-styled override of Bootstrap 5 default.

    Registered globally via `Paginator::defaultView('theme::components.pagination')`
    in themes/Web/Protera/Providers/ThemeServiceProvider.php. The `theme::`
    namespace resolves per-request through the active theme, so admin pages
    pick up themes/Admin/ViartasDefault/Resources/views/components/pagination.blade.php
    (a BS5 pass-through), preserving the existing admin look.

    Markup contract (used by tests/e2e/frontend-storefront-ux.spec.ts):
      - [data-pagination-storefront] outer marker so specs can scope to the
        custom view independent of class refactors.
      - `.pagination-storefront` styling hook (CSS lives in
        packages/va-themes/protera/Resources/assets/css/web.css — task-116b).
      - `<ul class="pagination">` + `<li class="page-item">` + `<a class="page-link">`
        preserves the BS5 hierarchy so generic BS5 utility classes still apply.

    Expected variable: $paginator (\Illuminate\Contracts\Pagination\LengthAwarePaginator)
--}}
@if ($paginator->hasPages())
    <nav class="pagination-storefront" role="navigation"
         aria-label="{{ __('pagination.navigation') }}" data-pagination-storefront>
        <ul class="pagination">
            {{-- Previous --}}
            @if ($paginator->onFirstPage())
                <li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
                    <span class="page-link" aria-hidden="true">&lsaquo;</span>
                </li>
            @else
                <li class="page-item">
                    <a class="page-link" href="{{ $paginator->previousPageUrl() }}"
                       rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>
                </li>
            @endif

            {{-- Page numbers + ellipsis ("Three Dots" pattern) --}}
            @foreach ($elements as $element)
                {{-- "Three Dots" separator --}}
                @if (is_string($element))
                    <li class="page-item disabled" aria-disabled="true">
                        <span class="page-link">{{ $element }}</span>
                    </li>
                @endif

                {{-- Array of links --}}
                @if (is_array($element))
                    @foreach ($element as $page => $url)
                        @if ($page == $paginator->currentPage())
                            <li class="page-item active" aria-current="page">
                                <span class="page-link">{{ $page }}</span>
                            </li>
                        @else
                            <li class="page-item">
                                <a class="page-link" href="{{ $url }}">{{ $page }}</a>
                            </li>
                        @endif
                    @endforeach
                @endif
            @endforeach

            {{-- Next --}}
            @if ($paginator->hasMorePages())
                <li class="page-item">
                    <a class="page-link" href="{{ $paginator->nextPageUrl() }}"
                       rel="next" aria-label="@lang('pagination.next')">&rsaquo;</a>
                </li>
            @else
                <li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
                    <span class="page-link" aria-hidden="true">&rsaquo;</span>
                </li>
            @endif
        </ul>
    </nav>
@endif
