"use client" import React, { useEffect } from 'react' interface ScreenshotGalleryProps { screenshots: string[] symbol: string timeframes: string[] enlargedImage: string | null onImageClick: (src: string) => void onClose: () => void } export default function ScreenshotGallery({ screenshots, symbol, timeframes, enlargedImage, onImageClick, onClose }: ScreenshotGalleryProps) { // Handle ESC key to close enlarged image useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape' && enlargedImage) { onClose() } } if (enlargedImage) { document.addEventListener('keydown', handleKeyDown) return () => document.removeEventListener('keydown', handleKeyDown) } }, [enlargedImage, onClose]) if (screenshots.length === 0) return null // Helper function to format screenshot URL const formatScreenshotUrl = (screenshot: string | any) => { // Handle both string URLs and screenshot objects const screenshotUrl = typeof screenshot === 'string' ? screenshot : screenshot.url || screenshot // Extract just the filename from the full path const filename = screenshotUrl.split('/').pop() || screenshotUrl // Use the new API route with query parameter return `/api/image?file=${filename}` } return ( <> {/* Gallery Grid */}

📸 Chart Screenshots

{screenshots.length} captured • Click to enlarge
{screenshots.map((screenshot, index) => { // Handle both string URLs and screenshot objects const screenshotUrl = typeof screenshot === 'string' ? screenshot : (screenshot as any)?.url || String(screenshot) const filename = screenshotUrl.split('/').pop() || '' // Extract timeframe from filename (e.g., SOLUSD_5_ai_timestamp.png -> "5m") const extractTimeframeFromFilename = (filename: string) => { const match = filename.match(/_(\d+|D)_/) if (!match) return 'Unknown' const tf = match[1] if (tf === 'D') return '1D' if (tf === '5') return '5m' if (tf === '15') return '15m' if (tf === '60') return '1h' if (tf === '240') return '4h' return `${tf}m` } const timeframe = timeframes[index] || extractTimeframeFromFilename(filename) const imageUrl = formatScreenshotUrl(screenshot) return (
onImageClick(imageUrl)} > {/* Preview Image */}
{`${symbol} { const target = e.target as HTMLImageElement target.style.display = 'none' const fallback = target.nextElementSibling as HTMLElement if (fallback) fallback.classList.remove('hidden') }} />
📊
Chart Preview
{filename}
{/* Overlay */}
🔍
{/* Image Info */}
{symbol}
{timeframe} Timeframe
Click to view
) })}
{/* Enlarged Image Modal */} {enlargedImage && (
e.stopPropagation()}> {/* Close Button */} {/* Image */} Enlarged chart { console.error('Failed to load enlarged image:', enlargedImage) const target = e.target as HTMLImageElement target.alt = 'Failed to load image' }} /> {/* Image Info Overlay */}
{symbol} Chart Analysis
AI analyzed screenshot • High resolution view
ESC to close • Click outside to close
)} ) }