import { useMemo } from "react";
import { IconBasket } from "@tabler/icons-react";
import { DataTableColumn } from "mantine-datatable";
import { Center } from "@mantine/core";
import UpdateDeleteTableActions from "@/components/ui/BaseTable/components/UpdateDeleteTableActions";
import { ClientSchema } from "@/lib/client";
import { ModuleNames } from "@/modules/modules";

type Props = {
    onChange: (client: ClientSchema) => void;
    onDelete: (client: ClientSchema) => void;
    onOpenMarketplacesList: (client: ClientSchema) => void;
    modulesSet: Set<ModuleNames>;
};

export const useClientsTableColumns = ({
    onChange,
    onDelete,
    onOpenMarketplacesList,
    modulesSet,
}: Props) => {
    return useMemo(
        () =>
            [
                {
                    accessor: "actions",
                    title: <Center>Действия</Center>,
                    width: "0%",
                    render: client => (
                        <UpdateDeleteTableActions
                            onDelete={() => onDelete(client)}
                            onChange={() => onChange(client)}
                            otherActions={[
                                {
                                    label: "Маркетплейсы",
                                    icon: <IconBasket />,
                                    onClick: () =>
                                        onOpenMarketplacesList(client),
                                    hidden: !modulesSet.has(
                                        ModuleNames.FULFILLMENT_BASE
                                    ),
                                },
                            ]}
                        />
                    ),
                },
                {
                    accessor: "name",
                    title: "Имя",
                },
                {
                    accessor: "details.telegram",
                    title: "Телеграм",
                },
                {
                    accessor: "details.email",
                    title: "Почта",
                },
                {
                    accessor: "details.phoneNumber",
                    title: "Телефон",
                },
                {
                    accessor: "details.inn",
                    title: "ИНН",
                },
                {
                    accessor: "companyName",
                    title: "Название компании",
                },
                {
                    accessor: "comment",
                    title: "Комментарий",
                },
            ] as DataTableColumn<ClientSchema>[],
        [onChange, onDelete]
    );
};
