import * as i from "react";
import { useTooltipRootContext as N } from "../root/TooltipRootContext.js";
import { TooltipPositionerContext as H } from "./TooltipPositionerContext.js";
import { useAnchorPositioning as V } from "../../utils/useAnchorPositioning.js";
import { popupStateMapping as U } from "../../utils/popupStateMapping.js";
import { useTooltipPortalContext as D } from "../portal/TooltipPortalContext.js";
import { useRenderElement as I } from "../../utils/useRenderElement.js";
import { POPUP_COLLISION_AVOIDANCE as _ } from "../../utils/constants.js";
import { adaptiveOrigin as L } from "../../utils/adaptiveOriginMiddleware.js";
import { getDisabledMountTransitionStyles as j } from "../../utils/getDisabledMountTransitionStyles.js";
import { jsx as B } from "react/jsx-runtime";
const q = /* @__PURE__ */ i.forwardRef(function(a, d) {
  const {
    render: F,
    className: G,
    anchor: u,
    positionMethod: m = "absolute",
    side: f = "top",
    align: S = "center",
    sideOffset: g = 0,
    alignOffset: P = 0,
    collisionBoundary: h = "clipping-ancestors",
    collisionPadding: w = 5,
    arrowPadding: y = 5,
    sticky: v = !1,
    disableAnchorTracking: x = !1,
    collisionAvoidance: T = _,
    ...b
  } = a, o = N(), C = D(), e = o.useState("open"), r = o.useState("mounted"), n = o.useState("trackCursorAxis"), p = o.useState("disableHoverablePopup"), O = o.useState("floatingRootContext"), l = o.useState("instantType"), R = o.useState("transitionStatus"), A = o.useState("hasViewport"), t = V({
    anchor: u,
    positionMethod: m,
    floatingRootContext: O,
    mounted: r,
    side: f,
    sideOffset: g,
    align: S,
    alignOffset: P,
    collisionBoundary: h,
    collisionPadding: w,
    sticky: v,
    arrowPadding: y,
    disableAnchorTracking: x,
    keepMounted: C,
    collisionAvoidance: T,
    adaptiveOrigin: A ? L : void 0
  }), M = i.useMemo(() => {
    const c = {};
    return (!e || n === "both" || p) && (c.pointerEvents = "none"), {
      role: "presentation",
      hidden: !r,
      style: {
        ...t.positionerStyles,
        ...c
      }
    };
  }, [e, n, p, r, t.positionerStyles]), s = i.useMemo(() => ({
    open: e,
    side: t.side,
    align: t.align,
    anchorHidden: t.anchorHidden,
    instant: n !== "none" ? "tracking-cursor" : l
  }), [e, t.side, t.align, t.anchorHidden, n, l]), k = i.useMemo(() => ({
    ...s,
    arrowRef: t.arrowRef,
    arrowStyles: t.arrowStyles,
    arrowUncentered: t.arrowUncentered
  }), [s, t.arrowRef, t.arrowStyles, t.arrowUncentered]), E = I("div", a, {
    state: s,
    props: [M, j(R), b],
    ref: [d, o.useStateSetter("positionerElement")],
    stateAttributesMapping: U
  });
  return /* @__PURE__ */ B(H.Provider, {
    value: k,
    children: E
  });
});
process.env.NODE_ENV !== "production" && (q.displayName = "TooltipPositioner");
export {
  q as TooltipPositioner
};
