import { NextRequest, NextResponse } from 'next/server' import { auth } from '@/auth' import { getDeckDetail } from '@/lib/flashcards/deck-queries' export async function GET( _request: NextRequest, { params }: { params: Promise<{ id: string }> }, ) { try { const session = await auth() if (!session?.user?.id) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } const { id } = await params const deck = await getDeckDetail(session.user.id, id) if (!deck) { return NextResponse.json({ error: 'Deck not found' }, { status: 404 }) } const now = new Date() const dueCount = deck.cards.filter((c) => c.due).length const masteredCount = deck.cards.filter((c) => c.mastered).length return NextResponse.json({ deck, stats: { total: deck.cards.length, due: dueCount, mastered: masteredCount, }, }) } catch (error) { console.error('[flashcards/decks/[id] GET]', error) return NextResponse.json({ error: 'Failed to load deck' }, { status: 500 }) } }