{{-- Training required at a home, in three steps: 1. Service-specific e-learning (opt-in, course_service) 2. Mandatory e-learning (per-home opt-out, service_course_exclusions) 3. Required face-to-face trainings (service_training_names) Used by the admin service form and the SM / RM "Manage Training" page. Needs: $selectableCourses, $requiredCourseIds, $mandatoryCourses, $excludedMandatoryIds; optional $sessionNames, $requiredSessionIds. Each card has live search, "show selected" filter, select/clear all and a live selected count; the summary strip at the top updates as you tick. --}} @php $reqIds = array_map('intval', old('required_course_ids', $requiredCourseIds)); $mandIds = array_map('intval', old('required_mandatory_ids', $mandatoryCourses->pluck('id')->diff($excludedMandatoryIds)->all())); $sessIds = array_map('intval', old('required_session_ids', $requiredSessionIds ?? [])); $hasSessions = isset($sessionNames); $cards = [ [ 'key' => 'specific', 'step' => 1, 'icon' => 'add_task', 'name' => 'required_course_ids[]', 'title' => 'Service-specific e-learning', 'help' => 'Extra online courses this home needs on top of the mandatory ones (e.g. Epilepsy, Bed Rails). Tick a course to assign it to every care worker here and the Service Manager.', 'items' => $selectableCourses->map(fn ($c) => [ 'id' => $c->id, 'title' => $c->title, 'sub' => ucwords(str_replace('_', ' ', $c->category)).($c->refresh_cycle ? ' · renew '.$c->refresh_cycle : ''), 'on' => in_array($c->id, $reqIds, true), ]), 'empty' => 'No service-specific courses available.', 'noun' => 'course', ], [ 'key' => 'mandatory', 'step' => 2, 'icon' => 'verified', 'name' => 'required_mandatory_ids[]', 'title' => 'Mandatory e-learning', 'help' => 'Organisation-wide courses — all ticked by default. Only untick a course this home genuinely doesn’t need: it won’t be assigned here, won’t count toward compliance, and shows as N/A on the matrix. Completed records are kept.', 'items' => $mandatoryCourses->map(fn ($c) => [ 'id' => $c->id, 'title' => $c->title, 'sub' => 'Mandatory', 'on' => in_array($c->id, $mandIds, true), ]), 'empty' => 'No mandatory courses defined.', 'noun' => 'course', 'marker' => 'mandatory_section', ], ]; if ($hasSessions) { $cards[] = [ 'key' => 'sessions', 'step' => 3, 'icon' => 'groups', 'name' => 'required_session_ids[]', 'title' => 'Required Face to Face Trainings', 'help' => 'Classroom / trainer-led sessions staff here must attend (the session names trainers use on the calendar). Each ticked training shows on this home’s session matrix, and anyone who hasn’t attended it counts as overdue in compliance.', // Insulin / PEG / Dysphagia observations first, next to the compulsory competency tile. 'items' => $sessionNames->sortBy(fn ($t) => \App\Models\ObservationRecord::typeForTitle($t->name) ? 0 : 1)->values()->map(fn ($t) => [ 'id' => $t->id, 'title' => $t->name, 'sub' => ($obsType = \App\Models\ObservationRecord::typeForTitle($t->name)) ? 'Observation · PDF upload · renewed '.\App\Models\ObservationRecord::renewalLabel($obsType).(isset(\App\Models\ObservationRecord::PREREQUISITES[$obsType]) ? ' · also requires '.\App\Models\ObservationRecord::PREREQUISITES[$obsType] : '') : ($t->training_code ? 'Face to face · '.$t->training_code : 'Face to face'), 'on' => in_array($t->id, $sessIds, true), ]), 'empty' => 'No face-to-face trainings exist yet — trainers add these when scheduling on the calendar.', 'noun' => 'training', 'marker' => 'sessions_section', ]; } @endphp {{-- At-a-glance summary (updates live) --}}

What staff at this home must complete

@foreach($cards as $card) {{ $card['icon'] }} {{ $card['items']->where('on', true)->count() }} / {{ $card['items']->count() }} {{ $card['title'] }} @endforeach
@foreach($cards as $card)
@isset($card['marker']) {{-- Marker so the controller only syncs this list when the card is present. --}} @endisset
{{ $card['step'] }}

{{ $card['title'] }}

check_circle {{ $card['items']->where('on', true)->count() }} of {{ $card['items']->count() }} selected

{!! $card['help'] !!}

@if($card['key'] === 'sessions' && ($sessionsPrefilled ?? false) && ! old('sessions_section'))
info No face-to-face trainings have been set for this home yet, so we’ve ticked the {{ $card['items']->where('on', true)->count() }} that staff here have already attended — what the session matrix shows today. Untick any that aren’t required, add any missing, then Save training.
@endif @if($card['key'] === 'sessions') {{-- Compulsory at every service — always on the session matrix, so it can't be unticked or saved. --}}
medication {{ \App\Support\MedicationCompetencyPack::NAME }} Observed medication competency by the SM / RM · renewed every year lock Compulsory for all services
{{-- Mandatory face-to-face sessions: required everywhere, so not choices here. --}} @if(($mandatorySessions ?? collect())->isNotEmpty())

Mandatory at every service

@foreach($mandatorySessions as $m)
lock {{ $m->name }} {{ $m->duration_label }} · {{ $m->refreshLabel() }}
@endforeach

Service-specific

@endif @endif @if($card['items']->isEmpty())

{{ $card['empty'] }}

@else {{-- Toolbar: search · show filter · bulk actions --}}
search
@foreach(['all' => 'All', 'on' => 'Selected', 'off' => 'Not selected'] as $val => $lbl) @endforeach
@foreach($card['items'] as $it) @endforeach
@endif
@endforeach @once @endonce