import { filterDOMProps as z, useId as F, mergeProps as $, useSlotId as v, isMac as D, isWebKit as w } from "../../utils/dist/module.es.js";
import { useFocusWithin as A, useHover as H, isFocusVisible as W } from "../../interactions/dist/module.es.js";
import { useLabel as K } from "../../label/dist/module.es.js";
import { useSelectableList as _, useSelectableItem as B } from "../../selection/dist/module.es.js";
import { getItemCount as L } from "../node_modules/@react-stately/collections/dist/module.es.js";
const h = /* @__PURE__ */ new WeakMap();
function k(e) {
  return typeof e == "string" ? e.replace(/\s*/g, "") : "" + e;
}
function C(e, i) {
  let l = h.get(e);
  if (!l)
    throw new Error("Unknown list");
  return `${l.id}-option-${k(i)}`;
}
function J(e, i, l) {
  let o = z(e, {
    labelable: !0
  }), { listProps: s } = _({
    ...e,
    ref: l,
    selectionManager: i.selectionManager,
    collection: i.collection,
    disabledKeys: i.disabledKeys
  }), { focusWithinProps: r } = A({
    onFocusWithin: e.onFocus,
    onBlurWithin: e.onBlur,
    onFocusWithinChange: e.onFocusChange
  }), a = F(e.id);
  h.set(i, {
    id: a,
    shouldUseVirtualFocus: e.shouldUseVirtualFocus,
    shouldSelectOnPressUp: e.shouldSelectOnPressUp,
    shouldFocusOnHover: e.shouldFocusOnHover,
    isVirtualized: e.isVirtualized,
    onAction: e.onAction
  });
  let { labelProps: d, fieldProps: n } = K({
    ...e,
    id: a,
    labelElementType: "span"
  });
  return {
    labelProps: d,
    listBoxProps: $(o, r, i.selectionManager.selectionMode === "multiple" ? {
      "aria-multiselectable": "true"
    } : {}, {
      role: "listbox",
      ...$(n, s)
    })
  };
}
function N(e, i, l) {
  let { key: o } = e, s = h.get(i);
  var r;
  let a = (r = e.isDisabled) !== null && r !== void 0 ? r : i.disabledKeys.has(o);
  var d;
  let n = (d = e.isSelected) !== null && d !== void 0 ? d : i.selectionManager.isSelected(o), S = i.selectionManager.focusedKey === o;
  var c;
  let p = (c = e.shouldSelectOnPressUp) !== null && c !== void 0 ? c : s.shouldSelectOnPressUp;
  var u;
  let P = (u = e.shouldFocusOnHover) !== null && u !== void 0 ? u : s.shouldFocusOnHover;
  var b;
  let O = (b = e.shouldUseVirtualFocus) !== null && b !== void 0 ? b : s.shouldUseVirtualFocus;
  var f;
  let g = (f = e.isVirtualized) !== null && f !== void 0 ? f : s.isVirtualized, x = v(), m = v(), t = {
    role: "option",
    "aria-disabled": a,
    "aria-selected": i.selectionManager.selectionMode !== "none" ? n : void 0
  };
  D() && w() || (t["aria-label"] = e["aria-label"], t["aria-labelledby"] = x, t["aria-describedby"] = m), g && (t["aria-posinset"] = i.collection.getItem(o).index + 1, t["aria-setsize"] = L(i.collection));
  let { itemProps: M, isPressed: U, hasAction: V, allowsSelection: y } = B({
    selectionManager: i.selectionManager,
    key: o,
    ref: l,
    shouldSelectOnPressUp: p,
    allowsDifferentPressOrigin: p && P,
    isVirtualized: g,
    shouldUseVirtualFocus: O,
    isDisabled: a,
    onAction: s.onAction ? () => s.onAction(o) : void 0
  }), { hoverProps: I } = H({
    isDisabled: a || !P,
    onHoverStart() {
      W() || (i.selectionManager.setFocused(!0), i.selectionManager.setFocusedKey(o));
    }
  });
  return {
    optionProps: {
      ...t,
      ...$(M, I),
      id: C(i, o)
    },
    labelProps: {
      id: x
    },
    descriptionProps: {
      id: m
    },
    isFocused: S,
    isSelected: n,
    isDisabled: a,
    isPressed: U,
    allowsSelection: y,
    hasAction: V
  };
}
function Q(e) {
  let { heading: i, "aria-label": l } = e, o = F();
  return {
    itemProps: {
      role: "presentation"
    },
    headingProps: i ? {
      id: o,
      "aria-hidden": !0
    } : {},
    groupProps: {
      role: "group",
      "aria-label": l,
      "aria-labelledby": i ? o : void 0
    }
  };
}
export {
  C as getItemId,
  h as listData,
  J as useListBox,
  Q as useListBoxSection,
  N as useOption
};
//# sourceMappingURL=module.es.js.map
