<x-filament-widgets::widget>
    <x-filament::section>
        <x-slot name="heading">
            Top offenders
        </x-slot>

        <x-slot name="description">
            Highest failed-operation clusters in {{ $windowLabel }}.
        </x-slot>

        @if ($offenders->isEmpty())
            <div class="rounded-lg border border-dashed border-gray-300 px-4 py-6 text-sm text-gray-500 dark:border-white/15 dark:text-gray-400">
                No failed operations in the selected time window.
            </div>
        @else
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200 text-sm dark:divide-white/10">
                    <thead>
                        <tr class="text-left text-xs uppercase tracking-wider text-gray-500 dark:text-gray-400">
                            <th class="px-3 py-2">Workspace</th>
                            <th class="px-3 py-2">ManagedEnvironment</th>
                            <th class="px-3 py-2">Operation</th>
                            <th class="px-3 py-2 text-right">Failed</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-100 dark:divide-white/5">
                        @foreach ($offenders as $offender)
                            <tr>
                                <td class="px-3 py-2 font-medium text-gray-950 dark:text-white">{{ $offender['workspace_label'] }}</td>
                                <td class="px-3 py-2 text-gray-700 dark:text-gray-300">{{ $offender['tenant_label'] }}</td>
                                <td class="px-3 py-2 text-gray-700 dark:text-gray-300">{{ $offender['operation_label'] }}</td>
                                <td class="px-3 py-2 text-right font-semibold text-danger-600 dark:text-danger-400">{{ number_format($offender['failed_count']) }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @endif

        <div class="mt-4">
            <x-filament::link :href="$runsUrl" icon="heroicon-m-arrow-top-right-on-square">
                Open all runs
            </x-filament::link>
        </div>
    </x-filament::section>
</x-filament-widgets::widget>
