import { isFunction as y } from "lodash-unified";
import { ref as K, computed as s, unref as c } from "vue";
const m = (a) => {
  const n = K([]);
  function f(e, t) {
    n.value = t;
  }
  const l = (e) => y(a.rowKey) ? a.rowKey(e) : e[a.rowKey], o = s(() => {
    const e = /* @__PURE__ */ new Map();
    return c(n).forEach((t) => {
      e.set(l(t), t);
    }), e;
  });
  function r(e) {
    return c(o).has(l(e));
  }
  function d(e) {
    const t = c(o);
    t.set(l(e), e), n.value = [...t.values()];
  }
  function i(e) {
    const t = c(o);
    for (const u of e)
      t.set(l(u), u);
    n.value = [...t.values()];
  }
  function S(e) {
    const t = c(o);
    t.delete(l(e)), n.value = [...t.values()];
  }
  function v(e) {
    const t = c(o);
    for (const u of e)
      t.delete(l(u));
    n.value = [...t.values()];
  }
  function M() {
    const e = c(o);
    c(a.dataSource).forEach((t) => {
      e.set(l(t), t);
    }), n.value = [...e.values()];
  }
  function w(e) {
    const t = c(o), u = l(e);
    t.has(u) ? t.delete(u) : t.set(u, e), n.value = [...t.values()];
  }
  function x() {
    const e = c(o);
    c(a.dataSource).forEach((t) => {
      e.delete(l(t));
    }), n.value = [...e.values()];
  }
  function h() {
    n.value = [];
  }
  return {
    select: d,
    unSelect: S,
    isSelected: r,
    selectAll: M,
    unSelectAll: x,
    clearAll: h,
    toggleSelect: w,
    selectedRows: n,
    selectMulti: i,
    unSelectMulti: v,
    rowSelection: s(() => ({
      ...a,
      onChange: f,
      selectedRowKeys: c(n).map((e) => l(e))
    }))
  };
};
export {
  m as default
};
