import { useMemo } from "react";
import { MRT_ColumnDef, MRT_RowData } from "mantine-react-table";

type Props = {
    isBox: boolean;
}

const useShippingTableColumns = <T extends MRT_RowData>({ isBox }: Props) => {
    const hideBoxColumns = ["id"];

    return useMemo<MRT_ColumnDef<T>[]>(
        () => [
            {
                header: "ID",
                accessorKey: "id",
                Cell: ({ row }) => `K${row.original.id}`,
            },
            {
                header: "Название",
                accessorKey: "product.name",
                Cell: ({ row }) => row.original.product?.name ?? "-",
            },
            {
                header: "Артикул",
                accessorKey: "product.article",
                Cell: ({ row }) => row.original.product?.article ?? "-",
            },
            {
                header: "Размер",
                accessorKey: "product.size",
                Cell: ({ row }) => row.original.product?.size ?? "-",
            },
            {
                header: "Количество",
                accessorKey: "quantity",
            },
        ],
        [],
    ).filter(
        columnDef => isBox || !hideBoxColumns.includes(columnDef.accessorKey || ""),
    );
};

export default useShippingTableColumns;
