@php $sections = $diff['sections'] ?? []; $years = $diff['years'] ?? []; $payload = $multiYear['payload'] ?? null; $stack = $multiYear['analyses'] ?? []; $fmtCell = function ($v, $unit = '') { if ($v === null || $v === '' || ! is_scalar($v)) return '—'; if (is_numeric($v)) { $n = (float) $v; $abs = abs($n); $formatted = $abs >= 1000 ? number_format($n, 0, '.', ' ') : (floor($n) == $n ? number_format($n, 0) : number_format($n, 2)); return trim($formatted.' '.$unit); } return (string) $v; }; @endphp {{-- Year-spaced picker — operator can refine which analyses to include. --}}
@csrf

{{ __('Choose the analyses to plot (2 to 5)') }}

{{ __('The latest is checked by default. Add prior deliveries to see the trend.') }}

@foreach($candidates->take(8) as $c) @endforeach
{{-- Trend table — KPI × year matrix. --}} @if(empty($sections))
{{ __('Not enough analyses for a multi-year view yet.') }}
@else
@foreach($years as $y) @endforeach @foreach($sections as $section) @foreach($section['rows'] as $row) @foreach($row['values'] as $v) @endforeach @endforeach @endforeach
{{ __('Indicator') }}{{ $y }}{{ __('Trend') }}
{{ __($section['label']) }}
{{ $row['label'] }} @if($row['anomaly'] ?? false) {{ __('Outlier') }} @endif
{{ $fmtCell($v, $row['unit'] ?? '') }} @if($row['direction'] === 'improved') @if($row['pct'] !== null){{ '+'.number_format(abs((float) $row['pct']), abs((float) $row['pct']) >= 10 ? 0 : 1) }}%@endif @elseif($row['direction'] === 'declined') @if($row['pct'] !== null){{ '-'.number_format(abs((float) $row['pct']), abs((float) $row['pct']) >= 10 ? 0 : 1) }}%@endif @else @endif
@endif {{-- Multi-year AI narrative (only after the operator clicks "Compute trend"). --}} @if($payload)
{{ __('Smart commentary') }}

{{ __('Multi-year trend explained') }}

{!! $payload['html'] !!}
@if(!empty($payload['model'])){{ __('Model') }}: {{ $payload['model'] }}@endif @if(!empty($payload['tokens']))· {{ number_format($payload['tokens']) }} {{ __('tokens') }}@endif @if(!empty($payload['provider']))· {{ strtoupper($payload['provider']) }}@endif
@endif