import{n as _,u as H,j as e,c as g}from"./index-O0BQoyzo.js";import{r as P}from"./react-Cb2sDjhD.js";import{T as $,a as q,b as u,c as D,d as B,e as b}from"./table-CPn1MRcy.js";import{E}from"./empty-state-C-qjOHyu.js";import{A as F}from"./arrow-up-63xELY5Q.js";import{A as L}from"./arrow-down-BXvC8Al2.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const O=_("ArrowUpDown",[["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"}]]);function V({columns:i,rows:r,getRowId:m,loading:N=!1,loadingRows:k=5,emptyState:y,onRowClick:h,selection:n,onSelectionChange:v,sort:x,onSortChange:p,className:M}){const{t:f}=H("common"),t=n!==void 0&&v!==void 0,j=t&&r.length>0&&r.every(a=>n.has(m(a))),T=t&&r.some(a=>n.has(m(a)))&&!j;function w(){if(!t)return;const a=new Set(n);if(j)for(const s of r)a.delete(m(s));else for(const s of r)a.add(m(s));v(a)}function A(a){if(!t)return;const s=new Set(n);s.has(a)?s.delete(a):s.add(a),v(s)}function U(a){p&&(!x||x.id!==a?p({id:a,dir:"asc"}):x.dir==="asc"?p({id:a,dir:"desc"}):p(null))}return e.jsxs("div",{className:g("w-full",M),children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs($,{children:[e.jsx(q,{children:e.jsxs(u,{children:[t&&e.jsx(D,{className:"w-10",children:e.jsx("input",{type:"checkbox",role:"checkbox","aria-label":f("table.selectAll"),"aria-checked":T?"mixed":j,checked:j,ref:a=>{a&&(a.indeterminate=T)},onChange:w,disabled:N||r.length===0,className:"h-4 w-4 accent-accent cursor-pointer"})}),i.map(a=>e.jsx(D,{className:a.headClassName,children:a.sortable&&p?e.jsxs("button",{type:"button",onClick:()=>U(a.id),className:g("inline-flex items-center gap-1","uppercase tracking-wide","hover:text-text transition-colors"),children:[a.header,x?.id===a.id?x.dir==="asc"?e.jsx(F,{className:"h-3 w-3"}):e.jsx(L,{className:"h-3 w-3"}):e.jsx(O,{className:"h-3 w-3 opacity-50"})]}):a.header},a.id))]})}),e.jsx(B,{children:N?Array.from({length:k}).map((a,s)=>e.jsxs(u,{children:[t&&e.jsx(b,{}),i.map(c=>e.jsx(b,{className:c.cellClassName,children:e.jsx("div",{className:"h-4 w-3/4 rounded bg-surface-2 animate-pulse"})},c.id))]},`skeleton-${s}`)):r.length===0?e.jsx(u,{children:e.jsx(b,{colSpan:i.length+(t?1:0),className:"p-0",children:y??e.jsx(E,{title:f("states.empty")})})}):r.map((a,s)=>{const c=m(a),o=t&&n.has(c);return e.jsxs(u,{"data-state":o?"selected":void 0,onClick:h?()=>h(a):void 0,className:h?"cursor-pointer":void 0,children:[t&&e.jsx(b,{onClick:d=>d.stopPropagation(),children:e.jsx("input",{type:"checkbox",role:"checkbox","aria-label":f("table.selectRow"),checked:o,onChange:()=>A(c),className:"h-4 w-4 accent-accent cursor-pointer"})}),i.map(d=>e.jsx(b,{className:d.cellClassName,children:d.cell(a,s)},d.id))]},c)})})]})}),e.jsx("div",{className:"md:hidden flex flex-col gap-2",children:N?Array.from({length:Math.min(3,k)}).map((a,s)=>e.jsxs("div",{className:"rounded-md border border-border bg-surface p-3 space-y-2",children:[e.jsx("div",{className:"h-4 w-1/2 rounded bg-surface-2 animate-pulse"}),e.jsx("div",{className:"h-3 w-3/4 rounded bg-surface-2 animate-pulse"}),e.jsx("div",{className:"h-3 w-2/3 rounded bg-surface-2 animate-pulse"})]},`mskel-${s}`)):r.length===0?y??e.jsx(E,{title:f("states.empty")}):r.map((a,s)=>{const c=m(a),o=t&&n.has(c),d=i.find(l=>l.asCardTitle)??i[0],C=i.filter(l=>!l.asCardTitle&&!l.hideOnMobile&&l.id!==d?.id);return e.jsxs("div",{"data-state":o?"selected":void 0,onClick:h?()=>h(a):void 0,className:g("rounded-md border bg-surface p-3",o?"border-accent":"border-border",h&&"cursor-pointer active:bg-surface-hover"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[d&&e.jsx("div",{className:"font-medium text-text",children:d.cell(a,s)}),t&&e.jsx("input",{type:"checkbox",role:"checkbox","aria-label":f("table.selectRow"),checked:!!o,onChange:()=>A(c),onClick:l=>l.stopPropagation(),className:"h-4 w-4 accent-accent cursor-pointer mt-0.5"})]}),C.length>0&&e.jsx("dl",{className:"mt-2 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1 text-sm",children:C.map(l=>e.jsxs(P.Fragment,{children:[e.jsx("dt",{className:"text-text-dim",children:l.header}),e.jsx("dd",{className:"text-text",children:l.cell(a,s)})]},l.id))})]},c)})})]})}V.displayName="DataTable";export{V as D};
//# sourceMappingURL=data-table-S7rIjwdO.js.map
