@opencorestack/opengridx 2.0.1 → 2.0.3

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,11 +1,11 @@
1
- (function(ae,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],i):(ae=typeof globalThis<"u"?globalThis:ae||self,i(ae.OpenGridX={},ae.React,ae.ReactDOM))})(this,(function(ae,i,Ge){"use strict";var Rt={exports:{}},gt={};var vn;function lo(){if(vn)return gt;vn=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(o,l,s){var d=null;if(s!==void 0&&(d=""+s),l.key!==void 0&&(d=""+l.key),"key"in l){s={};for(var a in l)a!=="key"&&(s[a]=l[a])}else s=l;return l=s.ref,{$$typeof:n,type:o,key:d,ref:l!==void 0?l:null,props:s}}return gt.Fragment=t,gt.jsx=e,gt.jsxs=e,gt}var ht={};var _n;function so(){return _n||(_n=1,process.env.NODE_ENV!=="production"&&(function(){function n(v){if(v==null)return null;if(typeof v=="function")return v.$$typeof===y?null:v.displayName||v.name||null;if(typeof v=="string")return v;switch(v){case C:return"Fragment";case _:return"Profiler";case E:return"StrictMode";case k:return"Suspense";case u:return"SuspenseList";case L: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 x:return"Portal";case N:return v.displayName||"Context";case S:return(v._context.displayName||"Context")+".Consumer";case g:var M=v.render;return v=v.displayName,v||(v=M.displayName||M.name||"",v=v!==""?"ForwardRef("+v+")":"ForwardRef"),v;case j:return M=v.displayName||null,M!==null?M:n(v.type)||"Memo";case P:M=v._payload,v=v._init;try{return n(v(M))}catch{}}return null}function t(v){return""+v}function e(v){try{t(v);var M=!1}catch{M=!0}if(M){M=console;var F=M.error,O=typeof Symbol=="function"&&Symbol.toStringTag&&v[Symbol.toStringTag]||v.constructor.name||"Object";return F.call(M,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",O),t(v)}}function o(v){if(v===C)return"<>";if(typeof v=="object"&&v!==null&&v.$$typeof===P)return"<...>";try{var M=n(v);return M?"<"+M+">":"<...>"}catch{return"<...>"}}function l(){var v=T.A;return v===null?null:v.getOwner()}function s(){return Error("react-stack-top-frame")}function d(v){if(I.call(v,"key")){var M=Object.getOwnPropertyDescriptor(v,"key").get;if(M&&M.isReactWarning)return!1}return v.key!==void 0}function a(v,M){function F(){D||(D=!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)",M))}F.isReactWarning=!0,Object.defineProperty(v,"key",{get:F,configurable:!0})}function c(){var v=n(this.type);return W[v]||(W[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 h(v,M,F,O,H,K){var V=F.ref;return v={$$typeof:m,type:v,key:M,props:F,_owner:O},(V!==void 0?V:null)!==null?Object.defineProperty(v,"ref",{enumerable:!1,get:c}):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:H}),Object.defineProperty(v,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.freeze&&(Object.freeze(v.props),Object.freeze(v)),v}function p(v,M,F,O,H,K){var V=M.children;if(V!==void 0)if(O)if(A(V)){for(O=0;O<V.length;O++)w(V[O]);Object.freeze&&Object.freeze(V)}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(V);if(I.call(M,"key")){V=n(v);var oe=Object.keys(M).filter(function(ne){return ne!=="key"});O=0<oe.length?"{key: someKey, "+oe.join(": ..., ")+": ...}":"{key: someKey}",U[V+O]||(oe=0<oe.length?"{"+oe.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ (function(ae,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],i):(ae=typeof globalThis<"u"?globalThis:ae||self,i(ae.OpenGridX={},ae.React,ae.ReactDOM))})(this,(function(ae,i,Ge){"use strict";var Rt={exports:{}},ht={};var Cn;function lo(){if(Cn)return ht;Cn=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(o,l,s){var d=null;if(s!==void 0&&(d=""+s),l.key!==void 0&&(d=""+l.key),"key"in l){s={};for(var a in l)a!=="key"&&(s[a]=l[a])}else s=l;return l=s.ref,{$$typeof:n,type:o,key:d,ref:l!==void 0?l:null,props:s}}return ht.Fragment=t,ht.jsx=e,ht.jsxs=e,ht}var pt={};var yn;function so(){return yn||(yn=1,process.env.NODE_ENV!=="production"&&(function(){function n(v){if(v==null)return null;if(typeof v=="function")return v.$$typeof===y?null:v.displayName||v.name||null;if(typeof v=="string")return v;switch(v){case C:return"Fragment";case _:return"Profiler";case E:return"StrictMode";case k:return"Suspense";case u:return"SuspenseList";case L: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 x:return"Portal";case N:return v.displayName||"Context";case S:return(v._context.displayName||"Context")+".Consumer";case g:var M=v.render;return v=v.displayName,v||(v=M.displayName||M.name||"",v=v!==""?"ForwardRef("+v+")":"ForwardRef"),v;case j:return M=v.displayName||null,M!==null?M:n(v.type)||"Memo";case P:M=v._payload,v=v._init;try{return n(v(M))}catch{}}return null}function t(v){return""+v}function e(v){try{t(v);var M=!1}catch{M=!0}if(M){M=console;var F=M.error,O=typeof Symbol=="function"&&Symbol.toStringTag&&v[Symbol.toStringTag]||v.constructor.name||"Object";return F.call(M,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",O),t(v)}}function o(v){if(v===C)return"<>";if(typeof v=="object"&&v!==null&&v.$$typeof===P)return"<...>";try{var M=n(v);return M?"<"+M+">":"<...>"}catch{return"<...>"}}function l(){var v=T.A;return v===null?null:v.getOwner()}function s(){return Error("react-stack-top-frame")}function d(v){if(I.call(v,"key")){var M=Object.getOwnPropertyDescriptor(v,"key").get;if(M&&M.isReactWarning)return!1}return v.key!==void 0}function a(v,M){function F(){D||(D=!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)",M))}F.isReactWarning=!0,Object.defineProperty(v,"key",{get:F,configurable:!0})}function c(){var v=n(this.type);return W[v]||(W[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 h(v,M,F,O,H,V){var U=F.ref;return v={$$typeof:m,type:v,key:M,props:F,_owner:O},(U!==void 0?U:null)!==null?Object.defineProperty(v,"ref",{enumerable:!1,get:c}):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:H}),Object.defineProperty(v,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.freeze&&(Object.freeze(v.props),Object.freeze(v)),v}function p(v,M,F,O,H,V){var U=M.children;if(U!==void 0)if(O)if(A(U)){for(O=0;O<U.length;O++)w(U[O]);Object.freeze&&Object.freeze(U)}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(U);if(I.call(M,"key")){U=n(v);var oe=Object.keys(M).filter(function(ne){return ne!=="key"});O=0<oe.length?"{key: someKey, "+oe.join(": ..., ")+": ...}":"{key: someKey}",K[U+O]||(oe=0<oe.length?"{"+oe.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} />`,O,V,oe,V),U[V+O]=!0)}if(V=null,F!==void 0&&(e(F),V=""+F),d(M)&&(e(M.key),V=""+M.key),"key"in M){F={};for(var ie in M)ie!=="key"&&(F[ie]=M[ie])}else F=M;return V&&a(F,typeof v=="function"?v.displayName||v.name||"Unknown":v),h(v,V,F,l(),H,K)}function w(v){b(v)?v._store&&(v._store.validated=1):typeof v=="object"&&v!==null&&v.$$typeof===P&&(v._payload.status==="fulfilled"?b(v._payload.value)&&v._payload.value._store&&(v._payload.value._store.validated=1):v._store&&(v._store.validated=1))}function b(v){return typeof v=="object"&&v!==null&&v.$$typeof===m}var f=i,m=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),E=Symbol.for("react.strict_mode"),_=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),N=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),L=Symbol.for("react.activity"),y=Symbol.for("react.client.reference"),T=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,A=Array.isArray,$=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(v){return v()}};var D,W={},z=f.react_stack_bottom_frame.bind(f,s)(),Y=$(o(s)),U={};ht.Fragment=C,ht.jsx=function(v,M,F){var O=1e4>T.recentlyCreatedOwnerStacks++;return p(v,M,F,!1,O?Error("react-stack-top-frame"):z,O?$(o(v)):Y)},ht.jsxs=function(v,M,F){var O=1e4>T.recentlyCreatedOwnerStacks++;return p(v,M,F,!0,O?Error("react-stack-top-frame"):z,O?$(o(v)):Y)}})()),ht}var Cn;function ao(){return Cn||(Cn=1,process.env.NODE_ENV==="production"?Rt.exports=lo():Rt.exports=so()),Rt.exports}var r=ao();function pt(n,t){return t?t.left?.includes(n)?"left":t.right?.includes(n)?"right":null:null}function co(n,t){const e=[],o=[],l=[];return t?(n.forEach(s=>{const d=pt(s.field,t);d==="left"?e.push(s):d==="right"?l.push(s):o.push(s)}),t.left&&e.sort((s,d)=>{const a=t.left.indexOf(s.field),c=t.left.indexOf(d.field);return a-c}),t.right&&l.sort((s,d)=>{const a=t.right.indexOf(s.field),c=t.right.indexOf(d.field);return a-c}),{left:e,center:o,right:l}):{left:e,center:n,right:l}}function qt(n,t,e,o,l,s,d,a){const c={};if(!e)return c;const h=co(n,e);let p=0;a&&(p+=48),s&&d&&(p+=48),o&&l&&(p+=48),h.left.forEach(b=>{c[b.field]=p;const f=t[b.field]??b.width??100;p+=f});let w=0;return[...h.right].reverse().forEach(b=>{const f=t[b.field]??b.width??100;c[b.field]=w,w+=f}),c}function Xt(n,t){return t?t.top?.includes(n)?"top":t.bottom?.includes(n)?"bottom":null:null}function uo(n,t){const e=[],o=[],l=[];return t?(n.forEach(s=>{const d=Xt(s.id,t);d==="top"?e.push(s):d==="bottom"?l.push(s):o.push(s)}),t.top&&e.sort((s,d)=>{const a=t.top.indexOf(s.id),c=t.top.indexOf(d.id);return a-c}),t.bottom&&l.sort((s,d)=>{const a=t.bottom.indexOf(s.id),c=t.bottom.indexOf(d.id);return a-c}),{top:e,center:o,bottom:l}):{top:e,center:n,bottom:l}}function qe(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 fo(n){const{rowHeight:t,pagination:e,paginatedUnpinnedRows:o,sortedUnpinnedRows:l,expandedRowIds:s,getDetailPanelHeight:d,pinnedTopRowsLength:a,pinnedBottomRowsLength:c,visibleOrderedColumns:h,pinnedColumns:p,columnWidths:w,viewportWidth:b,checkboxSelection:f,hasDetailPanel:m,rowReordering:x,paginationMode:C,isLoading:E,pageSize:_}=n;return i.useMemo(()=>{const S=e?o:l,N=S.map((B,Q)=>{let Z=t;if(s.has(B.id)){const ge=d?.({row:B,id:B.id,rowIndex:a+Q})??200;Z+=typeof ge=="number"?ge:parseInt(String(ge),10)||200}return Z}),g=N.reduce((B,Q,Z)=>(B.push((B[Z-1]||0)+Q),B),[]),k=C==="infinite"&&E&&S.length>0?Math.min(_,20):0,u=(g[g.length-1]||0)+k*t,j=a*t,P=c*t,L=[],y=[],T=[],I=[];h.forEach(B=>{const Q=pt(B.field,p);Q==="left"?L.push(B):Q==="right"?y.push(B):T.push(B)});const A=(f?48:0)+(m?48:0)+(x?48:0),$=B=>w[B.field]??B.width,D=L.reduce((B,Q)=>{const Z=qe($(Q));return B+(Z.type==="fixed"?Z.value:100)},0),W=y.reduce((B,Q)=>{const Z=qe($(Q));return B+(Z.type==="fixed"?Z.value:100)},0),z=T.reduce((B,Q)=>{if(!Object.prototype.hasOwnProperty.call(w,Q.field)&&Q.flex&&Q.flex>0){const ue=Q.minWidth??150,Ee=typeof Q.width=="number"?Q.width:150;return B+(ue||Ee)}const ge=qe($(Q));return ge.type==="fixed"?B+ge.value:ge.type==="percentage"?B+100:B+(Q.minWidth??150)},0),Y=Math.max(b-A-D-W,z),U=[],v=[],M=[];T.forEach(B=>{const Q=Object.prototype.hasOwnProperty.call(w,B.field),Z=qe($(B));if(!Q&&B.flex&&B.flex>0){M.push({col:B,flex:B.flex});return}Z.type==="fixed"?U.push({col:B,width:Z.value}):Z.type==="percentage"?v.push({col:B,percentage:Z.value}):M.push({col:B,flex:1})});const F=U.reduce((B,{width:Q})=>B+Q,0);let O=Math.max(0,Y-F);const H=new Map;v.forEach(({col:B,percentage:Q})=>{const Z=Q/100*O;H.set(B.field,Z),O-=Z}),O=Math.max(0,O);const K=new Map,V=M.map(B=>({...B,minWidth:B.col.minWidth??50,maxWidth:B.col.maxWidth??1/0,frozen:!1,computedWidth:0}));(()=>{let B=0;const Q=V.length*2;for(;B<Q;){B++;const Z=V.filter(ee=>!ee.frozen);if(Z.length===0)break;const ge=Z.reduce((ee,ye)=>ee+ye.flex,0),ue=V.reduce((ee,ye)=>ye.frozen?ee+ye.computedWidth:ee,0),Ee=Math.max(0,O-ue);if(ge<=0){Z.forEach(ee=>{ee.computedWidth=ee.minWidth,ee.frozen=!0});break}const Te=Ee/ge;let Pe=0;const Re=[],ze=[];if(Z.forEach(ee=>{const ye=Te*ee.flex;ye<ee.minWidth?(Pe+=ee.minWidth-ye,Re.push(ee)):ye>ee.maxWidth?(Pe+=ee.maxWidth-ye,ze.push(ee)):ee.computedWidth=ye}),Re.length===0&&ze.length===0){Z.forEach(ee=>ee.frozen=!0);break}Pe>0?Re.forEach(ee=>{ee.computedWidth=ee.minWidth,ee.frozen=!0}):Pe<0?ze.forEach(ee=>{ee.computedWidth=ee.maxWidth,ee.frozen=!0}):(Re.forEach(ee=>{ee.computedWidth=ee.minWidth,ee.frozen=!0}),ze.forEach(ee=>{ee.computedWidth=ee.maxWidth,ee.frozen=!0}))}})(),V.forEach(B=>K.set(B.col.field,B.computedWidth));const ie=new Map;T.forEach(B=>{let Q;if(K.has(B.field))Q=K.get(B.field);else{const Z=U.find(ue=>ue.col.field===B.field),ge=v.find(ue=>ue.col.field===B.field);if(Z)Q=Z.width;else if(ge){const ue=H.get(B.field)||0;Q=Math.max(B.minWidth??50,ue||100)}else Q=100}I.push(Q),ie.set(B.field,Q)});const ne=T.map(B=>{const Q=V.find(Z=>Z.col.field===B.field);return{...B,width:ie.get(B.field)??(typeof B.width=="number"?B.width:100),flex:Q?Q.flex:B.flex}}),R=11,le=L.map((B,Q)=>{const Z=qe($(B));return{...B,width:Z.type==="fixed"?Z.value:100,zIndex:R+Q}}),te=11,re=y.map((B,Q)=>{const Z=qe($(B));return{...B,width:Z.type==="fixed"?Z.value:100,zIndex:te+(y.length-1-Q)}}),q=I.reduce((B,Q)=>B+Q,0),J=D+q+W+A,de=I.reduce((B,Q,Z)=>(B.push((B[Z-1]||0)+Q),B),[]);return{rowHeights:N,cumulativeHeights:g,unpinnedRowsHeight:u,pinnedTopHeight:j,pinnedBottomHeight:P,leftPinnedCols:le,rightPinnedCols:re,unpinnedColsWithWidth:ne,unpinnedColWidths:I,unpinnedAccWidths:de,totalWidth:J,leftWidth:D,rightWidth:W,unpinnedTotalWidth:q,systemColumnsWidth:A,pinnedTopRowsLength:a,pinnedBottomRowsLength:c,unpinnedRowsLength:S.length}},[t,e,o,l,s,d,a,c,h,p,w,b,f,m,x,C,E,_])}function go(n){const{allRenderableRows:t,navigationColumns:e,checkboxSelection:o,selectedRowIds:l,handleSelectionChange:s,handleDetailPanelToggle:d,editingHandlers:a,setKeyboardMode:c,sortModel:h,handleSort:p,isCellEditable:w,pagination:b,pageSize:f,virtualization:m,viewportRef:x}=n,[C,E]=i.useState(null),_=i.useCallback(g=>{g.target===g.currentTarget&&E(k=>{if(k)return k;if(o)return{id:"HEADER",field:"__checkbox_col__"};const u=t[0],j=e[0];return u&&j?{id:u.id,field:j.field}:null})},[t,e,o]),S=i.useCallback(g=>{g.currentTarget.contains(g.relatedTarget)||E(null)},[]),N=i.useCallback(g=>{if(c(!0),!C)return;const{id:k,field:u}=C,j=!!a.editingCell;if(k==="HEADER"&&(g.key==="Enter"||g.key===" ")){g.preventDefault();const W=e.find(z=>z.field===u);if(W&&W.sortable!==!1){const z=h.find(U=>U.field===u);let Y="asc";z&&(Y=z.sort==="asc"?"desc":null),p(u,Y)}return}if(g.key==="Enter"){if(g.preventDefault(),j)a.stopCellEdit();else if(e.find(z=>z.field===u)?.editable){const z=t.find(Y=>Y.id===k);z&&a.startCellEdit({id:k,field:u,value:z[u]})}return}if((g.key===" "||g.key==="Spacebar")&&!j){if(u==="__checkbox_col__"){g.preventDefault(),s(k,!l.has(k));return}if(u==="__expand_col__"){g.preventDefault(),d(k);return}}if(g.key==="Escape"){j&&(g.preventDefault(),a.stopCellEdit({cancel:!0}));return}if(j&&g.key!=="Tab")return;const P=k==="HEADER",L=P?-1:t.findIndex(W=>W.id===k),y=e.findIndex(W=>W.field===u);if(!P&&L===-1||y===-1)return;const T=(W,z,Y,U,v,M=!1)=>{let F=W+Y,O=z+U;return v&&U!==0&&(U>0&&O>=e.length?(O=0,F++):U<0&&O<0&&(O=e.length-1,F--)),!v&&(O<0||O>=e.length)||F<(M?-1:0)||F>=t.length?null:{r:F,c:O}},I=(W,z,Y,U,v,M=!1)=>{let F=W,O=z,H=0;const K=t.length*e.length+e.length;for(;H<K;){if(H++,F+=Y,O+=U,U!==0)U>0?O>=e.length&&(O=0,F++):O<0&&(O=e.length-1,F--);else if(O<0||O>=e.length)return null;if(F<-1||F>=t.length)return null;if(F===-1){if(!M)continue;const R=e[O],le=R.sortable!==!1;if(["__checkbox_col__"].includes(R.field)||le)return{r:F,c:O};continue}const V=t[F],oe=e[O],ie=["__checkbox_col__","__expand_col__","__reorder_col__"].includes(oe.field);let ne=oe.editable||ie;if(w&&!ie)try{ne=w({row:V,field:oe.field,value:V[oe.field],colDef:oe,rowIndex:F,colIndex:O})}catch{}if(ne)return{r:F,c:O}}return null};let A=L,$=y,D=!1;if(g.key==="Tab"){const W=g.shiftKey?-1:1,z=I(L,y,0,W,!0,!1);z&&(A=z.r,$=z.c,D=!0)}else if(g.key==="ArrowRight"){const W=T(L,y,0,1,!0,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="ArrowLeft"){const W=T(L,y,0,-1,!0,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="ArrowDown"){const W=T(L,y,1,0,!1,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="ArrowUp"){const W=T(L,y,-1,0,!1,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="Home")$=0,(g.ctrlKey||g.metaKey)&&(A=-1),D=!0;else if(g.key==="End")$=e.length-1,(g.ctrlKey||g.metaKey)&&(A=t.length-1),D=!0;else if(g.key==="PageUp")A=Math.max(-1,A-(b?f:10)),D=!0;else if(g.key==="PageDown"){const W=b?f:10;A=Math.min(t.length-1,A+W),D=!0}if(D&&(g.preventDefault(),j&&g.key==="Tab"&&a.stopCellEdit(),A>=-1&&A<t.length&&$>=0&&$<e.length)){const W=e[$];E(A===-1?{id:"HEADER",field:W.field}:{id:t[A].id,field:W.field});const z=x.current;if(z){const{cumulativeHeights:Y,pinnedTopHeight:U,columnMetrics:v}=m,{clientHeight:M,clientWidth:F,scrollTop:O,scrollLeft:H}=z,K=A<=0?0:Y[A-1],V=Y[A],oe=O+U,ie=O+M;let ne=O;if(K<oe?ne=Math.max(0,K-U):V>ie&&(ne=V-M),ne!==O&&(z.scrollTop=ne),v){const{leftPinnedWidth:R,rightPinnedWidth:le,unpinnedAccWidths:te,unpinnedCols:re,totalSpecialsWidth:q,pinnedSpecialsWidth:J}=v,de=re.findIndex(B=>B.field===W.field);if(de!==-1){const B=q+R+(de>0?te[de-1]:0),Q=q+R+te[de],Z=H+J+R,ge=H+F-le;let ue=H;B<Z?ue=Math.max(0,B-J-R):Q>ge&&(ue=Q-F+le),ue!==H&&(z.scrollLeft=ue)}}}}},[C,t,e,a,m,l,s,d,c,h,p,w,b,f,x]);return{focusedCell:C,setFocusedCell:E,handleFocus:_,handleBlur:S,handleKeyDown:N}}const ho={rowFields:[],columnFields:[],valueFields:[]};function po(n){const{initialState:t,sortModel:e,aggregationModel:o,onAggregationModelChange:l,columnVisibilityModel:s,onColumnVisibilityModelChange:d,pinnedColumns:a,onPinnedColumnsChange:c,pivotModel:h,onPivotModelChange:p,paginationModel:w,onPaginationModelChange:b,rowSelectionModel:f}=n,[m,x]=i.useState(()=>t?.sorting?.sortModel??[]),C=e!==void 0,E=C?e:m,_=o!==void 0,[S,N]=i.useState(()=>o??{}),g=_?o:S,k=i.useCallback(R=>{_||N(R),l?.(R)},[_,l]),u=s!==void 0,[j,P]=i.useState(()=>t?.columns?.columnVisibilityModel??{}),L=u?s:j,y=i.useCallback(R=>{u||P(R),d?.(R)},[u,d]),T=a!==void 0,[I,A]=i.useState(()=>t?.columns?.pinnedColumns??{}),$=T?a:I,D=i.useCallback(R=>{T||A(R),c?.(R)},[T,c]),[W,z]=i.useState(()=>h??ho),Y=h??W,U=i.useCallback(R=>{z(R),p?.(R)},[p]),v=w!==void 0,[M,F]=i.useState(()=>t?.pagination?.paginationModel??w??{page:0,pageSize:100}),O=v?w:M,H=i.useCallback(R=>{v||F(R),b?.(R)},[v,b]),K=f!==void 0,[V,oe]=i.useState([]),ie=K?f:V,ne=i.useMemo(()=>new Set(ie),[ie]);return{sortModel:E,isSortControlled:C,setInternalSortModel:x,aggregationModel:g,handleAggregationModelChange:k,columnVisibilityModel:L,handleColumnVisibilityModelChange:y,pinnedColumns:$,handlePinnedColumnsChange:D,currentPivotModel:Y,handlePivotModelChange:U,effectivePaginationModel:O,handlePaginationModelChange:H,rowSelectionModel:ie,selectedRowIds:ne,isSelectionControlled:K,setInternalRowSelectionModel:oe}}const xo={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 mo(n,t){const{field:e,operator:o,value:l}=t,s=n[e],d=xo[o];return d?d(s,l):(console.warn(`Unknown filter operator: ${o}`),!0)}function bo(n,t){return!t||t.length===0?!0:t.every(e=>{const o=e.toLowerCase();return Object.values(n).some(l=>l==null?!1:String(l).toLowerCase().includes(o))})}function Jt(n,t){const e=t.items??[],o=t.logicOperator??"and",l=("quickFilterValues"in t?t.quickFilterValues:void 0)??[];if(l.length>0&&!bo(n,l))return!1;if(e.length===0)return!0;const s=d=>{if("logicOperator"in d&&"items"in d){const a=d,c=a.items;return c.length===0?!0:a.logicOperator==="and"?c.every(s):c.some(s)}else return mo(n,d)};return o==="and"?e.every(s):e.some(s)}function wo(n,t){if(!t)return n;const{items:e=[],quickFilterValues:o=[]}=t;return e.length===0&&(!o||o.length===0)?n:n.filter(l=>Jt(l,t))}function vo(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 Qt(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(),l=String(t).toLowerCase();return e==="asc"?o<l?-1:o>l?1:0:o>l?-1:o<l?1:0}function _o(n,t){if(t.length===0)return n;const e=[...n];return e.sort((o,l)=>{for(const s of t){const d=o[s.field],a=l[s.field],c=Qt(d,a,s.sort);if(c!==0)return c}return 0}),e}function Co(n){const{effectiveRows:t,activeHierarchyHandlers:e,filterMode:o,filterModel:l,dataSource:s,sortModel:d,sortingMode:a,pagination:c,paginationMode:h,effectivePaginationModel:p,pinnedRows:w,isLoading:b,pageSize:f}=n,m=i.useMemo(()=>e?e.getVisibleRows()||[]:o==="server"&&s?t:wo(t,l),[t,l,e,o,s]),{top:x,center:C,bottom:E}=i.useMemo(()=>e?{top:[],center:m,bottom:[]}:uo(m,w),[m,w,e]),_=i.useMemo(()=>e||a==="server"&&s?C:_o(C,d),[C,d,e,a,s]),S=i.useMemo(()=>{if(!c||h==="server"&&s)return _;const g=p.page*p.pageSize;return _.slice(g,g+p.pageSize)},[_,c,p.page,p.pageSize,h,s]),N=i.useMemo(()=>{if(e)return C;const g=c?S:_,k=[...x,...g,...E];if(h==="infinite"&&b&&k.length>0){const u=Math.min(f,20),j=Array.from({length:u},(P,L)=>({id:`__skeleton_${L}__`,_isSkeleton:!0}));return[...k,...j]}return k},[x,S,_,E,c,e,C,h,b,f]);return{filteredRows:m,pinnedTopRows:x,unpinnedRows:C,pinnedBottomRows:E,sortedUnpinnedRows:_,paginatedUnpinnedRows:S,allRenderableRows:N}}function yo(n){const{layout:t,scrollTop:e,scrollLeft:o,viewportWidth:l,viewportHeight:s,autoHeight:d,rowReordering:a,hasDetailPanel:c,checkboxSelection:h,pinCheckboxColumn:p,pinExpandColumn:w}=n;return i.useMemo(()=>{const{unpinnedAccWidths:b,unpinnedColsWithWidth:f,leftPinnedCols:m,rightPinnedCols:x,totalWidth:C,leftWidth:E,rightWidth:_,unpinnedTotalWidth:S,systemColumnsWidth:N,cumulativeHeights:g,pinnedTopHeight:k,pinnedBottomHeight:u,unpinnedRowsHeight:j,rowHeights:P,unpinnedRowsLength:L}=t,y=l||1e3,T=d?k+j+u+50:s||600,I=6,A=Math.max(0,o-E),$=o+y-E;let D=0,W=f.length-1,z=0,Y=b.length-1;for(;z<=Y;){const te=z+Y>>>1;b[te]<A?z=te+1:Y=te-1}D=Math.max(0,z-I);for(let te=D;te<b.length;te++){if((te===0?0:b[te-1])>$){W=Math.min(f.length-1,te+I);break}W=Math.min(f.length-1,te+I)}const U=D>0?b[D-1]:0,v=S-b[W],M=[...m,...U>0?[{field:"__spacer_left__",width:U,isSpacer:!0}]:[],...f.slice(D,W+1),...v>0?[{field:"__spacer_right__",width:v,isSpacer:!0}]:[],...x],O=y>0&&C>y?16:0,H=k+j+u+O+2,K=5;let V=0,oe=L-1,ie=0,ne=0,R=g.length-1;for(;ne<=R;){const te=ne+R>>>1;g[te]<e?ne=te+1:R=te-1}V=Math.max(0,ne-K),ie=V>0?g[V-1]:0;for(let te=V;te<g.length;te++)if(g[te]>=e+T){oe=Math.min(L-1,te+K);break}const le=(a?48:0)+(c&&w?48:0)+(h&&p?48:0);return{renderContext:{firstRowIndex:V,lastRowIndex:oe,firstColumnIndex:D,lastColumnIndex:W},offsetTop:ie,offsetLeft:0,totalHeight:H,pinnedTopHeight:k,pinnedBottomHeight:u,totalWidth:C,rowHeights:P,cumulativeHeights:g,virtualColumns:M,columnMetrics:{leftPinnedWidth:E,rightPinnedWidth:_,unpinnedAccWidths:b,unpinnedCols:f,totalSpecialsWidth:N,pinnedSpecialsWidth:le}}},[t,e,o,l,s,d,a,c,h,p,w])}function ko(n){const{columns:t,onColumnOrderChange:e,disableColumnReorder:o=!1}=n,[l,s]=i.useState(null),[d,a]=i.useState(null),c=i.useRef(-1),h=i.useCallback(f=>m=>{if(o)return;const x=t.findIndex(E=>E.field===f);if(t[x]?.pinnable===!1){m.preventDefault();return}s(f),c.current=x,m.dataTransfer&&(m.dataTransfer.effectAllowed="move",m.dataTransfer.setData("text/plain",f))},[t,o]),p=i.useCallback(f=>m=>{o||!l||(m.preventDefault(),m.dataTransfer.dropEffect="move",a(f))},[l,o]),w=i.useCallback(f=>m=>{if(m.preventDefault(),o||!l||l===f){s(null),a(null);return}const x=t.findIndex(_=>_.field===l),C=t.findIndex(_=>_.field===f);if(x===-1||C===-1){s(null),a(null);return}const E=t[x];e&&e({column:E,oldIndex:x,targetIndex:C}),s(null),a(null),c.current=-1},[t,l,o,e]),b=i.useCallback(()=>{s(null),a(null),c.current=-1},[]);return{draggedColumn:l,dragOverColumn:d,onDragStart:o?void 0:h,onDragOver:o?void 0:p,onDragEnd:o?void 0:b,onDrop:o?void 0:w}}function yn({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 So(n){const{activeColumns:t,isHierarchyEnabled:e,isRowGrouping:o,isTreeData:l,activeHierarchyHandlers:s,columnVisibilityModel:d,columnOrder:a,onColumnOrderChange:c,disableColumnReorder:h,pivotMode:p,checkboxSelection:w,hasDetailPanel:b,rowReordering:f,initialState:m,setColumns:x}=n,C=i.useMemo(()=>e?t.map((y,T)=>T===0?{...y,renderCell:I=>{const A=I.rowMeta,$=A?.treeDepth??0,D=!!A?.hasChildren,W=!!A?.isExpanded,z=A?.groupingField,Y=A?.groupingValue,U=A?.descendantCount,v=!!A?.isGroupRow;let M=y.renderCell?y.renderCell(I):I.value;if(l&&D&&v&&(M=r.jsxs("div",{className:"ogx__group-cell-content",children:[I.value,U!==void 0&&U>0?` (${U})`:""]})),o&&D&&z){const F=A?.groupLabel??`${z}: ${String(Y)}`;M=r.jsxs("div",{className:"ogx__group-cell-content",children:[F,U!==void 0?` (${U})`:""]})}return r.jsxs("div",{style:{display:"flex",alignItems:"center",paddingLeft:$*24,width:"100%",height:"100%"},children:[r.jsx("div",{style:{marginRight:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:D?"pointer":"default",flexShrink:0},children:D?r.jsx("div",{onClick:F=>{F.stopPropagation(),F.preventDefault(),s?.toggleExpansion(I.row.id)},onMouseDown:F=>{F.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:r.jsx(yn,{isExpanded:W,onClick:F=>{F.stopPropagation(),F.preventDefault(),s?.toggleExpansion(I.row.id)}})}):null}),r.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M})]})}}:{...y,renderCell:I=>{const A=I.rowMeta,$=!!A?.hasChildren,D=A?.groupingField;return o&&$?y.field===D?null:I.value!==void 0&&I.value!==null?y.renderCell?y.renderCell(I):I.value:null:y.renderCell?y.renderCell(I):I.value}}):t,[t,e,o,l,s]),[E,_]=i.useState(()=>m?.columns?.columnWidths??{}),S=i.useCallback((y,T)=>{_(I=>({...I,[y]:T}))},[]),[N,g]=i.useState(()=>m?.columns?.columnOrder??t.map(y=>y.field)),k=a??N;i.useEffect(()=>{x(t)},[t,x]),i.useEffect(()=>{p&&g(t.map(y=>y.field))},[p,t]);const u=i.useMemo(()=>{if(h)return C;const y=new Map(k.map((T,I)=>[T,I]));return[...C].sort((T,I)=>{const A=y.get(T.field)??C.indexOf(T),$=y.get(I.field)??C.indexOf(I);return A-$})},[C,k,h]),j=i.useMemo(()=>u.filter(y=>d[y.field]!==!1),[u,d]),P=ko({columns:u,onColumnOrderChange:i.useCallback(y=>{const{oldIndex:T,targetIndex:I}=y,A=[...k],[$]=A.splice(T,1);A.splice(I,0,$),a||g(A),c?.(y)},[k,a,c]),disableColumnReorder:h}),L=i.useMemo(()=>{const y=[];return f&&y.push({field:"__reorder_col__"}),b&&y.push({field:"__expand_col__"}),w&&y.push({field:"__checkbox_col__"}),[...y,...u]},[u,w,b,f]);return{effectiveColumns:C,orderedColumns:u,visibleOrderedColumns:j,navigationColumns:L,columnWidths:E,effectiveColumnOrder:k,setInternalColumnOrder:g,columnReorderHandlers:P,handleColumnResize:S}}function jo(n){const{renderContext:t,pinnedTopRows:e,pinnedBottomRows:o,paginatedUnpinnedRows:l,sortedUnpinnedRows:s,pagination:d}=n;return i.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:c}=t,h=d?l:s,p=e.length,w=e.map((_,S)=>({row:_,rowIndex:S})),b=o.map((_,S)=>({row:_,rowIndex:p+h.length+S})),f=Math.max(0,a-p),m=Math.min(h.length,c-p+1),x=h.slice(f,m).map((_,S)=>({row:_,rowIndex:p+f+S})),C=[...w,...x,...b],E=new Set;return C.filter(_=>E.has(_.row.id)?!1:(E.add(_.row.id),!0))},[t,e,o,l,s,d])}function Eo(n){const{onRowsScrollEnd:t}=n,e=i.useRef({scrollTop:0,scrollLeft:0}),o=i.useRef(null),[l,s]=i.useState({scrollTop:0,scrollLeft:0});i.useEffect(()=>()=>{o.current!==null&&cancelAnimationFrame(o.current)},[]);const d=i.useCallback(a=>{const c=a.currentTarget;if(e.current={scrollTop:c.scrollTop,scrollLeft:c.scrollLeft},o.current!==null&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{o.current=null,s(e.current)}),t){const{scrollTop:h,scrollHeight:p,clientHeight:w}=c;p-h-w<100&&t({visibleTop:h,visibleBottom:h+w,viewportHeight:w})}},[t]);return{scrollTop:l.scrollTop,scrollLeft:l.scrollLeft,handleScroll:d}}function No(n){const{onStateChange:t,sortModel:e,filterModel:o,effectivePaginationModel:l,columnWidths:s,effectiveColumnOrder:d,columnVisibilityModel:a,pinnedColumns:c}=n,h=i.useRef(t);i.useLayoutEffect(()=>{h.current=t}),i.useEffect(()=>{if(!h.current)return;const p={sorting:{sortModel:e},filter:{filterModel:o},pagination:{paginationModel:l},columns:{columnWidths:s,columnOrder:d,columnVisibilityModel:a,pinnedColumns:c}};h.current(p)},[e,o,l,s,d,a,c])}const Mo={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 kn(n){const{rows:t,columns:e,aggregationModel:o,isServerSide:l,dataSource:s,filterModel:d,sortModel:a,serverAggregationResults:c}=n,h=i.useMemo(()=>{const N=new Map;return(e??[]).forEach(g=>N.set(g.field,g)),N},[e]),p=i.useMemo(()=>{if(l||Object.keys(o).length===0)return{};const N={};for(const[g,k]of Object.entries(o)){const u=h.get(g);if(u?.availableAggregationFunctions&&!u.availableAggregationFunctions.includes(k))continue;const j=Mo[k];if(!j){console.warn(`[useAggregation] Unknown aggregation function: "${k}"`);continue}const P=t.map(L=>L[g]);N[g]=j(P)}return N},[t,h,o,l]),[w,b]=i.useState({}),[f,m]=i.useState(!1),[x,C]=i.useState(null),E=i.useRef(0),_=i.useCallback(async()=>{if(!s?.getAggregations||Object.keys(o).length===0)return;const N=++E.current;m(!0),C(null);try{const g=await s.getAggregations({sortModel:a??[],filterModel:d??{items:[]},groupKeys:[],aggregationModel:o});N===E.current&&b(g)}catch(g){N===E.current&&(C(g),console.error("[useAggregation] Server aggregation error:",g))}finally{N===E.current&&m(!1)}},[s,o,d,a]);return i.useEffect(()=>{l&&s?.getAggregations&&!c&&_()},[_,l,s,c]),{aggregationResult:i.useMemo(()=>l?c&&Object.keys(c).length>0?c:w:p,[l,p,c,w]),isLoading:f,error:x}}function Po({columns:n,aggregationModel:t,aggregationResult:e,columnWidths:o,rowHeight:l,checkboxSelection:s,hasDetailPanel:d,rowReordering:a,pinnedColumns:c}){const h=i.useMemo(()=>qt(n,o,c,s,!0,d,!0,a),[n,o,c,s,d,a]),p=c?.left?.[c.left.length-1],w=c?.right?.[0];return r.jsxs("div",{className:"ogx__aggregation-footer",role:"row","aria-label":"Aggregation totals","aria-live":"polite",style:{minHeight:`${l}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(b=>{const f=t[b.field],m=e[b.field],x=o[b.field]??(typeof b.width=="number"?b.width:120),C=pt(b.field,c),E=C?h[b.field]:void 0,_=["ogx__aggregation-cell",C==="left"&&"ogx__aggregation-cell--pinned-left",C==="right"&&"ogx__aggregation-cell--pinned-right",C==="left"&&b.field===p&&"ogx__aggregation-cell--pinned-left-last",C==="right"&&b.field===w&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),S={width:x,minWidth:x,maxWidth:x,textAlign:b.align||"left"};return C==="left"&&E!==void 0&&(S.left=E),C==="right"&&E!==void 0&&(S.right=E),r.jsx("div",{className:_,role:"gridcell",style:S,children:f?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"ogx__aggregation-label",children:f}),r.jsx("span",{className:"ogx__aggregation-value",children:_e(m,f)})]}):null},b.field)})]})}function Io({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 To({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 xt=({indeterminate:n=!1,label:t,className:e="",inputRef:o,...l})=>{const s=i.useRef(null),d=i.useCallback(c=>{s.current=c,typeof o=="function"?o(c):o&&(o.current=c)},[o]);i.useEffect(()=>{s.current&&(s.current.indeterminate=n)},[n]);const a=["ogx-checkbox-wrapper",l.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||l["aria-label"]||(n?"Select some":l.checked?"Deselect":"Select"),...l}),r.jsxs("span",{className:"ogx-checkbox__box",children:[l.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 Ro(n){const{field:t,currentWidth:e,onResize:o,minWidth:l=50,maxWidth:s=1e3}=n,[d,a]=i.useState(!1),c=i.useRef(0),h=i.useRef(0),p=i.useCallback(f=>{f.preventDefault(),f.stopPropagation(),a(!0),c.current=f.clientX,h.current=e;let m=0;const x=16,C=_=>{const S=_.clientX-c.current,N=Math.max(l,Math.min(s,h.current+S)),g=Date.now();g-m>=x&&(o(t,N),m=g)},E=_=>{a(!1);const S=_.clientX-c.current,N=Math.max(l,Math.min(s,h.current+S));o(t,N),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",E)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",E)},[t,e,o,l,s]),w=i.useCallback(f=>{f.preventDefault(),f.stopPropagation()},[]),b=["ogx-column-resize-handle",d&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return r.jsx("div",{className:b,onMouseDown:p,onClick:f=>f.stopPropagation(),onDragStart:f=>{f.preventDefault(),f.stopPropagation()},onDoubleClick:w,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,children:r.jsx("div",{className:"ogx-column-resize-handle__line"})})}function Xe(){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 Je(){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 Lo(){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 Fo(){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 Oo(){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 Wo(){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 Ao(){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 $o(){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 zo(){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 Bo(){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 Ho({colDef:n,sortModel:t,onSort:e,onHide:o,onPin:l,pinnedColumns:s,onManageColumns:d,onClose:a,anchorEl:c}){const h=i.useRef(null),[p,w]=i.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});i.useLayoutEffect(()=>{if(!c||!h.current)return;const g=c.getBoundingClientRect(),k=h.current.getBoundingClientRect(),u=window.innerWidth,j=window.innerHeight,P=8;let L=g.left;L+k.width+P>u&&(L=u-k.width-P),L<P&&(L=P);let y=g.bottom+4;y+k.height+P>j&&(y=g.top-k.height-4),w({position:"fixed",zIndex:1300,top:y,left:L,visibility:"visible"})},[c]),i.useEffect(()=>{function g(u){h.current&&!h.current.contains(u.target)&&c&&!c.contains(u.target)&&a()}function k(u){u.key==="Escape"&&a()}return document.addEventListener("mousedown",g),document.addEventListener("keydown",k),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",k),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[c,a]);const b=g=>{e?.(n.field,g),a()},f=()=>{o?.(n.field),a()},m=g=>{l?.(n.field,g),a()},x=t?.find(g=>g.field===n.field)?.sort,C=x==null,E=s?.left?.includes(n.field)??!1,_=s?.right?.includes(n.field)??!1,S=!E&&!_,N=n.headerName||n.field;return Ge.createPortal(r.jsxs("div",{ref:h,className:"ogx-column-menu",style:p,role:"menu","aria-label":`Column options for ${N}`,children:[e&&n.sortable!==!1&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:`ogx-menu-item${x==="asc"?" ogx-menu-item--active":""}`,onClick:()=>b("asc"),role:"menuitemradio","aria-checked":x==="asc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:x==="asc"?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Fo,{})}),"Sort Ascending"]}),r.jsxs("button",{className:`ogx-menu-item${x==="desc"?" ogx-menu-item--active":""}`,onClick:()=>b("desc"),role:"menuitemradio","aria-checked":x==="desc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:x==="desc"?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Oo,{})}),"Sort Descending"]}),r.jsxs("button",{className:`ogx-menu-item${C?" ogx-menu-item--active":""}`,onClick:()=>b(null),role:"menuitemradio","aria-checked":C,children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:C?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Wo,{})}),"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${E?" ogx-menu-item--active":""}`,onClick:()=>m("left"),role:"menuitemradio","aria-checked":E,"aria-label":"Pin to left",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx($o,{})}),"Pin to Left"]}),r.jsxs("button",{className:`ogx-menu-item${_?" ogx-menu-item--active":""}`,onClick:()=>m("right"),role:"menuitemradio","aria-checked":_,"aria-label":"Pin to right",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:_?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(zo,{})}),"Pin to Right"]}),r.jsxs("button",{className:`ogx-menu-item${S?" ogx-menu-item--active":""}`,onClick:()=>m(null),role:"menuitemradio","aria-checked":S,"aria-label":"Unpin column",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:S?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Bo,{})}),"Unpin"]}),r.jsx("div",{className:"ogx-menu-divider"}),r.jsxs("button",{className:"ogx-menu-item",onClick:f,role:"menuitem","aria-label":`Hide ${N} 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(Ao,{})}),"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(Lo,{})}),"Manage columns"]})]}),c?.closest(".ogx-theme-provider")||document.body)}function Do(){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 Go(){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 Sn(n){const t=[];for(const e of n.children)typeof e=="string"?t.push(e):t.push(...Sn(e));return t}function Vo(n){let t=0;function e(o,l){t=Math.max(t,l);for(const s of o.children)typeof s!="string"&&e(s,l+1)}return n.forEach(o=>e(o,1)),t}function Uo(n,t,e){function o(a,c,h){if(!Sn(a).includes(c))return null;if(h===e)return a;for(const p of a.children)if(typeof p!="string"){const w=o(p,c,h+1);if(w)return w}return null}const l=new Map;for(const a of t){let c=null;for(const h of n)if(c=o(h,a.field,0),c)break;l.set(a.field,c)}const s=[];let d=0;for(;d<t.length;){const a=t[d],c=l.get(a.field)??null,h=a.width;if(!c)s.push({key:`fg-${a.field}-${e}`,label:"",width:h,isGroup:!1}),d++;else{let p=0,w=d;for(;w<t.length&&l.get(t[w].field)===c;)p+=t[w].width,w++;s.push({key:`${c.groupId}-${e}`,label:c.headerName,width:p,isGroup:!0}),d=w}}return s}function jn(n){const{columns:t,allColumns:e,columnGroupingModel:o,checkboxSelection:l=!1,allSelected:s=!1,someSelected:d=!1,onSelectAll:a,onSort:c,sortModel:h=[],onColumnResize:p,columnWidths:w={},pinnedColumns:b,hasDetailPanel:f=!1,pinCheckboxColumn:m=!0,pinExpandColumn:x=!0,rowReordering:C=!1,aggregationModel:E,draggedColumn:_,dragOverColumn:S,onDragStart:N,onDragOver:g,onDragEnd:k,onDrop:u,focusedCell:j,onHeaderClick:P,onSortAdd:L,multiSort:y=!1,onHideColumn:T,onPinColumn:I,onManageColumns:A}=n,$=i.useId(),D=i.useRef({}),[W,z]=i.useState(null),Y=R=>le=>{le.stopPropagation(),z({colDef:R,anchorEl:le.currentTarget})},U=()=>{z(null)};i.useLayoutEffect(()=>{if(j?.id==="HEADER"){const R=D.current[j.field];R&&R.focus()}},[j]);const v=R=>le=>{if(R.sortable===!1)return;const te=h.find(q=>q.field===R.field);let re="asc";te&&(te.sort==="asc"?re="desc":re=null),(le.shiftKey||y)&&L?L(R.field,re):c&&c(R.field,re)},M=R=>{const le=h.find(re=>re.field===R);if(!le)return null;const te=h.length>1?h.indexOf(le)+1:null;return r.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${le.sort}`,"aria-hidden":"true",children:te!==null&&r.jsx("span",{className:"ogx__sort-badge",children:te})})},F=i.useMemo(()=>qt(t,w,b,l,m,f,x,C),[t,w,b,l,m,f,x,C]),O=o?Vo(o):0,K=(e??t).filter(R=>!R.isSpacer).map(R=>({field:R.field,width:w[R.field]??R.width??100})),ne=(C?48:0)+(f?48:0)+(l?48:0);return r.jsxs("div",{className:"ogx__header-wrap",children:[O>0&&Array.from({length:O},(R,le)=>{const te=Uo(o,K,le);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"}),te.map(re=>r.jsx("div",{role:"columnheader",className:`ogx-col-group-cell ${re.isGroup?"ogx-col-group-cell--group":"ogx-col-group-cell--filler"}`,style:{width:re.width,minWidth:re.width,flexShrink:0},title:re.isGroup?re.label:void 0,children:re.isGroup&&r.jsx("span",{className:"ogx-col-group-cell__label",children:re.label})},re.key))]},`ogx-grp-${le}`)}),r.jsxs("div",{className:"ogx__header",role:"row",children:[C&&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}}),f&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${x?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader","aria-label":"Expand row details",style:{minWidth:48,maxWidth:48,position:x?"sticky":void 0,left:x?C?48:0:void 0,zIndex:x?5:void 0}}),l&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${m?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader",style:{position:m?"sticky":void 0,left:m?(C?48:0)+(f&&x?48:0):void 0},children:r.jsx(xt,{id:$,name:$,checked:s,indeterminate:d,onChange:R=>a?.(R.target.checked),"aria-label":s?"Deselect all rows":"Select all rows",tabIndex:j?.id==="HEADER"&&j.field==="__checkbox_col__"?0:-1,onMouseDown:R=>R.preventDefault(),inputRef:R=>{D.current.__checkbox_col__=R}})}),t.map((R,le)=>{if(R.isSpacer)return r.jsx("div",{style:{width:R.width,minWidth:R.width,flexShrink:0},"aria-hidden":"true"},R.field);const te=R.sortable!==!1,re=h.some(ee=>ee.field===R.field),q=R.resizable!==!1,J=pt(R.field,b),de=J!==null,B=_===R.field,Q=S===R.field,Z=["ogx__header-cell",`ogx__header-cell--align-${R.headerAlign||R.align||"left"}`,te&&"ogx__header-cell--sortable",re&&"ogx__header-cell--sorted",de&&"ogx__header-cell--pinned",de&&`ogx__header-cell--pinned-${J}`,B&&"ogx__header-cell--dragging",Q&&"ogx__header-cell--drag-over",j?.id==="HEADER"&&j.field===R.field&&"ogx__header-cell--focused",R.headerClassName].filter(Boolean).join(" "),ge=w[R.field]??R.width??100,ue={width:ge,minWidth:R.minWidth,maxWidth:R.maxWidth,flexGrow:R.flex??0,flexShrink:0,flexBasis:(R.flex,"auto"),boxSizing:"border-box",position:de?"sticky":"relative",zIndex:R.zIndex,opacity:B?.5:1};if(de&&J){const ee=F[R.field];J==="left"?ue.left=ee:ue.right=ee}const Ee=R.renderHeader?R.renderHeader({field:R.field,colDef:R,colIndex:le}):R.headerName||R.field,Te=ee=>{if(ee.target.closest(".ogx-column-resize-handle")){ee.stopPropagation();return}P?.(R.field),te&&v(R)(ee)},Pe=N?N(R.field):void 0,Re=g?g(R.field):void 0,ze=u?u(R.field):void 0;return r.jsxs("div",{className:Z,style:ue,title:R.description,onClick:Te,role:"columnheader",draggable:!!N,onDragStart:Pe,onDragOver:Re,onDragEnd:k,onDrop:ze,"aria-sort":te?re?h.find(ee=>ee.field===R.field)?.sort==="asc"?"ascending":"descending":"none":void 0,"aria-colindex":le+1+(l?1:0),"data-field":R.field,tabIndex:-1,ref:ee=>{D.current[R.field]=ee},children:[r.jsxs("div",{className:"ogx__header-cell-content",children:[B&&r.jsx("div",{className:"ogx__header-drag-icon",children:r.jsx(Go,{})}),r.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[r.jsx("span",{className:"ogx__header-cell-title",children:Ee}),E&&E[R.field]&&r.jsx("span",{className:"ogx__header-cell-aggregation",children:E[R.field]})]}),te&&M(R.field),!R.disableColumnMenu&&r.jsx("button",{className:"ogx__menu-icon-btn",onClick:Y(R),"aria-label":`Open column menu for ${R.headerName||R.field}`,"aria-haspopup":"menu",tabIndex:-1,children:r.jsx(Do,{})})]}),q&&p&&r.jsx(Ro,{field:R.field,currentWidth:ge,onResize:p,minWidth:R.minWidth,maxWidth:R.maxWidth})]},R.field)}),W&&r.jsx(Ho,{colDef:W.colDef,sortModel:h,onSort:c,onHide:T,onPin:I,pinnedColumns:b,onManageColumns:A,onClose:U,anchorEl:W.anchorEl})]})]})}const mt=({variant:n="text",size:t="medium",color:e="default",disabled:o=!1,className:l="",children:s,...d})=>{const a=["ogx-button",`ogx-button--${n}`,`ogx-button--${t}`,`ogx-button--${e}`,o&&"ogx-button--disabled",l].filter(Boolean).join(" ");return r.jsx("button",{className:a,disabled:o,...d,children:s})};function En(n){const t=i.useId(),{page:e,pageSize:o,rowCount:l,onPageChange:s,onPageSizeChange:d,pageSizeOptions:a=[10,25,50,100],showFirstButton:c=!0,showLastButton:h=!0,localeText:p}=n,w=Math.max(1,Math.ceil(l/o)),b=Math.min(e,w-1),f=b*o,m=Math.min(f+o,l),x=l===0?0:`${f+1}–${m}`,C=p?.paginationRowsPerPage??"Rows per page:",E=p?.paginationOf?p.paginationOf(l===0?0:f+1,m,l):`${x} of ${l}`,_=p?.paginationPage?p.paginationPage(b+1,w):`Page ${b+1} of ${w}`,S=()=>{s(0)},N=()=>{s(Math.max(0,b-1))},g=()=>{s(Math.min(w-1,b+1))},k=()=>{s(w-1)},u=L=>{const y=parseInt(L.target.value,10);d(y)},j=b===0,P=b>=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:C}),r.jsx("select",{id:t,className:"ogx-pagination__select",value:o,onChange:u,"aria-label":"Rows per page",children:a.map(L=>r.jsx("option",{value:L,children:L},L))})]}),r.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:E}),r.jsxs("div",{className:"ogx-pagination__actions",children:[c&&r.jsx(mt,{variant:"text",size:"small",onClick:S,disabled:j,"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(mt,{variant:"text",size:"small",onClick:N,disabled:j,"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:_}),r.jsx(mt,{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"})})}),h&&r.jsx(mt,{variant:"text",size:"small",onClick:k,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 Ko(n,t,e={}){const o=new Map,l=[];n.forEach(a=>{o.set(a.id,a),l.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:l},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 Yo(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,l=new Map,s=[];return o.forEach(d=>{l.set(d.id,d),s.push(d.id)}),{...n,rows:{idRowsLookup:l,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(l=>{e.set(l.field,l),o.push(l.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 qo(n){const{rows:t,columns:e,rowHeight:o=52,headerHeight:l=56,columnVisibilityModel:s,initialState:d}=n,[a]=i.useState(()=>Ko(t,e,s)),[c,h]=i.useReducer(Yo,{...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:l}}),p=i.useRef(c);i.useLayoutEffect(()=>{p.current=c});const w=i.useRef(t);i.useEffect(()=>{t!==w.current&&(w.current=t,h({type:"SET_ROWS",payload:t}))},[t]);const b=i.useCallback((u,j)=>{h({type:"SET_ROWS",payload:u,preserveRowCount:j})},[]),f=i.useCallback(u=>{h({type:"SET_COLUMNS",payload:u})},[]),m=i.useCallback(u=>{h({type:"SET_SORT_MODEL",payload:u})},[]),x=i.useCallback(u=>{h({type:"SET_FILTER_MODEL",payload:u})},[]),C=i.useCallback(u=>{h({type:"SET_PAGINATION_MODEL",payload:u})},[]),E=i.useCallback(u=>{h({type:"SET_SELECTION",payload:u})},[]),_=i.useCallback((u,j)=>{h({type:"SET_DIMENSIONS",payload:{viewportWidth:u,viewportHeight:j}})},[]),S=i.useCallback(u=>{h({type:"SET_DATASOURCE_LOADING",payload:u})},[]),N=i.useCallback(u=>{h({type:"SET_DATASOURCE_ERROR",payload:u})},[]),g=i.useCallback(u=>{h({type:"SET_ROW_COUNT",payload:u})},[]),k=i.useRef({getRow:u=>p.current.rows.idRowsLookup.get(u)||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()),getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:u=>p.current.columns.lookup.get(u)||null,getAllColumns:()=>p.current.columns.all,getVisibleColumns:()=>p.current.columns.all,selectRow:(u,j=!0)=>{const P=new Set(p.current.selection.selectedRows);j?P.add(u):P.delete(u),E(P)},selectRows:(u,j=!0)=>{const P=new Set(p.current.selection.selectedRows);u.forEach(L=>{j?P.add(L):P.delete(L)}),E(P)},getSelectedRows:()=>Array.from(p.current.selection.selectedRows),sortColumn:(u,j)=>{if(j===null)m(p.current.sorting.sortModel.filter(P=>P.field!==u));else{const P=p.current.sorting.sortModel.findIndex(L=>L.field===u);if(P>=0){const L=[...p.current.sorting.sortModel];L[P]={field:u,sort:j},m(L)}else m([...p.current.sorting.sortModel,{field:u,sort:j}])}},getSortModel:()=>p.current.sorting.sortModel,setFilterModel:x,getFilterModel:()=>p.current.filter.filterModel,setPage:u=>{C({...p.current.pagination.paginationModel,page:u})},setPageSize:u=>{C({...p.current.pagination.paginationModel,pageSize:u,page:0})},scrollToIndexes:()=>{},copySelectedRows:()=>Promise.resolve()});return{state:c,dispatch:h,apiRef:k,setRows:b,setColumns:f,setSortModel:m,setFilterModel:x,setPaginationModel:C,setSelection:E,setDimensions:_,setDataSourceLoading:S,setDataSourceError:N,setRowCount:g}}function Xo(n){const{onRowOrderChange:t,rows:e,getRowId:o,rowReordering:l=!1}=n,[s,d]=i.useState(null),[a,c]=i.useState(null),h=i.useCallback(m=>o?o(m):m.id,[o]),p=i.useCallback(m=>x=>{l&&(d(m),x.dataTransfer.effectAllowed="move")},[l]),w=i.useCallback(m=>x=>{!l||!s||(x.preventDefault(),x.dataTransfer.dropEffect="move",a!==m&&c(m))},[l,s,a]),b=i.useCallback(()=>{d(null),c(null)},[]),f=i.useCallback(m=>x=>{if(x.preventDefault(),!s||!t){b();return}const C=e.findIndex(_=>h(_)===s),E=e.findIndex(_=>h(_)===m);C!==-1&&E!==-1&&C!==E&&t({row:e[C],oldIndex:C,targetIndex:E}),b()},[s,t,e,h,b]);return{draggedRowId:s,dragOverRowId:a,onDragStart:l?p:void 0,onDragOver:l?w:void 0,onDragEnd:l?b:void 0,onDrop:l?f:void 0}}function Jo(n){const{rows:t,getRowId:e,getTreeDataPath:o,treeData:l=!1,defaultGroupingExpansionDepth:s=0,filterModel:d,sortModel:a,onRowExpansionChange:c}=n,{treeNodes:h,rootIds:p,groupingRows:w}=i.useMemo(()=>{if(!l||!o)return{treeNodes:new Map,rootIds:[],groupingRows:[]};const g=new Map,k=[],u=[],j=new Map,P=L=>L.join("/");return t.forEach(L=>{const y=e(L),T=o(L),I=P(T);j.set(I,y),g.set(y,{id:y,parentId:null,depth:T.length-1,groupingKey:T[T.length-1],isExpanded:!1,children:[],serverChildrenCount:L.serverChildrenCount})}),t.forEach(L=>{const y=e(L),T=o(L);if(T.length===1){k.push(y);return}const I=$=>{if($.length<=1)return;const D=$.slice(0,-1),W=P(D);let z=j.get(W);if(z===void 0&&(z=`auto-group-${W}`,!g.has(z))){const Y=D[D.length-1];g.set(z,{id:z,parentId:null,depth:D.length-1,groupingKey:Y,isExpanded:!1,children:[],label:Y}),j.set(W,z);const U={id:z,name:Y,_isGroupRow:!0};u.push(U),D.length===1&&k.push(z),I(D)}return z},A=I(T);if(A!==void 0){const $=g.get(A),D=g.get(y);$&&D&&(D.parentId=A,$.children=$.children||[],$.children.includes(y)||$.children.push(y))}}),u.forEach(L=>{const y=L.id,T=g.get(y);if(!T)return;const A=y.replace("auto-group-","").split("/");if(A.length>1){const $=A.slice(0,-1),D=P($),W=j.get(D);if(W&&g.has(W)){T.parentId=W;const z=g.get(W);z&&(z.children=z.children||[],z.children.includes(y)||z.children.push(y))}}}),{treeNodes:g,rootIds:k,groupingRows:u}},[t,o,l,e]),b=i.useMemo(()=>{if(!l)return new Set;const g=new Set;return h.forEach(k=>{k.children&&k.children.length>0&&(s===-1||k.depth<s)&&g.add(k.id)}),g},[h,l,s]),[f,m]=i.useState(new Set);i.useEffect(()=>{b.size>0&&m(b)},[b]);const x=i.useCallback(g=>{m(k=>{const u=new Set(k),j=!u.has(g);if(u.has(g)?u.delete(g):u.add(g),j&&c){const P=h.get(g);P&&c(P)}return u})},[h,c]),C=i.useCallback(()=>{if(!l)return null;const g=new Map;t.forEach(I=>g.set(e(I),I)),w.forEach(I=>g.set(I.id,I));const k=I=>Jt(I,d),u=new Map,j=I=>{if(u.has(I))return u.get(I);const A=g.get(I);if(!A)return!1;if(k(A))return u.set(I,!0),!0;const D=h.get(I);return D&&D.children&&D.children.some(z=>j(z))?(u.set(I,!0),!0):(u.set(I,!1),!1)},P=(I,A)=>{if(!a||a.length===0)return 0;const $=g.get(I),D=g.get(A);if(!$||!D)return 0;for(const W of a){const z=$[W.field],Y=D[W.field],U=Qt(z,Y,W.sort);if(U!==0)return U}return 0},L=[],y=new Set,T=I=>{const A=I.filter($=>j($));A.sort(P),A.forEach($=>{if(y.has($))return;const D=g.get($),W=h.get($);if(D&&W){y.add($);const z={...D,_treeDepth:W.depth,_isExpanded:f.has($),_hasChildren:!!(W.children&&W.children.length>0||W.serverChildrenCount&&W.serverChildrenCount>0),_descendantCount:W.children?W.children.length:0};L.push(z),f.has($)&&W.children&&W.children.length>0&&T(W.children)}})};return T(p),L},[l,t,w,p,h,f,d,a,e]),E=i.useCallback(g=>f.has(g),[f]),_=i.useCallback(g=>h.get(g),[h]),S=i.useCallback(g=>{const k=[];let u=g;for(;u!==null;){const j=h.get(u);if(!j)break;k.unshift(j.groupingKey),u=j.parentId}return k},[h]),N=i.useMemo(()=>{const g=new Map,k=new Set(w.map(u=>u.id));return h.forEach((u,j)=>{g.set(j,{hasChildren:!!(u.children&&u.children.length>0||u.serverChildrenCount&&u.serverChildrenCount>0),treeDepth:u.depth,descendantCount:u.children?u.children.length:void 0,isGroupRow:k.has(j),isExpanded:f.has(j)})}),g},[h,w,f]);return i.useMemo(()=>({treeNodes:h,groupingRows:w,toggleExpansion:x,isGroupExpanded:E,getVisibleRows:C,getNode:_,getNodePath:S,rowMetaMap:N}),[h,w,x,E,C,_,S,N])}const Qo=n=>n?.depth===-1?"footer":"inline",Zo=[],er={};function tr(n){const{rows:t,getRowId:e,columns:o,rowGroupingModel:l=Zo,aggregationModel:s=er,defaultGroupingExpansionDepth:d=0,filterModel:a,sortModel:c,getAggregationPosition:h=Qo}=n,p=i.useMemo(()=>{const g=new Map;return(o??[]).forEach(k=>g.set(k.field,k)),g},[o]),[w,b]=i.useState(new Set),{treeNodes:f,rootIds:m,groupingRows:x}=i.useMemo(()=>{const g=new Map,k=new Map,u=[];if(l.length===0)return{treeNodes:g,rootIds:u,groupingRows:k};const j=(y,T,I)=>`auto-group-${y}-${T}-${I||"root"}`,P=(y,T,I)=>{if(T>=l.length)return y.map(z=>{const Y=e(z);return g.set(Y,{id:Y,parentId:I,depth:T,groupingKey:"",isExpanded:!1}),Y});const A=l[T],$=p.get(A);if($&&$.groupable===!1)return P(y,T+1,I);const D=new Map;y.forEach(z=>{const Y=z[A],U=String(Y);D.has(U)||D.set(U,[]),D.get(U).push(z)});const W=[];return D.forEach((z,Y)=>{const v=z[0][A],M=j(A,Y,I);W.push(M);const F={};s&&Object.entries(s).forEach(([oe,ie])=>{const ne=z.map(R=>R[oe]);if(ie==="sum")F[oe]=ne.reduce((R,le)=>R+(Number(le)||0),0);else if(ie==="min")F[oe]=Math.min(...ne.map(R=>Number(R)||0));else if(ie==="max")F[oe]=Math.max(...ne.map(R=>Number(R)||0));else if(ie==="avg"){const R=ne.reduce((le,te)=>le+(Number(te)||0),0);F[oe]=ne.length?R/ne.length:0}else ie==="count"&&(F[oe]=ne.length)});const O={[A]:v,...F,id:M};k.set(M,O);const H={id:M,parentId:I,depth:T,groupingKey:Y,groupingField:A,groupingValue:v,aggregatedValues:F,isExpanded:!1,children:[],label:$?.groupingValueFormatter?$.groupingValueFormatter({field:A,value:v}):`${A}: ${String(v)}`};H.aggregationPosition=h(H),g.set(M,H);const K=P(z,T+1,M);g.get(M).children=K;const V=z.length;g.get(M).descendantCount=V}),W},L=P(t,0,null);return u.push(...L),{treeNodes:g,rootIds:u,groupingRows:k}},[t,l,s,e,h,p]);i.useEffect(()=>{if(d===-1){const g=new Set;f.forEach((k,u)=>{k.children&&k.children.length>0&&g.add(u)}),b(g)}else if(d>0){const g=new Set;f.forEach((k,u)=>{k.depth<d&&k.children&&k.children.length>0&&g.add(u)}),b(g)}else b(new Set)},[l,d,f]);const C=i.useCallback(g=>{b(k=>{const u=new Set(k);return u.has(g)?u.delete(g):u.add(g),u})},[]),E=i.useCallback(g=>w.has(g),[w]),_=i.useCallback(()=>{if(l.length===0)return null;const g=[],k=new Set,u=new Map;t.forEach(y=>u.set(e(y),y));const j=y=>{const T=f.get(y);if(!T)return!1;if(!T.children||T.children.length===0){const I=u.get(y);return!(!I||a&&!Jt(I,a))}return T.children.some(I=>j(I))},P=y=>{let T=y;a&&(T=y.filter(j)),c&&c.length>0&&T.sort((I,A)=>{const $=x.get(I)||u.get(I),D=x.get(A)||u.get(A);if(!$||!D)return 0;for(const W of c){const z=$[W.field],Y=D[W.field],U=Qt(z,Y,W.sort);if(U!==0)return U}return 0}),T.forEach(I=>{if(k.has(I))return;const A=f.get(I),$=A?.children&&A.children.length>0,D=$?x.get(I):u.get(I);if(D&&A){k.add(I);const W={...D,_treeDepth:A.depth,_isExpanded:w.has(I),_hasChildren:$,_groupingField:A.groupingField,_groupingValue:A.groupingValue,_descendantCount:A.descendantCount};g.push(W),L.has(I)&&$&&P(A.children)}})},L=w;return P(m),g},[t,e,f,m,x,a,c,w,l]),S=i.useCallback(g=>f.get(g),[f]),N=i.useMemo(()=>{const g=new Map;return f.forEach((k,u)=>{const j=!!(k.children&&k.children.length>0);g.set(u,{hasChildren:j,treeDepth:k.depth,groupingField:k.groupingField,groupingValue:k.groupingValue,groupLabel:k.label,descendantCount:k.descendantCount,isGroupRow:j,isExpanded:j?w.has(u):void 0})}),g},[f,w]);return i.useMemo(()=>({treeNodes:f,groupingRows:x,toggleExpansion:C,isGroupExpanded:E,getVisibleRows:_,getNode:S,rowMetaMap:N}),[f,x,C,E,_,S,N])}function nr(n){const{rows:t,getRowId:e,processRowUpdate:o,onProcessRowUpdateError:l,onRowChange:s}=n,[d,a]=i.useState(null),c=i.useRef(null),h=i.useCallback(f=>{a(f),c.current=typeof f=="function"?f(c.current):f},[]),p=i.useCallback(f=>{h({id:f.id,field:f.field,value:f.value,originalValue:f.value})},[h]),w=i.useCallback(async f=>{const m=c.current;if(!m)return;if(f?.cancel){h(null);return}const{id:x,field:C,value:E,originalValue:_}=m;if(E===_){h(null);return}const S=t.find(g=>e(g)===x);if(!S){h(null);return}const N={...S,[C]:E};try{if(o){const g=await o(N,S);s?.(g)}else s?.(N);h(null)}catch(g){l?.(g)}},[h,t,e,o,s,l]),b=i.useCallback(f=>{d&&d.id===f.id&&d.field===f.field&&h(m=>m?{...m,value:f.value}:null)},[d,h]);return{editingCell:d,startCellEdit:p,stopCellEdit:w,setEditCellValue:b}}function or(n,t,e){const[o,l]=i.useState(new Map),[s,d]=i.useState({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}}),a=i.useCallback(()=>{l(new Map)},[]),c=i.useCallback((x,C)=>o.get(x)?.[C],[o]),h=i.useCallback((x,C,E,_,S)=>{const N=new Map(o);for(let g=_;g<S;g++){const k=t[g];if(!k)continue;let u=1;if(k.colSpan)if(typeof k.colSpan=="function"){const P={row:C,value:C[k.field],field:k.field,colDef:k,rowIndex:E,colIndex:g};u=k.colSpan(P)}else u=k.colSpan;if(u<=1){Qe(N,x,k.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:e[k.field]||100}});continue}let j=e[k.field]||100;for(let P=1;P<u;P++)if(g+P<S){const L=t[g+P];L&&(j+=e[L.field]||100,Qe(N,x,L.field,{spannedByColSpan:!0,leftVisibleCellIndex:g,rightVisibleCellIndex:Math.min(g+u-1,t.length-1)}))}Qe(N,x,k.field,{spannedByColSpan:!1,cellProps:{colSpan:u,width:j}}),g+=u-1}l(N)},[o,t,e]),p=i.useCallback((x,C)=>{const E={},_={},S={};t.forEach((N,g)=>{if(N.rowSpan)for(let k=x;k<C;k++){const u=n[k];if(!u||_[u.id]?.[N.field])continue;const j=N.valueGetter?N.valueGetter({row:u,field:N.field,value:u[N.field]}):u[N.field];let P=1;if(typeof N.rowSpan=="function"){const L={row:u,value:j,field:N.field,colDef:N,rowIndex:k,colIndex:g};P=N.rowSpan(L)}else typeof N.rowSpan=="number"&&(P=N.rowSpan);if(P>1){E[u.id]||(E[u.id]={}),E[u.id][N.field]=P;for(let L=1;L<P;L++){const y=k+L;if(y<C&&n[y]){const T=n[y];_[T.id]||(_[T.id]={}),_[T.id][N.field]=!0,S[y]||(S[y]={}),S[y][N.field]=k}}}}}),d({caches:{spannedCells:E,hiddenCells:_,hiddenCellOriginMap:S},processedRange:{firstRowIndex:x,lastRowIndex:C}})},[n,t]),w=i.useCallback(()=>{d({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}})},[]);i.useEffect(()=>{const x=new Map;n.forEach((S,N)=>{for(let g=0;g<t.length;g++){const k=t[g];if(!k)continue;let u=1;if(k.colSpan)if(typeof k.colSpan=="function"){const P={row:S,value:S[k.field],field:k.field,colDef:k,rowIndex:N,colIndex:g};u=k.colSpan(P)}else u=k.colSpan;if(u<=1){const P=e[k.field]||(typeof k.width=="number"?k.width:100);Qe(x,S.id,k.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:P}});continue}let j=e[k.field]||(typeof k.width=="number"?k.width:100);for(let P=1;P<u;P++)if(g+P<t.length){const L=t[g+P];if(L){const y=e[L.field]||(typeof L.width=="number"?L.width:100);j+=y,Qe(x,S.id,L.field,{spannedByColSpan:!0,leftVisibleCellIndex:g,rightVisibleCellIndex:Math.min(g+u-1,t.length-1)})}}Qe(x,S.id,k.field,{spannedByColSpan:!1,cellProps:{colSpan:u,width:j}}),g+=u-1}}),l(x);const C={},E={},_={};t.forEach((S,N)=>{if(S.rowSpan)for(let g=0;g<n.length;g++){const k=n[g];if(!k||E[k.id]?.[S.field])continue;const u=S.valueGetter?S.valueGetter({row:k,field:S.field,value:k[S.field]}):k[S.field];let j=1;if(typeof S.rowSpan=="function"){const P={row:k,value:u,field:S.field,colDef:S,rowIndex:g,colIndex:N};j=S.rowSpan(P)}else typeof S.rowSpan=="number"&&(j=S.rowSpan);if(j>1){C[k.id]||(C[k.id]={}),C[k.id][S.field]=j;for(let P=1;P<j;P++){const L=g+P;if(L<n.length&&n[L]){const y=n[L];E[y.id]||(E[y.id]={}),E[y.id][S.field]=!0,_[L]||(_[L]={}),_[L][S.field]=g}}}}}),d({caches:{spannedCells:C,hiddenCells:E,hiddenCellOriginMap:_},processedRange:{firstRowIndex:0,lastRowIndex:n.length}})},[n,t,e]);const b=i.useCallback(()=>s.caches.spannedCells,[s]),f=i.useCallback(()=>s.caches.hiddenCells,[s]),m=i.useCallback(()=>s.caches.hiddenCellOriginMap,[s]);return{colspanMap:o,resetColSpan:a,getCellColSpanInfo:c,calculateColSpan:h,rowSpanningState:s,calculateRowSpan:p,resetRowSpan:w,getSpannedCells:b,getHiddenCells:f,getHiddenCellOriginMap:m}}function Qe(n,t,e,o){let l=n.get(t);l||(l={},n.set(t,l)),l[e]=o}function rr(n){const{dataSource:t,sortModel:e,filterModel:o,paginationModel:l,paginationMode:s,sortingMode:d,filterMode:a,aggregationModel:c,setRows:h,setRowCount:p,setDataSourceLoading:w,setDataSourceError:b,onAggregationResults:f}=n,m=i.useRef(null),x=i.useRef(0),C=i.useCallback(async()=>{if(!t)return;const _=++x.current;w(!0),b(null);const S=l.page*l.pageSize,N=S+l.pageSize,g={startRow:S,endRow:N,sortModel:e,filterModel:o,groupKeys:[],aggregationModel:c};try{const k=await t.getRows(g);if(_!==x.current)return;let u=!1;if(s==="infinite"){const j=m.current;if(j){const P=JSON.stringify(j.sortModel)!==JSON.stringify(e),L=JSON.stringify(j.filterModel)!==JSON.stringify(o),y=j.pageSize!==l.pageSize;!P&&!L&&!y&&l.page>j.page&&(u=!0)}}h(u?j=>[...j,...k.rows]:k.rows,!0),k.aggregationResults&&f&&f(k.aggregationResults),k.rowCount!==void 0&&p(k.rowCount),m.current={sortModel:e,filterModel:o,page:l.page,pageSize:l.pageSize}}catch(k){_===x.current&&(b(k),console.error("Data Source Error:",k))}finally{_===x.current&&w(!1)}},[t,l.page,l.pageSize,e,o,s,c,f,h,p,w,b]);i.useEffect(()=>{if(t&&(s==="server"||s==="infinite"||d==="server"||a==="server")){const S=setTimeout(()=>{C()},300);return()=>clearTimeout(S)}},[C,t,s,d,a]);const E=i.useCallback(async(_,S)=>{if(t){w(!0);try{const N=await t.getRows({startRow:0,endRow:-1,sortModel:e,filterModel:o,groupKeys:S});N.rows.length>0&&h(g=>{const k=new Set(g.map(j=>j.id)),u=N.rows.filter(j=>!k.has(j.id));return[...g,...u]})}catch(N){b(N),console.error("Failed to fetch children:",N)}finally{w(!1)}}},[t,e,o,h,w,b]);return{fetchRows:C,fetchChildren:E}}const Nn="\0",bt="";function ir(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,l)=>o+l,0);case"avg":return e.reduce((o,l)=>o+l,0)/e.length;case"count":return e.length;case"min":return Math.min(...e);case"max":return Math.max(...e)}}function Lt(n,t){return t.map(e=>String(n[e]??"")).join(Nn)}function Zt(n,t,e,o){return o?`${n}${bt}${t}${bt}${e}`:`${t}${bt}${e}`}function Mn(n,t,e,o){return i.useMemo(()=>{const l={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1};if(!o)return l;const{rowFields:s,columnFields:d,valueFields:a}=e;if(s.length===0||a.length===0)return l;const c=d.length>0,h=new Map(t.map(_=>[_.field,_])),p=new Set;for(const _ of n)p.add(Lt(_,d));const w=Array.from(p).sort(),b=new Map;for(const _ of n){const S=Lt(_,s);if(!b.has(S)){const u={};for(const j of s)u[j]=_[j];b.set(S,{labelValues:u,bucket:new Map})}const N=b.get(S),g=Lt(_,d);N.bucket.has(g)||N.bucket.set(g,new Map);const k=N.bucket.get(g);for(const u of a){const j=_[u.field];k.has(u.field)||k.set(u.field,[]),j!=null&&!isNaN(Number(j))&&k.get(u.field).push(Number(j))}}let f=0;const m=[];for(const[,_]of b){const S={id:f++,..._.labelValues};for(const N of w){const g=_.bucket.get(N);for(const k of a){const u=Zt(N,k.field,k.aggFn,c),j=g?.get(k.field)??[];S[u]=j.length>0?ir(j,k.aggFn):null}}m.push(S)}const x=new Map;for(const _ of n){const S=Lt(_,d);for(const N of a){if(N.aggFn!=="avg"&&N.aggFn!=="min"&&N.aggFn!=="max")continue;const g=`${S}${bt}${N.field}`;x.has(g)||x.set(g,[]);const k=_[N.field];k!=null&&!isNaN(Number(k))&&x.get(g).push(Number(k))}}const C={id:"__pivot_grand_total__"};for(let _=0;_<s.length;_++)C[s[_]]=_===0?"Grand Total":"";for(const _ of w)for(const S of a){const N=Zt(_,S.field,S.aggFn,c),g=m.map(u=>u[N]).filter(u=>u!=null&&!isNaN(Number(u))).map(Number);if(g.length===0){C[N]=null;continue}const k=`${_}${bt}${S.field}`;switch(S.aggFn){case"sum":case"count":C[N]=g.reduce((u,j)=>u+j,0);break;case"avg":{const u=x.get(k)??[];C[N]=u.length>0?u.reduce((j,P)=>j+P,0)/u.length:null;break}case"min":C[N]=Math.min(...x.get(k)??g);break;case"max":C[N]=Math.max(...x.get(k)??g);break}}m.push(C);const E=[];for(const _ of s){const S=h.get(_);E.push({field:_,headerName:S?.headerName??_,width:S?.width??140,sortable:!0})}for(const _ of w){const S=c?_.split(Nn).map((N,g)=>{const k=h.get(d[g]);return k?.headerName?`${k.headerName}: ${N}`:N}).join(" / "):"";for(const N of a){const g=h.get(N.field),k=Zt(_,N.field,N.aggFn,c),u=N.headerName??g?.headerName??N.field,j=S?`${S} — ${u} (${N.aggFn})`:`${u} (${N.aggFn})`;E.push({field:k,headerName:j,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:P})=>{if(P==null)return"—";const L=Number(P);return N.aggFn==="avg"?L.toFixed(2):N.aggFn==="count"?L.toLocaleString():g?.valueFormatter?g.valueFormatter({value:P,row:{},field:N.field}):L.toLocaleString()}})}}return{pivotRows:m,pivotColumns:E,colKeys:w,isValid:!0}},[n,t,e,o])}function lr(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 sr(n){let t=!1;try{t=lr(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 ar(n){const{selectedRowIds:t,columns:e,getVisibleRows:o,getRowId:l}=n,s=i.useCallback(async()=>{if(t.size===0)return;const a=o().filter(b=>t.has(l(b)));if(a.length===0)return;const c=e.filter(b=>!b.field.startsWith("__")),h=c.map(b=>b.headerName||b.field).join(" "),p=a.map(b=>c.map(f=>{const m=b[f.field];return f.valueFormatter?f.valueFormatter({value:m,row:b,field:f.field}):m??""}).join(" ")).join(`
6
+ <%s key={someKey} {...props} />`,O,U,oe,U),K[U+O]=!0)}if(U=null,F!==void 0&&(e(F),U=""+F),d(M)&&(e(M.key),U=""+M.key),"key"in M){F={};for(var ie in M)ie!=="key"&&(F[ie]=M[ie])}else F=M;return U&&a(F,typeof v=="function"?v.displayName||v.name||"Unknown":v),h(v,U,F,l(),H,V)}function w(v){b(v)?v._store&&(v._store.validated=1):typeof v=="object"&&v!==null&&v.$$typeof===P&&(v._payload.status==="fulfilled"?b(v._payload.value)&&v._payload.value._store&&(v._payload.value._store.validated=1):v._store&&(v._store.validated=1))}function b(v){return typeof v=="object"&&v!==null&&v.$$typeof===m}var f=i,m=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),E=Symbol.for("react.strict_mode"),_=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),N=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),L=Symbol.for("react.activity"),y=Symbol.for("react.client.reference"),T=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,A=Array.isArray,$=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(v){return v()}};var D,W={},z=f.react_stack_bottom_frame.bind(f,s)(),Y=$(o(s)),K={};pt.Fragment=C,pt.jsx=function(v,M,F){var O=1e4>T.recentlyCreatedOwnerStacks++;return p(v,M,F,!1,O?Error("react-stack-top-frame"):z,O?$(o(v)):Y)},pt.jsxs=function(v,M,F){var O=1e4>T.recentlyCreatedOwnerStacks++;return p(v,M,F,!0,O?Error("react-stack-top-frame"):z,O?$(o(v)):Y)}})()),pt}var kn;function ao(){return kn||(kn=1,process.env.NODE_ENV==="production"?Rt.exports=lo():Rt.exports=so()),Rt.exports}var r=ao();function xt(n,t){return t?t.left?.includes(n)?"left":t.right?.includes(n)?"right":null:null}function co(n,t){const e=[],o=[],l=[];return t?(n.forEach(s=>{const d=xt(s.field,t);d==="left"?e.push(s):d==="right"?l.push(s):o.push(s)}),t.left&&e.sort((s,d)=>{const a=t.left.indexOf(s.field),c=t.left.indexOf(d.field);return a-c}),t.right&&l.sort((s,d)=>{const a=t.right.indexOf(s.field),c=t.right.indexOf(d.field);return a-c}),{left:e,center:o,right:l}):{left:e,center:n,right:l}}function Xt(n,t,e,o,l,s,d,a){const c={};if(!e)return c;const h=co(n,e);let p=0;a&&(p+=48),s&&d&&(p+=48),o&&l&&(p+=48),h.left.forEach(b=>{c[b.field]=p;const f=t[b.field]??b.width??100;p+=f});let w=0;return[...h.right].reverse().forEach(b=>{const f=t[b.field]??b.width??100;c[b.field]=w,w+=f}),c}function Jt(n,t){return t?t.top?.includes(n)?"top":t.bottom?.includes(n)?"bottom":null:null}function uo(n,t){const e=[],o=[],l=[];return t?(n.forEach(s=>{const d=Jt(s.id,t);d==="top"?e.push(s):d==="bottom"?l.push(s):o.push(s)}),t.top&&e.sort((s,d)=>{const a=t.top.indexOf(s.id),c=t.top.indexOf(d.id);return a-c}),t.bottom&&l.sort((s,d)=>{const a=t.bottom.indexOf(s.id),c=t.bottom.indexOf(d.id);return a-c}),{top:e,center:o,bottom:l}):{top:e,center:n,bottom:l}}function qe(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 fo(n){const{rowHeight:t,pagination:e,paginatedUnpinnedRows:o,sortedUnpinnedRows:l,expandedRowIds:s,getDetailPanelHeight:d,pinnedTopRowsLength:a,pinnedBottomRowsLength:c,visibleOrderedColumns:h,pinnedColumns:p,columnWidths:w,viewportWidth:b,checkboxSelection:f,hasDetailPanel:m,rowReordering:x,paginationMode:C,isLoading:E,pageSize:_}=n;return i.useMemo(()=>{const S=e?o:l,N=S.map((B,Q)=>{let Z=t;if(s.has(B.id)){const ge=d?.({row:B,id:B.id,rowIndex:a+Q})??200;Z+=typeof ge=="number"?ge:parseInt(String(ge),10)||200}return Z}),g=N.reduce((B,Q,Z)=>(B.push((B[Z-1]||0)+Q),B),[]),k=C==="infinite"&&E&&S.length>0?Math.min(_,20):0,u=(g[g.length-1]||0)+k*t,j=a*t,P=c*t,L=[],y=[],T=[],I=[];h.forEach(B=>{const Q=xt(B.field,p);Q==="left"?L.push(B):Q==="right"?y.push(B):T.push(B)});const A=(f?48:0)+(m?48:0)+(x?48:0),$=B=>w[B.field]??B.width,D=L.reduce((B,Q)=>{const Z=qe($(Q));return B+(Z.type==="fixed"?Z.value:100)},0),W=y.reduce((B,Q)=>{const Z=qe($(Q));return B+(Z.type==="fixed"?Z.value:100)},0),z=T.reduce((B,Q)=>{if(!Object.prototype.hasOwnProperty.call(w,Q.field)&&Q.flex&&Q.flex>0){const ce=Q.minWidth??150,Ee=typeof Q.width=="number"?Q.width:150;return B+(ce||Ee)}const ge=qe($(Q));return ge.type==="fixed"?B+ge.value:ge.type==="percentage"?B+100:B+(Q.minWidth??150)},0),Y=Math.max(b-A-D-W,z),K=[],v=[],M=[];T.forEach(B=>{const Q=Object.prototype.hasOwnProperty.call(w,B.field),Z=qe($(B));if(!Q&&B.flex&&B.flex>0){M.push({col:B,flex:B.flex});return}Z.type==="fixed"?K.push({col:B,width:Z.value}):Z.type==="percentage"?v.push({col:B,percentage:Z.value}):M.push({col:B,flex:1})});const F=K.reduce((B,{width:Q})=>B+Q,0);let O=Math.max(0,Y-F);const H=new Map;v.forEach(({col:B,percentage:Q})=>{const Z=Q/100*O;H.set(B.field,Z),O-=Z}),O=Math.max(0,O);const V=new Map,U=M.map(B=>({...B,minWidth:B.col.minWidth??50,maxWidth:B.col.maxWidth??1/0,frozen:!1,computedWidth:0}));(()=>{let B=0;const Q=U.length*2;for(;B<Q;){B++;const Z=U.filter(ee=>!ee.frozen);if(Z.length===0)break;const ge=Z.reduce((ee,ye)=>ee+ye.flex,0),ce=U.reduce((ee,ye)=>ye.frozen?ee+ye.computedWidth:ee,0),Ee=Math.max(0,O-ce);if(ge<=0){Z.forEach(ee=>{ee.computedWidth=ee.minWidth,ee.frozen=!0});break}const Te=Ee/ge;let Pe=0;const Re=[],ze=[];if(Z.forEach(ee=>{const ye=Te*ee.flex;ye<ee.minWidth?(Pe+=ee.minWidth-ye,Re.push(ee)):ye>ee.maxWidth?(Pe+=ee.maxWidth-ye,ze.push(ee)):ee.computedWidth=ye}),Re.length===0&&ze.length===0){Z.forEach(ee=>ee.frozen=!0);break}Pe>0?Re.forEach(ee=>{ee.computedWidth=ee.minWidth,ee.frozen=!0}):Pe<0?ze.forEach(ee=>{ee.computedWidth=ee.maxWidth,ee.frozen=!0}):(Re.forEach(ee=>{ee.computedWidth=ee.minWidth,ee.frozen=!0}),ze.forEach(ee=>{ee.computedWidth=ee.maxWidth,ee.frozen=!0}))}})(),U.forEach(B=>V.set(B.col.field,B.computedWidth));const ie=new Map;T.forEach(B=>{let Q;if(V.has(B.field))Q=V.get(B.field);else{const Z=K.find(ce=>ce.col.field===B.field),ge=v.find(ce=>ce.col.field===B.field);if(Z)Q=Z.width;else if(ge){const ce=H.get(B.field)||0;Q=Math.max(B.minWidth??50,ce||100)}else Q=100}I.push(Q),ie.set(B.field,Q)});const ne=T.map(B=>{const Q=U.find(Z=>Z.col.field===B.field);return{...B,width:ie.get(B.field)??(typeof B.width=="number"?B.width:100),flex:Q?Q.flex:B.flex}}),R=11,le=L.map((B,Q)=>{const Z=qe($(B));return{...B,width:Z.type==="fixed"?Z.value:100,zIndex:R+Q}}),te=11,re=y.map((B,Q)=>{const Z=qe($(B));return{...B,width:Z.type==="fixed"?Z.value:100,zIndex:te+(y.length-1-Q)}}),q=I.reduce((B,Q)=>B+Q,0),J=D+q+W+A,de=I.reduce((B,Q,Z)=>(B.push((B[Z-1]||0)+Q),B),[]);return{rowHeights:N,cumulativeHeights:g,unpinnedRowsHeight:u,pinnedTopHeight:j,pinnedBottomHeight:P,leftPinnedCols:le,rightPinnedCols:re,unpinnedColsWithWidth:ne,unpinnedColWidths:I,unpinnedAccWidths:de,totalWidth:J,leftWidth:D,rightWidth:W,unpinnedTotalWidth:q,systemColumnsWidth:A,pinnedTopRowsLength:a,pinnedBottomRowsLength:c,unpinnedRowsLength:S.length}},[t,e,o,l,s,d,a,c,h,p,w,b,f,m,x,C,E,_])}function go(n){const{allRenderableRows:t,navigationColumns:e,checkboxSelection:o,selectedRowIds:l,handleSelectionChange:s,handleDetailPanelToggle:d,editingHandlers:a,setKeyboardMode:c,sortModel:h,handleSort:p,isCellEditable:w,pagination:b,pageSize:f,virtualization:m,viewportRef:x}=n,[C,E]=i.useState(null),_=i.useCallback(g=>{g.target===g.currentTarget&&E(k=>{if(k)return k;if(o)return{id:"HEADER",field:"__checkbox_col__"};const u=t[0],j=e[0];return u&&j?{id:u.id,field:j.field}:null})},[t,e,o]),S=i.useCallback(g=>{g.currentTarget.contains(g.relatedTarget)||E(null)},[]),N=i.useCallback(g=>{if(c(!0),!C)return;const{id:k,field:u}=C,j=!!a.editingCell;if(k==="HEADER"&&(g.key==="Enter"||g.key===" ")){g.preventDefault();const W=e.find(z=>z.field===u);if(W&&W.sortable!==!1){const z=h.find(K=>K.field===u);let Y="asc";z&&(Y=z.sort==="asc"?"desc":null),p(u,Y)}return}if(g.key==="Enter"){if(g.preventDefault(),j)a.stopCellEdit();else if(e.find(z=>z.field===u)?.editable){const z=t.find(Y=>Y.id===k);z&&a.startCellEdit({id:k,field:u,value:z[u]})}return}if((g.key===" "||g.key==="Spacebar")&&!j){if(u==="__checkbox_col__"){g.preventDefault(),s(k,!l.has(k));return}if(u==="__expand_col__"){g.preventDefault(),d(k);return}}if(g.key==="Escape"){j&&(g.preventDefault(),a.stopCellEdit({cancel:!0}));return}if(j&&g.key!=="Tab")return;const P=k==="HEADER",L=P?-1:t.findIndex(W=>W.id===k),y=e.findIndex(W=>W.field===u);if(!P&&L===-1||y===-1)return;const T=(W,z,Y,K,v,M=!1)=>{let F=W+Y,O=z+K;return v&&K!==0&&(K>0&&O>=e.length?(O=0,F++):K<0&&O<0&&(O=e.length-1,F--)),!v&&(O<0||O>=e.length)||F<(M?-1:0)||F>=t.length?null:{r:F,c:O}},I=(W,z,Y,K,v,M=!1)=>{let F=W,O=z,H=0;const V=t.length*e.length+e.length;for(;H<V;){if(H++,F+=Y,O+=K,K!==0)K>0?O>=e.length&&(O=0,F++):O<0&&(O=e.length-1,F--);else if(O<0||O>=e.length)return null;if(F<-1||F>=t.length)return null;if(F===-1){if(!M)continue;const R=e[O],le=R.sortable!==!1;if(["__checkbox_col__"].includes(R.field)||le)return{r:F,c:O};continue}const U=t[F],oe=e[O],ie=["__checkbox_col__","__expand_col__","__reorder_col__"].includes(oe.field);let ne=oe.editable||ie;if(w&&!ie)try{ne=w({row:U,field:oe.field,value:U[oe.field],colDef:oe,rowIndex:F,colIndex:O})}catch{}if(ne)return{r:F,c:O}}return null};let A=L,$=y,D=!1;if(g.key==="Tab"){const W=g.shiftKey?-1:1,z=I(L,y,0,W,!0,!1);z&&(A=z.r,$=z.c,D=!0)}else if(g.key==="ArrowRight"){const W=T(L,y,0,1,!0,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="ArrowLeft"){const W=T(L,y,0,-1,!0,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="ArrowDown"){const W=T(L,y,1,0,!1,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="ArrowUp"){const W=T(L,y,-1,0,!1,!0);W&&(A=W.r,$=W.c,D=!0)}else if(g.key==="Home")$=0,(g.ctrlKey||g.metaKey)&&(A=-1),D=!0;else if(g.key==="End")$=e.length-1,(g.ctrlKey||g.metaKey)&&(A=t.length-1),D=!0;else if(g.key==="PageUp")A=Math.max(-1,A-(b?f:10)),D=!0;else if(g.key==="PageDown"){const W=b?f:10;A=Math.min(t.length-1,A+W),D=!0}if(D&&(g.preventDefault(),j&&g.key==="Tab"&&a.stopCellEdit(),A>=-1&&A<t.length&&$>=0&&$<e.length)){const W=e[$];E(A===-1?{id:"HEADER",field:W.field}:{id:t[A].id,field:W.field});const z=x.current;if(z){const{cumulativeHeights:Y,pinnedTopHeight:K,columnMetrics:v}=m,{clientHeight:M,clientWidth:F,scrollTop:O,scrollLeft:H}=z,V=A<=0?0:Y[A-1],U=Y[A],oe=O+K,ie=O+M;let ne=O;if(V<oe?ne=Math.max(0,V-K):U>ie&&(ne=U-M),ne!==O&&(z.scrollTop=ne),v){const{leftPinnedWidth:R,rightPinnedWidth:le,unpinnedAccWidths:te,unpinnedCols:re,totalSpecialsWidth:q,pinnedSpecialsWidth:J}=v,de=re.findIndex(B=>B.field===W.field);if(de!==-1){const B=q+R+(de>0?te[de-1]:0),Q=q+R+te[de],Z=H+J+R,ge=H+F-le;let ce=H;B<Z?ce=Math.max(0,B-J-R):Q>ge&&(ce=Q-F+le),ce!==H&&(z.scrollLeft=ce)}}}}},[C,t,e,a,m,l,s,d,c,h,p,w,b,f,x]);return{focusedCell:C,setFocusedCell:E,handleFocus:_,handleBlur:S,handleKeyDown:N}}const ho={rowFields:[],columnFields:[],valueFields:[]};function po(n){const{initialState:t,sortModel:e,aggregationModel:o,onAggregationModelChange:l,columnVisibilityModel:s,onColumnVisibilityModelChange:d,pinnedColumns:a,onPinnedColumnsChange:c,pivotModel:h,onPivotModelChange:p,paginationModel:w,onPaginationModelChange:b,rowSelectionModel:f}=n,[m,x]=i.useState(()=>t?.sorting?.sortModel??[]),C=e!==void 0,E=C?e:m,_=o!==void 0,[S,N]=i.useState(()=>o??{}),g=_?o:S,k=i.useCallback(R=>{_||N(R),l?.(R)},[_,l]),u=s!==void 0,[j,P]=i.useState(()=>t?.columns?.columnVisibilityModel??{}),L=u?s:j,y=i.useCallback(R=>{u||P(R),d?.(R)},[u,d]),T=a!==void 0,[I,A]=i.useState(()=>t?.columns?.pinnedColumns??{}),$=T?a:I,D=i.useCallback(R=>{T||A(R),c?.(R)},[T,c]),[W,z]=i.useState(()=>h??ho),Y=h??W,K=i.useCallback(R=>{z(R),p?.(R)},[p]),v=w!==void 0,[M,F]=i.useState(()=>t?.pagination?.paginationModel??w??{page:0,pageSize:100}),O=v?w:M,H=i.useCallback(R=>{v||F(R),b?.(R)},[v,b]),V=f!==void 0,[U,oe]=i.useState([]),ie=V?f:U,ne=i.useMemo(()=>new Set(ie),[ie]);return{sortModel:E,isSortControlled:C,setInternalSortModel:x,aggregationModel:g,handleAggregationModelChange:k,columnVisibilityModel:L,handleColumnVisibilityModelChange:y,pinnedColumns:$,handlePinnedColumnsChange:D,currentPivotModel:Y,handlePivotModelChange:K,effectivePaginationModel:O,handlePaginationModelChange:H,rowSelectionModel:ie,selectedRowIds:ne,isSelectionControlled:V,setInternalRowSelectionModel:oe}}const xo={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 mo(n,t){const{field:e,operator:o,value:l}=t,s=n[e],d=xo[o];return d?d(s,l):(console.warn(`Unknown filter operator: ${o}`),!0)}function bo(n,t){return!t||t.length===0?!0:t.every(e=>{const o=e.toLowerCase();return Object.values(n).some(l=>l==null?!1:String(l).toLowerCase().includes(o))})}function Qt(n,t){const e=t.items??[],o=t.logicOperator??"and",l=("quickFilterValues"in t?t.quickFilterValues:void 0)??[];if(l.length>0&&!bo(n,l))return!1;if(e.length===0)return!0;const s=d=>{if("logicOperator"in d&&"items"in d){const a=d,c=a.items;return c.length===0?!0:a.logicOperator==="and"?c.every(s):c.some(s)}else return mo(n,d)};return o==="and"?e.every(s):e.some(s)}function wo(n,t){if(!t)return n;const{items:e=[],quickFilterValues:o=[]}=t;return e.length===0&&(!o||o.length===0)?n:n.filter(l=>Qt(l,t))}function vo(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 Zt(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(),l=String(t).toLowerCase();return e==="asc"?o<l?-1:o>l?1:0:o>l?-1:o<l?1:0}function _o(n,t){if(t.length===0)return n;const e=[...n];return e.sort((o,l)=>{for(const s of t){const d=o[s.field],a=l[s.field],c=Zt(d,a,s.sort);if(c!==0)return c}return 0}),e}function Co(n){const{effectiveRows:t,activeHierarchyHandlers:e,filterMode:o,filterModel:l,dataSource:s,sortModel:d,sortingMode:a,pagination:c,paginationMode:h,effectivePaginationModel:p,pinnedRows:w,isLoading:b,pageSize:f}=n,m=i.useMemo(()=>e?e.getVisibleRows()||[]:o==="server"&&s?t:wo(t,l),[t,l,e,o,s]),{top:x,center:C,bottom:E}=i.useMemo(()=>e?{top:[],center:m,bottom:[]}:uo(m,w),[m,w,e]),_=i.useMemo(()=>e||a==="server"&&s?C:_o(C,d),[C,d,e,a,s]),S=i.useMemo(()=>{if(!c||h==="server"&&s)return _;const g=p.page*p.pageSize;return _.slice(g,g+p.pageSize)},[_,c,p.page,p.pageSize,h,s]),N=i.useMemo(()=>{if(e)return C;const g=c?S:_,k=[...x,...g,...E];if(h==="infinite"&&b&&k.length>0){const u=Math.min(f,20),j=Array.from({length:u},(P,L)=>({id:`__skeleton_${L}__`,_isSkeleton:!0}));return[...k,...j]}return k},[x,S,_,E,c,e,C,h,b,f]);return{filteredRows:m,pinnedTopRows:x,unpinnedRows:C,pinnedBottomRows:E,sortedUnpinnedRows:_,paginatedUnpinnedRows:S,allRenderableRows:N}}function yo(n){const{layout:t,scrollTop:e,scrollLeft:o,viewportWidth:l,viewportHeight:s,autoHeight:d,rowReordering:a,hasDetailPanel:c,checkboxSelection:h,pinCheckboxColumn:p,pinExpandColumn:w}=n;return i.useMemo(()=>{const{unpinnedAccWidths:b,unpinnedColsWithWidth:f,leftPinnedCols:m,rightPinnedCols:x,totalWidth:C,leftWidth:E,rightWidth:_,unpinnedTotalWidth:S,systemColumnsWidth:N,cumulativeHeights:g,pinnedTopHeight:k,pinnedBottomHeight:u,unpinnedRowsHeight:j,rowHeights:P,unpinnedRowsLength:L}=t,y=l||1e3,T=d?k+j+u+50:s||600,I=6,A=Math.max(0,o-E),$=o+y-E;let D=0,W=f.length-1,z=0,Y=b.length-1;for(;z<=Y;){const te=z+Y>>>1;b[te]<A?z=te+1:Y=te-1}D=Math.max(0,z-I);for(let te=D;te<b.length;te++){if((te===0?0:b[te-1])>$){W=Math.min(f.length-1,te+I);break}W=Math.min(f.length-1,te+I)}const K=D>0?b[D-1]:0,v=S-b[W],M=[...m,...K>0?[{field:"__spacer_left__",width:K,isSpacer:!0}]:[],...f.slice(D,W+1),...v>0?[{field:"__spacer_right__",width:v,isSpacer:!0}]:[],...x],O=y>0&&C>y?16:0,H=k+j+u+O+2,V=5;let U=0,oe=L-1,ie=0,ne=0,R=g.length-1;for(;ne<=R;){const te=ne+R>>>1;g[te]<e?ne=te+1:R=te-1}U=Math.max(0,ne-V),ie=U>0?g[U-1]:0;for(let te=U;te<g.length;te++)if(g[te]>=e+T){oe=Math.min(L-1,te+V);break}const le=(a?48:0)+(c&&w?48:0)+(h&&p?48:0);return{renderContext:{firstRowIndex:U,lastRowIndex:oe,firstColumnIndex:D,lastColumnIndex:W},offsetTop:ie,offsetLeft:0,totalHeight:H,pinnedTopHeight:k,pinnedBottomHeight:u,totalWidth:C,rowHeights:P,cumulativeHeights:g,virtualColumns:M,columnMetrics:{leftPinnedWidth:E,rightPinnedWidth:_,unpinnedAccWidths:b,unpinnedCols:f,totalSpecialsWidth:N,pinnedSpecialsWidth:le}}},[t,e,o,l,s,d,a,c,h,p,w])}function ko(n){const{columns:t,onColumnOrderChange:e,disableColumnReorder:o=!1}=n,[l,s]=i.useState(null),[d,a]=i.useState(null),c=i.useRef(-1),h=i.useCallback(f=>m=>{if(o)return;const x=t.findIndex(E=>E.field===f);if(t[x]?.pinnable===!1){m.preventDefault();return}s(f),c.current=x,m.dataTransfer&&(m.dataTransfer.effectAllowed="move",m.dataTransfer.setData("text/plain",f))},[t,o]),p=i.useCallback(f=>m=>{o||!l||(m.preventDefault(),m.dataTransfer.dropEffect="move",a(f))},[l,o]),w=i.useCallback(f=>m=>{if(m.preventDefault(),o||!l||l===f){s(null),a(null);return}const x=t.findIndex(_=>_.field===l),C=t.findIndex(_=>_.field===f);if(x===-1||C===-1){s(null),a(null);return}const E=t[x];e&&e({column:E,oldIndex:x,targetIndex:C}),s(null),a(null),c.current=-1},[t,l,o,e]),b=i.useCallback(()=>{s(null),a(null),c.current=-1},[]);return{draggedColumn:l,dragOverColumn:d,onDragStart:o?void 0:h,onDragOver:o?void 0:p,onDragEnd:o?void 0:b,onDrop:o?void 0:w}}function Sn({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 So(n){const{activeColumns:t,isHierarchyEnabled:e,isRowGrouping:o,isTreeData:l,activeHierarchyHandlers:s,columnVisibilityModel:d,columnOrder:a,onColumnOrderChange:c,disableColumnReorder:h,pivotMode:p,checkboxSelection:w,hasDetailPanel:b,rowReordering:f,initialState:m,setColumns:x}=n,C=i.useMemo(()=>e?t.map((y,T)=>T===0?{...y,renderCell:I=>{const A=I.rowMeta,$=A?.treeDepth??0,D=!!A?.hasChildren,W=!!A?.isExpanded,z=A?.groupingField,Y=A?.groupingValue,K=A?.descendantCount,v=!!A?.isGroupRow;let M=y.renderCell?y.renderCell(I):I.value;if(l&&D&&v&&(M=r.jsxs("div",{className:"ogx__group-cell-content",children:[I.value,K!==void 0&&K>0?` (${K})`:""]})),o&&D&&z){const F=A?.groupLabel??`${z}: ${String(Y)}`;M=r.jsxs("div",{className:"ogx__group-cell-content",children:[F,K!==void 0?` (${K})`:""]})}return r.jsxs("div",{style:{display:"flex",alignItems:"center",paddingLeft:$*24,width:"100%",height:"100%"},children:[r.jsx("div",{style:{marginRight:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:D?"pointer":"default",flexShrink:0},children:D?r.jsx("div",{onClick:F=>{F.stopPropagation(),F.preventDefault(),s?.toggleExpansion(I.row.id)},onMouseDown:F=>{F.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:r.jsx(Sn,{isExpanded:W,onClick:F=>{F.stopPropagation(),F.preventDefault(),s?.toggleExpansion(I.row.id)}})}):null}),r.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:M})]})}}:{...y,renderCell:I=>{const A=I.rowMeta,$=!!A?.hasChildren,D=A?.groupingField;return o&&$?y.field===D?null:I.value!==void 0&&I.value!==null?y.renderCell?y.renderCell(I):I.value:null:y.renderCell?y.renderCell(I):I.value}}):t,[t,e,o,l,s]),[E,_]=i.useState(()=>m?.columns?.columnWidths??{}),S=i.useCallback((y,T)=>{_(I=>({...I,[y]:T}))},[]),[N,g]=i.useState(()=>m?.columns?.columnOrder??t.map(y=>y.field)),k=a??N;i.useEffect(()=>{x(t)},[t,x]),i.useEffect(()=>{p&&g(t.map(y=>y.field))},[p,t]);const u=i.useMemo(()=>{if(h)return C;const y=new Map(k.map((T,I)=>[T,I]));return[...C].sort((T,I)=>{const A=y.get(T.field)??C.indexOf(T),$=y.get(I.field)??C.indexOf(I);return A-$})},[C,k,h]),j=i.useMemo(()=>u.filter(y=>d[y.field]!==!1),[u,d]),P=ko({columns:u,onColumnOrderChange:i.useCallback(y=>{const{oldIndex:T,targetIndex:I}=y,A=[...k],[$]=A.splice(T,1);A.splice(I,0,$),a||g(A),c?.(y)},[k,a,c]),disableColumnReorder:h}),L=i.useMemo(()=>{const y=[];return f&&y.push({field:"__reorder_col__"}),b&&y.push({field:"__expand_col__"}),w&&y.push({field:"__checkbox_col__"}),[...y,...u]},[u,w,b,f]);return{effectiveColumns:C,orderedColumns:u,visibleOrderedColumns:j,navigationColumns:L,columnWidths:E,effectiveColumnOrder:k,setInternalColumnOrder:g,columnReorderHandlers:P,handleColumnResize:S}}function jo(n){const{renderContext:t,pinnedTopRows:e,pinnedBottomRows:o,paginatedUnpinnedRows:l,sortedUnpinnedRows:s,pagination:d}=n;return i.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:c}=t,h=d?l:s,p=e.length,w=e.map((_,S)=>({row:_,rowIndex:S})),b=o.map((_,S)=>({row:_,rowIndex:p+h.length+S})),f=Math.max(0,a-p),m=Math.min(h.length,c-p+1),x=h.slice(f,m).map((_,S)=>({row:_,rowIndex:p+f+S})),C=[...w,...x,...b],E=new Set;return C.filter(_=>E.has(_.row.id)?!1:(E.add(_.row.id),!0))},[t,e,o,l,s,d])}function Eo(n){const{onRowsScrollEnd:t}=n,e=i.useRef({scrollTop:0,scrollLeft:0}),o=i.useRef(null),[l,s]=i.useState({scrollTop:0,scrollLeft:0});i.useEffect(()=>()=>{o.current!==null&&cancelAnimationFrame(o.current)},[]);const d=i.useCallback(a=>{const c=a.currentTarget;if(e.current={scrollTop:c.scrollTop,scrollLeft:c.scrollLeft},o.current!==null&&cancelAnimationFrame(o.current),o.current=requestAnimationFrame(()=>{o.current=null,s(e.current)}),t){const{scrollTop:h,scrollHeight:p,clientHeight:w}=c;p-h-w<100&&t({visibleTop:h,visibleBottom:h+w,viewportHeight:w})}},[t]);return{scrollTop:l.scrollTop,scrollLeft:l.scrollLeft,handleScroll:d}}function No(n){const{onStateChange:t,sortModel:e,filterModel:o,effectivePaginationModel:l,columnWidths:s,effectiveColumnOrder:d,columnVisibilityModel:a,pinnedColumns:c}=n,h=i.useRef(t);i.useLayoutEffect(()=>{h.current=t}),i.useEffect(()=>{if(!h.current)return;const p={sorting:{sortModel:e},filter:{filterModel:o},pagination:{paginationModel:l},columns:{columnWidths:s,columnOrder:d,columnVisibilityModel:a,pinnedColumns:c}};h.current(p)},[e,o,l,s,d,a,c])}const Mo={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 jn(n){const{rows:t,columns:e,aggregationModel:o,isServerSide:l,dataSource:s,filterModel:d,sortModel:a,serverAggregationResults:c}=n,h=i.useMemo(()=>{const N=new Map;return(e??[]).forEach(g=>N.set(g.field,g)),N},[e]),p=i.useMemo(()=>{if(l||Object.keys(o).length===0)return{};const N={};for(const[g,k]of Object.entries(o)){const u=h.get(g);if(u?.availableAggregationFunctions&&!u.availableAggregationFunctions.includes(k))continue;const j=Mo[k];if(!j){console.warn(`[useAggregation] Unknown aggregation function: "${k}"`);continue}const P=t.map(L=>L[g]);N[g]=j(P)}return N},[t,h,o,l]),[w,b]=i.useState({}),[f,m]=i.useState(!1),[x,C]=i.useState(null),E=i.useRef(0),_=i.useCallback(async()=>{if(!s?.getAggregations||Object.keys(o).length===0)return;const N=++E.current;m(!0),C(null);try{const g=await s.getAggregations({sortModel:a??[],filterModel:d??{items:[]},groupKeys:[],aggregationModel:o});N===E.current&&b(g)}catch(g){N===E.current&&(C(g),console.error("[useAggregation] Server aggregation error:",g))}finally{N===E.current&&m(!1)}},[s,o,d,a]);return i.useEffect(()=>{l&&s?.getAggregations&&!c&&_()},[_,l,s,c]),{aggregationResult:i.useMemo(()=>l?c&&Object.keys(c).length>0?c:w:p,[l,p,c,w]),isLoading:f,error:x}}function Po({columns:n,aggregationModel:t,aggregationResult:e,columnWidths:o,rowHeight:l,checkboxSelection:s,hasDetailPanel:d,rowReordering:a,pinnedColumns:c}){const h=i.useMemo(()=>Xt(n,o,c,s,!0,d,!0,a),[n,o,c,s,d,a]),p=c?.left?.[c.left.length-1],w=c?.right?.[0];return r.jsxs("div",{className:"ogx__aggregation-footer",role:"row","aria-label":"Aggregation totals","aria-live":"polite",style:{minHeight:`${l}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(b=>{const f=t[b.field],m=e[b.field],x=o[b.field]??(typeof b.width=="number"?b.width:120),C=xt(b.field,c),E=C?h[b.field]:void 0,_=["ogx__aggregation-cell",C==="left"&&"ogx__aggregation-cell--pinned-left",C==="right"&&"ogx__aggregation-cell--pinned-right",C==="left"&&b.field===p&&"ogx__aggregation-cell--pinned-left-last",C==="right"&&b.field===w&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),S={width:x,minWidth:x,maxWidth:x,textAlign:b.align||"left"};return C==="left"&&E!==void 0&&(S.left=E),C==="right"&&E!==void 0&&(S.right=E),r.jsx("div",{className:_,role:"gridcell",style:S,children:f?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"ogx__aggregation-label",children:f}),r.jsx("span",{className:"ogx__aggregation-value",children:_e(m,f)})]}):null},b.field)})]})}function Io({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 To({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 mt=({indeterminate:n=!1,label:t,className:e="",inputRef:o,...l})=>{const s=i.useRef(null),d=i.useCallback(c=>{s.current=c,typeof o=="function"?o(c):o&&(o.current=c)},[o]);i.useEffect(()=>{s.current&&(s.current.indeterminate=n)},[n]);const a=["ogx-checkbox-wrapper",l.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||l["aria-label"]||(n?"Select some":l.checked?"Deselect":"Select"),...l}),r.jsxs("span",{className:"ogx-checkbox__box",children:[l.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 Ro(n){const{field:t,currentWidth:e,onResize:o,minWidth:l=50,maxWidth:s=1e3}=n,[d,a]=i.useState(!1),c=i.useRef(0),h=i.useRef(0),p=i.useCallback(f=>{f.preventDefault(),f.stopPropagation(),a(!0),c.current=f.clientX,h.current=e;let m=0;const x=16,C=_=>{const S=_.clientX-c.current,N=Math.max(l,Math.min(s,h.current+S)),g=Date.now();g-m>=x&&(o(t,N),m=g)},E=_=>{a(!1);const S=_.clientX-c.current,N=Math.max(l,Math.min(s,h.current+S));o(t,N),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",E)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",E)},[t,e,o,l,s]),w=i.useCallback(f=>{f.preventDefault(),f.stopPropagation()},[]),b=["ogx-column-resize-handle",d&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return r.jsx("div",{className:b,onMouseDown:p,onClick:f=>f.stopPropagation(),onDragStart:f=>{f.preventDefault(),f.stopPropagation()},onDoubleClick:w,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,children:r.jsx("div",{className:"ogx-column-resize-handle__line"})})}function Xe(){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 Je(){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 Lo(){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 Fo(){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 Oo(){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 Wo(){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 Ao(){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 $o(){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 zo(){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 Bo(){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 Ho({colDef:n,sortModel:t,onSort:e,onHide:o,onPin:l,pinnedColumns:s,onManageColumns:d,onClose:a,anchorEl:c}){const h=i.useRef(null),[p,w]=i.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});i.useLayoutEffect(()=>{if(!c||!h.current)return;const g=c.getBoundingClientRect(),k=h.current.getBoundingClientRect(),u=window.innerWidth,j=window.innerHeight,P=8;let L=g.left;L+k.width+P>u&&(L=u-k.width-P),L<P&&(L=P);let y=g.bottom+4;y+k.height+P>j&&(y=g.top-k.height-4),w({position:"fixed",zIndex:1300,top:y,left:L,visibility:"visible"})},[c]),i.useEffect(()=>{function g(u){h.current&&!h.current.contains(u.target)&&c&&!c.contains(u.target)&&a()}function k(u){u.key==="Escape"&&a()}return document.addEventListener("mousedown",g),document.addEventListener("keydown",k),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",k),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[c,a]);const b=g=>{e?.(n.field,g),a()},f=()=>{o?.(n.field),a()},m=g=>{l?.(n.field,g),a()},x=t?.find(g=>g.field===n.field)?.sort,C=x==null,E=s?.left?.includes(n.field)??!1,_=s?.right?.includes(n.field)??!1,S=!E&&!_,N=n.headerName||n.field;return Ge.createPortal(r.jsxs("div",{ref:h,className:"ogx-column-menu",style:p,role:"menu","aria-label":`Column options for ${N}`,children:[e&&n.sortable!==!1&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:`ogx-menu-item${x==="asc"?" ogx-menu-item--active":""}`,onClick:()=>b("asc"),role:"menuitemradio","aria-checked":x==="asc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:x==="asc"?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Fo,{})}),"Sort Ascending"]}),r.jsxs("button",{className:`ogx-menu-item${x==="desc"?" ogx-menu-item--active":""}`,onClick:()=>b("desc"),role:"menuitemradio","aria-checked":x==="desc",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:x==="desc"?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Oo,{})}),"Sort Descending"]}),r.jsxs("button",{className:`ogx-menu-item${C?" ogx-menu-item--active":""}`,onClick:()=>b(null),role:"menuitemradio","aria-checked":C,children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:C?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Wo,{})}),"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${E?" ogx-menu-item--active":""}`,onClick:()=>m("left"),role:"menuitemradio","aria-checked":E,"aria-label":"Pin to left",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx($o,{})}),"Pin to Left"]}),r.jsxs("button",{className:`ogx-menu-item${_?" ogx-menu-item--active":""}`,onClick:()=>m("right"),role:"menuitemradio","aria-checked":_,"aria-label":"Pin to right",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:_?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(zo,{})}),"Pin to Right"]}),r.jsxs("button",{className:`ogx-menu-item${S?" ogx-menu-item--active":""}`,onClick:()=>m(null),role:"menuitemradio","aria-checked":S,"aria-label":"Unpin column",children:[r.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:S?r.jsx(Xe,{}):r.jsx(Je,{})}),r.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:r.jsx(Bo,{})}),"Unpin"]}),r.jsx("div",{className:"ogx-menu-divider"}),r.jsxs("button",{className:"ogx-menu-item",onClick:f,role:"menuitem","aria-label":`Hide ${N} 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(Ao,{})}),"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(Lo,{})}),"Manage columns"]})]}),c?.closest(".ogx-theme-provider")||document.body)}function Do(){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 Go(){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 En(n){const t=[];for(const e of n.children)typeof e=="string"?t.push(e):t.push(...En(e));return t}function Vo(n){let t=0;function e(o,l){t=Math.max(t,l);for(const s of o.children)typeof s!="string"&&e(s,l+1)}return n.forEach(o=>e(o,1)),t}function Uo(n,t,e){function o(a,c,h){if(!En(a).includes(c))return null;if(h===e)return a;for(const p of a.children)if(typeof p!="string"){const w=o(p,c,h+1);if(w)return w}return null}const l=new Map;for(const a of t){let c=null;for(const h of n)if(c=o(h,a.field,0),c)break;l.set(a.field,c)}const s=[];let d=0;for(;d<t.length;){const a=t[d],c=l.get(a.field)??null,h=a.width;if(!c)s.push({key:`fg-${a.field}-${e}`,label:"",width:h,isGroup:!1}),d++;else{let p=0,w=d;for(;w<t.length&&l.get(t[w].field)===c;)p+=t[w].width,w++;s.push({key:`${c.groupId}-${e}`,label:c.headerName,width:p,isGroup:!0}),d=w}}return s}function Nn(n){const{columns:t,allColumns:e,columnGroupingModel:o,checkboxSelection:l=!1,allSelected:s=!1,someSelected:d=!1,onSelectAll:a,onSort:c,sortModel:h=[],onColumnResize:p,columnWidths:w={},pinnedColumns:b,hasDetailPanel:f=!1,pinCheckboxColumn:m=!0,pinExpandColumn:x=!0,rowReordering:C=!1,aggregationModel:E,draggedColumn:_,dragOverColumn:S,onDragStart:N,onDragOver:g,onDragEnd:k,onDrop:u,focusedCell:j,onHeaderClick:P,onSortAdd:L,multiSort:y=!1,onHideColumn:T,onPinColumn:I,onManageColumns:A}=n,$=i.useId(),D=i.useRef({}),[W,z]=i.useState(null),Y=R=>le=>{le.stopPropagation(),z({colDef:R,anchorEl:le.currentTarget})},K=()=>{z(null)};i.useLayoutEffect(()=>{if(j?.id==="HEADER"){const R=D.current[j.field];R&&R.focus()}},[j]);const v=R=>le=>{if(R.sortable===!1)return;const te=h.find(q=>q.field===R.field);let re="asc";te&&(te.sort==="asc"?re="desc":re=null),(le.shiftKey||y)&&L?L(R.field,re):c&&c(R.field,re)},M=R=>{const le=h.find(re=>re.field===R);if(!le)return null;const te=h.length>1?h.indexOf(le)+1:null;return r.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${le.sort}`,"aria-hidden":"true",children:te!==null&&r.jsx("span",{className:"ogx__sort-badge",children:te})})},F=i.useMemo(()=>Xt(t,w,b,l,m,f,x,C),[t,w,b,l,m,f,x,C]),O=o?Vo(o):0,V=(e??t).filter(R=>!R.isSpacer).map(R=>({field:R.field,width:w[R.field]??R.width??100})),ne=(C?48:0)+(f?48:0)+(l?48:0);return r.jsxs("div",{className:"ogx__header-wrap",children:[O>0&&Array.from({length:O},(R,le)=>{const te=Uo(o,V,le);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"}),te.map(re=>r.jsx("div",{role:"columnheader",className:`ogx-col-group-cell ${re.isGroup?"ogx-col-group-cell--group":"ogx-col-group-cell--filler"}`,style:{width:re.width,minWidth:re.width,flexShrink:0},title:re.isGroup?re.label:void 0,children:re.isGroup&&r.jsx("span",{className:"ogx-col-group-cell__label",children:re.label})},re.key))]},`ogx-grp-${le}`)}),r.jsxs("div",{className:"ogx__header",role:"row",children:[C&&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}}),f&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${x?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader","aria-label":"Expand row details",style:{minWidth:48,maxWidth:48,position:x?"sticky":void 0,left:x?C?48:0:void 0,zIndex:x?5:void 0}}),l&&r.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${m?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""}`,role:"columnheader",style:{position:m?"sticky":void 0,left:m?(C?48:0)+(f&&x?48:0):void 0},children:r.jsx(mt,{id:$,name:$,checked:s,indeterminate:d,onChange:R=>a?.(R.target.checked),"aria-label":s?"Deselect all rows":"Select all rows",tabIndex:j?.id==="HEADER"&&j.field==="__checkbox_col__"?0:-1,onMouseDown:R=>R.preventDefault(),inputRef:R=>{D.current.__checkbox_col__=R}})}),t.map((R,le)=>{if(R.isSpacer)return r.jsx("div",{style:{width:R.width,minWidth:R.width,flexShrink:0},"aria-hidden":"true"},R.field);const te=R.sortable!==!1,re=h.some(ee=>ee.field===R.field),q=R.resizable!==!1,J=xt(R.field,b),de=J!==null,B=_===R.field,Q=S===R.field,Z=["ogx__header-cell",`ogx__header-cell--align-${R.headerAlign||R.align||"left"}`,te&&"ogx__header-cell--sortable",re&&"ogx__header-cell--sorted",de&&"ogx__header-cell--pinned",de&&`ogx__header-cell--pinned-${J}`,B&&"ogx__header-cell--dragging",Q&&"ogx__header-cell--drag-over",j?.id==="HEADER"&&j.field===R.field&&"ogx__header-cell--focused",R.headerClassName].filter(Boolean).join(" "),ge=w[R.field]??R.width??100,ce={width:ge,minWidth:R.minWidth,maxWidth:R.maxWidth,flexGrow:R.flex??0,flexShrink:0,flexBasis:(R.flex,"auto"),boxSizing:"border-box",position:de?"sticky":"relative",zIndex:R.zIndex,opacity:B?.5:1};if(de&&J){const ee=F[R.field];J==="left"?ce.left=ee:ce.right=ee}const Ee=R.renderHeader?R.renderHeader({field:R.field,colDef:R,colIndex:le}):R.headerName||R.field,Te=ee=>{if(ee.target.closest(".ogx-column-resize-handle")){ee.stopPropagation();return}P?.(R.field),te&&v(R)(ee)},Pe=N?N(R.field):void 0,Re=g?g(R.field):void 0,ze=u?u(R.field):void 0;return r.jsxs("div",{className:Z,style:ce,title:R.description,onClick:Te,role:"columnheader",draggable:!!N,onDragStart:Pe,onDragOver:Re,onDragEnd:k,onDrop:ze,"aria-sort":te?re?h.find(ee=>ee.field===R.field)?.sort==="asc"?"ascending":"descending":"none":void 0,"aria-colindex":le+1+(l?1:0),"data-field":R.field,tabIndex:-1,ref:ee=>{D.current[R.field]=ee},children:[r.jsxs("div",{className:"ogx__header-cell-content",children:[B&&r.jsx("div",{className:"ogx__header-drag-icon",children:r.jsx(Go,{})}),r.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[r.jsx("span",{className:"ogx__header-cell-title",children:Ee}),E&&E[R.field]&&r.jsx("span",{className:"ogx__header-cell-aggregation",children:E[R.field]})]}),te&&M(R.field),!R.disableColumnMenu&&r.jsx("button",{className:"ogx__menu-icon-btn",onClick:Y(R),"aria-label":`Open column menu for ${R.headerName||R.field}`,"aria-haspopup":"menu",tabIndex:-1,children:r.jsx(Do,{})})]}),q&&p&&r.jsx(Ro,{field:R.field,currentWidth:ge,onResize:p,minWidth:R.minWidth,maxWidth:R.maxWidth})]},R.field)}),W&&r.jsx(Ho,{colDef:W.colDef,sortModel:h,onSort:c,onHide:T,onPin:I,pinnedColumns:b,onManageColumns:A,onClose:K,anchorEl:W.anchorEl})]})]})}const bt=({variant:n="text",size:t="medium",color:e="default",disabled:o=!1,className:l="",children:s,...d})=>{const a=["ogx-button",`ogx-button--${n}`,`ogx-button--${t}`,`ogx-button--${e}`,o&&"ogx-button--disabled",l].filter(Boolean).join(" ");return r.jsx("button",{className:a,disabled:o,...d,children:s})};function Mn(n){const t=i.useId(),{page:e,pageSize:o,rowCount:l,onPageChange:s,onPageSizeChange:d,pageSizeOptions:a=[10,25,50,100],showFirstButton:c=!0,showLastButton:h=!0,localeText:p}=n,w=Math.max(1,Math.ceil(l/o)),b=Math.min(e,w-1),f=b*o,m=Math.min(f+o,l),x=l===0?0:`${f+1}–${m}`,C=p?.paginationRowsPerPage??"Rows per page:",E=p?.paginationOf?p.paginationOf(l===0?0:f+1,m,l):`${x} of ${l}`,_=p?.paginationPage?p.paginationPage(b+1,w):`Page ${b+1} of ${w}`,S=()=>{s(0)},N=()=>{s(Math.max(0,b-1))},g=()=>{s(Math.min(w-1,b+1))},k=()=>{s(w-1)},u=L=>{const y=parseInt(L.target.value,10);d(y)},j=b===0,P=b>=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:C}),r.jsx("select",{id:t,className:"ogx-pagination__select",value:o,onChange:u,"aria-label":"Rows per page",children:a.map(L=>r.jsx("option",{value:L,children:L},L))})]}),r.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:E}),r.jsxs("div",{className:"ogx-pagination__actions",children:[c&&r.jsx(bt,{variant:"text",size:"small",onClick:S,disabled:j,"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(bt,{variant:"text",size:"small",onClick:N,disabled:j,"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:_}),r.jsx(bt,{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"})})}),h&&r.jsx(bt,{variant:"text",size:"small",onClick:k,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 Ko(n,t,e={}){const o=new Map,l=[];n.forEach(a=>{o.set(a.id,a),l.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:l},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 Yo(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,l=new Map,s=[];return o.forEach(d=>{l.set(d.id,d),s.push(d.id)}),{...n,rows:{idRowsLookup:l,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(l=>{e.set(l.field,l),o.push(l.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 qo(n){const{rows:t,columns:e,rowHeight:o=52,headerHeight:l=56,columnVisibilityModel:s,initialState:d}=n,[a]=i.useState(()=>Ko(t,e,s)),[c,h]=i.useReducer(Yo,{...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:l}}),p=i.useRef(c);i.useLayoutEffect(()=>{p.current=c});const w=i.useRef(t);i.useEffect(()=>{t!==w.current&&(w.current=t,h({type:"SET_ROWS",payload:t}))},[t]);const b=i.useCallback((u,j)=>{h({type:"SET_ROWS",payload:u,preserveRowCount:j})},[]),f=i.useCallback(u=>{h({type:"SET_COLUMNS",payload:u})},[]),m=i.useCallback(u=>{h({type:"SET_SORT_MODEL",payload:u})},[]),x=i.useCallback(u=>{h({type:"SET_FILTER_MODEL",payload:u})},[]),C=i.useCallback(u=>{h({type:"SET_PAGINATION_MODEL",payload:u})},[]),E=i.useCallback(u=>{h({type:"SET_SELECTION",payload:u})},[]),_=i.useCallback((u,j)=>{h({type:"SET_DIMENSIONS",payload:{viewportWidth:u,viewportHeight:j}})},[]),S=i.useCallback(u=>{h({type:"SET_DATASOURCE_LOADING",payload:u})},[]),N=i.useCallback(u=>{h({type:"SET_DATASOURCE_ERROR",payload:u})},[]),g=i.useCallback(u=>{h({type:"SET_ROW_COUNT",payload:u})},[]),k=i.useRef({getRow:u=>p.current.rows.idRowsLookup.get(u)||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()),getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:u=>p.current.columns.lookup.get(u)||null,getAllColumns:()=>p.current.columns.all,getVisibleColumns:()=>p.current.columns.all,selectRow:(u,j=!0)=>{const P=new Set(p.current.selection.selectedRows);j?P.add(u):P.delete(u),E(P)},selectRows:(u,j=!0)=>{const P=new Set(p.current.selection.selectedRows);u.forEach(L=>{j?P.add(L):P.delete(L)}),E(P)},getSelectedRows:()=>Array.from(p.current.selection.selectedRows),sortColumn:(u,j)=>{if(j===null)m(p.current.sorting.sortModel.filter(P=>P.field!==u));else{const P=p.current.sorting.sortModel.findIndex(L=>L.field===u);if(P>=0){const L=[...p.current.sorting.sortModel];L[P]={field:u,sort:j},m(L)}else m([...p.current.sorting.sortModel,{field:u,sort:j}])}},getSortModel:()=>p.current.sorting.sortModel,setFilterModel:x,getFilterModel:()=>p.current.filter.filterModel,setPage:u=>{C({...p.current.pagination.paginationModel,page:u})},setPageSize:u=>{C({...p.current.pagination.paginationModel,pageSize:u,page:0})},scrollToIndexes:()=>{},copySelectedRows:()=>Promise.resolve()});return{state:c,dispatch:h,apiRef:k,setRows:b,setColumns:f,setSortModel:m,setFilterModel:x,setPaginationModel:C,setSelection:E,setDimensions:_,setDataSourceLoading:S,setDataSourceError:N,setRowCount:g}}function Xo(n){const{onRowOrderChange:t,rows:e,getRowId:o,rowReordering:l=!1}=n,[s,d]=i.useState(null),[a,c]=i.useState(null),h=i.useCallback(m=>o?o(m):m.id,[o]),p=i.useCallback(m=>x=>{l&&(d(m),x.dataTransfer.effectAllowed="move")},[l]),w=i.useCallback(m=>x=>{!l||!s||(x.preventDefault(),x.dataTransfer.dropEffect="move",a!==m&&c(m))},[l,s,a]),b=i.useCallback(()=>{d(null),c(null)},[]),f=i.useCallback(m=>x=>{if(x.preventDefault(),!s||!t){b();return}const C=e.findIndex(_=>h(_)===s),E=e.findIndex(_=>h(_)===m);C!==-1&&E!==-1&&C!==E&&t({row:e[C],oldIndex:C,targetIndex:E}),b()},[s,t,e,h,b]);return{draggedRowId:s,dragOverRowId:a,onDragStart:l?p:void 0,onDragOver:l?w:void 0,onDragEnd:l?b:void 0,onDrop:l?f:void 0}}function Jo(n){const{rows:t,getRowId:e,getTreeDataPath:o,treeData:l=!1,defaultGroupingExpansionDepth:s=0,filterModel:d,sortModel:a,onRowExpansionChange:c}=n,{treeNodes:h,rootIds:p,groupingRows:w}=i.useMemo(()=>{if(!l||!o)return{treeNodes:new Map,rootIds:[],groupingRows:[]};const g=new Map,k=[],u=[],j=new Map,P=L=>L.join("/");return t.forEach(L=>{const y=e(L),T=o(L),I=P(T);j.set(I,y),g.set(y,{id:y,parentId:null,depth:T.length-1,groupingKey:T[T.length-1],isExpanded:!1,children:[],serverChildrenCount:L.serverChildrenCount})}),t.forEach(L=>{const y=e(L),T=o(L);if(T.length===1){k.push(y);return}const I=$=>{if($.length<=1)return;const D=$.slice(0,-1),W=P(D);let z=j.get(W);if(z===void 0&&(z=`auto-group-${W}`,!g.has(z))){const Y=D[D.length-1];g.set(z,{id:z,parentId:null,depth:D.length-1,groupingKey:Y,isExpanded:!1,children:[],label:Y}),j.set(W,z);const K={id:z,name:Y,_isGroupRow:!0};u.push(K),D.length===1&&k.push(z),I(D)}return z},A=I(T);if(A!==void 0){const $=g.get(A),D=g.get(y);$&&D&&(D.parentId=A,$.children=$.children||[],$.children.includes(y)||$.children.push(y))}}),u.forEach(L=>{const y=L.id,T=g.get(y);if(!T)return;const A=y.replace("auto-group-","").split("/");if(A.length>1){const $=A.slice(0,-1),D=P($),W=j.get(D);if(W&&g.has(W)){T.parentId=W;const z=g.get(W);z&&(z.children=z.children||[],z.children.includes(y)||z.children.push(y))}}}),{treeNodes:g,rootIds:k,groupingRows:u}},[t,o,l,e]),b=i.useMemo(()=>{if(!l)return new Set;const g=new Set;return h.forEach(k=>{k.children&&k.children.length>0&&(s===-1||k.depth<s)&&g.add(k.id)}),g},[h,l,s]),[f,m]=i.useState(new Set);i.useEffect(()=>{b.size>0&&m(b)},[b]);const x=i.useCallback(g=>{m(k=>{const u=new Set(k),j=!u.has(g);if(u.has(g)?u.delete(g):u.add(g),j&&c){const P=h.get(g);P&&c(P)}return u})},[h,c]),C=i.useCallback(()=>{if(!l)return null;const g=new Map;t.forEach(I=>g.set(e(I),I)),w.forEach(I=>g.set(I.id,I));const k=I=>Qt(I,d),u=new Map,j=I=>{if(u.has(I))return u.get(I);const A=g.get(I);if(!A)return!1;if(k(A))return u.set(I,!0),!0;const D=h.get(I);return D&&D.children&&D.children.some(z=>j(z))?(u.set(I,!0),!0):(u.set(I,!1),!1)},P=(I,A)=>{if(!a||a.length===0)return 0;const $=g.get(I),D=g.get(A);if(!$||!D)return 0;for(const W of a){const z=$[W.field],Y=D[W.field],K=Zt(z,Y,W.sort);if(K!==0)return K}return 0},L=[],y=new Set,T=I=>{const A=I.filter($=>j($));A.sort(P),A.forEach($=>{if(y.has($))return;const D=g.get($),W=h.get($);if(D&&W){y.add($);const z={...D,_treeDepth:W.depth,_isExpanded:f.has($),_hasChildren:!!(W.children&&W.children.length>0||W.serverChildrenCount&&W.serverChildrenCount>0),_descendantCount:W.children?W.children.length:0};L.push(z),f.has($)&&W.children&&W.children.length>0&&T(W.children)}})};return T(p),L},[l,t,w,p,h,f,d,a,e]),E=i.useCallback(g=>f.has(g),[f]),_=i.useCallback(g=>h.get(g),[h]),S=i.useCallback(g=>{const k=[];let u=g;for(;u!==null;){const j=h.get(u);if(!j)break;k.unshift(j.groupingKey),u=j.parentId}return k},[h]),N=i.useMemo(()=>{const g=new Map,k=new Set(w.map(u=>u.id));return h.forEach((u,j)=>{g.set(j,{hasChildren:!!(u.children&&u.children.length>0||u.serverChildrenCount&&u.serverChildrenCount>0),treeDepth:u.depth,descendantCount:u.children?u.children.length:void 0,isGroupRow:k.has(j),isExpanded:f.has(j)})}),g},[h,w,f]);return i.useMemo(()=>({treeNodes:h,groupingRows:w,toggleExpansion:x,isGroupExpanded:E,getVisibleRows:C,getNode:_,getNodePath:S,rowMetaMap:N}),[h,w,x,E,C,_,S,N])}const Qo=n=>n?.depth===-1?"footer":"inline",Zo=[],er={};function tr(n){const{rows:t,getRowId:e,columns:o,rowGroupingModel:l=Zo,aggregationModel:s=er,defaultGroupingExpansionDepth:d=0,filterModel:a,sortModel:c,getAggregationPosition:h=Qo}=n,p=i.useMemo(()=>{const g=new Map;return(o??[]).forEach(k=>g.set(k.field,k)),g},[o]),[w,b]=i.useState(new Set),{treeNodes:f,rootIds:m,groupingRows:x}=i.useMemo(()=>{const g=new Map,k=new Map,u=[];if(l.length===0)return{treeNodes:g,rootIds:u,groupingRows:k};const j=(y,T,I)=>`auto-group-${y}-${T}-${I||"root"}`,P=(y,T,I)=>{if(T>=l.length)return y.map(z=>{const Y=e(z);return g.set(Y,{id:Y,parentId:I,depth:T,groupingKey:"",isExpanded:!1}),Y});const A=l[T],$=p.get(A);if($&&$.groupable===!1)return P(y,T+1,I);const D=new Map;y.forEach(z=>{const Y=z[A],K=String(Y);D.has(K)||D.set(K,[]),D.get(K).push(z)});const W=[];return D.forEach((z,Y)=>{const v=z[0][A],M=j(A,Y,I);W.push(M);const F={};s&&Object.entries(s).forEach(([oe,ie])=>{const ne=z.map(R=>R[oe]);if(ie==="sum")F[oe]=ne.reduce((R,le)=>R+(Number(le)||0),0);else if(ie==="min")F[oe]=Math.min(...ne.map(R=>Number(R)||0));else if(ie==="max")F[oe]=Math.max(...ne.map(R=>Number(R)||0));else if(ie==="avg"){const R=ne.reduce((le,te)=>le+(Number(te)||0),0);F[oe]=ne.length?R/ne.length:0}else ie==="count"&&(F[oe]=ne.length)});const O={[A]:v,...F,id:M};k.set(M,O);const H={id:M,parentId:I,depth:T,groupingKey:Y,groupingField:A,groupingValue:v,aggregatedValues:F,isExpanded:!1,children:[],label:$?.groupingValueFormatter?$.groupingValueFormatter({field:A,value:v}):`${A}: ${String(v)}`};H.aggregationPosition=h(H),g.set(M,H);const V=P(z,T+1,M);g.get(M).children=V;const U=z.length;g.get(M).descendantCount=U}),W},L=P(t,0,null);return u.push(...L),{treeNodes:g,rootIds:u,groupingRows:k}},[t,l,s,e,h,p]);i.useEffect(()=>{if(d===-1){const g=new Set;f.forEach((k,u)=>{k.children&&k.children.length>0&&g.add(u)}),b(g)}else if(d>0){const g=new Set;f.forEach((k,u)=>{k.depth<d&&k.children&&k.children.length>0&&g.add(u)}),b(g)}else b(new Set)},[l,d,f]);const C=i.useCallback(g=>{b(k=>{const u=new Set(k);return u.has(g)?u.delete(g):u.add(g),u})},[]),E=i.useCallback(g=>w.has(g),[w]),_=i.useCallback(()=>{if(l.length===0)return null;const g=[],k=new Set,u=new Map;t.forEach(y=>u.set(e(y),y));const j=y=>{const T=f.get(y);if(!T)return!1;if(!T.children||T.children.length===0){const I=u.get(y);return!(!I||a&&!Qt(I,a))}return T.children.some(I=>j(I))},P=y=>{let T=y;a&&(T=y.filter(j)),c&&c.length>0&&T.sort((I,A)=>{const $=x.get(I)||u.get(I),D=x.get(A)||u.get(A);if(!$||!D)return 0;for(const W of c){const z=$[W.field],Y=D[W.field],K=Zt(z,Y,W.sort);if(K!==0)return K}return 0}),T.forEach(I=>{if(k.has(I))return;const A=f.get(I),$=A?.children&&A.children.length>0,D=$?x.get(I):u.get(I);if(D&&A){k.add(I);const W={...D,_treeDepth:A.depth,_isExpanded:w.has(I),_hasChildren:$,_groupingField:A.groupingField,_groupingValue:A.groupingValue,_descendantCount:A.descendantCount};g.push(W),L.has(I)&&$&&P(A.children)}})},L=w;return P(m),g},[t,e,f,m,x,a,c,w,l]),S=i.useCallback(g=>f.get(g),[f]),N=i.useMemo(()=>{const g=new Map;return f.forEach((k,u)=>{const j=!!(k.children&&k.children.length>0);g.set(u,{hasChildren:j,treeDepth:k.depth,groupingField:k.groupingField,groupingValue:k.groupingValue,groupLabel:k.label,descendantCount:k.descendantCount,isGroupRow:j,isExpanded:j?w.has(u):void 0})}),g},[f,w]);return i.useMemo(()=>({treeNodes:f,groupingRows:x,toggleExpansion:C,isGroupExpanded:E,getVisibleRows:_,getNode:S,rowMetaMap:N}),[f,x,C,E,_,S,N])}function nr(n){const{rows:t,getRowId:e,processRowUpdate:o,onProcessRowUpdateError:l,onRowChange:s}=n,[d,a]=i.useState(null),c=i.useRef(null),h=i.useCallback(f=>{a(f),c.current=typeof f=="function"?f(c.current):f},[]),p=i.useCallback(f=>{h({id:f.id,field:f.field,value:f.value,originalValue:f.value})},[h]),w=i.useCallback(async f=>{const m=c.current;if(!m)return;if(f?.cancel){h(null);return}const{id:x,field:C,value:E,originalValue:_}=m;if(E===_){h(null);return}const S=t.find(g=>e(g)===x);if(!S){h(null);return}const N={...S,[C]:E};try{if(o){const g=await o(N,S);s?.(g)}else s?.(N);h(null)}catch(g){l?.(g)}},[h,t,e,o,s,l]),b=i.useCallback(f=>{d&&d.id===f.id&&d.field===f.field&&h(m=>m?{...m,value:f.value}:null)},[d,h]);return{editingCell:d,startCellEdit:p,stopCellEdit:w,setEditCellValue:b}}function or(n,t,e){const[o,l]=i.useState(new Map),[s,d]=i.useState({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}}),a=i.useCallback(()=>{l(new Map)},[]),c=i.useCallback((x,C)=>o.get(x)?.[C],[o]),h=i.useCallback((x,C,E,_,S)=>{const N=new Map(o);for(let g=_;g<S;g++){const k=t[g];if(!k)continue;let u=1;if(k.colSpan)if(typeof k.colSpan=="function"){const P={row:C,value:C[k.field],field:k.field,colDef:k,rowIndex:E,colIndex:g};u=k.colSpan(P)}else u=k.colSpan;if(u<=1){Qe(N,x,k.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:e[k.field]||100}});continue}let j=e[k.field]||100;for(let P=1;P<u;P++)if(g+P<S){const L=t[g+P];L&&(j+=e[L.field]||100,Qe(N,x,L.field,{spannedByColSpan:!0,leftVisibleCellIndex:g,rightVisibleCellIndex:Math.min(g+u-1,t.length-1)}))}Qe(N,x,k.field,{spannedByColSpan:!1,cellProps:{colSpan:u,width:j}}),g+=u-1}l(N)},[o,t,e]),p=i.useCallback((x,C)=>{const E={},_={},S={};t.forEach((N,g)=>{if(N.rowSpan)for(let k=x;k<C;k++){const u=n[k];if(!u||_[u.id]?.[N.field])continue;const j=N.valueGetter?N.valueGetter({row:u,field:N.field,value:u[N.field]}):u[N.field];let P=1;if(typeof N.rowSpan=="function"){const L={row:u,value:j,field:N.field,colDef:N,rowIndex:k,colIndex:g};P=N.rowSpan(L)}else typeof N.rowSpan=="number"&&(P=N.rowSpan);if(P>1){E[u.id]||(E[u.id]={}),E[u.id][N.field]=P;for(let L=1;L<P;L++){const y=k+L;if(y<C&&n[y]){const T=n[y];_[T.id]||(_[T.id]={}),_[T.id][N.field]=!0,S[y]||(S[y]={}),S[y][N.field]=k}}}}}),d({caches:{spannedCells:E,hiddenCells:_,hiddenCellOriginMap:S},processedRange:{firstRowIndex:x,lastRowIndex:C}})},[n,t]),w=i.useCallback(()=>{d({caches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},processedRange:{firstRowIndex:0,lastRowIndex:0}})},[]);i.useEffect(()=>{const x=new Map;n.forEach((S,N)=>{for(let g=0;g<t.length;g++){const k=t[g];if(!k)continue;let u=1;if(k.colSpan)if(typeof k.colSpan=="function"){const P={row:S,value:S[k.field],field:k.field,colDef:k,rowIndex:N,colIndex:g};u=k.colSpan(P)}else u=k.colSpan;if(u<=1){const P=e[k.field]||(typeof k.width=="number"?k.width:100);Qe(x,S.id,k.field,{spannedByColSpan:!1,cellProps:{colSpan:1,width:P}});continue}let j=e[k.field]||(typeof k.width=="number"?k.width:100);for(let P=1;P<u;P++)if(g+P<t.length){const L=t[g+P];if(L){const y=e[L.field]||(typeof L.width=="number"?L.width:100);j+=y,Qe(x,S.id,L.field,{spannedByColSpan:!0,leftVisibleCellIndex:g,rightVisibleCellIndex:Math.min(g+u-1,t.length-1)})}}Qe(x,S.id,k.field,{spannedByColSpan:!1,cellProps:{colSpan:u,width:j}}),g+=u-1}}),l(x);const C={},E={},_={};t.forEach((S,N)=>{if(S.rowSpan)for(let g=0;g<n.length;g++){const k=n[g];if(!k||E[k.id]?.[S.field])continue;const u=S.valueGetter?S.valueGetter({row:k,field:S.field,value:k[S.field]}):k[S.field];let j=1;if(typeof S.rowSpan=="function"){const P={row:k,value:u,field:S.field,colDef:S,rowIndex:g,colIndex:N};j=S.rowSpan(P)}else typeof S.rowSpan=="number"&&(j=S.rowSpan);if(j>1){C[k.id]||(C[k.id]={}),C[k.id][S.field]=j;for(let P=1;P<j;P++){const L=g+P;if(L<n.length&&n[L]){const y=n[L];E[y.id]||(E[y.id]={}),E[y.id][S.field]=!0,_[L]||(_[L]={}),_[L][S.field]=g}}}}}),d({caches:{spannedCells:C,hiddenCells:E,hiddenCellOriginMap:_},processedRange:{firstRowIndex:0,lastRowIndex:n.length}})},[n,t,e]);const b=i.useCallback(()=>s.caches.spannedCells,[s]),f=i.useCallback(()=>s.caches.hiddenCells,[s]),m=i.useCallback(()=>s.caches.hiddenCellOriginMap,[s]);return{colspanMap:o,resetColSpan:a,getCellColSpanInfo:c,calculateColSpan:h,rowSpanningState:s,calculateRowSpan:p,resetRowSpan:w,getSpannedCells:b,getHiddenCells:f,getHiddenCellOriginMap:m}}function Qe(n,t,e,o){let l=n.get(t);l||(l={},n.set(t,l)),l[e]=o}function rr(n){const{dataSource:t,sortModel:e,filterModel:o,paginationModel:l,paginationMode:s,sortingMode:d,filterMode:a,aggregationModel:c,setRows:h,setRowCount:p,setDataSourceLoading:w,setDataSourceError:b,onAggregationResults:f}=n,m=i.useRef(null),x=i.useRef(0),C=i.useCallback(async()=>{if(!t)return;const _=++x.current;w(!0),b(null);const S=l.page*l.pageSize,N=S+l.pageSize,g={startRow:S,endRow:N,sortModel:e,filterModel:o,groupKeys:[],aggregationModel:c};try{const k=await t.getRows(g);if(_!==x.current)return;let u=!1;if(s==="infinite"){const j=m.current;if(j){const P=JSON.stringify(j.sortModel)!==JSON.stringify(e),L=JSON.stringify(j.filterModel)!==JSON.stringify(o),y=j.pageSize!==l.pageSize;!P&&!L&&!y&&l.page>j.page&&(u=!0)}}h(u?j=>[...j,...k.rows]:k.rows,!0),k.aggregationResults&&f&&f(k.aggregationResults),k.rowCount!==void 0&&p(k.rowCount),m.current={sortModel:e,filterModel:o,page:l.page,pageSize:l.pageSize}}catch(k){_===x.current&&(b(k),console.error("Data Source Error:",k))}finally{_===x.current&&w(!1)}},[t,l.page,l.pageSize,e,o,s,c,f,h,p,w,b]);i.useEffect(()=>{if(t&&(s==="server"||s==="infinite"||d==="server"||a==="server")){const S=setTimeout(()=>{C()},300);return()=>clearTimeout(S)}},[C,t,s,d,a]);const E=i.useCallback(async(_,S)=>{if(t){w(!0);try{const N=await t.getRows({startRow:0,endRow:-1,sortModel:e,filterModel:o,groupKeys:S});N.rows.length>0&&h(g=>{const k=new Set(g.map(j=>j.id)),u=N.rows.filter(j=>!k.has(j.id));return[...g,...u]})}catch(N){b(N),console.error("Failed to fetch children:",N)}finally{w(!1)}}},[t,e,o,h,w,b]);return{fetchRows:C,fetchChildren:E}}const Pn="\0",wt="";function ir(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,l)=>o+l,0);case"avg":return e.reduce((o,l)=>o+l,0)/e.length;case"count":return e.length;case"min":return Math.min(...e);case"max":return Math.max(...e)}}function Lt(n,t){return t.map(e=>String(n[e]??"")).join(Pn)}function en(n,t,e,o){return o?`${n}${wt}${t}${wt}${e}`:`${t}${wt}${e}`}function In(n,t,e,o){return i.useMemo(()=>{const l={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1};if(!o)return l;const{rowFields:s,columnFields:d,valueFields:a}=e;if(s.length===0||a.length===0)return l;const c=d.length>0,h=new Map(t.map(_=>[_.field,_])),p=new Set;for(const _ of n)p.add(Lt(_,d));const w=Array.from(p).sort(),b=new Map;for(const _ of n){const S=Lt(_,s);if(!b.has(S)){const u={};for(const j of s)u[j]=_[j];b.set(S,{labelValues:u,bucket:new Map})}const N=b.get(S),g=Lt(_,d);N.bucket.has(g)||N.bucket.set(g,new Map);const k=N.bucket.get(g);for(const u of a){const j=_[u.field];k.has(u.field)||k.set(u.field,[]),j!=null&&!isNaN(Number(j))&&k.get(u.field).push(Number(j))}}let f=0;const m=[];for(const[,_]of b){const S={id:f++,..._.labelValues};for(const N of w){const g=_.bucket.get(N);for(const k of a){const u=en(N,k.field,k.aggFn,c),j=g?.get(k.field)??[];S[u]=j.length>0?ir(j,k.aggFn):null}}m.push(S)}const x=new Map;for(const _ of n){const S=Lt(_,d);for(const N of a){if(N.aggFn!=="avg"&&N.aggFn!=="min"&&N.aggFn!=="max")continue;const g=`${S}${wt}${N.field}`;x.has(g)||x.set(g,[]);const k=_[N.field];k!=null&&!isNaN(Number(k))&&x.get(g).push(Number(k))}}const C={id:"__pivot_grand_total__"};for(let _=0;_<s.length;_++)C[s[_]]=_===0?"Grand Total":"";for(const _ of w)for(const S of a){const N=en(_,S.field,S.aggFn,c),g=m.map(u=>u[N]).filter(u=>u!=null&&!isNaN(Number(u))).map(Number);if(g.length===0){C[N]=null;continue}const k=`${_}${wt}${S.field}`;switch(S.aggFn){case"sum":case"count":C[N]=g.reduce((u,j)=>u+j,0);break;case"avg":{const u=x.get(k)??[];C[N]=u.length>0?u.reduce((j,P)=>j+P,0)/u.length:null;break}case"min":C[N]=Math.min(...x.get(k)??g);break;case"max":C[N]=Math.max(...x.get(k)??g);break}}m.push(C);const E=[];for(const _ of s){const S=h.get(_);E.push({field:_,headerName:S?.headerName??_,width:S?.width??140,sortable:!0})}for(const _ of w){const S=c?_.split(Pn).map((N,g)=>{const k=h.get(d[g]);return k?.headerName?`${k.headerName}: ${N}`:N}).join(" / "):"";for(const N of a){const g=h.get(N.field),k=en(_,N.field,N.aggFn,c),u=N.headerName??g?.headerName??N.field,j=S?`${S} — ${u} (${N.aggFn})`:`${u} (${N.aggFn})`;E.push({field:k,headerName:j,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:P})=>{if(P==null)return"—";const L=Number(P);return N.aggFn==="avg"?L.toFixed(2):N.aggFn==="count"?L.toLocaleString():g?.valueFormatter?g.valueFormatter({value:P,row:{},field:N.field}):L.toLocaleString()}})}}return{pivotRows:m,pivotColumns:E,colKeys:w,isValid:!0}},[n,t,e,o])}function lr(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 sr(n){let t=!1;try{t=lr(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 ar(n){const{selectedRowIds:t,columns:e,getVisibleRows:o,getRowId:l}=n,s=i.useCallback(async()=>{if(t.size===0)return;const a=o().filter(b=>t.has(l(b)));if(a.length===0)return;const c=e.filter(b=>!b.field.startsWith("__")),h=c.map(b=>b.headerName||b.field).join(" "),p=a.map(b=>c.map(f=>{const m=b[f.field];return f.valueFormatter?f.valueFormatter({value:m,row:b,field:f.field}):m??""}).join(" ")).join(`
7
7
  `),w=`${h}
8
- ${p}`;try{await sr(w)}catch(b){console.error("[OpenGridX] Failed to copy to clipboard:",b)}},[t,e,o,l]);return i.useEffect(()=>{const d=a=>{if(!(a.ctrlKey||a.metaKey)||a.key!=="c")return;const c=document.activeElement,h=c?.tagName.toLowerCase(),p=c?.type;h==="input"&&p!=="checkbox"&&p!=="radio"||h==="textarea"||h==="select"||c?.isContentEditable||s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),{copySelectedRows:s}}function dr({row:n,rowIndex:t,listViewColumn:e,isSelected:o=!1,checkboxSelection:l=!1,rowHeight:s,onRowClick:d,onSelectionChange:a}){const c={row:n,value:void 0,field:e.field,colDef:{field:e.field},rowIndex:t,colIndex:0},h=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:[l&&r.jsx("div",{className:"ogx-list-view__checkbox",onClick:p=>p.stopPropagation(),children:r.jsx("input",{type:"checkbox",checked:o,onChange:h,"aria-label":`Select row ${n.id}`})}),r.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:e.renderCell(c)})]})}function cr({ariaLabel:n,allRenderableRows:t,filteredRows:e,pagination:o,effectivePaginationModel:l,pageSizeOptions:s,selectedRowIds:d,listViewColumn:a,noRowsLabel:c,rowHeight:h,checkboxSelection:p,paginationMode:w,dataSource:b,serverRowCount:f,paginationSlot:m,paginationSlotProps:x,localeText:C,onRowClick:E,onSelectionChange:_,onPaginationModelChange:S}){const N=m||En,g=w==="server"&&b?f||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 ${l.page+1} of ${Math.ceil(e.length/l.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"})]}),c]}):t.map((k,u)=>r.jsx(dr,{row:k,rowIndex:u,listViewColumn:a,isSelected:d.has(k.id),checkboxSelection:p,rowHeight:h,onRowClick:j=>E({row:j,id:j.id,rowIndex:u}),onSelectionChange:_},k.id))}),o&&r.jsx(N,{page:l.page,pageSize:l.pageSize,rowCount:g,pageSizeOptions:s,onPageChange:k=>S({...l,page:k}),onPageSizeChange:k=>S({...l,pageSize:k,page:0}),localeText:C,...x})]})}function ur({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[l,s]=i.useState(String(n??"")),d=i.useRef(null);return i.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"text",className:"ogx__edit-input",value:l,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 fr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[l,s]=i.useState(typeof n=="number"?n:""),d=i.useRef(null);return i.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"number",className:"ogx__edit-input ogx__edit-input--number",value:l,onChange:a=>{const c=a.target.value===""?"":Number(a.target.value);s(c),t(c===""?null:c)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function gr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const l=i.useRef(null);i.useEffect(()=>{l.current?.focus()},[]);const s=()=>{t(!n),setTimeout(e,0)};return r.jsx("div",{className:"ogx__edit-boolean",children:r.jsx("input",{ref:l,type:"checkbox",className:"ogx__edit-checkbox",checked:!!n,onChange:s,onKeyDown:d=>{d.key==="Escape"&&(d.stopPropagation(),o())}})})}function hr({value:n,colDef:t,onValueChange:e,onCommit:o,onCancel:l}){const s=i.useRef(null);i.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(),l())},children:d.map(a=>{const c=typeof a=="object"?a.value:a,h=typeof a=="object"?a.label:String(a);return r.jsx("option",{value:String(c),children:h},String(c))})})}function pr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[l,s]=i.useState(typeof n=="string"?n:String(n??"")),d=i.useRef(null);return i.useEffect(()=>{d.current?.focus()},[]),r.jsx("input",{ref:d,type:"date",className:"ogx__edit-input",value:l,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 xr(n){const{colDef:t}=n;switch(t.type){case"number":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(fr,{...n})});case"boolean":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(gr,{...n})});case"singleSelect":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(hr,{...n})});case"date":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(pr,{...n})});default:return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(ur,{...n})})}}function mr({renderFn:n}){return r.jsx(r.Fragment,{children:n()})}class br extends i.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(mr,{renderFn:this.props.renderFn})}}function wr(n){const{onCellClick:t,onCellEditStart:e,onCellValueChange:o,value:l,row:s,colDef:d,rowIndex:a,colIndex:c,isSelected:h,onClick:p,width:w,pinnedPosition:b,pinnedOffset:f,isFocused:m,isFocusVisible:x,isEditable:C,isEditing:E,onEditStart:_,onEditStop:S,onValueChange:N,colSpanInfo:g,rowSpan:k,isHiddenByRowSpan:u,rowMeta:j}=n,P=i.useCallback(v=>{o?o(d.field,v):N?.(v)},[o,N,d.field]),L=i.useMemo(()=>d.valueFormatter?d.valueFormatter({value:l,row:s,field:d.field}):l==null?"":String(l),[l,s,d]),y=i.useMemo(()=>d.cellClassName?typeof d.cellClassName=="function"?d.cellClassName({value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c})||"":d.cellClassName:"",[d,l,s,a,c]),T=i.useRef(null);if(i.useLayoutEffect(()=>{m&&T.current&&T.current.focus({preventScroll:!0})},[m]),g?.spannedByColSpan)return null;if(u)return r.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:{width:w??d.width??100},role:"presentation","data-field":d.field,"data-colindex":c});const I=v=>{t&&t({row:s,field:d.field,value:l,colDef:d,rowIndex:a,colIndex:c}),p?.(v)},A=v=>{C&&(_||e)&&(v.stopPropagation(),e?e(d.field,l):_?.())},$=b!=null,D=["ogx__cell",`ogx__cell--align-${d.align||"left"}`,h&&"ogx__cell--selected",m&&"ogx__cell--focused",m&&x&&"ogx__cell--focus-visible",d.type&&`ogx__cell--type-${d.type}`,$&&"ogx__cell--pinned",$&&`ogx__cell--pinned-${b}`,E&&"ogx__cell--editing",k&&k>1&&"ogx__cell--spanned",y].filter(Boolean).join(" "),W=g?.cellProps?.colSpan||1,z=k||1,Y=g?.cellProps?.width??w??d.width??100,U={width:"var(--width)","--width":typeof Y=="number"?`${Y}px`:Y,flexGrow:d.flex??0,flexShrink:0,flexBasis:(d.flex,"auto"),boxSizing:"border-box",minWidth:d.minWidth,maxWidth:d.maxWidth,position:$?"sticky":void 0,zIndex:d.zIndex??($?3:void 0),padding:E?0:void 0};return z>1&&(U.height=`calc(var(--height) * ${z} - var(--border-width, 1px))`,U.zIndex=10,$&&(U.zIndex=40)),$&&f!==void 0&&(b==="left"?U.left=f:U.right=f),r.jsx("div",{ref:T,className:D,style:U,onClick:I,onDoubleClick:A,role:"gridcell","aria-colindex":c+1,"aria-readonly":!C||void 0,tabIndex:-1,"data-field":d.field,"data-colindex":c,...W>1?{"aria-colspan":W}:{},...z>1?{"aria-rowspan":z}:{},children:r.jsx("div",{className:"ogx__cell-content",children:E&&(o||N)&&S?d.renderEditCell?d.renderEditCell({value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c,rowMeta:j}):r.jsx(xr,{value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c,onValueChange:P,onCommit:()=>S(),onCancel:()=>S(!0)}):d.renderCell?r.jsx(br,{field:d.field,resetKey:s,renderFn:()=>d.renderCell({value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c,rowMeta:j})}):L})})}const Pn=i.memo(wr),vr=({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 _r(n){const{content:t,height:e,isExpanded:o}=n;if(!o)return null;const l={height:e==="auto"?"auto":`${e}px`,overflow:e==="auto"?"visible":"auto"};return r.jsx("div",{className:"ogx__detail-panel",style:l,children:r.jsx("div",{className:"ogx__detail-panel-content",children:t})})}function Ft(n){const{row:t,columns:e,rowIndex:o,isSelected:l=!1,checkboxSelection:s=!1,onRowClick:d,onCellClick:a,onSelectionChange:c,columnWidths:h={},pinnedColumns:p,pinnedRows:w,hasDetailPanel:b=!1,isDetailPanelExpanded:f=!1,onDetailPanelToggle:m,detailPanelContent:x,detailPanelHeight:C=200,pinCheckboxColumn:E=!0,pinExpandColumn:_=!0,rowReordering:S=!1,onDragStart:N,onDragOver:g,onDragEnd:k,onDrop:u,isDragging:j,isDragOver:P,editingCell:L,onEditStart:y,onEditStop:T,onEditCellValueChange:I,focusedCellField:A,isFocusVisible:$,colspanMap:D,rowSpanningCaches:W,rowHeight:z=52,rowMeta:Y}=n,U=i.useId(),v=i.useRef(null),M=i.useRef(null);i.useLayoutEffect(()=>{A==="__expand_col__"&&v.current&&v.current.focus({preventScroll:!0}),A==="__checkbox_col__"&&M.current&&M.current.focus({preventScroll:!0})},[A]);const F=i.useMemo(()=>qt(e,h,p,s,E,b,_,S),[e,h,p,s,E,b,_,S]),O=Y?.hasChildren===!0,H=i.useCallback((q,J)=>{O||y?.({id:t.id,field:q,value:J})},[O,t.id,y]),K=i.useCallback((q,J)=>{I?.({id:t.id,field:q,value:J})},[I,t.id]),V=i.useCallback(q=>{T?.({cancel:q})},[T]);if(t._isSkeleton){const q=Math.max(e.length,5);return r.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:z,minHeight:z},children:Array.from({length:q}).map((J,de)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-bar"})},de))})}const oe=q=>{q.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell")||d?.({row:t,id:t.id,rowIndex:o})},ie=q=>{q.stopPropagation(),c?.(t.id,q.target.checked)},ne=q=>{q.stopPropagation(),m?.(t.id)},R=Xt(t.id,w),le=R==="top",te=R==="bottom",re=["ogx__row",l&&"ogx__row--selected",o%2===0&&"ogx__row--even",o%2===1&&"ogx__row--odd",le&&"ogx__row--pinned-top",te&&"ogx__row--pinned-bottom",j&&"ogx__row--dragging",P&&"ogx__row--drag-over",O&&"ogx__row--group"].filter(Boolean).join(" ");return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:re,onClick:oe,role:"row","aria-rowindex":o+1,"aria-selected":l,"data-rowindex":o,onDragOver:g?g(t.id):void 0,onDrop:u?u(t.id):void 0,style:{maxHeight:`${z}px`,minHeight:`${z}px`,"--height":`${z}px`,"--border-width":"1px"},children:[S&&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:N?N(t.id):void 0,onDragEnd:k,onClick:q=>q.stopPropagation(),children:r.jsx(vr,{})}),b&&r.jsx("div",{className:`ogx__cell ogx__cell--expand ${_?"ogx__cell--pinned-left":""} ${A==="__expand_col__"?"ogx__cell--focused":""} ${A==="__expand_col__"&&$?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":f?"Collapse row details":"Expand row details","aria-expanded":f,style:{position:_?"sticky":void 0,left:_?S?48:0:void 0,zIndex:_?5:void 0},ref:v,tabIndex:-1,onClick:q=>{q.stopPropagation(),a?.({row:t,field:"__expand_col__",value:f,colDef:{field:"__expand_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(yn,{isExpanded:f,onClick:ne,variant:"plus-minus"})}),s&&r.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${E?"ogx__cell--pinned-left":""} ${A==="__checkbox_col__"?"ogx__cell--focused":""} ${A==="__checkbox_col__"&&$?"ogx__cell--focus-visible":""}`,role:"gridcell",style:{position:E?"sticky":void 0,left:E?(S?48:0)+(b&&_?48:0):void 0,zIndex:E?11:void 0},ref:M,tabIndex:-1,onClick:q=>{q.stopPropagation(),a?.({row:t,field:"__checkbox_col__",value:l,colDef:{field:"__checkbox_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(xt,{id:U,name:`ogx-select-row-${t.id}`,checked:l,onChange:ie,onClick:q=>q.stopPropagation(),"aria-label":l?`Deselect row ${t.id}`:`Select row ${t.id}`,tabIndex:-1,onMouseDown:q=>q.preventDefault()})}),e.map((q,J)=>{if(q.isSpacer)return r.jsx("div",{style:{width:q.width,minWidth:q.width,flexShrink:0},"aria-hidden":"true"},q.field);const de=q.valueGetter?q.valueGetter({row:t,field:q.field,value:t[q.field]}):t[q.field],B=h[q.field]??q.width,Q=pt(q.field,p),Z=Q?F[q.field]:void 0,ge=L?.id===t.id&&L?.field===q.field,ue=ge?L?.value:de,Ee=D?.get(t.id)?.[q.field],Te=W?.spannedCells[t.id]?.[q.field],Pe=W?.hiddenCells[t.id]?.[q.field]||!1;return r.jsx(Pn,{value:ue,row:t,colDef:q,rowIndex:o,colIndex:J,isSelected:l,onCellClick:a,width:B,pinnedPosition:Q,pinnedOffset:Z,isFocused:A===q.field,isFocusVisible:$,isEditable:q.editable,isEditing:ge,onCellEditStart:H,onEditStop:V,onCellValueChange:K,colSpanInfo:Ee,rowSpan:Te,isHiddenByRowSpan:Pe,rowMeta:Y},q.field)})]}),b&&r.jsx(_r,{row:t,rowId:t.id,rowIndex:o,content:x,height:C,isExpanded:f})]})}function In({rows:n,position:t,columns:e,selectedRowIds:o,checkboxSelection:l,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:c,pinnedColumns:h,pinnedRows:p,hasDetailPanel:w,expandedRowIds:b,getDetailPanelContent:f,getDetailPanelHeight:m,onDetailPanelToggle:x,pinCheckboxColumn:C,pinExpandColumn:E,focusedCell:_,colspanMap:S,rowSpanningCaches:N,rowHeight:g,rowMetaMap:k}){return n.length===0?null:r.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:n.map((u,j)=>r.jsx(Ft,{row:u,columns:e,rowIndex:j,isSelected:o.has(u.id),checkboxSelection:l,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:c,pinnedColumns:h,pinnedRows:p,hasDetailPanel:w,isDetailPanelExpanded:b.has(u.id),detailPanelContent:f?f({row:u,id:u.id,rowIndex:j}):null,detailPanelHeight:m?.({row:u,id:u.id,rowIndex:j})||200,onDetailPanelToggle:x,pinCheckboxColumn:C,pinExpandColumn:E,focusedCellField:_?.id===u.id?_.field:null,colspanMap:S,rowSpanningCaches:N,rowHeight:g,rowMeta:k.get(u.id)},u.id))})}const Cr=({columns:n,rowHeight:t,checkboxSelection:e=!1,hasDetailPanel:o=!1,rowReordering:l=!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}})}),l&&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,c=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:c,height:16,borderRadius:4}})},s.field||d)})]});function yr({virtualContainerHeight:n,offsetTop:t,effectiveLoading:e,visibleRows:o,baseColumns:l,virtualColumns:s,viewportWidth:d,checkboxSelection:a,hasDetailPanel:c,rowReordering:h,rowHeight:p,pinnedRows:w,selectedRowIds:b,onRowClick:f,onCellClick:m,onSelectionChange:x,columnWidths:C,pinnedColumns:E,expandedRowIds:_,getDetailPanelContent:S,getDetailPanelHeight:N,onDetailPanelToggle:g,pinCheckboxColumn:k,pinExpandColumn:u,rowReorderHandlers:j,editingHandlers:P,focusedCell:L,colspanMap:y,rowSpanningCaches:T,paginationMode:I,dataSourceLoading:A,sortedUnpinnedRowCount:$,infiniteScrollSkeletonCount:D,unpinnedRowsLength:W,rowMetaMap:z}){const Y=l.length>0?l:(()=>{const v=(d||1e3)-(a?48:0)-(c?48:0)-(h?48:0),M=150,F=Math.max(1,Math.ceil(v/M));return Array.from({length:F},(O,H)=>({field:`placeholder_${H}`,headerName:"",width:M}))})(),U=o.filter(({row:v})=>!Xt(v.id,w)).filter((v,M,F)=>M===F.findIndex(O=>O.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,M)=>r.jsx(Cr,{columns:Y,rowHeight:p,checkboxSelection:a,hasDetailPanel:c,rowReordering:h},`skeleton-${M}`)):U.map(({row:v,rowIndex:M})=>r.jsx(Ft,{row:v,columns:s,rowIndex:M,isSelected:b.has(v.id),checkboxSelection:a,onRowClick:f,onCellClick:m,onSelectionChange:x,columnWidths:C,pinnedColumns:E,pinnedRows:w,hasDetailPanel:c,isDetailPanelExpanded:_.has(v.id),detailPanelContent:S?S({row:v,id:v.id,rowIndex:M}):null,detailPanelHeight:N?.({row:v,id:v.id,rowIndex:M})||200,onDetailPanelToggle:g,pinCheckboxColumn:k,pinExpandColumn:u,rowReordering:h,onDragStart:j.onDragStart,onDragOver:j.onDragOver,onDragEnd:j.onDragEnd,onDrop:j.onDrop,isDragging:j.draggedRowId===v.id,isDragOver:j.dragOverRowId===v.id,editingCell:P.editingCell,onEditStart:P.startCellEdit,onEditStop:P.stopCellEdit,onEditCellValueChange:P.setEditCellValue,focusedCellField:L!=null&&L.id===v.id?L.field:null,colspanMap:y,rowSpanningCaches:T,rowHeight:p,rowMeta:z.get(v.id)},v.id)),I==="infinite"&&A&&$>0&&r.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:D}).map((v,M)=>r.jsx(Ft,{row:{id:`__skeleton_${M}__`,_isSkeleton:!0},columns:s,rowIndex:W+M,rowHeight:p},`__skeleton_${M}__`))})]})})}function kr(){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 Sr(){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 Tn(n){const{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:l,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,showNonHideableColumns:c}=n,[h,p]=i.useState(""),[w,b]=i.useState(null),f=i.useRef(null),m=i.useMemo(()=>t.filter(u=>u.hideable!==!1),[t]),x=m.every(u=>e.has(u.field)),C=i.useMemo(()=>{const u=c?t:m;if(!h)return u;const j=h.toLowerCase();return u.filter(P=>(P.headerName||P.field).toLowerCase().includes(j))},[t,m,h,c]),E=u=>{u.target.checked?l():s()},_=u=>j=>{f.current=u,j.dataTransfer.effectAllowed="move",j.dataTransfer.setDragImage(j.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},S=u=>j=>{j.preventDefault(),j.dataTransfer.dropEffect="move",u!==f.current&&b(u)},N=()=>{b(null)},g=u=>j=>{j.preventDefault();const P=f.current;b(null),f.current=null,P&&P!==u&&d&&d(P,u)},k=()=>{b(null),f.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(kr,{}),r.jsx("input",{autoComplete:"off",className:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:h,onChange:u=>p(u.target.value)})]})}),r.jsx("div",{className:"ogx-column-visibility-panel__list",children:C.map(u=>{const j=e.has(u.field),P=u.hideable!==!1,L=w===u.field,y=!!d&&!h;return r.jsxs("div",{className:["ogx-column-visibility-panel__item",!P&&"ogx-column-visibility-panel__item--disabled",L&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:y,onDragOver:y?S(u.field):void 0,onDragLeave:y?N:void 0,onDrop:y?g(u.field):void 0,onDragEnd:y?k:void 0,children:[y&&r.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:_(u.field),title:"Drag to reorder",children:r.jsx(Sr,{})}),r.jsxs("label",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:P?"pointer":"not-allowed"},children:[r.jsx(xt,{checked:j,onChange:T=>o(u.field,T.target.checked),disabled:!P}),r.jsx("span",{className:"ogx-column-visibility-panel__label",children:u.headerName||u.field})]})]},u.field)})}),r.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[r.jsxs("label",{className:"ogx-column-visibility-panel__item",children:[r.jsx(xt,{checked:x,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:()=>{l(),a?.()},children:"Reset"})]})]})}function jr({isOpen:n,containerRef:t,panelRef:e,effectiveColumns:o,columnVisibilityModel:l,effectiveColumnOrder:s,columnOrder:d,disableColumnReorder:a,onClose:c,onColumnVisibilityChange:h,onColumnOrderChange:p,setInternalColumnOrder:w}){const[b,f]=i.useState(16),[m,x]=i.useState(16),[C,E]=i.useState(()=>document.body);if(i.useLayoutEffect(()=>{if(!n||!t.current)return;const S=t.current.getBoundingClientRect();f(S.top+8),x(window.innerWidth-S.right+8),E(t.current.closest(".ogx-theme-provider")||document.body)},[n,t]),!n)return null;const _=a?void 0:(S,N)=>{const g=[...s],k=g.indexOf(S),u=g.indexOf(N);if(k===-1||u===-1)return;const j=[...g];j.splice(k,1),j.splice(u,0,S),d||w(j),p?.({oldIndex:k,targetIndex:u,column:o.find(P=>P.field===S)})};return Ge.createPortal(r.jsxs("div",{ref:e,style:{position:"fixed",top:b,right:m,zIndex:9999,display:"inline-block"},children:[r.jsx("button",{onClick:c,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(Tn,{columns:o,visibleColumns:new Set(o.filter(S=>l[S.field]!==!1).map(S=>S.field)),onVisibilityChange:(S,N)=>{h({...l,[S]:N})},onShowAll:()=>{const S={...l};o.forEach(N=>{N.hideable!==!1&&(S[N.field]=!0)}),h(S)},onHideAll:()=>{const S={...l};o.forEach(N=>{N.hideable!==!1&&(S[N.field]=!1)}),h(S)},onColumnReorder:_})]}),C)}const Er=new Map;function Nr(n){const{rows:t,columns:e,getRowId:o,rowHeight:l=52,headerHeight:s=56,autoHeight:d=!1,density:a,checkboxSelection:c=!1,disableRowSelectionOnClick:h=!1,disableMultipleRowSelection:p=!1,rowSelectionModel:w,onRowSelectionModelChange:b,onRowClick:f,onCellClick:m,filterModel:x,onFilterModelChange:C,sortModel:E,onSortModelChange:_,pagination:S=!1,paginationModel:N,onPaginationModelChange:g,pageSizeOptions:k=[10,25,50,100],pinnedColumns:u,onPinnedColumnsChange:j,pinnedRows:P,getDetailPanelContent:L,getDetailPanelHeight:y,detailPanelExpandedRowIds:T,onDetailPanelExpandedRowIdsChange:I,pinCheckboxColumn:A=!0,pinExpandColumn:$=!0,disableColumnReorder:D=!1,columnOrder:W,onColumnOrderChange:z,height:Y,rowReordering:U=!1,onRowOrderChange:v,loading:M=!1,treeData:F=!1,getTreeDataPath:O,defaultGroupingExpansionDepth:H,groupingColDef:K,rowGroupingModel:V,aggregationModel:oe,onAggregationModelChange:ie,getAggregationPosition:ne,isCellEditable:R,processRowUpdate:le,onProcessRowUpdateError:te,dataSource:re,multiSort:q=!1,sortingMode:J="client",filterMode:de="client",paginationMode:B="client",rowCount:Q,slots:Z,slotProps:ge,pivotMode:ue=!1,pivotModel:Ee,onPivotModelChange:Te,className:Pe="",style:Re,onRowsScrollEnd:ze,ariaLabel:ee,initialState:ye,onStateChange:bi,columnVisibilityModel:wi,onColumnVisibilityModelChange:vi,listView:Ot=!1,listViewColumn:Hn,columnGroupingModel:Ve,noRowsLabel:_i="No Data",localeText:Le,apiRef:tn}=n,nn=Le?.noRowsLabel??_i,Ci=i.useMemo(()=>({items:[]}),[]),Ne=x||Ci,yi=i.useMemo(()=>[],[]),on=V||yi,Dn=i.useRef(Z?.toolbar);Dn.current=Z?.toolbar;const ki=i.useRef(G=>{const X=Dn.current;return X?X(G):null}).current,Si=po({initialState:ye,sortModel:E,aggregationModel:oe,onAggregationModelChange:ie,columnVisibilityModel:wi,onColumnVisibilityModelChange:vi,pinnedColumns:u,onPinnedColumnsChange:j,pivotModel:Ee,onPivotModelChange:Te,paginationModel:N,onPaginationModelChange:g,rowSelectionModel:w}),{sortModel:Ie,isSortControlled:Wt,setInternalSortModel:At,aggregationModel:Me,handleAggregationModelChange:Gn,columnVisibilityModel:Ue,handleColumnVisibilityModelChange:$t,pinnedColumns:vt,handlePinnedColumnsChange:rn,currentPivotModel:ln,handlePivotModelChange:Vn,effectivePaginationModel:ke,handlePaginationModelChange:sn,selectedRowIds:ve,isSelectionControlled:Ze,setInternalRowSelectionModel:et}=Si,tt=b,zt=Mn(t,e,ln,ue),Be=a==="compact"?32:a==="comfortable"?72:l,Un=ue&&zt.isValid?zt.pivotRows:t,Kn=ue&&zt.isValid?zt.pivotColumns:e,Yn=!!(V&&V.length>0),Ke=K&&Yn&&!ue?{...vt,left:["__group__",...(vt?.left??[]).filter(G=>G!=="__group__")]}:vt,_t=K&&Yn&&!ue?[{headerName:"Group",width:220,...K,field:"__group__",hideable:!1,sortable:!1,pinnable:!1,exportable:!1},...Kn]:Kn,[ji,qn]=i.useState(null);i.useEffect(()=>{qn(null)},[Me]);const nt=i.useRef(null),Ei=i.useRef(null),Bt=i.useRef(null),Ni=i.useCallback(G=>G.id,[]),ot=o||Ni,an=i.useMemo(()=>Un.map(G=>{const X=ot(G);return X===G.id?G:{...G,id:X}}),[Un,ot]),rt=i.useCallback(G=>{bn.current?.classList.toggle("ogx--kb",G)},[]),Xn=i.useRef(re);Xn.current=re;const Jn=i.useRef(null),Qn=i.useRef(null),Mi=i.useCallback(G=>{if(Xn.current&&F&&(G.serverChildrenCount??0)>0&&(G.children??[]).length===0){const X=Qn.current?.getNodePath(G.id)||[G.groupingKey];Jn.current?.(G.id,X)}},[F]),Ce=qo({rows:an,columns:_t,rowHeight:Be,headerHeight:s,rowCount:Q,columnVisibilityModel:Ue,initialState:n.initialState}),{state:pe,apiRef:it,setRows:dn,setColumns:Pi,setDimensions:Zn,setDataSourceLoading:Ii,setDataSourceError:Ti,setRowCount:Ri}=Ce,{scrollTop:Li,scrollLeft:Fi,handleScroll:Oi}=Eo({onRowsScrollEnd:ze});i.useEffect(()=>{tn&&(tn.current=it.current)},[tn,it]);const{copySelectedRows:eo}=ar({selectedRowIds:ve,columns:_t,getVisibleRows:()=>it.current.getVisibleRows(),getRowId:ot});i.useEffect(()=>{it.current.copySelectedRows=eo,it.current.getSelectedRows=()=>Array.from(ve)},[eo,ve,it]);const Wi=pe.dataSource.loading,Ct=M||Wi,lt=i.useMemo(()=>pe.rows.allRows.map(G=>pe.rows.idRowsLookup.get(G)),[pe.rows]),yt=Jo({rows:lt,getRowId:ot,getTreeDataPath:O,treeData:F,defaultGroupingExpansionDepth:H,filterModel:Ne,sortModel:Ie,onRowExpansionChange:Mi});i.useEffect(()=>{Qn.current=yt},[yt]);const kt=tr({rows:lt,getRowId:ot,columns:_t,rowGroupingModel:on,aggregationModel:Me,defaultGroupingExpansionDepth:H,filterModel:Ne,sortModel:Ie,getAggregationPosition:ne}),st=nr({rows:lt,getRowId:ot,processRowUpdate:le,onProcessRowUpdateError:te,onRowChange:G=>{const{dispatch:X}=Ce,ce=Array.from(Ce.state.rows.idRowsLookup.values()).map(fe=>fe.id===G.id?G:fe);X({type:"SET_ROWS",payload:ce})}}),St=F,He=!!(on&&on.length>0),cn=St||He,Ht=St?yt:He?kt:null,jt=i.useMemo(()=>St?yt.rowMetaMap:He?kt.rowMetaMap:Er,[St,yt.rowMetaMap,He,kt.rowMetaMap]),Fe=S&&!He,Dt=i.useCallback(G=>{const{row:X,id:se}=G;if(cn&&jt.get(X.id)?.hasChildren){Ht?.toggleExpansion(se);return}if(f?.(G),!h){let ce;if(p)ce=ve.has(se)?[]:[se];else{const fe=new Set(ve);fe.has(se)?fe.delete(se):fe.add(se),ce=Array.from(fe)}Ze||et(ce),tt?.(ce)}},[cn,Ht,f,jt,h,p,ve,Ze,et,tt]),un=rr({dataSource:re,sortModel:Ie,filterModel:Ne,paginationModel:ke,paginationMode:B,sortingMode:J,filterMode:de,aggregationModel:Me,setRows:dn,setRowCount:Ri,setDataSourceLoading:Ii,setDataSourceError:Ti,onAggregationResults:qn});i.useEffect(()=>{un.fetchChildren&&(Jn.current=un.fetchChildren)},[un.fetchChildren]),i.useEffect(()=>{re||dn(an)},[an,dn,re]);const Oe=!!L,[Ai,$i]=i.useState(new Set),at=T??Ai,Gt=i.useCallback(G=>{const X=new Set(at);X.has(G)?X.delete(G):X.add(G),T===void 0&&$i(X),I?.(X)},[at,T,I]),{effectiveColumns:De,orderedColumns:fn,visibleOrderedColumns:zi,navigationColumns:to,columnWidths:We,effectiveColumnOrder:Vt,setInternalColumnOrder:Ut,columnReorderHandlers:dt,handleColumnResize:Bi}=So({activeColumns:_t,isHierarchyEnabled:cn,isRowGrouping:He,isTreeData:St,activeHierarchyHandlers:Ht,columnVisibilityModel:Ue,columnOrder:W,onColumnOrderChange:z,disableColumnReorder:D,pivotMode:ue,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:U,initialState:ye,setColumns:Pi});No({onStateChange:bi,sortModel:Ie,filterModel:Ne,effectivePaginationModel:ke,columnWidths:We,effectiveColumnOrder:Vt,columnVisibilityModel:Ue,pinnedColumns:Ke});const ct=Co({effectiveRows:lt,activeHierarchyHandlers:Ht,filterMode:de,filterModel:Ne,dataSource:re,sortModel:Ie,sortingMode:J,pagination:Fe,paginationMode:B,effectivePaginationModel:ke,pinnedRows:P,isLoading:pe.dataSource.loading,pageSize:ke.pageSize}),Ye=ct.filteredRows,gn=ct.pinnedTopRows,hn=ct.pinnedBottomRows,Ae=ct.sortedUnpinnedRows,Et=ct.paginatedUnpinnedRows,pn=ct.allRenderableRows;i.useEffect(()=>{Ce.apiRef.current.getVisibleRows=()=>Fe?Et:Ae,Ce.apiRef.current.getAllFilteredRows=()=>Ae,Ce.apiRef.current.getVisibleColumns=()=>De},[Ae,Et,Fe,De,Ce.apiRef]);const Hi=Xo({rows:Fe?Et:Ae,getRowId:G=>G.id,onRowOrderChange:v,rowReordering:U}),ut=or(pn,to,We),{aggregationResult:Nt}=kn({rows:Ye,columns:_t,aggregationModel:Me,isServerSide:!!(re&&(B==="server"||J==="server")),dataSource:re,filterModel:Ne,sortModel:Ie,serverAggregationResults:ji}),ft=Object.keys(Me).length>0;i.useEffect(()=>{Ce.apiRef.current.getAggregationResult=()=>ft?Nt:null,Ce.apiRef.current.getAggregationModel=()=>ft?Me:null,Ce.apiRef.current.getGroupedExportRows=()=>{if(!He)return null;const{treeNodes:G,groupingRows:X}=kt,se=new Map;Ae.forEach(he=>se.set(he.id,he));const ce=[],fe=he=>{he.forEach(me=>{const be=G.get(me);if(!be)return;if(!!(be.children&&be.children.length>0))ce.push({type:"group-header",depth:be.depth,groupField:be.groupingField,groupValue:be.groupingValue}),fe(be.children),ft&&be.aggregatedValues&&ce.push({type:"group-subtotal",depth:be.depth,groupField:be.groupingField,groupValue:be.groupingValue,aggregatedValues:be.aggregatedValues});else{const Tt=se.get(me)??X.get(me);Tt&&ce.push({type:"leaf",depth:be.depth,row:Tt})}})};return fe(Array.from(G.keys()).filter(he=>G.get(he)?.parentId===null)),ft&&Nt&&ce.push({type:"grand-total",depth:0,aggregatedValues:Nt}),ce}},[Nt,Me,ft,Ce.apiRef,He,kt,Ae]);const xe=fo({rowHeight:Be,pagination:Fe,paginatedUnpinnedRows:Et,sortedUnpinnedRows:Ae,expandedRowIds:at,getDetailPanelHeight:y,pinnedTopRowsLength:gn.length,pinnedBottomRowsLength:hn.length,visibleOrderedColumns:zi,pinnedColumns:Ke,columnWidths:We,viewportWidth:pe.dimensions.viewportWidth||1e3,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:U,paginationMode:B,isLoading:pe.dataSource.loading,pageSize:ke.pageSize}),Di=i.useMemo(()=>{const G={};for(const X of[...xe.leftPinnedCols,...xe.unpinnedColsWithWidth,...xe.rightPinnedCols])X.isSpacer||(G[X.field]=X.width);return{...G,...We}},[xe.leftPinnedCols,xe.unpinnedColsWithWidth,xe.rightPinnedCols,We]);i.useEffect(()=>{Ce.apiRef.current.scrollToIndexes=({rowIndex:G,colIndex:X})=>{const se=nt.current;if(se){if(G!==void 0&&G>=0){const ce=G>0?xe.cumulativeHeights[G-1]:0,fe=xe.cumulativeHeights[G]??ce,{scrollTop:he,clientHeight:me}=se;ce<he?se.scrollTop=ce:fe>he+me&&(se.scrollTop=fe-me)}if(X!==void 0&&X>=0){const fe=[...xe.leftPinnedCols,...xe.unpinnedColsWithWidth,...xe.rightPinnedCols][X];if(!fe)return;const he=xe.unpinnedColsWithWidth.findIndex(Zi=>Zi.field===fe.field);if(he===-1)return;const me=he>0?xe.unpinnedAccWidths[he-1]:0,be=xe.unpinnedAccWidths[he]??me,It=xe.leftWidth+be,{scrollLeft:Tt,clientWidth:io}=se;me<Tt?se.scrollLeft=me:It>Tt+io&&(se.scrollLeft=It-io)}}}},[xe,nt,Ce.apiRef]);const Se=yo({layout:xe,scrollTop:Li,scrollLeft:Fi,viewportWidth:pe.dimensions.viewportWidth,viewportHeight:pe.dimensions.viewportHeight,autoHeight:d,rowReordering:U,hasDetailPanel:Oe,checkboxSelection:c,pinCheckboxColumn:A,pinExpandColumn:$});i.useEffect(()=>{if(!nt.current)return;const G=new ResizeObserver(X=>{for(const se of X){const{width:ce,height:fe}=se.contentRect;Zn(ce,fe)}});return G.observe(nt.current),()=>{G.disconnect()}},[Zn]);const Mt=i.useCallback((G,X)=>{const se=new Set(ve);X?se.add(G):se.delete(G);const ce=Array.from(se);Ze||et(ce),tt?.(ce)},[ve,Ze,tt,et]),Gi=i.useCallback(G=>{let X=[];G&&(X=lt.map(se=>se.id)),Ze||et(X),tt?.(X)},[lt,Ze,tt,et]),no=i.useCallback((G,X)=>{const se=X?[{field:G,sort:X}]:[];Wt||At(se),_?.(se)},[Wt,_,At]),Vi=i.useCallback((G,X)=>{const se=Ie.filter(fe=>fe.field!==G),ce=X?[...se,{field:G,sort:X}]:se;Wt||At(ce),_?.(ce)},[Ie,Wt,_,At]),{focusedCell:Kt,setFocusedCell:xn,handleFocus:Ui,handleBlur:Ki,handleKeyDown:Yi}=go({allRenderableRows:pn,navigationColumns:to,checkboxSelection:c,selectedRowIds:ve,handleSelectionChange:Mt,handleDetailPanelToggle:Gt,editingHandlers:st,setKeyboardMode:rt,sortModel:Ie,handleSort:no,isCellEditable:R,pagination:Fe,pageSize:ke.pageSize,virtualization:Se,viewportRef:nt}),mn=i.useCallback(G=>{rt(!1),xn({id:G.row.id,field:G.field}),Bt.current?.focus({preventScroll:!0}),m?.(G)},[m,rt,xn]),oo=i.useRef(st.editingCell);i.useEffect(()=>{const G=!!oo.current,X=!!st.editingCell;G&&!X&&Bt.current?.focus({preventScroll:!0}),oo.current=st.editingCell},[st.editingCell]);const qi=jo({renderContext:Se.renderContext,pinnedTopRows:gn,pinnedBottomRows:hn,paginatedUnpinnedRows:Et,sortedUnpinnedRows:Ae,pagination:Fe}),Xi=t.length>0&&ve.size===t.length,Ji=ve.size>0&&ve.size<t.length,Qi=i.useMemo(()=>De.some(G=>!!G.rowSpan),[De]),[Pt,Yt]=i.useState(!1),bn=i.useRef(null),wn=i.useRef(null),ro=i.useMemo(()=>{if(!Z?.toolbar)return null;const G=D?void 0:(X,se)=>{const ce=[...Vt],fe=ce.indexOf(X),he=ce.indexOf(se);if(fe===-1||he===-1)return;const me=[...ce];me.splice(fe,1),me.splice(he,0,X),W||Ut(me);const be=De.find(It=>It.field===X);be&&z?.({oldIndex:fe,targetIndex:he,column:be})};return{apiRef:Ce.apiRef,columns:fn,baseColumns:e,aggregationModel:Me,onAggregationModelChange:Gn,...ue||Ee||Te?{pivotModel:ln,onPivotModelChange:Vn}:{},filterModel:Ne,onFilterModelChange:C,columnVisibilityModel:Ue,onColumnVisibilityModelChange:$t,onColumnReorder:G,onColumnOrderReset:D?void 0:()=>Ut(e.map(X=>X.field)),forceColumnsOpen:Pt,onColumnsPanelClose:()=>Yt(!1),...ge?.toolbar}},[Z?.toolbar,D,Vt,fn,De,W,z,Ut,Ce.apiRef,e,Me,Gn,ue,Ee,Te,ln,Vn,Ne,C,Ue,$t,Pt,ge?.toolbar]);return i.useEffect(()=>{if(!Pt||Z?.toolbar)return;function G(X){wn.current&&!wn.current.contains(X.target)&&Yt(!1)}return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[Pt,Z?.toolbar]),r.jsxs("div",{ref:bn,className:["ogx",Pe,d&&"ogx--auto-height",Qi&&"ogx--row-spanning",Ot&&"ogx--list-view"].filter(Boolean).join(" "),style:{...Re,height:Y??Re?.height,"--ogx-row-height":`${Be}px`,"--ogx-header-height":`${s}px`},"aria-busy":Ct,children:[ro&&r.jsx(ki,{...ro}),!Z?.toolbar&&r.jsx(jr,{isOpen:Pt,containerRef:bn,panelRef:wn,effectiveColumns:De,columnVisibilityModel:Ue,effectiveColumnOrder:Vt,columnOrder:W,disableColumnReorder:D,onClose:()=>Yt(!1),onColumnVisibilityChange:$t,onColumnOrderChange:z,setInternalColumnOrder:Ut}),Ot&&Hn&&r.jsx(cr,{ariaLabel:ee,allRenderableRows:pn,filteredRows:Ye,pagination:Fe,effectivePaginationModel:ke,pageSizeOptions:k,selectedRowIds:ve,listViewColumn:Hn,noRowsLabel:nn,rowHeight:Be,checkboxSelection:c,paginationMode:B,dataSource:re,serverRowCount:pe.pagination.rowCount||0,paginationSlot:Z?.pagination,paginationSlotProps:ge?.pagination,localeText:Le?{paginationRowsPerPage:Le.paginationRowsPerPage,paginationOf:Le.paginationOf,paginationPage:Le.paginationPage}:void 0,onRowClick:Dt,onSelectionChange:Mt,onPaginationModelChange:sn}),!Ot&&r.jsx("div",{ref:G=>{nt.current=G,Bt.current=G},className:"ogx__viewport",onScroll:Oi,role:"grid","aria-label":ee||"Data grid","aria-rowcount":Ye.length+1,"aria-colcount":e.length+(c?1:0)+(Oe?1:0)+(U?1:0),"aria-busy":Ct,tabIndex:0,onKeyDownCapture:()=>{rt(!0)},onMouseDownCapture:()=>{rt(!1)},onKeyDown:Yi,onFocus:Ui,onBlur:Ki,children:r.jsxs("div",{ref:Ei,className:"ogx__content",style:{width:Se.totalWidth},role:"presentation",children:[r.jsx(jn,{columns:Se.virtualColumns,allColumns:De,columnGroupingModel:Ve,checkboxSelection:c,allSelected:Xi,someSelected:Ji,onSelectAll:Gi,sortModel:Ie,onSort:no,onSortAdd:Vi,multiSort:q,onColumnResize:Bi,columnWidths:We,pinnedColumns:Ke,focusedCell:Kt,onHeaderClick:G=>{xn({id:"HEADER",field:G}),rt(!1),Bt.current?.focus({preventScroll:!0})},onDragStart:Ve?void 0:dt.onDragStart,onDragOver:Ve?void 0:dt.onDragOver,onDragEnd:Ve?void 0:dt.onDragEnd,onDrop:Ve?void 0:dt.onDrop,draggedColumn:Ve?void 0:dt.draggedColumn,dragOverColumn:Ve?void 0:dt.dragOverColumn,rowReordering:U,hasDetailPanel:Oe,pinCheckboxColumn:A,pinExpandColumn:$,aggregationModel:Me,onHideColumn:G=>{$t({...Ue,[G]:!1})},onManageColumns:()=>Yt(!0),onPinColumn:(G,X)=>{const se=[...vt?.left??[]],ce=[...vt?.right??[]],fe=se.filter(me=>me!==G),he=ce.filter(me=>me!==G);rn(X==="left"?{left:[...fe,G],right:he}:X==="right"?{left:fe,right:[...he,G]}:{left:fe,right:he})}}),!Ct&&!pe.dataSource.error&&Ye.length===0&&r.jsx(Io,{noRowsLabel:nn,width:Se.totalWidth}),r.jsx(In,{rows:gn,position:"top",columns:Se.virtualColumns,selectedRowIds:ve,checkboxSelection:c,onRowClick:Dt,onCellClick:mn,onSelectionChange:Mt,columnWidths:We,pinnedColumns:Ke,pinnedRows:P,hasDetailPanel:Oe,expandedRowIds:at,getDetailPanelContent:L,getDetailPanelHeight:y,onDetailPanelToggle:Gt,pinCheckboxColumn:A,pinExpandColumn:$,focusedCell:Kt,colspanMap:ut.colspanMap,rowSpanningCaches:ut.rowSpanningState.caches,rowHeight:Be,rowMetaMap:jt}),r.jsx(yr,{virtualContainerHeight:Se.totalHeight-Se.pinnedTopHeight-Se.pinnedBottomHeight,offsetTop:Se.offsetTop,effectiveLoading:Ct,visibleRows:qi,baseColumns:e,virtualColumns:Se.virtualColumns,viewportWidth:pe.dimensions.viewportWidth,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:U,rowHeight:Be,pinnedRows:P,selectedRowIds:ve,onRowClick:Dt,onCellClick:mn,onSelectionChange:Mt,columnWidths:We,pinnedColumns:Ke,expandedRowIds:at,getDetailPanelContent:L,getDetailPanelHeight:y,onDetailPanelToggle:Gt,pinCheckboxColumn:A,pinExpandColumn:$,rowReorderHandlers:Hi,editingHandlers:st,focusedCell:Kt,colspanMap:ut.colspanMap,rowSpanningCaches:ut.rowSpanningState.caches,paginationMode:B,dataSourceLoading:pe.dataSource.loading,sortedUnpinnedRowCount:Ae.length,infiniteScrollSkeletonCount:Math.min(ke.pageSize,20),unpinnedRowsLength:xe.unpinnedRowsLength,rowMetaMap:jt}),r.jsx(In,{rows:hn,position:"bottom",columns:Se.virtualColumns,selectedRowIds:ve,checkboxSelection:c,onRowClick:Dt,onCellClick:mn,onSelectionChange:Mt,columnWidths:We,pinnedColumns:Ke,pinnedRows:P,hasDetailPanel:Oe,expandedRowIds:at,getDetailPanelContent:L,getDetailPanelHeight:y,onDetailPanelToggle:Gt,pinCheckboxColumn:A,pinExpandColumn:$,focusedCell:Kt,colspanMap:ut.colspanMap,rowSpanningCaches:ut.rowSpanningState.caches,rowHeight:Be,rowMetaMap:jt}),ft&&!ue&&r.jsx(Po,{columns:fn,aggregationModel:Me,aggregationResult:Nt,columnWidths:Di,rowHeight:Be,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:U,pinnedColumns:Ke})]})}),!Ot&&Fe&&(()=>{const G=Z?.pagination||En;return r.jsx(G,{page:ke.page,pageSize:ke.pageSize,rowCount:pe.pagination.rowCount,pageSizeOptions:k,onPageChange:X=>sn({...ke,page:X}),onPageSizeChange:X=>sn({...ke,pageSize:X,page:0}),localeText:Le?{paginationRowsPerPage:Le.paginationRowsPerPage,paginationOf:Le.paginationOf,paginationPage:Le.paginationPage}:void 0,...ge?.pagination})})(),r.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[Ct?"Loading data...":"",pe.dataSource.error?`Error: ${pe.dataSource.error instanceof Error?pe.dataSource.error.message:"Unknown error"}`:"",!M&&!pe.dataSource.error&&(Ye.length===0?nn:Ne&&((Ne.quickFilterValues?.length||0)>0||(Ne.items?.length||0)>0)?`${Ye.length} ${Ye.length===1?"row":"rows"} found`:"")]}),r.jsx(To,{error:pe.dataSource.error})]})}function Mr({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((l,s)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-content"})},s))},o))})}const Rn=new Set(["isEmpty","isNotEmpty"]);function Pr(n,t){return n.find(e=>"field"in e&&e.field===t)}const Ir=({col:n,item:t,onChange:e})=>{const o=i.useId(),l=vo(n.type),s=!!t,d=t?.operator??l[0],[a,c]=i.useState(t?.value!=null?String(t.value):""),h=i.useRef(e),p=i.useRef(t),w=i.useRef(n.field),b=i.useRef(d);i.useLayoutEffect(()=>{h.current=e,p.current=t,w.current=n.field,b.current=d});const f=i.useRef(t?.value);i.useEffect(()=>{t?.value!==f.current&&(f.current=t?.value,c(t?.value!=null?String(t.value):""))},[t?.value]),i.useEffect(()=>{const S=setTimeout(()=>{const N=p.current,g=N?.value??"";a!==g&&h.current({id:N?.id??`${w.current}-${Date.now()}`,field:w.current,operator:b.current,value:a})},300);return()=>clearTimeout(S)},[a]);const m=S=>{const N=Rn.has(S),g={id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:S,value:N?void 0:t?.value??(n.type==="boolean"?"true":"")};e(g)},x=()=>{c(""),e(null)},C=Rn.has(String(d)),E=n.type==="boolean",_=!C;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:S=>m(S.target.value),"aria-label":`Filter operator for ${n.headerName||n.field}`,children:l.map(S=>r.jsx("option",{value:S,children:S},S))}),_&&E&&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:S=>{c(S.target.value),e({id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:d,value:S.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"})]}),_&&!E&&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:S=>c(S.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:x,"aria-label":`Clear filter for ${n.headerName||n.field}`,title:"Clear",children:"×"})]})]})},Ln=({filterModel:n,columns:t,onFilterModelChange:e})=>{const o=i.useMemo(()=>n.items??[],[n.items]),l=n.logicOperator??"and",s=i.useCallback((c,h)=>{const p=o.filter(b=>"field"in b&&b.field!==c),w=h?[...p,h]:p;e({...n,items:w})},[o,n,e]),d=i.useCallback(c=>{e({...n,logicOperator:c})},[n,e]),a=t.filter(c=>c.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${l==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("and"),"aria-pressed":l==="and",children:"ALL (AND)"}),r.jsx("button",{className:`ogx-filter__logic-pill${l==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("or"),"aria-pressed":l==="or",children:"ANY (OR)"})]}),a.length===0?r.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):a.map(c=>r.jsx(Ir,{col:c,item:Pr(o,c.field),onChange:h=>s(c.field,h)},c.field))]})},Tr=["sum","avg","count","min","max"];function Fn(){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 Rr({anchorRef:n,columns:t,model:e,onChange:o,onClose:l}){const s=i.useRef(null),[d,a]=i.useState({top:0,right:0}),[c,h]=i.useState(document.body);i.useLayoutEffect(()=>{h(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const p=i.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]);i.useEffect(()=>{a(p());const y=()=>a(p());return window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[p]),i.useEffect(()=>{function y(I){s.current&&!s.current.contains(I.target)&&n.current&&!n.current.contains(I.target)&&l()}function T(I){I.key==="Escape"&&l()}return document.addEventListener("mousedown",y),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",T)}},[n,l]);const w=new Set(e.rowFields),b=new Set(e.columnFields),f=new Set(e.valueFields.map(y=>y.field)),m=y=>w.has(y)||b.has(y)||f.has(y);function x(y){w.has(y)||o({...e,rowFields:[...e.rowFields,y]})}function C(y){b.has(y)||o({...e,columnFields:[...e.columnFields,y]})}function E(y,T="sum"){f.has(y)||o({...e,valueFields:[...e.valueFields,{field:y,aggFn:T}]})}function _(y){o({...e,rowFields:e.rowFields.filter(T=>T!==y)})}function S(y){o({...e,columnFields:e.columnFields.filter(T=>T!==y)})}function N(y){o({...e,valueFields:e.valueFields.filter(T=>T.field!==y)})}function g(y,T){o({...e,valueFields:e.valueFields.map(I=>I.field===y?{...I,aggFn:T}:I)})}function k(){o({rowFields:[],columnFields:[],valueFields:[]})}const u=new Set(t.filter(y=>y.type==="number"||y.aggregable).map(y=>y.field)),j=e.rowFields.length+e.columnFields.length+e.valueFields.length,P=y=>t.find(T=>T.field===y)?.headerName??y,L=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(Fn,{}),"Pivot Mode"]}),j>0&&r.jsx("button",{className:"ogx-pivot-panel__reset-btn",onClick:k,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(y=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[P(y),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>_(y),title:`Remove ${P(y)}`,children:"×"})]},y))})]}),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(y=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[P(y),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>S(y),title:`Remove ${P(y)}`,children:"×"})]},y))})]}),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(y=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[P(y.field),r.jsx("select",{className:"ogx-pivot-chip__fn-select",value:y.aggFn,onChange:T=>g(y.field,T.target.value),title:"Aggregation function",children:Tr.map(T=>r.jsx("option",{value:T,children:T.toUpperCase()},T))}),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>N(y.field),title:`Remove ${P(y.field)}`,children:"×"})]},y.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(y=>{const T=u.has(y.field);return m(y.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:y.headerName??y.field}),r.jsxs("div",{className:"ogx-pivot-field-actions",children:[r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>x(y.field),title:"Add to Row Fields",children:"Row"}),r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>C(y.field),title:"Add to Column Fields",children:"Col"}),T&&r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>E(y.field),title:"Add to Value Fields",children:"Val"})]})]},y.field)}),t.every(y=>m(y.field))&&r.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return Ge.createPortal(L,c)}function Lr(){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 Fr(){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 Or({value:n="",onChange:t,placeholder:e="Search...",debounceMs:o=250}){const[l,s]=i.useState(()=>n.length>0),[d,a]=i.useState(n),c=i.useRef(null),h=i.useRef(null),p=i.useRef(t);i.useLayoutEffect(()=>{p.current=t},[t]);const w=i.useRef(n),b=i.useRef(n),f=i.useRef(!1);i.useLayoutEffect(()=>{f.current&&document.activeElement!==c.current&&c.current?.focus()}),i.useEffect(()=>{n!==b.current&&(b.current=n,n!==w.current&&(a(n),w.current=n,n?s(!0):(f.current=!1,s(!1))))},[n]),i.useEffect(()=>{const _=setTimeout(()=>{d!==w.current&&(w.current=d,p.current(d))},o);return()=>clearTimeout(_)},[d,o]);const m=i.useCallback(()=>{s(!0),requestAnimationFrame(()=>c.current?.focus())},[]),x=i.useCallback(_=>{_.stopPropagation(),a(""),w.current="",p.current(""),c.current?.focus()},[]),C=i.useCallback(()=>{f.current=!0,s(!0)},[]),E=i.useCallback(()=>{f.current=!1,setTimeout(()=>{if(h.current&&document.activeElement&&h.current.contains(document.activeElement)){f.current=!0;return}d||s(!1)},150)},[d]);return i.useEffect(()=>{const _=S=>{h.current&&!h.current.contains(S.target)&&(d||s(!1))};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[d]),r.jsxs("div",{ref:h,className:`ogx-global-search${l?" ogx-global-search--expanded":""}`,onClick:l?void 0:m,children:[r.jsx("div",{className:"ogx-global-search__icon-wrapper",children:r.jsx(Lr,{})}),r.jsx("input",{ref:c,className:"ogx-global-search__input",value:d,onChange:_=>a(_.target.value),onFocus:C,onBlur:E,placeholder:e,"aria-label":"Global Search",autoComplete:"off"}),d&&r.jsx("button",{className:"ogx-global-search__clear",onClick:x,"aria-label":"Clear search",children:r.jsx(Fr,{})})]})}function wt({title:n,children:t,placement:e="top",enterDelay:o=200,leaveDelay:l=0}){const[s,d]=i.useState(!1),[a,c]=i.useState({top:0,left:0}),h=i.useRef(null),p=i.useRef(null),w=i.useCallback(()=>{if(!p.current)return;const x=p.current.getBoundingClientRect();let C=0,E=0;const _=window.pageXOffset||document.documentElement.scrollLeft,S=window.pageYOffset||document.documentElement.scrollTop;e==="top"?(C=x.top+S-8,E=x.left+_+x.width/2):e==="bottom"&&(C=x.bottom+S+8,E=x.left+_+x.width/2),c({top:C,left:E})},[e]);i.useLayoutEffect(()=>(s&&(w(),window.addEventListener("scroll",w,!0),window.addEventListener("resize",w)),()=>{window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w)}),[s,w]);const b=()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{d(!0)},o)},f=()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{d(!1)},l)},m=i.useCallback(x=>{p.current=x?x.firstElementChild??x:null},[]);return r.jsxs(r.Fragment,{children:[r.jsx("span",{ref:m,style:{display:"inline-block",lineHeight:0},onMouseEnter:b,onMouseLeave:f,children:t}),s&&n&&Ge.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 Wr=["none","sum","avg","count","min","max"];function On(){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 Ar(){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 Wn(){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 $r({anchorRef:n,aggregationModel:t,aggregableColumns:e,onFunctionChange:o,onClearAll:l,onClose:s,activeCount:d}){const a=i.useRef(null),[c,h]=i.useState({top:0,right:0}),[p,w]=i.useState(document.body);i.useLayoutEffect(()=>{w(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const b=i.useCallback(()=>{if(!n.current)return{top:0,right:0};const m=n.current.getBoundingClientRect();return{top:m.bottom+6,right:window.innerWidth-m.right}},[n]);i.useEffect(()=>{h(b());const m=()=>h(b());return window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[b]),i.useEffect(()=>{function m(x){a.current&&!a.current.contains(x.target)&&n.current&&!n.current.contains(x.target)&&s()}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[n,s]),i.useEffect(()=>{function m(x){x.key==="Escape"&&s()}return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[s]);const f=r.jsxs("div",{ref:a,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:c.top,right:c.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(On,{}),"Summaries"]}),d>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:l,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(m=>{const x=t[m.field]||"none";return r.jsxs("div",{className:"ogx-toolbar__agg-row",children:[r.jsx("span",{className:"ogx-toolbar__agg-label",title:m.field,children:m.headerName||m.field}),r.jsx("div",{className:"ogx-toolbar__agg-pills",children:Wr.map(C=>r.jsx("button",{className:`ogx-toolbar__pill${x===C?" ogx-toolbar__pill--active":""}`,onClick:()=>o(m.field,C),"aria-pressed":x===C,children:C},C))})]},m.field)})})]});return Ge.createPortal(f,p)}function zr({anchorRef:n,columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:l,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,onClose:c,showNonHideableColumns:h}){const p=i.useRef(null),[w,b]=i.useState({top:0,right:0}),[f,m]=i.useState(document.body);i.useLayoutEffect(()=>{m(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const x=i.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]);i.useEffect(()=>{b(x());const E=()=>b(x());return window.addEventListener("scroll",E,!0),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E)}},[x]),i.useEffect(()=>{function E(_){p.current&&!p.current.contains(_.target)&&n.current&&!n.current.contains(_.target)&&c()}return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[n,c]);const C=r.jsx("div",{ref:p,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:w.top,right:w.right,width:280,padding:0},children:r.jsx(Tn,{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:l,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,showNonHideableColumns:h})});return Ge.createPortal(C,f)}function Br({anchorRef:n,columns:t,filterModel:e,onFilterModelChange:o,onClose:l}){const s=i.useRef(null),[d,a]=i.useState({top:0,right:0}),c=i.useRef(l);i.useLayoutEffect(()=>{c.current=l},[l]);const[h,p]=i.useState(document.body);i.useLayoutEffect(()=>{p(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const w=i.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]);i.useEffect(()=>{a(w());const x=()=>a(w());return window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[w]),i.useEffect(()=>{function x(C){C.key==="Escape"&&c.current()}return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[]);const b=e.items?.length??0,f=()=>{o({...e,items:[],logicOperator:"and"})},m=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(Wn,{}),"Filters",b>0&&r.jsx("span",{className:"ogx-toolbar__panel-count",children:b})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[b>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:f,title:"Clear all filters",children:"Clear all"}),r.jsx("button",{className:"ogx-toolbar__close-btn",onClick:()=>c.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(Ln,{columns:t,filterModel:e,onFilterModelChange:o})})]});return Ge.createPortal(m,h)}const Hr={rowFields:[],columnFields:[],valueFields:[]};function Dr({columns:n=[],baseColumns:t,aggregationModel:e={},onAggregationModelChange:o,pivotModel:l,onPivotModelChange:s,filterModel:d,onFilterModelChange:a,columnVisibilityModel:c={},onColumnVisibilityModelChange:h,onColumnReorder:p,onColumnOrderReset:w,forceColumnsOpen:b,onColumnsPanelClose:f,children:m,rightContent:x,style:C,renderColumnsButton:E,renderFilterButton:_,renderAggregationButton:S,renderExportButton:N,renderQuickFilter:g,className:k,showNonHideableColumns:u}){const[j,P]=i.useState(!1),[L,y]=i.useState(!1),[T,I]=i.useState(!1),[A,$]=i.useState(!1);i.useEffect(()=>{b&&(I(!0),P(!1),y(!1),$(!1))},[b]);const D=i.useRef(null),W=i.useRef(null),z=i.useRef(null),Y=i.useRef(null),U=i.useRef(null),v=i.useRef(null),M=i.useRef(null),F=l??Hr,O=F.rowFields.length>0||F.columnFields.length>0||F.valueFields.length>0,H=n.filter(J=>J.aggregable!==!1&&(J.type==="number"||J.aggregable===!0)),K=Object.keys(e).filter(J=>e[J]&&e[J]!=="none").length,V=i.useCallback((J,de)=>{if(!o)return;const B={...e};de==="none"?delete B[J]:B[J]=de,o(B)},[e,o]),oe=i.useCallback(()=>{o?.({})},[o]),ie=i.useCallback(J=>{if(!a)return;const B={...d||{},quickFilterValues:J?[J]:[],items:d?.items||[]};a(B)},[d,a]),ne=d?.quickFilterValues?.[0]||"",R=d?.items?.length||0,le=new Set(n.filter(J=>c[J.field]!==!1).map(J=>J.field)),te=i.useCallback((J,de)=>{if(!h)return;const B={...c,[J]:de};h(B)},[c,h]),re=i.useCallback(()=>{if(!h)return;const J={...c};n.forEach(de=>{de.hideable!==!1&&(J[de.field]=!0)}),h(J)},[n,c,h]),q=i.useCallback(()=>{if(!h)return;const J={...c};n.forEach(de=>{de.hideable!==!1&&(J[de.field]=!1)}),h(J)},[n,c,h]);return r.jsxs("div",{className:["ogx-toolbar",k].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:C,children:[m&&r.jsx("div",{className:"ogx-toolbar__left",children:m}),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:ne,onChange:ie}):r.jsx(Or,{value:ne,onChange:ie,placeholder:"Search..."})}),h&&r.jsxs("div",{ref:U,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[E?E({onClick:()=>{I(J=>!J),P(!1),y(!1),$(!1)},isOpen:T,activeCount:n.length-le.size}):r.jsx(wt,{title:"Columns",children:r.jsx("button",{ref:z,className:`ogx-toolbar__icon-btn${T?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns",onClick:()=>{I(!T),P(!1),y(!1),$(!1)},children:r.jsx(Ar,{})})}),T&&r.jsx(zr,{anchorRef:E?U:z,columns:n,visibleColumns:le,onVisibilityChange:te,onShowAll:re,onHideAll:q,onColumnReorder:p,onColumnOrderReset:w,onClose:()=>{I(!1),f?.()},showNonHideableColumns:u})]}),a&&r.jsxs("div",{ref:v,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[_?_({onClick:()=>{$(J=>!J),P(!1),y(!1),I(!1)},isOpen:A,activeCount:R}):r.jsx(wt,{title:"Filters",children:r.jsxs("button",{ref:Y,className:`ogx-toolbar__icon-btn${A?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters",onClick:()=>{$(!A),P(!1),y(!1),I(!1)},children:[r.jsx(Wn,{}),R>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),A&&r.jsx(Br,{anchorRef:_?v:Y,columns:n,filterModel:d||{items:[]},onFilterModelChange:a,onClose:()=>$(!1)})]}),s&&r.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[r.jsx(wt,{title:"Pivot",children:r.jsxs("button",{ref:W,className:`ogx-toolbar__icon-btn${L?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-expanded":L,onClick:()=>{y(!L),P(!1),I(!1),$(!1)},children:[r.jsx(Fn,{}),O&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),L&&r.jsx(Rr,{anchorRef:W,columns:t??n,model:F,onChange:J=>{s?.(J)},onClose:()=>y(!1)})]}),r.jsxs("div",{ref:M,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[S?S({onClick:()=>{P(J=>!J),y(!1),I(!1),$(!1)},isOpen:j,activeCount:K}):r.jsx(wt,{title:"Summaries",children:r.jsxs("button",{ref:D,className:`ogx-toolbar__icon-btn${j?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-expanded":j,onClick:()=>{P(!j),y(!1),I(!1),$(!1)},children:[r.jsx(On,{}),K>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${K} active summaries`})]})}),j&&r.jsx($r,{anchorRef:S?M:D,aggregationModel:e,aggregableColumns:H,onFunctionChange:V,onClearAll:oe,onClose:()=>P(!1),activeCount:K})]}),N&&N(),x]})]})}function Gr(){return i.useRef(null)}const Vr=({fullWidth:n=!1,error:t=!1,startAdornment:e,endAdornment:o,className:l="",...s})=>{const d=["ogx-input-wrapper",n&&"ogx-input-wrapper--full-width",t&&"ogx-input-wrapper--error",s.disabled&&"ogx-input-wrapper--disabled",l].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 An(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 Ur(n){return n.filter(t=>!(t.exportable===!1||t.field==="__check__"||t.field==="__actions__"))}function $n(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 zn(n){return(typeof n.width=="number"?n.width:void 0)??(n.flex??1)*100}function Kr(n,t){const e=n.reduce((l,s)=>l+zn(s),0),o={};return n.forEach((l,s)=>{o[s]={cellWidth:zn(l)/e*t}}),o}function Yr(n,t){return!n.items||n.items.length===0?"":n.items.flatMap(e=>{if("items"in e)return[];const l=t.find(d=>d.field===e.field)?.headerName??e.field,s=e.value!==void 0&&e.value!==null?String(e.value):"";return[`${l} ${e.operator} "${s}"`]}).join(" • ")}async function qr(n,t,e={}){let o,l;try{const[v,M]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);o=v.default,l=M.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:c="landscape",selectedRows:h,aggregationResult:p,aggregationModel:w,filterModel:b,alternateRowColor:f=!0,headerBackgroundColor:m="#4f46e5",headerTextColor:x="#ffffff",fontSize:C=9,groupedRows:E}=e,_=new o({orientation:c,unit:"mm",format:"a4"}),S=_.internal.pageSize.getWidth(),N=_.internal.pageSize.getHeight(),g=14,k=S-g*2,u=Ur(t),j=h&&h.length>0?n.filter(v=>h.includes(v.id)):n;let P=g;if(d){let v=g,M=g+8;if(a)try{_.addImage(a,"PNG",v,g,10,10),v+=14}catch{}_.setFontSize(16),_.setFont("helvetica","bold"),_.setTextColor(30,41,59),_.text(d,v,M),M+=6,_.setFontSize(8),_.setFont("helvetica","normal"),_.setTextColor(100,116,139);const F=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),O=E?E.filter(H=>H.type==="leaf").length:j.length;if(_.text(`Exported: ${F} • ${O} row${O!==1?"s":""}`,v,M),M+=5,b){const H=Yr(b,t);H&&(_.text(`Filters: ${H}`,v,M),M+=5)}_.setDrawColor(226,232,240),_.setLineWidth(.3),_.line(g,M+2,S-g,M+2),P=M+6}const L=[u.map(v=>v.headerName??v.field)];let y,T;if(E&&E.length>0){y=[];const v=w||{};E.forEach(M=>{if(M.type==="group-header"){const O=`${" ".repeat(M.depth*2)}${M.groupField??""}: ${String(M.groupValue??"")}`;y.push(u.map((H,K)=>K===0?O:""))}else if(M.type==="leaf"&&M.row){const F=M.row,O=" ".repeat(M.depth*2);y.push(u.map((H,K)=>(K===0?O:"")+$n(F,H)))}else if(M.type==="group-subtotal"&&M.aggregatedValues){const F=" ".repeat(M.depth*2);y.push(u.map((O,H)=>{if(H===0)return`${F}Subtotal`;const K=M.aggregatedValues[O.field];if(K==null)return"";let V=K;return O.valueFormatter?V=O.valueFormatter({value:K,row:{},field:O.field}):v[O.field]&&(V=_e(K,v[O.field])),String(V)}))}else M.type==="grand-total"&&M.aggregatedValues&&(T=[u.map((O,H)=>{if(H===0)return"Grand Total";const K=M.aggregatedValues[O.field];if(K==null)return"";let V=K;return O.valueFormatter?V=O.valueFormatter({value:K,row:{},field:O.field}):v[O.field]&&(V=_e(K,v[O.field])),String(V)})])})}else y=j.map(v=>u.map(M=>$n(v,M))),p&&w&&(T=[u.map((M,F)=>{if(F===0)return u.some(V=>w[V.field])?"TOTAL":"";const O=p[M.field];if(O==null)return"";let H=O;return M.valueFormatter?H=M.valueFormatter({value:O,row:{},field:M.field}):w[M.field]&&(H=_e(O,w[M.field])),String(H)})]);const I=Kr(u,k),[A,$,D]=An(m),[W,z,Y]=An(x);l(_,{head:L,body:y,...T?{foot:T}:{},startY:P,styles:{fontSize:C,cellPadding:3,font:"helvetica",overflow:"linebreak"},headStyles:{fillColor:[A,$,D],textColor:[W,z,Y],fontStyle:"bold"},...f?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...T?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:I,showFoot:T?"lastPage":"never",showHead:"everyPage",margin:{top:g,left:g,right:g,bottom:g+6}});const U=_.getNumberOfPages();for(let v=1;v<=U;v++)_.setPage(v),_.setFontSize(8),_.setTextColor(150,150,150),_.text(`Page ${v} of ${U}`,S-g,N-8,{align:"right"});_.save(`${s}.pdf`)}function Xr(n,t,e={}){const{fileName:o="export.csv",includeHeaders:l=!0,delimiter:s=",",selectedRows:d,groupedRows:a}=e,c=t.filter(p=>!(p.exportable===!1||p.field==="__check__"||p.field==="__actions__"));let h="";if(a&&a.length>0)l&&(h+=c.map(p=>je(p.headerName||p.field)).join(s)+`
8
+ ${p}`;try{await sr(w)}catch(b){console.error("[OpenGridX] Failed to copy to clipboard:",b)}},[t,e,o,l]);return i.useEffect(()=>{const d=a=>{if(!(a.ctrlKey||a.metaKey)||a.key!=="c")return;const c=document.activeElement,h=c?.tagName.toLowerCase(),p=c?.type;h==="input"&&p!=="checkbox"&&p!=="radio"||h==="textarea"||h==="select"||c?.isContentEditable||s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s]),{copySelectedRows:s}}function dr({row:n,rowIndex:t,listViewColumn:e,isSelected:o=!1,checkboxSelection:l=!1,rowHeight:s,onRowClick:d,onSelectionChange:a}){const c={row:n,value:void 0,field:e.field,colDef:{field:e.field},rowIndex:t,colIndex:0},h=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:[l&&r.jsx("div",{className:"ogx-list-view__checkbox",onClick:p=>p.stopPropagation(),children:r.jsx("input",{type:"checkbox",checked:o,onChange:h,"aria-label":`Select row ${n.id}`})}),r.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:e.renderCell(c)})]})}function cr({ariaLabel:n,allRenderableRows:t,filteredRows:e,pagination:o,effectivePaginationModel:l,pageSizeOptions:s,selectedRowIds:d,listViewColumn:a,noRowsLabel:c,rowHeight:h,checkboxSelection:p,paginationMode:w,dataSource:b,serverRowCount:f,paginationSlot:m,paginationSlotProps:x,localeText:C,onRowClick:E,onSelectionChange:_,onPaginationModelChange:S}){const N=m||Mn,g=w==="server"&&b?f||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 ${l.page+1} of ${Math.ceil(e.length/l.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"})]}),c]}):t.map((k,u)=>r.jsx(dr,{row:k,rowIndex:u,listViewColumn:a,isSelected:d.has(k.id),checkboxSelection:p,rowHeight:h,onRowClick:j=>E({row:j,id:j.id,rowIndex:u}),onSelectionChange:_},k.id))}),o&&r.jsx(N,{page:l.page,pageSize:l.pageSize,rowCount:g,pageSizeOptions:s,onPageChange:k=>S({...l,page:k}),onPageSizeChange:k=>S({...l,pageSize:k,page:0}),localeText:C,...x})]})}function ur({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[l,s]=i.useState(String(n??"")),d=i.useRef(null);return i.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"text",className:"ogx__edit-input",value:l,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 fr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[l,s]=i.useState(typeof n=="number"?n:""),d=i.useRef(null);return i.useEffect(()=>{d.current?.focus(),d.current?.select()},[]),r.jsx("input",{ref:d,type:"number",className:"ogx__edit-input ogx__edit-input--number",value:l,onChange:a=>{const c=a.target.value===""?"":Number(a.target.value);s(c),t(c===""?null:c)},onBlur:e,onKeyDown:a=>{a.key==="Enter"&&(a.stopPropagation(),e()),a.key==="Escape"&&(a.stopPropagation(),o())}})}function gr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const l=i.useRef(null);i.useEffect(()=>{l.current?.focus()},[]);const s=()=>{t(!n),setTimeout(e,0)};return r.jsx("div",{className:"ogx__edit-boolean",children:r.jsx("input",{ref:l,type:"checkbox",className:"ogx__edit-checkbox",checked:!!n,onChange:s,onKeyDown:d=>{d.key==="Escape"&&(d.stopPropagation(),o())}})})}function hr({value:n,colDef:t,onValueChange:e,onCommit:o,onCancel:l}){const s=i.useRef(null);i.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(),l())},children:d.map(a=>{const c=typeof a=="object"?a.value:a,h=typeof a=="object"?a.label:String(a);return r.jsx("option",{value:String(c),children:h},String(c))})})}function pr({value:n,onValueChange:t,onCommit:e,onCancel:o}){const[l,s]=i.useState(typeof n=="string"?n:String(n??"")),d=i.useRef(null);return i.useEffect(()=>{d.current?.focus()},[]),r.jsx("input",{ref:d,type:"date",className:"ogx__edit-input",value:l,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 xr(n){const{colDef:t}=n;switch(t.type){case"number":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(fr,{...n})});case"boolean":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(gr,{...n})});case"singleSelect":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(hr,{...n})});case"date":return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(pr,{...n})});default:return r.jsx("div",{className:"ogx__edit-cell",children:r.jsx(ur,{...n})})}}function mr({renderFn:n}){return r.jsx(r.Fragment,{children:n()})}class br extends i.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(mr,{renderFn:this.props.renderFn})}}function wr(n){const{onCellClick:t,onCellEditStart:e,onCellValueChange:o,value:l,row:s,colDef:d,rowIndex:a,colIndex:c,isSelected:h,onClick:p,width:w,pinnedPosition:b,pinnedOffset:f,isFocused:m,isFocusVisible:x,isEditable:C,isEditing:E,onEditStart:_,onEditStop:S,onValueChange:N,colSpanInfo:g,rowSpan:k,isHiddenByRowSpan:u,rowMeta:j}=n,P=i.useCallback(v=>{o?o(d.field,v):N?.(v)},[o,N,d.field]),L=i.useMemo(()=>d.valueFormatter?d.valueFormatter({value:l,row:s,field:d.field}):l==null?"":String(l),[l,s,d]),y=i.useMemo(()=>d.cellClassName?typeof d.cellClassName=="function"?d.cellClassName({value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c})||"":d.cellClassName:"",[d,l,s,a,c]),T=i.useRef(null);if(i.useLayoutEffect(()=>{m&&T.current&&T.current.focus({preventScroll:!0})},[m]),g?.spannedByColSpan)return null;if(u)return r.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:{width:w??d.width??100},role:"presentation","data-field":d.field,"data-colindex":c});const I=v=>{t&&t({row:s,field:d.field,value:l,colDef:d,rowIndex:a,colIndex:c}),p?.(v)},A=v=>{C&&(_||e)&&(v.stopPropagation(),e?e(d.field,l):_?.())},$=b!=null,D=["ogx__cell",`ogx__cell--align-${d.align||"left"}`,h&&"ogx__cell--selected",m&&"ogx__cell--focused",m&&x&&"ogx__cell--focus-visible",d.type&&`ogx__cell--type-${d.type}`,$&&"ogx__cell--pinned",$&&`ogx__cell--pinned-${b}`,E&&"ogx__cell--editing",k&&k>1&&"ogx__cell--spanned",y].filter(Boolean).join(" "),W=g?.cellProps?.colSpan||1,z=k||1,Y=g?.cellProps?.width??w??d.width??100,K={width:"var(--width)","--width":typeof Y=="number"?`${Y}px`:Y,flexGrow:d.flex??0,flexShrink:0,flexBasis:(d.flex,"auto"),boxSizing:"border-box",minWidth:d.minWidth,maxWidth:d.maxWidth,position:$?"sticky":void 0,zIndex:d.zIndex??($?3:void 0),padding:E?0:void 0};return z>1&&(K.height=`calc(var(--height) * ${z} - var(--border-width, 1px))`,K.zIndex=10,$&&(K.zIndex=40)),$&&f!==void 0&&(b==="left"?K.left=f:K.right=f),r.jsx("div",{ref:T,className:D,style:K,onClick:I,onDoubleClick:A,role:"gridcell","aria-colindex":c+1,"aria-readonly":!C||void 0,tabIndex:-1,"data-field":d.field,"data-colindex":c,...W>1?{"aria-colspan":W}:{},...z>1?{"aria-rowspan":z}:{},children:r.jsx("div",{className:"ogx__cell-content",children:E&&(o||N)&&S?d.renderEditCell?d.renderEditCell({value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c,rowMeta:j}):r.jsx(xr,{value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c,onValueChange:P,onCommit:()=>S(),onCancel:()=>S(!0)}):d.renderCell?r.jsx(br,{field:d.field,resetKey:s,renderFn:()=>d.renderCell({value:l,row:s,field:d.field,colDef:d,rowIndex:a,colIndex:c,rowMeta:j})}):L})})}const Tn=i.memo(wr),vr=({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 _r(n){const{content:t,height:e,isExpanded:o}=n;if(!o)return null;const l={height:e==="auto"?"auto":`${e}px`,overflow:e==="auto"?"visible":"auto"};return r.jsx("div",{className:"ogx__detail-panel",style:l,children:r.jsx("div",{className:"ogx__detail-panel-content",children:t})})}function Ft(n){const{row:t,columns:e,rowIndex:o,isSelected:l=!1,checkboxSelection:s=!1,onRowClick:d,onCellClick:a,onSelectionChange:c,columnWidths:h={},pinnedColumns:p,pinnedRows:w,hasDetailPanel:b=!1,isDetailPanelExpanded:f=!1,onDetailPanelToggle:m,detailPanelContent:x,detailPanelHeight:C=200,pinCheckboxColumn:E=!0,pinExpandColumn:_=!0,rowReordering:S=!1,onDragStart:N,onDragOver:g,onDragEnd:k,onDrop:u,isDragging:j,isDragOver:P,editingCell:L,onEditStart:y,onEditStop:T,onEditCellValueChange:I,focusedCellField:A,isFocusVisible:$,colspanMap:D,rowSpanningCaches:W,rowHeight:z=52,rowMeta:Y}=n,K=i.useId(),v=i.useRef(null),M=i.useRef(null);i.useLayoutEffect(()=>{A==="__expand_col__"&&v.current&&v.current.focus({preventScroll:!0}),A==="__checkbox_col__"&&M.current&&M.current.focus({preventScroll:!0})},[A]);const F=i.useMemo(()=>Xt(e,h,p,s,E,b,_,S),[e,h,p,s,E,b,_,S]),O=Y?.hasChildren===!0,H=i.useCallback((q,J)=>{O||y?.({id:t.id,field:q,value:J})},[O,t.id,y]),V=i.useCallback((q,J)=>{I?.({id:t.id,field:q,value:J})},[I,t.id]),U=i.useCallback(q=>{T?.({cancel:q})},[T]);if(t._isSkeleton){const q=Math.max(e.length,5);return r.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:z,minHeight:z},children:Array.from({length:q}).map((J,de)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-bar"})},de))})}const oe=q=>{q.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell")||d?.({row:t,id:t.id,rowIndex:o})},ie=q=>{q.stopPropagation(),c?.(t.id,q.target.checked)},ne=q=>{q.stopPropagation(),m?.(t.id)},R=Jt(t.id,w),le=R==="top",te=R==="bottom",re=["ogx__row",l&&"ogx__row--selected",o%2===0&&"ogx__row--even",o%2===1&&"ogx__row--odd",le&&"ogx__row--pinned-top",te&&"ogx__row--pinned-bottom",j&&"ogx__row--dragging",P&&"ogx__row--drag-over",O&&"ogx__row--group"].filter(Boolean).join(" ");return r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:re,onClick:oe,role:"row","aria-rowindex":o+1,"aria-selected":l,"data-rowindex":o,onDragOver:g?g(t.id):void 0,onDrop:u?u(t.id):void 0,style:{maxHeight:`${z}px`,minHeight:`${z}px`,"--height":`${z}px`,"--border-width":"1px"},children:[S&&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:N?N(t.id):void 0,onDragEnd:k,onClick:q=>q.stopPropagation(),children:r.jsx(vr,{})}),b&&r.jsx("div",{className:`ogx__cell ogx__cell--expand ${_?"ogx__cell--pinned-left":""} ${A==="__expand_col__"?"ogx__cell--focused":""} ${A==="__expand_col__"&&$?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":f?"Collapse row details":"Expand row details","aria-expanded":f,style:{position:_?"sticky":void 0,left:_?S?48:0:void 0,zIndex:_?5:void 0},ref:v,tabIndex:-1,onClick:q=>{q.stopPropagation(),a?.({row:t,field:"__expand_col__",value:f,colDef:{field:"__expand_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(Sn,{isExpanded:f,onClick:ne,variant:"plus-minus"})}),s&&r.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${E?"ogx__cell--pinned-left":""} ${A==="__checkbox_col__"?"ogx__cell--focused":""} ${A==="__checkbox_col__"&&$?"ogx__cell--focus-visible":""}`,role:"gridcell",style:{position:E?"sticky":void 0,left:E?(S?48:0)+(b&&_?48:0):void 0,zIndex:E?11:void 0},ref:M,tabIndex:-1,onClick:q=>{q.stopPropagation(),a?.({row:t,field:"__checkbox_col__",value:l,colDef:{field:"__checkbox_col__",width:48},rowIndex:o,colIndex:-1})},children:r.jsx(mt,{id:K,name:`ogx-select-row-${t.id}`,checked:l,onChange:ie,onClick:q=>q.stopPropagation(),"aria-label":l?`Deselect row ${t.id}`:`Select row ${t.id}`,tabIndex:-1,onMouseDown:q=>q.preventDefault()})}),e.map((q,J)=>{if(q.isSpacer)return r.jsx("div",{style:{width:q.width,minWidth:q.width,flexShrink:0},"aria-hidden":"true"},q.field);const de=q.valueGetter?q.valueGetter({row:t,field:q.field,value:t[q.field]}):t[q.field],B=h[q.field]??q.width,Q=xt(q.field,p),Z=Q?F[q.field]:void 0,ge=L?.id===t.id&&L?.field===q.field,ce=ge?L?.value:de,Ee=D?.get(t.id)?.[q.field],Te=W?.spannedCells[t.id]?.[q.field],Pe=W?.hiddenCells[t.id]?.[q.field]||!1;return r.jsx(Tn,{value:ce,row:t,colDef:q,rowIndex:o,colIndex:J,isSelected:l,onCellClick:a,width:B,pinnedPosition:Q,pinnedOffset:Z,isFocused:A===q.field,isFocusVisible:$,isEditable:q.editable,isEditing:ge,onCellEditStart:H,onEditStop:U,onCellValueChange:V,colSpanInfo:Ee,rowSpan:Te,isHiddenByRowSpan:Pe,rowMeta:Y},q.field)})]}),b&&r.jsx(_r,{row:t,rowId:t.id,rowIndex:o,content:x,height:C,isExpanded:f})]})}function Rn({rows:n,position:t,columns:e,selectedRowIds:o,checkboxSelection:l,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:c,pinnedColumns:h,pinnedRows:p,hasDetailPanel:w,expandedRowIds:b,getDetailPanelContent:f,getDetailPanelHeight:m,onDetailPanelToggle:x,pinCheckboxColumn:C,pinExpandColumn:E,focusedCell:_,colspanMap:S,rowSpanningCaches:N,rowHeight:g,rowMetaMap:k}){return n.length===0?null:r.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:n.map((u,j)=>r.jsx(Ft,{row:u,columns:e,rowIndex:j,isSelected:o.has(u.id),checkboxSelection:l,onRowClick:s,onCellClick:d,onSelectionChange:a,columnWidths:c,pinnedColumns:h,pinnedRows:p,hasDetailPanel:w,isDetailPanelExpanded:b.has(u.id),detailPanelContent:f?f({row:u,id:u.id,rowIndex:j}):null,detailPanelHeight:m?.({row:u,id:u.id,rowIndex:j})||200,onDetailPanelToggle:x,pinCheckboxColumn:C,pinExpandColumn:E,focusedCellField:_?.id===u.id?_.field:null,colspanMap:S,rowSpanningCaches:N,rowHeight:g,rowMeta:k.get(u.id)},u.id))})}const Cr=({columns:n,rowHeight:t,checkboxSelection:e=!1,hasDetailPanel:o=!1,rowReordering:l=!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}})}),l&&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,c=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:c,height:16,borderRadius:4}})},s.field||d)})]});function yr({virtualContainerHeight:n,offsetTop:t,effectiveLoading:e,visibleRows:o,baseColumns:l,virtualColumns:s,viewportWidth:d,checkboxSelection:a,hasDetailPanel:c,rowReordering:h,rowHeight:p,pinnedRows:w,selectedRowIds:b,onRowClick:f,onCellClick:m,onSelectionChange:x,columnWidths:C,pinnedColumns:E,expandedRowIds:_,getDetailPanelContent:S,getDetailPanelHeight:N,onDetailPanelToggle:g,pinCheckboxColumn:k,pinExpandColumn:u,rowReorderHandlers:j,editingHandlers:P,focusedCell:L,colspanMap:y,rowSpanningCaches:T,paginationMode:I,dataSourceLoading:A,sortedUnpinnedRowCount:$,infiniteScrollSkeletonCount:D,unpinnedRowsLength:W,rowMetaMap:z}){const Y=l.length>0?l:(()=>{const v=(d||1e3)-(a?48:0)-(c?48:0)-(h?48:0),M=150,F=Math.max(1,Math.ceil(v/M));return Array.from({length:F},(O,H)=>({field:`placeholder_${H}`,headerName:"",width:M}))})(),K=o.filter(({row:v})=>!Jt(v.id,w)).filter((v,M,F)=>M===F.findIndex(O=>O.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,M)=>r.jsx(Cr,{columns:Y,rowHeight:p,checkboxSelection:a,hasDetailPanel:c,rowReordering:h},`skeleton-${M}`)):K.map(({row:v,rowIndex:M})=>r.jsx(Ft,{row:v,columns:s,rowIndex:M,isSelected:b.has(v.id),checkboxSelection:a,onRowClick:f,onCellClick:m,onSelectionChange:x,columnWidths:C,pinnedColumns:E,pinnedRows:w,hasDetailPanel:c,isDetailPanelExpanded:_.has(v.id),detailPanelContent:S?S({row:v,id:v.id,rowIndex:M}):null,detailPanelHeight:N?.({row:v,id:v.id,rowIndex:M})||200,onDetailPanelToggle:g,pinCheckboxColumn:k,pinExpandColumn:u,rowReordering:h,onDragStart:j.onDragStart,onDragOver:j.onDragOver,onDragEnd:j.onDragEnd,onDrop:j.onDrop,isDragging:j.draggedRowId===v.id,isDragOver:j.dragOverRowId===v.id,editingCell:P.editingCell,onEditStart:P.startCellEdit,onEditStop:P.stopCellEdit,onEditCellValueChange:P.setEditCellValue,focusedCellField:L!=null&&L.id===v.id?L.field:null,colspanMap:y,rowSpanningCaches:T,rowHeight:p,rowMeta:z.get(v.id)},v.id)),I==="infinite"&&A&&$>0&&r.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:D}).map((v,M)=>r.jsx(Ft,{row:{id:`__skeleton_${M}__`,_isSkeleton:!0},columns:s,rowIndex:W+M,rowHeight:p},`__skeleton_${M}__`))})]})})}function kr(){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 Sr(){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 Ln(n){const{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:l,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,showNonHideableColumns:c}=n,[h,p]=i.useState(""),[w,b]=i.useState(null),f=i.useRef(null),m=i.useMemo(()=>t.filter(u=>u.hideable!==!1),[t]),x=m.every(u=>e.has(u.field)),C=i.useMemo(()=>{const u=c?t:m;if(!h)return u;const j=h.toLowerCase();return u.filter(P=>(P.headerName||P.field).toLowerCase().includes(j))},[t,m,h,c]),E=u=>{u.target.checked?l():s()},_=u=>j=>{f.current=u,j.dataTransfer.effectAllowed="move",j.dataTransfer.setDragImage(j.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},S=u=>j=>{j.preventDefault(),j.dataTransfer.dropEffect="move",u!==f.current&&b(u)},N=()=>{b(null)},g=u=>j=>{j.preventDefault();const P=f.current;b(null),f.current=null,P&&P!==u&&d&&d(P,u)},k=()=>{b(null),f.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(kr,{}),r.jsx("input",{autoComplete:"off",className:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:h,onChange:u=>p(u.target.value)})]})}),r.jsx("div",{className:"ogx-column-visibility-panel__list",children:C.map(u=>{const j=e.has(u.field),P=u.hideable!==!1,L=w===u.field,y=!!d&&!h;return r.jsxs("div",{className:["ogx-column-visibility-panel__item",!P&&"ogx-column-visibility-panel__item--disabled",L&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:y,onDragOver:y?S(u.field):void 0,onDragLeave:y?N:void 0,onDrop:y?g(u.field):void 0,onDragEnd:y?k:void 0,children:[y&&r.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:_(u.field),title:"Drag to reorder",children:r.jsx(Sr,{})}),r.jsxs("label",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:P?"pointer":"not-allowed"},children:[r.jsx(mt,{checked:j,onChange:T=>o(u.field,T.target.checked),disabled:!P}),r.jsx("span",{className:"ogx-column-visibility-panel__label",children:u.headerName||u.field})]})]},u.field)})}),r.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[r.jsxs("label",{className:"ogx-column-visibility-panel__item",children:[r.jsx(mt,{checked:x,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:()=>{l(),a?.()},children:"Reset"})]})]})}function jr({isOpen:n,containerRef:t,panelRef:e,effectiveColumns:o,columnVisibilityModel:l,effectiveColumnOrder:s,columnOrder:d,disableColumnReorder:a,onClose:c,onColumnVisibilityChange:h,onColumnOrderChange:p,setInternalColumnOrder:w}){const[b,f]=i.useState(16),[m,x]=i.useState(16),[C,E]=i.useState(()=>document.body);if(i.useLayoutEffect(()=>{if(!n||!t.current)return;const S=t.current.getBoundingClientRect();f(S.top+8),x(window.innerWidth-S.right+8),E(t.current.closest(".ogx-theme-provider")||document.body)},[n,t]),!n)return null;const _=a?void 0:(S,N)=>{const g=[...s],k=g.indexOf(S),u=g.indexOf(N);if(k===-1||u===-1)return;const j=[...g];j.splice(k,1),j.splice(u,0,S),d||w(j),p?.({oldIndex:k,targetIndex:u,column:o.find(P=>P.field===S)})};return Ge.createPortal(r.jsxs("div",{ref:e,style:{position:"fixed",top:b,right:m,zIndex:9999,display:"inline-block"},children:[r.jsx("button",{onClick:c,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(Ln,{columns:o,visibleColumns:new Set(o.filter(S=>l[S.field]!==!1).map(S=>S.field)),onVisibilityChange:(S,N)=>{h({...l,[S]:N})},onShowAll:()=>{const S={...l};o.forEach(N=>{N.hideable!==!1&&(S[N.field]=!0)}),h(S)},onHideAll:()=>{const S={...l};o.forEach(N=>{N.hideable!==!1&&(S[N.field]=!1)}),h(S)},onColumnReorder:_})]}),C)}const Er=new Map;function Nr(n){const{rows:t,columns:e,getRowId:o,rowHeight:l=52,headerHeight:s=56,autoHeight:d=!1,density:a,checkboxSelection:c=!1,disableRowSelectionOnClick:h=!1,disableMultipleRowSelection:p=!1,rowSelectionModel:w,onRowSelectionModelChange:b,onRowClick:f,onCellClick:m,filterModel:x,onFilterModelChange:C,sortModel:E,onSortModelChange:_,pagination:S=!1,paginationModel:N,onPaginationModelChange:g,pageSizeOptions:k=[10,25,50,100],pinnedColumns:u,onPinnedColumnsChange:j,pinnedRows:P,getDetailPanelContent:L,getDetailPanelHeight:y,detailPanelExpandedRowIds:T,onDetailPanelExpandedRowIdsChange:I,pinCheckboxColumn:A=!0,pinExpandColumn:$=!0,disableColumnReorder:D=!1,columnOrder:W,onColumnOrderChange:z,height:Y,rowReordering:K=!1,onRowOrderChange:v,loading:M=!1,treeData:F=!1,getTreeDataPath:O,defaultGroupingExpansionDepth:H,groupingColDef:V,rowGroupingModel:U,aggregationModel:oe,onAggregationModelChange:ie,getAggregationPosition:ne,isCellEditable:R,processRowUpdate:le,onProcessRowUpdateError:te,dataSource:re,multiSort:q=!1,sortingMode:J="client",filterMode:de="client",paginationMode:B="client",rowCount:Q,slots:Z,slotProps:ge,pivotMode:ce=!1,pivotModel:Ee,onPivotModelChange:Te,className:Pe="",style:Re,onRowsScrollEnd:ze,ariaLabel:ee,initialState:ye,onStateChange:bi,columnVisibilityModel:wi,onColumnVisibilityModelChange:vi,listView:Ot=!1,listViewColumn:Gn,columnGroupingModel:Ve,noRowsLabel:_i="No Data",localeText:Le,apiRef:nn}=n,on=Le?.noRowsLabel??_i,Ci=i.useMemo(()=>({items:[]}),[]),Ne=x||Ci,yi=i.useMemo(()=>[],[]),rn=U||yi,Vn=i.useRef(Z?.toolbar);Vn.current=Z?.toolbar;const ki=i.useRef(G=>{const X=Vn.current;return X?X(G):null}).current,Si=po({initialState:ye,sortModel:E,aggregationModel:oe,onAggregationModelChange:ie,columnVisibilityModel:wi,onColumnVisibilityModelChange:vi,pinnedColumns:u,onPinnedColumnsChange:j,pivotModel:Ee,onPivotModelChange:Te,paginationModel:N,onPaginationModelChange:g,rowSelectionModel:w}),{sortModel:Ie,isSortControlled:Wt,setInternalSortModel:At,aggregationModel:Me,handleAggregationModelChange:Un,columnVisibilityModel:Ue,handleColumnVisibilityModelChange:$t,pinnedColumns:Ze,handlePinnedColumnsChange:ln,currentPivotModel:sn,handlePivotModelChange:Kn,effectivePaginationModel:ke,handlePaginationModelChange:an,selectedRowIds:ve,isSelectionControlled:et,setInternalRowSelectionModel:tt}=Si,nt=b,zt=In(t,e,sn,ce),Be=a==="compact"?32:a==="comfortable"?72:l,Yn=ce&&zt.isValid?zt.pivotRows:t,dn=ce&&zt.isValid?zt.pivotColumns:e,Bt=!!(U&&U.length>0),Ke=i.useMemo(()=>V&&Bt&&!ce?{...Ze,left:["__group__",...(Ze?.left??[]).filter(G=>G!=="__group__")]}:Ze,[V,Bt,ce,Ze]),_t=i.useMemo(()=>V&&Bt&&!ce?[{headerName:"Group",width:220,...V,field:"__group__",hideable:!1,sortable:!1,pinnable:!1,exportable:!1},...dn]:dn,[V,Bt,ce,dn]),[ji,qn]=i.useState(null);i.useEffect(()=>{qn(null)},[Me]);const ot=i.useRef(null),Ei=i.useRef(null),Ht=i.useRef(null),Ni=i.useCallback(G=>G.id,[]),rt=o||Ni,cn=i.useMemo(()=>Yn.map(G=>{const X=rt(G);return X===G.id?G:{...G,id:X}}),[Yn,rt]),it=i.useCallback(G=>{vn.current?.classList.toggle("ogx--kb",G)},[]),Xn=i.useRef(re);Xn.current=re;const Jn=i.useRef(null),Qn=i.useRef(null),Mi=i.useCallback(G=>{if(Xn.current&&F&&(G.serverChildrenCount??0)>0&&(G.children??[]).length===0){const X=Qn.current?.getNodePath(G.id)||[G.groupingKey];Jn.current?.(G.id,X)}},[F]),Ce=qo({rows:cn,columns:_t,rowHeight:Be,headerHeight:s,rowCount:Q,columnVisibilityModel:Ue,initialState:n.initialState}),{state:pe,apiRef:lt,setRows:un,setColumns:Pi,setDimensions:Zn,setDataSourceLoading:Ii,setDataSourceError:Ti,setRowCount:Ri}=Ce,{scrollTop:Li,scrollLeft:Fi,handleScroll:Oi}=Eo({onRowsScrollEnd:ze});i.useEffect(()=>{nn&&(nn.current=lt.current)},[nn,lt]);const{copySelectedRows:eo}=ar({selectedRowIds:ve,columns:_t,getVisibleRows:()=>lt.current.getVisibleRows(),getRowId:rt});i.useEffect(()=>{lt.current.copySelectedRows=eo,lt.current.getSelectedRows=()=>Array.from(ve)},[eo,ve,lt]);const Wi=pe.dataSource.loading,Ct=M||Wi,st=i.useMemo(()=>pe.rows.allRows.map(G=>pe.rows.idRowsLookup.get(G)),[pe.rows]),yt=Jo({rows:st,getRowId:rt,getTreeDataPath:O,treeData:F,defaultGroupingExpansionDepth:H,filterModel:Ne,sortModel:Ie,onRowExpansionChange:Mi});i.useEffect(()=>{Qn.current=yt},[yt]);const kt=tr({rows:st,getRowId:rt,columns:_t,rowGroupingModel:rn,aggregationModel:Me,defaultGroupingExpansionDepth:H,filterModel:Ne,sortModel:Ie,getAggregationPosition:ne}),at=nr({rows:st,getRowId:rt,processRowUpdate:le,onProcessRowUpdateError:te,onRowChange:G=>{const{dispatch:X}=Ce,ue=Array.from(Ce.state.rows.idRowsLookup.values()).map(fe=>fe.id===G.id?G:fe);X({type:"SET_ROWS",payload:ue})}}),St=F,He=!!(rn&&rn.length>0),fn=St||He,Dt=St?yt:He?kt:null,jt=i.useMemo(()=>St?yt.rowMetaMap:He?kt.rowMetaMap:Er,[St,yt.rowMetaMap,He,kt.rowMetaMap]),Fe=S&&!He,Gt=i.useCallback(G=>{const{row:X,id:se}=G;if(fn&&jt.get(X.id)?.hasChildren){Dt?.toggleExpansion(se);return}if(f?.(G),!h){let ue;if(p)ue=ve.has(se)?[]:[se];else{const fe=new Set(ve);fe.has(se)?fe.delete(se):fe.add(se),ue=Array.from(fe)}et||tt(ue),nt?.(ue)}},[fn,Dt,f,jt,h,p,ve,et,tt,nt]),gn=rr({dataSource:re,sortModel:Ie,filterModel:Ne,paginationModel:ke,paginationMode:B,sortingMode:J,filterMode:de,aggregationModel:Me,setRows:un,setRowCount:Ri,setDataSourceLoading:Ii,setDataSourceError:Ti,onAggregationResults:qn});i.useEffect(()=>{gn.fetchChildren&&(Jn.current=gn.fetchChildren)},[gn.fetchChildren]),i.useEffect(()=>{re||un(cn)},[cn,un,re]);const Oe=!!L,[Ai,$i]=i.useState(new Set),dt=T??Ai,Vt=i.useCallback(G=>{const X=new Set(dt);X.has(G)?X.delete(G):X.add(G),T===void 0&&$i(X),I?.(X)},[dt,T,I]),{effectiveColumns:De,orderedColumns:hn,visibleOrderedColumns:zi,navigationColumns:to,columnWidths:We,effectiveColumnOrder:Ut,setInternalColumnOrder:Kt,columnReorderHandlers:ct,handleColumnResize:Bi}=So({activeColumns:_t,isHierarchyEnabled:fn,isRowGrouping:He,isTreeData:St,activeHierarchyHandlers:Dt,columnVisibilityModel:Ue,columnOrder:W,onColumnOrderChange:z,disableColumnReorder:D,pivotMode:ce,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:K,initialState:ye,setColumns:Pi});No({onStateChange:bi,sortModel:Ie,filterModel:Ne,effectivePaginationModel:ke,columnWidths:We,effectiveColumnOrder:Ut,columnVisibilityModel:Ue,pinnedColumns:Ke});const ut=Co({effectiveRows:st,activeHierarchyHandlers:Dt,filterMode:de,filterModel:Ne,dataSource:re,sortModel:Ie,sortingMode:J,pagination:Fe,paginationMode:B,effectivePaginationModel:ke,pinnedRows:P,isLoading:pe.dataSource.loading,pageSize:ke.pageSize}),Ye=ut.filteredRows,pn=ut.pinnedTopRows,xn=ut.pinnedBottomRows,Ae=ut.sortedUnpinnedRows,Et=ut.paginatedUnpinnedRows,mn=ut.allRenderableRows;i.useEffect(()=>{Ce.apiRef.current.getVisibleRows=()=>Fe?Et:Ae,Ce.apiRef.current.getAllFilteredRows=()=>Ae,Ce.apiRef.current.getVisibleColumns=()=>De},[Ae,Et,Fe,De,Ce.apiRef]);const Hi=Xo({rows:Fe?Et:Ae,getRowId:G=>G.id,onRowOrderChange:v,rowReordering:K}),ft=or(mn,to,We),{aggregationResult:Nt}=jn({rows:Ye,columns:_t,aggregationModel:Me,isServerSide:!!(re&&(B==="server"||J==="server")),dataSource:re,filterModel:Ne,sortModel:Ie,serverAggregationResults:ji}),gt=Object.keys(Me).length>0;i.useEffect(()=>{Ce.apiRef.current.getAggregationResult=()=>gt?Nt:null,Ce.apiRef.current.getAggregationModel=()=>gt?Me:null,Ce.apiRef.current.getGroupedExportRows=()=>{if(!He)return null;const{treeNodes:G,groupingRows:X}=kt,se=new Map;Ae.forEach(he=>se.set(he.id,he));const ue=[],fe=he=>{he.forEach(me=>{const be=G.get(me);if(!be)return;if(!!(be.children&&be.children.length>0))ue.push({type:"group-header",depth:be.depth,groupField:be.groupingField,groupValue:be.groupingValue}),fe(be.children),gt&&be.aggregatedValues&&ue.push({type:"group-subtotal",depth:be.depth,groupField:be.groupingField,groupValue:be.groupingValue,aggregatedValues:be.aggregatedValues});else{const Tt=se.get(me)??X.get(me);Tt&&ue.push({type:"leaf",depth:be.depth,row:Tt})}})};return fe(Array.from(G.keys()).filter(he=>G.get(he)?.parentId===null)),gt&&Nt&&ue.push({type:"grand-total",depth:0,aggregatedValues:Nt}),ue}},[Nt,Me,gt,Ce.apiRef,He,kt,Ae]);const xe=fo({rowHeight:Be,pagination:Fe,paginatedUnpinnedRows:Et,sortedUnpinnedRows:Ae,expandedRowIds:dt,getDetailPanelHeight:y,pinnedTopRowsLength:pn.length,pinnedBottomRowsLength:xn.length,visibleOrderedColumns:zi,pinnedColumns:Ke,columnWidths:We,viewportWidth:pe.dimensions.viewportWidth||1e3,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:K,paginationMode:B,isLoading:pe.dataSource.loading,pageSize:ke.pageSize}),Di=i.useMemo(()=>{const G={};for(const X of[...xe.leftPinnedCols,...xe.unpinnedColsWithWidth,...xe.rightPinnedCols])X.isSpacer||(G[X.field]=X.width);return{...G,...We}},[xe.leftPinnedCols,xe.unpinnedColsWithWidth,xe.rightPinnedCols,We]);i.useEffect(()=>{Ce.apiRef.current.scrollToIndexes=({rowIndex:G,colIndex:X})=>{const se=ot.current;if(se){if(G!==void 0&&G>=0){const ue=G>0?xe.cumulativeHeights[G-1]:0,fe=xe.cumulativeHeights[G]??ue,{scrollTop:he,clientHeight:me}=se;ue<he?se.scrollTop=ue:fe>he+me&&(se.scrollTop=fe-me)}if(X!==void 0&&X>=0){const fe=[...xe.leftPinnedCols,...xe.unpinnedColsWithWidth,...xe.rightPinnedCols][X];if(!fe)return;const he=xe.unpinnedColsWithWidth.findIndex(Zi=>Zi.field===fe.field);if(he===-1)return;const me=he>0?xe.unpinnedAccWidths[he-1]:0,be=xe.unpinnedAccWidths[he]??me,It=xe.leftWidth+be,{scrollLeft:Tt,clientWidth:io}=se;me<Tt?se.scrollLeft=me:It>Tt+io&&(se.scrollLeft=It-io)}}}},[xe,ot,Ce.apiRef]);const Se=yo({layout:xe,scrollTop:Li,scrollLeft:Fi,viewportWidth:pe.dimensions.viewportWidth,viewportHeight:pe.dimensions.viewportHeight,autoHeight:d,rowReordering:K,hasDetailPanel:Oe,checkboxSelection:c,pinCheckboxColumn:A,pinExpandColumn:$});i.useEffect(()=>{if(!ot.current)return;const G=new ResizeObserver(X=>{for(const se of X){const{width:ue,height:fe}=se.contentRect;Zn(ue,fe)}});return G.observe(ot.current),()=>{G.disconnect()}},[Zn]);const Mt=i.useCallback((G,X)=>{const se=new Set(ve);X?se.add(G):se.delete(G);const ue=Array.from(se);et||tt(ue),nt?.(ue)},[ve,et,nt,tt]),Gi=i.useCallback(G=>{let X=[];G&&(X=st.map(se=>se.id)),et||tt(X),nt?.(X)},[st,et,nt,tt]),no=i.useCallback((G,X)=>{const se=X?[{field:G,sort:X}]:[];Wt||At(se),_?.(se)},[Wt,_,At]),Vi=i.useCallback((G,X)=>{const se=Ie.filter(fe=>fe.field!==G),ue=X?[...se,{field:G,sort:X}]:se;Wt||At(ue),_?.(ue)},[Ie,Wt,_,At]),{focusedCell:Yt,setFocusedCell:bn,handleFocus:Ui,handleBlur:Ki,handleKeyDown:Yi}=go({allRenderableRows:mn,navigationColumns:to,checkboxSelection:c,selectedRowIds:ve,handleSelectionChange:Mt,handleDetailPanelToggle:Vt,editingHandlers:at,setKeyboardMode:it,sortModel:Ie,handleSort:no,isCellEditable:R,pagination:Fe,pageSize:ke.pageSize,virtualization:Se,viewportRef:ot}),wn=i.useCallback(G=>{it(!1),bn({id:G.row.id,field:G.field}),Ht.current?.focus({preventScroll:!0}),m?.(G)},[m,it,bn]),oo=i.useRef(at.editingCell);i.useEffect(()=>{const G=!!oo.current,X=!!at.editingCell;G&&!X&&Ht.current?.focus({preventScroll:!0}),oo.current=at.editingCell},[at.editingCell]);const qi=jo({renderContext:Se.renderContext,pinnedTopRows:pn,pinnedBottomRows:xn,paginatedUnpinnedRows:Et,sortedUnpinnedRows:Ae,pagination:Fe}),Xi=t.length>0&&ve.size===t.length,Ji=ve.size>0&&ve.size<t.length,Qi=i.useMemo(()=>De.some(G=>!!G.rowSpan),[De]),[Pt,qt]=i.useState(!1),vn=i.useRef(null),_n=i.useRef(null),ro=i.useMemo(()=>{if(!Z?.toolbar)return null;const G=D?void 0:(X,se)=>{const ue=[...Ut],fe=ue.indexOf(X),he=ue.indexOf(se);if(fe===-1||he===-1)return;const me=[...ue];me.splice(fe,1),me.splice(he,0,X),W||Kt(me);const be=De.find(It=>It.field===X);be&&z?.({oldIndex:fe,targetIndex:he,column:be})};return{apiRef:Ce.apiRef,columns:hn,baseColumns:e,aggregationModel:Me,onAggregationModelChange:Un,...ce||Ee||Te?{pivotModel:sn,onPivotModelChange:Kn}:{},filterModel:Ne,onFilterModelChange:C,columnVisibilityModel:Ue,onColumnVisibilityModelChange:$t,onColumnReorder:G,onColumnOrderReset:D?void 0:()=>Kt(e.map(X=>X.field)),forceColumnsOpen:Pt,onColumnsPanelClose:()=>qt(!1),...ge?.toolbar}},[Z?.toolbar,D,Ut,hn,De,W,z,Kt,Ce.apiRef,e,Me,Un,ce,Ee,Te,sn,Kn,Ne,C,Ue,$t,Pt,ge?.toolbar]);return i.useEffect(()=>{if(!Pt||Z?.toolbar)return;function G(X){_n.current&&!_n.current.contains(X.target)&&qt(!1)}return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[Pt,Z?.toolbar]),r.jsxs("div",{ref:vn,className:["ogx",Pe,d&&"ogx--auto-height",Qi&&"ogx--row-spanning",Ot&&"ogx--list-view"].filter(Boolean).join(" "),style:{...Re,height:Y??Re?.height,"--ogx-row-height":`${Be}px`,"--ogx-header-height":`${s}px`},"aria-busy":Ct,children:[ro&&r.jsx(ki,{...ro}),!Z?.toolbar&&r.jsx(jr,{isOpen:Pt,containerRef:vn,panelRef:_n,effectiveColumns:De,columnVisibilityModel:Ue,effectiveColumnOrder:Ut,columnOrder:W,disableColumnReorder:D,onClose:()=>qt(!1),onColumnVisibilityChange:$t,onColumnOrderChange:z,setInternalColumnOrder:Kt}),Ot&&Gn&&r.jsx(cr,{ariaLabel:ee,allRenderableRows:mn,filteredRows:Ye,pagination:Fe,effectivePaginationModel:ke,pageSizeOptions:k,selectedRowIds:ve,listViewColumn:Gn,noRowsLabel:on,rowHeight:Be,checkboxSelection:c,paginationMode:B,dataSource:re,serverRowCount:pe.pagination.rowCount||0,paginationSlot:Z?.pagination,paginationSlotProps:ge?.pagination,localeText:Le?{paginationRowsPerPage:Le.paginationRowsPerPage,paginationOf:Le.paginationOf,paginationPage:Le.paginationPage}:void 0,onRowClick:Gt,onSelectionChange:Mt,onPaginationModelChange:an}),!Ot&&r.jsx("div",{ref:G=>{ot.current=G,Ht.current=G},className:"ogx__viewport",onScroll:Oi,role:"grid","aria-label":ee||"Data grid","aria-rowcount":Ye.length+1,"aria-colcount":e.length+(c?1:0)+(Oe?1:0)+(K?1:0),"aria-busy":Ct,tabIndex:0,onKeyDownCapture:()=>{it(!0)},onMouseDownCapture:()=>{it(!1)},onKeyDown:Yi,onFocus:Ui,onBlur:Ki,children:r.jsxs("div",{ref:Ei,className:"ogx__content",style:{width:Se.totalWidth},role:"presentation",children:[r.jsx(Nn,{columns:Se.virtualColumns,allColumns:De,columnGroupingModel:Ve,checkboxSelection:c,allSelected:Xi,someSelected:Ji,onSelectAll:Gi,sortModel:Ie,onSort:no,onSortAdd:Vi,multiSort:q,onColumnResize:Bi,columnWidths:We,pinnedColumns:Ke,focusedCell:Yt,onHeaderClick:G=>{bn({id:"HEADER",field:G}),it(!1),Ht.current?.focus({preventScroll:!0})},onDragStart:Ve?void 0:ct.onDragStart,onDragOver:Ve?void 0:ct.onDragOver,onDragEnd:Ve?void 0:ct.onDragEnd,onDrop:Ve?void 0:ct.onDrop,draggedColumn:Ve?void 0:ct.draggedColumn,dragOverColumn:Ve?void 0:ct.dragOverColumn,rowReordering:K,hasDetailPanel:Oe,pinCheckboxColumn:A,pinExpandColumn:$,aggregationModel:Me,onHideColumn:G=>{$t({...Ue,[G]:!1})},onManageColumns:()=>qt(!0),onPinColumn:(G,X)=>{const se=[...Ze?.left??[]],ue=[...Ze?.right??[]],fe=se.filter(me=>me!==G),he=ue.filter(me=>me!==G);ln(X==="left"?{left:[...fe,G],right:he}:X==="right"?{left:fe,right:[...he,G]}:{left:fe,right:he})}}),!Ct&&!pe.dataSource.error&&Ye.length===0&&r.jsx(Io,{noRowsLabel:on,width:Se.totalWidth}),r.jsx(Rn,{rows:pn,position:"top",columns:Se.virtualColumns,selectedRowIds:ve,checkboxSelection:c,onRowClick:Gt,onCellClick:wn,onSelectionChange:Mt,columnWidths:We,pinnedColumns:Ke,pinnedRows:P,hasDetailPanel:Oe,expandedRowIds:dt,getDetailPanelContent:L,getDetailPanelHeight:y,onDetailPanelToggle:Vt,pinCheckboxColumn:A,pinExpandColumn:$,focusedCell:Yt,colspanMap:ft.colspanMap,rowSpanningCaches:ft.rowSpanningState.caches,rowHeight:Be,rowMetaMap:jt}),r.jsx(yr,{virtualContainerHeight:Se.totalHeight-Se.pinnedTopHeight-Se.pinnedBottomHeight,offsetTop:Se.offsetTop,effectiveLoading:Ct,visibleRows:qi,baseColumns:e,virtualColumns:Se.virtualColumns,viewportWidth:pe.dimensions.viewportWidth,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:K,rowHeight:Be,pinnedRows:P,selectedRowIds:ve,onRowClick:Gt,onCellClick:wn,onSelectionChange:Mt,columnWidths:We,pinnedColumns:Ke,expandedRowIds:dt,getDetailPanelContent:L,getDetailPanelHeight:y,onDetailPanelToggle:Vt,pinCheckboxColumn:A,pinExpandColumn:$,rowReorderHandlers:Hi,editingHandlers:at,focusedCell:Yt,colspanMap:ft.colspanMap,rowSpanningCaches:ft.rowSpanningState.caches,paginationMode:B,dataSourceLoading:pe.dataSource.loading,sortedUnpinnedRowCount:Ae.length,infiniteScrollSkeletonCount:Math.min(ke.pageSize,20),unpinnedRowsLength:xe.unpinnedRowsLength,rowMetaMap:jt}),r.jsx(Rn,{rows:xn,position:"bottom",columns:Se.virtualColumns,selectedRowIds:ve,checkboxSelection:c,onRowClick:Gt,onCellClick:wn,onSelectionChange:Mt,columnWidths:We,pinnedColumns:Ke,pinnedRows:P,hasDetailPanel:Oe,expandedRowIds:dt,getDetailPanelContent:L,getDetailPanelHeight:y,onDetailPanelToggle:Vt,pinCheckboxColumn:A,pinExpandColumn:$,focusedCell:Yt,colspanMap:ft.colspanMap,rowSpanningCaches:ft.rowSpanningState.caches,rowHeight:Be,rowMetaMap:jt}),gt&&!ce&&r.jsx(Po,{columns:hn,aggregationModel:Me,aggregationResult:Nt,columnWidths:Di,rowHeight:Be,checkboxSelection:c,hasDetailPanel:Oe,rowReordering:K,pinnedColumns:Ke})]})}),!Ot&&Fe&&(()=>{const G=Z?.pagination||Mn;return r.jsx(G,{page:ke.page,pageSize:ke.pageSize,rowCount:pe.pagination.rowCount,pageSizeOptions:k,onPageChange:X=>an({...ke,page:X}),onPageSizeChange:X=>an({...ke,pageSize:X,page:0}),localeText:Le?{paginationRowsPerPage:Le.paginationRowsPerPage,paginationOf:Le.paginationOf,paginationPage:Le.paginationPage}:void 0,...ge?.pagination})})(),r.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[Ct?"Loading data...":"",pe.dataSource.error?`Error: ${pe.dataSource.error instanceof Error?pe.dataSource.error.message:"Unknown error"}`:"",!M&&!pe.dataSource.error&&(Ye.length===0?on:Ne&&((Ne.quickFilterValues?.length||0)>0||(Ne.items?.length||0)>0)?`${Ye.length} ${Ye.length===1?"row":"rows"} found`:"")]}),r.jsx(To,{error:pe.dataSource.error})]})}function Mr({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((l,s)=>r.jsx("div",{className:"ogx__skeleton-cell",children:r.jsx("div",{className:"ogx__skeleton-content"})},s))},o))})}const Fn=new Set(["isEmpty","isNotEmpty"]);function Pr(n,t){return n.find(e=>"field"in e&&e.field===t)}const Ir=({col:n,item:t,onChange:e})=>{const o=i.useId(),l=vo(n.type),s=!!t,d=t?.operator??l[0],[a,c]=i.useState(t?.value!=null?String(t.value):""),h=i.useRef(e),p=i.useRef(t),w=i.useRef(n.field),b=i.useRef(d);i.useLayoutEffect(()=>{h.current=e,p.current=t,w.current=n.field,b.current=d});const f=i.useRef(t?.value);i.useEffect(()=>{t?.value!==f.current&&(f.current=t?.value,c(t?.value!=null?String(t.value):""))},[t?.value]),i.useEffect(()=>{const S=setTimeout(()=>{const N=p.current,g=N?.value??"";a!==g&&h.current({id:N?.id??`${w.current}-${Date.now()}`,field:w.current,operator:b.current,value:a})},300);return()=>clearTimeout(S)},[a]);const m=S=>{const N=Fn.has(S),g={id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:S,value:N?void 0:t?.value??(n.type==="boolean"?"true":"")};e(g)},x=()=>{c(""),e(null)},C=Fn.has(String(d)),E=n.type==="boolean",_=!C;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:S=>m(S.target.value),"aria-label":`Filter operator for ${n.headerName||n.field}`,children:l.map(S=>r.jsx("option",{value:S,children:S},S))}),_&&E&&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:S=>{c(S.target.value),e({id:t?.id??`${n.field}-${Date.now()}`,field:n.field,operator:d,value:S.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"})]}),_&&!E&&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:S=>c(S.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:x,"aria-label":`Clear filter for ${n.headerName||n.field}`,title:"Clear",children:"×"})]})]})},On=({filterModel:n,columns:t,onFilterModelChange:e})=>{const o=i.useMemo(()=>n.items??[],[n.items]),l=n.logicOperator??"and",s=i.useCallback((c,h)=>{const p=o.filter(b=>"field"in b&&b.field!==c),w=h?[...p,h]:p;e({...n,items:w})},[o,n,e]),d=i.useCallback(c=>{e({...n,logicOperator:c})},[n,e]),a=t.filter(c=>c.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${l==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("and"),"aria-pressed":l==="and",children:"ALL (AND)"}),r.jsx("button",{className:`ogx-filter__logic-pill${l==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>d("or"),"aria-pressed":l==="or",children:"ANY (OR)"})]}),a.length===0?r.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):a.map(c=>r.jsx(Ir,{col:c,item:Pr(o,c.field),onChange:h=>s(c.field,h)},c.field))]})},Tr=["sum","avg","count","min","max"];function Wn(){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 Rr({anchorRef:n,columns:t,model:e,onChange:o,onClose:l}){const s=i.useRef(null),[d,a]=i.useState({top:0,right:0}),[c,h]=i.useState(document.body);i.useLayoutEffect(()=>{h(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const p=i.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]);i.useEffect(()=>{a(p());const y=()=>a(p());return window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[p]),i.useEffect(()=>{function y(I){s.current&&!s.current.contains(I.target)&&n.current&&!n.current.contains(I.target)&&l()}function T(I){I.key==="Escape"&&l()}return document.addEventListener("mousedown",y),document.addEventListener("keydown",T),()=>{document.removeEventListener("mousedown",y),document.removeEventListener("keydown",T)}},[n,l]);const w=new Set(e.rowFields),b=new Set(e.columnFields),f=new Set(e.valueFields.map(y=>y.field)),m=y=>w.has(y)||b.has(y)||f.has(y);function x(y){w.has(y)||o({...e,rowFields:[...e.rowFields,y]})}function C(y){b.has(y)||o({...e,columnFields:[...e.columnFields,y]})}function E(y,T="sum"){f.has(y)||o({...e,valueFields:[...e.valueFields,{field:y,aggFn:T}]})}function _(y){o({...e,rowFields:e.rowFields.filter(T=>T!==y)})}function S(y){o({...e,columnFields:e.columnFields.filter(T=>T!==y)})}function N(y){o({...e,valueFields:e.valueFields.filter(T=>T.field!==y)})}function g(y,T){o({...e,valueFields:e.valueFields.map(I=>I.field===y?{...I,aggFn:T}:I)})}function k(){o({rowFields:[],columnFields:[],valueFields:[]})}const u=new Set(t.filter(y=>y.type==="number"||y.aggregable).map(y=>y.field)),j=e.rowFields.length+e.columnFields.length+e.valueFields.length,P=y=>t.find(T=>T.field===y)?.headerName??y,L=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(Wn,{}),"Pivot Mode"]}),j>0&&r.jsx("button",{className:"ogx-pivot-panel__reset-btn",onClick:k,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(y=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[P(y),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>_(y),title:`Remove ${P(y)}`,children:"×"})]},y))})]}),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(y=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[P(y),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>S(y),title:`Remove ${P(y)}`,children:"×"})]},y))})]}),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(y=>r.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[P(y.field),r.jsx("select",{className:"ogx-pivot-chip__fn-select",value:y.aggFn,onChange:T=>g(y.field,T.target.value),title:"Aggregation function",children:Tr.map(T=>r.jsx("option",{value:T,children:T.toUpperCase()},T))}),r.jsx("button",{className:"ogx-pivot-chip__remove",onClick:()=>N(y.field),title:`Remove ${P(y.field)}`,children:"×"})]},y.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(y=>{const T=u.has(y.field);return m(y.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:y.headerName??y.field}),r.jsxs("div",{className:"ogx-pivot-field-actions",children:[r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>x(y.field),title:"Add to Row Fields",children:"Row"}),r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>C(y.field),title:"Add to Column Fields",children:"Col"}),T&&r.jsx("button",{className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>E(y.field),title:"Add to Value Fields",children:"Val"})]})]},y.field)}),t.every(y=>m(y.field))&&r.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return Ge.createPortal(L,c)}function Lr(){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 Fr(){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 Or({value:n="",onChange:t,placeholder:e="Search...",debounceMs:o=250}){const[l,s]=i.useState(()=>n.length>0),[d,a]=i.useState(n),c=i.useRef(null),h=i.useRef(null),p=i.useRef(t);i.useLayoutEffect(()=>{p.current=t},[t]);const w=i.useRef(n),b=i.useRef(n),f=i.useRef(!1);i.useLayoutEffect(()=>{f.current&&document.activeElement!==c.current&&c.current?.focus()}),i.useEffect(()=>{n!==b.current&&(b.current=n,n!==w.current&&(a(n),w.current=n,n?s(!0):(f.current=!1,s(!1))))},[n]),i.useEffect(()=>{const _=setTimeout(()=>{d!==w.current&&(w.current=d,p.current(d))},o);return()=>clearTimeout(_)},[d,o]);const m=i.useCallback(()=>{s(!0),requestAnimationFrame(()=>c.current?.focus())},[]),x=i.useCallback(_=>{_.stopPropagation(),a(""),w.current="",p.current(""),c.current?.focus()},[]),C=i.useCallback(()=>{f.current=!0,s(!0)},[]),E=i.useCallback(()=>{f.current=!1,setTimeout(()=>{if(h.current&&document.activeElement&&h.current.contains(document.activeElement)){f.current=!0;return}d||s(!1)},150)},[d]);return i.useEffect(()=>{const _=S=>{h.current&&!h.current.contains(S.target)&&(d||s(!1))};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[d]),r.jsxs("div",{ref:h,className:`ogx-global-search${l?" ogx-global-search--expanded":""}`,onClick:l?void 0:m,children:[r.jsx("div",{className:"ogx-global-search__icon-wrapper",children:r.jsx(Lr,{})}),r.jsx("input",{ref:c,className:"ogx-global-search__input",value:d,onChange:_=>a(_.target.value),onFocus:C,onBlur:E,placeholder:e,"aria-label":"Global Search",autoComplete:"off"}),d&&r.jsx("button",{className:"ogx-global-search__clear",onClick:x,"aria-label":"Clear search",children:r.jsx(Fr,{})})]})}function vt({title:n,children:t,placement:e="top",enterDelay:o=200,leaveDelay:l=0}){const[s,d]=i.useState(!1),[a,c]=i.useState({top:0,left:0}),h=i.useRef(null),p=i.useRef(null),w=i.useCallback(()=>{if(!p.current)return;const x=p.current.getBoundingClientRect();let C=0,E=0;const _=window.pageXOffset||document.documentElement.scrollLeft,S=window.pageYOffset||document.documentElement.scrollTop;e==="top"?(C=x.top+S-8,E=x.left+_+x.width/2):e==="bottom"&&(C=x.bottom+S+8,E=x.left+_+x.width/2),c({top:C,left:E})},[e]);i.useLayoutEffect(()=>(s&&(w(),window.addEventListener("scroll",w,!0),window.addEventListener("resize",w)),()=>{window.removeEventListener("scroll",w,!0),window.removeEventListener("resize",w)}),[s,w]);const b=()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{d(!0)},o)},f=()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{d(!1)},l)},m=i.useCallback(x=>{p.current=x?x.firstElementChild??x:null},[]);return r.jsxs(r.Fragment,{children:[r.jsx("span",{ref:m,style:{display:"inline-block",lineHeight:0},onMouseEnter:b,onMouseLeave:f,children:t}),s&&n&&Ge.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 Wr=["none","sum","avg","count","min","max"];function An(){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 Ar(){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 $n(){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 $r({anchorRef:n,aggregationModel:t,aggregableColumns:e,onFunctionChange:o,onClearAll:l,onClose:s,activeCount:d}){const a=i.useRef(null),[c,h]=i.useState({top:0,right:0}),[p,w]=i.useState(document.body);i.useLayoutEffect(()=>{w(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const b=i.useCallback(()=>{if(!n.current)return{top:0,right:0};const m=n.current.getBoundingClientRect();return{top:m.bottom+6,right:window.innerWidth-m.right}},[n]);i.useEffect(()=>{h(b());const m=()=>h(b());return window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}},[b]),i.useEffect(()=>{function m(x){a.current&&!a.current.contains(x.target)&&n.current&&!n.current.contains(x.target)&&s()}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[n,s]),i.useEffect(()=>{function m(x){x.key==="Escape"&&s()}return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[s]);const f=r.jsxs("div",{ref:a,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:c.top,right:c.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(An,{}),"Summaries"]}),d>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:l,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(m=>{const x=t[m.field]||"none";return r.jsxs("div",{className:"ogx-toolbar__agg-row",children:[r.jsx("span",{className:"ogx-toolbar__agg-label",title:m.field,children:m.headerName||m.field}),r.jsx("div",{className:"ogx-toolbar__agg-pills",children:Wr.map(C=>r.jsx("button",{className:`ogx-toolbar__pill${x===C?" ogx-toolbar__pill--active":""}`,onClick:()=>o(m.field,C),"aria-pressed":x===C,children:C},C))})]},m.field)})})]});return Ge.createPortal(f,p)}function zr({anchorRef:n,columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:l,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,onClose:c,showNonHideableColumns:h}){const p=i.useRef(null),[w,b]=i.useState({top:0,right:0}),[f,m]=i.useState(document.body);i.useLayoutEffect(()=>{m(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const x=i.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]);i.useEffect(()=>{b(x());const E=()=>b(x());return window.addEventListener("scroll",E,!0),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,!0),window.removeEventListener("resize",E)}},[x]),i.useEffect(()=>{function E(_){p.current&&!p.current.contains(_.target)&&n.current&&!n.current.contains(_.target)&&c()}return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[n,c]);const C=r.jsx("div",{ref:p,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:w.top,right:w.right,width:280,padding:0},children:r.jsx(Ln,{columns:t,visibleColumns:e,onVisibilityChange:o,onShowAll:l,onHideAll:s,onColumnReorder:d,onColumnOrderReset:a,showNonHideableColumns:h})});return Ge.createPortal(C,f)}function Br({anchorRef:n,columns:t,filterModel:e,onFilterModelChange:o,onClose:l}){const s=i.useRef(null),[d,a]=i.useState({top:0,right:0}),c=i.useRef(l);i.useLayoutEffect(()=>{c.current=l},[l]);const[h,p]=i.useState(document.body);i.useLayoutEffect(()=>{p(n.current?.closest(".ogx-theme-provider")??document.body)},[n]);const w=i.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]);i.useEffect(()=>{a(w());const x=()=>a(w());return window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[w]),i.useEffect(()=>{function x(C){C.key==="Escape"&&c.current()}return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[]);const b=e.items?.length??0,f=()=>{o({...e,items:[],logicOperator:"and"})},m=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($n,{}),"Filters",b>0&&r.jsx("span",{className:"ogx-toolbar__panel-count",children:b})]}),r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[b>0&&r.jsx("button",{className:"ogx-toolbar__clear-btn",onClick:f,title:"Clear all filters",children:"Clear all"}),r.jsx("button",{className:"ogx-toolbar__close-btn",onClick:()=>c.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(On,{columns:t,filterModel:e,onFilterModelChange:o})})]});return Ge.createPortal(m,h)}const Hr={rowFields:[],columnFields:[],valueFields:[]};function Dr({columns:n=[],baseColumns:t,aggregationModel:e={},onAggregationModelChange:o,pivotModel:l,onPivotModelChange:s,filterModel:d,onFilterModelChange:a,columnVisibilityModel:c={},onColumnVisibilityModelChange:h,onColumnReorder:p,onColumnOrderReset:w,forceColumnsOpen:b,onColumnsPanelClose:f,children:m,rightContent:x,style:C,renderColumnsButton:E,renderFilterButton:_,renderAggregationButton:S,renderExportButton:N,renderQuickFilter:g,className:k,showNonHideableColumns:u}){const[j,P]=i.useState(!1),[L,y]=i.useState(!1),[T,I]=i.useState(!1),[A,$]=i.useState(!1);i.useEffect(()=>{b&&(I(!0),P(!1),y(!1),$(!1))},[b]);const D=i.useRef(null),W=i.useRef(null),z=i.useRef(null),Y=i.useRef(null),K=i.useRef(null),v=i.useRef(null),M=i.useRef(null),F=l??Hr,O=F.rowFields.length>0||F.columnFields.length>0||F.valueFields.length>0,H=n.filter(J=>J.aggregable!==!1&&(J.type==="number"||J.aggregable===!0)),V=Object.keys(e).filter(J=>e[J]&&e[J]!=="none").length,U=i.useCallback((J,de)=>{if(!o)return;const B={...e};de==="none"?delete B[J]:B[J]=de,o(B)},[e,o]),oe=i.useCallback(()=>{o?.({})},[o]),ie=i.useCallback(J=>{if(!a)return;const B={...d||{},quickFilterValues:J?[J]:[],items:d?.items||[]};a(B)},[d,a]),ne=d?.quickFilterValues?.[0]||"",R=d?.items?.length||0,le=new Set(n.filter(J=>c[J.field]!==!1).map(J=>J.field)),te=i.useCallback((J,de)=>{if(!h)return;const B={...c,[J]:de};h(B)},[c,h]),re=i.useCallback(()=>{if(!h)return;const J={...c};n.forEach(de=>{de.hideable!==!1&&(J[de.field]=!0)}),h(J)},[n,c,h]),q=i.useCallback(()=>{if(!h)return;const J={...c};n.forEach(de=>{de.hideable!==!1&&(J[de.field]=!1)}),h(J)},[n,c,h]);return r.jsxs("div",{className:["ogx-toolbar",k].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:C,children:[m&&r.jsx("div",{className:"ogx-toolbar__left",children:m}),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:ne,onChange:ie}):r.jsx(Or,{value:ne,onChange:ie,placeholder:"Search..."})}),h&&r.jsxs("div",{ref:K,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[E?E({onClick:()=>{I(J=>!J),P(!1),y(!1),$(!1)},isOpen:T,activeCount:n.length-le.size}):r.jsx(vt,{title:"Columns",children:r.jsx("button",{ref:z,className:`ogx-toolbar__icon-btn${T?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns",onClick:()=>{I(!T),P(!1),y(!1),$(!1)},children:r.jsx(Ar,{})})}),T&&r.jsx(zr,{anchorRef:E?K:z,columns:n,visibleColumns:le,onVisibilityChange:te,onShowAll:re,onHideAll:q,onColumnReorder:p,onColumnOrderReset:w,onClose:()=>{I(!1),f?.()},showNonHideableColumns:u})]}),a&&r.jsxs("div",{ref:v,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[_?_({onClick:()=>{$(J=>!J),P(!1),y(!1),I(!1)},isOpen:A,activeCount:R}):r.jsx(vt,{title:"Filters",children:r.jsxs("button",{ref:Y,className:`ogx-toolbar__icon-btn${A?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters",onClick:()=>{$(!A),P(!1),y(!1),I(!1)},children:[r.jsx($n,{}),R>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),A&&r.jsx(Br,{anchorRef:_?v:Y,columns:n,filterModel:d||{items:[]},onFilterModelChange:a,onClose:()=>$(!1)})]}),s&&r.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[r.jsx(vt,{title:"Pivot",children:r.jsxs("button",{ref:W,className:`ogx-toolbar__icon-btn${L?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-expanded":L,onClick:()=>{y(!L),P(!1),I(!1),$(!1)},children:[r.jsx(Wn,{}),O&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),L&&r.jsx(Rr,{anchorRef:W,columns:t??n,model:F,onChange:J=>{s?.(J)},onClose:()=>y(!1)})]}),r.jsxs("div",{ref:M,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[S?S({onClick:()=>{P(J=>!J),y(!1),I(!1),$(!1)},isOpen:j,activeCount:V}):r.jsx(vt,{title:"Summaries",children:r.jsxs("button",{ref:D,className:`ogx-toolbar__icon-btn${j?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-expanded":j,onClick:()=>{P(!j),y(!1),I(!1),$(!1)},children:[r.jsx(An,{}),V>0&&r.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${V} active summaries`})]})}),j&&r.jsx($r,{anchorRef:S?M:D,aggregationModel:e,aggregableColumns:H,onFunctionChange:U,onClearAll:oe,onClose:()=>P(!1),activeCount:V})]}),N&&N(),x]})]})}function Gr(){return i.useRef(null)}const Vr=({fullWidth:n=!1,error:t=!1,startAdornment:e,endAdornment:o,className:l="",...s})=>{const d=["ogx-input-wrapper",n&&"ogx-input-wrapper--full-width",t&&"ogx-input-wrapper--error",s.disabled&&"ogx-input-wrapper--disabled",l].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 zn(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 Ur(n){return n.filter(t=>!(t.exportable===!1||t.field==="__check__"||t.field==="__actions__"))}function Bn(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 Hn(n){return(typeof n.width=="number"?n.width:void 0)??(n.flex??1)*100}function Kr(n,t){const e=n.reduce((l,s)=>l+Hn(s),0),o={};return n.forEach((l,s)=>{o[s]={cellWidth:Hn(l)/e*t}}),o}function Yr(n,t){return!n.items||n.items.length===0?"":n.items.flatMap(e=>{if("items"in e)return[];const l=t.find(d=>d.field===e.field)?.headerName??e.field,s=e.value!==void 0&&e.value!==null?String(e.value):"";return[`${l} ${e.operator} "${s}"`]}).join(" • ")}async function qr(n,t,e={}){let o,l;try{const[v,M]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);o=v.default,l=M.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:c="landscape",selectedRows:h,aggregationResult:p,aggregationModel:w,filterModel:b,alternateRowColor:f=!0,headerBackgroundColor:m="#4f46e5",headerTextColor:x="#ffffff",fontSize:C=9,groupedRows:E}=e,_=new o({orientation:c,unit:"mm",format:"a4"}),S=_.internal.pageSize.getWidth(),N=_.internal.pageSize.getHeight(),g=14,k=S-g*2,u=Ur(t),j=h&&h.length>0?n.filter(v=>h.includes(v.id)):n;let P=g;if(d){let v=g,M=g+8;if(a)try{_.addImage(a,"PNG",v,g,10,10),v+=14}catch{}_.setFontSize(16),_.setFont("helvetica","bold"),_.setTextColor(30,41,59),_.text(d,v,M),M+=6,_.setFontSize(8),_.setFont("helvetica","normal"),_.setTextColor(100,116,139);const F=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),O=E?E.filter(H=>H.type==="leaf").length:j.length;if(_.text(`Exported: ${F} • ${O} row${O!==1?"s":""}`,v,M),M+=5,b){const H=Yr(b,t);H&&(_.text(`Filters: ${H}`,v,M),M+=5)}_.setDrawColor(226,232,240),_.setLineWidth(.3),_.line(g,M+2,S-g,M+2),P=M+6}const L=[u.map(v=>v.headerName??v.field)];let y,T;if(E&&E.length>0){y=[];const v=w||{};E.forEach(M=>{if(M.type==="group-header"){const O=`${" ".repeat(M.depth*2)}${M.groupField??""}: ${String(M.groupValue??"")}`;y.push(u.map((H,V)=>V===0?O:""))}else if(M.type==="leaf"&&M.row){const F=M.row,O=" ".repeat(M.depth*2);y.push(u.map((H,V)=>(V===0?O:"")+Bn(F,H)))}else if(M.type==="group-subtotal"&&M.aggregatedValues){const F=" ".repeat(M.depth*2);y.push(u.map((O,H)=>{if(H===0)return`${F}Subtotal`;const V=M.aggregatedValues[O.field];if(V==null)return"";let U=V;return O.valueFormatter?U=O.valueFormatter({value:V,row:{},field:O.field}):v[O.field]&&(U=_e(V,v[O.field])),String(U)}))}else M.type==="grand-total"&&M.aggregatedValues&&(T=[u.map((O,H)=>{if(H===0)return"Grand Total";const V=M.aggregatedValues[O.field];if(V==null)return"";let U=V;return O.valueFormatter?U=O.valueFormatter({value:V,row:{},field:O.field}):v[O.field]&&(U=_e(V,v[O.field])),String(U)})])})}else y=j.map(v=>u.map(M=>Bn(v,M))),p&&w&&(T=[u.map((M,F)=>{if(F===0)return u.some(U=>w[U.field])?"TOTAL":"";const O=p[M.field];if(O==null)return"";let H=O;return M.valueFormatter?H=M.valueFormatter({value:O,row:{},field:M.field}):w[M.field]&&(H=_e(O,w[M.field])),String(H)})]);const I=Kr(u,k),[A,$,D]=zn(m),[W,z,Y]=zn(x);l(_,{head:L,body:y,...T?{foot:T}:{},startY:P,styles:{fontSize:C,cellPadding:3,font:"helvetica",overflow:"linebreak"},headStyles:{fillColor:[A,$,D],textColor:[W,z,Y],fontStyle:"bold"},...f?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...T?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:I,showFoot:T?"lastPage":"never",showHead:"everyPage",margin:{top:g,left:g,right:g,bottom:g+6}});const K=_.getNumberOfPages();for(let v=1;v<=K;v++)_.setPage(v),_.setFontSize(8),_.setTextColor(150,150,150),_.text(`Page ${v} of ${K}`,S-g,N-8,{align:"right"});_.save(`${s}.pdf`)}function Xr(n,t,e={}){const{fileName:o="export.csv",includeHeaders:l=!0,delimiter:s=",",selectedRows:d,groupedRows:a}=e,c=t.filter(p=>!(p.exportable===!1||p.field==="__check__"||p.field==="__actions__"));let h="";if(a&&a.length>0)l&&(h+=c.map(p=>je(p.headerName||p.field)).join(s)+`
9
9
  `),a.forEach(p=>{if(p.type==="group-header"){const b=`${" ".repeat(p.depth)}${p.groupField??""}: ${String(p.groupValue??"")}`,f=c.map((m,x)=>x===0?je(b):"");h+=f.join(s)+`
10
10
  `}else if(p.type==="leaf"&&p.row){const w=p.row,b=" ".repeat(p.depth),f=c.map((m,x)=>{let C=w[m.field];return m.valueGetter&&(C=m.valueGetter({row:w,field:m.field,value:C})),m.valueFormatter&&C!==void 0&&C!==null&&(C=m.valueFormatter({value:C,row:w,field:m.field})),je((x===0?b:"")+String(C??""))});h+=f.join(s)+`
11
11
  `}else if(p.type==="group-subtotal"&&p.aggregatedValues){const w=" ".repeat(p.depth),b=e.aggregationModel||{},f=c.map((m,x)=>{if(x===0)return je(`${w}Subtotal`);const C=p.aggregatedValues[m.field];if(C!=null){let E=C;return m.valueFormatter?E=m.valueFormatter({value:C,row:{},field:m.field}):b[m.field]&&(E=_e(C,b[m.field])),je(String(E))}return""});h+=f.join(s)+`
@@ -14,8 +14,8 @@ ${p}`;try{await sr(w)}catch(b){console.error("[OpenGridX] Failed to copy to clip
14
14
  `),p.forEach(w=>{const b=c.map(f=>{let m=w[f.field];return f.valueGetter&&(m=f.valueGetter({row:w,field:f.field,value:m})),f.valueFormatter&&m!==void 0&&m!==null&&(m=f.valueFormatter({value:m,row:w,field:f.field})),je(String(m??""))});h+=b.join(s)+`
15
15
  `}),e.aggregationResult){const w=e.aggregationResult,b=e.aggregationModel||{},f=c.map(x=>je(b[x.field]?b[x.field].toUpperCase():""));h+=f.join(s)+`
16
16
  `;const m=c.map(x=>{const C=w[x.field];if(C!=null){let E=C;return x.valueFormatter?E=x.valueFormatter({value:C,row:{},field:x.field}):b[x.field]&&(E=_e(C,b[x.field])),je(String(E))}return""});h+=m.join(s)+`
17
- `}}en(h,o,"text/csv;charset=utf-8;")}function je(n){return n.includes(",")||n.includes('"')||n.includes(`
18
- `)?`"${n.replace(/"/g,'""')}"`:n}function Jr(n,t,e={}){const{fileName:o="export.xls",sheetName:l="Sheet1",includeHeaders:s=!0,selectedRows:d,groupedRows:a}=e,c=t.filter(w=>!(w.exportable===!1||w.field==="__check__"||w.field==="__actions__"));let p=`<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>${l}</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&&(p+="<thead><tr>",c.forEach(w=>{p+=`<th>${we(w.headerName||w.field)}</th>`}),p+="</tr></thead>"),p+="<tbody>",a&&a.length>0){const w=e.aggregationModel||{};a.forEach(b=>{if(b.type==="group-header"){const m=`${"  ".repeat(b.depth*2)}${b.groupField??""}: ${String(b.groupValue??"")}`;p+='<tr style="font-weight:bold;background:#e8eaf6;">',p+=`<td colspan="${c.length}">${we(m)}</td>`,p+="</tr>"}else if(b.type==="leaf"&&b.row){const f=b.row,m="  ".repeat(b.depth*2);p+="<tr>",c.forEach((x,C)=>{let E=f[x.field];x.valueGetter&&(E=x.valueGetter({row:f,field:x.field,value:E})),x.valueFormatter&&E!==void 0&&E!==null&&(E=x.valueFormatter({value:E,row:f,field:x.field})),p+=`<td>${we((C===0?m:"")+String(E??""))}</td>`}),p+="</tr>"}else if((b.type==="group-subtotal"||b.type==="grand-total")&&b.aggregatedValues){const f=b.type==="grand-total",m=f?"":"  ".repeat(b.depth*2),x=f?"Grand Total":`${m}Subtotal`;p+='<tr style="font-weight:bold;background:#f5f5f5;">',c.forEach((C,E)=>{if(E===0){p+=`<td>${we(x)}</td>`;return}const _=b.aggregatedValues[C.field];if(_!=null){let S=_;C.valueFormatter?S=C.valueFormatter({value:_,row:{},field:C.field}):w[C.field]&&(S=_e(_,w[C.field])),p+=`<td style="text-align:right;">${we(String(S))}</td>`}else p+="<td></td>"}),p+="</tr>"}})}else{const w=d&&d.length>0?n.filter(b=>d.includes(b.id)):n;if(w.length===0){console.warn("No rows to export");return}if(w.forEach(b=>{p+="<tr>",c.forEach(f=>{let m=b[f.field];f.valueGetter&&(m=f.valueGetter({row:b,field:f.field,value:m})),f.valueFormatter&&m!==void 0&&m!==null&&(m=f.valueFormatter({value:m,row:b,field:f.field})),p+=`<td>${we(String(m??""))}</td>`}),p+="</tr>"}),e.aggregationResult){const b=e.aggregationResult,f=e.aggregationModel||{};p+='<tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',c.forEach(m=>{p+=f[m.field]?`<td style="text-align:right;font-weight:bold;">${we(f[m.field].toUpperCase())}</td>`:"<td></td>"}),p+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',c.forEach(m=>{const x=b[m.field];if(x!=null){let C=x;m.valueFormatter?C=m.valueFormatter({value:x,row:{},field:m.field}):f[m.field]&&(C=_e(x,f[m.field])),p+=`<td style="text-align:right;">${we(String(C))}</td>`}else p+="<td></td>"}),p+="</tr>"}}p+="</tbody></table></body></html>",en(p,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 Qr(n,t,e={}){const{fileName:o="export.json",pretty:l=!0,selectedRows:s,groupedRows:d}=e,a=t.filter(h=>!(h.exportable===!1||h.field==="__check__"||h.field==="__actions__"));let c;if(d&&d.length>0){const h=[],p=[];let w;d.forEach(b=>{if(b.type==="group-header"){const f={group:`${b.groupField??""}: ${String(b.groupValue??"")}`,field:b.groupField??"",value:b.groupValue,rows:[],children:[]};for(;h.length>b.depth;)h.pop();h.length===0?p.push(f):(h[h.length-1].children??=[]).push(f),h.push(f)}else if(b.type==="leaf"&&b.row){const f=b.row,m={};a.forEach(x=>{let C=f[x.field];x.valueGetter&&(C=x.valueGetter({row:f,field:x.field,value:C})),m[x.field]=C}),h.length>0&&h[h.length-1].rows.push(m)}else b.type==="group-subtotal"&&b.aggregatedValues&&h.length>0?(h[h.length-1].subtotals={...b.aggregatedValues},h.pop()):b.type==="grand-total"&&b.aggregatedValues&&(w={...b.aggregatedValues})}),c=w?{groups:p,grandTotal:w}:{groups:p}}else{const h=s&&s.length>0?n.filter(w=>s.includes(w.id)):n;if(h.length===0){console.warn("No rows to export");return}const p=h.map(w=>{const b={};return a.forEach(f=>{let m=w[f.field];f.valueGetter&&(m=f.valueGetter({row:w,field:f.field,value:m})),b[f.field]=m}),b});if(e.aggregationResult){const w=e.aggregationResult,b=e.aggregationModel||{},f={};a.forEach(x=>{b[x.field]&&(f[x.field]=b[x.field].toUpperCase())});const m={};a.forEach(x=>{if(w[x.field]!==void 0&&w[x.field]!==null){let C=w[x.field];x.valueFormatter?C=x.valueFormatter({value:C,row:{},field:x.field}):b[x.field]&&(C=_e(C,b[x.field])),m[x.field]=C}}),c={data:p,aggregation:{labels:f,values:m}}}else c=p}en(l?JSON.stringify(c,null,2):JSON.stringify(c),o,"application/json;charset=utf-8;")}async function Zr(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(`
17
+ `}}tn(h,o,"text/csv;charset=utf-8;")}function je(n){return n.includes(",")||n.includes('"')||n.includes(`
18
+ `)?`"${n.replace(/"/g,'""')}"`:n}function Jr(n,t,e={}){const{fileName:o="export.xls",sheetName:l="Sheet1",includeHeaders:s=!0,selectedRows:d,groupedRows:a}=e,c=t.filter(w=>!(w.exportable===!1||w.field==="__check__"||w.field==="__actions__"));let p=`<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>${l}</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&&(p+="<thead><tr>",c.forEach(w=>{p+=`<th>${we(w.headerName||w.field)}</th>`}),p+="</tr></thead>"),p+="<tbody>",a&&a.length>0){const w=e.aggregationModel||{};a.forEach(b=>{if(b.type==="group-header"){const m=`${"  ".repeat(b.depth*2)}${b.groupField??""}: ${String(b.groupValue??"")}`;p+='<tr style="font-weight:bold;background:#e8eaf6;">',p+=`<td colspan="${c.length}">${we(m)}</td>`,p+="</tr>"}else if(b.type==="leaf"&&b.row){const f=b.row,m="  ".repeat(b.depth*2);p+="<tr>",c.forEach((x,C)=>{let E=f[x.field];x.valueGetter&&(E=x.valueGetter({row:f,field:x.field,value:E})),x.valueFormatter&&E!==void 0&&E!==null&&(E=x.valueFormatter({value:E,row:f,field:x.field})),p+=`<td>${we((C===0?m:"")+String(E??""))}</td>`}),p+="</tr>"}else if((b.type==="group-subtotal"||b.type==="grand-total")&&b.aggregatedValues){const f=b.type==="grand-total",m=f?"":"  ".repeat(b.depth*2),x=f?"Grand Total":`${m}Subtotal`;p+='<tr style="font-weight:bold;background:#f5f5f5;">',c.forEach((C,E)=>{if(E===0){p+=`<td>${we(x)}</td>`;return}const _=b.aggregatedValues[C.field];if(_!=null){let S=_;C.valueFormatter?S=C.valueFormatter({value:_,row:{},field:C.field}):w[C.field]&&(S=_e(_,w[C.field])),p+=`<td style="text-align:right;">${we(String(S))}</td>`}else p+="<td></td>"}),p+="</tr>"}})}else{const w=d&&d.length>0?n.filter(b=>d.includes(b.id)):n;if(w.length===0){console.warn("No rows to export");return}if(w.forEach(b=>{p+="<tr>",c.forEach(f=>{let m=b[f.field];f.valueGetter&&(m=f.valueGetter({row:b,field:f.field,value:m})),f.valueFormatter&&m!==void 0&&m!==null&&(m=f.valueFormatter({value:m,row:b,field:f.field})),p+=`<td>${we(String(m??""))}</td>`}),p+="</tr>"}),e.aggregationResult){const b=e.aggregationResult,f=e.aggregationModel||{};p+='<tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',c.forEach(m=>{p+=f[m.field]?`<td style="text-align:right;font-weight:bold;">${we(f[m.field].toUpperCase())}</td>`:"<td></td>"}),p+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',c.forEach(m=>{const x=b[m.field];if(x!=null){let C=x;m.valueFormatter?C=m.valueFormatter({value:x,row:{},field:m.field}):f[m.field]&&(C=_e(x,f[m.field])),p+=`<td style="text-align:right;">${we(String(C))}</td>`}else p+="<td></td>"}),p+="</tr>"}}p+="</tbody></table></body></html>",tn(p,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 Qr(n,t,e={}){const{fileName:o="export.json",pretty:l=!0,selectedRows:s,groupedRows:d}=e,a=t.filter(h=>!(h.exportable===!1||h.field==="__check__"||h.field==="__actions__"));let c;if(d&&d.length>0){const h=[],p=[];let w;d.forEach(b=>{if(b.type==="group-header"){const f={group:`${b.groupField??""}: ${String(b.groupValue??"")}`,field:b.groupField??"",value:b.groupValue,rows:[],children:[]};for(;h.length>b.depth;)h.pop();h.length===0?p.push(f):(h[h.length-1].children??=[]).push(f),h.push(f)}else if(b.type==="leaf"&&b.row){const f=b.row,m={};a.forEach(x=>{let C=f[x.field];x.valueGetter&&(C=x.valueGetter({row:f,field:x.field,value:C})),m[x.field]=C}),h.length>0&&h[h.length-1].rows.push(m)}else b.type==="group-subtotal"&&b.aggregatedValues&&h.length>0?(h[h.length-1].subtotals={...b.aggregatedValues},h.pop()):b.type==="grand-total"&&b.aggregatedValues&&(w={...b.aggregatedValues})}),c=w?{groups:p,grandTotal:w}:{groups:p}}else{const h=s&&s.length>0?n.filter(w=>s.includes(w.id)):n;if(h.length===0){console.warn("No rows to export");return}const p=h.map(w=>{const b={};return a.forEach(f=>{let m=w[f.field];f.valueGetter&&(m=f.valueGetter({row:w,field:f.field,value:m})),b[f.field]=m}),b});if(e.aggregationResult){const w=e.aggregationResult,b=e.aggregationModel||{},f={};a.forEach(x=>{b[x.field]&&(f[x.field]=b[x.field].toUpperCase())});const m={};a.forEach(x=>{if(w[x.field]!==void 0&&w[x.field]!==null){let C=w[x.field];x.valueFormatter?C=x.valueFormatter({value:C,row:{},field:x.field}):b[x.field]&&(C=_e(C,b[x.field])),m[x.field]=C}}),c={data:p,aggregation:{labels:f,values:m}}}else c=p}tn(l?JSON.stringify(c,null,2):JSON.stringify(c),o,"application/json;charset=utf-8;")}async function Zr(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(`
19
19
  <!DOCTYPE html>
20
20
  <html>
21
21
  <head>
@@ -46,5 +46,5 @@ ${p}`;try{await sr(w)}catch(b){console.error("[OpenGridX] Failed to copy to clip
46
46
  .group-subtotal{background:#f0f4ff;font-style:italic;}
47
47
  .grand-total{background:#f5f5f5;font-weight:bold;}
48
48
  @media print{body{margin:0;}@page{margin:1cm;}}
49
- </style></head><body>`;if(l&&(p+=`<h1>${we(l)}</h1>`),p+="<table><thead><tr>",h.forEach(b=>{p+=`<th>${we(b.headerName||b.field)}</th>`}),p+="</tr></thead><tbody>",c&&c.length>0){const b=a||{};c.forEach(f=>{if(f.type==="group-header"){const x=`${"&nbsp;".repeat(f.depth*4)}${we(f.groupField??"")}: ${we(String(f.groupValue??""))}`;p+=`<tr class="group-header"><td colspan="${h.length}">${x}</td></tr>`}else if(f.type==="leaf"&&f.row){const m=f.row,x="&nbsp;".repeat(f.depth*4);p+="<tr>",h.forEach((C,E)=>{let _=m[C.field];C.valueGetter&&(_=C.valueGetter({row:m,field:C.field,value:_})),C.valueFormatter&&_!==void 0&&_!==null&&(_=C.valueFormatter({value:_,row:m,field:C.field})),C.type==="image"&&_?p+=`<td><img src="${_}" style="max-height:40px;border-radius:4px;"></td>`:p+=`<td>${(E===0?x:"")+we(String(_??""))}</td>`}),p+="</tr>"}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const m=f.type==="grand-total",x=m?"":"&nbsp;".repeat(f.depth*4),C=m?"Grand Total":`${x}Subtotal`;p+=`<tr class="${m?"grand-total":"group-subtotal"}">`,h.forEach((_,S)=>{if(S===0){p+=`<td>${C}</td>`;return}const N=f.aggregatedValues[_.field];if(N!=null){let g=N;_.valueFormatter?g=_.valueFormatter({value:N,row:{},field:_.field}):b[_.field]&&(g=_e(N,b[_.field])),p+=`<td style="text-align:right;">${we(String(g))}</td>`}else p+="<td></td>"}),p+="</tr>"}})}else{const b=s&&s.length>0?n.filter(f=>s.includes(f.id)):n;if(b.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}if(b.forEach(f=>{p+="<tr>",h.forEach(m=>{let x=f[m.field];m.valueGetter&&(x=m.valueGetter({row:f,field:m.field,value:x})),m.valueFormatter&&x!==void 0&&x!==null&&(x=m.valueFormatter({value:x,row:f,field:m.field})),m.type==="image"&&x?p+=`<td><div style="display:flex;justify-content:center;"><img src="${x}" alt="${m.headerName}" style="max-height:40px;border-radius:4px;"></div></td>`:p+=`<td>${we(String(x??""))}</td>`}),p+="</tr>"}),d){const f=a||{};p+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',h.forEach(m=>{p+=f[m.field]?`<td style="text-align:right;font-weight:bold;">${we(f[m.field].toUpperCase())}</td>`:"<td></td>"}),p+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',h.forEach(m=>{const x=d[m.field];if(x!=null){let C=x;m.valueFormatter?C=m.valueFormatter({value:x,row:{},field:m.field}):f[m.field]&&(C=_e(x,f[m.field])),p+=`<td style="text-align:right;">${we(String(C))}</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=l||"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(l){if(console.error("Print generation failed:",l),o&&!o.closed){const s=l instanceof Error?l.message:String(l);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${s}</p></div>`}}}function en(n,t,e){const o=new Blob([n],{type:e}),l=URL.createObjectURL(o),s=document.createElement("a");s.href=l,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(l)}function ei(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 ti(n){if(n.type==="number")return"#,##0.##";if(n.type==="date")return"yyyy-mm-dd"}function ni(n,t){if(t!=null)return t;const e=n.width??120;return Math.min(60,Math.max(8,(e-5)/7))}function oi(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 ri(n){const t=await Promise.allSettled(n.map(async o=>{if(o.startsWith("data:")){const a=o.indexOf(","),c=o.slice(0,a),h=o.slice(a+1),p=atob(h),w=new Uint8Array(p.length);for(let x=0;x<p.length;x++)w[x]=p.charCodeAt(x);const f=c.match(/data:([^;,]+)/)?.[1]??"image/png";let m="png";return f.includes("jpeg")||f.includes("jpg")?m="jpeg":f.includes("gif")&&(m="gif"),{url:o,buffer:w.buffer,ext:m}}const l=await fetch(o,{mode:"cors"});if(!l.ok)throw new Error(`HTTP ${l.status}`);const s=await l.arrayBuffer(),d=oi(o,l.headers.get("content-type"));return{url:o,buffer:s,ext:d}})),e=new Map;return t.forEach((o,l)=>{o.status==="fulfilled"?e.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${n[l]}" (CORS/network error — raw URL written as fallback):`,o.reason)}),e}async function ii(n,t,e={}){const{fileName:o="export.xlsx",sheets:l,columnStyles:s={},headerFillColor:d="#f1f5f9",headerTextColor:a="#334155",headerFontSize:c=10,bodyFontSize:h=10,aggregationResult:p=null,aggregationModel:w=null,selectedRows:b}=e,f=(await import("exceljs")).default,m=new f.Workbook;m.creator="OpenGridX",m.created=new Date;const x=t.filter(j=>j.exportable!==!1&&j.field!=="__check__"&&j.field!=="__actions__"&&!j.isSpacer),C=n,E=b&&b.length>0?n.filter(j=>b.includes(j.id)):n,_=l??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],S=new Map;for(const j of _){if("type"in j&&j.type==="summary"){if(!p||!w)continue;const v=m.addWorksheet(j.name??"Summary");v.addRow(["Summary / Aggregation Totals"]),v.getRow(1).font={bold:!0,size:c+2,color:{argb:$e(a)}},v.addRow([]),v.addRow(["Column","Function","Value"]).eachCell(F=>{F.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(d)}},F.font={bold:!0,size:c,color:{argb:$e(a)}},F.border=Bn()}),x.forEach(F=>{const O=w[F.field],H=p[F.field];if(O==null||H==null)return;let K=H;F.valueFormatter?K=F.valueFormatter({value:H,row:{},field:F.field}):K=_e(H,O);const V=v.addRow([F.headerName??F.field,O.toUpperCase(),K]);V.getCell(3).alignment={horizontal:"right"},V.getCell(3).font={bold:!0,size:h}}),v.getColumn(1).width=20,v.getColumn(2).width=12,v.getColumn(3).width=18;continue}const P=j,{name:L="Data",rows:y="all",includeHeaders:T=!0,includeSummary:I=!1,autoFilter:A=!0,frozenHeader:$=!0,alternateRowColor:D="#f8fafc"}=P,W=y==="selected"?E:C,z=x.filter(v=>s[v.field]?.embedImage);if(z.length>0){const v=[],M=new Set;if(W.forEach(F=>{z.forEach(O=>{const H=F[O.field];typeof H=="string"&&H&&!S.has(H)&&!M.has(H)&&(v.push(H),M.add(H))})}),v.length>0){const F=await ri(v);for(const[O,{buffer:H,extension:K}]of F){const V=m.addImage({buffer:H,extension:K});S.set(O,V)}}}const Y=m.addWorksheet(L);if(Y.columns=x.map(v=>({key:v.field,width:ni(v,s[v.field]?.width),style:{numFmt:s[v.field]?.numFmt??ti(v)}})),T){const v=x.map(F=>F.headerName??F.field),M=Y.addRow(v);M.height=20,M.eachCell((F,O)=>{const H=x[O-1];F.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(d)}},F.font={bold:!0,size:c,color:{argb:$e(a)}},F.alignment={horizontal:s[H?.field]?.alignment??(H?.type==="number"?"right":"left"),vertical:"middle"},F.border=Bn()}),A&&(Y.autoFilter={from:{row:1,column:1},to:{row:1,column:x.length}}),$?Y.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:Y.views=[{showGridLines:!1}]}let U=T?1:0;if(W.forEach((v,M)=>{const F=x.map(H=>{if(s[H.field]?.embedImage)return"";let K=v[H.field];return H.valueGetter&&(K=H.valueGetter({row:v,field:H.field,value:K})),ei(H,K)==="string"&&H.valueFormatter&&K!=null&&(K=H.valueFormatter({value:K,row:v,field:H.field})),K}),O=Y.addRow(F);if(O.font={size:h},D&&M%2===1&&O.eachCell(H=>{H.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(D)}}}),O.eachCell((H,K)=>{const V=x[K-1];V&&(H.alignment={horizontal:s[V.field]?.alignment??(V.type==="number"?"right":"left"),vertical:"middle"},H.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}})}),z.length>0){const H=z.reduce((oe,ie)=>Math.max(oe,s[ie.field]?.imageHeight??40),0),K=Math.ceil(H/1.333),V=K*1.333;O.height=K,z.forEach(oe=>{const ie=x.indexOf(oe),ne=v[oe.field],R=typeof ne=="string"?S.get(ne):void 0;if(R===void 0){O.getCell(ie+1).value=typeof ne=="string"?ne:"";return}const le=s[oe.field],te=le?.imageWidth??40,re=le?.imageHeight??40,J=(Y.getColumn(ie+1).width??8)*7+5,de=Math.max(0,J-te)/2,B=Math.max(0,V-re)/2;Y.addImage(R,{tl:{col:ie,row:U,nativeColOff:Math.floor(de*9525),nativeRowOff:Math.floor(B*9525)},ext:{width:te,height:re},editAs:"oneCell"})})}else O.height=16;U++}),I&&p&&w){const v=x.map(H=>{const K=w[H.field];return K?K.toUpperCase():""}),M=Y.addRow(v);M.height=16,M.font={size:h-1,italic:!0,color:{argb:"FF94a3b8"}},M.eachCell(H=>{H.alignment={horizontal:"right",vertical:"middle"},H.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const F=x.map(H=>{const K=w[H.field],V=p[H.field];return K==null||V==null?"":H.valueFormatter?H.valueFormatter({value:V,row:{},field:H.field}):_e(V,K)}),O=Y.addRow(F);O.height=18,O.font={bold:!0,size:h,color:{argb:$e(a)}},O.eachCell(H=>{H.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(d)}},H.alignment={horizontal:"right",vertical:"middle"},H.border=li()})}}const N=await m.xlsx.writeBuffer(),g=new Blob([N],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),k=URL.createObjectURL(g),u=document.createElement("a");u.href=k,u.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(k)}function $e(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 Bn(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function li(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}const si={"--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 ai(n){const t={};function e(o,l){l!==void 0&&(t[o]=l)}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 di({theme:n,children:t,className:e,style:o}){const l=i.useMemo(()=>({...si,...ai(n)}),[n]);return r.jsx("div",{className:`ogx-theme-provider ${e||""}`.trim(),style:{...o,...l},children:t})}const ci={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"}},ui={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"}},fi={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"}},gi={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"}},hi={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function pi(n,t){try{const e=t.getItem(n);return e?JSON.parse(e):void 0}catch{return}}function xi(n,t,e,o){try{const l=e?Object.fromEntries(Object.entries(t).filter(([s])=>e.includes(s))):t;o.setItem(n,JSON.stringify(l))}catch{}}function mi(n){const t=typeof n=="string"?{key:n}:n,{key:e,debounceMs:o=300,include:l,storage:s=typeof window<"u"?window.localStorage:void 0}=t,d=i.useMemo(()=>{if(s)return pi(e,s)},[e,s]),a=i.useRef(null),c=i.useRef(null),h=i.useCallback(()=>{c.current&&s&&xi(e,c.current,l,s)},[e,l,s]),p=i.useCallback(b=>{c.current=b,a.current&&clearTimeout(a.current),a.current=setTimeout(h,o)},[h,o]);i.useEffect(()=>()=>{a.current&&(clearTimeout(a.current),h())},[h]);const w=i.useCallback(()=>{s&&s.removeItem(e)},[e,s]);return{initialState:d,onStateChange:p,clearState:w}}ae.Button=mt,ae.Cell=Pn,ae.Checkbox=xt,ae.DataGrid=Nr,ae.DataGridThemeProvider=di,ae.FilterPanel=Ln,ae.GridToolbar=Dr,ae.GridTooltip=wt,ae.Header=jn,ae.Input=Vr,ae.Row=Ft,ae.Skeleton=Mr,ae.amberTheme=gi,ae.compactTheme=hi,ae.darkTheme=ci,ae.emeraldTheme=fi,ae.exportToCsv=Xr,ae.exportToExcel=Jr,ae.exportToExcelAdvanced=ii,ae.exportToJson=Qr,ae.exportToPdf=qr,ae.formatAggregationValue=_e,ae.printGrid=Zr,ae.roseTheme=ui,ae.useAggregation=kn,ae.useGridApiRef=Gr,ae.useGridStateStorage=mi,ae.usePivot=Mn,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"})}));
49
+ </style></head><body>`;if(l&&(p+=`<h1>${we(l)}</h1>`),p+="<table><thead><tr>",h.forEach(b=>{p+=`<th>${we(b.headerName||b.field)}</th>`}),p+="</tr></thead><tbody>",c&&c.length>0){const b=a||{};c.forEach(f=>{if(f.type==="group-header"){const x=`${"&nbsp;".repeat(f.depth*4)}${we(f.groupField??"")}: ${we(String(f.groupValue??""))}`;p+=`<tr class="group-header"><td colspan="${h.length}">${x}</td></tr>`}else if(f.type==="leaf"&&f.row){const m=f.row,x="&nbsp;".repeat(f.depth*4);p+="<tr>",h.forEach((C,E)=>{let _=m[C.field];C.valueGetter&&(_=C.valueGetter({row:m,field:C.field,value:_})),C.valueFormatter&&_!==void 0&&_!==null&&(_=C.valueFormatter({value:_,row:m,field:C.field})),C.type==="image"&&_?p+=`<td><img src="${_}" style="max-height:40px;border-radius:4px;"></td>`:p+=`<td>${(E===0?x:"")+we(String(_??""))}</td>`}),p+="</tr>"}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const m=f.type==="grand-total",x=m?"":"&nbsp;".repeat(f.depth*4),C=m?"Grand Total":`${x}Subtotal`;p+=`<tr class="${m?"grand-total":"group-subtotal"}">`,h.forEach((_,S)=>{if(S===0){p+=`<td>${C}</td>`;return}const N=f.aggregatedValues[_.field];if(N!=null){let g=N;_.valueFormatter?g=_.valueFormatter({value:N,row:{},field:_.field}):b[_.field]&&(g=_e(N,b[_.field])),p+=`<td style="text-align:right;">${we(String(g))}</td>`}else p+="<td></td>"}),p+="</tr>"}})}else{const b=s&&s.length>0?n.filter(f=>s.includes(f.id)):n;if(b.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}if(b.forEach(f=>{p+="<tr>",h.forEach(m=>{let x=f[m.field];m.valueGetter&&(x=m.valueGetter({row:f,field:m.field,value:x})),m.valueFormatter&&x!==void 0&&x!==null&&(x=m.valueFormatter({value:x,row:f,field:m.field})),m.type==="image"&&x?p+=`<td><div style="display:flex;justify-content:center;"><img src="${x}" alt="${m.headerName}" style="max-height:40px;border-radius:4px;"></div></td>`:p+=`<td>${we(String(x??""))}</td>`}),p+="</tr>"}),d){const f=a||{};p+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',h.forEach(m=>{p+=f[m.field]?`<td style="text-align:right;font-weight:bold;">${we(f[m.field].toUpperCase())}</td>`:"<td></td>"}),p+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',h.forEach(m=>{const x=d[m.field];if(x!=null){let C=x;m.valueFormatter?C=m.valueFormatter({value:x,row:{},field:m.field}):f[m.field]&&(C=_e(x,f[m.field])),p+=`<td style="text-align:right;">${we(String(C))}</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=l||"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(l){if(console.error("Print generation failed:",l),o&&!o.closed){const s=l instanceof Error?l.message:String(l);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${s}</p></div>`}}}function tn(n,t,e){const o=new Blob([n],{type:e}),l=URL.createObjectURL(o),s=document.createElement("a");s.href=l,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(l)}function ei(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 ti(n){if(n.type==="number")return"#,##0.##";if(n.type==="date")return"yyyy-mm-dd"}function ni(n,t){if(t!=null)return t;const e=n.width??120;return Math.min(60,Math.max(8,(e-5)/7))}function oi(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 ri(n){const t=await Promise.allSettled(n.map(async o=>{if(o.startsWith("data:")){const a=o.indexOf(","),c=o.slice(0,a),h=o.slice(a+1),p=atob(h),w=new Uint8Array(p.length);for(let x=0;x<p.length;x++)w[x]=p.charCodeAt(x);const f=c.match(/data:([^;,]+)/)?.[1]??"image/png";let m="png";return f.includes("jpeg")||f.includes("jpg")?m="jpeg":f.includes("gif")&&(m="gif"),{url:o,buffer:w.buffer,ext:m}}const l=await fetch(o,{mode:"cors"});if(!l.ok)throw new Error(`HTTP ${l.status}`);const s=await l.arrayBuffer(),d=oi(o,l.headers.get("content-type"));return{url:o,buffer:s,ext:d}})),e=new Map;return t.forEach((o,l)=>{o.status==="fulfilled"?e.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${n[l]}" (CORS/network error — raw URL written as fallback):`,o.reason)}),e}async function ii(n,t,e={}){const{fileName:o="export.xlsx",sheets:l,columnStyles:s={},headerFillColor:d="#f1f5f9",headerTextColor:a="#334155",headerFontSize:c=10,bodyFontSize:h=10,aggregationResult:p=null,aggregationModel:w=null,selectedRows:b}=e,f=(await import("exceljs")).default,m=new f.Workbook;m.creator="OpenGridX",m.created=new Date;const x=t.filter(j=>j.exportable!==!1&&j.field!=="__check__"&&j.field!=="__actions__"&&!j.isSpacer),C=n,E=b&&b.length>0?n.filter(j=>b.includes(j.id)):n,_=l??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],S=new Map;for(const j of _){if("type"in j&&j.type==="summary"){if(!p||!w)continue;const v=m.addWorksheet(j.name??"Summary");v.addRow(["Summary / Aggregation Totals"]),v.getRow(1).font={bold:!0,size:c+2,color:{argb:$e(a)}},v.addRow([]),v.addRow(["Column","Function","Value"]).eachCell(F=>{F.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(d)}},F.font={bold:!0,size:c,color:{argb:$e(a)}},F.border=Dn()}),x.forEach(F=>{const O=w[F.field],H=p[F.field];if(O==null||H==null)return;let V=H;F.valueFormatter?V=F.valueFormatter({value:H,row:{},field:F.field}):V=_e(H,O);const U=v.addRow([F.headerName??F.field,O.toUpperCase(),V]);U.getCell(3).alignment={horizontal:"right"},U.getCell(3).font={bold:!0,size:h}}),v.getColumn(1).width=20,v.getColumn(2).width=12,v.getColumn(3).width=18;continue}const P=j,{name:L="Data",rows:y="all",includeHeaders:T=!0,includeSummary:I=!1,autoFilter:A=!0,frozenHeader:$=!0,alternateRowColor:D="#f8fafc"}=P,W=y==="selected"?E:C,z=x.filter(v=>s[v.field]?.embedImage);if(z.length>0){const v=[],M=new Set;if(W.forEach(F=>{z.forEach(O=>{const H=F[O.field];typeof H=="string"&&H&&!S.has(H)&&!M.has(H)&&(v.push(H),M.add(H))})}),v.length>0){const F=await ri(v);for(const[O,{buffer:H,extension:V}]of F){const U=m.addImage({buffer:H,extension:V});S.set(O,U)}}}const Y=m.addWorksheet(L);if(Y.columns=x.map(v=>({key:v.field,width:ni(v,s[v.field]?.width),style:{numFmt:s[v.field]?.numFmt??ti(v)}})),T){const v=x.map(F=>F.headerName??F.field),M=Y.addRow(v);M.height=20,M.eachCell((F,O)=>{const H=x[O-1];F.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(d)}},F.font={bold:!0,size:c,color:{argb:$e(a)}},F.alignment={horizontal:s[H?.field]?.alignment??(H?.type==="number"?"right":"left"),vertical:"middle"},F.border=Dn()}),A&&(Y.autoFilter={from:{row:1,column:1},to:{row:1,column:x.length}}),$?Y.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:Y.views=[{showGridLines:!1}]}let K=T?1:0;if(W.forEach((v,M)=>{const F=x.map(H=>{if(s[H.field]?.embedImage)return"";let V=v[H.field];return H.valueGetter&&(V=H.valueGetter({row:v,field:H.field,value:V})),ei(H,V)==="string"&&H.valueFormatter&&V!=null&&(V=H.valueFormatter({value:V,row:v,field:H.field})),V}),O=Y.addRow(F);if(O.font={size:h},D&&M%2===1&&O.eachCell(H=>{H.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(D)}}}),O.eachCell((H,V)=>{const U=x[V-1];U&&(H.alignment={horizontal:s[U.field]?.alignment??(U.type==="number"?"right":"left"),vertical:"middle"},H.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}})}),z.length>0){const H=z.reduce((oe,ie)=>Math.max(oe,s[ie.field]?.imageHeight??40),0),V=Math.ceil(H/1.333),U=V*1.333;O.height=V,z.forEach(oe=>{const ie=x.indexOf(oe),ne=v[oe.field],R=typeof ne=="string"?S.get(ne):void 0;if(R===void 0){O.getCell(ie+1).value=typeof ne=="string"?ne:"";return}const le=s[oe.field],te=le?.imageWidth??40,re=le?.imageHeight??40,J=(Y.getColumn(ie+1).width??8)*7+5,de=Math.max(0,J-te)/2,B=Math.max(0,U-re)/2;Y.addImage(R,{tl:{col:ie,row:K,nativeColOff:Math.floor(de*9525),nativeRowOff:Math.floor(B*9525)},ext:{width:te,height:re},editAs:"oneCell"})})}else O.height=16;K++}),I&&p&&w){const v=x.map(H=>{const V=w[H.field];return V?V.toUpperCase():""}),M=Y.addRow(v);M.height=16,M.font={size:h-1,italic:!0,color:{argb:"FF94a3b8"}},M.eachCell(H=>{H.alignment={horizontal:"right",vertical:"middle"},H.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const F=x.map(H=>{const V=w[H.field],U=p[H.field];return V==null||U==null?"":H.valueFormatter?H.valueFormatter({value:U,row:{},field:H.field}):_e(U,V)}),O=Y.addRow(F);O.height=18,O.font={bold:!0,size:h,color:{argb:$e(a)}},O.eachCell(H=>{H.fill={type:"pattern",pattern:"solid",fgColor:{argb:$e(d)}},H.alignment={horizontal:"right",vertical:"middle"},H.border=li()})}}const N=await m.xlsx.writeBuffer(),g=new Blob([N],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),k=URL.createObjectURL(g),u=document.createElement("a");u.href=k,u.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(k)}function $e(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 Dn(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function li(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}const si={"--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 ai(n){const t={};function e(o,l){l!==void 0&&(t[o]=l)}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 di({theme:n,children:t,className:e,style:o}){const l=i.useMemo(()=>({...si,...ai(n)}),[n]);return r.jsx("div",{className:`ogx-theme-provider ${e||""}`.trim(),style:{...o,...l},children:t})}const ci={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"}},ui={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"}},fi={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"}},gi={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"}},hi={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function pi(n,t){try{const e=t.getItem(n);return e?JSON.parse(e):void 0}catch{return}}function xi(n,t,e,o){try{const l=e?Object.fromEntries(Object.entries(t).filter(([s])=>e.includes(s))):t;o.setItem(n,JSON.stringify(l))}catch{}}function mi(n){const t=typeof n=="string"?{key:n}:n,{key:e,debounceMs:o=300,include:l,storage:s=typeof window<"u"?window.localStorage:void 0}=t,d=i.useMemo(()=>{if(s)return pi(e,s)},[e,s]),a=i.useRef(null),c=i.useRef(null),h=i.useCallback(()=>{c.current&&s&&xi(e,c.current,l,s)},[e,l,s]),p=i.useCallback(b=>{c.current=b,a.current&&clearTimeout(a.current),a.current=setTimeout(h,o)},[h,o]);i.useEffect(()=>()=>{a.current&&(clearTimeout(a.current),h())},[h]);const w=i.useCallback(()=>{s&&s.removeItem(e)},[e,s]);return{initialState:d,onStateChange:p,clearState:w}}ae.Button=bt,ae.Cell=Tn,ae.Checkbox=mt,ae.DataGrid=Nr,ae.DataGridThemeProvider=di,ae.FilterPanel=On,ae.GridToolbar=Dr,ae.GridTooltip=vt,ae.Header=Nn,ae.Input=Vr,ae.Row=Ft,ae.Skeleton=Mr,ae.amberTheme=gi,ae.compactTheme=hi,ae.darkTheme=ci,ae.emeraldTheme=fi,ae.exportToCsv=Xr,ae.exportToExcel=Jr,ae.exportToExcelAdvanced=ii,ae.exportToJson=Qr,ae.exportToPdf=qr,ae.formatAggregationValue=_e,ae.printGrid=Zr,ae.roseTheme=ui,ae.useAggregation=jn,ae.useGridApiRef=Gr,ae.useGridStateStorage=mi,ae.usePivot=In,Object.defineProperty(ae,Symbol.toStringTag,{value:"Module"})}));
50
50
  //# sourceMappingURL=opengridx.umd.js.map