import { useMemo } from "react";
import { MRT_ColumnDef } from "mantine-react-table";
import { TransactionSchemaBase } from "../../../../../client";
import { formatDate } from "../../../../../types/utils.ts";


export const useTransactionsTableColumns = () => {
    return useMemo<MRT_ColumnDef<TransactionSchemaBase>[]>(
        () => [
            {
                accessorKey: "spentDate",
                header: "Дата",
                Cell: ({ row }) => formatDate(row.original.spentDate as string),
            },
            {
                accessorKey: "name",
                header: "Наименование",
            },
            {
                accessorKey: "comment",
                header: "Комментарий",
            },
            {
                accessorKey: "amount",
                header: "Сумма",
            },
            {
                accessorKey: "tags",
                header: "Теги",
                Cell: ({ row }) => row.original.tags.map(tag => tag.name).join(", "),
            },
            {
                accessorKey: "createdByUser",
                header: "Создал запись",
                Cell: ({ row }) => {
                    return `${row.original.createdByUser.firstName} ${row.original.createdByUser.secondName}`;
                },
            },
        ],
        [],
    );
};