<?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="d-flex align-items-end flex-wrap">
    <a href="{{ $route }}?{{queryLineExcept(['sort_by', 'page'])}}&sort_by={!! urlencode($targetSortParamForInclusionOrReversal) !!}" class="text-decoration-none">
        <b class="{{$currentSortForKey ? 'text-primary' : 'text-secondary'}}">{!! $label !!}</b>
        <span class="ml-1 d-inline-flex align-items-baseline position-relative sort-header-arrows" @if($currentSortForKey) sort-index="{{$currentSortForKey['index']}}" @endif>
            <i class="text-sm fa fa-chevron-up {{$currentSortForKey && $currentSortForKey['order'] === 'DESC' ? '' : 'on-hover-opaque text-secondary'}}"></i>
            <i class="ml-1 text-sm fa fa-chevron-down {{$currentSortForKey && $currentSortForKey['order'] === 'ASC' ? '' : 'on-hover-opaque text-secondary'}}"></i>
        </span>
    </a>
    @if($currentSortForKey)
        <a href="{{ $route }}?{{queryLineExcept(['sort_by', 'page'])}}&sort_by={!! $targetSortParamForRemoval !== '[]' ? urlencode($targetSortParamForRemoval) : '' !!}" class="text-sm on-hover-opaque text-secondary ml-1">
            <i class="fa fa-times"></i>
        </a>
    @endif
</div>