import {useMemo} from "react";
import {MRT_ColumnDef} from "mantine-react-table";
import {ProductSchema} from "../../../../client";
import {List, Spoiler, useMantineTheme} from "@mantine/core";

export const useProductsTableColumns = () => {
    const theme = useMantineTheme();
    return useMemo<MRT_ColumnDef<ProductSchema>[]>(() => [
        {
            accessorKey: "article",
            header: "Артикул",
            enableSorting: false,
        },
        {
            accessorKey: "name",
            header: "Название",
            enableSorting: false,
        },
        {
            accessorKey: "barcodes",
            header: "Штрихкоды",
            Cell: ({cell}) => {
                return (
                    <List size={"sm"}>
                        <Spoiler maxHeight={parseFloat(theme.lineHeights.sm) * 25}
                                 showLabel={"Показать все"}
                                 hideLabel={"Скрыть"}>
                            {cell.getValue<string[]>().map(barcode => (
                                <List.Item key={barcode}>
                                    {barcode}
                                </List.Item>
                            ))}
                        </Spoiler>

                    </List>
                )
            },
            enableSorting: false,
        },
        {
            accessorKey: "barcodeTemplate.name",
            header: "Шаблон штрихкода",
            enableSorting: false,
        },
        {
            accessorKey: "brand",
            header: "Бренд",
            enableSorting: false
        },
        {
            accessorKey: "composition",
            header: "Состав",
            enableSorting: false,
        },
        {
            accessorKey: "color",
            header: "Цвет",
            enableSorting: false
        },
        {

            accessorKey: "size",
            header: "Размер",
            enableSorting: false
        },
        {
            accessorKey: "additionalInfo",
            header: "Доп. информация",
            enableSorting: false
        }
    ], []);

}