"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) { // Debug logging console.log('ScreenshotGallery props:', { screenshots, symbol, timeframes, enlargedImage, screenshotsLength: screenshots?.length }) // 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) { console.log('ScreenshotGallery: No screenshots to display') // TEMPORARY: Show a test gallery with known screenshots for debugging const testScreenshots = [ '/screenshots/SOLUSD_240_ai_1752447978639.png', '/screenshots/SOLUSD_15_ai_1752441315672.png' ] console.log('ScreenshotGallery: Using test screenshots for debugging:', testScreenshots) return ( <> {/* Test Gallery Grid */}

๐Ÿงช Test Screenshots (Debug Mode)

{testScreenshots.length} test images โ€ข Click to enlarge
{testScreenshots.map((screenshot, index) => { const filename = screenshot.split('/').pop() || '' const timeframe = index === 0 ? '4h' : '15m' return (
{ console.log('Test image clicked:', screenshot) onImageClick(screenshot) }} >
{`${symbol} console.log(`Test image loaded successfully: ${screenshot}`)} onError={(e: any) => { console.error(`Test image failed to load: ${screenshot}`, e) const target = e.target as HTMLImageElement target.style.display = 'none' }} />
{symbol}
{timeframe} Timeframe (Test)
Click to view
) })}
{/* Test Enlarged Image Modal */} {enlargedImage && (
e.stopPropagation()}> Enlarged chart { console.error('Failed to load enlarged image:', enlargedImage) const target = e.target as HTMLImageElement target.alt = 'Failed to load image' }} />
{symbol} Chart Analysis (Test Mode)
Debug screenshot โ€ข High resolution view
ESC to close โ€ข Click outside to close
)} ) } // 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() || '' // 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) console.log(`Screenshot ${index}:`, { screenshot, filename, timeframe, imageUrl }) return (
onImageClick(imageUrl)} > {/* Preview Image */}
{`${symbol} console.log(`Image loaded successfully: ${imageUrl}`)} onError={(e: any) => { console.error(`Failed to load image: ${imageUrl}`, e) 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
)} ) }