'use client';
import { Button } from './ui/button';
import { StatusBadge } from './Badge';
import { getContrastColor } from '../../lib/colorUtils';
interface InstalledScript {
id: number;
script_name: string;
script_path: string;
container_id: string | null;
server_id: number | null;
server_name: string | null;
server_ip: string | null;
server_user: string | null;
server_password: string | null;
server_auth_type: string | null;
server_ssh_key: string | null;
server_ssh_key_passphrase: string | null;
server_ssh_port: number | null;
server_color: string | null;
installation_date: string;
status: 'in_progress' | 'success' | 'failed';
output_log: string | null;
execution_mode: 'local' | 'ssh';
container_status?: 'running' | 'stopped' | 'unknown';
}
interface ScriptInstallationCardProps {
script: InstalledScript;
isEditing: boolean;
editFormData: { script_name: string; container_id: string };
onInputChange: (field: 'script_name' | 'container_id', value: string) => void;
onEdit: () => void;
onSave: () => void;
onCancel: () => void;
onUpdate: () => void;
onShell: () => void;
onDelete: () => void;
isUpdating: boolean;
isDeleting: boolean;
// New container control props
containerStatus?: 'running' | 'stopped' | 'unknown';
onStartStop: (action: 'start' | 'stop') => void;
onDestroy: () => void;
isControlling: boolean;
}
export function ScriptInstallationCard({
script,
isEditing,
editFormData,
onInputChange,
onEdit,
onSave,
onCancel,
onUpdate,
onShell,
onDelete,
isUpdating,
isDeleting,
containerStatus,
onStartStop,
onDestroy,
isControlling
}: ScriptInstallationCardProps) {
const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleString();
};
return (
{/* Header with Script Name and Status */}
{isEditing ? (
) : (
{script.script_name}
{script.script_path}
)}
{script.status.replace('_', ' ').toUpperCase()}
{/* Details Grid */}
{/* Container ID */}
Container ID
{isEditing ? (
onInputChange('container_id', e.target.value)}
className="w-full px-2 py-1 text-sm font-mono border border-border rounded bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary"
placeholder="Container ID"
/>
) : (
{script.container_id ? (
{script.container_id}
{script.container_status && (
{script.container_status === 'running' ? 'Running' :
script.container_status === 'stopped' ? 'Stopped' :
'Unknown'}
)}
) : '-'}
)}
{/* Server */}
Server
{script.server_name ?? '-'}
{/* Installation Date */}
Installation Date
{formatDate(String(script.installation_date))}
{/* Action Buttons */}
{isEditing ? (
<>
>
) : (
<>
{script.container_id && (
)}
{/* Shell button - only show for SSH scripts with container_id */}
{script.container_id && script.execution_mode === 'ssh' && (
)}
{/* Container Control Buttons - only show for SSH scripts with container_id */}
{script.container_id && script.execution_mode === 'ssh' && (
<>
>
)}
{/* Fallback to old Delete button for non-SSH scripts */}
{(!script.container_id || script.execution_mode !== 'ssh') && (
)}
>
)}
);
}