"use client";
'use strict';

var VIIRIBF3 = require('./VIIRIBF3.cjs');
var T7VMP3TM = require('./T7VMP3TM.cjs');
var KFH4SEIX = require('./KFH4SEIX.cjs');
var _5JTVDSTH = require('./5JTVDSTH.cjs');
var YV4JVR4I = require('./YV4JVR4I.cjs');
var LMDWO4NN = require('./LMDWO4NN.cjs');
var ABQUS43J = require('./ABQUS43J.cjs');
var _3YLGPPWQ = require('./3YLGPPWQ.cjs');
var PBFD2E7P = require('../../../../../../@ariakit_core@0.4.15/node_modules/@ariakit/core/esm/__chunks/PBFD2E7P.cjs');
var React = require('react');
var jsxRuntime = require('react/jsx-runtime');

var TagName = "div";
function useAriaLabelledBy(_a) {
  var _b = _a, { store } = _b, props = _3YLGPPWQ.__objRest(_b, ["store"]);
  const [id, setId] = React.useState(void 0);
  const label = props["aria-label"];
  const disclosureElement = YV4JVR4I.useStoreState(store, "disclosureElement");
  const contentElement = YV4JVR4I.useStoreState(store, "contentElement");
  React.useEffect(() => {
    const disclosure = disclosureElement;
    if (!disclosure) return;
    const menu = contentElement;
    if (!menu) return;
    const menuLabel = label || menu.hasAttribute("aria-label");
    if (menuLabel) {
      setId(void 0);
    } else if (disclosure.id) {
      setId(disclosure.id);
    }
  }, [label, disclosureElement, contentElement]);
  return id;
}
var useMenuList = LMDWO4NN.createHook(
  function useMenuList2(_a) {
    var _b = _a, { store, alwaysVisible, composite } = _b, props = _3YLGPPWQ.__objRest(_b, ["store", "alwaysVisible", "composite"]);
    const context = VIIRIBF3.useMenuProviderContext();
    store = store || context;
    PBFD2E7P.invariant(
      store,
      process.env.NODE_ENV !== "production" && "MenuList must receive a `store` prop or be wrapped in a MenuProvider component."
    );
    const parentMenu = store.parent;
    const parentMenubar = store.menubar;
    const hasParentMenu = !!parentMenu;
    const id = ABQUS43J.useId(props.id);
    const onKeyDownProp = props.onKeyDown;
    const dir = store.useState(
      (state) => state.placement.split("-")[0]
    );
    const orientation = store.useState(
      (state) => state.orientation === "both" ? void 0 : state.orientation
    );
    const isHorizontal = orientation !== "vertical";
    const isMenubarHorizontal = YV4JVR4I.useStoreState(
      parentMenubar,
      (state) => !!state && state.orientation !== "vertical"
    );
    const onKeyDown = ABQUS43J.useEvent((event) => {
      onKeyDownProp == null ? void 0 : onKeyDownProp(event);
      if (event.defaultPrevented) return;
      if (hasParentMenu || parentMenubar && !isHorizontal) {
        const hideMap = {
          ArrowRight: () => dir === "left" && !isHorizontal,
          ArrowLeft: () => dir === "right" && !isHorizontal,
          ArrowUp: () => dir === "bottom" && isHorizontal,
          ArrowDown: () => dir === "top" && isHorizontal
        };
        const action = hideMap[event.key];
        if (action == null ? void 0 : action()) {
          event.stopPropagation();
          event.preventDefault();
          return store == null ? void 0 : store.hide();
        }
      }
      if (parentMenubar) {
        const keyMap = {
          ArrowRight: () => {
            if (!isMenubarHorizontal) return;
            return parentMenubar.next();
          },
          ArrowLeft: () => {
            if (!isMenubarHorizontal) return;
            return parentMenubar.previous();
          },
          ArrowDown: () => {
            if (isMenubarHorizontal) return;
            return parentMenubar.next();
          },
          ArrowUp: () => {
            if (isMenubarHorizontal) return;
            return parentMenubar.previous();
          }
        };
        const action = keyMap[event.key];
        const id2 = action == null ? void 0 : action();
        if (id2 !== void 0) {
          event.stopPropagation();
          event.preventDefault();
          parentMenubar.move(id2);
        }
      }
    });
    props = ABQUS43J.useWrapElement(
      props,
      (element) => /* @__PURE__ */ jsxRuntime.jsx(VIIRIBF3.MenuScopedContextProvider, { value: store, children: element }),
      [store]
    );
    const ariaLabelledBy = useAriaLabelledBy(_3YLGPPWQ.__spreadValues({ store }, props));
    const mounted = store.useState("mounted");
    const hidden = KFH4SEIX.isHidden(mounted, props.hidden, alwaysVisible);
    const style = hidden ? _3YLGPPWQ.__spreadProps(_3YLGPPWQ.__spreadValues({}, props.style), { display: "none" }) : props.style;
    props = _3YLGPPWQ.__spreadProps(_3YLGPPWQ.__spreadValues({
      id,
      "aria-labelledby": ariaLabelledBy,
      hidden
    }, props), {
      ref: ABQUS43J.useMergeRefs(id ? store.setContentElement : null, props.ref),
      style,
      onKeyDown
    });
    const hasCombobox = !!store.combobox;
    composite = composite != null ? composite : !hasCombobox;
    if (composite) {
      props = _3YLGPPWQ.__spreadValues({
        role: "menu",
        "aria-orientation": orientation
      }, props);
    }
    props = _5JTVDSTH.useComposite(_3YLGPPWQ.__spreadValues({ store, composite }, props));
    props = T7VMP3TM.useCompositeTypeahead(_3YLGPPWQ.__spreadValues({ store, typeahead: !hasCombobox }, props));
    return props;
  }
);
LMDWO4NN.forwardRef(function MenuList2(props) {
  const htmlProps = useMenuList(props);
  return LMDWO4NN.createElement(TagName, htmlProps);
});

exports.useMenuList = useMenuList;
//# sourceMappingURL=MDUNURGC.cjs.map
