'use client'; import { useState } from 'react'; import { format, parseISO } from 'date-fns'; import { Play, Check, SkipForward, Clock, BookOpen, Target, AlertCircle, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { cn } from '@/lib/utils'; import { StudyTimer } from './StudyTimer'; import { CompletionDialog } from './CompletionDialog'; import type { StudySession, SessionType, SessionStatus } from '@/lib/types/study-plan'; interface SessionCardProps { session: StudySession; topicName?: string; onStart: () => void; onComplete: (rating: number, notes: string) => void; onSkip: (reason: string) => void; isStarting?: boolean; isCompleting?: boolean; isSkipping?: boolean; } const getSessionTypeIcon = (type: SessionType) => { switch (type) { case 'learn': return ; case 'review': return ; case 'practice': return ; case 'quiz': return ; default: return ; } }; const getStatusColor = (status: SessionStatus): string => { const colors: Record = { scheduled: 'bg-purple-100 text-purple-800 border-purple-200', in_progress: 'bg-blue-100 text-blue-800 border-blue-200', completed: 'bg-green-100 text-green-800 border-green-200', skipped: 'bg-orange-100 text-orange-800 border-orange-200', rescheduled: 'bg-indigo-100 text-indigo-800 border-indigo-200', }; return colors[status] || 'bg-gray-100 text-gray-800'; }; const formatDuration = (minutes: number): string => { if (minutes < 60) return `${minutes}min`; const hours = Math.floor(minutes / 60); const mins = minutes % 60; return mins > 0 ? `${hours}h ${mins}min` : `${hours}h`; }; export function SessionCard({ session, topicName, onStart, onComplete, onSkip, isStarting, isCompleting, isSkipping, }: SessionCardProps) { const [showCompletionDialog, setShowCompletionDialog] = useState(false); const [skipReason, setSkipReason] = useState(''); const isInProgress = session.status === 'in_progress'; const isScheduled = session.status === 'scheduled'; const isCompleted = session.status === 'completed'; const isSkipped = session.status === 'skipped'; const handleTimerComplete = () => { setShowCompletionDialog(true); }; const handleCompleteWithRating = (rating: number, notes: string) => { onComplete(rating, notes); setShowCompletionDialog(false); }; return ( <>
{/* Left side: Icon and Info */}
{/* Topic name (prominent) */} {topicName && (

{topicName}

)} {/* Session type and time */}
{getSessionTypeIcon(session.session_type)} {session.session_type} {format(parseISO(session.scheduled_date), 'h:mm a')} {formatDuration(session.scheduled_duration_minutes)}
{/* Status badge */} {session.status.replace('_', ' ')} {/* Rating if completed */} {isCompleted && session.rating && (
{'⭐'.repeat(session.rating)}
)} {/* Notes if available */} {session.notes && !isSkipped && (

“{session.notes}”

)}
{/* Right side: Timer or Actions */}
{isInProgress ? ( <> ) : isScheduled ? (
Skip this session? {topicName ? ( <>Skipping the {session.session_type} session for {topicName}. ) : ( <>You're about to skip this {session.session_type} session. )}

You can always create a new session later if needed.
Cancel onSkip('Skipped by user')} className="bg-orange-500 hover:bg-orange-600" > Skip Session
) : isCompleted ? (
) : isSkipped ? (
) : null}
{/* Completion Dialog */} ); }