@opencorestack/opengridx 3.5.0 → 3.5.1
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 +12 -0
- package/README.md +4 -3
- package/dist/opengridx.es.js +3707 -3657
- package/dist/opengridx.es.js.map +1 -1
- package/dist/opengridx.umd.js +16 -16
- package/dist/opengridx.umd.js.map +1 -1
- package/docs/architecture/datagrid-orchestration.md +2 -1
- package/docs/features/virtualization.md +5 -5
- package/docs/performance.md +212 -1
- package/docs/roadmap.md +1 -1
- package/lib/components/DataGrid/DataGrid.tsx +8 -1
- package/lib/hooks/core/useGridDevWarnings.ts +21 -6
- package/lib/hooks/core/useGridMaxContentHeight.ts +16 -0
- package/lib/hooks/core/useGridVirtualization.ts +19 -0
- package/lib/utils/maxElementHeight.ts +53 -0
- package/llms.txt +1 -1
- package/package.json +3 -2
package/dist/opengridx.umd.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
(function(_e,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],c):(_e=typeof globalThis<"u"?globalThis:_e||self,c(_e.OpenGridX={},_e.ReactJSXRuntime,_e.React,_e.ReactDOM))})(this,(function(_e,c,s,mt){"use strict";function ko(e,t,n){return Math.max(t??0,Math.min(n??1/0,e))}function Nt(e,t,n=100){if(e.isSpacer)return typeof e.width=="number"?e.width:0;const o=t[e.field]??e.width,r=typeof o=="number"&&Number.isFinite(o)?o:n;return ko(r,e.minWidth,e.maxWidth)}const He=48;function ct(e,t){return t?t.left?.includes(e)?"left":t.right?.includes(e)?"right":null:null}function wa(e,t){const n=[],o=[],r=[];return t?(e.forEach(i=>{const l=ct(i.field,t);l==="left"?n.push(i):l==="right"?r.push(i):o.push(i)}),t.left&&n.sort((i,l)=>{const d=t.left.indexOf(i.field),a=t.left.indexOf(l.field);return d-a}),t.right&&r.sort((i,l)=>{const d=t.right.indexOf(i.field),a=t.right.indexOf(l.field);return d-a}),{left:n,center:o,right:r}):{left:n,center:e,right:r}}function Eo(e,t,n,o,r,i,l,d){const a={};if(!n)return a;let u=(d?He:0)+(i&&l?He:0)+(o&&r?He:0);const g=[];e.forEach(w=>{if(w.isSpacer)return;const y=ct(w.field,n);y==="left"?(a[w.field]=u,u+=Nt(w,t)):y==="right"&&g.push(w)});let m=0;for(let w=g.length-1;w>=0;w--)a[g[w].field]=m,m+=Nt(g[w],t);return a}function Mo(e,t){let n=null,o=null;if(!t)return{lastLeft:n,firstRight:o};for(const r of e){if(r.isSpacer)continue;const i=ct(r.field,t);i==="left"?n=r.field:i==="right"&&o===null&&(o=r.field)}return{lastLeft:n,firstRight:o}}function ni(e,t){return t?t.top?.includes(e)?"top":t.bottom?.includes(e)?"bottom":null:null}function ba(e,t,n=o=>o.id){const o=[],r=[],i=[];return t?(e.forEach(l=>{const d=ni(n(l),t);d==="top"?o.push(l):d==="bottom"?i.push(l):r.push(l)}),t.top&&o.sort((l,d)=>{const a=t.top.indexOf(n(l)),u=t.top.indexOf(n(d));return a-u}),t.bottom&&i.sort((l,d)=>{const a=t.bottom.indexOf(n(l)),u=t.bottom.indexOf(n(d));return a-u}),{top:o,center:r,bottom:i}):{top:o,center:e,bottom:i}}function xa(e,t,n){const o=(e?.left??[]).filter(i=>i!==t),r=(e?.right??[]).filter(i=>i!==t);return n==="left"?{left:[...o,t],right:r}:n==="right"?{left:o,right:[...r,t]}:{left:o,right:r}}const oi=new Set;function Wt(e,t,n){process.env.NODE_ENV==="production"||oi.has(e)||(oi.add(e),console.warn(`[OpenGridX] ${t}.`,n))}function Dn(e,t,n,o){try{return e()}catch(r){return Wt(n,o,r),t}}function ri(e,t,n){const o=e[t];if(!n?.valueGetter)return{value:o};try{return{value:n.valueGetter({row:e,field:t,value:o})}}catch(r){return{value:void 0,error:r??new Error("valueGetter failed")}}}function Le(e,t,n){const{value:o,error:r}=ri(e,t,n);return r!==void 0&&Wt(`valueGetter:${t}`,`valueGetter for column "${t}" threw; the value is read as undefined`,r),o}function No(e,t,n,o){const r=o?.valueFormatter;if(r)return Dn(()=>r({value:n,row:e,field:t}),void 0,`valueFormatter:${t}`,`valueFormatter for column "${t}" threw; the value is shown unformatted`)}function It(e){if(e==null)return null;if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e=="string"){const t=e.trim();if(t==="")return null;const n=Number(t);return Number.isNaN(n)?null:n}if(typeof e=="boolean")return null;if(e instanceof Date){const t=e.getTime();return Number.isNaN(t)?null:t}return typeof e=="bigint"?Number(e):null}const ya=/^(\d{4})-(\d{2})-(\d{2})$/;function gn(e){if(e==null)return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else if(typeof e=="string"){const n=e.trim();if(n==="")return null;const o=ya.exec(n);if(o){const r=Number(o[1]),i=Number(o[2])-1,l=Number(o[3]);if(t=new Date(r,i,l),t.getMonth()!==i||t.getDate()!==l)return null}else t=new Date(n)}else return null;return Number.isNaN(t.getTime())?null:t}function $n(e){const t=gn(e);return t?t.getFullYear()*1e4+(t.getMonth()+1)*100+t.getDate():null}function ii(e){const t=gn(e);if(!t)return"";const n=String(t.getFullYear()).padStart(4,"0"),o=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${n}-${o}-${r}`}let li=null;function si(e){return li??=new Intl.DateTimeFormat,li.format(e)}function va(e,t){if(!e)return;const n=i=>typeof i=="object"?i.value:i,o=i=>typeof i=="object"?i.label:String(i),r=e.find(i=>Object.is(n(i),t))??e.find(i=>String(n(i))===String(t));return r===void 0?void 0:o(r)}function Io(e,t){if(e==null)return"";switch(t?.type){case"date":{const n=gn(e);return n?si(n):String(e)}case"boolean":return e===!0?"Yes":e===!1?"No":String(e);case"singleSelect":return va(t.valueOptions,e)??String(e);default:return String(e)}}const Lo=200;function Ao(e){if(e==="auto")return"auto";const t=typeof e=="string"?Number.parseFloat(e):e;return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:Lo}function Po(e,t){if(e)return Dn(()=>e(t),void 0,"getDetailPanelHeight","getDetailPanelHeight threw; the panel uses the default height")}function Ca(e,t){const n=Ao(e);return n==="auto"?t??Lo:n}function _a(e,t){if(t.size===0||e.size===0)return e;let n=!1;const o=new Set;for(const r of e)t.get(r)?.isGroupRow?n=!0:o.add(r);return n?o:e}const Sa=e=>e.id;function ka(e){if(e===void 0)return{type:"auto",value:0};if(typeof e=="number")return{type:"fixed",value:e};if(typeof e=="string"){if(e.toLowerCase()==="auto")return{type:"auto",value:0};if(e.endsWith("%"))return{type:"percentage",value:parseFloat(e)};const t=parseFloat(e);if(!isNaN(t))return{type:"fixed",value:t}}return{type:"fixed",value:100}}function Ea(e,t,n){const o=new Map;e.forEach(f=>{if(!Object.prototype.hasOwnProperty.call(t,f.field)&&f.flex&&f.flex>0){o.set(f.field,{kind:"flex",flex:f.flex});return}const x=ka(t[f.field]??f.width);x.type==="fixed"?o.set(f.field,{kind:"fixed",width:ko(x.value,f.minWidth,f.maxWidth)}):x.type==="percentage"?o.set(f.field,{kind:"percentage",percentage:x.value}):o.set(f.field,{kind:"flex",flex:1})});const r=e.reduce((f,h)=>{const x=o.get(h.field);if(x.kind==="fixed")return f+x.width;if(x.kind==="percentage")return f+100;if(h.flex&&h.flex>0){const b=h.minWidth??150;return f+(b||(typeof h.width=="number"?h.width:150))}return f+(h.minWidth??150)},0),i=Math.max(n,r),l=e.reduce((f,h)=>{const x=o.get(h.field);return x.kind==="fixed"?f+x.width:f},0),d=new Map,a=Math.max(0,i-l);let u=0;e.forEach(f=>{const h=o.get(f.field);if(h.kind==="fixed")d.set(f.field,h.width);else if(h.kind==="percentage"){const x=h.percentage/100*a,b=ko(x>0?x:100,f.minWidth??50,f.maxWidth);d.set(f.field,b),u+=b}});const g=Math.max(0,a-u),m=new Map,w=e.flatMap(f=>{const h=o.get(f.field);return h.kind!=="flex"?[]:(m.set(f.field,h.flex),[{field:f.field,flex:h.flex,minWidth:f.minWidth??50,maxWidth:f.maxWidth??1/0,frozen:!1,computedWidth:0}])});let y=0;const p=w.length*2;for(;y<p;){y++;const f=w.filter(M=>!M.frozen);if(f.length===0)break;const h=f.reduce((M,S)=>M+S.flex,0),x=w.reduce((M,S)=>S.frozen?M+S.computedWidth:M,0),b=Math.max(0,g-x);if(h<=0){f.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0});break}const v=b/h;let E=0;const k=[],N=[];if(f.forEach(M=>{const S=v*M.flex;S<M.minWidth?(E+=M.minWidth-S,k.push(M)):S>M.maxWidth?(E+=M.maxWidth-S,N.push(M)):M.computedWidth=S}),k.length===0&&N.length===0){f.forEach(M=>{M.frozen=!0});break}E>0?k.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}):E<0?N.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}):(k.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}),N.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}))}return w.forEach(f=>d.set(f.field,f.computedWidth)),{widths:d,flexByField:m}}function Ma(e){const{rowHeight:t,pagination:n,paginatedUnpinnedRows:o,sortedUnpinnedRows:r,expandedRowIds:i,getDetailPanelHeight:l,detailPanelHeights:d,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,pinnedTopRows:g,pinnedBottomRows:m,visibleOrderedColumns:w,pinnedColumns:y,columnWidths:p,viewportWidth:f,checkboxSelection:h,hasDetailPanel:x,rowReordering:b,pinCheckboxColumn:v,pinExpandColumn:E,paginationMode:k,isLoading:N,pageSize:M,getRowId:S=Sa}=e;return s.useMemo(()=>{const D=n?o:r,I=(P,T)=>{const X=S(P);if(!i.has(X))return t;const B=Po(l,{row:P,id:X,rowIndex:T});return t+Ca(B,d?.get(X))},A=D.map((P,T)=>I(P,a+T)),C=A.reduce((P,T,X)=>(P.push((P[X-1]||0)+T),P),[]),L=k==="infinite"&&N&&D.length>0?Math.min(M,20):0,F=(C[C.length-1]||0)+L*t,_=(P,T)=>P?P.reduce((X,B,ee)=>X+I(B,ee),0):T*t,z=_(g,a),K=_(m,u),{left:Q,center:G,right:j}=wa(w,y),H=(h?He:0)+(x?He:0)+(b?He:0),ie=(b?He:0)+(x&&E?He:0)+(h&&v?He:0),{widths:re,flexByField:ue}=Ea([...Q,...G,...j],p,f-H),ae=P=>re.get(P.field)??100,R=P=>({...P,width:ae(P),flex:ue.get(P.field)??P.flex}),te=11,ce=Q.map((P,T)=>({...R(P),zIndex:te+T})),W=11,le=j.map((P,T)=>({...R(P),zIndex:W+(j.length-1-T)})),V=G.map(R),J=V.map(P=>P.width),ne=ce.reduce((P,T)=>P+T.width,0),fe=le.reduce((P,T)=>P+T.width,0),Z=J.reduce((P,T)=>P+T,0),$=ne+Z+fe+H,O=J.reduce((P,T,X)=>(P.push((P[X-1]||0)+T),P),[]);return{rowHeights:A,cumulativeHeights:C,unpinnedRowsHeight:F,pinnedTopHeight:z,pinnedBottomHeight:K,leftPinnedCols:ce,rightPinnedCols:le,unpinnedColsWithWidth:V,unpinnedColWidths:J,unpinnedAccWidths:O,totalWidth:$,leftWidth:ne,rightWidth:fe,unpinnedTotalWidth:Z,systemColumnsWidth:H,pinnedSystemColumnsWidth:ie,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,unpinnedRowsLength:D.length}},[t,n,o,r,i,l,d,a,u,g,m,w,y,p,f,h,x,b,v,E,k,N,M,S])}function Na(e){const t=e.querySelector(".ogx__sticky-bottom");return t?t.getBoundingClientRect().height:0}function Gn(e,t,n,o,r){if(t<0||t>=n.length)return;const i=e.querySelector(".ogx__virtual-container");if(!i)return;const{scrollTop:l,clientHeight:d}=e,a=i.getBoundingClientRect().top-e.getBoundingClientRect().top+l,u=Math.max(o,Na(e)),g=a+(t===0?0:n[t-1]),m=r!==void 0?Math.min(g+r,a+n[t]):a+n[t];g<l+a?e.scrollTop=Math.max(0,g-a):m>l+d-u&&(e.scrollTop=m-d+u)}function To(e,t,n){const{unpinnedAccWidths:o,leftWidth:r,rightWidth:i,systemColumnsWidth:l,pinnedSystemColumnsWidth:d}=n;if(t<0||t>=o.length)return;const a=l+r,u=a+(t>0?o[t-1]:0),g=a+o[t],m=d+r,{scrollLeft:w,clientWidth:y}=e;u<w+m?e.scrollLeft=Math.max(0,u-m):g>w+y-i&&(e.scrollLeft=g-y+i)}function Fo(e,t){const{row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:d,rowMeta:a}=e;if(!i.editable||a?.isGroupRow||n._isSkeleton)return!1;if(!t)return!0;try{return!!t({row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:d})}catch{return!1}}const Ia={},Oo=e=>e==null||typeof e=="string"&&e.trim()==="",ai=e=>{const t=[];for(const n of e){const o=It(n);o!==null&&t.push(o)}return t},ci=(e,t)=>{let n=null,o=null;for(const r of e){const i=It(r);i!==null&&(n===null||t(i,n))&&(n=i,o=r)}return n===null?null:o instanceof Date?o:n},Lt={sum:e=>ai(e).reduce((t,n)=>t+n,0),avg:e=>{const t=ai(e);return t.length?t.reduce((n,o)=>n+o,0)/t.length:null},count:e=>e.filter(t=>!Oo(t)).length,min:e=>ci(e,(t,n)=>t<n),max:e=>ci(e,(t,n)=>t>n),unique:e=>new Set(e.filter(t=>!Oo(t))).size};function Do(e,t){return e?e.aggregable===!1?!1:!e.availableAggregationFunctions||e.availableAggregationFunctions.includes(t):!0}function Hn(e,t,n,o){const r={};for(const[i,l]of Object.entries(t)){const d=n.get(i);if(!Do(d,l))continue;const a=Lt[l];if(!a){console.warn(`[${o}] Unknown aggregation function: "${l}"`);continue}r[i]=a(e.map(u=>Le(u,i,d)))}return r}function pn(e,t){return e==null?"—":typeof e=="number"?t==="avg"?e.toLocaleString(void 0,{maximumFractionDigits:2}):e.toLocaleString():String(e)}const La=new Set(["count","unique"]);function di(e){return e!==void 0&&La.has(e)}function ui(e,t,n){return e?.type==="date"&&(t==="min"||t==="max")&&typeof n=="number"&&Number.isFinite(n)?new Date(n):n}function Bn(e,t,n,o){if(e==null)return"—";if(di(t))return pn(e,t);const r=ui(n,t,e);if(n?.valueFormatter)try{return String(n.valueFormatter({value:r,row:o??{},field:n.field})??"")}catch{}return r instanceof Date?Number.isNaN(r.getTime())?"":si(r):pn(r,t)}const Vt=new Set(["isEmpty","isNotEmpty"]);function $o(e){return e==null?!0:typeof e=="string"?e.trim()==="":Array.isArray(e)?e.length===0:!1}function Aa(e){return e==null?!0:typeof e=="number"?Number.isNaN(e):typeof e=="string"&&e.trim()===""}const hn=e=>(t,n)=>{const o=It(t),r=It(n);return o===null||r===null?!1:e(o,r)},mn=e=>(t,n)=>{const o=$n(t),r=$n(n);return o===null||r===null?!1:e(o,r)},fi=mn((e,t)=>e===t),gi=(e,t)=>{const n=$n(e),o=$n(t);return n===null||o===null?!0:n!==o},pi={contains:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase()),equals:(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:String(e).toLowerCase()===String(t).toLowerCase(),startsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().startsWith(String(t).toLowerCase()),endsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().endsWith(String(t).toLowerCase()),isEmpty:e=>e==null||String(e).trim()==="",isNotEmpty:e=>e!=null&&String(e).trim()!=="","=":hn((e,t)=>e===t),">":hn((e,t)=>e>t),">=":hn((e,t)=>e>=t),"<":hn((e,t)=>e<t),"<=":hn((e,t)=>e<=t),"!=":(e,t)=>{if($o(t))return!0;const n=It(e),o=It(t);return n!==null&&o!==null?n!==o:Aa(e)?!0:String(e).toLowerCase()!==String(t).toLowerCase()},isAnyOf:(e,t)=>{if(e==null)return!1;const n=Array.isArray(t)?t:[t],o=String(e).toLowerCase();return n.some(r=>r!=null&&String(r).toLowerCase()===o)},not:(e,t)=>e instanceof Date?gi(e,t):e==null&&t==null?!1:e==null||t==null?!0:String(e).toLowerCase()!==String(t).toLowerCase(),is:(e,t)=>t==null||t===""?!0:e instanceof Date?fi(e,t):String(e).toLowerCase()===String(t).toLowerCase(),after:mn((e,t)=>e>t),onOrAfter:mn((e,t)=>e>=t),before:mn((e,t)=>e<t),onOrBefore:mn((e,t)=>e<=t)},Pa={is:fi,not:gi};function Ta(e,t){if(!Object.prototype.hasOwnProperty.call(pi,e))return;const n=e;if(t?.type==="date"){const o=Pa[n];if(o)return o}return pi[n]}function Fa(e){return"items"in e&&Array.isArray(e.items)}function Oa(e,t){const{field:n,operator:o,value:r}=e;if(!Vt.has(o)&&$o(r))return null;const i=t.columns?.byField.get(n),l=Ta(o,i);return l?d=>l(Le(d,n,i),r):(t.warned.has(o)||(t.warned.add(o),console.warn(`Unknown filter operator: ${o}`)),null)}function hi(e,t,n){const o=[];for(const r of e){const i=Fa(r)?hi(r.items,r.logicOperator,n):Oa(r,n);i&&o.push(i)}return o.length===0?null:o.length===1?o[0]:t==="or"?r=>o.some(i=>i(r)):r=>o.every(i=>i(r))}function Go(e,t){if(t!=null){switch(typeof t){case"string":e.push(t.toLowerCase());return;case"number":Number.isNaN(t)||e.push(String(t));return;case"boolean":case"bigint":e.push(String(t));return}if(t instanceof Date){const n=ii(t);n&&e.push(n);return}if(Array.isArray(t))for(const n of t)(n==null||typeof n!="object")&&Go(e,n)}}function mi(e,t){const n=[];if(!t){for(const o of Object.values(e))Go(n,o);return n}for(const o of t.quickFilterColumns){const r=Le(e,o.field,o),i=No(e,o.field,r,o);i!=null&&i!==""&&n.push(String(i).toLowerCase()),Go(n,r)}return n}const wi=new WeakMap;function Da(e,t){if(!t)return mi(e,t);let n=wi.get(t);n||(n=new WeakMap,wi.set(t,n));let o=n.get(e);return o||(o=mi(e,t),n.set(e,o)),o}function $a(e,t){const n=(e??[]).map(o=>String(o??"").trim().toLowerCase()).filter(o=>o!=="");return n.length===0?null:o=>{const r=Da(o,t);return n.every(i=>r.some(l=>l.includes(i)))}}function Wn(e,t){if(!e)return null;const n={columns:t,warned:new Set},o="quickFilterValues"in e?e.quickFilterValues:void 0,r=$a(o,t),i=hi(e.items??[],e.logicOperator??"and",n);return r&&i?l=>r(l)&&i(l):r??i}function Ho(e,t,n){const o=Wn(t,n);return o?e.filter(r=>o(r)):e}function bi(e){switch(e){case"number":return["=","!=",">",">=","<","<=","isEmpty","isNotEmpty"];case"date":return["is","not","after","onOrAfter","before","onOrBefore","isEmpty","isNotEmpty"];case"boolean":return["is"];case"singleSelect":return["isAnyOf","is","not"];default:return["contains","equals","startsWith","endsWith","isEmpty","isNotEmpty"]}}function Bo(e,t){return e==null?"":t==="date"||e instanceof Date?ii(e)||(typeof e=="string"?e:""):Array.isArray(e)?e.map(n=>String(n)).join(", "):String(e)}const Ga=new Intl.Collator(void 0,{numeric:!0,sensitivity:"accent"}),Wo=0,xi=1,Ha=2,yi=3,vi=4;function zt(e,t){return{rank:e,num:t,str:""}}function Vo(e,t){if(e==null)return null;if(t==="number"){const n=It(e);return n===null?null:zt(Wo,n)}if(t==="date"){const n=gn(e);return n?zt(xi,n.getTime()):null}switch(typeof e){case"number":return Number.isNaN(e)?null:zt(Wo,e);case"bigint":return zt(Wo,Number(e));case"boolean":return zt(Ha,e?1:0);case"string":return{rank:yi,num:0,str:e}}if(e instanceof Date){const n=e.getTime();return Number.isNaN(n)?null:zt(xi,n)}return{rank:vi,num:0,str:String(e)}}function Ci(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:e.rank!==t.rank?e.rank-t.rank:e.rank===yi||e.rank===vi?Ga.compare(e.str,t.str):e.num<t.num?-1:e.num>t.num?1:0}function zo(e,t){return e===0?0:t==="asc"?e:-e}function Ba(e,t,n,o){return zo(Ci(Vo(e,o),Vo(t,o)),n)}function _i(e,t,n){let o;try{o=e(t.value,n.value,t,n)}catch(r){return Wt(`sortComparator:${t.field}`,`sortComparator for column "${t.field}" threw; the values are treated as equal`,r),0}return typeof o!="number"||Number.isNaN(o)?(Wt(`sortComparator:${t.field}:nan`,`sortComparator for column "${t.field}" returned ${String(o)}; the values are treated as equal`,void 0),0):o}const Wa=e=>e.id;function Va(e,t,n,o=Wa){return t.length===0?e:Ko(e,t,(r,i)=>{const l=n?.byField.get(i.field),d=Le(r,i.field,l);return{value:d,type:l?.type,comparator:l?.sortComparator,params:l?.sortComparator?{id:o(r),field:i.field,row:r,value:d}:void 0}})}function Ko(e,t,n){if(t.length===0||e.length<2)return[...e];const o=t.map(l=>e.map(d=>n(d,l))),r=o.map(l=>l.map(({value:d,type:a})=>Vo(d,a))),i=e.map((l,d)=>d);return i.sort((l,d)=>{for(let a=0;a<t.length;a++){const u=o[a][l],g=o[a][d],m=u.comparator&&u.comparator===g.comparator&&u.params&&g.params?_i(u.comparator,u.params,g.params):Ci(r[a][l],r[a][d]),w=zo(m,t[a].sort);if(w!==0)return w}return l-d}),i.map(l=>e[l])}function za(e,t,n){if(!n)return e.filter(r=>r.field!==t);const o=e.findIndex(r=>r.field===t);return o===-1?[...e,{field:t,sort:n}]:e.map((r,i)=>i===o?{field:t,sort:n}:r)}function jo(e,t={}){const n=new Map,o=[];for(const r of e)n.set(r.field,r),!(r.isSpacer||r.field.startsWith("__"))&&r.filterable!==!1&&t[r.field]!==!1&&o.push(r);return{byField:n,quickFilterColumns:o}}const Kt="__pivot_grand_total__",Ka="__pivot_row__:",Si=e=>`${Ka}${JSON.stringify(e.split(ki))}`,ja="Grand Total",ki="\0",jt="",Uo=`${jt}id`,Ei=e=>e==="id"?Uo:e,Ro={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1},Mi=e=>e.map(t=>String(t??"")).join(ki),Ni=e=>e===void 0||e===""?null:e;function Ua(e,t){const n=e==null,o=t==null;return n||o?n===o?0:n?1:-1:typeof e=="number"&&typeof t=="number"?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():typeof e=="boolean"&&typeof t=="boolean"?Number(e)-Number(t):String(e).localeCompare(String(t),void 0,{numeric:!0})}function Ra(e,t){for(let n=0;n<e.length;n++){const o=Ua(e[n],t[n]);if(o!==0)return o}return 0}function Ii(e,t){if(!e||e.length===0)return null;const n=Lt[t](e);return typeof n=="number"||n instanceof Date?n:null}const qa=e=>"logicOperator"in e&&"items"in e,Xa=e=>!!(e&&e.items&&e.items.length>0);function Ya(e,t){const n=l=>!t.has(l)&&l.includes(jt),o=l=>qa(l)?l.items.length>0&&l.items.every(o):n(l.field),r=[],i=[];for(const l of e.items??[])(o(l)?i:r).push(l);return{source:{...e,items:r},output:{items:i,logicOperator:e.logicOperator}}}function Li(e,t,n,o={}){const r=new Map(t.map(C=>[C.field,C])),i=C=>r.get(C)?.groupable!==!1,l=n.rowFields.filter(i),d=n.columnFields.filter(i),a=new Set,u=n.valueFields.filter(C=>{if(!Do(r.get(C.field),C.aggFn))return!1;const L=`${C.field}${jt}${C.aggFn}`;return a.has(L)?!1:(a.add(L),!0)});if(l.length===0||u.length===0)return Ro;const g=d.length>0,m=Array.from(new Set(u.map(C=>C.field))),w=(C,L)=>Le(C,L,r.get(L)),y=new Map,p=new Map(g?[]:[["",{values:[]}]]);for(const C of e){const L=l.map(j=>w(C,j)),F=Mi(L);let _=y.get(F);_||(_={labels:L.map(Ni),sample:C,cells:new Map},y.set(F,_));const z=d.map(j=>w(C,j)),K=g?Mi(z):"",Q=p.get(K);Q?Q.sample||(Q.sample=C):p.set(K,{values:z.map(Ni),sample:C});let G=_.cells.get(K);G||(G=new Map,_.cells.set(K,G));for(const j of m){const H=w(C,j);if(Oo(H))continue;let ie=G.get(j);ie||(ie=[],G.set(j,ie)),ie.push(H)}}const f=Array.from(p.keys()).sort((C,L)=>Ra(p.get(C).values,p.get(L).values)),h=(C,L)=>g?`${C}${jt}${L.field}${jt}${L.aggFn}`:`${L.field}${jt}${L.aggFn}`,x=new Map;let b=[];for(const[C,L]of y){const F={id:Si(C)};l.forEach((_,z)=>{F[Ei(_)]=L.labels[z]}),F.id=Si(C);for(const _ of f){const z=L.cells.get(_);for(const K of u)F[h(_,K)]=Ii(z?.get(K.field),K.aggFn)}x.set(F.id,L),b.push({row:F,entry:L})}const v=C=>l.includes(C),E=C=>v(C)?r.get(C)?.type:"number",{outputFilterModel:k,sortModel:N}=o;if(Xa(k)){const C=[];for(const F of f)for(const _ of u)C.push({field:h(F,_),type:"number"});const L=Wn(k,jo(C));L&&(b=b.filter(({row:F})=>L(F)))}const M=(C,L)=>L==="id"&&v("id")?C[Uo]:C[L];N&&N.length>0&&(b=[...b].sort((C,L)=>{for(const F of N){const _=M(C.row,F.field),z=M(L.row,F.field),K=v(F.field)?r.get(F.field)?.sortComparator:void 0,Q=K?zo(_i(K,{id:C.row.id,field:F.field,row:C.row,value:_},{id:L.row.id,field:F.field,row:L.row,value:z}),F.sort):Ba(_,z,F.sort,E(F.field));if(Q!==0)return Q}return 0}));const S=b.map(C=>C.row);if(b.length>0){const C={id:Kt};l.forEach((L,F)=>{C[Ei(L)]=F===0?ja:""}),C.id=Kt;for(const L of f)for(const F of m){const _=[];for(const{entry:z}of b){const K=z.cells.get(L)?.get(F);if(K)for(const Q of K)_.push(Q)}for(const z of u)z.field===F&&(C[h(L,z)]=Ii(_,z.aggFn))}S.push(C)}const D=b[0]?.entry.sample,I=C=>C===Kt?D:C===void 0?void 0:x.get(C)?.sample,A=l.map(C=>Za(C,r.get(C),I));for(const C of f){const L=p.get(C),F=g?d.map((_,z)=>{const K=r.get(_),Q=Ja(K,_,L.values[z],L.sample);return K?.headerName?`${K.headerName}: ${Q}`:Q}).join(" / "):"";for(const _ of u){const z=r.get(_.field),K=_.headerName??z?.headerName??_.field;A.push({field:h(C,_),headerName:F?`${F} — ${K} (${_.aggFn})`:`${K} (${_.aggFn})`,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:Q,row:G})=>Bn(Q,_.aggFn,z,G)})}}return{pivotRows:S,pivotColumns:A,colKeys:f,isValid:!0}}function Ja(e,t,n,o){const r=o?No(o,t,n,e):void 0;return r!==void 0?r:n==null?"":String(n)}function Za(e,t,n){const o={field:e,headerName:t?.headerName??e,width:t?.width??140,sortable:!0,hideable:!1};t&&(t.type!==void 0&&(o.type=t.type),t.align!==void 0&&(o.align=t.align),t.headerAlign!==void 0&&(o.headerAlign=t.headerAlign),t.description!==void 0&&(o.description=t.description),t.minWidth!==void 0&&(o.minWidth=t.minWidth),t.maxWidth!==void 0&&(o.maxWidth=t.maxWidth),t.valueOptions!==void 0&&(o.valueOptions=t.valueOptions)),e==="id"&&(o.valueGetter=({row:d})=>d[Uo]);const r=d=>d?.id===Kt,i=t?.valueFormatter;i&&(o.valueFormatter=({value:d,row:a})=>r(a)?String(d??""):i({value:d,row:n(a?.id)??a,field:e}));const l=t?.renderCell;return l&&(o.renderCell=d=>r(d.row)?d.formattedValue??String(d.value??""):l({...d,row:n(d.row.id)??d.row})),o}function qe(e,t){return e===Kt||t?.get(e)?.isGroupRow===!0}const At="__reorder_col__",Pt="__expand_col__",Je="__checkbox_col__",Ze=e=>e===At||e===Pt||e===Je,qo=(e,t)=>e===t||e!==null&&t!==null&&e.id===t.id&&e.field===t.field&&!e.headerFilter==!t.headerFilter,Qa=new Set(["checkbox","radio","button","submit","reset","image","file","color"]),ec=new Set(["textbox","searchbox","combobox","listbox","slider","spinbutton"]);function Ai(e){const t=e.tagName;if(t==="INPUT")return!Qa.has(e.type);if(t==="TEXTAREA"||t==="SELECT"||e.isContentEditable||e.closest('[contenteditable]:not([contenteditable="false"])'))return!0;const n=e.getAttribute("role");return n!==null&&ec.has(n)}const Pi=e=>e!==null&&e.nodeType===1;function Ti(e,t){const n=e.closest(".ogx__detail-panel");if(n&&t.contains(n))return null;const o=e.closest('[role="gridcell"], [role="columnheader"]');return!o||o.closest(".ogx__viewport")!==t?null:o}function Vn(e,t){if(e===t)return"grid";if(!Pi(e)||!t.contains(e))return"foreign";const n=Ti(e,t);return n?n.classList.contains("ogx__cell--editing")?"editor":n===e?"grid":Ai(e)?"foreign":n.classList.contains("ogx__header-cell--checkbox")?"grid":"control":"foreign"}function tc(e,t,n,o){if(!Pi(e))return null;const r=Ti(e,t),i=r?.dataset.field;if(!r||!i)return null;if(r.getAttribute("role")==="columnheader"){const a=r.parentElement;return a?.classList.contains("ogx__header")?{id:null,field:i}:a?.classList.contains("ogx__header-filter-row")?{id:null,field:i,headerFilter:!0}:null}const l=Number(r.parentElement?.getAttribute("data-rowindex")),d=Number.isInteger(l)?n[l]:void 0;return d?{id:o(d),field:i,rowIndex:l}:null}function Fi(e,t){if(!e)return null;for(const n of Array.from(e.children))if(n.dataset.field===t)return n;return null}function Xo(e,t,n){if(t.id===null){const r=e.querySelector(`:scope > .ogx__content > .ogx__sticky-top > .ogx__header-wrap > ${t.headerFilter?".ogx__header-filter-row":".ogx__header"}`),i=Fi(r,t.field);return i&&t.field===Je?i.querySelector("input")??i:i}if(n<0)return null;const o=e.querySelector(`:scope > .ogx__content > .ogx__virtual-container > .ogx__rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-top > .ogx__pinned-rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-bottom > .ogx__pinned-rows > [data-rowindex="${n}"]`);return Fi(o,t.field)}const Oi="__group__";function Xe(e){return!Ze(e)&&e!==Oi}const wt=(e,t)=>e===t||!!e&&!!t&&e.id===t.id&&e.field===t.field;function nc(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>wt(n.anchor,t[o].anchor)&&wt(n.head,t[o].head))}function zn(e,t,n){const{rowIds:o,fields:r,rowIndexById:i,colIndexByField:l,spans:d}=n,a={top:e,bottom:e,left:t,right:t};if(!d)return a;const u=o[e],g=r[t],m=d.getSpanOrigin(u,g)??{rowId:u,field:g},w=i.get(m.rowId),y=l.get(m.field);if(w===void 0||y===void 0)return a;const p=Math.max(1,d.getRowSpan(m.rowId,m.field)),f=Math.max(1,d.getColSpan(m.rowId,m.field));return{top:w,bottom:Math.min(o.length-1,w+p-1),left:y,right:Math.min(r.length-1,y+f-1)}}function oc(e,t){if(!t.spans)return e;let{top:n,bottom:o,left:r,right:i}=e,l=!0;const d=a=>{a.top<n&&(n=a.top,l=!0),a.bottom>o&&(o=a.bottom,l=!0),a.left<r&&(r=a.left,l=!0),a.right>i&&(i=a.right,l=!0)};for(;l;){l=!1;for(let a=n;a<=o;a++)d(zn(a,r,t)),i!==r&&d(zn(a,i,t));for(let a=r+1;a<i;a++)d(zn(n,a,t)),o!==n&&d(zn(o,a,t))}return{top:n,bottom:o,left:r,right:i}}function Kn(e,t){const n=t.rowIndexById.get(e.anchor.id),o=t.rowIndexById.get(e.head.id),r=t.colIndexByField.get(e.anchor.field),i=t.colIndexByField.get(e.head.field);return n===void 0||o===void 0||r===void 0||i===void 0?null:{...oc({top:Math.min(n,o),bottom:Math.max(n,o),left:Math.min(r,i),right:Math.max(r,i)},t),anchorRow:n,anchorCol:r,headRow:o,headCol:i}}const Tt=e=>(e.bottom-e.top+1)*(e.right-e.left+1);function rc(e,t,n,o,r,i){const{headRow:l,headCol:d,anchorRow:a,anchorCol:u,top:g,bottom:m,left:w,right:y}=e;let p=l,f=d;switch(t){case"ArrowRight":f=d>=u?y+1:d+1;break;case"ArrowLeft":f=d<=u?w-1:d-1;break;case"ArrowDown":p=l>=a?m+1:l+1;break;case"ArrowUp":p=l<=a?g-1:l-1;break;case"Home":f=0,n&&(p=0);break;case"End":f=i,n&&(p=r);break;case"PageUp":p=l-o;break;case"PageDown":p=l+o;break;default:return null}return p=Math.min(Math.max(p,0),r),f=Math.min(Math.max(f,0),i),p===l&&f===d?null:{row:p,col:f}}function Di(e,t,n,o){const r=o&&o.row===t?o.col:void 0;if(!e||t<e.top||t>e.bottom)return r===void 0?null:{left:0,right:-1,isTop:!1,isBottom:!1,bottomOffset:0,fillHandleCol:r};const i={left:e.left,right:e.right,isTop:t===e.top,isBottom:t===e.bottom,bottomOffset:n?e.bottom-t:0};return r!==void 0&&(i.fillHandleCol=r),i}const ic=(e,t)=>e===t||!!e&&!!t&&e.left===t.left&&e.right===t.right&&e.isTop===t.isTop&&e.isBottom===t.isBottom&&e.bottomOffset===t.bottomOffset&&e.fillHandleCol===t.fillHandleCol,Yo=1,$i=2,Gi=4,Hi=8,Bi=16,Wi=32;function lc(e,t,n,o){if(!e)return 0;const r=e.fillHandleCol===t?Wi:0,i=t+Math.max(1,n)-1;if(t<e.left||i>e.right)return r;let l=Yo|r;return e.isTop&&(l|=$i),(e.isBottom||o>1&&o-1>=e.bottomOffset)&&(l|=Gi),t===e.left&&(l|=Hi),i===e.right&&(l|=Bi),l}function sc(e,t,n){const o=(r,i,l)=>`${r} ${r===1?i:l}`;return`${o(e,"cell","cells")} selected, ${o(t,"row","rows")} by ${o(n,"column","columns")}`}const ac=1e5,cc=e=>e.id,Vi=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]);function dc(e,t,n,o,r){if(!e||n.length===0)return{cell:null,rowIndex:-1};const i=(n.find(u=>!Ze(u.field))??n[0]).field,l=n.some(u=>u.field===e.field)?e.field:i;if(e.id===null){const u=!!e.headerFilter&&r;return l===e.field&&u===!!e.headerFilter?{cell:e,rowIndex:-1}:{cell:u?{id:null,field:l,headerFilter:u}:{id:null,field:l},rowIndex:-1}}const d=e.rowIndex;let a=d!==void 0&&t[d]&&o(t[d])===e.id?d:t.findIndex(u=>o(u)===e.id);return a===-1?t.length===0?{cell:{id:null,field:l},rowIndex:-1}:(a=Math.min(Math.max(d??0,0),t.length-1),{cell:{id:o(t[a]),field:l,rowIndex:a},rowIndex:a}):{cell:l===e.field?e:{...e,field:l},rowIndex:a}}function uc(e){const{allRenderableRows:t,navigationColumns:n,checkboxSelection:o,selectedRowIds:r,handleSelectionChange:i,handleDetailPanelToggle:l,editingHandlers:d,setKeyboardMode:a,sortModel:u,handleSort:g,handleSortAdd:m,multiSort:w=!1,isCellEditable:y,pagination:p,pageSize:f,virtualization:h,viewportRef:x,pinnedTopRowCount:b=0,getRowId:v=cc,rowMetaMap:E,onRowActivate:k,toggleRowExpansion:N,handleSelectAll:M,rowSelectionEnabled:S=!0,multipleRowSelectionEnabled:D=!0,pinCheckboxColumn:I=!0,pinExpandColumn:A=!0,rowHeight:C,getSpanOrigin:L,cellSelection:F,headerFilters:_=!1}=e,[z,K]=s.useState(null),[Q,G]=s.useState(!1),j=s.useMemo(()=>dc(z,t,n,v,_),[z,t,n,v,_]),H=j.cell,ie=j.rowIndex,re=s.useRef(!1),ue=s.useRef(!1),ae=s.useRef(!1),R=s.useRef(null),te=s.useCallback($=>{ue.current=!0,$.focus({preventScroll:!0}),ue.current=!1},[]),ce=s.useCallback(()=>{const $=x.current;$&&!$.contains($.ownerDocument.activeElement)&&te($)},[x,te]),W=s.useMemo(()=>n.find($=>!Ze($.field))??n[0],[n]),le=s.useCallback(()=>{if(o)return{id:null,field:Je};if(!W)return null;const $=t[0];return $?{id:v($),field:W.field,rowIndex:0}:{id:null,field:W.field}},[o,W,t,v]),V=s.useCallback(($,O)=>{const P=x.current;if(!P)return;const{cumulativeHeights:T,pinnedBottomHeight:X,columnMetrics:B}=h;if($>=0&&Gn(P,$-b,T,X,C),Ze(O)){!(O===At||O===Pt&&A||O===Je&&I)&&P.scrollLeft>0&&(P.scrollLeft=0);return}if(!B)return;const{clientWidth:ee,scrollLeft:q}=P,{leftPinnedWidth:Y,rightPinnedWidth:oe,unpinnedAccWidths:me,unpinnedCols:U,totalSpecialsWidth:se,pinnedSpecialsWidth:we}=B,pe=U.findIndex(Ee=>Ee.field===O);if(pe===-1)return;const he=se+Y+(pe>0?me[pe-1]:0),ve=se+Y+me[pe],be=q+we+Y,de=q+ee-oe;let ye=q;he<be?ye=Math.max(0,he-we-Y):ve>de&&(ye=ve-ee+oe),ye!==q&&(P.scrollLeft=ye)},[x,h,b,C,I,A]);s.useLayoutEffect(()=>{const $=x.current,O=!qo(R.current,H);if(R.current=H,!$||!H)return;const P=$.ownerDocument,T=P.activeElement;let X;if(T===$?X=!0:!T||T===P.body?X=re.current:$.contains(T)?X=O:X=!1,!X)return;const B=Xo($,H,ie);B?B.contains(T)||B.focus({preventScroll:!0}):T!==$&&te($)});const J=s.useCallback(()=>{ae.current=!0,a(!1)},[a]),ne=s.useCallback($=>{const O=$.currentTarget,P=$.relatedTarget,T=!(P instanceof Node&&O.contains(P)),X=ae.current;if(ae.current=!1,re.current=!0,G(!0),ue.current)return;if($.target===O){if(!T)return;if(X||a(!0),H){const q=Xo(O,H,ie);q?q.focus({preventScroll:!0}):V(ie,H.field);return}const ee=le();ee&&(K(q=>q??ee),V(ee.rowIndex??-1,ee.field));return}const B=tc($.target,O,t,v);B&&!qo(B,H)&&K(B)},[H,ie,le,V,a,t,v]),fe=s.useCallback($=>{const O=$.relatedTarget;O instanceof Node&&$.currentTarget.contains(O)||(re.current=!1,ae.current=!1,G(!1),a(!1))},[a]),Z=s.useCallback($=>{const O=$.currentTarget,P=Vn($.target,O);if(P==="foreign"||(a(!0),$.nativeEvent?.isComposing||$.keyCode===229))return;const{key:T}=$,X=T===" "||T==="Spacebar",B=!!d.editingCell,ee=_?-2:-1,q=(ge,Ce)=>{const ke=n[Ce];!ke||ge<ee||ge>=t.length||(ge===ee?K({id:null,field:ke.field}):ge<0?K({id:null,field:ke.field,headerFilter:!0}):K({id:v(t[ge]),field:ke.field,rowIndex:ge}),V(ge,ke.field))};if(!H){if(!Vi.has(T))return;const ge=le();if(!ge)return;$.preventDefault(),K(ge),V(ge.rowIndex??-1,ge.field);return}const{id:Y,field:oe}=H,me=Y===null&&!!H.headerFilter,U=Y!==null?ie:me?-1:ee,se=n.findIndex(ge=>ge.field===oe),we=n.filter(ge=>Ze(ge.field)).length,pe=ge=>qe(ge,E),he=(ge,Ce,ke)=>{const xe=n[ke];return Ze(xe.field)?!1:Fo({row:ge,field:xe.field,value:Le(ge,xe.field,xe),colDef:xe,rowIndex:Ce,colIndex:ke-we,rowMeta:E?.get(v(ge))},y)},ve=ge=>{let Ce=U,ke=se;const xe=(t.length+1)*n.length;for(let je=0;je<xe;je++){if(ke+=ge,ke>=n.length?(ke=0,Ce++):ke<0&&(ke=n.length-1,Ce--),Ce<0||Ce>=t.length)return null;const nt=t[Ce];if(!L?.(v(nt),n[ke].field)&&he(nt,Ce,ke))return{r:Ce,c:ke}}return null};if(B){if(T==="Enter")$.preventDefault(),d.stopCellEdit();else if(T==="Escape")$.preventDefault(),d.stopCellEdit({cancel:!0});else if(T==="Tab"&&Y!==null){const ge=ve($.shiftKey?-1:1);ge&&($.preventDefault(),d.stopCellEdit(),q(ge.r,ge.c))}return}if(T==="Escape"&&F?.collapseSelection()){$.preventDefault();return}if(T==="Tab"||T==="Escape"||P==="control"&&(T==="Enter"||X))return;if(($.ctrlKey||$.metaKey)&&(T==="a"||T==="A")){if(F){F.selectAllCells()&&$.preventDefault();return}if(!S||!D||!M)return;$.preventDefault(),M(!0);return}if(me&&(T==="Enter"||X))return;if(Y===null){if(T==="Enter"||X){if($.preventDefault(),oe===Je){Xo(O,H,-1)?.click();return}const ge=n[se];if(!ge||Ze(oe)||ge.sortable===!1)return;const Ce=u.find(xe=>xe.field===oe),ke=Ce?Ce.sort==="asc"?"desc":null:"asc";(w||$.shiftKey)&&m?m(oe,ke):g(oe,ke);return}}else if(T==="Enter"||X){$.preventDefault();const ge=t[U];if(oe===Je){i(Y,!r.has(Y));return}if(oe===Pt){$.shiftKey||l(Y);return}if(X){$.shiftKey&&S&&!pe(Y)&&i(Y,!r.has(Y));return}if(oe===At)return;if(he(ge,U,se)){d.startCellEdit({id:Y,field:oe,value:Le(ge,oe,n[se])});return}if(N&&E?.get(Y)?.hasChildren){N(Y);return}k?.({row:ge,id:Y,rowIndex:U});return}if($.altKey&&(T==="ArrowRight"||T==="ArrowLeft")&&N&&Y!==null){$.preventDefault();const ge=E?.get(Y);ge?.hasChildren&&!!ge.isExpanded!=(T==="ArrowRight")&&N(Y);return}if(!Vi.has(T))return;$.preventDefault();const be=t.length-1,de=n.length-1,ye=$.ctrlKey||$.metaKey,Ee=p?f:10;if(F&&$.shiftKey&&Y!==null&&Xe(oe)&&F.extendSelection(T,ye,Ee,H))return;const Me=(ge,Ce)=>{switch(T){case"ArrowRight":return Ce+1>de?{r:ge+1,c:0}:{r:ge,c:Ce+1};case"ArrowLeft":return Ce-1<0?{r:ge-1,c:de}:{r:ge,c:Ce-1};case"ArrowDown":return{r:ge+1,c:Ce};case"ArrowUp":return{r:ge-1,c:Ce};case"Home":return{r:ye?ee:ge,c:0};case"End":return{r:ye?be:ge,c:de};case"PageUp":return{r:Math.max(ee,ge-Ee),c:Ce};default:return{r:Math.min(be,ge+Ee),c:Ce}}},Ne=({r:ge,c:Ce})=>ge>=ee&&ge<=be&&Ce>=0&&Ce<=de,Ie=({r:ge,c:Ce})=>ge>=0?L?.(v(t[ge]),n[Ce].field)??null:null;let Se=Me(U,se);if(T.startsWith("Arrow"))for(let ge=Ne(Se)?Ie(Se):null;ge&&ge.rowId===Y&&ge.field===oe;ge=Ne(Se)?Ie(Se):null)Se=Me(Se.r,Se.c);if(!Ne(Se))return;const Oe=Ie(Se);if(Oe){const ge=t.findIndex(ke=>v(ke)===Oe.rowId),Ce=n.findIndex(ke=>ke.field===Oe.field);ge!==-1&&Ce!==-1&&(Se={r:ge,c:Ce})}Se.r===U&&Se.c===se||q(Se.r,Se.c)},[H,ie,t,n,d,r,i,l,a,u,g,m,w,y,p,f,E,k,N,M,S,D,le,V,L,v,F,_]);return{focusedCell:H,setFocusedCell:K,viewportTabIndex:Q?-1:0,ensureGridFocus:ce,handleFocus:ne,handleBlur:fe,handleKeyDown:Z,handleMouseDownCapture:J}}const Jo=[];function fc(e){const{isPivotActive:t}=e,n=t?Jo:e.rowGroupingModel,o=e.treeData&&!t,r=o&&e.hasTreeDataPath,i=n.length>0;return{rowReordering:e.rowReordering&&!t,hierarchyRowGroupingModel:n,isTreeDataRequested:o,isTreeData:r,isRowGrouping:i,isHierarchyEnabled:r||i,hasGroupingColumn:e.hasGroupingColDef&&(i||r),pagination:e.pagination&&!i&&e.paginationMode!=="infinite",listView:e.listView&&e.hasListViewColumn}}const gc=[],pc={rowFields:[],columnFields:[],valueFields:[]},zi=100;function hc(e){return!e||e.length===0||e.includes(zi)?zi:e[0]}function mc(e){const{initialState:t,sortModel:n,onSortModelChange:o,filterModel:r,onFilterModelChange:i,aggregationModel:l,onAggregationModelChange:d,rowGroupingModel:a,onRowGroupingModelChange:u,columnVisibilityModel:g,onColumnVisibilityModelChange:m,pinnedColumns:w,onPinnedColumnsChange:y,pivotModel:p,onPivotModelChange:f,paginationModel:h,onPaginationModelChange:x,pageSizeOptions:b,rowSelectionModel:v,onRowSelectionModelChange:E,density:k,cellSelectionModel:N,onCellSelectionModelChange:M}=e,[S,D]=s.useState(()=>t?.sorting?.sortModel??[]),I=n!==void 0,A=I?n:S,C=s.useCallback(xe=>{I||D(xe),o?.(xe)},[I,o]),[L,F]=s.useState(()=>t?.filter?.filterModel??{items:[]}),_=r!=null,z=_?r:L,K=s.useCallback(xe=>{_||F(xe),i?.(xe)},[_,i]),Q=l!==void 0,[G,j]=s.useState(()=>l??{}),H=JSON.stringify(Q?l:G),ie=s.useMemo(()=>JSON.parse(H),[H]),re=s.useCallback(xe=>{Q||j(xe),d?.(xe)},[Q,d]),ue=a!==void 0,[ae,R]=s.useState(Jo),te=(ue?a:ae)||Jo,ce=s.useCallback(xe=>{ue||R(xe),u?.(xe)},[ue,u]),W=g!==void 0,[le,V]=s.useState(()=>t?.columns?.columnVisibilityModel??{}),J=W?g:le,ne=s.useCallback(xe=>{W||V(xe),m?.(xe)},[W,m]),fe=w!==void 0,[Z,$]=s.useState(()=>t?.columns?.pinnedColumns??{}),O=fe?w:Z,P=s.useCallback(xe=>{fe||$(xe),y?.(xe)},[fe,y]),[T,X]=s.useState(()=>p??pc),B=p??T,ee=s.useCallback(xe=>{X(xe),f?.(xe)},[f]),q=h!==void 0,[Y,oe]=s.useState(()=>t?.pagination?.paginationModel??h??{page:0,pageSize:hc(b)}),me=q?h:Y,U=s.useCallback(xe=>{q||oe(xe),x?.(xe)},[q,x]),se=v!==void 0,[we,pe]=s.useState([]),he=se?v:we,ve=s.useMemo(()=>new Set(he),[he]),be=s.useRef(null);s.useLayoutEffect(()=>{be.current=null});const de=s.useCallback(()=>be.current,[]),ye=s.useCallback(xe=>{be.current=xe,se||pe(xe),E?.(xe)},[se,E]),[Ee]=s.useState(()=>t?.density?.density??"standard"),Me=k??Ee,Ne=N!==void 0,[Ie,Se]=s.useState(gc),Oe=Ne?N:Ie,ge=s.useRef(null);s.useLayoutEffect(()=>{ge.current=null});const Ce=s.useCallback(()=>ge.current,[]),ke=s.useCallback((xe,je)=>{ge.current=xe,Ne||Se(xe),M?.(xe,{reason:je})},[Ne,M]);return{sortModel:A,isSortControlled:I,setInternalSortModel:D,handleSortModelChange:C,filterModel:z,isFilterControlled:_,handleFilterModelChange:K,aggregationModel:ie,handleAggregationModelChange:re,rowGroupingModel:te,handleRowGroupingModelChange:ce,columnVisibilityModel:J,handleColumnVisibilityModelChange:ne,pinnedColumns:O,handlePinnedColumnsChange:P,currentPivotModel:B,handlePivotModelChange:ee,effectivePaginationModel:me,handlePaginationModelChange:U,rowSelectionModel:he,selectedRowIds:ve,isSelectionControlled:se,setInternalRowSelectionModel:pe,handleRowSelectionModelChange:ye,getPendingRowSelectionModel:de,density:Me,cellSelectionModel:Oe,handleCellSelectionModelChange:ke,getPendingCellSelectionModel:Ce}}const Ki=s.createContext(null),wc=52,bc=56,xc=32,yc=72;function jn(e){if(e===void 0)return;const t=/^(\d+(?:\.\d+)?)(?:\s*px)?$/.exec(e.trim());if(!t)return;const n=Number(t[1]);return n>0?n:void 0}function vc(e){const{rowHeight:t,headerHeight:n,density:o}=e,r=s.useContext(Ki)?.grid;let i;return o==="compact"?i=jn(r?.rowHeightCompact)??xc:o==="comfortable"?i=jn(r?.rowHeightComfortable)??yc:i=t??jn(r?.rowHeightStandard)??wc,{rowHeight:i,headerHeight:n??jn(r?.headerHeight)??bc}}function Un(e){return e>=1?Math.floor(e):1}function Zo(e,t){return Math.max(1,Math.ceil(Math.max(0,e)/Un(t)))}function Cc(e){const{paginationMode:t,hasDataSource:n,dataSourceRowCount:o,rowCountProp:r,clientRowCount:i}=e;return t!=="server"?i:(n?o??r:r)??i}function ji(e){return e?{paginationRowsPerPage:e.paginationRowsPerPage,paginationOf:e.paginationOf,paginationPage:e.paginationPage}:void 0}function Ui(e,t){return Number.isFinite(e)?Math.min(Math.max(0,Math.floor(e)),Math.max(0,t-1)):0}function _c(e){const{effectiveRows:t,activeHierarchyHandlers:n,filterMode:o,filterModel:r,sortModel:i,sortingMode:l,pagination:d,paginationMode:a,effectivePaginationModel:u,pinnedRows:g,getRowId:m,columnLookup:w,hierarchyField:y}=e,p=s.useMemo(()=>n?n.getVisibleRows({labelField:y})||[]:o==="server"?t:Ho(t,r,w),[t,r,n,y,o,w]),f=s.useMemo(()=>n?o==="server"?t:Ho(t,r,w):p,[n,p,o,t,r,w]),{top:h,center:x,bottom:b}=s.useMemo(()=>n?{top:[],center:p,bottom:[]}:ba(p,g,m),[p,g,n,m]),v=s.useMemo(()=>n||l==="server"?x:Va(x,i,w,m),[x,i,n,l,w,m]),E=d&&a!=="server",k=Un(u.pageSize),N=E?Ui(u.page,Zo(v.length,k)):u.page,M=s.useMemo(()=>{if(!E)return v;const D=N*k;return v.slice(D,D+k)},[v,E,N,k]),S=s.useMemo(()=>{const D=d?M:v;return[...h,...D,...b]},[h,M,v,b,d]);return{filteredRows:p,dataRows:f,pinnedTopRows:h,unpinnedRows:x,pinnedBottomRows:b,sortedUnpinnedRows:v,paginatedUnpinnedRows:M,currentPage:N,allRenderableRows:S}}function Sc(e){const{layout:t,scrollTop:n,scrollLeft:o,viewportWidth:r,viewportHeight:i,autoHeight:l,rowReordering:d,hasDetailPanel:a,checkboxSelection:u,pinCheckboxColumn:g,pinExpandColumn:m,overscanRows:w=5}=e;return s.useMemo(()=>{const{unpinnedAccWidths:y,unpinnedColsWithWidth:p,leftPinnedCols:f,rightPinnedCols:h,totalWidth:x,leftWidth:b,rightWidth:v,unpinnedTotalWidth:E,systemColumnsWidth:k,cumulativeHeights:N,pinnedTopHeight:M,pinnedBottomHeight:S,unpinnedRowsHeight:D,rowHeights:I,unpinnedRowsLength:A}=t,C=r||1e3,L=l?M+D+S+50:i||600,F=6,_=Math.max(0,o-b),z=o+C-b;let K=0,Q=p.length-1,G=0,j=y.length-1;for(;G<=j;){const ne=G+j>>>1;y[ne]<_?G=ne+1:j=ne-1}K=Math.max(0,G-F);for(let ne=K;ne<y.length;ne++){if((ne===0?0:y[ne-1])>z){Q=Math.min(p.length-1,ne+F);break}Q=Math.min(p.length-1,ne+F)}const H=K>0?y[K-1]:0,ie=E-y[Q],re=[...f,...H>0?[{field:"__spacer_left__",width:H,isSpacer:!0}]:[],...p.slice(K,Q+1),...ie>0?[{field:"__spacer_right__",width:ie,isSpacer:!0}]:[],...h],ae=C>0&&x>C?16:0,R=M+D+S+ae+2;let te=0,ce=A-1,W=0,le=0,V=N.length-1;for(;le<=V;){const ne=le+V>>>1;N[ne]<n?le=ne+1:V=ne-1}te=Math.max(0,le-w),W=te>0?N[te-1]:0;for(let ne=te;ne<N.length;ne++)if(N[ne]>=n+L){ce=Math.min(A-1,ne+w);break}const J=(d?48:0)+(a&&m?48:0)+(u&&g?48:0);return{renderContext:{firstRowIndex:te,lastRowIndex:ce,firstColumnIndex:K,lastColumnIndex:Q},offsetTop:W,offsetLeft:0,totalHeight:R,pinnedTopHeight:M,pinnedBottomHeight:S,totalWidth:x,rowHeights:I,cumulativeHeights:N,virtualColumns:re,columnMetrics:{leftPinnedWidth:b,rightPinnedWidth:v,unpinnedAccWidths:y,unpinnedCols:p,totalSpecialsWidth:k,pinnedSpecialsWidth:J}}},[t,n,o,r,i,l,d,a,u,g,m,w])}const Qo="application/x-ogx-row",er="application/x-ogx-column";function Ri(e,t,n){const o=e.dataTransfer;!o||typeof o.setData!="function"||(o.setData(t,n),o.setData("text/plain",n))}function Rn(e,t){const n=e.dataTransfer?.types;return n?Array.from(n).includes(t):!0}function qi(e,t){if(!e||typeof e.addEventListener!="function")return()=>{};const n=()=>t();return e.addEventListener("dragend",n,{once:!0}),()=>e.removeEventListener("dragend",n)}function kc(e){const{columns:t,onColumnOrderChange:n,disableColumnReorder:o=!1}=e,[r,i]=s.useState(null),[l,d]=s.useState(null),a=s.useRef(()=>{}),u=s.useCallback(()=>{a.current(),a.current=()=>{},i(null),d(null)},[]);s.useEffect(()=>()=>a.current(),[]);const g=s.useCallback(y=>p=>{if(!o){if(!t.some(f=>f.field===y)){p.preventDefault();return}a.current(),a.current=qi(p.currentTarget,u),i(y),p.dataTransfer&&(p.dataTransfer.effectAllowed="move",Ri(p,er,y))}},[t,o,u]),m=s.useCallback(y=>p=>{if(!(o||r===null)){if(!Rn(p,er)){u();return}p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="move"),d(y)}},[r,o,u]),w=s.useCallback(y=>p=>{if(p.preventDefault(),o||r===null||!Rn(p,er)){u();return}const f=t.findIndex(x=>x.field===r),h=t.findIndex(x=>x.field===y);u(),!(f===-1||h===-1||f===h)&&n?.({column:t[f],oldIndex:f,targetIndex:h})},[t,r,o,n,u]);return{draggedColumn:r,dragOverColumn:l,onDragStart:o?void 0:g,onDragOver:o?void 0:m,onDragEnd:o?void 0:u,onDrop:o?void 0:w}}function tr({isExpanded:e,onClick:t,variant:n="chevron",tabIndex:o}){return c.jsx("button",{className:`ogx-expand-icon ${e?"ogx-expand-icon--expanded":""}`,onClick:r=>{t&&t(r)},"aria-label":e?"Collapse row":"Expand row",type:"button",tabIndex:o,children:n==="plus-minus"?c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[c.jsx("path",{d:"M4 8H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M8 4V12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:e?0:1,transition:"opacity 0.2s ease",transformOrigin:"center"}})]}):c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{transform:e?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease"},children:c.jsx("path",{d:"M6 4L10 8L6 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function Ec({renderFn:e}){"use no memo";return c.jsx(c.Fragment,{children:e()})}function Mc(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>Object.is(n,t[o])):Object.is(e,t)}class Ft extends s.Component{constructor(t){super(t),this.state={hasError:!1,error:null,resetKey:t.resetKey}}static getDerivedStateFromProps(t,n){return Mc(t.resetKey,n.resetKey)?null:n.hasError?{hasError:!1,error:null,resetKey:t.resetKey}:{resetKey:t.resetKey}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){process.env.NODE_ENV!=="production"&&console.warn(`[CellErrorBoundary] field="${this.props.field}"`,t,n.componentStack)}render(){return this.state.hasError?c.jsx("div",{className:"ogx__cell-error",role:"img","aria-label":`Error in cell: ${this.props.field}`,title:this.state.error?.message??"Render error",children:"⚠"}):c.jsx(Ec,{renderFn:this.props.renderFn})}}function Nc(e,t,n){if(!t||!n)return{valueGetter:e.valueGetter,valueFormatter:e.valueFormatter};const o=l=>n.has(l.id),r=e.valueGetter,i=e.valueFormatter;return{valueGetter:r?l=>o(l.row)?l.value:r(l):void 0,valueFormatter:l=>o(l.row)?Bn(l.value,t,e,l.row):i?i(l):l.value==null?"":String(l.value)}}function Xi(e,t){if(!t)return e;const n=t.left??[],o=t.right??[],r=i=>{const l=ct(i.field,t);return l==="left"?n.indexOf(i.field)-n.length:l==="right"?1+o.indexOf(i.field):0};return[...e].sort((i,l)=>r(i)-r(l))}const qn=e=>e.formattedValue??e.value;function Yi(e,t,n){const o=e.renderCell;if(!o)return{useDefault:!0};const r=!!t.rowMeta?.isGroupRow;if(!n){const l=o(t);return r&&l===void 0?{useDefault:!0}:{useDefault:!1,content:l}}let i;try{i=o(t)}catch(l){return{useDefault:!1,content:c.jsx(Ft,{field:e.field,resetKey:t.row,renderFn:()=>{throw l}})}}return r&&i===void 0?{useDefault:!0}:{useDefault:!1,content:c.jsx(Ft,{field:e.field,resetKey:t.row,renderFn:()=>i})}}function Ic(e,t,n){const o=e.rowMeta;if(!o?.isGroupRow)return qn(e);if(o.isGroupFooter)return null;const r=o.descendantCount;if(t&&o.hasChildren){const i=o.groupLabel??`${o.groupingField}: ${String(o.groupingValue)}`;return c.jsxs("div",{className:"ogx__group-cell-content",children:[i,r!==void 0?` (${r})`:""]})}return n?c.jsxs("div",{className:"ogx__group-cell-content",children:[o.groupLabel,r!==void 0&&r>0?` (${r})`:""]}):qn(e)}const Lc=e=>e.id;function Ac(e){const{activeColumns:t,isHierarchyEnabled:n,isRowGrouping:o,isTreeData:r,activeHierarchyHandlers:i,columnVisibilityModel:l,columnOrder:d,onColumnOrderChange:a,onColumnOrderModelChange:u,disableColumnReorder:g,pivotMode:m,checkboxSelection:w,hasDetailPanel:y,rowReordering:p,initialState:f,setColumns:h,pinnedColumns:x,getRowId:b=Lc,aggregationModel:v,groupingRows:E}=e,k=s.useMemo(()=>t.map(V=>V.field),[t]),[N,M]=s.useState(()=>f?.columns?.columnOrder??null),S=m?k.join("\0"):"",[D,I]=s.useState(null),A=D&&D.key===S?D.order:k,L=m?A:d??(N??k),F=s.useCallback(V=>{if(m){I(J=>{const ne=J&&J.key===S?J.order:k;return{key:S,order:typeof V=="function"?V(ne):V}});return}M(J=>typeof V=="function"?V(J??k):V)},[m,S,k]),_=s.useCallback(V=>m&&V.hideable===!1||l[V.field]!==!1,[m,l]),z=s.useMemo(()=>{if(!n)return;const V=new Map(L.map((Z,$)=>[Z,$])),J=Z=>V.get(Z.field)??t.indexOf(Z),ne=[...t].sort((Z,$)=>J(Z)-J($));return(Xi(ne.filter(Z=>l[Z.field]!==!1),x)[0]??t[0])?.field},[n,L,t,l,x]),K=s.useMemo(()=>{if(!n)return t;const V=o?E:void 0;return t.map(J=>{const ne=Nc(J,v?.[J.field],V);return J.field===z?{...J,...ne,renderCell:fe=>{const Z=fe.rowMeta,$=Z?.treeDepth??0,O=!!Z?.hasChildren,P=!!Z?.isExpanded,T=Yi(J,fe,!0),X=T.useDefault?Ic(fe,o,r):T.content;return c.jsxs("div",{style:{display:"flex",alignItems:"center",paddingLeft:$*24,width:"100%",height:"100%"},children:[c.jsx("div",{style:{marginRight:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:O?"pointer":"default",flexShrink:0},children:O?c.jsx("div",{onClick:B=>{B.stopPropagation(),B.preventDefault(),i?.toggleExpansion(b(fe.row))},onMouseDown:B=>{B.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:c.jsx(tr,{isExpanded:P,tabIndex:-1,onClick:B=>{B.stopPropagation(),B.preventDefault(),i?.toggleExpansion(b(fe.row))}})}):null}),c.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:X})]})}}:{...J,...ne,renderCell:fe=>{const Z=fe.rowMeta;if(!Z?.isGroupRow)return J.renderCell?J.renderCell(fe):qn(fe);const $=Yi(J,fe,!1);return $.useDefault?J.field===Z.groupingField&&!Z.isGroupFooter||fe.value==null?null:qn(fe):$.content}}})},[t,n,o,r,i,z,b,v,E]),[Q,G]=s.useState(()=>f?.columns?.columnWidths??{}),j=s.useCallback((V,J)=>{G(ne=>({...ne,[V]:J}))},[]);s.useEffect(()=>{h(t)},[t,h]);const H=s.useMemo(()=>{const V=new Map(L.map((J,ne)=>[J,ne]));return[...K].sort((J,ne)=>{const fe=V.get(J.field)??K.indexOf(J),Z=V.get(ne.field)??K.indexOf(ne);return fe-Z})},[K,L]),ie=s.useMemo(()=>H.filter(_),[H,_]),re=s.useCallback((V,J)=>{(m||!d)&&F(V),J&&a?.(J),m||u?.(V)},[m,d,F,a,u]),ue=s.useCallback((V,J)=>{const ne=H.map(Z=>Z.field),[fe]=ne.splice(V,1);ne.splice(J,0,fe),re(ne,{column:H[V],oldIndex:V,targetIndex:J})},[H,re]),ae=kc({columns:H,onColumnOrderChange:s.useCallback(({oldIndex:V,targetIndex:J})=>ue(V,J),[ue]),disableColumnReorder:g}),R=s.useCallback((V,J)=>{const ne=H.findIndex(Z=>Z.field===V),fe=H.findIndex(Z=>Z.field===J);ne===-1||fe===-1||ne===fe||ue(ne,fe)},[H,ue]),te=s.useCallback(()=>{re(k)},[re,k]),ce=s.useMemo(()=>Xi(ie,x),[ie,x]),W=s.useMemo(()=>{const V=[];return p&&V.push({field:At,sortable:!1,editable:!1}),y&&V.push({field:Pt,sortable:!1,editable:!1}),w&&V.push({field:Je,sortable:!1,editable:!1}),[...V,...ce]},[ce,w,y,p]),le=s.useMemo(()=>new Map(ce.map((V,J)=>[V.field,J])),[ce]);return{effectiveColumns:K,hierarchyField:z,orderedColumns:H,visibleOrderedColumns:ie,renderOrderedColumns:ce,navigationColumns:W,columnIndexMap:le,columnWidths:Q,effectiveColumnOrder:L,setInternalColumnOrder:F,columnReorderHandlers:ae,moveColumn:R,resetColumnOrder:te,handleColumnResize:j}}const Pc=e=>e.id;function Tc(e){const{renderContext:t,pinnedTopRows:n,pinnedBottomRows:o,paginatedUnpinnedRows:r,sortedUnpinnedRows:i,pagination:l,getRowId:d=Pc}=e;return s.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:u}=t,g=l?r:i,m=n.length,w=n.map((v,E)=>({row:v,id:d(v),rowIndex:E,pinned:"top"})),y=o.map((v,E)=>({row:v,id:d(v),rowIndex:m+g.length+E,pinned:"bottom"})),p=Math.max(0,a),f=Math.min(g.length,u+1),h=g.slice(p,f).map((v,E)=>({row:v,id:d(v),rowIndex:m+p+E})),x=[...w,...h,...y],b=new Set;return x.filter(v=>b.has(v.id)?!1:(b.add(v.id),!0))},[t,n,o,r,i,l,d])}const Fc=100;function Ji(e){const{scrollTop:t,scrollHeight:n,clientHeight:o}=e;return n-t-o>=Fc?null:{visibleTop:t,visibleBottom:t+o,viewportHeight:o}}function Oc(e){return e<.5?3:e<3?5:e<15?12:e<40?20:30}function Dc(e){const{onRowsScrollEnd:t,overscanRowCount:n=3,rowCount:o=0,autoHeight:r=!1}=e,i=s.useRef({scrollTop:0,scrollLeft:0,velocity:0}),l=s.useRef({scrollTop:0,scrollLeft:0,time:0}),d=s.useRef(null),a=s.useRef(null),u=s.useRef(null),g=s.useRef(!0),m=s.useRef(t),[w,y]=s.useState({scrollTop:0,scrollLeft:0,velocityOverscan:0});s.useEffect(()=>{m.current=t},[t]),s.useEffect(()=>()=>{d.current!==null&&cancelAnimationFrame(d.current),a.current!==null&&clearTimeout(a.current)},[]);const p=s.useCallback(x=>{const b=Ji(x);if(!b){g.current=!0;return}if(!g.current)return;const v=m.current;v&&(g.current=!1,v(b))},[]),f=s.useCallback(x=>{const b=x.currentTarget,v=performance.now(),E=Math.abs(b.scrollTop-l.current.scrollTop)+Math.abs(b.scrollLeft-l.current.scrollLeft),k=v-l.current.time,N=k>0?E/k:0,M=b.scrollTop!==l.current.scrollTop;l.current={scrollTop:b.scrollTop,scrollLeft:b.scrollLeft,time:v},i.current={scrollTop:b.scrollTop,scrollLeft:b.scrollLeft,velocity:N},d.current!==null&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{d.current=null;const{scrollTop:S,scrollLeft:D,velocity:I}=i.current;y({scrollTop:S,scrollLeft:D,velocityOverscan:Oc(I)})}),a.current!==null&&clearTimeout(a.current),a.current=setTimeout(()=>{a.current=null,y(S=>S.velocityOverscan===0?S:{...S,velocityOverscan:0})},200),M&&p(b)},[p]);s.useEffect(()=>{g.current=!0;const x=u.current;!x||r||o<=0||x.clientHeight===0||p(x)},[o,r,p]);const h=s.useCallback(x=>{if(u.current=x,!x)return;const{scrollTop:b,scrollLeft:v}=i.current;if(b===0&&v===0)return;x.scrollTop=b,x.scrollLeft=v;const E={scrollTop:x.scrollTop,scrollLeft:x.scrollLeft};(E.scrollTop!==b||E.scrollLeft!==v)&&(i.current={...i.current,...E},l.current={...l.current,...E},y(k=>({...k,...E})))},[]);return{scrollTop:w.scrollTop,scrollLeft:w.scrollLeft,overscanRows:Math.max(w.velocityOverscan,n),handleScroll:f,attachViewport:h}}function $c(e){const t=s.useRef(null);return s.useCallback(n=>{if(t.current?.disconnect(),t.current=null,!n||typeof ResizeObserver>"u")return;const o=new ResizeObserver(r=>{for(const i of r){const{width:l,height:d}=i.contentRect;e(l,d)}});o.observe(n),t.current=o},[e])}function Gc(e){const{setDimensions:t,viewportRef:n,...o}=e,{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:d,attachViewport:a}=Dc(o),u=$c(t),g=s.useCallback(m=>{n.current=m,u(m),a(m)},[n,u,a]);return{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:d,setViewportElement:g}}function Hc(){const[e,t]=s.useState(()=>new Map),n=s.useCallback((o,r)=>{t(i=>{if(i.get(o)===r)return i;const l=new Map(i);return l.set(o,r),l})},[]);return{detailPanelHeights:e,reportDetailPanelHeight:n}}function Bc(e){const{hasDetailPanel:t,controlledExpandedRowIds:n,onDetailPanelExpandedRowIdsChange:o,rowMetaMap:r}=e,[i,l]=s.useState(new Set),d=n??i,a=s.useMemo(()=>_a(d,r),[d,r]),u=s.useCallback(w=>{if(r.get(w)?.isGroupRow)return;const y=new Set(d);y.has(w)?y.delete(w):y.add(w),n===void 0&&l(y),o?.(y)},[d,r,n,o]),{detailPanelHeights:g,reportDetailPanelHeight:m}=Hc();return{hasDetailPanel:t,expandedRowIds:a,handleDetailPanelToggle:u,detailPanelHeights:g,reportDetailPanelHeight:m}}const Wc=new Set(["__group__"]),wn=e=>!Wc.has(e);function Zi(e){return Object.keys(e).every(wn)?e:Object.fromEntries(Object.entries(e).filter(([n])=>wn(n)))}function Vc(e){const t={...e};return e.left&&(t.left=e.left.filter(wn)),e.right&&(t.right=e.right.filter(wn)),t}function zc(e){const{onStateChange:t,sortModel:n,filterModel:o,effectivePaginationModel:r,columnWidths:i,effectiveColumnOrder:l,columnVisibilityModel:d,pinnedColumns:a,density:u}=e,g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t});const m=s.useRef(null);s.useEffect(()=>{if(!g.current)return;const w={sorting:{sortModel:n},filter:{filterModel:o},pagination:{paginationModel:r},columns:{columnWidths:Zi(i),columnOrder:l.filter(wn),columnVisibilityModel:Zi(d),pinnedColumns:Vc(a)},density:{density:u}},y=JSON.stringify(w);y!==m.current&&(m.current=y,g.current(w))},[n,o,r,i,l,d,a,u])}const Kc=200,jc=2e3,Uc=178e5;function Rc(e){const{paginationRequested:t,isRowGrouping:n,autoHeight:o,viewportHeight:r,renderedRowCount:i,totalRowCount:l,pinnedRowsIgnored:d=!1,scrollHeight:a=0,listViewWithoutColumn:u=!1,listViewRowCount:g=0}=e,m=s.useRef(!1),w=s.useRef(!1),y=s.useRef(!1),p=s.useRef(!1),f=s.useRef(!1),h=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||h.current||g<=jc||(h.current=!0,console.warn(`[OpenGridX] The list view is rendering all ${g} items: it does not virtualize. Above a few thousand items use \`pagination\`, server-side loading, or the grid view. See docs/features/list-view.md.`))},[g]),s.useEffect(()=>{process.env.NODE_ENV==="production"||f.current||!u||(f.current=!0,console.warn("[OpenGridX] `listView` is set without a `listViewColumn`, so the grid view is shown instead. Pass `listViewColumn` to render list items. See docs/features/list-view.md."))},[u]),s.useEffect(()=>{process.env.NODE_ENV==="production"||y.current||!d||(y.current=!0,console.warn("[OpenGridX] `pinnedRows` is ignored while treeData or rowGroupingModel is active: the rows stay in their place in the hierarchy. See docs/features/pinning.md."))},[d]),s.useEffect(()=>{process.env.NODE_ENV==="production"||p.current||a<=Uc||(p.current=!0,console.warn(`[OpenGridX] The grid content is ${Math.round(a)}px tall. Browsers cap element heights (about 17.9M px in Firefox, 33.5M px in Chrome and Safari), so the last rows may not be reachable by scrolling. Use pagination, server-side or infinite loading, or a smaller rowHeight. See docs/features/virtualization.md.`))},[a]),s.useEffect(()=>{process.env.NODE_ENV==="production"||m.current||t&&n&&(m.current=!0,console.warn("[OpenGridX] `pagination` is ignored while `rowGroupingModel` is active — all group rows render in one scrollable view. Give the grid a bounded height so it virtualizes. See docs/features/tree-data-grouping.md."))},[t,n]),s.useEffect(()=>{process.env.NODE_ENV==="production"||w.current||o||r>0&&l>Kc&&i>=l&&r>=a&&(w.current=!0,console.warn(`[OpenGridX] The grid viewport is ${Math.round(r)}px tall and is rendering all ${l} rows, so row virtualization is effectively off: the grid fills its container, and the container grows to fit every row. Give the container a definite height (for example \`height: 600px\` or \`100vh\`). If the container, or any ancestor up to the sized one, is a flex or grid item, add \`min-height: 0\` to it. Alternatively pass a \`height\` prop, or \`autoHeight\` if rendering every row is intended. See docs/features/virtualization.md.`))},[o,r,i,l,a])}function qc(e){return typeof window>"u"||typeof window.getComputedStyle!="function"||typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent)?!1:window.getComputedStyle(e).display!=="flex"}let Qi=!1;function Xc(e){s.useEffect(()=>{if(process.env.NODE_ENV==="production"||Qi)return;const t=e.current;!t||!qc(t)||(Qi=!0,console.warn("[OpenGridX] The grid stylesheet is not loaded, so the grid is unstyled and renders every row (its viewport does not scroll). Add `import '@opencorestack/opengridx/styles'` once in your app root. See README.md, Getting Started."))},[e])}function Xn(e,t,n,o){if(n&&o)return t.length>0?[t[t.length-1]]:Array.from(e);const r=new Set(e);return t.forEach(i=>n?r.add(i):r.delete(i)),Array.from(r)}function Yc(e,t,n){return n?e.has(t)?[]:[t]:Xn(e,[t],!e.has(t),!1)}function el(e,t){return t.length===e.size&&t.every(n=>e.has(n))}function Jc(e){const{selectedRowIds:t,onSelectionModelChange:n,disableMultipleRowSelection:o,selectableRowIds:r}=e,i=s.useCallback(m=>{el(t,m)||n(m)},[t,n]),l=s.useCallback((m,w)=>{i(Xn(t,[m],w,o))},[i,t,o]),d=s.useCallback(m=>{i(Yc(t,m,o))},[i,t,o]),a=s.useCallback(m=>{i(Xn(t,r,m,!1))},[i,t,r]),{allSelected:u,someSelected:g}=s.useMemo(()=>{let m=0;for(const y of r)t.has(y)&&m++;const w=r.length>0&&m===r.length;return{allSelected:w,someSelected:!w&&m>0}},[r,t]);return{toggleRow:l,clickRow:d,selectAll:o?void 0:a,allSelected:u,someSelected:g}}function Zc(e){const{dataRows:t,getRowId:n,isPivotActive:o,selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,disableRowSelectionOnClick:d,isHierarchyEnabled:a,rowMetaMap:u,activeHierarchyHandlers:g,onRowClick:m}=e,w=s.useMemo(()=>{const b=t.map(n);return o?b.filter(v=>v!==Kt):b},[t,n,o]),y=Jc({selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,selectableRowIds:w}),{clickRow:p,toggleRow:f}=y,h=s.useCallback(b=>{const{id:v}=b,E=a?u.get(v):void 0;if(E?.isGroupRow){E.hasChildren&&g?.toggleExpansion(v);return}m?.(b),!d&&!qe(v,u)&&p(v)},[a,g,m,u,d,p]),x=s.useCallback((b,v)=>{qe(b,u)||f(b,v)},[u,f]);return{rowSelection:y,handleRowClick:h,handleSelectionChange:x}}const tl=e=>JSON.stringify(Array.from(e,t=>typeof t=="number"?["n",t]:["s",t]));function Qc(e){const{selectedRowIds:t,rowsLookup:n,rowMetaMap:o,enabled:r,onSelectionModelChange:i}=e,l=s.useMemo(()=>{if(!r||t.size===0)return t;let u=!1;const g=new Set;for(const m of t)n.has(m)||o.has(m)?g.add(m):u=!0;return u?g:t},[r,t,n,o]),d=s.useRef(i);s.useLayoutEffect(()=>{d.current=i});const a=s.useRef(null);return s.useEffect(()=>{if(l===t){a.current=null;return}const u=`${tl(t)}|${tl(l)}`;a.current!==u&&(a.current=u,d.current(Array.from(l)))},[l,t]),l}function nr(e,t,n,o){return o?za(e,t,n):n?[{field:t,sort:n}]:e.filter(r=>r.field!==t)}function ed(e){const{sortModel:t,onSortModelChange:n}=e,o=s.useCallback((i,l)=>{n(nr(t,i,l,!1))},[t,n]),r=s.useCallback((i,l)=>{n(nr(t,i,l,!0))},[t,n]);return{handleSort:o,handleSortAdd:r}}function td(e){const{columnVisibilityModel:t,onColumnVisibilityModelChange:n,pinnedColumns:o,onPinnedColumnsChange:r}=e,i=s.useRef({columnVisibilityModel:t,pinnedColumns:o});s.useLayoutEffect(()=>{i.current={columnVisibilityModel:t,pinnedColumns:o}});const l=s.useCallback(a=>{const u={...i.current.columnVisibilityModel,[a]:!1};i.current={...i.current,columnVisibilityModel:u},n(u)},[n]),d=s.useCallback((a,u)=>{const g=xa(i.current.pinnedColumns,a,u);i.current={...i.current,pinnedColumns:g},r(g)},[r]);return{handleHideColumn:l,handlePinColumn:d}}function nd(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=t.current,r=()=>n.current;o.getSortModel=()=>r().sortModel,o.sortColumn=(a,u)=>{const{sortModel:g,multiSort:m,onSortModelChange:w}=r(),y=nr(g,a,u,m);n.current={...r(),sortModel:y},w(y)},o.getFilterModel=()=>r().filterModel,o.setFilterModel=a=>{n.current={...r(),filterModel:a},r().onFilterModelChange(a)};const i=a=>{n.current={...r(),paginationModel:a},r().onPaginationModelChange(a)};o.setPage=a=>i({...r().paginationModel,page:a}),o.setPageSize=a=>i({...r().paginationModel,pageSize:a,page:0});const l=()=>{const a=r().getPendingRowSelectionModel?.();return a?new Set(a):r().selectedRowIds},d=(a,u)=>{const{disableMultipleRowSelection:g,onRowSelectionModelChange:m,isSyntheticRowId:w}=r(),y=w?a.filter(h=>!w(h)):a;if(y.length===0)return;const p=l(),f=Xn(p,y,u,g);el(p,f)||(n.current={...r(),selectedRowIds:new Set(f)},m(f))};o.getSelectedRows=()=>Array.from(l()),o.selectRow=(a,u=!0)=>d([a],u),o.selectRows=(a,u=!0)=>d(a,u),o.getVisibleRows=()=>r().getVisibleRows(),o.getAllFilteredRows=()=>r().getAllFilteredRows(),o.getVisibleColumns=()=>r().visibleColumns,o.setSortModel=a=>{n.current={...r(),sortModel:a},r().onSortModelChange(a)},o.setRowGroupingModel=a=>{n.current={...r(),rowGroupingModel:a},r().onRowGroupingModelChange(a)},o.setAggregationModel=a=>{n.current={...r(),aggregationModel:a},r().onAggregationModelChange(a)},o.setColumnVisibilityModel=a=>{n.current={...r(),columnVisibilityModel:a},r().onColumnVisibilityModelChange(a)},o.setPivotModel=a=>{n.current={...r(),pivotModel:a},r().onPivotModelChange(a)},o.getGridAiState=()=>{const{filterModel:a,sortModel:u,rowGroupingModel:g,aggregationModel:m,pivotModel:w,columnVisibilityModel:y}=r();return{filterModel:a,sortModel:u,rowGroupingModel:g,aggregationModel:m,pivotModel:w,columnVisibilityModel:y}}},[t])}const nl="\0";function od(e,t){const n=e.filter(o=>t[o.field]===!1).map(o=>o.field).join(nl);return s.useMemo(()=>{const o={};if(n)for(const r of n.split(nl))o[r]=!1;return jo(e,o)},[e,n])}function rd({paginationModel:e,currentPage:t,enabled:n,onPaginationModelChange:o}){const r=s.useRef({paginationModel:e,onPaginationModelChange:o});s.useLayoutEffect(()=>{r.current={paginationModel:e,onPaginationModelChange:o}});const i=e.page,l=s.useRef(null);s.useEffect(()=>{if(!n)return;if(t===i){l.current=null;return}const d=`${i}>${t}`;if(l.current===d)return;l.current=d;const{paginationModel:a,onPaginationModelChange:u}=r.current;u({...a,page:t})},[n,t,i])}function id(){const[e,t]=s.useState(!1),[n,o]=s.useState(!1),r=s.useRef(null),i=s.useRef(0),[l,d]=s.useState(0),[a,u]=s.useState(!1),g=s.useMemo(()=>({registerColumnsPanel:()=>(i.current+=1,()=>{i.current-=1}),registerFiltersPanel:()=>(d(h=>h+1),()=>d(h=>h-1))}),[]),m=s.useCallback(()=>u(!0),[]),w=s.useCallback(()=>u(!1),[]),y=s.useCallback(()=>{i.current>0?t(!0):o(!0)},[]),p=s.useCallback(()=>t(!1),[]),f=s.useCallback(()=>o(!1),[]);return s.useEffect(()=>{if(!n)return;function h(b){r.current&&!r.current.contains(b.target)&&o(!1)}function x(b){b.key==="Escape"&&o(!1)}return document.addEventListener("mousedown",h),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",x)}},[n]),{toolbarHost:g,toolbarPanelRequested:e,closeToolbarPanel:p,standalonePanelOpen:n,closeStandalonePanel:f,standalonePanelRef:r,openColumnsPanel:y,toolbarFiltersRequested:a,closeToolbarFiltersPanel:w,openFiltersPanel:l>0?m:void 0}}const ol=s.createContext(null);function ld(e){if(typeof e!="function")return!1;const t=e.prototype;return!(typeof t=="object"&&t!==null&&"isReactComponent"in t)}function sd({render:e,toolbarProps:t}){"use no memo";return c.jsx(c.Fragment,{children:e(t)})}function ad({component:e,toolbarProps:t}){if(ld(e))return c.jsx(sd,{render:e,toolbarProps:t},`fn:${e.toString()}`);const n=e;return c.jsx(n,{...t})}const rl=48;function cd({columns:e,aggregationModel:t,aggregationResult:n,columnWidths:o,rowHeight:r,checkboxSelection:i,hasDetailPanel:l,rowReordering:d,pinCheckboxColumn:a=!0,pinExpandColumn:u=!0,pinnedColumns:g,loading:m=!1}){const w=s.useMemo(()=>Eo(e,o,g,i,a,l,u,d),[e,o,g,i,a,l,u,d]),{lastLeft:y,firstRight:p}=s.useMemo(()=>Mo(e,g),[e,g]),f=d?rl:0,h=f+(l&&u?rl:0),x=(b,v,E)=>c.jsx("div",{className:`ogx__aggregation-spacer${v?" ogx__aggregation-spacer--pinned":""}`,style:v?{left:E}:void 0,"aria-hidden":"true"},b);return c.jsxs("div",{className:`ogx__aggregation-footer${m?" ogx__aggregation-footer--loading":""}`,role:"row","aria-label":"Aggregation totals","aria-live":"polite","aria-busy":m||void 0,style:{minHeight:`${r}px`},children:[d&&x("__reorder_col__",!0,0),l&&x("__expand_col__",u,f),i&&x("__checkbox_col__",a,h),e.map(b=>{if(b.isSpacer){const A=typeof b.width=="number"?b.width:0;return c.jsx("div",{style:{width:A,minWidth:A,flexShrink:0},"aria-hidden":"true"},b.field)}const v=t[b.field],E=v&&Do(b,v)?v:void 0,k=n[b.field],N=Nt(b,o,120),M=ct(b.field,g),S=M?w[b.field]:void 0,D=["ogx__aggregation-cell",M==="left"&&"ogx__aggregation-cell--pinned-left",M==="right"&&"ogx__aggregation-cell--pinned-right",M==="left"&&b.field===y&&"ogx__aggregation-cell--pinned-left-last",M==="right"&&b.field===p&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),I={width:N,minWidth:N,maxWidth:N,textAlign:b.align||"left"};return M==="left"&&S!==void 0&&(I.left=S),M==="right"&&S!==void 0&&(I.right=S),c.jsx("div",{className:D,role:"gridcell",style:I,children:E?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"ogx__aggregation-label",children:E}),c.jsx("span",{className:"ogx__aggregation-value",children:Bn(k,E,b,n)})]}):null},b.field)})]})}function dd({noRowsLabel:e,width:t,overlay:n}){return n?c.jsx("div",{className:"ogx__empty",style:{width:t},children:n}):c.jsxs("div",{className:"ogx__empty",style:{width:t},children:[c.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),c.jsx("path",{d:"M3 9h18M9 21V9"})]}),c.jsx("span",{children:e})]})}function il({dataSource:e,paginationMode:t,sortingMode:n,filterMode:o}){return!!e&&(t==="server"||t==="infinite"||n==="server"||o==="server")}const ll=Number.MAX_SAFE_INTEGER,ud="An unexpected error occurred while loading the data.";function sl(e){return typeof e=="string"&&e?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"&&e.message?e.message:ud}function fd({error:e,onRetry:t}){if(!e)return null;const n=sl(e);return c.jsxs("div",{className:"ogx-error-overlay","aria-live":"assertive",role:"alert",children:[c.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 24 24",fill:"none",stroke:"var(--ogx-color-error)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),c.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),c.jsx("div",{className:"ogx-error-overlay__title",children:"Oops! Something went wrong"}),c.jsx("div",{className:"ogx-error-overlay__message",children:n}),t&&c.jsx("button",{type:"button",onClick:t,className:"ogx-button ogx-button--primary",children:"Retry"})]})}function al(e,t){typeof e=="function"?e(t):e&&(e.current=t)}const bt=s.forwardRef(function({indeterminate:t=!1,label:n,className:o="",inputClassName:r="",inputRef:i,...l},d){const a=s.useRef(null),u=s.useCallback(m=>{a.current=m,al(i,m),al(d,m)},[i,d]);s.useEffect(()=>{a.current&&(a.current.indeterminate=t)},[t]);const g=["ogx-checkbox-wrapper",l.disabled&&"ogx-checkbox-wrapper--disabled",o].filter(Boolean).join(" ");return c.jsxs("label",{className:g,children:[c.jsx("input",{ref:u,type:"checkbox",className:["ogx-checkbox__input",r].filter(Boolean).join(" "),...l}),c.jsxs("span",{className:"ogx-checkbox__box",children:[l.checked&&!t&&c.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),t&&c.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{d:"M19 13H5v-2h14v2z"})})]}),n&&c.jsx("span",{className:"ogx-checkbox__label",children:n})]})});bt.displayName="Checkbox";const cl=50;function or(e,t,n,o){const r=Math.min(n??cl,t),i=Math.max(o??1/0,t);return Math.max(r,Math.min(i,e))}const gd=16;function pd(e){e.preventDefault(),e.stopPropagation()}function hd(){const e=t=>{t.stopPropagation(),t.preventDefault()};window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}),0)}function md(e){const{field:t,currentWidth:n,onResize:o,onAutosize:r,minWidth:i,maxWidth:l,edge:d="end"}=e,[a,u]=s.useState(!1),g=s.useRef(null);s.useEffect(()=>()=>{g.current=null},[]);const m=s.useCallback((b,v)=>{const E=v-b.startX,k=b.startWidth+(d==="start"?-E:E);return or(k,b.startWidth,i,l)},[d,i,l]),w=s.useCallback(b=>{if(b.button===0){b.stopPropagation(),g.current={pointerId:b.pointerId,startX:b.clientX,startWidth:n,lastUpdate:0,moved:!1},u(!0);try{b.currentTarget.setPointerCapture(b.pointerId)}catch{}}},[n]),y=s.useCallback(b=>{const v=g.current;if(!v||b.pointerId!==v.pointerId||(b.clientX!==v.startX&&(v.moved=!0),!v.moved))return;const E=Date.now();E-v.lastUpdate>=gd&&(v.lastUpdate=E,o(t,m(v,b.clientX)))},[t,o,m]),p=s.useCallback((b,v)=>{const E=g.current;!E||b.pointerId!==E.pointerId||(g.current=null,u(!1),(E.moved||b.clientX!==E.startX)&&(hd(),v&&o(t,m(E,b.clientX))))},[t,o,m]),f=s.useCallback(b=>{if(b.key==="Enter"&&r){b.preventDefault(),b.stopPropagation(),r(t);return}if(b.key!=="ArrowLeft"&&b.key!=="ArrowRight")return;b.preventDefault(),b.stopPropagation();const v=(b.shiftKey?50:10)*(b.key==="ArrowRight"?1:-1);o(t,or(n+v,n,i,l))},[t,n,o,r,i,l]),h=s.useCallback(b=>{b.preventDefault(),b.stopPropagation(),r?.(t)},[t,r]),x=["ogx-column-resize-handle",d==="start"&&"ogx-column-resize-handle--start",a&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return c.jsx("div",{className:x,onPointerDown:w,onMouseDown:pd,onPointerMove:y,onPointerUp:b=>p(b,!0),onPointerCancel:b=>p(b,!1),onClick:b=>b.stopPropagation(),onDragStart:b=>{b.preventDefault(),b.stopPropagation()},onDoubleClick:h,onKeyDown:f,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,"aria-valuenow":Math.round(n),"aria-valuemin":Math.round(Math.min(i??50,n)),"aria-valuemax":l,tabIndex:-1,children:c.jsx("div",{className:"ogx-column-resize-handle__line"})})}function dl(e){if(!e)return 0;let t=0;const n=(o,r)=>{t=Math.max(t,r);for(const i of o.children)typeof i!="string"&&n(i,r+1)};return e.forEach(o=>n(o,1)),t}function ul(e){const t=new Map;if(!e)return t;const n=(o,r)=>{const i=[...r,o];for(const l of o.children)typeof l=="string"?t.has(l)||t.set(l,i):n(l,i)};return e.forEach(o=>n(o,[])),t}function rr(e,t,n){if(!e||e.length===0)return!0;const o=ul(e),r=o.get(t),i=o.get(n);return(r?.[r.length-1]??null)===(i?.[i.length-1]??null)}function wd(e,t,n){const o=[];let r=0,i=null,l=null;for(const d of e){const a=d.isSpacer?null:t.get(d.field)?.[n]??null;(i===null||l!==a||i.pinned!==d.pinned)&&(i={key:`${a?a.groupId:"filler"}-${n}-${d.field}`,isGroup:a!==null,label:a?.headerName??"",headerClassName:a?.headerClassName,width:0,flexGrow:0,fields:[],firstDataIndex:r,pinned:d.pinned},l=a,o.push(i)),i.width+=d.width,i.flexGrow+=d.flex??0,d.isSpacer||(i.fields.push(d.field),r++)}return o}function Ot(){return document.documentElement.clientWidth||window.innerWidth}function fl(){return document.documentElement.clientHeight||window.innerHeight}function Ut(){return c.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:c.jsx("circle",{cx:"4",cy:"4",r:"4"})})}function Rt(){return c.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:c.jsx("circle",{cx:"4",cy:"4",r:"3"})})}function bd(){return c.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.3"}),c.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),c.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function xd(){return c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),c.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function yd(){return c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function vd(){return c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:c.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Cd(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"}),c.jsx("path",{d:"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"}),c.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function _d(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"4",y1:"2",x2:"4",y2:"22"}),c.jsx("polyline",{points:"11 8 4 12 11 16"}),c.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Sd(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"20",y1:"2",x2:"20",y2:"22"}),c.jsx("polyline",{points:"13 8 20 12 13 16"}),c.jsx("line",{x1:"20",y1:"12",x2:"4",y2:"12"})]})}function kd(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),c.jsx("line",{x1:"4",y1:"4",x2:"4",y2:"20"}),c.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}const gl=e=>e?Array.from(e.querySelectorAll('[role="menuitem"], [role="menuitemradio"]')):[];function Ed({colDef:e,sortModel:t,onSort:n,onHide:o,onPin:r,pinnedColumns:i,onManageColumns:l,onClose:d,anchorEl:a}){const u=s.useRef(null),g=s.useCallback(I=>{I&&(a?.closest('[role="columnheader"]')??a)?.focus({preventScroll:!0}),d()},[a,d]),m=I=>{const A=gl(u.current),C=A.indexOf(I.target);let L=-1;if(I.key==="ArrowDown")L=C+1>=A.length?0:C+1;else if(I.key==="ArrowUp")L=C<=0?A.length-1:C-1;else if(I.key==="Home")L=0;else if(I.key==="End")L=A.length-1;else if(I.key==="Tab"){I.preventDefault(),g(!0);return}else return;I.preventDefault(),A[L]?.focus()},[w,y]=s.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});s.useLayoutEffect(()=>{if(!a||!u.current)return;const I=a.getBoundingClientRect(),A=u.current.getBoundingClientRect(),C=Ot(),L=fl(),F=8;let _=I.left;_+A.width+F>C&&(_=C-A.width-F),_<F&&(_=F);let z=I.bottom+4;z+A.height+F>L&&(z=I.top-A.height-4),y({position:"fixed",zIndex:1300,top:z,left:_,visibility:"visible"})},[a]);const p=w.visibility==="visible";s.useLayoutEffect(()=>{p&&gl(u.current)[0]?.focus({preventScroll:!0})},[p]),s.useEffect(()=>{function I(C){u.current&&!u.current.contains(C.target)&&a&&!a.contains(C.target)&&d()}function A(C){C.key==="Escape"&&g(!0)}return document.addEventListener("mousedown",I),document.addEventListener("keydown",A),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",A),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[a,d,g]);const f=I=>{n?.(e.field,I),g(!0)},h=!!o&&e.hideable!==!1,x=!!r&&e.pinnable!==!1,b=()=>{h&&o?.(e.field),g(!0)},v=I=>{x&&r?.(e.field,I),g(!0)},E=t?.find(I=>I.field===e.field)?.sort,k=E==null,N=i?.left?.includes(e.field)??!1,M=i?.right?.includes(e.field)??!1,S=!N&&!M,D=e.headerName||e.field;return mt.createPortal(c.jsxs("div",{ref:u,className:"ogx-column-menu",style:w,role:"menu","aria-label":`Column options for ${D}`,onKeyDown:m,children:[n&&e.sortable!==!1&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",className:`ogx-menu-item${E==="asc"?" ogx-menu-item--active":""}`,onClick:()=>f("asc"),role:"menuitemradio","aria-checked":E==="asc",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="asc"?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(xd,{})}),"Sort Ascending"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${E==="desc"?" ogx-menu-item--active":""}`,onClick:()=>f("desc"),role:"menuitemradio","aria-checked":E==="desc",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="desc"?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(yd,{})}),"Sort Descending"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${k?" ogx-menu-item--active":""}`,onClick:()=>f(null),role:"menuitemradio","aria-checked":k,children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:k?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(vd,{})}),"Unsort"]}),c.jsx("div",{className:"ogx-menu-divider"})]}),x&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"ogx-menu-section-label","aria-hidden":"true",children:"Pin column"}),c.jsxs("button",{type:"button",className:`ogx-menu-item${N?" ogx-menu-item--active":""}`,onClick:()=>v("left"),role:"menuitemradio","aria-checked":N,"aria-label":"Pin to left",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:N?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(_d,{})}),"Pin to Left"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${M?" ogx-menu-item--active":""}`,onClick:()=>v("right"),role:"menuitemradio","aria-checked":M,"aria-label":"Pin to right",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:M?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Sd,{})}),"Pin to Right"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${S?" ogx-menu-item--active":""}`,onClick:()=>v(null),role:"menuitemradio","aria-checked":S,"aria-label":"Unpin column",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:S?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(kd,{})}),"Unpin"]}),c.jsx("div",{className:"ogx-menu-divider"})]}),h&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:b,role:"menuitem","aria-label":`Hide ${D} column`,children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Cd,{})}),"Hide Column"]}),c.jsx("div",{className:"ogx-menu-divider"})]}),c.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:()=>{l?.(),g(!1)},role:"menuitem","aria-label":"Manage all columns",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(bd,{})}),"Manage columns"]})]}),a?.closest(".ogx-theme-provider")||document.body)}const Md=16,Nd=16;function Id(e,t=!1){const n=Number.isFinite(e)?e-Nd:0,o=Math.floor(n/Md)-(t?1:0);return Math.max(1,o)}function Ld(e,t){return e??t??!1}function pl(e,t,n,o){const r={width:t[e.field]??e.width??100,minWidth:e.minWidth,maxWidth:e.maxWidth,flexGrow:e.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",position:n?"sticky":"relative"};return n==="left"?r.left=o:n==="right"&&(r.right=o),r}const Ad="header:",Pd=40,Td=300,Fd="__group__",hl=[];function ir(e){return`${Ad}${e}`}function lr(e){return"items"in e&&Array.isArray(e.items)}function Od(e){return e.isSpacer||Ze(e.field)||e.field===Fd?!1:e.headerFilter!==!1&&e.filterable!==!1&&e.type!=="image"}function Yn(e){if(e.headerFilterOperator)return e.headerFilterOperator;switch(e.type){case"number":return"=";case"date":case"boolean":case"singleSelect":return"is";default:return"contains"}}function Dd(e){const t=bi(e.type),n=Yn(e);return t.includes(n)?t:[n,...t]}function ml(e,t){return e.items.some(n=>lr(n)?ml(n,t):n.field===t)}function $d(e){return(e?.logicOperator??"and")==="or"&&(e?.items?.length??0)>0}function wl(e,t){const n=e?.items??hl;if($d(e))return{kind:"custom"};const o=ir(t);let r;for(const i of n){if(lr(i)){if(ml(i,t))return{kind:"custom"};continue}if(i.field===t){if(i.id!==o||r)return{kind:"custom"};r=i}}return{kind:"editable",item:r}}function Gd(e,t,n){const o=e??{items:[]};if(wl(o,t).kind!=="editable")return o;const r=ir(t),i=o.items??hl,l=i.findIndex(u=>!lr(u)&&u.id===r),d=n?{...n,id:r,field:t}:null;let a;if(l===-1){if(!d)return o;if(i.length===0&&o.logicOperator==="or")return{...o,logicOperator:"and",items:[d]};a=[...i,d]}else d?a=i.map((u,g)=>g===l?d:u):a=i.filter((u,g)=>g!==l);return{...o,items:a}}function sr(e,t,n){const o=Vt.has(t);return!o&&$o(n)&&t===Yn(e)?null:{id:ir(e.field),field:e.field,operator:t,value:o?void 0:n}}function bl(e,t){if(!Vt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const Hd={contains:"∋",equals:"=",startsWith:"a…",endsWith:"…a",isEmpty:"∅",isNotEmpty:"!∅",isAnyOf:"∈","=":"=","!=":"≠",">":">",">=":"≥","<":"<","<=":"≤",is:"=",not:"≠",after:">",onOrAfter:"≥",before:"<",onOrBefore:"≤"},ar={contains:"Contains",equals:"Equals",startsWith:"Starts with",endsWith:"Ends with",isEmpty:"Is empty",isNotEmpty:"Is not empty",isAnyOf:"Is any of","=":"Equals","!=":"Does not equal",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",is:"Is",not:"Is not",after:"After",onOrAfter:"On or after",before:"Before",onOrBefore:"On or before"},Qe=s.forwardRef(function({fullWidth:t=!1,error:n=!1,startAdornment:o,endAdornment:r,className:i="",inputClassName:l="",variant:d="field",...a},u){const g=["ogx-input-wrapper",d==="cell"&&"ogx-input-wrapper--cell",t&&"ogx-input-wrapper--full-width",n&&"ogx-input-wrapper--error",a.disabled&&"ogx-input-wrapper--disabled",i].filter(Boolean).join(" "),m=["ogx-input",l].filter(Boolean).join(" ");return c.jsxs("div",{className:g,children:[o&&c.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--start",children:o}),c.jsx("input",{ref:u,className:m,"aria-invalid":n?!0:void 0,...a}),r&&c.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--end",children:r})]})});Qe.displayName="Input";const Bd={position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"},xl=e=>e?Array.from(e.querySelectorAll('[role="menuitemradio"]')):[];function Wd({anchorEl:e,columnLabel:t,operators:n,current:o,onSelect:r,onClose:i}){const l=s.useRef(null),[d,a]=s.useState(Bd);s.useLayoutEffect(()=>{const w=l.current;if(!w)return;const y=e.getBoundingClientRect(),p=w.getBoundingClientRect(),f=8;let h=Math.min(y.left,Ot()-p.width-f);h<f&&(h=f);let x=y.bottom+4;x+p.height+f>fl()&&(x=y.top-p.height-4),a({position:"fixed",zIndex:1300,top:x,left:h,visibility:"visible"})},[e]);const u=d.visibility==="visible";s.useLayoutEffect(()=>{if(!u)return;const w=xl(l.current);(w.find(y=>y.getAttribute("aria-checked")==="true")??w[0])?.focus({preventScroll:!0})},[u]);const g=s.useRef(i);s.useLayoutEffect(()=>{g.current=i}),s.useEffect(()=>{const w=e.ownerDocument,y=w.defaultView;function p(x){const b=x.target;l.current?.contains(b)||e.contains(b)||g.current(!1)}function f(x){l.current?.contains(x.target)||g.current(!1)}function h(){g.current(!1)}return w.addEventListener("mousedown",p),y?.addEventListener("scroll",f,!0),y?.addEventListener("resize",h),()=>{w.removeEventListener("mousedown",p),y?.removeEventListener("scroll",f,!0),y?.removeEventListener("resize",h)}},[e]);const m=w=>{w.stopPropagation();const y=xl(l.current),p=y.indexOf(w.target);let f=-1;switch(w.key){case"ArrowDown":f=p+1>=y.length?0:p+1;break;case"ArrowUp":f=p<=0?y.length-1:p-1;break;case"Home":f=0;break;case"End":f=y.length-1;break;case"Escape":case"Tab":w.preventDefault(),i(!0);return;default:return}w.preventDefault(),y[f]?.focus()};return mt.createPortal(c.jsx("div",{ref:l,className:"ogx-column-menu ogx__header-filter-menu",style:d,role:"menu","aria-label":`Filter operator for ${t}`,onKeyDown:m,children:n.map(w=>c.jsx("button",{type:"button",role:"menuitemradio","aria-checked":w===o,tabIndex:-1,className:`ogx-menu-item${w===o?" ogx-menu-item--active":""}`,onClick:()=>r(w),children:ar[w]??w},w))}),e.closest(".ogx-theme-provider")??e.ownerDocument.body)}function Vd(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function zd(e,t){const n=Array.isArray(t)?t[0]:t;return Object.is(e.value,n)?!0:n!=null&&String(e.value).toLowerCase()===String(n).toLowerCase()}function yl(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function vl(e,t){return Object.is(e,t)?!0:Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>vl(n,t[o])):!1}function Cl(e,t){return e===t?!0:!e||!t?!1:e.operator===t.operator&&vl(e.value,t.value)}function Kd(){return c.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"})]})}function jd({colDef:e,state:t,style:n,className:o,ariaColIndex:r,onItemChange:i,onOpenFilterPanel:l}){const d=e.headerName||e.field,a=t.kind==="editable"?t.item:void 0,u=a?.operator??Yn(e),g=Vd(e),m=e.type==="boolean"||e.type==="singleSelect"&&g.length>0,w=!Vt.has(u),[y,p]=s.useState(null),[f,h]=s.useState(null),[x,b]=s.useState(void 0),[v,E]=s.useState(a);if(v!==a){E(a);const R=x!==void 0&&Cl(x??void 0,a);!Cl(v,a)&&!R&&p(null)}const k=s.useRef(null),N=s.useRef(null),M=s.useRef(null),S=s.useRef(null),D=s.useRef(null),I=s.useRef({item:a,colDef:e,onItemChange:i});s.useLayoutEffect(()=>{I.current={item:a,colDef:e,onItemChange:i}});const A=s.useCallback(R=>{const{item:te,colDef:ce,onItemChange:W}=I.current;if(te?R===Bo(te.value,ce.type):R.trim()==="")return;const V=te?.operator??Yn(ce),J=sr(ce,V,yl(R,V));b(J),W(ce.field,J)},[]),C=s.useRef(null);s.useLayoutEffect(()=>{C.current=y}),s.useEffect(()=>()=>{const R=C.current;C.current=null,R!==null&&A(R)},[A]),s.useEffect(()=>{if(y===null)return;const R=setTimeout(()=>{C.current=null,A(y),p(null)},Td);return()=>clearTimeout(R)},[y,A]);const L=()=>k.current?.focus({preventScroll:!0}),F=()=>(N.current??M.current)?.focus({preventScroll:!0}),_=R=>{b(R),i(e.field,R)},z=R=>{p(null),_(sr(e,u,R))},K=()=>{p(null),_(null)},Q=()=>{D.current&&h(D.current)},G=R=>{h(null),R&&(N.current||M.current?F():L())},j=R=>{const te=y!==null?yl(y,R):a?.value;p(null),h(null),_(sr(e,R,bl(te,R))),requestAnimationFrame(()=>{N.current||M.current?F():L()})},H=t.kind==="custom",ie=!H&&w&&!m,re=R=>{const te=R.currentTarget,ce=R.target;if(!te.contains(ce)||R.nativeEvent.isComposing)return;const{key:W}=R,le=ce===te;if((R.altKey&&W==="ArrowDown"||(R.ctrlKey||R.metaKey)&&W==="Enter")&&!H&&ce!==M.current){R.preventDefault(),R.stopPropagation(),Q();return}if(!le){W==="Escape"&&(R.preventDefault(),R.stopPropagation(),L());return}if(W==="Enter"||W===" "||W==="Spacebar"){R.preventDefault(),R.stopPropagation(),H?S.current?.click():N.current||M.current?F():Q();return}if((W==="Delete"||W==="Backspace")&&a){R.preventDefault(),R.stopPropagation(),K();return}ie&&e.type!=="date"&&W.length===1&&!R.ctrlKey&&!R.metaKey&&!R.altKey&&(R.preventDefault(),R.stopPropagation(),N.current?.focus({preventScroll:!0}),p(W))};let ue=null;if(H)ue=l?c.jsx("button",{ref:S,type:"button",className:"ogx__header-filter-custom",tabIndex:-1,onClick:l,title:"Set in the filter panel",children:"Custom filter"}):c.jsx("span",{className:"ogx__header-filter-custom",title:"Set in the filter panel",children:"Custom filter"});else{let R;if(!w)R=c.jsx("span",{className:"ogx__header-filter-operator-label",children:ar[u]??u});else if(e.type==="boolean")R=c.jsxs("select",{ref:M,className:"ogx__header-filter-select",tabIndex:-1,value:a?.value==null||a.value===""?"":String(a.value),onChange:ce=>z(ce.target.value===""?"":ce.target.value==="true"),"aria-label":`Filter value for ${d}`,children:[c.jsx("option",{value:"",children:"Any"}),c.jsx("option",{value:"true",children:"Yes"}),c.jsx("option",{value:"false",children:"No"})]});else if(m){const ce=g.find(W=>zd(W,a?.value));R=c.jsxs("select",{ref:M,className:"ogx__header-filter-select",tabIndex:-1,value:ce?.key??"",onChange:W=>{const le=g.find(V=>V.key===W.target.value);z(bl(le?le.value:"",u))},"aria-label":`Filter value for ${d}`,children:[c.jsx("option",{value:"",children:"Any"}),g.map(W=>c.jsx("option",{value:W.key,children:W.label},W.key))]})}else R=c.jsx(Qe,{ref:N,className:"ogx__header-filter-input-wrapper",inputClassName:"ogx__header-filter-input",type:e.type==="date"?"date":"text",inputMode:e.type==="number"?"decimal":void 0,tabIndex:-1,autoComplete:"off",value:y??Bo(a?.value,e.type),onChange:ce=>p(ce.target.value),"aria-label":`Filter value for ${d}`});const te=ar[u]??u;ue=c.jsxs(c.Fragment,{children:[c.jsx("button",{ref:D,type:"button",className:`ogx__header-filter-operator${f?" ogx__header-filter-operator--open":""}`,tabIndex:-1,"aria-haspopup":"menu","aria-expanded":f!==null,"aria-label":`Filter operator for ${d}: ${te}`,title:te,onClick:()=>f?h(null):Q(),children:Hd[u]??"?"}),R,a&&c.jsx("button",{type:"button",className:"ogx__header-filter-clear",tabIndex:-1,"aria-label":`Clear filter for ${d}`,title:"Clear",onClick:()=>{K(),L()},children:c.jsx(Kd,{})}),f&&c.jsx(Wd,{anchorEl:f,columnLabel:d,operators:Dd(e),current:u,onSelect:j,onClose:G})]})}const ae=["ogx__header-filter-cell",a&&"ogx__header-filter-cell--active",H&&"ogx__header-filter-cell--custom",o].filter(Boolean).join(" ");return c.jsx("div",{ref:k,className:ae,style:n,role:"columnheader","aria-label":`Filter ${d}`,"aria-colindex":r,"data-field":e.field,tabIndex:-1,onKeyDown:re,children:ue})}function cr({field:e,ariaColIndex:t,sticky:n,left:o,focused:r}){return c.jsx("div",{className:["ogx__header-filter-cell","ogx__header-filter-cell--system",n&&"ogx__header-filter-cell--pinned ogx__header-filter-cell--pinned-left",r&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" "),style:{width:He,minWidth:He,maxWidth:He,position:n?"sticky":void 0,left:n?o:void 0},role:"columnheader","aria-colindex":t,"data-field":e,tabIndex:-1})}function Ud(e){const{columns:t,columnWidths:n,pinnedColumns:o,pinnedPositions:r,pinnedEdges:i,rowReordering:l,hasDetailPanel:d,checkboxSelection:a,pinExpandColumn:u,pinCheckboxColumn:g,columnIndexMap:m,ariaRowIndex:w,filterModel:y,onFilterModelChange:p,onOpenFilterPanel:f,focusedField:h}=e,x=s.useRef({filterModel:y,onFilterModelChange:p});s.useLayoutEffect(()=>{x.current={filterModel:y,onFilterModelChange:p}});const b=s.useCallback((D,I)=>{const{filterModel:A,onFilterModelChange:C}=x.current;if(!C)return;const L=Gd(A,D,I);L!==A&&(x.current={filterModel:L,onFilterModelChange:C},C(L))},[]),v=l?1:0,E=d?v+1:v,k=a?E+1:E,N=k,M=l?He:0,S=M+(d&&u?He:0);return c.jsxs("div",{className:"ogx__header-filter-row",role:"row","aria-rowindex":w,children:[l&&c.jsx(cr,{field:At,ariaColIndex:v,sticky:!0,left:0,focused:h===At}),d&&c.jsx(cr,{field:Pt,ariaColIndex:E,sticky:u,left:M,focused:h===Pt}),a&&c.jsx(cr,{field:Je,ariaColIndex:k,sticky:g,left:S,focused:h===Je}),t.map((D,I)=>{if(D.isSpacer)return c.jsx("div",{style:{width:D.width,minWidth:D.width,flexShrink:0},"aria-hidden":"true"},D.field);const A=ct(D.field,o),C=pl(D,n,A,A?r[D.field]:void 0),L=N+(m?.get(D.field)??I)+1,F=[A&&"ogx__header-filter-cell--pinned",A&&`ogx__header-filter-cell--pinned-${A}`,A==="left"&&D.field===i.lastLeft&&"ogx__header-filter-cell--pinned-left-last",A==="right"&&D.field===i.firstRight&&"ogx__header-filter-cell--pinned-right-first",h===D.field&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" ");return Od(D)?c.jsx(jd,{colDef:D,state:wl(y,D.field),style:C,className:F,ariaColIndex:L,onItemChange:b,onOpenFilterPanel:f},D.field):c.jsx("div",{className:`ogx__header-filter-cell ogx__header-filter-cell--empty ${F}`,style:C,role:"columnheader","aria-label":`No filter for ${D.headerName||D.field}`,"aria-colindex":L,"data-field":D.field,tabIndex:-1},D.field)})]})}function Rd(){return c.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"18",height:"18",children:c.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})})}function qd(){return c.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor",children:c.jsx("path",{d:"M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"})})}function _l(e){const{columns:t,allColumns:n,columnGroupingModel:o,checkboxSelection:r=!1,allSelected:i=!1,someSelected:l=!1,onSelectAll:d,onSort:a,sortModel:u=[],onColumnResize:g,onColumnAutosize:m,columnWidths:w={},pinnedColumns:y,hasDetailPanel:p=!1,pinCheckboxColumn:f=!0,pinExpandColumn:h=!0,rowReordering:x=!1,aggregationModel:b,draggedColumn:v,dragOverColumn:E,onDragStart:k,onDragOver:N,onDragEnd:M,onDrop:S,focusedCell:D,onHeaderClick:I,onSortAdd:A,multiSort:C=!1,onHideColumn:L,onPinColumn:F,onManageColumns:_,columnIndexMap:z,wrapHeaderText:K=!1,headerHeight:Q=56,headerFilters:G=!1,filterModel:j,onFilterModelChange:H,onOpenFilterPanel:ie}=e,re=s.useId(),[ue,ae]=s.useState(null),R=U=>se=>{se.stopPropagation(),ae({colDef:U,anchorEl:se.currentTarget})},te=s.useCallback(()=>{ae(null)},[]),ce=U=>se=>{if(se.altKey&&(se.key==="ArrowLeft"||se.key==="ArrowRight")&&se.target===se.currentTarget){if(U.resizable===!1||!g)return;se.preventDefault(),se.stopPropagation();const ve=Nt(U,w),be=(se.shiftKey?50:10)*(se.key==="ArrowRight"?1:-1);g(U.field,or(ve+be,ve,U.minWidth,U.maxWidth));return}if(!(se.altKey&&se.key==="ArrowDown"||(se.ctrlKey||se.metaKey)&&se.key==="Enter")||U.disableColumnMenu||se.target!==se.currentTarget)return;se.preventDefault(),se.stopPropagation();const he=se.currentTarget.querySelector(".ogx__menu-icon-btn")??se.currentTarget;ae({colDef:U,anchorEl:he})},W=U=>D?.id===null&&!D.headerFilter&&D.field===U,le=x?1:0,V=p?le+1:le,J=r?V+1:V,ne=U=>se=>{if(U.sortable===!1)return;const we=u.find(he=>he.field===U.field);let pe="asc";we&&(we.sort==="asc"?pe="desc":pe=null),(se.shiftKey||C)&&A?A(U.field,pe):a&&a(U.field,pe)},fe=(U,se)=>{const we=u.some(he=>he.field===U);A&&(se===null||we||C||!a)?A(U,se):a?.(U,se)},Z=U=>{const se=u.find(pe=>pe.field===U);if(!se)return null;const we=u.length>1?u.indexOf(se)+1:null;return c.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${se.sort}`,"aria-hidden":"true",children:we!==null&&c.jsx("span",{className:"ogx__sort-badge",children:we})})},$=s.useMemo(()=>Eo(t,w,y,r,f,p,h,x),[t,w,y,r,f,p,h,x]),O=s.useMemo(()=>Mo(t,y),[t,y]),P=dl(o),T=s.useMemo(()=>ul(o),[o]),X=s.useMemo(()=>P===0?[]:(n??t).map(U=>({field:U.field,width:Nt(U,w),flex:U.isSpacer?0:U.flex,pinned:U.isSpacer?null:ct(U.field,y),isSpacer:U.isSpacer})),[P,n,t,w,y]),Y=(x?48:0)+(p?48:0)+(r?48:0),oe=(x||p||r)&&(!p||h)&&(!r||f),me=(x?1:0)+(p?1:0)+(r?1:0);return c.jsxs("div",{className:"ogx__header-wrap",children:[P>0&&Array.from({length:P},(U,se)=>{const we=wd(X,T,se);return c.jsxs("div",{className:"ogx-col-group-row",role:"row","aria-rowindex":se+1,children:[Y>0&&c.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${oe?" ogx-col-group-cell--pinned ogx-col-group-cell--pinned-left":""}`,style:{width:Y,minWidth:Y,flexShrink:0,position:oe?"sticky":void 0,left:oe?0:void 0},"aria-hidden":"true"}),we.map((pe,he)=>{const ve=pe.pinned?` ogx-col-group-cell--pinned ogx-col-group-cell--pinned-${pe.pinned}`:"",be={width:pe.width,minWidth:pe.width,flexShrink:0,flexGrow:pe.flexGrow};return pe.pinned==="left"?(be.position="sticky",be.left=$[pe.fields[0]]):pe.pinned==="right"&&(be.position="sticky",be.right=$[pe.fields[pe.fields.length-1]],we[he-1]?.pinned!=="right"&&(be.marginLeft="auto")),pe.isGroup?c.jsx("div",{role:"columnheader","aria-colspan":pe.fields.length,"aria-colindex":me+pe.firstDataIndex+1,className:`ogx-col-group-cell ogx-col-group-cell--group${ve}${pe.headerClassName?` ${pe.headerClassName}`:""}`,style:be,title:pe.label,children:c.jsx("span",{className:"ogx-col-group-cell__label",children:pe.label})},pe.key):c.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${ve}`,style:be,"aria-hidden":"true"},pe.key)})]},`ogx-grp-${se}`)}),c.jsxs("div",{className:"ogx__header",role:"row","aria-rowindex":P+1,children:[x&&c.jsx("div",{className:`ogx__header-cell ogx__header-cell--pinned ogx__header-cell--pinned-left ${W("__reorder_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Row reorder handle","aria-colindex":le,"data-field":"__reorder_col__",tabIndex:-1,title:"Drag to reorder rows",style:{minWidth:48,maxWidth:48,position:"sticky",left:0}}),p&&c.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${h?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${W("__expand_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Expand row details","aria-colindex":V,"data-field":"__expand_col__",tabIndex:-1,style:{minWidth:48,maxWidth:48,position:h?"sticky":void 0,left:h?x?48:0:void 0}}),r&&c.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${f?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${W("__checkbox_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-colindex":J,"data-field":"__checkbox_col__",style:{position:f?"sticky":void 0,left:f?(x?48:0)+(p&&h?48:0):void 0},children:d&&c.jsx(bt,{id:re,name:re,checked:i,indeterminate:l,onChange:U=>d(U.target.checked),"aria-label":i?"Deselect all rows":"Select all rows",tabIndex:-1,onMouseDown:U=>U.preventDefault()})}),t.map((U,se)=>{if(U.isSpacer)return c.jsx("div",{style:{width:U.width,minWidth:U.width,flexShrink:0},"aria-hidden":"true"},U.field);const we=U.sortable!==!1,pe=u.findIndex(ot=>ot.field===U.field),he=pe!==-1,ve=he?u[pe].sort:null,be=z?.get(U.field)??se,de=we?pe===0?ve==="asc"?"ascending":"descending":"none":void 0,ye=he&&u.length>1?`Sorted ${ve==="asc"?"ascending":"descending"}, sort priority ${pe+1} of ${u.length}`:void 0,Ee=U.resizable!==!1,Me=ct(U.field,y),Ne=Me!==null,Ie=v===U.field,Se=E===U.field,Oe=Ld(U.wrapHeaderText,K),ge=b?.[U.field],Ce=["ogx__header-cell",`ogx__header-cell--align-${U.headerAlign||U.align||"left"}`,we&&"ogx__header-cell--sortable",he&&"ogx__header-cell--sorted",Ne&&"ogx__header-cell--pinned",Ne&&`ogx__header-cell--pinned-${Me}`,Me==="left"&&U.field===O.lastLeft&&"ogx__header-cell--pinned-left-last",Me==="right"&&U.field===O.firstRight&&"ogx__header-cell--pinned-right-first",Ie&&"ogx__header-cell--dragging",Se&&"ogx__header-cell--drag-over",Oe&&"ogx__header-cell--wrap",W(U.field)&&"ogx__header-cell--focused",U.headerClassName].filter(Boolean).join(" "),ke={...pl(U,w,Me,Me?$[U.field]:void 0),zIndex:U.zIndex,opacity:Ie?.5:1},xe=U.renderHeader?U.renderHeader({field:U.field,colDef:U,colIndex:be}):U.headerName||U.field,je=ot=>{if(ot.target.closest(".ogx-column-resize-handle")){ot.stopPropagation();return}I?.(U.field),we&&ne(U)(ot)},nt=k&&!Ne?k(U.field):void 0,nn=N&&!Ne?N(U.field):void 0,Mn=S&&!Ne?S(U.field):void 0;return c.jsxs("div",{className:Ce,style:ke,title:U.description??(Oe&&typeof xe=="string"?xe:void 0),onClick:je,role:"columnheader",draggable:!!nt,onDragStart:nt,onDragOver:nn,onDragEnd:M,onDrop:Mn,onKeyDown:ce(U),"aria-sort":de,"aria-description":ye,"aria-colindex":me+be+1,"data-field":U.field,tabIndex:-1,children:[c.jsxs("div",{className:"ogx__header-cell-content",children:[Ie&&c.jsx("div",{className:"ogx__header-drag-icon",children:c.jsx(qd,{})}),c.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[c.jsx("span",{className:"ogx__header-cell-title",style:Oe?{WebkitLineClamp:Id(Q,!!ge)}:void 0,children:xe}),ge&&c.jsx("span",{className:"ogx__header-cell-aggregation",children:ge})]}),we&&Z(U.field),!U.disableColumnMenu&&c.jsx("button",{type:"button",className:"ogx__menu-icon-btn",onClick:R(U),"aria-label":`Open column menu for ${U.headerName||U.field}`,"aria-haspopup":"menu",tabIndex:-1,children:c.jsx(Rd,{})})]}),Ee&&g&&c.jsx(md,{field:U.field,currentWidth:Nt(U,w),onResize:g,onAutosize:m,minWidth:U.minWidth,maxWidth:U.maxWidth,edge:Me==="right"?"start":"end"})]},U.field)}),ue&&c.jsx(Ed,{colDef:ue.colDef,sortModel:u,onSort:a||A?fe:void 0,onHide:L,onPin:F,pinnedColumns:y,onManageColumns:_,onClose:te,anchorEl:ue.anchorEl})]}),G&&c.jsx(Ud,{columns:t,columnWidths:w,pinnedColumns:y,pinnedPositions:$,pinnedEdges:O,rowReordering:x,hasDetailPanel:p,checkboxSelection:r,pinExpandColumn:h,pinCheckboxColumn:f,columnIndexMap:z,ariaRowIndex:P+2,filterModel:j,onFilterModelChange:H,onOpenFilterPanel:ie,focusedField:D?.id===null&&D.headerFilter?D.field:null})]})}const Ae=()=>{},dr=()=>Promise.resolve({updated:[],failed:[],skipped:[]});function Sl(){return{getRow:()=>null,getAllRows:()=>[],getVisibleRows:()=>[],getAllFilteredRows:()=>[],getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:()=>null,getAllColumns:()=>[],getVisibleColumns:()=>[],selectRow:Ae,selectRows:Ae,getSelectedRows:()=>[],sortColumn:Ae,getSortModel:()=>[],setFilterModel:Ae,getFilterModel:()=>({items:[]}),setPage:Ae,setPageSize:Ae,scrollToIndexes:Ae,autosizeColumn:Ae,autosizeColumns:Ae,copySelectedRows:()=>Promise.resolve(),getCellSelectionModel:()=>[],setCellSelectionModel:Ae,selectCellRange:Ae,clearCellSelection:Ae,getSelectedCells:()=>[],copySelectedCells:()=>Promise.resolve(),pasteText:dr,undo:dr,redo:dr,canUndo:()=>!1,canRedo:()=>!1,clearHistory:Ae,setSortModel:Ae,setRowGroupingModel:Ae,setAggregationModel:Ae,setColumnVisibilityModel:Ae,setPivotModel:Ae,getGridAiState:()=>({}),openAiAssistant:Ae,closeAiAssistant:Ae}}const Xd=e=>e.id;let kl=!1;function El(e,t,n){const o=new Map,r=new Map,i=[],l=[];return e.forEach(d=>{const a=n?.get(d)??t(d);if(o.has(a)){l.push(a);return}o.set(a,d),r.set(d,a),i.push(a)}),l.length>0&&!kl&&process.env.NODE_ENV!=="production"&&(kl=!0,console.warn(`[OpenGridX] ${l.length} row(s) reuse the id of an earlier row and were ignored (ids: ${l.slice(0,5).map(String).join(", ")}${l.length>5?", …":""}). Every row needs a unique id; pass getRowId if the unique key lives in another field.`)),{idRowsLookup:o,allRows:i,idByRow:r}}function Yd(e,t,n,o={}){const r=new Map,i=[];return n.forEach(l=>{r.set(l.field,l),i.push(l.field)}),{rows:El(e,t),columns:{all:n,lookup:r,orderedFields:i,columnVisibilityModel:o},pagination:{rowCount:void 0},pinning:{pinnedColumns:{},pinnedRows:{}},dimensions:{rowHeight:52,headerHeight:56,viewportWidth:0,viewportHeight:0},dataSource:{loading:!1,error:null}}}function Jd(e,t){switch(t.type){case"SET_ROWS":{const n=e.rows.allRows.map(r=>e.rows.idRowsLookup.get(r)),o=typeof t.payload=="function"?t.payload(n):t.payload;return{...e,rows:El(o,t.getRowId,e.rows.idByRow)}}case"REPLACE_ROW":{const n=e.rows.idRowsLookup.get(t.id);if(n===void 0)return e;const o=new Map(e.rows.idRowsLookup);o.set(t.id,t.row);const r=new Map(e.rows.idByRow);return r.delete(n),r.set(t.row,t.id),{...e,rows:{...e.rows,idRowsLookup:o,idByRow:r}}}case"REPLACE_ROWS":{let n=!1;const o=new Map(e.rows.idRowsLookup),r=new Map(e.rows.idByRow);for(const[i,l]of t.rows){const d=o.get(i);d!==void 0&&(n=!0,o.set(i,l),r.delete(d),r.set(l,i))}return n?{...e,rows:{...e.rows,idRowsLookup:o,idByRow:r}}:e}case"SET_COLUMNS":{const n=new Map,o=[];return t.payload.forEach(r=>{n.set(r.field,r),o.push(r.field)}),{...e,columns:{all:t.payload,lookup:n,orderedFields:o,columnVisibilityModel:e.columns.columnVisibilityModel}}}case"SET_DIMENSIONS":return{...e,dimensions:{...e.dimensions,viewportWidth:t.payload.viewportWidth,viewportHeight:t.payload.viewportHeight}};case"SET_DATASOURCE_LOADING":return{...e,dataSource:{...e.dataSource,loading:t.payload}};case"SET_DATASOURCE_ERROR":return{...e,dataSource:{...e.dataSource,error:t.payload}};case"SET_ROW_COUNT":return{...e,pagination:{...e.pagination,rowCount:t.payload}};default:return e}}function Zd(e){const{rows:t,columns:n,rowHeight:o=52,headerHeight:r=56,columnVisibilityModel:i,initialState:l,syncRows:d=!1}=e,a=e.getRowId??Xd,u=s.useRef(a);s.useLayoutEffect(()=>{u.current=a});const[g]=s.useState(()=>Yd(t,a,n,i)),[m,w]=s.useReducer(Jd,{...g,dataSource:l?.dataSource?{...g.dataSource,...l.dataSource}:g.dataSource,pagination:{rowCount:l?.pagination?.rowCount},dimensions:{...g.dimensions,rowHeight:o,headerHeight:r}}),[y,p]=s.useState({rows:t,syncRows:d});(y.rows!==t||y.syncRows!==d)&&(p({rows:t,syncRows:d}),d&&w({type:"SET_ROWS",payload:t,getRowId:a}));const f=s.useRef(m);s.useLayoutEffect(()=>{f.current=m});const h=s.useCallback((I,A)=>{w({type:"SET_ROWS",payload:I,getRowId:u.current})},[]),x=s.useCallback((I,A)=>{w({type:"REPLACE_ROW",id:I,row:A})},[]),b=s.useCallback(I=>{I.size>0&&w({type:"REPLACE_ROWS",rows:I})},[]),v=s.useCallback(I=>{w({type:"SET_COLUMNS",payload:I})},[]),E=s.useCallback((I,A)=>{w({type:"SET_DIMENSIONS",payload:{viewportWidth:I,viewportHeight:A}})},[]),k=s.useCallback(I=>{w({type:"SET_DATASOURCE_LOADING",payload:I})},[]),N=s.useCallback(I=>{w({type:"SET_DATASOURCE_ERROR",payload:I})},[]),M=s.useCallback(I=>{w({type:"SET_ROW_COUNT",payload:I})},[]),[S]=s.useState(()=>({...Sl(),getRow:I=>f.current.rows.idRowsLookup.get(I)||null,getAllRows:()=>f.current.rows.allRows.map(I=>f.current.rows.idRowsLookup.get(I)),getColumn:I=>f.current.columns.lookup.get(I)||null,getAllColumns:()=>f.current.columns.all})),D=s.useRef(S);return{state:m,dispatch:w,apiRef:D,setRows:h,replaceRow:x,replaceRows:b,setColumns:v,setDimensions:E,setDataSourceLoading:k,setDataSourceError:N,setRowCount:M}}function Qd(e){const{onRowOrderChange:t,rows:n,getRowId:o,rowReordering:r=!1}=e,[i,l]=s.useState(null),[d,a]=s.useState(null),u=s.useRef(()=>{}),g=s.useMemo(()=>{const h=new Map;return n.forEach((x,b)=>h.set(o?o(x):x.id,b)),h},[n,o]),m=s.useCallback(h=>g.has(h),[g]),w=s.useCallback(()=>{u.current(),u.current=()=>{},l(null),a(null)},[]);s.useEffect(()=>()=>u.current(),[]);const y=s.useCallback(h=>x=>{if(r){if(!g.has(h)){x.preventDefault();return}u.current(),u.current=qi(x.currentTarget,w),l(h),x.dataTransfer&&(x.dataTransfer.effectAllowed="move",Ri(x,Qo,String(h)))}},[r,g,w]),p=s.useCallback(h=>x=>{if(!(!r||i===null)){if(!Rn(x,Qo)){w();return}g.has(h)&&(x.preventDefault(),x.dataTransfer&&(x.dataTransfer.dropEffect="move"),d!==h&&a(h))}},[r,i,d,g,w]),f=s.useCallback(h=>x=>{if(x.preventDefault(),i===null||!Rn(x,Qo)){w();return}const b=g.get(i),v=g.get(h);w(),t&&b!==void 0&&v!==void 0&&b!==v&&t({row:n[b],oldIndex:b,targetIndex:v})},[i,t,n,g,w]);return{draggedRowId:i,dragOverRowId:d,canReorderRow:m,onDragStart:r?y:void 0,onDragOver:r?p:void 0,onDragEnd:r?w:void 0,onDrop:r?f:void 0}}const Ml=new Map,Nl=e=>JSON.stringify(e),eu=e=>`auto-group-${e}`,Il=5,Ll=e=>e.slice(0,Il).map(t=>JSON.stringify(t)).join(", ")+(e.length>Il?", …":""),tu={treeNodes:new Map,rootIds:[],groupingRows:[],syntheticIds:new Set,rowLookup:new Map,issues:[]};function nu(e,t,n){const o=new Map,r=[],i=[],l=new Set,d=new Map,a=new Map,u=[],g=new Array(e.length),m=new Array(e.length),w=[],y=new Map;e.forEach((f,h)=>{const x=t(f),b=n(f),v=Array.isArray(b)?b.map(E=>String(E)):[];if(g[h]=x,m[h]=v,d.set(x,f),v.length===0)w.push(x);else{const E=Nl(v),k=a.get(E);if(k===void 0)a.set(E,x);else{const N=y.get(E)??[k];N.push(x),y.set(E,N)}}o.set(x,{id:x,parentId:null,depth:Math.max(v.length-1,0),groupingKey:v[v.length-1]??"",isExpanded:!1,children:[],serverChildrenCount:f.serverChildrenCount})});const p=f=>{const h=Nl(f),x=a.get(h);if(x!==void 0)return x;const b=eu(h),v=f[f.length-1],E={id:b,parentId:null,depth:f.length-1,groupingKey:v,isExpanded:!1,children:[],label:v};o.set(b,E),a.set(h,b),l.add(b);const k={id:b};if(i.push(k),d.set(b,k),f.length===1)r.push(b);else{const N=p(f.slice(0,-1));E.parentId=N,o.get(N)?.children?.push(b)}return b};return e.forEach((f,h)=>{const x=g[h],b=m[h];if(b.length<=1){r.push(x);return}const v=p(b.slice(0,-1)),E=o.get(x);E&&(E.parentId=v),o.get(v)?.children?.push(x)}),w.length>0&&u.push(`[OpenGridX] treeData: getTreeDataPath returned an empty path for row(s) ${Ll(w)}. They are shown as top-level rows.`),y.forEach((f,h)=>{u.push(`[OpenGridX] treeData: rows ${Ll(f)} have the same path ${h}. Rows under that path are attached to row ${JSON.stringify(f[0])}.`)}),{treeNodes:o,rootIds:r,groupingRows:i,syntheticIds:l,rowLookup:d,issues:u}}function ou(e,t){const{treeNodes:n,rootIds:o,syntheticIds:r,rowLookup:i}=e,l=new Set,d=new Map,a=new Map,u=g=>{const m=n.get(g);if(!m)return!1;const w=[];let y=0;for(const x of m.children??[])u(x)&&(w.push(x),y+=(r.has(x)?0:1)+(a.get(x)??0));d.set(g,w),a.set(g,y);const p=i.get(g),h=!r.has(g)&&p!==void 0&&(t?t(p):!0)||w.length>0;return h&&l.add(g),h};return o.forEach(u),{visible:l,visibleChildren:d,descendantCounts:a}}function ru(e){const{rows:t,getRowId:n,getTreeDataPath:o,treeData:r=!1,defaultGroupingExpansionDepth:i=0,filterModel:l,sortModel:d,onRowExpansionChange:a,columnLookup:u,filterMode:g="client",sortingMode:m="client"}=e,w=r&&!!o,y=s.useMemo(()=>!r||!o?tu:nu(t,n,o),[t,o,r,n]),{treeNodes:p,rootIds:f,groupingRows:h,syntheticIds:x,rowLookup:b}=y,v=y.issues.join(`
|
|
2
|
-
`);s.useEffect(()=>{process.env.NODE_ENV==="production"||!
|
|
3
|
-
`).forEach(j=>console.warn(j))},[v]);const E=r&&!o;s.useEffect(()=>{process.env.NODE_ENV==="production"||!E||console.warn("[OpenGridX] treeData is set without getTreeDataPath, so the rows are shown as a flat list. Pass getTreeDataPath={(row) => row.path} to build the tree.")},[E]);const k=s.useMemo(()=>g==="server"?null:Wn(l,u),[g,l,u]),N=s.useMemo(()=>ou(y,k),[y,k]),M=`${r}|${i}`,[S,D]=s.useState(()=>({configKey:M,overrides:new Map})),I=S.configKey===M?S.overrides:Ml,A=s.useCallback(j=>((j?.children?.length??0)>0||(j?.serverChildrenCount??0)>0)&&(i===-1||(j?.depth??0)<i),[i]),C=s.useMemo(()=>{const j=new Set;return w&&p.forEach((H,ie)=>{(I.get(ie)??A(H))&&j.add(ie)}),j},[w,p,I,A]),L=s.useCallback(j=>{const H=!C.has(j);if(D(ie=>{const re=ie.configKey===M?ie.overrides:Ml,ue=new Map(re);return ue.set(j,H),{configKey:M,overrides:ue}}),H&&a){const ie=p.get(j);ie&&a(ie)}},[C,M,p,a]),F=m!=="server"&&!!(d&&d.length>0),_=s.useCallback(j=>{if(!w)return null;const H=j?.labelField,ie=j?.expandAll??!1,{visible:re,visibleChildren:ue}=N,ae=F&&d?d:[],R=(le,V)=>{if(x.has(le))return{value:V.field===H?p.get(le)?.label:void 0};const J=b.get(le),ne=u?.byField.get(V.field),fe=J?Le(J,V.field,ne):void 0,Z=ne?.sortComparator;return{value:fe,type:ne?.type,comparator:Z,params:Z&&J?{id:le,field:V.field,row:J,value:fe}:void 0}},te=[],ce=new Set,W=le=>{const V=le.filter(ne=>re.has(ne)),J=ae.length>0?Ko(V,ae,R):V;for(const ne of J){if(ce.has(ne))continue;const fe=b.get(ne);if(!fe)continue;ce.add(ne),te.push(fe);const Z=ue.get(ne);Z&&Z.length>0&&(ie||C.has(ne))&&W(Z)}};return W(f),te},[w,N,F,d,x,p,b,u,f,C]),z=s.useCallback(j=>C.has(j),[C]),K=s.useCallback(j=>p.get(j),[p]),Q=s.useCallback(j=>{const H=[];let ie=j;for(;ie!==null;){const re=p.get(ie);if(!re)break;H.unshift(re.groupingKey),ie=re.parentId}return H},[p]),G=s.useMemo(()=>{const j=new Map,{visibleChildren:H,descendantCounts:ie}=N;return p.forEach((re,ue)=>{const ae=(re.children?.length??0)===0&&(re.serverChildrenCount??0)>0,R=x.has(ue),te={hasChildren:(H.get(ue)?.length??0)>0||ae,treeDepth:re.depth,descendantCount:ae?void 0:ie.get(ue)??0,isGroupRow:R,isExpanded:C.has(ue)};R&&(te.groupLabel=re.label),j.set(ue,te)}),j},[p,x,N,C]);return s.useMemo(()=>({treeNodes:p,groupingRows:h,toggleExpansion:L,isGroupExpanded:z,getVisibleRows:_,getNode:K,getNodePath:Q,rowMetaMap:G}),[p,h,L,z,_,K,Q,G])}const Al=e=>e===null?"footer":"inline";function Pl(e,t){return Dn(()=>e(t),Al(t),"getAggregationPosition","getAggregationPosition threw; the default position is used")}function iu(e,t,n){const o=`${t}: ${String(n)}`,r=e?.groupingValueFormatter;return r?Dn(()=>r({field:t,value:n}),o,`groupingValueFormatter:${t}`,`groupingValueFormatter for column "${t}" threw; the group is labelled "${t}: value"`):o}const lu=[],su={},Tl=new Map,et="";function au(e){if(typeof e=="string")return e;if(e===null)return`${et}null`;if(e===void 0)return`${et}undefined`;if(e instanceof Date)return`${et}date:${e.getTime()}`;if(typeof e=="object")try{return`${et}object:${JSON.stringify(e)}`}catch{return`${et}object:${String(e)}`}return`${et}${typeof e}:${String(e)}`}const cu=(e,t,n)=>`auto-group-${e}-${t}-${n??"root"}`,du=e=>`${e}${et}footer`,uu=e=>e==="footer"?"f":e===null?"n":"i",fu=e=>e==="f"?"footer":e==="n"?null:"inline";function gu(e){const{rows:t,getRowId:n,columns:o,rowGroupingModel:r=lu,aggregationModel:i=su,defaultGroupingExpansionDepth:l=0,filterModel:d,sortModel:a,getAggregationPosition:u=Al,columnLookup:g,filterMode:m="client",sortingMode:w="client"}=e,y=r.join(et),p=s.useMemo(()=>y===""?[]:y.split(et),[y]),f=JSON.stringify(Object.entries(i)),h=s.useMemo(()=>Object.fromEntries(JSON.parse(f)),[f]),x=Object.keys(h).length>0,b=s.useMemo(()=>{const W=new Map;return(o??[]).forEach(le=>W.set(le.field,le)),W},[o]),v=p.length>0,E=s.useMemo(()=>p.filter(W=>b.get(W)?.groupable!==!1),[p,b]),N=`${E.join(et)}|${l}`,[M,S]=s.useState(()=>({configKey:N,overrides:new Map})),D=M.configKey===N?M.overrides:Tl,I=s.useMemo(()=>{if(!v||m==="server")return null;const W=Wn(d,g);return W?new Set(t.filter(le=>W(le))):null},[v,t,m,d,g]),A=s.useMemo(()=>{const W=new Map,le=[],V=[],J=new Map,ne=new Map,fe=new Map;if(!v)return{treeNodes:W,rootIds:le,groupIds:V,groupRowVariants:J,groupingRows:ne,rowLookup:fe};const Z=($,O,P)=>{if(O>=E.length)return(I?$.filter(Y=>I.has(Y)):$).map(Y=>{const oe=n(Y);return fe.set(oe,Y),W.set(oe,{id:oe,parentId:P,depth:O,groupingKey:"",isExpanded:!1}),oe});const T=E[O],X=b.get(T),B=new Map;for(const q of $){const Y=Le(q,T,X),oe=au(Y);let me=B.get(oe);me||(me={value:Y,rows:[]},B.set(oe,me)),me.rows.push(q)}const ee=[];return B.forEach((q,Y)=>{const oe=I?q.rows.filter(ve=>I.has(ve)):q.rows;if(oe.length===0)return;const me=cu(T,Y,P);ee.push(me),V.push(me);const U=x?Hn(oe,h,b,"useRowGrouping"):{},se={[T]:q.value,...U,id:me},we={[T]:q.value,id:me},pe=x?{...U,id:du(me)}:null;J.set(me,{inline:se,bare:we,footer:pe}),ne.set(me,se),pe&&ne.set(pe.id,pe);const he={id:me,parentId:P,depth:O,groupingKey:String(q.value),groupingField:T,groupingValue:q.value,aggregatedValues:U,isExpanded:!1,children:[],label:iu(X,T,q.value),descendantCount:oe.length};W.set(me,he),he.children=Z(q.rows,O+1,me)}),ee};return le.push(...Z(t,0,null)),{treeNodes:W,rootIds:le,groupIds:V,groupRowVariants:J,groupingRows:ne,rowLookup:fe}},[v,t,I,E,x,h,n,b]),{treeNodes:C,rootIds:L,groupIds:F,groupRowVariants:_,groupingRows:z,rowLookup:K}=A,Q=s.useCallback(W=>!!(W?.children&&W.children.length>0)&&(l===-1||(W?.depth??0)<l),[l]),G=s.useMemo(()=>{const W=new Set;return C.forEach((le,V)=>{!le.children||le.children.length===0||(D.get(V)??Q(le))&&W.add(V)}),W},[C,D,Q]),j=s.useCallback(W=>{S(le=>{const V=le.configKey===N?le.overrides:Tl,J=V.get(W)??Q(C.get(W)),ne=new Map(V);return ne.set(W,!J),{configKey:N,overrides:ne}})},[N,C,Q]),H=s.useCallback(W=>G.has(W),[G]),ie=x?F.map(W=>{const le=C.get(W);return le?uu(Pl(u,{...le,isExpanded:G.has(W)})):"i"}).join(""):"",re=s.useMemo(()=>{const W=new Map;return F.forEach((le,V)=>W.set(le,fu(ie[V]))),W},[F,ie]),ue=x?Pl(u,null):"footer",ae=w!=="server"&&!!(a&&a.length>0),R=s.useCallback(W=>{if(!v)return null;const le=W?.labelField,V=W?.expandAll??!1,J=ae&&a?a:[],ne=(O,P)=>{const T=C.get(O),X=_.get(O);if(T&&X){const oe=T.groupingField??"";if(P.field===oe||P.field===le){const me=g?.byField.get(oe),U=me?.sortComparator;return{value:T.groupingValue,type:me?.type,comparator:U,params:U?{id:O,field:oe,row:X.inline,value:T.groupingValue}:void 0}}return T.aggregatedValues&&Object.prototype.hasOwnProperty.call(T.aggregatedValues,P.field)?{value:T.aggregatedValues[P.field],type:g?.byField.get(P.field)?.type}:{value:void 0}}const B=K.get(O),ee=g?.byField.get(P.field),q=B?Le(B,P.field,ee):void 0,Y=ee?.sortComparator;return{value:q,type:ee?.type,comparator:Y,params:Y&&B?{id:O,field:P.field,row:B,value:q}:void 0}},fe=[],Z=new Set,$=O=>{const P=J.length>0?Ko(O,J,ne):O;for(const T of P){if(Z.has(T))continue;Z.add(T);const X=_.get(T);if(!X){const oe=K.get(T);oe&&fe.push(oe);continue}const B=C.get(T),ee=G.has(T),q=re.has(T)?re.get(T)??null:"inline",Y=q==="inline"||q==="footer"&&!ee;fe.push(Y?X.inline:X.bare),(ee||V)&&B?.children&&($(B.children),ee&&!V&&q==="footer"&&X.footer&&fe.push(X.footer))}};return $(L),fe},[v,ae,a,C,_,K,g,G,re,L]),te=s.useCallback(W=>C.get(W),[C]),ce=s.useMemo(()=>{const W=new Map;return C.forEach((le,V)=>{const J=_.get(V);if(!J){W.set(V,{hasChildren:!1,treeDepth:le.depth,isGroupRow:!1});return}const ne={hasChildren:!0,treeDepth:le.depth,groupingField:le.groupingField,groupingValue:le.groupingValue,groupLabel:le.label,descendantCount:le.descendantCount,isGroupRow:!0,isExpanded:G.has(V)};W.set(V,ne),J.footer&&re.get(V)==="footer"&&W.set(J.footer.id,{...ne,hasChildren:!1,treeDepth:le.depth+1,isExpanded:void 0,isGroupFooter:!0})}),W},[C,_,G,re]);return s.useMemo(()=>({treeNodes:C,groupingRows:z,toggleExpansion:j,isGroupExpanded:H,getVisibleRows:R,getNode:te,rowMetaMap:ce,aggregationPositions:re,rootAggregationPosition:ue}),[C,z,j,H,R,te,ce,re,ue])}const pu=new Map;function hu(e){const{rows:t,getRowId:n,getTreeDataPath:o,isTreeDataRequested:r,isTreeData:i,columns:l,rowGroupingModel:d,isRowGrouping:a,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:m,sortModel:w,getAggregationPosition:y,columnLookup:p,filterMode:f,sortingMode:h}=e,x=ru({rows:t,getRowId:n,getTreeDataPath:o,treeData:r,defaultGroupingExpansionDepth:g,filterModel:m,sortModel:w,columnLookup:p,filterMode:f,sortingMode:h}),b=gu({rows:t,getRowId:n,columns:l,rowGroupingModel:d,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:m,sortModel:w,getAggregationPosition:y,columnLookup:p,filterMode:f,sortingMode:h}),v=i?x:a?b:null,E=s.useMemo(()=>i?x.rowMetaMap:a?b.rowMetaMap:pu,[i,x.rowMetaMap,a,b.rowMetaMap]);return{treeDataHandlers:x,rowGroupingHandlers:b,activeHierarchyHandlers:v,rowMetaMap:E}}function We(e){try{return{ok:!0,value:e()}}catch(t){return{ok:!1,error:t}}}class Fl extends Error{}function xt(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function Ol(e){return typeof e=="object"&&e!==null&&typeof e.then=="function"}function Dl(e,t){t?t(e):process.env.NODE_ENV!=="production"&&e instanceof Fl&&console.error(e.message)}function $l(e,t){return new Fl(`[OpenGridX] processRowUpdate must return the updated row object (or a Promise of it); it returned ${e===null?"null":typeof e}. ${t}`)}function Gl(e,t,n,o){return n?.valueSetter?n.valueSetter({value:t.value,row:e,field:t.field}):(n?.valueGetter&&process.env.NODE_ENV!=="production"&&!o.has(t.field)&&(o.add(t.field),console.warn(`[OpenGridX] Column "${t.field}" is editable and has a valueGetter but no valueSetter. The edited value was written to row["${t.field}"], which the valueGetter may ignore, so the cell can keep showing the old value. Add a valueSetter that maps the value back onto the row.`)),{...e,[t.field]:t.value})}const qt=Promise.resolve();function mu(e){const[t,n]=s.useState(null),o=s.useRef(null),r=s.useRef(0),i=s.useRef(new Map),l=s.useRef(new Set),d=s.useRef(!1),a=s.useRef(e);s.useLayoutEffect(()=>{a.current=e}),s.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const u=s.useCallback(f=>{o.current=f,n(f)},[]),g=s.useRef(null),m=s.useCallback((f,h)=>{const x=i.current.get(f);if(x)return xt(x.value,h.value)?x.promise:x.promise.then(()=>{const G=o.current;if(!(r.current!==f||!G||xt(G.value,x.value)))return g.current?.(f,G)});const b=()=>r.current===f&&o.current!==null;if(xt(h.value,h.originalValue))return b()&&u(null),qt;const{rows:v,getRowId:E,columns:k,processRowUpdate:N}=a.current,M=v.find(G=>E(G)===h.id);if(!M)return b()&&u(null),qt;const S=G=>Dl(G,a.current.onProcessRowUpdateError),D=k?.find(G=>G.field===h.field),I=G=>{if(typeof G!="object"||G===null){S($l(G,"The edit was not saved and the editor stays open."));return}a.current.onRowChange?.(G,h.id);const{onCommitted:j}=a.current;if(j){const ie=Le(M,h.field,D),re=Le(G,h.field,D);xt(ie,re)||j([{id:h.id,field:h.field,before:ie,after:re}])}const H=o.current;r.current!==f||!H||(xt(H.value,h.value)?u(null):u({...H,originalValue:h.value}))};let A,C;const L=new Promise((G,j)=>{A=G,C=j}),F={value:h.value,promise:L};i.current.set(f,F);const _=()=>{i.current.get(f)===F&&i.current.delete(f)},z=We(()=>{const G=Gl(M,h,D,l.current);return N?N(G,M):G});if(!z.ok)return _(),S(z.error),A(),L;const K=z.value,Q=G=>{_();try{I(G),A()}catch(j){C(j)}};return Ol(K)?Promise.resolve(K).then(Q,G=>{_(),S(G),A()}):Q(K),L},[u]);s.useLayoutEffect(()=>{g.current=m},[m]);const w=s.useCallback(f=>{const h=o.current;if(h){if(h.id===f.id&&h.field===f.field)return;m(r.current,h)}r.current+=1,u({id:f.id,field:f.field,value:f.value,originalValue:f.value})},[m,u]),y=s.useCallback(f=>{const h=o.current;return!h||!d.current||f?.id!==void 0&&f.id!==h.id||f?.field!==void 0&&f.field!==h.field?qt:f?.cancel?(u(null),qt):m(r.current,h)},[m,u]),p=s.useCallback(f=>{const h=o.current;!h||h.id!==f.id||h.field!==f.field||u({...h,value:f.value})},[u]);return s.useMemo(()=>({editingCell:t,startCellEdit:w,stopCellEdit:y,setEditCellValue:p}),[t,w,y,p])}function wu(e){const t=s.useRef(e),n=s.useRef(new Map),o=s.useRef(new Set);s.useLayoutEffect(()=>{t.current=e,n.current.clear()});const r=s.useCallback(a=>{const u=n.current.get(a);return u===void 0?t.current.rowsLookup.get(a):u},[]),i=s.useCallback(a=>{a.size!==0&&(a.forEach((u,g)=>{n.current.set(g,u)}),t.current.replaceRows(a))},[]),l=s.useCallback((a,u)=>{i(new Map([[a,u]]))},[i]),d=s.useCallback((a,u)=>{const{columns:g,processRowUpdate:m}=t.current,w=k=>Dl(k,t.current.onProcessRowUpdateError),y=new Map,p=new Map;g.forEach((k,N)=>{y.set(k.field,N),p.set(k.field,k)});const f=[],h=new Map;for(const k of a){const N=r(k.id);if(N===void 0){f.push({id:k.id,field:k.field,reason:"missing"});continue}const M=p.get(k.field);if(k.expect&&!xt(Le(N,k.field,M),k.expect.value)){f.push({id:k.id,field:k.field,reason:"changed"});continue}let S=h.get(k.id);S||(S={id:k.id,row:N,cells:[]},h.set(k.id,S));const D=y.get(k.field)??Number.MAX_SAFE_INTEGER,I=S.cells.findIndex(C=>C.field===k.field),A={field:k.field,value:k.value,colDef:M,order:D};I===-1?S.cells.push(A):S.cells[I]=A}const x=[],b=[],v=o.current;h.forEach(k=>{const{id:N,row:M}=k,S=k.cells.filter(A=>!xt(Le(M,A.field,A.colDef),A.value)).sort((A,C)=>A.order-C.order);if(k.cells=S,S.length===0)return;const D=We(()=>{let A=M;for(const C of S)A=Gl(A,C,C.colDef,v);return m?m(A,M):A});if(!D.ok){x.push({id:N,ok:!1,error:D.error});return}const I=D.value;Ol(I)?b.push(Promise.resolve(I).then(A=>({id:N,ok:!0,processed:A}),A=>({id:N,ok:!1,error:A}))):x.push({id:N,ok:!0,processed:I})});const E=k=>{const N=new Map;k.forEach(A=>{N.set(A.id,A)});const M=[],S=[],D=[],I=new Map;return h.forEach(A=>{const C=N.get(A.id);if(!C)return;if(!C.ok){S.push({id:A.id,error:C.error}),w(C.error);return}const L=C.processed;if(typeof L!="object"||L===null){const _=$l(L,"The row was not saved.");S.push({id:A.id,error:_}),w(_);return}const F=L;I.set(A.id,F),M.push(A.id);for(const _ of A.cells){const z=Le(A.row,_.field,_.colDef),K=Le(F,_.field,_.colDef);xt(z,K)||D.push({id:A.id,field:_.field,before:z,after:K})}}),i(I),D.length>0&&u!=="undo"&&u!=="redo"&&t.current.onCommitted?.(D,u),{result:{updated:M,failed:S,skipped:f},committed:D}};return b.length===0?Promise.resolve(E(x)):Promise.all(b).then(k=>E([...x,...k]))},[r,i]);return s.useMemo(()=>({applyEdits:d,getRow:r,storeRow:l}),[d,r,l])}const dt={ok:!1},$e=e=>({ok:!0,value:e});function bu(e){const t=[];if(e==="")return t;let n=[],o="",r=0;const i=e.length;let l=!0;for(;r<i;){const d=e[r];if(l&&d==='"'){let a=r+1,u="",g=!1;for(;a<i;){const m=e[a];if(m==='"'){if(e[a+1]==='"'){u+='"',a+=2;continue}g=!0,a+=1;break}u+=m,a+=1}if(!g){o+=d,r+=1,l=!1;continue}o+=u,r=a,l=!1;continue}l=!1,d===" "?(n.push(o),o="",l=!0,r+=1):d===`
|
|
1
|
+
(function(_e,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],c):(_e=typeof globalThis<"u"?globalThis:_e||self,c(_e.OpenGridX={},_e.ReactJSXRuntime,_e.React,_e.ReactDOM))})(this,(function(_e,c,s,mt){"use strict";function ko(e,t,n){return Math.max(t??0,Math.min(n??1/0,e))}function Nt(e,t,n=100){if(e.isSpacer)return typeof e.width=="number"?e.width:0;const o=t[e.field]??e.width,r=typeof o=="number"&&Number.isFinite(o)?o:n;return ko(r,e.minWidth,e.maxWidth)}const Be=48;function ct(e,t){return t?t.left?.includes(e)?"left":t.right?.includes(e)?"right":null:null}function ya(e,t){const n=[],o=[],r=[];return t?(e.forEach(i=>{const l=ct(i.field,t);l==="left"?n.push(i):l==="right"?r.push(i):o.push(i)}),t.left&&n.sort((i,l)=>{const d=t.left.indexOf(i.field),a=t.left.indexOf(l.field);return d-a}),t.right&&r.sort((i,l)=>{const d=t.right.indexOf(i.field),a=t.right.indexOf(l.field);return d-a}),{left:n,center:o,right:r}):{left:n,center:e,right:r}}function Eo(e,t,n,o,r,i,l,d){const a={};if(!n)return a;let u=(d?Be:0)+(i&&l?Be:0)+(o&&r?Be:0);const g=[];e.forEach(w=>{if(w.isSpacer)return;const y=ct(w.field,n);y==="left"?(a[w.field]=u,u+=Nt(w,t)):y==="right"&&g.push(w)});let h=0;for(let w=g.length-1;w>=0;w--)a[g[w].field]=h,h+=Nt(g[w],t);return a}function Mo(e,t){let n=null,o=null;if(!t)return{lastLeft:n,firstRight:o};for(const r of e){if(r.isSpacer)continue;const i=ct(r.field,t);i==="left"?n=r.field:i==="right"&&o===null&&(o=r.field)}return{lastLeft:n,firstRight:o}}function oi(e,t){return t?t.top?.includes(e)?"top":t.bottom?.includes(e)?"bottom":null:null}function Ca(e,t,n=o=>o.id){const o=[],r=[],i=[];return t?(e.forEach(l=>{const d=oi(n(l),t);d==="top"?o.push(l):d==="bottom"?i.push(l):r.push(l)}),t.top&&o.sort((l,d)=>{const a=t.top.indexOf(n(l)),u=t.top.indexOf(n(d));return a-u}),t.bottom&&i.sort((l,d)=>{const a=t.bottom.indexOf(n(l)),u=t.bottom.indexOf(n(d));return a-u}),{top:o,center:r,bottom:i}):{top:o,center:e,bottom:i}}function va(e,t,n){const o=(e?.left??[]).filter(i=>i!==t),r=(e?.right??[]).filter(i=>i!==t);return n==="left"?{left:[...o,t],right:r}:n==="right"?{left:o,right:[...r,t]}:{left:o,right:r}}const ri=new Set;function Wt(e,t,n){process.env.NODE_ENV==="production"||ri.has(e)||(ri.add(e),console.warn(`[OpenGridX] ${t}.`,n))}function Dn(e,t,n,o){try{return e()}catch(r){return Wt(n,o,r),t}}function ii(e,t,n){const o=e[t];if(!n?.valueGetter)return{value:o};try{return{value:n.valueGetter({row:e,field:t,value:o})}}catch(r){return{value:void 0,error:r??new Error("valueGetter failed")}}}function Le(e,t,n){const{value:o,error:r}=ii(e,t,n);return r!==void 0&&Wt(`valueGetter:${t}`,`valueGetter for column "${t}" threw; the value is read as undefined`,r),o}function No(e,t,n,o){const r=o?.valueFormatter;if(r)return Dn(()=>r({value:n,row:e,field:t}),void 0,`valueFormatter:${t}`,`valueFormatter for column "${t}" threw; the value is shown unformatted`)}function It(e){if(e==null)return null;if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e=="string"){const t=e.trim();if(t==="")return null;const n=Number(t);return Number.isNaN(n)?null:n}if(typeof e=="boolean")return null;if(e instanceof Date){const t=e.getTime();return Number.isNaN(t)?null:t}return typeof e=="bigint"?Number(e):null}const _a=/^(\d{4})-(\d{2})-(\d{2})$/;function gn(e){if(e==null)return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else if(typeof e=="string"){const n=e.trim();if(n==="")return null;const o=_a.exec(n);if(o){const r=Number(o[1]),i=Number(o[2])-1,l=Number(o[3]);if(t=new Date(r,i,l),t.getMonth()!==i||t.getDate()!==l)return null}else t=new Date(n)}else return null;return Number.isNaN(t.getTime())?null:t}function $n(e){const t=gn(e);return t?t.getFullYear()*1e4+(t.getMonth()+1)*100+t.getDate():null}function li(e){const t=gn(e);if(!t)return"";const n=String(t.getFullYear()).padStart(4,"0"),o=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${n}-${o}-${r}`}let si=null;function ai(e){return si??=new Intl.DateTimeFormat,si.format(e)}function Sa(e,t){if(!e)return;const n=i=>typeof i=="object"?i.value:i,o=i=>typeof i=="object"?i.label:String(i),r=e.find(i=>Object.is(n(i),t))??e.find(i=>String(n(i))===String(t));return r===void 0?void 0:o(r)}function Io(e,t){if(e==null)return"";switch(t?.type){case"date":{const n=gn(e);return n?ai(n):String(e)}case"boolean":return e===!0?"Yes":e===!1?"No":String(e);case"singleSelect":return Sa(t.valueOptions,e)??String(e);default:return String(e)}}const Lo=200;function Ao(e){if(e==="auto")return"auto";const t=typeof e=="string"?Number.parseFloat(e):e;return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:Lo}function Po(e,t){if(e)return Dn(()=>e(t),void 0,"getDetailPanelHeight","getDetailPanelHeight threw; the panel uses the default height")}function ka(e,t){const n=Ao(e);return n==="auto"?t??Lo:n}function Ea(e,t){if(t.size===0||e.size===0)return e;let n=!1;const o=new Set;for(const r of e)t.get(r)?.isGroupRow?n=!0:o.add(r);return n?o:e}const Ma=e=>e.id;function Na(e){if(e===void 0)return{type:"auto",value:0};if(typeof e=="number")return{type:"fixed",value:e};if(typeof e=="string"){if(e.toLowerCase()==="auto")return{type:"auto",value:0};if(e.endsWith("%"))return{type:"percentage",value:parseFloat(e)};const t=parseFloat(e);if(!isNaN(t))return{type:"fixed",value:t}}return{type:"fixed",value:100}}function Ia(e,t,n){const o=new Map;e.forEach(f=>{if(!Object.prototype.hasOwnProperty.call(t,f.field)&&f.flex&&f.flex>0){o.set(f.field,{kind:"flex",flex:f.flex});return}const x=Na(t[f.field]??f.width);x.type==="fixed"?o.set(f.field,{kind:"fixed",width:ko(x.value,f.minWidth,f.maxWidth)}):x.type==="percentage"?o.set(f.field,{kind:"percentage",percentage:x.value}):o.set(f.field,{kind:"flex",flex:1})});const r=e.reduce((f,m)=>{const x=o.get(m.field);if(x.kind==="fixed")return f+x.width;if(x.kind==="percentage")return f+100;if(m.flex&&m.flex>0){const b=m.minWidth??150;return f+(b||(typeof m.width=="number"?m.width:150))}return f+(m.minWidth??150)},0),i=Math.max(n,r),l=e.reduce((f,m)=>{const x=o.get(m.field);return x.kind==="fixed"?f+x.width:f},0),d=new Map,a=Math.max(0,i-l);let u=0;e.forEach(f=>{const m=o.get(f.field);if(m.kind==="fixed")d.set(f.field,m.width);else if(m.kind==="percentage"){const x=m.percentage/100*a,b=ko(x>0?x:100,f.minWidth??50,f.maxWidth);d.set(f.field,b),u+=b}});const g=Math.max(0,a-u),h=new Map,w=e.flatMap(f=>{const m=o.get(f.field);return m.kind!=="flex"?[]:(h.set(f.field,m.flex),[{field:f.field,flex:m.flex,minWidth:f.minWidth??50,maxWidth:f.maxWidth??1/0,frozen:!1,computedWidth:0}])});let y=0;const p=w.length*2;for(;y<p;){y++;const f=w.filter(M=>!M.frozen);if(f.length===0)break;const m=f.reduce((M,S)=>M+S.flex,0),x=w.reduce((M,S)=>S.frozen?M+S.computedWidth:M,0),b=Math.max(0,g-x);if(m<=0){f.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0});break}const C=b/m;let E=0;const k=[],N=[];if(f.forEach(M=>{const S=C*M.flex;S<M.minWidth?(E+=M.minWidth-S,k.push(M)):S>M.maxWidth?(E+=M.maxWidth-S,N.push(M)):M.computedWidth=S}),k.length===0&&N.length===0){f.forEach(M=>{M.frozen=!0});break}E>0?k.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}):E<0?N.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}):(k.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}),N.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}))}return w.forEach(f=>d.set(f.field,f.computedWidth)),{widths:d,flexByField:h}}function La(e){const{rowHeight:t,pagination:n,paginatedUnpinnedRows:o,sortedUnpinnedRows:r,expandedRowIds:i,getDetailPanelHeight:l,detailPanelHeights:d,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,pinnedTopRows:g,pinnedBottomRows:h,visibleOrderedColumns:w,pinnedColumns:y,columnWidths:p,viewportWidth:f,checkboxSelection:m,hasDetailPanel:x,rowReordering:b,pinCheckboxColumn:C,pinExpandColumn:E,paginationMode:k,isLoading:N,pageSize:M,getRowId:S=Ma}=e;return s.useMemo(()=>{const F=n?o:r,I=(P,T)=>{const X=S(P);if(!i.has(X))return t;const B=Po(l,{row:P,id:X,rowIndex:T});return t+ka(B,d?.get(X))},A=F.map((P,T)=>I(P,a+T)),_=A.reduce((P,T,X)=>(P.push((P[X-1]||0)+T),P),[]),L=k==="infinite"&&N&&F.length>0?Math.min(M,20):0,D=(_[_.length-1]||0)+L*t,v=(P,T)=>P?P.reduce((X,B,ee)=>X+I(B,ee),0):T*t,V=v(g,a),R=v(h,u),{left:Q,center:G,right:W}=ya(w,y),H=(m?Be:0)+(x?Be:0)+(b?Be:0),ie=(b?Be:0)+(x&&E?Be:0)+(m&&C?Be:0),{widths:oe,flexByField:ue}=Ia([...Q,...G,...W],p,f-H),se=P=>oe.get(P.field)??100,U=P=>({...P,width:se(P),flex:ue.get(P.field)??P.flex}),te=11,ce=Q.map((P,T)=>({...U(P),zIndex:te+T})),z=11,re=W.map((P,T)=>({...U(P),zIndex:z+(W.length-1-T)})),K=G.map(U),J=K.map(P=>P.width),ae=ce.reduce((P,T)=>P+T.width,0),fe=re.reduce((P,T)=>P+T.width,0),Z=J.reduce((P,T)=>P+T,0),$=ae+Z+fe+H,O=J.reduce((P,T,X)=>(P.push((P[X-1]||0)+T),P),[]);return{rowHeights:A,cumulativeHeights:_,unpinnedRowsHeight:D,pinnedTopHeight:V,pinnedBottomHeight:R,leftPinnedCols:ce,rightPinnedCols:re,unpinnedColsWithWidth:K,unpinnedColWidths:J,unpinnedAccWidths:O,totalWidth:$,leftWidth:ae,rightWidth:fe,unpinnedTotalWidth:Z,systemColumnsWidth:H,pinnedSystemColumnsWidth:ie,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,unpinnedRowsLength:F.length}},[t,n,o,r,i,l,d,a,u,g,h,w,y,p,f,m,x,b,C,E,k,N,M,S])}function Aa(e){const t=e.querySelector(".ogx__sticky-bottom");return t?t.getBoundingClientRect().height:0}function Gn(e,t,n,o,r){if(t<0||t>=n.length)return;const i=e.querySelector(".ogx__virtual-container");if(!i)return;const{scrollTop:l,clientHeight:d}=e,a=i.getBoundingClientRect().top-e.getBoundingClientRect().top+l,u=Math.max(o,Aa(e)),g=a+(t===0?0:n[t-1]),h=r!==void 0?Math.min(g+r,a+n[t]):a+n[t];g<l+a?e.scrollTop=Math.max(0,g-a):h>l+d-u&&(e.scrollTop=h-d+u)}function To(e,t,n){const{unpinnedAccWidths:o,leftWidth:r,rightWidth:i,systemColumnsWidth:l,pinnedSystemColumnsWidth:d}=n;if(t<0||t>=o.length)return;const a=l+r,u=a+(t>0?o[t-1]:0),g=a+o[t],h=d+r,{scrollLeft:w,clientWidth:y}=e;u<w+h?e.scrollLeft=Math.max(0,u-h):g>w+y-i&&(e.scrollLeft=g-y+i)}function Fo(e,t){const{row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:d,rowMeta:a}=e;if(!i.editable||a?.isGroupRow||n._isSkeleton)return!1;if(!t)return!0;try{return!!t({row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:d})}catch{return!1}}const Pa={},Oo=e=>e==null||typeof e=="string"&&e.trim()==="",ci=e=>{const t=[];for(const n of e){const o=It(n);o!==null&&t.push(o)}return t},di=(e,t)=>{let n=null,o=null;for(const r of e){const i=It(r);i!==null&&(n===null||t(i,n))&&(n=i,o=r)}return n===null?null:o instanceof Date?o:n},Lt={sum:e=>ci(e).reduce((t,n)=>t+n,0),avg:e=>{const t=ci(e);return t.length?t.reduce((n,o)=>n+o,0)/t.length:null},count:e=>e.filter(t=>!Oo(t)).length,min:e=>di(e,(t,n)=>t<n),max:e=>di(e,(t,n)=>t>n),unique:e=>new Set(e.filter(t=>!Oo(t))).size};function Do(e,t){return e?e.aggregable===!1?!1:!e.availableAggregationFunctions||e.availableAggregationFunctions.includes(t):!0}function Hn(e,t,n,o){const r={};for(const[i,l]of Object.entries(t)){const d=n.get(i);if(!Do(d,l))continue;const a=Lt[l];if(!a){console.warn(`[${o}] Unknown aggregation function: "${l}"`);continue}r[i]=a(e.map(u=>Le(u,i,d)))}return r}function pn(e,t){return e==null?"—":typeof e=="number"?t==="avg"?e.toLocaleString(void 0,{maximumFractionDigits:2}):e.toLocaleString():String(e)}const Ta=new Set(["count","unique"]);function ui(e){return e!==void 0&&Ta.has(e)}function fi(e,t,n){return e?.type==="date"&&(t==="min"||t==="max")&&typeof n=="number"&&Number.isFinite(n)?new Date(n):n}function Bn(e,t,n,o){if(e==null)return"—";if(ui(t))return pn(e,t);const r=fi(n,t,e);if(n?.valueFormatter)try{return String(n.valueFormatter({value:r,row:o??{},field:n.field})??"")}catch{}return r instanceof Date?Number.isNaN(r.getTime())?"":ai(r):pn(r,t)}const Vt=new Set(["isEmpty","isNotEmpty"]);function $o(e){return e==null?!0:typeof e=="string"?e.trim()==="":Array.isArray(e)?e.length===0:!1}function Fa(e){return e==null?!0:typeof e=="number"?Number.isNaN(e):typeof e=="string"&&e.trim()===""}const hn=e=>(t,n)=>{const o=It(t),r=It(n);return o===null||r===null?!1:e(o,r)},mn=e=>(t,n)=>{const o=$n(t),r=$n(n);return o===null||r===null?!1:e(o,r)},gi=mn((e,t)=>e===t),pi=(e,t)=>{const n=$n(e),o=$n(t);return n===null||o===null?!0:n!==o},hi={contains:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase()),equals:(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:String(e).toLowerCase()===String(t).toLowerCase(),startsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().startsWith(String(t).toLowerCase()),endsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().endsWith(String(t).toLowerCase()),isEmpty:e=>e==null||String(e).trim()==="",isNotEmpty:e=>e!=null&&String(e).trim()!=="","=":hn((e,t)=>e===t),">":hn((e,t)=>e>t),">=":hn((e,t)=>e>=t),"<":hn((e,t)=>e<t),"<=":hn((e,t)=>e<=t),"!=":(e,t)=>{if($o(t))return!0;const n=It(e),o=It(t);return n!==null&&o!==null?n!==o:Fa(e)?!0:String(e).toLowerCase()!==String(t).toLowerCase()},isAnyOf:(e,t)=>{if(e==null)return!1;const n=Array.isArray(t)?t:[t],o=String(e).toLowerCase();return n.some(r=>r!=null&&String(r).toLowerCase()===o)},not:(e,t)=>e instanceof Date?pi(e,t):e==null&&t==null?!1:e==null||t==null?!0:String(e).toLowerCase()!==String(t).toLowerCase(),is:(e,t)=>t==null||t===""?!0:e instanceof Date?gi(e,t):String(e).toLowerCase()===String(t).toLowerCase(),after:mn((e,t)=>e>t),onOrAfter:mn((e,t)=>e>=t),before:mn((e,t)=>e<t),onOrBefore:mn((e,t)=>e<=t)},Oa={is:gi,not:pi};function Da(e,t){if(!Object.prototype.hasOwnProperty.call(hi,e))return;const n=e;if(t?.type==="date"){const o=Oa[n];if(o)return o}return hi[n]}function $a(e){return"items"in e&&Array.isArray(e.items)}function Ga(e,t){const{field:n,operator:o,value:r}=e;if(!Vt.has(o)&&$o(r))return null;const i=t.columns?.byField.get(n),l=Da(o,i);return l?d=>l(Le(d,n,i),r):(t.warned.has(o)||(t.warned.add(o),console.warn(`Unknown filter operator: ${o}`)),null)}function mi(e,t,n){const o=[];for(const r of e){const i=$a(r)?mi(r.items,r.logicOperator,n):Ga(r,n);i&&o.push(i)}return o.length===0?null:o.length===1?o[0]:t==="or"?r=>o.some(i=>i(r)):r=>o.every(i=>i(r))}function Go(e,t){if(t!=null){switch(typeof t){case"string":e.push(t.toLowerCase());return;case"number":Number.isNaN(t)||e.push(String(t));return;case"boolean":case"bigint":e.push(String(t));return}if(t instanceof Date){const n=li(t);n&&e.push(n);return}if(Array.isArray(t))for(const n of t)(n==null||typeof n!="object")&&Go(e,n)}}function wi(e,t){const n=[];if(!t){for(const o of Object.values(e))Go(n,o);return n}for(const o of t.quickFilterColumns){const r=Le(e,o.field,o),i=No(e,o.field,r,o);i!=null&&i!==""&&n.push(String(i).toLowerCase()),Go(n,r)}return n}const bi=new WeakMap;function Ha(e,t){if(!t)return wi(e,t);let n=bi.get(t);n||(n=new WeakMap,bi.set(t,n));let o=n.get(e);return o||(o=wi(e,t),n.set(e,o)),o}function Ba(e,t){const n=(e??[]).map(o=>String(o??"").trim().toLowerCase()).filter(o=>o!=="");return n.length===0?null:o=>{const r=Ha(o,t);return n.every(i=>r.some(l=>l.includes(i)))}}function Wn(e,t){if(!e)return null;const n={columns:t,warned:new Set},o="quickFilterValues"in e?e.quickFilterValues:void 0,r=Ba(o,t),i=mi(e.items??[],e.logicOperator??"and",n);return r&&i?l=>r(l)&&i(l):r??i}function Ho(e,t,n){const o=Wn(t,n);return o?e.filter(r=>o(r)):e}function xi(e){switch(e){case"number":return["=","!=",">",">=","<","<=","isEmpty","isNotEmpty"];case"date":return["is","not","after","onOrAfter","before","onOrBefore","isEmpty","isNotEmpty"];case"boolean":return["is"];case"singleSelect":return["isAnyOf","is","not"];default:return["contains","equals","startsWith","endsWith","isEmpty","isNotEmpty"]}}function Bo(e,t){return e==null?"":t==="date"||e instanceof Date?li(e)||(typeof e=="string"?e:""):Array.isArray(e)?e.map(n=>String(n)).join(", "):String(e)}const Wa=new Intl.Collator(void 0,{numeric:!0,sensitivity:"accent"}),Wo=0,yi=1,Va=2,Ci=3,vi=4;function zt(e,t){return{rank:e,num:t,str:""}}function Vo(e,t){if(e==null)return null;if(t==="number"){const n=It(e);return n===null?null:zt(Wo,n)}if(t==="date"){const n=gn(e);return n?zt(yi,n.getTime()):null}switch(typeof e){case"number":return Number.isNaN(e)?null:zt(Wo,e);case"bigint":return zt(Wo,Number(e));case"boolean":return zt(Va,e?1:0);case"string":return{rank:Ci,num:0,str:e}}if(e instanceof Date){const n=e.getTime();return Number.isNaN(n)?null:zt(yi,n)}return{rank:vi,num:0,str:String(e)}}function _i(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:e.rank!==t.rank?e.rank-t.rank:e.rank===Ci||e.rank===vi?Wa.compare(e.str,t.str):e.num<t.num?-1:e.num>t.num?1:0}function zo(e,t){return e===0?0:t==="asc"?e:-e}function za(e,t,n,o){return zo(_i(Vo(e,o),Vo(t,o)),n)}function Si(e,t,n){let o;try{o=e(t.value,n.value,t,n)}catch(r){return Wt(`sortComparator:${t.field}`,`sortComparator for column "${t.field}" threw; the values are treated as equal`,r),0}return typeof o!="number"||Number.isNaN(o)?(Wt(`sortComparator:${t.field}:nan`,`sortComparator for column "${t.field}" returned ${String(o)}; the values are treated as equal`,void 0),0):o}const Ka=e=>e.id;function ja(e,t,n,o=Ka){return t.length===0?e:Ko(e,t,(r,i)=>{const l=n?.byField.get(i.field),d=Le(r,i.field,l);return{value:d,type:l?.type,comparator:l?.sortComparator,params:l?.sortComparator?{id:o(r),field:i.field,row:r,value:d}:void 0}})}function Ko(e,t,n){if(t.length===0||e.length<2)return[...e];const o=t.map(l=>e.map(d=>n(d,l))),r=o.map(l=>l.map(({value:d,type:a})=>Vo(d,a))),i=e.map((l,d)=>d);return i.sort((l,d)=>{for(let a=0;a<t.length;a++){const u=o[a][l],g=o[a][d],h=u.comparator&&u.comparator===g.comparator&&u.params&&g.params?Si(u.comparator,u.params,g.params):_i(r[a][l],r[a][d]),w=zo(h,t[a].sort);if(w!==0)return w}return l-d}),i.map(l=>e[l])}function Ua(e,t,n){if(!n)return e.filter(r=>r.field!==t);const o=e.findIndex(r=>r.field===t);return o===-1?[...e,{field:t,sort:n}]:e.map((r,i)=>i===o?{field:t,sort:n}:r)}function jo(e,t={}){const n=new Map,o=[];for(const r of e)n.set(r.field,r),!(r.isSpacer||r.field.startsWith("__"))&&r.filterable!==!1&&t[r.field]!==!1&&o.push(r);return{byField:n,quickFilterColumns:o}}const Kt="__pivot_grand_total__",Ra="__pivot_row__:",ki=e=>`${Ra}${JSON.stringify(e.split(Ei))}`,qa="Grand Total",Ei="\0",jt="",Uo=`${jt}id`,Mi=e=>e==="id"?Uo:e,Ro={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1},Ni=e=>e.map(t=>String(t??"")).join(Ei),Ii=e=>e===void 0||e===""?null:e;function Xa(e,t){const n=e==null,o=t==null;return n||o?n===o?0:n?1:-1:typeof e=="number"&&typeof t=="number"?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():typeof e=="boolean"&&typeof t=="boolean"?Number(e)-Number(t):String(e).localeCompare(String(t),void 0,{numeric:!0})}function Ya(e,t){for(let n=0;n<e.length;n++){const o=Xa(e[n],t[n]);if(o!==0)return o}return 0}function Li(e,t){if(!e||e.length===0)return null;const n=Lt[t](e);return typeof n=="number"||n instanceof Date?n:null}const Ja=e=>"logicOperator"in e&&"items"in e,Za=e=>!!(e&&e.items&&e.items.length>0);function Qa(e,t){const n=l=>!t.has(l)&&l.includes(jt),o=l=>Ja(l)?l.items.length>0&&l.items.every(o):n(l.field),r=[],i=[];for(const l of e.items??[])(o(l)?i:r).push(l);return{source:{...e,items:r},output:{items:i,logicOperator:e.logicOperator}}}function Ai(e,t,n,o={}){const r=new Map(t.map(_=>[_.field,_])),i=_=>r.get(_)?.groupable!==!1,l=n.rowFields.filter(i),d=n.columnFields.filter(i),a=new Set,u=n.valueFields.filter(_=>{if(!Do(r.get(_.field),_.aggFn))return!1;const L=`${_.field}${jt}${_.aggFn}`;return a.has(L)?!1:(a.add(L),!0)});if(l.length===0||u.length===0)return Ro;const g=d.length>0,h=Array.from(new Set(u.map(_=>_.field))),w=(_,L)=>Le(_,L,r.get(L)),y=new Map,p=new Map(g?[]:[["",{values:[]}]]);for(const _ of e){const L=l.map(W=>w(_,W)),D=Ni(L);let v=y.get(D);v||(v={labels:L.map(Ii),sample:_,cells:new Map},y.set(D,v));const V=d.map(W=>w(_,W)),R=g?Ni(V):"",Q=p.get(R);Q?Q.sample||(Q.sample=_):p.set(R,{values:V.map(Ii),sample:_});let G=v.cells.get(R);G||(G=new Map,v.cells.set(R,G));for(const W of h){const H=w(_,W);if(Oo(H))continue;let ie=G.get(W);ie||(ie=[],G.set(W,ie)),ie.push(H)}}const f=Array.from(p.keys()).sort((_,L)=>Ya(p.get(_).values,p.get(L).values)),m=(_,L)=>g?`${_}${jt}${L.field}${jt}${L.aggFn}`:`${L.field}${jt}${L.aggFn}`,x=new Map;let b=[];for(const[_,L]of y){const D={id:ki(_)};l.forEach((v,V)=>{D[Mi(v)]=L.labels[V]}),D.id=ki(_);for(const v of f){const V=L.cells.get(v);for(const R of u)D[m(v,R)]=Li(V?.get(R.field),R.aggFn)}x.set(D.id,L),b.push({row:D,entry:L})}const C=_=>l.includes(_),E=_=>C(_)?r.get(_)?.type:"number",{outputFilterModel:k,sortModel:N}=o;if(Za(k)){const _=[];for(const D of f)for(const v of u)_.push({field:m(D,v),type:"number"});const L=Wn(k,jo(_));L&&(b=b.filter(({row:D})=>L(D)))}const M=(_,L)=>L==="id"&&C("id")?_[Uo]:_[L];N&&N.length>0&&(b=[...b].sort((_,L)=>{for(const D of N){const v=M(_.row,D.field),V=M(L.row,D.field),R=C(D.field)?r.get(D.field)?.sortComparator:void 0,Q=R?zo(Si(R,{id:_.row.id,field:D.field,row:_.row,value:v},{id:L.row.id,field:D.field,row:L.row,value:V}),D.sort):za(v,V,D.sort,E(D.field));if(Q!==0)return Q}return 0}));const S=b.map(_=>_.row);if(b.length>0){const _={id:Kt};l.forEach((L,D)=>{_[Mi(L)]=D===0?qa:""}),_.id=Kt;for(const L of f)for(const D of h){const v=[];for(const{entry:V}of b){const R=V.cells.get(L)?.get(D);if(R)for(const Q of R)v.push(Q)}for(const V of u)V.field===D&&(_[m(L,V)]=Li(v,V.aggFn))}S.push(_)}const F=b[0]?.entry.sample,I=_=>_===Kt?F:_===void 0?void 0:x.get(_)?.sample,A=l.map(_=>tc(_,r.get(_),I));for(const _ of f){const L=p.get(_),D=g?d.map((v,V)=>{const R=r.get(v),Q=ec(R,v,L.values[V],L.sample);return R?.headerName?`${R.headerName}: ${Q}`:Q}).join(" / "):"";for(const v of u){const V=r.get(v.field),R=v.headerName??V?.headerName??v.field;A.push({field:m(_,v),headerName:D?`${D} — ${R} (${v.aggFn})`:`${R} (${v.aggFn})`,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:Q,row:G})=>Bn(Q,v.aggFn,V,G)})}}return{pivotRows:S,pivotColumns:A,colKeys:f,isValid:!0}}function ec(e,t,n,o){const r=o?No(o,t,n,e):void 0;return r!==void 0?r:n==null?"":String(n)}function tc(e,t,n){const o={field:e,headerName:t?.headerName??e,width:t?.width??140,sortable:!0,hideable:!1};t&&(t.type!==void 0&&(o.type=t.type),t.align!==void 0&&(o.align=t.align),t.headerAlign!==void 0&&(o.headerAlign=t.headerAlign),t.description!==void 0&&(o.description=t.description),t.minWidth!==void 0&&(o.minWidth=t.minWidth),t.maxWidth!==void 0&&(o.maxWidth=t.maxWidth),t.valueOptions!==void 0&&(o.valueOptions=t.valueOptions)),e==="id"&&(o.valueGetter=({row:d})=>d[Uo]);const r=d=>d?.id===Kt,i=t?.valueFormatter;i&&(o.valueFormatter=({value:d,row:a})=>r(a)?String(d??""):i({value:d,row:n(a?.id)??a,field:e}));const l=t?.renderCell;return l&&(o.renderCell=d=>r(d.row)?d.formattedValue??String(d.value??""):l({...d,row:n(d.row.id)??d.row})),o}function Xe(e,t){return e===Kt||t?.get(e)?.isGroupRow===!0}const At="__reorder_col__",Pt="__expand_col__",Je="__checkbox_col__",Ze=e=>e===At||e===Pt||e===Je,qo=(e,t)=>e===t||e!==null&&t!==null&&e.id===t.id&&e.field===t.field&&!e.headerFilter==!t.headerFilter,nc=new Set(["checkbox","radio","button","submit","reset","image","file","color"]),oc=new Set(["textbox","searchbox","combobox","listbox","slider","spinbutton"]);function Pi(e){const t=e.tagName;if(t==="INPUT")return!nc.has(e.type);if(t==="TEXTAREA"||t==="SELECT"||e.isContentEditable||e.closest('[contenteditable]:not([contenteditable="false"])'))return!0;const n=e.getAttribute("role");return n!==null&&oc.has(n)}const Ti=e=>e!==null&&e.nodeType===1;function Fi(e,t){const n=e.closest(".ogx__detail-panel");if(n&&t.contains(n))return null;const o=e.closest('[role="gridcell"], [role="columnheader"]');return!o||o.closest(".ogx__viewport")!==t?null:o}function Vn(e,t){if(e===t)return"grid";if(!Ti(e)||!t.contains(e))return"foreign";const n=Fi(e,t);return n?n.classList.contains("ogx__cell--editing")?"editor":n===e?"grid":Pi(e)?"foreign":n.classList.contains("ogx__header-cell--checkbox")?"grid":"control":"foreign"}function rc(e,t,n,o){if(!Ti(e))return null;const r=Fi(e,t),i=r?.dataset.field;if(!r||!i)return null;if(r.getAttribute("role")==="columnheader"){const a=r.parentElement;return a?.classList.contains("ogx__header")?{id:null,field:i}:a?.classList.contains("ogx__header-filter-row")?{id:null,field:i,headerFilter:!0}:null}const l=Number(r.parentElement?.getAttribute("data-rowindex")),d=Number.isInteger(l)?n[l]:void 0;return d?{id:o(d),field:i,rowIndex:l}:null}function Oi(e,t){if(!e)return null;for(const n of Array.from(e.children))if(n.dataset.field===t)return n;return null}function Xo(e,t,n){if(t.id===null){const r=e.querySelector(`:scope > .ogx__content > .ogx__sticky-top > .ogx__header-wrap > ${t.headerFilter?".ogx__header-filter-row":".ogx__header"}`),i=Oi(r,t.field);return i&&t.field===Je?i.querySelector("input")??i:i}if(n<0)return null;const o=e.querySelector(`:scope > .ogx__content > .ogx__virtual-container > .ogx__rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-top > .ogx__pinned-rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-bottom > .ogx__pinned-rows > [data-rowindex="${n}"]`);return Oi(o,t.field)}const Di="__group__";function Ye(e){return!Ze(e)&&e!==Di}const wt=(e,t)=>e===t||!!e&&!!t&&e.id===t.id&&e.field===t.field;function ic(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>wt(n.anchor,t[o].anchor)&&wt(n.head,t[o].head))}function zn(e,t,n){const{rowIds:o,fields:r,rowIndexById:i,colIndexByField:l,spans:d}=n,a={top:e,bottom:e,left:t,right:t};if(!d)return a;const u=o[e],g=r[t],h=d.getSpanOrigin(u,g)??{rowId:u,field:g},w=i.get(h.rowId),y=l.get(h.field);if(w===void 0||y===void 0)return a;const p=Math.max(1,d.getRowSpan(h.rowId,h.field)),f=Math.max(1,d.getColSpan(h.rowId,h.field));return{top:w,bottom:Math.min(o.length-1,w+p-1),left:y,right:Math.min(r.length-1,y+f-1)}}function lc(e,t){if(!t.spans)return e;let{top:n,bottom:o,left:r,right:i}=e,l=!0;const d=a=>{a.top<n&&(n=a.top,l=!0),a.bottom>o&&(o=a.bottom,l=!0),a.left<r&&(r=a.left,l=!0),a.right>i&&(i=a.right,l=!0)};for(;l;){l=!1;for(let a=n;a<=o;a++)d(zn(a,r,t)),i!==r&&d(zn(a,i,t));for(let a=r+1;a<i;a++)d(zn(n,a,t)),o!==n&&d(zn(o,a,t))}return{top:n,bottom:o,left:r,right:i}}function Kn(e,t){const n=t.rowIndexById.get(e.anchor.id),o=t.rowIndexById.get(e.head.id),r=t.colIndexByField.get(e.anchor.field),i=t.colIndexByField.get(e.head.field);return n===void 0||o===void 0||r===void 0||i===void 0?null:{...lc({top:Math.min(n,o),bottom:Math.max(n,o),left:Math.min(r,i),right:Math.max(r,i)},t),anchorRow:n,anchorCol:r,headRow:o,headCol:i}}const Tt=e=>(e.bottom-e.top+1)*(e.right-e.left+1);function sc(e,t,n,o,r,i){const{headRow:l,headCol:d,anchorRow:a,anchorCol:u,top:g,bottom:h,left:w,right:y}=e;let p=l,f=d;switch(t){case"ArrowRight":f=d>=u?y+1:d+1;break;case"ArrowLeft":f=d<=u?w-1:d-1;break;case"ArrowDown":p=l>=a?h+1:l+1;break;case"ArrowUp":p=l<=a?g-1:l-1;break;case"Home":f=0,n&&(p=0);break;case"End":f=i,n&&(p=r);break;case"PageUp":p=l-o;break;case"PageDown":p=l+o;break;default:return null}return p=Math.min(Math.max(p,0),r),f=Math.min(Math.max(f,0),i),p===l&&f===d?null:{row:p,col:f}}function $i(e,t,n,o){const r=o&&o.row===t?o.col:void 0;if(!e||t<e.top||t>e.bottom)return r===void 0?null:{left:0,right:-1,isTop:!1,isBottom:!1,bottomOffset:0,fillHandleCol:r};const i={left:e.left,right:e.right,isTop:t===e.top,isBottom:t===e.bottom,bottomOffset:n?e.bottom-t:0};return r!==void 0&&(i.fillHandleCol=r),i}const ac=(e,t)=>e===t||!!e&&!!t&&e.left===t.left&&e.right===t.right&&e.isTop===t.isTop&&e.isBottom===t.isBottom&&e.bottomOffset===t.bottomOffset&&e.fillHandleCol===t.fillHandleCol,Yo=1,Gi=2,Hi=4,Bi=8,Wi=16,Vi=32;function cc(e,t,n,o){if(!e)return 0;const r=e.fillHandleCol===t?Vi:0,i=t+Math.max(1,n)-1;if(t<e.left||i>e.right)return r;let l=Yo|r;return e.isTop&&(l|=Gi),(e.isBottom||o>1&&o-1>=e.bottomOffset)&&(l|=Hi),t===e.left&&(l|=Bi),i===e.right&&(l|=Wi),l}function dc(e,t,n){const o=(r,i,l)=>`${r} ${r===1?i:l}`;return`${o(e,"cell","cells")} selected, ${o(t,"row","rows")} by ${o(n,"column","columns")}`}const uc=1e5,fc=e=>e.id,zi=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]);function gc(e,t,n,o,r){if(!e||n.length===0)return{cell:null,rowIndex:-1};const i=(n.find(u=>!Ze(u.field))??n[0]).field,l=n.some(u=>u.field===e.field)?e.field:i;if(e.id===null){const u=!!e.headerFilter&&r;return l===e.field&&u===!!e.headerFilter?{cell:e,rowIndex:-1}:{cell:u?{id:null,field:l,headerFilter:u}:{id:null,field:l},rowIndex:-1}}const d=e.rowIndex;let a=d!==void 0&&t[d]&&o(t[d])===e.id?d:t.findIndex(u=>o(u)===e.id);return a===-1?t.length===0?{cell:{id:null,field:l},rowIndex:-1}:(a=Math.min(Math.max(d??0,0),t.length-1),{cell:{id:o(t[a]),field:l,rowIndex:a},rowIndex:a}):{cell:l===e.field?e:{...e,field:l},rowIndex:a}}function pc(e){const{allRenderableRows:t,navigationColumns:n,checkboxSelection:o,selectedRowIds:r,handleSelectionChange:i,handleDetailPanelToggle:l,editingHandlers:d,setKeyboardMode:a,sortModel:u,handleSort:g,handleSortAdd:h,multiSort:w=!1,isCellEditable:y,pagination:p,pageSize:f,virtualization:m,viewportRef:x,pinnedTopRowCount:b=0,getRowId:C=fc,rowMetaMap:E,onRowActivate:k,toggleRowExpansion:N,handleSelectAll:M,rowSelectionEnabled:S=!0,multipleRowSelectionEnabled:F=!0,pinCheckboxColumn:I=!0,pinExpandColumn:A=!0,rowHeight:_,getSpanOrigin:L,cellSelection:D,headerFilters:v=!1}=e,[V,R]=s.useState(null),[Q,G]=s.useState(!1),W=s.useMemo(()=>gc(V,t,n,C,v),[V,t,n,C,v]),H=W.cell,ie=W.rowIndex,oe=s.useRef(!1),ue=s.useRef(!1),se=s.useRef(!1),U=s.useRef(null),te=s.useCallback($=>{ue.current=!0,$.focus({preventScroll:!0}),ue.current=!1},[]),ce=s.useCallback(()=>{const $=x.current;$&&!$.contains($.ownerDocument.activeElement)&&te($)},[x,te]),z=s.useMemo(()=>n.find($=>!Ze($.field))??n[0],[n]),re=s.useCallback(()=>{if(o)return{id:null,field:Je};if(!z)return null;const $=t[0];return $?{id:C($),field:z.field,rowIndex:0}:{id:null,field:z.field}},[o,z,t,C]),K=s.useCallback(($,O)=>{const P=x.current;if(!P)return;const{cumulativeHeights:T,pinnedBottomHeight:X,columnMetrics:B}=m;if($>=0&&Gn(P,$-b,T,X,_),Ze(O)){!(O===At||O===Pt&&A||O===Je&&I)&&P.scrollLeft>0&&(P.scrollLeft=0);return}if(!B)return;const{clientWidth:ee,scrollLeft:q}=P,{leftPinnedWidth:Y,rightPinnedWidth:ne,unpinnedAccWidths:me,unpinnedCols:j,totalSpecialsWidth:le,pinnedSpecialsWidth:we}=B,pe=j.findIndex(Ee=>Ee.field===O);if(pe===-1)return;const he=le+Y+(pe>0?me[pe-1]:0),Ce=le+Y+me[pe],be=q+we+Y,de=q+ee-ne;let ye=q;he<be?ye=Math.max(0,he-we-Y):Ce>de&&(ye=Ce-ee+ne),ye!==q&&(P.scrollLeft=ye)},[x,m,b,_,I,A]);s.useLayoutEffect(()=>{const $=x.current,O=!qo(U.current,H);if(U.current=H,!$||!H)return;const P=$.ownerDocument,T=P.activeElement;let X;if(T===$?X=!0:!T||T===P.body?X=oe.current:$.contains(T)?X=O:X=!1,!X)return;const B=Xo($,H,ie);B?B.contains(T)||B.focus({preventScroll:!0}):T!==$&&te($)});const J=s.useCallback(()=>{se.current=!0,a(!1)},[a]),ae=s.useCallback($=>{const O=$.currentTarget,P=$.relatedTarget,T=!(P instanceof Node&&O.contains(P)),X=se.current;if(se.current=!1,oe.current=!0,G(!0),ue.current)return;if($.target===O){if(!T)return;if(X||a(!0),H){const q=Xo(O,H,ie);q?q.focus({preventScroll:!0}):K(ie,H.field);return}const ee=re();ee&&(R(q=>q??ee),K(ee.rowIndex??-1,ee.field));return}const B=rc($.target,O,t,C);B&&!qo(B,H)&&R(B)},[H,ie,re,K,a,t,C]),fe=s.useCallback($=>{const O=$.relatedTarget;O instanceof Node&&$.currentTarget.contains(O)||(oe.current=!1,se.current=!1,G(!1),a(!1))},[a]),Z=s.useCallback($=>{const O=$.currentTarget,P=Vn($.target,O);if(P==="foreign"||(a(!0),$.nativeEvent?.isComposing||$.keyCode===229))return;const{key:T}=$,X=T===" "||T==="Spacebar",B=!!d.editingCell,ee=v?-2:-1,q=(ge,ve)=>{const ke=n[ve];!ke||ge<ee||ge>=t.length||(ge===ee?R({id:null,field:ke.field}):ge<0?R({id:null,field:ke.field,headerFilter:!0}):R({id:C(t[ge]),field:ke.field,rowIndex:ge}),K(ge,ke.field))};if(!H){if(!zi.has(T))return;const ge=re();if(!ge)return;$.preventDefault(),R(ge),K(ge.rowIndex??-1,ge.field);return}const{id:Y,field:ne}=H,me=Y===null&&!!H.headerFilter,j=Y!==null?ie:me?-1:ee,le=n.findIndex(ge=>ge.field===ne),we=n.filter(ge=>Ze(ge.field)).length,pe=ge=>Xe(ge,E),he=(ge,ve,ke)=>{const xe=n[ke];return Ze(xe.field)?!1:Fo({row:ge,field:xe.field,value:Le(ge,xe.field,xe),colDef:xe,rowIndex:ve,colIndex:ke-we,rowMeta:E?.get(C(ge))},y)},Ce=ge=>{let ve=j,ke=le;const xe=(t.length+1)*n.length;for(let je=0;je<xe;je++){if(ke+=ge,ke>=n.length?(ke=0,ve++):ke<0&&(ke=n.length-1,ve--),ve<0||ve>=t.length)return null;const nt=t[ve];if(!L?.(C(nt),n[ke].field)&&he(nt,ve,ke))return{r:ve,c:ke}}return null};if(B){if(T==="Enter")$.preventDefault(),d.stopCellEdit();else if(T==="Escape")$.preventDefault(),d.stopCellEdit({cancel:!0});else if(T==="Tab"&&Y!==null){const ge=Ce($.shiftKey?-1:1);ge&&($.preventDefault(),d.stopCellEdit(),q(ge.r,ge.c))}return}if(T==="Escape"&&D?.collapseSelection()){$.preventDefault();return}if(T==="Tab"||T==="Escape"||P==="control"&&(T==="Enter"||X))return;if(($.ctrlKey||$.metaKey)&&(T==="a"||T==="A")){if(D){D.selectAllCells()&&$.preventDefault();return}if(!S||!F||!M)return;$.preventDefault(),M(!0);return}if(me&&(T==="Enter"||X))return;if(Y===null){if(T==="Enter"||X){if($.preventDefault(),ne===Je){Xo(O,H,-1)?.click();return}const ge=n[le];if(!ge||Ze(ne)||ge.sortable===!1)return;const ve=u.find(xe=>xe.field===ne),ke=ve?ve.sort==="asc"?"desc":null:"asc";(w||$.shiftKey)&&h?h(ne,ke):g(ne,ke);return}}else if(T==="Enter"||X){$.preventDefault();const ge=t[j];if(ne===Je){i(Y,!r.has(Y));return}if(ne===Pt){$.shiftKey||l(Y);return}if(X){$.shiftKey&&S&&!pe(Y)&&i(Y,!r.has(Y));return}if(ne===At)return;if(he(ge,j,le)){d.startCellEdit({id:Y,field:ne,value:Le(ge,ne,n[le])});return}if(N&&E?.get(Y)?.hasChildren){N(Y);return}k?.({row:ge,id:Y,rowIndex:j});return}if($.altKey&&(T==="ArrowRight"||T==="ArrowLeft")&&N&&Y!==null){$.preventDefault();const ge=E?.get(Y);ge?.hasChildren&&!!ge.isExpanded!=(T==="ArrowRight")&&N(Y);return}if(!zi.has(T))return;$.preventDefault();const be=t.length-1,de=n.length-1,ye=$.ctrlKey||$.metaKey,Ee=p?f:10;if(D&&$.shiftKey&&Y!==null&&Ye(ne)&&D.extendSelection(T,ye,Ee,H))return;const Me=(ge,ve)=>{switch(T){case"ArrowRight":return ve+1>de?{r:ge+1,c:0}:{r:ge,c:ve+1};case"ArrowLeft":return ve-1<0?{r:ge-1,c:de}:{r:ge,c:ve-1};case"ArrowDown":return{r:ge+1,c:ve};case"ArrowUp":return{r:ge-1,c:ve};case"Home":return{r:ye?ee:ge,c:0};case"End":return{r:ye?be:ge,c:de};case"PageUp":return{r:Math.max(ee,ge-Ee),c:ve};default:return{r:Math.min(be,ge+Ee),c:ve}}},Ne=({r:ge,c:ve})=>ge>=ee&&ge<=be&&ve>=0&&ve<=de,Ie=({r:ge,c:ve})=>ge>=0?L?.(C(t[ge]),n[ve].field)??null:null;let Se=Me(j,le);if(T.startsWith("Arrow"))for(let ge=Ne(Se)?Ie(Se):null;ge&&ge.rowId===Y&&ge.field===ne;ge=Ne(Se)?Ie(Se):null)Se=Me(Se.r,Se.c);if(!Ne(Se))return;const Oe=Ie(Se);if(Oe){const ge=t.findIndex(ke=>C(ke)===Oe.rowId),ve=n.findIndex(ke=>ke.field===Oe.field);ge!==-1&&ve!==-1&&(Se={r:ge,c:ve})}Se.r===j&&Se.c===le||q(Se.r,Se.c)},[H,ie,t,n,d,r,i,l,a,u,g,h,w,y,p,f,E,k,N,M,S,F,re,K,L,C,D,v]);return{focusedCell:H,setFocusedCell:R,viewportTabIndex:Q?-1:0,ensureGridFocus:ce,handleFocus:ae,handleBlur:fe,handleKeyDown:Z,handleMouseDownCapture:J}}const Jo=[];function hc(e){const{isPivotActive:t}=e,n=t?Jo:e.rowGroupingModel,o=e.treeData&&!t,r=o&&e.hasTreeDataPath,i=n.length>0;return{rowReordering:e.rowReordering&&!t,hierarchyRowGroupingModel:n,isTreeDataRequested:o,isTreeData:r,isRowGrouping:i,isHierarchyEnabled:r||i,hasGroupingColumn:e.hasGroupingColDef&&(i||r),pagination:e.pagination&&!i&&e.paginationMode!=="infinite",listView:e.listView&&e.hasListViewColumn}}const mc=[],wc={rowFields:[],columnFields:[],valueFields:[]},Ki=100;function bc(e){return!e||e.length===0||e.includes(Ki)?Ki:e[0]}function xc(e){const{initialState:t,sortModel:n,onSortModelChange:o,filterModel:r,onFilterModelChange:i,aggregationModel:l,onAggregationModelChange:d,rowGroupingModel:a,onRowGroupingModelChange:u,columnVisibilityModel:g,onColumnVisibilityModelChange:h,pinnedColumns:w,onPinnedColumnsChange:y,pivotModel:p,onPivotModelChange:f,paginationModel:m,onPaginationModelChange:x,pageSizeOptions:b,rowSelectionModel:C,onRowSelectionModelChange:E,density:k,cellSelectionModel:N,onCellSelectionModelChange:M}=e,[S,F]=s.useState(()=>t?.sorting?.sortModel??[]),I=n!==void 0,A=I?n:S,_=s.useCallback(xe=>{I||F(xe),o?.(xe)},[I,o]),[L,D]=s.useState(()=>t?.filter?.filterModel??{items:[]}),v=r!=null,V=v?r:L,R=s.useCallback(xe=>{v||D(xe),i?.(xe)},[v,i]),Q=l!==void 0,[G,W]=s.useState(()=>l??{}),H=JSON.stringify(Q?l:G),ie=s.useMemo(()=>JSON.parse(H),[H]),oe=s.useCallback(xe=>{Q||W(xe),d?.(xe)},[Q,d]),ue=a!==void 0,[se,U]=s.useState(Jo),te=(ue?a:se)||Jo,ce=s.useCallback(xe=>{ue||U(xe),u?.(xe)},[ue,u]),z=g!==void 0,[re,K]=s.useState(()=>t?.columns?.columnVisibilityModel??{}),J=z?g:re,ae=s.useCallback(xe=>{z||K(xe),h?.(xe)},[z,h]),fe=w!==void 0,[Z,$]=s.useState(()=>t?.columns?.pinnedColumns??{}),O=fe?w:Z,P=s.useCallback(xe=>{fe||$(xe),y?.(xe)},[fe,y]),[T,X]=s.useState(()=>p??wc),B=p??T,ee=s.useCallback(xe=>{X(xe),f?.(xe)},[f]),q=m!==void 0,[Y,ne]=s.useState(()=>t?.pagination?.paginationModel??m??{page:0,pageSize:bc(b)}),me=q?m:Y,j=s.useCallback(xe=>{q||ne(xe),x?.(xe)},[q,x]),le=C!==void 0,[we,pe]=s.useState([]),he=le?C:we,Ce=s.useMemo(()=>new Set(he),[he]),be=s.useRef(null);s.useLayoutEffect(()=>{be.current=null});const de=s.useCallback(()=>be.current,[]),ye=s.useCallback(xe=>{be.current=xe,le||pe(xe),E?.(xe)},[le,E]),[Ee]=s.useState(()=>t?.density?.density??"standard"),Me=k??Ee,Ne=N!==void 0,[Ie,Se]=s.useState(mc),Oe=Ne?N:Ie,ge=s.useRef(null);s.useLayoutEffect(()=>{ge.current=null});const ve=s.useCallback(()=>ge.current,[]),ke=s.useCallback((xe,je)=>{ge.current=xe,Ne||Se(xe),M?.(xe,{reason:je})},[Ne,M]);return{sortModel:A,isSortControlled:I,setInternalSortModel:F,handleSortModelChange:_,filterModel:V,isFilterControlled:v,handleFilterModelChange:R,aggregationModel:ie,handleAggregationModelChange:oe,rowGroupingModel:te,handleRowGroupingModelChange:ce,columnVisibilityModel:J,handleColumnVisibilityModelChange:ae,pinnedColumns:O,handlePinnedColumnsChange:P,currentPivotModel:B,handlePivotModelChange:ee,effectivePaginationModel:me,handlePaginationModelChange:j,rowSelectionModel:he,selectedRowIds:Ce,isSelectionControlled:le,setInternalRowSelectionModel:pe,handleRowSelectionModelChange:ye,getPendingRowSelectionModel:de,density:Me,cellSelectionModel:Oe,handleCellSelectionModelChange:ke,getPendingCellSelectionModel:ve}}const ji=s.createContext(null),yc=52,Cc=56,vc=32,_c=72;function jn(e){if(e===void 0)return;const t=/^(\d+(?:\.\d+)?)(?:\s*px)?$/.exec(e.trim());if(!t)return;const n=Number(t[1]);return n>0?n:void 0}function Sc(e){const{rowHeight:t,headerHeight:n,density:o}=e,r=s.useContext(ji)?.grid;let i;return o==="compact"?i=jn(r?.rowHeightCompact)??vc:o==="comfortable"?i=jn(r?.rowHeightComfortable)??_c:i=t??jn(r?.rowHeightStandard)??yc,{rowHeight:i,headerHeight:n??jn(r?.headerHeight)??Cc}}function Un(e){return e>=1?Math.floor(e):1}function Zo(e,t){return Math.max(1,Math.ceil(Math.max(0,e)/Un(t)))}function kc(e){const{paginationMode:t,hasDataSource:n,dataSourceRowCount:o,rowCountProp:r,clientRowCount:i}=e;return t!=="server"?i:(n?o??r:r)??i}function Ui(e){return e?{paginationRowsPerPage:e.paginationRowsPerPage,paginationOf:e.paginationOf,paginationPage:e.paginationPage}:void 0}function Ri(e,t){return Number.isFinite(e)?Math.min(Math.max(0,Math.floor(e)),Math.max(0,t-1)):0}function Ec(e){const{effectiveRows:t,activeHierarchyHandlers:n,filterMode:o,filterModel:r,sortModel:i,sortingMode:l,pagination:d,paginationMode:a,effectivePaginationModel:u,pinnedRows:g,getRowId:h,columnLookup:w,hierarchyField:y}=e,p=s.useMemo(()=>n?n.getVisibleRows({labelField:y})||[]:o==="server"?t:Ho(t,r,w),[t,r,n,y,o,w]),f=s.useMemo(()=>n?o==="server"?t:Ho(t,r,w):p,[n,p,o,t,r,w]),{top:m,center:x,bottom:b}=s.useMemo(()=>n?{top:[],center:p,bottom:[]}:Ca(p,g,h),[p,g,n,h]),C=s.useMemo(()=>n||l==="server"?x:ja(x,i,w,h),[x,i,n,l,w,h]),E=d&&a!=="server",k=Un(u.pageSize),N=E?Ri(u.page,Zo(C.length,k)):u.page,M=s.useMemo(()=>{if(!E)return C;const F=N*k;return C.slice(F,F+k)},[C,E,N,k]),S=s.useMemo(()=>{const F=d?M:C;return[...m,...F,...b]},[m,M,C,b,d]);return{filteredRows:p,dataRows:f,pinnedTopRows:m,unpinnedRows:x,pinnedBottomRows:b,sortedUnpinnedRows:C,paginatedUnpinnedRows:M,currentPage:N,allRenderableRows:S}}const Qo=[33554400,17895e3,1e7,5e6],qi=new WeakMap;function Mc(e){const t=e.body;if(!t)return 1/0;const n=e.createElement("div");n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;top:0;left:-10000px;width:1px;visibility:hidden;pointer-events:none;",t.appendChild(n);try{if(n.style.height="100px",Math.abs(n.getBoundingClientRect().height-100)>1)return 1/0;for(const o of Qo)if(n.style.height=`${o}px`,Math.abs(n.getBoundingClientRect().height-o)<2)return o;return Qo[Qo.length-1]}finally{n.remove()}}function Nc(e){if(!e)return 1/0;const t=qi.get(e);if(t!==void 0)return t;const n=Mc(e);return qi.set(e,n),n}function Ic(e,t){if(!Number.isFinite(t))return e.length;let n=0,o=e.length;for(;n<o;){const r=n+o>>1;e[r]<=t?n=r+1:o=r}return n}function Lc(e){const[t,n]=s.useState(void 0);return s.useLayoutEffect(()=>{const o=Nc(e.current?.ownerDocument);n(r=>r===o?r:o)},[e]),t}function Ac(e){const{layout:t,scrollTop:n,scrollLeft:o,viewportWidth:r,viewportHeight:i,autoHeight:l,rowReordering:d,hasDetailPanel:a,checkboxSelection:u,pinCheckboxColumn:g,pinExpandColumn:h,overscanRows:w=5,maxContentHeight:y=1/0}=e;return s.useMemo(()=>{const{unpinnedAccWidths:p,unpinnedColsWithWidth:f,leftPinnedCols:m,rightPinnedCols:x,totalWidth:b,leftWidth:C,rightWidth:E,unpinnedTotalWidth:k,systemColumnsWidth:N,cumulativeHeights:M,pinnedTopHeight:S,pinnedBottomHeight:F,unpinnedRowsHeight:I,rowHeights:A,unpinnedRowsLength:_}=t,L=r||1e3,D=l?S+I+F+50:i||600,v=6,V=Math.max(0,o-C),R=o+L-C;let Q=0,G=f.length-1,W=0,H=p.length-1;for(;W<=H;){const $=W+H>>>1;p[$]<V?W=$+1:H=$-1}Q=Math.max(0,W-v);for(let $=Q;$<p.length;$++){if(($===0?0:p[$-1])>R){G=Math.min(f.length-1,$+v);break}G=Math.min(f.length-1,$+v)}const ie=Q>0?p[Q-1]:0,oe=k-p[G],ue=[...m,...ie>0?[{field:"__spacer_left__",width:ie,isSpacer:!0}]:[],...f.slice(Q,G+1),...oe>0?[{field:"__spacer_right__",width:oe,isSpacer:!0}]:[],...x],U=L>0&&b>L?16:0,te=S+I+F+U+2,ce=te-S-F,z=Number.isFinite(y)?Math.max(0,Math.min(ce,y-S-F)):ce;let re=0,K=_-1,J=0,ae=0,fe=M.length-1;for(;ae<=fe;){const $=ae+fe>>>1;M[$]<n?ae=$+1:fe=$-1}re=Math.max(0,ae-w),J=re>0?M[re-1]:0;for(let $=re;$<M.length;$++)if(M[$]>=n+D){K=Math.min(_-1,$+w);break}const Z=(d?48:0)+(a&&h?48:0)+(u&&g?48:0);return{renderContext:{firstRowIndex:re,lastRowIndex:K,firstColumnIndex:Q,lastColumnIndex:G},offsetTop:J,offsetLeft:0,totalHeight:te,virtualContainerHeight:z,pinnedTopHeight:S,pinnedBottomHeight:F,totalWidth:b,rowHeights:A,cumulativeHeights:M,virtualColumns:ue,columnMetrics:{leftPinnedWidth:C,rightPinnedWidth:E,unpinnedAccWidths:p,unpinnedCols:f,totalSpecialsWidth:N,pinnedSpecialsWidth:Z}}},[t,n,o,r,i,l,d,a,u,g,h,w,y])}const er="application/x-ogx-row",tr="application/x-ogx-column";function Xi(e,t,n){const o=e.dataTransfer;!o||typeof o.setData!="function"||(o.setData(t,n),o.setData("text/plain",n))}function Rn(e,t){const n=e.dataTransfer?.types;return n?Array.from(n).includes(t):!0}function Yi(e,t){if(!e||typeof e.addEventListener!="function")return()=>{};const n=()=>t();return e.addEventListener("dragend",n,{once:!0}),()=>e.removeEventListener("dragend",n)}function Pc(e){const{columns:t,onColumnOrderChange:n,disableColumnReorder:o=!1}=e,[r,i]=s.useState(null),[l,d]=s.useState(null),a=s.useRef(()=>{}),u=s.useCallback(()=>{a.current(),a.current=()=>{},i(null),d(null)},[]);s.useEffect(()=>()=>a.current(),[]);const g=s.useCallback(y=>p=>{if(!o){if(!t.some(f=>f.field===y)){p.preventDefault();return}a.current(),a.current=Yi(p.currentTarget,u),i(y),p.dataTransfer&&(p.dataTransfer.effectAllowed="move",Xi(p,tr,y))}},[t,o,u]),h=s.useCallback(y=>p=>{if(!(o||r===null)){if(!Rn(p,tr)){u();return}p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="move"),d(y)}},[r,o,u]),w=s.useCallback(y=>p=>{if(p.preventDefault(),o||r===null||!Rn(p,tr)){u();return}const f=t.findIndex(x=>x.field===r),m=t.findIndex(x=>x.field===y);u(),!(f===-1||m===-1||f===m)&&n?.({column:t[f],oldIndex:f,targetIndex:m})},[t,r,o,n,u]);return{draggedColumn:r,dragOverColumn:l,onDragStart:o?void 0:g,onDragOver:o?void 0:h,onDragEnd:o?void 0:u,onDrop:o?void 0:w}}function nr({isExpanded:e,onClick:t,variant:n="chevron",tabIndex:o}){return c.jsx("button",{className:`ogx-expand-icon ${e?"ogx-expand-icon--expanded":""}`,onClick:r=>{t&&t(r)},"aria-label":e?"Collapse row":"Expand row",type:"button",tabIndex:o,children:n==="plus-minus"?c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[c.jsx("path",{d:"M4 8H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M8 4V12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:e?0:1,transition:"opacity 0.2s ease",transformOrigin:"center"}})]}):c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{transform:e?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease"},children:c.jsx("path",{d:"M6 4L10 8L6 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function Tc({renderFn:e}){"use no memo";return c.jsx(c.Fragment,{children:e()})}function Fc(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>Object.is(n,t[o])):Object.is(e,t)}class Ft extends s.Component{constructor(t){super(t),this.state={hasError:!1,error:null,resetKey:t.resetKey}}static getDerivedStateFromProps(t,n){return Fc(t.resetKey,n.resetKey)?null:n.hasError?{hasError:!1,error:null,resetKey:t.resetKey}:{resetKey:t.resetKey}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){process.env.NODE_ENV!=="production"&&console.warn(`[CellErrorBoundary] field="${this.props.field}"`,t,n.componentStack)}render(){return this.state.hasError?c.jsx("div",{className:"ogx__cell-error",role:"img","aria-label":`Error in cell: ${this.props.field}`,title:this.state.error?.message??"Render error",children:"⚠"}):c.jsx(Tc,{renderFn:this.props.renderFn})}}function Oc(e,t,n){if(!t||!n)return{valueGetter:e.valueGetter,valueFormatter:e.valueFormatter};const o=l=>n.has(l.id),r=e.valueGetter,i=e.valueFormatter;return{valueGetter:r?l=>o(l.row)?l.value:r(l):void 0,valueFormatter:l=>o(l.row)?Bn(l.value,t,e,l.row):i?i(l):l.value==null?"":String(l.value)}}function Ji(e,t){if(!t)return e;const n=t.left??[],o=t.right??[],r=i=>{const l=ct(i.field,t);return l==="left"?n.indexOf(i.field)-n.length:l==="right"?1+o.indexOf(i.field):0};return[...e].sort((i,l)=>r(i)-r(l))}const qn=e=>e.formattedValue??e.value;function Zi(e,t,n){const o=e.renderCell;if(!o)return{useDefault:!0};const r=!!t.rowMeta?.isGroupRow;if(!n){const l=o(t);return r&&l===void 0?{useDefault:!0}:{useDefault:!1,content:l}}let i;try{i=o(t)}catch(l){return{useDefault:!1,content:c.jsx(Ft,{field:e.field,resetKey:t.row,renderFn:()=>{throw l}})}}return r&&i===void 0?{useDefault:!0}:{useDefault:!1,content:c.jsx(Ft,{field:e.field,resetKey:t.row,renderFn:()=>i})}}function Dc(e,t,n){const o=e.rowMeta;if(!o?.isGroupRow)return qn(e);if(o.isGroupFooter)return null;const r=o.descendantCount;if(t&&o.hasChildren){const i=o.groupLabel??`${o.groupingField}: ${String(o.groupingValue)}`;return c.jsxs("div",{className:"ogx__group-cell-content",children:[i,r!==void 0?` (${r})`:""]})}return n?c.jsxs("div",{className:"ogx__group-cell-content",children:[o.groupLabel,r!==void 0&&r>0?` (${r})`:""]}):qn(e)}const $c=e=>e.id;function Gc(e){const{activeColumns:t,isHierarchyEnabled:n,isRowGrouping:o,isTreeData:r,activeHierarchyHandlers:i,columnVisibilityModel:l,columnOrder:d,onColumnOrderChange:a,onColumnOrderModelChange:u,disableColumnReorder:g,pivotMode:h,checkboxSelection:w,hasDetailPanel:y,rowReordering:p,initialState:f,setColumns:m,pinnedColumns:x,getRowId:b=$c,aggregationModel:C,groupingRows:E}=e,k=s.useMemo(()=>t.map(K=>K.field),[t]),[N,M]=s.useState(()=>f?.columns?.columnOrder??null),S=h?k.join("\0"):"",[F,I]=s.useState(null),A=F&&F.key===S?F.order:k,L=h?A:d??(N??k),D=s.useCallback(K=>{if(h){I(J=>{const ae=J&&J.key===S?J.order:k;return{key:S,order:typeof K=="function"?K(ae):K}});return}M(J=>typeof K=="function"?K(J??k):K)},[h,S,k]),v=s.useCallback(K=>h&&K.hideable===!1||l[K.field]!==!1,[h,l]),V=s.useMemo(()=>{if(!n)return;const K=new Map(L.map((Z,$)=>[Z,$])),J=Z=>K.get(Z.field)??t.indexOf(Z),ae=[...t].sort((Z,$)=>J(Z)-J($));return(Ji(ae.filter(Z=>l[Z.field]!==!1),x)[0]??t[0])?.field},[n,L,t,l,x]),R=s.useMemo(()=>{if(!n)return t;const K=o?E:void 0;return t.map(J=>{const ae=Oc(J,C?.[J.field],K);return J.field===V?{...J,...ae,renderCell:fe=>{const Z=fe.rowMeta,$=Z?.treeDepth??0,O=!!Z?.hasChildren,P=!!Z?.isExpanded,T=Zi(J,fe,!0),X=T.useDefault?Dc(fe,o,r):T.content;return c.jsxs("div",{style:{display:"flex",alignItems:"center",paddingLeft:$*24,width:"100%",height:"100%"},children:[c.jsx("div",{style:{marginRight:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:O?"pointer":"default",flexShrink:0},children:O?c.jsx("div",{onClick:B=>{B.stopPropagation(),B.preventDefault(),i?.toggleExpansion(b(fe.row))},onMouseDown:B=>{B.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:c.jsx(nr,{isExpanded:P,tabIndex:-1,onClick:B=>{B.stopPropagation(),B.preventDefault(),i?.toggleExpansion(b(fe.row))}})}):null}),c.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:X})]})}}:{...J,...ae,renderCell:fe=>{const Z=fe.rowMeta;if(!Z?.isGroupRow)return J.renderCell?J.renderCell(fe):qn(fe);const $=Zi(J,fe,!1);return $.useDefault?J.field===Z.groupingField&&!Z.isGroupFooter||fe.value==null?null:qn(fe):$.content}}})},[t,n,o,r,i,V,b,C,E]),[Q,G]=s.useState(()=>f?.columns?.columnWidths??{}),W=s.useCallback((K,J)=>{G(ae=>({...ae,[K]:J}))},[]);s.useEffect(()=>{m(t)},[t,m]);const H=s.useMemo(()=>{const K=new Map(L.map((J,ae)=>[J,ae]));return[...R].sort((J,ae)=>{const fe=K.get(J.field)??R.indexOf(J),Z=K.get(ae.field)??R.indexOf(ae);return fe-Z})},[R,L]),ie=s.useMemo(()=>H.filter(v),[H,v]),oe=s.useCallback((K,J)=>{(h||!d)&&D(K),J&&a?.(J),h||u?.(K)},[h,d,D,a,u]),ue=s.useCallback((K,J)=>{const ae=H.map(Z=>Z.field),[fe]=ae.splice(K,1);ae.splice(J,0,fe),oe(ae,{column:H[K],oldIndex:K,targetIndex:J})},[H,oe]),se=Pc({columns:H,onColumnOrderChange:s.useCallback(({oldIndex:K,targetIndex:J})=>ue(K,J),[ue]),disableColumnReorder:g}),U=s.useCallback((K,J)=>{const ae=H.findIndex(Z=>Z.field===K),fe=H.findIndex(Z=>Z.field===J);ae===-1||fe===-1||ae===fe||ue(ae,fe)},[H,ue]),te=s.useCallback(()=>{oe(k)},[oe,k]),ce=s.useMemo(()=>Ji(ie,x),[ie,x]),z=s.useMemo(()=>{const K=[];return p&&K.push({field:At,sortable:!1,editable:!1}),y&&K.push({field:Pt,sortable:!1,editable:!1}),w&&K.push({field:Je,sortable:!1,editable:!1}),[...K,...ce]},[ce,w,y,p]),re=s.useMemo(()=>new Map(ce.map((K,J)=>[K.field,J])),[ce]);return{effectiveColumns:R,hierarchyField:V,orderedColumns:H,visibleOrderedColumns:ie,renderOrderedColumns:ce,navigationColumns:z,columnIndexMap:re,columnWidths:Q,effectiveColumnOrder:L,setInternalColumnOrder:D,columnReorderHandlers:se,moveColumn:U,resetColumnOrder:te,handleColumnResize:W}}const Hc=e=>e.id;function Bc(e){const{renderContext:t,pinnedTopRows:n,pinnedBottomRows:o,paginatedUnpinnedRows:r,sortedUnpinnedRows:i,pagination:l,getRowId:d=Hc}=e;return s.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:u}=t,g=l?r:i,h=n.length,w=n.map((C,E)=>({row:C,id:d(C),rowIndex:E,pinned:"top"})),y=o.map((C,E)=>({row:C,id:d(C),rowIndex:h+g.length+E,pinned:"bottom"})),p=Math.max(0,a),f=Math.min(g.length,u+1),m=g.slice(p,f).map((C,E)=>({row:C,id:d(C),rowIndex:h+p+E})),x=[...w,...m,...y],b=new Set;return x.filter(C=>b.has(C.id)?!1:(b.add(C.id),!0))},[t,n,o,r,i,l,d])}const Wc=100;function Qi(e){const{scrollTop:t,scrollHeight:n,clientHeight:o}=e;return n-t-o>=Wc?null:{visibleTop:t,visibleBottom:t+o,viewportHeight:o}}function Vc(e){return e<.5?3:e<3?5:e<15?12:e<40?20:30}function zc(e){const{onRowsScrollEnd:t,overscanRowCount:n=3,rowCount:o=0,autoHeight:r=!1}=e,i=s.useRef({scrollTop:0,scrollLeft:0,velocity:0}),l=s.useRef({scrollTop:0,scrollLeft:0,time:0}),d=s.useRef(null),a=s.useRef(null),u=s.useRef(null),g=s.useRef(!0),h=s.useRef(t),[w,y]=s.useState({scrollTop:0,scrollLeft:0,velocityOverscan:0});s.useEffect(()=>{h.current=t},[t]),s.useEffect(()=>()=>{d.current!==null&&cancelAnimationFrame(d.current),a.current!==null&&clearTimeout(a.current)},[]);const p=s.useCallback(x=>{const b=Qi(x);if(!b){g.current=!0;return}if(!g.current)return;const C=h.current;C&&(g.current=!1,C(b))},[]),f=s.useCallback(x=>{const b=x.currentTarget,C=performance.now(),E=Math.abs(b.scrollTop-l.current.scrollTop)+Math.abs(b.scrollLeft-l.current.scrollLeft),k=C-l.current.time,N=k>0?E/k:0,M=b.scrollTop!==l.current.scrollTop;l.current={scrollTop:b.scrollTop,scrollLeft:b.scrollLeft,time:C},i.current={scrollTop:b.scrollTop,scrollLeft:b.scrollLeft,velocity:N},d.current!==null&&cancelAnimationFrame(d.current),d.current=requestAnimationFrame(()=>{d.current=null;const{scrollTop:S,scrollLeft:F,velocity:I}=i.current;y({scrollTop:S,scrollLeft:F,velocityOverscan:Vc(I)})}),a.current!==null&&clearTimeout(a.current),a.current=setTimeout(()=>{a.current=null,y(S=>S.velocityOverscan===0?S:{...S,velocityOverscan:0})},200),M&&p(b)},[p]);s.useEffect(()=>{g.current=!0;const x=u.current;!x||r||o<=0||x.clientHeight===0||p(x)},[o,r,p]);const m=s.useCallback(x=>{if(u.current=x,!x)return;const{scrollTop:b,scrollLeft:C}=i.current;if(b===0&&C===0)return;x.scrollTop=b,x.scrollLeft=C;const E={scrollTop:x.scrollTop,scrollLeft:x.scrollLeft};(E.scrollTop!==b||E.scrollLeft!==C)&&(i.current={...i.current,...E},l.current={...l.current,...E},y(k=>({...k,...E})))},[]);return{scrollTop:w.scrollTop,scrollLeft:w.scrollLeft,overscanRows:Math.max(w.velocityOverscan,n),handleScroll:f,attachViewport:m}}function Kc(e){const t=s.useRef(null);return s.useCallback(n=>{if(t.current?.disconnect(),t.current=null,!n||typeof ResizeObserver>"u")return;const o=new ResizeObserver(r=>{for(const i of r){const{width:l,height:d}=i.contentRect;e(l,d)}});o.observe(n),t.current=o},[e])}function jc(e){const{setDimensions:t,viewportRef:n,...o}=e,{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:d,attachViewport:a}=zc(o),u=Kc(t),g=s.useCallback(h=>{n.current=h,u(h),a(h)},[n,u,a]);return{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:d,setViewportElement:g}}function Uc(){const[e,t]=s.useState(()=>new Map),n=s.useCallback((o,r)=>{t(i=>{if(i.get(o)===r)return i;const l=new Map(i);return l.set(o,r),l})},[]);return{detailPanelHeights:e,reportDetailPanelHeight:n}}function Rc(e){const{hasDetailPanel:t,controlledExpandedRowIds:n,onDetailPanelExpandedRowIdsChange:o,rowMetaMap:r}=e,[i,l]=s.useState(new Set),d=n??i,a=s.useMemo(()=>Ea(d,r),[d,r]),u=s.useCallback(w=>{if(r.get(w)?.isGroupRow)return;const y=new Set(d);y.has(w)?y.delete(w):y.add(w),n===void 0&&l(y),o?.(y)},[d,r,n,o]),{detailPanelHeights:g,reportDetailPanelHeight:h}=Uc();return{hasDetailPanel:t,expandedRowIds:a,handleDetailPanelToggle:u,detailPanelHeights:g,reportDetailPanelHeight:h}}const qc=new Set(["__group__"]),wn=e=>!qc.has(e);function el(e){return Object.keys(e).every(wn)?e:Object.fromEntries(Object.entries(e).filter(([n])=>wn(n)))}function Xc(e){const t={...e};return e.left&&(t.left=e.left.filter(wn)),e.right&&(t.right=e.right.filter(wn)),t}function Yc(e){const{onStateChange:t,sortModel:n,filterModel:o,effectivePaginationModel:r,columnWidths:i,effectiveColumnOrder:l,columnVisibilityModel:d,pinnedColumns:a,density:u}=e,g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t});const h=s.useRef(null);s.useEffect(()=>{if(!g.current)return;const w={sorting:{sortModel:n},filter:{filterModel:o},pagination:{paginationModel:r},columns:{columnWidths:el(i),columnOrder:l.filter(wn),columnVisibilityModel:el(d),pinnedColumns:Xc(a)},density:{density:u}},y=JSON.stringify(w);y!==h.current&&(h.current=y,g.current(w))},[n,o,r,i,l,d,a,u])}const Jc=200,Zc=2e3,Qc=178e5;function ed(e){const{paginationRequested:t,isRowGrouping:n,autoHeight:o,viewportHeight:r,renderedRowCount:i,totalRowCount:l,pinnedRowsIgnored:d=!1,scrollHeight:a=0,maxContentHeight:u,reachableRowCount:g,unpinnedRowCount:h,listViewWithoutColumn:w=!1,listViewRowCount:y=0}=e,p=s.useRef(!1),f=s.useRef(!1),m=s.useRef(!1),x=s.useRef(!1),b=s.useRef(!1),C=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||C.current||y<=Zc||(C.current=!0,console.warn(`[OpenGridX] The list view is rendering all ${y} items: it does not virtualize. Above a few thousand items use \`pagination\`, server-side loading, or the grid view. See docs/features/list-view.md.`))},[y]),s.useEffect(()=>{process.env.NODE_ENV==="production"||b.current||!w||(b.current=!0,console.warn("[OpenGridX] `listView` is set without a `listViewColumn`, so the grid view is shown instead. Pass `listViewColumn` to render list items. See docs/features/list-view.md."))},[w]),s.useEffect(()=>{process.env.NODE_ENV==="production"||m.current||!d||(m.current=!0,console.warn("[OpenGridX] `pinnedRows` is ignored while treeData or rowGroupingModel is active: the rows stay in their place in the hierarchy. See docs/features/pinning.md."))},[d]),s.useEffect(()=>{if(process.env.NODE_ENV==="production"||x.current||u===void 0)return;const E=Number.isFinite(u);if(E?a<=u:a<=Qc)return;x.current=!0;const k=E&&g!==void 0&&h!==void 0?`Only the first ${g.toLocaleString("en-US")} of ${h.toLocaleString("en-US")} rows can be scrolled to in this browser. `:"The last rows may not be reachable by scrolling. ";console.warn(`[OpenGridX] The grid content is ${Math.round(a)}px tall, more than this browser lays out (about 17.9M px in Firefox, 33.5M px in Chrome and Safari). `+k+"Use pagination, server-side or infinite loading, or a smaller rowHeight. See docs/features/virtualization.md.")},[a,u,g,h]),s.useEffect(()=>{process.env.NODE_ENV==="production"||p.current||t&&n&&(p.current=!0,console.warn("[OpenGridX] `pagination` is ignored while `rowGroupingModel` is active — all group rows render in one scrollable view. Give the grid a bounded height so it virtualizes. See docs/features/tree-data-grouping.md."))},[t,n]),s.useEffect(()=>{process.env.NODE_ENV==="production"||f.current||o||r>0&&l>Jc&&i>=l&&r>=a&&(f.current=!0,console.warn(`[OpenGridX] The grid viewport is ${Math.round(r)}px tall and is rendering all ${l} rows, so row virtualization is effectively off: the grid fills its container, and the container grows to fit every row. Give the container a definite height (for example \`height: 600px\` or \`100vh\`). If the container, or any ancestor up to the sized one, is a flex or grid item, add \`min-height: 0\` to it. Alternatively pass a \`height\` prop, or \`autoHeight\` if rendering every row is intended. See docs/features/virtualization.md.`))},[o,r,i,l,a])}function td(e){return typeof window>"u"||typeof window.getComputedStyle!="function"||typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent)?!1:window.getComputedStyle(e).display!=="flex"}let tl=!1;function nd(e){s.useEffect(()=>{if(process.env.NODE_ENV==="production"||tl)return;const t=e.current;!t||!td(t)||(tl=!0,console.warn("[OpenGridX] The grid stylesheet is not loaded, so the grid is unstyled and renders every row (its viewport does not scroll). Add `import '@opencorestack/opengridx/styles'` once in your app root. See README.md, Getting Started."))},[e])}function Xn(e,t,n,o){if(n&&o)return t.length>0?[t[t.length-1]]:Array.from(e);const r=new Set(e);return t.forEach(i=>n?r.add(i):r.delete(i)),Array.from(r)}function od(e,t,n){return n?e.has(t)?[]:[t]:Xn(e,[t],!e.has(t),!1)}function nl(e,t){return t.length===e.size&&t.every(n=>e.has(n))}function rd(e){const{selectedRowIds:t,onSelectionModelChange:n,disableMultipleRowSelection:o,selectableRowIds:r}=e,i=s.useCallback(h=>{nl(t,h)||n(h)},[t,n]),l=s.useCallback((h,w)=>{i(Xn(t,[h],w,o))},[i,t,o]),d=s.useCallback(h=>{i(od(t,h,o))},[i,t,o]),a=s.useCallback(h=>{i(Xn(t,r,h,!1))},[i,t,r]),{allSelected:u,someSelected:g}=s.useMemo(()=>{let h=0;for(const y of r)t.has(y)&&h++;const w=r.length>0&&h===r.length;return{allSelected:w,someSelected:!w&&h>0}},[r,t]);return{toggleRow:l,clickRow:d,selectAll:o?void 0:a,allSelected:u,someSelected:g}}function id(e){const{dataRows:t,getRowId:n,isPivotActive:o,selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,disableRowSelectionOnClick:d,isHierarchyEnabled:a,rowMetaMap:u,activeHierarchyHandlers:g,onRowClick:h}=e,w=s.useMemo(()=>{const b=t.map(n);return o?b.filter(C=>C!==Kt):b},[t,n,o]),y=rd({selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,selectableRowIds:w}),{clickRow:p,toggleRow:f}=y,m=s.useCallback(b=>{const{id:C}=b,E=a?u.get(C):void 0;if(E?.isGroupRow){E.hasChildren&&g?.toggleExpansion(C);return}h?.(b),!d&&!Xe(C,u)&&p(C)},[a,g,h,u,d,p]),x=s.useCallback((b,C)=>{Xe(b,u)||f(b,C)},[u,f]);return{rowSelection:y,handleRowClick:m,handleSelectionChange:x}}const ol=e=>JSON.stringify(Array.from(e,t=>typeof t=="number"?["n",t]:["s",t]));function ld(e){const{selectedRowIds:t,rowsLookup:n,rowMetaMap:o,enabled:r,onSelectionModelChange:i}=e,l=s.useMemo(()=>{if(!r||t.size===0)return t;let u=!1;const g=new Set;for(const h of t)n.has(h)||o.has(h)?g.add(h):u=!0;return u?g:t},[r,t,n,o]),d=s.useRef(i);s.useLayoutEffect(()=>{d.current=i});const a=s.useRef(null);return s.useEffect(()=>{if(l===t){a.current=null;return}const u=`${ol(t)}|${ol(l)}`;a.current!==u&&(a.current=u,d.current(Array.from(l)))},[l,t]),l}function or(e,t,n,o){return o?Ua(e,t,n):n?[{field:t,sort:n}]:e.filter(r=>r.field!==t)}function sd(e){const{sortModel:t,onSortModelChange:n}=e,o=s.useCallback((i,l)=>{n(or(t,i,l,!1))},[t,n]),r=s.useCallback((i,l)=>{n(or(t,i,l,!0))},[t,n]);return{handleSort:o,handleSortAdd:r}}function ad(e){const{columnVisibilityModel:t,onColumnVisibilityModelChange:n,pinnedColumns:o,onPinnedColumnsChange:r}=e,i=s.useRef({columnVisibilityModel:t,pinnedColumns:o});s.useLayoutEffect(()=>{i.current={columnVisibilityModel:t,pinnedColumns:o}});const l=s.useCallback(a=>{const u={...i.current.columnVisibilityModel,[a]:!1};i.current={...i.current,columnVisibilityModel:u},n(u)},[n]),d=s.useCallback((a,u)=>{const g=va(i.current.pinnedColumns,a,u);i.current={...i.current,pinnedColumns:g},r(g)},[r]);return{handleHideColumn:l,handlePinColumn:d}}function cd(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=t.current,r=()=>n.current;o.getSortModel=()=>r().sortModel,o.sortColumn=(a,u)=>{const{sortModel:g,multiSort:h,onSortModelChange:w}=r(),y=or(g,a,u,h);n.current={...r(),sortModel:y},w(y)},o.getFilterModel=()=>r().filterModel,o.setFilterModel=a=>{n.current={...r(),filterModel:a},r().onFilterModelChange(a)};const i=a=>{n.current={...r(),paginationModel:a},r().onPaginationModelChange(a)};o.setPage=a=>i({...r().paginationModel,page:a}),o.setPageSize=a=>i({...r().paginationModel,pageSize:a,page:0});const l=()=>{const a=r().getPendingRowSelectionModel?.();return a?new Set(a):r().selectedRowIds},d=(a,u)=>{const{disableMultipleRowSelection:g,onRowSelectionModelChange:h,isSyntheticRowId:w}=r(),y=w?a.filter(m=>!w(m)):a;if(y.length===0)return;const p=l(),f=Xn(p,y,u,g);nl(p,f)||(n.current={...r(),selectedRowIds:new Set(f)},h(f))};o.getSelectedRows=()=>Array.from(l()),o.selectRow=(a,u=!0)=>d([a],u),o.selectRows=(a,u=!0)=>d(a,u),o.getVisibleRows=()=>r().getVisibleRows(),o.getAllFilteredRows=()=>r().getAllFilteredRows(),o.getVisibleColumns=()=>r().visibleColumns,o.setSortModel=a=>{n.current={...r(),sortModel:a},r().onSortModelChange(a)},o.setRowGroupingModel=a=>{n.current={...r(),rowGroupingModel:a},r().onRowGroupingModelChange(a)},o.setAggregationModel=a=>{n.current={...r(),aggregationModel:a},r().onAggregationModelChange(a)},o.setColumnVisibilityModel=a=>{n.current={...r(),columnVisibilityModel:a},r().onColumnVisibilityModelChange(a)},o.setPivotModel=a=>{n.current={...r(),pivotModel:a},r().onPivotModelChange(a)},o.getGridAiState=()=>{const{filterModel:a,sortModel:u,rowGroupingModel:g,aggregationModel:h,pivotModel:w,columnVisibilityModel:y}=r();return{filterModel:a,sortModel:u,rowGroupingModel:g,aggregationModel:h,pivotModel:w,columnVisibilityModel:y}}},[t])}const rl="\0";function dd(e,t){const n=e.filter(o=>t[o.field]===!1).map(o=>o.field).join(rl);return s.useMemo(()=>{const o={};if(n)for(const r of n.split(rl))o[r]=!1;return jo(e,o)},[e,n])}function ud({paginationModel:e,currentPage:t,enabled:n,onPaginationModelChange:o}){const r=s.useRef({paginationModel:e,onPaginationModelChange:o});s.useLayoutEffect(()=>{r.current={paginationModel:e,onPaginationModelChange:o}});const i=e.page,l=s.useRef(null);s.useEffect(()=>{if(!n)return;if(t===i){l.current=null;return}const d=`${i}>${t}`;if(l.current===d)return;l.current=d;const{paginationModel:a,onPaginationModelChange:u}=r.current;u({...a,page:t})},[n,t,i])}function fd(){const[e,t]=s.useState(!1),[n,o]=s.useState(!1),r=s.useRef(null),i=s.useRef(0),[l,d]=s.useState(0),[a,u]=s.useState(!1),g=s.useMemo(()=>({registerColumnsPanel:()=>(i.current+=1,()=>{i.current-=1}),registerFiltersPanel:()=>(d(m=>m+1),()=>d(m=>m-1))}),[]),h=s.useCallback(()=>u(!0),[]),w=s.useCallback(()=>u(!1),[]),y=s.useCallback(()=>{i.current>0?t(!0):o(!0)},[]),p=s.useCallback(()=>t(!1),[]),f=s.useCallback(()=>o(!1),[]);return s.useEffect(()=>{if(!n)return;function m(b){r.current&&!r.current.contains(b.target)&&o(!1)}function x(b){b.key==="Escape"&&o(!1)}return document.addEventListener("mousedown",m),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",x)}},[n]),{toolbarHost:g,toolbarPanelRequested:e,closeToolbarPanel:p,standalonePanelOpen:n,closeStandalonePanel:f,standalonePanelRef:r,openColumnsPanel:y,toolbarFiltersRequested:a,closeToolbarFiltersPanel:w,openFiltersPanel:l>0?h:void 0}}const il=s.createContext(null);function gd(e){if(typeof e!="function")return!1;const t=e.prototype;return!(typeof t=="object"&&t!==null&&"isReactComponent"in t)}function pd({render:e,toolbarProps:t}){"use no memo";return c.jsx(c.Fragment,{children:e(t)})}function hd({component:e,toolbarProps:t}){if(gd(e))return c.jsx(pd,{render:e,toolbarProps:t},`fn:${e.toString()}`);const n=e;return c.jsx(n,{...t})}const ll=48;function md({columns:e,aggregationModel:t,aggregationResult:n,columnWidths:o,rowHeight:r,checkboxSelection:i,hasDetailPanel:l,rowReordering:d,pinCheckboxColumn:a=!0,pinExpandColumn:u=!0,pinnedColumns:g,loading:h=!1}){const w=s.useMemo(()=>Eo(e,o,g,i,a,l,u,d),[e,o,g,i,a,l,u,d]),{lastLeft:y,firstRight:p}=s.useMemo(()=>Mo(e,g),[e,g]),f=d?ll:0,m=f+(l&&u?ll:0),x=(b,C,E)=>c.jsx("div",{className:`ogx__aggregation-spacer${C?" ogx__aggregation-spacer--pinned":""}`,style:C?{left:E}:void 0,"aria-hidden":"true"},b);return c.jsxs("div",{className:`ogx__aggregation-footer${h?" ogx__aggregation-footer--loading":""}`,role:"row","aria-label":"Aggregation totals","aria-live":"polite","aria-busy":h||void 0,style:{minHeight:`${r}px`},children:[d&&x("__reorder_col__",!0,0),l&&x("__expand_col__",u,f),i&&x("__checkbox_col__",a,m),e.map(b=>{if(b.isSpacer){const A=typeof b.width=="number"?b.width:0;return c.jsx("div",{style:{width:A,minWidth:A,flexShrink:0},"aria-hidden":"true"},b.field)}const C=t[b.field],E=C&&Do(b,C)?C:void 0,k=n[b.field],N=Nt(b,o,120),M=ct(b.field,g),S=M?w[b.field]:void 0,F=["ogx__aggregation-cell",M==="left"&&"ogx__aggregation-cell--pinned-left",M==="right"&&"ogx__aggregation-cell--pinned-right",M==="left"&&b.field===y&&"ogx__aggregation-cell--pinned-left-last",M==="right"&&b.field===p&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),I={width:N,minWidth:N,maxWidth:N,textAlign:b.align||"left"};return M==="left"&&S!==void 0&&(I.left=S),M==="right"&&S!==void 0&&(I.right=S),c.jsx("div",{className:F,role:"gridcell",style:I,children:E?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"ogx__aggregation-label",children:E}),c.jsx("span",{className:"ogx__aggregation-value",children:Bn(k,E,b,n)})]}):null},b.field)})]})}function wd({noRowsLabel:e,width:t,overlay:n}){return n?c.jsx("div",{className:"ogx__empty",style:{width:t},children:n}):c.jsxs("div",{className:"ogx__empty",style:{width:t},children:[c.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),c.jsx("path",{d:"M3 9h18M9 21V9"})]}),c.jsx("span",{children:e})]})}function sl({dataSource:e,paginationMode:t,sortingMode:n,filterMode:o}){return!!e&&(t==="server"||t==="infinite"||n==="server"||o==="server")}const al=Number.MAX_SAFE_INTEGER,bd="An unexpected error occurred while loading the data.";function cl(e){return typeof e=="string"&&e?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"&&e.message?e.message:bd}function xd({error:e,onRetry:t}){if(!e)return null;const n=cl(e);return c.jsxs("div",{className:"ogx-error-overlay","aria-live":"assertive",role:"alert",children:[c.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 24 24",fill:"none",stroke:"var(--ogx-color-error)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),c.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),c.jsx("div",{className:"ogx-error-overlay__title",children:"Oops! Something went wrong"}),c.jsx("div",{className:"ogx-error-overlay__message",children:n}),t&&c.jsx("button",{type:"button",onClick:t,className:"ogx-button ogx-button--primary",children:"Retry"})]})}function dl(e,t){typeof e=="function"?e(t):e&&(e.current=t)}const bt=s.forwardRef(function({indeterminate:t=!1,label:n,className:o="",inputClassName:r="",inputRef:i,...l},d){const a=s.useRef(null),u=s.useCallback(h=>{a.current=h,dl(i,h),dl(d,h)},[i,d]);s.useEffect(()=>{a.current&&(a.current.indeterminate=t)},[t]);const g=["ogx-checkbox-wrapper",l.disabled&&"ogx-checkbox-wrapper--disabled",o].filter(Boolean).join(" ");return c.jsxs("label",{className:g,children:[c.jsx("input",{ref:u,type:"checkbox",className:["ogx-checkbox__input",r].filter(Boolean).join(" "),...l}),c.jsxs("span",{className:"ogx-checkbox__box",children:[l.checked&&!t&&c.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),t&&c.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{d:"M19 13H5v-2h14v2z"})})]}),n&&c.jsx("span",{className:"ogx-checkbox__label",children:n})]})});bt.displayName="Checkbox";const ul=50;function rr(e,t,n,o){const r=Math.min(n??ul,t),i=Math.max(o??1/0,t);return Math.max(r,Math.min(i,e))}const yd=16;function Cd(e){e.preventDefault(),e.stopPropagation()}function vd(){const e=t=>{t.stopPropagation(),t.preventDefault()};window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}),0)}function _d(e){const{field:t,currentWidth:n,onResize:o,onAutosize:r,minWidth:i,maxWidth:l,edge:d="end"}=e,[a,u]=s.useState(!1),g=s.useRef(null);s.useEffect(()=>()=>{g.current=null},[]);const h=s.useCallback((b,C)=>{const E=C-b.startX,k=b.startWidth+(d==="start"?-E:E);return rr(k,b.startWidth,i,l)},[d,i,l]),w=s.useCallback(b=>{if(b.button===0){b.stopPropagation(),g.current={pointerId:b.pointerId,startX:b.clientX,startWidth:n,lastUpdate:0,moved:!1},u(!0);try{b.currentTarget.setPointerCapture(b.pointerId)}catch{}}},[n]),y=s.useCallback(b=>{const C=g.current;if(!C||b.pointerId!==C.pointerId||(b.clientX!==C.startX&&(C.moved=!0),!C.moved))return;const E=Date.now();E-C.lastUpdate>=yd&&(C.lastUpdate=E,o(t,h(C,b.clientX)))},[t,o,h]),p=s.useCallback((b,C)=>{const E=g.current;!E||b.pointerId!==E.pointerId||(g.current=null,u(!1),(E.moved||b.clientX!==E.startX)&&(vd(),C&&o(t,h(E,b.clientX))))},[t,o,h]),f=s.useCallback(b=>{if(b.key==="Enter"&&r){b.preventDefault(),b.stopPropagation(),r(t);return}if(b.key!=="ArrowLeft"&&b.key!=="ArrowRight")return;b.preventDefault(),b.stopPropagation();const C=(b.shiftKey?50:10)*(b.key==="ArrowRight"?1:-1);o(t,rr(n+C,n,i,l))},[t,n,o,r,i,l]),m=s.useCallback(b=>{b.preventDefault(),b.stopPropagation(),r?.(t)},[t,r]),x=["ogx-column-resize-handle",d==="start"&&"ogx-column-resize-handle--start",a&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return c.jsx("div",{className:x,onPointerDown:w,onMouseDown:Cd,onPointerMove:y,onPointerUp:b=>p(b,!0),onPointerCancel:b=>p(b,!1),onClick:b=>b.stopPropagation(),onDragStart:b=>{b.preventDefault(),b.stopPropagation()},onDoubleClick:m,onKeyDown:f,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,"aria-valuenow":Math.round(n),"aria-valuemin":Math.round(Math.min(i??50,n)),"aria-valuemax":l,tabIndex:-1,children:c.jsx("div",{className:"ogx-column-resize-handle__line"})})}function fl(e){if(!e)return 0;let t=0;const n=(o,r)=>{t=Math.max(t,r);for(const i of o.children)typeof i!="string"&&n(i,r+1)};return e.forEach(o=>n(o,1)),t}function gl(e){const t=new Map;if(!e)return t;const n=(o,r)=>{const i=[...r,o];for(const l of o.children)typeof l=="string"?t.has(l)||t.set(l,i):n(l,i)};return e.forEach(o=>n(o,[])),t}function ir(e,t,n){if(!e||e.length===0)return!0;const o=gl(e),r=o.get(t),i=o.get(n);return(r?.[r.length-1]??null)===(i?.[i.length-1]??null)}function Sd(e,t,n){const o=[];let r=0,i=null,l=null;for(const d of e){const a=d.isSpacer?null:t.get(d.field)?.[n]??null;(i===null||l!==a||i.pinned!==d.pinned)&&(i={key:`${a?a.groupId:"filler"}-${n}-${d.field}`,isGroup:a!==null,label:a?.headerName??"",headerClassName:a?.headerClassName,width:0,flexGrow:0,fields:[],firstDataIndex:r,pinned:d.pinned},l=a,o.push(i)),i.width+=d.width,i.flexGrow+=d.flex??0,d.isSpacer||(i.fields.push(d.field),r++)}return o}function Ot(){return document.documentElement.clientWidth||window.innerWidth}function pl(){return document.documentElement.clientHeight||window.innerHeight}function Ut(){return c.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:c.jsx("circle",{cx:"4",cy:"4",r:"4"})})}function Rt(){return c.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:c.jsx("circle",{cx:"4",cy:"4",r:"3"})})}function kd(){return c.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.3"}),c.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),c.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ed(){return c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),c.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function Md(){return c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Nd(){return c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:c.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Id(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"}),c.jsx("path",{d:"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"}),c.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Ld(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"4",y1:"2",x2:"4",y2:"22"}),c.jsx("polyline",{points:"11 8 4 12 11 16"}),c.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Ad(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"20",y1:"2",x2:"20",y2:"22"}),c.jsx("polyline",{points:"13 8 20 12 13 16"}),c.jsx("line",{x1:"20",y1:"12",x2:"4",y2:"12"})]})}function Pd(){return c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),c.jsx("line",{x1:"4",y1:"4",x2:"4",y2:"20"}),c.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}const hl=e=>e?Array.from(e.querySelectorAll('[role="menuitem"], [role="menuitemradio"]')):[];function Td({colDef:e,sortModel:t,onSort:n,onHide:o,onPin:r,pinnedColumns:i,onManageColumns:l,onClose:d,anchorEl:a}){const u=s.useRef(null),g=s.useCallback(I=>{I&&(a?.closest('[role="columnheader"]')??a)?.focus({preventScroll:!0}),d()},[a,d]),h=I=>{const A=hl(u.current),_=A.indexOf(I.target);let L=-1;if(I.key==="ArrowDown")L=_+1>=A.length?0:_+1;else if(I.key==="ArrowUp")L=_<=0?A.length-1:_-1;else if(I.key==="Home")L=0;else if(I.key==="End")L=A.length-1;else if(I.key==="Tab"){I.preventDefault(),g(!0);return}else return;I.preventDefault(),A[L]?.focus()},[w,y]=s.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});s.useLayoutEffect(()=>{if(!a||!u.current)return;const I=a.getBoundingClientRect(),A=u.current.getBoundingClientRect(),_=Ot(),L=pl(),D=8;let v=I.left;v+A.width+D>_&&(v=_-A.width-D),v<D&&(v=D);let V=I.bottom+4;V+A.height+D>L&&(V=I.top-A.height-4),y({position:"fixed",zIndex:1300,top:V,left:v,visibility:"visible"})},[a]);const p=w.visibility==="visible";s.useLayoutEffect(()=>{p&&hl(u.current)[0]?.focus({preventScroll:!0})},[p]),s.useEffect(()=>{function I(_){u.current&&!u.current.contains(_.target)&&a&&!a.contains(_.target)&&d()}function A(_){_.key==="Escape"&&g(!0)}return document.addEventListener("mousedown",I),document.addEventListener("keydown",A),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",A),window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[a,d,g]);const f=I=>{n?.(e.field,I),g(!0)},m=!!o&&e.hideable!==!1,x=!!r&&e.pinnable!==!1,b=()=>{m&&o?.(e.field),g(!0)},C=I=>{x&&r?.(e.field,I),g(!0)},E=t?.find(I=>I.field===e.field)?.sort,k=E==null,N=i?.left?.includes(e.field)??!1,M=i?.right?.includes(e.field)??!1,S=!N&&!M,F=e.headerName||e.field;return mt.createPortal(c.jsxs("div",{ref:u,className:"ogx-column-menu",style:w,role:"menu","aria-label":`Column options for ${F}`,onKeyDown:h,children:[n&&e.sortable!==!1&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",className:`ogx-menu-item${E==="asc"?" ogx-menu-item--active":""}`,onClick:()=>f("asc"),role:"menuitemradio","aria-checked":E==="asc",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="asc"?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Ed,{})}),"Sort Ascending"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${E==="desc"?" ogx-menu-item--active":""}`,onClick:()=>f("desc"),role:"menuitemradio","aria-checked":E==="desc",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="desc"?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Md,{})}),"Sort Descending"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${k?" ogx-menu-item--active":""}`,onClick:()=>f(null),role:"menuitemradio","aria-checked":k,children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:k?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Nd,{})}),"Unsort"]}),c.jsx("div",{className:"ogx-menu-divider"})]}),x&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"ogx-menu-section-label","aria-hidden":"true",children:"Pin column"}),c.jsxs("button",{type:"button",className:`ogx-menu-item${N?" ogx-menu-item--active":""}`,onClick:()=>C("left"),role:"menuitemradio","aria-checked":N,"aria-label":"Pin to left",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:N?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Ld,{})}),"Pin to Left"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${M?" ogx-menu-item--active":""}`,onClick:()=>C("right"),role:"menuitemradio","aria-checked":M,"aria-label":"Pin to right",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:M?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Ad,{})}),"Pin to Right"]}),c.jsxs("button",{type:"button",className:`ogx-menu-item${S?" ogx-menu-item--active":""}`,onClick:()=>C(null),role:"menuitemradio","aria-checked":S,"aria-label":"Unpin column",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:S?c.jsx(Ut,{}):c.jsx(Rt,{})}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Pd,{})}),"Unpin"]}),c.jsx("div",{className:"ogx-menu-divider"})]}),m&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:b,role:"menuitem","aria-label":`Hide ${F} column`,children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(Id,{})}),"Hide Column"]}),c.jsx("div",{className:"ogx-menu-divider"})]}),c.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:()=>{l?.(),g(!1)},role:"menuitem","aria-label":"Manage all columns",children:[c.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),c.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:c.jsx(kd,{})}),"Manage columns"]})]}),a?.closest(".ogx-theme-provider")||document.body)}const Fd=16,Od=16;function Dd(e,t=!1){const n=Number.isFinite(e)?e-Od:0,o=Math.floor(n/Fd)-(t?1:0);return Math.max(1,o)}function $d(e,t){return e??t??!1}function ml(e,t,n,o){const r={width:t[e.field]??e.width??100,minWidth:e.minWidth,maxWidth:e.maxWidth,flexGrow:e.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",position:n?"sticky":"relative"};return n==="left"?r.left=o:n==="right"&&(r.right=o),r}const Gd="header:",Hd=40,Bd=300,Wd="__group__",wl=[];function lr(e){return`${Gd}${e}`}function sr(e){return"items"in e&&Array.isArray(e.items)}function Vd(e){return e.isSpacer||Ze(e.field)||e.field===Wd?!1:e.headerFilter!==!1&&e.filterable!==!1&&e.type!=="image"}function Yn(e){if(e.headerFilterOperator)return e.headerFilterOperator;switch(e.type){case"number":return"=";case"date":case"boolean":case"singleSelect":return"is";default:return"contains"}}function zd(e){const t=xi(e.type),n=Yn(e);return t.includes(n)?t:[n,...t]}function bl(e,t){return e.items.some(n=>sr(n)?bl(n,t):n.field===t)}function Kd(e){return(e?.logicOperator??"and")==="or"&&(e?.items?.length??0)>0}function xl(e,t){const n=e?.items??wl;if(Kd(e))return{kind:"custom"};const o=lr(t);let r;for(const i of n){if(sr(i)){if(bl(i,t))return{kind:"custom"};continue}if(i.field===t){if(i.id!==o||r)return{kind:"custom"};r=i}}return{kind:"editable",item:r}}function jd(e,t,n){const o=e??{items:[]};if(xl(o,t).kind!=="editable")return o;const r=lr(t),i=o.items??wl,l=i.findIndex(u=>!sr(u)&&u.id===r),d=n?{...n,id:r,field:t}:null;let a;if(l===-1){if(!d)return o;if(i.length===0&&o.logicOperator==="or")return{...o,logicOperator:"and",items:[d]};a=[...i,d]}else d?a=i.map((u,g)=>g===l?d:u):a=i.filter((u,g)=>g!==l);return{...o,items:a}}function ar(e,t,n){const o=Vt.has(t);return!o&&$o(n)&&t===Yn(e)?null:{id:lr(e.field),field:e.field,operator:t,value:o?void 0:n}}function yl(e,t){if(!Vt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const Ud={contains:"∋",equals:"=",startsWith:"a…",endsWith:"…a",isEmpty:"∅",isNotEmpty:"!∅",isAnyOf:"∈","=":"=","!=":"≠",">":">",">=":"≥","<":"<","<=":"≤",is:"=",not:"≠",after:">",onOrAfter:"≥",before:"<",onOrBefore:"≤"},cr={contains:"Contains",equals:"Equals",startsWith:"Starts with",endsWith:"Ends with",isEmpty:"Is empty",isNotEmpty:"Is not empty",isAnyOf:"Is any of","=":"Equals","!=":"Does not equal",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",is:"Is",not:"Is not",after:"After",onOrAfter:"On or after",before:"Before",onOrBefore:"On or before"},Qe=s.forwardRef(function({fullWidth:t=!1,error:n=!1,startAdornment:o,endAdornment:r,className:i="",inputClassName:l="",variant:d="field",...a},u){const g=["ogx-input-wrapper",d==="cell"&&"ogx-input-wrapper--cell",t&&"ogx-input-wrapper--full-width",n&&"ogx-input-wrapper--error",a.disabled&&"ogx-input-wrapper--disabled",i].filter(Boolean).join(" "),h=["ogx-input",l].filter(Boolean).join(" ");return c.jsxs("div",{className:g,children:[o&&c.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--start",children:o}),c.jsx("input",{ref:u,className:h,"aria-invalid":n?!0:void 0,...a}),r&&c.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--end",children:r})]})});Qe.displayName="Input";const Rd={position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"},Cl=e=>e?Array.from(e.querySelectorAll('[role="menuitemradio"]')):[];function qd({anchorEl:e,columnLabel:t,operators:n,current:o,onSelect:r,onClose:i}){const l=s.useRef(null),[d,a]=s.useState(Rd);s.useLayoutEffect(()=>{const w=l.current;if(!w)return;const y=e.getBoundingClientRect(),p=w.getBoundingClientRect(),f=8;let m=Math.min(y.left,Ot()-p.width-f);m<f&&(m=f);let x=y.bottom+4;x+p.height+f>pl()&&(x=y.top-p.height-4),a({position:"fixed",zIndex:1300,top:x,left:m,visibility:"visible"})},[e]);const u=d.visibility==="visible";s.useLayoutEffect(()=>{if(!u)return;const w=Cl(l.current);(w.find(y=>y.getAttribute("aria-checked")==="true")??w[0])?.focus({preventScroll:!0})},[u]);const g=s.useRef(i);s.useLayoutEffect(()=>{g.current=i}),s.useEffect(()=>{const w=e.ownerDocument,y=w.defaultView;function p(x){const b=x.target;l.current?.contains(b)||e.contains(b)||g.current(!1)}function f(x){l.current?.contains(x.target)||g.current(!1)}function m(){g.current(!1)}return w.addEventListener("mousedown",p),y?.addEventListener("scroll",f,!0),y?.addEventListener("resize",m),()=>{w.removeEventListener("mousedown",p),y?.removeEventListener("scroll",f,!0),y?.removeEventListener("resize",m)}},[e]);const h=w=>{w.stopPropagation();const y=Cl(l.current),p=y.indexOf(w.target);let f=-1;switch(w.key){case"ArrowDown":f=p+1>=y.length?0:p+1;break;case"ArrowUp":f=p<=0?y.length-1:p-1;break;case"Home":f=0;break;case"End":f=y.length-1;break;case"Escape":case"Tab":w.preventDefault(),i(!0);return;default:return}w.preventDefault(),y[f]?.focus()};return mt.createPortal(c.jsx("div",{ref:l,className:"ogx-column-menu ogx__header-filter-menu",style:d,role:"menu","aria-label":`Filter operator for ${t}`,onKeyDown:h,children:n.map(w=>c.jsx("button",{type:"button",role:"menuitemradio","aria-checked":w===o,tabIndex:-1,className:`ogx-menu-item${w===o?" ogx-menu-item--active":""}`,onClick:()=>r(w),children:cr[w]??w},w))}),e.closest(".ogx-theme-provider")??e.ownerDocument.body)}function Xd(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function Yd(e,t){const n=Array.isArray(t)?t[0]:t;return Object.is(e.value,n)?!0:n!=null&&String(e.value).toLowerCase()===String(n).toLowerCase()}function vl(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function _l(e,t){return Object.is(e,t)?!0:Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>_l(n,t[o])):!1}function Sl(e,t){return e===t?!0:!e||!t?!1:e.operator===t.operator&&_l(e.value,t.value)}function Jd(){return c.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"})]})}function Zd({colDef:e,state:t,style:n,className:o,ariaColIndex:r,onItemChange:i,onOpenFilterPanel:l}){const d=e.headerName||e.field,a=t.kind==="editable"?t.item:void 0,u=a?.operator??Yn(e),g=Xd(e),h=e.type==="boolean"||e.type==="singleSelect"&&g.length>0,w=!Vt.has(u),[y,p]=s.useState(null),[f,m]=s.useState(null),[x,b]=s.useState(void 0),[C,E]=s.useState(a);if(C!==a){E(a);const U=x!==void 0&&Sl(x??void 0,a);!Sl(C,a)&&!U&&p(null)}const k=s.useRef(null),N=s.useRef(null),M=s.useRef(null),S=s.useRef(null),F=s.useRef(null),I=s.useRef({item:a,colDef:e,onItemChange:i});s.useLayoutEffect(()=>{I.current={item:a,colDef:e,onItemChange:i}});const A=s.useCallback(U=>{const{item:te,colDef:ce,onItemChange:z}=I.current;if(te?U===Bo(te.value,ce.type):U.trim()==="")return;const K=te?.operator??Yn(ce),J=ar(ce,K,vl(U,K));b(J),z(ce.field,J)},[]),_=s.useRef(null);s.useLayoutEffect(()=>{_.current=y}),s.useEffect(()=>()=>{const U=_.current;_.current=null,U!==null&&A(U)},[A]),s.useEffect(()=>{if(y===null)return;const U=setTimeout(()=>{_.current=null,A(y),p(null)},Bd);return()=>clearTimeout(U)},[y,A]);const L=()=>k.current?.focus({preventScroll:!0}),D=()=>(N.current??M.current)?.focus({preventScroll:!0}),v=U=>{b(U),i(e.field,U)},V=U=>{p(null),v(ar(e,u,U))},R=()=>{p(null),v(null)},Q=()=>{F.current&&m(F.current)},G=U=>{m(null),U&&(N.current||M.current?D():L())},W=U=>{const te=y!==null?vl(y,U):a?.value;p(null),m(null),v(ar(e,U,yl(te,U))),requestAnimationFrame(()=>{N.current||M.current?D():L()})},H=t.kind==="custom",ie=!H&&w&&!h,oe=U=>{const te=U.currentTarget,ce=U.target;if(!te.contains(ce)||U.nativeEvent.isComposing)return;const{key:z}=U,re=ce===te;if((U.altKey&&z==="ArrowDown"||(U.ctrlKey||U.metaKey)&&z==="Enter")&&!H&&ce!==M.current){U.preventDefault(),U.stopPropagation(),Q();return}if(!re){z==="Escape"&&(U.preventDefault(),U.stopPropagation(),L());return}if(z==="Enter"||z===" "||z==="Spacebar"){U.preventDefault(),U.stopPropagation(),H?S.current?.click():N.current||M.current?D():Q();return}if((z==="Delete"||z==="Backspace")&&a){U.preventDefault(),U.stopPropagation(),R();return}ie&&e.type!=="date"&&z.length===1&&!U.ctrlKey&&!U.metaKey&&!U.altKey&&(U.preventDefault(),U.stopPropagation(),N.current?.focus({preventScroll:!0}),p(z))};let ue=null;if(H)ue=l?c.jsx("button",{ref:S,type:"button",className:"ogx__header-filter-custom",tabIndex:-1,onClick:l,title:"Set in the filter panel",children:"Custom filter"}):c.jsx("span",{className:"ogx__header-filter-custom",title:"Set in the filter panel",children:"Custom filter"});else{let U;if(!w)U=c.jsx("span",{className:"ogx__header-filter-operator-label",children:cr[u]??u});else if(e.type==="boolean")U=c.jsxs("select",{ref:M,className:"ogx__header-filter-select",tabIndex:-1,value:a?.value==null||a.value===""?"":String(a.value),onChange:ce=>V(ce.target.value===""?"":ce.target.value==="true"),"aria-label":`Filter value for ${d}`,children:[c.jsx("option",{value:"",children:"Any"}),c.jsx("option",{value:"true",children:"Yes"}),c.jsx("option",{value:"false",children:"No"})]});else if(h){const ce=g.find(z=>Yd(z,a?.value));U=c.jsxs("select",{ref:M,className:"ogx__header-filter-select",tabIndex:-1,value:ce?.key??"",onChange:z=>{const re=g.find(K=>K.key===z.target.value);V(yl(re?re.value:"",u))},"aria-label":`Filter value for ${d}`,children:[c.jsx("option",{value:"",children:"Any"}),g.map(z=>c.jsx("option",{value:z.key,children:z.label},z.key))]})}else U=c.jsx(Qe,{ref:N,className:"ogx__header-filter-input-wrapper",inputClassName:"ogx__header-filter-input",type:e.type==="date"?"date":"text",inputMode:e.type==="number"?"decimal":void 0,tabIndex:-1,autoComplete:"off",value:y??Bo(a?.value,e.type),onChange:ce=>p(ce.target.value),"aria-label":`Filter value for ${d}`});const te=cr[u]??u;ue=c.jsxs(c.Fragment,{children:[c.jsx("button",{ref:F,type:"button",className:`ogx__header-filter-operator${f?" ogx__header-filter-operator--open":""}`,tabIndex:-1,"aria-haspopup":"menu","aria-expanded":f!==null,"aria-label":`Filter operator for ${d}: ${te}`,title:te,onClick:()=>f?m(null):Q(),children:Ud[u]??"?"}),U,a&&c.jsx("button",{type:"button",className:"ogx__header-filter-clear",tabIndex:-1,"aria-label":`Clear filter for ${d}`,title:"Clear",onClick:()=>{R(),L()},children:c.jsx(Jd,{})}),f&&c.jsx(qd,{anchorEl:f,columnLabel:d,operators:zd(e),current:u,onSelect:W,onClose:G})]})}const se=["ogx__header-filter-cell",a&&"ogx__header-filter-cell--active",H&&"ogx__header-filter-cell--custom",o].filter(Boolean).join(" ");return c.jsx("div",{ref:k,className:se,style:n,role:"columnheader","aria-label":`Filter ${d}`,"aria-colindex":r,"data-field":e.field,tabIndex:-1,onKeyDown:oe,children:ue})}function dr({field:e,ariaColIndex:t,sticky:n,left:o,focused:r}){return c.jsx("div",{className:["ogx__header-filter-cell","ogx__header-filter-cell--system",n&&"ogx__header-filter-cell--pinned ogx__header-filter-cell--pinned-left",r&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" "),style:{width:Be,minWidth:Be,maxWidth:Be,position:n?"sticky":void 0,left:n?o:void 0},role:"columnheader","aria-colindex":t,"data-field":e,tabIndex:-1})}function Qd(e){const{columns:t,columnWidths:n,pinnedColumns:o,pinnedPositions:r,pinnedEdges:i,rowReordering:l,hasDetailPanel:d,checkboxSelection:a,pinExpandColumn:u,pinCheckboxColumn:g,columnIndexMap:h,ariaRowIndex:w,filterModel:y,onFilterModelChange:p,onOpenFilterPanel:f,focusedField:m}=e,x=s.useRef({filterModel:y,onFilterModelChange:p});s.useLayoutEffect(()=>{x.current={filterModel:y,onFilterModelChange:p}});const b=s.useCallback((F,I)=>{const{filterModel:A,onFilterModelChange:_}=x.current;if(!_)return;const L=jd(A,F,I);L!==A&&(x.current={filterModel:L,onFilterModelChange:_},_(L))},[]),C=l?1:0,E=d?C+1:C,k=a?E+1:E,N=k,M=l?Be:0,S=M+(d&&u?Be:0);return c.jsxs("div",{className:"ogx__header-filter-row",role:"row","aria-rowindex":w,children:[l&&c.jsx(dr,{field:At,ariaColIndex:C,sticky:!0,left:0,focused:m===At}),d&&c.jsx(dr,{field:Pt,ariaColIndex:E,sticky:u,left:M,focused:m===Pt}),a&&c.jsx(dr,{field:Je,ariaColIndex:k,sticky:g,left:S,focused:m===Je}),t.map((F,I)=>{if(F.isSpacer)return c.jsx("div",{style:{width:F.width,minWidth:F.width,flexShrink:0},"aria-hidden":"true"},F.field);const A=ct(F.field,o),_=ml(F,n,A,A?r[F.field]:void 0),L=N+(h?.get(F.field)??I)+1,D=[A&&"ogx__header-filter-cell--pinned",A&&`ogx__header-filter-cell--pinned-${A}`,A==="left"&&F.field===i.lastLeft&&"ogx__header-filter-cell--pinned-left-last",A==="right"&&F.field===i.firstRight&&"ogx__header-filter-cell--pinned-right-first",m===F.field&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" ");return Vd(F)?c.jsx(Zd,{colDef:F,state:xl(y,F.field),style:_,className:D,ariaColIndex:L,onItemChange:b,onOpenFilterPanel:f},F.field):c.jsx("div",{className:`ogx__header-filter-cell ogx__header-filter-cell--empty ${D}`,style:_,role:"columnheader","aria-label":`No filter for ${F.headerName||F.field}`,"aria-colindex":L,"data-field":F.field,tabIndex:-1},F.field)})]})}function eu(){return c.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"18",height:"18",children:c.jsx("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})})}function tu(){return c.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor",children:c.jsx("path",{d:"M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"})})}function kl(e){const{columns:t,allColumns:n,columnGroupingModel:o,checkboxSelection:r=!1,allSelected:i=!1,someSelected:l=!1,onSelectAll:d,onSort:a,sortModel:u=[],onColumnResize:g,onColumnAutosize:h,columnWidths:w={},pinnedColumns:y,hasDetailPanel:p=!1,pinCheckboxColumn:f=!0,pinExpandColumn:m=!0,rowReordering:x=!1,aggregationModel:b,draggedColumn:C,dragOverColumn:E,onDragStart:k,onDragOver:N,onDragEnd:M,onDrop:S,focusedCell:F,onHeaderClick:I,onSortAdd:A,multiSort:_=!1,onHideColumn:L,onPinColumn:D,onManageColumns:v,columnIndexMap:V,wrapHeaderText:R=!1,headerHeight:Q=56,headerFilters:G=!1,filterModel:W,onFilterModelChange:H,onOpenFilterPanel:ie}=e,oe=s.useId(),[ue,se]=s.useState(null),U=j=>le=>{le.stopPropagation(),se({colDef:j,anchorEl:le.currentTarget})},te=s.useCallback(()=>{se(null)},[]),ce=j=>le=>{if(le.altKey&&(le.key==="ArrowLeft"||le.key==="ArrowRight")&&le.target===le.currentTarget){if(j.resizable===!1||!g)return;le.preventDefault(),le.stopPropagation();const Ce=Nt(j,w),be=(le.shiftKey?50:10)*(le.key==="ArrowRight"?1:-1);g(j.field,rr(Ce+be,Ce,j.minWidth,j.maxWidth));return}if(!(le.altKey&&le.key==="ArrowDown"||(le.ctrlKey||le.metaKey)&&le.key==="Enter")||j.disableColumnMenu||le.target!==le.currentTarget)return;le.preventDefault(),le.stopPropagation();const he=le.currentTarget.querySelector(".ogx__menu-icon-btn")??le.currentTarget;se({colDef:j,anchorEl:he})},z=j=>F?.id===null&&!F.headerFilter&&F.field===j,re=x?1:0,K=p?re+1:re,J=r?K+1:K,ae=j=>le=>{if(j.sortable===!1)return;const we=u.find(he=>he.field===j.field);let pe="asc";we&&(we.sort==="asc"?pe="desc":pe=null),(le.shiftKey||_)&&A?A(j.field,pe):a&&a(j.field,pe)},fe=(j,le)=>{const we=u.some(he=>he.field===j);A&&(le===null||we||_||!a)?A(j,le):a?.(j,le)},Z=j=>{const le=u.find(pe=>pe.field===j);if(!le)return null;const we=u.length>1?u.indexOf(le)+1:null;return c.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${le.sort}`,"aria-hidden":"true",children:we!==null&&c.jsx("span",{className:"ogx__sort-badge",children:we})})},$=s.useMemo(()=>Eo(t,w,y,r,f,p,m,x),[t,w,y,r,f,p,m,x]),O=s.useMemo(()=>Mo(t,y),[t,y]),P=fl(o),T=s.useMemo(()=>gl(o),[o]),X=s.useMemo(()=>P===0?[]:(n??t).map(j=>({field:j.field,width:Nt(j,w),flex:j.isSpacer?0:j.flex,pinned:j.isSpacer?null:ct(j.field,y),isSpacer:j.isSpacer})),[P,n,t,w,y]),Y=(x?48:0)+(p?48:0)+(r?48:0),ne=(x||p||r)&&(!p||m)&&(!r||f),me=(x?1:0)+(p?1:0)+(r?1:0);return c.jsxs("div",{className:"ogx__header-wrap",children:[P>0&&Array.from({length:P},(j,le)=>{const we=Sd(X,T,le);return c.jsxs("div",{className:"ogx-col-group-row",role:"row","aria-rowindex":le+1,children:[Y>0&&c.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${ne?" ogx-col-group-cell--pinned ogx-col-group-cell--pinned-left":""}`,style:{width:Y,minWidth:Y,flexShrink:0,position:ne?"sticky":void 0,left:ne?0:void 0},"aria-hidden":"true"}),we.map((pe,he)=>{const Ce=pe.pinned?` ogx-col-group-cell--pinned ogx-col-group-cell--pinned-${pe.pinned}`:"",be={width:pe.width,minWidth:pe.width,flexShrink:0,flexGrow:pe.flexGrow};return pe.pinned==="left"?(be.position="sticky",be.left=$[pe.fields[0]]):pe.pinned==="right"&&(be.position="sticky",be.right=$[pe.fields[pe.fields.length-1]],we[he-1]?.pinned!=="right"&&(be.marginLeft="auto")),pe.isGroup?c.jsx("div",{role:"columnheader","aria-colspan":pe.fields.length,"aria-colindex":me+pe.firstDataIndex+1,className:`ogx-col-group-cell ogx-col-group-cell--group${Ce}${pe.headerClassName?` ${pe.headerClassName}`:""}`,style:be,title:pe.label,children:c.jsx("span",{className:"ogx-col-group-cell__label",children:pe.label})},pe.key):c.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${Ce}`,style:be,"aria-hidden":"true"},pe.key)})]},`ogx-grp-${le}`)}),c.jsxs("div",{className:"ogx__header",role:"row","aria-rowindex":P+1,children:[x&&c.jsx("div",{className:`ogx__header-cell ogx__header-cell--pinned ogx__header-cell--pinned-left ${z("__reorder_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Row reorder handle","aria-colindex":re,"data-field":"__reorder_col__",tabIndex:-1,title:"Drag to reorder rows",style:{minWidth:48,maxWidth:48,position:"sticky",left:0}}),p&&c.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${m?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${z("__expand_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Expand row details","aria-colindex":K,"data-field":"__expand_col__",tabIndex:-1,style:{minWidth:48,maxWidth:48,position:m?"sticky":void 0,left:m?x?48:0:void 0}}),r&&c.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${f?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${z("__checkbox_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-colindex":J,"data-field":"__checkbox_col__",style:{position:f?"sticky":void 0,left:f?(x?48:0)+(p&&m?48:0):void 0},children:d&&c.jsx(bt,{id:oe,name:oe,checked:i,indeterminate:l,onChange:j=>d(j.target.checked),"aria-label":i?"Deselect all rows":"Select all rows",tabIndex:-1,onMouseDown:j=>j.preventDefault()})}),t.map((j,le)=>{if(j.isSpacer)return c.jsx("div",{style:{width:j.width,minWidth:j.width,flexShrink:0},"aria-hidden":"true"},j.field);const we=j.sortable!==!1,pe=u.findIndex(ot=>ot.field===j.field),he=pe!==-1,Ce=he?u[pe].sort:null,be=V?.get(j.field)??le,de=we?pe===0?Ce==="asc"?"ascending":"descending":"none":void 0,ye=he&&u.length>1?`Sorted ${Ce==="asc"?"ascending":"descending"}, sort priority ${pe+1} of ${u.length}`:void 0,Ee=j.resizable!==!1,Me=ct(j.field,y),Ne=Me!==null,Ie=C===j.field,Se=E===j.field,Oe=$d(j.wrapHeaderText,R),ge=b?.[j.field],ve=["ogx__header-cell",`ogx__header-cell--align-${j.headerAlign||j.align||"left"}`,we&&"ogx__header-cell--sortable",he&&"ogx__header-cell--sorted",Ne&&"ogx__header-cell--pinned",Ne&&`ogx__header-cell--pinned-${Me}`,Me==="left"&&j.field===O.lastLeft&&"ogx__header-cell--pinned-left-last",Me==="right"&&j.field===O.firstRight&&"ogx__header-cell--pinned-right-first",Ie&&"ogx__header-cell--dragging",Se&&"ogx__header-cell--drag-over",Oe&&"ogx__header-cell--wrap",z(j.field)&&"ogx__header-cell--focused",j.headerClassName].filter(Boolean).join(" "),ke={...ml(j,w,Me,Me?$[j.field]:void 0),zIndex:j.zIndex,opacity:Ie?.5:1},xe=j.renderHeader?j.renderHeader({field:j.field,colDef:j,colIndex:be}):j.headerName||j.field,je=ot=>{if(ot.target.closest(".ogx-column-resize-handle")){ot.stopPropagation();return}I?.(j.field),we&&ae(j)(ot)},nt=k&&!Ne?k(j.field):void 0,nn=N&&!Ne?N(j.field):void 0,Mn=S&&!Ne?S(j.field):void 0;return c.jsxs("div",{className:ve,style:ke,title:j.description??(Oe&&typeof xe=="string"?xe:void 0),onClick:je,role:"columnheader",draggable:!!nt,onDragStart:nt,onDragOver:nn,onDragEnd:M,onDrop:Mn,onKeyDown:ce(j),"aria-sort":de,"aria-description":ye,"aria-colindex":me+be+1,"data-field":j.field,tabIndex:-1,children:[c.jsxs("div",{className:"ogx__header-cell-content",children:[Ie&&c.jsx("div",{className:"ogx__header-drag-icon",children:c.jsx(tu,{})}),c.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[c.jsx("span",{className:"ogx__header-cell-title",style:Oe?{WebkitLineClamp:Dd(Q,!!ge)}:void 0,children:xe}),ge&&c.jsx("span",{className:"ogx__header-cell-aggregation",children:ge})]}),we&&Z(j.field),!j.disableColumnMenu&&c.jsx("button",{type:"button",className:"ogx__menu-icon-btn",onClick:U(j),"aria-label":`Open column menu for ${j.headerName||j.field}`,"aria-haspopup":"menu",tabIndex:-1,children:c.jsx(eu,{})})]}),Ee&&g&&c.jsx(_d,{field:j.field,currentWidth:Nt(j,w),onResize:g,onAutosize:h,minWidth:j.minWidth,maxWidth:j.maxWidth,edge:Me==="right"?"start":"end"})]},j.field)}),ue&&c.jsx(Td,{colDef:ue.colDef,sortModel:u,onSort:a||A?fe:void 0,onHide:L,onPin:D,pinnedColumns:y,onManageColumns:v,onClose:te,anchorEl:ue.anchorEl})]}),G&&c.jsx(Qd,{columns:t,columnWidths:w,pinnedColumns:y,pinnedPositions:$,pinnedEdges:O,rowReordering:x,hasDetailPanel:p,checkboxSelection:r,pinExpandColumn:m,pinCheckboxColumn:f,columnIndexMap:V,ariaRowIndex:P+2,filterModel:W,onFilterModelChange:H,onOpenFilterPanel:ie,focusedField:F?.id===null&&F.headerFilter?F.field:null})]})}const Ae=()=>{},ur=()=>Promise.resolve({updated:[],failed:[],skipped:[]});function El(){return{getRow:()=>null,getAllRows:()=>[],getVisibleRows:()=>[],getAllFilteredRows:()=>[],getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:()=>null,getAllColumns:()=>[],getVisibleColumns:()=>[],selectRow:Ae,selectRows:Ae,getSelectedRows:()=>[],sortColumn:Ae,getSortModel:()=>[],setFilterModel:Ae,getFilterModel:()=>({items:[]}),setPage:Ae,setPageSize:Ae,scrollToIndexes:Ae,autosizeColumn:Ae,autosizeColumns:Ae,copySelectedRows:()=>Promise.resolve(),getCellSelectionModel:()=>[],setCellSelectionModel:Ae,selectCellRange:Ae,clearCellSelection:Ae,getSelectedCells:()=>[],copySelectedCells:()=>Promise.resolve(),pasteText:ur,undo:ur,redo:ur,canUndo:()=>!1,canRedo:()=>!1,clearHistory:Ae,setSortModel:Ae,setRowGroupingModel:Ae,setAggregationModel:Ae,setColumnVisibilityModel:Ae,setPivotModel:Ae,getGridAiState:()=>({}),openAiAssistant:Ae,closeAiAssistant:Ae}}const nu=e=>e.id;let Ml=!1;function Nl(e,t,n){const o=new Map,r=new Map,i=[],l=[];return e.forEach(d=>{const a=n?.get(d)??t(d);if(o.has(a)){l.push(a);return}o.set(a,d),r.set(d,a),i.push(a)}),l.length>0&&!Ml&&process.env.NODE_ENV!=="production"&&(Ml=!0,console.warn(`[OpenGridX] ${l.length} row(s) reuse the id of an earlier row and were ignored (ids: ${l.slice(0,5).map(String).join(", ")}${l.length>5?", …":""}). Every row needs a unique id; pass getRowId if the unique key lives in another field.`)),{idRowsLookup:o,allRows:i,idByRow:r}}function ou(e,t,n,o={}){const r=new Map,i=[];return n.forEach(l=>{r.set(l.field,l),i.push(l.field)}),{rows:Nl(e,t),columns:{all:n,lookup:r,orderedFields:i,columnVisibilityModel:o},pagination:{rowCount:void 0},pinning:{pinnedColumns:{},pinnedRows:{}},dimensions:{rowHeight:52,headerHeight:56,viewportWidth:0,viewportHeight:0},dataSource:{loading:!1,error:null}}}function ru(e,t){switch(t.type){case"SET_ROWS":{const n=e.rows.allRows.map(r=>e.rows.idRowsLookup.get(r)),o=typeof t.payload=="function"?t.payload(n):t.payload;return{...e,rows:Nl(o,t.getRowId,e.rows.idByRow)}}case"REPLACE_ROW":{const n=e.rows.idRowsLookup.get(t.id);if(n===void 0)return e;const o=new Map(e.rows.idRowsLookup);o.set(t.id,t.row);const r=new Map(e.rows.idByRow);return r.delete(n),r.set(t.row,t.id),{...e,rows:{...e.rows,idRowsLookup:o,idByRow:r}}}case"REPLACE_ROWS":{let n=!1;const o=new Map(e.rows.idRowsLookup),r=new Map(e.rows.idByRow);for(const[i,l]of t.rows){const d=o.get(i);d!==void 0&&(n=!0,o.set(i,l),r.delete(d),r.set(l,i))}return n?{...e,rows:{...e.rows,idRowsLookup:o,idByRow:r}}:e}case"SET_COLUMNS":{const n=new Map,o=[];return t.payload.forEach(r=>{n.set(r.field,r),o.push(r.field)}),{...e,columns:{all:t.payload,lookup:n,orderedFields:o,columnVisibilityModel:e.columns.columnVisibilityModel}}}case"SET_DIMENSIONS":return{...e,dimensions:{...e.dimensions,viewportWidth:t.payload.viewportWidth,viewportHeight:t.payload.viewportHeight}};case"SET_DATASOURCE_LOADING":return{...e,dataSource:{...e.dataSource,loading:t.payload}};case"SET_DATASOURCE_ERROR":return{...e,dataSource:{...e.dataSource,error:t.payload}};case"SET_ROW_COUNT":return{...e,pagination:{...e.pagination,rowCount:t.payload}};default:return e}}function iu(e){const{rows:t,columns:n,rowHeight:o=52,headerHeight:r=56,columnVisibilityModel:i,initialState:l,syncRows:d=!1}=e,a=e.getRowId??nu,u=s.useRef(a);s.useLayoutEffect(()=>{u.current=a});const[g]=s.useState(()=>ou(t,a,n,i)),[h,w]=s.useReducer(ru,{...g,dataSource:l?.dataSource?{...g.dataSource,...l.dataSource}:g.dataSource,pagination:{rowCount:l?.pagination?.rowCount},dimensions:{...g.dimensions,rowHeight:o,headerHeight:r}}),[y,p]=s.useState({rows:t,syncRows:d});(y.rows!==t||y.syncRows!==d)&&(p({rows:t,syncRows:d}),d&&w({type:"SET_ROWS",payload:t,getRowId:a}));const f=s.useRef(h);s.useLayoutEffect(()=>{f.current=h});const m=s.useCallback((I,A)=>{w({type:"SET_ROWS",payload:I,getRowId:u.current})},[]),x=s.useCallback((I,A)=>{w({type:"REPLACE_ROW",id:I,row:A})},[]),b=s.useCallback(I=>{I.size>0&&w({type:"REPLACE_ROWS",rows:I})},[]),C=s.useCallback(I=>{w({type:"SET_COLUMNS",payload:I})},[]),E=s.useCallback((I,A)=>{w({type:"SET_DIMENSIONS",payload:{viewportWidth:I,viewportHeight:A}})},[]),k=s.useCallback(I=>{w({type:"SET_DATASOURCE_LOADING",payload:I})},[]),N=s.useCallback(I=>{w({type:"SET_DATASOURCE_ERROR",payload:I})},[]),M=s.useCallback(I=>{w({type:"SET_ROW_COUNT",payload:I})},[]),[S]=s.useState(()=>({...El(),getRow:I=>f.current.rows.idRowsLookup.get(I)||null,getAllRows:()=>f.current.rows.allRows.map(I=>f.current.rows.idRowsLookup.get(I)),getColumn:I=>f.current.columns.lookup.get(I)||null,getAllColumns:()=>f.current.columns.all})),F=s.useRef(S);return{state:h,dispatch:w,apiRef:F,setRows:m,replaceRow:x,replaceRows:b,setColumns:C,setDimensions:E,setDataSourceLoading:k,setDataSourceError:N,setRowCount:M}}function lu(e){const{onRowOrderChange:t,rows:n,getRowId:o,rowReordering:r=!1}=e,[i,l]=s.useState(null),[d,a]=s.useState(null),u=s.useRef(()=>{}),g=s.useMemo(()=>{const m=new Map;return n.forEach((x,b)=>m.set(o?o(x):x.id,b)),m},[n,o]),h=s.useCallback(m=>g.has(m),[g]),w=s.useCallback(()=>{u.current(),u.current=()=>{},l(null),a(null)},[]);s.useEffect(()=>()=>u.current(),[]);const y=s.useCallback(m=>x=>{if(r){if(!g.has(m)){x.preventDefault();return}u.current(),u.current=Yi(x.currentTarget,w),l(m),x.dataTransfer&&(x.dataTransfer.effectAllowed="move",Xi(x,er,String(m)))}},[r,g,w]),p=s.useCallback(m=>x=>{if(!(!r||i===null)){if(!Rn(x,er)){w();return}g.has(m)&&(x.preventDefault(),x.dataTransfer&&(x.dataTransfer.dropEffect="move"),d!==m&&a(m))}},[r,i,d,g,w]),f=s.useCallback(m=>x=>{if(x.preventDefault(),i===null||!Rn(x,er)){w();return}const b=g.get(i),C=g.get(m);w(),t&&b!==void 0&&C!==void 0&&b!==C&&t({row:n[b],oldIndex:b,targetIndex:C})},[i,t,n,g,w]);return{draggedRowId:i,dragOverRowId:d,canReorderRow:h,onDragStart:r?y:void 0,onDragOver:r?p:void 0,onDragEnd:r?w:void 0,onDrop:r?f:void 0}}const Il=new Map,Ll=e=>JSON.stringify(e),su=e=>`auto-group-${e}`,Al=5,Pl=e=>e.slice(0,Al).map(t=>JSON.stringify(t)).join(", ")+(e.length>Al?", …":""),au={treeNodes:new Map,rootIds:[],groupingRows:[],syntheticIds:new Set,rowLookup:new Map,issues:[]};function cu(e,t,n){const o=new Map,r=[],i=[],l=new Set,d=new Map,a=new Map,u=[],g=new Array(e.length),h=new Array(e.length),w=[],y=new Map;e.forEach((f,m)=>{const x=t(f),b=n(f),C=Array.isArray(b)?b.map(E=>String(E)):[];if(g[m]=x,h[m]=C,d.set(x,f),C.length===0)w.push(x);else{const E=Ll(C),k=a.get(E);if(k===void 0)a.set(E,x);else{const N=y.get(E)??[k];N.push(x),y.set(E,N)}}o.set(x,{id:x,parentId:null,depth:Math.max(C.length-1,0),groupingKey:C[C.length-1]??"",isExpanded:!1,children:[],serverChildrenCount:f.serverChildrenCount})});const p=f=>{const m=Ll(f),x=a.get(m);if(x!==void 0)return x;const b=su(m),C=f[f.length-1],E={id:b,parentId:null,depth:f.length-1,groupingKey:C,isExpanded:!1,children:[],label:C};o.set(b,E),a.set(m,b),l.add(b);const k={id:b};if(i.push(k),d.set(b,k),f.length===1)r.push(b);else{const N=p(f.slice(0,-1));E.parentId=N,o.get(N)?.children?.push(b)}return b};return e.forEach((f,m)=>{const x=g[m],b=h[m];if(b.length<=1){r.push(x);return}const C=p(b.slice(0,-1)),E=o.get(x);E&&(E.parentId=C),o.get(C)?.children?.push(x)}),w.length>0&&u.push(`[OpenGridX] treeData: getTreeDataPath returned an empty path for row(s) ${Pl(w)}. They are shown as top-level rows.`),y.forEach((f,m)=>{u.push(`[OpenGridX] treeData: rows ${Pl(f)} have the same path ${m}. Rows under that path are attached to row ${JSON.stringify(f[0])}.`)}),{treeNodes:o,rootIds:r,groupingRows:i,syntheticIds:l,rowLookup:d,issues:u}}function du(e,t){const{treeNodes:n,rootIds:o,syntheticIds:r,rowLookup:i}=e,l=new Set,d=new Map,a=new Map,u=g=>{const h=n.get(g);if(!h)return!1;const w=[];let y=0;for(const x of h.children??[])u(x)&&(w.push(x),y+=(r.has(x)?0:1)+(a.get(x)??0));d.set(g,w),a.set(g,y);const p=i.get(g),m=!r.has(g)&&p!==void 0&&(t?t(p):!0)||w.length>0;return m&&l.add(g),m};return o.forEach(u),{visible:l,visibleChildren:d,descendantCounts:a}}function uu(e){const{rows:t,getRowId:n,getTreeDataPath:o,treeData:r=!1,defaultGroupingExpansionDepth:i=0,filterModel:l,sortModel:d,onRowExpansionChange:a,columnLookup:u,filterMode:g="client",sortingMode:h="client"}=e,w=r&&!!o,y=s.useMemo(()=>!r||!o?au:cu(t,n,o),[t,o,r,n]),{treeNodes:p,rootIds:f,groupingRows:m,syntheticIds:x,rowLookup:b}=y,C=y.issues.join(`
|
|
2
|
+
`);s.useEffect(()=>{process.env.NODE_ENV==="production"||!C||C.split(`
|
|
3
|
+
`).forEach(W=>console.warn(W))},[C]);const E=r&&!o;s.useEffect(()=>{process.env.NODE_ENV==="production"||!E||console.warn("[OpenGridX] treeData is set without getTreeDataPath, so the rows are shown as a flat list. Pass getTreeDataPath={(row) => row.path} to build the tree.")},[E]);const k=s.useMemo(()=>g==="server"?null:Wn(l,u),[g,l,u]),N=s.useMemo(()=>du(y,k),[y,k]),M=`${r}|${i}`,[S,F]=s.useState(()=>({configKey:M,overrides:new Map})),I=S.configKey===M?S.overrides:Il,A=s.useCallback(W=>((W?.children?.length??0)>0||(W?.serverChildrenCount??0)>0)&&(i===-1||(W?.depth??0)<i),[i]),_=s.useMemo(()=>{const W=new Set;return w&&p.forEach((H,ie)=>{(I.get(ie)??A(H))&&W.add(ie)}),W},[w,p,I,A]),L=s.useCallback(W=>{const H=!_.has(W);if(F(ie=>{const oe=ie.configKey===M?ie.overrides:Il,ue=new Map(oe);return ue.set(W,H),{configKey:M,overrides:ue}}),H&&a){const ie=p.get(W);ie&&a(ie)}},[_,M,p,a]),D=h!=="server"&&!!(d&&d.length>0),v=s.useCallback(W=>{if(!w)return null;const H=W?.labelField,ie=W?.expandAll??!1,{visible:oe,visibleChildren:ue}=N,se=D&&d?d:[],U=(re,K)=>{if(x.has(re))return{value:K.field===H?p.get(re)?.label:void 0};const J=b.get(re),ae=u?.byField.get(K.field),fe=J?Le(J,K.field,ae):void 0,Z=ae?.sortComparator;return{value:fe,type:ae?.type,comparator:Z,params:Z&&J?{id:re,field:K.field,row:J,value:fe}:void 0}},te=[],ce=new Set,z=re=>{const K=re.filter(ae=>oe.has(ae)),J=se.length>0?Ko(K,se,U):K;for(const ae of J){if(ce.has(ae))continue;const fe=b.get(ae);if(!fe)continue;ce.add(ae),te.push(fe);const Z=ue.get(ae);Z&&Z.length>0&&(ie||_.has(ae))&&z(Z)}};return z(f),te},[w,N,D,d,x,p,b,u,f,_]),V=s.useCallback(W=>_.has(W),[_]),R=s.useCallback(W=>p.get(W),[p]),Q=s.useCallback(W=>{const H=[];let ie=W;for(;ie!==null;){const oe=p.get(ie);if(!oe)break;H.unshift(oe.groupingKey),ie=oe.parentId}return H},[p]),G=s.useMemo(()=>{const W=new Map,{visibleChildren:H,descendantCounts:ie}=N;return p.forEach((oe,ue)=>{const se=(oe.children?.length??0)===0&&(oe.serverChildrenCount??0)>0,U=x.has(ue),te={hasChildren:(H.get(ue)?.length??0)>0||se,treeDepth:oe.depth,descendantCount:se?void 0:ie.get(ue)??0,isGroupRow:U,isExpanded:_.has(ue)};U&&(te.groupLabel=oe.label),W.set(ue,te)}),W},[p,x,N,_]);return s.useMemo(()=>({treeNodes:p,groupingRows:m,toggleExpansion:L,isGroupExpanded:V,getVisibleRows:v,getNode:R,getNodePath:Q,rowMetaMap:G}),[p,m,L,V,v,R,Q,G])}const Tl=e=>e===null?"footer":"inline";function Fl(e,t){return Dn(()=>e(t),Tl(t),"getAggregationPosition","getAggregationPosition threw; the default position is used")}function fu(e,t,n){const o=`${t}: ${String(n)}`,r=e?.groupingValueFormatter;return r?Dn(()=>r({field:t,value:n}),o,`groupingValueFormatter:${t}`,`groupingValueFormatter for column "${t}" threw; the group is labelled "${t}: value"`):o}const gu=[],pu={},Ol=new Map,et="";function hu(e){if(typeof e=="string")return e;if(e===null)return`${et}null`;if(e===void 0)return`${et}undefined`;if(e instanceof Date)return`${et}date:${e.getTime()}`;if(typeof e=="object")try{return`${et}object:${JSON.stringify(e)}`}catch{return`${et}object:${String(e)}`}return`${et}${typeof e}:${String(e)}`}const mu=(e,t,n)=>`auto-group-${e}-${t}-${n??"root"}`,wu=e=>`${e}${et}footer`,bu=e=>e==="footer"?"f":e===null?"n":"i",xu=e=>e==="f"?"footer":e==="n"?null:"inline";function yu(e){const{rows:t,getRowId:n,columns:o,rowGroupingModel:r=gu,aggregationModel:i=pu,defaultGroupingExpansionDepth:l=0,filterModel:d,sortModel:a,getAggregationPosition:u=Tl,columnLookup:g,filterMode:h="client",sortingMode:w="client"}=e,y=r.join(et),p=s.useMemo(()=>y===""?[]:y.split(et),[y]),f=JSON.stringify(Object.entries(i)),m=s.useMemo(()=>Object.fromEntries(JSON.parse(f)),[f]),x=Object.keys(m).length>0,b=s.useMemo(()=>{const z=new Map;return(o??[]).forEach(re=>z.set(re.field,re)),z},[o]),C=p.length>0,E=s.useMemo(()=>p.filter(z=>b.get(z)?.groupable!==!1),[p,b]),N=`${E.join(et)}|${l}`,[M,S]=s.useState(()=>({configKey:N,overrides:new Map})),F=M.configKey===N?M.overrides:Ol,I=s.useMemo(()=>{if(!C||h==="server")return null;const z=Wn(d,g);return z?new Set(t.filter(re=>z(re))):null},[C,t,h,d,g]),A=s.useMemo(()=>{const z=new Map,re=[],K=[],J=new Map,ae=new Map,fe=new Map;if(!C)return{treeNodes:z,rootIds:re,groupIds:K,groupRowVariants:J,groupingRows:ae,rowLookup:fe};const Z=($,O,P)=>{if(O>=E.length)return(I?$.filter(Y=>I.has(Y)):$).map(Y=>{const ne=n(Y);return fe.set(ne,Y),z.set(ne,{id:ne,parentId:P,depth:O,groupingKey:"",isExpanded:!1}),ne});const T=E[O],X=b.get(T),B=new Map;for(const q of $){const Y=Le(q,T,X),ne=hu(Y);let me=B.get(ne);me||(me={value:Y,rows:[]},B.set(ne,me)),me.rows.push(q)}const ee=[];return B.forEach((q,Y)=>{const ne=I?q.rows.filter(Ce=>I.has(Ce)):q.rows;if(ne.length===0)return;const me=mu(T,Y,P);ee.push(me),K.push(me);const j=x?Hn(ne,m,b,"useRowGrouping"):{},le={[T]:q.value,...j,id:me},we={[T]:q.value,id:me},pe=x?{...j,id:wu(me)}:null;J.set(me,{inline:le,bare:we,footer:pe}),ae.set(me,le),pe&&ae.set(pe.id,pe);const he={id:me,parentId:P,depth:O,groupingKey:String(q.value),groupingField:T,groupingValue:q.value,aggregatedValues:j,isExpanded:!1,children:[],label:fu(X,T,q.value),descendantCount:ne.length};z.set(me,he),he.children=Z(q.rows,O+1,me)}),ee};return re.push(...Z(t,0,null)),{treeNodes:z,rootIds:re,groupIds:K,groupRowVariants:J,groupingRows:ae,rowLookup:fe}},[C,t,I,E,x,m,n,b]),{treeNodes:_,rootIds:L,groupIds:D,groupRowVariants:v,groupingRows:V,rowLookup:R}=A,Q=s.useCallback(z=>!!(z?.children&&z.children.length>0)&&(l===-1||(z?.depth??0)<l),[l]),G=s.useMemo(()=>{const z=new Set;return _.forEach((re,K)=>{!re.children||re.children.length===0||(F.get(K)??Q(re))&&z.add(K)}),z},[_,F,Q]),W=s.useCallback(z=>{S(re=>{const K=re.configKey===N?re.overrides:Ol,J=K.get(z)??Q(_.get(z)),ae=new Map(K);return ae.set(z,!J),{configKey:N,overrides:ae}})},[N,_,Q]),H=s.useCallback(z=>G.has(z),[G]),ie=x?D.map(z=>{const re=_.get(z);return re?bu(Fl(u,{...re,isExpanded:G.has(z)})):"i"}).join(""):"",oe=s.useMemo(()=>{const z=new Map;return D.forEach((re,K)=>z.set(re,xu(ie[K]))),z},[D,ie]),ue=x?Fl(u,null):"footer",se=w!=="server"&&!!(a&&a.length>0),U=s.useCallback(z=>{if(!C)return null;const re=z?.labelField,K=z?.expandAll??!1,J=se&&a?a:[],ae=(O,P)=>{const T=_.get(O),X=v.get(O);if(T&&X){const ne=T.groupingField??"";if(P.field===ne||P.field===re){const me=g?.byField.get(ne),j=me?.sortComparator;return{value:T.groupingValue,type:me?.type,comparator:j,params:j?{id:O,field:ne,row:X.inline,value:T.groupingValue}:void 0}}return T.aggregatedValues&&Object.prototype.hasOwnProperty.call(T.aggregatedValues,P.field)?{value:T.aggregatedValues[P.field],type:g?.byField.get(P.field)?.type}:{value:void 0}}const B=R.get(O),ee=g?.byField.get(P.field),q=B?Le(B,P.field,ee):void 0,Y=ee?.sortComparator;return{value:q,type:ee?.type,comparator:Y,params:Y&&B?{id:O,field:P.field,row:B,value:q}:void 0}},fe=[],Z=new Set,$=O=>{const P=J.length>0?Ko(O,J,ae):O;for(const T of P){if(Z.has(T))continue;Z.add(T);const X=v.get(T);if(!X){const ne=R.get(T);ne&&fe.push(ne);continue}const B=_.get(T),ee=G.has(T),q=oe.has(T)?oe.get(T)??null:"inline",Y=q==="inline"||q==="footer"&&!ee;fe.push(Y?X.inline:X.bare),(ee||K)&&B?.children&&($(B.children),ee&&!K&&q==="footer"&&X.footer&&fe.push(X.footer))}};return $(L),fe},[C,se,a,_,v,R,g,G,oe,L]),te=s.useCallback(z=>_.get(z),[_]),ce=s.useMemo(()=>{const z=new Map;return _.forEach((re,K)=>{const J=v.get(K);if(!J){z.set(K,{hasChildren:!1,treeDepth:re.depth,isGroupRow:!1});return}const ae={hasChildren:!0,treeDepth:re.depth,groupingField:re.groupingField,groupingValue:re.groupingValue,groupLabel:re.label,descendantCount:re.descendantCount,isGroupRow:!0,isExpanded:G.has(K)};z.set(K,ae),J.footer&&oe.get(K)==="footer"&&z.set(J.footer.id,{...ae,hasChildren:!1,treeDepth:re.depth+1,isExpanded:void 0,isGroupFooter:!0})}),z},[_,v,G,oe]);return s.useMemo(()=>({treeNodes:_,groupingRows:V,toggleExpansion:W,isGroupExpanded:H,getVisibleRows:U,getNode:te,rowMetaMap:ce,aggregationPositions:oe,rootAggregationPosition:ue}),[_,V,W,H,U,te,ce,oe,ue])}const Cu=new Map;function vu(e){const{rows:t,getRowId:n,getTreeDataPath:o,isTreeDataRequested:r,isTreeData:i,columns:l,rowGroupingModel:d,isRowGrouping:a,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:h,sortModel:w,getAggregationPosition:y,columnLookup:p,filterMode:f,sortingMode:m}=e,x=uu({rows:t,getRowId:n,getTreeDataPath:o,treeData:r,defaultGroupingExpansionDepth:g,filterModel:h,sortModel:w,columnLookup:p,filterMode:f,sortingMode:m}),b=yu({rows:t,getRowId:n,columns:l,rowGroupingModel:d,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:h,sortModel:w,getAggregationPosition:y,columnLookup:p,filterMode:f,sortingMode:m}),C=i?x:a?b:null,E=s.useMemo(()=>i?x.rowMetaMap:a?b.rowMetaMap:Cu,[i,x.rowMetaMap,a,b.rowMetaMap]);return{treeDataHandlers:x,rowGroupingHandlers:b,activeHierarchyHandlers:C,rowMetaMap:E}}function We(e){try{return{ok:!0,value:e()}}catch(t){return{ok:!1,error:t}}}class Dl extends Error{}function xt(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function $l(e){return typeof e=="object"&&e!==null&&typeof e.then=="function"}function Gl(e,t){t?t(e):process.env.NODE_ENV!=="production"&&e instanceof Dl&&console.error(e.message)}function Hl(e,t){return new Dl(`[OpenGridX] processRowUpdate must return the updated row object (or a Promise of it); it returned ${e===null?"null":typeof e}. ${t}`)}function Bl(e,t,n,o){return n?.valueSetter?n.valueSetter({value:t.value,row:e,field:t.field}):(n?.valueGetter&&process.env.NODE_ENV!=="production"&&!o.has(t.field)&&(o.add(t.field),console.warn(`[OpenGridX] Column "${t.field}" is editable and has a valueGetter but no valueSetter. The edited value was written to row["${t.field}"], which the valueGetter may ignore, so the cell can keep showing the old value. Add a valueSetter that maps the value back onto the row.`)),{...e,[t.field]:t.value})}const qt=Promise.resolve();function _u(e){const[t,n]=s.useState(null),o=s.useRef(null),r=s.useRef(0),i=s.useRef(new Map),l=s.useRef(new Set),d=s.useRef(!1),a=s.useRef(e);s.useLayoutEffect(()=>{a.current=e}),s.useEffect(()=>(d.current=!0,()=>{d.current=!1}),[]);const u=s.useCallback(f=>{o.current=f,n(f)},[]),g=s.useRef(null),h=s.useCallback((f,m)=>{const x=i.current.get(f);if(x)return xt(x.value,m.value)?x.promise:x.promise.then(()=>{const G=o.current;if(!(r.current!==f||!G||xt(G.value,x.value)))return g.current?.(f,G)});const b=()=>r.current===f&&o.current!==null;if(xt(m.value,m.originalValue))return b()&&u(null),qt;const{rows:C,getRowId:E,columns:k,processRowUpdate:N}=a.current,M=C.find(G=>E(G)===m.id);if(!M)return b()&&u(null),qt;const S=G=>Gl(G,a.current.onProcessRowUpdateError),F=k?.find(G=>G.field===m.field),I=G=>{if(typeof G!="object"||G===null){S(Hl(G,"The edit was not saved and the editor stays open."));return}a.current.onRowChange?.(G,m.id);const{onCommitted:W}=a.current;if(W){const ie=Le(M,m.field,F),oe=Le(G,m.field,F);xt(ie,oe)||W([{id:m.id,field:m.field,before:ie,after:oe}])}const H=o.current;r.current!==f||!H||(xt(H.value,m.value)?u(null):u({...H,originalValue:m.value}))};let A,_;const L=new Promise((G,W)=>{A=G,_=W}),D={value:m.value,promise:L};i.current.set(f,D);const v=()=>{i.current.get(f)===D&&i.current.delete(f)},V=We(()=>{const G=Bl(M,m,F,l.current);return N?N(G,M):G});if(!V.ok)return v(),S(V.error),A(),L;const R=V.value,Q=G=>{v();try{I(G),A()}catch(W){_(W)}};return $l(R)?Promise.resolve(R).then(Q,G=>{v(),S(G),A()}):Q(R),L},[u]);s.useLayoutEffect(()=>{g.current=h},[h]);const w=s.useCallback(f=>{const m=o.current;if(m){if(m.id===f.id&&m.field===f.field)return;h(r.current,m)}r.current+=1,u({id:f.id,field:f.field,value:f.value,originalValue:f.value})},[h,u]),y=s.useCallback(f=>{const m=o.current;return!m||!d.current||f?.id!==void 0&&f.id!==m.id||f?.field!==void 0&&f.field!==m.field?qt:f?.cancel?(u(null),qt):h(r.current,m)},[h,u]),p=s.useCallback(f=>{const m=o.current;!m||m.id!==f.id||m.field!==f.field||u({...m,value:f.value})},[u]);return s.useMemo(()=>({editingCell:t,startCellEdit:w,stopCellEdit:y,setEditCellValue:p}),[t,w,y,p])}function Su(e){const t=s.useRef(e),n=s.useRef(new Map),o=s.useRef(new Set);s.useLayoutEffect(()=>{t.current=e,n.current.clear()});const r=s.useCallback(a=>{const u=n.current.get(a);return u===void 0?t.current.rowsLookup.get(a):u},[]),i=s.useCallback(a=>{a.size!==0&&(a.forEach((u,g)=>{n.current.set(g,u)}),t.current.replaceRows(a))},[]),l=s.useCallback((a,u)=>{i(new Map([[a,u]]))},[i]),d=s.useCallback((a,u)=>{const{columns:g,processRowUpdate:h}=t.current,w=k=>Gl(k,t.current.onProcessRowUpdateError),y=new Map,p=new Map;g.forEach((k,N)=>{y.set(k.field,N),p.set(k.field,k)});const f=[],m=new Map;for(const k of a){const N=r(k.id);if(N===void 0){f.push({id:k.id,field:k.field,reason:"missing"});continue}const M=p.get(k.field);if(k.expect&&!xt(Le(N,k.field,M),k.expect.value)){f.push({id:k.id,field:k.field,reason:"changed"});continue}let S=m.get(k.id);S||(S={id:k.id,row:N,cells:[]},m.set(k.id,S));const F=y.get(k.field)??Number.MAX_SAFE_INTEGER,I=S.cells.findIndex(_=>_.field===k.field),A={field:k.field,value:k.value,colDef:M,order:F};I===-1?S.cells.push(A):S.cells[I]=A}const x=[],b=[],C=o.current;m.forEach(k=>{const{id:N,row:M}=k,S=k.cells.filter(A=>!xt(Le(M,A.field,A.colDef),A.value)).sort((A,_)=>A.order-_.order);if(k.cells=S,S.length===0)return;const F=We(()=>{let A=M;for(const _ of S)A=Bl(A,_,_.colDef,C);return h?h(A,M):A});if(!F.ok){x.push({id:N,ok:!1,error:F.error});return}const I=F.value;$l(I)?b.push(Promise.resolve(I).then(A=>({id:N,ok:!0,processed:A}),A=>({id:N,ok:!1,error:A}))):x.push({id:N,ok:!0,processed:I})});const E=k=>{const N=new Map;k.forEach(A=>{N.set(A.id,A)});const M=[],S=[],F=[],I=new Map;return m.forEach(A=>{const _=N.get(A.id);if(!_)return;if(!_.ok){S.push({id:A.id,error:_.error}),w(_.error);return}const L=_.processed;if(typeof L!="object"||L===null){const v=Hl(L,"The row was not saved.");S.push({id:A.id,error:v}),w(v);return}const D=L;I.set(A.id,D),M.push(A.id);for(const v of A.cells){const V=Le(A.row,v.field,v.colDef),R=Le(D,v.field,v.colDef);xt(V,R)||F.push({id:A.id,field:v.field,before:V,after:R})}}),i(I),F.length>0&&u!=="undo"&&u!=="redo"&&t.current.onCommitted?.(F,u),{result:{updated:M,failed:S,skipped:f},committed:F}};return b.length===0?Promise.resolve(E(x)):Promise.all(b).then(k=>E([...x,...k]))},[r,i]);return s.useMemo(()=>({applyEdits:d,getRow:r,storeRow:l}),[d,r,l])}const dt={ok:!1},$e=e=>({ok:!0,value:e});function ku(e){const t=[];if(e==="")return t;let n=[],o="",r=0;const i=e.length;let l=!0;for(;r<i;){const d=e[r];if(l&&d==='"'){let a=r+1,u="",g=!1;for(;a<i;){const h=e[a];if(h==='"'){if(e[a+1]==='"'){u+='"',a+=2;continue}g=!0,a+=1;break}u+=h,a+=1}if(!g){o+=d,r+=1,l=!1;continue}o+=u,r=a,l=!1;continue}l=!1,d===" "?(n.push(o),o="",l=!0,r+=1):d===`
|
|
4
4
|
`||d==="\r"?(n.push(o),t.push(n),n=[],o="",l=!0,r+=d==="\r"&&e[r+1]===`
|
|
5
|
-
`?2:1):(o+=d,r+=1)}return(!l||n.length>0||o!=="")&&(n.push(o),t.push(n)),t}const xu=/^\d+(?:\.\d*)?(?:e[+-]?\d+)?$/i,yu=/^\.\d+(?:e[+-]?\d+)?$/i,vu=/^\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,Cu=/[\p{Sc}\s]/gu;function _u(e){let t=e.replace(Cu,"");if(t==="")return e.trim()===""?$e(null):dt;let n=!1;t.startsWith("(")&&t.endsWith(")")&&(n=!0,t=t.slice(1,-1)),(t.startsWith("-")||t.startsWith("+")||t.startsWith("−"))&&(t[0]!=="+"&&(n=!n),t=t.slice(1));let o=!1;if(t.endsWith("%")&&(o=!0,t=t.slice(0,-1)),vu.test(t))t=t.split(",").join("");else if(!xu.test(t)&&!yu.test(t))return dt;let r=Number(t);return Number.isFinite(r)?(o&&(r/=100),n&&(r=-r),$e(r)):dt}const Su=/^(\d{4}-\d{2}-\d{2})/,Hl=e=>String(e).padStart(2,"0"),ku=e=>`${e.getFullYear()}-${Hl(e.getMonth()+1)}-${Hl(e.getDate())}`;function Eu(e,t){const n=e.trim();if(n==="")return $e(null);const o=gn(n);if(!o)return dt;if(typeof t=="number")return $e(o.getTime());if(typeof t=="string"){const r=ku(o);return $e(Su.test(t)&&t.length>10?r+t.slice(10):r)}return $e(o)}const Mu=new Set(["true","yes","1"]),Nu=new Set(["false","no","0"]);function Iu(e,t){const n=e.trim().toLowerCase();return n===""?$e(null):t?.trueLabel!==void 0&&n===t.trueLabel.trim().toLowerCase()?$e(!0):t?.falseLabel!==void 0&&n===t.falseLabel.trim().toLowerCase()?$e(!1):Mu.has(n)?$e(!0):Nu.has(n)?$e(!1):dt}function Lu(e,t){const n=e.trim();if(n==="")return $e(null);if(!t||t.length===0)return dt;const o=n.toLowerCase();for(const r of t){const i=typeof r=="object"?r.value:r;if(String(i).toLowerCase()===o)return $e(i)}for(const r of t)if(typeof r=="object"&&r.label.toLowerCase()===o)return $e(r.value);return dt}function Au(e,t,n){switch(t?.type){case"number":return _u(e);case"date":return Eu(e,n?.current);case"boolean":return Iu(e,n?.booleanLabels);case"singleSelect":return Lu(e,t.valueOptions);default:return $e(e)}}function Pu(e,t,n,o){const{valueParser:r}=t;if(!r)return Au(e,t,o);let i;try{i=r(e,{row:n,field:t.field,colDef:t})}catch{return dt}return i===void 0?dt:$e(i)}function ur(e,t,n){const o=e.map(t),r=new Map;o.forEach((a,u)=>{r.has(a)||r.set(a,u)});const i=n.filter(a=>Xe(a.field)),l=new Map;i.forEach((a,u)=>{l.set(a.field,u)});const d=n.filter(a=>Ze(a.field)).length;return{rows:e,rowIds:o,rowIndexById:r,columns:i,colIndexByField:l,dataColumnOffset:d}}function fr(e,t,n,o,r){const i=e.rowIds[o],l=e.columns[r];if(!l||qe(i,t.rowMetaMap))return!1;const d=t.getSpanOrigin?.(i,l.field);return d&&(d.rowId!==i||d.field!==l.field)?!1:Fo({row:n,field:l.field,value:Le(n,l.field,l),colDef:l,rowIndex:o,colIndex:e.dataColumnOffset+r,rowMeta:t.rowMetaMap?.get(i)},t.isCellEditable)}function Tu(e,t){let n=1/0,o=-1/0,r=1/0,i=-1/0;for(const l of t){const d=e.rowIndexById.get(l.id),a=e.colIndexByField.get(l.field);d===void 0||a===void 0||(d<n&&(n=d),d>o&&(o=d),a<r&&(r=a),a>i&&(i=a))}return n===1/0?null:{top:n,bottom:o,left:r,right:i}}function Bl(e,t){return{anchor:{id:e.rowIds[t.top],field:e.columns[t.left].field},head:{id:e.rowIds[t.bottom],field:e.columns[t.right].field}}}function Fu(e){const t=e?.type;return t===void 0||t==="string"||t==="image"}const Wl=1e4,Jn=()=>({updated:[],failed:[],skipped:[]});function Ou(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Pasting ${e} cells. Pastes above ${Wl} cells can be slow; consider importing the data instead.`)}function Du(e){const{apiRef:t,containerRef:n,selection:o,disableClipboardPaste:r,disableRangeClear:i}=e,l=s.useRef(e);s.useLayoutEffect(()=>{l.current=e});const d=s.useCallback(()=>{const{allRenderableRows:p,getRowId:f,navigationColumns:h}=l.current;return ur(p,f,h)},[]),a=s.useCallback(()=>{const{selection:p}=l.current;return p.enabled?p.getCurrentRange().resolved:null},[]),u=s.useCallback(p=>{const f=a();if(f&&p.rowIds[f.top]!==void 0&&p.columns[f.left])return{id:p.rowIds[f.top],field:p.columns[f.left].field};const h=l.current.focusedCell;return h&&h.id!==null&&Xe(h.field)?{id:h.id,field:h.field}:null},[a]),g=s.useCallback(async(p,f,h)=>{const x=d(),b=f??u(x);let v=p;const{onBeforeClipboardPaste:E}=l.current;if(E){const ae=We(()=>E({text:v,anchor:b}));if(!ae.ok)return Wt("onBeforeClipboardPaste","onBeforeClipboardPaste threw; the paste was cancelled",ae.error),Jn();if(ae.value===!1)return Jn();typeof ae.value=="string"&&(v=ae.value)}if(!b)return Jn();const k=bu(v),N=x.rowIndexById.get(b.id),M=x.colIndexByField.get(b.field);if(k.length===0||N===void 0||M===void 0)return Jn();const S=x.rowIds.length-1,D=x.columns.length-1,I=f?null:a(),A=I&&Tt(I)>1?I:null,C=k.length===1&&k[0].length===1,L=k.reduce((ae,R)=>Math.max(ae,R.length),0);let F;C&&A?F=A:F={top:N,left:M,bottom:Math.min(N+k.length-1,S,A?A.bottom:S),right:Math.min(M+L-1,D,A?A.right:D)};const _=Tt(F);_>Wl&&Ou(_);const{batchEdit:z,isCellEditable:K,rowMetaMap:Q,getSpanOrigin:G}=l.current,j={isCellEditable:K,rowMetaMap:Q,getSpanOrigin:G},H=[],ie=[];for(let ae=F.top;ae<=F.bottom;ae++){const R=x.rowIds[ae],te=z.getRow(R)??x.rows[ae],ce=C?k[0]:k[ae-F.top];for(let W=F.left;W<=F.right;W++){const le=C?k[0][0]:ce?.[W-F.left];if(le===void 0)continue;const V=x.columns[W];if(!fr(x,j,te,ae,W)){ie.push({id:R,field:V.field,reason:"notEditable"});continue}const J=Pu(le,V,te,{current:Le(te,V.field,V)});if(!J.ok){ie.push({id:R,field:V.field,reason:"invalidValue"});continue}H.push({id:R,field:V.field,value:J.value})}}if(l.current.selection.enabled){const{anchor:ae,head:R}=Bl(x,F);l.current.selection.setModel([{anchor:ae,head:R}],h?"keyboard":"api")}const re=await z.applyEdits(H,"paste"),ue={updated:re.result.updated,failed:re.result.failed,skipped:[...ie,...re.result.skipped]};return l.current.onClipboardPaste?.({...ue,text:v}),ue},[d,u,a]),m=s.useCallback(()=>{const p=a();if(!p||Tt(p)<=1)return!1;const f=d(),{batchEdit:h,isCellEditable:x,rowMetaMap:b,getSpanOrigin:v}=l.current,E={isCellEditable:x,rowMetaMap:b,getSpanOrigin:v},k=[];for(let N=p.top;N<=p.bottom;N++){const M=f.rowIds[N];if(M===void 0)continue;const S=h.getRow(M)??f.rows[N];for(let D=p.left;D<=p.right;D++){const I=f.columns[D];!I||!fr(f,E,S,N,D)||k.push({id:M,field:I.field,value:Fu(I)?"":null})}}return h.applyEdits(k,"clear"),!0},[a,d]),w=o.enabled&&!r,y=o.enabled&&!i;s.useEffect(()=>{const p=n.current;if(!p||!w&&!y)return;const f=N=>{const M=l.current.viewportRef.current;if(!M||N.defaultPrevented||l.current.isEditing)return!1;const S=Vn(N.target,M);return S==="grid"||S==="control"};let h=null;const x=()=>{if(!h)return;const{textarea:N,restore:M,timer:S}=h;h=null,window.clearTimeout(S);const D=document.activeElement===N;N.remove(),D&&M&&M.isConnected&&M.focus({preventScroll:!0})},b=()=>{x();const N=document.createElement("textarea");N.setAttribute("aria-hidden","true"),N.tabIndex=-1,N.className="ogx__paste-capture",N.style.cssText="position:fixed;top:0;left:-10000px;width:1px;height:1px;opacity:0;",p.appendChild(N);const M=document.activeElement instanceof HTMLElement?document.activeElement:null;h={textarea:N,restore:M,timer:window.setTimeout(x,250)},N.focus({preventScroll:!0})},v=N=>h!==null&&N.target===h.textarea,E=N=>{if(v(N)){const S=N.clipboardData?N.clipboardData.getData("text/plain"):"";N.preventDefault(),x(),S!==""&&g(S,void 0,!0);return}if(!w||!f(N)||!l.current.navigationColumns.some(S=>S.editable))return;const M=N.clipboardData?N.clipboardData.getData("text/plain"):"";M!==""&&(N.preventDefault(),g(M,void 0,!0))},k=N=>{if((N.ctrlKey||N.metaKey)&&!N.altKey&&!N.shiftKey&&(N.key==="v"||N.key==="V"||N.code==="KeyV")){w&&f(N)&&l.current.navigationColumns.some(M=>M.editable)&&b();return}!y||N.key!=="Delete"&&N.key!=="Backspace"||N.ctrlKey||N.metaKey||N.altKey||N.shiftKey||f(N)&&m()&&N.preventDefault()};return p.addEventListener("paste",E),p.addEventListener("keydown",k),()=>{x(),p.removeEventListener("paste",E),p.removeEventListener("keydown",k)}},[n,w,y,g,m]),s.useLayoutEffect(()=>{t.current.pasteText=(p,f)=>g(p,f,!1)},[t,g])}const $u=100;function Gu(){const e=s.useRef(null),t=s.useCallback((o,r)=>{const i=e.current;i&&i(o,r)},[]),n=s.useCallback(o=>{e.current=o},[]);return s.useMemo(()=>({emit:t,setListener:n}),[t,n])}const Vl=()=>({updated:[],failed:[],skipped:[]});function Hu(e){if(e.altKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t),o=t==="z"||!n&&e.code==="KeyZ",r=t==="y"||!n&&e.code==="KeyY";return o?e.shiftKey?"redo":"undo":r&&e.ctrlKey&&!e.shiftKey?"redo":null}function Bu(e){const{apiRef:t,enabled:n,channel:o,containerRef:r}=e,i=s.useRef(e);s.useLayoutEffect(()=>{i.current=e});const l=s.useRef([]),d=s.useRef([]),a=s.useRef({canUndo:!1,canRedo:!1,size:0}),u=s.useRef(Promise.resolve()),g=s.useCallback(()=>{const x={canUndo:l.current.length>0,canRedo:d.current.length>0,size:l.current.length},b=a.current;b.canUndo===x.canUndo&&b.canRedo===x.canRedo&&b.size===x.size||(a.current=x,i.current.onHistoryChange?.(x))},[]),m=s.useCallback(x=>{if(!i.current.enabled||x.length===0)return;const b=l.current;b.push(x);const v=Math.max(1,i.current.limit);b.length>v&&b.splice(0,b.length-v),d.current=[],g()},[g]);s.useLayoutEffect(()=>(o.setListener(n?m:null),()=>o.setListener(null)),[o,n,m]);const w=s.useCallback(()=>{l.current=[],d.current=[],g()},[g]);s.useEffect(()=>{n||w()},[n,w]);const y=s.useCallback(x=>{const b=i.current,v=ur(b.allRenderableRows,b.getRowId,b.navigationColumns),E=Tu(v,x);if(!E)return;const{anchor:k,head:N}=Bl(v,E);b.selection.enabled?b.selection.setModel([{anchor:k,head:N}],"keyboard"):b.setFocusedCell({id:k.id,field:k.field,rowIndex:E.top});const M=b.viewportRef.current;M&&(Gn(M,E.top-b.pinnedTopRowCount,b.layout.cumulativeHeights,b.layout.pinnedBottomHeight,b.rowHeight),To(M,b.layout.unpinnedColsWithWidth.findIndex(S=>S.field===k.field),b.layout))},[]),p=s.useCallback(x=>{const b=async()=>{if(!i.current.enabled)return Vl();const E=x==="undo"?l:d,k=x==="undo"?d:l,N=E.current.pop();if(!N)return Vl();g();const M=N.map(I=>x==="undo"?{id:I.id,field:I.field,value:I.before,expect:{value:I.after}}:{id:I.id,field:I.field,value:I.after,expect:{value:I.before}}),S=await i.current.batchEdit.applyEdits(M,x);S.committed.length>0&&k.current.push(x==="undo"?S.committed.map(I=>({id:I.id,field:I.field,before:I.after,after:I.before})):S.committed);const D=new Set(S.result.failed.map(I=>I.id));if(D.size>0){const I=N.filter(A=>D.has(A.id));I.length>0&&E.current.push(I)}return g(),S.committed.length>0&&y(S.committed),S.result},v=u.current.then(b,b);return u.current=v,v},[g,y]),f=s.useCallback(()=>p("undo"),[p]),h=s.useCallback(()=>p("redo"),[p]);s.useEffect(()=>{const x=r.current;if(!x||!n)return;const b=v=>{if(v.defaultPrevented)return;const E=Hu(v);if(!E)return;const k=i.current.viewportRef.current;if(!k||i.current.isEditing)return;const N=Vn(v.target,k);N!=="grid"&&N!=="control"||(v.preventDefault(),E==="undo"?f():h())};return x.addEventListener("keydown",b),()=>x.removeEventListener("keydown",b)},[r,n,f,h]),s.useLayoutEffect(()=>{const x=t.current;x.undo=f,x.redo=h,x.canUndo=()=>i.current.enabled&&l.current.length>0,x.canRedo=()=>i.current.enabled&&d.current.length>0,x.clearHistory=w},[t,f,h,w])}function Wu(e){const t=String(e);if(t.includes("e")||t.includes("E"))return null;const n=t.indexOf(".");return n===-1?0:t.length-n-1}function gr(e,t){return t===null?e:Number(e.toFixed(Math.min(t,20)))}function Vu(e,t){let n=0;for(const l of e){const d=Wu(l);n=d===null||n===null?null:Math.max(n,d)}const o=gr(e[1]-e[0],n);for(let l=2;l<e.length;l++)if(gr(e[l]-e[l-1],n)!==o)return null;const r=e[e.length-1],i=[];for(let l=1;l<=t;l++)i.push(gr(r+o*l,n));return i}const zu=864e5,zl=e=>((e.getHours()*60+e.getMinutes())*60+e.getSeconds())*1e3+e.getMilliseconds(),Ku=e=>Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/zu),ju=e=>e.getFullYear()*12+e.getMonth(),Uu=(e,t)=>new Date(e,t+1,0).getDate();function pr(e){const t=e[1]-e[0];for(let n=2;n<e.length;n++)if(e[n]-e[n-1]!==t)return null;return t}function Ru(e,t){const n=e[e.length-1],o=e.every(l=>zl(l)===zl(n));if(o&&e.every(l=>l.getDate()===n.getDate())){const l=pr(e.map(ju));if(l!==null&&l!==0){const d=[];for(let a=1;a<=t;a++){const u=n.getMonth()+l*a,g=n.getFullYear()+Math.floor(u/12),m=(u%12+12)%12,w=new Date(n.getTime());w.setFullYear(g,m,Math.min(n.getDate(),Uu(g,m))),d.push(w)}return d}}if(o){const l=pr(e.map(Ku));if(l===null)return null;const d=[];for(let a=1;a<=t;a++){const u=new Date(n.getTime());u.setDate(n.getDate()+l*a),d.push(u)}return d}const r=pr(e.map(l=>l.getTime()));if(r===null)return null;const i=[];for(let l=1;l<=t;l++)i.push(new Date(n.getTime()+r*l));return i}const qu=e=>typeof e=="number"&&Number.isFinite(e),Xu=e=>e instanceof Date&&!Number.isNaN(e.getTime());function Yu(e,t){return e.length<2?null:e.every(qu)?Vu(e,t):e.every(Xu)?Ru(e,t):null}const Ju=e=>e instanceof Date?new Date(e.getTime()):e;function Zu(e,t,n){if(e.length===0||t<=0)return[];const o=n?Yu(e,t):null;if(o)return o;const r=[];for(let i=0;i<t;i++)r.push(Ju(e[i%e.length]));return r}function Qu(e,t,n,o){const r=t.row>e.bottom||t.row<e.top,i=t.col>e.right||t.col<e.left;return!r&&!i?null:r&&(!i||Math.abs(o)>=Math.abs(n))?t.row>e.bottom?{rect:{...e,bottom:t.row},direction:"down"}:{rect:{...e,top:t.row},direction:"up"}:t.col>e.right?{rect:{...e,right:t.col},direction:"right"}:{rect:{...e,left:t.col},direction:"left"}}function ef(e,t,n){const o=(a,u)=>{const g=[];if(a<=u)for(let m=a;m<=u;m++)g.push(m);else for(let m=a;m>=u;m--)g.push(m);return g},i=n==="down"||n==="up"?o(e.left,e.right):o(e.top,e.bottom);let l,d;switch(n){case"down":l=o(e.top,e.bottom),d=t.bottom>e.bottom?o(e.bottom+1,t.bottom):[];break;case"up":l=o(e.bottom,e.top),d=t.top<e.top?o(e.top-1,t.top):[];break;case"right":l=o(e.left,e.right),d=t.right>e.right?o(e.right+1,t.right):[];break;default:l=o(e.right,e.left),d=t.left<e.left?o(e.left-1,t.left):[]}return i.map(a=>({line:a,source:l,targets:d}))}function tf(e,t,n){const o=n.row===e.top||n.row===e.bottom,r=n.col===e.left||n.col===e.right;let i=n.row,l=n.col;return(!o||!r)&&(t==="down"||t==="up"?(i=t==="down"?e.top:e.bottom,l=n.col===e.right?e.right:e.left):(l=t==="right"?e.left:e.right,i=n.row===e.bottom?e.bottom:e.top)),{anchor:{row:i,col:l},head:{row:i===e.top?e.bottom:e.top,col:l===e.left?e.right:e.left}}}function nf(e,t,n,o){const r=t(e.bottom),i=n[e.right];if(r===void 0||i===void 0)return null;const l=o?.(r,i);if(!l||l.rowId===r&&l.field===i)return{row:e.bottom,field:i};for(let d=e.bottom;d>=Math.max(0,e.bottom-of);d--)if(t(d)===l.rowId)return{row:d,field:l.field};return null}const of=1e3,rf="ogx__cell-fill-handle";function lf(e){if(e.altKey||e.shiftKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t);return t==="d"||!n&&e.code==="KeyD"?"down":t==="r"||!n&&e.code==="KeyR"?"right":null}function sf(e){const{containerRef:t,viewportRef:n,selection:o,disableFillHandle:r,isEditing:i,allRenderableRows:l,getRowId:d,navigationColumns:a,columnIndexMap:u,getSpanOrigin:g}=e,m=s.useRef(e);s.useLayoutEffect(()=>{m.current=e});const w=o.enabled&&!r,y=s.useMemo(()=>a.some(S=>S.editable),[a]),p=o.resolved,f=s.useMemo(()=>{if(!w||!y||!p)return null;const S=a.filter(C=>Xe(C.field)).map(C=>C.field),I=nf(p,C=>{const L=l[C];return L===void 0?void 0:d(L)},S,g);if(!I)return null;const A=u.get(I.field);return A===void 0?null:{row:I.row,col:A}},[w,y,p,l,d,a,u,g]),h=s.useRef(!0);s.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const x=s.useCallback(()=>{const S=m.current;return ur(S.allRenderableRows,S.getRowId,S.navigationColumns)},[]),b=s.useCallback((S,D,I,A,C)=>{const L=tf(D,I,A),F=_=>({id:S.rowIds[_.row],field:S.columns[_.col].field});m.current.selection.setModel([{anchor:F(L.anchor),head:F(L.head)}],C)},[]),v=s.useCallback(async(S,D,I,A,C,L,F)=>{const{batchEdit:_,isCellEditable:z,rowMetaMap:K,getSpanOrigin:Q}=m.current,G={isCellEditable:z,rowMetaMap:K,getSpanOrigin:Q},j=A==="down"||A==="up",H=R=>{const te=S.rowIds[R];return te===void 0?void 0:_.getRow(te)??S.rows[R]},ie=[],re=[];for(const R of ef(D,I,A)){if(R.targets.length===0)continue;const te=le=>j?{r:le,c:R.line}:{r:R.line,c:le},ce=[];for(const le of R.source){const{r:V,c:J}=te(le),ne=H(V),fe=S.columns[J];!ne||!fe||qe(S.rowIds[V],K)||ce.push(Le(ne,fe.field,fe))}if(ce.length===0)continue;const W=Zu(ce,R.targets.length,!C);R.targets.forEach((le,V)=>{const{r:J,c:ne}=te(le),fe=H(J),Z=S.columns[ne],$=S.rowIds[J];if(!fe||!Z||$===void 0)return;if(!fr(S,G,fe,J,ne)){re.push({id:$,field:Z.field,reason:"notEditable"});return}let O=W[V];const P=Z.fillValue;if(P){const T=We(()=>P.call(Z,{row:fe,id:$,field:Z.field,colDef:Z,direction:A,sourceValues:ce.slice(),index:V,value:O,copy:C}));if(!T.ok){Wt(`fillValue:${Z.field}`,`fillValue of column "${Z.field}" threw; the cell was skipped`,T.error),re.push({id:$,field:Z.field,reason:"invalidValue"});return}O=T.value}ie.push({id:$,field:Z.field,value:O})})}b(S,I,A,L,F);const ue=await _.applyEdits(ie,"fill"),ae={updated:ue.result.updated,failed:ue.result.failed,skipped:[...re,...ue.result.skipped],direction:A};return m.current.onFill?.(ae),ae},[b]),E=s.useRef(null),k=s.useCallback((S,D,I)=>{const A=E.current,C=m.current.viewportRef.current;if(!A||!C)return;const L=A.ctx,F=L.rowIndexById.get(S.id),_=L.colIndexByField.get(S.field);if(F===void 0||_===void 0)return;const z=D-A.x+C.scrollLeft-A.scrollLeft,K=I-A.y+C.scrollTop-A.scrollTop,Q=Qu(A.source,{row:F,col:_},z,K);A.target=Q,Q?b(L,Q.rect,Q.direction,A.anchor,"pointer"):m.current.selection.setModel(A.sourceModel,"pointer")},[b]),N=s.useCallback(({cancelled:S,altKey:D})=>{const I=E.current;if(E.current=null,!I||!h.current)return;const A=I.ctx;if(S||!I.target){m.current.selection.setModel(I.sourceModel,"pointer");return}v(A,I.source,I.target.rect,I.target.direction,D,I.anchor,"pointer")},[v]),M=w&&y;return s.useEffect(()=>{const S=n.current;if(!S||!M)return;const D=I=>{if(I.button!==0||!(I.target instanceof Element))return;const A=I.target.closest(`.${rf}`);if(!A||A.closest(".ogx__viewport")!==S||m.current.isEditing)return;const{selection:C}=m.current,{range:L,resolved:F}=C.getCurrentRange();if(!L||!F)return;const _=x(),z=_.rowIds[F.bottom],K=_.columns[F.right];if(z===void 0||!K)return;I.preventDefault();const Q=S.ownerDocument;S.contains(Q.activeElement)||S.focus({preventScroll:!0}),We(()=>S.setPointerCapture(I.pointerId)),E.current={source:{top:F.top,bottom:F.bottom,left:F.left,right:F.right},sourceModel:[L],anchor:{row:F.anchorRow,col:F.anchorCol},ctx:_,x:I.clientX,y:I.clientY,scrollLeft:S.scrollLeft,scrollTop:S.scrollTop,target:null},C.startTrackedDrag({start:{id:z,field:K.field},x:I.clientX,y:I.clientY,pointerId:I.pointerId,onTrack:k,onEnd:N})};return S.addEventListener("pointerdown",D),()=>S.removeEventListener("pointerdown",D)},[n,M,x,k,N]),s.useEffect(()=>{const S=t.current;if(!S||!w)return;const D=I=>{if(I.defaultPrevented)return;const A=lf(I);if(!A)return;const C=m.current.viewportRef.current;if(!C||m.current.isEditing)return;const L=Vn(I.target,C);if(L!=="grid"&&L!=="control")return;const{range:F,resolved:_}=m.current.selection.getCurrentRange();if(!F||!_)return;I.preventDefault();const z={top:_.top,bottom:_.bottom,left:_.left,right:_.right},K=A==="down"?{...z,bottom:z.top}:{...z,right:z.left};(A==="down"?z.bottom===z.top:z.right===z.left)||v(x(),K,z,A,!0,{row:_.anchorRow,col:_.anchorCol},"keyboard")};return S.addEventListener("keydown",D),()=>S.removeEventListener("keydown",D)},[t,w,v,x]),{handle:i?null:f}}const af=e=>e.id,cf={hasColSpan:!1,hasRowSpan:!1,colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},getSpanOrigin:()=>null,getUnpinnedColSpanRanges:()=>{},getCenterRowSpanStart:e=>e},Kl="\0",jl="";function Ul(e){if(typeof e!="number"||Number.isNaN(e))return 1;if(e===1/0)return Number.MAX_SAFE_INTEGER;if(!Number.isFinite(e))return 1;const t=Math.floor(e);return t<1?1:t}function df(e){return e.map(t=>t.field).join(Kl)}function uf(e){const{pinnedTopRows:t,centerRows:n,pinnedBottomRows:o,columns:r,leftPinnedColumns:i,unpinnedColumns:l,rightPinnedColumns:d,expandedRowIds:a,rowMetaMap:u,getRowId:g=af}=e,m=s.useMemo(()=>r.some(x=>x.colSpan!==void 0&&x.colSpan!==null),[r]),w=s.useMemo(()=>r.some(x=>x.rowSpan!==void 0&&x.rowSpan!==null),[r]),y=m||w,p=y?[i,l,d].map(df).join(jl):"",f=s.useMemo(()=>{if(!p)return{columns:[],leftCount:0,unpinnedCount:0};const x=new Map(r.map(k=>[k.field,k])),b=p.split(jl).map(k=>k?k.split(Kl):[]),v=[];let E=0;for(const k of b){E+=k.length;for(const N of k){const M=x.get(N)??{field:N};v.push({colDef:M,field:N,sectionEnd:E,hasColSpan:M.colSpan!==void 0&&M.colSpan!==null,hasRowSpan:M.rowSpan!==void 0&&M.rowSpan!==null})}}return{columns:v,leftCount:b[0].length,unpinnedCount:b[1].length}},[p,r]),h=s.useMemo(()=>{if(!y||f.columns.length===0)return null;const x={colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},hiddenOriginFields:new Map,unpinnedRanges:new Map,centerRowSpanStart:new Map},v={spanColumns:f,expandedRowIds:a,rowMetaMap:u,getRowId:g,warned:new Set,out:x};return hr(t,0,!1,v),hr(n,t.length,!0,v),hr(o,t.length+n.length,!1,v),x},[y,f,t,n,o,a,u,g]);return s.useMemo(()=>{if(!h)return cf;const{colspanMap:x,rowSpanningCaches:b,hiddenOriginFields:v,unpinnedRanges:E,centerRowSpanStart:k}=h,N=f.columns;return{hasColSpan:m,hasRowSpan:w,colspanMap:x,rowSpanningCaches:b,getSpanOrigin:(M,S)=>{const D=x.get(M)?.[S];if(D?.spannedByColSpan)return{rowId:M,field:N[D.leftVisibleCellIndex].field};const I=b.hiddenCellOriginMap[M]?.[S];return I===void 0?null:{rowId:I,field:v.get(M)?.[S]??S}},getUnpinnedColSpanRanges:M=>E.get(M),getCenterRowSpanStart:M=>k.get(M)??M}},[h,m,w,f])}function hr(e,t,n,o){const{spanColumns:r,expandedRowIds:i,rowMetaMap:l,getRowId:d,warned:a,out:u}=o,{columns:g,leftCount:m,unpinnedCount:w}=r,y=g.length,{colspanMap:p,rowSpanningCaches:f,hiddenOriginFields:h,unpinnedRanges:x,centerRowSpanStart:b}=u,v=new Int32Array(y),E=new Array(y),k=new Array(y),N=new Int32Array(y);let M=0;const S=[];g.forEach((A,C)=>{(A.hasColSpan||A.hasRowSpan)&&S.push(C)});const D=(A,C,L)=>{const F=g[L].field;if(Xt(f.hiddenCells,A,F,!0),Xt(f.hiddenCellOriginMap,A,F,E[L]),k[L]!==F&&Xt(h,A,F,k[L]),n){const _=b.get(C);(_===void 0||N[L]<_)&&b.set(C,N[L])}},I=(A,C,L)=>{const F=g[L],_=d(A),z=ff(A,_,F.colDef,t+C,L,l,a);let K=1;if(F.hasColSpan){const G=Math.min(Rl(F.colDef.colSpan,z,"colSpan",F.field,a),F.sectionEnd-L);for(;K<G&&v[L+K]<=C;)K++}let Q=1;if(F.hasRowSpan){Q=Math.min(Rl(F.colDef.rowSpan,z,"rowSpan",F.field,a),e.length-C);for(let G=1;G<Q;G++)if(qe(d(e[C+G]),l)){Q=G;break}if(Q>1&&i&&i.size>0){for(let G=0;G<Q-1;G++)if(i.has(d(e[C+G]))){Q=G+1;break}}}if(K>1){Xt(p,_,F.field,{spannedByColSpan:!1,cellProps:{colSpan:K}});for(let G=1;G<K;G++){const j=g[L+G];Xt(p,_,j.field,{spannedByColSpan:!0,leftVisibleCellIndex:L,rightVisibleCellIndex:L+K-1})}if(L>=m&&L<m+w){let G=x.get(_);G||(G=[],x.set(_,G)),G.push(L-m,L+K-1-m)}}if(Q>1){Xt(f.spannedCells,_,F.field,Q);for(let G=L;G<L+K;G++)v[G]=C+Q,E[G]=_,k[G]=F.field,N[G]=C;C+Q>M&&(M=C+Q)}return K};for(let A=0;A<e.length;A++){const C=e[A];if(!C||C._isSkeleton||qe(d(C),l))continue;if(M<=A){let F=0;for(const _ of S)_>=F&&(F=_+I(C,A,_));continue}let L=0;for(;L<y;)v[L]>A?(D(d(C),A,L),L++):g[L].hasColSpan||g[L].hasRowSpan?L+=I(C,A,L):L++}}function ff(e,t,n,o,r,i,l){const d=e[n.field];let a=d;if(n.valueGetter)try{a=n.valueGetter({row:e,field:n.field,value:d})}catch(u){ql(l,`valueGetter:${n.field}`,`valueGetter for column "${n.field}" threw while computing its span`,u),a=void 0}return{row:e,value:a,field:n.field,colDef:n,rowIndex:o,colIndex:r,rowMeta:i?.get(t)}}function Rl(e,t,n,o,r){if(typeof e=="number")return Ul(e);if(typeof e!="function")return 1;try{return Ul(e(t))}catch(i){return ql(r,`${n}:${o}`,`${n} for column "${o}" threw; the cell is rendered without a span`,i),1}}function ql(e,t,n,o){process.env.NODE_ENV==="production"||e.has(t)||(e.add(t),console.warn(`[OpenGridX] ${n}.`,o))}function Xt(e,t,n,o){if(e instanceof Map){let i=e.get(t);i||(i={},e.set(t,i)),i[n]=o;return}let r=e[t];r||(r={},e[t]=r),r[n]=o}function gf(e){const{spanning:t,renderContext:n,offsetTop:o,cumulativeHeights:r}=e;return s.useMemo(()=>{if(!t.hasRowSpan)return{renderContext:n,offsetTop:o};let i=Math.max(0,n.firstRowIndex);for(let l=t.getCenterRowSpanStart(i);l<i;l=t.getCenterRowSpanStart(i))i=l;return i>=n.firstRowIndex?{renderContext:n,offsetTop:o}:{renderContext:{...n,firstRowIndex:i},offsetTop:i>0?r[i-1]??0:0}},[t,n,o,r])}function pf(e){const{spanning:t,firstColumnIndex:n,lastColumnIndex:o,virtualColumns:r,layout:i,rows:l}=e;return s.useMemo(()=>{if(!t.hasColSpan||i.unpinnedColsWithWidth.length===0)return r;let d=n,a=o,u=!0;for(;u;){u=!1;for(const{row:x,id:b}of l){const v=t.getUnpinnedColSpanRanges(b??x.id);if(v)for(let E=0;E<v.length;E+=2){const k=v[E],N=v[E+1];N<d||k>a||(k<d&&(d=k,u=!0),N>a&&(a=N,u=!0))}}}if(d===n&&a===o)return r;const{leftPinnedCols:g,unpinnedColsWithWidth:m,rightPinnedCols:w,unpinnedAccWidths:y,unpinnedTotalWidth:p}=i,f=d>0?y[d-1]:0,h=p-y[a];return[...g,...f>0?[{field:"__spacer_left__",width:f,isSpacer:!0}]:[],...m.slice(d,a+1),...h>0?[{field:"__spacer_right__",width:h,isSpacer:!0}]:[],...w]},[t,n,o,r,i,l])}function hf(e,t){const{draggedColumn:n,onDragOver:o,onDrop:r,onDragEnd:i}=t,l=s.useMemo(()=>{if(!e||e.length===0)return null;const d=a=>n===null||rr(e,n,a);return{onDragOver:o&&(a=>d(a)?o(a):()=>{}),onDrop:r&&(a=>d(a)?r(a):u=>{u.preventDefault(),i?.()})}},[e,n,o,r,i]);return l?{...t,...l}:t}const mf=300,Xl=e=>e.id;function wf(e,t){return e==="infinite"?"infinite":e==="server"?t?"all":"page":"all"}function Yl(e,t){const n=new Set,o=[];return e.forEach(r=>{const i=t(r);n.has(i)||(n.add(i),o.push({id:i,row:r}))}),o}function Jl(e,t,n){const o=new Set(e.map(n)),r=t.filter(i=>!o.has(i.id)).map(i=>i.row);return r.length===0?e:[...e,...r]}function bf(e){const{dataSource:t,sortModel:n,filterModel:o,paginationModel:r,paginationMode:i,sortingMode:l,filterMode:d,aggregationModel:a,rowGroupingActive:u=!1}=e,g=wf(i,u),m=!!t&&i==="server"&&u,w=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||w.current||!m||(w.current=!0,console.warn("[OpenGridX] `rowGroupingModel` turns pagination off, so the dataSource with `paginationMode: 'server'` is asked for every row (startRow 0, endRow Number.MAX_SAFE_INTEGER) instead of one page. See docs/features/data-source.md."))},[m]);const y=t?.getRows,p=il({dataSource:t,paginationMode:i,sortingMode:l,filterMode:d}),f=JSON.stringify([g,g!=="all"||l==="server"?n:null,g!=="all"||d==="server"?o:null,p?a??null:null,g==="all"?null:r.pageSize]),h=g==="all"?0:r.page,x=g==="all"?0:r.pageSize,b=s.useRef({params:e,kind:g});s.useLayoutEffect(()=>{b.current={params:e,kind:g}});const v=s.useRef(0),E=s.useRef(0),k=s.useRef(null),N=s.useRef({page:0,loadedEnd:0,inFlightEnd:null}),M=s.useRef(null),S=s.useRef(!1),D=s.useRef(0),I=s.useRef(!1),A=s.useRef(new Set),C=s.useCallback(()=>{const j=S.current||D.current>0;j!==I.current&&(I.current=j,b.current.params.setDataSourceLoading(j))},[]),L=s.useCallback(()=>{M.current!==null&&(clearTimeout(M.current),M.current=null)},[]),F=s.useCallback(()=>{v.current++,N.current.inFlightEnd=null,S.current=!1},[]),_=s.useCallback(()=>{E.current++,A.current.clear(),D.current=0},[]),z=s.useCallback(async()=>{const{params:j,kind:H}=b.current,ie=j.dataSource;if(!ie)return!1;const re=N.current,ue=j.paginationModel.pageSize;let ae,R;if(H==="infinite"){if(re.inFlightEnd!==null)return!1;if(ae=re.loadedEnd,R=(re.page+1)*ue,R<=ae)return S.current=!1,C(),!1;re.inFlightEnd=R}else H==="page"?(ae=j.paginationModel.page*ue,R=ae+ue):(ae=0,R=ll);const te=++v.current;S.current=!0,C(),j.setDataSourceError(null);let ce;try{ce=await ie.getRows({startRow:ae,endRow:R,sortModel:j.sortModel,filterModel:j.filterModel,groupKeys:[],aggregationModel:j.aggregationModel})}catch(W){return te!==v.current||(re.inFlightEnd=null,S.current=!1,b.current.params.setDataSourceError(W),console.error("Data Source Error:",W),C()),!1}if(te!==v.current)return!1;try{const{params:W}=b.current,le=W.getRowId??Xl,V=Yl(ce.rows,le);if(H==="infinite"&&ae>0?W.setRows(J=>Jl(J,V,le),!0):(W.setRows(V.map(J=>J.row),!0),_()),ce.aggregationResults&&W.onAggregationResults?.(ce.aggregationResults),ce.rowCount!==void 0&&W.setRowCount(ce.rowCount),H==="infinite"&&(re.inFlightEnd=null,re.loadedEnd=ae+ce.rows.length,ce.rows.length>=R-ae&&(re.page+1)*ue>R))return!0}catch(W){return re.inFlightEnd=null,S.current=!1,b.current.params.setDataSourceError(W),console.error("Data Source Error:",W),C(),!1}return S.current=!1,C(),!1},[C,_]),K=s.useCallback(async()=>{for(;await z(););},[z]);s.useLayoutEffect(()=>{if(!y){k.current&&(k.current=null,L(),F(),_(),b.current.params.setDataSourceError(null),C());return}const j=k.current,H=N.current;if(!j||j.key!==f||j.getRows!==y){k.current={key:f,getRows:y},F(),_();const ie=g==="infinite"&&j!==null&&h!==0;if(H.page=ie?0:h,H.loadedEnd=0,ie){const{params:re}=b.current;re.onPaginationModelChange?.({...re.paginationModel,page:0})}}else g==="infinite"?(h<H.page&&(F(),H.loadedEnd=0),H.page=h):F();if(g==="infinite"){const ie=H.inFlightEnd!==null;if(ie||(H.page+1)*x<=H.loadedEnd){S.current=ie,C();return}}return S.current=!0,C(),M.current=setTimeout(()=>{M.current=null,K()},mf),L},[y,f,g,h,x,L,F,_,C,K]),s.useEffect(()=>()=>{F(),_()},[F,_]);const Q=s.useCallback(()=>(L(),K()),[L,K]),G=s.useCallback(async(j,H,ie)=>{const{params:re}=b.current,ue=re.dataSource;if(!ue)return;const ae=JSON.stringify(H),R=A.current;if(R.has(ae))return;const te=E.current;R.add(ae),D.current++,C();try{const ce=await ue.getRows({startRow:0,endRow:ll,sortModel:re.sortModel,filterModel:re.filterModel,groupKeys:H,aggregationModel:re.aggregationModel});if(te!==E.current)return;if(ce.rows.length>0){const{params:W}=b.current,le=W.getRowId??Xl,V=Yl(ce.rows,le);W.setRows(J=>Jl(J,V,le),!0)}}catch(ce){if(te!==E.current)return;R.delete(ae),console.error("Failed to fetch children:",ce),ie?.(ce)}finally{te===E.current&&(D.current--,C())}},[C]);return{fetchRows:Q,fetchChildren:G}}function xf(e){return(e.serverChildrenCount??0)>0&&(e.children?.length??0)===0}function yf({enabled:e,treeNodes:t,isGroupExpanded:n,getNodePath:o,toggleExpansion:r,fetchChildren:i}){const l=s.useRef({isGroupExpanded:n,toggleExpansion:r});s.useLayoutEffect(()=>{l.current={isGroupExpanded:n,toggleExpansion:r}}),s.useEffect(()=>{e&&t.forEach((d,a)=>{!xf(d)||!n(a)||i(a,o(a),()=>{const{isGroupExpanded:u,toggleExpansion:g}=l.current;u(a)&&g(a)})})},[e,t,n,o,i])}const Zl={};function vf(e){const t=JSON.stringify(e),[n,o]=s.useState(null),r=s.useCallback(i=>o({modelKey:t,results:i}),[t]);return[n&&n.modelKey===t?n.results:null,r]}function Ql(e){const{rows:t,columns:n,aggregationModel:o,isServerSide:r,dataSource:i,filterModel:l,sortModel:d,serverAggregationResults:a}=e,u=Object.keys(o).length>0,g=s.useMemo(()=>{const k=new Map;return(n??[]).forEach(N=>k.set(N.field,N)),k},[n]),m=s.useMemo(()=>r||!u?Zl:Hn(t,o,g,"useAggregation"),[t,g,o,r,u]),w=JSON.stringify([o,l??null,d??[]]),y=r&&u&&!!i?.getAggregations&&!a,p=s.useRef({aggregationModel:o,filterModel:l,sortModel:d});s.useEffect(()=>{p.current={aggregationModel:o,filterModel:l,sortModel:d}});const[f,h]=s.useState(null);s.useEffect(()=>{const k=i?.getAggregations;if(!y||!k)return;let N=!1;const M=p.current,S={sortModel:M.sortModel??[],filterModel:M.filterModel??{items:[]},groupKeys:[],aggregationModel:M.aggregationModel};let D;try{D=Promise.resolve(k(S))}catch(I){D=Promise.reject(I)}return D.then(I=>{N||h({key:w,result:I,error:null})},I=>{N||(console.error("[useAggregation] Server aggregation error:",I),h({key:w,result:null,error:I}))}),()=>{N=!0}},[y,i,w]);const x=f&&f.key===w?f:null,b=y&&x===null,v=y?x?.error??null:null;return{aggregationResult:s.useMemo(()=>r?a&&Object.keys(a).length>0?a:x?.result??Zl:m,[r,m,a,x]),isLoading:b,error:v}}const Cf={items:[]},_f=[];function Sf(e){const{rows:t,columns:n,pivotMode:o,pivotModel:r,filterModel:i,sortModel:l,hasDataSource:d,hierarchyRequested:a}=e,u=o&&!d,g=s.useMemo(()=>new Set(n.map(x=>x.field)),[n]),m=s.useMemo(()=>jo(n),[n]),w=s.useMemo(()=>Ya(i,g),[i,g]),y=s.useMemo(()=>u?Ho(t,w.source,m):t,[u,t,w.source,m]),p=s.useMemo(()=>u?Li(y,n,r,{outputFilterModel:w.output,sortModel:l}):Ro,[u,y,n,r,w.output,l]),f=u&&p.isValid,h=s.useRef({dataSource:!1,hierarchy:!1});return s.useEffect(()=>{process.env.NODE_ENV!=="production"&&(o&&d&&!h.current.dataSource&&(h.current.dataSource=!0,console.warn("[OpenGridX] `pivotMode` is ignored when a `dataSource` is set: pivoting is client-side and the grid only holds the rows of one server page. Pivot on the server, or pass the full dataset as `rows`.")),f&&a&&!h.current.hierarchy&&(h.current.hierarchy=!0,console.warn("[OpenGridX] `treeData` and `rowGroupingModel` are turned off while `pivotMode` is active: the pivot rows are already grouped by the pivot row fields.")))},[o,d,f,a]),{isActive:f,rows:f?p.pivotRows:t,columns:f?p.pivotColumns:n,pipelineFilterModel:f?Cf:i,pipelineSortModel:f?_f:l}}const tt=({variant:e="text",size:t="medium",color:n="default",disabled:o=!1,className:r="",type:i="button",children:l,...d})=>{const a=["ogx-button",`ogx-button--${e}`,`ogx-button--${t}`,`ogx-button--${n}`,o&&"ogx-button--disabled",r].filter(Boolean).join(" ");return c.jsx("button",{type:i,className:a,disabled:o,...d,children:l})};function mr(e){const t=s.useId(),{page:n,pageSize:o,rowCount:r,onPageChange:i,onPageSizeChange:l,pageSizeOptions:d=[10,25,50,100],showFirstButton:a=!0,showLastButton:u=!0,localeText:g}=e,m=Un(o),w=Zo(r,m),y=Ui(n,w),p=d.includes(m)?d:[...d,m].sort((C,L)=>C-L),f=y*m,h=Math.min(f+m,r),x=r===0?0:`${f+1}–${h}`,b=g?.paginationRowsPerPage??"Rows per page:",v=g?.paginationOf?g.paginationOf(r===0?0:f+1,h,r):`${x} of ${r}`,E=g?.paginationPage?g.paginationPage(y+1,w):`Page ${y+1} of ${w}`,k=()=>{i(0)},N=()=>{i(Math.max(0,y-1))},M=()=>{i(Math.min(w-1,y+1))},S=()=>{i(w-1)},D=C=>{const L=parseInt(C.target.value,10);l(L)},I=y===0,A=y>=w-1;return c.jsxs("div",{className:"ogx-pagination",role:"navigation","aria-label":"Pagination",children:[c.jsxs("div",{className:"ogx-pagination__page-size",children:[c.jsx("label",{htmlFor:t,className:"ogx-pagination__label",children:b}),c.jsx("select",{id:t,className:"ogx-pagination__select",value:m,onChange:D,children:p.map(C=>c.jsx("option",{value:C,children:C},C))})]}),c.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:v}),c.jsxs("div",{className:"ogx-pagination__actions",children:[a&&c.jsx(tt,{variant:"text",size:"small",onClick:k,disabled:I,"aria-label":"Go to first page",title:"First page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"})})}),c.jsx(tt,{variant:"text",size:"small",onClick:N,disabled:I,"aria-label":"Go to previous page",title:"Previous page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),c.jsx("div",{className:"ogx-pagination__page-info","aria-current":"page",children:E}),c.jsx(tt,{variant:"text",size:"small",onClick:M,disabled:A,"aria-label":"Go to next page",title:"Next page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),u&&c.jsx(tt,{variant:"text",size:"small",onClick:S,disabled:A,"aria-label":"Go to last page",title:"Last page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"})})})]})]})}function kf({row:e,rowId:t,rowIndex:n,ariaRowIndex:o,listViewColumn:r,gridColumn:i,rowMeta:l,isSelected:d=!1,checkboxSelection:a=!1,rowHeight:u,onRowClick:g,onRowDoubleClick:m,onSelectionChange:w,tabIndex:y=-1,onFocus:p,onToggleExpansion:f}){const h=t??e.id,x=r.field,b=Le(e,x,i),v=No(e,x,b,i)??Io(b,i),E=l?.isGroupRow===!0||qe(h),k={row:e,value:b,formattedValue:v,field:x,colDef:i??r,rowIndex:n,colIndex:0,rowMeta:l},N=M=>{M.stopPropagation(),w?.(h,M.target.checked)};return c.jsxs("div",{className:`ogx-list-view__row${d?" ogx-list-view__row--selected":""}`,style:u?{minHeight:u}:void 0,onClick:()=>g?.(e),onDoubleClick:m?()=>m(e):void 0,role:"row","aria-rowindex":o??n+1,"aria-selected":d,"aria-level":l?.treeDepth!==void 0?l.treeDepth+1:void 0,"aria-expanded":l?.hasChildren?l.isExpanded===!0:void 0,"data-rowindex":n,tabIndex:y,onFocus:p?M=>{M.target===M.currentTarget&&p(n)}:void 0,children:[a&&c.jsx("div",{className:"ogx-list-view__checkbox",onClick:M=>M.stopPropagation(),children:!E&&c.jsx(bt,{checked:d,onChange:N,"aria-label":`Select row ${h}`,tabIndex:-1})}),l&&f&&c.jsx("div",{className:"ogx-list-view__expand",style:{paddingLeft:(l.treeDepth??0)*16},onClick:M=>M.stopPropagation(),onDoubleClick:M=>M.stopPropagation(),children:l.hasChildren&&c.jsx(tr,{isExpanded:l.isExpanded===!0,onClick:()=>f(h),tabIndex:-1})}),c.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:c.jsx(Ft,{field:x,resetKey:e,renderFn:()=>{const M=r.renderCell(k);return M===void 0&&E?l?.groupLabel:M}})})]})}function Ef(e,t){const n=s.useRef(!0),o=s.useRef(e);s.useEffect(()=>{o.current=e},[e]),s.useEffect(()=>{n.current=!0},[t]);const r=s.useCallback(i=>{const l=Ji(i.currentTarget);if(!l){n.current=!0;return}if(!n.current)return;const d=o.current;d&&(n.current=!1,d(l))},[]);return e?r:void 0}const Mf=e=>e.id;function Nf({ariaLabel:e,allRenderableRows:t,dataRowCount:n,pinnedTopRowCount:o,pinnedBottomRowCount:r,unpinnedRowCount:i,pagination:l,effectivePaginationModel:d,currentPage:a,pageSizeOptions:u,selectedRowIds:g,listViewColumn:m,columnsByField:w,rowMetaMap:y,noRowsLabel:p,rowHeight:f,checkboxSelection:h,paginationMode:x,serverRowCount:b,paginationSlot:v,paginationSlotProps:E,localeText:k,onRowClick:N,onRowDoubleClick:M,onSelectionChange:S,onPaginationModelChange:D,onRowsScrollEnd:I,getRowId:A=Mf,multiselectable:C=!1,loading:L=!1,loadingOverlay:F,noRowsOverlay:_,showPaginationControls:z=!0,selectable:K=!1,onToggleExpansion:Q}){const G=v||mr,j=s.useRef(null),[H,ie]=s.useState(null),re=H===null?-1:t.findIndex($=>A($)===H),ue=re===-1?0:re,ae=$=>{const O=t[$];O&&(ie(A(O)),j.current?.querySelector(`:scope > [role="row"][data-rowindex="${$}"]`)?.focus())},R=$=>{const O=$.target;if(O.getAttribute("role")!=="row"||O.parentElement!==j.current)return;const P=Number(O.getAttribute("data-rowindex")),T=t[P];if(!T)return;const X=A(T),B=t.length-1,ee=y.get(X),q=!!(ee?.hasChildren&&Q);if($.altKey&&($.key==="ArrowRight"||$.key==="ArrowLeft")){$.preventDefault(),q&&$.key==="ArrowRight"!=(ee?.isExpanded===!0)&&Q?.(X);return}switch($.key){case"ArrowDown":$.preventDefault(),ae(Math.min(P+1,B));return;case"ArrowUp":$.preventDefault(),ae(Math.max(P-1,0));return;case"Home":$.preventDefault(),ae(0);return;case"End":$.preventDefault(),ae(B);return;case"PageDown":$.preventDefault(),ae(Math.min(P+10,B));return;case"PageUp":$.preventDefault(),ae(Math.max(P-10,0));return;case"Enter":case" ":if($.preventDefault(),$.key===" "&&$.shiftKey){K&&!ee?.isGroupRow&&S(X,!g.has(X));return}q?Q?.(X):N({row:T,id:X,rowIndex:P});return}},te=x==="server",ce=te?b||0:i,W=te?b||0:n,le=Un(d.pageSize),V=Zo(ce,le),J=l?a*le:0,ne=t.length-o-r,fe=$=>{if($<o)return $+1;const O=$-o;return O<ne?o+J+O+1:o+ce+(O-ne)+1},Z=Ef(I,t.length);return c.jsxs("div",{className:"ogx-list-view",role:"grid","aria-label":e||"Data grid list view","aria-rowcount":W,"aria-multiselectable":C,children:[c.jsx("div",{className:"ogx-list-view__toolbar",children:c.jsxs("span",{children:[W," ",W===1?"item":"items",l?` · page ${a+1} of ${V}`:"",g.size>0?` · ${g.size} selected`:""]})}),c.jsx("div",{className:"ogx-list-view__rows",tabIndex:-1,onScroll:Z,onKeyDown:R,ref:j,children:t.length===0&&L?c.jsx("div",{className:"ogx-list-view__loading",children:F??c.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})}):t.length===0&&_?c.jsx("div",{className:"ogx-list-view__empty",children:_}):t.length===0?c.jsxs("div",{className:"ogx-list-view__empty",children:[c.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),c.jsx("path",{d:"M3 9h18M9 21V9"})]}),p]}):t.map(($,O)=>{const P=A($);return c.jsx(kf,{row:$,rowId:P,rowIndex:O,ariaRowIndex:fe(O),listViewColumn:m,gridColumn:w.get(m.field),rowMeta:y.get(P),isSelected:g.has(P),checkboxSelection:h,rowHeight:f,onRowClick:T=>N({row:T,id:P,rowIndex:O}),onRowDoubleClick:M?T=>M({row:T,id:P,rowIndex:O}):void 0,onSelectionChange:S,tabIndex:O===ue?0:-1,onToggleExpansion:Q,onFocus:T=>ie(A(t[T]))},P)})}),l&&z&&c.jsx(G,{page:a,pageSize:d.pageSize,rowCount:ce,pageSizeOptions:u,onPageChange:$=>D({...d,page:$}),onPageSizeChange:$=>D({...d,pageSize:$,page:0}),localeText:k,...E})]})}function If({overlay:e}){return e?c.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows ogx__loading-overlay--custom",children:e}):c.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows",children:c.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})})}function bn(e){return e.headerName||e.field}function Lf(e){return e.nativeEvent.isComposing||e.keyCode===229}function xn(e,t,n=!0){return o=>{if(Lf(o)){o.stopPropagation();return}n&&o.key==="Enter"&&(o.stopPropagation(),e()),o.key==="Escape"&&(o.stopPropagation(),t())}}function Af({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(String(e??"")),d=s.useRef(null);return s.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),c.jsx(Qe,{ref:d,variant:"cell",type:"text",inputClassName:"ogx__edit-input","aria-label":bn(t),value:i,onChange:a=>{l(a.target.value),n(a.target.value)},onBlur:o,onKeyDown:xn(o,r)})}function Pf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(typeof e=="number"?e:""),d=s.useRef(null);return s.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),c.jsx(Qe,{ref:d,variant:"cell",type:"number",inputClassName:"ogx__edit-input ogx__edit-input--number","aria-label":bn(t),value:i,onChange:a=>{const u=a.target.value===""?"":Number(a.target.value);l(u),n(u===""?null:u)},onBlur:o,onKeyDown:xn(o,r)})}function Tf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=()=>{n(!e),o()};return c.jsx("div",{className:"ogx__edit-boolean",onMouseDown:d=>d.preventDefault(),children:c.jsx(bt,{ref:i,inputClassName:"ogx__edit-checkbox","aria-label":bn(t),checked:!!e,onChange:l,onMouseDown:d=>d.preventDefault(),onBlur:o,onKeyDown:xn(o,r,!1)})})}const wr=e=>typeof e=="object"?e.value:e,Ff=e=>typeof e=="object"?e.label:String(e);function Of(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function Df({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=t.valueOptions??[],d=l.map(g=>String(wr(g)));let a=l.findIndex(g=>Of(wr(g),e));a===-1&&e!==null&&e!==void 0&&(a=d.indexOf(String(e)));const u=a===-1;return c.jsxs("select",{ref:i,className:"ogx__edit-select","aria-label":bn(t),value:u?"":d[a],onChange:g=>{const m=d.indexOf(g.target.value);n(m===-1?null:wr(l[m]))},onBlur:o,onKeyDown:xn(o,r),children:[u&&c.jsx("option",{value:""}),l.map((g,m)=>c.jsx("option",{value:d[m],children:Ff(g)},m))]})}const es=e=>String(e).padStart(2,"0"),ts=/^(\d{4}-\d{2}-\d{2})/;function br(e){if(e instanceof Date)return Number.isNaN(e.getTime())?"":`${e.getFullYear()}-${es(e.getMonth()+1)}-${es(e.getDate())}`;if(typeof e=="string"){const t=ts.exec(e);return t?t[1]:e===""?"":br(new Date(e))}return typeof e=="number"?br(new Date(e)):""}function $f(e,t){if(e==="")return null;const[n,o,r]=e.split("-").map(Number),i=l=>{const d=new Date(l.getTime());return d.setFullYear(n,o-1,r),d};return t instanceof Date&&!Number.isNaN(t.getTime())?i(t):typeof t=="number"&&Number.isFinite(t)?i(new Date(t)).getTime():typeof t=="string"&&ts.test(t)&&t.length>10?e+t.slice(10):e}function Gf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i]=s.useState(e),[l,d]=s.useState(()=>br(e)),a=s.useRef(null);return s.useEffect(()=>{a.current?.focus()},[]),c.jsx(Qe,{ref:a,variant:"cell",type:"date",inputClassName:"ogx__edit-input","aria-label":bn(t),value:l,onChange:u=>{d(u.target.value),n($f(u.target.value,i))},onBlur:o,onKeyDown:xn(o,r)})}function Hf(e){const{colDef:t}=e;switch(t.type){case"number":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Pf,{...e})});case"boolean":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Tf,{...e})});case"singleSelect":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Df,{...e})});case"date":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Gf,{...e})});default:return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Af,{...e})})}}function Bf(e){const{onCellClick:t,onCellEditStart:n,onCellValueChange:o,value:r,row:i,colDef:l,rowIndex:d,colIndex:a,ariaColIndex:u,isSelected:g,onClick:m,width:w,pinnedPosition:y,pinnedOffset:p,isPinnedEdge:f,isFocused:h,isFocusVisible:x,isEditable:b,isEditing:v,onEditStart:E,onEditStop:k,onValueChange:N,colSpanInfo:M,rowSpan:S,isHiddenByRowSpan:D,rowMeta:I,valueError:A,rangeFlags:C=0}=e,L=s.useCallback(Z=>{o?o(l.field,Z):N?.(Z)},[o,N,l.field]),F=I?.isGroupRow===!0,{formattedValue:_,error:z}=s.useMemo(()=>{const Z=l.valueFormatter;if(Z&&!(F&&r==null)){const $=We(()=>Z({value:r,row:i,field:l.field}));return $.ok?{formattedValue:$.value}:{formattedValue:"",error:$.error??new Error("valueFormatter failed")}}return{formattedValue:Io(r,l)}},[r,i,l,F]),K=s.useMemo(()=>{if(!l.cellClassName)return"";const Z=l.cellClassName;if(typeof Z=="function"){const $=We(()=>Z({value:r,formattedValue:_,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I}));return $.ok&&$.value||""}return l.cellClassName},[l,r,_,i,d,a,I]),Q=A??z,G=l.field,j=s.useCallback(()=>{k?.(!1,G)},[k,G]),H=s.useCallback(()=>{k?.(!0,G)},[k,G]),ie=s.useMemo(()=>[i,l.renderCell,r],[i,l.renderCell,r]),re=s.useRef(!1);if(s.useEffect(()=>{if(!(!v||!k))return re.current=!0,()=>{re.current=!1,queueMicrotask(()=>{re.current||k(!1,G)})}},[v,k,G]),M?.spannedByColSpan)return null;const ue=M?.cellProps.colSpan??1,ae=ue>1,R=(ae?M?.cellProps.width:void 0)??w??l.width??100,te={width:"var(--width)","--width":typeof R=="number"?`${R}px`:R,flexGrow:(ae?M?.cellProps.flexGrow:void 0)??l.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",minWidth:ae?void 0:l.minWidth,maxWidth:ae?void 0:l.maxWidth};if(D)return c.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:te,role:"presentation","data-field":l.field,"data-colindex":a});const ce=Z=>{v||(t&&t({row:i,field:l.field,value:r,colDef:l,rowIndex:d,colIndex:a}),m?.(Z))},W=()=>{v||!b||(n?n(l.field,r):E?.())},le=l.renderEditCell,V=y!=null,J=["ogx__cell",`ogx__cell--align-${l.align||"left"}`,g&&"ogx__cell--selected",h&&"ogx__cell--focused",h&&x&&"ogx__cell--focus-visible",l.type&&`ogx__cell--type-${l.type}`,V&&"ogx__cell--pinned",V&&`ogx__cell--pinned-${y}`,V&&f&&`ogx__cell--pinned-${y}-${y==="left"?"last":"first"}`,v&&"ogx__cell--editing",S&&S>1&&"ogx__cell--spanned",(C&Yo)!==0&&"ogx__cell--range",(C&$i)!==0&&"ogx__cell--range-top",(C&Gi)!==0&&"ogx__cell--range-bottom",(C&Hi)!==0&&"ogx__cell--range-left",(C&Bi)!==0&&"ogx__cell--range-right",K].filter(Boolean).join(" "),ne=S||1,fe={...te,position:V?"sticky":void 0,zIndex:l.zIndex??(V?3:void 0),padding:v?0:void 0};return ne>1&&(fe.height=`calc(var(--height) * ${ne} - var(--border-width, 1px))`,fe.zIndex=10,V&&(fe.zIndex=40)),V&&p!==void 0&&(y==="left"?fe.left=p:fe.right=p),c.jsxs("div",{className:J,style:fe,onClick:ce,onDoubleClick:W,role:"gridcell","aria-colindex":u??a+1,"aria-readonly":!b||void 0,tabIndex:-1,"data-field":l.field,"data-colindex":a,...ue>1?{"aria-colspan":ue}:{},...ne>1?{"aria-rowspan":ne}:{},...(C&Yo)!==0?{"aria-selected":!0}:{},children:[c.jsx("div",{className:"ogx__cell-content",children:v&&(o||N)&&k?le?c.jsx(Ft,{field:l.field,resetKey:i,renderFn:()=>le({value:r,formattedValue:_,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I,onValueChange:L,onCommit:j,onCancel:H})}):c.jsx(Hf,{value:r,formattedValue:_,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I,onValueChange:L,onCommit:j,onCancel:H}):Q!==void 0?c.jsx(Ft,{field:l.field,resetKey:i,renderFn:()=>{throw Q}}):l.renderCell?c.jsx(Ft,{field:l.field,resetKey:ie,renderFn:()=>l.renderCell({value:r,formattedValue:_,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I})}):l.type==="image"&&typeof r=="string"&&r!==""?c.jsx("img",{className:"ogx__cell-image",src:r,alt:l.headerName??l.field,loading:"lazy"}):_}),(C&Wi)!==0&&!v&&c.jsx("div",{className:"ogx__cell-fill-handle","aria-hidden":"true"})]})}const ns=s.memo(Bf),Wf=({className:e="",...t})=>c.jsx("button",{type:"button",className:`ogx-drag-handle ${e}`,"aria-label":"Drag to reorder row",...t,children:c.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zm-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})})});function Vf(e){const{rowId:t,content:n,height:o,isExpanded:r,onHeightChange:i,id:l,colSpan:d}=e,a=s.useRef(null),u=o==="auto";if(s.useLayoutEffect(()=>{const m=a.current;if(!m||!u||!r||!i)return;const w=()=>{m.getClientRects().length!==0&&i(t,m.offsetHeight)};if(w(),typeof ResizeObserver>"u")return;const y=new ResizeObserver(w);return y.observe(m),()=>y.disconnect()},[u,r,i,t]),!r)return null;const g={height:u?"auto":`${o}px`,overflow:u?"visible":"auto"};return c.jsx("div",{ref:a,className:"ogx__detail-panel",style:g,role:"row",id:l,children:c.jsx("div",{className:"ogx__detail-panel-content",role:"gridcell","aria-colspan":d,children:n})})}const xr=12;function zf(e,t,n,o){let r=0,i=0,l=0;for(let d=t;d<e.length&&l<n;d++){const a=e[d];if(a.isSpacer)break;r+=Nt(a,o),i+=a.flex??0,l++}return{spannedByColSpan:!1,cellProps:{colSpan:l,width:r,flexGrow:i}}}function Kf(e){const{row:t,rowId:n,columns:o,rowIndex:r,isSelected:i=!1,checkboxSelection:l=!1,onRowClick:d,onRowDoubleClick:a,onCellClick:u,onSelectionChange:g,columnWidths:m={},pinnedColumns:w,pinnedRows:y,hasDetailPanel:p=!1,isDetailPanelExpanded:f=!1,onDetailPanelToggle:h,detailPanelContent:x,detailPanelHeight:b=Lo,onDetailPanelHeightChange:v,pinCheckboxColumn:E=!0,pinExpandColumn:k=!0,rowReordering:N=!1,onDragStart:M,onDragOver:S,onDragEnd:D,onDrop:I,isDragging:A,isDragOver:C,editingCell:L,onEditStart:F,onEditStop:_,onEditCellValueChange:z,isCellEditable:K,focusedCellField:Q,isFocusVisible:G,colspanMap:j,rowSpanningCaches:H,rowHeight:ie=52,rowMeta:re,columnIndexMap:ue,ariaRowIndex:ae,cellRange:R}=e,te=n??t.id,ce=s.useId(),W=s.useId(),le=s.useMemo(()=>Eo(o,m,w,l,E,p,k,N),[o,m,w,l,E,p,k,N]),V=s.useMemo(()=>Mo(o,w),[o,w]),J=re?.hasChildren===!0,ne=re?.isGroupRow===!0,fe=p&&!ne,Z=!ne&&!qe(te),$=s.useCallback((de,ye)=>{F?.({id:te,field:de,value:ye})},[te,F]),O=s.useCallback((de,ye)=>{z?.({id:te,field:de,value:ye})},[z,te]),P=s.useCallback((de,ye)=>{_?.({cancel:de,id:te,field:ye})},[_,te]);if(t._isSkeleton){const de=Math.max(o.length,5);return c.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:ie,minHeight:ie},children:Array.from({length:de}).map((ye,Ee)=>c.jsx("div",{className:"ogx__skeleton-cell",children:c.jsx("div",{className:"ogx__skeleton-bar"})},Ee))})}const T=de=>{de.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||d?.({row:t,id:te,rowIndex:r})},X=de=>{de.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||a?.({row:t,id:te,rowIndex:r})},B=de=>{de.stopPropagation(),g?.(te,de.target.checked)},ee=de=>{de.stopPropagation(),h?.(te)},q=N?1:0,Y=p?q+1:q,oe=l?Y+1:Y,me=oe,U=ue?.size??o.filter(de=>!de.isSpacer).length,se=re!==void 0,we=re?.hasChildren===!0,pe=ni(te,y),he=pe==="top",ve=pe==="bottom",be=["ogx__row",i&&"ogx__row--selected",r%2===0&&"ogx__row--even",r%2===1&&"ogx__row--odd",he&&"ogx__row--pinned-top",ve&&"ogx__row--pinned-bottom",A&&"ogx__row--dragging",C&&"ogx__row--drag-over",J&&"ogx__row--group",re?.isGroupFooter&&"ogx__row--group-footer"].filter(Boolean).join(" ");return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:be,onClick:T,onDoubleClick:a?X:void 0,role:"row","aria-rowindex":ae??r+2,"aria-selected":i,"aria-level":se?(re?.treeDepth??0)+1:void 0,"aria-expanded":we?re?.isExpanded===!0:void 0,"data-rowindex":r,onDragOver:S?S(te):void 0,onDrop:I?I(te):void 0,style:{maxHeight:`${ie}px`,minHeight:`${ie}px`,"--height":`${ie}px`,"--border-width":"1px"},children:[N&&c.jsx("div",{className:`ogx__cell ogx__cell--drag-handle ${Q==="__reorder_col__"?"ogx__cell--focused":""} ${Q==="__reorder_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":M?"Drag to reorder row":void 0,"aria-colindex":q,"data-field":"__reorder_col__",tabIndex:-1,style:{position:"sticky",left:0,zIndex:xr},draggable:!!M,onDragStart:M?M(te):void 0,onDragEnd:D,onClick:de=>de.stopPropagation(),children:M&&c.jsx(Wf,{})}),p&&c.jsx("div",{className:`ogx__cell ogx__cell--expand ${k?"ogx__cell--pinned-left":""} ${Q==="__expand_col__"?"ogx__cell--focused":""} ${Q==="__expand_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":fe?f?"Collapse row details":"Expand row details":void 0,"aria-expanded":fe?f:void 0,"aria-controls":fe&&f?W:void 0,"aria-colindex":Y,"data-field":"__expand_col__",style:{position:k?"sticky":void 0,left:k?N?48:0:void 0,zIndex:k?xr:void 0},tabIndex:-1,onClick:de=>{de.stopPropagation(),u?.({row:t,field:"__expand_col__",value:f,colDef:{field:"__expand_col__",width:48},rowIndex:r,colIndex:-1})},children:fe&&c.jsx(tr,{isExpanded:f,onClick:ee,variant:"plus-minus",tabIndex:-1})}),l&&c.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${E?"ogx__cell--pinned-left":""} ${Q==="__checkbox_col__"?"ogx__cell--focused":""} ${Q==="__checkbox_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-colindex":oe,"data-field":"__checkbox_col__",style:{position:E?"sticky":void 0,left:E?(N?48:0)+(p&&k?48:0):void 0,zIndex:E?xr:void 0},tabIndex:-1,onClick:de=>{de.stopPropagation(),u?.({row:t,field:"__checkbox_col__",value:i,colDef:{field:"__checkbox_col__",width:48},rowIndex:r,colIndex:-1})},children:Z&&c.jsx(bt,{id:ce,name:`ogx-select-row-${te}`,checked:i,onChange:B,onClick:de=>de.stopPropagation(),"aria-label":i?`Deselect row ${te}`:`Select row ${te}`,tabIndex:-1,onMouseDown:de=>de.preventDefault()})}),o.map((de,ye)=>{if(de.isSpacer)return c.jsx("div",{style:{width:de.width,minWidth:de.width,flexShrink:0},"aria-hidden":"true"},de.field);let Ee,Me;ne?Ee=t[de.field]:{value:Ee,error:Me}=ri(t,de.field,de);const Ne=ue?.get(de.field)??ye,Ie=m[de.field]??de.width,Se=ct(de.field,w),Oe=!!F&&Fo({row:t,field:de.field,value:Ee,colDef:de,rowIndex:r,colIndex:Ne,rowMeta:re},K),ge=L?.id===te&&L?.field===de.field,Ce=ge?L?.value:Ee,ke=j?.get(te)?.[de.field],xe=ke&&!ke.spannedByColSpan&&ke.cellProps.colSpan>1?zf(o,Ne,ke.cellProps.colSpan,m):ke,je=xe&&!xe.spannedByColSpan?o[Ne+xe.cellProps.colSpan-1]?.field??de.field:de.field,nt=Se==="right"?je:de.field,nn=Se?le[nt]:void 0,Mn=Se==="left"&&je===V.lastLeft||Se==="right"&&de.field===V.firstRight,ot=H?.spannedCells[te]?.[de.field],lo=H?.hiddenCells[te]?.[de.field]||!1,so=R&&!lo&&de.field!==Oi?lc(R,Ne,xe&&!xe.spannedByColSpan?xe.cellProps.colSpan:1,ot??1):void 0;return c.jsx(ns,{value:Ce,row:t,colDef:de,rowIndex:r,colIndex:Ne,ariaColIndex:me+Ne+1,isSelected:i,onCellClick:u,width:Ie,pinnedPosition:Se,pinnedOffset:nn,isPinnedEdge:Mn,isFocused:Q===de.field,isFocusVisible:G,isEditable:Oe,isEditing:ge,onCellEditStart:$,onEditStop:P,onCellValueChange:O,colSpanInfo:xe,rowSpan:ot,isHiddenByRowSpan:lo,rowMeta:re,valueError:Me,rangeFlags:so},de.field)})]}),fe&&c.jsx(Vf,{id:W,colSpan:me+U,row:t,rowId:te,rowIndex:r,content:x,height:b,isExpanded:f,onHeightChange:v})]})}function jf(e,t){const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(o==="cellRange"){if(!ic(e.cellRange,t.cellRange))return!1}else if(!Object.is(e[o],t[o]))return!1;return!0}const Zn=s.memo(Kf,jf);function os({getContent:e,params:t}){return c.jsx(Ft,{field:"detail panel",renderFn:()=>e(t),resetKey:t.row})}const Uf=e=>e.id;function rs({rows:e,position:t,columns:n,selectedRowIds:o,checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:d,onSelectionChange:a,columnWidths:u,pinnedColumns:g,pinnedRows:m,hasDetailPanel:w,expandedRowIds:y,getDetailPanelContent:p,getDetailPanelHeight:f,onDetailPanelToggle:h,onDetailPanelHeightChange:x,pinCheckboxColumn:b,pinExpandColumn:v,focusedCell:E,colspanMap:k,rowSpanningCaches:N,rowHeight:M,rowMetaMap:S,getRowId:D=Uf,rowIndexOffset:I=0,ariaRowIndexBase:A,columnIndexMap:C,editingHandlers:L,isCellEditable:F,rowReordering:_=!1,cellRange:z,cellRangeHasRowSpan:K=!1,fillHandle:Q}){return e.length===0?null:c.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:e.map((G,j)=>{const H=D(G),ie=I+j;return c.jsx(Zn,{row:G,rowId:H,columns:n,rowIndex:ie,ariaRowIndex:A!==void 0?A+j:void 0,columnIndexMap:C,isSelected:o.has(H),checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:d,onSelectionChange:a,columnWidths:u,pinnedColumns:g,pinnedRows:m,hasDetailPanel:w,isDetailPanelExpanded:y.has(H),detailPanelContent:y.has(H)&&p?c.jsx(os,{getContent:p,params:{row:G,id:H,rowIndex:ie}}):null,detailPanelHeight:y.has(H)?Ao(Po(f,{row:G,id:H,rowIndex:ie})):void 0,onDetailPanelHeightChange:x,onDetailPanelToggle:h,pinCheckboxColumn:b,pinExpandColumn:v,focusedCellField:E?.id===H?E.field:null,colspanMap:k,rowSpanningCaches:N,rowHeight:M,rowMeta:S.get(H),editingCell:L?.editingCell,onEditStart:L?.startCellEdit,onEditStop:L?.stopCellEdit,onEditCellValueChange:L?.setEditCellValue,isCellEditable:F,rowReordering:_,cellRange:Di(z,ie,K,Q)},H)})})}const Rf=({columns:e,rowHeight:t,checkboxSelection:n=!1,hasDetailPanel:o=!1,rowReordering:r=!1})=>c.jsxs("div",{className:"ogx__row ogx__skeleton-row",style:{height:t},role:"row",children:[n&&c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:c.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),o&&c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:c.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),r&&c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:c.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),e.map((i,l)=>{const d=typeof i.width=="number"?i.width:150,a=Math.min(d*.7,d-20);return c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:d,minWidth:i.minWidth,maxWidth:i.maxWidth,left:i.left,right:i.right,position:i.isSpacer?"relative":i.pinned?"sticky":"relative",zIndex:i.zIndex},children:!i.isSpacer&&c.jsx("div",{className:"ogx-skeleton-box",style:{width:a,height:16,borderRadius:4}})},i.field||l)})]});function qf({virtualContainerHeight:e,offsetTop:t,effectiveLoading:n,visibleRows:o,baseColumns:r,virtualColumns:i,viewportWidth:l,checkboxSelection:d,hasDetailPanel:a,rowReordering:u,rowHeight:g,selectedRowIds:m,onRowClick:w,onRowDoubleClick:y,onCellClick:p,onSelectionChange:f,columnWidths:h,pinnedColumns:x,expandedRowIds:b,getDetailPanelContent:v,getDetailPanelHeight:E,onDetailPanelToggle:k,onDetailPanelHeightChange:N,pinCheckboxColumn:M,pinExpandColumn:S,rowReorderHandlers:D,editingHandlers:I,isCellEditable:A,focusedCell:C,colspanMap:L,rowSpanningCaches:F,paginationMode:_,dataSourceLoading:z,sortedUnpinnedRowCount:K,infiniteScrollSkeletonCount:Q,unpinnedRowsLength:G,lastRenderedRowIndex:j,rowMetaMap:H,loadingOverlay:ie,ariaRowIndexOffset:re,columnIndexMap:ue,cellRange:ae,cellRangeHasRowSpan:R=!1,fillHandle:te}){const ce=r.length>0?r:(()=>{const V=(l||1e3)-(d?48:0)-(a?48:0)-(u?48:0),J=150,ne=Math.max(1,Math.ceil(V/J));return Array.from({length:ne},(fe,Z)=>({field:`placeholder_${Z}`,headerName:"",width:J}))})(),W=o.filter(V=>!V.pinned),le=_==="infinite"&&z&&K>0&&j>=G-1;return c.jsx("div",{className:"ogx__virtual-container",style:{height:`${e}px`},role:"presentation",children:c.jsxs("div",{className:"ogx__rows",style:{transform:`translateY(${t}px)`},role:"rowgroup",children:[n&&o.length===0&&ie?c.jsx("div",{className:"ogx__loading-overlay",style:{width:l||void 0},children:ie}):n&&o.length===0?Array.from({length:10}).map((V,J)=>c.jsx(Rf,{columns:ce,rowHeight:g,checkboxSelection:d,hasDetailPanel:a,rowReordering:u},`skeleton-${J}`)):W.map(({row:V,id:J,rowIndex:ne})=>c.jsx(Zn,{row:V,rowId:J,columns:i,rowIndex:ne,ariaRowIndex:re!==void 0?ne+re:void 0,columnIndexMap:ue,isSelected:m.has(J),checkboxSelection:d,onRowClick:w,onRowDoubleClick:y,onCellClick:p,onSelectionChange:f,columnWidths:h,pinnedColumns:x,hasDetailPanel:a,isDetailPanelExpanded:b.has(J),detailPanelContent:b.has(J)&&v?c.jsx(os,{getContent:v,params:{row:V,id:J,rowIndex:ne}}):null,detailPanelHeight:b.has(J)?Ao(Po(E,{row:V,id:J,rowIndex:ne})):void 0,onDetailPanelHeightChange:N,onDetailPanelToggle:k,pinCheckboxColumn:M,pinExpandColumn:S,rowReordering:u,onDragStart:D.canReorderRow(J)?D.onDragStart:void 0,onDragOver:D.onDragOver,onDragEnd:D.onDragEnd,onDrop:D.onDrop,isDragging:D.draggedRowId===J,isDragOver:D.dragOverRowId===J,editingCell:I.editingCell,onEditStart:I.startCellEdit,onEditStop:I.stopCellEdit,onEditCellValueChange:I.setEditCellValue,isCellEditable:A,focusedCellField:C!=null&&C.id===J?C.field:null,colspanMap:L,rowSpanningCaches:F,rowHeight:g,rowMeta:H.get(J),cellRange:Di(ae,ne,R,te)},J)),le&&c.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:Q}).map((V,J)=>c.jsx(Zn,{row:{id:`__skeleton_${J}__`,_isSkeleton:!0},columns:i,rowIndex:G+J,rowHeight:g},`__skeleton_${J}__`))})]})})}function Xf(){return c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Yf(){return c.jsxs("svg",{className:"ogx-column-visibility-panel__drag-handle",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[c.jsx("circle",{cx:"9",cy:"5",r:"1.5"}),c.jsx("circle",{cx:"15",cy:"5",r:"1.5"}),c.jsx("circle",{cx:"9",cy:"12",r:"1.5"}),c.jsx("circle",{cx:"15",cy:"12",r:"1.5"}),c.jsx("circle",{cx:"9",cy:"19",r:"1.5"}),c.jsx("circle",{cx:"15",cy:"19",r:"1.5"})]})}function yr(e){const{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:d,showNonHideableColumns:a}=e,[u,g]=s.useState(""),m=s.useId(),[w,y]=s.useState(null),p=s.useRef(null),f=s.useMemo(()=>t.filter(S=>S.hideable!==!1),[t]),h=f.every(S=>n.has(S.field)),x=s.useMemo(()=>{const S=a?t:f;if(!u)return S;const D=u.toLowerCase();return S.filter(I=>(I.headerName||I.field).toLowerCase().includes(D))},[t,f,u,a]),b=S=>{S.target.checked?r():i()},v=S=>D=>{p.current=S,D.dataTransfer.effectAllowed="move",D.dataTransfer.setDragImage(D.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},E=S=>D=>{D.preventDefault(),D.dataTransfer.dropEffect="move",S!==p.current&&y(S)},k=()=>{y(null)},N=S=>D=>{D.preventDefault();const I=p.current;y(null),p.current=null,I&&I!==S&&l&&l(I,S)},M=()=>{y(null),p.current=null};return c.jsxs("div",{className:"ogx-column-visibility-panel",children:[c.jsx("div",{className:"ogx-column-visibility-panel__search-section",children:c.jsxs("div",{className:"ogx-column-visibility-panel__search-container",children:[c.jsx(Xf,{}),c.jsx(Qe,{autoComplete:"off",inputClassName:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:u,onChange:S=>g(S.target.value)})]})}),c.jsx("div",{className:"ogx-column-visibility-panel__list",children:x.map((S,D)=>{const I=`${m}-col-${D}`,A=n.has(S.field),C=S.hideable!==!1,L=w===S.field,F=!!l&&!u;return c.jsxs("div",{className:["ogx-column-visibility-panel__item",!C&&"ogx-column-visibility-panel__item--disabled",L&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:F,onDragOver:F?E(S.field):void 0,onDragLeave:F?k:void 0,onDrop:F?N(S.field):void 0,onDragEnd:F?M:void 0,children:[F&&c.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:v(S.field),title:"Drag to reorder",children:c.jsx(Yf,{})}),c.jsxs("div",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:C?"pointer":"not-allowed"},children:[c.jsx(bt,{id:I,checked:A,onChange:_=>o(S.field,_.target.checked),disabled:!C}),c.jsx("label",{htmlFor:I,className:"ogx-column-visibility-panel__label",children:S.headerName||S.field})]})]},S.field)})}),c.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[c.jsxs("div",{className:"ogx-column-visibility-panel__item",children:[c.jsx(bt,{id:`${m}-all`,checked:h,onChange:b}),c.jsx("label",{htmlFor:`${m}-all`,className:"ogx-column-visibility-panel__label",children:"Show/Hide All"})]}),c.jsx("button",{type:"button",className:"ogx-column-visibility-panel__reset-btn",onClick:()=>{r(),d?.()},children:"Reset"})]})]})}function Jf({isOpen:e,containerRef:t,panelRef:n,columns:o,columnVisibilityModel:r,disableColumnReorder:i,onClose:l,onColumnVisibilityChange:d,onColumnMove:a,onColumnOrderReset:u,columnGroupingModel:g}){const[m,w]=s.useState(null);if(s.useLayoutEffect(()=>{if(!e||!t.current)return;const p=t.current.getBoundingClientRect();w({top:p.top+8,right:Ot()-p.right+8,target:t.current.closest(".ogx-theme-provider")||document.body})},[e,t]),!e||!m)return null;const y=i?void 0:(p,f)=>{rr(g,p,f)&&a(p,f)};return mt.createPortal(c.jsxs("div",{ref:n,style:{position:"fixed",top:m.top,right:m.right,zIndex:9999,display:"inline-block"},children:[c.jsx("button",{type:"button",onClick:l,style:{position:"absolute",top:-12,right:-12,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",background:"#334155",color:"#fff",border:"none",borderRadius:"50%",cursor:"pointer",fontSize:14,lineHeight:1,zIndex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.2)"},"aria-label":"Close",children:"×"}),c.jsx(yr,{columns:o,visibleColumns:new Set(o.filter(p=>r[p.field]!==!1).map(p=>p.field)),onVisibilityChange:(p,f)=>{d({...r,[p]:f})},onShowAll:()=>{const p={...r};o.forEach(f=>{f.hideable!==!1&&(p[f.field]=!0)}),d(p)},onHideAll:()=>{const p={...r};o.forEach(f=>{f.hideable!==!1&&(p[f.field]=!1)}),d(p)},onColumnReorder:y,onColumnOrderReset:i?void 0:u})]}),m.target)}function Zf(e){const{baseColumns:t,pinnedColumns:n,hasGroupingColumn:o,groupingColDef:r,isTreeData:i,getTreeDataPath:l}=e,d=s.useMemo(()=>o?{...n,left:["__group__",...(n?.left??[]).filter(u=>u!=="__group__")]}:n,[o,n]);return{activeColumns:s.useMemo(()=>o?[{headerName:"Group",width:220,...i&&l?{valueGetter:({row:u})=>{const g=l(u);return g[g.length-1]}}:{},...r,field:"__group__",hideable:!1,sortable:!1,filterable:!1,pinnable:!1,exportable:!1},...t]:t,[r,o,i,l,t]),effectivePinnedColumns:d}}function Qf(e){return e.id}function eg(e){const t=s.useCallback(r=>e.get(r)??r.id,[e]),n=s.useRef(t);s.useLayoutEffect(()=>{n.current=t});const o=s.useCallback(r=>n.current(r),[]);return{getRowIdOf:t,getRowIdOfInEvents:o}}function tg(e,t){s.useLayoutEffect(()=>{e&&(e.current=t.current)},[e,t])}function ng(e){const{hierarchyHandlers:t,pinnedTopRows:n,sortedUnpinnedRows:o,pinnedBottomRows:r,rowMetaMap:i,getRowId:l,hierarchyField:d,dataRows:a}=e,u=t?.getVisibleRows({expandAll:!0,labelField:d});if(!u)return[...n,...o,...r];const g=a?new Set(a):null;return u.filter(m=>!i.get(l(m))?.isGroupRow&&(!g||g.has(m)))}function og(e,t){if(e===t)return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;const o=e,r=t;return n.every(i=>Object.prototype.hasOwnProperty.call(t,i)&&Object.is(o[i],r[i]))}function rg(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>og(n,t[o]))}function ig(e){const[t,n]=s.useState(e),o=rg(t,e);return o||n(e),o?t:e}function lg(e){const{rows:t,getRowId:n,rowMetaMap:o,columns:r,aggregationModel:i,aggregationResult:l,isSubtotalHidden:d}=e,a=Object.keys(i).length>0,u=new Map(r.map(y=>[y.field,y])),g=[],m=[],w=y=>{for(;m.length>0&&m[m.length-1].header.depth>=y;){const p=m.pop();a&&!d?.(p.id)&&g.push({type:"group-subtotal",depth:p.header.depth,groupField:p.header.groupField,groupValue:p.header.groupValue,groupLabel:p.header.groupLabel,aggregatedValues:Hn(p.leaves,i,u,"getGroupedExportRows")})}};for(const y of t){const p=n(y),f=o.get(p);if(!f?.isGroupFooter)if(f?.isGroupRow){const h=f.treeDepth??0;w(h);const x={type:"group-header",depth:h,groupField:f.groupingField,groupValue:f.groupingValue,groupLabel:f.groupLabel};g.push(x),m.push({id:p,header:x,leaves:[]})}else g.push({type:"leaf",depth:f?.treeDepth??m.length,row:y}),m.forEach(h=>h.leaves.push(y))}return w(0),a&&l&&g.push({type:"grand-total",depth:0,aggregatedValues:l}),g}function sg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=()=>n.current;t.current.getAggregationResult=()=>o().hasAggregation?o().aggregationResult:null,t.current.getAggregationModel=()=>o().hasAggregation?o().aggregationModel:null,t.current.getGroupedExportRows=()=>{const{hasAggregation:r,aggregationResult:i,aggregationModel:l,isRowGrouping:d,rowGroupingHandlers:a,rowMetaMap:u,columns:g,getRowId:m,hierarchyField:w}=o();return d?lg({rows:a.getVisibleRows({expandAll:!0,labelField:w})??[],getRowId:m,rowMetaMap:u,columns:g,aggregationModel:l,aggregationResult:r&&a.rootAggregationPosition!==null?i:null,isSubtotalHidden:y=>a.aggregationPositions.get(y)===null}):null}},[t])}const ag=new Set(["__group__","__check__","__actions__"]);function Dt(e){return e.filter(t=>t.exportable!==!1&&!t.isSpacer&&!Ze(t.field)&&!ag.has(t.field))}function yt(e){return!!e&&e.length>0}function is(e,t,n=o=>o.id){const o=new Set(t);return e.filter(r=>o.has(n(r)))}function yn(e,t,n){return yt(t)?is(e,t,n):e}function vn(e,t){return!!e&&e.length>0&&!yt(t)}function Yt(e,t,n,o,r){if(!o)return null;if(!t||!r||Object.keys(r).length===0)return o;const i=new Map(n.map(l=>[l.field,l]));return Hn(e,r,i,"export")}function Cn(e,t){const n=e[t.field];return t.valueGetter?t.valueGetter({row:e,field:t.field,value:n}):n}function _n(e,t,n){if(!t.valueFormatter)return Io(n,t);if(n==null)try{return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}catch{return""}return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}function vr(e,t,n,o){return n==null?"":Bn(n,t??"",e,o)}function Jt(e,t){return t?`${e}: ${t}`:e}function ls(e,t){const n={};return t.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o.field)&&(n[o.field]=e[o.field])}),n}const cg=/^[=+\-@\t\r]/,dg=/^[-+]?(?=[\d.,\s]*\d)[\d.,\s]*%?$/;function Qn(e,t=!1){return t||!cg.test(e)||dg.test(e)?e:`'${e}`}function vt(e){return typeof e=="number"||typeof e=="bigint"||typeof e=="boolean"||e instanceof Date}function Te(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ug(e){let t=0,n=e.length;for(;t<n&&e[t]==="'";)t++;for(;n>t&&e[n-1]==="'";)n--;return e.slice(t,n)}const fg=/[\\/?*:[\]]/g,ss=31;function Cr(e,t=new Set){let n=ug(String(e??"").replace(fg,"-").trim()).trim();n||(n="Sheet"),n=n.slice(0,ss).trim();const o=i=>t.has(i.toLowerCase())||i.toLowerCase()==="history";let r=n;for(let i=2;o(r);i++){const l=` (${i})`;r=`${n.slice(0,ss-l.length).trim()}${l}`}return t.add(r.toLowerCase()),r}const gg=new Set([Je,Pt,At]),pg=/[\t\n\r"]/;function _r(e){return pg.test(e)?`"${e.replace(/"/g,'""')}"`:e}function hg(e){return Dt(e).filter(t=>!gg.has(t.field))}function mg(e,t){const n=t.map(r=>_r(r.headerName||r.field)).join(" "),o=e.map(r=>t.map(i=>_r(_n(r,i,Le(r,i.field,i)))).join(" "));return[n,...o].join(`
|
|
6
|
-
`)}function
|
|
7
|
-
`)}function as(e){if(typeof document.execCommand!="function")return!1;const t=document.activeElement instanceof HTMLElement?document.activeElement:null,n=document.getSelection(),o=[];if(n)for(let l=0;l<n.rangeCount;l++)o.push(n.getRangeAt(l));const r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.setAttribute("aria-hidden","true"),r.style.cssText="position:fixed;top:-9999px;left:-9999px;opacity:0;",document.body.appendChild(r);let i=!1;try{r.focus({preventScroll:!0}),r.select(),i=document.execCommand("copy")}finally{document.body.removeChild(r),t&&t.isConnected&&t.focus({preventScroll:!0}),n&&(n.removeAllRanges(),o.forEach(l=>n.addRange(l)))}return i}async function Sr(e){const t=typeof navigator<"u"?navigator.clipboard:void 0;if(t&&typeof t.writeText=="function")try{await t.writeText(e);return}catch(n){if(as(e))return;throw n}if(!as(e))throw new Error("Clipboard API not available and fallback failed.")}function xg(e){if(!(e.ctrlKey||e.metaKey)||e.altKey||e.shiftKey)return!1;const t=e.key??"";return t.toLowerCase()==="c"?!0:e.code==="KeyC"&&!/^[a-z]$/i.test(t)}function yg(e){const t=s.useRef(e);s.useLayoutEffect(()=>{t.current=e});const n=s.useCallback(async()=>{const{getSelectedRowIds:r,getColumns:i,getRows:l,getRowId:d}=t.current,a=new Set(r());if(a.size===0)return;const u=l().filter(m=>a.has(d(m)));if(u.length===0)return;const g=mg(u,hg(i()));await Sr(g)},[]),o=!!e.disableKeyboardShortcut;return s.useEffect(()=>{if(o)return;const r=i=>{if(i.defaultPrevented||!xg(i))return;const l=document.activeElement,d=l?.tagName.toLowerCase(),a=l?.type;if(d==="input"&&a!=="checkbox"&&a!=="radio"||d==="textarea"||d==="select"||l?.isContentEditable)return;const{getRootElement:u}=t.current;if(u){const y=u();if(!y||!l||!y.contains(l))return}const g=window.getSelection();if(g&&!g.isCollapsed&&g.toString()!=="")return;const{getShortcutText:m}=t.current;(m?()=>{const y=m();return y===null?Promise.resolve():Sr(y)}:n)().catch(y=>{console.error("[OpenGridX] Failed to copy to clipboard:",y)})};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[n,o]),{copySelectedRows:n}}function vg(e){const{apiRef:t,columns:n,getRowId:o,containerRef:r,disableKeyboardShortcut:i,getCellRangeCopyText:l}=e,d=s.useCallback(()=>r.current,[r]),{copySelectedRows:a}=yg({getSelectedRowIds:()=>t.current.getSelectedRows(),getColumns:()=>n,getRows:()=>t.current.getAllFilteredRows(),getRowId:o,getRootElement:d,disableKeyboardShortcut:i,getShortcutText:l});s.useLayoutEffect(()=>{t.current.copySelectedRows=a},[a,t])}function Cg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{t.current.scrollToIndexes=({rowIndex:o,colIndex:r})=>{const{viewportRef:i,layout:l,rowHeight:d}=n.current,a=i.current;if(a&&(o!==void 0&&o>=0&&Gn(a,o,l.cumulativeHeights,l.pinnedBottomHeight,d),r!==void 0&&r>=0)){const g=[...l.leftPinnedCols,...l.unpinnedColsWithWidth,...l.rightPinnedCols][r];if(!g)return;To(a,l.unpinnedColsWithWidth.findIndex(m=>m.field===g.field),l)}}},[t])}const _g=".ogx";function cs(e,t){const n=t.style.cssText;t.style.width="max-content",t.style.minWidth="0",t.style.maxWidth="none",t.style.flex="none";const o=t.getBoundingClientRect().width;t.style.cssText=n;const r=getComputedStyle(e),i=[r.paddingLeft,r.paddingRight,r.borderLeftWidth,r.borderRightWidth].reduce((l,d)=>l+(parseFloat(d)||0),0);return o+i}function Sg(e,t){const n=typeof CSS<"u"&&CSS.escape?CSS.escape(t):t.replace(/["\\]/g,"\\$&"),o=l=>l.closest(_g)===e;let r=null;const i=l=>{r=r===null?l:Math.max(r,l)};return e.querySelectorAll(`[role="columnheader"][data-field="${n}"]`).forEach(l=>{if(!o(l))return;const d=l.querySelector(".ogx__header-cell-content");d&&i(cs(l,d))}),e.querySelectorAll(`[role="gridcell"][data-field="${n}"]`).forEach(l=>{if(!o(l)||l.hasAttribute("aria-colspan"))return;const d=l.querySelector(":scope > .ogx__cell-content");d&&i(cs(l,d))}),r===null?null:Math.ceil(r)}function kg(e,t,n){return Math.max(t??cl,Math.min(n??1/0,e))}function Eg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useCallback(i=>{const{containerRef:l,columns:d,onColumnResize:a}=n.current,u=l.current;if(!u)return;const g=[];for(const m of i??d.map(w=>w.field)){const w=d.find(p=>p.field===m);if(!w||w.resizable===!1)continue;const y=Sg(u,m);y!==null&&g.push([m,kg(y,w.minWidth,w.maxWidth)])}for(const[m,w]of g)a(m,w)},[]),r=s.useCallback(i=>o([i]),[o]);return s.useLayoutEffect(()=>{t.current.autosizeColumn=r,t.current.autosizeColumns=o},[t,r,o]),r}const ds="ogx--range-dragging",Ct=32,Mg=40,Ng=300;function us(e,t){if(!e||e.nodeType!==1)return null;const n=e.closest(".ogx__cell[data-field]");if(!n||n.closest(".ogx__viewport")!==t)return null;const o=n.closest(".ogx__detail-panel");if(o&&t.contains(o))return null;const r=n.closest('[role="row"][data-rowindex]');if(!r)return null;const i=Number(r.getAttribute("data-rowindex")),l=n.dataset.field;return!Number.isInteger(i)||!l?null:{rowIndex:i,field:l,element:n}}function kr(e){const t=e.getSelection();t&&t.rangeCount>0&&t.removeAllRanges()}const fs=(e,t,n)=>Math.min(Math.max(e,t),n),eo=e=>Math.min(Mg,Math.max(2,Math.round(e/2)));function Ig(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Copying ${e} cells. For ranges this large, exportToCsv or exportToExcel is the better tool.`)}function Lg(e){const{enabled:t,model:n,allRenderableRows:o,getRowId:r,navigationColumns:i,columnIndexMap:l,spanning:d,rowMetaMap:a,localeText:u,showStats:g}=e,m=t&&n.length>0?n[0]:null,w=s.useMemo(()=>t?i.filter(O=>Xe(O.field)):[],[t,i]),y=s.useMemo(()=>{if(!d.hasColSpan&&!d.hasRowSpan)return;const{colspanMap:O,rowSpanningCaches:P,getSpanOrigin:T}=d;return{getSpanOrigin:T,getColSpan:(X,B)=>{const ee=O.get(X)?.[B];return ee&&!ee.spannedByColSpan?ee.cellProps.colSpan:1},getRowSpan:(X,B)=>P.spannedCells[X]?.[B]??1}},[d]),p=s.useMemo(()=>{if(!t)return null;const O=o.map(r),P=new Map;O.forEach((X,B)=>{P.has(X)||P.set(X,B)});const T=w.map(X=>X.field);return{rowIds:O,rowIndexById:P,fields:T,colIndexByField:new Map(T.map((X,B)=>[X,B])),spans:y}},[t,o,r,w,y]),f=s.useMemo(()=>m&&p?Kn(m,p):null,[m,p]),h=f!==null&&Tt(f)>1,x=s.useMemo(()=>{if(!f||!h||!p)return null;const O=l.get(p.fields[f.left]),P=l.get(p.fields[f.right]);return O===void 0||P===void 0?null:{top:f.top,bottom:f.bottom,left:O,right:P}},[f,h,p,l]),b=s.useCallback(O=>qe(O,a),[a]),v=s.useCallback((O,P,T)=>{if(p)for(let X=O.top;X<=O.bottom;X++){const B=o[X],ee=p.rowIds[X];if(!(!B||b(ee))){P(B,ee);for(let q=O.left;q<=O.right;q++){const Y=w[q],oe=y?.getSpanOrigin(ee,Y.field);T(B,ee,Y,oe!=null&&(oe.rowId!==ee||oe.field!==Y.field))}}}},[p,o,w,y,b]),E={...e,range:m,resolved:f,context:p,rangeColumns:w,forEachCell:v},k=s.useRef(E);s.useLayoutEffect(()=>{k.current=E});const N=s.useRef(null),M=s.useCallback(O=>{N.current=O},[]),S=s.useCallback(()=>{const{getPendingModel:O,model:P}=k.current;return O()??P},[]),D=s.useCallback(()=>{const{context:O,range:P,resolved:T,enabled:X}=k.current,B=X?S()[0]??null:null;return!B||!O?{range:null,resolved:null}:B===P?{range:B,resolved:T}:{range:B,resolved:Kn(B,O)}},[S]),I=s.useCallback((O,P)=>{if(!k.current.enabled)return;const T=O.length>1?O.slice(0,1):O;nc(T,S())||k.current.onModelChange(T,P)},[S]),A=s.useCallback((O,P,T)=>{I([{anchor:O,head:P}],T)},[I]),C=s.useCallback((O,P)=>{const{viewportRef:T,layout:X,rowHeight:B,pinnedTopRowCount:ee}=k.current,q=T.current;q&&(Gn(q,O-ee,X.cumulativeHeights,X.pinnedBottomHeight,B),To(q,X.unpinnedColsWithWidth.findIndex(Y=>Y.field===P),X))},[]),L=s.useCallback((O,P,T,X)=>{const{context:B}=k.current,{range:ee,resolved:q}=D();if(!B||X.id===null||!Xe(X.field))return!1;const Y=B.rowIndexById.get(X.id),oe=B.colIndexByField.get(X.field);if(Y===void 0||oe===void 0)return!1;const me=ee&&q&&wt(ee.anchor,{id:X.id,field:X.field})?{range:ee,resolved:q}:null,U=me?me.range.anchor:{id:X.id,field:X.field},se=me?.resolved??Kn({anchor:U,head:U},B);if(!se)return!1;const we=rc(se,O,P,T,B.rowIds.length-1,B.fields.length-1);if(!we)return!0;const pe={id:B.rowIds[we.row],field:B.fields[we.col]};return A(U,pe,"keyboard"),C(we.row,pe.field),!0},[D,A,C]),F=s.useCallback(()=>{const{range:O,resolved:P}=D();return!O||!P||Tt(P)<=1?!1:(A(O.anchor,O.anchor,"keyboard"),!0)},[D,A]),_=s.useCallback(()=>{const{context:O}=k.current;return!O||O.rowIds.length===0||O.fields.length===0?!1:(A({id:O.rowIds[0],field:O.fields[0]},{id:O.rowIds[O.rowIds.length-1],field:O.fields[O.fields.length-1]},"selectAll"),!0)},[A]),z=s.useCallback(()=>{const{context:O}=k.current,{range:P,resolved:T}=D();if(!O)return null;if(T)return T;if(P)return null;const X=N.current;return!X||X.id===null||!Xe(X.field)?null:Kn({anchor:{id:X.id,field:X.field},head:{id:X.id,field:X.field}},O)},[D]),K=s.useCallback(()=>{const O=z();if(!O)return null;const{rangeColumns:P,forEachCell:T}=k.current,X=Tt(O);X>ac&&Ig(X);const B=[];if(T(O,me=>{B.push(me)},()=>{}),B.length===0)return null;const ee=P.slice(O.left,O.right+1),q=k.current.context?.spans,Y=k.current.getRowId;return bg(B,ee,q?(me,U)=>{const se=Y(me),we=q.getSpanOrigin(se,U.field);return we!==null&&(we.rowId!==se||we.field!==U.field)}:void 0)},[z]),Q=s.useCallback(()=>{const{forEachCell:O}=k.current,{resolved:P}=D();if(!P)return[];const T=[];return O(P,()=>{},(X,B,ee,q)=>{q||T.push({id:B,field:ee.field,value:Le(X,ee.field,ee)})}),T},[D]),G=s.useRef(null),j=s.useRef(!1);s.useEffect(()=>()=>G.current?.stop(),[]);const H=s.useCallback((O,P,T)=>{const X=k.current.context;if(!X)return null;const B=O.ownerDocument;if(typeof B.elementFromPoint!="function")return null;const ee=us(B.elementFromPoint(P,T),O);if(!ee)return null;const q=X.rowIds[ee.rowIndex];if(q===void 0)return null;const Y=Xe(ee.field)?ee.field:X.fields[0];return Y===void 0?null:{id:q,field:Y}},[]),ie=s.useCallback((O,P)=>{const{context:T,layout:X,pinnedTopRowCount:B}=k.current,ee=X.cumulativeHeights;if(!T||ee.length===0||O<0)return null;let q=0,Y=ee.length-1;for(;q<Y;){const me=q+Y>>1;ee[me]>O?Y=me:q=me+1}const oe=T.rowIds[q+B];return oe===void 0?null:{id:oe,field:P}},[]),re=s.useRef(()=>{}),ue=s.useCallback(O=>{const P=G.current,T=k.current.viewportRef.current;if(!P||!T)return;P.frame=0;const{layout:X}=k.current,B=T.getBoundingClientRect(),ee=T.clientWidth,q=T.clientHeight,Y=T.querySelector(":scope > .ogx__content > .ogx__sticky-top"),oe=T.querySelector(":scope > .ogx__content > .ogx__sticky-bottom"),me=Y?.querySelector(":scope > .ogx__header-wrap"),U=Y?Y.getBoundingClientRect().bottom:B.top,se=Math.min(B.top+q,oe?oe.getBoundingClientRect().top:B.top+q),we=me?me.getBoundingClientRect().bottom:U,pe=B.left+X.pinnedSystemColumnsWidth+X.leftWidth,he=B.left+ee-X.rightWidth,ve=fs(P.x,B.left+1,B.left+ee-2);let be=P.y;(be<B.top||be>B.top+q||be<we)&&(be=fs(be,U+1,Math.max(U+1,se-2)));const de=typeof T.ownerDocument.elementFromPoint=="function",Ee=H(T,ve,be)??(de&&P.moved?ie(be-B.top-(Y?Y.getBoundingClientRect().height:0)+T.scrollTop,P.head.field):null);if(Ee&&!wt(Ee,P.head)&&(P.head=Ee,!P.moved&&!wt(Ee,P.anchor)&&(P.moved=!0,k.current.containerRef.current?.classList.add(ds),kr(T.ownerDocument)),P.onTrack||A(P.anchor,Ee,"pointer")),P.onTrack&&P.onTrack(P.head,P.x,P.y),!O)return;const Me=P.y<U||P.y>se||P.x<B.left||P.x>B.left+ee;if(!P.moved&&!Me)return;let Ne=0,Ie=0;P.y<U+Ct?Ne=-eo(U+Ct-P.y):P.y>se-Ct&&(Ne=eo(P.y-(se-Ct))),P.x<pe+Ct?Ie=-eo(pe+Ct-P.x):P.x>he-Ct&&(Ie=eo(P.x-(he-Ct)));const Se=Ne<0&&T.scrollTop>0||Ne>0&&T.scrollTop+q<T.scrollHeight-1,Oe=Ie<0&&T.scrollLeft>0||Ie>0&&T.scrollLeft+ee<T.scrollWidth-1;!Se&&!Oe||(Se&&(T.scrollTop+=Ne),Oe&&(T.scrollLeft+=Ie),P.frame=requestAnimationFrame(()=>re.current(!0)))},[H,ie,A]);s.useLayoutEffect(()=>{re.current=ue},[ue]);const ae=s.useCallback((O,P,T,X,B,ee)=>{G.current?.stop();const q=ee?"pointermove":"mousemove",Y=ee?"pointerup":"mouseup",oe=de=>!ee||de.pointerId===ee.pointerId,me=de=>{const ye=G.current;if(!(!ye||!oe(de))){if(de.buttons===0){ye.stop();return}ye.x=de.clientX,ye.y=de.clientY,ye.moved&&(de.preventDefault(),kr(B)),ye.frame||(ye.frame=requestAnimationFrame(()=>ue(!0)))}},U=de=>{const ye=G.current;if(!ye||!oe(de))return;ye.x=de.clientX,ye.y=de.clientY,ue(!1);const Ee=ye.moved;ye.stop(!1,de.altKey),Ee&&kr(B),Ee&&(j.current=!0,setTimeout(()=>{j.current=!1},0))},se=de=>{oe(de)&&G.current?.stop()},we=de=>{de.key!=="Escape"||!G.current||(de.preventDefault(),de.stopPropagation(),G.current.stop())},pe=B.defaultView,he=()=>G.current?.stop();let ve=!1;const be={anchor:O,head:P,x:T,y:X,frame:0,moved:!1,onTrack:ee?.onTrack,stop:(de=!0,ye=!1)=>{be.frame&&cancelAnimationFrame(be.frame),be.frame=0,B.removeEventListener(q,me,!0),B.removeEventListener(Y,U,!0),ee&&(B.removeEventListener("pointercancel",se,!0),B.removeEventListener("keydown",we,!0)),pe?.removeEventListener("blur",he),k.current.containerRef.current?.classList.remove(ds),G.current===be&&(G.current=null),ve||(ve=!0,ee&&ee.onEnd({cancelled:de,altKey:ye}))}};G.current=be,B.addEventListener(q,me,!0),B.addEventListener(Y,U,!0),ee&&(B.addEventListener("pointercancel",se,!0),B.addEventListener("keydown",we,!0)),pe?.addEventListener("blur",he)},[ue]),R=s.useCallback(O=>{const P=k.current.viewportRef.current;if(!P||!k.current.enabled)return;const{start:T,x:X,y:B,pointerId:ee,onTrack:q,onEnd:Y}=O;ae(T,T,X,B,P.ownerDocument,{pointerId:ee,onTrack:q,onEnd:Y})},[ae]),te=s.useCallback(O=>{if(O.button!==0||O.defaultPrevented)return;const{context:P}=k.current;if(!P)return;const T=O.currentTarget,X=us(O.target,T);if(!X||!Xe(X.field)||O.target.closest?.(".ogx__cell-fill-handle")||X.element.classList.contains("ogx__cell--editing")||Ai(O.target))return;const B=P.rowIds[X.rowIndex];if(B===void 0)return;const ee={id:B,field:X.field};let q=ee;if(O.shiftKey){const Y=S()[0],oe=N.current;Y&&P.rowIndexById.has(Y.anchor.id)&&P.colIndexByField.has(Y.anchor.field)?q=Y.anchor:oe&&oe.id!==null&&Xe(oe.field)&&(q={id:oe.id,field:oe.field}),O.preventDefault(),j.current=!0;const me=T.ownerDocument;T.contains(me.activeElement)||T.focus({preventScroll:!0})}if(A(q,ee,"pointer"),ae(q,ee,O.clientX,O.clientY,T.ownerDocument),O.shiftKey){const Y=G.current;Y&&!wt(q,ee)&&(Y.moved=!0)}},[S,A,ae]),ce=s.useCallback(O=>{j.current&&(j.current=!1,O.stopPropagation(),O.preventDefault())},[]),W=f?f.right-f.left+1:0,le=f?f.bottom-f.top+1:0,V=u?.cellSelectionAnnouncement??sc,J=h?V(le*W,le,W):"",[ne,fe]=s.useState("");s.useEffect(()=>{if(!t)return;const O=setTimeout(()=>fe(J),Ng);return()=>clearTimeout(O)},[t,J]);const Z=s.useMemo(()=>{if(!g||!f||!h)return null;const O=[];v(f,()=>{},(T,X,B,ee)=>{ee||O.push(Le(T,B.field,B))});const P=O.filter(T=>typeof T=="number"&&!Number.isNaN(T));return{cellCount:Tt(f),rowCount:f.bottom-f.top+1,columnCount:f.right-f.left+1,count:Lt.count(O),numericCount:P.length,sum:P.length?Lt.sum(P):null,average:P.length?Lt.avg(P):null}},[g,f,h,v]),$=s.useMemo(()=>t?{extendSelection:L,collapseSelection:F,selectAllCells:_}:void 0,[t,L,F,_]);return{enabled:t,range:m,resolved:f,displayRange:x,hasRowSpan:d.hasRowSpan,handleMouseDown:t?te:void 0,handleClickCapture:t?ce:void 0,extendSelection:L,collapseSelection:F,selectAllCells:_,keyboard:$,getCopyText:K,getSelectedCells:Q,announcement:t?ne:"",stats:Z,reportFocus:M,setModel:I,getCurrentRange:D,startTrackedDrag:R}}function Ag(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useRef(null),r=s.useRef(null),i=s.useRef(null),{selection:l,model:d,focusedCell:a,setFocusedCell:u,containerRef:g}=e,m=l.range?.anchor??null,w=l.resolved?.anchorRow;s.useLayoutEffect(()=>{l.reportFocus(a);const y=!wt(o.current,m),p=!qo(r.current,a);if(o.current=m,r.current=a,!!l.enabled){if(l.range&&!l.resolved){i.current!==d&&(i.current=d,l.setModel([],"dataChange"));return}if(y&&m){(!a||a.id!==m.id||a.field!==m.field)&&u({id:m.id,field:m.field,rowIndex:w});return}if(p&&a&&a.id!==null&&Xe(a.field)&&!wt(m,{id:a.id,field:a.field})){const f={id:a.id,field:a.field},h=g.current?.classList.contains("ogx--kb")??!1;l.setModel([{anchor:f,head:f}],h?"keyboard":"pointer")}}},[l,d,m,w,a,u,g]),s.useLayoutEffect(()=>{const y=t.current,p=()=>n.current;y.getCellSelectionModel=()=>{const{selection:f,getPendingModel:h,model:x}=p();return f.enabled?h()??x:[]},y.setCellSelectionModel=f=>{p().selection.setModel(f,"api")},y.selectCellRange=(f,h)=>{p().selection.setModel([{anchor:f,head:h}],"api")},y.clearCellSelection=()=>{p().selection.setModel([],"clear")},y.getSelectedCells=()=>p().selection.getSelectedCells(),y.copySelectedCells=async()=>{const{selection:f}=p();if(!f.enabled)return;const h=f.getCopyText();h!==null&&await Sr(h)}},[t])}function gs({count:e,sum:t,average:n}){return c.jsxs("div",{className:"ogx__cell-selection-stats",children:[c.jsxs("span",{className:"ogx__cell-selection-stat",children:[c.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Count"}),c.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"count",children:e.toLocaleString()})]}),t!==null&&c.jsxs("span",{className:"ogx__cell-selection-stat",children:[c.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Sum"}),c.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"sum",children:pn(t,"sum")})]}),n!==null&&c.jsxs("span",{className:"ogx__cell-selection-stat",children:[c.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Average"}),c.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"average",children:pn(n,"avg")})]})]})}function Pg({stats:e,apiRef:t,slot:n,slotProps:o}){const r=n??gs;return c.jsx("div",{className:"ogx__cell-selection-stats-area","aria-hidden":e?void 0:!0,children:e&&c.jsx(r,{apiRef:t,...e,...o})})}function Tg(e){return s.useCallback(t=>{e.current?.classList.toggle("ogx--kb",t)},[e])}function Fg(e){const{ensureGridFocus:t,setKeyboardMode:n,setFocusedCell:o,getRowId:r,onCellClick:i}=e,l=s.useCallback(a=>{t(),n(!1),o({id:r(a.row),field:a.field,rowIndex:a.rowIndex}),i?.(a)},[i,n,o,t,r]),d=s.useCallback(a=>{t(),o({id:null,field:a}),n(!1)},[t,o,n]);return{handleCellClick:l,handleHeaderClick:d}}function Og({paginationSlot:e,paginationSlotProps:t,page:n,paginationModel:o,rowCount:r,pageSizeOptions:i,onPaginationModelChange:l,localeText:d}){const a=e||mr;return c.jsx(a,{page:n,pageSize:o.pageSize,rowCount:r,pageSizeOptions:i,onPageChange:u=>l({...o,page:u}),onPageSizeChange:u=>l({...o,pageSize:u,page:0}),localeText:ji(d),...t})}function Dg({loading:e,error:t,noRowsLabel:n,filteredRowCount:o,dataRowCount:r,filterModel:i,cellSelectionAnnouncement:l,aiAssistantAnnouncement:d}){return c.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[e?"Loading data...":"",t?`Error: ${sl(t)}`:"",!e&&!t&&(o===0?n:i&&((i.quickFilterValues?.length||0)>0||(i.items?.length||0)>0)?`${r} ${r===1?"row":"rows"} found`:""),l?c.jsxs("span",{className:"ogx-aria-live-status__cells",children:[" ",l]}):null,d?c.jsxs("span",{className:"ogx-aria-live-status__ai",children:[" ",d]}):null]})}function $g(e){const{headerRowCount:t,pinnedTopCount:n,pinnedBottomCount:o,pageRowCount:r,totalCenterRowCount:i,pageOffset:l}=e;return{rowCount:t+n+i+o,topBase:t+1,centerOffset:t+l+1,bottomBase:t+n+i+1,bottomRowIndexOffset:n+r}}function Gg(e){const{columnGroupingModel:t,headerFilterRow:n=!1,pinnedTopCount:o,pinnedBottomCount:r,pagination:i,paginationMode:l,paginationModel:d,paginationRowCount:a,paginatedUnpinnedRowCount:u,sortedUnpinnedRowCount:g}=e,{page:m,pageSize:w}=d;return s.useMemo(()=>$g({headerRowCount:1+dl(t)+(n?1:0),pinnedTopCount:o,pinnedBottomCount:r,pageRowCount:i?u:g,totalCenterRowCount:i&&l==="server"?Math.max(a,u):g,pageOffset:i?m*w:0}),[t,n,o,r,i,u,g,l,a,m,w])}function Hg(e){const{toolbar:t,toolbarSlotProps:n,apiRef:o,orderedColumns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:d,pivotMode:a,pivotModelProp:u,onPivotModelChangeProp:g,pivotModel:m,onPivotModelChange:w,filterModel:y,onFilterModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:h,disableColumnReorder:x,columnGroupingModel:b,moveColumn:v,resetColumnOrder:E,forceColumnsOpen:k,onColumnsPanelClose:N,aiAssistantEnabled:M=!1,aiAssistantOpen:S=!1,onAiAssistantToggle:D,aiAssistantLabel:I,forceFiltersOpen:A,onFiltersPanelClose:C}=e;return s.useMemo(()=>t?{apiRef:o,columns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:d,...a||u||g?{pivotModel:m,onPivotModelChange:w}:{},filterModel:y,onFilterModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:h,onColumnReorder:x?void 0:(F,_)=>{rr(b,F,_)&&v(F,_)},onColumnOrderReset:x?void 0:E,forceColumnsOpen:k,onColumnsPanelClose:N,...M&&D?{onAiAssistantToggle:D,aiAssistantOpen:S,...I?{aiAssistantLabel:I}:{}}:{},forceFiltersOpen:A,onFiltersPanelClose:C,...n}:null,[t,x,v,E,r,o,i,l,d,a,u,g,m,w,y,p,f,h,k,N,n,b,M,S,D,I,A,C])}const Bg=Symbol.for("opengridx.ai.validated");function Wg(e){return typeof e=="object"&&e!==null&&e[Bg]===!0}const to=["filter","sort","grouping","aggregation","pivot","columnVisibility"],Er={filter:"filterModel",sort:"sortModel",grouping:"rowGroupingModel",aggregation:"aggregationModel",pivot:"pivotModel",columnVisibility:"columnVisibilityModel"};function ps(e){return to.map(t=>Er[t]).filter(t=>e[t]!==void 0)}function Vg(e,t){const n={},o=[];for(const r of to){const i=Er[r];e[i]!==void 0&&(t.includes(r)?Object.assign(n,{[i]:e[i]}):o.push({path:i,message:"Part not allowed"}))}return{state:n,errors:o}}function zg(e,t){const n=e[t];if(Array.isArray(n))return n.length===0;if(t==="filterModel"){const o=e.filterModel;return!o||(o.items??[]).length===0&&(o.quickFilterValues??[]).length===0}if(t==="pivotModel"){const o=e.pivotModel;return!o||o.rowFields.length===0&&o.columnFields.length===0&&o.valueFields.length===0}return typeof n=="object"&&n!==null&&Object.keys(n).length===0}function Kg(e){let t=e.length;for(const n of[".","["]){const o=e.indexOf(n);o>=0&&o<t&&(t=o)}return e.slice(0,t)}function jg(e,t){const n=new Set(t.map(r=>Kg(typeof r.path=="string"?r.path:""))),o={};for(const r of ps(e))n.has(r)&&zg(e,r)||Object.assign(o,{[r]:e[r]});return o}function Ug(e,t){const n={};for(const o of ps(e))Object.assign(n,{[o]:t[o]});return n}function hs(e,t){const n={};for(const o of to.map(r=>Er[r]))!(o in t)&&e[o]===void 0||(e[o]===void 0?Object.assign(n,{[o]:t[o]}):o==="columnVisibilityModel"?n.columnVisibilityModel={...t.columnVisibilityModel,...e.columnVisibilityModel}:Object.assign(n,{[o]:e[o]}));return n}function Mr(e,t){t.filterModel&&e.setFilterModel(t.filterModel),t.sortModel&&e.setSortModel(t.sortModel),t.rowGroupingModel&&e.setRowGroupingModel(t.rowGroupingModel),t.aggregationModel&&e.setAggregationModel(t.aggregationModel),t.pivotModel&&e.setPivotModel(t.pivotModel),t.columnVisibilityModel&&e.setColumnVisibilityModel(t.columnVisibilityModel)}function ms(e){return Array.isArray(e)?e.map(ms).join(", "):e instanceof Date?e.toISOString().slice(0,10):e==null?"":String(e)}function ws(e,t){return"items"in e?`(${e.items.map(n=>ws(n,t)).join(` ${e.logicOperator} `)})`:[t(e.field),e.operator,ms(e.value)].filter(Boolean).join(" ")}const Rg={sum:"Sum",avg:"Average",count:"Count",min:"Min",max:"Max",unique:"Unique"};function bs(e,t){const n=[],{filterModel:o,sortModel:r,rowGroupingModel:i,aggregationModel:l,pivotModel:d,columnVisibilityModel:a}=e;if(o){const u=o.items??[];u.forEach((m,w)=>n.push({id:`filter:${w}`,part:"filter",label:ws(m,t)}));const g=o.quickFilterValues??[];g.length>0&&n.push({id:"filter:quick",part:"filter",label:`Search: ${g.join(" ")}`}),u.length===0&&g.length===0&&n.push({id:"filter:clear",part:"filter",label:"No filters"})}if(r&&(r.forEach((u,g)=>n.push({id:`sort:${g}`,part:"sort",label:`Sort: ${t(u.field)}, ${u.sort==="desc"?"descending":"ascending"}`})),r.length===0&&n.push({id:"sort:clear",part:"sort",label:"No sorting"})),i&&(i.forEach((u,g)=>n.push({id:`grouping:${g}`,part:"grouping",label:`Group: ${t(u)}`})),i.length===0&&n.push({id:"grouping:clear",part:"grouping",label:"No grouping"})),l){const u=Object.keys(l);u.forEach(g=>{const m=l[g];n.push({id:`aggregation:${g}`,part:"aggregation",label:`${Rg[m]??m}: ${t(g)}`})}),u.length===0&&n.push({id:"aggregation:clear",part:"aggregation",label:"No summaries"})}if(d){const u=[...d.rowFields,...d.columnFields,...d.valueFields.map(g=>g.field)];n.push({id:"pivot",part:"pivot",label:u.length>0?`Pivot: ${u.map(t).join(", ")}`:"No pivot"})}if(a)for(const u of Object.keys(a))n.push({id:`columnVisibility:${u}`,part:"columnVisibility",label:`${a[u]?"Show":"Hide"}: ${t(u)}`});return n}function qg(e,t){const n={...e},o=t.indexOf(":"),r=o<0?t:t.slice(0,o),i=o<0?"":t.slice(o+1),l=Number(i);if(r==="filter"&&n.filterModel){const d={...n.filterModel};i==="quick"?delete d.quickFilterValues:i==="clear"?d.items=[]:d.items=(d.items??[]).filter((a,u)=>u!==l),(d.items??[]).length===0&&(d.quickFilterValues??[]).length===0?delete n.filterModel:n.filterModel=d}else if(r==="sort"&&n.sortModel)n.sortModel=n.sortModel.filter((d,a)=>a!==l),(n.sortModel.length===0||i==="clear")&&delete n.sortModel;else if(r==="grouping"&&n.rowGroupingModel)n.rowGroupingModel=n.rowGroupingModel.filter((d,a)=>a!==l),(n.rowGroupingModel.length===0||i==="clear")&&delete n.rowGroupingModel;else if(r==="aggregation"&&n.aggregationModel){const d={...n.aggregationModel};delete d[i],Object.keys(d).length===0?delete n.aggregationModel:n.aggregationModel=d}else if(r==="columnVisibility"&&n.columnVisibilityModel){const d={...n.columnVisibilityModel};delete d[i],Object.keys(d).length===0?delete n.columnVisibilityModel:n.columnVisibilityModel=d}else r==="pivot"&&delete n.pivotModel;return n}const Xg="Ask about this table…",Yg=[],no=[],xs="The reply was not validated";function Jg(){return typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)}function Zg(e){return typeof e=="object"&&e!==null&&e.name==="AbortError"}function Qg(e){return e instanceof Error&&e.message?e.message:"Unknown error"}function ep(e,t){const n=e===0?"No changes":`Applied ${e} ${e===1?"change":"changes"}`;return t>0?`${n}, ${t} ignored`:n}function ys(e,t,n){if(!e)return;const o=We(()=>e(t));!o.ok&&process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] ${n} threw.`,o.error)}function tp(e){const{apiRef:t,options:n,columns:o}=e,r=!!n,[i,l]=s.useState(!1),[d,a]=s.useState("idle"),[u,g]=s.useState(""),[m,w]=s.useState(null),[y,p]=s.useState(no),[f,h]=s.useState(null),[x,b]=s.useState([]),v=s.useRef(null),E=s.useRef(null),k=s.useRef({params:e,applied:f,history:x,open:i});s.useLayoutEffect(()=>{k.current={params:e,applied:f,history:x,open:i}});const N=s.useMemo(()=>{const j=new Map(o.map(H=>[H.field,H.headerName||H.field]));return H=>j.get(H)??H},[o]),M=s.useMemo(()=>f?bs(f.state,N):[],[f,N]),S=s.useCallback(()=>{const j=v.current;v.current=null,j&&j.abort()},[]);s.useEffect(()=>S,[S]);const D=s.useCallback(j=>{if(!k.current.params.options)return;const H=typeof document>"u"?null:document.activeElement;E.current=j??(H instanceof HTMLElement?H:null),l(!0)},[]),I=s.useCallback(()=>{v.current&&(S(),a("stopped"),g("Stopped")),l(!1);const j=E.current;E.current=null,j&&j.isConnected&&j.focus()},[S]),A=s.useCallback(j=>{k.current.open?I():D(j)},[D,I]),C=s.useCallback((j,H)=>{a("error"),g(j),w(null),p(no),ys(k.current.params.onError,H,"onAiAssistantError")},[]),L=s.useCallback((j,H)=>{const{params:ie}=k.current;if(!(typeof H=="object"&&H!==null)||!Wg(H.state)){process.env.NODE_ENV!=="production"&&console.warn("[OpenGridX] aiAssistant: the onPrompt result was not applied because its state was not validated. Return the result of createGridAiPromptHandler, or pass the model reply through validateGridAiState (from @opencorestack/opengridx/ai) and return its state."),C(xs,new Error(xs));return}const ue=Vg(H.state,ie.options?.parts??to),ae=[...Array.isArray(H.errors)?H.errors:[],...ue.errors],R=jg(ue.state,ae),te=t.current,ce=Ug(R,te.getGridAiState());Mr(te,hs(R,ce)),h({state:R,previous:ce}),p(ae),w(typeof H.message=="string"&&H.message?H.message:null),b(W=>[...W,{prompt:j,applied:R}]),a("applied"),g(ep(bs(R,W=>W).length,ae.length)),ys(ie.onApply,H,"onAiAssistantApply")},[t,C]),F=s.useCallback(j=>{const H=j.trim(),{params:ie,history:re}=k.current,ue=ie.options?.onPrompt;if(!H||!ue)return;S();const ae=new AbortController;v.current=ae,a("running"),g("Thinking…"),w(null),p(no);const R={currentState:t.current.getGridAiState(),history:re,signal:ae.signal},te=We(()=>ue(H,R));(te.ok?Promise.resolve(te.value):Promise.reject(te.error)).then(W=>{v.current===ae&&(v.current=null,L(H,W))},W=>{if(v.current===ae){if(v.current=null,ae.signal.aborted||Zg(W)){a("stopped"),g("Stopped");return}C(`The assistant could not answer: ${Qg(W)}`,W)}})},[t,S,L,C]),_=s.useCallback(()=>{v.current&&(S(),a("stopped"),g("Stopped"))},[S]),z=s.useCallback(()=>{const j=k.current.applied;j&&(Mr(t.current,j.previous),h(null),p(no),w(null),a("idle"),g("Undone"))},[t]),K=s.useCallback(j=>{const H=k.current.applied;if(!H)return;const ie=qg(H.state,j);Mr(t.current,hs(ie,H.previous)),h({state:ie,previous:H.previous}),g("Change removed")},[t]);s.useLayoutEffect(()=>{const j=t.current;j.openAiAssistant=()=>D(),j.closeAiAssistant=()=>{k.current.open&&I()}},[t,D,I]);const Q=r&&i,G=s.useMemo(()=>!Q||!n?null:{status:d,statusText:u,message:m,errors:y,chips:M,history:x,suggestions:n.suggestions??Yg,placeholder:n.placeholder??Xg,voiceAvailable:n.voice!==!1&&Jg(),canUndo:f!==null,submit:F,stop:_,undo:z,removeChip:K,close:I},[Q,n,d,u,m,y,M,x,f,F,_,z,K,I]);return{enabled:r,open:Q,openPanel:D,togglePanel:A,closePanel:I,panelProps:G,announcement:r?u:""}}function np(){if(typeof window>"u")return null;const e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function op(e){const[t,n]=s.useState(!1),o=s.useRef(null),r=s.useRef(e);s.useLayoutEffect(()=>{r.current=e}),s.useEffect(()=>()=>{const l=o.current;o.current=null,l&&We(()=>l.abort())},[]);const i=s.useCallback(()=>{const l=o.current;if(l){We(()=>l.stop());return}const d=np();if(!d)return;const a=We(()=>new d);if(!a.ok)return;const u=a.value;u.lang=typeof navigator>"u"?"en-US":navigator.language,u.interimResults=!1,u.maxAlternatives=1,u.onresult=m=>{const w=m.results[0],y=w&&w[0]?w[0].transcript:"";y&&r.current(y)};const g=()=>{o.current===u&&(o.current=null),n(!1)};u.onend=g,u.onerror=g,o.current=u,n(!0),We(()=>u.start()).ok||g()},[]);return{listening:t,toggle:i}}function vs(){return c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:[c.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),c.jsx("path",{d:"M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8z"})]})}function rp(){return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",focusable:"false",children:[c.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),c.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}function ip(e){const{status:t,statusText:n,message:o,errors:r,chips:i,history:l,suggestions:d,placeholder:a,voiceAvailable:u,canUndo:g,submit:m,stop:w,undo:y,removeChip:p,close:f}=e,[h,x]=s.useState(""),b=s.useRef(null),v=op(x),E=t==="running";s.useEffect(()=>{b.current&&b.current.focus()},[]);const k=S=>{x(S),m(S)},N=S=>()=>{S(),b.current&&b.current.focus()},M=S=>{S.preventDefault(),E||m(h)};return c.jsxs("div",{className:"ogx-ai-panel",role:"dialog","aria-label":"Ask AI",children:[c.jsxs("div",{className:"ogx-ai-panel__header",children:[c.jsxs("span",{className:"ogx-ai-panel__title",children:[c.jsx(vs,{}),"Ask AI"]}),c.jsx(tt,{size:"small",className:"ogx-ai-panel__close","aria-label":"Close",onClick:f,children:"×"})]}),c.jsxs("form",{className:"ogx-ai-panel__form",onSubmit:M,children:[c.jsx(Qe,{ref:b,className:"ogx-ai-panel__input",value:h,placeholder:a,"aria-label":"Prompt",autoComplete:"off",onChange:S=>x(S.target.value)}),u&&c.jsx(tt,{size:"small",variant:"outlined",className:`ogx-ai-panel__mic${v.listening?" ogx-ai-panel__mic--on":""}`,"aria-label":v.listening?"Stop dictation":"Dictate a prompt","aria-pressed":v.listening,onClick:v.toggle,children:c.jsx(rp,{})}),E?c.jsx(tt,{size:"small",variant:"outlined",onClick:N(w),children:"Stop"},"stop"):c.jsx(tt,{size:"small",variant:"contained",color:"primary",type:"submit",disabled:h.trim()==="",children:"Ask"},"ask")]}),d.length>0&&c.jsx("div",{className:"ogx-ai-panel__suggestions","aria-label":"Suggestions",role:"group",children:d.map(S=>c.jsx("button",{type:"button",className:"ogx-ai-panel__suggestion",disabled:E,onClick:()=>k(S),children:S},S))}),n&&c.jsx("div",{className:`ogx-ai-panel__status ogx-ai-panel__status--${t}`,children:n}),o&&c.jsx("p",{className:"ogx-ai-panel__message",children:o}),(i.length>0||g)&&c.jsxs("div",{className:"ogx-ai-panel__changes",children:[c.jsx("ul",{className:"ogx-ai-panel__chips","aria-label":"Applied changes",children:i.map(S=>c.jsxs("li",{className:"ogx-ai-chip","data-part":S.part,children:[c.jsx("span",{className:"ogx-ai-chip__label",children:S.label}),c.jsx("button",{type:"button",className:"ogx-ai-chip__remove","aria-label":`Remove ${S.label}`,onClick:N(()=>p(S.id)),children:"×"})]},S.id))}),g&&c.jsx(tt,{size:"small",variant:"outlined",className:"ogx-ai-panel__undo",onClick:N(y),children:"Undo"})]}),r.length>0&&c.jsx("ul",{className:"ogx-ai-panel__errors","aria-label":"Ignored",children:r.map((S,D)=>c.jsx("li",{children:S.path?`Ignored: ${S.message}`:S.message},`${S.path}:${D}`))}),l.length>0&&c.jsxs("div",{className:"ogx-ai-panel__history",children:[c.jsx("div",{className:"ogx-ai-panel__history-title",children:"Earlier"}),c.jsx("ul",{children:l.map((S,D)=>c.jsx("li",{children:c.jsx("button",{type:"button",className:"ogx-ai-panel__history-item",onClick:()=>x(S.prompt),children:S.prompt})},`${D}:${S.prompt}`))})]})]})}function lp({panelProps:e,slot:t,slotProps:n}){const o=r=>{r.key==="Escape"&&(r.stopPropagation(),e.close())};return c.jsx("div",{className:"ogx-ai-anchor",onKeyDown:o,children:t?c.jsx(t,{...e,...n}):c.jsx(ip,{...e})})}function sp(e){const{rows:t,columns:n,getRowId:o,rowHeight:r,headerHeight:i,wrapHeaderText:l=!1,headerFilters:d=!1,headerFilterHeight:a=Pd,autoHeight:u=!1,density:g,checkboxSelection:m=!1,disableRowSelectionOnClick:w=!1,disableMultipleRowSelection:y=!1,disableClipboardCopy:p=!1,cellSelection:f=!1,cellSelectionModel:h,onCellSelectionModelChange:x,showCellSelectionStats:b=!1,disableClipboardPaste:v=!1,disableRangeClear:E=!1,onClipboardPaste:k,onBeforeClipboardPaste:N,undoRedo:M=!1,disableFillHandle:S=!1,onFill:D,onHistoryChange:I,rowSelectionModel:A,onRowSelectionModelChange:C,onRowClick:L,onRowDoubleClick:F,onCellClick:_,filterModel:z,onFilterModelChange:K,sortModel:Q,onSortModelChange:G,pagination:j=!1,paginationModel:H,onPaginationModelChange:ie,pageSizeOptions:re=[10,25,50,100],pinnedColumns:ue,onPinnedColumnsChange:ae,pinnedRows:R,getDetailPanelContent:te,getDetailPanelHeight:ce,detailPanelExpandedRowIds:W,onDetailPanelExpandedRowIdsChange:le,pinCheckboxColumn:V=!0,pinExpandColumn:J=!0,disableColumnReorder:ne=!1,columnOrder:fe,onColumnOrderChange:Z,onColumnOrderModelChange:$,height:O,rowReordering:P=!1,onRowOrderChange:T,loading:X=!1,treeData:B=!1,getTreeDataPath:ee,defaultGroupingExpansionDepth:q,groupingColDef:Y,rowGroupingModel:oe,onRowGroupingModelChange:me,aggregationModel:U,onAggregationModelChange:se,getAggregationPosition:we,isCellEditable:pe,processRowUpdate:he,onProcessRowUpdateError:ve,dataSource:be,multiSort:de=!1,sortingMode:ye="client",filterMode:Ee="client",paginationMode:Me="client",rowCount:Ne,slots:Ie,slotProps:Se,pivotMode:Oe=!1,pivotModel:ge,onPivotModelChange:Ce,className:ke="",style:xe,onRowsScrollEnd:je,ariaLabel:nt,initialState:nn,onStateChange:Mn,columnVisibilityModel:ot,onColumnVisibilityModelChange:lo,listView:so=!1,listViewColumn:Nn,columnGroupingModel:In,noRowsLabel:kh="No Data",localeText:Ln,apiRef:Eh,overscanRowCount:Mh=3,aiAssistant:Nh,onAiAssistantApply:Ih,onAiAssistantError:Lh}=e,Lr=ig(n),Ar=Ln?.noRowsLabel??kh,$t=mc({initialState:nn,sortModel:Q,onSortModelChange:G,filterModel:z,onFilterModelChange:K,aggregationModel:U,onAggregationModelChange:se,rowGroupingModel:oe,onRowGroupingModelChange:me,columnVisibilityModel:ot,onColumnVisibilityModelChange:lo,pinnedColumns:ue,onPinnedColumnsChange:ae,pivotModel:ge,onPivotModelChange:Ce,paginationModel:H,onPaginationModelChange:ie,pageSizeOptions:re,rowSelectionModel:A,onRowSelectionModelChange:C,density:g,cellSelectionModel:h,onCellSelectionModelChange:x}),{sortModel:ut,handleSortModelChange:Ys,filterModel:ft,handleFilterModelChange:Pr,aggregationModel:Ue,handleAggregationModelChange:Js,columnVisibilityModel:_t,handleColumnVisibilityModelChange:ao,pinnedColumns:Tr,handlePinnedColumnsChange:Ah,currentPivotModel:Fr,handlePivotModelChange:Zs,effectivePaginationModel:Re,handlePaginationModelChange:on,selectedRowIds:Ph,handleRowSelectionModelChange:Or,density:Qs,rowGroupingModel:Dr,handleRowGroupingModelChange:Th}=$t,An=Sf({rows:t,columns:Lr,pivotMode:Oe,pivotModel:Fr,filterModel:ft,sortModel:ut,hasDataSource:!!be,hierarchyRequested:B||Dr.length>0}),St=An.isActive,co=d&&!St,{rowReordering:Gt,hierarchyRowGroupingModel:Fh,isTreeDataRequested:Oh,isTreeData:uo,isRowGrouping:rn,isHierarchyEnabled:fo,hasGroupingColumn:Dh,pagination:rt,listView:ln}=fc({rowGroupingModel:Dr,treeData:B,hasTreeDataPath:!!ee,isPivotActive:St,rowReordering:P,hasGroupingColDef:!!Y,pagination:j,paginationMode:Me,listView:so,hasListViewColumn:!!Nn}),{rowHeight:it,headerHeight:$r}=vc({rowHeight:r,headerHeight:i,density:Qs}),$h=An.rows,Gh=An.columns,{activeColumns:gt,effectivePinnedColumns:sn}=Zf({baseColumns:Gh,pinnedColumns:Tr,hasGroupingColumn:Dh,groupingColDef:Y,isTreeData:uo,getTreeDataPath:ee}),Gr=od(gt,_t),[Hh,Bh]=vf(Ue),Ye=s.useRef(null),Ht=s.useRef(null),ea=!St&&o||Qf,Hr=Tg(Ye),go=Zd({rows:$h,getRowId:ea,columns:gt,rowHeight:it,headerHeight:$r,columnVisibilityModel:_t,initialState:e.initialState,syncRows:!be}),{state:Fe,apiRef:lt,setRows:Wh,replaceRows:Vh,setColumns:zh,setDimensions:Kh,setDataSourceLoading:jh,setDataSourceError:Uh,setRowCount:Rh}=go,{getRowIdOf:Pe,getRowIdOfInEvents:qh}=eg(Fe.rows.idByRow);tg(Eh,lt);const Xh=Fe.dataSource.loading,kt=X||Xh,po=s.useMemo(()=>Fe.rows.allRows.map(ht=>Fe.rows.idRowsLookup.get(ht)),[Fe.rows]),{treeDataHandlers:ho,rowGroupingHandlers:Br,activeHierarchyHandlers:an,rowMetaMap:Ve}=hu({rows:po,getRowId:Pe,getTreeDataPath:ee,isTreeDataRequested:Oh,isTreeData:uo,columns:gt,rowGroupingModel:Fh,isRowGrouping:rn,aggregationModel:Ue,defaultGroupingExpansionDepth:q,filterModel:ft,sortModel:ut,getAggregationPosition:we,columnLookup:Gr,filterMode:Ee,sortingMode:ye}),Wr=Gu(),mo=wu({rowsLookup:Fe.rows.idRowsLookup,columns:gt,processRowUpdate:he,onProcessRowUpdateError:ve,replaceRows:Vh,onCommitted:Wr.emit}),Pn=mu({rows:po,getRowId:Pe,columns:gt,processRowUpdate:he,onProcessRowUpdateError:ve,onRowChange:(ht,Sm)=>{mo.storeRow(Sm,ht)},onCommitted:ht=>Wr.emit(ht,"edit")}),Tn=Qc({selectedRowIds:Ph,rowsLookup:Fe.rows.idRowsLookup,rowMetaMap:Ve,enabled:!be&&!St&&Me==="client"&&Ee==="client",onSelectionModelChange:Or}),ta=bf({dataSource:be,sortModel:ut,filterModel:ft,paginationModel:Re,paginationMode:Me,sortingMode:ye,filterMode:Ee,aggregationModel:Ue,rowGroupingActive:rn,getRowId:ea,setRows:Wh,setRowCount:Rh,setDataSourceLoading:jh,setDataSourceError:Uh,onAggregationResults:Bh,onPaginationModelChange:on});yf({enabled:uo&&!!be,treeNodes:ho.treeNodes,isGroupExpanded:ho.isGroupExpanded,getNodePath:ho.getNodePath,toggleExpansion:ho.toggleExpansion,fetchChildren:ta.fetchChildren});const{hasDetailPanel:Bt,expandedRowIds:Vr,handleDetailPanelToggle:na,detailPanelHeights:Yh,reportDetailPanelHeight:Jh}=Bc({hasDetailPanel:!!te,controlledExpandedRowIds:W,onDetailPanelExpandedRowIdsChange:le,rowMetaMap:Ve}),{effectiveColumns:oa,hierarchyField:zr,orderedColumns:Kr,visibleOrderedColumns:ra,renderOrderedColumns:Zh,navigationColumns:cn,columnIndexMap:wo,columnWidths:Fn,effectiveColumnOrder:Qh,columnReorderHandlers:em,moveColumn:ia,resetColumnOrder:la,handleColumnResize:sa}=Ac({activeColumns:gt,isHierarchyEnabled:fo,isRowGrouping:rn,isTreeData:uo,activeHierarchyHandlers:an,columnVisibilityModel:_t,columnOrder:fe,onColumnOrderChange:Z,onColumnOrderModelChange:$,disableColumnReorder:ne,pivotMode:St,checkboxSelection:m,hasDetailPanel:Bt,rowReordering:Gt,initialState:nn,setColumns:zh,pinnedColumns:sn,getRowId:qh,aggregationModel:Ue,groupingRows:rn?Br.groupingRows:void 0});zc({onStateChange:Mn,sortModel:ut,filterModel:ft,effectivePaginationModel:Re,columnWidths:Fn,effectiveColumnOrder:Qh,columnVisibilityModel:_t,pinnedColumns:Tr,density:Qs});const bo=_c({effectiveRows:po,activeHierarchyHandlers:an,filterMode:Ee,filterModel:An.pipelineFilterModel,sortModel:An.pipelineSortModel,sortingMode:ye,pagination:rt,paginationMode:Me,effectivePaginationModel:Re,pinnedRows:R,getRowId:Pe,columnLookup:Gr,hierarchyField:zr}),{filteredRows:aa,dataRows:dn,pinnedTopRows:ze,pinnedBottomRows:st,sortedUnpinnedRows:pt,paginatedUnpinnedRows:xo,allRenderableRows:Et}=bo,jr=rt?xo:pt;rd({paginationModel:Re,currentPage:bo.currentPage,enabled:rt&&!kt&&pt.length>0,onPaginationModelChange:on});const yo=Cc({paginationMode:Me,hasDataSource:!!be,dataSourceRowCount:Fe.pagination.rowCount,rowCountProp:Ne,clientRowCount:pt.length}),{rowSelection:Ur,handleRowClick:Rr,handleSelectionChange:qr}=Zc({dataRows:dn,getRowId:Pe,isPivotActive:St,selectedRowIds:Tn,onSelectionModelChange:Or,disableMultipleRowSelection:y,disableRowSelectionOnClick:w,isHierarchyEnabled:fo,rowMetaMap:Ve,activeHierarchyHandlers:an,onRowClick:L});nd({apiRef:go.apiRef,sortModel:ut,multiSort:de,onSortModelChange:Ys,filterModel:ft,onFilterModelChange:Pr,paginationModel:Re,onPaginationModelChange:on,selectedRowIds:Tn,getPendingRowSelectionModel:$t.getPendingRowSelectionModel,onRowSelectionModelChange:Or,disableMultipleRowSelection:y,isSyntheticRowId:ht=>qe(ht,Ve),getVisibleRows:()=>[...ze,...jr,...st],getAllFilteredRows:()=>ng({hierarchyHandlers:an,pinnedTopRows:ze,sortedUnpinnedRows:pt,pinnedBottomRows:st,rowMetaMap:Ve,getRowId:Pe,hierarchyField:zr,dataRows:dn}),visibleColumns:Zh,rowGroupingModel:Dr,onRowGroupingModelChange:Th,aggregationModel:Ue,onAggregationModelChange:Js,columnVisibilityModel:_t,onColumnVisibilityModelChange:ao,pivotModel:Fr,onPivotModelChange:Zs});const tm=Qd({rows:po,getRowId:Pe,onRowOrderChange:T,rowReordering:Gt}),{aggregationResult:Xr,isLoading:nm}=Ql({rows:dn,columns:gt,aggregationModel:St?Ia:Ue,isServerSide:il({dataSource:be,paginationMode:Me,sortingMode:ye,filterMode:Ee}),dataSource:be,filterModel:ft,sortModel:ut,serverAggregationResults:Hh}),Yr=Object.keys(Ue).length>0&&!St;sg({apiRef:lt,hasAggregation:Yr,aggregationResult:Xr,aggregationModel:Ue,isRowGrouping:rn,rowGroupingHandlers:Br,rowMetaMap:Ve,columns:gt,getRowId:Pe,hierarchyField:zr});const De=Ma({rowHeight:it,pagination:rt,paginatedUnpinnedRows:xo,sortedUnpinnedRows:pt,expandedRowIds:Vr,getDetailPanelHeight:ce,detailPanelHeights:Yh,pinnedTopRowsLength:ze.length,pinnedBottomRowsLength:st.length,pinnedTopRows:ze,pinnedBottomRows:st,visibleOrderedColumns:ra,pinnedColumns:sn,columnWidths:Fn,viewportWidth:Fe.dimensions.viewportWidth||1e3,checkboxSelection:m,hasDetailPanel:Bt,rowReordering:Gt,pinCheckboxColumn:V,pinExpandColumn:J,paginationMode:Me,isLoading:Fe.dataSource.loading,pageSize:Re.pageSize,getRowId:Pe}),Mt=uf({pinnedTopRows:ze,centerRows:jr,pinnedBottomRows:st,columns:ra,leftPinnedColumns:De.leftPinnedCols,unpinnedColumns:De.unpinnedColsWithWidth,rightPinnedColumns:De.rightPinnedCols,expandedRowIds:Bt?Vr:void 0,rowMetaMap:Ve,getRowId:Pe}),ca=s.useMemo(()=>[...De.leftPinnedCols,...De.unpinnedColsWithWidth,...De.rightPinnedCols],[De.leftPinnedCols,De.unpinnedColsWithWidth,De.rightPinnedCols]),Ge=Lg({enabled:f&&!ln,model:$t.cellSelectionModel,onModelChange:$t.handleCellSelectionModelChange,getPendingModel:$t.getPendingCellSelectionModel,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,columnIndexMap:wo,spanning:Mt,rowMetaMap:Ve,layout:De,rowHeight:it,pinnedTopRowCount:ze.length,viewportRef:Ht,containerRef:Ye,localeText:Ln,showStats:b});vg({apiRef:lt,columns:ca,getRowId:Pe,containerRef:Ye,disableKeyboardShortcut:p,getCellRangeCopyText:Ge.enabled?Ge.getCopyText:void 0}),Cg({apiRef:lt,viewportRef:Ht,layout:De,rowHeight:it});const om=Eg({apiRef:lt,containerRef:Ye,columns:Kr,onColumnResize:sa}),{scrollTop:rm,scrollLeft:im,overscanRows:lm,handleScroll:sm,setViewportElement:am}=Gc({onRowsScrollEnd:je,overscanRowCount:Mh,rowCount:De.unpinnedRowsLength,autoHeight:u,setDimensions:Kh,viewportRef:Ht}),Be=Sc({layout:De,scrollTop:rm,scrollLeft:im,viewportWidth:Fe.dimensions.viewportWidth,viewportHeight:Fe.dimensions.viewportHeight,autoHeight:u,rowReordering:Gt,hasDetailPanel:Bt,checkboxSelection:m,pinCheckboxColumn:V,pinExpandColumn:J,overscanRows:lm}),{handleSort:da,handleSortAdd:ua}=ed({sortModel:ut,onSortModelChange:Ys}),vo=m||!w,{focusedCell:Co,setFocusedCell:Jr,viewportTabIndex:cm,ensureGridFocus:dm,handleFocus:um,handleBlur:fm,handleKeyDown:gm,handleMouseDownCapture:pm}=uc({allRenderableRows:Et,navigationColumns:cn,checkboxSelection:m,selectedRowIds:Tn,handleSelectionChange:qr,handleDetailPanelToggle:na,editingHandlers:Pn,setKeyboardMode:Hr,sortModel:ut,handleSort:da,handleSortAdd:ua,multiSort:de,isCellEditable:pe,pagination:rt,pageSize:Re.pageSize,virtualization:Be,viewportRef:Ht,pinnedTopRowCount:ze.length,getRowId:Pe,rowMetaMap:Ve,getSpanOrigin:Mt.getSpanOrigin,onRowActivate:Rr,toggleRowExpansion:an?.toggleExpansion,handleSelectAll:Ur.selectAll,rowSelectionEnabled:vo,multipleRowSelectionEnabled:!y,pinCheckboxColumn:V,pinExpandColumn:J,rowHeight:it,cellSelection:Ge.keyboard,headerFilters:co}),{handleCellClick:hm,handleHeaderClick:mm}=Fg({ensureGridFocus:dm,setKeyboardMode:Hr,setFocusedCell:Jr,getRowId:Pe,onCellClick:_});Ag({apiRef:lt,selection:Ge,model:$t.cellSelectionModel,getPendingModel:$t.getPendingCellSelectionModel,focusedCell:Co,setFocusedCell:Jr,containerRef:Ye}),Du({apiRef:lt,containerRef:Ye,viewportRef:Ht,selection:Ge,disableClipboardPaste:v,disableRangeClear:E,focusedCell:Co,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,isCellEditable:pe,rowMetaMap:Ve,getSpanOrigin:Mt.getSpanOrigin,isEditing:Pn.editingCell!==null,batchEdit:mo,onClipboardPaste:k,onBeforeClipboardPaste:N}),Bu({apiRef:lt,enabled:!!M,limit:typeof M=="object"&&M.limit||$u,onHistoryChange:I,channel:Wr,batchEdit:mo,isEditing:Pn.editingCell!==null,containerRef:Ye,viewportRef:Ht,selection:Ge,setFocusedCell:Jr,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,layout:De,rowHeight:it,pinnedTopRowCount:ze.length});const wm=sf({containerRef:Ye,viewportRef:Ht,selection:Ge,disableFillHandle:S,isEditing:Pn.editingCell!==null,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,columnIndexMap:wo,isCellEditable:pe,rowMetaMap:Ve,getSpanOrigin:Mt.getSpanOrigin,batchEdit:mo,onFill:D}),{handleHideColumn:bm,handlePinColumn:xm}=td({columnVisibilityModel:_t,onColumnVisibilityModelChange:ao,pinnedColumns:Tr,onPinnedColumnsChange:Ah}),On=Gg({columnGroupingModel:In,headerFilterRow:co,pinnedTopCount:ze.length,pinnedBottomCount:st.length,pagination:rt,paginationMode:Me,paginationModel:Re,paginationRowCount:yo,paginatedUnpinnedRowCount:xo.length,sortedUnpinnedRowCount:pt.length}),Zr=gf({spanning:Mt,renderContext:Be.renderContext,offsetTop:Be.offsetTop,cumulativeHeights:De.cumulativeHeights}),Qr=Tc({renderContext:Zr.renderContext,pinnedTopRows:ze,pinnedBottomRows:st,paginatedUnpinnedRows:xo,sortedUnpinnedRows:pt,pagination:rt,getRowId:Pe}),_o=pf({spanning:Mt,firstColumnIndex:Be.renderContext.firstColumnIndex,lastColumnIndex:Be.renderContext.lastColumnIndex,virtualColumns:Be.virtualColumns,layout:De,rows:Qr});Rc({paginationRequested:j,isRowGrouping:rn,autoHeight:u,viewportHeight:Fe.dimensions.viewportHeight,renderedRowCount:Qr.length,totalRowCount:ze.length+jr.length+st.length,pinnedRowsIgnored:fo&&!!(R?.top?.length||R?.bottom?.length),scrollHeight:Be.totalHeight,listViewWithoutColumn:so&&!Nn,listViewRowCount:ln&&Nn?Et.length:0});const{allSelected:ym,someSelected:vm}=Ur,un=hf(In,em),Cm=s.useMemo(()=>oa.some(ht=>!!ht.rowSpan),[oa]),at=id();Xc(Ye);const fn=tp({apiRef:lt,options:Nh,columns:gt,onApply:Ih,onError:Lh}),fa=Ie?.noRowsOverlay,ga=Ie?.loadingOverlay,ei=ga?c.jsx(ga,{...Se?.loadingOverlay}):void 0,pa=fa?c.jsx(fa,{...Se?.noRowsOverlay}):void 0,So=Ie?.footer,_m=kt&&Et.length>0&&Me!=="infinite",ha=Ie?.toolbar,ma=Hg({toolbar:Ie?.toolbar,toolbarSlotProps:Se?.toolbar,apiRef:lt,orderedColumns:Kr,baseColumns:Lr,aggregationModel:Ue,onAggregationModelChange:Js,pivotMode:Oe,pivotModelProp:ge,onPivotModelChangeProp:Ce,pivotModel:Fr,onPivotModelChange:Zs,filterModel:ft,onFilterModelChange:Pr,columnVisibilityModel:_t,onColumnVisibilityModelChange:ao,disableColumnReorder:ne,columnGroupingModel:In,moveColumn:ia,resetColumnOrder:la,forceColumnsOpen:at.toolbarPanelRequested,onColumnsPanelClose:at.closeToolbarPanel,aiAssistantEnabled:fn.enabled,aiAssistantOpen:fn.open,onAiAssistantToggle:fn.togglePanel,aiAssistantLabel:Ln?.aiAssistantButton,forceFiltersOpen:at.toolbarFiltersRequested,onFiltersPanelClose:at.closeToolbarFiltersPanel}),ti={rowReordering:Gt,columnIndexMap:wo,editingHandlers:Pn,isCellEditable:pe,selectedRowIds:Tn,checkboxSelection:m,onRowClick:Rr,onRowDoubleClick:F,onCellClick:hm,onSelectionChange:qr,columnWidths:Fn,pinnedColumns:sn,hasDetailPanel:Bt,expandedRowIds:Vr,getDetailPanelContent:te,getDetailPanelHeight:ce,onDetailPanelToggle:na,onDetailPanelHeightChange:Jh,pinCheckboxColumn:V,pinExpandColumn:J,focusedCell:Co,colspanMap:Mt.colspanMap,rowSpanningCaches:Mt.rowSpanningCaches,rowHeight:it,rowMetaMap:Ve,cellRange:Ge.displayRange,cellRangeHasRowSpan:Ge.hasRowSpan,fillHandle:wm.handle};return c.jsxs("div",{ref:Ye,className:["ogx",ke,u&&"ogx--auto-height",!u&&O===void 0&&xe?.height===void 0&&"ogx--fill",Cm&&"ogx--row-spanning",ln&&"ogx--list-view"].filter(Boolean).join(" "),style:{...xe,height:O??xe?.height,"--ogx-row-height":`${it}px`,"--ogx-header-height":`${$r}px`,...co?{"--ogx-header-filter-height":`${a}px`}:void 0},"aria-busy":kt,children:[ha&&ma&&c.jsx(ol.Provider,{value:at.toolbarHost,children:c.jsx(ad,{component:ha,toolbarProps:ma})}),fn.panelProps&&c.jsx(lp,{panelProps:fn.panelProps,slot:Ie?.aiAssistantPanel,slotProps:Se?.aiAssistantPanel}),c.jsx(Jf,{isOpen:at.standalonePanelOpen,containerRef:Ye,panelRef:at.standalonePanelRef,columns:Kr,columnVisibilityModel:_t,disableColumnReorder:ne,onClose:at.closeStandalonePanel,onColumnVisibilityChange:ao,onColumnMove:ia,onColumnOrderReset:la,columnGroupingModel:In}),ln&&Nn&&c.jsx(Nf,{ariaLabel:nt,allRenderableRows:Et,dataRowCount:dn.length,pinnedTopRowCount:ze.length,pinnedBottomRowCount:st.length,unpinnedRowCount:pt.length,pagination:rt,effectivePaginationModel:Re,currentPage:bo.currentPage,pageSizeOptions:re,selectedRowIds:Tn,listViewColumn:Nn,columnsByField:Gr.byField,rowMetaMap:Ve,noRowsLabel:Ar,rowHeight:it,checkboxSelection:m,paginationMode:Me,serverRowCount:yo,paginationSlot:Ie?.pagination,paginationSlotProps:Se?.pagination,localeText:ji(Ln),onRowClick:Rr,onRowDoubleClick:F,onSelectionChange:qr,onPaginationModelChange:on,onRowsScrollEnd:je,getRowId:Pe,multiselectable:vo&&!y,selectable:vo,onToggleExpansion:an?.toggleExpansion,loading:kt,loadingOverlay:ei,noRowsOverlay:pa,showPaginationControls:!So}),!ln&&c.jsx("div",{ref:am,className:"ogx__viewport",onScroll:sm,role:"grid","aria-label":nt||"Data grid","aria-rowcount":On.rowCount,"aria-colcount":cn.length,"aria-multiselectable":vo&&!y||Ge.enabled,"aria-busy":kt,tabIndex:cm,onKeyDownCapture:()=>{Hr(!0)},onMouseDownCapture:pm,onMouseDown:Ge.handleMouseDown,onClickCapture:Ge.handleClickCapture,onKeyDown:gm,onFocus:um,onBlur:fm,children:c.jsxs("div",{className:"ogx__content",style:{width:sn?.right?.length?`max(100%, ${Be.totalWidth}px)`:Be.totalWidth},role:"presentation",children:[c.jsxs("div",{className:"ogx__sticky-top",role:"presentation",children:[c.jsx(_l,{columns:_o,allColumns:ca,columnGroupingModel:In,checkboxSelection:m,allSelected:ym,someSelected:vm,onSelectAll:Ur.selectAll,sortModel:ut,onSort:da,onSortAdd:ua,multiSort:de,onColumnResize:sa,onColumnAutosize:om,columnWidths:Fn,pinnedColumns:sn,focusedCell:Co,columnIndexMap:wo,onHeaderClick:mm,onDragStart:un.onDragStart,onDragOver:un.onDragOver,onDragEnd:un.onDragEnd,onDrop:un.onDrop,draggedColumn:un.draggedColumn,dragOverColumn:un.dragOverColumn,rowReordering:Gt,hasDetailPanel:Bt,pinCheckboxColumn:V,pinExpandColumn:J,aggregationModel:Ue,onHideColumn:bm,onManageColumns:at.openColumnsPanel,onPinColumn:xm,wrapHeaderText:l,headerHeight:$r,headerFilters:co,filterModel:ft,onFilterModelChange:Pr,onOpenFilterPanel:at.openFiltersPanel}),c.jsx(rs,{...ti,rows:ze,position:"top",ariaRowIndexBase:On.topBase,columns:_o,pinnedRows:R,getRowId:Pe})]}),!kt&&!Fe.dataSource.error&&aa.length===0&&c.jsx(dd,{noRowsLabel:Ar,width:Be.totalWidth,overlay:pa}),c.jsx(qf,{...ti,virtualContainerHeight:Be.totalHeight-Be.pinnedTopHeight-Be.pinnedBottomHeight,offsetTop:Zr.offsetTop,effectiveLoading:kt,visibleRows:Qr,baseColumns:Lr,virtualColumns:_o,viewportWidth:Fe.dimensions.viewportWidth,rowReorderHandlers:tm,paginationMode:Me,dataSourceLoading:Fe.dataSource.loading,sortedUnpinnedRowCount:pt.length,infiniteScrollSkeletonCount:Math.min(Re.pageSize,20),unpinnedRowsLength:De.unpinnedRowsLength,lastRenderedRowIndex:Zr.renderContext.lastRowIndex,ariaRowIndexOffset:On.centerOffset,loadingOverlay:ei}),c.jsxs("div",{className:"ogx__sticky-bottom",role:"presentation",children:[c.jsx(rs,{...ti,rows:st,position:"bottom",rowIndexOffset:On.bottomRowIndexOffset,ariaRowIndexBase:On.bottomBase,columns:_o,pinnedRows:R,getRowId:Pe}),Yr&&Br.rootAggregationPosition!==null&&c.jsx(cd,{columns:Be.virtualColumns,aggregationModel:Ue,aggregationResult:Xr,columnWidths:Fn,rowHeight:it,checkboxSelection:m,hasDetailPanel:Bt,rowReordering:Gt,pinCheckboxColumn:V,pinExpandColumn:J,pinnedColumns:sn,loading:nm})]})]})}),Ge.enabled&&b&&c.jsx(Pg,{stats:Ge.stats,apiRef:go.apiRef,slot:Ie?.cellSelectionStats,slotProps:Se?.cellSelectionStats}),So&&c.jsx(So,{apiRef:go.apiRef,aggregationModel:Ue,aggregationResult:Yr?Xr:null,rowCount:fo&&Me!=="server"?dn.length:yo,pagination:rt,paginationModel:Re,pageSizeOptions:re,onPaginationModelChange:on,...Se?.footer}),!ln&&!So&&rt&&c.jsx(Og,{paginationSlot:Ie?.pagination,paginationSlotProps:Se?.pagination,page:bo.currentPage,paginationModel:Re,rowCount:yo,pageSizeOptions:re,onPaginationModelChange:on,localeText:Ln}),c.jsx(Dg,{loading:kt,error:Fe.dataSource.error,noRowsLabel:Ar,filteredRowCount:aa.length,dataRowCount:dn.length,filterModel:ft,cellSelectionAnnouncement:Ge.announcement,aiAssistantAnnouncement:fn.announcement}),_m&&c.jsx(If,{overlay:ei}),c.jsx(fd,{error:Fe.dataSource.error,onRetry:be?ta.fetchRows:void 0})]})}function ap({rows:e=5,columns:t=5}){return c.jsx("div",{className:"ogx__skeleton",children:Array.from({length:e}).map((n,o)=>c.jsx("div",{className:"ogx__skeleton-row",children:Array.from({length:t}).map((r,i)=>c.jsx("div",{className:"ogx__skeleton-cell",children:c.jsx("div",{className:"ogx__skeleton-content"})},i))},o))})}const cp=300;function Zt(e){return"field"in e&&!("items"in e)}function Cs(e,t){return e.find(n=>Zt(n)&&n.field===t)}function _s(e,t){return Object.is(e,t)?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>_s(n,t[o])):!1}function dp(e,t){return e===t?!0:Zt(e)&&Zt(t)?e.id===t.id&&e.field===t.field&&e.operator===t.operator&&_s(e.value,t.value):!Zt(e)&&!Zt(t)?e.id===t.id&&e.logicOperator===t.logicOperator&&Nr(e.items,t.items):!1}function Nr(e,t){return e===t?!0:e.length===t.length&&e.every((n,o)=>dp(n,t[o]))}function up(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function Ss(e,t){return Object.is(e.value,t)?!0:t!=null&&String(e.value).toLowerCase()===String(t).toLowerCase()}function ks(e,t){return Bo(e,t.type)}function Es(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function fp(e,t){if(!Vt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const gp=({col:e,item:t,resetToken:n,onChange:o})=>{const r=s.useId(),i=s.useMemo(()=>bi(e.type),[e.type]),l=i[0],d=t?.operator??l,a=i.includes(d)?i:[d,...i],u=!!t,g=e.headerName||e.field,[m,w]=s.useState(null),[y,p]=s.useState(n);y!==n&&(p(n),w(null));const f=s.useRef(o),h=s.useRef(t),x=s.useRef(e);s.useLayoutEffect(()=>{f.current=o,h.current=t,x.current=e});const b=s.useCallback((L,F)=>({id:h.current?.id??`${e.field}-${Date.now()}`,field:e.field,operator:L,value:F}),[e.field]),v=s.useCallback(L=>{const F=h.current;if(F?L===ks(F.value,x.current):L.trim()==="")return;const z=F?.operator??l;f.current(b(z,Es(L,z)))},[l,b]),E=s.useRef(null),k=s.useRef(v);s.useLayoutEffect(()=>{E.current=m,k.current=v}),s.useEffect(()=>()=>{const L=E.current;E.current=null,L!==null&&k.current(L)},[]),s.useEffect(()=>{if(m===null)return;const L=setTimeout(()=>{E.current=null,v(m),w(null)},cp);return()=>clearTimeout(L)},[m,v]);const N=L=>{const F=m!==null?Es(m,L):t?.value;w(null),o(b(L,fp(F,L)))},M=()=>{w(null),o(null)},S=!Vt.has(d),D=up(e),I=`ogx-filter__value-input${u?" ogx-filter__value-input--active":""}`,A=`Filter value for ${g}`;let C=null;if(S&&e.type==="boolean")C=c.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${I} ogx-filter__value-select`,value:t?.value==null?"":String(t.value),onChange:L=>{L.target.value===""?o(null):o(b(d,L.target.value))},"aria-label":A,children:[c.jsx("option",{value:"",children:"Any"}),c.jsx("option",{value:"true",children:"true"}),c.jsx("option",{value:"false",children:"false"})]});else if(S&&e.type==="singleSelect"&&D.length>0&&d==="isAnyOf"){const L=Array.isArray(t?.value)?t.value:t?.value==null||t.value===""?[]:[t.value];C=c.jsx("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${I} ogx-filter__value-multiselect`,multiple:!0,size:Math.min(D.length,4),value:D.filter(F=>L.some(_=>Ss(F,_))).map(F=>F.key),onChange:F=>{const _=new Set(Array.from(F.target.selectedOptions,z=>z.value));o(b("isAnyOf",D.filter(z=>_.has(z.key)).map(z=>z.value)))},"aria-label":A,children:D.map(F=>c.jsx("option",{value:F.key,children:F.label},F.key))})}else if(S&&e.type==="singleSelect"&&D.length>0&&(d==="is"||d==="not")){const L=D.find(F=>Ss(F,t?.value));C=c.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${I} ogx-filter__value-select`,value:L?.key??"",onChange:F=>{const _=D.find(z=>z.key===F.target.value);o(b(d,_?_.value:""))},"aria-label":A,children:[c.jsx("option",{value:"",children:"Any"}),D.map(F=>c.jsx("option",{value:F.key,children:F.label},F.key))]})}else S&&(C=c.jsx(Qe,{id:`${r}-val`,name:`filter-val-${e.field}`,inputClassName:I,type:e.type==="date"?"date":"text",value:m??ks(t?.value,e),onChange:L=>w(L.target.value),placeholder:e.type==="number"?"Number…":"Value…","aria-label":A}));return c.jsxs("div",{className:`ogx-filter__row${u?" ogx-filter__row--active":""}`,children:[c.jsx("span",{className:"ogx-filter__col-label",title:e.field,children:g}),c.jsxs("div",{className:"ogx-filter__controls",children:[c.jsx("select",{id:`${r}-op`,name:`filter-op-${e.field}`,className:`ogx-filter__op-select${u?" ogx-filter__op-select--active":""}`,value:d,onChange:L=>N(L.target.value),"aria-label":`Filter operator for ${g}`,children:a.map(L=>c.jsx("option",{value:L,children:L},L))}),C,u&&c.jsx("button",{type:"button",className:"ogx-filter__row-clear",onClick:M,"aria-label":`Clear filter for ${g}`,title:"Clear",children:"×"})]})]})},Ms=({filterModel:e,columns:t,onFilterModelChange:n})=>{const o=s.useMemo(()=>e.items??[],[e.items]),r=e.logicOperator??"and",[i,l]=s.useState(null),[d,a]=s.useState(o),[u,g]=s.useState(0);if(d!==o){a(o);const h=!Nr(d,o),x=i!==null&&Nr(i,o);h&&!x&&g(b=>b+1)}const m=s.useCallback((h,x)=>{const b=o.findIndex(E=>Zt(E)&&E.field===h);let v;if(b===-1){if(!x)return;v=[...o,x]}else x?v=o.map((E,k)=>k===b?x:E):v=o.filter((E,k)=>k!==b);l(v),n({...e,items:v})},[o,e,n]),w=s.useCallback(h=>{n({...e,logicOperator:h})},[e,n]),y=t.filter(h=>h.filterable!==!1),p=y.filter(h=>Cs(o,h.field)).length,f=o.length-p;return c.jsxs(c.Fragment,{children:[o.length>1&&c.jsxs("div",{className:"ogx-filter__logic-bar",children:[c.jsx("span",{className:"ogx-filter__logic-label",children:"Match:"}),c.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>w("and"),"aria-pressed":r==="and",children:"ALL (AND)"}),c.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>w("or"),"aria-pressed":r==="or",children:"ANY (OR)"})]}),f>0&&c.jsx("div",{className:"ogx-filter__hidden-note",role:"note",children:f===1?"1 more condition (a filter group or a second condition on a column) is applied and not shown here.":`${f} more conditions (filter groups or further conditions on a column) are applied and not shown here.`}),y.length===0?c.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):y.map(h=>c.jsx(gp,{col:h,item:Cs(o,h.field),resetToken:u,onChange:x=>m(h.field,x)},h.field))]})},Ns=["sum","avg","count","min","max"];function Is(){return c.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[c.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),c.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),c.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),c.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",fill:"currentColor",opacity:"0.25"}),c.jsx("path",{d:"M17 14v-4M17 10l-2 2 2 2"})]})}function pp({anchorRef:e,columns:t,model:n,onChange:o,onClose:r}){const i=s.useRef(null),[l,d]=s.useState({top:0,right:0}),[a,u]=s.useState(null);s.useLayoutEffect(()=>{u(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const g=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const _=e.current.getBoundingClientRect();return{top:_.bottom+6,right:Ot()-_.right}},[e]);s.useEffect(()=>{d(g());const _=()=>d(g());return window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_)}},[g]),s.useEffect(()=>{function _(K){i.current&&!i.current.contains(K.target)&&e.current&&!e.current.contains(K.target)&&r()}function z(K){K.key==="Escape"&&r()}return document.addEventListener("mousedown",_),document.addEventListener("keydown",z),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",z)}},[e,r]);const m=new Set(n.rowFields),w=new Set(n.columnFields),y=new Set(n.valueFields.map(_=>_.field)),p=_=>m.has(_)||w.has(_)||y.has(_),f=_=>t.find(z=>z.field===_),h=_=>f(_)?.headerName??_,x=_=>{const z=f(_)?.availableAggregationFunctions;return z?Ns.filter(K=>z.includes(K)):Ns},b=_=>_.aggregable!==!1&&(_.type==="number"||_.aggregable===!0)&&x(_.field).length>0,v=_=>_.groupable!==!1;function E(_){m.has(_)||o({...n,rowFields:[...n.rowFields,_]})}function k(_){w.has(_)||o({...n,columnFields:[...n.columnFields,_]})}function N(_){y.has(_)||o({...n,valueFields:[...n.valueFields,{field:_,aggFn:x(_)[0]??"sum"}]})}function M(_){o({...n,rowFields:n.rowFields.filter((z,K)=>K!==_)})}function S(_){o({...n,columnFields:n.columnFields.filter((z,K)=>K!==_)})}function D(_){o({...n,valueFields:n.valueFields.filter((z,K)=>K!==_)})}function I(_,z){o({...n,valueFields:n.valueFields.map((K,Q)=>Q===_?{...K,aggFn:z}:K)})}function A(){o({rowFields:[],columnFields:[],valueFields:[]})}const C=n.rowFields.length+n.columnFields.length+n.valueFields.length,L=t.filter(_=>!p(_.field)&&(v(_)||b(_))),F=c.jsxs("div",{ref:i,className:"ogx-pivot-panel",role:"dialog","aria-label":"Pivot configuration",style:{top:l.top,right:l.right},children:[c.jsxs("div",{className:"ogx-pivot-panel__header",children:[c.jsxs("span",{className:"ogx-pivot-panel__title",children:[c.jsx(Is,{}),"Pivot Mode"]}),C>0&&c.jsx("button",{type:"button",className:"ogx-pivot-panel__reset-btn",onClick:A,title:"Reset pivot",children:"Reset"})]}),c.jsxs("div",{className:"ogx-pivot-panel__body",children:[c.jsxs("div",{className:"ogx-pivot-zone",children:[c.jsxs("span",{className:"ogx-pivot-zone__label",children:[c.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--row"}),"Row Fields"]}),c.jsx("div",{className:`ogx-pivot-chips${n.rowFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — each becomes a row label",children:n.rowFields.map((_,z)=>c.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[h(_),c.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>M(z),title:`Remove ${h(_)}`,"aria-label":`Remove ${h(_)} from Row Fields`,children:"×"})]},`${z}:${_}`))})]}),c.jsxs("div",{className:"ogx-pivot-zone",children:[c.jsxs("span",{className:"ogx-pivot-zone__label",children:[c.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--col"}),"Column Fields"]}),c.jsx("div",{className:`ogx-pivot-chips${n.columnFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — unique values become column headers",children:n.columnFields.map((_,z)=>c.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[h(_),c.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>S(z),title:`Remove ${h(_)}`,"aria-label":`Remove ${h(_)} from Column Fields`,children:"×"})]},`${z}:${_}`))})]}),c.jsxs("div",{className:"ogx-pivot-zone",children:[c.jsxs("span",{className:"ogx-pivot-zone__label",children:[c.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--value"}),"Value Fields (aggregated)"]}),c.jsx("div",{className:`ogx-pivot-chips${n.valueFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add numeric fields here — values are aggregated",children:n.valueFields.map((_,z)=>{const K=x(_.field),Q=K.includes(_.aggFn)?K:[_.aggFn,...K];return c.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[h(_.field),c.jsx("select",{className:"ogx-pivot-chip__fn-select",value:_.aggFn,onChange:G=>I(z,G.target.value),title:"Aggregation function","aria-label":`Aggregation function for ${h(_.field)}`,children:Q.map(G=>c.jsx("option",{value:G,children:G.toUpperCase()},G))}),c.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>D(z),title:`Remove ${h(_.field)}`,"aria-label":`Remove ${h(_.field)} (${_.aggFn.toUpperCase()}) from Value Fields`,children:"×"})]},`${z}:${_.field}:${_.aggFn}`)})})]}),c.jsx("hr",{className:"ogx-pivot-panel__divider"}),c.jsxs("div",{children:[c.jsx("div",{className:"ogx-pivot-panel__fields-label",children:"Available Fields"}),c.jsxs("div",{className:"ogx-pivot-fields",children:[L.map(_=>{const z=b(_),K=v(_),Q=_.headerName??_.field;return c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[c.jsx("span",{className:`ogx-pivot-field-btn${z?" ogx-pivot-field-btn--numeric":""}`,children:Q}),c.jsxs("div",{className:"ogx-pivot-field-actions",children:[K&&c.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>E(_.field),title:"Add to Row Fields","aria-label":`Add ${Q} to Row Fields`,children:"Row"}),K&&c.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>k(_.field),title:"Add to Column Fields","aria-label":`Add ${Q} to Column Fields`,children:"Col"}),z&&c.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>N(_.field),title:"Add to Value Fields","aria-label":`Add ${Q} to Value Fields`,children:"Val"})]})]},_.field)}),L.length===0&&c.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return a?mt.createPortal(F,a):null}function hp(){return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function mp(){return c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Ls(e){return e.trim().split(/\s+/).filter(Boolean).join(" ")}function wp({value:e="",onChange:t,placeholder:n="Search...",debounceMs:o=250}){const[r,i]=s.useState(()=>e.length>0),[l,d]=s.useState(e),a=s.useRef(null),u=s.useRef(null),g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t},[t]);const m=s.useRef(e),w=s.useRef(e);s.useEffect(()=>{e!==w.current&&(w.current=e,Ls(e)!==Ls(m.current)&&(d(e),m.current=e,i(e.length>0)))},[e]),s.useEffect(()=>{const b=setTimeout(()=>{l!==m.current&&(m.current=l,g.current(l))},o);return()=>clearTimeout(b)},[l,o]);const y=s.useRef(l);s.useLayoutEffect(()=>{y.current=l}),s.useEffect(()=>()=>{const b=y.current;b!==m.current&&(m.current=b,g.current(b))},[]);const p=s.useCallback(()=>{i(!0),requestAnimationFrame(()=>a.current?.focus())},[]),f=s.useCallback(b=>{b.stopPropagation(),d(""),m.current="",g.current(""),a.current?.focus()},[]),h=s.useCallback(()=>{i(!0)},[]),x=s.useCallback(()=>{setTimeout(()=>{u.current&&document.activeElement&&u.current.contains(document.activeElement)||l||i(!1)},150)},[l]);return s.useEffect(()=>{const b=v=>{u.current&&!u.current.contains(v.target)&&(l||i(!1))};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[l]),c.jsxs("div",{ref:u,className:`ogx-global-search${r?" ogx-global-search--expanded":""}`,onClick:r?void 0:p,children:[c.jsx("div",{className:"ogx-global-search__icon-wrapper",children:c.jsx(hp,{})}),c.jsx(Qe,{ref:a,inputClassName:"ogx-global-search__input",value:l,onChange:b=>d(b.target.value),onFocus:h,onBlur:x,placeholder:n,"aria-label":"Global Search",autoComplete:"off"}),l&&c.jsx("button",{type:"button",className:"ogx-global-search__clear",onClick:f,"aria-label":"Clear search",children:c.jsx(mp,{})})]})}const oo=8;function Sn({title:e,children:t,placement:n="top",enterDelay:o=200,leaveDelay:r=0}){const[i,l]=s.useState(!1),[d,a]=s.useState({top:0,left:0}),[u,g]=s.useState(null),m=s.useRef(null),w=s.useRef(null),y=s.useId(),p=s.useCallback(()=>{if(!w.current)return;const k=w.current.getBoundingClientRect(),N=k.left+k.width/2,M=k.top+k.height/2;switch(n){case"bottom":a({top:k.bottom+oo,left:N});break;case"left":a({top:M,left:k.left-oo});break;case"right":a({top:M,left:k.right+oo});break;default:a({top:k.top-oo,left:N})}},[n]),f=s.useCallback(()=>{m.current&&clearTimeout(m.current),m.current=null},[]);s.useLayoutEffect(()=>{if(!i)return;p();const k=N=>{N.key==="Escape"&&(f(),l(!1))};return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),document.addEventListener("keydown",k),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p),document.removeEventListener("keydown",k)}},[i,p,f]),s.useEffect(()=>f,[f]);const h=()=>{f(),m.current=setTimeout(()=>{g(w.current?.closest(".ogx-theme-provider")??document.body),l(!0)},o)},x=()=>{f(),m.current=setTimeout(()=>{l(!1)},r)},b=s.useCallback(k=>{w.current=k?k.firstElementChild??k:null},[]),v=i&&!!e&&u!==null;let E=t;if(v&&s.isValidElement(t)){const k=t,N=k.props["aria-describedby"];E=s.cloneElement(k,{"aria-describedby":N?`${N} ${y}`:y})}return c.jsxs(c.Fragment,{children:[c.jsx("span",{ref:b,style:{display:"inline-block",lineHeight:0},onMouseEnter:h,onMouseLeave:x,onFocus:h,onBlur:x,children:E}),v&&u&&mt.createPortal(c.jsx("div",{id:y,role:"tooltip",className:`ogx-tooltip ogx-tooltip--${n}`,style:{top:d.top,left:d.left,position:"fixed",zIndex:99999},children:e}),u)]})}const bp=Object.keys(Lt);function xp(e){return Object.prototype.hasOwnProperty.call(Lt,e)}function As(e){return e.availableAggregationFunctions?Array.from(new Set(e.availableAggregationFunctions.filter(xp))):bp}function Ps(){return c.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:c.jsx("path",{d:"M18 4H6l6 8-6 8h12"})})}function yp(){return c.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.25"}),c.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),c.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Ts(){return c.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function vp({anchorRef:e,aggregationModel:t,aggregableColumns:n,onFunctionChange:o,onClearAll:r,onClose:i,activeCount:l}){const d=s.useRef(null),[a,u]=s.useState({top:0,right:0}),[g,m]=s.useState(null);s.useLayoutEffect(()=>{m(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const w=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const p=e.current.getBoundingClientRect();return{top:p.bottom+6,right:Ot()-p.right}},[e]);s.useEffect(()=>{u(w());const p=()=>u(w());return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[w]),s.useEffect(()=>{function p(f){d.current&&!d.current.contains(f.target)&&e.current&&!e.current.contains(f.target)&&i()}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[e,i]),s.useEffect(()=>{function p(f){f.key==="Escape"&&i()}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[i]);const y=c.jsxs("div",{ref:d,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:a.top,right:a.right,width:400,maxWidth:"calc(100vw - 24px)"},children:[c.jsxs("div",{className:"ogx-toolbar__panel-header",children:[c.jsxs("span",{className:"ogx-toolbar__panel-title",children:[c.jsx(Ps,{}),"Summaries"]}),l>0&&c.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:r,title:"Clear all summaries",children:"Clear all"})]}),c.jsx("div",{className:"ogx-toolbar__panel-body",children:n.length===0?c.jsxs("p",{className:"ogx-toolbar__empty",children:["No aggregable columns.",c.jsx("br",{}),"Set ",c.jsx("code",{children:"aggregable: true"})," on a column to enable."]}):n.map(p=>{const f=t[p.field]||"none";return c.jsxs("div",{className:"ogx-toolbar__agg-row",children:[c.jsx("span",{className:"ogx-toolbar__agg-label",title:p.field,children:p.headerName||p.field}),c.jsx("div",{className:"ogx-toolbar__agg-pills",children:["none",...As(p)].map(h=>c.jsx("button",{type:"button",className:`ogx-toolbar__pill${f===h?" ogx-toolbar__pill--active":""}`,onClick:()=>o(p.field,h),"aria-pressed":f===h,children:h},h))})]},p.field)})})]});return g?mt.createPortal(y,g):null}function Cp({anchorRef:e,columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:d,onClose:a,showNonHideableColumns:u}){const g=s.useRef(null),[m,w]=s.useState({top:0,right:0}),[y,p]=s.useState(null);s.useLayoutEffect(()=>{p(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const f=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const x=e.current.getBoundingClientRect();return{top:x.bottom+6,right:Ot()-x.right}},[e]);s.useEffect(()=>{w(f());const x=()=>w(f());return window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[f]),s.useEffect(()=>{function x(b){g.current&&!g.current.contains(b.target)&&e.current&&!e.current.contains(b.target)&&a()}return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[e,a]),s.useEffect(()=>{function x(b){b.key==="Escape"&&a()}return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[a]);const h=c.jsx("div",{ref:g,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:m.top,right:m.right,width:280,padding:0},children:c.jsx(yr,{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:d,showNonHideableColumns:u})});return y?mt.createPortal(h,y):null}function _p({anchorRef:e,columns:t,filterModel:n,onFilterModelChange:o,onClose:r}){const i=s.useRef(null),[l,d]=s.useState({top:0,right:0}),a=s.useRef(r);s.useLayoutEffect(()=>{a.current=r},[r]);const[u,g]=s.useState(null);s.useLayoutEffect(()=>{g(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const m=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const f=e.current.getBoundingClientRect();return{top:f.bottom+6,right:Ot()-f.right}},[e]);s.useEffect(()=>{d(m());const f=()=>d(m());return window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[m]),s.useEffect(()=>{function f(h){h.key==="Escape"&&a.current()}return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[]);const w=n.items?.length??0,y=()=>{o({...n,items:[],logicOperator:"and"})},p=c.jsxs("div",{ref:i,className:"ogx-toolbar__panel ogx-toolbar__panel--filter",role:"dialog","aria-label":"Advanced filters",style:{top:l.top,right:l.right,width:540,maxWidth:"calc(100vw - 24px)"},children:[c.jsxs("div",{className:"ogx-toolbar__panel-header",children:[c.jsxs("span",{className:"ogx-toolbar__panel-title",children:[c.jsx(Ts,{}),"Filters",w>0&&c.jsx("span",{className:"ogx-toolbar__panel-count",children:w})]}),c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[w>0&&c.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:y,title:"Clear all filters",children:"Clear all"}),c.jsx("button",{type:"button",className:"ogx-toolbar__close-btn",onClick:()=>a.current(),title:"Close filters","aria-label":"Close filters panel",children:"Close"})]})]}),c.jsx("div",{className:"ogx-toolbar__panel-body ogx-toolbar__panel-body--filter",children:c.jsx(Ms,{columns:t,filterModel:n,onFilterModelChange:o})})]});return u?mt.createPortal(p,u):null}const Sp={rowFields:[],columnFields:[],valueFields:[]},kp=[];function Ep({columns:e=kp,baseColumns:t,aggregationModel:n={},onAggregationModelChange:o,pivotModel:r,onPivotModelChange:i,filterModel:l,onFilterModelChange:d,columnVisibilityModel:a={},onColumnVisibilityModelChange:u,onColumnReorder:g,onColumnOrderReset:m,forceColumnsOpen:w,onColumnsPanelClose:y,forceFiltersOpen:p,onFiltersPanelClose:f,children:h,rightContent:x,style:b,renderColumnsButton:v,renderFilterButton:E,renderAggregationButton:k,renderExportButton:N,renderQuickFilter:M,className:S,showNonHideableColumns:D,onAiAssistantToggle:I,aiAssistantOpen:A=!1,aiAssistantLabel:C="Ask AI"}){const[L,F]=s.useState(w?"columns":null),_=L==="summaries",z=L==="pivot",K=L==="columns",Q=L==="filters",G=he=>{L==="columns"&&he!=="columns"&&y?.(),L==="filters"&&he!=="filters"&&f?.(),F(he)},j=he=>G(L===he?null:he),H=he=>{L===he&&G(null)},[ie,re]=s.useState(w);ie!==w&&(re(w),w&&F("columns"));const[ue,ae]=s.useState(p);ue!==p&&(ae(p),p&&d&&F("filters"));const R=s.useContext(ol),te=w!==void 0&&!!u;s.useEffect(()=>{if(!(!R||!te))return R.registerColumnsPanel()},[R,te]);const ce=p!==void 0&&!!d;s.useEffect(()=>{if(!(!R||!ce))return R.registerFiltersPanel()},[R,ce]);const W=s.useRef(null),le=s.useRef(null),V=s.useRef(null),J=s.useRef(null),ne=s.useRef(null),fe=s.useRef(null),Z=s.useRef(null),$=s.useRef(null),O=r??Sp,P=O.rowFields.length>0||O.columnFields.length>0||O.valueFields.length>0,T=t?new Set(t.map(he=>he.field)):null,X=e.filter(he=>he.aggregable!==!1&&(he.type==="number"||he.aggregable===!0)&&As(he).length>0&&(!T||T.has(he.field))),B=Object.keys(n).filter(he=>n[he]&&n[he]!=="none").length,ee=s.useCallback((he,ve)=>{if(!o)return;const be={...n};ve==="none"?delete be[he]:be[he]=ve,o(be)},[n,o]),q=s.useCallback(()=>{o?.({})},[o]),Y=s.useCallback(he=>{if(!d)return;const ve=he.trim().split(/\s+/).filter(Boolean),be={...l||{},quickFilterValues:ve,items:l?.items||[]};d(be)},[l,d]),oe=(l?.quickFilterValues??[]).join(" "),me=l?.items?.length||0,U=new Set(e.filter(he=>a[he.field]!==!1).map(he=>he.field)),se=s.useCallback((he,ve)=>{if(!u)return;const be={...a,[he]:ve};u(be)},[a,u]),we=s.useCallback(()=>{if(!u)return;const he={...a};e.forEach(ve=>{ve.hideable!==!1&&(he[ve.field]=!0)}),u(he)},[e,a,u]),pe=s.useCallback(()=>{if(!u)return;const he={...a};e.forEach(ve=>{ve.hideable!==!1&&(he[ve.field]=!1)}),u(he)},[e,a,u]);return c.jsxs("div",{className:["ogx-toolbar",S].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:b,children:[h&&c.jsx("div",{className:"ogx-toolbar__left",children:h}),c.jsx("div",{className:"ogx-toolbar__spacer"}),c.jsxs("div",{className:"ogx-toolbar__actions",children:[I&&c.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:c.jsxs("button",{type:"button",ref:le,className:`ogx-toolbar__icon-btn ogx-toolbar__ai-btn${A?" ogx-toolbar__icon-btn--active":""}`,"aria-haspopup":"dialog","aria-expanded":A,onClick:()=>{G(null),I(le.current)},children:[c.jsx(vs,{}),C]})}),d&&c.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:M?M({value:oe,onChange:Y}):c.jsx(wp,{value:oe,onChange:Y,placeholder:"Search..."})}),u&&c.jsxs("div",{ref:fe,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[v?v({onClick:()=>j("columns"),isOpen:K,activeCount:e.length-U.size}):c.jsx(Sn,{title:"Columns",children:c.jsx("button",{type:"button",ref:J,className:`ogx-toolbar__icon-btn${K?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns","aria-haspopup":"dialog","aria-expanded":K,onClick:()=>j("columns"),children:c.jsx(yp,{})})}),K&&c.jsx(Cp,{anchorRef:v?fe:J,columns:e,visibleColumns:U,onVisibilityChange:se,onShowAll:we,onHideAll:pe,onColumnReorder:g,onColumnOrderReset:m,onClose:()=>H("columns"),showNonHideableColumns:D})]}),d&&c.jsxs("div",{ref:Z,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[E?E({onClick:()=>j("filters"),isOpen:Q,activeCount:me}):c.jsx(Sn,{title:"Filters",children:c.jsxs("button",{type:"button",ref:ne,className:`ogx-toolbar__icon-btn${Q?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters","aria-haspopup":"dialog","aria-expanded":Q,onClick:()=>j("filters"),children:[c.jsx(Ts,{}),me>0&&c.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),Q&&c.jsx(_p,{anchorRef:E?Z:ne,columns:e,filterModel:l||{items:[]},onFilterModelChange:d,onClose:()=>H("filters")})]}),i&&c.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[c.jsx(Sn,{title:"Pivot",children:c.jsxs("button",{type:"button",ref:V,className:`ogx-toolbar__icon-btn${z?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-haspopup":"dialog","aria-expanded":z,onClick:()=>j("pivot"),children:[c.jsx(Is,{}),P&&c.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),z&&c.jsx(pp,{anchorRef:V,columns:t??e,model:O,onChange:he=>{i?.(he)},onClose:()=>H("pivot")})]}),o&&c.jsxs("div",{ref:$,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[k?k({onClick:()=>j("summaries"),isOpen:_,activeCount:B}):c.jsx(Sn,{title:"Summaries",children:c.jsxs("button",{type:"button",ref:W,className:`ogx-toolbar__icon-btn${_?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-haspopup":"dialog","aria-expanded":_,onClick:()=>j("summaries"),children:[c.jsx(Ps,{}),B>0&&c.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${B} active summaries`})]})}),_&&c.jsx(vp,{anchorRef:k?$:W,aggregationModel:n,aggregableColumns:X,onFunctionChange:ee,onClearAll:q,onClose:()=>H("summaries"),activeCount:B})]}),N&&N(),x]})]})}function Mp(){const[e]=s.useState(Sl);return s.useRef(e)}function Qt(e,t){if(e.groupLabel!==void 0)return e.groupLabel;const n=e.groupField??"",o=t.find(r=>r.field===n)?.groupingValueFormatter;return o?o({field:n,value:e.groupValue}):`${n}: ${String(e.groupValue??"")}`}const Np=new Set([8364,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,381,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,382,376]);function Ip(e){return e>=8192&&e<=8202||e===8239||e===8287||e===12288?" ":e>=8203&&e<=8205||e===8288||e===65279?"":e===8208||e===8209||e===8210||e===8722?"-":null}function Lp(e){let t="",n=!1;for(const o of e){const r=o.codePointAt(0)??0;if(r<=255||Np.has(r)){t+=o;continue}const i=Ip(r);i!==null?t+=i:(t+="?",n=!0)}return{text:t,lossy:n}}const Ap={sliceMs:30,renderChunkRows:40},Pp=2e4;function Fs(){return new Promise(e=>setTimeout(e,0))}function Tp(){return new DOMException("PDF export was aborted","AbortError")}const en=()=>typeof performance<"u"?performance.now():Date.now(),Os=e=>Math.max(2,Math.floor(e/2)*2),Fp=[79,70,229],Op=[255,255,255];function Ds(e,t){const n=e.trim().replace(/^#/,""),o=/^[a-f\d]{3}$/i.test(n)?n.split("").map(i=>i+i).join(""):n,r=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);return r?[parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16)]:t}function $s(e,t){return _n(e,t,Cn(e,t))}function Gs(e){return(typeof e.width=="number"?e.width:void 0)??(e.flex??1)*100}function Dp(e,t){const n=e.reduce((r,i)=>r+Gs(i),0),o={};return e.forEach((r,i)=>{o[i]={cellWidth:Gs(r)/n*t}}),o}const $p=new Set(["isEmpty","isNotEmpty"]);function Gp(e,t){const o=t.find(l=>l.field===e.field)?.headerName??e.field;if($p.has(e.operator))return`${o} ${e.operator}`;const{value:r}=e;if(r==null||r===""||Array.isArray(r)&&r.length===0)return null;const i=Array.isArray(r)?r.map(String).join(", "):String(r);return`${o} ${e.operator} "${i}"`}function Hs(e,t,n,o){const r=e.map(l=>"items"in l?Hs(l.items,l.logicOperator,n,!0):Gp(l,n)).filter(l=>!!l);if(r.length===0)return"";const i=r.join(t==="or"?" OR ":" AND ");return o&&r.length>1?`(${i})`:i}function Hp(e,t){const n=[],o=Hs(e.items??[],e.logicOperator??"and",t,!1);o&&n.push(o);const r=(e.quickFilterValues??[]).filter(i=>i.trim()!=="");return r.length>0&&n.push(`Search: ${r.map(i=>`"${i}"`).join(" ")}`),n.join(" • ")}const Bp=1.15*.3528;function Wp(e,t,n={}){return Vp(e,t,n,Ap)}async function Vp(e,t,n,o){const{signal:r,onProgress:i}=n,l=()=>{if(r?.aborted)throw Tp()};l();let d,a;try{const[q,Y]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);d=q.default,a=Y.default}catch{throw new Error("exportToPdf requires 'jspdf' and 'jspdf-autotable'. Run: npm install jspdf jspdf-autotable")}const{fileName:u="export",title:g,logoUrl:m,orientation:w="landscape",selectedRows:y,getRowId:p,aggregationResult:f,aggregationModel:h,filterModel:x,alternateRowColor:b=!0,headerBackgroundColor:v="#4f46e5",headerTextColor:E="#ffffff",fontSize:k=9,groupedRows:N,font:M,maxRows:S=Pp}=n;l();let D=en();const I=async()=>{en()-D<o.sliceMs||(await Fs(),l(),D=en())},A=(q,Y,oe)=>{i?.({phase:q,done:Y,total:oe})},C=new d({orientation:w,unit:"mm",format:"a4"}),L=C.internal.pageSize.getWidth(),F=C.internal.pageSize.getHeight(),_=14,z=L-_*2;let K="helvetica";M&&(C.addFileToVFS(`${M.name}-normal.ttf`,M.data),C.addFont(`${M.name}-normal.ttf`,M.name,"normal"),M.boldData&&C.addFileToVFS(`${M.name}-bold.ttf`,M.boldData),C.addFont(M.boldData?`${M.name}-bold.ttf`:`${M.name}-normal.ttf`,M.name,"bold"),K=M.name);let Q=!1;const G=q=>{if(M)return q;const Y=Lp(q);return Y.lossy&&(Q=!0),Y.text},j=(q,Y,oe,me,U)=>{const se=C.splitTextToSize(G(q),me);return C.text(se.length===1?se[0]:se,Y,oe),Math.max(0,se.length-1)*U*Bp},H=Dt(t),ie=vn(N,y),re=yn(e,y,p);let ue=_;if(g){let q=_,Y=_+8;if(m)try{C.addImage(m,"PNG",q,_,10,10),q+=14}catch{}const oe=L-_-q;C.setFontSize(16),C.setFont(K,"bold"),C.setTextColor(30,41,59),Y+=j(g,q,Y,oe,16),Y+=6,C.setFontSize(8),C.setFont(K,"normal"),C.setTextColor(100,116,139);const me=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),U=ie?N.filter(se=>se.type==="leaf").length:re.length;if(C.text(G(`Exported: ${me} • ${U} row${U!==1?"s":""}`),q,Y),Y+=5,x){const se=Hp(x,t);se&&(Y+=j(`Filters: ${se}`,q,Y,oe,8),Y+=5)}C.setDrawColor(226,232,240),C.setLineWidth(.3),C.line(_,Y+2,L-_,Y+2),ue=Y+6}const ae=[H.map(q=>G(q.headerName??q.field))],R=h||{},te=q=>H.map(Y=>vr(Y,R[Y.field],q[Y.field],q)),ce=[];let W;const le=q=>{ce.push(q.map(G))};if(ie){const q=N.length;A("prepare",0,q);for(let Y=0;Y<q;Y++){const oe=N[Y],me=" ".repeat(oe.depth*2);if(oe.type==="group-header"){const U=`${me}${Qt(oe,t)}`;le(H.map((se,we)=>we===0?U:""))}else if(oe.type==="leaf"&&oe.row){const U=oe.row;le(H.map((se,we)=>(we===0?me:"")+$s(U,se)))}else if(oe.type==="group-subtotal"&&oe.aggregatedValues){const U=te(oe.aggregatedValues);le(U.map((se,we)=>we===0?`${me}${Jt("Subtotal",se)}`:se))}else oe.type==="grand-total"&&oe.aggregatedValues&&(W=[te(oe.aggregatedValues).map((se,we)=>we===0?Jt("Grand Total",se):se).map(G)]);(Y&63)===63&&(A("prepare",Y+1,q),await I())}A("prepare",q,q)}else{const q=re.length;A("prepare",0,q);for(let oe=0;oe<q;oe++)le(H.map(me=>$s(re[oe],me))),(oe&63)===63&&(A("prepare",oe+1,q),await I());const Y=h?Yt(re,yt(y),t,f,h):null;if(Y&&h){const oe=H.some(U=>h[U.field]);W=[te(Y).map((U,se)=>se===0&&oe?Jt("TOTAL",U):U).map(G)]}A("prepare",q,q)}l(),ce.length>S&&process.env.NODE_ENV!=="production"&&console.warn(`[exportToPdf] Exporting ${ce.length} table rows (maxRows: ${S}). PDFs this large are slow to build and open and can reach tens of MB. Prefer exportToCsv or exportToExcelAdvanced for full-dataset exports, or pass a larger \`maxRows\` to silence this warning.`),Q&&console.warn('[exportToPdf] Some characters cannot be drawn with the built-in Helvetica font and were replaced with "?". Pass the `font` option (a Unicode .ttf, e.g. Noto Sans) to draw them.');const V=Dp(H,z),[J,ne,fe]=Ds(v,Fp),[Z,$,O]=Ds(E,Op),P={head:ae,styles:{fontSize:k,cellPadding:3,font:K,overflow:"linebreak"},headStyles:{fillColor:[J,ne,fe],textColor:[Z,$,O],fontStyle:"bold"},...b?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...W?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:V,showHead:"everyPage",margin:{top:_,left:_,right:_,bottom:_+6}},T=ce.length;A("render",0,T);let X=0,B=Os(o.renderChunkRows);do{const q=ce.slice(X,X+B),Y=X===0,oe=X+q.length>=T,me=Y?ue:C.lastAutoTable.finalY;let U=!0;const se=en();a(C,{...P,body:q,...oe&&W?{foot:W}:{},startY:Y?ue:_,showFoot:oe&&W?"lastPage":"never",...Y?{}:{willDrawPage:pe=>{U?(U=!1,pe.settings.showHead="never",pe.cursor&&(pe.cursor.y=me)):pe.settings.showHead="everyPage"}}}),X+=q.length,A("render",X,T);const we=en()-se;B=Os(we>0?Math.min(B*4,B*(o.sliceMs/we)):B*4),oe||(await Fs(),l(),D=en())}while(X<T);const ee=C.getNumberOfPages();for(let q=1;q<=ee;q++)C.setPage(q),C.setFontSize(8),C.setTextColor(150,150,150),C.text(`Page ${q} of ${ee}`,L-_,F-8,{align:"right"}),await I();l(),A("save",0,1),C.save(`${u}.pdf`),A("save",1,1)}function kn(e,t){const n=Cn(e,t);return{text:_n(e,t,n),raw:n}}function tn(e,t,n){return e.map(o=>vr(o,n[o.field],t[o.field],t))}const zp="\uFEFF";function Kp(e,t,n={}){const{fileName:o="export.csv",includeHeaders:r=!0,delimiter:i=",",selectedRows:l,groupedRows:d,escapeFormulas:a=!0,bom:u=!0}=n,g=Dt(t),m=n.aggregationModel||{},w=(f,h=!1)=>ro(a?Qn(f,h):f,i),y=()=>g.map(f=>w(f.headerName||f.field)).join(i)+`
|
|
8
|
-
`;let p="";if(
|
|
9
|
-
`}else if(f.type==="leaf"&&f.row){const x=f.row,b=g.map((
|
|
10
|
-
`}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const x=f.aggregatedValues,b=f.type==="grand-total"?"Grand Total":`${
|
|
11
|
-
`}});else{const f=yn(e,l,n.getRowId);if(f.length===0){console.warn("No rows to export");return}r&&(p+=y()),f.forEach(x=>{const b=g.map(
|
|
12
|
-
`});const
|
|
13
|
-
`;const b=tn(g,h
|
|
14
|
-
`}}
|
|
15
|
-
`)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}const io="ogx-xls-text";function
|
|
5
|
+
`?2:1):(o+=d,r+=1)}return(!l||n.length>0||o!=="")&&(n.push(o),t.push(n)),t}const Eu=/^\d+(?:\.\d*)?(?:e[+-]?\d+)?$/i,Mu=/^\.\d+(?:e[+-]?\d+)?$/i,Nu=/^\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,Iu=/[\p{Sc}\s]/gu;function Lu(e){let t=e.replace(Iu,"");if(t==="")return e.trim()===""?$e(null):dt;let n=!1;t.startsWith("(")&&t.endsWith(")")&&(n=!0,t=t.slice(1,-1)),(t.startsWith("-")||t.startsWith("+")||t.startsWith("−"))&&(t[0]!=="+"&&(n=!n),t=t.slice(1));let o=!1;if(t.endsWith("%")&&(o=!0,t=t.slice(0,-1)),Nu.test(t))t=t.split(",").join("");else if(!Eu.test(t)&&!Mu.test(t))return dt;let r=Number(t);return Number.isFinite(r)?(o&&(r/=100),n&&(r=-r),$e(r)):dt}const Au=/^(\d{4}-\d{2}-\d{2})/,Wl=e=>String(e).padStart(2,"0"),Pu=e=>`${e.getFullYear()}-${Wl(e.getMonth()+1)}-${Wl(e.getDate())}`;function Tu(e,t){const n=e.trim();if(n==="")return $e(null);const o=gn(n);if(!o)return dt;if(typeof t=="number")return $e(o.getTime());if(typeof t=="string"){const r=Pu(o);return $e(Au.test(t)&&t.length>10?r+t.slice(10):r)}return $e(o)}const Fu=new Set(["true","yes","1"]),Ou=new Set(["false","no","0"]);function Du(e,t){const n=e.trim().toLowerCase();return n===""?$e(null):t?.trueLabel!==void 0&&n===t.trueLabel.trim().toLowerCase()?$e(!0):t?.falseLabel!==void 0&&n===t.falseLabel.trim().toLowerCase()?$e(!1):Fu.has(n)?$e(!0):Ou.has(n)?$e(!1):dt}function $u(e,t){const n=e.trim();if(n==="")return $e(null);if(!t||t.length===0)return dt;const o=n.toLowerCase();for(const r of t){const i=typeof r=="object"?r.value:r;if(String(i).toLowerCase()===o)return $e(i)}for(const r of t)if(typeof r=="object"&&r.label.toLowerCase()===o)return $e(r.value);return dt}function Gu(e,t,n){switch(t?.type){case"number":return Lu(e);case"date":return Tu(e,n?.current);case"boolean":return Du(e,n?.booleanLabels);case"singleSelect":return $u(e,t.valueOptions);default:return $e(e)}}function Hu(e,t,n,o){const{valueParser:r}=t;if(!r)return Gu(e,t,o);let i;try{i=r(e,{row:n,field:t.field,colDef:t})}catch{return dt}return i===void 0?dt:$e(i)}function fr(e,t,n){const o=e.map(t),r=new Map;o.forEach((a,u)=>{r.has(a)||r.set(a,u)});const i=n.filter(a=>Ye(a.field)),l=new Map;i.forEach((a,u)=>{l.set(a.field,u)});const d=n.filter(a=>Ze(a.field)).length;return{rows:e,rowIds:o,rowIndexById:r,columns:i,colIndexByField:l,dataColumnOffset:d}}function gr(e,t,n,o,r){const i=e.rowIds[o],l=e.columns[r];if(!l||Xe(i,t.rowMetaMap))return!1;const d=t.getSpanOrigin?.(i,l.field);return d&&(d.rowId!==i||d.field!==l.field)?!1:Fo({row:n,field:l.field,value:Le(n,l.field,l),colDef:l,rowIndex:o,colIndex:e.dataColumnOffset+r,rowMeta:t.rowMetaMap?.get(i)},t.isCellEditable)}function Bu(e,t){let n=1/0,o=-1/0,r=1/0,i=-1/0;for(const l of t){const d=e.rowIndexById.get(l.id),a=e.colIndexByField.get(l.field);d===void 0||a===void 0||(d<n&&(n=d),d>o&&(o=d),a<r&&(r=a),a>i&&(i=a))}return n===1/0?null:{top:n,bottom:o,left:r,right:i}}function Vl(e,t){return{anchor:{id:e.rowIds[t.top],field:e.columns[t.left].field},head:{id:e.rowIds[t.bottom],field:e.columns[t.right].field}}}function Wu(e){const t=e?.type;return t===void 0||t==="string"||t==="image"}const zl=1e4,Jn=()=>({updated:[],failed:[],skipped:[]});function Vu(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Pasting ${e} cells. Pastes above ${zl} cells can be slow; consider importing the data instead.`)}function zu(e){const{apiRef:t,containerRef:n,selection:o,disableClipboardPaste:r,disableRangeClear:i}=e,l=s.useRef(e);s.useLayoutEffect(()=>{l.current=e});const d=s.useCallback(()=>{const{allRenderableRows:p,getRowId:f,navigationColumns:m}=l.current;return fr(p,f,m)},[]),a=s.useCallback(()=>{const{selection:p}=l.current;return p.enabled?p.getCurrentRange().resolved:null},[]),u=s.useCallback(p=>{const f=a();if(f&&p.rowIds[f.top]!==void 0&&p.columns[f.left])return{id:p.rowIds[f.top],field:p.columns[f.left].field};const m=l.current.focusedCell;return m&&m.id!==null&&Ye(m.field)?{id:m.id,field:m.field}:null},[a]),g=s.useCallback(async(p,f,m)=>{const x=d(),b=f??u(x);let C=p;const{onBeforeClipboardPaste:E}=l.current;if(E){const se=We(()=>E({text:C,anchor:b}));if(!se.ok)return Wt("onBeforeClipboardPaste","onBeforeClipboardPaste threw; the paste was cancelled",se.error),Jn();if(se.value===!1)return Jn();typeof se.value=="string"&&(C=se.value)}if(!b)return Jn();const k=ku(C),N=x.rowIndexById.get(b.id),M=x.colIndexByField.get(b.field);if(k.length===0||N===void 0||M===void 0)return Jn();const S=x.rowIds.length-1,F=x.columns.length-1,I=f?null:a(),A=I&&Tt(I)>1?I:null,_=k.length===1&&k[0].length===1,L=k.reduce((se,U)=>Math.max(se,U.length),0);let D;_&&A?D=A:D={top:N,left:M,bottom:Math.min(N+k.length-1,S,A?A.bottom:S),right:Math.min(M+L-1,F,A?A.right:F)};const v=Tt(D);v>zl&&Vu(v);const{batchEdit:V,isCellEditable:R,rowMetaMap:Q,getSpanOrigin:G}=l.current,W={isCellEditable:R,rowMetaMap:Q,getSpanOrigin:G},H=[],ie=[];for(let se=D.top;se<=D.bottom;se++){const U=x.rowIds[se],te=V.getRow(U)??x.rows[se],ce=_?k[0]:k[se-D.top];for(let z=D.left;z<=D.right;z++){const re=_?k[0][0]:ce?.[z-D.left];if(re===void 0)continue;const K=x.columns[z];if(!gr(x,W,te,se,z)){ie.push({id:U,field:K.field,reason:"notEditable"});continue}const J=Hu(re,K,te,{current:Le(te,K.field,K)});if(!J.ok){ie.push({id:U,field:K.field,reason:"invalidValue"});continue}H.push({id:U,field:K.field,value:J.value})}}if(l.current.selection.enabled){const{anchor:se,head:U}=Vl(x,D);l.current.selection.setModel([{anchor:se,head:U}],m?"keyboard":"api")}const oe=await V.applyEdits(H,"paste"),ue={updated:oe.result.updated,failed:oe.result.failed,skipped:[...ie,...oe.result.skipped]};return l.current.onClipboardPaste?.({...ue,text:C}),ue},[d,u,a]),h=s.useCallback(()=>{const p=a();if(!p||Tt(p)<=1)return!1;const f=d(),{batchEdit:m,isCellEditable:x,rowMetaMap:b,getSpanOrigin:C}=l.current,E={isCellEditable:x,rowMetaMap:b,getSpanOrigin:C},k=[];for(let N=p.top;N<=p.bottom;N++){const M=f.rowIds[N];if(M===void 0)continue;const S=m.getRow(M)??f.rows[N];for(let F=p.left;F<=p.right;F++){const I=f.columns[F];!I||!gr(f,E,S,N,F)||k.push({id:M,field:I.field,value:Wu(I)?"":null})}}return m.applyEdits(k,"clear"),!0},[a,d]),w=o.enabled&&!r,y=o.enabled&&!i;s.useEffect(()=>{const p=n.current;if(!p||!w&&!y)return;const f=N=>{const M=l.current.viewportRef.current;if(!M||N.defaultPrevented||l.current.isEditing)return!1;const S=Vn(N.target,M);return S==="grid"||S==="control"};let m=null;const x=()=>{if(!m)return;const{textarea:N,restore:M,timer:S}=m;m=null,window.clearTimeout(S);const F=document.activeElement===N;N.remove(),F&&M&&M.isConnected&&M.focus({preventScroll:!0})},b=()=>{x();const N=document.createElement("textarea");N.setAttribute("aria-hidden","true"),N.tabIndex=-1,N.className="ogx__paste-capture",N.style.cssText="position:fixed;top:0;left:-10000px;width:1px;height:1px;opacity:0;",p.appendChild(N);const M=document.activeElement instanceof HTMLElement?document.activeElement:null;m={textarea:N,restore:M,timer:window.setTimeout(x,250)},N.focus({preventScroll:!0})},C=N=>m!==null&&N.target===m.textarea,E=N=>{if(C(N)){const S=N.clipboardData?N.clipboardData.getData("text/plain"):"";N.preventDefault(),x(),S!==""&&g(S,void 0,!0);return}if(!w||!f(N)||!l.current.navigationColumns.some(S=>S.editable))return;const M=N.clipboardData?N.clipboardData.getData("text/plain"):"";M!==""&&(N.preventDefault(),g(M,void 0,!0))},k=N=>{if((N.ctrlKey||N.metaKey)&&!N.altKey&&!N.shiftKey&&(N.key==="v"||N.key==="V"||N.code==="KeyV")){w&&f(N)&&l.current.navigationColumns.some(M=>M.editable)&&b();return}!y||N.key!=="Delete"&&N.key!=="Backspace"||N.ctrlKey||N.metaKey||N.altKey||N.shiftKey||f(N)&&h()&&N.preventDefault()};return p.addEventListener("paste",E),p.addEventListener("keydown",k),()=>{x(),p.removeEventListener("paste",E),p.removeEventListener("keydown",k)}},[n,w,y,g,h]),s.useLayoutEffect(()=>{t.current.pasteText=(p,f)=>g(p,f,!1)},[t,g])}const Ku=100;function ju(){const e=s.useRef(null),t=s.useCallback((o,r)=>{const i=e.current;i&&i(o,r)},[]),n=s.useCallback(o=>{e.current=o},[]);return s.useMemo(()=>({emit:t,setListener:n}),[t,n])}const Kl=()=>({updated:[],failed:[],skipped:[]});function Uu(e){if(e.altKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t),o=t==="z"||!n&&e.code==="KeyZ",r=t==="y"||!n&&e.code==="KeyY";return o?e.shiftKey?"redo":"undo":r&&e.ctrlKey&&!e.shiftKey?"redo":null}function Ru(e){const{apiRef:t,enabled:n,channel:o,containerRef:r}=e,i=s.useRef(e);s.useLayoutEffect(()=>{i.current=e});const l=s.useRef([]),d=s.useRef([]),a=s.useRef({canUndo:!1,canRedo:!1,size:0}),u=s.useRef(Promise.resolve()),g=s.useCallback(()=>{const x={canUndo:l.current.length>0,canRedo:d.current.length>0,size:l.current.length},b=a.current;b.canUndo===x.canUndo&&b.canRedo===x.canRedo&&b.size===x.size||(a.current=x,i.current.onHistoryChange?.(x))},[]),h=s.useCallback(x=>{if(!i.current.enabled||x.length===0)return;const b=l.current;b.push(x);const C=Math.max(1,i.current.limit);b.length>C&&b.splice(0,b.length-C),d.current=[],g()},[g]);s.useLayoutEffect(()=>(o.setListener(n?h:null),()=>o.setListener(null)),[o,n,h]);const w=s.useCallback(()=>{l.current=[],d.current=[],g()},[g]);s.useEffect(()=>{n||w()},[n,w]);const y=s.useCallback(x=>{const b=i.current,C=fr(b.allRenderableRows,b.getRowId,b.navigationColumns),E=Bu(C,x);if(!E)return;const{anchor:k,head:N}=Vl(C,E);b.selection.enabled?b.selection.setModel([{anchor:k,head:N}],"keyboard"):b.setFocusedCell({id:k.id,field:k.field,rowIndex:E.top});const M=b.viewportRef.current;M&&(Gn(M,E.top-b.pinnedTopRowCount,b.layout.cumulativeHeights,b.layout.pinnedBottomHeight,b.rowHeight),To(M,b.layout.unpinnedColsWithWidth.findIndex(S=>S.field===k.field),b.layout))},[]),p=s.useCallback(x=>{const b=async()=>{if(!i.current.enabled)return Kl();const E=x==="undo"?l:d,k=x==="undo"?d:l,N=E.current.pop();if(!N)return Kl();g();const M=N.map(I=>x==="undo"?{id:I.id,field:I.field,value:I.before,expect:{value:I.after}}:{id:I.id,field:I.field,value:I.after,expect:{value:I.before}}),S=await i.current.batchEdit.applyEdits(M,x);S.committed.length>0&&k.current.push(x==="undo"?S.committed.map(I=>({id:I.id,field:I.field,before:I.after,after:I.before})):S.committed);const F=new Set(S.result.failed.map(I=>I.id));if(F.size>0){const I=N.filter(A=>F.has(A.id));I.length>0&&E.current.push(I)}return g(),S.committed.length>0&&y(S.committed),S.result},C=u.current.then(b,b);return u.current=C,C},[g,y]),f=s.useCallback(()=>p("undo"),[p]),m=s.useCallback(()=>p("redo"),[p]);s.useEffect(()=>{const x=r.current;if(!x||!n)return;const b=C=>{if(C.defaultPrevented)return;const E=Uu(C);if(!E)return;const k=i.current.viewportRef.current;if(!k||i.current.isEditing)return;const N=Vn(C.target,k);N!=="grid"&&N!=="control"||(C.preventDefault(),E==="undo"?f():m())};return x.addEventListener("keydown",b),()=>x.removeEventListener("keydown",b)},[r,n,f,m]),s.useLayoutEffect(()=>{const x=t.current;x.undo=f,x.redo=m,x.canUndo=()=>i.current.enabled&&l.current.length>0,x.canRedo=()=>i.current.enabled&&d.current.length>0,x.clearHistory=w},[t,f,m,w])}function qu(e){const t=String(e);if(t.includes("e")||t.includes("E"))return null;const n=t.indexOf(".");return n===-1?0:t.length-n-1}function pr(e,t){return t===null?e:Number(e.toFixed(Math.min(t,20)))}function Xu(e,t){let n=0;for(const l of e){const d=qu(l);n=d===null||n===null?null:Math.max(n,d)}const o=pr(e[1]-e[0],n);for(let l=2;l<e.length;l++)if(pr(e[l]-e[l-1],n)!==o)return null;const r=e[e.length-1],i=[];for(let l=1;l<=t;l++)i.push(pr(r+o*l,n));return i}const Yu=864e5,jl=e=>((e.getHours()*60+e.getMinutes())*60+e.getSeconds())*1e3+e.getMilliseconds(),Ju=e=>Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/Yu),Zu=e=>e.getFullYear()*12+e.getMonth(),Qu=(e,t)=>new Date(e,t+1,0).getDate();function hr(e){const t=e[1]-e[0];for(let n=2;n<e.length;n++)if(e[n]-e[n-1]!==t)return null;return t}function ef(e,t){const n=e[e.length-1],o=e.every(l=>jl(l)===jl(n));if(o&&e.every(l=>l.getDate()===n.getDate())){const l=hr(e.map(Zu));if(l!==null&&l!==0){const d=[];for(let a=1;a<=t;a++){const u=n.getMonth()+l*a,g=n.getFullYear()+Math.floor(u/12),h=(u%12+12)%12,w=new Date(n.getTime());w.setFullYear(g,h,Math.min(n.getDate(),Qu(g,h))),d.push(w)}return d}}if(o){const l=hr(e.map(Ju));if(l===null)return null;const d=[];for(let a=1;a<=t;a++){const u=new Date(n.getTime());u.setDate(n.getDate()+l*a),d.push(u)}return d}const r=hr(e.map(l=>l.getTime()));if(r===null)return null;const i=[];for(let l=1;l<=t;l++)i.push(new Date(n.getTime()+r*l));return i}const tf=e=>typeof e=="number"&&Number.isFinite(e),nf=e=>e instanceof Date&&!Number.isNaN(e.getTime());function of(e,t){return e.length<2?null:e.every(tf)?Xu(e,t):e.every(nf)?ef(e,t):null}const rf=e=>e instanceof Date?new Date(e.getTime()):e;function lf(e,t,n){if(e.length===0||t<=0)return[];const o=n?of(e,t):null;if(o)return o;const r=[];for(let i=0;i<t;i++)r.push(rf(e[i%e.length]));return r}function sf(e,t,n,o){const r=t.row>e.bottom||t.row<e.top,i=t.col>e.right||t.col<e.left;return!r&&!i?null:r&&(!i||Math.abs(o)>=Math.abs(n))?t.row>e.bottom?{rect:{...e,bottom:t.row},direction:"down"}:{rect:{...e,top:t.row},direction:"up"}:t.col>e.right?{rect:{...e,right:t.col},direction:"right"}:{rect:{...e,left:t.col},direction:"left"}}function af(e,t,n){const o=(a,u)=>{const g=[];if(a<=u)for(let h=a;h<=u;h++)g.push(h);else for(let h=a;h>=u;h--)g.push(h);return g},i=n==="down"||n==="up"?o(e.left,e.right):o(e.top,e.bottom);let l,d;switch(n){case"down":l=o(e.top,e.bottom),d=t.bottom>e.bottom?o(e.bottom+1,t.bottom):[];break;case"up":l=o(e.bottom,e.top),d=t.top<e.top?o(e.top-1,t.top):[];break;case"right":l=o(e.left,e.right),d=t.right>e.right?o(e.right+1,t.right):[];break;default:l=o(e.right,e.left),d=t.left<e.left?o(e.left-1,t.left):[]}return i.map(a=>({line:a,source:l,targets:d}))}function cf(e,t,n){const o=n.row===e.top||n.row===e.bottom,r=n.col===e.left||n.col===e.right;let i=n.row,l=n.col;return(!o||!r)&&(t==="down"||t==="up"?(i=t==="down"?e.top:e.bottom,l=n.col===e.right?e.right:e.left):(l=t==="right"?e.left:e.right,i=n.row===e.bottom?e.bottom:e.top)),{anchor:{row:i,col:l},head:{row:i===e.top?e.bottom:e.top,col:l===e.left?e.right:e.left}}}function df(e,t,n,o){const r=t(e.bottom),i=n[e.right];if(r===void 0||i===void 0)return null;const l=o?.(r,i);if(!l||l.rowId===r&&l.field===i)return{row:e.bottom,field:i};for(let d=e.bottom;d>=Math.max(0,e.bottom-uf);d--)if(t(d)===l.rowId)return{row:d,field:l.field};return null}const uf=1e3,ff="ogx__cell-fill-handle";function gf(e){if(e.altKey||e.shiftKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t);return t==="d"||!n&&e.code==="KeyD"?"down":t==="r"||!n&&e.code==="KeyR"?"right":null}function pf(e){const{containerRef:t,viewportRef:n,selection:o,disableFillHandle:r,isEditing:i,allRenderableRows:l,getRowId:d,navigationColumns:a,columnIndexMap:u,getSpanOrigin:g}=e,h=s.useRef(e);s.useLayoutEffect(()=>{h.current=e});const w=o.enabled&&!r,y=s.useMemo(()=>a.some(S=>S.editable),[a]),p=o.resolved,f=s.useMemo(()=>{if(!w||!y||!p)return null;const S=a.filter(_=>Ye(_.field)).map(_=>_.field),I=df(p,_=>{const L=l[_];return L===void 0?void 0:d(L)},S,g);if(!I)return null;const A=u.get(I.field);return A===void 0?null:{row:I.row,col:A}},[w,y,p,l,d,a,u,g]),m=s.useRef(!0);s.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]);const x=s.useCallback(()=>{const S=h.current;return fr(S.allRenderableRows,S.getRowId,S.navigationColumns)},[]),b=s.useCallback((S,F,I,A,_)=>{const L=cf(F,I,A),D=v=>({id:S.rowIds[v.row],field:S.columns[v.col].field});h.current.selection.setModel([{anchor:D(L.anchor),head:D(L.head)}],_)},[]),C=s.useCallback(async(S,F,I,A,_,L,D)=>{const{batchEdit:v,isCellEditable:V,rowMetaMap:R,getSpanOrigin:Q}=h.current,G={isCellEditable:V,rowMetaMap:R,getSpanOrigin:Q},W=A==="down"||A==="up",H=U=>{const te=S.rowIds[U];return te===void 0?void 0:v.getRow(te)??S.rows[U]},ie=[],oe=[];for(const U of af(F,I,A)){if(U.targets.length===0)continue;const te=re=>W?{r:re,c:U.line}:{r:U.line,c:re},ce=[];for(const re of U.source){const{r:K,c:J}=te(re),ae=H(K),fe=S.columns[J];!ae||!fe||Xe(S.rowIds[K],R)||ce.push(Le(ae,fe.field,fe))}if(ce.length===0)continue;const z=lf(ce,U.targets.length,!_);U.targets.forEach((re,K)=>{const{r:J,c:ae}=te(re),fe=H(J),Z=S.columns[ae],$=S.rowIds[J];if(!fe||!Z||$===void 0)return;if(!gr(S,G,fe,J,ae)){oe.push({id:$,field:Z.field,reason:"notEditable"});return}let O=z[K];const P=Z.fillValue;if(P){const T=We(()=>P.call(Z,{row:fe,id:$,field:Z.field,colDef:Z,direction:A,sourceValues:ce.slice(),index:K,value:O,copy:_}));if(!T.ok){Wt(`fillValue:${Z.field}`,`fillValue of column "${Z.field}" threw; the cell was skipped`,T.error),oe.push({id:$,field:Z.field,reason:"invalidValue"});return}O=T.value}ie.push({id:$,field:Z.field,value:O})})}b(S,I,A,L,D);const ue=await v.applyEdits(ie,"fill"),se={updated:ue.result.updated,failed:ue.result.failed,skipped:[...oe,...ue.result.skipped],direction:A};return h.current.onFill?.(se),se},[b]),E=s.useRef(null),k=s.useCallback((S,F,I)=>{const A=E.current,_=h.current.viewportRef.current;if(!A||!_)return;const L=A.ctx,D=L.rowIndexById.get(S.id),v=L.colIndexByField.get(S.field);if(D===void 0||v===void 0)return;const V=F-A.x+_.scrollLeft-A.scrollLeft,R=I-A.y+_.scrollTop-A.scrollTop,Q=sf(A.source,{row:D,col:v},V,R);A.target=Q,Q?b(L,Q.rect,Q.direction,A.anchor,"pointer"):h.current.selection.setModel(A.sourceModel,"pointer")},[b]),N=s.useCallback(({cancelled:S,altKey:F})=>{const I=E.current;if(E.current=null,!I||!m.current)return;const A=I.ctx;if(S||!I.target){h.current.selection.setModel(I.sourceModel,"pointer");return}C(A,I.source,I.target.rect,I.target.direction,F,I.anchor,"pointer")},[C]),M=w&&y;return s.useEffect(()=>{const S=n.current;if(!S||!M)return;const F=I=>{if(I.button!==0||!(I.target instanceof Element))return;const A=I.target.closest(`.${ff}`);if(!A||A.closest(".ogx__viewport")!==S||h.current.isEditing)return;const{selection:_}=h.current,{range:L,resolved:D}=_.getCurrentRange();if(!L||!D)return;const v=x(),V=v.rowIds[D.bottom],R=v.columns[D.right];if(V===void 0||!R)return;I.preventDefault();const Q=S.ownerDocument;S.contains(Q.activeElement)||S.focus({preventScroll:!0}),We(()=>S.setPointerCapture(I.pointerId)),E.current={source:{top:D.top,bottom:D.bottom,left:D.left,right:D.right},sourceModel:[L],anchor:{row:D.anchorRow,col:D.anchorCol},ctx:v,x:I.clientX,y:I.clientY,scrollLeft:S.scrollLeft,scrollTop:S.scrollTop,target:null},_.startTrackedDrag({start:{id:V,field:R.field},x:I.clientX,y:I.clientY,pointerId:I.pointerId,onTrack:k,onEnd:N})};return S.addEventListener("pointerdown",F),()=>S.removeEventListener("pointerdown",F)},[n,M,x,k,N]),s.useEffect(()=>{const S=t.current;if(!S||!w)return;const F=I=>{if(I.defaultPrevented)return;const A=gf(I);if(!A)return;const _=h.current.viewportRef.current;if(!_||h.current.isEditing)return;const L=Vn(I.target,_);if(L!=="grid"&&L!=="control")return;const{range:D,resolved:v}=h.current.selection.getCurrentRange();if(!D||!v)return;I.preventDefault();const V={top:v.top,bottom:v.bottom,left:v.left,right:v.right},R=A==="down"?{...V,bottom:V.top}:{...V,right:V.left};(A==="down"?V.bottom===V.top:V.right===V.left)||C(x(),R,V,A,!0,{row:v.anchorRow,col:v.anchorCol},"keyboard")};return S.addEventListener("keydown",F),()=>S.removeEventListener("keydown",F)},[t,w,C,x]),{handle:i?null:f}}const hf=e=>e.id,mf={hasColSpan:!1,hasRowSpan:!1,colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},getSpanOrigin:()=>null,getUnpinnedColSpanRanges:()=>{},getCenterRowSpanStart:e=>e},Ul="\0",Rl="";function ql(e){if(typeof e!="number"||Number.isNaN(e))return 1;if(e===1/0)return Number.MAX_SAFE_INTEGER;if(!Number.isFinite(e))return 1;const t=Math.floor(e);return t<1?1:t}function wf(e){return e.map(t=>t.field).join(Ul)}function bf(e){const{pinnedTopRows:t,centerRows:n,pinnedBottomRows:o,columns:r,leftPinnedColumns:i,unpinnedColumns:l,rightPinnedColumns:d,expandedRowIds:a,rowMetaMap:u,getRowId:g=hf}=e,h=s.useMemo(()=>r.some(x=>x.colSpan!==void 0&&x.colSpan!==null),[r]),w=s.useMemo(()=>r.some(x=>x.rowSpan!==void 0&&x.rowSpan!==null),[r]),y=h||w,p=y?[i,l,d].map(wf).join(Rl):"",f=s.useMemo(()=>{if(!p)return{columns:[],leftCount:0,unpinnedCount:0};const x=new Map(r.map(k=>[k.field,k])),b=p.split(Rl).map(k=>k?k.split(Ul):[]),C=[];let E=0;for(const k of b){E+=k.length;for(const N of k){const M=x.get(N)??{field:N};C.push({colDef:M,field:N,sectionEnd:E,hasColSpan:M.colSpan!==void 0&&M.colSpan!==null,hasRowSpan:M.rowSpan!==void 0&&M.rowSpan!==null})}}return{columns:C,leftCount:b[0].length,unpinnedCount:b[1].length}},[p,r]),m=s.useMemo(()=>{if(!y||f.columns.length===0)return null;const x={colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},hiddenOriginFields:new Map,unpinnedRanges:new Map,centerRowSpanStart:new Map},C={spanColumns:f,expandedRowIds:a,rowMetaMap:u,getRowId:g,warned:new Set,out:x};return mr(t,0,!1,C),mr(n,t.length,!0,C),mr(o,t.length+n.length,!1,C),x},[y,f,t,n,o,a,u,g]);return s.useMemo(()=>{if(!m)return mf;const{colspanMap:x,rowSpanningCaches:b,hiddenOriginFields:C,unpinnedRanges:E,centerRowSpanStart:k}=m,N=f.columns;return{hasColSpan:h,hasRowSpan:w,colspanMap:x,rowSpanningCaches:b,getSpanOrigin:(M,S)=>{const F=x.get(M)?.[S];if(F?.spannedByColSpan)return{rowId:M,field:N[F.leftVisibleCellIndex].field};const I=b.hiddenCellOriginMap[M]?.[S];return I===void 0?null:{rowId:I,field:C.get(M)?.[S]??S}},getUnpinnedColSpanRanges:M=>E.get(M),getCenterRowSpanStart:M=>k.get(M)??M}},[m,h,w,f])}function mr(e,t,n,o){const{spanColumns:r,expandedRowIds:i,rowMetaMap:l,getRowId:d,warned:a,out:u}=o,{columns:g,leftCount:h,unpinnedCount:w}=r,y=g.length,{colspanMap:p,rowSpanningCaches:f,hiddenOriginFields:m,unpinnedRanges:x,centerRowSpanStart:b}=u,C=new Int32Array(y),E=new Array(y),k=new Array(y),N=new Int32Array(y);let M=0;const S=[];g.forEach((A,_)=>{(A.hasColSpan||A.hasRowSpan)&&S.push(_)});const F=(A,_,L)=>{const D=g[L].field;if(Xt(f.hiddenCells,A,D,!0),Xt(f.hiddenCellOriginMap,A,D,E[L]),k[L]!==D&&Xt(m,A,D,k[L]),n){const v=b.get(_);(v===void 0||N[L]<v)&&b.set(_,N[L])}},I=(A,_,L)=>{const D=g[L],v=d(A),V=xf(A,v,D.colDef,t+_,L,l,a);let R=1;if(D.hasColSpan){const G=Math.min(Xl(D.colDef.colSpan,V,"colSpan",D.field,a),D.sectionEnd-L);for(;R<G&&C[L+R]<=_;)R++}let Q=1;if(D.hasRowSpan){Q=Math.min(Xl(D.colDef.rowSpan,V,"rowSpan",D.field,a),e.length-_);for(let G=1;G<Q;G++)if(Xe(d(e[_+G]),l)){Q=G;break}if(Q>1&&i&&i.size>0){for(let G=0;G<Q-1;G++)if(i.has(d(e[_+G]))){Q=G+1;break}}}if(R>1){Xt(p,v,D.field,{spannedByColSpan:!1,cellProps:{colSpan:R}});for(let G=1;G<R;G++){const W=g[L+G];Xt(p,v,W.field,{spannedByColSpan:!0,leftVisibleCellIndex:L,rightVisibleCellIndex:L+R-1})}if(L>=h&&L<h+w){let G=x.get(v);G||(G=[],x.set(v,G)),G.push(L-h,L+R-1-h)}}if(Q>1){Xt(f.spannedCells,v,D.field,Q);for(let G=L;G<L+R;G++)C[G]=_+Q,E[G]=v,k[G]=D.field,N[G]=_;_+Q>M&&(M=_+Q)}return R};for(let A=0;A<e.length;A++){const _=e[A];if(!_||_._isSkeleton||Xe(d(_),l))continue;if(M<=A){let D=0;for(const v of S)v>=D&&(D=v+I(_,A,v));continue}let L=0;for(;L<y;)C[L]>A?(F(d(_),A,L),L++):g[L].hasColSpan||g[L].hasRowSpan?L+=I(_,A,L):L++}}function xf(e,t,n,o,r,i,l){const d=e[n.field];let a=d;if(n.valueGetter)try{a=n.valueGetter({row:e,field:n.field,value:d})}catch(u){Yl(l,`valueGetter:${n.field}`,`valueGetter for column "${n.field}" threw while computing its span`,u),a=void 0}return{row:e,value:a,field:n.field,colDef:n,rowIndex:o,colIndex:r,rowMeta:i?.get(t)}}function Xl(e,t,n,o,r){if(typeof e=="number")return ql(e);if(typeof e!="function")return 1;try{return ql(e(t))}catch(i){return Yl(r,`${n}:${o}`,`${n} for column "${o}" threw; the cell is rendered without a span`,i),1}}function Yl(e,t,n,o){process.env.NODE_ENV==="production"||e.has(t)||(e.add(t),console.warn(`[OpenGridX] ${n}.`,o))}function Xt(e,t,n,o){if(e instanceof Map){let i=e.get(t);i||(i={},e.set(t,i)),i[n]=o;return}let r=e[t];r||(r={},e[t]=r),r[n]=o}function yf(e){const{spanning:t,renderContext:n,offsetTop:o,cumulativeHeights:r}=e;return s.useMemo(()=>{if(!t.hasRowSpan)return{renderContext:n,offsetTop:o};let i=Math.max(0,n.firstRowIndex);for(let l=t.getCenterRowSpanStart(i);l<i;l=t.getCenterRowSpanStart(i))i=l;return i>=n.firstRowIndex?{renderContext:n,offsetTop:o}:{renderContext:{...n,firstRowIndex:i},offsetTop:i>0?r[i-1]??0:0}},[t,n,o,r])}function Cf(e){const{spanning:t,firstColumnIndex:n,lastColumnIndex:o,virtualColumns:r,layout:i,rows:l}=e;return s.useMemo(()=>{if(!t.hasColSpan||i.unpinnedColsWithWidth.length===0)return r;let d=n,a=o,u=!0;for(;u;){u=!1;for(const{row:x,id:b}of l){const C=t.getUnpinnedColSpanRanges(b??x.id);if(C)for(let E=0;E<C.length;E+=2){const k=C[E],N=C[E+1];N<d||k>a||(k<d&&(d=k,u=!0),N>a&&(a=N,u=!0))}}}if(d===n&&a===o)return r;const{leftPinnedCols:g,unpinnedColsWithWidth:h,rightPinnedCols:w,unpinnedAccWidths:y,unpinnedTotalWidth:p}=i,f=d>0?y[d-1]:0,m=p-y[a];return[...g,...f>0?[{field:"__spacer_left__",width:f,isSpacer:!0}]:[],...h.slice(d,a+1),...m>0?[{field:"__spacer_right__",width:m,isSpacer:!0}]:[],...w]},[t,n,o,r,i,l])}function vf(e,t){const{draggedColumn:n,onDragOver:o,onDrop:r,onDragEnd:i}=t,l=s.useMemo(()=>{if(!e||e.length===0)return null;const d=a=>n===null||ir(e,n,a);return{onDragOver:o&&(a=>d(a)?o(a):()=>{}),onDrop:r&&(a=>d(a)?r(a):u=>{u.preventDefault(),i?.()})}},[e,n,o,r,i]);return l?{...t,...l}:t}const _f=300,Jl=e=>e.id;function Sf(e,t){return e==="infinite"?"infinite":e==="server"?t?"all":"page":"all"}function Zl(e,t){const n=new Set,o=[];return e.forEach(r=>{const i=t(r);n.has(i)||(n.add(i),o.push({id:i,row:r}))}),o}function Ql(e,t,n){const o=new Set(e.map(n)),r=t.filter(i=>!o.has(i.id)).map(i=>i.row);return r.length===0?e:[...e,...r]}function kf(e){const{dataSource:t,sortModel:n,filterModel:o,paginationModel:r,paginationMode:i,sortingMode:l,filterMode:d,aggregationModel:a,rowGroupingActive:u=!1}=e,g=Sf(i,u),h=!!t&&i==="server"&&u,w=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||w.current||!h||(w.current=!0,console.warn("[OpenGridX] `rowGroupingModel` turns pagination off, so the dataSource with `paginationMode: 'server'` is asked for every row (startRow 0, endRow Number.MAX_SAFE_INTEGER) instead of one page. See docs/features/data-source.md."))},[h]);const y=t?.getRows,p=sl({dataSource:t,paginationMode:i,sortingMode:l,filterMode:d}),f=JSON.stringify([g,g!=="all"||l==="server"?n:null,g!=="all"||d==="server"?o:null,p?a??null:null,g==="all"?null:r.pageSize]),m=g==="all"?0:r.page,x=g==="all"?0:r.pageSize,b=s.useRef({params:e,kind:g});s.useLayoutEffect(()=>{b.current={params:e,kind:g}});const C=s.useRef(0),E=s.useRef(0),k=s.useRef(null),N=s.useRef({page:0,loadedEnd:0,inFlightEnd:null}),M=s.useRef(null),S=s.useRef(!1),F=s.useRef(0),I=s.useRef(!1),A=s.useRef(new Set),_=s.useCallback(()=>{const W=S.current||F.current>0;W!==I.current&&(I.current=W,b.current.params.setDataSourceLoading(W))},[]),L=s.useCallback(()=>{M.current!==null&&(clearTimeout(M.current),M.current=null)},[]),D=s.useCallback(()=>{C.current++,N.current.inFlightEnd=null,S.current=!1},[]),v=s.useCallback(()=>{E.current++,A.current.clear(),F.current=0},[]),V=s.useCallback(async()=>{const{params:W,kind:H}=b.current,ie=W.dataSource;if(!ie)return!1;const oe=N.current,ue=W.paginationModel.pageSize;let se,U;if(H==="infinite"){if(oe.inFlightEnd!==null)return!1;if(se=oe.loadedEnd,U=(oe.page+1)*ue,U<=se)return S.current=!1,_(),!1;oe.inFlightEnd=U}else H==="page"?(se=W.paginationModel.page*ue,U=se+ue):(se=0,U=al);const te=++C.current;S.current=!0,_(),W.setDataSourceError(null);let ce;try{ce=await ie.getRows({startRow:se,endRow:U,sortModel:W.sortModel,filterModel:W.filterModel,groupKeys:[],aggregationModel:W.aggregationModel})}catch(z){return te!==C.current||(oe.inFlightEnd=null,S.current=!1,b.current.params.setDataSourceError(z),console.error("Data Source Error:",z),_()),!1}if(te!==C.current)return!1;try{const{params:z}=b.current,re=z.getRowId??Jl,K=Zl(ce.rows,re);if(H==="infinite"&&se>0?z.setRows(J=>Ql(J,K,re),!0):(z.setRows(K.map(J=>J.row),!0),v()),ce.aggregationResults&&z.onAggregationResults?.(ce.aggregationResults),ce.rowCount!==void 0&&z.setRowCount(ce.rowCount),H==="infinite"&&(oe.inFlightEnd=null,oe.loadedEnd=se+ce.rows.length,ce.rows.length>=U-se&&(oe.page+1)*ue>U))return!0}catch(z){return oe.inFlightEnd=null,S.current=!1,b.current.params.setDataSourceError(z),console.error("Data Source Error:",z),_(),!1}return S.current=!1,_(),!1},[_,v]),R=s.useCallback(async()=>{for(;await V(););},[V]);s.useLayoutEffect(()=>{if(!y){k.current&&(k.current=null,L(),D(),v(),b.current.params.setDataSourceError(null),_());return}const W=k.current,H=N.current;if(!W||W.key!==f||W.getRows!==y){k.current={key:f,getRows:y},D(),v();const ie=g==="infinite"&&W!==null&&m!==0;if(H.page=ie?0:m,H.loadedEnd=0,ie){const{params:oe}=b.current;oe.onPaginationModelChange?.({...oe.paginationModel,page:0})}}else g==="infinite"?(m<H.page&&(D(),H.loadedEnd=0),H.page=m):D();if(g==="infinite"){const ie=H.inFlightEnd!==null;if(ie||(H.page+1)*x<=H.loadedEnd){S.current=ie,_();return}}return S.current=!0,_(),M.current=setTimeout(()=>{M.current=null,R()},_f),L},[y,f,g,m,x,L,D,v,_,R]),s.useEffect(()=>()=>{D(),v()},[D,v]);const Q=s.useCallback(()=>(L(),R()),[L,R]),G=s.useCallback(async(W,H,ie)=>{const{params:oe}=b.current,ue=oe.dataSource;if(!ue)return;const se=JSON.stringify(H),U=A.current;if(U.has(se))return;const te=E.current;U.add(se),F.current++,_();try{const ce=await ue.getRows({startRow:0,endRow:al,sortModel:oe.sortModel,filterModel:oe.filterModel,groupKeys:H,aggregationModel:oe.aggregationModel});if(te!==E.current)return;if(ce.rows.length>0){const{params:z}=b.current,re=z.getRowId??Jl,K=Zl(ce.rows,re);z.setRows(J=>Ql(J,K,re),!0)}}catch(ce){if(te!==E.current)return;U.delete(se),console.error("Failed to fetch children:",ce),ie?.(ce)}finally{te===E.current&&(F.current--,_())}},[_]);return{fetchRows:Q,fetchChildren:G}}function Ef(e){return(e.serverChildrenCount??0)>0&&(e.children?.length??0)===0}function Mf({enabled:e,treeNodes:t,isGroupExpanded:n,getNodePath:o,toggleExpansion:r,fetchChildren:i}){const l=s.useRef({isGroupExpanded:n,toggleExpansion:r});s.useLayoutEffect(()=>{l.current={isGroupExpanded:n,toggleExpansion:r}}),s.useEffect(()=>{e&&t.forEach((d,a)=>{!Ef(d)||!n(a)||i(a,o(a),()=>{const{isGroupExpanded:u,toggleExpansion:g}=l.current;u(a)&&g(a)})})},[e,t,n,o,i])}const es={};function Nf(e){const t=JSON.stringify(e),[n,o]=s.useState(null),r=s.useCallback(i=>o({modelKey:t,results:i}),[t]);return[n&&n.modelKey===t?n.results:null,r]}function ts(e){const{rows:t,columns:n,aggregationModel:o,isServerSide:r,dataSource:i,filterModel:l,sortModel:d,serverAggregationResults:a}=e,u=Object.keys(o).length>0,g=s.useMemo(()=>{const k=new Map;return(n??[]).forEach(N=>k.set(N.field,N)),k},[n]),h=s.useMemo(()=>r||!u?es:Hn(t,o,g,"useAggregation"),[t,g,o,r,u]),w=JSON.stringify([o,l??null,d??[]]),y=r&&u&&!!i?.getAggregations&&!a,p=s.useRef({aggregationModel:o,filterModel:l,sortModel:d});s.useEffect(()=>{p.current={aggregationModel:o,filterModel:l,sortModel:d}});const[f,m]=s.useState(null);s.useEffect(()=>{const k=i?.getAggregations;if(!y||!k)return;let N=!1;const M=p.current,S={sortModel:M.sortModel??[],filterModel:M.filterModel??{items:[]},groupKeys:[],aggregationModel:M.aggregationModel};let F;try{F=Promise.resolve(k(S))}catch(I){F=Promise.reject(I)}return F.then(I=>{N||m({key:w,result:I,error:null})},I=>{N||(console.error("[useAggregation] Server aggregation error:",I),m({key:w,result:null,error:I}))}),()=>{N=!0}},[y,i,w]);const x=f&&f.key===w?f:null,b=y&&x===null,C=y?x?.error??null:null;return{aggregationResult:s.useMemo(()=>r?a&&Object.keys(a).length>0?a:x?.result??es:h,[r,h,a,x]),isLoading:b,error:C}}const If={items:[]},Lf=[];function Af(e){const{rows:t,columns:n,pivotMode:o,pivotModel:r,filterModel:i,sortModel:l,hasDataSource:d,hierarchyRequested:a}=e,u=o&&!d,g=s.useMemo(()=>new Set(n.map(x=>x.field)),[n]),h=s.useMemo(()=>jo(n),[n]),w=s.useMemo(()=>Qa(i,g),[i,g]),y=s.useMemo(()=>u?Ho(t,w.source,h):t,[u,t,w.source,h]),p=s.useMemo(()=>u?Ai(y,n,r,{outputFilterModel:w.output,sortModel:l}):Ro,[u,y,n,r,w.output,l]),f=u&&p.isValid,m=s.useRef({dataSource:!1,hierarchy:!1});return s.useEffect(()=>{process.env.NODE_ENV!=="production"&&(o&&d&&!m.current.dataSource&&(m.current.dataSource=!0,console.warn("[OpenGridX] `pivotMode` is ignored when a `dataSource` is set: pivoting is client-side and the grid only holds the rows of one server page. Pivot on the server, or pass the full dataset as `rows`.")),f&&a&&!m.current.hierarchy&&(m.current.hierarchy=!0,console.warn("[OpenGridX] `treeData` and `rowGroupingModel` are turned off while `pivotMode` is active: the pivot rows are already grouped by the pivot row fields.")))},[o,d,f,a]),{isActive:f,rows:f?p.pivotRows:t,columns:f?p.pivotColumns:n,pipelineFilterModel:f?If:i,pipelineSortModel:f?Lf:l}}const tt=({variant:e="text",size:t="medium",color:n="default",disabled:o=!1,className:r="",type:i="button",children:l,...d})=>{const a=["ogx-button",`ogx-button--${e}`,`ogx-button--${t}`,`ogx-button--${n}`,o&&"ogx-button--disabled",r].filter(Boolean).join(" ");return c.jsx("button",{type:i,className:a,disabled:o,...d,children:l})};function wr(e){const t=s.useId(),{page:n,pageSize:o,rowCount:r,onPageChange:i,onPageSizeChange:l,pageSizeOptions:d=[10,25,50,100],showFirstButton:a=!0,showLastButton:u=!0,localeText:g}=e,h=Un(o),w=Zo(r,h),y=Ri(n,w),p=d.includes(h)?d:[...d,h].sort((_,L)=>_-L),f=y*h,m=Math.min(f+h,r),x=r===0?0:`${f+1}–${m}`,b=g?.paginationRowsPerPage??"Rows per page:",C=g?.paginationOf?g.paginationOf(r===0?0:f+1,m,r):`${x} of ${r}`,E=g?.paginationPage?g.paginationPage(y+1,w):`Page ${y+1} of ${w}`,k=()=>{i(0)},N=()=>{i(Math.max(0,y-1))},M=()=>{i(Math.min(w-1,y+1))},S=()=>{i(w-1)},F=_=>{const L=parseInt(_.target.value,10);l(L)},I=y===0,A=y>=w-1;return c.jsxs("div",{className:"ogx-pagination",role:"navigation","aria-label":"Pagination",children:[c.jsxs("div",{className:"ogx-pagination__page-size",children:[c.jsx("label",{htmlFor:t,className:"ogx-pagination__label",children:b}),c.jsx("select",{id:t,className:"ogx-pagination__select",value:h,onChange:F,children:p.map(_=>c.jsx("option",{value:_,children:_},_))})]}),c.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:C}),c.jsxs("div",{className:"ogx-pagination__actions",children:[a&&c.jsx(tt,{variant:"text",size:"small",onClick:k,disabled:I,"aria-label":"Go to first page",title:"First page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"})})}),c.jsx(tt,{variant:"text",size:"small",onClick:N,disabled:I,"aria-label":"Go to previous page",title:"Previous page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),c.jsx("div",{className:"ogx-pagination__page-info","aria-current":"page",children:E}),c.jsx(tt,{variant:"text",size:"small",onClick:M,disabled:A,"aria-label":"Go to next page",title:"Next page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),u&&c.jsx(tt,{variant:"text",size:"small",onClick:S,disabled:A,"aria-label":"Go to last page",title:"Last page",children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"})})})]})]})}function Pf({row:e,rowId:t,rowIndex:n,ariaRowIndex:o,listViewColumn:r,gridColumn:i,rowMeta:l,isSelected:d=!1,checkboxSelection:a=!1,rowHeight:u,onRowClick:g,onRowDoubleClick:h,onSelectionChange:w,tabIndex:y=-1,onFocus:p,onToggleExpansion:f}){const m=t??e.id,x=r.field,b=Le(e,x,i),C=No(e,x,b,i)??Io(b,i),E=l?.isGroupRow===!0||Xe(m),k={row:e,value:b,formattedValue:C,field:x,colDef:i??r,rowIndex:n,colIndex:0,rowMeta:l},N=M=>{M.stopPropagation(),w?.(m,M.target.checked)};return c.jsxs("div",{className:`ogx-list-view__row${d?" ogx-list-view__row--selected":""}`,style:u?{minHeight:u}:void 0,onClick:()=>g?.(e),onDoubleClick:h?()=>h(e):void 0,role:"row","aria-rowindex":o??n+1,"aria-selected":d,"aria-level":l?.treeDepth!==void 0?l.treeDepth+1:void 0,"aria-expanded":l?.hasChildren?l.isExpanded===!0:void 0,"data-rowindex":n,tabIndex:y,onFocus:p?M=>{M.target===M.currentTarget&&p(n)}:void 0,children:[a&&c.jsx("div",{className:"ogx-list-view__checkbox",onClick:M=>M.stopPropagation(),children:!E&&c.jsx(bt,{checked:d,onChange:N,"aria-label":`Select row ${m}`,tabIndex:-1})}),l&&f&&c.jsx("div",{className:"ogx-list-view__expand",style:{paddingLeft:(l.treeDepth??0)*16},onClick:M=>M.stopPropagation(),onDoubleClick:M=>M.stopPropagation(),children:l.hasChildren&&c.jsx(nr,{isExpanded:l.isExpanded===!0,onClick:()=>f(m),tabIndex:-1})}),c.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:c.jsx(Ft,{field:x,resetKey:e,renderFn:()=>{const M=r.renderCell(k);return M===void 0&&E?l?.groupLabel:M}})})]})}function Tf(e,t){const n=s.useRef(!0),o=s.useRef(e);s.useEffect(()=>{o.current=e},[e]),s.useEffect(()=>{n.current=!0},[t]);const r=s.useCallback(i=>{const l=Qi(i.currentTarget);if(!l){n.current=!0;return}if(!n.current)return;const d=o.current;d&&(n.current=!1,d(l))},[]);return e?r:void 0}const Ff=e=>e.id;function Of({ariaLabel:e,allRenderableRows:t,dataRowCount:n,pinnedTopRowCount:o,pinnedBottomRowCount:r,unpinnedRowCount:i,pagination:l,effectivePaginationModel:d,currentPage:a,pageSizeOptions:u,selectedRowIds:g,listViewColumn:h,columnsByField:w,rowMetaMap:y,noRowsLabel:p,rowHeight:f,checkboxSelection:m,paginationMode:x,serverRowCount:b,paginationSlot:C,paginationSlotProps:E,localeText:k,onRowClick:N,onRowDoubleClick:M,onSelectionChange:S,onPaginationModelChange:F,onRowsScrollEnd:I,getRowId:A=Ff,multiselectable:_=!1,loading:L=!1,loadingOverlay:D,noRowsOverlay:v,showPaginationControls:V=!0,selectable:R=!1,onToggleExpansion:Q}){const G=C||wr,W=s.useRef(null),[H,ie]=s.useState(null),oe=H===null?-1:t.findIndex($=>A($)===H),ue=oe===-1?0:oe,se=$=>{const O=t[$];O&&(ie(A(O)),W.current?.querySelector(`:scope > [role="row"][data-rowindex="${$}"]`)?.focus())},U=$=>{const O=$.target;if(O.getAttribute("role")!=="row"||O.parentElement!==W.current)return;const P=Number(O.getAttribute("data-rowindex")),T=t[P];if(!T)return;const X=A(T),B=t.length-1,ee=y.get(X),q=!!(ee?.hasChildren&&Q);if($.altKey&&($.key==="ArrowRight"||$.key==="ArrowLeft")){$.preventDefault(),q&&$.key==="ArrowRight"!=(ee?.isExpanded===!0)&&Q?.(X);return}switch($.key){case"ArrowDown":$.preventDefault(),se(Math.min(P+1,B));return;case"ArrowUp":$.preventDefault(),se(Math.max(P-1,0));return;case"Home":$.preventDefault(),se(0);return;case"End":$.preventDefault(),se(B);return;case"PageDown":$.preventDefault(),se(Math.min(P+10,B));return;case"PageUp":$.preventDefault(),se(Math.max(P-10,0));return;case"Enter":case" ":if($.preventDefault(),$.key===" "&&$.shiftKey){R&&!ee?.isGroupRow&&S(X,!g.has(X));return}q?Q?.(X):N({row:T,id:X,rowIndex:P});return}},te=x==="server",ce=te?b||0:i,z=te?b||0:n,re=Un(d.pageSize),K=Zo(ce,re),J=l?a*re:0,ae=t.length-o-r,fe=$=>{if($<o)return $+1;const O=$-o;return O<ae?o+J+O+1:o+ce+(O-ae)+1},Z=Tf(I,t.length);return c.jsxs("div",{className:"ogx-list-view",role:"grid","aria-label":e||"Data grid list view","aria-rowcount":z,"aria-multiselectable":_,children:[c.jsx("div",{className:"ogx-list-view__toolbar",children:c.jsxs("span",{children:[z," ",z===1?"item":"items",l?` · page ${a+1} of ${K}`:"",g.size>0?` · ${g.size} selected`:""]})}),c.jsx("div",{className:"ogx-list-view__rows",tabIndex:-1,onScroll:Z,onKeyDown:U,ref:W,children:t.length===0&&L?c.jsx("div",{className:"ogx-list-view__loading",children:D??c.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})}):t.length===0&&v?c.jsx("div",{className:"ogx-list-view__empty",children:v}):t.length===0?c.jsxs("div",{className:"ogx-list-view__empty",children:[c.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),c.jsx("path",{d:"M3 9h18M9 21V9"})]}),p]}):t.map(($,O)=>{const P=A($);return c.jsx(Pf,{row:$,rowId:P,rowIndex:O,ariaRowIndex:fe(O),listViewColumn:h,gridColumn:w.get(h.field),rowMeta:y.get(P),isSelected:g.has(P),checkboxSelection:m,rowHeight:f,onRowClick:T=>N({row:T,id:P,rowIndex:O}),onRowDoubleClick:M?T=>M({row:T,id:P,rowIndex:O}):void 0,onSelectionChange:S,tabIndex:O===ue?0:-1,onToggleExpansion:Q,onFocus:T=>ie(A(t[T]))},P)})}),l&&V&&c.jsx(G,{page:a,pageSize:d.pageSize,rowCount:ce,pageSizeOptions:u,onPageChange:$=>F({...d,page:$}),onPageSizeChange:$=>F({...d,pageSize:$,page:0}),localeText:k,...E})]})}function Df({overlay:e}){return e?c.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows ogx__loading-overlay--custom",children:e}):c.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows",children:c.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})})}function bn(e){return e.headerName||e.field}function $f(e){return e.nativeEvent.isComposing||e.keyCode===229}function xn(e,t,n=!0){return o=>{if($f(o)){o.stopPropagation();return}n&&o.key==="Enter"&&(o.stopPropagation(),e()),o.key==="Escape"&&(o.stopPropagation(),t())}}function Gf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(String(e??"")),d=s.useRef(null);return s.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),c.jsx(Qe,{ref:d,variant:"cell",type:"text",inputClassName:"ogx__edit-input","aria-label":bn(t),value:i,onChange:a=>{l(a.target.value),n(a.target.value)},onBlur:o,onKeyDown:xn(o,r)})}function Hf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(typeof e=="number"?e:""),d=s.useRef(null);return s.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),c.jsx(Qe,{ref:d,variant:"cell",type:"number",inputClassName:"ogx__edit-input ogx__edit-input--number","aria-label":bn(t),value:i,onChange:a=>{const u=a.target.value===""?"":Number(a.target.value);l(u),n(u===""?null:u)},onBlur:o,onKeyDown:xn(o,r)})}function Bf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=()=>{n(!e),o()};return c.jsx("div",{className:"ogx__edit-boolean",onMouseDown:d=>d.preventDefault(),children:c.jsx(bt,{ref:i,inputClassName:"ogx__edit-checkbox","aria-label":bn(t),checked:!!e,onChange:l,onMouseDown:d=>d.preventDefault(),onBlur:o,onKeyDown:xn(o,r,!1)})})}const br=e=>typeof e=="object"?e.value:e,Wf=e=>typeof e=="object"?e.label:String(e);function Vf(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function zf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=t.valueOptions??[],d=l.map(g=>String(br(g)));let a=l.findIndex(g=>Vf(br(g),e));a===-1&&e!==null&&e!==void 0&&(a=d.indexOf(String(e)));const u=a===-1;return c.jsxs("select",{ref:i,className:"ogx__edit-select","aria-label":bn(t),value:u?"":d[a],onChange:g=>{const h=d.indexOf(g.target.value);n(h===-1?null:br(l[h]))},onBlur:o,onKeyDown:xn(o,r),children:[u&&c.jsx("option",{value:""}),l.map((g,h)=>c.jsx("option",{value:d[h],children:Wf(g)},h))]})}const ns=e=>String(e).padStart(2,"0"),os=/^(\d{4}-\d{2}-\d{2})/;function xr(e){if(e instanceof Date)return Number.isNaN(e.getTime())?"":`${e.getFullYear()}-${ns(e.getMonth()+1)}-${ns(e.getDate())}`;if(typeof e=="string"){const t=os.exec(e);return t?t[1]:e===""?"":xr(new Date(e))}return typeof e=="number"?xr(new Date(e)):""}function Kf(e,t){if(e==="")return null;const[n,o,r]=e.split("-").map(Number),i=l=>{const d=new Date(l.getTime());return d.setFullYear(n,o-1,r),d};return t instanceof Date&&!Number.isNaN(t.getTime())?i(t):typeof t=="number"&&Number.isFinite(t)?i(new Date(t)).getTime():typeof t=="string"&&os.test(t)&&t.length>10?e+t.slice(10):e}function jf({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i]=s.useState(e),[l,d]=s.useState(()=>xr(e)),a=s.useRef(null);return s.useEffect(()=>{a.current?.focus()},[]),c.jsx(Qe,{ref:a,variant:"cell",type:"date",inputClassName:"ogx__edit-input","aria-label":bn(t),value:l,onChange:u=>{d(u.target.value),n(Kf(u.target.value,i))},onBlur:o,onKeyDown:xn(o,r)})}function Uf(e){const{colDef:t}=e;switch(t.type){case"number":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Hf,{...e})});case"boolean":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Bf,{...e})});case"singleSelect":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(zf,{...e})});case"date":return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(jf,{...e})});default:return c.jsx("div",{className:"ogx__edit-cell",children:c.jsx(Gf,{...e})})}}function Rf(e){const{onCellClick:t,onCellEditStart:n,onCellValueChange:o,value:r,row:i,colDef:l,rowIndex:d,colIndex:a,ariaColIndex:u,isSelected:g,onClick:h,width:w,pinnedPosition:y,pinnedOffset:p,isPinnedEdge:f,isFocused:m,isFocusVisible:x,isEditable:b,isEditing:C,onEditStart:E,onEditStop:k,onValueChange:N,colSpanInfo:M,rowSpan:S,isHiddenByRowSpan:F,rowMeta:I,valueError:A,rangeFlags:_=0}=e,L=s.useCallback(Z=>{o?o(l.field,Z):N?.(Z)},[o,N,l.field]),D=I?.isGroupRow===!0,{formattedValue:v,error:V}=s.useMemo(()=>{const Z=l.valueFormatter;if(Z&&!(D&&r==null)){const $=We(()=>Z({value:r,row:i,field:l.field}));return $.ok?{formattedValue:$.value}:{formattedValue:"",error:$.error??new Error("valueFormatter failed")}}return{formattedValue:Io(r,l)}},[r,i,l,D]),R=s.useMemo(()=>{if(!l.cellClassName)return"";const Z=l.cellClassName;if(typeof Z=="function"){const $=We(()=>Z({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I}));return $.ok&&$.value||""}return l.cellClassName},[l,r,v,i,d,a,I]),Q=A??V,G=l.field,W=s.useCallback(()=>{k?.(!1,G)},[k,G]),H=s.useCallback(()=>{k?.(!0,G)},[k,G]),ie=s.useMemo(()=>[i,l.renderCell,r],[i,l.renderCell,r]),oe=s.useRef(!1);if(s.useEffect(()=>{if(!(!C||!k))return oe.current=!0,()=>{oe.current=!1,queueMicrotask(()=>{oe.current||k(!1,G)})}},[C,k,G]),M?.spannedByColSpan)return null;const ue=M?.cellProps.colSpan??1,se=ue>1,U=(se?M?.cellProps.width:void 0)??w??l.width??100,te={width:"var(--width)","--width":typeof U=="number"?`${U}px`:U,flexGrow:(se?M?.cellProps.flexGrow:void 0)??l.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",minWidth:se?void 0:l.minWidth,maxWidth:se?void 0:l.maxWidth};if(F)return c.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:te,role:"presentation","data-field":l.field,"data-colindex":a});const ce=Z=>{C||(t&&t({row:i,field:l.field,value:r,colDef:l,rowIndex:d,colIndex:a}),h?.(Z))},z=()=>{C||!b||(n?n(l.field,r):E?.())},re=l.renderEditCell,K=y!=null,J=["ogx__cell",`ogx__cell--align-${l.align||"left"}`,g&&"ogx__cell--selected",m&&"ogx__cell--focused",m&&x&&"ogx__cell--focus-visible",l.type&&`ogx__cell--type-${l.type}`,K&&"ogx__cell--pinned",K&&`ogx__cell--pinned-${y}`,K&&f&&`ogx__cell--pinned-${y}-${y==="left"?"last":"first"}`,C&&"ogx__cell--editing",S&&S>1&&"ogx__cell--spanned",(_&Yo)!==0&&"ogx__cell--range",(_&Gi)!==0&&"ogx__cell--range-top",(_&Hi)!==0&&"ogx__cell--range-bottom",(_&Bi)!==0&&"ogx__cell--range-left",(_&Wi)!==0&&"ogx__cell--range-right",R].filter(Boolean).join(" "),ae=S||1,fe={...te,position:K?"sticky":void 0,zIndex:l.zIndex??(K?3:void 0),padding:C?0:void 0};return ae>1&&(fe.height=`calc(var(--height) * ${ae} - var(--border-width, 1px))`,fe.zIndex=10,K&&(fe.zIndex=40)),K&&p!==void 0&&(y==="left"?fe.left=p:fe.right=p),c.jsxs("div",{className:J,style:fe,onClick:ce,onDoubleClick:z,role:"gridcell","aria-colindex":u??a+1,"aria-readonly":!b||void 0,tabIndex:-1,"data-field":l.field,"data-colindex":a,...ue>1?{"aria-colspan":ue}:{},...ae>1?{"aria-rowspan":ae}:{},...(_&Yo)!==0?{"aria-selected":!0}:{},children:[c.jsx("div",{className:"ogx__cell-content",children:C&&(o||N)&&k?re?c.jsx(Ft,{field:l.field,resetKey:i,renderFn:()=>re({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I,onValueChange:L,onCommit:W,onCancel:H})}):c.jsx(Uf,{value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I,onValueChange:L,onCommit:W,onCancel:H}):Q!==void 0?c.jsx(Ft,{field:l.field,resetKey:i,renderFn:()=>{throw Q}}):l.renderCell?c.jsx(Ft,{field:l.field,resetKey:ie,renderFn:()=>l.renderCell({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:d,colIndex:a,rowMeta:I})}):l.type==="image"&&typeof r=="string"&&r!==""?c.jsx("img",{className:"ogx__cell-image",src:r,alt:l.headerName??l.field,loading:"lazy"}):v}),(_&Vi)!==0&&!C&&c.jsx("div",{className:"ogx__cell-fill-handle","aria-hidden":"true"})]})}const rs=s.memo(Rf),qf=({className:e="",...t})=>c.jsx("button",{type:"button",className:`ogx-drag-handle ${e}`,"aria-label":"Drag to reorder row",...t,children:c.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:c.jsx("path",{d:"M11 18c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zm-2-8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"})})});function Xf(e){const{rowId:t,content:n,height:o,isExpanded:r,onHeightChange:i,id:l,colSpan:d}=e,a=s.useRef(null),u=o==="auto";if(s.useLayoutEffect(()=>{const h=a.current;if(!h||!u||!r||!i)return;const w=()=>{h.getClientRects().length!==0&&i(t,h.offsetHeight)};if(w(),typeof ResizeObserver>"u")return;const y=new ResizeObserver(w);return y.observe(h),()=>y.disconnect()},[u,r,i,t]),!r)return null;const g={height:u?"auto":`${o}px`,overflow:u?"visible":"auto"};return c.jsx("div",{ref:a,className:"ogx__detail-panel",style:g,role:"row",id:l,children:c.jsx("div",{className:"ogx__detail-panel-content",role:"gridcell","aria-colspan":d,children:n})})}const yr=12;function Yf(e,t,n,o){let r=0,i=0,l=0;for(let d=t;d<e.length&&l<n;d++){const a=e[d];if(a.isSpacer)break;r+=Nt(a,o),i+=a.flex??0,l++}return{spannedByColSpan:!1,cellProps:{colSpan:l,width:r,flexGrow:i}}}function Jf(e){const{row:t,rowId:n,columns:o,rowIndex:r,isSelected:i=!1,checkboxSelection:l=!1,onRowClick:d,onRowDoubleClick:a,onCellClick:u,onSelectionChange:g,columnWidths:h={},pinnedColumns:w,pinnedRows:y,hasDetailPanel:p=!1,isDetailPanelExpanded:f=!1,onDetailPanelToggle:m,detailPanelContent:x,detailPanelHeight:b=Lo,onDetailPanelHeightChange:C,pinCheckboxColumn:E=!0,pinExpandColumn:k=!0,rowReordering:N=!1,onDragStart:M,onDragOver:S,onDragEnd:F,onDrop:I,isDragging:A,isDragOver:_,editingCell:L,onEditStart:D,onEditStop:v,onEditCellValueChange:V,isCellEditable:R,focusedCellField:Q,isFocusVisible:G,colspanMap:W,rowSpanningCaches:H,rowHeight:ie=52,rowMeta:oe,columnIndexMap:ue,ariaRowIndex:se,cellRange:U}=e,te=n??t.id,ce=s.useId(),z=s.useId(),re=s.useMemo(()=>Eo(o,h,w,l,E,p,k,N),[o,h,w,l,E,p,k,N]),K=s.useMemo(()=>Mo(o,w),[o,w]),J=oe?.hasChildren===!0,ae=oe?.isGroupRow===!0,fe=p&&!ae,Z=!ae&&!Xe(te),$=s.useCallback((de,ye)=>{D?.({id:te,field:de,value:ye})},[te,D]),O=s.useCallback((de,ye)=>{V?.({id:te,field:de,value:ye})},[V,te]),P=s.useCallback((de,ye)=>{v?.({cancel:de,id:te,field:ye})},[v,te]);if(t._isSkeleton){const de=Math.max(o.length,5);return c.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:ie,minHeight:ie},children:Array.from({length:de}).map((ye,Ee)=>c.jsx("div",{className:"ogx__skeleton-cell",children:c.jsx("div",{className:"ogx__skeleton-bar"})},Ee))})}const T=de=>{de.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||d?.({row:t,id:te,rowIndex:r})},X=de=>{de.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||a?.({row:t,id:te,rowIndex:r})},B=de=>{de.stopPropagation(),g?.(te,de.target.checked)},ee=de=>{de.stopPropagation(),m?.(te)},q=N?1:0,Y=p?q+1:q,ne=l?Y+1:Y,me=ne,j=ue?.size??o.filter(de=>!de.isSpacer).length,le=oe!==void 0,we=oe?.hasChildren===!0,pe=oi(te,y),he=pe==="top",Ce=pe==="bottom",be=["ogx__row",i&&"ogx__row--selected",r%2===0&&"ogx__row--even",r%2===1&&"ogx__row--odd",he&&"ogx__row--pinned-top",Ce&&"ogx__row--pinned-bottom",A&&"ogx__row--dragging",_&&"ogx__row--drag-over",J&&"ogx__row--group",oe?.isGroupFooter&&"ogx__row--group-footer"].filter(Boolean).join(" ");return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:be,onClick:T,onDoubleClick:a?X:void 0,role:"row","aria-rowindex":se??r+2,"aria-selected":i,"aria-level":le?(oe?.treeDepth??0)+1:void 0,"aria-expanded":we?oe?.isExpanded===!0:void 0,"data-rowindex":r,onDragOver:S?S(te):void 0,onDrop:I?I(te):void 0,style:{maxHeight:`${ie}px`,minHeight:`${ie}px`,"--height":`${ie}px`,"--border-width":"1px"},children:[N&&c.jsx("div",{className:`ogx__cell ogx__cell--drag-handle ${Q==="__reorder_col__"?"ogx__cell--focused":""} ${Q==="__reorder_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":M?"Drag to reorder row":void 0,"aria-colindex":q,"data-field":"__reorder_col__",tabIndex:-1,style:{position:"sticky",left:0,zIndex:yr},draggable:!!M,onDragStart:M?M(te):void 0,onDragEnd:F,onClick:de=>de.stopPropagation(),children:M&&c.jsx(qf,{})}),p&&c.jsx("div",{className:`ogx__cell ogx__cell--expand ${k?"ogx__cell--pinned-left":""} ${Q==="__expand_col__"?"ogx__cell--focused":""} ${Q==="__expand_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":fe?f?"Collapse row details":"Expand row details":void 0,"aria-expanded":fe?f:void 0,"aria-controls":fe&&f?z:void 0,"aria-colindex":Y,"data-field":"__expand_col__",style:{position:k?"sticky":void 0,left:k?N?48:0:void 0,zIndex:k?yr:void 0},tabIndex:-1,onClick:de=>{de.stopPropagation(),u?.({row:t,field:"__expand_col__",value:f,colDef:{field:"__expand_col__",width:48},rowIndex:r,colIndex:-1})},children:fe&&c.jsx(nr,{isExpanded:f,onClick:ee,variant:"plus-minus",tabIndex:-1})}),l&&c.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${E?"ogx__cell--pinned-left":""} ${Q==="__checkbox_col__"?"ogx__cell--focused":""} ${Q==="__checkbox_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-colindex":ne,"data-field":"__checkbox_col__",style:{position:E?"sticky":void 0,left:E?(N?48:0)+(p&&k?48:0):void 0,zIndex:E?yr:void 0},tabIndex:-1,onClick:de=>{de.stopPropagation(),u?.({row:t,field:"__checkbox_col__",value:i,colDef:{field:"__checkbox_col__",width:48},rowIndex:r,colIndex:-1})},children:Z&&c.jsx(bt,{id:ce,name:`ogx-select-row-${te}`,checked:i,onChange:B,onClick:de=>de.stopPropagation(),"aria-label":i?`Deselect row ${te}`:`Select row ${te}`,tabIndex:-1,onMouseDown:de=>de.preventDefault()})}),o.map((de,ye)=>{if(de.isSpacer)return c.jsx("div",{style:{width:de.width,minWidth:de.width,flexShrink:0},"aria-hidden":"true"},de.field);let Ee,Me;ae?Ee=t[de.field]:{value:Ee,error:Me}=ii(t,de.field,de);const Ne=ue?.get(de.field)??ye,Ie=h[de.field]??de.width,Se=ct(de.field,w),Oe=!!D&&Fo({row:t,field:de.field,value:Ee,colDef:de,rowIndex:r,colIndex:Ne,rowMeta:oe},R),ge=L?.id===te&&L?.field===de.field,ve=ge?L?.value:Ee,ke=W?.get(te)?.[de.field],xe=ke&&!ke.spannedByColSpan&&ke.cellProps.colSpan>1?Yf(o,Ne,ke.cellProps.colSpan,h):ke,je=xe&&!xe.spannedByColSpan?o[Ne+xe.cellProps.colSpan-1]?.field??de.field:de.field,nt=Se==="right"?je:de.field,nn=Se?re[nt]:void 0,Mn=Se==="left"&&je===K.lastLeft||Se==="right"&&de.field===K.firstRight,ot=H?.spannedCells[te]?.[de.field],lo=H?.hiddenCells[te]?.[de.field]||!1,so=U&&!lo&&de.field!==Di?cc(U,Ne,xe&&!xe.spannedByColSpan?xe.cellProps.colSpan:1,ot??1):void 0;return c.jsx(rs,{value:ve,row:t,colDef:de,rowIndex:r,colIndex:Ne,ariaColIndex:me+Ne+1,isSelected:i,onCellClick:u,width:Ie,pinnedPosition:Se,pinnedOffset:nn,isPinnedEdge:Mn,isFocused:Q===de.field,isFocusVisible:G,isEditable:Oe,isEditing:ge,onCellEditStart:$,onEditStop:P,onCellValueChange:O,colSpanInfo:xe,rowSpan:ot,isHiddenByRowSpan:lo,rowMeta:oe,valueError:Me,rangeFlags:so},de.field)})]}),fe&&c.jsx(Xf,{id:z,colSpan:me+j,row:t,rowId:te,rowIndex:r,content:x,height:b,isExpanded:f,onHeightChange:C})]})}function Zf(e,t){const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(o==="cellRange"){if(!ac(e.cellRange,t.cellRange))return!1}else if(!Object.is(e[o],t[o]))return!1;return!0}const Zn=s.memo(Jf,Zf);function is({getContent:e,params:t}){return c.jsx(Ft,{field:"detail panel",renderFn:()=>e(t),resetKey:t.row})}const Qf=e=>e.id;function ls({rows:e,position:t,columns:n,selectedRowIds:o,checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:d,onSelectionChange:a,columnWidths:u,pinnedColumns:g,pinnedRows:h,hasDetailPanel:w,expandedRowIds:y,getDetailPanelContent:p,getDetailPanelHeight:f,onDetailPanelToggle:m,onDetailPanelHeightChange:x,pinCheckboxColumn:b,pinExpandColumn:C,focusedCell:E,colspanMap:k,rowSpanningCaches:N,rowHeight:M,rowMetaMap:S,getRowId:F=Qf,rowIndexOffset:I=0,ariaRowIndexBase:A,columnIndexMap:_,editingHandlers:L,isCellEditable:D,rowReordering:v=!1,cellRange:V,cellRangeHasRowSpan:R=!1,fillHandle:Q}){return e.length===0?null:c.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:e.map((G,W)=>{const H=F(G),ie=I+W;return c.jsx(Zn,{row:G,rowId:H,columns:n,rowIndex:ie,ariaRowIndex:A!==void 0?A+W:void 0,columnIndexMap:_,isSelected:o.has(H),checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:d,onSelectionChange:a,columnWidths:u,pinnedColumns:g,pinnedRows:h,hasDetailPanel:w,isDetailPanelExpanded:y.has(H),detailPanelContent:y.has(H)&&p?c.jsx(is,{getContent:p,params:{row:G,id:H,rowIndex:ie}}):null,detailPanelHeight:y.has(H)?Ao(Po(f,{row:G,id:H,rowIndex:ie})):void 0,onDetailPanelHeightChange:x,onDetailPanelToggle:m,pinCheckboxColumn:b,pinExpandColumn:C,focusedCellField:E?.id===H?E.field:null,colspanMap:k,rowSpanningCaches:N,rowHeight:M,rowMeta:S.get(H),editingCell:L?.editingCell,onEditStart:L?.startCellEdit,onEditStop:L?.stopCellEdit,onEditCellValueChange:L?.setEditCellValue,isCellEditable:D,rowReordering:v,cellRange:$i(V,ie,R,Q)},H)})})}const eg=({columns:e,rowHeight:t,checkboxSelection:n=!1,hasDetailPanel:o=!1,rowReordering:r=!1})=>c.jsxs("div",{className:"ogx__row ogx__skeleton-row",style:{height:t},role:"row",children:[n&&c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:c.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),o&&c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:c.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),r&&c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:c.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),e.map((i,l)=>{const d=typeof i.width=="number"?i.width:150,a=Math.min(d*.7,d-20);return c.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:d,minWidth:i.minWidth,maxWidth:i.maxWidth,left:i.left,right:i.right,position:i.isSpacer?"relative":i.pinned?"sticky":"relative",zIndex:i.zIndex},children:!i.isSpacer&&c.jsx("div",{className:"ogx-skeleton-box",style:{width:a,height:16,borderRadius:4}})},i.field||l)})]});function tg({virtualContainerHeight:e,offsetTop:t,effectiveLoading:n,visibleRows:o,baseColumns:r,virtualColumns:i,viewportWidth:l,checkboxSelection:d,hasDetailPanel:a,rowReordering:u,rowHeight:g,selectedRowIds:h,onRowClick:w,onRowDoubleClick:y,onCellClick:p,onSelectionChange:f,columnWidths:m,pinnedColumns:x,expandedRowIds:b,getDetailPanelContent:C,getDetailPanelHeight:E,onDetailPanelToggle:k,onDetailPanelHeightChange:N,pinCheckboxColumn:M,pinExpandColumn:S,rowReorderHandlers:F,editingHandlers:I,isCellEditable:A,focusedCell:_,colspanMap:L,rowSpanningCaches:D,paginationMode:v,dataSourceLoading:V,sortedUnpinnedRowCount:R,infiniteScrollSkeletonCount:Q,unpinnedRowsLength:G,lastRenderedRowIndex:W,rowMetaMap:H,loadingOverlay:ie,ariaRowIndexOffset:oe,columnIndexMap:ue,cellRange:se,cellRangeHasRowSpan:U=!1,fillHandle:te}){const ce=r.length>0?r:(()=>{const K=(l||1e3)-(d?48:0)-(a?48:0)-(u?48:0),J=150,ae=Math.max(1,Math.ceil(K/J));return Array.from({length:ae},(fe,Z)=>({field:`placeholder_${Z}`,headerName:"",width:J}))})(),z=o.filter(K=>!K.pinned),re=v==="infinite"&&V&&R>0&&W>=G-1;return c.jsx("div",{className:"ogx__virtual-container",style:{height:`${e}px`},role:"presentation",children:c.jsxs("div",{className:"ogx__rows",style:{transform:`translateY(${t}px)`},role:"rowgroup",children:[n&&o.length===0&&ie?c.jsx("div",{className:"ogx__loading-overlay",style:{width:l||void 0},children:ie}):n&&o.length===0?Array.from({length:10}).map((K,J)=>c.jsx(eg,{columns:ce,rowHeight:g,checkboxSelection:d,hasDetailPanel:a,rowReordering:u},`skeleton-${J}`)):z.map(({row:K,id:J,rowIndex:ae})=>c.jsx(Zn,{row:K,rowId:J,columns:i,rowIndex:ae,ariaRowIndex:oe!==void 0?ae+oe:void 0,columnIndexMap:ue,isSelected:h.has(J),checkboxSelection:d,onRowClick:w,onRowDoubleClick:y,onCellClick:p,onSelectionChange:f,columnWidths:m,pinnedColumns:x,hasDetailPanel:a,isDetailPanelExpanded:b.has(J),detailPanelContent:b.has(J)&&C?c.jsx(is,{getContent:C,params:{row:K,id:J,rowIndex:ae}}):null,detailPanelHeight:b.has(J)?Ao(Po(E,{row:K,id:J,rowIndex:ae})):void 0,onDetailPanelHeightChange:N,onDetailPanelToggle:k,pinCheckboxColumn:M,pinExpandColumn:S,rowReordering:u,onDragStart:F.canReorderRow(J)?F.onDragStart:void 0,onDragOver:F.onDragOver,onDragEnd:F.onDragEnd,onDrop:F.onDrop,isDragging:F.draggedRowId===J,isDragOver:F.dragOverRowId===J,editingCell:I.editingCell,onEditStart:I.startCellEdit,onEditStop:I.stopCellEdit,onEditCellValueChange:I.setEditCellValue,isCellEditable:A,focusedCellField:_!=null&&_.id===J?_.field:null,colspanMap:L,rowSpanningCaches:D,rowHeight:g,rowMeta:H.get(J),cellRange:$i(se,ae,U,te)},J)),re&&c.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:Q}).map((K,J)=>c.jsx(Zn,{row:{id:`__skeleton_${J}__`,_isSkeleton:!0},columns:i,rowIndex:G+J,rowHeight:g},`__skeleton_${J}__`))})]})})}function ng(){return c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function og(){return c.jsxs("svg",{className:"ogx-column-visibility-panel__drag-handle",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[c.jsx("circle",{cx:"9",cy:"5",r:"1.5"}),c.jsx("circle",{cx:"15",cy:"5",r:"1.5"}),c.jsx("circle",{cx:"9",cy:"12",r:"1.5"}),c.jsx("circle",{cx:"15",cy:"12",r:"1.5"}),c.jsx("circle",{cx:"9",cy:"19",r:"1.5"}),c.jsx("circle",{cx:"15",cy:"19",r:"1.5"})]})}function Cr(e){const{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:d,showNonHideableColumns:a}=e,[u,g]=s.useState(""),h=s.useId(),[w,y]=s.useState(null),p=s.useRef(null),f=s.useMemo(()=>t.filter(S=>S.hideable!==!1),[t]),m=f.every(S=>n.has(S.field)),x=s.useMemo(()=>{const S=a?t:f;if(!u)return S;const F=u.toLowerCase();return S.filter(I=>(I.headerName||I.field).toLowerCase().includes(F))},[t,f,u,a]),b=S=>{S.target.checked?r():i()},C=S=>F=>{p.current=S,F.dataTransfer.effectAllowed="move",F.dataTransfer.setDragImage(F.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},E=S=>F=>{F.preventDefault(),F.dataTransfer.dropEffect="move",S!==p.current&&y(S)},k=()=>{y(null)},N=S=>F=>{F.preventDefault();const I=p.current;y(null),p.current=null,I&&I!==S&&l&&l(I,S)},M=()=>{y(null),p.current=null};return c.jsxs("div",{className:"ogx-column-visibility-panel",children:[c.jsx("div",{className:"ogx-column-visibility-panel__search-section",children:c.jsxs("div",{className:"ogx-column-visibility-panel__search-container",children:[c.jsx(ng,{}),c.jsx(Qe,{autoComplete:"off",inputClassName:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:u,onChange:S=>g(S.target.value)})]})}),c.jsx("div",{className:"ogx-column-visibility-panel__list",children:x.map((S,F)=>{const I=`${h}-col-${F}`,A=n.has(S.field),_=S.hideable!==!1,L=w===S.field,D=!!l&&!u;return c.jsxs("div",{className:["ogx-column-visibility-panel__item",!_&&"ogx-column-visibility-panel__item--disabled",L&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:D,onDragOver:D?E(S.field):void 0,onDragLeave:D?k:void 0,onDrop:D?N(S.field):void 0,onDragEnd:D?M:void 0,children:[D&&c.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:C(S.field),title:"Drag to reorder",children:c.jsx(og,{})}),c.jsxs("div",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:_?"pointer":"not-allowed"},children:[c.jsx(bt,{id:I,checked:A,onChange:v=>o(S.field,v.target.checked),disabled:!_}),c.jsx("label",{htmlFor:I,className:"ogx-column-visibility-panel__label",children:S.headerName||S.field})]})]},S.field)})}),c.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[c.jsxs("div",{className:"ogx-column-visibility-panel__item",children:[c.jsx(bt,{id:`${h}-all`,checked:m,onChange:b}),c.jsx("label",{htmlFor:`${h}-all`,className:"ogx-column-visibility-panel__label",children:"Show/Hide All"})]}),c.jsx("button",{type:"button",className:"ogx-column-visibility-panel__reset-btn",onClick:()=>{r(),d?.()},children:"Reset"})]})]})}function rg({isOpen:e,containerRef:t,panelRef:n,columns:o,columnVisibilityModel:r,disableColumnReorder:i,onClose:l,onColumnVisibilityChange:d,onColumnMove:a,onColumnOrderReset:u,columnGroupingModel:g}){const[h,w]=s.useState(null);if(s.useLayoutEffect(()=>{if(!e||!t.current)return;const p=t.current.getBoundingClientRect();w({top:p.top+8,right:Ot()-p.right+8,target:t.current.closest(".ogx-theme-provider")||document.body})},[e,t]),!e||!h)return null;const y=i?void 0:(p,f)=>{ir(g,p,f)&&a(p,f)};return mt.createPortal(c.jsxs("div",{ref:n,style:{position:"fixed",top:h.top,right:h.right,zIndex:9999,display:"inline-block"},children:[c.jsx("button",{type:"button",onClick:l,style:{position:"absolute",top:-12,right:-12,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",background:"#334155",color:"#fff",border:"none",borderRadius:"50%",cursor:"pointer",fontSize:14,lineHeight:1,zIndex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.2)"},"aria-label":"Close",children:"×"}),c.jsx(Cr,{columns:o,visibleColumns:new Set(o.filter(p=>r[p.field]!==!1).map(p=>p.field)),onVisibilityChange:(p,f)=>{d({...r,[p]:f})},onShowAll:()=>{const p={...r};o.forEach(f=>{f.hideable!==!1&&(p[f.field]=!0)}),d(p)},onHideAll:()=>{const p={...r};o.forEach(f=>{f.hideable!==!1&&(p[f.field]=!1)}),d(p)},onColumnReorder:y,onColumnOrderReset:i?void 0:u})]}),h.target)}function ig(e){const{baseColumns:t,pinnedColumns:n,hasGroupingColumn:o,groupingColDef:r,isTreeData:i,getTreeDataPath:l}=e,d=s.useMemo(()=>o?{...n,left:["__group__",...(n?.left??[]).filter(u=>u!=="__group__")]}:n,[o,n]);return{activeColumns:s.useMemo(()=>o?[{headerName:"Group",width:220,...i&&l?{valueGetter:({row:u})=>{const g=l(u);return g[g.length-1]}}:{},...r,field:"__group__",hideable:!1,sortable:!1,filterable:!1,pinnable:!1,exportable:!1},...t]:t,[r,o,i,l,t]),effectivePinnedColumns:d}}function lg(e){return e.id}function sg(e){const t=s.useCallback(r=>e.get(r)??r.id,[e]),n=s.useRef(t);s.useLayoutEffect(()=>{n.current=t});const o=s.useCallback(r=>n.current(r),[]);return{getRowIdOf:t,getRowIdOfInEvents:o}}function ag(e,t){s.useLayoutEffect(()=>{e&&(e.current=t.current)},[e,t])}function cg(e){const{hierarchyHandlers:t,pinnedTopRows:n,sortedUnpinnedRows:o,pinnedBottomRows:r,rowMetaMap:i,getRowId:l,hierarchyField:d,dataRows:a}=e,u=t?.getVisibleRows({expandAll:!0,labelField:d});if(!u)return[...n,...o,...r];const g=a?new Set(a):null;return u.filter(h=>!i.get(l(h))?.isGroupRow&&(!g||g.has(h)))}function dg(e,t){if(e===t)return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;const o=e,r=t;return n.every(i=>Object.prototype.hasOwnProperty.call(t,i)&&Object.is(o[i],r[i]))}function ug(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>dg(n,t[o]))}function fg(e){const[t,n]=s.useState(e),o=ug(t,e);return o||n(e),o?t:e}function gg(e){const{rows:t,getRowId:n,rowMetaMap:o,columns:r,aggregationModel:i,aggregationResult:l,isSubtotalHidden:d}=e,a=Object.keys(i).length>0,u=new Map(r.map(y=>[y.field,y])),g=[],h=[],w=y=>{for(;h.length>0&&h[h.length-1].header.depth>=y;){const p=h.pop();a&&!d?.(p.id)&&g.push({type:"group-subtotal",depth:p.header.depth,groupField:p.header.groupField,groupValue:p.header.groupValue,groupLabel:p.header.groupLabel,aggregatedValues:Hn(p.leaves,i,u,"getGroupedExportRows")})}};for(const y of t){const p=n(y),f=o.get(p);if(!f?.isGroupFooter)if(f?.isGroupRow){const m=f.treeDepth??0;w(m);const x={type:"group-header",depth:m,groupField:f.groupingField,groupValue:f.groupingValue,groupLabel:f.groupLabel};g.push(x),h.push({id:p,header:x,leaves:[]})}else g.push({type:"leaf",depth:f?.treeDepth??h.length,row:y}),h.forEach(m=>m.leaves.push(y))}return w(0),a&&l&&g.push({type:"grand-total",depth:0,aggregatedValues:l}),g}function pg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=()=>n.current;t.current.getAggregationResult=()=>o().hasAggregation?o().aggregationResult:null,t.current.getAggregationModel=()=>o().hasAggregation?o().aggregationModel:null,t.current.getGroupedExportRows=()=>{const{hasAggregation:r,aggregationResult:i,aggregationModel:l,isRowGrouping:d,rowGroupingHandlers:a,rowMetaMap:u,columns:g,getRowId:h,hierarchyField:w}=o();return d?gg({rows:a.getVisibleRows({expandAll:!0,labelField:w})??[],getRowId:h,rowMetaMap:u,columns:g,aggregationModel:l,aggregationResult:r&&a.rootAggregationPosition!==null?i:null,isSubtotalHidden:y=>a.aggregationPositions.get(y)===null}):null}},[t])}const hg=new Set(["__group__","__check__","__actions__"]);function Dt(e){return e.filter(t=>t.exportable!==!1&&!t.isSpacer&&!Ze(t.field)&&!hg.has(t.field))}function yt(e){return!!e&&e.length>0}function ss(e,t,n=o=>o.id){const o=new Set(t);return e.filter(r=>o.has(n(r)))}function yn(e,t,n){return yt(t)?ss(e,t,n):e}function Cn(e,t){return!!e&&e.length>0&&!yt(t)}function Yt(e,t,n,o,r){if(!o)return null;if(!t||!r||Object.keys(r).length===0)return o;const i=new Map(n.map(l=>[l.field,l]));return Hn(e,r,i,"export")}function vn(e,t){const n=e[t.field];return t.valueGetter?t.valueGetter({row:e,field:t.field,value:n}):n}function _n(e,t,n){if(!t.valueFormatter)return Io(n,t);if(n==null)try{return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}catch{return""}return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}function vr(e,t,n,o){return n==null?"":Bn(n,t??"",e,o)}function Jt(e,t){return t?`${e}: ${t}`:e}function as(e,t){const n={};return t.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o.field)&&(n[o.field]=e[o.field])}),n}const mg=/^[=+\-@\t\r]/,wg=/^[-+]?(?=[\d.,\s]*\d)[\d.,\s]*%?$/;function Qn(e,t=!1){return t||!mg.test(e)||wg.test(e)?e:`'${e}`}function Ct(e){return typeof e=="number"||typeof e=="bigint"||typeof e=="boolean"||e instanceof Date}function Te(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function bg(e){let t=0,n=e.length;for(;t<n&&e[t]==="'";)t++;for(;n>t&&e[n-1]==="'";)n--;return e.slice(t,n)}const xg=/[\\/?*:[\]]/g,cs=31;function _r(e,t=new Set){let n=bg(String(e??"").replace(xg,"-").trim()).trim();n||(n="Sheet"),n=n.slice(0,cs).trim();const o=i=>t.has(i.toLowerCase())||i.toLowerCase()==="history";let r=n;for(let i=2;o(r);i++){const l=` (${i})`;r=`${n.slice(0,cs-l.length).trim()}${l}`}return t.add(r.toLowerCase()),r}const yg=new Set([Je,Pt,At]),Cg=/[\t\n\r"]/;function Sr(e){return Cg.test(e)?`"${e.replace(/"/g,'""')}"`:e}function vg(e){return Dt(e).filter(t=>!yg.has(t.field))}function _g(e,t){const n=t.map(r=>Sr(r.headerName||r.field)).join(" "),o=e.map(r=>t.map(i=>Sr(_n(r,i,Le(r,i.field,i)))).join(" "));return[n,...o].join(`
|
|
6
|
+
`)}function Sg(e,t){const n=Le(e,t.field,t);try{return _n(e,t,n)}catch{return n==null?"":String(n)}}function kg(e,t,n){const o=new Array(e.length);for(let r=0;r<e.length;r++){const i=e[r],l=new Array(t.length);for(let d=0;d<t.length;d++){const a=t[d];l[d]=n?.(i,a)?"":Sr(Sg(i,a))}o[r]=l.join(" ")}return o.join(`
|
|
7
|
+
`)}function ds(e){if(typeof document.execCommand!="function")return!1;const t=document.activeElement instanceof HTMLElement?document.activeElement:null,n=document.getSelection(),o=[];if(n)for(let l=0;l<n.rangeCount;l++)o.push(n.getRangeAt(l));const r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.setAttribute("aria-hidden","true"),r.style.cssText="position:fixed;top:-9999px;left:-9999px;opacity:0;",document.body.appendChild(r);let i=!1;try{r.focus({preventScroll:!0}),r.select(),i=document.execCommand("copy")}finally{document.body.removeChild(r),t&&t.isConnected&&t.focus({preventScroll:!0}),n&&(n.removeAllRanges(),o.forEach(l=>n.addRange(l)))}return i}async function kr(e){const t=typeof navigator<"u"?navigator.clipboard:void 0;if(t&&typeof t.writeText=="function")try{await t.writeText(e);return}catch(n){if(ds(e))return;throw n}if(!ds(e))throw new Error("Clipboard API not available and fallback failed.")}function Eg(e){if(!(e.ctrlKey||e.metaKey)||e.altKey||e.shiftKey)return!1;const t=e.key??"";return t.toLowerCase()==="c"?!0:e.code==="KeyC"&&!/^[a-z]$/i.test(t)}function Mg(e){const t=s.useRef(e);s.useLayoutEffect(()=>{t.current=e});const n=s.useCallback(async()=>{const{getSelectedRowIds:r,getColumns:i,getRows:l,getRowId:d}=t.current,a=new Set(r());if(a.size===0)return;const u=l().filter(h=>a.has(d(h)));if(u.length===0)return;const g=_g(u,vg(i()));await kr(g)},[]),o=!!e.disableKeyboardShortcut;return s.useEffect(()=>{if(o)return;const r=i=>{if(i.defaultPrevented||!Eg(i))return;const l=document.activeElement,d=l?.tagName.toLowerCase(),a=l?.type;if(d==="input"&&a!=="checkbox"&&a!=="radio"||d==="textarea"||d==="select"||l?.isContentEditable)return;const{getRootElement:u}=t.current;if(u){const y=u();if(!y||!l||!y.contains(l))return}const g=window.getSelection();if(g&&!g.isCollapsed&&g.toString()!=="")return;const{getShortcutText:h}=t.current;(h?()=>{const y=h();return y===null?Promise.resolve():kr(y)}:n)().catch(y=>{console.error("[OpenGridX] Failed to copy to clipboard:",y)})};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[n,o]),{copySelectedRows:n}}function Ng(e){const{apiRef:t,columns:n,getRowId:o,containerRef:r,disableKeyboardShortcut:i,getCellRangeCopyText:l}=e,d=s.useCallback(()=>r.current,[r]),{copySelectedRows:a}=Mg({getSelectedRowIds:()=>t.current.getSelectedRows(),getColumns:()=>n,getRows:()=>t.current.getAllFilteredRows(),getRowId:o,getRootElement:d,disableKeyboardShortcut:i,getShortcutText:l});s.useLayoutEffect(()=>{t.current.copySelectedRows=a},[a,t])}function Ig(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{t.current.scrollToIndexes=({rowIndex:o,colIndex:r})=>{const{viewportRef:i,layout:l,rowHeight:d}=n.current,a=i.current;if(a&&(o!==void 0&&o>=0&&Gn(a,o,l.cumulativeHeights,l.pinnedBottomHeight,d),r!==void 0&&r>=0)){const g=[...l.leftPinnedCols,...l.unpinnedColsWithWidth,...l.rightPinnedCols][r];if(!g)return;To(a,l.unpinnedColsWithWidth.findIndex(h=>h.field===g.field),l)}}},[t])}const Lg=".ogx";function us(e,t){const n=t.style.cssText;t.style.width="max-content",t.style.minWidth="0",t.style.maxWidth="none",t.style.flex="none";const o=t.getBoundingClientRect().width;t.style.cssText=n;const r=getComputedStyle(e),i=[r.paddingLeft,r.paddingRight,r.borderLeftWidth,r.borderRightWidth].reduce((l,d)=>l+(parseFloat(d)||0),0);return o+i}function Ag(e,t){const n=typeof CSS<"u"&&CSS.escape?CSS.escape(t):t.replace(/["\\]/g,"\\$&"),o=l=>l.closest(Lg)===e;let r=null;const i=l=>{r=r===null?l:Math.max(r,l)};return e.querySelectorAll(`[role="columnheader"][data-field="${n}"]`).forEach(l=>{if(!o(l))return;const d=l.querySelector(".ogx__header-cell-content");d&&i(us(l,d))}),e.querySelectorAll(`[role="gridcell"][data-field="${n}"]`).forEach(l=>{if(!o(l)||l.hasAttribute("aria-colspan"))return;const d=l.querySelector(":scope > .ogx__cell-content");d&&i(us(l,d))}),r===null?null:Math.ceil(r)}function Pg(e,t,n){return Math.max(t??ul,Math.min(n??1/0,e))}function Tg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useCallback(i=>{const{containerRef:l,columns:d,onColumnResize:a}=n.current,u=l.current;if(!u)return;const g=[];for(const h of i??d.map(w=>w.field)){const w=d.find(p=>p.field===h);if(!w||w.resizable===!1)continue;const y=Ag(u,h);y!==null&&g.push([h,Pg(y,w.minWidth,w.maxWidth)])}for(const[h,w]of g)a(h,w)},[]),r=s.useCallback(i=>o([i]),[o]);return s.useLayoutEffect(()=>{t.current.autosizeColumn=r,t.current.autosizeColumns=o},[t,r,o]),r}const fs="ogx--range-dragging",vt=32,Fg=40,Og=300;function gs(e,t){if(!e||e.nodeType!==1)return null;const n=e.closest(".ogx__cell[data-field]");if(!n||n.closest(".ogx__viewport")!==t)return null;const o=n.closest(".ogx__detail-panel");if(o&&t.contains(o))return null;const r=n.closest('[role="row"][data-rowindex]');if(!r)return null;const i=Number(r.getAttribute("data-rowindex")),l=n.dataset.field;return!Number.isInteger(i)||!l?null:{rowIndex:i,field:l,element:n}}function Er(e){const t=e.getSelection();t&&t.rangeCount>0&&t.removeAllRanges()}const ps=(e,t,n)=>Math.min(Math.max(e,t),n),eo=e=>Math.min(Fg,Math.max(2,Math.round(e/2)));function Dg(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Copying ${e} cells. For ranges this large, exportToCsv or exportToExcel is the better tool.`)}function $g(e){const{enabled:t,model:n,allRenderableRows:o,getRowId:r,navigationColumns:i,columnIndexMap:l,spanning:d,rowMetaMap:a,localeText:u,showStats:g}=e,h=t&&n.length>0?n[0]:null,w=s.useMemo(()=>t?i.filter(O=>Ye(O.field)):[],[t,i]),y=s.useMemo(()=>{if(!d.hasColSpan&&!d.hasRowSpan)return;const{colspanMap:O,rowSpanningCaches:P,getSpanOrigin:T}=d;return{getSpanOrigin:T,getColSpan:(X,B)=>{const ee=O.get(X)?.[B];return ee&&!ee.spannedByColSpan?ee.cellProps.colSpan:1},getRowSpan:(X,B)=>P.spannedCells[X]?.[B]??1}},[d]),p=s.useMemo(()=>{if(!t)return null;const O=o.map(r),P=new Map;O.forEach((X,B)=>{P.has(X)||P.set(X,B)});const T=w.map(X=>X.field);return{rowIds:O,rowIndexById:P,fields:T,colIndexByField:new Map(T.map((X,B)=>[X,B])),spans:y}},[t,o,r,w,y]),f=s.useMemo(()=>h&&p?Kn(h,p):null,[h,p]),m=f!==null&&Tt(f)>1,x=s.useMemo(()=>{if(!f||!m||!p)return null;const O=l.get(p.fields[f.left]),P=l.get(p.fields[f.right]);return O===void 0||P===void 0?null:{top:f.top,bottom:f.bottom,left:O,right:P}},[f,m,p,l]),b=s.useCallback(O=>Xe(O,a),[a]),C=s.useCallback((O,P,T)=>{if(p)for(let X=O.top;X<=O.bottom;X++){const B=o[X],ee=p.rowIds[X];if(!(!B||b(ee))){P(B,ee);for(let q=O.left;q<=O.right;q++){const Y=w[q],ne=y?.getSpanOrigin(ee,Y.field);T(B,ee,Y,ne!=null&&(ne.rowId!==ee||ne.field!==Y.field))}}}},[p,o,w,y,b]),E={...e,range:h,resolved:f,context:p,rangeColumns:w,forEachCell:C},k=s.useRef(E);s.useLayoutEffect(()=>{k.current=E});const N=s.useRef(null),M=s.useCallback(O=>{N.current=O},[]),S=s.useCallback(()=>{const{getPendingModel:O,model:P}=k.current;return O()??P},[]),F=s.useCallback(()=>{const{context:O,range:P,resolved:T,enabled:X}=k.current,B=X?S()[0]??null:null;return!B||!O?{range:null,resolved:null}:B===P?{range:B,resolved:T}:{range:B,resolved:Kn(B,O)}},[S]),I=s.useCallback((O,P)=>{if(!k.current.enabled)return;const T=O.length>1?O.slice(0,1):O;ic(T,S())||k.current.onModelChange(T,P)},[S]),A=s.useCallback((O,P,T)=>{I([{anchor:O,head:P}],T)},[I]),_=s.useCallback((O,P)=>{const{viewportRef:T,layout:X,rowHeight:B,pinnedTopRowCount:ee}=k.current,q=T.current;q&&(Gn(q,O-ee,X.cumulativeHeights,X.pinnedBottomHeight,B),To(q,X.unpinnedColsWithWidth.findIndex(Y=>Y.field===P),X))},[]),L=s.useCallback((O,P,T,X)=>{const{context:B}=k.current,{range:ee,resolved:q}=F();if(!B||X.id===null||!Ye(X.field))return!1;const Y=B.rowIndexById.get(X.id),ne=B.colIndexByField.get(X.field);if(Y===void 0||ne===void 0)return!1;const me=ee&&q&&wt(ee.anchor,{id:X.id,field:X.field})?{range:ee,resolved:q}:null,j=me?me.range.anchor:{id:X.id,field:X.field},le=me?.resolved??Kn({anchor:j,head:j},B);if(!le)return!1;const we=sc(le,O,P,T,B.rowIds.length-1,B.fields.length-1);if(!we)return!0;const pe={id:B.rowIds[we.row],field:B.fields[we.col]};return A(j,pe,"keyboard"),_(we.row,pe.field),!0},[F,A,_]),D=s.useCallback(()=>{const{range:O,resolved:P}=F();return!O||!P||Tt(P)<=1?!1:(A(O.anchor,O.anchor,"keyboard"),!0)},[F,A]),v=s.useCallback(()=>{const{context:O}=k.current;return!O||O.rowIds.length===0||O.fields.length===0?!1:(A({id:O.rowIds[0],field:O.fields[0]},{id:O.rowIds[O.rowIds.length-1],field:O.fields[O.fields.length-1]},"selectAll"),!0)},[A]),V=s.useCallback(()=>{const{context:O}=k.current,{range:P,resolved:T}=F();if(!O)return null;if(T)return T;if(P)return null;const X=N.current;return!X||X.id===null||!Ye(X.field)?null:Kn({anchor:{id:X.id,field:X.field},head:{id:X.id,field:X.field}},O)},[F]),R=s.useCallback(()=>{const O=V();if(!O)return null;const{rangeColumns:P,forEachCell:T}=k.current,X=Tt(O);X>uc&&Dg(X);const B=[];if(T(O,me=>{B.push(me)},()=>{}),B.length===0)return null;const ee=P.slice(O.left,O.right+1),q=k.current.context?.spans,Y=k.current.getRowId;return kg(B,ee,q?(me,j)=>{const le=Y(me),we=q.getSpanOrigin(le,j.field);return we!==null&&(we.rowId!==le||we.field!==j.field)}:void 0)},[V]),Q=s.useCallback(()=>{const{forEachCell:O}=k.current,{resolved:P}=F();if(!P)return[];const T=[];return O(P,()=>{},(X,B,ee,q)=>{q||T.push({id:B,field:ee.field,value:Le(X,ee.field,ee)})}),T},[F]),G=s.useRef(null),W=s.useRef(!1);s.useEffect(()=>()=>G.current?.stop(),[]);const H=s.useCallback((O,P,T)=>{const X=k.current.context;if(!X)return null;const B=O.ownerDocument;if(typeof B.elementFromPoint!="function")return null;const ee=gs(B.elementFromPoint(P,T),O);if(!ee)return null;const q=X.rowIds[ee.rowIndex];if(q===void 0)return null;const Y=Ye(ee.field)?ee.field:X.fields[0];return Y===void 0?null:{id:q,field:Y}},[]),ie=s.useCallback((O,P)=>{const{context:T,layout:X,pinnedTopRowCount:B}=k.current,ee=X.cumulativeHeights;if(!T||ee.length===0||O<0)return null;let q=0,Y=ee.length-1;for(;q<Y;){const me=q+Y>>1;ee[me]>O?Y=me:q=me+1}const ne=T.rowIds[q+B];return ne===void 0?null:{id:ne,field:P}},[]),oe=s.useRef(()=>{}),ue=s.useCallback(O=>{const P=G.current,T=k.current.viewportRef.current;if(!P||!T)return;P.frame=0;const{layout:X}=k.current,B=T.getBoundingClientRect(),ee=T.clientWidth,q=T.clientHeight,Y=T.querySelector(":scope > .ogx__content > .ogx__sticky-top"),ne=T.querySelector(":scope > .ogx__content > .ogx__sticky-bottom"),me=Y?.querySelector(":scope > .ogx__header-wrap"),j=Y?Y.getBoundingClientRect().bottom:B.top,le=Math.min(B.top+q,ne?ne.getBoundingClientRect().top:B.top+q),we=me?me.getBoundingClientRect().bottom:j,pe=B.left+X.pinnedSystemColumnsWidth+X.leftWidth,he=B.left+ee-X.rightWidth,Ce=ps(P.x,B.left+1,B.left+ee-2);let be=P.y;(be<B.top||be>B.top+q||be<we)&&(be=ps(be,j+1,Math.max(j+1,le-2)));const de=typeof T.ownerDocument.elementFromPoint=="function",Ee=H(T,Ce,be)??(de&&P.moved?ie(be-B.top-(Y?Y.getBoundingClientRect().height:0)+T.scrollTop,P.head.field):null);if(Ee&&!wt(Ee,P.head)&&(P.head=Ee,!P.moved&&!wt(Ee,P.anchor)&&(P.moved=!0,k.current.containerRef.current?.classList.add(fs),Er(T.ownerDocument)),P.onTrack||A(P.anchor,Ee,"pointer")),P.onTrack&&P.onTrack(P.head,P.x,P.y),!O)return;const Me=P.y<j||P.y>le||P.x<B.left||P.x>B.left+ee;if(!P.moved&&!Me)return;let Ne=0,Ie=0;P.y<j+vt?Ne=-eo(j+vt-P.y):P.y>le-vt&&(Ne=eo(P.y-(le-vt))),P.x<pe+vt?Ie=-eo(pe+vt-P.x):P.x>he-vt&&(Ie=eo(P.x-(he-vt)));const Se=Ne<0&&T.scrollTop>0||Ne>0&&T.scrollTop+q<T.scrollHeight-1,Oe=Ie<0&&T.scrollLeft>0||Ie>0&&T.scrollLeft+ee<T.scrollWidth-1;!Se&&!Oe||(Se&&(T.scrollTop+=Ne),Oe&&(T.scrollLeft+=Ie),P.frame=requestAnimationFrame(()=>oe.current(!0)))},[H,ie,A]);s.useLayoutEffect(()=>{oe.current=ue},[ue]);const se=s.useCallback((O,P,T,X,B,ee)=>{G.current?.stop();const q=ee?"pointermove":"mousemove",Y=ee?"pointerup":"mouseup",ne=de=>!ee||de.pointerId===ee.pointerId,me=de=>{const ye=G.current;if(!(!ye||!ne(de))){if(de.buttons===0){ye.stop();return}ye.x=de.clientX,ye.y=de.clientY,ye.moved&&(de.preventDefault(),Er(B)),ye.frame||(ye.frame=requestAnimationFrame(()=>ue(!0)))}},j=de=>{const ye=G.current;if(!ye||!ne(de))return;ye.x=de.clientX,ye.y=de.clientY,ue(!1);const Ee=ye.moved;ye.stop(!1,de.altKey),Ee&&Er(B),Ee&&(W.current=!0,setTimeout(()=>{W.current=!1},0))},le=de=>{ne(de)&&G.current?.stop()},we=de=>{de.key!=="Escape"||!G.current||(de.preventDefault(),de.stopPropagation(),G.current.stop())},pe=B.defaultView,he=()=>G.current?.stop();let Ce=!1;const be={anchor:O,head:P,x:T,y:X,frame:0,moved:!1,onTrack:ee?.onTrack,stop:(de=!0,ye=!1)=>{be.frame&&cancelAnimationFrame(be.frame),be.frame=0,B.removeEventListener(q,me,!0),B.removeEventListener(Y,j,!0),ee&&(B.removeEventListener("pointercancel",le,!0),B.removeEventListener("keydown",we,!0)),pe?.removeEventListener("blur",he),k.current.containerRef.current?.classList.remove(fs),G.current===be&&(G.current=null),Ce||(Ce=!0,ee&&ee.onEnd({cancelled:de,altKey:ye}))}};G.current=be,B.addEventListener(q,me,!0),B.addEventListener(Y,j,!0),ee&&(B.addEventListener("pointercancel",le,!0),B.addEventListener("keydown",we,!0)),pe?.addEventListener("blur",he)},[ue]),U=s.useCallback(O=>{const P=k.current.viewportRef.current;if(!P||!k.current.enabled)return;const{start:T,x:X,y:B,pointerId:ee,onTrack:q,onEnd:Y}=O;se(T,T,X,B,P.ownerDocument,{pointerId:ee,onTrack:q,onEnd:Y})},[se]),te=s.useCallback(O=>{if(O.button!==0||O.defaultPrevented)return;const{context:P}=k.current;if(!P)return;const T=O.currentTarget,X=gs(O.target,T);if(!X||!Ye(X.field)||O.target.closest?.(".ogx__cell-fill-handle")||X.element.classList.contains("ogx__cell--editing")||Pi(O.target))return;const B=P.rowIds[X.rowIndex];if(B===void 0)return;const ee={id:B,field:X.field};let q=ee;if(O.shiftKey){const Y=S()[0],ne=N.current;Y&&P.rowIndexById.has(Y.anchor.id)&&P.colIndexByField.has(Y.anchor.field)?q=Y.anchor:ne&&ne.id!==null&&Ye(ne.field)&&(q={id:ne.id,field:ne.field}),O.preventDefault(),W.current=!0;const me=T.ownerDocument;T.contains(me.activeElement)||T.focus({preventScroll:!0})}if(A(q,ee,"pointer"),se(q,ee,O.clientX,O.clientY,T.ownerDocument),O.shiftKey){const Y=G.current;Y&&!wt(q,ee)&&(Y.moved=!0)}},[S,A,se]),ce=s.useCallback(O=>{W.current&&(W.current=!1,O.stopPropagation(),O.preventDefault())},[]),z=f?f.right-f.left+1:0,re=f?f.bottom-f.top+1:0,K=u?.cellSelectionAnnouncement??dc,J=m?K(re*z,re,z):"",[ae,fe]=s.useState("");s.useEffect(()=>{if(!t)return;const O=setTimeout(()=>fe(J),Og);return()=>clearTimeout(O)},[t,J]);const Z=s.useMemo(()=>{if(!g||!f||!m)return null;const O=[];C(f,()=>{},(T,X,B,ee)=>{ee||O.push(Le(T,B.field,B))});const P=O.filter(T=>typeof T=="number"&&!Number.isNaN(T));return{cellCount:Tt(f),rowCount:f.bottom-f.top+1,columnCount:f.right-f.left+1,count:Lt.count(O),numericCount:P.length,sum:P.length?Lt.sum(P):null,average:P.length?Lt.avg(P):null}},[g,f,m,C]),$=s.useMemo(()=>t?{extendSelection:L,collapseSelection:D,selectAllCells:v}:void 0,[t,L,D,v]);return{enabled:t,range:h,resolved:f,displayRange:x,hasRowSpan:d.hasRowSpan,handleMouseDown:t?te:void 0,handleClickCapture:t?ce:void 0,extendSelection:L,collapseSelection:D,selectAllCells:v,keyboard:$,getCopyText:R,getSelectedCells:Q,announcement:t?ae:"",stats:Z,reportFocus:M,setModel:I,getCurrentRange:F,startTrackedDrag:U}}function Gg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useRef(null),r=s.useRef(null),i=s.useRef(null),{selection:l,model:d,focusedCell:a,setFocusedCell:u,containerRef:g}=e,h=l.range?.anchor??null,w=l.resolved?.anchorRow;s.useLayoutEffect(()=>{l.reportFocus(a);const y=!wt(o.current,h),p=!qo(r.current,a);if(o.current=h,r.current=a,!!l.enabled){if(l.range&&!l.resolved){i.current!==d&&(i.current=d,l.setModel([],"dataChange"));return}if(y&&h){(!a||a.id!==h.id||a.field!==h.field)&&u({id:h.id,field:h.field,rowIndex:w});return}if(p&&a&&a.id!==null&&Ye(a.field)&&!wt(h,{id:a.id,field:a.field})){const f={id:a.id,field:a.field},m=g.current?.classList.contains("ogx--kb")??!1;l.setModel([{anchor:f,head:f}],m?"keyboard":"pointer")}}},[l,d,h,w,a,u,g]),s.useLayoutEffect(()=>{const y=t.current,p=()=>n.current;y.getCellSelectionModel=()=>{const{selection:f,getPendingModel:m,model:x}=p();return f.enabled?m()??x:[]},y.setCellSelectionModel=f=>{p().selection.setModel(f,"api")},y.selectCellRange=(f,m)=>{p().selection.setModel([{anchor:f,head:m}],"api")},y.clearCellSelection=()=>{p().selection.setModel([],"clear")},y.getSelectedCells=()=>p().selection.getSelectedCells(),y.copySelectedCells=async()=>{const{selection:f}=p();if(!f.enabled)return;const m=f.getCopyText();m!==null&&await kr(m)}},[t])}function hs({count:e,sum:t,average:n}){return c.jsxs("div",{className:"ogx__cell-selection-stats",children:[c.jsxs("span",{className:"ogx__cell-selection-stat",children:[c.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Count"}),c.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"count",children:e.toLocaleString()})]}),t!==null&&c.jsxs("span",{className:"ogx__cell-selection-stat",children:[c.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Sum"}),c.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"sum",children:pn(t,"sum")})]}),n!==null&&c.jsxs("span",{className:"ogx__cell-selection-stat",children:[c.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Average"}),c.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"average",children:pn(n,"avg")})]})]})}function Hg({stats:e,apiRef:t,slot:n,slotProps:o}){const r=n??hs;return c.jsx("div",{className:"ogx__cell-selection-stats-area","aria-hidden":e?void 0:!0,children:e&&c.jsx(r,{apiRef:t,...e,...o})})}function Bg(e){return s.useCallback(t=>{e.current?.classList.toggle("ogx--kb",t)},[e])}function Wg(e){const{ensureGridFocus:t,setKeyboardMode:n,setFocusedCell:o,getRowId:r,onCellClick:i}=e,l=s.useCallback(a=>{t(),n(!1),o({id:r(a.row),field:a.field,rowIndex:a.rowIndex}),i?.(a)},[i,n,o,t,r]),d=s.useCallback(a=>{t(),o({id:null,field:a}),n(!1)},[t,o,n]);return{handleCellClick:l,handleHeaderClick:d}}function Vg({paginationSlot:e,paginationSlotProps:t,page:n,paginationModel:o,rowCount:r,pageSizeOptions:i,onPaginationModelChange:l,localeText:d}){const a=e||wr;return c.jsx(a,{page:n,pageSize:o.pageSize,rowCount:r,pageSizeOptions:i,onPageChange:u=>l({...o,page:u}),onPageSizeChange:u=>l({...o,pageSize:u,page:0}),localeText:Ui(d),...t})}function zg({loading:e,error:t,noRowsLabel:n,filteredRowCount:o,dataRowCount:r,filterModel:i,cellSelectionAnnouncement:l,aiAssistantAnnouncement:d}){return c.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[e?"Loading data...":"",t?`Error: ${cl(t)}`:"",!e&&!t&&(o===0?n:i&&((i.quickFilterValues?.length||0)>0||(i.items?.length||0)>0)?`${r} ${r===1?"row":"rows"} found`:""),l?c.jsxs("span",{className:"ogx-aria-live-status__cells",children:[" ",l]}):null,d?c.jsxs("span",{className:"ogx-aria-live-status__ai",children:[" ",d]}):null]})}function Kg(e){const{headerRowCount:t,pinnedTopCount:n,pinnedBottomCount:o,pageRowCount:r,totalCenterRowCount:i,pageOffset:l}=e;return{rowCount:t+n+i+o,topBase:t+1,centerOffset:t+l+1,bottomBase:t+n+i+1,bottomRowIndexOffset:n+r}}function jg(e){const{columnGroupingModel:t,headerFilterRow:n=!1,pinnedTopCount:o,pinnedBottomCount:r,pagination:i,paginationMode:l,paginationModel:d,paginationRowCount:a,paginatedUnpinnedRowCount:u,sortedUnpinnedRowCount:g}=e,{page:h,pageSize:w}=d;return s.useMemo(()=>Kg({headerRowCount:1+fl(t)+(n?1:0),pinnedTopCount:o,pinnedBottomCount:r,pageRowCount:i?u:g,totalCenterRowCount:i&&l==="server"?Math.max(a,u):g,pageOffset:i?h*w:0}),[t,n,o,r,i,u,g,l,a,h,w])}function Ug(e){const{toolbar:t,toolbarSlotProps:n,apiRef:o,orderedColumns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:d,pivotMode:a,pivotModelProp:u,onPivotModelChangeProp:g,pivotModel:h,onPivotModelChange:w,filterModel:y,onFilterModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:m,disableColumnReorder:x,columnGroupingModel:b,moveColumn:C,resetColumnOrder:E,forceColumnsOpen:k,onColumnsPanelClose:N,aiAssistantEnabled:M=!1,aiAssistantOpen:S=!1,onAiAssistantToggle:F,aiAssistantLabel:I,forceFiltersOpen:A,onFiltersPanelClose:_}=e;return s.useMemo(()=>t?{apiRef:o,columns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:d,...a||u||g?{pivotModel:h,onPivotModelChange:w}:{},filterModel:y,onFilterModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:m,onColumnReorder:x?void 0:(D,v)=>{ir(b,D,v)&&C(D,v)},onColumnOrderReset:x?void 0:E,forceColumnsOpen:k,onColumnsPanelClose:N,...M&&F?{onAiAssistantToggle:F,aiAssistantOpen:S,...I?{aiAssistantLabel:I}:{}}:{},forceFiltersOpen:A,onFiltersPanelClose:_,...n}:null,[t,x,C,E,r,o,i,l,d,a,u,g,h,w,y,p,f,m,k,N,n,b,M,S,F,I,A,_])}const Rg=Symbol.for("opengridx.ai.validated");function qg(e){return typeof e=="object"&&e!==null&&e[Rg]===!0}const to=["filter","sort","grouping","aggregation","pivot","columnVisibility"],Mr={filter:"filterModel",sort:"sortModel",grouping:"rowGroupingModel",aggregation:"aggregationModel",pivot:"pivotModel",columnVisibility:"columnVisibilityModel"};function ms(e){return to.map(t=>Mr[t]).filter(t=>e[t]!==void 0)}function Xg(e,t){const n={},o=[];for(const r of to){const i=Mr[r];e[i]!==void 0&&(t.includes(r)?Object.assign(n,{[i]:e[i]}):o.push({path:i,message:"Part not allowed"}))}return{state:n,errors:o}}function Yg(e,t){const n=e[t];if(Array.isArray(n))return n.length===0;if(t==="filterModel"){const o=e.filterModel;return!o||(o.items??[]).length===0&&(o.quickFilterValues??[]).length===0}if(t==="pivotModel"){const o=e.pivotModel;return!o||o.rowFields.length===0&&o.columnFields.length===0&&o.valueFields.length===0}return typeof n=="object"&&n!==null&&Object.keys(n).length===0}function Jg(e){let t=e.length;for(const n of[".","["]){const o=e.indexOf(n);o>=0&&o<t&&(t=o)}return e.slice(0,t)}function Zg(e,t){const n=new Set(t.map(r=>Jg(typeof r.path=="string"?r.path:""))),o={};for(const r of ms(e))n.has(r)&&Yg(e,r)||Object.assign(o,{[r]:e[r]});return o}function Qg(e,t){const n={};for(const o of ms(e))Object.assign(n,{[o]:t[o]});return n}function ws(e,t){const n={};for(const o of to.map(r=>Mr[r]))!(o in t)&&e[o]===void 0||(e[o]===void 0?Object.assign(n,{[o]:t[o]}):o==="columnVisibilityModel"?n.columnVisibilityModel={...t.columnVisibilityModel,...e.columnVisibilityModel}:Object.assign(n,{[o]:e[o]}));return n}function Nr(e,t){t.filterModel&&e.setFilterModel(t.filterModel),t.sortModel&&e.setSortModel(t.sortModel),t.rowGroupingModel&&e.setRowGroupingModel(t.rowGroupingModel),t.aggregationModel&&e.setAggregationModel(t.aggregationModel),t.pivotModel&&e.setPivotModel(t.pivotModel),t.columnVisibilityModel&&e.setColumnVisibilityModel(t.columnVisibilityModel)}function bs(e){return Array.isArray(e)?e.map(bs).join(", "):e instanceof Date?e.toISOString().slice(0,10):e==null?"":String(e)}function xs(e,t){return"items"in e?`(${e.items.map(n=>xs(n,t)).join(` ${e.logicOperator} `)})`:[t(e.field),e.operator,bs(e.value)].filter(Boolean).join(" ")}const ep={sum:"Sum",avg:"Average",count:"Count",min:"Min",max:"Max",unique:"Unique"};function ys(e,t){const n=[],{filterModel:o,sortModel:r,rowGroupingModel:i,aggregationModel:l,pivotModel:d,columnVisibilityModel:a}=e;if(o){const u=o.items??[];u.forEach((h,w)=>n.push({id:`filter:${w}`,part:"filter",label:xs(h,t)}));const g=o.quickFilterValues??[];g.length>0&&n.push({id:"filter:quick",part:"filter",label:`Search: ${g.join(" ")}`}),u.length===0&&g.length===0&&n.push({id:"filter:clear",part:"filter",label:"No filters"})}if(r&&(r.forEach((u,g)=>n.push({id:`sort:${g}`,part:"sort",label:`Sort: ${t(u.field)}, ${u.sort==="desc"?"descending":"ascending"}`})),r.length===0&&n.push({id:"sort:clear",part:"sort",label:"No sorting"})),i&&(i.forEach((u,g)=>n.push({id:`grouping:${g}`,part:"grouping",label:`Group: ${t(u)}`})),i.length===0&&n.push({id:"grouping:clear",part:"grouping",label:"No grouping"})),l){const u=Object.keys(l);u.forEach(g=>{const h=l[g];n.push({id:`aggregation:${g}`,part:"aggregation",label:`${ep[h]??h}: ${t(g)}`})}),u.length===0&&n.push({id:"aggregation:clear",part:"aggregation",label:"No summaries"})}if(d){const u=[...d.rowFields,...d.columnFields,...d.valueFields.map(g=>g.field)];n.push({id:"pivot",part:"pivot",label:u.length>0?`Pivot: ${u.map(t).join(", ")}`:"No pivot"})}if(a)for(const u of Object.keys(a))n.push({id:`columnVisibility:${u}`,part:"columnVisibility",label:`${a[u]?"Show":"Hide"}: ${t(u)}`});return n}function tp(e,t){const n={...e},o=t.indexOf(":"),r=o<0?t:t.slice(0,o),i=o<0?"":t.slice(o+1),l=Number(i);if(r==="filter"&&n.filterModel){const d={...n.filterModel};i==="quick"?delete d.quickFilterValues:i==="clear"?d.items=[]:d.items=(d.items??[]).filter((a,u)=>u!==l),(d.items??[]).length===0&&(d.quickFilterValues??[]).length===0?delete n.filterModel:n.filterModel=d}else if(r==="sort"&&n.sortModel)n.sortModel=n.sortModel.filter((d,a)=>a!==l),(n.sortModel.length===0||i==="clear")&&delete n.sortModel;else if(r==="grouping"&&n.rowGroupingModel)n.rowGroupingModel=n.rowGroupingModel.filter((d,a)=>a!==l),(n.rowGroupingModel.length===0||i==="clear")&&delete n.rowGroupingModel;else if(r==="aggregation"&&n.aggregationModel){const d={...n.aggregationModel};delete d[i],Object.keys(d).length===0?delete n.aggregationModel:n.aggregationModel=d}else if(r==="columnVisibility"&&n.columnVisibilityModel){const d={...n.columnVisibilityModel};delete d[i],Object.keys(d).length===0?delete n.columnVisibilityModel:n.columnVisibilityModel=d}else r==="pivot"&&delete n.pivotModel;return n}const np="Ask about this table…",op=[],no=[],Cs="The reply was not validated";function rp(){return typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)}function ip(e){return typeof e=="object"&&e!==null&&e.name==="AbortError"}function lp(e){return e instanceof Error&&e.message?e.message:"Unknown error"}function sp(e,t){const n=e===0?"No changes":`Applied ${e} ${e===1?"change":"changes"}`;return t>0?`${n}, ${t} ignored`:n}function vs(e,t,n){if(!e)return;const o=We(()=>e(t));!o.ok&&process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] ${n} threw.`,o.error)}function ap(e){const{apiRef:t,options:n,columns:o}=e,r=!!n,[i,l]=s.useState(!1),[d,a]=s.useState("idle"),[u,g]=s.useState(""),[h,w]=s.useState(null),[y,p]=s.useState(no),[f,m]=s.useState(null),[x,b]=s.useState([]),C=s.useRef(null),E=s.useRef(null),k=s.useRef({params:e,applied:f,history:x,open:i});s.useLayoutEffect(()=>{k.current={params:e,applied:f,history:x,open:i}});const N=s.useMemo(()=>{const W=new Map(o.map(H=>[H.field,H.headerName||H.field]));return H=>W.get(H)??H},[o]),M=s.useMemo(()=>f?ys(f.state,N):[],[f,N]),S=s.useCallback(()=>{const W=C.current;C.current=null,W&&W.abort()},[]);s.useEffect(()=>S,[S]);const F=s.useCallback(W=>{if(!k.current.params.options)return;const H=typeof document>"u"?null:document.activeElement;E.current=W??(H instanceof HTMLElement?H:null),l(!0)},[]),I=s.useCallback(()=>{C.current&&(S(),a("stopped"),g("Stopped")),l(!1);const W=E.current;E.current=null,W&&W.isConnected&&W.focus()},[S]),A=s.useCallback(W=>{k.current.open?I():F(W)},[F,I]),_=s.useCallback((W,H)=>{a("error"),g(W),w(null),p(no),vs(k.current.params.onError,H,"onAiAssistantError")},[]),L=s.useCallback((W,H)=>{const{params:ie}=k.current;if(!(typeof H=="object"&&H!==null)||!qg(H.state)){process.env.NODE_ENV!=="production"&&console.warn("[OpenGridX] aiAssistant: the onPrompt result was not applied because its state was not validated. Return the result of createGridAiPromptHandler, or pass the model reply through validateGridAiState (from @opencorestack/opengridx/ai) and return its state."),_(Cs,new Error(Cs));return}const ue=Xg(H.state,ie.options?.parts??to),se=[...Array.isArray(H.errors)?H.errors:[],...ue.errors],U=Zg(ue.state,se),te=t.current,ce=Qg(U,te.getGridAiState());Nr(te,ws(U,ce)),m({state:U,previous:ce}),p(se),w(typeof H.message=="string"&&H.message?H.message:null),b(z=>[...z,{prompt:W,applied:U}]),a("applied"),g(sp(ys(U,z=>z).length,se.length)),vs(ie.onApply,H,"onAiAssistantApply")},[t,_]),D=s.useCallback(W=>{const H=W.trim(),{params:ie,history:oe}=k.current,ue=ie.options?.onPrompt;if(!H||!ue)return;S();const se=new AbortController;C.current=se,a("running"),g("Thinking…"),w(null),p(no);const U={currentState:t.current.getGridAiState(),history:oe,signal:se.signal},te=We(()=>ue(H,U));(te.ok?Promise.resolve(te.value):Promise.reject(te.error)).then(z=>{C.current===se&&(C.current=null,L(H,z))},z=>{if(C.current===se){if(C.current=null,se.signal.aborted||ip(z)){a("stopped"),g("Stopped");return}_(`The assistant could not answer: ${lp(z)}`,z)}})},[t,S,L,_]),v=s.useCallback(()=>{C.current&&(S(),a("stopped"),g("Stopped"))},[S]),V=s.useCallback(()=>{const W=k.current.applied;W&&(Nr(t.current,W.previous),m(null),p(no),w(null),a("idle"),g("Undone"))},[t]),R=s.useCallback(W=>{const H=k.current.applied;if(!H)return;const ie=tp(H.state,W);Nr(t.current,ws(ie,H.previous)),m({state:ie,previous:H.previous}),g("Change removed")},[t]);s.useLayoutEffect(()=>{const W=t.current;W.openAiAssistant=()=>F(),W.closeAiAssistant=()=>{k.current.open&&I()}},[t,F,I]);const Q=r&&i,G=s.useMemo(()=>!Q||!n?null:{status:d,statusText:u,message:h,errors:y,chips:M,history:x,suggestions:n.suggestions??op,placeholder:n.placeholder??np,voiceAvailable:n.voice!==!1&&rp(),canUndo:f!==null,submit:D,stop:v,undo:V,removeChip:R,close:I},[Q,n,d,u,h,y,M,x,f,D,v,V,R,I]);return{enabled:r,open:Q,openPanel:F,togglePanel:A,closePanel:I,panelProps:G,announcement:r?u:""}}function cp(){if(typeof window>"u")return null;const e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function dp(e){const[t,n]=s.useState(!1),o=s.useRef(null),r=s.useRef(e);s.useLayoutEffect(()=>{r.current=e}),s.useEffect(()=>()=>{const l=o.current;o.current=null,l&&We(()=>l.abort())},[]);const i=s.useCallback(()=>{const l=o.current;if(l){We(()=>l.stop());return}const d=cp();if(!d)return;const a=We(()=>new d);if(!a.ok)return;const u=a.value;u.lang=typeof navigator>"u"?"en-US":navigator.language,u.interimResults=!1,u.maxAlternatives=1,u.onresult=h=>{const w=h.results[0],y=w&&w[0]?w[0].transcript:"";y&&r.current(y)};const g=()=>{o.current===u&&(o.current=null),n(!1)};u.onend=g,u.onerror=g,o.current=u,n(!0),We(()=>u.start()).ok||g()},[]);return{listening:t,toggle:i}}function _s(){return c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:[c.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),c.jsx("path",{d:"M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8z"})]})}function up(){return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",focusable:"false",children:[c.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),c.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}function fp(e){const{status:t,statusText:n,message:o,errors:r,chips:i,history:l,suggestions:d,placeholder:a,voiceAvailable:u,canUndo:g,submit:h,stop:w,undo:y,removeChip:p,close:f}=e,[m,x]=s.useState(""),b=s.useRef(null),C=dp(x),E=t==="running";s.useEffect(()=>{b.current&&b.current.focus()},[]);const k=S=>{x(S),h(S)},N=S=>()=>{S(),b.current&&b.current.focus()},M=S=>{S.preventDefault(),E||h(m)};return c.jsxs("div",{className:"ogx-ai-panel",role:"dialog","aria-label":"Ask AI",children:[c.jsxs("div",{className:"ogx-ai-panel__header",children:[c.jsxs("span",{className:"ogx-ai-panel__title",children:[c.jsx(_s,{}),"Ask AI"]}),c.jsx(tt,{size:"small",className:"ogx-ai-panel__close","aria-label":"Close",onClick:f,children:"×"})]}),c.jsxs("form",{className:"ogx-ai-panel__form",onSubmit:M,children:[c.jsx(Qe,{ref:b,className:"ogx-ai-panel__input",value:m,placeholder:a,"aria-label":"Prompt",autoComplete:"off",onChange:S=>x(S.target.value)}),u&&c.jsx(tt,{size:"small",variant:"outlined",className:`ogx-ai-panel__mic${C.listening?" ogx-ai-panel__mic--on":""}`,"aria-label":C.listening?"Stop dictation":"Dictate a prompt","aria-pressed":C.listening,onClick:C.toggle,children:c.jsx(up,{})}),E?c.jsx(tt,{size:"small",variant:"outlined",onClick:N(w),children:"Stop"},"stop"):c.jsx(tt,{size:"small",variant:"contained",color:"primary",type:"submit",disabled:m.trim()==="",children:"Ask"},"ask")]}),d.length>0&&c.jsx("div",{className:"ogx-ai-panel__suggestions","aria-label":"Suggestions",role:"group",children:d.map(S=>c.jsx("button",{type:"button",className:"ogx-ai-panel__suggestion",disabled:E,onClick:()=>k(S),children:S},S))}),n&&c.jsx("div",{className:`ogx-ai-panel__status ogx-ai-panel__status--${t}`,children:n}),o&&c.jsx("p",{className:"ogx-ai-panel__message",children:o}),(i.length>0||g)&&c.jsxs("div",{className:"ogx-ai-panel__changes",children:[c.jsx("ul",{className:"ogx-ai-panel__chips","aria-label":"Applied changes",children:i.map(S=>c.jsxs("li",{className:"ogx-ai-chip","data-part":S.part,children:[c.jsx("span",{className:"ogx-ai-chip__label",children:S.label}),c.jsx("button",{type:"button",className:"ogx-ai-chip__remove","aria-label":`Remove ${S.label}`,onClick:N(()=>p(S.id)),children:"×"})]},S.id))}),g&&c.jsx(tt,{size:"small",variant:"outlined",className:"ogx-ai-panel__undo",onClick:N(y),children:"Undo"})]}),r.length>0&&c.jsx("ul",{className:"ogx-ai-panel__errors","aria-label":"Ignored",children:r.map((S,F)=>c.jsx("li",{children:S.path?`Ignored: ${S.message}`:S.message},`${S.path}:${F}`))}),l.length>0&&c.jsxs("div",{className:"ogx-ai-panel__history",children:[c.jsx("div",{className:"ogx-ai-panel__history-title",children:"Earlier"}),c.jsx("ul",{children:l.map((S,F)=>c.jsx("li",{children:c.jsx("button",{type:"button",className:"ogx-ai-panel__history-item",onClick:()=>x(S.prompt),children:S.prompt})},`${F}:${S.prompt}`))})]})]})}function gp({panelProps:e,slot:t,slotProps:n}){const o=r=>{r.key==="Escape"&&(r.stopPropagation(),e.close())};return c.jsx("div",{className:"ogx-ai-anchor",onKeyDown:o,children:t?c.jsx(t,{...e,...n}):c.jsx(fp,{...e})})}function pp(e){const{rows:t,columns:n,getRowId:o,rowHeight:r,headerHeight:i,wrapHeaderText:l=!1,headerFilters:d=!1,headerFilterHeight:a=Hd,autoHeight:u=!1,density:g,checkboxSelection:h=!1,disableRowSelectionOnClick:w=!1,disableMultipleRowSelection:y=!1,disableClipboardCopy:p=!1,cellSelection:f=!1,cellSelectionModel:m,onCellSelectionModelChange:x,showCellSelectionStats:b=!1,disableClipboardPaste:C=!1,disableRangeClear:E=!1,onClipboardPaste:k,onBeforeClipboardPaste:N,undoRedo:M=!1,disableFillHandle:S=!1,onFill:F,onHistoryChange:I,rowSelectionModel:A,onRowSelectionModelChange:_,onRowClick:L,onRowDoubleClick:D,onCellClick:v,filterModel:V,onFilterModelChange:R,sortModel:Q,onSortModelChange:G,pagination:W=!1,paginationModel:H,onPaginationModelChange:ie,pageSizeOptions:oe=[10,25,50,100],pinnedColumns:ue,onPinnedColumnsChange:se,pinnedRows:U,getDetailPanelContent:te,getDetailPanelHeight:ce,detailPanelExpandedRowIds:z,onDetailPanelExpandedRowIdsChange:re,pinCheckboxColumn:K=!0,pinExpandColumn:J=!0,disableColumnReorder:ae=!1,columnOrder:fe,onColumnOrderChange:Z,onColumnOrderModelChange:$,height:O,rowReordering:P=!1,onRowOrderChange:T,loading:X=!1,treeData:B=!1,getTreeDataPath:ee,defaultGroupingExpansionDepth:q,groupingColDef:Y,rowGroupingModel:ne,onRowGroupingModelChange:me,aggregationModel:j,onAggregationModelChange:le,getAggregationPosition:we,isCellEditable:pe,processRowUpdate:he,onProcessRowUpdateError:Ce,dataSource:be,multiSort:de=!1,sortingMode:ye="client",filterMode:Ee="client",paginationMode:Me="client",rowCount:Ne,slots:Ie,slotProps:Se,pivotMode:Oe=!1,pivotModel:ge,onPivotModelChange:ve,className:ke="",style:xe,onRowsScrollEnd:je,ariaLabel:nt,initialState:nn,onStateChange:Mn,columnVisibilityModel:ot,onColumnVisibilityModelChange:lo,listView:so=!1,listViewColumn:Nn,columnGroupingModel:In,noRowsLabel:Ph="No Data",localeText:Ln,apiRef:Th,overscanRowCount:Fh=3,aiAssistant:Oh,onAiAssistantApply:Dh,onAiAssistantError:$h}=e,Ar=fg(n),Pr=Ln?.noRowsLabel??Ph,$t=xc({initialState:nn,sortModel:Q,onSortModelChange:G,filterModel:V,onFilterModelChange:R,aggregationModel:j,onAggregationModelChange:le,rowGroupingModel:ne,onRowGroupingModelChange:me,columnVisibilityModel:ot,onColumnVisibilityModelChange:lo,pinnedColumns:ue,onPinnedColumnsChange:se,pivotModel:ge,onPivotModelChange:ve,paginationModel:H,onPaginationModelChange:ie,pageSizeOptions:oe,rowSelectionModel:A,onRowSelectionModelChange:_,density:g,cellSelectionModel:m,onCellSelectionModelChange:x}),{sortModel:ut,handleSortModelChange:Zs,filterModel:ft,handleFilterModelChange:Tr,aggregationModel:Ue,handleAggregationModelChange:Qs,columnVisibilityModel:_t,handleColumnVisibilityModelChange:ao,pinnedColumns:Fr,handlePinnedColumnsChange:Gh,currentPivotModel:Or,handlePivotModelChange:ea,effectivePaginationModel:Re,handlePaginationModelChange:on,selectedRowIds:Hh,handleRowSelectionModelChange:Dr,density:ta,rowGroupingModel:$r,handleRowGroupingModelChange:Bh}=$t,An=Af({rows:t,columns:Ar,pivotMode:Oe,pivotModel:Or,filterModel:ft,sortModel:ut,hasDataSource:!!be,hierarchyRequested:B||$r.length>0}),St=An.isActive,co=d&&!St,{rowReordering:Gt,hierarchyRowGroupingModel:Wh,isTreeDataRequested:Vh,isTreeData:uo,isRowGrouping:rn,isHierarchyEnabled:fo,hasGroupingColumn:zh,pagination:rt,listView:ln}=hc({rowGroupingModel:$r,treeData:B,hasTreeDataPath:!!ee,isPivotActive:St,rowReordering:P,hasGroupingColDef:!!Y,pagination:W,paginationMode:Me,listView:so,hasListViewColumn:!!Nn}),{rowHeight:it,headerHeight:Gr}=Sc({rowHeight:r,headerHeight:i,density:ta}),Kh=An.rows,jh=An.columns,{activeColumns:gt,effectivePinnedColumns:sn}=ig({baseColumns:jh,pinnedColumns:Fr,hasGroupingColumn:zh,groupingColDef:Y,isTreeData:uo,getTreeDataPath:ee}),Hr=dd(gt,_t),[Uh,Rh]=Nf(Ue),qe=s.useRef(null),Ht=s.useRef(null),na=!St&&o||lg,Br=Bg(qe),go=iu({rows:Kh,getRowId:na,columns:gt,rowHeight:it,headerHeight:Gr,columnVisibilityModel:_t,initialState:e.initialState,syncRows:!be}),{state:Fe,apiRef:lt,setRows:qh,replaceRows:Xh,setColumns:Yh,setDimensions:Jh,setDataSourceLoading:Zh,setDataSourceError:Qh,setRowCount:em}=go,{getRowIdOf:Pe,getRowIdOfInEvents:tm}=sg(Fe.rows.idByRow);ag(Th,lt);const nm=Fe.dataSource.loading,kt=X||nm,po=s.useMemo(()=>Fe.rows.allRows.map(ht=>Fe.rows.idRowsLookup.get(ht)),[Fe.rows]),{treeDataHandlers:ho,rowGroupingHandlers:Wr,activeHierarchyHandlers:an,rowMetaMap:Ve}=vu({rows:po,getRowId:Pe,getTreeDataPath:ee,isTreeDataRequested:Vh,isTreeData:uo,columns:gt,rowGroupingModel:Wh,isRowGrouping:rn,aggregationModel:Ue,defaultGroupingExpansionDepth:q,filterModel:ft,sortModel:ut,getAggregationPosition:we,columnLookup:Hr,filterMode:Ee,sortingMode:ye}),Vr=ju(),mo=Su({rowsLookup:Fe.rows.idRowsLookup,columns:gt,processRowUpdate:he,onProcessRowUpdateError:Ce,replaceRows:Xh,onCommitted:Vr.emit}),Pn=_u({rows:po,getRowId:Pe,columns:gt,processRowUpdate:he,onProcessRowUpdateError:Ce,onRowChange:(ht,Am)=>{mo.storeRow(Am,ht)},onCommitted:ht=>Vr.emit(ht,"edit")}),Tn=ld({selectedRowIds:Hh,rowsLookup:Fe.rows.idRowsLookup,rowMetaMap:Ve,enabled:!be&&!St&&Me==="client"&&Ee==="client",onSelectionModelChange:Dr}),oa=kf({dataSource:be,sortModel:ut,filterModel:ft,paginationModel:Re,paginationMode:Me,sortingMode:ye,filterMode:Ee,aggregationModel:Ue,rowGroupingActive:rn,getRowId:na,setRows:qh,setRowCount:em,setDataSourceLoading:Zh,setDataSourceError:Qh,onAggregationResults:Rh,onPaginationModelChange:on});Mf({enabled:uo&&!!be,treeNodes:ho.treeNodes,isGroupExpanded:ho.isGroupExpanded,getNodePath:ho.getNodePath,toggleExpansion:ho.toggleExpansion,fetchChildren:oa.fetchChildren});const{hasDetailPanel:Bt,expandedRowIds:zr,handleDetailPanelToggle:ra,detailPanelHeights:om,reportDetailPanelHeight:rm}=Rc({hasDetailPanel:!!te,controlledExpandedRowIds:z,onDetailPanelExpandedRowIdsChange:re,rowMetaMap:Ve}),{effectiveColumns:ia,hierarchyField:Kr,orderedColumns:jr,visibleOrderedColumns:la,renderOrderedColumns:im,navigationColumns:cn,columnIndexMap:wo,columnWidths:Fn,effectiveColumnOrder:lm,columnReorderHandlers:sm,moveColumn:sa,resetColumnOrder:aa,handleColumnResize:ca}=Gc({activeColumns:gt,isHierarchyEnabled:fo,isRowGrouping:rn,isTreeData:uo,activeHierarchyHandlers:an,columnVisibilityModel:_t,columnOrder:fe,onColumnOrderChange:Z,onColumnOrderModelChange:$,disableColumnReorder:ae,pivotMode:St,checkboxSelection:h,hasDetailPanel:Bt,rowReordering:Gt,initialState:nn,setColumns:Yh,pinnedColumns:sn,getRowId:tm,aggregationModel:Ue,groupingRows:rn?Wr.groupingRows:void 0});Yc({onStateChange:Mn,sortModel:ut,filterModel:ft,effectivePaginationModel:Re,columnWidths:Fn,effectiveColumnOrder:lm,columnVisibilityModel:_t,pinnedColumns:Fr,density:ta});const bo=Ec({effectiveRows:po,activeHierarchyHandlers:an,filterMode:Ee,filterModel:An.pipelineFilterModel,sortModel:An.pipelineSortModel,sortingMode:ye,pagination:rt,paginationMode:Me,effectivePaginationModel:Re,pinnedRows:U,getRowId:Pe,columnLookup:Hr,hierarchyField:Kr}),{filteredRows:da,dataRows:dn,pinnedTopRows:ze,pinnedBottomRows:st,sortedUnpinnedRows:pt,paginatedUnpinnedRows:xo,allRenderableRows:Et}=bo,Ur=rt?xo:pt;ud({paginationModel:Re,currentPage:bo.currentPage,enabled:rt&&!kt&&pt.length>0,onPaginationModelChange:on});const yo=kc({paginationMode:Me,hasDataSource:!!be,dataSourceRowCount:Fe.pagination.rowCount,rowCountProp:Ne,clientRowCount:pt.length}),{rowSelection:Rr,handleRowClick:qr,handleSelectionChange:Xr}=id({dataRows:dn,getRowId:Pe,isPivotActive:St,selectedRowIds:Tn,onSelectionModelChange:Dr,disableMultipleRowSelection:y,disableRowSelectionOnClick:w,isHierarchyEnabled:fo,rowMetaMap:Ve,activeHierarchyHandlers:an,onRowClick:L});cd({apiRef:go.apiRef,sortModel:ut,multiSort:de,onSortModelChange:Zs,filterModel:ft,onFilterModelChange:Tr,paginationModel:Re,onPaginationModelChange:on,selectedRowIds:Tn,getPendingRowSelectionModel:$t.getPendingRowSelectionModel,onRowSelectionModelChange:Dr,disableMultipleRowSelection:y,isSyntheticRowId:ht=>Xe(ht,Ve),getVisibleRows:()=>[...ze,...Ur,...st],getAllFilteredRows:()=>cg({hierarchyHandlers:an,pinnedTopRows:ze,sortedUnpinnedRows:pt,pinnedBottomRows:st,rowMetaMap:Ve,getRowId:Pe,hierarchyField:Kr,dataRows:dn}),visibleColumns:im,rowGroupingModel:$r,onRowGroupingModelChange:Bh,aggregationModel:Ue,onAggregationModelChange:Qs,columnVisibilityModel:_t,onColumnVisibilityModelChange:ao,pivotModel:Or,onPivotModelChange:ea});const am=lu({rows:po,getRowId:Pe,onRowOrderChange:T,rowReordering:Gt}),{aggregationResult:Yr,isLoading:cm}=ts({rows:dn,columns:gt,aggregationModel:St?Pa:Ue,isServerSide:sl({dataSource:be,paginationMode:Me,sortingMode:ye,filterMode:Ee}),dataSource:be,filterModel:ft,sortModel:ut,serverAggregationResults:Uh}),Jr=Object.keys(Ue).length>0&&!St;pg({apiRef:lt,hasAggregation:Jr,aggregationResult:Yr,aggregationModel:Ue,isRowGrouping:rn,rowGroupingHandlers:Wr,rowMetaMap:Ve,columns:gt,getRowId:Pe,hierarchyField:Kr});const De=La({rowHeight:it,pagination:rt,paginatedUnpinnedRows:xo,sortedUnpinnedRows:pt,expandedRowIds:zr,getDetailPanelHeight:ce,detailPanelHeights:om,pinnedTopRowsLength:ze.length,pinnedBottomRowsLength:st.length,pinnedTopRows:ze,pinnedBottomRows:st,visibleOrderedColumns:la,pinnedColumns:sn,columnWidths:Fn,viewportWidth:Fe.dimensions.viewportWidth||1e3,checkboxSelection:h,hasDetailPanel:Bt,rowReordering:Gt,pinCheckboxColumn:K,pinExpandColumn:J,paginationMode:Me,isLoading:Fe.dataSource.loading,pageSize:Re.pageSize,getRowId:Pe}),Mt=bf({pinnedTopRows:ze,centerRows:Ur,pinnedBottomRows:st,columns:la,leftPinnedColumns:De.leftPinnedCols,unpinnedColumns:De.unpinnedColsWithWidth,rightPinnedColumns:De.rightPinnedCols,expandedRowIds:Bt?zr:void 0,rowMetaMap:Ve,getRowId:Pe}),ua=s.useMemo(()=>[...De.leftPinnedCols,...De.unpinnedColsWithWidth,...De.rightPinnedCols],[De.leftPinnedCols,De.unpinnedColsWithWidth,De.rightPinnedCols]),Ge=$g({enabled:f&&!ln,model:$t.cellSelectionModel,onModelChange:$t.handleCellSelectionModelChange,getPendingModel:$t.getPendingCellSelectionModel,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,columnIndexMap:wo,spanning:Mt,rowMetaMap:Ve,layout:De,rowHeight:it,pinnedTopRowCount:ze.length,viewportRef:Ht,containerRef:qe,localeText:Ln,showStats:b});Ng({apiRef:lt,columns:ua,getRowId:Pe,containerRef:qe,disableKeyboardShortcut:p,getCellRangeCopyText:Ge.enabled?Ge.getCopyText:void 0}),Ig({apiRef:lt,viewportRef:Ht,layout:De,rowHeight:it});const dm=Tg({apiRef:lt,containerRef:qe,columns:jr,onColumnResize:ca}),{scrollTop:um,scrollLeft:fm,overscanRows:gm,handleScroll:pm,setViewportElement:hm}=jc({onRowsScrollEnd:je,overscanRowCount:Fh,rowCount:De.unpinnedRowsLength,autoHeight:u,setDimensions:Jh,viewportRef:Ht}),fa=Lc(qe),He=Ac({layout:De,scrollTop:um,scrollLeft:fm,viewportWidth:Fe.dimensions.viewportWidth,viewportHeight:Fe.dimensions.viewportHeight,autoHeight:u,rowReordering:Gt,hasDetailPanel:Bt,checkboxSelection:h,pinCheckboxColumn:K,pinExpandColumn:J,overscanRows:gm,maxContentHeight:fa??1/0}),{handleSort:ga,handleSortAdd:pa}=sd({sortModel:ut,onSortModelChange:Zs}),Co=h||!w,{focusedCell:vo,setFocusedCell:Zr,viewportTabIndex:mm,ensureGridFocus:wm,handleFocus:bm,handleBlur:xm,handleKeyDown:ym,handleMouseDownCapture:Cm}=pc({allRenderableRows:Et,navigationColumns:cn,checkboxSelection:h,selectedRowIds:Tn,handleSelectionChange:Xr,handleDetailPanelToggle:ra,editingHandlers:Pn,setKeyboardMode:Br,sortModel:ut,handleSort:ga,handleSortAdd:pa,multiSort:de,isCellEditable:pe,pagination:rt,pageSize:Re.pageSize,virtualization:He,viewportRef:Ht,pinnedTopRowCount:ze.length,getRowId:Pe,rowMetaMap:Ve,getSpanOrigin:Mt.getSpanOrigin,onRowActivate:qr,toggleRowExpansion:an?.toggleExpansion,handleSelectAll:Rr.selectAll,rowSelectionEnabled:Co,multipleRowSelectionEnabled:!y,pinCheckboxColumn:K,pinExpandColumn:J,rowHeight:it,cellSelection:Ge.keyboard,headerFilters:co}),{handleCellClick:vm,handleHeaderClick:_m}=Wg({ensureGridFocus:wm,setKeyboardMode:Br,setFocusedCell:Zr,getRowId:Pe,onCellClick:v});Gg({apiRef:lt,selection:Ge,model:$t.cellSelectionModel,getPendingModel:$t.getPendingCellSelectionModel,focusedCell:vo,setFocusedCell:Zr,containerRef:qe}),zu({apiRef:lt,containerRef:qe,viewportRef:Ht,selection:Ge,disableClipboardPaste:C,disableRangeClear:E,focusedCell:vo,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,isCellEditable:pe,rowMetaMap:Ve,getSpanOrigin:Mt.getSpanOrigin,isEditing:Pn.editingCell!==null,batchEdit:mo,onClipboardPaste:k,onBeforeClipboardPaste:N}),Ru({apiRef:lt,enabled:!!M,limit:typeof M=="object"&&M.limit||Ku,onHistoryChange:I,channel:Vr,batchEdit:mo,isEditing:Pn.editingCell!==null,containerRef:qe,viewportRef:Ht,selection:Ge,setFocusedCell:Zr,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,layout:De,rowHeight:it,pinnedTopRowCount:ze.length});const Sm=pf({containerRef:qe,viewportRef:Ht,selection:Ge,disableFillHandle:S,isEditing:Pn.editingCell!==null,allRenderableRows:Et,getRowId:Pe,navigationColumns:cn,columnIndexMap:wo,isCellEditable:pe,rowMetaMap:Ve,getSpanOrigin:Mt.getSpanOrigin,batchEdit:mo,onFill:F}),{handleHideColumn:km,handlePinColumn:Em}=ad({columnVisibilityModel:_t,onColumnVisibilityModelChange:ao,pinnedColumns:Fr,onPinnedColumnsChange:Gh}),On=jg({columnGroupingModel:In,headerFilterRow:co,pinnedTopCount:ze.length,pinnedBottomCount:st.length,pagination:rt,paginationMode:Me,paginationModel:Re,paginationRowCount:yo,paginatedUnpinnedRowCount:xo.length,sortedUnpinnedRowCount:pt.length}),Qr=yf({spanning:Mt,renderContext:He.renderContext,offsetTop:He.offsetTop,cumulativeHeights:De.cumulativeHeights}),ei=Bc({renderContext:Qr.renderContext,pinnedTopRows:ze,pinnedBottomRows:st,paginatedUnpinnedRows:xo,sortedUnpinnedRows:pt,pagination:rt,getRowId:Pe}),_o=Cf({spanning:Mt,firstColumnIndex:He.renderContext.firstColumnIndex,lastColumnIndex:He.renderContext.lastColumnIndex,virtualColumns:He.virtualColumns,layout:De,rows:ei});ed({paginationRequested:W,isRowGrouping:rn,autoHeight:u,viewportHeight:Fe.dimensions.viewportHeight,renderedRowCount:ei.length,totalRowCount:ze.length+Ur.length+st.length,pinnedRowsIgnored:fo&&!!(U?.top?.length||U?.bottom?.length),scrollHeight:He.totalHeight,maxContentHeight:fa,reachableRowCount:Ic(He.cumulativeHeights,He.virtualContainerHeight),unpinnedRowCount:He.cumulativeHeights.length,listViewWithoutColumn:so&&!Nn,listViewRowCount:ln&&Nn?Et.length:0});const{allSelected:Mm,someSelected:Nm}=Rr,un=vf(In,sm),Im=s.useMemo(()=>ia.some(ht=>!!ht.rowSpan),[ia]),at=fd();nd(qe);const fn=ap({apiRef:lt,options:Oh,columns:gt,onApply:Dh,onError:$h}),ha=Ie?.noRowsOverlay,ma=Ie?.loadingOverlay,ti=ma?c.jsx(ma,{...Se?.loadingOverlay}):void 0,wa=ha?c.jsx(ha,{...Se?.noRowsOverlay}):void 0,So=Ie?.footer,Lm=kt&&Et.length>0&&Me!=="infinite",ba=Ie?.toolbar,xa=Ug({toolbar:Ie?.toolbar,toolbarSlotProps:Se?.toolbar,apiRef:lt,orderedColumns:jr,baseColumns:Ar,aggregationModel:Ue,onAggregationModelChange:Qs,pivotMode:Oe,pivotModelProp:ge,onPivotModelChangeProp:ve,pivotModel:Or,onPivotModelChange:ea,filterModel:ft,onFilterModelChange:Tr,columnVisibilityModel:_t,onColumnVisibilityModelChange:ao,disableColumnReorder:ae,columnGroupingModel:In,moveColumn:sa,resetColumnOrder:aa,forceColumnsOpen:at.toolbarPanelRequested,onColumnsPanelClose:at.closeToolbarPanel,aiAssistantEnabled:fn.enabled,aiAssistantOpen:fn.open,onAiAssistantToggle:fn.togglePanel,aiAssistantLabel:Ln?.aiAssistantButton,forceFiltersOpen:at.toolbarFiltersRequested,onFiltersPanelClose:at.closeToolbarFiltersPanel}),ni={rowReordering:Gt,columnIndexMap:wo,editingHandlers:Pn,isCellEditable:pe,selectedRowIds:Tn,checkboxSelection:h,onRowClick:qr,onRowDoubleClick:D,onCellClick:vm,onSelectionChange:Xr,columnWidths:Fn,pinnedColumns:sn,hasDetailPanel:Bt,expandedRowIds:zr,getDetailPanelContent:te,getDetailPanelHeight:ce,onDetailPanelToggle:ra,onDetailPanelHeightChange:rm,pinCheckboxColumn:K,pinExpandColumn:J,focusedCell:vo,colspanMap:Mt.colspanMap,rowSpanningCaches:Mt.rowSpanningCaches,rowHeight:it,rowMetaMap:Ve,cellRange:Ge.displayRange,cellRangeHasRowSpan:Ge.hasRowSpan,fillHandle:Sm.handle};return c.jsxs("div",{ref:qe,className:["ogx",ke,u&&"ogx--auto-height",!u&&O===void 0&&xe?.height===void 0&&"ogx--fill",Im&&"ogx--row-spanning",ln&&"ogx--list-view"].filter(Boolean).join(" "),style:{...xe,height:O??xe?.height,"--ogx-row-height":`${it}px`,"--ogx-header-height":`${Gr}px`,...co?{"--ogx-header-filter-height":`${a}px`}:void 0},"aria-busy":kt,children:[ba&&xa&&c.jsx(il.Provider,{value:at.toolbarHost,children:c.jsx(hd,{component:ba,toolbarProps:xa})}),fn.panelProps&&c.jsx(gp,{panelProps:fn.panelProps,slot:Ie?.aiAssistantPanel,slotProps:Se?.aiAssistantPanel}),c.jsx(rg,{isOpen:at.standalonePanelOpen,containerRef:qe,panelRef:at.standalonePanelRef,columns:jr,columnVisibilityModel:_t,disableColumnReorder:ae,onClose:at.closeStandalonePanel,onColumnVisibilityChange:ao,onColumnMove:sa,onColumnOrderReset:aa,columnGroupingModel:In}),ln&&Nn&&c.jsx(Of,{ariaLabel:nt,allRenderableRows:Et,dataRowCount:dn.length,pinnedTopRowCount:ze.length,pinnedBottomRowCount:st.length,unpinnedRowCount:pt.length,pagination:rt,effectivePaginationModel:Re,currentPage:bo.currentPage,pageSizeOptions:oe,selectedRowIds:Tn,listViewColumn:Nn,columnsByField:Hr.byField,rowMetaMap:Ve,noRowsLabel:Pr,rowHeight:it,checkboxSelection:h,paginationMode:Me,serverRowCount:yo,paginationSlot:Ie?.pagination,paginationSlotProps:Se?.pagination,localeText:Ui(Ln),onRowClick:qr,onRowDoubleClick:D,onSelectionChange:Xr,onPaginationModelChange:on,onRowsScrollEnd:je,getRowId:Pe,multiselectable:Co&&!y,selectable:Co,onToggleExpansion:an?.toggleExpansion,loading:kt,loadingOverlay:ti,noRowsOverlay:wa,showPaginationControls:!So}),!ln&&c.jsx("div",{ref:hm,className:"ogx__viewport",onScroll:pm,role:"grid","aria-label":nt||"Data grid","aria-rowcount":On.rowCount,"aria-colcount":cn.length,"aria-multiselectable":Co&&!y||Ge.enabled,"aria-busy":kt,tabIndex:mm,onKeyDownCapture:()=>{Br(!0)},onMouseDownCapture:Cm,onMouseDown:Ge.handleMouseDown,onClickCapture:Ge.handleClickCapture,onKeyDown:ym,onFocus:bm,onBlur:xm,children:c.jsxs("div",{className:"ogx__content",style:{width:sn?.right?.length?`max(100%, ${He.totalWidth}px)`:He.totalWidth},role:"presentation",children:[c.jsxs("div",{className:"ogx__sticky-top",role:"presentation",children:[c.jsx(kl,{columns:_o,allColumns:ua,columnGroupingModel:In,checkboxSelection:h,allSelected:Mm,someSelected:Nm,onSelectAll:Rr.selectAll,sortModel:ut,onSort:ga,onSortAdd:pa,multiSort:de,onColumnResize:ca,onColumnAutosize:dm,columnWidths:Fn,pinnedColumns:sn,focusedCell:vo,columnIndexMap:wo,onHeaderClick:_m,onDragStart:un.onDragStart,onDragOver:un.onDragOver,onDragEnd:un.onDragEnd,onDrop:un.onDrop,draggedColumn:un.draggedColumn,dragOverColumn:un.dragOverColumn,rowReordering:Gt,hasDetailPanel:Bt,pinCheckboxColumn:K,pinExpandColumn:J,aggregationModel:Ue,onHideColumn:km,onManageColumns:at.openColumnsPanel,onPinColumn:Em,wrapHeaderText:l,headerHeight:Gr,headerFilters:co,filterModel:ft,onFilterModelChange:Tr,onOpenFilterPanel:at.openFiltersPanel}),c.jsx(ls,{...ni,rows:ze,position:"top",ariaRowIndexBase:On.topBase,columns:_o,pinnedRows:U,getRowId:Pe})]}),!kt&&!Fe.dataSource.error&&da.length===0&&c.jsx(wd,{noRowsLabel:Pr,width:He.totalWidth,overlay:wa}),c.jsx(tg,{...ni,virtualContainerHeight:He.virtualContainerHeight,offsetTop:Qr.offsetTop,effectiveLoading:kt,visibleRows:ei,baseColumns:Ar,virtualColumns:_o,viewportWidth:Fe.dimensions.viewportWidth,rowReorderHandlers:am,paginationMode:Me,dataSourceLoading:Fe.dataSource.loading,sortedUnpinnedRowCount:pt.length,infiniteScrollSkeletonCount:Math.min(Re.pageSize,20),unpinnedRowsLength:De.unpinnedRowsLength,lastRenderedRowIndex:Qr.renderContext.lastRowIndex,ariaRowIndexOffset:On.centerOffset,loadingOverlay:ti}),c.jsxs("div",{className:"ogx__sticky-bottom",role:"presentation",children:[c.jsx(ls,{...ni,rows:st,position:"bottom",rowIndexOffset:On.bottomRowIndexOffset,ariaRowIndexBase:On.bottomBase,columns:_o,pinnedRows:U,getRowId:Pe}),Jr&&Wr.rootAggregationPosition!==null&&c.jsx(md,{columns:He.virtualColumns,aggregationModel:Ue,aggregationResult:Yr,columnWidths:Fn,rowHeight:it,checkboxSelection:h,hasDetailPanel:Bt,rowReordering:Gt,pinCheckboxColumn:K,pinExpandColumn:J,pinnedColumns:sn,loading:cm})]})]})}),Ge.enabled&&b&&c.jsx(Hg,{stats:Ge.stats,apiRef:go.apiRef,slot:Ie?.cellSelectionStats,slotProps:Se?.cellSelectionStats}),So&&c.jsx(So,{apiRef:go.apiRef,aggregationModel:Ue,aggregationResult:Jr?Yr:null,rowCount:fo&&Me!=="server"?dn.length:yo,pagination:rt,paginationModel:Re,pageSizeOptions:oe,onPaginationModelChange:on,...Se?.footer}),!ln&&!So&&rt&&c.jsx(Vg,{paginationSlot:Ie?.pagination,paginationSlotProps:Se?.pagination,page:bo.currentPage,paginationModel:Re,rowCount:yo,pageSizeOptions:oe,onPaginationModelChange:on,localeText:Ln}),c.jsx(zg,{loading:kt,error:Fe.dataSource.error,noRowsLabel:Pr,filteredRowCount:da.length,dataRowCount:dn.length,filterModel:ft,cellSelectionAnnouncement:Ge.announcement,aiAssistantAnnouncement:fn.announcement}),Lm&&c.jsx(Df,{overlay:ti}),c.jsx(xd,{error:Fe.dataSource.error,onRetry:be?oa.fetchRows:void 0})]})}function hp({rows:e=5,columns:t=5}){return c.jsx("div",{className:"ogx__skeleton",children:Array.from({length:e}).map((n,o)=>c.jsx("div",{className:"ogx__skeleton-row",children:Array.from({length:t}).map((r,i)=>c.jsx("div",{className:"ogx__skeleton-cell",children:c.jsx("div",{className:"ogx__skeleton-content"})},i))},o))})}const mp=300;function Zt(e){return"field"in e&&!("items"in e)}function Ss(e,t){return e.find(n=>Zt(n)&&n.field===t)}function ks(e,t){return Object.is(e,t)?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>ks(n,t[o])):!1}function wp(e,t){return e===t?!0:Zt(e)&&Zt(t)?e.id===t.id&&e.field===t.field&&e.operator===t.operator&&ks(e.value,t.value):!Zt(e)&&!Zt(t)?e.id===t.id&&e.logicOperator===t.logicOperator&&Ir(e.items,t.items):!1}function Ir(e,t){return e===t?!0:e.length===t.length&&e.every((n,o)=>wp(n,t[o]))}function bp(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function Es(e,t){return Object.is(e.value,t)?!0:t!=null&&String(e.value).toLowerCase()===String(t).toLowerCase()}function Ms(e,t){return Bo(e,t.type)}function Ns(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function xp(e,t){if(!Vt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const yp=({col:e,item:t,resetToken:n,onChange:o})=>{const r=s.useId(),i=s.useMemo(()=>xi(e.type),[e.type]),l=i[0],d=t?.operator??l,a=i.includes(d)?i:[d,...i],u=!!t,g=e.headerName||e.field,[h,w]=s.useState(null),[y,p]=s.useState(n);y!==n&&(p(n),w(null));const f=s.useRef(o),m=s.useRef(t),x=s.useRef(e);s.useLayoutEffect(()=>{f.current=o,m.current=t,x.current=e});const b=s.useCallback((L,D)=>({id:m.current?.id??`${e.field}-${Date.now()}`,field:e.field,operator:L,value:D}),[e.field]),C=s.useCallback(L=>{const D=m.current;if(D?L===Ms(D.value,x.current):L.trim()==="")return;const V=D?.operator??l;f.current(b(V,Ns(L,V)))},[l,b]),E=s.useRef(null),k=s.useRef(C);s.useLayoutEffect(()=>{E.current=h,k.current=C}),s.useEffect(()=>()=>{const L=E.current;E.current=null,L!==null&&k.current(L)},[]),s.useEffect(()=>{if(h===null)return;const L=setTimeout(()=>{E.current=null,C(h),w(null)},mp);return()=>clearTimeout(L)},[h,C]);const N=L=>{const D=h!==null?Ns(h,L):t?.value;w(null),o(b(L,xp(D,L)))},M=()=>{w(null),o(null)},S=!Vt.has(d),F=bp(e),I=`ogx-filter__value-input${u?" ogx-filter__value-input--active":""}`,A=`Filter value for ${g}`;let _=null;if(S&&e.type==="boolean")_=c.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${I} ogx-filter__value-select`,value:t?.value==null?"":String(t.value),onChange:L=>{L.target.value===""?o(null):o(b(d,L.target.value))},"aria-label":A,children:[c.jsx("option",{value:"",children:"Any"}),c.jsx("option",{value:"true",children:"true"}),c.jsx("option",{value:"false",children:"false"})]});else if(S&&e.type==="singleSelect"&&F.length>0&&d==="isAnyOf"){const L=Array.isArray(t?.value)?t.value:t?.value==null||t.value===""?[]:[t.value];_=c.jsx("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${I} ogx-filter__value-multiselect`,multiple:!0,size:Math.min(F.length,4),value:F.filter(D=>L.some(v=>Es(D,v))).map(D=>D.key),onChange:D=>{const v=new Set(Array.from(D.target.selectedOptions,V=>V.value));o(b("isAnyOf",F.filter(V=>v.has(V.key)).map(V=>V.value)))},"aria-label":A,children:F.map(D=>c.jsx("option",{value:D.key,children:D.label},D.key))})}else if(S&&e.type==="singleSelect"&&F.length>0&&(d==="is"||d==="not")){const L=F.find(D=>Es(D,t?.value));_=c.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${I} ogx-filter__value-select`,value:L?.key??"",onChange:D=>{const v=F.find(V=>V.key===D.target.value);o(b(d,v?v.value:""))},"aria-label":A,children:[c.jsx("option",{value:"",children:"Any"}),F.map(D=>c.jsx("option",{value:D.key,children:D.label},D.key))]})}else S&&(_=c.jsx(Qe,{id:`${r}-val`,name:`filter-val-${e.field}`,inputClassName:I,type:e.type==="date"?"date":"text",value:h??Ms(t?.value,e),onChange:L=>w(L.target.value),placeholder:e.type==="number"?"Number…":"Value…","aria-label":A}));return c.jsxs("div",{className:`ogx-filter__row${u?" ogx-filter__row--active":""}`,children:[c.jsx("span",{className:"ogx-filter__col-label",title:e.field,children:g}),c.jsxs("div",{className:"ogx-filter__controls",children:[c.jsx("select",{id:`${r}-op`,name:`filter-op-${e.field}`,className:`ogx-filter__op-select${u?" ogx-filter__op-select--active":""}`,value:d,onChange:L=>N(L.target.value),"aria-label":`Filter operator for ${g}`,children:a.map(L=>c.jsx("option",{value:L,children:L},L))}),_,u&&c.jsx("button",{type:"button",className:"ogx-filter__row-clear",onClick:M,"aria-label":`Clear filter for ${g}`,title:"Clear",children:"×"})]})]})},Is=({filterModel:e,columns:t,onFilterModelChange:n})=>{const o=s.useMemo(()=>e.items??[],[e.items]),r=e.logicOperator??"and",[i,l]=s.useState(null),[d,a]=s.useState(o),[u,g]=s.useState(0);if(d!==o){a(o);const m=!Ir(d,o),x=i!==null&&Ir(i,o);m&&!x&&g(b=>b+1)}const h=s.useCallback((m,x)=>{const b=o.findIndex(E=>Zt(E)&&E.field===m);let C;if(b===-1){if(!x)return;C=[...o,x]}else x?C=o.map((E,k)=>k===b?x:E):C=o.filter((E,k)=>k!==b);l(C),n({...e,items:C})},[o,e,n]),w=s.useCallback(m=>{n({...e,logicOperator:m})},[e,n]),y=t.filter(m=>m.filterable!==!1),p=y.filter(m=>Ss(o,m.field)).length,f=o.length-p;return c.jsxs(c.Fragment,{children:[o.length>1&&c.jsxs("div",{className:"ogx-filter__logic-bar",children:[c.jsx("span",{className:"ogx-filter__logic-label",children:"Match:"}),c.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>w("and"),"aria-pressed":r==="and",children:"ALL (AND)"}),c.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>w("or"),"aria-pressed":r==="or",children:"ANY (OR)"})]}),f>0&&c.jsx("div",{className:"ogx-filter__hidden-note",role:"note",children:f===1?"1 more condition (a filter group or a second condition on a column) is applied and not shown here.":`${f} more conditions (filter groups or further conditions on a column) are applied and not shown here.`}),y.length===0?c.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):y.map(m=>c.jsx(yp,{col:m,item:Ss(o,m.field),resetToken:u,onChange:x=>h(m.field,x)},m.field))]})},Ls=["sum","avg","count","min","max"];function As(){return c.jsxs("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[c.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),c.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),c.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),c.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",fill:"currentColor",opacity:"0.25"}),c.jsx("path",{d:"M17 14v-4M17 10l-2 2 2 2"})]})}function Cp({anchorRef:e,columns:t,model:n,onChange:o,onClose:r}){const i=s.useRef(null),[l,d]=s.useState({top:0,right:0}),[a,u]=s.useState(null);s.useLayoutEffect(()=>{u(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const g=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const v=e.current.getBoundingClientRect();return{top:v.bottom+6,right:Ot()-v.right}},[e]);s.useEffect(()=>{d(g());const v=()=>d(g());return window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[g]),s.useEffect(()=>{function v(R){i.current&&!i.current.contains(R.target)&&e.current&&!e.current.contains(R.target)&&r()}function V(R){R.key==="Escape"&&r()}return document.addEventListener("mousedown",v),document.addEventListener("keydown",V),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",V)}},[e,r]);const h=new Set(n.rowFields),w=new Set(n.columnFields),y=new Set(n.valueFields.map(v=>v.field)),p=v=>h.has(v)||w.has(v)||y.has(v),f=v=>t.find(V=>V.field===v),m=v=>f(v)?.headerName??v,x=v=>{const V=f(v)?.availableAggregationFunctions;return V?Ls.filter(R=>V.includes(R)):Ls},b=v=>v.aggregable!==!1&&(v.type==="number"||v.aggregable===!0)&&x(v.field).length>0,C=v=>v.groupable!==!1;function E(v){h.has(v)||o({...n,rowFields:[...n.rowFields,v]})}function k(v){w.has(v)||o({...n,columnFields:[...n.columnFields,v]})}function N(v){y.has(v)||o({...n,valueFields:[...n.valueFields,{field:v,aggFn:x(v)[0]??"sum"}]})}function M(v){o({...n,rowFields:n.rowFields.filter((V,R)=>R!==v)})}function S(v){o({...n,columnFields:n.columnFields.filter((V,R)=>R!==v)})}function F(v){o({...n,valueFields:n.valueFields.filter((V,R)=>R!==v)})}function I(v,V){o({...n,valueFields:n.valueFields.map((R,Q)=>Q===v?{...R,aggFn:V}:R)})}function A(){o({rowFields:[],columnFields:[],valueFields:[]})}const _=n.rowFields.length+n.columnFields.length+n.valueFields.length,L=t.filter(v=>!p(v.field)&&(C(v)||b(v))),D=c.jsxs("div",{ref:i,className:"ogx-pivot-panel",role:"dialog","aria-label":"Pivot configuration",style:{top:l.top,right:l.right},children:[c.jsxs("div",{className:"ogx-pivot-panel__header",children:[c.jsxs("span",{className:"ogx-pivot-panel__title",children:[c.jsx(As,{}),"Pivot Mode"]}),_>0&&c.jsx("button",{type:"button",className:"ogx-pivot-panel__reset-btn",onClick:A,title:"Reset pivot",children:"Reset"})]}),c.jsxs("div",{className:"ogx-pivot-panel__body",children:[c.jsxs("div",{className:"ogx-pivot-zone",children:[c.jsxs("span",{className:"ogx-pivot-zone__label",children:[c.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--row"}),"Row Fields"]}),c.jsx("div",{className:`ogx-pivot-chips${n.rowFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — each becomes a row label",children:n.rowFields.map((v,V)=>c.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[m(v),c.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>M(V),title:`Remove ${m(v)}`,"aria-label":`Remove ${m(v)} from Row Fields`,children:"×"})]},`${V}:${v}`))})]}),c.jsxs("div",{className:"ogx-pivot-zone",children:[c.jsxs("span",{className:"ogx-pivot-zone__label",children:[c.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--col"}),"Column Fields"]}),c.jsx("div",{className:`ogx-pivot-chips${n.columnFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — unique values become column headers",children:n.columnFields.map((v,V)=>c.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[m(v),c.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>S(V),title:`Remove ${m(v)}`,"aria-label":`Remove ${m(v)} from Column Fields`,children:"×"})]},`${V}:${v}`))})]}),c.jsxs("div",{className:"ogx-pivot-zone",children:[c.jsxs("span",{className:"ogx-pivot-zone__label",children:[c.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--value"}),"Value Fields (aggregated)"]}),c.jsx("div",{className:`ogx-pivot-chips${n.valueFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add numeric fields here — values are aggregated",children:n.valueFields.map((v,V)=>{const R=x(v.field),Q=R.includes(v.aggFn)?R:[v.aggFn,...R];return c.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[m(v.field),c.jsx("select",{className:"ogx-pivot-chip__fn-select",value:v.aggFn,onChange:G=>I(V,G.target.value),title:"Aggregation function","aria-label":`Aggregation function for ${m(v.field)}`,children:Q.map(G=>c.jsx("option",{value:G,children:G.toUpperCase()},G))}),c.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>F(V),title:`Remove ${m(v.field)}`,"aria-label":`Remove ${m(v.field)} (${v.aggFn.toUpperCase()}) from Value Fields`,children:"×"})]},`${V}:${v.field}:${v.aggFn}`)})})]}),c.jsx("hr",{className:"ogx-pivot-panel__divider"}),c.jsxs("div",{children:[c.jsx("div",{className:"ogx-pivot-panel__fields-label",children:"Available Fields"}),c.jsxs("div",{className:"ogx-pivot-fields",children:[L.map(v=>{const V=b(v),R=C(v),Q=v.headerName??v.field;return c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[c.jsx("span",{className:`ogx-pivot-field-btn${V?" ogx-pivot-field-btn--numeric":""}`,children:Q}),c.jsxs("div",{className:"ogx-pivot-field-actions",children:[R&&c.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>E(v.field),title:"Add to Row Fields","aria-label":`Add ${Q} to Row Fields`,children:"Row"}),R&&c.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>k(v.field),title:"Add to Column Fields","aria-label":`Add ${Q} to Column Fields`,children:"Col"}),V&&c.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>N(v.field),title:"Add to Value Fields","aria-label":`Add ${Q} to Value Fields`,children:"Val"})]})]},v.field)}),L.length===0&&c.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return a?mt.createPortal(D,a):null}function vp(){return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function _p(){return c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Ps(e){return e.trim().split(/\s+/).filter(Boolean).join(" ")}function Sp({value:e="",onChange:t,placeholder:n="Search...",debounceMs:o=250}){const[r,i]=s.useState(()=>e.length>0),[l,d]=s.useState(e),a=s.useRef(null),u=s.useRef(null),g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t},[t]);const h=s.useRef(e),w=s.useRef(e);s.useEffect(()=>{e!==w.current&&(w.current=e,Ps(e)!==Ps(h.current)&&(d(e),h.current=e,i(e.length>0)))},[e]),s.useEffect(()=>{const b=setTimeout(()=>{l!==h.current&&(h.current=l,g.current(l))},o);return()=>clearTimeout(b)},[l,o]);const y=s.useRef(l);s.useLayoutEffect(()=>{y.current=l}),s.useEffect(()=>()=>{const b=y.current;b!==h.current&&(h.current=b,g.current(b))},[]);const p=s.useCallback(()=>{i(!0),requestAnimationFrame(()=>a.current?.focus())},[]),f=s.useCallback(b=>{b.stopPropagation(),d(""),h.current="",g.current(""),a.current?.focus()},[]),m=s.useCallback(()=>{i(!0)},[]),x=s.useCallback(()=>{setTimeout(()=>{u.current&&document.activeElement&&u.current.contains(document.activeElement)||l||i(!1)},150)},[l]);return s.useEffect(()=>{const b=C=>{u.current&&!u.current.contains(C.target)&&(l||i(!1))};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[l]),c.jsxs("div",{ref:u,className:`ogx-global-search${r?" ogx-global-search--expanded":""}`,onClick:r?void 0:p,children:[c.jsx("div",{className:"ogx-global-search__icon-wrapper",children:c.jsx(vp,{})}),c.jsx(Qe,{ref:a,inputClassName:"ogx-global-search__input",value:l,onChange:b=>d(b.target.value),onFocus:m,onBlur:x,placeholder:n,"aria-label":"Global Search",autoComplete:"off"}),l&&c.jsx("button",{type:"button",className:"ogx-global-search__clear",onClick:f,"aria-label":"Clear search",children:c.jsx(_p,{})})]})}const oo=8;function Sn({title:e,children:t,placement:n="top",enterDelay:o=200,leaveDelay:r=0}){const[i,l]=s.useState(!1),[d,a]=s.useState({top:0,left:0}),[u,g]=s.useState(null),h=s.useRef(null),w=s.useRef(null),y=s.useId(),p=s.useCallback(()=>{if(!w.current)return;const k=w.current.getBoundingClientRect(),N=k.left+k.width/2,M=k.top+k.height/2;switch(n){case"bottom":a({top:k.bottom+oo,left:N});break;case"left":a({top:M,left:k.left-oo});break;case"right":a({top:M,left:k.right+oo});break;default:a({top:k.top-oo,left:N})}},[n]),f=s.useCallback(()=>{h.current&&clearTimeout(h.current),h.current=null},[]);s.useLayoutEffect(()=>{if(!i)return;p();const k=N=>{N.key==="Escape"&&(f(),l(!1))};return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),document.addEventListener("keydown",k),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p),document.removeEventListener("keydown",k)}},[i,p,f]),s.useEffect(()=>f,[f]);const m=()=>{f(),h.current=setTimeout(()=>{g(w.current?.closest(".ogx-theme-provider")??document.body),l(!0)},o)},x=()=>{f(),h.current=setTimeout(()=>{l(!1)},r)},b=s.useCallback(k=>{w.current=k?k.firstElementChild??k:null},[]),C=i&&!!e&&u!==null;let E=t;if(C&&s.isValidElement(t)){const k=t,N=k.props["aria-describedby"];E=s.cloneElement(k,{"aria-describedby":N?`${N} ${y}`:y})}return c.jsxs(c.Fragment,{children:[c.jsx("span",{ref:b,style:{display:"inline-block",lineHeight:0},onMouseEnter:m,onMouseLeave:x,onFocus:m,onBlur:x,children:E}),C&&u&&mt.createPortal(c.jsx("div",{id:y,role:"tooltip",className:`ogx-tooltip ogx-tooltip--${n}`,style:{top:d.top,left:d.left,position:"fixed",zIndex:99999},children:e}),u)]})}const kp=Object.keys(Lt);function Ep(e){return Object.prototype.hasOwnProperty.call(Lt,e)}function Ts(e){return e.availableAggregationFunctions?Array.from(new Set(e.availableAggregationFunctions.filter(Ep))):kp}function Fs(){return c.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:c.jsx("path",{d:"M18 4H6l6 8-6 8h12"})})}function Mp(){return c.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.25"}),c.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),c.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),c.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Os(){return c.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function Np({anchorRef:e,aggregationModel:t,aggregableColumns:n,onFunctionChange:o,onClearAll:r,onClose:i,activeCount:l}){const d=s.useRef(null),[a,u]=s.useState({top:0,right:0}),[g,h]=s.useState(null);s.useLayoutEffect(()=>{h(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const w=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const p=e.current.getBoundingClientRect();return{top:p.bottom+6,right:Ot()-p.right}},[e]);s.useEffect(()=>{u(w());const p=()=>u(w());return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[w]),s.useEffect(()=>{function p(f){d.current&&!d.current.contains(f.target)&&e.current&&!e.current.contains(f.target)&&i()}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[e,i]),s.useEffect(()=>{function p(f){f.key==="Escape"&&i()}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[i]);const y=c.jsxs("div",{ref:d,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:a.top,right:a.right,width:400,maxWidth:"calc(100vw - 24px)"},children:[c.jsxs("div",{className:"ogx-toolbar__panel-header",children:[c.jsxs("span",{className:"ogx-toolbar__panel-title",children:[c.jsx(Fs,{}),"Summaries"]}),l>0&&c.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:r,title:"Clear all summaries",children:"Clear all"})]}),c.jsx("div",{className:"ogx-toolbar__panel-body",children:n.length===0?c.jsxs("p",{className:"ogx-toolbar__empty",children:["No aggregable columns.",c.jsx("br",{}),"Set ",c.jsx("code",{children:"aggregable: true"})," on a column to enable."]}):n.map(p=>{const f=t[p.field]||"none";return c.jsxs("div",{className:"ogx-toolbar__agg-row",children:[c.jsx("span",{className:"ogx-toolbar__agg-label",title:p.field,children:p.headerName||p.field}),c.jsx("div",{className:"ogx-toolbar__agg-pills",children:["none",...Ts(p)].map(m=>c.jsx("button",{type:"button",className:`ogx-toolbar__pill${f===m?" ogx-toolbar__pill--active":""}`,onClick:()=>o(p.field,m),"aria-pressed":f===m,children:m},m))})]},p.field)})})]});return g?mt.createPortal(y,g):null}function Ip({anchorRef:e,columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:d,onClose:a,showNonHideableColumns:u}){const g=s.useRef(null),[h,w]=s.useState({top:0,right:0}),[y,p]=s.useState(null);s.useLayoutEffect(()=>{p(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const f=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const x=e.current.getBoundingClientRect();return{top:x.bottom+6,right:Ot()-x.right}},[e]);s.useEffect(()=>{w(f());const x=()=>w(f());return window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[f]),s.useEffect(()=>{function x(b){g.current&&!g.current.contains(b.target)&&e.current&&!e.current.contains(b.target)&&a()}return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[e,a]),s.useEffect(()=>{function x(b){b.key==="Escape"&&a()}return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[a]);const m=c.jsx("div",{ref:g,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:h.top,right:h.right,width:280,padding:0},children:c.jsx(Cr,{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:d,showNonHideableColumns:u})});return y?mt.createPortal(m,y):null}function Lp({anchorRef:e,columns:t,filterModel:n,onFilterModelChange:o,onClose:r}){const i=s.useRef(null),[l,d]=s.useState({top:0,right:0}),a=s.useRef(r);s.useLayoutEffect(()=>{a.current=r},[r]);const[u,g]=s.useState(null);s.useLayoutEffect(()=>{g(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const h=s.useCallback(()=>{if(!e.current)return{top:0,right:0};const f=e.current.getBoundingClientRect();return{top:f.bottom+6,right:Ot()-f.right}},[e]);s.useEffect(()=>{d(h());const f=()=>d(h());return window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[h]),s.useEffect(()=>{function f(m){m.key==="Escape"&&a.current()}return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[]);const w=n.items?.length??0,y=()=>{o({...n,items:[],logicOperator:"and"})},p=c.jsxs("div",{ref:i,className:"ogx-toolbar__panel ogx-toolbar__panel--filter",role:"dialog","aria-label":"Advanced filters",style:{top:l.top,right:l.right,width:540,maxWidth:"calc(100vw - 24px)"},children:[c.jsxs("div",{className:"ogx-toolbar__panel-header",children:[c.jsxs("span",{className:"ogx-toolbar__panel-title",children:[c.jsx(Os,{}),"Filters",w>0&&c.jsx("span",{className:"ogx-toolbar__panel-count",children:w})]}),c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[w>0&&c.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:y,title:"Clear all filters",children:"Clear all"}),c.jsx("button",{type:"button",className:"ogx-toolbar__close-btn",onClick:()=>a.current(),title:"Close filters","aria-label":"Close filters panel",children:"Close"})]})]}),c.jsx("div",{className:"ogx-toolbar__panel-body ogx-toolbar__panel-body--filter",children:c.jsx(Is,{columns:t,filterModel:n,onFilterModelChange:o})})]});return u?mt.createPortal(p,u):null}const Ap={rowFields:[],columnFields:[],valueFields:[]},Pp=[];function Tp({columns:e=Pp,baseColumns:t,aggregationModel:n={},onAggregationModelChange:o,pivotModel:r,onPivotModelChange:i,filterModel:l,onFilterModelChange:d,columnVisibilityModel:a={},onColumnVisibilityModelChange:u,onColumnReorder:g,onColumnOrderReset:h,forceColumnsOpen:w,onColumnsPanelClose:y,forceFiltersOpen:p,onFiltersPanelClose:f,children:m,rightContent:x,style:b,renderColumnsButton:C,renderFilterButton:E,renderAggregationButton:k,renderExportButton:N,renderQuickFilter:M,className:S,showNonHideableColumns:F,onAiAssistantToggle:I,aiAssistantOpen:A=!1,aiAssistantLabel:_="Ask AI"}){const[L,D]=s.useState(w?"columns":null),v=L==="summaries",V=L==="pivot",R=L==="columns",Q=L==="filters",G=he=>{L==="columns"&&he!=="columns"&&y?.(),L==="filters"&&he!=="filters"&&f?.(),D(he)},W=he=>G(L===he?null:he),H=he=>{L===he&&G(null)},[ie,oe]=s.useState(w);ie!==w&&(oe(w),w&&D("columns"));const[ue,se]=s.useState(p);ue!==p&&(se(p),p&&d&&D("filters"));const U=s.useContext(il),te=w!==void 0&&!!u;s.useEffect(()=>{if(!(!U||!te))return U.registerColumnsPanel()},[U,te]);const ce=p!==void 0&&!!d;s.useEffect(()=>{if(!(!U||!ce))return U.registerFiltersPanel()},[U,ce]);const z=s.useRef(null),re=s.useRef(null),K=s.useRef(null),J=s.useRef(null),ae=s.useRef(null),fe=s.useRef(null),Z=s.useRef(null),$=s.useRef(null),O=r??Ap,P=O.rowFields.length>0||O.columnFields.length>0||O.valueFields.length>0,T=t?new Set(t.map(he=>he.field)):null,X=e.filter(he=>he.aggregable!==!1&&(he.type==="number"||he.aggregable===!0)&&Ts(he).length>0&&(!T||T.has(he.field))),B=Object.keys(n).filter(he=>n[he]&&n[he]!=="none").length,ee=s.useCallback((he,Ce)=>{if(!o)return;const be={...n};Ce==="none"?delete be[he]:be[he]=Ce,o(be)},[n,o]),q=s.useCallback(()=>{o?.({})},[o]),Y=s.useCallback(he=>{if(!d)return;const Ce=he.trim().split(/\s+/).filter(Boolean),be={...l||{},quickFilterValues:Ce,items:l?.items||[]};d(be)},[l,d]),ne=(l?.quickFilterValues??[]).join(" "),me=l?.items?.length||0,j=new Set(e.filter(he=>a[he.field]!==!1).map(he=>he.field)),le=s.useCallback((he,Ce)=>{if(!u)return;const be={...a,[he]:Ce};u(be)},[a,u]),we=s.useCallback(()=>{if(!u)return;const he={...a};e.forEach(Ce=>{Ce.hideable!==!1&&(he[Ce.field]=!0)}),u(he)},[e,a,u]),pe=s.useCallback(()=>{if(!u)return;const he={...a};e.forEach(Ce=>{Ce.hideable!==!1&&(he[Ce.field]=!1)}),u(he)},[e,a,u]);return c.jsxs("div",{className:["ogx-toolbar",S].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:b,children:[m&&c.jsx("div",{className:"ogx-toolbar__left",children:m}),c.jsx("div",{className:"ogx-toolbar__spacer"}),c.jsxs("div",{className:"ogx-toolbar__actions",children:[I&&c.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:c.jsxs("button",{type:"button",ref:re,className:`ogx-toolbar__icon-btn ogx-toolbar__ai-btn${A?" ogx-toolbar__icon-btn--active":""}`,"aria-haspopup":"dialog","aria-expanded":A,onClick:()=>{G(null),I(re.current)},children:[c.jsx(_s,{}),_]})}),d&&c.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:M?M({value:ne,onChange:Y}):c.jsx(Sp,{value:ne,onChange:Y,placeholder:"Search..."})}),u&&c.jsxs("div",{ref:fe,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[C?C({onClick:()=>W("columns"),isOpen:R,activeCount:e.length-j.size}):c.jsx(Sn,{title:"Columns",children:c.jsx("button",{type:"button",ref:J,className:`ogx-toolbar__icon-btn${R?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns","aria-haspopup":"dialog","aria-expanded":R,onClick:()=>W("columns"),children:c.jsx(Mp,{})})}),R&&c.jsx(Ip,{anchorRef:C?fe:J,columns:e,visibleColumns:j,onVisibilityChange:le,onShowAll:we,onHideAll:pe,onColumnReorder:g,onColumnOrderReset:h,onClose:()=>H("columns"),showNonHideableColumns:F})]}),d&&c.jsxs("div",{ref:Z,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[E?E({onClick:()=>W("filters"),isOpen:Q,activeCount:me}):c.jsx(Sn,{title:"Filters",children:c.jsxs("button",{type:"button",ref:ae,className:`ogx-toolbar__icon-btn${Q?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters","aria-haspopup":"dialog","aria-expanded":Q,onClick:()=>W("filters"),children:[c.jsx(Os,{}),me>0&&c.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),Q&&c.jsx(Lp,{anchorRef:E?Z:ae,columns:e,filterModel:l||{items:[]},onFilterModelChange:d,onClose:()=>H("filters")})]}),i&&c.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[c.jsx(Sn,{title:"Pivot",children:c.jsxs("button",{type:"button",ref:K,className:`ogx-toolbar__icon-btn${V?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-haspopup":"dialog","aria-expanded":V,onClick:()=>W("pivot"),children:[c.jsx(As,{}),P&&c.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),V&&c.jsx(Cp,{anchorRef:K,columns:t??e,model:O,onChange:he=>{i?.(he)},onClose:()=>H("pivot")})]}),o&&c.jsxs("div",{ref:$,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[k?k({onClick:()=>W("summaries"),isOpen:v,activeCount:B}):c.jsx(Sn,{title:"Summaries",children:c.jsxs("button",{type:"button",ref:z,className:`ogx-toolbar__icon-btn${v?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-haspopup":"dialog","aria-expanded":v,onClick:()=>W("summaries"),children:[c.jsx(Fs,{}),B>0&&c.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${B} active summaries`})]})}),v&&c.jsx(Np,{anchorRef:k?$:z,aggregationModel:n,aggregableColumns:X,onFunctionChange:ee,onClearAll:q,onClose:()=>H("summaries"),activeCount:B})]}),N&&N(),x]})]})}function Fp(){const[e]=s.useState(El);return s.useRef(e)}function Qt(e,t){if(e.groupLabel!==void 0)return e.groupLabel;const n=e.groupField??"",o=t.find(r=>r.field===n)?.groupingValueFormatter;return o?o({field:n,value:e.groupValue}):`${n}: ${String(e.groupValue??"")}`}const Op=new Set([8364,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,381,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,382,376]);function Dp(e){return e>=8192&&e<=8202||e===8239||e===8287||e===12288?" ":e>=8203&&e<=8205||e===8288||e===65279?"":e===8208||e===8209||e===8210||e===8722?"-":null}function $p(e){let t="",n=!1;for(const o of e){const r=o.codePointAt(0)??0;if(r<=255||Op.has(r)){t+=o;continue}const i=Dp(r);i!==null?t+=i:(t+="?",n=!0)}return{text:t,lossy:n}}const Gp={sliceMs:30,renderChunkRows:40},Hp=2e4;function Ds(){return new Promise(e=>setTimeout(e,0))}function Bp(){return new DOMException("PDF export was aborted","AbortError")}const en=()=>typeof performance<"u"?performance.now():Date.now(),$s=e=>Math.max(2,Math.floor(e/2)*2),Wp=[79,70,229],Vp=[255,255,255];function Gs(e,t){const n=e.trim().replace(/^#/,""),o=/^[a-f\d]{3}$/i.test(n)?n.split("").map(i=>i+i).join(""):n,r=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);return r?[parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16)]:t}function Hs(e,t){return _n(e,t,vn(e,t))}function Bs(e){return(typeof e.width=="number"?e.width:void 0)??(e.flex??1)*100}function zp(e,t){const n=e.reduce((r,i)=>r+Bs(i),0),o={};return e.forEach((r,i)=>{o[i]={cellWidth:Bs(r)/n*t}}),o}const Kp=new Set(["isEmpty","isNotEmpty"]);function jp(e,t){const o=t.find(l=>l.field===e.field)?.headerName??e.field;if(Kp.has(e.operator))return`${o} ${e.operator}`;const{value:r}=e;if(r==null||r===""||Array.isArray(r)&&r.length===0)return null;const i=Array.isArray(r)?r.map(String).join(", "):String(r);return`${o} ${e.operator} "${i}"`}function Ws(e,t,n,o){const r=e.map(l=>"items"in l?Ws(l.items,l.logicOperator,n,!0):jp(l,n)).filter(l=>!!l);if(r.length===0)return"";const i=r.join(t==="or"?" OR ":" AND ");return o&&r.length>1?`(${i})`:i}function Up(e,t){const n=[],o=Ws(e.items??[],e.logicOperator??"and",t,!1);o&&n.push(o);const r=(e.quickFilterValues??[]).filter(i=>i.trim()!=="");return r.length>0&&n.push(`Search: ${r.map(i=>`"${i}"`).join(" ")}`),n.join(" • ")}const Rp=1.15*.3528;function qp(e,t,n={}){return Xp(e,t,n,Gp)}async function Xp(e,t,n,o){const{signal:r,onProgress:i}=n,l=()=>{if(r?.aborted)throw Bp()};l();let d,a;try{const[q,Y]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);d=q.default,a=Y.default}catch{throw new Error("exportToPdf requires 'jspdf' and 'jspdf-autotable'. Run: npm install jspdf jspdf-autotable")}const{fileName:u="export",title:g,logoUrl:h,orientation:w="landscape",selectedRows:y,getRowId:p,aggregationResult:f,aggregationModel:m,filterModel:x,alternateRowColor:b=!0,headerBackgroundColor:C="#4f46e5",headerTextColor:E="#ffffff",fontSize:k=9,groupedRows:N,font:M,maxRows:S=Hp}=n;l();let F=en();const I=async()=>{en()-F<o.sliceMs||(await Ds(),l(),F=en())},A=(q,Y,ne)=>{i?.({phase:q,done:Y,total:ne})},_=new d({orientation:w,unit:"mm",format:"a4"}),L=_.internal.pageSize.getWidth(),D=_.internal.pageSize.getHeight(),v=14,V=L-v*2;let R="helvetica";M&&(_.addFileToVFS(`${M.name}-normal.ttf`,M.data),_.addFont(`${M.name}-normal.ttf`,M.name,"normal"),M.boldData&&_.addFileToVFS(`${M.name}-bold.ttf`,M.boldData),_.addFont(M.boldData?`${M.name}-bold.ttf`:`${M.name}-normal.ttf`,M.name,"bold"),R=M.name);let Q=!1;const G=q=>{if(M)return q;const Y=$p(q);return Y.lossy&&(Q=!0),Y.text},W=(q,Y,ne,me,j)=>{const le=_.splitTextToSize(G(q),me);return _.text(le.length===1?le[0]:le,Y,ne),Math.max(0,le.length-1)*j*Rp},H=Dt(t),ie=Cn(N,y),oe=yn(e,y,p);let ue=v;if(g){let q=v,Y=v+8;if(h)try{_.addImage(h,"PNG",q,v,10,10),q+=14}catch{}const ne=L-v-q;_.setFontSize(16),_.setFont(R,"bold"),_.setTextColor(30,41,59),Y+=W(g,q,Y,ne,16),Y+=6,_.setFontSize(8),_.setFont(R,"normal"),_.setTextColor(100,116,139);const me=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),j=ie?N.filter(le=>le.type==="leaf").length:oe.length;if(_.text(G(`Exported: ${me} • ${j} row${j!==1?"s":""}`),q,Y),Y+=5,x){const le=Up(x,t);le&&(Y+=W(`Filters: ${le}`,q,Y,ne,8),Y+=5)}_.setDrawColor(226,232,240),_.setLineWidth(.3),_.line(v,Y+2,L-v,Y+2),ue=Y+6}const se=[H.map(q=>G(q.headerName??q.field))],U=m||{},te=q=>H.map(Y=>vr(Y,U[Y.field],q[Y.field],q)),ce=[];let z;const re=q=>{ce.push(q.map(G))};if(ie){const q=N.length;A("prepare",0,q);for(let Y=0;Y<q;Y++){const ne=N[Y],me=" ".repeat(ne.depth*2);if(ne.type==="group-header"){const j=`${me}${Qt(ne,t)}`;re(H.map((le,we)=>we===0?j:""))}else if(ne.type==="leaf"&&ne.row){const j=ne.row;re(H.map((le,we)=>(we===0?me:"")+Hs(j,le)))}else if(ne.type==="group-subtotal"&&ne.aggregatedValues){const j=te(ne.aggregatedValues);re(j.map((le,we)=>we===0?`${me}${Jt("Subtotal",le)}`:le))}else ne.type==="grand-total"&&ne.aggregatedValues&&(z=[te(ne.aggregatedValues).map((le,we)=>we===0?Jt("Grand Total",le):le).map(G)]);(Y&63)===63&&(A("prepare",Y+1,q),await I())}A("prepare",q,q)}else{const q=oe.length;A("prepare",0,q);for(let ne=0;ne<q;ne++)re(H.map(me=>Hs(oe[ne],me))),(ne&63)===63&&(A("prepare",ne+1,q),await I());const Y=m?Yt(oe,yt(y),t,f,m):null;if(Y&&m){const ne=H.some(j=>m[j.field]);z=[te(Y).map((j,le)=>le===0&&ne?Jt("TOTAL",j):j).map(G)]}A("prepare",q,q)}l(),ce.length>S&&process.env.NODE_ENV!=="production"&&console.warn(`[exportToPdf] Exporting ${ce.length} table rows (maxRows: ${S}). PDFs this large are slow to build and open and can reach tens of MB. Prefer exportToCsv or exportToExcelAdvanced for full-dataset exports, or pass a larger \`maxRows\` to silence this warning.`),Q&&console.warn('[exportToPdf] Some characters cannot be drawn with the built-in Helvetica font and were replaced with "?". Pass the `font` option (a Unicode .ttf, e.g. Noto Sans) to draw them.');const K=zp(H,V),[J,ae,fe]=Gs(C,Wp),[Z,$,O]=Gs(E,Vp),P={head:se,styles:{fontSize:k,cellPadding:3,font:R,overflow:"linebreak"},headStyles:{fillColor:[J,ae,fe],textColor:[Z,$,O],fontStyle:"bold"},...b?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...z?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:K,showHead:"everyPage",margin:{top:v,left:v,right:v,bottom:v+6}},T=ce.length;A("render",0,T);let X=0,B=$s(o.renderChunkRows);do{const q=ce.slice(X,X+B),Y=X===0,ne=X+q.length>=T,me=Y?ue:_.lastAutoTable.finalY;let j=!0;const le=en();a(_,{...P,body:q,...ne&&z?{foot:z}:{},startY:Y?ue:v,showFoot:ne&&z?"lastPage":"never",...Y?{}:{willDrawPage:pe=>{j?(j=!1,pe.settings.showHead="never",pe.cursor&&(pe.cursor.y=me)):pe.settings.showHead="everyPage"}}}),X+=q.length,A("render",X,T);const we=en()-le;B=$s(we>0?Math.min(B*4,B*(o.sliceMs/we)):B*4),ne||(await Ds(),l(),F=en())}while(X<T);const ee=_.getNumberOfPages();for(let q=1;q<=ee;q++)_.setPage(q),_.setFontSize(8),_.setTextColor(150,150,150),_.text(`Page ${q} of ${ee}`,L-v,D-8,{align:"right"}),await I();l(),A("save",0,1),_.save(`${u}.pdf`),A("save",1,1)}function kn(e,t){const n=vn(e,t);return{text:_n(e,t,n),raw:n}}function tn(e,t,n){return e.map(o=>vr(o,n[o.field],t[o.field],t))}const Yp="\uFEFF";function Jp(e,t,n={}){const{fileName:o="export.csv",includeHeaders:r=!0,delimiter:i=",",selectedRows:l,groupedRows:d,escapeFormulas:a=!0,bom:u=!0}=n,g=Dt(t),h=n.aggregationModel||{},w=(f,m=!1)=>ro(a?Qn(f,m):f,i),y=()=>g.map(f=>w(f.headerName||f.field)).join(i)+`
|
|
8
|
+
`;let p="";if(Cn(d,l))r&&(p+=y()),d.forEach(f=>{const m=" ".repeat(f.depth);if(f.type==="group-header"){const x=Qt(f,t),b=ro(m+(a?Qn(x):x),i);p+=g.map((C,E)=>E===0?b:"").join(i)+`
|
|
9
|
+
`}else if(f.type==="leaf"&&f.row){const x=f.row,b=g.map((C,E)=>{const k=kn(x,C),N=a?Qn(k.text,Ct(k.raw)):k.text;return ro((E===0?m:"")+N,i)});p+=b.join(i)+`
|
|
10
|
+
`}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const x=f.aggregatedValues,b=f.type==="grand-total"?"Grand Total":`${m}Subtotal`,C=tn(g,x,h),E=g.map((k,N)=>N===0?ro(Jt(b,C[0]),i):w(C[N],Ct(x[k.field])));p+=E.join(i)+`
|
|
11
|
+
`}});else{const f=yn(e,l,n.getRowId);if(f.length===0){console.warn("No rows to export");return}r&&(p+=y()),f.forEach(x=>{const b=g.map(C=>{const E=kn(x,C);return w(E.text,Ct(E.raw))});p+=b.join(i)+`
|
|
12
|
+
`});const m=Yt(f,yt(l),t,n.aggregationResult,n.aggregationModel);if(m){const x=g.map(C=>w(h[C.field]?h[C.field].toUpperCase():""));p+=x.join(i)+`
|
|
13
|
+
`;const b=tn(g,m,h);p+=g.map((C,E)=>w(b[E],Ct(m[C.field]))).join(i)+`
|
|
14
|
+
`}}Lr((u?Yp:"")+p,o,"text/csv;charset=utf-8;")}function ro(e,t){return t!==""&&e.includes(t)||e.includes('"')||e.includes(`
|
|
15
|
+
`)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}const io="ogx-xls-text";function Zp(e,t){return e.type!=="number"&&e.type!=="date"&&e.type!=="boolean"&&!Ct(t)}function Qp(e){if(!/\.xlsx$/i.test(e))return e;const t=e.replace(/\.xlsx$/i,".xls");return console.warn(`[exportToExcel] "${e}" renamed to "${t}": exportToExcel writes an HTML table that Excel refuses to open as .xlsx. Use exportToExcelAdvanced for a real .xlsx file.`),t}function eh(e,t,n={}){const{fileName:o="export.xls",sheetName:r="Sheet1",includeHeaders:i=!0,selectedRows:l,groupedRows:d,escapeFormulas:a=!0}=n,u=Dt(t),g=n.aggregationModel||{},h=(m,x=!1)=>Te(a?Qn(m,x):m),w=m=>`<td class="${io}">${m}</td>`;let p=`<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>${Te(_r(r))}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta charset="UTF-8"><style>.${io}{mso-number-format:"\\@";}</style></head><body><table border="1">`;i&&(p+="<thead><tr>",u.forEach(m=>{p+=`<th class="${io}">${h(m.headerName||m.field)}</th>`}),p+="</tr></thead>"),p+="<tbody>";const f=(m,x,b="")=>{const C=b+h(m.text,Ct(m.raw));return Zp(x,m.raw)?w(C):`<td>${C}</td>`};if(Cn(d,l))d.forEach(m=>{const x=" ".repeat(m.depth*2);if(m.type==="group-header")p+='<tr style="font-weight:bold;background:#e8eaf6;">',p+=`<td colspan="${u.length}" class="${io}">${Te(x)}${h(Qt(m,t))}</td>`,p+="</tr>";else if(m.type==="leaf"&&m.row){const b=m.row;p+="<tr>",u.forEach((C,E)=>{p+=f(kn(b,C),C,E===0?Te(x):"")}),p+="</tr>"}else if((m.type==="group-subtotal"||m.type==="grand-total")&&m.aggregatedValues){const b=m.aggregatedValues,C=m.type==="grand-total"?"Grand Total":`${x}Subtotal`,E=tn(u,b,g);p+='<tr style="font-weight:bold;background:#f5f5f5;">',u.forEach((k,N)=>{if(N===0){p+=w(Te(Jt(C,E[0])));return}p+=E[N]?`<td style="text-align:right;">${h(E[N],Ct(b[k.field]))}</td>`:"<td></td>"}),p+="</tr>"}});else{const m=yn(e,l,n.getRowId);if(m.length===0){console.warn("No rows to export");return}m.forEach(b=>{p+="<tr>",u.forEach(C=>{p+=f(kn(b,C),C)}),p+="</tr>"});const x=Yt(m,yt(l),t,n.aggregationResult,n.aggregationModel);if(x){p+='<tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',u.forEach(C=>{p+=g[C.field]?`<td style="text-align:right;font-weight:bold;">${Te(g[C.field].toUpperCase())}</td>`:"<td></td>"}),p+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">';const b=tn(u,x,g);u.forEach((C,E)=>{p+=b[E]?`<td style="text-align:right;">${h(b[E],Ct(x[C.field]))}</td>`:"<td></td>"}),p+="</tr>"}}p+="</tbody></table></body></html>",Lr(p,Qp(o),"application/vnd.ms-excel")}function th(e,t,n={}){const{fileName:o="export.json",pretty:r=!0,selectedRows:i,groupedRows:l}=n,d=Dt(t),a=g=>{const h={};return d.forEach(w=>{h[w.field]=vn(g,w)}),h};let u;if(Cn(l,i)){const g=[],h=[];let w;l.forEach(y=>{if(y.type==="group-header"){const p={group:Qt(y,t),field:y.groupField??"",value:y.groupValue,rows:[],children:[]};for(;g.length>y.depth;)g.pop();g.length===0?h.push(p):(g[g.length-1].children??=[]).push(p),g.push(p)}else y.type==="leaf"&&y.row?g.length>0&&g[g.length-1].rows.push(a(y.row)):y.type==="group-subtotal"&&y.aggregatedValues&&g.length>0?(g[g.length-1].subtotals=as(y.aggregatedValues,d),g.pop()):y.type==="grand-total"&&y.aggregatedValues&&(w=as(y.aggregatedValues,d))}),u=w?{groups:h,grandTotal:w}:{groups:h}}else{const g=yn(e,i,n.getRowId);if(g.length===0){console.warn("No rows to export");return}const h=g.map(a),w=Yt(g,yt(i),t,n.aggregationResult,n.aggregationModel);if(w){const y=n.aggregationModel||{},p={};d.forEach(m=>{y[m.field]&&(p[m.field]=y[m.field].toUpperCase())});const f={};d.forEach(m=>{w[m.field]!==void 0&&w[m.field]!==null&&(f[m.field]=w[m.field])}),u={data:h,aggregation:{labels:p,values:f}}}else u=h}Lr(r?JSON.stringify(u,null,2):JSON.stringify(u),o,"application/json;charset=utf-8;")}const nh=/^(?:https?:|data:image\/|blob:)/i,oh=/^[a-z][a-z\d+.-]*:/i;function rh(e){const t=e.trim();return t?nh.test(t)?t:oh.test(t)?null:t:null}async function ih(e,t,n){const o=window.open("","_blank");if(!o){console.error("Failed to open print window. Please check your popup blocker settings.");return}o.document.write(`
|
|
16
16
|
<!DOCTYPE html>
|
|
17
17
|
<html>
|
|
18
18
|
<head>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
</div>
|
|
33
33
|
</body>
|
|
34
34
|
</html>
|
|
35
|
-
`),o.document.close(),await new Promise(r=>setTimeout(r,100));try{let r="Print",i,l,d=null,a=null,u;typeof n=="string"?r=n:typeof n=="object"&&(r=n.title||"Print",i=n.selectedRows,l=n.getRowId,d=n.aggregationResult||null,a=n.aggregationModel||null,u=n.groupedRows);const g=Dt(t),
|
|
35
|
+
`),o.document.close(),await new Promise(r=>setTimeout(r,100));try{let r="Print",i,l,d=null,a=null,u;typeof n=="string"?r=n:typeof n=="object"&&(r=n.title||"Print",i=n.selectedRows,l=n.getRowId,d=n.aggregationResult||null,a=n.aggregationModel||null,u=n.groupedRows);const g=Dt(t),h=a||{};let w=`<!DOCTYPE html><html><head><title>${Te(r||"Print")}</title><style>
|
|
36
36
|
body{font-family:Arial,sans-serif;margin:20px;}
|
|
37
37
|
h1{font-size:24px;margin-bottom:20px;}
|
|
38
38
|
table{border-collapse:collapse;width:100%;}
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
tr.group-subtotal{background:#f0f4ff;font-style:italic;}
|
|
44
44
|
tr.grand-total{background:#f5f5f5;font-weight:bold;}
|
|
45
45
|
@media print{body{margin:0;}@page{margin:1cm;}}
|
|
46
|
-
</style></head><body>`;r&&(w+=`<h1>${Te(r)}</h1>`),w+="<table><thead><tr>",g.forEach(f=>{w+=`<th>${Te(f.headerName||f.field)}</th>`}),w+="</tr></thead><tbody>";const y=(f,h,x="",b=!1)=>{const{text:v}=kn(f,h),E=h.type==="image"?Jp(v):null;if(E!==null){const k=`<img src="${Te(E)}" alt="${Te(h.headerName||h.field)}" style="max-height:40px;border-radius:4px;">`;return b?`<td><div style="display:flex;justify-content:center;">${k}</div></td>`:`<td>${k}</td>`}return`<td>${x}${Te(v)}</td>`};if(vn(u,i))u.forEach(f=>{const h=" ".repeat(f.depth*4);if(f.type==="group-header")w+=`<tr class="group-header"><td colspan="${g.length}">${h}${Te(Qt(f,t))}</td></tr>`;else if(f.type==="leaf"&&f.row){const x=f.row;w+="<tr>",g.forEach((b,v)=>{w+=y(x,b,v===0?h:"")}),w+="</tr>"}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const x=f.type==="grand-total",b=tn(g,f.aggregatedValues,m);w+=`<tr class="${x?"grand-total":"group-subtotal"}">`,g.forEach((v,E)=>{if(E===0){w+=`<td>${x?"":h}${Te(Jt(x?"Grand Total":"Subtotal",b[0]))}</td>`;return}w+=b[E]?`<td style="text-align:right;">${Te(b[E])}</td>`:"<td></td>"}),w+="</tr>"}});else{const f=yn(e,i,l);if(f.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}f.forEach(x=>{w+="<tr>",g.forEach(b=>{w+=y(x,b,"",!0)}),w+="</tr>"});const h=Yt(f,yt(i),t,d,a);h&&(w+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',g.forEach(x=>{w+=m[x.field]?`<td style="text-align:right;font-weight:bold;">${Te(m[x.field].toUpperCase())}</td>`:"<td></td>"}),w+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',tn(g,h,m).forEach(x=>{w+=x?`<td style="text-align:right;">${Te(x)}</td>`:"<td></td>"}),w+="</tr></tfoot>")}w+="</tbody></table></body></html>",o.document.open(),o.document.write(w),o.document.close(),o.document.title=r||"Print Preview",o.focus();let p=!1;o.onload=()=>{p||(p=!0,o.print(),setTimeout(()=>{o.close()},100))},setTimeout(()=>{!p&&o&&!o.closed&&(p=!0,o.print(),setTimeout(()=>{o.closed||o.close()},100))},500)}catch(r){if(console.error("Print generation failed:",r),o&&!o.closed){const i=r instanceof Error?r.message:String(r);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${Te(i)}</p></div>`}}}function Ir(e,t,n){const o=new Blob([e],{type:n}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function Qp(e,t){return e.type==="number"?"number":e.type==="boolean"?"boolean":e.type==="date"?"date":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date?"date":"string"}function En(e){return Number.isNaN(e.getTime())?null:new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}const eh=/^(\d{4})-(\d{2})-(\d{2})$/,th=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/i,nh=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;function oh(e){if(e instanceof Date)return En(e);if(typeof e=="number")return Number.isFinite(e)?En(new Date(e)):null;if(typeof e!="string")return;const t=e.trim(),n=eh.exec(t);if(n){const[o,r,i]=[Number(n[1]),Number(n[2]),Number(n[3])],l=new Date(Date.UTC(o,r-1,i));return l.getUTCMonth()===r-1&&l.getUTCDate()===i?l:void 0}if(th.test(t)){const o=new Date(t.replace(" ","T"));return Number.isNaN(o.getTime())?void 0:En(o)}}function rh(e,t){if(t==null||t==="")return null;if(e==="number"){if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="bigint"){const n=Number(t);return Number.isSafeInteger(n)?n:void 0}if(typeof t=="string"&&nh.test(t.trim())){const n=Number(t.trim());return Number.isFinite(n)?n:void 0}return}if(e==="boolean"){if(typeof t=="boolean")return t;if(typeof t=="string"){const n=t.trim().toLowerCase();if(n==="true")return!0;if(n==="false")return!1}return}return oh(t)}function Bs(e){if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:null;if(e instanceof Date)return En(e);if(typeof e=="object")try{return JSON.stringify(e)??String(e)}catch{return String(e)}return String(e)}function ih(e,t){const n=Cn(e,t),o=Qp(t,n);if(o!=="string"){const r=rh(o,n);if(r!=null)return r;if(!t.valueFormatter)return r===null?null:Bs(n)}return t.valueFormatter?_n(e,t,n):Bs(n)}const Ws="#,##0",lh="#,##0.##";function sh(e){return Number.isInteger(e)?Ws:lh}function Vs(e,t){if(t?.numFmt)return t.numFmt;if(e.type==="date")return"yyyy-mm-dd"}function zs(e,t,n){if(!(t?.numFmt||typeof n!="number"||e.type!=="number"))return sh(n)}function ah(e,t){if(t!=null)return t;const n=e.width??120;return Math.min(60,Math.max(8,(n-5)/7))}function ch(e){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e.length>=6&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56?"gif":null}function Ks(e,t){const n=Cn(e,t);return typeof n=="string"&&n?n:null}async function dh(e){const t=await Promise.allSettled(e.map(async o=>{let r;if(o.startsWith("data:")){const l=o.slice(o.indexOf(",")+1),d=atob(l);r=new Uint8Array(d.length);for(let a=0;a<d.length;a++)r[a]=d.charCodeAt(a)}else{const l=await fetch(o,{mode:"cors"});if(!l.ok)throw new Error(`HTTP ${l.status}`);r=new Uint8Array(await l.arrayBuffer())}const i=ch(r);if(!i)throw new Error("unsupported image format (only PNG, JPEG and GIF can be embedded)");return{url:o,buffer:r.slice().buffer,ext:i}})),n=new Map;return t.forEach((o,r)=>{o.status==="fulfilled"?n.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${e[r]}" (CORS/network error or unsupported format — raw URL written as fallback):`,o.reason)}),n}async function uh(e,t,n={}){const{fileName:o="export.xlsx",sheets:r,columnStyles:i={},headerFillColor:l="#f1f5f9",headerTextColor:d="#334155",headerFontSize:a=10,bodyFontSize:u=10,aggregationResult:g=null,aggregationModel:m=null,selectedRows:w,getRowId:y,groupedRows:p,groupHeaderFillColor:f="#e8eaf6",groupSubtotalFillColor:h="#f0f4ff"}=n,x=(await import("exceljs")).default,b=new x.Workbook;b.creator="OpenGridX",b.created=new Date;const v=t,E=Dt(v),k=e,N=yt(w)?is(k,w,y):[],M=r??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],S=new Set,D=new Map,I=(_,z)=>{const K=z[_.field],Q=m?.[_.field];if(K==null)return{value:null};const G=ui(_,Q,K);return typeof G=="number"?Number.isFinite(G)?di(Q)?{value:G,numFmt:Ws}:{value:G,numFmt:zs(_,i[_.field],G)}:{value:null}:G instanceof Date?{value:En(G)}:{value:vr(_,Q,K,z)}};for(const _ of M){if("type"in _&&_.type==="summary"){if(!g||!m)continue;const Z=b.addWorksheet(Cr(_.name??"Summary",S));Z.addRow(["Summary / Aggregation Totals"]),Z.getRow(1).font={bold:!0,size:a+2,color:{argb:Ke(d)}},Z.addRow([]),Z.addRow(["Column","Function","Value"]).eachCell(O=>{O.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(l)}},O.font={bold:!0,size:a,color:{argb:Ke(d)}},O.border=js()}),E.forEach(O=>{const P=m[O.field];if(P==null||g[O.field]==null)return;const{value:T,numFmt:X}=I(O,g),ee=Z.addRow([O.headerName??O.field,P.toUpperCase(),T]).getCell(3),q=X??Vs(O,i[O.field]);q&&(ee.numFmt=q),ee.alignment={horizontal:"right"},ee.font={bold:!0,size:u}}),Z.getColumn(1).width=20,Z.getColumn(2).width=12,Z.getColumn(3).width=18;continue}const z=_,{name:K="Data",rows:Q="all",includeHeaders:G=!0,includeSummary:j=!1,autoFilter:H=!0,frozenHeader:ie=!0,alternateRowColor:re="#f8fafc"}=z,ue=Q==="all"&&!!(p&&p.length>0),ae=Q==="selected"?N:ue?p.flatMap(Z=>Z.type==="leaf"&&Z.row?[Z.row]:[]):k,R=E.filter(Z=>i[Z.field]?.embedImage);if(R.length>0){const Z=[],$=new Set;if(ae.forEach(O=>{R.forEach(P=>{const T=Ks(O,P);T&&!D.has(T)&&!$.has(T)&&(Z.push(T),$.add(T))})}),Z.length>0){const O=await dh(Z);for(const[P,{buffer:T,extension:X}]of O){const B=b.addImage({buffer:T,extension:X});D.set(P,B)}}}const te=b.addWorksheet(Cr(K,S));te.columns=E.map(Z=>({key:Z.field,width:ah(Z,i[Z.field]?.width),style:{numFmt:Vs(Z,i[Z.field])}}));const ce=(Z,$)=>{E.forEach((O,P)=>$(Z.getCell(P+1),O,P+1))};if(G){const Z=E.map(O=>O.headerName??O.field),$=te.addRow(Z);$.height=20,ce($,(O,P)=>{O.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(l)}},O.font={bold:!0,size:a,color:{argb:Ke(d)}},O.alignment={horizontal:i[P.field]?.alignment??(P.type==="number"?"right":"left"),vertical:"middle"},O.border=js()}),H&&(te.autoFilter={from:{row:1,column:1},to:{row:1,column:E.length}}),ie?te.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:te.views=[{showGridLines:!1}]}let W=G?1:0;const le=(Z,$,O)=>{const P=E.map(B=>i[B.field]?.embedImage?"":ih(Z,B)),T=te.addRow(P);T.font={size:u},O>0&&(T.outlineLevel=O);const X=!!re&&$%2===1;if(ce(T,(B,ee,q)=>{const Y=zs(ee,i[ee.field],P[q-1]);Y&&(B.numFmt=Y),X&&re&&(B.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(re)}}),B.alignment={horizontal:i[ee.field]?.alignment??(ee.type==="number"?"right":"left"),vertical:"middle"},B.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}}}),R.length>0){const B=R.reduce((Y,oe)=>Math.max(Y,i[oe.field]?.imageHeight??40),0),ee=Math.ceil(B/1.333),q=ee*1.333;T.height=ee,R.forEach(Y=>{const oe=E.indexOf(Y),me=Ks(Z,Y),U=me?D.get(me):void 0;if(U===void 0){T.getCell(oe+1).value=me??"";return}const se=i[Y.field],we=se?.imageWidth??40,pe=se?.imageHeight??40,ve=(te.getColumn(oe+1).width??8)*7+5,be=Math.max(0,ve-we)/2,de=Math.max(0,q-pe)/2;te.addImage(U,{tl:{col:oe,row:W,nativeColOff:Math.floor(be*9525),nativeRowOff:Math.floor(de*9525)},ext:{width:we,height:pe},editAs:"oneCell"})})}else T.height=16;W++},V=Z=>Qt(Z,v),J=(Z,$,O,P,T)=>{const X=E.map((ee,q)=>q===0&&$[ee.field]==null?{value:Z}:I(ee,$)),B=te.addRow(X.map(ee=>ee.value));B.height=18,P>0&&(B.outlineLevel=P),B.font={bold:T,italic:!T,size:u,color:{argb:Ke(d)}},ce(B,(ee,q,Y)=>{const oe=X[Y-1].numFmt;oe&&(ee.numFmt=oe),ee.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(O)}},ee.alignment={horizontal:Y===1?"left":q.type==="number"?"right":"left",vertical:"middle"},ee.border=Us()}),W++};let ne=!1;if(ue){let Z=0;p.forEach($=>{if($.type==="group-header"){const O=te.addRow([V($)]);O.height=18,$.depth>0&&(O.outlineLevel=$.depth),O.font={bold:!0,size:u,color:{argb:Ke(d)}};for(let P=1;P<=E.length;P++)O.getCell(P).fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(f)}};O.getCell(1).alignment={horizontal:"left",vertical:"middle",indent:$.depth},W++,Z=0}else $.type==="leaf"&&$.row?le($.row,Z++,$.depth):$.type==="group-subtotal"&&$.aggregatedValues?J("Subtotal",$.aggregatedValues,h,$.depth,!1):$.type==="grand-total"&&$.aggregatedValues&&(J("Grand Total",$.aggregatedValues,l,0,!0),ne=!0)}),te.properties.outlineProperties={summaryBelow:!0,summaryRight:!1}}else ae.forEach((Z,$)=>le(Z,$,0));const fe=Yt(ae,Q==="selected",v,g,m);if(j&&!ne&&fe&&m){const Z=E.map(T=>{const X=m[T.field];return X?X.toUpperCase():""}),$=te.addRow(Z);$.height=16,$.font={size:u-1,italic:!0,color:{argb:"FF94a3b8"}},ce($,T=>{T.alignment={horizontal:"right",vertical:"middle"},T.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const O=E.map(T=>m[T.field]==null?{value:null}:I(T,fe)),P=te.addRow(O.map(T=>T.value));P.height=18,P.font={bold:!0,size:u,color:{argb:Ke(d)}},ce(P,(T,X,B)=>{const ee=O[B-1].numFmt;ee&&(T.numFmt=ee),T.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(l)}},T.alignment={horizontal:"right",vertical:"middle"},T.border=Us()})}}const A=await b.xlsx.writeBuffer(),C=new Blob([A],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),L=URL.createObjectURL(C),F=document.createElement("a");F.href=L,F.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(F),F.click(),document.body.removeChild(F),URL.revokeObjectURL(L)}function Ke(e){const t=e.replace("#","");return t.length===3?"FF"+t.split("").map(n=>n+n).join(""):t.length===6?"FF"+t:"FF"+t.padEnd(6,"0")}function js(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function Us(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}function fh(e,t,n,o){return s.useMemo(()=>o?Li(e,t,n):Ro,[e,t,n,o])}const Rs={"--ogx-grid-row-selected-background":"var(--ogx-color-primary-light)","--ogx-grid-row-selected-hover-background":"color-mix(in srgb, var(--ogx-color-primary) 14%, var(--ogx-color-primary-light))","--ogx-grid-cell-focus-border":"var(--ogx-color-primary)","--ogx-range-background":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-range-border":"var(--ogx-color-primary)","--ogx-fill-handle-color":"var(--ogx-range-border)","--ogx-toolbar-btn-primary-bg":"var(--ogx-color-primary)","--ogx-toolbar-btn-primary-hover":"var(--ogx-color-primary-dark)","--ogx-toolbar-input-focus-border":"var(--ogx-color-primary)","--ogx-toolbar-input-focus-shadow":"0 0 0 3px color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-bg":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-text":"var(--ogx-color-primary-dark)","--ogx-overlay-item-selected-bg":"color-mix(in srgb, var(--ogx-color-primary) 8%, transparent)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary-dark)"},qs={"--ogx-color-primary":"#3b82f6","--ogx-color-primary-dark":"#2563eb","--ogx-color-primary-light":"#eff6ff","--ogx-color-primary-focus":"rgba(59, 130, 246, 0.5)","--ogx-color-secondary":"#8b5cf6","--ogx-color-secondary-dark":"#7c3aed","--ogx-color-secondary-light":"#f5f3ff","--ogx-color-white":"#ffffff","--ogx-color-black":"#0f172a","--ogx-color-gray-50":"#f8fafc","--ogx-color-gray-100":"#f1f5f9","--ogx-color-gray-200":"#e2e8f0","--ogx-color-gray-300":"#cbd5e1","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#64748b","--ogx-color-gray-600":"#475569","--ogx-color-gray-700":"#334155","--ogx-color-gray-800":"#1e293b","--ogx-color-gray-900":"#0f172a","--ogx-border-color":"#e2e8f0","--ogx-border-color-hover":"#cbd5e1","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.05)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02)","--ogx-grid-background":"#ffffff","--ogx-grid-border-color":"#e2e8f0","--ogx-grid-header-background":"#f8fafc","--ogx-grid-header-text":"#334155","--ogx-grid-header-hover-background":"#f1f5f9","--ogx-grid-header-sorted-background":"#f8fafc","--ogx-grid-row-text":"#1e293b","--ogx-grid-row-hover-background":"#f8fafc","--ogx-grid-row-alternate-background":"transparent","--ogx-checkbox-bg":"#ffffff","--ogx-checkbox-border":"#94a3b8","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.05)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.05)",...{"--ogx-toolbar-background":"var(--ogx-grid-header-background)","--ogx-toolbar-text":"var(--ogx-grid-header-text)","--ogx-toolbar-border":"var(--ogx-grid-border-color)","--ogx-toolbar-btn-bg":"transparent","--ogx-toolbar-btn-hover":"var(--ogx-grid-header-hover-background)","--ogx-toolbar-btn-text":"var(--ogx-grid-header-text)","--ogx-toolbar-input-bg":"var(--ogx-grid-background)","--ogx-toolbar-input-text":"var(--ogx-grid-row-text)","--ogx-toolbar-chip-bg":"transparent","--ogx-toolbar-chip-text":"var(--ogx-grid-row-text)"},"--ogx-toolbar-btn-primary-text":"#ffffff","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-text":"#ef4444","--ogx-toolbar-input-border":"#cbd5e1","--ogx-overlay-background":"#ffffff","--ogx-overlay-text":"#1e293b","--ogx-overlay-border":"#e2e8f0","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.06)","--ogx-overlay-item-hover-bg":"#f8fafc","--ogx-overlay-item-hover-text":"#0f172a","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-overlay-item-danger-text":"#ef4444","--ogx-scrollbar-thumb":"#cbd5e1","--ogx-scrollbar-track":"transparent","--ogx-scrollbar-size":"8px","--ogx-skeleton-base":"#f1f5f9","--ogx-skeleton-highlight":"#ffffff",...Rs},gh={...qs,"--ogx-color-primary":"#60a5fa","--ogx-color-primary-dark":"#3b82f6","--ogx-color-primary-light":"#1e3a5f","--ogx-color-primary-focus":"rgba(96, 165, 250, 0.4)","--ogx-color-white":"#0f172a","--ogx-color-black":"#f8fafc","--ogx-color-gray-50":"#1e293b","--ogx-color-gray-100":"#334155","--ogx-color-gray-200":"#475569","--ogx-color-gray-300":"#64748b","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#cbd5e1","--ogx-color-gray-600":"#e2e8f0","--ogx-color-gray-700":"#e2e8f0","--ogx-color-gray-800":"#f1f5f9","--ogx-color-gray-900":"#f8fafc","--ogx-border-color":"#334155","--ogx-border-color-hover":"#475569","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.3)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.3)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.3)","--ogx-grid-background":"#0f172a","--ogx-grid-border-color":"#334155","--ogx-grid-header-background":"#1e293b","--ogx-grid-header-text":"#e2e8f0","--ogx-grid-header-hover-background":"#334155","--ogx-grid-header-sorted-background":"#1e3a5f","--ogx-grid-row-text":"#cbd5e1","--ogx-grid-row-hover-background":"#1e293b","--ogx-grid-row-alternate-background":"#162032","--ogx-checkbox-bg":"#1e293b","--ogx-checkbox-border":"#64748b","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.25)","--ogx-toolbar-btn-danger-text":"#fca5a5","--ogx-toolbar-input-border":"#334155","--ogx-overlay-background":"#1e293b","--ogx-overlay-text":"#cbd5e1","--ogx-overlay-border":"#334155","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3), 0 0 0 1px rgba(0,0,0,0.2)","--ogx-overlay-item-hover-bg":"#334155","--ogx-overlay-item-hover-text":"#f1f5f9","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-overlay-item-danger-text":"#fca5a5","--ogx-scrollbar-thumb":"#475569","--ogx-skeleton-base":"#1e293b","--ogx-skeleton-highlight":"#334155",...Rs,"--ogx-toolbar-chip-active-text":"var(--ogx-color-primary)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary)"},ph=[50,100,200,300,400,500,600,700,800,900];function hh(e){const t={};function n(o,r){r!==void 0&&(t[o]=r)}if(e.colors){const o=e.colors;if(n("--ogx-color-primary",o.primary),n("--ogx-color-primary-dark",o.primaryDark),n("--ogx-color-primary-light",o.primaryLight),n("--ogx-color-primary-focus",o.primaryFocus),n("--ogx-color-secondary",o.secondary),n("--ogx-color-secondary-dark",o.secondaryDark),n("--ogx-color-secondary-light",o.secondaryLight),n("--ogx-color-success",o.success),n("--ogx-color-warning",o.warning),n("--ogx-color-error",o.error),n("--ogx-color-info",o.info),n("--ogx-color-white",o.white),n("--ogx-color-black",o.black),o.gray)for(const r of ph)n(`--ogx-color-gray-${r}`,o.gray[r])}if(e.typography){const o=e.typography;n("--ogx-font-family",o.fontFamily),n("--ogx-font-family-mono",o.fontFamilyMono),n("--ogx-font-size-xs",o.fontSizeXs),n("--ogx-font-size-sm",o.fontSizeSm),n("--ogx-font-size-md",o.fontSizeMd),n("--ogx-font-size-lg",o.fontSizeLg),n("--ogx-font-size-xl",o.fontSizeXl)}if(e.spacing){const o=e.spacing;n("--ogx-spacing-xs",o.xs),n("--ogx-spacing-sm",o.sm),n("--ogx-spacing-md",o.md),n("--ogx-spacing-lg",o.lg),n("--ogx-spacing-xl",o.xl),n("--ogx-spacing-xxl",o.xxl)}if(e.borders){const o=e.borders;n("--ogx-border-width-thin",o.widthThin),n("--ogx-border-width-medium",o.widthMedium),n("--ogx-border-width-thick",o.widthThick),n("--ogx-border-radius-sm",o.radiusSm),n("--ogx-border-radius-md",o.radiusMd),n("--ogx-border-radius-lg",o.radiusLg),n("--ogx-border-radius-xl",o.radiusXl),n("--ogx-border-color",o.color),n("--ogx-border-color-hover",o.colorHover)}if(e.shadows){const o=e.shadows;n("--ogx-shadow-sm",o.sm),n("--ogx-shadow-md",o.md),n("--ogx-shadow-lg",o.lg),n("--ogx-shadow-xl",o.xl)}if(e.grid){const o=e.grid;n("--ogx-grid-row-height-compact",o.rowHeightCompact),n("--ogx-grid-row-height-standard",o.rowHeightStandard),n("--ogx-row-height",o.rowHeightStandard),n("--ogx-grid-row-height-comfortable",o.rowHeightComfortable),n("--ogx-grid-header-height",o.headerHeight),n("--ogx-header-height",o.headerHeight),n("--ogx-grid-cell-padding-x",o.cellPaddingX),n("--ogx-grid-cell-padding-y",o.cellPaddingY),n("--ogx-grid-cell-font-size",o.cellFontSize),n("--ogx-grid-header-font-size",o.headerFontSize),n("--ogx-grid-background",o.background),n("--ogx-grid-border-color",o.borderColor),n("--ogx-grid-header-background",o.headerBackground),n("--ogx-grid-header-text",o.headerText),n("--ogx-grid-header-hover-background",o.headerHoverBackground),n("--ogx-grid-header-sorted-background",o.headerSortedBackground),n("--ogx-grid-row-text",o.rowText),n("--ogx-grid-row-hover-background",o.rowHoverBackground),n("--ogx-grid-row-alternate-background",o.rowAlternateBackground),n("--ogx-grid-row-selected-background",o.rowSelectedBackground),n("--ogx-grid-row-selected-hover-background",o.rowSelectedHoverBackground),n("--ogx-grid-cell-focus-border",o.cellFocusBorder),n("--ogx-range-background",o.rangeBackground),n("--ogx-range-border",o.rangeBorder),n("--ogx-fill-handle-color",o.fillHandleColor),n("--ogx-grid-pinned-left-shadow",o.pinnedLeftShadow),n("--ogx-grid-pinned-right-shadow",o.pinnedRightShadow),n("--ogx-checkbox-bg",o.checkboxBg),n("--ogx-checkbox-border",o.checkboxBorder)}if(e.transitions){const o=e.transitions;n("--ogx-transition-duration-fast",o.durationFast),n("--ogx-transition-duration-normal",o.durationNormal),n("--ogx-transition-duration-slow",o.durationSlow),n("--ogx-transition-easing",o.easing)}if(e.toolbar){const o=e.toolbar;n("--ogx-toolbar-background",o.background),n("--ogx-toolbar-text",o.text),n("--ogx-toolbar-border",o.border),n("--ogx-toolbar-btn-bg",o.buttonBackground),n("--ogx-toolbar-btn-hover",o.buttonHoverBackground),n("--ogx-toolbar-btn-text",o.buttonText),n("--ogx-toolbar-btn-primary-bg",o.buttonPrimaryBackground),n("--ogx-toolbar-btn-primary-hover",o.buttonPrimaryHoverBackground),n("--ogx-toolbar-btn-primary-text",o.buttonPrimaryText),n("--ogx-toolbar-btn-danger-bg",o.buttonDangerBackground),n("--ogx-toolbar-btn-danger-hover",o.buttonDangerHoverBackground),n("--ogx-toolbar-btn-danger-text",o.buttonDangerText),n("--ogx-toolbar-input-bg",o.inputBackground),n("--ogx-toolbar-input-text",o.inputText),n("--ogx-toolbar-input-border",o.inputBorder),n("--ogx-toolbar-input-focus-border",o.inputFocusBorder),n("--ogx-toolbar-input-focus-shadow",o.inputFocusShadow),n("--ogx-toolbar-chip-bg",o.chipBackground),n("--ogx-toolbar-chip-text",o.chipText),n("--ogx-toolbar-chip-active-bg",o.chipActiveBackground),n("--ogx-toolbar-chip-active-text",o.chipActiveText)}if(e.overlays){const o=e.overlays;n("--ogx-overlay-background",o.background),n("--ogx-overlay-text",o.text),n("--ogx-overlay-border",o.border),n("--ogx-overlay-shadow",o.shadow),n("--ogx-overlay-item-hover-bg",o.itemHoverBackground),n("--ogx-overlay-item-hover-text",o.itemHoverText),n("--ogx-overlay-item-selected-bg",o.itemSelectedBackground),n("--ogx-overlay-item-selected-text",o.itemSelectedText),n("--ogx-overlay-item-danger-bg",o.itemDangerBackground),n("--ogx-overlay-item-danger-text",o.itemDangerText)}if(e.scrollbar){const o=e.scrollbar;n("--ogx-scrollbar-thumb",o.thumbColor),n("--ogx-scrollbar-track",o.trackColor),n("--ogx-scrollbar-size",o.size)}if(e.skeleton){const o=e.skeleton;n("--ogx-skeleton-base",o.baseColor),n("--ogx-skeleton-highlight",o.highlightColor)}return t}function mh({theme:e,children:t,className:n,style:o}){const r=s.useMemo(()=>({...e.mode==="dark"?gh:qs,...hh(e)}),[e]);return c.jsx(Ki.Provider,{value:e,children:c.jsx("div",{className:`ogx-theme-provider ${n||""}`.trim(),style:{...o,...r},children:t})})}const wh={mode:"dark",colors:{primary:"#60a5fa",primaryDark:"#3b82f6",primaryLight:"#1e3a5f",primaryFocus:"rgba(96, 165, 250, 0.4)"},grid:{background:"#0f172a",headerBackground:"#1e293b",headerText:"#e2e8f0",headerHoverBackground:"#334155",headerSortedBackground:"#1e3a5f",rowText:"#cbd5e1",borderColor:"#334155",rowHoverBackground:"#1e293b",rowAlternateBackground:"#162032",rowSelectedBackground:"#1e3a5f",rowSelectedHoverBackground:"#1d4ed8",cellFocusBorder:"#60a5fa",rangeBackground:"rgba(96, 165, 250, 0.18)",rangeBorder:"#60a5fa",checkboxBg:"#1e293b",checkboxBorder:"#64748b"},borders:{color:"#334155",colorHover:"#475569"},shadows:{sm:"0 1px 2px 0 rgba(0, 0, 0, 0.3)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.3)"},toolbar:{background:"#1e293b",text:"#cbd5e1",border:"#334155",buttonBackground:"transparent",buttonHoverBackground:"#334155",buttonText:"#e2e8f0",buttonPrimaryBackground:"#3b82f6",buttonPrimaryHoverBackground:"#2563eb",buttonPrimaryText:"#ffffff",buttonDangerBackground:"rgba(239, 68, 68, 0.15)",buttonDangerHoverBackground:"rgba(239, 68, 68, 0.25)",buttonDangerText:"#fca5a5",inputBackground:"#0f172a",inputText:"#f8fafc",inputBorder:"#334155",inputFocusBorder:"#60a5fa",inputFocusShadow:"0 0 0 3px rgba(96, 165, 250, 0.2)",chipBackground:"#1e293b",chipText:"#94a3b8",chipActiveBackground:"rgba(96, 165, 250, 0.2)",chipActiveText:"#60a5fa"},overlays:{background:"#1e293b",text:"#f8fafc",border:"#334155",shadow:"0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3)",itemHoverBackground:"#334155",itemHoverText:"#ffffff",itemSelectedBackground:"rgba(96, 165, 250, 0.15)",itemSelectedText:"#60a5fa",itemDangerBackground:"rgba(239, 68, 68, 0.15)",itemDangerText:"#fca5a5"},scrollbar:{thumbColor:"rgba(148, 163, 184, 0.2)",trackColor:"transparent"},skeleton:{baseColor:"#1e293b",highlightColor:"#334155"}},bh={colors:{primary:"#e11d48",primaryDark:"#be123c",primaryLight:"#fff1f2",primaryFocus:"rgba(225, 29, 72, 0.4)"},grid:{headerBackground:"#fff1f2",headerHoverBackground:"#ffe4e6",headerSortedBackground:"#fecdd3",rowAlternateBackground:"#fff8f8",rowSelectedBackground:"#ffe4e6",rowSelectedHoverBackground:"#fecdd3",cellFocusBorder:"#e11d48",rangeBackground:"rgba(225, 29, 72, 0.10)",rangeBorder:"#e11d48"}},xh={colors:{primary:"#059669",primaryDark:"#047857",primaryLight:"#ecfdf5",primaryFocus:"rgba(5, 150, 105, 0.4)"},grid:{headerBackground:"#ecfdf5",headerHoverBackground:"#d1fae5",headerSortedBackground:"#a7f3d0",rowAlternateBackground:"#f6fdf9",rowSelectedBackground:"#d1fae5",rowSelectedHoverBackground:"#a7f3d0",cellFocusBorder:"#059669",rangeBackground:"rgba(5, 150, 105, 0.12)",rangeBorder:"#059669"}},yh={colors:{primary:"#d97706",primaryDark:"#b45309",primaryLight:"#fffbeb",primaryFocus:"rgba(217, 119, 6, 0.4)"},grid:{headerBackground:"#fffbeb",headerHoverBackground:"#fef3c7",headerSortedBackground:"#fde68a",rowAlternateBackground:"#fffdf5",rowSelectedBackground:"#fef3c7",rowSelectedHoverBackground:"#fde68a",cellFocusBorder:"#d97706",rangeBackground:"rgba(217, 119, 6, 0.12)",rangeBorder:"#d97706"}},vh={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px",cellFontSize:"12px",headerFontSize:"12px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function Ch(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}function Xs(e,t){try{const n=t.getItem(e);return n?JSON.parse(n):void 0}catch{return}}function _h(e,t,n,o){try{const r=n?Object.fromEntries(Object.entries(t).filter(([i])=>n.includes(i))):t;o.setItem(e,JSON.stringify(r))}catch{}}function Sh(e){const t=typeof e=="string"?{key:e}:e,{key:n,debounceMs:o=300,include:r,storage:i}=t,[l]=s.useState(Ch),d=i??l,a=s.useRef(r),u=s.useRef(d);s.useLayoutEffect(()=>{a.current=r,u.current=d});const[g,m]=s.useState(()=>({key:n,state:d?Xs(n,d):void 0}));let w=g.state;g.key!==n&&(w=d?Xs(n,d):void 0,m({key:n,state:w}));const y=s.useRef(null),p=s.useRef(null),f=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null);const b=p.current;p.current=null;const v=u.current;b&&v&&_h(b.key,b.state,a.current,v)},[]),h=s.useCallback(b=>{p.current&&p.current.key!==n&&f(),p.current={key:n,state:b},y.current&&clearTimeout(y.current),y.current=setTimeout(f,o)},[n,f,o]);s.useEffect(()=>f,[f]);const x=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null),p.current=null;const b=u.current;if(b)try{b.removeItem(n)}catch{}},[n]);return s.useMemo(()=>({initialState:w,onStateChange:h,clearState:x}),[w,h,x])}_e.Button=tt,_e.Cell=ns,_e.CellSelectionStats=gs,_e.Checkbox=bt,_e.ColumnVisibilityPanel=yr,_e.DataGrid=sp,_e.DataGridThemeProvider=mh,_e.FilterPanel=Ms,_e.GridToolbar=Ep,_e.GridTooltip=Sn,_e.Header=_l,_e.Input=Qe,_e.Pagination=mr,_e.Row=Zn,_e.Skeleton=ap,_e.amberTheme=yh,_e.compactTheme=vh,_e.darkTheme=wh,_e.emeraldTheme=xh,_e.exportToCsv=Kp,_e.exportToExcel=Rp,_e.exportToExcelAdvanced=uh,_e.exportToJson=qp,_e.exportToPdf=Wp,_e.formatAggregationValue=pn,_e.printGrid=Zp,_e.roseTheme=bh,_e.useAggregation=Ql,_e.useGridApiRef=Mp,_e.useGridStateStorage=Sh,_e.usePivot=fh,Object.defineProperty(_e,Symbol.toStringTag,{value:"Module"})}));
|
|
46
|
+
</style></head><body>`;r&&(w+=`<h1>${Te(r)}</h1>`),w+="<table><thead><tr>",g.forEach(f=>{w+=`<th>${Te(f.headerName||f.field)}</th>`}),w+="</tr></thead><tbody>";const y=(f,m,x="",b=!1)=>{const{text:C}=kn(f,m),E=m.type==="image"?rh(C):null;if(E!==null){const k=`<img src="${Te(E)}" alt="${Te(m.headerName||m.field)}" style="max-height:40px;border-radius:4px;">`;return b?`<td><div style="display:flex;justify-content:center;">${k}</div></td>`:`<td>${k}</td>`}return`<td>${x}${Te(C)}</td>`};if(Cn(u,i))u.forEach(f=>{const m=" ".repeat(f.depth*4);if(f.type==="group-header")w+=`<tr class="group-header"><td colspan="${g.length}">${m}${Te(Qt(f,t))}</td></tr>`;else if(f.type==="leaf"&&f.row){const x=f.row;w+="<tr>",g.forEach((b,C)=>{w+=y(x,b,C===0?m:"")}),w+="</tr>"}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const x=f.type==="grand-total",b=tn(g,f.aggregatedValues,h);w+=`<tr class="${x?"grand-total":"group-subtotal"}">`,g.forEach((C,E)=>{if(E===0){w+=`<td>${x?"":m}${Te(Jt(x?"Grand Total":"Subtotal",b[0]))}</td>`;return}w+=b[E]?`<td style="text-align:right;">${Te(b[E])}</td>`:"<td></td>"}),w+="</tr>"}});else{const f=yn(e,i,l);if(f.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}f.forEach(x=>{w+="<tr>",g.forEach(b=>{w+=y(x,b,"",!0)}),w+="</tr>"});const m=Yt(f,yt(i),t,d,a);m&&(w+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',g.forEach(x=>{w+=h[x.field]?`<td style="text-align:right;font-weight:bold;">${Te(h[x.field].toUpperCase())}</td>`:"<td></td>"}),w+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',tn(g,m,h).forEach(x=>{w+=x?`<td style="text-align:right;">${Te(x)}</td>`:"<td></td>"}),w+="</tr></tfoot>")}w+="</tbody></table></body></html>",o.document.open(),o.document.write(w),o.document.close(),o.document.title=r||"Print Preview",o.focus();let p=!1;o.onload=()=>{p||(p=!0,o.print(),setTimeout(()=>{o.close()},100))},setTimeout(()=>{!p&&o&&!o.closed&&(p=!0,o.print(),setTimeout(()=>{o.closed||o.close()},100))},500)}catch(r){if(console.error("Print generation failed:",r),o&&!o.closed){const i=r instanceof Error?r.message:String(r);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${Te(i)}</p></div>`}}}function Lr(e,t,n){const o=new Blob([e],{type:n}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function lh(e,t){return e.type==="number"?"number":e.type==="boolean"?"boolean":e.type==="date"?"date":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date?"date":"string"}function En(e){return Number.isNaN(e.getTime())?null:new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}const sh=/^(\d{4})-(\d{2})-(\d{2})$/,ah=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/i,ch=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;function dh(e){if(e instanceof Date)return En(e);if(typeof e=="number")return Number.isFinite(e)?En(new Date(e)):null;if(typeof e!="string")return;const t=e.trim(),n=sh.exec(t);if(n){const[o,r,i]=[Number(n[1]),Number(n[2]),Number(n[3])],l=new Date(Date.UTC(o,r-1,i));return l.getUTCMonth()===r-1&&l.getUTCDate()===i?l:void 0}if(ah.test(t)){const o=new Date(t.replace(" ","T"));return Number.isNaN(o.getTime())?void 0:En(o)}}function uh(e,t){if(t==null||t==="")return null;if(e==="number"){if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="bigint"){const n=Number(t);return Number.isSafeInteger(n)?n:void 0}if(typeof t=="string"&&ch.test(t.trim())){const n=Number(t.trim());return Number.isFinite(n)?n:void 0}return}if(e==="boolean"){if(typeof t=="boolean")return t;if(typeof t=="string"){const n=t.trim().toLowerCase();if(n==="true")return!0;if(n==="false")return!1}return}return dh(t)}function Vs(e){if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:null;if(e instanceof Date)return En(e);if(typeof e=="object")try{return JSON.stringify(e)??String(e)}catch{return String(e)}return String(e)}function fh(e,t){const n=vn(e,t),o=lh(t,n);if(o!=="string"){const r=uh(o,n);if(r!=null)return r;if(!t.valueFormatter)return r===null?null:Vs(n)}return t.valueFormatter?_n(e,t,n):Vs(n)}const zs="#,##0",gh="#,##0.##";function ph(e){return Number.isInteger(e)?zs:gh}function Ks(e,t){if(t?.numFmt)return t.numFmt;if(e.type==="date")return"yyyy-mm-dd"}function js(e,t,n){if(!(t?.numFmt||typeof n!="number"||e.type!=="number"))return ph(n)}function hh(e,t){if(t!=null)return t;const n=e.width??120;return Math.min(60,Math.max(8,(n-5)/7))}function mh(e){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e.length>=6&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56?"gif":null}function Us(e,t){const n=vn(e,t);return typeof n=="string"&&n?n:null}async function wh(e){const t=await Promise.allSettled(e.map(async o=>{let r;if(o.startsWith("data:")){const l=o.slice(o.indexOf(",")+1),d=atob(l);r=new Uint8Array(d.length);for(let a=0;a<d.length;a++)r[a]=d.charCodeAt(a)}else{const l=await fetch(o,{mode:"cors"});if(!l.ok)throw new Error(`HTTP ${l.status}`);r=new Uint8Array(await l.arrayBuffer())}const i=mh(r);if(!i)throw new Error("unsupported image format (only PNG, JPEG and GIF can be embedded)");return{url:o,buffer:r.slice().buffer,ext:i}})),n=new Map;return t.forEach((o,r)=>{o.status==="fulfilled"?n.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${e[r]}" (CORS/network error or unsupported format — raw URL written as fallback):`,o.reason)}),n}async function bh(e,t,n={}){const{fileName:o="export.xlsx",sheets:r,columnStyles:i={},headerFillColor:l="#f1f5f9",headerTextColor:d="#334155",headerFontSize:a=10,bodyFontSize:u=10,aggregationResult:g=null,aggregationModel:h=null,selectedRows:w,getRowId:y,groupedRows:p,groupHeaderFillColor:f="#e8eaf6",groupSubtotalFillColor:m="#f0f4ff"}=n,x=(await import("exceljs")).default,b=new x.Workbook;b.creator="OpenGridX",b.created=new Date;const C=t,E=Dt(C),k=e,N=yt(w)?ss(k,w,y):[],M=r??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],S=new Set,F=new Map,I=(v,V)=>{const R=V[v.field],Q=h?.[v.field];if(R==null)return{value:null};const G=fi(v,Q,R);return typeof G=="number"?Number.isFinite(G)?ui(Q)?{value:G,numFmt:zs}:{value:G,numFmt:js(v,i[v.field],G)}:{value:null}:G instanceof Date?{value:En(G)}:{value:vr(v,Q,R,V)}};for(const v of M){if("type"in v&&v.type==="summary"){if(!g||!h)continue;const Z=b.addWorksheet(_r(v.name??"Summary",S));Z.addRow(["Summary / Aggregation Totals"]),Z.getRow(1).font={bold:!0,size:a+2,color:{argb:Ke(d)}},Z.addRow([]),Z.addRow(["Column","Function","Value"]).eachCell(O=>{O.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(l)}},O.font={bold:!0,size:a,color:{argb:Ke(d)}},O.border=Rs()}),E.forEach(O=>{const P=h[O.field];if(P==null||g[O.field]==null)return;const{value:T,numFmt:X}=I(O,g),ee=Z.addRow([O.headerName??O.field,P.toUpperCase(),T]).getCell(3),q=X??Ks(O,i[O.field]);q&&(ee.numFmt=q),ee.alignment={horizontal:"right"},ee.font={bold:!0,size:u}}),Z.getColumn(1).width=20,Z.getColumn(2).width=12,Z.getColumn(3).width=18;continue}const V=v,{name:R="Data",rows:Q="all",includeHeaders:G=!0,includeSummary:W=!1,autoFilter:H=!0,frozenHeader:ie=!0,alternateRowColor:oe="#f8fafc"}=V,ue=Q==="all"&&!!(p&&p.length>0),se=Q==="selected"?N:ue?p.flatMap(Z=>Z.type==="leaf"&&Z.row?[Z.row]:[]):k,U=E.filter(Z=>i[Z.field]?.embedImage);if(U.length>0){const Z=[],$=new Set;if(se.forEach(O=>{U.forEach(P=>{const T=Us(O,P);T&&!F.has(T)&&!$.has(T)&&(Z.push(T),$.add(T))})}),Z.length>0){const O=await wh(Z);for(const[P,{buffer:T,extension:X}]of O){const B=b.addImage({buffer:T,extension:X});F.set(P,B)}}}const te=b.addWorksheet(_r(R,S));te.columns=E.map(Z=>({key:Z.field,width:hh(Z,i[Z.field]?.width),style:{numFmt:Ks(Z,i[Z.field])}}));const ce=(Z,$)=>{E.forEach((O,P)=>$(Z.getCell(P+1),O,P+1))};if(G){const Z=E.map(O=>O.headerName??O.field),$=te.addRow(Z);$.height=20,ce($,(O,P)=>{O.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(l)}},O.font={bold:!0,size:a,color:{argb:Ke(d)}},O.alignment={horizontal:i[P.field]?.alignment??(P.type==="number"?"right":"left"),vertical:"middle"},O.border=Rs()}),H&&(te.autoFilter={from:{row:1,column:1},to:{row:1,column:E.length}}),ie?te.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:te.views=[{showGridLines:!1}]}let z=G?1:0;const re=(Z,$,O)=>{const P=E.map(B=>i[B.field]?.embedImage?"":fh(Z,B)),T=te.addRow(P);T.font={size:u},O>0&&(T.outlineLevel=O);const X=!!oe&&$%2===1;if(ce(T,(B,ee,q)=>{const Y=js(ee,i[ee.field],P[q-1]);Y&&(B.numFmt=Y),X&&oe&&(B.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(oe)}}),B.alignment={horizontal:i[ee.field]?.alignment??(ee.type==="number"?"right":"left"),vertical:"middle"},B.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}}}),U.length>0){const B=U.reduce((Y,ne)=>Math.max(Y,i[ne.field]?.imageHeight??40),0),ee=Math.ceil(B/1.333),q=ee*1.333;T.height=ee,U.forEach(Y=>{const ne=E.indexOf(Y),me=Us(Z,Y),j=me?F.get(me):void 0;if(j===void 0){T.getCell(ne+1).value=me??"";return}const le=i[Y.field],we=le?.imageWidth??40,pe=le?.imageHeight??40,Ce=(te.getColumn(ne+1).width??8)*7+5,be=Math.max(0,Ce-we)/2,de=Math.max(0,q-pe)/2;te.addImage(j,{tl:{col:ne,row:z,nativeColOff:Math.floor(be*9525),nativeRowOff:Math.floor(de*9525)},ext:{width:we,height:pe},editAs:"oneCell"})})}else T.height=16;z++},K=Z=>Qt(Z,C),J=(Z,$,O,P,T)=>{const X=E.map((ee,q)=>q===0&&$[ee.field]==null?{value:Z}:I(ee,$)),B=te.addRow(X.map(ee=>ee.value));B.height=18,P>0&&(B.outlineLevel=P),B.font={bold:T,italic:!T,size:u,color:{argb:Ke(d)}},ce(B,(ee,q,Y)=>{const ne=X[Y-1].numFmt;ne&&(ee.numFmt=ne),ee.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(O)}},ee.alignment={horizontal:Y===1?"left":q.type==="number"?"right":"left",vertical:"middle"},ee.border=qs()}),z++};let ae=!1;if(ue){let Z=0;p.forEach($=>{if($.type==="group-header"){const O=te.addRow([K($)]);O.height=18,$.depth>0&&(O.outlineLevel=$.depth),O.font={bold:!0,size:u,color:{argb:Ke(d)}};for(let P=1;P<=E.length;P++)O.getCell(P).fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(f)}};O.getCell(1).alignment={horizontal:"left",vertical:"middle",indent:$.depth},z++,Z=0}else $.type==="leaf"&&$.row?re($.row,Z++,$.depth):$.type==="group-subtotal"&&$.aggregatedValues?J("Subtotal",$.aggregatedValues,m,$.depth,!1):$.type==="grand-total"&&$.aggregatedValues&&(J("Grand Total",$.aggregatedValues,l,0,!0),ae=!0)}),te.properties.outlineProperties={summaryBelow:!0,summaryRight:!1}}else se.forEach((Z,$)=>re(Z,$,0));const fe=Yt(se,Q==="selected",C,g,h);if(W&&!ae&&fe&&h){const Z=E.map(T=>{const X=h[T.field];return X?X.toUpperCase():""}),$=te.addRow(Z);$.height=16,$.font={size:u-1,italic:!0,color:{argb:"FF94a3b8"}},ce($,T=>{T.alignment={horizontal:"right",vertical:"middle"},T.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const O=E.map(T=>h[T.field]==null?{value:null}:I(T,fe)),P=te.addRow(O.map(T=>T.value));P.height=18,P.font={bold:!0,size:u,color:{argb:Ke(d)}},ce(P,(T,X,B)=>{const ee=O[B-1].numFmt;ee&&(T.numFmt=ee),T.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ke(l)}},T.alignment={horizontal:"right",vertical:"middle"},T.border=qs()})}}const A=await b.xlsx.writeBuffer(),_=new Blob([A],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),L=URL.createObjectURL(_),D=document.createElement("a");D.href=L,D.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(D),D.click(),document.body.removeChild(D),URL.revokeObjectURL(L)}function Ke(e){const t=e.replace("#","");return t.length===3?"FF"+t.split("").map(n=>n+n).join(""):t.length===6?"FF"+t:"FF"+t.padEnd(6,"0")}function Rs(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function qs(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}function xh(e,t,n,o){return s.useMemo(()=>o?Ai(e,t,n):Ro,[e,t,n,o])}const Xs={"--ogx-grid-row-selected-background":"var(--ogx-color-primary-light)","--ogx-grid-row-selected-hover-background":"color-mix(in srgb, var(--ogx-color-primary) 14%, var(--ogx-color-primary-light))","--ogx-grid-cell-focus-border":"var(--ogx-color-primary)","--ogx-range-background":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-range-border":"var(--ogx-color-primary)","--ogx-fill-handle-color":"var(--ogx-range-border)","--ogx-toolbar-btn-primary-bg":"var(--ogx-color-primary)","--ogx-toolbar-btn-primary-hover":"var(--ogx-color-primary-dark)","--ogx-toolbar-input-focus-border":"var(--ogx-color-primary)","--ogx-toolbar-input-focus-shadow":"0 0 0 3px color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-bg":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-text":"var(--ogx-color-primary-dark)","--ogx-overlay-item-selected-bg":"color-mix(in srgb, var(--ogx-color-primary) 8%, transparent)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary-dark)"},Ys={"--ogx-color-primary":"#3b82f6","--ogx-color-primary-dark":"#2563eb","--ogx-color-primary-light":"#eff6ff","--ogx-color-primary-focus":"rgba(59, 130, 246, 0.5)","--ogx-color-secondary":"#8b5cf6","--ogx-color-secondary-dark":"#7c3aed","--ogx-color-secondary-light":"#f5f3ff","--ogx-color-white":"#ffffff","--ogx-color-black":"#0f172a","--ogx-color-gray-50":"#f8fafc","--ogx-color-gray-100":"#f1f5f9","--ogx-color-gray-200":"#e2e8f0","--ogx-color-gray-300":"#cbd5e1","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#64748b","--ogx-color-gray-600":"#475569","--ogx-color-gray-700":"#334155","--ogx-color-gray-800":"#1e293b","--ogx-color-gray-900":"#0f172a","--ogx-border-color":"#e2e8f0","--ogx-border-color-hover":"#cbd5e1","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.05)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02)","--ogx-grid-background":"#ffffff","--ogx-grid-border-color":"#e2e8f0","--ogx-grid-header-background":"#f8fafc","--ogx-grid-header-text":"#334155","--ogx-grid-header-hover-background":"#f1f5f9","--ogx-grid-header-sorted-background":"#f8fafc","--ogx-grid-row-text":"#1e293b","--ogx-grid-row-hover-background":"#f8fafc","--ogx-grid-row-alternate-background":"transparent","--ogx-checkbox-bg":"#ffffff","--ogx-checkbox-border":"#94a3b8","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.05)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.05)",...{"--ogx-toolbar-background":"var(--ogx-grid-header-background)","--ogx-toolbar-text":"var(--ogx-grid-header-text)","--ogx-toolbar-border":"var(--ogx-grid-border-color)","--ogx-toolbar-btn-bg":"transparent","--ogx-toolbar-btn-hover":"var(--ogx-grid-header-hover-background)","--ogx-toolbar-btn-text":"var(--ogx-grid-header-text)","--ogx-toolbar-input-bg":"var(--ogx-grid-background)","--ogx-toolbar-input-text":"var(--ogx-grid-row-text)","--ogx-toolbar-chip-bg":"transparent","--ogx-toolbar-chip-text":"var(--ogx-grid-row-text)"},"--ogx-toolbar-btn-primary-text":"#ffffff","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-text":"#ef4444","--ogx-toolbar-input-border":"#cbd5e1","--ogx-overlay-background":"#ffffff","--ogx-overlay-text":"#1e293b","--ogx-overlay-border":"#e2e8f0","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.06)","--ogx-overlay-item-hover-bg":"#f8fafc","--ogx-overlay-item-hover-text":"#0f172a","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-overlay-item-danger-text":"#ef4444","--ogx-scrollbar-thumb":"#cbd5e1","--ogx-scrollbar-track":"transparent","--ogx-scrollbar-size":"8px","--ogx-skeleton-base":"#f1f5f9","--ogx-skeleton-highlight":"#ffffff",...Xs},yh={...Ys,"--ogx-color-primary":"#60a5fa","--ogx-color-primary-dark":"#3b82f6","--ogx-color-primary-light":"#1e3a5f","--ogx-color-primary-focus":"rgba(96, 165, 250, 0.4)","--ogx-color-white":"#0f172a","--ogx-color-black":"#f8fafc","--ogx-color-gray-50":"#1e293b","--ogx-color-gray-100":"#334155","--ogx-color-gray-200":"#475569","--ogx-color-gray-300":"#64748b","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#cbd5e1","--ogx-color-gray-600":"#e2e8f0","--ogx-color-gray-700":"#e2e8f0","--ogx-color-gray-800":"#f1f5f9","--ogx-color-gray-900":"#f8fafc","--ogx-border-color":"#334155","--ogx-border-color-hover":"#475569","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.3)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.3)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.3)","--ogx-grid-background":"#0f172a","--ogx-grid-border-color":"#334155","--ogx-grid-header-background":"#1e293b","--ogx-grid-header-text":"#e2e8f0","--ogx-grid-header-hover-background":"#334155","--ogx-grid-header-sorted-background":"#1e3a5f","--ogx-grid-row-text":"#cbd5e1","--ogx-grid-row-hover-background":"#1e293b","--ogx-grid-row-alternate-background":"#162032","--ogx-checkbox-bg":"#1e293b","--ogx-checkbox-border":"#64748b","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.25)","--ogx-toolbar-btn-danger-text":"#fca5a5","--ogx-toolbar-input-border":"#334155","--ogx-overlay-background":"#1e293b","--ogx-overlay-text":"#cbd5e1","--ogx-overlay-border":"#334155","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3), 0 0 0 1px rgba(0,0,0,0.2)","--ogx-overlay-item-hover-bg":"#334155","--ogx-overlay-item-hover-text":"#f1f5f9","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-overlay-item-danger-text":"#fca5a5","--ogx-scrollbar-thumb":"#475569","--ogx-skeleton-base":"#1e293b","--ogx-skeleton-highlight":"#334155",...Xs,"--ogx-toolbar-chip-active-text":"var(--ogx-color-primary)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary)"},Ch=[50,100,200,300,400,500,600,700,800,900];function vh(e){const t={};function n(o,r){r!==void 0&&(t[o]=r)}if(e.colors){const o=e.colors;if(n("--ogx-color-primary",o.primary),n("--ogx-color-primary-dark",o.primaryDark),n("--ogx-color-primary-light",o.primaryLight),n("--ogx-color-primary-focus",o.primaryFocus),n("--ogx-color-secondary",o.secondary),n("--ogx-color-secondary-dark",o.secondaryDark),n("--ogx-color-secondary-light",o.secondaryLight),n("--ogx-color-success",o.success),n("--ogx-color-warning",o.warning),n("--ogx-color-error",o.error),n("--ogx-color-info",o.info),n("--ogx-color-white",o.white),n("--ogx-color-black",o.black),o.gray)for(const r of Ch)n(`--ogx-color-gray-${r}`,o.gray[r])}if(e.typography){const o=e.typography;n("--ogx-font-family",o.fontFamily),n("--ogx-font-family-mono",o.fontFamilyMono),n("--ogx-font-size-xs",o.fontSizeXs),n("--ogx-font-size-sm",o.fontSizeSm),n("--ogx-font-size-md",o.fontSizeMd),n("--ogx-font-size-lg",o.fontSizeLg),n("--ogx-font-size-xl",o.fontSizeXl)}if(e.spacing){const o=e.spacing;n("--ogx-spacing-xs",o.xs),n("--ogx-spacing-sm",o.sm),n("--ogx-spacing-md",o.md),n("--ogx-spacing-lg",o.lg),n("--ogx-spacing-xl",o.xl),n("--ogx-spacing-xxl",o.xxl)}if(e.borders){const o=e.borders;n("--ogx-border-width-thin",o.widthThin),n("--ogx-border-width-medium",o.widthMedium),n("--ogx-border-width-thick",o.widthThick),n("--ogx-border-radius-sm",o.radiusSm),n("--ogx-border-radius-md",o.radiusMd),n("--ogx-border-radius-lg",o.radiusLg),n("--ogx-border-radius-xl",o.radiusXl),n("--ogx-border-color",o.color),n("--ogx-border-color-hover",o.colorHover)}if(e.shadows){const o=e.shadows;n("--ogx-shadow-sm",o.sm),n("--ogx-shadow-md",o.md),n("--ogx-shadow-lg",o.lg),n("--ogx-shadow-xl",o.xl)}if(e.grid){const o=e.grid;n("--ogx-grid-row-height-compact",o.rowHeightCompact),n("--ogx-grid-row-height-standard",o.rowHeightStandard),n("--ogx-row-height",o.rowHeightStandard),n("--ogx-grid-row-height-comfortable",o.rowHeightComfortable),n("--ogx-grid-header-height",o.headerHeight),n("--ogx-header-height",o.headerHeight),n("--ogx-grid-cell-padding-x",o.cellPaddingX),n("--ogx-grid-cell-padding-y",o.cellPaddingY),n("--ogx-grid-cell-font-size",o.cellFontSize),n("--ogx-grid-header-font-size",o.headerFontSize),n("--ogx-grid-background",o.background),n("--ogx-grid-border-color",o.borderColor),n("--ogx-grid-header-background",o.headerBackground),n("--ogx-grid-header-text",o.headerText),n("--ogx-grid-header-hover-background",o.headerHoverBackground),n("--ogx-grid-header-sorted-background",o.headerSortedBackground),n("--ogx-grid-row-text",o.rowText),n("--ogx-grid-row-hover-background",o.rowHoverBackground),n("--ogx-grid-row-alternate-background",o.rowAlternateBackground),n("--ogx-grid-row-selected-background",o.rowSelectedBackground),n("--ogx-grid-row-selected-hover-background",o.rowSelectedHoverBackground),n("--ogx-grid-cell-focus-border",o.cellFocusBorder),n("--ogx-range-background",o.rangeBackground),n("--ogx-range-border",o.rangeBorder),n("--ogx-fill-handle-color",o.fillHandleColor),n("--ogx-grid-pinned-left-shadow",o.pinnedLeftShadow),n("--ogx-grid-pinned-right-shadow",o.pinnedRightShadow),n("--ogx-checkbox-bg",o.checkboxBg),n("--ogx-checkbox-border",o.checkboxBorder)}if(e.transitions){const o=e.transitions;n("--ogx-transition-duration-fast",o.durationFast),n("--ogx-transition-duration-normal",o.durationNormal),n("--ogx-transition-duration-slow",o.durationSlow),n("--ogx-transition-easing",o.easing)}if(e.toolbar){const o=e.toolbar;n("--ogx-toolbar-background",o.background),n("--ogx-toolbar-text",o.text),n("--ogx-toolbar-border",o.border),n("--ogx-toolbar-btn-bg",o.buttonBackground),n("--ogx-toolbar-btn-hover",o.buttonHoverBackground),n("--ogx-toolbar-btn-text",o.buttonText),n("--ogx-toolbar-btn-primary-bg",o.buttonPrimaryBackground),n("--ogx-toolbar-btn-primary-hover",o.buttonPrimaryHoverBackground),n("--ogx-toolbar-btn-primary-text",o.buttonPrimaryText),n("--ogx-toolbar-btn-danger-bg",o.buttonDangerBackground),n("--ogx-toolbar-btn-danger-hover",o.buttonDangerHoverBackground),n("--ogx-toolbar-btn-danger-text",o.buttonDangerText),n("--ogx-toolbar-input-bg",o.inputBackground),n("--ogx-toolbar-input-text",o.inputText),n("--ogx-toolbar-input-border",o.inputBorder),n("--ogx-toolbar-input-focus-border",o.inputFocusBorder),n("--ogx-toolbar-input-focus-shadow",o.inputFocusShadow),n("--ogx-toolbar-chip-bg",o.chipBackground),n("--ogx-toolbar-chip-text",o.chipText),n("--ogx-toolbar-chip-active-bg",o.chipActiveBackground),n("--ogx-toolbar-chip-active-text",o.chipActiveText)}if(e.overlays){const o=e.overlays;n("--ogx-overlay-background",o.background),n("--ogx-overlay-text",o.text),n("--ogx-overlay-border",o.border),n("--ogx-overlay-shadow",o.shadow),n("--ogx-overlay-item-hover-bg",o.itemHoverBackground),n("--ogx-overlay-item-hover-text",o.itemHoverText),n("--ogx-overlay-item-selected-bg",o.itemSelectedBackground),n("--ogx-overlay-item-selected-text",o.itemSelectedText),n("--ogx-overlay-item-danger-bg",o.itemDangerBackground),n("--ogx-overlay-item-danger-text",o.itemDangerText)}if(e.scrollbar){const o=e.scrollbar;n("--ogx-scrollbar-thumb",o.thumbColor),n("--ogx-scrollbar-track",o.trackColor),n("--ogx-scrollbar-size",o.size)}if(e.skeleton){const o=e.skeleton;n("--ogx-skeleton-base",o.baseColor),n("--ogx-skeleton-highlight",o.highlightColor)}return t}function _h({theme:e,children:t,className:n,style:o}){const r=s.useMemo(()=>({...e.mode==="dark"?yh:Ys,...vh(e)}),[e]);return c.jsx(ji.Provider,{value:e,children:c.jsx("div",{className:`ogx-theme-provider ${n||""}`.trim(),style:{...o,...r},children:t})})}const Sh={mode:"dark",colors:{primary:"#60a5fa",primaryDark:"#3b82f6",primaryLight:"#1e3a5f",primaryFocus:"rgba(96, 165, 250, 0.4)"},grid:{background:"#0f172a",headerBackground:"#1e293b",headerText:"#e2e8f0",headerHoverBackground:"#334155",headerSortedBackground:"#1e3a5f",rowText:"#cbd5e1",borderColor:"#334155",rowHoverBackground:"#1e293b",rowAlternateBackground:"#162032",rowSelectedBackground:"#1e3a5f",rowSelectedHoverBackground:"#1d4ed8",cellFocusBorder:"#60a5fa",rangeBackground:"rgba(96, 165, 250, 0.18)",rangeBorder:"#60a5fa",checkboxBg:"#1e293b",checkboxBorder:"#64748b"},borders:{color:"#334155",colorHover:"#475569"},shadows:{sm:"0 1px 2px 0 rgba(0, 0, 0, 0.3)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.3)"},toolbar:{background:"#1e293b",text:"#cbd5e1",border:"#334155",buttonBackground:"transparent",buttonHoverBackground:"#334155",buttonText:"#e2e8f0",buttonPrimaryBackground:"#3b82f6",buttonPrimaryHoverBackground:"#2563eb",buttonPrimaryText:"#ffffff",buttonDangerBackground:"rgba(239, 68, 68, 0.15)",buttonDangerHoverBackground:"rgba(239, 68, 68, 0.25)",buttonDangerText:"#fca5a5",inputBackground:"#0f172a",inputText:"#f8fafc",inputBorder:"#334155",inputFocusBorder:"#60a5fa",inputFocusShadow:"0 0 0 3px rgba(96, 165, 250, 0.2)",chipBackground:"#1e293b",chipText:"#94a3b8",chipActiveBackground:"rgba(96, 165, 250, 0.2)",chipActiveText:"#60a5fa"},overlays:{background:"#1e293b",text:"#f8fafc",border:"#334155",shadow:"0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3)",itemHoverBackground:"#334155",itemHoverText:"#ffffff",itemSelectedBackground:"rgba(96, 165, 250, 0.15)",itemSelectedText:"#60a5fa",itemDangerBackground:"rgba(239, 68, 68, 0.15)",itemDangerText:"#fca5a5"},scrollbar:{thumbColor:"rgba(148, 163, 184, 0.2)",trackColor:"transparent"},skeleton:{baseColor:"#1e293b",highlightColor:"#334155"}},kh={colors:{primary:"#e11d48",primaryDark:"#be123c",primaryLight:"#fff1f2",primaryFocus:"rgba(225, 29, 72, 0.4)"},grid:{headerBackground:"#fff1f2",headerHoverBackground:"#ffe4e6",headerSortedBackground:"#fecdd3",rowAlternateBackground:"#fff8f8",rowSelectedBackground:"#ffe4e6",rowSelectedHoverBackground:"#fecdd3",cellFocusBorder:"#e11d48",rangeBackground:"rgba(225, 29, 72, 0.10)",rangeBorder:"#e11d48"}},Eh={colors:{primary:"#059669",primaryDark:"#047857",primaryLight:"#ecfdf5",primaryFocus:"rgba(5, 150, 105, 0.4)"},grid:{headerBackground:"#ecfdf5",headerHoverBackground:"#d1fae5",headerSortedBackground:"#a7f3d0",rowAlternateBackground:"#f6fdf9",rowSelectedBackground:"#d1fae5",rowSelectedHoverBackground:"#a7f3d0",cellFocusBorder:"#059669",rangeBackground:"rgba(5, 150, 105, 0.12)",rangeBorder:"#059669"}},Mh={colors:{primary:"#d97706",primaryDark:"#b45309",primaryLight:"#fffbeb",primaryFocus:"rgba(217, 119, 6, 0.4)"},grid:{headerBackground:"#fffbeb",headerHoverBackground:"#fef3c7",headerSortedBackground:"#fde68a",rowAlternateBackground:"#fffdf5",rowSelectedBackground:"#fef3c7",rowSelectedHoverBackground:"#fde68a",cellFocusBorder:"#d97706",rangeBackground:"rgba(217, 119, 6, 0.12)",rangeBorder:"#d97706"}},Nh={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px",cellFontSize:"12px",headerFontSize:"12px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function Ih(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}function Js(e,t){try{const n=t.getItem(e);return n?JSON.parse(n):void 0}catch{return}}function Lh(e,t,n,o){try{const r=n?Object.fromEntries(Object.entries(t).filter(([i])=>n.includes(i))):t;o.setItem(e,JSON.stringify(r))}catch{}}function Ah(e){const t=typeof e=="string"?{key:e}:e,{key:n,debounceMs:o=300,include:r,storage:i}=t,[l]=s.useState(Ih),d=i??l,a=s.useRef(r),u=s.useRef(d);s.useLayoutEffect(()=>{a.current=r,u.current=d});const[g,h]=s.useState(()=>({key:n,state:d?Js(n,d):void 0}));let w=g.state;g.key!==n&&(w=d?Js(n,d):void 0,h({key:n,state:w}));const y=s.useRef(null),p=s.useRef(null),f=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null);const b=p.current;p.current=null;const C=u.current;b&&C&&Lh(b.key,b.state,a.current,C)},[]),m=s.useCallback(b=>{p.current&&p.current.key!==n&&f(),p.current={key:n,state:b},y.current&&clearTimeout(y.current),y.current=setTimeout(f,o)},[n,f,o]);s.useEffect(()=>f,[f]);const x=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null),p.current=null;const b=u.current;if(b)try{b.removeItem(n)}catch{}},[n]);return s.useMemo(()=>({initialState:w,onStateChange:m,clearState:x}),[w,m,x])}_e.Button=tt,_e.Cell=rs,_e.CellSelectionStats=hs,_e.Checkbox=bt,_e.ColumnVisibilityPanel=Cr,_e.DataGrid=pp,_e.DataGridThemeProvider=_h,_e.FilterPanel=Is,_e.GridToolbar=Tp,_e.GridTooltip=Sn,_e.Header=kl,_e.Input=Qe,_e.Pagination=wr,_e.Row=Zn,_e.Skeleton=hp,_e.amberTheme=Mh,_e.compactTheme=Nh,_e.darkTheme=Sh,_e.emeraldTheme=Eh,_e.exportToCsv=Jp,_e.exportToExcel=eh,_e.exportToExcelAdvanced=bh,_e.exportToJson=th,_e.exportToPdf=qp,_e.formatAggregationValue=pn,_e.printGrid=ih,_e.roseTheme=kh,_e.useAggregation=ts,_e.useGridApiRef=Fp,_e.useGridStateStorage=Ah,_e.usePivot=xh,Object.defineProperty(_e,Symbol.toStringTag,{value:"Module"})}));
|
|
47
47
|
//# sourceMappingURL=opengridx.umd.js.map
|