"use client"; import React from "react"; import { Play, Clock, CheckCircle, AlertCircle, Bot, User, Activity, Zap, Eye, List, Loader2, ArrowRight, AlertTriangle, RotateCcw, } from "lucide-react"; import { Button } from "~/components/ui/button"; import { Badge } from "~/components/ui/badge"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "~/components/ui/tabs"; import { ScrollArea } from "~/components/ui/scroll-area"; import { Alert, AlertDescription } from "~/components/ui/alert"; interface StepData { id: string; name: string; description: string | null; type: | "wizard_action" | "robot_action" | "parallel_steps" | "conditional_branch"; parameters: Record; order: number; actions?: { id: string; name: string; description: string | null; type: string; parameters: Record; order: number; pluginId: string | null; }[]; } interface TrialData { id: string; status: "scheduled" | "in_progress" | "completed" | "aborted" | "failed"; scheduledAt: Date | null; startedAt: Date | null; completedAt: Date | null; duration: number | null; sessionNumber: number | null; notes: string | null; experimentId: string; participantId: string | null; wizardId: string | null; experiment: { id: string; name: string; description: string | null; studyId: string; }; participant: { id: string; participantCode: string; demographics: Record | null; }; } interface TrialEvent { type: string; timestamp: Date; data?: unknown; message?: string; } interface WizardExecutionPanelProps { trial: TrialData; currentStep: StepData | null; steps: StepData[]; currentStepIndex: number; trialEvents: TrialEvent[]; onStepSelect: (index: number) => void; onExecuteAction: ( actionId: string, parameters?: Record, ) => void; onExecuteRobotAction: ( pluginName: string, actionId: string, parameters: Record, options?: { autoAdvance?: boolean }, ) => Promise; activeTab: "current" | "timeline" | "events"; // Deprecated/Ignored onTabChange: (tab: "current" | "timeline" | "events") => void; // Deprecated/Ignored onSkipAction: ( pluginName: string, actionId: string, parameters: Record, options?: { autoAdvance?: boolean }, ) => Promise; isExecuting?: boolean; onNextStep?: () => void; onCompleteTrial?: () => void; completedActionsCount: number; onActionCompleted: () => void; } export function WizardExecutionPanel({ trial, currentStep, steps, currentStepIndex, trialEvents, onStepSelect, onExecuteAction, onExecuteRobotAction, activeTab, onTabChange, onSkipAction, isExecuting = false, onNextStep, onCompleteTrial, completedActionsCount, onActionCompleted, }: WizardExecutionPanelProps) { // Local state removed in favor of parent state to prevent reset on re-render // const [completedCount, setCompletedCount] = React.useState(0); const activeActionIndex = completedActionsCount; const getStepIcon = (type: string) => { switch (type) { case "wizard_action": return User; case "robot_action": return Bot; case "parallel_steps": return Activity; case "conditional_branch": return AlertCircle; default: return Play; } }; const getStepStatus = (stepIndex: number) => { if (stepIndex < currentStepIndex) return "completed"; if (stepIndex === currentStepIndex && trial.status === "in_progress") return "active"; return "pending"; }; const getStepVariant = (status: string) => { switch (status) { case "completed": return "default"; case "active": return "secondary"; case "pending": return "outline"; default: return "outline"; } }; // Pre-trial state if (trial.status === "scheduled") { return (

Trial Ready

{steps.length} steps prepared for execution

Ready to Begin

Use the control panel to start this trial

Experiment: {trial.experiment.name}
Participant: {trial.participant.participantCode}
); } // Post-trial state if ( trial.status === "completed" || trial.status === "aborted" || trial.status === "failed" ) { return (

Trial {trial.status === "completed" ? "Completed" : "Ended"}

{trial.completedAt && `Ended at ${new Date(trial.completedAt).toLocaleTimeString()} `}

Execution Complete

Review results and captured data

{trialEvents.length} events recorded
); } // Active trial state return (
{/* Header */}

Trial Execution

{currentStepIndex + 1} / {steps.length}
{currentStep && (

{currentStep.name}

)}
{/* Simplified Content - Sequential Focus */}
{currentStep ? (
{/* Header Info (Simplified) */}

{currentStep.name}

{currentStep.description && (
{currentStep.description}
)}
{/* Action Sequence */} {currentStep.actions && currentStep.actions.length > 0 && (

Execution Sequence

{currentStep.actions.map((action, idx) => { const isCompleted = idx < activeActionIndex; const isActive = idx === activeActionIndex; const isPending = idx > activeActionIndex; return (
{isCompleted ? : idx + 1}
{action.name}
{action.description && (
{action.description}
)}
{action.pluginId && isActive && (
)} {/* Fallback for actions with no plugin ID (e.g. manual steps) */} {!action.pluginId && isActive && (
)} {/* Completed State Indicator */} {isCompleted && (
Done
{action.pluginId && ( <> )}
)}
) })}
{/* Manual Advance Button */} {activeActionIndex >= (currentStep.actions?.length || 0) && (
)}
)} {/* Manual Wizard Controls (If applicable) */} {currentStep.type === "wizard_action" && (

Manual Controls

)}
) : (
No active step
)}
); }