import React, { useState, useEffect } from 'react'; import { AlertTriangle, StopCircle, PauseCircle, RotateCcw, Zap, AlertCircle } from 'lucide-react'; import { Button } from './ui/button'; import { InterruptionMatch } from '../utils/interruptionDetector'; interface InterruptionHandlerProps { match: InterruptionMatch | null; onConfirmInterruption: () => void; onCancelInterruption: () => void; onRedirect?: (newMessage: string) => void; className?: string; } export const InterruptionHandler: React.FC = ({ match, onConfirmInterruption, onCancelInterruption, onRedirect, className = '', }) => { const [redirectMessage, setRedirectMessage] = useState(''); const [showRedirectInput, setShowRedirectInput] = useState(false); const [isVisible, setIsVisible] = useState(false); useEffect(() => { if (match) { setIsVisible(true); if (match.keyword.action === 'redirect') { setShowRedirectInput(true); } else { setShowRedirectInput(false); setRedirectMessage(''); } } else { setIsVisible(false); } }, [match]); if (!match) { return null; } const getIcon = () => { switch (match.keyword.action) { case 'stop': return ; case 'pause': return ; case 'redirect': return ; default: return ; } }; const getActionColor = () => { switch (match.keyword.action) { case 'stop': return { bg: 'bg-red-50 dark:bg-red-950/20', border: 'border-red-200 dark:border-red-800/50', text: 'text-red-800 dark:text-red-200', accent: 'text-red-600 dark:text-red-400', }; case 'pause': return { bg: 'bg-amber-50 dark:bg-amber-950/20', border: 'border-amber-200 dark:border-amber-800/50', text: 'text-amber-800 dark:text-amber-200', accent: 'text-amber-600 dark:text-amber-400', }; case 'redirect': return { bg: 'bg-blue-50 dark:bg-blue-950/20', border: 'border-blue-200 dark:border-blue-800/50', text: 'text-blue-800 dark:text-blue-200', accent: 'text-blue-600 dark:text-blue-400', }; default: return { bg: 'bg-orange-50 dark:bg-orange-950/20', border: 'border-orange-200 dark:border-orange-800/50', text: 'text-orange-800 dark:text-orange-200', accent: 'text-orange-600 dark:text-orange-400', }; } }; const colors = getActionColor(); const handleConfirm = () => { if (showRedirectInput && onRedirect && redirectMessage.trim()) { onRedirect(redirectMessage.trim()); } else { onConfirmInterruption(); } }; const getActionTitle = () => { switch (match.keyword.action) { case 'stop': return 'Stop Processing'; case 'pause': return 'Pause Processing'; case 'redirect': return 'Redirect Processing'; default: return 'Interrupt Processing'; } }; const getActionDescription = () => { switch (match.keyword.action) { case 'stop': return 'This will immediately stop the current processing and clear any queued messages.'; case 'pause': return 'This will pause the current processing. Queued messages will be preserved.'; case 'redirect': return 'This will stop current processing and redirect to a new task.'; default: return 'This will interrupt the current processing.'; } }; return (
{/* Main card */}
{/* Header */}
{getIcon()}

{getActionTitle()}

Detected: "{match.matchedText}"

{Math.round(match.confidence * 100)}% confident
{/* Content */}

{getActionDescription()}

{/* Redirect input */} {showRedirectInput && (