"use client"; import { useState } from "react"; import Image from "next/image"; import type { ScriptCard } from "~/types/script"; import { TypeBadge, UpdateableBadge } from "./Badge"; interface ScriptCardListProps { script: ScriptCard; onClick: (script: ScriptCard) => void; isSelected?: boolean; onToggleSelect?: (slug: string) => void; } export function ScriptCardList({ script, onClick, isSelected = false, onToggleSelect, }: ScriptCardListProps) { const [imageError, setImageError] = useState(false); const handleImageError = () => { setImageError(true); }; const handleCheckboxClick = (e: React.MouseEvent) => { e.stopPropagation(); if (onToggleSelect && script.slug) { onToggleSelect(script.slug); } }; const formatDate = (dateString?: string) => { if (!dateString) return "Unknown"; try { return new Date(dateString).toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric", }); } catch { return "Unknown"; } }; const getCategoryNames = () => { if (!script.categoryNames || script.categoryNames.length === 0) return "Uncategorized"; return script.categoryNames.join(", "); }; const getRepoName = (url?: string): string => { if (!url) return ""; const match = /github\.com\/([^\/]+)\/([^\/]+)/.exec(url); if (match) { return `${match[1]}/${match[2]}`; } return url; }; return (
onClick(script)} > {/* Checkbox */} {onToggleSelect && (
{isSelected && ( )}
)}
{/* Logo */}
{script.logo && !imageError ? ( {`${script.name} ) : (
{script.name?.charAt(0)?.toUpperCase() || "?"}
)}
{/* Main Content */}
{/* Header Row */}

{script.name || "Unnamed Script"}

{script.updateable && } {script.repository_url && ( {getRepoName(script.repository_url)} )}
{script.isDownloaded ? "Downloaded" : "Not Downloaded"}
{/* Right side - Website link */} {script.website && ( e.stopPropagation()} > Website )}
{/* Description */}

{script.description || "No description available"}

{/* Metadata Row */}
Categories: {getCategoryNames()}
Created: {formatDate(script.date_created)}
{(script.os ?? script.version) && (
{script.os && script.version ? `${script.os.charAt(0).toUpperCase() + script.os.slice(1)} ${script.version}` : script.os ? script.os.charAt(0).toUpperCase() + script.os.slice(1) : script.version ? `Version ${script.version}` : ""}
)} {script.interface_port && (
Port: {script.interface_port}
)}
ID: {script.slug || "unknown"}
); }