"use client";
import * as n from "react";
import { composeEventHandlers as d } from "../../../../../@radix-ui_primitive@1.1.1/node_modules/@radix-ui/primitive/dist/index.js";
import { createContextScope as F } 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 { useControllableState as I } 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 { useComposedRefs as U } 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 { createPopperScope as H, Anchor as W, Content as B, Root as G, Arrow as K } 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 $ } 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 O } 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 j } 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 { DismissableLayer as V } 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 { jsx as i } from "react/jsx-runtime";
var g, x = "HoverCard", [_, le] = F(x, [
  H
]), b = H(), [q, E] = _(x), y = (e) => {
  const {
    __scopeHoverCard: o,
    children: t,
    open: s,
    defaultOpen: a,
    onOpenChange: c,
    openDelay: f = 700,
    closeDelay: v = 300
  } = e, l = b(o), C = n.useRef(0), u = n.useRef(0), m = n.useRef(!1), p = n.useRef(!1), [h = !1, r] = I({
    prop: s,
    defaultProp: a,
    onChange: c
  }), P = n.useCallback(() => {
    clearTimeout(u.current), C.current = window.setTimeout(() => r(!0), f);
  }, [f, r]), R = n.useCallback(() => {
    clearTimeout(C.current), !m.current && !p.current && (u.current = window.setTimeout(() => r(!1), v));
  }, [v, r]), k = n.useCallback(() => r(!1), [r]);
  return n.useEffect(() => () => {
    clearTimeout(C.current), clearTimeout(u.current);
  }, []), /* @__PURE__ */ i(
    q,
    {
      scope: o,
      open: h,
      onOpenChange: r,
      onOpen: P,
      onClose: R,
      onDismiss: k,
      hasSelectionRef: m,
      isPointerDownOnContentRef: p,
      children: /* @__PURE__ */ i(G, { ...l, children: t })
    }
  );
};
y.displayName = x;
var N = "HoverCardTrigger", D = n.forwardRef(
  (e, o) => {
    const { __scopeHoverCard: t, ...s } = e, a = E(N, t), c = b(t);
    return /* @__PURE__ */ i(W, { asChild: !0, ...c, children: /* @__PURE__ */ i(
      j.a,
      {
        "data-state": a.open ? "open" : "closed",
        ...s,
        ref: o,
        onPointerEnter: d(e.onPointerEnter, w(a.onOpen)),
        onPointerLeave: d(e.onPointerLeave, w(a.onClose)),
        onFocus: d(e.onFocus, a.onOpen),
        onBlur: d(e.onBlur, a.onClose),
        onTouchStart: d(e.onTouchStart, (f) => f.preventDefault())
      }
    ) });
  }
);
D.displayName = N;
var T = "HoverCardPortal", [z, J] = _(T, {
  forceMount: void 0
}), A = (e) => {
  const { __scopeHoverCard: o, forceMount: t, children: s, container: a } = e, c = E(T, o);
  return /* @__PURE__ */ i(z, { scope: o, forceMount: t, children: /* @__PURE__ */ i(O, { present: t || c.open, children: /* @__PURE__ */ i($, { asChild: !0, container: a, children: s }) }) });
};
A.displayName = T;
var S = "HoverCardContent", L = n.forwardRef(
  (e, o) => {
    const t = J(S, e.__scopeHoverCard), { forceMount: s = t.forceMount, ...a } = e, c = E(S, e.__scopeHoverCard);
    return /* @__PURE__ */ i(O, { present: s || c.open, children: /* @__PURE__ */ i(
      Q,
      {
        "data-state": c.open ? "open" : "closed",
        ...a,
        onPointerEnter: d(e.onPointerEnter, w(c.onOpen)),
        onPointerLeave: d(e.onPointerLeave, w(c.onClose)),
        ref: o
      }
    ) });
  }
);
L.displayName = S;
var Q = n.forwardRef((e, o) => {
  const {
    __scopeHoverCard: t,
    onEscapeKeyDown: s,
    onPointerDownOutside: a,
    onFocusOutside: c,
    onInteractOutside: f,
    ...v
  } = e, l = E(S, t), C = b(t), u = n.useRef(null), m = U(o, u), [p, h] = n.useState(!1);
  return n.useEffect(() => {
    if (p) {
      const r = document.body;
      return g = r.style.userSelect || r.style.webkitUserSelect, r.style.userSelect = "none", r.style.webkitUserSelect = "none", () => {
        r.style.userSelect = g, r.style.webkitUserSelect = g;
      };
    }
  }, [p]), n.useEffect(() => {
    if (u.current) {
      const r = () => {
        h(!1), l.isPointerDownOnContentRef.current = !1, setTimeout(() => {
          var R;
          ((R = document.getSelection()) == null ? void 0 : R.toString()) !== "" && (l.hasSelectionRef.current = !0);
        });
      };
      return document.addEventListener("pointerup", r), () => {
        document.removeEventListener("pointerup", r), l.hasSelectionRef.current = !1, l.isPointerDownOnContentRef.current = !1;
      };
    }
  }, [l.isPointerDownOnContentRef, l.hasSelectionRef]), n.useEffect(() => {
    u.current && Y(u.current).forEach((P) => P.setAttribute("tabindex", "-1"));
  }), /* @__PURE__ */ i(
    V,
    {
      asChild: !0,
      disableOutsidePointerEvents: !1,
      onInteractOutside: f,
      onEscapeKeyDown: s,
      onPointerDownOutside: a,
      onFocusOutside: d(c, (r) => {
        r.preventDefault();
      }),
      onDismiss: l.onDismiss,
      children: /* @__PURE__ */ i(
        B,
        {
          ...C,
          ...v,
          onPointerDown: d(v.onPointerDown, (r) => {
            r.currentTarget.contains(r.target) && h(!0), l.hasSelectionRef.current = !1, l.isPointerDownOnContentRef.current = !0;
          }),
          ref: m,
          style: {
            ...v.style,
            userSelect: p ? "text" : void 0,
            // Safari requires prefix
            WebkitUserSelect: p ? "text" : void 0,
            "--radix-hover-card-content-transform-origin": "var(--radix-popper-transform-origin)",
            "--radix-hover-card-content-available-width": "var(--radix-popper-available-width)",
            "--radix-hover-card-content-available-height": "var(--radix-popper-available-height)",
            "--radix-hover-card-trigger-width": "var(--radix-popper-anchor-width)",
            "--radix-hover-card-trigger-height": "var(--radix-popper-anchor-height)"
          }
        }
      )
    }
  );
}), X = "HoverCardArrow", M = n.forwardRef(
  (e, o) => {
    const { __scopeHoverCard: t, ...s } = e, a = b(t);
    return /* @__PURE__ */ i(K, { ...a, ...s, ref: o });
  }
);
M.displayName = X;
function w(e) {
  return (o) => o.pointerType === "touch" ? void 0 : e();
}
function Y(e) {
  const o = [], t = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT, {
    acceptNode: (s) => s.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
  });
  for (; t.nextNode(); ) o.push(t.currentNode);
  return o;
}
var de = y, ue = D, pe = A, fe = L, ve = M;
export {
  ve as Arrow,
  fe as Content,
  y as HoverCard,
  M as HoverCardArrow,
  L as HoverCardContent,
  A as HoverCardPortal,
  D as HoverCardTrigger,
  pe as Portal,
  de as Root,
  ue as Trigger,
  le as createHoverCardScope
};
//# sourceMappingURL=index.js.map
