import { useMemo as m } from "react";
import { map as p } from "es-toolkit/compat";
import { useVirtualizer as z } from "@tanstack/react-virtual";
const b = (r, i, n, a, s, d, o) => {
  const l = m(() => {
    if (n)
      return i.map((t) => ({
        type: "leaf",
        data: t,
        id: t.id
      }));
    if (a) {
      const t = [];
      return p(r, (e) => {
        const c = s?.includes(e.id) ?? !1;
        t.push({
          type: "group",
          data: e,
          id: e.id,
          isExpanded: c
        }), c && e.items.forEach((u) => {
          t.push({
            type: "leaf",
            data: u,
            id: u.id,
            groupId: e.id
          });
        });
      }), t;
    }
    return i.map((t) => ({
      type: "leaf",
      data: t,
      id: t.id
    }));
  }, [r, i, n, a, s]), f = z({
    count: l.length,
    // getScrollElement: () => scrollElementRef.current,
    getScrollElement: () => d.current ? d.current?.view : null,
    estimateSize: () => 41,
    // typical single line height without line-break
    measureElement: (t) => t?.children[0].clientHeight ?? 41,
    overscan: o,
    // Render 10 extra items above and below visible area
    // Add this to enable more aggressive remeasurement
    lanes: 1
  });
  return { virtualizedItems: l, virtualizer: f };
};
export {
  b as useTreeVirtualization
};
//# sourceMappingURL=useTreeVirtualization.js.map
