import { d as f, e as y, f as b } from "./SelectionManager-GNsyMc-q.es.js";
import { $ as h } from "./scrollIntoView-Btu7DgIo.es.js";
import { $ as m } from "./useCollator-DKdD8vEj.es.js";
import K, { useMemo as x, createContext as $ } from "react";
import { $ as v } from "./utils-CrjF8U_E.es.js";
import { $ as D, b as p } from "./CollectionBuilder-CTjJUDzO.es.js";
class c {
  getItemRect(e) {
    let t = this.ref.current;
    if (!t) return null;
    let i = e != null ? f(this.ref, e) : null;
    if (!i) return null;
    let l = t.getBoundingClientRect(), o = i.getBoundingClientRect();
    return {
      x: o.left - l.left - t.clientLeft + t.scrollLeft,
      y: o.top - l.top - t.clientTop + t.scrollTop,
      width: o.width,
      height: o.height
    };
  }
  getContentSize() {
    let e = this.ref.current;
    var t, i;
    return {
      width: (t = e?.scrollWidth) !== null && t !== void 0 ? t : 0,
      height: (i = e?.scrollHeight) !== null && i !== void 0 ? i : 0
    };
  }
  getVisibleRect() {
    let e = this.ref.current;
    var t, i, l, o;
    return {
      x: (t = e?.scrollLeft) !== null && t !== void 0 ? t : 0,
      y: (i = e?.scrollTop) !== null && i !== void 0 ? i : 0,
      width: (l = e?.clientWidth) !== null && l !== void 0 ? l : 0,
      height: (o = e?.clientHeight) !== null && o !== void 0 ? o : 0
    };
  }
  constructor(e) {
    this.ref = e;
  }
}
class w {
  isDisabled(e) {
    var t;
    return this.disabledBehavior === "all" && (((t = e.props) === null || t === void 0 ? void 0 : t.isDisabled) || this.disabledKeys.has(e.key));
  }
  findNextNonDisabled(e, t) {
    let i = e;
    for (; i != null; ) {
      let l = this.collection.getItem(i);
      if (l?.type === "item" && !this.isDisabled(l)) return i;
      i = t(i);
    }
    return null;
  }
  getNextKey(e) {
    let t = e;
    return t = this.collection.getKeyAfter(t), this.findNextNonDisabled(t, (i) => this.collection.getKeyAfter(i));
  }
  getPreviousKey(e) {
    let t = e;
    return t = this.collection.getKeyBefore(t), this.findNextNonDisabled(t, (i) => this.collection.getKeyBefore(i));
  }
  findKey(e, t, i) {
    let l = e, o = this.layoutDelegate.getItemRect(l);
    if (!o || l == null) return null;
    let r = o;
    do {
      if (l = t(l), l == null) break;
      o = this.layoutDelegate.getItemRect(l);
    } while (o && i(r, o) && l != null);
    return l;
  }
  isSameRow(e, t) {
    return e.y === t.y || e.x !== t.x;
  }
  isSameColumn(e, t) {
    return e.x === t.x || e.y !== t.y;
  }
  getKeyBelow(e) {
    return this.layout === "grid" && this.orientation === "vertical" ? this.findKey(e, (t) => this.getNextKey(t), this.isSameRow) : this.getNextKey(e);
  }
  getKeyAbove(e) {
    return this.layout === "grid" && this.orientation === "vertical" ? this.findKey(e, (t) => this.getPreviousKey(t), this.isSameRow) : this.getPreviousKey(e);
  }
  getNextColumn(e, t) {
    return t ? this.getPreviousKey(e) : this.getNextKey(e);
  }
  getKeyRightOf(e) {
    let t = this.direction === "ltr" ? "getKeyRightOf" : "getKeyLeftOf";
    return this.layoutDelegate[t] ? (e = this.layoutDelegate[t](e), this.findNextNonDisabled(e, (i) => this.layoutDelegate[t](i))) : this.layout === "grid" ? this.orientation === "vertical" ? this.getNextColumn(e, this.direction === "rtl") : this.findKey(e, (i) => this.getNextColumn(i, this.direction === "rtl"), this.isSameColumn) : this.orientation === "horizontal" ? this.getNextColumn(e, this.direction === "rtl") : null;
  }
  getKeyLeftOf(e) {
    let t = this.direction === "ltr" ? "getKeyLeftOf" : "getKeyRightOf";
    return this.layoutDelegate[t] ? (e = this.layoutDelegate[t](e), this.findNextNonDisabled(e, (i) => this.layoutDelegate[t](i))) : this.layout === "grid" ? this.orientation === "vertical" ? this.getNextColumn(e, this.direction === "ltr") : this.findKey(e, (i) => this.getNextColumn(i, this.direction === "ltr"), this.isSameColumn) : this.orientation === "horizontal" ? this.getNextColumn(e, this.direction === "ltr") : null;
  }
  getFirstKey() {
    let e = this.collection.getFirstKey();
    return this.findNextNonDisabled(e, (t) => this.collection.getKeyAfter(t));
  }
  getLastKey() {
    let e = this.collection.getLastKey();
    return this.findNextNonDisabled(e, (t) => this.collection.getKeyBefore(t));
  }
  getKeyPageAbove(e) {
    let t = this.ref.current, i = this.layoutDelegate.getItemRect(e);
    if (!i) return null;
    if (t && !h(t)) return this.getFirstKey();
    let l = e;
    if (this.orientation === "horizontal") {
      let o = Math.max(0, i.x + i.width - this.layoutDelegate.getVisibleRect().width);
      for (; i && i.x > o && l != null; )
        l = this.getKeyAbove(l), i = l == null ? null : this.layoutDelegate.getItemRect(l);
    } else {
      let o = Math.max(0, i.y + i.height - this.layoutDelegate.getVisibleRect().height);
      for (; i && i.y > o && l != null; )
        l = this.getKeyAbove(l), i = l == null ? null : this.layoutDelegate.getItemRect(l);
    }
    return l ?? this.getFirstKey();
  }
  getKeyPageBelow(e) {
    let t = this.ref.current, i = this.layoutDelegate.getItemRect(e);
    if (!i) return null;
    if (t && !h(t)) return this.getLastKey();
    let l = e;
    if (this.orientation === "horizontal") {
      let o = Math.min(this.layoutDelegate.getContentSize().width, i.y - i.width + this.layoutDelegate.getVisibleRect().width);
      for (; i && i.x < o && l != null; )
        l = this.getKeyBelow(l), i = l == null ? null : this.layoutDelegate.getItemRect(l);
    } else {
      let o = Math.min(this.layoutDelegate.getContentSize().height, i.y - i.height + this.layoutDelegate.getVisibleRect().height);
      for (; i && i.y < o && l != null; )
        l = this.getKeyBelow(l), i = l == null ? null : this.layoutDelegate.getItemRect(l);
    }
    return l ?? this.getLastKey();
  }
  getKeyForSearch(e, t) {
    if (!this.collator) return null;
    let i = this.collection, l = t || this.getFirstKey();
    for (; l != null; ) {
      let o = i.getItem(l);
      if (!o) return null;
      let r = o.textValue.slice(0, e.length);
      if (o.textValue && this.collator.compare(r, e) === 0) return l;
      l = this.getNextKey(l);
    }
    return null;
  }
  constructor(...e) {
    if (e.length === 1) {
      let t = e[0];
      this.collection = t.collection, this.ref = t.ref, this.collator = t.collator, this.disabledKeys = t.disabledKeys || /* @__PURE__ */ new Set(), this.disabledBehavior = t.disabledBehavior || "all", this.orientation = t.orientation || "vertical", this.direction = t.direction, this.layout = t.layout || "stack", this.layoutDelegate = t.layoutDelegate || new c(t.ref);
    } else
      this.collection = e[0], this.disabledKeys = e[1], this.ref = e[2], this.collator = e[3], this.layout = "stack", this.orientation = "vertical", this.disabledBehavior = "all", this.layoutDelegate = new c(this.ref);
    this.layout === "stack" && this.orientation === "vertical" && (this.getKeyLeftOf = void 0, this.getKeyRightOf = void 0);
  }
}
function S(n) {
  let { selectionManager: e, collection: t, disabledKeys: i, ref: l, keyboardDelegate: o, layoutDelegate: r } = n, a = m({
    usage: "search",
    sensitivity: "base"
  }), s = e.disabledBehavior, d = x(() => o || new w({
    collection: t,
    disabledKeys: i,
    disabledBehavior: s,
    ref: l,
    collator: a,
    layoutDelegate: r
  }), [
    o,
    r,
    t,
    i,
    l,
    a,
    s
  ]), { collectionProps: g } = y({
    ...n,
    ref: l,
    selectionManager: e,
    keyboardDelegate: d
  });
  return {
    listProps: g
  };
}
const u = /* @__PURE__ */ new WeakMap();
function M(n) {
  let e = u.get(n);
  if (e != null) return e;
  let t = 0, i = (l) => {
    for (let o of l)
      o.type === "section" ? i(b(o, n)) : o.type === "item" && t++;
  };
  return i(n), u.set(n, t), t;
}
const N = /* @__PURE__ */ $({}), P = /* @__PURE__ */ D(p, function(e, t) {
  return [e, t] = v(e, t, N), /* @__PURE__ */ K.createElement("header", {
    className: "react-aria-Header",
    ...e,
    ref: t
  }, e.children);
});
export {
  S as $,
  M as a,
  N as b,
  w as c,
  P as d,
  c as e
};
//# sourceMappingURL=Header-BQ99pNEi.es.js.map
