'use client'; import { useState } from 'react'; import { OrderItem } from '@/lib/types'; import { cn, formatDate, formatCurrency, parseCoordinates } from '@/lib/utils'; import { Check, AlertTriangle, Navigation, ChevronDown, ChevronUp, Package, Wrench, Hammer, ShoppingCart, AlertCircle, Clock, MapPin, } from 'lucide-react'; interface CollectionItemProps { item: OrderItem; supplierColor?: { dot: string; light: string; text: string; ring: string }; compact?: boolean; onCollect: (item: OrderItem) => void; onProblem: (item: OrderItem) => void; onNavigate: (lat: number, lng: number, name: string) => void; } function getItemType(item: OrderItem): { type: string; icon: React.ReactNode; color: string; bgColor: string; label: string; } { if (item.problem_flag) { return { type: 'problem', icon: , color: 'text-[#b3224a]', bgColor: 'bg-[#fbeaef]', label: 'Problem', }; } const orderNumber = item.expand?.order?.order_number || ''; if (orderNumber.toLowerCase().includes('breakdown')) { return { type: 'breakdown', icon: , color: 'text-[#8a5a02]', bgColor: 'bg-[#fcf3d8]', label: 'Breakdown', }; } if (orderNumber.toLowerCase().includes('repair')) { return { type: 'repair', icon: , color: 'text-[#8a5a02]', bgColor: 'bg-[#f6e3a4]', label: 'Repair', }; } if (item.is_stock_item) { return { type: 'stock', icon: , color: 'text-[#4a3d6b]', bgColor: 'bg-[#ece8f3]', label: 'Stock', }; } return { type: 'normal', icon: , color: 'text-[#26251e]', bgColor: 'bg-[#ebeae5]', label: 'Order', }; } export default function CollectionItemCard({ item, supplierColor, compact, onCollect, onProblem, onNavigate, }: CollectionItemProps) { const [expanded, setExpanded] = useState(false); const supplier = item.expand?.supplier; const itemType = getItemType(item); const coords = parseCoordinates(supplier?.coordinates); const hasCoords = coords !== null; const description = item.description || 'Unknown item'; const expectedQty = item.order_qty || item.quantity || 0; return (
{/* Header */} {/* Expanded Details */} {expanded && (
{/* Notes */} {item.notes && (

)} {item.problem_notes && (

)} {/* Details grid */}
{item.expand?.order?.order_number && (
Order
{item.expand.order.order_number}
)} {item.expand?.purchase_order?.po_number && (
PO
{item.expand.purchase_order.po_number}
)} {supplier?.supplieraddress && (
Address
{supplier.supplieraddress}
)}
{/* Action Buttons */}
{hasCoords && coords && supplier ? ( ) : (
)}
)}
); }