import {BaseTable} from "../../../../components/BaseTable/BaseTable.tsx";
import useDealProductsTableColumns from "./columns.tsx";
import {FC} from "react";
import {CRUDTableProps} from "../../../../types/CRUDTable.tsx";
import {DealProductSchema} from "../../../../client";
import {Button, Flex, rem} from "@mantine/core";
import {MRT_TableOptions} from "mantine-react-table";
import {modals} from "@mantine/modals";

type RestProps = {
    clientId: number;
}
type Props = CRUDTableProps<DealProductSchema> & RestProps;
const DealProductsTable: FC<Props> = ({items, clientId}) => {
    const columns = useDealProductsTableColumns();
    const onCreateClick = () => {
        modals.openContextModal({
            modal: "addDealProduct",
            title: "Добавление товара",
            innerProps: {
                onCreate: event => console.log(event),
                clientId
            }
        })

    }

    return (
        <BaseTable
            data={items}
            columns={columns}
            restProps={{
                renderBottomToolbar: ({}) => (
                    <Flex justify={"flex-end"} gap={rem(10)} p={rem(10)}>
                        {/*{(onMultipleDelete && table.getSelectedRowModel().rows.length > 0) && (*/}
                        {/*    <Button*/}
                        {/*        onClick={() => {*/}
                        {/*            onMultipleDelete(table.getSelectedRowModel().rows.map(row => row.original))*/}
                        {/*        }}*/}
                        {/*        variant={"filled"}*/}
                        {/*        color={"red"}*/}
                        {/*    >*/}
                        {/*        Удалить выбранные*/}
                        {/*    </Button>*/}
                        {/*)}*/}
                        <Button onClick={onCreateClick} variant={"default"}>
                            Добавить услугу
                        </Button>

                    </Flex>
                ),
            } as MRT_TableOptions<DealProductSchema>}
        />
    )
}

export default DealProductsTable;