import { useMemo } from "react";
import { DataTableColumn } from "mantine-datatable";
import UpdateDeleteTableActions from "@/components/ui/BaseTable/components/UpdateDeleteTableActions";
import { DealServiceSchema } from "@/lib/client";

type Props = {
    onChange: (dealService: DealServiceSchema) => void;
    onDelete: (dealService: DealServiceSchema) => void;
};

const useDealServicesTableColumns = ({ onChange, onDelete }: Props) => {
    return useMemo(
        () =>
            [
                {
                    accessor: "service.name",
                    title: "Название",
                    width: "53%",
                },
                {
                    accessor: "quantity",
                    title: "Кол-во",
                    width: "17%",
                },
                {
                    accessor: "price",
                    title: "Цена",
                    width: "30%",
                    render: dealService =>
                        dealService.price.toLocaleString("ru"),
                },
                {
                    accessor: "actions",
                    title: "Действия",
                    textAlign: "center",
                    width: "0%",
                    render: dealService => (
                        <UpdateDeleteTableActions
                            onDelete={() => onDelete(dealService)}
                            onChange={() => onChange(dealService)}
                        />
                    ),
                },
            ] as DataTableColumn<DealServiceSchema>[],
        [onChange, onDelete]
    );
};

export default useDealServicesTableColumns;
