import { useState } from 'react' import { MessageSquare, Zap, CheckCircle2, SkipForward, ChevronDown, ChevronUp } from 'lucide-react' import { cn } from '@/lib/utils' import type { AISessionStepResponse, StepResponseRequest } from '@/types/ai-session' import { FlowPilotOptions } from './FlowPilotOptions' interface FlowPilotStepCardProps { step: AISessionStepResponse isCurrentStep: boolean isProcessing: boolean onRespond: (response: StepResponseRequest) => void } const STEP_TYPE_ICONS = { question: MessageSquare, action: Zap, intake_analysis: MessageSquare, verification: CheckCircle2, info_request: MessageSquare, script_generation: Zap, note: MessageSquare, } as const export function FlowPilotStepCard({ step, isCurrentStep, isProcessing, onRespond }: FlowPilotStepCardProps) { const [freeText, setFreeText] = useState('') const [showFreeText, setShowFreeText] = useState(false) const [isCollapsed, setIsCollapsed] = useState(!isCurrentStep) const content = step.content as Record const stepText = (content.text as string) || '' const contentType = (content.type as string) || step.step_type const isResolutionSuggestion = contentType === 'resolution_suggestion' const Icon = STEP_TYPE_ICONS[step.step_type as keyof typeof STEP_TYPE_ICONS] ?? MessageSquare const handleOptionSelect = (value: string) => { onRespond({ selected_option: value }) } const handleFreeTextSubmit = () => { if (!freeText.trim()) return onRespond({ free_text_input: freeText.trim() }) setFreeText('') setShowFreeText(false) } const handleSkip = () => { onRespond({ was_skipped: true }) } const handleActionComplete = (success: boolean) => { onRespond({ action_result: { success, details: '' }, }) } const handleResolutionResponse = (accepted: boolean) => { if (accepted) { // Parent will handle opening the resolve modal onRespond({ selected_option: 'resolution_accepted' }) } else { onRespond({ free_text_input: 'No, keep investigating. The issue is not resolved.' }) } } // Completed step (collapsed view) if (!isCurrentStep && isCollapsed) { return ( ) } // Expanded completed step if (!isCurrentStep && !isCollapsed) { return (

{stepText}

) } // Current active step return (
{/* Context message */} {step.context_message && (

{step.context_message}

)} {/* Step content */}

{stepText}

{isResolutionSuggestion && typeof content.resolution_summary === 'string' && (

{content.resolution_summary}

)}
{/* Interactive area */} {isCurrentStep && !isProcessing && (
{/* Resolution suggestion buttons */} {isResolutionSuggestion && (
)} {/* Options for question steps */} {!isResolutionSuggestion && step.options.length > 0 && ( )} {/* Action step buttons */} {!isResolutionSuggestion && step.step_type === 'action' && (
)} {/* Free text escape hatch */} {!isResolutionSuggestion && step.allow_free_text && ( <> {!showFreeText ? ( ) : (