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