import {useMemo} from "react";
import {MRT_ColumnDef} from "mantine-react-table";
import {DealSummary} from "../../../../client";
import {ActionIcon, Image} from "@mantine/core";

const useDealsTableColumns = () => {
    return useMemo<MRT_ColumnDef<DealSummary>[]>(() => [

        {
            header: "Маркетплейс",
            size: 10,
            Cell: ({row}) => (
                <ActionIcon variant={"transparent"}>
                    <Image src={row.original.baseMarketplace?.iconUrl || ""}/>
                </ActionIcon>
            )
        },
        {
            header: "Дата создания",
            accessorKey: "createdAt",
            Cell: ({row}) => (new Date(row.original.createdAt)).toLocaleString("ru-RU"),
            enableSorting: true,
            sortingFn: (rowA, rowB) => ((new Date(rowB.original.createdAt)).getTime() - (new Date(rowA.original.createdAt)).getTime())
        },
        {
            accessorKey: "name",
            header: "Название",
            enableSorting: false
        },
        {
            accessorKey: "clientName",
            header: "Клиент",
            enableSorting: false
        },
        {
            Cell: ({row}) => (new Date(row.original.deadline)).toLocaleString("ru-RU"),
            accessorKey: "deadline",
            header: "Дедлайн",
            sortingFn: (rowA, rowB) => ((new Date(rowB.original.deadline)).getTime() - (new Date(rowA.original.deadline)).getTime())

        },
        {
            header: "Общая стоимость",
            Cell: ({row}) => (row.original.totalPrice).toLocaleString("ru-RU") + '₽',
            accessorKey:"totalPrice"
        }
    ], [])
}

export default useDealsTableColumns;