{{-- The fields of one template section: a row each (label | input), as on the paper form.
Uses $n / $val / $v / $tplKey from _template.blade.php; 'cols' 2 = two per row (patient block). --}}
@foreach ($fields as $f)
@php
$k = $f['key'];
$saved = $v[$k] ?? null;
$choiceVal = is_array($saved) ? ($saved['value'] ?? '') : '';
// a field taken off the template stays only on reports that filled it
$hasValue = is_array($saved) ? collect($saved)->flatten()->contains(fn ($x) => trim((string) $x) !== '') : trim((string) $saved) !== '';
@endphp
@continue(!empty($f['legacy']) && !$hasValue)
@switch($f['type'])
@case('textarea')
@break
@case('date')
@if (($f['auto'] ?? '') === 'edd')from the LMP (+280 days) — change if needed@endif
@break
@case('num')
@if (!empty($f['unit'])){{ $f['unit'] }}@endif
@break
@case('ga')
weeks
days
@break
@case('ga_parts')
@foreach ($f['parts'] as [$pk, $pl])
{{ $pl }}wd
@endforeach
@break
@case('measure')
@foreach ($f['choices'] ?? [] as $opt)
@endforeach
@foreach ($f['parts'] as [$pk, $pl, $unit])
@endforeach
@if ($choiceVal !== '' && !in_array($choiceVal, $f['options'], true))
{{-- saved before the options changed (e.g. "Normal") — kept until another is picked --}}
@endif
clear
@foreach ($f['extra'] ?? [] as [$ek, $el, $eu])