import { useMemo } from "react";
import { MRT_ColumnDef } from "mantine-react-table";
import { ModuleSchema } from "../../../../../../../client";
import { Center, Checkbox } from "@mantine/core";


type Props = {
    selectedModules: Set<number>;
}

const useModulesTableColumns = ({ selectedModules }: Props) => {
    return useMemo<MRT_ColumnDef<ModuleSchema>[]>(
        () => [
            {
                header: " ",
                Cell: ({ row }) => (
                    <Center>
                        <Checkbox
                            checked={selectedModules.has(row.original.id)}
                            onChange={() => {
                                if (selectedModules.has(row.original.id)) {
                                    selectedModules.delete(row.original.id);
                                } else {
                                    selectedModules.add(row.original.id);
                                }
                            }}
                        />
                    </Center>
                ),
                size: 1,
            },
            {
                header: "Название",
                accessorKey: "label",
                size: 10000,
            },
        ],
        [selectedModules],
    );
};

export default useModulesTableColumns;
