@@ -6,51 +6,65 @@ import { CardFooter } from './card-footer';
66import { CardHeader } from './card-header' ;
77
88export function BlackCard ( ) {
9- const { currentBlackCard } = useGame ( ) ;
10- // Determine text size class based on character count
11- const textSizeClass = useMemo ( ( ) => {
12- const text = currentBlackCard ?. text || '' ;
13- const charCount = text . length ;
9+ const { currentBlackCard, selectedWhiteCards, handleUnpickWhiteCard } =
10+ useGame ( ) ;
11+
12+ const combinedTextLength = useMemo ( ( ) => {
13+ if ( ! currentBlackCard ?. text ) return 0 ;
14+
15+ const blackCardText = currentBlackCard . text ;
16+ const whiteCardsText =
17+ selectedWhiteCards ?. map ( card => card . text ) . join ( '' ) || '' ;
1418
15- // Text size thresholds based on character count
16- if ( charCount <= 74 ) return 'text-4xl' ; // Up to 74 chars
17- if ( charCount <= 100 ) return 'text-3xl' ; // Up to 100 chars
18- if ( charCount <= 150 ) return 'text-2xl' ; // Up to 150 chars
19- if ( charCount <= 200 ) return 'text-xl' ; // Up to 200 chars
20- return 'text-lg' ; // More than 200 chars
21- } , [ currentBlackCard ?. text ] ) ;
19+ return blackCardText . length + whiteCardsText . length ;
20+ } , [ currentBlackCard ?. text , selectedWhiteCards ] ) ;
21+
22+ const textSizeClass = useMemo ( ( ) => {
23+ if ( combinedTextLength <= 50 ) return 'text-3xl' ;
24+ if ( combinedTextLength <= 70 ) return 'text-2xl' ;
25+ if ( combinedTextLength <= 100 ) return 'text-xl' ;
26+ if ( combinedTextLength <= 150 ) return 'text-lg' ;
27+ return 'text-base' ;
28+ } , [ combinedTextLength ] ) ;
2229
23- // Process text to replace "___" with styled lines
2430 const processedContent = useMemo ( ( ) => {
2531 const text = currentBlackCard ?. text || '' ;
26-
27- // If no fill-in-the-gap markers, return the text as is
2832 if ( ! text . includes ( '___' ) ) return text ;
2933
30- // Split by the fill-in-the-gap marker
3134 const segments = text . split ( '___' ) ;
35+ const whiteCards = selectedWhiteCards || [ ] ;
3236
33- // Map through segments and join with styled lines
3437 return segments . map ( ( segment , index ) => {
35- // Last segment doesn't need a line after it
3638 if ( index === segments . length - 1 ) {
3739 // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
38- return < span key = { index } > { segment } </ span > ;
40+ return < span key = { `segment- ${ index } ` } > { segment } </ span > ;
3941 }
4042
41- // Add a line after each segment (except the last)
43+ const hasWhiteCard = index < whiteCards . length ;
44+
4245 return (
4346 // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
44- < span key = { index } >
47+ < span key = { `segment- ${ index } ` } >
4548 { segment }
46- < span className = "mx-1 inline-block h-4 w-24 border-b-2 border-zinc-50 align-middle" />
49+ { hasWhiteCard ? (
50+ < button
51+ type = "button"
52+ onClick = { ( ) => handleUnpickWhiteCard ( whiteCards [ index ] ) }
53+ className = "my-1 inline-block rounded bg-white px-2 py-1 text-left font-bold text-zinc-950"
54+ >
55+ { whiteCards [ index ] . text }
56+ </ button >
57+ ) : (
58+ // Display empty blank
59+ < span className = "mx-1 inline-block h-4 w-24 border-b-2 border-white align-middle" />
60+ ) }
4761 </ span >
4862 ) ;
4963 } ) ;
50- } , [ currentBlackCard ?. text ] ) ;
64+ } , [ currentBlackCard ?. text , selectedWhiteCards , handleUnpickWhiteCard ] ) ;
5165
5266 return (
53- < div className = "flex aspect-card h-[30rem] flex-col justify-between gap-5 rounded-2xl border border-zinc-950 bg-zinc-950 p-9 dark:border-zinc-50" >
67+ < div className = "flex aspect-card h-96 flex-col justify-between gap-2 rounded-2xl border border-zinc-950 bg-zinc-950 p-6 dark:border-zinc-50" >
5468 < CardHeader packId = { currentBlackCard ?. packId || '' } variant = "blackCard" />
5569
5670 < div className = "flex flex-1 items-center" >
0 commit comments