import { motion } from 'framer-motion'; import { useState } from 'react'; export default function ResearchCard({ research, onPurchase, resources }) { const [isPurchasing, setIsPurchasing] = useState(false); const canAfford = research.cost.every(cost => { const resource = resources.find(r => r.name === cost.name); return resource && resource.amount >= cost.amount; }); const handlePurchase = () => { if (canAfford && !isPurchasing) { setIsPurchasing(true); setTimeout(() => { onPurchase(research); setIsPurchasing(false); }, 500); } }; return (

{research.name}

{research.unlocked && (
Active
)}

{research.description}

{research.cost.map((cost, index) => { const resource = resources.find(r => r.name === cost.name); const hasEnough = resource && resource.amount >= cost.amount; return (
{cost.amount}
); })}
{!research.unlocked ? ( {isPurchasing ? 'Researching...' : 'Research'} ) : (
Already researched
)}
); }