'use client' type RevertConfirmDialogProps = { actionType: string entityDescription: string previousState: Record | null newState: Record | null onConfirm: () => void onCancel: () => void } const ACTION_LABELS: Record = { node_add: 'node addition', node_update: 'node update', node_delete: 'node deletion', edge_add: 'edge addition', edge_update: 'edge update', edge_delete: 'edge deletion', } function formatStatePreview(state: Record | null): string { if (!state) return '(none)' const type = state.type as string | undefined const data = state.data as Record | undefined if (type === 'dialogue' && data) { const speaker = (data.speaker as string) || '(no speaker)' const text = (data.text as string) || '(no text)' return `Dialogue: ${speaker}\n"${text.slice(0, 80)}${text.length > 80 ? '…' : ''}"` } if (type === 'choice' && data) { const prompt = (data.prompt as string) || '(no prompt)' const options = (data.options as { label: string }[]) || [] const optionLabels = options.map((o) => o.label || '(empty)').join(', ') return `Choice: ${prompt.slice(0, 60)}${prompt.length > 60 ? '…' : ''}\nOptions: ${optionLabels}` } if (type === 'variable' && data) { const name = (data.variableName as string) || '(unnamed)' const op = (data.operation as string) || 'set' const val = data.value ?? 0 return `Variable: ${name} ${op} ${val}` } // Edge state if (state.source && state.target) { const condition = (state.data as Record | undefined)?.condition as Record | undefined if (condition) { return `Edge: ${state.source} → ${state.target}\nCondition: ${condition.variableName} ${condition.operator} ${condition.value}` } return `Edge: ${state.source} → ${state.target}` } return JSON.stringify(state, null, 2).slice(0, 200) } function getRevertDescription(actionType: string): string { switch (actionType) { case 'node_add': return 'This will delete the node that was added.' case 'node_update': return 'This will restore the node to its previous state.' case 'node_delete': return 'This will re-create the deleted node.' case 'edge_add': return 'This will delete the edge that was added.' case 'edge_update': return 'This will restore the edge to its previous state.' case 'edge_delete': return 'This will re-create the deleted edge.' default: return 'This will undo the change.' } } export default function RevertConfirmDialog({ actionType, entityDescription, previousState, newState, onConfirm, onCancel, }: RevertConfirmDialogProps) { const label = ACTION_LABELS[actionType] || actionType const description = getRevertDescription(actionType) // For revert, the "before" is the current state (newState) and "after" is what we're restoring to (previousState) const isAddition = actionType.endsWith('_add') const isDeletion = actionType.endsWith('_delete') return (
e.stopPropagation()} >

Revert {label}

{entityDescription}

{description}

{!isAddition && (
Current State
                  {formatStatePreview(newState)}
                
)} {!isDeletion && (
{isAddition ? 'Will be removed' : 'Restored State'}
                  {isAddition ? formatStatePreview(newState) : formatStatePreview(previousState)}
                
)} {isDeletion && (
Will be restored
                  {formatStatePreview(previousState)}
                
)}
) }