import * as React from "react"; import { Undo2, RefreshCw } from "lucide-react"; import { cn } from "@/lib/utils"; import { Card, CardHeader, CardTitle, CardDescription, CardAction, CardFooter, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Spinner } from "@/components/ui/spinner"; /** * CopilotActionCard — WealthX DS (Molecule) * * Renders an agentic action the broker Copilot proposes or has performed * (create a task, send an email, update a deal) with a confirm / undo / retry * affordance and a status badge. Composes Card + Button + Badge + Spinner. * * Pure display: the host wires onConfirm/onUndo/onRetry/onCancel to the real * side-effect (and any toast). */ export type CopilotActionStatus = "proposed" | "pending" | "done" | "failed"; export interface CopilotActionCardProps { /** What the action does, e.g. "Create follow-up task". */ title: string; /** Optional detail, e.g. "Call Jordan re: pre-approval · due Fri". */ description?: string; /** Lifecycle state. Defaults to "proposed". */ status?: CopilotActionStatus; /** Confirm a proposed action. */ onConfirm?: () => void; /** Dismiss a proposed action. */ onCancel?: () => void; /** Undo a completed action. */ onUndo?: () => void; /** Retry a failed action. */ onRetry?: () => void; confirmLabel?: string; cancelLabel?: string; undoLabel?: string; retryLabel?: string; className?: string; } const STATUS_BADGE: Record< Exclude, { label: string; variant: "warning" | "success" | "destructive" } > = { pending: { label: "Working…", variant: "warning" }, done: { label: "Done", variant: "success" }, failed: { label: "Failed", variant: "destructive" }, }; export function CopilotActionCard({ title, description, status = "proposed", onConfirm, onCancel, onUndo, onRetry, confirmLabel = "Confirm", cancelLabel = "Cancel", undoLabel = "Undo", retryLabel = "Retry", className, }: CopilotActionCardProps) { const badge = status === "proposed" ? null : STATUS_BADGE[status]; return ( {title} {description && ( {description} )} {badge && ( {status === "pending" && } {badge.label} )} {status === "proposed" && (onConfirm || onCancel) && ( {onConfirm && ( )} {onCancel && ( )} )} {status === "done" && onUndo && ( )} {status === "failed" && onRetry && ( )} ); }