"use client";
import * as React from "react";
import { useNavigationMenuRootContext, useNavigationMenuTreeContext } from "../root/NavigationMenuRootContext.js";
import { isOutsideMenuEvent } from "../utils/isOutsideMenuEvent.js";
import { CompositeItem } from "../../composite/item/CompositeItem.js";
import { createChangeEventDetails } from "../../utils/createBaseUIEventDetails.js";
import { jsx } from "react/jsx-runtime";
import { useFloatingTree } from "../../floating-ui-react/components/FloatingTree.js";
import { focusOut, linkPress } from "../../utils/reason-parts.js";
const NavigationMenuLink = /* @__PURE__ */ React.forwardRef(function NavigationMenuLink2(componentProps, forwardedRef) {
  const {
    className,
    render,
    active = false,
    closeOnClick = false,
    ...elementProps
  } = componentProps;
  const {
    setValue,
    popupElement,
    positionerElement,
    rootRef
  } = useNavigationMenuRootContext();
  const nodeId = useNavigationMenuTreeContext();
  const tree = useFloatingTree();
  const state = React.useMemo(() => ({
    active
  }), [active]);
  const defaultProps = {
    "aria-current": active ? "page" : void 0,
    tabIndex: void 0,
    onClick(event) {
      if (closeOnClick) {
        setValue(null, createChangeEventDetails(linkPress, event.nativeEvent));
      }
    },
    onBlur(event) {
      if (positionerElement && popupElement && isOutsideMenuEvent({
        currentTarget: event.currentTarget,
        relatedTarget: event.relatedTarget
      }, {
        popupElement,
        rootRef,
        tree,
        nodeId
      })) {
        setValue(null, createChangeEventDetails(focusOut, event.nativeEvent));
      }
    }
  };
  return /* @__PURE__ */ jsx(CompositeItem, {
    tag: "a",
    render,
    className,
    state,
    refs: [forwardedRef],
    props: [defaultProps, elementProps]
  });
});
if (process.env.NODE_ENV !== "production") NavigationMenuLink.displayName = "NavigationMenuLink";
export {
  NavigationMenuLink
};
//# sourceMappingURL=NavigationMenuLink.js.map
