/** * SchoolRow Component * Four-line row for primary school search results * * Line 1: School name · Ofsted badge (framework-aware) * Line 2: Phase · Type · Age range · the school page's flags (lib/schoolFacts) * Line 3: Reading, Writing & Maths % · trend arrow · vs-national delta · Pupils * Line 4: Local authority · Distance */ import type { School } from '@/lib/types'; import { formatPercentage, calculateTrend, getPhaseStyle, schoolUrl, buildOfstedListBadge, formatAgeRange, isProposedToClose, isSpecialSchool, listRwmValue } from '@/lib/utils'; import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts'; import styles from './SchoolRow.module.css'; interface SchoolRowProps { school: School; isLocationSearch?: boolean; isInCompare?: boolean; onAddToCompare?: (school: School) => void; onRemoveFromCompare?: (urn: number) => void; nationalAvgRwm?: number | null; } export function SchoolRow({ school, isLocationSearch, isInCompare = false, onAddToCompare, onRemoveFromCompare, nationalAvgRwm, }: SchoolRowProps) { const trend = calculateTrend(school.rwm_expected_pct, school.prev_rwm_expected_pct); const phase = getPhaseStyle(school.phase); const ofstedBadge = buildOfstedListBadge(school); const typeLabel = schoolTypeLabel(school); const flags = schoolFlags(school); // The school's OWN figure and its year-over-year trend are same-school // measures — shown whenever there's a real value (not the all-zero // placeholder, see listRwmValue), special schools included. const showRwmValue = listRwmValue(school) != null; // The vs-England delta is a mainstream benchmark: additionally dropped for // special schools / PRUs / AP, whose pupils aren't measured against it fairly. const rwmDelta = showRwmValue && !isSpecialSchool(school) && nationalAvgRwm != null ? Math.round((school.rwm_expected_pct as number) - nationalAvgRwm) : null; const handleCompareClick = () => { if (isInCompare) { onRemoveFromCompare?.(school.urn); } else { onAddToCompare?.(school); } }; return (
{/* Left: four content lines */}
{/* Line 1: School name + Ofsted badge */}
{school.school_name} {ofstedBadge.label}
{/* Line 2: Context tags */}
{phase.label && ( {phase.label} )} {typeLabel && {typeLabel}} {school.age_range && {formatAgeRange(school.age_range)}} {flags.map((flag) => ( {flag.label} ))} {isProposedToClose(school) && ( ⚠ Proposed to close )}
{/* Line 3: Key stats */}
{showRwmValue ? formatPercentage(school.rwm_expected_pct, 0) : '—'} {showRwmValue && school.prev_rwm_expected_pct != null && ( {trend === 'up' && ( )} {trend === 'down' && ( )} {trend === 'stable' && ( )} )} Reading, Writing & Maths {rwmDelta != null && ( = 2 ? styles.vsNational : rwmDelta <= -2 ? styles.vsNationalNeg : styles.vsNationalFlat } > {rwmDelta >= 2 ? `+${rwmDelta} pts vs national` : rwmDelta <= -2 ? `${rwmDelta} pts vs national` : '≈ national avg'} )} {school.total_pupils != null && ( {school.total_pupils.toLocaleString()} pupils )}
{/* Line 4: Location + distance */}
{school.local_authority && ( {school.local_authority} )} {isLocationSearch && school.distance != null && ( {school.distance.toFixed(1)} mi )}
{/* Right: actions, vertically centred */}
View {(onAddToCompare || onRemoveFromCompare) && ( )}
); }