@nice2dev/ui-forms 1.0.18 → 1.0.19

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"),Q=require("./index-BFmhgiku.cjs"),n=require("react"),Ai=require("react-dom"),An=({open:t,onClose:a,title:r,size:l="md",children:d,footer:m,closeOnOverlay:f=!0,closeOnEscape:o=!0,fullscreenable:g,zIndex:N,className:S,style:U,displayStyle:A})=>{const{t:L}=Q.ue(),P=n.useContext(Q.wt),W=n.useRef(null),[y,s]=n.useState(!1),w=Q.Us("modal",A),c=Q.Ks("modal",A);if(Q.ll(W,t),n.useEffect(()=>{if(!t||!o)return;const F=ne=>{ne.key==="Escape"&&a()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},[t,o,a]),n.useEffect(()=>(t?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[t]),!t||typeof document>"u")return null;const $=e.jsx("div",{className:"nice-modal-overlay",style:N?{zIndex:N}:void 0,onClick:f?a:void 0,children:e.jsxs("div",{ref:W,className:`nice-modal nice-modal--${y?"full":l} nice-modal--ds-${c} ${S||""}`,style:{...w,...U},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":L("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 Ai.createPortal($,(P==null?void 0:P.portalTarget)??document.body)};function $i(t,a,r){const l=[];if(a<=1)return a===1&&l.push(1),l;const d=Math.max(2,t-r),m=Math.min(a-1,t+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 ai=({page:t,totalPages:a,onChange:r,showInfo:l,siblingCount:d=1,size:m="md",showFirstLast:f,showJumpInput:o,jumpInputLabel:g,showPageSize:N,pageSizeOptions:S,pageSize:U,onPageSizeChange:A,disabled:L,className:P,style:W})=>{const y=$i(t,a,d);return e.jsxs("nav",{className:`nice-pagination nice-pagination--${m} ${P||""}`,style:W,"aria-label":"Pagination",children:[f&&e.jsx("button",{className:"nice-pagination__btn",disabled:L||t<=1,onClick:()=>r(1),"aria-label":"First page",title:"First page",children:"⏮"}),e.jsx("button",{className:"nice-pagination__btn",disabled:L||t<=1,onClick:()=>r(t-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===t?"nice-pagination__btn--active":""}`,disabled:L,onClick:()=>r(s),"aria-current":s===t?"page":void 0,children:s},s)),e.jsx("button",{className:"nice-pagination__btn",disabled:L||t>=a,onClick:()=>r(t+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:L||t>=a,onClick:()=>r(a),"aria-label":"Last page",title:"Last page",children:"⏭"}),l&&e.jsxs("span",{className:"nice-pagination__info",children:[t," / ",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(Q.Ze,{size:m==="lg"?"md":"sm",min:1,max:a,step:1,value:t,disabled:L,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:U??S[0],disabled:L,onChange:s=>A==null?void 0:A(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 ri({columns:t,data:a,striped:r,compact:l,emptyText:d,className:m,style:f,accessMode:o,id:g,displayStyle:N}){const S=Q.Cl(o,g)==="hidden",U=Q.Us("table",N),A=Q.Ks("table",N),[L,P]=n.useState(null),W=n.useMemo(()=>L?[...a].sort((s,w)=>{const c=s[L.field]??"",$=w[L.field]??"",F=typeof c=="number"?c-$:String(c).localeCompare(String($));return L.dir==="desc"?-F:F}):a,[a,L]),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:{...U,...f},children:e.jsxs("table",{className:`nice-table nice-table--ds-${A} ${r?"nice-table--striped":""} ${l?"nice-table--compact":""}`,"aria-rowcount":W.length,"aria-colcount":t.length,children:[e.jsx("thead",{children:e.jsx("tr",{children:t.map(s=>{const w=s.sortable?(L==null?void 0:L.field)===s.field?L.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&&(L==null?void 0:L.field)===s.field&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:L.dir==="asc"?"↑":"↓"})]},s.field)})})}),e.jsx("tbody",{children:W.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:t.length,className:"nice-table__empty",children:d||"No data"})}):W.map((s,w)=>e.jsx("tr",{children:t.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 li(t,a,r){const l=t.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(t.length);case"min":return Math.min(...l).toLocaleString();case"max":return Math.max(...l).toLocaleString()}}function ln(t){return t.includes(",")||t.includes('"')||t.includes(`
2
+ `)?`"${t.replace(/"/g,'""')}"`:t}function zi(t){return typeof t=="boolean"?t?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(t??"")}function cn({columns:t,data:a,keyField:r="id",dataSource:l,sortable:d=!0,sortField:m,sortDirection:f,onSort:o,selectable:g,selectedKeys:N,onSelectionChange:S,pagination:U,pageSize:A=10,page:L,onPageChange:P,totalRows:W,searchable:y,searchPlaceholder:s,virtualScroll:w,rowHeight:c=40,groupBy:$,groupRender:F,onCellEdit:ne,editMode:de="inline",formItems:Ae,formColumns:D=2,editFormTitle:ue,formProps:_e,onRowEdit:be,onRowAdd:ee,onRowDelete:ae,bulkActions:M,onBulkDelete:E,exportCsv:_,exportFilename:we="export",detailRow:le,expandedRowKeys:O,onExpandedRowChange:B,columnReorder:Y,onColumnReorder:X,columnResize:xe,rowDraggable:pe,onRowReorder:Re,striped:He,compact:tt,loading:De,emptyText:nt,toolbar:Te,onRowClick:Ke,pinnedTopKeys:H,pinnedBottomKeys:ye,colSpan:$e,showStatusBar:z,contextMenuItems:ce,onContextMenuAction:G,printFriendly:T,keyboardNavigation:te,focusedCell:je,onFocusedCellChange:V,cellRangeSelection:Ee,selectedCellRange:Se,onCellRangeChange:me,clipboard:Ye,clipboardFormat:ht="text",onBeforeCopy:ve,onCopy:jt,onPaste:wt,quickFilters:Ve,activeQuickFilters:It,onQuickFilterChange:I,columnGroups:oe,stateStorageKey:he,initialState:ke,onStateChange:dt,flashRowKeys:Ne,flashDuration:Ue=500,autoFitColumns:ut,showColumnStats:Ge,rowIndicator:it,frozenRows:kt,className:Bt,style:Gt,accessMode:Vt,id:Wt,displayStyle:Yt}){var Vn,qn;const mt=Q.Cl(Vt,Wt),on=mt==="hidden",qt=mt==="readOnly"||mt==="disabled",{t:Pe}=Q.ue();Q.Us("table",Yt),Q.Ks("table",Yt);const qe=Q.dc(l??null,{autoLoad:!!l,defaultPageSize:A}),Oe=!!l,Ot=Oe?qe.data:a??[],At=Oe?qe.loading:De,[Kt,Tt]=n.useState({field:"",dir:null}),[Ut,Zt]=n.useState(1),[u,h]=n.useState(new Set),[v,K]=n.useState(""),[q,k]=n.useState(A),[R,J]=n.useState(null),[Fe,Le]=n.useState(null),[re,Ze]=n.useState(null),[rt,pt]=n.useState(new Set),[lt,gt]=n.useState(0),Jt=n.useRef(null),[$t,Nt]=n.useState(new Set),zt=O??$t,[ct,dn]=n.useState({}),[Ct,Et]=n.useState(null),[Lt,en]=n.useState(null),[vn,tn]=n.useState(null),[Rt,un]=n.useState(null),[jn,wn]=n.useState([]),[En,mn]=n.useState(null),[kn,hn]=n.useState(new Set),[Ln,Fn]=n.useState(null),nn=n.useRef(null),Qe=je??vn,st=Se??Rt,ft=It??jn;n.useEffect(()=>{if(!he)return;const i=localStorage.getItem(`nice-datagrid-${he}`);if(i&&!ke)try{const p=JSON.parse(i);p.columnWidths&&dn(p.columnWidths),p.expandedGroups&&pt(new Set(p.expandedGroups))}catch{}},[he,ke]),n.useEffect(()=>{if(!(Ne!=null&&Ne.size))return;hn(new Set(Ne));const i=setTimeout(()=>hn(new Set),Ue);return()=>clearTimeout(i)},[Ne,Ue]),n.useEffect(()=>{if(!Lt)return;const i=()=>en(null);return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[Lt]);const Nn=n.useCallback((i,p)=>{ce!=null&&ce.length&&(i.preventDefault(),en({x:i.clientX,y:i.clientY,row:p}))},[ce]),an=n.useCallback(i=>{const p=new Set(zt);p.has(i)?p.delete(i):p.add(i),B?B(p):Nt(p)},[zt,B]),x=n.useCallback((i,p)=>{var ge;if(!xe)return;p.preventDefault();const b=p.clientX,j=((ge=p.target.closest("th"))==null?void 0:ge.offsetWidth)??100,C=Z=>{const Ce=Math.max(40,j+Z.clientX-b);dn(We=>({...We,[i]:Ce}))},ie=()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",ie)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",ie)},[xe]),se=Oe?((Vn=qe.sort[0])==null?void 0:Vn.field)??"":m??Kt.field,fe=Oe?((qn=qe.sort[0])==null?void 0:qn.direction)??null:f??Kt.dir,Me=Oe?qe.page:L??Ut,Ie=N??u;n.useCallback(()=>{if(!he)return;const i={columnWidths:ct,sortField:se||void 0,sortDirection:fe,pageSize:q,expandedGroups:Array.from(rt)};localStorage.setItem(`nice-datagrid-${he}`,JSON.stringify(i)),dt==null||dt(i)},[he,ct,se,fe,q,rt,dt]);const Xe=n.useMemo(()=>t.filter(i=>!i.hidden),[t]),bt=n.useMemo(()=>Xe.filter(i=>i.pinned==="left"),[Xe]),ot=n.useMemo(()=>Xe.filter(i=>i.pinned==="right"),[Xe]),pn=n.useMemo(()=>Xe.filter(i=>!i.pinned),[Xe]),Be=n.useMemo(()=>[...bt,...pn,...ot],[bt,pn,ot]),bi=n.useMemo(()=>Xe.some(i=>i.aggregate),[Xe]),rn=bt.length>0||ot.length>0,Pn=n.useCallback(i=>{const p=se===i?fe==="asc"?"desc":fe==="desc"?null:"asc":"asc";Oe?p?qe.setSortField(i,p):qe.setSort([]):o?o(i,p):Tt({field:i,dir:p})},[se,fe,Oe,qe,o]),_t=n.useMemo(()=>{if(Oe)return Ot;let i=[...Ot];if(v){const p=v.toLowerCase();i=i.filter(b=>Xe.some(j=>String(b[j.field]??"").toLowerCase().includes(p)))}return!o&&se&&fe&&i.sort((p,b)=>{const j=p[se]??"",C=b[se]??"",ie=typeof j=="number"?j-C:String(j).localeCompare(String(C));return fe==="desc"?-ie:ie}),i},[Ot,v,Xe,se,fe,o,Oe]),gn=Oe?qe.totalCount:W??_t.length,Qt=Oe?qe.pageSize:q,_i=Math.max(1,Math.ceil(gn/Qt)),St=Oe?_t:U&&!W?_t.slice((Me-1)*Qt,Me*Qt):_t,Cn=n.useCallback(i=>{Oe?qe.setPage(i):P?P(i):Zt(i)},[Oe,qe,P]),Xt=n.useMemo(()=>St.map(i=>String(i[r])),[St,r]),Ht=Xt.length>0&&Xt.every(i=>Ie.has(i)),On=Xt.some(i=>Ie.has(i)),Kn=n.useCallback(()=>{const i=new Set(Ie);Ht?Xt.forEach(p=>i.delete(p)):Xt.forEach(p=>i.add(p)),S?S(i):h(i)},[Ht,Xt,Ie,S]),Un=n.useCallback(i=>{const p=new Set(Ie);p.has(i)?p.delete(i):p.add(i),S?S(p):h(p)},[Ie,S]),Bn=({field:i})=>se!==i||!fe?e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:.3},children:"?"}):e.jsx("span",{className:"nice-table__sort-icon",children:"?"}),xt=n.useMemo(()=>{if(!$)return St.map((b,j)=>({type:"data",row:b,key:String(b[r]??j)}));const i=new Map;St.forEach(b=>{const j=b[$];i.has(j)||i.set(j,[]),i.get(j).push(b)});const p=[];return i.forEach((b,j)=>{const C=`__group_${String(j)}`,ie=rt.has(C);p.push({type:"group",value:j,rows:b,expanded:ie,key:C}),ie&&b.forEach((ge,Z)=>p.push({type:"data",row:ge,key:String(ge[r]??`${C}_${Z}`)}))}),p},[St,$,r,rt]),{pinnedTopRows:xi,pinnedBottomRows:yi,normalRows:vi}=n.useMemo(()=>{if(!(H!=null&&H.size)&&!(ye!=null&&ye.size))return{pinnedTopRows:[],pinnedBottomRows:[],normalRows:xt};const i=[],p=[],b=[];for(const j of xt){if(j.type==="data"){const C=j.key;if(H!=null&&H.has(C)){i.push(j);continue}if(ye!=null&&ye.has(C)){p.push(j);continue}}b.push(j)}return{pinnedTopRows:i,pinnedBottomRows:p,normalRows:b}},[xt,H,ye]),Gn=n.useCallback(i=>{pt(p=>{const b=new Set(p);return b.has(i)?b.delete(i):b.add(i),b})},[]),ji=n.useMemo(()=>{var C;if(!w)return xt;const i=((C=Jt.current)==null?void 0:C.clientHeight)??400,p=Math.ceil(i/c),b=Math.max(0,Math.floor(lt/c)-3),j=Math.min(xt.length-1,b+p+6);return xt.slice(b,j+1).map((ie,ge)=>({...ie,_vIdx:b+ge}))},[w,xt,lt,c]),fn=n.useCallback((i,p,b)=>{!ne||qt||(J({rowKey:i,field:p}),Le(b))},[ne]),Wn=n.useCallback(()=>{R&&ne&&ne(R.rowKey,R.field,Fe),J(null),Le(null)},[R,Fe,ne]),wi=n.useCallback(()=>{J(null),Le(null)},[]),ki=n.useCallback(()=>{const i=Xe,p=i.map(Z=>ln(Z.header)).join(","),b=_t.map(Z=>i.map(Ce=>ln(String(Z[Ce.field]??""))).join(",")),j=[p,...b].join(`
3
+ `),C=new Blob(["\uFEFF"+j],{type:"text/csv;charset=utf-8;"}),ie=URL.createObjectURL(C),ge=document.createElement("a");ge.href=ie,ge.download=`${we}.csv`,ge.click(),URL.revokeObjectURL(ie)},[Xe,_t,we]),bn=n.useCallback(i=>{V?V(i):tn(i)},[V]),_n=n.useCallback(i=>{me?me(i):un(i)},[me]),yt=n.useMemo(()=>xt.filter(i=>i.type==="data").map(i=>i.key),[xt]),Ni=n.useCallback(i=>{if(!te||R||!Qe)return;const p=yt.indexOf(Qe.rowKey),b=Be.findIndex(ge=>ge.field===Qe.field);if(p<0||b<0)return;let j=p,C=b;switch(i.key){case"ArrowUp":j=Math.max(0,p-1);break;case"ArrowDown":j=Math.min(yt.length-1,p+1);break;case"ArrowLeft":C=Math.max(0,b-1);break;case"ArrowRight":C=Math.min(Be.length-1,b+1);break;case"Tab":i.preventDefault(),i.shiftKey?C=Math.max(0,b-1):C=Math.min(Be.length-1,b+1);break;case"Enter":{const ge=Be[b];if(ge.editable&&ne){const Z=St.find(Ce=>String(Ce[r])===Qe.rowKey);Z&&fn(Qe.rowKey,ge.field,Z[ge.field])}return}case"Escape":bn(null),_n(null);return;case"Home":i.ctrlKey&&(j=0),C=0;break;case"End":i.ctrlKey&&(j=yt.length-1),C=Be.length-1;break;case"PageUp":j=Math.max(0,p-q);break;case"PageDown":j=Math.min(yt.length-1,p+q);break;default:return}i.preventDefault();const ie={rowKey:yt[j],field:Be[C].field};if(bn(ie),i.shiftKey&&Ee){const ge=(st==null?void 0:st.start)??Qe;_n({start:ge,end:ie})}else _n(null)},[te,R,Qe,yt,Be,Ee,st,bn,_n,ne,St,r,fn,q]),Yn=n.useCallback(()=>{let i=[],p=[];if(st){const b=yt.indexOf(st.start.rowKey),j=yt.indexOf(st.end.rowKey),C=Math.min(b,j),ie=Math.max(b,j),ge=Be.findIndex(Je=>Je.field===st.start.field),Z=Be.findIndex(Je=>Je.field===st.end.field),Ce=Math.min(ge,Z),We=Math.max(ge,Z);p=Be.slice(Ce,We+1).map(Je=>Je.field),i=St.filter(Je=>{const Ft=yt.indexOf(String(Je[r]));return Ft>=C&&Ft<=ie})}else Ie.size>0&&(i=St.filter(b=>Ie.has(String(b[r]))),p=Be.map(b=>b.field));return{rows:i,fields:p}},[st,yt,Be,St,r,Ie]),Zn=n.useCallback((i,p,b)=>{const j=Be.filter(C=>p.includes(C.field));switch(b){case"json":return JSON.stringify(i.map(C=>Object.fromEntries(p.map(ie=>[ie,C[ie]]))),null,2);case"csv":{const C=j.map(ge=>ln(ge.header)).join(","),ie=i.map(ge=>j.map(Z=>ln(String(ge[Z.field]??""))).join(",")).join(`
4
+ `);return C+`
5
+ `+ie}case"html":{const C=j.map(ge=>`<th>${ge.header}</th>`).join(""),ie=i.map(ge=>`<tr>${j.map(Z=>`<td>${ge[Z.field]??""}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${C}</tr></thead><tbody>${ie}</tbody></table>`}case"markdown":{const C="| "+j.map(Z=>Z.header).join(" | ")+" |",ie="| "+j.map(()=>"---").join(" | ")+" |",ge=i.map(Z=>"| "+j.map(Ce=>Z[Ce.field]??"").join(" | ")+" |").join(`
6
+ `);return C+`
7
+ `+ie+`
8
+ `+ge}default:return i.map(C=>j.map(ie=>C[ie.field]??"").join(" ")).join(`
9
+ `)}},[Be]),Sn=n.useCallback(async()=>{if(!Ye)return;const{rows:i,fields:p}=Yn();if(!i.length||(ve==null?void 0:ve(i,p))===!1)return;const b=Zn(i,p,ht);await navigator.clipboard.writeText(b),jt==null||jt(i,p,ht)},[Ye,Yn,ve,Zn,ht,jt]),Qn=n.useCallback(async()=>{if(!Ye||!Qe||!wt)return;const i=(await navigator.clipboard.readText()).split(`
10
+ `).map(p=>p.split(" "));wt(i,Qe)},[Ye,Qe,wt]);n.useEffect(()=>{if(!Ye||!nn.current)return;const i=p=>{var b;(b=nn.current)!=null&&b.contains(document.activeElement)&&(p.type==="copy"&&(p.preventDefault(),Sn()),p.type==="paste"&&(p.preventDefault(),Qn()))};return document.addEventListener("copy",i),document.addEventListener("paste",i),()=>{document.removeEventListener("copy",i),document.removeEventListener("paste",i)}},[Ye,Sn,Qn]);const Ci=n.useCallback(i=>{const p=ft.includes(i)?ft.filter(b=>b!==i):[...ft,i];I?I(p):wn(p)},[ft,I]),Si=n.useMemo(()=>{if(!(Ve!=null&&Ve.length)||!ft.length)return _t;const i=Ve.filter(p=>ft.includes(p.key));return _t.filter(p=>i.every(b=>b.filter(p)))},[_t,Ve,ft]),Xn=Ve!=null&&Ve.length?Si:_t;n.useCallback(i=>{const p=_t.map(Ce=>Ce[i]).filter(Ce=>Ce!=null),b=p.filter(Ce=>typeof Ce=="number");if(b.length===0){const Ce=new Set(p).size;return{count:p.length,unique:Ce,type:"text"}}const j=b.reduce((Ce,We)=>Ce+We,0),C=j/b.length,ie=Math.min(...b),ge=Math.max(...b),Z=Math.sqrt(b.reduce((Ce,We)=>Ce+(We-C)**2,0)/b.length);return{count:b.length,sum:j,avg:C,min:ie,max:ge,stdDev:Z,type:"numeric"}},[_t]);const Mi=n.useCallback((i,p,b)=>{if(!i.cellVisualization)return null;const j=Number(p);if(isNaN(j))return null;const C=i.visualMin??0,ie=i.visualMax??100,ge=Math.max(0,Math.min(100,(j-C)/(ie-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:`${ge}%`,height:"100%",background:ge>80?"var(--color-success)":ge>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(ge),"%"]})]});case"rating":{const Z=Math.round(j/ie*5);return e.jsx("div",{className:"nice-datagrid__cell-rating",children:[1,2,3,4,5].map(Ce=>e.jsx("span",{style:{color:Ce<=Z?"var(--color-warning)":"var(--text-muted)",fontSize:"0.85rem"},children:"?"},Ce))})}case"trend":{const Z=i.visualMin??j,Ce=j-Z,We="?",Je=Ce>0?"var(--color-success)":Ce<0?"var(--color-danger)":"var(--text-muted)";return e.jsxs("span",{style:{color:Je,fontWeight:500},children:[We," ",Math.abs(Ce).toFixed(1),"%"]})}case"heatmap":{const Z=ge/100,Ce=`rgba(${Math.round(255*Z)}, ${Math.round(100*(1-Z))}, ${Math.round(50*(1-Z))}, 0.6)`;return e.jsx("span",{style:{background:Ce,padding:"2px 8px",borderRadius:4},children:j})}default:return null}},[]),Di=n.useCallback((i,p,b)=>{var j;if(!((j=i.conditionalFormats)!=null&&j.length))return{};for(const C of i.conditionalFormats)if(C.when(p,b,i.field))return{className:C.className,style:{...C.style,backgroundColor:C.backgroundColor,color:C.color}};return{}},[]),Mn=n.useCallback((i,p)=>{if(!rn||!i.pinned)return{};const b={position:"sticky",zIndex:2,background:"var(--bg-primary, #fff)"};if(i.pinned==="left"){let j=0;for(let C=0;C<p;C++){const ie=Be[C];ie.pinned==="left"&&(j+=typeof ie.width=="number"?ie.width:parseInt(String(ie.width)||"100",10))}g&&p===0&&(j=36),b.left=j}else{let j=0;for(let C=Be.length-1;C>p;C--){const ie=Be[C];ie.pinned==="right"&&(j+=typeof ie.width=="number"?ie.width:parseInt(String(ie.width)||"100",10))}b.right=j}return b},[rn,Be,g]),Hn=(i,p,b,j)=>(R==null?void 0:R.rowKey)===b&&(R==null?void 0:R.field)===i.field?i.editor?i.editor(Fe,p,ie=>Le(ie)):e.jsx("input",{className:"nice-datagrid__edit-input",autoFocus:!0,value:Fe??"",onChange:ie=>Le(ie.target.value),onBlur:Wn,onKeyDown:ie=>{ie.key==="Enter"&&Wn(),ie.key==="Escape"&&wi()}}):Mi(i,p[i.field],p)||(i.render?i.render(p[i.field],p,j):zi(p[i.field])),Ii=(i,p,b,j)=>{const C=(Qe==null?void 0:Qe.rowKey)===b&&(Qe==null?void 0:Qe.field)===i.field,ie=st&&(()=>{const Z=yt.indexOf(st.start.rowKey),Ce=yt.indexOf(st.end.rowKey),We=yt.indexOf(b),Je=Be.findIndex(Pt=>Pt.field===st.start.field),Ft=Be.findIndex(Pt=>Pt.field===st.end.field);return We>=Math.min(Z,Ce)&&We<=Math.max(Z,Ce)&&j>=Math.min(Je,Ft)&&j<=Math.max(Je,Ft)})(),ge=Di(i,p[i.field],p);return{className:[ge.className,C&&"nice-datagrid__cell--focused",ie&&"nice-datagrid__cell--in-range"].filter(Boolean).join(" "),style:{...Mn(i,j),textAlign:i.align,...ge.style,...C?{outline:"2px solid var(--color-primary)",outlineOffset:-2}:{},...ie?{background:"var(--color-primary-light, rgba(59,130,246,0.15))"}:{}}}},xn=Be.length+(g?1:0)+(le?1:0)+(pe?1:0)+(it?1:0),Dn=(i,p,b)=>{const{row:j,key:C}=i,ie=Ie.has(C),ge=zt.has(C),Z=kn.has(C),Ce=[ie&&"nice-datagrid__row--selected",Ct===p&&"nice-datagrid__row--dragging",b&&"nice-datagrid__row--pinned",Z&&"nice-datagrid__row--flash"].filter(Boolean).join(" ");return e.jsxs(n.Fragment,{children:[e.jsxs("tr",{className:Ce,onClick:()=>Ke==null?void 0:Ke(j),onDoubleClick:de==="popup"&&(be||ne)?()=>Ze({key:C,data:{...j}}):void 0,onContextMenu:We=>Nn(We,j),style:Ke||de==="popup"?{cursor:"pointer"}:void 0,draggable:pe,onDragStart:pe?()=>Et(p):void 0,onDragOver:pe?We=>We.preventDefault():void 0,onDrop:pe&&Re&&Ct!=null?()=>{Re(Ct,p),Et(null)}:void 0,onDragEnd:pe?()=>Et(null):void 0,children:[it&&e.jsx("td",{className:"nice-datagrid__row-indicator",style:{width:32,padding:"0 4px"},children:it(j)}),le&&e.jsx("td",{className:"nice-datagrid__expand-col",onClick:We=>{We.stopPropagation(),an(C)},children:e.jsx("span",{className:"nice-datagrid__expand-btn",children:"?"})}),pe&&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:We=>We.stopPropagation(),style:rn?{position:"sticky",left:0,zIndex:1,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:ie,onChange:()=>Un(C),"aria-label":`Select row ${C}`})}),(()=>{let We=0;return Be.map((Je,Ft)=>{if(We>0)return We--,null;const Pt=$e?$e(j,Je,Ft):void 0;Pt&&Pt>1&&(We=Pt-1);const Jn=Ii(Je,j,C,Ft);return e.jsx("td",{colSpan:Pt,className:Jn.className,style:Jn.style,onClick:te?()=>bn({rowKey:C,field:Je.field}):void 0,onDoubleClick:Je.editable&&ne?()=>fn(C,Je.field,j[Je.field]):void 0,children:Hn(Je,j,C,p)},Je.field)})})()]}),le&&ge&&e.jsx("tr",{className:"nice-datagrid__detail-row",children:e.jsx("td",{colSpan:xn,children:le(j)})})]},C)};return on?null:e.jsxs("div",{ref:nn,className:`nice-datagrid ${T?"nice-datagrid--print":""} ${Bt||""}`,style:Gt,role:"grid","aria-label":Pe("datagrid.title","Data Grid"),"aria-rowcount":xt.length,"aria-colcount":Xe.length,"aria-busy":At||void 0,tabIndex:te?0:void 0,onKeyDown:te?Ni:void 0,children:[(y||Te||_||(Ve==null?void 0:Ve.length)||ee)&&e.jsxs("div",{className:"nice-datagrid__toolbar",children:[y&&e.jsx("div",{className:"nice-datagrid__search",children:e.jsx("input",{type:"text",value:Oe?qe.search:v,"aria-label":Pe("controls.search","Search"),onChange:i=>{Oe?qe.setSearch(i.target.value):(K(i.target.value),Cn(1))},placeholder:s||Pe("controls.search","Search...")})}),Ve&&Ve.length>0&&e.jsx("div",{className:"nice-datagrid__quick-filters",style:{display:"flex",gap:6,flexWrap:"wrap"},children:Ve.map(i=>e.jsxs("button",{className:`nice-datagrid__quick-filter ${ft.includes(i.key)?"nice-datagrid__quick-filter--active":""}`,onClick:()=>Ci(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:ft.includes(i.key)?`var(--color-${i.color||"primary"})`:"var(--bg-primary)",color:ft.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))}),Ye&&e.jsx("button",{className:"nice-btn nice-btn--sm nice-btn--ghost",onClick:Sn,title:Pe("controls.copy","Copy selected"),style:{marginLeft:4},children:"??"}),_&&e.jsx("button",{className:"nice-btn nice-btn--sm",onClick:ki,title:Pe("controls.exportCsv","Export CSV"),children:"CSV ?"}),ee&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--primary",onClick:()=>Ze({key:null,data:{}}),title:Pe("datagrid.addRow","Add row"),children:["+ ",Pe("datagrid.add","Add")]}),Te]}),g&&Ie.size>0&&((M==null?void 0:M.length)||E)&&e.jsxs("div",{className:"nice-datagrid__bulk-toolbar",role:"toolbar","aria-label":Pe("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:Pe("datagrid.selectedCount","{count} selected").replace("{count}",String(Ie.size))}),(M||[]).map(i=>{var C;const p=Array.from(Ie),b=Xn.filter(ie=>Ie.has(String(ie[r]))),j=((C=i.disabled)==null?void 0:C.call(i,p,b))||!1;return e.jsxs("button",{type:"button",className:`nice-btn nice-btn--sm nice-btn--${i.variant||"secondary"}`,disabled:j,onClick:()=>i.onClick(p,b),children:[i.icon,i.icon&&" ",i.label]},i.key)}),E&&!(M!=null&&M.length)&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--danger",onClick:()=>{const i=Array.from(Ie),p=Xn.filter(b=>Ie.has(String(b[r])));E(i,p)},children:["?? ",Pe("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:Pe("datagrid.clearSelection","Clear")})]}),e.jsxs("div",{ref:Jt,className:`nice-datagrid__table-wrap ${w?"nice-datagrid__table-wrap--virtual":""}`,style:w?{maxHeight:Math.min(xt.length*c,600),overflowY:"auto"}:void 0,onScroll:w?i=>gt(i.currentTarget.scrollTop):void 0,children:[w&&e.jsxs("div",{style:{height:xt.length*c,position:"relative"},children:[e.jsx("table",{className:`${He?"nice-table--striped":""} ${tt?"nice-table--compact":""}`,style:{position:"sticky",top:0,zIndex:3},children:e.jsx("thead",{children:e.jsxs("tr",{children:[le&&e.jsx("th",{className:"nice-datagrid__expand-col",style:{width:36}}),pe&&e.jsx("th",{style:{width:28}}),g&&e.jsx("th",{className:"nice-datagrid__checkbox",style:rn?{position:"sticky",left:0,zIndex:3,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:Ht,ref:i=>{i&&(i.indeterminate=On&&!Ht)},onChange:Kn,"aria-label":Pe("controls.selectAll","Select all")})}),Be.map((i,p)=>e.jsxs("th",{style:{width:ct[i.field]||i.width,minWidth:i.minWidth,textAlign:i.align,position:"relative",...Mn(i,p)},className:d&&i.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>d&&i.sortable!==!1&&Pn(i.field),children:[i.header,d&&i.sortable!==!1&&e.jsx(Bn,{field:i.field}),xe&&e.jsx("span",{className:"nice-datagrid__resize-handle",onMouseDown:b=>{b.stopPropagation(),x(i.field,b)}})]},i.field))]})})}),ji.map((i,p)=>{const b=i._vIdx??0;if(i.type==="group"){const Z=i;return e.jsxs("div",{className:"nice-datagrid__group-row",style:{position:"absolute",top:b*c,height:c,left:0,right:0},onClick:()=>Gn(Z.key),children:[e.jsx("span",{className:"nice-datagrid__group-toggle",children:(Z.expanded,"?")}),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,ie=Ie.has(C),ge=zt.has(C);return e.jsxs(n.Fragment,{children:[e.jsxs("div",{className:`nice-datagrid__vrow ${ie?"nice-datagrid__row--selected":""} ${Ct===p?"nice-datagrid__row--dragging":""}`,style:{position:"absolute",top:b*c,height:c,left:0,right:0,display:"flex",alignItems:"center"},onClick:()=>Ke==null?void 0:Ke(j),onDoubleClick:de==="popup"&&(be||ne)?()=>Ze({key:C,data:{...j}}):void 0,draggable:pe,onDragStart:pe?()=>Et(p):void 0,onDragOver:pe?Z=>Z.preventDefault():void 0,onDrop:pe&&Re&&Ct!=null?()=>{Re(Ct,p),Et(null)}:void 0,onDragEnd:pe?()=>Et(null):void 0,children:[le&&e.jsx("div",{className:"nice-datagrid__expand-col",style:{width:36,flexShrink:0,textAlign:"center",cursor:"pointer"},onClick:Z=>{Z.stopPropagation(),an(C)},children:e.jsx("span",{className:"nice-datagrid__expand-btn",children:"?"})}),pe&&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:ie,onChange:()=>Un(C)})}),Be.map(Z=>e.jsx("div",{className:"nice-datagrid__vcell",style:{width:ct[Z.field]||Z.width||"auto",flex:ct[Z.field]||Z.width?`0 0 ${typeof(ct[Z.field]||Z.width)=="number"?(ct[Z.field]||Z.width)+"px":ct[Z.field]||Z.width}`:1,textAlign:Z.align,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 8px"},onDoubleClick:Z.editable&&ne?()=>fn(C,Z.field,j[Z.field]):void 0,children:Hn(Z,j,C,b)},Z.field))]}),le&&ge&&e.jsx("div",{className:"nice-datagrid__detail-row",style:{position:"absolute",top:(b+1)*c,left:0,right:0,padding:"8px 12px",background:"var(--bg-secondary, #f8f8f8)"},children:le(j)})]},C)})]}),!w&&e.jsxs("table",{className:`${He?"nice-table--striped":""} ${tt?"nice-table--compact":""}`,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[le&&e.jsx("th",{className:"nice-datagrid__expand-col",style:{width:36}}),pe&&e.jsx("th",{style:{width:28}}),g&&e.jsx("th",{className:"nice-datagrid__checkbox",style:rn?{position:"sticky",left:0,zIndex:3,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:Ht,ref:i=>{i&&(i.indeterminate=On&&!Ht)},onChange:Kn,"aria-label":Pe("controls.selectAll","Select all")})}),Be.map((i,p)=>{const b=d&&i.sortable!==!1,j=b?se===i.field?fe==="asc"?"ascending":fe==="desc"?"descending":"none":"none":void 0;return e.jsxs("th",{style:{width:ct[i.field]||i.width,minWidth:i.minWidth,textAlign:i.align,position:"relative",...Mn(i,p)},className:b?"nice-datagrid__th--sortable":void 0,onClick:()=>b&&Pn(i.field),"aria-sort":j,scope:"col",children:[i.header,b&&e.jsx(Bn,{field:i.field}),xe&&e.jsx("span",{className:"nice-datagrid__resize-handle",onMouseDown:C=>{C.stopPropagation(),x(i.field,C)}})]},i.field)})]})}),e.jsx("tbody",{children:At?e.jsx("tr",{children:e.jsx("td",{colSpan:xn,className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):xt.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:xn,className:"nice-datagrid__empty",children:nt||Pe("controls.noData","No data available")})}):e.jsxs(e.Fragment,{children:[xi.map((i,p)=>i.type==="data"&&Dn(i,p,"top")),vi.map((i,p)=>{if(i.type==="group"){const b=i;return e.jsx("tr",{className:"nice-datagrid__group-row",onClick:()=>Gn(b.key),children:e.jsxs("td",{colSpan:xn,className:"nice-datagrid__group-cell",children:[e.jsx("span",{className:"nice-datagrid__group-toggle",children:(b.expanded,"?")}),F?F(b.value,b.rows):e.jsxs(e.Fragment,{children:[String(b.value)," (",b.rows.length,")"]})]})},b.key)}return Dn(i,p)}),yi.map((i,p)=>i.type==="data"&&Dn(i,p,"bottom"))]})}),bi&&!At&&St.length>0&&e.jsx("tfoot",{children:e.jsxs("tr",{className:"nice-datagrid__aggregate-row",children:[g&&e.jsx("td",{}),Be.map(i=>e.jsx("td",{style:{textAlign:i.align,fontWeight:600},children:i.aggregate?(i.aggregateLabel||i.aggregate.toUpperCase())+": "+li(_t,i.field,i.aggregate):""},i.field))]})})]})]}),U&&e.jsxs("div",{className:"nice-datagrid__footer",children:[e.jsxs("span",{className:"nice-datagrid__footer-info",children:[Pe("controls.showing","Showing")," ",(Me-1)*Qt+1,"�",Math.min(Me*Qt,gn)," ",Pe("controls.of","of")," ",gn]}),e.jsx(ai,{page:Me,totalPages:_i,onChange:Cn,showInfo:!0,pageSize:Qt,showPageSize:!0,pageSizeOptions:[5,10,25,50,100],onPageSizeChange:i=>{Oe?qe.setPageSize(i):(k(i),Cn(1))},showFirstLast:!0})]}),z&&!At&&e.jsxs("div",{className:"nice-datagrid__status-bar",children:[e.jsxs("span",{children:[Pe("controls.totalRows","Total rows"),": ",gn]}),g&&Ie.size>0&&e.jsxs("span",{children:[Pe("controls.selected","Selected"),": ",Ie.size]})]}),Lt&&ce&&e.jsx("div",{className:"nice-datagrid__context-menu",style:{position:"fixed",left:Lt.x,top:Lt.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,Lt.row),en(null)},children:[i.icon&&e.jsx("span",{className:"nice-datagrid__context-icon",children:i.icon}),i.label]},i.key))}),(de==="popup"||ee)&&re&&(()=>{const i=re.key===null,p=Ae??t.filter(b=>!b.hidden&&b.field!==r).map(b=>{var C;let j="text";return b.dataType==="number"||b.dataType==="currency"||b.dataType==="percent"?j="number":b.dataType==="boolean"?j="checkbox":b.dataType==="date"&&(j="date"),{field:b.field,label:b.header,type:j,required:(C=b.validation)==null?void 0:C.required}});return e.jsx(An,{open:!0,onClose:()=>Ze(null),title:ue??(i?Pe("datagrid.addRow","Add row"):Pe("datagrid.editRow","Edit row")),size:"lg",children:e.jsx(Q.Ga,{items:p,data:re.data,columns:D,showActions:!0,submitLabel:i?Pe("controls.add","Add"):Pe("controls.save","Save"),cancelLabel:Pe("controls.cancel","Cancel"),onCancel:()=>Ze(null),..._e,onFieldChange:(b,j)=>Ze(C=>C&&{...C,data:{...C.data,[b]:j}}),onSubmit:b=>{i?ee==null||ee(b):re.key&&(be?be(re.key,b):ne&&Object.keys(b).forEach(j=>{ne(re.key,j,b[j])})),Ze(null)}})})})()]})}cn.displayName="NiceDataGrid";const Ri=Object.freeze(Object.defineProperty({__proto__:null,NiceDataGrid:cn},Symbol.toStringTag,{value:"Module"}));function Ti(t,a){return t.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 Ei(t){return t.map(a=>({field:a.field,type:a.dataType||"string",label:typeof a.header=="string"?a.header:a.field}))}function Li(t,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:U,data:A,...L}=t,[P,W]=n.useState(""),[y,s]=n.useState([]),[w,c]=n.useState([]),[$,F]=n.useState(!1),[ne,de]=n.useState(null),Ae=n.useRef(null),{t:D}=Q.ue(),ue=Q.me(),{parseFilter:_e,isLoading:be}=Q.$d(),ee=r&&ue.isConfigured,ae=y.length>0?Ti(A||[],y):A,M=n.useCallback(async B=>{if(!ee||!d||!B.trim())return;de(B);const Y=Ei(U);try{const X=await _e(B,Y);s(X),o==null||o(B,X)}catch{s([])}},[ee,d,U,_e,o]),E=n.useCallback(()=>{s([]),de(null),W("")},[]),_=n.useCallback(()=>y,[y]),we=n.useCallback(async()=>{if(!ee||!m||!(A!=null&&A.length))return[];try{const B=await ue.complete([{role:"user",content:`Analyze this data and provide 3-5 key insights. Data sample (${A.length} total rows): ${JSON.stringify(A.slice(0,20))}
11
+
12
+ Columns: ${U.map(Y=>Y.field).join(", ")}
13
+
14
+ Return a JSON array of insight strings. Be specific with numbers and trends.`}],{temperature:.3,maxTokens:500});try{const Y=JSON.parse(B.content),X=Array.isArray(Y)?Y:[];return c(X),g==null||g(X),X}catch{return[]}}catch{return[]}},[ee,m,A,U,ue,g]),le=B=>{B.preventDefault(),P.trim()&&M(P)},O=B=>{W(B),M(B)};return n.useImperativeHandle(a,()=>({applyNLFilter:M,clearAIFilters:E,getAIFilters:_,generateInsights:we})),e.jsxs("div",{className:"nice-data-grid-ai","data-testid":t["data-testid"],children:[N&&ee&&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:le,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:B=>W(B.target.value),placeholder:f||D("dataGridAI.searchPlaceholder","Search with natural language..."),className:"nice-data-grid-ai__input",disabled:be}),be&&e.jsx("span",{className:"nice-data-grid-ai__loading-spinner"}),P&&!be&&e.jsx("button",{type:"button",className:"nice-data-grid-ai__clear-input",onClick:()=>W(""),children:"✕"})]}),e.jsx("button",{type:"submit",className:"nice-data-grid-ai__search-btn",disabled:be||!P.trim(),children:be?D("dataGridAI.searching","Searching..."):D("dataGridAI.search","Search")})]}),m&&e.jsxs("button",{type:"button",className:"nice-data-grid-ai__insights-btn",onClick:()=>{we(),F(!0)},disabled:be||!(A!=null&&A.length),title:D("dataGridAI.generateInsights","Generate AI Insights"),children:["💡 ",D("dataGridAI.insights","Insights")]})]}),N&&ee&&d&&!ne&&S.length>0&&e.jsxs("div",{className:"nice-data-grid-ai__examples",children:[e.jsx("span",{className:"nice-data-grid-ai__examples-label",children:D("dataGridAI.tryAsking","Try asking:")}),e.jsx("div",{className:"nice-data-grid-ai__examples-list",children:S.slice(0,4).map((B,Y)=>e.jsxs("button",{type:"button",className:"nice-data-grid-ai__example",onClick:()=>O(B),children:['"',B,'"']},Y))})]}),ne&&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:['"',ne,'"']}),e.jsxs("span",{className:"nice-data-grid-ai__filter-count",children:["(",(ae==null?void 0:ae.length)||0," ",D("dataGridAI.results","results"),")"]})]}),e.jsx("div",{className:"nice-data-grid-ai__filter-badges",children:y.map((B,Y)=>e.jsxs("span",{className:"nice-data-grid-ai__filter-badge",children:[B.field," ",B.operator," ",String(B.value)]},Y))}),e.jsxs("button",{type:"button",className:"nice-data-grid-ai__clear-filter",onClick:E,children:["✕ ",D("dataGridAI.clearFilter","Clear")]})]}),e.jsx("div",{className:"nice-data-grid-ai__grid-wrapper",children:e.jsx(cn,{columns:U,data:ae,...L})}),$&&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:["💡 ",D("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:be?e.jsx("div",{className:"nice-data-grid-ai__insights-loading",children:D("dataGridAI.analyzing","Analyzing data...")}):w.length>0?e.jsx("ul",{className:"nice-data-grid-ai__insights-list",children:w.map((B,Y)=>e.jsxs("li",{className:"nice-data-grid-ai__insight",children:[e.jsx("span",{className:"nice-data-grid-ai__insight-bullet",children:"•"}),B]},Y))}):e.jsx("div",{className:"nice-data-grid-ai__insights-empty",children:D("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:()=>we(),disabled:be,children:["🔄 ",D("dataGridAI.refresh","Refresh")]})})]})]})}n.forwardRef(Li);const si=({items:t,selectedKeys:a=[],onSelectionChange:r,selectionMode:l="none",searchable:d,searchPlaceholder:m,grouped:f,groupField:o="group",reorderable:g,onReorder:N,onItemClick:S,renderItem:U,showCheckboxes:A,loading:L,emptyText:P,size:W="md",bordered:y=!0,swipeActions:s,className:w,style:c,accessMode:$,id:F})=>{const ne=Q.Cl($,F)==="hidden",{t:de}=Q.ue(),[Ae,D]=n.useState(""),[ue,_e]=n.useState(null),[be,ee]=n.useState(null),ae=n.useRef(null),M=n.useMemo(()=>{if(!Ae)return t;const O=Ae.toLowerCase();return t.filter(B=>B.text.toLowerCase().includes(O))},[t,Ae]),E=n.useMemo(()=>{if(!f)return null;const O=new Map;return M.forEach(B=>{const Y=String(B[o]??"");O.has(Y)||O.set(Y,[]),O.get(Y).push(B)}),O},[M,f,o]),_=n.useCallback(O=>{r&&(l==="single"?r(a.includes(O)?[]:[O]):l==="multiple"&&r(a.includes(O)?a.filter(B=>B!==O):[...a,O]))},[a,l,r]),we=n.useCallback(O=>{ue!==null&&ue!==O&&N&&N(ue,O),_e(null)},[ue,N]),le=(O,B)=>{const Y=a.includes(O.key),X=be===O.key;return e.jsxs("li",{className:`nice-list__item ${Y?"nice-list__item--selected":""} ${O.disabled?"nice-list__item--disabled":""} ${X?"nice-list__item--swiped":""}`,onClick:()=>{O.disabled||(_(O.key),S==null||S(O))},draggable:g,onDragStart:()=>_e(B),onDragOver:xe=>xe.preventDefault(),onDrop:()=>we(B),onTouchStart:s!=null&&s.length?xe=>{ae.current={x:xe.touches[0].clientX,key:O.key}}:void 0,onTouchEnd:s!=null&&s.length?xe=>{if(!ae.current)return;const pe=xe.changedTouches[0].clientX-ae.current.x;pe<-50&&ae.current.key===O.key?ee(O.key):pe>50&&ee(null),ae.current=null}:void 0,role:l!=="none"?"option":void 0,"aria-selected":l!=="none"?Y:void 0,children:[e.jsxs("div",{className:"nice-list__item-content",children:[A&&l!=="none"&&e.jsx("input",{type:"checkbox",checked:Y,readOnly:!0,tabIndex:-1,className:"nice-list__checkbox"}),U?U(O):e.jsxs(e.Fragment,{children:[O.icon&&e.jsx("span",{className:"nice-list__icon",children:O.icon}),e.jsx("span",{className:"nice-list__text",children:O.text}),O.badge&&e.jsx("span",{className:"nice-list__badge",children:O.badge})]})]}),s&&X&&e.jsx("div",{className:"nice-list__swipe-actions",children:s.map(xe=>e.jsx("button",{className:"nice-list__swipe-btn",style:xe.color?{backgroundColor:xe.color}:void 0,onClick:pe=>{pe.stopPropagation(),xe.onClick(O),ee(null)},children:xe.label},xe.key))})]},O.key)};return ne?null:e.jsxs("div",{className:`nice-list nice-list--${W} ${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:O=>D(O.target.value),placeholder:m||de("controls.search","Search...")})}),L?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||de("controls.noData","No data available")}):E?e.jsx("div",{role:"listbox",children:Array.from(E.entries()).map(([O,B])=>e.jsxs("div",{className:"nice-list__group",children:[e.jsx("div",{className:"nice-list__group-header",children:O}),e.jsx("ul",{className:"nice-list__items",children:B.map((Y,X)=>le(Y,X))})]},O))}):e.jsx("ul",{className:"nice-list__items",role:"listbox",children:M.map((O,B)=>le(O,B))})]})};function ci(t){const a=[];if(t.children)for(const r of t.children)a.push(r.key),a.push(...ci(r));return a}function In(t,a){if(!t.children||t.children.length===0)return a.has(t.key)?"checked":"unchecked";let r=!0,l=a.has(t.key);for(const d of t.children){const m=In(d,a);m==="checked"?l=!0:(m==="indeterminate"&&(l=!0),r=!1)}return r&&l?"checked":l?"indeterminate":"unchecked"}const oi=({nodes:t,selectedKeys:a=[],expandedKeys:r,onSelectionChange:l,onExpandedChange:d,selectionMode:m="none",showCheckboxes:f,searchable:o,searchPlaceholder:g,onNodeClick:N,renderNode:S,showLines:U,loading:A,className:L,style:P,accessMode:W,id:y,draggable:s,onNodeDrop:w,onLoadChildren:c,contextMenuItems:$,onContextMenuAction:F,editable:ne,onNodeEdit:de,maxDepth:Ae})=>{const D=Q.Cl(W,y)==="hidden",{t:ue}=Q.ue(),[_e,be]=n.useState([]),[ee,ae]=n.useState(""),[M,E]=n.useState(new Set),[_,we]=n.useState(new Map),[le,O]=n.useState(null),[B,Y]=n.useState(null),[X,xe]=n.useState(null),[pe,Re]=n.useState(""),He=n.useRef(null),tt=r??_e,De=n.useMemo(()=>new Set(a),[a]),nt=n.useCallback(async(z,ce)=>{var te;const G=!tt.includes(z),T=G?[...tt,z]:tt.filter(je=>je!==z);if(d?d(T):be(T),G&&c&&!((te=ce.children)!=null&&te.length)&&ce.leaf!==!0&&!_.has(z)){E(V=>new Set(V).add(z));const je=await c(ce);we(V=>new Map(V).set(z,je)),E(V=>{const Ee=new Set(V);return Ee.delete(z),Ee})}},[tt,d,c,_]),Te=n.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 T=ci(ce),te=[z,...T];if(In(ce,De)==="checked")l(a.filter(je=>!te.includes(je)));else{const je=new Set([...a,...te]);l(Array.from(je))}}else l(a.includes(z)?a.filter(T=>T!==z):[...a,z])}},[a,m,l,f,De]),Ke=n.useCallback(z=>{var G;if(!ee)return!0;const ce=ee.toLowerCase();return z.text.toLowerCase().includes(ce)?!0:((G=_.get(z.key)??z.children)==null?void 0:G.some(T=>Ke(T)))??!1},[ee,_]),H=n.useCallback((z,ce)=>{$!=null&&$.length&&(z.preventDefault(),Y({x:z.clientX,y:z.clientY,node:ce}))},[$]),ye=n.useCallback(()=>{X&&de&&de(X,pe),xe(null)},[X,pe,de]),$e=(z,ce)=>{if(ee&&!Ke(z))return null;const G=typeof Ae=="number"?Math.min(10,Math.max(1,Ae)):1/0,T=ce+1>=G,te=T?void 0:_.get(z.key)??z.children,je=!T&&(te&&te.length>0||z.leaf!==!0&&c&&!(te!=null&&te.length)),V=tt.includes(z.key),Ee=De.has(z.key),Se=M.has(z.key),me=f&&m==="multiple"&&(te!=null&&te.length)?In(z,De):Ee?"checked":"unchecked",Ye=Math.min(ce+1,10),ht={paddingLeft:ce*20+4,"--nice-row-bg":`var(--nice-tree-level-${Ye}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${Ye}-text, inherit)`,"--nice-row-border":`var(--nice-tree-level-${Ye}-border, transparent)`,"--nice-row-hover-bg":`var(--nice-tree-level-${Ye}-hover-bg, var(--hover-bg, color-mix(in srgb, var(--text-primary) 6%, transparent)))`,"--nice-row-active-bg":`var(--nice-tree-level-${Ye}-active-bg, color-mix(in srgb, var(--color-primary) 14%, transparent))`};return e.jsxs("li",{className:"nice-tree__node",role:"treeitem","aria-expanded":je?V:void 0,"data-nice-depth":Ye,draggable:s&&!z.disabled,onDragStart:s?ve=>{ve.stopPropagation(),O(z.key)}:void 0,onDragOver:s?ve=>{ve.preventDefault(),ve.stopPropagation()}:void 0,onDrop:s&&le?ve=>{ve.stopPropagation(),w==null||w(le,z.key,"inside"),O(null)}:void 0,onDragEnd:s?()=>O(null):void 0,children:[e.jsxs("div",{className:`nice-tree__row ${Ee?"nice-tree__row--selected":""} ${z.disabled?"nice-tree__row--disabled":""} ${le===z.key?"nice-tree__row--dragging":""}`,style:ht,onClick:()=>{z.disabled||(Te(z.key,z),N==null||N(z))},onContextMenu:ve=>H(ve,z),onDoubleClick:ne&&!z.disabled?()=>{xe(z.key),Re(z.text)}:void 0,children:[e.jsx("span",{className:`nice-tree__toggle ${je?V?"nice-tree__toggle--expanded":"":"nice-tree__toggle--leaf"}`,onClick:ve=>{ve.stopPropagation(),je&&nt(z.key,z)},children:Se?e.jsx("span",{className:"nice-spinner nice-spinner--xs"}):je?V?"▾":"▸":""}),f&&m!=="none"&&e.jsx("input",{type:"checkbox",checked:me==="checked",ref:ve=>{ve&&(ve.indeterminate=me==="indeterminate")},onChange:()=>Te(z.key,z),onClick:ve=>ve.stopPropagation(),tabIndex:-1,className:"nice-tree__checkbox"}),X===z.key?e.jsx("input",{type:"text",className:"nice-tree__edit-input",value:pe,onChange:ve=>Re(ve.target.value),onBlur:ye,onKeyDown:ve=>{ve.key==="Enter"&&ye(),ve.key==="Escape"&&xe(null)},autoFocus:!0,onClick:ve=>ve.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})]})]}),te&&te.length>0&&V&&e.jsx("ul",{className:"nice-tree__children",role:"group",children:te.map(ve=>$e(ve,ce+1))})]},z.key)};return D?null:e.jsxs("div",{className:`nice-tree ${U?"nice-tree--lines":""} ${L||""}`,style:P,ref:He,onClick:()=>Y(null),children:[o&&e.jsx("div",{className:"nice-tree__search",children:e.jsx("input",{type:"text",value:ee,onChange:z=>ae(z.target.value),placeholder:g||ue("controls.search","Search..."),"aria-label":g||ue("controls.search","Search tree")})}),A?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:t.map(z=>$e(z,0))}),B&&$&&e.jsx("div",{className:"nice-tree__context-menu",style:{position:"fixed",top:B.y,left:B.x,zIndex:9999},children:$.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,B.node),Y(null))},children:[z.icon&&e.jsx("span",{children:z.icon}),z.label]},z.key))})]})};function Fi(t,a,r){const l=new Map,d=[];return t.forEach(m=>{const f={...m,children:[]};l.set(String(f[a]),f)}),t.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 di({columns:t,data:a,keyField:r="key",parentKeyField:l="parentKey",expandedKeys:d,onExpandedChange:m,selectedKeys:f=[],onSelectionChange:o,selectable:g,loading:N,emptyText:S,className:U,style:A,accessMode:L,id:P}){const W=Q.Cl(L,P)==="hidden",{t:y}=Q.ue(),[s,w]=n.useState([]),c=d??s,$=n.useMemo(()=>Fi(a,r,l),[a,r,l]),F=n.useMemo(()=>t.filter(D=>!D.hidden),[t]),ne=n.useCallback(D=>{const ue=c.includes(D)?c.filter(_e=>_e!==D):[...c,D];m?m(ue):w(ue)},[c,m]),de=n.useCallback(D=>{o&&o(f.includes(D)?f.filter(ue=>ue!==D):[...f,D])},[f,o]),Ae=(D,ue)=>{const _e=String(D[r]),be=D.children&&D.children.length>0,ee=c.includes(_e),ae=f.includes(_e);return e.jsxs(n.Fragment,{children:[e.jsxs("tr",{className:ae?"nice-treelist__row--selected":"",children:[g&&e.jsx("td",{className:"nice-treelist__checkbox",children:e.jsx("input",{type:"checkbox",checked:ae,onChange:()=>de(_e)})}),F.map((M,E)=>e.jsxs("td",{style:{textAlign:M.align},children:[E===0&&e.jsx("span",{style:{display:"inline-block",width:ue*20}}),E===0&&e.jsx("span",{className:"nice-treelist__toggle",onClick:()=>be&&ne(_e),style:{cursor:be?"pointer":"default",width:20,display:"inline-block"},children:be?ee?"▾":"▸":""}),M.render?M.render(D[M.field],D,0):String(D[M.field]??"")]},M.field))]}),be&&ee&&D.children.map(M=>Ae(M,ue+1))]},_e)};return W?null:e.jsx("div",{className:`nice-treelist ${U||""}`,style:A,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[g&&e.jsx("th",{className:"nice-treelist__checkbox"}),F.map(D=>e.jsx("th",{style:{width:D.width,minWidth:D.minWidth,textAlign:D.align},children:D.header},D.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"}})})}):$.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")})}):$.map(D=>Ae(D,0))})]})})}function ui({items:t,renderCard:a,columns:r=3,gap:l=16,searchable:d,searchField:m="text",searchPlaceholder:f,loading:o,emptyText:g,onCardClick:N,className:S,style:U,accessMode:A,id:L}){const P=Q.Cl(A,L)==="hidden",{t:W}=Q.ue(),[y,s]=n.useState(""),w=n.useMemo(()=>{if(!y)return t;const c=y.toLowerCase();return t.filter($=>String($[m]??"").toLowerCase().includes(c))},[t,y,m]);return P?null:e.jsxs("div",{className:`nice-cardview ${S||""}`,style:U,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||W("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||W("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 mi({items:t,tileWidth:a=180,tileHeight:r=180,direction:l="horizontal",renderTile:d,onTileClick:m,loading:f,emptyText:o,className:g,style:N}){const{t:S}=Q.ue();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"})}):t.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:t.map(U=>e.jsx("div",{className:"nice-tileview__tile",style:{width:a,height:r,cursor:m?"pointer":void 0},onClick:()=>m==null?void 0:m(U),children:d?d(U):e.jsxs(e.Fragment,{children:[U.image&&e.jsx("img",{src:U.image,alt:U.text||"",className:"nice-tileview__image"}),U.text&&e.jsx("div",{className:"nice-tileview__label",children:U.text})]})},U.key))})})}const ei=[{key:"row",label:"Rows"},{key:"column",label:"Columns"},{key:"data",label:"Values"},{key:"filter",label:"Filters"}],$n=({fields:t,onChange:a,className:r,style:l})=>{const d=t.filter(o=>!o.area),m=(o,g)=>{a(t.map(N=>N.field===o?{...N,area:g}:N))},f=o=>{a(t.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:ei.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))})]}),ei.map(o=>{const g=t.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 Pi(t,a){if(t.length===0)return 0;switch(a){case"sum":return t.reduce((r,l)=>r+l,0);case"count":return t.length;case"avg":return t.reduce((r,l)=>r+l,0)/t.length;case"min":return Math.min(...t);case"max":return Math.max(...t);default:return t.reduce((r,l)=>r+l,0)}}function ti(t,a){return[...new Set(t.map(r=>String(r[a]??"")))].sort()}const zn=({data:t,fields:a,onFieldsChange:r,showFieldChooser:l,loading:d,emptyText:m,exportCsv:f,exportFilename:o="pivot-export",onDrillThrough:g,className:N,style:S,accessMode:U,id:A})=>{const L=Q.Cl(U,A)==="hidden",{t:P}=Q.ue(),[W,y]=n.useState(a),[s,w]=n.useState(!1),c=n.useMemo(()=>W.filter(ee=>ee.area==="row"),[W]),$=n.useMemo(()=>W.filter(ee=>ee.area==="column"),[W]),F=n.useMemo(()=>W.filter(ee=>ee.area==="data"),[W]),ne=n.useMemo(()=>c.length===0?["Total"]:ti(t,c[0].field),[t,c]),de=n.useMemo(()=>$.length===0?["Total"]:ti(t,$[0].field),[t,$]),Ae=n.useCallback((ee,ae,M)=>{let E=t;c.length>0&&(E=E.filter(le=>String(le[c[0].field])===ee)),$.length>0&&(E=E.filter(le=>String(le[$[0].field])===ae));const _=E.map(le=>Number(le[M.field])||0),we=Pi(_,M.summaryType||"sum");return M.format?M.format(we):we},[t,c,$]),D=n.useCallback(ee=>{y(ee),r==null||r(ee)},[r]),ue=n.useCallback((ee,ae)=>{let M=t;return c.length>0&&(M=M.filter(E=>String(E[c[0].field])===ee)),$.length>0&&(M=M.filter(E=>String(E[$[0].field])===ae)),M},[t,c,$]),_e=n.useCallback((ee,ae)=>{g&&g(ee,ae,ue(ee,ae))},[g,ue]),be=n.useCallback(()=>{const ee=["",...de.flatMap(le=>F.length>0?F.map(O=>`${le} - ${O.caption}`):[le])],ae=ne.map(le=>{const O=de.flatMap(B=>F.length>0?F.map(Y=>String(Ae(le,B,Y))):["—"]);return[le,...O]}),M=[ee,...ae].map(le=>le.map(O=>`"${String(O).replace(/"/g,'""')}"`).join(",")).join(`
15
+ `),E=new Blob(["\uFEFF"+M],{type:"text/csv;charset=utf-8;"}),_=URL.createObjectURL(E),we=document.createElement("a");we.href=_,we.download=`${o}.csv`,we.click(),URL.revokeObjectURL(_)},[de,ne,F,Ae,o]);return L?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:be,children:"CSV ↓"})]}),s&&e.jsx($n,{fields:W,onChange:D}),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(ee=>ee.caption).join(" / ")||""}),de.map(ee=>e.jsx("th",{colSpan:F.length||1,children:ee},ee))]}),F.length>1&&e.jsxs("tr",{children:[e.jsx("th",{}),de.map(ee=>F.map(ae=>e.jsx("th",{children:ae.caption},`${ee}-${ae.field}`)))]})]}),e.jsx("tbody",{children:ne.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:1+de.length*Math.max(F.length,1),className:"nice-pivotgrid__empty",children:m||P("controls.noData","No data available")})}):ne.map(ee=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-pivotgrid__row-header",children:ee}),de.map(ae=>F.length>0?F.map(M=>e.jsx("td",{className:`nice-pivotgrid__cell ${g?"nice-pivotgrid__cell--clickable":""}`,onClick:g?()=>_e(ee,ae):void 0,children:Ae(ee,ae,M)},`${ae}-${M.field}`)):e.jsx("td",{className:"nice-pivotgrid__cell",children:"—"},ae))]},ee))})]})})]})},Oi=Object.freeze(Object.defineProperty({__proto__:null,NicePivotGrid:zn},Symbol.toStringTag,{value:"Module"})),Rn=n.forwardRef(({columns:t,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:U,collapsedColumns:A,onCollapsedColumnsChange:L,formItems:P,formColumns:W=1,formProps:y,editCardTitle:s,newCardTitle:w,onCardEdit:c,onCardCreate:$,onCardDelete:F,cookies:ne=!1,localStorage:de=!0,sessionStorage:Ae=!1,storageMode:D,storageKey:ue,className:_e,style:be,id:ee,...ae},M)=>{const{t:E}=Q.ue(),[_,we]=n.useState(null),[le,O]=n.useState(null),[B,Y]=n.useState(null),X=!!P&&(!!c||!!$),xe=n.useCallback(T=>{if(X&&c){Y({key:T.key,data:{...T},column:T.column});return}l==null||l(T)},[X,l,c]),pe=n.useCallback(T=>{if(X&&$){Y({key:null,data:{title:"",description:""},column:T});return}m==null||m(T)},[X,m,$]),Re=Q.fa(ue??"nice-kanban"),[He,tt]=n.useState(()=>Re.get("state")??{collapsedColumns:[],viewMode:"default"}),De=A??He.collapsedColumns??[],nt=S??He.viewMode??"default",Te=n.useCallback(T=>{tt(te=>{const je={...te,...T};return Re.set("state",je),je})},[Re]),Ke=n.useCallback(T=>{const te=De.includes(T)?De.filter(je=>je!==T):[...De,T];L?L(te):Te({collapsedColumns:te})},[De,L,Te]);n.useCallback(T=>{U?U(T):Te({viewMode:T})},[U,Te]);const H=n.useCallback(T=>a.filter(te=>te.column===T).sort((te,je)=>(te.order??0)-(je.order??0)),[a]),ye=n.useCallback((T,te)=>{f||(T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",String(te.key)),we({cardKey:te.key,fromColumn:te.column}))},[f]),$e=n.useCallback((T,te)=>{T.preventDefault(),T.dataTransfer.dropEffect="move",O({column:te})},[]),z=n.useCallback(()=>{O(null)},[]),ce=n.useCallback((T,te)=>{if(T.preventDefault(),O(null),!_||f)return;const je=H(te);r==null||r(_.cardKey,te,je.length),we(null)},[_,f,H,r]),G=n.useCallback(()=>{we(null),O(null)},[]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:M,id:ee,className:`nice-kanban nice-kanban--${o} nice-kanban--${nt} nice-kanban--layout-${N} ${f?"nice-kanban--disabled":""} ${_e||""}`,style:be,...ae,children:t.map(T=>{const te=H(T.key),je=(le==null?void 0:le.column)===T.key,V=T.limit!=null&&te.length>=T.limit,Ee=g&&De.includes(T.key);return e.jsxs("div",{className:`nice-kanban__column ${je?"nice-kanban__column--dragover":""} ${Ee?"nice-kanban__column--collapsed":""}`,onDragOver:Se=>!Ee&&$e(Se,T.key),onDragLeave:z,onDrop:Se=>!Ee&&ce(Se,T.key),children:[e.jsxs("div",{className:"nice-kanban__column-header",style:T.color?{borderTopColor:T.color}:void 0,onClick:g?()=>Ke(T.key):void 0,role:g?"button":void 0,tabIndex:g?0:void 0,onKeyDown:g?Se=>{(Se.key==="Enter"||Se.key===" ")&&Ke(T.key)}:void 0,children:[g&&e.jsx("span",{className:"nice-kanban__collapse-icon","aria-hidden":"true",children:"?"}),e.jsx("span",{className:"nice-kanban__column-title",children:T.title}),e.jsxs("span",{className:"nice-kanban__column-count",children:[te.length,T.limit!=null&&` / ${T.limit}`]})]}),!Ee&&e.jsxs("div",{className:"nice-kanban__column-body",children:[te.map(Se=>e.jsx("div",{className:`nice-kanban__card nice-kanban__card--${nt} ${(_==null?void 0:_.cardKey)===Se.key?"nice-kanban__card--dragging":""}`,draggable:!f,onDragStart:me=>ye(me,Se),onDragEnd:G,onClick:()=>xe(Se),role:"article",children:d?d(Se):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"nice-kanban__card-title",children:Se.title}),nt!=="compact"&&Se.description&&e.jsx("div",{className:"nice-kanban__card-desc",children:Se.description})]})},Se.key)),te.length===0&&e.jsx("div",{className:"nice-kanban__empty",children:E("kanban.empty","No cards")})]}),!Ee&&(m||X&&$)&&!V&&e.jsxs("button",{type:"button",className:"nice-kanban__add",onClick:()=>pe(T.key),disabled:f,children:["+ ",E("kanban.addCard","Add card")]})]},T.key)})}),X&&B&&e.jsxs(An,{open:!0,onClose:()=>Y(null),title:B.key==null?w||E("kanban.newCard","New card"):s||E("kanban.editCard","Edit card"),children:[e.jsx(Q.Ga,{items:P,data:B.data,columns:W,...y,onFieldChange:(T,te)=>Y(je=>je&&{...je,data:{...je.data,[T]:te}})}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16,flexWrap:"wrap"},children:[B.key!=null&&F&&e.jsx(Q.pn,{type:"button",size:"sm",variant:"error",style:{marginRight:"auto"},onClick:()=>{F(B.key),Y(null)},children:E("controls.delete","Delete")}),e.jsx(Q.pn,{type:"button",size:"sm",variant:"secondary",onClick:()=>Y(null),children:E("controls.cancel","Cancel")}),e.jsx(Q.pn,{type:"button",size:"sm",variant:"primary",onClick:()=>{if(B.key==null){const T={key:`card-${Date.now()}`,title:"",column:B.column,...B.data};$==null||$(T)}else c==null||c(B.key,{...B.data,key:B.key,column:B.column});Y(null)},children:E("controls.save","Save")})]})]})]})});Rn.displayName="NiceKanbanBoard";function Dt(...t){return t.filter(Boolean).map(a=>typeof a=="object"?Object.entries(a).filter(([,r])=>r).map(([r])=>r).join(" "):a).join(" ")}const Ki=50,Ui=[10,25,50,100,200],Bi=40,Gi=10,Wi=768,Yi=500,Zi=10;function vt(t,a){return a.split(".").reduce((r,l)=>r==null?void 0:r[l],t)}function sn(t,a,r="pl-PL"){var l,d,m;if(t==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(t);case"currency":return new Intl.NumberFormat(r,{style:"currency",currency:a.currencyCode||"PLN"}).format(t);case"percent":return new Intl.NumberFormat(r,{style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}).format(t/100);case"date":return new Intl.DateTimeFormat(r,{dateStyle:"short"}).format(new Date(t));case"datetime":return new Intl.DateTimeFormat(r,{dateStyle:"short",timeStyle:"short"}).format(new Date(t));case"boolean":return t?"✓":"✗";case"enum":return((m=(d=a.enumOptions)==null?void 0:d.find(f=>f.value===t))==null?void 0:m.label)||String(t);default:return String(t)}}function Qi(t,a,r,l){const[d,m]=n.useState(0),{startIndex:f,endIndex:o,totalHeight:g,offsetY:N}=n.useMemo(()=>{const A=t.length*r,L=Math.ceil(a/r),P=Math.max(0,Math.floor(d/r)-l),W=Math.min(t.length,Math.ceil(d/r)+L+l),y=P*r;return{startIndex:P,endIndex:W,totalHeight:A,offsetY:y}},[t.length,a,r,d,l]),S=n.useMemo(()=>t.slice(f,o),[t,f,o]),U=n.useCallback(A=>{m(A.currentTarget.scrollTop)},[]);return{visibleData:S,totalHeight:g,offsetY:N,handleScroll:U,startIndex:f}}function Xi(t,a){const[r,l]=n.useState(()=>{if(t&&typeof window<"u"){const m=localStorage.getItem(`nice-module-grid-${t}`);if(m)return JSON.parse(m)}return a||{}}),d=n.useCallback(m=>{l(f=>{const o={...f,...m};return t&&typeof window<"u"&&localStorage.setItem(`nice-module-grid-${t}`,JSON.stringify(o)),o})},[t]);return[r,d]}function Hi(t){const[a,r]=n.useState(typeof window<"u"&&window.innerWidth<t);return n.useEffect(()=>{if(typeof window>"u")return;const l=()=>r(window.innerWidth<t);return window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[t]),a}function Vi({column:t,sort:a,onSort:r,onResize:l,resizable:d,t:m}){const f=n.useRef(null),[o,g]=n.useState(!1),N=n.useCallback(A=>{if(!d||!l)return;A.preventDefault(),g(!0);const L=A.clientX,P=t.width||150,W=s=>{const w=s.clientX-L,c=Math.max(t.minWidth||50,P+w);l(t.field,Math.min(c,t.maxWidth||1/0))},y=()=>{g(!1),document.removeEventListener("mousemove",W),document.removeEventListener("mouseup",y)};document.addEventListener("mousemove",W),document.addEventListener("mouseup",y)},[t,d,l]),S=a==null?void 0:a.direction,U=S==="asc"?"↑":S==="desc"?"↓":null;return e.jsxs("div",{className:Dt("nice-module-grid__header-cell",t.sortable&&"nice-module-grid__header-cell--sortable",o&&"nice-module-grid__header-cell--resizing"),style:{width:t.width==="auto"?"auto":t.width||150,minWidth:t.minWidth,maxWidth:t.maxWidth,textAlign:t.align},onClick:()=>t.sortable&&(r==null?void 0:r(t.field)),role:"columnheader","aria-sort":S==="asc"?"ascending":S==="desc"?"descending":"none",title:t.headerTooltip,children:[e.jsx("span",{className:"nice-module-grid__header-text",children:t.header}),U&&e.jsx("span",{className:"nice-module-grid__sort-indicator",children:U}),d&&e.jsx("div",{ref:f,className:"nice-module-grid__resize-handle",onMouseDown:N})]})}function qi({column:t,row:a,rowIndex:r,value:l,locale:d="pl-PL",onClick:m}){const f=Q.$l({onClick:m}),o=m?f:{};if(t.render)return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:t.render(l,a,r)});if(t.type==="enum"&&t.enumOptions){const g=t.enumOptions.find(N=>N.value===l);if(g)return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:e.jsxs("span",{className:Dt("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(t.type==="progress"){const g=Math.min(100,Math.max(0,Number(l)||0));return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:e.jsxs("div",{className:"nice-module-grid__progress",children:[e.jsx("div",{className:Dt("nice-module-grid__progress-bar",`nice-module-grid__progress-bar--${t.progressColor||"primary"}`),style:{width:`${g}%`}}),e.jsxs("span",{className:"nice-module-grid__progress-text",children:[g,"%"]})]})})}if(t.type==="rating"){const g=t.maxRating||5,N=Number(l)||0;return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:e.jsx("span",{className:"nice-module-grid__rating","aria-label":`${N} out of ${g} stars`,children:Array.from({length:g},(S,U)=>e.jsx("span",{className:Dt("nice-module-grid__star",U<N&&"nice-module-grid__star--filled"),children:"★"},U))})})}if(t.type==="link"&&t.linkTemplate){const g=t.linkTemplate.replace(/\{\{(\w+)\}\}/g,(N,S)=>String(vt(a,S)??""));return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:e.jsx("a",{href:g,target:t.linkNewTab?"_blank":void 0,rel:t.linkNewTab?"noopener noreferrer":void 0,className:"nice-module-grid__link",children:sn(l,t,d)})})}if(t.type==="image"){const g={xs:24,sm:32,md:48,lg:64}[t.imageSize||"sm"];return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.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 t.type==="avatar"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.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:"?"})}):t.type==="color"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:e.jsx("span",{className:"nice-module-grid__color-swatch",style:{backgroundColor:l||"transparent"},title:l})}):t.type==="boolean"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align||"center"},...o,children:e.jsx("span",{className:Dt("nice-module-grid__boolean",!!l&&"nice-module-grid__boolean--true"),children:l?"✓":"✗"})}):e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...o,children:sn(l,t,d)})}function Ji({row:t,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:Dt("nice-module-grid__mobile-card",f&&"nice-module-grid__mobile-card--selected"),onClick:o,children:m(t,a)});const S=r.find(A=>A.field===l)||r[0],U=r.find(A=>A.field===d)||r[1];return e.jsxs("div",{className:Dt("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:sn(vt(t,(S==null?void 0:S.field)||""),S,g)}),U&&e.jsx("div",{className:"nice-module-grid__mobile-card-subtitle",children:sn(vt(t,U.field),U,g)})]}),e.jsx("div",{className:"nice-module-grid__mobile-card-body",children:r.filter(A=>!A.hidden&&A.field!==l&&A.field!==d).slice(0,4).map(A=>e.jsxs("div",{className:"nice-module-grid__mobile-card-field",children:[e.jsx("span",{className:"nice-module-grid__mobile-card-label",children:A.header}),e.jsx("span",{className:"nice-module-grid__mobile-card-value",children:sn(vt(t,A.field),A,g)})]},A.field))})]})}function ea({page:t,pageSize:a,totalRows:r,pageSizeOptions:l,onPageChange:d,t:m}){const f=Math.ceil(r/a),o=(t-1)*a+1,g=Math.min(t*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:t===1,"aria-label":m("pagination.first","First"),children:"««"}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(t-1,a),disabled:t===1,"aria-label":m("pagination.previous","Previous"),children:"«"}),e.jsxs("span",{className:"nice-module-grid__pagination-page",children:[t," / ",f]}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(t+1,a),disabled:t>=f,"aria-label":m("pagination.next","Next"),children:"»"}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>d(f,a),disabled:t>=f,"aria-label":m("pagination.last","Last"),children:"»»"})]})]})}function ta({columns:t}){return e.jsx("div",{className:"nice-module-grid__row nice-module-grid__row--skeleton",role:"row",children:t.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 na(t,a){var an;const{columns:r,data:l,keyField:d="id",dataSource:m,onFetch:f,sortable:o=!0,sort:g,onSortChange:N,multiSort:S=!1,filterable:U=!1,filter:A,onFilterChange:L,searchText:P,onSearchChange:W,searchPlaceholder:y="moduleGrid.searchPlaceholder",pagination:s=!0,page:w,pageSize:c,pageSizeOptions:$=Ui,totalRows:F,onPageChange:ne,virtualScroll:de=!0,rowHeight:Ae=Bi,overscan:D=Gi,selectionMode:ue="none",selectedKeys:_e,onSelectionChange:be,columnReorder:ee=!0,onColumnOrderChange:ae,columnResize:M=!0,onColumnWidthChange:E,groupBy:_,onGroupByChange:we,groupRowRender:le,expandAllGroups:O=!1,editable:B=!1,onCellEdit:Y,onRowEdit:X,editMode:xe="cell",contextMenuItems:pe,onContextMenuAction:Re,exportable:He=!0,exportFormats:tt=["csv","excel"],onExport:De,preferencesKey:nt,initialPreferences:Te,onPreferencesChange:Ke,density:H="normal",striped:ye=!0,bordered:$e=!1,hoverable:z=!0,loading:ce=!1,emptyState:G,toolbar:T,onRowClick:te,onRowDoubleClick:je,rowClassName:V,rowStyle:Ee,mobileCardView:Se=!0,mobileBreakpoint:me=Wi,mobileCardRender:Ye,mobilePrimaryField:ht,mobileSecondaryField:ve,moduleId:jt,permissions:wt,size:Ve="medium",skeletonLoading:It=!0,skeletonRows:I=Zi,"aria-label":oe,"aria-labelledby":he,"aria-describedby":ke,className:dt,style:Ne,id:Ue,testId:ut}=t,{t:Ge}=Q.ue();Q.Cl(),Q.Us("table");const it=Hi(me),[kt,Bt]=Xi(nt,Te),Gt=n.useRef(null),Vt=n.useRef(null),[Wt,Yt]=n.useState([]),[mt,on]=n.useState(),[qt,Pe]=n.useState(""),[qe,Oe]=n.useState(1),[Ot,At]=n.useState(c||Ki),[Kt,Tt]=n.useState(new Set),[Ut,Zt]=n.useState([]),[u,h]=n.useState(0),[v,K]=n.useState(!1),[q,k]=n.useState(new Set),[R,J]=n.useState(null),[Fe,Le]=n.useState({}),re=g??Wt,Ze=A??mt,rt=P??qt,pt=w??qe,lt=c??Ot,gt=_e??Kt,Jt=F??u??(l==null?void 0:l.length)??0,$t=!!(f||m),Nt=n.useMemo(()=>{const x=new Set(kt.hiddenColumns||[]);return r.filter(se=>!se.hidden&&!x.has(se.field))},[r,kt.hiddenColumns]),zt=n.useMemo(()=>{if($t)return Ut;if(!l)return[];let x=[...l];if(rt){const se=rt.toLowerCase(),fe=r.filter(Me=>Me.searchable!==!1).map(Me=>Me.field);x=x.filter(Me=>fe.some(Ie=>{const Xe=vt(Me,Ie);return String(Xe??"").toLowerCase().includes(se)}))}return re.length>0&&x.sort((se,fe)=>{for(const Me of re){const Ie=vt(se,Me.field),Xe=vt(fe,Me.field),bt=Ie<Xe?-1:Ie>Xe?1:0;if(bt!==0)return Me.direction==="asc"?bt:-bt}return 0}),x},[$t,Ut,l,rt,re,r]),ct=n.useMemo(()=>{if($t||!s)return zt;const x=(pt-1)*lt;return zt.slice(x,x+lt)},[$t,zt,s,pt,lt]),dn=((an=Gt.current)==null?void 0:an.clientHeight)||400,Ct=de&&ct.length>Yi,{visibleData:Et,totalHeight:Lt,offsetY:en,handleScroll:vn,startIndex:tn}=Qi(ct,dn,Ae,D),Rt=Ct?Et:ct,un=n.useCallback(async()=>{if(f){K(!0);try{const x=await f({page:pt,pageSize:lt,sort:re,filter:Ze,search:rt});Zt(x.data),h(x.total)}catch(x){console.error("NiceModuleGrid fetch error:",x)}finally{K(!1)}}},[f,pt,lt,re,Ze,rt]);n.useEffect(()=>{$t&&un()},[$t,un]);const jn=n.useCallback(x=>{const se=re.find(Me=>Me.field===x);let fe;se?se.direction==="asc"?fe=re.map(Me=>Me.field===x?{...Me,direction:"desc"}:Me):fe=re.filter(Me=>Me.field!==x):fe=S?[...re,{field:x,direction:"asc"}]:[{field:x,direction:"asc"}],N?N(fe):Yt(fe)},[re,S,N]),wn=n.useCallback((x,se)=>{ne?ne(x,se):(Oe(x),At(se))},[ne]),En=n.useCallback(x=>{W?W(x):Pe(x),ne||Oe(1)},[W,ne]),mn=n.useCallback((x,se)=>{const fe=new Set(gt);if(ue==="single"?(fe.clear(),fe.add(x)):(ue==="multiple"||ue==="checkbox")&&(fe.has(x)?fe.delete(x):fe.add(x)),be){const Me=ct.filter(Ie=>fe.has(String(vt(Ie,d))));be(fe,Me)}else Tt(fe)},[gt,ue,be,ct,d]),kn=n.useCallback((x,se)=>{Le(fe=>({...fe,[x]:se})),E==null||E(x,se),Bt({columnWidths:{...kt.columnWidths,[x]:se}})},[E,Bt,kt.columnWidths]),hn=n.useCallback((x,se)=>{pe!=null&&pe.length&&(x.preventDefault(),J({x:x.clientX,y:x.clientY,row:se}))},[pe]),Ln=n.useCallback(x=>{R&&(Re==null||Re(x,R.row)),J(null)},[R,Re]),Fn=n.useCallback(async x=>{if(De)await De(x,{selectedOnly:gt.size>0,columns:Nt.map(se=>se.field)});else if(x==="csv"){const se=Nt.map(ot=>ot.header).join(","),fe=ct.map(ot=>Nt.map(pn=>JSON.stringify(vt(ot,pn.field)??"")).join(",")),Me=[se,...fe].join(`
16
+ `),Ie=new Blob([Me],{type:"text/csv;charset=utf-8;"}),Xe=URL.createObjectURL(Ie),bt=document.createElement("a");bt.href=Xe,bt.download=`export-${new Date().toISOString().slice(0,10)}.csv`,bt.click(),URL.revokeObjectURL(Xe)}},[De,gt,Nt,ct,Ge]);n.useEffect(()=>{if(!R)return;const x=()=>J(null);return document.addEventListener("click",x),()=>document.removeEventListener("click",x)},[R]);const nn=n.useCallback(x=>{x.key==="Escape"&&J(null)},[]),Qe=ce||v,st=!Qe&&Rt.length===0,ft=it&&Se,Nn=Dt("nice-module-grid",`nice-module-grid--${H}`,`nice-module-grid--${Ve}`,ye&&"nice-module-grid--striped",$e&&"nice-module-grid--bordered",z&&"nice-module-grid--hoverable",Qe&&"nice-module-grid--loading",ft&&"nice-module-grid--mobile",dt);return e.jsxs("div",{ref:a,id:Ue,"data-testid":ut,className:Nn,style:Ne,onKeyDown:nn,role:"grid","aria-label":oe,"aria-labelledby":he,"aria-describedby":ke,"aria-rowcount":Jt,"aria-colcount":Nt.length,"aria-busy":Qe,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:rt,onChange:x=>En(x.target.value),"aria-label":Ge("moduleGrid.searchAriaLabel","Search")})}),T,He&&e.jsx("div",{className:"nice-module-grid__toolbar-export",children:tt.map(x=>e.jsx("button",{className:"nice-module-grid__export-btn",onClick:()=>Fn(x),"aria-label":Ge(`moduleGrid.export.${x}`,`Export to ${x.toUpperCase()}`),children:x.toUpperCase()},x))})]}),e.jsx("div",{ref:Gt,className:"nice-module-grid__container",onScroll:Ct?vn:void 0,children:ft?e.jsx("div",{className:"nice-module-grid__mobile-list",children:Qe&&It?Array.from({length:I},(x,se)=>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}})]},se)):st?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)||Ge("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]})]}):Rt.map((x,se)=>{const fe=String(vt(x,d));return e.jsx(Ji,{row:x,index:tn+se,columns:Nt,primaryField:ht,secondaryField:ve,customRender:Ye,selected:gt.has(fe),onClick:()=>{ue!=="none"&&mn(fe,x),te==null||te(x,tn+se)},t:Ge},fe)})}):e.jsxs("div",{ref:Vt,className:"nice-module-grid__table",children:[e.jsxs("div",{className:"nice-module-grid__header",role:"row",children:[ue==="checkbox"&&e.jsx("div",{className:"nice-module-grid__header-cell nice-module-grid__header-cell--checkbox",children:e.jsx("input",{type:"checkbox",checked:gt.size>0&&gt.size===Rt.length,onChange:()=>{if(gt.size===Rt.length)be==null||be(new Set,[]),Tt(new Set);else{const x=new Set(Rt.map(se=>String(vt(se,d))));be==null||be(x,Rt),Tt(x)}},"aria-label":Ge("moduleGrid.selectAll","Select all")})}),Nt.map(x=>e.jsx(Vi,{column:{...x,width:Fe[x.field]||x.width},sort:re.find(se=>se.field===x.field),onSort:o?jn:void 0,onResize:M?kn:void 0,resizable:M,t:Ge},x.field))]}),e.jsx("div",{className:"nice-module-grid__body",style:Ct?{height:Lt,position:"relative"}:void 0,children:Qe&&It?Array.from({length:I},(x,se)=>e.jsx(ta,{columns:Nt},se)):st?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)||Ge("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:Ct?{transform:`translateY(${en}px)`}:void 0,children:Rt.map((x,se)=>{const fe=String(vt(x,d)),Me=tn+se,Ie=gt.has(fe),Xe=typeof V=="function"?V(x,Me):V,bt=typeof Ee=="function"?Ee(x,Me):Ee;return e.jsxs("div",{className:Dt("nice-module-grid__row",Ie&&"nice-module-grid__row--selected",Xe),style:{...bt,height:Ae},role:"row","aria-rowindex":Me+1,"aria-selected":Ie,onClick:()=>{ue!=="none"&&mn(fe,x),te==null||te(x,Me)},onDoubleClick:()=>je==null?void 0:je(x,Me),onContextMenu:ot=>hn(ot,x),children:[ue==="checkbox"&&e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--checkbox",children:e.jsx("input",{type:"checkbox",checked:Ie,onChange:()=>mn(fe,x),onClick:ot=>ot.stopPropagation(),"aria-label":Ge("moduleGrid.selectRow","Select row")})}),Nt.map(ot=>e.jsx(qi,{column:{...ot,width:Fe[ot.field]||ot.width},row:x,rowIndex:Me,value:vt(x,ot.field)},ot.field))]},fe)})})})]})}),s&&Jt>0&&e.jsx(ea,{page:pt,pageSize:lt,totalRows:$t?u:zt.length,pageSizeOptions:$,onPageChange:wn,t:Ge}),R&&pe&&e.jsx("div",{className:"nice-module-grid__context-menu",style:{left:R.x,top:R.y},role:"menu",children:pe.filter(x=>typeof x.hidden=="function"?!x.hidden(R.row):!x.hidden).map(x=>{if(x.divider)return e.jsx("div",{className:"nice-module-grid__context-menu-divider"},x.key);const se=typeof x.disabled=="function"?x.disabled(R.row):x.disabled;return e.jsxs("button",{className:Dt("nice-module-grid__context-menu-item",x.danger&&"nice-module-grid__context-menu-item--danger",se&&"nice-module-grid__context-menu-item--disabled"),onClick:()=>{var fe;se||((fe=x.onClick)==null||fe.call(x,R.row),Ln(x.key))},disabled:se,role:"menuitem",children:[x.icon&&e.jsx("span",{className:"nice-module-grid__context-menu-icon",children:x.icon}),x.label]},x.key)})}),Qe&&!It&&e.jsx("div",{className:"nice-module-grid__loading-overlay",children:e.jsx("div",{className:"nice-module-grid__spinner","aria-label":Ge("moduleGrid.loading","Loading")})})]})}n.forwardRef(na);const ia=`
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 Mt(t,a="PLN",r="pl-PL"){return new Intl.NumberFormat(r,{style:"currency",currency:a,minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function yn(t,a="pl-PL"){return t?(typeof t=="string"?new Date(t):t).toLocaleDateString(a,{year:"numeric",month:"2-digit",day:"2-digit"}):"-"}function aa(t){return t>=80?"high":t>=50?"medium":"low"}function ra(){return`match-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function la({item:t,isSelected:a,isDragging:r,isDropTarget:l,suggestion:d,currency:m,locale:f,onSelect:o,onDoubleClick:g,onDragStart:N,onDragEnd:S,onDrop:U,disabled:A}){const L=t.status??"unmatched",P=(d==null?void 0:d.confidence)??t.confidence,W=s=>{s.dataTransfer.setData("text/plain",t.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--${L} ${a?"nice-reconciliation__row--selected":""} ${r?"nice-reconciliation__row--dragging":""} ${l?"nice-reconciliation__row--drop-target":""}`,draggable:!A&&L!=="matched",onDragStart:W,onDragEnd:S,onDragOver:y,onDrop:U,onClick:o,onDoubleClick:g,role:"row","aria-selected":a,tabIndex:0,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${L}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsx("div",{className:"nice-reconciliation__row-date",children:yn(t.date,f)}),e.jsx("div",{className:"nice-reconciliation__row-description",title:t.description,children:t.description}),t.counterparty&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:t.counterparty})]}),P!=null&&e.jsxs("span",{className:`nice-reconciliation__confidence nice-reconciliation__confidence--${aa(P)}`,children:[P,"%"]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Mt(t.amount,m,f)})]})}function sa({item:t,isSelected:a,isDragging:r,isDropTarget:l,currency:d,locale:m,onSelect:f,onDoubleClick:o,onDragStart:g,onDragEnd:N,onDrop:S,disabled:U}){const A=t.status??"unmatched",L=W=>{W.dataTransfer.setData("text/plain",t.id),W.dataTransfer.setData("source","entry"),W.dataTransfer.effectAllowed="move",g()},P=W=>{W.dataTransfer.types.includes("source")&&W.dataTransfer.getData("source")!=="entry"&&W.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${A} ${a?"nice-reconciliation__row--selected":""} ${r?"nice-reconciliation__row--dragging":""} ${l?"nice-reconciliation__row--drop-target":""}`,draggable:!U&&A!=="matched",onDragStart:L,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--${A}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsxs("div",{className:"nice-reconciliation__row-date",children:[yn(t.date,m),t.documentNumber&&e.jsxs("span",{children:[" · ",t.documentNumber]})]}),e.jsx("div",{className:"nice-reconciliation__row-description",title:t.description,children:t.description}),t.partyName&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:t.partyName})]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Mt(t.amount,d,m)})]})}n.forwardRef(function(t,a){const{statements:r,bankTransactions:l,entries:d,accountingEntries:m,matches:f,defaultMatches:o=[],suggestions:g=[],config:N={},currency:S,showConfidence:U,statementPanelConfig:A,entryPanelConfig:L,onMatch:P,onAutoMatch:W,onUnmatch:y,onBatchAction:s,onFilterChange:w,onRequestSuggestions:c,onSelectionChange:$,onComplete:F,size:ne="medium",showToolbar:de=!0,showFilters:Ae=!0,showSummary:D=!0,showSuggestions:ue=!0,layout:_e="horizontal",enableDragDrop:be=!0,enableKeyboard:ee=!0,enableDetailPanel:ae=!0,loading:M=!1,disabled:E=!1,readOnly:_=!1,locale:we="pl-PL",labels:le={},className:O,style:B}=t,Y=r??l??[],X=d??m??[],xe=S??N.currency??"PLN",[pe,Re]=n.useState(o),[He,tt]=n.useState(new Set),[De,nt]=n.useState(new Set),[Te,Ke]=n.useState(null),[H,ye]=n.useState(null),[$e,z]=n.useState({}),[ce,G]=n.useState(null),T=f??pe,te=n.useRef(null),je=n.useRef(null);n.useEffect(()=>{const I="nice-reconciliation-styles";if(!document.getElementById(I)){const oe=document.createElement("style");oe.id=I,oe.textContent=ia,document.head.appendChild(oe)}},[]);const V=n.useMemo(()=>{const I=new Set;return T.forEach(oe=>oe.statementIds.forEach(he=>I.add(he))),I},[T]),Ee=n.useMemo(()=>{const I=new Set;return T.forEach(oe=>oe.entryIds.forEach(he=>I.add(he))),I},[T]),Se=n.useMemo(()=>{const I=Y.filter(Ne=>!V.has(Ne.id)),oe=X.filter(Ne=>!Ee.has(Ne.id)),he=Y.reduce((Ne,Ue)=>Ne+Ue.amount,0),ke=X.reduce((Ne,Ue)=>Ne+Ue.amount,0),dt=Y.filter(Ne=>V.has(Ne.id)).reduce((Ne,Ue)=>Ne+Ue.amount,0);return{totalStatements:Y.length,totalEntries:X.length,matchedStatements:Y.length-I.length,matchedEntries:X.length-oe.length,unmatchedStatements:I.length,unmatchedEntries:oe.length,statementTotal:he,entryTotal:ke,matchedAmount:dt,unmatchedStatementAmount:I.reduce((Ne,Ue)=>Ne+Ue.amount,0),unmatchedEntryAmount:oe.reduce((Ne,Ue)=>Ne+Ue.amount,0),difference:he-ke,matchPercentage:Y.length>0?Math.round((Y.length-I.length)/Y.length*100):0,matchCount:T.length,partialMatchCount:T.filter(Ne=>Ne.status==="partial").length,pendingSuggestions:g.length}},[Y,X,T,g,V,Ee]),me=n.useCallback((I,oe)=>{const he=Y.filter(it=>I.includes(it.id)),ke=X.filter(it=>oe.includes(it.id));if(he.length===0||ke.length===0)return null;const dt=he.reduce((it,kt)=>it+kt.amount,0),Ne=ke.reduce((it,kt)=>it+kt.amount,0),Ue=Math.abs(dt-Ne),ut=N.amountTolerance??.01,Ge={id:ra(),statementIds:I,entryIds:oe,status:Ue<=ut?"matched":"partial",statementTotal:dt,entryTotal:Ne,difference:Ue,confidence:Ue<=ut?100:Math.max(0,100-Ue/Math.max(Math.abs(dt),1)*100),matchedBy:"user",matchedAt:new Date};return f||Re(it=>[...it,Ge]),P==null||P(Ge,he,ke),tt(new Set),nt(new Set),Ge},[Y,X,N.amountTolerance,f,P]),Ye=n.useCallback(I=>{const oe=T.find(he=>he.id===I);oe&&(f||Re(he=>he.filter(ke=>ke.id!==I)),y==null||y(I,oe.statementIds,oe.entryIds))},[T,f,y]),ht=n.useCallback(async()=>{const I=[],oe=new Set(V),he=new Set(Ee),ke=N.amountTolerance??.01,dt=N.dateTolerance??3;for(const Ne of Y){if(oe.has(Ne.id))continue;const Ue=X.filter(ut=>{if(he.has(ut.id)||Math.abs(Ne.amount-ut.amount)>ke)return!1;const Ge=new Date(Ne.date),it=new Date(ut.date);return!(Math.abs(Ge.getTime()-it.getTime())/(1e3*60*60*24)>dt)});if(Ue.length===1){const ut=Ue[0],Ge=me([Ne.id],[ut.id]);Ge&&(I.push(Ge),oe.add(Ne.id),he.add(ut.id))}}return s==null||s("autoMatch",I),I},[Y,X,V,Ee,N,me,s]),ve=n.useCallback((I,oe,he,ke)=>{ke!==oe&&(ke==="statement"?me([he],[I]):me([I],[he]),Ke(null),ye(null))},[me]),jt=n.useCallback(()=>{const I=Array.from(He),oe=Array.from(De);I.length>0&&oe.length>0&&me(I,oe)},[He,De,me]);n.useEffect(()=>{$==null||$(Array.from(He),Array.from(De))},[He,De,$]),n.useImperativeHandle(a,()=>({getMatches:()=>T,getUnmatchedStatements:()=>Y.filter(I=>!V.has(I.id)),getUnmatchedEntries:()=>X.filter(I=>!Ee.has(I.id)),createMatch:me,removeMatch:Ye,autoMatch:ht,getSuggestions:async I=>c?c(I??Y.filter(oe=>!V.has(oe.id)).map(oe=>oe.id)):[],applySuggestion:I=>me([I.statementId],I.entryIds),approveAll:()=>{s==null||s("approveAll",T)},clearAll:()=>{f||Re([]),s==null||s("clearAll",[])},exportMatched:I=>{s==null||s("exportMatched",T)},getSummary:()=>Se,reset:()=>{f||Re([]),tt(new Set),nt(new Set),z({})},focusStatements:()=>{var I;return(I=te.current)==null?void 0:I.focus()},focusEntries:()=>{var I;return(I=je.current)==null?void 0:I.focus()}}),[T,Y,X,V,Ee,me,Ye,ht,c,s,f,Se]);const wt=n.useMemo(()=>Y.filter(I=>{var oe,he;if($e.status&&$e.status.length>0){const ke=V.has(I.id)?"matched":"unmatched";if(!$e.status.includes(ke))return!1}if($e.searchText){const ke=$e.searchText.toLowerCase();if(!((oe=I.description)!=null&&oe.toLowerCase().includes(ke))&&!((he=I.counterparty)!=null&&he.toLowerCase().includes(ke)))return!1}return!0}),[Y,$e,V]),Ve=n.useMemo(()=>X.filter(I=>{var oe,he;if($e.status&&$e.status.length>0){const ke=Ee.has(I.id)?"matched":"unmatched";if(!$e.status.includes(ke))return!1}if($e.searchText){const ke=$e.searchText.toLowerCase();if(!((oe=I.description)!=null&&oe.toLowerCase().includes(ke))&&!((he=I.partyName)!=null&&he.toLowerCase().includes(ke)))return!1}return!0}),[X,$e,Ee]),It=He.size>0&&De.size>0&&!_&&!E;return e.jsxs("div",{className:`nice-reconciliation nice-reconciliation--${_e} ${O??""}`,style:B,children:[de&&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:ht,disabled:E||_||M,children:["⚡ ",le.autoMatch??"Auto-match"]}),e.jsx("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--success",onClick:jt,disabled:!It||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",T),disabled:T.length===0||E||M,children:["✓ ",le.approveAll??"Approve All"]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>{f||Re([]),s==null||s("clearAll",[])},disabled:T.length===0||E||_||M,children:["✕ ",le.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:["📄 ",le.statementPanelTitle??"Bank Statement",e.jsx("span",{className:"nice-reconciliation__panel-badge",children:wt.length})]})}),e.jsx("div",{ref:te,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:wt.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:"📋"}),le.noStatements??"No statement items"]}):wt.map(I=>e.jsx(la,{item:{...I,status:V.has(I.id)?"matched":"unmatched"},isSelected:He.has(I.id),isDragging:Te===I.id,isDropTarget:H===I.id,suggestion:g.find(oe=>oe.statementId===I.id),currency:xe,locale:we,onSelect:()=>{E||tt(oe=>{const he=new Set(oe);return he.has(I.id)?he.delete(I.id):he.add(I.id),he})},onDoubleClick:()=>ae&&G({type:"statement",id:I.id}),onDragStart:()=>Ke(I.id),onDragEnd:()=>{Ke(null),ye(null)},onDrop:()=>{Te&&Te!==I.id&&ve(I.id,"statement",Te,"entry")},disabled:E||_||!be},I.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:["📒 ",le.entryPanelTitle??"Book Entries",e.jsx("span",{className:"nice-reconciliation__panel-badge",children:Ve.length})]})}),e.jsx("div",{ref:je,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:Ve.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:"📚"}),le.noEntries??"No book entries"]}):Ve.map(I=>e.jsx(sa,{item:{...I,status:Ee.has(I.id)?"matched":"unmatched"},isSelected:De.has(I.id),isDragging:Te===I.id,isDropTarget:H===I.id,currency:xe,locale:we,onSelect:()=>{E||nt(oe=>{const he=new Set(oe);return he.has(I.id)?he.delete(I.id):he.add(I.id),he})},onDoubleClick:()=>ae&&G({type:"entry",id:I.id}),onDragStart:()=>Ke(I.id),onDragEnd:()=>{Ke(null),ye(null)},onDrop:()=>{Te&&Te!==I.id&&ve(I.id,"entry",Te,"statement")},disabled:E||_||!be},I.id))})]})]}),D&&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:[Se.matchedStatements,"/",Se.totalStatements," (",Se.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:Mt(Se.matchedAmount,xe,we)})]}),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:Mt(Se.unmatchedStatementAmount,xe,we)})]}),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(Se.difference)<.01?"nice-reconciliation__summary-value--success":"nice-reconciliation__summary-value--danger"}`,children:Mt(Se.difference,xe,we)})]})]}),ae&&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(ca,{type:ce.type,id:ce.id,statements:Y,entries:X,matches:T,currency:xe,locale:we,labels:le,onClose:()=>G(null)})})]})]})});function ca({type:t,id:a,statements:r,entries:l,matches:d,currency:m,locale:f,labels:o,onClose:g}){var W;const N=t==="statement"?r.find(y=>y.id===a):l.find(y=>y.id===a),S=t==="statement"?d.find(y=>y.statementIds.includes(a)):d.find(y=>y.entryIds.includes(a)),U=S?t==="statement"?l.filter(y=>S.entryIds.includes(y.id)):r.filter(y=>S.statementIds.includes(y.id)):[];if(!N)return null;const A=t==="statement",L=A?N:null,P=A?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:[A?"📄":"📒"," ",A?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"," (",((W=S.confidence)==null?void 0:W.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:Mt(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:Mt(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:Mt(S.difference,m,f)})]})]}),e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:["📋"," ",A?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:yn(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:Mt(N.amount,m,f)})]}),A&&(L==null?void 0:L.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:L.counterparty})]}),A&&(L==null?void 0:L.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:L.counterpartyAccount})]}),!A&&(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})]}),!A&&(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})]}),A&&(L==null?void 0:L.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:L.referenceNumber})]})]}),U.length>0&&e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:["🔗"," ",A?o.matchedEntries??"Matched Entries":o.matchedStatements??"Matched Statements"]}),U.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:yn(y.date,f)}),e.jsx("span",{style:{fontWeight:600,color:y.amount>=0?"var(--nice-success)":"var(--nice-danger)"},children:Mt(y.amount,m,f)})]})]},y.id))]})]})]})}function oa(t,a,r){const l=new Map,d=[];t.forEach(f=>l.set(String(f[a]),{data:f,children:[],key:String(f[a]),depth:0})),t.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 hi(t,a,r,l=0){return t.map(d=>({data:d,key:String(d[r]),depth:l,children:Array.isArray(d[a])?hi(d[a],a,r,l+1):[]}))}function da(t){const a=[],r=l=>{l.forEach(d=>{a.push(d.key),r(d.children)})};return r(t),a}function ua(t,a){const r=[],l=d=>{d.forEach(m=>{r.push(m),m.children.length>0&&a.has(m.key)&&l(m.children)})};return l(t),r}function pi(t,a,r){return!a||!r?t:[...t].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:pi(l.children,a,r)}))}function gi({columns:t,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:U,onSort:A,selectable:L,selectedKeys:P,onSelectionChange:W,searchable:y,searchPlaceholder:s,striped:w,compact:c,loading:$,emptyText:F,toolbar:ne,onRowClick:de,className:Ae,style:D}){const{t:ue}=Q.ue(),_e=n.useMemo(()=>d?hi(a,m,r):oa(a,r,l),[a,r,l,d,m]),be=n.useMemo(()=>da(_e),[_e]),[ee,ae]=n.useState(()=>g?new Set(be):new Set),M=f?new Set(f):ee,[E,_]=n.useState({field:"",dir:null}),[we,le]=n.useState(new Set),[O,B]=n.useState(""),Y=S??E.field,X=U??E.dir,xe=P??we,pe=n.useMemo(()=>t.filter(H=>!H.hidden),[t]),Re=n.useCallback(H=>{const ye=Y===H?X==="asc"?"desc":X==="desc"?null:"asc":"asc";A?A(H,ye):_({field:H,dir:ye})},[Y,X,A]),He=n.useCallback(H=>{const ye=new Set(M);ye.has(H)?ye.delete(H):ye.add(H),o?o([...ye]):ae(ye)},[M,o]),tt=n.useCallback(H=>{const ye=new Set(xe);ye.has(H)?ye.delete(H):ye.add(H),W?W(ye):le(ye)},[xe,W]),De=n.useMemo(()=>{if(!O)return _e;const H=O.toLowerCase(),ye=$e=>$e.reduce((z,ce)=>{const G=ye(ce.children);return(pe.some(T=>String(ce.data[T.field]??"").toLowerCase().includes(H))||G.length>0)&&z.push({...ce,children:G}),z},[]);return ye(_e)},[_e,O,pe]),nt=n.useMemo(()=>pi(De,Y,X),[De,Y,X]),Te=n.useMemo(()=>ua(nt,M),[nt,M]),Ke=({field:H})=>Y!==H||!X?e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:.3},children:"↕"}):e.jsx("span",{className:"nice-table__sort-icon",children:X==="asc"?"↑":"↓"});return e.jsxs("div",{className:`nice-treegrid nice-datagrid ${Ae||""}`,style:D,children:[(y||ne)&&e.jsxs("div",{className:"nice-datagrid__toolbar",children:[y&&e.jsx("div",{className:"nice-datagrid__search",children:e.jsx("input",{type:"text",value:O,onChange:H=>B(H.target.value),placeholder:s||ue("controls.search","Search...")})}),ne]}),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:[L&&e.jsx("th",{className:"nice-datagrid__checkbox",style:{width:36}}),pe.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&&Re(H.field),children:[H.header,N&&H.sortable!==!1&&e.jsx(Ke,{field:H.field})]},H.field))]})}),e.jsx("tbody",{children:$?e.jsx("tr",{children:e.jsx("td",{colSpan:pe.length+(L?1:0),className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):Te.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:pe.length+(L?1:0),className:"nice-datagrid__empty",children:F||ue("controls.noData","No data available")})}):Te.map((H,ye)=>{const $e=xe.has(H.key),z=H.children.length>0,ce=M.has(H.key);return e.jsxs("tr",{className:$e?"nice-datagrid__row--selected":void 0,onClick:()=>de==null?void 0:de(H.data),style:de?{cursor:"pointer"}:void 0,children:[L&&e.jsx("td",{className:"nice-datagrid__checkbox",onClick:G=>G.stopPropagation(),children:e.jsx("input",{type:"checkbox",checked:$e,onChange:()=>tt(H.key),"aria-label":`Select row ${H.key}`})}),pe.map((G,T)=>e.jsxs("td",{style:{textAlign:G.align},children:[T===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:te=>{te.stopPropagation(),z&&He(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,ye):String(H.data[G.field]??"")]},G.field))]},H.key)})})]})})]})}function fi(t){let a="",r=t;for(;r>=0;)a=String.fromCharCode(65+r%26)+a,r=Math.floor(r/26)-1;return a}function ze(t,a){return`${fi(a)}${t+1}`}function at(t){const a=t.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 ma(t,a,r=new Set){const l=t.startsWith("=")?t.slice(1).trim():t,d=(y,s)=>{if(!y||!s)return[];const w=[];for(let c=y.row;c<=s.row;c++)for(let $=y.col;$<=s.col;$++){const F=et(ze(c,$),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 $=y.col;$<=s.col;$++)w.push(et(ze(c,$),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=at(f[2].toUpperCase()),w=at(f[3].toUpperCase());switch(y){case"SUM":return d(s,w).reduce((c,$)=>c+$,0);case"AVG":case"AVERAGE":{const c=d(s,w);return c.length>0?c.reduce(($,F)=>$+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,ne)=>F-ne);if(!c.length)return 0;const $=Math.floor(c.length/2);return c.length%2?c[$]:(c[$-1]+c[$])/2}case"STDEV":{const c=d(s,w);if(c.length<2)return 0;const $=c.reduce((F,ne)=>F+ne,0)/c.length;return Math.sqrt(c.reduce((F,ne)=>F+(ne-$)**2,0)/(c.length-1))}case"PRODUCT":{const c=d(s,w);return c.length?c.reduce(($,F)=>$*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=at(o[2].toUpperCase()),w=at(o[3].toUpperCase()),c=o[4];if(s&&w){let $=0;for(let F=s.row;F<=w.row;F++)for(let ne=s.col;ne<=w.col;ne++){const de=et(ze(F,ne),a,new Set(r));(c.startsWith(">")?Number(de)>Number(c.slice(1)):c.startsWith("<")?Number(de)<Number(c.slice(1)):String(de)===c||typeof de=="number"&&de===Number(c))&&($+=y==="SUMIF"?typeof de=="number"?de:0:1)}return $}}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 $=!1;if(c){const de=et(c[1].toUpperCase(),a,new Set(r)),Ae=isNaN(Number(c[3]))?c[3].replace(/^"|"$/g,""):Number(c[3]),D=c[2],ue=typeof de=="number"?de:Number(de)||0,_e=typeof Ae=="number"?Ae:Number(Ae)||0;switch(D){case">":$=ue>_e;break;case"<":$=ue<_e;break;case">=":$=ue>=_e;break;case"<=":$=ue<=_e;break;case"=":case"==":$=ue===_e;break;case"<>":case"!=":$=ue!==_e;break}}const F=$?s:w;if(at(F.toUpperCase()))return et(F.toUpperCase(),a,new Set(r));const ne=Number(F);return isNaN(ne)?F.replace(/^"|"$/g,""):ne}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(at(y.toUpperCase())){const s=et(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;at(S[1].trim().toUpperCase())?y=et(S[1].trim().toUpperCase(),a,new Set(r)):y=isNaN(Number(S[1]))?S[1].replace(/^"|"$/g,""):Number(S[1]);const s=at(S[2].toUpperCase()),w=at(S[3].toUpperCase()),c=parseInt(S[4])-1;if(s&&w)for(let $=s.row;$<=w.row;$++){const F=et(ze($,s.col),a,new Set(r));if(String(F)===String(y))return et(ze($,s.col+c),a,new Set(r))}return null}const U=l.match(/^(ABS|ROUND|FLOOR|CEIL|CEILING|SQRT|LEN|UPPER|LOWER|TRIM|INT)\(([^)]+)\)$/i);if(U){const y=U[1].toUpperCase(),s=U[2].trim();let w;switch(at(s.toUpperCase())?w=et(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 A=l.match(/^POWER\(([^,]+),\s*([^)]+)\)$/i);if(A){const y=Number(at(A[1].trim().toUpperCase())?et(A[1].trim().toUpperCase(),a,new Set(r)):A[1].trim())||0,s=Number(at(A[2].trim().toUpperCase())?et(A[2].trim().toUpperCase(),a,new Set(r)):A[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 L=l.match(/^([A-Z]+\d+)$/i);if(L)return et(L[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=et(y,a,r),$=at(w.toUpperCase())?et(w.toUpperCase(),a,r):parseFloat(w),F=typeof c=="number"?c:0,ne=typeof $=="number"?$:0;switch(s){case"+":return F+ne;case"-":return F-ne;case"*":return F*ne;case"/":return ne!==0?F/ne:null}}const W=parseFloat(l);return isNaN(W)?l:W}function et(t,a,r){if(r.has(t))return null;r.add(t);const l=a[t];return l?l.formula?ma(l.formula,a,r):l.value:null}function ni(t,a){return t==null?"":a==="percent"&&typeof t=="number"?`${(t*100).toFixed(1)}%`:a==="currency"&&typeof t=="number"?`$${t.toFixed(2)}`:String(t)}function ii(t){return{name:t,data:{}}}const Tn=n.forwardRef(({sheets:t,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:U,onPaste:A,onInsert:L,onRemove:P,maxUndo:W=50,sortable:y=!1,filterable:s=!1,rangeSelection:w=!0,className:c,style:$,id:F,...ne},de)=>{var At,Kt,Tt,Ut,Zt;const Ae=Q.nl(F),{t:D}=Q.ue(),[ue,_e]=n.useState(()=>t??[ii(D("spreadsheet.sheet","Sheet")+" 1")]),[be,ee]=n.useState(0),ae=t??ue,M=a??be,E=ae[M]??ae[0],[_,we]=n.useState(null),[le,O]=n.useState(null),[B,Y]=n.useState(!1),[X,xe]=n.useState(null),[pe,Re]=n.useState(""),He=n.useRef(null),tt=n.useRef(null),[De,nt]=n.useState([]),[Te,Ke]=n.useState([]),[H,ye]=n.useState(null),$e=n.useRef({x:0,width:80}),[z,ce]=n.useState(null),[G,T]=n.useState(null),[te,je]=n.useState("");n.useEffect(()=>{X&&He.current&&He.current.focus()},[X]);const V=n.useMemo(()=>{if(!_)return null;const u=le??_;return{startRow:Math.min(_.row,u.row),startCol:Math.min(_.col,u.col),endRow:Math.max(_.row,u.row),endCol:Math.max(_.col,u.col)}},[_,le]),Ee=n.useCallback((u,h)=>V?u>=V.startRow&&u<=V.endRow&&h>=V.startCol&&h<=V.endCol:!1,[V]),Se=n.useCallback(u=>{nt(h=>{const v=[...h,u.map(K=>({...K,data:{...K.data}}))];return v.length>W?v.slice(-W):v}),Ke([])},[W]),me=n.useCallback((u,h=!0)=>{h&&Se(ae);const v=u(ae);t||_e(v),g==null||g(v)},[ae,t,g,Se]),Ye=n.useCallback(()=>{if(De.length===0)return;const u=De[De.length-1];Ke(h=>[...h,ae.map(v=>({...v,data:{...v.data}}))]),nt(h=>h.slice(0,-1)),t||_e(u),g==null||g(u)},[De,ae,t,g]),ht=n.useCallback(()=>{if(Te.length===0)return;const u=Te[Te.length-1];nt(h=>[...h,ae.map(v=>({...v,data:{...v.data}}))]),Ke(h=>h.slice(0,-1)),t||_e(u),g==null||g(u)},[Te,ae,t,g]),ve=n.useCallback(u=>{a||ee(u),N==null||N(u),we(null),O(null),xe(null)},[a,N]),jt=n.useCallback((u,h,v)=>{const K=ze(u,h);me(q=>{const k=q.map((J,Fe)=>Fe===M?{...J,data:{...J.data}}:J),R=v.startsWith("=");return k[M].data[K]={...k[M].data[K]??{value:null},formula:R?v:void 0,value:R?null:isNaN(Number(v))?v:Number(v)},k})},[M,me]),wt=n.useCallback((u,h,v)=>{v!=null&&v.shiftKey&&w&&_?O({row:u,col:h}):(we({row:u,col:h}),O(null)),xe(null),S==null||S(M,u,h)},[M,S,w,_]),Ve=n.useCallback((u,h,v)=>{v.button===0&&(wt(u,h,v),w&&!v.shiftKey&&Y(!0))},[wt,w]),It=n.useCallback((u,h)=>{B&&O({row:u,col:h})},[B]);n.useEffect(()=>{if(!B)return;const u=()=>Y(!1);return document.addEventListener("mouseup",u),()=>document.removeEventListener("mouseup",u)},[B]);const I=n.useCallback((u,h)=>{if(o)return;const v=ze(u,h),K=E.data[v];K!=null&&K.readOnly||(xe({row:u,col:h}),Re((K==null?void 0:K.formula)??((K==null?void 0:K.value)!=null?String(K.value):"")))},[o,E.data]),oe=n.useCallback(()=>{X&&(jt(X.row,X.col,pe),xe(null))},[X,pe,jt]),he=n.useCallback(u=>{if(u.key==="Enter")oe();else if(u.key==="Escape")xe(null);else if(u.key==="Tab"&&(u.preventDefault(),oe(),_)){const h=u.shiftKey?Math.max(0,_.col-1):Math.min(l-1,_.col+1);we({row:_.row,col:h})}},[oe,_,l]),ke=n.useCallback((u,h)=>{if(!_)return;const v=V??{startRow:_.row,startCol:_.col,endRow:_.row,endCol:_.col};me(K=>{const q=K.map((k,R)=>R===M?{...k,data:{...k.data}}:k);for(let k=v.startRow;k<=v.endRow;k++)for(let R=v.startCol;R<=v.endCol;R++){const J=ze(k,R);q[M].data[J]={...q[M].data[J]??{value:null},[u]:h}}return q})},[_,V,M,me]),dt=n.useCallback(u=>{if(!V||(U==null?void 0:U(V))===!1)return;const{startRow:h,startCol:v,endRow:K,endCol:q}=V,k=[];for(let R=h;R<=K;R++){const J=[];for(let Fe=v;Fe<=q;Fe++){const Le=ze(R,Fe),re=E.data[Le],Ze=re?et(Le,E.data,new Set):null;J.push(ni(Ze,re==null?void 0:re.format))}k.push(J.join(" "))}u.clipboardData.setData("text/plain",k.join(`
595
+ `)),u.preventDefault()},[V,E.data,U]),Ne=n.useCallback(u=>{if(o||!_)return;const h=u.clipboardData.getData("text/plain");if(!h)return;const v=h.split(`
596
+ `).map(K=>K.split(" "));(A==null?void 0:A(v,_.row,_.col))!==!1&&(me(K=>{const q=K.map((k,R)=>R===M?{...k,data:{...k.data}}:k);return v.forEach((k,R)=>{k.forEach((J,Fe)=>{const Le=ze(_.row+R,_.col+Fe),re=J.startsWith("=");q[M].data[Le]={...q[M].data[Le]??{value:null},formula:re?J:void 0,value:re?null:isNaN(Number(J))?J:Number(J)}})}),q}),u.preventDefault())},[o,_,M,me,A]),Ue=n.useCallback(u=>{me(h=>h.map((v,K)=>{if(K!==M)return v;const q={};for(const[k,R]of Object.entries(v.data)){const J=at(k);J&&(J.row>u?q[ze(J.row+1,J.col)]=R:q[k]=R)}return{...v,data:q}})),L==null||L("row",u)},[M,me,L]),ut=n.useCallback(u=>{me(h=>h.map((v,K)=>{if(K!==M)return v;const q={};for(const[k,R]of Object.entries(v.data)){const J=at(k);J&&(J.col>u?q[ze(J.row,J.col+1)]=R:q[k]=R)}return{...v,data:q}})),L==null||L("column",u)},[M,me,L]),Ge=n.useCallback(u=>{me(h=>h.map((v,K)=>{if(K!==M)return v;const q={};for(const[k,R]of Object.entries(v.data)){const J=at(k);J&&J.row!==u&&(J.row>u?q[ze(J.row-1,J.col)]=R:q[k]=R)}return{...v,data:q}})),P==null||P("row",u)},[M,me,P]),it=n.useCallback(u=>{me(h=>h.map((v,K)=>{if(K!==M)return v;const q={};for(const[k,R]of Object.entries(v.data)){const J=at(k);J&&J.col!==u&&(J.col>u?q[ze(J.row,J.col-1)]=R:q[k]=R)}return{...v,data:q}})),P==null||P("column",u)},[M,me,P]),kt=n.useCallback((u,h)=>{me(v=>v.map((K,q)=>{if(q!==M)return K;const k=new Map;for(const[Fe,Le]of Object.entries(K.data)){const re=at(Fe);re&&(k.has(re.row)||k.set(re.row,{}),k.get(re.row)[re.col]=Le)}const R=Array.from(k.entries()).sort((Fe,Le)=>{const re=et(ze(Fe[0],u),K.data,new Set),Ze=et(ze(Le[0],u),K.data,new Set),rt=typeof re=="number"?re:Number(re),pt=typeof Ze=="number"?Ze:Number(Ze);if(!isNaN(rt)&&!isNaN(pt))return h==="asc"?rt-pt:pt-rt;const lt=String(re??""),gt=String(Ze??"");return h==="asc"?lt.localeCompare(gt):gt.localeCompare(lt)}),J={};return R.forEach(([,Fe],Le)=>{for(const[re,Ze]of Object.entries(Fe))J[ze(Le,Number(re))]=Ze}),{...K,data:J,sortColumn:u,sortDirection:h}}))},[M,me]),Bt=n.useCallback((u,h)=>{const v=E.conditionalFormats;if(!(v!=null&&v.length))return;const K=ze(u,h),q=et(K,E.data,new Set),k=typeof q=="number"?q:Number(q);for(const R of v){const J=R.range.match(/^([A-Z]+\d+):([A-Z]+\d+)$/i);if(!J)continue;const Fe=at(J[1].toUpperCase()),Le=at(J[2].toUpperCase());if(!Fe||!Le||u<Fe.row||u>Le.row||h<Fe.col||h>Le.col)continue;let re=!1;switch(R.type){case"greaterThan":re=!isNaN(k)&&k>Number(R.value);break;case"lessThan":re=!isNaN(k)&&k<Number(R.value);break;case"equalTo":re=String(q)===String(R.value);break;case"between":re=!isNaN(k)&&k>=Number(R.value)&&k<=Number(R.value2);break;case"textContains":re=String(q).includes(String(R.value));break;case"isEmpty":re=q===null||q==="";break;case"isNotEmpty":re=q!==null&&q!=="";break}if(re)return{backgroundColor:R.style.bgColor,color:R.style.color,fontWeight:R.style.bold?"bold":void 0,fontStyle:R.style.italic?"italic":void 0}}},[E.conditionalFormats,E.data]),Gt=n.useCallback(()=>{const u=`${D("spreadsheet.sheet","Sheet")} ${ae.length+1}`;me(h=>[...h,ii(u)]),ve(ae.length)},[ae.length,me,ve,D]),Vt=n.useCallback(()=>{ae.length<=1||(me(u=>u.filter((h,v)=>v!==M)),ve(Math.max(0,M-1)))},[ae.length,M,me,ve]),Wt=n.useCallback((u,h)=>{h.trim()&&(me(v=>v.map((K,q)=>q===u?{...K,name:h.trim()}:K),!1),T(null))},[me]),Yt=n.useMemo(()=>{if(!_)return"";const u=ze(_.row,_.col),h=E.data[u];return(h==null?void 0:h.formula)??((h==null?void 0:h.value)!=null?String(h.value):"")},[_,E.data]),mt=n.useMemo(()=>{if(!V)return null;const{startRow:u,startCol:h,endRow:v,endCol:K}=V;if(u===v&&h===K)return null;const q=[];let k=0;for(let R=u;R<=v;R++)for(let J=h;J<=K;J++){const Fe=ze(R,J),Le=et(Fe,E.data,new Set);Le!==null&&Le!==""&&k++,typeof Le=="number"&&q.push(Le)}return q.length===0?{count:k}:{count:k,sum:q.reduce((R,J)=>R+J,0),avg:q.reduce((R,J)=>R+J,0)/q.length,min:Math.min(...q),max:Math.max(...q)}},[V,E.data]),on=n.useCallback((u,h)=>{var v;h.preventDefault(),h.stopPropagation(),ye(u),$e.current={x:h.clientX,width:((v=E.colWidths)==null?void 0:v[u])??80}},[E.colWidths]);n.useEffect(()=>{if(H===null)return;const u=v=>{const K=v.clientX-$e.current.x,q=Math.max(30,$e.current.width+K);me(k=>k.map((R,J)=>J===M?{...R,colWidths:{...R.colWidths,[H]:q}}:R),!1)},h=()=>ye(null);return document.addEventListener("mousemove",u),document.addEventListener("mouseup",h),()=>{document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",h)}},[H,M,me]);const qt=n.useCallback((u,h,v)=>{u.preventDefault(),we({row:h,col:v}),ce({x:u.clientX,y:u.clientY})},[]);n.useEffect(()=>{if(!z)return;const u=()=>ce(null);return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[z]);const Pe=n.useCallback(u=>{if((u.ctrlKey||u.metaKey)&&!X){if(u.key==="z"){u.preventDefault(),Ye();return}if(u.key==="y"){u.preventDefault(),ht();return}}if(X||!_)return;let{row:h,col:v}=_;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":I(h,v);return;case"Delete":case"Backspace":o||(V&&(V.startRow!==V.endRow||V.startCol!==V.endCol)?me(K=>{const q=K.map((k,R)=>R===M?{...k,data:{...k.data}}:k);for(let k=V.startRow;k<=V.endRow;k++)for(let R=V.startCol;R<=V.endCol;R++)delete q[M].data[ze(k,R)];return q}):jt(h,v,""));return;default:if(u.key.length===1&&!u.ctrlKey&&!u.metaKey&&!o){xe({row:h,col:v}),Re(u.key);return}return}u.preventDefault(),u.shiftKey&&w?O({row:h,col:v}):(we({row:h,col:v}),O(null)),S==null||S(M,h,v)},[X,_,r,l,o,I,jt,M,S,Ye,ht,V,me,w]),qe=E.frozenRows??0,Oe=E.frozenCols??0,Ot=[{value:"text",label:D("spreadsheet.formatText","Text")},{value:"number",label:D("spreadsheet.formatNumber","Number")},{value:"percent",label:D("spreadsheet.formatPercent","Percent")},{value:"currency",label:D("spreadsheet.formatCurrency","Currency")},{value:"date",label:D("spreadsheet.formatDate","Date")}];return e.jsxs("div",{ref:de,id:Ae,className:`nice-spreadsheet ${o?"nice-spreadsheet--readonly":""} ${c??""}`,style:$,onKeyDown:Pe,onCopy:dt,onPaste:Ne,tabIndex:0,role:"application","aria-label":D("spreadsheet.label","Spreadsheet"),...ne,children:[d&&!o&&e.jsxs("div",{className:"nice-spreadsheet__toolbar",role:"toolbar",children:[e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:Ye,disabled:De.length===0,title:D("spreadsheet.undo","Undo"),children:"?"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:ht,disabled:Te.length===0,title:D("spreadsheet.redo","Redo"),children:"?"}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Q.pn,{variant:(At=E.data[_?ze(_.row,_.col):""])!=null&&At.bold?"primary":"ghost",size:"sm",onClick:()=>{var u;return ke("bold",!((u=E.data[_?ze(_.row,_.col):""])!=null&&u.bold))},title:D("spreadsheet.bold","Bold"),children:e.jsx("strong",{children:"B"})}),e.jsx(Q.pn,{variant:(Kt=E.data[_?ze(_.row,_.col):""])!=null&&Kt.italic?"primary":"ghost",size:"sm",onClick:()=>{var u;return ke("italic",!((u=E.data[_?ze(_.row,_.col):""])!=null&&u.italic))},title:D("spreadsheet.italic","Italic"),children:e.jsx("em",{children:"I"})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>ke("align","left"),title:D("spreadsheet.alignLeft","Align left"),children:"?"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>ke("align","center"),title:D("spreadsheet.alignCenter","Center"),children:"?"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>ke("align","right"),title:D("spreadsheet.alignRight","Align right"),children:"?"}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Q.Ye,{value:((Tt=E.data[_?ze(_.row,_.col):""])==null?void 0:Tt.bgColor)??"var(--bg-primary, #ffffff)",onChange:u=>ke("bgColor",u),title:D("spreadsheet.bgColor","Background color"),showInput:!1,showRandom:!1}),e.jsx(Q.Ye,{value:((Ut=E.data[_?ze(_.row,_.col):""])==null?void 0:Ut.color)??"var(--text-primary, #000000)",onChange:u=>ke("color",u),title:D("spreadsheet.textColor","Text color"),showInput:!1,showRandom:!1}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Q.Ge,{size:"sm",value:((Zt=E.data[_?ze(_.row,_.col):""])==null?void 0:Zt.format)??"text",onChange:u=>ke("format",u),options:Ot,"aria-label":D("spreadsheet.format","Cell format")}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>_&&Ue(_.row),title:D("spreadsheet.insertRow","Insert row"),children:"+?"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>_&&ut(_.col),title:D("spreadsheet.insertCol","Insert column"),children:"+?"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>_&&Ge(_.row),title:D("spreadsheet.deleteRow","Delete row"),children:"-?"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>_&&it(_.col),title:D("spreadsheet.deleteCol","Delete column"),children:"-?"})]}),m&&e.jsxs("div",{className:"nice-spreadsheet__formula-bar",children:[e.jsxs("span",{className:"nice-spreadsheet__cell-label",children:[_?ze(_.row,_.col):"",V&&V.startRow!==V.endRow||V&&V.startCol!==V.endCol?`:${ze(V.endRow,V.endCol)}`:""]}),e.jsx(Q.Pe,{className:"nice-spreadsheet__formula-input",value:X?pe:Yt,onChange:u=>{X?Re(u):_&&(xe(_),Re(u))},onKeyDown:he,readOnly:o,"aria-label":D("spreadsheet.formulaBar","Formula bar")})]}),e.jsx("div",{className:"nice-spreadsheet__grid",ref:tt,children:e.jsxs("table",{role:"grid","aria-label":E.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<Oe?"nice-spreadsheet__col-header--frozen":""}`,style:{width:((v=E.colWidths)==null?void 0:v[h])??80,position:h<Oe?"sticky":void 0,left:h<Oe?h*80+40:void 0,zIndex:h<Oe?3:void 0},children:[e.jsx("span",{children:fi(h)}),y&&e.jsx("span",{className:"nice-spreadsheet__sort-trigger",onClick:()=>kt(h,E.sortColumn===h&&E.sortDirection==="asc"?"desc":"asc"),title:D("spreadsheet.sort","Sort"),children:(E.sortColumn===h&&E.sortDirection,"?")}),!o&&e.jsx("span",{className:"nice-spreadsheet__col-resize",onMouseDown:K=>on(h,K)})]},h)})]})}),e.jsx("tbody",{children:Array.from({length:r},(u,h)=>e.jsxs("tr",{className:h<qe?"nice-spreadsheet__row--frozen":"",style:h<qe?{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,K)=>{var rt,pt;const q=ze(h,K),k=E.data[q];if(k!=null&&k.mergedInto)return null;const R=(_==null?void 0:_.row)===h&&(_==null?void 0:_.col)===K,J=Ee(h,K),Fe=(X==null?void 0:X.row)===h&&(X==null?void 0:X.col)===K,Le=k?et(q,E.data,new Set):null,re=Bt(h,K),Ze=h<qe||K<Oe;return e.jsxs("td",{className:`nice-spreadsheet__cell ${R?"nice-spreadsheet__cell--selected":""} ${J&&!R?"nice-spreadsheet__cell--in-range":""} ${k!=null&&k.readOnly?"nice-spreadsheet__cell--readonly":""} ${Ze?"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:(re==null?void 0:re.backgroundColor)??(k==null?void 0:k.bgColor),color:(re==null?void 0:re.color)??(k==null?void 0:k.color),width:(rt=E.colWidths)==null?void 0:rt[K],height:(pt=E.rowHeights)==null?void 0:pt[h],position:Ze?"sticky":void 0,left:K<Oe?K*80+40:void 0,zIndex:Ze?1:void 0,...re},colSpan:k==null?void 0:k.colSpan,rowSpan:k==null?void 0:k.rowSpan,onMouseDown:lt=>Ve(h,K,lt),onMouseEnter:()=>It(h,K),onDoubleClick:()=>I(h,K),onContextMenu:lt=>qt(lt,h,K),role:"gridcell","aria-selected":R,title:k==null?void 0:k.comment,children:[(k==null?void 0:k.comment)&&e.jsx("span",{className:"nice-spreadsheet__comment-indicator"}),Fe?e.jsx("input",{ref:He,className:"nice-spreadsheet__cell-editor",value:pe,onChange:lt=>Re(lt.target.value),onKeyDown:he,onBlur:oe}):ni(Le,k==null?void 0:k.format)]},K)})]},h))})]})}),z&&!o&&_&&e.jsxs("div",{className:"nice-spreadsheet__context-menu",style:{position:"fixed",left:z.x,top:z.y,zIndex:1e3},children:[e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>{Ue(_.row),ce(null)},children:D("spreadsheet.insertRowAbove","Insert row above")}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>{Ue(_.row+1),ce(null)},children:D("spreadsheet.insertRowBelow","Insert row below")}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>{ut(_.col),ce(null)},children:D("spreadsheet.insertColLeft","Insert column left")}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>{ut(_.col+1),ce(null)},children:D("spreadsheet.insertColRight","Insert column right")}),e.jsx("hr",{className:"nice-spreadsheet__context-sep"}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>{Ge(_.row),ce(null)},children:D("spreadsheet.deleteRow","Delete row")}),e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:()=>{it(_.col),ce(null)},children:D("spreadsheet.deleteCol","Delete column")})]}),mt&&e.jsxs("div",{className:"nice-spreadsheet__status-bar",children:[e.jsxs("span",{children:[D("spreadsheet.count","Count"),": ",mt.count]}),mt.sum!==void 0&&e.jsxs("span",{children:[D("spreadsheet.sum","Sum"),": ",mt.sum.toFixed(2)]}),mt.avg!==void 0&&e.jsxs("span",{children:[D("spreadsheet.avg","Avg"),": ",mt.avg.toFixed(2)]}),mt.min!==void 0&&e.jsxs("span",{children:[D("spreadsheet.min","Min"),": ",mt.min]}),mt.max!==void 0&&e.jsxs("span",{children:[D("spreadsheet.max","Max"),": ",mt.max]})]}),f&&e.jsxs("div",{className:"nice-spreadsheet__tabs",role:"tablist",children:[ae.map((u,h)=>e.jsx("span",{className:"nice-spreadsheet__tab-wrapper",children:G===h?e.jsx(Q.Pe,{className:"nice-spreadsheet__tab-rename",value:te,onChange:v=>je(v),onBlur:()=>Wt(h,te),onKeyDown:v=>{v.key==="Enter"&&Wt(h,te),v.key==="Escape"&&T(null)},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>{o||(T(h),je(u.name))},children:e.jsx(Q.pn,{variant:h===M?"primary":"ghost",size:"sm",onClick:()=>ve(h),children:u.name})})},h)),!o&&e.jsxs(e.Fragment,{children:[e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:Gt,title:D("spreadsheet.addSheet","Add sheet"),children:"+"}),ae.length>1&&e.jsx(Q.pn,{variant:"ghost",size:"sm",onClick:Vt,title:D("spreadsheet.removeSheet","Remove sheet"),children:"�"})]})]})]})});Tn.displayName="NiceSpreadsheet";const ha=Object.freeze(Object.defineProperty({__proto__:null,N:ui,a:cn,c:Rn,d:si,f:zn,g:$n,j:Tn,k:ri,l:mi,m:gi,n:di,o:oi,p:li,q:ln,r:Ri,s:Oi},Symbol.toStringTag,{value:"Module"}));exports.A=An;exports.Bi=$n;exports.Ea=ri;exports.L=ai;exports.La=oi;exports.Na=Tn;exports.NiceSavedQueryPanelBIXW0y1X=ha;exports.Oa=mi;exports.Pa=ui;exports.Ta=di;exports.Wt=cn;exports.Xi=zn;exports.ja=gi;exports.qi=Rn;exports.za=si;