@nice2dev/ui 1.4.5 → 1.4.7
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.
- package/CHANGELOG.md +76 -0
- package/dist/{NiceDataGrid-mrnaLHQk.cjs → NiceDataGrid-D3qRQSjy.cjs} +1 -1
- package/dist/NiceForm-BWb4LTQJ.cjs +1 -0
- package/dist/{NiceHtmlEditor-C1OVtLQ6.cjs → NiceHtmlEditor-BzECmDO3.cjs} +1 -1
- package/dist/{NiceMention-tgJKS8PH.cjs → NiceMention-CYRqPKGU.cjs} +19 -19
- package/dist/NiceModuleLifecyclePanel-CiYbPcHV.cjs +1 -0
- package/dist/{NicePagination-D7XxeNFz.cjs → NicePagination-BAxwqeEd.cjs} +1 -1
- package/dist/{NicePivotGrid-Cnkr9WkC.cjs → NicePivotGrid-Cxu5PECg.cjs} +1 -1
- package/dist/{NiceSavedQueryPanel-U1-yaw-Q.cjs → NiceSavedQueryPanel-BSZhE-_l.cjs} +6 -6
- package/dist/{NiceScheduler-Boo-D1S-.cjs → NiceScheduler-BqYiHPvz.cjs} +1 -1
- package/dist/{core-lazy-C_qnVGxE.cjs → core-lazy-BQexApr7.cjs} +1 -1
- package/dist/data.cjs +1 -1
- package/dist/database/NiceDataSourceEditor.mjs +370 -0
- package/dist/database/NiceQueryDesigner.mjs +958 -0
- package/dist/database/moduleDataSource.mjs +151 -0
- package/dist/database/queryDesign.mjs +396 -0
- package/dist/database/queryDesignerPanels.mjs +1214 -0
- package/dist/database/querySql.mjs +481 -0
- package/dist/editors.cjs +1 -1
- package/dist/index.cjs +188 -181
- package/dist/index.d.ts +674 -0
- package/dist/index.mjs +774 -720
- package/dist/lazy.cjs +1 -1
- package/dist/navigation.cjs +1 -1
- package/dist/no-code/NiceNoCodeScriptEditor.mjs +584 -0
- package/dist/no-code/noCodeScript.mjs +326 -0
- package/dist/no-code-B1jzfUF5.cjs +331 -0
- package/dist/no-code.cjs +1 -1
- package/dist/no-code.d.ts +177 -0
- package/dist/no-code.mjs +26 -16
- package/dist/style.css +2 -2
- package/package.json +4 -4
- package/dist/NiceForm-O3sv-DNX.cjs +0 -1
- package/dist/NiceModuleLifecyclePanel-DKlqKPy2.cjs +0 -1
- package/dist/NiceSelect-BNPXs6FQ.cjs +0 -1
- package/dist/no-code-B3BHeyG-.cjs +0 -331
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),xi=require("@nice2dev/i18n"),k=require("@nice2dev/ui-core"),n=require("react"),yi=require("./NiceDataGrid-
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),xi=require("@nice2dev/i18n"),k=require("@nice2dev/ui-core"),n=require("react"),yi=require("./NiceDataGrid-D3qRQSjy.cjs"),vi=require("react-dom"),We=require("./NiceButton-DzCqkG5a.cjs"),ki=require("./NiceForm-BWb4LTQJ.cjs"),Ni=require("./NiceModal-BRVzjuUN.cjs"),wi=require("./core-lBFqvT0V.cjs"),vn=require("./no-code-B1jzfUF5.cjs"),Un=require("./NiceColorPicker-BLwYNSXJ.cjs"),ji=[];function Si(t,a){return t.filter(s=>a.every(r=>{const l=s[r.field],o=r.value;switch(r.operator){case"eq":return l===o;case"ne":return l!==o;case"gt":return typeof l=="number"&&typeof o=="number"&&l>o;case"gte":return typeof l=="number"&&typeof o=="number"&&l>=o;case"lt":return typeof l=="number"&&typeof o=="number"&&l<o;case"lte":return typeof l=="number"&&typeof o=="number"&&l<=o;case"contains":return String(l).toLowerCase().includes(String(o).toLowerCase());case"startsWith":return String(l).toLowerCase().startsWith(String(o).toLowerCase());case"endsWith":return String(l).toLowerCase().endsWith(String(o).toLowerCase());default:return!0}}))}function Ci(t){return t.map(a=>({field:a.field,type:a.dataType||"string",label:typeof a.header=="string"?a.header:a.field}))}function Ii(t,a){const{enableAI:s=!0,aiModel:r,enableNLSearch:l=!0,enableInsights:o=!0,nlPlaceholder:d,onAIFilter:c,onInsights:f,showAISearchBar:m=!0,exampleQueries:j=["Show items from last week","Filter by status = active","Orders over $1000",'Names starting with "A"'],columns:E=ji,data:L,...A}=t,[T,V]=n.useState(""),[g,x]=n.useState([]),[I,b]=n.useState([]),[z,S]=n.useState(!1),[U,H]=n.useState(null),fe=n.useRef(null),{t:re}=xi.useNiceTranslation(),ge=k.useNiceAI(),{parseFilter:Me,isLoading:J}=k.useNaturalLanguageFilter(),we=s&&ge.isConfigured,K=g.length>0?Si(L||[],g):L,Le=n.useCallback(async R=>{if(!we||!l||!R.trim())return;H(R);const _=Ci(E);try{const _e=await Me(R,_);x(_e),c?.(R,_e)}catch{x([])}},[we,l,E,Me,c]),Ne=n.useCallback(()=>{x([]),H(null),V("")},[]),Fe=n.useCallback(()=>g,[g]),X=n.useCallback(async()=>{if(!we||!o||!L?.length)return[];try{const R=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
2
|
|
|
3
3
|
Columns: ${E.map(_=>_.field).join(", ")}
|
|
4
4
|
|
|
5
|
-
Return a JSON array of insight strings. Be specific with numbers and trends.`}],{temperature:.3,maxTokens:500});try{const _=JSON.parse(R.content),_e=Array.isArray(_)?_:[];return b(_e),f?.(_e),_e}catch{return[]}}catch{return[]}},[we,o,L,E,ge,f]),$=R=>{R.preventDefault(),T.trim()&&Le(T)},P=R=>{V(R),Le(R)};return n.useImperativeHandle(a,()=>({applyNLFilter:Le,clearAIFilters:Ne,getAIFilters:Fe,generateInsights:X})),e.jsxs("div",{className:"nice-data-grid-ai","data-testid":t["data-testid"],children:[m&&we&&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:$,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(k.NiceIcon,{name:"search",size:14})}),e.jsx("input",{ref:fe,type:"text",value:T,onChange:R=>V(R.target.value),placeholder:d||re("dataGridAI.searchPlaceholder","Search with natural language..."),className:"nice-data-grid-ai__input",disabled:J}),J&&e.jsx("span",{className:"nice-data-grid-ai__loading-spinner"}),T&&!J&&e.jsx("button",{type:"button",className:"nice-data-grid-ai__clear-input",onClick:()=>V(""),"aria-label":re("dataGridAI.clearInput","Clear"),children:e.jsx(k.NiceIcon,{name:"close",size:14})})]}),e.jsx("button",{type:"submit",className:"nice-data-grid-ai__search-btn",disabled:J||!T.trim(),children:J?re("dataGridAI.searching","Searching..."):re("dataGridAI.search","Search")})]}),o&&e.jsxs("button",{type:"button",className:"nice-data-grid-ai__insights-btn",onClick:()=>{X(),S(!0)},disabled:J||!L?.length,title:re("dataGridAI.generateInsights","Generate AI Insights"),children:[e.jsx(k.NiceIcon,{name:"lightbulb",size:14})," ",re("dataGridAI.insights","Insights")]})]}),m&&we&&l&&!U&&j.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:j.slice(0,4).map((R,_)=>e.jsxs("button",{type:"button",className:"nice-data-grid-ai__example",onClick:()=>P(R),children:['"',R,'"']},_))})]}),U&&g.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(k.NiceIcon,{name:"target",size:14})}),e.jsxs("span",{className:"nice-data-grid-ai__filter-query",children:['"',U,'"']}),e.jsxs("span",{className:"nice-data-grid-ai__filter-count",children:["(",K?.length||0," ",re("dataGridAI.results","results"),")"]})]}),e.jsx("div",{className:"nice-data-grid-ai__filter-badges",children:g.map((R,_)=>e.jsxs("span",{className:"nice-data-grid-ai__filter-badge",children:[R.field," ",R.operator," ",String(R.value)]},_))}),e.jsxs("button",{type:"button",className:"nice-data-grid-ai__clear-filter",onClick:Ne,children:[e.jsx(k.NiceIcon,{name:"close",size:14})," ",re("dataGridAI.clearFilter","Clear")]})]}),e.jsx("div",{className:"nice-data-grid-ai__grid-wrapper",children:e.jsx(yi.NiceDataGrid,{columns:E,data:K,...A})}),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(k.NiceIcon,{name:"lightbulb",size:14})," ",re("dataGridAI.aiInsights","AI Insights")]}),e.jsx("button",{type:"button",className:"nice-data-grid-ai__insights-close",onClick:()=>S(!1),"aria-label":re("dataGridAI.closeInsights","Close"),children:e.jsx(k.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-data-grid-ai__insights-body",children:J?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((R,_)=>e.jsxs("li",{className:"nice-data-grid-ai__insight",children:[e.jsx("span",{className:"nice-data-grid-ai__insight-bullet",children:"•"}),R]},_))}):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:()=>X(),disabled:J,children:[e.jsx(k.NiceIcon,{name:"refresh",size:14})," ",re("dataGridAI.refresh","Refresh")]})})]})]})}const Di=n.forwardRef(Mi);function Ei(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const Nn=({text:t,query:a,highlightTag:s="mark",highlightClassName:r="",caseSensitive:l=!1,className:o="",style:d,testId:c,"data-testid":f})=>{const m=(Array.isArray(a)?a:[a]).map(A=>(A??"").trim()).filter(Boolean).map(Ei);if(m.length===0||!t)return e.jsx("span",{className:`nice-highlight ${o}`,style:d,"data-testid":f??c,children:t});const j=l?"g":"gi",E=new RegExp(`(${m.join("|")})`,j),L=t.split(E);return e.jsx("span",{className:`nice-highlight ${o}`,style:d,"data-testid":f??c,children:L.map((A,T)=>T%2===1?e.jsx(s,{className:`nice-highlight__mark ${r}`.trim(),children:A},T):e.jsx(n.Fragment,{children:A},T))})};process.env.NODE_ENV!=="production"&&(Nn.displayName="NiceHighlight");function Ri(t,a,s,r=0){const l=new Map,o=[];t.forEach(c=>l.set(String(c[a]),{data:c,children:[],key:String(c[a]),depth:0})),t.forEach(c=>{const f=c[s],m=l.get(String(c[a]));if(f!=null&&f!==""&&l.has(String(f))){const j=l.get(String(f));m.depth=j.depth+1,j.children.push(m)}else o.push(m)});const d=(c,f)=>{c.forEach(m=>{m.depth=f,d(m.children,f+1)})};return d(o,r),o}function Ai(t,a,s){const r=l=>l.map(o=>{const d=o.children.length===0?a.get(o.key):void 0,c=d?s(d,o.depth+1):o.children;return c.length>0?{...o,children:r(c)}:o});return r(t)}function Ti(t,a){const s=[],r=l=>{a(l)&&s.push(l.key),l.children.forEach(r)};return r(t),s}function Zn(t,a,s,r=0){return t.map(l=>({data:l,key:String(l[s]),depth:r,children:Array.isArray(l[a])?Zn(l[a],a,s,r+1):[]}))}function vn(t){const a=[],s=r=>{r.forEach(l=>{l.children.length>0&&(a.push(l.key),s(l.children))})};return s(t),a}function zi(t){const a=[],s=r=>{r.forEach(l=>{a.push(l.key),s(l.children)})};return s(t),a}function Jn(t,a,s){return!a||!s?t:[...t].sort((l,o)=>{const d=l.data[a]??"",c=o.data[a]??"",f=typeof d=="number"&&typeof c=="number"?d-c:String(d).localeCompare(String(c));return s==="desc"?-f:f}).map(l=>({...l,children:Jn(l.children,a,s)}))}function $i(t,a,s){const r=new Set,l=new Set,o=d=>d.reduce((c,f)=>{const m=o(f.children),j=a(f);return j&&l.add(f.key),m.length>0&&r.add(f.key),j&&s?c.push(f):(j||m.length>0)&&c.push({...f,children:m}),c},[]);return{tree:o(t),expand:r,matched:l}}function Li(t,a){const s=(r,l)=>r.reduce((o,d)=>{if(l)return o.push({...d,children:s(d.children,!0)}),o;if(a.isCheckable(d.key)){const f=a.state(d.key);if(f!=="unchecked"){const m=a.isLeaf(d.key)&&f==="checked";o.push({...d,children:s(d.children,m)})}return o}const c=s(d.children,!1);return c.length>0&&o.push({...d,children:c}),o},[]);return s(t,!1)}function Pi(t,a,s){const r=[],l=(o,d)=>{o.forEach((c,f)=>{if(r.push({node:c,level:d,posInSet:f+1,setSize:o.length}),c.children.length>0)a(c.key)&&l(c.children,d+1);else if(s&&a(c.key)){const m=s(c);m&&r.push({node:c,level:d+1,posInSet:1,setSize:1,placeholder:m})}})};return l(t,1),r}function wn(t,a,s={}){const{getKey:r,getChildren:l,isCheckable:o,isDisabled:d}=a,c=s.inheritDisabled!==!1,f=[],m=[],j=[],E=new Map,L=(T,V,g,x)=>{const I=r(T);if(E.has(I))return;const b=o?o(T):!0,z=(d?d(T):!1)||c&&x,S={pos:f.length,subtreeEnd:0,leafStart:m.length,leafEnd:0,checkable:b,leaf:!1,disabled:z,parent:g};E.set(I,S),f.push(I);const U=l(T,V);if(U)for(const H of U)L(H,V+1,I,z);b&&m.length===S.leafStart&&(S.leaf=!0,m.push(I),j.push(z)),S.leafEnd=m.length,S.subtreeEnd=f.length};for(const T of t)L(T,0,void 0,!1);const A=new Int32Array(m.length+1);for(let T=0;T<m.length;T++)A[T+1]=A[T]+(j[T]?1:0);return{keys:f,leaves:m,records:E,lockedBefore:A,has:T=>E.has(T),isCheckable:T=>E.get(T)?.checkable??!1,isLeaf:T=>E.get(T)?.leaf??!1,isLocked:T=>{const V=E.get(T);if(!V)return!1;const g=V.leafEnd-V.leafStart;return V.disabled||g===0?V.disabled:A[V.leafEnd]-A[V.leafStart]===g},leavesOf:T=>{const V=E.get(T);return V?m.slice(V.leafStart,V.leafEnd):[]},parentOf:T=>E.get(T)?.parent}}function jn(t,a){const s=new Set,r=[];if(!a)return{leaves:s,unknown:r};const l=new Set;for(const o of a){const d=t.records.get(o);if(!d){l.has(o)||(l.add(o),r.push(o));continue}if(d.checkable)for(let c=d.leafStart;c<d.leafEnd;c++)s.add(t.leaves[c])}return{leaves:s,unknown:r}}function sn(t,a){const s=new Int32Array(t.leaves.length+1);for(let d=0;d<t.leaves.length;d++)s[d+1]=s[d]+(a.has(t.leaves[d])?1:0);const r=d=>{const c=t.records.get(d);return c?{checked:s[c.leafEnd]-s[c.leafStart],total:c.leafEnd-c.leafStart}:{checked:0,total:0}},l=d=>{const{checked:c,total:f}=r(d);return c===0||f===0?"unchecked":c===f?"checked":"indeterminate"},o=[];for(const d of t.keys){const c=t.records.get(d);c.checkable&&!c.leaf&&l(d)==="indeterminate"&&o.push(d)}return{state:l,count:r,total:{checked:s[t.leaves.length],total:t.leaves.length},halfChecked:o}}function Sn(t,a,s,r){const l=t.records.get(s);if(!l||!l.checkable)return a;const o=[];for(let c=l.leafStart;c<l.leafEnd;c++)t.lockedBefore[c+1]===t.lockedBefore[c]&&o.push(t.leaves[c]);if(o.length===0)return a;const d=!o.every(c=>a.has(c));return ei(a,o,d)}function Gn(t,a,s,r){const l=[];for(const o of s){const d=t.records.get(o);d?.leaf&&!d.disabled&&l.push(o)}return l.length===0?a:ei(a,l,r)}function ei(t,a,s){const r=new Set(t);for(const l of a)s?r.add(l):r.delete(l);return r}function Zt(t,a,s,r=[]){const l=[];if(s==="leaves")for(const o of t.leaves)a.has(o)&&l.push(o);else{const o=new Int32Array(t.leaves.length+1);for(let c=0;c<t.leaves.length;c++)o[c+1]=o[c]+(a.has(t.leaves[c])?1:0);const d=c=>c.leafEnd>c.leafStart&&o[c.leafEnd]-o[c.leafStart]===c.leafEnd-c.leafStart;for(let c=0;c<t.keys.length;){const f=t.keys[c],m=t.records.get(f);if(m.checkable&&d(m)&&(l.push(f),s==="parents")){c=m.subtreeEnd;continue}c++}}for(const o of r)l.push(o);return l}const Oi=[],Fi=[],kn=[],Vi=new Set,Ki=new Map,Bi=[],Ui=new Map,Gi=new Map,Wn=["expandAll","collapseAll","onlyChecked","clearChecked"],Qn=10;function Wi({node:t,level:a,posInSet:s,setSize:r,rowIndex:l,ariaRowIndex:o,columns:d,highlight:c,query:f,expandable:m,expanded:j,busy:E,expandLabel:L,collapseLabel:A,subtreeAction:T,subtreeLabel:V,checkMode:g,hasCheckbox:x,checkState:I,checkLabel:b,locked:z,countChecked:S,countTotal:U,countTitle:H,selectColumn:fe,selected:re,selectLabel:ge,readOnly:Me,className:J,clickable:we,height:K,handlers:Le}){const Ne=x?e.jsx("input",{type:"checkbox",className:"nice-treegrid__check-input",checked:I==="checked",ref:X=>{X&&(X.indeterminate=I==="indeterminate")},disabled:z||Me,tabIndex:-1,"aria-label":b,onClick:X=>X.stopPropagation(),onChange:X=>{Le.toggleCheck(t.key),X.currentTarget.closest("tr")?.focus({preventScroll:!0})}}):null,Fe=["nice-treegrid__row",g!=="none"&&!x?"nice-treegrid__row--info":"",z?"nice-treegrid__row--disabled":"",x&&I==="checked"?"nice-treegrid__row--checked":"",re?"nice-datagrid__row--selected":"",J??""].filter(Boolean).join(" ");return e.jsxs("tr",{className:Fe,"data-key":t.key,tabIndex:-1,"aria-level":a,"aria-posinset":s,"aria-setsize":r,"aria-rowindex":o,"aria-expanded":m?j:void 0,"aria-selected":re,"aria-disabled":z||void 0,"aria-busy":E||void 0,onClick:()=>Le.rowClick(t),style:we||K!==void 0?{cursor:we?"pointer":void 0,height:K}:void 0,children:[g==="column"&&e.jsx("td",{className:"nice-datagrid__checkbox nice-treegrid__check-cell",children:Ne}),fe&&e.jsx("td",{className:"nice-datagrid__checkbox",children:e.jsx("input",{type:"checkbox",checked:!!re,onChange:()=>Le.toggleSelected(t.key),onClick:X=>X.stopPropagation(),disabled:Me,tabIndex:-1,"aria-label":ge})}),d.map((X,$)=>{const P=t.data[X.field];return e.jsxs("td",{style:{textAlign:X.align},children:[$===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 ${m?"":"nice-treegrid__toggle--leaf"}`,onClick:R=>{R.stopPropagation(),m&&Le.toggleExpand(t.key,R.altKey||R.shiftKey)},tabIndex:-1,"aria-hidden":m?void 0:!0,"aria-label":m?j?A:L:void 0,children:m?e.jsx(k.NiceIcon,{name:j?"chevron-down":"chevron-right",size:12}):""}),g==="tree"&&e.jsx("span",{className:`nice-treegrid__check${x?"":" nice-treegrid__check--none"}`,children:Ne})]}),X.render?X.render(P,t.data,l):c[$]&&f?e.jsx(Nn,{text:String(P??""),query:f,highlightClassName:"nice-treegrid__match"}):String(P??""),$===0&&U>0&&e.jsxs("span",{className:`nice-treegrid__count${S===U?" nice-treegrid__count--full":""}`,title:H,children:[S,"/",U]}),$===0&&T&&e.jsx("button",{type:"button",className:"nice-treegrid__row-action",tabIndex:-1,"aria-label":V,title:V,onClick:R=>{R.stopPropagation(),Le.setSubtreeExpanded(t.key,T==="expand")},children:e.jsx(k.NiceIcon,{name:T==="expand"?"expand":"collapse",size:12})})]},X.field)})]})}const Qi=n.memo(Wi);function qi({columns:t=Oi,data:a=Fi,keyField:s="id",parentKeyField:r="parentId",nested:l=!1,childrenField:o="children",expandedKeys:d,defaultExpandedKeys:c,onExpandedChange:f,hasChildren:m,loadChildren:j,rowActions:E,defaultExpandAll:L=!1,sortable:A=!0,sortField:T,sortDirection:V,onSort:g,selectable:x,selectedKeys:I,onSelectionChange:b,checkable:z,checkedKeys:S,defaultCheckedKeys:U,onCheckedChange:H,checkStrategy:fe="all",isRowCheckable:re,isRowDisabled:ge,checkboxPlacement:Me="tree",checkOnRowClick:J,showCheckedCount:we,checkedSummary:K,showSelectAll:Le=!0,showOnlyChecked:Ne,defaultShowOnlyChecked:Fe,onShowOnlyCheckedChange:X,toolbarActions:$,searchable:P,searchPlaceholder:R,searchText:_,defaultSearchText:_e,onSearchChange:ce,searchFields:w,searchFilter:ie,searchKeepDescendants:ue=!1,searchAutoExpand:be=!0,highlightMatches:M=!0,rowClassName:le,getRowLabel:xe,virtualScroll:ze,rowHeight:oe=36,height:je,striped:Oe,compact:De,size:Se="md",loading:rt,disabled:et,readOnly:tt,error:ke,emptyText:Q,toolbar:ye,onRowClick:Ee,contextMenuItems:Ke,className:Ae,style:ae,id:Z,testId:N,"data-testid":ve,accessMode:ee,"aria-label":Be,"aria-labelledby":Ye}){const{t:de}=k.useNiceTranslation(),Qe=k.useNiceAccessMode(ee,Z),C=!!et||Qe==="disabled",Y=!!tt||Qe==="readOnly",me=n.useCallback((i,y)=>l?Zn(i,o,s,y):Ri(i,s,r,y),[s,r,l,o]),$e=n.useMemo(()=>me(a,0),[me,a]),[qe,q]=n.useState(Ui),[Re,ct]=n.useState(Gi),Ue=n.useMemo(()=>qe.size>0?Ai($e,qe,me):$e,[$e,qe,me]),Ce=n.useMemo(()=>{const i=new Map,y=B=>B.forEach(ne=>{i.set(ne.key,ne),y(ne.children)});return y(Ue),i},[Ue]),lt=!!m||!!j,ot=n.useCallback(i=>{if(!lt)return!1;const y=Ce.get(i);return!!y&&y.children.length===0&&!qe.has(i)&&(m?m(y.data):!0)},[lt,Ce,qe,m]),Dt=n.useRef(new Set),Pt=n.useRef(!0);n.useEffect(()=>(Pt.current=!0,()=>{Pt.current=!1}),[]);const Vt=n.useCallback(i=>{const y=Ce.get(i);if(!j||!y||Dt.current.has(i))return;Dt.current.add(i);const B=ne=>{Dt.current.delete(i),Pt.current&&(ne&&q(Ge=>new Map(Ge).set(i,ne)),ct(Ge=>{const Xe=new Map(Ge);return ne?Xe.delete(i):Xe.set(i,"error"),Xe}))};ct(ne=>new Map(ne).set(i,"loading")),j(y.data).then(ne=>B(Array.isArray(ne)?ne:[]),()=>B(null))},[j,Ce]),Kt=n.useCallback(i=>{ct(y=>{const B=new Map(y);return B.delete(i),B})},[]),Nt=n.useMemo(()=>t.filter(i=>!i.hidden),[t]),Tt=n.useMemo(()=>vn(Ue),[Ue]),[nt,it]=n.useState(null),jt=n.useMemo(()=>{if(d)return new Set(d);if(nt)return nt;const i=new Set(c??kn);return L&&Tt.forEach(y=>i.add(y)),i},[d,nt,c,L,Tt]),Ot=n.useRef(jt);Ot.current=jt;const at=n.useCallback(i=>{Ot.current=i,d||it(i),f?.([...i])},[d,f]),[Et,ut]=n.useState({field:"",dir:null}),ft=T??Et.field,u=V??Et.dir,h=n.useCallback(i=>{const y=ft===i?u==="asc"?"desc":u==="desc"?null:"asc":"asc";g?g(i,y):ut({field:i,dir:y})},[ft,u,g]),[D,G]=k.useControllableState({value:I,fallbackValue:Vi,onChange:b,componentName:"NiceTreeGrid"}),W=n.useCallback(i=>{G(y=>{const B=new Set(y);return B.has(i)?B.delete(i):B.add(i),B})},[G]),p=n.useMemo(()=>z?wn(Ue,{getKey:i=>i.key,getChildren:i=>i.children,isCheckable:re?i=>re(i.data):void 0,isDisabled:ge?i=>ge(i.data):void 0}):null,[z,Ue,re,ge]),[O,te]=k.useControllableState({value:S,defaultValue:U,fallbackValue:kn,componentName:"NiceTreeGrid"}),F=n.useMemo(()=>p?jn(p,O):null,[p,O]),he=n.useMemo(()=>p&&F?sn(p,F.leaves):null,[p,F]),Pe=n.useMemo(()=>{if(typeof K!="function"||!p||!F||!he)return null;const i=Zt(p,F.leaves,"leaves"),y=[];return i.forEach(B=>{const ne=Ce.get(B);ne&&y.push(ne.data)}),{checked:he.total.checked,total:he.total.total,leafKeys:i,rows:y}},[K,p,F,he,Ce]),Ve=n.useCallback((i,y)=>{if(!p||!F||i===F.leaves)return;const B=Zt(p,i,fe,F.unknown);te(B),H?.(B,{...y,leafKeys:Zt(p,i,"leaves"),halfCheckedKeys:[...sn(p,i).halfChecked]})},[p,F,fe,te,H]),Je=n.useCallback(i=>{if(!p||!F)return;const y=Sn(p,F.leaves,i);Ve(y,{source:"row",checked:y.size>F.leaves.size,key:i,row:Ce.get(i)?.data})},[p,F,Ve,Ce]),[yt,ht]=k.useControllableState({value:_,defaultValue:_e,fallbackValue:"",onChange:ce,componentName:"NiceTreeGrid"}),dt=yt.trim(),Rt=n.useMemo(()=>w??Nt.map(i=>i.field),[w,Nt]),zt=n.useMemo(()=>{if(!dt)return null;const i=dt.toLowerCase();return $i(Ue,ie?B=>ie(B.data,dt):B=>Rt.some(ne=>String(B.data[ne]??"").toLowerCase().includes(i)),ue)},[Ue,dt,ie,Rt,ue]),Ft=zt?.tree??Ue,[Bt,cn]=k.useControllableState({value:Ne,defaultValue:Fe,fallbackValue:!1,onChange:X,componentName:"NiceTreeGrid"}),St=!!z&&Bt&&he!==null,Ct=n.useMemo(()=>St&&he&&p?Li(Ft,{state:he.state,isCheckable:p.isCheckable,isLeaf:p.isLeaf}):Ft,[St,he,p,Ft]),$t=dt!==""||St,Lt=`${dt}
|
|
6
|
-
${St?1:0}`,[Qt,At]=n.useState(()=>({key:"",map:new Map})),qt=Qt.key===Lt?Qt.map:Ki,Yt=n.useMemo(()=>{const i=new Set;return zt&&be&&zt.expand.forEach(y=>i.add(y)),St&&p&&vn(Ct).forEach(y=>{p.isLeaf(y)||i.add(y)}),i},[zt,be,St,p,Ct]),wt=n.useCallback(i=>$t?qt.get(i)??(jt.has(i)||Yt.has(i)):jt.has(i),[$t,qt,jt,Yt]),v=n.useCallback((i,y)=>{const B=Ot.current;if(i.some(ne=>B.has(ne)!==y)){const ne=new Set(B);i.forEach(Ge=>y?ne.add(Ge):ne.delete(Ge)),at(ne)}$t&&At(ne=>{const Ge=new Map(ne.key===Lt?ne.map:void 0);return i.forEach(Xe=>Ge.set(Xe,y)),{key:Lt,map:Ge}})},[at,$t,Lt]),se=n.useCallback(i=>i.children.length>0||ot(i.key),[ot]),pe=n.useRef(new Set),Ie=n.useCallback((i,y)=>{const B=i.flatMap(ne=>Ti(ne,se));B.forEach(ne=>{y?ot(ne)&&pe.current.add(ne):pe.current.delete(ne)}),v(B,y)},[se,ot,v]),st=n.useCallback((i,y)=>{const B=Ce.get(i);B&&Ie([B],y)},[Ce,Ie]),vt=n.useCallback((i,y)=>{const B=!wt(i);y?st(i,B):v([i],B)},[wt,st,v]),kt=n.useRef({nodeByKey:Ce,isPending:ot,setSubtreesExpanded:Ie});kt.current={nodeByKey:Ce,isPending:ot,setSubtreesExpanded:Ie},n.useEffect(()=>{const{nodeByKey:i,isPending:y,setSubtreesExpanded:B}=kt.current,ne=[];for(const Ge of[...pe.current]){const Xe=i.get(Ge);(!Xe||Xe.children.length>0||!y(Ge))&&(pe.current.delete(Ge),ne.push(...Xe?.children??[]))}ne.length>0&&B(ne,!0)},[Ue]);const mt=n.useCallback(i=>{i||pe.current.clear(),at(i?new Set(Tt):new Set),$t&&At({key:Lt,map:new Map(vn(Ct).map(y=>[y,i]))})},[at,Tt,$t,Lt,Ct]),en=n.useMemo(()=>Jn(Ct,ft,u),[Ct,ft,u]),Cn=n.useCallback(i=>ot(i.key)?Re.get(i.key)==="error"?"error":"loading":null,[ot,Re]),bt=n.useMemo(()=>Pi(en,wt,lt?Cn:void 0),[en,wt,lt,Cn]),ln=E===!0||Array.isArray(E)&&E.includes("expandSubtree"),si=n.useMemo(()=>{const i=new Set;if(!ln)return i;const y=B=>{if(B.children.length===0)return!ot(B.key);let ne=wt(B.key);return B.children.forEach(Ge=>{y(Ge)||(ne=!1)}),ne&&i.add(B.key),ne};return Ue.forEach(y),i},[ln,Ue,ot,wt]);n.useEffect(()=>{j&&bt.forEach(i=>{i.placeholder==="loading"&&Vt(i.node.key)})},[bt,j,Vt]);const Ut=n.useMemo(()=>p?dt?zi(Ft).filter(i=>p.isLeaf(i)):p.leaves:kn,[p,dt,Ft]),In=n.useMemo(()=>{if(!F||Ut.length===0)return"unchecked";let i=0;for(const y of Ut)F.leaves.has(y)&&i++;return i===0?"unchecked":i===Ut.length?"checked":"indeterminate"},[F,Ut]),ri=n.useCallback(()=>{if(!p||!F)return;const i=Ut.filter(B=>!p.isLocked(B)),y=!i.every(B=>F.leaves.has(B));Ve(Gn(p,F.leaves,i,y),{source:"selectAll",checked:y})},[p,F,Ut,Ve]),ci=n.useCallback(()=>{p&&F&&Ve(Gn(p,F.leaves,p.leaves,!1),{source:"clear",checked:!1})},[p,F,Ve]),Mn=i=>{Y||C||(z&&J&&p?.isCheckable(i.key)?Je(i.key):z&&x&&W(i.key),Ee?.(i.data))},Gt=n.useRef({toggleExpand:vt,setSubtreeExpanded:st,toggleCheck:Je,toggleSelected:W,rowClick:Mn});Gt.current={toggleExpand:vt,setSubtreeExpanded:st,toggleCheck:Je,toggleSelected:W,rowClick:Mn};const Dn=n.useMemo(()=>({toggleExpand:(i,y)=>Gt.current.toggleExpand(i,y),setSubtreeExpanded:(i,y)=>Gt.current.setSubtreeExpanded(i,y),toggleCheck:i=>Gt.current.toggleCheck(i),toggleSelected:i=>Gt.current.toggleSelected(i),rowClick:i=>Gt.current.rowClick(i)}),[]),pt=!!ze,tn=n.useRef(null),[En,li]=n.useState(typeof je=="number"?je:480);n.useEffect(()=>{const i=tn.current;if(!pt||!i||typeof ResizeObserver>"u")return;const y=new ResizeObserver(()=>{i.clientHeight>0&&li(i.clientHeight)});return y.observe(i),()=>y.disconnect()},[pt]);const on=k.useVirtualScroll({itemCount:pt?bt.length:0,itemHeight:oe,containerHeight:En,overscan:8}),dn=pt?on.startIndex:0,un=pt?on.endIndex:bt.length,hn=n.useRef(null),Rn=n.useRef(wt);Rn.current=wt,k.useTreeFocus(hn,{itemSelector:"tr.nice-treegrid__row",enabled:!C,onToggle:(i,y)=>{const B=i.dataset.key;B!==void 0&&i.hasAttribute("aria-expanded")&&Rn.current(B)!==y&&Dn.toggleExpand(B)}});const oi=n.useContext(k.NiceThemeContext),mn=n.useRef(null),[Wt,An]=n.useState(null),fn=n.useCallback(()=>An(null),[]);k.useOverlayFocus(mn,{open:!!Wt,modal:!1,initialFocus:'[role="menuitem"]:not([disabled])',onClose:fn}),k.useRovingFocus(mn,{orientation:"vertical",itemSelector:'[role="menuitem"]'});const Tn=(i,y,B)=>{const ne=Ke?Ce.get(i):void 0,Ge=ne?Ke?.(ne.data):void 0;return Ge?.some(Xe=>!Xe.divider)?(An({key:i,x:y,y:B,items:Ge}),!0):!1},pn=n.useCallback(i=>[...hn.current?.querySelectorAll("tr.nice-treegrid__row")??[]].find(y=>y.dataset.key===i),[]),[gn,zn]=n.useState(null);n.useEffect(()=>{if(gn===null)return;const i=pn(gn);i&&(i.focus(),zn(null))},[gn,dn,un,pn]);const di=i=>{const y=bt[i]?.placeholder?i-1:i,B=bt[y]?.node.key;if(B===void 0)return;const ne=pn(B);ne?ne.focus():pt&&tn.current&&(tn.current.scrollTop=Math.max(0,y*oe-En/2),zn(B))},ui=i=>{const y=i.target;if(i.altKey||i.ctrlKey||i.metaKey||!y.matches?.("tr.nice-treegrid__row"))return;const B=y.dataset.key??"";if(i.shiftKey&&(i.key==="ArrowRight"||i.key==="ArrowLeft")){if(y.hasAttribute("aria-expanded")){i.preventDefault();const Xe=getComputedStyle(y).direction==="rtl";st(B,i.key==="ArrowRight"!==Xe)}return}if(i.key===" "){if(Y)return;z&&p?.isCheckable(B)?(i.preventDefault(),Je(B)):x&&(i.preventDefault(),W(B));return}if(!(i.key==="PageDown"||i.key==="PageUp")&&!(pt&&(i.key==="Home"||i.key==="End")))return;const Ge=bt.findIndex(Xe=>Xe.node.key===B);Ge<0||(i.preventDefault(),di(i.key==="PageDown"?Math.min(bt.length-1,Ge+Qn):i.key==="PageUp"?Math.max(0,Ge-Qn):i.key==="Home"?0:bt.length-1))},hi=de("controls.expand","Expand"),mi=de("controls.collapse","Collapse"),$n=Nt[0]?.field,fi=i=>xe?xe(i.data):String(($n!=null?i.data[$n]:void 0)??i.key),Ln=(i,y)=>de("treeGrid.checkedSummary","{checked} of {total} selected").replace("{checked}",String(i)).replace("{total}",String(y)),pi=n.useMemo(()=>{const i=new Set(Rt);return Nt.map(y=>M&&!ie&&i.has(y.field))},[Nt,Rt,M,ie]),_n=$===!0?z?Wn:Wn.slice(0,2):Array.isArray($)?$.filter(i=>z||i==="expandAll"||i==="collapseAll"):Bi,nn=z?Me==="column"?"column":"tree":"none",an=!!x&&!z,Ht=Nt.length+(nn==="column"||an?1:0),Pn=[["checked",!he||K===!1?null:Pe&&typeof K=="function"?K(Pe):Ln(he.total.checked,he.total.total)],["matches",zt?de("treeGrid.matchCount","{count} matching rows").replace("{count}",String(zt.matched.size)):null]].filter(([,i])=>i!=null&&i!==!1&&i!=="");if(Qe==="hidden")return null;const bn=z&&Le&&p&&p.leaves.length>0?e.jsx("input",{type:"checkbox",className:"nice-treegrid__check-input nice-treegrid__select-all",checked:In==="checked",ref:i=>{i&&(i.indeterminate=In==="indeterminate")},disabled:Y||C,"aria-label":dt?de("treeGrid.selectAllResults","Select all results"):de("controls.selectAll","Select all"),onClick:i=>i.stopPropagation(),onChange:ri}):null,gi=i=>{const y={expandAll:{icon:"expand",label:de("treeGrid.expandAll","Expand all")},collapseAll:{icon:"collapse",label:de("treeGrid.collapseAll","Collapse all")},onlyChecked:{icon:"filter",label:de("treeGrid.showOnlyChecked","Show selected only")},clearChecked:{icon:"eraser",label:de("treeGrid.clearChecked","Clear selection")}}[i];return e.jsxs("button",{type:"button",className:`nice-btn nice-btn--sm nice-btn--ghost nice-treegrid__action${i==="onlyChecked"&&St?" nice-treegrid__action--active":""}`,"aria-pressed":i==="onlyChecked"?St:void 0,disabled:C||i==="clearChecked"&&(Y||!he||he.total.checked===0),onClick:()=>{i==="expandAll"||i==="collapseAll"?mt(i==="expandAll"):i==="onlyChecked"?cn(!Bt):ci()},children:[e.jsx(k.NiceIcon,{name:y.icon,size:14}),e.jsx("span",{children:y.label})]},i)},_i=i=>{const{node:y,level:B,posInSet:ne,setSize:Ge,placeholder:Xe}=bt[i],gt=y.key;if(Xe)return e.jsx("tr",{className:`nice-treegrid__placeholder nice-treegrid__placeholder--${Xe}`,"aria-level":B,style:pt?{height:oe}:void 0,children:e.jsxs("td",{colSpan:Ht,children:[e.jsx("span",{className:"nice-treegrid__indent",style:{width:(B-1)*20}}),e.jsx("span",{className:"nice-treegrid__toggle nice-treegrid__toggle--leaf","aria-hidden":"true"}),Xe==="loading"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-spinner nice-spinner--sm","aria-hidden":"true"}),e.jsx("span",{role:"status",children:de("treeGrid.loading","Loading…")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"alert",children:de("treeGrid.loadError","Could not load the rows.")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--ghost",onClick:()=>Kt(gt),children:de("treeGrid.retry","Retry")})]})]})},`${gt}\0${Xe}`);const xn=y.children.length>0||ot(gt),Vn=xn&&wt(gt),yn=ln&&xn?si.has(gt)?"collapse":"expand":null,Kn=!!p?.isCheckable(gt),Xt=we&&he&&p&&!p.isLeaf(gt)?he.count(gt):null,bi=fi(y);return e.jsx(Qi,{node:y,level:B,posInSet:ne,setSize:Ge,rowIndex:i,ariaRowIndex:pt?i+2:void 0,columns:Nt,highlight:pi,query:dt,expandable:xn,expanded:Vn,busy:Vn&&Re.get(gt)==="loading",expandLabel:hi,collapseLabel:mi,subtreeAction:yn,subtreeLabel:yn==="expand"?de("treeGrid.expandSubtree","Expand all below"):yn==="collapse"?de("treeGrid.collapseSubtree","Collapse all below"):"",checkMode:nn,hasCheckbox:Kn,checkState:he?he.state(gt):"unchecked",checkLabel:Kn?de("treeGrid.checkRow","Select {label}").replace("{label}",bi):"",locked:!!p?.isLocked(gt),countChecked:Xt?.checked??0,countTotal:Xt?.total??0,countTitle:Xt?Ln(Xt.checked,Xt.total):"",selectColumn:an,selected:x?D.has(gt):void 0,selectLabel:an?de("controls.selectRow","Select row {key}").replace("{key}",gt):"",readOnly:Y,className:typeof le=="function"?le(y.data,i):le,clickable:!Y&&(!!Ee||!!J||!!z&&!!x),height:pt?oe:void 0,handlers:Dn},gt)},On=[];for(let i=dn;i<un;i++)On.push(_i(i));const Fn=(i,y)=>i>0?e.jsx("tr",{className:"nice-treegrid__spacer","aria-hidden":"true",children:e.jsx("td",{colSpan:Ht,style:{height:i*oe}})},y):null;return e.jsxs("div",{id:Z,"data-testid":ve??N,className:`nice-treegrid nice-datagrid ${C?"nice-treegrid--disabled":""} ${Y?"nice-treegrid--readonly":""} ${ke?"nice-treegrid--error":""} ${pt?"nice-treegrid--virtual":""} ${Ae||""}`,style:ae,"aria-disabled":C||void 0,"aria-busy":rt||void 0,"aria-invalid":!!ke||void 0,children:[(P||ye||_n.length>0)&&e.jsxs("div",{className:"nice-datagrid__toolbar nice-treegrid__toolbar",children:[P&&e.jsxs("div",{className:"nice-datagrid__search nice-treegrid__search",children:[e.jsx("input",{type:"search",value:yt,onChange:i=>ht(i.target.value),onKeyDown:i=>{i.key==="Escape"&&yt&&(i.preventDefault(),ht(""))},placeholder:R||de("controls.search","Search..."),"aria-label":R||de("controls.search","Search...")}),yt&&e.jsx("button",{type:"button",className:"nice-treegrid__search-clear",onClick:()=>ht(""),"aria-label":de("treeGrid.clearSearch","Clear search"),children:e.jsx(k.NiceIcon,{name:"close",size:12})})]}),_n.length>0&&e.jsx("div",{className:"nice-treegrid__actions",children:_n.map(gi)}),ye,Pn.length>0&&e.jsx("span",{className:"nice-treegrid__summary",role:"status",children:Pn.map(([i,y],B)=>e.jsxs(n.Fragment,{children:[B>0&&" · ",y]},i))})]}),e.jsx("div",{ref:tn,className:"nice-datagrid__table-wrap",style:pt?{height:je??480,overflow:"auto"}:void 0,onScroll:pt?on.onScroll:void 0,children:e.jsxs("table",{ref:hn,role:"treegrid","aria-label":Be,"aria-labelledby":Ye,"aria-multiselectable":x||z||void 0,"aria-rowcount":pt?bt.length+1:void 0,className:`nice-table nice-table--${Se} ${Oe?"nice-table--striped":""} ${De?"nice-table--compact":""}`,onKeyDownCapture:i=>{if(Ke&&(i.key==="ContextMenu"||i.key==="F10"&&i.shiftKey)){const y=i.target.closest("tr.nice-treegrid__row"),B=y?.getBoundingClientRect();if(y?.dataset.key!==void 0&&B&&Tn(y.dataset.key,B.left+24,B.bottom)){i.preventDefault(),i.stopPropagation();return}}ui(i)},onContextMenu:Ke?i=>{const y=i.target.closest("tr.nice-treegrid__row");y?.dataset.key!==void 0&&Tn(y.dataset.key,i.clientX,i.clientY)&&i.preventDefault()}:void 0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[nn==="column"&&e.jsx("th",{className:"nice-datagrid__checkbox nice-treegrid__th-check",children:bn}),an&&e.jsx("th",{className:"nice-datagrid__checkbox",style:{width:36}}),Nt.map((i,y)=>e.jsxs("th",{style:{width:i.width,minWidth:i.minWidth,textAlign:i.align},className:A&&i.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>A&&i.sortable!==!1&&h(i.field),children:[y===0&&nn==="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})]}),i.header,A&&i.sortable!==!1&&e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:ft===i.field&&u?void 0:.3},children:e.jsx(k.NiceIcon,{name:ft===i.field&&u?u==="asc"?"sort-asc":"sort-desc":"sort",size:12})})]},i.field))]})}),e.jsx("tbody",{children:rt?e.jsx("tr",{children:e.jsx("td",{colSpan:Ht,className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):ke?e.jsx("tr",{children:e.jsx("td",{colSpan:Ht,className:"nice-datagrid__empty nice-treegrid__error",role:"alert",children:ke})}):bt.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Ht,className:"nice-datagrid__empty",children:dt?de("controls.noResults","No results"):Q||de("controls.noData","No data available")})}):e.jsxs(e.Fragment,{children:[Fn(dn,"top"),On,Fn(bt.length-un,"bottom")]})})]})}),Wt&&typeof document<"u"&&vi.createPortal(e.jsx("div",{ref:mn,className:"nice-treegrid__menu",role:"menu","aria-label":de("treeGrid.rowMenu","Row actions"),style:{position:"fixed",left:Wt.x,top:Wt.y},children:Wt.items.map(i=>i.divider?e.jsx("div",{className:"nice-treegrid__menu-divider",role:"separator"},i.id):e.jsxs("button",{type:"button",role:"menuitem",className:`nice-treegrid__menu-item${i.danger?" nice-treegrid__menu-item--danger":""}`,disabled:i.disabled,onClick:()=>{fn(),i.onSelect?.()},children:[i.icon&&e.jsx(k.NiceIcon,{name:i.icon,size:14}),i.label]},i.id))}),oi?.portalTarget??document.body),Wt&&e.jsx("div",{className:"nice-treegrid__menu-backdrop","aria-hidden":"true",onMouseDown:fn})]})}const Yi=[],Hi=[],Xi=[];function Zi(t,a,s){const r=[],l=(c,f)=>{c.forEach(m=>{r.push({item:m,parent:m[s]??f}),Array.isArray(m.children)&&m.children.length>0&&l(m.children,m[a])})};l(t,null);const o=new Map,d=[];return r.forEach(({item:c})=>{const f={...c,children:[]};o.set(String(f[a]),f)}),r.forEach(({item:c,parent:f})=>{f!=null&&o.has(String(f))?o.get(String(f)).children.push(o.get(String(c[a]))):d.push(o.get(String(c[a])))}),d}function Ji({columns:t=Yi,data:a=Hi,keyField:s="key",parentKeyField:r="parentKey",expandedKeys:l,onExpandedChange:o,selectedKeys:d=Xi,onSelectionChange:c,selectable:f,sortable:m,loading:j,emptyText:E,className:L,style:A,accessMode:T,id:V,"data-testid":g}){const I=k.useNiceAccessMode(T,V)==="hidden",{t:b}=k.useNiceTranslation(),[z,S]=n.useState([]),U=l??z,[H,fe]=n.useState(d),re=c?d:H,ge=n.useMemo(()=>Zi(a,s,r),[a,s,r]),Me=n.useMemo(()=>t.filter(w=>!w.hidden),[t]),[J,we]=n.useState(null),K=n.useCallback(w=>{we(ie=>ie?.field===w?ie.dir==="asc"?{field:w,dir:"desc"}:null:{field:w,dir:"asc"})},[]),Le=n.useCallback(w=>J?[...w].sort((ue,be)=>{const M=ue[J.field]??"",le=be[J.field]??"",xe=typeof M=="number"?M-le:String(M).localeCompare(String(le));return J.dir==="desc"?-xe:xe}).map(ue=>ue.children&&ue.children.length?{...ue,children:Le(ue.children)}:ue):w,[J]),Ne=n.useMemo(()=>Le(ge),[ge,Le]),Fe=n.useCallback(w=>{const ie=U.includes(w)?U.filter(ue=>ue!==w):[...U,w];o?o(ie):S(ie)},[U,o]),X=n.useMemo(()=>wn(ge,{getKey:w=>String(w[s]),getChildren:w=>w.children}),[ge,s]),$=n.useMemo(()=>jn(X,re),[X,re]),P=n.useMemo(()=>sn(X,$.leaves),[X,$]),R=n.useCallback(w=>{const ie=Sn(X,$.leaves,w),ue=Zt(X,ie,"all",$.unknown);c?c(ue):fe(ue)},[X,$,c]),_=Me[0]?.field;let _e=0;const ce=(w,ie)=>{const ue=String(w[s]),be=_e++,M=!!(w.children&&w.children.length>0),le=U.includes(ue),xe=P.state(ue),ze=xe==="checked",oe=xe==="indeterminate",je=_!=null?String(w[_]??ue):ue;return e.jsxs(n.Fragment,{children:[e.jsxs("tr",{className:ze?"nice-treelist__row--selected":"",children:[f&&e.jsx("td",{className:"nice-treelist__checkbox",children:e.jsx("input",{type:"checkbox",checked:ze,ref:Oe=>{Oe&&(Oe.indeterminate=oe)},onChange:()=>R(ue),"aria-label":b("controls.selectRow","Select row {key}").replace("{key}",je)})}),Me.map((Oe,De)=>e.jsxs("td",{style:{textAlign:Oe.align},children:[De===0&&e.jsx("span",{style:{display:"inline-block",width:ie*20}}),De===0&&e.jsx("span",{role:M?"button":void 0,tabIndex:M?0:void 0,"aria-expanded":M?le:void 0,"aria-label":M?b(le?"controls.collapse":"controls.expand",le?"Collapse":"Expand"):void 0,onKeyDown:M?k.clickOnActivationKey:void 0,className:"nice-treelist__toggle",onClick:()=>M&&Fe(ue),style:{cursor:M?"pointer":"default",width:20,display:"inline-block"},children:M?e.jsx(k.NiceIcon,{name:le?"chevron-down":"chevron-right",size:12}):""}),Oe.render?Oe.render(w[Oe.field],w,be):String(w[Oe.field]??"")]},Oe.field))]}),M&&le&&w.children.map(Oe=>ce(Oe,ie+1))]},ue)};return I?null:e.jsx("div",{className:`nice-treelist ${L||""}`,style:A,"data-testid":g,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[f&&e.jsx("th",{className:"nice-treelist__checkbox"}),Me.map(w=>{const ie=!!m&&!!w.sortable;return e.jsxs("th",{style:{width:w.width,minWidth:w.minWidth,textAlign:w.align},className:ie?"nice-treelist__th--sortable":void 0,onClick:()=>ie&&K(w.field),scope:"col","aria-sort":ie?J?.field===w.field?J.dir==="asc"?"ascending":"descending":"none":void 0,children:[w.header,ie&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:e.jsx(k.NiceIcon,{name:J?.field===w.field?J.dir==="desc"?"chevron-down":"chevron-up":"sort",size:12})})]},w.field)})]})}),e.jsx("tbody",{children:j?e.jsx("tr",{children:e.jsx("td",{colSpan:Me.length+(f?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:Me.length+(f?1:0),className:"nice-treelist__empty",children:E||b("controls.noData","No data available")})}):Ne.map(w=>ce(w,0))})]})})}function ti(t,a=[]){for(const s of t)s.expanded&&a.push(s.key),s.children&&ti(s.children,a);return a}const qn=[],ea=[],ta=({nodes:t=qn,header:a,selectedKeys:s=ea,expandedKeys:r,onSelectionChange:l,onExpandedChange:o,selectionMode:d="none",showCheckboxes:c,searchable:f,searchPlaceholder:m,onNodeClick:j,renderNode:E,showLines:L,loading:A,className:T,style:V,accessMode:g,id:x,draggable:I,onNodeDrop:b,onLoadChildren:z,contextMenuItems:S,onContextMenuAction:U,editable:H,onNodeEdit:fe,maxDepth:re,"data-testid":ge})=>{const J=k.useNiceAccessMode(g,x)==="hidden",{t:we}=k.useNiceTranslation(),[K,Le]=n.useState(()=>ti(t)),[Ne,Fe]=n.useState(""),[X,$]=n.useState(new Set),[P,R]=n.useState(new Map),[_,_e]=n.useState(null),[ce,w]=n.useState(null),[ie,ue]=n.useState(null),[be,M]=n.useState(""),le=n.useRef(null),xe=r??K,ze=n.useRef(xe);ze.current=xe;const oe=n.useMemo(()=>new Set(s),[s]),je=typeof re=="number"?Math.min(10,Math.max(1,re)):1/0,Oe=!!c&&d==="multiple",De=n.useMemo(()=>Oe?wn(t,{getKey:N=>N.key,getChildren:(N,ve)=>ve+1>=je?null:P.get(N.key)??N.children,isDisabled:N=>!!N.disabled},{inheritDisabled:!1}):null,[Oe,t,P,je]),Se=n.useMemo(()=>De?jn(De,s):null,[De,s]),rt=n.useMemo(()=>De&&Se?sn(De,Se.leaves):null,[De,Se]),et=n.useCallback(async(N,ve)=>{const ee=ze.current,Be=!ee.includes(N),Ye=Be?[...ee,N]:ee.filter(de=>de!==N);if(ze.current=Ye,o?o(Ye):Le(Ye),Be&&z&&!ve.children?.length&&ve.leaf!==!0&&!P.has(N)){$(Qe=>new Set(Qe).add(N));const de=await z(ve);R(Qe=>new Map(Qe).set(N,de)),$(Qe=>{const C=new Set(Qe);return C.delete(N),C})}},[o,z,P]),tt=n.useCallback(N=>{if(l){if(d==="single")l(s.includes(N)?[]:[N]);else if(d==="multiple")if(De&&Se){const ve=Sn(De,Se.leaves,N);ve!==Se.leaves&&l(Zt(De,ve,"all",Se.unknown))}else l(s.includes(N)?s.filter(ve=>ve!==N):[...s,N])}},[s,d,l,De,Se]),ke=n.useCallback(N=>{if(!Ne)return!0;const ve=Ne.toLowerCase();return N.text.toLowerCase().includes(ve)?!0:(P.get(N.key)??N.children)?.some(Be=>ke(Be))??!1},[Ne,P]),Q=n.useCallback((N,ve)=>{S?.length&&(N.preventDefault(),w({x:N.clientX,y:N.clientY,node:ve}))},[S]),ye=n.useCallback(()=>{ie&&fe&&fe(ie,be),ue(null)},[ie,be,fe]),Ee=n.useRef(null),Ke=(N,ve=t)=>{for(const ee of ve){const Be=ee.key===N?ee:Ke(N,P.get(ee.key)??ee.children??qn);if(Be)return Be}};k.useTreeFocus(Ee,{rowSelector:".nice-tree__row",onToggle:(N,ve)=>{const ee=N.dataset.key===void 0?void 0:Ke(N.dataset.key);ee&&ze.current.includes(ee.key)!==ve&&et(ee.key,ee)}});const Ae=n.useRef(null);n.useEffect(()=>{if(ie!==null||Ae.current===null)return;const N=Ae.current;Ae.current=null,[...Ee.current?.querySelectorAll('[role="treeitem"]')??[]].find(ve=>ve.dataset.key===N)?.focus()},[ie]);const ae=n.useRef(null);k.useRovingFocus(ae,{orientation:"vertical",wrap:!0,typeahead:!0}),k.useOverlayFocus(ae,{open:!!ce,modal:!1,onClose:()=>w(null)});const Z=(N,ve)=>{if(Ne&&!ke(N))return null;const ee=ve+1>=je,Be=ee?void 0:P.get(N.key)??N.children,Ye=!ee&&(Be&&Be.length>0||N.leaf!==!0&&z&&!Be?.length),de=xe.includes(N.key),Qe=rt?rt.state(N.key):oe.has(N.key)?"checked":"unchecked",C=rt?Qe==="checked":oe.has(N.key),Y=!!N.disabled||!!De?.isLocked(N.key),me=X.has(N.key),$e=Math.min(ve+1,10),qe={paddingLeft:ve*20+4,"--nice-row-bg":`var(--nice-tree-level-${$e}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${$e}-text, inherit)`,"--nice-row-border":`var(--nice-tree-level-${$e}-border, transparent)`,"--nice-row-hover-bg":`var(--nice-tree-level-${$e}-hover-bg, var(--nice-hover-bg, color-mix(in srgb, var(--nice-text-primary) 6%, transparent)))`,"--nice-row-active-bg":`var(--nice-tree-level-${$e}-active-bg, color-mix(in srgb, var(--nice-color-primary) 14%, transparent))`};return e.jsxs("li",{className:"nice-tree__node",role:"treeitem","aria-label":N.text,"aria-expanded":Ye?de:void 0,"aria-selected":d!=="none"?C:void 0,"aria-disabled":N.disabled||void 0,"data-key":N.key,"data-nice-depth":$e,onKeyDown:H&&!N.disabled?q=>{q.key==="F2"&&q.target===q.currentTarget&&(q.preventDefault(),ue(N.key),M(N.text))}:void 0,draggable:I&&!N.disabled,onDragStart:I?q=>{q.stopPropagation(),_e(N.key)}:void 0,onDragOver:I?q=>{q.preventDefault(),q.stopPropagation()}:void 0,onDrop:I&&_?q=>{q.stopPropagation(),b?.(_,N.key,"inside"),_e(null)}:void 0,onDragEnd:I?()=>_e(null):void 0,children:[e.jsxs("div",{role:"presentation",className:`nice-tree__row ${C?"nice-tree__row--selected":""} ${N.disabled?"nice-tree__row--disabled":""} ${_===N.key?"nice-tree__row--dragging":""}`,style:qe,onClick:()=>{N.disabled||(tt(N.key),j?.(N))},onContextMenu:q=>Q(q,N),onDoubleClick:H&&!N.disabled?()=>{ue(N.key),M(N.text)}:void 0,children:[e.jsx("span",{role:"presentation",className:`nice-tree__toggle ${Ye?de?"nice-tree__toggle--expanded":"":"nice-tree__toggle--leaf"}`,onClick:q=>{q.stopPropagation(),Ye&&et(N.key,N)},children:me?e.jsx("span",{className:"nice-spinner nice-spinner--xs"}):Ye?de?e.jsx(k.NiceIcon,{name:"chevron-down",size:12}):e.jsx(k.NiceIcon,{name:"chevron-right",size:12}):""}),c&&d!=="none"&&e.jsx("input",{type:"checkbox",checked:Qe==="checked",ref:q=>{q&&(q.indeterminate=Qe==="indeterminate")},onChange:()=>tt(N.key),onClick:q=>q.stopPropagation(),disabled:Y,tabIndex:-1,"aria-label":N.text,className:"nice-tree__checkbox"}),ie===N.key?e.jsx("input",{type:"text",className:"nice-tree__edit-input",value:be,onChange:q=>M(q.target.value),onBlur:ye,onKeyDown:q=>{q.key==="Enter"&&(Ae.current=N.key,ye()),q.key==="Escape"&&(q.preventDefault(),Ae.current=N.key,ue(null))},autoFocus:!0,onClick:q=>q.stopPropagation()}):E?E(N):e.jsxs(e.Fragment,{children:[N.icon&&e.jsx("span",{className:"nice-tree__icon",children:N.icon}),e.jsx("span",{className:"nice-tree__text",children:N.text})]})]}),Be&&Be.length>0&&de&&e.jsx("ul",{className:"nice-tree__children",role:"group",children:Be.map(q=>Z(q,ve+1))})]},N.key)};return J?null:e.jsxs("div",{role:"presentation",className:`nice-tree ${L?"nice-tree--lines":""} ${T||""}`,style:V,ref:le,"data-testid":ge,onClick:()=>w(null),children:[a!=null&&a!==!1&&e.jsx("div",{className:"nice-tree__header",children:a}),f&&e.jsx("div",{className:"nice-tree__search",children:e.jsx("input",{type:"text",value:Ne,onChange:N=>Fe(N.target.value),placeholder:m||we("controls.search","Search..."),"aria-label":m||we("controls.search","Search tree")})}),A?e.jsx("div",{className:"nice-tree__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm"})}):e.jsx("ul",{ref:Ee,className:"nice-tree__root",role:"tree","aria-multiselectable":d==="multiple"||void 0,children:t.map(N=>Z(N,0))}),ce&&S&&e.jsx("div",{ref:ae,className:"nice-tree__context-menu",role:"menu","aria-label":ce.node.text,style:{position:"fixed",top:ce.y,left:ce.x,zIndex:9999},children:S.map(N=>e.jsxs("button",{type:"button",role:"menuitem",disabled:N.disabled,className:`nice-tree__context-item ${N.disabled?"nice-tree__context-item--disabled":""}`,onClick:()=>{N.disabled||(U?.(N.key,ce.node),w(null))},children:[N.icon&&e.jsx("span",{children:N.icon}),N.label]},N.key))})]})},na=[],ia=({items:t=na,selectedKeys:a=[],onSelectionChange:s,selectionMode:r="none",searchable:l,searchPlaceholder:o,grouped:d,groupField:c="group",reorderable:f,onReorder:m,onItemClick:j,renderItem:E,showCheckboxes:L,loading:A,emptyText:T,size:V="md",header:g,disabled:x,readOnly:I,error:b,bordered:z=!0,swipeActions:S,className:U,style:H,accessMode:fe,id:re,"data-testid":ge})=>{const J=k.useNiceAccessMode(fe,re)==="hidden",{t:we}=k.useNiceTranslation(),[K,Le]=n.useState(""),[Ne,Fe]=n.useState(null),[X,$]=n.useState(null),P=n.useRef(null),R=n.useMemo(()=>{if(!K)return t;const M=K.toLowerCase();return t.filter(le=>le.text.toLowerCase().includes(M))},[t,K]),_=n.useMemo(()=>{if(!d)return null;const M=new Map;return R.forEach(le=>{const xe=String(le[c]??"");M.has(xe)||M.set(xe,[]),M.get(xe).push(le)}),M},[R,d,c]),_e=n.useCallback(M=>{s&&(r==="single"?s(a.includes(M)?[]:[M]):r==="multiple"&&s(a.includes(M)?a.filter(le=>le!==M):[...a,M]))},[a,r,s]),ce=n.useCallback(M=>{Ne!==null&&Ne!==M&&m&&m(Ne,M),Fe(null)},[Ne,m]),w=n.useRef(null),ie=n.useCallback(M=>{w.current=M},[]);k.useRovingFocus(w,{orientation:"vertical",itemSelector:".nice-list__item",typeahead:!0,pageSize:10});const ue=M=>{!M.disabled&&!x&&!I&&(_e(M.key),j?.(M))},be=(M,le)=>{const xe=a.includes(M.key),ze=X===M.key;return e.jsxs("li",{className:`nice-list__item ${xe?"nice-list__item--selected":""} ${M.disabled?"nice-list__item--disabled":""} ${ze?"nice-list__item--swiped":""}`,onClick:()=>ue(M),onKeyDown:oe=>{oe.target===oe.currentTarget&&(oe.key==="Enter"||oe.key===" ")&&(oe.preventDefault(),ue(M))},draggable:f&&!x&&!I,onDragStart:()=>Fe(le),onDragOver:oe=>oe.preventDefault(),onDrop:()=>ce(le),onTouchStart:S?.length?oe=>{P.current={x:oe.touches[0].clientX,key:M.key}}:void 0,onTouchEnd:S?.length?oe=>{if(!P.current)return;const je=oe.changedTouches[0].clientX-P.current.x;je<-50&&P.current.key===M.key?$(M.key):je>50&&$(null),P.current=null}:void 0,role:"option","aria-selected":r!=="none"?xe:void 0,"aria-disabled":M.disabled||void 0,children:[e.jsxs("div",{className:"nice-list__item-content",children:[L&&r!=="none"&&e.jsx("input",{type:"checkbox",checked:xe,readOnly:!0,tabIndex:-1,className:"nice-list__checkbox"}),E?E(M):e.jsxs(e.Fragment,{children:[M.icon&&e.jsx("span",{className:"nice-list__icon",children:M.icon}),e.jsx("span",{className:"nice-list__text",children:M.text}),M.badge&&e.jsx("span",{className:"nice-list__badge",children:M.badge})]})]}),S&&ze&&e.jsx("div",{className:"nice-list__swipe-actions",children:S.map(oe=>e.jsx("button",{className:"nice-list__swipe-btn",style:oe.color?{backgroundColor:oe.color}:void 0,onClick:je=>{je.stopPropagation(),oe.onClick(M),$(null)},children:oe.label},oe.key))})]},M.key)};return J?null:e.jsxs("div",{className:`nice-list nice-list--${V} ${z?"nice-list--bordered":""} ${x?"nice-list--disabled":""} ${I?"nice-list--readonly":""} ${b?"nice-list--error":""} ${U||""}`,style:H,"data-testid":ge,"aria-disabled":x||void 0,"aria-busy":A||void 0,children:[g&&e.jsx("div",{className:"nice-list__header",children:g}),l&&!A&&e.jsx("div",{className:"nice-list__search",children:e.jsx("input",{type:"text",value:K,onChange:M=>Le(M.target.value),placeholder:o||we("controls.search","Search...")})}),A?e.jsx("div",{className:"nice-list__loading",role:"status","aria-live":"polite",children:e.jsx("div",{className:`nice-spinner nice-spinner--${V}`})}):b?e.jsx("div",{className:"nice-list__error",role:"alert",children:b}):R.length===0?e.jsx("div",{className:"nice-list__empty",children:T||we("controls.noData","No data available")}):e.jsx("div",{role:"listbox",ref:ie,"aria-multiselectable":r==="multiple"||void 0,children:_?Array.from(_.entries()).map(([M,le])=>e.jsxs("div",{className:"nice-list__group",role:"group","aria-label":M,children:[e.jsx("div",{className:"nice-list__group-header","aria-hidden":"true",children:M}),e.jsx("ul",{className:"nice-list__items",role:"presentation",children:le.map((xe,ze)=>be(xe,ze))})]},M)):e.jsx("ul",{className:"nice-list__items",role:"presentation",children:R.map((M,le)=>be(M,le))})})]})},aa=[],sa=[];function ra({columns:t=aa,data:a=sa,striped:s,compact:r,size:l="md",emptyText:o,className:d,style:c,accessMode:f,id:m,displayStyle:j}){const{t:E}=k.useNiceTranslation(),L=k.normalizeSize(l),T=k.useNiceAccessMode(f,m)==="hidden",V=k.useComponentDisplayStyle("table",j),g=k.useComponentDisplayClass("table",j),[x,I]=n.useState(null),b=n.useMemo(()=>x?[...a].sort((S,U)=>{const H=S[x.field]??"",fe=U[x.field]??"",re=typeof H=="number"?H-fe:String(H).localeCompare(String(fe));return x.dir==="desc"?-re:re}):a,[a,x]),z=S=>{I(U=>U?.field===S?U.dir==="asc"?{field:S,dir:"desc"}:null:{field:S,dir:"asc"})};return T?null:e.jsx("div",{className:`nice-table-wrapper ${d||""}`,style:{...V,...c},children:e.jsxs("table",{className:`nice-table nice-table--ds-${g} nice-table--${L} ${s?"nice-table--striped":""} ${r?"nice-table--compact":""}`,"aria-rowcount":b.length,"aria-colcount":t.length,children:[e.jsx("thead",{children:e.jsx("tr",{children:t.map(S=>{const U=S.sortable?x?.field===S.field?x.dir==="asc"?"ascending":"descending":"none":void 0;return e.jsxs("th",{style:{width:S.width,textAlign:S.align},className:S.sortable?"th--sortable":void 0,onClick:()=>S.sortable&&z(S.field),scope:"col","aria-sort":U,children:[S.header,S.sortable&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:e.jsx(k.NiceIcon,{name:x?.field===S.field?x.dir==="desc"?"chevron-down":"chevron-up":"sort",size:12})})]},S.field)})})}),e.jsx("tbody",{children:b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:t.length,className:"nice-table__empty",children:o||E("table.noData","No data")})}):b.map((S,U)=>e.jsx("tr",{children:t.map(H=>e.jsx("td",{style:{textAlign:H.align},children:H.render?H.render(S[H.field],S):String(S[H.field]??"")},H.field))},U))})]})})}const ca=[];function la({items:t=ca,tileWidth:a=180,tileHeight:s=180,direction:r="horizontal",renderTile:l,onTileClick:o,loading:d,emptyText:c,className:f,style:m,"data-testid":j}){const{t:E}=k.useNiceTranslation();return e.jsx("div",{className:`nice-tileview nice-tileview--${r} ${f||""}`,style:m,"data-testid":j,children:d?e.jsx("div",{className:"nice-tileview__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):t.length===0?e.jsx("div",{className:"nice-tileview__empty",children:c||E("controls.noData","No data available")}):e.jsx("div",{className:"nice-tileview__container",style:{display:"flex",flexWrap:"wrap",gap:8,flexDirection:r==="vertical"?"column":"row"},children:t.map(L=>e.jsx("div",{role:o?"button":void 0,tabIndex:o?0:void 0,onKeyDown:o?k.clickOnActivationKey:void 0,className:"nice-tileview__tile",style:{width:a,height:s,cursor:o?"pointer":void 0},onClick:()=>o?.(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 oa=[],da=[];function ua({open:t}){return e.jsx(k.NiceIcon,{name:"chevron-down",size:14,style:{transition:"transform 160ms ease",transform:t?"rotate(0deg)":"rotate(-90deg)"}})}function ha(){return e.jsx(k.NiceIcon,{name:"plus",size:14})}const ma=[{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"}],fa=Object.assign(n.forwardRef(({columns:t=oa,cards:a=da,onCardMove:s,onCardClick:r,renderCard:l,onAddCard:o,disabled:d=!1,size:c="md",collapsible:f=!1,collapseDirection:m="vertical",layoutMode:j="scroll",viewMode:E,onViewModeChange:L,collapsedColumns:A,onCollapsedColumnsChange:T,formItems:V,formColumns:g=1,formProps:x,editCardTitle:I,newCardTitle:b,onCardEdit:z,onCardCreate:S,onCardDelete:U,tutorial:H,cookies:fe=!1,localStorage:re=!0,sessionStorage:ge=!1,storageMode:Me,storageKey:J,className:we,style:K,id:Le,...Ne},Fe)=>{const{t:X}=k.useNiceTranslation(),[$,P]=n.useState(null),[R,_]=n.useState(null),[_e,ce]=n.useState(null),w=!!V&&(!!z||!!S),ie=n.useCallback(Q=>{if(w&&z){ce({key:Q.key,data:{...Q},column:Q.column});return}r?.(Q)},[w,r,z]),ue=w&&!!z||!!r,be=n.useCallback(Q=>{if(w&&S){ce({key:null,data:{title:"",description:""},column:Q});return}o?.(Q)},[w,o,S]),M=wi.useStorageAdapter(J??"nice-kanban"),[le,xe]=n.useState(()=>M.get("state")??{collapsedColumns:[],viewMode:"default"}),ze=n.useMemo(()=>A??le.collapsedColumns??[],[A,le.collapsedColumns]),oe=E??le.viewMode??"default",je=n.useCallback(Q=>{xe(ye=>{const Ee={...ye,...Q};return M.set("state",Ee),Ee})},[M]),Oe=n.useCallback(Q=>{const ye=ze.includes(Q)?ze.filter(Ee=>Ee!==Q):[...ze,Q];T?T(ye):je({collapsedColumns:ye})},[ze,T,je]);n.useCallback(Q=>{L?L(Q):je({viewMode:Q})},[L,je]);const De=n.useCallback(Q=>a.filter(ye=>ye.column===Q).sort((ye,Ee)=>(ye.order??0)-(Ee.order??0)),[a]),Se=n.useCallback((Q,ye)=>{d||(Q.dataTransfer.effectAllowed="move",Q.dataTransfer.setData("text/plain",String(ye.key)),P({cardKey:ye.key,fromColumn:ye.column}))},[d]),rt=n.useCallback((Q,ye)=>{Q.preventDefault(),Q.dataTransfer.dropEffect="move",_({column:ye})},[]),et=n.useCallback(()=>{_(null)},[]),tt=n.useCallback((Q,ye)=>{if(Q.preventDefault(),_(null),!$||d)return;const Ee=De(ye);s?.($.cardKey,ye,Ee.length),P(null)},[$,d,De,s]),ke=n.useCallback(()=>{P(null),_(null)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:Fe,id:Le,className:`nice-kanban nice-kanban--${c} nice-kanban--${oe} nice-kanban--layout-${j} ${d?"nice-kanban--disabled":""} ${we||""}`,style:{position:"relative",...K},...Ne,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(k.NiceTutorialButton,{steps:k.resolveTutorial(H,ma)})}),t.map(Q=>{const ye=De(Q.key),Ee=R?.column===Q.key,Ke=Q.limit!=null&&ye.length>=Q.limit,Ae=f&&ze.includes(Q.key);return e.jsxs("div",{className:`nice-kanban__column ${Ee?"nice-kanban__column--dragover":""} ${Ae?`nice-kanban__column--collapsed nice-kanban__column--collapse-${m}`:""}`,onDragOver:ae=>!Ae&&rt(ae,Q.key),onDragLeave:et,onDrop:ae=>!Ae&&tt(ae,Q.key),children:[e.jsxs("div",{className:"nice-kanban__column-header",style:Q.color?{borderTopColor:Q.color}:void 0,onClick:f?()=>Oe(Q.key):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?ae=>{(ae.key==="Enter"||ae.key===" ")&&Oe(Q.key)}:void 0,children:[f&&e.jsx("span",{className:"nice-kanban__collapse-icon","aria-hidden":"true",children:e.jsx(ua,{open:!Ae})}),e.jsx("span",{className:"nice-kanban__column-title",children:Q.title}),e.jsx("span",{className:"nice-kanban__column-count",children:Q.limit!=null?e.jsxs("span",{className:"nice-kanban__count-frac",children:[e.jsx("span",{className:"nice-kanban__count-num",children:ye.length}),e.jsx("span",{className:"nice-kanban__count-slash",children:"/"}),e.jsx("span",{className:"nice-kanban__count-den",children:Q.limit})]}):ye.length})]}),!Ae&&e.jsxs("div",{className:"nice-kanban__column-body",children:[ye.map(ae=>e.jsx("div",{className:`nice-kanban__card nice-kanban__card--${oe} ${$?.cardKey===ae.key?"nice-kanban__card--dragging":""}`,draggable:!d,onDragStart:Z=>Se(Z,ae),onDragEnd:ke,onClick:()=>ie(ae),role:ue?"button":"article",tabIndex:ue?0:void 0,onKeyDown:ue?k.clickOnActivationKey:void 0,children:l?l(ae):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"nice-kanban__card-title",children:ae.title}),oe!=="compact"&&ae.description&&e.jsx("div",{className:"nice-kanban__card-desc",children:ae.description})]})},ae.key)),ye.length===0&&e.jsx("div",{className:"nice-kanban__empty",children:X("kanban.empty","No cards")})]}),!Ae&&(o||w&&S)&&!Ke&&e.jsxs("button",{type:"button",className:"nice-kanban__add",onClick:()=>be(Q.key),disabled:d,children:[e.jsx(ha,{})," ",X("kanban.addCard","Add card")]})]},Q.key)})]}),w&&_e&&e.jsxs(Ni.NiceModal,{open:!0,onClose:()=>ce(null),title:_e.key==null?b||X("kanban.newCard","New card"):I||X("kanban.editCard","Edit card"),children:[e.jsx(ki.NiceForm,{items:V,data:_e.data,columns:g,...x,onFieldChange:(Q,ye)=>ce(Ee=>Ee&&{...Ee,data:{...Ee.data,[Q]:ye}})}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16,flexWrap:"wrap"},children:[_e.key!=null&&U&&e.jsx(We.NiceButton,{type:"button",size:"sm",variant:"error",style:{marginRight:"auto"},onClick:()=>{U(_e.key),ce(null)},children:X("controls.delete","Delete")}),e.jsx(We.NiceButton,{type:"button",size:"sm",variant:"secondary",onClick:()=>ce(null),children:X("controls.cancel","Cancel")}),e.jsx(We.NiceButton,{type:"button",size:"sm",variant:"primary",onClick:()=>{if(_e.key==null){const Q={key:`card-${Date.now()}`,title:"",column:_e.column,..._e.data};S?.(Q)}else z?.(_e.key,{..._e.data,key:_e.key,column:_e.column});ce(null)},children:X("controls.save","Save")})]})]})]})}),{displayName:"NiceKanbanBoard"}),pa=[];function Mt(...t){return t.filter(Boolean).map(a=>typeof a=="object"?Object.entries(a).filter(([,s])=>s).map(([s])=>s).join(" "):a).join(" ")}const ga=50,_a=[10,25,50,100,200],ba=40,xa={compact:32,normal:ba,comfortable:48},ya=10,va=768,ka=500,Na=10;function xt(t,a){return a.split(".").reduce((s,r)=>s?.[r],t)}function ni(t){return t.width==="auto"?{flex:"1 1 0",minWidth:t.minWidth??80,maxWidth:t.maxWidth}:{width:t.width||150,minWidth:t.minWidth,maxWidth:t.maxWidth}}function Jt(t,a,s="pl-PL"){if(t==null)return"—";switch(a.type){case"number":return new Intl.NumberFormat(s,{minimumFractionDigits:a.format?.includes(".")?a.format.split(".")[1].length:0}).format(t);case"currency":return new Intl.NumberFormat(s,{style:"currency",currency:a.currencyCode||"PLN"}).format(t);case"percent":return new Intl.NumberFormat(s,{style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}).format(t/100);case"date":return new Intl.DateTimeFormat(s,{dateStyle:"short"}).format(new Date(t));case"datetime":return new Intl.DateTimeFormat(s,{dateStyle:"short",timeStyle:"short"}).format(new Date(t));case"boolean":return t?e.jsx(k.NiceIcon,{name:"check",size:14}):e.jsx(k.NiceIcon,{name:"close",size:14});case"enum":return a.enumOptions?.find(l=>l.value===t)?.label||String(t);default:return String(t)}}function wa(t,a,s,r){const[l,o]=n.useState(0),{startIndex:d,endIndex:c,totalHeight:f,offsetY:m}=n.useMemo(()=>{const L=t.length*s,A=Math.ceil(a/s),T=Math.max(0,Math.floor(l/s)-r),V=Math.min(t.length,Math.ceil(l/s)+A+r),g=T*s;return{startIndex:T,endIndex:V,totalHeight:L,offsetY:g}},[t.length,a,s,l,r]),j=n.useMemo(()=>t.slice(d,c),[t,d,c]),E=n.useCallback(L=>{o(L.currentTarget.scrollTop)},[]);return{visibleData:j,totalHeight:f,offsetY:m,handleScroll:E,startIndex:d}}function ja(t,a){const[s,r]=n.useState(()=>{if(t&&typeof window<"u"){const o=localStorage.getItem(`nice-module-grid-${t}`);if(o)return JSON.parse(o)}return a||{}}),l=n.useCallback(o=>{r(d=>{const c={...d,...o};return t&&typeof window<"u"&&localStorage.setItem(`nice-module-grid-${t}`,JSON.stringify(c)),c})},[t]);return[s,l]}function Sa(t){const[a,s]=n.useState(typeof window<"u"&&window.innerWidth<t);return n.useEffect(()=>{if(typeof window>"u")return;const r=()=>s(window.innerWidth<t);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[t]),a}function Ca({column:t,sort:a,onSort:s,onResize:r,resizable:l,t:o}){const d=n.useRef(null),[c,f]=n.useState(!1),m=n.useCallback(L=>{if(!l||!r)return;L.preventDefault(),f(!0);const A=L.clientX,T=t.width||150,V=x=>{const I=x.clientX-A,b=Math.max(t.minWidth||50,T+I);r(t.field,Math.min(b,t.maxWidth||1/0))},g=()=>{f(!1),document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",g)},[t,l,r]),j=a?.direction,E=j==="asc"?e.jsx(k.NiceIcon,{name:"sort-asc",size:12}):j==="desc"?e.jsx(k.NiceIcon,{name:"sort-desc",size:12}):null;return e.jsxs("div",{className:Mt("nice-module-grid__header-cell",t.sortable&&"nice-module-grid__header-cell--sortable",c&&"nice-module-grid__header-cell--resizing"),style:{...ni(t),textAlign:t.align},onClick:()=>t.sortable&&s?.(t.field),role:"columnheader","aria-sort":j==="asc"?"ascending":j==="desc"?"descending":"none",title:t.headerTooltip,children:[e.jsx("span",{className:"nice-module-grid__header-text",children:t.header}),E&&e.jsx("span",{className:"nice-module-grid__sort-indicator",children:E}),l&&e.jsx("div",{ref:d,className:"nice-module-grid__resize-handle",onMouseDown:m})]})}function Ia({column:t,row:a,rowIndex:s,value:r,locale:l="pl-PL",onClick:o}){const{t:d}=k.useNiceTranslation(),c=k.useAccessibleClick({onClick:o}),f=o?c:{},m={...ni(t),textAlign:t.align};if(t.render)return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:t.render(r,a,s)});if((t.type==="enum"||t.type==="badge")&&t.enumOptions){const j=t.enumOptions.find(E=>E.value===r);if(j)return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsxs("span",{className:Mt("nice-module-grid__badge",`nice-module-grid__badge--${j.color||"default"}`),children:[j.icon&&e.jsx("span",{className:"nice-module-grid__badge-icon",children:j.icon}),j.label]})})}if(t.type==="progress"){const j=Math.min(100,Math.max(0,Number(r)||0));return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsxs("div",{className:"nice-module-grid__progress",children:[e.jsx("div",{className:"nice-module-grid__progress-bar",children:e.jsx("div",{className:Mt("nice-module-grid__progress-fill",`nice-module-grid__progress-fill--${t.progressColor||"primary"}`),style:{width:`${j}%`}})}),e.jsxs("span",{className:"nice-module-grid__progress-text",children:[j,"%"]})]})})}if(t.type==="rating"){const j=t.maxRating||5,E=Number(r)||0;return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsx("span",{className:"nice-module-grid__rating","aria-label":d("pagination.outOfStars","{rating} out of {max} stars").replace("{rating}",String(E)).replace("{max}",String(j)),children:Array.from({length:j},(L,A)=>e.jsx("span",{className:Mt("nice-module-grid__rating-star",A<E&&"nice-module-grid__rating-star--filled"),children:e.jsx(k.NiceIcon,{name:"star",size:14})},A))})})}if(t.type==="link"&&t.linkTemplate){const j=t.linkTemplate.replace(/\{\{(\w+)\}\}/g,(E,L)=>String(xt(a,L)??""));return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsx("a",{href:j,target:t.linkNewTab?"_blank":void 0,rel:t.linkNewTab?"noopener noreferrer":void 0,className:"nice-module-grid__link",children:Jt(r,t,l)})})}if(t.type==="image"){const E={xs:24,sm:32,md:48,lg:64}[t.imageSize||"sm"];return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:r?e.jsx("img",{src:String(r),alt:"",className:"nice-module-grid__image",style:{width:E,height:E}}):e.jsx("div",{className:"nice-module-grid__image-placeholder",style:{width:E,height:E}})})}return t.type==="avatar"?e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:r?e.jsx("img",{src:String(r),alt:"",className:"nice-module-grid__avatar"}):e.jsx("div",{className:"nice-module-grid__avatar-placeholder",children:"?"})}):t.type==="color"?e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsx("span",{className:"nice-module-grid__color-swatch",style:{backgroundColor:r||"transparent"},title:r})}):t.type==="boolean"?e.jsx("div",{className:"nice-module-grid__cell",style:{...m,textAlign:t.align||"center"},role:"gridcell",...f,children:e.jsx("span",{className:Mt("nice-module-grid__boolean",!!r&&"nice-module-grid__boolean--true"),children:e.jsx(k.NiceIcon,{name:r?"check":"close",size:14})})}):e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:Jt(r,t,l)})}function Ma({row:t,index:a,columns:s,primaryField:r,secondaryField:l,customRender:o,selected:d,onClick:c,locale:f="pl-PL",t:m}){const j={role:"option","aria-selected":!!d,onClick:c,onKeyDown:A=>{A.target===A.currentTarget&&(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),c?.())}};if(o)return e.jsx("div",{className:Mt("nice-module-grid__mobile-card",d&&"nice-module-grid__mobile-card--selected"),...j,children:o(t,a)});const E=s.find(A=>A.field===r)||s[0],L=s.find(A=>A.field===l)||s[1];return e.jsxs("div",{className:Mt("nice-module-grid__mobile-card",d&&"nice-module-grid__mobile-card--selected"),...j,children:[e.jsxs("div",{className:"nice-module-grid__mobile-card-header",children:[e.jsx("div",{className:"nice-module-grid__mobile-card-title",children:Jt(xt(t,E?.field||""),E,f)}),L&&e.jsx("div",{className:"nice-module-grid__mobile-card-subtitle",children:Jt(xt(t,L.field),L,f)})]}),e.jsx("div",{className:"nice-module-grid__mobile-card-body",children:s.filter(A=>!A.hidden&&A.field!==r&&A.field!==l).slice(0,4).map(A=>e.jsxs("div",{className:"nice-module-grid__mobile-card-field",children:[e.jsx("span",{className:"nice-module-grid__mobile-card-label",children:A.header}),e.jsx("span",{className:"nice-module-grid__mobile-card-value",children:Jt(xt(t,A.field),A,f)})]},A.field))})]})}function Da({page:t,pageSize:a,totalRows:s,pageSizeOptions:r,onPageChange:l,t:o}){const d=Math.ceil(s/a),c=(t-1)*a+1,f=Math.min(t*a,s);return e.jsxs("div",{className:"nice-module-grid__pagination",role:"navigation","aria-label":o("pagination.ariaLabel","Pagination"),children:[e.jsxs("div",{className:"nice-module-grid__pagination-info",children:[o("pagination.showing","Showing")," ",c,"–",f," ",o("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:m=>l(1,Number(m.target.value)),"aria-label":o("pagination.rowsPerPage","Rows per page"),children:r.map(m=>e.jsx("option",{value:m,children:m},m))}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(1,a),disabled:t===1,"aria-label":o("pagination.first","First"),children:e.jsx(k.NiceIcon,{name:"skip-back",size:14})}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(t-1,a),disabled:t===1,"aria-label":o("pagination.previous","Previous"),children:e.jsx(k.NiceIcon,{name:"chevron-left",size:14})}),e.jsxs("span",{className:"nice-module-grid__pagination-page",children:[t," / ",d]}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(t+1,a),disabled:t>=d,"aria-label":o("pagination.next","Next"),children:e.jsx(k.NiceIcon,{name:"chevron-right",size:14})}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(d,a),disabled:t>=d,"aria-label":o("pagination.last","Last"),children:e.jsx(k.NiceIcon,{name:"skip-forward",size:14})})]})]})}function Ea({columns:t}){return e.jsx("div",{className:"nice-module-grid__row nice-module-grid__row--skeleton",role:"row",children:t.filter(a=>!a.hidden).map(a=>e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--skeleton",style:{width:a.width==="auto"?"auto":a.width||150},children:e.jsx("div",{className:"nice-module-grid__skeleton-bar"})},a.field))})}function Ra(t,a){const{columns:s=pa,data:r,keyField:l="id",dataSource:o,onFetch:d,sortable:c=!0,sort:f,onSortChange:m,multiSort:j=!1,filter:E,searchText:L,onSearchChange:A,searchPlaceholder:T,pagination:V=!0,page:g,pageSize:x,pageSizeOptions:I=_a,totalRows:b,onPageChange:z,virtualScroll:S=!0,rowHeight:U,overscan:H=ya,selectionMode:fe="none",selectedKeys:re,onSelectionChange:ge,columnResize:Me=!0,onColumnWidthChange:J,contextMenuItems:we,onContextMenuAction:K,exportable:Le=!0,exportFormats:Ne=["csv","excel"],onExport:Fe,preferencesKey:X,initialPreferences:$,density:P="normal",striped:R=!0,bordered:_=!1,hoverable:_e=!0,loading:ce=!1,emptyState:w,toolbar:ie,onRowClick:ue,onRowDoubleClick:be,rowClassName:M,rowStyle:le,mobileCardView:xe=!0,mobileBreakpoint:ze=va,mobileCardRender:oe,mobilePrimaryField:je,mobileSecondaryField:Oe,size:De="medium",skeletonLoading:Se=!0,skeletonRows:rt=Na,"aria-label":et,"aria-labelledby":tt,"aria-describedby":ke,className:Q,style:ye,id:Ee,testId:Ke}=t,Ae=U??xa[P],{t:ae,lang:Z}=k.useNiceTranslation();k.useNiceAccessMode(),k.useComponentDisplayStyle("table");const N=Sa(ze),[ve,ee]=ja(X,$),Be=n.useRef(null),Ye=n.useRef(null),[de,Qe]=n.useState([]),[C,Y]=n.useState(),[me,$e]=n.useState(""),[qe,q]=n.useState(1),[Re,ct]=n.useState(x||ga),[Ue,Ce]=n.useState(new Set),[lt,ot]=n.useState([]),[Dt,Pt]=n.useState(0),[Vt,Kt]=n.useState(!1),[Nt,Tt]=n.useState(new Set),[nt,it]=n.useState(null),[jt,Ot]=n.useState({}),at=f??de,Et=E??C,ut=L??me,ft=g??qe,u=x??Re,h=re??Ue,D=!!(d||o),G=b??(D?Dt:r?.length??0),W=n.useMemo(()=>{const v=new Set(ve.hiddenColumns||[]);return s.filter(se=>!se.hidden&&!v.has(se.field))},[s,ve.hiddenColumns]),p=n.useMemo(()=>{if(D)return lt;if(!r)return[];let v=[...r];if(ut){const se=ut.toLowerCase(),pe=s.filter(Ie=>Ie.searchable!==!1).map(Ie=>Ie.field);v=v.filter(Ie=>pe.some(st=>{const vt=xt(Ie,st);return String(vt??"").toLowerCase().includes(se)}))}return at.length>0&&v.sort((se,pe)=>{for(const Ie of at){const st=xt(se,Ie.field),vt=xt(pe,Ie.field),kt=st<vt?-1:st>vt?1:0;if(kt!==0)return Ie.direction==="asc"?kt:-kt}return 0}),v},[D,lt,r,ut,at,s]),O=n.useMemo(()=>{if(D||!V)return p;const v=(ft-1)*u;return p.slice(v,v+u)},[D,p,V,ft,u]),te=Be.current?.clientHeight||400,F=S&&O.length>ka,{visibleData:he,totalHeight:Pe,offsetY:Ve,handleScroll:Je,startIndex:yt}=wa(O,te,Ae,H),ht=F?he:O,dt=n.useCallback(async()=>{if(d){Kt(!0);try{const se=await d({page:ft,pageSize:u,sort:at,filter:Et,search:ut});ot(se.data),Pt(se.total)}catch(v){console.error("NiceModuleGrid fetch error:",v)}finally{Kt(!1)}}},[d,ft,u,at,Et,ut]);n.useEffect(()=>{D&&dt()},[D,dt]);const Rt=n.useCallback(v=>{const se=at.find(Ie=>Ie.field===v);let pe;se?se.direction==="asc"?pe=at.map(Ie=>Ie.field===v?{...Ie,direction:"desc"}:Ie):pe=at.filter(Ie=>Ie.field!==v):pe=j?[...at,{field:v,direction:"asc"}]:[{field:v,direction:"asc"}],m?m(pe):Qe(pe)},[at,j,m]),zt=n.useCallback((v,se)=>{z?z(v,se):(q(v),ct(se))},[z]),Ft=n.useCallback(v=>{A?A(v):$e(v),z||q(1)},[A,z]),Bt=n.useCallback((v,se)=>{const pe=new Set(h);if(fe==="single"?(pe.clear(),pe.add(v)):(fe==="multiple"||fe==="checkbox")&&(pe.has(v)?pe.delete(v):pe.add(v)),ge){const Ie=O.filter(st=>pe.has(String(xt(st,l))));ge(pe,Ie)}else Ce(pe)},[h,fe,ge,O,l]),cn=n.useCallback((v,se)=>{Ot(pe=>({...pe,[v]:se})),J?.(v,se),ee({columnWidths:{...ve.columnWidths,[v]:se}})},[J,ee,ve.columnWidths]),St=n.useCallback((v,se)=>{if(we?.length)if(v.preventDefault(),v.clientX===0&&v.clientY===0){const pe=v.currentTarget.getBoundingClientRect();it({x:pe.left,y:pe.bottom,row:se})}else it({x:v.clientX,y:v.clientY,row:se})},[we]),Ct=n.useRef(null);k.useOverlayFocus(Ct,{open:nt!=null,modal:!1,onClose:()=>it(null)}),k.useRovingFocus(Ct,{orientation:"vertical",wrap:!0,typeahead:!0});const $t=n.useCallback(v=>{nt&&K?.(v,nt.row),it(null)},[nt,K]),Lt=n.useCallback(async v=>{if(Fe)await Fe(v,{selectedOnly:h.size>0,columns:W.map(se=>se.field)});else if(v==="csv"){const se=W.map(mt=>mt.header).join(","),pe=O.map(mt=>W.map(en=>JSON.stringify(xt(mt,en.field)??"")).join(",")),Ie=[se,...pe].join(`
|
|
7
|
-
`),st=new Blob([Ie],{type:"text/csv;charset=utf-8;"}),vt=URL.createObjectURL(st),kt=document.createElement("a");kt.href=vt,kt.download=`export-${new Date().toISOString().slice(0,10)}.csv`,kt.click(),URL.revokeObjectURL(vt)}},[Fe,h,W,O]);n.useEffect(()=>{if(!nt)return;const v=()=>it(null);return document.addEventListener("click",v),()=>document.removeEventListener("click",v)},[nt]),k.useGridFocus(Ye,{pageSize:10});const Qt=n.useRef(null);k.useRovingFocus(Qt,{orientation:"vertical",pageSize:10});const At=ce||Vt,qt=!At&&ht.length===0,Yt=N&&xe,wt=Mt("nice-module-grid",`nice-module-grid--${P}`,`nice-module-grid--${De}`,R&&"nice-module-grid--striped",_&&"nice-module-grid--bordered",_e&&"nice-module-grid--hoverable",At&&"nice-module-grid--loading",Yt&&"nice-module-grid--mobile",Q);return e.jsxs("div",{ref:a,id:Ee,"data-testid":Ke,className:wt,style:ye,"aria-busy":At,children:[e.jsxs("div",{className:"nice-module-grid__toolbar",children:[e.jsx("div",{className:"nice-module-grid__toolbar-search",children:e.jsx("input",{type:"search",className:"nice-module-grid__search-input",placeholder:T??ae("moduleGrid.searchPlaceholder","Search…"),value:ut,onChange:v=>Ft(v.target.value),"aria-label":ae("moduleGrid.searchAriaLabel","Search")})}),ie,Le&&e.jsx("div",{className:"nice-module-grid__toolbar-export",children:Ne.map(v=>e.jsx("button",{className:"nice-module-grid__export-btn",onClick:()=>Lt(v),"aria-label":ae(`moduleGrid.export.${v}`,`Export to ${v.toUpperCase()}`),children:v.toUpperCase()},v))})]}),e.jsx("div",{ref:Be,className:"nice-module-grid__container",onScroll:F?Je:void 0,children:Yt?e.jsx("div",{ref:Qt,className:"nice-module-grid__mobile-list",role:"listbox","aria-label":et,"aria-labelledby":tt,"aria-describedby":ke,"aria-multiselectable":fe==="checkbox"||void 0,children:At&&Se?Array.from({length:rt},(v,se)=>e.jsxs("div",{className:"nice-module-grid__mobile-card nice-module-grid__mobile-card--skeleton",children:[e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"60%",height:20}}),e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"40%",height:14}}),e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"80%",height:14}})]},se)):qt?e.jsxs("div",{className:"nice-module-grid__empty",children:[w?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:w.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:w?.title||ae("moduleGrid.noData","No data")}),w?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:w.description}),w?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:w.action.onClick,children:[w.action.icon,w.action.label]})]}):ht.map((v,se)=>{const pe=String(xt(v,l));return e.jsx(Ma,{row:v,index:yt+se,columns:W,primaryField:je,secondaryField:Oe,customRender:oe,selected:h.has(pe),locale:Z,onClick:()=>{fe!=="none"&&Bt(pe,v),ue?.(v,yt+se)},t:ae},pe)})}):e.jsxs("div",{ref:Ye,className:"nice-module-grid__table",role:"grid","aria-label":et,"aria-labelledby":tt,"aria-describedby":ke,"aria-rowcount":G,"aria-colcount":W.length,children:[e.jsxs("div",{className:"nice-module-grid__header",role:"row",children:[fe==="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===ht.length,onChange:()=>{if(h.size===ht.length)ge?.(new Set,[]),Ce(new Set);else{const v=new Set(ht.map(se=>String(xt(se,l))));ge?.(v,ht),Ce(v)}},"aria-label":ae("moduleGrid.selectAll","Select all")})}),W.map(v=>e.jsx(Ca,{column:{...v,width:jt[v.field]||v.width},sort:at.find(se=>se.field===v.field),onSort:c?Rt:void 0,onResize:Me?cn:void 0,resizable:Me,t:ae},v.field))]}),e.jsx("div",{className:"nice-module-grid__body",style:F?{height:Pe,position:"relative"}:void 0,children:At&&Se?Array.from({length:rt},(v,se)=>e.jsx(Ea,{columns:W},se)):qt?e.jsxs("div",{className:"nice-module-grid__empty",children:[w?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:w.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:w?.title||ae("moduleGrid.noData","No data")}),w?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:w.description}),w?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:w.action.onClick,children:[w.action.icon,w.action.label]})]}):e.jsx("div",{style:F?{transform:`translateY(${Ve}px)`}:void 0,children:ht.map((v,se)=>{const pe=String(xt(v,l)),Ie=yt+se,st=h.has(pe),vt=typeof M=="function"?M(v,Ie):M,kt=typeof le=="function"?le(v,Ie):le;return e.jsxs("div",{className:Mt("nice-module-grid__row",st&&"nice-module-grid__row--selected",vt),style:{...kt,height:Ae},role:"row","aria-rowindex":Ie+1,"aria-selected":st,onClick:()=>{fe!=="none"&&Bt(pe,v),ue?.(v,Ie)},onDoubleClick:()=>be?.(v,Ie),onContextMenu:mt=>St(mt,v),children:[fe==="checkbox"&&e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--checkbox",role:"gridcell",children:e.jsx("input",{type:"checkbox",checked:st,onChange:()=>Bt(pe,v),onClick:mt=>mt.stopPropagation(),"aria-label":ae("moduleGrid.selectRow","Select row")})}),W.map(mt=>e.jsx(Ia,{column:{...mt,width:jt[mt.field]||mt.width},row:v,rowIndex:Ie,value:xt(v,mt.field),locale:Z},mt.field))]},pe)})})})]})}),V&&G>0&&e.jsx(Da,{page:ft,pageSize:u,totalRows:D?Dt:p.length,pageSizeOptions:I,onPageChange:zt,t:ae}),nt&&we&&e.jsx("div",{ref:Ct,className:"nice-module-grid__context-menu",style:{left:nt.x,top:nt.y},role:"menu",children:we.filter(v=>typeof v.hidden=="function"?!v.hidden(nt.row):!v.hidden).map(v=>{if(v.divider)return e.jsx("div",{className:"nice-module-grid__context-menu-divider"},v.key);const se=typeof v.disabled=="function"?v.disabled(nt.row):v.disabled;return e.jsxs("button",{className:Mt("nice-module-grid__context-menu-item",v.danger&&"nice-module-grid__context-menu-item--danger",se&&"nice-module-grid__context-menu-item--disabled"),onClick:()=>{se||(v.onClick?.(nt.row),$t(v.key))},disabled:se,role:"menuitem",children:[v.icon&&e.jsx("span",{className:"nice-module-grid__context-menu-icon",children:v.icon}),v.label]},v.key)})}),At&&!Se&&e.jsx("div",{className:"nice-module-grid__loading-overlay",children:e.jsx("div",{className:"nice-module-grid__spinner","aria-label":ae("moduleGrid.loading","Loading")})})]})}const Aa=n.forwardRef(Ra),_t={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},Ta=()=>e.jsxs("svg",{..._t,children:[e.jsx("path",{d:"M3 7v6h6"}),e.jsx("path",{d:"M21 17a9 9 0 0 0-15-6.7L3 13"})]}),za=()=>e.jsxs("svg",{..._t,children:[e.jsx("path",{d:"M21 7v6h-6"}),e.jsx("path",{d:"M3 17a9 9 0 0 1 15-6.7L21 13"})]}),$a=()=>e.jsxs("svg",{..._t,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"})]}),La=()=>e.jsxs("svg",{..._t,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"})]}),Pa=()=>e.jsxs("svg",{..._t,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"})]}),Oa=()=>e.jsxs("svg",{..._t,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"})]}),Fa=()=>e.jsxs("svg",{..._t,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"})]}),Va=()=>e.jsxs("svg",{..._t,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"})]}),Ka=()=>e.jsxs("svg",{..._t,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"})]}),Ba=()=>e.jsx("svg",{..._t,children:e.jsx("polyline",{points:"6 9 12 4 18 9"})}),Ua=()=>e.jsx("svg",{..._t,children:e.jsx("polyline",{points:"6 15 12 20 18 15"})}),Ga=()=>e.jsxs("svg",{..._t,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 9 12 4 18 9"}),e.jsx("polyline",{points:"6 15 12 20 18 15"})]}),Wa=()=>e.jsxs("svg",{..._t,children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),Qa=()=>e.jsxs("svg",{..._t,children:[e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),e.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"})]});function ii(t){let a="",s=t;for(;s>=0;)a=String.fromCharCode(65+s%26)+a,s=Math.floor(s/26)-1;return a}function Te(t,a){return`${ii(a)}${t+1}`}function Ze(t){const a=t.match(/^([A-Z]+)(\d+)$/);if(!a)return null;let s=0;for(let r=0;r<a[1].length;r++)s=s*26+(a[1].charCodeAt(r)-64);return{row:parseInt(a[2],10)-1,col:s-1}}function qa(t,a,s=new Set){const r=t.startsWith("=")?t.slice(1).trim():t,l=(g,x)=>{if(!g||!x)return[];const I=[];for(let b=g.row;b<=x.row;b++)for(let z=g.col;z<=x.col;z++){const S=He(Te(b,z),a,new Set(s));typeof S=="number"&&I.push(S)}return I},o=(g,x)=>{if(!g||!x)return[];const I=[];for(let b=g.row;b<=x.row;b++)for(let z=g.col;z<=x.col;z++)I.push(He(Te(b,z),a,new Set(s)));return I},d=r.match(/^(\w+)\(([A-Z]+\d+):([A-Z]+\d+)\)$/i);if(d){const g=d[1].toUpperCase(),x=Ze(d[2].toUpperCase()),I=Ze(d[3].toUpperCase());switch(g){case"SUM":return l(x,I).reduce((z,S)=>z+S,0);case"AVG":case"AVERAGE":{const b=l(x,I);return b.length>0?b.reduce((z,S)=>z+S,0)/b.length:0}case"COUNT":return l(x,I).length;case"COUNTA":return o(x,I).filter(b=>b!==null&&b!=="").length;case"COUNTBLANK":return o(x,I).filter(b=>b===null||b==="").length;case"MIN":{const b=l(x,I);return b.length?Math.min(...b):0}case"MAX":{const b=l(x,I);return b.length?Math.max(...b):0}case"MEDIAN":{const b=l(x,I).sort((S,U)=>S-U);if(!b.length)return 0;const z=Math.floor(b.length/2);return b.length%2?b[z]:(b[z-1]+b[z])/2}case"STDEV":{const b=l(x,I);if(b.length<2)return 0;const z=b.reduce((S,U)=>S+U,0)/b.length;return Math.sqrt(b.reduce((S,U)=>S+(U-z)**2,0)/(b.length-1))}case"PRODUCT":{const b=l(x,I);return b.length?b.reduce((z,S)=>z*S,1):0}}}const c=r.match(/^(SUMIF|COUNTIF)\(([A-Z]+\d+):([A-Z]+\d+)\s*,\s*"?([^"]*)"?\)$/i);if(c){const g=c[1].toUpperCase(),x=Ze(c[2].toUpperCase()),I=Ze(c[3].toUpperCase()),b=c[4];if(x&&I){let z=0;for(let S=x.row;S<=I.row;S++)for(let U=x.col;U<=I.col;U++){const H=He(Te(S,U),a,new Set(s));(b.startsWith(">")?Number(H)>Number(b.slice(1)):b.startsWith("<")?Number(H)<Number(b.slice(1)):String(H)===b||typeof H=="number"&&H===Number(b))&&(z+=g==="SUMIF"?typeof H=="number"?H:0:1)}return z}}const f=r.match(/^IF\(([^,]+),\s*([^,]+),\s*([^)]+)\)$/i);if(f){const g=f[1].trim(),x=f[2].trim(),I=f[3].trim(),b=g.match(/^([A-Z]+\d+)\s*([><=!]+)\s*(\S+)$/i);let z=!1;if(b){const H=He(b[1].toUpperCase(),a,new Set(s)),fe=isNaN(Number(b[3]))?b[3].replace(/^"|"$/g,""):Number(b[3]),re=b[2],ge=typeof H=="number"?H:Number(H)||0,Me=typeof fe=="number"?fe:Number(fe)||0;switch(re){case">":z=ge>Me;break;case"<":z=ge<Me;break;case">=":z=ge>=Me;break;case"<=":z=ge<=Me;break;case"=":case"==":z=ge===Me;break;case"<>":case"!=":z=ge!==Me;break}}const S=z?x:I;if(Ze(S.toUpperCase()))return He(S.toUpperCase(),a,new Set(s));const U=Number(S);return isNaN(U)?S.replace(/^"|"$/g,""):U}const m=r.match(/^CONCAT\((.+)\)$/i);if(m)return m[1].split(",").map(x=>x.trim()).map(x=>{if(x.startsWith('"')&&x.endsWith('"'))return x.slice(1,-1);if(Ze(x.toUpperCase())){const b=He(x.toUpperCase(),a,new Set(s));return b!==null?String(b):""}return x}).join("");const j=r.match(/^VLOOKUP\(([^,]+),\s*([A-Z]+\d+):([A-Z]+\d+),\s*(\d+)\)$/i);if(j){let g;Ze(j[1].trim().toUpperCase())?g=He(j[1].trim().toUpperCase(),a,new Set(s)):g=isNaN(Number(j[1]))?j[1].replace(/^"|"$/g,""):Number(j[1]);const I=Ze(j[2].toUpperCase()),b=Ze(j[3].toUpperCase()),z=parseInt(j[4])-1;if(I&&b)for(let S=I.row;S<=b.row;S++){const U=He(Te(S,I.col),a,new Set(s));if(String(U)===String(g))return He(Te(S,I.col+z),a,new Set(s))}return null}const E=r.match(/^(ABS|ROUND|FLOOR|CEIL|CEILING|SQRT|LEN|UPPER|LOWER|TRIM|INT)\(([^)]+)\)$/i);if(E){const g=E[1].toUpperCase(),x=E[2].trim();let I;switch(Ze(x.toUpperCase())?I=He(x.toUpperCase(),a,new Set(s)):I=isNaN(Number(x))?x.replace(/^"|"$/g,""):Number(x),g){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=r.match(/^POWER\(([^,]+),\s*([^)]+)\)$/i);if(L){const g=Number(Ze(L[1].trim().toUpperCase())?He(L[1].trim().toUpperCase(),a,new Set(s)):L[1].trim())||0,x=Number(Ze(L[2].trim().toUpperCase())?He(L[2].trim().toUpperCase(),a,new Set(s)):L[2].trim())||0;return Math.pow(g,x)}if(/^NOW\(\)$/i.test(r))return new Date().toISOString();if(/^TODAY\(\)$/i.test(r))return new Date().toISOString().split("T")[0];if(/^PI\(\)$/i.test(r))return Math.PI;const A=r.match(/^([A-Z]+\d+)$/i);if(A)return He(A[1].toUpperCase(),a,s);const T=r.match(/^([A-Z]+\d+)\s*([+\-*/])\s*([A-Z]+\d+|\d+\.?\d*)$/i);if(T){const g=T[1].toUpperCase(),x=T[2],I=T[3],b=He(g,a,s),S=Ze(I.toUpperCase())?He(I.toUpperCase(),a,s):parseFloat(I),U=typeof b=="number"?b:0,H=typeof S=="number"?S:0;switch(x){case"+":return U+H;case"-":return U-H;case"*":return U*H;case"/":return H!==0?U/H:null}}const V=parseFloat(r);return isNaN(V)?r:V}function He(t,a,s){if(s.has(t))return null;s.add(t);const r=a[t];return r?r.formula?qa(r.formula,a,s):r.value:null}function Yn(t,a){return t==null?"":a==="percent"&&typeof t=="number"?`${(t*100).toFixed(1)}%`:a==="currency"&&typeof t=="number"?`$${t.toFixed(2)}`:String(t)}function Hn(t){return{name:t,data:{}}}const Ya=Object.assign(n.forwardRef(({sheets:t,activeSheet:a,rows:s=50,cols:r=26,showToolbar:l=!0,showFormulaBar:o=!0,showSheetTabs:d=!0,readOnly:c=!1,disabled:f=!1,loading:m=!1,error:j,size:E="md",onChange:L,onActiveSheetChange:A,onCellSelect:T,onCopy:V,onPaste:g,onInsert:x,onRemove:I,maxUndo:b=50,sortable:z=!1,filterable:S=!1,rangeSelection:U=!0,className:H,style:fe,id:re,...ge},Me)=>{const J=c||f,we=k.useControlId(re),{t:K}=k.useNiceTranslation(),[Le,Ne]=n.useState(()=>t??[Hn(K("spreadsheet.sheet","Sheet")+" 1")]),[Fe,X]=n.useState(0),$=t??Le,P=a??Fe,R=$[P]??$[0],[_,_e]=n.useState(null),[ce,w]=n.useState(null),[ie,ue]=n.useState(!1),[be,M]=n.useState(null),[le,xe]=n.useState(""),ze=n.useRef(null),oe=n.useRef(null),[je,Oe]=n.useState([]),[De,Se]=n.useState([]),[rt,et]=n.useState(null),tt=n.useRef({x:0,width:80}),[ke,Q]=n.useState(null),[ye,Ee]=n.useState(null),Ke=n.useRef(null);k.useRovingFocus(Ke,{orientation:"horizontal",wrap:!0,activateOnMove:!0});const[Ae,ae]=n.useState("");n.useEffect(()=>{be&&ze.current&&ze.current.focus()},[be]);const Z=n.useMemo(()=>{if(!_)return null;const u=ce??_;return{startRow:Math.min(_.row,u.row),startCol:Math.min(_.col,u.col),endRow:Math.max(_.row,u.row),endCol:Math.max(_.col,u.col)}},[_,ce]),N=n.useCallback((u,h)=>Z?u>=Z.startRow&&u<=Z.endRow&&h>=Z.startCol&&h<=Z.endCol:!1,[Z]),ve=n.useCallback(u=>{Oe(h=>{const D=[...h,u.map(G=>({...G,data:{...G.data}}))];return D.length>b?D.slice(-b):D}),Se([])},[b]),ee=n.useCallback((u,h=!0)=>{h&&ve($);const D=u($);t||Ne(D),L?.(D)},[$,t,L,ve]),Be=n.useCallback(()=>{if(je.length===0)return;const u=je[je.length-1];Se(h=>[...h,$.map(D=>({...D,data:{...D.data}}))]),Oe(h=>h.slice(0,-1)),t||Ne(u),L?.(u)},[je,$,t,L]),Ye=n.useCallback(()=>{if(De.length===0)return;const u=De[De.length-1];Oe(h=>[...h,$.map(D=>({...D,data:{...D.data}}))]),Se(h=>h.slice(0,-1)),t||Ne(u),L?.(u)},[De,$,t,L]),de=n.useCallback(u=>{a||X(u),A?.(u),_e(null),w(null),M(null)},[a,A]),Qe=n.useCallback((u,h,D)=>{const G=Te(u,h);ee(W=>{const p=W.map((te,F)=>F===P?{...te,data:{...te.data}}:te),O=D.startsWith("=");return p[P].data[G]={...p[P].data[G]??{value:null},formula:O?D:void 0,value:O?null:isNaN(Number(D))?D:Number(D)},p})},[P,ee]),C=n.useCallback((u,h,D)=>{D?.shiftKey&&U&&_?w({row:u,col:h}):(_e({row:u,col:h}),w(null)),M(null),T?.(P,u,h)},[P,T,U,_]),Y=n.useCallback((u,h,D)=>{D.button===0&&(C(u,h,D),U&&!D.shiftKey&&ue(!0))},[C,U]),me=n.useCallback((u,h)=>{ie&&w({row:u,col:h})},[ie]);n.useEffect(()=>{if(!ie)return;const u=()=>ue(!1);return document.addEventListener("mouseup",u),()=>document.removeEventListener("mouseup",u)},[ie]);const $e=n.useCallback((u,h)=>{if(J)return;const D=Te(u,h),G=R.data[D];G?.readOnly||(M({row:u,col:h}),xe(G?.formula??(G?.value!=null?String(G.value):"")))},[J,R.data]),qe=n.useCallback(()=>{be&&(Qe(be.row,be.col,le),M(null))},[be,le,Qe]),q=n.useCallback(u=>{if(u.key==="Enter")qe();else if(u.key==="Escape")M(null);else if(u.key==="Tab"&&be&&(u.preventDefault(),qe(),_)){const h=u.shiftKey?Math.max(0,_.col-1):Math.min(r-1,_.col+1);_e({row:_.row,col:h})}},[qe,_,r,be]),Re=n.useCallback((u,h)=>{if(!_)return;const D=Z??{startRow:_.row,startCol:_.col,endRow:_.row,endCol:_.col};ee(G=>{const W=G.map((p,O)=>O===P?{...p,data:{...p.data}}:p);for(let p=D.startRow;p<=D.endRow;p++)for(let O=D.startCol;O<=D.endCol;O++){const te=Te(p,O);W[P].data[te]={...W[P].data[te]??{value:null},[u]:h}}return W})},[_,Z,P,ee]),ct=n.useCallback(u=>{if(!Z||V?.(Z)===!1)return;const{startRow:h,startCol:D,endRow:G,endCol:W}=Z,p=[];for(let O=h;O<=G;O++){const te=[];for(let F=D;F<=W;F++){const he=Te(O,F),Pe=R.data[he],Ve=Pe?He(he,R.data,new Set):null;te.push(Yn(Ve,Pe?.format))}p.push(te.join(" "))}u.clipboardData.setData("text/plain",p.join(`
|
|
5
|
+
Return a JSON array of insight strings. Be specific with numbers and trends.`}],{temperature:.3,maxTokens:500});try{const _=JSON.parse(R.content),_e=Array.isArray(_)?_:[];return b(_e),f?.(_e),_e}catch{return[]}}catch{return[]}},[we,o,L,E,ge,f]),$=R=>{R.preventDefault(),T.trim()&&Le(T)},P=R=>{V(R),Le(R)};return n.useImperativeHandle(a,()=>({applyNLFilter:Le,clearAIFilters:Ne,getAIFilters:Fe,generateInsights:X})),e.jsxs("div",{className:"nice-data-grid-ai","data-testid":t["data-testid"],children:[m&&we&&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:$,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(k.NiceIcon,{name:"search",size:14})}),e.jsx("input",{ref:fe,type:"text",value:T,onChange:R=>V(R.target.value),placeholder:d||re("dataGridAI.searchPlaceholder","Search with natural language..."),className:"nice-data-grid-ai__input",disabled:J}),J&&e.jsx("span",{className:"nice-data-grid-ai__loading-spinner"}),T&&!J&&e.jsx("button",{type:"button",className:"nice-data-grid-ai__clear-input",onClick:()=>V(""),"aria-label":re("dataGridAI.clearInput","Clear"),children:e.jsx(k.NiceIcon,{name:"close",size:14})})]}),e.jsx("button",{type:"submit",className:"nice-data-grid-ai__search-btn",disabled:J||!T.trim(),children:J?re("dataGridAI.searching","Searching..."):re("dataGridAI.search","Search")})]}),o&&e.jsxs("button",{type:"button",className:"nice-data-grid-ai__insights-btn",onClick:()=>{X(),S(!0)},disabled:J||!L?.length,title:re("dataGridAI.generateInsights","Generate AI Insights"),children:[e.jsx(k.NiceIcon,{name:"lightbulb",size:14})," ",re("dataGridAI.insights","Insights")]})]}),m&&we&&l&&!U&&j.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:j.slice(0,4).map((R,_)=>e.jsxs("button",{type:"button",className:"nice-data-grid-ai__example",onClick:()=>P(R),children:['"',R,'"']},_))})]}),U&&g.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(k.NiceIcon,{name:"target",size:14})}),e.jsxs("span",{className:"nice-data-grid-ai__filter-query",children:['"',U,'"']}),e.jsxs("span",{className:"nice-data-grid-ai__filter-count",children:["(",K?.length||0," ",re("dataGridAI.results","results"),")"]})]}),e.jsx("div",{className:"nice-data-grid-ai__filter-badges",children:g.map((R,_)=>e.jsxs("span",{className:"nice-data-grid-ai__filter-badge",children:[R.field," ",R.operator," ",String(R.value)]},_))}),e.jsxs("button",{type:"button",className:"nice-data-grid-ai__clear-filter",onClick:Ne,children:[e.jsx(k.NiceIcon,{name:"close",size:14})," ",re("dataGridAI.clearFilter","Clear")]})]}),e.jsx("div",{className:"nice-data-grid-ai__grid-wrapper",children:e.jsx(yi.NiceDataGrid,{columns:E,data:K,...A})}),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(k.NiceIcon,{name:"lightbulb",size:14})," ",re("dataGridAI.aiInsights","AI Insights")]}),e.jsx("button",{type:"button",className:"nice-data-grid-ai__insights-close",onClick:()=>S(!1),"aria-label":re("dataGridAI.closeInsights","Close"),children:e.jsx(k.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-data-grid-ai__insights-body",children:J?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((R,_)=>e.jsxs("li",{className:"nice-data-grid-ai__insight",children:[e.jsx("span",{className:"nice-data-grid-ai__insight-bullet",children:"•"}),R]},_))}):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:()=>X(),disabled:J,children:[e.jsx(k.NiceIcon,{name:"refresh",size:14})," ",re("dataGridAI.refresh","Refresh")]})})]})]})}const Mi=n.forwardRef(Ii);function Di(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const wn=({text:t,query:a,highlightTag:s="mark",highlightClassName:r="",caseSensitive:l=!1,className:o="",style:d,testId:c,"data-testid":f})=>{const m=(Array.isArray(a)?a:[a]).map(A=>(A??"").trim()).filter(Boolean).map(Di);if(m.length===0||!t)return e.jsx("span",{className:`nice-highlight ${o}`,style:d,"data-testid":f??c,children:t});const j=l?"g":"gi",E=new RegExp(`(${m.join("|")})`,j),L=t.split(E);return e.jsx("span",{className:`nice-highlight ${o}`,style:d,"data-testid":f??c,children:L.map((A,T)=>T%2===1?e.jsx(s,{className:`nice-highlight__mark ${r}`.trim(),children:A},T):e.jsx(n.Fragment,{children:A},T))})};process.env.NODE_ENV!=="production"&&(wn.displayName="NiceHighlight");function Ei(t,a,s,r=0){const l=new Map,o=[];t.forEach(c=>l.set(String(c[a]),{data:c,children:[],key:String(c[a]),depth:0})),t.forEach(c=>{const f=c[s],m=l.get(String(c[a]));if(f!=null&&f!==""&&l.has(String(f))){const j=l.get(String(f));m.depth=j.depth+1,j.children.push(m)}else o.push(m)});const d=(c,f)=>{c.forEach(m=>{m.depth=f,d(m.children,f+1)})};return d(o,r),o}function Ri(t,a,s){const r=l=>l.map(o=>{const d=o.children.length===0?a.get(o.key):void 0,c=d?s(d,o.depth+1):o.children;return c.length>0?{...o,children:r(c)}:o});return r(t)}function Ai(t,a){const s=[],r=l=>{a(l)&&s.push(l.key),l.children.forEach(r)};return r(t),s}function Zn(t,a,s,r=0){return t.map(l=>({data:l,key:String(l[s]),depth:r,children:Array.isArray(l[a])?Zn(l[a],a,s,r+1):[]}))}function kn(t){const a=[],s=r=>{r.forEach(l=>{l.children.length>0&&(a.push(l.key),s(l.children))})};return s(t),a}function Ti(t){const a=[],s=r=>{r.forEach(l=>{a.push(l.key),s(l.children)})};return s(t),a}function Jn(t,a,s){return!a||!s?t:[...t].sort((l,o)=>{const d=l.data[a]??"",c=o.data[a]??"",f=typeof d=="number"&&typeof c=="number"?d-c:String(d).localeCompare(String(c));return s==="desc"?-f:f}).map(l=>({...l,children:Jn(l.children,a,s)}))}function zi(t,a,s){const r=new Set,l=new Set,o=d=>d.reduce((c,f)=>{const m=o(f.children),j=a(f);return j&&l.add(f.key),m.length>0&&r.add(f.key),j&&s?c.push(f):(j||m.length>0)&&c.push({...f,children:m}),c},[]);return{tree:o(t),expand:r,matched:l}}function $i(t,a){const s=(r,l)=>r.reduce((o,d)=>{if(l)return o.push({...d,children:s(d.children,!0)}),o;if(a.isCheckable(d.key)){const f=a.state(d.key);if(f!=="unchecked"){const m=a.isLeaf(d.key)&&f==="checked";o.push({...d,children:s(d.children,m)})}return o}const c=s(d.children,!1);return c.length>0&&o.push({...d,children:c}),o},[]);return s(t,!1)}function Li(t,a,s){const r=[],l=(o,d)=>{o.forEach((c,f)=>{if(r.push({node:c,level:d,posInSet:f+1,setSize:o.length}),c.children.length>0)a(c.key)&&l(c.children,d+1);else if(s&&a(c.key)){const m=s(c);m&&r.push({node:c,level:d+1,posInSet:1,setSize:1,placeholder:m})}})};return l(t,1),r}function jn(t,a,s={}){const{getKey:r,getChildren:l,isCheckable:o,isDisabled:d}=a,c=s.inheritDisabled!==!1,f=[],m=[],j=[],E=new Map,L=(T,V,g,x)=>{const I=r(T);if(E.has(I))return;const b=o?o(T):!0,z=(d?d(T):!1)||c&&x,S={pos:f.length,subtreeEnd:0,leafStart:m.length,leafEnd:0,checkable:b,leaf:!1,disabled:z,parent:g};E.set(I,S),f.push(I);const U=l(T,V);if(U)for(const H of U)L(H,V+1,I,z);b&&m.length===S.leafStart&&(S.leaf=!0,m.push(I),j.push(z)),S.leafEnd=m.length,S.subtreeEnd=f.length};for(const T of t)L(T,0,void 0,!1);const A=new Int32Array(m.length+1);for(let T=0;T<m.length;T++)A[T+1]=A[T]+(j[T]?1:0);return{keys:f,leaves:m,records:E,lockedBefore:A,has:T=>E.has(T),isCheckable:T=>E.get(T)?.checkable??!1,isLeaf:T=>E.get(T)?.leaf??!1,isLocked:T=>{const V=E.get(T);if(!V)return!1;const g=V.leafEnd-V.leafStart;return V.disabled||g===0?V.disabled:A[V.leafEnd]-A[V.leafStart]===g},leavesOf:T=>{const V=E.get(T);return V?m.slice(V.leafStart,V.leafEnd):[]},parentOf:T=>E.get(T)?.parent}}function Sn(t,a){const s=new Set,r=[];if(!a)return{leaves:s,unknown:r};const l=new Set;for(const o of a){const d=t.records.get(o);if(!d){l.has(o)||(l.add(o),r.push(o));continue}if(d.checkable)for(let c=d.leafStart;c<d.leafEnd;c++)s.add(t.leaves[c])}return{leaves:s,unknown:r}}function sn(t,a){const s=new Int32Array(t.leaves.length+1);for(let d=0;d<t.leaves.length;d++)s[d+1]=s[d]+(a.has(t.leaves[d])?1:0);const r=d=>{const c=t.records.get(d);return c?{checked:s[c.leafEnd]-s[c.leafStart],total:c.leafEnd-c.leafStart}:{checked:0,total:0}},l=d=>{const{checked:c,total:f}=r(d);return c===0||f===0?"unchecked":c===f?"checked":"indeterminate"},o=[];for(const d of t.keys){const c=t.records.get(d);c.checkable&&!c.leaf&&l(d)==="indeterminate"&&o.push(d)}return{state:l,count:r,total:{checked:s[t.leaves.length],total:t.leaves.length},halfChecked:o}}function Cn(t,a,s,r){const l=t.records.get(s);if(!l||!l.checkable)return a;const o=[];for(let c=l.leafStart;c<l.leafEnd;c++)t.lockedBefore[c+1]===t.lockedBefore[c]&&o.push(t.leaves[c]);if(o.length===0)return a;const d=!o.every(c=>a.has(c));return ei(a,o,d)}function Gn(t,a,s,r){const l=[];for(const o of s){const d=t.records.get(o);d?.leaf&&!d.disabled&&l.push(o)}return l.length===0?a:ei(a,l,r)}function ei(t,a,s){const r=new Set(t);for(const l of a)s?r.add(l):r.delete(l);return r}function Zt(t,a,s,r=[]){const l=[];if(s==="leaves")for(const o of t.leaves)a.has(o)&&l.push(o);else{const o=new Int32Array(t.leaves.length+1);for(let c=0;c<t.leaves.length;c++)o[c+1]=o[c]+(a.has(t.leaves[c])?1:0);const d=c=>c.leafEnd>c.leafStart&&o[c.leafEnd]-o[c.leafStart]===c.leafEnd-c.leafStart;for(let c=0;c<t.keys.length;){const f=t.keys[c],m=t.records.get(f);if(m.checkable&&d(m)&&(l.push(f),s==="parents")){c=m.subtreeEnd;continue}c++}}for(const o of r)l.push(o);return l}const Pi=[],Oi=[],Nn=[],Fi=new Set,Vi=new Map,Ki=[],Bi=new Map,Ui=new Map,Wn=["expandAll","collapseAll","onlyChecked","clearChecked"],Qn=10;function Gi({node:t,level:a,posInSet:s,setSize:r,rowIndex:l,ariaRowIndex:o,columns:d,highlight:c,query:f,expandable:m,expanded:j,busy:E,expandLabel:L,collapseLabel:A,subtreeAction:T,subtreeLabel:V,checkMode:g,hasCheckbox:x,checkState:I,checkLabel:b,locked:z,countChecked:S,countTotal:U,countTitle:H,selectColumn:fe,selected:re,selectLabel:ge,readOnly:Me,className:J,clickable:we,height:K,handlers:Le}){const Ne=x?e.jsx("input",{type:"checkbox",className:"nice-treegrid__check-input",checked:I==="checked",ref:X=>{X&&(X.indeterminate=I==="indeterminate")},disabled:z||Me,tabIndex:-1,"aria-label":b,onClick:X=>X.stopPropagation(),onChange:X=>{Le.toggleCheck(t.key),X.currentTarget.closest("tr")?.focus({preventScroll:!0})}}):null,Fe=["nice-treegrid__row",g!=="none"&&!x?"nice-treegrid__row--info":"",z?"nice-treegrid__row--disabled":"",x&&I==="checked"?"nice-treegrid__row--checked":"",re?"nice-datagrid__row--selected":"",J??""].filter(Boolean).join(" ");return e.jsxs("tr",{className:Fe,"data-key":t.key,tabIndex:-1,"aria-level":a,"aria-posinset":s,"aria-setsize":r,"aria-rowindex":o,"aria-expanded":m?j:void 0,"aria-selected":re,"aria-disabled":z||void 0,"aria-busy":E||void 0,onClick:()=>Le.rowClick(t),style:we||K!==void 0?{cursor:we?"pointer":void 0,height:K}:void 0,children:[g==="column"&&e.jsx("td",{className:"nice-datagrid__checkbox nice-treegrid__check-cell",children:Ne}),fe&&e.jsx("td",{className:"nice-datagrid__checkbox",children:e.jsx("input",{type:"checkbox",checked:!!re,onChange:()=>Le.toggleSelected(t.key),onClick:X=>X.stopPropagation(),disabled:Me,tabIndex:-1,"aria-label":ge})}),d.map((X,$)=>{const P=t.data[X.field];return e.jsxs("td",{style:{textAlign:X.align},children:[$===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 ${m?"":"nice-treegrid__toggle--leaf"}`,onClick:R=>{R.stopPropagation(),m&&Le.toggleExpand(t.key,R.altKey||R.shiftKey)},tabIndex:-1,"aria-hidden":m?void 0:!0,"aria-label":m?j?A:L:void 0,children:m?e.jsx(k.NiceIcon,{name:j?"chevron-down":"chevron-right",size:12}):""}),g==="tree"&&e.jsx("span",{className:`nice-treegrid__check${x?"":" nice-treegrid__check--none"}`,children:Ne})]}),X.render?X.render(P,t.data,l):c[$]&&f?e.jsx(wn,{text:String(P??""),query:f,highlightClassName:"nice-treegrid__match"}):String(P??""),$===0&&U>0&&e.jsxs("span",{className:`nice-treegrid__count${S===U?" nice-treegrid__count--full":""}`,title:H,children:[S,"/",U]}),$===0&&T&&e.jsx("button",{type:"button",className:"nice-treegrid__row-action",tabIndex:-1,"aria-label":V,title:V,onClick:R=>{R.stopPropagation(),Le.setSubtreeExpanded(t.key,T==="expand")},children:e.jsx(k.NiceIcon,{name:T==="expand"?"expand":"collapse",size:12})})]},X.field)})]})}const Wi=n.memo(Gi);function Qi({columns:t=Pi,data:a=Oi,keyField:s="id",parentKeyField:r="parentId",nested:l=!1,childrenField:o="children",expandedKeys:d,defaultExpandedKeys:c,onExpandedChange:f,hasChildren:m,loadChildren:j,rowActions:E,defaultExpandAll:L=!1,sortable:A=!0,sortField:T,sortDirection:V,onSort:g,selectable:x,selectedKeys:I,onSelectionChange:b,checkable:z,checkedKeys:S,defaultCheckedKeys:U,onCheckedChange:H,checkStrategy:fe="all",isRowCheckable:re,isRowDisabled:ge,checkboxPlacement:Me="tree",checkOnRowClick:J,showCheckedCount:we,checkedSummary:K,showSelectAll:Le=!0,showOnlyChecked:Ne,defaultShowOnlyChecked:Fe,onShowOnlyCheckedChange:X,toolbarActions:$,searchable:P,searchPlaceholder:R,searchText:_,defaultSearchText:_e,onSearchChange:ce,searchFields:w,searchFilter:ie,searchKeepDescendants:ue=!1,searchAutoExpand:be=!0,highlightMatches:M=!0,rowClassName:le,getRowLabel:xe,virtualScroll:ze,rowHeight:oe=36,height:je,striped:Oe,compact:De,size:Se="md",loading:rt,disabled:et,readOnly:tt,error:ke,emptyText:Q,toolbar:ye,onRowClick:Ee,contextMenuItems:Ke,className:Ae,style:ae,id:Z,testId:N,"data-testid":ve,accessMode:ee,"aria-label":Be,"aria-labelledby":Ye}){const{t:de}=k.useNiceTranslation(),Qe=k.useNiceAccessMode(ee,Z),C=!!et||Qe==="disabled",Y=!!tt||Qe==="readOnly",me=n.useCallback((i,y)=>l?Zn(i,o,s,y):Ei(i,s,r,y),[s,r,l,o]),$e=n.useMemo(()=>me(a,0),[me,a]),[qe,q]=n.useState(Bi),[Re,ct]=n.useState(Ui),Ue=n.useMemo(()=>qe.size>0?Ri($e,qe,me):$e,[$e,qe,me]),Ce=n.useMemo(()=>{const i=new Map,y=B=>B.forEach(ne=>{i.set(ne.key,ne),y(ne.children)});return y(Ue),i},[Ue]),lt=!!m||!!j,ot=n.useCallback(i=>{if(!lt)return!1;const y=Ce.get(i);return!!y&&y.children.length===0&&!qe.has(i)&&(m?m(y.data):!0)},[lt,Ce,qe,m]),Dt=n.useRef(new Set),Pt=n.useRef(!0);n.useEffect(()=>(Pt.current=!0,()=>{Pt.current=!1}),[]);const Vt=n.useCallback(i=>{const y=Ce.get(i);if(!j||!y||Dt.current.has(i))return;Dt.current.add(i);const B=ne=>{Dt.current.delete(i),Pt.current&&(ne&&q(Ge=>new Map(Ge).set(i,ne)),ct(Ge=>{const Xe=new Map(Ge);return ne?Xe.delete(i):Xe.set(i,"error"),Xe}))};ct(ne=>new Map(ne).set(i,"loading")),j(y.data).then(ne=>B(Array.isArray(ne)?ne:[]),()=>B(null))},[j,Ce]),Kt=n.useCallback(i=>{ct(y=>{const B=new Map(y);return B.delete(i),B})},[]),Nt=n.useMemo(()=>t.filter(i=>!i.hidden),[t]),Tt=n.useMemo(()=>kn(Ue),[Ue]),[nt,it]=n.useState(null),jt=n.useMemo(()=>{if(d)return new Set(d);if(nt)return nt;const i=new Set(c??Nn);return L&&Tt.forEach(y=>i.add(y)),i},[d,nt,c,L,Tt]),Ot=n.useRef(jt);Ot.current=jt;const at=n.useCallback(i=>{Ot.current=i,d||it(i),f?.([...i])},[d,f]),[Et,ut]=n.useState({field:"",dir:null}),ft=T??Et.field,u=V??Et.dir,h=n.useCallback(i=>{const y=ft===i?u==="asc"?"desc":u==="desc"?null:"asc":"asc";g?g(i,y):ut({field:i,dir:y})},[ft,u,g]),[D,G]=k.useControllableState({value:I,fallbackValue:Fi,onChange:b,componentName:"NiceTreeGrid"}),W=n.useCallback(i=>{G(y=>{const B=new Set(y);return B.has(i)?B.delete(i):B.add(i),B})},[G]),p=n.useMemo(()=>z?jn(Ue,{getKey:i=>i.key,getChildren:i=>i.children,isCheckable:re?i=>re(i.data):void 0,isDisabled:ge?i=>ge(i.data):void 0}):null,[z,Ue,re,ge]),[O,te]=k.useControllableState({value:S,defaultValue:U,fallbackValue:Nn,componentName:"NiceTreeGrid"}),F=n.useMemo(()=>p?Sn(p,O):null,[p,O]),he=n.useMemo(()=>p&&F?sn(p,F.leaves):null,[p,F]),Pe=n.useMemo(()=>{if(typeof K!="function"||!p||!F||!he)return null;const i=Zt(p,F.leaves,"leaves"),y=[];return i.forEach(B=>{const ne=Ce.get(B);ne&&y.push(ne.data)}),{checked:he.total.checked,total:he.total.total,leafKeys:i,rows:y}},[K,p,F,he,Ce]),Ve=n.useCallback((i,y)=>{if(!p||!F||i===F.leaves)return;const B=Zt(p,i,fe,F.unknown);te(B),H?.(B,{...y,leafKeys:Zt(p,i,"leaves"),halfCheckedKeys:[...sn(p,i).halfChecked]})},[p,F,fe,te,H]),Je=n.useCallback(i=>{if(!p||!F)return;const y=Cn(p,F.leaves,i);Ve(y,{source:"row",checked:y.size>F.leaves.size,key:i,row:Ce.get(i)?.data})},[p,F,Ve,Ce]),[yt,ht]=k.useControllableState({value:_,defaultValue:_e,fallbackValue:"",onChange:ce,componentName:"NiceTreeGrid"}),dt=yt.trim(),Rt=n.useMemo(()=>w??Nt.map(i=>i.field),[w,Nt]),zt=n.useMemo(()=>{if(!dt)return null;const i=dt.toLowerCase();return zi(Ue,ie?B=>ie(B.data,dt):B=>Rt.some(ne=>String(B.data[ne]??"").toLowerCase().includes(i)),ue)},[Ue,dt,ie,Rt,ue]),Ft=zt?.tree??Ue,[Bt,cn]=k.useControllableState({value:Ne,defaultValue:Fe,fallbackValue:!1,onChange:X,componentName:"NiceTreeGrid"}),St=!!z&&Bt&&he!==null,Ct=n.useMemo(()=>St&&he&&p?$i(Ft,{state:he.state,isCheckable:p.isCheckable,isLeaf:p.isLeaf}):Ft,[St,he,p,Ft]),$t=dt!==""||St,Lt=`${dt}
|
|
6
|
+
${St?1:0}`,[Qt,At]=n.useState(()=>({key:"",map:new Map})),qt=Qt.key===Lt?Qt.map:Vi,Yt=n.useMemo(()=>{const i=new Set;return zt&&be&&zt.expand.forEach(y=>i.add(y)),St&&p&&kn(Ct).forEach(y=>{p.isLeaf(y)||i.add(y)}),i},[zt,be,St,p,Ct]),wt=n.useCallback(i=>$t?qt.get(i)??(jt.has(i)||Yt.has(i)):jt.has(i),[$t,qt,jt,Yt]),v=n.useCallback((i,y)=>{const B=Ot.current;if(i.some(ne=>B.has(ne)!==y)){const ne=new Set(B);i.forEach(Ge=>y?ne.add(Ge):ne.delete(Ge)),at(ne)}$t&&At(ne=>{const Ge=new Map(ne.key===Lt?ne.map:void 0);return i.forEach(Xe=>Ge.set(Xe,y)),{key:Lt,map:Ge}})},[at,$t,Lt]),se=n.useCallback(i=>i.children.length>0||ot(i.key),[ot]),pe=n.useRef(new Set),Ie=n.useCallback((i,y)=>{const B=i.flatMap(ne=>Ai(ne,se));B.forEach(ne=>{y?ot(ne)&&pe.current.add(ne):pe.current.delete(ne)}),v(B,y)},[se,ot,v]),st=n.useCallback((i,y)=>{const B=Ce.get(i);B&&Ie([B],y)},[Ce,Ie]),vt=n.useCallback((i,y)=>{const B=!wt(i);y?st(i,B):v([i],B)},[wt,st,v]),kt=n.useRef({nodeByKey:Ce,isPending:ot,setSubtreesExpanded:Ie});kt.current={nodeByKey:Ce,isPending:ot,setSubtreesExpanded:Ie},n.useEffect(()=>{const{nodeByKey:i,isPending:y,setSubtreesExpanded:B}=kt.current,ne=[];for(const Ge of[...pe.current]){const Xe=i.get(Ge);(!Xe||Xe.children.length>0||!y(Ge))&&(pe.current.delete(Ge),ne.push(...Xe?.children??[]))}ne.length>0&&B(ne,!0)},[Ue]);const mt=n.useCallback(i=>{i||pe.current.clear(),at(i?new Set(Tt):new Set),$t&&At({key:Lt,map:new Map(kn(Ct).map(y=>[y,i]))})},[at,Tt,$t,Lt,Ct]),en=n.useMemo(()=>Jn(Ct,ft,u),[Ct,ft,u]),In=n.useCallback(i=>ot(i.key)?Re.get(i.key)==="error"?"error":"loading":null,[ot,Re]),bt=n.useMemo(()=>Li(en,wt,lt?In:void 0),[en,wt,lt,In]),ln=E===!0||Array.isArray(E)&&E.includes("expandSubtree"),si=n.useMemo(()=>{const i=new Set;if(!ln)return i;const y=B=>{if(B.children.length===0)return!ot(B.key);let ne=wt(B.key);return B.children.forEach(Ge=>{y(Ge)||(ne=!1)}),ne&&i.add(B.key),ne};return Ue.forEach(y),i},[ln,Ue,ot,wt]);n.useEffect(()=>{j&&bt.forEach(i=>{i.placeholder==="loading"&&Vt(i.node.key)})},[bt,j,Vt]);const Ut=n.useMemo(()=>p?dt?Ti(Ft).filter(i=>p.isLeaf(i)):p.leaves:Nn,[p,dt,Ft]),Mn=n.useMemo(()=>{if(!F||Ut.length===0)return"unchecked";let i=0;for(const y of Ut)F.leaves.has(y)&&i++;return i===0?"unchecked":i===Ut.length?"checked":"indeterminate"},[F,Ut]),ri=n.useCallback(()=>{if(!p||!F)return;const i=Ut.filter(B=>!p.isLocked(B)),y=!i.every(B=>F.leaves.has(B));Ve(Gn(p,F.leaves,i,y),{source:"selectAll",checked:y})},[p,F,Ut,Ve]),ci=n.useCallback(()=>{p&&F&&Ve(Gn(p,F.leaves,p.leaves,!1),{source:"clear",checked:!1})},[p,F,Ve]),Dn=i=>{Y||C||(z&&J&&p?.isCheckable(i.key)?Je(i.key):z&&x&&W(i.key),Ee?.(i.data))},Gt=n.useRef({toggleExpand:vt,setSubtreeExpanded:st,toggleCheck:Je,toggleSelected:W,rowClick:Dn});Gt.current={toggleExpand:vt,setSubtreeExpanded:st,toggleCheck:Je,toggleSelected:W,rowClick:Dn};const En=n.useMemo(()=>({toggleExpand:(i,y)=>Gt.current.toggleExpand(i,y),setSubtreeExpanded:(i,y)=>Gt.current.setSubtreeExpanded(i,y),toggleCheck:i=>Gt.current.toggleCheck(i),toggleSelected:i=>Gt.current.toggleSelected(i),rowClick:i=>Gt.current.rowClick(i)}),[]),pt=!!ze,tn=n.useRef(null),[Rn,li]=n.useState(typeof je=="number"?je:480);n.useEffect(()=>{const i=tn.current;if(!pt||!i||typeof ResizeObserver>"u")return;const y=new ResizeObserver(()=>{i.clientHeight>0&&li(i.clientHeight)});return y.observe(i),()=>y.disconnect()},[pt]);const on=k.useVirtualScroll({itemCount:pt?bt.length:0,itemHeight:oe,containerHeight:Rn,overscan:8}),dn=pt?on.startIndex:0,un=pt?on.endIndex:bt.length,hn=n.useRef(null),An=n.useRef(wt);An.current=wt,k.useTreeFocus(hn,{itemSelector:"tr.nice-treegrid__row",enabled:!C,onToggle:(i,y)=>{const B=i.dataset.key;B!==void 0&&i.hasAttribute("aria-expanded")&&An.current(B)!==y&&En.toggleExpand(B)}});const oi=n.useContext(k.NiceThemeContext),mn=n.useRef(null),[Wt,Tn]=n.useState(null),fn=n.useCallback(()=>Tn(null),[]);k.useOverlayFocus(mn,{open:!!Wt,modal:!1,initialFocus:'[role="menuitem"]:not([disabled])',onClose:fn}),k.useRovingFocus(mn,{orientation:"vertical",itemSelector:'[role="menuitem"]'});const zn=(i,y,B)=>{const ne=Ke?Ce.get(i):void 0,Ge=ne?Ke?.(ne.data):void 0;return Ge?.some(Xe=>!Xe.divider)?(Tn({key:i,x:y,y:B,items:Ge}),!0):!1},pn=n.useCallback(i=>[...hn.current?.querySelectorAll("tr.nice-treegrid__row")??[]].find(y=>y.dataset.key===i),[]),[gn,$n]=n.useState(null);n.useEffect(()=>{if(gn===null)return;const i=pn(gn);i&&(i.focus(),$n(null))},[gn,dn,un,pn]);const di=i=>{const y=bt[i]?.placeholder?i-1:i,B=bt[y]?.node.key;if(B===void 0)return;const ne=pn(B);ne?ne.focus():pt&&tn.current&&(tn.current.scrollTop=Math.max(0,y*oe-Rn/2),$n(B))},ui=i=>{const y=i.target;if(i.altKey||i.ctrlKey||i.metaKey||!y.matches?.("tr.nice-treegrid__row"))return;const B=y.dataset.key??"";if(i.shiftKey&&(i.key==="ArrowRight"||i.key==="ArrowLeft")){if(y.hasAttribute("aria-expanded")){i.preventDefault();const Xe=getComputedStyle(y).direction==="rtl";st(B,i.key==="ArrowRight"!==Xe)}return}if(i.key===" "){if(Y)return;z&&p?.isCheckable(B)?(i.preventDefault(),Je(B)):x&&(i.preventDefault(),W(B));return}if(!(i.key==="PageDown"||i.key==="PageUp")&&!(pt&&(i.key==="Home"||i.key==="End")))return;const Ge=bt.findIndex(Xe=>Xe.node.key===B);Ge<0||(i.preventDefault(),di(i.key==="PageDown"?Math.min(bt.length-1,Ge+Qn):i.key==="PageUp"?Math.max(0,Ge-Qn):i.key==="Home"?0:bt.length-1))},hi=de("controls.expand","Expand"),mi=de("controls.collapse","Collapse"),Ln=Nt[0]?.field,fi=i=>xe?xe(i.data):String((Ln!=null?i.data[Ln]:void 0)??i.key),Pn=(i,y)=>de("treeGrid.checkedSummary","{checked} of {total} selected").replace("{checked}",String(i)).replace("{total}",String(y)),pi=n.useMemo(()=>{const i=new Set(Rt);return Nt.map(y=>M&&!ie&&i.has(y.field))},[Nt,Rt,M,ie]),_n=$===!0?z?Wn:Wn.slice(0,2):Array.isArray($)?$.filter(i=>z||i==="expandAll"||i==="collapseAll"):Ki,nn=z?Me==="column"?"column":"tree":"none",an=!!x&&!z,Ht=Nt.length+(nn==="column"||an?1:0),On=[["checked",!he||K===!1?null:Pe&&typeof K=="function"?K(Pe):Pn(he.total.checked,he.total.total)],["matches",zt?de("treeGrid.matchCount","{count} matching rows").replace("{count}",String(zt.matched.size)):null]].filter(([,i])=>i!=null&&i!==!1&&i!=="");if(Qe==="hidden")return null;const bn=z&&Le&&p&&p.leaves.length>0?e.jsx("input",{type:"checkbox",className:"nice-treegrid__check-input nice-treegrid__select-all",checked:Mn==="checked",ref:i=>{i&&(i.indeterminate=Mn==="indeterminate")},disabled:Y||C,"aria-label":dt?de("treeGrid.selectAllResults","Select all results"):de("controls.selectAll","Select all"),onClick:i=>i.stopPropagation(),onChange:ri}):null,gi=i=>{const y={expandAll:{icon:"expand",label:de("treeGrid.expandAll","Expand all")},collapseAll:{icon:"collapse",label:de("treeGrid.collapseAll","Collapse all")},onlyChecked:{icon:"filter",label:de("treeGrid.showOnlyChecked","Show selected only")},clearChecked:{icon:"eraser",label:de("treeGrid.clearChecked","Clear selection")}}[i];return e.jsxs("button",{type:"button",className:`nice-btn nice-btn--sm nice-btn--ghost nice-treegrid__action${i==="onlyChecked"&&St?" nice-treegrid__action--active":""}`,"aria-pressed":i==="onlyChecked"?St:void 0,disabled:C||i==="clearChecked"&&(Y||!he||he.total.checked===0),onClick:()=>{i==="expandAll"||i==="collapseAll"?mt(i==="expandAll"):i==="onlyChecked"?cn(!Bt):ci()},children:[e.jsx(k.NiceIcon,{name:y.icon,size:14}),e.jsx("span",{children:y.label})]},i)},_i=i=>{const{node:y,level:B,posInSet:ne,setSize:Ge,placeholder:Xe}=bt[i],gt=y.key;if(Xe)return e.jsx("tr",{className:`nice-treegrid__placeholder nice-treegrid__placeholder--${Xe}`,"aria-level":B,style:pt?{height:oe}:void 0,children:e.jsxs("td",{colSpan:Ht,children:[e.jsx("span",{className:"nice-treegrid__indent",style:{width:(B-1)*20}}),e.jsx("span",{className:"nice-treegrid__toggle nice-treegrid__toggle--leaf","aria-hidden":"true"}),Xe==="loading"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-spinner nice-spinner--sm","aria-hidden":"true"}),e.jsx("span",{role:"status",children:de("treeGrid.loading","Loading…")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"alert",children:de("treeGrid.loadError","Could not load the rows.")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--sm nice-btn--ghost",onClick:()=>Kt(gt),children:de("treeGrid.retry","Retry")})]})]})},`${gt}\0${Xe}`);const xn=y.children.length>0||ot(gt),Kn=xn&&wt(gt),yn=ln&&xn?si.has(gt)?"collapse":"expand":null,Bn=!!p?.isCheckable(gt),Xt=we&&he&&p&&!p.isLeaf(gt)?he.count(gt):null,bi=fi(y);return e.jsx(Wi,{node:y,level:B,posInSet:ne,setSize:Ge,rowIndex:i,ariaRowIndex:pt?i+2:void 0,columns:Nt,highlight:pi,query:dt,expandable:xn,expanded:Kn,busy:Kn&&Re.get(gt)==="loading",expandLabel:hi,collapseLabel:mi,subtreeAction:yn,subtreeLabel:yn==="expand"?de("treeGrid.expandSubtree","Expand all below"):yn==="collapse"?de("treeGrid.collapseSubtree","Collapse all below"):"",checkMode:nn,hasCheckbox:Bn,checkState:he?he.state(gt):"unchecked",checkLabel:Bn?de("treeGrid.checkRow","Select {label}").replace("{label}",bi):"",locked:!!p?.isLocked(gt),countChecked:Xt?.checked??0,countTotal:Xt?.total??0,countTitle:Xt?Pn(Xt.checked,Xt.total):"",selectColumn:an,selected:x?D.has(gt):void 0,selectLabel:an?de("controls.selectRow","Select row {key}").replace("{key}",gt):"",readOnly:Y,className:typeof le=="function"?le(y.data,i):le,clickable:!Y&&(!!Ee||!!J||!!z&&!!x),height:pt?oe:void 0,handlers:En},gt)},Fn=[];for(let i=dn;i<un;i++)Fn.push(_i(i));const Vn=(i,y)=>i>0?e.jsx("tr",{className:"nice-treegrid__spacer","aria-hidden":"true",children:e.jsx("td",{colSpan:Ht,style:{height:i*oe}})},y):null;return e.jsxs("div",{id:Z,"data-testid":ve??N,className:`nice-treegrid nice-datagrid ${C?"nice-treegrid--disabled":""} ${Y?"nice-treegrid--readonly":""} ${ke?"nice-treegrid--error":""} ${pt?"nice-treegrid--virtual":""} ${Ae||""}`,style:ae,"aria-disabled":C||void 0,"aria-busy":rt||void 0,"aria-invalid":!!ke||void 0,children:[(P||ye||_n.length>0)&&e.jsxs("div",{className:"nice-datagrid__toolbar nice-treegrid__toolbar",children:[P&&e.jsxs("div",{className:"nice-datagrid__search nice-treegrid__search",children:[e.jsx("input",{type:"search",value:yt,onChange:i=>ht(i.target.value),onKeyDown:i=>{i.key==="Escape"&&yt&&(i.preventDefault(),ht(""))},placeholder:R||de("controls.search","Search..."),"aria-label":R||de("controls.search","Search...")}),yt&&e.jsx("button",{type:"button",className:"nice-treegrid__search-clear",onClick:()=>ht(""),"aria-label":de("treeGrid.clearSearch","Clear search"),children:e.jsx(k.NiceIcon,{name:"close",size:12})})]}),_n.length>0&&e.jsx("div",{className:"nice-treegrid__actions",children:_n.map(gi)}),ye,On.length>0&&e.jsx("span",{className:"nice-treegrid__summary",role:"status",children:On.map(([i,y],B)=>e.jsxs(n.Fragment,{children:[B>0&&" · ",y]},i))})]}),e.jsx("div",{ref:tn,className:"nice-datagrid__table-wrap",style:pt?{height:je??480,overflow:"auto"}:void 0,onScroll:pt?on.onScroll:void 0,children:e.jsxs("table",{ref:hn,role:"treegrid","aria-label":Be,"aria-labelledby":Ye,"aria-multiselectable":x||z||void 0,"aria-rowcount":pt?bt.length+1:void 0,className:`nice-table nice-table--${Se} ${Oe?"nice-table--striped":""} ${De?"nice-table--compact":""}`,onKeyDownCapture:i=>{if(Ke&&(i.key==="ContextMenu"||i.key==="F10"&&i.shiftKey)){const y=i.target.closest("tr.nice-treegrid__row"),B=y?.getBoundingClientRect();if(y?.dataset.key!==void 0&&B&&zn(y.dataset.key,B.left+24,B.bottom)){i.preventDefault(),i.stopPropagation();return}}ui(i)},onContextMenu:Ke?i=>{const y=i.target.closest("tr.nice-treegrid__row");y?.dataset.key!==void 0&&zn(y.dataset.key,i.clientX,i.clientY)&&i.preventDefault()}:void 0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[nn==="column"&&e.jsx("th",{className:"nice-datagrid__checkbox nice-treegrid__th-check",children:bn}),an&&e.jsx("th",{className:"nice-datagrid__checkbox",style:{width:36}}),Nt.map((i,y)=>e.jsxs("th",{style:{width:i.width,minWidth:i.minWidth,textAlign:i.align},className:A&&i.sortable!==!1?"nice-datagrid__th--sortable":void 0,onClick:()=>A&&i.sortable!==!1&&h(i.field),children:[y===0&&nn==="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})]}),i.header,A&&i.sortable!==!1&&e.jsx("span",{className:"nice-table__sort-icon",style:{opacity:ft===i.field&&u?void 0:.3},children:e.jsx(k.NiceIcon,{name:ft===i.field&&u?u==="asc"?"sort-asc":"sort-desc":"sort",size:12})})]},i.field))]})}),e.jsx("tbody",{children:rt?e.jsx("tr",{children:e.jsx("td",{colSpan:Ht,className:"nice-datagrid__empty",children:e.jsx("div",{className:"nice-spinner nice-spinner--md",style:{margin:"0 auto"}})})}):ke?e.jsx("tr",{children:e.jsx("td",{colSpan:Ht,className:"nice-datagrid__empty nice-treegrid__error",role:"alert",children:ke})}):bt.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Ht,className:"nice-datagrid__empty",children:dt?de("controls.noResults","No results"):Q||de("controls.noData","No data available")})}):e.jsxs(e.Fragment,{children:[Vn(dn,"top"),Fn,Vn(bt.length-un,"bottom")]})})]})}),Wt&&typeof document<"u"&&vi.createPortal(e.jsx("div",{ref:mn,className:"nice-treegrid__menu",role:"menu","aria-label":de("treeGrid.rowMenu","Row actions"),style:{position:"fixed",left:Wt.x,top:Wt.y},children:Wt.items.map(i=>i.divider?e.jsx("div",{className:"nice-treegrid__menu-divider",role:"separator"},i.id):e.jsxs("button",{type:"button",role:"menuitem",className:`nice-treegrid__menu-item${i.danger?" nice-treegrid__menu-item--danger":""}`,disabled:i.disabled,onClick:()=>{fn(),i.onSelect?.()},children:[i.icon&&e.jsx(k.NiceIcon,{name:i.icon,size:14}),i.label]},i.id))}),oi?.portalTarget??document.body),Wt&&e.jsx("div",{className:"nice-treegrid__menu-backdrop","aria-hidden":"true",onMouseDown:fn})]})}const qi=[],Yi=[],Hi=[];function Xi(t,a,s){const r=[],l=(c,f)=>{c.forEach(m=>{r.push({item:m,parent:m[s]??f}),Array.isArray(m.children)&&m.children.length>0&&l(m.children,m[a])})};l(t,null);const o=new Map,d=[];return r.forEach(({item:c})=>{const f={...c,children:[]};o.set(String(f[a]),f)}),r.forEach(({item:c,parent:f})=>{f!=null&&o.has(String(f))?o.get(String(f)).children.push(o.get(String(c[a]))):d.push(o.get(String(c[a])))}),d}function Zi({columns:t=qi,data:a=Yi,keyField:s="key",parentKeyField:r="parentKey",expandedKeys:l,onExpandedChange:o,selectedKeys:d=Hi,onSelectionChange:c,selectable:f,sortable:m,loading:j,emptyText:E,className:L,style:A,accessMode:T,id:V,"data-testid":g}){const I=k.useNiceAccessMode(T,V)==="hidden",{t:b}=k.useNiceTranslation(),[z,S]=n.useState([]),U=l??z,[H,fe]=n.useState(d),re=c?d:H,ge=n.useMemo(()=>Xi(a,s,r),[a,s,r]),Me=n.useMemo(()=>t.filter(w=>!w.hidden),[t]),[J,we]=n.useState(null),K=n.useCallback(w=>{we(ie=>ie?.field===w?ie.dir==="asc"?{field:w,dir:"desc"}:null:{field:w,dir:"asc"})},[]),Le=n.useCallback(w=>J?[...w].sort((ue,be)=>{const M=ue[J.field]??"",le=be[J.field]??"",xe=typeof M=="number"?M-le:String(M).localeCompare(String(le));return J.dir==="desc"?-xe:xe}).map(ue=>ue.children&&ue.children.length?{...ue,children:Le(ue.children)}:ue):w,[J]),Ne=n.useMemo(()=>Le(ge),[ge,Le]),Fe=n.useCallback(w=>{const ie=U.includes(w)?U.filter(ue=>ue!==w):[...U,w];o?o(ie):S(ie)},[U,o]),X=n.useMemo(()=>jn(ge,{getKey:w=>String(w[s]),getChildren:w=>w.children}),[ge,s]),$=n.useMemo(()=>Sn(X,re),[X,re]),P=n.useMemo(()=>sn(X,$.leaves),[X,$]),R=n.useCallback(w=>{const ie=Cn(X,$.leaves,w),ue=Zt(X,ie,"all",$.unknown);c?c(ue):fe(ue)},[X,$,c]),_=Me[0]?.field;let _e=0;const ce=(w,ie)=>{const ue=String(w[s]),be=_e++,M=!!(w.children&&w.children.length>0),le=U.includes(ue),xe=P.state(ue),ze=xe==="checked",oe=xe==="indeterminate",je=_!=null?String(w[_]??ue):ue;return e.jsxs(n.Fragment,{children:[e.jsxs("tr",{className:ze?"nice-treelist__row--selected":"",children:[f&&e.jsx("td",{className:"nice-treelist__checkbox",children:e.jsx("input",{type:"checkbox",checked:ze,ref:Oe=>{Oe&&(Oe.indeterminate=oe)},onChange:()=>R(ue),"aria-label":b("controls.selectRow","Select row {key}").replace("{key}",je)})}),Me.map((Oe,De)=>e.jsxs("td",{style:{textAlign:Oe.align},children:[De===0&&e.jsx("span",{style:{display:"inline-block",width:ie*20}}),De===0&&e.jsx("span",{role:M?"button":void 0,tabIndex:M?0:void 0,"aria-expanded":M?le:void 0,"aria-label":M?b(le?"controls.collapse":"controls.expand",le?"Collapse":"Expand"):void 0,onKeyDown:M?k.clickOnActivationKey:void 0,className:"nice-treelist__toggle",onClick:()=>M&&Fe(ue),style:{cursor:M?"pointer":"default",width:20,display:"inline-block"},children:M?e.jsx(k.NiceIcon,{name:le?"chevron-down":"chevron-right",size:12}):""}),Oe.render?Oe.render(w[Oe.field],w,be):String(w[Oe.field]??"")]},Oe.field))]}),M&&le&&w.children.map(Oe=>ce(Oe,ie+1))]},ue)};return I?null:e.jsx("div",{className:`nice-treelist ${L||""}`,style:A,"data-testid":g,children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[f&&e.jsx("th",{className:"nice-treelist__checkbox"}),Me.map(w=>{const ie=!!m&&!!w.sortable;return e.jsxs("th",{style:{width:w.width,minWidth:w.minWidth,textAlign:w.align},className:ie?"nice-treelist__th--sortable":void 0,onClick:()=>ie&&K(w.field),scope:"col","aria-sort":ie?J?.field===w.field?J.dir==="asc"?"ascending":"descending":"none":void 0,children:[w.header,ie&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:e.jsx(k.NiceIcon,{name:J?.field===w.field?J.dir==="desc"?"chevron-down":"chevron-up":"sort",size:12})})]},w.field)})]})}),e.jsx("tbody",{children:j?e.jsx("tr",{children:e.jsx("td",{colSpan:Me.length+(f?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:Me.length+(f?1:0),className:"nice-treelist__empty",children:E||b("controls.noData","No data available")})}):Ne.map(w=>ce(w,0))})]})})}function ti(t,a=[]){for(const s of t)s.expanded&&a.push(s.key),s.children&&ti(s.children,a);return a}const qn=[],Ji=[],ea=({nodes:t=qn,header:a,selectedKeys:s=Ji,expandedKeys:r,onSelectionChange:l,onExpandedChange:o,selectionMode:d="none",showCheckboxes:c,searchable:f,searchPlaceholder:m,onNodeClick:j,renderNode:E,showLines:L,loading:A,className:T,style:V,accessMode:g,id:x,draggable:I,onNodeDrop:b,onLoadChildren:z,contextMenuItems:S,onContextMenuAction:U,editable:H,onNodeEdit:fe,maxDepth:re,"data-testid":ge})=>{const J=k.useNiceAccessMode(g,x)==="hidden",{t:we}=k.useNiceTranslation(),[K,Le]=n.useState(()=>ti(t)),[Ne,Fe]=n.useState(""),[X,$]=n.useState(new Set),[P,R]=n.useState(new Map),[_,_e]=n.useState(null),[ce,w]=n.useState(null),[ie,ue]=n.useState(null),[be,M]=n.useState(""),le=n.useRef(null),xe=r??K,ze=n.useRef(xe);ze.current=xe;const oe=n.useMemo(()=>new Set(s),[s]),je=typeof re=="number"?Math.min(10,Math.max(1,re)):1/0,Oe=!!c&&d==="multiple",De=n.useMemo(()=>Oe?jn(t,{getKey:N=>N.key,getChildren:(N,ve)=>ve+1>=je?null:P.get(N.key)??N.children,isDisabled:N=>!!N.disabled},{inheritDisabled:!1}):null,[Oe,t,P,je]),Se=n.useMemo(()=>De?Sn(De,s):null,[De,s]),rt=n.useMemo(()=>De&&Se?sn(De,Se.leaves):null,[De,Se]),et=n.useCallback(async(N,ve)=>{const ee=ze.current,Be=!ee.includes(N),Ye=Be?[...ee,N]:ee.filter(de=>de!==N);if(ze.current=Ye,o?o(Ye):Le(Ye),Be&&z&&!ve.children?.length&&ve.leaf!==!0&&!P.has(N)){$(Qe=>new Set(Qe).add(N));const de=await z(ve);R(Qe=>new Map(Qe).set(N,de)),$(Qe=>{const C=new Set(Qe);return C.delete(N),C})}},[o,z,P]),tt=n.useCallback(N=>{if(l){if(d==="single")l(s.includes(N)?[]:[N]);else if(d==="multiple")if(De&&Se){const ve=Cn(De,Se.leaves,N);ve!==Se.leaves&&l(Zt(De,ve,"all",Se.unknown))}else l(s.includes(N)?s.filter(ve=>ve!==N):[...s,N])}},[s,d,l,De,Se]),ke=n.useCallback(N=>{if(!Ne)return!0;const ve=Ne.toLowerCase();return N.text.toLowerCase().includes(ve)?!0:(P.get(N.key)??N.children)?.some(Be=>ke(Be))??!1},[Ne,P]),Q=n.useCallback((N,ve)=>{S?.length&&(N.preventDefault(),w({x:N.clientX,y:N.clientY,node:ve}))},[S]),ye=n.useCallback(()=>{ie&&fe&&fe(ie,be),ue(null)},[ie,be,fe]),Ee=n.useRef(null),Ke=(N,ve=t)=>{for(const ee of ve){const Be=ee.key===N?ee:Ke(N,P.get(ee.key)??ee.children??qn);if(Be)return Be}};k.useTreeFocus(Ee,{rowSelector:".nice-tree__row",onToggle:(N,ve)=>{const ee=N.dataset.key===void 0?void 0:Ke(N.dataset.key);ee&&ze.current.includes(ee.key)!==ve&&et(ee.key,ee)}});const Ae=n.useRef(null);n.useEffect(()=>{if(ie!==null||Ae.current===null)return;const N=Ae.current;Ae.current=null,[...Ee.current?.querySelectorAll('[role="treeitem"]')??[]].find(ve=>ve.dataset.key===N)?.focus()},[ie]);const ae=n.useRef(null);k.useRovingFocus(ae,{orientation:"vertical",wrap:!0,typeahead:!0}),k.useOverlayFocus(ae,{open:!!ce,modal:!1,onClose:()=>w(null)});const Z=(N,ve)=>{if(Ne&&!ke(N))return null;const ee=ve+1>=je,Be=ee?void 0:P.get(N.key)??N.children,Ye=!ee&&(Be&&Be.length>0||N.leaf!==!0&&z&&!Be?.length),de=xe.includes(N.key),Qe=rt?rt.state(N.key):oe.has(N.key)?"checked":"unchecked",C=rt?Qe==="checked":oe.has(N.key),Y=!!N.disabled||!!De?.isLocked(N.key),me=X.has(N.key),$e=Math.min(ve+1,10),qe={paddingLeft:ve*20+4,"--nice-row-bg":`var(--nice-tree-level-${$e}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${$e}-text, inherit)`,"--nice-row-border":`var(--nice-tree-level-${$e}-border, transparent)`,"--nice-row-hover-bg":`var(--nice-tree-level-${$e}-hover-bg, var(--nice-hover-bg, color-mix(in srgb, var(--nice-text-primary) 6%, transparent)))`,"--nice-row-active-bg":`var(--nice-tree-level-${$e}-active-bg, color-mix(in srgb, var(--nice-color-primary) 14%, transparent))`};return e.jsxs("li",{className:"nice-tree__node",role:"treeitem","aria-label":N.text,"aria-expanded":Ye?de:void 0,"aria-selected":d!=="none"?C:void 0,"aria-disabled":N.disabled||void 0,"data-key":N.key,"data-nice-depth":$e,onKeyDown:H&&!N.disabled?q=>{q.key==="F2"&&q.target===q.currentTarget&&(q.preventDefault(),ue(N.key),M(N.text))}:void 0,draggable:I&&!N.disabled,onDragStart:I?q=>{q.stopPropagation(),_e(N.key)}:void 0,onDragOver:I?q=>{q.preventDefault(),q.stopPropagation()}:void 0,onDrop:I&&_?q=>{q.stopPropagation(),b?.(_,N.key,"inside"),_e(null)}:void 0,onDragEnd:I?()=>_e(null):void 0,children:[e.jsxs("div",{role:"presentation",className:`nice-tree__row ${C?"nice-tree__row--selected":""} ${N.disabled?"nice-tree__row--disabled":""} ${_===N.key?"nice-tree__row--dragging":""}`,style:qe,onClick:()=>{N.disabled||(tt(N.key),j?.(N))},onContextMenu:q=>Q(q,N),onDoubleClick:H&&!N.disabled?()=>{ue(N.key),M(N.text)}:void 0,children:[e.jsx("span",{role:"presentation",className:`nice-tree__toggle ${Ye?de?"nice-tree__toggle--expanded":"":"nice-tree__toggle--leaf"}`,onClick:q=>{q.stopPropagation(),Ye&&et(N.key,N)},children:me?e.jsx("span",{className:"nice-spinner nice-spinner--xs"}):Ye?de?e.jsx(k.NiceIcon,{name:"chevron-down",size:12}):e.jsx(k.NiceIcon,{name:"chevron-right",size:12}):""}),c&&d!=="none"&&e.jsx("input",{type:"checkbox",checked:Qe==="checked",ref:q=>{q&&(q.indeterminate=Qe==="indeterminate")},onChange:()=>tt(N.key),onClick:q=>q.stopPropagation(),disabled:Y,tabIndex:-1,"aria-label":N.text,className:"nice-tree__checkbox"}),ie===N.key?e.jsx("input",{type:"text",className:"nice-tree__edit-input",value:be,onChange:q=>M(q.target.value),onBlur:ye,onKeyDown:q=>{q.key==="Enter"&&(Ae.current=N.key,ye()),q.key==="Escape"&&(q.preventDefault(),Ae.current=N.key,ue(null))},autoFocus:!0,onClick:q=>q.stopPropagation()}):E?E(N):e.jsxs(e.Fragment,{children:[N.icon&&e.jsx("span",{className:"nice-tree__icon",children:N.icon}),e.jsx("span",{className:"nice-tree__text",children:N.text})]})]}),Be&&Be.length>0&&de&&e.jsx("ul",{className:"nice-tree__children",role:"group",children:Be.map(q=>Z(q,ve+1))})]},N.key)};return J?null:e.jsxs("div",{role:"presentation",className:`nice-tree ${L?"nice-tree--lines":""} ${T||""}`,style:V,ref:le,"data-testid":ge,onClick:()=>w(null),children:[a!=null&&a!==!1&&e.jsx("div",{className:"nice-tree__header",children:a}),f&&e.jsx("div",{className:"nice-tree__search",children:e.jsx("input",{type:"text",value:Ne,onChange:N=>Fe(N.target.value),placeholder:m||we("controls.search","Search..."),"aria-label":m||we("controls.search","Search tree")})}),A?e.jsx("div",{className:"nice-tree__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--sm"})}):e.jsx("ul",{ref:Ee,className:"nice-tree__root",role:"tree","aria-multiselectable":d==="multiple"||void 0,children:t.map(N=>Z(N,0))}),ce&&S&&e.jsx("div",{ref:ae,className:"nice-tree__context-menu",role:"menu","aria-label":ce.node.text,style:{position:"fixed",top:ce.y,left:ce.x,zIndex:9999},children:S.map(N=>e.jsxs("button",{type:"button",role:"menuitem",disabled:N.disabled,className:`nice-tree__context-item ${N.disabled?"nice-tree__context-item--disabled":""}`,onClick:()=>{N.disabled||(U?.(N.key,ce.node),w(null))},children:[N.icon&&e.jsx("span",{children:N.icon}),N.label]},N.key))})]})},ta=[],na=({items:t=ta,selectedKeys:a=[],onSelectionChange:s,selectionMode:r="none",searchable:l,searchPlaceholder:o,grouped:d,groupField:c="group",reorderable:f,onReorder:m,onItemClick:j,renderItem:E,showCheckboxes:L,loading:A,emptyText:T,size:V="md",header:g,disabled:x,readOnly:I,error:b,bordered:z=!0,swipeActions:S,className:U,style:H,accessMode:fe,id:re,"data-testid":ge})=>{const J=k.useNiceAccessMode(fe,re)==="hidden",{t:we}=k.useNiceTranslation(),[K,Le]=n.useState(""),[Ne,Fe]=n.useState(null),[X,$]=n.useState(null),P=n.useRef(null),R=n.useMemo(()=>{if(!K)return t;const M=K.toLowerCase();return t.filter(le=>le.text.toLowerCase().includes(M))},[t,K]),_=n.useMemo(()=>{if(!d)return null;const M=new Map;return R.forEach(le=>{const xe=String(le[c]??"");M.has(xe)||M.set(xe,[]),M.get(xe).push(le)}),M},[R,d,c]),_e=n.useCallback(M=>{s&&(r==="single"?s(a.includes(M)?[]:[M]):r==="multiple"&&s(a.includes(M)?a.filter(le=>le!==M):[...a,M]))},[a,r,s]),ce=n.useCallback(M=>{Ne!==null&&Ne!==M&&m&&m(Ne,M),Fe(null)},[Ne,m]),w=n.useRef(null),ie=n.useCallback(M=>{w.current=M},[]);k.useRovingFocus(w,{orientation:"vertical",itemSelector:".nice-list__item",typeahead:!0,pageSize:10});const ue=M=>{!M.disabled&&!x&&!I&&(_e(M.key),j?.(M))},be=(M,le)=>{const xe=a.includes(M.key),ze=X===M.key;return e.jsxs("li",{className:`nice-list__item ${xe?"nice-list__item--selected":""} ${M.disabled?"nice-list__item--disabled":""} ${ze?"nice-list__item--swiped":""}`,onClick:()=>ue(M),onKeyDown:oe=>{oe.target===oe.currentTarget&&(oe.key==="Enter"||oe.key===" ")&&(oe.preventDefault(),ue(M))},draggable:f&&!x&&!I,onDragStart:()=>Fe(le),onDragOver:oe=>oe.preventDefault(),onDrop:()=>ce(le),onTouchStart:S?.length?oe=>{P.current={x:oe.touches[0].clientX,key:M.key}}:void 0,onTouchEnd:S?.length?oe=>{if(!P.current)return;const je=oe.changedTouches[0].clientX-P.current.x;je<-50&&P.current.key===M.key?$(M.key):je>50&&$(null),P.current=null}:void 0,role:"option","aria-selected":r!=="none"?xe:void 0,"aria-disabled":M.disabled||void 0,children:[e.jsxs("div",{className:"nice-list__item-content",children:[L&&r!=="none"&&e.jsx("input",{type:"checkbox",checked:xe,readOnly:!0,tabIndex:-1,className:"nice-list__checkbox"}),E?E(M):e.jsxs(e.Fragment,{children:[M.icon&&e.jsx("span",{className:"nice-list__icon",children:M.icon}),e.jsx("span",{className:"nice-list__text",children:M.text}),M.badge&&e.jsx("span",{className:"nice-list__badge",children:M.badge})]})]}),S&&ze&&e.jsx("div",{className:"nice-list__swipe-actions",children:S.map(oe=>e.jsx("button",{className:"nice-list__swipe-btn",style:oe.color?{backgroundColor:oe.color}:void 0,onClick:je=>{je.stopPropagation(),oe.onClick(M),$(null)},children:oe.label},oe.key))})]},M.key)};return J?null:e.jsxs("div",{className:`nice-list nice-list--${V} ${z?"nice-list--bordered":""} ${x?"nice-list--disabled":""} ${I?"nice-list--readonly":""} ${b?"nice-list--error":""} ${U||""}`,style:H,"data-testid":ge,"aria-disabled":x||void 0,"aria-busy":A||void 0,children:[g&&e.jsx("div",{className:"nice-list__header",children:g}),l&&!A&&e.jsx("div",{className:"nice-list__search",children:e.jsx("input",{type:"text",value:K,onChange:M=>Le(M.target.value),placeholder:o||we("controls.search","Search...")})}),A?e.jsx("div",{className:"nice-list__loading",role:"status","aria-live":"polite",children:e.jsx("div",{className:`nice-spinner nice-spinner--${V}`})}):b?e.jsx("div",{className:"nice-list__error",role:"alert",children:b}):R.length===0?e.jsx("div",{className:"nice-list__empty",children:T||we("controls.noData","No data available")}):e.jsx("div",{role:"listbox",ref:ie,"aria-multiselectable":r==="multiple"||void 0,children:_?Array.from(_.entries()).map(([M,le])=>e.jsxs("div",{className:"nice-list__group",role:"group","aria-label":M,children:[e.jsx("div",{className:"nice-list__group-header","aria-hidden":"true",children:M}),e.jsx("ul",{className:"nice-list__items",role:"presentation",children:le.map((xe,ze)=>be(xe,ze))})]},M)):e.jsx("ul",{className:"nice-list__items",role:"presentation",children:R.map((M,le)=>be(M,le))})})]})},ia=[],aa=[];function sa({columns:t=ia,data:a=aa,striped:s,compact:r,size:l="md",emptyText:o,className:d,style:c,accessMode:f,id:m,displayStyle:j}){const{t:E}=k.useNiceTranslation(),L=k.normalizeSize(l),T=k.useNiceAccessMode(f,m)==="hidden",V=k.useComponentDisplayStyle("table",j),g=k.useComponentDisplayClass("table",j),[x,I]=n.useState(null),b=n.useMemo(()=>x?[...a].sort((S,U)=>{const H=S[x.field]??"",fe=U[x.field]??"",re=typeof H=="number"?H-fe:String(H).localeCompare(String(fe));return x.dir==="desc"?-re:re}):a,[a,x]),z=S=>{I(U=>U?.field===S?U.dir==="asc"?{field:S,dir:"desc"}:null:{field:S,dir:"asc"})};return T?null:e.jsx("div",{className:`nice-table-wrapper ${d||""}`,style:{...V,...c},children:e.jsxs("table",{className:`nice-table nice-table--ds-${g} nice-table--${L} ${s?"nice-table--striped":""} ${r?"nice-table--compact":""}`,"aria-rowcount":b.length,"aria-colcount":t.length,children:[e.jsx("thead",{children:e.jsx("tr",{children:t.map(S=>{const U=S.sortable?x?.field===S.field?x.dir==="asc"?"ascending":"descending":"none":void 0;return e.jsxs("th",{style:{width:S.width,textAlign:S.align},className:S.sortable?"th--sortable":void 0,onClick:()=>S.sortable&&z(S.field),scope:"col","aria-sort":U,children:[S.header,S.sortable&&e.jsx("span",{className:"nice-table__sort-icon","aria-hidden":"true",children:e.jsx(k.NiceIcon,{name:x?.field===S.field?x.dir==="desc"?"chevron-down":"chevron-up":"sort",size:12})})]},S.field)})})}),e.jsx("tbody",{children:b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:t.length,className:"nice-table__empty",children:o||E("table.noData","No data")})}):b.map((S,U)=>e.jsx("tr",{children:t.map(H=>e.jsx("td",{style:{textAlign:H.align},children:H.render?H.render(S[H.field],S):String(S[H.field]??"")},H.field))},U))})]})})}const ra=[];function ca({items:t=ra,tileWidth:a=180,tileHeight:s=180,direction:r="horizontal",renderTile:l,onTileClick:o,loading:d,emptyText:c,className:f,style:m,"data-testid":j}){const{t:E}=k.useNiceTranslation();return e.jsx("div",{className:`nice-tileview nice-tileview--${r} ${f||""}`,style:m,"data-testid":j,children:d?e.jsx("div",{className:"nice-tileview__loading",children:e.jsx("div",{className:"nice-spinner nice-spinner--md"})}):t.length===0?e.jsx("div",{className:"nice-tileview__empty",children:c||E("controls.noData","No data available")}):e.jsx("div",{className:"nice-tileview__container",style:{display:"flex",flexWrap:"wrap",gap:8,flexDirection:r==="vertical"?"column":"row"},children:t.map(L=>e.jsx("div",{role:o?"button":void 0,tabIndex:o?0:void 0,onKeyDown:o?k.clickOnActivationKey:void 0,className:"nice-tileview__tile",style:{width:a,height:s,cursor:o?"pointer":void 0},onClick:()=>o?.(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 la=[],oa=[];function da({open:t}){return e.jsx(k.NiceIcon,{name:"chevron-down",size:14,style:{transition:"transform 160ms ease",transform:t?"rotate(0deg)":"rotate(-90deg)"}})}function ua(){return e.jsx(k.NiceIcon,{name:"plus",size:14})}const ha=[{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"}],ma=Object.assign(n.forwardRef(({columns:t=la,cards:a=oa,onCardMove:s,onCardClick:r,renderCard:l,onAddCard:o,disabled:d=!1,size:c="md",collapsible:f=!1,collapseDirection:m="vertical",layoutMode:j="scroll",viewMode:E,onViewModeChange:L,collapsedColumns:A,onCollapsedColumnsChange:T,formItems:V,formColumns:g=1,formProps:x,editCardTitle:I,newCardTitle:b,onCardEdit:z,onCardCreate:S,onCardDelete:U,tutorial:H,cookies:fe=!1,localStorage:re=!0,sessionStorage:ge=!1,storageMode:Me,storageKey:J,className:we,style:K,id:Le,...Ne},Fe)=>{const{t:X}=k.useNiceTranslation(),[$,P]=n.useState(null),[R,_]=n.useState(null),[_e,ce]=n.useState(null),w=!!V&&(!!z||!!S),ie=n.useCallback(Q=>{if(w&&z){ce({key:Q.key,data:{...Q},column:Q.column});return}r?.(Q)},[w,r,z]),ue=w&&!!z||!!r,be=n.useCallback(Q=>{if(w&&S){ce({key:null,data:{title:"",description:""},column:Q});return}o?.(Q)},[w,o,S]),M=wi.useStorageAdapter(J??"nice-kanban"),[le,xe]=n.useState(()=>M.get("state")??{collapsedColumns:[],viewMode:"default"}),ze=n.useMemo(()=>A??le.collapsedColumns??[],[A,le.collapsedColumns]),oe=E??le.viewMode??"default",je=n.useCallback(Q=>{xe(ye=>{const Ee={...ye,...Q};return M.set("state",Ee),Ee})},[M]),Oe=n.useCallback(Q=>{const ye=ze.includes(Q)?ze.filter(Ee=>Ee!==Q):[...ze,Q];T?T(ye):je({collapsedColumns:ye})},[ze,T,je]);n.useCallback(Q=>{L?L(Q):je({viewMode:Q})},[L,je]);const De=n.useCallback(Q=>a.filter(ye=>ye.column===Q).sort((ye,Ee)=>(ye.order??0)-(Ee.order??0)),[a]),Se=n.useCallback((Q,ye)=>{d||(Q.dataTransfer.effectAllowed="move",Q.dataTransfer.setData("text/plain",String(ye.key)),P({cardKey:ye.key,fromColumn:ye.column}))},[d]),rt=n.useCallback((Q,ye)=>{Q.preventDefault(),Q.dataTransfer.dropEffect="move",_({column:ye})},[]),et=n.useCallback(()=>{_(null)},[]),tt=n.useCallback((Q,ye)=>{if(Q.preventDefault(),_(null),!$||d)return;const Ee=De(ye);s?.($.cardKey,ye,Ee.length),P(null)},[$,d,De,s]),ke=n.useCallback(()=>{P(null),_(null)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:Fe,id:Le,className:`nice-kanban nice-kanban--${c} nice-kanban--${oe} nice-kanban--layout-${j} ${d?"nice-kanban--disabled":""} ${we||""}`,style:{position:"relative",...K},...Ne,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(k.NiceTutorialButton,{steps:k.resolveTutorial(H,ha)})}),t.map(Q=>{const ye=De(Q.key),Ee=R?.column===Q.key,Ke=Q.limit!=null&&ye.length>=Q.limit,Ae=f&&ze.includes(Q.key);return e.jsxs("div",{className:`nice-kanban__column ${Ee?"nice-kanban__column--dragover":""} ${Ae?`nice-kanban__column--collapsed nice-kanban__column--collapse-${m}`:""}`,onDragOver:ae=>!Ae&&rt(ae,Q.key),onDragLeave:et,onDrop:ae=>!Ae&&tt(ae,Q.key),children:[e.jsxs("div",{className:"nice-kanban__column-header",style:Q.color?{borderTopColor:Q.color}:void 0,onClick:f?()=>Oe(Q.key):void 0,role:f?"button":void 0,tabIndex:f?0:void 0,onKeyDown:f?ae=>{(ae.key==="Enter"||ae.key===" ")&&Oe(Q.key)}:void 0,children:[f&&e.jsx("span",{className:"nice-kanban__collapse-icon","aria-hidden":"true",children:e.jsx(da,{open:!Ae})}),e.jsx("span",{className:"nice-kanban__column-title",children:Q.title}),e.jsx("span",{className:"nice-kanban__column-count",children:Q.limit!=null?e.jsxs("span",{className:"nice-kanban__count-frac",children:[e.jsx("span",{className:"nice-kanban__count-num",children:ye.length}),e.jsx("span",{className:"nice-kanban__count-slash",children:"/"}),e.jsx("span",{className:"nice-kanban__count-den",children:Q.limit})]}):ye.length})]}),!Ae&&e.jsxs("div",{className:"nice-kanban__column-body",children:[ye.map(ae=>e.jsx("div",{className:`nice-kanban__card nice-kanban__card--${oe} ${$?.cardKey===ae.key?"nice-kanban__card--dragging":""}`,draggable:!d,onDragStart:Z=>Se(Z,ae),onDragEnd:ke,onClick:()=>ie(ae),role:ue?"button":"article",tabIndex:ue?0:void 0,onKeyDown:ue?k.clickOnActivationKey:void 0,children:l?l(ae):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"nice-kanban__card-title",children:ae.title}),oe!=="compact"&&ae.description&&e.jsx("div",{className:"nice-kanban__card-desc",children:ae.description})]})},ae.key)),ye.length===0&&e.jsx("div",{className:"nice-kanban__empty",children:X("kanban.empty","No cards")})]}),!Ae&&(o||w&&S)&&!Ke&&e.jsxs("button",{type:"button",className:"nice-kanban__add",onClick:()=>be(Q.key),disabled:d,children:[e.jsx(ua,{})," ",X("kanban.addCard","Add card")]})]},Q.key)})]}),w&&_e&&e.jsxs(Ni.NiceModal,{open:!0,onClose:()=>ce(null),title:_e.key==null?b||X("kanban.newCard","New card"):I||X("kanban.editCard","Edit card"),children:[e.jsx(ki.NiceForm,{items:V,data:_e.data,columns:g,...x,onFieldChange:(Q,ye)=>ce(Ee=>Ee&&{...Ee,data:{...Ee.data,[Q]:ye}})}),e.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16,flexWrap:"wrap"},children:[_e.key!=null&&U&&e.jsx(We.NiceButton,{type:"button",size:"sm",variant:"error",style:{marginRight:"auto"},onClick:()=>{U(_e.key),ce(null)},children:X("controls.delete","Delete")}),e.jsx(We.NiceButton,{type:"button",size:"sm",variant:"secondary",onClick:()=>ce(null),children:X("controls.cancel","Cancel")}),e.jsx(We.NiceButton,{type:"button",size:"sm",variant:"primary",onClick:()=>{if(_e.key==null){const Q={key:`card-${Date.now()}`,title:"",column:_e.column,..._e.data};S?.(Q)}else z?.(_e.key,{..._e.data,key:_e.key,column:_e.column});ce(null)},children:X("controls.save","Save")})]})]})]})}),{displayName:"NiceKanbanBoard"}),fa=[];function Mt(...t){return t.filter(Boolean).map(a=>typeof a=="object"?Object.entries(a).filter(([,s])=>s).map(([s])=>s).join(" "):a).join(" ")}const pa=50,ga=[10,25,50,100,200],_a=40,ba={compact:32,normal:_a,comfortable:48},xa=10,ya=768,va=500,ka=10;function xt(t,a){return a.split(".").reduce((s,r)=>s?.[r],t)}function ni(t){return t.width==="auto"?{flex:"1 1 0",minWidth:t.minWidth??80,maxWidth:t.maxWidth}:{width:t.width||150,minWidth:t.minWidth,maxWidth:t.maxWidth}}function Jt(t,a,s="pl-PL"){if(t==null)return"—";switch(a.type){case"number":return new Intl.NumberFormat(s,{minimumFractionDigits:a.format?.includes(".")?a.format.split(".")[1].length:0}).format(t);case"currency":return new Intl.NumberFormat(s,{style:"currency",currency:a.currencyCode||"PLN"}).format(t);case"percent":return new Intl.NumberFormat(s,{style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}).format(t/100);case"date":return new Intl.DateTimeFormat(s,{dateStyle:"short"}).format(new Date(t));case"datetime":return new Intl.DateTimeFormat(s,{dateStyle:"short",timeStyle:"short"}).format(new Date(t));case"boolean":return t?e.jsx(k.NiceIcon,{name:"check",size:14}):e.jsx(k.NiceIcon,{name:"close",size:14});case"enum":return a.enumOptions?.find(l=>l.value===t)?.label||String(t);default:return String(t)}}function Na(t,a,s,r){const[l,o]=n.useState(0),{startIndex:d,endIndex:c,totalHeight:f,offsetY:m}=n.useMemo(()=>{const L=t.length*s,A=Math.ceil(a/s),T=Math.max(0,Math.floor(l/s)-r),V=Math.min(t.length,Math.ceil(l/s)+A+r),g=T*s;return{startIndex:T,endIndex:V,totalHeight:L,offsetY:g}},[t.length,a,s,l,r]),j=n.useMemo(()=>t.slice(d,c),[t,d,c]),E=n.useCallback(L=>{o(L.currentTarget.scrollTop)},[]);return{visibleData:j,totalHeight:f,offsetY:m,handleScroll:E,startIndex:d}}function wa(t,a){const[s,r]=n.useState(()=>{if(t&&typeof window<"u"){const o=localStorage.getItem(`nice-module-grid-${t}`);if(o)return JSON.parse(o)}return a||{}}),l=n.useCallback(o=>{r(d=>{const c={...d,...o};return t&&typeof window<"u"&&localStorage.setItem(`nice-module-grid-${t}`,JSON.stringify(c)),c})},[t]);return[s,l]}function ja(t){const[a,s]=n.useState(typeof window<"u"&&window.innerWidth<t);return n.useEffect(()=>{if(typeof window>"u")return;const r=()=>s(window.innerWidth<t);return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[t]),a}function Sa({column:t,sort:a,onSort:s,onResize:r,resizable:l,t:o}){const d=n.useRef(null),[c,f]=n.useState(!1),m=n.useCallback(L=>{if(!l||!r)return;L.preventDefault(),f(!0);const A=L.clientX,T=t.width||150,V=x=>{const I=x.clientX-A,b=Math.max(t.minWidth||50,T+I);r(t.field,Math.min(b,t.maxWidth||1/0))},g=()=>{f(!1),document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",V),document.addEventListener("mouseup",g)},[t,l,r]),j=a?.direction,E=j==="asc"?e.jsx(k.NiceIcon,{name:"sort-asc",size:12}):j==="desc"?e.jsx(k.NiceIcon,{name:"sort-desc",size:12}):null;return e.jsxs("div",{className:Mt("nice-module-grid__header-cell",t.sortable&&"nice-module-grid__header-cell--sortable",c&&"nice-module-grid__header-cell--resizing"),style:{...ni(t),textAlign:t.align},onClick:()=>t.sortable&&s?.(t.field),role:"columnheader","aria-sort":j==="asc"?"ascending":j==="desc"?"descending":"none",title:t.headerTooltip,children:[e.jsx("span",{className:"nice-module-grid__header-text",children:t.header}),E&&e.jsx("span",{className:"nice-module-grid__sort-indicator",children:E}),l&&e.jsx("div",{ref:d,className:"nice-module-grid__resize-handle",onMouseDown:m})]})}function Ca({column:t,row:a,rowIndex:s,value:r,locale:l="pl-PL",onClick:o}){const{t:d}=k.useNiceTranslation(),c=k.useAccessibleClick({onClick:o}),f=o?c:{},m={...ni(t),textAlign:t.align};if(t.render)return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:t.render(r,a,s)});if((t.type==="enum"||t.type==="badge")&&t.enumOptions){const j=t.enumOptions.find(E=>E.value===r);if(j)return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsxs("span",{className:Mt("nice-module-grid__badge",`nice-module-grid__badge--${j.color||"default"}`),children:[j.icon&&e.jsx("span",{className:"nice-module-grid__badge-icon",children:j.icon}),j.label]})})}if(t.type==="progress"){const j=Math.min(100,Math.max(0,Number(r)||0));return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsxs("div",{className:"nice-module-grid__progress",children:[e.jsx("div",{className:"nice-module-grid__progress-bar",children:e.jsx("div",{className:Mt("nice-module-grid__progress-fill",`nice-module-grid__progress-fill--${t.progressColor||"primary"}`),style:{width:`${j}%`}})}),e.jsxs("span",{className:"nice-module-grid__progress-text",children:[j,"%"]})]})})}if(t.type==="rating"){const j=t.maxRating||5,E=Number(r)||0;return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsx("span",{className:"nice-module-grid__rating","aria-label":d("pagination.outOfStars","{rating} out of {max} stars").replace("{rating}",String(E)).replace("{max}",String(j)),children:Array.from({length:j},(L,A)=>e.jsx("span",{className:Mt("nice-module-grid__rating-star",A<E&&"nice-module-grid__rating-star--filled"),children:e.jsx(k.NiceIcon,{name:"star",size:14})},A))})})}if(t.type==="link"&&t.linkTemplate){const j=t.linkTemplate.replace(/\{\{(\w+)\}\}/g,(E,L)=>String(xt(a,L)??""));return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsx("a",{href:j,target:t.linkNewTab?"_blank":void 0,rel:t.linkNewTab?"noopener noreferrer":void 0,className:"nice-module-grid__link",children:Jt(r,t,l)})})}if(t.type==="image"){const E={xs:24,sm:32,md:48,lg:64}[t.imageSize||"sm"];return e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:r?e.jsx("img",{src:String(r),alt:"",className:"nice-module-grid__image",style:{width:E,height:E}}):e.jsx("div",{className:"nice-module-grid__image-placeholder",style:{width:E,height:E}})})}return t.type==="avatar"?e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:r?e.jsx("img",{src:String(r),alt:"",className:"nice-module-grid__avatar"}):e.jsx("div",{className:"nice-module-grid__avatar-placeholder",children:"?"})}):t.type==="color"?e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:e.jsx("span",{className:"nice-module-grid__color-swatch",style:{backgroundColor:r||"transparent"},title:r})}):t.type==="boolean"?e.jsx("div",{className:"nice-module-grid__cell",style:{...m,textAlign:t.align||"center"},role:"gridcell",...f,children:e.jsx("span",{className:Mt("nice-module-grid__boolean",!!r&&"nice-module-grid__boolean--true"),children:e.jsx(k.NiceIcon,{name:r?"check":"close",size:14})})}):e.jsx("div",{className:"nice-module-grid__cell",style:m,role:"gridcell",...f,children:Jt(r,t,l)})}function Ia({row:t,index:a,columns:s,primaryField:r,secondaryField:l,customRender:o,selected:d,onClick:c,locale:f="pl-PL",t:m}){const j={role:"option","aria-selected":!!d,onClick:c,onKeyDown:A=>{A.target===A.currentTarget&&(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),c?.())}};if(o)return e.jsx("div",{className:Mt("nice-module-grid__mobile-card",d&&"nice-module-grid__mobile-card--selected"),...j,children:o(t,a)});const E=s.find(A=>A.field===r)||s[0],L=s.find(A=>A.field===l)||s[1];return e.jsxs("div",{className:Mt("nice-module-grid__mobile-card",d&&"nice-module-grid__mobile-card--selected"),...j,children:[e.jsxs("div",{className:"nice-module-grid__mobile-card-header",children:[e.jsx("div",{className:"nice-module-grid__mobile-card-title",children:Jt(xt(t,E?.field||""),E,f)}),L&&e.jsx("div",{className:"nice-module-grid__mobile-card-subtitle",children:Jt(xt(t,L.field),L,f)})]}),e.jsx("div",{className:"nice-module-grid__mobile-card-body",children:s.filter(A=>!A.hidden&&A.field!==r&&A.field!==l).slice(0,4).map(A=>e.jsxs("div",{className:"nice-module-grid__mobile-card-field",children:[e.jsx("span",{className:"nice-module-grid__mobile-card-label",children:A.header}),e.jsx("span",{className:"nice-module-grid__mobile-card-value",children:Jt(xt(t,A.field),A,f)})]},A.field))})]})}function Ma({page:t,pageSize:a,totalRows:s,pageSizeOptions:r,onPageChange:l,t:o}){const d=Math.ceil(s/a),c=(t-1)*a+1,f=Math.min(t*a,s);return e.jsxs("div",{className:"nice-module-grid__pagination",role:"navigation","aria-label":o("pagination.ariaLabel","Pagination"),children:[e.jsxs("div",{className:"nice-module-grid__pagination-info",children:[o("pagination.showing","Showing")," ",c,"–",f," ",o("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:m=>l(1,Number(m.target.value)),"aria-label":o("pagination.rowsPerPage","Rows per page"),children:r.map(m=>e.jsx("option",{value:m,children:m},m))}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(1,a),disabled:t===1,"aria-label":o("pagination.first","First"),children:e.jsx(k.NiceIcon,{name:"skip-back",size:14})}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(t-1,a),disabled:t===1,"aria-label":o("pagination.previous","Previous"),children:e.jsx(k.NiceIcon,{name:"chevron-left",size:14})}),e.jsxs("span",{className:"nice-module-grid__pagination-page",children:[t," / ",d]}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(t+1,a),disabled:t>=d,"aria-label":o("pagination.next","Next"),children:e.jsx(k.NiceIcon,{name:"chevron-right",size:14})}),e.jsx("button",{className:"nice-module-grid__pagination-btn",onClick:()=>l(d,a),disabled:t>=d,"aria-label":o("pagination.last","Last"),children:e.jsx(k.NiceIcon,{name:"skip-forward",size:14})})]})]})}function Da({columns:t}){return e.jsx("div",{className:"nice-module-grid__row nice-module-grid__row--skeleton",role:"row",children:t.filter(a=>!a.hidden).map(a=>e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--skeleton",style:{width:a.width==="auto"?"auto":a.width||150},children:e.jsx("div",{className:"nice-module-grid__skeleton-bar"})},a.field))})}function Ea(t,a){const{columns:s=fa,data:r,keyField:l="id",dataSource:o,onFetch:d,sortable:c=!0,sort:f,onSortChange:m,multiSort:j=!1,filter:E,searchText:L,onSearchChange:A,searchPlaceholder:T,pagination:V=!0,page:g,pageSize:x,pageSizeOptions:I=ga,totalRows:b,onPageChange:z,virtualScroll:S=!0,rowHeight:U,overscan:H=xa,selectionMode:fe="none",selectedKeys:re,onSelectionChange:ge,columnResize:Me=!0,onColumnWidthChange:J,contextMenuItems:we,onContextMenuAction:K,exportable:Le=!0,exportFormats:Ne=["csv","excel"],onExport:Fe,preferencesKey:X,initialPreferences:$,density:P="normal",striped:R=!0,bordered:_=!1,hoverable:_e=!0,loading:ce=!1,emptyState:w,toolbar:ie,onRowClick:ue,onRowDoubleClick:be,rowClassName:M,rowStyle:le,mobileCardView:xe=!0,mobileBreakpoint:ze=ya,mobileCardRender:oe,mobilePrimaryField:je,mobileSecondaryField:Oe,size:De="medium",skeletonLoading:Se=!0,skeletonRows:rt=ka,"aria-label":et,"aria-labelledby":tt,"aria-describedby":ke,className:Q,style:ye,id:Ee,testId:Ke}=t,Ae=U??ba[P],{t:ae,lang:Z}=k.useNiceTranslation();k.useNiceAccessMode(),k.useComponentDisplayStyle("table");const N=ja(ze),[ve,ee]=wa(X,$),Be=n.useRef(null),Ye=n.useRef(null),[de,Qe]=n.useState([]),[C,Y]=n.useState(),[me,$e]=n.useState(""),[qe,q]=n.useState(1),[Re,ct]=n.useState(x||pa),[Ue,Ce]=n.useState(new Set),[lt,ot]=n.useState([]),[Dt,Pt]=n.useState(0),[Vt,Kt]=n.useState(!1),[Nt,Tt]=n.useState(new Set),[nt,it]=n.useState(null),[jt,Ot]=n.useState({}),at=f??de,Et=E??C,ut=L??me,ft=g??qe,u=x??Re,h=re??Ue,D=!!(d||o),G=b??(D?Dt:r?.length??0),W=n.useMemo(()=>{const v=new Set(ve.hiddenColumns||[]);return s.filter(se=>!se.hidden&&!v.has(se.field))},[s,ve.hiddenColumns]),p=n.useMemo(()=>{if(D)return lt;if(!r)return[];let v=[...r];if(ut){const se=ut.toLowerCase(),pe=s.filter(Ie=>Ie.searchable!==!1).map(Ie=>Ie.field);v=v.filter(Ie=>pe.some(st=>{const vt=xt(Ie,st);return String(vt??"").toLowerCase().includes(se)}))}return at.length>0&&v.sort((se,pe)=>{for(const Ie of at){const st=xt(se,Ie.field),vt=xt(pe,Ie.field),kt=st<vt?-1:st>vt?1:0;if(kt!==0)return Ie.direction==="asc"?kt:-kt}return 0}),v},[D,lt,r,ut,at,s]),O=n.useMemo(()=>{if(D||!V)return p;const v=(ft-1)*u;return p.slice(v,v+u)},[D,p,V,ft,u]),te=Be.current?.clientHeight||400,F=S&&O.length>va,{visibleData:he,totalHeight:Pe,offsetY:Ve,handleScroll:Je,startIndex:yt}=Na(O,te,Ae,H),ht=F?he:O,dt=n.useCallback(async()=>{if(d){Kt(!0);try{const se=await d({page:ft,pageSize:u,sort:at,filter:Et,search:ut});ot(se.data),Pt(se.total)}catch(v){console.error("NiceModuleGrid fetch error:",v)}finally{Kt(!1)}}},[d,ft,u,at,Et,ut]);n.useEffect(()=>{D&&dt()},[D,dt]);const Rt=n.useCallback(v=>{const se=at.find(Ie=>Ie.field===v);let pe;se?se.direction==="asc"?pe=at.map(Ie=>Ie.field===v?{...Ie,direction:"desc"}:Ie):pe=at.filter(Ie=>Ie.field!==v):pe=j?[...at,{field:v,direction:"asc"}]:[{field:v,direction:"asc"}],m?m(pe):Qe(pe)},[at,j,m]),zt=n.useCallback((v,se)=>{z?z(v,se):(q(v),ct(se))},[z]),Ft=n.useCallback(v=>{A?A(v):$e(v),z||q(1)},[A,z]),Bt=n.useCallback((v,se)=>{const pe=new Set(h);if(fe==="single"?(pe.clear(),pe.add(v)):(fe==="multiple"||fe==="checkbox")&&(pe.has(v)?pe.delete(v):pe.add(v)),ge){const Ie=O.filter(st=>pe.has(String(xt(st,l))));ge(pe,Ie)}else Ce(pe)},[h,fe,ge,O,l]),cn=n.useCallback((v,se)=>{Ot(pe=>({...pe,[v]:se})),J?.(v,se),ee({columnWidths:{...ve.columnWidths,[v]:se}})},[J,ee,ve.columnWidths]),St=n.useCallback((v,se)=>{if(we?.length)if(v.preventDefault(),v.clientX===0&&v.clientY===0){const pe=v.currentTarget.getBoundingClientRect();it({x:pe.left,y:pe.bottom,row:se})}else it({x:v.clientX,y:v.clientY,row:se})},[we]),Ct=n.useRef(null);k.useOverlayFocus(Ct,{open:nt!=null,modal:!1,onClose:()=>it(null)}),k.useRovingFocus(Ct,{orientation:"vertical",wrap:!0,typeahead:!0});const $t=n.useCallback(v=>{nt&&K?.(v,nt.row),it(null)},[nt,K]),Lt=n.useCallback(async v=>{if(Fe)await Fe(v,{selectedOnly:h.size>0,columns:W.map(se=>se.field)});else if(v==="csv"){const se=W.map(mt=>mt.header).join(","),pe=O.map(mt=>W.map(en=>JSON.stringify(xt(mt,en.field)??"")).join(",")),Ie=[se,...pe].join(`
|
|
7
|
+
`),st=new Blob([Ie],{type:"text/csv;charset=utf-8;"}),vt=URL.createObjectURL(st),kt=document.createElement("a");kt.href=vt,kt.download=`export-${new Date().toISOString().slice(0,10)}.csv`,kt.click(),URL.revokeObjectURL(vt)}},[Fe,h,W,O]);n.useEffect(()=>{if(!nt)return;const v=()=>it(null);return document.addEventListener("click",v),()=>document.removeEventListener("click",v)},[nt]),k.useGridFocus(Ye,{pageSize:10});const Qt=n.useRef(null);k.useRovingFocus(Qt,{orientation:"vertical",pageSize:10});const At=ce||Vt,qt=!At&&ht.length===0,Yt=N&&xe,wt=Mt("nice-module-grid",`nice-module-grid--${P}`,`nice-module-grid--${De}`,R&&"nice-module-grid--striped",_&&"nice-module-grid--bordered",_e&&"nice-module-grid--hoverable",At&&"nice-module-grid--loading",Yt&&"nice-module-grid--mobile",Q);return e.jsxs("div",{ref:a,id:Ee,"data-testid":Ke,className:wt,style:ye,"aria-busy":At,children:[e.jsxs("div",{className:"nice-module-grid__toolbar",children:[e.jsx("div",{className:"nice-module-grid__toolbar-search",children:e.jsx("input",{type:"search",className:"nice-module-grid__search-input",placeholder:T??ae("moduleGrid.searchPlaceholder","Search…"),value:ut,onChange:v=>Ft(v.target.value),"aria-label":ae("moduleGrid.searchAriaLabel","Search")})}),ie,Le&&e.jsx("div",{className:"nice-module-grid__toolbar-export",children:Ne.map(v=>e.jsx("button",{className:"nice-module-grid__export-btn",onClick:()=>Lt(v),"aria-label":ae(`moduleGrid.export.${v}`,`Export to ${v.toUpperCase()}`),children:v.toUpperCase()},v))})]}),e.jsx("div",{ref:Be,className:"nice-module-grid__container",onScroll:F?Je:void 0,children:Yt?e.jsx("div",{ref:Qt,className:"nice-module-grid__mobile-list",role:"listbox","aria-label":et,"aria-labelledby":tt,"aria-describedby":ke,"aria-multiselectable":fe==="checkbox"||void 0,children:At&&Se?Array.from({length:rt},(v,se)=>e.jsxs("div",{className:"nice-module-grid__mobile-card nice-module-grid__mobile-card--skeleton",children:[e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"60%",height:20}}),e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"40%",height:14}}),e.jsx("div",{className:"nice-module-grid__skeleton-bar",style:{width:"80%",height:14}})]},se)):qt?e.jsxs("div",{className:"nice-module-grid__empty",children:[w?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:w.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:w?.title||ae("moduleGrid.noData","No data")}),w?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:w.description}),w?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:w.action.onClick,children:[w.action.icon,w.action.label]})]}):ht.map((v,se)=>{const pe=String(xt(v,l));return e.jsx(Ia,{row:v,index:yt+se,columns:W,primaryField:je,secondaryField:Oe,customRender:oe,selected:h.has(pe),locale:Z,onClick:()=>{fe!=="none"&&Bt(pe,v),ue?.(v,yt+se)},t:ae},pe)})}):e.jsxs("div",{ref:Ye,className:"nice-module-grid__table",role:"grid","aria-label":et,"aria-labelledby":tt,"aria-describedby":ke,"aria-rowcount":G,"aria-colcount":W.length,children:[e.jsxs("div",{className:"nice-module-grid__header",role:"row",children:[fe==="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===ht.length,onChange:()=>{if(h.size===ht.length)ge?.(new Set,[]),Ce(new Set);else{const v=new Set(ht.map(se=>String(xt(se,l))));ge?.(v,ht),Ce(v)}},"aria-label":ae("moduleGrid.selectAll","Select all")})}),W.map(v=>e.jsx(Sa,{column:{...v,width:jt[v.field]||v.width},sort:at.find(se=>se.field===v.field),onSort:c?Rt:void 0,onResize:Me?cn:void 0,resizable:Me,t:ae},v.field))]}),e.jsx("div",{className:"nice-module-grid__body",style:F?{height:Pe,position:"relative"}:void 0,children:At&&Se?Array.from({length:rt},(v,se)=>e.jsx(Da,{columns:W},se)):qt?e.jsxs("div",{className:"nice-module-grid__empty",children:[w?.icon&&e.jsx("div",{className:"nice-module-grid__empty-icon",children:w.icon}),e.jsx("div",{className:"nice-module-grid__empty-title",children:w?.title||ae("moduleGrid.noData","No data")}),w?.description&&e.jsx("div",{className:"nice-module-grid__empty-description",children:w.description}),w?.action&&e.jsxs("button",{className:"nice-module-grid__empty-action",onClick:w.action.onClick,children:[w.action.icon,w.action.label]})]}):e.jsx("div",{style:F?{transform:`translateY(${Ve}px)`}:void 0,children:ht.map((v,se)=>{const pe=String(xt(v,l)),Ie=yt+se,st=h.has(pe),vt=typeof M=="function"?M(v,Ie):M,kt=typeof le=="function"?le(v,Ie):le;return e.jsxs("div",{className:Mt("nice-module-grid__row",st&&"nice-module-grid__row--selected",vt),style:{...kt,height:Ae},role:"row","aria-rowindex":Ie+1,"aria-selected":st,onClick:()=>{fe!=="none"&&Bt(pe,v),ue?.(v,Ie)},onDoubleClick:()=>be?.(v,Ie),onContextMenu:mt=>St(mt,v),children:[fe==="checkbox"&&e.jsx("div",{className:"nice-module-grid__cell nice-module-grid__cell--checkbox",role:"gridcell",children:e.jsx("input",{type:"checkbox",checked:st,onChange:()=>Bt(pe,v),onClick:mt=>mt.stopPropagation(),"aria-label":ae("moduleGrid.selectRow","Select row")})}),W.map(mt=>e.jsx(Ca,{column:{...mt,width:jt[mt.field]||mt.width},row:v,rowIndex:Ie,value:xt(v,mt.field),locale:Z},mt.field))]},pe)})})})]})}),V&&G>0&&e.jsx(Ma,{page:ft,pageSize:u,totalRows:D?Dt:p.length,pageSizeOptions:I,onPageChange:zt,t:ae}),nt&&we&&e.jsx("div",{ref:Ct,className:"nice-module-grid__context-menu",style:{left:nt.x,top:nt.y},role:"menu",children:we.filter(v=>typeof v.hidden=="function"?!v.hidden(nt.row):!v.hidden).map(v=>{if(v.divider)return e.jsx("div",{className:"nice-module-grid__context-menu-divider"},v.key);const se=typeof v.disabled=="function"?v.disabled(nt.row):v.disabled;return e.jsxs("button",{className:Mt("nice-module-grid__context-menu-item",v.danger&&"nice-module-grid__context-menu-item--danger",se&&"nice-module-grid__context-menu-item--disabled"),onClick:()=>{se||(v.onClick?.(nt.row),$t(v.key))},disabled:se,role:"menuitem",children:[v.icon&&e.jsx("span",{className:"nice-module-grid__context-menu-icon",children:v.icon}),v.label]},v.key)})}),At&&!Se&&e.jsx("div",{className:"nice-module-grid__loading-overlay",children:e.jsx("div",{className:"nice-module-grid__spinner","aria-label":ae("moduleGrid.loading","Loading")})})]})}const Ra=n.forwardRef(Ea),_t={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},Aa=()=>e.jsxs("svg",{..._t,children:[e.jsx("path",{d:"M3 7v6h6"}),e.jsx("path",{d:"M21 17a9 9 0 0 0-15-6.7L3 13"})]}),Ta=()=>e.jsxs("svg",{..._t,children:[e.jsx("path",{d:"M21 7v6h-6"}),e.jsx("path",{d:"M3 17a9 9 0 0 1 15-6.7L21 13"})]}),za=()=>e.jsxs("svg",{..._t,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"})]}),$a=()=>e.jsxs("svg",{..._t,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"})]}),La=()=>e.jsxs("svg",{..._t,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"})]}),Pa=()=>e.jsxs("svg",{..._t,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"})]}),Oa=()=>e.jsxs("svg",{..._t,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"})]}),Fa=()=>e.jsxs("svg",{..._t,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"})]}),Va=()=>e.jsxs("svg",{..._t,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"})]}),Ka=()=>e.jsx("svg",{..._t,children:e.jsx("polyline",{points:"6 9 12 4 18 9"})}),Ba=()=>e.jsx("svg",{..._t,children:e.jsx("polyline",{points:"6 15 12 20 18 15"})}),Ua=()=>e.jsxs("svg",{..._t,style:{opacity:.55},children:[e.jsx("polyline",{points:"6 9 12 4 18 9"}),e.jsx("polyline",{points:"6 15 12 20 18 15"})]}),Ga=()=>e.jsxs("svg",{..._t,children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),Wa=()=>e.jsxs("svg",{..._t,children:[e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),e.jsx("line",{x1:"6",y1:"18",x2:"18",y2:"6"})]});function ii(t){let a="",s=t;for(;s>=0;)a=String.fromCharCode(65+s%26)+a,s=Math.floor(s/26)-1;return a}function Te(t,a){return`${ii(a)}${t+1}`}function Ze(t){const a=t.match(/^([A-Z]+)(\d+)$/);if(!a)return null;let s=0;for(let r=0;r<a[1].length;r++)s=s*26+(a[1].charCodeAt(r)-64);return{row:parseInt(a[2],10)-1,col:s-1}}function Qa(t,a,s=new Set){const r=t.startsWith("=")?t.slice(1).trim():t,l=(g,x)=>{if(!g||!x)return[];const I=[];for(let b=g.row;b<=x.row;b++)for(let z=g.col;z<=x.col;z++){const S=He(Te(b,z),a,new Set(s));typeof S=="number"&&I.push(S)}return I},o=(g,x)=>{if(!g||!x)return[];const I=[];for(let b=g.row;b<=x.row;b++)for(let z=g.col;z<=x.col;z++)I.push(He(Te(b,z),a,new Set(s)));return I},d=r.match(/^(\w+)\(([A-Z]+\d+):([A-Z]+\d+)\)$/i);if(d){const g=d[1].toUpperCase(),x=Ze(d[2].toUpperCase()),I=Ze(d[3].toUpperCase());switch(g){case"SUM":return l(x,I).reduce((z,S)=>z+S,0);case"AVG":case"AVERAGE":{const b=l(x,I);return b.length>0?b.reduce((z,S)=>z+S,0)/b.length:0}case"COUNT":return l(x,I).length;case"COUNTA":return o(x,I).filter(b=>b!==null&&b!=="").length;case"COUNTBLANK":return o(x,I).filter(b=>b===null||b==="").length;case"MIN":{const b=l(x,I);return b.length?Math.min(...b):0}case"MAX":{const b=l(x,I);return b.length?Math.max(...b):0}case"MEDIAN":{const b=l(x,I).sort((S,U)=>S-U);if(!b.length)return 0;const z=Math.floor(b.length/2);return b.length%2?b[z]:(b[z-1]+b[z])/2}case"STDEV":{const b=l(x,I);if(b.length<2)return 0;const z=b.reduce((S,U)=>S+U,0)/b.length;return Math.sqrt(b.reduce((S,U)=>S+(U-z)**2,0)/(b.length-1))}case"PRODUCT":{const b=l(x,I);return b.length?b.reduce((z,S)=>z*S,1):0}}}const c=r.match(/^(SUMIF|COUNTIF)\(([A-Z]+\d+):([A-Z]+\d+)\s*,\s*"?([^"]*)"?\)$/i);if(c){const g=c[1].toUpperCase(),x=Ze(c[2].toUpperCase()),I=Ze(c[3].toUpperCase()),b=c[4];if(x&&I){let z=0;for(let S=x.row;S<=I.row;S++)for(let U=x.col;U<=I.col;U++){const H=He(Te(S,U),a,new Set(s));(b.startsWith(">")?Number(H)>Number(b.slice(1)):b.startsWith("<")?Number(H)<Number(b.slice(1)):String(H)===b||typeof H=="number"&&H===Number(b))&&(z+=g==="SUMIF"?typeof H=="number"?H:0:1)}return z}}const f=r.match(/^IF\(([^,]+),\s*([^,]+),\s*([^)]+)\)$/i);if(f){const g=f[1].trim(),x=f[2].trim(),I=f[3].trim(),b=g.match(/^([A-Z]+\d+)\s*([><=!]+)\s*(\S+)$/i);let z=!1;if(b){const H=He(b[1].toUpperCase(),a,new Set(s)),fe=isNaN(Number(b[3]))?b[3].replace(/^"|"$/g,""):Number(b[3]),re=b[2],ge=typeof H=="number"?H:Number(H)||0,Me=typeof fe=="number"?fe:Number(fe)||0;switch(re){case">":z=ge>Me;break;case"<":z=ge<Me;break;case">=":z=ge>=Me;break;case"<=":z=ge<=Me;break;case"=":case"==":z=ge===Me;break;case"<>":case"!=":z=ge!==Me;break}}const S=z?x:I;if(Ze(S.toUpperCase()))return He(S.toUpperCase(),a,new Set(s));const U=Number(S);return isNaN(U)?S.replace(/^"|"$/g,""):U}const m=r.match(/^CONCAT\((.+)\)$/i);if(m)return m[1].split(",").map(x=>x.trim()).map(x=>{if(x.startsWith('"')&&x.endsWith('"'))return x.slice(1,-1);if(Ze(x.toUpperCase())){const b=He(x.toUpperCase(),a,new Set(s));return b!==null?String(b):""}return x}).join("");const j=r.match(/^VLOOKUP\(([^,]+),\s*([A-Z]+\d+):([A-Z]+\d+),\s*(\d+)\)$/i);if(j){let g;Ze(j[1].trim().toUpperCase())?g=He(j[1].trim().toUpperCase(),a,new Set(s)):g=isNaN(Number(j[1]))?j[1].replace(/^"|"$/g,""):Number(j[1]);const I=Ze(j[2].toUpperCase()),b=Ze(j[3].toUpperCase()),z=parseInt(j[4])-1;if(I&&b)for(let S=I.row;S<=b.row;S++){const U=He(Te(S,I.col),a,new Set(s));if(String(U)===String(g))return He(Te(S,I.col+z),a,new Set(s))}return null}const E=r.match(/^(ABS|ROUND|FLOOR|CEIL|CEILING|SQRT|LEN|UPPER|LOWER|TRIM|INT)\(([^)]+)\)$/i);if(E){const g=E[1].toUpperCase(),x=E[2].trim();let I;switch(Ze(x.toUpperCase())?I=He(x.toUpperCase(),a,new Set(s)):I=isNaN(Number(x))?x.replace(/^"|"$/g,""):Number(x),g){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=r.match(/^POWER\(([^,]+),\s*([^)]+)\)$/i);if(L){const g=Number(Ze(L[1].trim().toUpperCase())?He(L[1].trim().toUpperCase(),a,new Set(s)):L[1].trim())||0,x=Number(Ze(L[2].trim().toUpperCase())?He(L[2].trim().toUpperCase(),a,new Set(s)):L[2].trim())||0;return Math.pow(g,x)}if(/^NOW\(\)$/i.test(r))return new Date().toISOString();if(/^TODAY\(\)$/i.test(r))return new Date().toISOString().split("T")[0];if(/^PI\(\)$/i.test(r))return Math.PI;const A=r.match(/^([A-Z]+\d+)$/i);if(A)return He(A[1].toUpperCase(),a,s);const T=r.match(/^([A-Z]+\d+)\s*([+\-*/])\s*([A-Z]+\d+|\d+\.?\d*)$/i);if(T){const g=T[1].toUpperCase(),x=T[2],I=T[3],b=He(g,a,s),S=Ze(I.toUpperCase())?He(I.toUpperCase(),a,s):parseFloat(I),U=typeof b=="number"?b:0,H=typeof S=="number"?S:0;switch(x){case"+":return U+H;case"-":return U-H;case"*":return U*H;case"/":return H!==0?U/H:null}}const V=parseFloat(r);return isNaN(V)?r:V}function He(t,a,s){if(s.has(t))return null;s.add(t);const r=a[t];return r?r.formula?Qa(r.formula,a,s):r.value:null}function Yn(t,a){return t==null?"":a==="percent"&&typeof t=="number"?`${(t*100).toFixed(1)}%`:a==="currency"&&typeof t=="number"?`$${t.toFixed(2)}`:String(t)}function Hn(t){return{name:t,data:{}}}const qa=Object.assign(n.forwardRef(({sheets:t,activeSheet:a,rows:s=50,cols:r=26,showToolbar:l=!0,showFormulaBar:o=!0,showSheetTabs:d=!0,readOnly:c=!1,disabled:f=!1,loading:m=!1,error:j,size:E="md",onChange:L,onActiveSheetChange:A,onCellSelect:T,onCopy:V,onPaste:g,onInsert:x,onRemove:I,maxUndo:b=50,sortable:z=!1,filterable:S=!1,rangeSelection:U=!0,className:H,style:fe,id:re,...ge},Me)=>{const J=c||f,we=k.useControlId(re),{t:K}=k.useNiceTranslation(),[Le,Ne]=n.useState(()=>t??[Hn(K("spreadsheet.sheet","Sheet")+" 1")]),[Fe,X]=n.useState(0),$=t??Le,P=a??Fe,R=$[P]??$[0],[_,_e]=n.useState(null),[ce,w]=n.useState(null),[ie,ue]=n.useState(!1),[be,M]=n.useState(null),[le,xe]=n.useState(""),ze=n.useRef(null),oe=n.useRef(null),[je,Oe]=n.useState([]),[De,Se]=n.useState([]),[rt,et]=n.useState(null),tt=n.useRef({x:0,width:80}),[ke,Q]=n.useState(null),[ye,Ee]=n.useState(null),Ke=n.useRef(null);k.useRovingFocus(Ke,{orientation:"horizontal",wrap:!0,activateOnMove:!0});const[Ae,ae]=n.useState("");n.useEffect(()=>{be&&ze.current&&ze.current.focus()},[be]);const Z=n.useMemo(()=>{if(!_)return null;const u=ce??_;return{startRow:Math.min(_.row,u.row),startCol:Math.min(_.col,u.col),endRow:Math.max(_.row,u.row),endCol:Math.max(_.col,u.col)}},[_,ce]),N=n.useCallback((u,h)=>Z?u>=Z.startRow&&u<=Z.endRow&&h>=Z.startCol&&h<=Z.endCol:!1,[Z]),ve=n.useCallback(u=>{Oe(h=>{const D=[...h,u.map(G=>({...G,data:{...G.data}}))];return D.length>b?D.slice(-b):D}),Se([])},[b]),ee=n.useCallback((u,h=!0)=>{h&&ve($);const D=u($);t||Ne(D),L?.(D)},[$,t,L,ve]),Be=n.useCallback(()=>{if(je.length===0)return;const u=je[je.length-1];Se(h=>[...h,$.map(D=>({...D,data:{...D.data}}))]),Oe(h=>h.slice(0,-1)),t||Ne(u),L?.(u)},[je,$,t,L]),Ye=n.useCallback(()=>{if(De.length===0)return;const u=De[De.length-1];Oe(h=>[...h,$.map(D=>({...D,data:{...D.data}}))]),Se(h=>h.slice(0,-1)),t||Ne(u),L?.(u)},[De,$,t,L]),de=n.useCallback(u=>{a||X(u),A?.(u),_e(null),w(null),M(null)},[a,A]),Qe=n.useCallback((u,h,D)=>{const G=Te(u,h);ee(W=>{const p=W.map((te,F)=>F===P?{...te,data:{...te.data}}:te),O=D.startsWith("=");return p[P].data[G]={...p[P].data[G]??{value:null},formula:O?D:void 0,value:O?null:isNaN(Number(D))?D:Number(D)},p})},[P,ee]),C=n.useCallback((u,h,D)=>{D?.shiftKey&&U&&_?w({row:u,col:h}):(_e({row:u,col:h}),w(null)),M(null),T?.(P,u,h)},[P,T,U,_]),Y=n.useCallback((u,h,D)=>{D.button===0&&(C(u,h,D),U&&!D.shiftKey&&ue(!0))},[C,U]),me=n.useCallback((u,h)=>{ie&&w({row:u,col:h})},[ie]);n.useEffect(()=>{if(!ie)return;const u=()=>ue(!1);return document.addEventListener("mouseup",u),()=>document.removeEventListener("mouseup",u)},[ie]);const $e=n.useCallback((u,h)=>{if(J)return;const D=Te(u,h),G=R.data[D];G?.readOnly||(M({row:u,col:h}),xe(G?.formula??(G?.value!=null?String(G.value):"")))},[J,R.data]),qe=n.useCallback(()=>{be&&(Qe(be.row,be.col,le),M(null))},[be,le,Qe]),q=n.useCallback(u=>{if(u.key==="Enter")qe();else if(u.key==="Escape")M(null);else if(u.key==="Tab"&&be&&(u.preventDefault(),qe(),_)){const h=u.shiftKey?Math.max(0,_.col-1):Math.min(r-1,_.col+1);_e({row:_.row,col:h})}},[qe,_,r,be]),Re=n.useCallback((u,h)=>{if(!_)return;const D=Z??{startRow:_.row,startCol:_.col,endRow:_.row,endCol:_.col};ee(G=>{const W=G.map((p,O)=>O===P?{...p,data:{...p.data}}:p);for(let p=D.startRow;p<=D.endRow;p++)for(let O=D.startCol;O<=D.endCol;O++){const te=Te(p,O);W[P].data[te]={...W[P].data[te]??{value:null},[u]:h}}return W})},[_,Z,P,ee]),ct=n.useCallback(u=>{if(!Z||V?.(Z)===!1)return;const{startRow:h,startCol:D,endRow:G,endCol:W}=Z,p=[];for(let O=h;O<=G;O++){const te=[];for(let F=D;F<=W;F++){const he=Te(O,F),Pe=R.data[he],Ve=Pe?He(he,R.data,new Set):null;te.push(Yn(Ve,Pe?.format))}p.push(te.join(" "))}u.clipboardData.setData("text/plain",p.join(`
|
|
8
8
|
`)),u.preventDefault()},[Z,R.data,V]),Ue=n.useCallback(u=>{if(J||!_)return;const h=u.clipboardData.getData("text/plain");if(!h)return;const D=h.split(`
|
|
9
|
-
`).map(G=>G.split(" "));g?.(D,_.row,_.col)!==!1&&(ee(G=>{const W=G.map((p,O)=>O===P?{...p,data:{...p.data}}:p);return D.forEach((p,O)=>{p.forEach((te,F)=>{const he=Te(_.row+O,_.col+F),Pe=te.startsWith("=");W[P].data[he]={...W[P].data[he]??{value:null},formula:Pe?te:void 0,value:Pe?null:isNaN(Number(te))?te:Number(te)}})}),W}),u.preventDefault())},[J,_,P,ee,g]),Ce=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&(F.row>u?p[Te(F.row+1,F.col)]=te:p[O]=te)}return{...G,data:p}})),x?.("row",u)},[P,ee,x]),lt=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&(F.col>u?p[Te(F.row,F.col+1)]=te:p[O]=te)}return{...G,data:p}})),x?.("column",u)},[P,ee,x]),ot=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&F.row!==u&&(F.row>u?p[Te(F.row-1,F.col)]=te:p[O]=te)}return{...G,data:p}})),I?.("row",u)},[P,ee,I]),Dt=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&F.col!==u&&(F.col>u?p[Te(F.row,F.col-1)]=te:p[O]=te)}return{...G,data:p}})),I?.("column",u)},[P,ee,I]),Pt=n.useCallback((u,h)=>{ee(D=>D.map((W,p)=>{if(p!==P)return W;const O=new Map;for(const[he,Pe]of Object.entries(W.data)){const Ve=Ze(he);Ve&&(O.has(Ve.row)||O.set(Ve.row,{}),O.get(Ve.row)[Ve.col]=Pe)}const te=Array.from(O.entries()).sort((he,Pe)=>{const Ve=He(Te(he[0],u),W.data,new Set),Je=He(Te(Pe[0],u),W.data,new Set),yt=typeof Ve=="number"?Ve:Number(Ve),ht=typeof Je=="number"?Je:Number(Je);if(!isNaN(yt)&&!isNaN(ht))return h==="asc"?yt-ht:ht-yt;const dt=String(Ve??""),Rt=String(Je??"");return h==="asc"?dt.localeCompare(Rt):Rt.localeCompare(dt)}),F={};return te.forEach(([,he],Pe)=>{for(const[Ve,Je]of Object.entries(he))F[Te(Pe,Number(Ve))]=Je}),{...W,data:F,sortColumn:u,sortDirection:h}}))},[P,ee]),Vt=n.useCallback((u,h)=>{const D=R.conditionalFormats;if(!D?.length)return;const G=Te(u,h),W=He(G,R.data,new Set),p=typeof W=="number"?W:Number(W);for(const O of D){const te=O.range.match(/^([A-Z]+\d+):([A-Z]+\d+)$/i);if(!te)continue;const F=Ze(te[1].toUpperCase()),he=Ze(te[2].toUpperCase());if(!F||!he||u<F.row||u>he.row||h<F.col||h>he.col)continue;let Pe=!1;switch(O.type){case"greaterThan":Pe=!isNaN(p)&&p>Number(O.value);break;case"lessThan":Pe=!isNaN(p)&&p<Number(O.value);break;case"equalTo":Pe=String(W)===String(O.value);break;case"between":Pe=!isNaN(p)&&p>=Number(O.value)&&p<=Number(O.value2);break;case"textContains":Pe=String(W).includes(String(O.value));break;case"isEmpty":Pe=W===null||W==="";break;case"isNotEmpty":Pe=W!==null&&W!=="";break}if(Pe)return{backgroundColor:O.style.bgColor,color:O.style.color,fontWeight:O.style.bold?"bold":void 0,fontStyle:O.style.italic?"italic":void 0}}},[R.conditionalFormats,R.data]),Kt=n.useCallback(()=>{const u=`${K("spreadsheet.sheet","Sheet")} ${$.length+1}`;ee(h=>[...h,Hn(u)]),de($.length)},[$.length,ee,de,K]),Nt=n.useCallback(()=>{$.length<=1||(ee(u=>u.filter((h,D)=>D!==P)),de(Math.max(0,P-1)))},[$.length,P,ee,de]),Tt=n.useCallback((u,h)=>{h.trim()&&(ee(D=>D.map((G,W)=>W===u?{...G,name:h.trim()}:G),!1),Ee(null))},[ee]),nt=n.useMemo(()=>{if(!_)return"";const u=Te(_.row,_.col),h=R.data[u];return h?.formula??(h?.value!=null?String(h.value):"")},[_,R.data]),it=n.useMemo(()=>{if(!Z)return null;const{startRow:u,startCol:h,endRow:D,endCol:G}=Z;if(u===D&&h===G)return null;const W=[];let p=0;for(let O=u;O<=D;O++)for(let te=h;te<=G;te++){const F=Te(O,te),he=He(F,R.data,new Set);he!==null&&he!==""&&p++,typeof he=="number"&&W.push(he)}return W.length===0?{count:p}:{count:p,sum:W.reduce((O,te)=>O+te,0),avg:W.reduce((O,te)=>O+te,0)/W.length,min:Math.min(...W),max:Math.max(...W)}},[Z,R.data]),jt=n.useCallback((u,h)=>{h.preventDefault(),h.stopPropagation(),et(u),tt.current={x:h.clientX,width:R.colWidths?.[u]??80}},[R.colWidths]);n.useEffect(()=>{if(rt===null)return;const u=D=>{const G=D.clientX-tt.current.x,W=Math.max(30,tt.current.width+G);ee(p=>p.map((te,F)=>F===P?{...te,colWidths:{...te.colWidths,[rt]:W}}:te),!1)},h=()=>et(null);return document.addEventListener("mousemove",u),document.addEventListener("mouseup",h),()=>{document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",h)}},[rt,P,ee]);const Ot=n.useCallback((u,h,D)=>{u.preventDefault(),_e({row:h,col:D}),Q({x:u.clientX,y:u.clientY})},[]);n.useEffect(()=>{if(!ke)return;const u=()=>Q(null);return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[ke]);const at=n.useCallback(u=>{if((u.ctrlKey||u.metaKey)&&!be){if(u.key==="z"){u.preventDefault(),Be();return}if(u.key==="y"){u.preventDefault(),Ye();return}}if(be||!_)return;let{row:h,col:D}=_;switch(u.key){case"ArrowUp":h=Math.max(0,h-1);break;case"ArrowDown":h=Math.min(s-1,h+1);break;case"ArrowLeft":D=Math.max(0,D-1);break;case"ArrowRight":D=Math.min(r-1,D+1);break;case"Home":D=0,h=u.ctrlKey||u.metaKey?0:h;break;case"End":D=r-1,h=u.ctrlKey||u.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":$e(h,D);return;case"Delete":case"Backspace":J||(Z&&(Z.startRow!==Z.endRow||Z.startCol!==Z.endCol)?ee(G=>{const W=G.map((p,O)=>O===P?{...p,data:{...p.data}}:p);for(let p=Z.startRow;p<=Z.endRow;p++)for(let O=Z.startCol;O<=Z.endCol;O++)delete W[P].data[Te(p,O)];return W}):Qe(h,D,""));return;default:if(u.key.length===1&&!u.ctrlKey&&!u.metaKey&&!J){M({row:h,col:D}),xe(u.key);return}return}u.preventDefault(),u.shiftKey&&U?w({row:h,col:D}):(_e({row:h,col:D}),w(null)),T?.(P,h,D)},[be,_,s,r,J,$e,Qe,P,T,Be,Ye,Z,ee,U]),Et=R.frozenRows??0,ut=R.frozenCols??0,ft=[{value:"text",label:K("spreadsheet.formatText","Text")},{value:"number",label:K("spreadsheet.formatNumber","Number")},{value:"percent",label:K("spreadsheet.formatPercent","Percent")},{value:"currency",label:K("spreadsheet.formatCurrency","Currency")},{value:"date",label:K("spreadsheet.formatDate","Date")}];return e.jsxs("div",{ref:Me,id:we,className:`nice-spreadsheet nice-spreadsheet--${E} ${c&&!f?"nice-spreadsheet--readonly":""} ${f?"nice-spreadsheet--disabled":""} ${m?"nice-spreadsheet--loading":""} ${j?"nice-spreadsheet--error":""} ${H??""}`,style:{...fe,position:m?"relative":fe?.position},onKeyDown:at,onCopy:ct,onPaste:Ue,tabIndex:f?-1:0,role:"application","aria-label":K("spreadsheet.label","Spreadsheet"),"aria-disabled":f||void 0,"aria-busy":m||void 0,...ge,children:[j&&e.jsx("div",{className:"nice-spreadsheet__error",role:"alert",children:j}),m&&e.jsx("span",{className:"nice-spreadsheet__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),l&&!J&&e.jsxs("div",{className:"nice-spreadsheet__toolbar",role:"toolbar",children:[e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Be,disabled:je.length===0,title:K("spreadsheet.undo","Undo"),children:e.jsx(Ta,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Ye,disabled:De.length===0,title:K("spreadsheet.redo","Redo"),children:e.jsx(za,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(We.NiceButton,{variant:R.data[_?Te(_.row,_.col):""]?.bold?"primary":"ghost",size:"sm",onClick:()=>Re("bold",!R.data[_?Te(_.row,_.col):""]?.bold),title:K("spreadsheet.bold","Bold"),children:e.jsx("strong",{children:"B"})}),e.jsx(We.NiceButton,{variant:R.data[_?Te(_.row,_.col):""]?.italic?"primary":"ghost",size:"sm",onClick:()=>Re("italic",!R.data[_?Te(_.row,_.col):""]?.italic),title:K("spreadsheet.italic","Italic"),children:e.jsx("em",{children:"I"})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>Re("align","left"),title:K("spreadsheet.alignLeft","Align left"),children:e.jsx($a,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>Re("align","center"),title:K("spreadsheet.alignCenter","Center"),children:e.jsx(La,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>Re("align","right"),title:K("spreadsheet.alignRight","Align right"),children:e.jsx(Pa,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Un.NiceColorPicker,{value:R.data[_?Te(_.row,_.col):""]?.bgColor??"var(--nice-bg-primary, #ffffff)",onChange:u=>Re("bgColor",u),title:K("spreadsheet.bgColor","Background color"),showInput:!1,showRandom:!1}),e.jsx(Un.NiceColorPicker,{value:R.data[_?Te(_.row,_.col):""]?.color??"var(--nice-text-primary, #000000)",onChange:u=>Re("color",u),title:K("spreadsheet.textColor","Text color"),showInput:!1,showRandom:!1}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(ji.NiceSelect,{size:"sm",value:R.data[_?Te(_.row,_.col):""]?.format??"text",onChange:u=>Re("format",u),options:ft,"aria-label":K("spreadsheet.format","Cell format")}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&&Ce(_.row),title:K("spreadsheet.insertRow","Insert row"),children:e.jsx(Oa,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&<(_.col),title:K("spreadsheet.insertCol","Insert column"),children:e.jsx(Fa,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&&ot(_.row),title:K("spreadsheet.deleteRow","Delete row"),children:e.jsx(Va,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&&Dt(_.col),title:K("spreadsheet.deleteCol","Delete column"),children:e.jsx(Ka,{})})]}),o&&e.jsxs("div",{className:"nice-spreadsheet__formula-bar",children:[e.jsxs("span",{className:"nice-spreadsheet__cell-label",children:[_?Te(_.row,_.col):"",Z&&Z.startRow!==Z.endRow||Z&&Z.startCol!==Z.endCol?`:${Te(Z.endRow,Z.endCol)}`:""]}),e.jsx(Bn.NiceTextInput,{className:"nice-spreadsheet__formula-input",value:be?le:nt,onChange:u=>{be?xe(u):_&&(M(_),xe(u))},onKeyDown:q,readOnly:J,"aria-label":K("spreadsheet.formulaBar","Formula bar")})]}),e.jsx("div",{className:"nice-spreadsheet__grid",ref:oe,children:e.jsxs("table",{role:"grid","aria-label":R.name,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-spreadsheet__corner"}),Array.from({length:r},(u,h)=>e.jsxs("th",{className:`nice-spreadsheet__col-header ${h<ut?"nice-spreadsheet__col-header--frozen":""}`,style:{width:R.colWidths?.[h]??80,position:h<ut?"sticky":void 0,left:h<ut?h*80+40:void 0,zIndex:h<ut?3:void 0},children:[e.jsx("span",{children:ii(h)}),z&&e.jsx("span",{role:"button",tabIndex:0,onKeyDown:k.clickOnActivationKey,className:"nice-spreadsheet__sort-trigger",onClick:()=>Pt(h,R.sortColumn===h&&R.sortDirection==="asc"?"desc":"asc"),title:K("spreadsheet.sort","Sort"),children:R.sortColumn===h?R.sortDirection==="asc"?e.jsx(Ba,{}):e.jsx(Ua,{}):e.jsx(Ga,{})}),!J&&e.jsx("span",{className:"nice-spreadsheet__col-resize",onMouseDown:D=>jt(h,D)})]},h))]})}),e.jsx("tbody",{children:Array.from({length:s},(u,h)=>e.jsxs("tr",{className:h<Et?"nice-spreadsheet__row--frozen":"",style:h<Et?{position:"sticky",top:h*24,zIndex:2}:void 0,children:[e.jsx("td",{className:"nice-spreadsheet__row-header",children:h+1}),Array.from({length:r},(D,G)=>{const W=Te(h,G),p=R.data[W];if(p?.mergedInto)return null;const O=_?.row===h&&_?.col===G,te=N(h,G),F=be?.row===h&&be?.col===G,he=p?He(W,R.data,new Set):null,Pe=Vt(h,G),Ve=h<Et||G<ut;return e.jsxs("td",{className:`nice-spreadsheet__cell ${O?"nice-spreadsheet__cell--selected":""} ${te&&!O?"nice-spreadsheet__cell--in-range":""} ${p?.readOnly?"nice-spreadsheet__cell--readonly":""} ${Ve?"nice-spreadsheet__cell--frozen":""}`,style:{textAlign:p?.align,fontWeight:p?.bold?"bold":void 0,fontStyle:p?.italic?"italic":void 0,backgroundColor:Pe?.backgroundColor??p?.bgColor,color:Pe?.color??p?.color,width:R.colWidths?.[G],height:R.rowHeights?.[h],position:Ve?"sticky":void 0,left:G<ut?G*80+40:void 0,zIndex:Ve?1:void 0,...Pe},colSpan:p?.colSpan,rowSpan:p?.rowSpan,onMouseDown:Je=>Y(h,G,Je),onMouseEnter:()=>me(h,G),onDoubleClick:()=>$e(h,G),onContextMenu:Je=>Ot(Je,h,G),role:"gridcell","aria-selected":O,title:p?.comment,children:[p?.comment&&e.jsx("span",{className:"nice-spreadsheet__comment-indicator"}),F?e.jsx("input",{ref:ze,className:"nice-spreadsheet__cell-editor",value:le,onChange:Je=>xe(Je.target.value),onKeyDown:q,onBlur:qe}):Yn(he,p?.format)]},G)})]},h))})]})}),ke&&!J&&_&&e.jsxs("div",{className:"nice-spreadsheet__context-menu",style:{position:"fixed",left:ke.x,top:ke.y,zIndex:1e3},children:[e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Ce(_.row),Q(null)},children:K("spreadsheet.insertRowAbove","Insert row above")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Ce(_.row+1),Q(null)},children:K("spreadsheet.insertRowBelow","Insert row below")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{lt(_.col),Q(null)},children:K("spreadsheet.insertColLeft","Insert column left")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{lt(_.col+1),Q(null)},children:K("spreadsheet.insertColRight","Insert column right")}),e.jsx("hr",{className:"nice-spreadsheet__context-sep"}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{ot(_.row),Q(null)},children:K("spreadsheet.deleteRow","Delete row")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Dt(_.col),Q(null)},children:K("spreadsheet.deleteCol","Delete column")})]}),it&&e.jsxs("div",{className:"nice-spreadsheet__status-bar",children:[e.jsxs("span",{children:[K("spreadsheet.count","Count"),": ",it.count]}),it.sum!==void 0&&e.jsxs("span",{children:[K("spreadsheet.sum","Sum"),": ",it.sum.toFixed(2)]}),it.avg!==void 0&&e.jsxs("span",{children:[K("spreadsheet.avg","Avg"),": ",it.avg.toFixed(2)]}),it.min!==void 0&&e.jsxs("span",{children:[K("spreadsheet.min","Min"),": ",it.min]}),it.max!==void 0&&e.jsxs("span",{children:[K("spreadsheet.max","Max"),": ",it.max]})]}),d&&e.jsxs("div",{className:"nice-spreadsheet__tabs",role:"tablist",ref:Ke,children:[$.map((u,h)=>e.jsx("span",{className:"nice-spreadsheet__tab-wrapper",children:ye===h?e.jsx(Bn.NiceTextInput,{className:"nice-spreadsheet__tab-rename",value:Ae,onChange:D=>ae(D),onBlur:()=>Tt(h,Ae),onKeyDown:D=>{D.key==="Enter"&&Tt(h,Ae),D.key==="Escape"&&Ee(null)},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>{J||(Ee(h),ae(u.name))},children:e.jsx(We.NiceButton,{variant:h===P?"primary":"ghost",size:"sm",role:"tab","aria-selected":h===P,onClick:()=>de(h),onKeyDown:D=>{D.key==="F2"&&!J&&(D.preventDefault(),Ee(h),ae(u.name))},children:u.name})})},h)),!J&&e.jsxs(e.Fragment,{children:[e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Kt,title:K("spreadsheet.addSheet","Add sheet"),children:e.jsx(Wa,{})}),$.length>1&&e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Nt,title:K("spreadsheet.removeSheet","Remove sheet"),children:e.jsx(Qa,{})})]})]})]})}),{displayName:"NiceSpreadsheet"}),Ha=`
|
|
9
|
+
`).map(G=>G.split(" "));g?.(D,_.row,_.col)!==!1&&(ee(G=>{const W=G.map((p,O)=>O===P?{...p,data:{...p.data}}:p);return D.forEach((p,O)=>{p.forEach((te,F)=>{const he=Te(_.row+O,_.col+F),Pe=te.startsWith("=");W[P].data[he]={...W[P].data[he]??{value:null},formula:Pe?te:void 0,value:Pe?null:isNaN(Number(te))?te:Number(te)}})}),W}),u.preventDefault())},[J,_,P,ee,g]),Ce=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&(F.row>u?p[Te(F.row+1,F.col)]=te:p[O]=te)}return{...G,data:p}})),x?.("row",u)},[P,ee,x]),lt=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&(F.col>u?p[Te(F.row,F.col+1)]=te:p[O]=te)}return{...G,data:p}})),x?.("column",u)},[P,ee,x]),ot=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&F.row!==u&&(F.row>u?p[Te(F.row-1,F.col)]=te:p[O]=te)}return{...G,data:p}})),I?.("row",u)},[P,ee,I]),Dt=n.useCallback(u=>{ee(h=>h.map((G,W)=>{if(W!==P)return G;const p={};for(const[O,te]of Object.entries(G.data)){const F=Ze(O);F&&F.col!==u&&(F.col>u?p[Te(F.row,F.col-1)]=te:p[O]=te)}return{...G,data:p}})),I?.("column",u)},[P,ee,I]),Pt=n.useCallback((u,h)=>{ee(D=>D.map((W,p)=>{if(p!==P)return W;const O=new Map;for(const[he,Pe]of Object.entries(W.data)){const Ve=Ze(he);Ve&&(O.has(Ve.row)||O.set(Ve.row,{}),O.get(Ve.row)[Ve.col]=Pe)}const te=Array.from(O.entries()).sort((he,Pe)=>{const Ve=He(Te(he[0],u),W.data,new Set),Je=He(Te(Pe[0],u),W.data,new Set),yt=typeof Ve=="number"?Ve:Number(Ve),ht=typeof Je=="number"?Je:Number(Je);if(!isNaN(yt)&&!isNaN(ht))return h==="asc"?yt-ht:ht-yt;const dt=String(Ve??""),Rt=String(Je??"");return h==="asc"?dt.localeCompare(Rt):Rt.localeCompare(dt)}),F={};return te.forEach(([,he],Pe)=>{for(const[Ve,Je]of Object.entries(he))F[Te(Pe,Number(Ve))]=Je}),{...W,data:F,sortColumn:u,sortDirection:h}}))},[P,ee]),Vt=n.useCallback((u,h)=>{const D=R.conditionalFormats;if(!D?.length)return;const G=Te(u,h),W=He(G,R.data,new Set),p=typeof W=="number"?W:Number(W);for(const O of D){const te=O.range.match(/^([A-Z]+\d+):([A-Z]+\d+)$/i);if(!te)continue;const F=Ze(te[1].toUpperCase()),he=Ze(te[2].toUpperCase());if(!F||!he||u<F.row||u>he.row||h<F.col||h>he.col)continue;let Pe=!1;switch(O.type){case"greaterThan":Pe=!isNaN(p)&&p>Number(O.value);break;case"lessThan":Pe=!isNaN(p)&&p<Number(O.value);break;case"equalTo":Pe=String(W)===String(O.value);break;case"between":Pe=!isNaN(p)&&p>=Number(O.value)&&p<=Number(O.value2);break;case"textContains":Pe=String(W).includes(String(O.value));break;case"isEmpty":Pe=W===null||W==="";break;case"isNotEmpty":Pe=W!==null&&W!=="";break}if(Pe)return{backgroundColor:O.style.bgColor,color:O.style.color,fontWeight:O.style.bold?"bold":void 0,fontStyle:O.style.italic?"italic":void 0}}},[R.conditionalFormats,R.data]),Kt=n.useCallback(()=>{const u=`${K("spreadsheet.sheet","Sheet")} ${$.length+1}`;ee(h=>[...h,Hn(u)]),de($.length)},[$.length,ee,de,K]),Nt=n.useCallback(()=>{$.length<=1||(ee(u=>u.filter((h,D)=>D!==P)),de(Math.max(0,P-1)))},[$.length,P,ee,de]),Tt=n.useCallback((u,h)=>{h.trim()&&(ee(D=>D.map((G,W)=>W===u?{...G,name:h.trim()}:G),!1),Ee(null))},[ee]),nt=n.useMemo(()=>{if(!_)return"";const u=Te(_.row,_.col),h=R.data[u];return h?.formula??(h?.value!=null?String(h.value):"")},[_,R.data]),it=n.useMemo(()=>{if(!Z)return null;const{startRow:u,startCol:h,endRow:D,endCol:G}=Z;if(u===D&&h===G)return null;const W=[];let p=0;for(let O=u;O<=D;O++)for(let te=h;te<=G;te++){const F=Te(O,te),he=He(F,R.data,new Set);he!==null&&he!==""&&p++,typeof he=="number"&&W.push(he)}return W.length===0?{count:p}:{count:p,sum:W.reduce((O,te)=>O+te,0),avg:W.reduce((O,te)=>O+te,0)/W.length,min:Math.min(...W),max:Math.max(...W)}},[Z,R.data]),jt=n.useCallback((u,h)=>{h.preventDefault(),h.stopPropagation(),et(u),tt.current={x:h.clientX,width:R.colWidths?.[u]??80}},[R.colWidths]);n.useEffect(()=>{if(rt===null)return;const u=D=>{const G=D.clientX-tt.current.x,W=Math.max(30,tt.current.width+G);ee(p=>p.map((te,F)=>F===P?{...te,colWidths:{...te.colWidths,[rt]:W}}:te),!1)},h=()=>et(null);return document.addEventListener("mousemove",u),document.addEventListener("mouseup",h),()=>{document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",h)}},[rt,P,ee]);const Ot=n.useCallback((u,h,D)=>{u.preventDefault(),_e({row:h,col:D}),Q({x:u.clientX,y:u.clientY})},[]);n.useEffect(()=>{if(!ke)return;const u=()=>Q(null);return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[ke]);const at=n.useCallback(u=>{if((u.ctrlKey||u.metaKey)&&!be){if(u.key==="z"){u.preventDefault(),Be();return}if(u.key==="y"){u.preventDefault(),Ye();return}}if(be||!_)return;let{row:h,col:D}=_;switch(u.key){case"ArrowUp":h=Math.max(0,h-1);break;case"ArrowDown":h=Math.min(s-1,h+1);break;case"ArrowLeft":D=Math.max(0,D-1);break;case"ArrowRight":D=Math.min(r-1,D+1);break;case"Home":D=0,h=u.ctrlKey||u.metaKey?0:h;break;case"End":D=r-1,h=u.ctrlKey||u.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":$e(h,D);return;case"Delete":case"Backspace":J||(Z&&(Z.startRow!==Z.endRow||Z.startCol!==Z.endCol)?ee(G=>{const W=G.map((p,O)=>O===P?{...p,data:{...p.data}}:p);for(let p=Z.startRow;p<=Z.endRow;p++)for(let O=Z.startCol;O<=Z.endCol;O++)delete W[P].data[Te(p,O)];return W}):Qe(h,D,""));return;default:if(u.key.length===1&&!u.ctrlKey&&!u.metaKey&&!J){M({row:h,col:D}),xe(u.key);return}return}u.preventDefault(),u.shiftKey&&U?w({row:h,col:D}):(_e({row:h,col:D}),w(null)),T?.(P,h,D)},[be,_,s,r,J,$e,Qe,P,T,Be,Ye,Z,ee,U]),Et=R.frozenRows??0,ut=R.frozenCols??0,ft=[{value:"text",label:K("spreadsheet.formatText","Text")},{value:"number",label:K("spreadsheet.formatNumber","Number")},{value:"percent",label:K("spreadsheet.formatPercent","Percent")},{value:"currency",label:K("spreadsheet.formatCurrency","Currency")},{value:"date",label:K("spreadsheet.formatDate","Date")}];return e.jsxs("div",{ref:Me,id:we,className:`nice-spreadsheet nice-spreadsheet--${E} ${c&&!f?"nice-spreadsheet--readonly":""} ${f?"nice-spreadsheet--disabled":""} ${m?"nice-spreadsheet--loading":""} ${j?"nice-spreadsheet--error":""} ${H??""}`,style:{...fe,position:m?"relative":fe?.position},onKeyDown:at,onCopy:ct,onPaste:Ue,tabIndex:f?-1:0,role:"application","aria-label":K("spreadsheet.label","Spreadsheet"),"aria-disabled":f||void 0,"aria-busy":m||void 0,...ge,children:[j&&e.jsx("div",{className:"nice-spreadsheet__error",role:"alert",children:j}),m&&e.jsx("span",{className:"nice-spreadsheet__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),l&&!J&&e.jsxs("div",{className:"nice-spreadsheet__toolbar",role:"toolbar",children:[e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Be,disabled:je.length===0,title:K("spreadsheet.undo","Undo"),children:e.jsx(Aa,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Ye,disabled:De.length===0,title:K("spreadsheet.redo","Redo"),children:e.jsx(Ta,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(We.NiceButton,{variant:R.data[_?Te(_.row,_.col):""]?.bold?"primary":"ghost",size:"sm",onClick:()=>Re("bold",!R.data[_?Te(_.row,_.col):""]?.bold),title:K("spreadsheet.bold","Bold"),children:e.jsx("strong",{children:"B"})}),e.jsx(We.NiceButton,{variant:R.data[_?Te(_.row,_.col):""]?.italic?"primary":"ghost",size:"sm",onClick:()=>Re("italic",!R.data[_?Te(_.row,_.col):""]?.italic),title:K("spreadsheet.italic","Italic"),children:e.jsx("em",{children:"I"})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>Re("align","left"),title:K("spreadsheet.alignLeft","Align left"),children:e.jsx(za,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>Re("align","center"),title:K("spreadsheet.alignCenter","Center"),children:e.jsx($a,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>Re("align","right"),title:K("spreadsheet.alignRight","Align right"),children:e.jsx(La,{})}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(Un.NiceColorPicker,{value:R.data[_?Te(_.row,_.col):""]?.bgColor??"var(--nice-bg-primary, #ffffff)",onChange:u=>Re("bgColor",u),title:K("spreadsheet.bgColor","Background color"),showInput:!1,showRandom:!1}),e.jsx(Un.NiceColorPicker,{value:R.data[_?Te(_.row,_.col):""]?.color??"var(--nice-text-primary, #000000)",onChange:u=>Re("color",u),title:K("spreadsheet.textColor","Text color"),showInput:!1,showRandom:!1}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(vn.NiceSelect,{size:"sm",value:R.data[_?Te(_.row,_.col):""]?.format??"text",onChange:u=>Re("format",u),options:ft,"aria-label":K("spreadsheet.format","Cell format")}),e.jsx("span",{className:"nice-spreadsheet__separator"}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&&Ce(_.row),title:K("spreadsheet.insertRow","Insert row"),children:e.jsx(Pa,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&<(_.col),title:K("spreadsheet.insertCol","Insert column"),children:e.jsx(Oa,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&&ot(_.row),title:K("spreadsheet.deleteRow","Delete row"),children:e.jsx(Fa,{})}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>_&&Dt(_.col),title:K("spreadsheet.deleteCol","Delete column"),children:e.jsx(Va,{})})]}),o&&e.jsxs("div",{className:"nice-spreadsheet__formula-bar",children:[e.jsxs("span",{className:"nice-spreadsheet__cell-label",children:[_?Te(_.row,_.col):"",Z&&Z.startRow!==Z.endRow||Z&&Z.startCol!==Z.endCol?`:${Te(Z.endRow,Z.endCol)}`:""]}),e.jsx(vn.NiceTextInput,{className:"nice-spreadsheet__formula-input",value:be?le:nt,onChange:u=>{be?xe(u):_&&(M(_),xe(u))},onKeyDown:q,readOnly:J,"aria-label":K("spreadsheet.formulaBar","Formula bar")})]}),e.jsx("div",{className:"nice-spreadsheet__grid",ref:oe,children:e.jsxs("table",{role:"grid","aria-label":R.name,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-spreadsheet__corner"}),Array.from({length:r},(u,h)=>e.jsxs("th",{className:`nice-spreadsheet__col-header ${h<ut?"nice-spreadsheet__col-header--frozen":""}`,style:{width:R.colWidths?.[h]??80,position:h<ut?"sticky":void 0,left:h<ut?h*80+40:void 0,zIndex:h<ut?3:void 0},children:[e.jsx("span",{children:ii(h)}),z&&e.jsx("span",{role:"button",tabIndex:0,onKeyDown:k.clickOnActivationKey,className:"nice-spreadsheet__sort-trigger",onClick:()=>Pt(h,R.sortColumn===h&&R.sortDirection==="asc"?"desc":"asc"),title:K("spreadsheet.sort","Sort"),children:R.sortColumn===h?R.sortDirection==="asc"?e.jsx(Ka,{}):e.jsx(Ba,{}):e.jsx(Ua,{})}),!J&&e.jsx("span",{className:"nice-spreadsheet__col-resize",onMouseDown:D=>jt(h,D)})]},h))]})}),e.jsx("tbody",{children:Array.from({length:s},(u,h)=>e.jsxs("tr",{className:h<Et?"nice-spreadsheet__row--frozen":"",style:h<Et?{position:"sticky",top:h*24,zIndex:2}:void 0,children:[e.jsx("td",{className:"nice-spreadsheet__row-header",children:h+1}),Array.from({length:r},(D,G)=>{const W=Te(h,G),p=R.data[W];if(p?.mergedInto)return null;const O=_?.row===h&&_?.col===G,te=N(h,G),F=be?.row===h&&be?.col===G,he=p?He(W,R.data,new Set):null,Pe=Vt(h,G),Ve=h<Et||G<ut;return e.jsxs("td",{className:`nice-spreadsheet__cell ${O?"nice-spreadsheet__cell--selected":""} ${te&&!O?"nice-spreadsheet__cell--in-range":""} ${p?.readOnly?"nice-spreadsheet__cell--readonly":""} ${Ve?"nice-spreadsheet__cell--frozen":""}`,style:{textAlign:p?.align,fontWeight:p?.bold?"bold":void 0,fontStyle:p?.italic?"italic":void 0,backgroundColor:Pe?.backgroundColor??p?.bgColor,color:Pe?.color??p?.color,width:R.colWidths?.[G],height:R.rowHeights?.[h],position:Ve?"sticky":void 0,left:G<ut?G*80+40:void 0,zIndex:Ve?1:void 0,...Pe},colSpan:p?.colSpan,rowSpan:p?.rowSpan,onMouseDown:Je=>Y(h,G,Je),onMouseEnter:()=>me(h,G),onDoubleClick:()=>$e(h,G),onContextMenu:Je=>Ot(Je,h,G),role:"gridcell","aria-selected":O,title:p?.comment,children:[p?.comment&&e.jsx("span",{className:"nice-spreadsheet__comment-indicator"}),F?e.jsx("input",{ref:ze,className:"nice-spreadsheet__cell-editor",value:le,onChange:Je=>xe(Je.target.value),onKeyDown:q,onBlur:qe}):Yn(he,p?.format)]},G)})]},h))})]})}),ke&&!J&&_&&e.jsxs("div",{className:"nice-spreadsheet__context-menu",style:{position:"fixed",left:ke.x,top:ke.y,zIndex:1e3},children:[e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Ce(_.row),Q(null)},children:K("spreadsheet.insertRowAbove","Insert row above")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Ce(_.row+1),Q(null)},children:K("spreadsheet.insertRowBelow","Insert row below")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{lt(_.col),Q(null)},children:K("spreadsheet.insertColLeft","Insert column left")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{lt(_.col+1),Q(null)},children:K("spreadsheet.insertColRight","Insert column right")}),e.jsx("hr",{className:"nice-spreadsheet__context-sep"}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{ot(_.row),Q(null)},children:K("spreadsheet.deleteRow","Delete row")}),e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:()=>{Dt(_.col),Q(null)},children:K("spreadsheet.deleteCol","Delete column")})]}),it&&e.jsxs("div",{className:"nice-spreadsheet__status-bar",children:[e.jsxs("span",{children:[K("spreadsheet.count","Count"),": ",it.count]}),it.sum!==void 0&&e.jsxs("span",{children:[K("spreadsheet.sum","Sum"),": ",it.sum.toFixed(2)]}),it.avg!==void 0&&e.jsxs("span",{children:[K("spreadsheet.avg","Avg"),": ",it.avg.toFixed(2)]}),it.min!==void 0&&e.jsxs("span",{children:[K("spreadsheet.min","Min"),": ",it.min]}),it.max!==void 0&&e.jsxs("span",{children:[K("spreadsheet.max","Max"),": ",it.max]})]}),d&&e.jsxs("div",{className:"nice-spreadsheet__tabs",role:"tablist",ref:Ke,children:[$.map((u,h)=>e.jsx("span",{className:"nice-spreadsheet__tab-wrapper",children:ye===h?e.jsx(vn.NiceTextInput,{className:"nice-spreadsheet__tab-rename",value:Ae,onChange:D=>ae(D),onBlur:()=>Tt(h,Ae),onKeyDown:D=>{D.key==="Enter"&&Tt(h,Ae),D.key==="Escape"&&Ee(null)},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>{J||(Ee(h),ae(u.name))},children:e.jsx(We.NiceButton,{variant:h===P?"primary":"ghost",size:"sm",role:"tab","aria-selected":h===P,onClick:()=>de(h),onKeyDown:D=>{D.key==="F2"&&!J&&(D.preventDefault(),Ee(h),ae(u.name))},children:u.name})})},h)),!J&&e.jsxs(e.Fragment,{children:[e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Kt,title:K("spreadsheet.addSheet","Add sheet"),children:e.jsx(Ga,{})}),$.length>1&&e.jsx(We.NiceButton,{variant:"ghost",size:"sm",onClick:Nt,title:K("spreadsheet.removeSheet","Remove sheet"),children:e.jsx(Wa,{})})]})]})]})}),{displayName:"NiceSpreadsheet"}),Ya=`
|
|
10
10
|
.nice-reconciliation {
|
|
11
11
|
display: flex;
|
|
12
12
|
flex-direction: column;
|
|
@@ -584,4 +584,4 @@ ${St?1:0}`,[Qt,At]=n.useState(()=>({key:"",map:new Map})),qt=Qt.key===Lt?Qt.map:
|
|
|
584
584
|
background: var(--nice-bg-primary-dark, #111827);
|
|
585
585
|
border-color: var(--nice-border-color-dark, #374151);
|
|
586
586
|
}
|
|
587
|
-
`;function It(t,a="PLN",s="pl-PL"){return new Intl.NumberFormat(s,{style:"currency",currency:a,minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function rn(t,a="pl-PL"){return t?(typeof t=="string"?new Date(t):t).toLocaleDateString(a,{year:"numeric",month:"2-digit",day:"2-digit"}):"-"}function Xa(t){return t>=80?"high":t>=50?"medium":"low"}function Za(){return`match-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function Xn(t){t?.querySelector('[role="option"][tabindex="0"]')?.focus()}function ai(t,a,s){t.target===t.currentTarget&&(t.key===" "||t.key==="Enter"&&!s?(t.preventDefault(),a()):t.key==="Enter"&&s&&(t.preventDefault(),s()))}function Ja({item:t,isSelected:a,isDragging:s,isDropTarget:r,suggestion:l,currency:o,locale:d,onSelect:c,onDoubleClick:f,onDragStart:m,onDragEnd:j,onDrop:E,disabled:L}){const A=t.status??"unmatched",T=l?.confidence??t.confidence,V=x=>{x.dataTransfer.setData("text/plain",t.id),x.dataTransfer.setData("source","statement"),x.dataTransfer.effectAllowed="move",m()},g=x=>{x.dataTransfer.types.includes("source")&&x.dataTransfer.getData("source")!=="statement"&&x.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${A} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${r?"nice-reconciliation__row--drop-target":""}`,draggable:!L&&A!=="matched",onDragStart:V,onDragEnd:j,onDragOver:g,onDrop:E,onClick:c,onDoubleClick:f,onKeyDown:x=>ai(x,c,f),role:"option","aria-selected":a,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${A}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsx("div",{className:"nice-reconciliation__row-date",children:rn(t.date,d)}),e.jsx("div",{className:"nice-reconciliation__row-description",title:t.description,children:t.description}),t.counterparty&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:t.counterparty})]}),T!=null&&e.jsxs("span",{className:`nice-reconciliation__confidence nice-reconciliation__confidence--${Xa(T)}`,children:[T,"%"]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(t.amount,o,d)})]})}function es({item:t,isSelected:a,isDragging:s,isDropTarget:r,currency:l,locale:o,onSelect:d,onDoubleClick:c,onDragStart:f,onDragEnd:m,onDrop:j,disabled:E}){const L=t.status??"unmatched",A=V=>{V.dataTransfer.setData("text/plain",t.id),V.dataTransfer.setData("source","entry"),V.dataTransfer.effectAllowed="move",f()},T=V=>{V.dataTransfer.types.includes("source")&&V.dataTransfer.getData("source")!=="entry"&&V.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${L} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${r?"nice-reconciliation__row--drop-target":""}`,draggable:!E&&L!=="matched",onDragStart:A,onDragEnd:m,onDragOver:T,onDrop:j,onClick:d,onDoubleClick:c,onKeyDown:V=>ai(V,d,c),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:[rn(t.date,o),t.documentNumber&&e.jsxs("span",{children:[" · ",t.documentNumber]})]}),e.jsx("div",{className:"nice-reconciliation__row-description",title:t.description,children:t.description}),t.partyName&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:t.partyName})]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(t.amount,l,o)})]})}const ts=n.forwardRef(function(a,s){const{t:r}=k.useNiceTranslation(),{statements:l,bankTransactions:o,entries:d,accountingEntries:c,matches:f,defaultMatches:m=[],suggestions:j=[],config:E={},currency:L,showConfidence:A,statementPanelConfig:T,entryPanelConfig:V,onMatch:g,onAutoMatch:x,onUnmatch:I,onBatchAction:b,onFilterChange:z,onRequestSuggestions:S,onSelectionChange:U,onComplete:H,size:fe="medium",showToolbar:re=!0,showFilters:ge=!0,showSummary:Me=!0,showSuggestions:J=!0,layout:we="horizontal",enableDragDrop:K=!0,enableKeyboard:Le=!0,enableDetailPanel:Ne=!0,loading:Fe=!1,disabled:X=!1,readOnly:$=!1,locale:P="pl-PL",labels:R={},className:_,style:_e}=a,ce=n.useMemo(()=>l??o??[],[l,o]),w=n.useMemo(()=>d??c??[],[d,c]),ie=L??E.currency??"PLN",[ue,be]=n.useState(m),[M,le]=n.useState(new Set),[xe,ze]=n.useState(new Set),[oe,je]=n.useState(null),[Oe,De]=n.useState(null),[Se,rt]=n.useState({}),[et,tt]=n.useState(null),ke=f??ue,Q=n.useRef(null),ye=n.useRef(null),Ee={orientation:"vertical",pageSize:10};k.useRovingFocus(Q,Ee),k.useRovingFocus(ye,Ee),n.useEffect(()=>{const C="nice-reconciliation-styles";if(!document.getElementById(C)){const Y=document.createElement("style");Y.id=C,Y.textContent=Ha,document.head.appendChild(Y)}},[]);const Ke=n.useMemo(()=>{const C=new Set;return ke.forEach(Y=>Y.statementIds.forEach(me=>C.add(me))),C},[ke]),Ae=n.useMemo(()=>{const C=new Set;return ke.forEach(Y=>Y.entryIds.forEach(me=>C.add(me))),C},[ke]),ae=n.useMemo(()=>{const C=ce.filter(q=>!Ke.has(q.id)),Y=w.filter(q=>!Ae.has(q.id)),me=ce.reduce((q,Re)=>q+Re.amount,0),$e=w.reduce((q,Re)=>q+Re.amount,0),qe=ce.filter(q=>Ke.has(q.id)).reduce((q,Re)=>q+Re.amount,0);return{totalStatements:ce.length,totalEntries:w.length,matchedStatements:ce.length-C.length,matchedEntries:w.length-Y.length,unmatchedStatements:C.length,unmatchedEntries:Y.length,statementTotal:me,entryTotal:$e,matchedAmount:qe,unmatchedStatementAmount:C.reduce((q,Re)=>q+Re.amount,0),unmatchedEntryAmount:Y.reduce((q,Re)=>q+Re.amount,0),difference:me-$e,matchPercentage:ce.length>0?Math.round((ce.length-C.length)/ce.length*100):0,matchCount:ke.length,partialMatchCount:ke.filter(q=>q.status==="partial").length,pendingSuggestions:j.length}},[ce,w,ke,j,Ke,Ae]),Z=n.useCallback((C,Y)=>{const me=ce.filter(Ce=>C.includes(Ce.id)),$e=w.filter(Ce=>Y.includes(Ce.id));if(me.length===0||$e.length===0)return null;const qe=me.reduce((Ce,lt)=>Ce+lt.amount,0),q=$e.reduce((Ce,lt)=>Ce+lt.amount,0),Re=Math.abs(qe-q),ct=E.amountTolerance??.01,Ue={id:Za(),statementIds:C,entryIds:Y,status:Re<=ct?"matched":"partial",statementTotal:qe,entryTotal:q,difference:Re,confidence:Re<=ct?100:Math.max(0,100-Re/Math.max(Math.abs(qe),1)*100),matchedBy:"user",matchedAt:new Date};return f||be(Ce=>[...Ce,Ue]),g?.(Ue,me,$e),le(new Set),ze(new Set),Ue},[ce,w,E.amountTolerance,f,g]),N=n.useCallback(C=>{const Y=ke.find(me=>me.id===C);Y&&(f||be(me=>me.filter($e=>$e.id!==C)),I?.(C,Y.statementIds,Y.entryIds))},[ke,f,I]),ve=n.useCallback(async()=>{const C=[],Y=new Set(Ke),me=new Set(Ae),$e=E.amountTolerance??.01,qe=E.dateTolerance??3;for(const q of ce){if(Y.has(q.id))continue;const Re=w.filter(ct=>{if(me.has(ct.id)||Math.abs(q.amount-ct.amount)>$e)return!1;const Ce=new Date(q.date),lt=new Date(ct.date);return!(Math.abs(Ce.getTime()-lt.getTime())/(1e3*60*60*24)>qe)});if(Re.length===1){const ct=Re[0],Ue=Z([q.id],[ct.id]);Ue&&(C.push(Ue),Y.add(q.id),me.add(ct.id))}}return b?.("autoMatch",C),C},[ce,w,Ke,Ae,E,Z,b]),ee=n.useCallback((C,Y,me,$e)=>{$e!==Y&&($e==="statement"?Z([me],[C]):Z([C],[me]),je(null),De(null))},[Z]),Be=n.useCallback(()=>{const C=Array.from(M),Y=Array.from(xe);C.length>0&&Y.length>0&&Z(C,Y)},[M,xe,Z]);n.useEffect(()=>{U?.(Array.from(M),Array.from(xe))},[M,xe,U]),n.useImperativeHandle(s,()=>({getMatches:()=>ke,getUnmatchedStatements:()=>ce.filter(C=>!Ke.has(C.id)),getUnmatchedEntries:()=>w.filter(C=>!Ae.has(C.id)),createMatch:Z,removeMatch:N,autoMatch:ve,getSuggestions:async C=>S?S(C??ce.filter(Y=>!Ke.has(Y.id)).map(Y=>Y.id)):[],applySuggestion:C=>Z([C.statementId],C.entryIds),approveAll:()=>{b?.("approveAll",ke)},clearAll:()=>{f||be([]),b?.("clearAll",[])},exportMatched:C=>{b?.("exportMatched",ke)},getSummary:()=>ae,reset:()=>{f||be([]),le(new Set),ze(new Set),rt({})},focusStatements:()=>Xn(Q.current),focusEntries:()=>Xn(ye.current)}),[ke,ce,w,Ke,Ae,Z,N,ve,S,b,f,ae]);const Ye=n.useMemo(()=>ce.filter(C=>{if(Se.status&&Se.status.length>0){const Y=Ke.has(C.id)?"matched":"unmatched";if(!Se.status.includes(Y))return!1}if(Se.searchText){const Y=Se.searchText.toLowerCase();if(!C.description?.toLowerCase().includes(Y)&&!C.counterparty?.toLowerCase().includes(Y))return!1}return!0}),[ce,Se,Ke]),de=n.useMemo(()=>w.filter(C=>{if(Se.status&&Se.status.length>0){const Y=Ae.has(C.id)?"matched":"unmatched";if(!Se.status.includes(Y))return!1}if(Se.searchText){const Y=Se.searchText.toLowerCase();if(!C.description?.toLowerCase().includes(Y)&&!C.partyName?.toLowerCase().includes(Y))return!1}return!0}),[w,Se,Ae]),Qe=M.size>0&&xe.size>0&&!$&&!X;return e.jsxs("div",{className:`nice-reconciliation nice-reconciliation--${we} ${_??""}`,style:_e,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:ve,disabled:X||$||Fe,children:[e.jsx(k.NiceIcon,{name:"zap",size:14})," ",R.autoMatch??r("reconciliationView.autoMatch","Auto-match")]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--success",onClick:Be,disabled:!Qe||Fe,children:[e.jsx(k.NiceIcon,{name:"link",size:14})," ",r("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:()=>b?.("approveAll",ke),disabled:ke.length===0||X||Fe,children:[e.jsx(k.NiceIcon,{name:"check",size:14})," ",R.approveAll??r("reconciliationView.approveAll","Approve All")]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>{f||be([]),b?.("clearAll",[])},disabled:ke.length===0||X||$||Fe,children:[e.jsx(k.NiceIcon,{name:"close",size:14})," ",R.clearAll??r("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(k.NiceIcon,{name:"file",size:14})," ",R.statementPanelTitle??r("reconciliationView.bankStatement","Bank Statement"),e.jsx("span",{className:"nice-reconciliation__panel-badge",children:Ye.length})]})}),e.jsx("div",{ref:Q,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:Ye.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:e.jsx(k.NiceIcon,{name:"clipboard",size:32})}),R.noStatements??r("reconciliationView.noStatementItems","No statement items")]}):Ye.map(C=>e.jsx(Ja,{item:{...C,status:Ke.has(C.id)?"matched":"unmatched"},isSelected:M.has(C.id),isDragging:oe===C.id,isDropTarget:Oe===C.id,suggestion:j.find(Y=>Y.statementId===C.id),currency:ie,locale:P,onSelect:()=>{X||le(Y=>{const me=new Set(Y);return me.has(C.id)?me.delete(C.id):me.add(C.id),me})},onDoubleClick:Ne?()=>tt({type:"statement",id:C.id}):void 0,onDragStart:()=>je(C.id),onDragEnd:()=>{je(null),De(null)},onDrop:()=>{oe&&oe!==C.id&&ee(C.id,"statement",oe,"entry")},disabled:X||$||!K},C.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(k.NiceIcon,{name:"book",size:14})," ",R.entryPanelTitle??r("reconciliationView.bookEntries","Book Entries"),e.jsx("span",{className:"nice-reconciliation__panel-badge",children:de.length})]})}),e.jsx("div",{ref:ye,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:de.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:e.jsx(k.NiceIcon,{name:"book",size:32})}),R.noEntries??r("reconciliationView.noBookEntries","No book entries")]}):de.map(C=>e.jsx(es,{item:{...C,status:Ae.has(C.id)?"matched":"unmatched"},isSelected:xe.has(C.id),isDragging:oe===C.id,isDropTarget:Oe===C.id,currency:ie,locale:P,onSelect:()=>{X||ze(Y=>{const me=new Set(Y);return me.has(C.id)?me.delete(C.id):me.add(C.id),me})},onDoubleClick:Ne?()=>tt({type:"entry",id:C.id}):void 0,onDragStart:()=>je(C.id),onDragEnd:()=>{je(null),De(null)},onDrop:()=>{oe&&oe!==C.id&&ee(C.id,"entry",oe,"statement")},disabled:X||$||!K},C.id))})]})]}),Me&&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:r("reconciliationView.matched","Matched:")}),e.jsxs("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--success",children:[ae.matchedStatements,"/",ae.totalStatements," (",ae.matchPercentage,"%)"]})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:r("reconciliationView.matchedAmount","Matched Amount:")}),e.jsx("span",{className:"nice-reconciliation__summary-value",children:It(ae.matchedAmount,ie,P)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:r("reconciliationView.unmatched","Unmatched:")}),e.jsx("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--warning",children:It(ae.unmatchedStatementAmount,ie,P)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:r("reconciliationView.difference","Difference:")}),e.jsx("span",{className:`nice-reconciliation__summary-value ${Math.abs(ae.difference)<.01?"nice-reconciliation__summary-value--success":"nice-reconciliation__summary-value--danger"}`,children:It(ae.difference,ie,P)})]})]}),Ne&&e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"presentation",className:`nice-reconciliation__detail-backdrop ${et?"nice-reconciliation__detail-backdrop--visible":""}`,onClick:()=>tt(null)}),e.jsx("div",{className:`nice-reconciliation__detail-panel ${et?"nice-reconciliation__detail-panel--open":""}`,children:et&&e.jsx(ns,{type:et.type,id:et.id,statements:ce,entries:w,matches:ke,currency:ie,locale:P,labels:R,onClose:()=>tt(null)})})]})]})});function ns({type:t,id:a,statements:s,entries:r,matches:l,currency:o,locale:d,labels:c,onClose:f}){const{t:m}=k.useNiceTranslation(),j=t==="statement"?s.find(g=>g.id===a):r.find(g=>g.id===a),E=t==="statement"?l.find(g=>g.statementIds.includes(a)):l.find(g=>g.entryIds.includes(a)),L=E?t==="statement"?r.filter(g=>E.entryIds.includes(g.id)):s.filter(g=>E.statementIds.includes(g.id)):[];if(!j)return null;const A=t==="statement",T=A?j:null,V=A?null:j;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(k.NiceIcon,{name:A?"file":"book",size:14})," ",A?c.statementDetails??m("reconciliationView.transactionDetails","Transaction Details"):c.entryDetails??m("reconciliationView.entryDetails","Entry Details")]}),e.jsx("button",{type:"button",className:"nice-reconciliation__detail-close",onClick:f,"aria-label":m("reconciliationView.close","Close"),children:e.jsx(k.NiceIcon,{name:"close",size:14})})]}),e.jsxs("div",{className:"nice-reconciliation__detail-content",children:[E&&e.jsxs("div",{className:"nice-reconciliation__detail-match-info",children:[e.jsxs("div",{className:"nice-reconciliation__detail-match-header",children:[e.jsx(k.NiceIcon,{name:"check",size:14})," ",m("reconciliationView.matchedConfidence","{label} ({confidence}% confidence)").replace("{label}",c.matchedWith??m("reconciliationView.matched2","Matched")).replace("{confidence}",String(E.confidence?.toFixed(0)??100))]}),e.jsx("div",{className:"nice-reconciliation__detail-match-detail",children:E.matchedBy==="ai"?c.matchedByAI??m("reconciliationView.matchedAutomaticallyByAi","Matched automatically by AI"):c.matchedManually??m("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:c.statementTotal??m("reconciliationView.statement","Statement")}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${E.statementTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(E.statementTotal,o,d)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:c.entryTotal??m("reconciliationView.bookEntry","Book Entry")}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${E.entryTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(E.entryTotal,o,d)})]})]}),E.difference>.01&&e.jsxs("div",{className:"nice-reconciliation__detail-row",style:{marginTop:"0.5rem",borderBottom:"none"},children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.difference??m("reconciliationView.difference2","Difference"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{color:"var(--nice-warning, #f59e0b)"},children:It(E.difference,o,d)})]})]}),e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:[e.jsx(k.NiceIcon,{name:"clipboard",size:14})," ",A?c.transactionInfo??m("reconciliationView.transactionInformation","Transaction Information"):c.entryInfo??m("reconciliationView.entryInformation","Entry Information")]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.date??m("reconciliationView.date","Date"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:rn(j.date,d)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.description??m("reconciliationView.description","Description"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:j.description})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.amount??m("reconciliationView.amount","Amount"),":"]}),e.jsx("span",{className:`nice-reconciliation__detail-value ${j.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(j.amount,o,d)})]}),A&&T?.counterparty&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.counterparty??m("reconciliationView.counterparty","Counterparty"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:T.counterparty})]}),A&&T?.counterpartyAccount&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.accountNumber??m("reconciliationView.account","Account"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:T.counterpartyAccount})]}),!A&&V?.partyName&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.party??m("reconciliationView.party","Party"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:V.partyName})]}),!A&&V?.documentNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.documentRef??m("reconciliationView.documentRef","Document Ref"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:V.documentNumber})]}),A&&T?.referenceNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.reference??m("reconciliationView.reference","Reference"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:T.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(k.NiceIcon,{name:"link",size:14})," ",A?c.matchedEntries??m("reconciliationView.matchedEntries","Matched Entries"):c.matchedStatements??m("reconciliationView.matchedStatements","Matched Statements")]}),L.map(g=>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:g.description}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:"var(--nice-text-secondary)"},children:[e.jsx("span",{children:rn(g.date,d)}),e.jsx("span",{style:{fontWeight:600,color:g.amount>=0?"var(--nice-success)":"var(--nice-danger)"},children:It(g.amount,o,d)})]})]},g.id))]})]})]})}const is=[],as=({queries:t=is,currentFilter:a,currentColumns:s,currentSort:r,onLoad:l,onSave:o,onUpdate:d,onDelete:c,onShare:f,onSetDefault:m,allowSharing:j=!0,allowPinning:E=!0,position:L="dropdown",className:A,style:T,"data-testid":V})=>{const{t:g}=k.useNiceTranslation(),[x,I]=n.useState(!1),[b,z]=n.useState(""),[S,U]=n.useState(!1),[H,fe]=n.useState(""),[re,ge]=n.useState(""),[Me,J]=n.useState(!1),we=n.useRef(null);k.useOverlayFocus(we,{open:x,modal:!1,onClose:()=>I(!1)});const K=t.filter($=>$.name.toLowerCase().includes(b.toLowerCase())),Le=K.filter($=>!$.isShared),Ne=K.filter($=>$.isShared),Fe=async()=>{if(H.trim()){U(!0);try{await o({name:H,description:re||void 0,filter:a??{},columns:s,sort:r}),J(!1),fe(""),ge("")}finally{U(!1)}}},X=$=>e.jsxs("div",{className:"nice-saved-query__item",children:[$.icon&&e.jsx("span",{className:"nice-saved-query__icon","aria-hidden":"true",children:$.icon}),e.jsx("span",{className:"nice-saved-query__name",children:$.name}),$.isDefault&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--default",children:g("savedQuery.default","default")}),$.isShared&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--shared",children:g("savedQuery.shared","shared")}),$.isPinned&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--pinned",children:g("savedQuery.pinned","pinned")}),e.jsxs("div",{className:"nice-saved-query__actions",children:[e.jsx("button",{onClick:()=>{l($),I(!1)},type:"button",children:g("savedQuery.load","Load")}),m&&e.jsx("button",{onClick:()=>m($.id),type:"button",title:g("savedQuery.setDefault","Set as default"),"aria-label":g("savedQuery.setDefault","Set as default"),children:e.jsx(k.NiceIcon,{name:"star",size:14})}),j&&f&&e.jsx("button",{onClick:()=>f($.id,[]),type:"button",title:g("savedQuery.share","Share"),"aria-label":g("savedQuery.share","Share"),children:e.jsx(k.NiceIcon,{name:"external-link",size:14})}),E&&e.jsx("button",{onClick:()=>d($.id,{...$}),type:"button",title:g("savedQuery.pin","Pin"),"aria-label":g("savedQuery.pin","Pin"),children:e.jsx(k.NiceIcon,{name:"map-pin",size:14})}),e.jsx("button",{onClick:()=>c($.id),type:"button",title:g("savedQuery.remove","Remove"),"aria-label":`${g("savedQuery.removeQuery","Remove query")} ${$.name}`,children:e.jsx(k.NiceIcon,{name:"close",size:14})})]})]},$.id);return e.jsxs("div",{className:`nice-saved-query nice-saved-query--${L} ${x?"nice-saved-query--open":""} ${A??""}`,style:T,"data-testid":V,children:[e.jsx("button",{className:"nice-saved-query__trigger",onClick:()=>I($=>!$),"aria-expanded":x,"aria-haspopup":"dialog",type:"button",children:g("savedQuery.trigger","Views and queries")}),x&&e.jsxs("div",{ref:we,className:"nice-saved-query__panel",role:"dialog","aria-label":g("savedQuery.manage","Manage saved queries"),children:[e.jsxs("div",{className:"nice-saved-query__search-row",children:[e.jsx("input",{type:"search",placeholder:g("savedQuery.searchPlaceholder","Search queries…"),value:b,onChange:$=>z($.target.value),"aria-label":g("savedQuery.search","Search queries")}),e.jsxs("button",{onClick:()=>J($=>!$),type:"button",children:[e.jsx(k.NiceIcon,{name:"plus",size:12})," ",g("savedQuery.saveCurrent","Save current view")]})]}),Me&&e.jsxs("div",{className:"nice-saved-query__save-form",children:[e.jsx("input",{type:"text",placeholder:g("savedQuery.name","Query name"),value:H,onChange:$=>fe($.target.value),"aria-label":g("savedQuery.name","Query name")}),e.jsx("input",{type:"text",placeholder:g("savedQuery.descriptionPlaceholder","Description (optional)"),value:re,onChange:$=>ge($.target.value),"aria-label":g("savedQuery.description","Query description")}),e.jsx("button",{onClick:Fe,disabled:S||!H.trim(),type:"button",children:S?g("savedQuery.saving","Saving…"):g("savedQuery.save","Save")}),e.jsx("button",{onClick:()=>J(!1),type:"button",children:g("savedQuery.cancel","Cancel")})]}),Le.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:g("savedQuery.mine","Mine")}),Le.map(X)]}),Ne.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:g("savedQuery.sharedSection","Shared")}),Ne.map(X)]}),K.length===0&&e.jsx("p",{className:"nice-saved-query__empty",children:g("savedQuery.empty","No saved queries")})]})]})};exports.NiceDataGridAI=Di;exports.NiceHighlight=Nn;exports.NiceKanbanBoard=fa;exports.NiceList=ia;exports.NiceModuleGrid=Aa;exports.NiceReconciliationView=ts;exports.NiceSavedQueryPanel=as;exports.NiceSpreadsheet=Ya;exports.NiceTable=ra;exports.NiceTileView=la;exports.NiceTreeGrid=qi;exports.NiceTreeList=Ji;exports.NiceTreeView=ta;
|
|
587
|
+
`;function It(t,a="PLN",s="pl-PL"){return new Intl.NumberFormat(s,{style:"currency",currency:a,minimumFractionDigits:2,maximumFractionDigits:2}).format(t)}function rn(t,a="pl-PL"){return t?(typeof t=="string"?new Date(t):t).toLocaleDateString(a,{year:"numeric",month:"2-digit",day:"2-digit"}):"-"}function Ha(t){return t>=80?"high":t>=50?"medium":"low"}function Xa(){return`match-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function Xn(t){t?.querySelector('[role="option"][tabindex="0"]')?.focus()}function ai(t,a,s){t.target===t.currentTarget&&(t.key===" "||t.key==="Enter"&&!s?(t.preventDefault(),a()):t.key==="Enter"&&s&&(t.preventDefault(),s()))}function Za({item:t,isSelected:a,isDragging:s,isDropTarget:r,suggestion:l,currency:o,locale:d,onSelect:c,onDoubleClick:f,onDragStart:m,onDragEnd:j,onDrop:E,disabled:L}){const A=t.status??"unmatched",T=l?.confidence??t.confidence,V=x=>{x.dataTransfer.setData("text/plain",t.id),x.dataTransfer.setData("source","statement"),x.dataTransfer.effectAllowed="move",m()},g=x=>{x.dataTransfer.types.includes("source")&&x.dataTransfer.getData("source")!=="statement"&&x.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${A} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${r?"nice-reconciliation__row--drop-target":""}`,draggable:!L&&A!=="matched",onDragStart:V,onDragEnd:j,onDragOver:g,onDrop:E,onClick:c,onDoubleClick:f,onKeyDown:x=>ai(x,c,f),role:"option","aria-selected":a,children:[e.jsx("span",{className:`nice-reconciliation__status nice-reconciliation__status--${A}`}),e.jsxs("div",{className:"nice-reconciliation__row-main",children:[e.jsx("div",{className:"nice-reconciliation__row-date",children:rn(t.date,d)}),e.jsx("div",{className:"nice-reconciliation__row-description",title:t.description,children:t.description}),t.counterparty&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:t.counterparty})]}),T!=null&&e.jsxs("span",{className:`nice-reconciliation__confidence nice-reconciliation__confidence--${Ha(T)}`,children:[T,"%"]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(t.amount,o,d)})]})}function Ja({item:t,isSelected:a,isDragging:s,isDropTarget:r,currency:l,locale:o,onSelect:d,onDoubleClick:c,onDragStart:f,onDragEnd:m,onDrop:j,disabled:E}){const L=t.status??"unmatched",A=V=>{V.dataTransfer.setData("text/plain",t.id),V.dataTransfer.setData("source","entry"),V.dataTransfer.effectAllowed="move",f()},T=V=>{V.dataTransfer.types.includes("source")&&V.dataTransfer.getData("source")!=="entry"&&V.preventDefault()};return e.jsxs("div",{className:`nice-reconciliation__row nice-reconciliation__row--${L} ${a?"nice-reconciliation__row--selected":""} ${s?"nice-reconciliation__row--dragging":""} ${r?"nice-reconciliation__row--drop-target":""}`,draggable:!E&&L!=="matched",onDragStart:A,onDragEnd:m,onDragOver:T,onDrop:j,onClick:d,onDoubleClick:c,onKeyDown:V=>ai(V,d,c),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:[rn(t.date,o),t.documentNumber&&e.jsxs("span",{children:[" · ",t.documentNumber]})]}),e.jsx("div",{className:"nice-reconciliation__row-description",title:t.description,children:t.description}),t.partyName&&e.jsx("div",{className:"nice-reconciliation__row-counterparty",children:t.partyName})]}),e.jsx("span",{className:`nice-reconciliation__row-amount ${t.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(t.amount,l,o)})]})}const es=n.forwardRef(function(a,s){const{t:r}=k.useNiceTranslation(),{statements:l,bankTransactions:o,entries:d,accountingEntries:c,matches:f,defaultMatches:m=[],suggestions:j=[],config:E={},currency:L,showConfidence:A,statementPanelConfig:T,entryPanelConfig:V,onMatch:g,onAutoMatch:x,onUnmatch:I,onBatchAction:b,onFilterChange:z,onRequestSuggestions:S,onSelectionChange:U,onComplete:H,size:fe="medium",showToolbar:re=!0,showFilters:ge=!0,showSummary:Me=!0,showSuggestions:J=!0,layout:we="horizontal",enableDragDrop:K=!0,enableKeyboard:Le=!0,enableDetailPanel:Ne=!0,loading:Fe=!1,disabled:X=!1,readOnly:$=!1,locale:P="pl-PL",labels:R={},className:_,style:_e}=a,ce=n.useMemo(()=>l??o??[],[l,o]),w=n.useMemo(()=>d??c??[],[d,c]),ie=L??E.currency??"PLN",[ue,be]=n.useState(m),[M,le]=n.useState(new Set),[xe,ze]=n.useState(new Set),[oe,je]=n.useState(null),[Oe,De]=n.useState(null),[Se,rt]=n.useState({}),[et,tt]=n.useState(null),ke=f??ue,Q=n.useRef(null),ye=n.useRef(null),Ee={orientation:"vertical",pageSize:10};k.useRovingFocus(Q,Ee),k.useRovingFocus(ye,Ee),n.useEffect(()=>{const C="nice-reconciliation-styles";if(!document.getElementById(C)){const Y=document.createElement("style");Y.id=C,Y.textContent=Ya,document.head.appendChild(Y)}},[]);const Ke=n.useMemo(()=>{const C=new Set;return ke.forEach(Y=>Y.statementIds.forEach(me=>C.add(me))),C},[ke]),Ae=n.useMemo(()=>{const C=new Set;return ke.forEach(Y=>Y.entryIds.forEach(me=>C.add(me))),C},[ke]),ae=n.useMemo(()=>{const C=ce.filter(q=>!Ke.has(q.id)),Y=w.filter(q=>!Ae.has(q.id)),me=ce.reduce((q,Re)=>q+Re.amount,0),$e=w.reduce((q,Re)=>q+Re.amount,0),qe=ce.filter(q=>Ke.has(q.id)).reduce((q,Re)=>q+Re.amount,0);return{totalStatements:ce.length,totalEntries:w.length,matchedStatements:ce.length-C.length,matchedEntries:w.length-Y.length,unmatchedStatements:C.length,unmatchedEntries:Y.length,statementTotal:me,entryTotal:$e,matchedAmount:qe,unmatchedStatementAmount:C.reduce((q,Re)=>q+Re.amount,0),unmatchedEntryAmount:Y.reduce((q,Re)=>q+Re.amount,0),difference:me-$e,matchPercentage:ce.length>0?Math.round((ce.length-C.length)/ce.length*100):0,matchCount:ke.length,partialMatchCount:ke.filter(q=>q.status==="partial").length,pendingSuggestions:j.length}},[ce,w,ke,j,Ke,Ae]),Z=n.useCallback((C,Y)=>{const me=ce.filter(Ce=>C.includes(Ce.id)),$e=w.filter(Ce=>Y.includes(Ce.id));if(me.length===0||$e.length===0)return null;const qe=me.reduce((Ce,lt)=>Ce+lt.amount,0),q=$e.reduce((Ce,lt)=>Ce+lt.amount,0),Re=Math.abs(qe-q),ct=E.amountTolerance??.01,Ue={id:Xa(),statementIds:C,entryIds:Y,status:Re<=ct?"matched":"partial",statementTotal:qe,entryTotal:q,difference:Re,confidence:Re<=ct?100:Math.max(0,100-Re/Math.max(Math.abs(qe),1)*100),matchedBy:"user",matchedAt:new Date};return f||be(Ce=>[...Ce,Ue]),g?.(Ue,me,$e),le(new Set),ze(new Set),Ue},[ce,w,E.amountTolerance,f,g]),N=n.useCallback(C=>{const Y=ke.find(me=>me.id===C);Y&&(f||be(me=>me.filter($e=>$e.id!==C)),I?.(C,Y.statementIds,Y.entryIds))},[ke,f,I]),ve=n.useCallback(async()=>{const C=[],Y=new Set(Ke),me=new Set(Ae),$e=E.amountTolerance??.01,qe=E.dateTolerance??3;for(const q of ce){if(Y.has(q.id))continue;const Re=w.filter(ct=>{if(me.has(ct.id)||Math.abs(q.amount-ct.amount)>$e)return!1;const Ce=new Date(q.date),lt=new Date(ct.date);return!(Math.abs(Ce.getTime()-lt.getTime())/(1e3*60*60*24)>qe)});if(Re.length===1){const ct=Re[0],Ue=Z([q.id],[ct.id]);Ue&&(C.push(Ue),Y.add(q.id),me.add(ct.id))}}return b?.("autoMatch",C),C},[ce,w,Ke,Ae,E,Z,b]),ee=n.useCallback((C,Y,me,$e)=>{$e!==Y&&($e==="statement"?Z([me],[C]):Z([C],[me]),je(null),De(null))},[Z]),Be=n.useCallback(()=>{const C=Array.from(M),Y=Array.from(xe);C.length>0&&Y.length>0&&Z(C,Y)},[M,xe,Z]);n.useEffect(()=>{U?.(Array.from(M),Array.from(xe))},[M,xe,U]),n.useImperativeHandle(s,()=>({getMatches:()=>ke,getUnmatchedStatements:()=>ce.filter(C=>!Ke.has(C.id)),getUnmatchedEntries:()=>w.filter(C=>!Ae.has(C.id)),createMatch:Z,removeMatch:N,autoMatch:ve,getSuggestions:async C=>S?S(C??ce.filter(Y=>!Ke.has(Y.id)).map(Y=>Y.id)):[],applySuggestion:C=>Z([C.statementId],C.entryIds),approveAll:()=>{b?.("approveAll",ke)},clearAll:()=>{f||be([]),b?.("clearAll",[])},exportMatched:C=>{b?.("exportMatched",ke)},getSummary:()=>ae,reset:()=>{f||be([]),le(new Set),ze(new Set),rt({})},focusStatements:()=>Xn(Q.current),focusEntries:()=>Xn(ye.current)}),[ke,ce,w,Ke,Ae,Z,N,ve,S,b,f,ae]);const Ye=n.useMemo(()=>ce.filter(C=>{if(Se.status&&Se.status.length>0){const Y=Ke.has(C.id)?"matched":"unmatched";if(!Se.status.includes(Y))return!1}if(Se.searchText){const Y=Se.searchText.toLowerCase();if(!C.description?.toLowerCase().includes(Y)&&!C.counterparty?.toLowerCase().includes(Y))return!1}return!0}),[ce,Se,Ke]),de=n.useMemo(()=>w.filter(C=>{if(Se.status&&Se.status.length>0){const Y=Ae.has(C.id)?"matched":"unmatched";if(!Se.status.includes(Y))return!1}if(Se.searchText){const Y=Se.searchText.toLowerCase();if(!C.description?.toLowerCase().includes(Y)&&!C.partyName?.toLowerCase().includes(Y))return!1}return!0}),[w,Se,Ae]),Qe=M.size>0&&xe.size>0&&!$&&!X;return e.jsxs("div",{className:`nice-reconciliation nice-reconciliation--${we} ${_??""}`,style:_e,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:ve,disabled:X||$||Fe,children:[e.jsx(k.NiceIcon,{name:"zap",size:14})," ",R.autoMatch??r("reconciliationView.autoMatch","Auto-match")]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn nice-reconciliation__btn--success",onClick:Be,disabled:!Qe||Fe,children:[e.jsx(k.NiceIcon,{name:"link",size:14})," ",r("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:()=>b?.("approveAll",ke),disabled:ke.length===0||X||Fe,children:[e.jsx(k.NiceIcon,{name:"check",size:14})," ",R.approveAll??r("reconciliationView.approveAll","Approve All")]}),e.jsxs("button",{type:"button",className:"nice-reconciliation__btn",onClick:()=>{f||be([]),b?.("clearAll",[])},disabled:ke.length===0||X||$||Fe,children:[e.jsx(k.NiceIcon,{name:"close",size:14})," ",R.clearAll??r("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(k.NiceIcon,{name:"file",size:14})," ",R.statementPanelTitle??r("reconciliationView.bankStatement","Bank Statement"),e.jsx("span",{className:"nice-reconciliation__panel-badge",children:Ye.length})]})}),e.jsx("div",{ref:Q,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:Ye.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:e.jsx(k.NiceIcon,{name:"clipboard",size:32})}),R.noStatements??r("reconciliationView.noStatementItems","No statement items")]}):Ye.map(C=>e.jsx(Za,{item:{...C,status:Ke.has(C.id)?"matched":"unmatched"},isSelected:M.has(C.id),isDragging:oe===C.id,isDropTarget:Oe===C.id,suggestion:j.find(Y=>Y.statementId===C.id),currency:ie,locale:P,onSelect:()=>{X||le(Y=>{const me=new Set(Y);return me.has(C.id)?me.delete(C.id):me.add(C.id),me})},onDoubleClick:Ne?()=>tt({type:"statement",id:C.id}):void 0,onDragStart:()=>je(C.id),onDragEnd:()=>{je(null),De(null)},onDrop:()=>{oe&&oe!==C.id&&ee(C.id,"statement",oe,"entry")},disabled:X||$||!K},C.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(k.NiceIcon,{name:"book",size:14})," ",R.entryPanelTitle??r("reconciliationView.bookEntries","Book Entries"),e.jsx("span",{className:"nice-reconciliation__panel-badge",children:de.length})]})}),e.jsx("div",{ref:ye,className:"nice-reconciliation__panel-content",role:"listbox","aria-multiselectable":"true",children:de.length===0?e.jsxs("div",{className:"nice-reconciliation__empty",children:[e.jsx("div",{className:"nice-reconciliation__empty-icon",children:e.jsx(k.NiceIcon,{name:"book",size:32})}),R.noEntries??r("reconciliationView.noBookEntries","No book entries")]}):de.map(C=>e.jsx(Ja,{item:{...C,status:Ae.has(C.id)?"matched":"unmatched"},isSelected:xe.has(C.id),isDragging:oe===C.id,isDropTarget:Oe===C.id,currency:ie,locale:P,onSelect:()=>{X||ze(Y=>{const me=new Set(Y);return me.has(C.id)?me.delete(C.id):me.add(C.id),me})},onDoubleClick:Ne?()=>tt({type:"entry",id:C.id}):void 0,onDragStart:()=>je(C.id),onDragEnd:()=>{je(null),De(null)},onDrop:()=>{oe&&oe!==C.id&&ee(C.id,"entry",oe,"statement")},disabled:X||$||!K},C.id))})]})]}),Me&&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:r("reconciliationView.matched","Matched:")}),e.jsxs("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--success",children:[ae.matchedStatements,"/",ae.totalStatements," (",ae.matchPercentage,"%)"]})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:r("reconciliationView.matchedAmount","Matched Amount:")}),e.jsx("span",{className:"nice-reconciliation__summary-value",children:It(ae.matchedAmount,ie,P)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:r("reconciliationView.unmatched","Unmatched:")}),e.jsx("span",{className:"nice-reconciliation__summary-value nice-reconciliation__summary-value--warning",children:It(ae.unmatchedStatementAmount,ie,P)})]}),e.jsxs("div",{className:"nice-reconciliation__summary-item",children:[e.jsx("span",{className:"nice-reconciliation__summary-label",children:r("reconciliationView.difference","Difference:")}),e.jsx("span",{className:`nice-reconciliation__summary-value ${Math.abs(ae.difference)<.01?"nice-reconciliation__summary-value--success":"nice-reconciliation__summary-value--danger"}`,children:It(ae.difference,ie,P)})]})]}),Ne&&e.jsxs(e.Fragment,{children:[e.jsx("div",{role:"presentation",className:`nice-reconciliation__detail-backdrop ${et?"nice-reconciliation__detail-backdrop--visible":""}`,onClick:()=>tt(null)}),e.jsx("div",{className:`nice-reconciliation__detail-panel ${et?"nice-reconciliation__detail-panel--open":""}`,children:et&&e.jsx(ts,{type:et.type,id:et.id,statements:ce,entries:w,matches:ke,currency:ie,locale:P,labels:R,onClose:()=>tt(null)})})]})]})});function ts({type:t,id:a,statements:s,entries:r,matches:l,currency:o,locale:d,labels:c,onClose:f}){const{t:m}=k.useNiceTranslation(),j=t==="statement"?s.find(g=>g.id===a):r.find(g=>g.id===a),E=t==="statement"?l.find(g=>g.statementIds.includes(a)):l.find(g=>g.entryIds.includes(a)),L=E?t==="statement"?r.filter(g=>E.entryIds.includes(g.id)):s.filter(g=>E.statementIds.includes(g.id)):[];if(!j)return null;const A=t==="statement",T=A?j:null,V=A?null:j;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(k.NiceIcon,{name:A?"file":"book",size:14})," ",A?c.statementDetails??m("reconciliationView.transactionDetails","Transaction Details"):c.entryDetails??m("reconciliationView.entryDetails","Entry Details")]}),e.jsx("button",{type:"button",className:"nice-reconciliation__detail-close",onClick:f,"aria-label":m("reconciliationView.close","Close"),children:e.jsx(k.NiceIcon,{name:"close",size:14})})]}),e.jsxs("div",{className:"nice-reconciliation__detail-content",children:[E&&e.jsxs("div",{className:"nice-reconciliation__detail-match-info",children:[e.jsxs("div",{className:"nice-reconciliation__detail-match-header",children:[e.jsx(k.NiceIcon,{name:"check",size:14})," ",m("reconciliationView.matchedConfidence","{label} ({confidence}% confidence)").replace("{label}",c.matchedWith??m("reconciliationView.matched2","Matched")).replace("{confidence}",String(E.confidence?.toFixed(0)??100))]}),e.jsx("div",{className:"nice-reconciliation__detail-match-detail",children:E.matchedBy==="ai"?c.matchedByAI??m("reconciliationView.matchedAutomaticallyByAi","Matched automatically by AI"):c.matchedManually??m("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:c.statementTotal??m("reconciliationView.statement","Statement")}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${E.statementTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(E.statementTotal,o,d)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-side-item",children:[e.jsx("div",{className:"nice-reconciliation__detail-side-label",children:c.entryTotal??m("reconciliationView.bookEntry","Book Entry")}),e.jsx("div",{className:`nice-reconciliation__detail-side-amount ${E.entryTotal>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(E.entryTotal,o,d)})]})]}),E.difference>.01&&e.jsxs("div",{className:"nice-reconciliation__detail-row",style:{marginTop:"0.5rem",borderBottom:"none"},children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.difference??m("reconciliationView.difference2","Difference"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{color:"var(--nice-warning, #f59e0b)"},children:It(E.difference,o,d)})]})]}),e.jsxs("div",{className:"nice-reconciliation__detail-section",children:[e.jsxs("div",{className:"nice-reconciliation__detail-section-title",children:[e.jsx(k.NiceIcon,{name:"clipboard",size:14})," ",A?c.transactionInfo??m("reconciliationView.transactionInformation","Transaction Information"):c.entryInfo??m("reconciliationView.entryInformation","Entry Information")]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.date??m("reconciliationView.date","Date"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:rn(j.date,d)})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.description??m("reconciliationView.description","Description"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:j.description})]}),e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.amount??m("reconciliationView.amount","Amount"),":"]}),e.jsx("span",{className:`nice-reconciliation__detail-value ${j.amount>=0?"nice-reconciliation__row-amount--positive":"nice-reconciliation__row-amount--negative"}`,children:It(j.amount,o,d)})]}),A&&T?.counterparty&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.counterparty??m("reconciliationView.counterparty","Counterparty"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:T.counterparty})]}),A&&T?.counterpartyAccount&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.accountNumber??m("reconciliationView.account","Account"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:T.counterpartyAccount})]}),!A&&V?.partyName&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.party??m("reconciliationView.party","Party"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:V.partyName})]}),!A&&V?.documentNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.documentRef??m("reconciliationView.documentRef","Document Ref"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:V.documentNumber})]}),A&&T?.referenceNumber&&e.jsxs("div",{className:"nice-reconciliation__detail-row",children:[e.jsxs("span",{className:"nice-reconciliation__detail-label",children:[c.reference??m("reconciliationView.reference","Reference"),":"]}),e.jsx("span",{className:"nice-reconciliation__detail-value",children:T.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(k.NiceIcon,{name:"link",size:14})," ",A?c.matchedEntries??m("reconciliationView.matchedEntries","Matched Entries"):c.matchedStatements??m("reconciliationView.matchedStatements","Matched Statements")]}),L.map(g=>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:g.description}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",color:"var(--nice-text-secondary)"},children:[e.jsx("span",{children:rn(g.date,d)}),e.jsx("span",{style:{fontWeight:600,color:g.amount>=0?"var(--nice-success)":"var(--nice-danger)"},children:It(g.amount,o,d)})]})]},g.id))]})]})]})}const ns=[],is=({queries:t=ns,currentFilter:a,currentColumns:s,currentSort:r,onLoad:l,onSave:o,onUpdate:d,onDelete:c,onShare:f,onSetDefault:m,allowSharing:j=!0,allowPinning:E=!0,position:L="dropdown",className:A,style:T,"data-testid":V})=>{const{t:g}=k.useNiceTranslation(),[x,I]=n.useState(!1),[b,z]=n.useState(""),[S,U]=n.useState(!1),[H,fe]=n.useState(""),[re,ge]=n.useState(""),[Me,J]=n.useState(!1),we=n.useRef(null);k.useOverlayFocus(we,{open:x,modal:!1,onClose:()=>I(!1)});const K=t.filter($=>$.name.toLowerCase().includes(b.toLowerCase())),Le=K.filter($=>!$.isShared),Ne=K.filter($=>$.isShared),Fe=async()=>{if(H.trim()){U(!0);try{await o({name:H,description:re||void 0,filter:a??{},columns:s,sort:r}),J(!1),fe(""),ge("")}finally{U(!1)}}},X=$=>e.jsxs("div",{className:"nice-saved-query__item",children:[$.icon&&e.jsx("span",{className:"nice-saved-query__icon","aria-hidden":"true",children:$.icon}),e.jsx("span",{className:"nice-saved-query__name",children:$.name}),$.isDefault&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--default",children:g("savedQuery.default","default")}),$.isShared&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--shared",children:g("savedQuery.shared","shared")}),$.isPinned&&e.jsx("span",{className:"nice-saved-query__badge nice-saved-query__badge--pinned",children:g("savedQuery.pinned","pinned")}),e.jsxs("div",{className:"nice-saved-query__actions",children:[e.jsx("button",{onClick:()=>{l($),I(!1)},type:"button",children:g("savedQuery.load","Load")}),m&&e.jsx("button",{onClick:()=>m($.id),type:"button",title:g("savedQuery.setDefault","Set as default"),"aria-label":g("savedQuery.setDefault","Set as default"),children:e.jsx(k.NiceIcon,{name:"star",size:14})}),j&&f&&e.jsx("button",{onClick:()=>f($.id,[]),type:"button",title:g("savedQuery.share","Share"),"aria-label":g("savedQuery.share","Share"),children:e.jsx(k.NiceIcon,{name:"external-link",size:14})}),E&&e.jsx("button",{onClick:()=>d($.id,{...$}),type:"button",title:g("savedQuery.pin","Pin"),"aria-label":g("savedQuery.pin","Pin"),children:e.jsx(k.NiceIcon,{name:"map-pin",size:14})}),e.jsx("button",{onClick:()=>c($.id),type:"button",title:g("savedQuery.remove","Remove"),"aria-label":`${g("savedQuery.removeQuery","Remove query")} ${$.name}`,children:e.jsx(k.NiceIcon,{name:"close",size:14})})]})]},$.id);return e.jsxs("div",{className:`nice-saved-query nice-saved-query--${L} ${x?"nice-saved-query--open":""} ${A??""}`,style:T,"data-testid":V,children:[e.jsx("button",{className:"nice-saved-query__trigger",onClick:()=>I($=>!$),"aria-expanded":x,"aria-haspopup":"dialog",type:"button",children:g("savedQuery.trigger","Views and queries")}),x&&e.jsxs("div",{ref:we,className:"nice-saved-query__panel",role:"dialog","aria-label":g("savedQuery.manage","Manage saved queries"),children:[e.jsxs("div",{className:"nice-saved-query__search-row",children:[e.jsx("input",{type:"search",placeholder:g("savedQuery.searchPlaceholder","Search queries…"),value:b,onChange:$=>z($.target.value),"aria-label":g("savedQuery.search","Search queries")}),e.jsxs("button",{onClick:()=>J($=>!$),type:"button",children:[e.jsx(k.NiceIcon,{name:"plus",size:12})," ",g("savedQuery.saveCurrent","Save current view")]})]}),Me&&e.jsxs("div",{className:"nice-saved-query__save-form",children:[e.jsx("input",{type:"text",placeholder:g("savedQuery.name","Query name"),value:H,onChange:$=>fe($.target.value),"aria-label":g("savedQuery.name","Query name")}),e.jsx("input",{type:"text",placeholder:g("savedQuery.descriptionPlaceholder","Description (optional)"),value:re,onChange:$=>ge($.target.value),"aria-label":g("savedQuery.description","Query description")}),e.jsx("button",{onClick:Fe,disabled:S||!H.trim(),type:"button",children:S?g("savedQuery.saving","Saving…"):g("savedQuery.save","Save")}),e.jsx("button",{onClick:()=>J(!1),type:"button",children:g("savedQuery.cancel","Cancel")})]}),Le.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:g("savedQuery.mine","Mine")}),Le.map(X)]}),Ne.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:g("savedQuery.sharedSection","Shared")}),Ne.map(X)]}),K.length===0&&e.jsx("p",{className:"nice-saved-query__empty",children:g("savedQuery.empty","No saved queries")})]})]})};exports.NiceDataGridAI=Mi;exports.NiceHighlight=wn;exports.NiceKanbanBoard=ma;exports.NiceList=na;exports.NiceModuleGrid=Ra;exports.NiceReconciliationView=es;exports.NiceSavedQueryPanel=is;exports.NiceSpreadsheet=qa;exports.NiceTable=sa;exports.NiceTileView=ca;exports.NiceTreeGrid=Qi;exports.NiceTreeList=Zi;exports.NiceTreeView=ea;
|