/** * SecondarySchoolRow Component * Four-line row for secondary school search results * * Line 1: School name · Ofsted badge * Line 2: Phase · Type · Age range · the school page's flags (lib/schoolFacts) * Line 3: Attainment 8 (large) · ±LA avg delta · Pupils * Line 4: LA name · distance */ 'use client'; import type { School } from '@/lib/types'; import { buildOfstedListBadge, getPhaseStyle, schoolUrl, formatAgeRange, isProposedToClose, isSpecialSchool } from '@/lib/utils'; import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts'; import styles from './SecondarySchoolRow.module.css'; interface SecondarySchoolRowProps { school: School; isLocationSearch?: boolean; isInCompare?: boolean; onAddToCompare?: (school: School) => void; onRemoveFromCompare?: (urn: number) => void; laAvgAttainment8?: number | null; } export function SecondarySchoolRow({ school, isLocationSearch, isInCompare = false, onAddToCompare, onRemoveFromCompare, laAvgAttainment8, }: SecondarySchoolRowProps) { const handleCompareClick = () => { if (isInCompare) { onRemoveFromCompare?.(school.urn); } else { onAddToCompare?.(school); } }; const ofstedBadge = buildOfstedListBadge(school); const phase = getPhaseStyle(school.phase); const att8 = school.attainment_8_score; // The school's own Attainment 8 is a same-school figure — shown whenever it // exists (special schools included; their type tag on line 2 gives context). // Only the vs-LA-average delta, a benchmark comparison, is dropped for // special schools / PRUs / AP, whose pupils aren't measured against it fairly. const laDelta = att8 != null && !isSpecialSchool(school) && laAvgAttainment8 != null ? att8 - laAvgAttainment8 : null; const typeLabel = schoolTypeLabel(school); const flags = schoolFlags(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: KS4 stats */}
{att8 != null ? att8.toFixed(1) : '—'} Attainment 8 {laDelta != null && ( = 0 ? styles.deltaPositive : styles.deltaNegative}`}> {laDelta >= 0 ? '+' : ''}{laDelta.toFixed(1)} vs LA 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 */}
View {(onAddToCompare || onRemoveFromCompare) && ( )}
); }