<?php $e=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); $filters=$filters??[]; $data=$assessments??['items'=>[],'total'=>0,'page'=>1,'pages'=>1]; $items=$data['items']??[]; ?>
<section class="page-header"><div><p class="eyebrow">Clinical · Assessments</p><h1>Assessments</h1><p><?= $e($pageDescription??'Clinical assessment records.') ?></p></div><?php if(\App\Core\Auth::hasPermission('assessments.create')): ?><a class="btn btn-primary" href="/crm/public/assessments/create">New Assessment</a><?php endif; ?></section>
<form class="card filter-card" method="get" action="/crm/public/assessments"><div class="filter-grid"><label class="form-field"><span>Search</span><input name="search" value="<?= $e($filters['search']??'') ?>" placeholder="Reference, patient or therapist"></label><label class="form-field"><span>Status</span><select name="status"><option value="">All statuses</option><?php foreach(['draft','submitted','reviewed','approved'] as $s): ?><option value="<?= $s ?>" <?= ($filters['status']??'')===$s?'selected':'' ?>><?= $e(ucfirst($s)) ?></option><?php endforeach; ?></select></label><label class="form-field"><span>Date</span><input type="date" name="date" value="<?= $e($filters['date']??'') ?>"></label><div class="filter-actions"><button class="btn btn-primary" type="submit">Filter</button><a class="btn btn-secondary" href="/crm/public/assessments">Reset</a></div></div></form>
<section class="card table-card"><div class="card-header"><div><h2>Clinical assessment records</h2><p><?= (int)$data['total'] ?> record<?= (int)$data['total']===1?'':'s' ?> found.</p></div></div><?php if(!$items): ?><div class="empty-state"><h3>No assessments found</h3><p>Create an assessment for a patient with a current therapist assignment.</p></div><?php else: ?><div class="table-wrap"><table class="data-table"><thead><tr><th>Reference</th><th>Patient</th><th>Therapist</th><th>Date</th><th>Status</th><th>Action</th></tr></thead><tbody><?php foreach($items as $a): ?><tr><td><strong><?= $e($a['assessment_reference']) ?></strong></td><td><strong><?= $e($a['first_name'].' '.$a['last_name']) ?></strong><br><small><?= $e($a['patient_reference']) ?></small></td><td><?= $e($a['therapist_name']) ?></td><td><?= $e($a['assessment_date']) ?></td><td><span class="badge <?= $a['status']==='approved'?'badge-success':($a['status']==='submitted'?'badge-muted':($a['status']==='reviewed'?'badge-muted':'badge-muted')) ?>"><?= $e(ucfirst($a['status'])) ?></span></td><td><a class="btn btn-secondary btn-small" href="/crm/public/assessments/<?= (int)$a['id'] ?>/edit">View / Edit</a></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?><?php if(($data['pages']??1)>1): ?><div class="pagination"><?php for($p=1;$p<=$data['pages'];$p++): ?><a class="page-button <?= $p===$data['page']?'active':'' ?>" href="?<?= http_build_query(array_merge($filters,['page'=>$p])) ?>"><?= $p ?></a><?php endfor; ?></div><?php endif; ?></section>
