import { useCallback as V } from "react";
const q = ({
  value: r,
  onChange: t,
  multiple: k = !0,
  disabled: s = !1,
  normalizedItems: p,
  getGroupItems: u,
  isGroupFullySelected: x,
  isItemSelected: l,
  areAllItemsSelected: H
}) => {
  const e = V(
    (c) => {
      if (!(!t || s))
        if (k) {
          const f = l(c) ? r.filter((L) => L !== c) : [...r, c];
          t(f);
        } else
          t(l(c) ? [] : [c]);
    },
    [t, s, k, r, l]
  ), i = V(
    (c) => {
      if (!t || s)
        return;
      const f = u(c);
      if (x(c)) {
        const o = r.filter(
          (w) => !f.some((T) => T.id === w)
        );
        t(o);
      } else {
        const o = f.map((T) => T.id), w = [.../* @__PURE__ */ new Set([...r, ...o])];
        t(w);
      }
    },
    [t, s, r, u, x]
  ), j = V(() => {
    if (!(!t || s))
      if (H)
        t([]);
      else {
        const c = p.map((f) => f.id);
        t(c);
      }
  }, [t, s, H, p]);
  return {
    handleItemToggle: e,
    handleGroupToggle: i,
    handleSelectAllToggle: j
  };
};
export {
  q as useCheckableListHandlers
};
