'use client'; import { useState } from 'react'; import { OrderItem, isOutOfStock, problemBadgeLabel } from '@/lib/types'; import { cn } from '@/lib/utils'; import CollectionItemCard from '@/components/CollectionItemCard'; import { ChevronDown, ChevronUp, MapPin, Navigation, Package, ShoppingCart, Hammer, Wrench, AlertTriangle, Layers, } from 'lucide-react'; interface AreaColor { dot: string; light: string; text: string; ring: string; } interface AreaGroupProps { clusterId: string; label: string; items: OrderItem[]; center: { latitude: number; longitude: number }; color: AreaColor; isExpanded: boolean; viewMode: 'compact' | 'detailed'; onToggle: () => void; onCollect: (item: OrderItem) => void; onProblem: (item: OrderItem) => void; onNavigate: (lat: number, lng: number, name: string) => void; onShowDetails: (item: OrderItem) => void; } function getItemIcon(item: OrderItem) { if (item.problem_flag) return ; const orderNumber = item.expand?.order?.order_number || ''; if (orderNumber.toLowerCase().includes('breakdown')) return ; if (orderNumber.toLowerCase().includes('repair')) return ; if (item.is_stock_item) return ; return ; } export default function AreaGroup({ clusterId, label, items, center, color, isExpanded, viewMode, onToggle, onCollect, onProblem, onNavigate, onShowDetails, }: AreaGroupProps) { const totalQty = items.reduce((sum, i) => sum + (i.order_qty || i.quantity || 0), 0); const uniqueSuppliers = Array.from( new Set( items .map(i => i.expand?.supplier?.suppliername) .filter((n): n is string => !!n) ) ); const hasCoords = center.latitude !== 0 && center.longitude !== 0; // Tracks whether any detailed-mode CollectionItemCard inside has // an open popover. We use this to lift the section's stacking // context so the popover paints above the next area group. const [childPopoverOpen, setChildPopoverOpen] = useState(false); return ( ); }