import React, { useState, useEffect, useRef } from 'react'; import { SlidersHorizontal, Sparkles, Brain } from 'lucide-react'; const ImagePreview = ({ imageData, fileName, onResolutionChange, onEnhanceToggle, isEnhanced, onReasoningModeToggle, useReasoning }) => { const [resolution, setResolution] = useState(100); const canvasRef = useRef(null); const [originalDimensions, setOriginalDimensions] = useState({ width: 0, height: 0 }); const [currentDimensions, setCurrentDimensions] = useState({ width: 0, height: 0 }); useEffect(() => { if (!imageData || !canvasRef.current) return; const canvas = canvasRef.current; const ctx = canvas.getContext('2d'); const img = new Image(); img.onload = () => { if (!originalDimensions.width) { setOriginalDimensions({ width: img.width, height: img.height }); } // Calculate new dimensions based on resolution const newWidth = Math.floor(img.width * (resolution / 100)); const newHeight = Math.floor(img.height * (resolution / 100)); setCurrentDimensions({ width: newWidth, height: newHeight }); // Set display size (max 400px width for preview) const displayWidth = Math.min(400, newWidth); const displayHeight = Math.floor(newHeight * (displayWidth / newWidth)); canvas.width = displayWidth; canvas.height = displayHeight; // Draw scaled image ctx.drawImage(img, 0, 0, displayWidth, displayHeight); // Notify parent of resolution change if (onResolutionChange) { const resizedCanvas = document.createElement('canvas'); resizedCanvas.width = newWidth; resizedCanvas.height = newHeight; const resizedCtx = resizedCanvas.getContext('2d'); resizedCtx.drawImage(img, 0, 0, newWidth, newHeight); const resizedDataUrl = resizedCanvas.toDataURL('image/jpeg', 0.95); onResolutionChange(resizedDataUrl, resolution); } }; img.src = imageData; }, [imageData, resolution]); const handleResolutionChange = (e) => { const newResolution = parseInt(e.target.value); setResolution(newResolution); }; return (