"use strict";var L=Object.create;var w=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var M=(l,s,d,x)=>{if(s&&typeof s=="object"||typeof s=="function")for(let f of R(s))!D.call(l,f)&&f!==d&&w(l,f,{get:()=>s[f],enumerable:!(x=A(s,f))||x.enumerable});return l};var O=(l,s,d)=>(d=l!=null?L(S(l)):{},M(s||!l||!l.__esModule?w(d,"default",{value:l,enumerable:!0}):d,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=15,_=.12,j=(l,s)=>{const d=n=>{const t=[],e=o=>{for(const r of o)if(r.children?.length)e(r.children);else{const a=r.width?Math.round(r.width*_):U;t.push({key:String(r.key),width:a,align:r.align})}};return e(n),t},x=n=>{let t=1;const e=(o,r)=>{for(const a of o)a.children?.length&&(t=Math.max(t,r+1),e(a.children,r+1))};return e(n,1),t},f=n=>{if(!n.children?.length)return 1;let t=0;for(const e of n.children)t+=f(e);return t},T=(n,t,e,o)=>{const r=h=>h.align?h.align:h.children?.length?"center":"left",a=(h,g,v)=>{let c=v;for(const i of h){const u=o?.[i.key]??(typeof i.title=="string"?i.title:""),p=n.getCell(g,c);if(p.value=u,p.alignment={vertical:"middle",horizontal:r(i)},i.children?.length){const m=f(i);m>1&&n.mergeCells(g,c,g,c+m-1),a(i.children,g+1,c),c+=m}else e>1&&n.mergeCells(g,c,e,c),c+=1}};a(t,1,1)},C=async n=>{const t=await import("exceljs").catch(()=>{throw new Error(`[AgGrid] exportToExcel requires exceljs.
Run: npm install exceljs`)}),e=typeof n=="string"?{fileName:n}:n,o=new t.Workbook,r=o.addWorksheet(e.sheetName??"Sheet1"),a=d(l.value),h=x(l.value);r.columns=a.map(u=>({key:u.key,width:u.width,alignment:{vertical:"middle",horizontal:u.align||"left"}})),T(r,l.value,h,e.titleMap),s.value.forEach(u=>{const p={};a.forEach(m=>{const y=E(l.value,m.key),k=b(u,y?.dataIndex);y?.renderText?p[m.key]=y.renderText({value:k,text:k,record:u,column:y}):p[m.key]=k}),r.addRow(p)});const g=await o.xlsx.writeBuffer(),v=new Blob([g],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),c=URL.createObjectURL(v),i=document.createElement("a");i.href=c,i.download=e.fileName,i.click(),URL.revokeObjectURL(c)},E=(n,t)=>{for(const e of n){if(e.key===t)return e;if(e.children){const o=E(e.children,t);if(o)return o}}},b=(n,t=[])=>{const e=Array.isArray(t)?t:[t];let o=n;for(const r of e){if(o==null)return;o=o[r]}return o};return{exportToExcel:C}};exports.useExportToExcel=j;
