"use client";
import * as s from "react";
import { composeEventHandlers as g } from "../../../../../@radix-ui_primitive@1.1.1/node_modules/@radix-ui/primitive/dist/index.js";
import { useComposedRefs as N } from "../../../../../@radix-ui_react-compose-refs@1.1.1_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createContextScope as W } from "../../../../../@radix-ui_react-context@1.1.1_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-context/dist/index.js";
import { DismissableLayer as $ } from "../../../../../@radix-ui_react-dismissable-layer@1.1.5_@types_react-dom@19.0.4_@types_react@19.0.10__@types__qhqqxzzcg7ybcfyqstucqlmfcm/node_modules/@radix-ui/react-dismissable-layer/dist/index.js";
import { useId as z } from "../../../../../@radix-ui_react-id@1.1.0_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-id/dist/index.js";
import { createPopperScope as S, Anchor as J, Arrow as Q, Content as Z, Root as ee } from "../../../../../@radix-ui_react-popper@1.2.2_@types_react-dom@19.0.4_@types_react@19.0.10__@types_react@19.0._uy7edyxv2sgvt4p3geolwujqzy/node_modules/@radix-ui/react-popper/dist/index.js";
import { Portal as te } from "../../../../../@radix-ui_react-portal@1.1.4_@types_react-dom@19.0.4_@types_react@19.0.10__@types_react@19.0._f6vgysj3caw5ywaw57ltmdlht4/node_modules/@radix-ui/react-portal/dist/index.js";
import { Presence as G } from "../../../../../@radix-ui_react-presence@1.1.2_@types_react-dom@19.0.4_@types_react@19.0.10__@types_react@19._23avbptz4koybcdlb5o3h467kq/node_modules/@radix-ui/react-presence/dist/index.js";
import { Primitive as oe } from "../../../../../@radix-ui_react-primitive@2.0.2_@types_react-dom@19.0.4_@types_react@19.0.10__@types_react@19_i7clg2yux7aeir464mbcqjzvuu/node_modules/@radix-ui/react-primitive/dist/index.js";
import { Slottable as re } from "../../../../../@radix-ui_react-slot@1.1.2_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-slot/dist/index.js";
import { useControllableState as ne } from "../../../../../@radix-ui_react-use-controllable-state@1.1.0_@types_react@19.0.10_react@19.0.0/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { Root as se } from "../../../../../@radix-ui_react-visually-hidden@1.1.2_@types_react-dom@19.0.4_@types_react@19.0.10__@types_re_4ein3fe2755aojd6mkuqoudsgi/node_modules/@radix-ui/react-visually-hidden/dist/index.js";
import { jsx as d, jsxs as ae } from "react/jsx-runtime";
var [_, Me] = W("Tooltip", [
  S
]), D = S(), F = "TooltipProvider", ie = 700, A = "tooltip.open", [le, k] = _(F), j = (t) => {
  const {
    __scopeTooltip: o,
    delayDuration: e = ie,
    skipDelayDuration: r = 300,
    disableHoverableContent: n = !1,
    children: i
  } = t, [c, v] = s.useState(!0), a = s.useRef(!1), p = s.useRef(0);
  return s.useEffect(() => {
    const l = p.current;
    return () => window.clearTimeout(l);
  }, []), /* @__PURE__ */ d(
    le,
    {
      scope: o,
      isOpenDelayed: c,
      delayDuration: e,
      onOpen: s.useCallback(() => {
        window.clearTimeout(p.current), v(!1);
      }, []),
      onClose: s.useCallback(() => {
        window.clearTimeout(p.current), p.current = window.setTimeout(
          () => v(!0),
          r
        );
      }, [r]),
      isPointerInTransitRef: a,
      onPointerInTransitChange: s.useCallback((l) => {
        a.current = l;
      }, []),
      disableHoverableContent: n,
      children: i
    }
  );
};
j.displayName = F;
var O = "Tooltip", [ce, R] = _(O), B = (t) => {
  const {
    __scopeTooltip: o,
    children: e,
    open: r,
    defaultOpen: n = !1,
    onOpenChange: i,
    disableHoverableContent: c,
    delayDuration: v
  } = t, a = k(O, t.__scopeTooltip), p = D(o), [l, f] = s.useState(null), m = z(), u = s.useRef(0), h = c ?? a.disableHoverableContent, y = v ?? a.delayDuration, T = s.useRef(!1), [x = !1, C] = ne({
    prop: r,
    defaultProp: n,
    onChange: (H) => {
      H ? (a.onOpen(), document.dispatchEvent(new CustomEvent(A))) : a.onClose(), i == null || i(H);
    }
  }), w = s.useMemo(() => x ? T.current ? "delayed-open" : "instant-open" : "closed", [x]), P = s.useCallback(() => {
    window.clearTimeout(u.current), u.current = 0, T.current = !1, C(!0);
  }, [C]), E = s.useCallback(() => {
    window.clearTimeout(u.current), u.current = 0, C(!1);
  }, [C]), M = s.useCallback(() => {
    window.clearTimeout(u.current), u.current = window.setTimeout(() => {
      T.current = !0, C(!0), u.current = 0;
    }, y);
  }, [y, C]);
  return s.useEffect(() => () => {
    u.current && (window.clearTimeout(u.current), u.current = 0);
  }, []), /* @__PURE__ */ d(ee, { ...p, children: /* @__PURE__ */ d(
    ce,
    {
      scope: o,
      contentId: m,
      open: x,
      stateAttribute: w,
      trigger: l,
      onTriggerChange: f,
      onTriggerEnter: s.useCallback(() => {
        a.isOpenDelayed ? M() : P();
      }, [a.isOpenDelayed, M, P]),
      onTriggerLeave: s.useCallback(() => {
        h ? E() : (window.clearTimeout(u.current), u.current = 0);
      }, [E, h]),
      onOpen: P,
      onClose: E,
      disableHoverableContent: h,
      children: e
    }
  ) });
};
B.displayName = O;
var L = "TooltipTrigger", U = s.forwardRef(
  (t, o) => {
    const { __scopeTooltip: e, ...r } = t, n = R(L, e), i = k(L, e), c = D(e), v = s.useRef(null), a = N(o, v, n.onTriggerChange), p = s.useRef(!1), l = s.useRef(!1), f = s.useCallback(() => p.current = !1, []);
    return s.useEffect(() => () => document.removeEventListener("pointerup", f), [f]), /* @__PURE__ */ d(J, { asChild: !0, ...c, children: /* @__PURE__ */ d(
      oe.button,
      {
        "aria-describedby": n.open ? n.contentId : void 0,
        "data-state": n.stateAttribute,
        ...r,
        ref: a,
        onPointerMove: g(t.onPointerMove, (m) => {
          m.pointerType !== "touch" && !l.current && !i.isPointerInTransitRef.current && (n.onTriggerEnter(), l.current = !0);
        }),
        onPointerLeave: g(t.onPointerLeave, () => {
          n.onTriggerLeave(), l.current = !1;
        }),
        onPointerDown: g(t.onPointerDown, () => {
          p.current = !0, document.addEventListener("pointerup", f, { once: !0 });
        }),
        onFocus: g(t.onFocus, () => {
          p.current || n.onOpen();
        }),
        onBlur: g(t.onBlur, n.onClose),
        onClick: g(t.onClick, n.onClose)
      }
    ) });
  }
);
U.displayName = L;
var I = "TooltipPortal", [ue, pe] = _(I, {
  forceMount: void 0
}), V = (t) => {
  const { __scopeTooltip: o, forceMount: e, children: r, container: n } = t, i = R(I, o);
  return /* @__PURE__ */ d(ue, { scope: o, forceMount: e, children: /* @__PURE__ */ d(G, { present: e || i.open, children: /* @__PURE__ */ d(te, { asChild: !0, container: n, children: r }) }) });
};
V.displayName = I;
var b = "TooltipContent", Y = s.forwardRef(
  (t, o) => {
    const e = pe(b, t.__scopeTooltip), { forceMount: r = e.forceMount, side: n = "top", ...i } = t, c = R(b, t.__scopeTooltip);
    return /* @__PURE__ */ d(G, { present: r || c.open, children: c.disableHoverableContent ? /* @__PURE__ */ d(q, { side: n, ...i, ref: o }) : /* @__PURE__ */ d(de, { side: n, ...i, ref: o }) });
  }
), de = s.forwardRef((t, o) => {
  const e = R(b, t.__scopeTooltip), r = k(b, t.__scopeTooltip), n = s.useRef(null), i = N(o, n), [c, v] = s.useState(null), { trigger: a, onClose: p } = e, l = n.current, { onPointerInTransitChange: f } = r, m = s.useCallback(() => {
    v(null), f(!1);
  }, [f]), u = s.useCallback(
    (h, y) => {
      const T = h.currentTarget, x = { x: h.clientX, y: h.clientY }, C = he(x, T.getBoundingClientRect()), w = me(x, C), P = Te(y.getBoundingClientRect()), E = Ce([...w, ...P]);
      v(E), f(!0);
    },
    [f]
  );
  return s.useEffect(() => () => m(), [m]), s.useEffect(() => {
    if (a && l) {
      const h = (T) => u(T, l), y = (T) => u(T, a);
      return a.addEventListener("pointerleave", h), l.addEventListener("pointerleave", y), () => {
        a.removeEventListener("pointerleave", h), l.removeEventListener("pointerleave", y);
      };
    }
  }, [a, l, u, m]), s.useEffect(() => {
    if (c) {
      const h = (y) => {
        const T = y.target, x = { x: y.clientX, y: y.clientY }, C = (a == null ? void 0 : a.contains(T)) || (l == null ? void 0 : l.contains(T)), w = !ye(x, c);
        C ? m() : w && (m(), p());
      };
      return document.addEventListener("pointermove", h), () => document.removeEventListener("pointermove", h);
    }
  }, [a, l, c, p, m]), /* @__PURE__ */ d(q, { ...t, ref: i });
}), [fe, ve] = _(O, { isInside: !1 }), q = s.forwardRef(
  (t, o) => {
    const {
      __scopeTooltip: e,
      children: r,
      "aria-label": n,
      onEscapeKeyDown: i,
      onPointerDownOutside: c,
      ...v
    } = t, a = R(b, e), p = D(e), { onClose: l } = a;
    return s.useEffect(() => (document.addEventListener(A, l), () => document.removeEventListener(A, l)), [l]), s.useEffect(() => {
      if (a.trigger) {
        const f = (m) => {
          const u = m.target;
          u != null && u.contains(a.trigger) && l();
        };
        return window.addEventListener("scroll", f, { capture: !0 }), () => window.removeEventListener("scroll", f, { capture: !0 });
      }
    }, [a.trigger, l]), /* @__PURE__ */ d(
      $,
      {
        asChild: !0,
        disableOutsidePointerEvents: !1,
        onEscapeKeyDown: i,
        onPointerDownOutside: c,
        onFocusOutside: (f) => f.preventDefault(),
        onDismiss: l,
        children: /* @__PURE__ */ ae(
          Z,
          {
            "data-state": a.stateAttribute,
            ...p,
            ...v,
            ref: o,
            style: {
              ...v.style,
              "--radix-tooltip-content-transform-origin": "var(--radix-popper-transform-origin)",
              "--radix-tooltip-content-available-width": "var(--radix-popper-available-width)",
              "--radix-tooltip-content-available-height": "var(--radix-popper-available-height)",
              "--radix-tooltip-trigger-width": "var(--radix-popper-anchor-width)",
              "--radix-tooltip-trigger-height": "var(--radix-popper-anchor-height)"
            },
            children: [
              /* @__PURE__ */ d(re, { children: r }),
              /* @__PURE__ */ d(fe, { scope: e, isInside: !0, children: /* @__PURE__ */ d(se, { id: a.contentId, role: "tooltip", children: n || r }) })
            ]
          }
        )
      }
    );
  }
);
Y.displayName = b;
var X = "TooltipArrow", K = s.forwardRef(
  (t, o) => {
    const { __scopeTooltip: e, ...r } = t, n = D(e);
    return ve(
      X,
      e
    ).isInside ? null : /* @__PURE__ */ d(Q, { ...n, ...r, ref: o });
  }
);
K.displayName = X;
function he(t, o) {
  const e = Math.abs(o.top - t.y), r = Math.abs(o.bottom - t.y), n = Math.abs(o.right - t.x), i = Math.abs(o.left - t.x);
  switch (Math.min(e, r, n, i)) {
    case i:
      return "left";
    case n:
      return "right";
    case e:
      return "top";
    case r:
      return "bottom";
    default:
      throw new Error("unreachable");
  }
}
function me(t, o, e = 5) {
  const r = [];
  switch (o) {
    case "top":
      r.push(
        { x: t.x - e, y: t.y + e },
        { x: t.x + e, y: t.y + e }
      );
      break;
    case "bottom":
      r.push(
        { x: t.x - e, y: t.y - e },
        { x: t.x + e, y: t.y - e }
      );
      break;
    case "left":
      r.push(
        { x: t.x + e, y: t.y - e },
        { x: t.x + e, y: t.y + e }
      );
      break;
    case "right":
      r.push(
        { x: t.x - e, y: t.y - e },
        { x: t.x - e, y: t.y + e }
      );
      break;
  }
  return r;
}
function Te(t) {
  const { top: o, right: e, bottom: r, left: n } = t;
  return [
    { x: n, y: o },
    { x: e, y: o },
    { x: e, y: r },
    { x: n, y: r }
  ];
}
function ye(t, o) {
  const { x: e, y: r } = t;
  let n = !1;
  for (let i = 0, c = o.length - 1; i < o.length; c = i++) {
    const v = o[i].x, a = o[i].y, p = o[c].x, l = o[c].y;
    a > r != l > r && e < (p - v) * (r - a) / (l - a) + v && (n = !n);
  }
  return n;
}
function Ce(t) {
  const o = t.slice();
  return o.sort((e, r) => e.x < r.x ? -1 : e.x > r.x ? 1 : e.y < r.y ? -1 : e.y > r.y ? 1 : 0), xe(o);
}
function xe(t) {
  if (t.length <= 1) return t.slice();
  const o = [];
  for (let r = 0; r < t.length; r++) {
    const n = t[r];
    for (; o.length >= 2; ) {
      const i = o[o.length - 1], c = o[o.length - 2];
      if ((i.x - c.x) * (n.y - c.y) >= (i.y - c.y) * (n.x - c.x)) o.pop();
      else break;
    }
    o.push(n);
  }
  o.pop();
  const e = [];
  for (let r = t.length - 1; r >= 0; r--) {
    const n = t[r];
    for (; e.length >= 2; ) {
      const i = e[e.length - 1], c = e[e.length - 2];
      if ((i.x - c.x) * (n.y - c.y) >= (i.y - c.y) * (n.x - c.x)) e.pop();
      else break;
    }
    e.push(n);
  }
  return e.pop(), o.length === 1 && e.length === 1 && o[0].x === e[0].x && o[0].y === e[0].y ? o : o.concat(e);
}
var He = j, Ne = B, Se = U, Ge = V, Fe = Y, je = K;
export {
  je as Arrow,
  Fe as Content,
  Ge as Portal,
  He as Provider,
  Ne as Root,
  B as Tooltip,
  K as TooltipArrow,
  Y as TooltipContent,
  V as TooltipPortal,
  j as TooltipProvider,
  U as TooltipTrigger,
  Se as Trigger,
  Me as createTooltipScope
};
//# sourceMappingURL=index.js.map
