import { j as e } from "../../_virtual/jsx-runtime.js";
import { useState as r } from "react";
import { usePopper as S } from "../../node_modules/react-popper/lib/esm/usePopper.js";
import U from "../../icons/Close.js";
import { useDelayUnmount as V } from "../../hooks/useDelayUnmount.js";
import { Wrapper as W, PopoverContainer as g, TooltipTitle as v, CloseIconContainer as B } from "./styles.js";
import { getId as L } from "../../utils/index.js";
import { IconButton as N } from "../IconButton/index.js";
function J({
  children: m,
  mode: f = "AUTO",
  width: u,
  content: l,
  variant: o = "definition",
  placement: a = "top-start",
  title: h,
  xOffset: x = 0,
  yOffset: j = 4,
  nonStaticWidth: b = !1,
  ...t
}) {
  const [E, T] = r(null), [k, C] = r(null), [c, d] = r(!1), I = V(c, 350), y = L(t["data-testid"]), p = b && o === "definition", i = f === "MANUAL" && o === "definition", M = p && !["top", "bottom"].includes(a) ? "top" : a, { styles: A, attributes: P } = S(E, k, {
    placement: M,
    modifiers: [
      {
        name: "offset",
        options: {
          offset: [x, j]
        }
      }
    ]
  }), n = () => {
    d(!0);
  }, s = () => {
    d(!1);
  }, R = () => i ? {
    onClick: n
  } : {
    onMouseEnter: n,
    onMouseLeave: s
  };
  return /* @__PURE__ */ e.jsxs(W, { children: [
    /* @__PURE__ */ e.jsx(
      "span",
      {
        ref: T,
        onFocus: n,
        onBlur: s,
        ...R(),
        tabIndex: 0,
        children: m
      }
    ),
    I && l && /* @__PURE__ */ e.jsxs(
      g,
      {
        ref: C,
        width: u,
        style: A.popper,
        variant: o,
        isVisible: c,
        isManual: i,
        nonStaticWidth: p,
        ...P.props,
        "data-testid": t["data-testid"],
        "data-trackid": t["data-trackid"],
        "aria-label": t["aria-label"],
        "aria-checked": t["aria-checked"],
        children: [
          o === "definition" && /* @__PURE__ */ e.jsx(v, { children: h }),
          l,
          i && /* @__PURE__ */ e.jsx(B, { children: /* @__PURE__ */ e.jsx(
            N,
            {
              icon: /* @__PURE__ */ e.jsx(U, {}),
              variant: "ghost",
              size: "x-small",
              "data-testid": y("close-icon"),
              onClick: s
            }
          ) })
        ]
      }
    )
  ] });
}
export {
  J as Tooltip
};
