import { Tooltip as MuiTooltip, type TooltipProps } from '@mui/material'

let tooltipEnterDelay = 500

/**
 * A wrapper around MUI's Tooltip component with enterNextDelay set to 1000ms by default.
 *
 * This component ensures consistent tooltip behavior across the application.
 *
 * @example
 * <Tooltip title="This is a tooltip">
 *   <Button>Hover me</Button>
 * </Tooltip>
 */
export function Tooltip({
  children,
  title,
  enterNextDelay = tooltipEnterDelay,
  ...props
}: TooltipProps) {
  return (
    <MuiTooltip title={title} enterNextDelay={enterNextDelay} {...props}>
      {children}
    </MuiTooltip>
  )
}

/**
 * Sets the global default `enterNextDelay` for all Tooltip components in the application.
 *
 * @param delay - Delay in milliseconds before showing tooltips on subsequent hovers.
 *
 * @example
 * ```tsx
 * import { setTooltipEnterDelay } from '@carto/ps-react-ui/components';
 *
 * // Set global delay to 300ms at app initialization
 * setTooltipEnterDelay(300);
 * ```
 */
export function setTooltipEnterDelay(delay: number) {
  tooltipEnterDelay = delay
}
