import HeaderWithAuth from "@/components/headerWithAuth"; import Main from "@/components/main"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import Link from "next/link"; import { isApiError } from "@/lib/api"; import { getCollections } from "@/lib/serverApi"; import type { CollectionResult } from "@/types/api"; import { formatDate, type RelativeTimeTranslator } from "@/lib/formatDate"; import { getTranslations } from "next-intl/server"; import { CreateCollectionDialog } from "./createCollectionDialog"; type Translator = (key: string, values?: Record) => string; function CollectionCard({ collection, tc, tt, tl }: { collection: CollectionResult; tc: Translator; tt: RelativeTimeTranslator; tl: Translator }) { return (

{collection.name === "history" ? tc("history") : collection.name}

{tl(collection.lang)}

{collection.words.length} {collection.words.length === 1 ? tc("word") : tc("words")} • {tc("updated")} {formatDate(collection.updated_at, tt)}

{collection.words.length > 0 && (
{[...collection.words].reverse().slice(0, 3).map((w) => ( {w} ))} {collection.words.length > 3 &&
{tc("andMore", { count: collection.words.length - 3 })}
}
)}
); } export default async function Collections() { const tt = await getTranslations("Time"); const tc = await getTranslations("Common"); const tl = await getTranslations("Languages"); const tCollections = await getTranslations("Collections"); const tApi = await getTranslations("ApiErrors"); let collections: CollectionResult[] = []; let error: string | null = null; try { collections = await getCollections(); } catch (err) { error = isApiError(err) ? tApi(err.kind) : tc("somethingWrong"); } return (

{tCollections("title")}

{error ? (

{error}

) : (
{collections.map((c) => ( ))}
)}
); }