import type React from "react"
import { Check, Clock, CheckCircle, AlertTriangle, ListTodo, X, Circle, CircleCheck } from "lucide-react"
import { cn } from "@/lib/utils"
import { extractTaskListData, type Task, type Section } from "./_utils"
import { getToolTitle } from "../utils"
import type { ToolViewProps } from "../types"
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { ScrollArea } from "@/components/ui/scroll-area"
const TaskItem: React.FC<{ task: Task; index: number }> = ({ task, index }) => {
const isCompleted = task.status === "completed"
const isCancelled = task.status === "cancelled"
const isPending = !isCompleted && !isCancelled
return (
{/* Status Icon */}
{isCompleted && }
{isCancelled && }
{isPending && }
{/* Task Content */}
)
}
const SectionHeader: React.FC<{ section: Section }> = ({ section }) => {
const totalTasks = section.tasks.length
const completedTasks = section.tasks.filter((t) => t.status === "completed").length
return (
{section.title}
{completedTasks}/{totalTasks}
{completedTasks === totalTasks && totalTasks > 0 && (
)}
)
}
const SectionView: React.FC<{ section: Section }> = ({ section }) => {
return (
{section.tasks.map((task, index) => (
))}
{section.tasks.length === 0 && (
)}
)
}
export const TaskListToolView: React.FC = ({
name = 'task-list',
assistantContent,
toolContent,
assistantTimestamp,
toolTimestamp,
isSuccess = true,
isStreaming = false
}) => {
const taskData = extractTaskListData(assistantContent, toolContent)
const toolTitle = getToolTitle(name)
// Process task data
const sections = taskData?.sections || []
const allTasks = sections.flatMap((section) => section.tasks)
const totalTasks = taskData?.total_tasks || 0
const completedTasks = allTasks.filter((t) => t.status === "completed").length
const hasData = taskData?.total_tasks && taskData?.total_tasks > 0
return (
{!isStreaming && (
{completedTasks} / {totalTasks} tasks
{isSuccess ? (
) : (
)}
{isSuccess ? 'Tasks loaded' : 'Failed to load'}
)}
{isStreaming && !hasData ? (
Loading Tasks
Preparing your task list...
) : hasData ? (
{sections.map((section) => )}
) : (
No Tasks Yet
Your task list will appear here once created
)}
{!isStreaming && hasData && (
{sections.length} sections
{completedTasks === totalTasks && totalTasks > 0 && (
All complete
)}
)}
{toolTimestamp && !isStreaming
? new Date(toolTimestamp).toLocaleTimeString()
: assistantTimestamp
? new Date(assistantTimestamp).toLocaleTimeString()
: ''}
)
}