<h1 class="mb-5">{{$name}}</h1>
@if($verif)
    <x-noData/>
@else
        <table class="table table-bordered" id="market-tab">
            <thead>
            <tr class="bg-primary text-white">
                @php
                    $fields = [
                        'libelle_marche' => 'Libellé marché',
                        'segment' => 'Famille',
                        'montant_ht' => 'Montant HT'
                    ];
                @endphp
                @foreach($fields as $field => $display)
                    @php
                        $url = url()->current() . '?' . http_build_query(array_merge(request()->except('sort_by', 'sort_order'), ['sort_by' => $field, 'sort_order' => ($sortField === $field && $sortOrder === 'asc') ? 'desc' : 'asc']));
                        $urlWithFragment = $url . '#market-tab';
                    @endphp
                    <th scope="col">{{ $display }}
                        <a class="ml-2"
                           href="{{ $urlWithFragment }}">
                            @if ($sortField === $field)
                                @if ($sortOrder === 'asc')
                                    <i class="fas fa-sort-down text-white"></i>
                                @else
                                    <i class="fas fa-sort-up text-white"></i>
                                @endif
                            @else
                                <i class="fas fa-sort text-white"></i>
                            @endif
                        </a>
                    </th>
                @endforeach
            </tr>
            </thead>
            <tbody>
            @foreach($marketsByAmount['marketByAmount']->items() as $marketByAmount)
                <tr>
                    <td>{{ $marketByAmount->libelle_marche }}</td>
                    <th scope="row">{{ $marketByAmount->segment }}</th>
                    <td>{{number_format($marketByAmount->montant_ht, 2, ',', ' ')}} €</td>
            @endforeach
            </tbody>
        </table>
    {{ $marketsByAmount['marketByAmount']->appends(request()->except('marketByAmount'))->fragment('market-tab')->links() }}
    <x-saveAsExcel :data="$marketsByAmount['allData']" :nameFile="'Marchés par montant'"/>

    <script>

        document.getElementById('selectMarketLimit').addEventListener('change', function () {
            document.getElementById('paginationMarketForm').submit();
        });

    </script>
@endif

