"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("lodash-unified"),c=require("vue");function _(l,o){return!o?.length||d.isFunction(l)?[]:o.map(S=>({[l]:S}))}const q=l=>{const o=c.ref(_(l.rowKey,l.defaultSelectedRowKeys));function S(e,t){o.value=t}const a=e=>d.isFunction(l.rowKey)?l.rowKey(e):e[l.rowKey],s=c.computed(()=>{const e=new Map;return c.unref(o).forEach(t=>{e.set(a(t),t)}),e});function M(e){return c.unref(s).has(a(e))}function w(e){if(!f(e))return;const t=c.unref(s);t.set(a(e),e),o.value=[...t.values()]}function h(e){const t=c.unref(s);for(const n of e)f(n)&&t.set(a(n),n);o.value=[...t.values()]}function g(e){if(d.isFunction(l.rowKey))return;const t=c.unref(s);for(const n of e){const u=c.unref(l.dataSource).find(i=>a(i)===n),r={[l.rowKey]:n};f(u||r)&&t.set(n,u||r)}o.value=[...t.values()]}function y(e){if(!f(e))return;const t=c.unref(s);t.delete(a(e)),o.value=[...t.values()]}function x(e){const t=c.unref(s);for(const n of e)f(n)&&t.delete(a(n));o.value=[...t.values()]}function v(e,t){const n=e;for(const u of t)n.set(a(u),u);return n}function K(e,t,n){const u=c.unref(s);e?v(u,[...n,...t]):c.unref(l.dataSource).forEach(r=>{const i=a(r);t.some(F=>a(F)===i)?u.set(i,r):u.delete(i)}),o.value=[...u.values()]}function b(e,t){const n=d.cloneDeep(c.unref(s));e?v(n,t):c.unref(l.dataSource).forEach(u=>{f(u)&&n.delete(a(u))}),o.value=[...n.values()]}function f(e){const t=l.shown,n=l.disabled,u=t?t(e):!0,r=n?n(e):!1;return u&&!r}function R(e,t){const n=d.cloneDeep(c.unref(s));c.unref(l.dataSource).forEach(u=>{e.find(i=>a(i)===a(u))?n.set(a(u),u):n.delete(a(u))}),v(n,t),o.value=[...n.values()]}function E(){const e=c.unref(s);c.unref(l.dataSource).forEach(t=>{f(t)&&e.set(a(t),t)}),o.value=[...e.values()]}function D(e){if(!f(e))return;const t=c.unref(s),n=a(e);t.has(n)?t.delete(n):t.set(n,e),o.value=[...t.values()]}function A(){const e=c.unref(s);c.unref(l.dataSource).forEach(t=>{f(t)&&e.delete(a(t))}),o.value=[...e.values()]}function C(){o.value=[]}return{select:w,unSelect:y,isSelected:M,selectAll:E,unSelectAll:A,clearAll:C,toggleSelect:D,selectedRows:o,selectMulti:h,unSelectMulti:x,rowSelection:c.computed(()=>({...l,onChange:S,selectedRowKeys:c.unref(o).map(e=>a(e))})),selectChange:K,selectAllChange:b,selectRangeChange:R,selectMultiByKeys:g}};exports.default=q;
