import React, { createContext, useContext, useState, useEffect } from 'react'; interface Module { id: string; name: string; description: string; concepts: string[]; difficulty: 'beginner' | 'intermediate' | 'advanced'; } interface LearningPath { id: string; name: string; description: string; modules: Module[]; } interface LearningContextType { paths: LearningPath[]; currentPath: string | null; currentModule: string | null; setCurrentPath: (pathId: string) => void; setCurrentModule: (moduleId: string) => void; loading: boolean; error: string | null; } const LearningContext = createContext(undefined); export const LearningProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [paths, setPaths] = useState([]); const [currentPath, setCurrentPath] = useState(null); const [currentModule, setCurrentModule] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchPaths = async () => { try { const response = await fetch('/api/learning-paths'); const data = await response.json(); setPaths(data); setLoading(false); } catch (err) { setError('Failed to load learning paths'); setLoading(false); } }; fetchPaths(); }, []); return ( {children} ); }; export const useLearning = () => { const context = useContext(LearningContext); if (context === undefined) { throw new Error('useLearning must be used within a LearningProvider'); } return context; };