import { Separator } from "@/components/ui/separator"; import { fetchVersions } from "@/lib/data"; import { extractDate } from "@/lib/time"; import { AppVersion, Script } from "@/lib/types"; import { X } from "lucide-react"; import Image from "next/image"; import { basePath } from "@/config/siteConfig"; import { useEffect, useState } from "react"; import { getDisplayValueFromType } from "./ScriptInfoBlocks"; import Alerts from "./ScriptItems/Alerts"; import Buttons from "./ScriptItems/Buttons"; import DefaultPassword from "./ScriptItems/DefaultPassword"; import Description from "./ScriptItems/Description"; import InstallCommand from "./ScriptItems/InstallCommand"; import InterFaces from "./ScriptItems/InterFaces"; import Tooltips from "./ScriptItems/Tooltips"; function ScriptItem({ item, setSelectedScript }: { item: Script; setSelectedScript: (script: string | null) => void }) { const closeScript = () => { window.history.pushState({}, document.title, window.location.pathname); setSelectedScript(null); }; const [versions, setVersions] = useState([]); useEffect(() => { fetchVersions() .then((fetchedVersions) => { console.log("Fetched Versions: ", fetchedVersions); if (Array.isArray(fetchedVersions)) { setVersions(fetchedVersions); } else if (fetchedVersions && typeof fetchedVersions === "object") { setVersions([fetchedVersions]); } else { setVersions([]); } }) .catch((error) => console.error("Error fetching versions:", error)); }, []); const defaultInstallMethod = item.install_methods?.[0]; const os = defaultInstallMethod?.resources?.os || "Proxmox Node"; const version = defaultInstallMethod?.resources?.version || ""; return (

Selected Script

((e.currentTarget as HTMLImageElement).src = `/${basePath}/logo.png`)} height={400} alt={item.name} unoptimized />

{item.name} {getDisplayValueFromType(item.type)}

Date added: {extractDate(item.date_created)}

Default OS: {os} {version}

{(() => { const getDisplayValueFromRAM = (ram: number) => ram >= 1024 ? `${Math.floor(ram / 1024)}GB` : `${ram}MB`; const IconText = ({ icon, label }: { icon: React.ReactNode; label: string }) => ( {icon} {label} ); const CPUIcon = ( ); const RAMIcon = ( ); const HDDIcon = ( ); const ResourceDisplay = ({ title, cpu, ram, hdd, }: { title: string; cpu: number | null; ram: number | null; hdd: number | null; }) => { const getDisplayValueFromRAM = (ram: number) => ram >= 1024 ? `${Math.floor(ram / 1024)}GB` : `${ram}MB`; const IconText = ({ icon, label }: { icon: React.ReactNode; label: string }) => ( {icon} {label} ); const hasCPU = typeof cpu === "number" && cpu > 0; const hasRAM = typeof ram === "number" && ram > 0; const hasHDD = typeof hdd === "number" && hdd > 0; if (!hasCPU && !hasRAM && !hasHDD) return null; return (
{title}: {hasCPU && ( <> | )} {hasRAM && ( <> | )} {hasHDD && }
); }; const defaultSettings = item.install_methods.find((method) => method.type === "default"); const alpineSettings = item.install_methods.find((method) => method.type === "alpine"); return ( <> {defaultSettings?.resources && ( )} {alpineSettings?.resources && ( )} ); })()}
{(() => { if (versions.length === 0) { return

Loading versions...

; } const cleanSlug = item.slug.replace(/[^a-z0-9]/gi, "").toLowerCase(); const matched = versions.find((v) => { const cleanName = v.name.replace(/[^a-z0-9]/gi, "").toLowerCase(); return cleanName === cleanSlug || cleanName.includes(cleanSlug); }); if (!matched) return null; return (
Version: {matched.version} ( {extractDate( matched.date instanceof Date ? matched.date.toISOString() : matched.date || "", )} Info
); })()}

How to {item.type == "misc" ? "use" : "install"}

); } export default ScriptItem;