import { useWagonsByTrain, useUnassignWagon, useReorderWagons } from '@/hooks/useWagons'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Button } from '@/components/ui/button'; import { Trash2, GripVertical } from 'lucide-react'; import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd'; export function WagonsTable({ trainId }: { trainId: string }) { const { data: wagons, refetch } = useWagonsByTrain(trainId); const unassign = useUnassignWagon(); const reorder = useReorderWagons(); const onDragEnd = (result: any) => { if (!result.destination) return; const items = Array.from(wagons || []); const [removed] = items.splice(result.source.index, 1); items.splice(result.destination.index, 0, removed); reorder.mutate({ trainId, wagonIds: items.map(w => w.id) }); }; if (!wagons?.length) return