import React from 'react'; import { Hero } from './components/Hero'; import { Gallery } from './components/Gallery'; import { Button } from './components/ui/Button'; import { popularSheets } from './data/mockData'; import { HowItWorks } from './components/HowItWorks'; function App() { const [generatedSheet, setGeneratedSheet] = React.useState(null); const [isGenerating, setIsGenerating] = React.useState(false); const [history, setHistory] = React.useState([]); const [error, setError] = React.useState(null); const handleGenerate = async (data) => { setIsGenerating(true); setError(null); try { const response = await fetch('/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }); if (!response.ok) throw new Error('Generation failed'); const result = await response.json(); setGeneratedSheet(result); // Add to history const newHistoryItem = { ...result, // Store full result (sections, etc) id: Date.now(), age: data.age, downloads: 0, bgColor: 'bg-primary-50', }; setHistory(prev => [newHistoryItem, ...prev]); } catch (error) { console.error("Error generating sheet:", error); setError(error.message || "Failed to generate sheet. Please try again."); } finally { setIsGenerating(false); } }; const handleRestore = (item) => { setGeneratedSheet(item); window.scrollTo({ top: 0, behavior: 'smooth' }); }; const galleryItems = history.length > 0 ? history.slice(0, 3) : popularSheets.slice(0, 3); const galleryTitle = history.length > 0 ? "Your Recent Creations" : "Most Popular Printables"; return (