<x-filament::section heading="Needs attention">
    @if ($triageReviewProgress !== [])
        <div class="mb-4 grid grid-cols-1 gap-3 lg:grid-cols-2">
            @foreach ($triageReviewProgress as $progress)
                <div class="rounded-xl border border-gray-200 bg-white p-4 dark:border-white/10 dark:bg-white/5">
                    <div class="flex items-start justify-between gap-3">
                        <div>
                            <div class="text-sm font-semibold text-gray-950 dark:text-white">
                                {{ $progress['label'] }}
                            </div>
                            <div class="mt-1 text-xs text-gray-500 dark:text-gray-400">
                                Reviewed {{ $progress['reviewed_count'] }}/{{ $progress['affected_total'] }} · Follow-up needed {{ $progress['follow_up_needed_count'] }} · Changed since review {{ $progress['changed_since_review_count'] }}
                            </div>
                        </div>

                        <span class="inline-flex items-center rounded-full border border-gray-200 bg-gray-50 px-2.5 py-0.5 text-xs font-medium text-gray-600 dark:border-white/10 dark:bg-white/10 dark:text-gray-300">
                            Current affected set
                        </span>
                    </div>

                    <div class="mt-3 flex flex-wrap gap-2 text-xs">
                        <x-filament::link :href="$progress['not_reviewed_destination']['url']" size="sm">
                            Not reviewed {{ $progress['not_reviewed_count'] }}
                        </x-filament::link>
                        <x-filament::link :href="$progress['follow_up_needed_destination']['url']" size="sm">
                            Follow-up needed {{ $progress['follow_up_needed_count'] }}
                        </x-filament::link>
                        <x-filament::link :href="$progress['changed_since_review_destination']['url']" size="sm">
                            Changed since review {{ $progress['changed_since_review_count'] }}
                        </x-filament::link>
                        <x-filament::link :href="$progress['reviewed_destination']['url']" size="sm">
                            Reviewed {{ $progress['reviewed_count'] }}
                        </x-filament::link>
                    </div>
                </div>
            @endforeach
        </div>
    @endif

    @if ($items === [])
        <div class="flex h-full flex-col justify-between gap-4">
            <div class="space-y-2">
                <p class="text-sm font-medium text-gray-950 dark:text-white">
                    {{ $emptyState['title'] ?? 'Nothing urgent in your current scope' }}
                </p>

                <p class="text-sm leading-6 text-gray-600 dark:text-gray-300">
                    {{ $emptyState['body'] ?? 'Recent operations and alert deliveries look healthy right now.' }}
                </p>
            </div>

            @if (filled($emptyState['action_url'] ?? null))
                <div>
                    <x-filament::link :href="$emptyState['action_url']" size="sm">
                        {{ $emptyState['action_label'] ?? 'Open operations' }}
                    </x-filament::link>
                </div>
            @endif
        </div>
    @else
        <div class="space-y-3">
            @foreach ($items as $item)
                @php
                    $destination = $item['destination'] ?? null;
                    $actionUrl = is_array($destination) && ($destination['disabled'] ?? false) === false
                        ? ($destination['url'] ?? null)
                        : null;
                @endphp

                <div class="rounded-xl border border-gray-200 bg-gray-50 p-4 dark:border-white/10 dark:bg-white/5">
                    <div class="space-y-3">
                        <div class="flex flex-wrap items-start justify-between gap-3">
                            <div class="space-y-2">
                                <div class="flex flex-wrap items-center gap-2">
                                    <span class="inline-flex items-center rounded-full border border-gray-200 bg-white px-2.5 py-0.5 text-xs font-medium text-gray-700 dark:border-white/10 dark:bg-white/10 dark:text-gray-200">
                                        {{ $item['tenant_label'] }}
                                    </span>

                                    <span class="inline-flex items-center rounded-full border border-gray-200 bg-white px-2.5 py-0.5 text-xs font-medium uppercase tracking-wide text-gray-500 dark:border-white/10 dark:bg-white/10 dark:text-gray-300">
                                        {{ str_replace('_', ' ', $item['urgency']) }}
                                    </span>

                                    <x-filament::badge :color="$item['badge_color']" size="sm">
                                        {{ $item['badge'] }}
                                    </x-filament::badge>
                                </div>

                                <div class="text-sm font-semibold text-gray-950 dark:text-white">
                                    {{ $item['title'] }}
                                </div>

                                <div class="text-sm leading-6 text-gray-600 dark:text-gray-300">
                                    {{ $item['body'] }}
                                </div>

                                @if (filled($item['supporting_message'] ?? null))
                                    <p class="text-xs leading-5 text-gray-500 dark:text-gray-400">
                                        {{ $item['supporting_message'] }}
                                    </p>
                                @endif
                            </div>
                        </div>

                        <div class="flex flex-wrap items-center gap-3 text-sm">
                            @if (is_string($actionUrl) && $actionUrl !== '')
                                <x-filament::link :href="$actionUrl" size="sm">
                                    {{ $destination['label'] ?? 'Open' }}
                                </x-filament::link>
                            @else
                                <span class="text-gray-500 dark:text-gray-400">
                                    {{ $destination['label'] ?? 'Unavailable' }}
                                </span>
                            @endif

                            @if (filled($item['helper_text'] ?? null))
                                <span class="text-xs text-gray-500 dark:text-gray-400">
                                    {{ $item['helper_text'] }}
                                </span>
                            @endif
                        </div>
                    </div>
                </div>
            @endforeach
        </div>
    @endif
</x-filament::section>
