import * as n from "react";
import { composeEventHandlers as d } from "../../../../../@radix-ui_primitive@1.1.0/node_modules/@radix-ui/primitive/dist/index.js";
import { createContextScope as M } from "../../../../../@radix-ui_react-context@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-context/dist/index.js";
import { useControllableState as k } from "../../../../../@radix-ui_react-use-controllable-state@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { useComposedRefs as F } from "../../../../../@radix-ui_react-compose-refs@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createPopperScope as T, Root as I, Anchor as U, Content as W, Arrow as B } from "../../../../../@radix-ui_react-popper@1.2.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@_0c236d22233b5684ecf8a3d8d1b24562/node_modules/@radix-ui/react-popper/dist/index.js";
import { Portal as G } from "../../../../../@radix-ui_react-portal@1.1.1_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@_d91fd04d10d265136bf0d35a7b9375b2/node_modules/@radix-ui/react-portal/dist/index.js";
import { Presence as H } from "../../../../../@radix-ui_react-presence@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_reac_4a916339a724b4591202705df11dd5fc/node_modules/@radix-ui/react-presence/dist/index.js";
import { Primitive as K } from "../../../../../@radix-ui_react-primitive@2.0.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_rea_bdcf182289a3a76356f07e550726e479/node_modules/@radix-ui/react-primitive/dist/index.js";
import { DismissableLayer as $ } from "../../../../../@radix-ui_react-dismissable-layer@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@t_540819d22b5f34e77f512765c1a78ce5/node_modules/@radix-ui/react-dismissable-layer/dist/index.js";
import { j as i } from "../../../../../../../_virtual/jsx-runtime.js";
var E, b = "HoverCard", [O, le] = M(b, [
  T
]), S = T(), [V, w] = O(b), _ = (e) => {
  const {
    __scopeHoverCard: o,
    children: t,
    open: s,
    defaultOpen: a,
    onOpenChange: c,
    openDelay: f = 700,
    closeDelay: v = 300
  } = e, l = S(o), C = n.useRef(0), u = n.useRef(0), m = n.useRef(!1), p = n.useRef(!1), [h = !1, r] = k({
    prop: s,
    defaultProp: a,
    onChange: c
  }), x = n.useCallback(() => {
    clearTimeout(u.current), C.current = window.setTimeout(() => r(!0), f);
  }, [f, r]), A = n.useCallback(() => {
    clearTimeout(C.current), !m.current && !p.current && (u.current = window.setTimeout(() => r(!1), v));
  }, [v, r]), L = n.useCallback(() => r(!1), [r]);
  return n.useEffect(() => () => {
    clearTimeout(C.current), clearTimeout(u.current);
  }, []), /* @__PURE__ */ i.jsx(
    V,
    {
      scope: o,
      open: h,
      onOpenChange: r,
      onOpen: x,
      onClose: A,
      onDismiss: L,
      hasSelectionRef: m,
      isPointerDownOnContentRef: p,
      children: /* @__PURE__ */ i.jsx(I, { ...l, children: t })
    }
  );
};
_.displayName = b;
var y = "HoverCardTrigger", N = n.forwardRef(
  (e, o) => {
    const { __scopeHoverCard: t, ...s } = e, a = w(y, t), c = S(t);
    return /* @__PURE__ */ i.jsx(U, { asChild: !0, ...c, children: /* @__PURE__ */ i.jsx(
      K.a,
      {
        "data-state": a.open ? "open" : "closed",
        ...s,
        ref: o,
        onPointerEnter: d(e.onPointerEnter, R(a.onOpen)),
        onPointerLeave: d(e.onPointerLeave, R(a.onClose)),
        onFocus: d(e.onFocus, a.onOpen),
        onBlur: d(e.onBlur, a.onClose),
        onTouchStart: d(e.onTouchStart, (f) => f.preventDefault())
      }
    ) });
  }
);
N.displayName = y;
var g = "HoverCardPortal", [q, z] = O(g, {
  forceMount: void 0
}), D = (e) => {
  const { __scopeHoverCard: o, forceMount: t, children: s, container: a } = e, c = w(g, o);
  return /* @__PURE__ */ i.jsx(q, { scope: o, forceMount: t, children: /* @__PURE__ */ i.jsx(H, { present: t || c.open, children: /* @__PURE__ */ i.jsx(G, { asChild: !0, container: a, children: s }) }) });
};
D.displayName = g;
var P = "HoverCardContent", j = n.forwardRef(
  (e, o) => {
    const t = z(P, e.__scopeHoverCard), { forceMount: s = t.forceMount, ...a } = e, c = w(P, e.__scopeHoverCard);
    return /* @__PURE__ */ i.jsx(H, { present: s || c.open, children: /* @__PURE__ */ i.jsx(
      J,
      {
        "data-state": c.open ? "open" : "closed",
        ...a,
        onPointerEnter: d(e.onPointerEnter, R(c.onOpen)),
        onPointerLeave: d(e.onPointerLeave, R(c.onClose)),
        ref: o
      }
    ) });
  }
);
j.displayName = P;
var J = n.forwardRef((e, o) => {
  const {
    __scopeHoverCard: t,
    onEscapeKeyDown: s,
    onPointerDownOutside: a,
    onFocusOutside: c,
    onInteractOutside: f,
    ...v
  } = e, l = w(P, t), C = S(t), u = n.useRef(null), m = F(o, u), [p, h] = n.useState(!1);
  return n.useEffect(() => {
    if (p) {
      const r = document.body;
      return E = r.style.userSelect || r.style.webkitUserSelect, r.style.userSelect = "none", r.style.webkitUserSelect = "none", () => {
        r.style.userSelect = E, r.style.webkitUserSelect = E;
      };
    }
  }, [p]), n.useEffect(() => {
    if (u.current) {
      const r = () => {
        h(!1), l.isPointerDownOnContentRef.current = !1, setTimeout(() => {
          document.getSelection()?.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((x) => x.setAttribute("tabindex", "-1"));
  }), /* @__PURE__ */ i.jsx(
    $,
    {
      asChild: !0,
      disableOutsidePointerEvents: !1,
      onInteractOutside: f,
      onEscapeKeyDown: s,
      onPointerDownOutside: a,
      onFocusOutside: d(c, (r) => {
        r.preventDefault();
      }),
      onDismiss: l.onDismiss,
      children: /* @__PURE__ */ i.jsx(
        W,
        {
          ...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)"
          }
        }
      )
    }
  );
}), Q = "HoverCardArrow", X = n.forwardRef(
  (e, o) => {
    const { __scopeHoverCard: t, ...s } = e, a = S(t);
    return /* @__PURE__ */ i.jsx(B, { ...a, ...s, ref: o });
  }
);
X.displayName = Q;
function R(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 = _, ue = N, pe = D, fe = j;
export {
  fe as Content,
  _ as HoverCard,
  X as HoverCardArrow,
  j as HoverCardContent,
  D as HoverCardPortal,
  N as HoverCardTrigger,
  pe as Portal,
  de as Root,
  ue as Trigger,
  le as createHoverCardScope
};
//# sourceMappingURL=index.js.map
