import type { WordInfo } from '../../api/client' import { speak, speechSupported } from '../../audio/speech' import { usePack } from '../../i18n' import { wordBand } from './wordband' // WordCard is the right-click popover for any word: its dictionary definition(s) // on top and tappable synonym pills below. Clicking a synonym replaces the word // in place. Both datasets are offline, so this opens instantly and fills in as // the (local) lookup returns. Labels are bilingual (zh-first, en subtitle) to // match the rest of Petal's chrome β€” the writer uses Mandarin and English. interface Props { word: string info: WordInfo | null loading: boolean // Whether the word is in the vocabulary garden (auto-saved on lookup). The // heart toggles it; `onToggleSave` removes/re-adds it. saved: boolean onToggleSave: () => void style: React.CSSProperties onReplace: (synonym: string) => void } export function WordCard({ word, info, loading, saved, onToggleSave, style, onReplace }: Props) { const t = usePack() const definitions = info?.definitions ?? [] const synonyms = info?.synonyms ?? [] const gloss = info?.gloss ?? '' const phonetic = info?.phonetic ?? '' const etymology = info?.etymology ?? '' // Null whenever the dictionary has no opinion β€” the chip then doesn't render. const band = info ? wordBand(info.frequency ?? 0, info.difficulty ?? -1) : null const empty = !loading && !gloss && definitions.length === 0 && synonyms.length === 0 return (
{t.editor.word} {word}
{!empty && !loading && ( )} {speechSupported() && ( )}
{/* How to say it, and how hard it is. The pronunciation aid pairs with the πŸ”Š button above; the band answers the question a learner actually has when she has found a word she likes β€” "can I use this?". Both are quiet, muted lines: information she can take or leave, never a verdict on her writing. */} {(phonetic || band) && (
{phonetic && /{phonetic}/} {band && ( {t.editor.wordBands[band].native} )}
)} {/* Chinese gloss first β€” it's what the Mandarin-speaking writer reaches for. */} {gloss && (

{gloss}

)} {loading && (
{t.editor.lookingUp}
)} {definitions.length > 0 && (

{t.editor.definition}

    {definitions.map((m, i) => (
  1. {m.part_of_speech && ( {m.part_of_speech} )} {m.definition} {m.example && ( β€œ{m.example}” )}
  2. ))}
)} {synonyms.length > 0 && (

{t.editor.synonyms} ({t.editor.tapToSwap})

{synonyms.map((s) => ( ))}
)} {/* Where the word came from. Last, and in small muted type, because it is the one thing here that is interesting rather than useful β€” and for a writer whose own language shares Latin roots with English, "efΓ©mero" sitting under "ephemeral" is how a word stops needing to be memorised. */} {etymology && (

{t.editor.origin}

{etymology}

)} {empty && (

{t.editor.nothingFound}

)}
) }