import{j as e,B as b,T as g,g as j,P as S,C as k}from"./index-B1H8BCL7.js";import{d as T}from"./FileDownloadOutlined-B1TjRPKt.js";import{d as z}from"./Refresh-942gtAB1.js";import{S as p}from"./Stack-BIAbaqpj.js";import{T as R}from"./TableContainer-CXAjhAg6.js";import{T as v,c as A,b as h,a as $}from"./TableRow-BfKE_xn9.js";import{T as u}from"./TableCell-D8CotAsC.js";const y=o=>{if(o==null)return"";const r=String(o);return r.includes(",")||r.includes('"')||r.includes(`
`)||r.includes("\r")?`"${r.replaceAll('"','""')}"`:r};function B(o,r,i){if(!Array.isArray(r)||!Array.isArray(i)||i.length===0)return;const l=i.map(t=>y(t.header??t.key)).join(","),n=r.map(t=>i.map(c=>{const a=t==null?void 0:t[c.key],m=c.format?c.format(a,t):a;return y(m)}).join(",")),f=[l,...n].join(`
`),d=new Blob(["\uFEFF"+f],{type:"text/csv;charset=utf-8;"}),x=URL.createObjectURL(d),s=document.createElement("a");s.href=x,s.download=o,document.body.appendChild(s),s.click(),document.body.removeChild(s),setTimeout(()=>URL.revokeObjectURL(x),100)}function F(){const o=new Date;return`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`}const O=({title:o,subtitle:r,filters:i,columns:l,rows:n,isFetching:f,refetch:d,csvFilenameStem:x})=>{const s=()=>{!n||n.length===0||B(`${x}-${F()}.csv`,n,l)};return e.jsxs(b,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[e.jsxs(p,{direction:"row",justifyContent:"space-between",alignItems:"flex-start",sx:{mb:1.5},children:[e.jsxs(b,{children:[e.jsx(g,{sx:{fontSize:"1rem",fontWeight:700},children:o}),r&&e.jsx(g,{sx:{fontSize:"0.74rem",color:"#94a3b8",mt:.25},children:r})]}),e.jsxs(p,{direction:"row",spacing:1,children:[e.jsx(j,{size:"small",variant:"outlined",startIcon:e.jsx(z,{sx:{fontSize:16}}),onClick:()=>d==null?void 0:d(),sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.78rem"},children:"Refresh"}),e.jsx(j,{size:"small",variant:"contained",disableElevation:!0,startIcon:e.jsx(T,{sx:{fontSize:16}}),onClick:s,disabled:!n||n.length===0,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.78rem",backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"CSV"})]})]}),i&&e.jsx(S,{variant:"outlined",sx:{p:1.5,mb:1.5,borderRadius:2,borderColor:"#e2e8f0",boxShadow:"none"},children:i}),e.jsx(p,{direction:"row",spacing:1.5,sx:{mb:1.5},children:e.jsx(k,{label:`${(n==null?void 0:n.length)??0} rows`,size:"small",sx:{backgroundColor:"#f1f5f9",color:"#475569",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}})}),e.jsx(R,{component:S,variant:"outlined",sx:{borderRadius:2,borderColor:"#e2e8f0",boxShadow:"none",overflow:"auto"},children:e.jsxs(v,{size:"small",sx:{minWidth:720},children:[e.jsx(A,{children:e.jsx(h,{sx:{backgroundColor:"#f8fafc"},children:l.map(t=>e.jsx(u,{sx:{...L,textAlign:t.align??"left",width:t.width},children:t.header??t.key},t.key))})}),e.jsx($,{children:!n||n.length===0?e.jsx(h,{children:e.jsx(u,{colSpan:l.length,sx:{textAlign:"center",py:5,color:"#94a3b8",fontSize:"0.8125rem"},children:f?"Loading…":"No data for the selected filters"})}):n.map((t,c)=>e.jsx(h,{hover:!0,children:l.map(a=>{const m=t[a.key],C=a.format?a.format(m,t):m??"—";return e.jsx(u,{sx:{...E,textAlign:a.align??"left",fontVariantNumeric:a.align==="right"?"tabular-nums":"normal"},children:C},a.key)})},c))})]})})]})},L={fontSize:"0.7rem",fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em",py:1.25,px:2,borderBottom:"1px solid #e2e8f0",whiteSpace:"nowrap"},E={fontSize:"0.8125rem",py:1,px:2,borderBottom:"1px solid #f1f5f9"};export{O as R};
