import type { Freight } from "@edr/types";
import { Table, type TableColumn } from "@edr/ui-common";

export interface BookingTableProps {
  bookings: Freight.IBooking[];
}

const columns: TableColumn<Freight.IBooking>[] = [
  { key: "reference", header: "Reference" },
  { key: "customerId", header: "Customer" },
  { key: "status", header: "Status" },
  {
    key: "scheduledDate",
    header: "Scheduled",
    render: (row) => new Date(row.scheduledDate).toLocaleDateString(),
  },
  {
    key: "totalAmount",
    header: "Total",
    render: (row) => row.totalAmount.toFixed(2),
  },
];

const BookingTable = ({ bookings }: BookingTableProps) => (
  <Table
    columns={columns}
    data={bookings}
    rowKey={(row) => row.id}
    emptyMessage="No bookings yet"
  />
);

export default BookingTable;
