@php
    $preserve = request()->only(['client', 'view', 'from', 'to', 'txn', 'q', 'company_name', 'contact_name', 'email', 'phone', 'city', 'dir']);
    $currentDir = $sortDir ?? 'asc';
    $currentSort = $sortBy ?? 'name';
@endphp
<div class="billing-sort-menu">
    <div class="billing-sort-menu__title">Sorted by</div>
    @foreach($sortOptions as $key => $label)
        @php
            $nextDir = ($currentSort === $key && $currentDir === 'asc') ? 'desc' : 'asc';
            $isActive = $currentSort === $key;
        @endphp
        <a href="{{ route('admin.customers.index', array_merge($preserve, ['sort' => $key, 'dir' => $isActive ? $nextDir : 'asc'])) }}"
           class="billing-sort-menu__item {{ $isActive ? 'is-active' : '' }}">
            <span>{{ $label }}</span>
            @if($isActive)
                <i class="ri-arrow-{{ $currentDir === 'asc' ? 'up' : 'down' }}-s-line"></i>
            @endif
        </a>
    @endforeach
    @if(!empty($showTableLink))
        <div class="billing-sort-menu__divider"></div>
        <a href="{{ route('admin.customers.index', request()->only(['sort', 'dir', 'q', 'company_name', 'contact_name', 'email', 'phone', 'city'])) }}" class="billing-sort-menu__item">
            <i class="ri-table-line me-2"></i> Table view
        </a>
    @endif
</div>
