'use client'; import React, { useState } from 'react'; interface ProductQuantityProps { onChange: (quantity: number) => void; initialQuantity?: number; min?: number; max?: number; } export function ProductQuantity({ onChange, initialQuantity = 1, min = 1, max = 100 }: ProductQuantityProps) { const [quantity, setQuantity] = useState(initialQuantity); const handleIncrement = () => { if (quantity < max) { const newQuantity = quantity + 1; setQuantity(newQuantity); onChange(newQuantity); } }; const handleDecrement = () => { if (quantity > min) { const newQuantity = quantity - 1; setQuantity(newQuantity); onChange(newQuantity); } }; const handleInputChange = (e: React.ChangeEvent) => { const value = parseInt(e.target.value); if (!isNaN(value) && value >= min && value <= max) { setQuantity(value); onChange(value); } }; return (
); }