import { CheckIcon, XIcon } from 'lucide-react' import { type PropsWithChildren, type ReactNode } from 'react' import { Button, cn } from 'ui' import { getConfirmFooterBar, type ConfirmFooterApprovalState } from './Confirm.utils' interface ConfirmFooterProps { message: string cancelLabel?: string confirmLabel?: string confirmLabelLoading?: string isLoading?: boolean isDisabled?: boolean outcome?: 'success' | 'error' | 'denied' showActions?: boolean action?: ReactNode /** Omit the confirm button so only Skip remains (unparseable / unapplyable previews). */ denyOnly?: boolean /** Escape hatch for consumers that attach the bar directly under their own frame. */ className?: string onCancel?: () => void | Promise onConfirm?: () => void | Promise } /** Action bar that sits at the bottom of `Confirm`. */ export const ConfirmFooter = ({ message, cancelLabel = 'Cancel', confirmLabel = 'Confirm', confirmLabelLoading = 'Working...', isLoading = false, isDisabled = false, outcome, showActions = true, action, denyOnly = false, className, onCancel, onConfirm, }: ConfirmFooterProps) => { const isInactive = isLoading || isDisabled return (
{outcome === 'success' && } {outcome === 'error' && } {message}
{(showActions || action) && (
{showActions && ( <> {!denyOnly && ( )} )} {action}
)}
) } interface ConfirmProps { /** * Result of `getManualToolApprovalConfirmState`. Interactive buttons only for * `approval-requested`; `approval-responded` is the post-approve loading morph. */ state?: ConfirmFooterApprovalState message: string cancelLabel?: string confirmLabel?: string confirmLabelLoading?: string successMessage?: string errorMessage?: string deniedMessage?: string footerAction?: ReactNode extraLoading?: boolean isLoading?: boolean /** * Children fill the remaining height of the card (e.g. `QueryEditor` in viewport * mode). Omit for content-sized bodies like notebook previews and Edge Function blocks. */ fill?: boolean className?: string /** Omit the confirm button so only Skip remains. */ denyOnly?: boolean onCancel?: () => void | Promise onConfirm?: () => void | Promise } /** * Card that wraps an assistant tool preview and optionally attaches a confirm footer * below it. The card owns the frame; the footer hangs inset from the sides so it reads * as tucked under the card. Nested surfaces (QueryEditor viewport, unframed notebook * previews, Edge Function blocks) fill the body. */ export const Confirm = ({ children, state, message, cancelLabel = 'Skip', confirmLabel = 'Confirm', confirmLabelLoading = 'Working...', successMessage, errorMessage, deniedMessage, footerAction, extraLoading = false, isLoading = false, fill = false, className, denyOnly = false, onCancel, onConfirm, }: PropsWithChildren) => { const bar = getConfirmFooterBar(state) const showLoading = bar.isLoading || extraLoading || isLoading const isApprovalRequested = state === 'approval-requested' const isApprovalResponded = state === 'approval-responded' const showActions = isApprovalRequested || isApprovalResponded const outcomeMessages = { success: successMessage, error: errorMessage, denied: deniedMessage, } const footerMessage = bar.outcome ? (outcomeMessages[bar.outcome] ?? message) : message return (
{children}
{bar.show && ( )}
) }