@nice2dev/ui 1.4.16 → 1.4.18

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 (42) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/NiceAlert-RVTgQxCE.cjs +1 -0
  3. package/dist/NiceDataGrid-Cszjz8NV.cjs +10 -0
  4. package/dist/NiceForm-DM2tARZT.cjs +1 -0
  5. package/dist/{NiceHtmlEditor-By7R1wRo.cjs → NiceHtmlEditor-BEWNA_UI.cjs} +1 -1
  6. package/dist/NiceLoginForm-Bkm5j80r.cjs +1 -0
  7. package/dist/{NiceMention-i7n2BoMw.cjs → NiceMention-DhaTUqvR.cjs} +1 -1
  8. package/dist/NiceModuleLifecyclePanel-DAIbzfZd.cjs +1 -0
  9. package/dist/{NicePagination-D9JguOl0.cjs → NicePagination-CnKYyKI5.cjs} +1 -1
  10. package/dist/{NicePivotGrid-B_7iQJys.cjs → NicePivotGrid-BshofJh1.cjs} +1 -1
  11. package/dist/NiceSavedQueryPanel-DJKEOqy5.cjs +587 -0
  12. package/dist/{NiceScheduler-B2DamQ_L.cjs → NiceScheduler-Dff8fuq_.cjs} +1 -1
  13. package/dist/{core-lazy-ChKRuEPb.cjs → core-lazy-BhQxFuLf.cjs} +1 -1
  14. package/dist/data/NiceRowEditDialog.mjs +42 -35
  15. package/dist/data/NiceTreeGrid.mjs +512 -474
  16. package/dist/data.cjs +1 -1
  17. package/dist/data.d.ts +30 -3
  18. package/dist/editors/forms/NiceForm.mjs +55 -52
  19. package/dist/editors/inputs/NiceRadioGroup.mjs +12 -12
  20. package/dist/editors/inputs/NiceSelect.mjs +51 -51
  21. package/dist/editors/pickers/NiceLanguagePicker.mjs +129 -125
  22. package/dist/editors/pickers/NiceThemePicker.mjs +1 -1
  23. package/dist/editors/pickers/pickerCommons.mjs +155 -203
  24. package/dist/editors.cjs +1 -1
  25. package/dist/feedback.cjs +1 -1
  26. package/dist/index.cjs +96 -96
  27. package/dist/index.d.ts +41 -7
  28. package/dist/lazy.cjs +1 -1
  29. package/dist/navigation.cjs +1 -1
  30. package/dist/navigation.d.ts +6 -0
  31. package/dist/{no-code-CN_q6TcB.cjs → no-code-DPc82kyy.cjs} +11 -11
  32. package/dist/no-code.cjs +1 -1
  33. package/dist/pickerCommons-CQnae2FM.cjs +1 -0
  34. package/dist/style.css +2 -2
  35. package/dist/tools/NiceThemeGalleryPicker.mjs +168 -265
  36. package/package.json +4 -4
  37. package/dist/NiceDataGrid-B1AOjgjm.cjs +0 -10
  38. package/dist/NiceForm-fmePSeA9.cjs +0 -1
  39. package/dist/NiceLoginForm-C2-WgRn0.cjs +0 -1
  40. package/dist/NiceModuleLifecyclePanel-DVHQuhc-.cjs +0 -1
  41. package/dist/NiceSavedQueryPanel-ChY4HwpM.cjs +0 -587
  42. package/dist/pickerCommons-CwcCc8Qi.cjs +0 -1
