import { jsx as m } from "@emotion/react/jsx-runtime";
import { SELECT_COLUMN_KEY as k, SelectCellFormatter as f } from "react-data-grid";
import { useDataGrid as u } from "../../../../hooks/shared/useDataGrid/useDataGrid.js";
const G = "filter-cell", A = 35;
function R(t, n) {
  const o = [];
  for (const e of t)
    "childRows" in e && Array.isArray(e.childRows) ? o.push(...R(e.childRows, n)) : o.push(n(e));
  return o;
}
function g(t) {
  const { checkedRows: n, onCheckedRowsChange: o, rowKeyGetter: e } = u(), { childRows: c } = t, l = R(c, e), s = l.filter((a) => n?.has(a)).length, r = l.length, d = r > 0 && s === r, i = s > 0 && s < r, h = (a) => {
    if (!o)
      return;
    const C = new Set(n);
    a ? l.forEach((w) => C.add(w)) : l.forEach((w) => C.delete(w)), o(C);
  };
  return /* @__PURE__ */ m(
    f,
    {
      value: d,
      indeterminate: i,
      tabIndex: t.tabIndex,
      onChange: h,
      "aria-label": "Select Group"
    }
  );
}
function S(t) {
  const { checkedRows: n, onCheckedRowsChange: o, rowKeyGetter: e } = u(), c = (l, s) => {
    const r = new Set(n);
    l ? r.add(e(t.row)) : r.delete(e(t.row)), o && o(r);
  };
  return /* @__PURE__ */ m(
    f,
    {
      value: n?.has(e(t.row)) || !1,
      tabIndex: t.tabIndex,
      onChange: c,
      "aria-label": "Select"
    }
  );
}
const b = (t) => {
  const { rows: n, rowKeyGetter: o, onCheckedRowsChange: e, checkedRows: c } = u(), l = c?.size ?? 0, s = n.length, r = s > 0 && l === s, d = l > 0 && l < s, i = (h) => {
    e && e(h ? new Set(n.map((a) => o(a))) : /* @__PURE__ */ new Set());
  };
  return f({
    "aria-label": "Select All",
    tabIndex: t.tabIndex,
    value: r,
    indeterminate: d,
    onChange: i
  });
}, E = {
  key: k,
  name: "",
  width: 32,
  minWidth: 32,
  isDraggable: !1,
  resizable: !1,
  sortable: !1,
  frozen: !0,
  type: "boolean",
  renderHeaderCell: b,
  renderCell: S,
  renderGroupCell: g
};
export {
  E as SelectColumn,
  G as filterColumnClassName,
  A as filterHeight
};
