import { useState as i, useRef as f, useEffect as E } from "react";
const v = ({
  groups: t,
  expandAllGroups: r = !0
}) => {
  const [h, p] = i(""), [m, d] = i(
    () => t ? r ? new Set(t.map((e) => e.id)) : new Set(t.filter((e) => !e.collapsed).map((e) => e.id)) : /* @__PURE__ */ new Set()
  ), [S, l] = i(
    /* @__PURE__ */ new Map()
  ), o = f([]), u = f(r);
  return E(() => {
    if (!t) {
      d(/* @__PURE__ */ new Set()), o.current = [];
      return;
    }
    const e = t.map((c) => c.id), a = o.current, s = e.length !== a.length || e.some((c, n) => c !== a[n]), w = u.current !== r;
    if (s || w) {
      const c = r ? new Set(t.map((n) => n.id)) : new Set(t.filter((n) => !n.collapsed).map((n) => n.id));
      d(c), o.current = e, u.current = r;
    }
  }, [t, r]), {
    searchQuery: h,
    setSearchQuery: p,
    expandedGroups: m,
    itemHeights: S,
    setItemHeights: l,
    handleGroupExpandToggle: (e) => {
      d((a) => {
        const s = new Set(a);
        return s.has(e) ? s.delete(e) : s.add(e), s;
      });
    }
  };
};
export {
  v as useCheckableListState
};
