import { a as N, e as X, g as ue, $ as Y, b as fe } from "./utils-CrjF8U_E.es.js";
import { g as $e, h as R, i as be } from "./SelectionManager-GNsyMc-q.es.js";
import u, { useRef as A, createContext as U, useCallback as pe, useMemo as Z, forwardRef as W, useContext as x, useEffect as ee } from "react";
import { $ as ve, a as ge, b as me, c as he } from "./Header-BQ99pNEi.es.js";
import { b as xe } from "./RSPContexts-DLgb84PF.es.js";
import { a as Pe, $ as De } from "./SelectionIndicator-B27AsfqE.es.js";
import { a as ye } from "./Separator-DFaT-SpI.es.js";
import { $ as Ee } from "./Text-DOcU1ycg.es.js";
import { c as Be, d as Me, $ as Se, e as Fe, f as Le, g as we, h as bo } from "./CollectionBuilder-CTjJUDzO.es.js";
import { b as Ie, a as oe, $ as w, c as J, d as ke } from "./mergeProps-B-cqsBhL.es.js";
import { $ as k } from "./filterDOMProps-Cxz9cAAv.es.js";
import { $ as te } from "./useObjectRef-CaJ5pgjX.es.js";
import { $ as Ve } from "./getScrollParent-vifdmp1X.es.js";
import { $ as Te } from "./useEffectEvent-B4Fd4l1o.es.js";
import { $ as Oe, a as Ce, b as Po } from "./useListState-BxWOm_-s.es.js";
import { c as Ae, h as Ne, f as Ue } from "./openLink-m90p5mer.es.js";
import { $ as Q } from "./useFocusVisible-_CKiSck5.es.js";
import { $ as ae } from "./useHover-BiPYlZr_.es.js";
import { $ as He } from "./useFocusWithin-CdBYoNiQ.es.js";
import { $ as Ke } from "./useLabel-D521nHvC.es.js";
import { $ as _e } from "./useFocus-DWn32Fi6.es.js";
import { $ as ze } from "./context-BfHy4NgG.es.js";
import { $ as Re } from "./useCollator-DKdD8vEj.es.js";
import { $ as We } from "./useFocusRing-CZQUsztf.es.js";
import { b as qe } from "./FocusScope-DI1zU4s2.es.js";
function ko(o, e) {
  let { collection: a, onLoadMore: t, scrollOffset: i = 1 } = o, l = A(null), r = Te((n) => {
    for (let s of n)
      s.isIntersecting && t && t();
  });
  Ie(() => (e.current && (l.current = new IntersectionObserver(r, {
    root: Ve(e?.current),
    rootMargin: `0px ${100 * i}% ${100 * i}% ${100 * i}%`
  }), l.current.observe(e.current)), () => {
    l.current && l.current.disconnect();
  }), [
    a,
    e,
    i
  ]);
}
const q = /* @__PURE__ */ new WeakMap();
function je(o) {
  return typeof o == "string" ? o.replace(/\s*/g, "") : "" + o;
}
function Ge(o, e) {
  let a = q.get(o);
  if (!a) throw new Error("Unknown list");
  return `${a.id}-option-${je(e)}`;
}
function Je(o, e, a) {
  let t = k(o, {
    labelable: !0
  }), i = o.selectionBehavior || "toggle", l = o.linkBehavior || (i === "replace" ? "action" : "override");
  i === "toggle" && l === "action" && (l = "override");
  let { listProps: r } = ve({
    ...o,
    ref: a,
    selectionManager: e.selectionManager,
    collection: e.collection,
    disabledKeys: e.disabledKeys,
    linkBehavior: l
  }), { focusWithinProps: n } = He({
    onFocusWithin: o.onFocus,
    onBlurWithin: o.onBlur,
    onFocusWithinChange: o.onFocusChange
  }), s = oe(o.id);
  q.set(e, {
    id: s,
    shouldUseVirtualFocus: o.shouldUseVirtualFocus,
    shouldSelectOnPressUp: o.shouldSelectOnPressUp,
    shouldFocusOnHover: o.shouldFocusOnHover,
    isVirtualized: o.isVirtualized,
    onAction: o.onAction,
    linkBehavior: l,
    // @ts-ignore
    UNSTABLE_itemBehavior: o.UNSTABLE_itemBehavior
  });
  let { labelProps: $, fieldProps: f } = Ke({
    ...o,
    id: s,
    // listbox is not an HTML input element so it
    // shouldn't be labeled by a <label> element.
    labelElementType: "span"
  });
  return {
    labelProps: $,
    listBoxProps: w(t, n, e.selectionManager.selectionMode === "multiple" ? {
      "aria-multiselectable": "true"
    } : {}, {
      role: "listbox",
      ...w(f, r)
    })
  };
}
function Qe(o, e, a) {
  var t, i;
  let { key: l } = o, r = q.get(e);
  var n;
  let s = (n = o.isDisabled) !== null && n !== void 0 ? n : e.selectionManager.isDisabled(l);
  var $;
  let f = ($ = o.isSelected) !== null && $ !== void 0 ? $ : e.selectionManager.isSelected(l);
  var d;
  let c = (d = o.shouldSelectOnPressUp) !== null && d !== void 0 ? d : r?.shouldSelectOnPressUp;
  var g;
  let v = (g = o.shouldFocusOnHover) !== null && g !== void 0 ? g : r?.shouldFocusOnHover;
  var P;
  let D = (P = o.shouldUseVirtualFocus) !== null && P !== void 0 ? P : r?.shouldUseVirtualFocus;
  var b;
  let B = (b = o.isVirtualized) !== null && b !== void 0 ? b : r?.isVirtualized, M = J(), y = J(), m = {
    role: "option",
    "aria-disabled": s || void 0,
    "aria-selected": e.selectionManager.selectionMode !== "none" ? f : void 0
  };
  Ae() && Ne() || (m["aria-label"] = o["aria-label"], m["aria-labelledby"] = M, m["aria-describedby"] = y);
  let p = e.collection.getItem(l);
  if (B) {
    let h = Number(p?.index);
    m["aria-posinset"] = Number.isNaN(h) ? void 0 : h + 1, m["aria-setsize"] = ge(e.collection);
  }
  let V = r?.onAction ? () => {
    var h;
    return r == null || (h = r.onAction) === null || h === void 0 ? void 0 : h.call(r, l);
  } : void 0, S = Ge(e, l), { itemProps: E, isPressed: F, isFocused: L, hasAction: T, allowsSelection: O } = $e({
    selectionManager: e.selectionManager,
    key: l,
    ref: a,
    shouldSelectOnPressUp: c,
    allowsDifferentPressOrigin: c && v,
    isVirtualized: B,
    shouldUseVirtualFocus: D,
    isDisabled: s,
    onAction: V || !(p == null || (t = p.props) === null || t === void 0) && t.onAction ? ke(p == null || (i = p.props) === null || i === void 0 ? void 0 : i.onAction, V) : void 0,
    linkBehavior: r?.linkBehavior,
    // @ts-ignore
    UNSTABLE_itemBehavior: r?.UNSTABLE_itemBehavior,
    id: S
  }), { hoverProps: _ } = ae({
    isDisabled: s || !v,
    onHoverStart() {
      Q() || (e.selectionManager.setFocused(!0), e.selectionManager.setFocusedKey(l));
    }
  }), I = k(p?.props);
  delete I.id;
  let C = Ue(p?.props);
  return {
    optionProps: {
      ...m,
      ...w(I, E, _, C),
      id: S
    },
    labelProps: {
      id: M
    },
    descriptionProps: {
      id: y
    },
    isFocused: L,
    isFocusVisible: L && e.selectionManager.isFocused && Q(),
    isSelected: f,
    isDisabled: s,
    isPressed: F,
    allowsSelection: O,
    hasAction: T
  };
}
function Xe(o) {
  let { heading: e, "aria-label": a } = o, t = oe();
  return {
    itemProps: {
      role: "presentation"
    },
    headingProps: e ? {
      // Techincally, listbox cannot contain headings according to ARIA.
      // We hide the heading from assistive technology, using role="presentation",
      // and only use it as a visual label for the nested group.
      id: t,
      role: "presentation"
    } : {},
    groupProps: {
      role: "group",
      "aria-label": a,
      "aria-labelledby": e ? t : void 0
    }
  };
}
const H = /* @__PURE__ */ U({}), re = /* @__PURE__ */ U(null), Ye = /* @__PURE__ */ W(function(e, a) {
  let { render: t } = x(re);
  return /* @__PURE__ */ u.createElement(u.Fragment, null, t(e, a));
});
function le(o, e) {
  var a;
  let t = o?.renderDropIndicator, i = o == null || (a = o.isVirtualDragging) === null || a === void 0 ? void 0 : a.call(o), l = pe((r) => {
    if (i || e?.isDropTarget(r)) return t ? t(r) : /* @__PURE__ */ u.createElement(Ye, {
      target: r
    });
  }, [
    e?.target,
    i,
    t
  ]);
  return o?.useDropIndicator ? l : void 0;
}
function Ze(o, e, a) {
  var t, i;
  let l = o.focusedKey, r = null;
  if (!(e == null || (t = e.isVirtualDragging) === null || t === void 0) && t.call(e) && (a == null || (i = a.target) === null || i === void 0 ? void 0 : i.type) === "item" && (r = a.target.key, a.target.dropPosition === "after")) {
    let d = a.collection.getKeyAfter(r), c = null;
    if (d != null) {
      var n, s;
      let g = (s = (n = a.collection.getItem(r)) === null || n === void 0 ? void 0 : n.level) !== null && s !== void 0 ? s : 0;
      for (; d; ) {
        let v = a.collection.getItem(d);
        if (!v) break;
        if (v.type !== "item") {
          d = a.collection.getKeyAfter(d);
          continue;
        }
        var $;
        if ((($ = v.level) !== null && $ !== void 0 ? $ : 0) <= g) break;
        c = d, d = a.collection.getKeyAfter(d);
      }
    }
    var f;
    r = (f = d ?? c) !== null && f !== void 0 ? f : r;
  }
  return Z(() => new Set([
    l,
    r
  ].filter((d) => d != null)), [
    l,
    r
  ]);
}
const ie = /* @__PURE__ */ U(null), K = /* @__PURE__ */ U(null), Vo = /* @__PURE__ */ W(function(e, a) {
  [e, a] = Y(e, a, ie);
  let t = x(K);
  return t ? /* @__PURE__ */ u.createElement(ne, {
    state: t,
    props: e,
    listBoxRef: a
  }) : /* @__PURE__ */ u.createElement(Le, {
    content: /* @__PURE__ */ u.createElement(we, e)
  }, (i) => /* @__PURE__ */ u.createElement(eo, {
    props: e,
    listBoxRef: a,
    collection: i
  }));
});
function eo({ props: o, listBoxRef: e, collection: a }) {
  o = {
    ...o,
    collection: a,
    children: null,
    items: null
  };
  let { layoutDelegate: t } = x(R), i = Ce({
    ...o,
    layoutDelegate: t
  });
  return /* @__PURE__ */ u.createElement(ne, {
    state: i,
    props: o,
    listBoxRef: e
  });
}
function ne({ state: o, props: e, listBoxRef: a }) {
  [e, a] = Y(e, a, xe);
  let { dragAndDropHooks: t, layout: i = "stack", orientation: l = "vertical", filter: r } = e, n = Oe(o, r), { collection: s, selectionManager: $ } = n, f = !!t?.useDraggableCollectionState, d = !!t?.useDroppableCollectionState, { direction: c } = ze(), { disabledBehavior: g, disabledKeys: v } = $, P = Re({
    usage: "search",
    sensitivity: "base"
  }), { isVirtualized: D, layoutDelegate: b, dropTargetDelegate: B, CollectionRoot: M } = x(R), y = Z(() => e.keyboardDelegate || new he({
    collection: s,
    collator: P,
    ref: a,
    disabledKeys: v,
    disabledBehavior: g,
    layout: i,
    orientation: l,
    direction: c,
    layoutDelegate: b
  }), [
    s,
    P,
    a,
    g,
    v,
    l,
    c,
    e.keyboardDelegate,
    i,
    b
  ]), { listBoxProps: m } = Je({
    ...e,
    shouldSelectOnPressUp: f || e.shouldSelectOnPressUp,
    keyboardDelegate: y,
    isVirtualized: D
  }, n, a), p = A(f), V = A(d);
  ee(() => {
    process.env.NODE_ENV !== "production" && (p.current !== f && console.warn("Drag hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior."), V.current !== d && console.warn("Drop hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior."));
  }, [
    f,
    d
  ]);
  let S, E, F, L = !1, T = null, O = A(null);
  if (f && t) {
    S = t.useDraggableCollectionState({
      collection: s,
      selectionManager: $,
      preview: t.renderDragPreview ? O : void 0
    }), t.useDraggableCollection({}, S, a);
    let z = t.DragPreview;
    T = t.renderDragPreview ? /* @__PURE__ */ u.createElement(z, {
      ref: O
    }, t.renderDragPreview) : null;
  }
  if (d && t) {
    E = t.useDroppableCollectionState({
      collection: s,
      selectionManager: $
    });
    let z = t.dropTargetDelegate || B || new t.ListDropTargetDelegate(s, a, {
      orientation: l,
      layout: i,
      direction: c
    });
    F = t.useDroppableCollection({
      keyboardDelegate: y,
      dropTargetDelegate: z
    }, E, a), L = E.isDropTarget({
      type: "root"
    });
  }
  let { focusProps: _, isFocused: I, isFocusVisible: C } = We(), h = n.collection.size === 0, j = {
    isDropTarget: L,
    isEmpty: h,
    isFocused: I,
    isFocusVisible: C,
    layout: e.layout || "stack",
    state: n
  }, se = N({
    className: e.className,
    style: e.style,
    defaultClassName: "react-aria-ListBox",
    values: j
  }), G = null;
  h && e.renderEmptyState && (G = /* @__PURE__ */ u.createElement("div", {
    // eslint-disable-next-line
    role: "option",
    style: {
      display: "contents"
    }
  }, e.renderEmptyState(j)));
  let ce = k(e, {
    global: !0
  });
  return /* @__PURE__ */ u.createElement(qe, null, /* @__PURE__ */ u.createElement("div", {
    ...w(ce, se, m, _, F?.collectionProps),
    ref: a,
    slot: e.slot || void 0,
    onScroll: e.onScroll,
    "data-drop-target": L || void 0,
    "data-empty": h || void 0,
    "data-focused": I || void 0,
    "data-focus-visible": C || void 0,
    "data-layout": e.layout || "stack",
    "data-orientation": e.orientation || "vertical"
  }, /* @__PURE__ */ u.createElement(X, {
    values: [
      [
        ie,
        e
      ],
      [
        K,
        n
      ],
      [
        H,
        {
          dragAndDropHooks: t,
          dragState: S,
          dropState: E
        }
      ],
      [
        ye,
        {
          elementType: "div"
        }
      ],
      [
        re,
        {
          render: oo
        }
      ],
      [
        be,
        {
          name: "ListBoxSection",
          render: de
        }
      ]
    ]
  }, /* @__PURE__ */ u.createElement(De, null, /* @__PURE__ */ u.createElement(M, {
    collection: s,
    scrollRef: a,
    persistedKeys: Ze($, t, E),
    renderDropIndicator: le(t, E)
  }))), G, T));
}
function de(o, e, a, t = "react-aria-ListBoxSection") {
  let i = x(K), { dragAndDropHooks: l, dropState: r } = x(H), { CollectionBranch: n } = x(R), [s, $] = fe();
  var f;
  let { headingProps: d, groupProps: c } = Xe({
    heading: $,
    "aria-label": (f = o["aria-label"]) !== null && f !== void 0 ? f : void 0
  }), g = N({
    defaultClassName: t,
    className: o.className,
    style: o.style,
    values: {}
  }), v = k(o, {
    global: !0
  });
  return delete v.id, /* @__PURE__ */ u.createElement("section", {
    ...w(v, g, c),
    ref: e
  }, /* @__PURE__ */ u.createElement(me.Provider, {
    value: {
      ...d,
      ref: s
    }
  }, /* @__PURE__ */ u.createElement(n, {
    collection: i.collection,
    parent: a,
    renderDropIndicator: le(l, r)
  })));
}
const To = /* @__PURE__ */ Be(Me, de), Oo = /* @__PURE__ */ Se(Fe, function(e, a, t) {
  let i = te(a), l = x(K), { dragAndDropHooks: r, dragState: n, dropState: s } = x(H), { optionProps: $, labelProps: f, descriptionProps: d, ...c } = Qe({
    key: t.key,
    "aria-label": e?.["aria-label"]
  }, l, i), { hoverProps: g, isHovered: v } = ae({
    isDisabled: !c.allowsSelection && !c.hasAction,
    onHoverStart: t.props.onHoverStart,
    onHoverChange: t.props.onHoverChange,
    onHoverEnd: t.props.onHoverEnd
  }), { focusProps: P } = _e(e), D = null;
  n && r && (D = r.useDraggableItem({
    key: t.key,
    hasAction: c.hasAction
  }, n));
  let b = null;
  s && r && (b = r.useDroppableItem({
    target: {
      type: "item",
      key: t.key,
      dropPosition: "on"
    }
  }, s, i));
  let B = n && n.isDragging(t.key), M = N({
    ...e,
    id: void 0,
    children: e.children,
    defaultClassName: "react-aria-ListBoxItem",
    values: {
      ...c,
      isHovered: v,
      selectionMode: l.selectionManager.selectionMode,
      selectionBehavior: l.selectionManager.selectionBehavior,
      allowsDragging: !!n,
      isDragging: B,
      isDropTarget: b?.isDropTarget
    }
  });
  ee(() => {
    !t.textValue && process.env.NODE_ENV !== "production" && console.warn("A `textValue` prop is required for <ListBoxItem> elements with non-plain text children in order to support accessibility features such as type to select.");
  }, [
    t.textValue
  ]);
  let y = e.href ? "a" : "div", m = k(e, {
    global: !0
  });
  return delete m.id, delete m.onClick, y === "a" && $.tabIndex == null && ($.tabIndex = -1), /* @__PURE__ */ u.createElement(y, {
    ...w(m, M, $, g, P, D?.dragProps, b?.dropProps),
    ref: i,
    "data-allows-dragging": !!n || void 0,
    "data-selected": c.isSelected || void 0,
    "data-disabled": c.isDisabled || void 0,
    "data-hovered": v || void 0,
    "data-focused": c.isFocused || void 0,
    "data-focus-visible": c.isFocusVisible || void 0,
    "data-pressed": c.isPressed || void 0,
    "data-dragging": B || void 0,
    "data-drop-target": b?.isDropTarget || void 0,
    "data-selection-mode": l.selectionManager.selectionMode === "none" ? void 0 : l.selectionManager.selectionMode
  }, /* @__PURE__ */ u.createElement(X, {
    values: [
      [
        Ee,
        {
          slots: {
            [ue]: f,
            label: f,
            description: d
          }
        }
      ],
      [
        Pe,
        {
          isSelected: c.isSelected
        }
      ]
    ]
  }, M.children));
});
function oo(o, e) {
  e = te(e);
  let { dragAndDropHooks: a, dropState: t } = x(H), { dropIndicatorProps: i, isHidden: l, isDropTarget: r } = a.useDropIndicator(o, t, e);
  return l ? null : /* @__PURE__ */ u.createElement(ao, {
    ...o,
    dropIndicatorProps: i,
    isDropTarget: r,
    ref: e
  });
}
function to(o, e) {
  let { dropIndicatorProps: a, isDropTarget: t, ...i } = o, l = N({
    ...i,
    defaultClassName: "react-aria-DropIndicator",
    values: {
      isDropTarget: t
    }
  });
  return /* @__PURE__ */ u.createElement("div", {
    ...a,
    ...l,
    // eslint-disable-next-line
    role: "option",
    ref: e,
    "data-drop-target": t || void 0
  });
}
const ao = /* @__PURE__ */ W(to);
export {
  ie as $,
  K as a,
  Vo as b,
  Oo as c,
  To as d,
  H as e,
  re as f,
  le as g,
  Ze as h,
  ko as i
};
//# sourceMappingURL=ListBox-Bp_3E18l.es.js.map
