import { s as __toESM } from "./chunk-BNovOVIE.js";
import { t as require_react } from "./react-Bs6Z0kvn.js";
import { t as require_compiler_runtime } from "./compiler-runtime-B_OLMU9S.js";
import { a as createPopperScope, i as Root2, n as Arrow, r as Content, s as Root, t as Anchor } from "./dist-D_UjpfOY.js";
import { f as createSlottable, m as useComposedRefs, y as cn } from "./button-DNlNlZY_.js";
import { t as require_jsx_runtime } from "./jsx-runtime-9hcJiI23.js";
import { $ as StyleNamespace, X as withFullScreenAsRoot, Z as withSmartCollisionBoundary, ct as useId, ft as composeEventHandlers, ht as Primitive, it as Portal, lt as Presence, mt as createContextScope, ot as DismissableLayer, ut as useControllableState } from "./zod-C6UGQ3fz.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 = (t) => {
  let { __scopeTooltip: j, delayDuration: M = DEFAULT_DELAY_DURATION, skipDelayDuration: N = 300, disableHoverableContent: P = false, children: F } = t, I = import_react.useRef(true), L = import_react.useRef(false), R = import_react.useRef(0);
  return import_react.useEffect(() => {
    let t2 = R.current;
    return () => window.clearTimeout(t2);
  }, []), /* @__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((t2) => {
      L.current = t2;
    }, []),
    disableHoverableContent: P,
    children: F
  });
};
TooltipProvider$1.displayName = PROVIDER_NAME;
var TOOLTIP_NAME = "Tooltip", [TooltipContextProvider, useTooltipContext] = createTooltipContext(TOOLTIP_NAME), Tooltip$1 = (t) => {
  let { __scopeTooltip: j, children: M, open: N, defaultOpen: F, onOpenChange: I, disableHoverableContent: L, delayDuration: R } = t, z = useTooltipProviderContext(TOOLTIP_NAME, t.__scopeTooltip), B = usePopperScope(j), [V, H] = import_react.useState(null), U = useId(), W = import_react.useRef(0), G = L ?? z.disableHoverableContent, K = R ?? z.delayDuration, q = import_react.useRef(false), [J, Y] = useControllableState({
    prop: N,
    defaultProp: F ?? false,
    onChange: (t2) => {
      t2 ? (z.onOpen(), document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN))) : z.onClose(), I == null ? void 0 : I(t2);
    },
    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((t, j) => {
  let { __scopeTooltip: M, ...N } = t, P = useTooltipContext(TRIGGER_NAME, M), F = useTooltipProviderContext(TRIGGER_NAME, M), I = usePopperScope(M), L = useComposedRefs(j, import_react.useRef(null), P.onTriggerChange), z = import_react.useRef(false), V = 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,
    ...I,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Primitive.button, {
      "aria-describedby": P.open ? P.contentId : void 0,
      "data-state": P.stateAttribute,
      ...N,
      ref: L,
      onPointerMove: composeEventHandlers(t.onPointerMove, (t2) => {
        t2.pointerType !== "touch" && !V.current && !F.isPointerInTransitRef.current && (P.onTriggerEnter(), V.current = true);
      }),
      onPointerLeave: composeEventHandlers(t.onPointerLeave, () => {
        P.onTriggerLeave(), V.current = false;
      }),
      onPointerDown: composeEventHandlers(t.onPointerDown, () => {
        P.open && P.onClose(), z.current = true, document.addEventListener("pointerup", H, { once: true });
      }),
      onFocus: composeEventHandlers(t.onFocus, () => {
        z.current || P.onOpen();
      }),
      onBlur: composeEventHandlers(t.onBlur, P.onClose),
      onClick: composeEventHandlers(t.onClick, P.onClose)
    })
  });
});
TooltipTrigger$1.displayName = TRIGGER_NAME;
var PORTAL_NAME = "TooltipPortal", [PortalProvider, usePortalContext] = createTooltipContext(PORTAL_NAME, { forceMount: void 0 }), TooltipPortal$1 = (t) => {
  let { __scopeTooltip: j, forceMount: M, children: N, container: P } = t, 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((t, j) => {
  let M = usePortalContext(CONTENT_NAME, t.__scopeTooltip), { forceMount: N = M.forceMount, side: P = "top", ...F } = t, I = useTooltipContext(CONTENT_NAME, t.__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((t, j) => {
  let M = useTooltipContext(CONTENT_NAME, t.__scopeTooltip), N = useTooltipProviderContext(CONTENT_NAME, t.__scopeTooltip), P = import_react.useRef(null), F = useComposedRefs(j, P), [I, L] = import_react.useState(null), { trigger: R, onClose: z } = M, V = P.current, { onPointerInTransitChange: H } = N, U = import_react.useCallback(() => {
    L(null), H(false);
  }, [H]), W = import_react.useCallback((t2, j2) => {
    let M2 = t2.currentTarget, N2 = {
      x: t2.clientX,
      y: t2.clientY
    }, P2 = getPaddedExitPoints(N2, getExitSideFromRect(N2, M2.getBoundingClientRect())), F2 = getPointsFromRect(j2.getBoundingClientRect());
    L(getHull([...P2, ...F2])), H(true);
  }, [H]);
  return import_react.useEffect(() => () => U(), [U]), import_react.useEffect(() => {
    if (R && V) {
      let t2 = (t3) => W(t3, V), j2 = (t3) => W(t3, R);
      return R.addEventListener("pointerleave", t2), V.addEventListener("pointerleave", j2), () => {
        R.removeEventListener("pointerleave", t2), V.removeEventListener("pointerleave", j2);
      };
    }
  }, [
    R,
    V,
    W,
    U
  ]), import_react.useEffect(() => {
    if (I) {
      let t2 = (t3) => {
        let j2 = t3.target, M2 = {
          x: t3.clientX,
          y: t3.clientY
        }, N2 = (R == null ? void 0 : R.contains(j2)) || (V == null ? void 0 : V.contains(j2)), P2 = !isPointInPolygon(M2, I);
        N2 ? U() : P2 && (U(), z());
      };
      return document.addEventListener("pointermove", t2), () => document.removeEventListener("pointermove", t2);
    }
  }, [
    R,
    V,
    I,
    z,
    U
  ]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContentImpl, {
    ...t,
    ref: F
  });
}), [VisuallyHiddenContentContextProvider, useVisuallyHiddenContentContext] = createTooltipContext(TOOLTIP_NAME, { isInside: false }), Slottable = createSlottable("TooltipContent"), TooltipContentImpl = import_react.forwardRef((t, j) => {
  let { __scopeTooltip: M, children: N, "aria-label": P, onEscapeKeyDown: F, onPointerDownOutside: R, ...z } = t, B = useTooltipContext(CONTENT_NAME, M), V = usePopperScope(M), { onClose: H } = B;
  return import_react.useEffect(() => (document.addEventListener(TOOLTIP_OPEN, H), () => document.removeEventListener(TOOLTIP_OPEN, H)), [H]), import_react.useEffect(() => {
    if (B.trigger) {
      let t2 = (t3) => {
        var _a;
        ((_a = t3.target) == null ? void 0 : _a.contains(B.trigger)) && H();
      };
      return window.addEventListener("scroll", t2, { capture: true }), () => window.removeEventListener("scroll", t2, { capture: true });
    }
  }, [B.trigger, H]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DismissableLayer, {
    asChild: true,
    disableOutsidePointerEvents: false,
    onEscapeKeyDown: F,
    onPointerDownOutside: R,
    onFocusOutside: (t2) => t2.preventDefault(),
    onDismiss: H,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Content, {
      "data-state": B.stateAttribute,
      ...V,
      ...z,
      ref: j,
      style: {
        ...z.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: B.contentId,
          role: "tooltip",
          children: P || N
        })
      })]
    })
  });
});
TooltipContent$1.displayName = CONTENT_NAME;
var ARROW_NAME = "TooltipArrow", TooltipArrow = import_react.forwardRef((t, j) => {
  let { __scopeTooltip: M, ...N } = t, 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(t, j) {
  let M = Math.abs(j.top - t.y), N = Math.abs(j.bottom - t.y), P = Math.abs(j.right - t.x), F = Math.abs(j.left - t.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(t, j, M = 5) {
  let N = [];
  switch (j) {
    case "top":
      N.push({
        x: t.x - M,
        y: t.y + M
      }, {
        x: t.x + M,
        y: t.y + M
      });
      break;
    case "bottom":
      N.push({
        x: t.x - M,
        y: t.y - M
      }, {
        x: t.x + M,
        y: t.y - M
      });
      break;
    case "left":
      N.push({
        x: t.x + M,
        y: t.y - M
      }, {
        x: t.x + M,
        y: t.y + M
      });
      break;
    case "right":
      N.push({
        x: t.x - M,
        y: t.y - M
      }, {
        x: t.x - M,
        y: t.y + M
      });
      break;
  }
  return N;
}
function getPointsFromRect(t) {
  let { top: j, right: M, bottom: N, left: P } = t;
  return [
    {
      x: P,
      y: j
    },
    {
      x: M,
      y: j
    },
    {
      x: M,
      y: N
    },
    {
      x: P,
      y: N
    }
  ];
}
function isPointInPolygon(t, j) {
  let { x: M, y: N } = t, P = false;
  for (let t2 = 0, F = j.length - 1; t2 < j.length; F = t2++) {
    let I = j[t2], 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(t) {
  let j = t.slice();
  return j.sort((t2, j2) => t2.x < j2.x ? -1 : t2.x > j2.x ? 1 : t2.y < j2.y ? -1 : t2.y > j2.y ? 1 : 0), getHullPresorted(j);
}
function getHullPresorted(t) {
  if (t.length <= 1) return t.slice();
  let j = [];
  for (let M2 = 0; M2 < t.length; M2++) {
    let N = t[M2];
    for (; j.length >= 2; ) {
      let t2 = j[j.length - 1], M3 = j[j.length - 2];
      if ((t2.x - M3.x) * (N.y - M3.y) >= (t2.y - M3.y) * (N.x - M3.x)) j.pop();
      else break;
    }
    j.push(N);
  }
  j.pop();
  let M = [];
  for (let j2 = t.length - 1; j2 >= 0; j2--) {
    let N = t[j2];
    for (; M.length >= 2; ) {
      let t2 = M[M.length - 1], j3 = M[M.length - 2];
      if ((t2.x - j3.x) * (N.y - j3.y) >= (t2.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 = (t) => {
  let j = (0, import_compiler_runtime.c)(6), M, N;
  j[0] === t ? (M = j[1], N = j[2]) : ({ delayDuration: N, ...M } = t, j[0] = t, 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((t, j) => {
  let M = (0, import_compiler_runtime.c)(11), N, P, F;
  M[0] === t ? (N = M[1], P = M[2], F = M[3]) : ({ className: N, sideOffset: F, ...P } = t, M[0] = t, M[1] = N, M[2] = P, M[3] = F);
  let I = F === void 0 ? 4 : F, L;
  M[4] === N ? L = M[5] : (L = 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", N), M[4] = N, M[5] = L);
  let R;
  return M[6] !== P || M[7] !== j || M[8] !== I || M[9] !== L ? (R = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyleNamespace, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InternalTooltipContent, {
    ref: j,
    sideOffset: I,
    className: L,
    ...P
  }) }), M[6] = P, M[7] = j, M[8] = I, M[9] = L, M[10] = R) : R = M[10], R;
});
TooltipContent.displayName = Content2.displayName;
var Tooltip = (t) => {
  let j = (0, import_compiler_runtime.c)(22), M, N, P, F, I, L, R, z;
  j[0] === t ? (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 } = t, j[0] = t, 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,
  Provider as s,
  Tooltip as t
};
