import React, { FC } from "react";
import { IconDotsVertical, IconEdit, IconTrash } from "@tabler/icons-react";
import { Box, Menu } from "@mantine/core";
import DropdownMenuItem from "@/components/ui/DropdownMenuItem/DropdownMenuItem";
import ThemeIcon from "@/components/ui/ThemeIcon/ThemeIcon";
import { DealProductSchema } from "@/lib/client";

type Props = {
    value: DealProductSchema;
    onChange: (dealProduct: DealProductSchema) => void;
    onDelete: (dealProduct: DealProductSchema) => void;
};

const ProductMenu: FC<Props> = ({ value, onChange, onDelete }) => {
    return (
        <Menu>
            <Menu.Target>
                <Box
                    style={{ cursor: "pointer" }}
                    onClick={e => e.stopPropagation()}>
                    <ThemeIcon
                        bd={0}
                        variant={"default"}
                        size={"sm"}>
                        <IconDotsVertical />
                    </ThemeIcon>
                </Box>
            </Menu.Target>
            <Menu.Dropdown>
                <DropdownMenuItem
                    onClick={() => onChange(value)}
                    icon={<IconEdit />}
                    label={"Редактировать"}
                />
                <DropdownMenuItem
                    onClick={() => onDelete(value)}
                    icon={<IconTrash />}
                    label={"Удалить"}
                />
            </Menu.Dropdown>
        </Menu>
    );
};

export default ProductMenu;
