@php use App\Support\Badges\BadgeCatalog; use App\Support\Badges\BadgeDomain; $resolvedState = isset($getState) ? $getState() : ($artifactTruthState ?? ($state ?? null)); $state = is_array($resolvedState) ? $resolvedState : []; $dimensions = collect(is_array($state['dimensions'] ?? null) ? $state['dimensions'] : []); $primary = $dimensions->first(fn (mixed $dimension): bool => is_array($dimension) && ($dimension['classification'] ?? null) === 'primary'); $existence = $dimensions->first(fn (mixed $dimension): bool => is_array($dimension) && ($dimension['axis'] ?? null) === 'artifact_existence'); $freshness = $dimensions->first(fn (mixed $dimension): bool => is_array($dimension) && ($dimension['axis'] ?? null) === 'data_freshness'); $publication = $dimensions->first(fn (mixed $dimension): bool => is_array($dimension) && ($dimension['axis'] ?? null) === 'publication_readiness'); $actionability = $dimensions->first(fn (mixed $dimension): bool => is_array($dimension) && ($dimension['axis'] ?? null) === 'operator_actionability'); $specFor = static function (mixed $dimension): ?\App\Support\Badges\BadgeSpec { if (! is_array($dimension)) { return null; } if (! is_string($dimension['badgeDomain'] ?? null) || ! is_string($dimension['badgeState'] ?? null)) { return null; } return BadgeCatalog::spec(BadgeDomain::from($dimension['badgeDomain']), $dimension['badgeState']); }; $primarySpec = $specFor($primary); $existenceSpec = $specFor($existence); $freshnessSpec = $specFor($freshness); $publicationSpec = $specFor($publication); $actionabilitySpec = $specFor($actionability); $reason = is_array($state['reason'] ?? null) ? $state['reason'] : []; $nextSteps = is_array($reason['nextSteps'] ?? null) ? $reason['nextSteps'] : []; $operatorExplanation = is_array($state['operatorExplanation'] ?? null) ? $state['operatorExplanation'] : []; $surface = is_string($surface ?? null) && trim($surface) !== '' ? trim($surface) : 'summary'; $evaluationSpec = is_string($operatorExplanation['evaluationResult'] ?? null) ? BadgeCatalog::spec(BadgeDomain::OperatorExplanationEvaluationResult, $operatorExplanation['evaluationResult']) : null; $trustSpec = is_string($operatorExplanation['trustworthinessLevel'] ?? null) ? BadgeCatalog::spec(BadgeDomain::OperatorExplanationTrustworthiness, $operatorExplanation['trustworthinessLevel']) : null; $operatorCounts = collect(is_array($operatorExplanation['countDescriptors'] ?? null) ? $operatorExplanation['countDescriptors'] : []); $normalizeArtifactTruthText = static function (mixed $value): ?string { if (! is_string($value)) { return null; } $value = trim((string) preg_replace('/\s+/', ' ', $value)); return $value !== '' ? $value : null; }; $uniqueArtifactTruthParagraphs = static function (array $values) use ($normalizeArtifactTruthText): array { $paragraphs = []; $seen = []; foreach ($values as $value) { $normalized = $normalizeArtifactTruthText($value); if ($normalized === null) { continue; } $key = mb_strtolower($normalized); if (array_key_exists($key, $seen)) { continue; } $seen[$key] = true; $paragraphs[] = $normalized; } return $paragraphs; }; $decisionSummaryArtifactTruthParagraph = $normalizeArtifactTruthText( $operatorExplanation['reliabilityStatement'] ?? ($state['primaryExplanation'] ?? null) ); $expandedArtifactTruthParagraphs = $uniqueArtifactTruthParagraphs([ $state['primaryExplanation'] ?? null, $operatorExplanation['reliabilityStatement'] ?? null, data_get($operatorExplanation, 'dominantCause.explanation'), ]); $expandedArtifactTruthParagraphs = array_values(array_filter( $expandedArtifactTruthParagraphs, static fn (string $paragraph): bool => $decisionSummaryArtifactTruthParagraph === null || mb_strtolower($paragraph) !== mb_strtolower($decisionSummaryArtifactTruthParagraph), )); $summaryArtifactTruthParagraphs = $uniqueArtifactTruthParagraphs([ $operatorExplanation['reliabilityStatement'] ?? ($state['primaryExplanation'] ?? null), data_get($operatorExplanation, 'dominantCause.explanation'), ]); @endphp @if ($surface === 'expanded')
Detailed artifact-truth context
@foreach ($expandedArtifactTruthParagraphs as $index => $paragraph)

