import { jsx as h } from "react/jsx-runtime";
import c, { useContext as E, useState as _, useMemo as S, useRef as m, useEffect as y, forwardRef as U, createContext as M } from "react";
import { $ as W, e as K, a as V } from "./utils-B6pV5ewr.es.js";
import { d as j, $ as Y, a as q, e as z, b as G, f as J } from "./OverlayArrow-BIjbCSXk.es.js";
import { $ as T, a as Q } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as H } from "./filterDOMProps-BSVCO5jK.es.js";
import { $ as X, a as Z } from "./useFocusable-Cs6i58WP.es.js";
import ee from "react-dom";
import { $ as te } from "./SSRProvider-eIEwc-2s.es.js";
import { b as oe, $ as re } from "./useFocusVisible-B3HmFL2Q.es.js";
import { $ as I } from "./useHover-BQRSM3qT.es.js";
import { createRecipeContext as ne } from "@chakra-ui/react";
const O = /* @__PURE__ */ c.createContext(null);
function le(e) {
  let { children: o } = e, t = E(O), [r, i] = _(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__ */ c.createElement(O.Provider, {
    value: a
  }, o);
}
function ae() {
  let e = E(O);
  return {
    modalProviderProps: {
      "aria-hidden": e && e.modalCount > 0 ? !0 : void 0
    }
  };
}
function ie(e) {
  let { modalProviderProps: o } = ae();
  return /* @__PURE__ */ c.createElement("div", {
    "data-overlay-container": !0,
    ...e,
    ...o
  });
}
function ce(e) {
  return /* @__PURE__ */ c.createElement(le, null, /* @__PURE__ */ c.createElement(ie, e));
}
function fe(e) {
  let o = te(), { portalContainer: t = o ? null : document.body, ...r } = e, { getContainer: i } = j();
  if (!e.portalContainer && i && (t = i()), c.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__ */ c.createElement(ce, r);
  return /* @__PURE__ */ ee.createPortal(a, t);
}
function de(e, o) {
  let t = H(e, {
    labelable: !0
  }), { hoverProps: r } = I({
    onHoverStart: () => o?.open(!0),
    onHoverEnd: () => o?.close()
  });
  return {
    tooltipProps: T(t, r, {
      role: "tooltip"
    })
  };
}
function ue(e, o, t) {
  let { isDisabled: r, trigger: i } = e, a = Q(), l = m(!1), n = m(!1), f = () => {
    (l.current || n.current) && o.open(n.current);
  }, s = (g) => {
    !l.current && !n.current && o.close(g);
  };
  y(() => {
    let g = (w) => {
      t && t.current && w.key === "Escape" && (w.stopPropagation(), o.close(!0));
    };
    if (o.isOpen)
      return document.addEventListener("keydown", g, !0), () => {
        document.removeEventListener("keydown", g, !0);
      };
  }, [
    t,
    o
  ]);
  let b = () => {
    i !== "focus" && (oe() === "pointer" ? l.current = !0 : l.current = !1, f());
  }, v = () => {
    i !== "focus" && (n.current = !1, l.current = !1, s());
  }, x = () => {
    n.current = !1, l.current = !1, s(!0);
  }, C = () => {
    re() && (n.current = !0, f());
  }, d = () => {
    n.current = !1, l.current = !1, s(!0);
  }, { hoverProps: F } = I({
    isDisabled: r,
    onHoverStart: b,
    onHoverEnd: v
  }), { focusableProps: N } = X({
    isDisabled: r,
    onFocus: C,
    onBlur: d
  }, t);
  return {
    triggerProps: {
      "aria-describedby": o.isOpen ? a : void 0,
      ...T(N, F, {
        onPointerDown: x,
        onKeyDown: x
      }),
      tabIndex: void 0
    },
    tooltipProps: {
      id: a
    }
  };
}
const se = 1500, D = 500;
let $ = {}, $e = 0, P = !1, u = null, p = null;
function L(e = {}) {
  let { delay: o = se, closeDelay: t = D } = e, { isOpen: r, open: i, close: a } = Y(e), l = S(() => `${++$e}`, []), n = m(null), f = m(a), s = () => {
    $[l] = x;
  }, b = () => {
    for (let d in $) d !== l && ($[d](!0), delete $[d]);
  }, v = () => {
    n.current && clearTimeout(n.current), n.current = null, b(), s(), P = !0, i(), u && (clearTimeout(u), u = null), p && (clearTimeout(p), p = null);
  }, x = (d) => {
    d || t <= 0 ? (n.current && clearTimeout(n.current), n.current = null, f.current()) : n.current || (n.current = setTimeout(() => {
      n.current = null, f.current();
    }, t)), u && (clearTimeout(u), u = null), P && (p && clearTimeout(p), p = setTimeout(() => {
      delete $[l], p = null, P = !1;
    }, Math.max(D, t)));
  }, C = () => {
    b(), s(), !r && !u && !P ? u = setTimeout(() => {
      u = null, P = !0, v();
    }, o) : r || v();
  };
  return y(() => {
    f.current = a;
  }, [
    a
  ]), y(() => () => {
    n.current && clearTimeout(n.current), $[l] && delete $[l];
  }, [
    l
  ]), {
    isOpen: r,
    open: (d) => {
      !d && o > 0 && !n.current ? C() : v();
    },
    close: x
  };
}
const R = /* @__PURE__ */ M(null), A = /* @__PURE__ */ M(null);
function pe(e) {
  let o = L(e), t = m(null), { triggerProps: r, tooltipProps: i } = ue(e, o, t);
  return /* @__PURE__ */ c.createElement(K, {
    values: [
      [
        R,
        o
      ],
      [
        A,
        {
          ...i,
          triggerRef: t
        }
      ]
    ]
  }, /* @__PURE__ */ c.createElement(Z, {
    ...r,
    ref: t
  }, e.children));
}
const be = /* @__PURE__ */ U(function({ UNSTABLE_portalContainer: o, ...t }, r) {
  [t, r] = W(t, r, A);
  let i = E(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__ */ c.createElement(fe, {
    portalContainer: o
  }, /* @__PURE__ */ c.createElement(me, {
    ...t,
    tooltipRef: r,
    isExiting: n
  }));
});
function me(e) {
  let o = E(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 = G(e.tooltipRef, !!a) || e.isEntering || !1, f = V({
    ...e,
    defaultClassName: "react-aria-Tooltip",
    values: {
      placement: a,
      isEntering: n,
      isExiting: e.isExiting,
      state: o
    }
  });
  e = T(e, r);
  let { tooltipProps: s } = de(e, o), b = H(e, {
    global: !0
  });
  return /* @__PURE__ */ c.createElement("div", {
    ...T(b, f, s),
    ref: e.tooltipRef,
    style: {
      ...r.style,
      "--trigger-anchor-point": l ? `${l.x}px ${l.y}px` : void 0,
      ...f.style
    },
    "data-placement": a ?? void 0,
    "data-entering": n || void 0,
    "data-exiting": e.isExiting || void 0
  }, /* @__PURE__ */ c.createElement(J.Provider, {
    value: {
      ...i,
      placement: a,
      ref: t
    }
  }, f.children));
}
function k({
  // Match delays to current ui-kit tooltip
  delay: e = 300,
  closeDelay: o = 200,
  ...t
}) {
  return /* @__PURE__ */ h(pe, { delay: e, closeDelay: o, ...t });
}
k.displayName = "Tooltip.Root";
const { withContext: ve } = /* @__PURE__ */ ne({ key: "tooltip" }), xe = /* @__PURE__ */ ve("div");
function B({
  children: e,
  placement: o = "bottom",
  ref: t,
  ...r
}) {
  return /* @__PURE__ */ h(xe, { ref: t, asChild: !0, ...r, children: /* @__PURE__ */ h(be, { placement: o, ...r, children: e }) });
}
B.displayName = "Tooltip.Content";
const Me = {
  /**
   * # 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 {
  Me as T
};
//# sourceMappingURL=tooltip-D3QrrizN.es.js.map
