import React, { useState } from 'react';
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
const products = [
{ id: 1, name: "Laptop", price: 800, description: "High performance laptop." },
{ id: 2, name: "Smartphone", price: 500, description: "Latest model smartphone." },
{ id: 3, name: "Headphones", price: 150, description: "Noise-cancelling headphones." }
];
const App = () => {
const [cart, setCart] = useState([]);
const addToCart = (product) => {
setCart([...cart, product]);
};
return (
<div className="p-4">
<h1 className="text-2xl mb-4">Simple E-Commerce Webpage</h1>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
{products.map((product) => (
<Card key={product.id} className="shadow-md">
<CardContent>
<h2 className="text-xl font-bold">{product.name}</h2>
<p>{product.description}</p>
<p className="text-lg font-semibold">${product.price}</p>
<Button onClick={() => addToCart(product)} className="mt-2">Add to Cart</Button>
</CardContent>
</Card>
))}
</div>
<h2 className="text-xl mb-2">Cart</h2>
{cart.length > 0 ? (
<ul>
{cart.map((item, index) => (
<li key={index}>{item.name} - ${item.price}</li>
))}
</ul>
):(
<p>Your cart is empty.</p>
)}
</div>
);
};
export default App;