import React, { useRef, useState, useEffect } from 'react'; import { Download, Copy, Check, Play } from 'lucide-react'; export default function GalleryCard({ clip }) { const [copied, setCopied] = useState(null); const [isVisible, setIsVisible] = useState(false); const [_hasLoaded, setHasLoaded] = useState(false); const cardRef = useRef(null); const videoRef = useRef(null); // Lazy loading with IntersectionObserver useEffect(() => { const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { setIsVisible(true); // Once loaded, we don't need to observe anymore observer.unobserve(entry.target); } }); }, { rootMargin: '200px', // Start loading 200px before entering viewport threshold: 0.1 } ); const node = cardRef.current; if (node) { observer.observe(node); } return () => { if (node) { observer.unobserve(node); } }; }, []); const handleCopy = (text, field) => { navigator.clipboard.writeText(text); setCopied(field); setTimeout(() => setCopied(null), 2000); }; const handleDownload = async (e) => { e.preventDefault(); try { const response = await fetch(clip.url); if (!response.ok) throw new Error('Download failed'); const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; a.download = `clip_${clip.job_id}_${clip.index + 1}.mp4`; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); document.body.removeChild(a); } catch (err) { console.error('Download error:', err); window.open(clip.url, '_blank'); } }; return (
{/* Video Player - Lazy loaded */}
{isVisible ? (
{/* Content & Details */}

{clip.title}

{clip.duration.toFixed(1)}s ID: {clip.job_id.substring(0, 8)}
{/* YouTube Title */}

YouTube Title

{clip.title}

{/* TikTok / IG Caption */}

TikTok ยท IG Caption

{clip.tiktok_desc || clip.insta_desc}

{/* Footer Action */}
); }