@php
    $state = $getState();
    $state = is_array($state) ? $state : [];

    $summary = is_string($state['summary'] ?? null) ? $state['summary'] : null;
    $artifactSources = is_array($state['artifact_sources'] ?? null) ? $state['artifact_sources'] : [];
    $highlights = is_array($state['highlights'] ?? null) ? $state['highlights'] : [];
    $items = is_array($state['items'] ?? null) ? $state['items'] : [];
@endphp

<div class="space-y-3 rounded-md border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-800 dark:bg-gray-900">
    @if ($summary)
        <div class="text-sm font-medium text-gray-900 dark:text-gray-100">{{ $summary }}</div>
    @endif

    @if ($artifactSources !== [])
        <div class="space-y-2">
            <div class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">Artifact source</div>
            <dl class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3">
                @foreach ($artifactSources as $source)
                    @continue(! is_array($source))

                    @foreach ([
                        'Source family' => $source['source_family'] ?? null,
                        'Source kind' => $source['source_kind'] ?? null,
                        'Source target' => $source['source_target_kind'] ?? null,
                        'Control' => $source['control_key'] ?? null,
                        'Detector' => $source['detector_key'] ?? null,
                    ] as $label => $value)
                        @php
                            $value = is_string($value) && trim($value) !== '' ? \Illuminate\Support\Str::headline($value) : null;
                        @endphp

                        @continue($value === null)

                        <div class="rounded-md border border-gray-100 bg-gray-50 px-3 py-2 dark:border-gray-800 dark:bg-gray-950/60">
                            <dt class="text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">{{ $label }}</dt>
                            <dd class="mt-1 text-sm text-gray-900 dark:text-gray-100">{{ $value }}</dd>
                        </div>
                    @endforeach
                @endforeach
            </dl>
        </div>
    @endif

    @if ($highlights !== [])
        <dl class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3">
            @foreach ($highlights as $highlight)
                @php
                    $label = is_string($highlight['label'] ?? null) ? $highlight['label'] : null;
                    $value = is_string($highlight['value'] ?? null) ? $highlight['value'] : null;
                @endphp

                @continue($label === null || $value === null)

                <div class="rounded-md border border-gray-100 bg-gray-50 px-3 py-2 dark:border-gray-800 dark:bg-gray-950/60">
                    <dt class="text-[11px] font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">{{ $label }}</dt>
                    <dd class="mt-1 text-sm text-gray-900 dark:text-gray-100">{{ $value }}</dd>
                </div>
            @endforeach
        </dl>
    @endif

    @if ($items !== [])
        <div class="space-y-2">
            <div class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">Recent items</div>
            <ul class="space-y-1 text-sm text-gray-700 dark:text-gray-300">
                @foreach ($items as $item)
                    @continue(! is_string($item) || trim($item) === '')

                    <li class="rounded-md border border-gray-100 bg-gray-50 px-3 py-2 dark:border-gray-800 dark:bg-gray-950/60">{{ $item }}</li>
                @endforeach
            </ul>
        </div>
    @endif
</div>
