@php $primaryContact = $institution?->contacts?->firstWhere('is_primary', true) ?? $institution?->contacts?->first(); $showRail = in_array($activeTab, ['overview', 'correspondence']); $client = $dsar->claim->client; // Built from the raw columns rather than $client->fullName — reading the // accessor caches a joined value that a later toArray() would feed back // through the set mutator and corrupt (see ValidateRecipientAction::nameOf). $clientName = trim(collect([ $client->title, $client->name_first, $client->name_last, ])->filter()->implode(' ')); @endphp
{{-- ══════════════════════════════════════════════════════════════════════ Header — who, what state, how late, and every action in one place. ══════════════════════════════════════════════════════════════════════ --}}

{{ $institution->display_name ?? 'Unknown institution' }}

@if($dsar->is_flagged) Flagged @endif

Subject Access Request for {{ $clientName ?: 'Client' }} @if($dsar->reference) {{ $dsar->reference }} @endif

@can('dsars.batch.send') @else {{ \App\Enum\Dsar\DsarStatus::label($dsar->status) }} @endcan {{-- Secondary actions live behind one menu so the header stays readable. --}}
{{-- ── At-a-glance strip: the questions this screen is opened to answer ── --}}
Sent {{ $dsar->created_at->format('d M Y') }}
Due {{ $summary['deadline']?->format('d M Y') ?? '—' }} @if($summary['isOverdue']) Overdue @endif
@if($summary['daysOutstanding'] !== null)
Outstanding {{ $summary['daysOutstanding'] }} days
@endif
Last contact {{ $summary['lastContactAt']?->diffForHumans() ?? 'No contact yet' }}
Chases {{ $summary['chaseCount'] }}
Responses {{ $summary['responseCount'] }}
@if(session('success')) @endif {{-- ══════════════════════════════════════════════════════════════════════ Tabs — Correspondence is the working tab; everything else is reference. ══════════════════════════════════════════════════════════════════════ --}}
{{-- ══════════════════════════════════════════════════════════════════ Left rail — constant context. Same place on every working tab, so the caseworker never loses who / where while reading the log. ══════════════════════════════════════════════════════════════════ --}} @if($showRail)
Institution
Name {{ $institution->display_name ?? '—' }}
@if($institution?->dsarType)
DSAR Type {{ $institution->dsarType->display_name }}
@endif @if($primaryContact)
Contact {{ $primaryContact->name ?? '—' }} @if($primaryContact->job_title)
{{ $primaryContact->job_title }}
@endif
@if($primaryContact->email)
Email {{ $primaryContact->email }}
@endif @if($primaryContact->telephone)
Telephone {{ $primaryContact->telephone->toNational() }}
@endif @else

No contact on file.

@endif
{{-- Key facts sit beside the log rather than inside it, and stay editable. --}}
Key Details
Due Date @can('dsars.batch.send') @else {{ $dsar->expected_at?->format('d M Y') ?? '—' }} @endcan
@if($dsar->reference)
Our Reference {{ $dsar->reference }}
@endif @if($dsar->receiver_reference)
Their Reference {{ $dsar->receiver_reference }}
@endif
Delivery @if($emailSend) Email
{{ $emailSend->recipient_name ? $emailSend->recipient_name . ' — ' : '' }}{{ $emailSend->recipient_email }}
@elseif(in_array($dsar->status, ['sent', 'needs posting', 'completed'])) Posted @if($dsar->posted_at)
{{ $dsar->posted_at->format('d M Y') }}
@endif @else Not sent yet @endif
@endif {{-- ══════════════════════════════════════════════════════════════════ Tab content ══════════════════════════════════════════════════════════════════ --}}
@if($activeTab === 'overview')
What was sent
{{-- The letter and covering email are reference material, so they are collapsed rather than dumped over the whole column. --}}

{!! $dsar->content !!}
@if($dsar->email_content)

{!! $dsar->email_content !!}
@endif
@elseif($activeTab === 'correspondence') {{-- One log for every contact with this institution about this DSAR: emails in and out, calls, chases and logged responses. --}} {{-- Contact that happened off-system still has to reach the same log. --}}

@elseif($activeTab === 'evidence') @elseif($activeTab === 'documents') @elseif($activeTab === 'history') @endif