@nice2dev/ui-enterprise 1.0.20 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,596 @@
1
+ "use strict";const e=require("react/jsx-runtime"),we=require("./index-DFU0vf1H.cjs"),t=require("react"),Re=require("./NiceForm-B7D1MASh-DHsQX2bA.cjs"),Ti=require("react-dom"),Tt=({open:n,onClose:a,title:r,size:l="md",children:d,footer:m,closeOnOverlay:f=!0,closeOnEscape:o=!0,fullscreenable:g,zIndex:N,className:S,style:K,displayStyle:I})=>{const{t:T}=we.de(),P=t.useContext(we.kr),V=t.useRef(null),[y,s]=t.useState(!1),w=we.Zs("modal",I),c=we._s("modal",I);if(we.pl(V,n),t.useEffect(()=>{if(!n||!o)return;const F=q=>{q.key==="Escape"&&a()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},[n,o,a]),t.useEffect(()=>(n?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[n]),!n||typeof document>"u")return null;const R=e.jsx("div",{className:"nice-modal-overlay",style:N?{zIndex:N}:void 0,onClick:f?a:void 0,children:e.jsxs("div",{ref:V,className:`nice-modal nice-modal--${y?"full":l} nice-modal--ds-${c} ${S||""}`,style:{...w,...K},role:"dialog","aria-modal":"true","aria-label":r,onClick:F=>F.stopPropagation(),children:[r&&e.jsxs("div",{className:"nice-modal__header",children:[e.jsx("h2",{className:"nice-modal__title",children:r}),e.jsxs("div",{className:"nice-modal__header-actions",children:[g&&e.jsx("button",{type:"button",className:"nice-modal__fullscreen",onClick:()=>s(F=>!F),"aria-label":y?"Exit fullscreen":"Fullscreen",children:y?"⇲":"⇱"}),e.jsx("button",{type:"button",className:"nice-modal__close",onClick:a,"aria-label":T("controls.close","Close"),children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})})})]})]}),e.jsx("div",{className:"nice-modal__body",children:d}),m&&e.jsx("div",{className:"nice-modal__footer",children:m})]})});return Ti.createPortal(R,(P==null?void 0:P.portalTarget)??document.body)};function $i(n,a,r){const l=[];if(a<=1)return a===1&&l.push(1),l;const d=Math.max(2,n-r),m=Math.min(a-1,n+r);l.push(1),d>2&&l.push("dots");for(let f=d;f<=m;f++)l.push(f);return m<a-1&&l.push("dots"),l.push(a),l}const oi=({page:n,totalPages:a,onChange:r,showInfo:l,siblingCount:d=1,size:m="md",showFirstLast:f,showJumpInput:o,jumpInputLabel:g,showPageSize:N,pageSizeOptions:S,pageSize:K,onPageSizeChange:I,disabled:T,className:P,style:V})=>{const y=$i(n,a,d);return e.jsxs("nav",{className:`nice-pagination nice-pagination--${m} ${P||""}`,style:V,"aria-label":"Pagination",children:[f&&e.jsx("button",{className:"nice-pagination__btn",disabled:T||n<=1,onClick:()=>r(1),"aria-label":"First page",title:"First page",children:"⏮"}),e.jsx("button",{className:"nice-pagination__btn",disabled:T||n<=1,onClick:()=>r(n-1),"aria-label":"Previous",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})})}),y.map((s,w)=>s==="dots"?e.jsx("span",{className:"nice-pagination__ellipsis",children:"…"},`dots-${w}`):e.jsx("button",{className:`nice-pagination__btn ${s===n?"nice-pagination__btn--active":""}`,disabled:T,onClick:()=>r(s),"aria-current":s===n?"page":void 0,children:s},s)),e.jsx("button",{className:"nice-pagination__btn",disabled:T||n>=a,onClick:()=>r(n+1),"aria-label":"Next",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}),f&&e.jsx("button",{className:"nice-pagination__btn",disabled:T||n>=a,onClick:()=>r(a),"aria-label":"Last page",title:"Last page",children:"⏭"}),l&&e.jsxs("span",{className:"nice-pagination__info",children:[n," / ",a]}),o&&e.jsxs("span",{className:"nice-pagination__jump",style:{display:"inline-flex",alignItems:"center",gap:6,marginLeft:8},children:[e.jsx("span",{style:{fontSize:"0.85rem",color:"var(--text-secondary)"},children:g??"Go to"}),e.jsx(Re.Ye,{size:m==="lg"?"md":"sm",min:1,max:a,step:1,value:n,disabled:T,onChange:s=>{const w=typeof s=="number"?s:Number(s);if(!Number.isNaN(w)){const c=Math.max(1,Math.min(a,Math.floor(w)));r(c)}}})]}),N&&S&&S.length>0&&e.jsx("select",{className:"nice-pagination__size",value:K??S[0],disabled:T,onChange:s=>I==null?void 0:I(Number(s.target.value)),style:{marginLeft:8,padding:"4px 8px",border:"1px solid var(--border-color)",borderRadius:6,background:"var(--bg-primary)",color:"var(--text-primary)",font:"inherit",fontSize:"0.85rem"},"aria-label":"Rows per page",children:S.map(s=>e.jsxs("option",{value:s,children:[s," / page"]},s))})]})};function di({columns:n,data:a,striped:r,compact:l,emptyText:d,className:m,style:f,accessMode:o,id:g,displayStyle:N}){const S=we.Al(o,g)==="hidden",K=we.Zs("table",N),I=we._s("table",N),[T,P]=t.useState(null),V=t.useMemo(()=>T?[...a].sort((s,w)=>{const c=s[T.field]??"",R=w[T.field]??"",F=typeof c=="number"?c-R:String(c).localeCompare(String(R));return T.dir==="desc"?-F:F}):a,[a,T]),y=s=>{P(w=>(w==null?void 0:w.field)===s?w.dir==="asc"?{field:s,dir:"desc"}:null:{field:s,dir:"asc"})};return S?null:e.jsx("div",{className:`nice-table-wrapper ${m||""}`,style:{...K,...f},children:e.jsxs("table",{className:`nice-table nice-table--ds-${I} ${r?"nice-table--striped":""} ${l?"nice-table--compact":""}`,"aria-rowcount":V.length,"aria-colcount":n.length,children:[e.jsx("thead",{children:e.jsx("tr",{children:n.map(s=>{const w=s.sortable?(T==null?void 0:T.field)===s.field?T.dir==="asc"?"ascending":"descending":"none":void 0;return e.jsxs("th",{style:{width:s.width,textAlign:s.align},className:s.sortable?"th--sortable":void 0,onClick:()=>s.sortable&&y(s.field),scope:"col","aria-sort":w,children:[s.header,s.sortable&&(T==null?void 0:T.field)===s.field&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:T.dir==="asc"?"↑":"↓"})]},s.field)})})}),e.jsx("tbody",{children:V.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:n.length,className:"nice-table__empty",children:d||"No data"})}):V.map((s,w)=>e.jsx("tr",{children:n.map(c=>e.jsx("td",{style:{textAlign:c.align},children:c.render?c.render(s[c.field],s):String(s[c.field]??"")},c.field))},w))})]})})}function ui(n,a,r){const l=n.map(d=>d[a]).filter(d=>typeof d=="number");if(l.length===0)return r==="count"?"0":"";switch(r){case"sum":return l.reduce((d,m)=>d+m,0).toLocaleString();case"avg":return(l.reduce((d,m)=>d+m,0)/l.length).toLocaleString(void 0,{maximumFractionDigits:2});case"count":return String(n.length);case"min":return Math.min(...l).toLocaleString();case"max":return Math.max(...l).toLocaleString()}}function dt(n){return n.includes(",")||n.includes('"')||n.includes(`
2
+ `)?`"${n.replace(/"/g,'""')}"`:n}const Vn={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},Fi=()=>e.jsx("svg",{...Vn,children:e.jsx("polyline",{points:"6 15 12 9 18 15"})}),ot=()=>e.jsx("svg",{...Vn,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})}),Oi=()=>e.jsxs("svg",{...Vn,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 10 12 5 18 10"}),e.jsx("polyline",{points:"6 14 12 19 18 14"})]}),kt=()=>e.jsx("svg",{...Vn,children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),Pi=()=>e.jsxs("svg",{...Vn,children:[e.jsx("polyline",{points:"3 17 9 11 13 15 21 7"}),e.jsx("polyline",{points:"14 7 21 7 21 14"})]}),Wi=()=>e.jsxs("svg",{...Vn,children:[e.jsx("polyline",{points:"3 7 9 13 13 9 21 17"}),e.jsx("polyline",{points:"14 17 21 17 21 10"})]}),Bi=()=>e.jsx("svg",{...Vn,children:e.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})});function Ui(n){return typeof n=="boolean"?n?e.jsx("svg",{className:"nice-datagrid__bool-icon nice-datagrid__bool-icon--true",width:"16",height:"16",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-label":"true",role:"img",children:e.jsx("path",{d:"M4 10.5l4 4L16 6"})}):e.jsx("svg",{className:"nice-datagrid__bool-icon nice-datagrid__bool-icon--false",width:"16",height:"16",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-label":"false",role:"img",children:e.jsx("path",{d:"M5 5l10 10M15 5L5 15"})}):String(n??"")}function mt({columns:n,data:a,keyField:r="id",dataSource:l,sortable:d=!0,sortField:m,sortDirection:f,onSort:o,selectable:g,selectedKeys:N,onSelectionChange:S,pagination:K,pageSize:I=10,page:T,onPageChange:P,totalRows:V,searchable:y,searchPlaceholder:s,virtualScroll:w,rowHeight:c=40,groupBy:R,groupRender:F,onCellEdit:q,editMode:ue="inline",formItems:Ae,formColumns:A=2,editFormTitle:he,formProps:ye,onRowEdit:xe,onRowAdd:Q,onRowDelete:ie,bulkActions:M,onBulkDelete:$,exportCsv:b,exportFilename:ve="export",detailRow:re,expandedRowKeys:W,onExpandedRowChange:ee,columnReorder:B,onColumnReorder:J,columnResize:pe,rowDraggable:ge,onRowReorder:Te,striped:Ze,compact:en,loading:$e,emptyText:Qe,toolbar:Le,onRowClick:Fe,pinnedTopKeys:H,pinnedBottomKeys:be,colSpan:De,showStatusBar:z,contextMenuItems:ce,onContextMenuAction:G,printFriendly:_e,keyboardNavigation:E,focusedCell:de,onFocusedCellChange:O,cellRangeSelection:We,selectedCellRange:Ke,onCellRangeChange:ne,clipboard:Ge,clipboardFormat:gn="text",onBeforeCopy:je,onCopy:Nn,onPaste:Cn,quickFilters:qe,activeQuickFilters:zn,onQuickFilterChange:D,columnGroups:oe,stateStorageKey:me,initialState:ke,onStateChange:mn,flashRowKeys:Ce,flashDuration:Be=500,autoFitColumns:hn,showColumnStats:Ve,rowIndicator:rn,frozenRows:Sn,className:Jn,style:Zn,accessMode:nt,id:Hn,displayStyle:Yn}){var ti,ii;const pn=we.Al(nt,Hn),ht=pn==="hidden",tt=pn==="readOnly"||pn==="disabled",{t:Oe}=we.de();we.Zs("table",Yn),we._s("table",Yn);const nn=we.yc(l??null,{autoLoad:!!l,defaultPageSize:I}),Pe=!!l,Un=Pe?nn.data:a??[],Ln=Pe?nn.loading:$e,[Kn,Fn]=t.useState({field:"",dir:null}),[Gn,Xn]=t.useState(1),[u,h]=t.useState(new Set),[v,U]=t.useState(""),[Y,k]=t.useState(I),[L,X]=t.useState(null),[Ee,ze]=t.useState(null),[ae,He]=t.useState(null),[sn,fn]=t.useState(new Set),[cn,xn]=t.useState(0),it=t.useRef(null),[En,Mn]=t.useState(new Set),Tn=W??En,[dn,pt]=t.useState({}),[An,On]=t.useState(null),[Pn,at]=t.useState(null),[Ct,rt]=t.useState(null),[$n,gt]=t.useState(null),[St,Mt]=t.useState([]),[Wt,ft]=t.useState(null),[At,xt]=t.useState(new Set),[Bt,Ut]=t.useState(null),lt=t.useRef(null),Ye=de??Ct,on=Ke??$n,_n=zn??St;t.useEffect(()=>{if(!me)return;const i=localStorage.getItem(`nice-datagrid-${me}`);if(i&&!ke)try{const p=JSON.parse(i);p.columnWidths&&pt(p.columnWidths),p.expandedGroups&&fn(new Set(p.expandedGroups))}catch{}},[me,ke]),t.useEffect(()=>{if(!(Ce!=null&&Ce.size))return;xt(new Set(Ce));const i=setTimeout(()=>xt(new Set),Be);return()=>clearTimeout(i)},[Ce,Be]),t.useEffect(()=>{if(!Pn)return;const i=()=>at(null);return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[Pn]);const Dt=t.useCallback((i,p)=>{ce!=null&&ce.length&&(i.preventDefault(),at({x:i.clientX,y:i.clientY,row:p}))},[ce]),st=t.useCallback(i=>{const p=new Set(Tn);p.has(i)?p.delete(i):p.add(i),ee?ee(p):Mn(p)},[Tn,ee]),_=t.useCallback((i,p)=>{var se;if(!pe)return;p.preventDefault();const x=p.clientX,j=((se=p.target.closest("th"))==null?void 0:se.offsetWidth)??100,C=Z=>{const Ne=Math.max(40,j+Z.clientX-x);pt(Je=>({...Je,[i]:Ne}))},te=()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",te)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",te)},[pe]),le=Pe?((ti=nn.sort[0])==null?void 0:ti.field)??"":m??Kn.field,fe=Pe?((ii=nn.sort[0])==null?void 0:ii.direction)??null:f??Kn.dir,Se=Pe?nn.page:T??Gn,Me=N??u;t.useCallback(()=>{if(!me)return;const i={columnWidths:dn,sortField:le||void 0,sortDirection:fe,pageSize:Y,expandedGroups:Array.from(sn)};localStorage.setItem(`nice-datagrid-${me}`,JSON.stringify(i)),mn==null||mn(i)},[me,dn,le,fe,Y,sn,mn]);const Xe=t.useMemo(()=>n.filter(i=>!i.hidden),[n]),yn=t.useMemo(()=>Xe.filter(i=>i.pinned==="left"),[Xe]),un=t.useMemo(()=>Xe.filter(i=>i.pinned==="right"),[Xe]),bt=t.useMemo(()=>Xe.filter(i=>!i.pinned),[Xe]),Ue=t.useMemo(()=>[...yn,...bt,...un],[yn,bt,un]),ji=t.useMemo(()=>Xe.some(i=>i.aggregate),[Xe]),ct=yn.length>0||un.length>0,Kt=t.useCallback(i=>{const p=le===i?fe==="asc"?"desc":fe==="desc"?null:"asc":"asc";Pe?p?nn.setSortField(i,p):nn.setSort([]):o?o(i,p):Fn({field:i,dir:p})},[le,fe,Pe,nn,o]),vn=t.useMemo(()=>{if(Pe)return Un;let i=[...Un];if(v){const p=v.toLowerCase();i=i.filter(x=>Xe.some(j=>String(x[j.field]??"").toLowerCase().includes(p)))}return!o&&le&&fe&&i.sort((p,x)=>{const j=p[le]??"",C=x[le]??"",te=typeof j=="number"?j-C:String(j).localeCompare(String(C));return fe==="desc"?-te:te}),i},[Un,v,Xe,le,fe,o,Pe]),_t=Pe?nn.totalCount:V??vn.length,Qn=Pe?nn.pageSize:Y,wi=Math.max(1,Math.ceil(_t/Qn)),Dn=Pe?vn:K&&!V?vn.slice((Se-1)*Qn,Se*Qn):vn,It=t.useCallback(i=>{Pe?nn.setPage(i):P?P(i):Xn(i)},[Pe,nn,P]),qn=t.useMemo(()=>Dn.map(i=>String(i[r])),[Dn,r]),et=qn.length>0&&qn.every(i=>Me.has(i)),Gt=qn.some(i=>Me.has(i)),Vt=t.useCallback(()=>{const i=new Set(Me);et?qn.forEach(p=>i.delete(p)):qn.forEach(p=>i.add(p)),S?S(i):h(i)},[et,qn,Me,S]),Jt=t.useCallback(i=>{const p=new Set(Me);p.has(i)?p.delete(i):p.add(i),S?S(p):h(p)},[Me,S]),Zt=({field:i})=>le!==i||!fe?e.jsx("span",{className:"nice-table__sort-icon",children:e.jsx(Oi,{})}):e.jsx("span",{className:"nice-table__sort-icon",children:fe==="asc"?e.jsx(Fi,{}):e.jsx(ot,{})}),jn=t.useMemo(()=>{if(!R)return Dn.map((x,j)=>({type:"data",row:x,key:String(x[r]??j)}));const i=new Map;Dn.forEach(x=>{const j=x[R];i.has(j)||i.set(j,[]),i.get(j).push(x)});const p=[];return i.forEach((x,j)=>{const C=`__group_${String(j)}`,te=sn.has(C);p.push({type:"group",value:j,rows:x,expanded:te,key:C}),te&&x.forEach((se,Z)=>p.push({type:"data",row:se,key:String(se[r]??`${C}_${Z}`)}))}),p},[Dn,R,r,sn]),{pinnedTopRows:ki,pinnedBottomRows:Ni,normalRows:Ci}=t.useMemo(()=>{if(!(H!=null&&H.size)&&!(be!=null&&be.size))return{pinnedTopRows:[],pinnedBottomRows:[],normalRows:jn};const i=[],p=[],x=[];for(const j of jn){if(j.type==="data"){const C=j.key;if(H!=null&&H.has(C)){i.push(j);continue}if(be!=null&&be.has(C)){p.push(j);continue}}x.push(j)}return{pinnedTopRows:i,pinnedBottomRows:p,normalRows:x}},[jn,H,be]),Ht=t.useCallback(i=>{fn(p=>{const x=new Set(p);return x.has(i)?x.delete(i):x.add(i),x})},[]),Si=t.useMemo(()=>{var C;if(!w)return jn;const i=((C=it.current)==null?void 0:C.clientHeight)??400,p=Math.ceil(i/c),x=Math.max(0,Math.floor(cn/c)-3),j=Math.min(jn.length-1,x+p+6);return jn.slice(x,j+1).map((te,se)=>({...te,_vIdx:x+se}))},[w,jn,cn,c]),yt=t.useCallback((i,p,x)=>{!q||tt||(X({rowKey:i,field:p}),ze(x))},[q]),Yt=t.useCallback(()=>{L&&q&&q(L.rowKey,L.field,Ee),X(null),ze(null)},[L,Ee,q]),Mi=t.useCallback(()=>{X(null),ze(null)},[]),Ai=t.useCallback(()=>{const i=Xe,p=i.map(Z=>dt(Z.header)).join(","),x=vn.map(Z=>i.map(Ne=>dt(String(Z[Ne.field]??""))).join(",")),j=[p,...x].join(`
3
+ `),C=new Blob(["\uFEFF"+j],{type:"text/csv;charset=utf-8;"}),te=URL.createObjectURL(C),se=document.createElement("a");se.href=te,se.download=`${ve}.csv`,se.click(),URL.revokeObjectURL(te)},[Xe,vn,ve]),vt=t.useCallback(i=>{O?O(i):rt(i)},[O]),jt=t.useCallback(i=>{ne?ne(i):gt(i)},[ne]),wn=t.useMemo(()=>jn.filter(i=>i.type==="data").map(i=>i.key),[jn]),Di=t.useCallback(i=>{if(!E||L||!Ye)return;const p=wn.indexOf(Ye.rowKey),x=Ue.findIndex(se=>se.field===Ye.field);if(p<0||x<0)return;let j=p,C=x;switch(i.key){case"ArrowUp":j=Math.max(0,p-1);break;case"ArrowDown":j=Math.min(wn.length-1,p+1);break;case"ArrowLeft":C=Math.max(0,x-1);break;case"ArrowRight":C=Math.min(Ue.length-1,x+1);break;case"Tab":i.preventDefault(),i.shiftKey?C=Math.max(0,x-1):C=Math.min(Ue.length-1,x+1);break;case"Enter":{const se=Ue[x];if(se.editable&&q){const Z=Dn.find(Ne=>String(Ne[r])===Ye.rowKey);Z&&yt(Ye.rowKey,se.field,Z[se.field])}return}case"Escape":vt(null),jt(null);return;case"Home":i.ctrlKey&&(j=0),C=0;break;case"End":i.ctrlKey&&(j=wn.length-1),C=Ue.length-1;break;case"PageUp":j=Math.max(0,p-Y);break;case"PageDown":j=Math.min(wn.length-1,p+Y);break;default:return}i.preventDefault();const te={rowKey:wn[j],field:Ue[C].field};if(vt(te),i.shiftKey&&We){const se=(on==null?void 0:on.start)??Ye;jt({start:se,end:te})}else jt(null)},[E,L,Ye,wn,Ue,We,on,vt,jt,q,Dn,r,yt,Y]),Xt=t.useCallback(()=>{let i=[],p=[];if(on){const x=wn.indexOf(on.start.rowKey),j=wn.indexOf(on.end.rowKey),C=Math.min(x,j),te=Math.max(x,j),se=Ue.findIndex(tn=>tn.field===on.start.field),Z=Ue.findIndex(tn=>tn.field===on.end.field),Ne=Math.min(se,Z),Je=Math.max(se,Z);p=Ue.slice(Ne,Je+1).map(tn=>tn.field),i=Dn.filter(tn=>{const Wn=wn.indexOf(String(tn[r]));return Wn>=C&&Wn<=te})}else Me.size>0&&(i=Dn.filter(x=>Me.has(String(x[r]))),p=Ue.map(x=>x.field));return{rows:i,fields:p}},[on,wn,Ue,Dn,r,Me]),Qt=t.useCallback((i,p,x)=>{const j=Ue.filter(C=>p.includes(C.field));switch(x){case"json":return JSON.stringify(i.map(C=>Object.fromEntries(p.map(te=>[te,C[te]]))),null,2);case"csv":{const C=j.map(se=>dt(se.header)).join(","),te=i.map(se=>j.map(Z=>dt(String(se[Z.field]??""))).join(",")).join(`
4
+ `);return C+`
5
+ `+te}case"html":{const C=j.map(se=>`<th>${se.header}</th>`).join(""),te=i.map(se=>`<tr>${j.map(Z=>`<td>${se[Z.field]??""}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${C}</tr></thead><tbody>${te}</tbody></table>`}case"markdown":{const C="| "+j.map(Z=>Z.header).join(" | ")+" |",te="| "+j.map(()=>"---").join(" | ")+" |",se=i.map(Z=>"| "+j.map(Ne=>Z[Ne.field]??"").join(" | ")+" |").join(`
6
+ `);return C+`
7
+ `+te+`
8
+ `+se}default:return i.map(C=>j.map(te=>C[te.field]??"").join(" ")).join(`
9
+ `)}},[Ue]),Rt=t.useCallback(async()=>{if(!Ge)return;const{rows:i,fields:p}=Xt();if(!i.length||(je==null?void 0:je(i,p))===!1)return;const x=Qt(i,p,gn);await navigator.clipboard.writeText(x),Nn==null||Nn(i,p,gn)},[Ge,Xt,je,Qt,gn,Nn]),qt=t.useCallback(async()=>{if(!Ge||!Ye||!Cn)return;const i=(await navigator.clipboard.readText()).split(`
10
+ `).map(p=>p.split(" "));Cn(i,Ye)},[Ge,Ye,Cn]);t.useEffect(()=>{if(!Ge||!lt.current)return;const i=p=>{var x;(x=lt.current)!=null&&x.contains(document.activeElement)&&(p.type==="copy"&&(p.preventDefault(),Rt()),p.type==="paste"&&(p.preventDefault(),qt()))};return document.addEventListener("copy",i),document.addEventListener("paste",i),()=>{document.removeEventListener("copy",i),document.removeEventListener("paste",i)}},[Ge,Rt,qt]);const Ii=t.useCallback(i=>{const p=_n.includes(i)?_n.filter(x=>x!==i):[..._n,i];D?D(p):Mt(p)},[_n,D]),Ri=t.useMemo(()=>{if(!(qe!=null&&qe.length)||!_n.length)return vn;const i=qe.filter(p=>_n.includes(p.key));return vn.filter(p=>i.every(x=>x.filter(p)))},[vn,qe,_n]),ei=qe!=null&&qe.length?Ri:vn;t.useCallback(i=>{const p=vn.map(Ne=>Ne[i]).filter(Ne=>Ne!=null),x=p.filter(Ne=>typeof Ne=="number");if(x.length===0){const Ne=new Set(p).size;return{count:p.length,unique:Ne,type:"text"}}const j=x.reduce((Ne,Je)=>Ne+Je,0),C=j/x.length,te=Math.min(...x),se=Math.max(...x),Z=Math.sqrt(x.reduce((Ne,Je)=>Ne+(Je-C)**2,0)/x.length);return{count:x.length,sum:j,avg:C,min:te,max:se,stdDev:Z,type:"numeric"}},[vn]);const zi=t.useCallback((i,p,x)=>{if(!i.cellVisualization)return null;const j=Number(p);if(isNaN(j))return null;const C=i.visualMin??0,te=i.visualMax??100,se=Math.max(0,Math.min(100,(j-C)/(te-C)*100));switch(i.cellVisualization){case"progress":return e.jsxs("div",{className:"nice-datagrid__cell-progress",style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("div",{style:{flex:1,height:6,background:"var(--border-color)",borderRadius:3,overflow:"hidden"},children:e.jsx("div",{style:{width:`${se}%`,height:"100%",background:se>80?"var(--color-success)":se>50?"var(--color-primary)":"var(--color-warning)",transition:"width 0.3s ease"}})}),e.jsxs("span",{style:{fontSize:"0.75rem",minWidth:32,textAlign:"right"},children:[Math.round(se),"%"]})]});case"rating":{const Z=Math.round(j/te*5);return e.jsx("div",{className:"nice-datagrid__cell-rating",children:[1,2,3,4,5].map(Ne=>e.jsx("span",{style:{color:Ne<=Z?"var(--color-warning)":"var(--text-muted)",fontSize:"0.95rem",lineHeight:1},"aria-hidden":"true",children:"★"},Ne))})}case"trend":{const Z=i.visualMin??j,Ne=j-Z,Je=Ne>0?Pi:Ne<0?Wi:Bi,tn=Ne>0?"var(--color-success)":Ne<0?"var(--color-danger)":"var(--text-muted)";return e.jsxs("span",{style:{color:tn,fontWeight:500,display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Je,{})," ",Math.abs(Ne).toFixed(1),"%"]})}case"heatmap":{const Z=se/100,Ne=`rgba(${Math.round(255*Z)}, ${Math.round(100*(1-Z))}, ${Math.round(50*(1-Z))}, 0.6)`;return e.jsx("span",{style:{background:Ne,padding:"2px 8px",borderRadius:4},children:j})}default:return null}},[]),Li=t.useCallback((i,p,x)=>{var j;if(!((j=i.conditionalFormats)!=null&&j.length))return{};for(const C of i.conditionalFormats)if(C.when(p,x,i.field))return{className:C.className,style:{...C.style,backgroundColor:C.backgroundColor,color:C.color}};return{}},[]),zt=t.useCallback((i,p)=>{if(!ct||!i.pinned)return{};const x={position:"sticky",zIndex:2,background:"var(--bg-primary, #fff)"};if(i.pinned==="left"){let j=0;for(let C=0;C<p;C++){const te=Ue[C];te.pinned==="left"&&(j+=typeof te.width=="number"?te.width:parseInt(String(te.width)||"100",10))}g&&p===0&&(j=36),x.left=j}else{let j=0;for(let C=Ue.length-1;C>p;C--){const te=Ue[C];te.pinned==="right"&&(j+=typeof te.width=="number"?te.width:parseInt(String(te.width)||"100",10))}x.right=j}return x},[ct,Ue,g]),ni=(i,p,x,j)=>(L==null?void 0:L.rowKey)===x&&(L==null?void 0:L.field)===i.field?i.editor?i.editor(Ee,p,te=>ze(te)):e.jsx("input",{className:"nice-datagrid__edit-input",autoFocus:!0,value:Ee??"",onChange:te=>ze(te.target.value),onBlur:Yt,onKeyDown:te=>{te.key==="Enter"&&Yt(),te.key==="Escape"&&Mi()}}):zi(i,p[i.field],p)||(i.render?i.render(p[i.field],p,j):Ui(p[i.field])),Ei=(i,p,x,j)=>{const C=(Ye==null?void 0:Ye.rowKey)===x&&(Ye==null?void 0:Ye.field)===i.field,te=on&&(()=>{const Z=wn.indexOf(on.start.rowKey),Ne=wn.indexOf(on.end.rowKey),Je=wn.indexOf(x),tn=Ue.findIndex(Bn=>Bn.field===on.start.field),Wn=Ue.findIndex(Bn=>Bn.field===on.end.field);return Je>=Math.min(Z,Ne)&&Je<=Math.max(Z,Ne)&&j>=Math.min(tn,Wn)&&j<=Math.max(tn,Wn)})(),se=Li(i,p[i.field],p);return{className:[se.className,C&&"nice-datagrid__cell--focused",te&&"nice-datagrid__cell--in-range"].filter(Boolean).join(" "),style:{...zt(i,j),textAlign:i.align,...se.style,...C?{outline:"2px solid var(--color-primary)",outlineOffset:-2}:{},...te?{background:"var(--color-primary-light, rgba(59,130,246,0.15))"}:{}}}},wt=Ue.length+(g?1:0)+(re?1:0)+(ge?1:0)+(rn?1:0),Lt=(i,p,x)=>{const{row:j,key:C}=i,te=Me.has(C),se=Tn.has(C),Z=At.has(C),Ne=[te&&"nice-datagrid__row--selected",An===p&&"nice-datagrid__row--dragging",x&&"nice-datagrid__row--pinned",Z&&"nice-datagrid__row--flash"].filter(Boolean).join(" ");return e.jsxs(t.Fragment,{children:[e.jsxs("tr",{className:Ne,onClick:()=>Fe==null?void 0:Fe(j),onDoubleClick:ue==="popup"&&(xe||q)?()=>He({key:C,data:{...j}}):void 0,onContextMenu:Je=>Dt(Je,j),style:Fe||ue==="popup"?{cursor:"pointer"}:void 0,draggable:ge,onDragStart:ge?()=>On(p):void 0,onDragOver:ge?Je=>Je.preventDefault():void 0,onDrop:ge&&Te&&An!=null?()=>{Te(An,p),On(null)}:void 0,onDragEnd:ge?()=>On(null):void 0,children:[rn&&e.jsx("td",{className:"nice-datagrid__row-indicator",style:{width:32,padding:"0 4px"},children:rn(j)}),re&&e.jsx("td",{className:"nice-datagrid__expand-col",onClick:Je=>{Je.stopPropagation(),st(C)},children:e.jsx("span",{className:"nice-datagrid__expand-btn","data-expanded":se,children:se?e.jsx(ot,{}):e.jsx(kt,{})})}),ge&&e.jsx("td",{className:"nice-datagrid__drag-handle",style:{cursor:"grab",textAlign:"center",color:"var(--text-muted)"},children:"?"}),g&&e.jsx("td",{className:"nice-datagrid__checkbox",onClick:Je=>Je.stopPropagation(),style:ct?{position:"sticky",left:0,zIndex:1,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:te,onChange:()=>Jt(C),"aria-label":`Select row ${C}`})}),(()=>{let Je=0;return Ue.map((tn,Wn)=>{if(Je>0)return Je--,null;const Bn=De?De(j,tn,Wn):void 0;Bn&&Bn>1&&(Je=Bn-1);const ai=Ei(tn,j,C,Wn);return e.jsx("td",{colSpan:Bn,className:ai.className,style:ai.style,onClick:E?()=>vt({rowKey:C,field:tn.field}):void 0,onDoubleClick:tn.editable&&q?()=>yt(C,tn.field,j[tn.field]):void 0,children:ni(tn,j,C,p)},tn.field)})})()]}),re&&se&&e.jsx("tr",{className:"nice-datagrid__detail-row",children:e.jsx("td",{colSpan:wt,children:re(j)})})]},C)};return ht?null:e.jsxs("div",{ref:lt,className:`nice-datagrid ${_e?"nice-datagrid--print":""} ${Jn||""}`,style:Zn,role:"grid","aria-label":Oe("datagrid.title","Data Grid"),"aria-rowcount":jn.length,"aria-colcount":Xe.length,"aria-busy":Ln||void 0,tabIndex:E?0:void 0,onKeyDown:E?Di:void 0,children:[(y||Le||b||(qe==null?void 0:qe.length)||Q)&&e.jsxs("div",{className:"nice-datagrid__toolbar",children:[y&&e.jsx("div",{className:"nice-datagrid__search",children:e.jsx("input",{type:"text",value:Pe?nn.search:v,"aria-label":Oe("controls.search","Search"),onChange:i=>{Pe?nn.setSearch(i.target.value):(U(i.target.value),It(1))},placeholder:s||Oe("controls.search","Search...")})}),qe&&qe.length>0&&e.jsx("div",{className:"nice-datagrid__quick-filters",style:{display:"flex",gap:6,flexWrap:"wrap"},children:qe.map(i=>e.jsxs("button",{className:`nice-datagrid__quick-filter ${_n.includes(i.key)?"nice-datagrid__quick-filter--active":""}`,onClick:()=>Ii(i.key),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 10px",fontSize:"0.75rem",border:"1px solid var(--border-color)",borderRadius:12,background:_n.includes(i.key)?`var(--color-${i.color||"primary"})`:"var(--bg-primary)",color:_n.includes(i.key)?"var(--bg-primary, #fff)":"inherit",cursor:"pointer",transition:"all 0.15s ease"},children:[i.icon&&e.jsx("span",{children:i.icon}),i.label]},i.key))}),Ge&&e.jsx("button",{className:"nice-btn nice-btn--sm nice-btn--ghost",onClick:Rt,title:Oe("controls.copy","Copy selected"),style:{marginLeft:4},children:"??"}),b&&e.jsx("button",{className:"nice-btn nice-btn--sm",onClick:Ai,title:Oe("controls.exportCsv","Export CSV"),children:"CSV ?"}),Q&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--primary",onClick:()=>He({key:null,data:{}}),title:Oe("datagrid.addRow","Add row"),children:["+ ",Oe("datagrid.add","Add")]}),Le]}),g&&Me.size>0&&((M==null?void 0:M.length)||$)&&e.jsxs("div",{className:"nice-datagrid__bulk-toolbar",role:"toolbar","aria-label":Oe("datagrid.bulkActions","Bulk actions"),style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"var(--bg-tertiary, #f1f5f9)",borderBottom:"1px solid var(--border-color)",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"0.85rem",color:"var(--text-secondary)"},children:Oe("datagrid.selectedCount","{count} selected").replace("{count}",String(Me.size))}),(M||[]).map(i=>{var C;const p=Array.from(Me),x=ei.filter(te=>Me.has(String(te[r]))),j=((C=i.disabled)==null?void 0:C.call(i,p,x))||!1;return e.jsxs("button",{type:"button",className:`nice-btn nice-btn--sm nice-btn--${i.variant||"secondary"}`,disabled:j,onClick:()=>i.onClick(p,x),children:[i.icon,i.icon&&" ",i.label]},i.key)}),$&&!(M!=null&&M.length)&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--danger",onClick:()=>{const i=Array.from(Me),p=ei.filter(x=>Me.has(String(x[r])));$(i,p)},children:["?? ",Oe("datagrid.deleteSelected","Delete selected")]}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--xs nice-btn--ghost",onClick:()=>{const i=new Set;N===void 0&&h(i),S==null||S(i)},style:{marginLeft:"auto"},children:Oe("datagrid.clearSelection","Clear")})]}),e.jsxs("div",{ref:it,className:`nice-datagrid__table-wrap ${w?"nice-datagrid__table-wrap--virtual":""}`,style:w?{maxHeight:Math.min(jn.length*c,600),overflowY:"auto"}:void 0,onScroll:w?i=>xn(i.currentTarget.scrollTop):void 0,children:[w&&e.jsxs("div",{style:{height:jn.length*c,position:"relative"},children:[e.jsx("table",{className:`${Ze?"nice-table--striped":""} ${en?"nice-table--compact":""}`,style:{position:"sticky",top:0,zIndex:3},children:e.jsx("thead",{children:e.jsxs("tr",{children:[re&&e.jsx("th",{className:"nice-datagrid__expand-col",style:{width:36}}),ge&&e.jsx("th",{style:{width:28}}),g&&e.jsx("th",{className:"nice-datagrid__checkbox",style:ct?{position:"sticky",left:0,zIndex:3,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:et,ref:i=>{i&&(i.indeterminate=Gt&&!et)},onChange:Vt,"aria-label":Oe("controls.selectAll","Select all")})}),Ue.map((i,p)=>e.jsxs("th",{style:{width:dn[i.field]||i.width,minWidth:i.minWidth,textAlign:i.align,position:"relative",...zt(i,p)},className:d&&i.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>d&&i.sortable!==!1&&Kt(i.field),children:[i.header,d&&i.sortable!==!1&&e.jsx(Zt,{field:i.field}),pe&&e.jsx("span",{className:"nice-datagrid__resize-handle",onMouseDown:x=>{x.stopPropagation(),_(i.field,x)}})]},i.field))]})})}),Si.map((i,p)=>{const x=i._vIdx??0;if(i.type==="group"){const Z=i;return e.jsxs("div",{className:"nice-datagrid__group-row",style:{position:"absolute",top:x*c,height:c,left:0,right:0},onClick:()=>Ht(Z.key),children:[e.jsx("span",{className:"nice-datagrid__group-toggle",children:Z.expanded?e.jsx(ot,{}):e.jsx(kt,{})}),F?F(Z.value,Z.rows):e.jsxs(e.Fragment,{children:[String(Z.value)," (",Z.rows.length,")"]})]},Z.key)}const{row:j,key:C}=i,te=Me.has(C),se=Tn.has(C);return e.jsxs(t.Fragment,{children:[e.jsxs("div",{className:`nice-datagrid__vrow ${te?"nice-datagrid__row--selected":""} ${An===p?"nice-datagrid__row--dragging":""}`,style:{position:"absolute",top:x*c,height:c,left:0,right:0,display:"flex",alignItems:"center"},onClick:()=>Fe==null?void 0:Fe(j),onDoubleClick:ue==="popup"&&(xe||q)?()=>He({key:C,data:{...j}}):void 0,draggable:ge,onDragStart:ge?()=>On(p):void 0,onDragOver:ge?Z=>Z.preventDefault():void 0,onDrop:ge&&Te&&An!=null?()=>{Te(An,p),On(null)}:void 0,onDragEnd:ge?()=>On(null):void 0,children:[re&&e.jsx("div",{className:"nice-datagrid__expand-col",style:{width:36,flexShrink:0,textAlign:"center",cursor:"pointer"},onClick:Z=>{Z.stopPropagation(),st(C)},children:e.jsx("span",{className:"nice-datagrid__expand-btn","data-expanded":se,children:se?e.jsx(ot,{}):e.jsx(kt,{})})}),ge&&e.jsx("div",{style:{width:28,flexShrink:0,cursor:"grab",textAlign:"center",color:"var(--text-muted)"},children:"?"}),g&&e.jsx("div",{className:"nice-datagrid__checkbox",style:{width:36,flexShrink:0},onClick:Z=>Z.stopPropagation(),children:e.jsx("input",{type:"checkbox",checked:te,onChange:()=>Jt(C)})}),Ue.map(Z=>e.jsx("div",{className:"nice-datagrid__vcell",style:{width:dn[Z.field]||Z.width||"auto",flex:dn[Z.field]||Z.width?`0 0 ${typeof(dn[Z.field]||Z.width)=="number"?(dn[Z.field]||Z.width)+"px":dn[Z.field]||Z.width}`:1,textAlign:Z.align,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 8px"},onDoubleClick:Z.editable&&q?()=>yt(C,Z.field,j[Z.field]):void 0,children:ni(Z,j,C,x)},Z.field))]}),re&&se&&e.jsx("div",{className:"nice-datagrid__detail-row",style:{position:"absolute",top:(x+1)*c,left:0,right:0,padding:"8px 12px",background:"var(--bg-secondary, #f8f8f8)"},children:re(j)})]},C)})]}),!w&&e.jsxs("table",{className:`${Ze?"nice-table--striped":""} ${en?"nice-table--compact":""}`,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[re&&e.jsx("th",{className:"nice-datagrid__expand-col",style:{width:36}}),ge&&e.jsx("th",{style:{width:28}}),g&&e.jsx("th",{className:"nice-datagrid__checkbox",style:ct?{position:"sticky",left:0,zIndex:3,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:et,ref:i=>{i&&(i.indeterminate=Gt&&!et)},onChange:Vt,"aria-label":Oe("controls.selectAll","Select all")})}),Ue.map((i,p)=>{const x=d&&i.sortable!==!1,j=x?le===i.field?fe==="asc"?"ascending":fe==="desc"?"descending":"none":"none":void 0;return e.jsxs("th",{style:{width:dn[i.field]||i.width,minWidth:i.minWidth,textAlign:i.align,position:"relative",...zt(i,p)},className:x?"nice-datagrid__th--sortable":void 0,onClick:()=>x&&Kt(i.field),"aria-sort":j,scope:"col",children:[i.header,x&&e.jsx(Zt,{field:i.field}),pe&&e.jsx("span",{className:"nice-datagrid__resize-handle",onMouseDown:C=>{C.stopPropagation(),_(i.field,C)}})]},i.field)})]})}),e.jsx("tbody",{children:Ln?e.jsx("tr",{children:e.jsx("td",{colSpan:wt,className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):jn.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:wt,className:"nice-datagrid__empty",children:Qe||Oe("controls.noData","No data available")})}):e.jsxs(e.Fragment,{children:[ki.map((i,p)=>i.type==="data"&&Lt(i,p,"top")),Ci.map((i,p)=>{if(i.type==="group"){const x=i;return e.jsx("tr",{className:"nice-datagrid__group-row",onClick:()=>Ht(x.key),children:e.jsxs("td",{colSpan:wt,className:"nice-datagrid__group-cell",children:[e.jsx("span",{className:"nice-datagrid__group-toggle",children:x.expanded?e.jsx(ot,{}):e.jsx(kt,{})}),F?F(x.value,x.rows):e.jsxs(e.Fragment,{children:[String(x.value)," (",x.rows.length,")"]})]})},x.key)}return Lt(i,p)}),Ni.map((i,p)=>i.type==="data"&&Lt(i,p,"bottom"))]})}),ji&&!Ln&&Dn.length>0&&e.jsx("tfoot",{children:e.jsxs("tr",{className:"nice-datagrid__aggregate-row",children:[g&&e.jsx("td",{}),Ue.map(i=>e.jsx("td",{style:{textAlign:i.align,fontWeight:600},children:i.aggregate?(i.aggregateLabel||i.aggregate.toUpperCase())+": "+ui(vn,i.field,i.aggregate):""},i.field))]})})]})]}),K&&e.jsxs("div",{className:"nice-datagrid__footer",children:[e.jsxs("span",{className:"nice-datagrid__footer-info",children:[Oe("controls.showing","Showing")," ",(Se-1)*Qn+1,"–",Math.min(Se*Qn,_t)," ",Oe("controls.of","of")," ",_t]}),e.jsx(oi,{page:Se,totalPages:wi,onChange:It,showInfo:!0,pageSize:Qn,showPageSize:!0,pageSizeOptions:[5,10,25,50,100],onPageSizeChange:i=>{Pe?nn.setPageSize(i):(k(i),It(1))},showFirstLast:!0})]}),z&&!Ln&&e.jsxs("div",{className:"nice-datagrid__status-bar",children:[e.jsxs("span",{children:[Oe("controls.totalRows","Total rows"),": ",_t]}),g&&Me.size>0&&e.jsxs("span",{children:[Oe("controls.selected","Selected"),": ",Me.size]})]}),Pn&&ce&&e.jsx("div",{className:"nice-datagrid__context-menu",style:{position:"fixed",left:Pn.x,top:Pn.y,zIndex:9999},onClick:i=>i.stopPropagation(),children:ce.map(i=>e.jsxs("button",{className:"nice-datagrid__context-item",disabled:i.disabled,onClick:()=>{G==null||G(i.key,Pn.row),at(null)},children:[i.icon&&e.jsx("span",{className:"nice-datagrid__context-icon",children:i.icon}),i.label]},i.key))}),(ue==="popup"||Q)&&ae&&(()=>{const i=ae.key===null,p=Ae??n.filter(x=>!x.hidden&&x.field!==r).map(x=>{var C;let j="text";return x.dataType==="number"||x.dataType==="currency"||x.dataType==="percent"?j="number":x.dataType==="boolean"?j="checkbox":x.dataType==="date"&&(j="date"),{field:x.field,label:x.header,type:j,required:(C=x.validation)==null?void 0:C.required}});return e.jsx(Tt,{open:!0,onClose:()=>He(null),title:he??(i?Oe("datagrid.addRow","Add row"):Oe("datagrid.editRow","Edit row")),size:"lg",children:e.jsx(Re.Ga,{items:p,data:ae.data,columns:A,showActions:!0,submitLabel:i?Oe("controls.add","Add"):Oe("controls.save","Save"),cancelLabel:Oe("controls.cancel","Cancel"),onCancel:()=>He(null),...ye,onFieldChange:(x,j)=>He(C=>C&&{...C,data:{...C.data,[x]:j}}),onSubmit:x=>{i?Q==null||Q(x):ae.key&&(xe?xe(ae.key,x):q&&Object.keys(x).forEach(j=>{q(ae.key,j,x[j])})),He(null)}})})})()]})}mt.displayName="NiceDataGrid";const Ki=Object.freeze(Object.defineProperty({__proto__:null,NiceDataGrid:mt},Symbol.toStringTag,{value:"Module"}));function Gi(n,a){return n.filter(r=>a.every(l=>{const d=r[l.field],m=l.value;switch(l.operator){case"eq":return d===m;case"ne":return d!==m;case"gt":return typeof d=="number"&&typeof m=="number"&&d>m;case"gte":return typeof d=="number"&&typeof m=="number"&&d>=m;case"lt":return typeof d=="number"&&typeof m=="number"&&d<m;case"lte":return typeof d=="number"&&typeof m=="number"&&d<=m;case"contains":return String(d).toLowerCase().includes(String(m).toLowerCase());case"startsWith":return String(d).toLowerCase().startsWith(String(m).toLowerCase());case"endsWith":return String(d).toLowerCase().endsWith(String(m).toLowerCase());default:return!0}}))}function Vi(n){return n.map(a=>({field:a.field,type:a.dataType||"string",label:typeof a.header=="string"?a.header:a.field}))}function Ji(n,a){const{enableAI:r=!0,aiModel:l,enableNLSearch:d=!0,enableInsights:m=!0,nlPlaceholder:f,onAIFilter:o,onInsights:g,showAISearchBar:N=!0,exampleQueries:S=["Show items from last week","Filter by status = active","Orders over $1000",'Names starting with "A"'],columns:K,data:I,...T}=n,[P,V]=t.useState(""),[y,s]=t.useState([]),[w,c]=t.useState([]),[R,F]=t.useState(!1),[q,ue]=t.useState(null),Ae=t.useRef(null),{t:A}=we.de(),he=we.me(),{parseFilter:ye,isLoading:xe}=we.Zd(),Q=r&&he.isConfigured,ie=y.length>0?Gi(I||[],y):I,M=t.useCallback(async ee=>{if(!Q||!d||!ee.trim())return;ue(ee);const B=Vi(K);try{const J=await ye(ee,B);s(J),o==null||o(ee,J)}catch{s([])}},[Q,d,K,ye,o]),$=t.useCallback(()=>{s([]),ue(null),V("")},[]),b=t.useCallback(()=>y,[y]),ve=t.useCallback(async()=>{if(!Q||!m||!(I!=null&&I.length))return[];try{const ee=await he.complete([{role:"user",content:`Analyze this data and provide 3-5 key insights. Data sample (${I.length} total rows): ${JSON.stringify(I.slice(0,20))}
11
+
12
+ Columns: ${K.map(B=>B.field).join(", ")}
13
+
14
+ Return a JSON array of insight strings. Be specific with numbers and trends.`}],{temperature:.3,maxTokens:500});try{const B=JSON.parse(ee.content),J=Array.isArray(B)?B:[];return c(J),g==null||g(J),J}catch{return[]}}catch{return[]}},[Q,m,I,K,he,g]),re=ee=>{ee.preventDefault(),P.trim()&&M(P)},W=ee=>{V(ee),M(ee)};return t.useImperativeHandle(a,()=>({applyNLFilter:M,clearAIFilters:$,getAIFilters:b,generateInsights:ve})),e.jsxs("div",{className:"nice-data-grid-ai","data-testid":n["data-testid"],children:[N&&Q&&d&&e.jsxs("div",{className:"nice-data-grid-ai__search-bar",children:[e.jsx("div",{className:"nice-data-grid-ai__search-left",children:e.jsx("span",{className:"nice-data-grid-ai__badge",children:"AI"})}),e.jsxs("form",{onSubmit:re,className:"nice-data-grid-ai__search-form",children:[e.jsxs("div",{className:"nice-data-grid-ai__input-wrapper",children:[e.jsx("span",{className:"nice-data-grid-ai__search-icon",children:"🔍"}),e.jsx("input",{ref:Ae,type:"text",value:P,onChange:ee=>V(ee.target.value),placeholder:f||A("dataGridAI.searchPlaceholder","Search with natural language..."),className:"nice-data-grid-ai__input",disabled:xe}),xe&&e.jsx("span",{className:"nice-data-grid-ai__loading-spinner"}),P&&!xe&&e.jsx("button",{type:"button",className:"nice-data-grid-ai__clear-input",onClick:()=>V(""),children:"✕"})]}),e.jsx("button",{type:"submit",className:"nice-data-grid-ai__search-btn",disabled:xe||!P.trim(),children:xe?A("dataGridAI.searching","Searching..."):A("dataGridAI.search","Search")})]}),m&&e.jsxs("button",{type:"button",className:"nice-data-grid-ai__insights-btn",onClick:()=>{ve(),F(!0)},disabled:xe||!(I!=null&&I.length),title:A("dataGridAI.generateInsights","Generate AI Insights"),children:["💡 ",A("dataGridAI.insights","Insights")]})]}),N&&Q&&d&&!q&&S.length>0&&e.jsxs("div",{className:"nice-data-grid-ai__examples",children:[e.jsx("span",{className:"nice-data-grid-ai__examples-label",children:A("dataGridAI.tryAsking","Try asking:")}),e.jsx("div",{className:"nice-data-grid-ai__examples-list",children:S.slice(0,4).map((ee,B)=>e.jsxs("button",{type:"button",className:"nice-data-grid-ai__example",onClick:()=>W(ee),children:['"',ee,'"']},B))})]}),q&&y.length>0&&e.jsxs("div",{className:"nice-data-grid-ai__active-filter",children:[e.jsxs("div",{className:"nice-data-grid-ai__filter-info",children:[e.jsx("span",{className:"nice-data-grid-ai__filter-icon",children:"🎯"}),e.jsxs("span",{className:"nice-data-grid-ai__filter-query",children:['"',q,'"']}),e.jsxs("span",{className:"nice-data-grid-ai__filter-count",children:["(",(ie==null?void 0:ie.length)||0," ",A("dataGridAI.results","results"),")"]})]}),e.jsx("div",{className:"nice-data-grid-ai__filter-badges",children:y.map((ee,B)=>e.jsxs("span",{className:"nice-data-grid-ai__filter-badge",children:[ee.field," ",ee.operator," ",String(ee.value)]},B))}),e.jsxs("button",{type:"button",className:"nice-data-grid-ai__clear-filter",onClick:$,children:["✕ ",A("dataGridAI.clearFilter","Clear")]})]}),e.jsx("div",{className:"nice-data-grid-ai__grid-wrapper",children:e.jsx(mt,{columns:K,data:ie,...T})}),R&&e.jsxs("div",{className:"nice-data-grid-ai__insights-panel",children:[e.jsxs("div",{className:"nice-data-grid-ai__insights-header",children:[e.jsxs("h4",{children:["💡 ",A("dataGridAI.aiInsights","AI Insights")]}),e.jsx("button",{type:"button",className:"nice-data-grid-ai__insights-close",onClick:()=>F(!1),children:"✕"})]}),e.jsx("div",{className:"nice-data-grid-ai__insights-body",children:xe?e.jsx("div",{className:"nice-data-grid-ai__insights-loading",children:A("dataGridAI.analyzing","Analyzing data...")}):w.length>0?e.jsx("ul",{className:"nice-data-grid-ai__insights-list",children:w.map((ee,B)=>e.jsxs("li",{className:"nice-data-grid-ai__insight",children:[e.jsx("span",{className:"nice-data-grid-ai__insight-bullet",children:"•"}),ee]},B))}):e.jsx("div",{className:"nice-data-grid-ai__insights-empty",children:A("dataGridAI.noInsights","Click to generate insights from your data")})}),e.jsx("div",{className:"nice-data-grid-ai__insights-footer",children:e.jsxs("button",{type:"button",className:"nice-data-grid-ai__refresh-insights",onClick:()=>ve(),disabled:xe,children:["🔄 ",A("dataGridAI.refresh","Refresh")]})})]})]})}t.forwardRef(Ji);const mi=({items:n,selectedKeys:a=[],onSelectionChange:r,selectionMode:l="none",searchable:d,searchPlaceholder:m,grouped:f,groupField:o="group",reorderable:g,onReorder:N,onItemClick:S,renderItem:K,showCheckboxes:I,loading:T,emptyText:P,size:V="md",bordered:y=!0,swipeActions:s,className:w,style:c,accessMode:R,id:F})=>{const q=we.Al(R,F)==="hidden",{t:ue}=we.de(),[Ae,A]=t.useState(""),[he,ye]=t.useState(null),[xe,Q]=t.useState(null),ie=t.useRef(null),M=t.useMemo(()=>{if(!Ae)return n;const W=Ae.toLowerCase();return n.filter(ee=>ee.text.toLowerCase().includes(W))},[n,Ae]),$=t.useMemo(()=>{if(!f)return null;const W=new Map;return M.forEach(ee=>{const B=String(ee[o]??"");W.has(B)||W.set(B,[]),W.get(B).push(ee)}),W},[M,f,o]),b=t.useCallback(W=>{r&&(l==="single"?r(a.includes(W)?[]:[W]):l==="multiple"&&r(a.includes(W)?a.filter(ee=>ee!==W):[...a,W]))},[a,l,r]),ve=t.useCallback(W=>{he!==null&&he!==W&&N&&N(he,W),ye(null)},[he,N]),re=(W,ee)=>{const B=a.includes(W.key),J=xe===W.key;return e.jsxs("li",{className:`nice-list__item ${B?"nice-list__item--selected":""} ${W.disabled?"nice-list__item--disabled":""} ${J?"nice-list__item--swiped":""}`,onClick:()=>{W.disabled||(b(W.key),S==null||S(W))},draggable:g,onDragStart:()=>ye(ee),onDragOver:pe=>pe.preventDefault(),onDrop:()=>ve(ee),onTouchStart:s!=null&&s.length?pe=>{ie.current={x:pe.touches[0].clientX,key:W.key}}:void 0,onTouchEnd:s!=null&&s.length?pe=>{if(!ie.current)return;const ge=pe.changedTouches[0].clientX-ie.current.x;ge<-50&&ie.current.key===W.key?Q(W.key):ge>50&&Q(null),ie.current=null}:void 0,role:l!=="none"?"option":void 0,"aria-selected":l!=="none"?B:void 0,children:[e.jsxs("div",{className:"nice-list__item-content",children:[I&&l!=="none"&&e.jsx("input",{type:"checkbox",checked:B,readOnly:!0,tabIndex:-1,className:"nice-list__checkbox"}),K?K(W):e.jsxs(e.Fragment,{children:[W.icon&&e.jsx("span",{className:"nice-list__icon",children:W.icon}),e.jsx("span",{className:"nice-list__text",children:W.text}),W.badge&&e.jsx("span",{className:"nice-list__badge",children:W.badge})]})]}),s&&J&&e.jsx("div",{className:"nice-list__swipe-actions",children:s.map(pe=>e.jsx("button",{className:"nice-list__swipe-btn",style:pe.color?{backgroundColor:pe.color}:void 0,onClick:ge=>{ge.stopPropagation(),pe.onClick(W),Q(null)},children:pe.label},pe.key))})]},W.key)};return q?null:e.jsxs("div",{className:`nice-list nice-list--${V} ${y?"nice-list--bordered":""} ${w||""}`,style:c,children:[d&&e.jsx("div",{className:"nice-list__search",children:e.jsx("input",{type:"text",value:Ae,onChange:W=>A(W.target.value),placeholder:m||ue("controls.search","Search...")})}),T?e.jsx("div",{className:"nice-list__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm"})}):M.length===0?e.jsx("div",{className:"nice-list__empty",children:P||ue("controls.noData","No data available")}):$?e.jsx("div",{role:"listbox",children:Array.from($.entries()).map(([W,ee])=>e.jsxs("div",{className:"nice-list__group",children:[e.jsx("div",{className:"nice-list__group-header",children:W}),e.jsx("ul",{className:"nice-list__items",children:ee.map((B,J)=>re(B,J))})]},W))}):e.jsx("ul",{className:"nice-list__items",role:"listbox",children:M.map((W,ee)=>re(W,ee))})]})};function hi(n){const a=[];if(n.children)for(const r of n.children)a.push(r.key),a.push(...hi(r));return a}function Et(n,a){if(!n.children||n.children.length===0)return a.has(n.key)?"checked":"unchecked";let r=!0,l=a.has(n.key);for(const d of n.children){const m=Et(d,a);m==="checked"?l=!0:(m==="indeterminate"&&(l=!0),r=!1)}return r&&l?"checked":l?"indeterminate":"unchecked"}const pi=({nodes:n,selectedKeys:a=[],expandedKeys:r,onSelectionChange:l,onExpandedChange:d,selectionMode:m="none",showCheckboxes:f,searchable:o,searchPlaceholder:g,onNodeClick:N,renderNode:S,showLines:K,loading:I,className:T,style:P,accessMode:V,id:y,draggable:s,onNodeDrop:w,onLoadChildren:c,contextMenuItems:R,onContextMenuAction:F,editable:q,onNodeEdit:ue,maxDepth:Ae})=>{const A=we.Al(V,y)==="hidden",{t:he}=we.de(),[ye,xe]=t.useState([]),[Q,ie]=t.useState(""),[M,$]=t.useState(new Set),[b,ve]=t.useState(new Map),[re,W]=t.useState(null),[ee,B]=t.useState(null),[J,pe]=t.useState(null),[ge,Te]=t.useState(""),Ze=t.useRef(null),en=r??ye,$e=t.useMemo(()=>new Set(a),[a]),Qe=t.useCallback(async(z,ce)=>{var E;const G=!en.includes(z),_e=G?[...en,z]:en.filter(de=>de!==z);if(d?d(_e):xe(_e),G&&c&&!((E=ce.children)!=null&&E.length)&&ce.leaf!==!0&&!b.has(z)){$(O=>new Set(O).add(z));const de=await c(ce);ve(O=>new Map(O).set(z,de)),$(O=>{const We=new Set(O);return We.delete(z),We})}},[en,d,c,b]),Le=t.useCallback((z,ce)=>{var G;if(l){if(m==="single")l(a.includes(z)?[]:[z]);else if(m==="multiple")if(f&&((G=ce.children)!=null&&G.length)){const _e=hi(ce),E=[z,..._e];if(Et(ce,$e)==="checked")l(a.filter(de=>!E.includes(de)));else{const de=new Set([...a,...E]);l(Array.from(de))}}else l(a.includes(z)?a.filter(_e=>_e!==z):[...a,z])}},[a,m,l,f,$e]),Fe=t.useCallback(z=>{var G;if(!Q)return!0;const ce=Q.toLowerCase();return z.text.toLowerCase().includes(ce)?!0:((G=b.get(z.key)??z.children)==null?void 0:G.some(_e=>Fe(_e)))??!1},[Q,b]),H=t.useCallback((z,ce)=>{R!=null&&R.length&&(z.preventDefault(),B({x:z.clientX,y:z.clientY,node:ce}))},[R]),be=t.useCallback(()=>{J&&ue&&ue(J,ge),pe(null)},[J,ge,ue]),De=(z,ce)=>{if(Q&&!Fe(z))return null;const G=typeof Ae=="number"?Math.min(10,Math.max(1,Ae)):1/0,_e=ce+1>=G,E=_e?void 0:b.get(z.key)??z.children,de=!_e&&(E&&E.length>0||z.leaf!==!0&&c&&!(E!=null&&E.length)),O=en.includes(z.key),We=$e.has(z.key),Ke=M.has(z.key),ne=f&&m==="multiple"&&(E!=null&&E.length)?Et(z,$e):We?"checked":"unchecked",Ge=Math.min(ce+1,10),gn={paddingLeft:ce*20+4,"--nice-row-bg":`var(--nice-tree-level-${Ge}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${Ge}-text, inherit)`,"--nice-row-border":`var(--nice-tree-level-${Ge}-border, transparent)`,"--nice-row-hover-bg":`var(--nice-tree-level-${Ge}-hover-bg, var(--hover-bg, color-mix(in srgb, var(--text-primary) 6%, transparent)))`,"--nice-row-active-bg":`var(--nice-tree-level-${Ge}-active-bg, color-mix(in srgb, var(--color-primary) 14%, transparent))`};return e.jsxs("li",{className:"nice-tree__node",role:"treeitem","aria-expanded":de?O:void 0,"data-nice-depth":Ge,draggable:s&&!z.disabled,onDragStart:s?je=>{je.stopPropagation(),W(z.key)}:void 0,onDragOver:s?je=>{je.preventDefault(),je.stopPropagation()}:void 0,onDrop:s&&re?je=>{je.stopPropagation(),w==null||w(re,z.key,"inside"),W(null)}:void 0,onDragEnd:s?()=>W(null):void 0,children:[e.jsxs("div",{className:`nice-tree__row ${We?"nice-tree__row--selected":""} ${z.disabled?"nice-tree__row--disabled":""} ${re===z.key?"nice-tree__row--dragging":""}`,style:gn,onClick:()=>{z.disabled||(Le(z.key,z),N==null||N(z))},onContextMenu:je=>H(je,z),onDoubleClick:q&&!z.disabled?()=>{pe(z.key),Te(z.text)}:void 0,children:[e.jsx("span",{className:`nice-tree__toggle ${de?O?"nice-tree__toggle--expanded":"":"nice-tree__toggle--leaf"}`,onClick:je=>{je.stopPropagation(),de&&Qe(z.key,z)},children:Ke?e.jsx("span",{className:"nice-spinner nice-spinner--xs"}):de?O?"▾":"▸":""}),f&&m!=="none"&&e.jsx("input",{type:"checkbox",checked:ne==="checked",ref:je=>{je&&(je.indeterminate=ne==="indeterminate")},onChange:()=>Le(z.key,z),onClick:je=>je.stopPropagation(),tabIndex:-1,className:"nice-tree__checkbox"}),J===z.key?e.jsx("input",{type:"text",className:"nice-tree__edit-input",value:ge,onChange:je=>Te(je.target.value),onBlur:be,onKeyDown:je=>{je.key==="Enter"&&be(),je.key==="Escape"&&pe(null)},autoFocus:!0,onClick:je=>je.stopPropagation()}):S?S(z):e.jsxs(e.Fragment,{children:[z.icon&&e.jsx("span",{className:"nice-tree__icon",children:z.icon}),e.jsx("span",{className:"nice-tree__text",children:z.text})]})]}),E&&E.length>0&&O&&e.jsx("ul",{className:"nice-tree__children",role:"group",children:E.map(je=>De(je,ce+1))})]},z.key)};return A?null:e.jsxs("div",{className:`nice-tree ${K?"nice-tree--lines":""} ${T||""}`,style:P,ref:Ze,onClick:()=>B(null),children:[o&&e.jsx("div",{className:"nice-tree__search",children:e.jsx("input",{type:"text",value:Q,onChange:z=>ie(z.target.value),placeholder:g||he("controls.search","Search..."),"aria-label":g||he("controls.search","Search tree")})}),I?e.jsx("div",{className:"nice-tree__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm"})}):e.jsx("ul",{className:"nice-tree__root",role:"tree",children:n.map(z=>De(z,0))}),ee&&R&&e.jsx("div",{className:"nice-tree__context-menu",style:{position:"fixed",top:ee.y,left:ee.x,zIndex:9999},children:R.map(z=>e.jsxs("div",{className:`nice-tree__context-item ${z.disabled?"nice-tree__context-item--disabled":""}`,onClick:()=>{z.disabled||(F==null||F(z.key,ee.node),B(null))},children:[z.icon&&e.jsx("span",{children:z.icon}),z.label]},z.key))})]})};function Zi(n,a,r){const l=new Map,d=[];return n.forEach(m=>{const f={...m,children:[]};l.set(String(f[a]),f)}),n.forEach(m=>{const f=m[r];f!=null&&l.has(String(f))?l.get(String(f)).children.push(l.get(String(m[a]))):d.push(l.get(String(m[a])))}),d}function gi({columns:n,data:a,keyField:r="key",parentKeyField:l="parentKey",expandedKeys:d,onExpandedChange:m,selectedKeys:f=[],onSelectionChange:o,selectable:g,loading:N,emptyText:S,className:K,style:I,accessMode:T,id:P}){const V=we.Al(T,P)==="hidden",{t:y}=we.de(),[s,w]=t.useState([]),c=d??s,R=t.useMemo(()=>Zi(a,r,l),[a,r,l]),F=t.useMemo(()=>n.filter(A=>!A.hidden),[n]),q=t.useCallback(A=>{const he=c.includes(A)?c.filter(ye=>ye!==A):[...c,A];m?m(he):w(he)},[c,m]),ue=t.useCallback(A=>{o&&o(f.includes(A)?f.filter(he=>he!==A):[...f,A])},[f,o]),Ae=(A,he)=>{const ye=String(A[r]),xe=A.children&&A.children.length>0,Q=c.includes(ye),ie=f.includes(ye);return e.jsxs(t.Fragment,{children:[e.jsxs("tr",{className:ie?"nice-treelist__row--selected":"",children:[g&&e.jsx("td",{className:"nice-treelist__checkbox",children:e.jsx("input",{type:"checkbox",checked:ie,onChange:()=>ue(ye)})}),F.map((M,$)=>e.jsxs("td",{style:{textAlign:M.align},children:[$===0&&e.jsx("span",{style:{display:"inline-block",width:he*20}}),$===0&&e.jsx("span",{className:"nice-treelist__toggle",onClick:()=>xe&&q(ye),style:{cursor:xe?"pointer":"default",width:20,display:"inline-block"},children:xe?Q?"▾":"▸":""}),M.render?M.render(A[M.field],A,0):String(A[M.field]??"")]},M.field))]}),xe&&Q&&A.children.map(M=>Ae(M,he+1))]},ye)};return V?null:e.jsx("div",{className:`nice-treelist ${K||""}`,style:I,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[g&&e.jsx("th",{className:"nice-treelist__checkbox"}),F.map(A=>e.jsx("th",{style:{width:A.width,minWidth:A.minWidth,textAlign:A.align},children:A.header},A.field))]})}),e.jsx("tbody",{children:N?e.jsx("tr",{children:e.jsx("td",{colSpan:F.length+(g?1:0),className:"nice-treelist__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):R.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:F.length+(g?1:0),className:"nice-treelist__empty",children:S||y("controls.noData","No data available")})}):R.map(A=>Ae(A,0))})]})})}function fi({items:n,renderCard:a,columns:r=3,gap:l=16,searchable:d,searchField:m="text",searchPlaceholder:f,loading:o,emptyText:g,onCardClick:N,className:S,style:K,accessMode:I,id:T}){const P=we.Al(I,T)==="hidden",{t:V}=we.de(),[y,s]=t.useState(""),w=t.useMemo(()=>{if(!y)return n;const c=y.toLowerCase();return n.filter(R=>String(R[m]??"").toLowerCase().includes(c))},[n,y,m]);return P?null:e.jsxs("div",{className:`nice-cardview ${S||""}`,style:K,children:[d&&e.jsx("div",{className:"nice-cardview__search",children:e.jsx("input",{type:"text",value:y,onChange:c=>s(c.target.value),placeholder:f||V("controls.search","Search...")})}),o?e.jsx("div",{className:"nice-cardview__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):w.length===0?e.jsx("div",{className:"nice-cardview__empty",children:g||V("controls.noData","No data available")}):e.jsx("div",{className:"nice-cardview__grid",style:{display:"grid",gridTemplateColumns:`repeat(${r}, 1fr)`,gap:l},children:w.map(c=>e.jsx("div",{className:"nice-cardview__card",onClick:()=>N==null?void 0:N(c),style:N?{cursor:"pointer"}:void 0,children:a(c)},c.key))})]})}function xi({items:n,tileWidth:a=180,tileHeight:r=180,direction:l="horizontal",renderTile:d,onTileClick:m,loading:f,emptyText:o,className:g,style:N}){const{t:S}=we.de();return e.jsx("div",{className:`nice-tileview nice-tileview--${l} ${g||""}`,style:N,children:f?e.jsx("div",{className:"nice-tileview__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):n.length===0?e.jsx("div",{className:"nice-tileview__empty",children:o||S("controls.noData","No data available")}):e.jsx("div",{className:"nice-tileview__container",style:{display:"flex",flexWrap:"wrap",gap:8,flexDirection:l==="vertical"?"column":"row"},children:n.map(K=>e.jsx("div",{className:"nice-tileview__tile",style:{width:a,height:r,cursor:m?"pointer":void 0},onClick:()=>m==null?void 0:m(K),children:d?d(K):e.jsxs(e.Fragment,{children:[K.image&&e.jsx("img",{src:K.image,alt:K.text||"",className:"nice-tileview__image"}),K.text&&e.jsx("div",{className:"nice-tileview__label",children:K.text})]})},K.key))})})}const ri=[{key:"row",label:"Rows"},{key:"column",label:"Columns"},{key:"data",label:"Values"},{key:"filter",label:"Filters"}],$t=({fields:n,onChange:a,className:r,style:l})=>{const d=n.filter(o=>!o.area),m=(o,g)=>{a(n.map(N=>N.field===o?{...N,area:g}:N))},f=o=>{a(n.map(g=>g.field===o?{...g,area:void 0}:g))};return e.jsx("div",{className:`nice-field-chooser ${r||""}`,style:l,children:e.jsxs("div",{className:"nice-field-chooser__panel",children:[e.jsxs("div",{className:"nice-field-chooser__section",children:[e.jsx("h4",{children:"Available Fields"}),e.jsx("ul",{children:d.map(o=>e.jsxs("li",{className:"nice-field-chooser__item",children:[e.jsx("span",{children:o.caption}),e.jsx("div",{className:"nice-field-chooser__actions",children:ri.map(g=>e.jsx("button",{type:"button",className:"nice-btn nice-btn--ghost nice-btn--sm",onClick:()=>m(o.field,g.key),children:g.label},g.key))})]},o.field))})]}),ri.map(o=>{const g=n.filter(N=>N.area===o.key);return e.jsxs("div",{className:"nice-field-chooser__section",children:[e.jsx("h4",{children:o.label}),e.jsx("ul",{children:g.map(N=>e.jsxs("li",{className:"nice-field-chooser__item",children:[e.jsx("span",{children:N.caption}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--ghost nice-btn--sm",onClick:()=>f(N.field),children:"✕"})]},N.field))})]},o.key)})]})})};function Hi(n,a){if(n.length===0)return 0;switch(a){case"sum":return n.reduce((r,l)=>r+l,0);case"count":return n.length;case"avg":return n.reduce((r,l)=>r+l,0)/n.length;case"min":return Math.min(...n);case"max":return Math.max(...n);default:return n.reduce((r,l)=>r+l,0)}}function li(n,a){return[...new Set(n.map(r=>String(r[a]??"")))].sort()}const Ft=({data:n,fields:a,onFieldsChange:r,showFieldChooser:l,loading:d,emptyText:m,exportCsv:f,exportFilename:o="pivot-export",onDrillThrough:g,className:N,style:S,accessMode:K,id:I})=>{const T=we.Al(K,I)==="hidden",{t:P}=we.de(),[V,y]=t.useState(a),[s,w]=t.useState(!1),c=t.useMemo(()=>V.filter(Q=>Q.area==="row"),[V]),R=t.useMemo(()=>V.filter(Q=>Q.area==="column"),[V]),F=t.useMemo(()=>V.filter(Q=>Q.area==="data"),[V]),q=t.useMemo(()=>c.length===0?["Total"]:li(n,c[0].field),[n,c]),ue=t.useMemo(()=>R.length===0?["Total"]:li(n,R[0].field),[n,R]),Ae=t.useCallback((Q,ie,M)=>{let $=n;c.length>0&&($=$.filter(re=>String(re[c[0].field])===Q)),R.length>0&&($=$.filter(re=>String(re[R[0].field])===ie));const b=$.map(re=>Number(re[M.field])||0),ve=Hi(b,M.summaryType||"sum");return M.format?M.format(ve):ve},[n,c,R]),A=t.useCallback(Q=>{y(Q),r==null||r(Q)},[r]),he=t.useCallback((Q,ie)=>{let M=n;return c.length>0&&(M=M.filter($=>String($[c[0].field])===Q)),R.length>0&&(M=M.filter($=>String($[R[0].field])===ie)),M},[n,c,R]),ye=t.useCallback((Q,ie)=>{g&&g(Q,ie,he(Q,ie))},[g,he]),xe=t.useCallback(()=>{const Q=["",...ue.flatMap(re=>F.length>0?F.map(W=>`${re} - ${W.caption}`):[re])],ie=q.map(re=>{const W=ue.flatMap(ee=>F.length>0?F.map(B=>String(Ae(re,ee,B))):["—"]);return[re,...W]}),M=[Q,...ie].map(re=>re.map(W=>`"${String(W).replace(/"/g,'""')}"`).join(",")).join(`
15
+ `),$=new Blob(["\uFEFF"+M],{type:"text/csv;charset=utf-8;"}),b=URL.createObjectURL($),ve=document.createElement("a");ve.href=b,ve.download=`${o}.csv`,ve.click(),URL.revokeObjectURL(b)},[ue,q,F,Ae,o]);return T?null:e.jsxs("div",{className:`nice-pivotgrid ${N||""}`,style:S,children:[(l||f)&&e.jsxs("div",{className:"nice-pivotgrid__toolbar",children:[l&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:()=>w(!s),children:P("controls.fieldChooser","Field Chooser")}),f&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--sm",onClick:xe,children:"CSV ↓"})]}),s&&e.jsx($t,{fields:V,onChange:A}),d?e.jsx("div",{className:"nice-pivotgrid__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):e.jsx("div",{className:"nice-pivotgrid__table-wrap",children:e.jsxs("table",{className:"nice-pivotgrid__table",children:[e.jsxs("thead",{children:[e.jsxs("tr",{children:[e.jsx("th",{children:c.map(Q=>Q.caption).join(" / ")||""}),ue.map(Q=>e.jsx("th",{colSpan:F.length||1,children:Q},Q))]}),F.length>1&&e.jsxs("tr",{children:[e.jsx("th",{}),ue.map(Q=>F.map(ie=>e.jsx("th",{children:ie.caption},`${Q}-${ie.field}`)))]})]}),e.jsx("tbody",{children:q.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:1+ue.length*Math.max(F.length,1),className:"nice-pivotgrid__empty",children:m||P("controls.noData","No data available")})}):q.map(Q=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-pivotgrid__row-header",children:Q}),ue.map(ie=>F.length>0?F.map(M=>e.jsx("td",{className:`nice-pivotgrid__cell ${g?"nice-pivotgrid__cell--clickable":""}`,onClick:g?()=>ye(Q,ie):void 0,children:Ae(Q,ie,M)},`${ie}-${M.field}`)):e.jsx("td",{className:"nice-pivotgrid__cell",children:"—"},ie))]},Q))})]})})]})},Yi=Object.freeze(Object.defineProperty({__proto__:null,NicePivotGrid:Ft},Symbol.toStringTag,{value:"Module"}));function Xi({open:n}){return e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{transition:"transform 160ms ease",transform:n?"rotate(0deg)":"rotate(-90deg)"},children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Qi(){return e.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}const qi=[{target:".nice-kanban",titleKey:"tutorial.kanbanBoard.intro.title",title:"Kanban board",contentKey:"tutorial.kanbanBoard.intro.content",content:'Drag cards between columns to change their status, add cards with the "+" button, and click a card to edit its details.',placement:"auto"}],Ot=t.forwardRef(({columns:n,cards:a,onCardMove:r,onCardClick:l,renderCard:d,onAddCard:m,disabled:f=!1,size:o="md",collapsible:g=!1,layoutMode:N="scroll",viewMode:S,onViewModeChange:K,collapsedColumns:I,onCollapsedColumnsChange:T,formItems:P,formColumns:V=1,formProps:y,editCardTitle:s,newCardTitle:w,onCardEdit:c,onCardCreate:R,onCardDelete:F,tutorial:q,cookies:ue=!1,localStorage:Ae=!0,sessionStorage:A=!1,storageMode:he,storageKey:ye,className:xe,style:Q,id:ie,...M},$)=>{const{t:b}=we.de(),[ve,re]=t.useState(null),[W,ee]=t.useState(null),[B,J]=t.useState(null),pe=!!P&&(!!c||!!R),ge=t.useCallback(E=>{if(pe&&c){J({key:E.key,data:{...E},column:E.column});return}l==null||l(E)},[pe,l,c]),Te=t.useCallback(E=>{if(pe&&R){J({key:null,data:{title:"",description:""},column:E});return}m==null||m(E)},[pe,m,R]),Ze=we.gt(ye??"nice-kanban"),[en,$e]=t.useState(()=>Ze.get("state")??{collapsedColumns:[],viewMode:"default"}),Qe=I??en.collapsedColumns??[],Le=S??en.viewMode??"default",Fe=t.useCallback(E=>{$e(de=>{const O={...de,...E};return Ze.set("state",O),O})},[Ze]),H=t.useCallback(E=>{const de=Qe.includes(E)?Qe.filter(O=>O!==E):[...Qe,E];T?T(de):Fe({collapsedColumns:de})},[Qe,T,Fe]);t.useCallback(E=>{K?K(E):Fe({viewMode:E})},[K,Fe]);const be=t.useCallback(E=>a.filter(de=>de.column===E).sort((de,O)=>(de.order??0)-(O.order??0)),[a]),De=t.useCallback((E,de)=>{f||(E.dataTransfer.effectAllowed="move",E.dataTransfer.setData("text/plain",String(de.key)),re({cardKey:de.key,fromColumn:de.column}))},[f]),z=t.useCallback((E,de)=>{E.preventDefault(),E.dataTransfer.dropEffect="move",ee({column:de})},[]),ce=t.useCallback(()=>{ee(null)},[]),G=t.useCallback((E,de)=>{if(E.preventDefault(),ee(null),!ve||f)return;const O=be(de);r==null||r(ve.cardKey,de,O.length),re(null)},[ve,f,be,r]),_e=t.useCallback(()=>{re(null),ee(null)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:$,id:ie,className:`nice-kanban nice-kanban--${o} nice-kanban--${Le} nice-kanban--layout-${N} ${f?"nice-kanban--disabled":""} ${xe||""}`,style:{position:"relative",...Q},...M,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(we.Hd,{steps:we.Od(q,qi)})}),n.map(E=>{const de=be(E.key),O=(W==null?void 0:W.column)===E.key,We=E.limit!=null&&de.length>=E.limit,Ke=g&&Qe.includes(E.key);return e.jsxs("div",{className:`nice-kanban__column ${O?"nice-kanban__column--dragover":""} ${Ke?"nice-kanban__column--collapsed":""}`,onDragOver:ne=>!Ke&&z(ne,E.key),onDragLeave:ce,onDrop:ne=>!Ke&&G(ne,E.key),children:[e.jsxs("div",{className:"nice-kanban__column-header",style:E.color?{borderTopColor:E.color}:void 0,onClick:g?()=>H(E.key):void 0,role:g?"button":void 0,tabIndex:g?0:void 0,onKeyDown:g?ne=>{(ne.key==="Enter"||ne.key===" ")&&H(E.key)}:void 0,children:[g&&e.jsx("span",{className:"nice-kanban__collapse-icon","aria-hidden":"true",children:e.jsx(Xi,{open:!Ke})}),e.jsx("span",{className:"nice-kanban__column-title",children:E.title}),e.jsxs("span",{className:"nice-kanban__column-count",children:[de.length,E.limit!=null&&` / ${E.limit}`]})]}),!Ke&&e.jsxs("div",{className:"nice-kanban__column-body",children:[de.map(ne=>e.jsx("div",{className:`nice-kanban__card nice-kanban__card--${Le} ${(ve==null?void 0:ve.cardKey)===ne.key?"nice-kanban__card--dragging":""}`,draggable:!f,onDragStart:Ge=>De(Ge,ne),onDragEnd:_e,onClick:()=>ge(ne),role:"article",children:d?d(ne):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"nice-kanban__card-title",children:ne.title}),Le!=="compact"&&ne.description&&e.jsx("div",{className:"nice-kanban__card-desc",children:ne.description})]})},ne.key)),de.length===0&&e.jsx("div",{className:"nice-kanban__empty",children:b("kanban.empty","No cards")})]}),!Ke&&(m||pe&&R)&&!We&&e.jsxs("button",{type:"button",className:"nice-kanban__add",onClick:()=>Te(E.key),disabled:f,children:[e.jsx(Qi,{})," ",b("kanban.addCard","Add card")]})]},E.key)})]}),pe&&B&&e.jsxs(Tt,{open:!0,onClose:()=>J(null),title:B.key==null?w||b("kanban.newCard","New card"):s||b("kanban.editCard","Edit card"),children:[e.jsx(Re.Ga,{items:P,data:B.data,columns:V,...y,onFieldChange:(E,de)=>J(O=>O&&{...O,data:{...O.data,[E]:de}})}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16,flexWrap:"wrap"},children:[B.key!=null&&F&&e.jsx(Re.pn,{type:"button",size:"sm",variant:"error",style:{marginRight:"auto"},onClick:()=>{F(B.key),J(null)},children:b("controls.delete","Delete")}),e.jsx(Re.pn,{type:"button",size:"sm",variant:"secondary",onClick:()=>J(null),children:b("controls.cancel","Cancel")}),e.jsx(Re.pn,{type:"button",size:"sm",variant:"primary",onClick:()=>{if(B.key==null){const E={key:`card-${Date.now()}`,title:"",column:B.column,...B.data};R==null||R(E)}else c==null||c(B.key,{...B.data,key:B.key,column:B.column});J(null)},children:b("controls.save","Save")})]})]})]})});Ot.displayName="NiceKanbanBoard";function Rn(...n){return n.filter(Boolean).map(a=>typeof a=="object"?Object.entries(a).filter(([,r])=>r).map(([r])=>r).join(" "):a).join(" ")}const ea=50,na=[10,25,50,100,200],ta=40,ia=10,aa=768,ra=500,la=10;function kn(n,a){return a.split(".").reduce((r,l)=>r==null?void 0:r[l],n)}function ut(n,a,r="pl-PL"){var l,d,m;if(n==null)return"—";switch(a.type){case"number":return new Intl.NumberFormat(r,{minimumFractionDigits:(l=a.format)!=null&&l.includes(".")?a.format.split(".")[1].length:0}).format(n);case"currency":return new Intl.NumberFormat(r,{style:"currency",currency:a.currencyCode||"PLN"}).format(n);case"percent":return new Intl.NumberFormat(r,{style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}).format(n/100);case"date":return new Intl.DateTimeFormat(r,{dateStyle:"short"}).format(new Date(n));case"datetime":return new Intl.DateTimeFormat(r,{dateStyle:"short",timeStyle:"short"}).format(new Date(n));case"boolean":return n?"✓":"✗";case"enum":return((m=(d=a.enumOptions)==null?void 0:d.find(f=>f.value===n))==null?void 0:m.label)||String(n);default:return String(n)}}function sa(n,a,r,l){const[d,m]=t.useState(0),{startIndex:f,endIndex:o,totalHeight:g,offsetY:N}=t.useMemo(()=>{const I=n.length*r,T=Math.ceil(a/r),P=Math.max(0,Math.floor(d/r)-l),V=Math.min(n.length,Math.ceil(d/r)+T+l),y=P*r;return{startIndex:P,endIndex:V,totalHeight:I,offsetY:y}},[n.length,a,r,d,l]),S=t.useMemo(()=>n.slice(f,o),[n,f,o]),K=t.useCallback(I=>{m(I.currentTarget.scrollTop)},[]);return{visibleData:S,totalHeight:g,offsetY:N,handleScroll:K,startIndex:f}}function ca(n,a){const[r,l]=t.useState(()=>{if(n&&typeof window<"u"){const m=localStorage.getItem(`nice-module-grid-${n}`);if(m)return JSON.parse(m)}return a||{}}),d=t.useCallback(m=>{l(f=>{const o={...f,...m};return n&&typeof window<"u"&&localStorage.setItem(`nice-module-grid-${n}`,JSON.stringify(o)),o})},[n]);return[r,d]}function oa(n){const[a,r]=t.useState(typeof window<"u"&&window.innerWidth<n);return t.useEffect(()=>{if(typeof window>"u")return;const l=()=>r(window.innerWidth<n);return window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[n]),a}function da({column:n,sort:a,onSort:r,onResize:l,resizable:d,t:m}){const f=t.useRef(null),[o,g]=t.useState(!1),N=t.useCallback(I=>{if(!d||!l)return;I.preventDefault(),g(!0);const T=I.clientX,P=n.width||150,V=s=>{const w=s.clientX-T,c=Math.max(n.minWidth||50,P+w);l(n.field,Math.min(c,n.maxWidth||1/0))},y=()=>{g(!1),document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",y)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",y)},[n,d,l]),S=a==null?void 0:a.direction,K=S==="asc"?"↑":S==="desc"?"↓":null;return e.jsxs("div",{className:Rn("nice-module-grid__header-cell",n.sortable&&"nice-module-grid__header-cell--sortable",o&&"nice-module-grid__header-cell--resizing"),style:{width:n.width==="auto"?"auto":n.width||150,minWidth:n.minWidth,maxWidth:n.maxWidth,textAlign:n.align},onClick:()=>n.sortable&&(r==null?void 0:r(n.field)),role:"columnheader","aria-sort":S==="asc"?"ascending":S==="desc"?"descending":"none",title:n.headerTooltip,children:[e.jsx("span",{className:"nice-module-grid__header-text",children:n.header}),K&&e.jsx("span",{className:"nice-module-grid__sort-indicator",children:K}),d&&e.jsx("div",{ref:f,className:"nice-module-grid__resize-handle",onMouseDown:N})]})}function ua({column:n,row:a,rowIndex:r,value:l,locale:d="pl-PL",onClick:m}){const f=we.Kl({onClick:m}),o=m?f:{};if(n.render)return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:n.render(l,a,r)});if(n.type==="enum"&&n.enumOptions){const g=n.enumOptions.find(N=>N.value===l);if(g)return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:e.jsxs("span",{className:Rn("nice-module-grid__badge",`nice-module-grid__badge--${g.color||"default"}`),children:[g.icon&&e.jsx("span",{className:"nice-module-grid__badge-icon",children:g.icon}),g.label]})})}if(n.type==="progress"){const g=Math.min(100,Math.max(0,Number(l)||0));return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:e.jsxs("div",{className:"nice-module-grid__progress",children:[e.jsx("div",{className:Rn("nice-module-grid__progress-bar",`nice-module-grid__progress-bar--${n.progressColor||"primary"}`),style:{width:`${g}%`}}),e.jsxs("span",{className:"nice-module-grid__progress-text",children:[g,"%"]})]})})}if(n.type==="rating"){const g=n.maxRating||5,N=Number(l)||0;return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:e.jsx("span",{className:"nice-module-grid__rating","aria-label":`${N} out of ${g} stars`,children:Array.from({length:g},(S,K)=>e.jsx("span",{className:Rn("nice-module-grid__star",K<N&&"nice-module-grid__star--filled"),children:"★"},K))})})}if(n.type==="link"&&n.linkTemplate){const g=n.linkTemplate.replace(/\{\{(\w+)\}\}/g,(N,S)=>String(kn(a,S)??""));return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:e.jsx("a",{href:g,target:n.linkNewTab?"_blank":void 0,rel:n.linkNewTab?"noopener noreferrer":void 0,className:"nice-module-grid__link",children:ut(l,n,d)})})}if(n.type==="image"){const g={xs:24,sm:32,md:48,lg:64}[n.imageSize||"sm"];return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:l?e.jsx("img",{src:String(l),alt:"",className:"nice-module-grid__image",style:{width:g,height:g}}):e.jsx("div",{className:"nice-module-grid__image-placeholder",style:{width:g,height:g}})})}return n.type==="avatar"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:l?e.jsx("img",{src:String(l),alt:"",className:"nice-module-grid__avatar"}):e.jsx("div",{className:"nice-module-grid__avatar-placeholder",children:"?"})}):n.type==="color"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:e.jsx("span",{className:"nice-module-grid__color-swatch",style:{backgroundColor:l||"transparent"},title:l})}):n.type==="boolean"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align||"center"},...o,children:e.jsx("span",{className:Rn("nice-module-grid__boolean",!!l&&"nice-module-grid__boolean--true"),children:l?"✓":"✗"})}):e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:n.align},...o,children:ut(l,n,d)})}function ma({row:n,index:a,columns:r,primaryField:l,secondaryField:d,customRender:m,selected:f,onClick:o,locale:g="pl-PL",t:N}){if(m)return e.jsx("div",{className:Rn("nice-module-grid__mobile-card",f&&"nice-module-grid__mobile-card--selected"),onClick:o,children:m(n,a)});const S=r.find(I=>I.field===l)||r[0],K=r.find(I=>I.field===d)||r[1];return e.jsxs("div",{className:Rn("nice-module-grid__mobile-card",f&&"nice-module-grid__mobile-card--selected"),onClick:o,role:"row","aria-selected":f,children:[e.jsxs("div",{className:"nice-module-grid__mobile-card-header",children:[e.jsx("div",{className:"nice-module-grid__mobile-card-title",children:ut(kn(n,(S==null?void 0:S.field)||""),S,g)}),K&&e.jsx("div",{className:"nice-module-grid__mobile-card-subtitle",children:ut(kn(n,K.field),K,g)})]}),e.jsx("div",{className:"nice-module-grid__mobile-card-body",children:r.filter(I=>!I.hidden&&I.field!==l&&I.field!==d).slice(0,4).map(I=>e.jsxs("div",{className:"nice-module-grid__mobile-card-field",children:[e.jsx("span",{className:"nice-module-grid__mobile-card-label",children:I.header}),e.jsx("span",{className:"nice-module-grid__mobile-card-value",children:ut(kn(n,I.field),I,g)})]},I.field))})]})}function ha({page:n,pageSize:a,totalRows:r,pageSizeOptions:l,onPageChange:d,t:m}){const f=Math.ceil(r/a),o=(n-1)*a+1,g=Math.min(n*a,r);return e.jsxs("div",{className:"nice-module-grid__pagination",role:"navigation","aria-label":m("pagination.ariaLabel","Pagination"),children:[e.jsxs("div",{className:"nice-module-grid__pagination-info",children:[m("pagination.showing","Showing")," ",o,"–",g," ",m("pagination.of","of")," ",r]}),e.jsxs("div",{className:"nice-module-grid__pagination-controls",children:[e.jsx("select",{className:"nice-module-grid__page-size-select",value:a,onChange:N=>d(1,Number(N.target.value)),"aria-label":m("pagination.rowsPerPage","Rows per page"),children:l.map(N=>e.jsx("option",{value:N,children:N},N))}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(1,a),disabled:n===1,"aria-label":m("pagination.first","First"),children:"««"}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(n-1,a),disabled:n===1,"aria-label":m("pagination.previous","Previous"),children:"«"}),e.jsxs("span",{className:"nice-module-grid__pagination-page",children:[n," / ",f]}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(n+1,a),disabled:n>=f,"aria-label":m("pagination.next","Next"),children:"»"}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(f,a),disabled:n>=f,"aria-label":m("pagination.last","Last"),children:"»»"})]})]})}function pa({columns:n}){return e.jsx("div",{className:"nice-module-grid__row nice-module-grid__row--skeleton",role:"row",children:n.filter(a=>!a.hidden).map(a=>e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--skeleton",style:{width:a.width==="auto"?"auto":a.width||150},children:e.jsx("div",{className:"nice-module-grid__skeleton-bar"})},a.field))})}function ga(n,a){var st;const{columns:r,data:l,keyField:d="id",dataSource:m,onFetch:f,sortable:o=!0,sort:g,onSortChange:N,multiSort:S=!1,filterable:K=!1,filter:I,onFilterChange:T,searchText:P,onSearchChange:V,searchPlaceholder:y="moduleGrid.searchPlaceholder",pagination:s=!0,page:w,pageSize:c,pageSizeOptions:R=na,totalRows:F,onPageChange:q,virtualScroll:ue=!0,rowHeight:Ae=ta,overscan:A=ia,selectionMode:he="none",selectedKeys:ye,onSelectionChange:xe,columnReorder:Q=!0,onColumnOrderChange:ie,columnResize:M=!0,onColumnWidthChange:$,groupBy:b,onGroupByChange:ve,groupRowRender:re,expandAllGroups:W=!1,editable:ee=!1,onCellEdit:B,onRowEdit:J,editMode:pe="cell",contextMenuItems:ge,onContextMenuAction:Te,exportable:Ze=!0,exportFormats:en=["csv","excel"],onExport:$e,preferencesKey:Qe,initialPreferences:Le,onPreferencesChange:Fe,density:H="normal",striped:be=!0,bordered:De=!1,hoverable:z=!0,loading:ce=!1,emptyState:G,toolbar:_e,onRowClick:E,onRowDoubleClick:de,rowClassName:O,rowStyle:We,mobileCardView:Ke=!0,mobileBreakpoint:ne=aa,mobileCardRender:Ge,mobilePrimaryField:gn,mobileSecondaryField:je,moduleId:Nn,permissions:Cn,size:qe="medium",skeletonLoading:zn=!0,skeletonRows:D=la,"aria-label":oe,"aria-labelledby":me,"aria-describedby":ke,className:mn,style:Ce,id:Be,testId:hn}=n,{t:Ve}=we.de();we.Al(),we.Zs("table");const rn=oa(ne),[Sn,Jn]=ca(Qe,Le),Zn=t.useRef(null),nt=t.useRef(null),[Hn,Yn]=t.useState([]),[pn,ht]=t.useState(),[tt,Oe]=t.useState(""),[nn,Pe]=t.useState(1),[Un,Ln]=t.useState(c||ea),[Kn,Fn]=t.useState(new Set),[Gn,Xn]=t.useState([]),[u,h]=t.useState(0),[v,U]=t.useState(!1),[Y,k]=t.useState(new Set),[L,X]=t.useState(null),[Ee,ze]=t.useState({}),ae=g??Hn,He=I??pn,sn=P??tt,fn=w??nn,cn=c??Un,xn=ye??Kn,it=F??u??(l==null?void 0:l.length)??0,En=!!(f||m),Mn=t.useMemo(()=>{const _=new Set(Sn.hiddenColumns||[]);return r.filter(le=>!le.hidden&&!_.has(le.field))},[r,Sn.hiddenColumns]),Tn=t.useMemo(()=>{if(En)return Gn;if(!l)return[];let _=[...l];if(sn){const le=sn.toLowerCase(),fe=r.filter(Se=>Se.searchable!==!1).map(Se=>Se.field);_=_.filter(Se=>fe.some(Me=>{const Xe=kn(Se,Me);return String(Xe??"").toLowerCase().includes(le)}))}return ae.length>0&&_.sort((le,fe)=>{for(const Se of ae){const Me=kn(le,Se.field),Xe=kn(fe,Se.field),yn=Me<Xe?-1:Me>Xe?1:0;if(yn!==0)return Se.direction==="asc"?yn:-yn}return 0}),_},[En,Gn,l,sn,ae,r]),dn=t.useMemo(()=>{if(En||!s)return Tn;const _=(fn-1)*cn;return Tn.slice(_,_+cn)},[En,Tn,s,fn,cn]),pt=((st=Zn.current)==null?void 0:st.clientHeight)||400,An=ue&&dn.length>ra,{visibleData:On,totalHeight:Pn,offsetY:at,handleScroll:Ct,startIndex:rt}=sa(dn,pt,Ae,A),$n=An?On:dn,gt=t.useCallback(async()=>{if(f){U(!0);try{const _=await f({page:fn,pageSize:cn,sort:ae,filter:He,search:sn});Xn(_.data),h(_.total)}catch(_){console.error("NiceModuleGrid fetch error:",_)}finally{U(!1)}}},[f,fn,cn,ae,He,sn]);t.useEffect(()=>{En&&gt()},[En,gt]);const St=t.useCallback(_=>{const le=ae.find(Se=>Se.field===_);let fe;le?le.direction==="asc"?fe=ae.map(Se=>Se.field===_?{...Se,direction:"desc"}:Se):fe=ae.filter(Se=>Se.field!==_):fe=S?[...ae,{field:_,direction:"asc"}]:[{field:_,direction:"asc"}],N?N(fe):Yn(fe)},[ae,S,N]),Mt=t.useCallback((_,le)=>{q?q(_,le):(Pe(_),Ln(le))},[q]),Wt=t.useCallback(_=>{V?V(_):Oe(_),q||Pe(1)},[V,q]),ft=t.useCallback((_,le)=>{const fe=new Set(xn);if(he==="single"?(fe.clear(),fe.add(_)):(he==="multiple"||he==="checkbox")&&(fe.has(_)?fe.delete(_):fe.add(_)),xe){const Se=dn.filter(Me=>fe.has(String(kn(Me,d))));xe(fe,Se)}else Fn(fe)},[xn,he,xe,dn,d]),At=t.useCallback((_,le)=>{ze(fe=>({...fe,[_]:le})),$==null||$(_,le),Jn({columnWidths:{...Sn.columnWidths,[_]:le}})},[$,Jn,Sn.columnWidths]),xt=t.useCallback((_,le)=>{ge!=null&&ge.length&&(_.preventDefault(),X({x:_.clientX,y:_.clientY,row:le}))},[ge]),Bt=t.useCallback(_=>{L&&(Te==null||Te(_,L.row)),X(null)},[L,Te]),Ut=t.useCallback(async _=>{if($e)await $e(_,{selectedOnly:xn.size>0,columns:Mn.map(le=>le.field)});else if(_==="csv"){const le=Mn.map(un=>un.header).join(","),fe=dn.map(un=>Mn.map(bt=>JSON.stringify(kn(un,bt.field)??"")).join(",")),Se=[le,...fe].join(`
16
+ `),Me=new Blob([Se],{type:"text/csv;charset=utf-8;"}),Xe=URL.createObjectURL(Me),yn=document.createElement("a");yn.href=Xe,yn.download=`export-${new Date().toISOString().slice(0,10)}.csv`,yn.click(),URL.revokeObjectURL(Xe)}},[$e,xn,Mn,dn,Ve]);t.useEffect(()=>{if(!L)return;const _=()=>X(null);return document.addEventListener("click",_),()=>document.removeEventListener("click",_)},[L]);const lt=t.useCallback(_=>{_.key==="Escape"&&X(null)},[]),Ye=ce||v,on=!Ye&&$n.length===0,_n=rn&&Ke,Dt=Rn("nice-module-grid",`nice-module-grid--${H}`,`nice-module-grid--${qe}`,be&&"nice-module-grid--striped",De&&"nice-module-grid--bordered",z&&"nice-module-grid--hoverable",Ye&&"nice-module-grid--loading",_n&&"nice-module-grid--mobile",mn);return e.jsxs("div",{ref:a,id:Be,"data-testid":hn,className:Dt,style:Ce,onKeyDown:lt,role:"grid","aria-label":oe,"aria-labelledby":me,"aria-describedby":ke,"aria-rowcount":it,"aria-colcount":Mn.length,"aria-busy":Ye,children:[e.jsxs("div",{className:"nice-module-grid__toolbar",children:[e.jsx("div",{className:"nice-module-grid__toolbar-search",children:e.jsx("input",{type:"search",className:"nice-module-grid__search-input",placeholder:y,value:sn,onChange:_=>Wt(_.target.value),"aria-label":Ve("moduleGrid.searchAriaLabel","Search")})}),_e,Ze&&e.jsx("div",{className:"nice-module-grid__toolbar-export",children:en.map(_=>e.jsx("button",{className:"nice-module-grid__export-btn",onClick:()=>Ut(_),"aria-label":Ve(`moduleGrid.export.${_}`,`Export to ${_.toUpperCase()}`),children:_.toUpperCase()},_))})]}),e.jsx("div",{ref:Zn,className:"nice-module-grid__container",onScroll:An?Ct:void 0,children:_n?e.jsx("div",{className:"nice-module-grid__mobile-list",children:Ye&&zn?Array.from({length:D},(_,le)=>e.jsxs("div",{className:"nice-module-grid__mobile-card nice-module-grid__mobile-card--skeleton",children:[e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"60%",height:20}}),e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"40%",height:14}}),e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"80%",height:14}})]},le)):on?e.jsxs("div",{className:"nice-module-grid__empty",children:[(G==null?void 0:G.icon)&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:G.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:(G==null?void 0:G.title)||Ve("moduleGrid.noData","No data")}),(G==null?void 0:G.description)&&e.jsx("div",{className:"nice-module-grid__empty-description",children:G.description}),(G==null?void 0:G.action)&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:G.action.onClick,children:[G.action.icon,G.action.label]})]}):$n.map((_,le)=>{const fe=String(kn(_,d));return e.jsx(ma,{row:_,index:rt+le,columns:Mn,primaryField:gn,secondaryField:je,customRender:Ge,selected:xn.has(fe),onClick:()=>{he!=="none"&&ft(fe,_),E==null||E(_,rt+le)},t:Ve},fe)})}):e.jsxs("div",{ref:nt,className:"nice-module-grid__table",children:[e.jsxs("div",{className:"nice-module-grid__header",role:"row",children:[he==="checkbox"&&e.jsx("div",{className:"nice-module-grid__header-cell nice-module-grid__header-cell--checkbox",children:e.jsx("input",{type:"checkbox",checked:xn.size>0&&xn.size===$n.length,onChange:()=>{if(xn.size===$n.length)xe==null||xe(new Set,[]),Fn(new Set);else{const _=new Set($n.map(le=>String(kn(le,d))));xe==null||xe(_,$n),Fn(_)}},"aria-label":Ve("moduleGrid.selectAll","Select all")})}),Mn.map(_=>e.jsx(da,{column:{..._,width:Ee[_.field]||_.width},sort:ae.find(le=>le.field===_.field),onSort:o?St:void 0,onResize:M?At:void 0,resizable:M,t:Ve},_.field))]}),e.jsx("div",{className:"nice-module-grid__body",style:An?{height:Pn,position:"relative"}:void 0,children:Ye&&zn?Array.from({length:D},(_,le)=>e.jsx(pa,{columns:Mn},le)):on?e.jsxs("div",{className:"nice-module-grid__empty",children:[(G==null?void 0:G.icon)&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:G.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:(G==null?void 0:G.title)||Ve("moduleGrid.noData","No data")}),(G==null?void 0:G.description)&&e.jsx("div",{className:"nice-module-grid__empty-description",children:G.description}),(G==null?void 0:G.action)&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:G.action.onClick,children:[G.action.icon,G.action.label]})]}):e.jsx("div",{style:An?{transform:`translateY(${at}px)`}:void 0,children:$n.map((_,le)=>{const fe=String(kn(_,d)),Se=rt+le,Me=xn.has(fe),Xe=typeof O=="function"?O(_,Se):O,yn=typeof We=="function"?We(_,Se):We;return e.jsxs("div",{className:Rn("nice-module-grid__row",Me&&"nice-module-grid__row--selected",Xe),style:{...yn,height:Ae},role:"row","aria-rowindex":Se+1,"aria-selected":Me,onClick:()=>{he!=="none"&&ft(fe,_),E==null||E(_,Se)},onDoubleClick:()=>de==null?void 0:de(_,Se),onContextMenu:un=>xt(un,_),children:[he==="checkbox"&&e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--checkbox",children:e.jsx("input",{type:"checkbox",checked:Me,onChange:()=>ft(fe,_),onClick:un=>un.stopPropagation(),"aria-label":Ve("moduleGrid.selectRow","Select row")})}),Mn.map(un=>e.jsx(ua,{column:{...un,width:Ee[un.field]||un.width},row:_,rowIndex:Se,value:kn(_,un.field)},un.field))]},fe)})})})]})}),s&&it>0&&e.jsx(ha,{page:fn,pageSize:cn,totalRows:En?u:Tn.length,pageSizeOptions:R,onPageChange:Mt,t:Ve}),L&&ge&&e.jsx("div",{className:"nice-module-grid__context-menu",style:{left:L.x,top:L.y},role:"menu",children:ge.filter(_=>typeof _.hidden=="function"?!_.hidden(L.row):!_.hidden).map(_=>{if(_.divider)return e.jsx("div",{className:"nice-module-grid__context-menu-divider"},_.key);const le=typeof _.disabled=="function"?_.disabled(L.row):_.disabled;return e.jsxs("button",{className:Rn("nice-module-grid__context-menu-item",_.danger&&"nice-module-grid__context-menu-item--danger",le&&"nice-module-grid__context-menu-item--disabled"),onClick:()=>{var fe;le||((fe=_.onClick)==null||fe.call(_,L.row),Bt(_.key))},disabled:le,role:"menuitem",children:[_.icon&&e.jsx("span",{className:"nice-module-grid__context-menu-icon",children:_.icon}),_.label]},_.key)})}),Ye&&!zn&&e.jsx("div",{className:"nice-module-grid__loading-overlay",children:e.jsx("div",{className:"nice-module-grid__spinner","aria-label":Ve("moduleGrid.loading","Loading")})})]})}t.forwardRef(ga);const fa=`
17
+ .nice-reconciliation {
18
+ display: flex;
19
+ flex-direction: column;
20
+ height: 100%;
21
+ background: var(--nice-bg-primary, #ffffff);
22
+ border: 1px solid var(--nice-border-color, #e5e7eb);
23
+ border-radius: var(--nice-radius-lg, 0.5rem);
24
+ overflow: hidden;
25
+ }
26
+
27
+ .nice-reconciliation__toolbar {
28
+ display: flex;
29
+ align-items: center;
30
+ gap: 0.75rem;
31
+ padding: 0.75rem 1rem;
32
+ background: var(--nice-bg-secondary, #f9fafb);
33
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
34
+ flex-wrap: wrap;
35
+ }
36
+
37
+ .nice-reconciliation__toolbar-group {
38
+ display: flex;
39
+ align-items: center;
40
+ gap: 0.5rem;
41
+ }
42
+
43
+ .nice-reconciliation__toolbar-group--end {
44
+ margin-inline-start: auto;
45
+ }
46
+
47
+ .nice-reconciliation__btn {
48
+ display: inline-flex;
49
+ align-items: center;
50
+ gap: 0.375rem;
51
+ padding: 0.375rem 0.75rem;
52
+ font-size: 0.8125rem;
53
+ font-weight: 500;
54
+ border-radius: var(--nice-radius-md, 0.375rem);
55
+ cursor: pointer;
56
+ transition: all 0.15s ease;
57
+ border: 1px solid var(--nice-border-color, #d1d5db);
58
+ background: var(--nice-bg-primary, #ffffff);
59
+ color: var(--nice-text-primary);
60
+ }
61
+
62
+ .nice-reconciliation__btn:hover {
63
+ background: var(--nice-bg-hover, #f3f4f6);
64
+ }
65
+
66
+ .nice-reconciliation__btn--primary {
67
+ background: var(--nice-primary, #3b82f6);
68
+ border-color: var(--nice-primary, #3b82f6);
69
+ color: white;
70
+ }
71
+
72
+ .nice-reconciliation__btn--primary:hover {
73
+ background: var(--nice-primary-dark, #2563eb);
74
+ }
75
+
76
+ .nice-reconciliation__btn--success {
77
+ background: var(--nice-success, #10b981);
78
+ border-color: var(--nice-success, #10b981);
79
+ color: white;
80
+ }
81
+
82
+ .nice-reconciliation__btn:disabled {
83
+ opacity: 0.5;
84
+ cursor: not-allowed;
85
+ }
86
+
87
+ .nice-reconciliation__content {
88
+ display: flex;
89
+ flex: 1;
90
+ overflow: hidden;
91
+ }
92
+
93
+ .nice-reconciliation--vertical .nice-reconciliation__content {
94
+ flex-direction: column;
95
+ }
96
+
97
+ .nice-reconciliation__panel {
98
+ flex: 1;
99
+ display: flex;
100
+ flex-direction: column;
101
+ min-width: 0;
102
+ min-height: 0;
103
+ overflow: hidden;
104
+ }
105
+
106
+ .nice-reconciliation__panel--statements {
107
+ border-inline-end: 1px solid var(--nice-border-color, #e5e7eb);
108
+ }
109
+
110
+ .nice-reconciliation--vertical .nice-reconciliation__panel--statements {
111
+ border-inline-end: none;
112
+ border-block-end: 1px solid var(--nice-border-color, #e5e7eb);
113
+ }
114
+
115
+ .nice-reconciliation__panel-header {
116
+ display: flex;
117
+ align-items: center;
118
+ justify-content: space-between;
119
+ padding: 0.75rem 1rem;
120
+ background: var(--nice-bg-secondary, #f9fafb);
121
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
122
+ }
123
+
124
+ .nice-reconciliation__panel-title {
125
+ font-weight: 600;
126
+ font-size: 0.875rem;
127
+ color: var(--nice-text-primary);
128
+ display: flex;
129
+ align-items: center;
130
+ gap: 0.5rem;
131
+ }
132
+
133
+ .nice-reconciliation__panel-badge {
134
+ font-size: 0.75rem;
135
+ font-weight: 500;
136
+ padding: 0.125rem 0.5rem;
137
+ border-radius: var(--nice-radius-full, 9999px);
138
+ background: var(--nice-bg-tertiary, #e5e7eb);
139
+ color: var(--nice-text-secondary);
140
+ }
141
+
142
+ .nice-reconciliation__panel-content {
143
+ flex: 1;
144
+ overflow: auto;
145
+ }
146
+
147
+ .nice-reconciliation__row {
148
+ display: flex;
149
+ align-items: center;
150
+ gap: 0.75rem;
151
+ padding: 0.625rem 1rem;
152
+ border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
153
+ cursor: pointer;
154
+ user-select: none;
155
+ transition: background 0.1s ease;
156
+ }
157
+
158
+ .nice-reconciliation__row:hover {
159
+ background: var(--nice-bg-hover, rgba(0, 0, 0, 0.02));
160
+ }
161
+
162
+ .nice-reconciliation__row--selected {
163
+ background: var(--nice-primary-light, rgba(59, 130, 246, 0.1));
164
+ }
165
+
166
+ .nice-reconciliation__row--dragging {
167
+ opacity: 0.6;
168
+ background: var(--nice-primary-light, rgba(59, 130, 246, 0.15));
169
+ }
170
+
171
+ .nice-reconciliation__row--drop-target {
172
+ background: var(--nice-success-light, rgba(16, 185, 129, 0.15));
173
+ box-shadow: inset 0 0 0 2px var(--nice-success, #10b981);
174
+ }
175
+
176
+ .nice-reconciliation__row--matched {
177
+ background: var(--nice-success-light, rgba(16, 185, 129, 0.08));
178
+ }
179
+
180
+ .nice-reconciliation__row--partial {
181
+ background: var(--nice-warning-light, rgba(245, 158, 11, 0.08));
182
+ }
183
+
184
+ .nice-reconciliation__row--unmatched {
185
+ background: transparent;
186
+ }
187
+
188
+ .nice-reconciliation__row--excluded {
189
+ opacity: 0.5;
190
+ background: var(--nice-bg-disabled, #f3f4f6);
191
+ }
192
+
193
+ .nice-reconciliation__status {
194
+ width: 0.5rem;
195
+ height: 0.5rem;
196
+ border-radius: var(--nice-radius-full, 50%);
197
+ flex-shrink: 0;
198
+ }
199
+
200
+ .nice-reconciliation__status--matched {
201
+ background: var(--nice-success, #10b981);
202
+ }
203
+
204
+ .nice-reconciliation__status--partial {
205
+ background: var(--nice-warning, #f59e0b);
206
+ }
207
+
208
+ .nice-reconciliation__status--unmatched {
209
+ background: var(--nice-danger, #ef4444);
210
+ }
211
+
212
+ .nice-reconciliation__status--excluded {
213
+ background: var(--nice-text-disabled, #9ca3af);
214
+ }
215
+
216
+ .nice-reconciliation__row-main {
217
+ flex: 1;
218
+ min-width: 0;
219
+ }
220
+
221
+ .nice-reconciliation__row-date {
222
+ font-size: 0.75rem;
223
+ color: var(--nice-text-secondary);
224
+ margin-bottom: 0.125rem;
225
+ }
226
+
227
+ .nice-reconciliation__row-description {
228
+ font-size: 0.8125rem;
229
+ color: var(--nice-text-primary);
230
+ white-space: nowrap;
231
+ overflow: hidden;
232
+ text-overflow: ellipsis;
233
+ }
234
+
235
+ .nice-reconciliation__row-counterparty {
236
+ font-size: 0.75rem;
237
+ color: var(--nice-text-tertiary);
238
+ white-space: nowrap;
239
+ overflow: hidden;
240
+ text-overflow: ellipsis;
241
+ }
242
+
243
+ .nice-reconciliation__row-amount {
244
+ font-size: 0.875rem;
245
+ font-weight: 600;
246
+ font-variant-numeric: tabular-nums;
247
+ white-space: nowrap;
248
+ }
249
+
250
+ .nice-reconciliation__row-amount--positive {
251
+ color: var(--nice-success, #10b981);
252
+ }
253
+
254
+ .nice-reconciliation__row-amount--negative {
255
+ color: var(--nice-danger, #ef4444);
256
+ }
257
+
258
+ .nice-reconciliation__confidence {
259
+ display: flex;
260
+ align-items: center;
261
+ gap: 0.25rem;
262
+ font-size: 0.6875rem;
263
+ padding: 0.125rem 0.375rem;
264
+ border-radius: var(--nice-radius-sm, 0.25rem);
265
+ }
266
+
267
+ .nice-reconciliation__confidence--high {
268
+ background: var(--nice-success-light, rgba(16, 185, 129, 0.15));
269
+ color: var(--nice-success-dark, #059669);
270
+ }
271
+
272
+ .nice-reconciliation__confidence--medium {
273
+ background: var(--nice-warning-light, rgba(245, 158, 11, 0.15));
274
+ color: var(--nice-warning-dark, #d97706);
275
+ }
276
+
277
+ .nice-reconciliation__confidence--low {
278
+ background: var(--nice-danger-light, rgba(239, 68, 68, 0.15));
279
+ color: var(--nice-danger-dark, #dc2626);
280
+ }
281
+
282
+ .nice-reconciliation__empty {
283
+ display: flex;
284
+ flex-direction: column;
285
+ align-items: center;
286
+ justify-content: center;
287
+ padding: 3rem 1rem;
288
+ color: var(--nice-text-secondary);
289
+ text-align: center;
290
+ }
291
+
292
+ .nice-reconciliation__empty-icon {
293
+ font-size: 2.5rem;
294
+ margin-bottom: 0.75rem;
295
+ opacity: 0.5;
296
+ }
297
+
298
+ .nice-reconciliation__summary {
299
+ display: flex;
300
+ align-items: center;
301
+ gap: 1.5rem;
302
+ padding: 0.75rem 1rem;
303
+ background: var(--nice-bg-secondary, #f9fafb);
304
+ border-top: 1px solid var(--nice-border-color, #e5e7eb);
305
+ font-size: 0.8125rem;
306
+ flex-wrap: wrap;
307
+ }
308
+
309
+ .nice-reconciliation__summary-item {
310
+ display: flex;
311
+ align-items: center;
312
+ gap: 0.375rem;
313
+ }
314
+
315
+ .nice-reconciliation__summary-label {
316
+ color: var(--nice-text-secondary);
317
+ }
318
+
319
+ .nice-reconciliation__summary-value {
320
+ font-weight: 600;
321
+ color: var(--nice-text-primary);
322
+ font-variant-numeric: tabular-nums;
323
+ }
324
+
325
+ .nice-reconciliation__summary-value--success {
326
+ color: var(--nice-success, #10b981);
327
+ }
328
+
329
+ .nice-reconciliation__summary-value--warning {
330
+ color: var(--nice-warning, #f59e0b);
331
+ }
332
+
333
+ .nice-reconciliation__summary-value--danger {
334
+ color: var(--nice-danger, #ef4444);
335
+ }
336
+
337
+ .nice-reconciliation__resizer {
338
+ width: 4px;
339
+ background: var(--nice-border-color, #e5e7eb);
340
+ cursor: col-resize;
341
+ transition: background 0.15s ease;
342
+ }
343
+
344
+ .nice-reconciliation__resizer:hover {
345
+ background: var(--nice-primary, #3b82f6);
346
+ }
347
+
348
+ .nice-reconciliation--vertical .nice-reconciliation__resizer {
349
+ width: 100%;
350
+ height: 4px;
351
+ cursor: row-resize;
352
+ }
353
+
354
+ .nice-reconciliation__suggestions {
355
+ padding: 0.75rem 1rem;
356
+ background: var(--nice-info-light, rgba(59, 130, 246, 0.08));
357
+ border-bottom: 1px solid var(--nice-info, #3b82f6);
358
+ }
359
+
360
+ .nice-reconciliation__suggestion {
361
+ display: flex;
362
+ align-items: center;
363
+ gap: 0.75rem;
364
+ padding: 0.5rem;
365
+ background: var(--nice-bg-primary, #ffffff);
366
+ border-radius: var(--nice-radius-md, 0.375rem);
367
+ margin-bottom: 0.5rem;
368
+ }
369
+
370
+ .nice-reconciliation__suggestion:last-child {
371
+ margin-bottom: 0;
372
+ }
373
+
374
+ /* Dark mode */
375
+ .dark .nice-reconciliation {
376
+ background: var(--nice-bg-primary-dark, #111827);
377
+ border-color: var(--nice-border-color-dark, #374151);
378
+ }
379
+
380
+ .dark .nice-reconciliation__toolbar,
381
+ .dark .nice-reconciliation__panel-header,
382
+ .dark .nice-reconciliation__summary {
383
+ background: var(--nice-bg-secondary-dark, #1f2937);
384
+ border-color: var(--nice-border-color-dark, #374151);
385
+ }
386
+
387
+ .dark .nice-reconciliation__row--selected {
388
+ background: var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2));
389
+ }
390
+
391
+ /* RTL support */
392
+ [dir="rtl"] .nice-reconciliation__row-amount {
393
+ direction: ltr;
394
+ text-align: left;
395
+ }
396
+
397
+ /* Detail Panel */
398
+ .nice-reconciliation__detail-panel {
399
+ position: fixed;
400
+ inset-inline-end: 0;
401
+ top: 0;
402
+ bottom: 0;
403
+ width: 420px;
404
+ max-width: 90vw;
405
+ background: var(--nice-bg-primary, #ffffff);
406
+ box-shadow: -4px 0 24px var(--nice-overlay-15, rgba(0, 0, 0, 0.15));
407
+ z-index: 1000;
408
+ display: flex;
409
+ flex-direction: column;
410
+ transform: translateX(100%);
411
+ transition: transform 0.25s ease-out;
412
+ }
413
+
414
+ .nice-reconciliation__detail-panel--open {
415
+ transform: translateX(0);
416
+ }
417
+
418
+ .nice-reconciliation__detail-header {
419
+ display: flex;
420
+ align-items: center;
421
+ justify-content: space-between;
422
+ padding: 1rem;
423
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
424
+ background: var(--nice-bg-secondary, #f9fafb);
425
+ }
426
+
427
+ .nice-reconciliation__detail-title {
428
+ font-weight: 600;
429
+ font-size: 1rem;
430
+ color: var(--nice-text-primary);
431
+ display: flex;
432
+ align-items: center;
433
+ gap: 0.5rem;
434
+ }
435
+
436
+ .nice-reconciliation__detail-close {
437
+ width: 2rem;
438
+ height: 2rem;
439
+ display: flex;
440
+ align-items: center;
441
+ justify-content: center;
442
+ background: transparent;
443
+ border: none;
444
+ cursor: pointer;
445
+ font-size: 1.25rem;
446
+ color: var(--nice-text-secondary);
447
+ border-radius: var(--nice-radius-md, 0.375rem);
448
+ transition: all 0.15s ease;
449
+ }
450
+
451
+ .nice-reconciliation__detail-close:hover {
452
+ background: var(--nice-bg-hover, #f3f4f6);
453
+ color: var(--nice-text-primary);
454
+ }
455
+
456
+ .nice-reconciliation__detail-content {
457
+ flex: 1;
458
+ overflow: auto;
459
+ padding: 1rem;
460
+ }
461
+
462
+ .nice-reconciliation__detail-section {
463
+ margin-bottom: 1.5rem;
464
+ }
465
+
466
+ .nice-reconciliation__detail-section-title {
467
+ font-weight: 600;
468
+ font-size: 0.875rem;
469
+ color: var(--nice-text-primary);
470
+ margin-bottom: 0.75rem;
471
+ display: flex;
472
+ align-items: center;
473
+ gap: 0.375rem;
474
+ }
475
+
476
+ .nice-reconciliation__detail-row {
477
+ display: flex;
478
+ justify-content: space-between;
479
+ align-items: flex-start;
480
+ padding: 0.5rem 0;
481
+ border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
482
+ }
483
+
484
+ .nice-reconciliation__detail-row:last-child {
485
+ border-bottom: none;
486
+ }
487
+
488
+ .nice-reconciliation__detail-label {
489
+ font-size: 0.8125rem;
490
+ color: var(--nice-text-secondary);
491
+ }
492
+
493
+ .nice-reconciliation__detail-value {
494
+ font-size: 0.8125rem;
495
+ font-weight: 500;
496
+ color: var(--nice-text-primary);
497
+ text-align: end;
498
+ max-width: 60%;
499
+ word-break: break-word;
500
+ }
501
+
502
+ .nice-reconciliation__detail-divider {
503
+ height: 1px;
504
+ background: var(--nice-border-color, #e5e7eb);
505
+ margin: 1rem 0;
506
+ }
507
+
508
+ .nice-reconciliation__detail-match-info {
509
+ padding: 0.75rem;
510
+ background: var(--nice-success-light, rgba(16, 185, 129, 0.08));
511
+ border-radius: var(--nice-radius-md, 0.375rem);
512
+ margin-bottom: 1rem;
513
+ }
514
+
515
+ .nice-reconciliation__detail-match-header {
516
+ display: flex;
517
+ align-items: center;
518
+ gap: 0.5rem;
519
+ font-weight: 600;
520
+ font-size: 0.8125rem;
521
+ color: var(--nice-success-dark, #059669);
522
+ margin-bottom: 0.5rem;
523
+ }
524
+
525
+ .nice-reconciliation__detail-match-detail {
526
+ font-size: 0.75rem;
527
+ color: var(--nice-text-secondary);
528
+ }
529
+
530
+ .nice-reconciliation__detail-side-by-side {
531
+ display: grid;
532
+ grid-template-columns: 1fr 1fr;
533
+ gap: 1rem;
534
+ padding: 0.75rem;
535
+ background: var(--nice-bg-secondary, #f9fafb);
536
+ border-radius: var(--nice-radius-md, 0.375rem);
537
+ margin-top: 0.75rem;
538
+ }
539
+
540
+ .nice-reconciliation__detail-side-item {
541
+ padding: 0.5rem;
542
+ background: var(--nice-bg-primary, #ffffff);
543
+ border-radius: var(--nice-radius-sm, 0.25rem);
544
+ border: 1px solid var(--nice-border-color, #e5e7eb);
545
+ }
546
+
547
+ .nice-reconciliation__detail-side-label {
548
+ font-size: 0.6875rem;
549
+ font-weight: 500;
550
+ text-transform: uppercase;
551
+ color: var(--nice-text-tertiary);
552
+ margin-bottom: 0.375rem;
553
+ }
554
+
555
+ .nice-reconciliation__detail-side-amount {
556
+ font-size: 1.125rem;
557
+ font-weight: 600;
558
+ font-variant-numeric: tabular-nums;
559
+ }
560
+
561
+ .nice-reconciliation__detail-backdrop {
562
+ position: fixed;
563
+ inset: 0;
564
+ background: var(--nice-overlay-30, rgba(0, 0, 0, 0.3));
565
+ z-index: 999;
566
+ opacity: 0;
567
+ pointer-events: none;
568
+ transition: opacity 0.2s ease;
569
+ }
570
+
571
+ .nice-reconciliation__detail-backdrop--visible {
572
+ opacity: 1;
573
+ pointer-events: auto;
574
+ }
575
+
576
+ .dark .nice-reconciliation__detail-panel {
577
+ background: var(--nice-bg-primary-dark, #111827);
578
+ box-shadow: -4px 0 24px var(--nice-overlay-40, rgba(0, 0, 0, 0.4));
579
+ }
580
+
581
+ .dark .nice-reconciliation__detail-header {
582
+ background: var(--nice-bg-secondary-dark, #1f2937);
583
+ border-color: var(--nice-border-color-dark, #374151);
584
+ }
585
+
586
+ .dark .nice-reconciliation__detail-side-by-side {
587
+ background: var(--nice-bg-secondary-dark, #1f2937);
588
+ }
589
+
590
+ .dark .nice-reconciliation__detail-side-item {
591
+ background: var(--nice-bg-primary-dark, #111827);
592
+ border-color: var(--nice-border-color-dark, #374151);
593
+ }
594
+ `;function In(n,a="PLN",r="pl-PL"){return new Intl.NumberFormat(r,{style:"currency",currency:a,minimumFractionDigits:2,maximumFractionDigits:2}).format(n)}function Nt(n,a="pl-PL"){return n?(typeof n=="string"?new Date(n):n).toLocaleDateString(a,{year:"numeric",month:"2-digit",day:"2-digit"}):"-"}function xa(n){return n>=80?"high":n>=50?"medium":"low"}function ba(){return`match-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function _a({item:n,isSelected:a,isDragging:r,isDropTarget:l,suggestion:d,currency:m,locale:f,onSelect:o,onDoubleClick:g,onDragStart:N,onDragEnd:S,onDrop:K,disabled:I}){const T=n.status??"unmatched",P=(d==null?void 0:d.confidence)??n.confidence,V=s=>{s.dataTransfer.setData("text/plain",n.id),s.dataTransfer.setData("source","statement"),s.dataTransfer.effectAllowed="move",N()},y=s=>{s.dataTransfer.types.includes("source")&&s.dataTransfer.getData("source")!=="statement"&&s.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${T} ${a?"nice-reconciliation__row--selected":""} ${r?"nice-reconciliation__row--dragging":""} ${l?"nice-reconciliation__row--drop-target":""}`,draggable:!I&&T!=="matched",onDragStart:V,onDragEnd:S,onDragOver:y,onDrop:K,onClick:o,onDoubleClick:g,role:"row","aria-selected":a,tabIndex:0,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${T}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsx("div",{className:"nice-reconciliation__row-date",children:Nt(n.date,f)}),e.jsx("div",{className:"nice-reconciliation__row-description",title:n.description,children:n.description}),n.counterparty&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:n.counterparty})]}),P!=null&&e.jsxs("span",{className:`nice-reconciliation__confidence nice-reconciliation__confidence--${xa(P)}`,children:[P,"%"]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${n.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:In(n.amount,m,f)})]})}function ya({item:n,isSelected:a,isDragging:r,isDropTarget:l,currency:d,locale:m,onSelect:f,onDoubleClick:o,onDragStart:g,onDragEnd:N,onDrop:S,disabled:K}){const I=n.status??"unmatched",T=V=>{V.dataTransfer.setData("text/plain",n.id),V.dataTransfer.setData("source","entry"),V.dataTransfer.effectAllowed="move",g()},P=V=>{V.dataTransfer.types.includes("source")&&V.dataTransfer.getData("source")!=="entry"&&V.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${I} ${a?"nice-reconciliation__row--selected":""} ${r?"nice-reconciliation__row--dragging":""} ${l?"nice-reconciliation__row--drop-target":""}`,draggable:!K&&I!=="matched",onDragStart:T,onDragEnd:N,onDragOver:P,onDrop:S,onClick:f,onDoubleClick:o,role:"row","aria-selected":a,tabIndex:0,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${I}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsxs("div",{className:"nice-reconciliation__row-date",children:[Nt(n.date,m),n.documentNumber&&e.jsxs("span",{children:[" · ",n.documentNumber]})]}),e.jsx("div",{className:"nice-reconciliation__row-description",title:n.description,children:n.description}),n.partyName&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:n.partyName})]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${n.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:In(n.amount,d,m)})]})}t.forwardRef(function(n,a){const{statements:r,bankTransactions:l,entries:d,accountingEntries:m,matches:f,defaultMatches:o=[],suggestions:g=[],config:N={},currency:S,showConfidence:K,statementPanelConfig:I,entryPanelConfig:T,onMatch:P,onAutoMatch:V,onUnmatch:y,onBatchAction:s,onFilterChange:w,onRequestSuggestions:c,onSelectionChange:R,onComplete:F,size:q="medium",showToolbar:ue=!0,showFilters:Ae=!0,showSummary:A=!0,showSuggestions:he=!0,layout:ye="horizontal",enableDragDrop:xe=!0,enableKeyboard:Q=!0,enableDetailPanel:ie=!0,loading:M=!1,disabled:$=!1,readOnly:b=!1,locale:ve="pl-PL",labels:re={},className:W,style:ee}=n,B=r??l??[],J=d??m??[],pe=S??N.currency??"PLN",[ge,Te]=t.useState(o),[Ze,en]=t.useState(new Set),[$e,Qe]=t.useState(new Set),[Le,Fe]=t.useState(null),[H,be]=t.useState(null),[De,z]=t.useState({}),[ce,G]=t.useState(null),_e=f??ge,E=t.useRef(null),de=t.useRef(null);t.useEffect(()=>{const D="nice-reconciliation-styles";if(!document.getElementById(D)){const oe=document.createElement("style");oe.id=D,oe.textContent=fa,document.head.appendChild(oe)}},[]);const O=t.useMemo(()=>{const D=new Set;return _e.forEach(oe=>oe.statementIds.forEach(me=>D.add(me))),D},[_e]),We=t.useMemo(()=>{const D=new Set;return _e.forEach(oe=>oe.entryIds.forEach(me=>D.add(me))),D},[_e]),Ke=t.useMemo(()=>{const D=B.filter(Ce=>!O.has(Ce.id)),oe=J.filter(Ce=>!We.has(Ce.id)),me=B.reduce((Ce,Be)=>Ce+Be.amount,0),ke=J.reduce((Ce,Be)=>Ce+Be.amount,0),mn=B.filter(Ce=>O.has(Ce.id)).reduce((Ce,Be)=>Ce+Be.amount,0);return{totalStatements:B.length,totalEntries:J.length,matchedStatements:B.length-D.length,matchedEntries:J.length-oe.length,unmatchedStatements:D.length,unmatchedEntries:oe.length,statementTotal:me,entryTotal:ke,matchedAmount:mn,unmatchedStatementAmount:D.reduce((Ce,Be)=>Ce+Be.amount,0),unmatchedEntryAmount:oe.reduce((Ce,Be)=>Ce+Be.amount,0),difference:me-ke,matchPercentage:B.length>0?Math.round((B.length-D.length)/B.length*100):0,matchCount:_e.length,partialMatchCount:_e.filter(Ce=>Ce.status==="partial").length,pendingSuggestions:g.length}},[B,J,_e,g,O,We]),ne=t.useCallback((D,oe)=>{const me=B.filter(rn=>D.includes(rn.id)),ke=J.filter(rn=>oe.includes(rn.id));if(me.length===0||ke.length===0)return null;const mn=me.reduce((rn,Sn)=>rn+Sn.amount,0),Ce=ke.reduce((rn,Sn)=>rn+Sn.amount,0),Be=Math.abs(mn-Ce),hn=N.amountTolerance??.01,Ve={id:ba(),statementIds:D,entryIds:oe,status:Be<=hn?"matched":"partial",statementTotal:mn,entryTotal:Ce,difference:Be,confidence:Be<=hn?100:Math.max(0,100-Be/Math.max(Math.abs(mn),1)*100),matchedBy:"user",matchedAt:new Date};return f||Te(rn=>[...rn,Ve]),P==null||P(Ve,me,ke),en(new Set),Qe(new Set),Ve},[B,J,N.amountTolerance,f,P]),Ge=t.useCallback(D=>{const oe=_e.find(me=>me.id===D);oe&&(f||Te(me=>me.filter(ke=>ke.id!==D)),y==null||y(D,oe.statementIds,oe.entryIds))},[_e,f,y]),gn=t.useCallback(async()=>{const D=[],oe=new Set(O),me=new Set(We),ke=N.amountTolerance??.01,mn=N.dateTolerance??3;for(const Ce of B){if(oe.has(Ce.id))continue;const Be=J.filter(hn=>{if(me.has(hn.id)||Math.abs(Ce.amount-hn.amount)>ke)return!1;const Ve=new Date(Ce.date),rn=new Date(hn.date);return!(Math.abs(Ve.getTime()-rn.getTime())/(1e3*60*60*24)>mn)});if(Be.length===1){const hn=Be[0],Ve=ne([Ce.id],[hn.id]);Ve&&(D.push(Ve),oe.add(Ce.id),me.add(hn.id))}}return s==null||s("autoMatch",D),D},[B,J,O,We,N,ne,s]),je=t.useCallback((D,oe,me,ke)=>{ke!==oe&&(ke==="statement"?ne([me],[D]):ne([D],[me]),Fe(null),be(null))},[ne]),Nn=t.useCallback(()=>{const D=Array.from(Ze),oe=Array.from($e);D.length>0&&oe.length>0&&ne(D,oe)},[Ze,$e,ne]);t.useEffect(()=>{R==null||R(Array.from(Ze),Array.from($e))},[Ze,$e,R]),t.useImperativeHandle(a,()=>({getMatches:()=>_e,getUnmatchedStatements:()=>B.filter(D=>!O.has(D.id)),getUnmatchedEntries:()=>J.filter(D=>!We.has(D.id)),createMatch:ne,removeMatch:Ge,autoMatch:gn,getSuggestions:async D=>c?c(D??B.filter(oe=>!O.has(oe.id)).map(oe=>oe.id)):[],applySuggestion:D=>ne([D.statementId],D.entryIds),approveAll:()=>{s==null||s("approveAll",_e)},clearAll:()=>{f||Te([]),s==null||s("clearAll",[])},exportMatched:D=>{s==null||s("exportMatched",_e)},getSummary:()=>Ke,reset:()=>{f||Te([]),en(new Set),Qe(new Set),z({})},focusStatements:()=>{var D;return(D=E.current)==null?void 0:D.focus()},focusEntries:()=>{var D;return(D=de.current)==null?void 0:D.focus()}}),[_e,B,J,O,We,ne,Ge,gn,c,s,f,Ke]);const Cn=t.useMemo(()=>B.filter(D=>{var oe,me;if(De.status&&De.status.length>0){const ke=O.has(D.id)?"matched":"unmatched";if(!De.status.includes(ke))return!1}if(De.searchText){const ke=De.searchText.toLowerCase();if(!((oe=D.description)!=null&&oe.toLowerCase().includes(ke))&&!((me=D.counterparty)!=null&&me.toLowerCase().includes(ke)))return!1}return!0}),[B,De,O]),qe=t.useMemo(()=>J.filter(D=>{var oe,me;if(De.status&&De.status.length>0){const ke=We.has(D.id)?"matched":"unmatched";if(!De.status.includes(ke))return!1}if(De.searchText){const ke=De.searchText.toLowerCase();if(!((oe=D.description)!=null&&oe.toLowerCase().includes(ke))&&!((me=D.partyName)!=null&&me.toLowerCase().includes(ke)))return!1}return!0}),[J,De,We]),zn=Ze.size>0&&$e.size>0&&!b&&!$;return e.jsxs("div",{className:`nice-reconciliation nice-reconciliation--${ye} ${W??""}`,style:ee,children:[ue&&e.jsxs("div",{className:"nice-reconciliation__toolbar",children:[e.jsxs("div",{className:"nice-reconciliation__toolbar-group",children:[e.jsxs("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--primary",onClick:gn,disabled:$||b||M,children:["⚡ ",re.autoMatch??"Auto-match"]}),e.jsx("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--success",onClick:Nn,disabled:!zn||M,children:"🔗 Match Selected"})]}),e.jsxs("div",{className:"nice-reconciliation__toolbar-group nice-reconciliation__toolbar-group--end",children:[e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>s==null?void 0:s("approveAll",_e),disabled:_e.length===0||$||M,children:["✓ ",re.approveAll??"Approve All"]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>{f||Te([]),s==null||s("clearAll",[])},disabled:_e.length===0||$||b||M,children:["✕ ",re.clearAll??"Clear All"]})]})]}),e.jsxs("div",{className:"nice-reconciliation__content",children:[e.jsxs("div",{className:"nice-reconciliation__panel nice-reconciliation__panel--statements",children:[e.jsx("div",{className:"nice-reconciliation__panel-header",children:e.jsxs("span",{className:"nice-reconciliation__panel-title",children:["📄 ",re.statementPanelTitle??"Bank Statement",e.jsx("span",{className:"nice-reconciliation__panel-badge",children:Cn.length})]})}),e.jsx("div",{ref:E,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:Cn.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:"📋"}),re.noStatements??"No statement items"]}):Cn.map(D=>e.jsx(_a,{item:{...D,status:O.has(D.id)?"matched":"unmatched"},isSelected:Ze.has(D.id),isDragging:Le===D.id,isDropTarget:H===D.id,suggestion:g.find(oe=>oe.statementId===D.id),currency:pe,locale:ve,onSelect:()=>{$||en(oe=>{const me=new Set(oe);return me.has(D.id)?me.delete(D.id):me.add(D.id),me})},onDoubleClick:()=>ie&&G({type:"statement",id:D.id}),onDragStart:()=>Fe(D.id),onDragEnd:()=>{Fe(null),be(null)},onDrop:()=>{Le&&Le!==D.id&&je(D.id,"statement",Le,"entry")},disabled:$||b||!xe},D.id))})]}),e.jsxs("div",{className:"nice-reconciliation__panel nice-reconciliation__panel--entries",children:[e.jsx("div",{className:"nice-reconciliation__panel-header",children:e.jsxs("span",{className:"nice-reconciliation__panel-title",children:["📒 ",re.entryPanelTitle??"Book Entries",e.jsx("span",{className:"nice-reconciliation__panel-badge",children:qe.length})]})}),e.jsx("div",{ref:de,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:qe.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:"📚"}),re.noEntries??"No book entries"]}):qe.map(D=>e.jsx(ya,{item:{...D,status:We.has(D.id)?"matched":"unmatched"},isSelected:$e.has(D.id),isDragging:Le===D.id,isDropTarget:H===D.id,currency:pe,locale:ve,onSelect:()=>{$||Qe(oe=>{const me=new Set(oe);return me.has(D.id)?me.delete(D.id):me.add(D.id),me})},onDoubleClick:()=>ie&&G({type:"entry",id:D.id}),onDragStart:()=>Fe(D.id),onDragEnd:()=>{Fe(null),be(null)},onDrop:()=>{Le&&Le!==D.id&&je(D.id,"entry",Le,"statement")},disabled:$||b||!xe},D.id))})]})]}),A&&e.jsxs("div",{className:"nice-reconciliation__summary",children:[e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:"Matched:"}),e.jsxs("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--success",children:[Ke.matchedStatements,"/",Ke.totalStatements," (",Ke.matchPercentage,"%)"]})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:"Matched Amount:"}),e.jsx("span",{className:"nice-reconciliation__summary-value",children:In(Ke.matchedAmount,pe,ve)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:"Unmatched:"}),e.jsx("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--warning",children:In(Ke.unmatchedStatementAmount,pe,ve)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:"Difference:"}),e.jsx("span",{className:`nice-reconciliation__summary-value ${Math.abs(Ke.difference)<.01?"nice-reconciliation__summary-value--success":"nice-reconciliation__summary-value--danger"}`,children:In(Ke.difference,pe,ve)})]})]}),ie&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`nice-reconciliation__detail-backdrop ${ce?"nice-reconciliation__detail-backdrop--visible":""}`,onClick:()=>G(null)}),e.jsx("div",{className:`nice-reconciliation__detail-panel ${ce?"nice-reconciliation__detail-panel--open":""}`,children:ce&&e.jsx(va,{type:ce.type,id:ce.id,statements:B,entries:J,matches:_e,currency:pe,locale:ve,labels:re,onClose:()=>G(null)})})]})]})});function va({type:n,id:a,statements:r,entries:l,matches:d,currency:m,locale:f,labels:o,onClose:g}){var V;const N=n==="statement"?r.find(y=>y.id===a):l.find(y=>y.id===a),S=n==="statement"?d.find(y=>y.statementIds.includes(a)):d.find(y=>y.entryIds.includes(a)),K=S?n==="statement"?l.filter(y=>S.entryIds.includes(y.id)):r.filter(y=>S.statementIds.includes(y.id)):[];if(!N)return null;const I=n==="statement",T=I?N:null,P=I?null:N;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-reconciliation__detail-header",children:[e.jsxs("span",{className:"nice-reconciliation__detail-title",children:[I?"📄":"📒"," ",I?o.statementDetails??"Transaction Details":o.entryDetails??"Entry Details"]}),e.jsx("button",{type:"button",className:"nice-reconciliation__detail-close",onClick:g,"aria-label":"Close",children:"✕"})]}),e.jsxs("div",{className:"nice-reconciliation__detail-content",children:[S&&e.jsxs("div",{className:"nice-reconciliation__detail-match-info",children:[e.jsxs("div",{className:"nice-reconciliation__detail-match-header",children:["✓ ",o.matchedWith??"Matched"," (",((V=S.confidence)==null?void 0:V.toFixed(0))??100,"% confidence)"]}),e.jsx("div",{className:"nice-reconciliation__detail-match-detail",children:S.matchedBy==="ai"?o.matchedByAI??"Matched automatically by AI":o.matchedManually??"Matched manually"}),e.jsxs("div",{className:"nice-reconciliation__detail-side-by-side",children:[e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:o.statementTotal??"Statement"}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${S.statementTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:In(S.statementTotal,m,f)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:o.entryTotal??"Book Entry"}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${S.entryTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:In(S.entryTotal,m,f)})]})]}),S.difference>.01&&e.jsxs("div",{className:"nice-reconciliation__detail-row",style:{marginTop:"0.5rem",borderBottom:"none"},children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.difference??"Difference",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{color:"var(--nice-warning, #f59e0b)"},children:In(S.difference,m,f)})]})]}),e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:["📋"," ",I?o.transactionInfo??"Transaction Information":o.entryInfo??"Entry Information"]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.date??"Date",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:Nt(N.date,f)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.description??"Description",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:N.description})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.amount??"Amount",":"]}),e.jsx("span",{className:`nice-reconciliation__detail-value ${N.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:In(N.amount,m,f)})]}),I&&(T==null?void 0:T.counterparty)&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.counterparty??"Counterparty",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:T.counterparty})]}),I&&(T==null?void 0:T.counterpartyAccount)&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.accountNumber??"Account",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:T.counterpartyAccount})]}),!I&&(P==null?void 0:P.partyName)&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.party??"Party",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:P.partyName})]}),!I&&(P==null?void 0:P.documentNumber)&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.documentRef??"Document Ref",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:P.documentNumber})]}),I&&(T==null?void 0:T.referenceNumber)&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.reference??"Reference",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:T.referenceNumber})]})]}),K.length>0&&e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:["🔗"," ",I?o.matchedEntries??"Matched Entries":o.matchedStatements??"Matched Statements"]}),K.map(y=>e.jsxs("div",{style:{padding:"0.5rem",background:"var(--nice-bg-secondary, #f9fafb)",borderRadius:"0.25rem",marginBottom:"0.5rem",fontSize:"0.8125rem"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.25rem"},children:y.description}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:"var(--nice-text-secondary)"},children:[e.jsx("span",{children:Nt(y.date,f)}),e.jsx("span",{style:{fontWeight:600,color:y.amount>=0?"var(--nice-success)":"var(--nice-danger)"},children:In(y.amount,m,f)})]})]},y.id))]})]})]})}function ja(n,a,r){const l=new Map,d=[];n.forEach(f=>l.set(String(f[a]),{data:f,children:[],key:String(f[a]),depth:0})),n.forEach(f=>{const o=f[r],g=l.get(String(f[a]));if(o!=null&&o!==""&&l.has(String(o))){const N=l.get(String(o));g.depth=N.depth+1,N.children.push(g)}else d.push(g)});const m=(f,o)=>{f.forEach(g=>{g.depth=o,m(g.children,o+1)})};return m(d,0),d}function bi(n,a,r,l=0){return n.map(d=>({data:d,key:String(d[r]),depth:l,children:Array.isArray(d[a])?bi(d[a],a,r,l+1):[]}))}function wa(n){const a=[],r=l=>{l.forEach(d=>{a.push(d.key),r(d.children)})};return r(n),a}function ka(n,a){const r=[],l=d=>{d.forEach(m=>{r.push(m),m.children.length>0&&a.has(m.key)&&l(m.children)})};return l(n),r}function _i(n,a,r){return!a||!r?n:[...n].sort((l,d)=>{const m=l.data[a]??"",f=d.data[a]??"",o=typeof m=="number"&&typeof f=="number"?m-f:String(m).localeCompare(String(f));return r==="desc"?-o:o}).map(l=>({...l,children:_i(l.children,a,r)}))}function yi({columns:n,data:a,keyField:r="id",parentKeyField:l="parentId",nested:d=!1,childrenField:m="children",expandedKeys:f,onExpandedChange:o,defaultExpandAll:g=!1,sortable:N=!0,sortField:S,sortDirection:K,onSort:I,selectable:T,selectedKeys:P,onSelectionChange:V,searchable:y,searchPlaceholder:s,striped:w,compact:c,loading:R,emptyText:F,toolbar:q,onRowClick:ue,className:Ae,style:A}){const{t:he}=we.de(),ye=t.useMemo(()=>d?bi(a,m,r):ja(a,r,l),[a,r,l,d,m]),xe=t.useMemo(()=>wa(ye),[ye]),[Q,ie]=t.useState(()=>g?new Set(xe):new Set),M=f?new Set(f):Q,[$,b]=t.useState({field:"",dir:null}),[ve,re]=t.useState(new Set),[W,ee]=t.useState(""),B=S??$.field,J=K??$.dir,pe=P??ve,ge=t.useMemo(()=>n.filter(H=>!H.hidden),[n]),Te=t.useCallback(H=>{const be=B===H?J==="asc"?"desc":J==="desc"?null:"asc":"asc";I?I(H,be):b({field:H,dir:be})},[B,J,I]),Ze=t.useCallback(H=>{const be=new Set(M);be.has(H)?be.delete(H):be.add(H),o?o([...be]):ie(be)},[M,o]),en=t.useCallback(H=>{const be=new Set(pe);be.has(H)?be.delete(H):be.add(H),V?V(be):re(be)},[pe,V]),$e=t.useMemo(()=>{if(!W)return ye;const H=W.toLowerCase(),be=De=>De.reduce((z,ce)=>{const G=be(ce.children);return(ge.some(_e=>String(ce.data[_e.field]??"").toLowerCase().includes(H))||G.length>0)&&z.push({...ce,children:G}),z},[]);return be(ye)},[ye,W,ge]),Qe=t.useMemo(()=>_i($e,B,J),[$e,B,J]),Le=t.useMemo(()=>ka(Qe,M),[Qe,M]),Fe=({field:H})=>B!==H||!J?e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:.3},children:"↕"}):e.jsx("span",{className:"nice-table__sort-icon",children:J==="asc"?"↑":"↓"});return e.jsxs("div",{className:`nice-treegrid nice-datagrid ${Ae||""}`,style:A,children:[(y||q)&&e.jsxs("div",{className:"nice-datagrid__toolbar",children:[y&&e.jsx("div",{className:"nice-datagrid__search",children:e.jsx("input",{type:"text",value:W,onChange:H=>ee(H.target.value),placeholder:s||he("controls.search","Search...")})}),q]}),e.jsx("div",{className:"nice-datagrid__table-wrap",children:e.jsxs("table",{className:`${w?"nice-table--striped":""} ${c?"nice-table--compact":""}`,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[T&&e.jsx("th",{className:"nice-datagrid__checkbox",style:{width:36}}),ge.map(H=>e.jsxs("th",{style:{width:H.width,minWidth:H.minWidth,textAlign:H.align},className:N&&H.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>N&&H.sortable!==!1&&Te(H.field),children:[H.header,N&&H.sortable!==!1&&e.jsx(Fe,{field:H.field})]},H.field))]})}),e.jsx("tbody",{children:R?e.jsx("tr",{children:e.jsx("td",{colSpan:ge.length+(T?1:0),className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):Le.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:ge.length+(T?1:0),className:"nice-datagrid__empty",children:F||he("controls.noData","No data available")})}):Le.map((H,be)=>{const De=pe.has(H.key),z=H.children.length>0,ce=M.has(H.key);return e.jsxs("tr",{className:De?"nice-datagrid__row--selected":void 0,onClick:()=>ue==null?void 0:ue(H.data),style:ue?{cursor:"pointer"}:void 0,children:[T&&e.jsx("td",{className:"nice-datagrid__checkbox",onClick:G=>G.stopPropagation(),children:e.jsx("input",{type:"checkbox",checked:De,onChange:()=>en(H.key),"aria-label":`Select row ${H.key}`})}),ge.map((G,_e)=>e.jsxs("td",{style:{textAlign:G.align},children:[_e===0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{display:"inline-block",width:H.depth*20}}),e.jsx("button",{className:`nice-treegrid__toggle ${z?"":"nice-treegrid__toggle--leaf"}`,onClick:E=>{E.stopPropagation(),z&&Ze(H.key)},tabIndex:z?0:-1,"aria-expanded":z?ce:void 0,"aria-label":z?ce?"Collapse":"Expand":void 0,children:z?ce?"▾":"▸":""})]}),G.render?G.render(H.data[G.field],H.data,be):String(H.data[G.field]??"")]},G.field))]},H.key)})})]})})]})}const bn={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},Na=()=>e.jsxs("svg",{...bn,children:[e.jsx("path",{d:"M3 7v6h6"}),e.jsx("path",{d:"M21 17a9 9 0 0 0-15-6.7L3 13"})]}),Ca=()=>e.jsxs("svg",{...bn,children:[e.jsx("path",{d:"M21 7v6h-6"}),e.jsx("path",{d:"M3 17a9 9 0 0 1 15-6.7L21 13"})]}),Sa=()=>e.jsxs("svg",{...bn,children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"15",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"18",y2:"18"})]}),Ma=()=>e.jsxs("svg",{...bn,children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),e.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),Aa=()=>e.jsxs("svg",{...bn,children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"6",y1:"18",x2:"21",y2:"18"})]}),Da=()=>e.jsxs("svg",{...bn,children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"6",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"18",height:"6",rx:"1"}),e.jsx("line",{x1:"12",y1:"11",x2:"12",y2:"13"})]}),Ia=()=>e.jsxs("svg",{...bn,children:[e.jsx("rect",{x:"4",y:"3",width:"6",height:"18",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"6",height:"18",rx:"1"}),e.jsx("line",{x1:"11",y1:"12",x2:"13",y2:"12"})]}),Ra=()=>e.jsxs("svg",{...bn,children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"6",rx:"1"}),e.jsx("line",{x1:"6",y1:"17",x2:"18",y2:"17"})]}),za=()=>e.jsxs("svg",{...bn,children:[e.jsx("rect",{x:"4",y:"3",width:"6",height:"18",rx:"1"}),e.jsx("line",{x1:"14",y1:"12",x2:"20",y2:"12"})]}),La=()=>e.jsx("svg",{...bn,children:e.jsx("polyline",{points:"6 9 12 4 18 9"})}),Ea=()=>e.jsx("svg",{...bn,children:e.jsx("polyline",{points:"6 15 12 20 18 15"})}),Ta=()=>e.jsxs("svg",{...bn,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 9 12 4 18 9"}),e.jsx("polyline",{points:"6 15 12 20 18 15"})]}),$a=()=>e.jsxs("svg",{...bn,children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),Fa=()=>e.jsxs("svg",{...bn,children:[e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),e.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"})]});function vi(n){let a="",r=n;for(;r>=0;)a=String.fromCharCode(65+r%26)+a,r=Math.floor(r/26)-1;return a}function Ie(n,a){return`${vi(a)}${n+1}`}function ln(n){const a=n.match(/^([A-Z]+)(\d+)$/);if(!a)return null;let r=0;for(let l=0;l<a[1].length;l++)r=r*26+(a[1].charCodeAt(l)-64);return{row:parseInt(a[2],10)-1,col:r-1}}function Oa(n,a,r=new Set){const l=n.startsWith("=")?n.slice(1).trim():n,d=(y,s)=>{if(!y||!s)return[];const w=[];for(let c=y.row;c<=s.row;c++)for(let R=y.col;R<=s.col;R++){const F=an(Ie(c,R),a,new Set(r));typeof F=="number"&&w.push(F)}return w},m=(y,s)=>{if(!y||!s)return[];const w=[];for(let c=y.row;c<=s.row;c++)for(let R=y.col;R<=s.col;R++)w.push(an(Ie(c,R),a,new Set(r)));return w},f=l.match(/^(\w+)\(([A-Z]+\d+):([A-Z]+\d+)\)$/i);if(f){const y=f[1].toUpperCase(),s=ln(f[2].toUpperCase()),w=ln(f[3].toUpperCase());switch(y){case"SUM":return d(s,w).reduce((c,R)=>c+R,0);case"AVG":case"AVERAGE":{const c=d(s,w);return c.length>0?c.reduce((R,F)=>R+F,0)/c.length:0}case"COUNT":return d(s,w).length;case"COUNTA":return m(s,w).filter(c=>c!==null&&c!=="").length;case"COUNTBLANK":return m(s,w).filter(c=>c===null||c==="").length;case"MIN":{const c=d(s,w);return c.length?Math.min(...c):0}case"MAX":{const c=d(s,w);return c.length?Math.max(...c):0}case"MEDIAN":{const c=d(s,w).sort((F,q)=>F-q);if(!c.length)return 0;const R=Math.floor(c.length/2);return c.length%2?c[R]:(c[R-1]+c[R])/2}case"STDEV":{const c=d(s,w);if(c.length<2)return 0;const R=c.reduce((F,q)=>F+q,0)/c.length;return Math.sqrt(c.reduce((F,q)=>F+(q-R)**2,0)/(c.length-1))}case"PRODUCT":{const c=d(s,w);return c.length?c.reduce((R,F)=>R*F,1):0}}}const o=l.match(/^(SUMIF|COUNTIF)\(([A-Z]+\d+):([A-Z]+\d+)\s*,\s*"?([^"]*)"?\)$/i);if(o){const y=o[1].toUpperCase(),s=ln(o[2].toUpperCase()),w=ln(o[3].toUpperCase()),c=o[4];if(s&&w){let R=0;for(let F=s.row;F<=w.row;F++)for(let q=s.col;q<=w.col;q++){const ue=an(Ie(F,q),a,new Set(r));(c.startsWith(">")?Number(ue)>Number(c.slice(1)):c.startsWith("<")?Number(ue)<Number(c.slice(1)):String(ue)===c||typeof ue=="number"&&ue===Number(c))&&(R+=y==="SUMIF"?typeof ue=="number"?ue:0:1)}return R}}const g=l.match(/^IF\(([^,]+),\s*([^,]+),\s*([^)]+)\)$/i);if(g){const y=g[1].trim(),s=g[2].trim(),w=g[3].trim(),c=y.match(/^([A-Z]+\d+)\s*([><=!]+)\s*(\S+)$/i);let R=!1;if(c){const ue=an(c[1].toUpperCase(),a,new Set(r)),Ae=isNaN(Number(c[3]))?c[3].replace(/^"|"$/g,""):Number(c[3]),A=c[2],he=typeof ue=="number"?ue:Number(ue)||0,ye=typeof Ae=="number"?Ae:Number(Ae)||0;switch(A){case">":R=he>ye;break;case"<":R=he<ye;break;case">=":R=he>=ye;break;case"<=":R=he<=ye;break;case"=":case"==":R=he===ye;break;case"<>":case"!=":R=he!==ye;break}}const F=R?s:w;if(ln(F.toUpperCase()))return an(F.toUpperCase(),a,new Set(r));const q=Number(F);return isNaN(q)?F.replace(/^"|"$/g,""):q}const N=l.match(/^CONCAT\((.+)\)$/i);if(N)return N[1].split(",").map(y=>y.trim()).map(y=>{if(y.startsWith('"')&&y.endsWith('"'))return y.slice(1,-1);if(ln(y.toUpperCase())){const s=an(y.toUpperCase(),a,new Set(r));return s!==null?String(s):""}return y}).join("");const S=l.match(/^VLOOKUP\(([^,]+),\s*([A-Z]+\d+):([A-Z]+\d+),\s*(\d+)\)$/i);if(S){let y;ln(S[1].trim().toUpperCase())?y=an(S[1].trim().toUpperCase(),a,new Set(r)):y=isNaN(Number(S[1]))?S[1].replace(/^"|"$/g,""):Number(S[1]);const s=ln(S[2].toUpperCase()),w=ln(S[3].toUpperCase()),c=parseInt(S[4])-1;if(s&&w)for(let R=s.row;R<=w.row;R++){const F=an(Ie(R,s.col),a,new Set(r));if(String(F)===String(y))return an(Ie(R,s.col+c),a,new Set(r))}return null}const K=l.match(/^(ABS|ROUND|FLOOR|CEIL|CEILING|SQRT|LEN|UPPER|LOWER|TRIM|INT)\(([^)]+)\)$/i);if(K){const y=K[1].toUpperCase(),s=K[2].trim();let w;switch(ln(s.toUpperCase())?w=an(s.toUpperCase(),a,new Set(r)):w=isNaN(Number(s))?s.replace(/^"|"$/g,""):Number(s),y){case"ABS":return Math.abs(Number(w)||0);case"ROUND":return Math.round(Number(w)||0);case"FLOOR":return Math.floor(Number(w)||0);case"CEIL":case"CEILING":return Math.ceil(Number(w)||0);case"SQRT":return Math.sqrt(Number(w)||0);case"INT":return Math.trunc(Number(w)||0);case"LEN":return String(w??"").length;case"UPPER":return String(w??"").toUpperCase();case"LOWER":return String(w??"").toLowerCase();case"TRIM":return String(w??"").trim()}}const I=l.match(/^POWER\(([^,]+),\s*([^)]+)\)$/i);if(I){const y=Number(ln(I[1].trim().toUpperCase())?an(I[1].trim().toUpperCase(),a,new Set(r)):I[1].trim())||0,s=Number(ln(I[2].trim().toUpperCase())?an(I[2].trim().toUpperCase(),a,new Set(r)):I[2].trim())||0;return Math.pow(y,s)}if(/^NOW\(\)$/i.test(l))return new Date().toISOString();if(/^TODAY\(\)$/i.test(l))return new Date().toISOString().split("T")[0];if(/^PI\(\)$/i.test(l))return Math.PI;const T=l.match(/^([A-Z]+\d+)$/i);if(T)return an(T[1].toUpperCase(),a,r);const P=l.match(/^([A-Z]+\d+)\s*([+\-*/])\s*([A-Z]+\d+|\d+\.?\d*)$/i);if(P){const y=P[1].toUpperCase(),s=P[2],w=P[3],c=an(y,a,r),R=ln(w.toUpperCase())?an(w.toUpperCase(),a,r):parseFloat(w),F=typeof c=="number"?c:0,q=typeof R=="number"?R:0;switch(s){case"+":return F+q;case"-":return F-q;case"*":return F*q;case"/":return q!==0?F/q:null}}const V=parseFloat(l);return isNaN(V)?l:V}function an(n,a,r){if(r.has(n))return null;r.add(n);const l=a[n];return l?l.formula?Oa(l.formula,a,r):l.value:null}function si(n,a){return n==null?"":a==="percent"&&typeof n=="number"?`${(n*100).toFixed(1)}%`:a==="currency"&&typeof n=="number"?`$${n.toFixed(2)}`:String(n)}function ci(n){return{name:n,data:{}}}const Pt=t.forwardRef(({sheets:n,activeSheet:a,rows:r=50,cols:l=26,showToolbar:d=!0,showFormulaBar:m=!0,showSheetTabs:f=!0,readOnly:o=!1,onChange:g,onActiveSheetChange:N,onCellSelect:S,onCopy:K,onPaste:I,onInsert:T,onRemove:P,maxUndo:V=50,sortable:y=!1,filterable:s=!1,rangeSelection:w=!0,className:c,style:R,id:F,...q},ue)=>{var Ln,Kn,Fn,Gn,Xn;const Ae=we.dl(F),{t:A}=we.de(),[he,ye]=t.useState(()=>n??[ci(A("spreadsheet.sheet","Sheet")+" 1")]),[xe,Q]=t.useState(0),ie=n??he,M=a??xe,$=ie[M]??ie[0],[b,ve]=t.useState(null),[re,W]=t.useState(null),[ee,B]=t.useState(!1),[J,pe]=t.useState(null),[ge,Te]=t.useState(""),Ze=t.useRef(null),en=t.useRef(null),[$e,Qe]=t.useState([]),[Le,Fe]=t.useState([]),[H,be]=t.useState(null),De=t.useRef({x:0,width:80}),[z,ce]=t.useState(null),[G,_e]=t.useState(null),[E,de]=t.useState("");t.useEffect(()=>{J&&Ze.current&&Ze.current.focus()},[J]);const O=t.useMemo(()=>{if(!b)return null;const u=re??b;return{startRow:Math.min(b.row,u.row),startCol:Math.min(b.col,u.col),endRow:Math.max(b.row,u.row),endCol:Math.max(b.col,u.col)}},[b,re]),We=t.useCallback((u,h)=>O?u>=O.startRow&&u<=O.endRow&&h>=O.startCol&&h<=O.endCol:!1,[O]),Ke=t.useCallback(u=>{Qe(h=>{const v=[...h,u.map(U=>({...U,data:{...U.data}}))];return v.length>V?v.slice(-V):v}),Fe([])},[V]),ne=t.useCallback((u,h=!0)=>{h&&Ke(ie);const v=u(ie);n||ye(v),g==null||g(v)},[ie,n,g,Ke]),Ge=t.useCallback(()=>{if($e.length===0)return;const u=$e[$e.length-1];Fe(h=>[...h,ie.map(v=>({...v,data:{...v.data}}))]),Qe(h=>h.slice(0,-1)),n||ye(u),g==null||g(u)},[$e,ie,n,g]),gn=t.useCallback(()=>{if(Le.length===0)return;const u=Le[Le.length-1];Qe(h=>[...h,ie.map(v=>({...v,data:{...v.data}}))]),Fe(h=>h.slice(0,-1)),n||ye(u),g==null||g(u)},[Le,ie,n,g]),je=t.useCallback(u=>{a||Q(u),N==null||N(u),ve(null),W(null),pe(null)},[a,N]),Nn=t.useCallback((u,h,v)=>{const U=Ie(u,h);ne(Y=>{const k=Y.map((X,Ee)=>Ee===M?{...X,data:{...X.data}}:X),L=v.startsWith("=");return k[M].data[U]={...k[M].data[U]??{value:null},formula:L?v:void 0,value:L?null:isNaN(Number(v))?v:Number(v)},k})},[M,ne]),Cn=t.useCallback((u,h,v)=>{v!=null&&v.shiftKey&&w&&b?W({row:u,col:h}):(ve({row:u,col:h}),W(null)),pe(null),S==null||S(M,u,h)},[M,S,w,b]),qe=t.useCallback((u,h,v)=>{v.button===0&&(Cn(u,h,v),w&&!v.shiftKey&&B(!0))},[Cn,w]),zn=t.useCallback((u,h)=>{ee&&W({row:u,col:h})},[ee]);t.useEffect(()=>{if(!ee)return;const u=()=>B(!1);return document.addEventListener("mouseup",u),()=>document.removeEventListener("mouseup",u)},[ee]);const D=t.useCallback((u,h)=>{if(o)return;const v=Ie(u,h),U=$.data[v];U!=null&&U.readOnly||(pe({row:u,col:h}),Te((U==null?void 0:U.formula)??((U==null?void 0:U.value)!=null?String(U.value):"")))},[o,$.data]),oe=t.useCallback(()=>{J&&(Nn(J.row,J.col,ge),pe(null))},[J,ge,Nn]),me=t.useCallback(u=>{if(u.key==="Enter")oe();else if(u.key==="Escape")pe(null);else if(u.key==="Tab"&&(u.preventDefault(),oe(),b)){const h=u.shiftKey?Math.max(0,b.col-1):Math.min(l-1,b.col+1);ve({row:b.row,col:h})}},[oe,b,l]),ke=t.useCallback((u,h)=>{if(!b)return;const v=O??{startRow:b.row,startCol:b.col,endRow:b.row,endCol:b.col};ne(U=>{const Y=U.map((k,L)=>L===M?{...k,data:{...k.data}}:k);for(let k=v.startRow;k<=v.endRow;k++)for(let L=v.startCol;L<=v.endCol;L++){const X=Ie(k,L);Y[M].data[X]={...Y[M].data[X]??{value:null},[u]:h}}return Y})},[b,O,M,ne]),mn=t.useCallback(u=>{if(!O||(K==null?void 0:K(O))===!1)return;const{startRow:h,startCol:v,endRow:U,endCol:Y}=O,k=[];for(let L=h;L<=U;L++){const X=[];for(let Ee=v;Ee<=Y;Ee++){const ze=Ie(L,Ee),ae=$.data[ze],He=ae?an(ze,$.data,new Set):null;X.push(si(He,ae==null?void 0:ae.format))}k.push(X.join(" "))}u.clipboardData.setData("text/plain",k.join(`
595
+ `)),u.preventDefault()},[O,$.data,K]),Ce=t.useCallback(u=>{if(o||!b)return;const h=u.clipboardData.getData("text/plain");if(!h)return;const v=h.split(`
596
+ `).map(U=>U.split(" "));(I==null?void 0:I(v,b.row,b.col))!==!1&&(ne(U=>{const Y=U.map((k,L)=>L===M?{...k,data:{...k.data}}:k);return v.forEach((k,L)=>{k.forEach((X,Ee)=>{const ze=Ie(b.row+L,b.col+Ee),ae=X.startsWith("=");Y[M].data[ze]={...Y[M].data[ze]??{value:null},formula:ae?X:void 0,value:ae?null:isNaN(Number(X))?X:Number(X)}})}),Y}),u.preventDefault())},[o,b,M,ne,I]),Be=t.useCallback(u=>{ne(h=>h.map((v,U)=>{if(U!==M)return v;const Y={};for(const[k,L]of Object.entries(v.data)){const X=ln(k);X&&(X.row>u?Y[Ie(X.row+1,X.col)]=L:Y[k]=L)}return{...v,data:Y}})),T==null||T("row",u)},[M,ne,T]),hn=t.useCallback(u=>{ne(h=>h.map((v,U)=>{if(U!==M)return v;const Y={};for(const[k,L]of Object.entries(v.data)){const X=ln(k);X&&(X.col>u?Y[Ie(X.row,X.col+1)]=L:Y[k]=L)}return{...v,data:Y}})),T==null||T("column",u)},[M,ne,T]),Ve=t.useCallback(u=>{ne(h=>h.map((v,U)=>{if(U!==M)return v;const Y={};for(const[k,L]of Object.entries(v.data)){const X=ln(k);X&&X.row!==u&&(X.row>u?Y[Ie(X.row-1,X.col)]=L:Y[k]=L)}return{...v,data:Y}})),P==null||P("row",u)},[M,ne,P]),rn=t.useCallback(u=>{ne(h=>h.map((v,U)=>{if(U!==M)return v;const Y={};for(const[k,L]of Object.entries(v.data)){const X=ln(k);X&&X.col!==u&&(X.col>u?Y[Ie(X.row,X.col-1)]=L:Y[k]=L)}return{...v,data:Y}})),P==null||P("column",u)},[M,ne,P]),Sn=t.useCallback((u,h)=>{ne(v=>v.map((U,Y)=>{if(Y!==M)return U;const k=new Map;for(const[Ee,ze]of Object.entries(U.data)){const ae=ln(Ee);ae&&(k.has(ae.row)||k.set(ae.row,{}),k.get(ae.row)[ae.col]=ze)}const L=Array.from(k.entries()).sort((Ee,ze)=>{const ae=an(Ie(Ee[0],u),U.data,new Set),He=an(Ie(ze[0],u),U.data,new Set),sn=typeof ae=="number"?ae:Number(ae),fn=typeof He=="number"?He:Number(He);if(!isNaN(sn)&&!isNaN(fn))return h==="asc"?sn-fn:fn-sn;const cn=String(ae??""),xn=String(He??"");return h==="asc"?cn.localeCompare(xn):xn.localeCompare(cn)}),X={};return L.forEach(([,Ee],ze)=>{for(const[ae,He]of Object.entries(Ee))X[Ie(ze,Number(ae))]=He}),{...U,data:X,sortColumn:u,sortDirection:h}}))},[M,ne]),Jn=t.useCallback((u,h)=>{const v=$.conditionalFormats;if(!(v!=null&&v.length))return;const U=Ie(u,h),Y=an(U,$.data,new Set),k=typeof Y=="number"?Y:Number(Y);for(const L of v){const X=L.range.match(/^([A-Z]+\d+):([A-Z]+\d+)$/i);if(!X)continue;const Ee=ln(X[1].toUpperCase()),ze=ln(X[2].toUpperCase());if(!Ee||!ze||u<Ee.row||u>ze.row||h<Ee.col||h>ze.col)continue;let ae=!1;switch(L.type){case"greaterThan":ae=!isNaN(k)&&k>Number(L.value);break;case"lessThan":ae=!isNaN(k)&&k<Number(L.value);break;case"equalTo":ae=String(Y)===String(L.value);break;case"between":ae=!isNaN(k)&&k>=Number(L.value)&&k<=Number(L.value2);break;case"textContains":ae=String(Y).includes(String(L.value));break;case"isEmpty":ae=Y===null||Y==="";break;case"isNotEmpty":ae=Y!==null&&Y!=="";break}if(ae)return{backgroundColor:L.style.bgColor,color:L.style.color,fontWeight:L.style.bold?"bold":void 0,fontStyle:L.style.italic?"italic":void 0}}},[$.conditionalFormats,$.data]),Zn=t.useCallback(()=>{const u=`${A("spreadsheet.sheet","Sheet")} ${ie.length+1}`;ne(h=>[...h,ci(u)]),je(ie.length)},[ie.length,ne,je,A]),nt=t.useCallback(()=>{ie.length<=1||(ne(u=>u.filter((h,v)=>v!==M)),je(Math.max(0,M-1)))},[ie.length,M,ne,je]),Hn=t.useCallback((u,h)=>{h.trim()&&(ne(v=>v.map((U,Y)=>Y===u?{...U,name:h.trim()}:U),!1),_e(null))},[ne]),Yn=t.useMemo(()=>{if(!b)return"";const u=Ie(b.row,b.col),h=$.data[u];return(h==null?void 0:h.formula)??((h==null?void 0:h.value)!=null?String(h.value):"")},[b,$.data]),pn=t.useMemo(()=>{if(!O)return null;const{startRow:u,startCol:h,endRow:v,endCol:U}=O;if(u===v&&h===U)return null;const Y=[];let k=0;for(let L=u;L<=v;L++)for(let X=h;X<=U;X++){const Ee=Ie(L,X),ze=an(Ee,$.data,new Set);ze!==null&&ze!==""&&k++,typeof ze=="number"&&Y.push(ze)}return Y.length===0?{count:k}:{count:k,sum:Y.reduce((L,X)=>L+X,0),avg:Y.reduce((L,X)=>L+X,0)/Y.length,min:Math.min(...Y),max:Math.max(...Y)}},[O,$.data]),ht=t.useCallback((u,h)=>{var v;h.preventDefault(),h.stopPropagation(),be(u),De.current={x:h.clientX,width:((v=$.colWidths)==null?void 0:v[u])??80}},[$.colWidths]);t.useEffect(()=>{if(H===null)return;const u=v=>{const U=v.clientX-De.current.x,Y=Math.max(30,De.current.width+U);ne(k=>k.map((L,X)=>X===M?{...L,colWidths:{...L.colWidths,[H]:Y}}:L),!1)},h=()=>be(null);return document.addEventListener("mousemove",u),document.addEventListener("mouseup",h),()=>{document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",h)}},[H,M,ne]);const tt=t.useCallback((u,h,v)=>{u.preventDefault(),ve({row:h,col:v}),ce({x:u.clientX,y:u.clientY})},[]);t.useEffect(()=>{if(!z)return;const u=()=>ce(null);return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[z]);const Oe=t.useCallback(u=>{if((u.ctrlKey||u.metaKey)&&!J){if(u.key==="z"){u.preventDefault(),Ge();return}if(u.key==="y"){u.preventDefault(),gn();return}}if(J||!b)return;let{row:h,col:v}=b;switch(u.key){case"ArrowUp":h=Math.max(0,h-1);break;case"ArrowDown":h=Math.min(r-1,h+1);break;case"ArrowLeft":v=Math.max(0,v-1);break;case"ArrowRight":v=Math.min(l-1,v+1);break;case"Enter":D(h,v);return;case"Delete":case"Backspace":o||(O&&(O.startRow!==O.endRow||O.startCol!==O.endCol)?ne(U=>{const Y=U.map((k,L)=>L===M?{...k,data:{...k.data}}:k);for(let k=O.startRow;k<=O.endRow;k++)for(let L=O.startCol;L<=O.endCol;L++)delete Y[M].data[Ie(k,L)];return Y}):Nn(h,v,""));return;default:if(u.key.length===1&&!u.ctrlKey&&!u.metaKey&&!o){pe({row:h,col:v}),Te(u.key);return}return}u.preventDefault(),u.shiftKey&&w?W({row:h,col:v}):(ve({row:h,col:v}),W(null)),S==null||S(M,h,v)},[J,b,r,l,o,D,Nn,M,S,Ge,gn,O,ne,w]),nn=$.frozenRows??0,Pe=$.frozenCols??0,Un=[{value:"text",label:A("spreadsheet.formatText","Text")},{value:"number",label:A("spreadsheet.formatNumber","Number")},{value:"percent",label:A("spreadsheet.formatPercent","Percent")},{value:"currency",label:A("spreadsheet.formatCurrency","Currency")},{value:"date",label:A("spreadsheet.formatDate","Date")}];return e.jsxs("div",{ref:ue,id:Ae,className:`nice-spreadsheet ${o?"nice-spreadsheet--readonly":""} ${c??""}`,style:R,onKeyDown:Oe,onCopy:mn,onPaste:Ce,tabIndex:0,role:"application","aria-label":A("spreadsheet.label","Spreadsheet"),...q,children:[d&&!o&&e.jsxs("div",{className:"nice-spreadsheet__toolbar",role:"toolbar",children:[e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:Ge,disabled:$e.length===0,title:A("spreadsheet.undo","Undo"),children:e.jsx(Na,{})}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:gn,disabled:Le.length===0,title:A("spreadsheet.redo","Redo"),children:e.jsx(Ca,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Re.pn,{variant:(Ln=$.data[b?Ie(b.row,b.col):""])!=null&&Ln.bold?"primary":"ghost",size:"sm",onClick:()=>{var u;return ke("bold",!((u=$.data[b?Ie(b.row,b.col):""])!=null&&u.bold))},title:A("spreadsheet.bold","Bold"),children:e.jsx("strong",{children:"B"})}),e.jsx(Re.pn,{variant:(Kn=$.data[b?Ie(b.row,b.col):""])!=null&&Kn.italic?"primary":"ghost",size:"sm",onClick:()=>{var u;return ke("italic",!((u=$.data[b?Ie(b.row,b.col):""])!=null&&u.italic))},title:A("spreadsheet.italic","Italic"),children:e.jsx("em",{children:"I"})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>ke("align","left"),title:A("spreadsheet.alignLeft","Align left"),children:e.jsx(Sa,{})}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>ke("align","center"),title:A("spreadsheet.alignCenter","Center"),children:e.jsx(Ma,{})}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>ke("align","right"),title:A("spreadsheet.alignRight","Align right"),children:e.jsx(Aa,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Re.Xe,{value:((Fn=$.data[b?Ie(b.row,b.col):""])==null?void 0:Fn.bgColor)??"var(--bg-primary, #ffffff)",onChange:u=>ke("bgColor",u),title:A("spreadsheet.bgColor","Background color"),showInput:!1,showRandom:!1}),e.jsx(Re.Xe,{value:((Gn=$.data[b?Ie(b.row,b.col):""])==null?void 0:Gn.color)??"var(--text-primary, #000000)",onChange:u=>ke("color",u),title:A("spreadsheet.textColor","Text color"),showInput:!1,showRandom:!1}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Re.Ze,{size:"sm",value:((Xn=$.data[b?Ie(b.row,b.col):""])==null?void 0:Xn.format)??"text",onChange:u=>ke("format",u),options:Un,"aria-label":A("spreadsheet.format","Cell format")}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>b&&Be(b.row),title:A("spreadsheet.insertRow","Insert row"),children:e.jsx(Da,{})}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>b&&hn(b.col),title:A("spreadsheet.insertCol","Insert column"),children:e.jsx(Ia,{})}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>b&&Ve(b.row),title:A("spreadsheet.deleteRow","Delete row"),children:e.jsx(Ra,{})}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>b&&rn(b.col),title:A("spreadsheet.deleteCol","Delete column"),children:e.jsx(za,{})})]}),m&&e.jsxs("div",{className:"nice-spreadsheet__formula-bar",children:[e.jsxs("span",{className:"nice-spreadsheet__cell-label",children:[b?Ie(b.row,b.col):"",O&&O.startRow!==O.endRow||O&&O.startCol!==O.endCol?`:${Ie(O.endRow,O.endCol)}`:""]}),e.jsx(Re.Pe,{className:"nice-spreadsheet__formula-input",value:J?ge:Yn,onChange:u=>{J?Te(u):b&&(pe(b),Te(u))},onKeyDown:me,readOnly:o,"aria-label":A("spreadsheet.formulaBar","Formula bar")})]}),e.jsx("div",{className:"nice-spreadsheet__grid",ref:en,children:e.jsxs("table",{role:"grid","aria-label":$.name,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-spreadsheet__corner"}),Array.from({length:l},(u,h)=>{var v;return e.jsxs("th",{className:`nice-spreadsheet__col-header ${h<Pe?"nice-spreadsheet__col-header--frozen":""}`,style:{width:((v=$.colWidths)==null?void 0:v[h])??80,position:h<Pe?"sticky":void 0,left:h<Pe?h*80+40:void 0,zIndex:h<Pe?3:void 0},children:[e.jsx("span",{children:vi(h)}),y&&e.jsx("span",{className:"nice-spreadsheet__sort-trigger",onClick:()=>Sn(h,$.sortColumn===h&&$.sortDirection==="asc"?"desc":"asc"),title:A("spreadsheet.sort","Sort"),children:$.sortColumn===h?$.sortDirection==="asc"?e.jsx(La,{}):e.jsx(Ea,{}):e.jsx(Ta,{})}),!o&&e.jsx("span",{className:"nice-spreadsheet__col-resize",onMouseDown:U=>ht(h,U)})]},h)})]})}),e.jsx("tbody",{children:Array.from({length:r},(u,h)=>e.jsxs("tr",{className:h<nn?"nice-spreadsheet__row--frozen":"",style:h<nn?{position:"sticky",top:h*24,zIndex:2}:void 0,children:[e.jsx("td",{className:"nice-spreadsheet__row-header",children:h+1}),Array.from({length:l},(v,U)=>{var sn,fn;const Y=Ie(h,U),k=$.data[Y];if(k!=null&&k.mergedInto)return null;const L=(b==null?void 0:b.row)===h&&(b==null?void 0:b.col)===U,X=We(h,U),Ee=(J==null?void 0:J.row)===h&&(J==null?void 0:J.col)===U,ze=k?an(Y,$.data,new Set):null,ae=Jn(h,U),He=h<nn||U<Pe;return e.jsxs("td",{className:`nice-spreadsheet__cell ${L?"nice-spreadsheet__cell--selected":""} ${X&&!L?"nice-spreadsheet__cell--in-range":""} ${k!=null&&k.readOnly?"nice-spreadsheet__cell--readonly":""} ${He?"nice-spreadsheet__cell--frozen":""}`,style:{textAlign:k==null?void 0:k.align,fontWeight:k!=null&&k.bold?"bold":void 0,fontStyle:k!=null&&k.italic?"italic":void 0,backgroundColor:(ae==null?void 0:ae.backgroundColor)??(k==null?void 0:k.bgColor),color:(ae==null?void 0:ae.color)??(k==null?void 0:k.color),width:(sn=$.colWidths)==null?void 0:sn[U],height:(fn=$.rowHeights)==null?void 0:fn[h],position:He?"sticky":void 0,left:U<Pe?U*80+40:void 0,zIndex:He?1:void 0,...ae},colSpan:k==null?void 0:k.colSpan,rowSpan:k==null?void 0:k.rowSpan,onMouseDown:cn=>qe(h,U,cn),onMouseEnter:()=>zn(h,U),onDoubleClick:()=>D(h,U),onContextMenu:cn=>tt(cn,h,U),role:"gridcell","aria-selected":L,title:k==null?void 0:k.comment,children:[(k==null?void 0:k.comment)&&e.jsx("span",{className:"nice-spreadsheet__comment-indicator"}),Ee?e.jsx("input",{ref:Ze,className:"nice-spreadsheet__cell-editor",value:ge,onChange:cn=>Te(cn.target.value),onKeyDown:me,onBlur:oe}):si(ze,k==null?void 0:k.format)]},U)})]},h))})]})}),z&&!o&&b&&e.jsxs("div",{className:"nice-spreadsheet__context-menu",style:{position:"fixed",left:z.x,top:z.y,zIndex:1e3},children:[e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>{Be(b.row),ce(null)},children:A("spreadsheet.insertRowAbove","Insert row above")}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>{Be(b.row+1),ce(null)},children:A("spreadsheet.insertRowBelow","Insert row below")}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>{hn(b.col),ce(null)},children:A("spreadsheet.insertColLeft","Insert column left")}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>{hn(b.col+1),ce(null)},children:A("spreadsheet.insertColRight","Insert column right")}),e.jsx("hr",{className:"nice-spreadsheet__context-sep"}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>{Ve(b.row),ce(null)},children:A("spreadsheet.deleteRow","Delete row")}),e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:()=>{rn(b.col),ce(null)},children:A("spreadsheet.deleteCol","Delete column")})]}),pn&&e.jsxs("div",{className:"nice-spreadsheet__status-bar",children:[e.jsxs("span",{children:[A("spreadsheet.count","Count"),": ",pn.count]}),pn.sum!==void 0&&e.jsxs("span",{children:[A("spreadsheet.sum","Sum"),": ",pn.sum.toFixed(2)]}),pn.avg!==void 0&&e.jsxs("span",{children:[A("spreadsheet.avg","Avg"),": ",pn.avg.toFixed(2)]}),pn.min!==void 0&&e.jsxs("span",{children:[A("spreadsheet.min","Min"),": ",pn.min]}),pn.max!==void 0&&e.jsxs("span",{children:[A("spreadsheet.max","Max"),": ",pn.max]})]}),f&&e.jsxs("div",{className:"nice-spreadsheet__tabs",role:"tablist",children:[ie.map((u,h)=>e.jsx("span",{className:"nice-spreadsheet__tab-wrapper",children:G===h?e.jsx(Re.Pe,{className:"nice-spreadsheet__tab-rename",value:E,onChange:v=>de(v),onBlur:()=>Hn(h,E),onKeyDown:v=>{v.key==="Enter"&&Hn(h,E),v.key==="Escape"&&_e(null)},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>{o||(_e(h),de(u.name))},children:e.jsx(Re.pn,{variant:h===M?"primary":"ghost",size:"sm",onClick:()=>je(h),children:u.name})})},h)),!o&&e.jsxs(e.Fragment,{children:[e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:Zn,title:A("spreadsheet.addSheet","Add sheet"),children:e.jsx($a,{})}),ie.length>1&&e.jsx(Re.pn,{variant:"ghost",size:"sm",onClick:nt,title:A("spreadsheet.removeSheet","Remove sheet"),children:e.jsx(Fa,{})})]})]})]})});Pt.displayName="NiceSpreadsheet";const Pa=Object.freeze(Object.defineProperty({__proto__:null,N:fi,a:mt,c:Ot,d:mi,f:Ft,g:$t,j:Pt,k:di,l:xi,m:yi,n:gi,o:pi,p:ui,q:dt,r:Ki,s:Yi},Symbol.toStringTag,{value:"Module"}));exports.Ha=Pt;exports.Kt=mt;exports.L=oi;exports.NiceSavedQueryPanelDFDDuKWd=Pa;exports.dr=gi;exports.fr=yi;exports.hr=xi;exports.ia=$t;exports.lr=mi;exports.oa=Ot;exports.or=pi;exports.q=Tt;exports.ra=Ft;exports.rr=di;exports.ur=fi;