import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import React__default, { useState, useEffect } from 'react';
import { TooltipProvider, Tooltip as Tooltip$1, TooltipTrigger, TooltipContent } from './primitives/Tooltip.js';

const SIDE_MAP = {
  top: "top",
  bottom: "bottom",
  left: "left",
  right: "right",
  "top-start": "top",
  "top-end": "top",
  "bottom-start": "bottom",
  "bottom-end": "bottom",
  "left-start": "left",
  "left-end": "left",
  "right-start": "right",
  "right-end": "right",
  auto: "top"
};
const ALIGN_MAP = {
  top: "center",
  bottom: "center",
  left: "center",
  right: "center",
  "top-start": "start",
  "top-end": "end",
  "bottom-start": "start",
  "bottom-end": "end",
  "left-start": "start",
  "left-end": "end",
  "right-start": "start",
  "right-end": "end",
  auto: "center"
};

const Tooltip = ({
  content,
  children,
  disabled = false,
  position = "auto",
  interactive = false,
  hideAfter = -1,
  className,
  delayDuration = 0,
  defaultOpen,
  // Radix TooltipContent props forwarded
  ...contentProps
}) => {
  const [open, setOpen] = useState(false);
  useEffect(() => {
    if (!open || hideAfter <= 0) return;
    const timer = setTimeout(() => setOpen(false), hideAfter);
    return () => clearTimeout(timer);
  }, [open, hideAfter]);
  if (disabled || !content) {
    return /* @__PURE__ */ jsx(Fragment, { children });
  }
  const side = SIDE_MAP[position] ?? "top";
  const align = ALIGN_MAP[position] ?? "center";
  const trigger = React__default.isValidElement(children) ? children : /* @__PURE__ */ jsx("span", { children });
  return /* @__PURE__ */ jsx(TooltipProvider, { delayDuration, children: /* @__PURE__ */ jsxs(
    Tooltip$1,
    {
      open,
      onOpenChange: setOpen,
      defaultOpen,
      disableHoverableContent: !interactive,
      children: [
        /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: trigger }),
        /* @__PURE__ */ jsx(
          TooltipContent,
          {
            side,
            align,
            className,
            onPointerDownOutside: interactive ? (e) => e.preventDefault() : void 0,
            ...contentProps,
            children: content
          }
        )
      ]
    }
  ) });
};
Tooltip.displayName = "Tooltip";

export { Tooltip as T };
//# sourceMappingURL=Tooltip-CA3irJ2q.js.map
