'use client';
import { OrderItem, Supplier } from '@/lib/types';
import { cn, formatCurrency, parseCoordinates } from '@/lib/utils';
import CollectionItemCard from '@/components/CollectionItemCard';
import {
ChevronDown,
ChevronUp,
MapPin,
Navigation,
Package,
ShoppingCart,
Hammer,
Wrench,
AlertTriangle,
} from 'lucide-react';
interface SupplierColor {
border: string;
dot: string;
light: string;
text: string;
ring: string;
}
interface SupplierGroupProps {
supplier: Supplier;
items: OrderItem[];
color: SupplierColor;
isExpanded: boolean;
viewMode: 'compact' | 'detailed';
onToggle: () => void;
onCollect: (item: OrderItem) => void;
onProblem: (item: OrderItem) => void;
onNavigate: (lat: number, lng: number, name: string) => void;
}
function getItemIcon(item: OrderItem) {
if (item.item_status === 'problem' || 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 SupplierGroup({
supplier,
items,
color,
isExpanded,
viewMode,
onToggle,
onCollect,
onProblem,
onNavigate,
}: SupplierGroupProps) {
const coords = parseCoordinates(supplier.coordinates);
const hasCoords = coords !== null;
const totalQty = items.reduce((sum, i) => sum + (i.order_qty || i.quantity || 0), 0);
return (
{/* Supplier Header — always visible, tap to expand/collapse */}
{/* Expanded content */}
{isExpanded && (
{viewMode === 'compact' ? (
/* COMPACT MODE: simple list with item name + qty */
{items.map((item) => {
const expectedQty = item.order_qty || item.quantity || 0;
return (
{
// Determine if we should open collect or problem modal
// For now, just expand - user can use the action buttons
}}
>
{getItemIcon(item)}
{item.description || 'Unknown item'}
{item.item_status === 'problem' && (
Problem
)}
{expectedQty}×
);
})}
) : (
/* DETAILED MODE: full item cards */
{items.map((item) => (
))}
)}
{/* Supplier footer with navigate button */}
{hasCoords && coords && (
)}
)}
);
}