/**
* SchoolDetailView Component
* Displays comprehensive school information with performance charts
*/
'use client';
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 { 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 (
{/* Header Section */}
{/* 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)}
)}
)}
{/* Performance Over Time */}
{yearlyData.length > 0 && (
)}
{/* Detailed Metrics */}
{latestResults && (
Detailed Metrics
{/* Reading Metrics */}
📖 Reading
{latestResults.reading_expected_pct !== null && (
Expected Standard
{formatPercentage(latestResults.reading_expected_pct)}
)}
{latestResults.reading_high_pct !== null && (
Higher Standard
{formatPercentage(latestResults.reading_high_pct)}
)}
{latestResults.reading_progress !== null && (
Progress Score
{formatProgress(latestResults.reading_progress)}
)}
{latestResults.reading_avg_score !== null && (
Average Scaled Score
{latestResults.reading_avg_score.toFixed(1)}
)}
{/* Writing Metrics */}
✍️ Writing
{latestResults.writing_expected_pct !== null && (
Expected Standard
{formatPercentage(latestResults.writing_expected_pct)}
)}
{latestResults.writing_high_pct !== null && (
Higher Standard
{formatPercentage(latestResults.writing_high_pct)}
)}
{latestResults.writing_progress !== null && (
Progress Score
{formatProgress(latestResults.writing_progress)}
)}
{/* Maths Metrics */}
Mathematics
{latestResults.maths_expected_pct !== null && (
Expected Standard
{formatPercentage(latestResults.maths_expected_pct)}
)}
{latestResults.maths_high_pct !== null && (
Higher Standard
{formatPercentage(latestResults.maths_high_pct)}
)}
{latestResults.maths_progress !== null && (
Progress Score
{formatProgress(latestResults.maths_progress)}
)}
{latestResults.maths_avg_score !== null && (
Average Scaled 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)}
)}
)}
{/* Map */}
{schoolInfo.latitude && schoolInfo.longitude && (
)}
{/* All Years Data Table */}
{yearlyData.length > 0 && (
Historical Data
| Year |
RWM Expected |
RWM Higher |
Reading Progress |
Writing Progress |
Maths Progress |
Avg. Scaled Score |
{yearlyData.map((result) => (
| {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) : '-'} |
- |
))}
)}
);
}