@nice2dev/ui 1.0.25 → 1.0.27

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/NiceErrorBoundary-B91z3IjT.cjs +1 -0
  3. package/dist/NiceErrorBoundary-DQLk-68V.js +770 -0
  4. package/dist/NiceForm-8_p8P0uJ.js +5386 -0
  5. package/dist/NiceForm-DkVFd5Z5.cjs +382 -0
  6. package/dist/NiceModal-CdiLaYTg.cjs +1 -0
  7. package/dist/NiceModal-D6Yj67eH.js +95 -0
  8. package/dist/NiceModuleLifecyclePanel-Bhd8VNjU.js +6856 -0
  9. package/dist/NiceModuleLifecyclePanel-Cn_nB4dg.cjs +1 -0
  10. package/dist/NicePagination-Dnlho_8O.cjs +1 -0
  11. package/dist/NicePagination-kokSP8ls.js +171 -0
  12. package/dist/NicePinCodeInput-1YGb7l2o.cjs +696 -0
  13. package/dist/NicePinCodeInput-CZpYON--.js +13097 -0
  14. package/dist/NiceSavedQueryPanel-C6pPtOAf.js +6893 -0
  15. package/dist/NiceSavedQueryPanel-DOixGvLP.cjs +596 -0
  16. package/dist/NiceTabs-DHiA02RD.cjs +1 -0
  17. package/dist/NiceTabs-MBVJomax.js +1657 -0
  18. package/dist/NiceWindow-DUOkdKuX.js +1592 -0
  19. package/dist/NiceWindow-ZAAUD3LJ.cjs +1 -0
  20. package/dist/charts-B_lYNVMJ.cjs +761 -0
  21. package/dist/charts-CABhvyAA.js +4657 -0
  22. package/dist/charts.cjs +1 -1
  23. package/dist/charts.mjs +1 -1
  24. package/dist/core-BHZDvnBo.js +25364 -0
  25. package/dist/core-C7PK1L9r.cjs +122 -0
  26. package/dist/data-branching-BGw7O52F.js +6133 -0
  27. package/dist/data-branching-Dz3xLUZM.cjs +1 -0
  28. package/dist/data-branching.cjs +1 -1
  29. package/dist/data-branching.mjs +1 -1
  30. package/dist/data.cjs +1 -1
  31. package/dist/data.mjs +1 -1
  32. package/dist/devops-CX538_rA.js +7684 -0
  33. package/dist/devops-JwBTMk0A.cjs +17 -0
  34. package/dist/devops.cjs +1 -1
  35. package/dist/devops.mjs +1 -1
  36. package/dist/editors.cjs +1 -1
  37. package/dist/editors.mjs +3 -3
  38. package/dist/feedback.cjs +1 -1
  39. package/dist/feedback.mjs +2 -2
  40. package/dist/index-CTe-G23X.cjs +5518 -0
  41. package/dist/index-DGjd42Q9.js +68223 -0
  42. package/dist/index.cjs +1 -1
  43. package/dist/index.css +1 -1
  44. package/dist/index.d.ts +75 -0
  45. package/dist/index.mjs +803 -797
  46. package/dist/lazy.cjs +1 -1
  47. package/dist/lazy.mjs +24 -24
  48. package/dist/navigation.cjs +1 -1
  49. package/dist/navigation.d.ts +18 -1
  50. package/dist/navigation.mjs +4 -4
  51. package/dist/no-code-CIf6wiUc.js +7133 -0
  52. package/dist/no-code-DSa5Yn6l.cjs +332 -0
  53. package/dist/no-code.cjs +1 -1
  54. package/dist/no-code.mjs +1 -1
  55. package/dist/overlays.cjs +1 -1
  56. package/dist/overlays.mjs +55 -55
  57. package/dist/style.css +1 -1
  58. package/package.json +1 -1
