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 { BoardSchema } from "@/lib/client";

type Props = {
    board: BoardSchema;
    startEditing: () => void;
    onDeleteBoard: (board: BoardSchema) => void;
    isHovered?: boolean;
};

const BoardMenu: FC<Props> = ({
    board,
    startEditing,
    onDeleteBoard,
    isHovered = true,
}) => {
    return (
        <Menu>
            <Menu.Target>
                <Box
                    style={{
                        opacity: isHovered ? 1 : 0,
                        cursor: "pointer",
                    }}
                    onClick={e => e.stopPropagation()}>
                    <ThemeIcon size={"sm"}>
                        <IconDotsVertical />
                    </ThemeIcon>
                </Box>
            </Menu.Target>
            <Menu.Dropdown>
                <DropdownMenuItem
                    onClick={startEditing}
                    icon={<IconEdit />}
                    label={"Переименовать"}
                />
                <DropdownMenuItem
                    onClick={() => onDeleteBoard(board)}
                    icon={<IconTrash />}
                    label={"Удалить"}
                />
            </Menu.Dropdown>
        </Menu>
    );
};

export default BoardMenu;
