{{--
    Veri tablosu sayfalama çubuğu (üst/alt ortak partial)
    Beklenen değişkenler:
      $paginator      => LengthAwarePaginator
      $perPageOptions => [10, 25, 50, 100]
      $position       => 'top' | 'bottom'
--}}
@php
    $perPageOptions = $perPageOptions ?? [10, 25, 50, 100];
    $position = $position ?? 'bottom';
    $current  = $paginator->currentPage();
    $last      = $paginator->lastPage();
    $window    = 2; // aktif sayfanın iki yanındaki sayfa adedi
    $start     = max(1, $current - $window);
    $end       = min($last, $current + $window);
@endphp

<div class="dt-pager dt-pager-{{ $position }}">
    <div class="dt-pager-info">
        @if($paginator->total() > 0)
            <i class="fas fa-list-ul"></i>
            <span><strong>{{ $paginator->firstItem() }}</strong>–<strong>{{ $paginator->lastItem() }}</strong>
            / <strong>{{ number_format($paginator->total(), 0, ',', '.') }}</strong> kayıt</span>
        @else
            <span><strong>0</strong> kayıt</span>
        @endif
    </div>

    <div class="dt-pager-right">
        <label class="dt-perpage">
            <span>Sayfa başına</span>
            <select class="dt-perpage-select" data-dt-perpage>
                @foreach($perPageOptions as $opt)
                    <option value="{{ $opt }}" @selected((int) $paginator->perPage() === (int) $opt)>{{ $opt }}</option>
                @endforeach
            </select>
        </label>

        @if($last > 1)
            <nav class="dt-pages" aria-label="Sayfalama">
                <a class="dt-page-btn {{ $paginator->onFirstPage() ? 'disabled' : '' }}"
                   href="{{ $paginator->onFirstPage() ? '#' : $paginator->url(1) }}" title="İlk sayfa" aria-label="İlk sayfa">
                    <i class="fas fa-angles-left"></i>
                </a>
                <a class="dt-page-btn {{ $paginator->onFirstPage() ? 'disabled' : '' }}"
                   href="{{ $paginator->previousPageUrl() ?? '#' }}" title="Önceki" aria-label="Önceki sayfa" rel="prev">
                    <i class="fas fa-angle-left"></i>
                </a>

                @if($start > 1)
                    <a class="dt-page-btn" href="{{ $paginator->url(1) }}">1</a>
                    @if($start > 2)<span class="dt-page-gap">…</span>@endif
                @endif

                @for($p = $start; $p <= $end; $p++)
                    <a class="dt-page-btn {{ $p === $current ? 'active' : '' }}"
                       href="{{ $paginator->url($p) }}" @if($p === $current) aria-current="page" @endif>{{ $p }}</a>
                @endfor

                @if($end < $last)
                    @if($end < $last - 1)<span class="dt-page-gap">…</span>@endif
                    <a class="dt-page-btn" href="{{ $paginator->url($last) }}">{{ $last }}</a>
                @endif

                <a class="dt-page-btn {{ !$paginator->hasMorePages() ? 'disabled' : '' }}"
                   href="{{ $paginator->nextPageUrl() ?? '#' }}" title="Sonraki" aria-label="Sonraki sayfa" rel="next">
                    <i class="fas fa-angle-right"></i>
                </a>
                <a class="dt-page-btn {{ $current >= $last ? 'disabled' : '' }}"
                   href="{{ $current >= $last ? '#' : $paginator->url($last) }}" title="Son sayfa" aria-label="Son sayfa">
                    <i class="fas fa-angles-right"></i>
                </a>
            </nav>
        @endif
    </div>
</div>
