@php /** @var \App\Support\Witness\WitnessQuestionnaire $questionnaire */ /** @var array $answers keyed "section.question" => [value, origin, review_status, provenance] */ $fmt = function ($value) { if (is_bool($value)) { return $value ? 'Yes' : 'No'; } if (is_array($value)) { // repeater rows or multiselect if ($value !== [] && is_array(reset($value))) { return null; // handled as table } return implode(', ', array_filter($value, fn ($v) => $v !== null && $v !== '')); } return (string) $value; }; // Map "section.question" => ["EXHIBIT 1", …] from the exhibit citations, so the // reference is woven in beside the answer it supports — deterministically, from // the agent's citations, never invented. $citationMap = []; foreach ($exhibits ?? [] as $ex) { foreach ($ex['cited_by'] ?? [] as $answerKey) { $citationMap[$answerKey][] = $ex['exhibit_ref']; } } $citationsFor = function ($key) use ($citationMap) { $refs = $citationMap[$key] ?? []; return $refs ? ' (see '.implode(', ', $refs).')' : ''; }; @endphp @if($coverLetter)

{{ now()->format('d F Y') }}

{{ $client->fullName }}
@if($answers['client_details.current_address']['value'] ?? null){!! nl2br(e($answers['client_details.current_address']['value'])) !!}@endif

Dear {{ $client->name_first ?? 'Sir/Madam' }},

Re: Your Witness Statement — Scottish Redress Scheme application {{ $claim->case_number }}

Please find enclosed your witness statement prepared in support of your application to the Scottish Redress Scheme. Please read it carefully, check that it is accurate and reflects your account in your own words, and let us know of any amendments. Once you are satisfied it is correct, please sign and date the statement of truth at the end.

Yours sincerely,

{{ $solicitor->name ?? 'MMA Legal' }}

@endif

Witness Statement

Scottish Redress Scheme · Application {{ $claim->case_number }} · Version {{ $versionNumber }} · Generated {{ now()->format('d/m/Y') }}
Applicant{{ $client->fullName }}
Date of birth{{ optional($client->date_of_birth)->format('d F Y') }}
Application reference{{ $claim->case_number }}
@foreach($questionnaire->groups() as $group) @php $groupSections = $questionnaire->sectionsForGroup($group); // Does this group have any answered content? $hasContent = $groupSections->flatMap(fn ($s) => $s->questions->map(fn ($q) => $answers[$s->key.'.'.$q->key]['value'] ?? null)) ->contains(fn ($v) => $v !== null && $v !== '' && $v !== []); @endphp @continue(! $hasContent)

{{ $loop->iteration }}. {{ $group }}

@foreach($groupSections as $section) @php $sectionHas = $section->questions->contains(fn ($q) => ! in_array($answers[$section->key.'.'.$q->key]['value'] ?? null, [null, '', []], true)); @endphp @continue(! $sectionHas)

{{ $section->title }}

@foreach($section->questions as $question) @php $answer = $answers[$section->key.'.'.$question->key] ?? null; @endphp @php $value = $answer['value'] ?? null; @endphp @continue($value === null || $value === '' || $value === []) @if($question->type === 'repeater' && is_array($value))
{{ $question->label }}
@foreach($question->fields as $sub)@endforeach @foreach($value as $row) @foreach($question->fields as $sub)@endforeach @endforeach
{{ $sub->label }}
{{ $row[$sub->key] ?? '' }}
@else
{{ $question->label }}
{{ $fmt($value) }}{{ $citationsFor($section->key.'.'.$question->key) }}
@endif @endforeach @endforeach @endforeach @if(! empty($exhibits))

Schedule of Exhibits

@endif

Statement of Truth

I believe that the facts stated in this Witness Statement are true to the best of my knowledge and recollection.

Signed___________________________
Name{{ $answers['declaration.signed_name']['value'] ?? $client->fullName }}
Date{{ $answers['declaration.signed_date']['value'] ?? '_______________' }}