import type { ColumnDef } from '@tanstack/react-table'; import { ArrowDown, ArrowUp } from 'lucide-react'; export type StockMutation = { id: number; type: 'in' | 'out'; quantity: number; formatted_quantity: string; stock_before: number; stock_after: number; formatted_stock_before: string; formatted_stock_after: string; stock_quality: 'good' | 'reject' | 'retail'; description: string | null; created_at: string; formatted_created_at: string; stockable: { id: number; name: string; product: { id: number; name: string; } | null; } | null; user: { id: number; username: string; email: string; user_profile?: { full_name: string; }; } | null; }; function getQualityLabel(quality: string): string { const labels: Record = { good: 'Bagus', reject: 'Reject', retail: 'Ecer', }; return labels[quality] ?? quality; } function getQualityColor(quality: string): string { const colors: Record = { good: 'bg-green-100 text-green-800', reject: 'bg-red-100 text-red-800', retail: 'bg-blue-100 text-blue-800', }; return colors[quality] ?? 'bg-gray-100 text-gray-800'; } export const columns: ColumnDef[] = [ { accessorKey: 'formatted_created_at', header: () => Tanggal, cell: ({ row }) => ( {row.getValue('formatted_created_at') as string} ), }, { id: 'product', header: () => Produk, cell: ({ row }) => { const stockable = row.original.stockable; return (
{stockable?.product?.name ?? '-'} {stockable?.name ?? '-'}
); }, }, { id: 'type', header: () => Tipe, cell: ({ row }) => { const mutation = row.original; const isIn = mutation.type === 'in'; return ( {isIn ? ( ) : ( )} {isIn ? 'Masuk' : 'Keluar'} ); }, }, { id: 'stock_quality', header: () => Kualitas, cell: ({ row }) => { const quality = row.original.stock_quality; return ( {getQualityLabel(quality)} ); }, }, { id: 'quantity', header: () => Qty, cell: ({ row }) => { const mutation = row.original; const isPositive = mutation.quantity > 0; return ( {isPositive ? '+' : ''} {mutation.formatted_quantity} ); }, }, { id: 'stock_change', header: () => Stok, cell: ({ row }) => { const mutation = row.original; return ( {mutation.formatted_stock_before} →{' '} {mutation.formatted_stock_after} ); }, }, { accessorKey: 'description', header: () => Keterangan, cell: ({ row }) => ( {(row.getValue('description') as string | null) ?? '-'} ), }, { id: 'user', header: () => Oleh, cell: ({ row }) => { const user = row.original.user; return ( {user?.user_profile?.full_name ?? user?.username ?? '-'} ); }, }, ];