/* Copyright 2026 Marimo. All rights reserved. */ import { useAtomValue, useStore } from "jotai"; import { ChevronDown, ChevronUp, SparklesIcon } from "lucide-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { stagedAICellsAtom, useStagedCells } from "@/core/ai/staged-cells"; import type { CellId } from "@/core/cells/ids"; import { getNextIndex } from "@/utils/arrays"; import { cn } from "@/utils/cn"; import { AcceptCompletionButton, RejectCompletionButton, } from "../../ai/completion-handlers"; import { acceptStagedCell, rejectStagedCell } from "../../cell/StagedAICell"; import { useRunCells } from "../../cell/useRunCells"; import { scrollAndHighlightCell } from "../../links/cell-link"; export const PendingAICells: React.FC = () => { const [currentIndex, setCurrentIndex] = useState(null); const stagedAiCells = useAtomValue(stagedAICellsAtom); const listStagedCells = [...stagedAiCells.keys()]; const store = useStore(); const { deleteStagedCell, removeStagedCell } = useStagedCells(store); const runCell = useRunCells(); if (stagedAiCells.size === 0) { return null; } const scrollToCell = (cellId: CellId) => { scrollAndHighlightCell(cellId, "focus"); }; const clickNext = (direction: "up" | "down") => { const newIndex = getNextIndex( currentIndex, listStagedCells.length, direction, ); setCurrentIndex(newIndex); scrollToCell(listStagedCells[newIndex]); }; const acceptAllCompletions = () => { for (const [cellId, edit] of stagedAiCells) { acceptStagedCell(cellId, edit, removeStagedCell, deleteStagedCell); } }; const rejectAllCompletions = () => { for (const [cellId, edit] of stagedAiCells) { rejectStagedCell(cellId, edit, removeStagedCell, deleteStagedCell); } }; const runAllCells = () => { runCell(listStagedCells); }; const cyanShadow = "shadow-[0_0_6px_0_#00A2C733]"; return (
{currentIndex === null ? `${listStagedCells.length} pending` : `${currentIndex + 1} / ${listStagedCells.length}`}
); };