@php
$queryParams = [];
if (!empty($searchQuery)) $queryParams['search'] = $searchQuery;
if (!empty($searchStatus)) $queryParams['status'] = $searchStatus;
if (!empty($searchSort)) $queryParams['sort'] = $searchSort;
$queryString = !empty($queryParams) ? '&' . http_build_query($queryParams) : '';
@endphp

<div class="pagination">
    @if($currentPage > 1)
        <a href="{{ route('admin.panel') }}?page=1{{ $queryString }}">&laquo; First</a>
        <a href="{{ route('admin.panel') }}?page={{ $currentPage - 1 }}{{ $queryString }}">&lsaquo; Prev</a>
    @endif

    @php
    $start = max(1, $currentPage - 2);
    $end = min($totalPages, $currentPage + 2);
    @endphp

    @for($i = $start; $i <= $end; $i++)
        @if($i == $currentPage)
            <span class="current">{{ $i }}</span>
        @else
            <a href="{{ route('admin.panel') }}?page={{ $i }}{{ $queryString }}">{{ $i }}</a>
        @endif
    @endfor

    @if($currentPage < $totalPages)
        <a href="{{ route('admin.panel') }}?page={{ $currentPage + 1 }}{{ $queryString }}">Next &rsaquo;</a>
        <a href="{{ route('admin.panel') }}?page={{ $totalPages }}{{ $queryString }}">Last &raquo;</a>
    @endif
</div>
