"use client";
'use strict';

var KFH4SEIX = require('./KFH4SEIX.cjs');
var S43UC3DV = require('./S43UC3DV.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";
var useComboboxList = LMDWO4NN.createHook(
  function useComboboxList2(_a) {
    var _b = _a, { store, alwaysVisible } = _b, props = _3YLGPPWQ.__objRest(_b, ["store", "alwaysVisible"]);
    const scopedContext = S43UC3DV.useComboboxScopedContext(true);
    const context = S43UC3DV.useComboboxContext();
    store = store || context;
    const scopedContextSameStore = !!store && store === scopedContext;
    PBFD2E7P.invariant(
      store,
      process.env.NODE_ENV !== "production" && "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
    );
    const ref = React.useRef(null);
    const id = ABQUS43J.useId(props.id);
    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;
    const multiSelectable = store.useState(
      (state) => Array.isArray(state.selectedValue)
    );
    const role = ABQUS43J.useAttribute(ref, "role", props.role);
    const isCompositeRole = role === "listbox" || role === "tree" || role === "grid";
    const ariaMultiSelectable = isCompositeRole ? multiSelectable || void 0 : void 0;
    const [hasListboxInside, setHasListboxInside] = React.useState(false);
    const contentElement = store.useState("contentElement");
    ABQUS43J.useSafeLayoutEffect(() => {
      if (!mounted) return;
      const element = ref.current;
      if (!element) return;
      if (contentElement !== element) return;
      const callback = () => {
        setHasListboxInside(!!element.querySelector("[role='listbox']"));
      };
      const observer = new MutationObserver(callback);
      observer.observe(element, {
        subtree: true,
        childList: true,
        attributeFilter: ["role"]
      });
      callback();
      return () => observer.disconnect();
    }, [mounted, contentElement]);
    if (!hasListboxInside) {
      props = _3YLGPPWQ.__spreadValues({
        role: "listbox",
        "aria-multiselectable": ariaMultiSelectable
      }, props);
    }
    props = ABQUS43J.useWrapElement(
      props,
      (element) => /* @__PURE__ */ jsxRuntime.jsx(S43UC3DV.ComboboxScopedContextProvider, { value: store, children: /* @__PURE__ */ jsxRuntime.jsx(S43UC3DV.ComboboxListRoleContext.Provider, { value: role, children: element }) }),
      [store, role]
    );
    const setContentElement = id && (!scopedContext || !scopedContextSameStore) ? store.setContentElement : null;
    props = _3YLGPPWQ.__spreadProps(_3YLGPPWQ.__spreadValues({
      id,
      hidden
    }, props), {
      ref: ABQUS43J.useMergeRefs(setContentElement, ref, props.ref),
      style
    });
    return PBFD2E7P.removeUndefinedValues(props);
  }
);
var ComboboxList = LMDWO4NN.forwardRef(function ComboboxList2(props) {
  const htmlProps = useComboboxList(props);
  return LMDWO4NN.createElement(TagName, htmlProps);
});

exports.ComboboxList = ComboboxList;
exports.useComboboxList = useComboboxList;
//# sourceMappingURL=MAXQOH4L.cjs.map
