"use client"; import Link from "next/link"; import { useMemo } from "react"; import { ArrowRightIcon } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { lookupDictionary } from "@/lib/api"; import { useResource } from "@/hooks/useResource"; import { useTranslations } from "next-intl"; import type { DictionaryResult, Language } from "@/types/api"; import { RemoveWordButton } from "./removeWordButton"; export function WordCard({ word, lang, collectionId, isRemovable, }: { word: string; lang: Language; collectionId: string; isRemovable: boolean; }) { const td = useTranslations("Definition"); const key = `dict:${lang}:${word.toLowerCase()}`; const state = useResource(key, () => lookupDictionary(lang, word)); const definition = useMemo(() => { if (state.status !== "done" || !state.data) return undefined; const entry = state.data.entries[0]; if (!entry) return null; return { text: entry.senses[0]?.definition ?? null, quantity: entry.senses.length, }; }, [state]); return (

{word}

{isRemovable && }
{state.status === "loading" ? (
) : state.status === "error" || !definition?.text ? (
{td("notFound")}
) : (
{definition.text} {definition.quantity > 1 && ( {td("otherDefinitions", { count: definition.quantity - 1 })} )}
)}
); }