"use client"; import { useState } from "react"; import type { Script } from "../../types/script"; import { Button } from "./ui/button"; import { useRegisterModal } from "./modal/ModalStackProvider"; interface ScriptVersionModalProps { isOpen: boolean; onClose: () => void; onSelectVersion: (versionType: string) => void; script: Script | null; } export function ScriptVersionModal({ isOpen, onClose, onSelectVersion, script, }: ScriptVersionModalProps) { useRegisterModal(isOpen, { id: "script-version-modal", allowEscape: true, onClose, }); const [selectedVersion, setSelectedVersion] = useState(null); if (!isOpen || !script) return null; // Get available install methods const installMethods = script.install_methods || []; const defaultMethod = installMethods.find( (method) => method.type === "default", ); const alpineMethod = installMethods.find( (method) => method.type === "alpine", ); const handleConfirm = () => { if (selectedVersion) { onSelectVersion(selectedVersion); onClose(); } }; const handleVersionSelect = (versionType: string) => { setSelectedVersion(versionType); }; return (
{/* Header */}

Select Version

{/* Content */}

Choose a version for "{script.name}"

Select the version you want to install. Each version has different resource requirements.

{/* Default Version */} {defaultMethod && (
handleVersionSelect("default")} className={`cursor-pointer rounded-lg border-2 p-4 transition-all ${ selectedVersion === "default" ? "border-primary bg-primary/10" : "border-border bg-card hover:border-primary/50" }`} >
{selectedVersion === "default" && ( )}

{defaultMethod.type}

CPU: {defaultMethod.resources.cpu} cores
RAM: {defaultMethod.resources.ram} MB
HDD: {defaultMethod.resources.hdd} GB
OS: {defaultMethod.resources.os}{" "} {defaultMethod.resources.version}
)} {/* Alpine Version */} {alpineMethod && (
handleVersionSelect("alpine")} className={`cursor-pointer rounded-lg border-2 p-4 transition-all ${ selectedVersion === "alpine" ? "border-primary bg-primary/10" : "border-border bg-card hover:border-primary/50" }`} >
{selectedVersion === "alpine" && ( )}

{alpineMethod.type}

CPU: {alpineMethod.resources.cpu} cores
RAM: {alpineMethod.resources.ram} MB
HDD: {alpineMethod.resources.hdd} GB
OS: {alpineMethod.resources.os}{" "} {alpineMethod.resources.version}
)}
{/* Action Buttons */}
); }