// Share modal — copy link, QR, friend challenge const ShareModal = ({ profile, score, mode, onClose }) => { const t = window.MP_I18N.t; const lang = window.MP_I18N.getLang(); const [tab, setTab] = React.useState('challenge'); const [copied, setCopied] = React.useState(false); const url = window.location.origin + window.location.pathname; const shareUrl = `${url}?challenge=${encodeURIComponent(profile.firstName)}&s=${score || profile.points}&m=${mode || 'time_attack'}`; const shareText = t('share_text', { score: score || profile.points }); const copy = async () => { try { await navigator.clipboard.writeText(shareUrl); setCopied(true); window.MP_SOUND.celebrate(); setTimeout(() => setCopied(false), 1500); } catch {} }; const nativeShare = async () => { if (navigator.share) { try { await navigator.share({ title: t('share_title'), text: shareText, url: shareUrl }); } catch {} } else copy(); }; // QR via Google Charts (offline-friendly fallback: shows code) const qrSrc = `https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(profile.schoolCode ? url + '?school=' + profile.schoolCode : url)}&color=1a0b2e&bgcolor=ffffff`; return (
e.stopPropagation()}>
{tab === 'challenge' ? (
{t('share_title')}
{score || profile.points}
{shareText}
) : (
{t('school_code')}
{profile.schoolCode || '—'}
{lang === 'es' ? 'Compártelo con tus amigos para entrar a la misma escuela' : 'Share with friends to join the same school'}
QR e.currentTarget.style.display='none'} />
{lang === 'es' ? 'Escanea para abrir' : 'Scan to open'}
)}
); }; window.ShareModal = ShareModal;