import { useMemo as s } from "react";
const k = (b) => {
  const { bodyRows: n, selectedRowIds: g, onSelectionChange: o } = b, d = s(
    () => n.filter(
      (e) => (e.kind === "data" || e.kind === "expanded" || e.kind === "group") && !e.disabled && e.selectable !== !1
    ).map((e) => e.rowId),
    [n]
  ), a = s(() => new Set(d), [d]), t = s(
    () => n.filter(
      (e) => (e.kind === "data" || e.kind === "group") && !e.disabled && e.selectable !== !1
    ).map((e) => e.rowId),
    [n]
  ), l = g ?? [], i = s(() => new Set(l), [l]), S = s(
    () => l.filter((e) => t.includes(e)),
    [l, t]
  ), R = s(
    () => new Set(S),
    [S]
  ), c = t.length > 0 && t.every((e) => R.has(e)), u = R.size > 0 && !c, h = t.length > 0;
  return {
    currentSelectedRowIds: l,
    selectedRowIdSet: i,
    selectableRowIdSet: a,
    isAllRowsSelected: c,
    isSomeRowsSelected: u,
    hasSelectableRows: h,
    handleToggleAllSelection: () => {
      o?.(c ? [] : t);
    },
    handleToggleRowSelection: (e) => {
      !o || !a.has(e) || o(
        i.has(e) ? l.filter((r) => r !== e) : [...l, e]
      );
    }
  };
};
export {
  k as default
};
//# sourceMappingURL=useInternalTableSelectionState.js.map
