import{r as x,j as e,H as c,bU as j,q as C,t as b,l as g,aJ as f,m as v}from"./vendor-ClLR6ncd.js";import"./lodash-ZyeDnt0e.js";import{ah as k}from"./index-OtVJl4GC.js";function A({accessorKey2header:i,columnVisibility:o,setColumnVisibility:t}){const[a,s]=x.useState(null),r=Object.entries(o).map(([n,l])=>({accessorKey:n,header:i[n],visible:l})),d=n=>()=>t(l=>({...l,[n]:!l[n]})),m=n=>{s(n.currentTarget)},u=()=>{s(null)},h=!!a;return e.jsxs("div",{children:[e.jsx(c,{variant:r.some(({visible:n})=>!n)?"contained":"outlined",onClick:m,children:"Filter columns"}),e.jsx(j,{open:h,anchorEl:a,onClose:u,anchorOrigin:{vertical:"bottom",horizontal:"left"},children:e.jsx(C,{children:r.map(({accessorKey:n,header:l,visible:p})=>e.jsx(b,{disablePadding:!0,children:e.jsxs(k,{onClick:d(n),children:[e.jsx(g,{children:e.jsx(f,{edge:"start",checked:p,tabIndex:-1})}),e.jsx(v,{primary:l})]})},n))})})]})}function I(i,o){const t=document.createElement("a");t.setAttribute("href","data:text/csv;charset=utf-8,"+encodeURIComponent(o)),t.setAttribute("download",i),t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t)}function L(i){return i.map(o=>o.map(t=>Number.isFinite(t)||!t?t:`"${t.replace(/"/g,'""')}"`).join(",")).join(`
`)}function F({filenamePrefix:i,rows:o,columns:t}){return e.jsx(c,{variant:"contained",disabled:o.length===0,onClick:()=>{I(`${i}-${new Date().toLocaleString()}.csv`,L([t.map(({header:a})=>a)].concat(o.map(a=>t.map(({accessorKey:s})=>a[s])))))},children:"Download"})}export{F as D,A as F};
