'use client'; import { useState } from 'react'; import { Play, Square, RotateCw, Activity, Zap, Terminal } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ProcessInfo, ProcessStateCode, getProcessStateClass, formatUptime, canStartProcess, canStopProcess } from '@/lib/supervisor/types'; import { useStartProcess, useStopProcess, useRestartProcess } from '@/lib/hooks/useSupervisor'; import { SignalSender } from './SignalSender'; import { StdinInput } from './StdinInput'; import { cn } from '@/lib/utils/cn'; interface ProcessCardProps { process: ProcessInfo; isSelected?: boolean; onSelectionChange?: (processId: string, selected: boolean) => void; } export function ProcessCard({ process, isSelected = false, onSelectionChange }: ProcessCardProps) { const [showSignalModal, setShowSignalModal] = useState(false); const [showStdinModal, setShowStdinModal] = useState(false); const startMutation = useStartProcess(); const stopMutation = useStopProcess(); const restartMutation = useRestartProcess(); const fullName = `${process.group}:${process.name}`; const isLoading = startMutation.isPending || stopMutation.isPending || restartMutation.isPending; const uptime = process.state === 20 ? formatUptime(process.start, process.now) : 'Not running'; const handleStart = () => startMutation.mutate({ name: fullName }); const handleStop = () => stopMutation.mutate({ name: fullName }); const handleRestart = () => restartMutation.mutate(fullName); const handleCardClick = () => { if (onSelectionChange) { onSelectionChange(fullName, !isSelected); } }; return (
{onSelectionChange && (
{ e.stopPropagation(); onSelectionChange(fullName, e.target.checked); }} className="h-4 w-4 rounded border-input text-primary focus:ring-2 focus:ring-primary focus:ring-offset-2" />
)}
{process.name}

{process.group}

{process.statename}
{/* Metrics */}
PID: {process.pid || 'N/A'}
Uptime: {uptime}
{process.exitstatus !== 0 && (
Exit Status: {process.exitstatus}
)}
{/* Error Description */} {process.spawnerr && (
{process.spawnerr}
)} {/* Actions */}
e.stopPropagation()}>
{/* Description */} {process.description && process.description !== 'pid ' + process.pid && (

{process.description}

)}
{/* Signal Modal */} {showSignalModal && ( setShowSignalModal(false)} /> )} {/* Stdin Modal */} {showStdinModal && ( setShowStdinModal(false)} /> )}
); }