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