'use client'; import { useState, useRef, useEffect } from 'react'; import Link from 'next/link'; import { Question as HelpCircle } from '@phosphor-icons/react'; interface LearnPopoverProps { term: string; explanation: string; topic?: string; children: React.ReactNode; } export function LearnPopover({ term, explanation, topic, children }: LearnPopoverProps) { const [open, setOpen] = useState(false); const wrapperRef = useRef(null); useEffect(() => { function handleClickOutside(e: MouseEvent) { if (wrapperRef.current && !wrapperRef.current.contains(e.target as Node)) { setOpen(false); } } if (open) { document.addEventListener('mousedown', handleClickOutside); } return () => document.removeEventListener('mousedown', handleClickOutside); }, [open]); return ( setOpen(!open)} role="button" tabIndex={0} onKeyDown={e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setOpen(!open); } }} aria-label={`Learn about ${term}`} > {children} setOpen(!open)} /> {open && (

{term}

{explanation}

{topic && ( Learn more → )}
)}
); }