import React, { useState } from 'react'; import { type ShareButtonsProps } from '@/types'; export default function ShareButtons({ lang, title, url }: ShareButtonsProps) { const [copied, setCopied] = useState(false); const shareUrl = url || (typeof window !== 'undefined' ? window.location.href : ''); const shareText = lang === 'zh' ? '分享这篇文章' : 'Share this article'; const copyText = lang === 'zh' ? '复制链接' : 'Copy link'; const copiedText = lang === 'zh' ? '已复制!' : 'Copied!'; const handleCopyLink = async () => { try { await navigator.clipboard.writeText(shareUrl); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { console.error('Failed to copy link:', err); } }; const shareLinks = [ { name: 'Twitter', url: `https://twitter.com/intent/tweet?text=${encodeURIComponent(title)}&url=${encodeURIComponent(shareUrl)}`, icon: ( ), color: 'hover:bg-blue-500/10 hover:text-blue-500' }, { name: 'LinkedIn', url: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareUrl)}`, icon: ( ), color: 'hover:bg-blue-600/10 hover:text-blue-600' }, { name: 'Facebook', url: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(shareUrl)}`, icon: ( ), color: 'hover:bg-blue-700/10 hover:text-blue-700' } ]; return (

{shareText}

{/* Social Share Buttons */} {shareLinks.map((link) => ( {link.icon} ))} {/* Copy Link Button */}
{/* Copy Success Message */} {copied && (
{copiedText}
)}
); }