import { useEffect, useState } from "react"
import { ChevronRightIcon, ExternalLinkIcon } from "lucide-react"
import { toast } from "sonner"
import type { Fix } from "@workspace/types"
import { Alert, AlertDescription } from "@workspace/ui/components/alert"
import { Button } from "@workspace/ui/components/button"
import { Card, CardContent, CardHeader, CardTitle, CardAction } from "@workspace/ui/components/card"
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@workspace/ui/components/collapsible"
import { Input } from "@workspace/ui/components/input"
import { Separator } from "@workspace/ui/components/separator"
import { Textarea } from "@workspace/ui/components/textarea"
import { useItemAction } from "@/lib/api"
import { AgentMessage } from "./agent-message"
import { DiffView } from "./diff-view"
import { Screenshots } from "./screenshots"
/** The fix, as the latest thing in the thread: live while it runs, then the diff and the approval. */
export function FixPanel({ itemId, fix }: { itemId: number; fix: Fix }) {
const act = useItemAction(itemId)
const [title, setTitle] = useState(fix.title)
const [body, setBody] = useState(fix.body)
// The agent proposes the text; take its latest proposal unless it was edited here.
useEffect(() => setTitle(fix.title), [fix.title])
useEffect(() => setBody(fix.body), [fix.body])
if (fix.status === "working") {
return fix.live ? (
Preparing checkouts of {fix.repos.join(", ")} for the fix
) } const discard = ( ) if (fix.status === "failed") { return ({fix.error}
{fix.branch}
The fix agent made no changes.
) : ({d.stat.trim()}