import React, { useState } from 'react'; import Header from '../components/Header'; import { useAuth } from '../AuthContext'; import { motion } from 'framer-motion'; import { Brain, Upload, Image as ImageIcon, AlertCircle } from 'lucide-react'; import NeuroScorecard from '../components/NeuroScorecard'; import { ApiKeyModal } from '../components/ApiKeyModal'; const ScorecardPage = () => { const { user, token, logout, refreshUser } = useAuth(); const [imageUrl, setImageUrl] = useState(''); const [loading, setLoading] = useState(false); const [analysis, setAnalysis] = useState(null); const [error, setError] = useState(null); const [isApiKeyModalOpen, setIsApiKeyModalOpen] = useState(false); const handleImageUpload = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onloadend = () => { setImageUrl(reader.result as string); setAnalysis(null); // Reset analysis when new image is uploaded }; reader.readAsDataURL(file); } }; const analyzeImage = async () => { if (!imageUrl) return; setLoading(true); setError(null); try { // Strip base64 prefix if present for API const base64Data = imageUrl.split(',')[1]; const response = await fetch('http://localhost:3001/api/neuro-score', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ imageBase64: base64Data, apiKey: localStorage.getItem('gemini_api_key') || user?.apiKey // BYOK support }) }); const data = await response.json(); if (!data.success) { throw new Error(data.error || "Analysis failed"); } setAnalysis(data.data); } catch (err: any) { setError(err.message); } finally { setLoading(false); } }; return (
setIsApiKeyModalOpen(true)} /> setIsApiKeyModalOpen(false)} />
{/* Hero Section */}
The Internal Critic

Neuro-Scorecard

Don't guess what sells. Let our AI predict your conversion rate by analyzing dopamine triggers, cognitive ease, and market fit.

{/* Input Section */}
{!imageUrl ? ( ) : (
Analysis Target
)}
{error && (

{error}

)}
{/* Results Section */}
{!analysis && !loading && (

Ready to Score

Upload an image to see its commercial prediction.

)} {(analysis || loading) && ( )}
); }; export default ScorecardPage;