"use client" import { useState, useEffect } from "react" import { cn } from "@/lib/utils" import { Brain, ChevronDown, ChevronRight, Check, Clock, Search, Lightbulb } from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" interface ThinkingStep { id: string title: string status: "pending" | "active" | "completed" duration?: number details?: string } interface ThinkingIndicatorProps { isActive: boolean steps?: ThinkingStep[] currentStep?: number className?: string onToggle?: (expanded: boolean) => void defaultExpanded?: boolean } const defaultThinkingSteps: ThinkingStep[] = [ { id: "1", title: "Understanding your question", status: "pending" }, { id: "2", title: "Searching relevant information", status: "pending" }, { id: "3", title: "Analyzing sources", status: "pending" }, { id: "4", title: "Formulating response", status: "pending" } ] export function ThinkingIndicator({ isActive, steps = defaultThinkingSteps, currentStep = 0, className, onToggle, defaultExpanded = false }: ThinkingIndicatorProps) { const [isExpanded, setIsExpanded] = useState(defaultExpanded) const [activeSteps, setActiveSteps] = useState(steps) useEffect(() => { if (isActive) { const timer = setInterval(() => { setActiveSteps(prev => { const newSteps = [...prev] const currentActiveIndex = newSteps.findIndex(step => step.status === "active") if (currentActiveIndex >= 0 && currentActiveIndex < newSteps.length - 1) { newSteps[currentActiveIndex].status = "completed" newSteps[currentActiveIndex + 1].status = "active" } else if (currentActiveIndex === -1 && newSteps.length > 0) { newSteps[0].status = "active" } return newSteps }) }, 2000) return () => clearInterval(timer) } }, [isActive]) useEffect(() => { if (!isActive) { setActiveSteps(steps.map(step => ({ ...step, status: "pending" }))) } }, [isActive, steps]) const handleToggle = () => { const newExpanded = !isExpanded setIsExpanded(newExpanded) onToggle?.(newExpanded) } const getStepIcon = (status: string) => { switch (status) { case "completed": return case "active": return
default: return
} } if (!isActive) return null return (
Thinking {isExpanded ? ( ) : ( )}
Analyzing...
{isExpanded && (
{activeSteps.map((step, index) => (
{getStepIcon(step.status)}
{step.title}
{step.details && step.status === "active" && (
{step.details}
)}
{step.status === "active" && ( )} {step.status === "completed" && step.duration && ( {step.duration}ms )}
))}
)}
) } interface CompactThinkingIndicatorProps { isActive: boolean className?: string } export function CompactThinkingIndicator({ isActive, className }: CompactThinkingIndicatorProps) { if (!isActive) return null return (
Thinking...
) }