'use client'; import { useState } from 'react'; interface ShareButtonProps { title?: string; text?: string; url?: string; className?: string; } export default function ShareButton({ title = 'Veja a lista do chá de bebê!', text = 'Dê uma olhada na lista de presentes do chá de bebê.', url, className = '' }: ShareButtonProps) { const [isSupported, setIsSupported] = useState(true); const handleShare = async () => { // Use current URL if not provided const shareUrl = url || window.location.href; // Check if Web Share API is supported if (!navigator.share) { setIsSupported(false); // Fallback: copy to clipboard try { await navigator.clipboard.writeText(shareUrl); alert('Link copiado!'); } catch (err) { console.error('Failed to copy:', err); alert('Não foi possível compartilhar'); } return; } try { await navigator.share({ title, text, url: shareUrl, }); } catch (err: any) { // User cancelled or share failed if (err.name !== 'AbortError') { console.error('Error sharing:', err); } } }; if (!isSupported && typeof window !== 'undefined' && !navigator.clipboard) { // Don't show button if neither share nor clipboard is supported return null; } return ( ); }