import React, { useState } from "react"; const ProductForm = ({ editingProduct, setEditingProduct, onSave, onCancel, }) => { const [selectedCategory, setSelectedCategory] = useState(""); const categories = [ "Electronics", "Clothing", "Home & Garden", "Toys & Games", "Books", "Sports & Outdoors", "Automotive", "Beauty & Personal Care", "Health & Wellness", "Jewelry", "Art & Collectibles", "Food & Beverages", "Office Supplies", "Pet Supplies", "Music & Instruments", "Other", ]; const addCategory = () => { if ( selectedCategory && !(editingProduct.categories || []).includes(selectedCategory) ) { setEditingProduct((prev) => ({ ...prev, categories: [...(prev.categories || []), selectedCategory], })); setSelectedCategory(""); } }; const removeCategory = (categoryToRemove) => { setEditingProduct((prev) => ({ ...prev, categories: (prev.categories || []).filter( (cat) => cat !== categoryToRemove, ), })); }; return (
{/* Back Button */}

{editingProduct?.id ? "Edit Your Product" : "List a New Product"}

{/* Product Name */}
setEditingProduct({ ...editingProduct, name: e.target.value }) } className="w-full px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500" />
{/* Price */}
setEditingProduct({ ...editingProduct, price: e.target.value, }) } className="w-full px-4 py-2 border-2 border-gray-200 rounded-md focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500" />
{/* Categories - Dropdown with Add button */}
{/* Selected Categories */} {(editingProduct.categories || []).length > 0 ? (
{(editingProduct.categories || []).map((category) => ( {category} ))}
) : (

Please select at least one category

)}
{/* Status - Updated to Unsold/Sold */}
{/* Description - New Field */}
{/* Simplified Image Upload */}
{/* Simple file input */} { const files = Array.from(e.target.files).slice(0, 5); setEditingProduct((prev) => ({ ...prev, images: [...prev.images, ...files].slice(0, 5), })); }} className="hidden" id="image-upload" /> {/* Image previews */} {editingProduct.images.length > 0 && (

{editingProduct.images.length}{" "} {editingProduct.images.length === 1 ? "image" : "images"}{" "} selected

{editingProduct.images.map((img, idx) => (
{`Product
))} {editingProduct.images.length > 0 && ( )}
)}
{/* Actions */}
); }; export default ProductForm;