import { ChevronDown, Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { formatDateTime, formatNumber } from '@/lib/format'; import { formatCurrency } from '@/lib/utils'; import type { Transaction } from './columns'; const STATUS_BADGE_CLASSES: Record = { pending: 'bg-yellow-100 text-yellow-800 hover:bg-yellow-100', processing: 'bg-blue-100 text-blue-800 hover:bg-blue-100', completed: 'bg-green-100 text-green-800 hover:bg-green-100', cancelled: 'bg-red-100 text-red-800 hover:bg-red-100', refunded: 'bg-purple-100 text-purple-800 hover:bg-purple-100', }; export type TransactionCardRowParams = { transaction: Transaction; index: number; isExpanded: boolean; onToggleExpand: () => void; onEdit: (transaction: Transaction) => void; onDelete: (transaction: Transaction) => void; }; export function TransactionCardRow({ transaction, index, isExpanded, onToggleExpand, onEdit, onDelete, }: TransactionCardRowParams) { const items = transaction.order_items ?? []; const variantCount = items.length; const productNames = [ ...new Set( items .map((item) => item.product_variant?.product?.name) .filter(Boolean), ), ]; const totalQty = items.reduce( (sum, item) => sum + Number(item.quantity), 0, ); const statusBadgeClass = STATUS_BADGE_CLASSES[transaction.status] ?? STATUS_BADGE_CLASSES.pending; return (
{index}.

{transaction.order_number}

{transaction.status_label} {transaction.payment_type_label}
{productNames.length > 0 && ( {productNames.join(', ')} )} {variantCount > 0 && ( ({variantCount} varian) )}
{formatDateTime(transaction.created_at)} Oleh:{' '} {transaction.created_by?.user_profile ?.full_name ?? '-'} {transaction.customer && ( Pelanggan:{' '} {transaction.customer.name} )} {transaction.notes && ( {transaction.notes} )}
Qty:{' '} {formatNumber(totalQty)} Channel:{' '} {transaction.channel_label} Harga:{' '} {transaction.price_type_label} Sub:{' '} {formatCurrency(transaction.subtotal)} {transaction.discount > 0 && ( Diskon:{' '} {formatCurrency(transaction.discount)} )} Total:{' '} {formatCurrency(transaction.total_amount)} = 0 ? 'text-green-600' : 'text-red-600'}> Laba:{' '} {formatCurrency(transaction.profit)} HPP:{' '} {formatCurrency(transaction.cogs)}
, onClick: () => onEdit(transaction), }, { label: 'Hapus', icon: ( ), onClick: () => onDelete(transaction), }, ]} wrapperClassName="flex shrink-0 items-center gap-1" />
); }