"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";
import {
CheckCircle,
XCircle,
Loader2,
GitBranch,
Layers3,
Plus,
Bug,
} from "lucide-react";
import { useRouter } from "next/navigation";
import { getThreadTitle } from "@/lib/thread";
import { getActivePlanItems } from "@open-swe/shared/open-swe/tasks";
import { ThreadDisplayInfo } from "./types";
interface ThreadSwitcherProps {
currentThread: ThreadDisplayInfo;
allThreads: ThreadDisplayInfo[];
onThreadSelect: (thread: ThreadDisplayInfo) => void;
onNewChat: () => void;
}
export function ThreadSwitcher({
currentThread,
allThreads,
onThreadSelect,
onNewChat,
}: ThreadSwitcherProps) {
const [open, setOpen] = useState(false);
const router = useRouter();
const getStatusIcon = (status: ThreadDisplayInfo["status"]) => {
switch (status) {
case "running":
return ;
case "completed":
return ;
case "failed":
return ;
default:
return
;
}
};
const getStatusColor = (status: ThreadDisplayInfo["status"]) => {
switch (status) {
case "running":
return "bg-blue-950 text-blue-400";
case "completed":
return "bg-green-950 text-green-400";
case "failed":
return "bg-red-950 text-red-400";
default:
return "bg-gray-800 text-gray-400";
}
};
const getPRStatusColor = (status: string) => {
switch (status) {
case "merged":
return "text-purple-400";
case "open":
return "text-green-400";
case "draft":
return "text-gray-400";
case "closed":
return "text-red-400";
default:
return "text-gray-400";
}
};
const otherThreads = allThreads.filter((t) => t.id !== currentThread.id);
const runningCount = otherThreads.filter(
(t) => t.status === "running",
).length;
return (
All Threads
{/* New Chat Button */}
{/* Current Thread */}
Current Thread
{getStatusIcon(currentThread.status)}
{currentThread.title}
{currentThread.repository}
{currentThread.status}
{currentThread.githubIssue && (
)}
{/* TODO: Add PR info to state, then hook this up. */}
{/* {currentThread.pullRequest && (
)} */}
{/* Other Threads */}
{otherThreads.length > 0 && (
Other Threads
{otherThreads.map((thread) => (
))}
)}
);
}