import { useState } from "react"; import type { BudgetIncident } from "@paperclipai/shared"; import { AlertOctagon, ArrowUpRight, PauseCircle } from "lucide-react"; import { formatCents } from "../lib/utils"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; function centsInputValue(value: number) { return (value / 100).toFixed(2); } function parseDollarInput(value: string) { const parsed = Number(value); if (!Number.isFinite(parsed) || parsed < 0) return null; return Math.round(parsed * 100); } export function BudgetIncidentCard({ incident, onRaiseAndResume, onKeepPaused, isMutating, }: { incident: BudgetIncident; onRaiseAndResume: (amountCents: number) => void; onKeepPaused: () => void; isMutating?: boolean; }) { const [draftAmount, setDraftAmount] = useState( centsInputValue(Math.max(incident.amountObserved + 1000, incident.amountLimit)), ); const parsed = parseDollarInput(draftAmount); return (
{incident.scopeType} hard stop
{incident.scopeName} Spending reached {formatCents(incident.amountObserved)} against a limit of {formatCents(incident.amountLimit)}.
{incident.scopeType === "project" ? "Project execution is paused. New work in this project will not start until you resolve the budget incident." : "This scope is paused. New heartbeats will not start until you resolve the budget incident."}
setDraftAmount(event.target.value)} inputMode="decimal" placeholder="0.00" />
{parsed !== null && parsed <= incident.amountObserved ? (

The new budget must exceed current observed spend.

) : null}
); }