import { useState } from 'react'; export default function ProductCard({ product, onAddToCart }) { const [isHovered, setIsHovered] = useState(false); const [isAdded, setIsAdded] = useState(false); const handleAddToCart = () => { onAddToCart(product); setIsAdded(true); setTimeout(() => setIsAdded(false), 2000); }; const renderStars = (rating) => { const stars = []; for (let i = 0; i < 5; i++) { if (i < Math.floor(rating)) { stars.push( ); } else { stars.push( ); } } return stars; }; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {/* Product Image */}
{product.name} {product.isPrime && (
prime
)}
{/* Product Info */}

{product.name}

{/* Rating */}
{renderStars(product.rating)} {product.reviews}
{/* Price */}
$ {product.price} {product.originalPrice && ( <> {product.originalPrice} ({Math.round((1 - product.price / product.originalPrice) * 100)}% off) )}
{/* Delivery */}

{product.delivery || 'FREE delivery'}

{/* Add to Cart Button */}
); }