@php
    /** @var array<string, mixed>|null $summaryAssessment */
    $summary = is_array($summaryAssessment ?? null) ? $summaryAssessment : null;
    $tone = (string) ($summary['tone'] ?? 'warning');
    $headline = (string) ($summary['headline'] ?? 'Baseline compare needs review.');
    $supportingMessage = $summary['supportingMessage'] ?? null;
    $nextAction = is_array($summary['nextAction'] ?? null) ? $summary['nextAction'] : ['label' => 'Review compare detail', 'target' => 'none'];

    [$wrapperClasses, $textClasses] = match ($tone) {
        'danger' => [
            'rounded-lg border border-danger-300 bg-danger-50 p-4 dark:border-danger-700 dark:bg-danger-950/40',
            'text-danger-900 dark:text-danger-100',
        ],
        'info' => [
            'rounded-lg border border-info-300 bg-info-50 p-4 dark:border-info-700 dark:bg-info-950/40',
            'text-info-900 dark:text-info-100',
        ],
        'gray' => [
            'rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-gray-800 dark:bg-white/5',
            'text-gray-900 dark:text-white',
        ],
        default => [
            'rounded-lg border border-warning-300 bg-warning-50 p-4 dark:border-warning-700 dark:bg-warning-950/40',
            'text-warning-900 dark:text-warning-100',
        ],
    };
@endphp

<div>
    @if ($shouldShow && $summary)
        <div class="{{ $wrapperClasses }}">
            <div class="flex flex-col gap-2">
                <div class="text-sm font-semibold {{ $textClasses }}">
                    {{ $headline }}
                </div>

                @if (filled($supportingMessage))
                    <div class="text-sm">
                        {{ $supportingMessage }}
                    </div>
                @endif

                @if (filled($nextActionUrl))
                    <div class="mt-1">
                        <a class="text-sm font-medium text-primary-600 hover:underline dark:text-primary-400" href="{{ $nextActionUrl }}">
                            {{ $nextAction['label'] }}
                        </a>
                    </div>
                @elseif (filled($nextAction['label'] ?? null))
                    <div class="text-xs font-medium uppercase tracking-wide">
                        {{ $nextAction['label'] }}
                    </div>
                @endif
            </div>
        </div>
    @endif
</div>
