{{-- : the one badge for a CRM signal on a list or a record (CRM Wave 4, conflict register C11). Each Wave 4 session fills its own column; this badge shows it the same way everywhere. kind score | health | prediction | response value The column's value. Null renders nothing at all: "not scored yet" is not shown as zero or as a grey badge. reasons Why: strings, or rows with `label` and optional `points` (a score breakdown). Shown on hover and read by screen readers, so no signal is ever an unexplained number. label Optional override for the badge text. --}} @props([ 'kind' => 'score', 'value' => null, 'reasons' => [], 'label' => null, ]) @php $text = null; $color = 'slate'; $icon = 'star'; if ($value !== null && $value !== '') { switch ($kind) { case 'health': $text = __(\App\Models\Customer::HEALTH_LABELS[$value] ?? (string) $value); $color = ['healthy' => 'emerald', 'watch' => 'amber', 'at_risk' => 'rose'][$value] ?? 'slate'; $icon = 'heart'; break; case 'prediction': $date = $value instanceof \DateTimeInterface ? \Illuminate\Support\Carbon::instance($value) : \Illuminate\Support\Carbon::parse((string) $value); $text = __('Reorder due :month', ['month' => $date->format('M Y')]); $color = 'sky'; $icon = 'arrow-path'; break; case 'response': $text = __(':hours working h to respond', ['hours' => rtrim(rtrim(number_format((float) $value, 1), '0'), '.')]); $color = 'sky'; $icon = 'clock'; break; default: $text = __('Score :score', ['score' => (int) $value]); $color = 'indigo'; $icon = 'star'; } } $lines = collect(is_array($reasons) ? $reasons : []) ->map(function ($reason): string { if (is_array($reason)) { $points = $reason['points'] ?? null; $prefix = $points === null ? '' : (((int) $points >= 0 ? '+' : '').(int) $points.' '); return $prefix.($reason['label'] ?? ''); } return (string) $reason; }) ->filter(fn (string $line): bool => trim($line) !== '') ->values(); $title = $lines->implode("\n"); @endphp @if ($text !== null) {{ $label ?? $text }} @if ($lines->isNotEmpty()) : {{ $lines->implode('; ') }} @endif @endif