import { useState, MouseEvent } from "react";
import Info from "@icons/Info";

import { Paper, Popover, SxProps, Typography } from "@mui/material";

export const InfoPopover = ({ blink = false, sx }: {blink?: boolean, sx?: SxProps}) => {
    const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);

    const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
        setAnchorEl(event.currentTarget);
    };

    const handleClose = () => {
        setAnchorEl(null);
    };

    const open = Boolean(anchorEl);
    const id = open ? "simple-popover" : undefined;

    return (
        <>
            <Info
                className={blink ? "blink" : ""}
                onClick={handleClick}
                sx={{p:0, height: "20px", ...sx}}
            />
            <Popover
                id={id}
                open={open}
                anchorEl={anchorEl}
                onClose={handleClose}
                anchorOrigin={{
                    vertical: "bottom",
                    horizontal: "left",
                }}
            >
                <Paper
                    sx={{
                        p: "20px",
                        display: "flex",
                        justifyContent: "center",
                        alignItems: "center",
                        flexDirection: "column",
                    }}
                >
                    <Typography>
                        подсказка
                    </Typography>
                </Paper>
            </Popover>
        </>
    );
};