"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) => { // Extract just the filename from the full path const filename = screenshot.split('/').pop() || screenshot // Return the Next.js API route format return `/screenshots/${filename}` } return ( <> {/* Gallery Grid */}

📸 Chart Screenshots

{screenshots.length} captured • Click to enlarge
{screenshots.map((screenshot, index) => { const filename = screenshot.split('/').pop() || '' const timeframe = timeframes[index] || 'Unknown' 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
)} ) }