<h1 class="mb-5">{{$name}}</h1>
@if($verif)
    <x-noData/>
@else
        <table class="table table-bordered" id="suppliers-tab">
            <thead>
            <tr class="bg-primary text-white">
                @php
                    $fields = [
                        'tiers_nom' => 'Fournisseur',
                        '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 . '#suppliers-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($suppliersOffMarketByDomain['retrieveSuppliersOffMarketByDomain']->items() as $supplier)
                <tr>
                    <th scope="row">{{ $supplier->tiers_nom }}</th>
                    <td>{{ $supplier->segment }}</td>
                    <td>{{ number_format($supplier->montant_ht, 2, ',', ' ') }} €</td>
                </tr>
            @endforeach
            </tbody>
        </table>
    {{ $suppliersOffMarketByDomain['retrieveSuppliersOffMarketByDomain']->appends(request()->except('suppliersPage'))->fragment('suppliers-tab')->links() }}
    <x-saveAsExcel :data="$suppliersOffMarketByDomain['allData']" :nameFile="'Fournisseurs hors marché'"/>

    <script>

        document.getElementById('selectSuppliersOffMarketLimit').addEventListener('change', function () {
            document.getElementById('paginationSuppliersOffForm').submit();
        });

    </script>
@endif
