import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { mostPopularScripts } from "@/config/siteConfig"; import { extractDate } from "@/lib/time"; import { Category, Script } from "@/lib/types"; import { CalendarPlus } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import { useMemo, useState } from "react"; const ITEMS_PER_PAGE = 3; export const getDisplayValueFromType = (type: string) => { switch (type) { case "ct": return "LXC"; case "vm": return "VM"; case "misc": return ""; default: return ""; } }; export function LatestScripts({ items }: { items: Category[] }) { const [page, setPage] = useState(1); const latestScripts = useMemo(() => { if (!items) return []; const scripts = items.flatMap((category) => category.scripts || []); return scripts.sort( (a, b) => new Date(b.date_created).getTime() - new Date(a.date_created).getTime(), ); }, [items]); const goToNextPage = () => { setPage((prevPage) => prevPage + 1); }; const goToPreviousPage = () => { setPage((prevPage) => prevPage - 1); }; const startIndex = (page - 1) * ITEMS_PER_PAGE; const endIndex = page * ITEMS_PER_PAGE; if (!items) { return null; } return (
{script.name} {getDisplayValueFromType(script.type)}
{script.name} {getDisplayValueFromType(script.type)}