import React, { FC } from "react";
import { IconDotsVertical, IconEdit, IconTrash } from "@tabler/icons-react";
import { Box, Group, Menu, Text } from "@mantine/core";
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>
                <Menu.Item
                    onClick={e => {
                        e.stopPropagation();
                        onChange(value);
                    }}>
                    <Group wrap={"nowrap"}>
                        <IconEdit />
                        <Text>Редактировать</Text>
                    </Group>
                </Menu.Item>
                <Menu.Item
                    onClick={e => {
                        e.stopPropagation();
                        onDelete(value);
                    }}>
                    <Group wrap={"nowrap"}>
                        <IconTrash />
                        <Text>Удалить</Text>
                    </Group>
                </Menu.Item>
            </Menu.Dropdown>
        </Menu>
    );
};

export default ProductMenu;
