import { motion } from 'framer-motion'; import { useState } from 'react'; export default function BuildingCard({ building, onPurchase, resources }) { const [isPurchasing, setIsPurchasing] = useState(false); const canAfford = building.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(building); setIsPurchasing(false); }, 500); } }; return (

{building.name}

Level {building.level}
+{building.production}/s

{building.description}

{building.cost.map((cost, index) => { const resource = resources.find(r => r.name === cost.name); const hasEnough = resource && resource.amount >= cost.amount; return (
{cost.amount}
); })}
{isPurchasing ? 'Purchasing...' : `Buy (${building.cost[0].amount} ${building.cost[0].name})`}
); }