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

    $facts = array_values(array_filter($decisionZone['facts'] ?? [], 'is_array'));
    $primaryNextStep = is_array($decisionZone['primaryNextStep'] ?? null) ? $decisionZone['primaryNextStep'] : null;
    $compactCounts = is_array($decisionZone['compactCounts'] ?? null) ? $decisionZone['compactCounts'] : null;
    $countFacts = array_values(array_filter($compactCounts['primaryFacts'] ?? [], 'is_array'));
    $attentionNote = is_string($decisionZone['attentionNote'] ?? null) && trim($decisionZone['attentionNote']) !== ''
        ? trim($decisionZone['attentionNote'])
        : null;
@endphp

<x-filament::section
    :heading="$decisionZone['title'] ?? 'Decision'"
    :description="$decisionZone['description'] ?? 'Start here to see how the run ended, whether the result is usable, and what to do next.'"
>
    <div class="grid gap-6 xl:grid-cols-[minmax(0,2fr)_minmax(18rem,1fr)]">
        <div class="space-y-4">
            @if ($attentionNote !== null)
                <div class="rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-100">
                    {{ $attentionNote }}
                </div>
            @endif

            @if ($facts !== [])
                @include('filament.infolists.entries.enterprise-detail.section-items', [
                    'items' => $facts,
                    'variant' => 'summary',
                ])
            @endif
        </div>

        <div class="space-y-4">
            @if ($primaryNextStep !== null)
                <div class="rounded-xl border-l-4 border-primary-500 bg-primary-50 px-4 py-4 dark:bg-primary-500/10">
                    <div class="text-xs font-semibold uppercase tracking-[0.16em] text-primary-600 dark:text-primary-400">
                        {{ $primaryNextStep['label'] ?? 'Primary next step' }}
                    </div>
                    <div class="mt-2 text-base font-semibold text-gray-950 dark:text-white">
                        {{ $primaryNextStep['text'] ?? 'No action needed.' }}
                    </div>
                </div>
            @endif

            @if (filled($compactCounts['summaryLine'] ?? null) || $countFacts !== [])
                <div class="rounded-xl border border-gray-200 bg-gray-50/70 px-4 py-4 dark:border-gray-700 dark:bg-gray-800/50">
                    <div class="text-xs font-semibold uppercase tracking-[0.16em] text-gray-500 dark:text-gray-400">
                        Counts
                    </div>
                    <div class="mt-2 space-y-4">
                        @if (filled($compactCounts['summaryLine'] ?? null))
                            <div class="text-sm font-medium text-gray-900 dark:text-white">
                                {{ $compactCounts['summaryLine'] }}
                            </div>
                        @endif

                        @if ($countFacts !== [])
                            @include('filament.infolists.entries.enterprise-detail.section-items', [
                                'items' => $countFacts,
                                'variant' => 'supporting',
                            ])
                        @endif
                    </div>
                </div>
            @endif
        </div>
    </div>
</x-filament::section>
