import O, { useRef as F, useEffect as j, useMemo as q, createContext as we, isValidElement as Me, cloneElement as Be, useState as re } from "react";
import { a as Fe, d as Pe } from "./utils-oAGBWzI5.es.js";
import { d as ye, $ as Y, a as Te, c as pe, e as Le } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as ue } from "./focusWithoutScrolling-CDw3JYiq.es.js";
import { a as Ee, d as Re } from "./openLink-BNz58j4a.es.js";
import { $ as J } from "./useEvent-CRo5BZDX.es.js";
import { a as Oe, b as Ue, c as he } from "./scrollIntoView-B7D07fJk.es.js";
import { a as ze } from "./FocusScope-CqEZq7sr.es.js";
import { b as ve } from "./useFocusVisible-B3HmFL2Q.es.js";
import { $ as ae } from "./focusSafely-Cwb0Tyy6.es.js";
import { flushSync as Ve } from "react-dom";
import { $ as He } from "./context-DW7UvQ8z.es.js";
import { b as We, g as Ge } from "./platform-Z5fvtFmM.es.js";
import { $ as ke } from "./usePress-BuLomD_X.es.js";
import { $ as qe } from "./useGlobalListeners-BOOfV5Wh.es.js";
import { i as je } from "./CollectionBuilder-BOe312C_.es.js";
import { $ as Ye } from "./useControlledState-u436Wbp1.es.js";
function $e(i, e) {
  const t = F(!0), l = F(null);
  ye(() => (t.current = !0, () => {
    t.current = !1;
  }), []), ye(() => {
    t.current ? t.current = !1 : (!l.current || e.some((n, c) => !Object.is(n, l[c]))) && i(), l.current = e;
  }, e);
}
function G(i) {
  return We() ? i.metaKey : i.ctrlKey;
}
const Ze = /* @__PURE__ */ new Set([
  "checkbox",
  "radio",
  "range",
  "color",
  "file",
  "image",
  "button",
  "submit",
  "reset"
]);
function It(i) {
  return i instanceof HTMLInputElement && !Ze.has(i.type) || i instanceof HTMLTextAreaElement || i instanceof HTMLElement && i.isContentEditable;
}
const Je = "react-aria-clear-focus", Qe = "react-aria-focus", Xe = 500;
function Ne(i) {
  let { isDisabled: e, onLongPressStart: t, onLongPressEnd: l, onLongPress: n, threshold: c = Xe, accessibilityDescription: s } = i;
  const f = F(void 0);
  let { addGlobalListener: a, removeGlobalListener: m } = qe(), { pressProps: D } = ke({
    isDisabled: e,
    onPressStart(y) {
      if (y.continuePropagation(), (y.pointerType === "mouse" || y.pointerType === "touch") && (t && t({
        ...y,
        type: "longpressstart"
      }), f.current = setTimeout(() => {
        y.target.dispatchEvent(new PointerEvent("pointercancel", {
          bubbles: !0
        })), Fe(y.target).activeElement !== y.target && ue(y.target), n && n({
          ...y,
          type: "longpress"
        }), f.current = void 0;
      }, c), y.pointerType === "touch")) {
        let K = (v) => {
          v.preventDefault();
        };
        a(y.target, "contextmenu", K, {
          once: !0
        }), a(window, "pointerup", () => {
          setTimeout(() => {
            m(y.target, "contextmenu", K);
          }, 30);
        }, {
          once: !0
        });
      }
    },
    onPressEnd(y) {
      f.current && clearTimeout(f.current), l && (y.pointerType === "mouse" || y.pointerType === "touch") && l({
        ...y,
        type: "longpressend"
      });
    }
  }), g = Oe(n && !e ? s : void 0);
  return {
    longPressProps: Y(D, g)
  };
}
function De(i) {
  let e = et(Fe(i));
  e !== i && (e && _e(e, i), i && Ie(i, e));
}
function _e(i, e) {
  i.dispatchEvent(new FocusEvent("blur", {
    relatedTarget: e
  })), i.dispatchEvent(new FocusEvent("focusout", {
    bubbles: !0,
    relatedTarget: e
  }));
}
function Ie(i, e) {
  i.dispatchEvent(new FocusEvent("focus", {
    relatedTarget: e
  })), i.dispatchEvent(new FocusEvent("focusin", {
    bubbles: !0,
    relatedTarget: e
  }));
}
function et(i) {
  let e = Pe(i), t = e?.getAttribute("aria-activedescendant");
  return t && i.getElementById(t) || e;
}
function fe(i) {
  return Ge() ? i.altKey : i.ctrlKey;
}
function se(i, e) {
  var t, l;
  let n = `[data-key="${CSS.escape(String(e))}"]`, c = (t = i.current) === null || t === void 0 ? void 0 : t.dataset.collection;
  return c && (n = `[data-collection="${CSS.escape(c)}"]${n}`), (l = i.current) === null || l === void 0 ? void 0 : l.querySelector(n);
}
const Ae = /* @__PURE__ */ new WeakMap();
function tt(i) {
  let e = Te();
  return Ae.set(i, e), e;
}
function lt(i) {
  return Ae.get(i);
}
const it = 1e3;
function nt(i) {
  let { keyboardDelegate: e, selectionManager: t, onTypeSelect: l } = i, n = F({
    search: "",
    timeout: void 0
  }).current, c = (s) => {
    let f = rt(s.key);
    if (!(!f || s.ctrlKey || s.metaKey || !s.currentTarget.contains(s.target) || n.search.length === 0 && f === " ")) {
      if (f === " " && n.search.trim().length > 0 && (s.preventDefault(), "continuePropagation" in s || s.stopPropagation()), n.search += f, e.getKeyForSearch != null) {
        let a = e.getKeyForSearch(n.search, t.focusedKey);
        a == null && (a = e.getKeyForSearch(n.search)), a != null && (t.setFocusedKey(a), l && l(a));
      }
      clearTimeout(n.timeout), n.timeout = setTimeout(() => {
        n.search = "";
      }, it);
    }
  };
  return {
    typeSelectProps: {
      // Using a capturing listener to catch the keydown event before
      // other hooks in order to handle the Spacebar event.
      onKeyDownCapture: e.getKeyForSearch ? c : void 0
    }
  };
}
function rt(i) {
  return i.length === 1 || !/^[A-Z]/i.test(i) ? i : "";
}
function At(i) {
  let { selectionManager: e, keyboardDelegate: t, ref: l, autoFocus: n = !1, shouldFocusWrap: c = !1, disallowEmptySelection: s = !1, disallowSelectAll: f = !1, escapeKeyBehavior: a = "clearSelection", selectOnFocus: m = e.selectionBehavior === "replace", disallowTypeAhead: D = !1, shouldUseVirtualFocus: g, allowsTabNavigation: y = !1, isVirtualized: K, scrollRef: v = l, linkBehavior: I = "action" } = i, { direction: p } = He(), w = Ee(), h = (o) => {
    var d;
    if (o.altKey && o.key === "Tab" && o.preventDefault(), !(!((d = l.current) === null || d === void 0) && d.contains(o.target))) return;
    const b = (u, V) => {
      if (u != null) {
        if (e.isLink(u) && I === "selection" && m && !fe(o)) {
          Ve(() => {
            e.setFocusedKey(u, V);
          });
          let H = se(l, u), de = e.getItemProps(u);
          H && w.open(H, o, de.href, de.routerOptions);
          return;
        }
        if (e.setFocusedKey(u, V), e.isLink(u) && I === "override") return;
        o.shiftKey && e.selectionMode === "multiple" ? e.extendSelection(u) : m && !fe(o) && e.replaceSelection(u);
      }
    };
    switch (o.key) {
      case "ArrowDown":
        if (t.getKeyBelow) {
          var r, x, E;
          let u = e.focusedKey != null ? (r = t.getKeyBelow) === null || r === void 0 ? void 0 : r.call(t, e.focusedKey) : (x = t.getFirstKey) === null || x === void 0 ? void 0 : x.call(t);
          u == null && c && (u = (E = t.getFirstKey) === null || E === void 0 ? void 0 : E.call(t, e.focusedKey)), u != null && (o.preventDefault(), b(u));
        }
        break;
      case "ArrowUp":
        if (t.getKeyAbove) {
          var B, U, N;
          let u = e.focusedKey != null ? (B = t.getKeyAbove) === null || B === void 0 ? void 0 : B.call(t, e.focusedKey) : (U = t.getLastKey) === null || U === void 0 ? void 0 : U.call(t);
          u == null && c && (u = (N = t.getLastKey) === null || N === void 0 ? void 0 : N.call(t, e.focusedKey)), u != null && (o.preventDefault(), b(u));
        }
        break;
      case "ArrowLeft":
        if (t.getKeyLeftOf) {
          var _, ee, te;
          let u = e.focusedKey != null ? (_ = t.getKeyLeftOf) === null || _ === void 0 ? void 0 : _.call(t, e.focusedKey) : null;
          u == null && c && (u = p === "rtl" ? (ee = t.getFirstKey) === null || ee === void 0 ? void 0 : ee.call(t, e.focusedKey) : (te = t.getLastKey) === null || te === void 0 ? void 0 : te.call(t, e.focusedKey)), u != null && (o.preventDefault(), b(u, p === "rtl" ? "first" : "last"));
        }
        break;
      case "ArrowRight":
        if (t.getKeyRightOf) {
          var le, ie, ne;
          let u = e.focusedKey != null ? (le = t.getKeyRightOf) === null || le === void 0 ? void 0 : le.call(t, e.focusedKey) : null;
          u == null && c && (u = p === "rtl" ? (ie = t.getLastKey) === null || ie === void 0 ? void 0 : ie.call(t, e.focusedKey) : (ne = t.getFirstKey) === null || ne === void 0 ? void 0 : ne.call(t, e.focusedKey)), u != null && (o.preventDefault(), b(u, p === "rtl" ? "last" : "first"));
        }
        break;
      case "Home":
        if (t.getFirstKey) {
          if (e.focusedKey === null && o.shiftKey) return;
          o.preventDefault();
          let u = t.getFirstKey(e.focusedKey, G(o));
          e.setFocusedKey(u), u != null && (G(o) && o.shiftKey && e.selectionMode === "multiple" ? e.extendSelection(u) : m && e.replaceSelection(u));
        }
        break;
      case "End":
        if (t.getLastKey) {
          if (e.focusedKey === null && o.shiftKey) return;
          o.preventDefault();
          let u = t.getLastKey(e.focusedKey, G(o));
          e.setFocusedKey(u), u != null && (G(o) && o.shiftKey && e.selectionMode === "multiple" ? e.extendSelection(u) : m && e.replaceSelection(u));
        }
        break;
      case "PageDown":
        if (t.getKeyPageBelow && e.focusedKey != null) {
          let u = t.getKeyPageBelow(e.focusedKey);
          u != null && (o.preventDefault(), b(u));
        }
        break;
      case "PageUp":
        if (t.getKeyPageAbove && e.focusedKey != null) {
          let u = t.getKeyPageAbove(e.focusedKey);
          u != null && (o.preventDefault(), b(u));
        }
        break;
      case "a":
        G(o) && e.selectionMode === "multiple" && f !== !0 && (o.preventDefault(), e.selectAll());
        break;
      case "Escape":
        a === "clearSelection" && !s && e.selectedKeys.size !== 0 && (o.stopPropagation(), o.preventDefault(), e.clearSelection());
        break;
      case "Tab":
        if (!y) {
          if (o.shiftKey) l.current.focus();
          else {
            let u = ze(l.current, {
              tabbable: !0
            }), V, H;
            do
              H = u.lastChild(), H && (V = H);
            while (H);
            V && !V.contains(document.activeElement) && ue(V);
          }
          break;
        }
    }
  }, $ = F({
    top: 0,
    left: 0
  });
  J(v, "scroll", K ? void 0 : () => {
    var o, d, b, r;
    $.current = {
      top: (b = (o = v.current) === null || o === void 0 ? void 0 : o.scrollTop) !== null && b !== void 0 ? b : 0,
      left: (r = (d = v.current) === null || d === void 0 ? void 0 : d.scrollLeft) !== null && r !== void 0 ? r : 0
    };
  });
  let S = (o) => {
    if (e.isFocused) {
      o.currentTarget.contains(o.target) || e.setFocused(!1);
      return;
    }
    if (o.currentTarget.contains(o.target)) {
      if (e.setFocused(!0), e.focusedKey == null) {
        var d, b;
        let E = (U) => {
          U != null && (e.setFocusedKey(U), m && !e.isSelected(U) && e.replaceSelection(U));
        }, B = o.relatedTarget;
        var r, x;
        B && o.currentTarget.compareDocumentPosition(B) & Node.DOCUMENT_POSITION_FOLLOWING ? E((r = e.lastSelectedKey) !== null && r !== void 0 ? r : (d = t.getLastKey) === null || d === void 0 ? void 0 : d.call(t)) : E((x = e.firstSelectedKey) !== null && x !== void 0 ? x : (b = t.getFirstKey) === null || b === void 0 ? void 0 : b.call(t));
      } else !K && v.current && (v.current.scrollTop = $.current.top, v.current.scrollLeft = $.current.left);
      if (e.focusedKey != null && v.current) {
        let E = se(l, e.focusedKey);
        E instanceof HTMLElement && (!E.contains(document.activeElement) && !g && ue(E), ve() === "keyboard" && he(E, {
          containingElement: l.current
        }));
      }
    }
  }, L = (o) => {
    o.currentTarget.contains(o.relatedTarget) || e.setFocused(!1);
  }, k = F(!1);
  J(l, Qe, g ? (o) => {
    let { detail: d } = o;
    o.stopPropagation(), e.setFocused(!0), d?.focusStrategy === "first" && (k.current = !0);
  } : void 0);
  let C = pe(() => {
    var o, d;
    let b = (d = (o = t.getFirstKey) === null || o === void 0 ? void 0 : o.call(t)) !== null && d !== void 0 ? d : null;
    if (b == null) {
      let r = Pe();
      De(l.current), Ie(r, null), e.collection.size > 0 && (k.current = !1);
    } else
      e.setFocusedKey(b), k.current = !1;
  });
  $e(() => {
    k.current && C();
  }, [
    e.collection,
    C
  ]);
  let T = pe(() => {
    e.collection.size > 0 && (k.current = !1);
  });
  $e(() => {
    T();
  }, [
    e.focusedKey,
    T
  ]), J(l, Je, g ? (o) => {
    var d;
    o.stopPropagation(), e.setFocused(!1), !((d = o.detail) === null || d === void 0) && d.clearFocusKey && e.setFocusedKey(null);
  } : void 0);
  const W = F(n), z = F(!1);
  j(() => {
    if (W.current) {
      var o, d;
      let x = null;
      var b;
      n === "first" && (x = (b = (o = t.getFirstKey) === null || o === void 0 ? void 0 : o.call(t)) !== null && b !== void 0 ? b : null);
      var r;
      n === "last" && (x = (r = (d = t.getLastKey) === null || d === void 0 ? void 0 : d.call(t)) !== null && r !== void 0 ? r : null);
      let E = e.selectedKeys;
      if (E.size) {
        for (let B of E) if (e.canSelectItem(B)) {
          x = B;
          break;
        }
      }
      e.setFocused(!0), e.setFocusedKey(x), x == null && !g && l.current && ae(l.current), e.collection.size > 0 && (W.current = !1, z.current = !0);
    }
  });
  let R = F(e.focusedKey), M = F(null);
  j(() => {
    if (e.isFocused && e.focusedKey != null && (e.focusedKey !== R.current || z.current) && v.current && l.current) {
      let o = ve(), d = se(l, e.focusedKey);
      if (!(d instanceof HTMLElement))
        return;
      (o === "keyboard" || z.current) && (M.current && cancelAnimationFrame(M.current), M.current = requestAnimationFrame(() => {
        v.current && (Ue(v.current, d), o !== "virtual" && he(d, {
          containingElement: l.current
        }));
      }));
    }
    !g && e.isFocused && e.focusedKey == null && R.current != null && l.current && ae(l.current), R.current = e.focusedKey, z.current = !1;
  }), j(() => () => {
    M.current && cancelAnimationFrame(M.current);
  }, []), J(l, "react-aria-focus-scope-restore", (o) => {
    o.preventDefault(), e.setFocused(!0);
  });
  let P = {
    onKeyDown: h,
    onFocus: S,
    onBlur: L,
    onMouseDown(o) {
      v.current === o.target && o.preventDefault();
    }
  }, { typeSelectProps: Q } = nt({
    keyboardDelegate: t,
    selectionManager: e
  });
  D || (P = Y(Q, P));
  let Z;
  g || (Z = e.focusedKey == null ? 0 : -1);
  let X = tt(e.collection);
  return {
    collectionProps: Y(P, {
      tabIndex: Z,
      "data-collection": X
    })
  };
}
function Ct(i) {
  let { id: e, selectionManager: t, key: l, ref: n, shouldSelectOnPressUp: c, shouldUseVirtualFocus: s, focus: f, isDisabled: a, onAction: m, allowsDifferentPressOrigin: D, linkBehavior: g = "action" } = i, y = Ee();
  e = Te(e);
  let K = (r) => {
    if (r.pointerType === "keyboard" && fe(r)) t.toggleSelection(l);
    else {
      if (t.selectionMode === "none") return;
      if (t.isLink(l)) {
        if (g === "selection" && n.current) {
          let x = t.getItemProps(l);
          y.open(n.current, r, x.href, x.routerOptions), t.setSelectedKeys(t.selectedKeys);
          return;
        } else if (g === "override" || g === "none") return;
      }
      t.selectionMode === "single" ? t.isSelected(l) && !t.disallowEmptySelection ? t.toggleSelection(l) : t.replaceSelection(l) : r && r.shiftKey ? t.extendSelection(l) : t.selectionBehavior === "toggle" || r && (G(r) || r.pointerType === "touch" || r.pointerType === "virtual") ? t.toggleSelection(l) : t.replaceSelection(l);
    }
  };
  j(() => {
    l === t.focusedKey && t.isFocused && (s ? De(n.current) : f ? f() : document.activeElement !== n.current && n.current && ae(n.current));
  }, [
    n,
    l,
    t.focusedKey,
    t.childFocusStrategy,
    t.isFocused,
    s
  ]), a = a || t.isDisabled(l);
  let v = {};
  !s && !a ? v = {
    tabIndex: l === t.focusedKey ? 0 : -1,
    onFocus(r) {
      r.target === n.current && t.setFocusedKey(l);
    }
  } : a && (v.onMouseDown = (r) => {
    r.preventDefault();
  });
  let I = t.isLink(l) && g === "override", p = m && i.UNSTABLE_itemBehavior === "action", w = t.isLink(l) && g !== "selection" && g !== "none", h = !a && t.canSelectItem(l) && !I && !p, $ = (m || w) && !a, S = $ && (t.selectionBehavior === "replace" ? !h : !h || t.isEmpty), L = $ && h && t.selectionBehavior === "replace", k = S || L, C = F(null), T = k && h, W = F(!1), z = F(!1), R = t.getItemProps(l), M = (r) => {
    if (m) {
      var x;
      m(), (x = n.current) === null || x === void 0 || x.dispatchEvent(new CustomEvent("react-aria-item-action", {
        bubbles: !0
      }));
    }
    w && n.current && y.open(n.current, r, R.href, R.routerOptions);
  }, P = {
    ref: n
  };
  if (c ? (P.onPressStart = (r) => {
    C.current = r.pointerType, W.current = T, r.pointerType === "keyboard" && (!k || me()) && K(r);
  }, D ? (P.onPressUp = S ? void 0 : (r) => {
    r.pointerType === "mouse" && h && K(r);
  }, P.onPress = S ? M : (r) => {
    r.pointerType !== "keyboard" && r.pointerType !== "mouse" && h && K(r);
  }) : P.onPress = (r) => {
    if (S || L && r.pointerType !== "mouse") {
      if (r.pointerType === "keyboard" && !be()) return;
      M(r);
    } else r.pointerType !== "keyboard" && h && K(r);
  }) : (P.onPressStart = (r) => {
    C.current = r.pointerType, W.current = T, z.current = S, h && (r.pointerType === "mouse" && !S || r.pointerType === "keyboard" && (!$ || me())) && K(r);
  }, P.onPress = (r) => {
    (r.pointerType === "touch" || r.pointerType === "pen" || r.pointerType === "virtual" || r.pointerType === "keyboard" && k && be() || r.pointerType === "mouse" && z.current) && (k ? M(r) : h && K(r));
  }), v["data-collection"] = lt(t.collection), v["data-key"] = l, P.preventFocusOnPress = s, s && (P = Y(P, {
    onPressStart(r) {
      r.pointerType !== "touch" && (t.setFocused(!0), t.setFocusedKey(l));
    },
    onPress(r) {
      r.pointerType === "touch" && (t.setFocused(!0), t.setFocusedKey(l));
    }
  })), R)
    for (let r of [
      "onPressStart",
      "onPressEnd",
      "onPressChange",
      "onPress",
      "onPressUp",
      "onClick"
    ]) R[r] && (P[r] = Le(P[r], R[r]));
  let { pressProps: Q, isPressed: Z } = ke(P), X = L ? (r) => {
    C.current === "mouse" && (r.stopPropagation(), r.preventDefault(), M(r));
  } : void 0, { longPressProps: o } = Ne({
    isDisabled: !T,
    onLongPress(r) {
      r.pointerType === "touch" && (K(r), t.setSelectionBehavior("toggle"));
    }
  }), d = (r) => {
    C.current === "touch" && W.current && r.preventDefault();
  }, b = g !== "none" && t.isLink(l) ? (r) => {
    Re.isOpening || r.preventDefault();
  } : void 0;
  return {
    itemProps: Y(
      v,
      h || S || s && !a ? Q : {},
      T ? o : {},
      {
        onDoubleClick: X,
        onDragStartCapture: d,
        onClick: b,
        id: e
      },
      // Prevent DOM focus from moving on mouse down when using virtual focus
      s ? {
        onMouseDown: (r) => r.preventDefault()
      } : void 0
    ),
    isPressed: Z,
    isSelected: t.isSelected(l),
    isFocused: t.isFocused && t.focusedKey === l,
    isDisabled: a,
    allowsSelection: h,
    hasAction: k
  };
}
function be() {
  let i = window.event;
  return i?.key === "Enter";
}
function me() {
  let i = window.event;
  return i?.key === " " || i?.code === "Space";
}
class st {
  build(e, t) {
    return this.context = t, ge(() => this.iterateCollection(e));
  }
  *iterateCollection(e) {
    let { children: t, items: l } = e;
    if (O.isValidElement(t) && t.type === O.Fragment) yield* this.iterateCollection({
      children: t.props.children,
      items: l
    });
    else if (typeof t == "function") {
      if (!l) throw new Error("props.children was a function but props.items is missing");
      let n = 0;
      for (let c of l)
        yield* this.getFullNode({
          value: c,
          index: n
        }, {
          renderer: t
        }), n++;
    } else {
      let n = [];
      O.Children.forEach(t, (s) => {
        s && n.push(s);
      });
      let c = 0;
      for (let s of n) {
        let f = this.getFullNode({
          element: s,
          index: c
        }, {});
        for (let a of f)
          c++, yield a;
      }
    }
  }
  getKey(e, t, l, n) {
    if (e.key != null) return e.key;
    if (t.type === "cell" && t.key != null) return `${n}${t.key}`;
    let c = t.value;
    if (c != null) {
      var s;
      let f = (s = c.key) !== null && s !== void 0 ? s : c.id;
      if (f == null) throw new Error("No key found for item");
      return f;
    }
    return n ? `${n}.${t.index}` : `$.${t.index}`;
  }
  getChildState(e, t) {
    return {
      renderer: t.renderer || e.renderer
    };
  }
  *getFullNode(e, t, l, n) {
    if (O.isValidElement(e.element) && e.element.type === O.Fragment) {
      let p = [];
      O.Children.forEach(e.element.props.children, (h) => {
        p.push(h);
      });
      var c;
      let w = (c = e.index) !== null && c !== void 0 ? c : 0;
      for (const h of p) yield* this.getFullNode({
        element: h,
        index: w++
      }, t, l, n);
      return;
    }
    let s = e.element;
    if (!s && e.value && t && t.renderer) {
      let p = this.cache.get(e.value);
      if (p && (!p.shouldInvalidate || !p.shouldInvalidate(this.context))) {
        p.index = e.index, p.parentKey = n ? n.key : null, yield p;
        return;
      }
      s = t.renderer(e.value);
    }
    if (O.isValidElement(s)) {
      let p = s.type;
      if (typeof p != "function" && typeof p.getCollectionNode != "function") {
        let S = s.type;
        throw new Error(`Unknown element <${S}> in collection.`);
      }
      let w = p.getCollectionNode(s.props, this.context);
      var f;
      let h = (f = e.index) !== null && f !== void 0 ? f : 0, $ = w.next();
      for (; !$.done && $.value; ) {
        let S = $.value;
        e.index = h;
        var a;
        let L = (a = S.key) !== null && a !== void 0 ? a : null;
        L == null && (L = S.element ? null : this.getKey(s, e, t, l));
        let C = [
          ...this.getFullNode({
            ...S,
            key: L,
            index: h,
            wrapper: ot(e.wrapper, S.wrapper)
          }, this.getChildState(t, S), l ? `${l}${s.key}` : s.key, n)
        ];
        for (let T of C) {
          var m, D;
          T.value = (D = (m = S.value) !== null && m !== void 0 ? m : e.value) !== null && D !== void 0 ? D : null, T.value && this.cache.set(T.value, T);
          var g;
          if (e.type && T.type !== e.type) throw new Error(`Unsupported type <${oe(T.type)}> in <${oe((g = n?.type) !== null && g !== void 0 ? g : "unknown parent type")}>. Only <${oe(e.type)}> is supported.`);
          h++, yield T;
        }
        $ = w.next(C);
      }
      return;
    }
    if (e.key == null || e.type == null) return;
    let y = this;
    var K, v;
    let I = {
      type: e.type,
      props: e.props,
      key: e.key,
      parentKey: n ? n.key : null,
      value: (K = e.value) !== null && K !== void 0 ? K : null,
      level: n ? n.level + 1 : 0,
      index: e.index,
      rendered: e.rendered,
      textValue: (v = e.textValue) !== null && v !== void 0 ? v : "",
      "aria-label": e["aria-label"],
      wrapper: e.wrapper,
      shouldInvalidate: e.shouldInvalidate,
      hasChildNodes: e.hasChildNodes || !1,
      childNodes: ge(function* () {
        if (!e.hasChildNodes || !e.childNodes) return;
        let p = 0;
        for (let w of e.childNodes()) {
          w.key != null && (w.key = `${I.key}${w.key}`);
          let h = y.getFullNode({
            ...w,
            index: p
          }, y.getChildState(t, w), I.key, I);
          for (let $ of h)
            p++, yield $;
        }
      })
    };
    yield I;
  }
  constructor() {
    this.cache = /* @__PURE__ */ new WeakMap();
  }
}
function ge(i) {
  let e = [], t = null;
  return {
    *[Symbol.iterator]() {
      for (let l of e) yield l;
      t || (t = i());
      for (let l of t)
        e.push(l), yield l;
    }
  };
}
function ot(i, e) {
  if (i && e) return (t) => i(e(t));
  if (i) return i;
  if (e) return e;
}
function oe(i) {
  return i[0].toUpperCase() + i.slice(1);
}
function Mt(i, e, t) {
  let l = q(() => new st(), []), { children: n, items: c, collection: s } = i;
  return q(() => {
    if (s) return s;
    let a = l.build({
      children: n,
      items: c
    }, t);
    return e(a);
  }, [
    l,
    n,
    c,
    s,
    t,
    e
  ]);
}
function ct(i, e) {
  return typeof e.getChildren == "function" ? e.getChildren(i.key) : i.childNodes;
}
function ut(i) {
  return at(i, 0);
}
function at(i, e) {
  if (e < 0) return;
  let t = 0;
  for (let l of i) {
    if (t === e) return l;
    t++;
  }
}
function Bt(i) {
  let e;
  for (let t of i) e = t;
  return e;
}
function ce(i, e, t) {
  if (e.parentKey === t.parentKey) return e.index - t.index;
  let l = [
    ...Ke(i, e),
    e
  ], n = [
    ...Ke(i, t),
    t
  ], c = l.slice(0, n.length).findIndex((s, f) => s !== n[f]);
  return c !== -1 ? (e = l[c], t = n[c], e.index - t.index) : l.findIndex((s) => s === t) >= 0 ? 1 : (n.findIndex((s) => s === e) >= 0, -1);
}
function Ke(i, e) {
  let t = [], l = e;
  for (; l?.parentKey != null; )
    l = i.getItem(l.parentKey), l && t.unshift(l);
  return t;
}
const Lt = /* @__PURE__ */ we(null), ft = {
  CollectionRoot({ collection: i, renderDropIndicator: e }) {
    return Se(i, null, e);
  },
  CollectionBranch({ collection: i, parent: e, renderDropIndicator: t }) {
    return Se(i, e, t);
  }
};
function Se(i, e, t) {
  return je({
    items: e ? i.getChildren(e.key) : i,
    dependencies: [
      t
    ],
    children(l) {
      let n = l.render(l);
      return !t || l.type !== "item" ? n : /* @__PURE__ */ O.createElement(O.Fragment, null, t({
        type: "item",
        key: l.key,
        dropPosition: "before"
      }), n, dt(i, l, t));
    }
  });
}
function dt(i, e, t) {
  let l = e.key, n = i.getKeyAfter(l), c = n != null ? i.getItem(n) : null;
  for (; c != null && c.type !== "item"; )
    n = i.getKeyAfter(c.key), c = n != null ? i.getItem(n) : null;
  let s = e.nextKey != null ? i.getItem(e.nextKey) : null;
  for (; s != null && s.type !== "item"; ) s = s.nextKey != null ? i.getItem(s.nextKey) : null;
  let f = [];
  if (s == null) {
    let a = e;
    for (; a && (!c || a.parentKey !== c.parentKey && c.level < a.level); ) {
      let m = t({
        type: "item",
        key: a.key,
        dropPosition: "after"
      });
      /* @__PURE__ */ Me(m) && f.push(/* @__PURE__ */ Be(m, {
        key: `${a.key}-after`
      })), a = a.parentKey != null ? i.getItem(a.parentKey) : null;
    }
  }
  return f;
}
const Rt = /* @__PURE__ */ we(ft);
function Ot(i) {
  return q(() => i != null ? /* @__PURE__ */ new Set([
    i
  ]) : null, [
    i
  ]);
}
class A extends Set {
  constructor(e, t, l) {
    super(e), e instanceof A ? (this.anchorKey = t ?? e.anchorKey, this.currentKey = l ?? e.currentKey) : (this.anchorKey = t ?? null, this.currentKey = l ?? null);
  }
}
function yt(i, e) {
  if (i.size !== e.size) return !1;
  for (let t of i)
    if (!e.has(t)) return !1;
  return !0;
}
function Ut(i) {
  let { selectionMode: e = "none", disallowEmptySelection: t = !1, allowDuplicateSelectionEvents: l, selectionBehavior: n = "toggle", disabledBehavior: c = "all" } = i, s = F(!1), [, f] = re(!1), a = F(null), m = F(null), [, D] = re(null), g = q(() => xe(i.selectedKeys), [
    i.selectedKeys
  ]), y = q(() => xe(i.defaultSelectedKeys, new A()), [
    i.defaultSelectedKeys
  ]), [K, v] = Ye(g, y, i.onSelectionChange), I = q(() => i.disabledKeys ? new Set(i.disabledKeys) : /* @__PURE__ */ new Set(), [
    i.disabledKeys
  ]), [p, w] = re(n);
  n === "replace" && p === "toggle" && typeof K == "object" && K.size === 0 && w("replace");
  let h = F(n);
  return j(() => {
    n !== h.current && (w(n), h.current = n);
  }, [
    n
  ]), {
    selectionMode: e,
    disallowEmptySelection: t,
    selectionBehavior: p,
    setSelectionBehavior: w,
    get isFocused() {
      return s.current;
    },
    setFocused($) {
      s.current = $, f($);
    },
    get focusedKey() {
      return a.current;
    },
    get childFocusStrategy() {
      return m.current;
    },
    setFocusedKey($, S = "first") {
      a.current = $, m.current = S, D($);
    },
    selectedKeys: K,
    setSelectedKeys($) {
      (l || !yt($, K)) && v($);
    },
    disabledKeys: I,
    disabledBehavior: c
  };
}
function xe(i, e) {
  return i ? i === "all" ? "all" : new A(i) : e;
}
class Ce {
  /**
  * The type of selection that is allowed in the collection.
  */
  get selectionMode() {
    return this.state.selectionMode;
  }
  /**
  * Whether the collection allows empty selection.
  */
  get disallowEmptySelection() {
    return this.state.disallowEmptySelection;
  }
  /**
  * The selection behavior for the collection.
  */
  get selectionBehavior() {
    return this.state.selectionBehavior;
  }
  /**
  * Sets the selection behavior for the collection.
  */
  setSelectionBehavior(e) {
    this.state.setSelectionBehavior(e);
  }
  /**
  * Whether the collection is currently focused.
  */
  get isFocused() {
    return this.state.isFocused;
  }
  /**
  * Sets whether the collection is focused.
  */
  setFocused(e) {
    this.state.setFocused(e);
  }
  /**
  * The current focused key in the collection.
  */
  get focusedKey() {
    return this.state.focusedKey;
  }
  /** Whether the first or last child of the focused key should receive focus. */
  get childFocusStrategy() {
    return this.state.childFocusStrategy;
  }
  /**
  * Sets the focused key.
  */
  setFocusedKey(e, t) {
    (e == null || this.collection.getItem(e)) && this.state.setFocusedKey(e, t);
  }
  /**
  * The currently selected keys in the collection.
  */
  get selectedKeys() {
    return this.state.selectedKeys === "all" ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
  }
  /**
  * The raw selection value for the collection.
  * Either 'all' for select all, or a set of keys.
  */
  get rawSelection() {
    return this.state.selectedKeys;
  }
  /**
  * Returns whether a key is selected.
  */
  isSelected(e) {
    if (this.state.selectionMode === "none") return !1;
    let t = this.getKey(e);
    return t == null ? !1 : this.state.selectedKeys === "all" ? this.canSelectItem(t) : this.state.selectedKeys.has(t);
  }
  /**
  * Whether the selection is empty.
  */
  get isEmpty() {
    return this.state.selectedKeys !== "all" && this.state.selectedKeys.size === 0;
  }
  /**
  * Whether all items in the collection are selected.
  */
  get isSelectAll() {
    if (this.isEmpty) return !1;
    if (this.state.selectedKeys === "all") return !0;
    if (this._isSelectAll != null) return this._isSelectAll;
    let e = this.getSelectAllKeys(), t = this.state.selectedKeys;
    return this._isSelectAll = e.every((l) => t.has(l)), this._isSelectAll;
  }
  get firstSelectedKey() {
    let e = null;
    for (let l of this.state.selectedKeys) {
      let n = this.collection.getItem(l);
      (!e || n && ce(this.collection, n, e) < 0) && (e = n);
    }
    var t;
    return (t = e?.key) !== null && t !== void 0 ? t : null;
  }
  get lastSelectedKey() {
    let e = null;
    for (let l of this.state.selectedKeys) {
      let n = this.collection.getItem(l);
      (!e || n && ce(this.collection, n, e) > 0) && (e = n);
    }
    var t;
    return (t = e?.key) !== null && t !== void 0 ? t : null;
  }
  get disabledKeys() {
    return this.state.disabledKeys;
  }
  get disabledBehavior() {
    return this.state.disabledBehavior;
  }
  /**
  * Extends the selection to the given key.
  */
  extendSelection(e) {
    if (this.selectionMode === "none") return;
    if (this.selectionMode === "single") {
      this.replaceSelection(e);
      return;
    }
    let t = this.getKey(e);
    if (t == null) return;
    let l;
    if (this.state.selectedKeys === "all") l = new A([
      t
    ], t, t);
    else {
      let s = this.state.selectedKeys;
      var n;
      let f = (n = s.anchorKey) !== null && n !== void 0 ? n : t;
      l = new A(s, f, t);
      var c;
      for (let a of this.getKeyRange(f, (c = s.currentKey) !== null && c !== void 0 ? c : t)) l.delete(a);
      for (let a of this.getKeyRange(t, f)) this.canSelectItem(a) && l.add(a);
    }
    this.state.setSelectedKeys(l);
  }
  getKeyRange(e, t) {
    let l = this.collection.getItem(e), n = this.collection.getItem(t);
    return l && n ? ce(this.collection, l, n) <= 0 ? this.getKeyRangeInternal(e, t) : this.getKeyRangeInternal(t, e) : [];
  }
  getKeyRangeInternal(e, t) {
    var l;
    if (!((l = this.layoutDelegate) === null || l === void 0) && l.getKeyRange) return this.layoutDelegate.getKeyRange(e, t);
    let n = [], c = e;
    for (; c != null; ) {
      let s = this.collection.getItem(c);
      if (s && (s.type === "item" || s.type === "cell" && this.allowsCellSelection) && n.push(c), c === t) return n;
      c = this.collection.getKeyAfter(c);
    }
    return [];
  }
  getKey(e) {
    let t = this.collection.getItem(e);
    if (!t || t.type === "cell" && this.allowsCellSelection) return e;
    for (; t && t.type !== "item" && t.parentKey != null; ) t = this.collection.getItem(t.parentKey);
    return !t || t.type !== "item" ? null : t.key;
  }
  /**
  * Toggles whether the given key is selected.
  */
  toggleSelection(e) {
    if (this.selectionMode === "none") return;
    if (this.selectionMode === "single" && !this.isSelected(e)) {
      this.replaceSelection(e);
      return;
    }
    let t = this.getKey(e);
    if (t == null) return;
    let l = new A(this.state.selectedKeys === "all" ? this.getSelectAllKeys() : this.state.selectedKeys);
    l.has(t) ? l.delete(t) : this.canSelectItem(t) && (l.add(t), l.anchorKey = t, l.currentKey = t), !(this.disallowEmptySelection && l.size === 0) && this.state.setSelectedKeys(l);
  }
  /**
  * Replaces the selection with only the given key.
  */
  replaceSelection(e) {
    if (this.selectionMode === "none") return;
    let t = this.getKey(e);
    if (t == null) return;
    let l = this.canSelectItem(t) ? new A([
      t
    ], t, t) : new A();
    this.state.setSelectedKeys(l);
  }
  /**
  * Replaces the selection with the given keys.
  */
  setSelectedKeys(e) {
    if (this.selectionMode === "none") return;
    let t = new A();
    for (let l of e) {
      let n = this.getKey(l);
      if (n != null && (t.add(n), this.selectionMode === "single"))
        break;
    }
    this.state.setSelectedKeys(t);
  }
  getSelectAllKeys() {
    let e = [], t = (l) => {
      for (; l != null; ) {
        if (this.canSelectItem(l)) {
          var n;
          let s = this.collection.getItem(l);
          s?.type === "item" && e.push(l);
          var c;
          s?.hasChildNodes && (this.allowsCellSelection || s.type !== "item") && t((c = (n = ut(ct(s, this.collection))) === null || n === void 0 ? void 0 : n.key) !== null && c !== void 0 ? c : null);
        }
        l = this.collection.getKeyAfter(l);
      }
    };
    return t(this.collection.getFirstKey()), e;
  }
  /**
  * Selects all items in the collection.
  */
  selectAll() {
    !this.isSelectAll && this.selectionMode === "multiple" && this.state.setSelectedKeys("all");
  }
  /**
  * Removes all keys from the selection.
  */
  clearSelection() {
    !this.disallowEmptySelection && (this.state.selectedKeys === "all" || this.state.selectedKeys.size > 0) && this.state.setSelectedKeys(new A());
  }
  /**
  * Toggles between select all and an empty selection.
  */
  toggleSelectAll() {
    this.isSelectAll ? this.clearSelection() : this.selectAll();
  }
  select(e, t) {
    this.selectionMode !== "none" && (this.selectionMode === "single" ? this.isSelected(e) && !this.disallowEmptySelection ? this.toggleSelection(e) : this.replaceSelection(e) : this.selectionBehavior === "toggle" || t && (t.pointerType === "touch" || t.pointerType === "virtual") ? this.toggleSelection(e) : this.replaceSelection(e));
  }
  /**
  * Returns whether the current selection is equal to the given selection.
  */
  isSelectionEqual(e) {
    if (e === this.state.selectedKeys) return !0;
    let t = this.selectedKeys;
    if (e.size !== t.size) return !1;
    for (let l of e)
      if (!t.has(l)) return !1;
    for (let l of t)
      if (!e.has(l)) return !1;
    return !0;
  }
  canSelectItem(e) {
    var t;
    if (this.state.selectionMode === "none" || this.state.disabledKeys.has(e)) return !1;
    let l = this.collection.getItem(e);
    return !(!l || !(l == null || (t = l.props) === null || t === void 0) && t.isDisabled || l.type === "cell" && !this.allowsCellSelection);
  }
  isDisabled(e) {
    var t, l;
    return this.state.disabledBehavior === "all" && (this.state.disabledKeys.has(e) || !!(!((l = this.collection.getItem(e)) === null || l === void 0 || (t = l.props) === null || t === void 0) && t.isDisabled));
  }
  isLink(e) {
    var t, l;
    return !!(!((l = this.collection.getItem(e)) === null || l === void 0 || (t = l.props) === null || t === void 0) && t.href);
  }
  getItemProps(e) {
    var t;
    return (t = this.collection.getItem(e)) === null || t === void 0 ? void 0 : t.props;
  }
  withCollection(e) {
    return new Ce(e, this.state, {
      allowsCellSelection: this.allowsCellSelection,
      layoutDelegate: this.layoutDelegate || void 0
    });
  }
  constructor(e, t, l) {
    this.collection = e, this.state = t;
    var n;
    this.allowsCellSelection = (n = l?.allowsCellSelection) !== null && n !== void 0 ? n : !1, this._isSelectAll = null, this.layoutDelegate = l?.layoutDelegate || null;
  }
}
export {
  Ut as $,
  Mt as a,
  Ce as b,
  It as c,
  se as d,
  At as e,
  ct as f,
  Ct as g,
  Rt as h,
  Lt as i,
  ft as j,
  Ot as k,
  nt as l,
  Bt as m,
  ut as n,
  at as o,
  Ne as p
};
//# sourceMappingURL=SelectionManager-CX9btso_.es.js.map
