import { useRef as k, useCallback as a, useLayoutEffect as x } from "react";
import { COMMAND_VARIANT as n } from "../constants/index.js";
const K = ({
  value: i,
  variant: h,
  setValueState: d,
  setOpen: g,
  onItemSelect: r,
  commandListRef: A,
  selectedGroupRef: H
}) => {
  const b = k(0), G = a(
    (u) => {
      if (h === n.CHECKBOX)
        r == null || r(u);
      else {
        const { label: s, value: f } = u;
        d(s), g(!1), r == null || r(f);
      }
    },
    [r, d, g, h]
  ), w = a(
    (u) => {
      r == null || r(u.filter((s) => s !== null));
    },
    [r]
  ), C = a(
    (u) => u.items.filter((s) => s.value !== null).map((s) => String(s.value)),
    []
  ), E = a(
    (u) => {
      const s = Array.from(/* @__PURE__ */ new Set([...i ?? [], ...C(u)]));
      r == null || r(s);
    },
    [i, r, C]
  ), O = a(
    (u) => {
      const s = new Set(C(u)), f = (i ?? []).filter((p) => !s.has(p));
      r == null || r(f);
    },
    [i, r, C]
  ), V = a(() => {
    r == null || r([]);
  }, [r]);
  return x(() => {
    if (h !== n.CHECKBOX) return;
    const u = H.current, s = A.current;
    if (!s) return;
    const f = u ? u.offsetHeight : 0, p = f - b.current;
    p !== 0 && (s.scrollTop += p), b.current = f;
  }, [i, h, A, H]), {
    handleContentItemOnSelect: G,
    handleCheckboxGroupChange: w,
    getSelectableGroupValues: C,
    handleGroupSelectAll: E,
    handleGroupClear: O,
    handleClearAll: V
  };
};
export {
  K as useCommandSelection
};
//# sourceMappingURL=useCommandSelection.js.map
