@props(['data', 'metadata' => null, 'emptyMessage' => 'Aucun resultat.', 'emptyIcon' => 'heroicon-o-inbox'])

@if (count($data) > 0)
    @php
        $firstRow = reset($data);
        $isAssociative = is_array($firstRow);
        $headers = $isAssociative ? array_keys($firstRow) : [];
    @endphp

    <div class="overflow-x-auto">
        <table class="w-full text-left text-sm">
            <thead>
                <tr class="border-b border-gray-200 dark:border-white/10">
                    @if ($isAssociative)
                        @foreach ($headers as $key)
                            <th class="px-3 py-2.5 text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">{{ $key }}</th>
                        @endforeach
                    @else
                        <th class="px-3 py-2.5 text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">Valeur</th>
                    @endif
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100 dark:divide-white/5">
                @foreach ($data as $row)
                    <tr class="transition-colors hover:bg-gray-50 dark:hover:bg-white/5">
                        @if ($isAssociative)
                            @foreach ($row as $value)
                                <td class="px-3 py-2.5 text-sm text-gray-700 dark:text-gray-300">{{ is_array($value) ? json_encode($value) : $value }}</td>
                            @endforeach
                        @else
                            <td class="px-3 py-2.5 text-sm text-gray-700 dark:text-gray-300">{{ $row }}</td>
                        @endif
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
@else
    <x-logistics.empty-state :icon="$emptyIcon" :title="$emptyMessage" />
@endif
