"use client"; import { Activity, ArrowRight, Bot, CheckCircle, GitBranch, MessageSquare, Play, Settings, Timer, User, Users } from "lucide-react"; import { useState } from "react"; import { Alert, AlertDescription } from "~/components/ui/alert"; import { Badge } from "~/components/ui/badge"; import { Button } from "~/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; import { Progress } from "~/components/ui/progress"; import { Separator } from "~/components/ui/separator"; interface StepDisplayProps { step: { id: string; name: string; type: "wizard_action" | "robot_action" | "parallel_steps" | "conditional_branch"; description?: string; parameters?: any; duration?: number; actions?: any[]; conditions?: any; branches?: any[]; substeps?: any[]; }; stepIndex: number; totalSteps: number; isActive: boolean; onExecuteAction: (actionType: string, actionData: any) => Promise; } const stepTypeConfig = { wizard_action: { label: "Wizard Action", icon: User, color: "blue", description: "Action to be performed by the wizard operator", }, robot_action: { label: "Robot Action", icon: Bot, color: "green", description: "Automated action performed by the robot", }, parallel_steps: { label: "Parallel Steps", icon: Users, color: "purple", description: "Multiple actions happening simultaneously", }, conditional_branch: { label: "Conditional Branch", icon: GitBranch, color: "orange", description: "Step with conditional logic and branching", }, }; export function StepDisplay({ step, stepIndex, totalSteps, isActive, onExecuteAction }: StepDisplayProps) { const [isExecuting, setIsExecuting] = useState(false); const [completedActions, setCompletedActions] = useState>(new Set()); const stepConfig = stepTypeConfig[step.type]; const StepIcon = stepConfig.icon; const handleActionExecution = async (actionId: string, actionData: any) => { setIsExecuting(true); try { await onExecuteAction(actionId, actionData); setCompletedActions(prev => new Set([...prev, actionId])); } catch (_error) { console.error("Failed to execute action:", _error); } finally { setIsExecuting(false); } }; const renderStepContent = () => { switch (step.type) { case "wizard_action": return (
{step.description && ( {step.description} )} {step.actions && step.actions.length > 0 && (

Available Actions:

{step.actions.map((action: any, index: number) => { const isCompleted = completedActions.has(action.id); return (
{isCompleted ? ( ) : ( )}

{action.name}

{action.description && (

{action.description}

)}
{isActive && !isCompleted && ( )}
); })}
)}
); case "robot_action": return (
{step.description && ( {step.description} )} {step.parameters && (

Robot Parameters:

{JSON.stringify(step.parameters, null, 2)}
)} {isActive && (
Robot executing action...
)}
); case "parallel_steps": return (
{step.description && ( {step.description} )} {step.substeps && step.substeps.length > 0 && (

Parallel Actions:

{step.substeps.map((substep: any, index: number) => (
{index + 1}

{substep.name}

{substep.description && (

{substep.description}

)}
{substep.type}
))}
)}
); case "conditional_branch": return (
{step.description && ( {step.description} )} {step.conditions && (

Conditions:

{JSON.stringify(step.conditions, null, 2)}
)} {step.branches && step.branches.length > 0 && (

Possible Branches:

{step.branches.map((branch: any, index: number) => (

{branch.name}

{branch.condition && (

If: {branch.condition}

)}
{isActive && ( )}
))}
)}
); default: return (

Unknown step type: {step.type}

); } }; return (
{step.name}
{stepConfig.label} Step {stepIndex + 1} of {totalSteps}

{stepConfig.description}

{isActive && ( Active )} {step.duration && (
{step.duration}s
)}
{renderStepContent()} {/* Step Progress Indicator */}
Step Progress {stepIndex + 1}/{totalSteps}
); }