@php
/** @var array $totali */
$totali = $this->totaliMediSettimana;
/** @var array|null $ref */
$ref = $this->riferimentiStep3;
@endphp
@if(!$ref)
Completa lo step 3 Impostazione piano per impostare i target di energia e macronutrienti
e visualizzare il confronto con il piano alimentare.
@else
@php
$energiaCurr = (int) round($totali['energia_kcal'] ?? 0);
$energiaRef = (int) round($ref['energia_kcal'] ?? 0);
$energiaSupera = $energiaRef > 0 && $energiaCurr > $energiaRef;
$energiaPct = $energiaRef > 0 ? min(100, (int) round(($energiaCurr / $energiaRef) * 100)) : 0;
@endphp
Energia
{{ $energiaCurr }}
@if($energiaRef > 0)
/ {{ $energiaRef }} kcal
@if($energiaSupera)
!
@endif
@else
kcal
@endif
@if($energiaRef > 0)
@endif
@php
$macroConfig = [
'lipidi' => ['key' => 'lipidi_g', 'label' => 'Lipidi', 'class' => 'macro-lipidi-bg', 'var' => '--macro-lipidi'],
'carboidrati' => ['key' => 'carboidrati_g', 'label' => 'Carboidrati', 'class' => 'macro-carboidrati-bg', 'var' => '--macro-carboidrati'],
'proteine' => ['key' => 'proteine_g', 'label' => 'Proteine', 'class' => 'macro-proteine-bg', 'var' => '--macro-proteine'],
'fibre' => ['key' => 'fibre_g', 'label' => 'Fibre alimentari', 'class' => 'macro-fibre-bg', 'var' => '--macro-fibre'],
];
@endphp
@foreach($macroConfig as $slug => $cfg)
@php
$curr = (float) ($totali[$cfg['key']] ?? 0);
$target = (float) ($ref[$cfg['key']] ?? 0);
$supera = $target > 0 && $curr > $target;
$pct = $target > 0 ? min(120, (int) round(($curr / $target) * 100)) : 0;
$barWidth = min(100, $pct);
$colorVar = $cfg['var'];
$angle = $barWidth * 3.6;
$gradient = $target > 0
? "conic-gradient(var({$colorVar}) 0deg, var({$colorVar}) {$angle}deg, #e9ecef {$angle}deg 360deg)"
: "var({$colorVar})";
@endphp
@if($supera)
!
@endif
@if($target > 0)
{{ number_format($curr, 0) }}g
{{ number_format($target, 0) }}g
@else
{{ number_format($curr, 0) }}g
@endif
{{ $cfg['label'] }}
@endforeach
@endif