import{r as i,j as e,a3 as E,N as T,l as G}from"./index-B-YXshIJ.js";import{a as V,d as D}from"./index-Brfj1MB8.js";import{C as M,A as z}from"./AnimateHeight-DPr6lKJ-.js";import{i as F}from"./Icons-C9UDsqhh.js";import{T as H,g as J}from"./TinyAreaGraph-CpO36t7S.js";const P=s=>typeof s=="object"&&s!==null&&"type"in s&&s.type==="graph",Q=({data:s,columns:p,rowKey:A,ChildComponent:n,isChild:o=!1,defaultSortColumnIndex:y=0,variant:m,hasChild:x=()=>!0,additionalRowClassName:f})=>{const[b,w]=i.useState([]),[$,k]=i.useState([]),[u,R]=i.useState(y),[d,N]=i.useState(y===0?"asc":"desc"),g=i.useMemo(()=>{const{sorter:r}=p[u];return r?s==null?void 0:s.sort((d==="asc"?V:D)(r)):s},[p,s,u,d]);return e.jsxs("table",{className:"w-full ".concat(o?"bg-theme-secondary":m==="default"?"bg-theme-page-content":""),children:[e.jsx("thead",{children:e.jsxs("tr",{className:E(m==="default"?"bg-theme-hover border-b border-theme-seperator":"bg-theme-col-header","text-xs text-theme-helptext",o&&"border-y border-theme-seperator"),children:[e.jsx("th",{className:n||o?"w-12":"w-5",children:" "}),p.map((r,t)=>e.jsx("th",{className:"font-normal whitespace-nowrap ".concat(t===0?"text-left":"text-right pr-4"),children:e.jsxs("button",{className:"".concat(o?"":"uppercase"," ").concat(t===0?"pr-6":"pl-6"," py-2 ").concat(r.sorter?"":"cursor-default"),onClick:()=>{if(r.sorter){if(u===t)return N(h=>h==="asc"?"desc":"asc");R(t),N(t===0?"asc":"desc")}},children:[r.title,e.jsx("span",{className:"inline-block -mb-[0.125em] ml-1 transition-transform duration-200 ".concat(u===t?"w-3 ".concat(d==="asc"?"":"rotate-180"):"mr-3"),children:u===t?e.jsx(F,{className:"w-3 h-3"}):""})]})},"heading-".concat(r.key)))]})}),e.jsx("tbody",{children:g==null?void 0:g.map(r=>{const t=A(r),h=b.includes(t),S=c=>{c.stopPropagation(),n&&x(r)&&(h?(w(a=>a.filter(l=>l!==t)),k(a=>[...a,t])):w(a=>[...a,t]))};return e.jsxs(i.Fragment,{children:[e.jsxs("tr",{className:T("border-b border-theme-seperator",n&&x(r)&&"cursor-pointer hover:bg-theme-hover",o&&"text-sm",f==null?void 0:f(r)),onClick:S,children:[e.jsx("td",{children:n&&x(r)?e.jsx("button",{className:"block w-full h-full text-center",onClick:S,"aria-label":"Expand row",children:e.jsx(M,{size:18,className:"inline-block mb-[0.125rem] ml-4 transition-all duration-200 text-theme-icon ".concat(h?"rotate-90 text-theme-icon-active":"")})}):null}),p.map((c,a)=>{const l=c.value(r),j=P(l);return e.jsx("td",{className:E("align-top",a===0?"text-left":"text-right pr-8 whitespace-nowrap",j&&m==="default"?"py-1":"py-0",!j&&m==="default"?"py-4":"py-3",a===0&&!b.includes(t)||o||m==="default"?"":"font-semibold"),children:j?e.jsx(H,{data:l.data,itemToValue:G,color:l.color,graphConfig:J.small}):l},"".concat(t,"-").concat(c.key))})]}),n&&(b.includes(t)||$.includes(t))?e.jsx("tr",{children:e.jsx("td",{colSpan:p.length+1,className:"p-0",children:e.jsx(z,{collapse:$.includes(t),onCollapsed:()=>k(c=>c.filter(a=>a!==t)),children:e.jsx(n,{item:r})})})}):null]},t)})})]})};export{Q as S};