@@ -0,0 +1,596 @@
1
+ "use strict";const e=require("react/jsx-runtime"),ye=require("./core-C7PK1L9r.cjs"),n=require("react"),xi=require("./NiceForm-DkVFd5Z5.cjs"),_i=require("./NiceModal-CdiLaYTg.cjs"),Zi=require("./NicePagination-Dnlho_8O.cjs"),ze=require("./NiceTabs-DHiA02RD.cjs");function qi({columns:t,data:a,striped:s,compact:r,emptyText:o,className:u,style:f,accessMode:c,id:g,displayStyle:w}){const L=ye.pc(c,g)==="hidden",C=ye.Fs("table",w),Q=ye.Hs("table",w),[V,$]=n.useState(null),T=n.useMemo(()=>V?[...a].sort((x,_)=>{const j=x[V.field]??"",B=_[V.field]??"",Z=typeof j=="number"?j-B:String(j).localeCompare(String(B));return V.dir==="desc"?-Z:Z}):a,[a,V]),v=x=>{$(_=>_?.field===x?_.dir==="asc"?{field:x,dir:"desc"}:null:{field:x,dir:"asc"})};return L?null:e.jsx("div",{className:`nice-table-wrapper ${u||""}`,style:{...C,...f},children:e.jsxs("table",{className:`nice-table nice-table--ds-${Q} ${s?"nice-table--striped":""} ${r?"nice-table--compact":""}`,"aria-rowcount":T.length,"aria-colcount":t.length,children:[e.jsx("thead",{children:e.jsx("tr",{children:t.map(x=>{const _=x.sortable?V?.field===x.field?V.dir==="asc"?"ascending":"descending":"none":void 0;return e.jsxs("th",{style:{width:x.width,textAlign:x.align},className:x.sortable?"th--sortable":void 0,onClick:()=>x.sortable&&v(x.field),scope:"col","aria-sort":_,children:[x.header,x.sortable&&V?.field===x.field&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:V.dir==="asc"?"↑":"↓"})]},x.field)})})}),e.jsx("tbody",{children:T.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:t.length,className:"nice-table__empty",children:o||"No data"})}):T.map((x,_)=>e.jsx("tr",{children:t.map(j=>e.jsx("td",{style:{textAlign:j.align},children:j.render?j.render(x[j.field],x):String(x[j.field]??"")},j.field))},_))})]})})}const Xi=[{target:".nice-filterbuilder",titleKey:"tutorial.filterBuilder.intro.title",title:"Filter builder",contentKey:"tutorial.filterBuilder.intro.content",content:"Build complex AND/OR filter trees: add conditions and nested groups, choose fields and operators, and save reusable presets.",placement:"auto"}],Hi=[{value:"=",label:"Equals"},{value:"<>",label:"Not Equals"},{value:"<",label:"Less Than"},{value:"<=",label:"Less or Equal"},{value:">",label:"Greater Than"},{value:">=",label:"Greater or Equal"},{value:"contains",label:"Contains"},{value:"notcontains",label:"Not Contains"},{value:"startswith",label:"Starts With"},{value:"endswith",label:"Ends With"},{value:"isblank",label:"Is Blank"},{value:"isnotblank",label:"Is Not Blank"}],Qi=({condition:t,fields:a,onChange:s,onRemove:r})=>{const o=a.find(c=>c.field===t.field),u=t.operator==="isblank"||t.operator==="isnotblank",f=o?.operators||Hi;return e.jsxs("div",{className:"nice-filterbuilder__condition",children:[e.jsx("select",{className:"nice-filterbuilder__select",value:t.field,onChange:c=>s({...t,field:c.target.value,value:""}),children:a.map(c=>e.jsx("option",{value:c.field,children:c.label},c.field))}),e.jsx("select",{className:"nice-filterbuilder__select",value:t.operator,onChange:c=>s({...t,operator:c.target.value}),children:f.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))}),!u&&(o?.options?e.jsxs("select",{className:"nice-filterbuilder__select",value:String(t.value??""),onChange:c=>s({...t,value:c.target.value}),children:[e.jsx("option",{value:"",children:"--"}),o.options.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))]}):o?.type==="boolean"?e.jsxs("select",{className:"nice-filterbuilder__select",value:String(t.value??""),onChange:c=>s({...t,value:c.target.value==="true"}),children:[e.jsx("option",{value:"true",children:"True"}),e.jsx("option",{value:"false",children:"False"})]}):e.jsx("input",{className:"nice-filterbuilder__input",type:o?.type==="number"?"number":o?.type==="date"?"date":"text",value:String(t.value??""),onChange:c=>s({...t,value:o?.type==="number"?Number(c.target.value):c.target.value})})),e.jsx("button",{className:"nice-filterbuilder__remove",onClick:r,children:"×"})]})},bi=({group:t,fields:a,onChange:s,onRemove:r,depth:o,maxDepth:u})=>{const f=()=>s({...t,logic:t.logic==="and"?"or":"and"}),c=()=>{const L={type:"condition",field:a[0]?.field||"",operator:"=",value:""};s({...t,items:[...t.items,L]})},g=()=>{if(o>=u)return;const L={type:"group",logic:"and",items:[]};s({...t,items:[...t.items,L]})},w=(L,C)=>{const Q=[...t.items];Q[L]=C,s({...t,items:Q})},R=L=>{s({...t,items:t.items.filter((C,Q)=>Q!==L)})};return e.jsxs("div",{className:`nice-filterbuilder__group nice-filterbuilder__group--depth-${Math.min(o,3)}`,children:[e.jsxs("div",{className:"nice-filterbuilder__group-header",children:[e.jsx("button",{className:"nice-filterbuilder__logic",onClick:f,children:t.logic.toUpperCase()}),e.jsx("button",{className:"nice-btn nice-btn--sm",onClick:c,children:"+ Condition"}),o<u&&e.jsx("button",{className:"nice-btn nice-btn--sm",onClick:g,children:"+ Group"}),r&&e.jsx("button",{className:"nice-filterbuilder__remove",onClick:r,children:"×"})]}),e.jsx("div",{className:"nice-filterbuilder__group-body",children:t.items.map((L,C)=>e.jsx(n.Fragment,{children:L.type==="condition"?e.jsx(Qi,{condition:L,fields:a,onChange:Q=>w(C,Q),onRemove:()=>R(C)}):e.jsx(bi,{group:L,fields:a,onChange:Q=>w(C,Q),onRemove:()=>R(C),depth:o+1,maxDepth:u})},C))})]})},Xn=({fields:t,value:a,onChange:s,maxDepth:r=3,presets:o,onSavePreset:u,onDeletePreset:f,tutorial:c,className:g,style:w})=>{const[R,L]=n.useState(""),C=n.useCallback(V=>{const $=o?.find(T=>T.name===V);$&&s(structuredClone($.filter))},[o,s]),Q=n.useCallback(()=>{!R.trim()||!u||(u({name:R.trim(),filter:structuredClone(a)}),L(""))},[R,a,u]);return e.jsxs("div",{className:`nice-filterbuilder ${g||""}`,style:{position:"relative",...w},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(ye.Ll,{steps:ye.El(c,Xi)})}),(o?.length||u)&&e.jsxs("div",{className:"nice-filterbuilder__presets",children:[o&&o.length>0&&e.jsx("div",{className:"nice-filterbuilder__preset-list",children:o.map(V=>e.jsxs("span",{className:"nice-filterbuilder__preset-tag",children:[e.jsx("button",{type:"button",className:"nice-filterbuilder__preset-btn",onClick:()=>C(V.name),children:V.name}),f&&e.jsx("button",{type:"button",className:"nice-filterbuilder__preset-del",onClick:()=>f(V.name),children:"×"})]},V.name))}),u&&e.jsxs("div",{className:"nice-filterbuilder__preset-save",children:[e.jsx("input",{className:"nice-filterbuilder__input",value:R,onChange:V=>L(V.target.value),placeholder:"Preset name..."}),e.jsx("button",{className:"nice-btn nice-btn--sm",onClick:Q,disabled:!R.trim(),children:"Save"})]})]}),e.jsx(bi,{group:a,fields:t,onChange:s,depth:0,maxDepth:r})]})};Xn.displayName="NiceFilterBuilder";function vi(t,a,s){const r=t.map(o=>o[a]).filter(o=>typeof o=="number");if(r.length===0)return s==="count"?"0":"";switch(s){case"sum":return r.reduce((o,u)=>o+u,0).toLocaleString();case"avg":return(r.reduce((o,u)=>o+u,0)/r.length).toLocaleString(void 0,{maximumFractionDigits:2});case"count":return String(t.length);case"min":return Math.min(...r).toLocaleString();case"max":return Math.max(...r).toLocaleString()}}function wn(t){return t.includes(",")||t.includes('"')||t.includes(`
2
+ `)?`"${t.replace(/"/g,'""')}"`:t}const rn={width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.4,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},Yi=()=>e.jsx("svg",{...rn,children:e.jsx("polyline",{points:"6 15 12 9 18 15"})}),Nn=()=>e.jsx("svg",{...rn,children:e.jsx("polyline",{points:"6 9 12 15 18 9"})}),Ji=()=>e.jsxs("svg",{...rn,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 10 12 5 18 10"}),e.jsx("polyline",{points:"6 14 12 19 18 14"})]}),Ln=()=>e.jsx("svg",{...rn,children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),ea=()=>e.jsxs("svg",{...rn,children:[e.jsx("polyline",{points:"3 17 9 11 13 15 21 7"}),e.jsx("polyline",{points:"14 7 21 7 21 14"})]}),ta=()=>e.jsxs("svg",{...rn,children:[e.jsx("polyline",{points:"3 7 9 13 13 9 21 17"}),e.jsx("polyline",{points:"14 17 21 17 21 10"})]}),na=()=>e.jsx("svg",{...rn,children:e.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})});function ia(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 Tn({columns:t,data:a,keyField:s="id",dataSource:r,sortable:o=!0,sortField:u,sortDirection:f,onSort:c,showAdvancedFilter:g,advancedFilter:w,onAdvancedFilterChange:R,filterFields:L,filterPresets:C,onSaveFilterPreset:Q,onDeleteFilterPreset:V,selectable:$,selectedKeys:T,onSelectionChange:v,pagination:x,pageSize:_=10,page:j,onPageChange:B,totalRows:Z,autoPagination:se=!1,stickyHeader:ve=!0,stickyFooter:O=!0,searchable:H,searchPlaceholder:ce,virtualScroll:le,rowHeight:fe=40,groupBy:U,groupRender:A,onCellEdit:N,editMode:l="inline",formItems:xe,formColumns:De=2,editFormTitle:de,formProps:D,onRowEdit:Y,onRowAdd:P,onRowDelete:me,bulkActions:he,onBulkDelete:Te,exportCsv:Ve,exportFilename:Qe="export",detailRow:ke,expandedRowKeys:$e,onExpandedRowChange:Ue,columnReorder:We,onColumnReorder:J,columnResize:_e,rowDraggable:je,onRowReorder:ge,striped:M,compact:ee,loading:Fe,emptyText:I,toolbar:ue,onRowClick:W,pinnedTopKeys:Ie,pinnedBottomKeys:Le,colSpan:te,showStatusBar:Ke,contextMenuItems:Ye,onContextMenuAction:it,printFriendly:Ne,keyboardNavigation:jt,focusedCell:Pt,onFocusedCellChange:mt,cellRangeSelection:Nt,selectedCellRange:E,onCellRangeChange:ae,clipboard:oe,clipboardFormat:qe="text",onBeforeCopy:rt,onCopy:we,onPaste:Pe,quickFilters:Se,activeQuickFilters:ct,onQuickFilterChange:Ze,columnGroups:wt,stateStorageKey:bt,initialState:cn,onStateChange:Qt,flashRowKeys:Yt,flashDuration:at=500,autoFitColumns:Fn,showColumnStats:Sn,rowIndicator:Jt,frozenRows:ln,className:kt,style:fn,accessMode:m,id:h,displayStyle:z}){const K=ye.pc(m,h),ie=K==="hidden",F=K==="readOnly"||K==="disabled",{t:k}=ye.Zt();ye.Fs("table",z),ye.Hs("table",z);const q=ye.Cd(r??null,{autoLoad:!!r,defaultPageSize:_}),X=!!r,Oe=X?q.data:a??[],Ae=X?q.loading:Fe,[Ce,et]=n.useState({field:"",dir:null}),[Zt,en]=n.useState(1),[nt,Ot]=n.useState(new Set),[St,tn]=n.useState(""),[qt,Ct]=n.useState({type:"group",logic:"and",items:[]}),[gn,Bt]=n.useState(!1),st=w??qt,nn=i=>{R?R(i):Ct(i)},Ut=n.useMemo(()=>L??t.filter(i=>i.filterable!==!1&&i.field).map(i=>({field:String(i.field),label:String(i.header??i.field)})),[L,t]),xn=st.items.length,[Mt,Pn]=n.useState(_),[Et,_n]=n.useState(null),[on,Wt]=n.useState(null),[lt,$t]=n.useState(null),[dn,Cn]=n.useState(new Set),[Mn,bn]=n.useState(0),vn=n.useRef(null),[On,Bn]=n.useState(new Set),un=$e??On,[Dt,Gt]=n.useState({}),[Vt,Kt]=n.useState(null),[Xt,y]=n.useState(null),[pe,Me]=n.useState(null),[Ee,ot]=n.useState(null),[It,Rt]=n.useState([]),[dt,Hn]=n.useState(null),[Di,Qn]=n.useState(new Set),[ds,us]=n.useState(null),Un=n.useRef(null),[Ii,Ri]=n.useState(_);n.useEffect(()=>{if(!se)return;const i=vn.current;if(!i||typeof ResizeObserver>"u")return;const d=()=>{const b=i.clientHeight;if(b<=0)return;const S=Math.max(1,Math.floor(b/fe)-1);Ri(ne=>ne===S?ne:S),X&&q.setPageSize(S)};d();const p=new ResizeObserver(d);return p.observe(i),()=>p.disconnect()},[se,fe,X]);const vt=Pt??pe,ht=E??Ee,Lt=ct??It;n.useEffect(()=>{if(!bt)return;const i=localStorage.getItem(`nice-datagrid-${bt}`);if(i&&!cn)try{const d=JSON.parse(i);d.columnWidths&&Gt(d.columnWidths),d.expandedGroups&&Cn(new Set(d.expandedGroups))}catch{}},[bt,cn]),n.useEffect(()=>{if(!Yt?.size)return;Qn(new Set(Yt));const i=setTimeout(()=>Qn(new Set),at);return()=>clearTimeout(i)},[Yt,at]),n.useEffect(()=>{if(!Xt)return;const i=()=>y(null);return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[Xt]);const Ai=n.useCallback((i,d)=>{Ye?.length&&(i.preventDefault(),y({x:i.clientX,y:i.clientY,row:d}))},[Ye]),Yn=n.useCallback(i=>{const d=new Set(un);d.has(i)?d.delete(i):d.add(i),Ue?Ue(d):Bn(d)},[un,Ue]),Jn=n.useCallback((i,d)=>{if(!_e)return;d.preventDefault();const p=d.clientX,S=d.target.closest("th")?.offsetWidth??100,ne=G=>{const be=Math.max(40,S+G.clientX-p);Gt(Ge=>({...Ge,[i]:be}))},re=()=>{document.removeEventListener("mousemove",ne),document.removeEventListener("mouseup",re)};document.addEventListener("mousemove",ne),document.addEventListener("mouseup",re)},[_e]),zt=X?q.sort[0]?.field??"":u??Ce.field,yt=X?q.sort[0]?.direction??null:f??Ce.dir,yn=X?q.page:j??Zt,tt=T??nt;n.useCallback(()=>{if(!bt)return;const i={columnWidths:Dt,sortField:zt||void 0,sortDirection:yt,pageSize:Mt,expandedGroups:Array.from(dn)};localStorage.setItem(`nice-datagrid-${bt}`,JSON.stringify(i)),Qt?.(i)},[bt,Dt,zt,yt,Mt,dn,Qt]);const pt=n.useMemo(()=>t.filter(i=>!i.hidden),[t]),Wn=n.useMemo(()=>pt.filter(i=>i.pinned==="left"),[pt]),Gn=n.useMemo(()=>pt.filter(i=>i.pinned==="right"),[pt]),ei=n.useMemo(()=>pt.filter(i=>!i.pinned),[pt]),Be=n.useMemo(()=>[...Wn,...ei,...Gn],[Wn,ei,Gn]),Ei=n.useMemo(()=>pt.some(i=>i.aggregate),[pt]),jn=Wn.length>0||Gn.length>0,ti=n.useCallback(i=>{const d=zt===i?yt==="asc"?"desc":yt==="desc"?null:"asc":"asc";X?d?q.setSortField(i,d):q.setSort([]):c?c(i,d):et({field:i,dir:d})},[zt,yt,X,q,c]),ft=n.useMemo(()=>{if(X)return Oe;let i=[...Oe];if(St){const d=St.toLowerCase();i=i.filter(p=>pt.some(b=>String(p[b.field]??"").toLowerCase().includes(d)))}return st.items.length>0&&(i=i.filter(d=>ye.ur(d,st))),!c&&zt&&yt&&i.sort((d,p)=>{const b=d[zt]??"",S=p[zt]??"",ne=typeof b=="number"?b-S:String(b).localeCompare(String(S));return yt==="desc"?-ne:ne}),i},[Oe,St,st,pt,zt,yt,c,X]),Dn=X?q.totalCount:Z??ft.length,an=se?Ii:X?q.pageSize:Mt,$i=Math.max(1,Math.ceil(Dn/an)),At=X?ft:x&&!Z?ft.slice((yn-1)*an,yn*an):ft,In=n.useCallback(i=>{X?q.setPage(i):B?B(i):en(i)},[X,q,B]),mn=n.useMemo(()=>At.map(i=>String(i[s])),[At,s]),hn=mn.length>0&&mn.every(i=>tt.has(i)),ni=mn.some(i=>tt.has(i)),ii=n.useCallback(()=>{const i=new Set(tt);hn?mn.forEach(d=>i.delete(d)):mn.forEach(d=>i.add(d)),v?v(i):Ot(i)},[hn,mn,tt,v]),ai=n.useCallback(i=>{const d=new Set(tt);d.has(i)?d.delete(i):d.add(i),v?v(d):Ot(d)},[tt,v]),si=({field:i})=>zt!==i||!yt?e.jsx("span",{className:"nice-table__sort-icon",children:e.jsx(Ji,{})}):e.jsx("span",{className:"nice-table__sort-icon",children:yt==="asc"?e.jsx(Yi,{}):e.jsx(Nn,{})}),gt=n.useMemo(()=>{if(!U)return At.map((p,b)=>({type:"data",row:p,key:String(p[s]??b)}));const i=new Map;At.forEach(p=>{const b=p[U];i.has(b)||i.set(b,[]),i.get(b).push(p)});const d=[];return i.forEach((p,b)=>{const S=`__group_${String(b)}`,ne=dn.has(S);d.push({type:"group",value:b,rows:p,expanded:ne,key:S}),ne&&p.forEach((re,G)=>d.push({type:"data",row:re,key:String(re[s]??`${S}_${G}`)}))}),d},[At,U,s,dn]),{pinnedTopRows:Li,pinnedBottomRows:zi,normalRows:Ti}=n.useMemo(()=>{if(!Ie?.size&&!Le?.size)return{pinnedTopRows:[],pinnedBottomRows:[],normalRows:gt};const i=[],d=[],p=[];for(const b of gt){if(b.type==="data"){const S=b.key;if(Ie?.has(S)){i.push(b);continue}if(Le?.has(S)){d.push(b);continue}}p.push(b)}return{pinnedTopRows:i,pinnedBottomRows:d,normalRows:p}},[gt,Ie,Le]),ri=n.useCallback(i=>{Cn(d=>{const p=new Set(d);return p.has(i)?p.delete(i):p.add(i),p})},[]),Fi=n.useMemo(()=>{if(!le)return gt;const i=vn.current?.clientHeight??400,d=Math.ceil(i/fe),p=Math.max(0,Math.floor(Mn/fe)-3),b=Math.min(gt.length-1,p+d+6);return gt.slice(p,b+1).map((S,ne)=>({...S,_vIdx:p+ne}))},[le,gt,Mn,fe]),Rn=n.useCallback((i,d,p)=>{!N||F||(_n({rowKey:i,field:d}),Wt(p))},[N]),ci=n.useCallback(()=>{Et&&N&&N(Et.rowKey,Et.field,on),_n(null),Wt(null)},[Et,on,N]),Pi=n.useCallback(()=>{_n(null),Wt(null)},[]),Oi=n.useCallback(()=>{const i=pt,d=i.map(G=>wn(G.header)).join(","),p=ft.map(G=>i.map(be=>wn(String(G[be.field]??""))).join(",")),b=[d,...p].join(`
3
+ `),S=new Blob(["\uFEFF"+b],{type:"text/csv;charset=utf-8;"}),ne=URL.createObjectURL(S),re=document.createElement("a");re.href=ne,re.download=`${Qe}.csv`,re.click(),URL.revokeObjectURL(ne)},[pt,ft,Qe]),An=n.useCallback(i=>{mt?mt(i):Me(i)},[mt]),En=n.useCallback(i=>{ae?ae(i):ot(i)},[ae]),xt=n.useMemo(()=>gt.filter(i=>i.type==="data").map(i=>i.key),[gt]),Bi=n.useCallback(i=>{if(!jt||Et||!vt)return;const d=xt.indexOf(vt.rowKey),p=Be.findIndex(re=>re.field===vt.field);if(d<0||p<0)return;let b=d,S=p;switch(i.key){case"ArrowUp":b=Math.max(0,d-1);break;case"ArrowDown":b=Math.min(xt.length-1,d+1);break;case"ArrowLeft":S=Math.max(0,p-1);break;case"ArrowRight":S=Math.min(Be.length-1,p+1);break;case"Tab":i.preventDefault(),i.shiftKey?S=Math.max(0,p-1):S=Math.min(Be.length-1,p+1);break;case"Enter":{const re=Be[p];if(re.editable&&N){const G=At.find(be=>String(be[s])===vt.rowKey);G&&Rn(vt.rowKey,re.field,G[re.field])}return}case"Escape":An(null),En(null);return;case"Home":i.ctrlKey&&(b=0),S=0;break;case"End":i.ctrlKey&&(b=xt.length-1),S=Be.length-1;break;case"PageUp":b=Math.max(0,d-Mt);break;case"PageDown":b=Math.min(xt.length-1,d+Mt);break;default:return}i.preventDefault();const ne={rowKey:xt[b],field:Be[S].field};if(An(ne),i.shiftKey&&Nt){const re=ht?.start??vt;En({start:re,end:ne})}else En(null)},[jt,Et,vt,xt,Be,Nt,ht,An,En,N,At,s,Rn,Mt]),li=n.useCallback(()=>{let i=[],d=[];if(ht){const p=xt.indexOf(ht.start.rowKey),b=xt.indexOf(ht.end.rowKey),S=Math.min(p,b),ne=Math.max(p,b),re=Be.findIndex(Xe=>Xe.field===ht.start.field),G=Be.findIndex(Xe=>Xe.field===ht.end.field),be=Math.min(re,G),Ge=Math.max(re,G);d=Be.slice(be,Ge+1).map(Xe=>Xe.field),i=At.filter(Xe=>{const Ht=xt.indexOf(String(Xe[s]));return Ht>=S&&Ht<=ne})}else tt.size>0&&(i=At.filter(p=>tt.has(String(p[s]))),d=Be.map(p=>p.field));return{rows:i,fields:d}},[ht,xt,Be,At,s,tt]),oi=n.useCallback((i,d,p)=>{const b=Be.filter(S=>d.includes(S.field));switch(p){case"json":return JSON.stringify(i.map(S=>Object.fromEntries(d.map(ne=>[ne,S[ne]]))),null,2);case"csv":{const S=b.map(re=>wn(re.header)).join(","),ne=i.map(re=>b.map(G=>wn(String(re[G.field]??""))).join(",")).join(`
4
+ `);return S+`
5
+ `+ne}case"html":{const S=b.map(re=>`<th>${re.header}</th>`).join(""),ne=i.map(re=>`<tr>${b.map(G=>`<td>${re[G.field]??""}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${S}</tr></thead><tbody>${ne}</tbody></table>`}case"markdown":{const S="| "+b.map(G=>G.header).join(" | ")+" |",ne="| "+b.map(()=>"---").join(" | ")+" |",re=i.map(G=>"| "+b.map(be=>G[be.field]??"").join(" | ")+" |").join(`
6
+ `);return S+`
7
+ `+ne+`
8
+ `+re}default:return i.map(S=>b.map(ne=>S[ne.field]??"").join(" ")).join(`
9
+ `)}},[Be]),Vn=n.useCallback(async()=>{if(!oe)return;const{rows:i,fields:d}=li();if(!i.length||rt?.(i,d)===!1)return;const p=oi(i,d,qe);await navigator.clipboard.writeText(p),we?.(i,d,qe)},[oe,li,rt,oi,qe,we]),di=n.useCallback(async()=>{if(!oe||!vt||!Pe)return;const d=(await navigator.clipboard.readText()).split(`
10
+ `).map(p=>p.split(" "));Pe(d,vt)},[oe,vt,Pe]);n.useEffect(()=>{if(!oe||!Un.current)return;const i=d=>{Un.current?.contains(document.activeElement)&&(d.type==="copy"&&(d.preventDefault(),Vn()),d.type==="paste"&&(d.preventDefault(),di()))};return document.addEventListener("copy",i),document.addEventListener("paste",i),()=>{document.removeEventListener("copy",i),document.removeEventListener("paste",i)}},[oe,Vn,di]);const Ui=n.useCallback(i=>{const d=Lt.includes(i)?Lt.filter(p=>p!==i):[...Lt,i];Ze?Ze(d):Rt(d)},[Lt,Ze]),Wi=n.useMemo(()=>{if(!Se?.length||!Lt.length)return ft;const i=Se.filter(d=>Lt.includes(d.key));return ft.filter(d=>i.every(p=>p.filter(d)))},[ft,Se,Lt]),ui=Se?.length?Wi:ft;n.useCallback(i=>{const d=ft.map(be=>be[i]).filter(be=>be!=null),p=d.filter(be=>typeof be=="number");if(p.length===0){const be=new Set(d).size;return{count:d.length,unique:be,type:"text"}}const b=p.reduce((be,Ge)=>be+Ge,0),S=b/p.length,ne=Math.min(...p),re=Math.max(...p),G=Math.sqrt(p.reduce((be,Ge)=>be+(Ge-S)**2,0)/p.length);return{count:p.length,sum:b,avg:S,min:ne,max:re,stdDev:G,type:"numeric"}},[ft]);const Gi=n.useCallback((i,d,p)=>{if(!i.cellVisualization)return null;const b=Number(d);if(isNaN(b))return null;const S=i.visualMin??0,ne=i.visualMax??100,re=Math.max(0,Math.min(100,(b-S)/(ne-S)*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:`${re}%`,height:"100%",background:re>80?"var(--color-success)":re>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(re),"%"]})]});case"rating":{const G=Math.round(b/ne*5);return e.jsx("div",{className:"nice-datagrid__cell-rating",children:[1,2,3,4,5].map(be=>e.jsx("span",{style:{color:be<=G?"var(--color-warning)":"var(--text-muted)",fontSize:"0.95rem",lineHeight:1},"aria-hidden":"true",children:"★"},be))})}case"trend":{const G=i.visualMin??b,be=b-G,Ge=be>0?ea:be<0?ta:na,Xe=be>0?"var(--color-success)":be<0?"var(--color-danger)":"var(--text-muted)";return e.jsxs("span",{style:{color:Xe,fontWeight:500,display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(Ge,{})," ",Math.abs(be).toFixed(1),"%"]})}case"heatmap":{const G=re/100,be=`rgba(${Math.round(255*G)}, ${Math.round(100*(1-G))}, ${Math.round(50*(1-G))}, 0.6)`;return e.jsx("span",{style:{background:be,padding:"2px 8px",borderRadius:4},children:b})}default:return null}},[]),Vi=n.useCallback((i,d,p)=>{if(!i.conditionalFormats?.length)return{};for(const b of i.conditionalFormats)if(b.when(d,p,i.field))return{className:b.className,style:{...b.style,backgroundColor:b.backgroundColor,color:b.color}};return{}},[]),Kn=n.useCallback((i,d)=>{if(!jn||!i.pinned)return{};const p={position:"sticky",zIndex:2,background:"var(--bg-primary, #fff)"};if(i.pinned==="left"){let b=0;for(let S=0;S<d;S++){const ne=Be[S];ne.pinned==="left"&&(b+=typeof ne.width=="number"?ne.width:parseInt(String(ne.width)||"100",10))}$&&d===0&&(b=36),p.left=b}else{let b=0;for(let S=Be.length-1;S>d;S--){const ne=Be[S];ne.pinned==="right"&&(b+=typeof ne.width=="number"?ne.width:parseInt(String(ne.width)||"100",10))}p.right=b}return p},[jn,Be,$]),mi=(i,d,p,b)=>{if(Et?.rowKey===p&&Et?.field===i.field)return i.editor?i.editor(on,d,G=>Wt(G)):e.jsx("input",{className:"nice-datagrid__edit-input",autoFocus:!0,value:on??"",onChange:G=>Wt(G.target.value),onBlur:ci,onKeyDown:G=>{G.key==="Enter"&&ci(),G.key==="Escape"&&Pi()}});const ne=Gi(i,d[i.field],d);return ne||(i.render?i.render(d[i.field],d,b):ia(d[i.field]))},Ki=(i,d,p,b)=>{const S=vt?.rowKey===p&&vt?.field===i.field,ne=ht&&(()=>{const be=xt.indexOf(ht.start.rowKey),Ge=xt.indexOf(ht.end.rowKey),Xe=xt.indexOf(p),Ht=Be.findIndex(pn=>pn.field===ht.start.field),sn=Be.findIndex(pn=>pn.field===ht.end.field);return Xe>=Math.min(be,Ge)&&Xe<=Math.max(be,Ge)&&b>=Math.min(Ht,sn)&&b<=Math.max(Ht,sn)})(),re=Vi(i,d[i.field],d);return{className:[re.className,S&&"nice-datagrid__cell--focused",ne&&"nice-datagrid__cell--in-range"].filter(Boolean).join(" "),style:{...Kn(i,b),textAlign:i.align,...re.style,...S?{outline:"2px solid var(--color-primary)",outlineOffset:-2}:{},...ne?{background:"var(--color-primary-light, rgba(59,130,246,0.15))"}:{}}}},$n=Be.length+($?1:0)+(ke?1:0)+(je?1:0)+(Jt?1:0),Zn=(i,d,p)=>{const{row:b,key:S}=i,ne=tt.has(S),re=un.has(S),G=Di.has(S),be=[ne&&"nice-datagrid__row--selected",Vt===d&&"nice-datagrid__row--dragging",p&&"nice-datagrid__row--pinned",G&&"nice-datagrid__row--flash"].filter(Boolean).join(" ");return e.jsxs(n.Fragment,{children:[e.jsxs("tr",{className:be,onClick:()=>W?.(b),onDoubleClick:l==="popup"&&(Y||N)?()=>$t({key:S,data:{...b}}):void 0,onContextMenu:Ge=>Ai(Ge,b),style:W||l==="popup"?{cursor:"pointer"}:void 0,draggable:je,onDragStart:je?()=>Kt(d):void 0,onDragOver:je?Ge=>Ge.preventDefault():void 0,onDrop:je&&ge&&Vt!=null?()=>{ge(Vt,d),Kt(null)}:void 0,onDragEnd:je?()=>Kt(null):void 0,children:[Jt&&e.jsx("td",{className:"nice-datagrid__row-indicator",style:{width:32,padding:"0 4px"},children:Jt(b)}),ke&&e.jsx("td",{className:"nice-datagrid__expand-col",onClick:Ge=>{Ge.stopPropagation(),Yn(S)},children:e.jsx("span",{className:"nice-datagrid__expand-btn","data-expanded":re,children:re?e.jsx(Nn,{}):e.jsx(Ln,{})})}),je&&e.jsx("td",{className:"nice-datagrid__drag-handle",style:{cursor:"grab",textAlign:"center",color:"var(--text-muted)"},children:"?"}),$&&e.jsx("td",{className:"nice-datagrid__checkbox",onClick:Ge=>Ge.stopPropagation(),style:jn?{position:"sticky",left:0,zIndex:1,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:ne,onChange:()=>ai(S),"aria-label":`Select row ${S}`})}),(()=>{let Ge=0;return Be.map((Xe,Ht)=>{if(Ge>0)return Ge--,null;const sn=te?te(b,Xe,Ht):void 0;sn&&sn>1&&(Ge=sn-1);const pn=Ki(Xe,b,S,Ht);return e.jsx("td",{colSpan:sn,className:pn.className,style:pn.style,onClick:jt?()=>An({rowKey:S,field:Xe.field}):void 0,onDoubleClick:Xe.editable&&N?()=>Rn(S,Xe.field,b[Xe.field]):void 0,children:mi(Xe,b,S,d)},Xe.field)})})()]}),ke&&re&&e.jsx("tr",{className:"nice-datagrid__detail-row",children:e.jsx("td",{colSpan:$n,children:ke(b)})})]},S)};return ie?null:e.jsxs("div",{ref:Un,className:`nice-datagrid ${Ne?"nice-datagrid--print":""} ${ve?"nice-datagrid--sticky-header":""} ${O?"nice-datagrid--sticky-footer":""} ${se?"nice-datagrid--auto-pagination":""} ${kt||""}`,style:fn,role:"grid","aria-label":k("datagrid.title","Data Grid"),"aria-rowcount":gt.length,"aria-colcount":pt.length,"aria-busy":Ae||void 0,tabIndex:jt?0:void 0,onKeyDown:jt?Bi:void 0,children:[(H||ue||Ve||Se?.length||P||g)&&e.jsxs("div",{className:"nice-datagrid__toolbar",children:[H&&e.jsx("div",{className:"nice-datagrid__search",children:e.jsx("input",{type:"text",value:X?q.search:St,"aria-label":k("controls.search","Search"),onChange:i=>{X?q.setSearch(i.target.value):(tn(i.target.value),In(1))},placeholder:ce||k("controls.search","Search...")})}),g&&e.jsxs("button",{type:"button",className:`nice-datagrid__filter-toggle ${xn>0?"nice-datagrid__filter-toggle--active":""}`,"aria-expanded":gn,onClick:()=>Bt(i=>!i),children:[k("controls.filter","Filter"),xn>0?` (${xn})`:""]}),Se&&Se.length>0&&e.jsx("div",{className:"nice-datagrid__quick-filters",style:{display:"flex",gap:6,flexWrap:"wrap"},children:Se.map(i=>e.jsxs("button",{className:`nice-datagrid__quick-filter ${Lt.includes(i.key)?"nice-datagrid__quick-filter--active":""}`,onClick:()=>Ui(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:Lt.includes(i.key)?`var(--color-${i.color||"primary"})`:"var(--bg-primary)",color:Lt.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))}),oe&&e.jsx("button",{className:"nice-btn nice-btn--sm nice-btn--ghost",onClick:Vn,title:k("controls.copy","Copy selected"),style:{marginLeft:4},children:"??"}),Ve&&e.jsx("button",{className:"nice-btn nice-btn--sm",onClick:Oi,title:k("controls.exportCsv","Export CSV"),children:"CSV ?"}),P&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--primary",onClick:()=>$t({key:null,data:{}}),title:k("datagrid.addRow","Add row"),children:["+ ",k("datagrid.add","Add")]}),ue]}),g&&gn&&e.jsx("div",{className:"nice-datagrid__filter-panel",style:{padding:"8px 12px",borderBottom:"1px solid var(--border-color)"},children:e.jsx(Xn,{fields:Ut,value:st,onChange:i=>{nn(i),In(1)},presets:C,onSavePreset:Q,onDeletePreset:V})}),$&&tt.size>0&&(he?.length||Te)&&e.jsxs("div",{className:"nice-datagrid__bulk-toolbar",role:"toolbar","aria-label":k("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:k("datagrid.selectedCount","{count} selected").replace("{count}",String(tt.size))}),(he||[]).map(i=>{const d=Array.from(tt),p=ui.filter(S=>tt.has(String(S[s]))),b=i.disabled?.(d,p)||!1;return e.jsxs("button",{type:"button",className:`nice-btn nice-btn--sm nice-btn--${i.variant||"secondary"}`,disabled:b,onClick:()=>i.onClick(d,p),children:[i.icon,i.icon&&" ",i.label]},i.key)}),Te&&!he?.length&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--danger",onClick:()=>{const i=Array.from(tt),d=ui.filter(p=>tt.has(String(p[s])));Te(i,d)},children:["?? ",k("datagrid.deleteSelected","Delete selected")]}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--xs nice-btn--ghost",onClick:()=>{const i=new Set;T===void 0&&Ot(i),v?.(i)},style:{marginLeft:"auto"},children:k("datagrid.clearSelection","Clear")})]}),e.jsxs("div",{ref:vn,className:`nice-datagrid__table-wrap ${le?"nice-datagrid__table-wrap--virtual":""}`,style:le?{maxHeight:Math.min(gt.length*fe,600),overflowY:"auto"}:void 0,onScroll:le?i=>bn(i.currentTarget.scrollTop):void 0,children:[le&&e.jsxs("div",{style:{height:gt.length*fe,position:"relative"},children:[e.jsx("table",{className:`${M?"nice-table--striped":""} ${ee?"nice-table--compact":""}`,style:{position:"sticky",top:0,zIndex:3},children:e.jsx("thead",{children:e.jsxs("tr",{children:[ke&&e.jsx("th",{className:"nice-datagrid__expand-col",style:{width:36}}),je&&e.jsx("th",{style:{width:28}}),$&&e.jsx("th",{className:"nice-datagrid__checkbox",style:jn?{position:"sticky",left:0,zIndex:3,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:hn,ref:i=>{i&&(i.indeterminate=ni&&!hn)},onChange:ii,"aria-label":k("controls.selectAll","Select all")})}),Be.map((i,d)=>e.jsxs("th",{style:{width:Dt[i.field]||i.width,minWidth:i.minWidth,textAlign:i.align,position:"relative",...Kn(i,d)},className:o&&i.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>o&&i.sortable!==!1&&ti(i.field),children:[i.header,o&&i.sortable!==!1&&e.jsx(si,{field:i.field}),_e&&e.jsx("span",{className:"nice-datagrid__resize-handle",onMouseDown:p=>{p.stopPropagation(),Jn(i.field,p)}})]},i.field))]})})}),Fi.map((i,d)=>{const p=i._vIdx??0;if(i.type==="group"){const G=i;return e.jsxs("div",{className:"nice-datagrid__group-row",style:{position:"absolute",top:p*fe,height:fe,left:0,right:0},onClick:()=>ri(G.key),children:[e.jsx("span",{className:"nice-datagrid__group-toggle",children:G.expanded?e.jsx(Nn,{}):e.jsx(Ln,{})}),A?A(G.value,G.rows):e.jsxs(e.Fragment,{children:[String(G.value)," (",G.rows.length,")"]})]},G.key)}const{row:b,key:S}=i,ne=tt.has(S),re=un.has(S);return e.jsxs(n.Fragment,{children:[e.jsxs("div",{className:`nice-datagrid__vrow ${ne?"nice-datagrid__row--selected":""} ${Vt===d?"nice-datagrid__row--dragging":""}`,style:{position:"absolute",top:p*fe,height:fe,left:0,right:0,display:"flex",alignItems:"center"},onClick:()=>W?.(b),onDoubleClick:l==="popup"&&(Y||N)?()=>$t({key:S,data:{...b}}):void 0,draggable:je,onDragStart:je?()=>Kt(d):void 0,onDragOver:je?G=>G.preventDefault():void 0,onDrop:je&&ge&&Vt!=null?()=>{ge(Vt,d),Kt(null)}:void 0,onDragEnd:je?()=>Kt(null):void 0,children:[ke&&e.jsx("div",{className:"nice-datagrid__expand-col",style:{width:36,flexShrink:0,textAlign:"center",cursor:"pointer"},onClick:G=>{G.stopPropagation(),Yn(S)},children:e.jsx("span",{className:"nice-datagrid__expand-btn","data-expanded":re,children:re?e.jsx(Nn,{}):e.jsx(Ln,{})})}),je&&e.jsx("div",{style:{width:28,flexShrink:0,cursor:"grab",textAlign:"center",color:"var(--text-muted)"},children:"?"}),$&&e.jsx("div",{className:"nice-datagrid__checkbox",style:{width:36,flexShrink:0},onClick:G=>G.stopPropagation(),children:e.jsx("input",{type:"checkbox",checked:ne,onChange:()=>ai(S)})}),Be.map(G=>e.jsx("div",{className:"nice-datagrid__vcell",style:{width:Dt[G.field]||G.width||"auto",flex:Dt[G.field]||G.width?`0 0 ${typeof(Dt[G.field]||G.width)=="number"?(Dt[G.field]||G.width)+"px":Dt[G.field]||G.width}`:1,textAlign:G.align,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 8px"},onDoubleClick:G.editable&&N?()=>Rn(S,G.field,b[G.field]):void 0,children:mi(G,b,S,p)},G.field))]}),ke&&re&&e.jsx("div",{className:"nice-datagrid__detail-row",style:{position:"absolute",top:(p+1)*fe,left:0,right:0,padding:"8px 12px",background:"var(--bg-secondary, #f8f8f8)"},children:ke(b)})]},S)})]}),!le&&e.jsxs("table",{className:`${M?"nice-table--striped":""} ${ee?"nice-table--compact":""}`,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[ke&&e.jsx("th",{className:"nice-datagrid__expand-col",style:{width:36}}),je&&e.jsx("th",{style:{width:28}}),$&&e.jsx("th",{className:"nice-datagrid__checkbox",style:jn?{position:"sticky",left:0,zIndex:3,background:"var(--bg-primary, #fff)"}:void 0,children:e.jsx("input",{type:"checkbox",checked:hn,ref:i=>{i&&(i.indeterminate=ni&&!hn)},onChange:ii,"aria-label":k("controls.selectAll","Select all")})}),Be.map((i,d)=>{const p=o&&i.sortable!==!1,b=p?zt===i.field?yt==="asc"?"ascending":yt==="desc"?"descending":"none":"none":void 0;return e.jsxs("th",{style:{width:Dt[i.field]||i.width,minWidth:i.minWidth,textAlign:i.align,position:"relative",...Kn(i,d)},className:p?"nice-datagrid__th--sortable":void 0,onClick:()=>p&&ti(i.field),"aria-sort":b,scope:"col",children:[i.header,p&&e.jsx(si,{field:i.field}),_e&&e.jsx("span",{className:"nice-datagrid__resize-handle",onMouseDown:S=>{S.stopPropagation(),Jn(i.field,S)}})]},i.field)})]})}),e.jsx("tbody",{children:Ae?e.jsx("tr",{children:e.jsx("td",{colSpan:$n,className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):gt.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:$n,className:"nice-datagrid__empty",children:I||k("controls.noData","No data available")})}):e.jsxs(e.Fragment,{children:[Li.map((i,d)=>i.type==="data"&&Zn(i,d,"top")),Ti.map((i,d)=>{if(i.type==="group"){const p=i;return e.jsx("tr",{className:"nice-datagrid__group-row",onClick:()=>ri(p.key),children:e.jsxs("td",{colSpan:$n,className:"nice-datagrid__group-cell",children:[e.jsx("span",{className:"nice-datagrid__group-toggle",children:p.expanded?e.jsx(Nn,{}):e.jsx(Ln,{})}),A?A(p.value,p.rows):e.jsxs(e.Fragment,{children:[String(p.value)," (",p.rows.length,")"]})]})},p.key)}return Zn(i,d)}),zi.map((i,d)=>i.type==="data"&&Zn(i,d,"bottom"))]})}),Ei&&!Ae&&At.length>0&&e.jsx("tfoot",{children:e.jsxs("tr",{className:"nice-datagrid__aggregate-row",children:[$&&e.jsx("td",{}),Be.map(i=>e.jsx("td",{style:{textAlign:i.align,fontWeight:600},children:i.aggregate?(i.aggregateLabel||i.aggregate.toUpperCase())+": "+vi(ft,i.field,i.aggregate):""},i.field))]})})]})]}),x&&e.jsxs("div",{className:"nice-datagrid__footer",children:[e.jsxs("span",{className:"nice-datagrid__footer-info",children:[k("controls.showing","Showing")," ",(yn-1)*an+1,"–",Math.min(yn*an,Dn)," ",k("controls.of","of")," ",Dn,se&&e.jsxs("span",{className:"nice-datagrid__page-size-label",children:[" · ",an," ",k("controls.perPage","/ page")]})]}),e.jsx(Zi.NicePagination,{page:yn,totalPages:$i,onChange:In,showInfo:!0,pageSize:an,showPageSize:!se,pageSizeOptions:[5,10,25,50,100],onPageSizeChange:i=>{X?q.setPageSize(i):(Pn(i),In(1))},showFirstLast:!0})]}),Ke&&!Ae&&e.jsxs("div",{className:"nice-datagrid__status-bar",children:[e.jsxs("span",{children:[k("controls.totalRows","Total rows"),": ",Dn]}),$&&tt.size>0&&e.jsxs("span",{children:[k("controls.selected","Selected"),": ",tt.size]})]}),Xt&&Ye&&e.jsx("div",{className:"nice-datagrid__context-menu",style:{position:"fixed",left:Xt.x,top:Xt.y,zIndex:9999},onClick:i=>i.stopPropagation(),children:Ye.map(i=>e.jsxs("button",{className:"nice-datagrid__context-item",disabled:i.disabled,onClick:()=>{it?.(i.key,Xt.row),y(null)},children:[i.icon&&e.jsx("span",{className:"nice-datagrid__context-icon",children:i.icon}),i.label]},i.key))}),(l==="popup"||P)&&lt&&(()=>{const i=lt.key===null,d=xe??t.filter(p=>!p.hidden&&p.field!==s).map(p=>{let b="text";return p.dataType==="number"||p.dataType==="currency"||p.dataType==="percent"?b="number":p.dataType==="boolean"?b="checkbox":p.dataType==="date"&&(b="date"),{field:p.field,label:p.header,type:b,required:p.validation?.required}});return e.jsx(_i.NiceModal,{open:!0,onClose:()=>$t(null),title:de??(i?k("datagrid.addRow","Add row"):k("datagrid.editRow","Edit row")),size:"lg",children:e.jsx(xi.NiceForm,{items:d,data:lt.data,columns:De,showActions:!0,submitLabel:i?k("controls.add","Add"):k("controls.save","Save"),cancelLabel:k("controls.cancel","Cancel"),onCancel:()=>$t(null),...D,onFieldChange:(p,b)=>$t(S=>S&&{...S,data:{...S.data,[p]:b}}),onSubmit:p=>{i?P?.(p):lt.key&&(Y?Y(lt.key,p):N&&Object.keys(p).forEach(b=>{N(lt.key,b,p[b])})),$t(null)}})})})()]})}Tn.displayName="NiceDataGrid";const aa=Object.freeze(Object.defineProperty({__proto__:null,NiceDataGrid:Tn},Symbol.toStringTag,{value:"Module"}));function sa(t,a){return t.filter(s=>a.every(r=>{const o=s[r.field],u=r.value;switch(r.operator){case"eq":return o===u;case"ne":return o!==u;case"gt":return typeof o=="number"&&typeof u=="number"&&o>u;case"gte":return typeof o=="number"&&typeof u=="number"&&o>=u;case"lt":return typeof o=="number"&&typeof u=="number"&&o<u;case"lte":return typeof o=="number"&&typeof u=="number"&&o<=u;case"contains":return String(o).toLowerCase().includes(String(u).toLowerCase());case"startsWith":return String(o).toLowerCase().startsWith(String(u).toLowerCase());case"endsWith":return String(o).toLowerCase().endsWith(String(u).toLowerCase());default:return!0}}))}function ra(t){return t.map(a=>({field:a.field,type:a.dataType||"string",label:typeof a.header=="string"?a.header:a.field}))}function ca(t,a){const{enableAI:s=!0,aiModel:r,enableNLSearch:o=!0,enableInsights:u=!0,nlPlaceholder:f,onAIFilter:c,onInsights:g,showAISearchBar:w=!0,exampleQueries:R=["Show items from last week","Filter by status = active","Orders over $1000",'Names starting with "A"'],columns:L,data:C,...Q}=t,[V,$]=n.useState(""),[T,v]=n.useState([]),[x,_]=n.useState([]),[j,B]=n.useState(!1),[Z,se]=n.useState(null),ve=n.useRef(null),{t:O}=ye.Zt(),H=ye.ce(),{parseFilter:ce,isLoading:le}=ye.ed(),fe=s&&H.isConfigured,U=T.length>0?sa(C||[],T):C,A=n.useCallback(async D=>{if(!fe||!o||!D.trim())return;se(D);const Y=ra(L);try{const P=await ce(D,Y);v(P),c?.(D,P)}catch{v([])}},[fe,o,L,ce,c]),N=n.useCallback(()=>{v([]),se(null),$("")},[]),l=n.useCallback(()=>T,[T]),xe=n.useCallback(async()=>{if(!fe||!u||!C?.length)return[];try{const D=await H.complete([{role:"user",content:`Analyze this data and provide 3-5 key insights. Data sample (${C.length} total rows): ${JSON.stringify(C.slice(0,20))}
11
+
12
+ Columns: ${L.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(D.content),P=Array.isArray(Y)?Y:[];return _(P),g?.(P),P}catch{return[]}}catch{return[]}},[fe,u,C,L,H,g]),De=D=>{D.preventDefault(),V.trim()&&A(V)},de=D=>{$(D),A(D)};return n.useImperativeHandle(a,()=>({applyNLFilter:A,clearAIFilters:N,getAIFilters:l,generateInsights:xe})),e.jsxs("div",{className:"nice-data-grid-ai","data-testid":t["data-testid"],children:[w&&fe&&o&&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:De,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:ve,type:"text",value:V,onChange:D=>$(D.target.value),placeholder:f||O("dataGridAI.searchPlaceholder","Search with natural language..."),className:"nice-data-grid-ai__input",disabled:le}),le&&e.jsx("span",{className:"nice-data-grid-ai__loading-spinner"}),V&&!le&&e.jsx("button",{type:"button",className:"nice-data-grid-ai__clear-input",onClick:()=>$(""),children:"✕"})]}),e.jsx("button",{type:"submit",className:"nice-data-grid-ai__search-btn",disabled:le||!V.trim(),children:le?O("dataGridAI.searching","Searching..."):O("dataGridAI.search","Search")})]}),u&&e.jsxs("button",{type:"button",className:"nice-data-grid-ai__insights-btn",onClick:()=>{xe(),B(!0)},disabled:le||!C?.length,title:O("dataGridAI.generateInsights","Generate AI Insights"),children:["💡 ",O("dataGridAI.insights","Insights")]})]}),w&&fe&&o&&!Z&&R.length>0&&e.jsxs("div",{className:"nice-data-grid-ai__examples",children:[e.jsx("span",{className:"nice-data-grid-ai__examples-label",children:O("dataGridAI.tryAsking","Try asking:")}),e.jsx("div",{className:"nice-data-grid-ai__examples-list",children:R.slice(0,4).map((D,Y)=>e.jsxs("button",{type:"button",className:"nice-data-grid-ai__example",onClick:()=>de(D),children:['"',D,'"']},Y))})]}),Z&&T.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:['"',Z,'"']}),e.jsxs("span",{className:"nice-data-grid-ai__filter-count",children:["(",U?.length||0," ",O("dataGridAI.results","results"),")"]})]}),e.jsx("div",{className:"nice-data-grid-ai__filter-badges",children:T.map((D,Y)=>e.jsxs("span",{className:"nice-data-grid-ai__filter-badge",children:[D.field," ",D.operator," ",String(D.value)]},Y))}),e.jsxs("button",{type:"button",className:"nice-data-grid-ai__clear-filter",onClick:N,children:["✕ ",O("dataGridAI.clearFilter","Clear")]})]}),e.jsx("div",{className:"nice-data-grid-ai__grid-wrapper",children:e.jsx(Tn,{columns:L,data:U,...Q})}),j&&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:["💡 ",O("dataGridAI.aiInsights","AI Insights")]}),e.jsx("button",{type:"button",className:"nice-data-grid-ai__insights-close",onClick:()=>B(!1),children:"✕"})]}),e.jsx("div",{className:"nice-data-grid-ai__insights-body",children:le?e.jsx("div",{className:"nice-data-grid-ai__insights-loading",children:O("dataGridAI.analyzing","Analyzing data...")}):x.length>0?e.jsx("ul",{className:"nice-data-grid-ai__insights-list",children:x.map((D,Y)=>e.jsxs("li",{className:"nice-data-grid-ai__insight",children:[e.jsx("span",{className:"nice-data-grid-ai__insight-bullet",children:"•"}),D]},Y))}):e.jsx("div",{className:"nice-data-grid-ai__insights-empty",children:O("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:()=>xe(),disabled:le,children:["🔄 ",O("dataGridAI.refresh","Refresh")]})})]})]})}const la=n.forwardRef(ca),oa=({items:t,selectedKeys:a=[],onSelectionChange:s,selectionMode:r="none",searchable:o,searchPlaceholder:u,grouped:f,groupField:c="group",reorderable:g,onReorder:w,onItemClick:R,renderItem:L,showCheckboxes:C,loading:Q,emptyText:V,size:$="md",bordered:T=!0,swipeActions:v,className:x,style:_,accessMode:j,id:B})=>{const se=ye.pc(j,B)==="hidden",{t:ve}=ye.Zt(),[O,H]=n.useState(""),[ce,le]=n.useState(null),[fe,U]=n.useState(null),A=n.useRef(null),N=n.useMemo(()=>{if(!O)return t;const D=O.toLowerCase();return t.filter(Y=>Y.text.toLowerCase().includes(D))},[t,O]),l=n.useMemo(()=>{if(!f)return null;const D=new Map;return N.forEach(Y=>{const P=String(Y[c]??"");D.has(P)||D.set(P,[]),D.get(P).push(Y)}),D},[N,f,c]),xe=n.useCallback(D=>{s&&(r==="single"?s(a.includes(D)?[]:[D]):r==="multiple"&&s(a.includes(D)?a.filter(Y=>Y!==D):[...a,D]))},[a,r,s]),De=n.useCallback(D=>{ce!==null&&ce!==D&&w&&w(ce,D),le(null)},[ce,w]),de=(D,Y)=>{const P=a.includes(D.key),me=fe===D.key;return e.jsxs("li",{className:`nice-list__item ${P?"nice-list__item--selected":""} ${D.disabled?"nice-list__item--disabled":""} ${me?"nice-list__item--swiped":""}`,onClick:()=>{D.disabled||(xe(D.key),R?.(D))},draggable:g,onDragStart:()=>le(Y),onDragOver:he=>he.preventDefault(),onDrop:()=>De(Y),onTouchStart:v?.length?he=>{A.current={x:he.touches[0].clientX,key:D.key}}:void 0,onTouchEnd:v?.length?he=>{if(!A.current)return;const Te=he.changedTouches[0].clientX-A.current.x;Te<-50&&A.current.key===D.key?U(D.key):Te>50&&U(null),A.current=null}:void 0,role:r!=="none"?"option":void 0,"aria-selected":r!=="none"?P:void 0,children:[e.jsxs("div",{className:"nice-list__item-content",children:[C&&r!=="none"&&e.jsx("input",{type:"checkbox",checked:P,readOnly:!0,tabIndex:-1,className:"nice-list__checkbox"}),L?L(D):e.jsxs(e.Fragment,{children:[D.icon&&e.jsx("span",{className:"nice-list__icon",children:D.icon}),e.jsx("span",{className:"nice-list__text",children:D.text}),D.badge&&e.jsx("span",{className:"nice-list__badge",children:D.badge})]})]}),v&&me&&e.jsx("div",{className:"nice-list__swipe-actions",children:v.map(he=>e.jsx("button",{className:"nice-list__swipe-btn",style:he.color?{backgroundColor:he.color}:void 0,onClick:Te=>{Te.stopPropagation(),he.onClick(D),U(null)},children:he.label},he.key))})]},D.key)};return se?null:e.jsxs("div",{className:`nice-list nice-list--${$} ${T?"nice-list--bordered":""} ${x||""}`,style:_,children:[o&&e.jsx("div",{className:"nice-list__search",children:e.jsx("input",{type:"text",value:O,onChange:D=>H(D.target.value),placeholder:u||ve("controls.search","Search...")})}),Q?e.jsx("div",{className:"nice-list__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm"})}):N.length===0?e.jsx("div",{className:"nice-list__empty",children:V||ve("controls.noData","No data available")}):l?e.jsx("div",{role:"listbox",children:Array.from(l.entries()).map(([D,Y])=>e.jsxs("div",{className:"nice-list__group",children:[e.jsx("div",{className:"nice-list__group-header",children:D}),e.jsx("ul",{className:"nice-list__items",children:Y.map((P,me)=>de(P,me))})]},D))}):e.jsx("ul",{className:"nice-list__items",role:"listbox",children:N.map((D,Y)=>de(D,Y))})]})};function yi(t){const a=[];if(t.children)for(const s of t.children)a.push(s.key),a.push(...yi(s));return a}function qn(t,a){if(!t.children||t.children.length===0)return a.has(t.key)?"checked":"unchecked";let s=!0,r=a.has(t.key);for(const o of t.children){const u=qn(o,a);u==="checked"?r=!0:(u==="indeterminate"&&(r=!0),s=!1)}return s&&r?"checked":r?"indeterminate":"unchecked"}const da=({nodes:t,selectedKeys:a=[],expandedKeys:s,onSelectionChange:r,onExpandedChange:o,selectionMode:u="none",showCheckboxes:f,searchable:c,searchPlaceholder:g,onNodeClick:w,renderNode:R,showLines:L,loading:C,className:Q,style:V,accessMode:$,id:T,draggable:v,onNodeDrop:x,onLoadChildren:_,contextMenuItems:j,onContextMenuAction:B,editable:Z,onNodeEdit:se,maxDepth:ve})=>{const H=ye.pc($,T)==="hidden",{t:ce}=ye.Zt(),[le,fe]=n.useState([]),[U,A]=n.useState(""),[N,l]=n.useState(new Set),[xe,De]=n.useState(new Map),[de,D]=n.useState(null),[Y,P]=n.useState(null),[me,he]=n.useState(null),[Te,Ve]=n.useState(""),Qe=n.useRef(null),ke=s??le,$e=n.useMemo(()=>new Set(a),[a]),Ue=n.useCallback(async(M,ee)=>{const Fe=!ke.includes(M),I=Fe?[...ke,M]:ke.filter(ue=>ue!==M);if(o?o(I):fe(I),Fe&&_&&!ee.children?.length&&ee.leaf!==!0&&!xe.has(M)){l(W=>new Set(W).add(M));const ue=await _(ee);De(W=>new Map(W).set(M,ue)),l(W=>{const Ie=new Set(W);return Ie.delete(M),Ie})}},[ke,o,_,xe]),We=n.useCallback((M,ee)=>{if(r){if(u==="single")r(a.includes(M)?[]:[M]);else if(u==="multiple")if(f&&ee.children?.length){const Fe=yi(ee),I=[M,...Fe];if(qn(ee,$e)==="checked")r(a.filter(W=>!I.includes(W)));else{const W=new Set([...a,...I]);r(Array.from(W))}}else r(a.includes(M)?a.filter(Fe=>Fe!==M):[...a,M])}},[a,u,r,f,$e]),J=n.useCallback(M=>{if(!U)return!0;const ee=U.toLowerCase();return M.text.toLowerCase().includes(ee)?!0:(xe.get(M.key)??M.children)?.some(I=>J(I))??!1},[U,xe]),_e=n.useCallback((M,ee)=>{j?.length&&(M.preventDefault(),P({x:M.clientX,y:M.clientY,node:ee}))},[j]),je=n.useCallback(()=>{me&&se&&se(me,Te),he(null)},[me,Te,se]),ge=(M,ee)=>{if(U&&!J(M))return null;const Fe=typeof ve=="number"?Math.min(10,Math.max(1,ve)):1/0,I=ee+1>=Fe,ue=I?void 0:xe.get(M.key)??M.children,W=!I&&(ue&&ue.length>0||M.leaf!==!0&&_&&!ue?.length),Ie=ke.includes(M.key),Le=$e.has(M.key),te=N.has(M.key),Ke=f&&u==="multiple"&&ue?.length?qn(M,$e):Le?"checked":"unchecked",Ye=Math.min(ee+1,10),it={paddingLeft:ee*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":W?Ie:void 0,"data-nice-depth":Ye,draggable:v&&!M.disabled,onDragStart:v?Ne=>{Ne.stopPropagation(),D(M.key)}:void 0,onDragOver:v?Ne=>{Ne.preventDefault(),Ne.stopPropagation()}:void 0,onDrop:v&&de?Ne=>{Ne.stopPropagation(),x?.(de,M.key,"inside"),D(null)}:void 0,onDragEnd:v?()=>D(null):void 0,children:[e.jsxs("div",{className:`nice-tree__row ${Le?"nice-tree__row--selected":""} ${M.disabled?"nice-tree__row--disabled":""} ${de===M.key?"nice-tree__row--dragging":""}`,style:it,onClick:()=>{M.disabled||(We(M.key,M),w?.(M))},onContextMenu:Ne=>_e(Ne,M),onDoubleClick:Z&&!M.disabled?()=>{he(M.key),Ve(M.text)}:void 0,children:[e.jsx("span",{className:`nice-tree__toggle ${W?Ie?"nice-tree__toggle--expanded":"":"nice-tree__toggle--leaf"}`,onClick:Ne=>{Ne.stopPropagation(),W&&Ue(M.key,M)},children:te?e.jsx("span",{className:"nice-spinner nice-spinner--xs"}):W?Ie?"▾":"▸":""}),f&&u!=="none"&&e.jsx("input",{type:"checkbox",checked:Ke==="checked",ref:Ne=>{Ne&&(Ne.indeterminate=Ke==="indeterminate")},onChange:()=>We(M.key,M),onClick:Ne=>Ne.stopPropagation(),tabIndex:-1,className:"nice-tree__checkbox"}),me===M.key?e.jsx("input",{type:"text",className:"nice-tree__edit-input",value:Te,onChange:Ne=>Ve(Ne.target.value),onBlur:je,onKeyDown:Ne=>{Ne.key==="Enter"&&je(),Ne.key==="Escape"&&he(null)},autoFocus:!0,onClick:Ne=>Ne.stopPropagation()}):R?R(M):e.jsxs(e.Fragment,{children:[M.icon&&e.jsx("span",{className:"nice-tree__icon",children:M.icon}),e.jsx("span",{className:"nice-tree__text",children:M.text})]})]}),ue&&ue.length>0&&Ie&&e.jsx("ul",{className:"nice-tree__children",role:"group",children:ue.map(Ne=>ge(Ne,ee+1))})]},M.key)};return H?null:e.jsxs("div",{className:`nice-tree ${L?"nice-tree--lines":""} ${Q||""}`,style:V,ref:Qe,onClick:()=>P(null),children:[c&&e.jsx("div",{className:"nice-tree__search",children:e.jsx("input",{type:"text",value:U,onChange:M=>A(M.target.value),placeholder:g||ce("controls.search","Search..."),"aria-label":g||ce("controls.search","Search tree")})}),C?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(M=>ge(M,0))}),Y&&j&&e.jsx("div",{className:"nice-tree__context-menu",style:{position:"fixed",top:Y.y,left:Y.x,zIndex:9999},children:j.map(M=>e.jsxs("div",{className:`nice-tree__context-item ${M.disabled?"nice-tree__context-item--disabled":""}`,onClick:()=>{M.disabled||(B?.(M.key,Y.node),P(null))},children:[M.icon&&e.jsx("span",{children:M.icon}),M.label]},M.key))})]})};function ua(t,a,s){const r=new Map,o=[];return t.forEach(u=>{const f={...u,children:[]};r.set(String(f[a]),f)}),t.forEach(u=>{const f=u[s];f!=null&&r.has(String(f))?r.get(String(f)).children.push(r.get(String(u[a]))):o.push(r.get(String(u[a])))}),o}function ma({columns:t,data:a,keyField:s="key",parentKeyField:r="parentKey",expandedKeys:o,onExpandedChange:u,selectedKeys:f=[],onSelectionChange:c,selectable:g,loading:w,emptyText:R,className:L,style:C,accessMode:Q,id:V}){const T=ye.pc(Q,V)==="hidden",{t:v}=ye.Zt(),[x,_]=n.useState([]),j=o??x,B=n.useMemo(()=>ua(a,s,r),[a,s,r]),Z=n.useMemo(()=>t.filter(H=>!H.hidden),[t]),se=n.useCallback(H=>{const ce=j.includes(H)?j.filter(le=>le!==H):[...j,H];u?u(ce):_(ce)},[j,u]),ve=n.useCallback(H=>{c&&c(f.includes(H)?f.filter(ce=>ce!==H):[...f,H])},[f,c]),O=(H,ce)=>{const le=String(H[s]),fe=H.children&&H.children.length>0,U=j.includes(le),A=f.includes(le);return e.jsxs(n.Fragment,{children:[e.jsxs("tr",{className:A?"nice-treelist__row--selected":"",children:[g&&e.jsx("td",{className:"nice-treelist__checkbox",children:e.jsx("input",{type:"checkbox",checked:A,onChange:()=>ve(le)})}),Z.map((N,l)=>e.jsxs("td",{style:{textAlign:N.align},children:[l===0&&e.jsx("span",{style:{display:"inline-block",width:ce*20}}),l===0&&e.jsx("span",{className:"nice-treelist__toggle",onClick:()=>fe&&se(le),style:{cursor:fe?"pointer":"default",width:20,display:"inline-block"},children:fe?U?"▾":"▸":""}),N.render?N.render(H[N.field],H,0):String(H[N.field]??"")]},N.field))]}),fe&&U&&H.children.map(N=>O(N,ce+1))]},le)};return T?null:e.jsx("div",{className:`nice-treelist ${L||""}`,style:C,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[g&&e.jsx("th",{className:"nice-treelist__checkbox"}),Z.map(H=>e.jsx("th",{style:{width:H.width,minWidth:H.minWidth,textAlign:H.align},children:H.header},H.field))]})}),e.jsx("tbody",{children:w?e.jsx("tr",{children:e.jsx("td",{colSpan:Z.length+(g?1:0),className:"nice-treelist__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):B.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Z.length+(g?1:0),className:"nice-treelist__empty",children:R||v("controls.noData","No data available")})}):B.map(H=>O(H,0))})]})})}function ha({items:t,renderCard:a,columns:s=3,gap:r=16,searchable:o,searchField:u="text",searchPlaceholder:f,loading:c,emptyText:g,onCardClick:w,className:R,style:L,accessMode:C,id:Q}){const $=ye.pc(C,Q)==="hidden",{t:T}=ye.Zt(),[v,x]=n.useState(""),_=n.useMemo(()=>{if(!v)return t;const j=v.toLowerCase();return t.filter(B=>String(B[u]??"").toLowerCase().includes(j))},[t,v,u]);return $?null:e.jsxs("div",{className:`nice-cardview ${R||""}`,style:L,children:[o&&e.jsx("div",{className:"nice-cardview__search",children:e.jsx("input",{type:"text",value:v,onChange:j=>x(j.target.value),placeholder:f||T("controls.search","Search...")})}),c?e.jsx("div",{className:"nice-cardview__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):_.length===0?e.jsx("div",{className:"nice-cardview__empty",children:g||T("controls.noData","No data available")}):e.jsx("div",{className:"nice-cardview__grid",style:{display:"grid",gridTemplateColumns:`repeat(${s}, 1fr)`,gap:r},children:_.map(j=>e.jsx("div",{className:"nice-cardview__card",onClick:()=>w?.(j),style:w?{cursor:"pointer"}:void 0,children:a(j)},j.key))})]})}function pa({items:t,tileWidth:a=180,tileHeight:s=180,direction:r="horizontal",renderTile:o,onTileClick:u,loading:f,emptyText:c,className:g,style:w}){const{t:R}=ye.Zt();return e.jsx("div",{className:`nice-tileview nice-tileview--${r} ${g||""}`,style:w,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:c||R("controls.noData","No data available")}):e.jsx("div",{className:"nice-tileview__container",style:{display:"flex",flexWrap:"wrap",gap:8,flexDirection:r==="vertical"?"column":"row"},children:t.map(L=>e.jsx("div",{className:"nice-tileview__tile",style:{width:a,height:s,cursor:u?"pointer":void 0},onClick:()=>u?.(L),children:o?o(L):e.jsxs(e.Fragment,{children:[L.image&&e.jsx("img",{src:L.image,alt:L.text||"",className:"nice-tileview__image"}),L.text&&e.jsx("div",{className:"nice-tileview__label",children:L.text})]})},L.key))})})}const hi=[{key:"row",label:"Rows"},{key:"column",label:"Columns"},{key:"data",label:"Values"},{key:"filter",label:"Filters"}],ji=({fields:t,onChange:a,className:s,style:r})=>{const o=t.filter(c=>!c.area),u=(c,g)=>{a(t.map(w=>w.field===c?{...w,area:g}:w))},f=c=>{a(t.map(g=>g.field===c?{...g,area:void 0}:g))};return e.jsx("div",{className:`nice-field-chooser ${s||""}`,style:r,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:o.map(c=>e.jsxs("li",{className:"nice-field-chooser__item",children:[e.jsx("span",{children:c.caption}),e.jsx("div",{className:"nice-field-chooser__actions",children:hi.map(g=>e.jsx("button",{type:"button",className:"nice-btn nice-btn--ghost nice-btn--sm",onClick:()=>u(c.field,g.key),children:g.label},g.key))})]},c.field))})]}),hi.map(c=>{const g=t.filter(w=>w.area===c.key);return e.jsxs("div",{className:"nice-field-chooser__section",children:[e.jsx("h4",{children:c.label}),e.jsx("ul",{children:g.map(w=>e.jsxs("li",{className:"nice-field-chooser__item",children:[e.jsx("span",{children:w.caption}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--ghost nice-btn--sm",onClick:()=>f(w.field),children:"✕"})]},w.field))})]},c.key)})]})})};function fa(t,a){if(t.length===0)return 0;switch(a){case"sum":return t.reduce((s,r)=>s+r,0);case"count":return t.length;case"avg":return t.reduce((s,r)=>s+r,0)/t.length;case"min":return Math.min(...t);case"max":return Math.max(...t);default:return t.reduce((s,r)=>s+r,0)}}function pi(t,a){return[...new Set(t.map(s=>String(s[a]??"")))].sort()}const Ni=({data:t,fields:a,onFieldsChange:s,showFieldChooser:r,loading:o,emptyText:u,exportCsv:f,exportFilename:c="pivot-export",onDrillThrough:g,className:w,style:R,accessMode:L,id:C})=>{const V=ye.pc(L,C)==="hidden",{t:$}=ye.Zt(),[T,v]=n.useState(a),[x,_]=n.useState(!1),j=n.useMemo(()=>T.filter(U=>U.area==="row"),[T]),B=n.useMemo(()=>T.filter(U=>U.area==="column"),[T]),Z=n.useMemo(()=>T.filter(U=>U.area==="data"),[T]),se=n.useMemo(()=>j.length===0?["Total"]:pi(t,j[0].field),[t,j]),ve=n.useMemo(()=>B.length===0?["Total"]:pi(t,B[0].field),[t,B]),O=n.useCallback((U,A,N)=>{let l=t;j.length>0&&(l=l.filter(de=>String(de[j[0].field])===U)),B.length>0&&(l=l.filter(de=>String(de[B[0].field])===A));const xe=l.map(de=>Number(de[N.field])||0),De=fa(xe,N.summaryType||"sum");return N.format?N.format(De):De},[t,j,B]),H=n.useCallback(U=>{v(U),s?.(U)},[s]),ce=n.useCallback((U,A)=>{let N=t;return j.length>0&&(N=N.filter(l=>String(l[j[0].field])===U)),B.length>0&&(N=N.filter(l=>String(l[B[0].field])===A)),N},[t,j,B]),le=n.useCallback((U,A)=>{g&&g(U,A,ce(U,A))},[g,ce]),fe=n.useCallback(()=>{const U=["",...ve.flatMap(de=>Z.length>0?Z.map(D=>`${de} - ${D.caption}`):[de])],A=se.map(de=>{const D=ve.flatMap(Y=>Z.length>0?Z.map(P=>String(O(de,Y,P))):["—"]);return[de,...D]}),N=[U,...A].map(de=>de.map(D=>`"${String(D).replace(/"/g,'""')}"`).join(",")).join(`
15
+ `),l=new Blob(["\uFEFF"+N],{type:"text/csv;charset=utf-8;"}),xe=URL.createObjectURL(l),De=document.createElement("a");De.href=xe,De.download=`${c}.csv`,De.click(),URL.revokeObjectURL(xe)},[ve,se,Z,O,c]);return V?null:e.jsxs("div",{className:`nice-pivotgrid ${w||""}`,style:R,children:[(r||f)&&e.jsxs("div",{className:"nice-pivotgrid__toolbar",children:[r&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:()=>_(!x),children:$("controls.fieldChooser","Field Chooser")}),f&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--sm",onClick:fe,children:"CSV ↓"})]}),x&&e.jsx(ji,{fields:T,onChange:H}),o?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:j.map(U=>U.caption).join(" / ")||""}),ve.map(U=>e.jsx("th",{colSpan:Z.length||1,children:U},U))]}),Z.length>1&&e.jsxs("tr",{children:[e.jsx("th",{}),ve.map(U=>Z.map(A=>e.jsx("th",{children:A.caption},`${U}-${A.field}`)))]})]}),e.jsx("tbody",{children:se.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:1+ve.length*Math.max(Z.length,1),className:"nice-pivotgrid__empty",children:u||$("controls.noData","No data available")})}):se.map(U=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-pivotgrid__row-header",children:U}),ve.map(A=>Z.length>0?Z.map(N=>e.jsx("td",{className:`nice-pivotgrid__cell ${g?"nice-pivotgrid__cell--clickable":""}`,onClick:g?()=>le(U,A):void 0,children:O(U,A,N)},`${A}-${N.field}`)):e.jsx("td",{className:"nice-pivotgrid__cell",children:"—"},A))]},U))})]})})]})},ga=Object.freeze(Object.defineProperty({__proto__:null,NicePivotGrid:Ni},Symbol.toStringTag,{value:"Module"}));function xa({open:t}){return e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{transition:"transform 160ms ease",transform:t?"rotate(0deg)":"rotate(-90deg)"},children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function _a(){return e.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}const ba=[{target:".nice-kanban",titleKey:"tutorial.kanbanBoard.intro.title",title:"Kanban board",contentKey:"tutorial.kanbanBoard.intro.content",content:'Drag cards between columns to change their status, add cards with the "+" button, and click a card to edit its details.',placement:"auto"}],wi=n.forwardRef(({columns:t,cards:a,onCardMove:s,onCardClick:r,renderCard:o,onAddCard:u,disabled:f=!1,size:c="md",collapsible:g=!1,layoutMode:w="scroll",viewMode:R,onViewModeChange:L,collapsedColumns:C,onCollapsedColumnsChange:Q,formItems:V,formColumns:$=1,formProps:T,editCardTitle:v,newCardTitle:x,onCardEdit:_,onCardCreate:j,onCardDelete:B,tutorial:Z,cookies:se=!1,localStorage:ve=!0,sessionStorage:O=!1,storageMode:H,storageKey:ce,className:le,style:fe,id:U,...A},N)=>{const{t:l}=ye.Zt(),[xe,De]=n.useState(null),[de,D]=n.useState(null),[Y,P]=n.useState(null),me=!!V&&(!!_||!!j),he=n.useCallback(I=>{if(me&&_){P({key:I.key,data:{...I},column:I.column});return}r?.(I)},[me,r,_]),Te=n.useCallback(I=>{if(me&&j){P({key:null,data:{title:"",description:""},column:I});return}u?.(I)},[me,u,j]),Ve=ye.useStorageAdapter(ce??"nice-kanban"),[Qe,ke]=n.useState(()=>Ve.get("state")??{collapsedColumns:[],viewMode:"default"}),$e=C??Qe.collapsedColumns??[],Ue=R??Qe.viewMode??"default",We=n.useCallback(I=>{ke(ue=>{const W={...ue,...I};return Ve.set("state",W),W})},[Ve]),J=n.useCallback(I=>{const ue=$e.includes(I)?$e.filter(W=>W!==I):[...$e,I];Q?Q(ue):We({collapsedColumns:ue})},[$e,Q,We]);n.useCallback(I=>{L?L(I):We({viewMode:I})},[L,We]);const _e=n.useCallback(I=>a.filter(ue=>ue.column===I).sort((ue,W)=>(ue.order??0)-(W.order??0)),[a]),je=n.useCallback((I,ue)=>{f||(I.dataTransfer.effectAllowed="move",I.dataTransfer.setData("text/plain",String(ue.key)),De({cardKey:ue.key,fromColumn:ue.column}))},[f]),ge=n.useCallback((I,ue)=>{I.preventDefault(),I.dataTransfer.dropEffect="move",D({column:ue})},[]),M=n.useCallback(()=>{D(null)},[]),ee=n.useCallback((I,ue)=>{if(I.preventDefault(),D(null),!xe||f)return;const W=_e(ue);s?.(xe.cardKey,ue,W.length),De(null)},[xe,f,_e,s]),Fe=n.useCallback(()=>{De(null),D(null)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:N,id:U,className:`nice-kanban nice-kanban--${c} nice-kanban--${Ue} nice-kanban--layout-${w} ${f?"nice-kanban--disabled":""} ${le||""}`,style:{position:"relative",...fe},...A,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(ye.Ll,{steps:ye.El(Z,ba)})}),t.map(I=>{const ue=_e(I.key),W=de?.column===I.key,Ie=I.limit!=null&&ue.length>=I.limit,Le=g&&$e.includes(I.key);return e.jsxs("div",{className:`nice-kanban__column ${W?"nice-kanban__column--dragover":""} ${Le?"nice-kanban__column--collapsed":""}`,onDragOver:te=>!Le&&ge(te,I.key),onDragLeave:M,onDrop:te=>!Le&&ee(te,I.key),children:[e.jsxs("div",{className:"nice-kanban__column-header",style:I.color?{borderTopColor:I.color}:void 0,onClick:g?()=>J(I.key):void 0,role:g?"button":void 0,tabIndex:g?0:void 0,onKeyDown:g?te=>{(te.key==="Enter"||te.key===" ")&&J(I.key)}:void 0,children:[g&&e.jsx("span",{className:"nice-kanban__collapse-icon","aria-hidden":"true",children:e.jsx(xa,{open:!Le})}),e.jsx("span",{className:"nice-kanban__column-title",children:I.title}),e.jsxs("span",{className:"nice-kanban__column-count",children:[ue.length,I.limit!=null&&` / ${I.limit}`]})]}),!Le&&e.jsxs("div",{className:"nice-kanban__column-body",children:[ue.map(te=>e.jsx("div",{className:`nice-kanban__card nice-kanban__card--${Ue} ${xe?.cardKey===te.key?"nice-kanban__card--dragging":""}`,draggable:!f,onDragStart:Ke=>je(Ke,te),onDragEnd:Fe,onClick:()=>he(te),role:"article",children:o?o(te):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"nice-kanban__card-title",children:te.title}),Ue!=="compact"&&te.description&&e.jsx("div",{className:"nice-kanban__card-desc",children:te.description})]})},te.key)),ue.length===0&&e.jsx("div",{className:"nice-kanban__empty",children:l("kanban.empty","No cards")})]}),!Le&&(u||me&&j)&&!Ie&&e.jsxs("button",{type:"button",className:"nice-kanban__add",onClick:()=>Te(I.key),disabled:f,children:[e.jsx(_a,{})," ",l("kanban.addCard","Add card")]})]},I.key)})]}),me&&Y&&e.jsxs(_i.NiceModal,{open:!0,onClose:()=>P(null),title:Y.key==null?x||l("kanban.newCard","New card"):v||l("kanban.editCard","Edit card"),children:[e.jsx(xi.NiceForm,{items:V,data:Y.data,columns:$,...T,onFieldChange:(I,ue)=>P(W=>W&&{...W,data:{...W.data,[I]:ue}})}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16,flexWrap:"wrap"},children:[Y.key!=null&&B&&e.jsx(ze.NiceButton,{type:"button",size:"sm",variant:"error",style:{marginRight:"auto"},onClick:()=>{B(Y.key),P(null)},children:l("controls.delete","Delete")}),e.jsx(ze.NiceButton,{type:"button",size:"sm",variant:"secondary",onClick:()=>P(null),children:l("controls.cancel","Cancel")}),e.jsx(ze.NiceButton,{type:"button",size:"sm",variant:"primary",onClick:()=>{if(Y.key==null){const I={key:`card-${Date.now()}`,title:"",column:Y.column,...Y.data};j?.(I)}else _?.(Y.key,{...Y.data,key:Y.key,column:Y.column});P(null)},children:l("controls.save","Save")})]})]})]})});wi.displayName="NiceKanbanBoard";function Ft(...t){return t.filter(Boolean).map(a=>typeof a=="object"?Object.entries(a).filter(([,s])=>s).map(([s])=>s).join(" "):a).join(" ")}const va=50,ya=[10,25,50,100,200],ja=40,Na=10,wa=768,ka=500,Sa=10;function _t(t,a){return a.split(".").reduce((s,r)=>s?.[r],t)}function kn(t,a,s="pl-PL"){if(t==null)return"—";switch(a.type){case"number":return new Intl.NumberFormat(s,{minimumFractionDigits:a.format?.includes(".")?a.format.split(".")[1].length:0}).format(t);case"currency":return new Intl.NumberFormat(s,{style:"currency",currency:a.currencyCode||"PLN"}).format(t);case"percent":return new Intl.NumberFormat(s,{style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}).format(t/100);case"date":return new Intl.DateTimeFormat(s,{dateStyle:"short"}).format(new Date(t));case"datetime":return new Intl.DateTimeFormat(s,{dateStyle:"short",timeStyle:"short"}).format(new Date(t));case"boolean":return t?"✓":"✗";case"enum":return a.enumOptions?.find(o=>o.value===t)?.label||String(t);default:return String(t)}}function Ca(t,a,s,r){const[o,u]=n.useState(0),{startIndex:f,endIndex:c,totalHeight:g,offsetY:w}=n.useMemo(()=>{const C=t.length*s,Q=Math.ceil(a/s),V=Math.max(0,Math.floor(o/s)-r),$=Math.min(t.length,Math.ceil(o/s)+Q+r),T=V*s;return{startIndex:V,endIndex:$,totalHeight:C,offsetY:T}},[t.length,a,s,o,r]),R=n.useMemo(()=>t.slice(f,c),[t,f,c]),L=n.useCallback(C=>{u(C.currentTarget.scrollTop)},[]);return{visibleData:R,totalHeight:g,offsetY:w,handleScroll:L,startIndex:f}}function Ma(t,a){const[s,r]=n.useState(()=>{if(t&&typeof window<"u"){const u=localStorage.getItem(`nice-module-grid-${t}`);if(u)return JSON.parse(u)}return a||{}}),o=n.useCallback(u=>{r(f=>{const c={...f,...u};return t&&typeof window<"u"&&localStorage.setItem(`nice-module-grid-${t}`,JSON.stringify(c)),c})},[t]);return[s,o]}function Da(t){const[a,s]=n.useState(typeof window<"u"&&window.innerWidth<t);return n.useEffect(()=>{if(typeof window>"u")return;const r=()=>s(window.innerWidth<t);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[t]),a}function Ia({column:t,sort:a,onSort:s,onResize:r,resizable:o,t:u}){const f=n.useRef(null),[c,g]=n.useState(!1),w=n.useCallback(C=>{if(!o||!r)return;C.preventDefault(),g(!0);const Q=C.clientX,V=t.width||150,$=v=>{const x=v.clientX-Q,_=Math.max(t.minWidth||50,V+x);r(t.field,Math.min(_,t.maxWidth||1/0))},T=()=>{g(!1),document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",T)};document.addEventListener("mousemove",$),document.addEventListener("mouseup",T)},[t,o,r]),R=a?.direction,L=R==="asc"?"↑":R==="desc"?"↓":null;return e.jsxs("div",{className:Ft("nice-module-grid__header-cell",t.sortable&&"nice-module-grid__header-cell--sortable",c&&"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&&s?.(t.field),role:"columnheader","aria-sort":R==="asc"?"ascending":R==="desc"?"descending":"none",title:t.headerTooltip,children:[e.jsx("span",{className:"nice-module-grid__header-text",children:t.header}),L&&e.jsx("span",{className:"nice-module-grid__sort-indicator",children:L}),o&&e.jsx("div",{ref:f,className:"nice-module-grid__resize-handle",onMouseDown:w})]})}function Ra({column:t,row:a,rowIndex:s,value:r,locale:o="pl-PL",onClick:u}){const f=ye.Ic({onClick:u}),c=u?f:{};if(t.render)return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:t.render(r,a,s)});if(t.type==="enum"&&t.enumOptions){const g=t.enumOptions.find(w=>w.value===r);if(g)return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:e.jsxs("span",{className:Ft("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(r)||0));return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:e.jsxs("div",{className:"nice-module-grid__progress",children:[e.jsx("div",{className:Ft("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,w=Number(r)||0;return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:e.jsx("span",{className:"nice-module-grid__rating","aria-label":`${w} out of ${g} stars`,children:Array.from({length:g},(R,L)=>e.jsx("span",{className:Ft("nice-module-grid__star",L<w&&"nice-module-grid__star--filled"),children:"★"},L))})})}if(t.type==="link"&&t.linkTemplate){const g=t.linkTemplate.replace(/\{\{(\w+)\}\}/g,(w,R)=>String(_t(a,R)??""));return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,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:kn(r,t,o)})})}if(t.type==="image"){const w={xs:24,sm:32,md:48,lg:64}[t.imageSize||"sm"];return e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:r?e.jsx("img",{src:String(r),alt:"",className:"nice-module-grid__image",style:{width:w,height:w}}):e.jsx("div",{className:"nice-module-grid__image-placeholder",style:{width:w,height:w}})})}return t.type==="avatar"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:r?e.jsx("img",{src:String(r),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},...c,children:e.jsx("span",{className:"nice-module-grid__color-swatch",style:{backgroundColor:r||"transparent"},title:r})}):t.type==="boolean"?e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align||"center"},...c,children:e.jsx("span",{className:Ft("nice-module-grid__boolean",!!r&&"nice-module-grid__boolean--true"),children:r?"✓":"✗"})}):e.jsx("div",{className:"nice-module-grid__cell",style:{textAlign:t.align},...c,children:kn(r,t,o)})}function Aa({row:t,index:a,columns:s,primaryField:r,secondaryField:o,customRender:u,selected:f,onClick:c,locale:g="pl-PL",t:w}){if(u)return e.jsx("div",{className:Ft("nice-module-grid__mobile-card",f&&"nice-module-grid__mobile-card--selected"),onClick:c,children:u(t,a)});const R=s.find(C=>C.field===r)||s[0],L=s.find(C=>C.field===o)||s[1];return e.jsxs("div",{className:Ft("nice-module-grid__mobile-card",f&&"nice-module-grid__mobile-card--selected"),onClick:c,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:kn(_t(t,R?.field||""),R,g)}),L&&e.jsx("div",{className:"nice-module-grid__mobile-card-subtitle",children:kn(_t(t,L.field),L,g)})]}),e.jsx("div",{className:"nice-module-grid__mobile-card-body",children:s.filter(C=>!C.hidden&&C.field!==r&&C.field!==o).slice(0,4).map(C=>e.jsxs("div",{className:"nice-module-grid__mobile-card-field",children:[e.jsx("span",{className:"nice-module-grid__mobile-card-label",children:C.header}),e.jsx("span",{className:"nice-module-grid__mobile-card-value",children:kn(_t(t,C.field),C,g)})]},C.field))})]})}function Ea({page:t,pageSize:a,totalRows:s,pageSizeOptions:r,onPageChange:o,t:u}){const f=Math.ceil(s/a),c=(t-1)*a+1,g=Math.min(t*a,s);return e.jsxs("div",{className:"nice-module-grid__pagination",role:"navigation","aria-label":u("pagination.ariaLabel","Pagination"),children:[e.jsxs("div",{className:"nice-module-grid__pagination-info",children:[u("pagination.showing","Showing")," ",c,"–",g," ",u("pagination.of","of")," ",s]}),e.jsxs("div",{className:"nice-module-grid__pagination-controls",children:[e.jsx("select",{className:"nice-module-grid__page-size-select",value:a,onChange:w=>o(1,Number(w.target.value)),"aria-label":u("pagination.rowsPerPage","Rows per page"),children:r.map(w=>e.jsx("option",{value:w,children:w},w))}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>o(1,a),disabled:t===1,"aria-label":u("pagination.first","First"),children:"««"}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>o(t-1,a),disabled:t===1,"aria-label":u("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:()=>o(t+1,a),disabled:t>=f,"aria-label":u("pagination.next","Next"),children:"»"}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>o(f,a),disabled:t>=f,"aria-label":u("pagination.last","Last"),children:"»»"})]})]})}function $a({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 La(t,a){const{columns:s,data:r,keyField:o="id",dataSource:u,onFetch:f,sortable:c=!0,sort:g,onSortChange:w,multiSort:R=!1,filterable:L=!1,filter:C,onFilterChange:Q,searchText:V,onSearchChange:$,searchPlaceholder:T="moduleGrid.searchPlaceholder",pagination:v=!0,page:x,pageSize:_,pageSizeOptions:j=ya,totalRows:B,onPageChange:Z,virtualScroll:se=!0,rowHeight:ve=ja,overscan:O=Na,selectionMode:H="none",selectedKeys:ce,onSelectionChange:le,columnReorder:fe=!0,onColumnOrderChange:U,columnResize:A=!0,onColumnWidthChange:N,groupBy:l,onGroupByChange:xe,groupRowRender:De,expandAllGroups:de=!1,editable:D=!1,onCellEdit:Y,onRowEdit:P,editMode:me="cell",contextMenuItems:he,onContextMenuAction:Te,exportable:Ve=!0,exportFormats:Qe=["csv","excel"],onExport:ke,preferencesKey:$e,initialPreferences:Ue,onPreferencesChange:We,density:J="normal",striped:_e=!0,bordered:je=!1,hoverable:ge=!0,loading:M=!1,emptyState:ee,toolbar:Fe,onRowClick:I,onRowDoubleClick:ue,rowClassName:W,rowStyle:Ie,mobileCardView:Le=!0,mobileBreakpoint:te=wa,mobileCardRender:Ke,mobilePrimaryField:Ye,mobileSecondaryField:it,moduleId:Ne,permissions:jt,size:Pt="medium",skeletonLoading:mt=!0,skeletonRows:Nt=Sa,"aria-label":E,"aria-labelledby":ae,"aria-describedby":oe,className:qe,style:rt,id:we,testId:Pe}=t,{t:Se}=ye.Zt();ye.pc(),ye.Fs("table");const ct=Da(te),[Ze,wt]=Ma($e,Ue),bt=n.useRef(null),cn=n.useRef(null),[Qt,Yt]=n.useState([]),[at,Fn]=n.useState(),[Sn,Jt]=n.useState(""),[ln,kt]=n.useState(1),[fn,m]=n.useState(_||va),[h,z]=n.useState(new Set),[K,ie]=n.useState([]),[F,k]=n.useState(0),[q,X]=n.useState(!1),[Oe,Ae]=n.useState(new Set),[Ce,et]=n.useState(null),[Zt,en]=n.useState({}),nt=g??Qt,Ot=C??at,St=V??Sn,tn=x??ln,qt=_??fn,Ct=ce??h,gn=B??F??r?.length??0,Bt=!!(f||u),st=n.useMemo(()=>{const y=new Set(Ze.hiddenColumns||[]);return s.filter(pe=>!pe.hidden&&!y.has(pe.field))},[s,Ze.hiddenColumns]),nn=n.useMemo(()=>{if(Bt)return K;if(!r)return[];let y=[...r];if(St){const pe=St.toLowerCase(),Me=s.filter(Ee=>Ee.searchable!==!1).map(Ee=>Ee.field);y=y.filter(Ee=>Me.some(ot=>{const It=_t(Ee,ot);return String(It??"").toLowerCase().includes(pe)}))}return nt.length>0&&y.sort((pe,Me)=>{for(const Ee of nt){const ot=_t(pe,Ee.field),It=_t(Me,Ee.field),Rt=ot<It?-1:ot>It?1:0;if(Rt!==0)return Ee.direction==="asc"?Rt:-Rt}return 0}),y},[Bt,K,r,St,nt,s]),Ut=n.useMemo(()=>{if(Bt||!v)return nn;const y=(tn-1)*qt;return nn.slice(y,y+qt)},[Bt,nn,v,tn,qt]),xn=bt.current?.clientHeight||400,Mt=se&&Ut.length>ka,{visibleData:Pn,totalHeight:Et,offsetY:_n,handleScroll:on,startIndex:Wt}=Ca(Ut,xn,ve,O),lt=Mt?Pn:Ut,$t=n.useCallback(async()=>{if(f){X(!0);try{const pe=await f({page:tn,pageSize:qt,sort:nt,filter:Ot,search:St});ie(pe.data),k(pe.total)}catch(y){console.error("NiceModuleGrid fetch error:",y)}finally{X(!1)}}},[f,tn,qt,nt,Ot,St]);n.useEffect(()=>{Bt&&$t()},[Bt,$t]);const dn=n.useCallback(y=>{const pe=nt.find(Ee=>Ee.field===y);let Me;pe?pe.direction==="asc"?Me=nt.map(Ee=>Ee.field===y?{...Ee,direction:"desc"}:Ee):Me=nt.filter(Ee=>Ee.field!==y):Me=R?[...nt,{field:y,direction:"asc"}]:[{field:y,direction:"asc"}],w?w(Me):Yt(Me)},[nt,R,w]),Cn=n.useCallback((y,pe)=>{Z?Z(y,pe):(kt(y),m(pe))},[Z]),Mn=n.useCallback(y=>{$?$(y):Jt(y),Z||kt(1)},[$,Z]),bn=n.useCallback((y,pe)=>{const Me=new Set(Ct);if(H==="single"?(Me.clear(),Me.add(y)):(H==="multiple"||H==="checkbox")&&(Me.has(y)?Me.delete(y):Me.add(y)),le){const Ee=Ut.filter(ot=>Me.has(String(_t(ot,o))));le(Me,Ee)}else z(Me)},[Ct,H,le,Ut,o]),vn=n.useCallback((y,pe)=>{en(Me=>({...Me,[y]:pe})),N?.(y,pe),wt({columnWidths:{...Ze.columnWidths,[y]:pe}})},[N,wt,Ze.columnWidths]),On=n.useCallback((y,pe)=>{he?.length&&(y.preventDefault(),et({x:y.clientX,y:y.clientY,row:pe}))},[he]),Bn=n.useCallback(y=>{Ce&&Te?.(y,Ce.row),et(null)},[Ce,Te]),un=n.useCallback(async y=>{if(ke)await ke(y,{selectedOnly:Ct.size>0,columns:st.map(pe=>pe.field)});else if(y==="csv"){const pe=st.map(dt=>dt.header).join(","),Me=Ut.map(dt=>st.map(Hn=>JSON.stringify(_t(dt,Hn.field)??"")).join(",")),Ee=[pe,...Me].join(`
16
+ `),ot=new Blob([Ee],{type:"text/csv;charset=utf-8;"}),It=URL.createObjectURL(ot),Rt=document.createElement("a");Rt.href=It,Rt.download=`export-${new Date().toISOString().slice(0,10)}.csv`,Rt.click(),URL.revokeObjectURL(It)}},[ke,Ct,st,Ut,Se]);n.useEffect(()=>{if(!Ce)return;const y=()=>et(null);return document.addEventListener("click",y),()=>document.removeEventListener("click",y)},[Ce]);const Dt=n.useCallback(y=>{y.key==="Escape"&&et(null)},[]),Gt=M||q,Vt=!Gt&&lt.length===0,Kt=ct&&Le,Xt=Ft("nice-module-grid",`nice-module-grid--${J}`,`nice-module-grid--${Pt}`,_e&&"nice-module-grid--striped",je&&"nice-module-grid--bordered",ge&&"nice-module-grid--hoverable",Gt&&"nice-module-grid--loading",Kt&&"nice-module-grid--mobile",qe);return e.jsxs("div",{ref:a,id:we,"data-testid":Pe,className:Xt,style:rt,onKeyDown:Dt,role:"grid","aria-label":E,"aria-labelledby":ae,"aria-describedby":oe,"aria-rowcount":gn,"aria-colcount":st.length,"aria-busy":Gt,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:T,value:St,onChange:y=>Mn(y.target.value),"aria-label":Se("moduleGrid.searchAriaLabel","Search")})}),Fe,Ve&&e.jsx("div",{className:"nice-module-grid__toolbar-export",children:Qe.map(y=>e.jsx("button",{className:"nice-module-grid__export-btn",onClick:()=>un(y),"aria-label":Se(`moduleGrid.export.${y}`,`Export to ${y.toUpperCase()}`),children:y.toUpperCase()},y))})]}),e.jsx("div",{ref:bt,className:"nice-module-grid__container",onScroll:Mt?on:void 0,children:Kt?e.jsx("div",{className:"nice-module-grid__mobile-list",children:Gt&&mt?Array.from({length:Nt},(y,pe)=>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}})]},pe)):Vt?e.jsxs("div",{className:"nice-module-grid__empty",children:[ee?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:ee.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:ee?.title||Se("moduleGrid.noData","No data")}),ee?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:ee.description}),ee?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:ee.action.onClick,children:[ee.action.icon,ee.action.label]})]}):lt.map((y,pe)=>{const Me=String(_t(y,o));return e.jsx(Aa,{row:y,index:Wt+pe,columns:st,primaryField:Ye,secondaryField:it,customRender:Ke,selected:Ct.has(Me),onClick:()=>{H!=="none"&&bn(Me,y),I?.(y,Wt+pe)},t:Se},Me)})}):e.jsxs("div",{ref:cn,className:"nice-module-grid__table",children:[e.jsxs("div",{className:"nice-module-grid__header",role:"row",children:[H==="checkbox"&&e.jsx("div",{className:"nice-module-grid__header-cell nice-module-grid__header-cell--checkbox",children:e.jsx("input",{type:"checkbox",checked:Ct.size>0&&Ct.size===lt.length,onChange:()=>{if(Ct.size===lt.length)le?.(new Set,[]),z(new Set);else{const y=new Set(lt.map(pe=>String(_t(pe,o))));le?.(y,lt),z(y)}},"aria-label":Se("moduleGrid.selectAll","Select all")})}),st.map(y=>e.jsx(Ia,{column:{...y,width:Zt[y.field]||y.width},sort:nt.find(pe=>pe.field===y.field),onSort:c?dn:void 0,onResize:A?vn:void 0,resizable:A,t:Se},y.field))]}),e.jsx("div",{className:"nice-module-grid__body",style:Mt?{height:Et,position:"relative"}:void 0,children:Gt&&mt?Array.from({length:Nt},(y,pe)=>e.jsx($a,{columns:st},pe)):Vt?e.jsxs("div",{className:"nice-module-grid__empty",children:[ee?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:ee.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:ee?.title||Se("moduleGrid.noData","No data")}),ee?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:ee.description}),ee?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:ee.action.onClick,children:[ee.action.icon,ee.action.label]})]}):e.jsx("div",{style:Mt?{transform:`translateY(${_n}px)`}:void 0,children:lt.map((y,pe)=>{const Me=String(_t(y,o)),Ee=Wt+pe,ot=Ct.has(Me),It=typeof W=="function"?W(y,Ee):W,Rt=typeof Ie=="function"?Ie(y,Ee):Ie;return e.jsxs("div",{className:Ft("nice-module-grid__row",ot&&"nice-module-grid__row--selected",It),style:{...Rt,height:ve},role:"row","aria-rowindex":Ee+1,"aria-selected":ot,onClick:()=>{H!=="none"&&bn(Me,y),I?.(y,Ee)},onDoubleClick:()=>ue?.(y,Ee),onContextMenu:dt=>On(dt,y),children:[H==="checkbox"&&e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--checkbox",children:e.jsx("input",{type:"checkbox",checked:ot,onChange:()=>bn(Me,y),onClick:dt=>dt.stopPropagation(),"aria-label":Se("moduleGrid.selectRow","Select row")})}),st.map(dt=>e.jsx(Ra,{column:{...dt,width:Zt[dt.field]||dt.width},row:y,rowIndex:Ee,value:_t(y,dt.field)},dt.field))]},Me)})})})]})}),v&&gn>0&&e.jsx(Ea,{page:tn,pageSize:qt,totalRows:Bt?F:nn.length,pageSizeOptions:j,onPageChange:Cn,t:Se}),Ce&&he&&e.jsx("div",{className:"nice-module-grid__context-menu",style:{left:Ce.x,top:Ce.y},role:"menu",children:he.filter(y=>typeof y.hidden=="function"?!y.hidden(Ce.row):!y.hidden).map(y=>{if(y.divider)return e.jsx("div",{className:"nice-module-grid__context-menu-divider"},y.key);const pe=typeof y.disabled=="function"?y.disabled(Ce.row):y.disabled;return e.jsxs("button",{className:Ft("nice-module-grid__context-menu-item",y.danger&&"nice-module-grid__context-menu-item--danger",pe&&"nice-module-grid__context-menu-item--disabled"),onClick:()=>{pe||(y.onClick?.(Ce.row),Bn(y.key))},disabled:pe,role:"menuitem",children:[y.icon&&e.jsx("span",{className:"nice-module-grid__context-menu-icon",children:y.icon}),y.label]},y.key)})}),Gt&&!mt&&e.jsx("div",{className:"nice-module-grid__loading-overlay",children:e.jsx("div",{className:"nice-module-grid__spinner","aria-label":Se("moduleGrid.loading","Loading")})})]})}const za=n.forwardRef(La),Ta=`
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 Tt(t,a="PLN",s="pl-PL"){return new Intl.NumberFormat(s,{style:"currency",currency:a,minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function zn(t,a="pl-PL"){return t?(typeof t=="string"?new Date(t):t).toLocaleDateString(a,{year:"numeric",month:"2-digit",day:"2-digit"}):"-"}function Fa(t){return t>=80?"high":t>=50?"medium":"low"}function Pa(){return`match-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function Oa({item:t,isSelected:a,isDragging:s,isDropTarget:r,suggestion:o,currency:u,locale:f,onSelect:c,onDoubleClick:g,onDragStart:w,onDragEnd:R,onDrop:L,disabled:C}){const Q=t.status??"unmatched",V=o?.confidence??t.confidence,$=v=>{v.dataTransfer.setData("text/plain",t.id),v.dataTransfer.setData("source","statement"),v.dataTransfer.effectAllowed="move",w()},T=v=>{v.dataTransfer.types.includes("source")&&v.dataTransfer.getData("source")!=="statement"&&v.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${Q} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${r?"nice-reconciliation__row--drop-target":""}`,draggable:!C&&Q!=="matched",onDragStart:$,onDragEnd:R,onDragOver:T,onDrop:L,onClick:c,onDoubleClick:g,role:"row","aria-selected":a,tabIndex:0,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${Q}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsx("div",{className:"nice-reconciliation__row-date",children:zn(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})]}),V!=null&&e.jsxs("span",{className:`nice-reconciliation__confidence nice-reconciliation__confidence--${Fa(V)}`,children:[V,"%"]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Tt(t.amount,u,f)})]})}function Ba({item:t,isSelected:a,isDragging:s,isDropTarget:r,currency:o,locale:u,onSelect:f,onDoubleClick:c,onDragStart:g,onDragEnd:w,onDrop:R,disabled:L}){const C=t.status??"unmatched",Q=$=>{$.dataTransfer.setData("text/plain",t.id),$.dataTransfer.setData("source","entry"),$.dataTransfer.effectAllowed="move",g()},V=$=>{$.dataTransfer.types.includes("source")&&$.dataTransfer.getData("source")!=="entry"&&$.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${C} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${r?"nice-reconciliation__row--drop-target":""}`,draggable:!L&&C!=="matched",onDragStart:Q,onDragEnd:w,onDragOver:V,onDrop:R,onClick:f,onDoubleClick:c,role:"row","aria-selected":a,tabIndex:0,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${C}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsxs("div",{className:"nice-reconciliation__row-date",children:[zn(t.date,u),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:Tt(t.amount,o,u)})]})}const Ua=n.forwardRef(function(a,s){const{statements:r,bankTransactions:o,entries:u,accountingEntries:f,matches:c,defaultMatches:g=[],suggestions:w=[],config:R={},currency:L,showConfidence:C,statementPanelConfig:Q,entryPanelConfig:V,onMatch:$,onAutoMatch:T,onUnmatch:v,onBatchAction:x,onFilterChange:_,onRequestSuggestions:j,onSelectionChange:B,onComplete:Z,size:se="medium",showToolbar:ve=!0,showFilters:O=!0,showSummary:H=!0,showSuggestions:ce=!0,layout:le="horizontal",enableDragDrop:fe=!0,enableKeyboard:U=!0,enableDetailPanel:A=!0,loading:N=!1,disabled:l=!1,readOnly:xe=!1,locale:De="pl-PL",labels:de={},className:D,style:Y}=a,P=r??o??[],me=u??f??[],he=L??R.currency??"PLN",[Te,Ve]=n.useState(g),[Qe,ke]=n.useState(new Set),[$e,Ue]=n.useState(new Set),[We,J]=n.useState(null),[_e,je]=n.useState(null),[ge,M]=n.useState({}),[ee,Fe]=n.useState(null),I=c??Te,ue=n.useRef(null),W=n.useRef(null);n.useEffect(()=>{const E="nice-reconciliation-styles";if(!document.getElementById(E)){const ae=document.createElement("style");ae.id=E,ae.textContent=Ta,document.head.appendChild(ae)}},[]);const Ie=n.useMemo(()=>{const E=new Set;return I.forEach(ae=>ae.statementIds.forEach(oe=>E.add(oe))),E},[I]),Le=n.useMemo(()=>{const E=new Set;return I.forEach(ae=>ae.entryIds.forEach(oe=>E.add(oe))),E},[I]),te=n.useMemo(()=>{const E=P.filter(we=>!Ie.has(we.id)),ae=me.filter(we=>!Le.has(we.id)),oe=P.reduce((we,Pe)=>we+Pe.amount,0),qe=me.reduce((we,Pe)=>we+Pe.amount,0),rt=P.filter(we=>Ie.has(we.id)).reduce((we,Pe)=>we+Pe.amount,0);return{totalStatements:P.length,totalEntries:me.length,matchedStatements:P.length-E.length,matchedEntries:me.length-ae.length,unmatchedStatements:E.length,unmatchedEntries:ae.length,statementTotal:oe,entryTotal:qe,matchedAmount:rt,unmatchedStatementAmount:E.reduce((we,Pe)=>we+Pe.amount,0),unmatchedEntryAmount:ae.reduce((we,Pe)=>we+Pe.amount,0),difference:oe-qe,matchPercentage:P.length>0?Math.round((P.length-E.length)/P.length*100):0,matchCount:I.length,partialMatchCount:I.filter(we=>we.status==="partial").length,pendingSuggestions:w.length}},[P,me,I,w,Ie,Le]),Ke=n.useCallback((E,ae)=>{const oe=P.filter(Ze=>E.includes(Ze.id)),qe=me.filter(Ze=>ae.includes(Ze.id));if(oe.length===0||qe.length===0)return null;const rt=oe.reduce((Ze,wt)=>Ze+wt.amount,0),we=qe.reduce((Ze,wt)=>Ze+wt.amount,0),Pe=Math.abs(rt-we),Se=R.amountTolerance??.01,ct={id:Pa(),statementIds:E,entryIds:ae,status:Pe<=Se?"matched":"partial",statementTotal:rt,entryTotal:we,difference:Pe,confidence:Pe<=Se?100:Math.max(0,100-Pe/Math.max(Math.abs(rt),1)*100),matchedBy:"user",matchedAt:new Date};return c||Ve(Ze=>[...Ze,ct]),$?.(ct,oe,qe),ke(new Set),Ue(new Set),ct},[P,me,R.amountTolerance,c,$]),Ye=n.useCallback(E=>{const ae=I.find(oe=>oe.id===E);ae&&(c||Ve(oe=>oe.filter(qe=>qe.id!==E)),v?.(E,ae.statementIds,ae.entryIds))},[I,c,v]),it=n.useCallback(async()=>{const E=[],ae=new Set(Ie),oe=new Set(Le),qe=R.amountTolerance??.01,rt=R.dateTolerance??3;for(const we of P){if(ae.has(we.id))continue;const Pe=me.filter(Se=>{if(oe.has(Se.id)||Math.abs(we.amount-Se.amount)>qe)return!1;const Ze=new Date(we.date),wt=new Date(Se.date);return!(Math.abs(Ze.getTime()-wt.getTime())/(1e3*60*60*24)>rt)});if(Pe.length===1){const Se=Pe[0],ct=Ke([we.id],[Se.id]);ct&&(E.push(ct),ae.add(we.id),oe.add(Se.id))}}return x?.("autoMatch",E),E},[P,me,Ie,Le,R,Ke,x]),Ne=n.useCallback((E,ae,oe,qe)=>{qe!==ae&&(qe==="statement"?Ke([oe],[E]):Ke([E],[oe]),J(null),je(null))},[Ke]),jt=n.useCallback(()=>{const E=Array.from(Qe),ae=Array.from($e);E.length>0&&ae.length>0&&Ke(E,ae)},[Qe,$e,Ke]);n.useEffect(()=>{B?.(Array.from(Qe),Array.from($e))},[Qe,$e,B]),n.useImperativeHandle(s,()=>({getMatches:()=>I,getUnmatchedStatements:()=>P.filter(E=>!Ie.has(E.id)),getUnmatchedEntries:()=>me.filter(E=>!Le.has(E.id)),createMatch:Ke,removeMatch:Ye,autoMatch:it,getSuggestions:async E=>j?j(E??P.filter(ae=>!Ie.has(ae.id)).map(ae=>ae.id)):[],applySuggestion:E=>Ke([E.statementId],E.entryIds),approveAll:()=>{x?.("approveAll",I)},clearAll:()=>{c||Ve([]),x?.("clearAll",[])},exportMatched:E=>{x?.("exportMatched",I)},getSummary:()=>te,reset:()=>{c||Ve([]),ke(new Set),Ue(new Set),M({})},focusStatements:()=>ue.current?.focus(),focusEntries:()=>W.current?.focus()}),[I,P,me,Ie,Le,Ke,Ye,it,j,x,c,te]);const Pt=n.useMemo(()=>P.filter(E=>{if(ge.status&&ge.status.length>0){const ae=Ie.has(E.id)?"matched":"unmatched";if(!ge.status.includes(ae))return!1}if(ge.searchText){const ae=ge.searchText.toLowerCase();if(!E.description?.toLowerCase().includes(ae)&&!E.counterparty?.toLowerCase().includes(ae))return!1}return!0}),[P,ge,Ie]),mt=n.useMemo(()=>me.filter(E=>{if(ge.status&&ge.status.length>0){const ae=Le.has(E.id)?"matched":"unmatched";if(!ge.status.includes(ae))return!1}if(ge.searchText){const ae=ge.searchText.toLowerCase();if(!E.description?.toLowerCase().includes(ae)&&!E.partyName?.toLowerCase().includes(ae))return!1}return!0}),[me,ge,Le]),Nt=Qe.size>0&&$e.size>0&&!xe&&!l;return e.jsxs("div",{className:`nice-reconciliation nice-reconciliation--${le} ${D??""}`,style:Y,children:[ve&&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:it,disabled:l||xe||N,children:["⚡ ",de.autoMatch??"Auto-match"]}),e.jsx("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--success",onClick:jt,disabled:!Nt||N,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:()=>x?.("approveAll",I),disabled:I.length===0||l||N,children:["✓ ",de.approveAll??"Approve All"]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>{c||Ve([]),x?.("clearAll",[])},disabled:I.length===0||l||xe||N,children:["✕ ",de.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:["📄 ",de.statementPanelTitle??"Bank Statement",e.jsx("span",{className:"nice-reconciliation__panel-badge",children:Pt.length})]})}),e.jsx("div",{ref:ue,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:Pt.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:"📋"}),de.noStatements??"No statement items"]}):Pt.map(E=>e.jsx(Oa,{item:{...E,status:Ie.has(E.id)?"matched":"unmatched"},isSelected:Qe.has(E.id),isDragging:We===E.id,isDropTarget:_e===E.id,suggestion:w.find(ae=>ae.statementId===E.id),currency:he,locale:De,onSelect:()=>{l||ke(ae=>{const oe=new Set(ae);return oe.has(E.id)?oe.delete(E.id):oe.add(E.id),oe})},onDoubleClick:()=>A&&Fe({type:"statement",id:E.id}),onDragStart:()=>J(E.id),onDragEnd:()=>{J(null),je(null)},onDrop:()=>{We&&We!==E.id&&Ne(E.id,"statement",We,"entry")},disabled:l||xe||!fe},E.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:["📒 ",de.entryPanelTitle??"Book Entries",e.jsx("span",{className:"nice-reconciliation__panel-badge",children:mt.length})]})}),e.jsx("div",{ref:W,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:mt.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:"📚"}),de.noEntries??"No book entries"]}):mt.map(E=>e.jsx(Ba,{item:{...E,status:Le.has(E.id)?"matched":"unmatched"},isSelected:$e.has(E.id),isDragging:We===E.id,isDropTarget:_e===E.id,currency:he,locale:De,onSelect:()=>{l||Ue(ae=>{const oe=new Set(ae);return oe.has(E.id)?oe.delete(E.id):oe.add(E.id),oe})},onDoubleClick:()=>A&&Fe({type:"entry",id:E.id}),onDragStart:()=>J(E.id),onDragEnd:()=>{J(null),je(null)},onDrop:()=>{We&&We!==E.id&&Ne(E.id,"entry",We,"statement")},disabled:l||xe||!fe},E.id))})]})]}),H&&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:[te.matchedStatements,"/",te.totalStatements," (",te.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:Tt(te.matchedAmount,he,De)})]}),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:Tt(te.unmatchedStatementAmount,he,De)})]}),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(te.difference)<.01?"nice-reconciliation__summary-value--success":"nice-reconciliation__summary-value--danger"}`,children:Tt(te.difference,he,De)})]})]}),A&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`nice-reconciliation__detail-backdrop ${ee?"nice-reconciliation__detail-backdrop--visible":""}`,onClick:()=>Fe(null)}),e.jsx("div",{className:`nice-reconciliation__detail-panel ${ee?"nice-reconciliation__detail-panel--open":""}`,children:ee&&e.jsx(Wa,{type:ee.type,id:ee.id,statements:P,entries:me,matches:I,currency:he,locale:De,labels:de,onClose:()=>Fe(null)})})]})]})});function Wa({type:t,id:a,statements:s,entries:r,matches:o,currency:u,locale:f,labels:c,onClose:g}){const w=t==="statement"?s.find($=>$.id===a):r.find($=>$.id===a),R=t==="statement"?o.find($=>$.statementIds.includes(a)):o.find($=>$.entryIds.includes(a)),L=R?t==="statement"?r.filter($=>R.entryIds.includes($.id)):s.filter($=>R.statementIds.includes($.id)):[];if(!w)return null;const C=t==="statement",Q=C?w:null,V=C?null:w;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-reconciliation__detail-header",children:[e.jsxs("span",{className:"nice-reconciliation__detail-title",children:[C?"📄":"📒"," ",C?c.statementDetails??"Transaction Details":c.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:[R&&e.jsxs("div",{className:"nice-reconciliation__detail-match-info",children:[e.jsxs("div",{className:"nice-reconciliation__detail-match-header",children:["✓ ",c.matchedWith??"Matched"," (",R.confidence?.toFixed(0)??100,"% confidence)"]}),e.jsx("div",{className:"nice-reconciliation__detail-match-detail",children:R.matchedBy==="ai"?c.matchedByAI??"Matched automatically by AI":c.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:c.statementTotal??"Statement"}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${R.statementTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Tt(R.statementTotal,u,f)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:c.entryTotal??"Book Entry"}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${R.entryTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Tt(R.entryTotal,u,f)})]})]}),R.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:[c.difference??"Difference",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{color:"var(--nice-warning, #f59e0b)"},children:Tt(R.difference,u,f)})]})]}),e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:["📋"," ",C?c.transactionInfo??"Transaction Information":c.entryInfo??"Entry Information"]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.date??"Date",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:zn(w.date,f)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.description??"Description",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:w.description})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.amount??"Amount",":"]}),e.jsx("span",{className:`nice-reconciliation__detail-value ${w.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Tt(w.amount,u,f)})]}),C&&Q?.counterparty&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.counterparty??"Counterparty",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:Q.counterparty})]}),C&&Q?.counterpartyAccount&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.accountNumber??"Account",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:Q.counterpartyAccount})]}),!C&&V?.partyName&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.party??"Party",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:V.partyName})]}),!C&&V?.documentNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.documentRef??"Document Ref",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:V.documentNumber})]}),C&&Q?.referenceNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.reference??"Reference",":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:Q.referenceNumber})]})]}),L.length>0&&e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:["🔗"," ",C?c.matchedEntries??"Matched Entries":c.matchedStatements??"Matched Statements"]}),L.map($=>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:$.description}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:"var(--nice-text-secondary)"},children:[e.jsx("span",{children:zn($.date,f)}),e.jsx("span",{style:{fontWeight:600,color:$.amount>=0?"var(--nice-success)":"var(--nice-danger)"},children:Tt($.amount,u,f)})]})]},$.id))]})]})]})}function Ga(t,a,s){const r=new Map,o=[];t.forEach(f=>r.set(String(f[a]),{data:f,children:[],key:String(f[a]),depth:0})),t.forEach(f=>{const c=f[s],g=r.get(String(f[a]));if(c!=null&&c!==""&&r.has(String(c))){const w=r.get(String(c));g.depth=w.depth+1,w.children.push(g)}else o.push(g)});const u=(f,c)=>{f.forEach(g=>{g.depth=c,u(g.children,c+1)})};return u(o,0),o}function ki(t,a,s,r=0){return t.map(o=>({data:o,key:String(o[s]),depth:r,children:Array.isArray(o[a])?ki(o[a],a,s,r+1):[]}))}function Va(t){const a=[],s=r=>{r.forEach(o=>{a.push(o.key),s(o.children)})};return s(t),a}function Ka(t,a){const s=[],r=o=>{o.forEach(u=>{s.push(u),u.children.length>0&&a.has(u.key)&&r(u.children)})};return r(t),s}function Si(t,a,s){return!a||!s?t:[...t].sort((o,u)=>{const f=o.data[a]??"",c=u.data[a]??"",g=typeof f=="number"&&typeof c=="number"?f-c:String(f).localeCompare(String(c));return s==="desc"?-g:g}).map(o=>({...o,children:Si(o.children,a,s)}))}function Za({columns:t,data:a,keyField:s="id",parentKeyField:r="parentId",nested:o=!1,childrenField:u="children",expandedKeys:f,onExpandedChange:c,defaultExpandAll:g=!1,sortable:w=!0,sortField:R,sortDirection:L,onSort:C,selectable:Q,selectedKeys:V,onSelectionChange:$,searchable:T,searchPlaceholder:v,striped:x,compact:_,loading:j,emptyText:B,toolbar:Z,onRowClick:se,className:ve,style:O}){const{t:H}=ye.Zt(),ce=n.useMemo(()=>o?ki(a,u,s):Ga(a,s,r),[a,s,r,o,u]),le=n.useMemo(()=>Va(ce),[ce]),[fe,U]=n.useState(()=>g?new Set(le):new Set),A=f?new Set(f):fe,[N,l]=n.useState({field:"",dir:null}),[xe,De]=n.useState(new Set),[de,D]=n.useState(""),Y=R??N.field,P=L??N.dir,me=V??xe,he=n.useMemo(()=>t.filter(J=>!J.hidden),[t]),Te=n.useCallback(J=>{const _e=Y===J?P==="asc"?"desc":P==="desc"?null:"asc":"asc";C?C(J,_e):l({field:J,dir:_e})},[Y,P,C]),Ve=n.useCallback(J=>{const _e=new Set(A);_e.has(J)?_e.delete(J):_e.add(J),c?c([..._e]):U(_e)},[A,c]),Qe=n.useCallback(J=>{const _e=new Set(me);_e.has(J)?_e.delete(J):_e.add(J),$?$(_e):De(_e)},[me,$]),ke=n.useMemo(()=>{if(!de)return ce;const J=de.toLowerCase(),_e=je=>je.reduce((ge,M)=>{const ee=_e(M.children);return(he.some(I=>String(M.data[I.field]??"").toLowerCase().includes(J))||ee.length>0)&&ge.push({...M,children:ee}),ge},[]);return _e(ce)},[ce,de,he]),$e=n.useMemo(()=>Si(ke,Y,P),[ke,Y,P]),Ue=n.useMemo(()=>Ka($e,A),[$e,A]),We=({field:J})=>Y!==J||!P?e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:.3},children:"↕"}):e.jsx("span",{className:"nice-table__sort-icon",children:P==="asc"?"↑":"↓"});return e.jsxs("div",{className:`nice-treegrid nice-datagrid ${ve||""}`,style:O,children:[(T||Z)&&e.jsxs("div",{className:"nice-datagrid__toolbar",children:[T&&e.jsx("div",{className:"nice-datagrid__search",children:e.jsx("input",{type:"text",value:de,onChange:J=>D(J.target.value),placeholder:v||H("controls.search","Search...")})}),Z]}),e.jsx("div",{className:"nice-datagrid__table-wrap",children:e.jsxs("table",{className:`${x?"nice-table--striped":""} ${_?"nice-table--compact":""}`,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[Q&&e.jsx("th",{className:"nice-datagrid__checkbox",style:{width:36}}),he.map(J=>e.jsxs("th",{style:{width:J.width,minWidth:J.minWidth,textAlign:J.align},className:w&&J.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>w&&J.sortable!==!1&&Te(J.field),children:[J.header,w&&J.sortable!==!1&&e.jsx(We,{field:J.field})]},J.field))]})}),e.jsx("tbody",{children:j?e.jsx("tr",{children:e.jsx("td",{colSpan:he.length+(Q?1:0),className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):Ue.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:he.length+(Q?1:0),className:"nice-datagrid__empty",children:B||H("controls.noData","No data available")})}):Ue.map((J,_e)=>{const je=me.has(J.key),ge=J.children.length>0,M=A.has(J.key);return e.jsxs("tr",{className:je?"nice-datagrid__row--selected":void 0,onClick:()=>se?.(J.data),style:se?{cursor:"pointer"}:void 0,children:[Q&&e.jsx("td",{className:"nice-datagrid__checkbox",onClick:ee=>ee.stopPropagation(),children:e.jsx("input",{type:"checkbox",checked:je,onChange:()=>Qe(J.key),"aria-label":`Select row ${J.key}`})}),he.map((ee,Fe)=>e.jsxs("td",{style:{textAlign:ee.align},children:[Fe===0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{display:"inline-block",width:J.depth*20}}),e.jsx("button",{className:`nice-treegrid__toggle ${ge?"":"nice-treegrid__toggle--leaf"}`,onClick:I=>{I.stopPropagation(),ge&&Ve(J.key)},tabIndex:ge?0:-1,"aria-expanded":ge?M:void 0,"aria-label":ge?M?"Collapse":"Expand":void 0,children:ge?M?"▾":"▸":""})]}),ee.render?ee.render(J.data[ee.field],J.data,_e):String(J.data[ee.field]??"")]},ee.field))]},J.key)})})]})})]})}const ut={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},qa=()=>e.jsxs("svg",{...ut,children:[e.jsx("path",{d:"M3 7v6h6"}),e.jsx("path",{d:"M21 17a9 9 0 0 0-15-6.7L3 13"})]}),Xa=()=>e.jsxs("svg",{...ut,children:[e.jsx("path",{d:"M21 7v6h-6"}),e.jsx("path",{d:"M3 17a9 9 0 0 1 15-6.7L21 13"})]}),Ha=()=>e.jsxs("svg",{...ut,children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"12",x2:"15",y2:"12"}),e.jsx("line",{x1:"3",y1:"18",x2:"18",y2:"18"})]}),Qa=()=>e.jsxs("svg",{...ut,children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"6",y1:"12",x2:"18",y2:"12"}),e.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]}),Ya=()=>e.jsxs("svg",{...ut,children:[e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"9",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"6",y1:"18",x2:"21",y2:"18"})]}),Ja=()=>e.jsxs("svg",{...ut,children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"6",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"18",height:"6",rx:"1"}),e.jsx("line",{x1:"12",y1:"11",x2:"12",y2:"13"})]}),es=()=>e.jsxs("svg",{...ut,children:[e.jsx("rect",{x:"4",y:"3",width:"6",height:"18",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"6",height:"18",rx:"1"}),e.jsx("line",{x1:"11",y1:"12",x2:"13",y2:"12"})]}),ts=()=>e.jsxs("svg",{...ut,children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"6",rx:"1"}),e.jsx("line",{x1:"6",y1:"17",x2:"18",y2:"17"})]}),ns=()=>e.jsxs("svg",{...ut,children:[e.jsx("rect",{x:"4",y:"3",width:"6",height:"18",rx:"1"}),e.jsx("line",{x1:"14",y1:"12",x2:"20",y2:"12"})]}),is=()=>e.jsx("svg",{...ut,children:e.jsx("polyline",{points:"6 9 12 4 18 9"})}),as=()=>e.jsx("svg",{...ut,children:e.jsx("polyline",{points:"6 15 12 20 18 15"})}),ss=()=>e.jsxs("svg",{...ut,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 9 12 4 18 9"}),e.jsx("polyline",{points:"6 15 12 20 18 15"})]}),rs=()=>e.jsxs("svg",{...ut,children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),cs=()=>e.jsxs("svg",{...ut,children:[e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),e.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"})]});function Ci(t){let a="",s=t;for(;s>=0;)a=String.fromCharCode(65+s%26)+a,s=Math.floor(s/26)-1;return a}function Re(t,a){return`${Ci(a)}${t+1}`}function Je(t){const a=t.match(/^([A-Z]+)(\d+)$/);if(!a)return null;let s=0;for(let r=0;r<a[1].length;r++)s=s*26+(a[1].charCodeAt(r)-64);return{row:parseInt(a[2],10)-1,col:s-1}}function ls(t,a,s=new Set){const r=t.startsWith("=")?t.slice(1).trim():t,o=(T,v)=>{if(!T||!v)return[];const x=[];for(let _=T.row;_<=v.row;_++)for(let j=T.col;j<=v.col;j++){const B=He(Re(_,j),a,new Set(s));typeof B=="number"&&x.push(B)}return x},u=(T,v)=>{if(!T||!v)return[];const x=[];for(let _=T.row;_<=v.row;_++)for(let j=T.col;j<=v.col;j++)x.push(He(Re(_,j),a,new Set(s)));return x},f=r.match(/^(\w+)\(([A-Z]+\d+):([A-Z]+\d+)\)$/i);if(f){const T=f[1].toUpperCase(),v=Je(f[2].toUpperCase()),x=Je(f[3].toUpperCase());switch(T){case"SUM":return o(v,x).reduce((j,B)=>j+B,0);case"AVG":case"AVERAGE":{const _=o(v,x);return _.length>0?_.reduce((j,B)=>j+B,0)/_.length:0}case"COUNT":return o(v,x).length;case"COUNTA":return u(v,x).filter(_=>_!==null&&_!=="").length;case"COUNTBLANK":return u(v,x).filter(_=>_===null||_==="").length;case"MIN":{const _=o(v,x);return _.length?Math.min(..._):0}case"MAX":{const _=o(v,x);return _.length?Math.max(..._):0}case"MEDIAN":{const _=o(v,x).sort((B,Z)=>B-Z);if(!_.length)return 0;const j=Math.floor(_.length/2);return _.length%2?_[j]:(_[j-1]+_[j])/2}case"STDEV":{const _=o(v,x);if(_.length<2)return 0;const j=_.reduce((B,Z)=>B+Z,0)/_.length;return Math.sqrt(_.reduce((B,Z)=>B+(Z-j)**2,0)/(_.length-1))}case"PRODUCT":{const _=o(v,x);return _.length?_.reduce((j,B)=>j*B,1):0}}}const c=r.match(/^(SUMIF|COUNTIF)\(([A-Z]+\d+):([A-Z]+\d+)\s*,\s*"?([^"]*)"?\)$/i);if(c){const T=c[1].toUpperCase(),v=Je(c[2].toUpperCase()),x=Je(c[3].toUpperCase()),_=c[4];if(v&&x){let j=0;for(let B=v.row;B<=x.row;B++)for(let Z=v.col;Z<=x.col;Z++){const se=He(Re(B,Z),a,new Set(s));(_.startsWith(">")?Number(se)>Number(_.slice(1)):_.startsWith("<")?Number(se)<Number(_.slice(1)):String(se)===_||typeof se=="number"&&se===Number(_))&&(j+=T==="SUMIF"?typeof se=="number"?se:0:1)}return j}}const g=r.match(/^IF\(([^,]+),\s*([^,]+),\s*([^)]+)\)$/i);if(g){const T=g[1].trim(),v=g[2].trim(),x=g[3].trim(),_=T.match(/^([A-Z]+\d+)\s*([><=!]+)\s*(\S+)$/i);let j=!1;if(_){const se=He(_[1].toUpperCase(),a,new Set(s)),ve=isNaN(Number(_[3]))?_[3].replace(/^"|"$/g,""):Number(_[3]),O=_[2],H=typeof se=="number"?se:Number(se)||0,ce=typeof ve=="number"?ve:Number(ve)||0;switch(O){case">":j=H>ce;break;case"<":j=H<ce;break;case">=":j=H>=ce;break;case"<=":j=H<=ce;break;case"=":case"==":j=H===ce;break;case"<>":case"!=":j=H!==ce;break}}const B=j?v:x;if(Je(B.toUpperCase()))return He(B.toUpperCase(),a,new Set(s));const Z=Number(B);return isNaN(Z)?B.replace(/^"|"$/g,""):Z}const w=r.match(/^CONCAT\((.+)\)$/i);if(w)return w[1].split(",").map(v=>v.trim()).map(v=>{if(v.startsWith('"')&&v.endsWith('"'))return v.slice(1,-1);if(Je(v.toUpperCase())){const _=He(v.toUpperCase(),a,new Set(s));return _!==null?String(_):""}return v}).join("");const R=r.match(/^VLOOKUP\(([^,]+),\s*([A-Z]+\d+):([A-Z]+\d+),\s*(\d+)\)$/i);if(R){let T;Je(R[1].trim().toUpperCase())?T=He(R[1].trim().toUpperCase(),a,new Set(s)):T=isNaN(Number(R[1]))?R[1].replace(/^"|"$/g,""):Number(R[1]);const x=Je(R[2].toUpperCase()),_=Je(R[3].toUpperCase()),j=parseInt(R[4])-1;if(x&&_)for(let B=x.row;B<=_.row;B++){const Z=He(Re(B,x.col),a,new Set(s));if(String(Z)===String(T))return He(Re(B,x.col+j),a,new Set(s))}return null}const L=r.match(/^(ABS|ROUND|FLOOR|CEIL|CEILING|SQRT|LEN|UPPER|LOWER|TRIM|INT)\(([^)]+)\)$/i);if(L){const T=L[1].toUpperCase(),v=L[2].trim();let x;switch(Je(v.toUpperCase())?x=He(v.toUpperCase(),a,new Set(s)):x=isNaN(Number(v))?v.replace(/^"|"$/g,""):Number(v),T){case"ABS":return Math.abs(Number(x)||0);case"ROUND":return Math.round(Number(x)||0);case"FLOOR":return Math.floor(Number(x)||0);case"CEIL":case"CEILING":return Math.ceil(Number(x)||0);case"SQRT":return Math.sqrt(Number(x)||0);case"INT":return Math.trunc(Number(x)||0);case"LEN":return String(x??"").length;case"UPPER":return String(x??"").toUpperCase();case"LOWER":return String(x??"").toLowerCase();case"TRIM":return String(x??"").trim()}}const C=r.match(/^POWER\(([^,]+),\s*([^)]+)\)$/i);if(C){const T=Number(Je(C[1].trim().toUpperCase())?He(C[1].trim().toUpperCase(),a,new Set(s)):C[1].trim())||0,v=Number(Je(C[2].trim().toUpperCase())?He(C[2].trim().toUpperCase(),a,new Set(s)):C[2].trim())||0;return Math.pow(T,v)}if(/^NOW\(\)$/i.test(r))return new Date().toISOString();if(/^TODAY\(\)$/i.test(r))return new Date().toISOString().split("T")[0];if(/^PI\(\)$/i.test(r))return Math.PI;const Q=r.match(/^([A-Z]+\d+)$/i);if(Q)return He(Q[1].toUpperCase(),a,s);const V=r.match(/^([A-Z]+\d+)\s*([+\-*/])\s*([A-Z]+\d+|\d+\.?\d*)$/i);if(V){const T=V[1].toUpperCase(),v=V[2],x=V[3],_=He(T,a,s),B=Je(x.toUpperCase())?He(x.toUpperCase(),a,s):parseFloat(x),Z=typeof _=="number"?_:0,se=typeof B=="number"?B:0;switch(v){case"+":return Z+se;case"-":return Z-se;case"*":return Z*se;case"/":return se!==0?Z/se:null}}const $=parseFloat(r);return isNaN($)?r:$}function He(t,a,s){if(s.has(t))return null;s.add(t);const r=a[t];return r?r.formula?ls(r.formula,a,s):r.value:null}function fi(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 gi(t){return{name:t,data:{}}}const Mi=n.forwardRef(({sheets:t,activeSheet:a,rows:s=50,cols:r=26,showToolbar:o=!0,showFormulaBar:u=!0,showSheetTabs:f=!0,readOnly:c=!1,onChange:g,onActiveSheetChange:w,onCellSelect:R,onCopy:L,onPaste:C,onInsert:Q,onRemove:V,maxUndo:$=50,sortable:T=!1,filterable:v=!1,rangeSelection:x=!0,className:_,style:j,id:B,...Z},se)=>{const ve=ye.Gs(B),{t:O}=ye.Zt(),[H,ce]=n.useState(()=>t??[gi(O("spreadsheet.sheet","Sheet")+" 1")]),[le,fe]=n.useState(0),U=t??H,A=a??le,N=U[A]??U[0],[l,xe]=n.useState(null),[De,de]=n.useState(null),[D,Y]=n.useState(!1),[P,me]=n.useState(null),[he,Te]=n.useState(""),Ve=n.useRef(null),Qe=n.useRef(null),[ke,$e]=n.useState([]),[Ue,We]=n.useState([]),[J,_e]=n.useState(null),je=n.useRef({x:0,width:80}),[ge,M]=n.useState(null),[ee,Fe]=n.useState(null),[I,ue]=n.useState("");n.useEffect(()=>{P&&Ve.current&&Ve.current.focus()},[P]);const W=n.useMemo(()=>{if(!l)return null;const m=De??l;return{startRow:Math.min(l.row,m.row),startCol:Math.min(l.col,m.col),endRow:Math.max(l.row,m.row),endCol:Math.max(l.col,m.col)}},[l,De]),Ie=n.useCallback((m,h)=>W?m>=W.startRow&&m<=W.endRow&&h>=W.startCol&&h<=W.endCol:!1,[W]),Le=n.useCallback(m=>{$e(h=>{const z=[...h,m.map(K=>({...K,data:{...K.data}}))];return z.length>$?z.slice(-$):z}),We([])},[$]),te=n.useCallback((m,h=!0)=>{h&&Le(U);const z=m(U);t||ce(z),g?.(z)},[U,t,g,Le]),Ke=n.useCallback(()=>{if(ke.length===0)return;const m=ke[ke.length-1];We(h=>[...h,U.map(z=>({...z,data:{...z.data}}))]),$e(h=>h.slice(0,-1)),t||ce(m),g?.(m)},[ke,U,t,g]),Ye=n.useCallback(()=>{if(Ue.length===0)return;const m=Ue[Ue.length-1];$e(h=>[...h,U.map(z=>({...z,data:{...z.data}}))]),We(h=>h.slice(0,-1)),t||ce(m),g?.(m)},[Ue,U,t,g]),it=n.useCallback(m=>{a||fe(m),w?.(m),xe(null),de(null),me(null)},[a,w]),Ne=n.useCallback((m,h,z)=>{const K=Re(m,h);te(ie=>{const F=ie.map((q,X)=>X===A?{...q,data:{...q.data}}:q),k=z.startsWith("=");return F[A].data[K]={...F[A].data[K]??{value:null},formula:k?z:void 0,value:k?null:isNaN(Number(z))?z:Number(z)},F})},[A,te]),jt=n.useCallback((m,h,z)=>{z?.shiftKey&&x&&l?de({row:m,col:h}):(xe({row:m,col:h}),de(null)),me(null),R?.(A,m,h)},[A,R,x,l]),Pt=n.useCallback((m,h,z)=>{z.button===0&&(jt(m,h,z),x&&!z.shiftKey&&Y(!0))},[jt,x]),mt=n.useCallback((m,h)=>{D&&de({row:m,col:h})},[D]);n.useEffect(()=>{if(!D)return;const m=()=>Y(!1);return document.addEventListener("mouseup",m),()=>document.removeEventListener("mouseup",m)},[D]);const Nt=n.useCallback((m,h)=>{if(c)return;const z=Re(m,h),K=N.data[z];K?.readOnly||(me({row:m,col:h}),Te(K?.formula??(K?.value!=null?String(K.value):"")))},[c,N.data]),E=n.useCallback(()=>{P&&(Ne(P.row,P.col,he),me(null))},[P,he,Ne]),ae=n.useCallback(m=>{if(m.key==="Enter")E();else if(m.key==="Escape")me(null);else if(m.key==="Tab"&&(m.preventDefault(),E(),l)){const h=m.shiftKey?Math.max(0,l.col-1):Math.min(r-1,l.col+1);xe({row:l.row,col:h})}},[E,l,r]),oe=n.useCallback((m,h)=>{if(!l)return;const z=W??{startRow:l.row,startCol:l.col,endRow:l.row,endCol:l.col};te(K=>{const ie=K.map((F,k)=>k===A?{...F,data:{...F.data}}:F);for(let F=z.startRow;F<=z.endRow;F++)for(let k=z.startCol;k<=z.endCol;k++){const q=Re(F,k);ie[A].data[q]={...ie[A].data[q]??{value:null},[m]:h}}return ie})},[l,W,A,te]),qe=n.useCallback(m=>{if(!W||L?.(W)===!1)return;const{startRow:h,startCol:z,endRow:K,endCol:ie}=W,F=[];for(let k=h;k<=K;k++){const q=[];for(let X=z;X<=ie;X++){const Oe=Re(k,X),Ae=N.data[Oe],Ce=Ae?He(Oe,N.data,new Set):null;q.push(fi(Ce,Ae?.format))}F.push(q.join(" "))}m.clipboardData.setData("text/plain",F.join(`
595
+ `)),m.preventDefault()},[W,N.data,L]),rt=n.useCallback(m=>{if(c||!l)return;const h=m.clipboardData.getData("text/plain");if(!h)return;const z=h.split(`
596
+ `).map(K=>K.split(" "));C?.(z,l.row,l.col)!==!1&&(te(K=>{const ie=K.map((F,k)=>k===A?{...F,data:{...F.data}}:F);return z.forEach((F,k)=>{F.forEach((q,X)=>{const Oe=Re(l.row+k,l.col+X),Ae=q.startsWith("=");ie[A].data[Oe]={...ie[A].data[Oe]??{value:null},formula:Ae?q:void 0,value:Ae?null:isNaN(Number(q))?q:Number(q)}})}),ie}),m.preventDefault())},[c,l,A,te,C]),we=n.useCallback(m=>{te(h=>h.map((K,ie)=>{if(ie!==A)return K;const F={};for(const[k,q]of Object.entries(K.data)){const X=Je(k);X&&(X.row>m?F[Re(X.row+1,X.col)]=q:F[k]=q)}return{...K,data:F}})),Q?.("row",m)},[A,te,Q]),Pe=n.useCallback(m=>{te(h=>h.map((K,ie)=>{if(ie!==A)return K;const F={};for(const[k,q]of Object.entries(K.data)){const X=Je(k);X&&(X.col>m?F[Re(X.row,X.col+1)]=q:F[k]=q)}return{...K,data:F}})),Q?.("column",m)},[A,te,Q]),Se=n.useCallback(m=>{te(h=>h.map((K,ie)=>{if(ie!==A)return K;const F={};for(const[k,q]of Object.entries(K.data)){const X=Je(k);X&&X.row!==m&&(X.row>m?F[Re(X.row-1,X.col)]=q:F[k]=q)}return{...K,data:F}})),V?.("row",m)},[A,te,V]),ct=n.useCallback(m=>{te(h=>h.map((K,ie)=>{if(ie!==A)return K;const F={};for(const[k,q]of Object.entries(K.data)){const X=Je(k);X&&X.col!==m&&(X.col>m?F[Re(X.row,X.col-1)]=q:F[k]=q)}return{...K,data:F}})),V?.("column",m)},[A,te,V]),Ze=n.useCallback((m,h)=>{te(z=>z.map((ie,F)=>{if(F!==A)return ie;const k=new Map;for(const[Oe,Ae]of Object.entries(ie.data)){const Ce=Je(Oe);Ce&&(k.has(Ce.row)||k.set(Ce.row,{}),k.get(Ce.row)[Ce.col]=Ae)}const q=Array.from(k.entries()).sort((Oe,Ae)=>{const Ce=He(Re(Oe[0],m),ie.data,new Set),et=He(Re(Ae[0],m),ie.data,new Set),Zt=typeof Ce=="number"?Ce:Number(Ce),en=typeof et=="number"?et:Number(et);if(!isNaN(Zt)&&!isNaN(en))return h==="asc"?Zt-en:en-Zt;const nt=String(Ce??""),Ot=String(et??"");return h==="asc"?nt.localeCompare(Ot):Ot.localeCompare(nt)}),X={};return q.forEach(([,Oe],Ae)=>{for(const[Ce,et]of Object.entries(Oe))X[Re(Ae,Number(Ce))]=et}),{...ie,data:X,sortColumn:m,sortDirection:h}}))},[A,te]),wt=n.useCallback((m,h)=>{const z=N.conditionalFormats;if(!z?.length)return;const K=Re(m,h),ie=He(K,N.data,new Set),F=typeof ie=="number"?ie:Number(ie);for(const k of z){const q=k.range.match(/^([A-Z]+\d+):([A-Z]+\d+)$/i);if(!q)continue;const X=Je(q[1].toUpperCase()),Oe=Je(q[2].toUpperCase());if(!X||!Oe||m<X.row||m>Oe.row||h<X.col||h>Oe.col)continue;let Ae=!1;switch(k.type){case"greaterThan":Ae=!isNaN(F)&&F>Number(k.value);break;case"lessThan":Ae=!isNaN(F)&&F<Number(k.value);break;case"equalTo":Ae=String(ie)===String(k.value);break;case"between":Ae=!isNaN(F)&&F>=Number(k.value)&&F<=Number(k.value2);break;case"textContains":Ae=String(ie).includes(String(k.value));break;case"isEmpty":Ae=ie===null||ie==="";break;case"isNotEmpty":Ae=ie!==null&&ie!=="";break}if(Ae)return{backgroundColor:k.style.bgColor,color:k.style.color,fontWeight:k.style.bold?"bold":void 0,fontStyle:k.style.italic?"italic":void 0}}},[N.conditionalFormats,N.data]),bt=n.useCallback(()=>{const m=`${O("spreadsheet.sheet","Sheet")} ${U.length+1}`;te(h=>[...h,gi(m)]),it(U.length)},[U.length,te,it,O]),cn=n.useCallback(()=>{U.length<=1||(te(m=>m.filter((h,z)=>z!==A)),it(Math.max(0,A-1)))},[U.length,A,te,it]),Qt=n.useCallback((m,h)=>{h.trim()&&(te(z=>z.map((K,ie)=>ie===m?{...K,name:h.trim()}:K),!1),Fe(null))},[te]),Yt=n.useMemo(()=>{if(!l)return"";const m=Re(l.row,l.col),h=N.data[m];return h?.formula??(h?.value!=null?String(h.value):"")},[l,N.data]),at=n.useMemo(()=>{if(!W)return null;const{startRow:m,startCol:h,endRow:z,endCol:K}=W;if(m===z&&h===K)return null;const ie=[];let F=0;for(let k=m;k<=z;k++)for(let q=h;q<=K;q++){const X=Re(k,q),Oe=He(X,N.data,new Set);Oe!==null&&Oe!==""&&F++,typeof Oe=="number"&&ie.push(Oe)}return ie.length===0?{count:F}:{count:F,sum:ie.reduce((k,q)=>k+q,0),avg:ie.reduce((k,q)=>k+q,0)/ie.length,min:Math.min(...ie),max:Math.max(...ie)}},[W,N.data]),Fn=n.useCallback((m,h)=>{h.preventDefault(),h.stopPropagation(),_e(m),je.current={x:h.clientX,width:N.colWidths?.[m]??80}},[N.colWidths]);n.useEffect(()=>{if(J===null)return;const m=z=>{const K=z.clientX-je.current.x,ie=Math.max(30,je.current.width+K);te(F=>F.map((q,X)=>X===A?{...q,colWidths:{...q.colWidths,[J]:ie}}:q),!1)},h=()=>_e(null);return document.addEventListener("mousemove",m),document.addEventListener("mouseup",h),()=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",h)}},[J,A,te]);const Sn=n.useCallback((m,h,z)=>{m.preventDefault(),xe({row:h,col:z}),M({x:m.clientX,y:m.clientY})},[]);n.useEffect(()=>{if(!ge)return;const m=()=>M(null);return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[ge]);const Jt=n.useCallback(m=>{if((m.ctrlKey||m.metaKey)&&!P){if(m.key==="z"){m.preventDefault(),Ke();return}if(m.key==="y"){m.preventDefault(),Ye();return}}if(P||!l)return;let{row:h,col:z}=l;switch(m.key){case"ArrowUp":h=Math.max(0,h-1);break;case"ArrowDown":h=Math.min(s-1,h+1);break;case"ArrowLeft":z=Math.max(0,z-1);break;case"ArrowRight":z=Math.min(r-1,z+1);break;case"Enter":Nt(h,z);return;case"Delete":case"Backspace":c||(W&&(W.startRow!==W.endRow||W.startCol!==W.endCol)?te(K=>{const ie=K.map((F,k)=>k===A?{...F,data:{...F.data}}:F);for(let F=W.startRow;F<=W.endRow;F++)for(let k=W.startCol;k<=W.endCol;k++)delete ie[A].data[Re(F,k)];return ie}):Ne(h,z,""));return;default:if(m.key.length===1&&!m.ctrlKey&&!m.metaKey&&!c){me({row:h,col:z}),Te(m.key);return}return}m.preventDefault(),m.shiftKey&&x?de({row:h,col:z}):(xe({row:h,col:z}),de(null)),R?.(A,h,z)},[P,l,s,r,c,Nt,Ne,A,R,Ke,Ye,W,te,x]),ln=N.frozenRows??0,kt=N.frozenCols??0,fn=[{value:"text",label:O("spreadsheet.formatText","Text")},{value:"number",label:O("spreadsheet.formatNumber","Number")},{value:"percent",label:O("spreadsheet.formatPercent","Percent")},{value:"currency",label:O("spreadsheet.formatCurrency","Currency")},{value:"date",label:O("spreadsheet.formatDate","Date")}];return e.jsxs("div",{ref:se,id:ve,className:`nice-spreadsheet ${c?"nice-spreadsheet--readonly":""} ${_??""}`,style:j,onKeyDown:Jt,onCopy:qe,onPaste:rt,tabIndex:0,role:"application","aria-label":O("spreadsheet.label","Spreadsheet"),...Z,children:[o&&!c&&e.jsxs("div",{className:"nice-spreadsheet__toolbar",role:"toolbar",children:[e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:Ke,disabled:ke.length===0,title:O("spreadsheet.undo","Undo"),children:e.jsx(qa,{})}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:Ye,disabled:Ue.length===0,title:O("spreadsheet.redo","Redo"),children:e.jsx(Xa,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(ze.NiceButton,{variant:N.data[l?Re(l.row,l.col):""]?.bold?"primary":"ghost",size:"sm",onClick:()=>oe("bold",!N.data[l?Re(l.row,l.col):""]?.bold),title:O("spreadsheet.bold","Bold"),children:e.jsx("strong",{children:"B"})}),e.jsx(ze.NiceButton,{variant:N.data[l?Re(l.row,l.col):""]?.italic?"primary":"ghost",size:"sm",onClick:()=>oe("italic",!N.data[l?Re(l.row,l.col):""]?.italic),title:O("spreadsheet.italic","Italic"),children:e.jsx("em",{children:"I"})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>oe("align","left"),title:O("spreadsheet.alignLeft","Align left"),children:e.jsx(Ha,{})}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>oe("align","center"),title:O("spreadsheet.alignCenter","Center"),children:e.jsx(Qa,{})}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>oe("align","right"),title:O("spreadsheet.alignRight","Align right"),children:e.jsx(Ya,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(ze.NiceColorPicker,{value:N.data[l?Re(l.row,l.col):""]?.bgColor??"var(--bg-primary, #ffffff)",onChange:m=>oe("bgColor",m),title:O("spreadsheet.bgColor","Background color"),showInput:!1,showRandom:!1}),e.jsx(ze.NiceColorPicker,{value:N.data[l?Re(l.row,l.col):""]?.color??"var(--text-primary, #000000)",onChange:m=>oe("color",m),title:O("spreadsheet.textColor","Text color"),showInput:!1,showRandom:!1}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(ze.NiceSelect,{size:"sm",value:N.data[l?Re(l.row,l.col):""]?.format??"text",onChange:m=>oe("format",m),options:fn,"aria-label":O("spreadsheet.format","Cell format")}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>l&&we(l.row),title:O("spreadsheet.insertRow","Insert row"),children:e.jsx(Ja,{})}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>l&&Pe(l.col),title:O("spreadsheet.insertCol","Insert column"),children:e.jsx(es,{})}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>l&&Se(l.row),title:O("spreadsheet.deleteRow","Delete row"),children:e.jsx(ts,{})}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>l&&ct(l.col),title:O("spreadsheet.deleteCol","Delete column"),children:e.jsx(ns,{})})]}),u&&e.jsxs("div",{className:"nice-spreadsheet__formula-bar",children:[e.jsxs("span",{className:"nice-spreadsheet__cell-label",children:[l?Re(l.row,l.col):"",W&&W.startRow!==W.endRow||W&&W.startCol!==W.endCol?`:${Re(W.endRow,W.endCol)}`:""]}),e.jsx(ze.NiceTextInput,{className:"nice-spreadsheet__formula-input",value:P?he:Yt,onChange:m=>{P?Te(m):l&&(me(l),Te(m))},onKeyDown:ae,readOnly:c,"aria-label":O("spreadsheet.formulaBar","Formula bar")})]}),e.jsx("div",{className:"nice-spreadsheet__grid",ref:Qe,children:e.jsxs("table",{role:"grid","aria-label":N.name,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-spreadsheet__corner"}),Array.from({length:r},(m,h)=>e.jsxs("th",{className:`nice-spreadsheet__col-header ${h<kt?"nice-spreadsheet__col-header--frozen":""}`,style:{width:N.colWidths?.[h]??80,position:h<kt?"sticky":void 0,left:h<kt?h*80+40:void 0,zIndex:h<kt?3:void 0},children:[e.jsx("span",{children:Ci(h)}),T&&e.jsx("span",{className:"nice-spreadsheet__sort-trigger",onClick:()=>Ze(h,N.sortColumn===h&&N.sortDirection==="asc"?"desc":"asc"),title:O("spreadsheet.sort","Sort"),children:N.sortColumn===h?N.sortDirection==="asc"?e.jsx(is,{}):e.jsx(as,{}):e.jsx(ss,{})}),!c&&e.jsx("span",{className:"nice-spreadsheet__col-resize",onMouseDown:z=>Fn(h,z)})]},h))]})}),e.jsx("tbody",{children:Array.from({length:s},(m,h)=>e.jsxs("tr",{className:h<ln?"nice-spreadsheet__row--frozen":"",style:h<ln?{position:"sticky",top:h*24,zIndex:2}:void 0,children:[e.jsx("td",{className:"nice-spreadsheet__row-header",children:h+1}),Array.from({length:r},(z,K)=>{const ie=Re(h,K),F=N.data[ie];if(F?.mergedInto)return null;const k=l?.row===h&&l?.col===K,q=Ie(h,K),X=P?.row===h&&P?.col===K,Oe=F?He(ie,N.data,new Set):null,Ae=wt(h,K),Ce=h<ln||K<kt;return e.jsxs("td",{className:`nice-spreadsheet__cell ${k?"nice-spreadsheet__cell--selected":""} ${q&&!k?"nice-spreadsheet__cell--in-range":""} ${F?.readOnly?"nice-spreadsheet__cell--readonly":""} ${Ce?"nice-spreadsheet__cell--frozen":""}`,style:{textAlign:F?.align,fontWeight:F?.bold?"bold":void 0,fontStyle:F?.italic?"italic":void 0,backgroundColor:Ae?.backgroundColor??F?.bgColor,color:Ae?.color??F?.color,width:N.colWidths?.[K],height:N.rowHeights?.[h],position:Ce?"sticky":void 0,left:K<kt?K*80+40:void 0,zIndex:Ce?1:void 0,...Ae},colSpan:F?.colSpan,rowSpan:F?.rowSpan,onMouseDown:et=>Pt(h,K,et),onMouseEnter:()=>mt(h,K),onDoubleClick:()=>Nt(h,K),onContextMenu:et=>Sn(et,h,K),role:"gridcell","aria-selected":k,title:F?.comment,children:[F?.comment&&e.jsx("span",{className:"nice-spreadsheet__comment-indicator"}),X?e.jsx("input",{ref:Ve,className:"nice-spreadsheet__cell-editor",value:he,onChange:et=>Te(et.target.value),onKeyDown:ae,onBlur:E}):fi(Oe,F?.format)]},K)})]},h))})]})}),ge&&!c&&l&&e.jsxs("div",{className:"nice-spreadsheet__context-menu",style:{position:"fixed",left:ge.x,top:ge.y,zIndex:1e3},children:[e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{we(l.row),M(null)},children:O("spreadsheet.insertRowAbove","Insert row above")}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{we(l.row+1),M(null)},children:O("spreadsheet.insertRowBelow","Insert row below")}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Pe(l.col),M(null)},children:O("spreadsheet.insertColLeft","Insert column left")}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Pe(l.col+1),M(null)},children:O("spreadsheet.insertColRight","Insert column right")}),e.jsx("hr",{className:"nice-spreadsheet__context-sep"}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Se(l.row),M(null)},children:O("spreadsheet.deleteRow","Delete row")}),e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{ct(l.col),M(null)},children:O("spreadsheet.deleteCol","Delete column")})]}),at&&e.jsxs("div",{className:"nice-spreadsheet__status-bar",children:[e.jsxs("span",{children:[O("spreadsheet.count","Count"),": ",at.count]}),at.sum!==void 0&&e.jsxs("span",{children:[O("spreadsheet.sum","Sum"),": ",at.sum.toFixed(2)]}),at.avg!==void 0&&e.jsxs("span",{children:[O("spreadsheet.avg","Avg"),": ",at.avg.toFixed(2)]}),at.min!==void 0&&e.jsxs("span",{children:[O("spreadsheet.min","Min"),": ",at.min]}),at.max!==void 0&&e.jsxs("span",{children:[O("spreadsheet.max","Max"),": ",at.max]})]}),f&&e.jsxs("div",{className:"nice-spreadsheet__tabs",role:"tablist",children:[U.map((m,h)=>e.jsx("span",{className:"nice-spreadsheet__tab-wrapper",children:ee===h?e.jsx(ze.NiceTextInput,{className:"nice-spreadsheet__tab-rename",value:I,onChange:z=>ue(z),onBlur:()=>Qt(h,I),onKeyDown:z=>{z.key==="Enter"&&Qt(h,I),z.key==="Escape"&&Fe(null)},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>{c||(Fe(h),ue(m.name))},children:e.jsx(ze.NiceButton,{variant:h===A?"primary":"ghost",size:"sm",onClick:()=>it(h),children:m.name})})},h)),!c&&e.jsxs(e.Fragment,{children:[e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:bt,title:O("spreadsheet.addSheet","Add sheet"),children:e.jsx(rs,{})}),U.length>1&&e.jsx(ze.NiceButton,{variant:"ghost",size:"sm",onClick:cn,title:O("spreadsheet.removeSheet","Remove sheet"),children:e.jsx(cs,{})})]})]})]})});Mi.displayName="NiceSpreadsheet";const os=({queries:t,currentFilter:a,currentColumns:s,currentSort:r,onLoad:o,onSave:u,onUpdate:f,onDelete:c,onShare:g,onSetDefault:w,allowSharing:R=!0,allowPinning:L=!0,position:C="dropdown",className:Q,style:V,"data-testid":$})=>{const[T,v]=n.useState(!1),[x,_]=n.useState(""),[j,B]=n.useState(!1),[Z,se]=n.useState(""),[ve,O]=n.useState(""),[H,ce]=n.useState(!1),le=t.filter(l=>l.name.toLowerCase().includes(x.toLowerCase())),fe=le.filter(l=>!l.isShared),U=le.filter(l=>l.isShared),A=async()=>{if(Z.trim()){B(!0);try{await u({name:Z,description:ve||void 0,filter:a??{},columns:s,sort:r}),ce(!1),se(""),O("")}finally{B(!1)}}},N=l=>e.jsxs("div",{className:"nice-saved-query__item",children:[l.icon&&e.jsx("span",{className:"nice-saved-query__icon","aria-hidden":"true",children:l.icon}),e.jsx("span",{className:"nice-saved-query__name",children:l.name}),l.isDefault&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--default",children:"domyślne"}),l.isShared&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--shared",children:"udostępnione"}),l.isPinned&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--pinned",children:"przypięte"}),e.jsxs("div",{className:"nice-saved-query__actions",children:[e.jsx("button",{onClick:()=>{o(l),v(!1)},type:"button",children:"Wczytaj"}),w&&e.jsx("button",{onClick:()=>w(l.id),type:"button",title:"Ustaw domyślne",children:"★"}),R&&g&&e.jsx("button",{onClick:()=>g(l.id,[]),type:"button",title:"Udostępnij",children:"↗"}),L&&e.jsx("button",{onClick:()=>f(l.id,{...l}),type:"button",title:"Przypnij",children:"📌"}),e.jsx("button",{onClick:()=>c(l.id),type:"button",title:"Usuń","aria-label":`Usuń zapytanie ${l.name}`,children:"✕"})]})]},l.id);return e.jsxs("div",{className:`nice-saved-query nice-saved-query--${C} ${T?"nice-saved-query--open":""} ${Q??""}`,style:V,"data-testid":$,children:[e.jsx("button",{className:"nice-saved-query__trigger",onClick:()=>v(l=>!l),"aria-expanded":T,"aria-haspopup":"listbox",type:"button",children:"Widoki i zapytania"}),T&&e.jsxs("div",{className:"nice-saved-query__panel",role:"dialog","aria-label":"Zarządzanie zapytaniami",children:[e.jsxs("div",{className:"nice-saved-query__search-row",children:[e.jsx("input",{type:"search",placeholder:"Szukaj zapytania…",value:x,onChange:l=>_(l.target.value),"aria-label":"Szukaj zapytania"}),e.jsx("button",{onClick:()=>ce(l=>!l),type:"button",children:"+ Zapisz bieżący widok"})]}),H&&e.jsxs("div",{className:"nice-saved-query__save-form",children:[e.jsx("input",{type:"text",placeholder:"Nazwa zapytania",value:Z,onChange:l=>se(l.target.value),"aria-label":"Nazwa zapytania"}),e.jsx("input",{type:"text",placeholder:"Opis (opcjonalnie)",value:ve,onChange:l=>O(l.target.value),"aria-label":"Opis zapytania"}),e.jsx("button",{onClick:A,disabled:j||!Z.trim(),type:"button",children:j?"Zapisywanie…":"Zapisz"}),e.jsx("button",{onClick:()=>ce(!1),type:"button",children:"Anuluj"})]}),fe.length>0&&e.jsxs("section",{className:"nice-saved-query__group","aria-labelledby":"nice-saved-query-mine",children:[e.jsx("h3",{id:"nice-saved-query-mine",className:"nice-saved-query__group-title",children:"Moje"}),fe.map(N)]}),U.length>0&&e.jsxs("section",{className:"nice-saved-query__group","aria-labelledby":"nice-saved-query-shared",children:[e.jsx("h3",{id:"nice-saved-query-shared",className:"nice-saved-query__group-title",children:"Udostępnione"}),U.map(N)]}),le.length===0&&e.jsx("p",{className:"nice-saved-query__empty",children:"Brak zapisanych zapytań"})]})]})};exports.NiceCardView=ha;exports.NiceDataGrid=Tn;exports.NiceDataGrid$1=aa;exports.NiceDataGridAI=la;exports.NiceFilterBuilder=Xn;exports.NiceKanbanBoard=wi;exports.NiceList=oa;exports.NiceModuleGrid=za;exports.NicePivotGrid=Ni;exports.NicePivotGrid$1=ga;exports.NicePivotGridFieldChooser=ji;exports.NiceReconciliationView=Ua;exports.NiceSavedQueryPanel=os;exports.NiceSpreadsheet=Mi;exports.NiceTable=qi;exports.NiceTileView=pa;exports.NiceTreeGrid=Za;exports.NiceTreeList=ma;exports.NiceTreeView=da;exports.computeAggregate=vi;exports.escapeCsvField=wn;