/** * SchoolDetailView Component * Displays comprehensive school information with performance charts */ 'use client'; import { useRouter } from 'next/navigation'; import { useComparison } from '@/hooks/useComparison'; import { PerformanceChart } from './PerformanceChart'; import { SchoolMap } from './SchoolMap'; import type { School, SchoolResult, AbsenceData } from '@/lib/types'; import { formatPercentage, formatProgress, calculateTrend } from '@/lib/utils'; import styles from './SchoolDetailView.module.css'; interface SchoolDetailViewProps { schoolInfo: School; yearlyData: SchoolResult[]; absenceData: AbsenceData | null; } export function SchoolDetailView({ schoolInfo, yearlyData, absenceData }: SchoolDetailViewProps) { const router = useRouter(); const { addSchool, removeSchool, isSelected } = useComparison(); const isInComparison = isSelected(schoolInfo.urn); // Get latest results const latestResults = yearlyData.length > 0 ? yearlyData[yearlyData.length - 1] : null; // Handle add/remove from comparison const handleComparisonToggle = () => { if (isInComparison) { removeSchool(schoolInfo.urn); } else { addSchool(schoolInfo); } }; return (
{/* Back Navigation */}
{/* Header Section */}

{schoolInfo.school_name}

{schoolInfo.local_authority && ( {schoolInfo.local_authority} )} {schoolInfo.school_type && ( {schoolInfo.school_type} )}
{schoolInfo.address && (

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

)}
{/* Latest Results Summary */} {latestResults && (

Latest Results ({latestResults.year})

{latestResults.rwm_expected_pct !== null && (
RWM Expected Standard
{formatPercentage(latestResults.rwm_expected_pct)}
)} {latestResults.rwm_high_pct !== null && (
RWM Higher Standard
{formatPercentage(latestResults.rwm_high_pct)}
)} {latestResults.reading_progress !== null && (
Reading Progress
{formatProgress(latestResults.reading_progress)}
)} {latestResults.writing_progress !== null && (
Writing Progress
{formatProgress(latestResults.writing_progress)}
)} {latestResults.maths_progress !== null && (
Maths Progress
{formatProgress(latestResults.maths_progress)}
)}
{(latestResults.reading_progress !== null || latestResults.writing_progress !== null || latestResults.maths_progress !== null) && (

Progress scores: 0 = national average. Positive = above average, negative = below average.

)}
)} {/* Map */} {schoolInfo.latitude && schoolInfo.longitude && (

Location

)} {/* Performance Over Time */} {yearlyData.length > 0 && (

Performance Over Time

)} {/* Detailed Metrics */} {latestResults && (

Detailed Metrics

{/* Reading Metrics */}

Reading

{latestResults.reading_expected_pct !== null && (
Expected {formatPercentage(latestResults.reading_expected_pct)}
)} {latestResults.reading_high_pct !== null && (
Higher {formatPercentage(latestResults.reading_high_pct)}
)} {latestResults.reading_progress !== null && (
Progress {formatProgress(latestResults.reading_progress)}
)} {latestResults.reading_avg_score !== null && (
Avg Score {latestResults.reading_avg_score.toFixed(1)}
)}
{/* Writing Metrics */}

Writing

{latestResults.writing_expected_pct !== null && (
Expected {formatPercentage(latestResults.writing_expected_pct)}
)} {latestResults.writing_high_pct !== null && (
Higher {formatPercentage(latestResults.writing_high_pct)}
)} {latestResults.writing_progress !== null && (
Progress {formatProgress(latestResults.writing_progress)}
)}
{/* Maths Metrics */}

Maths

{latestResults.maths_expected_pct !== null && (
Expected {formatPercentage(latestResults.maths_expected_pct)}
)} {latestResults.maths_high_pct !== null && (
Higher {formatPercentage(latestResults.maths_high_pct)}
)} {latestResults.maths_progress !== null && (
Progress {formatProgress(latestResults.maths_progress)}
)} {latestResults.maths_avg_score !== null && (
Avg Score {latestResults.maths_avg_score.toFixed(1)}
)}
)} {/* Absence Data */} {absenceData && (

Absence Data

{absenceData.overall_absence_rate !== null && (
Overall Absence Rate
{formatPercentage(absenceData.overall_absence_rate)}
)} {absenceData.persistent_absence_rate !== null && (
Persistent Absence
{formatPercentage(absenceData.persistent_absence_rate)}
)}
)} {/* All Years Data Table */} {yearlyData.length > 0 && (

Historical Data

{yearlyData.map((result) => ( ))}
Year RWM Expected RWM Higher Reading Progress Writing Progress Maths Progress
{result.year} {result.rwm_expected_pct !== null ? formatPercentage(result.rwm_expected_pct) : '-'} {result.rwm_high_pct !== null ? formatPercentage(result.rwm_high_pct) : '-'} {result.reading_progress !== null ? formatProgress(result.reading_progress) : '-'} {result.writing_progress !== null ? formatProgress(result.writing_progress) : '-'} {result.maths_progress !== null ? formatProgress(result.maths_progress) : '-'}
)}
); }