import { s as __toESM } from "./chunk-BNovOVIE.js";
import { f as createSlottable, g as cn, m as useComposedRefs } from "./button-Dj4BTre0.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { a as createPopperScope, i as Root2, n as Arrow, r as Content, s as Root, t as Anchor } from "./dist-D3ZI9nhS.js";
import { t as require_jsx_runtime } from "./jsx-runtime-COBk7ree.js";
import { $ as StyleNamespace, X as withFullScreenAsRoot, Z as withSmartCollisionBoundary, _t as Primitive, dt as Presence, ft as useControllableState, gt as createContextScope, it as Portal, mt as composeEventHandlers, st as DismissableLayer, ut as useId } from "./zod-BWkcDORu.js";
var import_react = /* @__PURE__ */ __toESM(require_react(), 1), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1), [createTooltipContext, createTooltipScope] = createContextScope("Tooltip", [createPopperScope]), usePopperScope = createPopperScope(), PROVIDER_NAME = "TooltipProvider", DEFAULT_DELAY_DURATION = 700, TOOLTIP_OPEN = "tooltip.open", [TooltipProviderContextProvider, useTooltipProviderContext] = createTooltipContext(PROVIDER_NAME), TooltipProvider$1 = (n) => {
  let { __scopeTooltip: j, delayDuration: M = DEFAULT_DELAY_DURATION, skipDelayDuration: N = 300, disableHoverableContent: P = false, children: F } = n, I = import_react.useRef(true), L = import_react.useRef(false), R = import_react.useRef(0);
  return import_react.useEffect(() => {
    let n2 = R.current;
    return () => window.clearTimeout(n2);
  }, []), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipProviderContextProvider, {
    scope: j,
    isOpenDelayedRef: I,
    delayDuration: M,
    onOpen: import_react.useCallback(() => {
      window.clearTimeout(R.current), I.current = false;
    }, []),
    onClose: import_react.useCallback(() => {
      window.clearTimeout(R.current), R.current = window.setTimeout(() => I.current = true, N);
    }, [N]),
    isPointerInTransitRef: L,
    onPointerInTransitChange: import_react.useCallback((n2) => {
      L.current = n2;
    }, []),
    disableHoverableContent: P,
    children: F
  });
};
TooltipProvider$1.displayName = PROVIDER_NAME;
var TOOLTIP_NAME = "Tooltip", [TooltipContextProvider, useTooltipContext] = createTooltipContext(TOOLTIP_NAME), Tooltip$1 = (n) => {
  let { __scopeTooltip: j, children: M, open: N, defaultOpen: P, onOpenChange: F, disableHoverableContent: I, delayDuration: R } = n, z = useTooltipProviderContext(TOOLTIP_NAME, n.__scopeTooltip), B = usePopperScope(j), [V, H] = import_react.useState(null), U = useId(), W = import_react.useRef(0), G = I ?? z.disableHoverableContent, K = R ?? z.delayDuration, q = import_react.useRef(false), [J, Y] = useControllableState({
    prop: N,
    defaultProp: P ?? false,
    onChange: (n2) => {
      n2 ? (z.onOpen(), document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN))) : z.onClose(), F == null ? void 0 : F(n2);
    },
    caller: TOOLTIP_NAME
  }), X = import_react.useMemo(() => J ? q.current ? "delayed-open" : "instant-open" : "closed", [J]), Z = import_react.useCallback(() => {
    window.clearTimeout(W.current), W.current = 0, q.current = false, Y(true);
  }, [Y]), Q = import_react.useCallback(() => {
    window.clearTimeout(W.current), W.current = 0, Y(false);
  }, [Y]), $ = import_react.useCallback(() => {
    window.clearTimeout(W.current), W.current = window.setTimeout(() => {
      q.current = true, Y(true), W.current = 0;
    }, K);
  }, [K, Y]);
  return import_react.useEffect(() => () => {
    W.current && (W.current = (window.clearTimeout(W.current), 0));
  }, []), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root2, {
    ...B,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContextProvider, {
      scope: j,
      contentId: U,
      open: J,
      stateAttribute: X,
      trigger: V,
      onTriggerChange: H,
      onTriggerEnter: import_react.useCallback(() => {
        z.isOpenDelayedRef.current ? $() : Z();
      }, [
        z.isOpenDelayedRef,
        $,
        Z
      ]),
      onTriggerLeave: import_react.useCallback(() => {
        G ? Q() : (window.clearTimeout(W.current), W.current = 0);
      }, [Q, G]),
      onOpen: Z,
      onClose: Q,
      disableHoverableContent: G,
      children: M
    })
  });
};
Tooltip$1.displayName = TOOLTIP_NAME;
var TRIGGER_NAME = "TooltipTrigger", TooltipTrigger$1 = import_react.forwardRef((n, j) => {
  let { __scopeTooltip: M, ...P } = n, F = useTooltipContext(TRIGGER_NAME, M), I = useTooltipProviderContext(TRIGGER_NAME, M), L = usePopperScope(M), R = useComposedRefs(j, import_react.useRef(null), F.onTriggerChange), z = import_react.useRef(false), B = import_react.useRef(false), H = import_react.useCallback(() => z.current = false, []);
  return import_react.useEffect(() => () => document.removeEventListener("pointerup", H), [H]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Anchor, {
    asChild: true,
    ...L,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.button, {
      "aria-describedby": F.open ? F.contentId : void 0,
      "data-state": F.stateAttribute,
      ...P,
      ref: R,
      onPointerMove: composeEventHandlers(n.onPointerMove, (n2) => {
        n2.pointerType !== "touch" && !B.current && !I.isPointerInTransitRef.current && (F.onTriggerEnter(), B.current = true);
      }),
      onPointerLeave: composeEventHandlers(n.onPointerLeave, () => {
        F.onTriggerLeave(), B.current = false;
      }),
      onPointerDown: composeEventHandlers(n.onPointerDown, () => {
        F.open && F.onClose(), z.current = true, document.addEventListener("pointerup", H, { once: true });
      }),
      onFocus: composeEventHandlers(n.onFocus, () => {
        z.current || F.onOpen();
      }),
      onBlur: composeEventHandlers(n.onBlur, F.onClose),
      onClick: composeEventHandlers(n.onClick, F.onClose)
    })
  });
});
TooltipTrigger$1.displayName = TRIGGER_NAME;
var PORTAL_NAME = "TooltipPortal", [PortalProvider, usePortalContext] = createTooltipContext(PORTAL_NAME, { forceMount: void 0 }), TooltipPortal$1 = (n) => {
  let { __scopeTooltip: j, forceMount: M, children: N, container: P } = n, F = useTooltipContext(PORTAL_NAME, j);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PortalProvider, {
    scope: j,
    forceMount: M,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Presence, {
      present: M || F.open,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal, {
        asChild: true,
        container: P,
        children: N
      })
    })
  });
};
TooltipPortal$1.displayName = PORTAL_NAME;
var CONTENT_NAME = "TooltipContent", TooltipContent$1 = import_react.forwardRef((n, j) => {
  let M = usePortalContext(CONTENT_NAME, n.__scopeTooltip), { forceMount: N = M.forceMount, side: P = "top", ...F } = n, I = useTooltipContext(CONTENT_NAME, n.__scopeTooltip);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Presence, {
    present: N || I.open,
    children: I.disableHoverableContent ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContentImpl, {
      side: P,
      ...F,
      ref: j
    }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContentHoverable, {
      side: P,
      ...F,
      ref: j
    })
  });
}), TooltipContentHoverable = import_react.forwardRef((n, j) => {
  let M = useTooltipContext(CONTENT_NAME, n.__scopeTooltip), P = useTooltipProviderContext(CONTENT_NAME, n.__scopeTooltip), F = import_react.useRef(null), I = useComposedRefs(j, F), [L, R] = import_react.useState(null), { trigger: z, onClose: B } = M, V = F.current, { onPointerInTransitChange: H } = P, U = import_react.useCallback(() => {
    R(null), H(false);
  }, [H]), W = import_react.useCallback((n2, j2) => {
    let M2 = n2.currentTarget, N = {
      x: n2.clientX,
      y: n2.clientY
    }, P2 = getPaddedExitPoints(N, getExitSideFromRect(N, M2.getBoundingClientRect())), F2 = getPointsFromRect(j2.getBoundingClientRect());
    R(getHull([...P2, ...F2])), H(true);
  }, [H]);
  return import_react.useEffect(() => () => U(), [U]), import_react.useEffect(() => {
    if (z && V) {
      let n2 = (n3) => W(n3, V), j2 = (n3) => W(n3, z);
      return z.addEventListener("pointerleave", n2), V.addEventListener("pointerleave", j2), () => {
        z.removeEventListener("pointerleave", n2), V.removeEventListener("pointerleave", j2);
      };
    }
  }, [
    z,
    V,
    W,
    U
  ]), import_react.useEffect(() => {
    if (L) {
      let n2 = (n3) => {
        let j2 = n3.target, M2 = {
          x: n3.clientX,
          y: n3.clientY
        }, N = (z == null ? void 0 : z.contains(j2)) || (V == null ? void 0 : V.contains(j2)), P2 = !isPointInPolygon(M2, L);
        N ? U() : P2 && (U(), B());
      };
      return document.addEventListener("pointermove", n2), () => document.removeEventListener("pointermove", n2);
    }
  }, [
    z,
    V,
    L,
    B,
    U
  ]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContentImpl, {
    ...n,
    ref: I
  });
}), [VisuallyHiddenContentContextProvider, useVisuallyHiddenContentContext] = createTooltipContext(TOOLTIP_NAME, { isInside: false }), Slottable = createSlottable("TooltipContent"), TooltipContentImpl = import_react.forwardRef((n, j) => {
  let { __scopeTooltip: M, children: N, "aria-label": P, onEscapeKeyDown: F, onPointerDownOutside: I, ...L } = n, R = useTooltipContext(CONTENT_NAME, M), V = usePopperScope(M), { onClose: H } = R;
  return import_react.useEffect(() => (document.addEventListener(TOOLTIP_OPEN, H), () => document.removeEventListener(TOOLTIP_OPEN, H)), [H]), import_react.useEffect(() => {
    if (R.trigger) {
      let n2 = (n3) => {
        var _a;
        ((_a = n3.target) == null ? void 0 : _a.contains(R.trigger)) && H();
      };
      return window.addEventListener("scroll", n2, { capture: true }), () => window.removeEventListener("scroll", n2, { capture: true });
    }
  }, [R.trigger, H]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DismissableLayer, {
    asChild: true,
    disableOutsidePointerEvents: false,
    onEscapeKeyDown: F,
    onPointerDownOutside: I,
    onFocusOutside: (n2) => n2.preventDefault(),
    onDismiss: H,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Content, {
      "data-state": R.stateAttribute,
      ...V,
      ...L,
      ref: j,
      style: {
        ...L.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__ */ (0, import_jsx_runtime.jsx)(Slottable, { children: N }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VisuallyHiddenContentContextProvider, {
        scope: M,
        isInside: true,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root, {
          id: R.contentId,
          role: "tooltip",
          children: P || N
        })
      })]
    })
  });
});
TooltipContent$1.displayName = CONTENT_NAME;
var ARROW_NAME = "TooltipArrow", TooltipArrow = import_react.forwardRef((n, j) => {
  let { __scopeTooltip: M, ...N } = n, P = usePopperScope(M);
  return useVisuallyHiddenContentContext(ARROW_NAME, M).isInside ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Arrow, {
    ...P,
    ...N,
    ref: j
  });
});
TooltipArrow.displayName = ARROW_NAME;
function getExitSideFromRect(n, j) {
  let M = Math.abs(j.top - n.y), N = Math.abs(j.bottom - n.y), P = Math.abs(j.right - n.x), F = Math.abs(j.left - n.x);
  switch (Math.min(M, N, P, F)) {
    case F:
      return "left";
    case P:
      return "right";
    case M:
      return "top";
    case N:
      return "bottom";
    default:
      throw Error("unreachable");
  }
}
function getPaddedExitPoints(n, j, M = 5) {
  let N = [];
  switch (j) {
    case "top":
      N.push({
        x: n.x - M,
        y: n.y + M
      }, {
        x: n.x + M,
        y: n.y + M
      });
      break;
    case "bottom":
      N.push({
        x: n.x - M,
        y: n.y - M
      }, {
        x: n.x + M,
        y: n.y - M
      });
      break;
    case "left":
      N.push({
        x: n.x + M,
        y: n.y - M
      }, {
        x: n.x + M,
        y: n.y + M
      });
      break;
    case "right":
      N.push({
        x: n.x - M,
        y: n.y - M
      }, {
        x: n.x - M,
        y: n.y + M
      });
      break;
  }
  return N;
}
function getPointsFromRect(n) {
  let { top: j, right: M, bottom: N, left: P } = n;
  return [
    {
      x: P,
      y: j
    },
    {
      x: M,
      y: j
    },
    {
      x: M,
      y: N
    },
    {
      x: P,
      y: N
    }
  ];
}
function isPointInPolygon(n, j) {
  let { x: M, y: N } = n, P = false;
  for (let n2 = 0, F = j.length - 1; n2 < j.length; F = n2++) {
    let I = j[n2], L = j[F], R = I.x, z = I.y, B = L.x, V = L.y;
    z > N != V > N && M < (B - R) * (N - z) / (V - z) + R && (P = !P);
  }
  return P;
}
function getHull(n) {
  let j = n.slice();
  return j.sort((n2, j2) => n2.x < j2.x ? -1 : n2.x > j2.x ? 1 : n2.y < j2.y ? -1 : n2.y > j2.y ? 1 : 0), getHullPresorted(j);
}
function getHullPresorted(n) {
  if (n.length <= 1) return n.slice();
  let j = [];
  for (let M2 = 0; M2 < n.length; M2++) {
    let N = n[M2];
    for (; j.length >= 2; ) {
      let n2 = j[j.length - 1], M3 = j[j.length - 2];
      if ((n2.x - M3.x) * (N.y - M3.y) >= (n2.y - M3.y) * (N.x - M3.x)) j.pop();
      else break;
    }
    j.push(N);
  }
  j.pop();
  let M = [];
  for (let j2 = n.length - 1; j2 >= 0; j2--) {
    let N = n[j2];
    for (; M.length >= 2; ) {
      let n2 = M[M.length - 1], j3 = M[M.length - 2];
      if ((n2.x - j3.x) * (N.y - j3.y) >= (n2.y - j3.y) * (N.x - j3.x)) M.pop();
      else break;
    }
    M.push(N);
  }
  return M.pop(), j.length === 1 && M.length === 1 && j[0].x === M[0].x && j[0].y === M[0].y ? j : j.concat(M);
}
var Provider = TooltipProvider$1, Root3 = Tooltip$1, Trigger = TooltipTrigger$1, Portal$1 = TooltipPortal$1, Content2 = TooltipContent$1, import_compiler_runtime = require_compiler_runtime(), TooltipProvider = (n) => {
  let j = (0, import_compiler_runtime.c)(6), M, N;
  j[0] === n ? (M = j[1], N = j[2]) : ({ delayDuration: N, ...M } = n, j[0] = n, j[1] = M, j[2] = N);
  let P = N === void 0 ? 400 : N, F;
  return j[3] !== P || j[4] !== M ? (F = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, {
    delayDuration: P,
    ...M
  }), j[3] = P, j[4] = M, j[5] = F) : F = j[5], F;
}, TooltipPortal = withFullScreenAsRoot(Portal$1), TooltipRoot = Root3, InternalTooltipContent = withSmartCollisionBoundary(Content2), TooltipTrigger = Trigger, TooltipContent = import_react.forwardRef((n, j) => {
  let N = (0, import_compiler_runtime.c)(11), P, F, I;
  N[0] === n ? (P = N[1], F = N[2], I = N[3]) : ({ className: P, sideOffset: I, ...F } = n, N[0] = n, N[1] = P, N[2] = F, N[3] = I);
  let L = I === void 0 ? 4 : I, R;
  N[4] === P ? R = N[5] : (R = cn("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-xs data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1", P), N[4] = P, N[5] = R);
  let z;
  return N[6] !== F || N[7] !== j || N[8] !== L || N[9] !== R ? (z = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyleNamespace, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InternalTooltipContent, {
    ref: j,
    sideOffset: L,
    className: R,
    ...F
  }) }), N[6] = F, N[7] = j, N[8] = L, N[9] = R, N[10] = z) : z = N[10], z;
});
TooltipContent.displayName = Content2.displayName;
var Tooltip = (n) => {
  let j = (0, import_compiler_runtime.c)(22), M, N, P, F, I, L, R, z;
  j[0] === n ? (M = j[1], N = j[2], P = j[3], F = j[4], I = j[5], L = j[6], R = j[7], z = j[8]) : ({ content: P, children: N, usePortal: L, asChild: R, tabIndex: z, side: I, align: M, ...F } = n, j[0] = n, j[1] = M, j[2] = N, j[3] = P, j[4] = F, j[5] = I, j[6] = L, j[7] = R, j[8] = z);
  let B = L === void 0 ? true : L, V = R === void 0 ? true : R;
  if (P == null || P === "") return N;
  let H;
  j[9] !== V || j[10] !== N || j[11] !== z ? (H = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipTrigger, {
    asChild: V,
    tabIndex: z,
    children: N
  }), j[9] = V, j[10] = N, j[11] = z, j[12] = H) : H = j[12];
  let U;
  j[13] !== M || j[14] !== P || j[15] !== I || j[16] !== B ? (U = B ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, {
    side: I,
    align: M,
    children: P
  }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, {
    side: I,
    align: M,
    children: P
  }), j[13] = M, j[14] = P, j[15] = I, j[16] = B, j[17] = U) : U = j[17];
  let W;
  return j[18] !== F || j[19] !== H || j[20] !== U ? (W = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TooltipRoot, {
    disableHoverableContent: true,
    ...F,
    children: [H, U]
  }), j[18] = F, j[19] = H, j[20] = U, j[21] = W) : W = j[21], W;
};
export {
  TooltipRoot as a,
  TooltipProvider as i,
  TooltipContent as n,
  TooltipTrigger as o,
  TooltipPortal as r,
  Tooltip as t
};
