"use client" import { useMemo } from "react" import Link from "next/link" import { BarChart3, TrendingDown, TrendingUp, Minus, Trophy } from "lucide-react" import { ChartCardShell } from "@/shared/components/charts/chart-card-shell" import { TrendLineChart } from "@/shared/components/charts/trend-line-chart" import { Badge } from "@/shared/components/ui/badge" import { formatDate } from "@/shared/lib/utils" import type { StudentDashboardGradeProps } from "@/modules/homework/types" type TrendDirection = "up" | "down" | "flat" | "unknown" const computeTrend = (trend: { percentage: number }[]): TrendDirection => { if (trend.length < 2) return "unknown" const latest = trend[trend.length - 1].percentage const prev = trend[trend.length - 2].percentage if (latest > prev) return "up" if (latest < prev) return "down" return "flat" } const TrendIcon = ({ direction }: { direction: TrendDirection }) => { if (direction === "up") { return } if (direction === "down") { return } if (direction === "flat") { return } return null } export function ChildGradeSummary({ grades, childId, childName, }: { grades: StudentDashboardGradeProps childId: string childName: string }) { const hasGradeTrend = grades.trend.length > 0 const ranking = grades.ranking const latestGrade = grades.trend[grades.trend.length - 1] const trendDirection = computeTrend(grades.trend) const chartData = useMemo( () => grades.trend.map((item, idx) => ({ title: item.assignmentTitle, score: Math.round(item.percentage), fullTitle: item.assignmentTitle, date: formatDate(item.submittedAt), index: idx + 1, rawScore: item.score, maxScore: item.maxScore, })), [grades.trend], ) return (
Latest Score
{latestGrade ? `${Math.round(latestGrade.percentage)}%` : "-"}
{hasGradeTrend ? : null}
{latestGrade ? (
{latestGrade.score}/{latestGrade.maxScore}
) : null}
Class Rank
{ranking ? `${ranking.rank}/${ranking.classSize}` : "-"}
{ranking ? (
Top {Math.ceil((ranking.rank / ranking.classSize) * 100)}%
) : null}
{grades.recent.length > 0 ? (
Recent Grades
{grades.recent.slice(0, 3).map((r) => (
{r.assignmentTitle}
{formatDate(r.submittedAt)}
{r.score}/{r.maxScore} ))}
) : null}
) }