/** * SecondarySchoolDetailView Component * Dedicated detail view for secondary schools with tabbed navigation: * Overview | Academic | Admissions | Wellbeing | Parents | Finance */ 'use client'; import { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import { useComparison } from '@/hooks/useComparison'; import { PerformanceChart } from './PerformanceChart'; import { MetricTooltip } from './MetricTooltip'; import type { School, SchoolResult, AbsenceData, OfstedInspection, OfstedParentView, SchoolCensus, SchoolAdmissions, SenDetail, Phonics, SchoolDeprivation, SchoolFinance, NationalAverages, } from '@/lib/types'; import { formatPercentage, formatProgress, formatAcademicYear } from '@/lib/utils'; import styles from './SecondarySchoolDetailView.module.css'; const OFSTED_LABELS: Record = { 1: 'Outstanding', 2: 'Good', 3: 'Requires Improvement', 4: 'Inadequate', }; const RC_LABELS: Record = { 1: 'Exceptional', 2: 'Strong', 3: 'Expected standard', 4: 'Needs attention', 5: 'Urgent improvement', }; const RC_CATEGORIES = [ { key: 'rc_inclusion' as const, label: 'Inclusion' }, { key: 'rc_curriculum_teaching' as const, label: 'Curriculum & Teaching' }, { key: 'rc_achievement' as const, label: 'Achievement' }, { key: 'rc_attendance_behaviour' as const, label: 'Attendance & Behaviour' }, { key: 'rc_personal_development' as const, label: 'Personal Development' }, { key: 'rc_leadership_governance' as const, label: 'Leadership & Governance' }, { key: 'rc_early_years' as const, label: 'Early Years' }, { key: 'rc_sixth_form' as const, label: 'Sixth Form' }, ]; type Tab = 'overview' | 'academic' | 'admissions' | 'wellbeing' | 'parents' | 'finance'; interface SecondarySchoolDetailViewProps { schoolInfo: School; yearlyData: SchoolResult[]; absenceData: AbsenceData | null; ofsted: OfstedInspection | null; parentView: OfstedParentView | null; census: SchoolCensus | null; admissions: SchoolAdmissions | null; senDetail: SenDetail | null; phonics: Phonics | null; deprivation: SchoolDeprivation | null; finance: SchoolFinance | null; } function progressClass(val: number | null | undefined, modStyles: Record): string { if (val == null) return ''; if (val > 0) return modStyles.progressPositive; if (val < 0) return modStyles.progressNegative; return ''; } function deprivationDesc(decile: number): string { if (decile <= 3) return `This school is in one of England's most deprived areas (decile ${decile}/10). Many pupils may face additional challenges at home.`; if (decile <= 7) return `This school is in an area with average levels of deprivation (decile ${decile}/10).`; return `This school is in one of England's less deprived areas (decile ${decile}/10).`; } export function SecondarySchoolDetailView({ schoolInfo, yearlyData, ofsted, parentView, admissions, senDetail, deprivation, finance, absenceData, }: SecondarySchoolDetailViewProps) { const router = useRouter(); const { addSchool, removeSchool, isSelected } = useComparison(); const isInComparison = isSelected(schoolInfo.urn); const latestResults = yearlyData.length > 0 ? yearlyData[yearlyData.length - 1] : null; const [activeTab, setActiveTab] = useState('overview'); const [nationalAvg, setNationalAvg] = useState(null); useEffect(() => { fetch('/api/national-averages') .then(r => r.ok ? r.json() : null) .then(data => { if (data) setNationalAvg(data); }) .catch(() => {}); }, []); const secondaryAvg = nationalAvg?.secondary ?? {}; const hasSixthForm = schoolInfo.age_range?.includes('18') ?? false; const hasFinance = finance != null && finance.per_pupil_spend != null; const hasParents = parentView != null || ofsted != null; const hasDeprivation = deprivation != null && deprivation.idaci_decile != null; const p8Suspended = latestResults != null && latestResults.year >= 202425; const admissionsTag = (() => { const policy = schoolInfo.admissions_policy?.toLowerCase() ?? ''; if (policy.includes('selective')) return 'Selective'; const denom = schoolInfo.religious_denomination ?? ''; if (denom && denom !== 'Does not apply') return 'Faith priority'; return null; })(); const tabs: { key: Tab; label: string }[] = [ { key: 'overview', label: 'Overview' }, { key: 'academic', label: 'Academic' }, { key: 'admissions', label: 'Admissions' }, { key: 'wellbeing', label: 'Wellbeing' }, ...(hasParents ? [{ key: 'parents' as Tab, label: 'Parents' }] : []), ...(hasFinance ? [{ key: 'finance' as Tab, label: 'Finance' }] : []), ]; const handleComparisonToggle = () => { if (isInComparison) { removeSchool(schoolInfo.urn); } else { addSchool(schoolInfo); } }; return (
{/* ── Header ─────────────────────────────────────── */}

{schoolInfo.school_name}

{schoolInfo.school_type && ( {schoolInfo.school_type} )} {schoolInfo.gender && schoolInfo.gender !== 'Mixed' && ( {schoolInfo.gender}'s school )} {schoolInfo.age_range && ( {schoolInfo.age_range} )} {hasSixthForm && ( Sixth form )} {admissionsTag && ( {admissionsTag} )}
{schoolInfo.address && (

{schoolInfo.address}{schoolInfo.postcode && `, ${schoolInfo.postcode}`}

)}
{schoolInfo.headteacher_name && ( Headteacher: {schoolInfo.headteacher_name} )} {schoolInfo.website && ( School website ↗ )} {latestResults?.total_pupils != null && ( Pupils: {latestResults.total_pupils.toLocaleString()} {schoolInfo.capacity != null && ` (capacity: ${schoolInfo.capacity})`} )} {schoolInfo.trust_name && ( Part of {schoolInfo.trust_name} )}
{/* ── Tab navigation (sticky) ─────────────────────── */} {/* ── Overview Tab ─────────────────────────────────── */} {activeTab === 'overview' && (
{/* Ofsted summary card */} {ofsted && (

{ofsted.framework === 'ReportCard' ? 'Ofsted Report Card' : 'Ofsted Rating'} {ofsted.inspection_date && ( {' '}Inspected {new Date(ofsted.inspection_date).toLocaleDateString('en-GB', { month: 'long', year: 'numeric' })} )} Full report ↗

{ofsted.framework === 'ReportCard' ? (

From November 2025, Ofsted replaced single overall grades with Report Cards.

) : ofsted.overall_effectiveness ? (
{OFSTED_LABELS[ofsted.overall_effectiveness]}
) : ( <>

From September 2024, Ofsted no longer gives a single overall grade.

{[ { label: 'Quality of Education', value: ofsted.quality_of_education }, { label: 'Behaviour & Attitudes', value: ofsted.behaviour_attitudes }, { label: 'Personal Development', value: ofsted.personal_development }, { label: 'Leadership & Management', value: ofsted.leadership_management }, ].filter(({ value }) => value != null).map(({ label, value }) => (
{label}
{OFSTED_LABELS[value!]}
))}
)} {parentView?.q_recommend_pct != null && parentView.total_responses != null && parentView.total_responses > 0 && (

{Math.round(parentView.q_recommend_pct)}% of parents would recommend this school ({parentView.total_responses.toLocaleString()} responses)

)}
)} {/* Attainment 8 headline */} {latestResults?.attainment_8_score != null && (

GCSE Performance at a Glance ({formatAcademicYear(latestResults.year)})

Attainment 8
{latestResults.attainment_8_score.toFixed(1)}
{secondaryAvg.attainment_8_score != null && (
National avg: {secondaryAvg.attainment_8_score.toFixed(1)}
)}
{latestResults.english_maths_standard_pass_pct != null && (
English & Maths Grade 4+
{formatPercentage(latestResults.english_maths_standard_pass_pct)}
{secondaryAvg.english_maths_standard_pass_pct != null && (
National avg: {secondaryAvg.english_maths_standard_pass_pct.toFixed(0)}%
)}
)} {admissions?.oversubscribed != null && (
Admissions
{admissions.oversubscribed ? 'Oversubscribed' : 'Places available'}
Last year
)}
{p8Suspended && (
Progress 8 scores for 2024/25 are not used for accountability purposes following the KS2 assessment disruption. Treat with caution.
)}
)} {/* Admissions summary */} {admissions && (admissions.published_admission_number != null || admissions.total_applications != null) && (

Admissions at a Glance

{admissions.published_admission_number != null && (
Year 7 places (PAN)
{admissions.published_admission_number}
)} {admissions.total_applications != null && (
Total applications
{admissions.total_applications.toLocaleString()}
)} {admissions.first_preference_offer_pct != null && (
1st choice offer rate
{admissions.first_preference_offer_pct}%
)}
)} {/* SEN & school context summary */} {(latestResults?.sen_support_pct != null || latestResults?.sen_ehcp_pct != null || latestResults?.total_pupils != null) && (

School Context

{latestResults?.total_pupils != null && (
Total pupils
{latestResults.total_pupils.toLocaleString()}
{schoolInfo.capacity != null && (
Capacity: {schoolInfo.capacity}
)}
)} {latestResults?.sen_support_pct != null && (
SEN support
{formatPercentage(latestResults.sen_support_pct)}
)} {latestResults?.sen_ehcp_pct != null && (
EHCP
{formatPercentage(latestResults.sen_ehcp_pct)}
)}
)} {/* Top Parent View scores */} {parentView != null && parentView.total_responses != null && parentView.total_responses > 0 && (

What Parents Say

{[ { label: 'My child is happy here', pct: parentView.q_happy_pct }, { label: 'Would recommend this school', pct: parentView.q_recommend_pct }, ].filter(q => q.pct != null).map(({ label, pct }) => (
{label}
{Math.round(pct!)}%
))}
)}
)} {/* ── Academic Tab ─────────────────────────────────── */} {activeTab === 'academic' && latestResults && (

GCSE Results ({formatAcademicYear(latestResults.year)})

GCSE results for Year 11 pupils. National averages shown for comparison.

{p8Suspended && (
Progress 8 scores for 2024/25 are not used for accountability purposes following the KS2 assessment disruption. Treat with caution.
)}
{latestResults.attainment_8_score != null && (
Attainment 8
{latestResults.attainment_8_score.toFixed(1)}
{secondaryAvg.attainment_8_score != null && (
National avg: {secondaryAvg.attainment_8_score.toFixed(1)}
)}
)} {latestResults.progress_8_score != null && (
Progress 8
{formatProgress(latestResults.progress_8_score)}
{(latestResults.progress_8_lower_ci != null || latestResults.progress_8_upper_ci != null) && (
CI: {latestResults.progress_8_lower_ci?.toFixed(2) ?? '?'} to {latestResults.progress_8_upper_ci?.toFixed(2) ?? '?'}
)}
)} {latestResults.english_maths_standard_pass_pct != null && (
English & Maths Grade 4+
{formatPercentage(latestResults.english_maths_standard_pass_pct)}
{secondaryAvg.english_maths_standard_pass_pct != null && (
National 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)}
{secondaryAvg.english_maths_strong_pass_pct != null && (
National avg: {secondaryAvg.english_maths_strong_pass_pct.toFixed(0)}%
)}
)}
{/* A8 component breakdown */} {(latestResults.progress_8_english != null || latestResults.progress_8_maths != null || latestResults.progress_8_ebacc != null || latestResults.progress_8_open != null) && ( <>

Attainment 8 Components (Progress 8 contribution)

{[ { label: 'English', val: latestResults.progress_8_english }, { label: 'Maths', val: latestResults.progress_8_maths }, { label: 'EBacc subjects', val: latestResults.progress_8_ebacc }, { label: 'Open (other GCSEs)', val: latestResults.progress_8_open }, ].filter(r => r.val != null).map(({ label, val }) => (
{label} {formatProgress(val!)}
))}
)} {/* 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)}
)} {latestResults.ebacc_avg_score != null && (
EBacc average point score {latestResults.ebacc_avg_score.toFixed(2)}
)}
)}
{/* Performance over time */} {yearlyData.length > 0 && (

Results Over Time

{yearlyData.length > 1 && ( <>

Detailed year-by-year figures

{yearlyData.map((result) => ( ))}
Year Attainment 8 Progress 8 Eng & Maths 4+ EBacc entry %
{formatAcademicYear(result.year)} {result.attainment_8_score != null ? result.attainment_8_score.toFixed(1) : '-'} {result.progress_8_score != null ? formatProgress(result.progress_8_score) : '-'} {result.english_maths_standard_pass_pct != null ? formatPercentage(result.english_maths_standard_pass_pct) : '-'} {result.ebacc_entry_pct != null ? formatPercentage(result.ebacc_entry_pct) : '-'}
)}
)}
)} {/* ── Admissions Tab ───────────────────────────────── */} {activeTab === 'admissions' && (

Admissions

{admissionsTag && (
{admissionsTag}{' '} {admissionsTag === 'Selective' ? '— Entry to this school is by selective examination (e.g. 11+).' : `— This school has a faith-based admissions priority (${schoolInfo.religious_denomination}).`}
)} {admissions ? ( <>
{admissions.published_admission_number != null && (
Year 7 places per year (PAN)
{admissions.published_admission_number}
)} {admissions.total_applications != null && (
Total applications
{admissions.total_applications.toLocaleString()}
)} {admissions.first_preference_applications != null && (
1st preference applications
{admissions.first_preference_applications.toLocaleString()}
)} {admissions.first_preference_offer_pct != null && (
Families who got their first choice
{admissions.first_preference_offer_pct}%
)}
{admissions.oversubscribed != null && (
{admissions.oversubscribed ? '⚠ Applications exceeded places last year' : '✓ Places were available last year'}
)}

Historical distance cut-off data is not available for this school. Contact the admissions authority for oversubscription criteria details.

) : (

Admissions data for this school is not yet available.

)} {hasSixthForm && (
This school has a sixth form (Post-16 provision). Post-16 destination data coming soon.
)}
)} {/* ── Wellbeing Tab ────────────────────────────────── */} {activeTab === 'wellbeing' && (
{/* SEN */} {(latestResults?.sen_support_pct != null || latestResults?.sen_ehcp_pct != null) && (

Special Educational Needs (SEN)

{latestResults?.sen_support_pct != null && (
Pupils receiving SEN support
{formatPercentage(latestResults.sen_support_pct)}
SEN support without an EHCP
)} {latestResults?.sen_ehcp_pct != null && (
Pupils with an EHCP
{formatPercentage(latestResults.sen_ehcp_pct)}
Education, Health and Care Plan
)} {latestResults?.total_pupils != null && (
Total pupils
{latestResults.total_pupils.toLocaleString()}
)}
)} {/* Deprivation */} {hasDeprivation && deprivation && (

Local Area Context

{Array.from({ length: 10 }, (_, i) => (
))}
Most deprived Least deprived

{deprivationDesc(deprivation.idaci_decile!)}

)} {latestResults?.sen_support_pct == null && latestResults?.sen_ehcp_pct == null && !hasDeprivation && (

Wellbeing data is not yet available for this school.

)}
)} {/* ── Parents Tab ─────────────────────────────────── */} {activeTab === 'parents' && (
{/* Full Ofsted detail */} {ofsted && (

{ofsted.framework === 'ReportCard' ? 'Ofsted Report Card' : 'Ofsted Rating'} {ofsted.inspection_date && ( {' '}Inspected {new Date(ofsted.inspection_date).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' })} )} Full report ↗

{ofsted.framework === 'ReportCard' ? ( <>

From November 2025, Ofsted replaced single overall grades with Report Cards rating schools across several areas.

{ofsted.rc_safeguarding_met != null && (
Safeguarding
{ofsted.rc_safeguarding_met ? 'Met' : 'Not met'}
)} {RC_CATEGORIES.filter(({ key }) => key !== 'rc_early_years' || ofsted[key] != null).map(({ key, label }) => { const value = ofsted[key] as number | null; return value != null ? (
{label}
{RC_LABELS[value]}
) : null; })}
) : ( <>
{ofsted.overall_effectiveness ? OFSTED_LABELS[ofsted.overall_effectiveness] : 'Not rated'} {ofsted.previous_overall != null && ofsted.previous_overall !== ofsted.overall_effectiveness && ( Previously: {OFSTED_LABELS[ofsted.previous_overall]} )}

From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections.

{[ { label: 'Quality of Teaching', value: ofsted.quality_of_education }, { label: 'Behaviour in School', value: ofsted.behaviour_attitudes }, { label: 'Pupils\' Wider Development', value: ofsted.personal_development }, { label: 'School Leadership', value: ofsted.leadership_management }, ...(ofsted.early_years_provision != null ? [{ label: 'Early Years (Reception)', value: ofsted.early_years_provision }] : []), ].map(({ label, value }) => value != null && (
{label}
{OFSTED_LABELS[value]}
))}
)}
)} {/* Parent View survey */} {parentView && parentView.total_responses != null && parentView.total_responses > 0 && (

What Parents Say {parentView.total_responses.toLocaleString()} responses

From the Ofsted Parent View survey — parents share their experience of this school.

{[ { label: 'Would recommend this school', pct: parentView.q_recommend_pct }, { label: 'My child is happy here', pct: parentView.q_happy_pct }, { label: 'My child feels safe here', pct: parentView.q_safe_pct }, { label: 'Teaching is good', pct: parentView.q_teaching_pct }, { label: 'My child makes good progress', pct: parentView.q_progress_pct }, { label: 'School looks after pupils\' wellbeing', pct: parentView.q_wellbeing_pct }, { label: 'Behaviour is well managed', pct: parentView.q_behaviour_pct }, { label: 'School deals well with bullying', pct: parentView.q_bullying_pct }, { label: 'Communicates well with parents', pct: parentView.q_communication_pct }, ].filter(q => q.pct != null).map(({ label, pct }) => (
{label}
{Math.round(pct!)}%
))}
)} {!ofsted && (!parentView || parentView.total_responses == null || parentView.total_responses === 0) && (

Parent and Ofsted data is not yet available for this school.

)}
)} {/* ── Finance Tab ─────────────────────────────────── */} {activeTab === 'finance' && hasFinance && finance && (

School Finances ({formatAcademicYear(finance.year)})

Per-pupil spending shows how much the school has to spend on each child's education.

Total spend per pupil per year
£{Math.round(finance.per_pupil_spend!).toLocaleString()}
How much the school has to spend on each pupil annually
{finance.teacher_cost_pct != null && (
Share of budget spent on teachers
{finance.teacher_cost_pct.toFixed(1)}%
)} {finance.staff_cost_pct != null && (
Share of budget spent on all staff
{finance.staff_cost_pct.toFixed(1)}%
)} {finance.premises_cost_pct != null && (
Share of budget spent on premises
{finance.premises_cost_pct.toFixed(1)}%
)}
)}
); }