'use client'; import { useState } from 'react'; import { OrderItem } from '@/lib/types'; import { cn, formatCurrency } from '@/lib/utils'; import { X, Minus, Plus, Check } from 'lucide-react'; interface CollectModalProps { item: OrderItem | null; isOpen: boolean; onClose: () => void; onConfirm: (item: OrderItem, receivedQty: number, notes: string) => void; } export default function CollectModal({ item, isOpen, onClose, onConfirm, }: CollectModalProps) { const [receivedQty, setReceivedQty] = useState(''); const [notes, setNotes] = useState(''); const [error, setError] = useState(''); if (!isOpen || !item) return null; const expectedQty = item.order_qty || item.quantity || 0; const parsedQty = parseFloat(receivedQty) || 0; const isPartial = parsedQty > 0 && parsedQty < expectedQty; const isOverQty = parsedQty > expectedQty; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setError(''); const qty = parseFloat(receivedQty); if (isNaN(qty) || qty <= 0) { setError('Please enter a valid quantity'); return; } onConfirm(item, qty, notes); setReceivedQty(''); setNotes(''); setError(''); }; const adjustQty = (delta: number) => { const current = parseFloat(receivedQty) || 0; const newQty = Math.max(0, current + delta); setReceivedQty(newQty.toString()); setError(''); }; return (
{/* Drag indicator */}

Collect Item

{/* Item info */}

{item.description}

{item.expand?.supplier?.suppliername || 'Unknown'} Expected: {expectedQty} units
{item.selling_price && (

Unit price: {formatCurrency(item.selling_price)}

)}
{/* Quantity */}
{ setReceivedQty(e.target.value); setError(''); }} className="w-20 text-center text-2xl font-bold py-3 border-2 border-gray-200 rounded-xl focus:ring-2 focus:ring-green-500/30 focus:border-green-500 transition-all" placeholder="0" autoFocus /> {expectedQty > 0 && ( )}
{isPartial && (

Partial collection: {parsedQty} of {expectedQty} units

)} {isOverQty && (

Over collection: {parsedQty} exceeds expected {expectedQty}

)} {error &&

{error}

}
{/* Notes */}