var e=Object.defineProperty,r=Object.defineProperties,n=Object.getOwnPropertyDescriptors,t=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,a=(r,n,t)=>n in r?e(r,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[n]=t,p=(e,r)=>{for(var n in r||(r={}))l.call(r,n)&&a(e,n,r[n]);if(t)for(var n of t(r))o.call(r,n)&&a(e,n,r[n]);return e},s=(e,t)=>r(e,n(t));import{$ as c}from"./index-CY1ySRal.js";import{r as u,S as i,c as m}from"./vendor-core-Di0OO4oJ.js";const d={selection:{prop:"__selection__",label:c("table.column.selection")},expand:{prop:"__expand__",label:c("table.column.expand")},index:{prop:"__index__",label:c("table.column.index")}},v=e=>{var r,n;return null!=(n=null==(r=d[e.type])?void 0:r.prop)?n:e.prop},b=e=>{var r;return void 0!==e.visible?e.visible:null==(r=e.checked)||r},y=e=>e.map(e=>{const r=e.type&&d[e.type],n=b(e);return s(p({},e),r?{prop:r.prop,label:r.label,checked:!0,visible:!0}:{checked:n,visible:n})});function f(e){const r=u(e()),n=u(y(r.value));i(r,e=>{const r=new Map(n.value.map(e=>[v(e),b(e)])),t=y(e).map(e=>{const n=v(e),t=r.has(n)?r.get(n):b(e);return s(p({},e),{checked:t,visible:t})});n.value=t},{deep:!0});const t=m(()=>{const e=new Map(r.value.map(e=>[v(e),e]));return n.value.filter(e=>b(e)).map(r=>e.get(v(r))).filter(Boolean)}),l=e=>{const n=[...r.value],t=e(n);r.value=Array.isArray(t)?t:n};return{columns:t,columnChecks:n,addColumn:(e,r)=>l(n=>{const t=[...n],l=Array.isArray(e)?e:[e],o="number"==typeof r&&r>=0&&r<=t.length?r:t.length;return t.splice(o,0,...l),t}),removeColumn:e=>l(r=>{const n=Array.isArray(e)?e:[e];return r.filter(e=>!n.includes(v(e)))}),updateColumn:(e,r)=>{Array.isArray(e)?l(r=>{const n=new Map(e.map(e=>[e.prop,e.updates]));return r.map(e=>{const r=v(e),t=n.get(r);return t?p(p({},e),t):e})}):r&&l(n=>n.map(n=>v(n)===e?p(p({},n),r):n))},toggleColumn:(e,r)=>{const t=Array.isArray(e)?e:[e],l=[...n.value];t.forEach(e=>{const n=l.findIndex(r=>v(r)===e);if(n>-1){const e=b(l[n]),t=null!=r?r:!e;l[n]=s(p({},l[n]),{checked:t,visible:t})}}),n.value=l},resetColumns:()=>{r.value=e()},batchUpdateColumns:e=>l(r=>{const n=new Map(e.map(e=>[e.prop,e.updates]));return r.map(e=>{const r=v(e),t=n.get(r);return t?p(p({},e),t):e})}),reorderColumns:(e,r)=>l(n=>{if(e<0||e>=n.length||r<0||r>=n.length||e===r)return n;const t=[...n],[l]=t.splice(e,1);return t.splice(r,0,l),t}),getColumnConfig:e=>r.value.find(r=>v(r)===e),getAllColumns:()=>[...r.value]}}export{f as u};
