import { jsx as h } from "react/jsx-runtime";
import f, { useContext as C, useState as U, useMemo as S, useRef as m, useEffect as O, forwardRef as W, createContext as M } from "react";
import { $ as K, e as V, a as j } from "./utils-CrjF8U_E.es.js";
import { b as Y, $ as q, c as z, d as G } from "./OverlayArrow-DQTbb80n.es.js";
import { $ as E, a as J } from "./mergeProps-B-cqsBhL.es.js";
import { $ as H } from "./filterDOMProps-Cxz9cAAv.es.js";
import { $ as Q, a as X } from "./animation-BfmkkMe7.es.js";
import { $ as Z, a as ee } from "./useFocusable-C4Re42UX.es.js";
import te from "react-dom";
import { $ as oe } from "./SSRProvider-CQ9PmFV6.es.js";
import { b as re, $ as ne } from "./useFocusVisible-_CKiSck5.es.js";
import { $ as I } from "./useHover-BiPYlZr_.es.js";
import { createRecipeContext as le } from "@chakra-ui/react";
const y = /* @__PURE__ */ f.createContext(null);
function ae(e) {
  let { children: o } = e, t = C(y), [r, i] = U(0), a = S(() => ({
    parent: t,
    modalCount: r,
    addModal() {
      i((l) => l + 1), t && t.addModal();
    },
    removeModal() {
      i((l) => l - 1), t && t.removeModal();
    }
  }), [
    t,
    r
  ]);
  return /* @__PURE__ */ f.createElement(y.Provider, {
    value: a
  }, o);
}
function ie() {
  let e = C(y);
  return {
    modalProviderProps: {
      "aria-hidden": e && e.modalCount > 0 ? !0 : void 0
    }
  };
}
function ce(e) {
  let { modalProviderProps: o } = ie();
  return /* @__PURE__ */ f.createElement("div", {
    "data-overlay-container": !0,
    ...e,
    ...o
  });
}
function fe(e) {
  return /* @__PURE__ */ f.createElement(ae, null, /* @__PURE__ */ f.createElement(ce, e));
}
function de(e) {
  let o = oe(), { portalContainer: t = o ? null : document.body, ...r } = e, { getContainer: i } = Y();
  if (!e.portalContainer && i && (t = i()), f.useEffect(() => {
    if (t?.closest("[data-overlay-container]")) throw new Error("An OverlayContainer must not be inside another container. Please change the portalContainer prop.");
  }, [
    t
  ]), !t) return null;
  let a = /* @__PURE__ */ f.createElement(fe, r);
  return /* @__PURE__ */ te.createPortal(a, t);
}
function ue(e, o) {
  let t = H(e, {
    labelable: !0
  }), { hoverProps: r } = I({
    onHoverStart: () => o?.open(!0),
    onHoverEnd: () => o?.close()
  });
  return {
    tooltipProps: E(t, r, {
      role: "tooltip"
    })
  };
}
function se(e, o, t) {
  let { isDisabled: r, trigger: i, shouldCloseOnPress: a = !0 } = e, l = J(), n = m(!1), c = m(!1), $ = () => {
    (n.current || c.current) && o.open(c.current);
  }, s = (x) => {
    !n.current && !c.current && o.close(x);
  };
  O(() => {
    let x = (w) => {
      t && t.current && w.key === "Escape" && (w.stopPropagation(), o.close(!0));
    };
    if (o.isOpen)
      return document.addEventListener("keydown", x, !0), () => {
        document.removeEventListener("keydown", x, !0);
      };
  }, [
    t,
    o
  ]);
  let v = () => {
    i !== "focus" && (re() === "pointer" ? n.current = !0 : n.current = !1, $());
  }, g = () => {
    i !== "focus" && (c.current = !1, n.current = !1, s());
  }, T = () => {
    a && (c.current = !1, n.current = !1, s(!0));
  }, d = () => {
    ne() && (c.current = !0, $());
  }, F = () => {
    c.current = !1, n.current = !1, s(!0);
  }, { hoverProps: N } = I({
    isDisabled: r,
    onHoverStart: v,
    onHoverEnd: g
  }), { focusableProps: _ } = Z({
    isDisabled: r,
    onFocus: d,
    onBlur: F
  }, t);
  return {
    triggerProps: {
      "aria-describedby": o.isOpen ? l : void 0,
      ...E(_, N, {
        onPointerDown: T,
        onKeyDown: T
      }),
      tabIndex: void 0
    },
    tooltipProps: {
      id: l
    }
  };
}
const $e = 1500, D = 500;
let p = {}, pe = 0, P = !1, u = null, b = null;
function L(e = {}) {
  let { delay: o = $e, closeDelay: t = D } = e, { isOpen: r, open: i, close: a } = q(e), l = S(() => `${++pe}`, []), n = m(null), c = m(a), $ = () => {
    p[l] = g;
  }, s = () => {
    for (let d in p) d !== l && (p[d](!0), delete p[d]);
  }, v = () => {
    n.current && clearTimeout(n.current), n.current = null, s(), $(), P = !0, i(), u && (clearTimeout(u), u = null), b && (clearTimeout(b), b = null);
  }, g = (d) => {
    d || t <= 0 ? (n.current && clearTimeout(n.current), n.current = null, c.current()) : n.current || (n.current = setTimeout(() => {
      n.current = null, c.current();
    }, t)), u && (clearTimeout(u), u = null), P && (b && clearTimeout(b), b = setTimeout(() => {
      delete p[l], b = null, P = !1;
    }, Math.max(D, t)));
  }, T = () => {
    s(), $(), !r && !u && !P ? u = setTimeout(() => {
      u = null, P = !0, v();
    }, o) : r || v();
  };
  return O(() => {
    c.current = a;
  }, [
    a
  ]), O(() => () => {
    n.current && clearTimeout(n.current), p[l] && delete p[l];
  }, [
    l
  ]), {
    isOpen: r,
    open: (d) => {
      !d && o > 0 && !n.current ? T() : v();
    },
    close: g
  };
}
const R = /* @__PURE__ */ M(null), A = /* @__PURE__ */ M(null);
function be(e) {
  let o = L(e), t = m(null), { triggerProps: r, tooltipProps: i } = se(e, o, t);
  return /* @__PURE__ */ f.createElement(V, {
    values: [
      [
        R,
        o
      ],
      [
        A,
        {
          ...i,
          triggerRef: t
        }
      ]
    ]
  }, /* @__PURE__ */ f.createElement(ee, {
    ...r,
    ref: t
  }, e.children));
}
const me = /* @__PURE__ */ W(function({ UNSTABLE_portalContainer: o, ...t }, r) {
  [t, r] = K(t, r, A);
  let i = C(R), a = L(t), l = t.isOpen != null || t.defaultOpen != null || !i ? a : i, n = Q(r, l.isOpen) || t.isExiting || !1;
  return !l.isOpen && !n ? null : /* @__PURE__ */ f.createElement(de, {
    portalContainer: o
  }, /* @__PURE__ */ f.createElement(ve, {
    ...t,
    tooltipRef: r,
    isExiting: n
  }));
});
function ve(e) {
  let o = C(R), t = m(null), { overlayProps: r, arrowProps: i, placement: a, triggerAnchorPoint: l } = z({
    placement: e.placement || "top",
    targetRef: e.triggerRef,
    overlayRef: e.tooltipRef,
    arrowRef: t,
    offset: e.offset,
    crossOffset: e.crossOffset,
    isOpen: o.isOpen,
    arrowBoundaryOffset: e.arrowBoundaryOffset,
    shouldFlip: e.shouldFlip,
    containerPadding: e.containerPadding,
    onClose: () => o.close(!0)
  }), n = X(e.tooltipRef, !!a) || e.isEntering || !1, c = j({
    ...e,
    defaultClassName: "react-aria-Tooltip",
    values: {
      placement: a,
      isEntering: n,
      isExiting: e.isExiting,
      state: o
    }
  });
  e = E(e, r);
  let { tooltipProps: $ } = ue(e, o), s = H(e, {
    global: !0
  });
  return /* @__PURE__ */ f.createElement("div", {
    ...E(s, c, $),
    ref: e.tooltipRef,
    style: {
      ...r.style,
      "--trigger-anchor-point": l ? `${l.x}px ${l.y}px` : void 0,
      ...c.style
    },
    "data-placement": a ?? void 0,
    "data-entering": n || void 0,
    "data-exiting": e.isExiting || void 0
  }, /* @__PURE__ */ f.createElement(G.Provider, {
    value: {
      ...i,
      placement: a,
      ref: t
    }
  }, c.children));
}
function k({
  // Match delays to current ui-kit tooltip
  delay: e = 300,
  closeDelay: o = 200,
  ...t
}) {
  return /* @__PURE__ */ h(be, { delay: e, closeDelay: o, ...t });
}
k.displayName = "Tooltip.Root";
const { withContext: xe } = /* @__PURE__ */ le({ key: "nimbusTooltip" }), Pe = /* @__PURE__ */ xe("div");
function B({
  children: e,
  placement: o = "bottom",
  ref: t,
  ...r
}) {
  return /* @__PURE__ */ h(Pe, { ref: t, asChild: !0, ...r, children: /* @__PURE__ */ h(me, { placement: o, ...r, children: e }) });
}
B.displayName = "Tooltip.Content";
const Ie = {
  /**
   * # Tooltip.Root
   *
   * The root component that provides state management and positioning logic.
   * Wraps the trigger element and tooltip content, handling hover and focus interactions.
   *
   * @example
   * ```tsx
   * <Tooltip.Root placement="top" delay={200}>
   *   <IconButton aria-label="Info">
   *     <InfoIcon />
   *   </IconButton>
   *   <Tooltip.Content>Additional information</Tooltip.Content>
   * </Tooltip.Root>
   * ```
   */
  Root: k,
  /**
   * # Tooltip.Content
   *
   * The tooltip content container that appears on trigger hover or focus.
   * Automatically positions itself relative to the trigger element.
   *
   * @example
   * ```tsx
   * <Tooltip.Root>
   *   <span tabIndex={0}>Hover or focus me</span>
   *   <Tooltip.Content>
   *     <Stack gap="100">
   *       <Text fontWeight="600">Tooltip Title</Text>
   *       <Text>Detailed description goes here.</Text>
   *     </Stack>
   *   </Tooltip.Content>
   * </Tooltip.Root>
   * ```
   */
  Content: B
};
export {
  Ie as T
};
//# sourceMappingURL=tooltip-cwtXJhIK.es.js.map
