import{a as e,t}from"./react-D0JuimcS.js";import{n,o as r}from"./utils-Dac180Gn.js";import{t as i}from"./createLucideIcon-CJ2NGl7n.js";import{t as a}from"./chevron-left-6kXheZvz.js";import{ga as o,yo as s}from"./index-BP3TYB4i.js";import{t as c}from"./card-BVFw-jgA.js";var l=i(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),u=i(`arrow-up-down`,[[`path`,{d:`m21 16-4 4-4-4`,key:`f6ql7i`}],[`path`,{d:`M17 20V4`,key:`1ejh1v`}],[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}]]),d=i(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),f=e(t(),1),p=r();function m({data:e,columns:t,isLoading:r,emptyMessage:i=`No data found`,rowKey:m,pageSize:h=15,pageSizeOptions:g=[10,15,25,50,100],footer:_,onRowClick:v,totalCount:y,currentPage:b,onPageChange:x,onPageSizeChange:S}){let C=(0,f.useMemo)(()=>t.map(e=>({...e,className:e.className?.replace(/\btext-right\b/g,`text-center`)})),[t]),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(`asc`),[O,k]=(0,f.useState)(1),[A,j]=(0,f.useState)(h),M=y!==void 0&&x!==void 0,N=e=>{w===e?D(e=>e===`asc`?`desc`:`asc`):(T(e),D(`asc`)),M||k(1)},P=(0,f.useMemo)(()=>w?[...e].sort((e,t)=>{let n=e[w],r=t[w],i=n==null?``:String(n),a=r==null?``:String(r),o=Number(i),s=Number(a),c;return c=!isNaN(o)&&!isNaN(s)&&i!==``&&a!==``?o-s:i.localeCompare(a,void 0,{numeric:!0,sensitivity:`base`}),E===`asc`?c:-c}):e,[e,w,E]),F=M?y:P.length,I=M?b||1:O,L=Math.max(1,Math.ceil(F/A)),R=Math.min(I,L),z=(R-1)*A,B=M?P:P.slice(z,z+A),V=e=>{M?x(e):k(e)},H=e=>{j(e),M?(S?.(e),x(1)):k(1)},U=({col:e})=>w===e?E===`asc`?(0,p.jsx)(d,{className:`ml-1 inline size-3`}):(0,p.jsx)(l,{className:`ml-1 inline size-3`}):(0,p.jsx)(u,{className:`ml-1 inline size-3 text-muted-foreground/40`}),W=z;return(0,p.jsxs)(c,{className:`p-0 overflow-hidden flex flex-col w-full max-w-full h-[calc(100vh-180px)]`,children:[(0,p.jsx)(`div`,{className:`flex-1 overflow-auto min-h-0`,children:(0,p.jsxs)(`table`,{className:`w-full text-sm border-collapse`,style:{minWidth:`800px`},children:[(0,p.jsxs)(`colgroup`,{children:[(0,p.jsx)(`col`,{style:{width:`40px`}}),C.map(e=>(0,p.jsx)(`col`,{},e.key))]}),(0,p.jsx)(`thead`,{className:`bg-blue-50 dark:bg-blue-950/30 sticky top-0 z-10`,children:(0,p.jsxs)(`tr`,{className:`border-b`,children:[(0,p.jsx)(`th`,{className:`text-left px-2 py-2 text-[11px] font-bold text-[#1a3c6e] dark:text-[#4a7ab5] uppercase tracking-wider`,children:`#`}),C.map(e=>(0,p.jsxs)(`th`,{className:`px-2 py-2 text-[11px] font-bold text-[#1a3c6e] dark:text-[#4a7ab5] uppercase tracking-wider whitespace-nowrap ${e.className||`text-left`} ${e.sortable===!1?``:`cursor-pointer select-none hover:text-[#142e55] dark:hover:text-[#8fb3d6]`}`,onClick:e.sortable===!1?void 0:()=>N(e.key),children:[e.label,e.sortable!==!1&&(0,p.jsx)(U,{col:e.key})]},e.key))]})}),(0,p.jsx)(`tbody`,{children:r?(0,p.jsx)(`tr`,{children:(0,p.jsx)(`td`,{colSpan:C.length+1,className:`text-center py-8 text-muted-foreground`,children:`Loading...`})}):B.length===0?(0,p.jsx)(`tr`,{children:(0,p.jsx)(`td`,{colSpan:C.length+1,className:`text-center py-8 text-muted-foreground`,children:i})}):B.map((e,t)=>(0,p.jsxs)(`tr`,{className:`border-b last:border-b-0 hover:bg-muted/30 transition-colors ${v?`cursor-pointer`:``}`,onClick:v?()=>v(e):void 0,children:[(0,p.jsx)(`td`,{className:`px-2 py-1.5 text-muted-foreground text-xs`,children:W+t+1}),C.map(r=>{let i=e[r.key],a;return a=r.render?r.render(e,W+t):r.key.includes(`date`)&&typeof i==`string`&&/^\d{4}-\d{2}-\d{2}/.test(i)?n(i):String(i??`—`),(0,p.jsx)(`td`,{className:`px-2 py-1.5 text-sm ${r.className||``}`,children:a},r.key)})]},m(e)))}),_&&(0,p.jsx)(`tfoot`,{children:_})]})}),(F>0||M)&&(0,p.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between border-t px-3 py-2 bg-muted/20 gap-2 flex-wrap`,children:[(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Rows per page:`}),(0,p.jsx)(`select`,{className:`border rounded px-1.5 py-0.5 text-xs h-7`,value:A,onChange:e=>H(Number(e.target.value)),children:g.map(e=>(0,p.jsx)(`option`,{value:e,children:e},e))})]}),(0,p.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[z+1,`–`,Math.min(z+A,F),` of `,F]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,p.jsx)(o,{variant:`outline`,size:`icon`,className:`size-7`,disabled:R<=1,onClick:()=>V(R-1),children:(0,p.jsx)(a,{className:`size-3.5`})}),Array.from({length:Math.min(L,5)},(e,t)=>{let n;return n=L<=5||R<=3?t+1:R>=L-2?L-4+t:R-2+t,(0,p.jsx)(o,{variant:n===R?`default`:`outline`,size:`icon`,className:`size-7 text-xs`,onClick:()=>V(n),children:n},n)}),(0,p.jsx)(o,{variant:`outline`,size:`icon`,className:`size-7`,disabled:R>=L,onClick:()=>V(R+1),children:(0,p.jsx)(s,{className:`size-3.5`})})]})]})]})}export{m as t};