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