@piyushnagar/react-editable-table
Version:
A comprehensive, feature-rich React table component with inline editing, sorting, filtering, column resizing, and more
209 lines • 84.2 kB
JavaScript
(function(V,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(V=typeof globalThis<"u"?globalThis:V||self,e(V.ReactEditableTable={},V.React,V.React))})(this,function(V,e,h){"use strict";/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/var Xt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ht=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().trim(),W=(t,r)=>{const a=h.forwardRef(({color:l="currentColor",size:c=24,strokeWidth:p=2,absoluteStrokeWidth:v,className:b="",children:k,...f},N)=>h.createElement("svg",{ref:N,...Xt,width:c,height:c,stroke:l,strokeWidth:v?Number(p)*24/Number(c):p,className:["lucide",`lucide-${Ht(t)}`,b].join(" "),...f},[...r.map(([y,i])=>h.createElement(y,i)),...Array.isArray(k)?k:[k]]));return a.displayName=`${t}`,a};/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Me=W("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ae=W("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Gt=W("BoxSelect",[["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M21 19a2 2 0 0 1-2 2",key:"1j7049"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h1",key:"15o7lz"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M14 21h1",key:"v9vybs"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v1",key:"mxsmne"}],["path",{d:"M3 14v1",key:"vnatye"}],["path",{d:"M21 14v1",key:"169vum"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Xe=W("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ie=W("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Yt=W("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const He=W("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Zt=W("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const $e=W("Clipboard",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const _t=W("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ee=W("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ge=W("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ye=W("EyeOff",[["path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24",key:"1jxqfv"}],["path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68",key:"9wicm4"}],["path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61",key:"1jreej"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ze=W("Eye",[["path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z",key:"rwhkz3"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const _e=W("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ut=W("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Ue=W("GripVertical",[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Jt=W("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Qt=W("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Rt=W("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z",key:"ymcmye"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Je=W("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Fe=W("Scissors",[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Qe=W("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Re=W("Table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const we=W("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const et=W("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const er=W("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const tr=W("XCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
* @license lucide-react v0.344.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const me=W("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),tt=({column:t,data:r,activeFilters:a,sortConfig:l,onFilterChange:c,onSort:p,onClearFilter:v})=>{const[b,k]=h.useState(!1),[f,N]=h.useState(""),[y,i]=h.useState("right"),x=h.useRef(null),n=h.useRef(null),s=h.useMemo(()=>{const S=r.map(X=>{const H=X[t.id];return H==null?"(Blank)":t.type==="multiselect"&&Array.isArray(H)?H:t.type==="boolean"?H?"True":"False":t.type==="date"&&H?new Date(H).toLocaleDateString():t.type==="number"?Number(H).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):t.type==="integer"?Number(H).toLocaleString():String(H)});let O;t.type==="multiselect"?O=S.reduce((X,H)=>(Array.isArray(H)?X.push(...H):H==="(Blank)"&&X.push(H),X),[]):O=S;const q=Array.from(new Set(O)).sort(),U=q.indexOf("(Blank)");return U>-1&&(q.splice(U,1),q.push("(Blank)")),q},[r,t.id,t.type]),o=s.filter(S=>S.toLowerCase().includes(f.toLowerCase())),u=a[t.id]||[],g=u.length>0,M=(l==null?void 0:l.column)===t.id,$=h.useCallback(()=>{if(!n.current)return;const S=n.current.getBoundingClientRect(),O=window.innerWidth,q=320,U=O-S.right,X=S.left;U>=q?i("right"):X>=q?i("left"):i(U>X?"right":"left")},[]),F=()=>{b||$(),k(!b)};h.useEffect(()=>{const S=O=>{x.current&&!x.current.contains(O.target)&&(k(!1),N(""))};return b&&document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[b]),h.useEffect(()=>{const S=()=>{b&&$()};return window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[b,$]);const j=S=>{const O=u,q=O.includes(S)?O.filter(U=>U!==S):[...O,S];c(t.id,q)},z=()=>{c(t.id,o)},A=()=>{c(t.id,[])},K=()=>{v(t.id),k(!1)},D=o.length>0&&o.every(S=>u.includes(S)),E=o.some(S=>u.includes(S));return e.jsxs("div",{className:"relative",ref:x,children:[e.jsx("button",{ref:n,onClick:F,className:`
p-0.5 rounded hover:bg-gray-200 transition-colors flex items-center flex-shrink-0 relative z-20
${g?"text-blue-600 bg-blue-50":"text-gray-400"}
${M?"text-blue-600":""}
`,title:"Filter and sort",children:e.jsx(Ie,{className:"w-2.5 h-2.5"})}),b&&e.jsxs("div",{className:`absolute top-full mt-1 bg-white border border-gray-200 rounded-lg shadow-lg z-[9999] min-w-64 max-w-80 ${y==="left"?"right-full mr-1":"left-0"}`,style:{minWidth:"256px",maxWidth:"320px"},children:[e.jsxs("div",{className:"p-3 border-b border-gray-100",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:t.title}),e.jsx("button",{onClick:()=>k(!1),className:"p-1 hover:bg-gray-100 rounded",children:e.jsx(me,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex gap-1 mb-2",children:[e.jsxs("button",{onClick:()=>p(t.id),className:`
flex items-center px-2 py-1 text-xs rounded transition-colors
${M&&(l==null?void 0:l.direction)==="asc"?"bg-blue-100 text-blue-700":"hover:bg-gray-100 text-gray-600"}
`,children:[e.jsx(Ae,{className:"w-3 h-3 mr-1"}),"Sort A→Z"]}),e.jsxs("button",{onClick:()=>p(t.id),className:`
flex items-center px-2 py-1 text-xs rounded transition-colors
${M&&(l==null?void 0:l.direction)==="desc"?"bg-blue-100 text-blue-700":"hover:bg-gray-100 text-gray-600"}
`,children:[e.jsx(Me,{className:"w-3 h-3 mr-1"}),"Sort Z→A"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Qe,{className:"w-4 h-4 absolute left-2 top-1/2 transform -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search values...",value:f,onChange:S=>N(S.target.value),className:"w-full pl-8 pr-3 py-1 text-sm border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-blue-500"})]})]}),e.jsxs("div",{className:"p-2",children:[e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:z,disabled:D,className:"text-xs text-blue-600 hover:text-blue-700 disabled:text-gray-400 disabled:cursor-not-allowed",children:"Select All"}),e.jsx("button",{onClick:A,disabled:!E,className:"text-xs text-blue-600 hover:text-blue-700 disabled:text-gray-400 disabled:cursor-not-allowed",children:"Deselect All"}),g&&e.jsx("button",{onClick:K,className:"text-xs text-red-600 hover:text-red-700 ml-auto",children:"Clear Filter"})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto",children:o.length===0?e.jsx("div",{className:"text-sm text-gray-500 py-2 text-center",children:"No values found"}):o.map(S=>{const O=u.includes(S);return e.jsxs("label",{className:"flex items-center py-1 px-2 hover:bg-gray-50 rounded cursor-pointer",children:[e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("input",{type:"checkbox",checked:O,onChange:()=>j(S),className:"sr-only"}),e.jsx("div",{className:`
w-4 h-4 border-2 rounded flex items-center justify-center mr-2
${O?"bg-blue-600 border-blue-600":"border-gray-300 hover:border-gray-400"}
`,children:O&&e.jsx(Xe,{className:"w-3 h-3 text-white"})})]}),e.jsx("span",{className:"text-sm text-gray-700 truncate flex-1",children:S})]},S)})})]}),e.jsx("div",{className:"p-2 border-t border-gray-100 text-xs text-gray-500",children:u.length>0?`${u.length} of ${s.length} selected`:`${s.length} items`})]})]})},rt=({columnId:t,onMouseDown:r,isResizing:a})=>{const l=c=>{c.preventDefault(),c.stopPropagation(),r(c,t)};return e.jsx("div",{className:`
absolute right-0 top-0 bottom-0 cursor-col-resize z-30 group/resizer
transition-all duration-150 ease-out
${a?"bg-blue-500 w-1":"bg-transparent hover:bg-blue-300 w-1 hover:w-1.5"}
`,onMouseDown:l,style:{right:"-2px",minWidth:"4px"},title:"Drag to resize column",children:e.jsx("div",{className:`
absolute inset-0 transition-all duration-150
${a?"bg-blue-600 shadow-lg":"bg-blue-400 opacity-0 group-hover/resizer:opacity-100"}
`})})},st=({columns:t,data:r,sortConfig:a,columnFilters:l,onSort:c,onFilterChange:p,onClearFilter:v,onAddColumn:b,onDeleteColumn:k,showColumnActions:f=!1,onColumnResize:N,isResizing:y=!1,resizingColumnId:i,onColumnDragStart:x,onColumnDragEnd:n,onColumnDragOver:s,onColumnDragLeave:o,onColumnDrop:u,draggedColumnIndex:g,dragOverColumnIndex:M})=>{const $=(A,K)=>{x&&x(A,K)},F=A=>{n==null||n(A)},j=(A,K)=>{s==null||s(A,K)},z=(A,K)=>{u==null||u(A,K)};return e.jsx("thead",{className:"bg-gray-50 border-b border-gray-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-12 px-1 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider bg-gray-100 border-r border-gray-200",children:e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("span",{className:"text-xs",children:"#"})})}),t.map((A,K)=>e.jsxs("th",{className:`
px-2 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider
relative group border-r border-gray-200 select-none overflow-visible cursor-grab active:cursor-grabbing
transition-all duration-150 ease-out
${g===K?"opacity-50 bg-blue-50":""}
${M===K?"bg-blue-100 border-blue-300 border-2":""}
${y&&i===A.id?"bg-blue-50":""}
`,style:{width:A.width||150,minWidth:Math.max(60,A.width||150),maxWidth:A.width||150},draggable:!0,onDragStart:D=>$(D,K),onDragEnd:F,onDragOver:D=>j(D,K),onDragLeave:o,onDrop:D=>z(D,K),title:`${A.title} - Drag to reorder column`,children:[e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("div",{className:"flex items-center min-w-0 flex-1 mr-1 overflow-hidden",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Ue,{className:"w-3 h-3 text-gray-400 group-hover:text-gray-600 mr-1 flex-shrink-0"}),e.jsx("span",{className:"truncate text-xs",title:A.title,children:A.title})]})}),e.jsxs("div",{className:"flex items-center flex-shrink-0 relative z-20",children:[A.sortable&&e.jsxs("button",{onClick:()=>c(A.id),className:"flex flex-col items-center hover:bg-gray-200 p-0.5 rounded transition-colors relative z-20",children:[e.jsx(Zt,{className:`w-2 h-2 ${(a==null?void 0:a.column)===A.id&&(a==null?void 0:a.direction)==="asc"?"text-blue-600":"text-gray-400"}`}),e.jsx(Ie,{className:`w-2 h-2 -mt-0.5 ${(a==null?void 0:a.column)===A.id&&(a==null?void 0:a.direction)==="desc"?"text-blue-600":"text-gray-400"}`})]}),e.jsx(tt,{column:A,data:r,activeFilters:l,sortConfig:a,onFilterChange:p,onSort:c,onClearFilter:v}),f&&e.jsx("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity flex items-center ml-1",children:e.jsx("button",{onClick:()=>k==null?void 0:k(A.id),className:"p-0.5 hover:bg-red-100 rounded text-red-600 transition-colors",title:"Delete column",children:e.jsx(we,{className:"w-3 h-3"})})})]})]}),N&&e.jsx(rt,{columnId:A.id,onMouseDown:N,isResizing:y&&i===A.id})]},A.id)),b&&e.jsx("th",{className:"px-4 py-3 w-12",children:e.jsx("button",{onClick:b,className:"p-1 hover:bg-blue-100 rounded text-blue-600 transition-colors",title:"Add column",children:e.jsx(Je,{className:"w-4 h-4"})})})]})})},rr=t=>t&&typeof t=="object"&&t.id&&Array.isArray(t.rows)?t:{id:`subtable-${Date.now()}-${Math.random()}`,rows:Array.isArray(t)?t:[]},lt=({row:t,column:r,value:a,position:l,isSelected:c,isInSelection:p,onValueChange:v,onCellClick:b,onCellRightClick:k,isEditing:f,onStartEdit:N,onStopEdit:y,onConfirmAndMoveDown:i,expandedSubTables:x=new Set,onToggleSubTable:n})=>{var be,se,I,P,Y;const[s,o]=h.useState(a),u=h.useRef(null),g=h.useRef(null);h.useEffect(()=>{o(a)},[a]),h.useEffect(()=>{f&&u.current&&setTimeout(()=>{if(u.current&&(u.current.focus(),u.current instanceof HTMLInputElement&&u.current.type==="text")){const m=u.current.value.length;u.current.setSelectionRange(m,m)}},0)},[f]);const M=()=>{v(t.id,r.id,s),y()},$=()=>{v(t.id,r.id,s),i()},F=m=>{m.key==="Enter"||m.key==="Return"?(m.preventDefault(),$()):m.key==="Escape"&&(m.preventDefault(),o(a),y())},j=m=>{const T=Array.isArray(s)?s:[],te=T.includes(m)?T.filter(J=>J!==m):[...T,m];o(te)},z=m=>{var R;const T=m.target.files;if(!T)return;const te=Array.isArray(s)?s:[],J=r.maxFiles||10,re=r.maxFileSize||100*1024*1024,ce=r.acceptedFileTypes||[],ae=[],xe=te.reduce((ie,ee)=>ie+ee.size,0);for(let ie=0;ie<T.length;ie++){const ee=T[ie];if(xe+ae.reduce((Z,de)=>Z+de.size,0)+ee.size>re){const Z=re-xe-ae.reduce((de,fe)=>de+fe.size,0);alert(`Adding "${ee.name}" would exceed the total size limit of ${(re/1024/1024).toFixed(1)}MB. Remaining space: ${(Z/1024/1024).toFixed(1)}MB`);continue}if(ce.length>0){const Z="."+((R=ee.name.split(".").pop())==null?void 0:R.toLowerCase());if(!ce.some(fe=>fe.startsWith(".")?fe.toLowerCase()===Z:ee.type.includes(fe))){alert(`File "${ee.name}" type is not allowed. Accepted types: ${ce.join(", ")}`);continue}}if(te.length+ae.length>=J){alert(`Maximum ${J} files allowed`);break}const Te={id:`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:ee.name,size:ee.size,type:ee.type,url:URL.createObjectURL(ee),file:ee};ae.push(Te)}ae.length>0&&o([...te,...ae]),g.current&&(g.current.value="")},A=m=>{const T=Array.isArray(s)?s:[],te=T.filter(re=>re.id!==m),J=T.find(re=>re.id===m);J!=null&&J.url&&URL.revokeObjectURL(J.url),o(te)},K=m=>{if(m.url){const T=document.createElement("a");T.href=m.url,T.download=m.name,document.body.appendChild(T),T.click(),document.body.removeChild(T)}},D=m=>m.startsWith("video/")||[".mp4",".avi",".mov",".wmv",".flv",".webm",".mkv",".m4v"].some(T=>m.toLowerCase().includes(T.replace(".",""))),E=m=>m.startsWith("image/")||[".jpg",".jpeg",".png",".gif",".bmp",".webp",".svg"].some(T=>m.toLowerCase().includes(T.replace(".",""))),S=m=>D(m)?e.jsx("div",{className:"w-4 h-4 bg-red-500 rounded flex items-center justify-center text-white text-xs font-bold",children:"▶"}):E(m)?e.jsx("div",{className:"w-4 h-4 bg-green-500 rounded flex items-center justify-center text-white text-xs font-bold",children:"🖼"}):e.jsx(_e,{className:"w-4 h-4 text-gray-500 flex-shrink-0"}),O=m=>{if(m===0)return"0 Bytes";const T=1024,te=["Bytes","KB","MB","GB"],J=Math.floor(Math.log(m)/Math.log(T));return parseFloat((m/Math.pow(T,J)).toFixed(2))+" "+te[J]},q=m=>{m.preventDefault(),m.stopPropagation(),b(l)},U=()=>{r.editable&&(b(l),N())},X=m=>{m.preventDefault(),m.stopPropagation(),k(m,l)},H=()=>{if(n&&(n(t.id,r.id),!x.has(`${t.id}-${r.id}`)&&(!a||!a.rows))){const T={id:`subtable-${t.id}-${r.id}`,rows:[]};v(t.id,r.id,T)}},Q=`
p-2 h-full flex items-center cursor-pointer transition-colors border-2 min-w-0 overflow-hidden
${c?"border-blue-500 bg-blue-50":"border-transparent"}
${p?"bg-blue-100":"hover:bg-gray-50"}
${f?"bg-white":""}
`.trim();if(!r.editable)return e.jsx("div",{className:Q,onClick:q,onContextMenu:X,children:at(a,r.type)});if(f)return e.jsx("div",{className:"p-1",children:r.type==="file"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-3 text-center hover:border-gray-400 transition-colors",children:[e.jsx("input",{ref:g,type:"file",multiple:!0,accept:(be=r.acceptedFileTypes)==null?void 0:be.join(","),onChange:z,className:"hidden",id:`file-input-${t.id}-${r.id}`}),e.jsxs("label",{htmlFor:`file-input-${t.id}-${r.id}`,className:"cursor-pointer flex flex-col items-center space-y-1",children:[e.jsx(et,{className:"w-6 h-6 text-gray-400"}),e.jsx("span",{className:"text-sm text-gray-600",children:"Click to upload files"}),e.jsx("span",{className:"text-xs text-gray-400",children:(se=r.acceptedFileTypes)!=null&&se.length?`Accepted: ${r.acceptedFileTypes.join(", ")}`:"All file types accepted"}),r.maxFileSize&&e.jsxs("span",{className:"text-xs text-gray-400",children:["Total limit: ",O(r.maxFileSize)]})]})]}),Array.isArray(s)&&s.length>0&&e.jsxs("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:[e.jsxs("div",{className:"text-xs text-gray-500 px-2 py-1 bg-gray-100 rounded",children:["Total size: ",O(s.reduce((m,T)=>m+T.size,0)),r.maxFileSize&&` / ${O(r.maxFileSize)}`]}),s.map(m=>e.jsxs("div",{className:"space-y-2",children:[m.url&&D(m.type)&&e.jsxs("div",{className:"relative",children:[e.jsx("video",{src:m.url,className:"w-full h-24 object-cover rounded border bg-black",controls:!0,preload:"metadata",children:"Your browser does not support video playback."}),e.jsx("div",{className:"absolute top-1 right-1 bg-black bg-opacity-50 text-white text-xs px-1 rounded",children:"VIDEO"})]}),m.url&&E(m.type)&&e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:m.url,alt:m.name,className:"w-full h-24 object-cover rounded border",onError:T=>{T.target.style.display="none"}}),e.jsx("div",{className:"absolute top-1 right-1 bg-black bg-opacity-50 text-white text-xs px-1 rounded",children:"IMAGE"})]}),e.jsxs("div",{className:"flex items-center justify-between p-2 bg-gray-50 rounded border text-sm",children:[e.jsxs("div",{className:"flex items-center space-x-2 min-w-0 flex-1",children:[S(m.type),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium text-gray-700",children:m.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[O(m.size)," • ",m.type]})]})]}),e.jsxs("div",{className:"flex items-center space-x-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>K(m),className:"p-1 hover:bg-gray-200 rounded text-blue-600",title:"Download file",children:e.jsx(Ge,{className:"w-3 h-3"})}),e.jsx("button",{onClick:()=>A(m.id),className:"p-1 hover:bg-gray-200 rounded text-red-600",title:"Remove file",children:e.jsx(me,{className:"w-3 h-3"})})]})]})]},m.id))]}),e.jsxs("div",{className:"flex justify-end space-x-1",children:[e.jsx("button",{onClick:M,className:"px-3 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600",children:"Save"}),e.jsx("button",{onClick:()=>{o(a),y()},className:"px-3 py-1 text-xs bg-gray-300 text-gray-700 rounded hover:bg-gray-400",children:"Cancel"})]})]}):r.type==="multiselect"?e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"border border-blue-300 rounded p-1 bg-white max-h-32 overflow-y-auto",children:(I=r.options)==null?void 0:I.map(m=>{const T=Array.isArray(s)&&s.includes(m);return e.jsxs("label",{className:"flex items-center py-1 px-2 hover:bg-gray-50 rounded cursor-pointer text-sm",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:()=>j(m),className:"mr-2 w-3 h-3"}),e.jsx("span",{children:m})]},m)})}),e.jsxs("div",{className:"flex justify-end mt-1 space-x-1",children:[e.jsx("button",{onClick:M,className:"px-2 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600",children:"Save"}),e.jsx("button",{onClick:()=>{o(a),y()},className:"px-2 py-1 text-xs bg-gray-300 text-gray-700 rounded hover:bg-gray-400",children:"Cancel"})]})]}):r.type==="table"?e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"border border-blue-300 rounded p-1 bg-white max-h-32 overflow-y-auto",children:(P=r.options)==null?void 0:P.map(m=>{const T=Array.isArray(s)&&s.includes(m);return e.jsxs("label",{className:"flex items-center py-1 px-2 hover:bg-gray-50 rounded cursor-pointer text-sm",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:()=>j(m),className:"mr-2 w-3 h-3"}),e.jsx("span",{children:m})]},m)})}),e.jsxs("div",{className:"flex justify-end mt-1 space-x-1",children:[e.jsx("button",{onClick:M,className:"px-2 py-1 text-xs bg-blue-500 text-white rounded hover:bg-blue-600",children:"Save"}),e.jsx("button",{onClick:()=>{o(a),y()},className:"px-2 py-1 text-xs bg-gray-300 text-gray-700 rounded hover:bg-gray-400",children:"Cancel"})]})]}):r.type==="select"?e.jsxs("select",{ref:u,value:s||"",onChange:m=>o(m.target.value),onBlur:M,onKeyDown:F,className:"w-full p-1 border border-blue-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"Select..."}),(Y=r.options)==null?void 0:Y.map(m=>e.jsx("option",{value:m,children:m},m))]}):r.type==="boolean"?e.jsx("input",{ref:u,type:"checkbox",checked:s||!1,onChange:m=>o(m.target.checked),onBlur:M,onKeyDown:F,className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}):e.jsx("input",{ref:u,type:r.type==="number"||r.type==="integer"?"number":r.type==="date"?"date":"text",step:r.type==="integer"?"1":r.type==="number"?"0.01":void 0,value:s||"",onChange:m=>o(m.target.value),onBlur:M,onKeyDown:F,className:"w-full p-1 border border-blue-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500"})});if(r.type==="table"){const m=x.has(`${t.id}-${r.id}`);return e.jsx("div",{className:`${Q} ${m?"bg-blue-100 border-blue-400":""}`,onClick:q,onDoubleClick:H,onKeyDown:T=>{T.key==="Enter"&&H()},onContextMenu:X,children:e.jsxs("div",{className:"w-full flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Re,{className:`w-4 h-4 ${m?"text-blue-600":"text-gray-500"}`}),e.jsx("span",{className:`text-sm ${m?"text-blue-800 font-medium":"text-gray-700"}`,children:nt(a)})]}),e.jsx(He,{className:`w-4 h-4 transition-transform ${m?"rotate-90 text-blue-600":"text-gray-400"}`})]})})}return e.jsx("div",{tabIndex:0,className:Q,onClick:q,onDoubleClick:U,onKeyDown:m=>{m.key==="Enter"&&U()},onContextMenu:X,title:String(a||""),children:e.jsxs("div",{className:"w-full min-w-0 overflow-hidden flex items-center justify-between",children:[e.jsx("div",{className:"flex-1 min-w-0",children:at(a,r.type)}),(r.type==="select"||r.type==="multiselect")&&r.editable&&e.jsx(Ie,{className:"w-3 h-3 text-gray-400 flex-shrink-0 ml-1"})]})})},nt=t=>{const a=rr(t).rows.length;return a===0?"Empty table (double-click to expand)":`${a} row${a!==1?"s":""} (double-click to expand)`},at=(t,r)=>{if(t==null)return"";switch(r){case"table":return nt(t);case"file":return Array.isArray(t)&&t.length>0?e.jsxs("div",{className:"flex flex-wrap gap-1 min-w-0 overflow-hidden",children:[t.slice(0,3).map((l,c)=>{const p=lr(l.type),v=nr(l.type);return e.jsxs("div",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium truncate max-w-full ${p?"bg-red-100 text-red-800":v?"bg-green-100 text-green-800":"bg-purple-100 text-purple-800"}`,title:`${l.name} (${l.size?sr(l.size):"Unknown size"})`,children:[p?e.jsx("div",{className:"w-3 h-3 mr-1 flex-shrink-0 bg-red-500 rounded flex items-center justify-center text-white text-xs",children:"▶"}):v?e.jsx("div",{className:"w-3 h-3 mr-1 flex-shrink-0 bg-green-500 rounded flex items-center justify-center text-white text-xs",children:"🖼"}):e.jsx(_e,{className:"w-3 h-3 mr-1 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:l.name})]},l.id||c)}),t.length>3&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-600",children:["+",t.length-3," more"]})]}):e.jsx("span",{className:"text-gray-400 text-sm italic",children:"No files"});case"multiselect":return Array.isArray(t)?e.jsx("div",{className:"flex flex-wrap gap-1 min-w-0 overflow-hidden",children:t.map((l,c)=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 truncate max-w-full",children:e.jsx("span",{className:"truncate",children:l})},c))}):"";case"boolean":return e.jsx("span",{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${t?"bg-green-100 text-green-800":"bg-red-100 text-red-800"}`,children:t?"Yes":"No"});case"date":return e.jsx("span",{className:"truncate block",children:new Date(t).toLocaleDateString()});case"integer":return e.jsx("span",{className:"truncate block",children:Number(t).toLocaleString()});case"number":const a=typeof t=="number"?t.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2}):Number(t).toLocaleString();return e.jsx("span",{className:"truncate block",children:a});default:return e.jsx("span",{className:"truncate block",children:t})}},sr=t=>{if(t===0)return"0 Bytes";const r=1024,a=["Bytes","KB","MB","GB"],l=Math.floor(Math.log(t)/Math.log(r));return parseFloat((t/Math.pow(r,l)).toFixed(2))+" "+a[l]},lr=t=>t.startsWith("video/")||[".mp4",".avi",".mov",".wmv",".flv",".webm",".mkv",".m4v"].some(r=>t.toLowerCase().includes(r.replace(".",""))),nr=t=>t.startsWith("image/")||[".jpg",".jpeg",".png",".gif",".bmp",".webp",".svg"].some(r=>t.toLowerCase().includes(r.replace(".",""))),ar=t=>t&&typeof t=="object"&&t.id&&Array.isArray(t.rows)?t:{id:`subtable-${Date.now()}-${Math.random()}`,rows:Array.isArray(t)?t:[]},ot=({rowId:t,column:r,subTableData:a,totalColumns:l,onDataChange:c,onClose:p})=>{var f,N,y,i,x;const v=ar(a),b=n=>{const s={...v,rows:n};c(s)},k=n=>{console.log("Sub-table columns changed:",n)};return r.subTableSchema?e.jsx("tr",{children:e.jsx("td",{colSpan:l,className:"p-0 bg-gray-50 border-b border-gray-200",children:e.jsxs("div",{className:"border-l-4 border-blue-500 bg-white m-2 rounded-lg shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 border-b border-gray-200 rounded-t-lg",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(Re,{className:"w-5 h-5 text-blue-600"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:r.title}),e.jsxs("p",{className:"text-sm text-gray-600",children:[v.rows.length," row",v.rows.length!==1?"s":"",((f=r.subTableConfig)==null?void 0:f.maxRows)&&e.jsxs("span",{className:"text-gray-500 ml-2",children:["(max: ",r.subTableConfig.maxRows,")"]})]})]})]}),e.jsxs("button",{onClick:p,className:"flex items-center px-3 py-2 text-sm text-gray-600 hover:text-gray-800 hover:bg-gray-100 rounded-lg transition-colors",title:"Close sub-table",children:[e.jsx(me,{className:"w-4 h-4 mr-1"}),"Close"]})]}),e.jsx("div",{className:"p-4",children:e.jsx(Dt,{columns:r.subTableSchema,data:v.rows,onDataChange:b,onColumnChange:k,sortable:((N=r.subTableConfig)==null?void 0:N.sortable)??!0,filterable:((y=r.subTableConfig)==null?void 0:y.filterable)??!0,addRows:((i=r.subTableConfig)==null?void 0:i.addRows)??!0,deleteRows:((x=r.subTableConfig)==null?void 0:x.deleteRows)??!0,addColumns:!1,deleteColumns:!1,pagination:{enabled:!1},onRowAdd:(n,s)=>{console.log("Sub-table row added:",{parentRow:t,column:r.id,newRow:n,insertIndex:s})},onRowUpdate:(n,s,o)=>{console.log("Sub-table row updated:",{parentRow:t,column:r.id,updatedRow:n,rowIndex:s,changes:o})},onRowDelete:(n,s)=>{console.log("Sub-table row deleted:",{parentRow:t,column:r.id,deletedRow:n,rowIndex:s})},onCellUpdate:(n,s,o,u,g,M)=>{console.log("Sub-table cell updated:",{parentRow:t,parentColumn:r.id,subRowId:n,subColumnId:s,oldValue:o,newValue:u,subRowIndex:g,subColumnIndex:M})}})})]})})}):null},ct=({row:t,rowIndex:r,actualRowNumber:a,isSelected:l=!1,isCut:c=!1,columns:p,selectedCell:v,selectionRange:b,onValueChange:k,onCellClick:f,onCellRightClick:N,onRowRightClick:y,onRowClick:i,onDeleteRow:x,onConfirmEditAndMoveDown:n,showRowActions:s=!1,isDragging:o=!1,isDragOver:u=!1,onDragStart:g,onDragEnd:M,onDragOver:$,onDragLeave:F,onDrop:j,expandedSubTables:z=new Set,onToggleSubTable:A,onSubTableDataChange:K})=>{const[D,E]=h.useState(null),S=I=>(v==null?void 0:v.rowIndex)===r&&(v==null?void 0:v.columnIndex)===I,O=I=>{const P=p[I];return P?D===P.id:!1},q=I=>{I.preventDefault(),I.stopPropagation(),y==null||y(I,r)},U=I=>{i&&I.target.closest(".row-selector")&&(I.preventDefault(),I.stopPropagation(),i(r,I.shiftKey,I.ctrlKey||I.metaKey))},X=I=>{if(!b)return!1;const{start:P,end:Y}=b,m=Math.min(P.rowIndex,Y.rowIndex),T=Math.max(P.rowIndex,Y.rowIndex),te=Math.min(P.columnIndex,Y.columnIndex),J=Math.max(P.columnIndex,Y.columnIndex);return r>=m&&r<=T&&I>=te&&I<=J},H=I=>{g==null||g(I,r)},Q=I=>{M==null||M(I)},be=I=>{$==null||$(I,r)},se=I=>{j==null||j(I,r)};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{className:`
border-b border-gray-200 group relative transition-all duration-200
${c?"opacity-50 bg-orange-50 border-orange-200":""}
${l?"bg-blue-50 border-blue-200":""}
${o?"opacity-50 bg-blue-50":"hover:bg-gray-50"}
${u?"bg-blue-100 border-blue-300 border-2":""}
`,draggable:!0,onDragStart:H,onDragEnd:Q,onDragOver:be,onDragLeave:F,onDrop:se,children:[e.jsx("td",{className:"w-12 px-1 py-2 text-center text-xs text-gray-500 bg-gray-50 border-r border-gray-200 select-none",children:e.jsx("div",{className:`
flex items-center justify-center h-8 rounded cursor-grab active:cursor-grabbing group row-selector
${c?"bg-orange-200 hover:bg-orange-300":""}
${l?"bg-blue-200 hover:bg-blue-300":"hover:bg-gray-100"}
`,onContextMenu:q,onClick:U,title:"Drag to reorder • Right-click for options",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Ue,{className:"w-3 h-3 text-gray-400 group-hover:text-gray-600 mr-1"}),e.jsx("span",{className:"text-xs",children:a||r+1})]})})}),p.map((I,P)=>e.jsx("td",{className:"border-r border-gray-200 h-12 min-w-0 overflow-hidden relative",style:{width:I.width||150,minWidth:I.width||150,maxWidth:I.width||150},children:e.jsx(lt,{row:t,column:I,position:{rowIndex:r,columnIndex:p.findIndex(Y=>Y.id===I.id)},isSelected:S(P),isInSelection:X(P),value:t[I.id],onValueChange:k,onCellClick:f,onCellRightClick:N,isEditing:O(p.findIndex(Y=>Y.id===I.id)),onStartEdit:()=>{E(I.id),f({rowIndex:r,columnIndex:p.findIndex(Y=>Y.id===I.id)})},onStopEdit:()=>{E(null)},onConfirmAndMoveDown:()=>{E(null),n==null||n({rowIndex:r,columnIndex:p.findIndex(Y=>Y.id===I.id)})},expandedSubTables:z,onToggleSubTable:A})},I.id)),s&&e.jsx("td",{className:"px-4 py-2 w-12",children:e.jsx("button",{onClick:()=>x==null?void 0:x(t.id),className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-red-100 rounded text-red-600 transition-all",title:"Delete row",children:e.jsx(we,{className:"w-4 h-4"})})})]}),p.map(I=>I.type==="table"&&z.has(`${t.id}-${I.id}`)?e.jsx(ot,{rowId:t.id,column:I,subTableData:t[I.id],totalColumns:p.length+(s?2:1),onDataChange:P=>K==null?void 0:K(t.id,I.id,P),onClose:()=>A==null?void 0:A(t.id,I.id)},`${t.id}-${I.id}`):null)]})},it=({columns:t,visibleColumns:r,onVisibilityChange:a})=>{const[l,c]=h.useState(!1),p=h.useRef(null);h.useEffect(()=>{const y=i=>{p.current&&!p.current.contains(i.target)&&c(!1)};return l&&document.addEventListener("mousedown",y),()=>{document.removeEventListener("mousedown",y)}},[l]);const v=y=>{const i=r.includes(y)?r.filter(x=>x!==y):[...r,y];a(i)},b=()=>{a(t.map(y=>y.id))},k=()=>{a([])},f=r.length,N=t.length;return e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{onClick:()=>c(!l),className:"flex items-center px-3 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors border border-gray-300",title:"Show/Hide Columns",children:[e.jsx(_t,{className:"w-4 h-4 mr-2"}),e.jsxs("span",{className:"text-sm",children:["Columns (",f,"/",N,")"]})]}),l&&e.jsxs("div",{className:"absolute top-full mt-1 bg-white border border-gray-200 rounded-lg shadow-lg z-50 min-w-64 max-w-80 right-0",children:[e.jsxs("div",{className:"p-3 border-b border-gray-100",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"font-medium text-gray-700",children:"Column Visibility"}),e.jsx("button",{onClick:()=>c(!1),className:"p-1 hover:bg-gray-100 rounded",children:e.jsx(me,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:b,className:"flex items-center px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition-colors",children:[e.jsx(Ze,{className:"w-3 h-3 mr-1"}),"Show All"]}),e.jsxs("button",{onClick:k,className:"flex items-center px-2 py-1 text-xs bg-gray-100 text-gray-700 rounded hover:bg-gray-200 transition-colors",children:[e.jsx(Ye,{className:"w-3 h-3 mr-1"}),"Hide All"]})]})]}),e.jsx("div",{className:"p-2 max-h-64 overflow-y-auto",children:t.map(y=>{const i=r.includes(y.id);return e.jsxs("label",{className:"flex items-center py-2 px-2 hover:bg-gray-50 rounded cursor-pointer",children:[e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:()=>v(y.id),className:"sr-only"}),e.jsx("div",{className:`
w-4 h-4 border-2 rounded flex items-center justify-center mr-3
${i?"bg-blue-600 border-blue-600":"border-gray-300 hover:border-gray-400"}
`,children:i&&e.jsx(Xe,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{className:"flex items-center flex-1 min-w-0",children:[i?e.jsx(Ze,{className:"w-4 h-4 text-green-600 mr-2 flex-shrink-0"}):e.jsx(Ye,{className:"w-4 h-4 text-gray-400 mr-2 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:`text-sm truncate block ${i?"text-gray-900 font-medium":"text-gray-500"}`,children:y.title}),e.jsxs("span",{className:"text-xs text-gray-400 truncate block",children:[y.type," • ",y.width||150,"px"]})]})]})]},y.id)})}),e.jsx("div",{className:"p-2 border-t border-gray-100 text-xs text-gray-500 bg-gray-50",children:f===0?e.jsx("span",{className:"text-orange-600 font-medium",children:"⚠️ No columns visible"}):e.jsxs("span",{children:[f," of ",N," columns visible"]})})]})]})},dt=({searchTerm:t,onSearchChange:r,hasActiveFilters:a=!1,activeFilterCount:l=0,onClearAllFilters:c,onAddRow:p,onExport:v,onImport:b,showSearch:k=!0,showAddRow:f=!0,showExport:N=!0,showImport:y=!0,columns:i=[],visibleColumns:x=[],onColumnVisibilityChange:n,showColumnVisibility:s=!0})=>e.jsxs("div",{className:"flex items-center justify-between p-4 bg-white border-b border-gray-200",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[k&&e.jsxs("div",{className:"relative",children:[e.jsx(Qe,{className:"w-4 h-4 absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search...",value:t,onChange:o=>r(o.target.value),className:"pl-10 pr-10 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),t&&e.jsx("button",{onClick:()=>r(""),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors",title:"Clear search",children:e.jsx(tr,{className:"w-4 h-4"})})]}),a&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("div",{className:"flex items-center px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm",children:[e.jsx(Ut,{className:"w-4 h-4 mr-1"}),l," filter",l!==1?"s":""," active"]}),c&&e.jsxs("button",{onClick:c,className:"flex items-center px-2 py-1 text-sm text-red-600 hover:bg-red-50 rounded transition-colors",title:"Clear all filters",children:[e.jsx(me,{className:"w-4 h-4 mr-1"}),"Clear All"]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[s&&i.length>0&&n&&e.jsx(it,{columns:i,visibleColumns:x,onVisibilityChange:n}),f&&p&&e.jsxs("button",{onClick:p,className:"flex items-center px-3 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[e.jsx(Je,{className:"w-4 h-4 mr-2"}),"Add Row"]}),N&&v&&e.jsxs("button",{onClick:v,className:"flex items-center px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors",children:[e.jsx(Ge,{className:"w-4 h-4 mr-2"}),"Export"]}),y&&b&&e.jsxs("button",{onClick:b,className:"flex items-center px-3 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors",children:[e.jsx(et,{className:"w-4 h-4 mr-2"}),"Import"]})]})]}),ht=({currentPage:t,totalPages:r,totalItems:a,pageSize:l,onPageChange:c})=>{const p=(t-1)*l+1,v=Math.min(t*l,a);return e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-white border-t border-gray-200",children:[e.jsx("div",{className:"flex items-center text-sm text-gray-700",children:e.jsxs("span",{children:["Showing ",p," to ",v," of ",a," entries"]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs("button",{onClick:()=>c(t-1),disabled:t===1,className:"flex items-center px-3 py-1 text-sm border border-gray-300 rounded hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx(Yt,{className:"w-4 h-4 mr-1"}),"Previous"]}),e.jsx("div",{className:"flex items-center space-x-1",children:Array.from({length:r},(b,k)=>k+1).map(b=>e.jsx("button",{onClick:()=>c(b),className:`px-3 py-1 text-sm rounded transition-colors ${b===t?"bg-blue-600 text-white":"border border-gray-300 hover:bg-gray-50"}`,children:b},b))}),e.jsxs("button",{onClick:()=>c(t+1),disabled:t===r,className:"flex items-center px-3 py-1 text-sm border border-gray-300 rounded hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:["Next",e.jsx(He,{className:"w-4 h-4 ml-1"})]})]})]})},ut=({x:t,y:r,onClose:a,onCopy:l,onCut:c,onPaste:p,onDelete:v,onAddRowAbove:b,onAddRowBelow:k,onDeleteRow:f,onEdit:N,canPaste:y,hasSelection:i})=>{const x=h.useRef(null);h.useEffect(()=>{const o=g=>{x.current&&!x.current.contains(g.target)&&a()},u=g=>{g.key==="Escape"&&a()};return document.addEventListener("mousedown",o),document.addEventListener("keydown",u),()=>{document.removeEventListener("mousedown",o),document.removeEventListener("keydown",u)}},[a]);const n=[{label:"Edit Cell",icon:Rt,action:N,shortcut:"Enter",disabled:!1},{type:"separator"},{label:"Copy",icon:Ee,action:l,shortcut:"Ctrl+C",disabled:!i},{label:"Cut",icon:Fe,action:c,shortcut:"Ctrl+X",disabled:!i},{label:"Paste",icon:$e,action:p,shortcut:"Ctrl+V",disabled:!y},{label:"Delete",icon:we,action:v,shortcut:"Del",disabled:!i},{type:"separator"},{label:"Insert Row Above",icon:Ae,action:b,shortcut:"",disabled:!1},{label:"Insert Row Below",icon:Me,action:k,shortcut:"",disabled:!1},{label:"Delete Row",icon:Qt,action:f,shortcut:"",disabled:!1,danger:!0}],s=o=>{o(),a()};return e.jsx("div",{ref:x,className:"fixed bg-white border border-gray-200 rounded-lg shadow-lg py-2 z-50 min-w-48",style:{left:t,top:r},children:n.map((o,u)=>{if(o.type==="separator")return e.jsx("div",{className:"border-t border-gray-100 my-1"},u);const g=o.icon;return e.jsxs("button",{onClick:()=>s(o.action),disabled:o.disabled,className:`
w-full flex items-center justify-between px-4 py-2 text-sm text-left
transition-colors hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed
${o.danger?"text-red-600 hover:bg-red-50":"text-gray-700"}
`,children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(g,{className:"w-4 h-4 mr-3"}),e.jsx("span",{children:o.label})]}),o.shortcut&&e.jsx("span",{className:"text-xs text-gray-400 ml-4",children:o.shortcut})]},u)})})},bt=({x:t,y:r,rowIndex:a,onClose:l,onCopyRow:c,onCutRow:p,onPasteRow:v,onAddRowAbove:b,onAddRowBelow:k,onDeleteRow:f,canPaste:N})=>{const y=h.useRef(null);h.useEffect(()=>{const n=o=>{y.current&&!y.current.contains(o.target)&&l()},s=o=>{o.key==="Escape"&&l()};return document.addEventListener("mousedown",n),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",s)}},[l]);const i=[{label:`Row ${a+1} Actions`,icon:Jt,action:()=>{},disabled:!0,header:!0},{type:"separator"},{label:"Copy Row",icon:Ee,action:c,shortcut:"Ctrl+C",disabled:!1},{label:"Cut Row",icon:Fe,action:p,shortcut:"Ctrl+X",disabled:!1},{label:"Paste Row",icon:$e,action:v,shortcut:"Ctrl+V",disabled:!N},{type:"separator"},{label:"Insert Row Above",icon:Ae,action:b,shortcut:"",disabled:!1},{label:"Insert Row Below",icon:Me,action:k,shortcut:"",disabled:!1},{type:"separator"},{label:"Delete Row",icon:we,action:f,shortcut:"",disabled:!1,danger:!0}],x=(n,s)=>{s||(n(),l())};return e.jsx("div",{ref:y,className:"fixed bg-white border border-gray-200 rounded-lg shadow-lg py-2 z-50 min-w-48",style:{left:t,top:r},children:i.map((n,s)=>{if(n.type==="separator")return e.jsx("div",{className:"border-t border-gray-100 my-1"},s);const o=n.icon;return e.jsxs("button",{onClick:()=>x(n.action,n.disabled||!1),disabled:n.disabled,className:`
w-full flex items-center justify-between px-4 py-2 text-sm text-left
transition-colors disabled:cursor-not-allowed
${n.header?"text-gray-500 font-medium cursor-default":n.disabled?"opacity-50":n.danger?"text-red-600 hover:bg-red-50":"text-gray-700 hover:bg-gray-50"}
`,children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(o,{className:"w-4 h-4 mr-3"}),e.jsx("span",{children:n.label})]}),n.shortcut&&!n.header&&e.jsx("span",{className:"text-xs text-gray-400 ml-4",children:n.shortcut})]},s)})})},ft=({x:t,y:r,selectedRowCount:a,onClose:l,onCopyRows:c,onCutRows:p,onPasteRows:v,onDeleteRows:b,onSelectAll:k,onClearSelection:f,canPaste:N})=>{const y=h.useRef(null);h.useEffect(()=>{const n=o=>{y.current&&!y.current.contains(o.target)&&l()},s=o=>{o.key==="Escape"&