{{ $paragraph }}

@endforeach @if (is_string($operatorExplanation['coverageStatement'] ?? null) && trim($operatorExplanation['coverageStatement']) !== '')

Coverage: {{ $operatorExplanation['coverageStatement'] }}

@endif @if (is_string($state['diagnosticLabel'] ?? null) && trim($state['diagnosticLabel']) !== '')

Diagnostic: {{ $state['diagnosticLabel'] }}

@endif
@if ($evaluationSpec && $evaluationSpec->label !== 'Unknown')
Result meaning
{{ $evaluationSpec->label }}
@endif @if ($trustSpec && $trustSpec->label !== 'Unknown')
Result trust
{{ $trustSpec->label }}
@endif @if ($primarySpec)
Primary artifact state
{{ $primarySpec->label }}
@endif @if ($actionabilitySpec)
Actionability
{{ $actionabilitySpec->label }}
@endif @if ($existenceSpec)
Artifact exists
{{ $existenceSpec->label }}
@endif @if ($freshnessSpec)
Freshness
{{ $freshnessSpec->label }}
@endif @if ($publicationSpec)
Publication
{{ $publicationSpec->label }}
@endif
@if ($operatorCounts->isNotEmpty())
@foreach ($operatorCounts as $count) @continue(! is_array($count))
{{ $count['label'] ?? 'Count' }}
{{ (int) ($count['value'] ?? 0) }}
@if (filled($count['qualifier'] ?? null))
{{ $count['qualifier'] }}
@endif
@endforeach
@endif
@else
@if ($evaluationSpec && $evaluationSpec->label !== 'Unknown') {{ $evaluationSpec->label }} @endif @if ($trustSpec && $trustSpec->label !== 'Unknown') {{ $trustSpec->label }} @endif @if ($primarySpec) {{ $primarySpec->label }} @endif @if ($actionabilitySpec) {{ $actionabilitySpec->label }} @endif
{{ $operatorExplanation['headline'] ?? ($state['primaryLabel'] ?? 'Artifact truth') }}
@foreach ($summaryArtifactTruthParagraphs as $paragraph)

{{ $paragraph }}

@endforeach @if (is_string($operatorExplanation['coverageStatement'] ?? null) && trim($operatorExplanation['coverageStatement']) !== '')

Coverage: {{ $operatorExplanation['coverageStatement'] }}

@endif @if (is_string($state['diagnosticLabel'] ?? null) && trim($state['diagnosticLabel']) !== '')

Diagnostic: {{ $state['diagnosticLabel'] }}

@endif
@if ($existenceSpec)
Artifact exists
{{ $existenceSpec->label }}
@endif @if ($freshnessSpec)
Freshness
{{ $freshnessSpec->label }}
@endif @if ($publicationSpec)
Publication
{{ $publicationSpec->label }}
@endif @if ($trustSpec && $trustSpec->label !== 'Unknown')
Result trust
{{ $trustSpec->label }}
@endif
Next step
{{ data_get($operatorExplanation, 'nextAction.text') ?? ($state['nextActionLabel'] ?? 'No action needed') }}
@if ($operatorCounts->isNotEmpty())
@foreach ($operatorCounts as $count) @continue(! is_array($count))
{{ $count['label'] ?? 'Count' }}
{{ (int) ($count['value'] ?? 0) }}
@if (filled($count['qualifier'] ?? null))
{{ $count['qualifier'] }}
@endif
@endforeach
@endif @if ($nextSteps !== [])
Guidance
@endif
@endif