"use client"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import Link from "next/link"; import { Layers } from "lucide-react"; import type { ActionOutputDeck } from "@/modules/deck/deck-action-dto"; import type { ActionOutputCardStats } from "@/modules/card/card-action-dto"; import { PageLayout } from "@/components/ui/PageLayout"; import { PrimaryButton } from "@/design-system/base/button"; interface DeckWithStats extends ActionOutputDeck { stats?: ActionOutputCardStats; } interface DeckSelectorProps { decks: ActionOutputDeck[]; deckStats: Map; } const DeckSelector: React.FC = ({ decks, deckStats }) => { const t = useTranslations("memorize.deck_selector"); const router = useRouter(); const formatCardStats = (stats: ActionOutputCardStats | undefined): string => { if (!stats) return t("noCards"); const parts: string[] = []; if (stats.new > 0) parts.push(`${t("new")}: ${stats.new}`); if (stats.learning > 0) parts.push(`${t("learning")}: ${stats.learning}`); if (stats.review > 0) parts.push(`${t("review")}: ${stats.review}`); if (stats.due > 0) parts.push(`${t("due")}: ${stats.due}`); return parts.length > 0 ? parts.join(" • ") : t("noCards"); }; const getDueCount = (deckId: number): number => { const stats = deckStats.get(deckId); return stats?.due ?? 0; }; return ( {decks.length === 0 ? (

{t("noDecks")}

{t("goToDecks")}
) : ( <>

{t("selectDeck")}

{decks .toSorted((a, b) => a.id - b.id) .map((deck) => { const stats = deckStats.get(deck.id); const dueCount = getDueCount(deck.id); return (
router.push(`/memorize?deck_id=${deck.id}`) } className="flex flex-row items-center p-4 gap-3 hover:cursor-pointer hover:bg-gray-50 transition-colors border-b border-gray-100 last:border-b-0" >
{deck.name}
{formatCardStats(stats)}
{dueCount > 0 && (
{dueCount}
)}
); })}
)}
); }; export { DeckSelector };