import{p as me,a as f,s as R,b as he,u as pe,g as e,c as j,d as h,f as u,i as N,e as n,h as b,j as V,t as g,k as ge,l as U,m as M,n as v,o as q,q as we,r as xe,w as Se,x as ke}from"./index-DW7rebFp.js";var ye=u('<input class="datagrid-search svelte-13v1on6" placeholder="Search..."/>'),Le=u('<button class="export-btn svelte-13v1on6">Export CSV</button>'),je=u('<th class="select-col svelte-13v1on6"></th>'),Ne=u('<span class="sort-indicator svelte-13v1on6"> </span>'),Re=u("<th><span> </span> <!></th>"),De=u('<td class="select-col svelte-13v1on6"><input type="checkbox"/></td>'),Ce=u("<td> </td>"),Fe=u("<tr><!><!></tr>"),Ue=u('<div class="pagination svelte-13v1on6"><button class="svelte-13v1on6">Prev</button> <span> </span> <button class="svelte-13v1on6">Next</button></div>'),Me=u('<div><div class="datagrid-toolbar svelte-13v1on6"><!> <!></div> <div class="table-wrapper svelte-13v1on6"><table class="svelte-13v1on6"><thead><tr><!><!></tr></thead><tbody></tbody></table></div> <!></div>');function Ie(Q,c){me(c,!0);let W=f(c,"columns",19,()=>[]),X=f(c,"rows",19,()=>[]),w=f(c,"pageSize",3,10),B=f(c,"sortable",3,!0),z=f(c,"filterable",3,!1),I=f(c,"selectable",3,!1),Y=f(c,"exportable",3,!1),Z=f(c,"striped",3,!0),$=f(c,"compact",3,!1),D=R(""),o=R(1),x=R(null),S=R("asc"),O=R(he(new Set));const C=j(()=>W().map(t=>({field:t.field,header:t.header||t.field,width:t.width,sortable:t.sortable??B(),filterable:t.filterable??z(),format:t.format??"text",align:t.align??"left"}))),ee=j(()=>X().filter(t=>{if(!z()||!e(D).trim())return!0;const a=e(D).toLowerCase();return Object.values(t).some(r=>String(r??"").toLowerCase().includes(a))})),F=j(()=>[...e(ee)].sort((t,a)=>{if(!e(x))return 0;const r=t[e(x)],s=a[e(x)];return r===s?0:r==null?1:s==null?-1:r<s?e(S)==="asc"?-1:1:e(S)==="asc"?1:-1})),k=j(()=>w()>0?Math.max(1,Math.ceil(e(F).length/w())):1);pe(()=>{e(o)>e(k)&&h(o,e(k),!0)});const te=j(()=>w()>0?e(F).slice((e(o)-1)*w(),e(o)*w()):e(F));function ae(t){B()&&(e(x)===t?h(S,e(S)==="asc"?"desc":"asc",!0):(h(x,t,!0),h(S,"asc")))}function G(t,a){if(t==null)return"";switch(a){case"currency":return new Intl.NumberFormat(void 0,{style:"currency",currency:"USD"}).format(Number(t));case"percent":return new Intl.NumberFormat(void 0,{style:"percent"}).format(Number(t));case"number":return new Intl.NumberFormat().format(Number(t));case"date":return new Date(String(t)).toLocaleDateString();case"datetime":return new Date(String(t)).toLocaleString();case"boolean":return t?"True":"False";default:return String(t)}}function re(t){if(!I())return;const a=new Set(e(O));a.has(t)?a.delete(t):a.add(t),h(O,a,!0)}function se(){const t=e(C).map(_=>_.header).join(","),a=e(F).map(_=>e(C).map(y=>{const p=_[y.field],d=G(p,y.format);return`"${String(d).replace(/"/g,'""')}"`}).join(",")),r=[t,...a].join(`
`),s=new Blob([r],{type:"text/csv;charset=utf-8;"}),l=URL.createObjectURL(s),i=document.createElement("a");i.href=l,i.download="data.csv",i.click(),URL.revokeObjectURL(l)}var P=Me(),T=n(P),A=n(T);{var ne=t=>{var a=ye();Se(a,()=>e(D),r=>h(D,r)),v(t,a)};N(A,t=>{z()&&t(ne)})}var oe=b(A,2);{var le=t=>{var a=Le();a.__click=se,v(t,a)};N(oe,t=>{Y()&&t(le)})}var H=b(T,2),ie=n(H),J=n(ie),ce=n(J),K=n(ce);{var de=t=>{var a=je();v(t,a)};N(K,t=>{I()&&t(de)})}var ve=b(K);V(ve,17,()=>e(C),q,(t,a)=>{var r=Re();r.__click=()=>e(a).sortable&&ae(e(a).field);let s;var l=n(r),i=n(l),_=b(l,2);{var y=p=>{var d=Ne(),m=n(d);g(()=>M(m,e(S)==="asc"?"▲":"▼")),v(p,d)};N(_,p=>{e(x)===e(a).field&&p(y)})}g(()=>{ge(r,e(a).width?`width: ${e(a).width}px`:""),s=U(r,1,"svelte-13v1on6",null,s,{sortable:e(a).sortable}),M(i,e(a).header)}),v(t,r)});var ue=b(J);V(ue,21,()=>e(te),q,(t,a,r)=>{const s=j(()=>e(a).id??r);var l=Fe();let i;var _=n(l);{var y=d=>{var m=De(),L=n(m);L.__change=()=>re(e(s)),g(E=>we(L,E),[()=>e(O).has(e(s))]),v(d,m)};N(_,d=>{I()&&d(y)})}var p=b(_);V(p,17,()=>e(C),q,(d,m)=>{var L=Ce(),E=n(L);g(_e=>{U(L,1,`align-${e(m).align}`,"svelte-13v1on6"),M(E,_e)},[()=>G(e(a)[e(m).field],e(m).format)]),v(d,L)}),g(()=>i=U(l,1,"svelte-13v1on6",null,i,{striped:Z()&&r%2===1})),v(t,l)});var fe=b(H,2);{var be=t=>{var a=Ue(),r=n(a);r.__click=()=>h(o,Math.max(1,e(o)-1),!0);var s=b(r,2),l=n(s),i=b(s,2);i.__click=()=>h(o,Math.min(e(k),e(o)+1),!0),g(()=>{r.disabled=e(o)===1,M(l,`Page ${e(o)??""} / ${e(k)??""}`),i.disabled=e(o)===e(k)}),v(t,a)};N(fe,t=>{w()>0&&e(k)>1&&t(be)})}g(()=>U(P,1,`datagrid ${$()?"compact":""}`,"svelte-13v1on6")),v(Q,P),xe()}ke(["click","change"]);export{Ie as default};
