/** * ResultsSection — KS2 SATs (and, for all-through schools, the KS4 block). * Primary and all-through pages. Server component. */ import type { School, SchoolResult } from '@/lib/types'; import { formatPercentage, formatProgress, formatAcademicYear } from '@/lib/utils'; import { MetricTooltip } from '../MetricTooltip'; import { DeltaChip } from '../DeltaChip'; import { SpecialSchoolNote } from '../SpecialSchoolNote'; import { Section, sectionStyles as styles, progressClass } from './sectionShared'; import { SatsChart } from './charts'; export function ResultsSection({ latestResults, schoolInfo, primaryAvg, secondaryAvg, isAllThrough, isSecondary, isSpecial, hasKS2Results, hasKS4Results, ks2Placeholder, suppressKs2Comparison, suppressKs4Comparison, }: { latestResults: SchoolResult; schoolInfo: School; primaryAvg: Record; secondaryAvg: Record; isAllThrough: boolean; isSecondary: boolean; isSpecial: boolean; hasKS2Results: boolean; hasKS4Results: boolean; ks2Placeholder: boolean; suppressKs2Comparison: boolean; suppressKs4Comparison: boolean; }) { return (

{isAllThrough ? 'SATs & GCSE Results' : isSecondary ? 'GCSE Results' : 'SATs Results'} ({formatAcademicYear(latestResults.year)})

{isSpecial ? (isSecondary ? 'GCSE results for Year 11 pupils.' : 'End-of-primary-school tests taken by Year 6 pupils.') : isAllThrough ? 'KS2 SATs (end of Year 6) and GCSE results (Year 11) — this school covers both. England averages shown for comparison.' : isSecondary ? 'GCSE results for Year 11 pupils. England averages shown for comparison.' : 'End-of-primary-school tests taken by Year 6 pupils. England averages shown for comparison.'}

{/* Explains up front why the England comparison is dropped below, so a 0% headline never reads as a failing grade against a benchmark that doesn't fit. Type-aware copy (special vs PRU vs AP). */} {/* ── Primary / KS2 content ── */} {hasKS2Results && ( <> {isAllThrough && (

Primary — KS2 SATs (Year 6)

)}
{latestResults.rwm_expected_pct !== null && (
Reading, Writing & Maths combined
{formatPercentage(latestResults.rwm_expected_pct)} {!suppressKs2Comparison && primaryAvg.rwm_expected_pct != null && ( )}
{!suppressKs2Comparison && primaryAvg.rwm_expected_pct != null && (
England avg: {primaryAvg.rwm_expected_pct.toFixed(0)}%
)}
)} {latestResults.rwm_high_pct !== null && (
Exceeding expected level (Reading, Writing & Maths)
{formatPercentage(latestResults.rwm_high_pct)} {!suppressKs2Comparison && primaryAvg.rwm_high_pct != null && ( )}
{!suppressKs2Comparison && primaryAvg.rwm_high_pct != null && (
England avg: {primaryAvg.rwm_high_pct.toFixed(0)}%
)}
)}
{!suppressKs2Comparison && latestResults.rwm_expected_pct != null && latestResults.reading_expected_pct != null && latestResults.writing_expected_pct != null && latestResults.maths_expected_pct != null && (
Why is combined lower? A pupil is only counted if they met the bar in{' '} all three subjects. Some passed reading but not writing; some passed writing but not maths.
Reading {latestResults.reading_expected_pct.toFixed(0)}% · Writing {latestResults.writing_expected_pct.toFixed(0)}% · Maths {latestResults.maths_expected_pct.toFixed(0)}% All three {latestResults.rwm_expected_pct.toFixed(0)}%
)} {/* All-zero placeholder rows (special / suppressed) would render as three empty bars against the national markers — misleading, so skip the chart. For a special school with some non-zero subjects, keep the bars but drop the national markers. */} {!ks2Placeholder && ( )} {/* Progress scores row */} {(latestResults.reading_progress != null || latestResults.writing_progress != null || latestResults.maths_progress != null) && (

Progress Scores

{latestResults.reading_progress != null && (
Reading {formatProgress(latestResults.reading_progress)}
)} {latestResults.writing_progress != null && (
Writing {formatProgress(latestResults.writing_progress)}
)} {latestResults.maths_progress != null && (
Maths {formatProgress(latestResults.maths_progress)}
)}
)} {(latestResults.reading_progress !== null || latestResults.writing_progress !== null || latestResults.maths_progress !== null) && (

Progress scores measure how much pupils improved compared to similar schools nationally. Above 0 = better than average, below 0 = below average.

)} )} {/* ── Secondary / KS4 content ── */} {hasKS4Results && ( <> {isAllThrough && (

Secondary — GCSEs (Year 11)

)}
{latestResults.attainment_8_score !== null && (
Attainment 8
{latestResults.attainment_8_score.toFixed(1)}
{!suppressKs4Comparison && secondaryAvg.attainment_8_score != null && (
England avg: {secondaryAvg.attainment_8_score.toFixed(1)}
)}
)} {latestResults.progress_8_score !== null && (
Progress 8
{formatProgress(latestResults.progress_8_score)}
0 = national average
)} {latestResults.english_maths_standard_pass_pct !== null && (
English & Maths Grade 4+
{formatPercentage(latestResults.english_maths_standard_pass_pct)}
{!suppressKs4Comparison && secondaryAvg.english_maths_standard_pass_pct != null && (
England avg: {secondaryAvg.english_maths_standard_pass_pct.toFixed(0)}%
)}
)} {latestResults.english_maths_strong_pass_pct !== null && (
English & Maths Grade 5+
{formatPercentage(latestResults.english_maths_strong_pass_pct)}
{!suppressKs4Comparison && secondaryAvg.english_maths_strong_pass_pct != null && (
England avg: {secondaryAvg.english_maths_strong_pass_pct.toFixed(0)}%
)}
)}
{/* EBacc */} {(latestResults.ebacc_entry_pct !== null || latestResults.ebacc_standard_pass_pct !== null) && ( <>

English Baccalaureate (EBacc)

{latestResults.ebacc_entry_pct !== null && (
Pupils entered for EBacc {formatPercentage(latestResults.ebacc_entry_pct)}
)} {latestResults.ebacc_standard_pass_pct !== null && (
EBacc Grade 4+ {formatPercentage(latestResults.ebacc_standard_pass_pct)}
)} {latestResults.ebacc_strong_pass_pct !== null && (
EBacc Grade 5+ {formatPercentage(latestResults.ebacc_strong_pass_pct)}
)}
)} )}
); }