'use client'; import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { X as CloseIcon, Link as LinkIcon, Copy, Check, ShareNetwork, ArrowSquareOut as ExternalLink, XLogo, FacebookLogo, LinkedinLogo, WhatsappLogo, TelegramLogo, RedditLogo, Envelope, } from '@phosphor-icons/react'; import { SHARE_PLATFORMS, openSharePlatform } from '@/lib/share'; const PLATFORM_ICONS: Record> = { x: XLogo, facebook: FacebookLogo, linkedin: LinkedinLogo, whatsapp: WhatsappLogo, telegram: TelegramLogo, reddit: RedditLogo, email: Envelope, }; interface ShareDialogProps { open: boolean; onClose: () => void; url: string; message?: string; title?: string; } export function ShareDialog({ open, onClose, url, message, title = 'Share result' }: ShareDialogProps) { const [copied, setCopied] = useState(false); const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []); useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [open, onClose]); const copyLink = async () => { if (!url) return; try { await navigator.clipboard.writeText(url); setCopied(true); setTimeout(() => setCopied(false), 1600); } catch { const ta = document.createElement('textarea'); ta.value = url; ta.style.position = 'fixed'; ta.style.opacity = '0'; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); document.body.removeChild(ta); setCopied(true); setTimeout(() => setCopied(false), 1600); } }; const nativeShare = async () => { if (typeof navigator !== 'undefined' && typeof navigator.share === 'function') { try { await navigator.share({ title: 'Synteny — Analysis Result', text: message, url }); } catch { // User dismissed — nothing to do. } } }; const dialog = (

{title}

{url}
Preview shared result
{typeof navigator !== 'undefined' && typeof navigator.share === 'function' && ( )}

Share to

{SHARE_PLATFORMS.map((platform) => { const Icon = PLATFORM_ICONS[platform.id] ?? ShareNetwork; return ( ); })}
); if (!mounted) return null; return createPortal( {open ? dialog : null}, document.body, ); }