import { useMemo } from "react";
import { MRT_ColumnDef } from "mantine-react-table";
import { DealSchema } from "@/lib/client";
import { utcDateTimeToLocalString } from "@/utils/datetime";

const useDealsTableColumns = () => {
    return useMemo<MRT_ColumnDef<DealSchema>[]>(
        () => [
            {
                accessorKey: "id",
                header: "Номер",
                size: 20,
            },
            {
                accessorKey: "name",
                header: "Название",
                enableSorting: false,
            },
            {
                header: "Дата создания",
                accessorKey: "createdAt",
                Cell: ({ row }) =>
                    utcDateTimeToLocalString(row.original.createdAt),
                enableSorting: true,
                sortingFn: (rowA, rowB) =>
                    new Date(rowB.original.createdAt).getTime() -
                    new Date(rowA.original.createdAt).getTime(),
            },
        ],
        []
    );
};

export default useDealsTableColumns;
