"use client";
import { tooltipVariants } from '@heroui/styles';
import React__default, { createContext, useContext } from 'react';
import { TooltipTrigger as TooltipTrigger$1, OverlayArrow, Tooltip, Focusable } from 'react-aria-components';
import { composeTwRenderProps, composeSlotClassName } from '../../utils/compose.js';
import { jsx } from 'react/jsx-runtime';

const TooltipContext = /*#__PURE__*/createContext({});

/* -------------------------------------------------------------------------------------------------
 * Tooltip Root
 * -----------------------------------------------------------------------------------------------*/

const TooltipRoot = ({
  children,
  ...props
}) => {
  const slots = React__default.useMemo(() => tooltipVariants(), []);
  return /*#__PURE__*/jsx(TooltipContext, {
    value: {
      slots
    },
    children: /*#__PURE__*/jsx(TooltipTrigger$1, {
      "data-slot": "tooltip-root",
      ...props,
      children: children
    })
  });
};

/* -------------------------------------------------------------------------------------------------
 * Tooltip Content
 * -----------------------------------------------------------------------------------------------*/

const TooltipContent = ({
  children,
  className,
  offset: offsetProp,
  showArrow = false,
  ...props
}) => {
  const {
    slots
  } = useContext(TooltipContext);
  const offset = offsetProp ? offsetProp : showArrow ? 7 : 3;
  return /*#__PURE__*/jsx(Tooltip, {
    ...props,
    className: composeTwRenderProps(className, slots?.base()),
    offset: offset,
    children: children
  });
};

/* -------------------------------------------------------------------------------------------------
 * Tooltip Arrow
 * -----------------------------------------------------------------------------------------------*/

const TooltipArrow = ({
  children,
  className,
  ...props
}) => {
  const defaultArrow = /*#__PURE__*/jsx("svg", {
    "data-slot": "overlay-arrow",
    height: 12,
    viewBox: "0 0 12 12",
    width: 12,
    children: /*#__PURE__*/jsx("path", {
      d: "M0 0 Q6 9 12 0"
    })
  });
  const arrow = /*#__PURE__*/React__default.isValidElement(children) ? /*#__PURE__*/React__default.cloneElement(children, {
    "data-slot": "overlay-arrow"
  }) : defaultArrow;
  return /*#__PURE__*/jsx(OverlayArrow, {
    "data-slot": "tooltip-arrow",
    ...props,
    className: className,
    children: arrow
  });
};

/* -------------------------------------------------------------------------------------------------
 * Tooltip Trigger
 * -----------------------------------------------------------------------------------------------*/

const TooltipTrigger = ({
  children,
  className,
  ...props
}) => {
  const {
    slots
  } = useContext(TooltipContext);
  return /*#__PURE__*/jsx(Focusable, {
    children: /*#__PURE__*/jsx("div", {
      className: composeSlotClassName(slots?.trigger, className),
      "data-slot": "tooltip-trigger",
      role: "button",
      ...props,
      children: children
    })
  });
};

export { TooltipArrow, TooltipContent, TooltipRoot, TooltipTrigger };
