@opencorestack/opengridx 1.2.2 → 1.3.0

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.
@@ -1,16 +1,21 @@
1
- (function(re,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],l):(re=typeof globalThis<"u"?globalThis:re||self,l(re.OpenGridX={},re.React,re.ReactDOM))})(this,(function(re,l,ze){"use strict";var _t={exports:{}},st={};var hn;function Zn(){if(hn)return st;hn=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(o,i,s){var d=null;if(s!==void 0&&(d=""+s),i.key!==void 0&&(d=""+i.key),"key"in i){s={};for(var a in i)a!=="key"&&(s[a]=i[a])}else s=i;return i=s.ref,{$$typeof:n,type:o,key:d,ref:i!==void 0?i:null,props:s}}return st.Fragment=t,st.jsx=e,st.jsxs=e,st}var at={};var pn;function eo(){return pn||(pn=1,process.env.NODE_ENV!=="production"&&(function(){function n(v){if(v==null)return null;if(typeof v=="function")return v.$$typeof===_?null:v.displayName||v.name||null;if(typeof v=="string")return v;switch(v){case E:return"Fragment";case j:return"Profiler";case N:return"StrictMode";case x:return"Suspense";case f:return"SuspenseList";case M:return"Activity"}if(typeof v=="object")switch(typeof v.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),v.$$typeof){case y:return"Portal";case k:return v.displayName||"Context";case w:return(v._context.displayName||"Context")+".Consumer";case g:var R=v.render;return v=v.displayName,v||(v=R.displayName||R.name||"",v=v!==""?"ForwardRef("+v+")":"ForwardRef"),v;case S:return R=v.displayName||null,R!==null?R:n(v.type)||"Memo";case P:R=v._payload,v=v._init;try{return n(v(R))}catch{}}return null}function t(v){return""+v}function e(v){try{t(v);var R=!1}catch{R=!0}if(R){R=console;var W=R.error,$=typeof Symbol=="function"&&Symbol.toStringTag&&v[Symbol.toStringTag]||v.constructor.name||"Object";return W.call(R,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",$),t(v)}}function o(v){if(v===E)return"<>";if(typeof v=="object"&&v!==null&&v.$$typeof===P)return"<...>";try{var R=n(v);return R?"<"+R+">":"<...>"}catch{return"<...>"}}function i(){var v=I.A;return v===null?null:v.getOwner()}function s(){return Error("react-stack-top-frame")}function d(v){if(L.call(v,"key")){var R=Object.getOwnPropertyDescriptor(v,"key").get;if(R&&R.isReactWarning)return!1}return v.key!==void 0}function a(v,R){function W(){V||(V=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",R))}W.isReactWarning=!0,Object.defineProperty(v,"key",{get:W,configurable:!0})}function u(){var v=n(this.type);return T[v]||(T[v]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),v=this.props.ref,v!==void 0?v:null}function c(v,R,W,$,G,q){var Y=W.ref;return v={$$typeof:C,type:v,key:R,props:W,_owner:$},(Y!==void 0?Y:null)!==null?Object.defineProperty(v,"ref",{enumerable:!1,get:u}):Object.defineProperty(v,"ref",{enumerable:!1,value:null}),v._store={},Object.defineProperty(v._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(v,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(v,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:G}),Object.defineProperty(v,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(v.props),Object.freeze(v)),v}function p(v,R,W,$,G,q){var Y=R.children;if(Y!==void 0)if($)if(F(Y)){for($=0;$<Y.length;$++)m(Y[$]);Object.freeze&&Object.freeze(Y)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else m(Y);if(L.call(R,"key")){Y=n(v);var te=Object.keys(R).filter(function(J){return J!=="key"});$=0<te.length?"{key: someKey, "+te.join(": ..., ")+": ...}":"{key: someKey}",H[Y+$]||(te=0<te.length?"{"+te.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ (function(ie,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],l):(ie=typeof globalThis<"u"?globalThis:ie||self,l(ie.OpenGridX={},ie.React,ie.ReactDOM))})(this,(function(ie,l,He){"use strict";var Et={exports:{}},dt={};var pn;function eo(){if(pn)return dt;pn=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(o,i,s){var d=null;if(s!==void 0&&(d=""+s),i.key!==void 0&&(d=""+i.key),"key"in i){s={};for(var a in i)a!=="key"&&(s[a]=i[a])}else s=i;return i=s.ref,{$$typeof:n,type:o,key:d,ref:i!==void 0?i:null,props:s}}return dt.Fragment=t,dt.jsx=e,dt.jsxs=e,dt}var ct={};var xn;function to(){return xn||(xn=1,process.env.NODE_ENV!=="production"&&(function(){function n(C){if(C==null)return null;if(typeof C=="function")return C.$$typeof===_?null:C.displayName||C.name||null;if(typeof C=="string")return C;switch(C){case k:return"Fragment";case y:return"Profiler";case N:return"StrictMode";case S:return"Suspense";case h:return"SuspenseList";case I:return"Activity"}if(typeof C=="object")switch(typeof C.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),C.$$typeof){case g:return"Portal";case j:return C.displayName||"Context";case v:return(C._context.displayName||"Context")+".Consumer";case b:var P=C.render;return C=C.displayName,C||(C=P.displayName||P.name||"",C=C!==""?"ForwardRef("+C+")":"ForwardRef"),C;case E:return P=C.displayName||null,P!==null?P:n(C.type)||"Memo";case M:P=C._payload,C=C._init;try{return n(C(P))}catch{}}return null}function t(C){return""+C}function e(C){try{t(C);var P=!1}catch{P=!0}if(P){P=console;var W=P.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&C[Symbol.toStringTag]||C.constructor.name||"Object";return W.call(P,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),t(C)}}function o(C){if(C===k)return"<>";if(typeof C=="object"&&C!==null&&C.$$typeof===M)return"<...>";try{var P=n(C);return P?"<"+P+">":"<...>"}catch{return"<...>"}}function i(){var C=T.A;return C===null?null:C.getOwner()}function s(){return Error("react-stack-top-frame")}function d(C){if(L.call(C,"key")){var P=Object.getOwnPropertyDescriptor(C,"key").get;if(P&&P.isReactWarning)return!1}return C.key!==void 0}function a(C,P){function W(){H||(H=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",P))}W.isReactWarning=!0,Object.defineProperty(C,"key",{get:W,configurable:!0})}function p(){var C=n(this.type);return F[C]||(F[C]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),C=this.props.ref,C!==void 0?C:null}function c(C,P,W,R,z,U){var G=W.ref;return C={$$typeof:x,type:C,key:P,props:W,_owner:R},(G!==void 0?G:null)!==null?Object.defineProperty(C,"ref",{enumerable:!1,get:p}):Object.defineProperty(C,"ref",{enumerable:!1,value:null}),C._store={},Object.defineProperty(C._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(C,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(C,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:z}),Object.defineProperty(C,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(C.props),Object.freeze(C)),C}function f(C,P,W,R,z,U){var G=P.children;if(G!==void 0)if(R)if($(G)){for(R=0;R<G.length;R++)w(G[R]);Object.freeze&&Object.freeze(G)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else w(G);if(L.call(P,"key")){G=n(C);var ne=Object.keys(P).filter(function(J){return J!=="key"});R=0<ne.length?"{key: someKey, "+ne.join(": ..., ")+": ...}":"{key: someKey}",K[G+R]||(ne=0<ne.length?"{"+ne.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,$,Y,te,Y),H[Y+$]=!0)}if(Y=null,W!==void 0&&(e(W),Y=""+W),d(R)&&(e(R.key),Y=""+R.key),"key"in R){W={};for(var O in R)O!=="key"&&(W[O]=R[O])}else W=R;return Y&&a(W,typeof v=="function"?v.displayName||v.name||"Unknown":v),c(v,Y,W,i(),G,q)}function m(v){h(v)?v._store&&(v._store.validated=1):typeof v=="object"&&v!==null&&v.$$typeof===P&&(v._payload.status==="fulfilled"?h(v._payload.value)&&v._payload.value._store&&(v._payload.value._store.validated=1):v._store&&(v._store.validated=1))}function h(v){return typeof v=="object"&&v!==null&&v.$$typeof===C}var b=l,C=Symbol.for("react.transitional.element"),y=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),N=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),k=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),M=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),I=b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L=Object.prototype.hasOwnProperty,F=Array.isArray,A=console.createTask?console.createTask:function(){return null};b={react_stack_bottom_frame:function(v){return v()}};var V,T={},B=b.react_stack_bottom_frame.bind(b,s)(),K=A(o(s)),H={};at.Fragment=E,at.jsx=function(v,R,W){var $=1e4>I.recentlyCreatedOwnerStacks++;return p(v,R,W,!1,$?Error("react-stack-top-frame"):B,$?A(o(v)):K)},at.jsxs=function(v,R,W){var $=1e4>I.recentlyCreatedOwnerStacks++;return p(v,R,W,!0,$?Error("react-stack-top-frame"):B,$?A(o(v)):K)}})()),at}var xn;function to(){return xn||(xn=1,process.env.NODE_ENV==="production"?_t.exports=Zn():_t.exports=eo()),_t.exports}var r=to();function dt(n,t){return t?t.left?.includes(n)?"left":t.right?.includes(n)?"right":null:null}function no(n,t){const e=[],o=[],i=[];return t?(n.forEach(s=>{const d=dt(s.field,t);d==="left"?e.push(s):d==="right"?i.push(s):o.push(s)}),t.left&&e.sort((s,d)=>{const a=t.left.indexOf(s.field),u=t.left.indexOf(d.field);return a-u}),t.right&&i.sort((s,d)=>{const a=t.right.indexOf(s.field),u=t.right.indexOf(d.field);return a-u}),{left:e,center:o,right:i}):{left:e,center:n,right:i}}function Bt(n,t,e,o,i,s,d,a){const u={};if(!e)return u;const c=no(n,e);let p=0;a&&(p+=48),s&&d&&(p+=48),o&&i&&(p+=48),c.left.forEach(h=>{u[h.field]=p;const b=t[h.field]??h.width??100;p+=b});let m=0;return[...c.right].reverse().forEach(h=>{const b=t[h.field]??h.width??100;u[h.field]=m,m+=b}),u}function $t(n,t){return t?t.top?.includes(n)?"top":t.bottom?.includes(n)?"bottom":null:null}function oo(n,t){const e=[],o=[],i=[];return t?(n.forEach(s=>{const d=$t(s.id,t);d==="top"?e.push(s):d==="bottom"?i.push(s):o.push(s)}),t.top&&e.sort((s,d)=>{const a=t.top.indexOf(s.id),u=t.top.indexOf(d.id);return a-u}),t.bottom&&i.sort((s,d)=>{const a=t.bottom.indexOf(s.id),u=t.bottom.indexOf(d.id);return a-u}),{top:e,center:o,bottom:i}):{top:e,center:n,bottom:i}}function Ge(n){if(n===void 0)return{type:"auto",value:0};if(typeof n=="number")return{type:"fixed",value:n};if(typeof n=="string"){if(n.toLowerCase()==="auto")return{type:"auto",value:0};if(n.endsWith("%"))return{type:"percentage",value:parseFloat(n)};const t=parseFloat(n);if(!isNaN(t))return{type:"fixed",value:t}}return{type:"fixed",value:100}}function ro(n){const{rowHeight:t,pagination:e,paginatedUnpinnedRows:o,sortedUnpinnedRows:i,expandedRowIds:s,getDetailPanelHeight:d,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,visibleOrderedColumns:c,pinnedColumns:p,columnWidths:m,viewportWidth:h,checkboxSelection:b,hasDetailPanel:C,rowReordering:y,paginationMode:E,isLoading:N,pageSize:j}=n;return l.useMemo(()=>{const w=e?o:i,k=w.map((D,X)=>{let ee=t;if(s.has(D.id)){const de=d?.({row:D,id:D.id,rowIndex:a+X})??200;ee+=typeof de=="number"?de:parseInt(String(de),10)||200}return ee}),g=k.reduce((D,X,ee)=>(D.push((D[ee-1]||0)+X),D),[]),x=E==="infinite"&&N&&w.length>0?Math.min(j,20):0,f=(g[g.length-1]||0)+x*t,S=a*t,P=u*t,M=[],_=[],I=[],L=[];c.forEach(D=>{const X=dt(D.field,p);X==="left"?M.push(D):X==="right"?_.push(D):I.push(D)});const F=(b?48:0)+(C?48:0)+(y?48:0),A=D=>m[D.field]??D.width,V=M.reduce((D,X)=>{const ee=Ge(A(X));return D+(ee.type==="fixed"?ee.value:100)},0),T=_.reduce((D,X)=>{const ee=Ge(A(X));return D+(ee.type==="fixed"?ee.value:100)},0),B=I.reduce((D,X)=>{if(!Object.prototype.hasOwnProperty.call(m,X.field)&&X.flex&&X.flex>0){const ce=X.minWidth??150,je=typeof X.width=="number"?X.width:150;return D+(ce||je)}const de=Ge(A(X));return de.type==="fixed"?D+de.value:de.type==="percentage"?D+100:D+(X.minWidth??150)},0),K=Math.max(h-F-V-T,B),H=[],v=[],R=[];I.forEach(D=>{const X=Object.prototype.hasOwnProperty.call(m,D.field),ee=Ge(A(D));if(!X&&D.flex&&D.flex>0){R.push({col:D,flex:D.flex});return}ee.type==="fixed"?H.push({col:D,width:ee.value}):ee.type==="percentage"?v.push({col:D,percentage:ee.value}):R.push({col:D,flex:1})});const W=H.reduce((D,{width:X})=>D+X,0);let $=Math.max(0,K-W);const G=new Map;v.forEach(({col:D,percentage:X})=>{const ee=X/100*$;G.set(D.field,ee),$-=ee}),$=Math.max(0,$);const q=new Map,Y=R.map(D=>({...D,minWidth:D.col.minWidth??50,maxWidth:D.col.maxWidth??1/0,frozen:!1,computedWidth:0}));(()=>{let D=0;const X=Y.length*2;for(;D<X;){D++;const ee=Y.filter(ne=>!ne.frozen);if(ee.length===0)break;const de=ee.reduce((ne,ve)=>ne+ve.flex,0),ce=Y.reduce((ne,ve)=>ve.frozen?ne+ve.computedWidth:ne,0),je=Math.max(0,$-ce);if(de<=0){ee.forEach(ne=>{ne.computedWidth=ne.minWidth,ne.frozen=!0});break}const Fe=je/de;let Ee=0;const fe=[],qe=[];if(ee.forEach(ne=>{const ve=Fe*ne.flex;ve<ne.minWidth?(Ee+=ne.minWidth-ve,fe.push(ne)):ve>ne.maxWidth?(Ee+=ne.maxWidth-ve,qe.push(ne)):ne.computedWidth=ve}),fe.length===0&&qe.length===0){ee.forEach(ne=>ne.frozen=!0);break}Ee>0?fe.forEach(ne=>{ne.computedWidth=ne.minWidth,ne.frozen=!0}):Ee<0?qe.forEach(ne=>{ne.computedWidth=ne.maxWidth,ne.frozen=!0}):(fe.forEach(ne=>{ne.computedWidth=ne.minWidth,ne.frozen=!0}),qe.forEach(ne=>{ne.computedWidth=ne.maxWidth,ne.frozen=!0}))}})(),Y.forEach(D=>q.set(D.col.field,D.computedWidth));const O=new Map;I.forEach(D=>{let X;if(q.has(D.field))X=q.get(D.field);else{const ee=H.find(ce=>ce.col.field===D.field),de=v.find(ce=>ce.col.field===D.field);if(ee)X=ee.width;else if(de){const ce=G.get(D.field)||0;X=Math.max(D.minWidth??50,ce||100)}else X=100}L.push(X),O.set(D.field,X)});const J=I.map(D=>{const X=Y.find(ee=>ee.col.field===D.field);return{...D,width:O.get(D.field)??(typeof D.width=="number"?D.width:100),flex:X?X.flex:D.flex}}),Q=11,le=M.map((D,X)=>{const ee=Ge(A(D));return{...D,width:ee.type==="fixed"?ee.value:100,zIndex:Q+X}}),oe=11,pe=_.map((D,X)=>{const ee=Ge(A(D));return{...D,width:ee.type==="fixed"?ee.value:100,zIndex:oe+(_.length-1-X)}}),z=L.reduce((D,X)=>D+X,0),ie=V+z+T+F,se=L.reduce((D,X,ee)=>(D.push((D[ee-1]||0)+X),D),[]);return{rowHeights:k,cumulativeHeights:g,unpinnedRowsHeight:f,pinnedTopHeight:S,pinnedBottomHeight:P,leftPinnedCols:le,rightPinnedCols:pe,unpinnedColsWithWidth:J,unpinnedColWidths:L,unpinnedAccWidths:se,totalWidth:ie,leftWidth:V,rightWidth:T,unpinnedTotalWidth:z,systemColumnsWidth:F,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,unpinnedRowsLength:w.length}},[t,e,o,i,s,d,a,u,c,p,m,h,b,C,y,E,N,j])}function io(n){const{allRenderableRows:t,navigationColumns:e,checkboxSelection:o,selectedRowIds:i,handleSelectionChange:s,handleDetailPanelToggle:d,editingHandlers:a,setKeyboardMode:u,sortModel:c,handleSort:p,isCellEditable:m,pagination:h,pageSize:b,virtualization:C,viewportRef:y}=n,[E,N]=l.useState(null),j=l.useCallback(g=>{g.target===g.currentTarget&&N(x=>{if(x)return x;if(o)return{id:"HEADER",field:"__checkbox_col__"};const f=t[0],S=e[0];return f&&S?{id:f.id,field:S.field}:null})},[t,e,o]),w=l.useCallback(g=>{g.currentTarget.contains(g.relatedTarget)||N(null)},[]),k=l.useCallback(g=>{if(u(!0),!E)return;const{id:x,field:f}=E,S=!!a.editingCell;if(x==="HEADER"&&(g.key==="Enter"||g.key===" ")){g.preventDefault();const T=e.find(B=>B.field===f);if(T&&T.sortable!==!1){const B=c.find(H=>H.field===f);let K="asc";B&&(K=B.sort==="asc"?"desc":null),p(f,K)}return}if(g.key==="Enter"){if(g.preventDefault(),S)a.stopCellEdit();else if(e.find(B=>B.field===f)?.editable){const B=t.find(K=>K.id===x);B&&a.startCellEdit({id:x,field:f,value:B[f]})}return}if((g.key===" "||g.key==="Spacebar")&&!S){if(f==="__checkbox_col__"){g.preventDefault(),s(x,!i.has(x));return}if(f==="__expand_col__"){g.preventDefault(),d(x);return}}if(g.key==="Escape"){S&&(g.preventDefault(),a.stopCellEdit({cancel:!0}));return}if(S&&g.key!=="Tab")return;const P=x==="HEADER",M=P?-1:t.findIndex(T=>T.id===x),_=e.findIndex(T=>T.field===f);if(!P&&M===-1||_===-1)return;const I=(T,B,K,H,v,R=!1)=>{let W=T+K,$=B+H;return v&&H!==0&&(H>0&&$>=e.length?($=0,W++):H<0&&$<0&&($=e.length-1,W--)),!v&&($<0||$>=e.length)||W<(R?-1:0)||W>=t.length?null:{r:W,c:$}},L=(T,B,K,H,v,R=!1)=>{let W=T,$=B,G=0;const q=t.length*e.length+e.length;for(;G<q;){if(G++,W+=K,$+=H,H!==0)H>0?$>=e.length&&($=0,W++):$<0&&($=e.length-1,W--);else if($<0||$>=e.length)return null;if(W<-1||W>=t.length)return null;if(W===-1){if(!R)continue;const Q=e[$],le=Q.sortable!==!1;if(["__checkbox_col__"].includes(Q.field)||le)return{r:W,c:$};continue}const Y=t[W],te=e[$],O=["__checkbox_col__","__expand_col__","__reorder_col__"].includes(te.field);let J=te.editable||O;if(m&&!O)try{J=m({row:Y,field:te.field,value:Y[te.field],colDef:te,rowIndex:W,colIndex:$})}catch{}if(J)return{r:W,c:$}}return null};let F=M,A=_,V=!1;if(g.key==="Tab"){const T=g.shiftKey?-1:1,B=L(M,_,0,T,!0,!1);B&&(F=B.r,A=B.c,V=!0)}else if(g.key==="ArrowRight"){const T=I(M,_,0,1,!0,!0);T&&(F=T.r,A=T.c,V=!0)}else if(g.key==="ArrowLeft"){const T=I(M,_,0,-1,!0,!0);T&&(F=T.r,A=T.c,V=!0)}else if(g.key==="ArrowDown"){const T=I(M,_,1,0,!1,!0);T&&(F=T.r,A=T.c,V=!0)}else if(g.key==="ArrowUp"){const T=I(M,_,-1,0,!1,!0);T&&(F=T.r,A=T.c,V=!0)}else if(g.key==="Home")A=0,(g.ctrlKey||g.metaKey)&&(F=-1),V=!0;else if(g.key==="End")A=e.length-1,(g.ctrlKey||g.metaKey)&&(F=t.length-1),V=!0;else if(g.key==="PageUp")F=Math.max(-1,F-(h?b:10)),V=!0;else if(g.key==="PageDown"){const T=h?b:10;F=Math.min(t.length-1,F+T),V=!0}if(V&&(g.preventDefault(),S&&g.key==="Tab"&&a.stopCellEdit(),F>=-1&&F<t.length&&A>=0&&A<e.length)){const T=e[A];N(F===-1?{id:"HEADER",field:T.field}:{id:t[F].id,field:T.field});const B=y.current;if(B){const{cumulativeHeights:K,pinnedTopHeight:H,columnMetrics:v}=C,{clientHeight:R,clientWidth:W,scrollTop:$,scrollLeft:G}=B,q=F<=0?0:K[F-1],Y=K[F],te=$+H,O=$+R;let J=$;if(q<te?J=Math.max(0,q-H):Y>O&&(J=Y-R),J!==$&&(B.scrollTop=J),v){const{leftPinnedWidth:Q,rightPinnedWidth:le,unpinnedAccWidths:oe,unpinnedCols:pe,totalSpecialsWidth:z,pinnedSpecialsWidth:ie}=v,se=pe.findIndex(D=>D.field===T.field);if(se!==-1){const D=z+Q+(se>0?oe[se-1]:0),X=z+Q+oe[se],ee=G+ie+Q,de=G+W-le;let ce=G;D<ee?ce=Math.max(0,D-ie-Q):X>de&&(ce=X-W+le),ce!==G&&(B.scrollLeft=ce)}}}}},[E,t,e,a,C,i,s,d,u,c,p,m,h,b,y]);return{focusedCell:E,setFocusedCell:N,handleFocus:j,handleBlur:w,handleKeyDown:k}}const lo={rowFields:[],columnFields:[],valueFields:[]};function so(n){const{initialState:t,sortModel:e,aggregationModel:o,onAggregationModelChange:i,columnVisibilityModel:s,onColumnVisibilityModelChange:d,pinnedColumns:a,onPinnedColumnsChange:u,pivotModel:c,onPivotModelChange:p,paginationModel:m={page:0,pageSize:100},onPaginationModelChange:h,rowSelectionModel:b}=n,[C,y]=l.useState(()=>t?.sorting?.sortModel??[]),E=e!==void 0,N=E?e:C,j=o!==void 0,[w,k]=l.useState(()=>o??{}),g=j?o:w,x=l.useCallback(Q=>{j||k(Q),i?.(Q)},[j,i]),f=s!==void 0,[S,P]=l.useState(()=>t?.columns?.columnVisibilityModel??{}),M=f?s:S,_=l.useCallback(Q=>{f||P(Q),d?.(Q)},[f,d]),I=a!==void 0,[L,F]=l.useState(()=>t?.columns?.pinnedColumns??{}),A=I?a:L,V=l.useCallback(Q=>{I||F(Q),u?.(Q)},[I,u]),[T,B]=l.useState(()=>c??lo),K=c??T,H=l.useCallback(Q=>{B(Q),p?.(Q)},[p]),v=m!==void 0&&n.paginationModel!==void 0,[R,W]=l.useState(()=>t?.pagination?.paginationModel??m),$=v?m:R,G=l.useCallback(Q=>{v||W(Q),h?.(Q)},[v,h]),q=b!==void 0,[Y,te]=l.useState([]),O=q?b:Y,J=l.useMemo(()=>new Set(O),[O]);return{sortModel:N,isSortControlled:E,setInternalSortModel:y,aggregationModel:g,handleAggregationModelChange:x,columnVisibilityModel:M,handleColumnVisibilityModelChange:_,pinnedColumns:A,handlePinnedColumnsChange:V,currentPivotModel:K,handlePivotModelChange:H,effectivePaginationModel:$,handlePaginationModelChange:G,rowSelectionModel:O,selectedRowIds:J,isSelectionControlled:q,setInternalRowSelectionModel:te}}const ao={contains:(n,t)=>n==null||t==null?!1:String(n).toLowerCase().includes(String(t).toLowerCase()),equals:(n,t)=>n==null&&t==null?!0:n==null||t==null?!1:String(n).toLowerCase()===String(t).toLowerCase(),startsWith:(n,t)=>n==null||t==null?!1:String(n).toLowerCase().startsWith(String(t).toLowerCase()),endsWith:(n,t)=>n==null||t==null?!1:String(n).toLowerCase().endsWith(String(t).toLowerCase()),isEmpty:n=>n==null||String(n).trim()==="",isNotEmpty:n=>n!=null&&String(n).trim()!=="",">":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e>o},">=":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e>=o},"<":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e<o},"<=":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e<=o},"!=":(n,t)=>{if(t==null||t==="")return!0;const e=Number(n),o=Number(t);return!isNaN(e)&&!isNaN(o)?e!==o:String(n).toLowerCase()!==String(t).toLowerCase()},isAnyOf:(n,t)=>n==null||!Array.isArray(t)?!1:t.some(e=>String(n).toLowerCase()===String(e).toLowerCase()),not:(n,t)=>n==null&&t==null?!1:n==null||t==null?!0:String(n).toLowerCase()!==String(t).toLowerCase(),is:(n,t)=>{if(t==null||t==="")return!0;const e=String(n).toLowerCase(),o=String(t).toLowerCase();return e===o},"=":(n,t)=>n==null||t==null||t===""?!1:Number(n)===Number(t)};function co(n,t){const{field:e,operator:o,value:i}=t,s=n[e],d=ao[o];return d?d(s,i):(console.warn(`Unknown filter operator: ${o}`),!0)}function uo(n,t){return!t||t.length===0?!0:t.every(e=>{const o=e.toLowerCase();return Object.values(n).some(i=>i==null?!1:String(i).toLowerCase().includes(o))})}function Dt(n,t){const e=t.items??[],o=t.logicOperator??"and",i=("quickFilterValues"in t?t.quickFilterValues:void 0)??[];if(i.length>0&&!uo(n,i))return!1;if(e.length===0)return!0;const s=d=>{if("logicOperator"in d&&"items"in d){const a=d,u=a.items;return u.length===0?!0:a.logicOperator==="and"?u.every(s):u.some(s)}else return co(n,d)};return o==="and"?e.every(s):e.some(s)}function fo(n,t){if(!t)return n;const{items:e=[],quickFilterValues:o=[]}=t;return e.length===0&&(!o||o.length===0)?n:n.filter(i=>Dt(i,t))}function go(n){switch(n){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 Ht(n,t,e){if(n==null&&t==null)return 0;if(n==null)return e==="asc"?1:-1;if(t==null)return e==="asc"?-1:1;if(typeof n=="number"&&typeof t=="number")return e==="asc"?n-t:t-n;if(n instanceof Date&&t instanceof Date)return e==="asc"?n.getTime()-t.getTime():t.getTime()-n.getTime();const o=String(n).toLowerCase(),i=String(t).toLowerCase();return e==="asc"?o<i?-1:o>i?1:0:o>i?-1:o<i?1:0}function ho(n,t){if(t.length===0)return n;const e=[...n];return e.sort((o,i)=>{for(const s of t){const d=o[s.field],a=i[s.field],u=Ht(d,a,s.sort);if(u!==0)return u}return 0}),e}function po(n){const{effectiveRows:t,activeHierarchyHandlers:e,filterMode:o,filterModel:i,dataSource:s,sortModel:d,sortingMode:a,pagination:u,paginationMode:c,effectivePaginationModel:p,pinnedRows:m,isLoading:h,pageSize:b}=n,C=l.useMemo(()=>e?e.getVisibleRows()||[]:o==="server"&&s?t:fo(t,i),[t,i,e,o,s]),{top:y,center:E,bottom:N}=l.useMemo(()=>e?{top:[],center:C,bottom:[]}:oo(C,m),[C,m,e]),j=l.useMemo(()=>e||a==="server"&&s?E:ho(E,d),[E,d,e,a,s]),w=l.useMemo(()=>{if(!u||c==="server"&&s)return j;const g=p.page*p.pageSize;return j.slice(g,g+p.pageSize)},[j,u,p.page,p.pageSize,c,s]),k=l.useMemo(()=>{if(e)return E;const g=u?w:j,x=[...y,...g,...N];if(c==="infinite"&&h&&x.length>0){const f=Math.min(b,20),S=Array.from({length:f},(P,M)=>({id:`__skeleton_${M}__`,_isSkeleton:!0}));return[...x,...S]}return x},[y,w,j,N,u,e,E,c,h,b]);return{filteredRows:C,pinnedTopRows:y,unpinnedRows:E,pinnedBottomRows:N,sortedUnpinnedRows:j,paginatedUnpinnedRows:w,allRenderableRows:k}}function xo(n){const{layout:t,scrollTop:e,scrollLeft:o,viewportWidth:i,viewportHeight:s,autoHeight:d,rowReordering:a,hasDetailPanel:u,checkboxSelection:c,pinCheckboxColumn:p,pinExpandColumn:m}=n;return l.useMemo(()=>{const{unpinnedAccWidths:h,unpinnedColsWithWidth:b,leftPinnedCols:C,rightPinnedCols:y,totalWidth:E,leftWidth:N,rightWidth:j,unpinnedTotalWidth:w,systemColumnsWidth:k,cumulativeHeights:g,pinnedTopHeight:x,pinnedBottomHeight:f,unpinnedRowsHeight:S,rowHeights:P,unpinnedRowsLength:M}=t,_=i||1e3,I=d?x+S+f+50:s||600,L=6,F=Math.max(0,o-N),A=o+_-N;let V=0,T=b.length-1,B=0,K=h.length-1;for(;B<=K;){const oe=B+K>>>1;h[oe]<F?B=oe+1:K=oe-1}V=Math.max(0,B-L);for(let oe=V;oe<h.length;oe++){if((oe===0?0:h[oe-1])>A){T=Math.min(b.length-1,oe+L);break}T=Math.min(b.length-1,oe+L)}const H=V>0?h[V-1]:0,v=w-h[T],R=[...C,...H>0?[{field:"__spacer_left__",width:H,isSpacer:!0}]:[],...b.slice(V,T+1),...v>0?[{field:"__spacer_right__",width:v,isSpacer:!0}]:[],...y],$=_>0&&E>_?16:0,G=x+S+f+$+2,q=5;let Y=0,te=M-1,O=0,J=0,Q=g.length-1;for(;J<=Q;){const oe=J+Q>>>1;g[oe]<e?J=oe+1:Q=oe-1}Y=Math.max(0,J-q),O=Y>0?g[Y-1]:0;for(let oe=Y;oe<g.length;oe++)if(g[oe]>=e+I){te=Math.min(M-1,oe+q);break}const le=(a?48:0)+(u&&m?48:0)+(c&&p?48:0);return{renderContext:{firstRowIndex:Y,lastRowIndex:te,firstColumnIndex:V,lastColumnIndex:T},offsetTop:O,offsetLeft:0,totalHeight:G,pinnedTopHeight:x,pinnedBottomHeight:f,totalWidth:E,rowHeights:P,cumulativeHeights:g,virtualColumns:R,columnMetrics:{leftPinnedWidth:N,rightPinnedWidth:j,unpinnedAccWidths:h,unpinnedCols:b,totalSpecialsWidth:k,pinnedSpecialsWidth:le}}},[t,e,o,i,s,d,a,u,c,p,m])}function mo(n){const{columns:t,onColumnOrderChange:e,disableColumnReorder:o=!1}=n,[i,s]=l.useState(null),[d,a]=l.useState(null),u=l.useRef(-1),c=l.useCallback(b=>C=>{if(o)return;const y=t.findIndex(N=>N.field===b);if(t[y]?.pinnable===!1){C.preventDefault();return}s(b),u.current=y,C.dataTransfer&&(C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",b))},[t,o]),p=l.useCallback(b=>C=>{o||!i||(C.preventDefault(),C.dataTransfer.dropEffect="move",a(b))},[i,o]),m=l.useCallback(b=>C=>{if(C.preventDefault(),o||!i||i===b){s(null),a(null);return}const y=t.findIndex(j=>j.field===i),E=t.findIndex(j=>j.field===b);if(y===-1||E===-1){s(null),a(null);return}const N=t[y];e&&e({column:N,oldIndex:y,targetIndex:E}),s(null),a(null),u.current=-1},[t,i,o,e]),h=l.useCallback(()=>{s(null),a(null),u.current=-1},[]);return{draggedColumn:i,dragOverColumn:d,onDragStart:o?void 0:c,onDragOver:o?void 0:p,onDragEnd:o?void 0:h,onDrop:o?void 0:m}}function mn({isExpanded:n,onClick:t,variant:e="chevron"}){return r.jsx("button",{className:`ogx-expand-icon ${n?"ogx-expand-icon--expanded":""}`,onClick:o=>{t&&t(o)},"aria-label":n?"Collapse row":"Expand row",type:"button",children:e==="plus-minus"?r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("path",{d:"M4 8H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M8 4V12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:n?0:1,transition:"opacity 0.2s ease",transformOrigin:"center"}})]}):r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{transform:n?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease"},children:r.jsx("path",{d:"M6 4L10 8L6 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function bo(n){const{activeColumns:t,isHierarchyEnabled:e,isRowGrouping:o,isTreeData:i,activeHierarchyHandlers:s,columnVisibilityModel:d,columnOrder:a,onColumnOrderChange:u,disableColumnReorder:c,pivotMode:p,checkboxSelection:m,hasDetailPanel:h,rowReordering:b,initialState:C,setColumns:y}=n,E=l.useMemo(()=>e?t.map((_,I)=>I===0?{..._,renderCell:L=>{const F=L.rowMeta,A=F?.treeDepth??0,V=!!F?.hasChildren,T=!!F?.isExpanded,B=F?.groupingField,K=F?.groupingValue,H=F?.descendantCount,v=!!F?.isGroupRow;let R=_.renderCell?_.renderCell(L):L.value;return i&&V&&v&&(R=r.jsxs("div",{className:"ogx__group-cell-content",children:[L.value,H!==void 0&&H>0?` (${H})`:""]})),o&&V&&B&&(R=r.jsxs("div",{className:"ogx__group-cell-content",children:[_.field===B?"":`${B}: `,String(K),H!==void 0?` (${H})`:""]})),r.jsxs("div",{style:{display:"flex",alignItems:"center",paddingLeft:A*24,width:"100%",height:"100%"},children:[r.jsx("div",{style:{marginRight:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:V?"pointer":"default",flexShrink:0},children:V?r.jsx("div",{onClick:W=>{W.stopPropagation(),W.preventDefault(),s?.toggleExpansion(L.row.id)},onMouseDown:W=>{W.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:r.jsx(mn,{isExpanded:T,onClick:W=>{W.stopPropagation(),W.preventDefault(),s?.toggleExpansion(L.row.id)}})}):null}),r.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R})]})}}:{..._,renderCell:L=>{const F=L.rowMeta,A=!!F?.hasChildren,V=F?.groupingField;return o&&A?_.field===V?null:L.value!==void 0&&L.value!==null?_.renderCell?_.renderCell(L):L.value:null:_.renderCell?_.renderCell(L):L.value}}):t,[t,e,o,i,s]),[N,j]=l.useState(()=>C?.columns?.columnWidths??{}),w=l.useCallback((_,I)=>{j(L=>({...L,[_]:I}))},[]),[k,g]=l.useState(()=>C?.columns?.columnOrder??t.map(_=>_.field)),x=a??k;l.useEffect(()=>{y(t)},[t,y]),l.useEffect(()=>{p&&g(t.map(_=>_.field))},[p,t]);const f=l.useMemo(()=>{if(c)return E;const _=new Map(x.map((I,L)=>[I,L]));return[...E].sort((I,L)=>{const F=_.get(I.field)??E.indexOf(I),A=_.get(L.field)??E.indexOf(L);return F-A})},[E,x,c]),S=l.useMemo(()=>f.filter(_=>d[_.field]!==!1),[f,d]),P=mo({columns:f,onColumnOrderChange:l.useCallback(_=>{const{oldIndex:I,targetIndex:L}=_,F=[...x],[A]=F.splice(I,1);F.splice(L,0,A),a||g(F),u?.(_)},[x,a,u]),disableColumnReorder:c}),M=l.useMemo(()=>{const _=[];return b&&_.push({field:"__reorder_col__"}),h&&_.push({field:"__expand_col__"}),m&&_.push({field:"__checkbox_col__"}),[..._,...f]},[f,m,h,b]);return{effectiveColumns:E,orderedColumns:f,visibleOrderedColumns:S,navigationColumns:M,columnWidths:N,effectiveColumnOrder:x,setInternalColumnOrder:g,columnReorderHandlers:P,handleColumnResize:w}}function wo(n){const{renderContext:t,pinnedTopRows:e,pinnedBottomRows:o,paginatedUnpinnedRows:i,sortedUnpinnedRows:s,pagination:d}=n;return l.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:u}=t,c=d?i:s,p=e.length,m=e.map((j,w)=>({row:j,rowIndex:w})),h=o.map((j,w)=>({row:j,rowIndex:p+c.length+w})),b=Math.max(0,a-p),C=Math.min(c.length,u-p+1),y=c.slice(b,C).map((j,w)=>({row:j,rowIndex:p+b+w})),E=[...m,...y,...h],N=new Set;return E.filter(j=>N.has(j.row.id)?!1:(N.add(j.row.id),!0))},[t,e,o,i,s,d])}function vo(n){const{onRowsScrollEnd:t}=n,e=l.useRef({scrollTop:0,scrollLeft:0}),o=l.useRef(null),[i,s]=l.useState({scrollTop:0,scrollLeft:0});l.useEffect(()=>()=>{o.current!==null&&cancelAnimationFrame(o.current)},[]);const d=l.useCallback(a=>{const u=a.currentTarget;if(e.current={scrollTop:u.scrollTop,scrollLeft:u.scrollLeft},o.current!==null&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{o.current=null,s(e.current)}),t){const{scrollTop:c,scrollHeight:p,clientHeight:m}=u;p-c-m<100&&t({visibleTop:c,visibleBottom:c+m,viewportHeight:m})}},[t]);return{scrollTop:i.scrollTop,scrollLeft:i.scrollLeft,handleScroll:d}}function _o(n){const{onStateChange:t,sortModel:e,filterModel:o,effectivePaginationModel:i,columnWidths:s,effectiveColumnOrder:d,columnVisibilityModel:a,pinnedColumns:u}=n,c=l.useRef(t);l.useLayoutEffect(()=>{c.current=t}),l.useEffect(()=>{if(!c.current)return;const p={sorting:{sortModel:e},filter:{filterModel:o},pagination:{paginationModel:i},columns:{columnWidths:s,columnOrder:d,columnVisibilityModel:a,pinnedColumns:u}};c.current(p)},[e,o,i,s,d,a,u])}const Co={sum:n=>n.filter(e=>e!=null&&!isNaN(Number(e))).reduce((e,o)=>e+Number(o),0),avg:n=>{const t=n.filter(e=>e!=null&&!isNaN(Number(e)));return t.length===0?null:t.reduce((e,o)=>e+Number(o),0)/t.length},count:n=>n.filter(t=>t!=null).length,min:n=>{const t=n.filter(e=>e!=null&&!isNaN(Number(e))).map(Number);return t.length?Math.min(...t):null},max:n=>{const t=n.filter(e=>e!=null&&!isNaN(Number(e))).map(Number);return t.length?Math.max(...t):null},unique:n=>new Set(n.filter(t=>t!=null)).size};function Ne(n,t){return n==null?"—":typeof n=="number"?t==="avg"?n.toLocaleString(void 0,{maximumFractionDigits:2}):n.toLocaleString():String(n)}function bn(n){const{rows:t,aggregationModel:e,isServerSide:o,dataSource:i,filterModel:s,sortModel:d,serverAggregationResults:a}=n,u=l.useMemo(()=>{if(o||Object.keys(e).length===0)return{};const j={};for(const[w,k]of Object.entries(e)){const g=Co[k];if(!g){console.warn(`[useAggregation] Unknown aggregation function: "${k}"`);continue}const x=t.map(f=>f[w]);j[w]=g(x)}return j},[t,e,o]),[c,p]=l.useState({}),[m,h]=l.useState(!1),[b,C]=l.useState(null),y=l.useRef(0),E=l.useCallback(async()=>{if(!i?.getAggregations||Object.keys(e).length===0)return;const j=++y.current;h(!0),C(null);try{const w=await i.getAggregations({sortModel:d??[],filterModel:s??{items:[]},groupKeys:[],aggregationModel:e});j===y.current&&p(w)}catch(w){j===y.current&&(C(w),console.error("[useAggregation] Server aggregation error:",w))}finally{j===y.current&&h(!1)}},[i,e,s,d]);return l.useEffect(()=>{o&&i?.getAggregations&&!a&&E()},[E,o,i,a]),{aggregationResult:l.useMemo(()=>o?a&&Object.keys(a).length>0?a:c:u,[o,u,a,c]),isLoading:m,error:b}}function yo({columns:n,aggregationModel:t,aggregationResult:e,columnWidths:o,rowHeight:i,checkboxSelection:s,hasDetailPanel:d,rowReordering:a,pinnedColumns:u}){const c=l.useMemo(()=>Bt(n,o,u,s,!0,d,!0,a),[n,o,u,s,d,a]),p=u?.left?.[u.left.length-1],m=u?.right?.[0];return r.jsxs("div",{className:"ogx__aggregation-footer",role:"row","aria-label":"Aggregation totals","aria-live":"polite",style:{minHeight:`${i}px`},children:[s&&r.jsx("div",{style:{width:48,flexShrink:0}}),d&&r.jsx("div",{style:{width:48,flexShrink:0}}),a&&r.jsx("div",{style:{width:48,flexShrink:0}}),n.map(h=>{const b=t[h.field],C=e[h.field],y=o[h.field]??(typeof h.width=="number"?h.width:120),E=dt(h.field,u),N=E?c[h.field]:void 0,j=["ogx__aggregation-cell",E==="left"&&"ogx__aggregation-cell--pinned-left",E==="right"&&"ogx__aggregation-cell--pinned-right",E==="left"&&h.field===p&&"ogx__aggregation-cell--pinned-left-last",E==="right"&&h.field===m&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),w={width:y,minWidth:y,maxWidth:y,textAlign:h.align||"left"};return E==="left"&&N!==void 0&&(w.left=N),E==="right"&&N!==void 0&&(w.right=N),r.jsx("div",{className:j,role:"gridcell",style:w,children:b?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"ogx__aggregation-label",children:b}),r.jsx("span",{className:"ogx__aggregation-value",children:Ne(C,b)})]}):null},h.field)})]})}function ko({noRowsLabel:n,width:t}){return r.jsxs("div",{className:"ogx__empty",style:{width:t},children:[r.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9h18M9 21V9"})]}),r.jsx("span",{children:n})]})}function So({error:n}){if(!n)return null;const t=n instanceof Error?n.message:typeof n=="string"?n:"An unexpected error occurred while loading the data.";return r.jsxs("div",{className:"ogx-error-overlay","aria-live":"assertive",role:"alert",children:[r.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:[r.jsx("circle",{cx:"12",cy:"12",r:"10"}),r.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),r.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),r.jsx("div",{className:"ogx-error-overlay__title",children:"Oops! Something went wrong"}),r.jsx("div",{className:"ogx-error-overlay__message",children:t}),r.jsx("button",{onClick:()=>window.location.reload(),className:"ogx-button ogx-button--primary",children:"Retry"})]})}const ct=({indeterminate:n=!1,label:t,className:e="",inputRef:o,...i})=>{const s=l.useRef(null),d=l.useCallback(u=>{s.current=u,typeof o=="function"?o(u):o&&(o.current=u)},[o]);l.useEffect(()=>{s.current&&(s.current.indeterminate=n)},[n]);const a=["ogx-checkbox-wrapper",i.disabled&&"ogx-checkbox-wrapper--disabled",e].filter(Boolean).join(" ");return r.jsxs("label",{className:a,children:[r.jsx("input",{ref:d,type:"checkbox",className:"ogx-checkbox__input","aria-label":t||i["aria-label"]||(n?"Select some":i.checked?"Deselect":"Select"),...i}),r.jsxs("span",{className:"ogx-checkbox__box",children:[i.checked&&!n&&r.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:r.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),n&&r.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:r.jsx("path",{d:"M19 13H5v-2h14v2z"})})]}),t&&r.jsx("span",{className:"ogx-checkbox__label",children:t})]})};function jo(n){const{field:t,currentWidth:e,onResize:o,minWidth:i=50,maxWidth:s=1e3}=n,[d,a]=l.useState(!1),u=l.useRef(0),c=l.useRef(0),p=l.useCallback(b=>{b.preventDefault(),b.stopPropagation(),a(!0),u.current=b.clientX,c.current=e;let C=0;const y=16,E=j=>{const w=j.clientX-u.current,k=Math.max(i,Math.min(s,c.current+w)),g=Date.now();g-C>=y&&(o(t,k),C=g)},N=j=>{a(!1);const w=j.clientX-u.current,k=Math.max(i,Math.min(s,c.current+w));o(t,k),document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",N)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",N)},[t,e,o,i,s]),m=l.useCallback(b=>{b.preventDefault(),b.stopPropagation()},[]),h=["ogx-column-resize-handle",d&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return r.jsx("div",{className:h,onMouseDown:p,onClick:b=>b.stopPropagation(),onDragStart:b=>{b.preventDefault(),b.stopPropagation()},onDoubleClick:m,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,children:r.jsx("div",{className:"ogx-column-resize-handle__line"})})}function Ve(){return r.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:r.jsx("circle",{cx:"4",cy:"4",r:"4"})})}function Ue(){return r.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:r.jsx("circle",{cx:"4",cy:"4",r:"3"})})}function Eo(){return r.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",children:[r.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.3"}),r.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),r.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function No(){return r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),r.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function Mo(){return r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),r.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Po(){return r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Io(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.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"}),r.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"}),r.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function To(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"4",y1:"2",x2:"4",y2:"22"}),r.jsx("polyline",{points:"11 8 4 12 11 16"}),r.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Lo(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"20",y1:"2",x2:"20",y2:"22"}),r.jsx("polyline",{points:"13 8 20 12 13 16"}),r.jsx("line",{x1:"20",y1:"12",x2:"4",y2:"12"})]})}function Ro(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),r.jsx("line",{x1:"4",y1:"4",x2:"4",y2:"20"}),r.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Oo({colDef:n,sortModel:t,onSort:e,onHide:o,onPin:i,pinnedColumns:s,onManageColumns:d,onClose:a,anchorEl:u}){const c=l.useRef(null),[p,m]=l.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});l.useLayoutEffect(()=>{if(!u||!c.current)return;const g=u.getBoundingClientRect(),x=c.current.getBoundingClientRect(),f=window.innerWidth,S=window.innerHeight,P=8;let M=g.left;M+x.width+P>f&&(M=f-x.width-P),M<P&&(M=P);let _=g.bottom+4;_+x.height+P>S&&(_=g.top-x.height-4),m({position:"fixed",zIndex:1300,top:_,left:M,visibility:"visible"})},[u]),l.useEffect(()=>{function g(f){c.current&&!c.current.contains(f.target)&&u&&!u.contains(f.target)&&a()}function x(f){f.key==="Escape"&&a()}return document.addEventListener("mousedown",g),document.addEventListener("keydown",x),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",x),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[u,a]);const h=g=>{e?.(n.field,g),a()},b=()=>{o?.(n.field),a()},C=g=>{i?.(n.field,g),a()},y=t?.find(g=>g.field===n.field)?.sort,E=y==null,N=s?.left?.includes(n.field)??!1,j=s?.right?.includes(n.field)??!1,w=!N&&!j,k=n.headerName||n.field;return ze.createPortal(r.jsxs("div",{ref:c,className:"ogx-column-menu",style:p,role:"menu","aria-label":`Column options for ${k}`,children:[e&&n.sortable!==!1&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:`ogx-menu-item${y==="asc"?" ogx-menu-item--active":""}`,onClick:()=>h("asc"),role:"menuitemradio","aria-checked":y==="asc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:y==="asc"?r.jsx(Ve,{}):r.jsx(Ue,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(No,{})}),"Sort Ascending"]}),r.jsxs("button",{className:`ogx-menu-item${y==="desc"?" ogx-menu-item--active":""}`,onClick:()=>h("desc"),role:"menuitemradio","aria-checked":y==="desc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:y==="desc"?r.jsx(Ve,{}):r.jsx(Ue,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Mo,{})}),"Sort Descending"]}),r.jsxs("button",{className:`ogx-menu-item${E?" ogx-menu-item--active":""}`,onClick:()=>h(null),role:"menuitemradio","aria-checked":E,children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E?r.jsx(Ve,{}):r.jsx(Ue,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Po,{})}),"Unsort"]}),r.jsx("div",{className:"ogx-menu-divider"})]}),r.jsx("div",{className:"ogx-menu-section-label","aria-hidden":"true",children:"Pin column"}),r.jsxs("button",{className:`ogx-menu-item${N?" ogx-menu-item--active":""}`,onClick:()=>C("left"),role:"menuitemradio","aria-checked":N,"aria-label":"Pin to left",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:N?r.jsx(Ve,{}):r.jsx(Ue,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(To,{})}),"Pin to Left"]}),r.jsxs("button",{className:`ogx-menu-item${j?" ogx-menu-item--active":""}`,onClick:()=>C("right"),role:"menuitemradio","aria-checked":j,"aria-label":"Pin to right",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:j?r.jsx(Ve,{}):r.jsx(Ue,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Lo,{})}),"Pin to Right"]}),r.jsxs("button",{className:`ogx-menu-item${w?" ogx-menu-item--active":""}`,onClick:()=>C(null),role:"menuitemradio","aria-checked":w,"aria-label":"Unpin column",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:w?r.jsx(Ve,{}):r.jsx(Ue,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Ro,{})}),"Unpin"]}),r.jsx("div",{className:"ogx-menu-divider"}),r.jsxs("button",{className:"ogx-menu-item",onClick:b,role:"menuitem","aria-label":`Hide ${k} column`,children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Io,{})}),"Hide Column"]}),r.jsx("div",{className:"ogx-menu-divider"}),r.jsxs("button",{className:"ogx-menu-item",onClick:()=>{d?.(),a()},role:"menuitem","aria-label":"Manage all columns",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Eo,{})}),"Manage columns"]})]}),u?.closest(".ogx-theme-provider")||document.body)}function Fo(){return r.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"18",height:"18",children:r.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 Wo(){return r.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor",children:r.jsx("path",{d:"M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"})})}function wn(n){const t=[];for(const e of n.children)typeof e=="string"?t.push(e):t.push(...wn(e));return t}function Ao(n){let t=0;function e(o,i){t=Math.max(t,i);for(const s of o.children)typeof s!="string"&&e(s,i+1)}return n.forEach(o=>e(o,1)),t}function zo(n,t,e){function o(a,u,c){if(!wn(a).includes(u))return null;if(c===e)return a;for(const p of a.children)if(typeof p!="string"){const m=o(p,u,c+1);if(m)return m}return null}const i=new Map;for(const a of t){let u=null;for(const c of n)if(u=o(c,a.field,0),u)break;i.set(a.field,u)}const s=[];let d=0;for(;d<t.length;){const a=t[d],u=i.get(a.field)??null,c=a.width;if(!u)s.push({key:`fg-${a.field}-${e}`,label:"",width:c,isGroup:!1}),d++;else{let p=0,m=d;for(;m<t.length&&i.get(t[m].field)===u;)p+=t[m].width,m++;s.push({key:`${u.groupId}-${e}`,label:u.headerName,width:p,isGroup:!0}),d=m}}return s}function vn(n){const{columns:t,allColumns:e,columnGroupingModel:o,checkboxSelection:i=!1,allSelected:s=!1,someSelected:d=!1,onSelectAll:a,onSort:u,sortModel:c=[],onColumnResize:p,columnWidths:m={},pinnedColumns:h,hasDetailPanel:b=!1,pinCheckboxColumn:C=!0,pinExpandColumn:y=!0,rowReordering:E=!1,aggregationModel:N,draggedColumn:j,dragOverColumn:w,onDragStart:k,onDragOver:g,onDragEnd:x,onDrop:f,focusedCell:S,onHeaderClick:P,onHideColumn:M,onPinColumn:_,onManageColumns:I}=n,L=l.useId(),F=l.useRef({}),[A,V]=l.useState(null),T=O=>J=>{J.stopPropagation(),V({colDef:O,anchorEl:J.currentTarget})},B=()=>{V(null)};l.useLayoutEffect(()=>{if(S?.id==="HEADER"){const O=F.current[S.field];O&&O.focus()}},[S]);const K=O=>()=>{if(O.sortable===!1||!u)return;const J=c.find(le=>le.field===O.field);let Q="asc";J&&(J.sort==="asc"?Q="desc":Q=null),u(O.field,Q)},H=O=>{const J=c.find(Q=>Q.field===O);return J?r.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${J.sort}`,"aria-hidden":"true"}):null},v=l.useMemo(()=>Bt(t,m,h,i,C,b,y,E),[t,m,h,i,C,b,y,E]),R=o?Ao(o):0,$=(e??t).filter(O=>!O.isSpacer).map(O=>({field:O.field,width:m[O.field]??O.width??100})),te=(E?48:0)+(b?48:0)+(i?48:0);return r.jsxs("div",{className:"ogx__header-wrap",children:[R>0&&Array.from({length:R},(O,J)=>{const Q=zo(o,$,J);return r.jsxs("div",{className:"ogx-col-group-row",role:"row",children:[te>0&&r.jsx("div",{className:"ogx-col-group-cell ogx-col-group-cell--filler",style:{width:te,minWidth:te,flexShrink:0},role:"columnheader"}),Q.map(le=>r.jsx("div",{role:"columnheader",className:`ogx-col-group-cell ${le.isGroup?"ogx-col-group-cell--group":"ogx-col-group-cell--filler"}`,style:{width:le.width,minWidth:le.width,flexShrink:0},title:le.isGroup?le.label:void 0,children:le.isGroup&&r.jsx("span",{className:"ogx-col-group-cell__label",children:le.label})},le.key))]},`ogx-grp-${J}`)}),r.jsxs("div",{className:"ogx__header",role:"row",children:[E&&r.jsx("div",{className:"ogx__header-cell ogx__header-cell--pinned ogx__header-cell--pinned-left",role:"columnheader","aria-label":"Row reorder handle",title:"Drag to reorder rows",style:{minWidth:48,maxWidth:48,position:"sticky",left:0,zIndex:4}}),b&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${y?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader","aria-label":"Expand row details",style:{minWidth:48,maxWidth:48,position:y?"sticky":void 0,left:y?E?48:0:void 0,zIndex:y?5:void 0}}),i&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${C?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader",style:{position:C?"sticky":void 0,left:C?(E?48:0)+(b&&y?48:0):void 0},children:r.jsx(ct,{id:L,name:L,checked:s,indeterminate:d,onChange:O=>a?.(O.target.checked),"aria-label":s?"Deselect all rows":"Select all rows",tabIndex:S?.id==="HEADER"&&S.field==="__checkbox_col__"?0:-1,onMouseDown:O=>O.preventDefault(),inputRef:O=>{F.current.__checkbox_col__=O}})}),t.map((O,J)=>{if(O.isSpacer)return r.jsx("div",{style:{width:O.width,minWidth:O.width,flexShrink:0},"aria-hidden":"true"},O.field);const Q=O.sortable!==!1,le=c.some(fe=>fe.field===O.field),oe=O.resizable!==!1,pe=dt(O.field,h),z=pe!==null,ie=j===O.field,se=w===O.field,D=["ogx__header-cell",`ogx__header-cell--align-${O.headerAlign||O.align||"left"}`,Q&&"ogx__header-cell--sortable",le&&"ogx__header-cell--sorted",z&&"ogx__header-cell--pinned",z&&`ogx__header-cell--pinned-${pe}`,ie&&"ogx__header-cell--dragging",se&&"ogx__header-cell--drag-over",S?.id==="HEADER"&&S.field===O.field&&"ogx__header-cell--focused",O.headerClassName].filter(Boolean).join(" "),X=m[O.field]??O.width??100,ee={width:X,minWidth:O.minWidth,maxWidth:O.maxWidth,flexGrow:O.flex??0,flexShrink:0,flexBasis:(O.flex,"auto"),boxSizing:"border-box",position:z?"sticky":"relative",zIndex:O.zIndex,opacity:ie?.5:1};if(z&&pe){const fe=v[O.field];pe==="left"?ee.left=fe:ee.right=fe}const de=O.renderHeader?O.renderHeader({field:O.field,colDef:O,colIndex:J}):O.headerName||O.field,ce=fe=>{if(fe.target.closest(".ogx-column-resize-handle")){fe.stopPropagation();return}P?.(O.field),Q&&K(O)()},je=k?k(O.field):void 0,Fe=g?g(O.field):void 0,Ee=f?f(O.field):void 0;return r.jsxs("div",{className:D,style:ee,onClick:ce,role:"columnheader",draggable:!!k,onDragStart:je,onDragOver:Fe,onDragEnd:x,onDrop:Ee,"aria-sort":Q?le?c.find(fe=>fe.field===O.field)?.sort==="asc"?"ascending":"descending":"none":void 0,"aria-colindex":J+1+(i?1:0),"data-field":O.field,tabIndex:-1,ref:fe=>{F.current[O.field]=fe},children:[r.jsxs("div",{className:"ogx__header-cell-content",children:[ie&&r.jsx("div",{className:"ogx__header-drag-icon",children:r.jsx(Wo,{})}),r.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[r.jsx("span",{className:"ogx__header-cell-title",children:de}),N&&N[O.field]&&r.jsx("span",{className:"ogx__header-cell-aggregation",children:N[O.field]})]}),Q&&H(O.field),!O.disableColumnMenu&&r.jsx("button",{className:"ogx__menu-icon-btn",onClick:T(O),"aria-label":`Open column menu for ${O.headerName||O.field}`,"aria-haspopup":"menu",tabIndex:-1,children:r.jsx(Fo,{})})]}),oe&&p&&r.jsx(jo,{field:O.field,currentWidth:X,onResize:p,minWidth:O.minWidth,maxWidth:O.maxWidth})]},O.field)}),A&&r.jsx(Oo,{colDef:A.colDef,sortModel:c,onSort:u,onHide:M,onPin:_,pinnedColumns:h,onManageColumns:I,onClose:B,anchorEl:A.anchorEl})]})]})}const ut=({variant:n="text",size:t="medium",color:e="default",disabled:o=!1,className:i="",children:s,...d})=>{const a=["ogx-button",`ogx-button--${n}`,`ogx-button--${t}`,`ogx-button--${e}`,o&&"ogx-button--disabled",i].filter(Boolean).join(" ");return r.jsx("button",{className:a,disabled:o,...d,children:s})};function _n(n){const t=l.useId(),{page:e,pageSize:o,rowCount:i,onPageChange:s,onPageSizeChange:d,pageSizeOptions:a=[10,25,50,100],showFirstButton:u=!0,showLastButton:c=!0,localeText:p}=n,m=Math.max(1,Math.ceil(i/o)),h=Math.min(e,m-1),b=h*o,C=Math.min(b+o,i),y=i===0?0:`${b+1}–${C}`,E=p?.paginationRowsPerPage??"Rows per page:",N=p?.paginationOf?p.paginationOf(i===0?0:b+1,C,i):`${y} of ${i}`,j=p?.paginationPage?p.paginationPage(h+1,m):`Page ${h+1} of ${m}`,w=()=>{s(0)},k=()=>{s(Math.max(0,h-1))},g=()=>{s(Math.min(m-1,h+1))},x=()=>{s(m-1)},f=M=>{const _=parseInt(M.target.value,10);d(_)},S=h===0,P=h>=m-1;return r.jsxs("div",{className:"ogx-pagination",role:"navigation","aria-label":"Pagination",children:[r.jsxs("div",{className:"ogx-pagination__page-size",children:[r.jsx("label",{htmlFor:t,className:"ogx-pagination__label",children:E}),r.jsx("select",{id:t,className:"ogx-pagination__select",value:o,onChange:f,"aria-label":"Rows per page",children:a.map(M=>r.jsx("option",{value:M,children:M},M))})]}),r.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:N}),r.jsxs("div",{className:"ogx-pagination__actions",children:[u&&r.jsx(ut,{variant:"text",size:"small",onClick:w,disabled:S,"aria-label":"Go to first page",title:"First page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"})})}),r.jsx(ut,{variant:"text",size:"small",onClick:k,disabled:S,"aria-label":"Go to previous page",title:"Previous page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),r.jsx("div",{className:"ogx-pagination__page-info","aria-current":"page",children:j}),r.jsx(ut,{variant:"text",size:"small",onClick:g,disabled:P,"aria-label":"Go to next page",title:"Next page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),c&&r.jsx(ut,{variant:"text",size:"small",onClick:x,disabled:P,"aria-label":"Go to last page",title:"Last page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"})})})]})]})}function Bo(n,t,e={}){const o=new Map,i=[];n.forEach(a=>{o.set(a.id,a),i.push(a.id)});const s=new Map,d=[];return t.forEach(a=>{s.set(a.field,a),d.push(a.field)}),{rows:{idRowsLookup:o,allRows:i},columns:{all:t,lookup:s,orderedFields:d,columnVisibilityModel:e},sorting:{sortModel:[]},filter:{filterModel:{items:[]}},pagination:{paginationModel:{page:0,pageSize:100},rowCount:n.length},selection:{selectedRows:new Set},pinning:{pinnedColumns:{},pinnedRows:{}},virtualization:{renderContext:{firstRowIndex:0,lastRowIndex:0,firstColumnIndex:0,lastColumnIndex:0}},dimensions:{rowHeight:52,headerHeight:56,viewportWidth:0,viewportHeight:0},dataSource:{loading:!1,error:null}}}function $o(n,t){switch(t.type){case"SET_ROWS":{const e=Array.from(n.rows.idRowsLookup.values()),o=typeof t.payload=="function"?t.payload(e):t.payload,i=new Map,s=[];return o.forEach(d=>{i.set(d.id,d),s.push(d.id)}),{...n,rows:{idRowsLookup:i,allRows:s},pagination:{...n.pagination,rowCount:t.preserveRowCount?n.pagination.rowCount:o.length}}}case"SET_COLUMNS":{const e=new Map,o=[];return t.payload.forEach(i=>{e.set(i.field,i),o.push(i.field)}),{...n,columns:{all:t.payload,lookup:e,orderedFields:o,columnVisibilityModel:n.columns.columnVisibilityModel}}}case"SET_SORT_MODEL":return{...n,sorting:{sortModel:t.payload}};case"SET_FILTER_MODEL":return{...n,filter:{filterModel:t.payload}};case"SET_PAGINATION_MODEL":return{...n,pagination:{...n.pagination,paginationModel:t.payload}};case"SET_SELECTION":return{...n,selection:{selectedRows:t.payload}};case"SET_DIMENSIONS":return{...n,dimensions:{...n.dimensions,viewportWidth:t.payload.viewportWidth,viewportHeight:t.payload.viewportHeight}};case"SET_DATASOURCE_LOADING":return{...n,dataSource:{...n.dataSource,loading:t.payload}};case"SET_DATASOURCE_ERROR":return{...n,dataSource:{...n.dataSource,error:t.payload}};case"SET_ROW_COUNT":return{...n,pagination:{...n.pagination,rowCount:t.payload}};default:return n}}function Do(n){const{rows:t,columns:e,rowHeight:o=52,headerHeight:i=56,columnVisibilityModel:s,initialState:d}=n,[a]=l.useState(()=>Bo(t,e,s)),[u,c]=l.useReducer($o,{...a,sorting:d?.sorting||a.sorting,filter:d?.filter||a.filter,dataSource:d?.dataSource?{...a.dataSource,...d.dataSource}:a.dataSource,pagination:{...a.pagination,...d?.pagination||{},rowCount:n.rowCount??d?.pagination?.rowCount??a.pagination.rowCount},dimensions:{...a.dimensions,rowHeight:o,headerHeight:i}}),p=l.useRef(u);l.useLayoutEffect(()=>{p.current=u});const m=l.useRef(t);l.useEffect(()=>{t!==m.current&&(m.current=t,c({type:"SET_ROWS",payload:t}))},[t]);const h=l.useCallback((f,S)=>{c({type:"SET_ROWS",payload:f,preserveRowCount:S})},[]),b=l.useCallback(f=>{c({type:"SET_COLUMNS",payload:f})},[]),C=l.useCallback(f=>{c({type:"SET_SORT_MODEL",payload:f})},[]),y=l.useCallback(f=>{c({type:"SET_FILTER_MODEL",payload:f})},[]),E=l.useCallback(f=>{c({type:"SET_PAGINATION_MODEL",payload:f})},[]),N=l.useCallback(f=>{c({type:"SET_SELECTION",payload:f})},[]),j=l.useCallback((f,S)=>{c({type:"SET_DIMENSIONS",payload:{viewportWidth:f,viewportHeight:S}})},[]),w=l.useCallback(f=>{c({type:"SET_DATASOURCE_LOADING",payload:f})},[]),k=l.useCallback(f=>{c({type:"SET_DATASOURCE_ERROR",payload:f})},[]),g=l.useCallback(f=>{c({type:"SET_ROW_COUNT",payload:f})},[]),x=l.useRef({getRow:f=>p.current.rows.idRowsLookup.get(f)||null,getAllRows:()=>Array.from(p.current.rows.idRowsLookup.values()),getVisibleRows:()=>Array.from(p.current.rows.idRowsLookup.values()),getAllFilteredRows:()=>Array.from(p.current.rows.idRowsLookup.values()),getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:f=>p.current.columns.lookup.get(f)||null,getAllColumns:()=>p.current.columns.all,getVisibleColumns:()=>p.current.columns.all,selectRow:(f,S=!0)=>{const P=new Set(p.current.selection.selectedRows);S?P.add(f):P.delete(f),N(P)},selectRows:(f,S=!0)=>{const P=new Set(p.current.selection.selectedRows);f.forEach(M=>{S?P.add(M):P.delete(M)}),N(P)},getSelectedRows:()=>Array.from(p.current.selection.selectedRows),sortColumn:(f,S)=>{if(S===null)C(p.current.sorting.sortModel.filter(P=>P.field!==f));else{const P=p.current.sorting.sortModel.findIndex(M=>M.field===f);if(P>=0){const M=[...p.current.sorting.sortModel];M[P]={field:f,sort:S},C(M)}else C([...p.current.sorting.sortModel,{field:f,sort:S}])}},getSortModel:()=>p.current.sorting.sortModel,setFilterModel:y,getFilterModel:()=>p.current.filter.filterModel,setPage:f=>{E({...p.current.pagination.paginationModel,page:f})},setPageSize:f=>{E({...p.current.pagination.paginationModel,pageSize:f,page:0})},scrollToIndexes:()=>{},copySelectedRows:()=>Promise.resolve()});return{state:u,dispatch:c,apiRef:x,setRows:h,setColumns:b,setSortModel:C,setFilterModel:y,setPaginationModel:E,setSelection:N,setDimensions:j,setDataSourceLoading:w,setDataSourceError:k,setRowCount:g}}function Ho(n){const{onRowOrderChange:t,rows:e,getRowId:o,rowReordering:i=!1}=n,[s,d]=l.useState(null),[a,u]=l.useState(null),c=l.useCallback(C=>o?o(C):C.id,[o]),p=l.useCallback(C=>y=>{i&&(d(C),y.dataTransfer.effectAllowed="move")},[i]),m=l.useCallback(C=>y=>{!i||!s||(y.preventDefault(),y.dataTransfer.dropEffect="move",a!==C&&u(C))},[i,s,a]),h=l.useCallback(()=>{d(null),u(null)},[]),b=l.useCallback(C=>y=>{if(y.preventDefault(),!s||!t){h();return}const E=e.findIndex(j=>c(j)===s),N=e.findIndex(j=>c(j)===C);E!==-1&&N!==-1&&E!==N&&t({row:e[E],oldIndex:E,targetIndex:N}),h()},[s,t,e,c,h]);return{draggedRowId:s,dragOverRowId:a,onDragStart:i?p:void 0,onDragOver:i?m:void 0,onDragEnd:i?h:void 0,onDrop:i?b:void 0}}function Go(n){const{rows:t,getRowId:e,getTreeDataPath:o,treeData:i=!1,defaultGroupingExpansionDepth:s=0,filterModel:d,sortModel:a,onRowExpansionChange:u}=n,{treeNodes:c,rootIds:p,groupingRows:m}=l.useMemo(()=>{if(!i||!o)return{treeNodes:new Map,rootIds:[],groupingRows:[]};const g=new Map,x=[],f=[],S=new Map,P=M=>M.join("/");return t.forEach(M=>{const _=e(M),I=o(M),L=P(I);S.set(L,_),g.set(_,{id:_,parentId:null,depth:I.length-1,groupingKey:I[I.length-1],isExpanded:!1,children:[],serverChildrenCount:M.serverChildrenCount})}),t.forEach(M=>{const _=e(M),I=o(M);if(I.length===1){x.push(_);return}const L=A=>{if(A.length<=1)return;const V=A.slice(0,-1),T=P(V);let B=S.get(T);if(B===void 0&&(B=`auto-group-${T}`,!g.has(B))){const K=V[V.length-1];g.set(B,{id:B,parentId:null,depth:V.length-1,groupingKey:K,isExpanded:!1,children:[],label:K}),S.set(T,B);const H={id:B,name:K,_isGroupRow:!0};f.push(H),V.length===1&&x.push(B),L(V)}return B},F=L(I);if(F!==void 0){const A=g.get(F),V=g.get(_);A&&V&&(V.parentId=F,A.children=A.children||[],A.children.includes(_)||A.children.push(_))}}),f.forEach(M=>{const _=M.id,I=g.get(_);if(!I)return;const F=_.replace("auto-group-","").split("/");if(F.length>1){const A=F.slice(0,-1),V=P(A),T=S.get(V);if(T&&g.has(T)){I.parentId=T;const B=g.get(T);B&&(B.children=B.children||[],B.children.includes(_)||B.children.push(_))}}}),{treeNodes:g,rootIds:x,groupingRows:f}},[t,o,i,e]),h=l.useMemo(()=>{if(!i)return new Set;const g=new Set;return c.forEach(x=>{x.children&&x.children.length>0&&(s===-1||x.depth<s)&&g.add(x.id)}),g},[c,i,s]),[b,C]=l.useState(new Set);l.useEffect(()=>{h.size>0&&C(h)},[h]);const y=l.useCallback(g=>{C(x=>{const f=new Set(x),S=!f.has(g);if(f.has(g)?f.delete(g):f.add(g),S&&u){const P=c.get(g);P&&u(P)}return f})},[c,u]),E=l.useCallback(()=>{if(!i)return null;const g=new Map;t.forEach(L=>g.set(e(L),L)),m.forEach(L=>g.set(L.id,L));const x=L=>Dt(L,d),f=new Map,S=L=>{if(f.has(L))return f.get(L);const F=g.get(L);if(!F)return!1;if(x(F))return f.set(L,!0),!0;const V=c.get(L);return V&&V.children&&V.children.some(B=>S(B))?(f.set(L,!0),!0):(f.set(L,!1),!1)},P=(L,F)=>{if(!a||a.length===0)return 0;const A=g.get(L),V=g.get(F);if(!A||!V)return 0;for(const T of a){const B=A[T.field],K=V[T.field],H=Ht(B,K,T.sort);if(H!==0)return H}return 0},M=[],_=new Set,I=L=>{const F=L.filter(A=>S(A));F.sort(P),F.forEach(A=>{if(_.has(A))return;const V=g.get(A),T=c.get(A);if(V&&T){_.add(A);const B={...V,_treeDepth:T.depth,_isExpanded:b.has(A),_hasChildren:!!(T.children&&T.children.length>0||T.serverChildrenCount&&T.serverChildrenCount>0),_descendantCount:T.children?T.children.length:0};M.push(B),b.has(A)&&T.children&&T.children.length>0&&I(T.children)}})};return I(p),M},[i,t,m,p,c,b,d,a,e]),N=l.useCallback(g=>b.has(g),[b]),j=l.useCallback(g=>c.get(g),[c]),w=l.useCallback(g=>{const x=[];let f=g;for(;f!==null;){const S=c.get(f);if(!S)break;x.unshift(S.groupingKey),f=S.parentId}return x},[c]),k=l.useMemo(()=>{const g=new Map,x=new Set(m.map(f=>f.id));return c.forEach((f,S)=>{g.set(S,{hasChildren:!!(f.children&&f.children.length>0||f.serverChildrenCount&&f.serverChildrenCount>0),treeDepth:f.depth,descendantCount:f.children?f.children.length:void 0,isGroupRow:x.has(S),isExpanded:b.has(S)})}),g},[c,m,b]);return l.useMemo(()=>({treeNodes:c,groupingRows:m,toggleExpansion:y,isGroupExpanded:N,getVisibleRows:E,getNode:j,getNodePath:w,rowMetaMap:k}),[c,m,y,N,E,j,w,k])}const Vo=n=>n?.depth===-1?"footer":"inline",Uo=[],Ko={};function Yo(n){const{rows:t,getRowId:e,rowGroupingModel:o=Uo,aggregationModel:i=Ko,defaultGroupingExpansionDepth:s=0,filterModel:d,sortModel:a,getAggregationPosition:u=Vo}=n,[c,p]=l.useState(new Set),{treeNodes:m,rootIds:h,groupingRows:b}=l.useMemo(()=>{const w=new Map,k=new Map,g=[];if(o.length===0)return{treeNodes:w,rootIds:g,groupingRows:k};const x=(P,M,_)=>`auto-group-${P}-${M}-${_||"root"}`,f=(P,M,_)=>{if(M>=o.length)return P.map(A=>{const V=e(A);return w.set(V,{id:V,parentId:_,depth:M,groupingKey:"",isExpanded:!1}),V});const I=o[M],L=new Map;P.forEach(A=>{const V=A[I],T=String(V);L.has(T)||L.set(T,[]),L.get(T).push(A)});const F=[];return L.forEach((A,V)=>{const B=A[0][I],K=x(I,V,_);F.push(K);const H={};i&&Object.entries(i).forEach(([G,q])=>{const Y=A.map(te=>te[G]);if(q==="sum")H[G]=Y.reduce((te,O)=>te+(Number(O)||0),0);else if(q==="min")H[G]=Math.min(...Y.map(te=>Number(te)||0));else if(q==="max")H[G]=Math.max(...Y.map(te=>Number(te)||0));else if(q==="avg"){const te=Y.reduce((O,J)=>O+(Number(J)||0),0);H[G]=Y.length?te/Y.length:0}else q==="count"&&(H[G]=Y.length)});const v={[I]:B,...H,id:K};k.set(K,v);const R={id:K,parentId:_,depth:M,groupingKey:V,groupingField:I,groupingValue:B,aggregatedValues:H,isExpanded:!1,children:[],label:`${I}: ${String(B)}`};R.aggregationPosition=u(R),w.set(K,R);const W=f(A,M+1,K);w.get(K).children=W;const $=A.length;w.get(K).descendantCount=$}),F},S=f(t,0,null);return g.push(...S),{treeNodes:w,rootIds:g,groupingRows:k}},[t,o,i,e,u]);l.useEffect(()=>{if(s===-1){const w=new Set;m.forEach((k,g)=>{k.children&&k.children.length>0&&w.add(g)}),p(w)}else if(s>0){const w=new Set;m.forEach((k,g)=>{k.depth<s&&k.children&&k.children.length>0&&w.add(g)}),p(w)}else p(new Set)},[o,s,m]);const C=l.useCallback(w=>{p(k=>{const g=new Set(k);return g.has(w)?g.delete(w):g.add(w),g})},[]),y=l.useCallback(w=>c.has(w),[c]),E=l.useCallback(()=>{if(o.length===0)return null;const w=[],k=new Set,g=new Map;t.forEach(P=>g.set(e(P),P));const x=P=>{const M=m.get(P);if(!M)return!1;if(!M.children||M.children.length===0){const _=g.get(P);return!(!_||d&&!Dt(_,d))}return M.children.some(_=>x(_))},f=P=>{let M=P;d&&(M=P.filter(x)),a&&a.length>0&&M.sort((_,I)=>{const L=b.get(_)||g.get(_),F=b.get(I)||g.get(I);if(!L||!F)return 0;for(const A of a){const V=L[A.field],T=F[A.field],B=Ht(V,T,A.sort);if(B!==0)return B}return 0}),M.forEach(_=>{if(k.has(_))return;const I=m.get(_),L=I?.children&&I.children.length>0,F=L?b.get(_):g.get(_);if(F&&I){k.add(_);const A={...F,_treeDepth:I.depth,_isExpanded:c.has(_),_hasChildren:L,_groupingField:I.groupingField,_groupingValue:I.groupingValue,_descendantCount:I.descendantCount};w.push(A),S.has(_)&&L&&f(I.children)}})},S=c;return f(h),w},[t,e,m,h,b,d,a,c,o]),N=l.useCallback(w=>m.get(w),[m]),j=l.useMemo(()=>{const w=new Map;return m.forEach((k,g)=>{const x=!!(k.children&&k.children.length>0);w.set(g,{hasChildren:x,treeDepth:k.depth,groupingField:k.groupingField,groupingValue:k.groupingValue,descendantCount:k.descendantCount,isGroupRow:x,isExpanded:x?c.has(g):void 0})}),w},[m,c]);return l.useMemo(()=>({treeNodes:m,groupingRows:b,toggleExpansion:C,isGroupExpanded:y,getVisibleRows:E,getNode:N,rowMetaMap:j}),[m,b,C,y,E,N,j])}function qo(n){const{rows:t,getRowId:e,processRowUpdate:o,onProcessRowUpdateError:i,onRowChange:s}=n,[d,a]=l.useState(null),u=l.useRef(null),c=l.useCallback(b=>{a(b),u.current=typeof b=="function"?b(u.current):b},[]),p=l.useCallback(b=>{c({id:b.id,field:b.field,value:b.value,originalValue:b.value})},[c]),m=l.useCallback(async b=>{const C=u.current;if(!C)return;if(b?.cancel){c(null);return}const{id:y,field:E,value:N,originalValue:j}=C;if(N===j){c(null);return}const w=t.find(g=>e(g)===y);if(!w){c(null);return}const k={...w,[E]:N};try{if(o){const g=await o(k,w);s?.(g)}else s?.(k);c(null)}catch(g){i?.(g)}},[c,t,e,o,s,i]),h=l.useCallback(b=>{d&&d.id===b.id&&d.field===b.field&&c(C=>C?{...C,value:b.value}:null)},[d,c]);return{editingCell:d,startCellEdit:p,stopCellEdit:m,setEditCellValue:h}}function Xo(n,t,e){const[o,i]=l.useState(new Map),[s,d]=l.useState({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}}),a=l.useCallback(()=>{i(new Map)},[]),u=l.useCallback((y,E)=>o.get(y)?.[E],[o]),c=l.useCallback((y,E,N,j,w)=>{const k=new Map(o);for(let g=j;g<w;g++){const x=t[g];if(!x)continue;let f=1;if(x.colSpan)if(typeof x.colSpan=="function"){const P={row:E,value:E[x.field],field:x.field,colDef:x,rowIndex:N,colIndex:g};f=x.colSpan(P)}else f=x.colSpan;if(f<=1){Ke(k,y,x.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:e[x.field]||100}});continue}let S=e[x.field]||100;for(let P=1;P<f;P++)if(g+P<w){const M=t[g+P];M&&(S+=e[M.field]||100,Ke(k,y,M.field,{spannedByColSpan:!0,leftVisibleCellIndex:g,rightVisibleCellIndex:Math.min(g+f-1,t.length-1)}))}Ke(k,y,x.field,{spannedByColSpan:!1,cellProps:{colSpan:f,width:S}}),g+=f-1}i(k)},[o,t,e]),p=l.useCallback((y,E)=>{const N={},j={},w={};t.forEach((k,g)=>{if(k.rowSpan)for(let x=y;x<E;x++){const f=n[x];if(!f||j[f.id]?.[k.field])continue;const S=k.valueGetter?k.valueGetter({row:f,field:k.field,value:f[k.field]}):f[k.field];let P=1;if(typeof k.rowSpan=="function"){const M={row:f,value:S,field:k.field,colDef:k,rowIndex:x,colIndex:g};P=k.rowSpan(M)}else typeof k.rowSpan=="number"&&(P=k.rowSpan);if(P>1){N[f.id]||(N[f.id]={}),N[f.id][k.field]=P;for(let M=1;M<P;M++){const _=x+M;if(_<E&&n[_]){const I=n[_];j[I.id]||(j[I.id]={}),j[I.id][k.field]=!0,w[_]||(w[_]={}),w[_][k.field]=x}}}}}),d({caches:{spannedCells:N,hiddenCells:j,hiddenCellOriginMap:w},processedRange:{firstRowIndex:y,lastRowIndex:E}})},[n,t]),m=l.useCallback(()=>{d({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}})},[]);l.useEffect(()=>{const y=new Map;n.forEach((w,k)=>{for(let g=0;g<t.length;g++){const x=t[g];if(!x)continue;let f=1;if(x.colSpan)if(typeof x.colSpan=="function"){const P={row:w,value:w[x.field],field:x.field,colDef:x,rowIndex:k,colIndex:g};f=x.colSpan(P)}else f=x.colSpan;if(f<=1){const P=e[x.field]||(typeof x.width=="number"?x.width:100);Ke(y,w.id,x.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:P}});continue}let S=e[x.field]||(typeof x.width=="number"?x.width:100);for(let P=1;P<f;P++)if(g+P<t.length){const M=t[g+P];if(M){const _=e[M.field]||(typeof M.width=="number"?M.width:100);S+=_,Ke(y,w.id,M.field,{spannedByColSpan:!0,leftVisibleCellIndex:g,rightVisibleCellIndex:Math.min(g+f-1,t.length-1)})}}Ke(y,w.id,x.field,{spannedByColSpan:!1,cellProps:{colSpan:f,width:S}}),g+=f-1}}),i(y);const E={},N={},j={};t.forEach((w,k)=>{if(w.rowSpan)for(let g=0;g<n.length;g++){const x=n[g];if(!x||N[x.id]?.[w.field])continue;const f=w.valueGetter?w.valueGetter({row:x,field:w.field,value:x[w.field]}):x[w.field];let S=1;if(typeof w.rowSpan=="function"){const P={row:x,value:f,field:w.field,colDef:w,rowIndex:g,colIndex:k};S=w.rowSpan(P)}else typeof w.rowSpan=="number"&&(S=w.rowSpan);if(S>1){E[x.id]||(E[x.id]={}),E[x.id][w.field]=S;for(let P=1;P<S;P++){const M=g+P;if(M<n.length&&n[M]){const _=n[M];N[_.id]||(N[_.id]={}),N[_.id][w.field]=!0,j[M]||(j[M]={}),j[M][w.field]=g}}}}}),d({caches:{spannedCells:E,hiddenCells:N,hiddenCellOriginMap:j},processedRange:{firstRowIndex:0,lastRowIndex:n.length}})},[n,t,e]);const h=l.useCallback(()=>s.caches.spannedCells,[s]),b=l.useCallback(()=>s.caches.hiddenCells,[s]),C=l.useCallback(()=>s.caches.hiddenCellOriginMap,[s]);return{colspanMap:o,resetColSpan:a,getCellColSpanInfo:u,calculateColSpan:c,rowSpanningState:s,calculateRowSpan:p,resetRowSpan:m,getSpannedCells:h,getHiddenCells:b,getHiddenCellOriginMap:C}}function Ke(n,t,e,o){let i=n.get(t);i||(i={},n.set(t,i)),i[e]=o}function Jo(n){const{dataSource:t,sortModel:e,filterModel:o,paginationModel:i,paginationMode:s,sortingMode:d,filterMode:a,aggregationModel:u,setRows:c,setRowCount:p,setDataSourceLoading:m,setDataSourceError:h,onAggregationResults:b}=n,C=l.useRef(null),y=l.useRef(0),E=l.useCallback(async()=>{if(!t)return;const j=++y.current;m(!0),h(null);const w=i.page*i.pageSize,k=w+i.pageSize,g={startRow:w,endRow:k,sortModel:e,filterModel:o,groupKeys:[],aggregationModel:u};try{const x=await t.getRows(g);if(j!==y.current)return;let f=!1;if(s==="infinite"){const S=C.current;if(S){const P=JSON.stringify(S.sortModel)!==JSON.stringify(e),M=JSON.stringify(S.filterModel)!==JSON.stringify(o),_=S.pageSize!==i.pageSize;!P&&!M&&!_&&i.page>S.page&&(f=!0)}}c(f?S=>[...S,...x.rows]:x.rows,!0),x.aggregationResults&&b&&b(x.aggregationResults),x.rowCount!==void 0&&p(x.rowCount),C.current={sortModel:e,filterModel:o,page:i.page,pageSize:i.pageSize}}catch(x){j===y.current&&(h(x),console.error("Data Source Error:",x))}finally{j===y.current&&m(!1)}},[t,i.page,i.pageSize,e,o,s,u,b,c,p,m,h]);l.useEffect(()=>{if(t&&(s==="server"||s==="infinite"||d==="server"||a==="server")){const w=setTimeout(()=>{E()},300);return()=>clearTimeout(w)}},[E,t,s,d,a]);const N=l.useCallback(async(j,w)=>{if(t){m(!0);try{const k=await t.getRows({startRow:0,endRow:-1,sortModel:e,filterModel:o,groupKeys:w});k.rows.length>0&&c(g=>{const x=new Set(g.map(S=>S.id)),f=k.rows.filter(S=>!x.has(S.id));return[...g,...f]})}catch(k){h(k),console.error("Failed to fetch children:",k)}finally{m(!1)}}},[t,e,o,c,m,h]);return{fetchRows:E,fetchChildren:N}}const Cn="\0",ft="";function Qo(n,t){const e=n.filter(o=>o!=null&&!isNaN(o));if(e.length===0)return null;switch(t){case"sum":return e.reduce((o,i)=>o+i,0);case"avg":return e.reduce((o,i)=>o+i,0)/e.length;case"count":return e.length;case"min":return Math.min(...e);case"max":return Math.max(...e)}}function Ct(n,t){return t.map(e=>String(n[e]??"")).join(Cn)}function Gt(n,t,e,o){return o?`${n}${ft}${t}${ft}${e}`:`${t}${ft}${e}`}function yn(n,t,e,o){return l.useMemo(()=>{const i={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1};if(!o)return i;const{rowFields:s,columnFields:d,valueFields:a}=e;if(s.length===0||a.length===0)return i;const u=d.length>0,c=new Map(t.map(j=>[j.field,j])),p=new Set;for(const j of n)p.add(Ct(j,d));const m=Array.from(p).sort(),h=new Map;for(const j of n){const w=Ct(j,s);if(!h.has(w)){const f={};for(const S of s)f[S]=j[S];h.set(w,{labelValues:f,bucket:new Map})}const k=h.get(w),g=Ct(j,d);k.bucket.has(g)||k.bucket.set(g,new Map);const x=k.bucket.get(g);for(const f of a){const S=j[f.field];x.has(f.field)||x.set(f.field,[]),S!=null&&!isNaN(Number(S))&&x.get(f.field).push(Number(S))}}let b=0;const C=[];for(const[,j]of h){const w={id:b++,...j.labelValues};for(const k of m){const g=j.bucket.get(k);for(const x of a){const f=Gt(k,x.field,x.aggFn,u),S=g?.get(x.field)??[];w[f]=S.length>0?Qo(S,x.aggFn):null}}C.push(w)}const y=new Map;for(const j of n){const w=Ct(j,d);for(const k of a){if(k.aggFn!=="avg"&&k.aggFn!=="min"&&k.aggFn!=="max")continue;const g=`${w}${ft}${k.field}`;y.has(g)||y.set(g,[]);const x=j[k.field];x!=null&&!isNaN(Number(x))&&y.get(g).push(Number(x))}}const E={id:"__pivot_grand_total__"};for(let j=0;j<s.length;j++)E[s[j]]=j===0?"Grand Total":"";for(const j of m)for(const w of a){const k=Gt(j,w.field,w.aggFn,u),g=C.map(f=>f[k]).filter(f=>f!=null&&!isNaN(Number(f))).map(Number);if(g.length===0){E[k]=null;continue}const x=`${j}${ft}${w.field}`;switch(w.aggFn){case"sum":case"count":E[k]=g.reduce((f,S)=>f+S,0);break;case"avg":{const f=y.get(x)??[];E[k]=f.length>0?f.reduce((S,P)=>S+P,0)/f.length:null;break}case"min":E[k]=Math.min(...y.get(x)??g);break;case"max":E[k]=Math.max(...y.get(x)??g);break}}C.push(E);const N=[];for(const j of s){const w=c.get(j);N.push({field:j,headerName:w?.headerName??j,width:w?.width??140,sortable:!0})}for(const j of m){const w=u?j.split(Cn).map((k,g)=>{const x=c.get(d[g]);return x?.headerName?`${x.headerName}: ${k}`:k}).join(" / "):"";for(const k of a){const g=c.get(k.field),x=Gt(j,k.field,k.aggFn,u),f=k.headerName??g?.headerName??k.field,S=w?`${w} — ${f} (${k.aggFn})`:`${f} (${k.aggFn})`;N.push({field:x,headerName:S,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:P})=>{if(P==null)return"—";const M=Number(P);return k.aggFn==="avg"?M.toFixed(2):k.aggFn==="count"?M.toLocaleString():g?.valueFormatter?g.valueFormatter({value:P,row:{},field:k.field}):M.toLocaleString()}})}}return{pivotRows:C,pivotColumns:N,colKeys:m,isValid:!0}},[n,t,e,o])}function Zo(n){const t=document.createElement("textarea");t.value=n,t.style.cssText="position:fixed;top:-9999px;left:-9999px;opacity:0;",document.body.appendChild(t),t.focus(),t.select();let e=!1;try{e=document.execCommand("copy")}finally{document.body.removeChild(t)}return e}async function er(n){let t=!1;try{t=Zo(n)}catch{}if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function")try{await navigator.clipboard.writeText(n);return}catch(e){if(t)return;throw e}else if(!t)throw new Error("Clipboard API not available and fallback failed.")}function tr(n){const{selectedRowIds:t,columns:e,getVisibleRows:o,getRowId:i}=n,s=l.useCallback(async()=>{if(t.size===0)return;const a=o().filter(h=>t.has(i(h)));if(a.length===0)return;const u=e.filter(h=>!h.field.startsWith("__")),c=u.map(h=>h.headerName||h.field).join(" "),p=a.map(h=>u.map(b=>{const C=h[b.field];return b.valueFormatter?b.valueFormatter({value:C,row:h,field:b.field}):C??""}).join(" ")).join(`
7
- `),m=`${c}
8
- ${p}`;try{await er(m)}catch(h){console.error("[OpenGridX] Failed to copy to clipboard:",h)}},[t,e,o,i]);return l.useEffect(()=>{const d=a=>{if(!(a.ctrlKey||a.metaKey)||a.key!=="c")return;const u=document.activeElement,c=u?.tagName.toLowerCase(),p=u?.type;c==="input"&&p!=="checkbox"&&p!=="radio"||c==="textarea"||c==="select"||u?.isContentEditable||s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),{copySelectedRows:s}}function nr({row:n,rowIndex:t,listViewColumn:e,isSelected:o=!1,checkboxSelection:i=!1,rowHeight:s,onRowClick:d,onSelectionChange:a}){const u={row:n,value:void 0,field:e.field,colDef:{field:e.field},rowIndex:t,colIndex:0},c=p=>{p.stopPropagation(),a?.(n.id,p.target.checked)};return r.jsxs("div",{className:`ogx-list-view__row${o?" ogx-list-view__row--selected":""}`,style:s?{minHeight:s}:void 0,onClick:()=>d?.(n),role:"row","aria-rowindex":t+2,"aria-selected":o,children:[i&&r.jsx("div",{className:"ogx-list-view__checkbox",onClick:p=>p.stopPropagation(),children:r.jsx("input",{type:"checkbox",checked:o,onChange:c,"aria-label":`Select row ${n.id}`})}),r.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:e.renderCell(u)})]})}function or({ariaLabel:n,allRenderableRows:t,filteredRows:e,pagination:o,effectivePaginationModel:i,pageSizeOptions:s,selectedRowIds:d,listViewColumn:a,noRowsLabel:u,rowHeight:c,checkboxSelection:p,paginationMode:m,dataSource:h,serverRowCount:b,paginationSlot:C,paginationSlotProps:y,localeText:E,onRowClick:N,onSelectionChange:j,onPaginationModelChange:w}){const k=C||_n,g=m==="server"&&h?b||0:e.length;return r.jsxs("div",{className:"ogx-list-view",role:"grid","aria-label":n||"Data grid list view","aria-rowcount":t.length+1,children:[r.jsx("div",{className:"ogx-list-view__toolbar",children:r.jsxs("span",{children:[e.length," ",e.length===1?"item":"items",o?` · page ${i.page+1} of ${Math.ceil(e.length/i.pageSize)||1}`:"",d.size>0?` · ${d.size} selected`:""]})}),r.jsx("div",{className:"ogx-list-view__rows",children:t.length===0?r.jsxs("div",{className:"ogx-list-view__empty","aria-live":"polite",role:"status",children:[r.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9h18M9 21V9"})]}),u]}):t.map((x,f)=>r.jsx(nr,{row:x,rowIndex:f,listViewColumn:a,isSelected:d.has(x.id),checkboxSelection:p,rowHeight:c,onRowClick:S=>N({row:S,id:S.id,rowIndex:f}),onSelectionChange:j},x.id))}),o&&r.jsx(k,{page:i.page,pageSize:i.pageSize,rowCount:g,pageSizeOptions:s,onPageChange:x=>w({...i,page:x}),onPageSizeChange:x=>w({...i,pageSize:x,page:0}),localeText:E,...y})]})}function rr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[i,s]=l.useState(String(n??"")),d=l.useRef(null);return l.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"text",className:"ogx__edit-input",value:i,onChange:a=>{s(a.target.value),t(a.target.value)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function ir({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[i,s]=l.useState(typeof n=="number"?n:""),d=l.useRef(null);return l.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"number",className:"ogx__edit-input ogx__edit-input--number",value:i,onChange:a=>{const u=a.target.value===""?"":Number(a.target.value);s(u),t(u===""?null:u)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function lr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const i=l.useRef(null);l.useEffect(()=>{i.current?.focus()},[]);const s=()=>{t(!n),setTimeout(e,0)};return r.jsx("div",{className:"ogx__edit-boolean",children:r.jsx("input",{ref:i,type:"checkbox",className:"ogx__edit-checkbox",checked:!!n,onChange:s,onKeyDown:d=>{d.key==="Escape"&&(d.stopPropagation(),o())}})})}function sr({value:n,colDef:t,onValueChange:e,onCommit:o,onCancel:i}){const s=l.useRef(null);l.useEffect(()=>{s.current?.focus()},[]);const d=t.valueOptions??[];return r.jsx("select",{ref:s,className:"ogx__edit-select",value:String(n??""),onChange:a=>{e(a.target.value)},onBlur:o,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),o()),a.key==="Escape"&&(a.stopPropagation(),i())},children:d.map(a=>{const u=typeof a=="object"?a.value:a,c=typeof a=="object"?a.label:String(a);return r.jsx("option",{value:String(u),children:c},String(u))})})}function ar({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[i,s]=l.useState(typeof n=="string"?n:String(n??"")),d=l.useRef(null);return l.useEffect(()=>{d.current?.focus()},[]),r.jsx("input",{ref:d,type:"date",className:"ogx__edit-input",value:i,onChange:a=>{s(a.target.value),t(a.target.value)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function dr(n){const{colDef:t}=n;switch(t.type){case"number":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(ir,{...n})});case"boolean":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(lr,{...n})});case"singleSelect":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(sr,{...n})});case"date":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(ar,{...n})});default:return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(rr,{...n})})}}function cr({renderFn:n}){return r.jsx(r.Fragment,{children:n()})}class ur extends l.Component{constructor(t){super(t),this.state={hasError:!1,error:null,resetKey:t.resetKey}}static getDerivedStateFromProps(t,e){return e.hasError&&t.resetKey!==e.resetKey?{hasError:!1,error:null,resetKey:t.resetKey}:t.resetKey!==e.resetKey?{resetKey:t.resetKey}:null}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,e){process.env.NODE_ENV!=="production"&&console.warn(`[CellErrorBoundary] field="${this.props.field}"`,t,e.componentStack)}render(){return this.state.hasError?r.jsx("div",{className:"ogx__cell-error",role:"status","aria-label":`Error in cell: ${this.props.field}`,title:this.state.error?.message??"Render error",children:"⚠"}):r.jsx(cr,{renderFn:this.props.renderFn})}}function fr(n){const{onCellClick:t,onCellEditStart:e,onCellValueChange:o,value:i,row:s,colDef:d,rowIndex:a,colIndex:u,isSelected:c,onClick:p,width:m,pinnedPosition:h,pinnedOffset:b,isFocused:C,isFocusVisible:y,isEditable:E,isEditing:N,onEditStart:j,onEditStop:w,onValueChange:k,colSpanInfo:g,rowSpan:x,isHiddenByRowSpan:f,rowMeta:S}=n,P=l.useCallback(v=>{o?o(d.field,v):k?.(v)},[o,k,d.field]),M=l.useMemo(()=>d.valueFormatter?d.valueFormatter({value:i,row:s,field:d.field}):i==null?"":String(i),[i,s,d]),_=l.useMemo(()=>d.cellClassName?typeof d.cellClassName=="function"?d.cellClassName({value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:u})||"":d.cellClassName:"",[d,i,s,a,u]),I=l.useRef(null);if(l.useLayoutEffect(()=>{C&&I.current&&I.current.focus({preventScroll:!0})},[C]),g?.spannedByColSpan)return null;if(f)return r.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:{width:m??d.width??100},role:"presentation","data-field":d.field,"data-colindex":u});const L=v=>{t&&t({row:s,field:d.field,value:i,colDef:d,rowIndex:a,colIndex:u}),p?.(v)},F=v=>{E&&(j||e)&&(v.stopPropagation(),e?e(d.field,i):j?.())},A=h!=null,V=["ogx__cell",`ogx__cell--align-${d.align||"left"}`,c&&"ogx__cell--selected",C&&"ogx__cell--focused",C&&y&&"ogx__cell--focus-visible",d.type&&`ogx__cell--type-${d.type}`,A&&"ogx__cell--pinned",A&&`ogx__cell--pinned-${h}`,N&&"ogx__cell--editing",x&&x>1&&"ogx__cell--spanned",_].filter(Boolean).join(" "),T=g?.cellProps?.colSpan||1,B=x||1,K=g?.cellProps?.width??m??d.width??100,H={width:"var(--width)","--width":typeof K=="number"?`${K}px`:K,flexGrow:d.flex??0,flexShrink:0,flexBasis:(d.flex,"auto"),boxSizing:"border-box",minWidth:d.minWidth,maxWidth:d.maxWidth,position:A?"sticky":void 0,zIndex:d.zIndex??(A?3:void 0),padding:N?0:void 0};return B>1&&(H.height=`calc(var(--height) * ${B} - var(--border-width, 1px))`,H.zIndex=10,A&&(H.zIndex=40)),A&&b!==void 0&&(h==="left"?H.left=b:H.right=b),r.jsx("div",{ref:I,className:V,style:H,onClick:L,onDoubleClick:F,role:"gridcell","aria-colindex":u+1,"aria-readonly":!E||void 0,tabIndex:-1,"data-field":d.field,"data-colindex":u,...T>1?{"aria-colspan":T}:{},...B>1?{"aria-rowspan":B}:{},children:r.jsx("div",{className:"ogx__cell-content",children:N&&(o||k)&&w?d.renderEditCell?d.renderEditCell({value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:u,rowMeta:S}):r.jsx(dr,{value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:u,onValueChange:P,onCommit:()=>w(),onCancel:()=>w(!0)}):d.renderCell?r.jsx(ur,{field:d.field,resetKey:s,renderFn:()=>d.renderCell({value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:u,rowMeta:S})}):M})})}const kn=l.memo(fr),gr=({className:n="",...t})=>r.jsx("button",{type:"button",className:`ogx-drag-handle ${n}`,"aria-label":"Drag to reorder row",...t,children:r.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:r.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 hr(n){const{content:t,height:e,isExpanded:o}=n;if(!o)return null;const i={height:e==="auto"?"auto":`${e}px`,overflow:e==="auto"?"visible":"auto"};return r.jsx("div",{className:"ogx__detail-panel",style:i,children:r.jsx("div",{className:"ogx__detail-panel-content",children:t})})}function yt(n){const{row:t,columns:e,rowIndex:o,isSelected:i=!1,checkboxSelection:s=!1,onRowClick:d,onCellClick:a,onSelectionChange:u,columnWidths:c={},pinnedColumns:p,pinnedRows:m,hasDetailPanel:h=!1,isDetailPanelExpanded:b=!1,onDetailPanelToggle:C,detailPanelContent:y,detailPanelHeight:E=200,pinCheckboxColumn:N=!0,pinExpandColumn:j=!0,rowReordering:w=!1,onDragStart:k,onDragOver:g,onDragEnd:x,onDrop:f,isDragging:S,isDragOver:P,editingCell:M,onEditStart:_,onEditStop:I,onEditCellValueChange:L,focusedCellField:F,isFocusVisible:A,colspanMap:V,rowSpanningCaches:T,rowHeight:B=52,rowMeta:K}=n,H=l.useId(),v=l.useRef(null),R=l.useRef(null);l.useLayoutEffect(()=>{F==="__expand_col__"&&v.current&&v.current.focus({preventScroll:!0}),F==="__checkbox_col__"&&R.current&&R.current.focus({preventScroll:!0})},[F]);const W=l.useMemo(()=>Bt(e,c,p,s,N,h,j,w),[e,c,p,s,N,h,j,w]),$=K?.hasChildren===!0,G=l.useCallback((z,ie)=>{$||_?.({id:t.id,field:z,value:ie})},[$,t.id,_]),q=l.useCallback((z,ie)=>{L?.({id:t.id,field:z,value:ie})},[L,t.id]),Y=l.useCallback(z=>{I?.({cancel:z})},[I]);if(t._isSkeleton){const z=Math.max(e.length,5);return r.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:B,minHeight:B},children:Array.from({length:z}).map((ie,se)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-bar"})},se))})}const te=z=>{z.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell")||d?.({row:t,id:t.id,rowIndex:o})},O=z=>{z.stopPropagation(),u?.(t.id,z.target.checked)},J=z=>{z.stopPropagation(),C?.(t.id)},Q=$t(t.id,m),le=Q==="top",oe=Q==="bottom",pe=["ogx__row",i&&"ogx__row--selected",o%2===0&&"ogx__row--even",o%2===1&&"ogx__row--odd",le&&"ogx__row--pinned-top",oe&&"ogx__row--pinned-bottom",S&&"ogx__row--dragging",P&&"ogx__row--drag-over",$&&"ogx__row--group"].filter(Boolean).join(" ");return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:pe,onClick:te,role:"row","aria-rowindex":o+1,"aria-selected":i,"data-rowindex":o,onDragOver:g?g(t.id):void 0,onDrop:f?f(t.id):void 0,style:{maxHeight:`${B}px`,minHeight:`${B}px`,"--height":`${B}px`,"--border-width":"1px"},children:[w&&r.jsx("div",{className:"ogx__cell ogx__cell--drag-handle",role:"gridcell","aria-label":"Drag to reorder row",style:{position:"sticky",left:0,zIndex:4},draggable:!0,onDragStart:k?k(t.id):void 0,onDragEnd:x,onClick:z=>z.stopPropagation(),children:r.jsx(gr,{})}),h&&r.jsx("div",{className:`ogx__cell ogx__cell--expand ${j?"ogx__cell--pinned-left":""} ${F==="__expand_col__"?"ogx__cell--focused":""} ${F==="__expand_col__"&&A?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":b?"Collapse row details":"Expand row details","aria-expanded":b,style:{position:j?"sticky":void 0,left:j?w?48:0:void 0,zIndex:j?5:void 0},ref:v,tabIndex:-1,onClick:z=>{z.stopPropagation(),a?.({row:t,field:"__expand_col__",value:b,colDef:{field:"__expand_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(mn,{isExpanded:b,onClick:J,variant:"plus-minus"})}),s&&r.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${N?"ogx__cell--pinned-left":""} ${F==="__checkbox_col__"?"ogx__cell--focused":""} ${F==="__checkbox_col__"&&A?"ogx__cell--focus-visible":""}`,role:"gridcell",style:{position:N?"sticky":void 0,left:N?(w?48:0)+(h&&j?48:0):void 0,zIndex:N?11:void 0},ref:R,tabIndex:-1,onClick:z=>{z.stopPropagation(),a?.({row:t,field:"__checkbox_col__",value:i,colDef:{field:"__checkbox_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(ct,{id:H,name:`ogx-select-row-${t.id}`,checked:i,onChange:O,onClick:z=>z.stopPropagation(),"aria-label":i?`Deselect row ${t.id}`:`Select row ${t.id}`,tabIndex:-1,onMouseDown:z=>z.preventDefault()})}),e.map((z,ie)=>{if(z.isSpacer)return r.jsx("div",{style:{width:z.width,minWidth:z.width,flexShrink:0},"aria-hidden":"true"},z.field);const se=z.valueGetter?z.valueGetter({row:t,field:z.field,value:t[z.field]}):t[z.field],D=c[z.field]??z.width,X=dt(z.field,p),ee=X?W[z.field]:void 0,de=M?.id===t.id&&M?.field===z.field,ce=de?M?.value:se,je=V?.get(t.id)?.[z.field],Fe=T?.spannedCells[t.id]?.[z.field],Ee=T?.hiddenCells[t.id]?.[z.field]||!1;return r.jsx(kn,{value:ce,row:t,colDef:z,rowIndex:o,colIndex:ie,isSelected:i,onCellClick:a,width:D,pinnedPosition:X,pinnedOffset:ee,isFocused:F===z.field,isFocusVisible:A,isEditable:z.editable,isEditing:de,onCellEditStart:G,onEditStop:Y,onCellValueChange:q,colSpanInfo:je,rowSpan:Fe,isHiddenByRowSpan:Ee,rowMeta:K},z.field)})]}),h&&r.jsx(hr,{row:t,rowId:t.id,rowIndex:o,content:y,height:E,isExpanded:b})]})}function Sn({rows:n,position:t,columns:e,selectedRowIds:o,checkboxSelection:i,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:u,pinnedColumns:c,pinnedRows:p,hasDetailPanel:m,expandedRowIds:h,getDetailPanelContent:b,getDetailPanelHeight:C,onDetailPanelToggle:y,pinCheckboxColumn:E,pinExpandColumn:N,focusedCell:j,colspanMap:w,rowSpanningCaches:k,rowHeight:g,rowMetaMap:x}){return n.length===0?null:r.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:n.map((f,S)=>r.jsx(yt,{row:f,columns:e,rowIndex:S,isSelected:o.has(f.id),checkboxSelection:i,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:u,pinnedColumns:c,pinnedRows:p,hasDetailPanel:m,isDetailPanelExpanded:h.has(f.id),detailPanelContent:b?b({row:f,id:f.id,rowIndex:S}):null,detailPanelHeight:C?.({row:f,id:f.id,rowIndex:S})||200,onDetailPanelToggle:y,pinCheckboxColumn:E,pinExpandColumn:N,focusedCellField:j?.id===f.id?j.field:null,colspanMap:w,rowSpanningCaches:k,rowHeight:g,rowMeta:x.get(f.id)},f.id))})}const pr=({columns:n,rowHeight:t,checkboxSelection:e=!1,hasDetailPanel:o=!1,rowReordering:i=!1})=>r.jsxs("div",{className:"ogx__row ogx__skeleton-row",style:{height:t},role:"row",children:[e&&r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:r.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),o&&r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:r.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),i&&r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:r.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),n.map((s,d)=>{const a=typeof s.width=="number"?s.width:150,u=Math.min(a*.7,a-20);return r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:a,minWidth:s.minWidth,maxWidth:s.maxWidth,left:s.left,right:s.right,position:s.isSpacer?"relative":s.pinned?"sticky":"relative",zIndex:s.zIndex},children:!s.isSpacer&&r.jsx("div",{className:"ogx-skeleton-box",style:{width:u,height:16,borderRadius:4}})},s.field||d)})]});function xr({virtualContainerHeight:n,offsetTop:t,effectiveLoading:e,visibleRows:o,baseColumns:i,virtualColumns:s,viewportWidth:d,checkboxSelection:a,hasDetailPanel:u,rowReordering:c,rowHeight:p,pinnedRows:m,selectedRowIds:h,onRowClick:b,onCellClick:C,onSelectionChange:y,columnWidths:E,pinnedColumns:N,expandedRowIds:j,getDetailPanelContent:w,getDetailPanelHeight:k,onDetailPanelToggle:g,pinCheckboxColumn:x,pinExpandColumn:f,rowReorderHandlers:S,editingHandlers:P,focusedCell:M,colspanMap:_,rowSpanningCaches:I,paginationMode:L,dataSourceLoading:F,sortedUnpinnedRowCount:A,infiniteScrollSkeletonCount:V,unpinnedRowsLength:T,rowMetaMap:B}){const K=i.length>0?i:(()=>{const v=(d||1e3)-(a?48:0)-(u?48:0)-(c?48:0),R=150,W=Math.max(1,Math.ceil(v/R));return Array.from({length:W},($,G)=>({field:`placeholder_${G}`,headerName:"",width:R}))})(),H=o.filter(({row:v})=>!$t(v.id,m)).filter((v,R,W)=>R===W.findIndex($=>$.row.id===v.row.id));return r.jsx("div",{className:"ogx__virtual-container",style:{height:`${n}px`},role:"presentation",children:r.jsxs("div",{className:"ogx__rows",style:{transform:`translateY(${t}px)`},role:"rowgroup",children:[e&&o.length===0?Array.from({length:10}).map((v,R)=>r.jsx(pr,{columns:K,rowHeight:p,checkboxSelection:a,hasDetailPanel:u,rowReordering:c},`skeleton-${R}`)):H.map(({row:v,rowIndex:R})=>r.jsx(yt,{row:v,columns:s,rowIndex:R,isSelected:h.has(v.id),checkboxSelection:a,onRowClick:b,onCellClick:C,onSelectionChange:y,columnWidths:E,pinnedColumns:N,pinnedRows:m,hasDetailPanel:u,isDetailPanelExpanded:j.has(v.id),detailPanelContent:w?w({row:v,id:v.id,rowIndex:R}):null,detailPanelHeight:k?.({row:v,id:v.id,rowIndex:R})||200,onDetailPanelToggle:g,pinCheckboxColumn:x,pinExpandColumn:f,rowReordering:c,onDragStart:S.onDragStart,onDragOver:S.onDragOver,onDragEnd:S.onDragEnd,onDrop:S.onDrop,isDragging:S.draggedRowId===v.id,isDragOver:S.dragOverRowId===v.id,editingCell:P.editingCell,onEditStart:P.startCellEdit,onEditStop:P.stopCellEdit,onEditCellValueChange:P.setEditCellValue,focusedCellField:M!=null&&M.id===v.id?M.field:null,colspanMap:_,rowSpanningCaches:I,rowHeight:p,rowMeta:B.get(v.id)},v.id)),L==="infinite"&&F&&A>0&&r.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:V}).map((v,R)=>r.jsx(yt,{row:{id:`__skeleton_${R}__`,_isSkeleton:!0},columns:s,rowIndex:T+R,rowHeight:p},`__skeleton_${R}__`))})]})})}function mr(){return r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function br(){return r.jsxs("svg",{className:"ogx-column-visibility-panel__drag-handle",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[r.jsx("circle",{cx:"9",cy:"5",r:"1.5"}),r.jsx("circle",{cx:"15",cy:"5",r:"1.5"}),r.jsx("circle",{cx:"9",cy:"12",r:"1.5"}),r.jsx("circle",{cx:"15",cy:"12",r:"1.5"}),r.jsx("circle",{cx:"9",cy:"19",r:"1.5"}),r.jsx("circle",{cx:"15",cy:"19",r:"1.5"})]})}function jn(n){const{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:i,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a}=n,[u,c]=l.useState(""),[p,m]=l.useState(null),h=l.useRef(null),C=l.useMemo(()=>t.filter(x=>x.hideable!==!1),[t]).every(x=>e.has(x.field)),y=l.useMemo(()=>{if(!u)return t;const x=u.toLowerCase();return t.filter(f=>(f.headerName||f.field).toLowerCase().includes(x))},[t,u]),E=x=>{x.target.checked?i():s()},N=x=>f=>{h.current=x,f.dataTransfer.effectAllowed="move",f.dataTransfer.setDragImage(f.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},j=x=>f=>{f.preventDefault(),f.dataTransfer.dropEffect="move",x!==h.current&&m(x)},w=()=>{m(null)},k=x=>f=>{f.preventDefault();const S=h.current;m(null),h.current=null,S&&S!==x&&d&&d(S,x)},g=()=>{m(null),h.current=null};return r.jsxs("div",{className:"ogx-column-visibility-panel",children:[r.jsx("div",{className:"ogx-column-visibility-panel__search-section",children:r.jsxs("div",{className:"ogx-column-visibility-panel__search-container",children:[r.jsx(mr,{}),r.jsx("input",{autoComplete:"off",className:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:u,onChange:x=>c(x.target.value)})]})}),r.jsx("div",{className:"ogx-column-visibility-panel__list",children:y.map(x=>{const f=e.has(x.field),S=x.hideable!==!1,P=p===x.field,M=!!d&&!u;return r.jsxs("div",{className:["ogx-column-visibility-panel__item",!S&&"ogx-column-visibility-panel__item--disabled",P&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:M,onDragOver:M?j(x.field):void 0,onDragLeave:M?w:void 0,onDrop:M?k(x.field):void 0,onDragEnd:M?g:void 0,children:[M&&r.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:N(x.field),title:"Drag to reorder",children:r.jsx(br,{})}),r.jsxs("label",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:S?"pointer":"not-allowed"},children:[r.jsx(ct,{checked:f,onChange:_=>o(x.field,_.target.checked),disabled:!S}),r.jsx("span",{className:"ogx-column-visibility-panel__label",children:x.headerName||x.field})]})]},x.field)})}),r.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[r.jsxs("label",{className:"ogx-column-visibility-panel__item",children:[r.jsx(ct,{checked:C,onChange:E}),r.jsx("span",{className:"ogx-column-visibility-panel__label",children:"Show/Hide All"})]}),r.jsx("button",{className:"ogx-column-visibility-panel__reset-btn",onClick:()=>{i(),a?.()},children:"Reset"})]})]})}function wr({isOpen:n,containerRef:t,panelRef:e,effectiveColumns:o,columnVisibilityModel:i,effectiveColumnOrder:s,columnOrder:d,disableColumnReorder:a,onClose:u,onColumnVisibilityChange:c,onColumnOrderChange:p,setInternalColumnOrder:m}){const[h,b]=l.useState(16),[C,y]=l.useState(16),[E,N]=l.useState(()=>document.body);if(l.useLayoutEffect(()=>{if(!n||!t.current)return;const w=t.current.getBoundingClientRect();b(w.top+8),y(window.innerWidth-w.right+8),N(t.current.closest(".ogx-theme-provider")||document.body)},[n,t]),!n)return null;const j=a?void 0:(w,k)=>{const g=[...s],x=g.indexOf(w),f=g.indexOf(k);if(x===-1||f===-1)return;const S=[...g];S.splice(x,1),S.splice(f,0,w),d||m(S),p?.({oldIndex:x,targetIndex:f,column:o.find(P=>P.field===w)})};return ze.createPortal(r.jsxs("div",{ref:e,style:{position:"fixed",top:h,right:C,zIndex:9999,display:"inline-block"},children:[r.jsx("button",{onClick:u,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:"×"}),r.jsx(jn,{columns:o,visibleColumns:new Set(o.filter(w=>i[w.field]!==!1).map(w=>w.field)),onVisibilityChange:(w,k)=>{c({...i,[w]:k})},onShowAll:()=>{const w={...i};o.forEach(k=>{k.hideable!==!1&&(w[k.field]=!0)}),c(w)},onHideAll:()=>{const w={...i};o.forEach(k=>{k.hideable!==!1&&(w[k.field]=!1)}),c(w)},onColumnReorder:j})]}),E)}const vr=new Map;function _r(n){const{rows:t,columns:e,getRowId:o,rowHeight:i=52,headerHeight:s=56,autoHeight:d=!1,checkboxSelection:a=!1,rowSelectionModel:u,onRowSelectionModelChange:c,onRowClick:p,onCellClick:m,filterModel:h,onFilterModelChange:b,sortModel:C,onSortModelChange:y,pagination:E=!1,paginationModel:N={page:0,pageSize:100},onPaginationModelChange:j,pageSizeOptions:w=[10,25,50,100],pinnedColumns:k,onPinnedColumnsChange:g,pinnedRows:x,getDetailPanelContent:f,getDetailPanelHeight:S,detailPanelExpandedRowIds:P,onDetailPanelExpandedRowIdsChange:M,pinCheckboxColumn:_=!0,pinExpandColumn:I=!0,disableColumnReorder:L=!1,columnOrder:F,onColumnOrderChange:A,height:V,rowReordering:T=!1,onRowOrderChange:B,loading:K=!1,treeData:H=!1,getTreeDataPath:v,defaultGroupingExpansionDepth:R,rowGroupingModel:W,aggregationModel:$,onAggregationModelChange:G,getAggregationPosition:q,isCellEditable:Y,processRowUpdate:te,onProcessRowUpdateError:O,dataSource:J,sortingMode:Q="client",filterMode:le="client",paginationMode:oe="client",rowCount:pe,slots:z,slotProps:ie,pivotMode:se=!1,pivotModel:D,onPivotModelChange:X,className:ee="",style:de,onRowsScrollEnd:ce,ariaLabel:je,initialState:Fe,onStateChange:Ee,columnVisibilityModel:fe,onColumnVisibilityModelChange:qe,listView:ne=!1,listViewColumn:ve,columnGroupingModel:Be,noRowsLabel:fi="No Data",localeText:Pe,apiRef:Ut}=n,Kt=Pe?.noRowsLabel??fi,gi=l.useMemo(()=>({items:[]}),[]),ke=h||gi,hi=l.useMemo(()=>[],[]),Yt=W||hi,On=l.useRef(z?.toolbar);On.current=z?.toolbar;const pi=l.useRef(U=>{const Z=On.current;return Z?Z(U):null}).current,xi=so({initialState:Fe,sortModel:C,aggregationModel:$,onAggregationModelChange:G,columnVisibilityModel:fe,onColumnVisibilityModelChange:qe,pinnedColumns:k,onPinnedColumnsChange:g,pivotModel:D,onPivotModelChange:X,paginationModel:N,onPaginationModelChange:j,rowSelectionModel:u}),{sortModel:We,isSortControlled:Fn,setInternalSortModel:Wn,aggregationModel:Se,handleAggregationModelChange:An,columnVisibilityModel:$e,handleColumnVisibilityModelChange:kt,pinnedColumns:Ie,handlePinnedColumnsChange:qt,currentPivotModel:Xt,handlePivotModelChange:zn,effectivePaginationModel:Ce,handlePaginationModelChange:Jt,selectedRowIds:_e,isSelectionControlled:St,setInternalRowSelectionModel:jt}=xi,Et=c,Nt=yn(t,e,Xt,se),Bn=se&&Nt.isValid?Nt.pivotRows:t,Qt=se&&Nt.isValid?Nt.pivotColumns:e,[mi,$n]=l.useState(null);l.useEffect(()=>{$n(null)},[Se]);const Xe=l.useRef(null),bi=l.useRef(null),Mt=l.useRef(null),wi=l.useCallback(U=>U.id,[]),Je=o||wi,Zt=l.useMemo(()=>Bn.map(U=>{const Z=Je(U);return Z===U.id?U:{...U,id:Z}}),[Bn,Je]),Qe=l.useCallback(U=>{fn.current?.classList.toggle("ogx--kb",U)},[]),Dn=l.useRef(J);Dn.current=J;const Hn=l.useRef(null),Gn=l.useRef(null),vi=l.useCallback(U=>{if(Dn.current&&H&&(U.serverChildrenCount??0)>0&&(U.children??[]).length===0){const Z=Gn.current?.getNodePath(U.id)||[U.groupingKey];Hn.current?.(U.id,Z)}},[H]),be=Do({rows:Zt,columns:Qt,rowHeight:i,headerHeight:s,rowCount:pe,columnVisibilityModel:$e,initialState:n.initialState}),{state:ue,apiRef:Ze,setRows:en,setColumns:_i,setDimensions:Vn,setDataSourceLoading:Ci,setDataSourceError:yi,setRowCount:ki}=be,{scrollTop:Si,scrollLeft:ji,handleScroll:Ei}=vo({onRowsScrollEnd:ce});l.useEffect(()=>{Ut&&(Ut.current=Ze.current)},[Ut,Ze]);const{copySelectedRows:Un}=tr({selectedRowIds:_e,columns:Qt,getVisibleRows:()=>Ze.current.getVisibleRows(),getRowId:Je});l.useEffect(()=>{Ze.current.copySelectedRows=Un,Ze.current.getSelectedRows=()=>Array.from(_e)},[Un,_e,Ze]);const Ni=ue.dataSource.loading,ht=K||Ni,et=l.useMemo(()=>ue.rows.allRows.map(U=>ue.rows.idRowsLookup.get(U)),[ue.rows]),pt=Go({rows:et,getRowId:Je,getTreeDataPath:v,treeData:H,defaultGroupingExpansionDepth:R,filterModel:ke,sortModel:We,onRowExpansionChange:vi});l.useEffect(()=>{Gn.current=pt},[pt]);const tn=Yo({rows:et,getRowId:Je,rowGroupingModel:Yt,aggregationModel:Se,defaultGroupingExpansionDepth:R,filterModel:ke,sortModel:We,getAggregationPosition:q}),tt=qo({rows:et,getRowId:Je,processRowUpdate:te,onProcessRowUpdateError:O,onRowChange:U=>{const{dispatch:Z}=be,xe=Array.from(be.state.rows.idRowsLookup.values()).map(he=>he.id===U.id?U:he);Z({type:"SET_ROWS",payload:xe})}}),xt=H,nt=!!(Yt&&Yt.length>0),nn=xt||nt,Pt=xt?pt:nt?tn:null,mt=l.useMemo(()=>xt?pt.rowMetaMap:nt?tn.rowMetaMap:vr,[xt,pt.rowMetaMap,nt,tn.rowMetaMap]),Te=E&&!nt,It=l.useCallback(U=>{const{row:Z,id:ae}=U;if(nn&&mt.get(Z.id)?.hasChildren){Pt?.toggleExpansion(ae);return}p?.(U)},[nn,Pt,p,mt]),on=Jo({dataSource:J,sortModel:We,filterModel:ke,paginationModel:Ce,paginationMode:oe,sortingMode:Q,filterMode:le,aggregationModel:Se,setRows:en,setRowCount:ki,setDataSourceLoading:Ci,setDataSourceError:yi,onAggregationResults:$n});l.useEffect(()=>{on.fetchChildren&&(Hn.current=on.fetchChildren)},[on.fetchChildren]),l.useEffect(()=>{J||en(Zt)},[Zt,en,J]);const Le=!!f,[Mi,Pi]=l.useState(new Set),ot=P??Mi,Tt=l.useCallback(U=>{const Z=new Set(ot);Z.has(U)?Z.delete(U):Z.add(U),P===void 0&&Pi(Z),M?.(Z)},[ot,P,M]),{effectiveColumns:Ae,orderedColumns:rn,visibleOrderedColumns:Ii,navigationColumns:Kn,columnWidths:Re,effectiveColumnOrder:Lt,setInternalColumnOrder:Rt,columnReorderHandlers:rt,handleColumnResize:Ti}=bo({activeColumns:Qt,isHierarchyEnabled:nn,isRowGrouping:nt,isTreeData:xt,activeHierarchyHandlers:Pt,columnVisibilityModel:$e,columnOrder:F,onColumnOrderChange:A,disableColumnReorder:L,pivotMode:se,checkboxSelection:a,hasDetailPanel:Le,rowReordering:T,initialState:Fe,setColumns:_i});_o({onStateChange:Ee,sortModel:We,filterModel:ke,effectivePaginationModel:Ce,columnWidths:Re,effectiveColumnOrder:Lt,columnVisibilityModel:$e,pinnedColumns:Ie});const it=po({effectiveRows:et,activeHierarchyHandlers:Pt,filterMode:le,filterModel:ke,dataSource:J,sortModel:We,sortingMode:Q,pagination:Te,paginationMode:oe,effectivePaginationModel:Ce,pinnedRows:x,isLoading:ue.dataSource.loading,pageSize:Ce.pageSize}),De=it.filteredRows,ln=it.pinnedTopRows,sn=it.pinnedBottomRows,He=it.sortedUnpinnedRows,bt=it.paginatedUnpinnedRows,an=it.allRenderableRows;l.useEffect(()=>{be.apiRef.current.getVisibleRows=()=>Te?bt:He,be.apiRef.current.getAllFilteredRows=()=>He,be.apiRef.current.getVisibleColumns=()=>Ae},[He,bt,Te,Ae,be.apiRef]);const Li=Ho({rows:Te?bt:He,getRowId:U=>U.id,onRowOrderChange:B,rowReordering:T}),lt=Xo(an,Kn,Re),{aggregationResult:dn}=bn({rows:De,aggregationModel:Se,isServerSide:!!(J&&(oe==="server"||Q==="server")),dataSource:J,filterModel:ke,sortModel:We,serverAggregationResults:mi}),Ot=Object.keys(Se).length>0;l.useEffect(()=>{be.apiRef.current.getAggregationResult=()=>Ot?dn:null,be.apiRef.current.getAggregationModel=()=>Ot?Se:null},[dn,Se,Ot,be.apiRef]);const ge=ro({rowHeight:i,pagination:Te,paginatedUnpinnedRows:bt,sortedUnpinnedRows:He,expandedRowIds:ot,getDetailPanelHeight:S,pinnedTopRowsLength:ln.length,pinnedBottomRowsLength:sn.length,visibleOrderedColumns:Ii,pinnedColumns:Ie,columnWidths:Re,viewportWidth:ue.dimensions.viewportWidth||1e3,checkboxSelection:a,hasDetailPanel:Le,rowReordering:T,paginationMode:oe,isLoading:ue.dataSource.loading,pageSize:Ce.pageSize}),Ri=l.useMemo(()=>{const U={};for(const Z of[...ge.leftPinnedCols,...ge.unpinnedColsWithWidth,...ge.rightPinnedCols])Z.isSpacer||(U[Z.field]=Z.width);return{...U,...Re}},[ge.leftPinnedCols,ge.unpinnedColsWithWidth,ge.rightPinnedCols,Re]);l.useEffect(()=>{be.apiRef.current.scrollToIndexes=({rowIndex:U,colIndex:Z})=>{const ae=Xe.current;if(ae){if(U!==void 0&&U>=0){const xe=U>0?ge.cumulativeHeights[U-1]:0,he=ge.cumulativeHeights[U]??xe,{scrollTop:me,clientHeight:we}=ae;xe<me?ae.scrollTop=xe:he>me+we&&(ae.scrollTop=he-we)}if(Z!==void 0&&Z>=0){const he=[...ge.leftPinnedCols,...ge.unpinnedColsWithWidth,...ge.rightPinnedCols][Z];if(!he)return;const me=ge.unpinnedColsWithWidth.findIndex(Hi=>Hi.field===he.field);if(me===-1)return;const we=me>0?ge.unpinnedAccWidths[me-1]:0,At=ge.unpinnedAccWidths[me]??we,zt=ge.leftWidth+At,{scrollLeft:Jn,clientWidth:Qn}=ae;we<Jn?ae.scrollLeft=we:zt>Jn+Qn&&(ae.scrollLeft=zt-Qn)}}}},[ge,Xe,be.apiRef]);const ye=xo({layout:ge,scrollTop:Si,scrollLeft:ji,viewportWidth:ue.dimensions.viewportWidth,viewportHeight:ue.dimensions.viewportHeight,autoHeight:d,rowReordering:T,hasDetailPanel:Le,checkboxSelection:a,pinCheckboxColumn:_,pinExpandColumn:I});l.useEffect(()=>{if(!Xe.current)return;const U=new ResizeObserver(Z=>{for(const ae of Z){const{width:xe,height:he}=ae.contentRect;Vn(xe,he)}});return U.observe(Xe.current),()=>{U.disconnect()}},[Vn]);const wt=l.useCallback((U,Z)=>{const ae=new Set(_e);Z?ae.add(U):ae.delete(U);const xe=Array.from(ae);St||jt(xe),Et?.(xe)},[_e,St,Et,jt]),Oi=l.useCallback(U=>{let Z=[];U&&(Z=et.map(ae=>ae.id)),St||jt(Z),Et?.(Z)},[et,St,Et,jt]),Yn=l.useCallback((U,Z)=>{const ae=Z?[{field:U,sort:Z}]:[];Fn||Wn(ae),y?.(ae)},[Fn,y,Wn]),{focusedCell:Ft,setFocusedCell:cn,handleFocus:Fi,handleBlur:Wi,handleKeyDown:Ai}=io({allRenderableRows:an,navigationColumns:Kn,checkboxSelection:a,selectedRowIds:_e,handleSelectionChange:wt,handleDetailPanelToggle:Tt,editingHandlers:tt,setKeyboardMode:Qe,sortModel:We,handleSort:Yn,isCellEditable:Y,pagination:Te,pageSize:Ce.pageSize,virtualization:ye,viewportRef:Xe}),un=l.useCallback(U=>{Qe(!1),cn({id:U.row.id,field:U.field}),Mt.current?.focus({preventScroll:!0}),m?.(U)},[m,Qe,cn]),qn=l.useRef(tt.editingCell);l.useEffect(()=>{const U=!!qn.current,Z=!!tt.editingCell;U&&!Z&&Mt.current?.focus({preventScroll:!0}),qn.current=tt.editingCell},[tt.editingCell]);const zi=wo({renderContext:ye.renderContext,pinnedTopRows:ln,pinnedBottomRows:sn,paginatedUnpinnedRows:bt,sortedUnpinnedRows:He,pagination:Te}),Bi=t.length>0&&_e.size===t.length,$i=_e.size>0&&_e.size<t.length,Di=l.useMemo(()=>Ae.some(U=>!!U.rowSpan),[Ae]),[vt,Wt]=l.useState(!1),fn=l.useRef(null),gn=l.useRef(null),Xn=l.useMemo(()=>{if(!z?.toolbar)return null;const U=L?void 0:(Z,ae)=>{const xe=[...Lt],he=xe.indexOf(Z),me=xe.indexOf(ae);if(he===-1||me===-1)return;const we=[...xe];we.splice(he,1),we.splice(me,0,Z),F||Rt(we);const At=Ae.find(zt=>zt.field===Z);At&&A?.({oldIndex:he,targetIndex:me,column:At})};return{apiRef:be.apiRef,columns:rn,baseColumns:e,aggregationModel:Se,onAggregationModelChange:An,...se||D||X?{pivotModel:Xt,onPivotModelChange:zn}:{},filterModel:ke,onFilterModelChange:b,columnVisibilityModel:$e,onColumnVisibilityModelChange:kt,onColumnReorder:U,onColumnOrderReset:L?void 0:()=>Rt(e.map(Z=>Z.field)),forceColumnsOpen:vt,onColumnsPanelClose:()=>Wt(!1),...ie?.toolbar}},[z?.toolbar,L,Lt,rn,Ae,F,A,Rt,be.apiRef,e,Se,An,se,D,X,Xt,zn,ke,b,$e,kt,vt,ie?.toolbar]);return l.useEffect(()=>{if(!vt||z?.toolbar)return;function U(Z){gn.current&&!gn.current.contains(Z.target)&&Wt(!1)}return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[vt,z?.toolbar]),r.jsxs("div",{ref:fn,className:["ogx",ee,d&&"ogx--auto-height",Di&&"ogx--row-spanning",ne&&"ogx--list-view"].filter(Boolean).join(" "),style:{...de,height:V??de?.height,"--ogx-row-height":`${i}px`,"--ogx-header-height":`${s}px`},"aria-busy":ht,children:[Xn&&r.jsx(pi,{...Xn}),!z?.toolbar&&r.jsx(wr,{isOpen:vt,containerRef:fn,panelRef:gn,effectiveColumns:Ae,columnVisibilityModel:$e,effectiveColumnOrder:Lt,columnOrder:F,disableColumnReorder:L,onClose:()=>Wt(!1),onColumnVisibilityChange:kt,onColumnOrderChange:A,setInternalColumnOrder:Rt}),ne&&ve&&r.jsx(or,{ariaLabel:je,allRenderableRows:an,filteredRows:De,pagination:Te,effectivePaginationModel:Ce,pageSizeOptions:w,selectedRowIds:_e,listViewColumn:ve,noRowsLabel:Kt,rowHeight:i,checkboxSelection:a,paginationMode:oe,dataSource:J,serverRowCount:ue.pagination.rowCount||0,paginationSlot:z?.pagination,paginationSlotProps:ie?.pagination,localeText:Pe?{paginationRowsPerPage:Pe.paginationRowsPerPage,paginationOf:Pe.paginationOf,paginationPage:Pe.paginationPage}:void 0,onRowClick:It,onSelectionChange:wt,onPaginationModelChange:Jt}),!ne&&r.jsx("div",{ref:U=>{Xe.current=U,Mt.current=U},className:"ogx__viewport",onScroll:Ei,role:"grid","aria-label":je||"Data grid","aria-rowcount":De.length+1,"aria-colcount":e.length+(a?1:0)+(Le?1:0)+(T?1:0),"aria-busy":ht,tabIndex:0,onKeyDownCapture:()=>{Qe(!0)},onMouseDownCapture:()=>{Qe(!1)},onKeyDown:Ai,onFocus:Fi,onBlur:Wi,children:r.jsxs("div",{ref:bi,className:"ogx__content",style:{width:ye.totalWidth},role:"presentation",children:[r.jsx(vn,{columns:ye.virtualColumns,allColumns:Ae,columnGroupingModel:Be,checkboxSelection:a,allSelected:Bi,someSelected:$i,onSelectAll:Oi,sortModel:We,onSort:Yn,onColumnResize:Ti,columnWidths:Re,pinnedColumns:Ie,focusedCell:Ft,onHeaderClick:U=>{cn({id:"HEADER",field:U}),Qe(!1),Mt.current?.focus({preventScroll:!0})},onDragStart:Be?void 0:rt.onDragStart,onDragOver:Be?void 0:rt.onDragOver,onDragEnd:Be?void 0:rt.onDragEnd,onDrop:Be?void 0:rt.onDrop,draggedColumn:Be?void 0:rt.draggedColumn,dragOverColumn:Be?void 0:rt.dragOverColumn,rowReordering:T,hasDetailPanel:Le,pinCheckboxColumn:_,pinExpandColumn:I,aggregationModel:Se,onHideColumn:U=>{kt({...$e,[U]:!1})},onManageColumns:()=>Wt(!0),onPinColumn:(U,Z)=>{const ae=[...Ie?.left??[]],xe=[...Ie?.right??[]],he=ae.filter(we=>we!==U),me=xe.filter(we=>we!==U);qt(Z==="left"?{left:[...he,U],right:me}:Z==="right"?{left:he,right:[...me,U]}:{left:he,right:me})}}),!ht&&!ue.dataSource.error&&De.length===0&&r.jsx(ko,{noRowsLabel:Kt,width:ye.totalWidth}),r.jsx(Sn,{rows:ln,position:"top",columns:ye.virtualColumns,selectedRowIds:_e,checkboxSelection:a,onRowClick:It,onCellClick:un,onSelectionChange:wt,columnWidths:Re,pinnedColumns:Ie,pinnedRows:x,hasDetailPanel:Le,expandedRowIds:ot,getDetailPanelContent:f,getDetailPanelHeight:S,onDetailPanelToggle:Tt,pinCheckboxColumn:_,pinExpandColumn:I,focusedCell:Ft,colspanMap:lt.colspanMap,rowSpanningCaches:lt.rowSpanningState.caches,rowHeight:i,rowMetaMap:mt}),r.jsx(xr,{virtualContainerHeight:ye.totalHeight-ye.pinnedTopHeight-ye.pinnedBottomHeight,offsetTop:ye.offsetTop,effectiveLoading:ht,visibleRows:zi,baseColumns:e,virtualColumns:ye.virtualColumns,viewportWidth:ue.dimensions.viewportWidth,checkboxSelection:a,hasDetailPanel:Le,rowReordering:T,rowHeight:i,pinnedRows:x,selectedRowIds:_e,onRowClick:It,onCellClick:un,onSelectionChange:wt,columnWidths:Re,pinnedColumns:Ie,expandedRowIds:ot,getDetailPanelContent:f,getDetailPanelHeight:S,onDetailPanelToggle:Tt,pinCheckboxColumn:_,pinExpandColumn:I,rowReorderHandlers:Li,editingHandlers:tt,focusedCell:Ft,colspanMap:lt.colspanMap,rowSpanningCaches:lt.rowSpanningState.caches,paginationMode:oe,dataSourceLoading:ue.dataSource.loading,sortedUnpinnedRowCount:He.length,infiniteScrollSkeletonCount:Math.min(Ce.pageSize,20),unpinnedRowsLength:ge.unpinnedRowsLength,rowMetaMap:mt}),r.jsx(Sn,{rows:sn,position:"bottom",columns:ye.virtualColumns,selectedRowIds:_e,checkboxSelection:a,onRowClick:It,onCellClick:un,onSelectionChange:wt,columnWidths:Re,pinnedColumns:Ie,pinnedRows:x,hasDetailPanel:Le,expandedRowIds:ot,getDetailPanelContent:f,getDetailPanelHeight:S,onDetailPanelToggle:Tt,pinCheckboxColumn:_,pinExpandColumn:I,focusedCell:Ft,colspanMap:lt.colspanMap,rowSpanningCaches:lt.rowSpanningState.caches,rowHeight:i,rowMetaMap:mt}),Ot&&!se&&r.jsx(yo,{columns:rn,aggregationModel:Se,aggregationResult:dn,columnWidths:Ri,rowHeight:i,checkboxSelection:a,hasDetailPanel:Le,rowReordering:T,pinnedColumns:Ie})]})}),!ne&&Te&&(()=>{const U=z?.pagination||_n;return r.jsx(U,{page:Ce.page,pageSize:Ce.pageSize,rowCount:ue.pagination.rowCount,pageSizeOptions:w,onPageChange:Z=>Jt({...Ce,page:Z}),onPageSizeChange:Z=>Jt({...Ce,pageSize:Z,page:0}),localeText:Pe?{paginationRowsPerPage:Pe.paginationRowsPerPage,paginationOf:Pe.paginationOf,paginationPage:Pe.paginationPage}:void 0,...ie?.pagination})})(),r.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[ht?"Loading data...":"",ue.dataSource.error?`Error: ${ue.dataSource.error instanceof Error?ue.dataSource.error.message:"Unknown error"}`:"",!K&&!ue.dataSource.error&&(De.length===0?Kt:ke&&((ke.quickFilterValues?.length||0)>0||(ke.items?.length||0)>0)?`${De.length} ${De.length===1?"row":"rows"} found`:"")]}),r.jsx(So,{error:ue.dataSource.error})]})}function Cr({rows:n=5,columns:t=5}){return r.jsx("div",{className:"ogx__skeleton",children:Array.from({length:n}).map((e,o)=>r.jsx("div",{className:"ogx__skeleton-row",children:Array.from({length:t}).map((i,s)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-content"})},s))},o))})}const En=new Set(["isEmpty","isNotEmpty"]);function yr(n,t){return n.find(e=>"field"in e&&e.field===t)}const kr=({col:n,item:t,onChange:e})=>{const o=l.useId(),i=go(n.type),s=!!t,d=t?.operator??i[0],[a,u]=l.useState(t?.value!=null?String(t.value):""),c=l.useRef(e),p=l.useRef(t),m=l.useRef(n.field),h=l.useRef(d);l.useLayoutEffect(()=>{c.current=e,p.current=t,m.current=n.field,h.current=d});const b=l.useRef(t?.value);l.useEffect(()=>{t?.value!==b.current&&(b.current=t?.value,u(t?.value!=null?String(t.value):""))},[t?.value]),l.useEffect(()=>{const w=setTimeout(()=>{const k=p.current,g=k?.value??"";a!==g&&c.current({id:k?.id??`${m.current}-${Date.now()}`,field:m.current,operator:h.current,value:a})},300);return()=>clearTimeout(w)},[a]);const C=w=>{const k=En.has(w),g={id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:w,value:k?void 0:t?.value??(n.type==="boolean"?"true":"")};e(g)},y=()=>{u(""),e(null)},E=En.has(String(d)),N=n.type==="boolean",j=!E;return r.jsxs("div",{className:`ogx-filter__row${s?" ogx-filter__row--active":""}`,children:[r.jsx("span",{className:"ogx-filter__col-label",title:n.field,children:n.headerName||n.field}),r.jsxs("div",{className:"ogx-filter__controls",children:[r.jsx("select",{id:`${o}-op`,name:`filter-op-${n.field}`,className:`ogx-filter__op-select${s?" ogx-filter__op-select--active":""}`,value:String(d),onChange:w=>C(w.target.value),"aria-label":`Filter operator for ${n.headerName||n.field}`,children:i.map(w=>r.jsx("option",{value:w,children:w},w))}),j&&N&&r.jsxs("select",{id:`${o}-val`,name:`filter-val-${n.field}`,className:`ogx-filter__value-input ogx-filter__value-select${s?" ogx-filter__value-input--active":""}`,value:String(t?.value??"true"),onChange:w=>{u(w.target.value),e({id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:d,value:w.target.value})},"aria-label":`Filter value for ${n.headerName||n.field}`,children:[r.jsx("option",{value:"true",children:"true"}),r.jsx("option",{value:"false",children:"false"})]}),j&&!N&&r.jsx("input",{id:`${o}-val`,name:`filter-val-${n.field}`,className:`ogx-filter__value-input${s?" ogx-filter__value-input--active":""}`,type:"text",value:a,onChange:w=>u(w.target.value),placeholder:n.type==="number"?"Number…":"Value…","aria-label":`Filter value for ${n.headerName||n.field}`}),s&&r.jsx("button",{className:"ogx-filter__row-clear",onClick:y,"aria-label":`Clear filter for ${n.headerName||n.field}`,title:"Clear",children:"×"})]})]})},Nn=({filterModel:n,columns:t,onFilterModelChange:e})=>{const o=l.useMemo(()=>n.items??[],[n.items]),i=n.logicOperator??"and",s=l.useCallback((u,c)=>{const p=o.filter(h=>"field"in h&&h.field!==u),m=c?[...p,c]:p;e({...n,items:m})},[o,n,e]),d=l.useCallback(u=>{e({...n,logicOperator:u})},[n,e]),a=t.filter(u=>u.filterable!==!1);return r.jsxs(r.Fragment,{children:[o.length>1&&r.jsxs("div",{className:"ogx-filter__logic-bar",children:[r.jsx("span",{className:"ogx-filter__logic-label",children:"Match:"}),r.jsx("button",{className:`ogx-filter__logic-pill${i==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("and"),"aria-pressed":i==="and",children:"ALL (AND)"}),r.jsx("button",{className:`ogx-filter__logic-pill${i==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("or"),"aria-pressed":i==="or",children:"ANY (OR)"})]}),a.length===0?r.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):a.map(u=>r.jsx(kr,{col:u,item:yr(o,u.field),onChange:c=>s(u.field,c)},u.field))]})},Sr=["sum","avg","count","min","max"];function Mn(){return r.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:[r.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),r.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),r.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),r.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",fill:"currentColor",opacity:"0.25"}),r.jsx("path",{d:"M17 14v-4M17 10l-2 2 2 2"})]})}function jr({anchorRef:n,columns:t,model:e,onChange:o,onClose:i}){const s=l.useRef(null),[d,a]=l.useState({top:0,right:0}),[u,c]=l.useState(document.body);l.useLayoutEffect(()=>{c(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const p=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const _=n.current.getBoundingClientRect();return{top:_.bottom+6,right:window.innerWidth-_.right}},[n]);l.useEffect(()=>{a(p());const _=()=>a(p());return window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_)}},[p]),l.useEffect(()=>{function _(L){s.current&&!s.current.contains(L.target)&&n.current&&!n.current.contains(L.target)&&i()}function I(L){L.key==="Escape"&&i()}return document.addEventListener("mousedown",_),document.addEventListener("keydown",I),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",I)}},[n,i]);const m=new Set(e.rowFields),h=new Set(e.columnFields),b=new Set(e.valueFields.map(_=>_.field)),C=_=>m.has(_)||h.has(_)||b.has(_);function y(_){m.has(_)||o({...e,rowFields:[...e.rowFields,_]})}function E(_){h.has(_)||o({...e,columnFields:[...e.columnFields,_]})}function N(_,I="sum"){b.has(_)||o({...e,valueFields:[...e.valueFields,{field:_,aggFn:I}]})}function j(_){o({...e,rowFields:e.rowFields.filter(I=>I!==_)})}function w(_){o({...e,columnFields:e.columnFields.filter(I=>I!==_)})}function k(_){o({...e,valueFields:e.valueFields.filter(I=>I.field!==_)})}function g(_,I){o({...e,valueFields:e.valueFields.map(L=>L.field===_?{...L,aggFn:I}:L)})}function x(){o({rowFields:[],columnFields:[],valueFields:[]})}const f=new Set(t.filter(_=>_.type==="number"||_.aggregable).map(_=>_.field)),S=e.rowFields.length+e.columnFields.length+e.valueFields.length,P=_=>t.find(I=>I.field===_)?.headerName??_,M=r.jsxs("div",{ref:s,className:"ogx-pivot-panel",role:"dialog","aria-label":"Pivot configuration",style:{top:d.top,right:d.right},children:[r.jsxs("div",{className:"ogx-pivot-panel__header",children:[r.jsxs("span",{className:"ogx-pivot-panel__title",children:[r.jsx(Mn,{}),"Pivot Mode"]}),S>0&&r.jsx("button",{className:"ogx-pivot-panel__reset-btn",onClick:x,title:"Reset pivot",children:"Reset"})]}),r.jsxs("div",{className:"ogx-pivot-panel__body",children:[r.jsxs("div",{className:"ogx-pivot-zone",children:[r.jsxs("span",{className:"ogx-pivot-zone__label",children:[r.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--row"}),"Row Fields"]}),r.jsx("div",{className:`ogx-pivot-chips${e.rowFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — each becomes a row label",children:e.rowFields.map(_=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[P(_),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>j(_),title:`Remove ${P(_)}`,children:"×"})]},_))})]}),r.jsxs("div",{className:"ogx-pivot-zone",children:[r.jsxs("span",{className:"ogx-pivot-zone__label",children:[r.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--col"}),"Column Fields"]}),r.jsx("div",{className:`ogx-pivot-chips${e.columnFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — unique values become column headers",children:e.columnFields.map(_=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[P(_),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>w(_),title:`Remove ${P(_)}`,children:"×"})]},_))})]}),r.jsxs("div",{className:"ogx-pivot-zone",children:[r.jsxs("span",{className:"ogx-pivot-zone__label",children:[r.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--value"}),"Value Fields (aggregated)"]}),r.jsx("div",{className:`ogx-pivot-chips${e.valueFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add numeric fields here — values are aggregated",children:e.valueFields.map(_=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[P(_.field),r.jsx("select",{className:"ogx-pivot-chip__fn-select",value:_.aggFn,onChange:I=>g(_.field,I.target.value),title:"Aggregation function",children:Sr.map(I=>r.jsx("option",{value:I,children:I.toUpperCase()},I))}),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>k(_.field),title:`Remove ${P(_.field)}`,children:"×"})]},_.field))})]}),r.jsx("hr",{className:"ogx-pivot-panel__divider"}),r.jsxs("div",{children:[r.jsx("div",{className:"ogx-pivot-panel__fields-label",children:"Available Fields"}),r.jsxs("div",{className:"ogx-pivot-fields",children:[t.map(_=>{const I=f.has(_.field);return C(_.field)?null:r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[r.jsx("span",{className:`ogx-pivot-field-btn${I?" ogx-pivot-field-btn--numeric":""}`,children:_.headerName??_.field}),r.jsxs("div",{className:"ogx-pivot-field-actions",children:[r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>y(_.field),title:"Add to Row Fields",children:"Row"}),r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>E(_.field),title:"Add to Column Fields",children:"Col"}),I&&r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>N(_.field),title:"Add to Value Fields",children:"Val"})]})]},_.field)}),t.every(_=>C(_.field))&&r.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return ze.createPortal(M,u)}function Er(){return r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Nr(){return r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Mr({value:n="",onChange:t,placeholder:e="Search...",debounceMs:o=250}){const[i,s]=l.useState(()=>n.length>0),[d,a]=l.useState(n),u=l.useRef(null),c=l.useRef(null),p=l.useRef(t);l.useLayoutEffect(()=>{p.current=t},[t]);const m=l.useRef(n),h=l.useRef(n),b=l.useRef(!1);l.useLayoutEffect(()=>{b.current&&document.activeElement!==u.current&&u.current?.focus()}),l.useEffect(()=>{n!==h.current&&(h.current=n,n!==m.current&&(a(n),m.current=n,n?s(!0):(b.current=!1,s(!1))))},[n]),l.useEffect(()=>{const j=setTimeout(()=>{d!==m.current&&(m.current=d,p.current(d))},o);return()=>clearTimeout(j)},[d,o]);const C=l.useCallback(()=>{s(!0),requestAnimationFrame(()=>u.current?.focus())},[]),y=l.useCallback(j=>{j.stopPropagation(),a(""),m.current="",p.current(""),u.current?.focus()},[]),E=l.useCallback(()=>{b.current=!0,s(!0)},[]),N=l.useCallback(()=>{b.current=!1,setTimeout(()=>{if(c.current&&document.activeElement&&c.current.contains(document.activeElement)){b.current=!0;return}d||s(!1)},150)},[d]);return l.useEffect(()=>{const j=w=>{c.current&&!c.current.contains(w.target)&&(d||s(!1))};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[d]),r.jsxs("div",{ref:c,className:`ogx-global-search${i?" ogx-global-search--expanded":""}`,onClick:i?void 0:C,children:[r.jsx("div",{className:"ogx-global-search__icon-wrapper",children:r.jsx(Er,{})}),r.jsx("input",{ref:u,className:"ogx-global-search__input",value:d,onChange:j=>a(j.target.value),onFocus:E,onBlur:N,placeholder:e,"aria-label":"Global Search",autoComplete:"off"}),d&&r.jsx("button",{className:"ogx-global-search__clear",onClick:y,"aria-label":"Clear search",children:r.jsx(Nr,{})})]})}function gt({title:n,children:t,placement:e="top",enterDelay:o=200,leaveDelay:i=0}){const[s,d]=l.useState(!1),[a,u]=l.useState({top:0,left:0}),c=l.useRef(null),p=l.useRef(null),m=l.useCallback(()=>{if(!p.current)return;const y=p.current.getBoundingClientRect();let E=0,N=0;const j=window.pageXOffset||document.documentElement.scrollLeft,w=window.pageYOffset||document.documentElement.scrollTop;e==="top"?(E=y.top+w-8,N=y.left+j+y.width/2):e==="bottom"&&(E=y.bottom+w+8,N=y.left+j+y.width/2),u({top:E,left:N})},[e]);l.useLayoutEffect(()=>(s&&(m(),window.addEventListener("scroll",m,!0),window.addEventListener("resize",m)),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[s,m]);const h=()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d(!0)},o)},b=()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d(!1)},i)},C=l.useCallback(y=>{p.current=y?y.firstElementChild??y:null},[]);return r.jsxs(r.Fragment,{children:[r.jsx("span",{ref:C,style:{display:"inline-block",lineHeight:0},onMouseEnter:h,onMouseLeave:b,children:t}),s&&n&&ze.createPortal(r.jsx("div",{className:`ogx-tooltip ogx-tooltip--${e}`,style:{top:a.top,left:a.left,position:"absolute",zIndex:99999},children:n}),document.body)]})}const Pr=["none","sum","avg","count","min","max"];function Pn(){return r.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:r.jsx("path",{d:"M18 4H6l6 8-6 8h12"})})}function Ir(){return r.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",children:[r.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.25"}),r.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),r.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function In(){return r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function Tr({anchorRef:n,aggregationModel:t,aggregableColumns:e,onFunctionChange:o,onClearAll:i,onClose:s,activeCount:d}){const a=l.useRef(null),[u,c]=l.useState({top:0,right:0}),[p,m]=l.useState(document.body);l.useLayoutEffect(()=>{m(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const h=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const C=n.current.getBoundingClientRect();return{top:C.bottom+6,right:window.innerWidth-C.right}},[n]);l.useEffect(()=>{c(h());const C=()=>c(h());return window.addEventListener("scroll",C,!0),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C,!0),window.removeEventListener("resize",C)}},[h]),l.useEffect(()=>{function C(y){a.current&&!a.current.contains(y.target)&&n.current&&!n.current.contains(y.target)&&s()}return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[n,s]),l.useEffect(()=>{function C(y){y.key==="Escape"&&s()}return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[s]);const b=r.jsxs("div",{ref:a,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:u.top,right:u.right,width:400,maxWidth:"calc(100vw - 24px)"},children:[r.jsxs("div",{className:"ogx-toolbar__panel-header",children:[r.jsxs("span",{className:"ogx-toolbar__panel-title",children:[r.jsx(Pn,{}),"Summaries"]}),d>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:i,title:"Clear all summaries",children:"Clear all"})]}),r.jsx("div",{className:"ogx-toolbar__panel-body",children:e.length===0?r.jsxs("p",{className:"ogx-toolbar__empty",children:["No aggregable columns.",r.jsx("br",{}),"Set ",r.jsx("code",{children:"aggregable: true"})," on a column to enable."]}):e.map(C=>{const y=t[C.field]||"none";return r.jsxs("div",{className:"ogx-toolbar__agg-row",children:[r.jsx("span",{className:"ogx-toolbar__agg-label",title:C.field,children:C.headerName||C.field}),r.jsx("div",{className:"ogx-toolbar__agg-pills",children:Pr.map(E=>r.jsx("button",{className:`ogx-toolbar__pill${y===E?" ogx-toolbar__pill--active":""}`,onClick:()=>o(C.field,E),"aria-pressed":y===E,children:E},E))})]},C.field)})})]});return ze.createPortal(b,p)}function Lr({anchorRef:n,columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:i,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,onClose:u}){const c=l.useRef(null),[p,m]=l.useState({top:0,right:0}),[h,b]=l.useState(document.body);l.useLayoutEffect(()=>{b(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const C=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const E=n.current.getBoundingClientRect();return{top:E.bottom+6,right:window.innerWidth-E.right}},[n]);l.useEffect(()=>{m(C());const E=()=>m(C());return window.addEventListener("scroll",E,!0),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E)}},[C]),l.useEffect(()=>{function E(N){c.current&&!c.current.contains(N.target)&&n.current&&!n.current.contains(N.target)&&u()}return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[n,u]);const y=r.jsx("div",{ref:c,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:p.top,right:p.right,width:280,padding:0},children:r.jsx(jn,{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:i,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a})});return ze.createPortal(y,h)}function Rr({anchorRef:n,columns:t,filterModel:e,onFilterModelChange:o,onClose:i}){const s=l.useRef(null),[d,a]=l.useState({top:0,right:0}),u=l.useRef(i);l.useLayoutEffect(()=>{u.current=i},[i]);const[c,p]=l.useState(document.body);l.useLayoutEffect(()=>{p(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const m=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const y=n.current.getBoundingClientRect();return{top:y.bottom+6,right:window.innerWidth-y.right}},[n]);l.useEffect(()=>{a(m());const y=()=>a(m());return window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[m]),l.useEffect(()=>{function y(E){E.key==="Escape"&&u.current()}return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[]);const h=e.items?.length??0,b=()=>{o({...e,items:[],logicOperator:"and"})},C=r.jsxs("div",{ref:s,className:"ogx-toolbar__panel ogx-toolbar__panel--filter",role:"dialog","aria-label":"Advanced filters",style:{top:d.top,right:d.right,width:540,maxWidth:"calc(100vw - 24px)"},children:[r.jsxs("div",{className:"ogx-toolbar__panel-header",children:[r.jsxs("span",{className:"ogx-toolbar__panel-title",children:[r.jsx(In,{}),"Filters",h>0&&r.jsx("span",{className:"ogx-toolbar__panel-count",children:h})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[h>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:b,title:"Clear all filters",children:"Clear all"}),r.jsx("button",{className:"ogx-toolbar__close-btn",onClick:()=>u.current(),title:"Close filters","aria-label":"Close filters panel",children:"Close"})]})]}),r.jsx("div",{className:"ogx-toolbar__panel-body ogx-toolbar__panel-body--filter",children:r.jsx(Nn,{columns:t,filterModel:e,onFilterModelChange:o})})]});return ze.createPortal(C,c)}const Or={rowFields:[],columnFields:[],valueFields:[]};function Fr({columns:n=[],baseColumns:t,aggregationModel:e={},onAggregationModelChange:o,pivotModel:i,onPivotModelChange:s,filterModel:d,onFilterModelChange:a,columnVisibilityModel:u={},onColumnVisibilityModelChange:c,onColumnReorder:p,onColumnOrderReset:m,forceColumnsOpen:h,onColumnsPanelClose:b,children:C,rightContent:y,style:E,renderColumnsButton:N,renderFilterButton:j,renderAggregationButton:w,renderExportButton:k,renderQuickFilter:g,className:x}){const[f,S]=l.useState(!1),[P,M]=l.useState(!1),[_,I]=l.useState(!1),[L,F]=l.useState(!1);l.useEffect(()=>{h&&(I(!0),S(!1),M(!1),F(!1))},[h]);const A=l.useRef(null),V=l.useRef(null),T=l.useRef(null),B=l.useRef(null),K=l.useRef(null),H=l.useRef(null),v=l.useRef(null),R=i??Or,W=R.rowFields.length>0||R.columnFields.length>0||R.valueFields.length>0,$=n.filter(z=>z.aggregable!==!1&&(z.type==="number"||z.aggregable===!0)),G=Object.keys(e).filter(z=>e[z]&&e[z]!=="none").length,q=l.useCallback((z,ie)=>{if(!o)return;const se={...e};ie==="none"?delete se[z]:se[z]=ie,o(se)},[e,o]),Y=l.useCallback(()=>{o?.({})},[o]),te=l.useCallback(z=>{if(!a)return;const se={...d||{},quickFilterValues:z?[z]:[],items:d?.items||[]};a(se)},[d,a]),O=d?.quickFilterValues?.[0]||"",J=d?.items?.length||0,Q=new Set(n.filter(z=>u[z.field]!==!1).map(z=>z.field)),le=l.useCallback((z,ie)=>{if(!c)return;const se={...u,[z]:ie};c(se)},[u,c]),oe=l.useCallback(()=>{if(!c)return;const z={...u};n.forEach(ie=>{ie.hideable!==!1&&(z[ie.field]=!0)}),c(z)},[n,u,c]),pe=l.useCallback(()=>{if(!c)return;const z={...u};n.forEach(ie=>{ie.hideable!==!1&&(z[ie.field]=!1)}),c(z)},[n,u,c]);return r.jsxs("div",{className:["ogx-toolbar",x].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:E,children:[C&&r.jsx("div",{className:"ogx-toolbar__left",children:C}),r.jsx("div",{className:"ogx-toolbar__spacer"}),r.jsxs("div",{className:"ogx-toolbar__actions",children:[a&&r.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:g?g({value:O,onChange:te}):r.jsx(Mr,{value:O,onChange:te,placeholder:"Search..."})}),c&&r.jsxs("div",{ref:K,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[N?N({onClick:()=>{I(z=>!z),S(!1),M(!1),F(!1)},isOpen:_,activeCount:n.length-Q.size}):r.jsx(gt,{title:"Columns",children:r.jsx("button",{ref:T,className:`ogx-toolbar__icon-btn${_?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns",onClick:()=>{I(!_),S(!1),M(!1),F(!1)},children:r.jsx(Ir,{})})}),_&&r.jsx(Lr,{anchorRef:N?K:T,columns:n,visibleColumns:Q,onVisibilityChange:le,onShowAll:oe,onHideAll:pe,onColumnReorder:p,onColumnOrderReset:m,onClose:()=>{I(!1),b?.()}})]}),a&&r.jsxs("div",{ref:H,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[j?j({onClick:()=>{F(z=>!z),S(!1),M(!1),I(!1)},isOpen:L,activeCount:J}):r.jsx(gt,{title:"Filters",children:r.jsxs("button",{ref:B,className:`ogx-toolbar__icon-btn${L?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters",onClick:()=>{F(!L),S(!1),M(!1),I(!1)},children:[r.jsx(In,{}),J>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),L&&r.jsx(Rr,{anchorRef:j?H:B,columns:n,filterModel:d||{items:[]},onFilterModelChange:a,onClose:()=>F(!1)})]}),s&&r.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[r.jsx(gt,{title:"Pivot",children:r.jsxs("button",{ref:V,className:`ogx-toolbar__icon-btn${P?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-expanded":P,onClick:()=>{M(!P),S(!1),I(!1),F(!1)},children:[r.jsx(Mn,{}),W&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),P&&r.jsx(jr,{anchorRef:V,columns:t??n,model:R,onChange:z=>{s?.(z)},onClose:()=>M(!1)})]}),r.jsxs("div",{ref:v,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[w?w({onClick:()=>{S(z=>!z),M(!1),I(!1),F(!1)},isOpen:f,activeCount:G}):r.jsx(gt,{title:"Summaries",children:r.jsxs("button",{ref:A,className:`ogx-toolbar__icon-btn${f?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-expanded":f,onClick:()=>{S(!f),M(!1),I(!1),F(!1)},children:[r.jsx(Pn,{}),G>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${G} active summaries`})]})}),f&&r.jsx(Tr,{anchorRef:w?v:A,aggregationModel:e,aggregableColumns:$,onFunctionChange:q,onClearAll:Y,onClose:()=>S(!1),activeCount:G})]}),k&&k(),y]})]})}function Wr(){return l.useRef(null)}const Ar=({fullWidth:n=!1,error:t=!1,startAdornment:e,endAdornment:o,className:i="",...s})=>{const d=["ogx-input-wrapper",n&&"ogx-input-wrapper--full-width",t&&"ogx-input-wrapper--error",s.disabled&&"ogx-input-wrapper--disabled",i].filter(Boolean).join(" ");return r.jsxs("div",{className:d,children:[e&&r.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--start",children:e}),r.jsx("input",{className:"ogx-input",...s}),o&&r.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--end",children:o})]})};function Tn(n){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[79,70,229]}function zr(n){return n.filter(t=>!(t.exportable===!1||t.field==="__check__"||t.field==="__actions__"))}function Br(n,t){let e=n[t.field];return t.valueGetter&&(e=t.valueGetter({row:n,field:t.field,value:e})),t.valueFormatter&&e!==void 0&&e!==null&&(e=t.valueFormatter({value:e,row:n,field:t.field})),String(e??"")}function Ln(n){return(typeof n.width=="number"?n.width:void 0)??(n.flex??1)*100}function $r(n,t){const e=n.reduce((i,s)=>i+Ln(s),0),o={};return n.forEach((i,s)=>{o[s]={cellWidth:Ln(i)/e*t}}),o}function Dr(n,t){return!n.items||n.items.length===0?"":n.items.flatMap(e=>{if("items"in e)return[];const i=t.find(d=>d.field===e.field)?.headerName??e.field,s=e.value!==void 0&&e.value!==null?String(e.value):"";return[`${i} ${e.operator} "${s}"`]}).join(" • ")}async function Hr(n,t,e={}){let o,i;try{const[H,v]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);o=H.default,i=v.default}catch{throw new Error("exportToPdf requires 'jspdf' and 'jspdf-autotable'. Run: npm install jspdf jspdf-autotable")}const{fileName:s="export",title:d,logoUrl:a,orientation:u="landscape",selectedRows:c,aggregationResult:p,aggregationModel:m,filterModel:h,alternateRowColor:b=!0,headerBackgroundColor:C="#4f46e5",headerTextColor:y="#ffffff",fontSize:E=9}=e,N=new o({orientation:u,unit:"mm",format:"a4"}),j=N.internal.pageSize.getWidth(),w=N.internal.pageSize.getHeight(),k=14,g=j-k*2,x=zr(t),f=c&&c.length>0?n.filter(H=>c.includes(H.id)):n;let S=k;if(d){let H=k,v=k+8;if(a)try{N.addImage(a,"PNG",H,k,10,10),H+=14}catch{}N.setFontSize(16),N.setFont("helvetica","bold"),N.setTextColor(30,41,59),N.text(d,H,v),v+=6,N.setFontSize(8),N.setFont("helvetica","normal"),N.setTextColor(100,116,139);const R=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});if(N.text(`Exported: ${R} • ${f.length} row${f.length!==1?"s":""}`,H,v),v+=5,h){const W=Dr(h,t);W&&(N.text(`Filters: ${W}`,H,v),v+=5)}N.setDrawColor(226,232,240),N.setLineWidth(.3),N.line(k,v+2,j-k,v+2),S=v+6}const P=[x.map(H=>H.headerName??H.field)],M=f.map(H=>x.map(v=>Br(H,v)));let _;p&&m&&(_=[x.map((v,R)=>{if(R===0)return x.some(q=>m[q.field])?"TOTAL":"";const W=p[v.field];if(W==null)return"";let $=W;return v.valueFormatter?$=v.valueFormatter({value:W,row:{},field:v.field}):m[v.field]&&($=Ne(W,m[v.field])),String($)})]);const I=$r(x,g),[L,F,A]=Tn(C),[V,T,B]=Tn(y);i(N,{head:P,body:M,..._?{foot:_}:{},startY:S,styles:{fontSize:E,cellPadding:3,font:"helvetica",overflow:"linebreak"},headStyles:{fillColor:[L,F,A],textColor:[V,T,B],fontStyle:"bold"},...b?{alternateRowStyles:{fillColor:[248,250,252]}}:{},..._?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:I,showFoot:_?"lastPage":"never",showHead:"everyPage",margin:{top:k,left:k,right:k,bottom:k+6}});const K=N.getNumberOfPages();for(let H=1;H<=K;H++)N.setPage(H),N.setFontSize(8),N.setTextColor(150,150,150),N.text(`Page ${H} of ${K}`,j-k,w-8,{align:"right"});N.save(`${s}.pdf`)}function Gr(n,t,e={}){const{fileName:o="export.csv",includeHeaders:i=!0,delimiter:s=",",selectedRows:d}=e,a=d&&d.length>0?n.filter(p=>d.includes(p.id)):n;if(a.length===0){console.warn("No rows to export");return}const u=t.filter(p=>!(p.exportable===!1||p.field==="__check__"||p.field==="__actions__"));let c="";if(i){const p=u.map(m=>Ye(m.headerName||m.field));c+=p.join(s)+`
9
- `}if(a.forEach(p=>{const m=u.map(h=>{let b=p[h.field];return h.valueGetter&&(b=h.valueGetter({row:p,field:h.field,value:b})),h.valueFormatter&&b!==void 0&&b!==null&&(b=h.valueFormatter({value:b,row:p,field:h.field})),Ye(String(b??""))});c+=m.join(s)+`
10
- `}),e.aggregationResult){const p=e.aggregationResult,m=e.aggregationModel||{},h=u.map(C=>m[C.field]?Ye(m[C.field].toUpperCase()):Ye(""));c+=h.join(s)+`
11
- `;const b=u.map(C=>{const y=p[C.field];if(y!=null){let E=y;return C.valueFormatter?E=C.valueFormatter({value:y,row:{},field:C.field}):m[C.field]&&(E=Ne(y,m[C.field])),Ye(String(E))}return Ye("")});c+=b.join(s)+`
12
- `}Vt(c,o,"text/csv;charset=utf-8;")}function Ye(n){return n.includes(",")||n.includes('"')||n.includes(`
13
- `)?`"${n.replace(/"/g,'""')}"`:n}function Vr(n,t,e={}){const{fileName:o="export.xls",sheetName:i="Sheet1",includeHeaders:s=!0,selectedRows:d}=e,a=d&&d.length>0?n.filter(p=>d.includes(p.id)):n;if(a.length===0){console.warn("No rows to export");return}const u=t.filter(p=>!(p.exportable===!1||p.field==="__check__"||p.field==="__actions__"));let c='<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">';if(c+="<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>",c+=`<x:Name>${i}</x:Name>`,c+="<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->",c+='<meta charset="UTF-8"></head><body>',c+='<table border="1">',s&&(c+="<thead><tr>",u.forEach(p=>{c+=`<th>${Me(p.headerName||p.field)}</th>`}),c+="</tr></thead>"),c+="<tbody>",a.forEach(p=>{c+="<tr>",u.forEach(m=>{let h=p[m.field];m.valueGetter&&(h=m.valueGetter({row:p,field:m.field,value:h})),m.valueFormatter&&h!==void 0&&h!==null&&(h=m.valueFormatter({value:h,row:p,field:m.field})),c+=`<td>${Me(String(h??""))}</td>`})}),e.aggregationResult){const p=e.aggregationResult,m=e.aggregationModel||{};c+='<tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',u.forEach(h=>{m[h.field]?c+=`<td style="text-align: right; font-weight: bold;">${Me(m[h.field].toUpperCase())}</td>`:c+="<td></td>"}),c+="</tr>",c+='<tr style="font-weight: bold; background-color: #f5f5f5;">',u.forEach(h=>{const b=p[h.field];if(b!=null){let C=b;h.valueFormatter?C=h.valueFormatter({value:b,row:{},field:h.field}):m[h.field]&&(C=Ne(b,m[h.field])),c+=`<td style="text-align: right;">${Me(String(C))}</td>`}else c+="<td></td>"}),c+="</tr>"}c+="</tbody></table></body></html>",Vt(c,o,"application/vnd.ms-excel")}function Me(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function Ur(n,t,e={}){const{fileName:o="export.json",pretty:i=!0,selectedRows:s}=e,d=s&&s.length>0?n.filter(m=>s.includes(m.id)):n;if(d.length===0){console.warn("No rows to export");return}const a=t.filter(m=>!(m.exportable===!1||m.field==="__check__"||m.field==="__actions__")),u=d.map(m=>{const h={};return a.forEach(b=>{let C=m[b.field];b.valueGetter&&(C=b.valueGetter({row:m,field:b.field,value:C})),h[b.field]=C}),h});let c=u;if(e.aggregationResult){const m=e.aggregationResult,h=e.aggregationModel||{},b={};a.forEach(y=>{h[y.field]&&(b[y.field]=h[y.field].toUpperCase())});const C={};a.forEach(y=>{if(m[y.field]!==void 0&&m[y.field]!==null){let E=m[y.field];y.valueFormatter?E=y.valueFormatter({value:E,row:{},field:y.field}):h[y.field]&&(E=Ne(E,h[y.field])),C[y.field]=E}}),c={data:u,aggregation:{labels:b,values:C}}}const p=i?JSON.stringify(c,null,2):JSON.stringify(c);Vt(p,o,"application/json;charset=utf-8;")}async function Kr(n,t,e){const o=window.open("","_blank");if(!o){console.error("Failed to open print window. Please check your popup blocker settings.");return}o.document.write(`
6
+ <%s key={someKey} {...props} />`,R,G,ne,G),K[G+R]=!0)}if(G=null,W!==void 0&&(e(W),G=""+W),d(P)&&(e(P.key),G=""+P.key),"key"in P){W={};for(var A in P)A!=="key"&&(W[A]=P[A])}else W=P;return G&&a(W,typeof C=="function"?C.displayName||C.name||"Unknown":C),c(C,G,W,i(),z,U)}function w(C){m(C)?C._store&&(C._store.validated=1):typeof C=="object"&&C!==null&&C.$$typeof===M&&(C._payload.status==="fulfilled"?m(C._payload.value)&&C._payload.value._store&&(C._payload.value._store.validated=1):C._store&&(C._store.validated=1))}function m(C){return typeof C=="object"&&C!==null&&C.$$typeof===x}var u=l,x=Symbol.for("react.transitional.element"),g=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),N=Symbol.for("react.strict_mode"),y=Symbol.for("react.profiler"),v=Symbol.for("react.consumer"),j=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),E=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),I=Symbol.for("react.activity"),_=Symbol.for("react.client.reference"),T=u.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L=Object.prototype.hasOwnProperty,$=Array.isArray,O=console.createTask?console.createTask:function(){return null};u={react_stack_bottom_frame:function(C){return C()}};var H,F={},D=u.react_stack_bottom_frame.bind(u,s)(),q=O(o(s)),K={};ct.Fragment=k,ct.jsx=function(C,P,W){var R=1e4>T.recentlyCreatedOwnerStacks++;return f(C,P,W,!1,R?Error("react-stack-top-frame"):D,R?O(o(C)):q)},ct.jsxs=function(C,P,W){var R=1e4>T.recentlyCreatedOwnerStacks++;return f(C,P,W,!0,R?Error("react-stack-top-frame"):D,R?O(o(C)):q)}})()),ct}var mn;function no(){return mn||(mn=1,process.env.NODE_ENV==="production"?Et.exports=eo():Et.exports=to()),Et.exports}var r=no();function ut(n,t){return t?t.left?.includes(n)?"left":t.right?.includes(n)?"right":null:null}function oo(n,t){const e=[],o=[],i=[];return t?(n.forEach(s=>{const d=ut(s.field,t);d==="left"?e.push(s):d==="right"?i.push(s):o.push(s)}),t.left&&e.sort((s,d)=>{const a=t.left.indexOf(s.field),p=t.left.indexOf(d.field);return a-p}),t.right&&i.sort((s,d)=>{const a=t.right.indexOf(s.field),p=t.right.indexOf(d.field);return a-p}),{left:e,center:o,right:i}):{left:e,center:n,right:i}}function Ht(n,t,e,o,i,s,d,a){const p={};if(!e)return p;const c=oo(n,e);let f=0;a&&(f+=48),s&&d&&(f+=48),o&&i&&(f+=48),c.left.forEach(m=>{p[m.field]=f;const u=t[m.field]??m.width??100;f+=u});let w=0;return[...c.right].reverse().forEach(m=>{const u=t[m.field]??m.width??100;p[m.field]=w,w+=u}),p}function Gt(n,t){return t?t.top?.includes(n)?"top":t.bottom?.includes(n)?"bottom":null:null}function ro(n,t){const e=[],o=[],i=[];return t?(n.forEach(s=>{const d=Gt(s.id,t);d==="top"?e.push(s):d==="bottom"?i.push(s):o.push(s)}),t.top&&e.sort((s,d)=>{const a=t.top.indexOf(s.id),p=t.top.indexOf(d.id);return a-p}),t.bottom&&i.sort((s,d)=>{const a=t.bottom.indexOf(s.id),p=t.bottom.indexOf(d.id);return a-p}),{top:e,center:o,bottom:i}):{top:e,center:n,bottom:i}}function Ke(n){if(n===void 0)return{type:"auto",value:0};if(typeof n=="number")return{type:"fixed",value:n};if(typeof n=="string"){if(n.toLowerCase()==="auto")return{type:"auto",value:0};if(n.endsWith("%"))return{type:"percentage",value:parseFloat(n)};const t=parseFloat(n);if(!isNaN(t))return{type:"fixed",value:t}}return{type:"fixed",value:100}}function io(n){const{rowHeight:t,pagination:e,paginatedUnpinnedRows:o,sortedUnpinnedRows:i,expandedRowIds:s,getDetailPanelHeight:d,pinnedTopRowsLength:a,pinnedBottomRowsLength:p,visibleOrderedColumns:c,pinnedColumns:f,columnWidths:w,viewportWidth:m,checkboxSelection:u,hasDetailPanel:x,rowReordering:g,paginationMode:k,isLoading:N,pageSize:y}=n;return l.useMemo(()=>{const v=e?o:i,j=v.map((B,X)=>{let te=t;if(s.has(B.id)){const ce=d?.({row:B,id:B.id,rowIndex:a+X})??200;te+=typeof ce=="number"?ce:parseInt(String(ce),10)||200}return te}),b=j.reduce((B,X,te)=>(B.push((B[te-1]||0)+X),B),[]),S=k==="infinite"&&N&&v.length>0?Math.min(y,20):0,h=(b[b.length-1]||0)+S*t,E=a*t,M=p*t,I=[],_=[],T=[],L=[];c.forEach(B=>{const X=ut(B.field,f);X==="left"?I.push(B):X==="right"?_.push(B):T.push(B)});const $=(u?48:0)+(x?48:0)+(g?48:0),O=B=>w[B.field]??B.width,H=I.reduce((B,X)=>{const te=Ke(O(X));return B+(te.type==="fixed"?te.value:100)},0),F=_.reduce((B,X)=>{const te=Ke(O(X));return B+(te.type==="fixed"?te.value:100)},0),D=T.reduce((B,X)=>{if(!Object.prototype.hasOwnProperty.call(w,X.field)&&X.flex&&X.flex>0){const ge=X.minWidth??150,Pe=typeof X.width=="number"?X.width:150;return B+(ge||Pe)}const ce=Ke(O(X));return ce.type==="fixed"?B+ce.value:ce.type==="percentage"?B+100:B+(X.minWidth??150)},0),q=Math.max(m-$-H-F,D),K=[],C=[],P=[];T.forEach(B=>{const X=Object.prototype.hasOwnProperty.call(w,B.field),te=Ke(O(B));if(!X&&B.flex&&B.flex>0){P.push({col:B,flex:B.flex});return}te.type==="fixed"?K.push({col:B,width:te.value}):te.type==="percentage"?C.push({col:B,percentage:te.value}):P.push({col:B,flex:1})});const W=K.reduce((B,{width:X})=>B+X,0);let R=Math.max(0,q-W);const z=new Map;C.forEach(({col:B,percentage:X})=>{const te=X/100*R;z.set(B.field,te),R-=te}),R=Math.max(0,R);const U=new Map,G=P.map(B=>({...B,minWidth:B.col.minWidth??50,maxWidth:B.col.maxWidth??1/0,frozen:!1,computedWidth:0}));(()=>{let B=0;const X=G.length*2;for(;B<X;){B++;const te=G.filter(oe=>!oe.frozen);if(te.length===0)break;const ce=te.reduce((oe,ye)=>oe+ye.flex,0),ge=G.reduce((oe,ye)=>ye.frozen?oe+ye.computedWidth:oe,0),Pe=Math.max(0,R-ge);if(ce<=0){te.forEach(oe=>{oe.computedWidth=oe.minWidth,oe.frozen=!0});break}const $e=Pe/ce;let Ie=0;const pe=[],Je=[];if(te.forEach(oe=>{const ye=$e*oe.flex;ye<oe.minWidth?(Ie+=oe.minWidth-ye,pe.push(oe)):ye>oe.maxWidth?(Ie+=oe.maxWidth-ye,Je.push(oe)):oe.computedWidth=ye}),pe.length===0&&Je.length===0){te.forEach(oe=>oe.frozen=!0);break}Ie>0?pe.forEach(oe=>{oe.computedWidth=oe.minWidth,oe.frozen=!0}):Ie<0?Je.forEach(oe=>{oe.computedWidth=oe.maxWidth,oe.frozen=!0}):(pe.forEach(oe=>{oe.computedWidth=oe.minWidth,oe.frozen=!0}),Je.forEach(oe=>{oe.computedWidth=oe.maxWidth,oe.frozen=!0}))}})(),G.forEach(B=>U.set(B.col.field,B.computedWidth));const A=new Map;T.forEach(B=>{let X;if(U.has(B.field))X=U.get(B.field);else{const te=K.find(ge=>ge.col.field===B.field),ce=C.find(ge=>ge.col.field===B.field);if(te)X=te.width;else if(ce){const ge=z.get(B.field)||0;X=Math.max(B.minWidth??50,ge||100)}else X=100}L.push(X),A.set(B.field,X)});const J=T.map(B=>{const X=G.find(te=>te.col.field===B.field);return{...B,width:A.get(B.field)??(typeof B.width=="number"?B.width:100),flex:X?X.flex:B.flex}}),ee=11,se=I.map((B,X)=>{const te=Ke(O(B));return{...B,width:te.type==="fixed"?te.value:100,zIndex:ee+X}}),re=11,ve=_.map((B,X)=>{const te=Ke(O(B));return{...B,width:te.type==="fixed"?te.value:100,zIndex:re+(_.length-1-X)}}),Y=L.reduce((B,X)=>B+X,0),Q=H+Y+F+$,le=L.reduce((B,X,te)=>(B.push((B[te-1]||0)+X),B),[]);return{rowHeights:j,cumulativeHeights:b,unpinnedRowsHeight:h,pinnedTopHeight:E,pinnedBottomHeight:M,leftPinnedCols:se,rightPinnedCols:ve,unpinnedColsWithWidth:J,unpinnedColWidths:L,unpinnedAccWidths:le,totalWidth:Q,leftWidth:H,rightWidth:F,unpinnedTotalWidth:Y,systemColumnsWidth:$,pinnedTopRowsLength:a,pinnedBottomRowsLength:p,unpinnedRowsLength:v.length}},[t,e,o,i,s,d,a,p,c,f,w,m,u,x,g,k,N,y])}function lo(n){const{allRenderableRows:t,navigationColumns:e,checkboxSelection:o,selectedRowIds:i,handleSelectionChange:s,handleDetailPanelToggle:d,editingHandlers:a,setKeyboardMode:p,sortModel:c,handleSort:f,isCellEditable:w,pagination:m,pageSize:u,virtualization:x,viewportRef:g}=n,[k,N]=l.useState(null),y=l.useCallback(b=>{b.target===b.currentTarget&&N(S=>{if(S)return S;if(o)return{id:"HEADER",field:"__checkbox_col__"};const h=t[0],E=e[0];return h&&E?{id:h.id,field:E.field}:null})},[t,e,o]),v=l.useCallback(b=>{b.currentTarget.contains(b.relatedTarget)||N(null)},[]),j=l.useCallback(b=>{if(p(!0),!k)return;const{id:S,field:h}=k,E=!!a.editingCell;if(S==="HEADER"&&(b.key==="Enter"||b.key===" ")){b.preventDefault();const F=e.find(D=>D.field===h);if(F&&F.sortable!==!1){const D=c.find(K=>K.field===h);let q="asc";D&&(q=D.sort==="asc"?"desc":null),f(h,q)}return}if(b.key==="Enter"){if(b.preventDefault(),E)a.stopCellEdit();else if(e.find(D=>D.field===h)?.editable){const D=t.find(q=>q.id===S);D&&a.startCellEdit({id:S,field:h,value:D[h]})}return}if((b.key===" "||b.key==="Spacebar")&&!E){if(h==="__checkbox_col__"){b.preventDefault(),s(S,!i.has(S));return}if(h==="__expand_col__"){b.preventDefault(),d(S);return}}if(b.key==="Escape"){E&&(b.preventDefault(),a.stopCellEdit({cancel:!0}));return}if(E&&b.key!=="Tab")return;const M=S==="HEADER",I=M?-1:t.findIndex(F=>F.id===S),_=e.findIndex(F=>F.field===h);if(!M&&I===-1||_===-1)return;const T=(F,D,q,K,C,P=!1)=>{let W=F+q,R=D+K;return C&&K!==0&&(K>0&&R>=e.length?(R=0,W++):K<0&&R<0&&(R=e.length-1,W--)),!C&&(R<0||R>=e.length)||W<(P?-1:0)||W>=t.length?null:{r:W,c:R}},L=(F,D,q,K,C,P=!1)=>{let W=F,R=D,z=0;const U=t.length*e.length+e.length;for(;z<U;){if(z++,W+=q,R+=K,K!==0)K>0?R>=e.length&&(R=0,W++):R<0&&(R=e.length-1,W--);else if(R<0||R>=e.length)return null;if(W<-1||W>=t.length)return null;if(W===-1){if(!P)continue;const ee=e[R],se=ee.sortable!==!1;if(["__checkbox_col__"].includes(ee.field)||se)return{r:W,c:R};continue}const G=t[W],ne=e[R],A=["__checkbox_col__","__expand_col__","__reorder_col__"].includes(ne.field);let J=ne.editable||A;if(w&&!A)try{J=w({row:G,field:ne.field,value:G[ne.field],colDef:ne,rowIndex:W,colIndex:R})}catch{}if(J)return{r:W,c:R}}return null};let $=I,O=_,H=!1;if(b.key==="Tab"){const F=b.shiftKey?-1:1,D=L(I,_,0,F,!0,!1);D&&($=D.r,O=D.c,H=!0)}else if(b.key==="ArrowRight"){const F=T(I,_,0,1,!0,!0);F&&($=F.r,O=F.c,H=!0)}else if(b.key==="ArrowLeft"){const F=T(I,_,0,-1,!0,!0);F&&($=F.r,O=F.c,H=!0)}else if(b.key==="ArrowDown"){const F=T(I,_,1,0,!1,!0);F&&($=F.r,O=F.c,H=!0)}else if(b.key==="ArrowUp"){const F=T(I,_,-1,0,!1,!0);F&&($=F.r,O=F.c,H=!0)}else if(b.key==="Home")O=0,(b.ctrlKey||b.metaKey)&&($=-1),H=!0;else if(b.key==="End")O=e.length-1,(b.ctrlKey||b.metaKey)&&($=t.length-1),H=!0;else if(b.key==="PageUp")$=Math.max(-1,$-(m?u:10)),H=!0;else if(b.key==="PageDown"){const F=m?u:10;$=Math.min(t.length-1,$+F),H=!0}if(H&&(b.preventDefault(),E&&b.key==="Tab"&&a.stopCellEdit(),$>=-1&&$<t.length&&O>=0&&O<e.length)){const F=e[O];N($===-1?{id:"HEADER",field:F.field}:{id:t[$].id,field:F.field});const D=g.current;if(D){const{cumulativeHeights:q,pinnedTopHeight:K,columnMetrics:C}=x,{clientHeight:P,clientWidth:W,scrollTop:R,scrollLeft:z}=D,U=$<=0?0:q[$-1],G=q[$],ne=R+K,A=R+P;let J=R;if(U<ne?J=Math.max(0,U-K):G>A&&(J=G-P),J!==R&&(D.scrollTop=J),C){const{leftPinnedWidth:ee,rightPinnedWidth:se,unpinnedAccWidths:re,unpinnedCols:ve,totalSpecialsWidth:Y,pinnedSpecialsWidth:Q}=C,le=ve.findIndex(B=>B.field===F.field);if(le!==-1){const B=Y+ee+(le>0?re[le-1]:0),X=Y+ee+re[le],te=z+Q+ee,ce=z+W-se;let ge=z;B<te?ge=Math.max(0,B-Q-ee):X>ce&&(ge=X-W+se),ge!==z&&(D.scrollLeft=ge)}}}}},[k,t,e,a,x,i,s,d,p,c,f,w,m,u,g]);return{focusedCell:k,setFocusedCell:N,handleFocus:y,handleBlur:v,handleKeyDown:j}}const so={rowFields:[],columnFields:[],valueFields:[]};function ao(n){const{initialState:t,sortModel:e,aggregationModel:o,onAggregationModelChange:i,columnVisibilityModel:s,onColumnVisibilityModelChange:d,pinnedColumns:a,onPinnedColumnsChange:p,pivotModel:c,onPivotModelChange:f,paginationModel:w={page:0,pageSize:100},onPaginationModelChange:m,rowSelectionModel:u}=n,[x,g]=l.useState(()=>t?.sorting?.sortModel??[]),k=e!==void 0,N=k?e:x,y=o!==void 0,[v,j]=l.useState(()=>o??{}),b=y?o:v,S=l.useCallback(ee=>{y||j(ee),i?.(ee)},[y,i]),h=s!==void 0,[E,M]=l.useState(()=>t?.columns?.columnVisibilityModel??{}),I=h?s:E,_=l.useCallback(ee=>{h||M(ee),d?.(ee)},[h,d]),T=a!==void 0,[L,$]=l.useState(()=>t?.columns?.pinnedColumns??{}),O=T?a:L,H=l.useCallback(ee=>{T||$(ee),p?.(ee)},[T,p]),[F,D]=l.useState(()=>c??so),q=c??F,K=l.useCallback(ee=>{D(ee),f?.(ee)},[f]),C=w!==void 0&&n.paginationModel!==void 0,[P,W]=l.useState(()=>t?.pagination?.paginationModel??w),R=C?w:P,z=l.useCallback(ee=>{C||W(ee),m?.(ee)},[C,m]),U=u!==void 0,[G,ne]=l.useState([]),A=U?u:G,J=l.useMemo(()=>new Set(A),[A]);return{sortModel:N,isSortControlled:k,setInternalSortModel:g,aggregationModel:b,handleAggregationModelChange:S,columnVisibilityModel:I,handleColumnVisibilityModelChange:_,pinnedColumns:O,handlePinnedColumnsChange:H,currentPivotModel:q,handlePivotModelChange:K,effectivePaginationModel:R,handlePaginationModelChange:z,rowSelectionModel:A,selectedRowIds:J,isSelectionControlled:U,setInternalRowSelectionModel:ne}}const co={contains:(n,t)=>n==null||t==null?!1:String(n).toLowerCase().includes(String(t).toLowerCase()),equals:(n,t)=>n==null&&t==null?!0:n==null||t==null?!1:String(n).toLowerCase()===String(t).toLowerCase(),startsWith:(n,t)=>n==null||t==null?!1:String(n).toLowerCase().startsWith(String(t).toLowerCase()),endsWith:(n,t)=>n==null||t==null?!1:String(n).toLowerCase().endsWith(String(t).toLowerCase()),isEmpty:n=>n==null||String(n).trim()==="",isNotEmpty:n=>n!=null&&String(n).trim()!=="",">":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e>o},">=":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e>=o},"<":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e<o},"<=":(n,t)=>{if(n==null||t==null)return!1;const e=Number(n),o=Number(t);return isNaN(e)||isNaN(o)?!1:e<=o},"!=":(n,t)=>{if(t==null||t==="")return!0;const e=Number(n),o=Number(t);return!isNaN(e)&&!isNaN(o)?e!==o:String(n).toLowerCase()!==String(t).toLowerCase()},isAnyOf:(n,t)=>n==null||!Array.isArray(t)?!1:t.some(e=>String(n).toLowerCase()===String(e).toLowerCase()),not:(n,t)=>n==null&&t==null?!1:n==null||t==null?!0:String(n).toLowerCase()!==String(t).toLowerCase(),is:(n,t)=>{if(t==null||t==="")return!0;const e=String(n).toLowerCase(),o=String(t).toLowerCase();return e===o},"=":(n,t)=>n==null||t==null||t===""?!1:Number(n)===Number(t)};function uo(n,t){const{field:e,operator:o,value:i}=t,s=n[e],d=co[o];return d?d(s,i):(console.warn(`Unknown filter operator: ${o}`),!0)}function fo(n,t){return!t||t.length===0?!0:t.every(e=>{const o=e.toLowerCase();return Object.values(n).some(i=>i==null?!1:String(i).toLowerCase().includes(o))})}function Vt(n,t){const e=t.items??[],o=t.logicOperator??"and",i=("quickFilterValues"in t?t.quickFilterValues:void 0)??[];if(i.length>0&&!fo(n,i))return!1;if(e.length===0)return!0;const s=d=>{if("logicOperator"in d&&"items"in d){const a=d,p=a.items;return p.length===0?!0:a.logicOperator==="and"?p.every(s):p.some(s)}else return uo(n,d)};return o==="and"?e.every(s):e.some(s)}function go(n,t){if(!t)return n;const{items:e=[],quickFilterValues:o=[]}=t;return e.length===0&&(!o||o.length===0)?n:n.filter(i=>Vt(i,t))}function ho(n){switch(n){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 Ut(n,t,e){if(n==null&&t==null)return 0;if(n==null)return e==="asc"?1:-1;if(t==null)return e==="asc"?-1:1;if(typeof n=="number"&&typeof t=="number")return e==="asc"?n-t:t-n;if(n instanceof Date&&t instanceof Date)return e==="asc"?n.getTime()-t.getTime():t.getTime()-n.getTime();const o=String(n).toLowerCase(),i=String(t).toLowerCase();return e==="asc"?o<i?-1:o>i?1:0:o>i?-1:o<i?1:0}function po(n,t){if(t.length===0)return n;const e=[...n];return e.sort((o,i)=>{for(const s of t){const d=o[s.field],a=i[s.field],p=Ut(d,a,s.sort);if(p!==0)return p}return 0}),e}function xo(n){const{effectiveRows:t,activeHierarchyHandlers:e,filterMode:o,filterModel:i,dataSource:s,sortModel:d,sortingMode:a,pagination:p,paginationMode:c,effectivePaginationModel:f,pinnedRows:w,isLoading:m,pageSize:u}=n,x=l.useMemo(()=>e?e.getVisibleRows()||[]:o==="server"&&s?t:go(t,i),[t,i,e,o,s]),{top:g,center:k,bottom:N}=l.useMemo(()=>e?{top:[],center:x,bottom:[]}:ro(x,w),[x,w,e]),y=l.useMemo(()=>e||a==="server"&&s?k:po(k,d),[k,d,e,a,s]),v=l.useMemo(()=>{if(!p||c==="server"&&s)return y;const b=f.page*f.pageSize;return y.slice(b,b+f.pageSize)},[y,p,f.page,f.pageSize,c,s]),j=l.useMemo(()=>{if(e)return k;const b=p?v:y,S=[...g,...b,...N];if(c==="infinite"&&m&&S.length>0){const h=Math.min(u,20),E=Array.from({length:h},(M,I)=>({id:`__skeleton_${I}__`,_isSkeleton:!0}));return[...S,...E]}return S},[g,v,y,N,p,e,k,c,m,u]);return{filteredRows:x,pinnedTopRows:g,unpinnedRows:k,pinnedBottomRows:N,sortedUnpinnedRows:y,paginatedUnpinnedRows:v,allRenderableRows:j}}function mo(n){const{layout:t,scrollTop:e,scrollLeft:o,viewportWidth:i,viewportHeight:s,autoHeight:d,rowReordering:a,hasDetailPanel:p,checkboxSelection:c,pinCheckboxColumn:f,pinExpandColumn:w}=n;return l.useMemo(()=>{const{unpinnedAccWidths:m,unpinnedColsWithWidth:u,leftPinnedCols:x,rightPinnedCols:g,totalWidth:k,leftWidth:N,rightWidth:y,unpinnedTotalWidth:v,systemColumnsWidth:j,cumulativeHeights:b,pinnedTopHeight:S,pinnedBottomHeight:h,unpinnedRowsHeight:E,rowHeights:M,unpinnedRowsLength:I}=t,_=i||1e3,T=d?S+E+h+50:s||600,L=6,$=Math.max(0,o-N),O=o+_-N;let H=0,F=u.length-1,D=0,q=m.length-1;for(;D<=q;){const re=D+q>>>1;m[re]<$?D=re+1:q=re-1}H=Math.max(0,D-L);for(let re=H;re<m.length;re++){if((re===0?0:m[re-1])>O){F=Math.min(u.length-1,re+L);break}F=Math.min(u.length-1,re+L)}const K=H>0?m[H-1]:0,C=v-m[F],P=[...x,...K>0?[{field:"__spacer_left__",width:K,isSpacer:!0}]:[],...u.slice(H,F+1),...C>0?[{field:"__spacer_right__",width:C,isSpacer:!0}]:[],...g],R=_>0&&k>_?16:0,z=S+E+h+R+2,U=5;let G=0,ne=I-1,A=0,J=0,ee=b.length-1;for(;J<=ee;){const re=J+ee>>>1;b[re]<e?J=re+1:ee=re-1}G=Math.max(0,J-U),A=G>0?b[G-1]:0;for(let re=G;re<b.length;re++)if(b[re]>=e+T){ne=Math.min(I-1,re+U);break}const se=(a?48:0)+(p&&w?48:0)+(c&&f?48:0);return{renderContext:{firstRowIndex:G,lastRowIndex:ne,firstColumnIndex:H,lastColumnIndex:F},offsetTop:A,offsetLeft:0,totalHeight:z,pinnedTopHeight:S,pinnedBottomHeight:h,totalWidth:k,rowHeights:M,cumulativeHeights:b,virtualColumns:P,columnMetrics:{leftPinnedWidth:N,rightPinnedWidth:y,unpinnedAccWidths:m,unpinnedCols:u,totalSpecialsWidth:j,pinnedSpecialsWidth:se}}},[t,e,o,i,s,d,a,p,c,f,w])}function bo(n){const{columns:t,onColumnOrderChange:e,disableColumnReorder:o=!1}=n,[i,s]=l.useState(null),[d,a]=l.useState(null),p=l.useRef(-1),c=l.useCallback(u=>x=>{if(o)return;const g=t.findIndex(N=>N.field===u);if(t[g]?.pinnable===!1){x.preventDefault();return}s(u),p.current=g,x.dataTransfer&&(x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/plain",u))},[t,o]),f=l.useCallback(u=>x=>{o||!i||(x.preventDefault(),x.dataTransfer.dropEffect="move",a(u))},[i,o]),w=l.useCallback(u=>x=>{if(x.preventDefault(),o||!i||i===u){s(null),a(null);return}const g=t.findIndex(y=>y.field===i),k=t.findIndex(y=>y.field===u);if(g===-1||k===-1){s(null),a(null);return}const N=t[g];e&&e({column:N,oldIndex:g,targetIndex:k}),s(null),a(null),p.current=-1},[t,i,o,e]),m=l.useCallback(()=>{s(null),a(null),p.current=-1},[]);return{draggedColumn:i,dragOverColumn:d,onDragStart:o?void 0:c,onDragOver:o?void 0:f,onDragEnd:o?void 0:m,onDrop:o?void 0:w}}function bn({isExpanded:n,onClick:t,variant:e="chevron"}){return r.jsx("button",{className:`ogx-expand-icon ${n?"ogx-expand-icon--expanded":""}`,onClick:o=>{t&&t(o)},"aria-label":n?"Collapse row":"Expand row",type:"button",children:e==="plus-minus"?r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[r.jsx("path",{d:"M4 8H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),r.jsx("path",{d:"M8 4V12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:n?0:1,transition:"opacity 0.2s ease",transformOrigin:"center"}})]}):r.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{transform:n?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease"},children:r.jsx("path",{d:"M6 4L10 8L6 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function wo(n){const{activeColumns:t,isHierarchyEnabled:e,isRowGrouping:o,isTreeData:i,activeHierarchyHandlers:s,columnVisibilityModel:d,columnOrder:a,onColumnOrderChange:p,disableColumnReorder:c,pivotMode:f,checkboxSelection:w,hasDetailPanel:m,rowReordering:u,initialState:x,setColumns:g}=n,k=l.useMemo(()=>e?t.map((_,T)=>T===0?{..._,renderCell:L=>{const $=L.rowMeta,O=$?.treeDepth??0,H=!!$?.hasChildren,F=!!$?.isExpanded,D=$?.groupingField,q=$?.groupingValue,K=$?.descendantCount,C=!!$?.isGroupRow;let P=_.renderCell?_.renderCell(L):L.value;return i&&H&&C&&(P=r.jsxs("div",{className:"ogx__group-cell-content",children:[L.value,K!==void 0&&K>0?` (${K})`:""]})),o&&H&&D&&(P=r.jsxs("div",{className:"ogx__group-cell-content",children:[_.field===D?"":`${D}: `,String(q),K!==void 0?` (${K})`:""]})),r.jsxs("div",{style:{display:"flex",alignItems:"center",paddingLeft:O*24,width:"100%",height:"100%"},children:[r.jsx("div",{style:{marginRight:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:H?"pointer":"default",flexShrink:0},children:H?r.jsx("div",{onClick:W=>{W.stopPropagation(),W.preventDefault(),s?.toggleExpansion(L.row.id)},onMouseDown:W=>{W.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:r.jsx(bn,{isExpanded:F,onClick:W=>{W.stopPropagation(),W.preventDefault(),s?.toggleExpansion(L.row.id)}})}):null}),r.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:P})]})}}:{..._,renderCell:L=>{const $=L.rowMeta,O=!!$?.hasChildren,H=$?.groupingField;return o&&O?_.field===H?null:L.value!==void 0&&L.value!==null?_.renderCell?_.renderCell(L):L.value:null:_.renderCell?_.renderCell(L):L.value}}):t,[t,e,o,i,s]),[N,y]=l.useState(()=>x?.columns?.columnWidths??{}),v=l.useCallback((_,T)=>{y(L=>({...L,[_]:T}))},[]),[j,b]=l.useState(()=>x?.columns?.columnOrder??t.map(_=>_.field)),S=a??j;l.useEffect(()=>{g(t)},[t,g]),l.useEffect(()=>{f&&b(t.map(_=>_.field))},[f,t]);const h=l.useMemo(()=>{if(c)return k;const _=new Map(S.map((T,L)=>[T,L]));return[...k].sort((T,L)=>{const $=_.get(T.field)??k.indexOf(T),O=_.get(L.field)??k.indexOf(L);return $-O})},[k,S,c]),E=l.useMemo(()=>h.filter(_=>d[_.field]!==!1),[h,d]),M=bo({columns:h,onColumnOrderChange:l.useCallback(_=>{const{oldIndex:T,targetIndex:L}=_,$=[...S],[O]=$.splice(T,1);$.splice(L,0,O),a||b($),p?.(_)},[S,a,p]),disableColumnReorder:c}),I=l.useMemo(()=>{const _=[];return u&&_.push({field:"__reorder_col__"}),m&&_.push({field:"__expand_col__"}),w&&_.push({field:"__checkbox_col__"}),[..._,...h]},[h,w,m,u]);return{effectiveColumns:k,orderedColumns:h,visibleOrderedColumns:E,navigationColumns:I,columnWidths:N,effectiveColumnOrder:S,setInternalColumnOrder:b,columnReorderHandlers:M,handleColumnResize:v}}function vo(n){const{renderContext:t,pinnedTopRows:e,pinnedBottomRows:o,paginatedUnpinnedRows:i,sortedUnpinnedRows:s,pagination:d}=n;return l.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:p}=t,c=d?i:s,f=e.length,w=e.map((y,v)=>({row:y,rowIndex:v})),m=o.map((y,v)=>({row:y,rowIndex:f+c.length+v})),u=Math.max(0,a-f),x=Math.min(c.length,p-f+1),g=c.slice(u,x).map((y,v)=>({row:y,rowIndex:f+u+v})),k=[...w,...g,...m],N=new Set;return k.filter(y=>N.has(y.row.id)?!1:(N.add(y.row.id),!0))},[t,e,o,i,s,d])}function _o(n){const{onRowsScrollEnd:t}=n,e=l.useRef({scrollTop:0,scrollLeft:0}),o=l.useRef(null),[i,s]=l.useState({scrollTop:0,scrollLeft:0});l.useEffect(()=>()=>{o.current!==null&&cancelAnimationFrame(o.current)},[]);const d=l.useCallback(a=>{const p=a.currentTarget;if(e.current={scrollTop:p.scrollTop,scrollLeft:p.scrollLeft},o.current!==null&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{o.current=null,s(e.current)}),t){const{scrollTop:c,scrollHeight:f,clientHeight:w}=p;f-c-w<100&&t({visibleTop:c,visibleBottom:c+w,viewportHeight:w})}},[t]);return{scrollTop:i.scrollTop,scrollLeft:i.scrollLeft,handleScroll:d}}function Co(n){const{onStateChange:t,sortModel:e,filterModel:o,effectivePaginationModel:i,columnWidths:s,effectiveColumnOrder:d,columnVisibilityModel:a,pinnedColumns:p}=n,c=l.useRef(t);l.useLayoutEffect(()=>{c.current=t}),l.useEffect(()=>{if(!c.current)return;const f={sorting:{sortModel:e},filter:{filterModel:o},pagination:{paginationModel:i},columns:{columnWidths:s,columnOrder:d,columnVisibilityModel:a,pinnedColumns:p}};c.current(f)},[e,o,i,s,d,a,p])}const yo={sum:n=>n.filter(e=>e!=null&&!isNaN(Number(e))).reduce((e,o)=>e+Number(o),0),avg:n=>{const t=n.filter(e=>e!=null&&!isNaN(Number(e)));return t.length===0?null:t.reduce((e,o)=>e+Number(o),0)/t.length},count:n=>n.filter(t=>t!=null).length,min:n=>{const t=n.filter(e=>e!=null&&!isNaN(Number(e))).map(Number);return t.length?Math.min(...t):null},max:n=>{const t=n.filter(e=>e!=null&&!isNaN(Number(e))).map(Number);return t.length?Math.max(...t):null},unique:n=>new Set(n.filter(t=>t!=null)).size};function _e(n,t){return n==null?"—":typeof n=="number"?t==="avg"?n.toLocaleString(void 0,{maximumFractionDigits:2}):n.toLocaleString():String(n)}function wn(n){const{rows:t,aggregationModel:e,isServerSide:o,dataSource:i,filterModel:s,sortModel:d,serverAggregationResults:a}=n,p=l.useMemo(()=>{if(o||Object.keys(e).length===0)return{};const y={};for(const[v,j]of Object.entries(e)){const b=yo[j];if(!b){console.warn(`[useAggregation] Unknown aggregation function: "${j}"`);continue}const S=t.map(h=>h[v]);y[v]=b(S)}return y},[t,e,o]),[c,f]=l.useState({}),[w,m]=l.useState(!1),[u,x]=l.useState(null),g=l.useRef(0),k=l.useCallback(async()=>{if(!i?.getAggregations||Object.keys(e).length===0)return;const y=++g.current;m(!0),x(null);try{const v=await i.getAggregations({sortModel:d??[],filterModel:s??{items:[]},groupKeys:[],aggregationModel:e});y===g.current&&f(v)}catch(v){y===g.current&&(x(v),console.error("[useAggregation] Server aggregation error:",v))}finally{y===g.current&&m(!1)}},[i,e,s,d]);return l.useEffect(()=>{o&&i?.getAggregations&&!a&&k()},[k,o,i,a]),{aggregationResult:l.useMemo(()=>o?a&&Object.keys(a).length>0?a:c:p,[o,p,a,c]),isLoading:w,error:u}}function ko({columns:n,aggregationModel:t,aggregationResult:e,columnWidths:o,rowHeight:i,checkboxSelection:s,hasDetailPanel:d,rowReordering:a,pinnedColumns:p}){const c=l.useMemo(()=>Ht(n,o,p,s,!0,d,!0,a),[n,o,p,s,d,a]),f=p?.left?.[p.left.length-1],w=p?.right?.[0];return r.jsxs("div",{className:"ogx__aggregation-footer",role:"row","aria-label":"Aggregation totals","aria-live":"polite",style:{minHeight:`${i}px`},children:[s&&r.jsx("div",{style:{width:48,flexShrink:0}}),d&&r.jsx("div",{style:{width:48,flexShrink:0}}),a&&r.jsx("div",{style:{width:48,flexShrink:0}}),n.map(m=>{const u=t[m.field],x=e[m.field],g=o[m.field]??(typeof m.width=="number"?m.width:120),k=ut(m.field,p),N=k?c[m.field]:void 0,y=["ogx__aggregation-cell",k==="left"&&"ogx__aggregation-cell--pinned-left",k==="right"&&"ogx__aggregation-cell--pinned-right",k==="left"&&m.field===f&&"ogx__aggregation-cell--pinned-left-last",k==="right"&&m.field===w&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),v={width:g,minWidth:g,maxWidth:g,textAlign:m.align||"left"};return k==="left"&&N!==void 0&&(v.left=N),k==="right"&&N!==void 0&&(v.right=N),r.jsx("div",{className:y,role:"gridcell",style:v,children:u?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"ogx__aggregation-label",children:u}),r.jsx("span",{className:"ogx__aggregation-value",children:_e(x,u)})]}):null},m.field)})]})}function So({noRowsLabel:n,width:t}){return r.jsxs("div",{className:"ogx__empty",style:{width:t},children:[r.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9h18M9 21V9"})]}),r.jsx("span",{children:n})]})}function jo({error:n}){if(!n)return null;const t=n instanceof Error?n.message:typeof n=="string"?n:"An unexpected error occurred while loading the data.";return r.jsxs("div",{className:"ogx-error-overlay","aria-live":"assertive",role:"alert",children:[r.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:[r.jsx("circle",{cx:"12",cy:"12",r:"10"}),r.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),r.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),r.jsx("div",{className:"ogx-error-overlay__title",children:"Oops! Something went wrong"}),r.jsx("div",{className:"ogx-error-overlay__message",children:t}),r.jsx("button",{onClick:()=>window.location.reload(),className:"ogx-button ogx-button--primary",children:"Retry"})]})}const ft=({indeterminate:n=!1,label:t,className:e="",inputRef:o,...i})=>{const s=l.useRef(null),d=l.useCallback(p=>{s.current=p,typeof o=="function"?o(p):o&&(o.current=p)},[o]);l.useEffect(()=>{s.current&&(s.current.indeterminate=n)},[n]);const a=["ogx-checkbox-wrapper",i.disabled&&"ogx-checkbox-wrapper--disabled",e].filter(Boolean).join(" ");return r.jsxs("label",{className:a,children:[r.jsx("input",{ref:d,type:"checkbox",className:"ogx-checkbox__input","aria-label":t||i["aria-label"]||(n?"Select some":i.checked?"Deselect":"Select"),...i}),r.jsxs("span",{className:"ogx-checkbox__box",children:[i.checked&&!n&&r.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:r.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),n&&r.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:r.jsx("path",{d:"M19 13H5v-2h14v2z"})})]}),t&&r.jsx("span",{className:"ogx-checkbox__label",children:t})]})};function Eo(n){const{field:t,currentWidth:e,onResize:o,minWidth:i=50,maxWidth:s=1e3}=n,[d,a]=l.useState(!1),p=l.useRef(0),c=l.useRef(0),f=l.useCallback(u=>{u.preventDefault(),u.stopPropagation(),a(!0),p.current=u.clientX,c.current=e;let x=0;const g=16,k=y=>{const v=y.clientX-p.current,j=Math.max(i,Math.min(s,c.current+v)),b=Date.now();b-x>=g&&(o(t,j),x=b)},N=y=>{a(!1);const v=y.clientX-p.current,j=Math.max(i,Math.min(s,c.current+v));o(t,j),document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",N)};document.addEventListener("mousemove",k),document.addEventListener("mouseup",N)},[t,e,o,i,s]),w=l.useCallback(u=>{u.preventDefault(),u.stopPropagation()},[]),m=["ogx-column-resize-handle",d&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return r.jsx("div",{className:m,onMouseDown:f,onClick:u=>u.stopPropagation(),onDragStart:u=>{u.preventDefault(),u.stopPropagation()},onDoubleClick:w,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,children:r.jsx("div",{className:"ogx-column-resize-handle__line"})})}function Ye(){return r.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:r.jsx("circle",{cx:"4",cy:"4",r:"4"})})}function qe(){return r.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:r.jsx("circle",{cx:"4",cy:"4",r:"3"})})}function No(){return r.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",children:[r.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.3"}),r.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),r.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Mo(){return r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),r.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function Po(){return r.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),r.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Io(){return r.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:r.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function To(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.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"}),r.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"}),r.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Ro(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"4",y1:"2",x2:"4",y2:"22"}),r.jsx("polyline",{points:"11 8 4 12 11 16"}),r.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Lo(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"20",y1:"2",x2:"20",y2:"22"}),r.jsx("polyline",{points:"13 8 20 12 13 16"}),r.jsx("line",{x1:"20",y1:"12",x2:"4",y2:"12"})]})}function Fo(){return r.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),r.jsx("line",{x1:"4",y1:"4",x2:"4",y2:"20"}),r.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Oo({colDef:n,sortModel:t,onSort:e,onHide:o,onPin:i,pinnedColumns:s,onManageColumns:d,onClose:a,anchorEl:p}){const c=l.useRef(null),[f,w]=l.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});l.useLayoutEffect(()=>{if(!p||!c.current)return;const b=p.getBoundingClientRect(),S=c.current.getBoundingClientRect(),h=window.innerWidth,E=window.innerHeight,M=8;let I=b.left;I+S.width+M>h&&(I=h-S.width-M),I<M&&(I=M);let _=b.bottom+4;_+S.height+M>E&&(_=b.top-S.height-4),w({position:"fixed",zIndex:1300,top:_,left:I,visibility:"visible"})},[p]),l.useEffect(()=>{function b(h){c.current&&!c.current.contains(h.target)&&p&&!p.contains(h.target)&&a()}function S(h){h.key==="Escape"&&a()}return document.addEventListener("mousedown",b),document.addEventListener("keydown",S),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",S),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[p,a]);const m=b=>{e?.(n.field,b),a()},u=()=>{o?.(n.field),a()},x=b=>{i?.(n.field,b),a()},g=t?.find(b=>b.field===n.field)?.sort,k=g==null,N=s?.left?.includes(n.field)??!1,y=s?.right?.includes(n.field)??!1,v=!N&&!y,j=n.headerName||n.field;return He.createPortal(r.jsxs("div",{ref:c,className:"ogx-column-menu",style:f,role:"menu","aria-label":`Column options for ${j}`,children:[e&&n.sortable!==!1&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:`ogx-menu-item${g==="asc"?" ogx-menu-item--active":""}`,onClick:()=>m("asc"),role:"menuitemradio","aria-checked":g==="asc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:g==="asc"?r.jsx(Ye,{}):r.jsx(qe,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Mo,{})}),"Sort Ascending"]}),r.jsxs("button",{className:`ogx-menu-item${g==="desc"?" ogx-menu-item--active":""}`,onClick:()=>m("desc"),role:"menuitemradio","aria-checked":g==="desc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:g==="desc"?r.jsx(Ye,{}):r.jsx(qe,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Po,{})}),"Sort Descending"]}),r.jsxs("button",{className:`ogx-menu-item${k?" ogx-menu-item--active":""}`,onClick:()=>m(null),role:"menuitemradio","aria-checked":k,children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:k?r.jsx(Ye,{}):r.jsx(qe,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Io,{})}),"Unsort"]}),r.jsx("div",{className:"ogx-menu-divider"})]}),r.jsx("div",{className:"ogx-menu-section-label","aria-hidden":"true",children:"Pin column"}),r.jsxs("button",{className:`ogx-menu-item${N?" ogx-menu-item--active":""}`,onClick:()=>x("left"),role:"menuitemradio","aria-checked":N,"aria-label":"Pin to left",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:N?r.jsx(Ye,{}):r.jsx(qe,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Ro,{})}),"Pin to Left"]}),r.jsxs("button",{className:`ogx-menu-item${y?" ogx-menu-item--active":""}`,onClick:()=>x("right"),role:"menuitemradio","aria-checked":y,"aria-label":"Pin to right",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:y?r.jsx(Ye,{}):r.jsx(qe,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Lo,{})}),"Pin to Right"]}),r.jsxs("button",{className:`ogx-menu-item${v?" ogx-menu-item--active":""}`,onClick:()=>x(null),role:"menuitemradio","aria-checked":v,"aria-label":"Unpin column",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:v?r.jsx(Ye,{}):r.jsx(qe,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Fo,{})}),"Unpin"]}),r.jsx("div",{className:"ogx-menu-divider"}),r.jsxs("button",{className:"ogx-menu-item",onClick:u,role:"menuitem","aria-label":`Hide ${j} column`,children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(To,{})}),"Hide Column"]}),r.jsx("div",{className:"ogx-menu-divider"}),r.jsxs("button",{className:"ogx-menu-item",onClick:()=>{d?.(),a()},role:"menuitem","aria-label":"Manage all columns",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(No,{})}),"Manage columns"]})]}),p?.closest(".ogx-theme-provider")||document.body)}function Wo(){return r.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"18",height:"18",children:r.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 Ao(){return r.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor",children:r.jsx("path",{d:"M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"})})}function vn(n){const t=[];for(const e of n.children)typeof e=="string"?t.push(e):t.push(...vn(e));return t}function $o(n){let t=0;function e(o,i){t=Math.max(t,i);for(const s of o.children)typeof s!="string"&&e(s,i+1)}return n.forEach(o=>e(o,1)),t}function zo(n,t,e){function o(a,p,c){if(!vn(a).includes(p))return null;if(c===e)return a;for(const f of a.children)if(typeof f!="string"){const w=o(f,p,c+1);if(w)return w}return null}const i=new Map;for(const a of t){let p=null;for(const c of n)if(p=o(c,a.field,0),p)break;i.set(a.field,p)}const s=[];let d=0;for(;d<t.length;){const a=t[d],p=i.get(a.field)??null,c=a.width;if(!p)s.push({key:`fg-${a.field}-${e}`,label:"",width:c,isGroup:!1}),d++;else{let f=0,w=d;for(;w<t.length&&i.get(t[w].field)===p;)f+=t[w].width,w++;s.push({key:`${p.groupId}-${e}`,label:p.headerName,width:f,isGroup:!0}),d=w}}return s}function _n(n){const{columns:t,allColumns:e,columnGroupingModel:o,checkboxSelection:i=!1,allSelected:s=!1,someSelected:d=!1,onSelectAll:a,onSort:p,sortModel:c=[],onColumnResize:f,columnWidths:w={},pinnedColumns:m,hasDetailPanel:u=!1,pinCheckboxColumn:x=!0,pinExpandColumn:g=!0,rowReordering:k=!1,aggregationModel:N,draggedColumn:y,dragOverColumn:v,onDragStart:j,onDragOver:b,onDragEnd:S,onDrop:h,focusedCell:E,onHeaderClick:M,onHideColumn:I,onPinColumn:_,onManageColumns:T}=n,L=l.useId(),$=l.useRef({}),[O,H]=l.useState(null),F=A=>J=>{J.stopPropagation(),H({colDef:A,anchorEl:J.currentTarget})},D=()=>{H(null)};l.useLayoutEffect(()=>{if(E?.id==="HEADER"){const A=$.current[E.field];A&&A.focus()}},[E]);const q=A=>()=>{if(A.sortable===!1||!p)return;const J=c.find(se=>se.field===A.field);let ee="asc";J&&(J.sort==="asc"?ee="desc":ee=null),p(A.field,ee)},K=A=>{const J=c.find(ee=>ee.field===A);return J?r.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${J.sort}`,"aria-hidden":"true"}):null},C=l.useMemo(()=>Ht(t,w,m,i,x,u,g,k),[t,w,m,i,x,u,g,k]),P=o?$o(o):0,R=(e??t).filter(A=>!A.isSpacer).map(A=>({field:A.field,width:w[A.field]??A.width??100})),ne=(k?48:0)+(u?48:0)+(i?48:0);return r.jsxs("div",{className:"ogx__header-wrap",children:[P>0&&Array.from({length:P},(A,J)=>{const ee=zo(o,R,J);return r.jsxs("div",{className:"ogx-col-group-row",role:"row",children:[ne>0&&r.jsx("div",{className:"ogx-col-group-cell ogx-col-group-cell--filler",style:{width:ne,minWidth:ne,flexShrink:0},role:"columnheader"}),ee.map(se=>r.jsx("div",{role:"columnheader",className:`ogx-col-group-cell ${se.isGroup?"ogx-col-group-cell--group":"ogx-col-group-cell--filler"}`,style:{width:se.width,minWidth:se.width,flexShrink:0},title:se.isGroup?se.label:void 0,children:se.isGroup&&r.jsx("span",{className:"ogx-col-group-cell__label",children:se.label})},se.key))]},`ogx-grp-${J}`)}),r.jsxs("div",{className:"ogx__header",role:"row",children:[k&&r.jsx("div",{className:"ogx__header-cell ogx__header-cell--pinned ogx__header-cell--pinned-left",role:"columnheader","aria-label":"Row reorder handle",title:"Drag to reorder rows",style:{minWidth:48,maxWidth:48,position:"sticky",left:0,zIndex:4}}),u&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${g?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader","aria-label":"Expand row details",style:{minWidth:48,maxWidth:48,position:g?"sticky":void 0,left:g?k?48:0:void 0,zIndex:g?5:void 0}}),i&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${x?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader",style:{position:x?"sticky":void 0,left:x?(k?48:0)+(u&&g?48:0):void 0},children:r.jsx(ft,{id:L,name:L,checked:s,indeterminate:d,onChange:A=>a?.(A.target.checked),"aria-label":s?"Deselect all rows":"Select all rows",tabIndex:E?.id==="HEADER"&&E.field==="__checkbox_col__"?0:-1,onMouseDown:A=>A.preventDefault(),inputRef:A=>{$.current.__checkbox_col__=A}})}),t.map((A,J)=>{if(A.isSpacer)return r.jsx("div",{style:{width:A.width,minWidth:A.width,flexShrink:0},"aria-hidden":"true"},A.field);const ee=A.sortable!==!1,se=c.some(pe=>pe.field===A.field),re=A.resizable!==!1,ve=ut(A.field,m),Y=ve!==null,Q=y===A.field,le=v===A.field,B=["ogx__header-cell",`ogx__header-cell--align-${A.headerAlign||A.align||"left"}`,ee&&"ogx__header-cell--sortable",se&&"ogx__header-cell--sorted",Y&&"ogx__header-cell--pinned",Y&&`ogx__header-cell--pinned-${ve}`,Q&&"ogx__header-cell--dragging",le&&"ogx__header-cell--drag-over",E?.id==="HEADER"&&E.field===A.field&&"ogx__header-cell--focused",A.headerClassName].filter(Boolean).join(" "),X=w[A.field]??A.width??100,te={width:X,minWidth:A.minWidth,maxWidth:A.maxWidth,flexGrow:A.flex??0,flexShrink:0,flexBasis:(A.flex,"auto"),boxSizing:"border-box",position:Y?"sticky":"relative",zIndex:A.zIndex,opacity:Q?.5:1};if(Y&&ve){const pe=C[A.field];ve==="left"?te.left=pe:te.right=pe}const ce=A.renderHeader?A.renderHeader({field:A.field,colDef:A,colIndex:J}):A.headerName||A.field,ge=pe=>{if(pe.target.closest(".ogx-column-resize-handle")){pe.stopPropagation();return}M?.(A.field),ee&&q(A)()},Pe=j?j(A.field):void 0,$e=b?b(A.field):void 0,Ie=h?h(A.field):void 0;return r.jsxs("div",{className:B,style:te,onClick:ge,role:"columnheader",draggable:!!j,onDragStart:Pe,onDragOver:$e,onDragEnd:S,onDrop:Ie,"aria-sort":ee?se?c.find(pe=>pe.field===A.field)?.sort==="asc"?"ascending":"descending":"none":void 0,"aria-colindex":J+1+(i?1:0),"data-field":A.field,tabIndex:-1,ref:pe=>{$.current[A.field]=pe},children:[r.jsxs("div",{className:"ogx__header-cell-content",children:[Q&&r.jsx("div",{className:"ogx__header-drag-icon",children:r.jsx(Ao,{})}),r.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[r.jsx("span",{className:"ogx__header-cell-title",children:ce}),N&&N[A.field]&&r.jsx("span",{className:"ogx__header-cell-aggregation",children:N[A.field]})]}),ee&&K(A.field),!A.disableColumnMenu&&r.jsx("button",{className:"ogx__menu-icon-btn",onClick:F(A),"aria-label":`Open column menu for ${A.headerName||A.field}`,"aria-haspopup":"menu",tabIndex:-1,children:r.jsx(Wo,{})})]}),re&&f&&r.jsx(Eo,{field:A.field,currentWidth:X,onResize:f,minWidth:A.minWidth,maxWidth:A.maxWidth})]},A.field)}),O&&r.jsx(Oo,{colDef:O.colDef,sortModel:c,onSort:p,onHide:I,onPin:_,pinnedColumns:m,onManageColumns:T,onClose:D,anchorEl:O.anchorEl})]})]})}const gt=({variant:n="text",size:t="medium",color:e="default",disabled:o=!1,className:i="",children:s,...d})=>{const a=["ogx-button",`ogx-button--${n}`,`ogx-button--${t}`,`ogx-button--${e}`,o&&"ogx-button--disabled",i].filter(Boolean).join(" ");return r.jsx("button",{className:a,disabled:o,...d,children:s})};function Cn(n){const t=l.useId(),{page:e,pageSize:o,rowCount:i,onPageChange:s,onPageSizeChange:d,pageSizeOptions:a=[10,25,50,100],showFirstButton:p=!0,showLastButton:c=!0,localeText:f}=n,w=Math.max(1,Math.ceil(i/o)),m=Math.min(e,w-1),u=m*o,x=Math.min(u+o,i),g=i===0?0:`${u+1}–${x}`,k=f?.paginationRowsPerPage??"Rows per page:",N=f?.paginationOf?f.paginationOf(i===0?0:u+1,x,i):`${g} of ${i}`,y=f?.paginationPage?f.paginationPage(m+1,w):`Page ${m+1} of ${w}`,v=()=>{s(0)},j=()=>{s(Math.max(0,m-1))},b=()=>{s(Math.min(w-1,m+1))},S=()=>{s(w-1)},h=I=>{const _=parseInt(I.target.value,10);d(_)},E=m===0,M=m>=w-1;return r.jsxs("div",{className:"ogx-pagination",role:"navigation","aria-label":"Pagination",children:[r.jsxs("div",{className:"ogx-pagination__page-size",children:[r.jsx("label",{htmlFor:t,className:"ogx-pagination__label",children:k}),r.jsx("select",{id:t,className:"ogx-pagination__select",value:o,onChange:h,"aria-label":"Rows per page",children:a.map(I=>r.jsx("option",{value:I,children:I},I))})]}),r.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:N}),r.jsxs("div",{className:"ogx-pagination__actions",children:[p&&r.jsx(gt,{variant:"text",size:"small",onClick:v,disabled:E,"aria-label":"Go to first page",title:"First page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"})})}),r.jsx(gt,{variant:"text",size:"small",onClick:j,disabled:E,"aria-label":"Go to previous page",title:"Previous page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),r.jsx("div",{className:"ogx-pagination__page-info","aria-current":"page",children:y}),r.jsx(gt,{variant:"text",size:"small",onClick:b,disabled:M,"aria-label":"Go to next page",title:"Next page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),c&&r.jsx(gt,{variant:"text",size:"small",onClick:S,disabled:M,"aria-label":"Go to last page",title:"Last page",children:r.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:r.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"})})})]})]})}function Bo(n,t,e={}){const o=new Map,i=[];n.forEach(a=>{o.set(a.id,a),i.push(a.id)});const s=new Map,d=[];return t.forEach(a=>{s.set(a.field,a),d.push(a.field)}),{rows:{idRowsLookup:o,allRows:i},columns:{all:t,lookup:s,orderedFields:d,columnVisibilityModel:e},sorting:{sortModel:[]},filter:{filterModel:{items:[]}},pagination:{paginationModel:{page:0,pageSize:100},rowCount:n.length},selection:{selectedRows:new Set},pinning:{pinnedColumns:{},pinnedRows:{}},virtualization:{renderContext:{firstRowIndex:0,lastRowIndex:0,firstColumnIndex:0,lastColumnIndex:0}},dimensions:{rowHeight:52,headerHeight:56,viewportWidth:0,viewportHeight:0},dataSource:{loading:!1,error:null}}}function Do(n,t){switch(t.type){case"SET_ROWS":{const e=Array.from(n.rows.idRowsLookup.values()),o=typeof t.payload=="function"?t.payload(e):t.payload,i=new Map,s=[];return o.forEach(d=>{i.set(d.id,d),s.push(d.id)}),{...n,rows:{idRowsLookup:i,allRows:s},pagination:{...n.pagination,rowCount:t.preserveRowCount?n.pagination.rowCount:o.length}}}case"SET_COLUMNS":{const e=new Map,o=[];return t.payload.forEach(i=>{e.set(i.field,i),o.push(i.field)}),{...n,columns:{all:t.payload,lookup:e,orderedFields:o,columnVisibilityModel:n.columns.columnVisibilityModel}}}case"SET_SORT_MODEL":return{...n,sorting:{sortModel:t.payload}};case"SET_FILTER_MODEL":return{...n,filter:{filterModel:t.payload}};case"SET_PAGINATION_MODEL":return{...n,pagination:{...n.pagination,paginationModel:t.payload}};case"SET_SELECTION":return{...n,selection:{selectedRows:t.payload}};case"SET_DIMENSIONS":return{...n,dimensions:{...n.dimensions,viewportWidth:t.payload.viewportWidth,viewportHeight:t.payload.viewportHeight}};case"SET_DATASOURCE_LOADING":return{...n,dataSource:{...n.dataSource,loading:t.payload}};case"SET_DATASOURCE_ERROR":return{...n,dataSource:{...n.dataSource,error:t.payload}};case"SET_ROW_COUNT":return{...n,pagination:{...n.pagination,rowCount:t.payload}};default:return n}}function Ho(n){const{rows:t,columns:e,rowHeight:o=52,headerHeight:i=56,columnVisibilityModel:s,initialState:d}=n,[a]=l.useState(()=>Bo(t,e,s)),[p,c]=l.useReducer(Do,{...a,sorting:d?.sorting||a.sorting,filter:d?.filter||a.filter,dataSource:d?.dataSource?{...a.dataSource,...d.dataSource}:a.dataSource,pagination:{...a.pagination,...d?.pagination||{},rowCount:n.rowCount??d?.pagination?.rowCount??a.pagination.rowCount},dimensions:{...a.dimensions,rowHeight:o,headerHeight:i}}),f=l.useRef(p);l.useLayoutEffect(()=>{f.current=p});const w=l.useRef(t);l.useEffect(()=>{t!==w.current&&(w.current=t,c({type:"SET_ROWS",payload:t}))},[t]);const m=l.useCallback((h,E)=>{c({type:"SET_ROWS",payload:h,preserveRowCount:E})},[]),u=l.useCallback(h=>{c({type:"SET_COLUMNS",payload:h})},[]),x=l.useCallback(h=>{c({type:"SET_SORT_MODEL",payload:h})},[]),g=l.useCallback(h=>{c({type:"SET_FILTER_MODEL",payload:h})},[]),k=l.useCallback(h=>{c({type:"SET_PAGINATION_MODEL",payload:h})},[]),N=l.useCallback(h=>{c({type:"SET_SELECTION",payload:h})},[]),y=l.useCallback((h,E)=>{c({type:"SET_DIMENSIONS",payload:{viewportWidth:h,viewportHeight:E}})},[]),v=l.useCallback(h=>{c({type:"SET_DATASOURCE_LOADING",payload:h})},[]),j=l.useCallback(h=>{c({type:"SET_DATASOURCE_ERROR",payload:h})},[]),b=l.useCallback(h=>{c({type:"SET_ROW_COUNT",payload:h})},[]),S=l.useRef({getRow:h=>f.current.rows.idRowsLookup.get(h)||null,getAllRows:()=>Array.from(f.current.rows.idRowsLookup.values()),getVisibleRows:()=>Array.from(f.current.rows.idRowsLookup.values()),getAllFilteredRows:()=>Array.from(f.current.rows.idRowsLookup.values()),getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:h=>f.current.columns.lookup.get(h)||null,getAllColumns:()=>f.current.columns.all,getVisibleColumns:()=>f.current.columns.all,selectRow:(h,E=!0)=>{const M=new Set(f.current.selection.selectedRows);E?M.add(h):M.delete(h),N(M)},selectRows:(h,E=!0)=>{const M=new Set(f.current.selection.selectedRows);h.forEach(I=>{E?M.add(I):M.delete(I)}),N(M)},getSelectedRows:()=>Array.from(f.current.selection.selectedRows),sortColumn:(h,E)=>{if(E===null)x(f.current.sorting.sortModel.filter(M=>M.field!==h));else{const M=f.current.sorting.sortModel.findIndex(I=>I.field===h);if(M>=0){const I=[...f.current.sorting.sortModel];I[M]={field:h,sort:E},x(I)}else x([...f.current.sorting.sortModel,{field:h,sort:E}])}},getSortModel:()=>f.current.sorting.sortModel,setFilterModel:g,getFilterModel:()=>f.current.filter.filterModel,setPage:h=>{k({...f.current.pagination.paginationModel,page:h})},setPageSize:h=>{k({...f.current.pagination.paginationModel,pageSize:h,page:0})},scrollToIndexes:()=>{},copySelectedRows:()=>Promise.resolve()});return{state:p,dispatch:c,apiRef:S,setRows:m,setColumns:u,setSortModel:x,setFilterModel:g,setPaginationModel:k,setSelection:N,setDimensions:y,setDataSourceLoading:v,setDataSourceError:j,setRowCount:b}}function Go(n){const{onRowOrderChange:t,rows:e,getRowId:o,rowReordering:i=!1}=n,[s,d]=l.useState(null),[a,p]=l.useState(null),c=l.useCallback(x=>o?o(x):x.id,[o]),f=l.useCallback(x=>g=>{i&&(d(x),g.dataTransfer.effectAllowed="move")},[i]),w=l.useCallback(x=>g=>{!i||!s||(g.preventDefault(),g.dataTransfer.dropEffect="move",a!==x&&p(x))},[i,s,a]),m=l.useCallback(()=>{d(null),p(null)},[]),u=l.useCallback(x=>g=>{if(g.preventDefault(),!s||!t){m();return}const k=e.findIndex(y=>c(y)===s),N=e.findIndex(y=>c(y)===x);k!==-1&&N!==-1&&k!==N&&t({row:e[k],oldIndex:k,targetIndex:N}),m()},[s,t,e,c,m]);return{draggedRowId:s,dragOverRowId:a,onDragStart:i?f:void 0,onDragOver:i?w:void 0,onDragEnd:i?m:void 0,onDrop:i?u:void 0}}function Vo(n){const{rows:t,getRowId:e,getTreeDataPath:o,treeData:i=!1,defaultGroupingExpansionDepth:s=0,filterModel:d,sortModel:a,onRowExpansionChange:p}=n,{treeNodes:c,rootIds:f,groupingRows:w}=l.useMemo(()=>{if(!i||!o)return{treeNodes:new Map,rootIds:[],groupingRows:[]};const b=new Map,S=[],h=[],E=new Map,M=I=>I.join("/");return t.forEach(I=>{const _=e(I),T=o(I),L=M(T);E.set(L,_),b.set(_,{id:_,parentId:null,depth:T.length-1,groupingKey:T[T.length-1],isExpanded:!1,children:[],serverChildrenCount:I.serverChildrenCount})}),t.forEach(I=>{const _=e(I),T=o(I);if(T.length===1){S.push(_);return}const L=O=>{if(O.length<=1)return;const H=O.slice(0,-1),F=M(H);let D=E.get(F);if(D===void 0&&(D=`auto-group-${F}`,!b.has(D))){const q=H[H.length-1];b.set(D,{id:D,parentId:null,depth:H.length-1,groupingKey:q,isExpanded:!1,children:[],label:q}),E.set(F,D);const K={id:D,name:q,_isGroupRow:!0};h.push(K),H.length===1&&S.push(D),L(H)}return D},$=L(T);if($!==void 0){const O=b.get($),H=b.get(_);O&&H&&(H.parentId=$,O.children=O.children||[],O.children.includes(_)||O.children.push(_))}}),h.forEach(I=>{const _=I.id,T=b.get(_);if(!T)return;const $=_.replace("auto-group-","").split("/");if($.length>1){const O=$.slice(0,-1),H=M(O),F=E.get(H);if(F&&b.has(F)){T.parentId=F;const D=b.get(F);D&&(D.children=D.children||[],D.children.includes(_)||D.children.push(_))}}}),{treeNodes:b,rootIds:S,groupingRows:h}},[t,o,i,e]),m=l.useMemo(()=>{if(!i)return new Set;const b=new Set;return c.forEach(S=>{S.children&&S.children.length>0&&(s===-1||S.depth<s)&&b.add(S.id)}),b},[c,i,s]),[u,x]=l.useState(new Set);l.useEffect(()=>{m.size>0&&x(m)},[m]);const g=l.useCallback(b=>{x(S=>{const h=new Set(S),E=!h.has(b);if(h.has(b)?h.delete(b):h.add(b),E&&p){const M=c.get(b);M&&p(M)}return h})},[c,p]),k=l.useCallback(()=>{if(!i)return null;const b=new Map;t.forEach(L=>b.set(e(L),L)),w.forEach(L=>b.set(L.id,L));const S=L=>Vt(L,d),h=new Map,E=L=>{if(h.has(L))return h.get(L);const $=b.get(L);if(!$)return!1;if(S($))return h.set(L,!0),!0;const H=c.get(L);return H&&H.children&&H.children.some(D=>E(D))?(h.set(L,!0),!0):(h.set(L,!1),!1)},M=(L,$)=>{if(!a||a.length===0)return 0;const O=b.get(L),H=b.get($);if(!O||!H)return 0;for(const F of a){const D=O[F.field],q=H[F.field],K=Ut(D,q,F.sort);if(K!==0)return K}return 0},I=[],_=new Set,T=L=>{const $=L.filter(O=>E(O));$.sort(M),$.forEach(O=>{if(_.has(O))return;const H=b.get(O),F=c.get(O);if(H&&F){_.add(O);const D={...H,_treeDepth:F.depth,_isExpanded:u.has(O),_hasChildren:!!(F.children&&F.children.length>0||F.serverChildrenCount&&F.serverChildrenCount>0),_descendantCount:F.children?F.children.length:0};I.push(D),u.has(O)&&F.children&&F.children.length>0&&T(F.children)}})};return T(f),I},[i,t,w,f,c,u,d,a,e]),N=l.useCallback(b=>u.has(b),[u]),y=l.useCallback(b=>c.get(b),[c]),v=l.useCallback(b=>{const S=[];let h=b;for(;h!==null;){const E=c.get(h);if(!E)break;S.unshift(E.groupingKey),h=E.parentId}return S},[c]),j=l.useMemo(()=>{const b=new Map,S=new Set(w.map(h=>h.id));return c.forEach((h,E)=>{b.set(E,{hasChildren:!!(h.children&&h.children.length>0||h.serverChildrenCount&&h.serverChildrenCount>0),treeDepth:h.depth,descendantCount:h.children?h.children.length:void 0,isGroupRow:S.has(E),isExpanded:u.has(E)})}),b},[c,w,u]);return l.useMemo(()=>({treeNodes:c,groupingRows:w,toggleExpansion:g,isGroupExpanded:N,getVisibleRows:k,getNode:y,getNodePath:v,rowMetaMap:j}),[c,w,g,N,k,y,v,j])}const Uo=n=>n?.depth===-1?"footer":"inline",Ko=[],Yo={};function qo(n){const{rows:t,getRowId:e,rowGroupingModel:o=Ko,aggregationModel:i=Yo,defaultGroupingExpansionDepth:s=0,filterModel:d,sortModel:a,getAggregationPosition:p=Uo}=n,[c,f]=l.useState(new Set),{treeNodes:w,rootIds:m,groupingRows:u}=l.useMemo(()=>{const v=new Map,j=new Map,b=[];if(o.length===0)return{treeNodes:v,rootIds:b,groupingRows:j};const S=(M,I,_)=>`auto-group-${M}-${I}-${_||"root"}`,h=(M,I,_)=>{if(I>=o.length)return M.map(O=>{const H=e(O);return v.set(H,{id:H,parentId:_,depth:I,groupingKey:"",isExpanded:!1}),H});const T=o[I],L=new Map;M.forEach(O=>{const H=O[T],F=String(H);L.has(F)||L.set(F,[]),L.get(F).push(O)});const $=[];return L.forEach((O,H)=>{const D=O[0][T],q=S(T,H,_);$.push(q);const K={};i&&Object.entries(i).forEach(([z,U])=>{const G=O.map(ne=>ne[z]);if(U==="sum")K[z]=G.reduce((ne,A)=>ne+(Number(A)||0),0);else if(U==="min")K[z]=Math.min(...G.map(ne=>Number(ne)||0));else if(U==="max")K[z]=Math.max(...G.map(ne=>Number(ne)||0));else if(U==="avg"){const ne=G.reduce((A,J)=>A+(Number(J)||0),0);K[z]=G.length?ne/G.length:0}else U==="count"&&(K[z]=G.length)});const C={[T]:D,...K,id:q};j.set(q,C);const P={id:q,parentId:_,depth:I,groupingKey:H,groupingField:T,groupingValue:D,aggregatedValues:K,isExpanded:!1,children:[],label:`${T}: ${String(D)}`};P.aggregationPosition=p(P),v.set(q,P);const W=h(O,I+1,q);v.get(q).children=W;const R=O.length;v.get(q).descendantCount=R}),$},E=h(t,0,null);return b.push(...E),{treeNodes:v,rootIds:b,groupingRows:j}},[t,o,i,e,p]);l.useEffect(()=>{if(s===-1){const v=new Set;w.forEach((j,b)=>{j.children&&j.children.length>0&&v.add(b)}),f(v)}else if(s>0){const v=new Set;w.forEach((j,b)=>{j.depth<s&&j.children&&j.children.length>0&&v.add(b)}),f(v)}else f(new Set)},[o,s,w]);const x=l.useCallback(v=>{f(j=>{const b=new Set(j);return b.has(v)?b.delete(v):b.add(v),b})},[]),g=l.useCallback(v=>c.has(v),[c]),k=l.useCallback(()=>{if(o.length===0)return null;const v=[],j=new Set,b=new Map;t.forEach(M=>b.set(e(M),M));const S=M=>{const I=w.get(M);if(!I)return!1;if(!I.children||I.children.length===0){const _=b.get(M);return!(!_||d&&!Vt(_,d))}return I.children.some(_=>S(_))},h=M=>{let I=M;d&&(I=M.filter(S)),a&&a.length>0&&I.sort((_,T)=>{const L=u.get(_)||b.get(_),$=u.get(T)||b.get(T);if(!L||!$)return 0;for(const O of a){const H=L[O.field],F=$[O.field],D=Ut(H,F,O.sort);if(D!==0)return D}return 0}),I.forEach(_=>{if(j.has(_))return;const T=w.get(_),L=T?.children&&T.children.length>0,$=L?u.get(_):b.get(_);if($&&T){j.add(_);const O={...$,_treeDepth:T.depth,_isExpanded:c.has(_),_hasChildren:L,_groupingField:T.groupingField,_groupingValue:T.groupingValue,_descendantCount:T.descendantCount};v.push(O),E.has(_)&&L&&h(T.children)}})},E=c;return h(m),v},[t,e,w,m,u,d,a,c,o]),N=l.useCallback(v=>w.get(v),[w]),y=l.useMemo(()=>{const v=new Map;return w.forEach((j,b)=>{const S=!!(j.children&&j.children.length>0);v.set(b,{hasChildren:S,treeDepth:j.depth,groupingField:j.groupingField,groupingValue:j.groupingValue,descendantCount:j.descendantCount,isGroupRow:S,isExpanded:S?c.has(b):void 0})}),v},[w,c]);return l.useMemo(()=>({treeNodes:w,groupingRows:u,toggleExpansion:x,isGroupExpanded:g,getVisibleRows:k,getNode:N,rowMetaMap:y}),[w,u,x,g,k,N,y])}function Xo(n){const{rows:t,getRowId:e,processRowUpdate:o,onProcessRowUpdateError:i,onRowChange:s}=n,[d,a]=l.useState(null),p=l.useRef(null),c=l.useCallback(u=>{a(u),p.current=typeof u=="function"?u(p.current):u},[]),f=l.useCallback(u=>{c({id:u.id,field:u.field,value:u.value,originalValue:u.value})},[c]),w=l.useCallback(async u=>{const x=p.current;if(!x)return;if(u?.cancel){c(null);return}const{id:g,field:k,value:N,originalValue:y}=x;if(N===y){c(null);return}const v=t.find(b=>e(b)===g);if(!v){c(null);return}const j={...v,[k]:N};try{if(o){const b=await o(j,v);s?.(b)}else s?.(j);c(null)}catch(b){i?.(b)}},[c,t,e,o,s,i]),m=l.useCallback(u=>{d&&d.id===u.id&&d.field===u.field&&c(x=>x?{...x,value:u.value}:null)},[d,c]);return{editingCell:d,startCellEdit:f,stopCellEdit:w,setEditCellValue:m}}function Jo(n,t,e){const[o,i]=l.useState(new Map),[s,d]=l.useState({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}}),a=l.useCallback(()=>{i(new Map)},[]),p=l.useCallback((g,k)=>o.get(g)?.[k],[o]),c=l.useCallback((g,k,N,y,v)=>{const j=new Map(o);for(let b=y;b<v;b++){const S=t[b];if(!S)continue;let h=1;if(S.colSpan)if(typeof S.colSpan=="function"){const M={row:k,value:k[S.field],field:S.field,colDef:S,rowIndex:N,colIndex:b};h=S.colSpan(M)}else h=S.colSpan;if(h<=1){Xe(j,g,S.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:e[S.field]||100}});continue}let E=e[S.field]||100;for(let M=1;M<h;M++)if(b+M<v){const I=t[b+M];I&&(E+=e[I.field]||100,Xe(j,g,I.field,{spannedByColSpan:!0,leftVisibleCellIndex:b,rightVisibleCellIndex:Math.min(b+h-1,t.length-1)}))}Xe(j,g,S.field,{spannedByColSpan:!1,cellProps:{colSpan:h,width:E}}),b+=h-1}i(j)},[o,t,e]),f=l.useCallback((g,k)=>{const N={},y={},v={};t.forEach((j,b)=>{if(j.rowSpan)for(let S=g;S<k;S++){const h=n[S];if(!h||y[h.id]?.[j.field])continue;const E=j.valueGetter?j.valueGetter({row:h,field:j.field,value:h[j.field]}):h[j.field];let M=1;if(typeof j.rowSpan=="function"){const I={row:h,value:E,field:j.field,colDef:j,rowIndex:S,colIndex:b};M=j.rowSpan(I)}else typeof j.rowSpan=="number"&&(M=j.rowSpan);if(M>1){N[h.id]||(N[h.id]={}),N[h.id][j.field]=M;for(let I=1;I<M;I++){const _=S+I;if(_<k&&n[_]){const T=n[_];y[T.id]||(y[T.id]={}),y[T.id][j.field]=!0,v[_]||(v[_]={}),v[_][j.field]=S}}}}}),d({caches:{spannedCells:N,hiddenCells:y,hiddenCellOriginMap:v},processedRange:{firstRowIndex:g,lastRowIndex:k}})},[n,t]),w=l.useCallback(()=>{d({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}})},[]);l.useEffect(()=>{const g=new Map;n.forEach((v,j)=>{for(let b=0;b<t.length;b++){const S=t[b];if(!S)continue;let h=1;if(S.colSpan)if(typeof S.colSpan=="function"){const M={row:v,value:v[S.field],field:S.field,colDef:S,rowIndex:j,colIndex:b};h=S.colSpan(M)}else h=S.colSpan;if(h<=1){const M=e[S.field]||(typeof S.width=="number"?S.width:100);Xe(g,v.id,S.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:M}});continue}let E=e[S.field]||(typeof S.width=="number"?S.width:100);for(let M=1;M<h;M++)if(b+M<t.length){const I=t[b+M];if(I){const _=e[I.field]||(typeof I.width=="number"?I.width:100);E+=_,Xe(g,v.id,I.field,{spannedByColSpan:!0,leftVisibleCellIndex:b,rightVisibleCellIndex:Math.min(b+h-1,t.length-1)})}}Xe(g,v.id,S.field,{spannedByColSpan:!1,cellProps:{colSpan:h,width:E}}),b+=h-1}}),i(g);const k={},N={},y={};t.forEach((v,j)=>{if(v.rowSpan)for(let b=0;b<n.length;b++){const S=n[b];if(!S||N[S.id]?.[v.field])continue;const h=v.valueGetter?v.valueGetter({row:S,field:v.field,value:S[v.field]}):S[v.field];let E=1;if(typeof v.rowSpan=="function"){const M={row:S,value:h,field:v.field,colDef:v,rowIndex:b,colIndex:j};E=v.rowSpan(M)}else typeof v.rowSpan=="number"&&(E=v.rowSpan);if(E>1){k[S.id]||(k[S.id]={}),k[S.id][v.field]=E;for(let M=1;M<E;M++){const I=b+M;if(I<n.length&&n[I]){const _=n[I];N[_.id]||(N[_.id]={}),N[_.id][v.field]=!0,y[I]||(y[I]={}),y[I][v.field]=b}}}}}),d({caches:{spannedCells:k,hiddenCells:N,hiddenCellOriginMap:y},processedRange:{firstRowIndex:0,lastRowIndex:n.length}})},[n,t,e]);const m=l.useCallback(()=>s.caches.spannedCells,[s]),u=l.useCallback(()=>s.caches.hiddenCells,[s]),x=l.useCallback(()=>s.caches.hiddenCellOriginMap,[s]);return{colspanMap:o,resetColSpan:a,getCellColSpanInfo:p,calculateColSpan:c,rowSpanningState:s,calculateRowSpan:f,resetRowSpan:w,getSpannedCells:m,getHiddenCells:u,getHiddenCellOriginMap:x}}function Xe(n,t,e,o){let i=n.get(t);i||(i={},n.set(t,i)),i[e]=o}function Qo(n){const{dataSource:t,sortModel:e,filterModel:o,paginationModel:i,paginationMode:s,sortingMode:d,filterMode:a,aggregationModel:p,setRows:c,setRowCount:f,setDataSourceLoading:w,setDataSourceError:m,onAggregationResults:u}=n,x=l.useRef(null),g=l.useRef(0),k=l.useCallback(async()=>{if(!t)return;const y=++g.current;w(!0),m(null);const v=i.page*i.pageSize,j=v+i.pageSize,b={startRow:v,endRow:j,sortModel:e,filterModel:o,groupKeys:[],aggregationModel:p};try{const S=await t.getRows(b);if(y!==g.current)return;let h=!1;if(s==="infinite"){const E=x.current;if(E){const M=JSON.stringify(E.sortModel)!==JSON.stringify(e),I=JSON.stringify(E.filterModel)!==JSON.stringify(o),_=E.pageSize!==i.pageSize;!M&&!I&&!_&&i.page>E.page&&(h=!0)}}c(h?E=>[...E,...S.rows]:S.rows,!0),S.aggregationResults&&u&&u(S.aggregationResults),S.rowCount!==void 0&&f(S.rowCount),x.current={sortModel:e,filterModel:o,page:i.page,pageSize:i.pageSize}}catch(S){y===g.current&&(m(S),console.error("Data Source Error:",S))}finally{y===g.current&&w(!1)}},[t,i.page,i.pageSize,e,o,s,p,u,c,f,w,m]);l.useEffect(()=>{if(t&&(s==="server"||s==="infinite"||d==="server"||a==="server")){const v=setTimeout(()=>{k()},300);return()=>clearTimeout(v)}},[k,t,s,d,a]);const N=l.useCallback(async(y,v)=>{if(t){w(!0);try{const j=await t.getRows({startRow:0,endRow:-1,sortModel:e,filterModel:o,groupKeys:v});j.rows.length>0&&c(b=>{const S=new Set(b.map(E=>E.id)),h=j.rows.filter(E=>!S.has(E.id));return[...b,...h]})}catch(j){m(j),console.error("Failed to fetch children:",j)}finally{w(!1)}}},[t,e,o,c,w,m]);return{fetchRows:k,fetchChildren:N}}const yn="\0",ht="";function Zo(n,t){const e=n.filter(o=>o!=null&&!isNaN(o));if(e.length===0)return null;switch(t){case"sum":return e.reduce((o,i)=>o+i,0);case"avg":return e.reduce((o,i)=>o+i,0)/e.length;case"count":return e.length;case"min":return Math.min(...e);case"max":return Math.max(...e)}}function Nt(n,t){return t.map(e=>String(n[e]??"")).join(yn)}function Kt(n,t,e,o){return o?`${n}${ht}${t}${ht}${e}`:`${t}${ht}${e}`}function kn(n,t,e,o){return l.useMemo(()=>{const i={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1};if(!o)return i;const{rowFields:s,columnFields:d,valueFields:a}=e;if(s.length===0||a.length===0)return i;const p=d.length>0,c=new Map(t.map(y=>[y.field,y])),f=new Set;for(const y of n)f.add(Nt(y,d));const w=Array.from(f).sort(),m=new Map;for(const y of n){const v=Nt(y,s);if(!m.has(v)){const h={};for(const E of s)h[E]=y[E];m.set(v,{labelValues:h,bucket:new Map})}const j=m.get(v),b=Nt(y,d);j.bucket.has(b)||j.bucket.set(b,new Map);const S=j.bucket.get(b);for(const h of a){const E=y[h.field];S.has(h.field)||S.set(h.field,[]),E!=null&&!isNaN(Number(E))&&S.get(h.field).push(Number(E))}}let u=0;const x=[];for(const[,y]of m){const v={id:u++,...y.labelValues};for(const j of w){const b=y.bucket.get(j);for(const S of a){const h=Kt(j,S.field,S.aggFn,p),E=b?.get(S.field)??[];v[h]=E.length>0?Zo(E,S.aggFn):null}}x.push(v)}const g=new Map;for(const y of n){const v=Nt(y,d);for(const j of a){if(j.aggFn!=="avg"&&j.aggFn!=="min"&&j.aggFn!=="max")continue;const b=`${v}${ht}${j.field}`;g.has(b)||g.set(b,[]);const S=y[j.field];S!=null&&!isNaN(Number(S))&&g.get(b).push(Number(S))}}const k={id:"__pivot_grand_total__"};for(let y=0;y<s.length;y++)k[s[y]]=y===0?"Grand Total":"";for(const y of w)for(const v of a){const j=Kt(y,v.field,v.aggFn,p),b=x.map(h=>h[j]).filter(h=>h!=null&&!isNaN(Number(h))).map(Number);if(b.length===0){k[j]=null;continue}const S=`${y}${ht}${v.field}`;switch(v.aggFn){case"sum":case"count":k[j]=b.reduce((h,E)=>h+E,0);break;case"avg":{const h=g.get(S)??[];k[j]=h.length>0?h.reduce((E,M)=>E+M,0)/h.length:null;break}case"min":k[j]=Math.min(...g.get(S)??b);break;case"max":k[j]=Math.max(...g.get(S)??b);break}}x.push(k);const N=[];for(const y of s){const v=c.get(y);N.push({field:y,headerName:v?.headerName??y,width:v?.width??140,sortable:!0})}for(const y of w){const v=p?y.split(yn).map((j,b)=>{const S=c.get(d[b]);return S?.headerName?`${S.headerName}: ${j}`:j}).join(" / "):"";for(const j of a){const b=c.get(j.field),S=Kt(y,j.field,j.aggFn,p),h=j.headerName??b?.headerName??j.field,E=v?`${v} — ${h} (${j.aggFn})`:`${h} (${j.aggFn})`;N.push({field:S,headerName:E,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:M})=>{if(M==null)return"—";const I=Number(M);return j.aggFn==="avg"?I.toFixed(2):j.aggFn==="count"?I.toLocaleString():b?.valueFormatter?b.valueFormatter({value:M,row:{},field:j.field}):I.toLocaleString()}})}}return{pivotRows:x,pivotColumns:N,colKeys:w,isValid:!0}},[n,t,e,o])}function er(n){const t=document.createElement("textarea");t.value=n,t.style.cssText="position:fixed;top:-9999px;left:-9999px;opacity:0;",document.body.appendChild(t),t.focus(),t.select();let e=!1;try{e=document.execCommand("copy")}finally{document.body.removeChild(t)}return e}async function tr(n){let t=!1;try{t=er(n)}catch{}if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function")try{await navigator.clipboard.writeText(n);return}catch(e){if(t)return;throw e}else if(!t)throw new Error("Clipboard API not available and fallback failed.")}function nr(n){const{selectedRowIds:t,columns:e,getVisibleRows:o,getRowId:i}=n,s=l.useCallback(async()=>{if(t.size===0)return;const a=o().filter(m=>t.has(i(m)));if(a.length===0)return;const p=e.filter(m=>!m.field.startsWith("__")),c=p.map(m=>m.headerName||m.field).join(" "),f=a.map(m=>p.map(u=>{const x=m[u.field];return u.valueFormatter?u.valueFormatter({value:x,row:m,field:u.field}):x??""}).join(" ")).join(`
7
+ `),w=`${c}
8
+ ${f}`;try{await tr(w)}catch(m){console.error("[OpenGridX] Failed to copy to clipboard:",m)}},[t,e,o,i]);return l.useEffect(()=>{const d=a=>{if(!(a.ctrlKey||a.metaKey)||a.key!=="c")return;const p=document.activeElement,c=p?.tagName.toLowerCase(),f=p?.type;c==="input"&&f!=="checkbox"&&f!=="radio"||c==="textarea"||c==="select"||p?.isContentEditable||s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),{copySelectedRows:s}}function or({row:n,rowIndex:t,listViewColumn:e,isSelected:o=!1,checkboxSelection:i=!1,rowHeight:s,onRowClick:d,onSelectionChange:a}){const p={row:n,value:void 0,field:e.field,colDef:{field:e.field},rowIndex:t,colIndex:0},c=f=>{f.stopPropagation(),a?.(n.id,f.target.checked)};return r.jsxs("div",{className:`ogx-list-view__row${o?" ogx-list-view__row--selected":""}`,style:s?{minHeight:s}:void 0,onClick:()=>d?.(n),role:"row","aria-rowindex":t+2,"aria-selected":o,children:[i&&r.jsx("div",{className:"ogx-list-view__checkbox",onClick:f=>f.stopPropagation(),children:r.jsx("input",{type:"checkbox",checked:o,onChange:c,"aria-label":`Select row ${n.id}`})}),r.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:e.renderCell(p)})]})}function rr({ariaLabel:n,allRenderableRows:t,filteredRows:e,pagination:o,effectivePaginationModel:i,pageSizeOptions:s,selectedRowIds:d,listViewColumn:a,noRowsLabel:p,rowHeight:c,checkboxSelection:f,paginationMode:w,dataSource:m,serverRowCount:u,paginationSlot:x,paginationSlotProps:g,localeText:k,onRowClick:N,onSelectionChange:y,onPaginationModelChange:v}){const j=x||Cn,b=w==="server"&&m?u||0:e.length;return r.jsxs("div",{className:"ogx-list-view",role:"grid","aria-label":n||"Data grid list view","aria-rowcount":t.length+1,children:[r.jsx("div",{className:"ogx-list-view__toolbar",children:r.jsxs("span",{children:[e.length," ",e.length===1?"item":"items",o?` · page ${i.page+1} of ${Math.ceil(e.length/i.pageSize)||1}`:"",d.size>0?` · ${d.size} selected`:""]})}),r.jsx("div",{className:"ogx-list-view__rows",children:t.length===0?r.jsxs("div",{className:"ogx-list-view__empty","aria-live":"polite",role:"status",children:[r.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[r.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9h18M9 21V9"})]}),p]}):t.map((S,h)=>r.jsx(or,{row:S,rowIndex:h,listViewColumn:a,isSelected:d.has(S.id),checkboxSelection:f,rowHeight:c,onRowClick:E=>N({row:E,id:E.id,rowIndex:h}),onSelectionChange:y},S.id))}),o&&r.jsx(j,{page:i.page,pageSize:i.pageSize,rowCount:b,pageSizeOptions:s,onPageChange:S=>v({...i,page:S}),onPageSizeChange:S=>v({...i,pageSize:S,page:0}),localeText:k,...g})]})}function ir({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[i,s]=l.useState(String(n??"")),d=l.useRef(null);return l.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"text",className:"ogx__edit-input",value:i,onChange:a=>{s(a.target.value),t(a.target.value)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function lr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[i,s]=l.useState(typeof n=="number"?n:""),d=l.useRef(null);return l.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"number",className:"ogx__edit-input ogx__edit-input--number",value:i,onChange:a=>{const p=a.target.value===""?"":Number(a.target.value);s(p),t(p===""?null:p)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function sr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const i=l.useRef(null);l.useEffect(()=>{i.current?.focus()},[]);const s=()=>{t(!n),setTimeout(e,0)};return r.jsx("div",{className:"ogx__edit-boolean",children:r.jsx("input",{ref:i,type:"checkbox",className:"ogx__edit-checkbox",checked:!!n,onChange:s,onKeyDown:d=>{d.key==="Escape"&&(d.stopPropagation(),o())}})})}function ar({value:n,colDef:t,onValueChange:e,onCommit:o,onCancel:i}){const s=l.useRef(null);l.useEffect(()=>{s.current?.focus()},[]);const d=t.valueOptions??[];return r.jsx("select",{ref:s,className:"ogx__edit-select",value:String(n??""),onChange:a=>{e(a.target.value)},onBlur:o,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),o()),a.key==="Escape"&&(a.stopPropagation(),i())},children:d.map(a=>{const p=typeof a=="object"?a.value:a,c=typeof a=="object"?a.label:String(a);return r.jsx("option",{value:String(p),children:c},String(p))})})}function dr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[i,s]=l.useState(typeof n=="string"?n:String(n??"")),d=l.useRef(null);return l.useEffect(()=>{d.current?.focus()},[]),r.jsx("input",{ref:d,type:"date",className:"ogx__edit-input",value:i,onChange:a=>{s(a.target.value),t(a.target.value)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function cr(n){const{colDef:t}=n;switch(t.type){case"number":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(lr,{...n})});case"boolean":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(sr,{...n})});case"singleSelect":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(ar,{...n})});case"date":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(dr,{...n})});default:return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(ir,{...n})})}}function ur({renderFn:n}){return r.jsx(r.Fragment,{children:n()})}class fr extends l.Component{constructor(t){super(t),this.state={hasError:!1,error:null,resetKey:t.resetKey}}static getDerivedStateFromProps(t,e){return e.hasError&&t.resetKey!==e.resetKey?{hasError:!1,error:null,resetKey:t.resetKey}:t.resetKey!==e.resetKey?{resetKey:t.resetKey}:null}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,e){process.env.NODE_ENV!=="production"&&console.warn(`[CellErrorBoundary] field="${this.props.field}"`,t,e.componentStack)}render(){return this.state.hasError?r.jsx("div",{className:"ogx__cell-error",role:"status","aria-label":`Error in cell: ${this.props.field}`,title:this.state.error?.message??"Render error",children:"⚠"}):r.jsx(ur,{renderFn:this.props.renderFn})}}function gr(n){const{onCellClick:t,onCellEditStart:e,onCellValueChange:o,value:i,row:s,colDef:d,rowIndex:a,colIndex:p,isSelected:c,onClick:f,width:w,pinnedPosition:m,pinnedOffset:u,isFocused:x,isFocusVisible:g,isEditable:k,isEditing:N,onEditStart:y,onEditStop:v,onValueChange:j,colSpanInfo:b,rowSpan:S,isHiddenByRowSpan:h,rowMeta:E}=n,M=l.useCallback(C=>{o?o(d.field,C):j?.(C)},[o,j,d.field]),I=l.useMemo(()=>d.valueFormatter?d.valueFormatter({value:i,row:s,field:d.field}):i==null?"":String(i),[i,s,d]),_=l.useMemo(()=>d.cellClassName?typeof d.cellClassName=="function"?d.cellClassName({value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:p})||"":d.cellClassName:"",[d,i,s,a,p]),T=l.useRef(null);if(l.useLayoutEffect(()=>{x&&T.current&&T.current.focus({preventScroll:!0})},[x]),b?.spannedByColSpan)return null;if(h)return r.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:{width:w??d.width??100},role:"presentation","data-field":d.field,"data-colindex":p});const L=C=>{t&&t({row:s,field:d.field,value:i,colDef:d,rowIndex:a,colIndex:p}),f?.(C)},$=C=>{k&&(y||e)&&(C.stopPropagation(),e?e(d.field,i):y?.())},O=m!=null,H=["ogx__cell",`ogx__cell--align-${d.align||"left"}`,c&&"ogx__cell--selected",x&&"ogx__cell--focused",x&&g&&"ogx__cell--focus-visible",d.type&&`ogx__cell--type-${d.type}`,O&&"ogx__cell--pinned",O&&`ogx__cell--pinned-${m}`,N&&"ogx__cell--editing",S&&S>1&&"ogx__cell--spanned",_].filter(Boolean).join(" "),F=b?.cellProps?.colSpan||1,D=S||1,q=b?.cellProps?.width??w??d.width??100,K={width:"var(--width)","--width":typeof q=="number"?`${q}px`:q,flexGrow:d.flex??0,flexShrink:0,flexBasis:(d.flex,"auto"),boxSizing:"border-box",minWidth:d.minWidth,maxWidth:d.maxWidth,position:O?"sticky":void 0,zIndex:d.zIndex??(O?3:void 0),padding:N?0:void 0};return D>1&&(K.height=`calc(var(--height) * ${D} - var(--border-width, 1px))`,K.zIndex=10,O&&(K.zIndex=40)),O&&u!==void 0&&(m==="left"?K.left=u:K.right=u),r.jsx("div",{ref:T,className:H,style:K,onClick:L,onDoubleClick:$,role:"gridcell","aria-colindex":p+1,"aria-readonly":!k||void 0,tabIndex:-1,"data-field":d.field,"data-colindex":p,...F>1?{"aria-colspan":F}:{},...D>1?{"aria-rowspan":D}:{},children:r.jsx("div",{className:"ogx__cell-content",children:N&&(o||j)&&v?d.renderEditCell?d.renderEditCell({value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:p,rowMeta:E}):r.jsx(cr,{value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:p,onValueChange:M,onCommit:()=>v(),onCancel:()=>v(!0)}):d.renderCell?r.jsx(fr,{field:d.field,resetKey:s,renderFn:()=>d.renderCell({value:i,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:p,rowMeta:E})}):I})})}const Sn=l.memo(gr),hr=({className:n="",...t})=>r.jsx("button",{type:"button",className:`ogx-drag-handle ${n}`,"aria-label":"Drag to reorder row",...t,children:r.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:r.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 pr(n){const{content:t,height:e,isExpanded:o}=n;if(!o)return null;const i={height:e==="auto"?"auto":`${e}px`,overflow:e==="auto"?"visible":"auto"};return r.jsx("div",{className:"ogx__detail-panel",style:i,children:r.jsx("div",{className:"ogx__detail-panel-content",children:t})})}function Mt(n){const{row:t,columns:e,rowIndex:o,isSelected:i=!1,checkboxSelection:s=!1,onRowClick:d,onCellClick:a,onSelectionChange:p,columnWidths:c={},pinnedColumns:f,pinnedRows:w,hasDetailPanel:m=!1,isDetailPanelExpanded:u=!1,onDetailPanelToggle:x,detailPanelContent:g,detailPanelHeight:k=200,pinCheckboxColumn:N=!0,pinExpandColumn:y=!0,rowReordering:v=!1,onDragStart:j,onDragOver:b,onDragEnd:S,onDrop:h,isDragging:E,isDragOver:M,editingCell:I,onEditStart:_,onEditStop:T,onEditCellValueChange:L,focusedCellField:$,isFocusVisible:O,colspanMap:H,rowSpanningCaches:F,rowHeight:D=52,rowMeta:q}=n,K=l.useId(),C=l.useRef(null),P=l.useRef(null);l.useLayoutEffect(()=>{$==="__expand_col__"&&C.current&&C.current.focus({preventScroll:!0}),$==="__checkbox_col__"&&P.current&&P.current.focus({preventScroll:!0})},[$]);const W=l.useMemo(()=>Ht(e,c,f,s,N,m,y,v),[e,c,f,s,N,m,y,v]),R=q?.hasChildren===!0,z=l.useCallback((Y,Q)=>{R||_?.({id:t.id,field:Y,value:Q})},[R,t.id,_]),U=l.useCallback((Y,Q)=>{L?.({id:t.id,field:Y,value:Q})},[L,t.id]),G=l.useCallback(Y=>{T?.({cancel:Y})},[T]);if(t._isSkeleton){const Y=Math.max(e.length,5);return r.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:D,minHeight:D},children:Array.from({length:Y}).map((Q,le)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-bar"})},le))})}const ne=Y=>{Y.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell")||d?.({row:t,id:t.id,rowIndex:o})},A=Y=>{Y.stopPropagation(),p?.(t.id,Y.target.checked)},J=Y=>{Y.stopPropagation(),x?.(t.id)},ee=Gt(t.id,w),se=ee==="top",re=ee==="bottom",ve=["ogx__row",i&&"ogx__row--selected",o%2===0&&"ogx__row--even",o%2===1&&"ogx__row--odd",se&&"ogx__row--pinned-top",re&&"ogx__row--pinned-bottom",E&&"ogx__row--dragging",M&&"ogx__row--drag-over",R&&"ogx__row--group"].filter(Boolean).join(" ");return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:ve,onClick:ne,role:"row","aria-rowindex":o+1,"aria-selected":i,"data-rowindex":o,onDragOver:b?b(t.id):void 0,onDrop:h?h(t.id):void 0,style:{maxHeight:`${D}px`,minHeight:`${D}px`,"--height":`${D}px`,"--border-width":"1px"},children:[v&&r.jsx("div",{className:"ogx__cell ogx__cell--drag-handle",role:"gridcell","aria-label":"Drag to reorder row",style:{position:"sticky",left:0,zIndex:4},draggable:!0,onDragStart:j?j(t.id):void 0,onDragEnd:S,onClick:Y=>Y.stopPropagation(),children:r.jsx(hr,{})}),m&&r.jsx("div",{className:`ogx__cell ogx__cell--expand ${y?"ogx__cell--pinned-left":""} ${$==="__expand_col__"?"ogx__cell--focused":""} ${$==="__expand_col__"&&O?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":u?"Collapse row details":"Expand row details","aria-expanded":u,style:{position:y?"sticky":void 0,left:y?v?48:0:void 0,zIndex:y?5:void 0},ref:C,tabIndex:-1,onClick:Y=>{Y.stopPropagation(),a?.({row:t,field:"__expand_col__",value:u,colDef:{field:"__expand_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(bn,{isExpanded:u,onClick:J,variant:"plus-minus"})}),s&&r.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${N?"ogx__cell--pinned-left":""} ${$==="__checkbox_col__"?"ogx__cell--focused":""} ${$==="__checkbox_col__"&&O?"ogx__cell--focus-visible":""}`,role:"gridcell",style:{position:N?"sticky":void 0,left:N?(v?48:0)+(m&&y?48:0):void 0,zIndex:N?11:void 0},ref:P,tabIndex:-1,onClick:Y=>{Y.stopPropagation(),a?.({row:t,field:"__checkbox_col__",value:i,colDef:{field:"__checkbox_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(ft,{id:K,name:`ogx-select-row-${t.id}`,checked:i,onChange:A,onClick:Y=>Y.stopPropagation(),"aria-label":i?`Deselect row ${t.id}`:`Select row ${t.id}`,tabIndex:-1,onMouseDown:Y=>Y.preventDefault()})}),e.map((Y,Q)=>{if(Y.isSpacer)return r.jsx("div",{style:{width:Y.width,minWidth:Y.width,flexShrink:0},"aria-hidden":"true"},Y.field);const le=Y.valueGetter?Y.valueGetter({row:t,field:Y.field,value:t[Y.field]}):t[Y.field],B=c[Y.field]??Y.width,X=ut(Y.field,f),te=X?W[Y.field]:void 0,ce=I?.id===t.id&&I?.field===Y.field,ge=ce?I?.value:le,Pe=H?.get(t.id)?.[Y.field],$e=F?.spannedCells[t.id]?.[Y.field],Ie=F?.hiddenCells[t.id]?.[Y.field]||!1;return r.jsx(Sn,{value:ge,row:t,colDef:Y,rowIndex:o,colIndex:Q,isSelected:i,onCellClick:a,width:B,pinnedPosition:X,pinnedOffset:te,isFocused:$===Y.field,isFocusVisible:O,isEditable:Y.editable,isEditing:ce,onCellEditStart:z,onEditStop:G,onCellValueChange:U,colSpanInfo:Pe,rowSpan:$e,isHiddenByRowSpan:Ie,rowMeta:q},Y.field)})]}),m&&r.jsx(pr,{row:t,rowId:t.id,rowIndex:o,content:g,height:k,isExpanded:u})]})}function jn({rows:n,position:t,columns:e,selectedRowIds:o,checkboxSelection:i,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:p,pinnedColumns:c,pinnedRows:f,hasDetailPanel:w,expandedRowIds:m,getDetailPanelContent:u,getDetailPanelHeight:x,onDetailPanelToggle:g,pinCheckboxColumn:k,pinExpandColumn:N,focusedCell:y,colspanMap:v,rowSpanningCaches:j,rowHeight:b,rowMetaMap:S}){return n.length===0?null:r.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:n.map((h,E)=>r.jsx(Mt,{row:h,columns:e,rowIndex:E,isSelected:o.has(h.id),checkboxSelection:i,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:p,pinnedColumns:c,pinnedRows:f,hasDetailPanel:w,isDetailPanelExpanded:m.has(h.id),detailPanelContent:u?u({row:h,id:h.id,rowIndex:E}):null,detailPanelHeight:x?.({row:h,id:h.id,rowIndex:E})||200,onDetailPanelToggle:g,pinCheckboxColumn:k,pinExpandColumn:N,focusedCellField:y?.id===h.id?y.field:null,colspanMap:v,rowSpanningCaches:j,rowHeight:b,rowMeta:S.get(h.id)},h.id))})}const xr=({columns:n,rowHeight:t,checkboxSelection:e=!1,hasDetailPanel:o=!1,rowReordering:i=!1})=>r.jsxs("div",{className:"ogx__row ogx__skeleton-row",style:{height:t},role:"row",children:[e&&r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:r.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),o&&r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:r.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),i&&r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:r.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),n.map((s,d)=>{const a=typeof s.width=="number"?s.width:150,p=Math.min(a*.7,a-20);return r.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:a,minWidth:s.minWidth,maxWidth:s.maxWidth,left:s.left,right:s.right,position:s.isSpacer?"relative":s.pinned?"sticky":"relative",zIndex:s.zIndex},children:!s.isSpacer&&r.jsx("div",{className:"ogx-skeleton-box",style:{width:p,height:16,borderRadius:4}})},s.field||d)})]});function mr({virtualContainerHeight:n,offsetTop:t,effectiveLoading:e,visibleRows:o,baseColumns:i,virtualColumns:s,viewportWidth:d,checkboxSelection:a,hasDetailPanel:p,rowReordering:c,rowHeight:f,pinnedRows:w,selectedRowIds:m,onRowClick:u,onCellClick:x,onSelectionChange:g,columnWidths:k,pinnedColumns:N,expandedRowIds:y,getDetailPanelContent:v,getDetailPanelHeight:j,onDetailPanelToggle:b,pinCheckboxColumn:S,pinExpandColumn:h,rowReorderHandlers:E,editingHandlers:M,focusedCell:I,colspanMap:_,rowSpanningCaches:T,paginationMode:L,dataSourceLoading:$,sortedUnpinnedRowCount:O,infiniteScrollSkeletonCount:H,unpinnedRowsLength:F,rowMetaMap:D}){const q=i.length>0?i:(()=>{const C=(d||1e3)-(a?48:0)-(p?48:0)-(c?48:0),P=150,W=Math.max(1,Math.ceil(C/P));return Array.from({length:W},(R,z)=>({field:`placeholder_${z}`,headerName:"",width:P}))})(),K=o.filter(({row:C})=>!Gt(C.id,w)).filter((C,P,W)=>P===W.findIndex(R=>R.row.id===C.row.id));return r.jsx("div",{className:"ogx__virtual-container",style:{height:`${n}px`},role:"presentation",children:r.jsxs("div",{className:"ogx__rows",style:{transform:`translateY(${t}px)`},role:"rowgroup",children:[e&&o.length===0?Array.from({length:10}).map((C,P)=>r.jsx(xr,{columns:q,rowHeight:f,checkboxSelection:a,hasDetailPanel:p,rowReordering:c},`skeleton-${P}`)):K.map(({row:C,rowIndex:P})=>r.jsx(Mt,{row:C,columns:s,rowIndex:P,isSelected:m.has(C.id),checkboxSelection:a,onRowClick:u,onCellClick:x,onSelectionChange:g,columnWidths:k,pinnedColumns:N,pinnedRows:w,hasDetailPanel:p,isDetailPanelExpanded:y.has(C.id),detailPanelContent:v?v({row:C,id:C.id,rowIndex:P}):null,detailPanelHeight:j?.({row:C,id:C.id,rowIndex:P})||200,onDetailPanelToggle:b,pinCheckboxColumn:S,pinExpandColumn:h,rowReordering:c,onDragStart:E.onDragStart,onDragOver:E.onDragOver,onDragEnd:E.onDragEnd,onDrop:E.onDrop,isDragging:E.draggedRowId===C.id,isDragOver:E.dragOverRowId===C.id,editingCell:M.editingCell,onEditStart:M.startCellEdit,onEditStop:M.stopCellEdit,onEditCellValueChange:M.setEditCellValue,focusedCellField:I!=null&&I.id===C.id?I.field:null,colspanMap:_,rowSpanningCaches:T,rowHeight:f,rowMeta:D.get(C.id)},C.id)),L==="infinite"&&$&&O>0&&r.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:H}).map((C,P)=>r.jsx(Mt,{row:{id:`__skeleton_${P}__`,_isSkeleton:!0},columns:s,rowIndex:F+P,rowHeight:f},`__skeleton_${P}__`))})]})})}function br(){return r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function wr(){return r.jsxs("svg",{className:"ogx-column-visibility-panel__drag-handle",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[r.jsx("circle",{cx:"9",cy:"5",r:"1.5"}),r.jsx("circle",{cx:"15",cy:"5",r:"1.5"}),r.jsx("circle",{cx:"9",cy:"12",r:"1.5"}),r.jsx("circle",{cx:"15",cy:"12",r:"1.5"}),r.jsx("circle",{cx:"9",cy:"19",r:"1.5"}),r.jsx("circle",{cx:"15",cy:"19",r:"1.5"})]})}function En(n){const{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:i,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,showNonHideableColumns:p}=n,[c,f]=l.useState(""),[w,m]=l.useState(null),u=l.useRef(null),x=l.useMemo(()=>t.filter(h=>h.hideable!==!1),[t]),g=x.every(h=>e.has(h.field)),k=l.useMemo(()=>{const h=p?t:x;if(!c)return h;const E=c.toLowerCase();return h.filter(M=>(M.headerName||M.field).toLowerCase().includes(E))},[t,x,c,p]),N=h=>{h.target.checked?i():s()},y=h=>E=>{u.current=h,E.dataTransfer.effectAllowed="move",E.dataTransfer.setDragImage(E.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},v=h=>E=>{E.preventDefault(),E.dataTransfer.dropEffect="move",h!==u.current&&m(h)},j=()=>{m(null)},b=h=>E=>{E.preventDefault();const M=u.current;m(null),u.current=null,M&&M!==h&&d&&d(M,h)},S=()=>{m(null),u.current=null};return r.jsxs("div",{className:"ogx-column-visibility-panel",children:[r.jsx("div",{className:"ogx-column-visibility-panel__search-section",children:r.jsxs("div",{className:"ogx-column-visibility-panel__search-container",children:[r.jsx(br,{}),r.jsx("input",{autoComplete:"off",className:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:c,onChange:h=>f(h.target.value)})]})}),r.jsx("div",{className:"ogx-column-visibility-panel__list",children:k.map(h=>{const E=e.has(h.field),M=h.hideable!==!1,I=w===h.field,_=!!d&&!c;return r.jsxs("div",{className:["ogx-column-visibility-panel__item",!M&&"ogx-column-visibility-panel__item--disabled",I&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:_,onDragOver:_?v(h.field):void 0,onDragLeave:_?j:void 0,onDrop:_?b(h.field):void 0,onDragEnd:_?S:void 0,children:[_&&r.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:y(h.field),title:"Drag to reorder",children:r.jsx(wr,{})}),r.jsxs("label",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:M?"pointer":"not-allowed"},children:[r.jsx(ft,{checked:E,onChange:T=>o(h.field,T.target.checked),disabled:!M}),r.jsx("span",{className:"ogx-column-visibility-panel__label",children:h.headerName||h.field})]})]},h.field)})}),r.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[r.jsxs("label",{className:"ogx-column-visibility-panel__item",children:[r.jsx(ft,{checked:g,onChange:N}),r.jsx("span",{className:"ogx-column-visibility-panel__label",children:"Show/Hide All"})]}),r.jsx("button",{className:"ogx-column-visibility-panel__reset-btn",onClick:()=>{i(),a?.()},children:"Reset"})]})]})}function vr({isOpen:n,containerRef:t,panelRef:e,effectiveColumns:o,columnVisibilityModel:i,effectiveColumnOrder:s,columnOrder:d,disableColumnReorder:a,onClose:p,onColumnVisibilityChange:c,onColumnOrderChange:f,setInternalColumnOrder:w}){const[m,u]=l.useState(16),[x,g]=l.useState(16),[k,N]=l.useState(()=>document.body);if(l.useLayoutEffect(()=>{if(!n||!t.current)return;const v=t.current.getBoundingClientRect();u(v.top+8),g(window.innerWidth-v.right+8),N(t.current.closest(".ogx-theme-provider")||document.body)},[n,t]),!n)return null;const y=a?void 0:(v,j)=>{const b=[...s],S=b.indexOf(v),h=b.indexOf(j);if(S===-1||h===-1)return;const E=[...b];E.splice(S,1),E.splice(h,0,v),d||w(E),f?.({oldIndex:S,targetIndex:h,column:o.find(M=>M.field===v)})};return He.createPortal(r.jsxs("div",{ref:e,style:{position:"fixed",top:m,right:x,zIndex:9999,display:"inline-block"},children:[r.jsx("button",{onClick:p,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:"×"}),r.jsx(En,{columns:o,visibleColumns:new Set(o.filter(v=>i[v.field]!==!1).map(v=>v.field)),onVisibilityChange:(v,j)=>{c({...i,[v]:j})},onShowAll:()=>{const v={...i};o.forEach(j=>{j.hideable!==!1&&(v[j.field]=!0)}),c(v)},onHideAll:()=>{const v={...i};o.forEach(j=>{j.hideable!==!1&&(v[j.field]=!1)}),c(v)},onColumnReorder:y})]}),k)}const _r=new Map;function Cr(n){const{rows:t,columns:e,getRowId:o,rowHeight:i=52,headerHeight:s=56,autoHeight:d=!1,checkboxSelection:a=!1,rowSelectionModel:p,onRowSelectionModelChange:c,onRowClick:f,onCellClick:w,filterModel:m,onFilterModelChange:u,sortModel:x,onSortModelChange:g,pagination:k=!1,paginationModel:N={page:0,pageSize:100},onPaginationModelChange:y,pageSizeOptions:v=[10,25,50,100],pinnedColumns:j,onPinnedColumnsChange:b,pinnedRows:S,getDetailPanelContent:h,getDetailPanelHeight:E,detailPanelExpandedRowIds:M,onDetailPanelExpandedRowIdsChange:I,pinCheckboxColumn:_=!0,pinExpandColumn:T=!0,disableColumnReorder:L=!1,columnOrder:$,onColumnOrderChange:O,height:H,rowReordering:F=!1,onRowOrderChange:D,loading:q=!1,treeData:K=!1,getTreeDataPath:C,defaultGroupingExpansionDepth:P,rowGroupingModel:W,aggregationModel:R,onAggregationModelChange:z,getAggregationPosition:U,isCellEditable:G,processRowUpdate:ne,onProcessRowUpdateError:A,dataSource:J,sortingMode:ee="client",filterMode:se="client",paginationMode:re="client",rowCount:ve,slots:Y,slotProps:Q,pivotMode:le=!1,pivotModel:B,onPivotModelChange:X,className:te="",style:ce,onRowsScrollEnd:ge,ariaLabel:Pe,initialState:$e,onStateChange:Ie,columnVisibilityModel:pe,onColumnVisibilityModelChange:Je,listView:oe=!1,listViewColumn:ye,columnGroupingModel:Ge,noRowsLabel:fi="No Data",localeText:Te,apiRef:qt}=n,Xt=Te?.noRowsLabel??fi,gi=l.useMemo(()=>({items:[]}),[]),Ne=m||gi,hi=l.useMemo(()=>[],[]),Jt=W||hi,Wn=l.useRef(Y?.toolbar);Wn.current=Y?.toolbar;const pi=l.useRef(V=>{const Z=Wn.current;return Z?Z(V):null}).current,xi=ao({initialState:$e,sortModel:x,aggregationModel:R,onAggregationModelChange:z,columnVisibilityModel:pe,onColumnVisibilityModelChange:Je,pinnedColumns:j,onPinnedColumnsChange:b,pivotModel:B,onPivotModelChange:X,paginationModel:N,onPaginationModelChange:y,rowSelectionModel:p}),{sortModel:ze,isSortControlled:An,setInternalSortModel:$n,aggregationModel:Me,handleAggregationModelChange:zn,columnVisibilityModel:Ve,handleColumnVisibilityModelChange:Pt,pinnedColumns:Re,handlePinnedColumnsChange:Qt,currentPivotModel:Zt,handlePivotModelChange:Bn,effectivePaginationModel:Se,handlePaginationModelChange:en,selectedRowIds:ke,isSelectionControlled:It,setInternalRowSelectionModel:Tt}=xi,Rt=c,Lt=kn(t,e,Zt,le),Dn=le&&Lt.isValid?Lt.pivotRows:t,tn=le&&Lt.isValid?Lt.pivotColumns:e,[mi,Hn]=l.useState(null);l.useEffect(()=>{Hn(null)},[Me]);const Qe=l.useRef(null),bi=l.useRef(null),Ft=l.useRef(null),wi=l.useCallback(V=>V.id,[]),Ze=o||wi,nn=l.useMemo(()=>Dn.map(V=>{const Z=Ze(V);return Z===V.id?V:{...V,id:Z}}),[Dn,Ze]),et=l.useCallback(V=>{gn.current?.classList.toggle("ogx--kb",V)},[]),Gn=l.useRef(J);Gn.current=J;const Vn=l.useRef(null),Un=l.useRef(null),vi=l.useCallback(V=>{if(Gn.current&&K&&(V.serverChildrenCount??0)>0&&(V.children??[]).length===0){const Z=Un.current?.getNodePath(V.id)||[V.groupingKey];Vn.current?.(V.id,Z)}},[K]),Ce=Ho({rows:nn,columns:tn,rowHeight:i,headerHeight:s,rowCount:ve,columnVisibilityModel:Ve,initialState:n.initialState}),{state:he,apiRef:tt,setRows:on,setColumns:_i,setDimensions:Kn,setDataSourceLoading:Ci,setDataSourceError:yi,setRowCount:ki}=Ce,{scrollTop:Si,scrollLeft:ji,handleScroll:Ei}=_o({onRowsScrollEnd:ge});l.useEffect(()=>{qt&&(qt.current=tt.current)},[qt,tt]);const{copySelectedRows:Yn}=nr({selectedRowIds:ke,columns:tn,getVisibleRows:()=>tt.current.getVisibleRows(),getRowId:Ze});l.useEffect(()=>{tt.current.copySelectedRows=Yn,tt.current.getSelectedRows=()=>Array.from(ke)},[Yn,ke,tt]);const Ni=he.dataSource.loading,xt=q||Ni,nt=l.useMemo(()=>he.rows.allRows.map(V=>he.rows.idRowsLookup.get(V)),[he.rows]),mt=Vo({rows:nt,getRowId:Ze,getTreeDataPath:C,treeData:K,defaultGroupingExpansionDepth:P,filterModel:Ne,sortModel:ze,onRowExpansionChange:vi});l.useEffect(()=>{Un.current=mt},[mt]);const bt=qo({rows:nt,getRowId:Ze,rowGroupingModel:Jt,aggregationModel:Me,defaultGroupingExpansionDepth:P,filterModel:Ne,sortModel:ze,getAggregationPosition:U}),ot=Xo({rows:nt,getRowId:Ze,processRowUpdate:ne,onProcessRowUpdateError:A,onRowChange:V=>{const{dispatch:Z}=Ce,de=Array.from(Ce.state.rows.idRowsLookup.values()).map(fe=>fe.id===V.id?V:fe);Z({type:"SET_ROWS",payload:de})}}),wt=K,Be=!!(Jt&&Jt.length>0),rn=wt||Be,Ot=wt?mt:Be?bt:null,vt=l.useMemo(()=>wt?mt.rowMetaMap:Be?bt.rowMetaMap:_r,[wt,mt.rowMetaMap,Be,bt.rowMetaMap]),Le=k&&!Be,Wt=l.useCallback(V=>{const{row:Z,id:ae}=V;if(rn&&vt.get(Z.id)?.hasChildren){Ot?.toggleExpansion(ae);return}f?.(V)},[rn,Ot,f,vt]),ln=Qo({dataSource:J,sortModel:ze,filterModel:Ne,paginationModel:Se,paginationMode:re,sortingMode:ee,filterMode:se,aggregationModel:Me,setRows:on,setRowCount:ki,setDataSourceLoading:Ci,setDataSourceError:yi,onAggregationResults:Hn});l.useEffect(()=>{ln.fetchChildren&&(Vn.current=ln.fetchChildren)},[ln.fetchChildren]),l.useEffect(()=>{J||on(nn)},[nn,on,J]);const Fe=!!h,[Mi,Pi]=l.useState(new Set),rt=M??Mi,At=l.useCallback(V=>{const Z=new Set(rt);Z.has(V)?Z.delete(V):Z.add(V),M===void 0&&Pi(Z),I?.(Z)},[rt,M,I]),{effectiveColumns:De,orderedColumns:sn,visibleOrderedColumns:Ii,navigationColumns:qn,columnWidths:Oe,effectiveColumnOrder:$t,setInternalColumnOrder:zt,columnReorderHandlers:it,handleColumnResize:Ti}=wo({activeColumns:tn,isHierarchyEnabled:rn,isRowGrouping:Be,isTreeData:wt,activeHierarchyHandlers:Ot,columnVisibilityModel:Ve,columnOrder:$,onColumnOrderChange:O,disableColumnReorder:L,pivotMode:le,checkboxSelection:a,hasDetailPanel:Fe,rowReordering:F,initialState:$e,setColumns:_i});Co({onStateChange:Ie,sortModel:ze,filterModel:Ne,effectivePaginationModel:Se,columnWidths:Oe,effectiveColumnOrder:$t,columnVisibilityModel:Ve,pinnedColumns:Re});const lt=xo({effectiveRows:nt,activeHierarchyHandlers:Ot,filterMode:se,filterModel:Ne,dataSource:J,sortModel:ze,sortingMode:ee,pagination:Le,paginationMode:re,effectivePaginationModel:Se,pinnedRows:S,isLoading:he.dataSource.loading,pageSize:Se.pageSize}),Ue=lt.filteredRows,an=lt.pinnedTopRows,dn=lt.pinnedBottomRows,We=lt.sortedUnpinnedRows,_t=lt.paginatedUnpinnedRows,cn=lt.allRenderableRows;l.useEffect(()=>{Ce.apiRef.current.getVisibleRows=()=>Le?_t:We,Ce.apiRef.current.getAllFilteredRows=()=>We,Ce.apiRef.current.getVisibleColumns=()=>De},[We,_t,Le,De,Ce.apiRef]);const Ri=Go({rows:Le?_t:We,getRowId:V=>V.id,onRowOrderChange:D,rowReordering:F}),st=Jo(cn,qn,Oe),{aggregationResult:Ct}=wn({rows:Ue,aggregationModel:Me,isServerSide:!!(J&&(re==="server"||ee==="server")),dataSource:J,filterModel:Ne,sortModel:ze,serverAggregationResults:mi}),at=Object.keys(Me).length>0;l.useEffect(()=>{Ce.apiRef.current.getAggregationResult=()=>at?Ct:null,Ce.apiRef.current.getAggregationModel=()=>at?Me:null,Ce.apiRef.current.getGroupedExportRows=()=>{if(!Be)return null;const{treeNodes:V,groupingRows:Z}=bt,ae=new Map;We.forEach(ue=>ae.set(ue.id,ue));const de=[],fe=ue=>{ue.forEach(me=>{const be=V.get(me);if(!be)return;if(!!(be.children&&be.children.length>0))de.push({type:"group-header",depth:be.depth,groupField:be.groupingField,groupValue:be.groupingValue}),fe(be.children),at&&be.aggregatedValues&&de.push({type:"group-subtotal",depth:be.depth,groupField:be.groupingField,groupValue:be.groupingValue,aggregatedValues:be.aggregatedValues});else{const jt=ae.get(me)??Z.get(me);jt&&de.push({type:"leaf",depth:be.depth,row:jt})}})};return fe(Array.from(V.keys()).filter(ue=>V.get(ue)?.parentId===null)),at&&Ct&&de.push({type:"grand-total",depth:0,aggregatedValues:Ct}),de}},[Ct,Me,at,Ce.apiRef,Be,bt,We]);const xe=io({rowHeight:i,pagination:Le,paginatedUnpinnedRows:_t,sortedUnpinnedRows:We,expandedRowIds:rt,getDetailPanelHeight:E,pinnedTopRowsLength:an.length,pinnedBottomRowsLength:dn.length,visibleOrderedColumns:Ii,pinnedColumns:Re,columnWidths:Oe,viewportWidth:he.dimensions.viewportWidth||1e3,checkboxSelection:a,hasDetailPanel:Fe,rowReordering:F,paginationMode:re,isLoading:he.dataSource.loading,pageSize:Se.pageSize}),Li=l.useMemo(()=>{const V={};for(const Z of[...xe.leftPinnedCols,...xe.unpinnedColsWithWidth,...xe.rightPinnedCols])Z.isSpacer||(V[Z.field]=Z.width);return{...V,...Oe}},[xe.leftPinnedCols,xe.unpinnedColsWithWidth,xe.rightPinnedCols,Oe]);l.useEffect(()=>{Ce.apiRef.current.scrollToIndexes=({rowIndex:V,colIndex:Z})=>{const ae=Qe.current;if(ae){if(V!==void 0&&V>=0){const de=V>0?xe.cumulativeHeights[V-1]:0,fe=xe.cumulativeHeights[V]??de,{scrollTop:ue,clientHeight:me}=ae;de<ue?ae.scrollTop=de:fe>ue+me&&(ae.scrollTop=fe-me)}if(Z!==void 0&&Z>=0){const fe=[...xe.leftPinnedCols,...xe.unpinnedColsWithWidth,...xe.rightPinnedCols][Z];if(!fe)return;const ue=xe.unpinnedColsWithWidth.findIndex(Hi=>Hi.field===fe.field);if(ue===-1)return;const me=ue>0?xe.unpinnedAccWidths[ue-1]:0,be=xe.unpinnedAccWidths[ue]??me,St=xe.leftWidth+be,{scrollLeft:jt,clientWidth:Zn}=ae;me<jt?ae.scrollLeft=me:St>jt+Zn&&(ae.scrollLeft=St-Zn)}}}},[xe,Qe,Ce.apiRef]);const je=mo({layout:xe,scrollTop:Si,scrollLeft:ji,viewportWidth:he.dimensions.viewportWidth,viewportHeight:he.dimensions.viewportHeight,autoHeight:d,rowReordering:F,hasDetailPanel:Fe,checkboxSelection:a,pinCheckboxColumn:_,pinExpandColumn:T});l.useEffect(()=>{if(!Qe.current)return;const V=new ResizeObserver(Z=>{for(const ae of Z){const{width:de,height:fe}=ae.contentRect;Kn(de,fe)}});return V.observe(Qe.current),()=>{V.disconnect()}},[Kn]);const yt=l.useCallback((V,Z)=>{const ae=new Set(ke);Z?ae.add(V):ae.delete(V);const de=Array.from(ae);It||Tt(de),Rt?.(de)},[ke,It,Rt,Tt]),Fi=l.useCallback(V=>{let Z=[];V&&(Z=nt.map(ae=>ae.id)),It||Tt(Z),Rt?.(Z)},[nt,It,Rt,Tt]),Xn=l.useCallback((V,Z)=>{const ae=Z?[{field:V,sort:Z}]:[];An||$n(ae),g?.(ae)},[An,g,$n]),{focusedCell:Bt,setFocusedCell:un,handleFocus:Oi,handleBlur:Wi,handleKeyDown:Ai}=lo({allRenderableRows:cn,navigationColumns:qn,checkboxSelection:a,selectedRowIds:ke,handleSelectionChange:yt,handleDetailPanelToggle:At,editingHandlers:ot,setKeyboardMode:et,sortModel:ze,handleSort:Xn,isCellEditable:G,pagination:Le,pageSize:Se.pageSize,virtualization:je,viewportRef:Qe}),fn=l.useCallback(V=>{et(!1),un({id:V.row.id,field:V.field}),Ft.current?.focus({preventScroll:!0}),w?.(V)},[w,et,un]),Jn=l.useRef(ot.editingCell);l.useEffect(()=>{const V=!!Jn.current,Z=!!ot.editingCell;V&&!Z&&Ft.current?.focus({preventScroll:!0}),Jn.current=ot.editingCell},[ot.editingCell]);const $i=vo({renderContext:je.renderContext,pinnedTopRows:an,pinnedBottomRows:dn,paginatedUnpinnedRows:_t,sortedUnpinnedRows:We,pagination:Le}),zi=t.length>0&&ke.size===t.length,Bi=ke.size>0&&ke.size<t.length,Di=l.useMemo(()=>De.some(V=>!!V.rowSpan),[De]),[kt,Dt]=l.useState(!1),gn=l.useRef(null),hn=l.useRef(null),Qn=l.useMemo(()=>{if(!Y?.toolbar)return null;const V=L?void 0:(Z,ae)=>{const de=[...$t],fe=de.indexOf(Z),ue=de.indexOf(ae);if(fe===-1||ue===-1)return;const me=[...de];me.splice(fe,1),me.splice(ue,0,Z),$||zt(me);const be=De.find(St=>St.field===Z);be&&O?.({oldIndex:fe,targetIndex:ue,column:be})};return{apiRef:Ce.apiRef,columns:sn,baseColumns:e,aggregationModel:Me,onAggregationModelChange:zn,...le||B||X?{pivotModel:Zt,onPivotModelChange:Bn}:{},filterModel:Ne,onFilterModelChange:u,columnVisibilityModel:Ve,onColumnVisibilityModelChange:Pt,onColumnReorder:V,onColumnOrderReset:L?void 0:()=>zt(e.map(Z=>Z.field)),forceColumnsOpen:kt,onColumnsPanelClose:()=>Dt(!1),...Q?.toolbar}},[Y?.toolbar,L,$t,sn,De,$,O,zt,Ce.apiRef,e,Me,zn,le,B,X,Zt,Bn,Ne,u,Ve,Pt,kt,Q?.toolbar]);return l.useEffect(()=>{if(!kt||Y?.toolbar)return;function V(Z){hn.current&&!hn.current.contains(Z.target)&&Dt(!1)}return document.addEventListener("mousedown",V),()=>document.removeEventListener("mousedown",V)},[kt,Y?.toolbar]),r.jsxs("div",{ref:gn,className:["ogx",te,d&&"ogx--auto-height",Di&&"ogx--row-spanning",oe&&"ogx--list-view"].filter(Boolean).join(" "),style:{...ce,height:H??ce?.height,"--ogx-row-height":`${i}px`,"--ogx-header-height":`${s}px`},"aria-busy":xt,children:[Qn&&r.jsx(pi,{...Qn}),!Y?.toolbar&&r.jsx(vr,{isOpen:kt,containerRef:gn,panelRef:hn,effectiveColumns:De,columnVisibilityModel:Ve,effectiveColumnOrder:$t,columnOrder:$,disableColumnReorder:L,onClose:()=>Dt(!1),onColumnVisibilityChange:Pt,onColumnOrderChange:O,setInternalColumnOrder:zt}),oe&&ye&&r.jsx(rr,{ariaLabel:Pe,allRenderableRows:cn,filteredRows:Ue,pagination:Le,effectivePaginationModel:Se,pageSizeOptions:v,selectedRowIds:ke,listViewColumn:ye,noRowsLabel:Xt,rowHeight:i,checkboxSelection:a,paginationMode:re,dataSource:J,serverRowCount:he.pagination.rowCount||0,paginationSlot:Y?.pagination,paginationSlotProps:Q?.pagination,localeText:Te?{paginationRowsPerPage:Te.paginationRowsPerPage,paginationOf:Te.paginationOf,paginationPage:Te.paginationPage}:void 0,onRowClick:Wt,onSelectionChange:yt,onPaginationModelChange:en}),!oe&&r.jsx("div",{ref:V=>{Qe.current=V,Ft.current=V},className:"ogx__viewport",onScroll:Ei,role:"grid","aria-label":Pe||"Data grid","aria-rowcount":Ue.length+1,"aria-colcount":e.length+(a?1:0)+(Fe?1:0)+(F?1:0),"aria-busy":xt,tabIndex:0,onKeyDownCapture:()=>{et(!0)},onMouseDownCapture:()=>{et(!1)},onKeyDown:Ai,onFocus:Oi,onBlur:Wi,children:r.jsxs("div",{ref:bi,className:"ogx__content",style:{width:je.totalWidth},role:"presentation",children:[r.jsx(_n,{columns:je.virtualColumns,allColumns:De,columnGroupingModel:Ge,checkboxSelection:a,allSelected:zi,someSelected:Bi,onSelectAll:Fi,sortModel:ze,onSort:Xn,onColumnResize:Ti,columnWidths:Oe,pinnedColumns:Re,focusedCell:Bt,onHeaderClick:V=>{un({id:"HEADER",field:V}),et(!1),Ft.current?.focus({preventScroll:!0})},onDragStart:Ge?void 0:it.onDragStart,onDragOver:Ge?void 0:it.onDragOver,onDragEnd:Ge?void 0:it.onDragEnd,onDrop:Ge?void 0:it.onDrop,draggedColumn:Ge?void 0:it.draggedColumn,dragOverColumn:Ge?void 0:it.dragOverColumn,rowReordering:F,hasDetailPanel:Fe,pinCheckboxColumn:_,pinExpandColumn:T,aggregationModel:Me,onHideColumn:V=>{Pt({...Ve,[V]:!1})},onManageColumns:()=>Dt(!0),onPinColumn:(V,Z)=>{const ae=[...Re?.left??[]],de=[...Re?.right??[]],fe=ae.filter(me=>me!==V),ue=de.filter(me=>me!==V);Qt(Z==="left"?{left:[...fe,V],right:ue}:Z==="right"?{left:fe,right:[...ue,V]}:{left:fe,right:ue})}}),!xt&&!he.dataSource.error&&Ue.length===0&&r.jsx(So,{noRowsLabel:Xt,width:je.totalWidth}),r.jsx(jn,{rows:an,position:"top",columns:je.virtualColumns,selectedRowIds:ke,checkboxSelection:a,onRowClick:Wt,onCellClick:fn,onSelectionChange:yt,columnWidths:Oe,pinnedColumns:Re,pinnedRows:S,hasDetailPanel:Fe,expandedRowIds:rt,getDetailPanelContent:h,getDetailPanelHeight:E,onDetailPanelToggle:At,pinCheckboxColumn:_,pinExpandColumn:T,focusedCell:Bt,colspanMap:st.colspanMap,rowSpanningCaches:st.rowSpanningState.caches,rowHeight:i,rowMetaMap:vt}),r.jsx(mr,{virtualContainerHeight:je.totalHeight-je.pinnedTopHeight-je.pinnedBottomHeight,offsetTop:je.offsetTop,effectiveLoading:xt,visibleRows:$i,baseColumns:e,virtualColumns:je.virtualColumns,viewportWidth:he.dimensions.viewportWidth,checkboxSelection:a,hasDetailPanel:Fe,rowReordering:F,rowHeight:i,pinnedRows:S,selectedRowIds:ke,onRowClick:Wt,onCellClick:fn,onSelectionChange:yt,columnWidths:Oe,pinnedColumns:Re,expandedRowIds:rt,getDetailPanelContent:h,getDetailPanelHeight:E,onDetailPanelToggle:At,pinCheckboxColumn:_,pinExpandColumn:T,rowReorderHandlers:Ri,editingHandlers:ot,focusedCell:Bt,colspanMap:st.colspanMap,rowSpanningCaches:st.rowSpanningState.caches,paginationMode:re,dataSourceLoading:he.dataSource.loading,sortedUnpinnedRowCount:We.length,infiniteScrollSkeletonCount:Math.min(Se.pageSize,20),unpinnedRowsLength:xe.unpinnedRowsLength,rowMetaMap:vt}),r.jsx(jn,{rows:dn,position:"bottom",columns:je.virtualColumns,selectedRowIds:ke,checkboxSelection:a,onRowClick:Wt,onCellClick:fn,onSelectionChange:yt,columnWidths:Oe,pinnedColumns:Re,pinnedRows:S,hasDetailPanel:Fe,expandedRowIds:rt,getDetailPanelContent:h,getDetailPanelHeight:E,onDetailPanelToggle:At,pinCheckboxColumn:_,pinExpandColumn:T,focusedCell:Bt,colspanMap:st.colspanMap,rowSpanningCaches:st.rowSpanningState.caches,rowHeight:i,rowMetaMap:vt}),at&&!le&&r.jsx(ko,{columns:sn,aggregationModel:Me,aggregationResult:Ct,columnWidths:Li,rowHeight:i,checkboxSelection:a,hasDetailPanel:Fe,rowReordering:F,pinnedColumns:Re})]})}),!oe&&Le&&(()=>{const V=Y?.pagination||Cn;return r.jsx(V,{page:Se.page,pageSize:Se.pageSize,rowCount:he.pagination.rowCount,pageSizeOptions:v,onPageChange:Z=>en({...Se,page:Z}),onPageSizeChange:Z=>en({...Se,pageSize:Z,page:0}),localeText:Te?{paginationRowsPerPage:Te.paginationRowsPerPage,paginationOf:Te.paginationOf,paginationPage:Te.paginationPage}:void 0,...Q?.pagination})})(),r.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[xt?"Loading data...":"",he.dataSource.error?`Error: ${he.dataSource.error instanceof Error?he.dataSource.error.message:"Unknown error"}`:"",!q&&!he.dataSource.error&&(Ue.length===0?Xt:Ne&&((Ne.quickFilterValues?.length||0)>0||(Ne.items?.length||0)>0)?`${Ue.length} ${Ue.length===1?"row":"rows"} found`:"")]}),r.jsx(jo,{error:he.dataSource.error})]})}function yr({rows:n=5,columns:t=5}){return r.jsx("div",{className:"ogx__skeleton",children:Array.from({length:n}).map((e,o)=>r.jsx("div",{className:"ogx__skeleton-row",children:Array.from({length:t}).map((i,s)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-content"})},s))},o))})}const Nn=new Set(["isEmpty","isNotEmpty"]);function kr(n,t){return n.find(e=>"field"in e&&e.field===t)}const Sr=({col:n,item:t,onChange:e})=>{const o=l.useId(),i=ho(n.type),s=!!t,d=t?.operator??i[0],[a,p]=l.useState(t?.value!=null?String(t.value):""),c=l.useRef(e),f=l.useRef(t),w=l.useRef(n.field),m=l.useRef(d);l.useLayoutEffect(()=>{c.current=e,f.current=t,w.current=n.field,m.current=d});const u=l.useRef(t?.value);l.useEffect(()=>{t?.value!==u.current&&(u.current=t?.value,p(t?.value!=null?String(t.value):""))},[t?.value]),l.useEffect(()=>{const v=setTimeout(()=>{const j=f.current,b=j?.value??"";a!==b&&c.current({id:j?.id??`${w.current}-${Date.now()}`,field:w.current,operator:m.current,value:a})},300);return()=>clearTimeout(v)},[a]);const x=v=>{const j=Nn.has(v),b={id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:v,value:j?void 0:t?.value??(n.type==="boolean"?"true":"")};e(b)},g=()=>{p(""),e(null)},k=Nn.has(String(d)),N=n.type==="boolean",y=!k;return r.jsxs("div",{className:`ogx-filter__row${s?" ogx-filter__row--active":""}`,children:[r.jsx("span",{className:"ogx-filter__col-label",title:n.field,children:n.headerName||n.field}),r.jsxs("div",{className:"ogx-filter__controls",children:[r.jsx("select",{id:`${o}-op`,name:`filter-op-${n.field}`,className:`ogx-filter__op-select${s?" ogx-filter__op-select--active":""}`,value:String(d),onChange:v=>x(v.target.value),"aria-label":`Filter operator for ${n.headerName||n.field}`,children:i.map(v=>r.jsx("option",{value:v,children:v},v))}),y&&N&&r.jsxs("select",{id:`${o}-val`,name:`filter-val-${n.field}`,className:`ogx-filter__value-input ogx-filter__value-select${s?" ogx-filter__value-input--active":""}`,value:String(t?.value??"true"),onChange:v=>{p(v.target.value),e({id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:d,value:v.target.value})},"aria-label":`Filter value for ${n.headerName||n.field}`,children:[r.jsx("option",{value:"true",children:"true"}),r.jsx("option",{value:"false",children:"false"})]}),y&&!N&&r.jsx("input",{id:`${o}-val`,name:`filter-val-${n.field}`,className:`ogx-filter__value-input${s?" ogx-filter__value-input--active":""}`,type:"text",value:a,onChange:v=>p(v.target.value),placeholder:n.type==="number"?"Number…":"Value…","aria-label":`Filter value for ${n.headerName||n.field}`}),s&&r.jsx("button",{className:"ogx-filter__row-clear",onClick:g,"aria-label":`Clear filter for ${n.headerName||n.field}`,title:"Clear",children:"×"})]})]})},Mn=({filterModel:n,columns:t,onFilterModelChange:e})=>{const o=l.useMemo(()=>n.items??[],[n.items]),i=n.logicOperator??"and",s=l.useCallback((p,c)=>{const f=o.filter(m=>"field"in m&&m.field!==p),w=c?[...f,c]:f;e({...n,items:w})},[o,n,e]),d=l.useCallback(p=>{e({...n,logicOperator:p})},[n,e]),a=t.filter(p=>p.filterable!==!1);return r.jsxs(r.Fragment,{children:[o.length>1&&r.jsxs("div",{className:"ogx-filter__logic-bar",children:[r.jsx("span",{className:"ogx-filter__logic-label",children:"Match:"}),r.jsx("button",{className:`ogx-filter__logic-pill${i==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("and"),"aria-pressed":i==="and",children:"ALL (AND)"}),r.jsx("button",{className:`ogx-filter__logic-pill${i==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("or"),"aria-pressed":i==="or",children:"ANY (OR)"})]}),a.length===0?r.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):a.map(p=>r.jsx(Sr,{col:p,item:kr(o,p.field),onChange:c=>s(p.field,c)},p.field))]})},jr=["sum","avg","count","min","max"];function Pn(){return r.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:[r.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),r.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),r.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),r.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",fill:"currentColor",opacity:"0.25"}),r.jsx("path",{d:"M17 14v-4M17 10l-2 2 2 2"})]})}function Er({anchorRef:n,columns:t,model:e,onChange:o,onClose:i}){const s=l.useRef(null),[d,a]=l.useState({top:0,right:0}),[p,c]=l.useState(document.body);l.useLayoutEffect(()=>{c(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const f=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const _=n.current.getBoundingClientRect();return{top:_.bottom+6,right:window.innerWidth-_.right}},[n]);l.useEffect(()=>{a(f());const _=()=>a(f());return window.addEventListener("scroll",_,!0),window.addEventListener("resize",_),()=>{window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",_)}},[f]),l.useEffect(()=>{function _(L){s.current&&!s.current.contains(L.target)&&n.current&&!n.current.contains(L.target)&&i()}function T(L){L.key==="Escape"&&i()}return document.addEventListener("mousedown",_),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",T)}},[n,i]);const w=new Set(e.rowFields),m=new Set(e.columnFields),u=new Set(e.valueFields.map(_=>_.field)),x=_=>w.has(_)||m.has(_)||u.has(_);function g(_){w.has(_)||o({...e,rowFields:[...e.rowFields,_]})}function k(_){m.has(_)||o({...e,columnFields:[...e.columnFields,_]})}function N(_,T="sum"){u.has(_)||o({...e,valueFields:[...e.valueFields,{field:_,aggFn:T}]})}function y(_){o({...e,rowFields:e.rowFields.filter(T=>T!==_)})}function v(_){o({...e,columnFields:e.columnFields.filter(T=>T!==_)})}function j(_){o({...e,valueFields:e.valueFields.filter(T=>T.field!==_)})}function b(_,T){o({...e,valueFields:e.valueFields.map(L=>L.field===_?{...L,aggFn:T}:L)})}function S(){o({rowFields:[],columnFields:[],valueFields:[]})}const h=new Set(t.filter(_=>_.type==="number"||_.aggregable).map(_=>_.field)),E=e.rowFields.length+e.columnFields.length+e.valueFields.length,M=_=>t.find(T=>T.field===_)?.headerName??_,I=r.jsxs("div",{ref:s,className:"ogx-pivot-panel",role:"dialog","aria-label":"Pivot configuration",style:{top:d.top,right:d.right},children:[r.jsxs("div",{className:"ogx-pivot-panel__header",children:[r.jsxs("span",{className:"ogx-pivot-panel__title",children:[r.jsx(Pn,{}),"Pivot Mode"]}),E>0&&r.jsx("button",{className:"ogx-pivot-panel__reset-btn",onClick:S,title:"Reset pivot",children:"Reset"})]}),r.jsxs("div",{className:"ogx-pivot-panel__body",children:[r.jsxs("div",{className:"ogx-pivot-zone",children:[r.jsxs("span",{className:"ogx-pivot-zone__label",children:[r.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--row"}),"Row Fields"]}),r.jsx("div",{className:`ogx-pivot-chips${e.rowFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — each becomes a row label",children:e.rowFields.map(_=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[M(_),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>y(_),title:`Remove ${M(_)}`,children:"×"})]},_))})]}),r.jsxs("div",{className:"ogx-pivot-zone",children:[r.jsxs("span",{className:"ogx-pivot-zone__label",children:[r.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--col"}),"Column Fields"]}),r.jsx("div",{className:`ogx-pivot-chips${e.columnFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — unique values become column headers",children:e.columnFields.map(_=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[M(_),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>v(_),title:`Remove ${M(_)}`,children:"×"})]},_))})]}),r.jsxs("div",{className:"ogx-pivot-zone",children:[r.jsxs("span",{className:"ogx-pivot-zone__label",children:[r.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--value"}),"Value Fields (aggregated)"]}),r.jsx("div",{className:`ogx-pivot-chips${e.valueFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add numeric fields here — values are aggregated",children:e.valueFields.map(_=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[M(_.field),r.jsx("select",{className:"ogx-pivot-chip__fn-select",value:_.aggFn,onChange:T=>b(_.field,T.target.value),title:"Aggregation function",children:jr.map(T=>r.jsx("option",{value:T,children:T.toUpperCase()},T))}),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>j(_.field),title:`Remove ${M(_.field)}`,children:"×"})]},_.field))})]}),r.jsx("hr",{className:"ogx-pivot-panel__divider"}),r.jsxs("div",{children:[r.jsx("div",{className:"ogx-pivot-panel__fields-label",children:"Available Fields"}),r.jsxs("div",{className:"ogx-pivot-fields",children:[t.map(_=>{const T=h.has(_.field);return x(_.field)?null:r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[r.jsx("span",{className:`ogx-pivot-field-btn${T?" ogx-pivot-field-btn--numeric":""}`,children:_.headerName??_.field}),r.jsxs("div",{className:"ogx-pivot-field-actions",children:[r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>g(_.field),title:"Add to Row Fields",children:"Row"}),r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>k(_.field),title:"Add to Column Fields",children:"Col"}),T&&r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>N(_.field),title:"Add to Value Fields",children:"Val"})]})]},_.field)}),t.every(_=>x(_.field))&&r.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return He.createPortal(I,p)}function Nr(){return r.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("circle",{cx:"11",cy:"11",r:"8"}),r.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Mr(){return r.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Pr({value:n="",onChange:t,placeholder:e="Search...",debounceMs:o=250}){const[i,s]=l.useState(()=>n.length>0),[d,a]=l.useState(n),p=l.useRef(null),c=l.useRef(null),f=l.useRef(t);l.useLayoutEffect(()=>{f.current=t},[t]);const w=l.useRef(n),m=l.useRef(n),u=l.useRef(!1);l.useLayoutEffect(()=>{u.current&&document.activeElement!==p.current&&p.current?.focus()}),l.useEffect(()=>{n!==m.current&&(m.current=n,n!==w.current&&(a(n),w.current=n,n?s(!0):(u.current=!1,s(!1))))},[n]),l.useEffect(()=>{const y=setTimeout(()=>{d!==w.current&&(w.current=d,f.current(d))},o);return()=>clearTimeout(y)},[d,o]);const x=l.useCallback(()=>{s(!0),requestAnimationFrame(()=>p.current?.focus())},[]),g=l.useCallback(y=>{y.stopPropagation(),a(""),w.current="",f.current(""),p.current?.focus()},[]),k=l.useCallback(()=>{u.current=!0,s(!0)},[]),N=l.useCallback(()=>{u.current=!1,setTimeout(()=>{if(c.current&&document.activeElement&&c.current.contains(document.activeElement)){u.current=!0;return}d||s(!1)},150)},[d]);return l.useEffect(()=>{const y=v=>{c.current&&!c.current.contains(v.target)&&(d||s(!1))};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[d]),r.jsxs("div",{ref:c,className:`ogx-global-search${i?" ogx-global-search--expanded":""}`,onClick:i?void 0:x,children:[r.jsx("div",{className:"ogx-global-search__icon-wrapper",children:r.jsx(Nr,{})}),r.jsx("input",{ref:p,className:"ogx-global-search__input",value:d,onChange:y=>a(y.target.value),onFocus:k,onBlur:N,placeholder:e,"aria-label":"Global Search",autoComplete:"off"}),d&&r.jsx("button",{className:"ogx-global-search__clear",onClick:g,"aria-label":"Clear search",children:r.jsx(Mr,{})})]})}function pt({title:n,children:t,placement:e="top",enterDelay:o=200,leaveDelay:i=0}){const[s,d]=l.useState(!1),[a,p]=l.useState({top:0,left:0}),c=l.useRef(null),f=l.useRef(null),w=l.useCallback(()=>{if(!f.current)return;const g=f.current.getBoundingClientRect();let k=0,N=0;const y=window.pageXOffset||document.documentElement.scrollLeft,v=window.pageYOffset||document.documentElement.scrollTop;e==="top"?(k=g.top+v-8,N=g.left+y+g.width/2):e==="bottom"&&(k=g.bottom+v+8,N=g.left+y+g.width/2),p({top:k,left:N})},[e]);l.useLayoutEffect(()=>(s&&(w(),window.addEventListener("scroll",w,!0),window.addEventListener("resize",w)),()=>{window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w)}),[s,w]);const m=()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d(!0)},o)},u=()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d(!1)},i)},x=l.useCallback(g=>{f.current=g?g.firstElementChild??g:null},[]);return r.jsxs(r.Fragment,{children:[r.jsx("span",{ref:x,style:{display:"inline-block",lineHeight:0},onMouseEnter:m,onMouseLeave:u,children:t}),s&&n&&He.createPortal(r.jsx("div",{className:`ogx-tooltip ogx-tooltip--${e}`,style:{top:a.top,left:a.left,position:"absolute",zIndex:99999},children:n}),document.body)]})}const Ir=["none","sum","avg","count","min","max"];function In(){return r.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:r.jsx("path",{d:"M18 4H6l6 8-6 8h12"})})}function Tr(){return r.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",children:[r.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.25"}),r.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),r.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),r.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Tn(){return r.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function Rr({anchorRef:n,aggregationModel:t,aggregableColumns:e,onFunctionChange:o,onClearAll:i,onClose:s,activeCount:d}){const a=l.useRef(null),[p,c]=l.useState({top:0,right:0}),[f,w]=l.useState(document.body);l.useLayoutEffect(()=>{w(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const m=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const x=n.current.getBoundingClientRect();return{top:x.bottom+6,right:window.innerWidth-x.right}},[n]);l.useEffect(()=>{c(m());const x=()=>c(m());return window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[m]),l.useEffect(()=>{function x(g){a.current&&!a.current.contains(g.target)&&n.current&&!n.current.contains(g.target)&&s()}return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[n,s]),l.useEffect(()=>{function x(g){g.key==="Escape"&&s()}return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[s]);const u=r.jsxs("div",{ref:a,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:p.top,right:p.right,width:400,maxWidth:"calc(100vw - 24px)"},children:[r.jsxs("div",{className:"ogx-toolbar__panel-header",children:[r.jsxs("span",{className:"ogx-toolbar__panel-title",children:[r.jsx(In,{}),"Summaries"]}),d>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:i,title:"Clear all summaries",children:"Clear all"})]}),r.jsx("div",{className:"ogx-toolbar__panel-body",children:e.length===0?r.jsxs("p",{className:"ogx-toolbar__empty",children:["No aggregable columns.",r.jsx("br",{}),"Set ",r.jsx("code",{children:"aggregable: true"})," on a column to enable."]}):e.map(x=>{const g=t[x.field]||"none";return r.jsxs("div",{className:"ogx-toolbar__agg-row",children:[r.jsx("span",{className:"ogx-toolbar__agg-label",title:x.field,children:x.headerName||x.field}),r.jsx("div",{className:"ogx-toolbar__agg-pills",children:Ir.map(k=>r.jsx("button",{className:`ogx-toolbar__pill${g===k?" ogx-toolbar__pill--active":""}`,onClick:()=>o(x.field,k),"aria-pressed":g===k,children:k},k))})]},x.field)})})]});return He.createPortal(u,f)}function Lr({anchorRef:n,columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:i,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,onClose:p,showNonHideableColumns:c}){const f=l.useRef(null),[w,m]=l.useState({top:0,right:0}),[u,x]=l.useState(document.body);l.useLayoutEffect(()=>{x(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const g=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const N=n.current.getBoundingClientRect();return{top:N.bottom+6,right:window.innerWidth-N.right}},[n]);l.useEffect(()=>{m(g());const N=()=>m(g());return window.addEventListener("scroll",N,!0),window.addEventListener("resize",N),()=>{window.removeEventListener("scroll",N,!0),window.removeEventListener("resize",N)}},[g]),l.useEffect(()=>{function N(y){f.current&&!f.current.contains(y.target)&&n.current&&!n.current.contains(y.target)&&p()}return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[n,p]);const k=r.jsx("div",{ref:f,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:w.top,right:w.right,width:280,padding:0},children:r.jsx(En,{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:i,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,showNonHideableColumns:c})});return He.createPortal(k,u)}function Fr({anchorRef:n,columns:t,filterModel:e,onFilterModelChange:o,onClose:i}){const s=l.useRef(null),[d,a]=l.useState({top:0,right:0}),p=l.useRef(i);l.useLayoutEffect(()=>{p.current=i},[i]);const[c,f]=l.useState(document.body);l.useLayoutEffect(()=>{f(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const w=l.useCallback(()=>{if(!n.current)return{top:0,right:0};const g=n.current.getBoundingClientRect();return{top:g.bottom+6,right:window.innerWidth-g.right}},[n]);l.useEffect(()=>{a(w());const g=()=>a(w());return window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[w]),l.useEffect(()=>{function g(k){k.key==="Escape"&&p.current()}return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[]);const m=e.items?.length??0,u=()=>{o({...e,items:[],logicOperator:"and"})},x=r.jsxs("div",{ref:s,className:"ogx-toolbar__panel ogx-toolbar__panel--filter",role:"dialog","aria-label":"Advanced filters",style:{top:d.top,right:d.right,width:540,maxWidth:"calc(100vw - 24px)"},children:[r.jsxs("div",{className:"ogx-toolbar__panel-header",children:[r.jsxs("span",{className:"ogx-toolbar__panel-title",children:[r.jsx(Tn,{}),"Filters",m>0&&r.jsx("span",{className:"ogx-toolbar__panel-count",children:m})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[m>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:u,title:"Clear all filters",children:"Clear all"}),r.jsx("button",{className:"ogx-toolbar__close-btn",onClick:()=>p.current(),title:"Close filters","aria-label":"Close filters panel",children:"Close"})]})]}),r.jsx("div",{className:"ogx-toolbar__panel-body ogx-toolbar__panel-body--filter",children:r.jsx(Mn,{columns:t,filterModel:e,onFilterModelChange:o})})]});return He.createPortal(x,c)}const Or={rowFields:[],columnFields:[],valueFields:[]};function Wr({columns:n=[],baseColumns:t,aggregationModel:e={},onAggregationModelChange:o,pivotModel:i,onPivotModelChange:s,filterModel:d,onFilterModelChange:a,columnVisibilityModel:p={},onColumnVisibilityModelChange:c,onColumnReorder:f,onColumnOrderReset:w,forceColumnsOpen:m,onColumnsPanelClose:u,children:x,rightContent:g,style:k,renderColumnsButton:N,renderFilterButton:y,renderAggregationButton:v,renderExportButton:j,renderQuickFilter:b,className:S,showNonHideableColumns:h}){const[E,M]=l.useState(!1),[I,_]=l.useState(!1),[T,L]=l.useState(!1),[$,O]=l.useState(!1);l.useEffect(()=>{m&&(L(!0),M(!1),_(!1),O(!1))},[m]);const H=l.useRef(null),F=l.useRef(null),D=l.useRef(null),q=l.useRef(null),K=l.useRef(null),C=l.useRef(null),P=l.useRef(null),W=i??Or,R=W.rowFields.length>0||W.columnFields.length>0||W.valueFields.length>0,z=n.filter(Q=>Q.aggregable!==!1&&(Q.type==="number"||Q.aggregable===!0)),U=Object.keys(e).filter(Q=>e[Q]&&e[Q]!=="none").length,G=l.useCallback((Q,le)=>{if(!o)return;const B={...e};le==="none"?delete B[Q]:B[Q]=le,o(B)},[e,o]),ne=l.useCallback(()=>{o?.({})},[o]),A=l.useCallback(Q=>{if(!a)return;const B={...d||{},quickFilterValues:Q?[Q]:[],items:d?.items||[]};a(B)},[d,a]),J=d?.quickFilterValues?.[0]||"",ee=d?.items?.length||0,se=new Set(n.filter(Q=>p[Q.field]!==!1).map(Q=>Q.field)),re=l.useCallback((Q,le)=>{if(!c)return;const B={...p,[Q]:le};c(B)},[p,c]),ve=l.useCallback(()=>{if(!c)return;const Q={...p};n.forEach(le=>{le.hideable!==!1&&(Q[le.field]=!0)}),c(Q)},[n,p,c]),Y=l.useCallback(()=>{if(!c)return;const Q={...p};n.forEach(le=>{le.hideable!==!1&&(Q[le.field]=!1)}),c(Q)},[n,p,c]);return r.jsxs("div",{className:["ogx-toolbar",S].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:k,children:[x&&r.jsx("div",{className:"ogx-toolbar__left",children:x}),r.jsx("div",{className:"ogx-toolbar__spacer"}),r.jsxs("div",{className:"ogx-toolbar__actions",children:[a&&r.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:b?b({value:J,onChange:A}):r.jsx(Pr,{value:J,onChange:A,placeholder:"Search..."})}),c&&r.jsxs("div",{ref:K,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[N?N({onClick:()=>{L(Q=>!Q),M(!1),_(!1),O(!1)},isOpen:T,activeCount:n.length-se.size}):r.jsx(pt,{title:"Columns",children:r.jsx("button",{ref:D,className:`ogx-toolbar__icon-btn${T?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns",onClick:()=>{L(!T),M(!1),_(!1),O(!1)},children:r.jsx(Tr,{})})}),T&&r.jsx(Lr,{anchorRef:N?K:D,columns:n,visibleColumns:se,onVisibilityChange:re,onShowAll:ve,onHideAll:Y,onColumnReorder:f,onColumnOrderReset:w,onClose:()=>{L(!1),u?.()},showNonHideableColumns:h})]}),a&&r.jsxs("div",{ref:C,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[y?y({onClick:()=>{O(Q=>!Q),M(!1),_(!1),L(!1)},isOpen:$,activeCount:ee}):r.jsx(pt,{title:"Filters",children:r.jsxs("button",{ref:q,className:`ogx-toolbar__icon-btn${$?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters",onClick:()=>{O(!$),M(!1),_(!1),L(!1)},children:[r.jsx(Tn,{}),ee>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),$&&r.jsx(Fr,{anchorRef:y?C:q,columns:n,filterModel:d||{items:[]},onFilterModelChange:a,onClose:()=>O(!1)})]}),s&&r.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[r.jsx(pt,{title:"Pivot",children:r.jsxs("button",{ref:F,className:`ogx-toolbar__icon-btn${I?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-expanded":I,onClick:()=>{_(!I),M(!1),L(!1),O(!1)},children:[r.jsx(Pn,{}),R&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),I&&r.jsx(Er,{anchorRef:F,columns:t??n,model:W,onChange:Q=>{s?.(Q)},onClose:()=>_(!1)})]}),r.jsxs("div",{ref:P,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[v?v({onClick:()=>{M(Q=>!Q),_(!1),L(!1),O(!1)},isOpen:E,activeCount:U}):r.jsx(pt,{title:"Summaries",children:r.jsxs("button",{ref:H,className:`ogx-toolbar__icon-btn${E?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-expanded":E,onClick:()=>{M(!E),_(!1),L(!1),O(!1)},children:[r.jsx(In,{}),U>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${U} active summaries`})]})}),E&&r.jsx(Rr,{anchorRef:v?P:H,aggregationModel:e,aggregableColumns:z,onFunctionChange:G,onClearAll:ne,onClose:()=>M(!1),activeCount:U})]}),j&&j(),g]})]})}function Ar(){return l.useRef(null)}const $r=({fullWidth:n=!1,error:t=!1,startAdornment:e,endAdornment:o,className:i="",...s})=>{const d=["ogx-input-wrapper",n&&"ogx-input-wrapper--full-width",t&&"ogx-input-wrapper--error",s.disabled&&"ogx-input-wrapper--disabled",i].filter(Boolean).join(" ");return r.jsxs("div",{className:d,children:[e&&r.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--start",children:e}),r.jsx("input",{className:"ogx-input",...s}),o&&r.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--end",children:o})]})};function Rn(n){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(n);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[79,70,229]}function zr(n){return n.filter(t=>!(t.exportable===!1||t.field==="__check__"||t.field==="__actions__"))}function Ln(n,t){let e=n[t.field];return t.valueGetter&&(e=t.valueGetter({row:n,field:t.field,value:e})),t.valueFormatter&&e!==void 0&&e!==null&&(e=t.valueFormatter({value:e,row:n,field:t.field})),String(e??"")}function Fn(n){return(typeof n.width=="number"?n.width:void 0)??(n.flex??1)*100}function Br(n,t){const e=n.reduce((i,s)=>i+Fn(s),0),o={};return n.forEach((i,s)=>{o[s]={cellWidth:Fn(i)/e*t}}),o}function Dr(n,t){return!n.items||n.items.length===0?"":n.items.flatMap(e=>{if("items"in e)return[];const i=t.find(d=>d.field===e.field)?.headerName??e.field,s=e.value!==void 0&&e.value!==null?String(e.value):"";return[`${i} ${e.operator} "${s}"`]}).join(" • ")}async function Hr(n,t,e={}){let o,i;try{const[C,P]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);o=C.default,i=P.default}catch{throw new Error("exportToPdf requires 'jspdf' and 'jspdf-autotable'. Run: npm install jspdf jspdf-autotable")}const{fileName:s="export",title:d,logoUrl:a,orientation:p="landscape",selectedRows:c,aggregationResult:f,aggregationModel:w,filterModel:m,alternateRowColor:u=!0,headerBackgroundColor:x="#4f46e5",headerTextColor:g="#ffffff",fontSize:k=9,groupedRows:N}=e,y=new o({orientation:p,unit:"mm",format:"a4"}),v=y.internal.pageSize.getWidth(),j=y.internal.pageSize.getHeight(),b=14,S=v-b*2,h=zr(t),E=c&&c.length>0?n.filter(C=>c.includes(C.id)):n;let M=b;if(d){let C=b,P=b+8;if(a)try{y.addImage(a,"PNG",C,b,10,10),C+=14}catch{}y.setFontSize(16),y.setFont("helvetica","bold"),y.setTextColor(30,41,59),y.text(d,C,P),P+=6,y.setFontSize(8),y.setFont("helvetica","normal"),y.setTextColor(100,116,139);const W=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),R=N?N.filter(z=>z.type==="leaf").length:E.length;if(y.text(`Exported: ${W} • ${R} row${R!==1?"s":""}`,C,P),P+=5,m){const z=Dr(m,t);z&&(y.text(`Filters: ${z}`,C,P),P+=5)}y.setDrawColor(226,232,240),y.setLineWidth(.3),y.line(b,P+2,v-b,P+2),M=P+6}const I=[h.map(C=>C.headerName??C.field)];let _,T;if(N&&N.length>0){_=[];const C=w||{};N.forEach(P=>{if(P.type==="group-header"){const R=`${" ".repeat(P.depth*2)}${P.groupField??""}: ${String(P.groupValue??"")}`;_.push(h.map((z,U)=>U===0?R:""))}else if(P.type==="leaf"&&P.row){const W=P.row,R=" ".repeat(P.depth*2);_.push(h.map((z,U)=>(U===0?R:"")+Ln(W,z)))}else if(P.type==="group-subtotal"&&P.aggregatedValues){const W=" ".repeat(P.depth*2);_.push(h.map((R,z)=>{if(z===0)return`${W}Subtotal`;const U=P.aggregatedValues[R.field];if(U==null)return"";let G=U;return R.valueFormatter?G=R.valueFormatter({value:U,row:{},field:R.field}):C[R.field]&&(G=_e(U,C[R.field])),String(G)}))}else P.type==="grand-total"&&P.aggregatedValues&&(T=[h.map((R,z)=>{if(z===0)return"Grand Total";const U=P.aggregatedValues[R.field];if(U==null)return"";let G=U;return R.valueFormatter?G=R.valueFormatter({value:U,row:{},field:R.field}):C[R.field]&&(G=_e(U,C[R.field])),String(G)})])})}else _=E.map(C=>h.map(P=>Ln(C,P))),f&&w&&(T=[h.map((P,W)=>{if(W===0)return h.some(G=>w[G.field])?"TOTAL":"";const R=f[P.field];if(R==null)return"";let z=R;return P.valueFormatter?z=P.valueFormatter({value:R,row:{},field:P.field}):w[P.field]&&(z=_e(R,w[P.field])),String(z)})]);const L=Br(h,S),[$,O,H]=Rn(x),[F,D,q]=Rn(g);i(y,{head:I,body:_,...T?{foot:T}:{},startY:M,styles:{fontSize:k,cellPadding:3,font:"helvetica",overflow:"linebreak"},headStyles:{fillColor:[$,O,H],textColor:[F,D,q],fontStyle:"bold"},...u?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...T?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:L,showFoot:T?"lastPage":"never",showHead:"everyPage",margin:{top:b,left:b,right:b,bottom:b+6}});const K=y.getNumberOfPages();for(let C=1;C<=K;C++)y.setPage(C),y.setFontSize(8),y.setTextColor(150,150,150),y.text(`Page ${C} of ${K}`,v-b,j-8,{align:"right"});y.save(`${s}.pdf`)}function Gr(n,t,e={}){const{fileName:o="export.csv",includeHeaders:i=!0,delimiter:s=",",selectedRows:d,groupedRows:a}=e,p=t.filter(f=>!(f.exportable===!1||f.field==="__check__"||f.field==="__actions__"));let c="";if(a&&a.length>0)i&&(c+=p.map(f=>Ee(f.headerName||f.field)).join(s)+`
9
+ `),a.forEach(f=>{if(f.type==="group-header"){const m=`${" ".repeat(f.depth)}${f.groupField??""}: ${String(f.groupValue??"")}`,u=p.map((x,g)=>g===0?Ee(m):"");c+=u.join(s)+`
10
+ `}else if(f.type==="leaf"&&f.row){const w=f.row,m=" ".repeat(f.depth),u=p.map((x,g)=>{let k=w[x.field];return x.valueGetter&&(k=x.valueGetter({row:w,field:x.field,value:k})),x.valueFormatter&&k!==void 0&&k!==null&&(k=x.valueFormatter({value:k,row:w,field:x.field})),Ee((g===0?m:"")+String(k??""))});c+=u.join(s)+`
11
+ `}else if(f.type==="group-subtotal"&&f.aggregatedValues){const w=" ".repeat(f.depth),m=e.aggregationModel||{},u=p.map((x,g)=>{if(g===0)return Ee(`${w}Subtotal`);const k=f.aggregatedValues[x.field];if(k!=null){let N=k;return x.valueFormatter?N=x.valueFormatter({value:k,row:{},field:x.field}):m[x.field]&&(N=_e(k,m[x.field])),Ee(String(N))}return""});c+=u.join(s)+`
12
+ `}else if(f.type==="grand-total"&&f.aggregatedValues){const w=e.aggregationModel||{},m=p.map((u,x)=>{if(x===0)return Ee("Grand Total");const g=f.aggregatedValues[u.field];if(g!=null){let k=g;return u.valueFormatter?k=u.valueFormatter({value:g,row:{},field:u.field}):w[u.field]&&(k=_e(g,w[u.field])),Ee(String(k))}return""});c+=m.join(s)+`
13
+ `}});else{const f=d&&d.length>0?n.filter(w=>d.includes(w.id)):n;if(f.length===0){console.warn("No rows to export");return}if(i&&(c+=p.map(w=>Ee(w.headerName||w.field)).join(s)+`
14
+ `),f.forEach(w=>{const m=p.map(u=>{let x=w[u.field];return u.valueGetter&&(x=u.valueGetter({row:w,field:u.field,value:x})),u.valueFormatter&&x!==void 0&&x!==null&&(x=u.valueFormatter({value:x,row:w,field:u.field})),Ee(String(x??""))});c+=m.join(s)+`
15
+ `}),e.aggregationResult){const w=e.aggregationResult,m=e.aggregationModel||{},u=p.map(g=>Ee(m[g.field]?m[g.field].toUpperCase():""));c+=u.join(s)+`
16
+ `;const x=p.map(g=>{const k=w[g.field];if(k!=null){let N=k;return g.valueFormatter?N=g.valueFormatter({value:k,row:{},field:g.field}):m[g.field]&&(N=_e(k,m[g.field])),Ee(String(N))}return""});c+=x.join(s)+`
17
+ `}}Yt(c,o,"text/csv;charset=utf-8;")}function Ee(n){return n.includes(",")||n.includes('"')||n.includes(`
18
+ `)?`"${n.replace(/"/g,'""')}"`:n}function Vr(n,t,e={}){const{fileName:o="export.xls",sheetName:i="Sheet1",includeHeaders:s=!0,selectedRows:d,groupedRows:a}=e,p=t.filter(w=>!(w.exportable===!1||w.field==="__check__"||w.field==="__actions__"));let f=`<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>${i}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta charset="UTF-8"></head><body><table border="1">`;if(s&&(f+="<thead><tr>",p.forEach(w=>{f+=`<th>${we(w.headerName||w.field)}</th>`}),f+="</tr></thead>"),f+="<tbody>",a&&a.length>0){const w=e.aggregationModel||{};a.forEach(m=>{if(m.type==="group-header"){const x=`${"  ".repeat(m.depth*2)}${m.groupField??""}: ${String(m.groupValue??"")}`;f+='<tr style="font-weight:bold;background:#e8eaf6;">',f+=`<td colspan="${p.length}">${we(x)}</td>`,f+="</tr>"}else if(m.type==="leaf"&&m.row){const u=m.row,x="  ".repeat(m.depth*2);f+="<tr>",p.forEach((g,k)=>{let N=u[g.field];g.valueGetter&&(N=g.valueGetter({row:u,field:g.field,value:N})),g.valueFormatter&&N!==void 0&&N!==null&&(N=g.valueFormatter({value:N,row:u,field:g.field})),f+=`<td>${we((k===0?x:"")+String(N??""))}</td>`}),f+="</tr>"}else if((m.type==="group-subtotal"||m.type==="grand-total")&&m.aggregatedValues){const u=m.type==="grand-total",x=u?"":"  ".repeat(m.depth*2),g=u?"Grand Total":`${x}Subtotal`;f+='<tr style="font-weight:bold;background:#f5f5f5;">',p.forEach((k,N)=>{if(N===0){f+=`<td>${we(g)}</td>`;return}const y=m.aggregatedValues[k.field];if(y!=null){let v=y;k.valueFormatter?v=k.valueFormatter({value:y,row:{},field:k.field}):w[k.field]&&(v=_e(y,w[k.field])),f+=`<td style="text-align:right;">${we(String(v))}</td>`}else f+="<td></td>"}),f+="</tr>"}})}else{const w=d&&d.length>0?n.filter(m=>d.includes(m.id)):n;if(w.length===0){console.warn("No rows to export");return}if(w.forEach(m=>{f+="<tr>",p.forEach(u=>{let x=m[u.field];u.valueGetter&&(x=u.valueGetter({row:m,field:u.field,value:x})),u.valueFormatter&&x!==void 0&&x!==null&&(x=u.valueFormatter({value:x,row:m,field:u.field})),f+=`<td>${we(String(x??""))}</td>`}),f+="</tr>"}),e.aggregationResult){const m=e.aggregationResult,u=e.aggregationModel||{};f+='<tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',p.forEach(x=>{f+=u[x.field]?`<td style="text-align:right;font-weight:bold;">${we(u[x.field].toUpperCase())}</td>`:"<td></td>"}),f+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',p.forEach(x=>{const g=m[x.field];if(g!=null){let k=g;x.valueFormatter?k=x.valueFormatter({value:g,row:{},field:x.field}):u[x.field]&&(k=_e(g,u[x.field])),f+=`<td style="text-align:right;">${we(String(k))}</td>`}else f+="<td></td>"}),f+="</tr>"}}f+="</tbody></table></body></html>",Yt(f,o,"application/vnd.ms-excel")}function we(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function Ur(n,t,e={}){const{fileName:o="export.json",pretty:i=!0,selectedRows:s,groupedRows:d}=e,a=t.filter(c=>!(c.exportable===!1||c.field==="__check__"||c.field==="__actions__"));let p;if(d&&d.length>0){const c=[],f=[];let w;d.forEach(m=>{if(m.type==="group-header"){const u={group:`${m.groupField??""}: ${String(m.groupValue??"")}`,field:m.groupField??"",value:m.groupValue,rows:[],children:[]};for(;c.length>m.depth;)c.pop();c.length===0?f.push(u):(c[c.length-1].children??=[]).push(u),c.push(u)}else if(m.type==="leaf"&&m.row){const u=m.row,x={};a.forEach(g=>{let k=u[g.field];g.valueGetter&&(k=g.valueGetter({row:u,field:g.field,value:k})),x[g.field]=k}),c.length>0&&c[c.length-1].rows.push(x)}else m.type==="group-subtotal"&&m.aggregatedValues&&c.length>0?(c[c.length-1].subtotals={...m.aggregatedValues},c.pop()):m.type==="grand-total"&&m.aggregatedValues&&(w={...m.aggregatedValues})}),p=w?{groups:f,grandTotal:w}:{groups:f}}else{const c=s&&s.length>0?n.filter(w=>s.includes(w.id)):n;if(c.length===0){console.warn("No rows to export");return}const f=c.map(w=>{const m={};return a.forEach(u=>{let x=w[u.field];u.valueGetter&&(x=u.valueGetter({row:w,field:u.field,value:x})),m[u.field]=x}),m});if(e.aggregationResult){const w=e.aggregationResult,m=e.aggregationModel||{},u={};a.forEach(g=>{m[g.field]&&(u[g.field]=m[g.field].toUpperCase())});const x={};a.forEach(g=>{if(w[g.field]!==void 0&&w[g.field]!==null){let k=w[g.field];g.valueFormatter?k=g.valueFormatter({value:k,row:{},field:g.field}):m[g.field]&&(k=_e(k,m[g.field])),x[g.field]=k}}),p={data:f,aggregation:{labels:u,values:x}}}else p=f}Yt(i?JSON.stringify(p,null,2):JSON.stringify(p),o,"application/json;charset=utf-8;")}async function Kr(n,t,e){const o=window.open("","_blank");if(!o){console.error("Failed to open print window. Please check your popup blocker settings.");return}o.document.write(`
14
19
  <!DOCTYPE html>
15
20
  <html>
16
21
  <head>
@@ -30,24 +35,16 @@ ${p}`;try{await er(m)}catch(h){console.error("[OpenGridX] Failed to copy to clip
30
35
  </div>
31
36
  </body>
32
37
  </html>
33
- `),o.document.close(),await new Promise(i=>setTimeout(i,100));try{let i="Print",s,d=null,a=null;typeof e=="string"?i=e:typeof e=="object"&&(i=e.title||"Print",s=e.selectedRows,d=e.aggregationResult||null,a=e.aggregationModel||null);const u=s&&s.length>0?n.filter(h=>s.includes(h.id)):n;if(u.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}const c=t.filter(h=>!(h.exportable===!1||h.field==="__check__"||h.field==="__actions__"));let p=`
34
- <!DOCTYPE html>
35
- <html>
36
- <head>
37
- <title>${i||"Print"}</title>
38
- <style>
39
- body { font-family: Arial, sans-serif; margin: 20px; }
40
- h1 { font-size: 24px; margin-bottom: 20px; }
41
- table { border-collapse: collapse; width: 100%; }
42
- th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
43
- th { background-color: #f5f5f5; font-weight: bold; }
44
- tr:nth-child(even) { background-color: #f9f9f9; }
45
- @media print {
46
- body { margin: 0; }
47
- @page { margin: 1cm; }
48
- }
49
- </style>
50
- </head>
51
- <body>
52
- `;if(i&&(p+=`<h1>${Me(i)}</h1>`),p+="<table>",p+="<thead><tr>",c.forEach(h=>{p+=`<th>${Me(h.headerName||h.field)}</th>`}),p+="</tr></thead>",p+="<tbody>",u.forEach(h=>{p+="<tr>",c.forEach(b=>{let C=h[b.field];b.valueGetter&&(C=b.valueGetter({row:h,field:b.field,value:C})),b.valueFormatter&&C!==void 0&&C!==null&&(C=b.valueFormatter({value:C,row:h,field:b.field})),b.type==="image"&&C?p+=`<td><div style="display:flex;justify-content:center;"><img src="${C}" alt="${b.headerName}" style="max-height: 40px; border-radius: 4px;"></div></td>`:p+=`<td>${Me(String(C??""))}</td>`}),p+="</tr>"}),d){const h=a||{};p+='<tfoot><tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',c.forEach(b=>{h[b.field]?p+=`<td style="text-align: right; font-weight: bold;">${Me(h[b.field].toUpperCase())}</td>`:p+="<td></td>"}),p+='</tr><tr style="font-weight: bold; background-color: #f5f5f5;">',c.forEach(b=>{const C=d[b.field];if(C!=null){let y=C;b.valueFormatter?y=b.valueFormatter({value:C,row:{},field:b.field}):h[b.field]&&(y=Ne(C,h[b.field])),p+=`<td style="text-align: right;">${Me(String(y))}</td>`}else p+="<td></td>"}),p+="</tr></tfoot>"}p+="</tbody></table></body></html>",o.document.open(),o.document.write(p),o.document.close(),o.document.title=i||"Print Preview",o.focus();let m=!1;o.onload=()=>{m||(m=!0,o.print(),setTimeout(()=>{o.close()},100))},setTimeout(()=>{!m&&o&&!o.closed&&(m=!0,o.print(),setTimeout(()=>{o.closed||o.close()},100))},500)}catch(i){if(console.error("Print generation failed:",i),o&&!o.closed){const s=i instanceof Error?i.message:String(i);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${s}</p></div>`}}}function Vt(n,t,e){const o=new Blob([n],{type:e}),i=URL.createObjectURL(o),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function Yr(n,t){return n.type==="number"?"number":n.type==="boolean"?"boolean":n.type==="date"?"date":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date?"date":"string"}function qr(n){if(n.type==="number")return"#,##0.##";if(n.type==="date")return"yyyy-mm-dd"}function Xr(n,t){if(t!=null)return t;const e=n.width??120;return Math.min(60,Math.max(8,(e-5)/7))}function Jr(n,t){const e=t??"";if(e.includes("jpeg")||e.includes("jpg"))return"jpeg";if(e.includes("gif"))return"gif";const o=n.split("?")[0].toLowerCase();return o.endsWith(".jpg")||o.endsWith(".jpeg")?"jpeg":o.endsWith(".gif")?"gif":"png"}async function Qr(n){const t=await Promise.allSettled(n.map(async o=>{if(o.startsWith("data:")){const a=o.indexOf(","),u=o.slice(0,a),c=o.slice(a+1),p=atob(c),m=new Uint8Array(p.length);for(let y=0;y<p.length;y++)m[y]=p.charCodeAt(y);const b=u.match(/data:([^;,]+)/)?.[1]??"image/png";let C="png";return b.includes("jpeg")||b.includes("jpg")?C="jpeg":b.includes("gif")&&(C="gif"),{url:o,buffer:m.buffer,ext:C}}const i=await fetch(o,{mode:"cors"});if(!i.ok)throw new Error(`HTTP ${i.status}`);const s=await i.arrayBuffer(),d=Jr(o,i.headers.get("content-type"));return{url:o,buffer:s,ext:d}})),e=new Map;return t.forEach((o,i)=>{o.status==="fulfilled"?e.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${n[i]}" (CORS/network error — raw URL written as fallback):`,o.reason)}),e}async function Zr(n,t,e={}){const{fileName:o="export.xlsx",sheets:i,columnStyles:s={},headerFillColor:d="#f1f5f9",headerTextColor:a="#334155",headerFontSize:u=10,bodyFontSize:c=10,aggregationResult:p=null,aggregationModel:m=null,selectedRows:h}=e,b=(await import("exceljs")).default,C=new b.Workbook;C.creator="OpenGridX",C.created=new Date;const y=t.filter(S=>S.exportable!==!1&&S.field!=="__check__"&&S.field!=="__actions__"&&!S.isSpacer),E=n,N=h&&h.length>0?n.filter(S=>h.includes(S.id)):n,j=i??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],w=new Map;for(const S of j){if("type"in S&&S.type==="summary"){if(!p||!m)continue;const v=C.addWorksheet(S.name??"Summary");v.addRow(["Summary / Aggregation Totals"]),v.getRow(1).font={bold:!0,size:u+2,color:{argb:Oe(a)}},v.addRow([]),v.addRow(["Column","Function","Value"]).eachCell(W=>{W.fill={type:"pattern",pattern:"solid",fgColor:{argb:Oe(d)}},W.font={bold:!0,size:u,color:{argb:Oe(a)}},W.border=Rn()}),y.forEach(W=>{const $=m[W.field],G=p[W.field];if($==null||G==null)return;let q=G;W.valueFormatter?q=W.valueFormatter({value:G,row:{},field:W.field}):q=Ne(G,$);const Y=v.addRow([W.headerName??W.field,$.toUpperCase(),q]);Y.getCell(3).alignment={horizontal:"right"},Y.getCell(3).font={bold:!0,size:c}}),v.getColumn(1).width=20,v.getColumn(2).width=12,v.getColumn(3).width=18;continue}const P=S,{name:M="Data",rows:_="all",includeHeaders:I=!0,includeSummary:L=!1,autoFilter:F=!0,frozenHeader:A=!0,alternateRowColor:V="#f8fafc"}=P,T=_==="selected"?N:E,B=y.filter(v=>s[v.field]?.embedImage);if(B.length>0){const v=[],R=new Set;if(T.forEach(W=>{B.forEach($=>{const G=W[$.field];typeof G=="string"&&G&&!w.has(G)&&!R.has(G)&&(v.push(G),R.add(G))})}),v.length>0){const W=await Qr(v);for(const[$,{buffer:G,extension:q}]of W){const Y=C.addImage({buffer:G,extension:q});w.set($,Y)}}}const K=C.addWorksheet(M);if(K.columns=y.map(v=>({key:v.field,width:Xr(v,s[v.field]?.width),style:{numFmt:s[v.field]?.numFmt??qr(v)}})),I){const v=y.map(W=>W.headerName??W.field),R=K.addRow(v);R.height=20,R.eachCell((W,$)=>{const G=y[$-1];W.fill={type:"pattern",pattern:"solid",fgColor:{argb:Oe(d)}},W.font={bold:!0,size:u,color:{argb:Oe(a)}},W.alignment={horizontal:s[G?.field]?.alignment??(G?.type==="number"?"right":"left"),vertical:"middle"},W.border=Rn()}),F&&(K.autoFilter={from:{row:1,column:1},to:{row:1,column:y.length}}),A?K.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:K.views=[{showGridLines:!1}]}let H=I?1:0;if(T.forEach((v,R)=>{const W=y.map(G=>{if(s[G.field]?.embedImage)return"";let q=v[G.field];return G.valueGetter&&(q=G.valueGetter({row:v,field:G.field,value:q})),Yr(G,q)==="string"&&G.valueFormatter&&q!=null&&(q=G.valueFormatter({value:q,row:v,field:G.field})),q}),$=K.addRow(W);if($.font={size:c},V&&R%2===1&&$.eachCell(G=>{G.fill={type:"pattern",pattern:"solid",fgColor:{argb:Oe(V)}}}),$.eachCell((G,q)=>{const Y=y[q-1];Y&&(G.alignment={horizontal:s[Y.field]?.alignment??(Y.type==="number"?"right":"left"),vertical:"middle"},G.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}})}),B.length>0){const G=B.reduce((te,O)=>Math.max(te,s[O.field]?.imageHeight??40),0),q=Math.ceil(G/1.333),Y=q*1.333;$.height=q,B.forEach(te=>{const O=y.indexOf(te),J=v[te.field],Q=typeof J=="string"?w.get(J):void 0;if(Q===void 0){$.getCell(O+1).value=typeof J=="string"?J:"";return}const le=s[te.field],oe=le?.imageWidth??40,pe=le?.imageHeight??40,ie=(K.getColumn(O+1).width??8)*7+5,se=Math.max(0,ie-oe)/2,D=Math.max(0,Y-pe)/2;K.addImage(Q,{tl:{col:O,row:H,nativeColOff:Math.floor(se*9525),nativeRowOff:Math.floor(D*9525)},ext:{width:oe,height:pe},editAs:"oneCell"})})}else $.height=16;H++}),L&&p&&m){const v=y.map(G=>{const q=m[G.field];return q?q.toUpperCase():""}),R=K.addRow(v);R.height=16,R.font={size:c-1,italic:!0,color:{argb:"FF94a3b8"}},R.eachCell(G=>{G.alignment={horizontal:"right",vertical:"middle"},G.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const W=y.map(G=>{const q=m[G.field],Y=p[G.field];return q==null||Y==null?"":G.valueFormatter?G.valueFormatter({value:Y,row:{},field:G.field}):Ne(Y,q)}),$=K.addRow(W);$.height=18,$.font={bold:!0,size:c,color:{argb:Oe(a)}},$.eachCell(G=>{G.fill={type:"pattern",pattern:"solid",fgColor:{argb:Oe(d)}},G.alignment={horizontal:"right",vertical:"middle"},G.border=ei()})}}const k=await C.xlsx.writeBuffer(),g=new Blob([k],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),x=URL.createObjectURL(g),f=document.createElement("a");f.href=x,f.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(f),f.click(),document.body.removeChild(f),URL.revokeObjectURL(x)}function Oe(n){const t=n.replace("#","");return t.length===3?"FF"+t.split("").map(e=>e+e).join(""):t.length===6?"FF"+t:"FF"+t.padEnd(6,"0")}function Rn(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function ei(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}const ti={"--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-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-grid-row-selected-background":"#eff6ff","--ogx-grid-row-selected-hover-background":"#dbeafe","--ogx-grid-cell-focus-border":"#3b82f6","--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":"transparent","--ogx-toolbar-text":"#1e293b","--ogx-toolbar-border":"#e2e8f0","--ogx-toolbar-btn-bg":"transparent","--ogx-toolbar-btn-hover":"#f1f5f9","--ogx-toolbar-btn-text":"#334155","--ogx-toolbar-btn-primary-bg":"#3b82f6","--ogx-toolbar-btn-primary-hover":"#2563eb","--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-bg":"#ffffff","--ogx-toolbar-input-text":"#1e293b","--ogx-toolbar-input-border":"#cbd5e1","--ogx-toolbar-input-focus-border":"#3b82f6","--ogx-toolbar-input-focus-shadow":"0 0 0 3px rgba(59, 130, 246, 0.12)","--ogx-toolbar-chip-bg":"#f1f5f9","--ogx-toolbar-chip-text":"#475569","--ogx-toolbar-chip-active-bg":"rgba(59, 130, 246, 0.12)","--ogx-toolbar-chip-active-text":"#2563eb","--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-selected-bg":"rgba(59, 130, 246, 0.08)","--ogx-overlay-item-selected-text":"#2563eb","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-overlay-item-danger-text":"#ef4444","--ogx-scrollbar-thumb":"rgba(148, 163, 184, 0.5)","--ogx-scrollbar-track":"transparent","--ogx-scrollbar-size":"10px","--ogx-skeleton-base":"#f1f5f9","--ogx-skeleton-highlight":"#ffffff","--ogx-skeleton-dark-base":"#e2e8f0","--ogx-skeleton-dark-highlight":"#f8fafc"};function ni(n){const t={};function e(o,i){i!==void 0&&(t[o]=i)}if(n.colors){const o=n.colors;e("--ogx-color-primary",o.primary),e("--ogx-color-primary-dark",o.primaryDark),e("--ogx-color-primary-light",o.primaryLight),e("--ogx-color-primary-focus",o.primaryFocus),e("--ogx-color-secondary",o.secondary),e("--ogx-color-secondary-dark",o.secondaryDark),e("--ogx-color-secondary-light",o.secondaryLight),e("--ogx-color-success",o.success),e("--ogx-color-warning",o.warning),e("--ogx-color-error",o.error),e("--ogx-color-info",o.info)}if(n.typography){const o=n.typography;e("--ogx-font-family",o.fontFamily),e("--ogx-font-family-mono",o.fontFamilyMono),e("--ogx-font-size-xs",o.fontSizeXs),e("--ogx-font-size-sm",o.fontSizeSm),e("--ogx-font-size-md",o.fontSizeMd),e("--ogx-font-size-lg",o.fontSizeLg),e("--ogx-font-size-xl",o.fontSizeXl)}if(n.spacing){const o=n.spacing;e("--ogx-spacing-xs",o.xs),e("--ogx-spacing-sm",o.sm),e("--ogx-spacing-md",o.md),e("--ogx-spacing-lg",o.lg),e("--ogx-spacing-xl",o.xl),e("--ogx-spacing-xxl",o.xxl)}if(n.borders){const o=n.borders;e("--ogx-border-width-thin",o.widthThin),e("--ogx-border-width-medium",o.widthMedium),e("--ogx-border-width-thick",o.widthThick),e("--ogx-border-radius-sm",o.radiusSm),e("--ogx-border-radius-md",o.radiusMd),e("--ogx-border-radius-lg",o.radiusLg),e("--ogx-border-radius-xl",o.radiusXl),e("--ogx-border-color",o.color),e("--ogx-border-color-hover",o.colorHover)}if(n.shadows){const o=n.shadows;e("--ogx-shadow-sm",o.sm),e("--ogx-shadow-md",o.md),e("--ogx-shadow-lg",o.lg),e("--ogx-shadow-xl",o.xl)}if(n.grid){const o=n.grid;e("--ogx-grid-row-height-compact",o.rowHeightCompact),e("--ogx-grid-row-height-standard",o.rowHeightStandard),e("--ogx-row-height",o.rowHeightStandard),e("--ogx-grid-row-height-comfortable",o.rowHeightComfortable),e("--ogx-grid-header-height",o.headerHeight),e("--ogx-header-height",o.headerHeight),e("--ogx-grid-cell-padding-x",o.cellPaddingX),e("--ogx-grid-cell-padding-y",o.cellPaddingY),e("--ogx-grid-background",o.background),e("--ogx-grid-border-color",o.borderColor),e("--ogx-grid-header-background",o.headerBackground),e("--ogx-grid-header-text",o.headerText),e("--ogx-grid-header-hover-background",o.headerHoverBackground),e("--ogx-grid-header-sorted-background",o.headerSortedBackground),e("--ogx-grid-row-text",o.rowText),e("--ogx-grid-row-hover-background",o.rowHoverBackground),e("--ogx-grid-row-alternate-background",o.rowAlternateBackground),e("--ogx-grid-row-selected-background",o.rowSelectedBackground),e("--ogx-grid-row-selected-hover-background",o.rowSelectedHoverBackground),e("--ogx-grid-cell-focus-border",o.cellFocusBorder),e("--ogx-grid-pinned-left-shadow",o.pinnedLeftShadow),e("--ogx-grid-pinned-right-shadow",o.pinnedRightShadow),e("--ogx-checkbox-bg",o.checkboxBg),e("--ogx-checkbox-border",o.checkboxBorder)}if(n.transitions){const o=n.transitions;e("--ogx-transition-duration-fast",o.durationFast),e("--ogx-transition-duration-normal",o.durationNormal),e("--ogx-transition-duration-slow",o.durationSlow),e("--ogx-transition-easing",o.easing)}if(n.toolbar){const o=n.toolbar;e("--ogx-toolbar-background",o.background),e("--ogx-toolbar-text",o.text),e("--ogx-toolbar-border",o.border),e("--ogx-toolbar-btn-bg",o.buttonBackground),e("--ogx-toolbar-btn-hover",o.buttonHoverBackground),e("--ogx-toolbar-btn-text",o.buttonText),e("--ogx-toolbar-btn-primary-bg",o.buttonPrimaryBackground),e("--ogx-toolbar-btn-primary-hover",o.buttonPrimaryHoverBackground),e("--ogx-toolbar-btn-primary-text",o.buttonPrimaryText),e("--ogx-toolbar-btn-danger-bg",o.buttonDangerBackground),e("--ogx-toolbar-btn-danger-hover",o.buttonDangerHoverBackground),e("--ogx-toolbar-btn-danger-text",o.buttonDangerText),e("--ogx-toolbar-input-bg",o.inputBackground),e("--ogx-toolbar-input-text",o.inputText),e("--ogx-toolbar-input-border",o.inputBorder),e("--ogx-toolbar-input-focus-border",o.inputFocusBorder),e("--ogx-toolbar-input-focus-shadow",o.inputFocusShadow),e("--ogx-toolbar-chip-bg",o.chipBackground),e("--ogx-toolbar-chip-text",o.chipText),e("--ogx-toolbar-chip-active-bg",o.chipActiveBackground),e("--ogx-toolbar-chip-active-text",o.chipActiveText)}if(n.overlays){const o=n.overlays;e("--ogx-overlay-background",o.background),e("--ogx-overlay-text",o.text),e("--ogx-overlay-border",o.border),e("--ogx-overlay-shadow",o.shadow),e("--ogx-overlay-item-hover-bg",o.itemHoverBackground),e("--ogx-overlay-item-hover-text",o.itemHoverText),e("--ogx-overlay-item-selected-bg",o.itemSelectedBackground),e("--ogx-overlay-item-selected-text",o.itemSelectedText),e("--ogx-overlay-item-danger-bg",o.itemDangerBackground),e("--ogx-overlay-item-danger-text",o.itemDangerText)}if(n.scrollbar){const o=n.scrollbar;e("--ogx-scrollbar-thumb",o.thumbColor),e("--ogx-scrollbar-track",o.trackColor),e("--ogx-scrollbar-size",o.size)}if(n.skeleton){const o=n.skeleton;e("--ogx-skeleton-base",o.baseColor),e("--ogx-skeleton-highlight",o.highlightColor),e("--ogx-skeleton-dark-base",o.darkBaseColor),e("--ogx-skeleton-dark-highlight",o.darkHighlightColor)}return t}function oi({theme:n,children:t,className:e,style:o}){const i=l.useMemo(()=>({...ti,...ni(n)}),[n]);return r.jsx("div",{className:`ogx-theme-provider ${e||""}`.trim(),style:{...o,...i},children:t})}const ri={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",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:"transparent",text:"#cbd5e1",border:"#334155",buttonBackground:"transparent",buttonHoverBackground:"#1e293b",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",darkBaseColor:"#0f172a",darkHighlightColor:"#1e293b"}},ii={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"}},li={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"}},si={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"}},ai={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function di(n,t){try{const e=t.getItem(n);return e?JSON.parse(e):void 0}catch{return}}function ci(n,t,e,o){try{const i=e?Object.fromEntries(Object.entries(t).filter(([s])=>e.includes(s))):t;o.setItem(n,JSON.stringify(i))}catch{}}function ui(n){const t=typeof n=="string"?{key:n}:n,{key:e,debounceMs:o=300,include:i,storage:s=typeof window<"u"?window.localStorage:void 0}=t,d=l.useMemo(()=>{if(s)return di(e,s)},[e,s]),a=l.useRef(null),u=l.useRef(null),c=l.useCallback(()=>{u.current&&s&&ci(e,u.current,i,s)},[e,i,s]),p=l.useCallback(h=>{u.current=h,a.current&&clearTimeout(a.current),a.current=setTimeout(c,o)},[c,o]);l.useEffect(()=>()=>{a.current&&(clearTimeout(a.current),c())},[c]);const m=l.useCallback(()=>{s&&s.removeItem(e)},[e,s]);return{initialState:d,onStateChange:p,clearState:m}}re.Button=ut,re.Cell=kn,re.Checkbox=ct,re.DataGrid=_r,re.DataGridThemeProvider=oi,re.FilterPanel=Nn,re.GridToolbar=Fr,re.GridTooltip=gt,re.Header=vn,re.Input=Ar,re.Row=yt,re.Skeleton=Cr,re.amberTheme=si,re.compactTheme=ai,re.darkTheme=ri,re.emeraldTheme=li,re.exportToCsv=Gr,re.exportToExcel=Vr,re.exportToExcelAdvanced=Zr,re.exportToJson=Ur,re.exportToPdf=Hr,re.formatAggregationValue=Ne,re.printGrid=Kr,re.roseTheme=ii,re.useAggregation=bn,re.useGridApiRef=Wr,re.useGridStateStorage=ui,re.usePivot=yn,Object.defineProperty(re,Symbol.toStringTag,{value:"Module"})}));
38
+ `),o.document.close(),await new Promise(i=>setTimeout(i,100));try{let i="Print",s,d=null,a=null,p;typeof e=="string"?i=e:typeof e=="object"&&(i=e.title||"Print",s=e.selectedRows,d=e.aggregationResult||null,a=e.aggregationModel||null,p=e.groupedRows);const c=t.filter(m=>!(m.exportable===!1||m.field==="__check__"||m.field==="__actions__"));let f=`<!DOCTYPE html><html><head><title>${i||"Print"}</title><style>
39
+ body{font-family:Arial,sans-serif;margin:20px;}
40
+ h1{font-size:24px;margin-bottom:20px;}
41
+ table{border-collapse:collapse;width:100%;}
42
+ th,td{border:1px solid #ddd;padding:8px;text-align:left;}
43
+ th{background-color:#f5f5f5;font-weight:bold;}
44
+ tr:nth-child(even){background-color:#f9f9f9;}
45
+ .group-header{background:#e8eaf6;font-weight:bold;}
46
+ .group-subtotal{background:#f0f4ff;font-style:italic;}
47
+ .grand-total{background:#f5f5f5;font-weight:bold;}
48
+ @media print{body{margin:0;}@page{margin:1cm;}}
49
+ </style></head><body>`;if(i&&(f+=`<h1>${we(i)}</h1>`),f+="<table><thead><tr>",c.forEach(m=>{f+=`<th>${we(m.headerName||m.field)}</th>`}),f+="</tr></thead><tbody>",p&&p.length>0){const m=a||{};p.forEach(u=>{if(u.type==="group-header"){const g=`${"&nbsp;".repeat(u.depth*4)}${we(u.groupField??"")}: ${we(String(u.groupValue??""))}`;f+=`<tr class="group-header"><td colspan="${c.length}">${g}</td></tr>`}else if(u.type==="leaf"&&u.row){const x=u.row,g="&nbsp;".repeat(u.depth*4);f+="<tr>",c.forEach((k,N)=>{let y=x[k.field];k.valueGetter&&(y=k.valueGetter({row:x,field:k.field,value:y})),k.valueFormatter&&y!==void 0&&y!==null&&(y=k.valueFormatter({value:y,row:x,field:k.field})),k.type==="image"&&y?f+=`<td><img src="${y}" style="max-height:40px;border-radius:4px;"></td>`:f+=`<td>${(N===0?g:"")+we(String(y??""))}</td>`}),f+="</tr>"}else if((u.type==="group-subtotal"||u.type==="grand-total")&&u.aggregatedValues){const x=u.type==="grand-total",g=x?"":"&nbsp;".repeat(u.depth*4),k=x?"Grand Total":`${g}Subtotal`;f+=`<tr class="${x?"grand-total":"group-subtotal"}">`,c.forEach((y,v)=>{if(v===0){f+=`<td>${k}</td>`;return}const j=u.aggregatedValues[y.field];if(j!=null){let b=j;y.valueFormatter?b=y.valueFormatter({value:j,row:{},field:y.field}):m[y.field]&&(b=_e(j,m[y.field])),f+=`<td style="text-align:right;">${we(String(b))}</td>`}else f+="<td></td>"}),f+="</tr>"}})}else{const m=s&&s.length>0?n.filter(u=>s.includes(u.id)):n;if(m.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}if(m.forEach(u=>{f+="<tr>",c.forEach(x=>{let g=u[x.field];x.valueGetter&&(g=x.valueGetter({row:u,field:x.field,value:g})),x.valueFormatter&&g!==void 0&&g!==null&&(g=x.valueFormatter({value:g,row:u,field:x.field})),x.type==="image"&&g?f+=`<td><div style="display:flex;justify-content:center;"><img src="${g}" alt="${x.headerName}" style="max-height:40px;border-radius:4px;"></div></td>`:f+=`<td>${we(String(g??""))}</td>`}),f+="</tr>"}),d){const u=a||{};f+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',c.forEach(x=>{f+=u[x.field]?`<td style="text-align:right;font-weight:bold;">${we(u[x.field].toUpperCase())}</td>`:"<td></td>"}),f+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',c.forEach(x=>{const g=d[x.field];if(g!=null){let k=g;x.valueFormatter?k=x.valueFormatter({value:g,row:{},field:x.field}):u[x.field]&&(k=_e(g,u[x.field])),f+=`<td style="text-align:right;">${we(String(k))}</td>`}else f+="<td></td>"}),f+="</tr></tfoot>"}}f+="</tbody></table></body></html>",o.document.open(),o.document.write(f),o.document.close(),o.document.title=i||"Print Preview",o.focus();let w=!1;o.onload=()=>{w||(w=!0,o.print(),setTimeout(()=>{o.close()},100))},setTimeout(()=>{!w&&o&&!o.closed&&(w=!0,o.print(),setTimeout(()=>{o.closed||o.close()},100))},500)}catch(i){if(console.error("Print generation failed:",i),o&&!o.closed){const s=i instanceof Error?i.message:String(i);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${s}</p></div>`}}}function Yt(n,t,e){const o=new Blob([n],{type:e}),i=URL.createObjectURL(o),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function Yr(n,t){return n.type==="number"?"number":n.type==="boolean"?"boolean":n.type==="date"?"date":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date?"date":"string"}function qr(n){if(n.type==="number")return"#,##0.##";if(n.type==="date")return"yyyy-mm-dd"}function Xr(n,t){if(t!=null)return t;const e=n.width??120;return Math.min(60,Math.max(8,(e-5)/7))}function Jr(n,t){const e=t??"";if(e.includes("jpeg")||e.includes("jpg"))return"jpeg";if(e.includes("gif"))return"gif";const o=n.split("?")[0].toLowerCase();return o.endsWith(".jpg")||o.endsWith(".jpeg")?"jpeg":o.endsWith(".gif")?"gif":"png"}async function Qr(n){const t=await Promise.allSettled(n.map(async o=>{if(o.startsWith("data:")){const a=o.indexOf(","),p=o.slice(0,a),c=o.slice(a+1),f=atob(c),w=new Uint8Array(f.length);for(let g=0;g<f.length;g++)w[g]=f.charCodeAt(g);const u=p.match(/data:([^;,]+)/)?.[1]??"image/png";let x="png";return u.includes("jpeg")||u.includes("jpg")?x="jpeg":u.includes("gif")&&(x="gif"),{url:o,buffer:w.buffer,ext:x}}const i=await fetch(o,{mode:"cors"});if(!i.ok)throw new Error(`HTTP ${i.status}`);const s=await i.arrayBuffer(),d=Jr(o,i.headers.get("content-type"));return{url:o,buffer:s,ext:d}})),e=new Map;return t.forEach((o,i)=>{o.status==="fulfilled"?e.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${n[i]}" (CORS/network error — raw URL written as fallback):`,o.reason)}),e}async function Zr(n,t,e={}){const{fileName:o="export.xlsx",sheets:i,columnStyles:s={},headerFillColor:d="#f1f5f9",headerTextColor:a="#334155",headerFontSize:p=10,bodyFontSize:c=10,aggregationResult:f=null,aggregationModel:w=null,selectedRows:m}=e,u=(await import("exceljs")).default,x=new u.Workbook;x.creator="OpenGridX",x.created=new Date;const g=t.filter(E=>E.exportable!==!1&&E.field!=="__check__"&&E.field!=="__actions__"&&!E.isSpacer),k=n,N=m&&m.length>0?n.filter(E=>m.includes(E.id)):n,y=i??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],v=new Map;for(const E of y){if("type"in E&&E.type==="summary"){if(!f||!w)continue;const C=x.addWorksheet(E.name??"Summary");C.addRow(["Summary / Aggregation Totals"]),C.getRow(1).font={bold:!0,size:p+2,color:{argb:Ae(a)}},C.addRow([]),C.addRow(["Column","Function","Value"]).eachCell(W=>{W.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ae(d)}},W.font={bold:!0,size:p,color:{argb:Ae(a)}},W.border=On()}),g.forEach(W=>{const R=w[W.field],z=f[W.field];if(R==null||z==null)return;let U=z;W.valueFormatter?U=W.valueFormatter({value:z,row:{},field:W.field}):U=_e(z,R);const G=C.addRow([W.headerName??W.field,R.toUpperCase(),U]);G.getCell(3).alignment={horizontal:"right"},G.getCell(3).font={bold:!0,size:c}}),C.getColumn(1).width=20,C.getColumn(2).width=12,C.getColumn(3).width=18;continue}const M=E,{name:I="Data",rows:_="all",includeHeaders:T=!0,includeSummary:L=!1,autoFilter:$=!0,frozenHeader:O=!0,alternateRowColor:H="#f8fafc"}=M,F=_==="selected"?N:k,D=g.filter(C=>s[C.field]?.embedImage);if(D.length>0){const C=[],P=new Set;if(F.forEach(W=>{D.forEach(R=>{const z=W[R.field];typeof z=="string"&&z&&!v.has(z)&&!P.has(z)&&(C.push(z),P.add(z))})}),C.length>0){const W=await Qr(C);for(const[R,{buffer:z,extension:U}]of W){const G=x.addImage({buffer:z,extension:U});v.set(R,G)}}}const q=x.addWorksheet(I);if(q.columns=g.map(C=>({key:C.field,width:Xr(C,s[C.field]?.width),style:{numFmt:s[C.field]?.numFmt??qr(C)}})),T){const C=g.map(W=>W.headerName??W.field),P=q.addRow(C);P.height=20,P.eachCell((W,R)=>{const z=g[R-1];W.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ae(d)}},W.font={bold:!0,size:p,color:{argb:Ae(a)}},W.alignment={horizontal:s[z?.field]?.alignment??(z?.type==="number"?"right":"left"),vertical:"middle"},W.border=On()}),$&&(q.autoFilter={from:{row:1,column:1},to:{row:1,column:g.length}}),O?q.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:q.views=[{showGridLines:!1}]}let K=T?1:0;if(F.forEach((C,P)=>{const W=g.map(z=>{if(s[z.field]?.embedImage)return"";let U=C[z.field];return z.valueGetter&&(U=z.valueGetter({row:C,field:z.field,value:U})),Yr(z,U)==="string"&&z.valueFormatter&&U!=null&&(U=z.valueFormatter({value:U,row:C,field:z.field})),U}),R=q.addRow(W);if(R.font={size:c},H&&P%2===1&&R.eachCell(z=>{z.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ae(H)}}}),R.eachCell((z,U)=>{const G=g[U-1];G&&(z.alignment={horizontal:s[G.field]?.alignment??(G.type==="number"?"right":"left"),vertical:"middle"},z.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}})}),D.length>0){const z=D.reduce((ne,A)=>Math.max(ne,s[A.field]?.imageHeight??40),0),U=Math.ceil(z/1.333),G=U*1.333;R.height=U,D.forEach(ne=>{const A=g.indexOf(ne),J=C[ne.field],ee=typeof J=="string"?v.get(J):void 0;if(ee===void 0){R.getCell(A+1).value=typeof J=="string"?J:"";return}const se=s[ne.field],re=se?.imageWidth??40,ve=se?.imageHeight??40,Q=(q.getColumn(A+1).width??8)*7+5,le=Math.max(0,Q-re)/2,B=Math.max(0,G-ve)/2;q.addImage(ee,{tl:{col:A,row:K,nativeColOff:Math.floor(le*9525),nativeRowOff:Math.floor(B*9525)},ext:{width:re,height:ve},editAs:"oneCell"})})}else R.height=16;K++}),L&&f&&w){const C=g.map(z=>{const U=w[z.field];return U?U.toUpperCase():""}),P=q.addRow(C);P.height=16,P.font={size:c-1,italic:!0,color:{argb:"FF94a3b8"}},P.eachCell(z=>{z.alignment={horizontal:"right",vertical:"middle"},z.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const W=g.map(z=>{const U=w[z.field],G=f[z.field];return U==null||G==null?"":z.valueFormatter?z.valueFormatter({value:G,row:{},field:z.field}):_e(G,U)}),R=q.addRow(W);R.height=18,R.font={bold:!0,size:c,color:{argb:Ae(a)}},R.eachCell(z=>{z.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ae(d)}},z.alignment={horizontal:"right",vertical:"middle"},z.border=ei()})}}const j=await x.xlsx.writeBuffer(),b=new Blob([j],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),S=URL.createObjectURL(b),h=document.createElement("a");h.href=S,h.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(S)}function Ae(n){const t=n.replace("#","");return t.length===3?"FF"+t.split("").map(e=>e+e).join(""):t.length===6?"FF"+t:"FF"+t.padEnd(6,"0")}function On(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function ei(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}const ti={"--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-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-grid-row-selected-background":"#eff6ff","--ogx-grid-row-selected-hover-background":"#dbeafe","--ogx-grid-cell-focus-border":"#3b82f6","--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":"transparent","--ogx-toolbar-text":"#1e293b","--ogx-toolbar-border":"#e2e8f0","--ogx-toolbar-btn-bg":"transparent","--ogx-toolbar-btn-hover":"#f1f5f9","--ogx-toolbar-btn-text":"#334155","--ogx-toolbar-btn-primary-bg":"#3b82f6","--ogx-toolbar-btn-primary-hover":"#2563eb","--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-bg":"#ffffff","--ogx-toolbar-input-text":"#1e293b","--ogx-toolbar-input-border":"#cbd5e1","--ogx-toolbar-input-focus-border":"#3b82f6","--ogx-toolbar-input-focus-shadow":"0 0 0 3px rgba(59, 130, 246, 0.12)","--ogx-toolbar-chip-bg":"#f1f5f9","--ogx-toolbar-chip-text":"#475569","--ogx-toolbar-chip-active-bg":"rgba(59, 130, 246, 0.12)","--ogx-toolbar-chip-active-text":"#2563eb","--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-selected-bg":"rgba(59, 130, 246, 0.08)","--ogx-overlay-item-selected-text":"#2563eb","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-overlay-item-danger-text":"#ef4444","--ogx-scrollbar-thumb":"rgba(148, 163, 184, 0.5)","--ogx-scrollbar-track":"transparent","--ogx-scrollbar-size":"10px","--ogx-skeleton-base":"#f1f5f9","--ogx-skeleton-highlight":"#ffffff","--ogx-skeleton-dark-base":"#e2e8f0","--ogx-skeleton-dark-highlight":"#f8fafc"};function ni(n){const t={};function e(o,i){i!==void 0&&(t[o]=i)}if(n.colors){const o=n.colors;e("--ogx-color-primary",o.primary),e("--ogx-color-primary-dark",o.primaryDark),e("--ogx-color-primary-light",o.primaryLight),e("--ogx-color-primary-focus",o.primaryFocus),e("--ogx-color-secondary",o.secondary),e("--ogx-color-secondary-dark",o.secondaryDark),e("--ogx-color-secondary-light",o.secondaryLight),e("--ogx-color-success",o.success),e("--ogx-color-warning",o.warning),e("--ogx-color-error",o.error),e("--ogx-color-info",o.info)}if(n.typography){const o=n.typography;e("--ogx-font-family",o.fontFamily),e("--ogx-font-family-mono",o.fontFamilyMono),e("--ogx-font-size-xs",o.fontSizeXs),e("--ogx-font-size-sm",o.fontSizeSm),e("--ogx-font-size-md",o.fontSizeMd),e("--ogx-font-size-lg",o.fontSizeLg),e("--ogx-font-size-xl",o.fontSizeXl)}if(n.spacing){const o=n.spacing;e("--ogx-spacing-xs",o.xs),e("--ogx-spacing-sm",o.sm),e("--ogx-spacing-md",o.md),e("--ogx-spacing-lg",o.lg),e("--ogx-spacing-xl",o.xl),e("--ogx-spacing-xxl",o.xxl)}if(n.borders){const o=n.borders;e("--ogx-border-width-thin",o.widthThin),e("--ogx-border-width-medium",o.widthMedium),e("--ogx-border-width-thick",o.widthThick),e("--ogx-border-radius-sm",o.radiusSm),e("--ogx-border-radius-md",o.radiusMd),e("--ogx-border-radius-lg",o.radiusLg),e("--ogx-border-radius-xl",o.radiusXl),e("--ogx-border-color",o.color),e("--ogx-border-color-hover",o.colorHover)}if(n.shadows){const o=n.shadows;e("--ogx-shadow-sm",o.sm),e("--ogx-shadow-md",o.md),e("--ogx-shadow-lg",o.lg),e("--ogx-shadow-xl",o.xl)}if(n.grid){const o=n.grid;e("--ogx-grid-row-height-compact",o.rowHeightCompact),e("--ogx-grid-row-height-standard",o.rowHeightStandard),e("--ogx-row-height",o.rowHeightStandard),e("--ogx-grid-row-height-comfortable",o.rowHeightComfortable),e("--ogx-grid-header-height",o.headerHeight),e("--ogx-header-height",o.headerHeight),e("--ogx-grid-cell-padding-x",o.cellPaddingX),e("--ogx-grid-cell-padding-y",o.cellPaddingY),e("--ogx-grid-background",o.background),e("--ogx-grid-border-color",o.borderColor),e("--ogx-grid-header-background",o.headerBackground),e("--ogx-grid-header-text",o.headerText),e("--ogx-grid-header-hover-background",o.headerHoverBackground),e("--ogx-grid-header-sorted-background",o.headerSortedBackground),e("--ogx-grid-row-text",o.rowText),e("--ogx-grid-row-hover-background",o.rowHoverBackground),e("--ogx-grid-row-alternate-background",o.rowAlternateBackground),e("--ogx-grid-row-selected-background",o.rowSelectedBackground),e("--ogx-grid-row-selected-hover-background",o.rowSelectedHoverBackground),e("--ogx-grid-cell-focus-border",o.cellFocusBorder),e("--ogx-grid-pinned-left-shadow",o.pinnedLeftShadow),e("--ogx-grid-pinned-right-shadow",o.pinnedRightShadow),e("--ogx-checkbox-bg",o.checkboxBg),e("--ogx-checkbox-border",o.checkboxBorder)}if(n.transitions){const o=n.transitions;e("--ogx-transition-duration-fast",o.durationFast),e("--ogx-transition-duration-normal",o.durationNormal),e("--ogx-transition-duration-slow",o.durationSlow),e("--ogx-transition-easing",o.easing)}if(n.toolbar){const o=n.toolbar;e("--ogx-toolbar-background",o.background),e("--ogx-toolbar-text",o.text),e("--ogx-toolbar-border",o.border),e("--ogx-toolbar-btn-bg",o.buttonBackground),e("--ogx-toolbar-btn-hover",o.buttonHoverBackground),e("--ogx-toolbar-btn-text",o.buttonText),e("--ogx-toolbar-btn-primary-bg",o.buttonPrimaryBackground),e("--ogx-toolbar-btn-primary-hover",o.buttonPrimaryHoverBackground),e("--ogx-toolbar-btn-primary-text",o.buttonPrimaryText),e("--ogx-toolbar-btn-danger-bg",o.buttonDangerBackground),e("--ogx-toolbar-btn-danger-hover",o.buttonDangerHoverBackground),e("--ogx-toolbar-btn-danger-text",o.buttonDangerText),e("--ogx-toolbar-input-bg",o.inputBackground),e("--ogx-toolbar-input-text",o.inputText),e("--ogx-toolbar-input-border",o.inputBorder),e("--ogx-toolbar-input-focus-border",o.inputFocusBorder),e("--ogx-toolbar-input-focus-shadow",o.inputFocusShadow),e("--ogx-toolbar-chip-bg",o.chipBackground),e("--ogx-toolbar-chip-text",o.chipText),e("--ogx-toolbar-chip-active-bg",o.chipActiveBackground),e("--ogx-toolbar-chip-active-text",o.chipActiveText)}if(n.overlays){const o=n.overlays;e("--ogx-overlay-background",o.background),e("--ogx-overlay-text",o.text),e("--ogx-overlay-border",o.border),e("--ogx-overlay-shadow",o.shadow),e("--ogx-overlay-item-hover-bg",o.itemHoverBackground),e("--ogx-overlay-item-hover-text",o.itemHoverText),e("--ogx-overlay-item-selected-bg",o.itemSelectedBackground),e("--ogx-overlay-item-selected-text",o.itemSelectedText),e("--ogx-overlay-item-danger-bg",o.itemDangerBackground),e("--ogx-overlay-item-danger-text",o.itemDangerText)}if(n.scrollbar){const o=n.scrollbar;e("--ogx-scrollbar-thumb",o.thumbColor),e("--ogx-scrollbar-track",o.trackColor),e("--ogx-scrollbar-size",o.size)}if(n.skeleton){const o=n.skeleton;e("--ogx-skeleton-base",o.baseColor),e("--ogx-skeleton-highlight",o.highlightColor),e("--ogx-skeleton-dark-base",o.darkBaseColor),e("--ogx-skeleton-dark-highlight",o.darkHighlightColor)}return t}function oi({theme:n,children:t,className:e,style:o}){const i=l.useMemo(()=>({...ti,...ni(n)}),[n]);return r.jsx("div",{className:`ogx-theme-provider ${e||""}`.trim(),style:{...o,...i},children:t})}const ri={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",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:"transparent",text:"#cbd5e1",border:"#334155",buttonBackground:"transparent",buttonHoverBackground:"#1e293b",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",darkBaseColor:"#0f172a",darkHighlightColor:"#1e293b"}},ii={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"}},li={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"}},si={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"}},ai={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function di(n,t){try{const e=t.getItem(n);return e?JSON.parse(e):void 0}catch{return}}function ci(n,t,e,o){try{const i=e?Object.fromEntries(Object.entries(t).filter(([s])=>e.includes(s))):t;o.setItem(n,JSON.stringify(i))}catch{}}function ui(n){const t=typeof n=="string"?{key:n}:n,{key:e,debounceMs:o=300,include:i,storage:s=typeof window<"u"?window.localStorage:void 0}=t,d=l.useMemo(()=>{if(s)return di(e,s)},[e,s]),a=l.useRef(null),p=l.useRef(null),c=l.useCallback(()=>{p.current&&s&&ci(e,p.current,i,s)},[e,i,s]),f=l.useCallback(m=>{p.current=m,a.current&&clearTimeout(a.current),a.current=setTimeout(c,o)},[c,o]);l.useEffect(()=>()=>{a.current&&(clearTimeout(a.current),c())},[c]);const w=l.useCallback(()=>{s&&s.removeItem(e)},[e,s]);return{initialState:d,onStateChange:f,clearState:w}}ie.Button=gt,ie.Cell=Sn,ie.Checkbox=ft,ie.DataGrid=Cr,ie.DataGridThemeProvider=oi,ie.FilterPanel=Mn,ie.GridToolbar=Wr,ie.GridTooltip=pt,ie.Header=_n,ie.Input=$r,ie.Row=Mt,ie.Skeleton=yr,ie.amberTheme=si,ie.compactTheme=ai,ie.darkTheme=ri,ie.emeraldTheme=li,ie.exportToCsv=Gr,ie.exportToExcel=Vr,ie.exportToExcelAdvanced=Zr,ie.exportToJson=Ur,ie.exportToPdf=Hr,ie.formatAggregationValue=_e,ie.printGrid=Kr,ie.roseTheme=ii,ie.useAggregation=wn,ie.useGridApiRef=Ar,ie.useGridStateStorage=ui,ie.usePivot=kn,Object.defineProperty(ie,Symbol.toStringTag,{value:"Module"})}));
53
50
  //# sourceMappingURL=opengridx.umd.js.map