"use client"
import{k as P}from"./chunk-FUECQ2KU.mjs";import{a as h}from"./chunk-EXIDG7B4.mjs";import{a as T}from"./chunk-NYK7ECCW.mjs";import{j as g,k as S,q as w}from"./chunk-N6TU54UG.mjs";import{flexRender as N,getCoreRowModel as O,useReactTable as W}from"@tanstack/react-table";import{AnimatePresence as B,motion as j}from"framer-motion";import{useEffect as V,useState as L}from"react";import{jsx as i,jsxs as l}from"react/jsx-runtime";var D=t=>g(["py-2.5 text-left text-sm leading-6 whitespace-nowrap border-gray-200 px-4 relative","border-l border-b",t==="menu"&&"bg-white border-l-transparent py-0 px-1"]);function oe(t){let{data:n,rowCount:m,columns:b,defaultColumn:x,columnPinning:y,pagination:s,onPaginationChange:f}=t,[a,p]=L(t.columnVisibility??{});V(()=>{t.columnVisibility&&!S(t.columnVisibility,a)&&p(t.columnVisibility??{})},[t.columnVisibility]),V(()=>{var r;(r=t.onColumnVisibilityChange)==null||r.call(t,a)},[a]);let v=W({data:n,rowCount:m,columns:b,defaultColumn:{minSize:120,size:0,maxSize:300,...x},getCoreRowModel:O(),onPaginationChange:f,onColumnVisibilityChange:r=>p(r),state:{pagination:s,columnVisibility:a,columnPinning:{left:[],right:[],...y}},initialState:{pagination:{pageIndex:1,pageSize:(s==null?void 0:s.pageSize)||w}},manualPagination:!0,autoResetPageIndex:!1,manualSorting:!0});return{...t,columnVisibility:a,table:v}}function ae({columns:t,data:n,loading:m,error:b,emptyState:x,cellRight:y,sortBy:s,sortOrder:f,onSortChange:a,sortableColumns:p=[],className:v,thClassName:r,tdClassName:R,table:o,pagination:u,resourceName:d,rowCount:I,children:A}){return l("div",{className:"relative border border-gray-200 bg-white sm:rounded-xl",children:[!b&&!!(n!=null&&n.length)||m?l("div",{className:"relative min-h-[400px] overflow-x-auto rounded-[inherit]",children:[l("table",{className:g(["group/table w-full border-separate border-spacing-0 transition-[border-spacing,margin-top]","[&_tr>*:first-child]:border-l-transparent","[&_tr>*:last-child]:border-r-transparent"],v),children:[i("thead",{children:o.getHeaderGroups().map(c=>i("tr",{children:c.headers.map(e=>{let C=p.includes(e.column.id),M=C?"button":"div";return i("th",{className:g(D(e.id),"select-none font-medium",z(e.column,!o.getRowModel().rows.length),r),style:{minWidth:e.column.columnDef.minSize,maxWidth:e.column.columnDef.maxSize,width:e.column.columnDef.size||"auto",...k(e.column)},children:i("div",{className:"flex items-center justify-between gap-6 !pr-0",children:l(M,{className:"flex items-center gap-2",...C&&{type:"button",disabled:!C,"aria-label":"Sort by column",onClick:()=>a==null?void 0:a({sortBy:e.column.id,sortOrder:s!==e.column.id||f==="asc"?"desc":"asc"})},children:[i("span",{children:e.isPlaceholder?null:N(e.column.columnDef.header,e.getContext())}),C&&i(h,{order:s===e.column.id?f||"desc":null})]})})},e.id)})},c.id))}),i("tbody",{children:o.getRowModel().rows.map(c=>i("tr",{children:c.getVisibleCells().map(e=>i("td",{className:g(D(e.column.id),"group text-gray-600",z(e.column,c.index===o.getRowModel().rows.length-1),R),style:{minWidth:e.column.columnDef.minSize,maxWidth:e.column.columnDef.maxSize,width:e.column.columnDef.size||"auto",...k(e.column)},children:l("div",{className:"flex w-full items-center justify-between overflow-hidden truncate",children:[i("div",{className:"min-w-0 shrink grow truncate",children:N(e.column.columnDef.cell,e.getContext())}),y==null?void 0:y(e)]})},e.id))},c.id))})]}),A]}):i("div",{className:"flex h-96 w-full items-center justify-center text-sm text-gray-500",children:b||x||`No ${(d==null?void 0:d(!0))||"items"} found.`}),u&&!b&&!!(n!=null&&n.length)&&!!I&&l("div",{className:"sticky bottom-0 mx-auto -mt-px flex w-full max-w-full items-center justify-between rounded-b-[inherit] border-t border-gray-200 bg-white px-4 py-3.5 text-sm leading-6 text-gray-600",children:[l("div",{children:[i("span",{className:"hidden sm:inline-block",children:"Viewing"})," ",l("span",{className:"font-medium",children:[(u.pageIndex-1)*u.pageSize+1,"-",Math.min((u.pageIndex-1)*u.pageSize+u.pageSize,o.getRowCount())]})," ","of"," ",i("span",{className:"font-medium",children:o.getRowCount().toLocaleString()})," ",(d==null?void 0:d(o.getRowCount()!==1))||"items"]}),l("div",{className:"flex items-center gap-2",children:[i(P,{variant:"secondary",text:"Previous",className:"h-7 px-2",onClick:()=>o.previousPage(),disabled:!o.getCanPreviousPage()}),i(P,{variant:"secondary",text:"Next",className:"h-7 px-2",onClick:()=>o.nextPage(),disabled:!o.getCanNextPage()})]})]}),i(B,{children:m&&i(j.div,{initial:{opacity:0},animate:{opacity:1},className:"absolute inset-0 flex items-center justify-center rounded-xl bg-white/50",children:i(T,{})})})]})}var z=(t,n)=>{let m=t.getIsPinned();return g(m&&!n&&"animate-table-pinned-shadow [animation-timeline:scroll(inline)]")},k=t=>{let n=t.getIsPinned();return{left:n==="left"?`${t.getStart("left")}px`:void 0,right:n==="right"?`${t.getAfter("right")}px`:void 0,position:n?"sticky":"relative"}};export{oe as a,ae as b};
