import React, { FC } from "react";
import { IconDotsVertical, IconEdit, IconTrash } from "@tabler/icons-react";
import { Box, Group, Menu, Text } from "@mantine/core";
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
import { ProjectSchema } from "@/lib/client";
import styles from "./../ProjectsEditorDrawer.module.css";

type Props = {
    project: ProjectSchema;
    startEditing: () => void;
};

const ProjectMenu: FC<Props> = ({ project, startEditing }) => {
    const { projectsCrud } = useProjectsContext();

    return (
        <Menu>
            <Menu.Target>
                <Box
                    className={styles["menu-button"]}
                    onClick={e => e.stopPropagation()}>
                    <IconDotsVertical />
                </Box>
            </Menu.Target>
            <Menu.Dropdown>
                <Menu.Item
                    onClick={e => {
                        e.stopPropagation();
                        startEditing();
                    }}>
                    <Group wrap={"nowrap"}>
                        <IconEdit />
                        <Text>Переименовать</Text>
                    </Group>
                </Menu.Item>
                <Menu.Item
                    onClick={e => {
                        e.stopPropagation();
                        projectsCrud.onDelete(project);
                    }}>
                    <Group wrap={"nowrap"}>
                        <IconTrash />
                        <Text>Удалить</Text>
                    </Group>
                </Menu.Item>
            </Menu.Dropdown>
        </Menu>
    );
};

export default ProjectMenu;
