'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var primitives_Tooltip = require('./primitives/Tooltip.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

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

exports.Tooltip = Tooltip;
//# sourceMappingURL=Tooltip-Dph_R3Ct.js.map
