import ToolTipIcon from "@Assets/Icons/tool-tip.svg";
import styled from "@emotion/styled";
import TooltipMUI, { tooltipClasses, TooltipProps } from "@mui/material/Tooltip";
import Image from "next/image";
import React from "react";

type IProps = {
	title?: string | JSX.Element;
	text?: string | JSX.Element;
	className?: string;
	isNotFlex?: boolean;
};

type IState = {
	showContent: boolean;
	event: React.MouseEvent<HTMLElement> | null;
};

const LightTooltip = styled(({ className, ...props }: TooltipProps) => <TooltipMUI {...props} classes={{ popper: className }} />)(
	({ theme }) => ({
		[`& .${tooltipClasses.tooltip}`]: {
			backgroundColor: "var(--color-generic-white)",
			color: "var(--color-generic-black)",
			boxShadow: "0px 4px 24px 0px #00000026",
			fontSize: 14,
			fontWeight: 400,
			lineHeight: "22px",
			fontFamily: "var(--font-primary)",
			padding: "16px",
			borderRadius: "0px",
		},
		[`& .${tooltipClasses.arrow}`]: {
			color: "var(--color-generic-white)",
		},
	}),
);

export default class Tooltip extends React.Component<IProps, IState> {
	static defaultProps: Partial<IProps> = {
		isNotFlex: false,
	};

	public constructor(props: IProps) {
		super(props);
	}

	public override render(): JSX.Element {
		return (
			<LightTooltip title={this.props.text} placement="top" arrow>
				<span className={this.props.className} style={!this.props.isNotFlex ? { display: "flex" } : {}}>
					<Image src={ToolTipIcon} alt="toolTip icon" />
				</span>
			</LightTooltip>
		);
	}
}
