import { useState } from "react"; import { Plus, Minus, Trash2 } from "lucide-react"; import { Dialog, DialogContent, DialogOverlay } from "../ui/dialog"; import { Button } from "../ui/button"; interface QuantityControlProps { quantity: number; maxQuantity: number; onIncrease: () => void; onDecrease: () => void; onRemove?: () => void; isPending: boolean; allowManualEdit?: boolean; onQuantityChange?: (quantity: number) => void; } export const QuantityControl = ({ quantity, maxQuantity, onIncrease, onDecrease, onRemove, isPending, allowManualEdit = false, onQuantityChange, }: QuantityControlProps) => { const [openDeleteModal, setOpenDeleteModal] = useState(false); const [isEditing, setIsEditing] = useState(false); const [editValue, setEditValue] = useState(quantity.toString()); const handleEditStart = () => { if (allowManualEdit) { setIsEditing(true); setEditValue(quantity.toString()); } }; const handleEditConfirm = () => { const newQuantity = parseInt(editValue); if (!isNaN(newQuantity) && newQuantity > 0 && newQuantity <= maxQuantity) { onQuantityChange?.(newQuantity); } setIsEditing(false); }; const handleEditCancel = () => { setIsEditing(false); setEditValue(quantity.toString()); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { handleEditConfirm(); } else if (e.key === "Escape") { handleEditCancel(); } }; return (