@if($key !== '__clear_sort__')
    <?php
    // sort=key:order,key:order...
    $current = request()->input('sort_by');
    $current = $current ? json_decode($current, true) : [];
    $currentSortForKey = currentSortForKey($current, $key);
    $targetSortParamForInclusionOrReversal = json_encode(includeOrReverseInMultiSort($current, $key));
    $targetSortParamForRemoval = json_encode(removeFromMultiSort($current, $key));
    ?>
    <div class="">
        <a href="{{ $route }}?{{queryLineExcept(['sort_by', 'page'])}}&sort_by={!! urlencode($targetSortParamForInclusionOrReversal) !!}" class="text-decoration-none d-block">
            <b class="{{$currentSortForKey ? 'text-primary' : 'text-secondary'}}">{!! $label !!}</b>
        </a>
        <div class="mb-1 d-flex align-items-end position-relative sort-header-arrows flex-nowrap">
            <i class="mr-1 text-sm fa fa-chevron-up {{$currentSortForKey && $currentSortForKey['order'] === 'DESC' ? 'text-primary' : 'on-hover-opaque text-secondary'}}"></i>
            <i class="mr-1 text-sm fa fa-chevron-down {{$currentSortForKey && $currentSortForKey['order'] === 'ASC' ? 'text-primary' : 'on-hover-opaque text-secondary'}}"></i>
            @if($currentSortForKey)
                <div class="multi-sort-index mr-1">{{$currentSortForKey['index']}}</div>
            @endif
            @if($currentSortForKey)
                <a href="{{ $route }}?{{queryLineExcept(['sort_by', 'page'])}}&sort_by={!! $targetSortParamForRemoval !== '[]' ? urlencode($targetSortParamForRemoval) : '' !!}" class="text-sm on-hover-opaque text-secondary">
                    <i class="fa fa-times"></i>
                </a>
            @endif
        </div>
    </div>
@else
    <div class="">
        @if(request()->input('sort_by'))
            <a href="{{ $route }}?{{queryLineExcept(['sort_by', 'page'])}}" class="text-sm font-weight-normal d-block lh-16px">
                Clear<br>Sort
            </a>
        @else
            <span class="text-sm font-weight-normal text-secondary">Sort</span>
        @endif
    </div>


@endif