'use client' import { useState, useEffect, useCallback } from 'react' import { Settings, MessageSquare, HelpCircle, RefreshCw } from 'lucide-react' import { CompanionMode, TeacherSettings, FeedbackType } from '@/lib/companion/types' import { DEFAULT_TEACHER_SETTINGS, STORAGE_KEYS } from '@/lib/companion/constants' // Components import { ModeToggle } from './ModeToggle' import { PhaseTimeline } from './companion-mode/PhaseTimeline' import { StatsGrid } from './companion-mode/StatsGrid' import { SuggestionList } from './companion-mode/SuggestionList' import { EventsCard } from './companion-mode/EventsCard' import { LessonContainer } from './lesson-mode/LessonContainer' import { SettingsModal } from './modals/SettingsModal' import { FeedbackModal } from './modals/FeedbackModal' import { OnboardingModal } from './modals/OnboardingModal' // Hooks import { useCompanionData } from '@/hooks/companion/useCompanionData' import { useLessonSession } from '@/hooks/companion/useLessonSession' import { useKeyboardShortcuts } from '@/hooks/companion/useKeyboardShortcuts' export function CompanionDashboard() { // Mode state const [mode, setMode] = useState('companion') // Modal states const [showSettings, setShowSettings] = useState(false) const [showFeedback, setShowFeedback] = useState(false) const [showOnboarding, setShowOnboarding] = useState(false) // Settings const [settings, setSettings] = useState(DEFAULT_TEACHER_SETTINGS) // Load settings from localStorage useEffect(() => { const stored = localStorage.getItem(STORAGE_KEYS.SETTINGS) if (stored) { try { const parsed = JSON.parse(stored) setSettings({ ...DEFAULT_TEACHER_SETTINGS, ...parsed }) } catch { // Invalid stored settings } } // Check if onboarding needed const onboardingStored = localStorage.getItem(STORAGE_KEYS.ONBOARDING_STATE) if (!onboardingStored) { setShowOnboarding(true) } // Restore last mode const lastMode = localStorage.getItem(STORAGE_KEYS.LAST_MODE) as CompanionMode if (lastMode && ['companion', 'lesson', 'classic'].includes(lastMode)) { setMode(lastMode) } }, []) // Save mode to localStorage useEffect(() => { localStorage.setItem(STORAGE_KEYS.LAST_MODE, mode) }, [mode]) // Companion data hook const { data: companionData, loading: companionLoading, refresh } = useCompanionData() // Lesson session hook const { session, startLesson, endLesson, pauseLesson, resumeLesson, extendTime, skipPhase, saveReflection, addHomework, removeHomework, isPaused, } = useLessonSession({ onOvertimeStart: () => { // Play sound if enabled if (settings.soundNotifications) { // TODO: Play notification sound } }, }) // Handle pause/resume toggle const handlePauseToggle = useCallback(() => { if (isPaused) { resumeLesson() } else { pauseLesson() } }, [isPaused, pauseLesson, resumeLesson]) // Keyboard shortcuts useKeyboardShortcuts({ onPauseResume: mode === 'lesson' && session ? handlePauseToggle : undefined, onExtend: mode === 'lesson' && session && !isPaused ? () => extendTime(5) : undefined, onNextPhase: mode === 'lesson' && session && !isPaused ? skipPhase : undefined, onCloseModal: () => { setShowSettings(false) setShowFeedback(false) setShowOnboarding(false) }, enabled: settings.showKeyboardShortcuts, }) // Handle settings save const handleSaveSettings = (newSettings: TeacherSettings) => { setSettings(newSettings) localStorage.setItem(STORAGE_KEYS.SETTINGS, JSON.stringify(newSettings)) } // Handle feedback submit const handleFeedbackSubmit = async (type: FeedbackType, title: string, description: string) => { const response = await fetch('/api/admin/companion/feedback', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ type, title, description, sessionId: session?.sessionId, }), }) if (!response.ok) { throw new Error('Failed to submit feedback') } } // Handle onboarding complete const handleOnboardingComplete = (data: { state?: string; schoolType?: string }) => { localStorage.setItem(STORAGE_KEYS.ONBOARDING_STATE, JSON.stringify({ ...data, completed: true, completedAt: new Date().toISOString(), })) setShowOnboarding(false) setSettings({ ...settings, onboardingCompleted: true }) } // Handle lesson start const handleStartLesson = (data: { classId: string; subject: string; topic?: string; templateId?: string }) => { startLesson(data) setMode('lesson') } return (
{/* Header */}
{/* Refresh Button */} {mode === 'companion' && ( )} {/* Feedback Button */} {/* Settings Button */} {/* Help Button */}
{/* Main Content */} {mode === 'companion' && (
{/* Phase Timeline */}

Aktuelle Phase

{companionData ? ( p.status === 'active')} /> ) : (
)}
{/* Stats */} {/* Two Column Layout */}
{/* Suggestions */} { // Navigate to action target window.location.href = suggestion.actionTarget }} /> {/* Events */}
{/* Quick Start Lesson Button */}

Bereit fuer die naechste Stunde?

Starten Sie den Lesson-Modus fuer strukturierten Unterricht.

)} {mode === 'lesson' && ( )} {mode === 'classic' && (

Classic Mode

Die klassische Ansicht ohne Timer und Phasenstruktur.

Dieser Modus ist fuer flexible Unterrichtsgestaltung gedacht.

)} {/* Modals */} setShowSettings(false)} settings={settings} onSave={handleSaveSettings} /> setShowFeedback(false)} onSubmit={handleFeedbackSubmit} /> setShowOnboarding(false)} onComplete={handleOnboardingComplete} />
) }