"use client"
import{b as w}from"./chunk-APZP4YU4.mjs";import{a as T}from"./chunk-6OXPQMNH.mjs";import{a as S}from"./chunk-LONL47IJ.mjs";import{h as g}from"./chunk-5WAMXBD2.mjs";import{flexRender as z,getCoreRowModel as D,useReactTable as M}from"@tanstack/react-table";import{AnimatePresence as $,motion as j}from"framer-motion";import{useEffect as A,useMemo as H,useState as I}from"react";import{jsx as t,jsxs as o}from"react/jsx-runtime";var P=g(["py-2.5 text-left text-sm leading-6 whitespace-nowrap border-gray-200 px-4 relative","border-r border-b"]);function Z(a){let{data:s,rowCount:p,columns:u,defaultColumn:C,resizeColumns:l=!0,pagination:b,onPaginationChange:y}=a,[r,f]=I(a.columnVisibility??{});A(()=>{f(a.columnVisibility??{})},[a.columnVisibility]);let v=M({data:s,rowCount:p,columns:u,defaultColumn:{minSize:60,size:150,maxSize:250,...C},columnResizeMode:l?"onChange":void 0,getCoreRowModel:D(),onPaginationChange:y,onColumnVisibilityChange:f,state:{pagination:b,columnVisibility:r},manualPagination:!0,autoResetPageIndex:!1,manualSorting:!0});return{...a,columnVisibility:r,resizeColumns:l,table:v}}function G({columns:a,data:s,loading:p,error:u,emptyState:C,cellRight:l,sortBy:b,sortOrder:y,onSortChange:r,sortableColumns:f=[],resizeColumns:v,columnVisibility:h={},className:N,thClassName:V,tdClassName:k,table:i,pagination:m,resourceName:c}){let R=H(()=>{let n=i.getFlatHeaders(),e={};for(let d=0;d<n.length;d++){let x=n[d];e[`--header-${x.id}-size`]=x.getSize(),e[`--col-${x.column.id}-size`]=x.column.getSize()}return e},[a,h,i.getState().columnSizingInfo,i.getState().columnSizing]);return o("div",{className:"relative border border-gray-200 bg-white sm:rounded-xl",children:[!u&&!!(s!=null&&s.length)||p?t("div",{className:"min-h-[400px] overflow-x-auto rounded-[inherit]",children:o("table",{className:g(["group/table w-full table-fixed border-separate border-spacing-0 transition-[border-spacing,margin-top]","[&_tr>*:first-child]:border-l-transparent","[&_tr>*:last-child]:border-r-transparent"],N),style:R,children:[t("thead",{children:i.getHeaderGroups().map(n=>t("tr",{children:n.headers.map(e=>{let d=f.includes(e.column.id);return o("th",{className:g(P,"select-none font-medium",V),style:{width:`calc(var(--header-${e==null?void 0:e.id}-size) * 1px)`},children:[t("div",{className:"flex items-center justify-between gap-6 !pr-0",children:o("button",{type:"button",className:"flex items-center gap-2",disabled:!d,onClick:()=>r==null?void 0:r({sortBy:e.column.id,sortOrder:b!==e.column.id||y==="asc"?"desc":"asc"}),"aria-label":"Sort by column",children:[t("span",{children:e.isPlaceholder?null:z(e.column.columnDef.header,e.getContext())}),d&&t(T,{order:b===e.column.id?y||"desc":null})]})}),v&&e.index<n.headers.length-1&&t("div",{className:"absolute -right-[4px] top-0 z-[1] h-full w-[7px] cursor-col-resize",...{onDoubleClick:()=>e.column.resetSize(),onMouseDown:e.getResizeHandler(),onTouchStart:e.getResizeHandler()}})]},e.id)})},n.id))}),t("tbody",{children:i.getRowModel().rows.map(n=>t("tr",{children:n.getVisibleCells().map(e=>t("td",{className:g(P,"group text-gray-600",k),style:{width:`calc(var(--col-${e.column.id}-size) * 1px)`},children:o("div",{className:"flex w-full items-center justify-between overflow-hidden truncate",children:[t("div",{className:"min-w-0 shrink grow",children:z(e.column.columnDef.cell,e.getContext())}),l==null?void 0:l(e)]})},e.id))},n.id))})]})}):t("div",{className:"flex h-96 w-full items-center justify-center text-sm text-gray-500",children:u||C||`No ${(c==null?void 0:c(!0))||"items"} found.`}),m&&!u&&!!(s!=null&&s.length)&&o("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:[o("div",{children:[t("span",{className:"hidden sm:inline-block",children:"Viewing"})," ",o("span",{className:"font-medium",children:[m.pageIndex*m.pageSize+1,"-",Math.min(m.pageIndex*m.pageSize+m.pageSize,i.getRowCount())]})," ","of"," ",t("span",{className:"font-medium",children:i.getRowCount().toLocaleString()})," ",(c==null?void 0:c(i.getRowCount()!==1))||"items"]}),o("div",{className:"flex items-center gap-2",children:[t(w,{variant:"secondary",text:"Previous",className:"h-7 px-2",onClick:()=>i.previousPage(),disabled:!i.getCanPreviousPage()}),t(w,{variant:"secondary",text:"Next",className:"h-7 px-2",onClick:()=>i.nextPage(),disabled:!i.getCanNextPage()})]})]}),t($,{children:p&&t(j.div,{initial:{opacity:0},animate:{opacity:1},className:"absolute inset-0 flex items-center justify-center rounded-xl bg-white/50",children:t(S,{})})})]})}export{Z as a,G as b};
