import { useMemo } from "react";
import { MRT_ColumnDef } from "mantine-react-table";
import { TransactionTagSchema } from "../../../../../client";
import { TextInput } from "@mantine/core";


type Props = {
    editingTagId: number;
    setTagName: (tagName: string) => void;
}

export const useTransactionTagsTableColumns = ({
                                               editingTagId, setTagName,
                                           }: Props) => {
    return useMemo<MRT_ColumnDef<TransactionTagSchema>[]>(
        () => [
            {
                accessorKey: "name",
                header: "Наименование",
                Cell: ({ row }) => {
                    if (row.original.id === editingTagId) {
                        return (
                            <TextInput
                                defaultValue={row.original.name}
                                onChange={event => setTagName(event.target.value)}
                            />
                        );
                    }
                    return row.original.name;
                },
            },
        ],
        [editingTagId],
    );
};