'use client'; import { Fragment, useId, useState, type ReactNode } from 'react'; import type { Card } from '@/game/cards'; import { browseHand, type HandCategory, type HandSort } from '@/game/hand-browsing'; import { Button } from './ui/button'; export function HandBrowser({ cards, empty, children }: { cards: readonly Card[]; empty: ReactNode; children: (card: Card) => ReactNode; }) { const [query, setQuery] = useState(''); const [category, setCategory] = useState('all'); const [sort, setSort] = useState('hand'); const gridId = useId(); const shown = browseHand(cards, query, category, sort); const filtered = query !== '' || category !== 'all'; return ( <> {cards.length > 0 && (
event.preventDefault()}>
{shown.length} of {cards.length} {cards.length === 1 ? 'card' : 'cards'} shown {filtered && } Hand browsing help
)} {/* oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- Keyboard users need access to this independently scrolling card row. */}
{cards.length === 0 ? empty : shown.length === 0 ?

No cards match. Change the name or category, or choose Show all cards.

: shown.map(card => {children(card)})}
); }