'use client'; import * as React from 'react'; import { Button } from '@/components/ui/button'; // --------------------------------------------------------------------------- // Social Share Buttons — Facebook, Zalo, Copy Link, QR Code // --------------------------------------------------------------------------- interface SocialShareProps { listingId: string; listingTitle: string; } const apiUrl = process.env['NEXT_PUBLIC_API_URL'] || 'http://localhost:3001/api/v1'; export function SocialShare({ listingId, listingTitle }: SocialShareProps) { const [copied, setCopied] = React.useState(false); const [showQr, setShowQr] = React.useState(false); const listingUrl = typeof window !== 'undefined' ? window.location.href : ''; const handleCopyLink = React.useCallback(async () => { try { await navigator.clipboard.writeText(listingUrl); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch { // Fallback for older browsers const textarea = document.createElement('textarea'); textarea.value = listingUrl; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); setCopied(true); setTimeout(() => setCopied(false), 2000); } }, [listingUrl]); const handleShareFacebook = React.useCallback(() => { const url = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(listingUrl)}`; window.open(url, '_blank', 'noopener,noreferrer,width=600,height=400'); }, [listingUrl]); const handleShareZalo = React.useCallback(() => { const url = `https://zalo.me/share?url=${encodeURIComponent(listingUrl)}&title=${encodeURIComponent(listingTitle)}`; window.open(url, '_blank', 'noopener,noreferrer,width=600,height=400'); }, [listingUrl, listingTitle]); const qrCodeUrl = `${apiUrl}/listings/${listingId}/qr-code`; return (

Chia sẻ

{/* Facebook */} {/* Zalo */} {/* Copy link */}
{/* QR Code toggle */}
{showQr && (
{`Mã
)}
); }