"use client"; import { ReusableTable, ActionButtons } from "../UI"; import { ORDER_STATUS_MAP } from "./OrderDetailModel"; import type { TableColumn } from "@/src/types/models"; import type { Order } from "@/src/types/order"; function fmtDate(iso?: string | null): string { if (!iso) return "—"; return new Date(iso).toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" }); } function fmtAmount(n?: number | null): string { if (n == null) return "—"; return `${n.toFixed(2)} SAR`; } interface OrderTableProps { orders: Order[]; loading: boolean; search: string; page: number; pages: number; setPage: React.Dispatch>; onRowClick: (orderId: string) => void; onEdit: (order: Order) => void; onDelete: (order: Order) => void; } export function OrderTable({ orders, loading, search, page, pages, setPage, onRowClick, onEdit, onDelete, }: OrderTableProps) { const columns: TableColumn[] = [ { key: "shipmentNumber", header: "رقم الشحنة #", width: "1.6fr", render: (o) => (

{o.shipmentNumber}

{fmtDate(o.createdAt)}

), }, { key: "recipient", header: "المستلم", width: "1.6fr", render: (o) => (

{o.recipientName}

{o.recipientPhone}

), }, { key: "client", header: "العميل", width: "1.2fr", render: (o) => o.client?.name ?? "—" }, { key: "amount", header: "الكمية", width: "1.1fr", render: (o) => ( {fmtAmount(o.totalPrice)} ), }, { key: "status", header: "الحالة", width: "1fr", render: (o) => { const s = ORDER_STATUS_MAP[o.currentStatus] ?? ORDER_STATUS_MAP.Created; return ( {s.label} ); }, }, ]; return ( onRowClick(o.id)} emptyDescription={search ? `No results for "${search}"` : undefined} renderActions={(o) => ( onEdit(o)} onDelete={() => onDelete(o)} /> )} /> ); }