import { useState, useEffect } from 'react' import { ExternalLink } from 'lucide-react' import { collabApi } from '../../api/client' // ── Website Thumbnail (fetches OG image) ──────────────────────────────────── const ogCache = {} interface WebsiteThumbnailProps { url: string tripId: number color: string } export function WebsiteThumbnail({ url, tripId, color }: WebsiteThumbnailProps) { const [data, setData] = useState(ogCache[url] || null) const [failed, setFailed] = useState(false) useEffect(() => { if (ogCache[url]) { setData(ogCache[url]); return } collabApi.linkPreview(tripId, url).then(d => { ogCache[url] = d; setData(d) }).catch(() => setFailed(true)) }, [url, tripId]) const domain = (() => { try { return new URL(url).hostname.replace('www.', '') } catch { return 'link' } })() return ( { e.currentTarget.style.transform = 'scale(1.08)'; e.currentTarget.style.boxShadow = '0 2px 8px rgba(0,0,0,0.15)' }} onMouseLeave={e => { e.currentTarget.style.transform = 'scale(1)'; e.currentTarget.style.boxShadow = 'none' }}> {data?.image && !failed ? ( setFailed(true)} /> ) : ( <> {domain} )} ) }