"use client";
import * as React from "react";
import { usePreviewCardRootContext } from "../root/PreviewCardContext.js";
import { PreviewCardPositionerContext } from "./PreviewCardPositionerContext.js";
import { useAnchorPositioning } from "../../utils/useAnchorPositioning.js";
import { popupStateMapping } from "../../utils/popupStateMapping.js";
import { usePreviewCardPortalContext } from "../portal/PreviewCardPortalContext.js";
import { POPUP_COLLISION_AVOIDANCE } from "../../utils/constants.js";
import { useRenderElement } from "../../utils/useRenderElement.js";
import { jsx } from "react/jsx-runtime";
const PreviewCardPositioner = /* @__PURE__ */ React.forwardRef(function PreviewCardPositioner2(componentProps, forwardedRef) {
  const {
    render,
    className,
    anchor,
    positionMethod = "absolute",
    side = "bottom",
    align = "center",
    sideOffset = 0,
    alignOffset = 0,
    collisionBoundary = "clipping-ancestors",
    collisionPadding = 5,
    arrowPadding = 5,
    sticky = false,
    disableAnchorTracking = false,
    collisionAvoidance = POPUP_COLLISION_AVOIDANCE,
    ...elementProps
  } = componentProps;
  const {
    open,
    mounted,
    floatingRootContext,
    setPositionerElement
  } = usePreviewCardRootContext();
  const keepMounted = usePreviewCardPortalContext();
  const positioning = useAnchorPositioning({
    anchor,
    floatingRootContext,
    positionMethod,
    mounted,
    side,
    sideOffset,
    align,
    alignOffset,
    arrowPadding,
    collisionBoundary,
    collisionPadding,
    sticky,
    disableAnchorTracking,
    keepMounted,
    collisionAvoidance
  });
  const defaultProps = React.useMemo(() => {
    const hiddenStyles = {};
    if (!open) {
      hiddenStyles.pointerEvents = "none";
    }
    return {
      role: "presentation",
      hidden: !mounted,
      style: {
        ...positioning.positionerStyles,
        ...hiddenStyles
      }
    };
  }, [open, mounted, positioning.positionerStyles]);
  const state = React.useMemo(() => ({
    open,
    side: positioning.side,
    align: positioning.align,
    anchorHidden: positioning.anchorHidden
  }), [open, positioning.side, positioning.align, positioning.anchorHidden]);
  const contextValue = React.useMemo(() => ({
    side: positioning.side,
    align: positioning.align,
    arrowRef: positioning.arrowRef,
    arrowUncentered: positioning.arrowUncentered,
    arrowStyles: positioning.arrowStyles
  }), [positioning.side, positioning.align, positioning.arrowRef, positioning.arrowUncentered, positioning.arrowStyles]);
  const element = useRenderElement("div", componentProps, {
    state,
    ref: [setPositionerElement, forwardedRef],
    props: [defaultProps, elementProps],
    stateAttributesMapping: popupStateMapping
  });
  return /* @__PURE__ */ jsx(PreviewCardPositionerContext.Provider, {
    value: contextValue,
    children: element
  });
});
if (process.env.NODE_ENV !== "production") PreviewCardPositioner.displayName = "PreviewCardPositioner";
export {
  PreviewCardPositioner
};
//# sourceMappingURL=PreviewCardPositioner.js.map
