"use client" import { useState } from "react" import { useTranslations } from "next-intl" import { Sparkles, CheckCircle, Clock, AlertCircle, Target } from "lucide-react" import { notify } from "@/shared/lib/notify" import { Button } from "@/shared/components/ui/button" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/shared/components/ui/card" import { Badge } from "@/shared/components/ui/badge" import { SectionErrorBoundary } from "@/shared/components/section-error-boundary" import { SkeletonCard } from "@/shared/components/ui/skeleton" import { useAiClient } from "@/modules/ai/context/ai-client-provider" import type { StudyPathResult, StudyPathInput } from "@/modules/ai/types" type AiStudyPathProps = { studentId: string subject?: string currentMastery?: StudyPathInput["currentMastery"] learningGoal?: string /** 教材 ID(传入后自动获取知识图谱注入路径推荐,对标 Squirrel AI) */ textbookId?: string onStartLearning?: (step: StudyPathResult["learningPath"][number]) => void } /** * 学生学习路径推荐组件 * * 参考 Squirrel AI 纳米级知识图谱和 Century Tech 自适应路径。 * 为学生生成个性化学习路径: * - 当前水平评估 * - 分步骤学习路径(含状态、建议、预计时间) * - 学习总结 * - 鼓励语 * * V3:支持 textbookId 参数,自动获取知识图谱与掌握度数据, * 使 AI 沿前置依赖链推荐学习路径。 */ export function AiStudyPath({ studentId, subject, currentMastery, learningGoal, textbookId, onStartLearning, }: AiStudyPathProps): React.ReactNode { const t = useTranslations("ai") const aiClient = useAiClient() const [loading, setLoading] = useState(false) const [path, setPath] = useState(null) const handleGenerate = async (): Promise => { if (!aiClient.recommendStudyPath) { notify.error(t("studyPath.error")) return } setLoading(true) try { const result = await aiClient.recommendStudyPath({ studentId, subject, currentMastery, learningGoal, textbookId, }) if (result.success && result.data) { setPath(result.data) notify.success(t("studyPath.title")) } else { notify.error(result.message ?? t("studyPath.error")) } } catch { notify.error(t("studyPath.error")) } finally { setLoading(false) } } const statusConfig = { mastered: { icon: CheckCircle, color: "text-green-500", badge: "secondary" as const, label: t("studyPath.mastered"), }, in_progress: { icon: Clock, color: "text-blue-500", badge: "default" as const, label: t("studyPath.inProgress"), }, needs_work: { icon: AlertCircle, color: "text-orange-500", badge: "destructive" as const, label: t("studyPath.needsWork"), }, } return ( {t("studyPath.title")} {t("studyPath.description")} {loading ? ( ) : path ? (
{/* 当前水平 */}

{path.currentLevel}

{/* 学习路径步骤 */}

{t("studyPath.nextSteps")}

{path.learningPath.map((step, index) => { const config = statusConfig[step.status] const Icon = config.icon return (
{/* 连接线 */} {index < path.learningPath.length - 1 ? (
) : null}
{step.step}. {step.knowledgePoint} {config.label}

{step.recommendedAction}

{step.estimatedTime}
{onStartLearning && step.status !== "mastered" ? ( ) : null}
) })}
{/* 学习总结 */}

{t("studyPath.title")}

{path.summary}

{/* 鼓励语 */}

{path.motivation}

) : ( )} ) }