'use client'; import { useState, useEffect } from 'react'; import { useLanguage } from '@/context/LanguageContext'; import { ShareIcon, LinkIcon, CheckIcon, } from '@heroicons/react/24/outline'; import toast from 'react-hot-toast'; interface ShareButtonsProps { title: string; url?: string; description?: string; } export default function ShareButtons({ title, url, description }: ShareButtonsProps) { const { locale } = useLanguage(); const [copied, setCopied] = useState(false); const [supportsNativeShare, setSupportsNativeShare] = useState(false); // Check for native share support only after mount to avoid hydration mismatch useEffect(() => { setSupportsNativeShare(typeof navigator !== 'undefined' && typeof navigator.share === 'function'); }, []); // Use provided URL or current page URL const shareUrl = url || (typeof window !== 'undefined' ? window.location.href : ''); const shareText = description || title; const handleCopyLink = async () => { try { await navigator.clipboard.writeText(shareUrl); setCopied(true); toast.success(locale === 'es' ? 'Enlace copiado' : 'Link copied'); setTimeout(() => setCopied(false), 2000); } catch (err) { toast.error(locale === 'es' ? 'Error al copiar' : 'Failed to copy'); } }; const shareToWhatsApp = () => { const text = encodeURIComponent(`${shareText}\n\n${shareUrl}`); window.open(`https://wa.me/?text=${text}`, '_blank'); }; const shareToFacebook = () => { const encodedUrl = encodeURIComponent(shareUrl); window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`, '_blank', 'width=600,height=400'); }; const shareToTwitter = () => { const text = encodeURIComponent(shareText); const encodedUrl = encodeURIComponent(shareUrl); window.open(`https://twitter.com/intent/tweet?text=${text}&url=${encodedUrl}`, '_blank', 'width=600,height=400'); }; const shareToLinkedIn = () => { const encodedUrl = encodeURIComponent(shareUrl); window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${encodedUrl}`, '_blank', 'width=600,height=400'); }; const handleNativeShare = async () => { if (navigator.share) { try { await navigator.share({ title, text: shareText, url: shareUrl, }); } catch (err) { // User cancelled or error } } }; return (

{locale === 'es' ? 'Compartir evento' : 'Share event'}

{/* WhatsApp */} {/* Facebook */} {/* Twitter/X */} {/* LinkedIn */} {/* Copy Link */} {/* Native Share (mobile) */} {supportsNativeShare && ( )}
); }