@@ -0,0 +1,587 @@
1
+ "use strict";const e=require("react/jsx-runtime"),ua=require("@nice2dev/i18n"),N=require("@nice2dev/ui-core"),i=require("react"),Yn=require("./NiceDataGrid-Cszjz8NV.cjs"),ha=require("react-dom"),He=require("./NiceButton-DzCqkG5a.cjs"),ma=require("./NiceForm-DM2tARZT.cjs"),fa=require("./NiceModal-BRVzjuUN.cjs"),pa=require("./core-lBFqvT0V.cjs"),Gn=require("./no-code-DPc82kyy.cjs"),Ei=require("./NiceColorPicker-79rkvaSk.cjs"),ga=[];function _a(n,a){return n.filter(s=>a.every(c=>{const l=s[c.field],d=c.value;switch(c.operator){case"eq":return l===d;case"ne":return l!==d;case"gt":return typeof l=="number"&&typeof d=="number"&&l>d;case"gte":return typeof l=="number"&&typeof d=="number"&&l>=d;case"lt":return typeof l=="number"&&typeof d=="number"&&l<d;case"lte":return typeof l=="number"&&typeof d=="number"&&l<=d;case"contains":return String(l).toLowerCase().includes(String(d).toLowerCase());case"startsWith":return String(l).toLowerCase().startsWith(String(d).toLowerCase());case"endsWith":return String(l).toLowerCase().endsWith(String(d).toLowerCase());default:return!0}}))}function ba(n){return n.map(a=>({field:a.field,type:a.dataType||"string",label:typeof a.header=="string"?a.header:a.field}))}function xa(n,a){const{enableAI:s=!0,aiModel:c,enableNLSearch:l=!0,enableInsights:d=!0,nlPlaceholder:u,onAIFilter:o,onInsights:_,showAISearchBar:f=!0,exampleQueries:S=["Show items from last week","Filter by status = active","Orders over $1000",'Names starting with "A"'],columns:R=ga,data:L,...z}=n,[b,D]=i.useState(""),[p,x]=i.useState([]),[I,y]=i.useState([]),[$,M]=i.useState(!1),[F,H]=i.useState(null),xe=i.useRef(null),{t:re}=ua.useNiceTranslation(),ge=N.useNiceAI(),{parseFilter:Ce,isLoading:te}=N.useNaturalLanguageFilter(),Me=s&&ge.isConfigured,V=p.length>0?_a(L||[],p):L,Ge=i.useCallback(async k=>{if(!Me||!l||!k.trim())return;H(k);const v=ba(R);try{const le=await Ce(k,v);x(le),o?.(k,le)}catch{x([])}},[Me,l,R,Ce,o]),Re=i.useCallback(()=>{x([]),H(null),D("")},[]),Ae=i.useCallback(()=>p,[p]),se=i.useCallback(async()=>{if(!Me||!d||!L?.length)return[];try{const k=await ge.complete([{role:"user",content:`Analyze this data and provide 3-5 key insights. Data sample (${L.length} total rows): ${JSON.stringify(L.slice(0,20))}
2
+
3
+ Columns: ${R.map(v=>v.field).join(", ")}
4
+
5
+ Return a JSON array of insight strings. Be specific with numbers and trends.`}],{temperature:.3,maxTokens:500});try{const v=JSON.parse(k.content),le=Array.isArray(v)?v:[];return y(le),_?.(le),le}catch{return[]}}catch{return[]}},[Me,d,L,R,ge,_]),P=k=>{k.preventDefault(),b.trim()&&Ge(b)},G=k=>{D(k),Ge(k)};return i.useImperativeHandle(a,()=>({applyNLFilter:Ge,clearAIFilters:Re,getAIFilters:Ae,generateInsights:se})),e.jsxs("div",{className:"nice-data-grid-ai","data-testid":n["data-testid"],children:[f&&Me&&l&&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:re("dataGridAI.ai","AI")})}),e.jsxs("form",{onSubmit:P,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(N.NiceIcon,{name:"search",size:14})}),e.jsx("input",{ref:xe,type:"text",value:b,onChange:k=>D(k.target.value),placeholder:u||re("dataGridAI.searchPlaceholder","Search with natural language..."),className:"nice-data-grid-ai__input",disabled:te}),te&&e.jsx("span",{className:"nice-data-grid-ai__loading-spinner"}),b&&!te&&e.jsx("button",{type:"button",className:"nice-data-grid-ai__clear-input",onClick:()=>D(""),"aria-label":re("dataGridAI.clearInput","Clear"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]}),e.jsx("button",{type:"submit",className:"nice-data-grid-ai__search-btn",disabled:te||!b.trim(),children:te?re("dataGridAI.searching","Searching..."):re("dataGridAI.search","Search")})]}),d&&e.jsxs("button",{type:"button",className:"nice-data-grid-ai__insights-btn",onClick:()=>{se(),M(!0)},disabled:te||!L?.length,title:re("dataGridAI.generateInsights","Generate AI Insights"),children:[e.jsx(N.NiceIcon,{name:"lightbulb",size:14})," ",re("dataGridAI.insights","Insights")]})]}),f&&Me&&l&&!F&&S.length>0&&e.jsxs("div",{className:"nice-data-grid-ai__examples",children:[e.jsx("span",{className:"nice-data-grid-ai__examples-label",children:re("dataGridAI.tryAsking","Try asking:")}),e.jsx("div",{className:"nice-data-grid-ai__examples-list",children:S.slice(0,4).map((k,v)=>e.jsxs("button",{type:"button",className:"nice-data-grid-ai__example",onClick:()=>G(k),children:['"',k,'"']},v))})]}),F&&p.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.jsx(N.NiceIcon,{name:"target",size:14})}),e.jsxs("span",{className:"nice-data-grid-ai__filter-query",children:['"',F,'"']}),e.jsxs("span",{className:"nice-data-grid-ai__filter-count",children:["(",V?.length||0," ",re("dataGridAI.results","results"),")"]})]}),e.jsx("div",{className:"nice-data-grid-ai__filter-badges",children:p.map((k,v)=>e.jsxs("span",{className:"nice-data-grid-ai__filter-badge",children:[k.field," ",k.operator," ",String(k.value)]},v))}),e.jsxs("button",{type:"button",className:"nice-data-grid-ai__clear-filter",onClick:Re,children:[e.jsx(N.NiceIcon,{name:"close",size:14})," ",re("dataGridAI.clearFilter","Clear")]})]}),e.jsx("div",{className:"nice-data-grid-ai__grid-wrapper",children:e.jsx(Yn.NiceDataGrid,{columns:R,data:V,...z})}),$&&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:[e.jsx(N.NiceIcon,{name:"lightbulb",size:14})," ",re("dataGridAI.aiInsights","AI Insights")]}),e.jsx("button",{type:"button",className:"nice-data-grid-ai__insights-close",onClick:()=>M(!1),"aria-label":re("dataGridAI.closeInsights","Close"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-data-grid-ai__insights-body",children:te?e.jsx("div",{className:"nice-data-grid-ai__insights-loading",children:re("dataGridAI.analyzing","Analyzing data...")}):I.length>0?e.jsx("ul",{className:"nice-data-grid-ai__insights-list",children:I.map((k,v)=>e.jsxs("li",{className:"nice-data-grid-ai__insight",children:[e.jsx("span",{className:"nice-data-grid-ai__insight-bullet",children:"•"}),k]},v))}):e.jsx("div",{className:"nice-data-grid-ai__insights-empty",children:re("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:()=>se(),disabled:te,children:[e.jsx(N.NiceIcon,{name:"refresh",size:14})," ",re("dataGridAI.refresh","Refresh")]})})]})]})}const ya=i.forwardRef(xa);function va(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const Xn=({text:n,query:a,highlightTag:s="mark",highlightClassName:c="",caseSensitive:l=!1,className:d="",style:u,testId:o,"data-testid":_})=>{const f=(Array.isArray(a)?a:[a]).map(z=>(z??"").trim()).filter(Boolean).map(va);if(f.length===0||!n)return e.jsx("span",{className:`nice-highlight ${d}`,style:u,"data-testid":_??o,children:n});const S=l?"g":"gi",R=new RegExp(`(${f.join("|")})`,S),L=n.split(R);return e.jsx("span",{className:`nice-highlight ${d}`,style:u,"data-testid":_??o,children:L.map((z,b)=>b%2===1?e.jsx(s,{className:`nice-highlight__mark ${c}`.trim(),children:z},b):e.jsx(i.Fragment,{children:z},b))})};process.env.NODE_ENV!=="production"&&(Xn.displayName="NiceHighlight");function ka(n,a,s,c=0){const l=new Map,d=[];n.forEach(o=>l.set(String(o[a]),{data:o,children:[],key:String(o[a]),depth:0})),n.forEach(o=>{const _=o[s],f=l.get(String(o[a]));if(_!=null&&_!==""&&l.has(String(_))){const S=l.get(String(_));f.depth=S.depth+1,S.children.push(f)}else d.push(f)});const u=(o,_)=>{o.forEach(f=>{f.depth=_,u(f.children,_+1)})};return u(d,c),d}function wa(n,a,s){const c=l=>l.map(d=>{const u=d.children.length===0?a.get(d.key):void 0,o=u?s(u,d.depth+1):d.children;return o.length>0?{...d,children:c(o)}:d});return c(n)}function Na(n,a){const s=[],c=l=>{a(l)&&s.push(l.key),l.children.forEach(c)};return c(n),s}function Oi(n,a,s,c=0){return n.map(l=>({data:l,key:String(l[s]),depth:c,children:Array.isArray(l[a])?Oi(l[a],a,s,c+1):[]}))}function Wn(n){const a=[],s=c=>{c.forEach(l=>{l.children.length>0&&(a.push(l.key),s(l.children))})};return s(n),a}function ja(n){const a=[],s=c=>{c.forEach(l=>{a.push(l.key),s(l.children)})};return s(n),a}function Pi(n,a,s){return!a||!s?n:[...n].sort((l,d)=>{const u=l.data[a]??"",o=d.data[a]??"",_=typeof u=="number"&&typeof o=="number"?u-o:String(u).localeCompare(String(o));return s==="desc"?-_:_}).map(l=>({...l,children:Pi(l.children,a,s)}))}function Sa(n,a,s){const c=new Set,l=new Set,d=u=>u.reduce((o,_)=>{const f=d(_.children),S=a(_);return S&&l.add(_.key),f.length>0&&c.add(_.key),S&&s?o.push(_):(S||f.length>0)&&o.push({..._,children:f}),o},[]);return{tree:d(n),expand:c,matched:l}}function Ca(n,a){const s=(c,l)=>c.reduce((d,u)=>{if(l)return d.push({...u,children:s(u.children,!0)}),d;if(a.isCheckable(u.key)){const _=a.state(u.key);if(_!=="unchecked"){const f=a.isLeaf(u.key)&&_==="checked";d.push({...u,children:s(u.children,f)})}return d}const o=s(u.children,!1);return o.length>0&&d.push({...u,children:o}),d},[]);return s(n,!1)}function Da(n,a,s){const c=[],l=(d,u)=>{d.forEach((o,_)=>{if(c.push({node:o,level:u,posInSet:_+1,setSize:d.length}),o.children.length>0)a(o.key)&&l(o.children,u+1);else if(s&&a(o.key)){const f=s(o);f&&c.push({node:o,level:u+1,posInSet:1,setSize:1,placeholder:f})}})};return l(n,1),c}function Zn(n,a,s={}){const{getKey:c,getChildren:l,isCheckable:d,isDisabled:u}=a,o=s.inheritDisabled!==!1,_=[],f=[],S=[],R=new Map,L=(b,D,p,x)=>{const I=c(b);if(R.has(I))return;const y=d?d(b):!0,$=(u?u(b):!1)||o&&x,M={pos:_.length,subtreeEnd:0,leafStart:f.length,leafEnd:0,checkable:y,leaf:!1,disabled:$,parent:p};R.set(I,M),_.push(I);const F=l(b,D);if(F)for(const H of F)L(H,D+1,I,$);y&&f.length===M.leafStart&&(M.leaf=!0,f.push(I),S.push($)),M.leafEnd=f.length,M.subtreeEnd=_.length};for(const b of n)L(b,0,void 0,!1);const z=new Int32Array(f.length+1);for(let b=0;b<f.length;b++)z[b+1]=z[b]+(S[b]?1:0);return{keys:_,leaves:f,records:R,lockedBefore:z,has:b=>R.has(b),isCheckable:b=>R.get(b)?.checkable??!1,isLeaf:b=>R.get(b)?.leaf??!1,isLocked:b=>{const D=R.get(b);if(!D)return!1;const p=D.leafEnd-D.leafStart;return D.disabled||p===0?D.disabled:z[D.leafEnd]-z[D.leafStart]===p},leavesOf:b=>{const D=R.get(b);return D?f.slice(D.leafStart,D.leafEnd):[]},parentOf:b=>R.get(b)?.parent}}function Jn(n,a){const s=new Set,c=[];if(!a)return{leaves:s,unknown:c};const l=new Set;for(const d of a){const u=n.records.get(d);if(!u){l.has(d)||(l.add(d),c.push(d));continue}if(u.checkable)for(let o=u.leafStart;o<u.leafEnd;o++)s.add(n.leaves[o])}return{leaves:s,unknown:c}}function vn(n,a){const s=new Int32Array(n.leaves.length+1);for(let u=0;u<n.leaves.length;u++)s[u+1]=s[u]+(a.has(n.leaves[u])?1:0);const c=u=>{const o=n.records.get(u);return o?{checked:s[o.leafEnd]-s[o.leafStart],total:o.leafEnd-o.leafStart}:{checked:0,total:0}},l=u=>{const{checked:o,total:_}=c(u);return o===0||_===0?"unchecked":o===_?"checked":"indeterminate"},d=[];for(const u of n.keys){const o=n.records.get(u);o.checkable&&!o.leaf&&l(u)==="indeterminate"&&d.push(u)}return{state:l,count:c,total:{checked:s[n.leaves.length],total:n.leaves.length},halfChecked:d}}function ei(n,a,s,c){const l=n.records.get(s);if(!l||!l.checkable)return a;const d=[];for(let o=l.leafStart;o<l.leafEnd;o++)n.lockedBefore[o+1]===n.lockedBefore[o]&&d.push(n.leaves[o]);if(d.length===0)return a;const u=!d.every(o=>a.has(o));return Ki(a,d,u)}function Ri(n,a,s,c){const l=[];for(const d of s){const u=n.records.get(d);u?.leaf&&!u.disabled&&l.push(d)}return l.length===0?a:Ki(a,l,c)}function Ki(n,a,s){const c=new Set(n);for(const l of a)s?c.add(l):c.delete(l);return c}function an(n,a,s,c=[]){const l=[];if(s==="leaves")for(const d of n.leaves)a.has(d)&&l.push(d);else{const d=new Int32Array(n.leaves.length+1);for(let o=0;o<n.leaves.length;o++)d[o+1]=d[o]+(a.has(n.leaves[o])?1:0);const u=o=>o.leafEnd>o.leafStart&&d[o.leafEnd]-d[o.leafStart]===o.leafEnd-o.leafStart;for(let o=0;o<n.keys.length;){const _=n.keys[o],f=n.records.get(_);if(f.checkable&&u(f)&&(l.push(_),s==="parents")){o=f.subtreeEnd;continue}o++}}for(const d of c)l.push(d);return l}const Ma=600,Fi="application/x-nice-tree-row";function Hn(n,a,s=!0){const c=(n-a.top)/Math.max(1,a.height);return s?c<.25?"before":c>.75?"after":"inside":c<.5?"before":"after"}function ti(n,a=!1){if(!(n.ctrlKey||n.metaKey)||!n.shiftKey||n.altKey)return null;switch(n.key){case"ArrowUp":return"up";case"ArrowDown":return"down";case"ArrowRight":return a?"out":"in";case"ArrowLeft":return a?"in":"out";default:return null}}function ni(n,a,s,c){const l=c.indexOf(a);if(l<0)return null;switch(n){case"up":return l>0?{key:c[l-1],position:"before"}:null;case"down":return l<c.length-1?{key:c[l+1],position:"after"}:null;case"in":return l>0?{key:c[l-1],position:"inside"}:null;case"out":return s!==null?{key:s,position:"after"}:null}}function ii(n){const a=i.useRef(n);a.current=n;const[s,c]=i.useState(null),[l,d]=i.useState(null),u=i.useRef({drag:null,target:null}),o=i.useRef({key:null,timer:void 0}),_=i.useCallback(()=>{clearTimeout(o.current.timer),o.current={key:null,timer:void 0}},[]),f=i.useCallback(b=>{const D=u.current.target;if(D?.key===b?.key&&D?.position===b?.position)return;u.current.target=b,d(b);const p=b?.position==="inside"?b.key:null;p!==o.current.key&&(_(),p!==null&&a.current.onHoverOpen&&(o.current={key:p,timer:setTimeout(()=>a.current.onHoverOpen?.(p),Ma)}))},[_]),S=i.useCallback(()=>{_(),u.current={drag:null,target:null},c(null),d(null)},[_]);i.useEffect(()=>_,[_]);const R=b=>{const D=b.target?.closest?.(a.current.rowSelector);return D&&b.currentTarget.contains(D)?D:null},L=b=>{const D=a.current,p=u.current.drag,x=R(b),I=x?.dataset.key;if(!x||I===void 0||p===null||D.isWithin(I,p))return null;const y=(D.rectOf?.(x)??x).getBoundingClientRect(),$=D.canNest?D.canNest(I):!0,M=H=>D.canDrop?D.canDrop(p,I,H):!0,F=Hn(b.clientY,y,$);if(M(F))return{key:I,position:F};if(F==="inside"){const H=Hn(b.clientY,y,!1);return M(H)?{key:I,position:H}:null}return null};return{dragKey:s,target:l,handlers:{onDragStart:b=>{const D=a.current,p=R(b)?.dataset.key;if(!(!D.enabled||p===void 0)){if(D.canDrag&&!D.canDrag(p)){b.preventDefault();return}b.stopPropagation();try{b.dataTransfer.setData(Fi,p),b.dataTransfer.setData("text/plain",p),b.dataTransfer.effectAllowed="move"}catch{}u.current={drag:p,target:null},c(p)}},onDragOver:b=>{if(u.current.drag===null)return;const D=L(b);if(f(D),D){b.preventDefault();try{b.dataTransfer.dropEffect="move"}catch{}}},onDragLeave:b=>{const D=b.relatedTarget;(!D||!b.currentTarget.contains(D))&&f(null)},onDrop:b=>{const D=u.current.drag;if(D===null)return;const p=L(b)??u.current.target;b.preventDefault(),b.stopPropagation(),S(),p&&a.current.onDrop?.(D,p.key,p.position)},onDragEnd:S}}}const Ia=[],Ea=[],Qn=[],Ra=new Set,Aa=new Map,Ta=[],za=new Map,$a=new Map,Ai=["expandAll","collapseAll","onlyChecked","clearChecked"],Ti=10;function La({node:n,level:a,posInSet:s,setSize:c,rowIndex:l,ariaRowIndex:d,columns:u,highlight:o,query:_,expandable:f,expanded:S,busy:R,expandLabel:L,collapseLabel:z,subtreeAction:b,subtreeLabel:D,checkMode:p,hasCheckbox:x,checkState:I,checkLabel:y,locked:$,countChecked:M,countTotal:F,countTitle:H,selectColumn:xe,selected:re,selectLabel:ge,readOnly:Ce,className:te,clickable:Me,height:V,draggable:Ge,drop:Re,dragging:Ae,handlers:se}){const P=x?e.jsx("input",{type:"checkbox",className:"nice-treegrid__check-input",checked:I==="checked",ref:k=>{k&&(k.indeterminate=I==="indeterminate")},disabled:$||Ce,tabIndex:-1,"aria-label":y,onClick:k=>k.stopPropagation(),onChange:k=>{se.toggleCheck(n.key),k.currentTarget.closest("tr")?.focus({preventScroll:!0})}}):null,G=["nice-treegrid__row",p!=="none"&&!x?"nice-treegrid__row--info":"",$?"nice-treegrid__row--disabled":"",x&&I==="checked"?"nice-treegrid__row--checked":"",re?"nice-datagrid__row--selected":"",Re?`nice-treegrid__row--drop-${Re}`:"",Ae?"nice-treegrid__row--dragging":"",te??""].filter(Boolean).join(" ");return e.jsxs("tr",{className:G,"data-key":n.key,draggable:Ge||void 0,tabIndex:-1,"aria-level":a,"aria-posinset":s,"aria-setsize":c,"aria-rowindex":d,"aria-expanded":f?S:void 0,"aria-selected":re,"aria-disabled":$||void 0,"aria-busy":R||void 0,onClick:()=>se.rowClick(n),style:Me||V!==void 0?{cursor:Me?"pointer":void 0,height:V}:void 0,children:[p==="column"&&e.jsx("td",{className:"nice-datagrid__checkbox nice-treegrid__check-cell",children:P}),xe&&e.jsx("td",{className:"nice-datagrid__checkbox",children:e.jsx("input",{type:"checkbox",checked:!!re,onChange:()=>se.toggleSelected(n.key),onClick:k=>k.stopPropagation(),disabled:Ce,tabIndex:-1,"aria-label":ge})}),u.map((k,v)=>{const le=n.data[k.field];return e.jsxs("td",{style:{textAlign:k.align},children:[v===0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-treegrid__indent",style:{width:(a-1)*20}}),e.jsx("button",{type:"button",className:`nice-treegrid__toggle ${f?"":"nice-treegrid__toggle--leaf"}`,onClick:ie=>{ie.stopPropagation(),f&&se.toggleExpand(n.key,ie.altKey||ie.shiftKey)},tabIndex:-1,"aria-hidden":f?void 0:!0,"aria-label":f?S?z:L:void 0,children:f?e.jsx(N.NiceIcon,{name:S?"chevron-down":"chevron-right",size:12}):""}),p==="tree"&&e.jsx("span",{className:`nice-treegrid__check${x?"":" nice-treegrid__check--none"}`,children:P})]}),k.render?k.render(le,n.data,l):o[v]&&_?e.jsx(Xn,{text:String(le??""),query:_,highlightClassName:"nice-treegrid__match"}):String(le??""),v===0&&F>0&&e.jsxs("span",{className:`nice-treegrid__count${M===F?" nice-treegrid__count--full":""}`,title:H,children:[M,"/",F]}),v===0&&b&&e.jsx("button",{type:"button",className:"nice-treegrid__row-action",tabIndex:-1,"aria-label":D,title:D,onClick:ie=>{ie.stopPropagation(),se.setSubtreeExpanded(n.key,b==="expand")},children:e.jsx(N.NiceIcon,{name:b==="expand"?"expand":"collapse",size:12})})]},k.field)})]})}const Oa=i.memo(La);function Pa({columns:n=Ia,data:a=Ea,keyField:s="id",parentKeyField:c="parentId",nested:l=!1,childrenField:d="children",expandedKeys:u,defaultExpandedKeys:o,onExpandedChange:_,hasChildren:f,loadChildren:S,rowActions:R,defaultExpandAll:L=!1,sortable:z=!0,sortField:b,sortDirection:D,onSort:p,selectable:x,selectedKeys:I,onSelectionChange:y,checkable:$,checkedKeys:M,defaultCheckedKeys:F,onCheckedChange:H,checkStrategy:xe="all",isRowCheckable:re,isRowDisabled:ge,checkboxPlacement:Ce="tree",checkOnRowClick:te,showCheckedCount:Me,checkedSummary:V,showSelectAll:Ge=!0,showOnlyChecked:Re,defaultShowOnlyChecked:Ae,onShowOnlyCheckedChange:se,toolbarActions:P,searchable:G,searchPlaceholder:k,searchText:v,defaultSearchText:le,onSearchChange:ie,searchFields:j,searchFilter:me,searchKeepDescendants:fe=!1,searchAutoExpand:ye=!0,highlightMatches:T=!0,rowClassName:ce,getRowLabel:pe,virtualScroll:Ke,rowHeight:de=36,height:Ie,striped:we,compact:Pe,size:Fe="md",loading:rt,disabled:st,readOnly:ct,error:Se,emptyText:W,toolbar:_e,onRowClick:Ne,contextMenuItems:Ee,rowDraggable:Oe,canDrop:oe,onRowDrop:Z,editMode:kt,formItems:gt,formColumns:je=2,editFormTitle:Ct,formProps:at,onRowEdit:ot,apiRef:wt,selectionMode:r,selectedKey:C,defaultSelectedKey:Q,onSelectedKeyChange:J,className:Te,style:Y,id:ue,testId:We,"data-testid":ut,accessMode:Qe,"aria-label":Xe,"aria-labelledby":Et}){const{t:X}=N.useNiceTranslation(),Lt=N.useNiceAccessMode(Qe,ue),Nt=!!st||Lt==="disabled",bt=!!ct||Lt==="readOnly",Ot=i.useCallback((t,g)=>l?Oi(t,d,s,g):ka(t,s,c,g),[s,c,l,d]),Pt=i.useMemo(()=>Ot(a,0),[Ot,a]),[Je,lt]=i.useState(za),[At,Kt]=i.useState($a),Ue=i.useMemo(()=>Je.size>0?wa(Pt,Je,Ot):Pt,[Pt,Je,Ot]),Ve=i.useMemo(()=>{const t=new Map,g=E=>E.forEach(B=>{t.set(B.key,B),g(B.children)});return g(Ue),t},[Ue]),dt=!!f||!!S,et=i.useCallback(t=>{if(!dt)return!1;const g=Ve.get(t);return!!g&&g.children.length===0&&!Je.has(t)&&(f?f(g.data):!0)},[dt,Ve,Je,f]),m=i.useRef(new Set),h=i.useRef(!0);i.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const A=i.useCallback(t=>{const g=Ve.get(t);if(!S||!g||m.current.has(t))return;m.current.add(t);const E=B=>{m.current.delete(t),h.current&&(B&&lt(De=>new Map(De).set(t,B)),Kt(De=>{const ve=new Map(De);return B?ve.delete(t):ve.set(t,"error"),ve}))};Kt(B=>new Map(B).set(t,"loading")),S(g.data).then(B=>E(Array.isArray(B)?B:[]),()=>E(null))},[S,Ve]),q=i.useCallback(t=>{Kt(g=>{const E=new Map(g);return E.delete(t),E})},[]),U=i.useMemo(()=>n.filter(t=>!t.hidden),[n]),O=i.useMemo(()=>Wn(Ue),[Ue]),[K,ne]=i.useState(null),ee=i.useMemo(()=>{if(u)return new Set(u);if(K)return K;const t=new Set(o??Qn);return L&&O.forEach(g=>t.add(g)),t},[u,K,o,L,O]),Be=i.useRef(ee);Be.current=ee;const ze=i.useCallback(t=>{Be.current=t,u||ne(t),_?.([...t])},[u,_]),[qe,mt]=i.useState({field:"",dir:null}),xt=b??qe.field,tt=D??qe.dir,Ft=i.useCallback(t=>{const g=xt===t?tt==="asc"?"desc":tt==="desc"?null:"asc":"asc";p?p(t,g):mt({field:t,dir:g})},[xt,tt,p]),Rt=r==="single"&&!x,[wn,Nn]=i.useState(Q??null),Bt=C!==void 0?C:wn,[jn,sn]=N.useControllableState({value:I,fallbackValue:Ra,onChange:y,componentName:"NiceTreeGrid"}),Tt=i.useCallback(t=>{sn(g=>{const E=new Set(g);return E.has(t)?E.delete(t):E.add(t),E})},[sn]),he=i.useMemo(()=>$?Zn(Ue,{getKey:t=>t.key,getChildren:t=>t.children,isCheckable:re?t=>re(t.data):void 0,isDisabled:ge?t=>ge(t.data):void 0}):null,[$,Ue,re,ge]),[cn,Xt]=N.useControllableState({value:M,defaultValue:F,fallbackValue:Qn,componentName:"NiceTreeGrid"}),$e=i.useMemo(()=>he?Jn(he,cn):null,[he,cn]),nt=i.useMemo(()=>he&&$e?vn(he,$e.leaves):null,[he,$e]),Zt=i.useMemo(()=>{if(typeof V!="function"||!he||!$e||!nt)return null;const t=an(he,$e.leaves,"leaves"),g=[];return t.forEach(E=>{const B=Ve.get(E);B&&g.push(B.data)}),{checked:nt.total.checked,total:nt.total.total,leafKeys:t,rows:g}},[V,he,$e,nt,Ve]),zt=i.useCallback((t,g)=>{if(!he||!$e||t===$e.leaves)return;const E=an(he,t,xe,$e.unknown);Xt(E),H?.(E,{...g,leafKeys:an(he,t,"leaves"),halfCheckedKeys:[...vn(he,t).halfChecked]})},[he,$e,xe,Xt,H]),w=i.useCallback(t=>{if(!he||!$e)return;const g=ei(he,$e.leaves,t);zt(g,{source:"row",checked:g.size>$e.leaves.size,key:t,row:Ve.get(t)?.data})},[he,$e,zt,Ve]),[ae,ke]=N.useControllableState({value:v,defaultValue:le,fallbackValue:"",onChange:ie,componentName:"NiceTreeGrid"}),be=ae.trim(),ht=i.useMemo(()=>j??U.map(t=>t.field),[j,U]),ft=i.useMemo(()=>{if(!be)return null;const t=be.toLowerCase();return Sa(Ue,me?E=>me(E.data,be):E=>ht.some(B=>String(E.data[B]??"").toLowerCase().includes(t)),fe)},[Ue,be,me,ht,fe]),_t=ft?.tree??Ue,[pt,Sn]=N.useControllableState({value:Re,defaultValue:Ae,fallbackValue:!1,onChange:se,componentName:"NiceTreeGrid"}),$t=!!$&&pt&&nt!==null,Ut=i.useMemo(()=>$t&&nt&&he?Ca(_t,{state:nt.state,isCheckable:he.isCheckable,isLeaf:he.isLeaf}):_t,[$t,nt,he,_t]),Gt=be!==""||$t,Wt=`${be}
6
+ ${$t?1:0}`,[ai,ri]=i.useState(()=>({key:"",map:new Map})),si=ai.key===Wt?ai.map:Aa,ci=i.useMemo(()=>{const t=new Set;return ft&&ye&&ft.expand.forEach(g=>t.add(g)),$t&&he&&Wn(Ut).forEach(g=>{he.isLeaf(g)||t.add(g)}),t},[ft,ye,$t,he,Ut]),Dt=i.useCallback(t=>Gt?si.get(t)??(ee.has(t)||ci.has(t)):ee.has(t),[Gt,si,ee,ci]),on=i.useCallback((t,g)=>{const E=Be.current;if(t.some(B=>E.has(B)!==g)){const B=new Set(E);t.forEach(De=>g?B.add(De):B.delete(De)),ze(B)}Gt&&ri(B=>{const De=new Map(B.key===Wt?B.map:void 0);return t.forEach(ve=>De.set(ve,g)),{key:Wt,map:De}})},[ze,Gt,Wt]),oi=i.useCallback(t=>t.children.length>0||et(t.key),[et]),Jt=i.useRef(new Set),ln=i.useCallback((t,g)=>{const E=t.flatMap(B=>Na(B,oi));E.forEach(B=>{g?et(B)&&Jt.current.add(B):Jt.current.delete(B)}),on(E,g)},[oi,et,on]),en=i.useCallback((t,g)=>{const E=Ve.get(t);E&&ln([E],g)},[Ve,ln]),dn=i.useCallback((t,g)=>{const E=!Dt(t);g?en(t,E):on([t],E)},[Dt,en,on]),li=i.useRef({nodeByKey:Ve,isPending:et,setSubtreesExpanded:ln});li.current={nodeByKey:Ve,isPending:et,setSubtreesExpanded:ln},i.useEffect(()=>{const{nodeByKey:t,isPending:g,setSubtreesExpanded:E}=li.current,B=[];for(const De of[...Jt.current]){const ve=t.get(De);(!ve||ve.children.length>0||!g(De))&&(Jt.current.delete(De),B.push(...ve?.children??[]))}B.length>0&&E(B,!0)},[Ue]);const Wi=i.useCallback(t=>{t||Jt.current.clear(),ze(t?new Set(O):new Set),Gt&&ri({key:Wt,map:new Map(Wn(Ut).map(g=>[g,t]))})},[ze,O,Gt,Wt,Ut]),un=i.useMemo(()=>Pi(Ut,xt,tt),[Ut,xt,tt]),di=i.useCallback(t=>et(t.key)?At.get(t.key)==="error"?"error":"loading":null,[et,At]),jt=i.useMemo(()=>Da(un,Dt,dt?di:void 0),[un,Dt,dt,di]),Cn=R===!0||Array.isArray(R)&&R.includes("expandSubtree"),Qi=i.useMemo(()=>{const t=new Set;if(!Cn)return t;const g=E=>{if(E.children.length===0)return!et(E.key);let B=Dt(E.key);return E.children.forEach(De=>{g(De)||(B=!1)}),B&&t.add(E.key),B};return Ue.forEach(g),t},[Cn,Ue,et,Dt]);i.useEffect(()=>{S&&jt.forEach(t=>{t.placeholder==="loading"&&A(t.node.key)})},[jt,S,A]);const Qt=i.useMemo(()=>he?be?ja(_t).filter(t=>he.isLeaf(t)):he.leaves:Qn,[he,be,_t]),ui=i.useMemo(()=>{if(!$e||Qt.length===0)return"unchecked";let t=0;for(const g of Qt)$e.leaves.has(g)&&t++;return t===0?"unchecked":t===Qt.length?"checked":"indeterminate"},[$e,Qt]),qi=i.useCallback(()=>{if(!he||!$e)return;const t=Qt.filter(E=>!he.isLocked(E)),g=!t.every(E=>$e.leaves.has(E));zt(Ri(he,$e.leaves,t,g),{source:"selectAll",checked:g})},[he,$e,Qt,zt]),Yi=i.useCallback(()=>{he&&$e&&zt(Ri(he,$e.leaves,he.leaves,!1),{source:"clear",checked:!1})},[he,$e,zt]),hi=t=>{!Rt||Nt||t===Bt||(C===void 0&&Nn(t),J?.(t,Ve.get(t)?.data??null))},mi=t=>{hi(t.key),!(bt||Nt)&&($&&te&&he?.isCheckable(t.key)?w(t.key):$&&x&&Tt(t.key),Ne?.(t.data))},qt=i.useRef({toggleExpand:dn,setSubtreeExpanded:en,toggleCheck:w,toggleSelected:Tt,rowClick:mi});qt.current={toggleExpand:dn,setSubtreeExpanded:en,toggleCheck:w,toggleSelected:Tt,rowClick:mi};const fi=i.useMemo(()=>({toggleExpand:(t,g)=>qt.current.toggleExpand(t,g),setSubtreeExpanded:(t,g)=>qt.current.setSubtreeExpanded(t,g),toggleCheck:t=>qt.current.toggleCheck(t),toggleSelected:t=>qt.current.toggleSelected(t),rowClick:t=>qt.current.rowClick(t)}),[]),Vt=!!Oe&&!!Z&&!bt&&!Nt,Dn=i.useMemo(()=>{const t=new Map;if(!Vt)return t;const g=(E,B)=>{const De=E.map(ve=>ve.key);E.forEach(ve=>{t.set(ve.key,{parent:B,siblings:De}),g(ve.children,ve.key)})};return g(un,null),t},[Vt,un]),pi=i.useCallback((t,g)=>{const E=new Set;for(let B=t;B!=null&&!E.has(B);B=Dn.get(B)?.parent){if(B===g)return!0;E.add(B)}return!1},[Dn]),Mn=t=>{const g=Ve.get(t);return!!g&&(typeof Oe=="function"?Oe(g.data):!0)},gi=(t,g,E)=>{const B=Ve.get(t),De=Ve.get(g);return!B||!De||pi(g,t)?!1:oe?oe(B.data,De.data,E):!0},hn=ii({enabled:Vt,rowSelector:"tr.nice-treegrid__row",canDrag:Mn,isWithin:pi,canDrop:gi,onDrop:(t,g,E)=>Z?.(t,g,E),onHoverOpen:t=>{const g=Ve.get(t);g&&(g.children.length>0||et(t))&&!Dt(t)&&dn(t)}}),[Hi,_i]=i.useState(""),In=kt==="popup"&&!!ot&&!bt&&!Nt,[mn,En]=i.useState(null),[Xi,fn]=i.useState(null),[Zi,bi]=i.useState(!1),Rn=t=>{const g=t===void 0?void 0:Ve.get(t);In&&g&&(fn(null),En({key:g.key,data:{...g.data}}))},xi=()=>{En(null),fn(null)},pn=t=>{if(t===!1||typeof t=="string"){fn(typeof t=="string"&&t?t:X("treeGrid.saveFailed","The row could not be saved."));return}xi()},yi=t=>t instanceof Error?t.message:String(t),Ji=(t,g)=>{let E;try{E=ot?.(t,g)}catch(B){pn(yi(B));return}if(E instanceof Promise){bi(!0),fn(null),E.then(pn,B=>pn(yi(B))).finally(()=>bi(!1));return}pn(E)};i.useImperativeHandle(wt,()=>({editRow:t=>Rn(t)}));const yt=!!Ke,gn=i.useRef(null),[vi,ea]=i.useState(typeof Ie=="number"?Ie:480);i.useEffect(()=>{const t=gn.current;if(!yt||!t||typeof ResizeObserver>"u")return;const g=new ResizeObserver(()=>{t.clientHeight>0&&ea(t.clientHeight)});return g.observe(t),()=>g.disconnect()},[yt]);const An=N.useVirtualScroll({itemCount:yt?jt.length:0,itemHeight:de,containerHeight:vi,overscan:8}),Tn=yt?An.startIndex:0,zn=yt?An.endIndex:jt.length,$n=i.useRef(null),ki=i.useRef(Dt);ki.current=Dt,N.useTreeFocus($n,{itemSelector:"tr.nice-treegrid__row",enabled:!Nt,onToggle:(t,g)=>{const E=t.dataset.key;E!==void 0&&t.hasAttribute("aria-expanded")&&ki.current(E)!==g&&fi.toggleExpand(E)}});const ta=i.useContext(N.NiceThemeContext),Ln=i.useRef(null),[Yt,wi]=i.useState(null),On=i.useCallback(()=>wi(null),[]);N.useOverlayFocus(Ln,{open:!!Yt,modal:!1,initialFocus:'[role="menuitem"]:not([disabled])',onClose:On}),N.useRovingFocus(Ln,{orientation:"vertical",itemSelector:'[role="menuitem"]'});const Ni=(t,g,E)=>{const B=Ee?Ve.get(t):void 0,De=B?Ee?.(B.data):void 0;return De?.some(ve=>!ve.divider)?(wi({key:t,x:g,y:E,items:De}),!0):!1},Pn=i.useCallback(t=>[...$n.current?.querySelectorAll("tr.nice-treegrid__row")??[]].find(g=>g.dataset.key===t),[]),[Kn,Fn]=i.useState(null);i.useEffect(()=>{if(Kn===null)return;const t=Pn(Kn);t&&(t.focus(),Fn(null))},[Kn,Tn,zn,Pn]);const na=t=>{const g=jt[t]?.placeholder?t-1:t,E=jt[g]?.node.key;if(E===void 0)return;const B=Pn(E);B?B.focus():yt&&gn.current&&(gn.current.scrollTop=Math.max(0,g*de-vi/2),Fn(E))},ia=t=>{const g=t.target;if(t.altKey||t.ctrlKey||t.metaKey||!g.matches?.("tr.nice-treegrid__row"))return;const E=g.dataset.key??"";if(t.shiftKey&&(t.key==="ArrowRight"||t.key==="ArrowLeft")){if(g.hasAttribute("aria-expanded")){t.preventDefault();const ve=getComputedStyle(g).direction==="rtl";en(E,t.key==="ArrowRight"!==ve)}return}if(t.key===" "){if(Rt&&!$){t.preventDefault(),hi(E);return}if(bt)return;$&&he?.isCheckable(E)?(t.preventDefault(),w(E)):x&&(t.preventDefault(),Tt(E));return}if(!(t.key==="PageDown"||t.key==="PageUp")&&!(yt&&(t.key==="Home"||t.key==="End")))return;const De=jt.findIndex(ve=>ve.node.key===E);De<0||(t.preventDefault(),na(t.key==="PageDown"?Math.min(jt.length-1,De+Ti):t.key==="PageUp"?Math.max(0,De-Ti):t.key==="Home"?0:jt.length-1))},aa=X("controls.expand","Expand"),ra=X("controls.collapse","Collapse"),ji=U[0]?.field,_n=t=>pe?pe(t.data):String((ji!=null?t.data[ji]:void 0)??t.key),Si=(t,g)=>X("treeGrid.checkedSummary","{checked} of {total} selected").replace("{checked}",String(t)).replace("{total}",String(g)),sa=t=>{const g=t.target;if(!Vt||!g.matches?.("tr.nice-treegrid__row"))return!1;const E=ti(t,getComputedStyle(g).direction==="rtl");if(!E)return!1;t.preventDefault();const B=g.dataset.key??"",De=Dn.get(B),ve=De?ni(E,B,De.parent,De.siblings):null,Ye=Ve.get(B),Ht=ve?Ve.get(ve.key):void 0;if(!ve||!Ye||!Ht||!Mn(B)||!gi(B,ve.key,ve.position))return _i(X("treeDrop.cannotMove","Cannot move {label} there").replace("{label}",Ye?_n(Ye):B)),!0;ve.position==="inside"&&!Dt(ve.key)&&dn(ve.key),Z?.(B,ve.key,ve.position),Fn(B);const yn=ve.position==="before"?X("treeDrop.movedBefore","{label} moved before {target}"):ve.position==="after"?X("treeDrop.movedAfter","{label} moved after {target}"):X("treeDrop.movedInside","{label} moved into {target}");return _i(yn.replace("{label}",_n(Ye)).replace("{target}",_n(Ht))),!0},ca=i.useMemo(()=>{const t=new Set(ht);return U.map(g=>T&&!me&&t.has(g.field))},[U,ht,T,me]),Vn=P===!0?$?Ai:Ai.slice(0,2):Array.isArray(P)?P.filter(t=>$||t==="expandAll"||t==="collapseAll"):Ta,bn=$?Ce==="column"?"column":"tree":"none",xn=!!x&&!$,tn=U.length+(bn==="column"||xn?1:0),Ci=[["checked",!nt||V===!1?null:Zt&&typeof V=="function"?V(Zt):Si(nt.total.checked,nt.total.total)],["matches",ft?X("treeGrid.matchCount","{count} matching rows").replace("{count}",String(ft.matched.size)):null]].filter(([,t])=>t!=null&&t!==!1&&t!=="");if(Lt==="hidden")return null;const Bn=$&&Ge&&he&&he.leaves.length>0?e.jsx("input",{type:"checkbox",className:"nice-treegrid__check-input nice-treegrid__select-all",checked:ui==="checked",ref:t=>{t&&(t.indeterminate=ui==="indeterminate")},disabled:bt||Nt,"aria-label":be?X("treeGrid.selectAllResults","Select all results"):X("controls.selectAll","Select all"),onClick:t=>t.stopPropagation(),onChange:qi}):null,oa=t=>{const g={expandAll:{icon:"expand",label:X("treeGrid.expandAll","Expand all")},collapseAll:{icon:"collapse",label:X("treeGrid.collapseAll","Collapse all")},onlyChecked:{icon:"filter",label:X("treeGrid.showOnlyChecked","Show selected only")},clearChecked:{icon:"eraser",label:X("treeGrid.clearChecked","Clear selection")}}[t];return e.jsxs("button",{type:"button",className:`nice-btn nice-btn--sm nice-btn--ghost nice-treegrid__action${t==="onlyChecked"&&$t?" nice-treegrid__action--active":""}`,"aria-pressed":t==="onlyChecked"?$t:void 0,disabled:Nt||t==="clearChecked"&&(bt||!nt||nt.total.checked===0),onClick:()=>{t==="expandAll"||t==="collapseAll"?Wi(t==="expandAll"):t==="onlyChecked"?Sn(!pt):Yi()},children:[e.jsx(N.NiceIcon,{name:g.icon,size:14}),e.jsx("span",{children:g.label})]},t)},la=t=>{const{node:g,level:E,posInSet:B,setSize:De,placeholder:ve}=jt[t],Ye=g.key;if(ve)return e.jsx("tr",{className:`nice-treegrid__placeholder nice-treegrid__placeholder--${ve}`,"aria-level":E,style:yt?{height:de}:void 0,children:e.jsxs("td",{colSpan:tn,children:[e.jsx("span",{className:"nice-treegrid__indent",style:{width:(E-1)*20}}),e.jsx("span",{className:"nice-treegrid__toggle nice-treegrid__toggle--leaf","aria-hidden":"true"}),ve==="loading"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-spinner nice-spinner--sm","aria-hidden":"true"}),e.jsx("span",{role:"status",children:X("treeGrid.loading","Loading…")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"alert",children:X("treeGrid.loadError","Could not load the rows.")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--ghost",onClick:()=>q(Ye),children:X("treeGrid.retry","Retry")})]})]})},`${Ye}\0${ve}`);const Ht=g.children.length>0||et(Ye),yn=Ht&&Dt(Ye),Un=Cn&&Ht?Qi.has(Ye)?"collapse":"expand":null,Ii=!!he?.isCheckable(Ye),nn=Me&&nt&&he&&!he.isLeaf(Ye)?nt.count(Ye):null,da=_n(g);return e.jsx(Oa,{node:g,level:E,posInSet:B,setSize:De,rowIndex:t,ariaRowIndex:yt?t+2:void 0,columns:U,highlight:ca,query:be,expandable:Ht,expanded:yn,busy:yn&&At.get(Ye)==="loading",expandLabel:aa,collapseLabel:ra,subtreeAction:Un,subtreeLabel:Un==="expand"?X("treeGrid.expandSubtree","Expand all below"):Un==="collapse"?X("treeGrid.collapseSubtree","Collapse all below"):"",checkMode:bn,hasCheckbox:Ii,checkState:nt?nt.state(Ye):"unchecked",checkLabel:Ii?X("treeGrid.checkRow","Select {label}").replace("{label}",da):"",locked:!!he?.isLocked(Ye),countChecked:nn?.checked??0,countTotal:nn?.total??0,countTitle:nn?Si(nn.checked,nn.total):"",selectColumn:xn,selected:x?jn.has(Ye):Rt?Bt===Ye:void 0,selectLabel:xn?X("controls.selectRow","Select row {key}").replace("{key}",Ye):"",readOnly:bt,className:typeof ce=="function"?ce(g.data,t):ce,clickable:Rt||!bt&&(!!Ne||!!te||!!$&&!!x),height:yt?de:void 0,draggable:Vt&&Mn(Ye),drop:hn.target?.key===Ye?hn.target.position:null,dragging:hn.dragKey===Ye,handlers:fi},Ye)},Di=[];for(let t=Tn;t<zn;t++)Di.push(la(t));const Mi=(t,g)=>t>0?e.jsx("tr",{className:"nice-treegrid__spacer","aria-hidden":"true",children:e.jsx("td",{colSpan:tn,style:{height:t*de}})},g):null;return e.jsxs("div",{id:ue,"data-testid":ut??We,className:`nice-treegrid nice-datagrid ${Nt?"nice-treegrid--disabled":""} ${bt?"nice-treegrid--readonly":""} ${Se?"nice-treegrid--error":""} ${yt?"nice-treegrid--virtual":""} ${Te||""}`,style:Y,"aria-disabled":Nt||void 0,"aria-busy":rt||void 0,"aria-invalid":!!Se||void 0,children:[(G||_e||Vn.length>0)&&e.jsxs("div",{className:"nice-datagrid__toolbar nice-treegrid__toolbar",children:[G&&e.jsxs("div",{className:"nice-datagrid__search nice-treegrid__search",children:[e.jsx("input",{type:"search",value:ae,onChange:t=>ke(t.target.value),onKeyDown:t=>{t.key==="Escape"&&ae&&(t.preventDefault(),ke(""))},placeholder:k||X("controls.search","Search..."),"aria-label":k||X("controls.search","Search...")}),ae&&e.jsx("button",{type:"button",className:"nice-treegrid__search-clear",onClick:()=>ke(""),"aria-label":X("treeGrid.clearSearch","Clear search"),children:e.jsx(N.NiceIcon,{name:"close",size:12})})]}),Vn.length>0&&e.jsx("div",{className:"nice-treegrid__actions",children:Vn.map(oa)}),_e,Ci.length>0&&e.jsx("span",{className:"nice-treegrid__summary",role:"status",children:Ci.map(([t,g],E)=>e.jsxs(i.Fragment,{children:[E>0&&" · ",g]},t))})]}),e.jsx("div",{ref:gn,className:"nice-datagrid__table-wrap",style:yt?{height:Ie??480,overflow:"auto"}:void 0,onScroll:yt?An.onScroll:void 0,children:e.jsxs("table",{ref:$n,role:"treegrid","aria-label":Xe,"aria-labelledby":Et,"aria-multiselectable":x||$||void 0,"aria-rowcount":yt?jt.length+1:void 0,className:`nice-table nice-table--${Fe} ${we?"nice-table--striped":""} ${Pe?"nice-table--compact":""}`,onKeyDownCapture:t=>{if(Ee&&(t.key==="ContextMenu"||t.key==="F10"&&t.shiftKey)){const g=t.target.closest("tr.nice-treegrid__row"),E=g?.getBoundingClientRect();if(g?.dataset.key!==void 0&&E&&Ni(g.dataset.key,E.left+24,E.bottom)){t.preventDefault(),t.stopPropagation();return}}if(!sa(t)){if(In&&t.key==="F2"){const g=t.target.closest("tr.nice-treegrid__row");if(g){t.preventDefault(),Rn(g.dataset.key);return}}ia(t)}},onContextMenu:Ee?t=>{const g=t.target.closest("tr.nice-treegrid__row");g?.dataset.key!==void 0&&Ni(g.dataset.key,t.clientX,t.clientY)&&t.preventDefault()}:void 0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[bn==="column"&&e.jsx("th",{className:"nice-datagrid__checkbox nice-treegrid__th-check",children:Bn}),xn&&e.jsx("th",{className:"nice-datagrid__checkbox",style:{width:36}}),U.map((t,g)=>e.jsxs("th",{style:{width:t.width,minWidth:t.minWidth,textAlign:t.align},className:z&&t.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>z&&t.sortable!==!1&&Ft(t.field),children:[g===0&&bn==="tree"&&Bn&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-treegrid__toggle nice-treegrid__toggle--leaf","aria-hidden":"true"}),e.jsx("span",{className:"nice-treegrid__check",children:Bn})]}),t.header,z&&t.sortable!==!1&&e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:xt===t.field&&tt?void 0:.3},children:e.jsx(N.NiceIcon,{name:xt===t.field&&tt?tt==="asc"?"sort-asc":"sort-desc":"sort",size:12})})]},t.field))]})}),e.jsx("tbody",{...Vt?hn.handlers:void 0,onDoubleClick:In?t=>Rn(t.target.closest("tr.nice-treegrid__row")?.dataset.key):void 0,children:rt?e.jsx("tr",{children:e.jsx("td",{colSpan:tn,className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):Se?e.jsx("tr",{children:e.jsx("td",{colSpan:tn,className:"nice-datagrid__empty nice-treegrid__error",role:"alert",children:Se})}):jt.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:tn,className:"nice-datagrid__empty",children:be?X("controls.noResults","No results"):W||X("controls.noData","No data available")})}):e.jsxs(e.Fragment,{children:[Mi(Tn,"top"),Di,Mi(jt.length-zn,"bottom")]})})]})}),Yt&&typeof document<"u"&&ha.createPortal(e.jsx("div",{ref:Ln,className:"nice-treegrid__menu",role:"menu","aria-label":X("treeGrid.rowMenu","Row actions"),style:{position:"fixed",left:Yt.x,top:Yt.y},children:Yt.items.map(t=>t.divider?e.jsx("div",{className:"nice-treegrid__menu-divider",role:"separator"},t.id):e.jsxs("button",{type:"button",role:"menuitem",className:`nice-treegrid__menu-item${t.danger?" nice-treegrid__menu-item--danger":""}`,disabled:t.disabled,onClick:()=>{On(),t.onSelect?.()},children:[t.icon&&e.jsx(N.NiceIcon,{name:t.icon,size:14}),t.label]},t.id))}),ta?.portalTarget??document.body),mn&&e.jsx(Yn.NiceRowEditDialog,{title:Ct,items:gt??Yn.rowEditFormItems(n,s),data:mn.data,columns:je,formProps:at,error:Xi,saving:Zi,onClose:xi,onFieldChange:(t,g)=>En(E=>E&&{...E,data:{...E.data,[t]:g}}),onSubmit:t=>{Ji(mn.key,{...mn.data,...t})}}),Vt&&e.jsx("span",{className:"nice-sr-only",role:"status","aria-live":"polite",children:Hi}),Yt&&e.jsx("div",{className:"nice-treegrid__menu-backdrop","aria-hidden":"true",onMouseDown:On})]})}const Ka=[],Fa=[],Va=[];function Ba(n,a,s){const c=[],l=(o,_)=>{o.forEach(f=>{c.push({item:f,parent:f[s]??_}),Array.isArray(f.children)&&f.children.length>0&&l(f.children,f[a])})};l(n,null);const d=new Map,u=[];return c.forEach(({item:o})=>{const _={...o,children:[]};d.set(String(_[a]),_)}),c.forEach(({item:o,parent:_})=>{_!=null&&d.has(String(_))?d.get(String(_)).children.push(d.get(String(o[a]))):u.push(d.get(String(o[a])))}),u}function Ua({columns:n=Ka,data:a=Fa,keyField:s="key",parentKeyField:c="parentKey",expandedKeys:l,onExpandedChange:d,selectedKeys:u=Va,onSelectionChange:o,selectable:_,sortable:f,loading:S,emptyText:R,className:L,style:z,accessMode:b,id:D,"data-testid":p}){const I=N.useNiceAccessMode(b,D)==="hidden",{t:y}=N.useNiceTranslation(),[$,M]=i.useState([]),F=l??$,[H,xe]=i.useState(u),re=o?u:H,ge=i.useMemo(()=>Ba(a,s,c),[a,s,c]),Ce=i.useMemo(()=>n.filter(j=>!j.hidden),[n]),[te,Me]=i.useState(null),V=i.useCallback(j=>{Me(me=>me?.field===j?me.dir==="asc"?{field:j,dir:"desc"}:null:{field:j,dir:"asc"})},[]),Ge=i.useCallback(j=>te?[...j].sort((fe,ye)=>{const T=fe[te.field]??"",ce=ye[te.field]??"",pe=typeof T=="number"?T-ce:String(T).localeCompare(String(ce));return te.dir==="desc"?-pe:pe}).map(fe=>fe.children&&fe.children.length?{...fe,children:Ge(fe.children)}:fe):j,[te]),Re=i.useMemo(()=>Ge(ge),[ge,Ge]),Ae=i.useCallback(j=>{const me=F.includes(j)?F.filter(fe=>fe!==j):[...F,j];d?d(me):M(me)},[F,d]),se=i.useMemo(()=>Zn(ge,{getKey:j=>String(j[s]),getChildren:j=>j.children}),[ge,s]),P=i.useMemo(()=>Jn(se,re),[se,re]),G=i.useMemo(()=>vn(se,P.leaves),[se,P]),k=i.useCallback(j=>{const me=ei(se,P.leaves,j),fe=an(se,me,"all",P.unknown);o?o(fe):xe(fe)},[se,P,o]),v=Ce[0]?.field;let le=0;const ie=(j,me)=>{const fe=String(j[s]),ye=le++,T=!!(j.children&&j.children.length>0),ce=F.includes(fe),pe=G.state(fe),Ke=pe==="checked",de=pe==="indeterminate",Ie=v!=null?String(j[v]??fe):fe;return e.jsxs(i.Fragment,{children:[e.jsxs("tr",{className:Ke?"nice-treelist__row--selected":"",children:[_&&e.jsx("td",{className:"nice-treelist__checkbox",children:e.jsx("input",{type:"checkbox",checked:Ke,ref:we=>{we&&(we.indeterminate=de)},onChange:()=>k(fe),"aria-label":y("controls.selectRow","Select row {key}").replace("{key}",Ie)})}),Ce.map((we,Pe)=>e.jsxs("td",{style:{textAlign:we.align},children:[Pe===0&&e.jsx("span",{style:{display:"inline-block",width:me*20}}),Pe===0&&e.jsx("span",{role:T?"button":void 0,tabIndex:T?0:void 0,"aria-expanded":T?ce:void 0,"aria-label":T?y(ce?"controls.collapse":"controls.expand",ce?"Collapse":"Expand"):void 0,onKeyDown:T?N.clickOnActivationKey:void 0,className:"nice-treelist__toggle",onClick:()=>T&&Ae(fe),style:{cursor:T?"pointer":"default",width:20,display:"inline-block"},children:T?e.jsx(N.NiceIcon,{name:ce?"chevron-down":"chevron-right",size:12}):""}),we.render?we.render(j[we.field],j,ye):String(j[we.field]??"")]},we.field))]}),T&&ce&&j.children.map(we=>ie(we,me+1))]},fe)};return I?null:e.jsx("div",{className:`nice-treelist ${L||""}`,style:z,"data-testid":p,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[_&&e.jsx("th",{className:"nice-treelist__checkbox"}),Ce.map(j=>{const me=!!f&&!!j.sortable;return e.jsxs("th",{style:{width:j.width,minWidth:j.minWidth,textAlign:j.align},className:me?"nice-treelist__th--sortable":void 0,onClick:()=>me&&V(j.field),scope:"col","aria-sort":me?te?.field===j.field?te.dir==="asc"?"ascending":"descending":"none":void 0,children:[j.header,me&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:e.jsx(N.NiceIcon,{name:te?.field===j.field?te.dir==="desc"?"chevron-down":"chevron-up":"sort",size:12})})]},j.field)})]})}),e.jsx("tbody",{children:S?e.jsx("tr",{children:e.jsx("td",{colSpan:Ce.length+(_?1:0),className:"nice-treelist__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):ge.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Ce.length+(_?1:0),className:"nice-treelist__empty",children:R||y("controls.noData","No data available")})}):Re.map(j=>ie(j,0))})]})})}function Vi(n,a=[]){for(const s of n)s.expanded&&a.push(s.key),s.children&&Vi(s.children,a);return a}const qn=[],Ga=[],Wa=({nodes:n=qn,header:a,selectedKeys:s=Ga,expandedKeys:c,onSelectionChange:l,onExpandedChange:d,selectionMode:u="none",showCheckboxes:o,searchable:_,searchPlaceholder:f,onNodeClick:S,renderNode:R,showLines:L,loading:z,className:b,style:D,accessMode:p,id:x,draggable:I,onNodeDrop:y,canDrop:$,onLoadChildren:M,contextMenuItems:F,onContextMenuAction:H,editable:xe,onNodeEdit:re,maxDepth:ge,"data-testid":Ce})=>{const Me=N.useNiceAccessMode(p,x)==="hidden",{t:V}=N.useNiceTranslation(),[Ge,Re]=i.useState(()=>Vi(n)),[Ae,se]=i.useState(""),[P,G]=i.useState(new Set),[k,v]=i.useState(new Map),[le,ie]=i.useState(null),[j,me]=i.useState(null),[fe,ye]=i.useState(""),T=i.useRef(null),ce=c??Ge,pe=i.useRef(ce);pe.current=ce;const Ke=i.useMemo(()=>new Set(s),[s]),de=typeof ge=="number"?Math.min(10,Math.max(1,ge)):1/0,Ie=!!o&&u==="multiple",we=i.useMemo(()=>Ie?Zn(n,{getKey:r=>r.key,getChildren:(r,C)=>C+1>=de?null:k.get(r.key)??r.children,isDisabled:r=>!!r.disabled},{inheritDisabled:!1}):null,[Ie,n,k,de]),Pe=i.useMemo(()=>we?Jn(we,s):null,[we,s]),Fe=i.useMemo(()=>we&&Pe?vn(we,Pe.leaves):null,[we,Pe]),rt=i.useCallback(async(r,C)=>{const Q=pe.current,J=!Q.includes(r),Te=J?[...Q,r]:Q.filter(Y=>Y!==r);if(pe.current=Te,d?d(Te):Re(Te),J&&M&&!C.children?.length&&C.leaf!==!0&&!k.has(r)){G(ue=>new Set(ue).add(r));const Y=await M(C);v(ue=>new Map(ue).set(r,Y)),G(ue=>{const We=new Set(ue);return We.delete(r),We})}},[d,M,k]),st=i.useCallback(r=>{if(l){if(u==="single")l(s.includes(r)?[]:[r]);else if(u==="multiple")if(we&&Pe){const C=ei(we,Pe.leaves,r);C!==Pe.leaves&&l(an(we,C,"all",Pe.unknown))}else l(s.includes(r)?s.filter(C=>C!==r):[...s,r])}},[s,u,l,we,Pe]),ct=i.useCallback(r=>{if(!Ae)return!0;const C=Ae.toLowerCase();return r.text.toLowerCase().includes(C)?!0:(k.get(r.key)??r.children)?.some(J=>ct(J))??!1},[Ae,k]),Se=i.useCallback((r,C)=>{F?.length&&(r.preventDefault(),ie({x:r.clientX,y:r.clientY,node:C}))},[F]),W=i.useCallback(()=>{j&&re&&re(j,fe),me(null)},[j,fe,re]),_e=i.useRef(null),Ne=(r,C=n)=>{for(const Q of C){const J=Q.key===r?Q:Ne(r,k.get(Q.key)??Q.children??qn);if(J)return J}},Ee=!!I&&!!y,Oe=i.useMemo(()=>{const r=new Map;if(!Ee)return r;const C=(Q,J)=>{const Te=Q.map(Y=>Y.key);Q.forEach(Y=>{r.set(Y.key,{parent:J,siblings:Te}),C(k.get(Y.key)??Y.children??qn,Y.key)})};return C(n,null),r},[Ee,n,k]),oe=(r,C)=>{const Q=new Set;for(let J=r;J!=null&&!Q.has(J);J=Oe.get(J)?.parent){if(J===C)return!0;Q.add(J)}return!1},Z=(r,C,Q)=>!oe(C,r)&&(Q!=="inside"||Ne(C)?.leaf!==!0)&&($?$(r,C,Q):!0),kt=ii({enabled:Ee,rowSelector:'[role="treeitem"]',rectOf:r=>[...r.children].find(C=>C.classList.contains("nice-tree__row"))??r,canDrag:r=>!Ne(r)?.disabled,canNest:r=>Ne(r)?.leaf!==!0,isWithin:oe,canDrop:Z,onDrop:(r,C,Q)=>y?.(r,C,Q),onHoverOpen:r=>{const C=Ne(r);C&&!pe.current.includes(r)&&rt(r,C)}}),[gt,je]=i.useState(""),Ct=r=>{const C=r.target.closest?.('[role="treeitem"]'),Q=Ee&&C&&j===null?ti(r,getComputedStyle(C).direction==="rtl"):null;if(!C||!Q)return;r.preventDefault(),r.stopPropagation();const J=C.dataset.key??"",Te=Oe.get(J),Y=Te?ni(Q,J,Te.parent,Te.siblings):null,ue=Ne(J),We=Y?Ne(Y.key):void 0;if(!Y||!ue||!We||ue.disabled||!Z(J,Y.key,Y.position)){je(V("treeDrop.cannotMove","Cannot move {label} there").replace("{label}",ue?.text??J));return}Y.position==="inside"&&!pe.current.includes(Y.key)&&rt(Y.key,We),y?.(J,Y.key,Y.position),at.current=J;const ut=Y.position==="before"?V("treeDrop.movedBefore","{label} moved before {target}"):Y.position==="after"?V("treeDrop.movedAfter","{label} moved after {target}"):V("treeDrop.movedInside","{label} moved into {target}");je(ut.replace("{label}",ue.text).replace("{target}",We.text))};N.useTreeFocus(_e,{rowSelector:".nice-tree__row",onToggle:(r,C)=>{const Q=r.dataset.key===void 0?void 0:Ne(r.dataset.key);Q&&pe.current.includes(Q.key)!==C&&rt(Q.key,Q)}});const at=i.useRef(null);i.useEffect(()=>{if(j!==null||at.current===null)return;const r=at.current;at.current=null,[..._e.current?.querySelectorAll('[role="treeitem"]')??[]].find(C=>C.dataset.key===r)?.focus()},[j]);const ot=i.useRef(null);N.useRovingFocus(ot,{orientation:"vertical",wrap:!0,typeahead:!0}),N.useOverlayFocus(ot,{open:!!le,modal:!1,onClose:()=>ie(null)});const wt=(r,C)=>{if(Ae&&!ct(r))return null;const Q=C+1>=de,J=Q?void 0:k.get(r.key)??r.children,Te=!Q&&(J&&J.length>0||r.leaf!==!0&&M&&!J?.length),Y=ce.includes(r.key),ue=Fe?Fe.state(r.key):Ke.has(r.key)?"checked":"unchecked",We=Fe?ue==="checked":Ke.has(r.key),ut=!!r.disabled||!!we?.isLocked(r.key),Qe=P.has(r.key),Xe=Math.min(C+1,10),Et={paddingLeft:C*20+4,"--nice-row-bg":`var(--nice-tree-level-${Xe}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${Xe}-text, inherit)`,"--nice-row-border":`var(--nice-tree-level-${Xe}-border, transparent)`,"--nice-row-hover-bg":`var(--nice-tree-level-${Xe}-hover-bg, var(--nice-hover-bg, color-mix(in srgb, var(--nice-text-primary) 6%, transparent)))`,"--nice-row-active-bg":`var(--nice-tree-level-${Xe}-active-bg, color-mix(in srgb, var(--nice-color-primary) 14%, transparent))`};return e.jsxs("li",{className:"nice-tree__node",role:"treeitem","aria-label":r.text,"aria-expanded":Te?Y:void 0,"aria-selected":u!=="none"?We:void 0,"aria-disabled":r.disabled||void 0,"data-key":r.key,"data-nice-depth":Xe,onKeyDown:xe&&!r.disabled?X=>{X.key==="F2"&&X.target===X.currentTarget&&(X.preventDefault(),me(r.key),ye(r.text))}:void 0,draggable:Ee&&!r.disabled||void 0,children:[e.jsxs("div",{role:"presentation",className:`nice-tree__row ${We?"nice-tree__row--selected":""} ${r.disabled?"nice-tree__row--disabled":""} ${kt.dragKey===r.key?"nice-tree__row--dragging":""} ${kt.target?.key===r.key?`nice-tree__row--drop-${kt.target.position}`:""}`,style:Et,onClick:()=>{r.disabled||(st(r.key),S?.(r))},onContextMenu:X=>Se(X,r),onDoubleClick:xe&&!r.disabled?()=>{me(r.key),ye(r.text)}:void 0,children:[e.jsx("span",{role:"presentation",className:`nice-tree__toggle ${Te?Y?"nice-tree__toggle--expanded":"":"nice-tree__toggle--leaf"}`,onClick:X=>{X.stopPropagation(),Te&&rt(r.key,r)},children:Qe?e.jsx("span",{className:"nice-spinner nice-spinner--xs"}):Te?Y?e.jsx(N.NiceIcon,{name:"chevron-down",size:12}):e.jsx(N.NiceIcon,{name:"chevron-right",size:12}):""}),o&&u!=="none"&&e.jsx("input",{type:"checkbox",checked:ue==="checked",ref:X=>{X&&(X.indeterminate=ue==="indeterminate")},onChange:()=>st(r.key),onClick:X=>X.stopPropagation(),disabled:ut,tabIndex:-1,"aria-label":r.text,className:"nice-tree__checkbox"}),j===r.key?e.jsx("input",{type:"text",className:"nice-tree__edit-input",value:fe,onChange:X=>ye(X.target.value),onBlur:W,onKeyDown:X=>{X.key==="Enter"&&(at.current=r.key,W()),X.key==="Escape"&&(X.preventDefault(),at.current=r.key,me(null))},autoFocus:!0,onClick:X=>X.stopPropagation()}):R?R(r):e.jsxs(e.Fragment,{children:[r.icon&&e.jsx("span",{className:"nice-tree__icon",children:r.icon}),e.jsx("span",{className:"nice-tree__text",children:r.text})]})]}),J&&J.length>0&&Y&&e.jsx("ul",{className:"nice-tree__children",role:"group",children:J.map(X=>wt(X,C+1))})]},r.key)};return Me?null:e.jsxs("div",{role:"presentation",className:`nice-tree ${L?"nice-tree--lines":""} ${b||""}`,style:D,ref:T,"data-testid":Ce,onClick:()=>ie(null),children:[a!=null&&a!==!1&&e.jsx("div",{className:"nice-tree__header",children:a}),_&&e.jsx("div",{className:"nice-tree__search",children:e.jsx("input",{type:"text",value:Ae,onChange:r=>se(r.target.value),placeholder:f||V("controls.search","Search..."),"aria-label":f||V("controls.search","Search tree")})}),z?e.jsx("div",{className:"nice-tree__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm"})}):e.jsx("ul",{ref:_e,className:"nice-tree__root",role:"tree","aria-multiselectable":u==="multiple"||void 0,onKeyDownCapture:Ee?Ct:void 0,...Ee?kt.handlers:void 0,children:n.map(r=>wt(r,0))}),Ee&&e.jsx("span",{className:"nice-sr-only",role:"status","aria-live":"polite",children:gt}),le&&F&&e.jsx("div",{ref:ot,className:"nice-tree__context-menu",role:"menu","aria-label":le.node.text,style:{position:"fixed",top:le.y,left:le.x,zIndex:9999},children:F.map(r=>e.jsxs("button",{type:"button",role:"menuitem",disabled:r.disabled,className:`nice-tree__context-item ${r.disabled?"nice-tree__context-item--disabled":""}`,onClick:()=>{r.disabled||(H?.(r.key,le.node),ie(null))},children:[r.icon&&e.jsx("span",{children:r.icon}),r.label]},r.key))})]})},Qa=[],qa=({items:n=Qa,selectedKeys:a=[],onSelectionChange:s,selectionMode:c="none",searchable:l,searchPlaceholder:d,grouped:u,groupField:o="group",reorderable:_,onReorder:f,onItemClick:S,renderItem:R,showCheckboxes:L,loading:z,emptyText:b,size:D="md",header:p,disabled:x,readOnly:I,error:y,bordered:$=!0,swipeActions:M,className:F,style:H,accessMode:xe,id:re,"data-testid":ge})=>{const te=N.useNiceAccessMode(xe,re)==="hidden",{t:Me}=N.useNiceTranslation(),[V,Ge]=i.useState(""),[Re,Ae]=i.useState(null),[se,P]=i.useState(null),G=i.useRef(null),k=i.useMemo(()=>{if(!V)return n;const T=V.toLowerCase();return n.filter(ce=>ce.text.toLowerCase().includes(T))},[n,V]),v=i.useMemo(()=>{if(!u)return null;const T=new Map;return k.forEach(ce=>{const pe=String(ce[o]??"");T.has(pe)||T.set(pe,[]),T.get(pe).push(ce)}),T},[k,u,o]),le=i.useCallback(T=>{s&&(c==="single"?s(a.includes(T)?[]:[T]):c==="multiple"&&s(a.includes(T)?a.filter(ce=>ce!==T):[...a,T]))},[a,c,s]),ie=i.useCallback(T=>{Re!==null&&Re!==T&&f&&f(Re,T),Ae(null)},[Re,f]),j=i.useRef(null),me=i.useCallback(T=>{j.current=T},[]);N.useRovingFocus(j,{orientation:"vertical",itemSelector:".nice-list__item",typeahead:!0,pageSize:10});const fe=T=>{!T.disabled&&!x&&!I&&(le(T.key),S?.(T))},ye=(T,ce)=>{const pe=a.includes(T.key),Ke=se===T.key;return e.jsxs("li",{className:`nice-list__item ${pe?"nice-list__item--selected":""} ${T.disabled?"nice-list__item--disabled":""} ${Ke?"nice-list__item--swiped":""}`,onClick:()=>fe(T),onKeyDown:de=>{de.target===de.currentTarget&&(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),fe(T))},draggable:_&&!x&&!I,onDragStart:()=>Ae(ce),onDragOver:de=>de.preventDefault(),onDrop:()=>ie(ce),onTouchStart:M?.length?de=>{G.current={x:de.touches[0].clientX,key:T.key}}:void 0,onTouchEnd:M?.length?de=>{if(!G.current)return;const Ie=de.changedTouches[0].clientX-G.current.x;Ie<-50&&G.current.key===T.key?P(T.key):Ie>50&&P(null),G.current=null}:void 0,role:"option","aria-selected":c!=="none"?pe:void 0,"aria-disabled":T.disabled||void 0,children:[e.jsxs("div",{className:"nice-list__item-content",children:[L&&c!=="none"&&e.jsx("input",{type:"checkbox",checked:pe,readOnly:!0,tabIndex:-1,className:"nice-list__checkbox"}),R?R(T):e.jsxs(e.Fragment,{children:[T.icon&&e.jsx("span",{className:"nice-list__icon",children:T.icon}),e.jsx("span",{className:"nice-list__text",children:T.text}),T.badge&&e.jsx("span",{className:"nice-list__badge",children:T.badge})]})]}),M&&Ke&&e.jsx("div",{className:"nice-list__swipe-actions",children:M.map(de=>e.jsx("button",{className:"nice-list__swipe-btn",style:de.color?{backgroundColor:de.color}:void 0,onClick:Ie=>{Ie.stopPropagation(),de.onClick(T),P(null)},children:de.label},de.key))})]},T.key)};return te?null:e.jsxs("div",{className:`nice-list nice-list--${D} ${$?"nice-list--bordered":""} ${x?"nice-list--disabled":""} ${I?"nice-list--readonly":""} ${y?"nice-list--error":""} ${F||""}`,style:H,"data-testid":ge,"aria-disabled":x||void 0,"aria-busy":z||void 0,children:[p&&e.jsx("div",{className:"nice-list__header",children:p}),l&&!z&&e.jsx("div",{className:"nice-list__search",children:e.jsx("input",{type:"text",value:V,onChange:T=>Ge(T.target.value),placeholder:d||Me("controls.search","Search...")})}),z?e.jsx("div",{className:"nice-list__loading",role:"status","aria-live":"polite",children:e.jsx("div",{className:`nice-spinner nice-spinner--${D}`})}):y?e.jsx("div",{className:"nice-list__error",role:"alert",children:y}):k.length===0?e.jsx("div",{className:"nice-list__empty",children:b||Me("controls.noData","No data available")}):e.jsx("div",{role:"listbox",ref:me,"aria-multiselectable":c==="multiple"||void 0,children:v?Array.from(v.entries()).map(([T,ce])=>e.jsxs("div",{className:"nice-list__group",role:"group","aria-label":T,children:[e.jsx("div",{className:"nice-list__group-header","aria-hidden":"true",children:T}),e.jsx("ul",{className:"nice-list__items",role:"presentation",children:ce.map((pe,Ke)=>ye(pe,Ke))})]},T)):e.jsx("ul",{className:"nice-list__items",role:"presentation",children:k.map((T,ce)=>ye(T,ce))})})]})},Ya=[],Ha=[];function Xa({columns:n=Ya,data:a=Ha,striped:s,compact:c,size:l="md",emptyText:d,className:u,style:o,accessMode:_,id:f,displayStyle:S}){const{t:R}=N.useNiceTranslation(),L=N.normalizeSize(l),b=N.useNiceAccessMode(_,f)==="hidden",D=N.useComponentDisplayStyle("table",S),p=N.useComponentDisplayClass("table",S),[x,I]=i.useState(null),y=i.useMemo(()=>x?[...a].sort((M,F)=>{const H=M[x.field]??"",xe=F[x.field]??"",re=typeof H=="number"?H-xe:String(H).localeCompare(String(xe));return x.dir==="desc"?-re:re}):a,[a,x]),$=M=>{I(F=>F?.field===M?F.dir==="asc"?{field:M,dir:"desc"}:null:{field:M,dir:"asc"})};return b?null:e.jsx("div",{className:`nice-table-wrapper ${u||""}`,style:{...D,...o},children:e.jsxs("table",{className:`nice-table nice-table--ds-${p} nice-table--${L} ${s?"nice-table--striped":""} ${c?"nice-table--compact":""}`,"aria-rowcount":y.length,"aria-colcount":n.length,children:[e.jsx("thead",{children:e.jsx("tr",{children:n.map(M=>{const F=M.sortable?x?.field===M.field?x.dir==="asc"?"ascending":"descending":"none":void 0;return e.jsxs("th",{style:{width:M.width,textAlign:M.align},className:M.sortable?"th--sortable":void 0,onClick:()=>M.sortable&&$(M.field),scope:"col","aria-sort":F,children:[M.header,M.sortable&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:e.jsx(N.NiceIcon,{name:x?.field===M.field?x.dir==="desc"?"chevron-down":"chevron-up":"sort",size:12})})]},M.field)})})}),e.jsx("tbody",{children:y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:n.length,className:"nice-table__empty",children:d||R("table.noData","No data")})}):y.map((M,F)=>e.jsx("tr",{children:n.map(H=>e.jsx("td",{style:{textAlign:H.align},children:H.render?H.render(M[H.field],M):String(M[H.field]??"")},H.field))},F))})]})})}const Za=[];function Ja({items:n=Za,tileWidth:a=180,tileHeight:s=180,direction:c="horizontal",renderTile:l,onTileClick:d,loading:u,emptyText:o,className:_,style:f,"data-testid":S}){const{t:R}=N.useNiceTranslation();return e.jsx("div",{className:`nice-tileview nice-tileview--${c} ${_||""}`,style:f,"data-testid":S,children:u?e.jsx("div",{className:"nice-tileview__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):n.length===0?e.jsx("div",{className:"nice-tileview__empty",children:o||R("controls.noData","No data available")}):e.jsx("div",{className:"nice-tileview__container",style:{display:"flex",flexWrap:"wrap",gap:8,flexDirection:c==="vertical"?"column":"row"},children:n.map(L=>e.jsx("div",{role:d?"button":void 0,tabIndex:d?0:void 0,onKeyDown:d?N.clickOnActivationKey:void 0,className:"nice-tileview__tile",style:{width:a,height:s,cursor:d?"pointer":void 0},onClick:()=>d?.(L),children:l?l(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 er=[],tr=[];function nr({open:n}){return e.jsx(N.NiceIcon,{name:"chevron-down",size:14,style:{transition:"transform 160ms ease",transform:n?"rotate(0deg)":"rotate(-90deg)"}})}function ir(){return e.jsx(N.NiceIcon,{name:"plus",size:14})}const ar=[{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"}],rr=Object.assign(i.forwardRef(({columns:n=er,cards:a=tr,onCardMove:s,onCardClick:c,renderCard:l,onAddCard:d,disabled:u=!1,size:o="md",collapsible:_=!1,collapseDirection:f="vertical",layoutMode:S="scroll",viewMode:R,onViewModeChange:L,collapsedColumns:z,onCollapsedColumnsChange:b,formItems:D,formColumns:p=1,formProps:x,editCardTitle:I,newCardTitle:y,onCardEdit:$,onCardCreate:M,onCardDelete:F,tutorial:H,cookies:xe=!1,localStorage:re=!0,sessionStorage:ge=!1,storageMode:Ce,storageKey:te,className:Me,style:V,id:Ge,...Re},Ae)=>{const{t:se}=N.useNiceTranslation(),[P,G]=i.useState(null),[k,v]=i.useState(null),[le,ie]=i.useState(null),j=!!D&&(!!$||!!M),me=i.useCallback(W=>{if(j&&$){ie({key:W.key,data:{...W},column:W.column});return}c?.(W)},[j,c,$]),fe=j&&!!$||!!c,ye=i.useCallback(W=>{if(j&&M){ie({key:null,data:{title:"",description:""},column:W});return}d?.(W)},[j,d,M]),T=pa.useStorageAdapter(te??"nice-kanban"),[ce,pe]=i.useState(()=>T.get("state")??{collapsedColumns:[],viewMode:"default"}),Ke=i.useMemo(()=>z??ce.collapsedColumns??[],[z,ce.collapsedColumns]),de=R??ce.viewMode??"default",Ie=i.useCallback(W=>{pe(_e=>{const Ne={..._e,...W};return T.set("state",Ne),Ne})},[T]),we=i.useCallback(W=>{const _e=Ke.includes(W)?Ke.filter(Ne=>Ne!==W):[...Ke,W];b?b(_e):Ie({collapsedColumns:_e})},[Ke,b,Ie]);i.useCallback(W=>{L?L(W):Ie({viewMode:W})},[L,Ie]);const Pe=i.useCallback(W=>a.filter(_e=>_e.column===W).sort((_e,Ne)=>(_e.order??0)-(Ne.order??0)),[a]),Fe=i.useCallback((W,_e)=>{u||(W.dataTransfer.effectAllowed="move",W.dataTransfer.setData("text/plain",String(_e.key)),G({cardKey:_e.key,fromColumn:_e.column}))},[u]),rt=i.useCallback((W,_e)=>{W.preventDefault(),W.dataTransfer.dropEffect="move",v({column:_e})},[]),st=i.useCallback(()=>{v(null)},[]),ct=i.useCallback((W,_e)=>{if(W.preventDefault(),v(null),!P||u)return;const Ne=Pe(_e);s?.(P.cardKey,_e,Ne.length),G(null)},[P,u,Pe,s]),Se=i.useCallback(()=>{G(null),v(null)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:Ae,id:Ge,className:`nice-kanban nice-kanban--${o} nice-kanban--${de} nice-kanban--layout-${S} ${u?"nice-kanban--disabled":""} ${Me||""}`,style:{position:"relative",...V},...Re,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(H,ar)})}),n.map(W=>{const _e=Pe(W.key),Ne=k?.column===W.key,Ee=W.limit!=null&&_e.length>=W.limit,Oe=_&&Ke.includes(W.key);return e.jsxs("div",{className:`nice-kanban__column ${Ne?"nice-kanban__column--dragover":""} ${Oe?`nice-kanban__column--collapsed nice-kanban__column--collapse-${f}`:""}`,onDragOver:oe=>!Oe&&rt(oe,W.key),onDragLeave:st,onDrop:oe=>!Oe&&ct(oe,W.key),children:[e.jsxs("div",{className:"nice-kanban__column-header",style:W.color?{borderTopColor:W.color}:void 0,onClick:_?()=>we(W.key):void 0,role:_?"button":void 0,tabIndex:_?0:void 0,onKeyDown:_?oe=>{(oe.key==="Enter"||oe.key===" ")&&we(W.key)}:void 0,children:[_&&e.jsx("span",{className:"nice-kanban__collapse-icon","aria-hidden":"true",children:e.jsx(nr,{open:!Oe})}),e.jsx("span",{className:"nice-kanban__column-title",children:W.title}),e.jsx("span",{className:"nice-kanban__column-count",children:W.limit!=null?e.jsxs("span",{className:"nice-kanban__count-frac",children:[e.jsx("span",{className:"nice-kanban__count-num",children:_e.length}),e.jsx("span",{className:"nice-kanban__count-slash",children:"/"}),e.jsx("span",{className:"nice-kanban__count-den",children:W.limit})]}):_e.length})]}),!Oe&&e.jsxs("div",{className:"nice-kanban__column-body",children:[_e.map(oe=>e.jsx("div",{className:`nice-kanban__card nice-kanban__card--${de} ${P?.cardKey===oe.key?"nice-kanban__card--dragging":""}`,draggable:!u,onDragStart:Z=>Fe(Z,oe),onDragEnd:Se,onClick:()=>me(oe),role:fe?"button":"article",tabIndex:fe?0:void 0,onKeyDown:fe?N.clickOnActivationKey:void 0,children:l?l(oe):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"nice-kanban__card-title",children:oe.title}),de!=="compact"&&oe.description&&e.jsx("div",{className:"nice-kanban__card-desc",children:oe.description})]})},oe.key)),_e.length===0&&e.jsx("div",{className:"nice-kanban__empty",children:se("kanban.empty","No cards")})]}),!Oe&&(d||j&&M)&&!Ee&&e.jsxs("button",{type:"button",className:"nice-kanban__add",onClick:()=>ye(W.key),disabled:u,children:[e.jsx(ir,{})," ",se("kanban.addCard","Add card")]})]},W.key)})]}),j&&le&&e.jsxs(fa.NiceModal,{open:!0,onClose:()=>ie(null),title:le.key==null?y||se("kanban.newCard","New card"):I||se("kanban.editCard","Edit card"),children:[e.jsx(ma.NiceForm,{items:D,data:le.data,columns:p,...x,onFieldChange:(W,_e)=>ie(Ne=>Ne&&{...Ne,data:{...Ne.data,[W]:_e}})}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16,flexWrap:"wrap"},children:[le.key!=null&&F&&e.jsx(He.NiceButton,{type:"button",size:"sm",variant:"error",style:{marginRight:"auto"},onClick:()=>{F(le.key),ie(null)},children:se("controls.delete","Delete")}),e.jsx(He.NiceButton,{type:"button",size:"sm",variant:"secondary",onClick:()=>ie(null),children:se("controls.cancel","Cancel")}),e.jsx(He.NiceButton,{type:"button",size:"sm",variant:"primary",onClick:()=>{if(le.key==null){const W={key:`card-${Date.now()}`,title:"",column:le.column,...le.data};M?.(W)}else $?.(le.key,{...le.data,key:le.key,column:le.column});ie(null)},children:se("controls.save","Save")})]})]})]})}),{displayName:"NiceKanbanBoard"}),sr=[];function It(...n){return n.filter(Boolean).map(a=>typeof a=="object"?Object.entries(a).filter(([,s])=>s).map(([s])=>s).join(" "):a).join(" ")}const cr=50,or=[10,25,50,100,200],lr=40,dr={compact:32,normal:lr,comfortable:48},ur=10,hr=768,mr=500,fr=10;function St(n,a){return a.split(".").reduce((s,c)=>s?.[c],n)}function Bi(n){return n.width==="auto"?{flex:"1 1 0",minWidth:n.minWidth??80,maxWidth:n.maxWidth}:{width:n.width||150,minWidth:n.minWidth,maxWidth:n.maxWidth}}function rn(n,a,s="pl-PL"){if(n==null)return"—";switch(a.type){case"number":return new Intl.NumberFormat(s,{minimumFractionDigits:a.format?.includes(".")?a.format.split(".")[1].length:0}).format(n);case"currency":return new Intl.NumberFormat(s,{style:"currency",currency:a.currencyCode||"PLN"}).format(n);case"percent":return new Intl.NumberFormat(s,{style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}).format(n/100);case"date":return new Intl.DateTimeFormat(s,{dateStyle:"short"}).format(new Date(n));case"datetime":return new Intl.DateTimeFormat(s,{dateStyle:"short",timeStyle:"short"}).format(new Date(n));case"boolean":return n?e.jsx(N.NiceIcon,{name:"check",size:14}):e.jsx(N.NiceIcon,{name:"close",size:14});case"enum":return a.enumOptions?.find(l=>l.value===n)?.label||String(n);default:return String(n)}}function pr(n,a,s,c){const[l,d]=i.useState(0),{startIndex:u,endIndex:o,totalHeight:_,offsetY:f}=i.useMemo(()=>{const L=n.length*s,z=Math.ceil(a/s),b=Math.max(0,Math.floor(l/s)-c),D=Math.min(n.length,Math.ceil(l/s)+z+c),p=b*s;return{startIndex:b,endIndex:D,totalHeight:L,offsetY:p}},[n.length,a,s,l,c]),S=i.useMemo(()=>n.slice(u,o),[n,u,o]),R=i.useCallback(L=>{d(L.currentTarget.scrollTop)},[]);return{visibleData:S,totalHeight:_,offsetY:f,handleScroll:R,startIndex:u}}function gr(n,a){const[s,c]=i.useState(()=>{if(n&&typeof window<"u"){const d=localStorage.getItem(`nice-module-grid-${n}`);if(d)return JSON.parse(d)}return a||{}}),l=i.useCallback(d=>{c(u=>{const o={...u,...d};return n&&typeof window<"u"&&localStorage.setItem(`nice-module-grid-${n}`,JSON.stringify(o)),o})},[n]);return[s,l]}function _r(n){const[a,s]=i.useState(typeof window<"u"&&window.innerWidth<n);return i.useEffect(()=>{if(typeof window>"u")return;const c=()=>s(window.innerWidth<n);return window.addEventListener("resize",c),()=>window.removeEventListener("resize",c)},[n]),a}function br({column:n,sort:a,onSort:s,onResize:c,resizable:l,t:d}){const u=i.useRef(null),[o,_]=i.useState(!1),f=i.useCallback(L=>{if(!l||!c)return;L.preventDefault(),_(!0);const z=L.clientX,b=n.width||150,D=x=>{const I=x.clientX-z,y=Math.max(n.minWidth||50,b+I);c(n.field,Math.min(y,n.maxWidth||1/0))},p=()=>{_(!1),document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",D),document.addEventListener("mouseup",p)},[n,l,c]),S=a?.direction,R=S==="asc"?e.jsx(N.NiceIcon,{name:"sort-asc",size:12}):S==="desc"?e.jsx(N.NiceIcon,{name:"sort-desc",size:12}):null;return e.jsxs("div",{className:It("nice-module-grid__header-cell",n.sortable&&"nice-module-grid__header-cell--sortable",o&&"nice-module-grid__header-cell--resizing"),style:{...Bi(n),textAlign:n.align},onClick:()=>n.sortable&&s?.(n.field),role:"columnheader","aria-sort":S==="asc"?"ascending":S==="desc"?"descending":"none",title:n.headerTooltip,children:[e.jsx("span",{className:"nice-module-grid__header-text",children:n.header}),R&&e.jsx("span",{className:"nice-module-grid__sort-indicator",children:R}),l&&e.jsx("div",{ref:u,className:"nice-module-grid__resize-handle",onMouseDown:f})]})}function xr({column:n,row:a,rowIndex:s,value:c,locale:l="pl-PL",onClick:d}){const{t:u}=N.useNiceTranslation(),o=N.useAccessibleClick({onClick:d}),_=d?o:{},f={...Bi(n),textAlign:n.align};if(n.render)return e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:n.render(c,a,s)});if((n.type==="enum"||n.type==="badge")&&n.enumOptions){const S=n.enumOptions.find(R=>R.value===c);if(S)return e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:e.jsxs("span",{className:It("nice-module-grid__badge",`nice-module-grid__badge--${S.color||"default"}`),children:[S.icon&&e.jsx("span",{className:"nice-module-grid__badge-icon",children:S.icon}),S.label]})})}if(n.type==="progress"){const S=Math.min(100,Math.max(0,Number(c)||0));return e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:e.jsxs("div",{className:"nice-module-grid__progress",children:[e.jsx("div",{className:"nice-module-grid__progress-bar",children:e.jsx("div",{className:It("nice-module-grid__progress-fill",`nice-module-grid__progress-fill--${n.progressColor||"primary"}`),style:{width:`${S}%`}})}),e.jsxs("span",{className:"nice-module-grid__progress-text",children:[S,"%"]})]})})}if(n.type==="rating"){const S=n.maxRating||5,R=Number(c)||0;return e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:e.jsx("span",{className:"nice-module-grid__rating","aria-label":u("pagination.outOfStars","{rating} out of {max} stars").replace("{rating}",String(R)).replace("{max}",String(S)),children:Array.from({length:S},(L,z)=>e.jsx("span",{className:It("nice-module-grid__rating-star",z<R&&"nice-module-grid__rating-star--filled"),children:e.jsx(N.NiceIcon,{name:"star",size:14})},z))})})}if(n.type==="link"&&n.linkTemplate){const S=n.linkTemplate.replace(/\{\{(\w+)\}\}/g,(R,L)=>String(St(a,L)??""));return e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:e.jsx("a",{href:S,target:n.linkNewTab?"_blank":void 0,rel:n.linkNewTab?"noopener noreferrer":void 0,className:"nice-module-grid__link",children:rn(c,n,l)})})}if(n.type==="image"){const R={xs:24,sm:32,md:48,lg:64}[n.imageSize||"sm"];return e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:c?e.jsx("img",{src:String(c),alt:"",className:"nice-module-grid__image",style:{width:R,height:R}}):e.jsx("div",{className:"nice-module-grid__image-placeholder",style:{width:R,height:R}})})}return n.type==="avatar"?e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:c?e.jsx("img",{src:String(c),alt:"",className:"nice-module-grid__avatar"}):e.jsx("div",{className:"nice-module-grid__avatar-placeholder",children:"?"})}):n.type==="color"?e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:e.jsx("span",{className:"nice-module-grid__color-swatch",style:{backgroundColor:c||"transparent"},title:c})}):n.type==="boolean"?e.jsx("div",{className:"nice-module-grid__cell",style:{...f,textAlign:n.align||"center"},role:"gridcell",..._,children:e.jsx("span",{className:It("nice-module-grid__boolean",!!c&&"nice-module-grid__boolean--true"),children:e.jsx(N.NiceIcon,{name:c?"check":"close",size:14})})}):e.jsx("div",{className:"nice-module-grid__cell",style:f,role:"gridcell",..._,children:rn(c,n,l)})}function yr({row:n,index:a,columns:s,primaryField:c,secondaryField:l,customRender:d,selected:u,onClick:o,locale:_="pl-PL",t:f}){const S={role:"option","aria-selected":!!u,onClick:o,onKeyDown:z=>{z.target===z.currentTarget&&(z.key==="Enter"||z.key===" ")&&(z.preventDefault(),o?.())}};if(d)return e.jsx("div",{className:It("nice-module-grid__mobile-card",u&&"nice-module-grid__mobile-card--selected"),...S,children:d(n,a)});const R=s.find(z=>z.field===c)||s[0],L=s.find(z=>z.field===l)||s[1];return e.jsxs("div",{className:It("nice-module-grid__mobile-card",u&&"nice-module-grid__mobile-card--selected"),...S,children:[e.jsxs("div",{className:"nice-module-grid__mobile-card-header",children:[e.jsx("div",{className:"nice-module-grid__mobile-card-title",children:rn(St(n,R?.field||""),R,_)}),L&&e.jsx("div",{className:"nice-module-grid__mobile-card-subtitle",children:rn(St(n,L.field),L,_)})]}),e.jsx("div",{className:"nice-module-grid__mobile-card-body",children:s.filter(z=>!z.hidden&&z.field!==c&&z.field!==l).slice(0,4).map(z=>e.jsxs("div",{className:"nice-module-grid__mobile-card-field",children:[e.jsx("span",{className:"nice-module-grid__mobile-card-label",children:z.header}),e.jsx("span",{className:"nice-module-grid__mobile-card-value",children:rn(St(n,z.field),z,_)})]},z.field))})]})}function vr({page:n,pageSize:a,totalRows:s,pageSizeOptions:c,onPageChange:l,t:d}){const u=Math.ceil(s/a),o=(n-1)*a+1,_=Math.min(n*a,s);return e.jsxs("div",{className:"nice-module-grid__pagination",role:"navigation","aria-label":d("pagination.ariaLabel","Pagination"),children:[e.jsxs("div",{className:"nice-module-grid__pagination-info",children:[d("pagination.showing","Showing")," ",o,"–",_," ",d("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:f=>l(1,Number(f.target.value)),"aria-label":d("pagination.rowsPerPage","Rows per page"),children:c.map(f=>e.jsx("option",{value:f,children:f},f))}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(1,a),disabled:n===1,"aria-label":d("pagination.first","First"),children:e.jsx(N.NiceIcon,{name:"skip-back",size:14})}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(n-1,a),disabled:n===1,"aria-label":d("pagination.previous","Previous"),children:e.jsx(N.NiceIcon,{name:"chevron-left",size:14})}),e.jsxs("span",{className:"nice-module-grid__pagination-page",children:[n," / ",u]}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(n+1,a),disabled:n>=u,"aria-label":d("pagination.next","Next"),children:e.jsx(N.NiceIcon,{name:"chevron-right",size:14})}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(u,a),disabled:n>=u,"aria-label":d("pagination.last","Last"),children:e.jsx(N.NiceIcon,{name:"skip-forward",size:14})})]})]})}function kr({columns:n}){return e.jsx("div",{className:"nice-module-grid__row nice-module-grid__row--skeleton",role:"row",children:n.filter(a=>!a.hidden).map(a=>e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--skeleton",style:{width:a.width==="auto"?"auto":a.width||150},children:e.jsx("div",{className:"nice-module-grid__skeleton-bar"})},a.field))})}function wr(n,a){const{columns:s=sr,data:c,keyField:l="id",dataSource:d,onFetch:u,sortable:o=!0,sort:_,onSortChange:f,multiSort:S=!1,filter:R,searchText:L,onSearchChange:z,searchPlaceholder:b,pagination:D=!0,page:p,pageSize:x,pageSizeOptions:I=or,totalRows:y,onPageChange:$,virtualScroll:M=!0,rowHeight:F,overscan:H=ur,selectionMode:xe="none",selectedKeys:re,onSelectionChange:ge,columnResize:Ce=!0,onColumnWidthChange:te,contextMenuItems:Me,onContextMenuAction:V,exportable:Ge=!0,exportFormats:Re=["csv","excel"],onExport:Ae,preferencesKey:se,initialPreferences:P,density:G="normal",striped:k=!0,bordered:v=!1,hoverable:le=!0,loading:ie=!1,emptyState:j,toolbar:me,onRowClick:fe,onRowDoubleClick:ye,rowClassName:T,rowStyle:ce,mobileCardView:pe=!0,mobileBreakpoint:Ke=hr,mobileCardRender:de,mobilePrimaryField:Ie,mobileSecondaryField:we,size:Pe="medium",skeletonLoading:Fe=!0,skeletonRows:rt=fr,"aria-label":st,"aria-labelledby":ct,"aria-describedby":Se,className:W,style:_e,id:Ne,testId:Ee}=n,Oe=F??dr[G],{t:oe,lang:Z}=N.useNiceTranslation();N.useNiceAccessMode(),N.useComponentDisplayStyle("table");const kt=_r(Ke),[gt,je]=gr(se,P),Ct=i.useRef(null),at=i.useRef(null),[ot,wt]=i.useState([]),[r,C]=i.useState(),[Q,J]=i.useState(""),[Te,Y]=i.useState(1),[ue,We]=i.useState(x||cr),[ut,Qe]=i.useState(new Set),[Xe,Et]=i.useState([]),[X,Lt]=i.useState(0),[Nt,bt]=i.useState(!1),[Ot,Pt]=i.useState(new Set),[Je,lt]=i.useState(null),[At,Kt]=i.useState({}),Ue=_??ot,Ve=R??r,dt=L??Q,et=p??Te,m=x??ue,h=re??ut,A=!!(u||d),q=y??(A?X:c?.length??0),U=i.useMemo(()=>{const w=new Set(gt.hiddenColumns||[]);return s.filter(ae=>!ae.hidden&&!w.has(ae.field))},[s,gt.hiddenColumns]),O=i.useMemo(()=>{if(A)return Xe;if(!c)return[];let w=[...c];if(dt){const ae=dt.toLowerCase(),ke=s.filter(be=>be.searchable!==!1).map(be=>be.field);w=w.filter(be=>ke.some(ht=>{const ft=St(be,ht);return String(ft??"").toLowerCase().includes(ae)}))}return Ue.length>0&&w.sort((ae,ke)=>{for(const be of Ue){const ht=St(ae,be.field),ft=St(ke,be.field),_t=ht<ft?-1:ht>ft?1:0;if(_t!==0)return be.direction==="asc"?_t:-_t}return 0}),w},[A,Xe,c,dt,Ue,s]),K=i.useMemo(()=>{if(A||!D)return O;const w=(et-1)*m;return O.slice(w,w+m)},[A,O,D,et,m]),ne=Ct.current?.clientHeight||400,ee=M&&K.length>mr,{visibleData:Be,totalHeight:ze,offsetY:qe,handleScroll:mt,startIndex:xt}=pr(K,ne,Oe,H),tt=ee?Be:K,Ft=i.useCallback(async()=>{if(u){bt(!0);try{const ae=await u({page:et,pageSize:m,sort:Ue,filter:Ve,search:dt});Et(ae.data),Lt(ae.total)}catch(w){console.error("NiceModuleGrid fetch error:",w)}finally{bt(!1)}}},[u,et,m,Ue,Ve,dt]);i.useEffect(()=>{A&&Ft()},[A,Ft]);const Rt=i.useCallback(w=>{const ae=Ue.find(be=>be.field===w);let ke;ae?ae.direction==="asc"?ke=Ue.map(be=>be.field===w?{...be,direction:"desc"}:be):ke=Ue.filter(be=>be.field!==w):ke=S?[...Ue,{field:w,direction:"asc"}]:[{field:w,direction:"asc"}],f?f(ke):wt(ke)},[Ue,S,f]),wn=i.useCallback((w,ae)=>{$?$(w,ae):(Y(w),We(ae))},[$]),Nn=i.useCallback(w=>{z?z(w):J(w),$||Y(1)},[z,$]),Bt=i.useCallback((w,ae)=>{const ke=new Set(h);if(xe==="single"?(ke.clear(),ke.add(w)):(xe==="multiple"||xe==="checkbox")&&(ke.has(w)?ke.delete(w):ke.add(w)),ge){const be=K.filter(ht=>ke.has(String(St(ht,l))));ge(ke,be)}else Qe(ke)},[h,xe,ge,K,l]),jn=i.useCallback((w,ae)=>{Kt(ke=>({...ke,[w]:ae})),te?.(w,ae),je({columnWidths:{...gt.columnWidths,[w]:ae}})},[te,je,gt.columnWidths]),sn=i.useCallback((w,ae)=>{if(Me?.length)if(w.preventDefault(),w.clientX===0&&w.clientY===0){const ke=w.currentTarget.getBoundingClientRect();lt({x:ke.left,y:ke.bottom,row:ae})}else lt({x:w.clientX,y:w.clientY,row:ae})},[Me]),Tt=i.useRef(null);N.useOverlayFocus(Tt,{open:Je!=null,modal:!1,onClose:()=>lt(null)}),N.useRovingFocus(Tt,{orientation:"vertical",wrap:!0,typeahead:!0});const he=i.useCallback(w=>{Je&&V?.(w,Je.row),lt(null)},[Je,V]),cn=i.useCallback(async w=>{if(Ae)await Ae(w,{selectedOnly:h.size>0,columns:U.map(ae=>ae.field)});else if(w==="csv"){const ae=U.map(pt=>pt.header).join(","),ke=K.map(pt=>U.map(Sn=>JSON.stringify(St(pt,Sn.field)??"")).join(",")),be=[ae,...ke].join(`
7
+ `),ht=new Blob([be],{type:"text/csv;charset=utf-8;"}),ft=URL.createObjectURL(ht),_t=document.createElement("a");_t.href=ft,_t.download=`export-${new Date().toISOString().slice(0,10)}.csv`,_t.click(),URL.revokeObjectURL(ft)}},[Ae,h,U,K]);i.useEffect(()=>{if(!Je)return;const w=()=>lt(null);return document.addEventListener("click",w),()=>document.removeEventListener("click",w)},[Je]),N.useGridFocus(at,{pageSize:10});const Xt=i.useRef(null);N.useRovingFocus(Xt,{orientation:"vertical",pageSize:10});const $e=ie||Nt,nt=!$e&&tt.length===0,Zt=kt&&pe,zt=It("nice-module-grid",`nice-module-grid--${G}`,`nice-module-grid--${Pe}`,k&&"nice-module-grid--striped",v&&"nice-module-grid--bordered",le&&"nice-module-grid--hoverable",$e&&"nice-module-grid--loading",Zt&&"nice-module-grid--mobile",W);return e.jsxs("div",{ref:a,id:Ne,"data-testid":Ee,className:zt,style:_e,"aria-busy":$e,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:b??oe("moduleGrid.searchPlaceholder","Search…"),value:dt,onChange:w=>Nn(w.target.value),"aria-label":oe("moduleGrid.searchAriaLabel","Search")})}),me,Ge&&e.jsx("div",{className:"nice-module-grid__toolbar-export",children:Re.map(w=>e.jsx("button",{className:"nice-module-grid__export-btn",onClick:()=>cn(w),"aria-label":oe(`moduleGrid.export.${w}`,`Export to ${w.toUpperCase()}`),children:w.toUpperCase()},w))})]}),e.jsx("div",{ref:Ct,className:"nice-module-grid__container",onScroll:ee?mt:void 0,children:Zt?e.jsx("div",{ref:Xt,className:"nice-module-grid__mobile-list",role:"listbox","aria-label":st,"aria-labelledby":ct,"aria-describedby":Se,"aria-multiselectable":xe==="checkbox"||void 0,children:$e&&Fe?Array.from({length:rt},(w,ae)=>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}})]},ae)):nt?e.jsxs("div",{className:"nice-module-grid__empty",children:[j?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:j.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:j?.title||oe("moduleGrid.noData","No data")}),j?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:j.description}),j?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:j.action.onClick,children:[j.action.icon,j.action.label]})]}):tt.map((w,ae)=>{const ke=String(St(w,l));return e.jsx(yr,{row:w,index:xt+ae,columns:U,primaryField:Ie,secondaryField:we,customRender:de,selected:h.has(ke),locale:Z,onClick:()=>{xe!=="none"&&Bt(ke,w),fe?.(w,xt+ae)},t:oe},ke)})}):e.jsxs("div",{ref:at,className:"nice-module-grid__table",role:"grid","aria-label":st,"aria-labelledby":ct,"aria-describedby":Se,"aria-rowcount":q,"aria-colcount":U.length,children:[e.jsxs("div",{className:"nice-module-grid__header",role:"row",children:[xe==="checkbox"&&e.jsx("div",{className:"nice-module-grid__header-cell nice-module-grid__header-cell--checkbox",role:"columnheader",children:e.jsx("input",{type:"checkbox",checked:h.size>0&&h.size===tt.length,onChange:()=>{if(h.size===tt.length)ge?.(new Set,[]),Qe(new Set);else{const w=new Set(tt.map(ae=>String(St(ae,l))));ge?.(w,tt),Qe(w)}},"aria-label":oe("moduleGrid.selectAll","Select all")})}),U.map(w=>e.jsx(br,{column:{...w,width:At[w.field]||w.width},sort:Ue.find(ae=>ae.field===w.field),onSort:o?Rt:void 0,onResize:Ce?jn:void 0,resizable:Ce,t:oe},w.field))]}),e.jsx("div",{className:"nice-module-grid__body",style:ee?{height:ze,position:"relative"}:void 0,children:$e&&Fe?Array.from({length:rt},(w,ae)=>e.jsx(kr,{columns:U},ae)):nt?e.jsxs("div",{className:"nice-module-grid__empty",children:[j?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:j.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:j?.title||oe("moduleGrid.noData","No data")}),j?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:j.description}),j?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:j.action.onClick,children:[j.action.icon,j.action.label]})]}):e.jsx("div",{style:ee?{transform:`translateY(${qe}px)`}:void 0,children:tt.map((w,ae)=>{const ke=String(St(w,l)),be=xt+ae,ht=h.has(ke),ft=typeof T=="function"?T(w,be):T,_t=typeof ce=="function"?ce(w,be):ce;return e.jsxs("div",{className:It("nice-module-grid__row",ht&&"nice-module-grid__row--selected",ft),style:{..._t,height:Oe},role:"row","aria-rowindex":be+1,"aria-selected":ht,onClick:()=>{xe!=="none"&&Bt(ke,w),fe?.(w,be)},onDoubleClick:()=>ye?.(w,be),onContextMenu:pt=>sn(pt,w),children:[xe==="checkbox"&&e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--checkbox",role:"gridcell",children:e.jsx("input",{type:"checkbox",checked:ht,onChange:()=>Bt(ke,w),onClick:pt=>pt.stopPropagation(),"aria-label":oe("moduleGrid.selectRow","Select row")})}),U.map(pt=>e.jsx(xr,{column:{...pt,width:At[pt.field]||pt.width},row:w,rowIndex:be,value:St(w,pt.field),locale:Z},pt.field))]},ke)})})})]})}),D&&q>0&&e.jsx(vr,{page:et,pageSize:m,totalRows:A?X:O.length,pageSizeOptions:I,onPageChange:wn,t:oe}),Je&&Me&&e.jsx("div",{ref:Tt,className:"nice-module-grid__context-menu",style:{left:Je.x,top:Je.y},role:"menu",children:Me.filter(w=>typeof w.hidden=="function"?!w.hidden(Je.row):!w.hidden).map(w=>{if(w.divider)return e.jsx("div",{className:"nice-module-grid__context-menu-divider"},w.key);const ae=typeof w.disabled=="function"?w.disabled(Je.row):w.disabled;return e.jsxs("button",{className:It("nice-module-grid__context-menu-item",w.danger&&"nice-module-grid__context-menu-item--danger",ae&&"nice-module-grid__context-menu-item--disabled"),onClick:()=>{ae||(w.onClick?.(Je.row),he(w.key))},disabled:ae,role:"menuitem",children:[w.icon&&e.jsx("span",{className:"nice-module-grid__context-menu-icon",children:w.icon}),w.label]},w.key)})}),$e&&!Fe&&e.jsx("div",{className:"nice-module-grid__loading-overlay",children:e.jsx("div",{className:"nice-module-grid__spinner","aria-label":oe("moduleGrid.loading","Loading")})})]})}const Nr=i.forwardRef(wr),vt={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},jr=()=>e.jsxs("svg",{...vt,children:[e.jsx("path",{d:"M3 7v6h6"}),e.jsx("path",{d:"M21 17a9 9 0 0 0-15-6.7L3 13"})]}),Sr=()=>e.jsxs("svg",{...vt,children:[e.jsx("path",{d:"M21 7v6h-6"}),e.jsx("path",{d:"M3 17a9 9 0 0 1 15-6.7L21 13"})]}),Cr=()=>e.jsxs("svg",{...vt,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"})]}),Dr=()=>e.jsxs("svg",{...vt,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"})]}),Mr=()=>e.jsxs("svg",{...vt,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"})]}),Ir=()=>e.jsxs("svg",{...vt,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"})]}),Er=()=>e.jsxs("svg",{...vt,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"})]}),Rr=()=>e.jsxs("svg",{...vt,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"})]}),Ar=()=>e.jsxs("svg",{...vt,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"})]}),Tr=()=>e.jsx("svg",{...vt,children:e.jsx("polyline",{points:"6 9 12 4 18 9"})}),zr=()=>e.jsx("svg",{...vt,children:e.jsx("polyline",{points:"6 15 12 20 18 15"})}),$r=()=>e.jsxs("svg",{...vt,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 9 12 4 18 9"}),e.jsx("polyline",{points:"6 15 12 20 18 15"})]}),Lr=()=>e.jsxs("svg",{...vt,children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),Or=()=>e.jsxs("svg",{...vt,children:[e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),e.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"})]});function Ui(n){let a="",s=n;for(;s>=0;)a=String.fromCharCode(65+s%26)+a,s=Math.floor(s/26)-1;return a}function Le(n,a){return`${Ui(a)}${n+1}`}function it(n){const a=n.match(/^([A-Z]+)(\d+)$/);if(!a)return null;let s=0;for(let c=0;c<a[1].length;c++)s=s*26+(a[1].charCodeAt(c)-64);return{row:parseInt(a[2],10)-1,col:s-1}}function Pr(n,a,s=new Set){const c=n.startsWith("=")?n.slice(1).trim():n,l=(p,x)=>{if(!p||!x)return[];const I=[];for(let y=p.row;y<=x.row;y++)for(let $=p.col;$<=x.col;$++){const M=Ze(Le(y,$),a,new Set(s));typeof M=="number"&&I.push(M)}return I},d=(p,x)=>{if(!p||!x)return[];const I=[];for(let y=p.row;y<=x.row;y++)for(let $=p.col;$<=x.col;$++)I.push(Ze(Le(y,$),a,new Set(s)));return I},u=c.match(/^(\w+)\(([A-Z]+\d+):([A-Z]+\d+)\)$/i);if(u){const p=u[1].toUpperCase(),x=it(u[2].toUpperCase()),I=it(u[3].toUpperCase());switch(p){case"SUM":return l(x,I).reduce(($,M)=>$+M,0);case"AVG":case"AVERAGE":{const y=l(x,I);return y.length>0?y.reduce(($,M)=>$+M,0)/y.length:0}case"COUNT":return l(x,I).length;case"COUNTA":return d(x,I).filter(y=>y!==null&&y!=="").length;case"COUNTBLANK":return d(x,I).filter(y=>y===null||y==="").length;case"MIN":{const y=l(x,I);return y.length?Math.min(...y):0}case"MAX":{const y=l(x,I);return y.length?Math.max(...y):0}case"MEDIAN":{const y=l(x,I).sort((M,F)=>M-F);if(!y.length)return 0;const $=Math.floor(y.length/2);return y.length%2?y[$]:(y[$-1]+y[$])/2}case"STDEV":{const y=l(x,I);if(y.length<2)return 0;const $=y.reduce((M,F)=>M+F,0)/y.length;return Math.sqrt(y.reduce((M,F)=>M+(F-$)**2,0)/(y.length-1))}case"PRODUCT":{const y=l(x,I);return y.length?y.reduce(($,M)=>$*M,1):0}}}const o=c.match(/^(SUMIF|COUNTIF)\(([A-Z]+\d+):([A-Z]+\d+)\s*,\s*"?([^"]*)"?\)$/i);if(o){const p=o[1].toUpperCase(),x=it(o[2].toUpperCase()),I=it(o[3].toUpperCase()),y=o[4];if(x&&I){let $=0;for(let M=x.row;M<=I.row;M++)for(let F=x.col;F<=I.col;F++){const H=Ze(Le(M,F),a,new Set(s));(y.startsWith(">")?Number(H)>Number(y.slice(1)):y.startsWith("<")?Number(H)<Number(y.slice(1)):String(H)===y||typeof H=="number"&&H===Number(y))&&($+=p==="SUMIF"?typeof H=="number"?H:0:1)}return $}}const _=c.match(/^IF\(([^,]+),\s*([^,]+),\s*([^)]+)\)$/i);if(_){const p=_[1].trim(),x=_[2].trim(),I=_[3].trim(),y=p.match(/^([A-Z]+\d+)\s*([><=!]+)\s*(\S+)$/i);let $=!1;if(y){const H=Ze(y[1].toUpperCase(),a,new Set(s)),xe=isNaN(Number(y[3]))?y[3].replace(/^"|"$/g,""):Number(y[3]),re=y[2],ge=typeof H=="number"?H:Number(H)||0,Ce=typeof xe=="number"?xe:Number(xe)||0;switch(re){case">":$=ge>Ce;break;case"<":$=ge<Ce;break;case">=":$=ge>=Ce;break;case"<=":$=ge<=Ce;break;case"=":case"==":$=ge===Ce;break;case"<>":case"!=":$=ge!==Ce;break}}const M=$?x:I;if(it(M.toUpperCase()))return Ze(M.toUpperCase(),a,new Set(s));const F=Number(M);return isNaN(F)?M.replace(/^"|"$/g,""):F}const f=c.match(/^CONCAT\((.+)\)$/i);if(f)return f[1].split(",").map(x=>x.trim()).map(x=>{if(x.startsWith('"')&&x.endsWith('"'))return x.slice(1,-1);if(it(x.toUpperCase())){const y=Ze(x.toUpperCase(),a,new Set(s));return y!==null?String(y):""}return x}).join("");const S=c.match(/^VLOOKUP\(([^,]+),\s*([A-Z]+\d+):([A-Z]+\d+),\s*(\d+)\)$/i);if(S){let p;it(S[1].trim().toUpperCase())?p=Ze(S[1].trim().toUpperCase(),a,new Set(s)):p=isNaN(Number(S[1]))?S[1].replace(/^"|"$/g,""):Number(S[1]);const I=it(S[2].toUpperCase()),y=it(S[3].toUpperCase()),$=parseInt(S[4])-1;if(I&&y)for(let M=I.row;M<=y.row;M++){const F=Ze(Le(M,I.col),a,new Set(s));if(String(F)===String(p))return Ze(Le(M,I.col+$),a,new Set(s))}return null}const R=c.match(/^(ABS|ROUND|FLOOR|CEIL|CEILING|SQRT|LEN|UPPER|LOWER|TRIM|INT)\(([^)]+)\)$/i);if(R){const p=R[1].toUpperCase(),x=R[2].trim();let I;switch(it(x.toUpperCase())?I=Ze(x.toUpperCase(),a,new Set(s)):I=isNaN(Number(x))?x.replace(/^"|"$/g,""):Number(x),p){case"ABS":return Math.abs(Number(I)||0);case"ROUND":return Math.round(Number(I)||0);case"FLOOR":return Math.floor(Number(I)||0);case"CEIL":case"CEILING":return Math.ceil(Number(I)||0);case"SQRT":return Math.sqrt(Number(I)||0);case"INT":return Math.trunc(Number(I)||0);case"LEN":return String(I??"").length;case"UPPER":return String(I??"").toUpperCase();case"LOWER":return String(I??"").toLowerCase();case"TRIM":return String(I??"").trim()}}const L=c.match(/^POWER\(([^,]+),\s*([^)]+)\)$/i);if(L){const p=Number(it(L[1].trim().toUpperCase())?Ze(L[1].trim().toUpperCase(),a,new Set(s)):L[1].trim())||0,x=Number(it(L[2].trim().toUpperCase())?Ze(L[2].trim().toUpperCase(),a,new Set(s)):L[2].trim())||0;return Math.pow(p,x)}if(/^NOW\(\)$/i.test(c))return new Date().toISOString();if(/^TODAY\(\)$/i.test(c))return new Date().toISOString().split("T")[0];if(/^PI\(\)$/i.test(c))return Math.PI;const z=c.match(/^([A-Z]+\d+)$/i);if(z)return Ze(z[1].toUpperCase(),a,s);const b=c.match(/^([A-Z]+\d+)\s*([+\-*/])\s*([A-Z]+\d+|\d+\.?\d*)$/i);if(b){const p=b[1].toUpperCase(),x=b[2],I=b[3],y=Ze(p,a,s),M=it(I.toUpperCase())?Ze(I.toUpperCase(),a,s):parseFloat(I),F=typeof y=="number"?y:0,H=typeof M=="number"?M:0;switch(x){case"+":return F+H;case"-":return F-H;case"*":return F*H;case"/":return H!==0?F/H:null}}const D=parseFloat(c);return isNaN(D)?c:D}function Ze(n,a,s){if(s.has(n))return null;s.add(n);const c=a[n];return c?c.formula?Pr(c.formula,a,s):c.value:null}function zi(n,a){return n==null?"":a==="percent"&&typeof n=="number"?`${(n*100).toFixed(1)}%`:a==="currency"&&typeof n=="number"?`$${n.toFixed(2)}`:String(n)}function $i(n){return{name:n,data:{}}}const Kr=Object.assign(i.forwardRef(({sheets:n,activeSheet:a,rows:s=50,cols:c=26,showToolbar:l=!0,showFormulaBar:d=!0,showSheetTabs:u=!0,readOnly:o=!1,disabled:_=!1,loading:f=!1,error:S,size:R="md",onChange:L,onActiveSheetChange:z,onCellSelect:b,onCopy:D,onPaste:p,onInsert:x,onRemove:I,maxUndo:y=50,sortable:$=!1,filterable:M=!1,rangeSelection:F=!0,className:H,style:xe,id:re,...ge},Ce)=>{const te=o||_,Me=N.useControlId(re),{t:V}=N.useNiceTranslation(),[Ge,Re]=i.useState(()=>n??[$i(V("spreadsheet.sheet","Sheet")+" 1")]),[Ae,se]=i.useState(0),P=n??Ge,G=a??Ae,k=P[G]??P[0],[v,le]=i.useState(null),[ie,j]=i.useState(null),[me,fe]=i.useState(!1),[ye,T]=i.useState(null),[ce,pe]=i.useState(""),Ke=i.useRef(null),de=i.useRef(null),[Ie,we]=i.useState([]),[Pe,Fe]=i.useState([]),[rt,st]=i.useState(null),ct=i.useRef({x:0,width:80}),[Se,W]=i.useState(null),[_e,Ne]=i.useState(null),Ee=i.useRef(null);N.useRovingFocus(Ee,{orientation:"horizontal",wrap:!0,activateOnMove:!0});const[Oe,oe]=i.useState("");i.useEffect(()=>{ye&&Ke.current&&Ke.current.focus()},[ye]);const Z=i.useMemo(()=>{if(!v)return null;const m=ie??v;return{startRow:Math.min(v.row,m.row),startCol:Math.min(v.col,m.col),endRow:Math.max(v.row,m.row),endCol:Math.max(v.col,m.col)}},[v,ie]),kt=i.useCallback((m,h)=>Z?m>=Z.startRow&&m<=Z.endRow&&h>=Z.startCol&&h<=Z.endCol:!1,[Z]),gt=i.useCallback(m=>{we(h=>{const A=[...h,m.map(q=>({...q,data:{...q.data}}))];return A.length>y?A.slice(-y):A}),Fe([])},[y]),je=i.useCallback((m,h=!0)=>{h&&gt(P);const A=m(P);n||Re(A),L?.(A)},[P,n,L,gt]),Ct=i.useCallback(()=>{if(Ie.length===0)return;const m=Ie[Ie.length-1];Fe(h=>[...h,P.map(A=>({...A,data:{...A.data}}))]),we(h=>h.slice(0,-1)),n||Re(m),L?.(m)},[Ie,P,n,L]),at=i.useCallback(()=>{if(Pe.length===0)return;const m=Pe[Pe.length-1];we(h=>[...h,P.map(A=>({...A,data:{...A.data}}))]),Fe(h=>h.slice(0,-1)),n||Re(m),L?.(m)},[Pe,P,n,L]),ot=i.useCallback(m=>{a||se(m),z?.(m),le(null),j(null),T(null)},[a,z]),wt=i.useCallback((m,h,A)=>{const q=Le(m,h);je(U=>{const O=U.map((ne,ee)=>ee===G?{...ne,data:{...ne.data}}:ne),K=A.startsWith("=");return O[G].data[q]={...O[G].data[q]??{value:null},formula:K?A:void 0,value:K?null:isNaN(Number(A))?A:Number(A)},O})},[G,je]),r=i.useCallback((m,h,A)=>{A?.shiftKey&&F&&v?j({row:m,col:h}):(le({row:m,col:h}),j(null)),T(null),b?.(G,m,h)},[G,b,F,v]),C=i.useCallback((m,h,A)=>{A.button===0&&(r(m,h,A),F&&!A.shiftKey&&fe(!0))},[r,F]),Q=i.useCallback((m,h)=>{me&&j({row:m,col:h})},[me]);i.useEffect(()=>{if(!me)return;const m=()=>fe(!1);return document.addEventListener("mouseup",m),()=>document.removeEventListener("mouseup",m)},[me]);const J=i.useCallback((m,h)=>{if(te)return;const A=Le(m,h),q=k.data[A];q?.readOnly||(T({row:m,col:h}),pe(q?.formula??(q?.value!=null?String(q.value):"")))},[te,k.data]),Te=i.useCallback(()=>{ye&&(wt(ye.row,ye.col,ce),T(null))},[ye,ce,wt]),Y=i.useCallback(m=>{if(m.key==="Enter")Te();else if(m.key==="Escape")T(null);else if(m.key==="Tab"&&ye&&(m.preventDefault(),Te(),v)){const h=m.shiftKey?Math.max(0,v.col-1):Math.min(c-1,v.col+1);le({row:v.row,col:h})}},[Te,v,c,ye]),ue=i.useCallback((m,h)=>{if(!v)return;const A=Z??{startRow:v.row,startCol:v.col,endRow:v.row,endCol:v.col};je(q=>{const U=q.map((O,K)=>K===G?{...O,data:{...O.data}}:O);for(let O=A.startRow;O<=A.endRow;O++)for(let K=A.startCol;K<=A.endCol;K++){const ne=Le(O,K);U[G].data[ne]={...U[G].data[ne]??{value:null},[m]:h}}return U})},[v,Z,G,je]),We=i.useCallback(m=>{if(!Z||D?.(Z)===!1)return;const{startRow:h,startCol:A,endRow:q,endCol:U}=Z,O=[];for(let K=h;K<=q;K++){const ne=[];for(let ee=A;ee<=U;ee++){const Be=Le(K,ee),ze=k.data[Be],qe=ze?Ze(Be,k.data,new Set):null;ne.push(zi(qe,ze?.format))}O.push(ne.join(" "))}m.clipboardData.setData("text/plain",O.join(`
8
+ `)),m.preventDefault()},[Z,k.data,D]),ut=i.useCallback(m=>{if(te||!v)return;const h=m.clipboardData.getData("text/plain");if(!h)return;const A=h.split(`
9
+ `).map(q=>q.split(" "));p?.(A,v.row,v.col)!==!1&&(je(q=>{const U=q.map((O,K)=>K===G?{...O,data:{...O.data}}:O);return A.forEach((O,K)=>{O.forEach((ne,ee)=>{const Be=Le(v.row+K,v.col+ee),ze=ne.startsWith("=");U[G].data[Be]={...U[G].data[Be]??{value:null},formula:ze?ne:void 0,value:ze?null:isNaN(Number(ne))?ne:Number(ne)}})}),U}),m.preventDefault())},[te,v,G,je,p]),Qe=i.useCallback(m=>{je(h=>h.map((q,U)=>{if(U!==G)return q;const O={};for(const[K,ne]of Object.entries(q.data)){const ee=it(K);ee&&(ee.row>m?O[Le(ee.row+1,ee.col)]=ne:O[K]=ne)}return{...q,data:O}})),x?.("row",m)},[G,je,x]),Xe=i.useCallback(m=>{je(h=>h.map((q,U)=>{if(U!==G)return q;const O={};for(const[K,ne]of Object.entries(q.data)){const ee=it(K);ee&&(ee.col>m?O[Le(ee.row,ee.col+1)]=ne:O[K]=ne)}return{...q,data:O}})),x?.("column",m)},[G,je,x]),Et=i.useCallback(m=>{je(h=>h.map((q,U)=>{if(U!==G)return q;const O={};for(const[K,ne]of Object.entries(q.data)){const ee=it(K);ee&&ee.row!==m&&(ee.row>m?O[Le(ee.row-1,ee.col)]=ne:O[K]=ne)}return{...q,data:O}})),I?.("row",m)},[G,je,I]),X=i.useCallback(m=>{je(h=>h.map((q,U)=>{if(U!==G)return q;const O={};for(const[K,ne]of Object.entries(q.data)){const ee=it(K);ee&&ee.col!==m&&(ee.col>m?O[Le(ee.row,ee.col-1)]=ne:O[K]=ne)}return{...q,data:O}})),I?.("column",m)},[G,je,I]),Lt=i.useCallback((m,h)=>{je(A=>A.map((U,O)=>{if(O!==G)return U;const K=new Map;for(const[Be,ze]of Object.entries(U.data)){const qe=it(Be);qe&&(K.has(qe.row)||K.set(qe.row,{}),K.get(qe.row)[qe.col]=ze)}const ne=Array.from(K.entries()).sort((Be,ze)=>{const qe=Ze(Le(Be[0],m),U.data,new Set),mt=Ze(Le(ze[0],m),U.data,new Set),xt=typeof qe=="number"?qe:Number(qe),tt=typeof mt=="number"?mt:Number(mt);if(!isNaN(xt)&&!isNaN(tt))return h==="asc"?xt-tt:tt-xt;const Ft=String(qe??""),Rt=String(mt??"");return h==="asc"?Ft.localeCompare(Rt):Rt.localeCompare(Ft)}),ee={};return ne.forEach(([,Be],ze)=>{for(const[qe,mt]of Object.entries(Be))ee[Le(ze,Number(qe))]=mt}),{...U,data:ee,sortColumn:m,sortDirection:h}}))},[G,je]),Nt=i.useCallback((m,h)=>{const A=k.conditionalFormats;if(!A?.length)return;const q=Le(m,h),U=Ze(q,k.data,new Set),O=typeof U=="number"?U:Number(U);for(const K of A){const ne=K.range.match(/^([A-Z]+\d+):([A-Z]+\d+)$/i);if(!ne)continue;const ee=it(ne[1].toUpperCase()),Be=it(ne[2].toUpperCase());if(!ee||!Be||m<ee.row||m>Be.row||h<ee.col||h>Be.col)continue;let ze=!1;switch(K.type){case"greaterThan":ze=!isNaN(O)&&O>Number(K.value);break;case"lessThan":ze=!isNaN(O)&&O<Number(K.value);break;case"equalTo":ze=String(U)===String(K.value);break;case"between":ze=!isNaN(O)&&O>=Number(K.value)&&O<=Number(K.value2);break;case"textContains":ze=String(U).includes(String(K.value));break;case"isEmpty":ze=U===null||U==="";break;case"isNotEmpty":ze=U!==null&&U!=="";break}if(ze)return{backgroundColor:K.style.bgColor,color:K.style.color,fontWeight:K.style.bold?"bold":void 0,fontStyle:K.style.italic?"italic":void 0}}},[k.conditionalFormats,k.data]),bt=i.useCallback(()=>{const m=`${V("spreadsheet.sheet","Sheet")} ${P.length+1}`;je(h=>[...h,$i(m)]),ot(P.length)},[P.length,je,ot,V]),Ot=i.useCallback(()=>{P.length<=1||(je(m=>m.filter((h,A)=>A!==G)),ot(Math.max(0,G-1)))},[P.length,G,je,ot]),Pt=i.useCallback((m,h)=>{h.trim()&&(je(A=>A.map((q,U)=>U===m?{...q,name:h.trim()}:q),!1),Ne(null))},[je]),Je=i.useMemo(()=>{if(!v)return"";const m=Le(v.row,v.col),h=k.data[m];return h?.formula??(h?.value!=null?String(h.value):"")},[v,k.data]),lt=i.useMemo(()=>{if(!Z)return null;const{startRow:m,startCol:h,endRow:A,endCol:q}=Z;if(m===A&&h===q)return null;const U=[];let O=0;for(let K=m;K<=A;K++)for(let ne=h;ne<=q;ne++){const ee=Le(K,ne),Be=Ze(ee,k.data,new Set);Be!==null&&Be!==""&&O++,typeof Be=="number"&&U.push(Be)}return U.length===0?{count:O}:{count:O,sum:U.reduce((K,ne)=>K+ne,0),avg:U.reduce((K,ne)=>K+ne,0)/U.length,min:Math.min(...U),max:Math.max(...U)}},[Z,k.data]),At=i.useCallback((m,h)=>{h.preventDefault(),h.stopPropagation(),st(m),ct.current={x:h.clientX,width:k.colWidths?.[m]??80}},[k.colWidths]);i.useEffect(()=>{if(rt===null)return;const m=A=>{const q=A.clientX-ct.current.x,U=Math.max(30,ct.current.width+q);je(O=>O.map((ne,ee)=>ee===G?{...ne,colWidths:{...ne.colWidths,[rt]:U}}:ne),!1)},h=()=>st(null);return document.addEventListener("mousemove",m),document.addEventListener("mouseup",h),()=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",h)}},[rt,G,je]);const Kt=i.useCallback((m,h,A)=>{m.preventDefault(),le({row:h,col:A}),W({x:m.clientX,y:m.clientY})},[]);i.useEffect(()=>{if(!Se)return;const m=()=>W(null);return document.addEventListener("click",m),()=>document.removeEventListener("click",m)},[Se]);const Ue=i.useCallback(m=>{if((m.ctrlKey||m.metaKey)&&!ye){if(m.key==="z"){m.preventDefault(),Ct();return}if(m.key==="y"){m.preventDefault(),at();return}}if(ye||!v)return;let{row:h,col:A}=v;switch(m.key){case"ArrowUp":h=Math.max(0,h-1);break;case"ArrowDown":h=Math.min(s-1,h+1);break;case"ArrowLeft":A=Math.max(0,A-1);break;case"ArrowRight":A=Math.min(c-1,A+1);break;case"Home":A=0,h=m.ctrlKey||m.metaKey?0:h;break;case"End":A=c-1,h=m.ctrlKey||m.metaKey?s-1:h;break;case"PageUp":h=Math.max(0,h-10);break;case"PageDown":h=Math.min(s-1,h+10);break;case"Enter":J(h,A);return;case"Delete":case"Backspace":te||(Z&&(Z.startRow!==Z.endRow||Z.startCol!==Z.endCol)?je(q=>{const U=q.map((O,K)=>K===G?{...O,data:{...O.data}}:O);for(let O=Z.startRow;O<=Z.endRow;O++)for(let K=Z.startCol;K<=Z.endCol;K++)delete U[G].data[Le(O,K)];return U}):wt(h,A,""));return;default:if(m.key.length===1&&!m.ctrlKey&&!m.metaKey&&!te){T({row:h,col:A}),pe(m.key);return}return}m.preventDefault(),m.shiftKey&&F?j({row:h,col:A}):(le({row:h,col:A}),j(null)),b?.(G,h,A)},[ye,v,s,c,te,J,wt,G,b,Ct,at,Z,je,F]),Ve=k.frozenRows??0,dt=k.frozenCols??0,et=[{value:"text",label:V("spreadsheet.formatText","Text")},{value:"number",label:V("spreadsheet.formatNumber","Number")},{value:"percent",label:V("spreadsheet.formatPercent","Percent")},{value:"currency",label:V("spreadsheet.formatCurrency","Currency")},{value:"date",label:V("spreadsheet.formatDate","Date")}];return e.jsxs("div",{ref:Ce,id:Me,className:`nice-spreadsheet nice-spreadsheet--${R} ${o&&!_?"nice-spreadsheet--readonly":""} ${_?"nice-spreadsheet--disabled":""} ${f?"nice-spreadsheet--loading":""} ${S?"nice-spreadsheet--error":""} ${H??""}`,style:{...xe,position:f?"relative":xe?.position},onKeyDown:Ue,onCopy:We,onPaste:ut,tabIndex:_?-1:0,role:"application","aria-label":V("spreadsheet.label","Spreadsheet"),"aria-disabled":_||void 0,"aria-busy":f||void 0,...ge,children:[S&&e.jsx("div",{className:"nice-spreadsheet__error",role:"alert",children:S}),f&&e.jsx("span",{className:"nice-spreadsheet__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),l&&!te&&e.jsxs("div",{className:"nice-spreadsheet__toolbar",role:"toolbar",children:[e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:Ct,disabled:Ie.length===0,title:V("spreadsheet.undo","Undo"),children:e.jsx(jr,{})}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:at,disabled:Pe.length===0,title:V("spreadsheet.redo","Redo"),children:e.jsx(Sr,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(He.NiceButton,{variant:k.data[v?Le(v.row,v.col):""]?.bold?"primary":"ghost",size:"sm",onClick:()=>ue("bold",!k.data[v?Le(v.row,v.col):""]?.bold),title:V("spreadsheet.bold","Bold"),children:e.jsx("strong",{children:"B"})}),e.jsx(He.NiceButton,{variant:k.data[v?Le(v.row,v.col):""]?.italic?"primary":"ghost",size:"sm",onClick:()=>ue("italic",!k.data[v?Le(v.row,v.col):""]?.italic),title:V("spreadsheet.italic","Italic"),children:e.jsx("em",{children:"I"})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>ue("align","left"),title:V("spreadsheet.alignLeft","Align left"),children:e.jsx(Cr,{})}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>ue("align","center"),title:V("spreadsheet.alignCenter","Center"),children:e.jsx(Dr,{})}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>ue("align","right"),title:V("spreadsheet.alignRight","Align right"),children:e.jsx(Mr,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Ei.NiceColorPicker,{value:k.data[v?Le(v.row,v.col):""]?.bgColor??"var(--nice-bg-primary, #ffffff)",onChange:m=>ue("bgColor",m),title:V("spreadsheet.bgColor","Background color"),showInput:!1,showRandom:!1}),e.jsx(Ei.NiceColorPicker,{value:k.data[v?Le(v.row,v.col):""]?.color??"var(--nice-text-primary, #000000)",onChange:m=>ue("color",m),title:V("spreadsheet.textColor","Text color"),showInput:!1,showRandom:!1}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Gn.NiceSelect,{size:"sm",value:k.data[v?Le(v.row,v.col):""]?.format??"text",onChange:m=>ue("format",m),options:et,"aria-label":V("spreadsheet.format","Cell format")}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>v&&Qe(v.row),title:V("spreadsheet.insertRow","Insert row"),children:e.jsx(Ir,{})}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>v&&Xe(v.col),title:V("spreadsheet.insertCol","Insert column"),children:e.jsx(Er,{})}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>v&&Et(v.row),title:V("spreadsheet.deleteRow","Delete row"),children:e.jsx(Rr,{})}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>v&&X(v.col),title:V("spreadsheet.deleteCol","Delete column"),children:e.jsx(Ar,{})})]}),d&&e.jsxs("div",{className:"nice-spreadsheet__formula-bar",children:[e.jsxs("span",{className:"nice-spreadsheet__cell-label",children:[v?Le(v.row,v.col):"",Z&&Z.startRow!==Z.endRow||Z&&Z.startCol!==Z.endCol?`:${Le(Z.endRow,Z.endCol)}`:""]}),e.jsx(Gn.NiceTextInput,{className:"nice-spreadsheet__formula-input",value:ye?ce:Je,onChange:m=>{ye?pe(m):v&&(T(v),pe(m))},onKeyDown:Y,readOnly:te,"aria-label":V("spreadsheet.formulaBar","Formula bar")})]}),e.jsx("div",{className:"nice-spreadsheet__grid",ref:de,children:e.jsxs("table",{role:"grid","aria-label":k.name,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-spreadsheet__corner"}),Array.from({length:c},(m,h)=>e.jsxs("th",{className:`nice-spreadsheet__col-header ${h<dt?"nice-spreadsheet__col-header--frozen":""}`,style:{width:k.colWidths?.[h]??80,position:h<dt?"sticky":void 0,left:h<dt?h*80+40:void 0,zIndex:h<dt?3:void 0},children:[e.jsx("span",{children:Ui(h)}),$&&e.jsx("span",{role:"button",tabIndex:0,onKeyDown:N.clickOnActivationKey,className:"nice-spreadsheet__sort-trigger",onClick:()=>Lt(h,k.sortColumn===h&&k.sortDirection==="asc"?"desc":"asc"),title:V("spreadsheet.sort","Sort"),children:k.sortColumn===h?k.sortDirection==="asc"?e.jsx(Tr,{}):e.jsx(zr,{}):e.jsx($r,{})}),!te&&e.jsx("span",{className:"nice-spreadsheet__col-resize",onMouseDown:A=>At(h,A)})]},h))]})}),e.jsx("tbody",{children:Array.from({length:s},(m,h)=>e.jsxs("tr",{className:h<Ve?"nice-spreadsheet__row--frozen":"",style:h<Ve?{position:"sticky",top:h*24,zIndex:2}:void 0,children:[e.jsx("td",{className:"nice-spreadsheet__row-header",children:h+1}),Array.from({length:c},(A,q)=>{const U=Le(h,q),O=k.data[U];if(O?.mergedInto)return null;const K=v?.row===h&&v?.col===q,ne=kt(h,q),ee=ye?.row===h&&ye?.col===q,Be=O?Ze(U,k.data,new Set):null,ze=Nt(h,q),qe=h<Ve||q<dt;return e.jsxs("td",{className:`nice-spreadsheet__cell ${K?"nice-spreadsheet__cell--selected":""} ${ne&&!K?"nice-spreadsheet__cell--in-range":""} ${O?.readOnly?"nice-spreadsheet__cell--readonly":""} ${qe?"nice-spreadsheet__cell--frozen":""}`,style:{textAlign:O?.align,fontWeight:O?.bold?"bold":void 0,fontStyle:O?.italic?"italic":void 0,backgroundColor:ze?.backgroundColor??O?.bgColor,color:ze?.color??O?.color,width:k.colWidths?.[q],height:k.rowHeights?.[h],position:qe?"sticky":void 0,left:q<dt?q*80+40:void 0,zIndex:qe?1:void 0,...ze},colSpan:O?.colSpan,rowSpan:O?.rowSpan,onMouseDown:mt=>C(h,q,mt),onMouseEnter:()=>Q(h,q),onDoubleClick:()=>J(h,q),onContextMenu:mt=>Kt(mt,h,q),role:"gridcell","aria-selected":K,title:O?.comment,children:[O?.comment&&e.jsx("span",{className:"nice-spreadsheet__comment-indicator"}),ee?e.jsx("input",{ref:Ke,className:"nice-spreadsheet__cell-editor",value:ce,onChange:mt=>pe(mt.target.value),onKeyDown:Y,onBlur:Te}):zi(Be,O?.format)]},q)})]},h))})]})}),Se&&!te&&v&&e.jsxs("div",{className:"nice-spreadsheet__context-menu",style:{position:"fixed",left:Se.x,top:Se.y,zIndex:1e3},children:[e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Qe(v.row),W(null)},children:V("spreadsheet.insertRowAbove","Insert row above")}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Qe(v.row+1),W(null)},children:V("spreadsheet.insertRowBelow","Insert row below")}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Xe(v.col),W(null)},children:V("spreadsheet.insertColLeft","Insert column left")}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Xe(v.col+1),W(null)},children:V("spreadsheet.insertColRight","Insert column right")}),e.jsx("hr",{className:"nice-spreadsheet__context-sep"}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Et(v.row),W(null)},children:V("spreadsheet.deleteRow","Delete row")}),e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{X(v.col),W(null)},children:V("spreadsheet.deleteCol","Delete column")})]}),lt&&e.jsxs("div",{className:"nice-spreadsheet__status-bar",children:[e.jsxs("span",{children:[V("spreadsheet.count","Count"),": ",lt.count]}),lt.sum!==void 0&&e.jsxs("span",{children:[V("spreadsheet.sum","Sum"),": ",lt.sum.toFixed(2)]}),lt.avg!==void 0&&e.jsxs("span",{children:[V("spreadsheet.avg","Avg"),": ",lt.avg.toFixed(2)]}),lt.min!==void 0&&e.jsxs("span",{children:[V("spreadsheet.min","Min"),": ",lt.min]}),lt.max!==void 0&&e.jsxs("span",{children:[V("spreadsheet.max","Max"),": ",lt.max]})]}),u&&e.jsxs("div",{className:"nice-spreadsheet__tabs",role:"tablist",ref:Ee,children:[P.map((m,h)=>e.jsx("span",{className:"nice-spreadsheet__tab-wrapper",children:_e===h?e.jsx(Gn.NiceTextInput,{className:"nice-spreadsheet__tab-rename",value:Oe,onChange:A=>oe(A),onBlur:()=>Pt(h,Oe),onKeyDown:A=>{A.key==="Enter"&&Pt(h,Oe),A.key==="Escape"&&Ne(null)},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>{te||(Ne(h),oe(m.name))},children:e.jsx(He.NiceButton,{variant:h===G?"primary":"ghost",size:"sm",role:"tab","aria-selected":h===G,onClick:()=>ot(h),onKeyDown:A=>{A.key==="F2"&&!te&&(A.preventDefault(),Ne(h),oe(m.name))},children:m.name})})},h)),!te&&e.jsxs(e.Fragment,{children:[e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:bt,title:V("spreadsheet.addSheet","Add sheet"),children:e.jsx(Lr,{})}),P.length>1&&e.jsx(He.NiceButton,{variant:"ghost",size:"sm",onClick:Ot,title:V("spreadsheet.removeSheet","Remove sheet"),children:e.jsx(Or,{})})]})]})]})}),{displayName:"NiceSpreadsheet"}),Fr=`
10
+ .nice-reconciliation {
11
+ display: flex;
12
+ flex-direction: column;
13
+ height: 100%;
14
+ background: var(--nice-bg-primary, #ffffff);
15
+ border: 1px solid var(--nice-border-color, #e5e7eb);
16
+ border-radius: var(--nice-radius-lg, 0.5rem);
17
+ overflow: hidden;
18
+ }
19
+
20
+ .nice-reconciliation__toolbar {
21
+ display: flex;
22
+ align-items: center;
23
+ gap: 0.75rem;
24
+ padding: 0.75rem 1rem;
25
+ background: var(--nice-bg-secondary, #f9fafb);
26
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
27
+ flex-wrap: wrap;
28
+ }
29
+
30
+ .nice-reconciliation__toolbar-group {
31
+ display: flex;
32
+ align-items: center;
33
+ gap: 0.5rem;
34
+ }
35
+
36
+ .nice-reconciliation__toolbar-group--end {
37
+ margin-inline-start: auto;
38
+ }
39
+
40
+ .nice-reconciliation__btn {
41
+ display: inline-flex;
42
+ align-items: center;
43
+ gap: 0.375rem;
44
+ padding: 0.375rem 0.75rem;
45
+ font-size: 0.8125rem;
46
+ font-weight: 500;
47
+ border-radius: var(--nice-radius-md, 0.375rem);
48
+ cursor: pointer;
49
+ transition: all 0.15s ease;
50
+ border: 1px solid var(--nice-border-color, #d1d5db);
51
+ background: var(--nice-bg-primary, #ffffff);
52
+ color: var(--nice-text-primary);
53
+ }
54
+
55
+ .nice-reconciliation__btn:hover {
56
+ background: var(--nice-bg-hover, #f3f4f6);
57
+ }
58
+
59
+ .nice-reconciliation__btn--primary {
60
+ background: var(--nice-primary, #3b82f6);
61
+ border-color: var(--nice-primary, #3b82f6);
62
+ color: white;
63
+ }
64
+
65
+ .nice-reconciliation__btn--primary:hover {
66
+ background: var(--nice-primary-dark, #2563eb);
67
+ }
68
+
69
+ .nice-reconciliation__btn--success {
70
+ background: var(--nice-success, #10b981);
71
+ border-color: var(--nice-success, #10b981);
72
+ color: white;
73
+ }
74
+
75
+ .nice-reconciliation__btn:disabled {
76
+ opacity: 0.5;
77
+ cursor: not-allowed;
78
+ }
79
+
80
+ .nice-reconciliation__content {
81
+ display: flex;
82
+ flex: 1;
83
+ overflow: hidden;
84
+ }
85
+
86
+ .nice-reconciliation--vertical .nice-reconciliation__content {
87
+ flex-direction: column;
88
+ }
89
+
90
+ .nice-reconciliation__panel {
91
+ flex: 1;
92
+ display: flex;
93
+ flex-direction: column;
94
+ min-width: 0;
95
+ min-height: 0;
96
+ overflow: hidden;
97
+ }
98
+
99
+ .nice-reconciliation__panel--statements {
100
+ border-inline-end: 1px solid var(--nice-border-color, #e5e7eb);
101
+ }
102
+
103
+ .nice-reconciliation--vertical .nice-reconciliation__panel--statements {
104
+ border-inline-end: none;
105
+ border-block-end: 1px solid var(--nice-border-color, #e5e7eb);
106
+ }
107
+
108
+ .nice-reconciliation__panel-header {
109
+ display: flex;
110
+ align-items: center;
111
+ justify-content: space-between;
112
+ padding: 0.75rem 1rem;
113
+ background: var(--nice-bg-secondary, #f9fafb);
114
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
115
+ }
116
+
117
+ .nice-reconciliation__panel-title {
118
+ font-weight: 600;
119
+ font-size: 0.875rem;
120
+ color: var(--nice-text-primary);
121
+ display: flex;
122
+ align-items: center;
123
+ gap: 0.5rem;
124
+ }
125
+
126
+ .nice-reconciliation__panel-badge {
127
+ font-size: 0.75rem;
128
+ font-weight: 500;
129
+ padding: 0.125rem 0.5rem;
130
+ border-radius: var(--nice-radius-full, 9999px);
131
+ background: var(--nice-bg-tertiary, #e5e7eb);
132
+ color: var(--nice-text-secondary);
133
+ }
134
+
135
+ .nice-reconciliation__panel-content {
136
+ flex: 1;
137
+ overflow: auto;
138
+ }
139
+
140
+ .nice-reconciliation__row {
141
+ display: flex;
142
+ align-items: center;
143
+ gap: 0.75rem;
144
+ padding: 0.625rem 1rem;
145
+ border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
146
+ cursor: pointer;
147
+ user-select: none;
148
+ transition: background 0.1s ease;
149
+ }
150
+
151
+ .nice-reconciliation__row:hover {
152
+ background: var(--nice-bg-hover, rgba(0, 0, 0, 0.02));
153
+ }
154
+
155
+ .nice-reconciliation__row--selected {
156
+ background: var(--nice-primary-light, rgba(59, 130, 246, 0.1));
157
+ }
158
+
159
+ .nice-reconciliation__row--dragging {
160
+ opacity: 0.6;
161
+ background: var(--nice-primary-light, rgba(59, 130, 246, 0.15));
162
+ }
163
+
164
+ .nice-reconciliation__row--drop-target {
165
+ background: var(--nice-success-bg, rgba(16, 185, 129, 0.15));
166
+ box-shadow: inset 0 0 0 2px var(--nice-success, #10b981);
167
+ }
168
+
169
+ .nice-reconciliation__row--matched {
170
+ background: var(--nice-success-bg, rgba(16, 185, 129, 0.08));
171
+ }
172
+
173
+ .nice-reconciliation__row--partial {
174
+ background: var(--nice-warning-bg, rgba(245, 158, 11, 0.08));
175
+ }
176
+
177
+ .nice-reconciliation__row--unmatched {
178
+ background: transparent;
179
+ }
180
+
181
+ .nice-reconciliation__row--excluded {
182
+ opacity: 0.5;
183
+ background: var(--nice-bg-tertiary, #f3f4f6);
184
+ }
185
+
186
+ .nice-reconciliation__status {
187
+ width: 0.5rem;
188
+ height: 0.5rem;
189
+ border-radius: var(--nice-radius-full, 50%);
190
+ flex-shrink: 0;
191
+ }
192
+
193
+ .nice-reconciliation__status--matched {
194
+ background: var(--nice-success, #10b981);
195
+ }
196
+
197
+ .nice-reconciliation__status--partial {
198
+ background: var(--nice-warning, #f59e0b);
199
+ }
200
+
201
+ .nice-reconciliation__status--unmatched {
202
+ background: var(--nice-danger, #ef4444);
203
+ }
204
+
205
+ .nice-reconciliation__status--excluded {
206
+ background: var(--nice-text-disabled, #9ca3af);
207
+ }
208
+
209
+ .nice-reconciliation__row-main {
210
+ flex: 1;
211
+ min-width: 0;
212
+ }
213
+
214
+ .nice-reconciliation__row-date {
215
+ font-size: 0.75rem;
216
+ color: var(--nice-text-secondary);
217
+ margin-bottom: 0.125rem;
218
+ }
219
+
220
+ .nice-reconciliation__row-description {
221
+ font-size: 0.8125rem;
222
+ color: var(--nice-text-primary);
223
+ white-space: nowrap;
224
+ overflow: hidden;
225
+ text-overflow: ellipsis;
226
+ }
227
+
228
+ .nice-reconciliation__row-counterparty {
229
+ font-size: 0.75rem;
230
+ color: var(--nice-text-tertiary);
231
+ white-space: nowrap;
232
+ overflow: hidden;
233
+ text-overflow: ellipsis;
234
+ }
235
+
236
+ .nice-reconciliation__row-amount {
237
+ font-size: 0.875rem;
238
+ font-weight: 600;
239
+ font-variant-numeric: tabular-nums;
240
+ white-space: nowrap;
241
+ }
242
+
243
+ .nice-reconciliation__row-amount--positive {
244
+ color: var(--nice-success, #10b981);
245
+ }
246
+
247
+ .nice-reconciliation__row-amount--negative {
248
+ color: var(--nice-danger, #ef4444);
249
+ }
250
+
251
+ .nice-reconciliation__confidence {
252
+ display: flex;
253
+ align-items: center;
254
+ gap: 0.25rem;
255
+ font-size: 0.6875rem;
256
+ padding: 0.125rem 0.375rem;
257
+ border-radius: var(--nice-radius-sm, 0.25rem);
258
+ }
259
+
260
+ .nice-reconciliation__confidence--high {
261
+ background: var(--nice-success-bg, rgba(16, 185, 129, 0.15));
262
+ color: var(--nice-success-dark, #059669);
263
+ }
264
+
265
+ .nice-reconciliation__confidence--medium {
266
+ background: var(--nice-warning-bg, rgba(245, 158, 11, 0.15));
267
+ color: var(--nice-warning-dark, #d97706);
268
+ }
269
+
270
+ .nice-reconciliation__confidence--low {
271
+ background: var(--nice-danger-bg, rgba(239, 68, 68, 0.15));
272
+ color: var(--nice-danger-dark, #dc2626);
273
+ }
274
+
275
+ .nice-reconciliation__empty {
276
+ display: flex;
277
+ flex-direction: column;
278
+ align-items: center;
279
+ justify-content: center;
280
+ padding: 3rem 1rem;
281
+ color: var(--nice-text-secondary);
282
+ text-align: center;
283
+ }
284
+
285
+ .nice-reconciliation__empty-icon {
286
+ font-size: 2.5rem;
287
+ margin-bottom: 0.75rem;
288
+ opacity: 0.5;
289
+ }
290
+
291
+ .nice-reconciliation__summary {
292
+ display: flex;
293
+ align-items: center;
294
+ gap: 1.5rem;
295
+ padding: 0.75rem 1rem;
296
+ background: var(--nice-bg-secondary, #f9fafb);
297
+ border-top: 1px solid var(--nice-border-color, #e5e7eb);
298
+ font-size: 0.8125rem;
299
+ flex-wrap: wrap;
300
+ }
301
+
302
+ .nice-reconciliation__summary-item {
303
+ display: flex;
304
+ align-items: center;
305
+ gap: 0.375rem;
306
+ }
307
+
308
+ .nice-reconciliation__summary-label {
309
+ color: var(--nice-text-secondary);
310
+ }
311
+
312
+ .nice-reconciliation__summary-value {
313
+ font-weight: 600;
314
+ color: var(--nice-text-primary);
315
+ font-variant-numeric: tabular-nums;
316
+ }
317
+
318
+ .nice-reconciliation__summary-value--success {
319
+ color: var(--nice-success, #10b981);
320
+ }
321
+
322
+ .nice-reconciliation__summary-value--warning {
323
+ color: var(--nice-warning, #f59e0b);
324
+ }
325
+
326
+ .nice-reconciliation__summary-value--danger {
327
+ color: var(--nice-danger, #ef4444);
328
+ }
329
+
330
+ .nice-reconciliation__resizer {
331
+ width: 4px;
332
+ background: var(--nice-border-color, #e5e7eb);
333
+ cursor: col-resize;
334
+ transition: background 0.15s ease;
335
+ }
336
+
337
+ .nice-reconciliation__resizer:hover {
338
+ background: var(--nice-primary, #3b82f6);
339
+ }
340
+
341
+ .nice-reconciliation--vertical .nice-reconciliation__resizer {
342
+ width: 100%;
343
+ height: 4px;
344
+ cursor: row-resize;
345
+ }
346
+
347
+ .nice-reconciliation__suggestions {
348
+ padding: 0.75rem 1rem;
349
+ background: var(--nice-info-bg, rgba(59, 130, 246, 0.08));
350
+ border-bottom: 1px solid var(--nice-info, #3b82f6);
351
+ }
352
+
353
+ .nice-reconciliation__suggestion {
354
+ display: flex;
355
+ align-items: center;
356
+ gap: 0.75rem;
357
+ padding: 0.5rem;
358
+ background: var(--nice-bg-primary, #ffffff);
359
+ border-radius: var(--nice-radius-md, 0.375rem);
360
+ margin-bottom: 0.5rem;
361
+ }
362
+
363
+ .nice-reconciliation__suggestion:last-child {
364
+ margin-bottom: 0;
365
+ }
366
+
367
+ /* Dark mode */
368
+ .dark .nice-reconciliation {
369
+ background: var(--nice-bg-primary-dark, #111827);
370
+ border-color: var(--nice-border-color-dark, #374151);
371
+ }
372
+
373
+ .dark .nice-reconciliation__toolbar,
374
+ .dark .nice-reconciliation__panel-header,
375
+ .dark .nice-reconciliation__summary {
376
+ background: var(--nice-bg-secondary-dark, #1f2937);
377
+ border-color: var(--nice-border-color-dark, #374151);
378
+ }
379
+
380
+ .dark .nice-reconciliation__row--selected {
381
+ background: var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2));
382
+ }
383
+
384
+ /* RTL support */
385
+ [dir="rtl"] .nice-reconciliation__row-amount {
386
+ direction: ltr;
387
+ text-align: left;
388
+ }
389
+
390
+ /* Detail Panel */
391
+ .nice-reconciliation__detail-panel {
392
+ position: fixed;
393
+ inset-inline-end: 0;
394
+ top: 0;
395
+ bottom: 0;
396
+ width: 420px;
397
+ max-width: 90vw;
398
+ background: var(--nice-bg-primary, #ffffff);
399
+ box-shadow: -4px 0 24px var(--nice-overlay-15, rgba(0, 0, 0, 0.15));
400
+ z-index: 1000;
401
+ display: flex;
402
+ flex-direction: column;
403
+ transform: translateX(100%);
404
+ transition: transform 0.25s ease-out;
405
+ }
406
+
407
+ .nice-reconciliation__detail-panel--open {
408
+ transform: translateX(0);
409
+ }
410
+
411
+ .nice-reconciliation__detail-header {
412
+ display: flex;
413
+ align-items: center;
414
+ justify-content: space-between;
415
+ padding: 1rem;
416
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
417
+ background: var(--nice-bg-secondary, #f9fafb);
418
+ }
419
+
420
+ .nice-reconciliation__detail-title {
421
+ font-weight: 600;
422
+ font-size: 1rem;
423
+ color: var(--nice-text-primary);
424
+ display: flex;
425
+ align-items: center;
426
+ gap: 0.5rem;
427
+ }
428
+
429
+ .nice-reconciliation__detail-close {
430
+ width: 2rem;
431
+ height: 2rem;
432
+ display: flex;
433
+ align-items: center;
434
+ justify-content: center;
435
+ background: transparent;
436
+ border: none;
437
+ cursor: pointer;
438
+ font-size: 1.25rem;
439
+ color: var(--nice-text-secondary);
440
+ border-radius: var(--nice-radius-md, 0.375rem);
441
+ transition: all 0.15s ease;
442
+ }
443
+
444
+ .nice-reconciliation__detail-close:hover {
445
+ background: var(--nice-bg-hover, #f3f4f6);
446
+ color: var(--nice-text-primary);
447
+ }
448
+
449
+ .nice-reconciliation__detail-content {
450
+ flex: 1;
451
+ overflow: auto;
452
+ padding: 1rem;
453
+ }
454
+
455
+ .nice-reconciliation__detail-section {
456
+ margin-bottom: 1.5rem;
457
+ }
458
+
459
+ .nice-reconciliation__detail-section-title {
460
+ font-weight: 600;
461
+ font-size: 0.875rem;
462
+ color: var(--nice-text-primary);
463
+ margin-bottom: 0.75rem;
464
+ display: flex;
465
+ align-items: center;
466
+ gap: 0.375rem;
467
+ }
468
+
469
+ .nice-reconciliation__detail-row {
470
+ display: flex;
471
+ justify-content: space-between;
472
+ align-items: flex-start;
473
+ padding: 0.5rem 0;
474
+ border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
475
+ }
476
+
477
+ .nice-reconciliation__detail-row:last-child {
478
+ border-bottom: none;
479
+ }
480
+
481
+ .nice-reconciliation__detail-label {
482
+ font-size: 0.8125rem;
483
+ color: var(--nice-text-secondary);
484
+ }
485
+
486
+ .nice-reconciliation__detail-value {
487
+ font-size: 0.8125rem;
488
+ font-weight: 500;
489
+ color: var(--nice-text-primary);
490
+ text-align: end;
491
+ max-width: 60%;
492
+ word-break: break-word;
493
+ }
494
+
495
+ .nice-reconciliation__detail-divider {
496
+ height: 1px;
497
+ background: var(--nice-border-color, #e5e7eb);
498
+ margin: 1rem 0;
499
+ }
500
+
501
+ .nice-reconciliation__detail-match-info {
502
+ padding: 0.75rem;
503
+ background: var(--nice-success-bg, rgba(16, 185, 129, 0.08));
504
+ border-radius: var(--nice-radius-md, 0.375rem);
505
+ margin-bottom: 1rem;
506
+ }
507
+
508
+ .nice-reconciliation__detail-match-header {
509
+ display: flex;
510
+ align-items: center;
511
+ gap: 0.5rem;
512
+ font-weight: 600;
513
+ font-size: 0.8125rem;
514
+ color: var(--nice-success-dark, #059669);
515
+ margin-bottom: 0.5rem;
516
+ }
517
+
518
+ .nice-reconciliation__detail-match-detail {
519
+ font-size: 0.75rem;
520
+ color: var(--nice-text-secondary);
521
+ }
522
+
523
+ .nice-reconciliation__detail-side-by-side {
524
+ display: grid;
525
+ grid-template-columns: 1fr 1fr;
526
+ gap: 1rem;
527
+ padding: 0.75rem;
528
+ background: var(--nice-bg-secondary, #f9fafb);
529
+ border-radius: var(--nice-radius-md, 0.375rem);
530
+ margin-top: 0.75rem;
531
+ }
532
+
533
+ .nice-reconciliation__detail-side-item {
534
+ padding: 0.5rem;
535
+ background: var(--nice-bg-primary, #ffffff);
536
+ border-radius: var(--nice-radius-sm, 0.25rem);
537
+ border: 1px solid var(--nice-border-color, #e5e7eb);
538
+ }
539
+
540
+ .nice-reconciliation__detail-side-label {
541
+ font-size: 0.6875rem;
542
+ font-weight: 500;
543
+ text-transform: uppercase;
544
+ color: var(--nice-text-tertiary);
545
+ margin-bottom: 0.375rem;
546
+ }
547
+
548
+ .nice-reconciliation__detail-side-amount {
549
+ font-size: 1.125rem;
550
+ font-weight: 600;
551
+ font-variant-numeric: tabular-nums;
552
+ }
553
+
554
+ .nice-reconciliation__detail-backdrop {
555
+ position: fixed;
556
+ inset: 0;
557
+ background: var(--nice-overlay-30, rgba(0, 0, 0, 0.3));
558
+ z-index: 999;
559
+ opacity: 0;
560
+ pointer-events: none;
561
+ transition: opacity 0.2s ease;
562
+ }
563
+
564
+ .nice-reconciliation__detail-backdrop--visible {
565
+ opacity: 1;
566
+ pointer-events: auto;
567
+ }
568
+
569
+ .dark .nice-reconciliation__detail-panel {
570
+ background: var(--nice-bg-primary-dark, #111827);
571
+ box-shadow: -4px 0 24px var(--nice-overlay-40, rgba(0, 0, 0, 0.4));
572
+ }
573
+
574
+ .dark .nice-reconciliation__detail-header {
575
+ background: var(--nice-bg-secondary-dark, #1f2937);
576
+ border-color: var(--nice-border-color-dark, #374151);
577
+ }
578
+
579
+ .dark .nice-reconciliation__detail-side-by-side {
580
+ background: var(--nice-bg-secondary-dark, #1f2937);
581
+ }
582
+
583
+ .dark .nice-reconciliation__detail-side-item {
584
+ background: var(--nice-bg-primary-dark, #111827);
585
+ border-color: var(--nice-border-color-dark, #374151);
586
+ }
587
+ `;function Mt(n,a="PLN",s="pl-PL"){return new Intl.NumberFormat(s,{style:"currency",currency:a,minimumFractionDigits:2,maximumFractionDigits:2}).format(n)}function kn(n,a="pl-PL"){return n?(typeof n=="string"?new Date(n):n).toLocaleDateString(a,{year:"numeric",month:"2-digit",day:"2-digit"}):"-"}function Vr(n){return n>=80?"high":n>=50?"medium":"low"}function Br(){return`match-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function Li(n){n?.querySelector('[role="option"][tabindex="0"]')?.focus()}function Gi(n,a,s){n.target===n.currentTarget&&(n.key===" "||n.key==="Enter"&&!s?(n.preventDefault(),a()):n.key==="Enter"&&s&&(n.preventDefault(),s()))}function Ur({item:n,isSelected:a,isDragging:s,isDropTarget:c,suggestion:l,currency:d,locale:u,onSelect:o,onDoubleClick:_,onDragStart:f,onDragEnd:S,onDrop:R,disabled:L}){const z=n.status??"unmatched",b=l?.confidence??n.confidence,D=x=>{x.dataTransfer.setData("text/plain",n.id),x.dataTransfer.setData("source","statement"),x.dataTransfer.effectAllowed="move",f()},p=x=>{x.dataTransfer.types.includes("source")&&x.dataTransfer.getData("source")!=="statement"&&x.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${z} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${c?"nice-reconciliation__row--drop-target":""}`,draggable:!L&&z!=="matched",onDragStart:D,onDragEnd:S,onDragOver:p,onDrop:R,onClick:o,onDoubleClick:_,onKeyDown:x=>Gi(x,o,_),role:"option","aria-selected":a,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${z}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsx("div",{className:"nice-reconciliation__row-date",children:kn(n.date,u)}),e.jsx("div",{className:"nice-reconciliation__row-description",title:n.description,children:n.description}),n.counterparty&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:n.counterparty})]}),b!=null&&e.jsxs("span",{className:`nice-reconciliation__confidence nice-reconciliation__confidence--${Vr(b)}`,children:[b,"%"]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${n.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Mt(n.amount,d,u)})]})}function Gr({item:n,isSelected:a,isDragging:s,isDropTarget:c,currency:l,locale:d,onSelect:u,onDoubleClick:o,onDragStart:_,onDragEnd:f,onDrop:S,disabled:R}){const L=n.status??"unmatched",z=D=>{D.dataTransfer.setData("text/plain",n.id),D.dataTransfer.setData("source","entry"),D.dataTransfer.effectAllowed="move",_()},b=D=>{D.dataTransfer.types.includes("source")&&D.dataTransfer.getData("source")!=="entry"&&D.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${L} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${c?"nice-reconciliation__row--drop-target":""}`,draggable:!R&&L!=="matched",onDragStart:z,onDragEnd:f,onDragOver:b,onDrop:S,onClick:u,onDoubleClick:o,onKeyDown:D=>Gi(D,u,o),role:"option","aria-selected":a,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${L}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsxs("div",{className:"nice-reconciliation__row-date",children:[kn(n.date,d),n.documentNumber&&e.jsxs("span",{children:[" · ",n.documentNumber]})]}),e.jsx("div",{className:"nice-reconciliation__row-description",title:n.description,children:n.description}),n.partyName&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:n.partyName})]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${n.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Mt(n.amount,l,d)})]})}const Wr=i.forwardRef(function(a,s){const{t:c}=N.useNiceTranslation(),{statements:l,bankTransactions:d,entries:u,accountingEntries:o,matches:_,defaultMatches:f=[],suggestions:S=[],config:R={},currency:L,showConfidence:z,statementPanelConfig:b,entryPanelConfig:D,onMatch:p,onAutoMatch:x,onUnmatch:I,onBatchAction:y,onFilterChange:$,onRequestSuggestions:M,onSelectionChange:F,onComplete:H,size:xe="medium",showToolbar:re=!0,showFilters:ge=!0,showSummary:Ce=!0,showSuggestions:te=!0,layout:Me="horizontal",enableDragDrop:V=!0,enableKeyboard:Ge=!0,enableDetailPanel:Re=!0,loading:Ae=!1,disabled:se=!1,readOnly:P=!1,locale:G="pl-PL",labels:k={},className:v,style:le}=a,ie=i.useMemo(()=>l??d??[],[l,d]),j=i.useMemo(()=>u??o??[],[u,o]),me=L??R.currency??"PLN",[fe,ye]=i.useState(f),[T,ce]=i.useState(new Set),[pe,Ke]=i.useState(new Set),[de,Ie]=i.useState(null),[we,Pe]=i.useState(null),[Fe,rt]=i.useState({}),[st,ct]=i.useState(null),Se=_??fe,W=i.useRef(null),_e=i.useRef(null),Ne={orientation:"vertical",pageSize:10};N.useRovingFocus(W,Ne),N.useRovingFocus(_e,Ne),i.useEffect(()=>{const r="nice-reconciliation-styles";if(!document.getElementById(r)){const C=document.createElement("style");C.id=r,C.textContent=Fr,document.head.appendChild(C)}},[]);const Ee=i.useMemo(()=>{const r=new Set;return Se.forEach(C=>C.statementIds.forEach(Q=>r.add(Q))),r},[Se]),Oe=i.useMemo(()=>{const r=new Set;return Se.forEach(C=>C.entryIds.forEach(Q=>r.add(Q))),r},[Se]),oe=i.useMemo(()=>{const r=ie.filter(Y=>!Ee.has(Y.id)),C=j.filter(Y=>!Oe.has(Y.id)),Q=ie.reduce((Y,ue)=>Y+ue.amount,0),J=j.reduce((Y,ue)=>Y+ue.amount,0),Te=ie.filter(Y=>Ee.has(Y.id)).reduce((Y,ue)=>Y+ue.amount,0);return{totalStatements:ie.length,totalEntries:j.length,matchedStatements:ie.length-r.length,matchedEntries:j.length-C.length,unmatchedStatements:r.length,unmatchedEntries:C.length,statementTotal:Q,entryTotal:J,matchedAmount:Te,unmatchedStatementAmount:r.reduce((Y,ue)=>Y+ue.amount,0),unmatchedEntryAmount:C.reduce((Y,ue)=>Y+ue.amount,0),difference:Q-J,matchPercentage:ie.length>0?Math.round((ie.length-r.length)/ie.length*100):0,matchCount:Se.length,partialMatchCount:Se.filter(Y=>Y.status==="partial").length,pendingSuggestions:S.length}},[ie,j,Se,S,Ee,Oe]),Z=i.useCallback((r,C)=>{const Q=ie.filter(Qe=>r.includes(Qe.id)),J=j.filter(Qe=>C.includes(Qe.id));if(Q.length===0||J.length===0)return null;const Te=Q.reduce((Qe,Xe)=>Qe+Xe.amount,0),Y=J.reduce((Qe,Xe)=>Qe+Xe.amount,0),ue=Math.abs(Te-Y),We=R.amountTolerance??.01,ut={id:Br(),statementIds:r,entryIds:C,status:ue<=We?"matched":"partial",statementTotal:Te,entryTotal:Y,difference:ue,confidence:ue<=We?100:Math.max(0,100-ue/Math.max(Math.abs(Te),1)*100),matchedBy:"user",matchedAt:new Date};return _||ye(Qe=>[...Qe,ut]),p?.(ut,Q,J),ce(new Set),Ke(new Set),ut},[ie,j,R.amountTolerance,_,p]),kt=i.useCallback(r=>{const C=Se.find(Q=>Q.id===r);C&&(_||ye(Q=>Q.filter(J=>J.id!==r)),I?.(r,C.statementIds,C.entryIds))},[Se,_,I]),gt=i.useCallback(async()=>{const r=[],C=new Set(Ee),Q=new Set(Oe),J=R.amountTolerance??.01,Te=R.dateTolerance??3;for(const Y of ie){if(C.has(Y.id))continue;const ue=j.filter(We=>{if(Q.has(We.id)||Math.abs(Y.amount-We.amount)>J)return!1;const Qe=new Date(Y.date),Xe=new Date(We.date);return!(Math.abs(Qe.getTime()-Xe.getTime())/(1e3*60*60*24)>Te)});if(ue.length===1){const We=ue[0],ut=Z([Y.id],[We.id]);ut&&(r.push(ut),C.add(Y.id),Q.add(We.id))}}return y?.("autoMatch",r),r},[ie,j,Ee,Oe,R,Z,y]),je=i.useCallback((r,C,Q,J)=>{J!==C&&(J==="statement"?Z([Q],[r]):Z([r],[Q]),Ie(null),Pe(null))},[Z]),Ct=i.useCallback(()=>{const r=Array.from(T),C=Array.from(pe);r.length>0&&C.length>0&&Z(r,C)},[T,pe,Z]);i.useEffect(()=>{F?.(Array.from(T),Array.from(pe))},[T,pe,F]),i.useImperativeHandle(s,()=>({getMatches:()=>Se,getUnmatchedStatements:()=>ie.filter(r=>!Ee.has(r.id)),getUnmatchedEntries:()=>j.filter(r=>!Oe.has(r.id)),createMatch:Z,removeMatch:kt,autoMatch:gt,getSuggestions:async r=>M?M(r??ie.filter(C=>!Ee.has(C.id)).map(C=>C.id)):[],applySuggestion:r=>Z([r.statementId],r.entryIds),approveAll:()=>{y?.("approveAll",Se)},clearAll:()=>{_||ye([]),y?.("clearAll",[])},exportMatched:r=>{y?.("exportMatched",Se)},getSummary:()=>oe,reset:()=>{_||ye([]),ce(new Set),Ke(new Set),rt({})},focusStatements:()=>Li(W.current),focusEntries:()=>Li(_e.current)}),[Se,ie,j,Ee,Oe,Z,kt,gt,M,y,_,oe]);const at=i.useMemo(()=>ie.filter(r=>{if(Fe.status&&Fe.status.length>0){const C=Ee.has(r.id)?"matched":"unmatched";if(!Fe.status.includes(C))return!1}if(Fe.searchText){const C=Fe.searchText.toLowerCase();if(!r.description?.toLowerCase().includes(C)&&!r.counterparty?.toLowerCase().includes(C))return!1}return!0}),[ie,Fe,Ee]),ot=i.useMemo(()=>j.filter(r=>{if(Fe.status&&Fe.status.length>0){const C=Oe.has(r.id)?"matched":"unmatched";if(!Fe.status.includes(C))return!1}if(Fe.searchText){const C=Fe.searchText.toLowerCase();if(!r.description?.toLowerCase().includes(C)&&!r.partyName?.toLowerCase().includes(C))return!1}return!0}),[j,Fe,Oe]),wt=T.size>0&&pe.size>0&&!P&&!se;return e.jsxs("div",{className:`nice-reconciliation nice-reconciliation--${Me} ${v??""}`,style:le,children:[re&&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:gt,disabled:se||P||Ae,children:[e.jsx(N.NiceIcon,{name:"zap",size:14})," ",k.autoMatch??c("reconciliationView.autoMatch","Auto-match")]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--success",onClick:Ct,disabled:!wt||Ae,children:[e.jsx(N.NiceIcon,{name:"link",size:14})," ",c("reconciliationView.matchSelected","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:()=>y?.("approveAll",Se),disabled:Se.length===0||se||Ae,children:[e.jsx(N.NiceIcon,{name:"check",size:14})," ",k.approveAll??c("reconciliationView.approveAll","Approve All")]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>{_||ye([]),y?.("clearAll",[])},disabled:Se.length===0||se||P||Ae,children:[e.jsx(N.NiceIcon,{name:"close",size:14})," ",k.clearAll??c("reconciliationView.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:[e.jsx(N.NiceIcon,{name:"file",size:14})," ",k.statementPanelTitle??c("reconciliationView.bankStatement","Bank Statement"),e.jsx("span",{className:"nice-reconciliation__panel-badge",children:at.length})]})}),e.jsx("div",{ref:W,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:at.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:e.jsx(N.NiceIcon,{name:"clipboard",size:32})}),k.noStatements??c("reconciliationView.noStatementItems","No statement items")]}):at.map(r=>e.jsx(Ur,{item:{...r,status:Ee.has(r.id)?"matched":"unmatched"},isSelected:T.has(r.id),isDragging:de===r.id,isDropTarget:we===r.id,suggestion:S.find(C=>C.statementId===r.id),currency:me,locale:G,onSelect:()=>{se||ce(C=>{const Q=new Set(C);return Q.has(r.id)?Q.delete(r.id):Q.add(r.id),Q})},onDoubleClick:Re?()=>ct({type:"statement",id:r.id}):void 0,onDragStart:()=>Ie(r.id),onDragEnd:()=>{Ie(null),Pe(null)},onDrop:()=>{de&&de!==r.id&&je(r.id,"statement",de,"entry")},disabled:se||P||!V},r.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:[e.jsx(N.NiceIcon,{name:"book",size:14})," ",k.entryPanelTitle??c("reconciliationView.bookEntries","Book Entries"),e.jsx("span",{className:"nice-reconciliation__panel-badge",children:ot.length})]})}),e.jsx("div",{ref:_e,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:ot.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:e.jsx(N.NiceIcon,{name:"book",size:32})}),k.noEntries??c("reconciliationView.noBookEntries","No book entries")]}):ot.map(r=>e.jsx(Gr,{item:{...r,status:Oe.has(r.id)?"matched":"unmatched"},isSelected:pe.has(r.id),isDragging:de===r.id,isDropTarget:we===r.id,currency:me,locale:G,onSelect:()=>{se||Ke(C=>{const Q=new Set(C);return Q.has(r.id)?Q.delete(r.id):Q.add(r.id),Q})},onDoubleClick:Re?()=>ct({type:"entry",id:r.id}):void 0,onDragStart:()=>Ie(r.id),onDragEnd:()=>{Ie(null),Pe(null)},onDrop:()=>{de&&de!==r.id&&je(r.id,"entry",de,"statement")},disabled:se||P||!V},r.id))})]})]}),Ce&&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:c("reconciliationView.matched","Matched:")}),e.jsxs("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--success",children:[oe.matchedStatements,"/",oe.totalStatements," (",oe.matchPercentage,"%)"]})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:c("reconciliationView.matchedAmount","Matched Amount:")}),e.jsx("span",{className:"nice-reconciliation__summary-value",children:Mt(oe.matchedAmount,me,G)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:c("reconciliationView.unmatched","Unmatched:")}),e.jsx("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--warning",children:Mt(oe.unmatchedStatementAmount,me,G)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:c("reconciliationView.difference","Difference:")}),e.jsx("span",{className:`nice-reconciliation__summary-value ${Math.abs(oe.difference)<.01?"nice-reconciliation__summary-value--success":"nice-reconciliation__summary-value--danger"}`,children:Mt(oe.difference,me,G)})]})]}),Re&&e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"presentation",className:`nice-reconciliation__detail-backdrop ${st?"nice-reconciliation__detail-backdrop--visible":""}`,onClick:()=>ct(null)}),e.jsx("div",{className:`nice-reconciliation__detail-panel ${st?"nice-reconciliation__detail-panel--open":""}`,children:st&&e.jsx(Qr,{type:st.type,id:st.id,statements:ie,entries:j,matches:Se,currency:me,locale:G,labels:k,onClose:()=>ct(null)})})]})]})});function Qr({type:n,id:a,statements:s,entries:c,matches:l,currency:d,locale:u,labels:o,onClose:_}){const{t:f}=N.useNiceTranslation(),S=n==="statement"?s.find(p=>p.id===a):c.find(p=>p.id===a),R=n==="statement"?l.find(p=>p.statementIds.includes(a)):l.find(p=>p.entryIds.includes(a)),L=R?n==="statement"?c.filter(p=>R.entryIds.includes(p.id)):s.filter(p=>R.statementIds.includes(p.id)):[];if(!S)return null;const z=n==="statement",b=z?S:null,D=z?null:S;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-reconciliation__detail-header",children:[e.jsxs("span",{className:"nice-reconciliation__detail-title",children:[e.jsx(N.NiceIcon,{name:z?"file":"book",size:14})," ",z?o.statementDetails??f("reconciliationView.transactionDetails","Transaction Details"):o.entryDetails??f("reconciliationView.entryDetails","Entry Details")]}),e.jsx("button",{type:"button",className:"nice-reconciliation__detail-close",onClick:_,"aria-label":f("reconciliationView.close","Close"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]}),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:[e.jsx(N.NiceIcon,{name:"check",size:14})," ",f("reconciliationView.matchedConfidence","{label} ({confidence}% confidence)").replace("{label}",o.matchedWith??f("reconciliationView.matched2","Matched")).replace("{confidence}",String(R.confidence?.toFixed(0)??100))]}),e.jsx("div",{className:"nice-reconciliation__detail-match-detail",children:R.matchedBy==="ai"?o.matchedByAI??f("reconciliationView.matchedAutomaticallyByAi","Matched automatically by AI"):o.matchedManually??f("reconciliationView.matchedManually","Matched manually")}),e.jsxs("div",{className:"nice-reconciliation__detail-side-by-side",children:[e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:o.statementTotal??f("reconciliationView.statement","Statement")}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${R.statementTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Mt(R.statementTotal,d,u)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:o.entryTotal??f("reconciliationView.bookEntry","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:Mt(R.entryTotal,d,u)})]})]}),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:[o.difference??f("reconciliationView.difference2","Difference"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{color:"var(--nice-warning, #f59e0b)"},children:Mt(R.difference,d,u)})]})]}),e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:[e.jsx(N.NiceIcon,{name:"clipboard",size:14})," ",z?o.transactionInfo??f("reconciliationView.transactionInformation","Transaction Information"):o.entryInfo??f("reconciliationView.entryInformation","Entry Information")]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.date??f("reconciliationView.date","Date"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:kn(S.date,u)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.description??f("reconciliationView.description","Description"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:S.description})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.amount??f("reconciliationView.amount","Amount"),":"]}),e.jsx("span",{className:`nice-reconciliation__detail-value ${S.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:Mt(S.amount,d,u)})]}),z&&b?.counterparty&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.counterparty??f("reconciliationView.counterparty","Counterparty"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:b.counterparty})]}),z&&b?.counterpartyAccount&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.accountNumber??f("reconciliationView.account","Account"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:b.counterpartyAccount})]}),!z&&D?.partyName&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.party??f("reconciliationView.party","Party"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:D.partyName})]}),!z&&D?.documentNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.documentRef??f("reconciliationView.documentRef","Document Ref"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:D.documentNumber})]}),z&&b?.referenceNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[o.reference??f("reconciliationView.reference","Reference"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:b.referenceNumber})]})]}),L.length>0&&e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:[e.jsx(N.NiceIcon,{name:"link",size:14})," ",z?o.matchedEntries??f("reconciliationView.matchedEntries","Matched Entries"):o.matchedStatements??f("reconciliationView.matchedStatements","Matched Statements")]}),L.map(p=>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:p.description}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:"var(--nice-text-secondary)"},children:[e.jsx("span",{children:kn(p.date,u)}),e.jsx("span",{style:{fontWeight:600,color:p.amount>=0?"var(--nice-success)":"var(--nice-danger)"},children:Mt(p.amount,d,u)})]})]},p.id))]})]})]})}const qr=[],Yr=({queries:n=qr,currentFilter:a,currentColumns:s,currentSort:c,onLoad:l,onSave:d,onUpdate:u,onDelete:o,onShare:_,onSetDefault:f,allowSharing:S=!0,allowPinning:R=!0,position:L="dropdown",className:z,style:b,"data-testid":D})=>{const{t:p}=N.useNiceTranslation(),[x,I]=i.useState(!1),[y,$]=i.useState(""),[M,F]=i.useState(!1),[H,xe]=i.useState(""),[re,ge]=i.useState(""),[Ce,te]=i.useState(!1),Me=i.useRef(null);N.useOverlayFocus(Me,{open:x,modal:!1,onClose:()=>I(!1)});const V=n.filter(P=>P.name.toLowerCase().includes(y.toLowerCase())),Ge=V.filter(P=>!P.isShared),Re=V.filter(P=>P.isShared),Ae=async()=>{if(H.trim()){F(!0);try{await d({name:H,description:re||void 0,filter:a??{},columns:s,sort:c}),te(!1),xe(""),ge("")}finally{F(!1)}}},se=P=>e.jsxs("div",{className:"nice-saved-query__item",children:[P.icon&&e.jsx("span",{className:"nice-saved-query__icon","aria-hidden":"true",children:P.icon}),e.jsx("span",{className:"nice-saved-query__name",children:P.name}),P.isDefault&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--default",children:p("savedQuery.default","default")}),P.isShared&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--shared",children:p("savedQuery.shared","shared")}),P.isPinned&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--pinned",children:p("savedQuery.pinned","pinned")}),e.jsxs("div",{className:"nice-saved-query__actions",children:[e.jsx("button",{onClick:()=>{l(P),I(!1)},type:"button",children:p("savedQuery.load","Load")}),f&&e.jsx("button",{onClick:()=>f(P.id),type:"button",title:p("savedQuery.setDefault","Set as default"),"aria-label":p("savedQuery.setDefault","Set as default"),children:e.jsx(N.NiceIcon,{name:"star",size:14})}),S&&_&&e.jsx("button",{onClick:()=>_(P.id,[]),type:"button",title:p("savedQuery.share","Share"),"aria-label":p("savedQuery.share","Share"),children:e.jsx(N.NiceIcon,{name:"external-link",size:14})}),R&&e.jsx("button",{onClick:()=>u(P.id,{...P}),type:"button",title:p("savedQuery.pin","Pin"),"aria-label":p("savedQuery.pin","Pin"),children:e.jsx(N.NiceIcon,{name:"map-pin",size:14})}),e.jsx("button",{onClick:()=>o(P.id),type:"button",title:p("savedQuery.remove","Remove"),"aria-label":`${p("savedQuery.removeQuery","Remove query")} ${P.name}`,children:e.jsx(N.NiceIcon,{name:"close",size:14})})]})]},P.id);return e.jsxs("div",{className:`nice-saved-query nice-saved-query--${L} ${x?"nice-saved-query--open":""} ${z??""}`,style:b,"data-testid":D,children:[e.jsx("button",{className:"nice-saved-query__trigger",onClick:()=>I(P=>!P),"aria-expanded":x,"aria-haspopup":"dialog",type:"button",children:p("savedQuery.trigger","Views and queries")}),x&&e.jsxs("div",{ref:Me,className:"nice-saved-query__panel",role:"dialog","aria-label":p("savedQuery.manage","Manage saved queries"),children:[e.jsxs("div",{className:"nice-saved-query__search-row",children:[e.jsx("input",{type:"search",placeholder:p("savedQuery.searchPlaceholder","Search queries…"),value:y,onChange:P=>$(P.target.value),"aria-label":p("savedQuery.search","Search queries")}),e.jsxs("button",{onClick:()=>te(P=>!P),type:"button",children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",p("savedQuery.saveCurrent","Save current view")]})]}),Ce&&e.jsxs("div",{className:"nice-saved-query__save-form",children:[e.jsx("input",{type:"text",placeholder:p("savedQuery.name","Query name"),value:H,onChange:P=>xe(P.target.value),"aria-label":p("savedQuery.name","Query name")}),e.jsx("input",{type:"text",placeholder:p("savedQuery.descriptionPlaceholder","Description (optional)"),value:re,onChange:P=>ge(P.target.value),"aria-label":p("savedQuery.description","Query description")}),e.jsx("button",{onClick:Ae,disabled:M||!H.trim(),type:"button",children:M?p("savedQuery.saving","Saving…"):p("savedQuery.save","Save")}),e.jsx("button",{onClick:()=>te(!1),type:"button",children:p("savedQuery.cancel","Cancel")})]}),Ge.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:p("savedQuery.mine","Mine")}),Ge.map(se)]}),Re.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:p("savedQuery.sharedSection","Shared")}),Re.map(se)]}),V.length===0&&e.jsx("p",{className:"nice-saved-query__empty",children:p("savedQuery.empty","No saved queries")})]})]})};exports.NICE_TREE_ROW_MIME=Fi;exports.NiceDataGridAI=ya;exports.NiceHighlight=Xn;exports.NiceKanbanBoard=rr;exports.NiceList=qa;exports.NiceModuleGrid=Nr;exports.NiceReconciliationView=Wr;exports.NiceSavedQueryPanel=Yr;exports.NiceSpreadsheet=Kr;exports.NiceTable=Xa;exports.NiceTileView=Ja;exports.NiceTreeGrid=Pa;exports.NiceTreeList=Ua;exports.NiceTreeView=Wa;exports.treeDropPosition=Hn;exports.treeKeyboardMove=ti;exports.treeKeyboardTarget=ni;exports.useTreeRowDrop=ii;