import { useMemo } from "react";
import { DataTableColumn } from "mantine-datatable";
import UpdateDeleteTableActions from "@/components/ui/BaseTable/components/UpdateDeleteTableActions";
import { ServicesKitSchema } from "@/lib/client";
import { ServiceType } from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/types/service";

type Props = {
    onChange: (kit: ServicesKitSchema) => void;
    onDelete: (kit: ServicesKitSchema) => void;
};

const useServicesKitsTableColumns = ({ onDelete, onChange }: Props) => {
    return useMemo(
        () =>
            [
                {
                    accessor: "actions",
                    title: "Действия",
                    sortable: false,
                    textAlign: "center",
                    width: "0%",
                    render: kit => (
                        <UpdateDeleteTableActions
                            onDelete={() => onDelete(kit)}
                            onChange={() => onChange(kit)}
                        />
                    ),
                },
                {
                    accessor: "name",
                    title: "Название",
                    width: "60%",
                },
                {
                    title: "Кол-во услуг",
                    accessor: "services",
                    render: kit => kit.services.length,
                    width: "20%",
                },
                {
                    title: "Тип набора",
                    accessor: "serviceType",
                    render: kit =>
                        kit.serviceType === ServiceType.DEAL_SERVICE
                            ? "Для сделок"
                            : "Для товаров",
                    width: "20%",
                },
            ] as DataTableColumn<ServicesKitSchema>[],
        []
    );
};

export default useServicesKitsTableColumns;
