import { useState, useMemo } from 'react'; import { CheckCircle2, Circle, Loader2, ChevronDown, ChevronUp } from 'lucide-react'; import { Progress } from './ui/progress'; import { BottomSheet } from './BottomSheet'; import type { AggregatedTask, TaskSnapshot } from '../hooks/useTaskState'; interface TaskBottomSheetProps { snapshot: TaskSnapshot; open: boolean; onClose: () => void; } function TaskRow({ task, taskMap }: { task: AggregatedTask; taskMap: Map }) { const [expanded, setExpanded] = useState(false); const blockers = useMemo(() => { if (!task.blockedBy?.length) return []; return task.blockedBy .map(id => taskMap.get(`${task.source}:${id}`)) .filter((b): b is AggregatedTask => !!b && b.status !== 'completed'); }, [task.blockedBy, task.source, taskMap]); const isBlocked = blockers.length > 0; const hasExpandable = task.description || task.activeForm; return (
hasExpandable && setExpanded(!expanded)} > {task.status === 'completed' ? ( ) : task.status === 'in_progress' ? ( ) : ( )} {task.subject} {isBlocked && ( blocked )} {hasExpandable && ( {expanded ? ( ) : ( )} )}
{task.status === 'in_progress' && task.activeForm && (
{task.activeForm}
)} {isBlocked && (
waiting: {blockers.map(b => b.subject).join(', ')}
)} {expanded && task.description && (
{task.description}
)}
); } function HistorySection({ tasks, taskMap }: { tasks: AggregatedTask[]; taskMap: Map }) { const [expanded, setExpanded] = useState(false); const completed = tasks.filter(t => t.status === 'completed').length; return (
{expanded && tasks.map(task => ( ))}
); } export function TaskBottomSheet({ snapshot, open, onClose }: TaskBottomSheetProps) { const { tasks, currentRound, completed, total, hasHistory } = snapshot; const pct = total > 0 ? Math.round((completed / total) * 100) : 0; const taskMap = useMemo(() => { const map = new Map(); for (const t of tasks) map.set(`${t.source}:${t.id}`, t); return map; }, [tasks]); const historyTasks = useMemo(() => { if (!hasHistory) return []; const currentIds = new Set(currentRound.map(t => `${t.source}:${t.id}`)); return tasks.filter(t => !currentIds.has(`${t.source}:${t.id}`)); }, [tasks, currentRound, hasHistory]); return (
Tasks {completed}/{total}
{currentRound.map(task => ( ))} {historyTasks.length > 0 && ( )}
); }