"use client"; import { AlertTriangle, Camera, Clock, Hand, HelpCircle, Lightbulb, MessageSquare, Pause, RotateCcw, Target, Video, VideoOff, Volume2, VolumeX, Zap, } from "lucide-react"; import { useState } from "react"; import { Button } from "~/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "~/components/ui/dialog"; import { Label } from "~/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "~/components/ui/select"; import { Textarea } from "~/components/ui/textarea"; interface ActionControlsProps { trialId: string; currentStep: { id: string; name: string; type: | "wizard_action" | "robot_action" | "parallel_steps" | "conditional_branch"; description?: string; parameters?: Record; duration?: number; } | null; onActionComplete: ( actionId: string, actionData: Record, ) => void; isConnected: boolean; } interface QuickAction { id: string; label: string; icon: React.ComponentType<{ className?: string }>; type: "primary" | "secondary" | "emergency"; action: string; description: string; requiresConfirmation?: boolean; } export function ActionControls({ trialId: _trialId, currentStep, onActionComplete, isConnected: _isConnected, }: ActionControlsProps) { const [isRecording, setIsRecording] = useState(false); const [isVideoOn, setIsVideoOn] = useState(true); const [isAudioOn, setIsAudioOn] = useState(true); const [isCommunicationOpen, setIsCommunicationOpen] = useState(false); const [interventionNote, setInterventionNote] = useState(""); const [selectedEmergencyAction, setSelectedEmergencyAction] = useState(""); const [showEmergencyDialog, setShowEmergencyDialog] = useState(false); // Quick action definitions const quickActions: QuickAction[] = [ { id: "manual_intervention", label: "Manual Intervention", icon: Hand, type: "primary", action: "manual_intervention", description: "Take manual control of the interaction", }, { id: "provide_hint", label: "Provide Hint", icon: Lightbulb, type: "primary", action: "provide_hint", description: "Give a helpful hint to the participant", }, { id: "clarification", label: "Clarification", icon: HelpCircle, type: "primary", action: "clarification", description: "Provide clarification or explanation", }, { id: "pause_interaction", label: "Pause", icon: Pause, type: "secondary", action: "pause_interaction", description: "Temporarily pause the interaction", }, { id: "reset_step", label: "Reset Step", icon: RotateCcw, type: "secondary", action: "reset_step", description: "Reset the current step", }, { id: "emergency_stop", label: "Emergency Stop", icon: AlertTriangle, type: "emergency", action: "emergency_stop", description: "Emergency stop all robot actions", requiresConfirmation: true, }, ]; const emergencyActions = [ { value: "stop_robot", label: "Stop Robot Movement" }, { value: "safe_position", label: "Move to Safe Position" }, { value: "disable_motors", label: "Disable All Motors" }, { value: "cut_power", label: "Emergency Power Cut" }, ]; const handleQuickAction = (action: QuickAction) => { if (action.requiresConfirmation) { setShowEmergencyDialog(true); return; } onActionComplete(action.id, { action_type: action.action, notes: action.description, timestamp: new Date().toISOString(), }); }; const handleEmergencyAction = () => { if (!selectedEmergencyAction) return; onActionComplete("emergency_action", { emergency_type: selectedEmergencyAction, notes: interventionNote || "Emergency action executed", timestamp: new Date().toISOString(), }); setShowEmergencyDialog(false); setSelectedEmergencyAction(""); setInterventionNote(""); }; const handleInterventionSubmit = () => { if (!interventionNote.trim()) return; onActionComplete("wizard_intervention", { intervention_type: "note", content: interventionNote, timestamp: new Date().toISOString(), }); setInterventionNote(""); setIsCommunicationOpen(false); }; const toggleRecording = () => { const newState = !isRecording; setIsRecording(newState); onActionComplete("recording_control", { action: newState ? "start_recording" : "stop_recording", timestamp: new Date().toISOString(), }); }; const toggleVideo = () => { const newState = !isVideoOn; setIsVideoOn(newState); onActionComplete("video_control", { action: newState ? "video_on" : "video_off", timestamp: new Date().toISOString(), }); }; const toggleAudio = () => { const newState = !isAudioOn; setIsAudioOn(newState); onActionComplete("audio_control", { action: newState ? "audio_on" : "audio_off", timestamp: new Date().toISOString(), }); }; return (
{/* Media Controls */} Media Controls
{/* Quick Actions */} Quick Actions
{quickActions.map((action) => ( ))}
{/* Step-Specific Controls */} {currentStep && currentStep.type === "wizard_action" && ( Step Controls
Current step:{" "} {currentStep.name}
Use the controls below to execute wizard actions for this step.
)} {/* Communication Dialog */} Add Intervention Note Record an intervention or observation during the trial.