import { ChevronDown, Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { ToggleStatus } from '@/components/toggle-status'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { formatNumber } from '@/lib/format'; import type { Product } from './columns'; function getStatusLabel(status: string): string { const labels: Record = { active: 'Aktif', inactive: 'Non Aktif', draft: 'Draft', }; return labels[status] ?? status; } function getStatusVariant(status: string): string { const variants: Record = { active: 'bg-green-100 text-green-800', inactive: 'bg-red-100 text-red-800', draft: 'bg-yellow-100 text-yellow-800', }; return variants[status] ?? 'bg-gray-100 text-gray-800'; } export type ProductCardRowParams = { product: Product; index: number; isExpanded: boolean; onToggleExpand: () => void; onEdit: (product: Product) => void; onDelete: (product: Product) => void; toggleStatusUrl: (id: number) => string; }; export function ProductCardRow({ product, index, isExpanded, onToggleExpand, onEdit, onDelete, toggleStatusUrl, }: ProductCardRowParams) { const variants = product.product_variants ?? []; const totalStock = variants.reduce((sum, v) => sum + (v.stock ?? 0), 0); const totalReject = variants.reduce( (sum, v) => sum + (v.reject_stock ?? 0), 0, ); const totalRetail = variants.reduce( (sum, v) => sum + (v.retail_stock ?? 0), 0, ); const totalAll = totalStock + totalReject + totalRetail; const isToggleable = product.status === 'active' || product.status === 'inactive'; const isChecked = product.status === 'active'; return (
{index}.

{product.name}

{product.categories?.length > 0 && ( ( {product.categories .map((c) => c.name) .join(', ')} ) )}
{variants.length} varian Bagus:{' '} {formatNumber(totalStock)} Reject:{' '} {formatNumber(totalReject)} Ecer:{' '} {formatNumber(totalRetail)} Total:{' '} {formatNumber(totalAll)}
{isToggleable ? ( ) : ( {getStatusLabel(product.status)} )}
, onClick: () => onEdit(product), }, { label: 'Hapus', icon: ( ), onClick: () => onDelete(product), }, ]} wrapperClassName="flex shrink-0 items-center gap-1" />
); }