import { useState, useEffect, cloneElement } from 'react';
import { Tooltip, ClickAwayListener } from '@mui/material';
import { useMemoizedFn } from 'ahooks';
import useMobile from '../hooks/use-mobile';
import { jsx as _jsx } from "react/jsx-runtime";
function TooltipEnhance({
  children,
  ...props
}) {
  const isMobile = useMobile();
  const [visible, setVisible] = useState(false);
  const triggerVisible = useMemoizedFn(() => {
    setVisible(!visible);
  });
  useEffect(() => {
    setVisible(false);
  }, [isMobile]);
  if (isMobile) {
    return /*#__PURE__*/_jsx(ClickAwayListener, {
      onClickAway: () => setVisible(false),
      children: /*#__PURE__*/_jsx(Tooltip, {
        ...props,
        disableFocusListener: true,
        disableHoverListener: true,
        disableTouchListener: true,
        slotProps: {
          popper: {
            disablePortal: true
          }
        },
        open: visible,
        onClose: triggerVisible,
        children: /*#__PURE__*/cloneElement(children, {
          onClick: triggerVisible
        })
      })
    });
  }
  return /*#__PURE__*/_jsx(Tooltip, {
    ...props,
    children: children
  });
}

// 直接复制 MUI Tooltip 的 propTypes 和 defaultProps
TooltipEnhance.propTypes = Tooltip.propTypes;
TooltipEnhance.defaultProps = Tooltip.defaultProps;
export default TooltipEnhance;