import { computed as f, toValue as w, ref as x } from "vue";
function R({
  items: g,
  trackBy: A = "id",
  shouldDisable: t,
  shouldPreselect: o
}) {
  const v = f(() => w(g));
  function r(e) {
    return String(e[A]);
  }
  const c = f(
    () => v.value.reduce(
      (e, u) => (e[r(u)] = u, e),
      {}
    )
  ), n = x(/* @__PURE__ */ new Set());
  function m(e) {
    t != null && t(c.value[r(e)]) || n.value.add(r(e));
  }
  function E(e) {
    t != null && t(c.value[r(e)]) || n.value.delete(r(e));
  }
  function k(e) {
    if (t != null && t(c.value[r(e)]))
      return;
    n.value.has(r(e)) ? n.value.delete(r(e)) : n.value.add(r(e));
  }
  function l() {
    v.value.forEach((e) => {
      t != null && t(e) || n.value.add(r(e));
    });
  }
  function a() {
    typeof t == "function" ? n.value.forEach((e, u) => {
      t(c.value[u]) || n.value.delete(u);
    }) : n.value.clear();
  }
  function z() {
    y.value ? a() : l();
  }
  function i() {
    a(), typeof o == "function" && v.value.forEach((e) => {
      o(e) && n.value.add(r(e));
    });
  }
  function I(e) {
    return n.value.has(r(e));
  }
  function K(e) {
    return typeof t != "function" ? !1 : t(c.value[r(e)]);
  }
  const N = f(() => Array.from(n.value.keys()).map((e) => c.value[e])), S = f(() => n.value.size === v.value.length), y = f(() => {
    if (typeof t != "function")
      return S.value;
    for (const e of v.value)
      if (!t(e) && !n.value.has(r(e)))
        return !1;
    return !0;
  }), p = f(() => n.value.size > 0), T = f(() => {
    if (typeof t != "function")
      return p.value;
    for (const e of n.value.keys())
      if (!t(c.value[e]))
        return !0;
    return !1;
  });
  return i(), {
    select: m,
    unselect: E,
    selectToggle: k,
    selectAll: l,
    unselectAll: a,
    selectToggleAll: z,
    resetSelection: i,
    isSelected: I,
    isSelectDisabled: K,
    selectedItems: N,
    allSelected: S,
    allNonDisabledSelected: y,
    someSelected: p,
    someNonDisabledSelected: T
  };
}
export {
  R as default
};
//# sourceMappingURL=useSelection.js.map
