@opencorestack/opengridx 3.7.1 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.es.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/opengridx.css +1 -1
- package/dist/opengridx.es.js +6043 -5979
- package/dist/opengridx.es.js.map +1 -1
- package/dist/opengridx.umd.js +16 -16
- package/dist/opengridx.umd.js.map +1 -1
- package/docs/API_REFERENCE.md +28 -0
- package/docs/features/filtering.md +2 -0
- package/lib/components/AiAssistant/GridAiAssistantPanel.css +2 -2
- package/lib/components/Cell/Cell.css +1 -3
- package/lib/components/ColumnGroupHeader/ColumnGroupHeader.css +1 -2
- package/lib/components/DataGrid/DataGrid.css +1 -28
- package/lib/components/DataGrid/DataGrid.tsx +2 -4
- package/lib/components/DataGrid/GridListView.tsx +1 -1
- package/lib/components/DataGrid/GridPinnedRows.tsx +1 -1
- package/lib/components/DataGrid/GridVirtualRows.tsx +3 -2
- package/lib/components/FilterPanel/FilterPanel.tsx +7 -39
- package/lib/components/Header/Header.css +2 -11
- package/lib/components/HeaderFilter/HeaderFilterCell.tsx +6 -37
- package/lib/components/ListView/ListView.css +0 -16
- package/lib/components/Row/Row.tsx +4 -1
- package/lib/hooks/core/useDataGrid.ts +40 -35
- package/lib/hooks/core/useGridAggregationApi.ts +1 -1
- package/lib/hooks/core/useGridCellSelection.ts +3 -4
- package/lib/hooks/core/useGridClipboardPaste.ts +1 -1
- package/lib/hooks/core/useGridDetailPanel.ts +1 -1
- package/lib/hooks/core/useGridFillHandle.ts +1 -1
- package/lib/hooks/core/useGridHierarchy.ts +2 -2
- package/lib/hooks/core/useGridKeyboardNavigation.ts +1 -1
- package/lib/hooks/core/useGridLiveRowSelection.ts +9 -2
- package/lib/hooks/core/useGridRangeEditing.ts +1 -1
- package/lib/hooks/core/useGridRowInteractions.ts +3 -2
- package/lib/hooks/features/useGridSpanning.ts +4 -4
- package/lib/hooks/useRowGrouping.ts +19 -10
- package/lib/hooks/useRowReorder.ts +9 -3
- package/lib/styles/base/reset.css +6 -7
- package/lib/theme/__baseline__/default-theme.darwin.chromium.json +1 -1503
- package/lib/theme/__baseline__/default-theme.darwin.firefox.json +1 -1503
- package/lib/theme/__baseline__/default-theme.darwin.webkit.json +1 -1503
- package/lib/types/rows.ts +0 -2
- package/lib/types/state.ts +9 -0
- package/lib/utils/cellSelection.ts +0 -2
- package/lib/utils/editing/index.ts +1 -1
- package/lib/utils/editing/targets.ts +2 -3
- package/lib/utils/filtering/filterInput.ts +45 -0
- package/lib/utils/filtering/index.ts +0 -28
- package/lib/utils/gridApiRows.ts +1 -1
- package/lib/utils/grouping/groupedExportRows.ts +1 -1
- package/lib/utils/grouping/layeredMap.ts +52 -0
- package/lib/utils/pinning/index.ts +0 -107
- package/lib/utils/rowIndex.ts +67 -0
- package/lib/utils/sorting/index.ts +42 -33
- package/lib/utils/values.ts +5 -1
- package/llms.txt +7 -3
- package/package.json +1 -1
- package/lib/theme/defaultStyles.ts +0 -0
package/dist/opengridx.umd.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
(function(_e,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],d):(_e=typeof globalThis<"u"?globalThis:_e||self,d(_e.OpenGridX={},_e.ReactJSXRuntime,_e.React,_e.ReactDOM))})(this,(function(_e,d,s,st){"use strict";"use client";function so(e,t,n){return Math.max(t??0,Math.min(n??1/0,e))}function yt(e,t,n=100){if(e.isSpacer)return typeof e.width=="number"?e.width:0;const o=t[e.field]??e.width,r=typeof o=="number"&&Number.isFinite(o)?o:n;return so(r,e.minWidth,e.maxWidth)}const He=48;function tt(e,t){return t?t.left?.includes(e)?"left":t.right?.includes(e)?"right":null:null}function ca(e,t){const n=[],o=[],r=[];return t?(e.forEach(i=>{const l=tt(i.field,t);l==="left"?n.push(i):l==="right"?r.push(i):o.push(i)}),t.left&&n.sort((i,l)=>{const a=t.left.indexOf(i.field),c=t.left.indexOf(l.field);return a-c}),t.right&&r.sort((i,l)=>{const a=t.right.indexOf(i.field),c=t.right.indexOf(l.field);return a-c}),{left:n,center:o,right:r}):{left:n,center:e,right:r}}function ao(e,t,n,o,r,i,l,a){const c={};if(!n)return c;let u=(a?He:0)+(i&&l?He:0)+(o&&r?He:0);const g=[];e.forEach(x=>{if(x.isSpacer)return;const y=tt(x.field,n);y==="left"?(c[x.field]=u,u+=yt(x,t)):y==="right"&&g.push(x)});let m=0;for(let x=g.length-1;x>=0;x--)c[g[x].field]=m,m+=yt(g[x],t);return c}function co(e,t){let n=null,o=null;if(!t)return{lastLeft:n,firstRight:o};for(const r of e){if(r.isSpacer)continue;const i=tt(r.field,t);i==="left"?n=r.field:i==="right"&&o===null&&(o=r.field)}return{lastLeft:n,firstRight:o}}function Dr(e,t){return t?t.top?.includes(e)?"top":t.bottom?.includes(e)?"bottom":null:null}function da(e,t,n=o=>o.id){const o=[],r=[],i=[];return t?(e.forEach(l=>{const a=Dr(n(l),t);a==="top"?o.push(l):a==="bottom"?i.push(l):r.push(l)}),t.top&&o.sort((l,a)=>{const c=t.top.indexOf(n(l)),u=t.top.indexOf(n(a));return c-u}),t.bottom&&i.sort((l,a)=>{const c=t.bottom.indexOf(n(l)),u=t.bottom.indexOf(n(a));return c-u}),{top:o,center:r,bottom:i}):{top:o,center:e,bottom:i}}function ua(e,t,n){const o=(e?.left??[]).filter(i=>i!==t),r=(e?.right??[]).filter(i=>i!==t);return n==="left"?{left:[...o,t],right:r}:n==="right"?{left:o,right:[...r,t]}:{left:o,right:r}}const $r=new Set;function Ct(e,t,n){process.env.NODE_ENV==="production"||$r.has(e)||($r.add(e),console.warn(`[OpenGridX] ${t}.`,n))}function uo(e,t,n,o){try{return e()}catch(r){return Ct(n,o,r),t}}function Gr(e,t,n){const o=e[t];if(!n?.valueGetter)return{value:o};try{return{value:n.valueGetter({row:e,field:t,value:o})}}catch(r){return{value:void 0,error:r??new Error("valueGetter failed")}}}function Me(e,t,n){if(!n?.valueGetter)return e[t];const{value:o,error:r}=Gr(e,t,n);return r!==void 0&&Ct(`valueGetter:${t}`,`valueGetter for column "${t}" threw; the value is read as undefined`,r),o}function fo(e,t,n,o){const r=o?.valueFormatter;if(r)try{return r({value:n,row:e,field:t})}catch(i){Ct(`valueFormatter:${t}`,`valueFormatter for column "${t}" threw; the value is shown unformatted`,i);return}}function nt(e){if(e==null)return null;if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e=="string"){const t=e.trim();if(t==="")return null;const n=Number(t);return Number.isNaN(n)?null:n}if(typeof e=="boolean")return null;if(e instanceof Date){const t=e.getTime();return Number.isNaN(t)?null:t}return typeof e=="bigint"?Number(e):null}const fa=/^(\d{4})-(\d{2})-(\d{2})$/;function Qt(e){if(e==null)return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else if(typeof e=="string"){const n=e.trim();if(n==="")return null;const o=fa.exec(n);if(o){const r=Number(o[1]),i=Number(o[2])-1,l=Number(o[3]);if(t=new Date(r,i,l),t.getMonth()!==i||t.getDate()!==l)return null}else{if(!ma(n))return null;t=new Date(n)}}else return null;return Number.isNaN(t.getTime())?null:t}const ga=["january","february","march","april","may","june","july","august","september","october","november","december","monday","tuesday","wednesday","thursday","friday","saturday","sunday"],pa=new Set(["t","z","am","pm","gmt","utc","sept"]);function ha(e){return pa.has(e)?!0:e.length>=3&&ga.some(t=>t.startsWith(e))}function ma(e){let t="";for(let n=0;n<=e.length;n++){const o=n<e.length?e[n].toLowerCase():"";if(o>="a"&&o<="z"){t+=o;continue}if(t!==""&&!ha(t))return!1;t=""}return!0}function kn(e){const t=Qt(e);return t?t.getFullYear()*1e4+(t.getMonth()+1)*100+t.getDate():null}function Hr(e){const t=Qt(e);if(!t)return"";const n=String(t.getFullYear()).padStart(4,"0"),o=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${n}-${o}-${r}`}let Br=null;function Wr(e){return Br??=new Intl.DateTimeFormat,Br.format(e)}function wa(e,t){if(!e)return;const n=i=>typeof i=="object"?i.value:i,o=i=>typeof i=="object"?i.label:String(i),r=e.find(i=>Object.is(n(i),t))??e.find(i=>String(n(i))===String(t));return r===void 0?void 0:o(r)}function En(e,t){if(e==null)return"";switch(t?.type){case"date":{const n=Qt(e);return n?Wr(n):String(e)}case"boolean":return e===!0?"Yes":e===!1?"No":String(e);case"singleSelect":return wa(t.valueOptions,e)??String(e);default:return String(e)}}const go=200;function po(e){if(e==="auto")return"auto";const t=typeof e=="string"?Number.parseFloat(e):e;return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:go}function ho(e,t){if(e)return uo(()=>e(t),void 0,"getDetailPanelHeight","getDetailPanelHeight threw; the panel uses the default height")}function ba(e,t){const n=po(e);return n==="auto"?t??go:n}function xa(e,t){if(t.size===0||e.size===0)return e;let n=!1;const o=new Set;for(const r of e)t.get(r)?.isGroupRow?n=!0:o.add(r);return n?o:e}const ya=e=>e.id;function Ca(e){if(e===void 0)return{type:"auto",value:0};if(typeof e=="number")return{type:"fixed",value:e};if(typeof e=="string"){if(e.toLowerCase()==="auto")return{type:"auto",value:0};if(e.endsWith("%"))return{type:"percentage",value:parseFloat(e)};const t=parseFloat(e);if(!isNaN(t))return{type:"fixed",value:t}}return{type:"fixed",value:100}}function va(e,t,n){const o=new Map;e.forEach(f=>{if(!Object.prototype.hasOwnProperty.call(t,f.field)&&f.flex&&f.flex>0){o.set(f.field,{kind:"flex",flex:f.flex});return}const b=Ca(t[f.field]??f.width);b.type==="fixed"?o.set(f.field,{kind:"fixed",width:so(b.value,f.minWidth,f.maxWidth)}):b.type==="percentage"?o.set(f.field,{kind:"percentage",percentage:b.value}):o.set(f.field,{kind:"flex",flex:1})});const r=e.reduce((f,h)=>{const b=o.get(h.field);if(b.kind==="fixed")return f+b.width;if(b.kind==="percentage")return f+100;if(h.flex&&h.flex>0){const w=h.minWidth??150;return f+(w||(typeof h.width=="number"?h.width:150))}return f+(h.minWidth??150)},0),i=Math.max(n,r),l=e.reduce((f,h)=>{const b=o.get(h.field);return b.kind==="fixed"?f+b.width:f},0),a=new Map,c=Math.max(0,i-l);let u=0;e.forEach(f=>{const h=o.get(f.field);if(h.kind==="fixed")a.set(f.field,h.width);else if(h.kind==="percentage"){const b=h.percentage/100*c,w=so(b>0?b:100,f.minWidth??50,f.maxWidth);a.set(f.field,w),u+=w}});const g=Math.max(0,c-u),m=new Map,x=e.flatMap(f=>{const h=o.get(f.field);return h.kind!=="flex"?[]:(m.set(f.field,h.flex),[{field:f.field,flex:h.flex,minWidth:f.minWidth??50,maxWidth:f.maxWidth??1/0,frozen:!1,computedWidth:0}])});let y=0;const p=x.length*2;for(;y<p;){y++;const f=x.filter(M=>!M.frozen);if(f.length===0)break;const h=f.reduce((M,_)=>M+_.flex,0),b=x.reduce((M,_)=>_.frozen?M+_.computedWidth:M,0),w=Math.max(0,g-b);if(h<=0){f.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0});break}const C=w/h;let E=0;const S=[],N=[];if(f.forEach(M=>{const _=C*M.flex;_<M.minWidth?(E+=M.minWidth-_,S.push(M)):_>M.maxWidth?(E+=M.maxWidth-_,N.push(M)):M.computedWidth=_}),S.length===0&&N.length===0){f.forEach(M=>{M.frozen=!0});break}E>0?S.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}):E<0?N.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}):(S.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}),N.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}))}return x.forEach(f=>a.set(f.field,f.computedWidth)),{widths:a,flexByField:m}}function Sa(e){const{rowHeight:t,pagination:n,paginatedUnpinnedRows:o,sortedUnpinnedRows:r,expandedRowIds:i,getDetailPanelHeight:l,detailPanelHeights:a,pinnedTopRowsLength:c,pinnedBottomRowsLength:u,pinnedTopRows:g,pinnedBottomRows:m,visibleOrderedColumns:x,pinnedColumns:y,columnWidths:p,viewportWidth:f,checkboxSelection:h,hasDetailPanel:b,rowReordering:w,pinCheckboxColumn:C,pinExpandColumn:E,paginationMode:S,isLoading:N,pageSize:M,getRowId:_=ya}=e,F=s.useMemo(()=>{const L=n?o:r,k=(ee,de)=>{const ie=_(ee);if(!i.has(ie))return t;const ae=ho(l,{row:ee,id:ie,rowIndex:de});return t+ba(ae,a?.get(ie))},I=L.length,P=new Array(I),v=new Array(I),B=i.size>0;let W=0;for(let ee=0;ee<I;ee++){const de=B?k(L[ee],c+ee):t;P[ee]=de,W=(W||0)+de,v[ee]=W}const J=S==="infinite"&&N&&L.length>0?Math.min(M,20):0,G=(v[v.length-1]||0)+J*t,z=(ee,de)=>ee?ee.reduce((ie,ae,R)=>ie+k(ae,R),0):de*t,H=z(g,c),re=z(m,u);return{rowHeights:P,cumulativeHeights:v,unpinnedRowsHeight:G,pinnedTopHeight:H,pinnedBottomHeight:re,pinnedTopRowsLength:c,pinnedBottomRowsLength:u,unpinnedRowsLength:I}},[t,n,o,r,i,l,a,c,u,g,m,S,N,M,_]),A=s.useMemo(()=>{const{left:L,center:k,right:I}=ca(x,y),P=(h?He:0)+(b?He:0)+(w?He:0),v=(w?He:0)+(b&&E?He:0)+(h&&C?He:0),{widths:B,flexByField:W}=va([...L,...k,...I],p,f-P),J=V=>B.get(V.field)??100,G=V=>({...V,width:J(V),flex:W.get(V.field)??V.flex}),z=11,H=L.map((V,U)=>({...G(V),zIndex:z+U})),re=11,ee=I.map((V,U)=>({...G(V),zIndex:re+(I.length-1-U)})),de=k.map(G),ie=de.map(V=>V.width),ae=H.reduce((V,U)=>V+U.width,0),R=ee.reduce((V,U)=>V+U.width,0),ue=ie.reduce((V,U)=>V+U,0),q=ae+ue+R+P,te=ie.reduce((V,U,ce)=>(V.push((V[ce-1]||0)+U),V),[]);return{leftPinnedCols:H,rightPinnedCols:ee,unpinnedColsWithWidth:de,unpinnedColWidths:ie,unpinnedAccWidths:te,totalWidth:q,leftWidth:ae,rightWidth:R,unpinnedTotalWidth:ue,systemColumnsWidth:P,pinnedSystemColumnsWidth:v}},[x,y,p,f,h,b,w,C,E]);return s.useMemo(()=>({...F,...A}),[F,A])}function Xe(e){if(!e)return!1;const t=e.ownerDocument.defaultView;return t?t.getComputedStyle(e).direction==="rtl":!1}function Mn(e,t){return t?e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e:e}function Ot(e){return Xe(e)?-e.scrollLeft:e.scrollLeft}function en(e,t){e.scrollLeft=Xe(e)?-t:t}function Nn(e,t){if(!e)return{top:0,right:0};const n=e.getBoundingClientRect();return Xe(e)?{top:n.bottom+6,left:n.left}:{top:n.bottom+6,right:t-n.right}}function _a(e){const t=e.querySelector(".ogx__sticky-bottom");return t?t.getBoundingClientRect().height:0}function In(e,t,n,o,r){if(t<0||t>=n.length)return;const i=e.querySelector(".ogx__virtual-container");if(!i)return;const{scrollTop:l,clientHeight:a}=e,c=i.getBoundingClientRect().top-e.getBoundingClientRect().top+l,u=Math.max(o,_a(e)),g=c+(t===0?0:n[t-1]),m=r!==void 0?Math.min(g+r,c+n[t]):c+n[t];g<l+c?e.scrollTop=Math.max(0,g-c):m>l+a-u&&(e.scrollTop=m-a+u)}function mo(e,t,n){const{unpinnedAccWidths:o,leftWidth:r,rightWidth:i,systemColumnsWidth:l,pinnedSystemColumnsWidth:a}=n;if(t<0||t>=o.length)return;const c=l+r,u=c+(t>0?o[t-1]:0),g=c+o[t],m=a+r,{clientWidth:x}=e,y=Ot(e);u<y+m?en(e,Math.max(0,u-m)):g>y+x-i&&en(e,g-x+i)}function wo(e,t){const{row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:a,rowMeta:c}=e;if(!i.editable||c?.isGroupRow||n._isSkeleton)return!1;if(!t)return!0;try{return!!t({row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:a})}catch{return!1}}const ka={},tn=e=>e==null||typeof e=="string"&&e.trim()==="",Vr=e=>{const t=[];for(const n of e){const o=nt(n);o!==null&&t.push(o)}return t},zr=(e,t)=>{let n=null,o=null;for(const r of e){const i=nt(r);i!==null&&(n===null||t(i,n))&&(n=i,o=r)}return n===null?null:o instanceof Date?o:n},at={sum:e=>Vr(e).reduce((t,n)=>t+n,0),avg:e=>{const t=Vr(e);return t.length?t.reduce((n,o)=>n+o,0)/t.length:null},count:e=>e.filter(t=>!tn(t)).length,min:e=>zr(e,(t,n)=>t<n),max:e=>zr(e,(t,n)=>t>n),unique:e=>new Set(e.filter(t=>!tn(t))).size};function bo(e,t){return e?e.aggregable===!1?!1:!e.availableAggregationFunctions||e.availableAggregationFunctions.includes(t):!0}function Ln(e,t,n,o){const r={};for(const[i,l]of Object.entries(t)){const a=n.get(i);if(!bo(a,l))continue;const c=at[l];if(!c){console.warn(`[${o}] Unknown aggregation function: "${l}"`);continue}r[i]=Object.prototype.hasOwnProperty.call(at,l)?Ea(e,i,a,l):c(e.map(u=>Me(u,i,a)))}return r}function Ea(e,t,n,o){switch(o){case"sum":case"avg":{let r=0,i=0;for(const l of e){const a=nt(Me(l,t,n));a!==null&&(r+=a,i++)}return o==="sum"?r:i?r/i:null}case"count":{let r=0;for(const i of e)tn(Me(i,t,n))||r++;return r}case"min":case"max":{const r=o==="min";let i=null,l=null;for(const a of e){const c=Me(a,t,n),u=nt(c);u!==null&&(i===null||(r?u<i:u>i))&&(i=u,l=c)}return i===null?null:l instanceof Date?l:i}case"unique":{const r=new Set;for(const i of e){const l=Me(i,t,n);tn(l)||r.add(l)}return r.size}}}function nn(e,t){return e==null?"—":typeof e=="number"?t==="avg"?e.toLocaleString(void 0,{maximumFractionDigits:2}):e.toLocaleString():String(e)}const Ma=new Set(["count","unique"]);function Rr(e){return e!==void 0&&Ma.has(e)}function Kr(e,t,n){return e?.type==="date"&&(t==="min"||t==="max")&&typeof n=="number"&&Number.isFinite(n)?new Date(n):n}function An(e,t,n,o){if(e==null)return"—";if(Rr(t))return nn(e,t);const r=Kr(n,t,e);if(n?.valueFormatter)try{return String(n.valueFormatter({value:r,row:o??{},field:n.field})??"")}catch{}return r instanceof Date?Number.isNaN(r.getTime())?"":Wr(r):nn(r,t)}const Dt=new Set(["isEmpty","isNotEmpty"]);function xo(e){return e==null?!0:typeof e=="string"?e.trim()==="":Array.isArray(e)?e.length===0:!1}function Na(e){return e==null?!0:typeof e=="number"?Number.isNaN(e):typeof e=="string"&&e.trim()===""}const on=e=>(t,n)=>{const o=nt(t),r=nt(n);return o===null||r===null?!1:e(o,r)},rn=e=>(t,n)=>{const o=kn(t),r=kn(n);return o===null||r===null?!1:e(o,r)},Ur=rn((e,t)=>e===t),jr=(e,t)=>{const n=kn(e),o=kn(t);return n===null||o===null?!0:n!==o},qr={contains:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase()),equals:(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:String(e).toLowerCase()===String(t).toLowerCase(),startsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().startsWith(String(t).toLowerCase()),endsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().endsWith(String(t).toLowerCase()),isEmpty:e=>e==null||String(e).trim()==="",isNotEmpty:e=>e!=null&&String(e).trim()!=="","=":on((e,t)=>e===t),">":on((e,t)=>e>t),">=":on((e,t)=>e>=t),"<":on((e,t)=>e<t),"<=":on((e,t)=>e<=t),"!=":(e,t)=>{if(xo(t))return!0;const n=nt(e),o=nt(t);return n!==null&&o!==null?n!==o:Na(e)?!0:String(e).toLowerCase()!==String(t).toLowerCase()},isAnyOf:(e,t)=>{if(e==null)return!1;const n=Array.isArray(t)?t:[t],o=String(e).toLowerCase();return n.some(r=>r!=null&&String(r).toLowerCase()===o)},not:(e,t)=>e instanceof Date?jr(e,t):e==null&&t==null?!1:e==null||t==null?!0:String(e).toLowerCase()!==String(t).toLowerCase(),is:(e,t)=>t==null||t===""?!0:e instanceof Date?Ur(e,t):String(e).toLowerCase()===String(t).toLowerCase(),after:rn((e,t)=>e>t),onOrAfter:rn((e,t)=>e>=t),before:rn((e,t)=>e<t),onOrBefore:rn((e,t)=>e<=t)},Ia={is:Ur,not:jr};function La(e,t){if(!Object.prototype.hasOwnProperty.call(qr,e))return;const n=e;if(t?.type==="date"){const o=Ia[n];if(o)return o}return qr[n]}function Aa(e){return"items"in e&&Array.isArray(e.items)}function Pa(e,t){const{field:n,operator:o,value:r}=e;if(!Dt.has(o)&&xo(r))return null;const i=t.columns?.byField.get(n),l=La(o,i);return l?a=>l(Me(a,n,i),r):(t.warned.has(o)||(t.warned.add(o),console.warn(`Unknown filter operator: ${o}`)),null)}function yo(e,t,n){const o=[];for(const r of e){const i=Aa(r)?yo(r.items,r.logicOperator,n):Pa(r,n);i&&o.push(i)}return o.length===0?null:o.length===1?o[0]:t==="or"?r=>o.some(i=>i(r)):r=>o.every(i=>i(r))}function Co(e,t){if(t!=null){switch(typeof t){case"string":e.push(t.toLowerCase());return;case"number":Number.isNaN(t)||e.push(String(t));return;case"boolean":case"bigint":e.push(String(t));return}if(t instanceof Date){const n=Hr(t);n&&e.push(n);return}if(Array.isArray(t))for(const n of t)(n==null||typeof n!="object")&&Co(e,n)}}function vo(e,t){const n=[];if(!t){for(const o of Object.values(e))Co(n,o);return n}for(const o of t.quickFilterColumns){const r=Me(e,o.field,o),i=fo(e,o.field,r,o);if(i!=null&&i!=="")n.push(String(i).toLowerCase());else if(o.type==="date"||o.type==="boolean"||o.type==="singleSelect"){const l=En(r,o);l!==""&&n.push(l.toLowerCase())}Co(n,r)}return n}const Xr=new WeakMap;function Ta(e,t){if(!t)return vo(e,t);let n=Xr.get(t);n||(n=new WeakMap,Xr.set(t,n));let o=n.get(e);return o||(o=vo(e,t),n.set(e,o)),o}function Yr(e){return(e??[]).map(t=>String(t??"").trim().toLowerCase()).filter(t=>t!=="")}function Jr(e,t){for(let n=0;n<t.length;n++){const o=t[n];let r=!1;for(let i=0;i<e.length;i++)if(e[i].includes(o)){r=!0;break}if(!r)return!1}return!0}function Fa(e,t){const n=Yr(e);return n.length===0?null:o=>Jr(Ta(o,t),n)}const Zr=new WeakMap;function Oa(e,t){const n=Zr.get(t);if(n&&n.rows===e)return n.texts;const o=new Array(e.length);for(let r=0;r<e.length;r++){const i=e[r];o[r]=n&&r<n.rows.length&&n.rows[r]===i?n.texts[r]:vo(i,t)}return Zr.set(t,{rows:e,texts:o}),o}function Pn(e,t){if(!e)return null;const n={columns:t,warned:new Set},o="quickFilterValues"in e?e.quickFilterValues:void 0,r=Fa(o,t),i=yo(e.items??[],e.logicOperator??"and",n);return r&&i?l=>r(l)&&i(l):r??i}function So(e,t,n){const o=n&&t?Yr(t.quickFilterValues):[];if(n&&o.length>0){const i=yo(t.items??[],t.logicOperator??"and",{columns:n,warned:new Set}),l=Oa(e,n),a=[];for(let c=0;c<e.length;c++)Jr(l[c],o)&&(!i||i(e[c]))&&a.push(e[c]);return a}const r=Pn(t,n);return r?e.filter(i=>r(i)):e}function Qr(e){switch(e){case"number":return["=","!=",">",">=","<","<=","isEmpty","isNotEmpty"];case"date":return["is","not","after","onOrAfter","before","onOrBefore","isEmpty","isNotEmpty"];case"boolean":return["is"];case"singleSelect":return["isAnyOf","is","not"];default:return["contains","equals","startsWith","endsWith","isEmpty","isNotEmpty"]}}function _o(e,t){return e==null?"":t==="date"||e instanceof Date?Hr(e)||(typeof e=="string"?e:""):Array.isArray(e)?e.map(n=>String(n)).join(", "):String(e)}const ko=new Intl.Collator(void 0,{numeric:!0,sensitivity:"accent"}),Tn=0,ei=1,Da=2,Eo=3,Fn=4;function $t(e,t){return{rank:e,num:t,str:""}}function On(e,t){if(e==null)return null;if(t==="number"){const n=nt(e);return n===null?null:$t(Tn,n)}if(t==="date"){const n=Qt(e);return n?$t(ei,n.getTime()):null}switch(typeof e){case"number":return Number.isNaN(e)?null:$t(Tn,e);case"bigint":return $t(Tn,Number(e));case"boolean":return $t(Da,e?1:0);case"string":return{rank:Eo,num:0,str:e}}if(e instanceof Date){const n=e.getTime();return Number.isNaN(n)?null:$t(ei,n)}return{rank:Fn,num:0,str:String(e)}}function ti(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:e.rank!==t.rank?e.rank-t.rank:e.rank===Eo||e.rank===Fn?ko.compare(e.str,t.str):e.num<t.num?-1:e.num>t.num?1:0}function Mo(e,t){return e===0?0:t==="asc"?e:-e}function $a(e,t,n,o){return Mo(ti(On(e,o),On(t,o)),n)}function ni(e,t,n){let o;try{o=e(t.value,n.value,t,n)}catch(r){return Ct(`sortComparator:${t.field}`,`sortComparator for column "${t.field}" threw; the values are treated as equal`,r),0}return typeof o!="number"||Number.isNaN(o)?(Ct(`sortComparator:${t.field}:nan`,`sortComparator for column "${t.field}" returned ${String(o)}; the values are treated as equal`,void 0),0):o}const Ga=e=>e.id;function Ha(e,t,n,o=Ga){if(t.length===0)return e;if(e.length<2)return[...e];const r=t.map(i=>{const l=n?.byField.get(i.field),a=l?.sortComparator;if(a)return ai(e.map(u=>{const g=Me(u,i.field,l);return{value:g,type:l.type,comparator:a,params:{id:o(u),field:i.field,row:u,value:g}}}));const c=l?.type;return si(e.length,u=>Me(e[u],i.field,l),()=>c)});return ci(e,t,r)}function oi(e,t,n){if(t.length===0||e.length<2)return[...e];const o=t.map(r=>{const i=e.map(l=>n(l,r));return i.some(l=>l.comparator&&l.params)?ai(i):si(i.length,l=>i[l].value,l=>i[l].type)});return ci(e,t,o)}const ri=Fn+1;function ii(e,t){const n=[...e.keys()].sort(ko.compare);let o=0;for(let r=0;r<n.length;r++){r>0&&ko.compare(n[r-1],n[r])!==0&&o++;for(const i of e.get(n[r])??[])t[i]=o}}function li(e,t,n){const o=e.get(t);o?o.push(n):e.set(t,[n])}function si(e,t,n){const o=new Uint8Array(e),r=new Float64Array(e),i=new Map,l=new Map;for(let a=0;a<e;a++){const c=t(a),u=n(a);if(typeof c=="number"&&u!=="date"){Number.isNaN(c)?o[a]=ri:(o[a]=Tn,r[a]=c);continue}const g=On(c,u);g===null?o[a]=ri:(o[a]=g.rank,g.rank===Eo?li(i,g.str,a):g.rank===Fn?li(l,g.str,a):r[a]=g.num)}return ii(i,r),ii(l,r),{kind:"encoded",group:o,num:r}}function ai(e){return{kind:"generic",values:e,keys:e.map(({value:t,type:n})=>On(t,n))}}function Ba(e,t,n){if(e.kind==="encoded"){const i=e.group[t],l=e.group[n];if(i!==l)return i-l;const a=e.num[t],c=e.num[n];return a<c?-1:a>c?1:0}const o=e.values[t],r=e.values[n];return o.comparator&&o.comparator===r.comparator&&o.params&&r.params?ni(o.comparator,o.params,r.params):ti(e.keys[t],e.keys[n])}function ci(e,t,n){const o=e.length,r=new Array(o);for(let a=0;a<o;a++)r[a]=a;const i=n[0];if(n.length===1&&i.kind==="encoded"){const{group:a,num:c}=i,u=t[0].sort==="asc"?1:-1;r.sort((g,m)=>{const x=a[g],y=a[m];if(x!==y)return(x-y)*u;const p=c[g],f=c[m];return p<f?-u:p>f?u:g-m})}else r.sort((a,c)=>{for(let u=0;u<n.length;u++){const g=Mo(Ba(n[u],a,c),t[u].sort);if(g!==0)return g}return a-c});const l=new Array(o);for(let a=0;a<o;a++)l[a]=e[r[a]];return l}function Wa(e,t,n){if(!n)return e.filter(r=>r.field!==t);const o=e.findIndex(r=>r.field===t);return o===-1?[...e,{field:t,sort:n}]:e.map((r,i)=>i===o?{field:t,sort:n}:r)}function No(e,t={}){const n=new Map,o=[];for(const r of e)n.set(r.field,r),!(r.isSpacer||r.field.startsWith("__"))&&r.filterable!==!1&&t[r.field]!==!1&&o.push(r);return{byField:n,quickFilterColumns:o}}const Gt="__pivot_grand_total__",Va="__pivot_row__:",di=e=>`${Va}${JSON.stringify(e.split(ui))}`,za="Grand Total",ui="\0",Ht="",Io=`${Ht}id`,fi=e=>e==="id"?Io:e,Lo={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1},gi=e=>e.map(t=>String(t??"")).join(ui),pi=e=>e===void 0||e===""?null:e;function Ra(e,t){const n=e==null,o=t==null;return n||o?n===o?0:n?1:-1:typeof e=="number"&&typeof t=="number"?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():typeof e=="boolean"&&typeof t=="boolean"?Number(e)-Number(t):String(e).localeCompare(String(t),void 0,{numeric:!0})}function Ka(e,t){for(let n=0;n<e.length;n++){const o=Ra(e[n],t[n]);if(o!==0)return o}return 0}function hi(e,t){if(!e||e.length===0)return null;const n=at[t](e);return typeof n=="number"||n instanceof Date?n:null}const Ua=e=>"logicOperator"in e&&"items"in e,ja=e=>!!(e&&e.items&&e.items.length>0);function qa(e,t){const n=l=>!t.has(l)&&l.includes(Ht),o=l=>Ua(l)?l.items.length>0&&l.items.every(o):n(l.field),r=[],i=[];for(const l of e.items??[])(o(l)?i:r).push(l);return{source:{...e,items:r},output:{items:i,logicOperator:e.logicOperator}}}function mi(e,t,n,o={}){const r=new Map(t.map(k=>[k.field,k])),i=k=>r.get(k)?.groupable!==!1,l=n.rowFields.filter(i),a=n.columnFields.filter(i),c=new Set,u=n.valueFields.filter(k=>{if(!bo(r.get(k.field),k.aggFn))return!1;const I=`${k.field}${Ht}${k.aggFn}`;return c.has(I)?!1:(c.add(I),!0)});if(l.length===0||u.length===0)return Lo;const g=a.length>0,m=Array.from(new Set(u.map(k=>k.field))),x=(k,I)=>Me(k,I,r.get(I)),y=new Map,p=new Map(g?[]:[["",{values:[]}]]);for(const k of e){const I=l.map(z=>x(k,z)),P=gi(I);let v=y.get(P);v||(v={labels:I.map(pi),sample:k,cells:new Map},y.set(P,v));const B=a.map(z=>x(k,z)),W=g?gi(B):"",J=p.get(W);J?J.sample||(J.sample=k):p.set(W,{values:B.map(pi),sample:k});let G=v.cells.get(W);G||(G=new Map,v.cells.set(W,G));for(const z of m){const H=x(k,z);if(tn(H))continue;let re=G.get(z);re||(re=[],G.set(z,re)),re.push(H)}}const f=Array.from(p.keys()).sort((k,I)=>Ka(p.get(k).values,p.get(I).values)),h=(k,I)=>g?`${k}${Ht}${I.field}${Ht}${I.aggFn}`:`${I.field}${Ht}${I.aggFn}`,b=new Map;let w=[];for(const[k,I]of y){const P={id:di(k)};l.forEach((v,B)=>{P[fi(v)]=I.labels[B]}),P.id=di(k);for(const v of f){const B=I.cells.get(v);for(const W of u)P[h(v,W)]=hi(B?.get(W.field),W.aggFn)}b.set(P.id,I),w.push({row:P,entry:I})}const C=k=>l.includes(k),E=k=>C(k)?r.get(k)?.type:"number",{outputFilterModel:S,sortModel:N}=o;if(ja(S)){const k=[];for(const P of f)for(const v of u)k.push({field:h(P,v),type:"number"});const I=Pn(S,No(k));I&&(w=w.filter(({row:P})=>I(P)))}const M=(k,I)=>I==="id"&&C("id")?k[Io]:k[I];N&&N.length>0&&(w=[...w].sort((k,I)=>{for(const P of N){const v=M(k.row,P.field),B=M(I.row,P.field),W=C(P.field)?r.get(P.field)?.sortComparator:void 0,J=W?Mo(ni(W,{id:k.row.id,field:P.field,row:k.row,value:v},{id:I.row.id,field:P.field,row:I.row,value:B}),P.sort):$a(v,B,P.sort,E(P.field));if(J!==0)return J}return 0}));const _=w.map(k=>k.row);if(w.length>0){const k={id:Gt};l.forEach((I,P)=>{k[fi(I)]=P===0?za:""}),k.id=Gt;for(const I of f)for(const P of m){const v=[];for(const{entry:B}of w){const W=B.cells.get(I)?.get(P);if(W)for(const J of W)v.push(J)}for(const B of u)B.field===P&&(k[h(I,B)]=hi(v,B.aggFn))}_.push(k)}const F=w[0]?.entry.sample,A=k=>k===Gt?F:k===void 0?void 0:b.get(k)?.sample,L=l.map(k=>Ya(k,r.get(k),A));for(const k of f){const I=p.get(k),P=g?a.map((v,B)=>{const W=r.get(v),J=Xa(W,v,I.values[B],I.sample);return W?.headerName?`${W.headerName}: ${J}`:J}).join(" / "):"";for(const v of u){const B=r.get(v.field),W=v.headerName??B?.headerName??v.field;L.push({field:h(k,v),headerName:P?`${P} — ${W} (${v.aggFn})`:`${W} (${v.aggFn})`,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:J,row:G})=>An(J,v.aggFn,B,G)})}}return{pivotRows:_,pivotColumns:L,colKeys:f,isValid:!0}}function Xa(e,t,n,o){const r=o?fo(o,t,n,e):void 0;return r!==void 0?r:n==null?"":String(n)}function Ya(e,t,n){const o={field:e,headerName:t?.headerName??e,width:t?.width??140,sortable:!0,hideable:!1};t&&(t.type!==void 0&&(o.type=t.type),t.align!==void 0&&(o.align=t.align),t.headerAlign!==void 0&&(o.headerAlign=t.headerAlign),t.description!==void 0&&(o.description=t.description),t.minWidth!==void 0&&(o.minWidth=t.minWidth),t.maxWidth!==void 0&&(o.maxWidth=t.maxWidth),t.valueOptions!==void 0&&(o.valueOptions=t.valueOptions)),e==="id"&&(o.valueGetter=({row:a})=>a[Io]);const r=a=>a?.id===Gt,i=t?.valueFormatter;i&&(o.valueFormatter=({value:a,row:c})=>r(c)?String(a??""):i({value:a,row:n(c?.id)??c,field:e}));const l=t?.renderCell;return l&&(o.renderCell=a=>r(a.row)?a.formattedValue??String(a.value??""):l({...a,row:n(a.row.id)??a.row})),o}function Re(e,t){return e===Gt||t?.get(e)?.isGroupRow===!0}const vt="__reorder_col__",St="__expand_col__",Ye="__checkbox_col__",Je=e=>e===vt||e===St||e===Ye,Ao=(e,t)=>e===t||e!==null&&t!==null&&e.id===t.id&&e.field===t.field&&!e.headerFilter==!t.headerFilter,Ja=new Set(["checkbox","radio","button","submit","reset","image","file","color"]),Za=new Set(["textbox","searchbox","combobox","listbox","slider","spinbutton"]);function wi(e){const t=e.tagName;if(t==="INPUT")return!Ja.has(e.type);if(t==="TEXTAREA"||t==="SELECT"||e.isContentEditable||e.closest('[contenteditable]:not([contenteditable="false"])'))return!0;const n=e.getAttribute("role");return n!==null&&Za.has(n)}const bi=e=>e!==null&&e.nodeType===1;function xi(e,t){const n=e.closest(".ogx__detail-panel");if(n&&t.contains(n))return null;const o=e.closest('[role="gridcell"], [role="columnheader"]');return!o||o.closest(".ogx__viewport")!==t?null:o}function Dn(e,t){if(e===t)return"grid";if(!bi(e)||!t.contains(e))return"foreign";const n=xi(e,t);return n?n.classList.contains("ogx__cell--editing")?"editor":n===e?"grid":wi(e)?"foreign":n.classList.contains("ogx__header-cell--checkbox")?"grid":"control":"foreign"}function Qa(e,t,n,o){if(!bi(e))return null;const r=xi(e,t),i=r?.dataset.field;if(!r||!i)return null;if(r.getAttribute("role")==="columnheader"){const c=r.parentElement;return c?.classList.contains("ogx__header")?{id:null,field:i}:c?.classList.contains("ogx__header-filter-row")?{id:null,field:i,headerFilter:!0}:null}const l=Number(r.parentElement?.getAttribute("data-rowindex")),a=Number.isInteger(l)?n[l]:void 0;return a?{id:o(a),field:i,rowIndex:l}:null}function yi(e,t){if(!e)return null;for(const n of Array.from(e.children))if(n.dataset.field===t)return n;return null}function Po(e,t,n){if(t.id===null){const r=e.querySelector(`:scope > .ogx__content > .ogx__sticky-top > .ogx__header-wrap > ${t.headerFilter?".ogx__header-filter-row":".ogx__header"}`),i=yi(r,t.field);return i&&t.field===Ye?i.querySelector("input")??i:i}if(n<0)return null;const o=e.querySelector(`:scope > .ogx__content > .ogx__virtual-container > .ogx__rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-top > .ogx__pinned-rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-bottom > .ogx__pinned-rows > [data-rowindex="${n}"]`);return yi(o,t.field)}const Ci="__group__";function Ke(e){return!Je(e)&&e!==Ci}const ct=(e,t)=>e===t||!!e&&!!t&&e.id===t.id&&e.field===t.field;function ec(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>ct(n.anchor,t[o].anchor)&&ct(n.head,t[o].head))}function $n(e,t,n){const{rowIds:o,fields:r,rowIndexById:i,colIndexByField:l,spans:a}=n,c={top:e,bottom:e,left:t,right:t};if(!a)return c;const u=o[e],g=r[t],m=a.getSpanOrigin(u,g)??{rowId:u,field:g},x=i.get(m.rowId),y=l.get(m.field);if(x===void 0||y===void 0)return c;const p=Math.max(1,a.getRowSpan(m.rowId,m.field)),f=Math.max(1,a.getColSpan(m.rowId,m.field));return{top:x,bottom:Math.min(o.length-1,x+p-1),left:y,right:Math.min(r.length-1,y+f-1)}}function tc(e,t){if(!t.spans)return e;let{top:n,bottom:o,left:r,right:i}=e,l=!0;const a=c=>{c.top<n&&(n=c.top,l=!0),c.bottom>o&&(o=c.bottom,l=!0),c.left<r&&(r=c.left,l=!0),c.right>i&&(i=c.right,l=!0)};for(;l;){l=!1;for(let c=n;c<=o;c++)a($n(c,r,t)),i!==r&&a($n(c,i,t));for(let c=r+1;c<i;c++)a($n(n,c,t)),o!==n&&a($n(o,c,t))}return{top:n,bottom:o,left:r,right:i}}function Gn(e,t){const n=t.rowIndexById.get(e.anchor.id),o=t.rowIndexById.get(e.head.id),r=t.colIndexByField.get(e.anchor.field),i=t.colIndexByField.get(e.head.field);return n===void 0||o===void 0||r===void 0||i===void 0?null:{...tc({top:Math.min(n,o),bottom:Math.max(n,o),left:Math.min(r,i),right:Math.max(r,i)},t),anchorRow:n,anchorCol:r,headRow:o,headCol:i}}const _t=e=>(e.bottom-e.top+1)*(e.right-e.left+1);function nc(e,t,n,o,r,i){const{headRow:l,headCol:a,anchorRow:c,anchorCol:u,top:g,bottom:m,left:x,right:y}=e;let p=l,f=a;switch(t){case"ArrowRight":f=a>=u?y+1:a+1;break;case"ArrowLeft":f=a<=u?x-1:a-1;break;case"ArrowDown":p=l>=c?m+1:l+1;break;case"ArrowUp":p=l<=c?g-1:l-1;break;case"Home":f=0,n&&(p=0);break;case"End":f=i,n&&(p=r);break;case"PageUp":p=l-o;break;case"PageDown":p=l+o;break;default:return null}return p=Math.min(Math.max(p,0),r),f=Math.min(Math.max(f,0),i),p===l&&f===a?null:{row:p,col:f}}function vi(e,t,n,o){const r=o&&o.row===t?o.col:void 0;if(!e||t<e.top||t>e.bottom)return r===void 0?null:{left:0,right:-1,isTop:!1,isBottom:!1,bottomOffset:0,fillHandleCol:r};const i={left:e.left,right:e.right,isTop:t===e.top,isBottom:t===e.bottom,bottomOffset:n?e.bottom-t:0};return r!==void 0&&(i.fillHandleCol=r),i}const oc=(e,t)=>e===t||!!e&&!!t&&e.left===t.left&&e.right===t.right&&e.isTop===t.isTop&&e.isBottom===t.isBottom&&e.bottomOffset===t.bottomOffset&&e.fillHandleCol===t.fillHandleCol,To=1,Si=2,_i=4,ki=8,Ei=16,Mi=32;function rc(e,t,n,o){if(!e)return 0;const r=e.fillHandleCol===t?Mi:0,i=t+Math.max(1,n)-1;if(t<e.left||i>e.right)return r;let l=To|r;return e.isTop&&(l|=Si),(e.isBottom||o>1&&o-1>=e.bottomOffset)&&(l|=_i),t===e.left&&(l|=ki),i===e.right&&(l|=Ei),l}function ic(e,t,n){const o=(r,i,l)=>`${r} ${r===1?i:l}`;return`${o(e,"cell","cells")} selected, ${o(t,"row","rows")} by ${o(n,"column","columns")}`}const lc=1e5,sc=e=>e.id,Ni=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]);function ac(e,t,n,o,r){if(!e||n.length===0)return{cell:null,rowIndex:-1};const i=(n.find(u=>!Je(u.field))??n[0]).field,l=n.some(u=>u.field===e.field)?e.field:i;if(e.id===null){const u=!!e.headerFilter&&r;return l===e.field&&u===!!e.headerFilter?{cell:e,rowIndex:-1}:{cell:u?{id:null,field:l,headerFilter:u}:{id:null,field:l},rowIndex:-1}}const a=e.rowIndex;let c=a!==void 0&&t[a]&&o(t[a])===e.id?a:t.findIndex(u=>o(u)===e.id);return c===-1?t.length===0?{cell:{id:null,field:l},rowIndex:-1}:(c=Math.min(Math.max(a??0,0),t.length-1),{cell:{id:o(t[c]),field:l,rowIndex:c},rowIndex:c}):{cell:l===e.field?e:{...e,field:l},rowIndex:c}}function cc(e){const{allRenderableRows:t,navigationColumns:n,checkboxSelection:o,selectedRowIds:r,handleSelectionChange:i,handleDetailPanelToggle:l,editingHandlers:a,setKeyboardMode:c,sortModel:u,handleSort:g,handleSortAdd:m,multiSort:x=!1,isCellEditable:y,pagination:p,pageSize:f,virtualization:h,viewportRef:b,pinnedTopRowCount:w=0,getRowId:C=sc,rowMetaMap:E,onRowActivate:S,toggleRowExpansion:N,handleSelectAll:M,rowSelectionEnabled:_=!0,multipleRowSelectionEnabled:F=!0,pinCheckboxColumn:A=!0,pinExpandColumn:L=!0,rowHeight:k,getSpanOrigin:I,cellSelection:P,headerFilters:v=!1}=e,[B,W]=s.useState(null),[J,G]=s.useState(!1),z=s.useMemo(()=>ac(B,t,n,C,v),[B,t,n,C,v]),H=z.cell,re=z.rowIndex,ee=s.useRef(!1),de=s.useRef(!1),ie=s.useRef(!1),ae=s.useRef(null),R=s.useCallback(D=>{de.current=!0,D.focus({preventScroll:!0}),de.current=!1},[]),ue=s.useCallback(()=>{const D=b.current;D&&!D.contains(D.ownerDocument.activeElement)&&R(D)},[b,R]),q=s.useMemo(()=>n.find(D=>!Je(D.field))??n[0],[n]),te=s.useCallback(()=>{if(o)return{id:null,field:Ye};if(!q)return null;const D=t[0];return D?{id:C(D),field:q.field,rowIndex:0}:{id:null,field:q.field}},[o,q,t,C]),V=s.useCallback((D,T)=>{const $=b.current;if(!$)return;const{cumulativeHeights:O,pinnedBottomHeight:Z,columnMetrics:j}=h;if(D>=0&&In($,D-w,O,Z,k),Je(T)){!(T===vt||T===St&&L||T===Ye&&A)&&Ot($)>0&&en($,0);return}if(!j)return;const{clientWidth:ne}=$,X=Ot($),{leftPinnedWidth:Y,rightPinnedWidth:oe,unpinnedAccWidths:he,unpinnedCols:me,totalSpecialsWidth:K,pinnedSpecialsWidth:fe}=j,we=me.findIndex(ke=>ke.field===T);if(we===-1)return;const le=K+Y+(we>0?he[we-1]:0),xe=K+Y+he[we],Ce=X+fe+Y,se=X+ne-oe;let ye=X;le<Ce?ye=Math.max(0,le-fe-Y):xe>se&&(ye=xe-ne+oe),ye!==X&&en($,ye)},[b,h,w,k,A,L]);s.useLayoutEffect(()=>{const D=b.current,T=!Ao(ae.current,H);if(ae.current=H,!D||!H)return;const $=D.ownerDocument,O=$.activeElement;let Z;if(O===D?Z=!0:!O||O===$.body?Z=ee.current:D.contains(O)?Z=T:Z=!1,!Z)return;const j=Po(D,H,re);j?j.contains(O)||j.focus({preventScroll:!0}):O!==D&&R(D)});const U=s.useCallback(()=>{ie.current=!0,c(!1)},[c]),ce=s.useCallback(D=>{const T=D.currentTarget,$=D.relatedTarget,O=!($ instanceof Node&&T.contains($)),Z=ie.current;if(ie.current=!1,ee.current=!0,G(!0),de.current)return;if(D.target===T){if(!O)return;if(Z||c(!0),H){const X=Po(T,H,re);X?X.focus({preventScroll:!0}):V(re,H.field);return}const ne=te();ne&&(W(X=>X??ne),V(ne.rowIndex??-1,ne.field));return}const j=Qa(D.target,T,t,C);j&&!Ao(j,H)&&W(j)},[H,re,te,V,c,t,C]),ge=s.useCallback(D=>{const T=D.relatedTarget;T instanceof Node&&D.currentTarget.contains(T)||(ee.current=!1,ie.current=!1,G(!1),c(!1))},[c]),Q=s.useCallback(D=>{const T=D.currentTarget,$=Dn(D.target,T);if($==="foreign"||(c(!0),D.nativeEvent?.isComposing||D.keyCode===229))return;const O=Mn(D.key,Xe(T)),Z=O===" "||O==="Spacebar",j=!!a.editingCell,ne=v?-2:-1,X=(pe,ve)=>{const Se=n[ve];!Se||pe<ne||pe>=t.length||(pe===ne?W({id:null,field:Se.field}):pe<0?W({id:null,field:Se.field,headerFilter:!0}):W({id:C(t[pe]),field:Se.field,rowIndex:pe}),V(pe,Se.field))};if(!H){if(!Ni.has(O))return;const pe=te();if(!pe)return;D.preventDefault(),W(pe),V(pe.rowIndex??-1,pe.field);return}const{id:Y,field:oe}=H,he=Y===null&&!!H.headerFilter,me=Y!==null?re:he?-1:ne,K=n.findIndex(pe=>pe.field===oe),fe=n.filter(pe=>Je(pe.field)).length,we=pe=>Re(pe,E),le=(pe,ve,Se)=>{const be=n[Se];return Je(be.field)?!1:wo({row:pe,field:be.field,value:Me(pe,be.field,be),colDef:be,rowIndex:ve,colIndex:Se-fe,rowMeta:E?.get(C(pe))},y)},xe=pe=>{let ve=me,Se=K;const be=(t.length+1)*n.length;for(let Le=0;Le<be;Le++){if(Se+=pe,Se>=n.length?(Se=0,ve++):Se<0&&(Se=n.length-1,ve--),ve<0||ve>=t.length)return null;const Ue=t[ve];if(!I?.(C(Ue),n[Se].field)&&le(Ue,ve,Se))return{r:ve,c:Se}}return null};if(j){if(O==="Enter")D.preventDefault(),a.stopCellEdit();else if(O==="Escape")D.preventDefault(),a.stopCellEdit({cancel:!0});else if(O==="Tab"&&Y!==null){const pe=xe(D.shiftKey?-1:1);pe&&(D.preventDefault(),a.stopCellEdit(),X(pe.r,pe.c))}return}if(O==="Escape"&&P?.collapseSelection()){D.preventDefault();return}if(O==="Tab"||O==="Escape"||$==="control"&&(O==="Enter"||Z))return;if((D.ctrlKey||D.metaKey)&&(O==="a"||O==="A")){if(P){P.selectAllCells()&&D.preventDefault();return}if(!_||!F||!M)return;D.preventDefault(),M(!0);return}if(he&&(O==="Enter"||Z))return;if(Y===null){if(O==="Enter"||Z){if(D.preventDefault(),oe===Ye){Po(T,H,-1)?.click();return}const pe=n[K];if(!pe||Je(oe)||pe.sortable===!1)return;const ve=u.find(be=>be.field===oe),Se=ve?ve.sort==="asc"?"desc":null:"asc";(x||D.shiftKey)&&m?m(oe,Se):g(oe,Se);return}}else if(O==="Enter"||Z){D.preventDefault();const pe=t[me];if(oe===Ye){i(Y,!r.has(Y));return}if(oe===St){D.shiftKey||l(Y);return}if(Z){D.shiftKey&&_&&!we(Y)&&i(Y,!r.has(Y));return}if(oe===vt)return;if(le(pe,me,K)){a.startCellEdit({id:Y,field:oe,value:Me(pe,oe,n[K])});return}if(N&&E?.get(Y)?.hasChildren){N(Y);return}S?.({row:pe,id:Y,rowIndex:me});return}if(D.altKey&&(O==="ArrowRight"||O==="ArrowLeft")&&N&&Y!==null){D.preventDefault();const pe=E?.get(Y);pe?.hasChildren&&!!pe.isExpanded!=(O==="ArrowRight")&&N(Y);return}if(!Ni.has(O))return;D.preventDefault();const Ce=t.length-1,se=n.length-1,ye=D.ctrlKey||D.metaKey,ke=p?f:10;if(P&&D.shiftKey&&Y!==null&&Ke(oe)&&P.extendSelection(O,ye,ke,H))return;const De=(pe,ve)=>{switch(O){case"ArrowRight":return ve+1>se?{r:pe+1,c:0}:{r:pe,c:ve+1};case"ArrowLeft":return ve-1<0?{r:pe-1,c:se}:{r:pe,c:ve-1};case"ArrowDown":return{r:pe+1,c:ve};case"ArrowUp":return{r:pe-1,c:ve};case"Home":return{r:ye?ne:pe,c:0};case"End":return{r:ye?Ce:pe,c:se};case"PageUp":return{r:Math.max(ne,pe-ke),c:ve};default:return{r:Math.min(Ce,pe+ke),c:ve}}},Ne=({r:pe,c:ve})=>pe>=ne&&pe<=Ce&&ve>=0&&ve<=se,Ie=({r:pe,c:ve})=>pe>=0?I?.(C(t[pe]),n[ve].field)??null:null;let Ee=De(me,K);if(O.startsWith("Arrow"))for(let pe=Ne(Ee)?Ie(Ee):null;pe&&pe.rowId===Y&&pe.field===oe;pe=Ne(Ee)?Ie(Ee):null)Ee=De(Ee.r,Ee.c);if(!Ne(Ee))return;const Pe=Ie(Ee);if(Pe){const pe=t.findIndex(Se=>C(Se)===Pe.rowId),ve=n.findIndex(Se=>Se.field===Pe.field);pe!==-1&&ve!==-1&&(Ee={r:pe,c:ve})}Ee.r===me&&Ee.c===K||X(Ee.r,Ee.c)},[H,re,t,n,a,r,i,l,c,u,g,m,x,y,p,f,E,S,N,M,_,F,te,V,I,C,P,v]);return{focusedCell:H,setFocusedCell:W,viewportTabIndex:J?-1:0,ensureGridFocus:ue,handleFocus:ce,handleBlur:ge,handleKeyDown:Q,handleMouseDownCapture:U}}const Fo=[];function dc(e){const{isPivotActive:t}=e,n=t?Fo:e.rowGroupingModel,o=e.treeData&&!t,r=o&&e.hasTreeDataPath,i=n.length>0;return{rowReordering:e.rowReordering&&!t,hierarchyRowGroupingModel:n,isTreeDataRequested:o,isTreeData:r,isRowGrouping:i,isHierarchyEnabled:r||i,hasGroupingColumn:e.hasGroupingColDef&&(i||r),pagination:e.pagination&&!i&&e.paginationMode!=="infinite",listView:e.listView&&e.hasListViewColumn}}const uc=[],fc={rowFields:[],columnFields:[],valueFields:[]},Ii=100;function gc(e){return!e||e.length===0||e.includes(Ii)?Ii:e[0]}function pc(e){const{initialState:t,sortModel:n,onSortModelChange:o,filterModel:r,onFilterModelChange:i,aggregationModel:l,onAggregationModelChange:a,rowGroupingModel:c,onRowGroupingModelChange:u,columnVisibilityModel:g,onColumnVisibilityModelChange:m,pinnedColumns:x,onPinnedColumnsChange:y,pivotModel:p,onPivotModelChange:f,paginationModel:h,onPaginationModelChange:b,pageSizeOptions:w,rowSelectionModel:C,onRowSelectionModelChange:E,density:S,cellSelectionModel:N,onCellSelectionModelChange:M}=e,[_,F]=s.useState(()=>t?.sorting?.sortModel??[]),A=n!==void 0,L=A?n:_,k=s.useCallback(be=>{A||F(be),o?.(be)},[A,o]),[I,P]=s.useState(()=>t?.filter?.filterModel??{items:[]}),v=r!=null,B=v?r:I,W=s.useCallback(be=>{v||P(be),i?.(be)},[v,i]),J=l!==void 0,[G,z]=s.useState(()=>l??{}),H=JSON.stringify(J?l:G),re=s.useMemo(()=>JSON.parse(H),[H]),ee=s.useCallback(be=>{J||z(be),a?.(be)},[J,a]),de=c!==void 0,[ie,ae]=s.useState(Fo),R=(de?c:ie)||Fo,ue=s.useCallback(be=>{de||ae(be),u?.(be)},[de,u]),q=g!==void 0,[te,V]=s.useState(()=>t?.columns?.columnVisibilityModel??{}),U=q?g:te,ce=s.useCallback(be=>{q||V(be),m?.(be)},[q,m]),ge=x!==void 0,[Q,D]=s.useState(()=>t?.columns?.pinnedColumns??{}),T=ge?x:Q,$=s.useCallback(be=>{ge||D(be),y?.(be)},[ge,y]),[O,Z]=s.useState(()=>p??fc),j=p??O,ne=s.useCallback(be=>{Z(be),f?.(be)},[f]),X=h!==void 0,[Y,oe]=s.useState(()=>t?.pagination?.paginationModel??h??{page:0,pageSize:gc(w)}),he=X?h:Y,me=s.useCallback(be=>{X||oe(be),b?.(be)},[X,b]),K=C!==void 0,[fe,we]=s.useState([]),le=K?C:fe,xe=s.useMemo(()=>new Set(le),[le]),Ce=s.useRef(null);s.useLayoutEffect(()=>{Ce.current=null});const se=s.useCallback(()=>Ce.current,[]),ye=s.useCallback(be=>{Ce.current=be,K||we(be),E?.(be)},[K,E]),[ke]=s.useState(()=>t?.density?.density??"standard"),De=S??ke,Ne=N!==void 0,[Ie,Ee]=s.useState(uc),Pe=Ne?N:Ie,pe=s.useRef(null);s.useLayoutEffect(()=>{pe.current=null});const ve=s.useCallback(()=>pe.current,[]),Se=s.useCallback((be,Le)=>{pe.current=be,Ne||Ee(be),M?.(be,{reason:Le})},[Ne,M]);return{sortModel:L,isSortControlled:A,setInternalSortModel:F,handleSortModelChange:k,filterModel:B,isFilterControlled:v,handleFilterModelChange:W,aggregationModel:re,handleAggregationModelChange:ee,rowGroupingModel:R,handleRowGroupingModelChange:ue,columnVisibilityModel:U,handleColumnVisibilityModelChange:ce,pinnedColumns:T,handlePinnedColumnsChange:$,currentPivotModel:j,handlePivotModelChange:ne,effectivePaginationModel:he,handlePaginationModelChange:me,rowSelectionModel:le,selectedRowIds:xe,isSelectionControlled:K,setInternalRowSelectionModel:we,handleRowSelectionModelChange:ye,getPendingRowSelectionModel:se,density:De,cellSelectionModel:Pe,handleCellSelectionModelChange:Se,getPendingCellSelectionModel:ve}}const Li=s.createContext(null),hc=52,mc=56,wc=32,bc=72;function Hn(e){if(e===void 0)return;const t=/^(\d+(?:\.\d+)?)(?:\s*px)?$/.exec(e.trim());if(!t)return;const n=Number(t[1]);return n>0?n:void 0}function xc(e){const{rowHeight:t,headerHeight:n,density:o}=e,r=s.useContext(Li)?.grid;let i;return o==="compact"?i=Hn(r?.rowHeightCompact)??wc:o==="comfortable"?i=Hn(r?.rowHeightComfortable)??bc:i=t??Hn(r?.rowHeightStandard)??hc,{rowHeight:i,headerHeight:n??Hn(r?.headerHeight)??mc}}function Bn(e){return e>=1?Math.floor(e):1}function Oo(e,t){return Math.max(1,Math.ceil(Math.max(0,e)/Bn(t)))}function yc(e){const{paginationMode:t,hasDataSource:n,dataSourceRowCount:o,rowCountProp:r,clientRowCount:i}=e;return t!=="server"?i:(n?o??r:r)??i}function Ai(e){return e?{paginationRowsPerPage:e.paginationRowsPerPage,paginationOf:e.paginationOf,paginationPage:e.paginationPage}:void 0}function Pi(e,t){return Number.isFinite(e)?Math.min(Math.max(0,Math.floor(e)),Math.max(0,t-1)):0}function Cc(e){const{effectiveRows:t,activeHierarchyHandlers:n,filterMode:o,filterModel:r,sortModel:i,sortingMode:l,pagination:a,paginationMode:c,effectivePaginationModel:u,pinnedRows:g,getRowId:m,columnLookup:x,hierarchyField:y}=e,p=s.useMemo(()=>n?n.getVisibleRows({labelField:y})||[]:o==="server"?t:So(t,r,x),[t,r,n,y,o,x]),f=s.useMemo(()=>n?o==="server"?t:So(t,r,x):p,[n,p,o,t,r,x]),{top:h,center:b,bottom:w}=s.useMemo(()=>n?{top:[],center:p,bottom:[]}:da(p,g,m),[p,g,n,m]),C=s.useMemo(()=>n||l==="server"?b:Ha(b,i,x,m),[b,i,n,l,x,m]),E=a&&c!=="server",S=Bn(u.pageSize),N=E?Pi(u.page,Oo(C.length,S)):u.page,M=s.useMemo(()=>{if(!E)return C;const F=N*S;return C.slice(F,F+S)},[C,E,N,S]),_=s.useMemo(()=>{const F=a?M:C;return[...h,...F,...w]},[h,M,C,w,a]);return{filteredRows:p,dataRows:f,pinnedTopRows:h,unpinnedRows:b,pinnedBottomRows:w,sortedUnpinnedRows:C,paginatedUnpinnedRows:M,currentPage:N,allRenderableRows:_}}const Do=[33554400,17895e3,1e7,5e6],Ti=new WeakMap;function vc(e){const t=e.body;if(!t)return 1/0;const n=e.createElement("div");n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;top:0;left:-10000px;width:1px;visibility:hidden;pointer-events:none;",t.appendChild(n);try{if(n.style.height="100px",Math.abs(n.getBoundingClientRect().height-100)>1)return 1/0;for(const o of Do)if(n.style.height=`${o}px`,Math.abs(n.getBoundingClientRect().height-o)<2)return o;return Do[Do.length-1]}finally{n.remove()}}function Sc(e){if(!e)return 1/0;const t=Ti.get(e);if(t!==void 0)return t;const n=vc(e);return Ti.set(e,n),n}function _c(e,t){if(!Number.isFinite(t))return e.length;let n=0,o=e.length;for(;n<o;){const r=n+o>>1;e[r]<=t?n=r+1:o=r}return n}const $o="application/x-ogx-row",Go="application/x-ogx-column";function Fi(e,t,n){const o=e.dataTransfer;!o||typeof o.setData!="function"||(o.setData(t,n),o.setData("text/plain",n))}function Wn(e,t){const n=e.dataTransfer?.types;return n?Array.from(n).includes(t):!0}function Oi(e,t){if(!e||typeof e.addEventListener!="function")return()=>{};const n=()=>t();return e.addEventListener("dragend",n,{once:!0}),()=>e.removeEventListener("dragend",n)}function kc(e){const{columns:t,onColumnOrderChange:n,disableColumnReorder:o=!1}=e,[r,i]=s.useState(null),[l,a]=s.useState(null),c=s.useRef(()=>{}),u=s.useCallback(()=>{c.current(),c.current=()=>{},i(null),a(null)},[]);s.useEffect(()=>()=>c.current(),[]);const g=s.useCallback(y=>p=>{if(!o){if(!t.some(f=>f.field===y)){p.preventDefault();return}c.current(),c.current=Oi(p.currentTarget,u),i(y),p.dataTransfer&&(p.dataTransfer.effectAllowed="move",Fi(p,Go,y))}},[t,o,u]),m=s.useCallback(y=>p=>{if(!(o||r===null)){if(!Wn(p,Go)){u();return}p.preventDefault(),p.dataTransfer&&(p.dataTransfer.dropEffect="move"),a(y)}},[r,o,u]),x=s.useCallback(y=>p=>{if(p.preventDefault(),o||r===null||!Wn(p,Go)){u();return}const f=t.findIndex(b=>b.field===r),h=t.findIndex(b=>b.field===y);u(),!(f===-1||h===-1||f===h)&&n?.({column:t[f],oldIndex:f,targetIndex:h})},[t,r,o,n,u]);return{draggedColumn:r,dragOverColumn:l,onDragStart:o?void 0:g,onDragOver:o?void 0:m,onDragEnd:o?void 0:u,onDrop:o?void 0:x}}function Ho({isExpanded:e,onClick:t,variant:n="chevron",tabIndex:o}){return d.jsx("button",{className:`ogx-expand-icon ${e?"ogx-expand-icon--expanded":""}`,onClick:r=>{t&&t(r)},"aria-label":e?"Collapse row":"Expand row",type:"button",tabIndex:o,children:n==="plus-minus"?d.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("path",{d:"M4 8H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),d.jsx("path",{d:"M8 4V12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:e?0:1,transition:"opacity 0.2s ease",transformOrigin:"center"}})]}):d.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"ogx-expand-icon__chevron","aria-hidden":"true",children:d.jsx("path",{d:"M6 4L10 8L6 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function Ec({renderFn:e}){"use no memo";return d.jsx(d.Fragment,{children:e()})}function Mc(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>Object.is(n,t[o])):Object.is(e,t)}class kt extends s.Component{constructor(t){super(t),this.state={hasError:!1,error:null,resetKey:t.resetKey}}static getDerivedStateFromProps(t,n){return Mc(t.resetKey,n.resetKey)?null:n.hasError?{hasError:!1,error:null,resetKey:t.resetKey}:{resetKey:t.resetKey}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){process.env.NODE_ENV!=="production"&&console.warn(`[CellErrorBoundary] field="${this.props.field}"`,t,n.componentStack)}render(){return this.state.hasError?d.jsx("div",{className:"ogx__cell-error",role:"img","aria-label":`Error in cell: ${this.props.field}`,title:this.state.error?.message??"Render error",children:"⚠"}):d.jsx(Ec,{renderFn:this.props.renderFn})}}function Nc(e,t,n){if(!t||!n)return{valueGetter:e.valueGetter,valueFormatter:e.valueFormatter};const o=l=>n.has(l.id),r=e.valueGetter,i=e.valueFormatter;return{valueGetter:r?l=>o(l.row)?l.value:r(l):void 0,valueFormatter:l=>o(l.row)?An(l.value,t,e,l.row):i?i(l):l.value==null?"":String(l.value)}}function Di(e,t){if(!t)return e;const n=t.left??[],o=t.right??[],r=i=>{const l=tt(i.field,t);return l==="left"?n.indexOf(i.field)-n.length:l==="right"?1+o.indexOf(i.field):0};return[...e].sort((i,l)=>r(i)-r(l))}const Vn=e=>e.formattedValue??e.value;function $i(e,t,n){const o=e.renderCell;if(!o)return{useDefault:!0};const r=!!t.rowMeta?.isGroupRow;if(!n){const l=o(t);return r&&l===void 0?{useDefault:!0}:{useDefault:!1,content:l}}let i;try{i=o(t)}catch(l){return{useDefault:!1,content:d.jsx(kt,{field:e.field,resetKey:t.row,renderFn:()=>{throw l}})}}return r&&i===void 0?{useDefault:!0}:{useDefault:!1,content:d.jsx(kt,{field:e.field,resetKey:t.row,renderFn:()=>i})}}function Ic(e,t,n){const o=e.rowMeta;if(!o?.isGroupRow)return Vn(e);if(o.isGroupFooter)return null;const r=o.descendantCount;if(t&&o.hasChildren){const i=o.groupLabel??`${o.groupingField}: ${String(o.groupingValue)}`;return d.jsxs("div",{className:"ogx__group-cell-content",children:[i,r!==void 0?` (${r})`:""]})}return n?d.jsxs("div",{className:"ogx__group-cell-content",children:[o.groupLabel,r!==void 0&&r>0?` (${r})`:""]}):Vn(e)}const Lc=e=>e.id;function Ac(e){const{activeColumns:t,isHierarchyEnabled:n,isRowGrouping:o,isTreeData:r,activeHierarchyHandlers:i,columnVisibilityModel:l,columnOrder:a,onColumnOrderChange:c,onColumnOrderModelChange:u,disableColumnReorder:g,pivotMode:m,checkboxSelection:x,hasDetailPanel:y,rowReordering:p,initialState:f,setColumns:h,pinnedColumns:b,getRowId:w=Lc,aggregationModel:C,groupingRows:E}=e,S=s.useMemo(()=>t.map(V=>V.field),[t]),[N,M]=s.useState(()=>f?.columns?.columnOrder??null),_=m?S.join("\0"):"",[F,A]=s.useState(null),L=F&&F.key===_?F.order:S,I=m?L:a??(N??S),P=s.useCallback(V=>{if(m){A(U=>{const ce=U&&U.key===_?U.order:S;return{key:_,order:typeof V=="function"?V(ce):V}});return}M(U=>typeof V=="function"?V(U??S):V)},[m,_,S]),v=s.useCallback(V=>m&&V.hideable===!1||l[V.field]!==!1,[m,l]),B=s.useMemo(()=>{if(!n)return;const V=new Map(I.map((Q,D)=>[Q,D])),U=Q=>V.get(Q.field)??t.indexOf(Q),ce=[...t].sort((Q,D)=>U(Q)-U(D));return(Di(ce.filter(Q=>l[Q.field]!==!1),b)[0]??t[0])?.field},[n,I,t,l,b]),W=s.useMemo(()=>{if(!n)return t;const V=o?E:void 0;return t.map(U=>{const ce=Nc(U,C?.[U.field],V);return U.field===B?{...U,...ce,renderCell:ge=>{const Q=ge.rowMeta,D=Q?.treeDepth??0,T=!!Q?.hasChildren,$=!!Q?.isExpanded,O=$i(U,ge,!0),Z=O.useDefault?Ic(ge,o,r):O.content;return d.jsxs("div",{style:{display:"flex",alignItems:"center",paddingInlineStart:D*24,width:"100%",height:"100%"},children:[d.jsx("div",{style:{marginInlineEnd:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:T?"pointer":"default",flexShrink:0},children:T?d.jsx("div",{onClick:j=>{j.stopPropagation(),j.preventDefault(),i?.toggleExpansion(w(ge.row))},onMouseDown:j=>{j.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:d.jsx(Ho,{isExpanded:$,tabIndex:-1,onClick:j=>{j.stopPropagation(),j.preventDefault(),i?.toggleExpansion(w(ge.row))}})}):null}),d.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Z})]})}}:{...U,...ce,renderCell:ge=>{const Q=ge.rowMeta;if(!Q?.isGroupRow)return U.renderCell?U.renderCell(ge):Vn(ge);const D=$i(U,ge,!1);return D.useDefault?U.field===Q.groupingField&&!Q.isGroupFooter||ge.value==null?null:Vn(ge):D.content}}})},[t,n,o,r,i,B,w,C,E]),[J,G]=s.useState(()=>f?.columns?.columnWidths??{}),z=s.useCallback((V,U)=>{G(ce=>({...ce,[V]:U}))},[]);s.useEffect(()=>{h(t)},[t,h]);const H=s.useMemo(()=>{const V=new Map(I.map((U,ce)=>[U,ce]));return[...W].sort((U,ce)=>{const ge=V.get(U.field)??W.indexOf(U),Q=V.get(ce.field)??W.indexOf(ce);return ge-Q})},[W,I]),re=s.useMemo(()=>H.filter(v),[H,v]),ee=s.useCallback((V,U)=>{(m||!a)&&P(V),U&&c?.(U),m||u?.(V)},[m,a,P,c,u]),de=s.useCallback((V,U)=>{const ce=H.map(Q=>Q.field),[ge]=ce.splice(V,1);ce.splice(U,0,ge),ee(ce,{column:H[V],oldIndex:V,targetIndex:U})},[H,ee]),ie=kc({columns:H,onColumnOrderChange:s.useCallback(({oldIndex:V,targetIndex:U})=>de(V,U),[de]),disableColumnReorder:g}),ae=s.useCallback((V,U)=>{const ce=H.findIndex(Q=>Q.field===V),ge=H.findIndex(Q=>Q.field===U);ce===-1||ge===-1||ce===ge||de(ce,ge)},[H,de]),R=s.useCallback(()=>{ee(S)},[ee,S]),ue=s.useMemo(()=>Di(re,b),[re,b]),q=s.useMemo(()=>{const V=[];return p&&V.push({field:vt,sortable:!1,editable:!1}),y&&V.push({field:St,sortable:!1,editable:!1}),x&&V.push({field:Ye,sortable:!1,editable:!1}),[...V,...ue]},[ue,x,y,p]),te=s.useMemo(()=>new Map(ue.map((V,U)=>[V.field,U])),[ue]);return{effectiveColumns:W,hierarchyField:B,orderedColumns:H,visibleOrderedColumns:re,renderOrderedColumns:ue,navigationColumns:q,columnIndexMap:te,columnWidths:J,effectiveColumnOrder:I,setInternalColumnOrder:P,columnReorderHandlers:ie,moveColumn:ae,resetColumnOrder:R,handleColumnResize:z}}function Pc(){const[e,t]=s.useState(()=>new Map),n=s.useCallback((o,r)=>{t(i=>{if(i.get(o)===r)return i;const l=new Map(i);return l.set(o,r),l})},[]);return{detailPanelHeights:e,reportDetailPanelHeight:n}}function Tc(e){const{hasDetailPanel:t,controlledExpandedRowIds:n,onDetailPanelExpandedRowIdsChange:o,rowMetaMap:r}=e,[i,l]=s.useState(new Set),a=n??i,c=s.useMemo(()=>xa(a,r),[a,r]),u=s.useCallback(x=>{if(r.get(x)?.isGroupRow)return;const y=new Set(a);y.has(x)?y.delete(x):y.add(x),n===void 0&&l(y),o?.(y)},[a,r,n,o]),{detailPanelHeights:g,reportDetailPanelHeight:m}=Pc();return{hasDetailPanel:t,expandedRowIds:c,handleDetailPanelToggle:u,detailPanelHeights:g,reportDetailPanelHeight:m}}const Fc=new Set(["__group__"]),ln=e=>!Fc.has(e);function Gi(e){return Object.keys(e).every(ln)?e:Object.fromEntries(Object.entries(e).filter(([n])=>ln(n)))}function Oc(e){const t={...e};return e.left&&(t.left=e.left.filter(ln)),e.right&&(t.right=e.right.filter(ln)),t}function Dc(e){const{onStateChange:t,sortModel:n,filterModel:o,effectivePaginationModel:r,columnWidths:i,effectiveColumnOrder:l,columnVisibilityModel:a,pinnedColumns:c,density:u}=e,g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t});const m=s.useRef(null);s.useEffect(()=>{if(!g.current)return;const x={sorting:{sortModel:n},filter:{filterModel:o},pagination:{paginationModel:r},columns:{columnWidths:Gi(i),columnOrder:l.filter(ln),columnVisibilityModel:Gi(a),pinnedColumns:Oc(c)},density:{density:u}},y=JSON.stringify(x);y!==m.current&&(m.current=y,g.current(x))},[n,o,r,i,l,a,c,u])}const $c=200,Gc=2e3,Hc=178e5;function Bc(e){const{paginationRequested:t,isRowGrouping:n,autoHeight:o,viewportHeight:r,renderedRowCount:i,totalRowCount:l,pinnedRowsIgnored:a=!1,scrollHeight:c=0,maxContentHeight:u,reachableRowCount:g,unpinnedRowCount:m,listViewWithoutColumn:x=!1,listViewRowCount:y=0}=e,p=s.useRef(!1),f=s.useRef(!1),h=s.useRef(!1),b=s.useRef(!1),w=s.useRef(!1),C=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||C.current||y<=Gc||(C.current=!0,console.warn(`[OpenGridX] The list view is rendering all ${y} items: it does not virtualize. Above a few thousand items use \`pagination\`, server-side loading, or the grid view. See docs/features/list-view.md.`))},[y]),s.useEffect(()=>{process.env.NODE_ENV==="production"||w.current||!x||(w.current=!0,console.warn("[OpenGridX] `listView` is set without a `listViewColumn`, so the grid view is shown instead. Pass `listViewColumn` to render list items. See docs/features/list-view.md."))},[x]),s.useEffect(()=>{process.env.NODE_ENV==="production"||h.current||!a||(h.current=!0,console.warn("[OpenGridX] `pinnedRows` is ignored while treeData or rowGroupingModel is active: the rows stay in their place in the hierarchy. See docs/features/pinning.md."))},[a]),s.useEffect(()=>{if(process.env.NODE_ENV==="production"||b.current||u===void 0)return;const E=Number.isFinite(u);if(E?c<=u:c<=Hc)return;b.current=!0;const S=E&&g!==void 0&&m!==void 0?`Only the first ${g.toLocaleString("en-US")} of ${m.toLocaleString("en-US")} rows can be scrolled to in this browser. `:"The last rows may not be reachable by scrolling. ";console.warn(`[OpenGridX] The grid content is ${Math.round(c)}px tall, more than this browser lays out (about 17.9M px in Firefox, 33.5M px in Chrome and Safari). `+S+'Load the rows on demand with a `dataSource` (server-side pages or infinite scroll, docs/features/data-source.md), use `pagination`, or a smaller rowHeight (density="compact"). See docs/features/virtualization.md#the-browser-height-limit.')},[c,u,g,m]),s.useEffect(()=>{process.env.NODE_ENV==="production"||p.current||t&&n&&(p.current=!0,console.warn("[OpenGridX] `pagination` is ignored while `rowGroupingModel` is active — all group rows render in one scrollable view. Give the grid a bounded height so it virtualizes. See docs/features/tree-data-grouping.md."))},[t,n]),s.useEffect(()=>{process.env.NODE_ENV==="production"||f.current||o||r>0&&l>$c&&i>=l&&r>=c&&(f.current=!0,console.warn(`[OpenGridX] The grid viewport is ${Math.round(r)}px tall and is rendering all ${l} rows, so row virtualization is effectively off: the grid fills its container, and the container grows to fit every row. Give the container a definite height (for example \`height: 600px\` or \`100vh\`). If the container, or any ancestor up to the sized one, is a flex or grid item, add \`min-height: 0\` to it. Alternatively pass a \`height\` prop, or \`autoHeight\` if rendering every row is intended. See docs/features/virtualization.md.`))},[o,r,i,l,c])}function Wc(e){return typeof window>"u"||typeof window.getComputedStyle!="function"||typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent)?!1:window.getComputedStyle(e).display!=="flex"}let Hi=!1;function Vc(e){s.useEffect(()=>{if(process.env.NODE_ENV==="production"||Hi)return;const t=e.current;!t||!Wc(t)||(Hi=!0,console.warn("[OpenGridX] The grid stylesheet is not loaded, so the grid is unstyled and renders every row (its viewport does not scroll). Add `import '@opencorestack/opengridx/styles'` once in your app root. See README.md, Getting Started."))},[e])}const Bi=e=>JSON.stringify(Array.from(e,t=>typeof t=="number"?["n",t]:["s",t]));function zc(e){const{selectedRowIds:t,rowsLookup:n,rowMetaMap:o,enabled:r,onSelectionModelChange:i}=e,l=s.useMemo(()=>{if(!r||t.size===0)return t;let u=!1;const g=new Set;for(const m of t)n.has(m)||o.has(m)?g.add(m):u=!0;return u?g:t},[r,t,n,o]),a=s.useRef(i);s.useLayoutEffect(()=>{a.current=i});const c=s.useRef(null);return s.useEffect(()=>{if(l===t){c.current=null;return}const u=`${Bi(t)}|${Bi(l)}`;c.current!==u&&(c.current=u,a.current(Array.from(l)))},[l,t]),l}function zn(e,t,n,o){if(n&&o)return t.length>0?[t[t.length-1]]:Array.from(e);const r=new Set(e);return t.forEach(i=>n?r.add(i):r.delete(i)),Array.from(r)}function Rc(e,t,n){return n?e.has(t)?[]:[t]:zn(e,[t],!e.has(t),!1)}function Wi(e,t){return t.length===e.size&&t.every(n=>e.has(n))}function Kc(e){const{selectedRowIds:t,onSelectionModelChange:n,disableMultipleRowSelection:o,selectableRowIds:r}=e,i=s.useCallback(m=>{Wi(t,m)||n(m)},[t,n]),l=s.useCallback((m,x)=>{i(zn(t,[m],x,o))},[i,t,o]),a=s.useCallback(m=>{i(Rc(t,m,o))},[i,t,o]),c=s.useCallback(m=>{i(zn(t,r,m,!1))},[i,t,r]),{allSelected:u,someSelected:g}=s.useMemo(()=>{let m=0;for(const y of r)t.has(y)&&m++;const x=r.length>0&&m===r.length;return{allSelected:x,someSelected:!x&&m>0}},[r,t]);return{toggleRow:l,clickRow:a,selectAll:o?void 0:c,allSelected:u,someSelected:g}}function Uc(e){const{dataRows:t,getRowId:n,isPivotActive:o,selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,disableRowSelectionOnClick:a,isHierarchyEnabled:c,rowMetaMap:u,activeHierarchyHandlers:g,onRowClick:m}=e,x=s.useMemo(()=>{const w=t.map(n);return o?w.filter(C=>C!==Gt):w},[t,n,o]),y=Kc({selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,selectableRowIds:x}),{clickRow:p,toggleRow:f}=y,h=s.useCallback(w=>{const{id:C}=w,E=c?u.get(C):void 0;if(E?.isGroupRow){E.hasChildren&&g?.toggleExpansion(C);return}m?.(w),!a&&!Re(C,u)&&p(C)},[c,g,m,u,a,p]),b=s.useCallback((w,C)=>{Re(w,u)||f(w,C)},[u,f]);return{rowSelection:y,handleRowClick:h,handleSelectionChange:b}}function Bo(e,t,n,o){return o?Wa(e,t,n):n?[{field:t,sort:n}]:e.filter(r=>r.field!==t)}function jc(e){const{sortModel:t,onSortModelChange:n}=e,o=s.useCallback((i,l)=>{n(Bo(t,i,l,!1))},[t,n]),r=s.useCallback((i,l)=>{n(Bo(t,i,l,!0))},[t,n]);return{handleSort:o,handleSortAdd:r}}function qc(e){const{columnVisibilityModel:t,onColumnVisibilityModelChange:n,pinnedColumns:o,onPinnedColumnsChange:r}=e,i=s.useRef({columnVisibilityModel:t,pinnedColumns:o});s.useLayoutEffect(()=>{i.current={columnVisibilityModel:t,pinnedColumns:o}});const l=s.useCallback(c=>{const u={...i.current.columnVisibilityModel,[c]:!1};i.current={...i.current,columnVisibilityModel:u},n(u)},[n]),a=s.useCallback((c,u)=>{const g=ua(i.current.pinnedColumns,c,u);i.current={...i.current,pinnedColumns:g},r(g)},[r]);return{handleHideColumn:l,handlePinColumn:a}}function Xc(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=t.current,r=()=>n.current;o.getSortModel=()=>r().sortModel,o.sortColumn=(c,u)=>{const{sortModel:g,multiSort:m,onSortModelChange:x}=r(),y=Bo(g,c,u,m);n.current={...r(),sortModel:y},x(y)},o.getFilterModel=()=>r().filterModel,o.setFilterModel=c=>{n.current={...r(),filterModel:c},r().onFilterModelChange(c)};const i=c=>{n.current={...r(),paginationModel:c},r().onPaginationModelChange(c)};o.setPage=c=>i({...r().paginationModel,page:c}),o.setPageSize=c=>i({...r().paginationModel,pageSize:c,page:0});const l=()=>{const c=r().getPendingRowSelectionModel?.();return c?new Set(c):r().selectedRowIds},a=(c,u)=>{const{disableMultipleRowSelection:g,onRowSelectionModelChange:m,isSyntheticRowId:x}=r(),y=x?c.filter(h=>!x(h)):c;if(y.length===0)return;const p=l(),f=zn(p,y,u,g);Wi(p,f)||(n.current={...r(),selectedRowIds:new Set(f)},m(f))};o.getSelectedRows=()=>Array.from(l()),o.selectRow=(c,u=!0)=>a([c],u),o.selectRows=(c,u=!0)=>a(c,u),o.getVisibleRows=()=>r().getVisibleRows(),o.getAllFilteredRows=()=>r().getAllFilteredRows(),o.getVisibleColumns=()=>r().visibleColumns,o.setSortModel=c=>{n.current={...r(),sortModel:c},r().onSortModelChange(c)},o.setRowGroupingModel=c=>{n.current={...r(),rowGroupingModel:c},r().onRowGroupingModelChange(c)},o.setAggregationModel=c=>{n.current={...r(),aggregationModel:c},r().onAggregationModelChange(c)},o.setColumnVisibilityModel=c=>{n.current={...r(),columnVisibilityModel:c},r().onColumnVisibilityModelChange(c)},o.setPivotModel=c=>{n.current={...r(),pivotModel:c},r().onPivotModelChange(c)},o.getGridAiState=()=>{const{filterModel:c,sortModel:u,rowGroupingModel:g,aggregationModel:m,pivotModel:x,columnVisibilityModel:y}=r();return{filterModel:c,sortModel:u,rowGroupingModel:g,aggregationModel:m,pivotModel:x,columnVisibilityModel:y}}},[t])}function Yc(e){const{controlledState:t,interactions:n,api:o}=e,{sortModel:r,handleSortModelChange:i,filterModel:l,handleFilterModelChange:a,effectivePaginationModel:c,handlePaginationModelChange:u,handleRowSelectionModelChange:g,rowGroupingModel:m,handleRowGroupingModelChange:x,aggregationModel:y,handleAggregationModelChange:p,columnVisibilityModel:f,handleColumnVisibilityModelChange:h,currentPivotModel:b,handlePivotModelChange:w}=t,C=Uc({...n,selectedRowIds:o.selectedRowIds,onSelectionModelChange:g,disableMultipleRowSelection:o.disableMultipleRowSelection});return Xc({...o,onSortModelChange:i,sortModel:r,filterModel:l,onFilterModelChange:a,paginationModel:c,onPaginationModelChange:u,getPendingRowSelectionModel:t.getPendingRowSelectionModel,onRowSelectionModelChange:g,rowGroupingModel:m,onRowGroupingModelChange:x,aggregationModel:y,onAggregationModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:h,pivotModel:b,onPivotModelChange:w}),C}const Vi="\0";function Jc(e,t){const n=e.filter(o=>t[o.field]===!1).map(o=>o.field).join(Vi);return s.useMemo(()=>{const o={};if(n)for(const r of n.split(Vi))o[r]=!1;return No(e,o)},[e,n])}function Zc({paginationModel:e,currentPage:t,enabled:n,onPaginationModelChange:o}){const r=s.useRef({paginationModel:e,onPaginationModelChange:o});s.useLayoutEffect(()=>{r.current={paginationModel:e,onPaginationModelChange:o}});const i=e.page,l=s.useRef(null);s.useEffect(()=>{if(!n)return;if(t===i){l.current=null;return}const a=`${i}>${t}`;if(l.current===a)return;l.current=a;const{paginationModel:c,onPaginationModelChange:u}=r.current;u({...c,page:t})},[n,t,i])}const Ae=()=>{},Wo=()=>Promise.resolve({updated:[],failed:[],skipped:[]});function zi(){return{getRow:()=>null,getAllRows:()=>[],getVisibleRows:()=>[],getAllFilteredRows:()=>[],getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:()=>null,getAllColumns:()=>[],getVisibleColumns:()=>[],selectRow:Ae,selectRows:Ae,getSelectedRows:()=>[],sortColumn:Ae,getSortModel:()=>[],setFilterModel:Ae,getFilterModel:()=>({items:[]}),setPage:Ae,setPageSize:Ae,scrollToIndexes:Ae,autosizeColumn:Ae,autosizeColumns:Ae,copySelectedRows:()=>Promise.resolve(),getCellSelectionModel:()=>[],setCellSelectionModel:Ae,selectCellRange:Ae,clearCellSelection:Ae,getSelectedCells:()=>[],copySelectedCells:()=>Promise.resolve(),pasteText:Wo,undo:Wo,redo:Wo,canUndo:()=>!1,canRedo:()=>!1,clearHistory:Ae,setSortModel:Ae,setRowGroupingModel:Ae,setAggregationModel:Ae,setColumnVisibilityModel:Ae,setPivotModel:Ae,getGridAiState:()=>({}),openAiAssistant:Ae,closeAiAssistant:Ae}}const Qc=e=>e.id;let Ri=!1;function Ki(e,t,n){const o=new Map,r=new Map,i=[],l=[];return e.forEach(a=>{const c=n?.get(a)??t(a);if(o.has(c)){l.push(c);return}o.set(c,a),r.set(a,c),i.push(c)}),l.length>0&&!Ri&&process.env.NODE_ENV!=="production"&&(Ri=!0,console.warn(`[OpenGridX] ${l.length} row(s) reuse the id of an earlier row and were ignored (ids: ${l.slice(0,5).map(String).join(", ")}${l.length>5?", …":""}). Every row needs a unique id; pass getRowId if the unique key lives in another field.`)),{idRowsLookup:o,allRows:i,idByRow:r}}function ed(e,t,n,o={}){const r=new Map,i=[];return n.forEach(l=>{r.set(l.field,l),i.push(l.field)}),{rows:Ki(e,t),columns:{all:n,lookup:r,orderedFields:i,columnVisibilityModel:o},pagination:{rowCount:void 0},pinning:{pinnedColumns:{},pinnedRows:{}},dimensions:{rowHeight:52,headerHeight:56,viewportWidth:0,viewportHeight:0},dataSource:{loading:!1,error:null}}}function td(e,t){switch(t.type){case"SET_ROWS":{const n=e.rows.allRows.map(r=>e.rows.idRowsLookup.get(r)),o=typeof t.payload=="function"?t.payload(n):t.payload;return{...e,rows:Ki(o,t.getRowId,e.rows.idByRow)}}case"REPLACE_ROW":{const n=e.rows.idRowsLookup.get(t.id);if(n===void 0)return e;const o=new Map(e.rows.idRowsLookup);o.set(t.id,t.row);const r=new Map(e.rows.idByRow);return r.delete(n),r.set(t.row,t.id),{...e,rows:{...e.rows,idRowsLookup:o,idByRow:r}}}case"REPLACE_ROWS":{let n=!1;const o=new Map(e.rows.idRowsLookup),r=new Map(e.rows.idByRow);for(const[i,l]of t.rows){const a=o.get(i);a!==void 0&&(n=!0,o.set(i,l),r.delete(a),r.set(l,i))}return n?{...e,rows:{...e.rows,idRowsLookup:o,idByRow:r}}:e}case"SET_COLUMNS":{const n=new Map,o=[];return t.payload.forEach(r=>{n.set(r.field,r),o.push(r.field)}),{...e,columns:{all:t.payload,lookup:n,orderedFields:o,columnVisibilityModel:e.columns.columnVisibilityModel}}}case"SET_DIMENSIONS":return{...e,dimensions:{...e.dimensions,viewportWidth:t.payload.viewportWidth,viewportHeight:t.payload.viewportHeight}};case"SET_DATASOURCE_LOADING":return{...e,dataSource:{...e.dataSource,loading:t.payload}};case"SET_DATASOURCE_ERROR":return{...e,dataSource:{...e.dataSource,error:t.payload}};case"SET_ROW_COUNT":return{...e,pagination:{...e.pagination,rowCount:t.payload}};default:return e}}function nd(e){const{rows:t,columns:n,rowHeight:o=52,headerHeight:r=56,columnVisibilityModel:i,initialState:l,syncRows:a=!1}=e,c=e.getRowId??Qc,u=s.useRef(c);s.useLayoutEffect(()=>{u.current=c});const[g]=s.useState(()=>ed(t,c,n,i)),[m,x]=s.useReducer(td,{...g,dataSource:l?.dataSource?{...g.dataSource,...l.dataSource}:g.dataSource,pagination:{rowCount:l?.pagination?.rowCount},dimensions:{...g.dimensions,rowHeight:o,headerHeight:r}}),[y,p]=s.useState({rows:t,syncRows:a});(y.rows!==t||y.syncRows!==a)&&(p({rows:t,syncRows:a}),a&&x({type:"SET_ROWS",payload:t,getRowId:c}));const f=s.useRef(m);s.useLayoutEffect(()=>{f.current=m});const h=s.useCallback((A,L)=>{x({type:"SET_ROWS",payload:A,getRowId:u.current})},[]),b=s.useCallback((A,L)=>{x({type:"REPLACE_ROW",id:A,row:L})},[]),w=s.useCallback(A=>{A.size>0&&x({type:"REPLACE_ROWS",rows:A})},[]),C=s.useCallback(A=>{x({type:"SET_COLUMNS",payload:A})},[]),E=s.useCallback((A,L)=>{x({type:"SET_DIMENSIONS",payload:{viewportWidth:A,viewportHeight:L}})},[]),S=s.useCallback(A=>{x({type:"SET_DATASOURCE_LOADING",payload:A})},[]),N=s.useCallback(A=>{x({type:"SET_DATASOURCE_ERROR",payload:A})},[]),M=s.useCallback(A=>{x({type:"SET_ROW_COUNT",payload:A})},[]),[_]=s.useState(()=>({...zi(),getRow:A=>f.current.rows.idRowsLookup.get(A)||null,getAllRows:()=>f.current.rows.allRows.map(A=>f.current.rows.idRowsLookup.get(A)),getColumn:A=>f.current.columns.lookup.get(A)||null,getAllColumns:()=>f.current.columns.all})),F=s.useRef(_);return{state:m,dispatch:x,apiRef:F,setRows:h,replaceRow:b,replaceRows:w,setColumns:C,setDimensions:E,setDataSourceLoading:S,setDataSourceError:N,setRowCount:M}}function od(e){const{onRowOrderChange:t,rows:n,getRowId:o,rowReordering:r=!1}=e,[i,l]=s.useState(null),[a,c]=s.useState(null),u=s.useRef(()=>{}),g=s.useMemo(()=>{const h=new Map;return n.forEach((b,w)=>h.set(o?o(b):b.id,w)),h},[n,o]),m=s.useCallback(h=>g.has(h),[g]),x=s.useCallback(()=>{u.current(),u.current=()=>{},l(null),c(null)},[]);s.useEffect(()=>()=>u.current(),[]);const y=s.useCallback(h=>b=>{if(r){if(!g.has(h)){b.preventDefault();return}u.current(),u.current=Oi(b.currentTarget,x),l(h),b.dataTransfer&&(b.dataTransfer.effectAllowed="move",Fi(b,$o,String(h)))}},[r,g,x]),p=s.useCallback(h=>b=>{if(!(!r||i===null)){if(!Wn(b,$o)){x();return}g.has(h)&&(b.preventDefault(),b.dataTransfer&&(b.dataTransfer.dropEffect="move"),a!==h&&c(h))}},[r,i,a,g,x]),f=s.useCallback(h=>b=>{if(b.preventDefault(),i===null||!Wn(b,$o)){x();return}const w=g.get(i),C=g.get(h);x(),t&&w!==void 0&&C!==void 0&&w!==C&&t({row:n[w],oldIndex:w,targetIndex:C})},[i,t,n,g,x]);return{draggedRowId:i,dragOverRowId:a,canReorderRow:m,onDragStart:r?y:void 0,onDragOver:r?p:void 0,onDragEnd:r?x:void 0,onDrop:r?f:void 0}}const Ui=new Map,ji=e=>JSON.stringify(e),rd=e=>`auto-group-${e}`,qi=5,Xi=e=>e.slice(0,qi).map(t=>JSON.stringify(t)).join(", ")+(e.length>qi?", …":""),id={treeNodes:new Map,rootIds:[],groupingRows:[],syntheticIds:new Set,rowLookup:new Map,issues:[]};function ld(e,t,n){const o=new Map,r=[],i=[],l=new Set,a=new Map,c=new Map,u=[],g=new Array(e.length),m=new Array(e.length),x=[],y=new Map;e.forEach((f,h)=>{const b=t(f),w=n(f),C=Array.isArray(w)?w.map(E=>String(E)):[];if(g[h]=b,m[h]=C,a.set(b,f),C.length===0)x.push(b);else{const E=ji(C),S=c.get(E);if(S===void 0)c.set(E,b);else{const N=y.get(E)??[S];N.push(b),y.set(E,N)}}o.set(b,{id:b,parentId:null,depth:Math.max(C.length-1,0),groupingKey:C[C.length-1]??"",isExpanded:!1,children:[],serverChildrenCount:f.serverChildrenCount})});const p=f=>{const h=ji(f),b=c.get(h);if(b!==void 0)return b;const w=rd(h),C=f[f.length-1],E={id:w,parentId:null,depth:f.length-1,groupingKey:C,isExpanded:!1,children:[],label:C};o.set(w,E),c.set(h,w),l.add(w);const S={id:w};if(i.push(S),a.set(w,S),f.length===1)r.push(w);else{const N=p(f.slice(0,-1));E.parentId=N,o.get(N)?.children?.push(w)}return w};return e.forEach((f,h)=>{const b=g[h],w=m[h];if(w.length<=1){r.push(b);return}const C=p(w.slice(0,-1)),E=o.get(b);E&&(E.parentId=C),o.get(C)?.children?.push(b)}),x.length>0&&u.push(`[OpenGridX] treeData: getTreeDataPath returned an empty path for row(s) ${Xi(x)}. They are shown as top-level rows.`),y.forEach((f,h)=>{u.push(`[OpenGridX] treeData: rows ${Xi(f)} have the same path ${h}. Rows under that path are attached to row ${JSON.stringify(f[0])}.`)}),{treeNodes:o,rootIds:r,groupingRows:i,syntheticIds:l,rowLookup:a,issues:u}}function sd(e,t){const{treeNodes:n,rootIds:o,syntheticIds:r,rowLookup:i}=e,l=new Set,a=new Map,c=new Map,u=g=>{const m=n.get(g);if(!m)return!1;const x=[];let y=0;for(const b of m.children??[])u(b)&&(x.push(b),y+=(r.has(b)?0:1)+(c.get(b)??0));a.set(g,x),c.set(g,y);const p=i.get(g),h=!r.has(g)&&p!==void 0&&(t?t(p):!0)||x.length>0;return h&&l.add(g),h};return o.forEach(u),{visible:l,visibleChildren:a,descendantCounts:c}}function ad(e){const{rows:t,getRowId:n,getTreeDataPath:o,treeData:r=!1,defaultGroupingExpansionDepth:i=0,filterModel:l,sortModel:a,onRowExpansionChange:c,columnLookup:u,filterMode:g="client",sortingMode:m="client"}=e,x=r&&!!o,y=s.useMemo(()=>!r||!o?id:ld(t,n,o),[t,o,r,n]),{treeNodes:p,rootIds:f,groupingRows:h,syntheticIds:b,rowLookup:w}=y,C=y.issues.join(`
|
|
1
|
+
(function(Se,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],d):(Se=typeof globalThis<"u"?globalThis:Se||self,d(Se.OpenGridX={},Se.ReactJSXRuntime,Se.React,Se.ReactDOM))})(this,(function(Se,d,s,st){"use strict";"use client";function co(e,t,n){return Math.max(t??0,Math.min(n??1/0,e))}function xt(e,t,n=100){if(e.isSpacer)return typeof e.width=="number"?e.width:0;const o=t[e.field]??e.width,r=typeof o=="number"&&Number.isFinite(o)?o:n;return co(r,e.minWidth,e.maxWidth)}const He=48;function tt(e,t){return t?t.left?.includes(e)?"left":t.right?.includes(e)?"right":null:null}function ga(e,t){const n=[],o=[],r=[];return t?(e.forEach(i=>{const l=tt(i.field,t);l==="left"?n.push(i):l==="right"?r.push(i):o.push(i)}),t.left&&n.sort((i,l)=>{const c=t.left.indexOf(i.field),a=t.left.indexOf(l.field);return c-a}),t.right&&r.sort((i,l)=>{const c=t.right.indexOf(i.field),a=t.right.indexOf(l.field);return c-a}),{left:n,center:o,right:r}):{left:n,center:e,right:r}}function uo(e,t,n,o,r,i,l,c){const a={};if(!n)return a;let u=(c?He:0)+(i&&l?He:0)+(o&&r?He:0);const g=[];e.forEach(x=>{if(x.isSpacer)return;const y=tt(x.field,n);y==="left"?(a[x.field]=u,u+=xt(x,t)):y==="right"&&g.push(x)});let p=0;for(let x=g.length-1;x>=0;x--)a[g[x].field]=p,p+=xt(g[x],t);return a}function fo(e,t){let n=null,o=null;if(!t)return{lastLeft:n,firstRight:o};for(const r of e){if(r.isSpacer)continue;const i=tt(r.field,t);i==="left"?n=r.field:i==="right"&&o===null&&(o=r.field)}return{lastLeft:n,firstRight:o}}function Vr(e,t){return t?t.top?.includes(e)?"top":t.bottom?.includes(e)?"bottom":null:null}function pa(e,t,n=o=>o.id){const o=[],r=[],i=[];return t?(e.forEach(l=>{const c=Vr(n(l),t);c==="top"?o.push(l):c==="bottom"?i.push(l):r.push(l)}),t.top&&o.sort((l,c)=>{const a=t.top.indexOf(n(l)),u=t.top.indexOf(n(c));return a-u}),t.bottom&&i.sort((l,c)=>{const a=t.bottom.indexOf(n(l)),u=t.bottom.indexOf(n(c));return a-u}),{top:o,center:r,bottom:i}):{top:o,center:e,bottom:i}}function ha(e,t,n){const o=(e?.left??[]).filter(i=>i!==t),r=(e?.right??[]).filter(i=>i!==t);return n==="left"?{left:[...o,t],right:r}:n==="right"?{left:o,right:[...r,t]}:{left:o,right:r}}const zr=new Set;function yt(e,t,n){process.env.NODE_ENV==="production"||zr.has(e)||(zr.add(e),console.warn(`[OpenGridX] ${t}.`,n))}function go(e,t,n,o){try{return e()}catch(r){return yt(n,o,r),t}}function Kr(e,t,n){const o=e[t];if(!n?.valueGetter)return{value:o};try{return{value:n.valueGetter({row:e,field:t,value:o})}}catch(r){return{value:void 0,error:r??new Error("valueGetter failed")}}}function Ee(e,t,n){if(!n?.valueGetter)return e[t];const{value:o,error:r}=Kr(e,t,n);return r!==void 0&&yt(`valueGetter:${t}`,`valueGetter for column "${t}" threw; the value is read as undefined`,r),o}function po(e,t,n,o){const r=o?.valueFormatter;if(r)try{return r({value:n,row:e,field:t})}catch(i){yt(`valueFormatter:${t}`,`valueFormatter for column "${t}" threw; the value is shown unformatted`,i);return}}const ma=/^[+-]?0[box]/i;function nt(e){if(e==null)return null;if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e=="string"){const t=e.trim();if(t===""||ma.test(t))return null;const n=Number(t);return Number.isFinite(n)?n:null}if(typeof e=="boolean")return null;if(e instanceof Date){const t=e.getTime();return Number.isNaN(t)?null:t}return typeof e=="bigint"?Number(e):null}const wa=/^(\d{4})-(\d{2})-(\d{2})$/;function Qt(e){if(e==null)return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else if(typeof e=="string"){const n=e.trim();if(n==="")return null;const o=wa.exec(n);if(o){const r=Number(o[1]),i=Number(o[2])-1,l=Number(o[3]);if(t=new Date(r,i,l),t.getMonth()!==i||t.getDate()!==l)return null}else{if(!Ca(n))return null;t=new Date(n)}}else return null;return Number.isNaN(t.getTime())?null:t}const ba=["january","february","march","april","may","june","july","august","september","october","november","december","monday","tuesday","wednesday","thursday","friday","saturday","sunday"],xa=new Set(["t","z","am","pm","gmt","utc","sept"]);function ya(e){return xa.has(e)?!0:e.length>=3&&ba.some(t=>t.startsWith(e))}function Ca(e){let t="";for(let n=0;n<=e.length;n++){const o=n<e.length?e[n].toLowerCase():"";if(o>="a"&&o<="z"){t+=o;continue}if(t!==""&&!ya(t))return!1;t=""}return!0}function kn(e){const t=Qt(e);return t?t.getFullYear()*1e4+(t.getMonth()+1)*100+t.getDate():null}function Rr(e){const t=Qt(e);if(!t)return"";const n=String(t.getFullYear()).padStart(4,"0"),o=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${n}-${o}-${r}`}let Ur=null;function jr(e){return Ur??=new Intl.DateTimeFormat,Ur.format(e)}function va(e,t){if(!e)return;const n=i=>typeof i=="object"?i.value:i,o=i=>typeof i=="object"?i.label:String(i),r=e.find(i=>Object.is(n(i),t))??e.find(i=>String(n(i))===String(t));return r===void 0?void 0:o(r)}function En(e,t){if(e==null)return"";switch(t?.type){case"date":{const n=Qt(e);return n?jr(n):String(e)}case"boolean":return e===!0?"Yes":e===!1?"No":String(e);case"singleSelect":return va(t.valueOptions,e)??String(e);default:return String(e)}}const ho=200;function mo(e){if(e==="auto")return"auto";const t=typeof e=="string"?Number.parseFloat(e):e;return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:ho}function wo(e,t){if(e)return go(()=>e(t),void 0,"getDetailPanelHeight","getDetailPanelHeight threw; the panel uses the default height")}function Sa(e,t){const n=mo(e);return n==="auto"?t??ho:n}function _a(e,t){if(t.size===0||e.size===0)return e;let n=!1;const o=new Set;for(const r of e)t.get(r)?.isGroupRow?n=!0:o.add(r);return n?o:e}const ka=e=>e.id;function Ea(e){if(e===void 0)return{type:"auto",value:0};if(typeof e=="number")return{type:"fixed",value:e};if(typeof e=="string"){if(e.toLowerCase()==="auto")return{type:"auto",value:0};if(e.endsWith("%"))return{type:"percentage",value:parseFloat(e)};const t=parseFloat(e);if(!isNaN(t))return{type:"fixed",value:t}}return{type:"fixed",value:100}}function Ma(e,t,n){const o=new Map;e.forEach(f=>{if(!Object.prototype.hasOwnProperty.call(t,f.field)&&f.flex&&f.flex>0){o.set(f.field,{kind:"flex",flex:f.flex});return}const b=Ea(t[f.field]??f.width);b.type==="fixed"?o.set(f.field,{kind:"fixed",width:co(b.value,f.minWidth,f.maxWidth)}):b.type==="percentage"?o.set(f.field,{kind:"percentage",percentage:b.value}):o.set(f.field,{kind:"flex",flex:1})});const r=e.reduce((f,w)=>{const b=o.get(w.field);if(b.kind==="fixed")return f+b.width;if(b.kind==="percentage")return f+100;if(w.flex&&w.flex>0){const m=w.minWidth??150;return f+(m||(typeof w.width=="number"?w.width:150))}return f+(w.minWidth??150)},0),i=Math.max(n,r),l=e.reduce((f,w)=>{const b=o.get(w.field);return b.kind==="fixed"?f+b.width:f},0),c=new Map,a=Math.max(0,i-l);let u=0;e.forEach(f=>{const w=o.get(f.field);if(w.kind==="fixed")c.set(f.field,w.width);else if(w.kind==="percentage"){const b=w.percentage/100*a,m=co(b>0?b:100,f.minWidth??50,f.maxWidth);c.set(f.field,m),u+=m}});const g=Math.max(0,a-u),p=new Map,x=e.flatMap(f=>{const w=o.get(f.field);return w.kind!=="flex"?[]:(p.set(f.field,w.flex),[{field:f.field,flex:w.flex,minWidth:f.minWidth??50,maxWidth:f.maxWidth??1/0,frozen:!1,computedWidth:0}])});let y=0;const h=x.length*2;for(;y<h;){y++;const f=x.filter(M=>!M.frozen);if(f.length===0)break;const w=f.reduce((M,S)=>M+S.flex,0),b=x.reduce((M,S)=>S.frozen?M+S.computedWidth:M,0),m=Math.max(0,g-b);if(w<=0){f.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0});break}const C=m/w;let E=0;const _=[],I=[];if(f.forEach(M=>{const S=C*M.flex;S<M.minWidth?(E+=M.minWidth-S,_.push(M)):S>M.maxWidth?(E+=M.maxWidth-S,I.push(M)):M.computedWidth=S}),_.length===0&&I.length===0){f.forEach(M=>{M.frozen=!0});break}E>0?_.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}):E<0?I.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}):(_.forEach(M=>{M.computedWidth=M.minWidth,M.frozen=!0}),I.forEach(M=>{M.computedWidth=M.maxWidth,M.frozen=!0}))}return x.forEach(f=>c.set(f.field,f.computedWidth)),{widths:c,flexByField:p}}function Ia(e){const{rowHeight:t,pagination:n,paginatedUnpinnedRows:o,sortedUnpinnedRows:r,expandedRowIds:i,getDetailPanelHeight:l,detailPanelHeights:c,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,pinnedTopRows:g,pinnedBottomRows:p,visibleOrderedColumns:x,pinnedColumns:y,columnWidths:h,viewportWidth:f,checkboxSelection:w,hasDetailPanel:b,rowReordering:m,pinCheckboxColumn:C,pinExpandColumn:E,paginationMode:_,isLoading:I,pageSize:M,getRowId:S=ka}=e,F=s.useMemo(()=>{const L=n?o:r,k=(te,ce)=>{const oe=S(te);if(!i.has(oe))return t;const de=wo(l,{row:te,id:oe,rowIndex:ce});return t+Sa(de,c?.get(oe))},N=L.length,T=new Array(N),v=new Array(N),W=i.size>0;let B=0;for(let te=0;te<N;te++){const ce=W?k(L[te],a+te):t;T[te]=ce,B=(B||0)+ce,v[te]=B}const Q=_==="infinite"&&I&&L.length>0?Math.min(M,20):0,$=(v[v.length-1]||0)+Q*t,z=(te,ce)=>te?te.reduce((oe,de,X)=>oe+k(de,X),0):ce*t,V=z(g,a),ie=z(p,u);return{rowHeights:T,cumulativeHeights:v,unpinnedRowsHeight:$,pinnedTopHeight:V,pinnedBottomHeight:ie,pinnedTopRowsLength:a,pinnedBottomRowsLength:u,unpinnedRowsLength:N}},[t,n,o,r,i,l,c,a,u,g,p,_,I,M,S]),P=s.useMemo(()=>{const{left:L,center:k,right:N}=ga(x,y),T=(w?He:0)+(b?He:0)+(m?He:0),v=(m?He:0)+(b&&E?He:0)+(w&&C?He:0),{widths:W,flexByField:B}=Ma([...L,...k,...N],h,f-T),Q=H=>W.get(H.field)??100,$=H=>({...H,width:Q(H),flex:B.get(H.field)??H.flex}),z=11,V=L.map((H,R)=>({...$(H),zIndex:z+R})),ie=11,te=N.map((H,R)=>({...$(H),zIndex:ie+(N.length-1-R)})),ce=k.map($),oe=ce.map(H=>H.width),de=V.reduce((H,R)=>H+R.width,0),X=te.reduce((H,R)=>H+R.width,0),ne=oe.reduce((H,R)=>H+R,0),se=de+ne+X+T,Y=oe.reduce((H,R,ae)=>(H.push((H[ae-1]||0)+R),H),[]);return{leftPinnedCols:V,rightPinnedCols:te,unpinnedColsWithWidth:ce,unpinnedColWidths:oe,unpinnedAccWidths:Y,totalWidth:se,leftWidth:de,rightWidth:X,unpinnedTotalWidth:ne,systemColumnsWidth:T,pinnedSystemColumnsWidth:v}},[x,y,h,f,w,b,m,C,E]);return s.useMemo(()=>({...F,...P}),[F,P])}function Xe(e){if(!e)return!1;const t=e.ownerDocument.defaultView;return t?t.getComputedStyle(e).direction==="rtl":!1}function Mn(e,t){return t?e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e:e}function Ot(e){return Xe(e)?-e.scrollLeft:e.scrollLeft}function en(e,t){e.scrollLeft=Xe(e)?-t:t}function In(e,t){if(!e)return{top:0,right:0};const n=e.getBoundingClientRect();return Xe(e)?{top:n.bottom+6,left:n.left}:{top:n.bottom+6,right:t-n.right}}function Na(e){const t=e.querySelector(".ogx__sticky-bottom");return t?t.getBoundingClientRect().height:0}function Nn(e,t,n,o,r){if(t<0||t>=n.length)return;const i=e.querySelector(".ogx__virtual-container");if(!i)return;const{scrollTop:l,clientHeight:c}=e,a=i.getBoundingClientRect().top-e.getBoundingClientRect().top+l,u=Math.max(o,Na(e)),g=a+(t===0?0:n[t-1]),p=r!==void 0?Math.min(g+r,a+n[t]):a+n[t];g<l+a?e.scrollTop=Math.max(0,g-a):p>l+c-u&&(e.scrollTop=p-c+u)}function bo(e,t,n){const{unpinnedAccWidths:o,leftWidth:r,rightWidth:i,systemColumnsWidth:l,pinnedSystemColumnsWidth:c}=n;if(t<0||t>=o.length)return;const a=l+r,u=a+(t>0?o[t-1]:0),g=a+o[t],p=c+r,{clientWidth:x}=e,y=Ot(e);u<y+p?en(e,Math.max(0,u-p)):g>y+x-i&&en(e,g-x+i)}function xo(e,t){const{row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:c,rowMeta:a}=e;if(!i.editable||a?.isGroupRow)return!1;if(!t)return!0;try{return!!t({row:n,field:o,value:r,colDef:i,rowIndex:l,colIndex:c})}catch{return!1}}const La={},tn=e=>e==null||typeof e=="string"&&e.trim()==="",qr=e=>{const t=[];for(const n of e){const o=nt(n);o!==null&&t.push(o)}return t},Xr=(e,t)=>{let n=null,o=null;for(const r of e){const i=nt(r);i!==null&&(n===null||t(i,n))&&(n=i,o=r)}return n===null?null:o instanceof Date?o:n},at={sum:e=>qr(e).reduce((t,n)=>t+n,0),avg:e=>{const t=qr(e);return t.length?t.reduce((n,o)=>n+o,0)/t.length:null},count:e=>e.filter(t=>!tn(t)).length,min:e=>Xr(e,(t,n)=>t<n),max:e=>Xr(e,(t,n)=>t>n),unique:e=>new Set(e.filter(t=>!tn(t))).size};function yo(e,t){return e?e.aggregable===!1?!1:!e.availableAggregationFunctions||e.availableAggregationFunctions.includes(t):!0}function Ln(e,t,n,o){const r={};for(const[i,l]of Object.entries(t)){const c=n.get(i);if(!yo(c,l))continue;const a=at[l];if(!a){console.warn(`[${o}] Unknown aggregation function: "${l}"`);continue}r[i]=Object.prototype.hasOwnProperty.call(at,l)?Pa(e,i,c,l):a(e.map(u=>Ee(u,i,c)))}return r}function Pa(e,t,n,o){switch(o){case"sum":case"avg":{let r=0,i=0;for(const l of e){const c=nt(Ee(l,t,n));c!==null&&(r+=c,i++)}return o==="sum"?r:i?r/i:null}case"count":{let r=0;for(const i of e)tn(Ee(i,t,n))||r++;return r}case"min":case"max":{const r=o==="min";let i=null,l=null;for(const c of e){const a=Ee(c,t,n),u=nt(a);u!==null&&(i===null||(r?u<i:u>i))&&(i=u,l=a)}return i===null?null:l instanceof Date?l:i}case"unique":{const r=new Set;for(const i of e){const l=Ee(i,t,n);tn(l)||r.add(l)}return r.size}}}function nn(e,t){return e==null?"—":typeof e=="number"?t==="avg"?e.toLocaleString(void 0,{maximumFractionDigits:2}):e.toLocaleString():String(e)}const Ta=new Set(["count","unique"]);function Yr(e){return e!==void 0&&Ta.has(e)}function Jr(e,t,n){return e?.type==="date"&&(t==="min"||t==="max")&&typeof n=="number"&&Number.isFinite(n)?new Date(n):n}function Pn(e,t,n,o){if(e==null)return"—";if(Yr(t))return nn(e,t);const r=Jr(n,t,e);if(n?.valueFormatter)try{return String(n.valueFormatter({value:r,row:o??{},field:n.field})??"")}catch{}return r instanceof Date?Number.isNaN(r.getTime())?"":jr(r):nn(r,t)}const Dt=new Set(["isEmpty","isNotEmpty"]);function Co(e){return e==null?!0:typeof e=="string"?e.trim()==="":Array.isArray(e)?e.length===0:!1}function Aa(e){return e==null?!0:typeof e=="number"?Number.isNaN(e):typeof e=="string"&&e.trim()===""}const on=e=>(t,n)=>{const o=nt(t),r=nt(n);return o===null||r===null?!1:e(o,r)},rn=e=>(t,n)=>{const o=kn(t),r=kn(n);return o===null||r===null?!1:e(o,r)},Zr=rn((e,t)=>e===t),Qr=(e,t)=>{const n=kn(e),o=kn(t);return n===null||o===null?!0:n!==o},ei={contains:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase()),equals:(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:String(e).toLowerCase()===String(t).toLowerCase(),startsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().startsWith(String(t).toLowerCase()),endsWith:(e,t)=>e==null||t==null?!1:String(e).toLowerCase().endsWith(String(t).toLowerCase()),isEmpty:e=>e==null||String(e).trim()==="",isNotEmpty:e=>e!=null&&String(e).trim()!=="","=":on((e,t)=>e===t),">":on((e,t)=>e>t),">=":on((e,t)=>e>=t),"<":on((e,t)=>e<t),"<=":on((e,t)=>e<=t),"!=":(e,t)=>{if(Co(t))return!0;const n=nt(e),o=nt(t);return n!==null&&o!==null?n!==o:Aa(e)?!0:String(e).toLowerCase()!==String(t).toLowerCase()},isAnyOf:(e,t)=>{if(e==null)return!1;const n=Array.isArray(t)?t:[t],o=String(e).toLowerCase();return n.some(r=>r!=null&&String(r).toLowerCase()===o)},not:(e,t)=>e instanceof Date?Qr(e,t):e==null&&t==null?!1:e==null||t==null?!0:String(e).toLowerCase()!==String(t).toLowerCase(),is:(e,t)=>t==null||t===""?!0:e instanceof Date?Zr(e,t):String(e).toLowerCase()===String(t).toLowerCase(),after:rn((e,t)=>e>t),onOrAfter:rn((e,t)=>e>=t),before:rn((e,t)=>e<t),onOrBefore:rn((e,t)=>e<=t)},Fa={is:Zr,not:Qr};function Oa(e,t){if(!Object.prototype.hasOwnProperty.call(ei,e))return;const n=e;if(t?.type==="date"){const o=Fa[n];if(o)return o}return ei[n]}function Da(e){return"items"in e&&Array.isArray(e.items)}function $a(e,t){const{field:n,operator:o,value:r}=e;if(!Dt.has(o)&&Co(r))return null;const i=t.columns?.byField.get(n),l=Oa(o,i);return l?c=>l(Ee(c,n,i),r):(t.warned.has(o)||(t.warned.add(o),console.warn(`Unknown filter operator: ${o}`)),null)}function vo(e,t,n){const o=[];for(const r of e){const i=Da(r)?vo(r.items,r.logicOperator,n):$a(r,n);i&&o.push(i)}return o.length===0?null:o.length===1?o[0]:t==="or"?r=>o.some(i=>i(r)):r=>o.every(i=>i(r))}function So(e,t){if(t!=null){switch(typeof t){case"string":e.push(t.toLowerCase());return;case"number":Number.isNaN(t)||e.push(String(t));return;case"boolean":case"bigint":e.push(String(t));return}if(t instanceof Date){const n=Rr(t);n&&e.push(n);return}if(Array.isArray(t))for(const n of t)(n==null||typeof n!="object")&&So(e,n)}}function _o(e,t){const n=[];if(!t){for(const o of Object.values(e))So(n,o);return n}for(const o of t.quickFilterColumns){const r=Ee(e,o.field,o),i=po(e,o.field,r,o);if(i!=null&&i!=="")n.push(String(i).toLowerCase());else if(o.type==="date"||o.type==="boolean"||o.type==="singleSelect"){const l=En(r,o);l!==""&&n.push(l.toLowerCase())}So(n,r)}return n}const ti=new WeakMap;function Ga(e,t){if(!t)return _o(e,t);let n=ti.get(t);n||(n=new WeakMap,ti.set(t,n));let o=n.get(e);return o||(o=_o(e,t),n.set(e,o)),o}function ni(e){return(e??[]).map(t=>String(t??"").trim().toLowerCase()).filter(t=>t!=="")}function oi(e,t){for(let n=0;n<t.length;n++){const o=t[n];let r=!1;for(let i=0;i<e.length;i++)if(e[i].includes(o)){r=!0;break}if(!r)return!1}return!0}function Ha(e,t){const n=ni(e);return n.length===0?null:o=>oi(Ga(o,t),n)}const ri=new WeakMap;function Ba(e,t){const n=ri.get(t);if(n&&n.rows===e)return n.texts;const o=new Array(e.length);for(let r=0;r<e.length;r++){const i=e[r];o[r]=n&&r<n.rows.length&&n.rows[r]===i?n.texts[r]:_o(i,t)}return ri.set(t,{rows:e,texts:o}),o}function Tn(e,t){if(!e)return null;const n={columns:t,warned:new Set},o="quickFilterValues"in e?e.quickFilterValues:void 0,r=Ha(o,t),i=vo(e.items??[],e.logicOperator??"and",n);return r&&i?l=>r(l)&&i(l):r??i}function ko(e,t,n){const o=n&&t?ni(t.quickFilterValues):[];if(n&&o.length>0){const i=vo(t.items??[],t.logicOperator??"and",{columns:n,warned:new Set}),l=Ba(e,n),c=[];for(let a=0;a<e.length;a++)oi(l[a],o)&&(!i||i(e[a]))&&c.push(e[a]);return c}const r=Tn(t,n);return r?e.filter(i=>r(i)):e}function ii(e){switch(e){case"number":return["=","!=",">",">=","<","<=","isEmpty","isNotEmpty"];case"date":return["is","not","after","onOrAfter","before","onOrBefore","isEmpty","isNotEmpty"];case"boolean":return["is"];case"singleSelect":return["isAnyOf","is","not"];default:return["contains","equals","startsWith","endsWith","isEmpty","isNotEmpty"]}}function Eo(e,t){return e==null?"":t==="date"||e instanceof Date?Rr(e)||(typeof e=="string"?e:""):Array.isArray(e)?e.map(n=>String(n)).join(", "):String(e)}const Mo=new Intl.Collator(void 0,{numeric:!0,sensitivity:"accent"}),$t=0,li=1,Wa=2,Io=3,An=4;function ln(e,t){return{rank:e,num:t,str:""}}function Fn(e,t){if(e==null)return null;if(t==="number"){if(typeof e=="bigint")return{rank:$t,num:Number(e),str:"",big:e};const n=nt(e);return n===null?null:ln($t,n)}if(t==="date"){const n=Qt(e);return n?ln(li,n.getTime()):null}switch(typeof e){case"number":return Number.isNaN(e)?null:ln($t,e);case"bigint":return{rank:$t,num:Number(e),str:"",big:e};case"boolean":return ln(Wa,e?1:0);case"string":return{rank:Io,num:0,str:e}}if(e instanceof Date){const n=e.getTime();return Number.isNaN(n)?null:ln(li,n)}return{rank:An,num:0,str:String(e)}}function si(e,t){return e===null&&t===null?0:e===null?1:t===null?-1:e.rank!==t.rank?e.rank-t.rank:e.rank===Io||e.rank===An?Mo.compare(e.str,t.str):e.num!==t.num?e.num<t.num?-1:1:e.big!==void 0||t.big!==void 0?On(e.big??e.num,t.big??t.num):0}function On(e,t){if(typeof e=="number"&&typeof t=="number"||typeof e=="bigint"&&typeof t=="bigint")return e<t?-1:e>t?1:0;if(typeof e=="number")return-On(t,e);const n=t;if(!Number.isFinite(n))return n>0?-1:1;const o=Math.floor(n),r=BigInt(o);return e<r?-1:e>r?1:n>o?-1:0}const Va=e=>typeof e=="bigint"&&(e>BigInt(Number.MAX_SAFE_INTEGER)||e<BigInt(Number.MIN_SAFE_INTEGER));function No(e,t){return e===0?0:t==="asc"?e:-e}function za(e,t,n,o){return No(si(Fn(e,o),Fn(t,o)),n)}function ai(e,t,n){let o;try{o=e(t.value,n.value,t,n)}catch(r){return yt(`sortComparator:${t.field}`,`sortComparator for column "${t.field}" threw; the values are treated as equal`,r),0}return typeof o!="number"||Number.isNaN(o)?(yt(`sortComparator:${t.field}:nan`,`sortComparator for column "${t.field}" returned ${String(o)}; the values are treated as equal`,void 0),0):o}const Ka=e=>e.id;function Ra(e,t,n,o=Ka){if(t.length===0)return e;if(e.length<2)return[...e];const r=t.map(i=>{const l=n?.byField.get(i.field),c=l?.sortComparator;if(c)return pi(e.map(u=>{const g=Ee(u,i.field,l);return{value:g,type:l.type,comparator:c,params:{id:o(u),field:i.field,row:u,value:g}}}));const a=l?.type;return gi(e.length,u=>Ee(e[u],i.field,l),()=>a)});return hi(e,t,r)}function ci(e,t,n){if(t.length===0||e.length<2)return[...e];const o=t.map(r=>{const i=e.map(l=>n(l,r));return i.some(l=>l.comparator&&l.params)?pi(i):gi(i.length,l=>i[l].value,l=>i[l].type)});return hi(e,t,o)}const di=An+1;function ui(e,t){const n=[...e.keys()].sort(Mo.compare);let o=0;for(let r=0;r<n.length;r++){r>0&&Mo.compare(n[r-1],n[r])!==0&&o++;for(const i of e.get(n[r])??[])t[i]=o}}function Ua(e,t,n){const o=[];for(let l=0;l<e.length;l++)e[l]===$t&&o.push(l);const r=l=>n.get(l)??t[l];o.sort((l,c)=>On(r(l),r(c)));let i=0;for(let l=0;l<o.length;l++)l>0&&On(r(o[l-1]),r(o[l]))!==0&&i++,t[o[l]]=i}function fi(e,t,n){const o=e.get(t);o?o.push(n):e.set(t,[n])}function gi(e,t,n){const o=new Uint8Array(e),r=new Float64Array(e),i=new Map,l=new Map;let c=null;for(let a=0;a<e;a++){const u=t(a),g=n(a);if(Va(u)&&g!=="date"&&(c??=new Map).set(a,u),typeof u=="number"&&g!=="date"){Number.isNaN(u)?o[a]=di:(o[a]=$t,r[a]=u);continue}const p=Fn(u,g);p===null?o[a]=di:(o[a]=p.rank,p.rank===Io?fi(i,p.str,a):p.rank===An?fi(l,p.str,a):r[a]=p.num)}return ui(i,r),ui(l,r),c&&Ua(o,r,c),{kind:"encoded",group:o,num:r}}function pi(e){return{kind:"generic",values:e,keys:e.map(({value:t,type:n})=>Fn(t,n))}}function ja(e,t,n){if(e.kind==="encoded"){const i=e.group[t],l=e.group[n];if(i!==l)return i-l;const c=e.num[t],a=e.num[n];return c<a?-1:c>a?1:0}const o=e.values[t],r=e.values[n];return o.comparator&&o.comparator===r.comparator&&o.params&&r.params?ai(o.comparator,o.params,r.params):si(e.keys[t],e.keys[n])}function hi(e,t,n){const o=e.length,r=new Array(o);for(let c=0;c<o;c++)r[c]=c;const i=n[0];if(n.length===1&&i.kind==="encoded"){const{group:c,num:a}=i,u=t[0].sort==="asc"?1:-1;r.sort((g,p)=>{const x=c[g],y=c[p];if(x!==y)return(x-y)*u;const h=a[g],f=a[p];return h<f?-u:h>f?u:g-p})}else r.sort((c,a)=>{for(let u=0;u<n.length;u++){const g=No(ja(n[u],c,a),t[u].sort);if(g!==0)return g}return c-a});const l=new Array(o);for(let c=0;c<o;c++)l[c]=e[r[c]];return l}function qa(e,t,n){if(!n)return e.filter(r=>r.field!==t);const o=e.findIndex(r=>r.field===t);return o===-1?[...e,{field:t,sort:n}]:e.map((r,i)=>i===o?{field:t,sort:n}:r)}function Lo(e,t={}){const n=new Map,o=[];for(const r of e)n.set(r.field,r),!(r.isSpacer||r.field.startsWith("__"))&&r.filterable!==!1&&t[r.field]!==!1&&o.push(r);return{byField:n,quickFilterColumns:o}}const Gt="__pivot_grand_total__",Xa="__pivot_row__:",mi=e=>`${Xa}${JSON.stringify(e.split(wi))}`,Ya="Grand Total",wi="\0",Ht="",Po=`${Ht}id`,bi=e=>e==="id"?Po:e,To={pivotRows:[],pivotColumns:[],colKeys:[],isValid:!1},xi=e=>e.map(t=>String(t??"")).join(wi),yi=e=>e===void 0||e===""?null:e;function Ja(e,t){const n=e==null,o=t==null;return n||o?n===o?0:n?1:-1:typeof e=="number"&&typeof t=="number"?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():typeof e=="boolean"&&typeof t=="boolean"?Number(e)-Number(t):String(e).localeCompare(String(t),void 0,{numeric:!0})}function Za(e,t){for(let n=0;n<e.length;n++){const o=Ja(e[n],t[n]);if(o!==0)return o}return 0}function Ci(e,t){if(!e||e.length===0)return null;const n=at[t](e);return typeof n=="number"||n instanceof Date?n:null}const Qa=e=>"logicOperator"in e&&"items"in e,ec=e=>!!(e&&e.items&&e.items.length>0);function tc(e,t){const n=l=>!t.has(l)&&l.includes(Ht),o=l=>Qa(l)?l.items.length>0&&l.items.every(o):n(l.field),r=[],i=[];for(const l of e.items??[])(o(l)?i:r).push(l);return{source:{...e,items:r},output:{items:i,logicOperator:e.logicOperator}}}function vi(e,t,n,o={}){const r=new Map(t.map(k=>[k.field,k])),i=k=>r.get(k)?.groupable!==!1,l=n.rowFields.filter(i),c=n.columnFields.filter(i),a=new Set,u=n.valueFields.filter(k=>{if(!yo(r.get(k.field),k.aggFn))return!1;const N=`${k.field}${Ht}${k.aggFn}`;return a.has(N)?!1:(a.add(N),!0)});if(l.length===0||u.length===0)return To;const g=c.length>0,p=Array.from(new Set(u.map(k=>k.field))),x=(k,N)=>Ee(k,N,r.get(N)),y=new Map,h=new Map(g?[]:[["",{values:[]}]]);for(const k of e){const N=l.map(z=>x(k,z)),T=xi(N);let v=y.get(T);v||(v={labels:N.map(yi),sample:k,cells:new Map},y.set(T,v));const W=c.map(z=>x(k,z)),B=g?xi(W):"",Q=h.get(B);Q?Q.sample||(Q.sample=k):h.set(B,{values:W.map(yi),sample:k});let $=v.cells.get(B);$||($=new Map,v.cells.set(B,$));for(const z of p){const V=x(k,z);if(tn(V))continue;let ie=$.get(z);ie||(ie=[],$.set(z,ie)),ie.push(V)}}const f=Array.from(h.keys()).sort((k,N)=>Za(h.get(k).values,h.get(N).values)),w=(k,N)=>g?`${k}${Ht}${N.field}${Ht}${N.aggFn}`:`${N.field}${Ht}${N.aggFn}`,b=new Map;let m=[];for(const[k,N]of y){const T={id:mi(k)};l.forEach((v,W)=>{T[bi(v)]=N.labels[W]}),T.id=mi(k);for(const v of f){const W=N.cells.get(v);for(const B of u)T[w(v,B)]=Ci(W?.get(B.field),B.aggFn)}b.set(T.id,N),m.push({row:T,entry:N})}const C=k=>l.includes(k),E=k=>C(k)?r.get(k)?.type:"number",{outputFilterModel:_,sortModel:I}=o;if(ec(_)){const k=[];for(const T of f)for(const v of u)k.push({field:w(T,v),type:"number"});const N=Tn(_,Lo(k));N&&(m=m.filter(({row:T})=>N(T)))}const M=(k,N)=>N==="id"&&C("id")?k[Po]:k[N];I&&I.length>0&&(m=[...m].sort((k,N)=>{for(const T of I){const v=M(k.row,T.field),W=M(N.row,T.field),B=C(T.field)?r.get(T.field)?.sortComparator:void 0,Q=B?No(ai(B,{id:k.row.id,field:T.field,row:k.row,value:v},{id:N.row.id,field:T.field,row:N.row,value:W}),T.sort):za(v,W,T.sort,E(T.field));if(Q!==0)return Q}return 0}));const S=m.map(k=>k.row);if(m.length>0){const k={id:Gt};l.forEach((N,T)=>{k[bi(N)]=T===0?Ya:""}),k.id=Gt;for(const N of f)for(const T of p){const v=[];for(const{entry:W}of m){const B=W.cells.get(N)?.get(T);if(B)for(const Q of B)v.push(Q)}for(const W of u)W.field===T&&(k[w(N,W)]=Ci(v,W.aggFn))}S.push(k)}const F=m[0]?.entry.sample,P=k=>k===Gt?F:k===void 0?void 0:b.get(k)?.sample,L=l.map(k=>oc(k,r.get(k),P));for(const k of f){const N=h.get(k),T=g?c.map((v,W)=>{const B=r.get(v),Q=nc(B,v,N.values[W],N.sample);return B?.headerName?`${B.headerName}: ${Q}`:Q}).join(" / "):"";for(const v of u){const W=r.get(v.field),B=v.headerName??W?.headerName??v.field;L.push({field:w(k,v),headerName:T?`${T} — ${B} (${v.aggFn})`:`${B} (${v.aggFn})`,width:140,type:"number",align:"right",headerAlign:"right",sortable:!0,valueFormatter:({value:Q,row:$})=>Pn(Q,v.aggFn,W,$)})}}return{pivotRows:S,pivotColumns:L,colKeys:f,isValid:!0}}function nc(e,t,n,o){const r=o?po(o,t,n,e):void 0;return r!==void 0?r:n==null?"":String(n)}function oc(e,t,n){const o={field:e,headerName:t?.headerName??e,width:t?.width??140,sortable:!0,hideable:!1};t&&(t.type!==void 0&&(o.type=t.type),t.align!==void 0&&(o.align=t.align),t.headerAlign!==void 0&&(o.headerAlign=t.headerAlign),t.description!==void 0&&(o.description=t.description),t.minWidth!==void 0&&(o.minWidth=t.minWidth),t.maxWidth!==void 0&&(o.maxWidth=t.maxWidth),t.valueOptions!==void 0&&(o.valueOptions=t.valueOptions)),e==="id"&&(o.valueGetter=({row:c})=>c[Po]);const r=c=>c?.id===Gt,i=t?.valueFormatter;i&&(o.valueFormatter=({value:c,row:a})=>r(a)?String(c??""):i({value:c,row:n(a?.id)??a,field:e}));const l=t?.renderCell;return l&&(o.renderCell=c=>r(c.row)?c.formattedValue??String(c.value??""):l({...c,row:n(c.row.id)??c.row})),o}function Re(e,t){return e===Gt||t?.get(e)?.isGroupRow===!0}const Ct="__reorder_col__",vt="__expand_col__",Ye="__checkbox_col__",Je=e=>e===Ct||e===vt||e===Ye,Ao=(e,t)=>e===t||e!==null&&t!==null&&e.id===t.id&&e.field===t.field&&!e.headerFilter==!t.headerFilter,rc=new Set(["checkbox","radio","button","submit","reset","image","file","color"]),ic=new Set(["textbox","searchbox","combobox","listbox","slider","spinbutton"]);function Si(e){const t=e.tagName;if(t==="INPUT")return!rc.has(e.type);if(t==="TEXTAREA"||t==="SELECT"||e.isContentEditable||e.closest('[contenteditable]:not([contenteditable="false"])'))return!0;const n=e.getAttribute("role");return n!==null&&ic.has(n)}const _i=e=>e!==null&&e.nodeType===1;function ki(e,t){const n=e.closest(".ogx__detail-panel");if(n&&t.contains(n))return null;const o=e.closest('[role="gridcell"], [role="columnheader"]');return!o||o.closest(".ogx__viewport")!==t?null:o}function Dn(e,t){if(e===t)return"grid";if(!_i(e)||!t.contains(e))return"foreign";const n=ki(e,t);return n?n.classList.contains("ogx__cell--editing")?"editor":n===e?"grid":Si(e)?"foreign":n.classList.contains("ogx__header-cell--checkbox")?"grid":"control":"foreign"}function lc(e,t,n,o){if(!_i(e))return null;const r=ki(e,t),i=r?.dataset.field;if(!r||!i)return null;if(r.getAttribute("role")==="columnheader"){const a=r.parentElement;return a?.classList.contains("ogx__header")?{id:null,field:i}:a?.classList.contains("ogx__header-filter-row")?{id:null,field:i,headerFilter:!0}:null}const l=Number(r.parentElement?.getAttribute("data-rowindex")),c=Number.isInteger(l)?n[l]:void 0;return c?{id:o(c),field:i,rowIndex:l}:null}function Ei(e,t){if(!e)return null;for(const n of Array.from(e.children))if(n.dataset.field===t)return n;return null}function Fo(e,t,n){if(t.id===null){const r=e.querySelector(`:scope > .ogx__content > .ogx__sticky-top > .ogx__header-wrap > ${t.headerFilter?".ogx__header-filter-row":".ogx__header"}`),i=Ei(r,t.field);return i&&t.field===Ye?i.querySelector("input")??i:i}if(n<0)return null;const o=e.querySelector(`:scope > .ogx__content > .ogx__virtual-container > .ogx__rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-top > .ogx__pinned-rows > [data-rowindex="${n}"],:scope > .ogx__content > .ogx__sticky-bottom > .ogx__pinned-rows > [data-rowindex="${n}"]`);return Ei(o,t.field)}const Mi="__group__";function Ue(e){return!Je(e)&&e!==Mi}const ct=(e,t)=>e===t||!!e&&!!t&&e.id===t.id&&e.field===t.field;function sc(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>ct(n.anchor,t[o].anchor)&&ct(n.head,t[o].head))}function $n(e,t,n){const{rowIds:o,fields:r,rowIndexById:i,colIndexByField:l,spans:c}=n,a={top:e,bottom:e,left:t,right:t};if(!c)return a;const u=o[e],g=r[t],p=c.getSpanOrigin(u,g)??{rowId:u,field:g},x=i.get(p.rowId),y=l.get(p.field);if(x===void 0||y===void 0)return a;const h=Math.max(1,c.getRowSpan(p.rowId,p.field)),f=Math.max(1,c.getColSpan(p.rowId,p.field));return{top:x,bottom:Math.min(o.length-1,x+h-1),left:y,right:Math.min(r.length-1,y+f-1)}}function ac(e,t){if(!t.spans)return e;let{top:n,bottom:o,left:r,right:i}=e,l=!0;const c=a=>{a.top<n&&(n=a.top,l=!0),a.bottom>o&&(o=a.bottom,l=!0),a.left<r&&(r=a.left,l=!0),a.right>i&&(i=a.right,l=!0)};for(;l;){l=!1;for(let a=n;a<=o;a++)c($n(a,r,t)),i!==r&&c($n(a,i,t));for(let a=r+1;a<i;a++)c($n(n,a,t)),o!==n&&c($n(o,a,t))}return{top:n,bottom:o,left:r,right:i}}function Gn(e,t){const n=t.rowIndexById.get(e.anchor.id),o=t.rowIndexById.get(e.head.id),r=t.colIndexByField.get(e.anchor.field),i=t.colIndexByField.get(e.head.field);return n===void 0||o===void 0||r===void 0||i===void 0?null:{...ac({top:Math.min(n,o),bottom:Math.max(n,o),left:Math.min(r,i),right:Math.max(r,i)},t),anchorRow:n,anchorCol:r,headRow:o,headCol:i}}const St=e=>(e.bottom-e.top+1)*(e.right-e.left+1);function cc(e,t,n,o,r,i){const{headRow:l,headCol:c,anchorRow:a,anchorCol:u,top:g,bottom:p,left:x,right:y}=e;let h=l,f=c;switch(t){case"ArrowRight":f=c>=u?y+1:c+1;break;case"ArrowLeft":f=c<=u?x-1:c-1;break;case"ArrowDown":h=l>=a?p+1:l+1;break;case"ArrowUp":h=l<=a?g-1:l-1;break;case"Home":f=0,n&&(h=0);break;case"End":f=i,n&&(h=r);break;case"PageUp":h=l-o;break;case"PageDown":h=l+o;break;default:return null}return h=Math.min(Math.max(h,0),r),f=Math.min(Math.max(f,0),i),h===l&&f===c?null:{row:h,col:f}}function Ii(e,t,n,o){const r=o&&o.row===t?o.col:void 0;if(!e||t<e.top||t>e.bottom)return r===void 0?null:{left:0,right:-1,isTop:!1,isBottom:!1,bottomOffset:0,fillHandleCol:r};const i={left:e.left,right:e.right,isTop:t===e.top,isBottom:t===e.bottom,bottomOffset:n?e.bottom-t:0};return r!==void 0&&(i.fillHandleCol=r),i}const dc=(e,t)=>e===t||!!e&&!!t&&e.left===t.left&&e.right===t.right&&e.isTop===t.isTop&&e.isBottom===t.isBottom&&e.bottomOffset===t.bottomOffset&&e.fillHandleCol===t.fillHandleCol,Oo=1,Ni=2,Li=4,Pi=8,Ti=16,Ai=32;function uc(e,t,n,o){if(!e)return 0;const r=e.fillHandleCol===t?Ai:0,i=t+Math.max(1,n)-1;if(t<e.left||i>e.right)return r;let l=Oo|r;return e.isTop&&(l|=Ni),(e.isBottom||o>1&&o-1>=e.bottomOffset)&&(l|=Li),t===e.left&&(l|=Pi),i===e.right&&(l|=Ti),l}function fc(e,t,n){const o=(r,i,l)=>`${r} ${r===1?i:l}`;return`${o(e,"cell","cells")} selected, ${o(t,"row","rows")} by ${o(n,"column","columns")}`}const gc=1e5,pc=e=>e.id,Fi=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"]);function hc(e,t,n,o,r){if(!e||n.length===0)return{cell:null,rowIndex:-1};const i=(n.find(u=>!Je(u.field))??n[0]).field,l=n.some(u=>u.field===e.field)?e.field:i;if(e.id===null){const u=!!e.headerFilter&&r;return l===e.field&&u===!!e.headerFilter?{cell:e,rowIndex:-1}:{cell:u?{id:null,field:l,headerFilter:u}:{id:null,field:l},rowIndex:-1}}const c=e.rowIndex;let a=c!==void 0&&t[c]&&o(t[c])===e.id?c:t.findIndex(u=>o(u)===e.id);return a===-1?t.length===0?{cell:{id:null,field:l},rowIndex:-1}:(a=Math.min(Math.max(c??0,0),t.length-1),{cell:{id:o(t[a]),field:l,rowIndex:a},rowIndex:a}):{cell:l===e.field?e:{...e,field:l},rowIndex:a}}function mc(e){const{allRenderableRows:t,navigationColumns:n,checkboxSelection:o,selectedRowIds:r,handleSelectionChange:i,handleDetailPanelToggle:l,editingHandlers:c,setKeyboardMode:a,sortModel:u,handleSort:g,handleSortAdd:p,multiSort:x=!1,isCellEditable:y,pagination:h,pageSize:f,virtualization:w,viewportRef:b,pinnedTopRowCount:m=0,getRowId:C=pc,rowMetaMap:E,onRowActivate:_,toggleRowExpansion:I,handleSelectAll:M,rowSelectionEnabled:S=!0,multipleRowSelectionEnabled:F=!0,pinCheckboxColumn:P=!0,pinExpandColumn:L=!0,rowHeight:k,getSpanOrigin:N,cellSelection:T,headerFilters:v=!1}=e,[W,B]=s.useState(null),[Q,$]=s.useState(!1),z=s.useMemo(()=>hc(W,t,n,C,v),[W,t,n,C,v]),V=z.cell,ie=z.rowIndex,te=s.useRef(!1),ce=s.useRef(!1),oe=s.useRef(!1),de=s.useRef(null),X=s.useCallback(O=>{ce.current=!0,O.focus({preventScroll:!0}),ce.current=!1},[]),ne=s.useCallback(()=>{const O=b.current;O&&!O.contains(O.ownerDocument.activeElement)&&X(O)},[b,X]),se=s.useMemo(()=>n.find(O=>!Je(O.field))??n[0],[n]),Y=s.useCallback(()=>{if(o)return{id:null,field:Ye};if(!se)return null;const O=t[0];return O?{id:C(O),field:se.field,rowIndex:0}:{id:null,field:se.field}},[o,se,t,C]),H=s.useCallback((O,A)=>{const G=b.current;if(!G)return;const{cumulativeHeights:D,pinnedBottomHeight:U,columnMetrics:q}=w;if(O>=0&&Nn(G,O-m,D,U,k),Je(A)){!(A===Ct||A===vt&&L||A===Ye&&P)&&Ot(G)>0&&en(G,0);return}if(!q)return;const{clientWidth:ee}=G,Z=Ot(G),{leftPinnedWidth:j,rightPinnedWidth:re,unpinnedAccWidths:me,unpinnedCols:pe,totalSpecialsWidth:K,pinnedSpecialsWidth:fe}=q,we=pe.findIndex(ke=>ke.field===A);if(we===-1)return;const le=K+j+(we>0?me[we-1]:0),be=K+j+me[we],Ce=Z+fe+j,ye=Z+ee-re;let ue=Z;le<Ce?ue=Math.max(0,le-fe-j):be>ye&&(ue=be-ee+re),ue!==Z&&en(G,ue)},[b,w,m,k,P,L]);s.useLayoutEffect(()=>{const O=b.current,A=!Ao(de.current,V);if(de.current=V,!O||!V)return;const G=O.ownerDocument,D=G.activeElement;let U;if(D===O?U=!0:!D||D===G.body?U=te.current:O.contains(D)?U=A:U=!1,!U)return;const q=Fo(O,V,ie);q?q.contains(D)||q.focus({preventScroll:!0}):D!==O&&X(O)});const R=s.useCallback(()=>{oe.current=!0,a(!1)},[a]),ae=s.useCallback(O=>{const A=O.currentTarget,G=O.relatedTarget,D=!(G instanceof Node&&A.contains(G)),U=oe.current;if(oe.current=!1,te.current=!0,$(!0),ce.current)return;if(O.target===A){if(!D)return;if(U||a(!0),V){const Z=Fo(A,V,ie);Z?Z.focus({preventScroll:!0}):H(ie,V.field);return}const ee=Y();ee&&(B(Z=>Z??ee),H(ee.rowIndex??-1,ee.field));return}const q=lc(O.target,A,t,C);q&&!Ao(q,V)&&B(q)},[V,ie,Y,H,a,t,C]),ge=s.useCallback(O=>{const A=O.relatedTarget;A instanceof Node&&O.currentTarget.contains(A)||(te.current=!1,oe.current=!1,$(!1),a(!1))},[a]),J=s.useCallback(O=>{const A=O.currentTarget,G=Dn(O.target,A);if(G==="foreign"||(a(!0),O.nativeEvent?.isComposing||O.keyCode===229))return;const D=Mn(O.key,Xe(A)),U=D===" "||D==="Spacebar",q=!!c.editingCell,ee=v?-2:-1,Z=(he,ve)=>{const _e=n[ve];!_e||he<ee||he>=t.length||(he===ee?B({id:null,field:_e.field}):he<0?B({id:null,field:_e.field,headerFilter:!0}):B({id:C(t[he]),field:_e.field,rowIndex:he}),H(he,_e.field))};if(!V){if(!Fi.has(D))return;const he=Y();if(!he)return;O.preventDefault(),B(he),H(he.rowIndex??-1,he.field);return}const{id:j,field:re}=V,me=j===null&&!!V.headerFilter,pe=j!==null?ie:me?-1:ee,K=n.findIndex(he=>he.field===re),fe=n.filter(he=>Je(he.field)).length,we=he=>Re(he,E),le=(he,ve,_e)=>{const xe=n[_e];return Je(xe.field)?!1:xo({row:he,field:xe.field,value:Ee(he,xe.field,xe),colDef:xe,rowIndex:ve,colIndex:_e-fe,rowMeta:E?.get(C(he))},y)},be=he=>{let ve=pe,_e=K;const xe=(t.length+1)*n.length;for(let Ne=0;Ne<xe;Ne++){if(_e+=he,_e>=n.length?(_e=0,ve++):_e<0&&(_e=n.length-1,ve--),ve<0||ve>=t.length)return null;const ze=t[ve];if(!N?.(C(ze),n[_e].field)&&le(ze,ve,_e))return{r:ve,c:_e}}return null};if(q){if(D==="Enter")O.preventDefault(),c.stopCellEdit();else if(D==="Escape")O.preventDefault(),c.stopCellEdit({cancel:!0});else if(D==="Tab"&&j!==null){const he=be(O.shiftKey?-1:1);he&&(O.preventDefault(),c.stopCellEdit(),Z(he.r,he.c))}return}if(D==="Escape"&&T?.collapseSelection()){O.preventDefault();return}if(D==="Tab"||D==="Escape"||G==="control"&&(D==="Enter"||U))return;if((O.ctrlKey||O.metaKey)&&(D==="a"||D==="A")){if(T){T.selectAllCells()&&O.preventDefault();return}if(!S||!F||!M)return;O.preventDefault(),M(!0);return}if(me&&(D==="Enter"||U))return;if(j===null){if(D==="Enter"||U){if(O.preventDefault(),re===Ye){Fo(A,V,-1)?.click();return}const he=n[K];if(!he||Je(re)||he.sortable===!1)return;const ve=u.find(xe=>xe.field===re),_e=ve?ve.sort==="asc"?"desc":null:"asc";(x||O.shiftKey)&&p?p(re,_e):g(re,_e);return}}else if(D==="Enter"||U){O.preventDefault();const he=t[pe];if(re===Ye){i(j,!r.has(j));return}if(re===vt){O.shiftKey||l(j);return}if(U){O.shiftKey&&S&&!we(j)&&i(j,!r.has(j));return}if(re===Ct)return;if(le(he,pe,K)){c.startCellEdit({id:j,field:re,value:Ee(he,re,n[K])});return}if(I&&E?.get(j)?.hasChildren){I(j);return}_?.({row:he,id:j,rowIndex:pe});return}if(O.altKey&&(D==="ArrowRight"||D==="ArrowLeft")&&I&&j!==null){O.preventDefault();const he=E?.get(j);he?.hasChildren&&!!he.isExpanded!=(D==="ArrowRight")&&I(j);return}if(!Fi.has(D))return;O.preventDefault();const Ce=t.length-1,ye=n.length-1,ue=O.ctrlKey||O.metaKey,ke=h?f:10;if(T&&O.shiftKey&&j!==null&&Ue(re)&&T.extendSelection(D,ue,ke,V))return;const Ae=(he,ve)=>{switch(D){case"ArrowRight":return ve+1>ye?{r:he+1,c:0}:{r:he,c:ve+1};case"ArrowLeft":return ve-1<0?{r:he-1,c:ye}:{r:he,c:ve-1};case"ArrowDown":return{r:he+1,c:ve};case"ArrowUp":return{r:he-1,c:ve};case"Home":return{r:ue?ee:he,c:0};case"End":return{r:ue?Ce:he,c:ye};case"PageUp":return{r:Math.max(ee,he-ke),c:ve};default:return{r:Math.min(Ce,he+ke),c:ve}}},Le=({r:he,c:ve})=>he>=ee&&he<=Ce&&ve>=0&&ve<=ye,Me=({r:he,c:ve})=>he>=0?N?.(C(t[he]),n[ve].field)??null:null;let Ie=Ae(pe,K);if(D.startsWith("Arrow"))for(let he=Le(Ie)?Me(Ie):null;he&&he.rowId===j&&he.field===re;he=Le(Ie)?Me(Ie):null)Ie=Ae(Ie.r,Ie.c);if(!Le(Ie))return;const Pe=Me(Ie);if(Pe){const he=t.findIndex(_e=>C(_e)===Pe.rowId),ve=n.findIndex(_e=>_e.field===Pe.field);he!==-1&&ve!==-1&&(Ie={r:he,c:ve})}Ie.r===pe&&Ie.c===K||Z(Ie.r,Ie.c)},[V,ie,t,n,c,r,i,l,a,u,g,p,x,y,h,f,E,_,I,M,S,F,Y,H,N,C,T,v]);return{focusedCell:V,setFocusedCell:B,viewportTabIndex:Q?-1:0,ensureGridFocus:ne,handleFocus:ae,handleBlur:ge,handleKeyDown:J,handleMouseDownCapture:R}}const Do=[];function wc(e){const{isPivotActive:t}=e,n=t?Do:e.rowGroupingModel,o=e.treeData&&!t,r=o&&e.hasTreeDataPath,i=n.length>0;return{rowReordering:e.rowReordering&&!t,hierarchyRowGroupingModel:n,isTreeDataRequested:o,isTreeData:r,isRowGrouping:i,isHierarchyEnabled:r||i,hasGroupingColumn:e.hasGroupingColDef&&(i||r),pagination:e.pagination&&!i&&e.paginationMode!=="infinite",listView:e.listView&&e.hasListViewColumn}}const bc=[],xc={rowFields:[],columnFields:[],valueFields:[]},Oi=100;function yc(e){return!e||e.length===0||e.includes(Oi)?Oi:e[0]}function Cc(e){const{initialState:t,sortModel:n,onSortModelChange:o,filterModel:r,onFilterModelChange:i,aggregationModel:l,onAggregationModelChange:c,rowGroupingModel:a,onRowGroupingModelChange:u,columnVisibilityModel:g,onColumnVisibilityModelChange:p,pinnedColumns:x,onPinnedColumnsChange:y,pivotModel:h,onPivotModelChange:f,paginationModel:w,onPaginationModelChange:b,pageSizeOptions:m,rowSelectionModel:C,onRowSelectionModelChange:E,density:_,cellSelectionModel:I,onCellSelectionModelChange:M}=e,[S,F]=s.useState(()=>t?.sorting?.sortModel??[]),P=n!==void 0,L=P?n:S,k=s.useCallback(xe=>{P||F(xe),o?.(xe)},[P,o]),[N,T]=s.useState(()=>t?.filter?.filterModel??{items:[]}),v=r!=null,W=v?r:N,B=s.useCallback(xe=>{v||T(xe),i?.(xe)},[v,i]),Q=l!==void 0,[$,z]=s.useState(()=>l??{}),V=JSON.stringify(Q?l:$),ie=s.useMemo(()=>JSON.parse(V),[V]),te=s.useCallback(xe=>{Q||z(xe),c?.(xe)},[Q,c]),ce=a!==void 0,[oe,de]=s.useState(Do),X=(ce?a:oe)||Do,ne=s.useCallback(xe=>{ce||de(xe),u?.(xe)},[ce,u]),se=g!==void 0,[Y,H]=s.useState(()=>t?.columns?.columnVisibilityModel??{}),R=se?g:Y,ae=s.useCallback(xe=>{se||H(xe),p?.(xe)},[se,p]),ge=x!==void 0,[J,O]=s.useState(()=>t?.columns?.pinnedColumns??{}),A=ge?x:J,G=s.useCallback(xe=>{ge||O(xe),y?.(xe)},[ge,y]),[D,U]=s.useState(()=>h??xc),q=h??D,ee=s.useCallback(xe=>{U(xe),f?.(xe)},[f]),Z=w!==void 0,[j,re]=s.useState(()=>t?.pagination?.paginationModel??w??{page:0,pageSize:yc(m)}),me=Z?w:j,pe=s.useCallback(xe=>{Z||re(xe),b?.(xe)},[Z,b]),K=C!==void 0,[fe,we]=s.useState([]),le=K?C:fe,be=s.useMemo(()=>new Set(le),[le]),Ce=s.useRef(null);s.useLayoutEffect(()=>{Ce.current=null});const ye=s.useCallback(()=>Ce.current,[]),ue=s.useCallback(xe=>{Ce.current=xe,K||we(xe),E?.(xe)},[K,E]),[ke]=s.useState(()=>t?.density?.density??"standard"),Ae=_??ke,Le=I!==void 0,[Me,Ie]=s.useState(bc),Pe=Le?I:Me,he=s.useRef(null);s.useLayoutEffect(()=>{he.current=null});const ve=s.useCallback(()=>he.current,[]),_e=s.useCallback((xe,Ne)=>{he.current=xe,Le||Ie(xe),M?.(xe,{reason:Ne})},[Le,M]);return{sortModel:L,isSortControlled:P,setInternalSortModel:F,handleSortModelChange:k,filterModel:W,isFilterControlled:v,handleFilterModelChange:B,aggregationModel:ie,handleAggregationModelChange:te,rowGroupingModel:X,handleRowGroupingModelChange:ne,columnVisibilityModel:R,handleColumnVisibilityModelChange:ae,pinnedColumns:A,handlePinnedColumnsChange:G,currentPivotModel:q,handlePivotModelChange:ee,effectivePaginationModel:me,handlePaginationModelChange:pe,rowSelectionModel:le,selectedRowIds:be,isSelectionControlled:K,setInternalRowSelectionModel:we,handleRowSelectionModelChange:ue,getPendingRowSelectionModel:ye,density:Ae,cellSelectionModel:Pe,handleCellSelectionModelChange:_e,getPendingCellSelectionModel:ve}}const Di=s.createContext(null),vc=52,Sc=56,_c=32,kc=72;function Hn(e){if(e===void 0)return;const t=/^(\d+(?:\.\d+)?)(?:\s*px)?$/.exec(e.trim());if(!t)return;const n=Number(t[1]);return n>0?n:void 0}function Ec(e){const{rowHeight:t,headerHeight:n,density:o}=e,r=s.useContext(Di)?.grid;let i;return o==="compact"?i=Hn(r?.rowHeightCompact)??_c:o==="comfortable"?i=Hn(r?.rowHeightComfortable)??kc:i=t??Hn(r?.rowHeightStandard)??vc,{rowHeight:i,headerHeight:n??Hn(r?.headerHeight)??Sc}}function Bn(e){return e>=1?Math.floor(e):1}function $o(e,t){return Math.max(1,Math.ceil(Math.max(0,e)/Bn(t)))}function Mc(e){const{paginationMode:t,hasDataSource:n,dataSourceRowCount:o,rowCountProp:r,clientRowCount:i}=e;return t!=="server"?i:(n?o??r:r)??i}function $i(e){return e?{paginationRowsPerPage:e.paginationRowsPerPage,paginationOf:e.paginationOf,paginationPage:e.paginationPage}:void 0}function Gi(e,t){return Number.isFinite(e)?Math.min(Math.max(0,Math.floor(e)),Math.max(0,t-1)):0}function Ic(e){const{effectiveRows:t,activeHierarchyHandlers:n,filterMode:o,filterModel:r,sortModel:i,sortingMode:l,pagination:c,paginationMode:a,effectivePaginationModel:u,pinnedRows:g,getRowId:p,columnLookup:x,hierarchyField:y}=e,h=s.useMemo(()=>n?n.getVisibleRows({labelField:y})||[]:o==="server"?t:ko(t,r,x),[t,r,n,y,o,x]),f=s.useMemo(()=>n?o==="server"?t:ko(t,r,x):h,[n,h,o,t,r,x]),{top:w,center:b,bottom:m}=s.useMemo(()=>n?{top:[],center:h,bottom:[]}:pa(h,g,p),[h,g,n,p]),C=s.useMemo(()=>n||l==="server"?b:Ra(b,i,x,p),[b,i,n,l,x,p]),E=c&&a!=="server",_=Bn(u.pageSize),I=E?Gi(u.page,$o(C.length,_)):u.page,M=s.useMemo(()=>{if(!E)return C;const F=I*_;return C.slice(F,F+_)},[C,E,I,_]),S=s.useMemo(()=>{const F=c?M:C;return[...w,...F,...m]},[w,M,C,m,c]);return{filteredRows:h,dataRows:f,pinnedTopRows:w,unpinnedRows:b,pinnedBottomRows:m,sortedUnpinnedRows:C,paginatedUnpinnedRows:M,currentPage:I,allRenderableRows:S}}const Go=[33554400,17895e3,1e7,5e6],Hi=new WeakMap;function Nc(e){const t=e.body;if(!t)return 1/0;const n=e.createElement("div");n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;top:0;left:-10000px;width:1px;visibility:hidden;pointer-events:none;",t.appendChild(n);try{if(n.style.height="100px",Math.abs(n.getBoundingClientRect().height-100)>1)return 1/0;for(const o of Go)if(n.style.height=`${o}px`,Math.abs(n.getBoundingClientRect().height-o)<2)return o;return Go[Go.length-1]}finally{n.remove()}}function Lc(e){if(!e)return 1/0;const t=Hi.get(e);if(t!==void 0)return t;const n=Nc(e);return Hi.set(e,n),n}function Pc(e,t){if(!Number.isFinite(t))return e.length;let n=0,o=e.length;for(;n<o;){const r=n+o>>1;e[r]<=t?n=r+1:o=r}return n}const Ho="application/x-ogx-row",Bo="application/x-ogx-column";function Bi(e,t,n){const o=e.dataTransfer;!o||typeof o.setData!="function"||(o.setData(t,n),o.setData("text/plain",n))}function Wn(e,t){const n=e.dataTransfer?.types;return n?Array.from(n).includes(t):!0}function Wi(e,t){if(!e||typeof e.addEventListener!="function")return()=>{};const n=()=>t();return e.addEventListener("dragend",n,{once:!0}),()=>e.removeEventListener("dragend",n)}function Tc(e){const{columns:t,onColumnOrderChange:n,disableColumnReorder:o=!1}=e,[r,i]=s.useState(null),[l,c]=s.useState(null),a=s.useRef(()=>{}),u=s.useCallback(()=>{a.current(),a.current=()=>{},i(null),c(null)},[]);s.useEffect(()=>()=>a.current(),[]);const g=s.useCallback(y=>h=>{if(!o){if(!t.some(f=>f.field===y)){h.preventDefault();return}a.current(),a.current=Wi(h.currentTarget,u),i(y),h.dataTransfer&&(h.dataTransfer.effectAllowed="move",Bi(h,Bo,y))}},[t,o,u]),p=s.useCallback(y=>h=>{if(!(o||r===null)){if(!Wn(h,Bo)){u();return}h.preventDefault(),h.dataTransfer&&(h.dataTransfer.dropEffect="move"),c(y)}},[r,o,u]),x=s.useCallback(y=>h=>{if(h.preventDefault(),o||r===null||!Wn(h,Bo)){u();return}const f=t.findIndex(b=>b.field===r),w=t.findIndex(b=>b.field===y);u(),!(f===-1||w===-1||f===w)&&n?.({column:t[f],oldIndex:f,targetIndex:w})},[t,r,o,n,u]);return{draggedColumn:r,dragOverColumn:l,onDragStart:o?void 0:g,onDragOver:o?void 0:p,onDragEnd:o?void 0:u,onDrop:o?void 0:x}}function Wo({isExpanded:e,onClick:t,variant:n="chevron",tabIndex:o}){return d.jsx("button",{className:`ogx-expand-icon ${e?"ogx-expand-icon--expanded":""}`,onClick:r=>{t&&t(r)},"aria-label":e?"Collapse row":"Expand row",type:"button",tabIndex:o,children:n==="plus-minus"?d.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("path",{d:"M4 8H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),d.jsx("path",{d:"M8 4V12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:e?0:1,transition:"opacity 0.2s ease",transformOrigin:"center"}})]}):d.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"ogx-expand-icon__chevron","aria-hidden":"true",children:d.jsx("path",{d:"M6 4L10 8L6 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}function Ac({renderFn:e}){"use no memo";return d.jsx(d.Fragment,{children:e()})}function Fc(e,t){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>Object.is(n,t[o])):Object.is(e,t)}class _t extends s.Component{constructor(t){super(t),this.state={hasError:!1,error:null,resetKey:t.resetKey}}static getDerivedStateFromProps(t,n){return Fc(t.resetKey,n.resetKey)?null:n.hasError?{hasError:!1,error:null,resetKey:t.resetKey}:{resetKey:t.resetKey}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){process.env.NODE_ENV!=="production"&&console.warn(`[CellErrorBoundary] field="${this.props.field}"`,t,n.componentStack)}render(){return this.state.hasError?d.jsx("div",{className:"ogx__cell-error",role:"img","aria-label":`Error in cell: ${this.props.field}`,title:this.state.error?.message??"Render error",children:"⚠"}):d.jsx(Ac,{renderFn:this.props.renderFn})}}function Oc(e,t,n){if(!t||!n)return{valueGetter:e.valueGetter,valueFormatter:e.valueFormatter};const o=l=>n.has(l.id),r=e.valueGetter,i=e.valueFormatter;return{valueGetter:r?l=>o(l.row)?l.value:r(l):void 0,valueFormatter:l=>o(l.row)?Pn(l.value,t,e,l.row):i?i(l):l.value==null?"":String(l.value)}}function Vi(e,t){if(!t)return e;const n=t.left??[],o=t.right??[],r=i=>{const l=tt(i.field,t);return l==="left"?n.indexOf(i.field)-n.length:l==="right"?1+o.indexOf(i.field):0};return[...e].sort((i,l)=>r(i)-r(l))}const Vn=e=>e.formattedValue??e.value;function zi(e,t,n){const o=e.renderCell;if(!o)return{useDefault:!0};const r=!!t.rowMeta?.isGroupRow;if(!n){const l=o(t);return r&&l===void 0?{useDefault:!0}:{useDefault:!1,content:l}}let i;try{i=o(t)}catch(l){return{useDefault:!1,content:d.jsx(_t,{field:e.field,resetKey:t.row,renderFn:()=>{throw l}})}}return r&&i===void 0?{useDefault:!0}:{useDefault:!1,content:d.jsx(_t,{field:e.field,resetKey:t.row,renderFn:()=>i})}}function Dc(e,t,n){const o=e.rowMeta;if(!o?.isGroupRow)return Vn(e);if(o.isGroupFooter)return null;const r=o.descendantCount;if(t&&o.hasChildren){const i=o.groupLabel??`${o.groupingField}: ${String(o.groupingValue)}`;return d.jsxs("div",{className:"ogx__group-cell-content",children:[i,r!==void 0?` (${r})`:""]})}return n?d.jsxs("div",{className:"ogx__group-cell-content",children:[o.groupLabel,r!==void 0&&r>0?` (${r})`:""]}):Vn(e)}const $c=e=>e.id;function Gc(e){const{activeColumns:t,isHierarchyEnabled:n,isRowGrouping:o,isTreeData:r,activeHierarchyHandlers:i,columnVisibilityModel:l,columnOrder:c,onColumnOrderChange:a,onColumnOrderModelChange:u,disableColumnReorder:g,pivotMode:p,checkboxSelection:x,hasDetailPanel:y,rowReordering:h,initialState:f,setColumns:w,pinnedColumns:b,getRowId:m=$c,aggregationModel:C,groupingRows:E}=e,_=s.useMemo(()=>t.map(H=>H.field),[t]),[I,M]=s.useState(()=>f?.columns?.columnOrder??null),S=p?_.join("\0"):"",[F,P]=s.useState(null),L=F&&F.key===S?F.order:_,N=p?L:c??(I??_),T=s.useCallback(H=>{if(p){P(R=>{const ae=R&&R.key===S?R.order:_;return{key:S,order:typeof H=="function"?H(ae):H}});return}M(R=>typeof H=="function"?H(R??_):H)},[p,S,_]),v=s.useCallback(H=>p&&H.hideable===!1||l[H.field]!==!1,[p,l]),W=s.useMemo(()=>{if(!n)return;const H=new Map(N.map((J,O)=>[J,O])),R=J=>H.get(J.field)??t.indexOf(J),ae=[...t].sort((J,O)=>R(J)-R(O));return(Vi(ae.filter(J=>l[J.field]!==!1),b)[0]??t[0])?.field},[n,N,t,l,b]),B=s.useMemo(()=>{if(!n)return t;const H=o?E:void 0;return t.map(R=>{const ae=Oc(R,C?.[R.field],H);return R.field===W?{...R,...ae,renderCell:ge=>{const J=ge.rowMeta,O=J?.treeDepth??0,A=!!J?.hasChildren,G=!!J?.isExpanded,D=zi(R,ge,!0),U=D.useDefault?Dc(ge,o,r):D.content;return d.jsxs("div",{style:{display:"flex",alignItems:"center",paddingInlineStart:O*24,width:"100%",height:"100%"},children:[d.jsx("div",{style:{marginInlineEnd:4,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",cursor:A?"pointer":"default",flexShrink:0},children:A?d.jsx("div",{onClick:q=>{q.stopPropagation(),q.preventDefault(),i?.toggleExpansion(m(ge.row))},onMouseDown:q=>{q.stopPropagation()},style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",zIndex:10,position:"relative"},children:d.jsx(Wo,{isExpanded:G,tabIndex:-1,onClick:q=>{q.stopPropagation(),q.preventDefault(),i?.toggleExpansion(m(ge.row))}})}):null}),d.jsx("div",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:U})]})}}:{...R,...ae,renderCell:ge=>{const J=ge.rowMeta;if(!J?.isGroupRow)return R.renderCell?R.renderCell(ge):Vn(ge);const O=zi(R,ge,!1);return O.useDefault?R.field===J.groupingField&&!J.isGroupFooter||ge.value==null?null:Vn(ge):O.content}}})},[t,n,o,r,i,W,m,C,E]),[Q,$]=s.useState(()=>f?.columns?.columnWidths??{}),z=s.useCallback((H,R)=>{$(ae=>({...ae,[H]:R}))},[]);s.useEffect(()=>{w(t)},[t,w]);const V=s.useMemo(()=>{const H=new Map(N.map((R,ae)=>[R,ae]));return[...B].sort((R,ae)=>{const ge=H.get(R.field)??B.indexOf(R),J=H.get(ae.field)??B.indexOf(ae);return ge-J})},[B,N]),ie=s.useMemo(()=>V.filter(v),[V,v]),te=s.useCallback((H,R)=>{(p||!c)&&T(H),R&&a?.(R),p||u?.(H)},[p,c,T,a,u]),ce=s.useCallback((H,R)=>{const ae=V.map(J=>J.field),[ge]=ae.splice(H,1);ae.splice(R,0,ge),te(ae,{column:V[H],oldIndex:H,targetIndex:R})},[V,te]),oe=Tc({columns:V,onColumnOrderChange:s.useCallback(({oldIndex:H,targetIndex:R})=>ce(H,R),[ce]),disableColumnReorder:g}),de=s.useCallback((H,R)=>{const ae=V.findIndex(J=>J.field===H),ge=V.findIndex(J=>J.field===R);ae===-1||ge===-1||ae===ge||ce(ae,ge)},[V,ce]),X=s.useCallback(()=>{te(_)},[te,_]),ne=s.useMemo(()=>Vi(ie,b),[ie,b]),se=s.useMemo(()=>{const H=[];return h&&H.push({field:Ct,sortable:!1,editable:!1}),y&&H.push({field:vt,sortable:!1,editable:!1}),x&&H.push({field:Ye,sortable:!1,editable:!1}),[...H,...ne]},[ne,x,y,h]),Y=s.useMemo(()=>new Map(ne.map((H,R)=>[H.field,R])),[ne]);return{effectiveColumns:B,hierarchyField:W,orderedColumns:V,visibleOrderedColumns:ie,renderOrderedColumns:ne,navigationColumns:se,columnIndexMap:Y,columnWidths:Q,effectiveColumnOrder:N,setInternalColumnOrder:T,columnReorderHandlers:oe,moveColumn:de,resetColumnOrder:X,handleColumnResize:z}}function Hc(){const[e,t]=s.useState(()=>new Map),n=s.useCallback((o,r)=>{t(i=>{if(i.get(o)===r)return i;const l=new Map(i);return l.set(o,r),l})},[]);return{detailPanelHeights:e,reportDetailPanelHeight:n}}function Bc(e){const{hasDetailPanel:t,controlledExpandedRowIds:n,onDetailPanelExpandedRowIdsChange:o,rowMetaMap:r}=e,[i,l]=s.useState(new Set),c=n??i,a=s.useMemo(()=>_a(c,r),[c,r]),u=s.useCallback(x=>{if(r.get(x)?.isGroupRow)return;const y=new Set(c);y.has(x)?y.delete(x):y.add(x),n===void 0&&l(y),o?.(y)},[c,r,n,o]),{detailPanelHeights:g,reportDetailPanelHeight:p}=Hc();return{hasDetailPanel:t,expandedRowIds:a,handleDetailPanelToggle:u,detailPanelHeights:g,reportDetailPanelHeight:p}}const Wc=new Set(["__group__"]),sn=e=>!Wc.has(e);function Ki(e){return Object.keys(e).every(sn)?e:Object.fromEntries(Object.entries(e).filter(([n])=>sn(n)))}function Vc(e){const t={...e};return e.left&&(t.left=e.left.filter(sn)),e.right&&(t.right=e.right.filter(sn)),t}function zc(e){const{onStateChange:t,sortModel:n,filterModel:o,effectivePaginationModel:r,columnWidths:i,effectiveColumnOrder:l,columnVisibilityModel:c,pinnedColumns:a,density:u}=e,g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t});const p=s.useRef(null);s.useEffect(()=>{if(!g.current)return;const x={sorting:{sortModel:n},filter:{filterModel:o},pagination:{paginationModel:r},columns:{columnWidths:Ki(i),columnOrder:l.filter(sn),columnVisibilityModel:Ki(c),pinnedColumns:Vc(a)},density:{density:u}},y=JSON.stringify(x);y!==p.current&&(p.current=y,g.current(x))},[n,o,r,i,l,c,a,u])}const Kc=200,Rc=2e3,Uc=178e5;function jc(e){const{paginationRequested:t,isRowGrouping:n,autoHeight:o,viewportHeight:r,renderedRowCount:i,totalRowCount:l,pinnedRowsIgnored:c=!1,scrollHeight:a=0,maxContentHeight:u,reachableRowCount:g,unpinnedRowCount:p,listViewWithoutColumn:x=!1,listViewRowCount:y=0}=e,h=s.useRef(!1),f=s.useRef(!1),w=s.useRef(!1),b=s.useRef(!1),m=s.useRef(!1),C=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||C.current||y<=Rc||(C.current=!0,console.warn(`[OpenGridX] The list view is rendering all ${y} items: it does not virtualize. Above a few thousand items use \`pagination\`, server-side loading, or the grid view. See docs/features/list-view.md.`))},[y]),s.useEffect(()=>{process.env.NODE_ENV==="production"||m.current||!x||(m.current=!0,console.warn("[OpenGridX] `listView` is set without a `listViewColumn`, so the grid view is shown instead. Pass `listViewColumn` to render list items. See docs/features/list-view.md."))},[x]),s.useEffect(()=>{process.env.NODE_ENV==="production"||w.current||!c||(w.current=!0,console.warn("[OpenGridX] `pinnedRows` is ignored while treeData or rowGroupingModel is active: the rows stay in their place in the hierarchy. See docs/features/pinning.md."))},[c]),s.useEffect(()=>{if(process.env.NODE_ENV==="production"||b.current||u===void 0)return;const E=Number.isFinite(u);if(E?a<=u:a<=Uc)return;b.current=!0;const _=E&&g!==void 0&&p!==void 0?`Only the first ${g.toLocaleString("en-US")} of ${p.toLocaleString("en-US")} rows can be scrolled to in this browser. `:"The last rows may not be reachable by scrolling. ";console.warn(`[OpenGridX] The grid content is ${Math.round(a)}px tall, more than this browser lays out (about 17.9M px in Firefox, 33.5M px in Chrome and Safari). `+_+'Load the rows on demand with a `dataSource` (server-side pages or infinite scroll, docs/features/data-source.md), use `pagination`, or a smaller rowHeight (density="compact"). See docs/features/virtualization.md#the-browser-height-limit.')},[a,u,g,p]),s.useEffect(()=>{process.env.NODE_ENV==="production"||h.current||t&&n&&(h.current=!0,console.warn("[OpenGridX] `pagination` is ignored while `rowGroupingModel` is active — all group rows render in one scrollable view. Give the grid a bounded height so it virtualizes. See docs/features/tree-data-grouping.md."))},[t,n]),s.useEffect(()=>{process.env.NODE_ENV==="production"||f.current||o||r>0&&l>Kc&&i>=l&&r>=a&&(f.current=!0,console.warn(`[OpenGridX] The grid viewport is ${Math.round(r)}px tall and is rendering all ${l} rows, so row virtualization is effectively off: the grid fills its container, and the container grows to fit every row. Give the container a definite height (for example \`height: 600px\` or \`100vh\`). If the container, or any ancestor up to the sized one, is a flex or grid item, add \`min-height: 0\` to it. Alternatively pass a \`height\` prop, or \`autoHeight\` if rendering every row is intended. See docs/features/virtualization.md.`))},[o,r,i,l,a])}function qc(e){return typeof window>"u"||typeof window.getComputedStyle!="function"||typeof navigator<"u"&&/jsdom/i.test(navigator.userAgent)?!1:window.getComputedStyle(e).display!=="flex"}let Ri=!1;function Xc(e){s.useEffect(()=>{if(process.env.NODE_ENV==="production"||Ri)return;const t=e.current;!t||!qc(t)||(Ri=!0,console.warn("[OpenGridX] The grid stylesheet is not loaded, so the grid is unstyled and renders every row (its viewport does not scroll). Add `import '@opencorestack/opengridx/styles'` once in your app root. See README.md, Getting Started."))},[e])}const Ui=e=>JSON.stringify(Array.from(e,t=>typeof t=="number"?["n",t]:["s",t]));function Yc(e){const{selectedRowIds:t,rowsLookup:n,rowMetaMap:o,enabled:r,onSelectionModelChange:i}=e,l=s.useMemo(()=>{if(!r||t.size===0)return t;let u=!1;for(const p of t)if(!n.has(p)&&!o.has(p)){u=!0;break}if(!u)return t;const g=new Set;for(const p of t)(n.has(p)||o.has(p))&&g.add(p);return g},[r,t,n,o]),c=s.useRef(i);s.useLayoutEffect(()=>{c.current=i});const a=s.useRef(null);return s.useEffect(()=>{if(l===t){a.current=null;return}const u=`${Ui(t)}|${Ui(l)}`;a.current!==u&&(a.current=u,c.current(Array.from(l)))},[l,t]),l}function zn(e,t,n,o){if(n&&o)return t.length>0?[t[t.length-1]]:Array.from(e);const r=new Set(e);return t.forEach(i=>n?r.add(i):r.delete(i)),Array.from(r)}function Jc(e,t,n){return n?e.has(t)?[]:[t]:zn(e,[t],!e.has(t),!1)}function ji(e,t){return t.length===e.size&&t.every(n=>e.has(n))}function Zc(e){const{selectedRowIds:t,onSelectionModelChange:n,disableMultipleRowSelection:o,selectableRowIds:r}=e,i=s.useCallback(p=>{ji(t,p)||n(p)},[t,n]),l=s.useCallback((p,x)=>{i(zn(t,[p],x,o))},[i,t,o]),c=s.useCallback(p=>{i(Jc(t,p,o))},[i,t,o]),a=s.useCallback(p=>{i(zn(t,r,p,!1))},[i,t,r]),{allSelected:u,someSelected:g}=s.useMemo(()=>{let p=0;for(const y of r)t.has(y)&&p++;const x=r.length>0&&p===r.length;return{allSelected:x,someSelected:!x&&p>0}},[r,t]);return{toggleRow:l,clickRow:c,selectAll:o?void 0:a,allSelected:u,someSelected:g}}const qi=new WeakMap;function Qc(e,t){const n=new Array(e.length),o=new Map;for(let r=0;r<e.length;r++){const i=t(e[r]);n[r]=i,o.has(i)||o.set(i,r)}return{rowIds:n,rowIndexById:o}}function Vo(e,t,n){let o=qi.get(t);const r=o?.get(n);if(r&&r.rows.length===e.length){const l=r.rows,c=r.value.rowIds;let a=!0;for(let u=0;u<e.length;u++){const g=e[u];if(g!==l[u]&&t(g)!==c[u]){a=!1;break}}if(a)return r.rows=e,r.value}const i=Qc(e,t);return o||(o=new Map,qi.set(t,o)),o.set(n,{rows:e,value:i}),i}function ed(e){const{dataRows:t,getRowId:n,isPivotActive:o,selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,disableRowSelectionOnClick:c,isHierarchyEnabled:a,rowMetaMap:u,activeHierarchyHandlers:g,onRowClick:p}=e,x=s.useMemo(()=>{const{rowIds:m}=Vo(t,n,"data");return o?m.filter(C=>C!==Gt):m},[t,n,o]),y=Zc({selectedRowIds:r,onSelectionModelChange:i,disableMultipleRowSelection:l,selectableRowIds:x}),{clickRow:h,toggleRow:f}=y,w=s.useCallback(m=>{const{id:C}=m,E=a?u.get(C):void 0;if(E?.isGroupRow){E.hasChildren&&g?.toggleExpansion(C);return}p?.(m),!c&&!Re(C,u)&&h(C)},[a,g,p,u,c,h]),b=s.useCallback((m,C)=>{Re(m,u)||f(m,C)},[u,f]);return{rowSelection:y,handleRowClick:w,handleSelectionChange:b}}function zo(e,t,n,o){return o?qa(e,t,n):n?[{field:t,sort:n}]:e.filter(r=>r.field!==t)}function td(e){const{sortModel:t,onSortModelChange:n}=e,o=s.useCallback((i,l)=>{n(zo(t,i,l,!1))},[t,n]),r=s.useCallback((i,l)=>{n(zo(t,i,l,!0))},[t,n]);return{handleSort:o,handleSortAdd:r}}function nd(e){const{columnVisibilityModel:t,onColumnVisibilityModelChange:n,pinnedColumns:o,onPinnedColumnsChange:r}=e,i=s.useRef({columnVisibilityModel:t,pinnedColumns:o});s.useLayoutEffect(()=>{i.current={columnVisibilityModel:t,pinnedColumns:o}});const l=s.useCallback(a=>{const u={...i.current.columnVisibilityModel,[a]:!1};i.current={...i.current,columnVisibilityModel:u},n(u)},[n]),c=s.useCallback((a,u)=>{const g=ha(i.current.pinnedColumns,a,u);i.current={...i.current,pinnedColumns:g},r(g)},[r]);return{handleHideColumn:l,handlePinColumn:c}}function od(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=t.current,r=()=>n.current;o.getSortModel=()=>r().sortModel,o.sortColumn=(a,u)=>{const{sortModel:g,multiSort:p,onSortModelChange:x}=r(),y=zo(g,a,u,p);n.current={...r(),sortModel:y},x(y)},o.getFilterModel=()=>r().filterModel,o.setFilterModel=a=>{n.current={...r(),filterModel:a},r().onFilterModelChange(a)};const i=a=>{n.current={...r(),paginationModel:a},r().onPaginationModelChange(a)};o.setPage=a=>i({...r().paginationModel,page:a}),o.setPageSize=a=>i({...r().paginationModel,pageSize:a,page:0});const l=()=>{const a=r().getPendingRowSelectionModel?.();return a?new Set(a):r().selectedRowIds},c=(a,u)=>{const{disableMultipleRowSelection:g,onRowSelectionModelChange:p,isSyntheticRowId:x}=r(),y=x?a.filter(w=>!x(w)):a;if(y.length===0)return;const h=l(),f=zn(h,y,u,g);ji(h,f)||(n.current={...r(),selectedRowIds:new Set(f)},p(f))};o.getSelectedRows=()=>Array.from(l()),o.selectRow=(a,u=!0)=>c([a],u),o.selectRows=(a,u=!0)=>c(a,u),o.getVisibleRows=()=>r().getVisibleRows(),o.getAllFilteredRows=()=>r().getAllFilteredRows(),o.getVisibleColumns=()=>r().visibleColumns,o.setSortModel=a=>{n.current={...r(),sortModel:a},r().onSortModelChange(a)},o.setRowGroupingModel=a=>{n.current={...r(),rowGroupingModel:a},r().onRowGroupingModelChange(a)},o.setAggregationModel=a=>{n.current={...r(),aggregationModel:a},r().onAggregationModelChange(a)},o.setColumnVisibilityModel=a=>{n.current={...r(),columnVisibilityModel:a},r().onColumnVisibilityModelChange(a)},o.setPivotModel=a=>{n.current={...r(),pivotModel:a},r().onPivotModelChange(a)},o.getGridAiState=()=>{const{filterModel:a,sortModel:u,rowGroupingModel:g,aggregationModel:p,pivotModel:x,columnVisibilityModel:y}=r();return{filterModel:a,sortModel:u,rowGroupingModel:g,aggregationModel:p,pivotModel:x,columnVisibilityModel:y}}},[t])}function rd(e){const{controlledState:t,interactions:n,api:o}=e,{sortModel:r,handleSortModelChange:i,filterModel:l,handleFilterModelChange:c,effectivePaginationModel:a,handlePaginationModelChange:u,handleRowSelectionModelChange:g,rowGroupingModel:p,handleRowGroupingModelChange:x,aggregationModel:y,handleAggregationModelChange:h,columnVisibilityModel:f,handleColumnVisibilityModelChange:w,currentPivotModel:b,handlePivotModelChange:m}=t,C=ed({...n,selectedRowIds:o.selectedRowIds,onSelectionModelChange:g,disableMultipleRowSelection:o.disableMultipleRowSelection});return od({...o,onSortModelChange:i,sortModel:r,filterModel:l,onFilterModelChange:c,paginationModel:a,onPaginationModelChange:u,getPendingRowSelectionModel:t.getPendingRowSelectionModel,onRowSelectionModelChange:g,rowGroupingModel:p,onRowGroupingModelChange:x,aggregationModel:y,onAggregationModelChange:h,columnVisibilityModel:f,onColumnVisibilityModelChange:w,pivotModel:b,onPivotModelChange:m}),C}const Xi="\0";function id(e,t){const n=e.filter(o=>t[o.field]===!1).map(o=>o.field).join(Xi);return s.useMemo(()=>{const o={};if(n)for(const r of n.split(Xi))o[r]=!1;return Lo(e,o)},[e,n])}function ld({paginationModel:e,currentPage:t,enabled:n,onPaginationModelChange:o}){const r=s.useRef({paginationModel:e,onPaginationModelChange:o});s.useLayoutEffect(()=>{r.current={paginationModel:e,onPaginationModelChange:o}});const i=e.page,l=s.useRef(null);s.useEffect(()=>{if(!n)return;if(t===i){l.current=null;return}const c=`${i}>${t}`;if(l.current===c)return;l.current=c;const{paginationModel:a,onPaginationModelChange:u}=r.current;u({...a,page:t})},[n,t,i])}const Te=()=>{},Ko=()=>Promise.resolve({updated:[],failed:[],skipped:[]});function Yi(){return{getRow:()=>null,getAllRows:()=>[],getVisibleRows:()=>[],getAllFilteredRows:()=>[],getGroupedExportRows:()=>null,getAggregationResult:()=>null,getAggregationModel:()=>null,getColumn:()=>null,getAllColumns:()=>[],getVisibleColumns:()=>[],selectRow:Te,selectRows:Te,getSelectedRows:()=>[],sortColumn:Te,getSortModel:()=>[],setFilterModel:Te,getFilterModel:()=>({items:[]}),setPage:Te,setPageSize:Te,scrollToIndexes:Te,autosizeColumn:Te,autosizeColumns:Te,copySelectedRows:()=>Promise.resolve(),getCellSelectionModel:()=>[],setCellSelectionModel:Te,selectCellRange:Te,clearCellSelection:Te,getSelectedCells:()=>[],copySelectedCells:()=>Promise.resolve(),pasteText:Ko,undo:Ko,redo:Ko,canUndo:()=>!1,canRedo:()=>!1,clearHistory:Te,setSortModel:Te,setRowGroupingModel:Te,setAggregationModel:Te,setColumnVisibilityModel:Te,setPivotModel:Te,getGridAiState:()=>({}),openAiAssistant:Te,closeAiAssistant:Te}}const sd=e=>e.id;let Ji=!1;function Zi(e,t,n){const o=new Map,r=new Map,i=new Map,l=[],c=[],a=[];return e.forEach(u=>{const g=n?.get(u)??t(u);if(o.has(g)){a.push(g);return}o.set(g,u),r.set(u,g),i.set(g,l.length),l.push(g),c.push(u)}),a.length>0&&!Ji&&process.env.NODE_ENV!=="production"&&(Ji=!0,console.warn(`[OpenGridX] ${a.length} row(s) reuse the id of an earlier row and were ignored (ids: ${a.slice(0,5).map(String).join(", ")}${a.length>5?", …":""}). Every row needs a unique id; pass getRowId if the unique key lives in another field.`)),{idRowsLookup:o,allRows:l,idByRow:r,rows:c,indexById:i}}function ad(e,t,n,o={}){const r=new Map,i=[];return n.forEach(l=>{r.set(l.field,l),i.push(l.field)}),{rows:Zi(e,t),columns:{all:n,lookup:r,orderedFields:i,columnVisibilityModel:o},pagination:{rowCount:void 0},pinning:{pinnedColumns:{},pinnedRows:{}},dimensions:{rowHeight:52,headerHeight:56,viewportWidth:0,viewportHeight:0},dataSource:{loading:!1,error:null}}}function Qi(e,t){const{idRowsLookup:n,idByRow:o,indexById:r}=e.rows;let i=null;for(const[l,c]of t){const a=r.get(l);if(a===void 0)continue;const u=n.get(l);u!==void 0&&u!==c&&o.delete(u),n.set(l,c),o.set(c,l),e.rows.rows[a]!==c&&(i??=e.rows.rows.slice(),i[a]=c)}return i?{...e,rows:{...e.rows,rows:i}}:e}function cd(e,t){switch(t.type){case"SET_ROWS":{const n=e.rows.rows,o=typeof t.payload=="function"?t.payload(n):t.payload;return{...e,rows:Zi(o,t.getRowId,e.rows.idByRow)}}case"REPLACE_ROW":return Qi(e,[[t.id,t.row]]);case"REPLACE_ROWS":return Qi(e,t.rows);case"SET_COLUMNS":{const n=new Map,o=[];return t.payload.forEach(r=>{n.set(r.field,r),o.push(r.field)}),{...e,columns:{all:t.payload,lookup:n,orderedFields:o,columnVisibilityModel:e.columns.columnVisibilityModel}}}case"SET_DIMENSIONS":return{...e,dimensions:{...e.dimensions,viewportWidth:t.payload.viewportWidth,viewportHeight:t.payload.viewportHeight}};case"SET_DATASOURCE_LOADING":return{...e,dataSource:{...e.dataSource,loading:t.payload}};case"SET_DATASOURCE_ERROR":return{...e,dataSource:{...e.dataSource,error:t.payload}};case"SET_ROW_COUNT":return{...e,pagination:{...e.pagination,rowCount:t.payload}};default:return e}}function dd(e){const{rows:t,columns:n,rowHeight:o=52,headerHeight:r=56,columnVisibilityModel:i,initialState:l,syncRows:c=!1}=e,a=e.getRowId??sd,u=s.useRef(a);s.useLayoutEffect(()=>{u.current=a});const[g]=s.useState(()=>ad(t,a,n,i)),[p,x]=s.useReducer(cd,{...g,dataSource:l?.dataSource?{...g.dataSource,...l.dataSource}:g.dataSource,pagination:{rowCount:l?.pagination?.rowCount},dimensions:{...g.dimensions,rowHeight:o,headerHeight:r}}),[y,h]=s.useState({rows:t,syncRows:c});(y.rows!==t||y.syncRows!==c)&&(h({rows:t,syncRows:c}),c&&x({type:"SET_ROWS",payload:t,getRowId:a}));const f=s.useRef(p);s.useLayoutEffect(()=>{f.current=p});const w=s.useCallback((P,L)=>{x({type:"SET_ROWS",payload:P,getRowId:u.current})},[]),b=s.useCallback((P,L)=>{x({type:"REPLACE_ROW",id:P,row:L})},[]),m=s.useCallback(P=>{P.size>0&&x({type:"REPLACE_ROWS",rows:P})},[]),C=s.useCallback(P=>{x({type:"SET_COLUMNS",payload:P})},[]),E=s.useCallback((P,L)=>{x({type:"SET_DIMENSIONS",payload:{viewportWidth:P,viewportHeight:L}})},[]),_=s.useCallback(P=>{x({type:"SET_DATASOURCE_LOADING",payload:P})},[]),I=s.useCallback(P=>{x({type:"SET_DATASOURCE_ERROR",payload:P})},[]),M=s.useCallback(P=>{x({type:"SET_ROW_COUNT",payload:P})},[]),[S]=s.useState(()=>({...Yi(),getRow:P=>f.current.rows.idRowsLookup.get(P)||null,getAllRows:()=>f.current.rows.rows.slice(),getColumn:P=>f.current.columns.lookup.get(P)||null,getAllColumns:()=>f.current.columns.all})),F=s.useRef(S);return{state:p,dispatch:x,apiRef:F,setRows:w,replaceRow:b,replaceRows:m,setColumns:C,setDimensions:E,setDataSourceLoading:_,setDataSourceError:I,setRowCount:M}}function ud(e){const{onRowOrderChange:t,rows:n,getRowId:o,indexById:r,rowReordering:i=!1}=e,[l,c]=s.useState(null),[a,u]=s.useState(null),g=s.useRef(()=>{}),p=s.useMemo(()=>{if(r)return r;const b=new Map;return n.forEach((m,C)=>b.set(o?o(m):m.id,C)),b},[r,n,o]),x=s.useCallback(b=>p.has(b),[p]),y=s.useCallback(()=>{g.current(),g.current=()=>{},c(null),u(null)},[]);s.useEffect(()=>()=>g.current(),[]);const h=s.useCallback(b=>m=>{if(i){if(!p.has(b)){m.preventDefault();return}g.current(),g.current=Wi(m.currentTarget,y),c(b),m.dataTransfer&&(m.dataTransfer.effectAllowed="move",Bi(m,Ho,String(b)))}},[i,p,y]),f=s.useCallback(b=>m=>{if(!(!i||l===null)){if(!Wn(m,Ho)){y();return}p.has(b)&&(m.preventDefault(),m.dataTransfer&&(m.dataTransfer.dropEffect="move"),a!==b&&u(b))}},[i,l,a,p,y]),w=s.useCallback(b=>m=>{if(m.preventDefault(),l===null||!Wn(m,Ho)){y();return}const C=p.get(l),E=p.get(b);y(),t&&C!==void 0&&E!==void 0&&C!==E&&t({row:n[C],oldIndex:C,targetIndex:E})},[l,t,n,p,y]);return{draggedRowId:l,dragOverRowId:a,canReorderRow:x,onDragStart:i?h:void 0,onDragOver:i?f:void 0,onDragEnd:i?y:void 0,onDrop:i?w:void 0}}const el=new Map,tl=e=>JSON.stringify(e),fd=e=>`auto-group-${e}`,nl=5,ol=e=>e.slice(0,nl).map(t=>JSON.stringify(t)).join(", ")+(e.length>nl?", …":""),gd={treeNodes:new Map,rootIds:[],groupingRows:[],syntheticIds:new Set,rowLookup:new Map,issues:[]};function pd(e,t,n){const o=new Map,r=[],i=[],l=new Set,c=new Map,a=new Map,u=[],g=new Array(e.length),p=new Array(e.length),x=[],y=new Map;e.forEach((f,w)=>{const b=t(f),m=n(f),C=Array.isArray(m)?m.map(E=>String(E)):[];if(g[w]=b,p[w]=C,c.set(b,f),C.length===0)x.push(b);else{const E=tl(C),_=a.get(E);if(_===void 0)a.set(E,b);else{const I=y.get(E)??[_];I.push(b),y.set(E,I)}}o.set(b,{id:b,parentId:null,depth:Math.max(C.length-1,0),groupingKey:C[C.length-1]??"",isExpanded:!1,children:[],serverChildrenCount:f.serverChildrenCount})});const h=f=>{const w=tl(f),b=a.get(w);if(b!==void 0)return b;const m=fd(w),C=f[f.length-1],E={id:m,parentId:null,depth:f.length-1,groupingKey:C,isExpanded:!1,children:[],label:C};o.set(m,E),a.set(w,m),l.add(m);const _={id:m};if(i.push(_),c.set(m,_),f.length===1)r.push(m);else{const I=h(f.slice(0,-1));E.parentId=I,o.get(I)?.children?.push(m)}return m};return e.forEach((f,w)=>{const b=g[w],m=p[w];if(m.length<=1){r.push(b);return}const C=h(m.slice(0,-1)),E=o.get(b);E&&(E.parentId=C),o.get(C)?.children?.push(b)}),x.length>0&&u.push(`[OpenGridX] treeData: getTreeDataPath returned an empty path for row(s) ${ol(x)}. They are shown as top-level rows.`),y.forEach((f,w)=>{u.push(`[OpenGridX] treeData: rows ${ol(f)} have the same path ${w}. Rows under that path are attached to row ${JSON.stringify(f[0])}.`)}),{treeNodes:o,rootIds:r,groupingRows:i,syntheticIds:l,rowLookup:c,issues:u}}function hd(e,t){const{treeNodes:n,rootIds:o,syntheticIds:r,rowLookup:i}=e,l=new Set,c=new Map,a=new Map,u=g=>{const p=n.get(g);if(!p)return!1;const x=[];let y=0;for(const b of p.children??[])u(b)&&(x.push(b),y+=(r.has(b)?0:1)+(a.get(b)??0));c.set(g,x),a.set(g,y);const h=i.get(g),w=!r.has(g)&&h!==void 0&&(t?t(h):!0)||x.length>0;return w&&l.add(g),w};return o.forEach(u),{visible:l,visibleChildren:c,descendantCounts:a}}function md(e){const{rows:t,getRowId:n,getTreeDataPath:o,treeData:r=!1,defaultGroupingExpansionDepth:i=0,filterModel:l,sortModel:c,onRowExpansionChange:a,columnLookup:u,filterMode:g="client",sortingMode:p="client"}=e,x=r&&!!o,y=s.useMemo(()=>!r||!o?gd:pd(t,n,o),[t,o,r,n]),{treeNodes:h,rootIds:f,groupingRows:w,syntheticIds:b,rowLookup:m}=y,C=y.issues.join(`
|
|
2
2
|
`);s.useEffect(()=>{process.env.NODE_ENV==="production"||!C||C.split(`
|
|
3
|
-
`).forEach(z=>console.warn(z))},[C]);const E=r&&!o;s.useEffect(()=>{process.env.NODE_ENV==="production"||!E||console.warn("[OpenGridX] treeData is set without getTreeDataPath, so the rows are shown as a flat list. Pass getTreeDataPath={(row) => row.path} to build the tree.")},[E]);const S=s.useMemo(()=>g==="server"?null:Pn(l,u),[g,l,u]),N=s.useMemo(()=>sd(y,S),[y,S]),M=`${r}|${i}`,[_,F]=s.useState(()=>({configKey:M,overrides:new Map})),A=_.configKey===M?_.overrides:Ui,L=s.useCallback(z=>((z?.children?.length??0)>0||(z?.serverChildrenCount??0)>0)&&(i===-1||(z?.depth??0)<i),[i]),k=s.useMemo(()=>{const z=new Set;return x&&p.forEach((H,re)=>{(A.get(re)??L(H))&&z.add(re)}),z},[x,p,A,L]),I=s.useCallback(z=>{const H=!k.has(z);if(F(re=>{const ee=re.configKey===M?re.overrides:Ui,de=new Map(ee);return de.set(z,H),{configKey:M,overrides:de}}),H&&c){const re=p.get(z);re&&c(re)}},[k,M,p,c]),P=m!=="server"&&!!(a&&a.length>0),v=s.useCallback(z=>{if(!x)return null;const H=z?.labelField,re=z?.expandAll??!1,{visible:ee,visibleChildren:de}=N,ie=P&&a?a:[],ae=(te,V)=>{if(b.has(te))return{value:V.field===H?p.get(te)?.label:void 0};const U=w.get(te),ce=u?.byField.get(V.field),ge=U?Me(U,V.field,ce):void 0,Q=ce?.sortComparator;return{value:ge,type:ce?.type,comparator:Q,params:Q&&U?{id:te,field:V.field,row:U,value:ge}:void 0}},R=[],ue=new Set,q=te=>{const V=te.filter(ce=>ee.has(ce)),U=ie.length>0?oi(V,ie,ae):V;for(const ce of U){if(ue.has(ce))continue;const ge=w.get(ce);if(!ge)continue;ue.add(ce),R.push(ge);const Q=de.get(ce);Q&&Q.length>0&&(re||k.has(ce))&&q(Q)}};return q(f),R},[x,N,P,a,b,p,w,u,f,k]),B=s.useCallback(z=>k.has(z),[k]),W=s.useCallback(z=>p.get(z),[p]),J=s.useCallback(z=>{const H=[];let re=z;for(;re!==null;){const ee=p.get(re);if(!ee)break;H.unshift(ee.groupingKey),re=ee.parentId}return H},[p]),G=s.useMemo(()=>{const z=new Map,{visibleChildren:H,descendantCounts:re}=N;return p.forEach((ee,de)=>{const ie=(ee.children?.length??0)===0&&(ee.serverChildrenCount??0)>0,ae=b.has(de),R={hasChildren:(H.get(de)?.length??0)>0||ie,treeDepth:ee.depth,descendantCount:ie?void 0:re.get(de)??0,isGroupRow:ae,isExpanded:k.has(de)};ae&&(R.groupLabel=ee.label),z.set(de,R)}),z},[p,b,N,k]);return s.useMemo(()=>({treeNodes:p,groupingRows:h,toggleExpansion:I,isGroupExpanded:B,getVisibleRows:v,getNode:W,getNodePath:J,rowMetaMap:G}),[p,h,I,B,v,W,J,G])}const Yi=e=>e===null?"footer":"inline";function Ji(e,t){return uo(()=>e(t),Yi(t),"getAggregationPosition","getAggregationPosition threw; the default position is used")}function cd(e,t,n){const o=`${t}: ${String(n)}`,r=e?.groupingValueFormatter;return r?uo(()=>r({field:t,value:n}),o,`groupingValueFormatter:${t}`,`groupingValueFormatter for column "${t}" threw; the group is labelled "${t}: value"`):o}const dd=[],ud={},Zi=new Map,Ze="";function fd(e){if(typeof e=="string")return e;if(e===null)return`${Ze}null`;if(e===void 0)return`${Ze}undefined`;if(e instanceof Date)return`${Ze}date:${e.getTime()}`;if(typeof e=="object")try{return`${Ze}object:${JSON.stringify(e)}`}catch{return`${Ze}object:${String(e)}`}return`${Ze}${typeof e}:${String(e)}`}const gd=(e,t,n)=>`auto-group-${e}-${t}-${n??"root"}`,pd=e=>`${e}${Ze}footer`,hd=e=>e==="footer"?"f":e===null?"n":"i",md=e=>e==="f"?"footer":e==="n"?null:"inline";function wd(e){const{rows:t,getRowId:n,columns:o,rowGroupingModel:r=dd,aggregationModel:i=ud,defaultGroupingExpansionDepth:l=0,filterModel:a,sortModel:c,getAggregationPosition:u=Yi,columnLookup:g,filterMode:m="client",sortingMode:x="client"}=e,y=r.join(Ze),p=s.useMemo(()=>y===""?[]:y.split(Ze),[y]),f=JSON.stringify(Object.entries(i)),h=s.useMemo(()=>Object.fromEntries(JSON.parse(f)),[f]),b=Object.keys(h).length>0,w=s.useMemo(()=>{const q=new Map;return(o??[]).forEach(te=>q.set(te.field,te)),q},[o]),C=p.length>0,E=s.useMemo(()=>p.filter(q=>w.get(q)?.groupable!==!1),[p,w]),N=`${E.join(Ze)}|${l}`,[M,_]=s.useState(()=>({configKey:N,overrides:new Map})),F=M.configKey===N?M.overrides:Zi,A=s.useMemo(()=>{if(!C||m==="server")return null;const q=Pn(a,g);return q?new Set(t.filter(te=>q(te))):null},[C,t,m,a,g]),L=s.useMemo(()=>{const q=new Map,te=[],V=[],U=new Map,ce=new Map,ge=new Map;if(!C)return{treeNodes:q,rootIds:te,groupIds:V,groupRowVariants:U,groupingRows:ce,rowLookup:ge};const Q=(D,T,$)=>{if(T>=E.length)return(A?D.filter(Y=>A.has(Y)):D).map(Y=>{const oe=n(Y);return ge.set(oe,Y),q.set(oe,{id:oe,parentId:$,depth:T,groupingKey:"",isExpanded:!1}),oe});const O=E[T],Z=w.get(O),j=new Map;for(const X of D){const Y=Me(X,O,Z),oe=fd(Y);let he=j.get(oe);he||(he={value:Y,rows:[]},j.set(oe,he)),he.rows.push(X)}const ne=[];return j.forEach((X,Y)=>{const oe=A?X.rows.filter(xe=>A.has(xe)):X.rows;if(oe.length===0)return;const he=gd(O,Y,$);ne.push(he),V.push(he);const me=b?Ln(oe,h,w,"useRowGrouping"):{},K={[O]:X.value,...me,id:he},fe={[O]:X.value,id:he},we=b?{...me,id:pd(he)}:null;U.set(he,{inline:K,bare:fe,footer:we}),ce.set(he,K),we&&ce.set(we.id,we);const le={id:he,parentId:$,depth:T,groupingKey:String(X.value),groupingField:O,groupingValue:X.value,aggregatedValues:me,isExpanded:!1,children:[],label:cd(Z,O,X.value),descendantCount:oe.length};q.set(he,le),le.children=Q(X.rows,T+1,he)}),ne};return te.push(...Q(t,0,null)),{treeNodes:q,rootIds:te,groupIds:V,groupRowVariants:U,groupingRows:ce,rowLookup:ge}},[C,t,A,E,b,h,n,w]),{treeNodes:k,rootIds:I,groupIds:P,groupRowVariants:v,groupingRows:B,rowLookup:W}=L,J=s.useCallback(q=>!!(q?.children&&q.children.length>0)&&(l===-1||(q?.depth??0)<l),[l]),G=s.useMemo(()=>{const q=new Set;for(const te of P){const V=k.get(te);!V?.children||V.children.length===0||(F.get(te)??J(V))&&q.add(te)}return q},[P,k,F,J]),z=s.useCallback(q=>{_(te=>{const V=te.configKey===N?te.overrides:Zi,U=V.get(q)??J(k.get(q)),ce=new Map(V);return ce.set(q,!U),{configKey:N,overrides:ce}})},[N,k,J]),H=s.useCallback(q=>G.has(q),[G]),re=b?P.map(q=>{const te=k.get(q);return te?hd(Ji(u,{...te,isExpanded:G.has(q)})):"i"}).join(""):"",ee=s.useMemo(()=>{const q=new Map;return P.forEach((te,V)=>q.set(te,md(re[V]))),q},[P,re]),de=b?Ji(u,null):"footer",ie=x!=="server"&&!!(c&&c.length>0),ae=s.useCallback(q=>{if(!C)return null;const te=q?.labelField,V=q?.expandAll??!1,U=ie&&c?c:[],ce=(T,$)=>{const O=k.get(T),Z=v.get(T);if(O&&Z){const oe=O.groupingField??"";if($.field===oe||$.field===te){const he=g?.byField.get(oe),me=he?.sortComparator;return{value:O.groupingValue,type:he?.type,comparator:me,params:me?{id:T,field:oe,row:Z.inline,value:O.groupingValue}:void 0}}return O.aggregatedValues&&Object.prototype.hasOwnProperty.call(O.aggregatedValues,$.field)?{value:O.aggregatedValues[$.field],type:g?.byField.get($.field)?.type}:{value:void 0}}const j=W.get(T),ne=g?.byField.get($.field),X=j?Me(j,$.field,ne):void 0,Y=ne?.sortComparator;return{value:X,type:ne?.type,comparator:Y,params:Y&&j?{id:T,field:$.field,row:j,value:X}:void 0}},ge=[],Q=new Set,D=T=>{const $=U.length>0?oi(T,U,ce):T;for(const O of $){if(Q.has(O))continue;Q.add(O);const Z=v.get(O);if(!Z){const oe=W.get(O);oe&&ge.push(oe);continue}const j=k.get(O),ne=G.has(O),X=ee.has(O)?ee.get(O)??null:"inline",Y=X==="inline"||X==="footer"&&!ne;ge.push(Y?Z.inline:Z.bare),(ne||V)&&j?.children&&(D(j.children),ne&&!V&&X==="footer"&&Z.footer&&ge.push(Z.footer))}};return D(I),ge},[C,ie,c,k,v,W,g,G,ee,I]),R=s.useCallback(q=>k.get(q),[k]),ue=s.useMemo(()=>{const q=new Map;return k.forEach((te,V)=>{const U=v.get(V);if(!U){q.set(V,{hasChildren:!1,treeDepth:te.depth,isGroupRow:!1});return}const ce={hasChildren:!0,treeDepth:te.depth,groupingField:te.groupingField,groupingValue:te.groupingValue,groupLabel:te.label,descendantCount:te.descendantCount,isGroupRow:!0,isExpanded:G.has(V)};q.set(V,ce),U.footer&&ee.get(V)==="footer"&&q.set(U.footer.id,{...ce,hasChildren:!1,treeDepth:te.depth+1,isExpanded:void 0,isGroupFooter:!0})}),q},[k,v,G,ee]);return s.useMemo(()=>({treeNodes:k,groupingRows:B,toggleExpansion:z,isGroupExpanded:H,getVisibleRows:ae,getNode:R,rowMetaMap:ue,aggregationPositions:ee,rootAggregationPosition:de}),[k,B,z,H,ae,R,ue,ee,de])}const bd=new Map;function xd(e){const{rows:t,getRowId:n,getTreeDataPath:o,isTreeDataRequested:r,isTreeData:i,columns:l,rowGroupingModel:a,isRowGrouping:c,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:m,sortModel:x,getAggregationPosition:y,columnLookup:p,filterMode:f,sortingMode:h}=e,b=ad({rows:t,getRowId:n,getTreeDataPath:o,treeData:r,defaultGroupingExpansionDepth:g,filterModel:m,sortModel:x,columnLookup:p,filterMode:f,sortingMode:h}),w=wd({rows:t,getRowId:n,columns:l,rowGroupingModel:a,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:m,sortModel:x,getAggregationPosition:y,columnLookup:p,filterMode:f,sortingMode:h}),C=i?b:c?w:null,E=s.useMemo(()=>i?b.rowMetaMap:c?w.rowMetaMap:bd,[i,b.rowMetaMap,c,w.rowMetaMap]);return{treeDataHandlers:b,rowGroupingHandlers:w,activeHierarchyHandlers:C,rowMetaMap:E}}function yd(e){const{spanning:t,renderContext:n,offsetTop:o,cumulativeHeights:r}=e;return s.useMemo(()=>{if(!t.hasRowSpan)return{renderContext:n,offsetTop:o};let i=Math.max(0,n.firstRowIndex);for(let l=t.getCenterRowSpanStart(i);l<i;l=t.getCenterRowSpanStart(i))i=l;return i>=n.firstRowIndex?{renderContext:n,offsetTop:o}:{renderContext:{...n,firstRowIndex:i},offsetTop:i>0?r[i-1]??0:0}},[t,n,o,r])}function Cd(e){const{spanning:t,firstColumnIndex:n,lastColumnIndex:o,virtualColumns:r,layout:i,rows:l}=e;return s.useMemo(()=>{if(!t.hasColSpan||i.unpinnedColsWithWidth.length===0)return r;let a=n,c=o,u=!0;for(;u;){u=!1;for(const{row:b,id:w}of l){const C=t.getUnpinnedColSpanRanges(w??b.id);if(C)for(let E=0;E<C.length;E+=2){const S=C[E],N=C[E+1];N<a||S>c||(S<a&&(a=S,u=!0),N>c&&(c=N,u=!0))}}}if(a===n&&c===o)return r;const{leftPinnedCols:g,unpinnedColsWithWidth:m,rightPinnedCols:x,unpinnedAccWidths:y,unpinnedTotalWidth:p}=i,f=a>0?y[a-1]:0,h=p-y[c];return[...g,...f>0?[{field:"__spacer_left__",width:f,isSpacer:!0}]:[],...m.slice(a,c+1),...h>0?[{field:"__spacer_right__",width:h,isSpacer:!0}]:[],...x]},[t,n,o,r,i,l])}function vd(e){const{headerRowCount:t,pinnedTopCount:n,pinnedBottomCount:o,pageRowCount:r,totalCenterRowCount:i,pageOffset:l}=e;return{rowCount:t+n+i+o,topBase:t+1,centerOffset:t+l+1,bottomBase:t+n+i+1,bottomRowIndexOffset:n+r}}function Qi(e){if(!e)return 0;let t=0;const n=(o,r)=>{t=Math.max(t,r);for(const i of o.children)typeof i!="string"&&n(i,r+1)};return e.forEach(o=>n(o,1)),t}function el(e){const t=new Map;if(!e)return t;const n=(o,r)=>{const i=[...r,o];for(const l of o.children)typeof l=="string"?t.has(l)||t.set(l,i):n(l,i)};return e.forEach(o=>n(o,[])),t}function Vo(e,t,n){if(!e||e.length===0)return!0;const o=el(e),r=o.get(t),i=o.get(n);return(r?.[r.length-1]??null)===(i?.[i.length-1]??null)}function Sd(e,t,n){const o=[];let r=0,i=null,l=null;for(const a of e){const c=a.isSpacer?null:t.get(a.field)?.[n]??null;(i===null||l!==c||i.pinned!==a.pinned)&&(i={key:`${c?c.groupId:"filler"}-${n}-${a.field}`,isGroup:c!==null,label:c?.headerName??"",headerClassName:c?.headerClassName,width:0,flexGrow:0,fields:[],firstDataIndex:r,pinned:a.pinned},l=c,o.push(i)),i.width+=a.width,i.flexGrow+=a.flex??0,a.isSpacer||(i.fields.push(a.field),r++)}return o}function _d(e){const{columnGroupingModel:t,headerFilterRow:n=!1,pinnedTopCount:o,pinnedBottomCount:r,pagination:i,paginationMode:l,paginationModel:a,paginationRowCount:c,paginatedUnpinnedRowCount:u,sortedUnpinnedRowCount:g}=e,{page:m,pageSize:x}=a;return s.useMemo(()=>vd({headerRowCount:1+Qi(t)+(n?1:0),pinnedTopCount:o,pinnedBottomCount:r,pageRowCount:i?u:g,totalCenterRowCount:i&&l==="server"?Math.max(c,u):g,pageOffset:i?m*x:0}),[t,n,o,r,i,u,g,l,c,m,x])}const kd=e=>e.id;function Ed(e){const{renderContext:t,pinnedTopRows:n,pinnedBottomRows:o,paginatedUnpinnedRows:r,sortedUnpinnedRows:i,pagination:l,getRowId:a=kd}=e;return s.useMemo(()=>{const{firstRowIndex:c,lastRowIndex:u}=t,g=l?r:i,m=n.length,x=n.map((C,E)=>({row:C,id:a(C),rowIndex:E,pinned:"top"})),y=o.map((C,E)=>({row:C,id:a(C),rowIndex:m+g.length+E,pinned:"bottom"})),p=Math.max(0,c),f=Math.min(g.length,u+1),h=g.slice(p,f).map((C,E)=>({row:C,id:a(C),rowIndex:m+p+E})),b=[...x,...h,...y],w=new Set;return b.filter(C=>w.has(C.id)?!1:(w.add(C.id),!0))},[t,n,o,r,i,l,a])}function Md(e){const{aria:t,spanning:n,virtualization:o,layout:r,pinnedTopRows:i,pinnedBottomRows:l,paginatedUnpinnedRows:a,sortedUnpinnedRows:c,pagination:u,getRowId:g}=e,m=_d(t),x=yd({spanning:n,renderContext:o.renderContext,offsetTop:o.offsetTop,cumulativeHeights:r.cumulativeHeights}),y=Ed({renderContext:x.renderContext,pinnedTopRows:i,pinnedBottomRows:l,paginatedUnpinnedRows:a,sortedUnpinnedRows:c,pagination:u,getRowId:g}),p=Cd({spanning:n,firstColumnIndex:o.renderContext.firstColumnIndex,lastColumnIndex:o.renderContext.lastColumnIndex,virtualColumns:o.virtualColumns,layout:r,rows:y});return{ariaRows:m,spanRowWindow:x,visibleRows:y,renderColumns:p}}const Nd=new Set(["__group__","__check__","__actions__"]);function Et(e){return e.filter(t=>t.exportable!==!1&&!t.isSpacer&&!Je(t.field)&&!Nd.has(t.field))}function dt(e){return!!e&&e.length>0}function tl(e,t,n=o=>o.id){const o=new Set(t);return e.filter(r=>o.has(n(r)))}function sn(e,t,n){return dt(t)?tl(e,t,n):e}function an(e,t){return!!e&&e.length>0&&!dt(t)}function Bt(e,t,n,o,r){if(!o)return null;if(!t||!r||Object.keys(r).length===0)return o;const i=new Map(n.map(l=>[l.field,l]));return Ln(e,r,i,"export")}function cn(e,t){return Me(e,t.field,t)}function dn(e,t,n){if(!t.valueFormatter)return En(n,t);if(n==null)try{return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}catch{return""}return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}function zo(e,t,n,o){return n==null?"":An(n,t??"",e,o)}function Wt(e,t){return t?`${e}: ${t}`:e}function nl(e,t){const n={};return t.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o.field)&&(n[o.field]=e[o.field])}),n}const Id=/^[=+\-@\t\r]/,Ld=/^[-+]?(?=[\d.,\s]*\d)[\d.,\s]*%?$/;function Rn(e,t=!1){return t||!Id.test(e)||Ld.test(e)?e:`'${e}`}const Ad=/^[\d\s.,'%+\-()\p{Sc}]*$/u;function Pd(e,t,n){return Vt(e)?!n||Ad.test(t):!1}function Vt(e){return typeof e=="number"||typeof e=="bigint"||typeof e=="boolean"||e instanceof Date}function Te(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Td(e){let t=0,n=e.length;for(;t<n&&e[t]==="'";)t++;for(;n>t&&e[n-1]==="'";)n--;return e.slice(t,n)}const Fd=/[\\/?*:[\]]/g,ol=31;function Ro(e,t=new Set){let n=Td(String(e??"").replace(Fd,"-").trim()).trim();n||(n="Sheet"),n=n.slice(0,ol).trim();const o=i=>t.has(i.toLowerCase())||i.toLowerCase()==="history";let r=n;for(let i=2;o(r);i++){const l=` (${i})`;r=`${n.slice(0,ol-l.length).trim()}${l}`}return t.add(r.toLowerCase()),r}const Od=new Set([Ye,St,vt]),Dd=/[\t\n\r"]/;function Ko(e){return Dd.test(e)?`"${e.replace(/"/g,'""')}"`:e}function $d(e){return Et(e).filter(t=>!Od.has(t.field))}function Gd(e,t){const n=t.map(r=>Ko(r.headerName||r.field)).join(" "),o=e.map(r=>t.map(i=>Ko(dn(r,i,Me(r,i.field,i)))).join(" "));return[n,...o].join(`
|
|
4
|
-
`)}function
|
|
5
|
-
`)}function
|
|
6
|
-
`||
|
|
7
|
-
`?2:1):(o+=a,r+=1)}return(!l||n.length>0||o!=="")&&(n.push(o),t.push(n)),t}const Kd=/^\d+(?:\.\d*)?(?:e[+-]?\d+)?$/i,Ud=/^\.\d+(?:e[+-]?\d+)?$/i,jd=/^\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,qd=/[\p{Sc}\s]/gu;function Xd(e){let t=e.replace(qd,"");if(t==="")return e.trim()===""?Fe(null):ot;let n=!1;t.startsWith("(")&&t.endsWith(")")&&(n=!0,t=t.slice(1,-1)),(t.startsWith("-")||t.startsWith("+")||t.startsWith("−"))&&(t[0]!=="+"&&(n=!n),t=t.slice(1));let o=!1;if(t.endsWith("%")&&(o=!0,t=t.slice(0,-1)),jd.test(t))t=t.split(",").join("");else if(!Kd.test(t)&&!Ud.test(t))return ot;let r=Number(t);return Number.isFinite(r)?(o&&(r/=100),n&&(r=-r),Fe(r)):ot}const Yd=/^(\d{4}-\d{2}-\d{2})/,il=e=>String(e).padStart(2,"0");function Jd(e){const t=e.trimEnd();if(t.endsWith("Z")||t.endsWith("z"))return!0;const n=t.indexOf("T");if(n<0)return!1;for(let o=t.length-1;o>n;o--){const r=t[o];if(r==="+"||r==="-")return!0;if(!(r>="0"&&r<="9")&&r!==":")return!1}return!1}const Zd=e=>`${e.getFullYear()}-${il(e.getMonth()+1)}-${il(e.getDate())}`;function Qd(e,t){const n=e.trim();if(n==="")return Fe(null);const o=Qt(n);if(!o)return ot;if(typeof t=="number")return Fe(o.getTime());if(typeof t=="string"){const r=Zd(o);if(!Yd.test(t)||t.length<=10)return Fe(r);const i=Jd(t)?new Date(t):null;return i&&!Number.isNaN(i.getTime())?Fe(new Date(o.getFullYear(),o.getMonth(),o.getDate(),i.getHours(),i.getMinutes(),i.getSeconds(),i.getMilliseconds()).toISOString()):Fe(r+t.slice(10))}return Fe(o)}const eu=new Set(["true","yes","1"]),tu=new Set(["false","no","0"]);function nu(e,t){const n=e.trim().toLowerCase();return n===""?Fe(null):t?.trueLabel!==void 0&&n===t.trueLabel.trim().toLowerCase()?Fe(!0):t?.falseLabel!==void 0&&n===t.falseLabel.trim().toLowerCase()?Fe(!1):eu.has(n)?Fe(!0):tu.has(n)?Fe(!1):ot}function ou(e,t){const n=e.trim();if(n==="")return Fe(null);if(!t||t.length===0)return ot;const o=n.toLowerCase();for(const r of t){const i=typeof r=="object"?r.value:r;if(String(i).toLowerCase()===o)return Fe(i)}for(const r of t)if(typeof r=="object"&&r.label.toLowerCase()===o)return Fe(r.value);return ot}function ru(e,t,n){switch(t?.type){case"number":return Xd(e);case"date":return Qd(e,n?.current);case"boolean":return nu(e,n?.booleanLabels);case"singleSelect":return ou(e,t.valueOptions);default:return Fe(e)}}function iu(e,t,n,o){const{valueParser:r}=t;if(!r)return ru(e,t,o);let i;try{i=r(e,{row:n,field:t.field,colDef:t})}catch{return ot}return i===void 0?ot:Fe(i)}function jo(e,t,n){const o=e.map(t),r=new Map;o.forEach((c,u)=>{r.has(c)||r.set(c,u)});const i=n.filter(c=>Ke(c.field)),l=new Map;i.forEach((c,u)=>{l.set(c.field,u)});const a=n.filter(c=>Je(c.field)).length;return{rows:e,rowIds:o,rowIndexById:r,columns:i,colIndexByField:l,dataColumnOffset:a}}function qo(e,t,n,o,r){const i=e.rowIds[o],l=e.columns[r];if(!l||Re(i,t.rowMetaMap))return!1;const a=t.getSpanOrigin?.(i,l.field);return a&&(a.rowId!==i||a.field!==l.field)?!1:wo({row:n,field:l.field,value:Me(n,l.field,l),colDef:l,rowIndex:o,colIndex:e.dataColumnOffset+r,rowMeta:t.rowMetaMap?.get(i)},t.isCellEditable)}function lu(e,t){let n=1/0,o=-1/0,r=1/0,i=-1/0;for(const l of t){const a=e.rowIndexById.get(l.id),c=e.colIndexByField.get(l.field);a===void 0||c===void 0||(a<n&&(n=a),a>o&&(o=a),c<r&&(r=c),c>i&&(i=c))}return n===1/0?null:{top:n,bottom:o,left:r,right:i}}function ll(e,t){return{anchor:{id:e.rowIds[t.top],field:e.columns[t.left].field},head:{id:e.rowIds[t.bottom],field:e.columns[t.right].field}}}function su(e){const t=e?.type;return t===void 0||t==="string"||t==="image"}const sl=1e4,Kn=()=>({updated:[],failed:[],skipped:[]});function au(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Pasting ${e} cells. Pastes above ${sl} cells can be slow; consider importing the data instead.`)}function cu(e){const{apiRef:t,containerRef:n,selection:o,disableClipboardPaste:r,disableRangeClear:i}=e,l=s.useRef(e);s.useLayoutEffect(()=>{l.current=e});const a=s.useCallback(()=>{const{allRenderableRows:p,getRowId:f,navigationColumns:h}=l.current;return jo(p,f,h)},[]),c=s.useCallback(()=>{const{selection:p}=l.current;return p.enabled?p.getCurrentRange().resolved:null},[]),u=s.useCallback(p=>{const f=c();if(f&&p.rowIds[f.top]!==void 0&&p.columns[f.left])return{id:p.rowIds[f.top],field:p.columns[f.left].field};const h=l.current.focusedCell;return h&&h.id!==null&&Ke(h.field)?{id:h.id,field:h.field}:null},[c]),g=s.useCallback(async(p,f,h)=>{const b=a(),w=f??u(b);let C=p;const{onBeforeClipboardPaste:E}=l.current;if(E){const ie=We(()=>E({text:C,anchor:w}));if(!ie.ok)return Ct("onBeforeClipboardPaste","onBeforeClipboardPaste threw; the paste was cancelled",ie.error),Kn();if(ie.value===!1)return Kn();typeof ie.value=="string"&&(C=ie.value)}if(!w)return Kn();const S=Rd(C),N=b.rowIndexById.get(w.id),M=b.colIndexByField.get(w.field);if(S.length===0||N===void 0||M===void 0)return Kn();const _=b.rowIds.length-1,F=b.columns.length-1,A=f?null:c(),L=A&&_t(A)>1?A:null,k=S.length===1&&S[0].length===1,I=S.reduce((ie,ae)=>Math.max(ie,ae.length),0);let P;k&&L?P=L:P={top:N,left:M,bottom:Math.min(N+S.length-1,_,L?L.bottom:_),right:Math.min(M+I-1,F,L?L.right:F)};const v=_t(P);v>sl&&au(v);const{batchEdit:B,isCellEditable:W,rowMetaMap:J,getSpanOrigin:G}=l.current,z={isCellEditable:W,rowMetaMap:J,getSpanOrigin:G},H=[],re=[];for(let ie=P.top;ie<=P.bottom;ie++){const ae=b.rowIds[ie],R=B.getRow(ae)??b.rows[ie],ue=k?S[0]:S[ie-P.top];for(let q=P.left;q<=P.right;q++){const te=k?S[0][0]:ue?.[q-P.left];if(te===void 0)continue;const V=b.columns[q];if(!qo(b,z,R,ie,q)){re.push({id:ae,field:V.field,reason:"notEditable"});continue}const U=iu(te,V,R,{current:Me(R,V.field,V)});if(!U.ok){re.push({id:ae,field:V.field,reason:"invalidValue"});continue}H.push({id:ae,field:V.field,value:U.value})}}if(l.current.selection.enabled){const{anchor:ie,head:ae}=ll(b,P);l.current.selection.setModel([{anchor:ie,head:ae}],h?"keyboard":"api")}const ee=await B.applyEdits(H,"paste"),de={updated:ee.result.updated,failed:ee.result.failed,skipped:[...re,...ee.result.skipped]};return l.current.onClipboardPaste?.({...de,text:C}),de},[a,u,c]),m=s.useCallback(()=>{const p=c();if(!p||_t(p)<=1)return!1;const f=a(),{batchEdit:h,isCellEditable:b,rowMetaMap:w,getSpanOrigin:C}=l.current,E={isCellEditable:b,rowMetaMap:w,getSpanOrigin:C},S=[];for(let N=p.top;N<=p.bottom;N++){const M=f.rowIds[N];if(M===void 0)continue;const _=h.getRow(M)??f.rows[N];for(let F=p.left;F<=p.right;F++){const A=f.columns[F];!A||!qo(f,E,_,N,F)||S.push({id:M,field:A.field,value:su(A)?"":null})}}return h.applyEdits(S,"clear"),!0},[c,a]),x=o.enabled&&!r,y=o.enabled&&!i;s.useEffect(()=>{const p=n.current;if(!p||!x&&!y)return;const f=N=>{const M=l.current.viewportRef.current;if(!M||N.defaultPrevented||l.current.isEditing)return!1;const _=Dn(N.target,M);return _==="grid"||_==="control"};let h=null;const b=()=>{if(!h)return;const{textarea:N,restore:M,timer:_}=h;h=null,window.clearTimeout(_);const F=document.activeElement===N;N.remove(),F&&M&&M.isConnected&&M.focus({preventScroll:!0})},w=()=>{b();const N=document.createElement("textarea");N.setAttribute("aria-hidden","true"),N.tabIndex=-1,N.className="ogx__paste-capture",N.style.cssText="position:fixed;top:0;left:-10000px;width:1px;height:1px;opacity:0;",p.appendChild(N);const M=document.activeElement instanceof HTMLElement?document.activeElement:null;h={textarea:N,restore:M,timer:window.setTimeout(b,250)},N.focus({preventScroll:!0})},C=N=>h!==null&&N.target===h.textarea,E=N=>{if(C(N)){const _=N.clipboardData?N.clipboardData.getData("text/plain"):"";N.preventDefault(),b(),_!==""&&g(_,void 0,!0);return}if(!x||!f(N)||!l.current.navigationColumns.some(_=>_.editable))return;const M=N.clipboardData?N.clipboardData.getData("text/plain"):"";M!==""&&(N.preventDefault(),g(M,void 0,!0))},S=N=>{if((N.ctrlKey||N.metaKey)&&!N.altKey&&!N.shiftKey&&(N.key==="v"||N.key==="V"||N.code==="KeyV")){x&&f(N)&&l.current.navigationColumns.some(M=>M.editable)&&w();return}!y||N.key!=="Delete"&&N.key!=="Backspace"||N.ctrlKey||N.metaKey||N.altKey||N.shiftKey||f(N)&&m()&&N.preventDefault()};return p.addEventListener("paste",E),p.addEventListener("keydown",S),()=>{b(),p.removeEventListener("paste",E),p.removeEventListener("keydown",S)}},[n,x,y,g,m]),s.useLayoutEffect(()=>{t.current.pasteText=(p,f)=>g(p,f,!1)},[t,g])}const du=100;function uu(){const e=s.useRef(null),t=s.useCallback((o,r)=>{const i=e.current;i&&i(o,r)},[]),n=s.useCallback(o=>{e.current=o},[]);return s.useMemo(()=>({emit:t,setListener:n}),[t,n])}const al=()=>({updated:[],failed:[],skipped:[]});function fu(e){if(e.altKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t),o=t==="z"||!n&&e.code==="KeyZ",r=t==="y"||!n&&e.code==="KeyY";return o?e.shiftKey?"redo":"undo":r&&e.ctrlKey&&!e.shiftKey?"redo":null}function gu(e){const{apiRef:t,enabled:n,channel:o,containerRef:r}=e,i=s.useRef(e);s.useLayoutEffect(()=>{i.current=e});const l=s.useRef([]),a=s.useRef([]),c=s.useRef({canUndo:!1,canRedo:!1,size:0}),u=s.useRef(Promise.resolve()),g=s.useCallback(()=>{const b={canUndo:l.current.length>0,canRedo:a.current.length>0,size:l.current.length},w=c.current;w.canUndo===b.canUndo&&w.canRedo===b.canRedo&&w.size===b.size||(c.current=b,i.current.onHistoryChange?.(b))},[]),m=s.useCallback(b=>{if(!i.current.enabled||b.length===0)return;const w=l.current;w.push(b);const C=Math.max(1,i.current.limit);w.length>C&&w.splice(0,w.length-C),a.current=[],g()},[g]);s.useLayoutEffect(()=>(o.setListener(n?m:null),()=>o.setListener(null)),[o,n,m]);const x=s.useCallback(()=>{l.current=[],a.current=[],g()},[g]);s.useEffect(()=>{n||x()},[n,x]);const y=s.useCallback(b=>{const w=i.current,C=jo(w.allRenderableRows,w.getRowId,w.navigationColumns),E=lu(C,b);if(!E)return;const{anchor:S,head:N}=ll(C,E);w.selection.enabled?w.selection.setModel([{anchor:S,head:N}],"keyboard"):w.setFocusedCell({id:S.id,field:S.field,rowIndex:E.top});const M=w.viewportRef.current;M&&(In(M,E.top-w.pinnedTopRowCount,w.layout.cumulativeHeights,w.layout.pinnedBottomHeight,w.rowHeight),mo(M,w.layout.unpinnedColsWithWidth.findIndex(_=>_.field===S.field),w.layout))},[]),p=s.useCallback(b=>{const w=async()=>{if(!i.current.enabled)return al();const E=b==="undo"?l:a,S=b==="undo"?a:l,N=E.current.pop();if(!N)return al();g();const M=N.map(A=>b==="undo"?{id:A.id,field:A.field,value:A.before,expect:{value:A.after}}:{id:A.id,field:A.field,value:A.after,expect:{value:A.before}}),_=await i.current.batchEdit.applyEdits(M,b);_.committed.length>0&&S.current.push(b==="undo"?_.committed.map(A=>({id:A.id,field:A.field,before:A.after,after:A.before})):_.committed);const F=new Set(_.result.failed.map(A=>A.id));if(F.size>0){const A=N.filter(L=>F.has(L.id));A.length>0&&E.current.push(A)}return g(),_.committed.length>0&&y(_.committed),_.result},C=u.current.then(w,w);return u.current=C,C},[g,y]),f=s.useCallback(()=>p("undo"),[p]),h=s.useCallback(()=>p("redo"),[p]);s.useEffect(()=>{const b=r.current;if(!b||!n)return;const w=C=>{if(C.defaultPrevented)return;const E=fu(C);if(!E)return;const S=i.current.viewportRef.current;if(!S||i.current.isEditing)return;const N=Dn(C.target,S);N!=="grid"&&N!=="control"||(C.preventDefault(),E==="undo"?f():h())};return b.addEventListener("keydown",w),()=>b.removeEventListener("keydown",w)},[r,n,f,h]),s.useLayoutEffect(()=>{const b=t.current;b.undo=f,b.redo=h,b.canUndo=()=>i.current.enabled&&l.current.length>0,b.canRedo=()=>i.current.enabled&&a.current.length>0,b.clearHistory=x},[t,f,h,x])}function pu(e){const t=String(e);if(t.includes("e")||t.includes("E"))return null;const n=t.indexOf(".");return n===-1?0:t.length-n-1}function Xo(e,t){return t===null?e:Number(e.toFixed(Math.min(t,20)))}function hu(e,t){let n=0;for(const l of e){const a=pu(l);n=a===null||n===null?null:Math.max(n,a)}const o=Xo(e[1]-e[0],n);for(let l=2;l<e.length;l++)if(Xo(e[l]-e[l-1],n)!==o)return null;const r=e[e.length-1],i=[];for(let l=1;l<=t;l++)i.push(Xo(r+o*l,n));return i}const mu=864e5,cl=e=>((e.getHours()*60+e.getMinutes())*60+e.getSeconds())*1e3+e.getMilliseconds(),wu=e=>Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/mu),bu=e=>e.getFullYear()*12+e.getMonth(),xu=(e,t)=>new Date(e,t+1,0).getDate();function Yo(e){const t=e[1]-e[0];for(let n=2;n<e.length;n++)if(e[n]-e[n-1]!==t)return null;return t}function yu(e,t){const n=e[e.length-1],o=e.every(l=>cl(l)===cl(n));if(o&&e.every(l=>l.getDate()===n.getDate())){const l=Yo(e.map(bu));if(l!==null&&l!==0){const a=[];for(let c=1;c<=t;c++){const u=n.getMonth()+l*c,g=n.getFullYear()+Math.floor(u/12),m=(u%12+12)%12,x=new Date(n.getTime());x.setFullYear(g,m,Math.min(n.getDate(),xu(g,m))),a.push(x)}return a}}if(o){const l=Yo(e.map(wu));if(l===null)return null;const a=[];for(let c=1;c<=t;c++){const u=new Date(n.getTime());u.setDate(n.getDate()+l*c),a.push(u)}return a}const r=Yo(e.map(l=>l.getTime()));if(r===null)return null;const i=[];for(let l=1;l<=t;l++)i.push(new Date(n.getTime()+r*l));return i}const Cu=e=>typeof e=="number"&&Number.isFinite(e),vu=e=>e instanceof Date&&!Number.isNaN(e.getTime());function Su(e,t){return e.length<2?null:e.every(Cu)?hu(e,t):e.every(vu)?yu(e,t):null}const _u=e=>e instanceof Date?new Date(e.getTime()):e;function ku(e,t,n){if(e.length===0||t<=0)return[];const o=n?Su(e,t):null;if(o)return o;const r=[];for(let i=0;i<t;i++)r.push(_u(e[i%e.length]));return r}function Eu(e,t,n,o){const r=t.row>e.bottom||t.row<e.top,i=t.col>e.right||t.col<e.left;return!r&&!i?null:r&&(!i||Math.abs(o)>=Math.abs(n))?t.row>e.bottom?{rect:{...e,bottom:t.row},direction:"down"}:{rect:{...e,top:t.row},direction:"up"}:t.col>e.right?{rect:{...e,right:t.col},direction:"right"}:{rect:{...e,left:t.col},direction:"left"}}function Mu(e,t,n){const o=(c,u)=>{const g=[];if(c<=u)for(let m=c;m<=u;m++)g.push(m);else for(let m=c;m>=u;m--)g.push(m);return g},i=n==="down"||n==="up"?o(e.left,e.right):o(e.top,e.bottom);let l,a;switch(n){case"down":l=o(e.top,e.bottom),a=t.bottom>e.bottom?o(e.bottom+1,t.bottom):[];break;case"up":l=o(e.bottom,e.top),a=t.top<e.top?o(e.top-1,t.top):[];break;case"right":l=o(e.left,e.right),a=t.right>e.right?o(e.right+1,t.right):[];break;default:l=o(e.right,e.left),a=t.left<e.left?o(e.left-1,t.left):[]}return i.map(c=>({line:c,source:l,targets:a}))}function Nu(e,t,n){const o=n.row===e.top||n.row===e.bottom,r=n.col===e.left||n.col===e.right;let i=n.row,l=n.col;return(!o||!r)&&(t==="down"||t==="up"?(i=t==="down"?e.top:e.bottom,l=n.col===e.right?e.right:e.left):(l=t==="right"?e.left:e.right,i=n.row===e.bottom?e.bottom:e.top)),{anchor:{row:i,col:l},head:{row:i===e.top?e.bottom:e.top,col:l===e.left?e.right:e.left}}}function Iu(e,t,n,o){const r=t(e.bottom),i=n[e.right];if(r===void 0||i===void 0)return null;const l=o?.(r,i);if(!l||l.rowId===r&&l.field===i)return{row:e.bottom,field:i};for(let a=e.bottom;a>=Math.max(0,e.bottom-Lu);a--)if(t(a)===l.rowId)return{row:a,field:l.field};return null}const Lu=1e3,Au="ogx__cell-fill-handle";function Pu(e){if(e.altKey||e.shiftKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t);return t==="d"||!n&&e.code==="KeyD"?"down":t==="r"||!n&&e.code==="KeyR"?"right":null}function Tu(e){const{containerRef:t,viewportRef:n,selection:o,disableFillHandle:r,isEditing:i,allRenderableRows:l,getRowId:a,navigationColumns:c,columnIndexMap:u,getSpanOrigin:g}=e,m=s.useRef(e);s.useLayoutEffect(()=>{m.current=e});const x=o.enabled&&!r,y=s.useMemo(()=>c.some(_=>_.editable),[c]),p=o.resolved,f=s.useMemo(()=>{if(!x||!y||!p)return null;const _=c.filter(k=>Ke(k.field)).map(k=>k.field),A=Iu(p,k=>{const I=l[k];return I===void 0?void 0:a(I)},_,g);if(!A)return null;const L=u.get(A.field);return L===void 0?null:{row:A.row,col:L}},[x,y,p,l,a,c,u,g]),h=s.useRef(!0);s.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]);const b=s.useCallback(()=>{const _=m.current;return jo(_.allRenderableRows,_.getRowId,_.navigationColumns)},[]),w=s.useCallback((_,F,A,L,k)=>{const I=Nu(F,A,L),P=v=>({id:_.rowIds[v.row],field:_.columns[v.col].field});m.current.selection.setModel([{anchor:P(I.anchor),head:P(I.head)}],k)},[]),C=s.useCallback(async(_,F,A,L,k,I,P)=>{const{batchEdit:v,isCellEditable:B,rowMetaMap:W,getSpanOrigin:J}=m.current,G={isCellEditable:B,rowMetaMap:W,getSpanOrigin:J},z=L==="down"||L==="up",H=ae=>{const R=_.rowIds[ae];return R===void 0?void 0:v.getRow(R)??_.rows[ae]},re=[],ee=[];for(const ae of Mu(F,A,L)){if(ae.targets.length===0)continue;const R=te=>z?{r:te,c:ae.line}:{r:ae.line,c:te},ue=[];for(const te of ae.source){const{r:V,c:U}=R(te),ce=H(V),ge=_.columns[U];!ce||!ge||Re(_.rowIds[V],W)||ue.push(Me(ce,ge.field,ge))}if(ue.length===0)continue;const q=ku(ue,ae.targets.length,!k);ae.targets.forEach((te,V)=>{const{r:U,c:ce}=R(te),ge=H(U),Q=_.columns[ce],D=_.rowIds[U];if(!ge||!Q||D===void 0)return;if(!qo(_,G,ge,U,ce)){ee.push({id:D,field:Q.field,reason:"notEditable"});return}let T=q[V];const $=Q.fillValue;if($){const O=We(()=>$.call(Q,{row:ge,id:D,field:Q.field,colDef:Q,direction:L,sourceValues:ue.slice(),index:V,value:T,copy:k}));if(!O.ok){Ct(`fillValue:${Q.field}`,`fillValue of column "${Q.field}" threw; the cell was skipped`,O.error),ee.push({id:D,field:Q.field,reason:"invalidValue"});return}T=O.value}re.push({id:D,field:Q.field,value:T})})}w(_,A,L,I,P);const de=await v.applyEdits(re,"fill"),ie={updated:de.result.updated,failed:de.result.failed,skipped:[...ee,...de.result.skipped],direction:L};return m.current.onFill?.(ie),ie},[w]),E=s.useRef(null),S=s.useCallback((_,F,A)=>{const L=E.current,k=m.current.viewportRef.current;if(!L||!k)return;const I=L.ctx,P=I.rowIndexById.get(_.id),v=I.colIndexByField.get(_.field);if(P===void 0||v===void 0)return;const B=F-L.x+k.scrollLeft-L.scrollLeft,W=A-L.y+k.scrollTop-L.scrollTop,J=Eu(L.source,{row:P,col:v},B,W);L.target=J,J?w(I,J.rect,J.direction,L.anchor,"pointer"):m.current.selection.setModel(L.sourceModel,"pointer")},[w]),N=s.useCallback(({cancelled:_,altKey:F})=>{const A=E.current;if(E.current=null,!A||!h.current)return;const L=A.ctx;if(_||!A.target){m.current.selection.setModel(A.sourceModel,"pointer");return}C(L,A.source,A.target.rect,A.target.direction,F,A.anchor,"pointer")},[C]),M=x&&y;return s.useEffect(()=>{const _=n.current;if(!_||!M)return;const F=A=>{if(A.button!==0||!(A.target instanceof Element))return;const L=A.target.closest(`.${Au}`);if(!L||L.closest(".ogx__viewport")!==_||m.current.isEditing)return;const{selection:k}=m.current,{range:I,resolved:P}=k.getCurrentRange();if(!I||!P)return;const v=b(),B=v.rowIds[P.bottom],W=v.columns[P.right];if(B===void 0||!W)return;A.preventDefault();const J=_.ownerDocument;_.contains(J.activeElement)||_.focus({preventScroll:!0}),We(()=>_.setPointerCapture(A.pointerId)),E.current={source:{top:P.top,bottom:P.bottom,left:P.left,right:P.right},sourceModel:[I],anchor:{row:P.anchorRow,col:P.anchorCol},ctx:v,x:A.clientX,y:A.clientY,scrollLeft:_.scrollLeft,scrollTop:_.scrollTop,target:null},k.startTrackedDrag({start:{id:B,field:W.field},x:A.clientX,y:A.clientY,pointerId:A.pointerId,onTrack:S,onEnd:N})};return _.addEventListener("pointerdown",F),()=>_.removeEventListener("pointerdown",F)},[n,M,b,S,N]),s.useEffect(()=>{const _=t.current;if(!_||!x)return;const F=A=>{if(A.defaultPrevented)return;const L=Pu(A);if(!L)return;const k=m.current.viewportRef.current;if(!k||m.current.isEditing)return;const I=Dn(A.target,k);if(I!=="grid"&&I!=="control")return;const{range:P,resolved:v}=m.current.selection.getCurrentRange();if(!P||!v)return;A.preventDefault();const B={top:v.top,bottom:v.bottom,left:v.left,right:v.right},W=L==="down"?{...B,bottom:B.top}:{...B,right:B.left};(L==="down"?B.bottom===B.top:B.right===B.left)||C(b(),W,B,L,!0,{row:v.anchorRow,col:v.anchorCol},"keyboard")};return _.addEventListener("keydown",F),()=>_.removeEventListener("keydown",F)},[t,x,C,b]),{handle:i?null:f}}function Fu(e){const{props:t,apiRef:n,containerRef:o,viewportRef:r,selection:i,model:l,getPendingModel:a,focusedCell:c,setFocusedCell:u,allRenderableRows:g,getRowId:m,navigationColumns:x,columnIndexMap:y,isCellEditable:p,rowMetaMap:f,getSpanOrigin:h,isEditing:b,batchEdit:w,channel:C,layout:E,rowHeight:S,pinnedTopRowCount:N}=e,{disableClipboardPaste:M=!1,disableRangeClear:_=!1,onClipboardPaste:F,onBeforeClipboardPaste:A,undoRedo:L=!1,disableFillHandle:k=!1,onFill:I,onHistoryChange:P}=t;return zd({apiRef:n,selection:i,model:l,getPendingModel:a,focusedCell:c,setFocusedCell:u,containerRef:o}),cu({apiRef:n,containerRef:o,viewportRef:r,selection:i,disableClipboardPaste:M,disableRangeClear:_,focusedCell:c,allRenderableRows:g,getRowId:m,navigationColumns:x,isCellEditable:p,rowMetaMap:f,getSpanOrigin:h,isEditing:b,batchEdit:w,onClipboardPaste:F,onBeforeClipboardPaste:A}),gu({apiRef:n,enabled:!!L,limit:typeof L=="object"&&L.limit||du,onHistoryChange:P,channel:C,batchEdit:w,isEditing:b,containerRef:o,viewportRef:r,selection:i,setFocusedCell:u,allRenderableRows:g,getRowId:m,navigationColumns:x,layout:E,rowHeight:S,pinnedTopRowCount:N}),Tu({containerRef:o,viewportRef:r,selection:i,disableFillHandle:k,isEditing:b,allRenderableRows:g,getRowId:m,navigationColumns:x,columnIndexMap:y,isCellEditable:p,rowMetaMap:f,getSpanOrigin:h,batchEdit:w,onFill:I})}const Ou=100;function dl(e){const{scrollTop:t,scrollHeight:n,clientHeight:o}=e;return n-t-o>=Ou?null:{visibleTop:t,visibleBottom:t+o,viewportHeight:o}}function Du(e){return e<.5?3:e<3?5:e<15?12:e<40?20:30}function $u(e){const{onRowsScrollEnd:t,overscanRowCount:n=3,rowCount:o=0,autoHeight:r=!1}=e,i=s.useRef({scrollTop:0,scrollLeft:0,velocity:0}),l=s.useRef({scrollTop:0,scrollLeft:0,time:0}),a=s.useRef(null),c=s.useRef(null),u=s.useRef(null),g=s.useRef(!0),m=s.useRef(t),[x,y]=s.useState({scrollTop:0,scrollLeft:0,velocityOverscan:0});s.useEffect(()=>{m.current=t},[t]),s.useEffect(()=>()=>{a.current!==null&&cancelAnimationFrame(a.current),c.current!==null&&clearTimeout(c.current)},[]);const p=s.useCallback(b=>{const w=dl(b);if(!w){g.current=!0;return}if(!g.current)return;const C=m.current;C&&(g.current=!1,C(w))},[]),f=s.useCallback(b=>{const w=b.currentTarget,C=performance.now(),E=Ot(w),S=Math.abs(w.scrollTop-l.current.scrollTop)+Math.abs(E-l.current.scrollLeft),N=C-l.current.time,M=N>0?S/N:0,_=w.scrollTop!==l.current.scrollTop;l.current={scrollTop:w.scrollTop,scrollLeft:E,time:C},i.current={scrollTop:w.scrollTop,scrollLeft:E,velocity:M},a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{a.current=null;const{scrollTop:F,scrollLeft:A,velocity:L}=i.current;y({scrollTop:F,scrollLeft:A,velocityOverscan:Du(L)})}),c.current!==null&&clearTimeout(c.current),c.current=setTimeout(()=>{c.current=null,y(F=>F.velocityOverscan===0?F:{...F,velocityOverscan:0})},200),_&&p(w)},[p]);s.useEffect(()=>{g.current=!0;const b=u.current;!b||r||o<=0||b.clientHeight===0||p(b)},[o,r,p]),s.useEffect(()=>{const b=u.current?.ownerDocument??(typeof document>"u"?null:document);if(!b||typeof MutationObserver>"u")return;const w=new MutationObserver(()=>{const C=u.current;if(!C)return;const E={scrollTop:C.scrollTop,scrollLeft:Ot(C)},S=i.current;E.scrollTop===S.scrollTop&&E.scrollLeft===S.scrollLeft||(i.current={...S,...E},l.current={...l.current,...E},y(N=>({...N,...E})))});return w.observe(b.documentElement,{attributes:!0,attributeFilter:["dir"],subtree:!0}),()=>w.disconnect()},[]);const h=s.useCallback(b=>{if(u.current=b,!b)return;const{scrollTop:w,scrollLeft:C}=i.current;if(w===0&&C===0)return;b.scrollTop=w,en(b,C);const E={scrollTop:b.scrollTop,scrollLeft:Ot(b)};(E.scrollTop!==w||E.scrollLeft!==C)&&(i.current={...i.current,...E},l.current={...l.current,...E},y(S=>({...S,...E})))},[]);return{scrollTop:x.scrollTop,scrollLeft:x.scrollLeft,overscanRows:Math.max(x.velocityOverscan,n),handleScroll:f,attachViewport:h}}function Gu(e){const t=s.useRef(null);return s.useCallback(n=>{if(t.current?.disconnect(),t.current=null,!n||typeof ResizeObserver>"u")return;const o=new ResizeObserver(r=>{for(const i of r){const{width:l,height:a}=i.contentRect;e(l,a)}});o.observe(n),t.current=o},[e])}function Hu(e){const{setDimensions:t,viewportRef:n,...o}=e,{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:a,attachViewport:c}=$u(o),u=Gu(t),g=s.useCallback(m=>{n.current=m,u(m),c(m)},[n,u,c]);return{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:a,setViewportElement:g}}function Bu(e){const[t,n]=s.useState(void 0);return s.useLayoutEffect(()=>{const o=Sc(e.current?.ownerDocument);n(r=>r===o?r:o)},[e]),t}function Wu(e){const{layout:t,scrollTop:n,scrollLeft:o,viewportWidth:r,viewportHeight:i,autoHeight:l,rowReordering:a,hasDetailPanel:c,checkboxSelection:u,pinCheckboxColumn:g,pinExpandColumn:m,overscanRows:x=5,maxContentHeight:y=1/0}=e;return s.useMemo(()=>{const{unpinnedAccWidths:p,unpinnedColsWithWidth:f,leftPinnedCols:h,rightPinnedCols:b,totalWidth:w,leftWidth:C,rightWidth:E,unpinnedTotalWidth:S,systemColumnsWidth:N,cumulativeHeights:M,pinnedTopHeight:_,pinnedBottomHeight:F,unpinnedRowsHeight:A,rowHeights:L,unpinnedRowsLength:k}=t,I=r||1e3,P=l?_+A+F+50:i||600,v=6,B=Math.max(0,o-C),W=o+I-C;let J=0,G=f.length-1,z=0,H=p.length-1;for(;z<=H;){const D=z+H>>>1;p[D]<B?z=D+1:H=D-1}J=Math.max(0,z-v);for(let D=J;D<p.length;D++){if((D===0?0:p[D-1])>W){G=Math.min(f.length-1,D+v);break}G=Math.min(f.length-1,D+v)}const re=J>0?p[J-1]:0,ee=S-p[G],de=[...h,...re>0?[{field:"__spacer_left__",width:re,isSpacer:!0}]:[],...f.slice(J,G+1),...ee>0?[{field:"__spacer_right__",width:ee,isSpacer:!0}]:[],...b],ae=I>0&&w>I?16:0,R=_+A+F+ae+2,ue=R-_-F,q=Number.isFinite(y)?Math.max(0,Math.min(ue,y-_-F)):ue;let te=0,V=k-1,U=0,ce=0,ge=M.length-1;for(;ce<=ge;){const D=ce+ge>>>1;M[D]<n?ce=D+1:ge=D-1}te=Math.max(0,ce-x),U=te>0?M[te-1]:0;for(let D=te;D<M.length;D++)if(M[D]>=n+P){V=Math.min(k-1,D+x);break}const Q=(a?48:0)+(c&&m?48:0)+(u&&g?48:0);return{renderContext:{firstRowIndex:te,lastRowIndex:V,firstColumnIndex:J,lastColumnIndex:G},offsetTop:U,offsetLeft:0,totalHeight:R,virtualContainerHeight:q,pinnedTopHeight:_,pinnedBottomHeight:F,totalWidth:w,rowHeights:L,cumulativeHeights:M,virtualColumns:de,columnMetrics:{leftPinnedWidth:C,rightPinnedWidth:E,unpinnedAccWidths:p,unpinnedCols:f,totalSpecialsWidth:N,pinnedSpecialsWidth:Q}}},[t,n,o,r,i,l,a,c,u,g,m,x,y])}function Vu(e){const{viewport:t,viewportRef:n,containerRef:o,layout:r,viewportWidth:i,viewportHeight:l,virtualization:a}=e,{scrollTop:c,scrollLeft:u,overscanRows:g,handleScroll:m,setViewportElement:x}=Hu({...t,rowCount:r.unpinnedRowsLength,viewportRef:n}),y=Bu(o),p=Wu({layout:r,scrollTop:c,scrollLeft:u,viewportWidth:i,viewportHeight:l,...a,overscanRows:g,maxContentHeight:y??1/0});return{handleScroll:m,setViewportElement:x,maxContentHeight:y,virtualization:p}}function zu(e){const{apiRef:t,columns:n,getRowId:o,containerRef:r,disableKeyboardShortcut:i,getCellRangeCopyText:l}=e,a=s.useCallback(()=>r.current,[r]),{copySelectedRows:c}=Vd({getSelectedRowIds:()=>t.current.getSelectedRows(),getColumns:()=>n,getRows:()=>t.current.getAllFilteredRows(),getRowId:o,getRootElement:a,disableKeyboardShortcut:i,getShortcutText:l});s.useLayoutEffect(()=>{t.current.copySelectedRows=c},[c,t])}function Ru(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{t.current.scrollToIndexes=({rowIndex:o,colIndex:r})=>{const{viewportRef:i,layout:l,rowHeight:a}=n.current,c=i.current;if(c&&(o!==void 0&&o>=0&&In(c,o,l.cumulativeHeights,l.pinnedBottomHeight,a),r!==void 0&&r>=0)){const g=[...l.leftPinnedCols,...l.unpinnedColsWithWidth,...l.rightPinnedCols][r];if(!g)return;mo(c,l.unpinnedColsWithWidth.findIndex(m=>m.field===g.field),l)}}},[t])}const ul=50;function Jo(e,t,n,o){const r=Math.min(n??ul,t),i=Math.max(o??1/0,t);return Math.max(r,Math.min(i,e))}const Ku=".ogx";function fl(e,t){const n=t.style.cssText;t.style.width="max-content",t.style.minWidth="0",t.style.maxWidth="none",t.style.flex="none";const o=t.getBoundingClientRect().width;t.style.cssText=n;const r=getComputedStyle(e),i=[r.paddingLeft,r.paddingRight,r.borderLeftWidth,r.borderRightWidth].reduce((l,a)=>l+(parseFloat(a)||0),0);return o+i}function Uu(e,t){const n=typeof CSS<"u"&&CSS.escape?CSS.escape(t):t.replace(/["\\]/g,"\\$&"),o=l=>l.closest(Ku)===e;let r=null;const i=l=>{r=r===null?l:Math.max(r,l)};return e.querySelectorAll(`[role="columnheader"][data-field="${n}"]`).forEach(l=>{if(!o(l))return;const a=l.querySelector(".ogx__header-cell-content");a&&i(fl(l,a))}),e.querySelectorAll(`[role="gridcell"][data-field="${n}"]`).forEach(l=>{if(!o(l)||l.hasAttribute("aria-colspan"))return;const a=l.querySelector(":scope > .ogx__cell-content");a&&i(fl(l,a))}),r===null?null:Math.ceil(r)}function ju(e,t,n){return Math.max(t??ul,Math.min(n??1/0,e))}function qu(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useCallback(i=>{const{containerRef:l,columns:a,onColumnResize:c}=n.current,u=l.current;if(!u)return;const g=[];for(const m of i??a.map(x=>x.field)){const x=a.find(p=>p.field===m);if(!x||x.resizable===!1)continue;const y=Uu(u,m);y!==null&&g.push([m,ju(y,x.minWidth,x.maxWidth)])}for(const[m,x]of g)c(m,x)},[]),r=s.useCallback(i=>o([i]),[o]);return s.useLayoutEffect(()=>{t.current.autosizeColumn=r,t.current.autosizeColumns=o},[t,r,o]),r}function Xu(e){const{apiRef:t,containerRef:n,viewportRef:o,copyColumns:r,getRowId:i,disableClipboardCopy:l,getCellRangeCopyText:a,layout:c,rowHeight:u,orderedColumns:g,onColumnResize:m}=e;return zu({apiRef:t,columns:r,getRowId:i,containerRef:n,disableKeyboardShortcut:l,getCellRangeCopyText:a}),Ru({apiRef:t,viewportRef:o,layout:c,rowHeight:u}),qu({apiRef:t,containerRef:n,columns:g,onColumnResize:m})}class gl extends Error{}function ut(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function pl(e){return typeof e=="object"&&e!==null&&typeof e.then=="function"}function hl(e,t){t?t(e):process.env.NODE_ENV!=="production"&&e instanceof gl&&console.error(e.message)}function ml(e,t){return new gl(`[OpenGridX] processRowUpdate must return the updated row object (or a Promise of it); it returned ${e===null?"null":typeof e}. ${t}`)}function wl(e,t,n,o){return n?.valueSetter?n.valueSetter({value:t.value,row:e,field:t.field}):(n?.valueGetter&&process.env.NODE_ENV!=="production"&&!o.has(t.field)&&(o.add(t.field),console.warn(`[OpenGridX] Column "${t.field}" is editable and has a valueGetter but no valueSetter. The edited value was written to row["${t.field}"], which the valueGetter may ignore, so the cell can keep showing the old value. Add a valueSetter that maps the value back onto the row.`)),{...e,[t.field]:t.value})}function Yu(e){const t=s.useRef(e),n=s.useRef(new Map),o=s.useRef(new Set);s.useLayoutEffect(()=>{t.current=e,n.current.clear()});const r=s.useCallback(c=>{const u=n.current.get(c);return u===void 0?t.current.rowsLookup.get(c):u},[]),i=s.useCallback(c=>{c.size!==0&&(c.forEach((u,g)=>{n.current.set(g,u)}),t.current.replaceRows(c))},[]),l=s.useCallback((c,u)=>{i(new Map([[c,u]]))},[i]),a=s.useCallback((c,u)=>{const{columns:g,processRowUpdate:m}=t.current,x=S=>hl(S,t.current.onProcessRowUpdateError),y=new Map,p=new Map;g.forEach((S,N)=>{y.set(S.field,N),p.set(S.field,S)});const f=[],h=new Map;for(const S of c){const N=r(S.id);if(N===void 0){f.push({id:S.id,field:S.field,reason:"missing"});continue}const M=p.get(S.field);if(S.expect&&!ut(Me(N,S.field,M),S.expect.value)){f.push({id:S.id,field:S.field,reason:"changed"});continue}let _=h.get(S.id);_||(_={id:S.id,row:N,cells:[]},h.set(S.id,_));const F=y.get(S.field)??Number.MAX_SAFE_INTEGER,A=_.cells.findIndex(k=>k.field===S.field),L={field:S.field,value:S.value,colDef:M,order:F};A===-1?_.cells.push(L):_.cells[A]=L}const b=[],w=[],C=o.current;h.forEach(S=>{const{id:N,row:M}=S,_=S.cells.filter(L=>!ut(Me(M,L.field,L.colDef),L.value)).sort((L,k)=>L.order-k.order);if(S.cells=_,_.length===0)return;const F=We(()=>{let L=M;for(const k of _)L=wl(L,k,k.colDef,C);return m?m(L,M):L});if(!F.ok){b.push({id:N,ok:!1,error:F.error});return}const A=F.value;pl(A)?w.push(Promise.resolve(A).then(L=>({id:N,ok:!0,processed:L}),L=>({id:N,ok:!1,error:L}))):b.push({id:N,ok:!0,processed:A})});const E=S=>{const N=new Map;S.forEach(L=>{N.set(L.id,L)});const M=[],_=[],F=[],A=new Map;return h.forEach(L=>{const k=N.get(L.id);if(!k)return;if(!k.ok){_.push({id:L.id,error:k.error}),x(k.error);return}const I=k.processed;if(typeof I!="object"||I===null){const v=ml(I,"The row was not saved.");_.push({id:L.id,error:v}),x(v);return}const P=I;A.set(L.id,P),M.push(L.id);for(const v of L.cells){const B=Me(L.row,v.field,v.colDef),W=Me(P,v.field,v.colDef);ut(B,W)||F.push({id:L.id,field:v.field,before:B,after:W})}}),i(A),F.length>0&&u!=="undo"&&u!=="redo"&&t.current.onCommitted?.(F,u),{result:{updated:M,failed:_,skipped:f},committed:F}};return w.length===0?Promise.resolve(E(b)):Promise.all(w).then(S=>E([...b,...S]))},[r,i]);return s.useMemo(()=>({applyEdits:a,getRow:r,storeRow:l}),[a,r,l])}const zt=Promise.resolve();function Ju(e){const[t,n]=s.useState(null),o=s.useRef(null),r=s.useRef(0),i=s.useRef(new Map),l=s.useRef(new Set),a=s.useRef(!1),c=s.useRef(e);s.useLayoutEffect(()=>{c.current=e}),s.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);const u=s.useCallback(f=>{o.current=f,n(f)},[]),g=s.useRef(null),m=s.useCallback((f,h)=>{const b=i.current.get(f);if(b)return ut(b.value,h.value)?b.promise:b.promise.then(()=>{const G=o.current;if(!(r.current!==f||!G||ut(G.value,b.value)))return g.current?.(f,G)});const w=()=>r.current===f&&o.current!==null;if(ut(h.value,h.originalValue))return w()&&u(null),zt;const{rows:C,getRowId:E,columns:S,processRowUpdate:N}=c.current,M=C.find(G=>E(G)===h.id);if(!M)return w()&&u(null),zt;const _=G=>hl(G,c.current.onProcessRowUpdateError),F=S?.find(G=>G.field===h.field),A=G=>{if(typeof G!="object"||G===null){_(ml(G,"The edit was not saved and the editor stays open."));return}c.current.onRowChange?.(G,h.id);const{onCommitted:z}=c.current;if(z){const re=Me(M,h.field,F),ee=Me(G,h.field,F);ut(re,ee)||z([{id:h.id,field:h.field,before:re,after:ee}])}const H=o.current;r.current!==f||!H||(ut(H.value,h.value)?u(null):u({...H,originalValue:h.value}))};let L,k;const I=new Promise((G,z)=>{L=G,k=z}),P={value:h.value,promise:I};i.current.set(f,P);const v=()=>{i.current.get(f)===P&&i.current.delete(f)},B=We(()=>{const G=wl(M,h,F,l.current);return N?N(G,M):G});if(!B.ok)return v(),_(B.error),L(),I;const W=B.value,J=G=>{v();try{A(G),L()}catch(z){k(z)}};return pl(W)?Promise.resolve(W).then(J,G=>{v(),_(G),L()}):J(W),I},[u]);s.useLayoutEffect(()=>{g.current=m},[m]);const x=s.useCallback(f=>{const h=o.current;if(h){if(h.id===f.id&&h.field===f.field)return;m(r.current,h)}r.current+=1,u({id:f.id,field:f.field,value:f.value,originalValue:f.value})},[m,u]),y=s.useCallback(f=>{const h=o.current;return!h||!a.current||f?.id!==void 0&&f.id!==h.id||f?.field!==void 0&&f.field!==h.field?zt:f?.cancel?(u(null),zt):m(r.current,h)},[m,u]),p=s.useCallback(f=>{const h=o.current;!h||h.id!==f.id||h.field!==f.field||u({...h,value:f.value})},[u]);return s.useMemo(()=>({editingCell:t,startCellEdit:x,stopCellEdit:y,setEditCellValue:p}),[t,x,y,p])}function Zu(e){const{rowsLookup:t,rows:n,getRowId:o,columns:r,processRowUpdate:i,onProcessRowUpdateError:l,replaceRows:a}=e,c=uu(),u=Yu({rowsLookup:t,columns:r,processRowUpdate:i,onProcessRowUpdateError:l,replaceRows:a,onCommitted:c.emit}),g=Ju({rows:n,getRowId:o,columns:r,processRowUpdate:i,onProcessRowUpdateError:l,onRowChange:(m,x)=>{u.storeRow(x,m)},onCommitted:m=>c.emit(m,"edit")});return{editCommitChannel:c,batchEdit:u,editingHandlers:g}}const Qu=e=>e.id,ef={hasColSpan:!1,hasRowSpan:!1,colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},getSpanOrigin:()=>null,getUnpinnedColSpanRanges:()=>{},getCenterRowSpanStart:e=>e},bl="\0",xl="";function yl(e){if(typeof e!="number"||Number.isNaN(e))return 1;if(e===1/0)return Number.MAX_SAFE_INTEGER;if(!Number.isFinite(e))return 1;const t=Math.floor(e);return t<1?1:t}function tf(e){return e.map(t=>t.field).join(bl)}function nf(e){const{pinnedTopRows:t,centerRows:n,pinnedBottomRows:o,columns:r,leftPinnedColumns:i,unpinnedColumns:l,rightPinnedColumns:a,expandedRowIds:c,rowMetaMap:u,getRowId:g=Qu}=e,m=s.useMemo(()=>r.some(b=>b.colSpan!==void 0&&b.colSpan!==null),[r]),x=s.useMemo(()=>r.some(b=>b.rowSpan!==void 0&&b.rowSpan!==null),[r]),y=m||x,p=y?[i,l,a].map(tf).join(xl):"",f=s.useMemo(()=>{if(!p)return{columns:[],leftCount:0,unpinnedCount:0};const b=new Map(r.map(S=>[S.field,S])),w=p.split(xl).map(S=>S?S.split(bl):[]),C=[];let E=0;for(const S of w){E+=S.length;for(const N of S){const M=b.get(N)??{field:N};C.push({colDef:M,field:N,sectionEnd:E,hasColSpan:M.colSpan!==void 0&&M.colSpan!==null,hasRowSpan:M.rowSpan!==void 0&&M.rowSpan!==null})}}return{columns:C,leftCount:w[0].length,unpinnedCount:w[1].length}},[p,r]),h=s.useMemo(()=>{if(!y||f.columns.length===0)return null;const b={colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},hiddenOriginFields:new Map,unpinnedRanges:new Map,centerRowSpanStart:new Map},C={spanColumns:f,expandedRowIds:c,rowMetaMap:u,getRowId:g,warned:new Set,out:b};return Zo(t,0,!1,C),Zo(n,t.length,!0,C),Zo(o,t.length+n.length,!1,C),b},[y,f,t,n,o,c,u,g]);return s.useMemo(()=>{if(!h)return ef;const{colspanMap:b,rowSpanningCaches:w,hiddenOriginFields:C,unpinnedRanges:E,centerRowSpanStart:S}=h,N=f.columns;return{hasColSpan:m,hasRowSpan:x,colspanMap:b,rowSpanningCaches:w,getSpanOrigin:(M,_)=>{const F=b.get(M)?.[_];if(F?.spannedByColSpan)return{rowId:M,field:N[F.leftVisibleCellIndex].field};const A=w.hiddenCellOriginMap[M]?.[_];return A===void 0?null:{rowId:A,field:C.get(M)?.[_]??_}},getUnpinnedColSpanRanges:M=>E.get(M),getCenterRowSpanStart:M=>S.get(M)??M}},[h,m,x,f])}function Zo(e,t,n,o){const{spanColumns:r,expandedRowIds:i,rowMetaMap:l,getRowId:a,warned:c,out:u}=o,{columns:g,leftCount:m,unpinnedCount:x}=r,y=g.length,{colspanMap:p,rowSpanningCaches:f,hiddenOriginFields:h,unpinnedRanges:b,centerRowSpanStart:w}=u,C=new Int32Array(y),E=new Array(y),S=new Array(y),N=new Int32Array(y);let M=0;const _=[];g.forEach((L,k)=>{(L.hasColSpan||L.hasRowSpan)&&_.push(k)});const F=(L,k,I)=>{const P=g[I].field;if(Rt(f.hiddenCells,L,P,!0),Rt(f.hiddenCellOriginMap,L,P,E[I]),S[I]!==P&&Rt(h,L,P,S[I]),n){const v=w.get(k);(v===void 0||N[I]<v)&&w.set(k,N[I])}},A=(L,k,I)=>{const P=g[I],v=a(L),B=of(L,v,P.colDef,t+k,I,l,c);let W=1;if(P.hasColSpan){const G=Math.min(Cl(P.colDef.colSpan,B,"colSpan",P.field,c),P.sectionEnd-I);for(;W<G&&C[I+W]<=k;)W++}let J=1;if(P.hasRowSpan){J=Math.min(Cl(P.colDef.rowSpan,B,"rowSpan",P.field,c),e.length-k);for(let G=1;G<J;G++)if(Re(a(e[k+G]),l)){J=G;break}if(J>1&&i&&i.size>0){for(let G=0;G<J-1;G++)if(i.has(a(e[k+G]))){J=G+1;break}}}if(W>1){Rt(p,v,P.field,{spannedByColSpan:!1,cellProps:{colSpan:W}});for(let G=1;G<W;G++){const z=g[I+G];Rt(p,v,z.field,{spannedByColSpan:!0,leftVisibleCellIndex:I,rightVisibleCellIndex:I+W-1})}if(I>=m&&I<m+x){let G=b.get(v);G||(G=[],b.set(v,G)),G.push(I-m,I+W-1-m)}}if(J>1){Rt(f.spannedCells,v,P.field,J);for(let G=I;G<I+W;G++)C[G]=k+J,E[G]=v,S[G]=P.field,N[G]=k;k+J>M&&(M=k+J)}return W};for(let L=0;L<e.length;L++){const k=e[L];if(!k||k._isSkeleton||Re(a(k),l))continue;if(M<=L){let P=0;for(const v of _)v>=P&&(P=v+A(k,L,v));continue}let I=0;for(;I<y;)C[I]>L?(F(a(k),L,I),I++):g[I].hasColSpan||g[I].hasRowSpan?I+=A(k,L,I):I++}}function of(e,t,n,o,r,i,l){const a=e[n.field];let c=a;if(n.valueGetter)try{c=n.valueGetter({row:e,field:n.field,value:a})}catch(u){vl(l,`valueGetter:${n.field}`,`valueGetter for column "${n.field}" threw while computing its span`,u),c=void 0}return{row:e,value:c,field:n.field,colDef:n,rowIndex:o,colIndex:r,rowMeta:i?.get(t)}}function Cl(e,t,n,o,r){if(typeof e=="number")return yl(e);if(typeof e!="function")return 1;try{return yl(e(t))}catch(i){return vl(r,`${n}:${o}`,`${n} for column "${o}" threw; the cell is rendered without a span`,i),1}}function vl(e,t,n,o){process.env.NODE_ENV==="production"||e.has(t)||(e.add(t),console.warn(`[OpenGridX] ${n}.`,o))}function Rt(e,t,n,o){if(e instanceof Map){let i=e.get(t);i||(i={},e.set(t,i)),i[n]=o;return}let r=e[t];r||(r={},e[t]=r),r[n]=o}function rf(e,t){const{draggedColumn:n,onDragOver:o,onDrop:r,onDragEnd:i}=t,l=s.useMemo(()=>{if(!e||e.length===0)return null;const a=c=>n===null||Vo(e,n,c);return{onDragOver:o&&(c=>a(c)?o(c):()=>{}),onDrop:r&&(c=>a(c)?r(c):u=>{u.preventDefault(),i?.()})}},[e,n,o,r,i]);return l?{...t,...l}:t}function Sl({dataSource:e,paginationMode:t,sortingMode:n,filterMode:o}){return!!e&&(t==="server"||t==="infinite"||n==="server"||o==="server")}const _l=Number.MAX_SAFE_INTEGER,lf="An unexpected error occurred while loading the data.";function kl(e){return typeof e=="string"&&e?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"&&e.message?e.message:lf}const sf=300,El=e=>e.id;function af(e,t){return e==="infinite"?"infinite":e==="server"?t?"all":"page":"all"}function Ml(e,t){const n=new Set,o=[];return e.forEach(r=>{const i=t(r);n.has(i)||(n.add(i),o.push({id:i,row:r}))}),o}function Nl(e,t,n){const o=new Set(e.map(n)),r=t.filter(i=>!o.has(i.id)).map(i=>i.row);return r.length===0?e:[...e,...r]}function cf(e){const{dataSource:t,sortModel:n,filterModel:o,paginationModel:r,paginationMode:i,sortingMode:l,filterMode:a,aggregationModel:c,rowGroupingActive:u=!1}=e,g=af(i,u),m=!!t&&i==="server"&&u,x=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||x.current||!m||(x.current=!0,console.warn("[OpenGridX] `rowGroupingModel` turns pagination off, so the dataSource with `paginationMode: 'server'` is asked for every row (startRow 0, endRow Number.MAX_SAFE_INTEGER) instead of one page. See docs/features/data-source.md."))},[m]);const y=t?.getRows,p=Sl({dataSource:t,paginationMode:i,sortingMode:l,filterMode:a}),f=JSON.stringify([g,g!=="all"||l==="server"?n:null,g!=="all"||a==="server"?o:null,p?c??null:null,g==="all"?null:r.pageSize]),h=g==="all"?0:r.page,b=g==="all"?0:r.pageSize,w=s.useRef({params:e,kind:g});s.useLayoutEffect(()=>{w.current={params:e,kind:g}});const C=s.useRef(0),E=s.useRef(0),S=s.useRef(null),N=s.useRef({page:0,loadedEnd:0,inFlightEnd:null}),M=s.useRef(null),_=s.useRef(!1),F=s.useRef(0),A=s.useRef(!1),L=s.useRef(new Set),k=s.useCallback(()=>{const z=_.current||F.current>0;z!==A.current&&(A.current=z,w.current.params.setDataSourceLoading(z))},[]),I=s.useCallback(()=>{M.current!==null&&(clearTimeout(M.current),M.current=null)},[]),P=s.useCallback(()=>{C.current++,N.current.inFlightEnd=null,_.current=!1},[]),v=s.useCallback(()=>{E.current++,L.current.clear(),F.current=0},[]),B=s.useCallback(async()=>{const{params:z,kind:H}=w.current,re=z.dataSource;if(!re)return!1;const ee=N.current,de=z.paginationModel.pageSize;let ie,ae;if(H==="infinite"){if(ee.inFlightEnd!==null)return!1;if(ie=ee.loadedEnd,ae=(ee.page+1)*de,ae<=ie)return _.current=!1,k(),!1;ee.inFlightEnd=ae}else H==="page"?(ie=z.paginationModel.page*de,ae=ie+de):(ie=0,ae=_l);const R=++C.current;_.current=!0,k(),z.setDataSourceError(null);let ue;try{ue=await re.getRows({startRow:ie,endRow:ae,sortModel:z.sortModel,filterModel:z.filterModel,groupKeys:[],aggregationModel:z.aggregationModel})}catch(q){return R!==C.current||(ee.inFlightEnd=null,_.current=!1,w.current.params.setDataSourceError(q),console.error("Data Source Error:",q),k()),!1}if(R!==C.current)return!1;try{const{params:q}=w.current,te=q.getRowId??El,V=Ml(ue.rows,te);if(H==="infinite"&&ie>0?q.setRows(U=>Nl(U,V,te),!0):(q.setRows(V.map(U=>U.row),!0),v()),ue.aggregationResults&&q.onAggregationResults?.(ue.aggregationResults),ue.rowCount!==void 0&&q.setRowCount(ue.rowCount),H==="infinite"&&(ee.inFlightEnd=null,ee.loadedEnd=ie+ue.rows.length,ue.rows.length>=ae-ie&&(ee.page+1)*de>ae))return!0}catch(q){return ee.inFlightEnd=null,_.current=!1,w.current.params.setDataSourceError(q),console.error("Data Source Error:",q),k(),!1}return _.current=!1,k(),!1},[k,v]),W=s.useCallback(async()=>{for(;await B(););},[B]);s.useLayoutEffect(()=>{if(!y){S.current&&(S.current=null,I(),P(),v(),w.current.params.setDataSourceError(null),k());return}const z=S.current,H=N.current;if(!z||z.key!==f||z.getRows!==y){S.current={key:f,getRows:y},P(),v();const re=g==="infinite"&&z!==null&&h!==0;if(H.page=re?0:h,H.loadedEnd=0,re){const{params:ee}=w.current;ee.onPaginationModelChange?.({...ee.paginationModel,page:0})}}else g==="infinite"?(h<H.page&&(P(),H.loadedEnd=0),H.page=h):P();if(g==="infinite"){const re=H.inFlightEnd!==null;if(re||(H.page+1)*b<=H.loadedEnd){_.current=re,k();return}}return _.current=!0,k(),M.current=setTimeout(()=>{M.current=null,W()},sf),I},[y,f,g,h,b,I,P,v,k,W]),s.useEffect(()=>()=>{P(),v()},[P,v]);const J=s.useCallback(()=>(I(),W()),[I,W]),G=s.useCallback(async(z,H,re)=>{const{params:ee}=w.current,de=ee.dataSource;if(!de)return;const ie=JSON.stringify(H),ae=L.current;if(ae.has(ie))return;const R=E.current;ae.add(ie),F.current++,k();try{const ue=await de.getRows({startRow:0,endRow:_l,sortModel:ee.sortModel,filterModel:ee.filterModel,groupKeys:H,aggregationModel:ee.aggregationModel});if(R!==E.current)return;if(ue.rows.length>0){const{params:q}=w.current,te=q.getRowId??El,V=Ml(ue.rows,te);q.setRows(U=>Nl(U,V,te),!0)}}catch(ue){if(R!==E.current)return;ae.delete(ie),console.error("Failed to fetch children:",ue),re?.(ue)}finally{R===E.current&&(F.current--,k())}},[k]);return{fetchRows:J,fetchChildren:G}}function df(e){return(e.serverChildrenCount??0)>0&&(e.children?.length??0)===0}function uf({enabled:e,treeNodes:t,isGroupExpanded:n,getNodePath:o,toggleExpansion:r,fetchChildren:i}){const l=s.useRef({isGroupExpanded:n,toggleExpansion:r});s.useLayoutEffect(()=>{l.current={isGroupExpanded:n,toggleExpansion:r}}),s.useEffect(()=>{e&&t.forEach((a,c)=>{!df(a)||!n(c)||i(c,o(c),()=>{const{isGroupExpanded:u,toggleExpansion:g}=l.current;u(c)&&g(c)})})},[e,t,n,o,i])}const Il={};function ff(e){const t=JSON.stringify(e),[n,o]=s.useState(null),r=s.useCallback(i=>o({modelKey:t,results:i}),[t]);return[n&&n.modelKey===t?n.results:null,r]}function Ll(e){const{rows:t,columns:n,aggregationModel:o,isServerSide:r,dataSource:i,filterModel:l,sortModel:a,serverAggregationResults:c}=e,u=Object.keys(o).length>0,g=s.useMemo(()=>{const S=new Map;return(n??[]).forEach(N=>S.set(N.field,N)),S},[n]),m=s.useMemo(()=>r||!u?Il:Ln(t,o,g,"useAggregation"),[t,g,o,r,u]),x=JSON.stringify([o,l??null,a??[]]),y=r&&u&&!!i?.getAggregations&&!c,p=s.useRef({aggregationModel:o,filterModel:l,sortModel:a});s.useEffect(()=>{p.current={aggregationModel:o,filterModel:l,sortModel:a}});const[f,h]=s.useState(null);s.useEffect(()=>{const S=i?.getAggregations;if(!y||!S)return;let N=!1;const M=p.current,_={sortModel:M.sortModel??[],filterModel:M.filterModel??{items:[]},groupKeys:[],aggregationModel:M.aggregationModel};let F;try{F=Promise.resolve(S(_))}catch(A){F=Promise.reject(A)}return F.then(A=>{N||h({key:x,result:A,error:null})},A=>{N||(console.error("[useAggregation] Server aggregation error:",A),h({key:x,result:null,error:A}))}),()=>{N=!0}},[y,i,x]);const b=f&&f.key===x?f:null,w=y&&b===null,C=y?b?.error??null:null;return{aggregationResult:s.useMemo(()=>r?c&&Object.keys(c).length>0?c:b?.result??Il:m,[r,m,c,b]),isLoading:w,error:C}}const gf={items:[]},pf=[];function hf(e){const{rows:t,columns:n,pivotMode:o,pivotModel:r,filterModel:i,sortModel:l,hasDataSource:a,hierarchyRequested:c}=e,u=o&&!a,g=s.useMemo(()=>new Set(n.map(b=>b.field)),[n]),m=s.useMemo(()=>No(n),[n]),x=s.useMemo(()=>qa(i,g),[i,g]),y=s.useMemo(()=>u?So(t,x.source,m):t,[u,t,x.source,m]),p=s.useMemo(()=>u?mi(y,n,r,{outputFilterModel:x.output,sortModel:l}):Lo,[u,y,n,r,x.output,l]),f=u&&p.isValid,h=s.useRef({dataSource:!1,hierarchy:!1});return s.useEffect(()=>{process.env.NODE_ENV!=="production"&&(o&&a&&!h.current.dataSource&&(h.current.dataSource=!0,console.warn("[OpenGridX] `pivotMode` is ignored when a `dataSource` is set: pivoting is client-side and the grid only holds the rows of one server page. Pivot on the server, or pass the full dataset as `rows`.")),f&&c&&!h.current.hierarchy&&(h.current.hierarchy=!0,console.warn("[OpenGridX] `treeData` and `rowGroupingModel` are turned off while `pivotMode` is active: the pivot rows are already grouped by the pivot row fields.")))},[o,a,f,c]),{isActive:f,rows:f?p.pivotRows:t,columns:f?p.pivotColumns:n,pipelineFilterModel:f?gf:i,pipelineSortModel:f?pf:l}}const Al=s.createContext(null);function mf(e){if(typeof e!="function")return!1;const t=e.prototype;return!(typeof t=="object"&&t!==null&&"isReactComponent"in t)}function wf({render:e,toolbarProps:t}){"use no memo";return d.jsx(d.Fragment,{children:e(t)})}function bf({component:e,toolbarProps:t}){if(mf(e))return d.jsx(wf,{render:e,toolbarProps:t},`fn:${e.toString()}`);const n=e;return d.jsx(n,{...t})}const Qe=({variant:e="text",size:t="medium",color:n="default",disabled:o=!1,className:r="",type:i="button",children:l,...a})=>{const c=["ogx-button",`ogx-button--${e}`,`ogx-button--${t}`,`ogx-button--${n}`,o&&"ogx-button--disabled",r].filter(Boolean).join(" ");return d.jsx("button",{type:i,className:c,disabled:o,...a,children:l})},et=s.forwardRef(function({fullWidth:t=!1,error:n=!1,startAdornment:o,endAdornment:r,className:i="",inputClassName:l="",variant:a="field",...c},u){const g=["ogx-input-wrapper",a==="cell"&&"ogx-input-wrapper--cell",t&&"ogx-input-wrapper--full-width",n&&"ogx-input-wrapper--error",c.disabled&&"ogx-input-wrapper--disabled",i].filter(Boolean).join(" "),m=["ogx-input",l].filter(Boolean).join(" ");return d.jsxs("div",{className:g,children:[o&&d.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--start",children:o}),d.jsx("input",{ref:u,className:m,"aria-invalid":n?!0:void 0,...c}),r&&d.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--end",children:r})]})});et.displayName="Input";function xf(){if(typeof window>"u")return null;const e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function yf(e){const[t,n]=s.useState(!1),o=s.useRef(null),r=s.useRef(e);s.useLayoutEffect(()=>{r.current=e}),s.useEffect(()=>()=>{const l=o.current;o.current=null,l&&We(()=>l.abort())},[]);const i=s.useCallback(()=>{const l=o.current;if(l){We(()=>l.stop());return}const a=xf();if(!a)return;const c=We(()=>new a);if(!c.ok)return;const u=c.value;u.lang=typeof navigator>"u"?"en-US":navigator.language,u.interimResults=!1,u.maxAlternatives=1,u.onresult=m=>{const x=m.results[0],y=x&&x[0]?x[0].transcript:"";y&&r.current(y)};const g=()=>{o.current===u&&(o.current=null),n(!1)};u.onend=g,u.onerror=g,o.current=u,n(!0),We(()=>u.start()).ok||g()},[]);return{listening:t,toggle:i}}function Pl(){return d.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:[d.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),d.jsx("path",{d:"M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8z"})]})}function Cf(){return d.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",focusable:"false",children:[d.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),d.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}function vf(e){const{status:t,statusText:n,message:o,errors:r,chips:i,history:l,suggestions:a,placeholder:c,voiceAvailable:u,canUndo:g,submit:m,stop:x,undo:y,removeChip:p,close:f}=e,[h,b]=s.useState(""),w=s.useRef(null),C=yf(b),E=t==="running";s.useEffect(()=>{w.current&&w.current.focus()},[]);const S=_=>{b(_),m(_)},N=_=>()=>{_(),w.current&&w.current.focus()},M=_=>{_.preventDefault(),E||m(h)};return d.jsxs("div",{className:"ogx-ai-panel",role:"dialog","aria-label":"Ask AI",children:[d.jsxs("div",{className:"ogx-ai-panel__header",children:[d.jsxs("span",{className:"ogx-ai-panel__title",children:[d.jsx(Pl,{}),"Ask AI"]}),d.jsx(Qe,{size:"small",className:"ogx-ai-panel__close","aria-label":"Close",onClick:f,children:"×"})]}),d.jsxs("form",{className:"ogx-ai-panel__form",onSubmit:M,children:[d.jsx(et,{ref:w,className:"ogx-ai-panel__input",value:h,placeholder:c,"aria-label":"Prompt",autoComplete:"off",onChange:_=>b(_.target.value)}),u&&d.jsx(Qe,{size:"small",variant:"outlined",className:`ogx-ai-panel__mic${C.listening?" ogx-ai-panel__mic--on":""}`,"aria-label":C.listening?"Stop dictation":"Dictate a prompt","aria-pressed":C.listening,onClick:C.toggle,children:d.jsx(Cf,{})}),E?d.jsx(Qe,{size:"small",variant:"outlined",onClick:N(x),children:"Stop"},"stop"):d.jsx(Qe,{size:"small",variant:"contained",color:"primary",type:"submit",disabled:h.trim()==="",children:"Ask"},"ask")]}),a.length>0&&d.jsx("div",{className:"ogx-ai-panel__suggestions","aria-label":"Suggestions",role:"group",children:a.map(_=>d.jsx("button",{type:"button",className:"ogx-ai-panel__suggestion",disabled:E,onClick:()=>S(_),children:_},_))}),n&&d.jsx("div",{className:`ogx-ai-panel__status ogx-ai-panel__status--${t}`,children:n}),o&&d.jsx("p",{className:"ogx-ai-panel__message",children:o}),(i.length>0||g)&&d.jsxs("div",{className:"ogx-ai-panel__changes",children:[d.jsx("ul",{className:"ogx-ai-panel__chips","aria-label":"Applied changes",children:i.map(_=>d.jsxs("li",{className:"ogx-ai-chip","data-part":_.part,children:[d.jsx("span",{className:"ogx-ai-chip__label",children:_.label}),d.jsx("button",{type:"button",className:"ogx-ai-chip__remove","aria-label":`Remove ${_.label}`,onClick:N(()=>p(_.id)),children:"×"})]},_.id))}),g&&d.jsx(Qe,{size:"small",variant:"outlined",className:"ogx-ai-panel__undo",onClick:N(y),children:"Undo"})]}),r.length>0&&d.jsx("ul",{className:"ogx-ai-panel__errors","aria-label":"Ignored",children:r.map((_,F)=>d.jsx("li",{children:_.path?`Ignored: ${_.message}`:_.message},`${_.path}:${F}`))}),l.length>0&&d.jsxs("div",{className:"ogx-ai-panel__history",children:[d.jsx("div",{className:"ogx-ai-panel__history-title",children:"Earlier"}),d.jsx("ul",{children:l.map((_,F)=>d.jsx("li",{children:d.jsx("button",{type:"button",className:"ogx-ai-panel__history-item",onClick:()=>b(_.prompt),children:_.prompt})},`${F}:${_.prompt}`))})]})]})}function Sf({panelProps:e,slot:t,slotProps:n}){const o=r=>{r.key==="Escape"&&(r.stopPropagation(),e.close())};return d.jsx("div",{className:"ogx-ai-anchor",onKeyDown:o,children:t?d.jsx(t,{...e,...n}):d.jsx(vf,{...e})})}function Tl(e,t){typeof e=="function"?e(t):e&&(e.current=t)}const ft=s.forwardRef(function({indeterminate:t=!1,label:n,className:o="",inputClassName:r="",inputRef:i,...l},a){const c=s.useRef(null),u=s.useCallback(m=>{c.current=m,Tl(i,m),Tl(a,m)},[i,a]);s.useEffect(()=>{c.current&&(c.current.indeterminate=t)},[t]);const g=["ogx-checkbox-wrapper",l.disabled&&"ogx-checkbox-wrapper--disabled",o].filter(Boolean).join(" ");return d.jsxs("label",{className:g,children:[d.jsx("input",{ref:u,type:"checkbox",className:["ogx-checkbox__input",r].filter(Boolean).join(" "),...l}),d.jsxs("span",{className:"ogx-checkbox__box",children:[l.checked&&!t&&d.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:d.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),t&&d.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:d.jsx("path",{d:"M19 13H5v-2h14v2z"})})]}),n&&d.jsx("span",{className:"ogx-checkbox__label",children:n})]})});ft.displayName="Checkbox";function _f(){return d.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("circle",{cx:"11",cy:"11",r:"8"}),d.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function kf(){return d.jsxs("svg",{className:"ogx-column-visibility-panel__drag-handle",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[d.jsx("circle",{cx:"9",cy:"5",r:"1.5"}),d.jsx("circle",{cx:"15",cy:"5",r:"1.5"}),d.jsx("circle",{cx:"9",cy:"12",r:"1.5"}),d.jsx("circle",{cx:"15",cy:"12",r:"1.5"}),d.jsx("circle",{cx:"9",cy:"19",r:"1.5"}),d.jsx("circle",{cx:"15",cy:"19",r:"1.5"})]})}function Qo(e){const{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:a,showNonHideableColumns:c}=e,[u,g]=s.useState(""),m=s.useId(),[x,y]=s.useState(null),p=s.useRef(null),f=s.useMemo(()=>t.filter(_=>_.hideable!==!1),[t]),h=f.every(_=>n.has(_.field)),b=s.useMemo(()=>{const _=c?t:f;if(!u)return _;const F=u.toLowerCase();return _.filter(A=>(A.headerName||A.field).toLowerCase().includes(F))},[t,f,u,c]),w=_=>{_.target.checked?r():i()},C=_=>F=>{p.current=_,F.dataTransfer.effectAllowed="move",F.dataTransfer.setDragImage(F.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},E=_=>F=>{F.preventDefault(),F.dataTransfer.dropEffect="move",_!==p.current&&y(_)},S=()=>{y(null)},N=_=>F=>{F.preventDefault();const A=p.current;y(null),p.current=null,A&&A!==_&&l&&l(A,_)},M=()=>{y(null),p.current=null};return d.jsxs("div",{className:"ogx-column-visibility-panel",children:[d.jsx("div",{className:"ogx-column-visibility-panel__search-section",children:d.jsxs("div",{className:"ogx-column-visibility-panel__search-container",children:[d.jsx(_f,{}),d.jsx(et,{autoComplete:"off",inputClassName:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:u,onChange:_=>g(_.target.value)})]})}),d.jsx("div",{className:"ogx-column-visibility-panel__list",children:b.map((_,F)=>{const A=`${m}-col-${F}`,L=n.has(_.field),k=_.hideable!==!1,I=x===_.field,P=!!l&&!u;return d.jsxs("div",{className:["ogx-column-visibility-panel__item",!k&&"ogx-column-visibility-panel__item--disabled",I&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:P,onDragOver:P?E(_.field):void 0,onDragLeave:P?S:void 0,onDrop:P?N(_.field):void 0,onDragEnd:P?M:void 0,children:[P&&d.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:C(_.field),title:"Drag to reorder",children:d.jsx(kf,{})}),d.jsxs("div",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:k?"pointer":"not-allowed"},children:[d.jsx(ft,{id:A,checked:L,onChange:v=>o(_.field,v.target.checked),disabled:!k}),d.jsx("label",{htmlFor:A,className:"ogx-column-visibility-panel__label",children:_.headerName||_.field})]})]},_.field)})}),d.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[d.jsxs("div",{className:"ogx-column-visibility-panel__item",children:[d.jsx(ft,{id:`${m}-all`,checked:h,onChange:w}),d.jsx("label",{htmlFor:`${m}-all`,className:"ogx-column-visibility-panel__label",children:"Show/Hide All"})]}),d.jsx("button",{type:"button",className:"ogx-column-visibility-panel__reset-btn",onClick:()=>{r(),a?.()},children:"Reset"})]})]})}function Mt(){return document.documentElement.clientWidth||window.innerWidth}function Fl(){return document.documentElement.clientHeight||window.innerHeight}function Ef({isOpen:e,containerRef:t,panelRef:n,columns:o,columnVisibilityModel:r,disableColumnReorder:i,onClose:l,onColumnVisibilityChange:a,onColumnMove:c,onColumnOrderReset:u,columnGroupingModel:g}){const[m,x]=s.useState(null);if(s.useLayoutEffect(()=>{if(!e||!t.current)return;const p=t.current.getBoundingClientRect();x({top:p.top+8,right:Mt()-p.right+8,target:t.current.closest(".ogx-theme-provider")||document.body})},[e,t]),!e||!m)return null;const y=i?void 0:(p,f)=>{Vo(g,p,f)&&c(p,f)};return st.createPortal(d.jsxs("div",{ref:n,style:{position:"fixed",top:m.top,right:m.right,zIndex:9999,display:"inline-block"},children:[d.jsx("button",{type:"button",onClick:l,style:{position:"absolute",top:-12,right:-12,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",background:"#334155",color:"#fff",border:"none",borderRadius:"50%",cursor:"pointer",fontSize:14,lineHeight:1,zIndex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.2)"},"aria-label":"Close",children:"×"}),d.jsx(Qo,{columns:o,visibleColumns:new Set(o.filter(p=>r[p.field]!==!1).map(p=>p.field)),onVisibilityChange:(p,f)=>{a({...r,[p]:f})},onShowAll:()=>{const p={...r};o.forEach(f=>{f.hideable!==!1&&(p[f.field]=!0)}),a(p)},onHideAll:()=>{const p={...r};o.forEach(f=>{f.hideable!==!1&&(p[f.field]=!1)}),a(p)},onColumnReorder:y,onColumnOrderReset:i?void 0:u})]}),m.target)}function er(e){const t=s.useId(),{page:n,pageSize:o,rowCount:r,onPageChange:i,onPageSizeChange:l,pageSizeOptions:a=[10,25,50,100],showFirstButton:c=!0,showLastButton:u=!0,localeText:g}=e,m=Bn(o),x=Oo(r,m),y=Pi(n,x),p=a.includes(m)?a:[...a,m].sort((k,I)=>k-I),f=y*m,h=Math.min(f+m,r),b=r===0?0:`${f+1}–${h}`,w=g?.paginationRowsPerPage??"Rows per page:",C=g?.paginationOf?g.paginationOf(r===0?0:f+1,h,r):`${b} of ${r}`,E=g?.paginationPage?g.paginationPage(y+1,x):`Page ${y+1} of ${x}`,S=()=>{i(0)},N=()=>{i(Math.max(0,y-1))},M=()=>{i(Math.min(x-1,y+1))},_=()=>{i(x-1)},F=k=>{const I=parseInt(k.target.value,10);l(I)},A=y===0,L=y>=x-1;return d.jsxs("div",{className:"ogx-pagination",role:"navigation","aria-label":"Pagination",children:[d.jsxs("div",{className:"ogx-pagination__page-size",children:[d.jsx("label",{htmlFor:t,className:"ogx-pagination__label",children:w}),d.jsx("select",{id:t,className:"ogx-pagination__select",value:m,onChange:F,children:p.map(k=>d.jsx("option",{value:k,children:k},k))})]}),d.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:C}),d.jsxs("div",{className:"ogx-pagination__actions",children:[c&&d.jsx(Qe,{variant:"text",size:"small",onClick:S,disabled:A,"aria-label":"Go to first page",title:"First page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"})})}),d.jsx(Qe,{variant:"text",size:"small",onClick:N,disabled:A,"aria-label":"Go to previous page",title:"Previous page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),d.jsx("div",{className:"ogx-pagination__page-info","aria-current":"page",children:E}),d.jsx(Qe,{variant:"text",size:"small",onClick:M,disabled:L,"aria-label":"Go to next page",title:"Next page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),u&&d.jsx(Qe,{variant:"text",size:"small",onClick:_,disabled:L,"aria-label":"Go to last page",title:"Last page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"})})})]})]})}function Mf({row:e,rowId:t,rowIndex:n,ariaRowIndex:o,listViewColumn:r,gridColumn:i,rowMeta:l,isSelected:a=!1,checkboxSelection:c=!1,rowHeight:u,onRowClick:g,onRowDoubleClick:m,onSelectionChange:x,tabIndex:y=-1,onFocus:p,onToggleExpansion:f}){const h=t??e.id,b=r.field,w=Me(e,b,i),C=fo(e,b,w,i)??En(w,i),E=l?.isGroupRow===!0||Re(h),S={row:e,value:w,formattedValue:C,field:b,colDef:i??r,rowIndex:n,colIndex:0,rowMeta:l},N=M=>{M.stopPropagation(),x?.(h,M.target.checked)};return d.jsxs("div",{className:`ogx-list-view__row${a?" ogx-list-view__row--selected":""}`,style:u?{minHeight:u}:void 0,onClick:()=>g?.(e),onDoubleClick:m?()=>m(e):void 0,role:"row","aria-rowindex":o??n+1,"aria-selected":a,"aria-level":l?.treeDepth!==void 0?l.treeDepth+1:void 0,"aria-expanded":l?.hasChildren?l.isExpanded===!0:void 0,"data-rowindex":n,tabIndex:y,onFocus:p?M=>{M.target===M.currentTarget&&p(n)}:void 0,children:[c&&d.jsx("div",{className:"ogx-list-view__checkbox",onClick:M=>M.stopPropagation(),children:!E&&d.jsx(ft,{checked:a,onChange:N,"aria-label":`Select row ${h}`,tabIndex:-1})}),l&&f&&d.jsx("div",{className:"ogx-list-view__expand",style:{paddingInlineStart:(l.treeDepth??0)*16},onClick:M=>M.stopPropagation(),onDoubleClick:M=>M.stopPropagation(),children:l.hasChildren&&d.jsx(Ho,{isExpanded:l.isExpanded===!0,onClick:()=>f(h),tabIndex:-1})}),d.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:d.jsx(kt,{field:b,resetKey:e,renderFn:()=>{const M=r.renderCell(S);return M===void 0&&E?l?.groupLabel:M}})})]})}function Nf(e,t){const n=s.useRef(!0),o=s.useRef(e);s.useEffect(()=>{o.current=e},[e]),s.useEffect(()=>{n.current=!0},[t]);const r=s.useCallback(i=>{const l=dl(i.currentTarget);if(!l){n.current=!0;return}if(!n.current)return;const a=o.current;a&&(n.current=!1,a(l))},[]);return e?r:void 0}const If=e=>e.id;function Lf({ariaLabel:e,allRenderableRows:t,dataRowCount:n,pinnedTopRowCount:o,pinnedBottomRowCount:r,unpinnedRowCount:i,pagination:l,effectivePaginationModel:a,currentPage:c,pageSizeOptions:u,selectedRowIds:g,listViewColumn:m,columnsByField:x,rowMetaMap:y,noRowsLabel:p,rowHeight:f,checkboxSelection:h,paginationMode:b,serverRowCount:w,paginationSlot:C,paginationSlotProps:E,localeText:S,onRowClick:N,onRowDoubleClick:M,onSelectionChange:_,onPaginationModelChange:F,onRowsScrollEnd:A,getRowId:L=If,multiselectable:k=!1,loading:I=!1,loadingOverlay:P,noRowsOverlay:v,showPaginationControls:B=!0,selectable:W=!1,onToggleExpansion:J}){const G=C||er,z=s.useRef(null),[H,re]=s.useState(null),ee=H===null?-1:t.findIndex(D=>L(D)===H),de=ee===-1?0:ee,ie=D=>{const T=t[D];T&&(re(L(T)),z.current?.querySelector(`:scope > [role="row"][data-rowindex="${D}"]`)?.focus())},ae=D=>{const T=D.target;if(T.getAttribute("role")!=="row"||T.parentElement!==z.current)return;const $=Number(T.getAttribute("data-rowindex")),O=t[$];if(!O)return;const Z=L(O),j=t.length-1,ne=y.get(Z),X=!!(ne?.hasChildren&&J);if(D.altKey&&(D.key==="ArrowRight"||D.key==="ArrowLeft")){D.preventDefault();const Y=Mn(D.key,Xe(D.currentTarget))==="ArrowRight";X&&Y!==(ne?.isExpanded===!0)&&J?.(Z);return}switch(D.key){case"ArrowDown":D.preventDefault(),ie(Math.min($+1,j));return;case"ArrowUp":D.preventDefault(),ie(Math.max($-1,0));return;case"Home":D.preventDefault(),ie(0);return;case"End":D.preventDefault(),ie(j);return;case"PageDown":D.preventDefault(),ie(Math.min($+10,j));return;case"PageUp":D.preventDefault(),ie(Math.max($-10,0));return;case"Enter":case" ":if(D.preventDefault(),D.key===" "&&D.shiftKey){W&&!ne?.isGroupRow&&_(Z,!g.has(Z));return}X?J?.(Z):N({row:O,id:Z,rowIndex:$});return}},R=b==="server",ue=R?w||0:i,q=R?w||0:n,te=Bn(a.pageSize),V=Oo(ue,te),U=l?c*te:0,ce=t.length-o-r,ge=D=>{if(D<o)return D+1;const T=D-o;return T<ce?o+U+T+1:o+ue+(T-ce)+1},Q=Nf(A,t.length);return d.jsxs("div",{className:"ogx-list-view",role:"grid","aria-label":e||"Data grid list view","aria-rowcount":q,"aria-multiselectable":k,children:[d.jsx("div",{className:"ogx-list-view__toolbar",children:d.jsxs("span",{children:[q," ",q===1?"item":"items",l?` · page ${c+1} of ${V}`:"",g.size>0?` · ${g.size} selected`:""]})}),d.jsx("div",{className:"ogx-list-view__rows",tabIndex:-1,onScroll:Q,onKeyDown:ae,ref:z,children:t.length===0&&I?d.jsx("div",{className:"ogx-list-view__loading",children:P??d.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})}):t.length===0&&v?d.jsx("div",{className:"ogx-list-view__empty",children:v}):t.length===0?d.jsxs("div",{className:"ogx-list-view__empty",children:[d.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[d.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),d.jsx("path",{d:"M3 9h18M9 21V9"})]}),p]}):t.map((D,T)=>{const $=L(D);return d.jsx(Mf,{row:D,rowId:$,rowIndex:T,ariaRowIndex:ge(T),listViewColumn:m,gridColumn:x.get(m.field),rowMeta:y.get($),isSelected:g.has($),checkboxSelection:h,rowHeight:f,onRowClick:O=>N({row:O,id:$,rowIndex:T}),onRowDoubleClick:M?O=>M({row:O,id:$,rowIndex:T}):void 0,onSelectionChange:_,tabIndex:T===de?0:-1,onToggleExpansion:J,onFocus:O=>re(L(t[O]))},$)})}),l&&B&&d.jsx(G,{page:c,pageSize:a.pageSize,rowCount:ue,pageSizeOptions:u,onPageChange:D=>F({...a,page:D}),onPageSizeChange:D=>F({...a,pageSize:D,page:0}),localeText:S,...E})]})}const Af=16;function Pf(e){e.preventDefault(),e.stopPropagation()}function Tf(){const e=t=>{t.stopPropagation(),t.preventDefault()};window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}),0)}function Ff(e){const{field:t,currentWidth:n,onResize:o,onAutosize:r,minWidth:i,maxWidth:l,edge:a="end"}=e,[c,u]=s.useState(!1),g=s.useRef(null);s.useEffect(()=>()=>{g.current=null},[]);const m=s.useCallback((w,C)=>{const E=(C-w.startX)*(w.rtl?-1:1),S=w.startWidth+(a==="start"?-E:E);return Jo(S,w.startWidth,i,l)},[a,i,l]),x=s.useCallback(w=>{if(w.button===0){w.stopPropagation(),g.current={pointerId:w.pointerId,startX:w.clientX,startWidth:n,rtl:Xe(w.currentTarget),lastUpdate:0,moved:!1},u(!0);try{w.currentTarget.setPointerCapture(w.pointerId)}catch{}}},[n]),y=s.useCallback(w=>{const C=g.current;if(!C||w.pointerId!==C.pointerId||(w.clientX!==C.startX&&(C.moved=!0),!C.moved))return;const E=Date.now();E-C.lastUpdate>=Af&&(C.lastUpdate=E,o(t,m(C,w.clientX)))},[t,o,m]),p=s.useCallback((w,C)=>{const E=g.current;if(!(!E||w.pointerId!==E.pointerId)){if(g.current=null,u(!1),w.currentTarget.hasPointerCapture?.(w.pointerId))try{w.currentTarget.releasePointerCapture(w.pointerId)}catch{}(E.moved||w.clientX!==E.startX)&&(Tf(),C&&o(t,m(E,w.clientX)))}},[t,o,m]),f=s.useCallback(w=>{if(w.key==="Enter"&&r){w.preventDefault(),w.stopPropagation(),r(t);return}if(w.key!=="ArrowLeft"&&w.key!=="ArrowRight")return;w.preventDefault(),w.stopPropagation();const C=Mn(w.key,Xe(w.currentTarget)),E=(w.shiftKey?50:10)*(C==="ArrowRight"?1:-1);o(t,Jo(n+E,n,i,l))},[t,n,o,r,i,l]),h=s.useCallback(w=>{w.preventDefault(),w.stopPropagation(),r?.(t)},[t,r]),b=["ogx-column-resize-handle",a==="start"&&"ogx-column-resize-handle--start",c&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return d.jsx("div",{className:b,onPointerDown:x,onMouseDown:Pf,onPointerMove:y,onPointerUp:w=>p(w,!0),onPointerCancel:w=>p(w,!1),onClick:w=>w.stopPropagation(),onDragStart:w=>{w.preventDefault(),w.stopPropagation()},onDoubleClick:h,onKeyDown:f,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,"aria-valuenow":Math.round(n),"aria-valuemin":Math.round(Math.min(i??50,n)),"aria-valuemax":l,tabIndex:-1,children:d.jsx("div",{className:"ogx-column-resize-handle__line"})})}function Kt(){return d.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:d.jsx("circle",{cx:"4",cy:"4",r:"4"})})}function Ut(){return d.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:d.jsx("circle",{cx:"4",cy:"4",r:"3"})})}function Of(){return d.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",children:[d.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.3"}),d.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),d.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Df(){return d.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),d.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function $f(){return d.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),d.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function Gf(){return d.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:d.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function Hf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.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"}),d.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"}),d.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Bf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"4",y1:"2",x2:"4",y2:"22"}),d.jsx("polyline",{points:"11 8 4 12 11 16"}),d.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Wf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"20",y1:"2",x2:"20",y2:"22"}),d.jsx("polyline",{points:"13 8 20 12 13 16"}),d.jsx("line",{x1:"20",y1:"12",x2:"4",y2:"12"})]})}function Vf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),d.jsx("line",{x1:"4",y1:"4",x2:"4",y2:"20"}),d.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}const Ol=e=>e?Array.from(e.querySelectorAll('[role="menuitem"], [role="menuitemradio"]')):[];function zf({colDef:e,sortModel:t,onSort:n,onHide:o,onPin:r,pinnedColumns:i,onManageColumns:l,onClose:a,anchorEl:c}){const u=s.useRef(null),g=s.useCallback(v=>{v&&(c?.closest('[role="columnheader"]')??c)?.focus({preventScroll:!0}),a()},[c,a]),m=v=>{const B=Ol(u.current),W=B.indexOf(v.target);let J=-1;if(v.key==="ArrowDown")J=W+1>=B.length?0:W+1;else if(v.key==="ArrowUp")J=W<=0?B.length-1:W-1;else if(v.key==="Home")J=0;else if(v.key==="End")J=B.length-1;else if(v.key==="Tab"){v.preventDefault(),g(!0);return}else return;v.preventDefault(),B[J]?.focus()},[x,y]=s.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});s.useLayoutEffect(()=>{if(!c||!u.current)return;const v=c.getBoundingClientRect(),B=u.current.getBoundingClientRect(),W=Mt(),J=Fl(),G=8;let z=v.left;z+B.width+G>W&&(z=W-B.width-G),z<G&&(z=G);let H=v.bottom+4;H+B.height+G>J&&(H=v.top-B.height-4),y({position:"fixed",zIndex:1300,top:H,left:z,visibility:"visible"})},[c]);const p=x.visibility==="visible";s.useLayoutEffect(()=>{p&&Ol(u.current)[0]?.focus({preventScroll:!0})},[p]),s.useEffect(()=>{function v(W){u.current&&!u.current.contains(W.target)&&c&&!c.contains(W.target)&&a()}function B(W){W.key==="Escape"&&g(!0)}return document.addEventListener("mousedown",v),document.addEventListener("keydown",B),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",B),window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[c,a,g]);const f=v=>{n?.(e.field,v),g(!0)},h=!!o&&e.hideable!==!1,b=!!r&&e.pinnable!==!1,w=()=>{h&&o?.(e.field),g(!0)},C=v=>{b&&r?.(e.field,v),g(!0)},E=t?.find(v=>v.field===e.field)?.sort,S=E==null,N=i?.left?.includes(e.field)??!1,M=i?.right?.includes(e.field)??!1,_=!N&&!M,F=Xe(c),A=F?"right":"left",L=F?"left":"right",k=F?M:N,I=F?N:M,P=e.headerName||e.field;return st.createPortal(d.jsxs("div",{ref:u,className:"ogx-column-menu",style:x,role:"menu","aria-label":`Column options for ${P}`,onKeyDown:m,children:[n&&e.sortable!==!1&&d.jsxs(d.Fragment,{children:[d.jsxs("button",{type:"button",className:`ogx-menu-item${E==="asc"?" ogx-menu-item--active":""}`,onClick:()=>f("asc"),role:"menuitemradio","aria-checked":E==="asc",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="asc"?d.jsx(Kt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Df,{})}),"Sort Ascending"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${E==="desc"?" ogx-menu-item--active":""}`,onClick:()=>f("desc"),role:"menuitemradio","aria-checked":E==="desc",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="desc"?d.jsx(Kt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx($f,{})}),"Sort Descending"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${S?" ogx-menu-item--active":""}`,onClick:()=>f(null),role:"menuitemradio","aria-checked":S,children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:S?d.jsx(Kt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Gf,{})}),"Unsort"]}),d.jsx("div",{className:"ogx-menu-divider"})]}),b&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"ogx-menu-section-label","aria-hidden":"true",children:"Pin column"}),d.jsxs("button",{type:"button",className:`ogx-menu-item${k?" ogx-menu-item--active":""}`,onClick:()=>C(A),role:"menuitemradio","aria-checked":k,"aria-label":"Pin to left",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:k?d.jsx(Kt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Bf,{})}),"Pin to Left"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${I?" ogx-menu-item--active":""}`,onClick:()=>C(L),role:"menuitemradio","aria-checked":I,"aria-label":"Pin to right",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:I?d.jsx(Kt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Wf,{})}),"Pin to Right"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${_?" ogx-menu-item--active":""}`,onClick:()=>C(null),role:"menuitemradio","aria-checked":_,"aria-label":"Unpin column",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:_?d.jsx(Kt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Vf,{})}),"Unpin"]}),d.jsx("div",{className:"ogx-menu-divider"})]}),h&&d.jsxs(d.Fragment,{children:[d.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:w,role:"menuitem","aria-label":`Hide ${P} column`,children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Hf,{})}),"Hide Column"]}),d.jsx("div",{className:"ogx-menu-divider"})]}),d.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:()=>{l?.(),g(!1)},role:"menuitem","aria-label":"Manage all columns",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Of,{})}),"Manage columns"]})]}),c?.closest(".ogx-theme-provider")||document.body)}const Rf=16,Kf=16;function Uf(e,t=!1){const n=Number.isFinite(e)?e-Kf:0,o=Math.floor(n/Rf)-(t?1:0);return Math.max(1,o)}function jf(e,t){return e??t??!1}function Dl(e,t,n,o){const r={width:t[e.field]??e.width??100,minWidth:e.minWidth,maxWidth:e.maxWidth,flexGrow:e.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",position:n?"sticky":"relative"};return n==="left"?r.insetInlineStart=o:n==="right"&&(r.insetInlineEnd=o),r}const qf="header:",Xf=40,Yf=300,Jf="__group__",$l=[];function tr(e){return`${qf}${e}`}function nr(e){return"items"in e&&Array.isArray(e.items)}function Zf(e){return e.isSpacer||Je(e.field)||e.field===Jf?!1:e.headerFilter!==!1&&e.filterable!==!1&&e.type!=="image"}function Un(e){if(e.headerFilterOperator)return e.headerFilterOperator;switch(e.type){case"number":return"=";case"date":case"boolean":case"singleSelect":return"is";default:return"contains"}}function Qf(e){const t=Qr(e.type),n=Un(e);return t.includes(n)?t:[n,...t]}function Gl(e,t){return e.items.some(n=>nr(n)?Gl(n,t):n.field===t)}function eg(e){return(e?.logicOperator??"and")==="or"&&(e?.items?.length??0)>0}function Hl(e,t){const n=e?.items??$l;if(eg(e))return{kind:"custom"};const o=tr(t);let r;for(const i of n){if(nr(i)){if(Gl(i,t))return{kind:"custom"};continue}if(i.field===t){if(i.id!==o||r)return{kind:"custom"};r=i}}return{kind:"editable",item:r}}function tg(e,t,n){const o=e??{items:[]};if(Hl(o,t).kind!=="editable")return o;const r=tr(t),i=o.items??$l,l=i.findIndex(u=>!nr(u)&&u.id===r),a=n?{...n,id:r,field:t}:null;let c;if(l===-1){if(!a)return o;if(i.length===0&&o.logicOperator==="or")return{...o,logicOperator:"and",items:[a]};c=[...i,a]}else a?c=i.map((u,g)=>g===l?a:u):c=i.filter((u,g)=>g!==l);return{...o,items:c}}function or(e,t,n){const o=Dt.has(t);return!o&&xo(n)&&t===Un(e)?null:{id:tr(e.field),field:e.field,operator:t,value:o?void 0:n}}function Bl(e,t){if(!Dt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const ng={contains:"∋",equals:"=",startsWith:"a…",endsWith:"…a",isEmpty:"∅",isNotEmpty:"!∅",isAnyOf:"∈","=":"=","!=":"≠",">":">",">=":"≥","<":"<","<=":"≤",is:"=",not:"≠",after:">",onOrAfter:"≥",before:"<",onOrBefore:"≤"},og={contains:"Contains",equals:"Equals",startsWith:"Starts with",endsWith:"Ends with",isEmpty:"Is empty",isNotEmpty:"Is not empty",isAnyOf:"Is any of","=":"Equals","!=":"Does not equal",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",is:"Is",not:"Is not",after:"After",onOrAfter:"On or after",before:"Before",onOrBefore:"On or before"};function rg(e){const t=e?.headerFilterOperators;return{custom:e?.headerFilterCustom??"Custom filter",customTooltip:e?.headerFilterCustomTooltip??"Set in the filter panel",cellLabel:e?.headerFilterCellLabel??(n=>`Filter ${n}`),valueLabel:e?.headerFilterValueLabel??(n=>`Filter value for ${n}`),operatorButtonLabel:e?.headerFilterOperatorButtonLabel??((n,o)=>`Filter operator for ${n}: ${o}`),operatorMenuLabel:e?.headerFilterOperatorMenuLabel??(n=>`Filter operator for ${n}`),clearLabel:e?.headerFilterClearLabel??(n=>`Clear filter for ${n}`),clearTooltip:e?.headerFilterClearTooltip??"Clear",any:e?.headerFilterAny??"Any",yes:e?.headerFilterTrue??"Yes",no:e?.headerFilterFalse??"No",operator:n=>t?.[n]??og[n]??n}}const ig={position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"},Wl=e=>e?Array.from(e.querySelectorAll('[role="menuitemradio"]')):[];function lg({anchorEl:e,columnLabel:t,operators:n,current:o,onSelect:r,onClose:i,locale:l}){const a=s.useRef(null),[c,u]=s.useState(ig);s.useLayoutEffect(()=>{const y=a.current;if(!y)return;const p=e.getBoundingClientRect(),f=y.getBoundingClientRect(),h=8;let b=Math.min(p.left,Mt()-f.width-h);b<h&&(b=h);let w=p.bottom+4;w+f.height+h>Fl()&&(w=p.top-f.height-4),u({position:"fixed",zIndex:1300,top:w,left:b,visibility:"visible"})},[e]);const g=c.visibility==="visible";s.useLayoutEffect(()=>{if(!g)return;const y=Wl(a.current);(y.find(p=>p.getAttribute("aria-checked")==="true")??y[0])?.focus({preventScroll:!0})},[g]);const m=s.useRef(i);s.useLayoutEffect(()=>{m.current=i}),s.useEffect(()=>{const y=e.ownerDocument,p=y.defaultView;function f(w){const C=w.target;a.current?.contains(C)||e.contains(C)||m.current(!1)}function h(w){a.current?.contains(w.target)||m.current(!1)}function b(){m.current(!1)}return y.addEventListener("mousedown",f),p?.addEventListener("scroll",h,!0),p?.addEventListener("resize",b),()=>{y.removeEventListener("mousedown",f),p?.removeEventListener("scroll",h,!0),p?.removeEventListener("resize",b)}},[e]);const x=y=>{y.stopPropagation();const p=Wl(a.current),f=p.indexOf(y.target);let h=-1;switch(y.key){case"ArrowDown":h=f+1>=p.length?0:f+1;break;case"ArrowUp":h=f<=0?p.length-1:f-1;break;case"Home":h=0;break;case"End":h=p.length-1;break;case"Escape":case"Tab":y.preventDefault(),i(!0);return;default:return}y.preventDefault(),p[h]?.focus()};return st.createPortal(d.jsx("div",{ref:a,className:"ogx-column-menu ogx__header-filter-menu",style:c,role:"menu","aria-label":l.operatorMenuLabel(t),onKeyDown:x,children:n.map(y=>d.jsx("button",{type:"button",role:"menuitemradio","aria-checked":y===o,tabIndex:-1,className:`ogx-menu-item${y===o?" ogx-menu-item--active":""}`,onClick:()=>r(y),children:l.operator(y)},y))}),e.closest(".ogx-theme-provider")??e.ownerDocument.body)}function sg(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function ag(e,t){const n=Array.isArray(t)?t[0]:t;return Object.is(e.value,n)?!0:n!=null&&String(e.value).toLowerCase()===String(n).toLowerCase()}function Vl(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function zl(e,t){return Object.is(e,t)?!0:Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>zl(n,t[o])):!1}function Rl(e,t){return e===t?!0:!e||!t?!1:e.operator===t.operator&&zl(e.value,t.value)}function cg(){return d.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[d.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),d.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"})]})}function dg({colDef:e,state:t,style:n,className:o,ariaColIndex:r,onItemChange:i,onOpenFilterPanel:l,locale:a}){const c=e.headerName||e.field,u=t.kind==="editable"?t.item:void 0,g=u?.operator??Un(e),m=sg(e),x=e.type==="boolean"||e.type==="singleSelect"&&m.length>0,y=!Dt.has(g),[p,f]=s.useState(null),[h,b]=s.useState(null),[w,C]=s.useState(void 0),[E,S]=s.useState(u);if(E!==u){S(u);const R=w!==void 0&&Rl(w??void 0,u);!Rl(E,u)&&!R&&f(null)}const N=s.useRef(null),M=s.useRef(null),_=s.useRef(null),F=s.useRef(null),A=s.useRef(null),L=s.useRef({item:u,colDef:e,onItemChange:i});s.useLayoutEffect(()=>{L.current={item:u,colDef:e,onItemChange:i}});const k=s.useCallback(R=>{const{item:ue,colDef:q,onItemChange:te}=L.current;if(ue?R===_o(ue.value,q.type):R.trim()==="")return;const U=ue?.operator??Un(q),ce=or(q,U,Vl(R,U));C(ce),te(q.field,ce)},[]),I=s.useRef(null);s.useLayoutEffect(()=>{I.current=p}),s.useEffect(()=>()=>{const R=I.current;I.current=null,R!==null&&k(R)},[k]),s.useEffect(()=>{if(p===null)return;const R=setTimeout(()=>{I.current=null,k(p),f(null)},Yf);return()=>clearTimeout(R)},[p,k]);const P=()=>N.current?.focus({preventScroll:!0}),v=()=>(M.current??_.current)?.focus({preventScroll:!0}),B=R=>{C(R),i(e.field,R)},W=R=>{f(null),B(or(e,g,R))},J=()=>{f(null),B(null)},G=()=>{A.current&&b(A.current)},z=R=>{b(null),R&&(M.current||_.current?v():P())},H=R=>{const ue=p!==null?Vl(p,R):u?.value;f(null),b(null),B(or(e,R,Bl(ue,R))),requestAnimationFrame(()=>{M.current||_.current?v():P()})},re=t.kind==="custom",ee=!re&&y&&!x,de=R=>{const ue=R.currentTarget,q=R.target;if(!ue.contains(q)||R.nativeEvent.isComposing)return;const{key:te}=R,V=q===ue;if((R.altKey&&te==="ArrowDown"||(R.ctrlKey||R.metaKey)&&te==="Enter")&&!re&&q!==_.current){R.preventDefault(),R.stopPropagation(),G();return}if(!V){te==="Escape"&&(R.preventDefault(),R.stopPropagation(),P());return}if(te==="Enter"||te===" "||te==="Spacebar"){R.preventDefault(),R.stopPropagation(),re?F.current?.click():M.current||_.current?v():G();return}if((te==="Delete"||te==="Backspace")&&u){R.preventDefault(),R.stopPropagation(),J();return}ee&&e.type!=="date"&&te.length===1&&!R.ctrlKey&&!R.metaKey&&!R.altKey&&(R.preventDefault(),R.stopPropagation(),M.current?.focus({preventScroll:!0}),f(te))};let ie=null;if(re)ie=l?d.jsx("button",{ref:F,type:"button",className:"ogx__header-filter-custom",tabIndex:-1,onClick:l,title:a.customTooltip,children:a.custom}):d.jsx("span",{className:"ogx__header-filter-custom",title:a.customTooltip,children:a.custom});else{let R;if(!y)R=d.jsx("span",{className:"ogx__header-filter-operator-label",children:a.operator(g)});else if(e.type==="boolean")R=d.jsxs("select",{ref:_,className:"ogx__header-filter-select",tabIndex:-1,value:u?.value==null||u.value===""?"":String(u.value),onChange:q=>W(q.target.value===""?"":q.target.value==="true"),"aria-label":a.valueLabel(c),children:[d.jsx("option",{value:"",children:a.any}),d.jsx("option",{value:"true",children:a.yes}),d.jsx("option",{value:"false",children:a.no})]});else if(x){const q=m.find(te=>ag(te,u?.value));R=d.jsxs("select",{ref:_,className:"ogx__header-filter-select",tabIndex:-1,value:q?.key??"",onChange:te=>{const V=m.find(U=>U.key===te.target.value);W(Bl(V?V.value:"",g))},"aria-label":a.valueLabel(c),children:[d.jsx("option",{value:"",children:a.any}),m.map(te=>d.jsx("option",{value:te.key,children:te.label},te.key))]})}else R=d.jsx(et,{ref:M,className:"ogx__header-filter-input-wrapper",inputClassName:"ogx__header-filter-input",type:e.type==="date"?"date":"text",inputMode:e.type==="number"?"decimal":void 0,tabIndex:-1,autoComplete:"off",value:p??_o(u?.value,e.type),onChange:q=>f(q.target.value),"aria-label":a.valueLabel(c)});const ue=a.operator(g);ie=d.jsxs(d.Fragment,{children:[d.jsx("button",{ref:A,type:"button",className:`ogx__header-filter-operator${h?" ogx__header-filter-operator--open":""}`,tabIndex:-1,"aria-haspopup":"menu","aria-expanded":h!==null,"aria-label":a.operatorButtonLabel(c,ue),title:ue,onClick:()=>h?b(null):G(),children:ng[g]??"?"}),R,u&&d.jsx("button",{type:"button",className:"ogx__header-filter-clear",tabIndex:-1,"aria-label":a.clearLabel(c),title:a.clearTooltip,onClick:()=>{J(),P()},children:d.jsx(cg,{})}),h&&d.jsx(lg,{anchorEl:h,columnLabel:c,locale:a,operators:Qf(e),current:g,onSelect:H,onClose:z})]})}const ae=["ogx__header-filter-cell",u&&"ogx__header-filter-cell--active",re&&"ogx__header-filter-cell--custom",o].filter(Boolean).join(" ");return d.jsx("div",{ref:N,className:ae,style:n,role:"columnheader","aria-label":a.cellLabel(c),"aria-colindex":r,"data-field":e.field,tabIndex:-1,onKeyDown:de,children:ie})}function rr({field:e,ariaColIndex:t,sticky:n,left:o,focused:r}){return d.jsx("div",{className:["ogx__header-filter-cell","ogx__header-filter-cell--system",n&&"ogx__header-filter-cell--pinned ogx__header-filter-cell--pinned-left",r&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" "),style:{width:He,minWidth:He,maxWidth:He,position:n?"sticky":void 0,insetInlineStart:n?o:void 0},role:"columnheader","aria-colindex":t,"data-field":e,tabIndex:-1})}function ug(e){const{columns:t,columnWidths:n,pinnedColumns:o,pinnedPositions:r,pinnedEdges:i,rowReordering:l,hasDetailPanel:a,checkboxSelection:c,pinExpandColumn:u,pinCheckboxColumn:g,columnIndexMap:m,ariaRowIndex:x,filterModel:y,onFilterModelChange:p,onOpenFilterPanel:f,focusedField:h,localeText:b}=e,w=s.useRef({filterModel:y,onFilterModelChange:p});s.useLayoutEffect(()=>{w.current={filterModel:y,onFilterModelChange:p}});const C=s.useCallback((L,k)=>{const{filterModel:I,onFilterModelChange:P}=w.current;if(!P)return;const v=tg(I,L,k);v!==I&&(w.current={filterModel:v,onFilterModelChange:P},P(v))},[]),E=rg(b),S=l?1:0,N=a?S+1:S,M=c?N+1:N,_=M,F=l?He:0,A=F+(a&&u?He:0);return d.jsxs("div",{className:"ogx__header-filter-row",role:"row","aria-rowindex":x,children:[l&&d.jsx(rr,{field:vt,ariaColIndex:S,sticky:!0,left:0,focused:h===vt}),a&&d.jsx(rr,{field:St,ariaColIndex:N,sticky:u,left:F,focused:h===St}),c&&d.jsx(rr,{field:Ye,ariaColIndex:M,sticky:g,left:A,focused:h===Ye}),t.map((L,k)=>{if(L.isSpacer)return d.jsx("div",{style:{width:L.width,minWidth:L.width,flexShrink:0},"aria-hidden":"true"},L.field);const I=tt(L.field,o),P=Dl(L,n,I,I?r[L.field]:void 0),v=_+(m?.get(L.field)??k)+1,B=[I&&"ogx__header-filter-cell--pinned",I&&`ogx__header-filter-cell--pinned-${I}`,I==="left"&&L.field===i.lastLeft&&"ogx__header-filter-cell--pinned-left-last",I==="right"&&L.field===i.firstRight&&"ogx__header-filter-cell--pinned-right-first",h===L.field&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" ");return Zf(L)?d.jsx(dg,{colDef:L,state:Hl(y,L.field),style:P,className:B,ariaColIndex:v,onItemChange:C,onOpenFilterPanel:f,locale:E},L.field):d.jsx("div",{className:`ogx__header-filter-cell ogx__header-filter-cell--empty ${B}`,style:P,role:"columnheader","aria-label":`No filter for ${L.headerName||L.field}`,"aria-colindex":v,"data-field":L.field,tabIndex:-1},L.field)})]})}function fg(){return d.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"18",height:"18",children:d.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 gg(){return d.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor",children:d.jsx("path",{d:"M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"})})}function Kl(e){const{columns:t,allColumns:n,columnGroupingModel:o,checkboxSelection:r=!1,allSelected:i=!1,someSelected:l=!1,onSelectAll:a,onSort:c,sortModel:u=[],onColumnResize:g,onColumnAutosize:m,columnWidths:x={},pinnedColumns:y,hasDetailPanel:p=!1,pinCheckboxColumn:f=!0,pinExpandColumn:h=!0,rowReordering:b=!1,aggregationModel:w,draggedColumn:C,dragOverColumn:E,onDragStart:S,onDragOver:N,onDragEnd:M,onDrop:_,focusedCell:F,onHeaderClick:A,onSortAdd:L,multiSort:k=!1,onHideColumn:I,onPinColumn:P,onManageColumns:v,columnIndexMap:B,wrapHeaderText:W=!1,headerHeight:J=56,headerFilters:G=!1,filterModel:z,onFilterModelChange:H,onOpenFilterPanel:re,localeText:ee}=e,de=s.useId(),[ie,ae]=s.useState(null),R=K=>fe=>{fe.stopPropagation(),ae({colDef:K,anchorEl:fe.currentTarget})},ue=s.useCallback(()=>{ae(null)},[]),q=K=>fe=>{if(fe.altKey&&(fe.key==="ArrowLeft"||fe.key==="ArrowRight")&&fe.target===fe.currentTarget){if(K.resizable===!1||!g)return;fe.preventDefault(),fe.stopPropagation();const Ce=yt(K,x),se=Mn(fe.key,Xe(fe.currentTarget)),ye=(fe.shiftKey?50:10)*(se==="ArrowRight"?1:-1);g(K.field,Jo(Ce+ye,Ce,K.minWidth,K.maxWidth));return}if(!(fe.altKey&&fe.key==="ArrowDown"||(fe.ctrlKey||fe.metaKey)&&fe.key==="Enter")||K.disableColumnMenu||fe.target!==fe.currentTarget)return;fe.preventDefault(),fe.stopPropagation();const xe=fe.currentTarget.querySelector(".ogx__menu-icon-btn")??fe.currentTarget;ae({colDef:K,anchorEl:xe})},te=K=>F?.id===null&&!F.headerFilter&&F.field===K,V=b?1:0,U=p?V+1:V,ce=r?U+1:U,ge=K=>fe=>{if(K.sortable===!1)return;const we=u.find(xe=>xe.field===K.field);let le="asc";we&&(we.sort==="asc"?le="desc":le=null),(fe.shiftKey||k)&&L?L(K.field,le):c&&c(K.field,le)},Q=(K,fe)=>{const we=u.some(xe=>xe.field===K);L&&(fe===null||we||k||!c)?L(K,fe):c?.(K,fe)},D=K=>{const fe=u.find(le=>le.field===K);if(!fe)return null;const we=u.length>1?u.indexOf(fe)+1:null;return d.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${fe.sort}`,"aria-hidden":"true",children:we!==null&&d.jsx("span",{className:"ogx__sort-badge",children:we})})},T=s.useMemo(()=>ao(t,x,y,r,f,p,h,b),[t,x,y,r,f,p,h,b]),$=s.useMemo(()=>co(t,y),[t,y]),O=Qi(o),Z=s.useMemo(()=>el(o),[o]),j=s.useMemo(()=>O===0?[]:(n??t).map(K=>({field:K.field,width:yt(K,x),flex:K.isSpacer?0:K.flex,pinned:K.isSpacer?null:tt(K.field,y),isSpacer:K.isSpacer})),[O,n,t,x,y]),oe=(b?48:0)+(p?48:0)+(r?48:0),he=(b||p||r)&&(!p||h)&&(!r||f),me=(b?1:0)+(p?1:0)+(r?1:0);return d.jsxs("div",{className:"ogx__header-wrap",children:[O>0&&Array.from({length:O},(K,fe)=>{const we=Sd(j,Z,fe);return d.jsxs("div",{className:"ogx-col-group-row",role:"row","aria-rowindex":fe+1,children:[oe>0&&d.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${he?" ogx-col-group-cell--pinned ogx-col-group-cell--pinned-left":""}`,style:{width:oe,minWidth:oe,flexShrink:0,position:he?"sticky":void 0,insetInlineStart:he?0:void 0},"aria-hidden":"true"}),we.map((le,xe)=>{const Ce=le.pinned?` ogx-col-group-cell--pinned ogx-col-group-cell--pinned-${le.pinned}`:"",se={width:le.width,minWidth:le.width,flexShrink:0,flexGrow:le.flexGrow};return le.pinned==="left"?(se.position="sticky",se.insetInlineStart=T[le.fields[0]]):le.pinned==="right"&&(se.position="sticky",se.insetInlineEnd=T[le.fields[le.fields.length-1]],we[xe-1]?.pinned!=="right"&&(se.marginInlineStart="auto")),le.isGroup?d.jsx("div",{role:"columnheader","aria-colspan":le.fields.length,"aria-colindex":me+le.firstDataIndex+1,className:`ogx-col-group-cell ogx-col-group-cell--group${Ce}${le.headerClassName?` ${le.headerClassName}`:""}`,style:se,title:le.label,children:d.jsx("span",{className:"ogx-col-group-cell__label",children:le.label})},le.key):d.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${Ce}`,style:se,"aria-hidden":"true"},le.key)})]},`ogx-grp-${fe}`)}),d.jsxs("div",{className:"ogx__header",role:"row","aria-rowindex":O+1,children:[b&&d.jsx("div",{className:`ogx__header-cell ogx__header-cell--pinned ogx__header-cell--pinned-left ${te("__reorder_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Row reorder handle","aria-colindex":V,"data-field":"__reorder_col__",tabIndex:-1,title:"Drag to reorder rows",style:{minWidth:48,maxWidth:48,position:"sticky",insetInlineStart:0}}),p&&d.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${h?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${te("__expand_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Expand row details","aria-colindex":U,"data-field":"__expand_col__",tabIndex:-1,style:{minWidth:48,maxWidth:48,position:h?"sticky":void 0,insetInlineStart:h?b?48:0:void 0}}),r&&d.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${f?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${te("__checkbox_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-colindex":ce,"data-field":"__checkbox_col__",style:{position:f?"sticky":void 0,insetInlineStart:f?(b?48:0)+(p&&h?48:0):void 0},children:a&&d.jsx(ft,{id:de,name:de,checked:i,indeterminate:l,onChange:K=>a(K.target.checked),"aria-label":i?"Deselect all rows":"Select all rows",tabIndex:-1,onMouseDown:K=>K.preventDefault()})}),t.map((K,fe)=>{if(K.isSpacer)return d.jsx("div",{style:{width:K.width,minWidth:K.width,flexShrink:0},"aria-hidden":"true"},K.field);const we=K.sortable!==!1,le=u.findIndex(Be=>Be.field===K.field),xe=le!==-1,Ce=xe?u[le].sort:null,se=B?.get(K.field)??fe,ye=we?le===0?Ce==="asc"?"ascending":"descending":"none":void 0,ke=xe&&u.length>1?`Sorted ${Ce==="asc"?"ascending":"descending"}, sort priority ${le+1} of ${u.length}`:void 0,De=K.resizable!==!1,Ne=tt(K.field,y),Ie=Ne!==null,Ee=C===K.field,Pe=E===K.field,pe=jf(K.wrapHeaderText,W),ve=w?.[K.field],Se=["ogx__header-cell",`ogx__header-cell--align-${K.headerAlign||K.align||"left"}`,we&&"ogx__header-cell--sortable",xe&&"ogx__header-cell--sorted",Ie&&"ogx__header-cell--pinned",Ie&&`ogx__header-cell--pinned-${Ne}`,Ne==="left"&&K.field===$.lastLeft&&"ogx__header-cell--pinned-left-last",Ne==="right"&&K.field===$.firstRight&&"ogx__header-cell--pinned-right-first",Ee&&"ogx__header-cell--dragging",Pe&&"ogx__header-cell--drag-over",pe&&"ogx__header-cell--wrap",te(K.field)&&"ogx__header-cell--focused",K.headerClassName].filter(Boolean).join(" "),be={...Dl(K,x,Ne,Ne?T[K.field]:void 0),zIndex:K.zIndex,opacity:Ee?.5:1},Le=K.renderHeader?K.renderHeader({field:K.field,colDef:K,colIndex:se}):K.headerName||K.field,Ue=Be=>{if(Be.target.closest(".ogx-column-resize-handle")){Be.stopPropagation();return}A?.(K.field),we&&ge(K)(Be)},je=S&&!Ie?S(K.field):void 0,Nt=N&&!Ie?N(K.field):void 0,pt=_&&!Ie?_(K.field):void 0;return d.jsxs("div",{className:Se,style:be,title:K.description??(pe&&typeof Le=="string"?Le:void 0),onClick:Ue,role:"columnheader",draggable:!!je,onDragStart:je,onDragOver:Nt,onDragEnd:M,onDrop:pt,onKeyDown:q(K),"aria-sort":ye,"aria-description":ke,"aria-colindex":me+se+1,"data-field":K.field,tabIndex:-1,children:[d.jsxs("div",{className:"ogx__header-cell-content",children:[Ee&&d.jsx("div",{className:"ogx__header-drag-icon",children:d.jsx(gg,{})}),d.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[d.jsx("span",{className:"ogx__header-cell-title",style:pe?{WebkitLineClamp:Uf(J,!!ve)}:void 0,children:Le}),ve&&d.jsx("span",{className:"ogx__header-cell-aggregation",children:ve})]}),we&&D(K.field),!K.disableColumnMenu&&d.jsx("button",{type:"button",className:"ogx__menu-icon-btn",onClick:R(K),"aria-label":`Open column menu for ${K.headerName||K.field}`,"aria-haspopup":"menu",tabIndex:-1,children:d.jsx(fg,{})})]}),De&&g&&d.jsx(Ff,{field:K.field,currentWidth:yt(K,x),onResize:g,onAutosize:m,minWidth:K.minWidth,maxWidth:K.maxWidth,edge:Ne==="right"?"start":"end"})]},K.field)}),ie&&d.jsx(zf,{colDef:ie.colDef,sortModel:u,onSort:c||L?Q:void 0,onHide:I,onPin:P,pinnedColumns:y,onManageColumns:v,onClose:ue,anchorEl:ie.anchorEl})]}),G&&d.jsx(ug,{columns:t,columnWidths:x,pinnedColumns:y,pinnedPositions:T,pinnedEdges:$,rowReordering:b,hasDetailPanel:p,checkboxSelection:r,pinExpandColumn:h,pinCheckboxColumn:f,columnIndexMap:B,ariaRowIndex:O+2,filterModel:z,onFilterModelChange:H,onOpenFilterPanel:re,localeText:ee,focusedField:F?.id===null&&F.headerFilter?F.field:null})]})}function un(e){return e.headerName||e.field}function pg(e){return e.nativeEvent.isComposing||e.keyCode===229}function fn(e,t,n=!0){return o=>{if(pg(o)){o.stopPropagation();return}n&&o.key==="Enter"&&(o.stopPropagation(),e()),o.key==="Escape"&&(o.stopPropagation(),t())}}function hg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(String(e??"")),a=s.useRef(null);return s.useEffect(()=>{a.current?.focus(),a.current?.select()},[]),d.jsx(et,{ref:a,variant:"cell",type:"text",inputClassName:"ogx__edit-input","aria-label":un(t),value:i,onChange:c=>{l(c.target.value),n(c.target.value)},onBlur:o,onKeyDown:fn(o,r)})}function mg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(typeof e=="number"?e:""),a=s.useRef(null);return s.useEffect(()=>{a.current?.focus(),a.current?.select()},[]),d.jsx(et,{ref:a,variant:"cell",type:"number",inputClassName:"ogx__edit-input ogx__edit-input--number","aria-label":un(t),value:i,onChange:c=>{const u=c.target.value===""?"":Number(c.target.value);l(u),n(u===""?null:u)},onBlur:o,onKeyDown:fn(o,r)})}function wg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=()=>{n(!e),o()};return d.jsx("div",{className:"ogx__edit-boolean",onMouseDown:a=>a.preventDefault(),children:d.jsx(ft,{ref:i,inputClassName:"ogx__edit-checkbox","aria-label":un(t),checked:!!e,onChange:l,onMouseDown:a=>a.preventDefault(),onBlur:o,onKeyDown:fn(o,r,!1)})})}const ir=e=>typeof e=="object"?e.value:e,bg=e=>typeof e=="object"?e.label:String(e);function xg(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function yg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=t.valueOptions??[],a=l.map(g=>String(ir(g)));let c=l.findIndex(g=>xg(ir(g),e));c===-1&&e!==null&&e!==void 0&&(c=a.indexOf(String(e)));const u=c===-1;return d.jsxs("select",{ref:i,className:"ogx__edit-select","aria-label":un(t),value:u?"":a[c],onChange:g=>{const m=a.indexOf(g.target.value);n(m===-1?null:ir(l[m]))},onBlur:o,onKeyDown:fn(o,r),children:[u&&d.jsx("option",{value:""}),l.map((g,m)=>d.jsx("option",{value:a[m],children:bg(g)},m))]})}const Ul=e=>String(e).padStart(2,"0"),jl=/^(\d{4}-\d{2}-\d{2})/;function lr(e){if(e instanceof Date)return Number.isNaN(e.getTime())?"":`${e.getFullYear()}-${Ul(e.getMonth()+1)}-${Ul(e.getDate())}`;if(typeof e=="string"){const t=jl.exec(e);return t?t[1]:e===""?"":lr(new Date(e))}return typeof e=="number"?lr(new Date(e)):""}function Cg(e,t){if(e==="")return null;const[n,o,r]=e.split("-").map(Number),i=l=>{const a=new Date(l.getTime());return a.setFullYear(n,o-1,r),a};return t instanceof Date&&!Number.isNaN(t.getTime())?i(t):typeof t=="number"&&Number.isFinite(t)?i(new Date(t)).getTime():typeof t=="string"&&jl.test(t)&&t.length>10?e+t.slice(10):e}function vg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i]=s.useState(e),[l,a]=s.useState(()=>lr(e)),c=s.useRef(null);return s.useEffect(()=>{c.current?.focus()},[]),d.jsx(et,{ref:c,variant:"cell",type:"date",inputClassName:"ogx__edit-input","aria-label":un(t),value:l,onChange:u=>{a(u.target.value),n(Cg(u.target.value,i))},onBlur:o,onKeyDown:fn(o,r)})}function Sg(e){const{colDef:t}=e;switch(t.type){case"number":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(mg,{...e})});case"boolean":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(wg,{...e})});case"singleSelect":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(yg,{...e})});case"date":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(vg,{...e})});default:return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(hg,{...e})})}}function _g(e){const{onCellClick:t,onCellEditStart:n,onCellValueChange:o,value:r,row:i,colDef:l,rowIndex:a,colIndex:c,ariaColIndex:u,isSelected:g,onClick:m,width:x,pinnedPosition:y,pinnedOffset:p,isPinnedEdge:f,isFocused:h,isFocusVisible:b,isEditable:w,isEditing:C,onEditStart:E,onEditStop:S,onValueChange:N,colSpanInfo:M,rowSpan:_,isHiddenByRowSpan:F,rowMeta:A,valueError:L,rangeFlags:k=0}=e,I=s.useCallback(Q=>{o?o(l.field,Q):N?.(Q)},[o,N,l.field]),P=A?.isGroupRow===!0,{formattedValue:v,error:B}=s.useMemo(()=>{const Q=l.valueFormatter;if(Q&&!(P&&r==null)){const D=We(()=>Q({value:r,row:i,field:l.field}));return D.ok?{formattedValue:D.value}:{formattedValue:"",error:D.error??new Error("valueFormatter failed")}}return{formattedValue:En(r,l)}},[r,i,l,P]),W=s.useMemo(()=>{if(!l.cellClassName)return"";const Q=l.cellClassName;if(typeof Q=="function"){const D=We(()=>Q({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:a,colIndex:c,rowMeta:A}));return D.ok&&D.value||""}return l.cellClassName},[l,r,v,i,a,c,A]),J=L??B,G=l.field,z=s.useCallback(()=>{S?.(!1,G)},[S,G]),H=s.useCallback(()=>{S?.(!0,G)},[S,G]),re=s.useMemo(()=>[i,l.renderCell,r],[i,l.renderCell,r]),ee=s.useRef(!1);if(s.useEffect(()=>{if(!(!C||!S))return ee.current=!0,()=>{ee.current=!1,queueMicrotask(()=>{ee.current||S(!1,G)})}},[C,S,G]),M?.spannedByColSpan)return null;const de=M?.cellProps.colSpan??1,ie=de>1,ae=(ie?M?.cellProps.width:void 0)??x??l.width??100,R={width:"var(--width)","--width":typeof ae=="number"?`${ae}px`:ae,flexGrow:(ie?M?.cellProps.flexGrow:void 0)??l.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",minWidth:ie?void 0:l.minWidth,maxWidth:ie?void 0:l.maxWidth};if(F)return d.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:R,role:"presentation","data-field":l.field,"data-colindex":c});const ue=Q=>{C||(t&&t({row:i,field:l.field,value:r,colDef:l,rowIndex:a,colIndex:c}),m?.(Q))},q=()=>{C||!w||(n?n(l.field,r):E?.())},te=l.renderEditCell,V=y!=null,U=["ogx__cell",`ogx__cell--align-${l.align||"left"}`,g&&"ogx__cell--selected",h&&"ogx__cell--focused",h&&b&&"ogx__cell--focus-visible",l.type&&`ogx__cell--type-${l.type}`,V&&"ogx__cell--pinned",V&&`ogx__cell--pinned-${y}`,V&&f&&`ogx__cell--pinned-${y}-${y==="left"?"last":"first"}`,C&&"ogx__cell--editing",_&&_>1&&"ogx__cell--spanned",(k&To)!==0&&"ogx__cell--range",(k&Si)!==0&&"ogx__cell--range-top",(k&_i)!==0&&"ogx__cell--range-bottom",(k&ki)!==0&&"ogx__cell--range-left",(k&Ei)!==0&&"ogx__cell--range-right",W].filter(Boolean).join(" "),ce=_||1,ge={...R,position:V?"sticky":void 0,zIndex:l.zIndex??(V?3:void 0),padding:C?0:void 0};return ce>1&&(ge.height=`calc(var(--height) * ${ce} - var(--border-width, 1px))`,ge.zIndex=10,V&&(ge.zIndex=40)),V&&p!==void 0&&(y==="left"?ge.insetInlineStart=p:ge.insetInlineEnd=p),d.jsxs("div",{className:U,style:ge,onClick:ue,onDoubleClick:q,role:"gridcell","aria-colindex":u??c+1,"aria-readonly":!w||void 0,tabIndex:-1,"data-field":l.field,"data-colindex":c,...de>1?{"aria-colspan":de}:{},...ce>1?{"aria-rowspan":ce}:{},...(k&To)!==0?{"aria-selected":!0}:{},children:[d.jsx("div",{className:"ogx__cell-content",children:C&&(o||N)&&S?te?d.jsx(kt,{field:l.field,resetKey:i,renderFn:()=>te({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:a,colIndex:c,rowMeta:A,onValueChange:I,onCommit:z,onCancel:H})}):d.jsx(Sg,{value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:a,colIndex:c,rowMeta:A,onValueChange:I,onCommit:z,onCancel:H}):J!==void 0?d.jsx(kt,{field:l.field,resetKey:i,renderFn:()=>{throw J}}):l.renderCell?d.jsx(kt,{field:l.field,resetKey:re,renderFn:()=>l.renderCell({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:a,colIndex:c,rowMeta:A})}):l.type==="image"&&typeof r=="string"&&r!==""?d.jsx("img",{className:"ogx__cell-image",src:r,alt:l.headerName??l.field,loading:"lazy"}):v}),(k&Mi)!==0&&!C&&d.jsx("div",{className:"ogx__cell-fill-handle","aria-hidden":"true"})]})}const ql=s.memo(_g),kg=({className:e="",...t})=>d.jsx("button",{type:"button",className:`ogx-drag-handle ${e}`,"aria-label":"Drag to reorder row",...t,children:d.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:d.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 Eg(e){const{rowId:t,content:n,height:o,isExpanded:r,onHeightChange:i,id:l,colSpan:a}=e,c=s.useRef(null),u=o==="auto";if(s.useLayoutEffect(()=>{const m=c.current;if(!m||!u||!r||!i)return;const x=()=>{m.getClientRects().length!==0&&i(t,m.offsetHeight)};if(x(),typeof ResizeObserver>"u")return;const y=new ResizeObserver(x);return y.observe(m),()=>y.disconnect()},[u,r,i,t]),!r)return null;const g={height:u?"auto":`${o}px`,overflow:u?"visible":"auto"};return d.jsx("div",{ref:c,className:"ogx__detail-panel",style:g,role:"row",id:l,children:d.jsx("div",{className:"ogx__detail-panel-content",role:"gridcell","aria-colspan":a,children:n})})}const sr=12;function Mg(e,t,n,o){let r=0,i=0,l=0;for(let a=t;a<e.length&&l<n;a++){const c=e[a];if(c.isSpacer)break;r+=yt(c,o),i+=c.flex??0,l++}return{spannedByColSpan:!1,cellProps:{colSpan:l,width:r,flexGrow:i}}}function Ng(e){const{row:t,rowId:n,columns:o,rowIndex:r,isSelected:i=!1,checkboxSelection:l=!1,onRowClick:a,onRowDoubleClick:c,onCellClick:u,onSelectionChange:g,columnWidths:m={},pinnedColumns:x,pinnedRows:y,hasDetailPanel:p=!1,isDetailPanelExpanded:f=!1,onDetailPanelToggle:h,detailPanelContent:b,detailPanelHeight:w=go,onDetailPanelHeightChange:C,pinCheckboxColumn:E=!0,pinExpandColumn:S=!0,rowReordering:N=!1,onDragStart:M,onDragOver:_,onDragEnd:F,onDrop:A,isDragging:L,isDragOver:k,editingCell:I,onEditStart:P,onEditStop:v,onEditCellValueChange:B,isCellEditable:W,focusedCellField:J,isFocusVisible:G,colspanMap:z,rowSpanningCaches:H,rowHeight:re=52,rowMeta:ee,columnIndexMap:de,ariaRowIndex:ie,cellRange:ae}=e,R=n??t.id,ue=s.useId(),q=s.useId(),te=s.useMemo(()=>ao(o,m,x,l,E,p,S,N),[o,m,x,l,E,p,S,N]),V=s.useMemo(()=>co(o,x),[o,x]),U=ee?.hasChildren===!0,ce=ee?.isGroupRow===!0,ge=p&&!ce,Q=!ce&&!Re(R),D=s.useCallback((se,ye)=>{P?.({id:R,field:se,value:ye})},[R,P]),T=s.useCallback((se,ye)=>{B?.({id:R,field:se,value:ye})},[B,R]),$=s.useCallback((se,ye)=>{v?.({cancel:se,id:R,field:ye})},[v,R]);if(t._isSkeleton){const se=Math.max(o.length,5);return d.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:re,minHeight:re},children:Array.from({length:se}).map((ye,ke)=>d.jsx("div",{className:"ogx__skeleton-cell",children:d.jsx("div",{className:"ogx__skeleton-bar"})},ke))})}const O=se=>{se.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||a?.({row:t,id:R,rowIndex:r})},Z=se=>{se.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||c?.({row:t,id:R,rowIndex:r})},j=se=>{se.stopPropagation(),g?.(R,se.target.checked)},ne=se=>{se.stopPropagation(),h?.(R)},X=N?1:0,Y=p?X+1:X,oe=l?Y+1:Y,he=oe,me=de?.size??o.filter(se=>!se.isSpacer).length,K=ee!==void 0,fe=ee?.hasChildren===!0,we=Dr(R,y),le=we==="top",xe=we==="bottom",Ce=["ogx__row",i&&"ogx__row--selected",r%2===0&&"ogx__row--even",r%2===1&&"ogx__row--odd",le&&"ogx__row--pinned-top",xe&&"ogx__row--pinned-bottom",L&&"ogx__row--dragging",k&&"ogx__row--drag-over",U&&"ogx__row--group",ee?.isGroupFooter&&"ogx__row--group-footer"].filter(Boolean).join(" ");return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:Ce,onClick:O,onDoubleClick:c?Z:void 0,role:"row","aria-rowindex":ie??r+2,"aria-selected":i,"aria-level":K?(ee?.treeDepth??0)+1:void 0,"aria-expanded":fe?ee?.isExpanded===!0:void 0,"data-rowindex":r,onDragOver:_?_(R):void 0,onDrop:A?A(R):void 0,style:{maxHeight:`${re}px`,minHeight:`${re}px`,"--height":`${re}px`,"--border-width":"1px"},children:[N&&d.jsx("div",{className:`ogx__cell ogx__cell--drag-handle ${J==="__reorder_col__"?"ogx__cell--focused":""} ${J==="__reorder_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":M?"Drag to reorder row":void 0,"aria-colindex":X,"data-field":"__reorder_col__",tabIndex:-1,style:{position:"sticky",insetInlineStart:0,zIndex:sr},draggable:!!M,onDragStart:M?M(R):void 0,onDragEnd:F,onClick:se=>se.stopPropagation(),children:M&&d.jsx(kg,{})}),p&&d.jsx("div",{className:`ogx__cell ogx__cell--expand ${S?"ogx__cell--pinned-left":""} ${J==="__expand_col__"?"ogx__cell--focused":""} ${J==="__expand_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":ge?f?"Collapse row details":"Expand row details":void 0,"aria-expanded":ge?f:void 0,"aria-controls":ge&&f?q:void 0,"aria-colindex":Y,"data-field":"__expand_col__",style:{position:S?"sticky":void 0,insetInlineStart:S?N?48:0:void 0,zIndex:S?sr:void 0},tabIndex:-1,onClick:se=>{se.stopPropagation(),u?.({row:t,field:"__expand_col__",value:f,colDef:{field:"__expand_col__",width:48},rowIndex:r,colIndex:-1})},children:ge&&d.jsx(Ho,{isExpanded:f,onClick:ne,variant:"plus-minus",tabIndex:-1})}),l&&d.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${E?"ogx__cell--pinned-left":""} ${J==="__checkbox_col__"?"ogx__cell--focused":""} ${J==="__checkbox_col__"&&G?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-colindex":oe,"data-field":"__checkbox_col__",style:{position:E?"sticky":void 0,insetInlineStart:E?(N?48:0)+(p&&S?48:0):void 0,zIndex:E?sr:void 0},tabIndex:-1,onClick:se=>{se.stopPropagation(),u?.({row:t,field:"__checkbox_col__",value:i,colDef:{field:"__checkbox_col__",width:48},rowIndex:r,colIndex:-1})},children:Q&&d.jsx(ft,{id:ue,name:`ogx-select-row-${R}`,checked:i,onChange:j,onClick:se=>se.stopPropagation(),"aria-label":i?`Deselect row ${R}`:`Select row ${R}`,tabIndex:-1,onMouseDown:se=>se.preventDefault()})}),o.map((se,ye)=>{if(se.isSpacer)return d.jsx("div",{style:{width:se.width,minWidth:se.width,flexShrink:0},"aria-hidden":"true"},se.field);let ke,De;ce?ke=t[se.field]:{value:ke,error:De}=Gr(t,se.field,se);const Ne=de?.get(se.field)??ye,Ie=m[se.field]??se.width,Ee=tt(se.field,x),Pe=!!P&&wo({row:t,field:se.field,value:ke,colDef:se,rowIndex:r,colIndex:Ne,rowMeta:ee},W),pe=I?.id===R&&I?.field===se.field,ve=pe?I?.value:ke,Se=z?.get(R)?.[se.field],be=Se&&!Se.spannedByColSpan&&Se.cellProps.colSpan>1?Mg(o,Ne,Se.cellProps.colSpan,m):Se,Le=be&&!be.spannedByColSpan?o[Ne+be.cellProps.colSpan-1]?.field??se.field:se.field,Ue=Ee==="right"?Le:se.field,je=Ee?te[Ue]:void 0,Nt=Ee==="left"&&Le===V.lastLeft||Ee==="right"&&se.field===V.firstRight,pt=H?.spannedCells[R]?.[se.field],Be=H?.hiddenCells[R]?.[se.field]||!1,gr=ae&&!Be&&se.field!==Ci?rc(ae,Ne,be&&!be.spannedByColSpan?be.cellProps.colSpan:1,pt??1):void 0;return d.jsx(ql,{value:ve,row:t,colDef:se,rowIndex:r,colIndex:Ne,ariaColIndex:he+Ne+1,isSelected:i,onCellClick:u,width:Ie,pinnedPosition:Ee,pinnedOffset:je,isPinnedEdge:Nt,isFocused:J===se.field,isFocusVisible:G,isEditable:Pe,isEditing:pe,onCellEditStart:D,onEditStop:$,onCellValueChange:T,colSpanInfo:be,rowSpan:pt,isHiddenByRowSpan:Be,rowMeta:ee,valueError:De,rangeFlags:gr},se.field)})]}),ge&&d.jsx(Eg,{id:q,colSpan:he+me,row:t,rowId:R,rowIndex:r,content:b,height:w,isExpanded:f,onHeightChange:C})]})}function Ig(e,t){const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(o==="cellRange"){if(!oc(e.cellRange,t.cellRange))return!1}else if(!Object.is(e[o],t[o]))return!1;return!0}const jn=s.memo(Ng,Ig);function Xl({getContent:e,params:t}){return d.jsx(kt,{field:"detail panel",renderFn:()=>e(t),resetKey:t.row})}const Lg=e=>e.id;function Yl({rows:e,position:t,columns:n,selectedRowIds:o,checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:a,onSelectionChange:c,columnWidths:u,pinnedColumns:g,pinnedRows:m,hasDetailPanel:x,expandedRowIds:y,getDetailPanelContent:p,getDetailPanelHeight:f,onDetailPanelToggle:h,onDetailPanelHeightChange:b,pinCheckboxColumn:w,pinExpandColumn:C,focusedCell:E,colspanMap:S,rowSpanningCaches:N,rowHeight:M,rowMetaMap:_,getRowId:F=Lg,rowIndexOffset:A=0,ariaRowIndexBase:L,columnIndexMap:k,editingHandlers:I,isCellEditable:P,rowReordering:v=!1,cellRange:B,cellRangeHasRowSpan:W=!1,fillHandle:J}){return e.length===0?null:d.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:e.map((G,z)=>{const H=F(G),re=A+z;return d.jsx(jn,{row:G,rowId:H,columns:n,rowIndex:re,ariaRowIndex:L!==void 0?L+z:void 0,columnIndexMap:k,isSelected:o.has(H),checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:a,onSelectionChange:c,columnWidths:u,pinnedColumns:g,pinnedRows:m,hasDetailPanel:x,isDetailPanelExpanded:y.has(H),detailPanelContent:y.has(H)&&p?d.jsx(Xl,{getContent:p,params:{row:G,id:H,rowIndex:re}}):null,detailPanelHeight:y.has(H)?po(ho(f,{row:G,id:H,rowIndex:re})):void 0,onDetailPanelHeightChange:b,onDetailPanelToggle:h,pinCheckboxColumn:w,pinExpandColumn:C,focusedCellField:E?.id===H?E.field:null,colspanMap:S,rowSpanningCaches:N,rowHeight:M,rowMeta:_.get(H),editingCell:I?.editingCell,onEditStart:I?.startCellEdit,onEditStop:I?.stopCellEdit,onEditCellValueChange:I?.setEditCellValue,isCellEditable:P,rowReordering:v,cellRange:vi(B,re,W,J)},H)})})}const Ag=({columns:e,rowHeight:t,checkboxSelection:n=!1,hasDetailPanel:o=!1,rowReordering:r=!1})=>d.jsxs("div",{className:"ogx__row ogx__skeleton-row",style:{height:t},role:"row",children:[n&&d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:d.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),o&&d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:d.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),r&&d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:d.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),e.map((i,l)=>{const a=typeof i.width=="number"?i.width:150,c=Math.min(a*.7,a-20);return d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:a,minWidth:i.minWidth,maxWidth:i.maxWidth,insetInlineStart:i.left,insetInlineEnd:i.right,position:i.isSpacer?"relative":i.pinned?"sticky":"relative",zIndex:i.zIndex},children:!i.isSpacer&&d.jsx("div",{className:"ogx-skeleton-box",style:{width:c,height:16,borderRadius:4}})},i.field||l)})]});function Pg({virtualContainerHeight:e,offsetTop:t,effectiveLoading:n,visibleRows:o,baseColumns:r,virtualColumns:i,viewportWidth:l,checkboxSelection:a,hasDetailPanel:c,rowReordering:u,rowHeight:g,selectedRowIds:m,onRowClick:x,onRowDoubleClick:y,onCellClick:p,onSelectionChange:f,columnWidths:h,pinnedColumns:b,expandedRowIds:w,getDetailPanelContent:C,getDetailPanelHeight:E,onDetailPanelToggle:S,onDetailPanelHeightChange:N,pinCheckboxColumn:M,pinExpandColumn:_,rowReorderHandlers:F,editingHandlers:A,isCellEditable:L,focusedCell:k,colspanMap:I,rowSpanningCaches:P,paginationMode:v,dataSourceLoading:B,sortedUnpinnedRowCount:W,infiniteScrollSkeletonCount:J,unpinnedRowsLength:G,lastRenderedRowIndex:z,rowMetaMap:H,loadingOverlay:re,ariaRowIndexOffset:ee,columnIndexMap:de,cellRange:ie,cellRangeHasRowSpan:ae=!1,fillHandle:R}){const ue=r.length>0?r:(()=>{const V=(l||1e3)-(a?48:0)-(c?48:0)-(u?48:0),U=150,ce=Math.max(1,Math.ceil(V/U));return Array.from({length:ce},(ge,Q)=>({field:`placeholder_${Q}`,headerName:"",width:U}))})(),q=o.filter(V=>!V.pinned),te=v==="infinite"&&B&&W>0&&z>=G-1;return d.jsx("div",{className:"ogx__virtual-container",style:{height:`${e}px`},role:"presentation",children:d.jsxs("div",{className:"ogx__rows",style:{transform:`translateY(${t}px)`},role:"rowgroup",children:[n&&o.length===0&&re?d.jsx("div",{className:"ogx__loading-overlay",style:{width:l||void 0},children:re}):n&&o.length===0?Array.from({length:10}).map((V,U)=>d.jsx(Ag,{columns:ue,rowHeight:g,checkboxSelection:a,hasDetailPanel:c,rowReordering:u},`skeleton-${U}`)):q.map(({row:V,id:U,rowIndex:ce})=>d.jsx(jn,{row:V,rowId:U,columns:i,rowIndex:ce,ariaRowIndex:ee!==void 0?ce+ee:void 0,columnIndexMap:de,isSelected:m.has(U),checkboxSelection:a,onRowClick:x,onRowDoubleClick:y,onCellClick:p,onSelectionChange:f,columnWidths:h,pinnedColumns:b,hasDetailPanel:c,isDetailPanelExpanded:w.has(U),detailPanelContent:w.has(U)&&C?d.jsx(Xl,{getContent:C,params:{row:V,id:U,rowIndex:ce}}):null,detailPanelHeight:w.has(U)?po(ho(E,{row:V,id:U,rowIndex:ce})):void 0,onDetailPanelHeightChange:N,onDetailPanelToggle:S,pinCheckboxColumn:M,pinExpandColumn:_,rowReordering:u,onDragStart:F.canReorderRow(U)?F.onDragStart:void 0,onDragOver:F.onDragOver,onDragEnd:F.onDragEnd,onDrop:F.onDrop,isDragging:F.draggedRowId===U,isDragOver:F.dragOverRowId===U,editingCell:A.editingCell,onEditStart:A.startCellEdit,onEditStop:A.stopCellEdit,onEditCellValueChange:A.setEditCellValue,isCellEditable:L,focusedCellField:k!=null&&k.id===U?k.field:null,colspanMap:I,rowSpanningCaches:P,rowHeight:g,rowMeta:H.get(U),cellRange:vi(ie,ce,ae,R)},U)),te&&d.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:J}).map((V,U)=>d.jsx(jn,{row:{id:`__skeleton_${U}__`,_isSkeleton:!0},columns:i,rowIndex:G+U,rowHeight:g},`__skeleton_${U}__`))})]})})}function Tg({noRowsLabel:e,width:t,overlay:n}){return n?d.jsx("div",{className:"ogx__empty",style:{width:t},children:n}):d.jsxs("div",{className:"ogx__empty",style:{width:t},children:[d.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[d.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),d.jsx("path",{d:"M3 9h18M9 21V9"})]}),d.jsx("span",{children:e})]})}const Jl=48;function Fg({columns:e,aggregationModel:t,aggregationResult:n,columnWidths:o,rowHeight:r,checkboxSelection:i,hasDetailPanel:l,rowReordering:a,pinCheckboxColumn:c=!0,pinExpandColumn:u=!0,pinnedColumns:g,loading:m=!1}){const x=s.useMemo(()=>ao(e,o,g,i,c,l,u,a),[e,o,g,i,c,l,u,a]),{lastLeft:y,firstRight:p}=s.useMemo(()=>co(e,g),[e,g]),f=a?Jl:0,h=f+(l&&u?Jl:0),b=(w,C,E)=>d.jsx("div",{className:`ogx__aggregation-spacer${C?" ogx__aggregation-spacer--pinned":""}`,style:C?{insetInlineStart:E}:void 0,"aria-hidden":"true"},w);return d.jsxs("div",{className:`ogx__aggregation-footer${m?" ogx__aggregation-footer--loading":""}`,role:"row","aria-label":"Aggregation totals","aria-live":"polite","aria-busy":m||void 0,style:{minHeight:`${r}px`},children:[a&&b("__reorder_col__",!0,0),l&&b("__expand_col__",u,f),i&&b("__checkbox_col__",c,h),e.map(w=>{if(w.isSpacer){const L=typeof w.width=="number"?w.width:0;return d.jsx("div",{style:{width:L,minWidth:L,flexShrink:0},"aria-hidden":"true"},w.field)}const C=t[w.field],E=C&&bo(w,C)?C:void 0,S=n[w.field],N=yt(w,o,120),M=tt(w.field,g),_=M?x[w.field]:void 0,F=["ogx__aggregation-cell",M==="left"&&"ogx__aggregation-cell--pinned-left",M==="right"&&"ogx__aggregation-cell--pinned-right",M==="left"&&w.field===y&&"ogx__aggregation-cell--pinned-left-last",M==="right"&&w.field===p&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),A={width:N,minWidth:N,maxWidth:N,textAlign:w.align||"left"};return M==="left"&&_!==void 0&&(A.insetInlineStart=_),M==="right"&&_!==void 0&&(A.insetInlineEnd=_),d.jsx("div",{className:F,role:"gridcell",style:A,children:E?d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"ogx__aggregation-label",children:E}),d.jsx("span",{className:"ogx__aggregation-value",children:An(S,E,w,n)})]}):null},w.field)})]})}function Og(e){const{setViewportElement:t,handleScroll:n,ariaLabel:o,ariaRows:r,navigationColumnCount:i,rowSelectionEnabled:l,disableMultipleRowSelection:a,cellSelection:c,effectiveLoading:u,viewportTabIndex:g,setKeyboardMode:m,handleMouseDownCapture:x,handleKeyDown:y,handleFocus:p,handleBlur:f,effectivePinnedColumns:h,virtualization:b,renderColumns:w,renderedDataColumns:C,columnGroupingModel:E,checkboxSelection:S,rowSelection:N,sortModel:M,handleSort:_,handleSortAdd:F,multiSort:A,handleColumnResize:L,handleColumnAutosize:k,columnWidths:I,focusedCell:P,columnIndexMap:v,handleHeaderClick:B,headerReorderHandlers:W,rowReordering:J,hasDetailPanel:G,pinCheckboxColumn:z,pinExpandColumn:H,aggregationModel:re,handleHideColumn:ee,columnsPanel:de,handlePinColumn:ie,wrapHeaderText:ae,headerHeight:R,showHeaderFilters:ue,filterModel:q,handleFilterModelChange:te,localeText:V,editingHandlers:U,isCellEditable:ce,selectedRowIds:ge,handleRowClick:Q,onRowDoubleClick:D,handleCellClick:T,handleSelectionChange:$,expandedRowIds:O,getDetailPanelContent:Z,getDetailPanelHeight:j,handleDetailPanelToggle:ne,reportDetailPanelHeight:X,spanning:Y,rowMetaMap:oe,fillHandle:he,pinnedTopRows:me,pinnedBottomRows:K,pinnedRows:fe,getRowIdOf:we,showEmptyState:le,effectiveNoRowsLabel:xe,noRowsOverlay:Ce,loadingOverlay:se,spanRowWindow:ye,visibleRows:ke,baseColumns:De,viewportWidth:Ne,rowReorderHandlers:Ie,paginationMode:Ee,dataSourceLoading:Pe,sortedUnpinnedRowCount:pe,pageSize:ve,unpinnedRowsLength:Se,showAggregationFooter:be,aggregationResult:Le,effectiveRowHeight:Ue,isAggregationLoading:je}=e,{allSelected:Nt,someSelected:pt}=N,Be={rowReordering:J,columnIndexMap:v,editingHandlers:U,isCellEditable:ce,selectedRowIds:ge,checkboxSelection:S,onRowClick:Q,onRowDoubleClick:D,onCellClick:T,onSelectionChange:$,columnWidths:I,pinnedColumns:h,hasDetailPanel:G,expandedRowIds:O,getDetailPanelContent:Z,getDetailPanelHeight:j,onDetailPanelToggle:ne,onDetailPanelHeightChange:X,pinCheckboxColumn:z,pinExpandColumn:H,focusedCell:P,colspanMap:Y.colspanMap,rowSpanningCaches:Y.rowSpanningCaches,rowHeight:Ue,rowMetaMap:oe,cellRange:c.displayRange,cellRangeHasRowSpan:c.hasRowSpan,fillHandle:he.handle};return d.jsx("div",{ref:t,className:"ogx__viewport",onScroll:n,role:"grid","aria-label":o||"Data grid","aria-rowcount":r.rowCount,"aria-colcount":i,"aria-multiselectable":l&&!a||c.enabled,"aria-busy":u,tabIndex:g,onKeyDownCapture:()=>{m(!0)},onMouseDownCapture:x,onMouseDown:c.handleMouseDown,onClickCapture:c.handleClickCapture,onKeyDown:y,onFocus:p,onBlur:f,children:d.jsxs("div",{className:"ogx__content",style:{width:h?.right?.length?`max(100%, ${b.totalWidth}px)`:b.totalWidth},role:"presentation",children:[d.jsxs("div",{className:"ogx__sticky-top",role:"presentation",children:[d.jsx(Kl,{columns:w,allColumns:C,columnGroupingModel:E,checkboxSelection:S,allSelected:Nt,someSelected:pt,onSelectAll:N.selectAll,sortModel:M,onSort:_,onSortAdd:F,multiSort:A,onColumnResize:L,onColumnAutosize:k,columnWidths:I,pinnedColumns:h,focusedCell:P,columnIndexMap:v,onHeaderClick:B,onDragStart:W.onDragStart,onDragOver:W.onDragOver,onDragEnd:W.onDragEnd,onDrop:W.onDrop,draggedColumn:W.draggedColumn,dragOverColumn:W.dragOverColumn,rowReordering:J,hasDetailPanel:G,pinCheckboxColumn:z,pinExpandColumn:H,aggregationModel:re,onHideColumn:ee,onManageColumns:de.openColumnsPanel,onPinColumn:ie,wrapHeaderText:ae,headerHeight:R,headerFilters:ue,filterModel:q,onFilterModelChange:te,onOpenFilterPanel:de.openFiltersPanel,localeText:V}),d.jsx(Yl,{...Be,rows:me,position:"top",ariaRowIndexBase:r.topBase,columns:w,pinnedRows:fe,getRowId:we})]}),le&&d.jsx(Tg,{noRowsLabel:xe,width:b.totalWidth,overlay:Ce}),d.jsx(Pg,{...Be,virtualContainerHeight:b.virtualContainerHeight,offsetTop:ye.offsetTop,effectiveLoading:u,visibleRows:ke,baseColumns:De,virtualColumns:w,viewportWidth:Ne,rowReorderHandlers:Ie,paginationMode:Ee,dataSourceLoading:Pe,sortedUnpinnedRowCount:pe,infiniteScrollSkeletonCount:Math.min(ve,20),unpinnedRowsLength:Se,lastRenderedRowIndex:ye.renderContext.lastRowIndex,ariaRowIndexOffset:r.centerOffset,loadingOverlay:se}),d.jsxs("div",{className:"ogx__sticky-bottom",role:"presentation",children:[d.jsx(Yl,{...Be,rows:K,position:"bottom",rowIndexOffset:r.bottomRowIndexOffset,ariaRowIndexBase:r.bottomBase,columns:w,pinnedRows:fe,getRowId:we}),be&&d.jsx(Fg,{columns:b.virtualColumns,aggregationModel:re,aggregationResult:Le,columnWidths:I,rowHeight:Ue,checkboxSelection:S,hasDetailPanel:G,rowReordering:J,pinCheckboxColumn:z,pinExpandColumn:H,pinnedColumns:h,loading:je})]})]})})}function Zl({count:e,sum:t,average:n}){return d.jsxs("div",{className:"ogx__cell-selection-stats",children:[d.jsxs("span",{className:"ogx__cell-selection-stat",children:[d.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Count"}),d.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"count",children:e.toLocaleString()})]}),t!==null&&d.jsxs("span",{className:"ogx__cell-selection-stat",children:[d.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Sum"}),d.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"sum",children:nn(t,"sum")})]}),n!==null&&d.jsxs("span",{className:"ogx__cell-selection-stat",children:[d.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Average"}),d.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"average",children:nn(n,"avg")})]})]})}function Dg({stats:e,apiRef:t,slot:n,slotProps:o}){const r=n??Zl;return d.jsx("div",{className:"ogx__cell-selection-stats-area","aria-hidden":e?void 0:!0,children:e&&d.jsx(r,{apiRef:t,...e,...o})})}function $g({paginationSlot:e,paginationSlotProps:t,page:n,paginationModel:o,rowCount:r,pageSizeOptions:i,onPaginationModelChange:l,localeText:a}){const c=e||er;return d.jsx(c,{page:n,pageSize:o.pageSize,rowCount:r,pageSizeOptions:i,onPageChange:u=>l({...o,page:u}),onPageSizeChange:u=>l({...o,pageSize:u,page:0}),localeText:Ai(a),...t})}function Gg({loading:e,error:t,noRowsLabel:n,filteredRowCount:o,dataRowCount:r,filterModel:i,cellSelectionAnnouncement:l,aiAssistantAnnouncement:a}){return d.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[e?"Loading data...":"",t?`Error: ${kl(t)}`:"",!e&&!t&&(o===0?n:i&&((i.quickFilterValues?.length||0)>0||(i.items?.length||0)>0)?`${r} ${r===1?"row":"rows"} found`:""),l?d.jsxs("span",{className:"ogx-aria-live-status__cells",children:[" ",l]}):null,a?d.jsxs("span",{className:"ogx-aria-live-status__ai",children:[" ",a]}):null]})}function Hg({overlay:e}){return e?d.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows ogx__loading-overlay--custom",children:e}):d.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows",children:d.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})})}function Bg({error:e,onRetry:t}){if(!e)return null;const n=kl(e);return d.jsxs("div",{className:"ogx-error-overlay","aria-live":"assertive",role:"alert",children:[d.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:[d.jsx("circle",{cx:"12",cy:"12",r:"10"}),d.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),d.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),d.jsx("div",{className:"ogx-error-overlay__title",children:"Oops! Something went wrong"}),d.jsx("div",{className:"ogx-error-overlay__message",children:n}),t&&d.jsx("button",{type:"button",onClick:t,className:"ogx-button ogx-button--primary",children:"Retry"})]})}function Wg(e){const{containerRef:t,className:n,autoHeight:o,height:r,style:i,hasRowSpanning:l,listView:a,headerFilterHeight:c,slots:u,slotProps:g,toolbarProps:m,aiAssistantPanel:x,orderedColumns:y,columnVisibilityModel:p,disableColumnReorder:f,handleColumnVisibilityModelChange:h,moveColumn:b,resetColumnOrder:w,listViewColumn:C,allRenderableRows:E,dataRows:S,pagination:N,effectivePaginationModel:M,currentPage:_,pageSizeOptions:F,columnsByField:A,paginationRowCount:L,handlePaginationModelChange:k,onRowsScrollEnd:I,toggleExpansion:P,showCellSelectionStats:v,apiRef:B,hasAggregation:W,isHierarchyEnabled:J,dataSourceError:G,filteredRowCount:z,onRetry:H,...re}=e,{effectiveRowHeight:ee,headerHeight:de,showHeaderFilters:ie,effectiveLoading:ae,columnsPanel:R,columnGroupingModel:ue,ariaLabel:q,pinnedTopRows:te,pinnedBottomRows:V,sortedUnpinnedRowCount:U,effectiveNoRowsLabel:ce,checkboxSelection:ge,paginationMode:Q,localeText:D,getRowIdOf:T,rowSelectionEnabled:$,disableMultipleRowSelection:O,cellSelection:Z,aggregationModel:j,aggregationResult:ne,filterModel:X,selectedRowIds:Y,rowMetaMap:oe,handleRowClick:he,onRowDoubleClick:me,handleSelectionChange:K}=re,fe=u?.noRowsOverlay,we=u?.loadingOverlay,le=we?d.jsx(we,{...g?.loadingOverlay}):void 0,xe=fe?d.jsx(fe,{...g?.noRowsOverlay}):void 0,Ce=u?.footer,se=ae&&E.length>0&&Q!=="infinite",ye=u?.toolbar;return d.jsxs("div",{ref:t,className:["ogx",n,o&&"ogx--auto-height",!o&&r===void 0&&i?.height===void 0&&"ogx--fill",l&&"ogx--row-spanning",a&&"ogx--list-view"].filter(Boolean).join(" "),style:{...i,height:r??i?.height,"--ogx-row-height":`${ee}px`,"--ogx-header-height":`${de}px`,...ie?{"--ogx-header-filter-height":`${c}px`}:void 0},"aria-busy":ae,children:[ye&&m&&d.jsx(Al.Provider,{value:R.toolbarHost,children:d.jsx(bf,{component:ye,toolbarProps:m})}),x.panelProps&&d.jsx(Sf,{panelProps:x.panelProps,slot:u?.aiAssistantPanel,slotProps:g?.aiAssistantPanel}),d.jsx(Ef,{isOpen:R.standalonePanelOpen,containerRef:t,panelRef:R.standalonePanelRef,columns:y,columnVisibilityModel:p,disableColumnReorder:f,onClose:R.closeStandalonePanel,onColumnVisibilityChange:h,onColumnMove:b,onColumnOrderReset:w,columnGroupingModel:ue}),a&&C&&d.jsx(Lf,{ariaLabel:q,allRenderableRows:E,dataRowCount:S.length,pinnedTopRowCount:te.length,pinnedBottomRowCount:V.length,unpinnedRowCount:U,pagination:N,effectivePaginationModel:M,currentPage:_,pageSizeOptions:F,selectedRowIds:Y,listViewColumn:C,columnsByField:A,rowMetaMap:oe,noRowsLabel:ce,rowHeight:ee,checkboxSelection:ge,paginationMode:Q,serverRowCount:L,paginationSlot:u?.pagination,paginationSlotProps:g?.pagination,localeText:Ai(D),onRowClick:he,onRowDoubleClick:me,onSelectionChange:K,onPaginationModelChange:k,onRowsScrollEnd:I,getRowId:T,multiselectable:$&&!O,selectable:$,onToggleExpansion:P,loading:ae,loadingOverlay:le,noRowsOverlay:xe,showPaginationControls:!Ce}),!a&&d.jsx(Og,{...re,loadingOverlay:le,noRowsOverlay:xe}),Z.enabled&&v&&d.jsx(Dg,{stats:Z.stats,apiRef:B,slot:u?.cellSelectionStats,slotProps:g?.cellSelectionStats}),Ce&&d.jsx(Ce,{apiRef:B,aggregationModel:j,aggregationResult:W?ne:null,rowCount:J&&Q!=="server"?S.length:L,pagination:N,paginationModel:M,pageSizeOptions:F,onPaginationModelChange:k,...g?.footer}),!a&&!Ce&&N&&d.jsx($g,{paginationSlot:u?.pagination,paginationSlotProps:g?.pagination,page:_,paginationModel:M,rowCount:L,pageSizeOptions:F,onPaginationModelChange:k,localeText:D}),d.jsx(Gg,{loading:ae,error:G,noRowsLabel:ce,filteredRowCount:z,dataRowCount:S.length,filterModel:X,cellSelectionAnnouncement:Z.announcement,aiAssistantAnnouncement:x.announcement}),se&&d.jsx(Hg,{overlay:le}),d.jsx(Bg,{error:G,onRetry:H})]})}function Vg(e){const{baseColumns:t,pinnedColumns:n,hasGroupingColumn:o,groupingColDef:r,isTreeData:i,getTreeDataPath:l}=e,a=s.useMemo(()=>o?{...n,left:["__group__",...(n?.left??[]).filter(u=>u!=="__group__")]}:n,[o,n]);return{activeColumns:s.useMemo(()=>o?[{headerName:"Group",width:220,...i&&l?{valueGetter:({row:u})=>{const g=l(u);return g[g.length-1]}}:{},...r,field:"__group__",hideable:!1,sortable:!1,filterable:!1,pinnable:!1,exportable:!1},...t]:t,[r,o,i,l,t]),effectivePinnedColumns:a}}function zg(e){return e.id}function Rg(e){const t=s.useCallback(r=>e.get(r)??r.id,[e]),n=s.useRef(t);s.useLayoutEffect(()=>{n.current=t});const o=s.useCallback(r=>n.current(r),[]);return{getRowIdOf:t,getRowIdOfInEvents:o}}function Kg(e,t){s.useLayoutEffect(()=>{e&&(e.current=t.current)},[e,t])}function Ug(e){const{hierarchyHandlers:t,pinnedTopRows:n,sortedUnpinnedRows:o,pinnedBottomRows:r,rowMetaMap:i,getRowId:l,hierarchyField:a,dataRows:c}=e,u=t?.getVisibleRows({expandAll:!0,labelField:a});if(!u)return[...n,...o,...r];const g=c?new Set(c):null;return u.filter(m=>!i.get(l(m))?.isGroupRow&&(!g||g.has(m)))}function jg(e,t){if(e===t)return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;const o=e,r=t;return n.every(i=>Object.prototype.hasOwnProperty.call(t,i)&&Object.is(o[i],r[i]))}function qg(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>jg(n,t[o]))}function Xg(e){const[t,n]=s.useState(e),o=qg(t,e);return o||n(e),o?t:e}function Yg(e){const{rows:t,getRowId:n,rowMetaMap:o,columns:r,aggregationModel:i,aggregationResult:l,isSubtotalHidden:a}=e,c=Object.keys(i).length>0,u=new Map(r.map(y=>[y.field,y])),g=[],m=[],x=y=>{for(;m.length>0&&m[m.length-1].header.depth>=y;){const p=m.pop();c&&!a?.(p.id)&&g.push({type:"group-subtotal",depth:p.header.depth,groupField:p.header.groupField,groupValue:p.header.groupValue,groupLabel:p.header.groupLabel,aggregatedValues:Ln(p.leaves,i,u,"getGroupedExportRows")})}};for(const y of t){const p=n(y),f=o.get(p);if(!f?.isGroupFooter)if(f?.isGroupRow){const h=f.treeDepth??0;x(h);const b={type:"group-header",depth:h,groupField:f.groupingField,groupValue:f.groupingValue,groupLabel:f.groupLabel};g.push(b),m.push({id:p,header:b,leaves:[]})}else g.push({type:"leaf",depth:f?.treeDepth??m.length,row:y}),m.forEach(h=>h.leaves.push(y))}return x(0),c&&l&&g.push({type:"grand-total",depth:0,aggregatedValues:l}),g}function Jg(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=()=>n.current;t.current.getAggregationResult=()=>o().hasAggregation?o().aggregationResult:null,t.current.getAggregationModel=()=>o().hasAggregation?o().aggregationModel:null,t.current.getGroupedExportRows=()=>{const{hasAggregation:r,aggregationResult:i,aggregationModel:l,isRowGrouping:a,rowGroupingHandlers:c,rowMetaMap:u,columns:g,getRowId:m,hierarchyField:x}=o();return a?Yg({rows:c.getVisibleRows({expandAll:!0,labelField:x})??[],getRowId:m,rowMetaMap:u,columns:g,aggregationModel:l,aggregationResult:r&&c.rootAggregationPosition!==null?i:null,isSubtotalHidden:y=>c.aggregationPositions.get(y)===null}):null}},[t])}const Ql="ogx--range-dragging",gt=32,Zg=40,Qg=300;function es(e,t){if(!e||e.nodeType!==1)return null;const n=e.closest(".ogx__cell[data-field]");if(!n||n.closest(".ogx__viewport")!==t)return null;const o=n.closest(".ogx__detail-panel");if(o&&t.contains(o))return null;const r=n.closest('[role="row"][data-rowindex]');if(!r)return null;const i=Number(r.getAttribute("data-rowindex")),l=n.dataset.field;return!Number.isInteger(i)||!l?null:{rowIndex:i,field:l,element:n}}function ar(e){const t=e.getSelection();t&&t.rangeCount>0&&t.removeAllRanges()}const ts=(e,t,n)=>Math.min(Math.max(e,t),n),qn=e=>Math.min(Zg,Math.max(2,Math.round(e/2)));function ep(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Copying ${e} cells. For ranges this large, exportToCsv or exportToExcel is the better tool.`)}function tp(e){const{enabled:t,model:n,allRenderableRows:o,getRowId:r,navigationColumns:i,columnIndexMap:l,spanning:a,rowMetaMap:c,localeText:u,showStats:g}=e,m=t&&n.length>0?n[0]:null,x=s.useMemo(()=>t?i.filter(T=>Ke(T.field)):[],[t,i]),y=s.useMemo(()=>{if(!a.hasColSpan&&!a.hasRowSpan)return;const{colspanMap:T,rowSpanningCaches:$,getSpanOrigin:O}=a;return{getSpanOrigin:O,getColSpan:(Z,j)=>{const ne=T.get(Z)?.[j];return ne&&!ne.spannedByColSpan?ne.cellProps.colSpan:1},getRowSpan:(Z,j)=>$.spannedCells[Z]?.[j]??1}},[a]),p=s.useMemo(()=>{if(!t)return null;const T=o.map(r),$=new Map;T.forEach((Z,j)=>{$.has(Z)||$.set(Z,j)});const O=x.map(Z=>Z.field);return{rowIds:T,rowIndexById:$,fields:O,colIndexByField:new Map(O.map((Z,j)=>[Z,j])),spans:y}},[t,o,r,x,y]),f=s.useMemo(()=>m&&p?Gn(m,p):null,[m,p]),h=f!==null&&_t(f)>1,b=s.useMemo(()=>{if(!f||!h||!p)return null;const T=l.get(p.fields[f.left]),$=l.get(p.fields[f.right]);return T===void 0||$===void 0?null:{top:f.top,bottom:f.bottom,left:T,right:$}},[f,h,p,l]),w=s.useCallback(T=>Re(T,c),[c]),C=s.useCallback((T,$,O)=>{if(p)for(let Z=T.top;Z<=T.bottom;Z++){const j=o[Z],ne=p.rowIds[Z];if(!(!j||w(ne))){$(j,ne);for(let X=T.left;X<=T.right;X++){const Y=x[X],oe=y?.getSpanOrigin(ne,Y.field);O(j,ne,Y,oe!=null&&(oe.rowId!==ne||oe.field!==Y.field))}}}},[p,o,x,y,w]),E={...e,range:m,resolved:f,context:p,rangeColumns:x,forEachCell:C},S=s.useRef(E);s.useLayoutEffect(()=>{S.current=E});const N=s.useRef(null),M=s.useCallback(T=>{N.current=T},[]),_=s.useCallback(()=>{const{getPendingModel:T,model:$}=S.current;return T()??$},[]),F=s.useCallback(()=>{const{context:T,range:$,resolved:O,enabled:Z}=S.current,j=Z?_()[0]??null:null;return!j||!T?{range:null,resolved:null}:j===$?{range:j,resolved:O}:{range:j,resolved:Gn(j,T)}},[_]),A=s.useCallback((T,$)=>{if(!S.current.enabled)return;const O=T.length>1?T.slice(0,1):T;ec(O,_())||S.current.onModelChange(O,$)},[_]),L=s.useCallback((T,$,O)=>{A([{anchor:T,head:$}],O)},[A]),k=s.useCallback((T,$)=>{const{viewportRef:O,layout:Z,rowHeight:j,pinnedTopRowCount:ne}=S.current,X=O.current;X&&(In(X,T-ne,Z.cumulativeHeights,Z.pinnedBottomHeight,j),mo(X,Z.unpinnedColsWithWidth.findIndex(Y=>Y.field===$),Z))},[]),I=s.useCallback((T,$,O,Z)=>{const{context:j}=S.current,{range:ne,resolved:X}=F();if(!j||Z.id===null||!Ke(Z.field))return!1;const Y=j.rowIndexById.get(Z.id),oe=j.colIndexByField.get(Z.field);if(Y===void 0||oe===void 0)return!1;const he=ne&&X&&ct(ne.anchor,{id:Z.id,field:Z.field})?{range:ne,resolved:X}:null,me=he?he.range.anchor:{id:Z.id,field:Z.field},K=he?.resolved??Gn({anchor:me,head:me},j);if(!K)return!1;const fe=nc(K,T,$,O,j.rowIds.length-1,j.fields.length-1);if(!fe)return!0;const we={id:j.rowIds[fe.row],field:j.fields[fe.col]};return L(me,we,"keyboard"),k(fe.row,we.field),!0},[F,L,k]),P=s.useCallback(()=>{const{range:T,resolved:$}=F();return!T||!$||_t($)<=1?!1:(L(T.anchor,T.anchor,"keyboard"),!0)},[F,L]),v=s.useCallback(()=>{const{context:T}=S.current;return!T||T.rowIds.length===0||T.fields.length===0?!1:(L({id:T.rowIds[0],field:T.fields[0]},{id:T.rowIds[T.rowIds.length-1],field:T.fields[T.fields.length-1]},"selectAll"),!0)},[L]),B=s.useCallback(()=>{const{context:T}=S.current,{range:$,resolved:O}=F();if(!T)return null;if(O)return O;if($)return null;const Z=N.current;return!Z||Z.id===null||!Ke(Z.field)?null:Gn({anchor:{id:Z.id,field:Z.field},head:{id:Z.id,field:Z.field}},T)},[F]),W=s.useCallback(()=>{const T=B();if(!T)return null;const{rangeColumns:$,forEachCell:O}=S.current,Z=_t(T);Z>lc&&ep(Z);const j=[];if(O(T,he=>{j.push(he)},()=>{}),j.length===0)return null;const ne=$.slice(T.left,T.right+1),X=S.current.context?.spans,Y=S.current.getRowId;return Bd(j,ne,X?(he,me)=>{const K=Y(he),fe=X.getSpanOrigin(K,me.field);return fe!==null&&(fe.rowId!==K||fe.field!==me.field)}:void 0)},[B]),J=s.useCallback(()=>{const{forEachCell:T}=S.current,{resolved:$}=F();if(!$)return[];const O=[];return T($,()=>{},(Z,j,ne,X)=>{X||O.push({id:j,field:ne.field,value:Me(Z,ne.field,ne)})}),O},[F]),G=s.useRef(null),z=s.useRef(!1);s.useEffect(()=>()=>G.current?.stop(),[]);const H=s.useCallback((T,$,O)=>{const Z=S.current.context;if(!Z)return null;const j=T.ownerDocument;if(typeof j.elementFromPoint!="function")return null;const ne=es(j.elementFromPoint($,O),T);if(!ne)return null;const X=Z.rowIds[ne.rowIndex];if(X===void 0)return null;const Y=Ke(ne.field)?ne.field:Z.fields[0];return Y===void 0?null:{id:X,field:Y}},[]),re=s.useCallback((T,$)=>{const{context:O,layout:Z,pinnedTopRowCount:j}=S.current,ne=Z.cumulativeHeights;if(!O||ne.length===0||T<0)return null;let X=0,Y=ne.length-1;for(;X<Y;){const he=X+Y>>1;ne[he]>T?Y=he:X=he+1}const oe=O.rowIds[X+j];return oe===void 0?null:{id:oe,field:$}},[]),ee=s.useRef(()=>{}),de=s.useCallback(T=>{const $=G.current,O=S.current.viewportRef.current;if(!$||!O)return;$.frame=0;const{layout:Z}=S.current,j=O.getBoundingClientRect(),ne=O.clientWidth,X=O.clientHeight,Y=O.querySelector(":scope > .ogx__content > .ogx__sticky-top"),oe=O.querySelector(":scope > .ogx__content > .ogx__sticky-bottom"),he=Y?.querySelector(":scope > .ogx__header-wrap"),me=Y?Y.getBoundingClientRect().bottom:j.top,K=Math.min(j.top+X,oe?oe.getBoundingClientRect().top:j.top+X),fe=he?he.getBoundingClientRect().bottom:me;$.rtl===void 0&&($.rtl=Xe(O));const we=$.rtl,le=we?j.right-ne:j.left,xe=Z.pinnedSystemColumnsWidth+Z.leftWidth,Ce=le+(we?Z.rightWidth:xe),se=le+ne-(we?xe:Z.rightWidth),ye=ts($.x,le+1,le+ne-2);let ke=$.y;(ke<j.top||ke>j.top+X||ke<fe)&&(ke=ts(ke,me+1,Math.max(me+1,K-2)));const De=typeof O.ownerDocument.elementFromPoint=="function",Ie=H(O,ye,ke)??(De&&$.moved?re(ke-j.top-(Y?Y.getBoundingClientRect().height:0)+O.scrollTop,$.head.field):null);if(Ie&&!ct(Ie,$.head)&&($.head=Ie,!$.moved&&!ct(Ie,$.anchor)&&($.moved=!0,S.current.containerRef.current?.classList.add(Ql),ar(O.ownerDocument)),$.onTrack||L($.anchor,Ie,"pointer")),$.onTrack&&$.onTrack($.head,$.x,$.y),!T)return;const Ee=$.y<me||$.y>K||$.x<le||$.x>le+ne;if(!$.moved&&!Ee)return;let Pe=0,pe=0;$.y<me+gt?Pe=-qn(me+gt-$.y):$.y>K-gt&&(Pe=qn($.y-(K-gt))),$.x<Ce+gt?pe=-qn(Ce+gt-$.x):$.x>se-gt&&(pe=qn($.x-(se-gt)));const ve=Pe<0&&O.scrollTop>0||Pe>0&&O.scrollTop+X<O.scrollHeight-1,Se=O.scrollWidth-ne,be=we?-Se:0,Le=pe<0&&O.scrollLeft>be||pe>0&&O.scrollLeft<be+Se-1;!ve&&!Le||(ve&&(O.scrollTop+=Pe),Le&&(O.scrollLeft+=pe),$.frame=requestAnimationFrame(()=>ee.current(!0)))},[H,re,L]);s.useLayoutEffect(()=>{ee.current=de},[de]);const ie=s.useCallback((T,$,O,Z,j,ne)=>{G.current?.stop();const X=ne?"pointermove":"mousemove",Y=ne?"pointerup":"mouseup",oe=se=>!ne||se.pointerId===ne.pointerId,he=se=>{const ye=G.current;if(!(!ye||!oe(se))){if(se.buttons===0){ye.stop();return}ye.x=se.clientX,ye.y=se.clientY,ye.moved&&(se.preventDefault(),ar(j)),ye.frame||(ye.frame=requestAnimationFrame(()=>de(!0)))}},me=se=>{const ye=G.current;if(!ye||!oe(se))return;ye.x=se.clientX,ye.y=se.clientY,de(!1);const ke=ye.moved;ye.stop(!1,se.altKey),ke&&ar(j),ke&&(z.current=!0,setTimeout(()=>{z.current=!1},0))},K=se=>{oe(se)&&G.current?.stop()},fe=se=>{se.key!=="Escape"||!G.current||(se.preventDefault(),se.stopPropagation(),G.current.stop())},we=j.defaultView,le=()=>G.current?.stop();let xe=!1;const Ce={anchor:T,head:$,x:O,y:Z,frame:0,moved:!1,onTrack:ne?.onTrack,stop:(se=!0,ye=!1)=>{Ce.frame&&cancelAnimationFrame(Ce.frame),Ce.frame=0,j.removeEventListener(X,he,!0),j.removeEventListener(Y,me,!0),ne&&(j.removeEventListener("pointercancel",K,!0),j.removeEventListener("keydown",fe,!0)),we?.removeEventListener("blur",le),S.current.containerRef.current?.classList.remove(Ql),G.current===Ce&&(G.current=null),xe||(xe=!0,ne&&ne.onEnd({cancelled:se,altKey:ye}))}};G.current=Ce,j.addEventListener(X,he,!0),j.addEventListener(Y,me,!0),ne&&(j.addEventListener("pointercancel",K,!0),j.addEventListener("keydown",fe,!0)),we?.addEventListener("blur",le)},[de]),ae=s.useCallback(T=>{const $=S.current.viewportRef.current;if(!$||!S.current.enabled)return;const{start:O,x:Z,y:j,pointerId:ne,onTrack:X,onEnd:Y}=T;ie(O,O,Z,j,$.ownerDocument,{pointerId:ne,onTrack:X,onEnd:Y})},[ie]),R=s.useCallback(T=>{if(T.button!==0||T.defaultPrevented)return;const{context:$}=S.current;if(!$)return;const O=T.currentTarget,Z=es(T.target,O);if(!Z||!Ke(Z.field)||T.target.closest?.(".ogx__cell-fill-handle")||Z.element.classList.contains("ogx__cell--editing")||wi(T.target))return;const j=$.rowIds[Z.rowIndex];if(j===void 0)return;const ne={id:j,field:Z.field};let X=ne;if(T.shiftKey){const Y=_()[0],oe=N.current;Y&&$.rowIndexById.has(Y.anchor.id)&&$.colIndexByField.has(Y.anchor.field)?X=Y.anchor:oe&&oe.id!==null&&Ke(oe.field)&&(X={id:oe.id,field:oe.field}),T.preventDefault(),z.current=!0;const he=O.ownerDocument;O.contains(he.activeElement)||O.focus({preventScroll:!0})}if(L(X,ne,"pointer"),ie(X,ne,T.clientX,T.clientY,O.ownerDocument),T.shiftKey){const Y=G.current;Y&&!ct(X,ne)&&(Y.moved=!0)}},[_,L,ie]),ue=s.useCallback(T=>{z.current&&(z.current=!1,T.stopPropagation(),T.preventDefault())},[]),q=f?f.right-f.left+1:0,te=f?f.bottom-f.top+1:0,V=u?.cellSelectionAnnouncement??ic,U=h?V(te*q,te,q):"",[ce,ge]=s.useState("");s.useEffect(()=>{if(!t)return;const T=setTimeout(()=>ge(U),Qg);return()=>clearTimeout(T)},[t,U]);const Q=s.useMemo(()=>{if(!g||!f||!h)return null;const T=[];C(f,()=>{},(O,Z,j,ne)=>{ne||T.push(Me(O,j.field,j))});const $=T.filter(O=>typeof O=="number"&&!Number.isNaN(O));return{cellCount:_t(f),rowCount:f.bottom-f.top+1,columnCount:f.right-f.left+1,count:at.count(T),numericCount:$.length,sum:$.length?at.sum($):null,average:$.length?at.avg($):null}},[g,f,h,C]),D=s.useMemo(()=>t?{extendSelection:I,collapseSelection:P,selectAllCells:v}:void 0,[t,I,P,v]);return{enabled:t,range:m,resolved:f,displayRange:b,hasRowSpan:a.hasRowSpan,handleMouseDown:t?R:void 0,handleClickCapture:t?ue:void 0,extendSelection:I,collapseSelection:P,selectAllCells:v,keyboard:D,getCopyText:W,getSelectedCells:J,announcement:t?ce:"",stats:Q,reportFocus:M,setModel:A,getCurrentRange:F,startTrackedDrag:ae}}function np(e){return s.useCallback(t=>{e.current?.classList.toggle("ogx--kb",t)},[e])}function op(e){const{ensureGridFocus:t,setKeyboardMode:n,setFocusedCell:o,getRowId:r,onCellClick:i}=e,l=s.useCallback(c=>{t(),n(!1),o({id:r(c.row),field:c.field,rowIndex:c.rowIndex}),i?.(c)},[i,n,o,t,r]),a=s.useCallback(c=>{t(),o({id:null,field:c}),n(!1)},[t,o,n]);return{handleCellClick:l,handleHeaderClick:a}}function rp(){const[e,t]=s.useState(!1),[n,o]=s.useState(!1),r=s.useRef(null),i=s.useRef(0),[l,a]=s.useState(0),[c,u]=s.useState(!1),g=s.useMemo(()=>({registerColumnsPanel:()=>(i.current+=1,()=>{i.current-=1}),registerFiltersPanel:()=>(a(h=>h+1),()=>a(h=>h-1))}),[]),m=s.useCallback(()=>u(!0),[]),x=s.useCallback(()=>u(!1),[]),y=s.useCallback(()=>{i.current>0?t(!0):o(!0)},[]),p=s.useCallback(()=>t(!1),[]),f=s.useCallback(()=>o(!1),[]);return s.useEffect(()=>{if(!n)return;function h(w){r.current&&!r.current.contains(w.target)&&o(!1)}function b(w){w.key==="Escape"&&o(!1)}return document.addEventListener("mousedown",h),document.addEventListener("keydown",b),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",b)}},[n]),{toolbarHost:g,toolbarPanelRequested:e,closeToolbarPanel:p,standalonePanelOpen:n,closeStandalonePanel:f,standalonePanelRef:r,openColumnsPanel:y,toolbarFiltersRequested:c,closeToolbarFiltersPanel:x,openFiltersPanel:l>0?m:void 0}}const ip=Symbol.for("opengridx.ai.validated");function lp(e){return typeof e=="object"&&e!==null&&e[ip]===!0}const Xn=["filter","sort","grouping","aggregation","pivot","columnVisibility"],cr={filter:"filterModel",sort:"sortModel",grouping:"rowGroupingModel",aggregation:"aggregationModel",pivot:"pivotModel",columnVisibility:"columnVisibilityModel"};function ns(e){return Xn.map(t=>cr[t]).filter(t=>e[t]!==void 0)}function sp(e,t){const n={},o=[];for(const r of Xn){const i=cr[r];e[i]!==void 0&&(t.includes(r)?Object.assign(n,{[i]:e[i]}):o.push({path:i,message:"Part not allowed"}))}return{state:n,errors:o}}function ap(e,t){const n=e[t];if(Array.isArray(n))return n.length===0;if(t==="filterModel"){const o=e.filterModel;return!o||(o.items??[]).length===0&&(o.quickFilterValues??[]).length===0}if(t==="pivotModel"){const o=e.pivotModel;return!o||o.rowFields.length===0&&o.columnFields.length===0&&o.valueFields.length===0}return typeof n=="object"&&n!==null&&Object.keys(n).length===0}function cp(e){let t=e.length;for(const n of[".","["]){const o=e.indexOf(n);o>=0&&o<t&&(t=o)}return e.slice(0,t)}function dp(e,t){const n=new Set(t.map(r=>cp(typeof r.path=="string"?r.path:""))),o={};for(const r of ns(e))n.has(r)&&ap(e,r)||Object.assign(o,{[r]:e[r]});return o}function up(e,t){const n={};for(const o of ns(e))Object.assign(n,{[o]:t[o]});return n}function os(e,t){const n={};for(const o of Xn.map(r=>cr[r]))!(o in t)&&e[o]===void 0||(e[o]===void 0?Object.assign(n,{[o]:t[o]}):o==="columnVisibilityModel"?n.columnVisibilityModel={...t.columnVisibilityModel,...e.columnVisibilityModel}:Object.assign(n,{[o]:e[o]}));return n}function dr(e,t){t.filterModel&&e.setFilterModel(t.filterModel),t.sortModel&&e.setSortModel(t.sortModel),t.rowGroupingModel&&e.setRowGroupingModel(t.rowGroupingModel),t.aggregationModel&&e.setAggregationModel(t.aggregationModel),t.pivotModel&&e.setPivotModel(t.pivotModel),t.columnVisibilityModel&&e.setColumnVisibilityModel(t.columnVisibilityModel)}function rs(e){return Array.isArray(e)?e.map(rs).join(", "):e instanceof Date?e.toISOString().slice(0,10):e==null?"":String(e)}function is(e,t){return"items"in e?`(${e.items.map(n=>is(n,t)).join(` ${e.logicOperator} `)})`:[t(e.field),e.operator,rs(e.value)].filter(Boolean).join(" ")}const fp={sum:"Sum",avg:"Average",count:"Count",min:"Min",max:"Max",unique:"Unique"};function ls(e,t){const n=[],{filterModel:o,sortModel:r,rowGroupingModel:i,aggregationModel:l,pivotModel:a,columnVisibilityModel:c}=e;if(o){const u=o.items??[];u.forEach((m,x)=>n.push({id:`filter:${x}`,part:"filter",label:is(m,t)}));const g=o.quickFilterValues??[];g.length>0&&n.push({id:"filter:quick",part:"filter",label:`Search: ${g.join(" ")}`}),u.length===0&&g.length===0&&n.push({id:"filter:clear",part:"filter",label:"No filters"})}if(r&&(r.forEach((u,g)=>n.push({id:`sort:${g}`,part:"sort",label:`Sort: ${t(u.field)}, ${u.sort==="desc"?"descending":"ascending"}`})),r.length===0&&n.push({id:"sort:clear",part:"sort",label:"No sorting"})),i&&(i.forEach((u,g)=>n.push({id:`grouping:${g}`,part:"grouping",label:`Group: ${t(u)}`})),i.length===0&&n.push({id:"grouping:clear",part:"grouping",label:"No grouping"})),l){const u=Object.keys(l);u.forEach(g=>{const m=l[g];n.push({id:`aggregation:${g}`,part:"aggregation",label:`${fp[m]??m}: ${t(g)}`})}),u.length===0&&n.push({id:"aggregation:clear",part:"aggregation",label:"No summaries"})}if(a){const u=[...a.rowFields,...a.columnFields,...a.valueFields.map(g=>g.field)];n.push({id:"pivot",part:"pivot",label:u.length>0?`Pivot: ${u.map(t).join(", ")}`:"No pivot"})}if(c)for(const u of Object.keys(c))n.push({id:`columnVisibility:${u}`,part:"columnVisibility",label:`${c[u]?"Show":"Hide"}: ${t(u)}`});return n}function gp(e,t){const n={...e},o=t.indexOf(":"),r=o<0?t:t.slice(0,o),i=o<0?"":t.slice(o+1),l=Number(i);if(r==="filter"&&n.filterModel){const a={...n.filterModel};i==="quick"?delete a.quickFilterValues:i==="clear"?a.items=[]:a.items=(a.items??[]).filter((c,u)=>u!==l),(a.items??[]).length===0&&(a.quickFilterValues??[]).length===0?delete n.filterModel:n.filterModel=a}else if(r==="sort"&&n.sortModel)n.sortModel=n.sortModel.filter((a,c)=>c!==l),(n.sortModel.length===0||i==="clear")&&delete n.sortModel;else if(r==="grouping"&&n.rowGroupingModel)n.rowGroupingModel=n.rowGroupingModel.filter((a,c)=>c!==l),(n.rowGroupingModel.length===0||i==="clear")&&delete n.rowGroupingModel;else if(r==="aggregation"&&n.aggregationModel){const a={...n.aggregationModel};delete a[i],Object.keys(a).length===0?delete n.aggregationModel:n.aggregationModel=a}else if(r==="columnVisibility"&&n.columnVisibilityModel){const a={...n.columnVisibilityModel};delete a[i],Object.keys(a).length===0?delete n.columnVisibilityModel:n.columnVisibilityModel=a}else r==="pivot"&&delete n.pivotModel;return n}const pp="Ask about this table…",hp=[],Yn=[],ss="The reply was not validated";function mp(){return typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)}function wp(e){return typeof e=="object"&&e!==null&&e.name==="AbortError"}function bp(e){return e instanceof Error&&e.message?e.message:"Unknown error"}function xp(e,t){const n=e===0?"No changes":`Applied ${e} ${e===1?"change":"changes"}`;return t>0?`${n}, ${t} ignored`:n}function as(e,t,n){if(!e)return;const o=We(()=>e(t));!o.ok&&process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] ${n} threw.`,o.error)}function yp(e){const{apiRef:t,options:n,columns:o}=e,r=!!n,[i,l]=s.useState(!1),[a,c]=s.useState("idle"),[u,g]=s.useState(""),[m,x]=s.useState(null),[y,p]=s.useState(Yn),[f,h]=s.useState(null),[b,w]=s.useState([]),C=s.useRef(null),E=s.useRef(null),S=s.useRef({params:e,applied:f,history:b,open:i});s.useLayoutEffect(()=>{S.current={params:e,applied:f,history:b,open:i}});const N=s.useMemo(()=>{const z=new Map(o.map(H=>[H.field,H.headerName||H.field]));return H=>z.get(H)??H},[o]),M=s.useMemo(()=>f?ls(f.state,N):[],[f,N]),_=s.useCallback(()=>{const z=C.current;C.current=null,z&&z.abort()},[]);s.useEffect(()=>_,[_]);const F=s.useCallback(z=>{if(!S.current.params.options)return;const H=typeof document>"u"?null:document.activeElement;E.current=z??(H instanceof HTMLElement?H:null),l(!0)},[]),A=s.useCallback(()=>{C.current&&(_(),c("stopped"),g("Stopped")),l(!1);const z=E.current;E.current=null,z&&z.isConnected&&z.focus()},[_]),L=s.useCallback(z=>{S.current.open?A():F(z)},[F,A]),k=s.useCallback((z,H)=>{c("error"),g(z),x(null),p(Yn),as(S.current.params.onError,H,"onAiAssistantError")},[]),I=s.useCallback((z,H)=>{const{params:re}=S.current;if(!(typeof H=="object"&&H!==null)||!lp(H.state)){process.env.NODE_ENV!=="production"&&console.warn("[OpenGridX] aiAssistant: the onPrompt result was not applied because its state was not validated. Return the result of createGridAiPromptHandler, or pass the model reply through validateGridAiState (from @opencorestack/opengridx/ai) and return its state."),k(ss,new Error(ss));return}const de=sp(H.state,re.options?.parts??Xn),ie=[...Array.isArray(H.errors)?H.errors:[],...de.errors],ae=dp(de.state,ie),R=t.current,ue=up(ae,R.getGridAiState());dr(R,os(ae,ue)),h({state:ae,previous:ue}),p(ie),x(typeof H.message=="string"&&H.message?H.message:null),w(q=>[...q,{prompt:z,applied:ae}]),c("applied"),g(xp(ls(ae,q=>q).length,ie.length)),as(re.onApply,H,"onAiAssistantApply")},[t,k]),P=s.useCallback(z=>{const H=z.trim(),{params:re,history:ee}=S.current,de=re.options?.onPrompt;if(!H||!de)return;_();const ie=new AbortController;C.current=ie,c("running"),g("Thinking…"),x(null),p(Yn);const ae={currentState:t.current.getGridAiState(),history:ee,signal:ie.signal},R=We(()=>de(H,ae));(R.ok?Promise.resolve(R.value):Promise.reject(R.error)).then(q=>{C.current===ie&&(C.current=null,I(H,q))},q=>{if(C.current===ie){if(C.current=null,ie.signal.aborted||wp(q)){c("stopped"),g("Stopped");return}k(`The assistant could not answer: ${bp(q)}`,q)}})},[t,_,I,k]),v=s.useCallback(()=>{C.current&&(_(),c("stopped"),g("Stopped"))},[_]),B=s.useCallback(()=>{const z=S.current.applied;z&&(dr(t.current,z.previous),h(null),p(Yn),x(null),c("idle"),g("Undone"))},[t]),W=s.useCallback(z=>{const H=S.current.applied;if(!H)return;const re=gp(H.state,z);dr(t.current,os(re,H.previous)),h({state:re,previous:H.previous}),g("Change removed")},[t]);s.useLayoutEffect(()=>{const z=t.current;z.openAiAssistant=()=>F(),z.closeAiAssistant=()=>{S.current.open&&A()}},[t,F,A]);const J=r&&i,G=s.useMemo(()=>!J||!n?null:{status:a,statusText:u,message:m,errors:y,chips:M,history:b,suggestions:n.suggestions??hp,placeholder:n.placeholder??pp,voiceAvailable:n.voice!==!1&&mp(),canUndo:f!==null,submit:P,stop:v,undo:B,removeChip:W,close:A},[J,n,a,u,m,y,M,b,f,P,v,B,W,A]);return{enabled:r,open:J,openPanel:F,togglePanel:L,closePanel:A,panelProps:G,announcement:r?u:""}}function Cp(e){const{toolbar:t,toolbarSlotProps:n,apiRef:o,orderedColumns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:a,pivotMode:c,pivotModelProp:u,onPivotModelChangeProp:g,pivotModel:m,onPivotModelChange:x,filterModel:y,onFilterModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:h,disableColumnReorder:b,columnGroupingModel:w,moveColumn:C,resetColumnOrder:E,forceColumnsOpen:S,onColumnsPanelClose:N,aiAssistantEnabled:M=!1,aiAssistantOpen:_=!1,onAiAssistantToggle:F,aiAssistantLabel:A,forceFiltersOpen:L,onFiltersPanelClose:k}=e;return s.useMemo(()=>t?{apiRef:o,columns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:a,...c||u||g?{pivotModel:m,onPivotModelChange:x}:{},filterModel:y,onFilterModelChange:p,columnVisibilityModel:f,onColumnVisibilityModelChange:h,onColumnReorder:b?void 0:(P,v)=>{Vo(w,P,v)&&C(P,v)},onColumnOrderReset:b?void 0:E,forceColumnsOpen:S,onColumnsPanelClose:N,...M&&F?{onAiAssistantToggle:F,aiAssistantOpen:_,...A?{aiAssistantLabel:A}:{}}:{},forceFiltersOpen:L,onFiltersPanelClose:k,...n}:null,[t,b,C,E,r,o,i,l,a,c,u,g,m,x,y,p,f,h,S,N,n,w,M,_,F,A,L,k])}function vp(e){const{apiRef:t,containerRef:n,aiAssistant:o,toolbar:r,localeText:i}=e,l=rp();Vc(n);const a=yp({apiRef:t,...o}),c=Cp({...r,apiRef:t,forceColumnsOpen:l.toolbarPanelRequested,onColumnsPanelClose:l.closeToolbarPanel,aiAssistantEnabled:a.enabled,aiAssistantOpen:a.open,onAiAssistantToggle:a.togglePanel,aiAssistantLabel:i?.aiAssistantButton,forceFiltersOpen:l.toolbarFiltersRequested,onFiltersPanelClose:l.closeToolbarFiltersPanel});return{columnsPanel:l,aiAssistantPanel:a,toolbarProps:c}}function Sp(e){const{rows:t,columns:n,getRowId:o,rowHeight:r,headerHeight:i,wrapHeaderText:l=!1,headerFilters:a=!1,headerFilterHeight:c=Xf,autoHeight:u=!1,density:g,height:m,className:x="",style:y,ariaLabel:p,loading:f=!1,checkboxSelection:h=!1,disableRowSelectionOnClick:b=!1,disableMultipleRowSelection:w=!1,disableClipboardCopy:C=!1,cellSelection:E=!1,cellSelectionModel:S,onCellSelectionModelChange:N,showCellSelectionStats:M=!1,rowSelectionModel:_,onRowSelectionModelChange:F,onRowClick:A,onRowDoubleClick:L,onCellClick:k,filterModel:I,onFilterModelChange:P,sortModel:v,onSortModelChange:B,pagination:W=!1,paginationModel:J,onPaginationModelChange:G,pageSizeOptions:z=[10,25,50,100],pinnedColumns:H,onPinnedColumnsChange:re,pinnedRows:ee,getDetailPanelContent:de,getDetailPanelHeight:ie,detailPanelExpandedRowIds:ae,onDetailPanelExpandedRowIdsChange:R,pinCheckboxColumn:ue=!0,pinExpandColumn:q=!0,disableColumnReorder:te=!1,columnOrder:V,onColumnOrderChange:U,onColumnOrderModelChange:ce,rowReordering:ge=!1,onRowOrderChange:Q,treeData:D=!1,getTreeDataPath:T,defaultGroupingExpansionDepth:$,groupingColDef:O,rowGroupingModel:Z,onRowGroupingModelChange:j,aggregationModel:ne,onAggregationModelChange:X,getAggregationPosition:Y,isCellEditable:oe,processRowUpdate:he,onProcessRowUpdateError:me,dataSource:K,multiSort:fe=!1,sortingMode:we="client",filterMode:le="client",paginationMode:xe="client",rowCount:Ce,slots:se,slotProps:ye,pivotMode:ke=!1,pivotModel:De,onPivotModelChange:Ne,onRowsScrollEnd:Ie,initialState:Ee,onStateChange:Pe,columnVisibilityModel:pe,onColumnVisibilityModelChange:ve,listView:Se=!1,listViewColumn:be,columnGroupingModel:Le,noRowsLabel:Ue="No Data",localeText:je,apiRef:Nt,overscanRowCount:pt=3,aiAssistant:Be,onAiAssistantApply:gr,onAiAssistantError:Wh}=e,pr=Xg(n),Vh=je?.noRowsLabel??Ue,It=pc({initialState:Ee,sortModel:v,onSortModelChange:B,filterModel:I,onFilterModelChange:P,aggregationModel:ne,onAggregationModelChange:X,rowGroupingModel:Z,onRowGroupingModelChange:j,columnVisibilityModel:pe,onColumnVisibilityModelChange:ve,pinnedColumns:H,onPinnedColumnsChange:re,pivotModel:De,onPivotModelChange:Ne,paginationModel:J,onPaginationModelChange:G,pageSizeOptions:z,rowSelectionModel:_,onRowSelectionModelChange:F,density:g,cellSelectionModel:S,onCellSelectionModelChange:N}),{sortModel:ht,handleSortModelChange:zh,filterModel:Lt,handleFilterModelChange:$s,aggregationModel:rt,handleAggregationModelChange:Rh,columnVisibilityModel:At,handleColumnVisibilityModelChange:hr,pinnedColumns:mr,handlePinnedColumnsChange:Kh,currentPivotModel:Gs,handlePivotModelChange:Uh,effectivePaginationModel:it,handlePaginationModelChange:wr,selectedRowIds:jh,handleRowSelectionModelChange:qh,density:Hs,rowGroupingModel:Bs}=It,mn=hf({rows:t,columns:pr,pivotMode:ke,pivotModel:Gs,filterModel:Lt,sortModel:ht,hasDataSource:!!K,hierarchyRequested:D||Bs.length>0}),mt=mn.isActive,br=a&&!mt,{rowReordering:wn,hierarchyRowGroupingModel:Xh,isTreeDataRequested:Yh,isTreeData:eo,isRowGrouping:Jt,isHierarchyEnabled:to,hasGroupingColumn:Jh,pagination:wt,listView:xr}=dc({rowGroupingModel:Bs,treeData:D,hasTreeDataPath:!!T,isPivotActive:mt,rowReordering:ge,hasGroupingColDef:!!O,pagination:W,paginationMode:xe,listView:Se,hasListViewColumn:!!be}),{rowHeight:Pt,headerHeight:Ws}=xc({rowHeight:r,headerHeight:i,density:Hs}),Zh=mn.rows,Qh=mn.columns,{activeColumns:bt,effectivePinnedColumns:yr}=Vg({baseColumns:Qh,pinnedColumns:mr,hasGroupingColumn:Jh,groupingColDef:O,isTreeData:eo,getTreeDataPath:T}),Cr=Jc(bt,At),[em,tm]=ff(rt),Tt=s.useRef(null),bn=s.useRef(null),Vs=!mt&&o||zg,vr=np(Tt),Sr=nd({rows:Zh,getRowId:Vs,columns:bt,rowHeight:Pt,headerHeight:Ws,columnVisibilityModel:At,initialState:e.initialState,syncRows:!K}),{state:Oe,apiRef:xn,setRows:nm,replaceRows:om,setColumns:rm,setDimensions:im,setDataSourceLoading:lm,setDataSourceError:sm,setRowCount:am}=Sr,{getRowIdOf:$e,getRowIdOfInEvents:cm}=Rg(Oe.rows.idByRow);Kg(Nt,xn);const dm=Oe.dataSource.loading,_r=f||dm,no=s.useMemo(()=>Oe.rows.allRows.map(_n=>Oe.rows.idRowsLookup.get(_n)),[Oe.rows]),{treeDataHandlers:oo,rowGroupingHandlers:kr,activeHierarchyHandlers:Zt,rowMetaMap:qe}=xd({rows:no,getRowId:$e,getTreeDataPath:T,isTreeDataRequested:Yh,isTreeData:eo,columns:bt,rowGroupingModel:Xh,isRowGrouping:Jt,aggregationModel:rt,defaultGroupingExpansionDepth:$,filterModel:Lt,sortModel:ht,getAggregationPosition:Y,columnLookup:Cr,filterMode:le,sortingMode:we}),{editCommitChannel:um,batchEdit:fm,editingHandlers:Er}=Zu({rowsLookup:Oe.rows.idRowsLookup,rows:no,getRowId:$e,columns:bt,processRowUpdate:he,onProcessRowUpdateError:me,replaceRows:om}),Mr=zc({selectedRowIds:jh,rowsLookup:Oe.rows.idRowsLookup,rowMetaMap:qe,enabled:!K&&!mt&&xe==="client"&&le==="client",onSelectionModelChange:qh}),zs=cf({dataSource:K,sortModel:ht,filterModel:Lt,paginationModel:it,paginationMode:xe,sortingMode:we,filterMode:le,aggregationModel:rt,rowGroupingActive:Jt,getRowId:Vs,setRows:nm,setRowCount:am,setDataSourceLoading:lm,setDataSourceError:sm,onAggregationResults:tm,onPaginationModelChange:wr});uf({enabled:eo&&!!K,treeNodes:oo.treeNodes,isGroupExpanded:oo.isGroupExpanded,getNodePath:oo.getNodePath,toggleExpansion:oo.toggleExpansion,fetchChildren:zs.fetchChildren});const{hasDetailPanel:yn,expandedRowIds:Nr,handleDetailPanelToggle:Rs,detailPanelHeights:gm,reportDetailPanelHeight:pm}=Tc({hasDetailPanel:!!de,controlledExpandedRowIds:ae,onDetailPanelExpandedRowIdsChange:R,rowMetaMap:qe}),{effectiveColumns:Ks,hierarchyField:Ir,orderedColumns:Lr,visibleOrderedColumns:Us,renderOrderedColumns:hm,navigationColumns:ro,columnIndexMap:Ar,columnWidths:Pr,effectiveColumnOrder:mm,columnReorderHandlers:wm,moveColumn:js,resetColumnOrder:qs,handleColumnResize:Xs}=Ac({activeColumns:bt,isHierarchyEnabled:to,isRowGrouping:Jt,isTreeData:eo,activeHierarchyHandlers:Zt,columnVisibilityModel:At,columnOrder:V,onColumnOrderChange:U,onColumnOrderModelChange:ce,disableColumnReorder:te,pivotMode:mt,checkboxSelection:h,hasDetailPanel:yn,rowReordering:wn,initialState:Ee,setColumns:rm,pinnedColumns:yr,getRowId:cm,aggregationModel:rt,groupingRows:Jt?kr.groupingRows:void 0});Dc({onStateChange:Pe,sortModel:ht,filterModel:Lt,effectivePaginationModel:it,columnWidths:Pr,effectiveColumnOrder:mm,columnVisibilityModel:At,pinnedColumns:mr,density:Hs});const Tr=Cc({effectiveRows:no,activeHierarchyHandlers:Zt,filterMode:le,filterModel:mn.pipelineFilterModel,sortModel:mn.pipelineSortModel,sortingMode:we,pagination:wt,paginationMode:xe,effectivePaginationModel:it,pinnedRows:ee,getRowId:$e,columnLookup:Cr,hierarchyField:Ir}),{filteredRows:Ys,dataRows:io,pinnedTopRows:ze,pinnedBottomRows:lt,sortedUnpinnedRows:xt,paginatedUnpinnedRows:lo,allRenderableRows:Cn}=Tr,Fr=wt?lo:xt;Zc({paginationModel:it,currentPage:Tr.currentPage,enabled:wt&&!_r&&xt.length>0,onPaginationModelChange:wr});const Js=yc({paginationMode:xe,hasDataSource:!!K,dataSourceRowCount:Oe.pagination.rowCount,rowCountProp:Ce,clientRowCount:xt.length}),{rowSelection:Zs,handleRowClick:Qs,handleSelectionChange:ea}=Yc({controlledState:It,interactions:{dataRows:io,getRowId:$e,isPivotActive:mt,disableRowSelectionOnClick:b,isHierarchyEnabled:to,rowMetaMap:qe,activeHierarchyHandlers:Zt,onRowClick:A},api:{apiRef:Sr.apiRef,multiSort:fe,selectedRowIds:Mr,disableMultipleRowSelection:w,isSyntheticRowId:_n=>Re(_n,qe),getVisibleRows:()=>[...ze,...Fr,...lt],getAllFilteredRows:()=>Ug({hierarchyHandlers:Zt,pinnedTopRows:ze,sortedUnpinnedRows:xt,pinnedBottomRows:lt,rowMetaMap:qe,getRowId:$e,hierarchyField:Ir,dataRows:io}),visibleColumns:hm}}),bm=od({rows:no,getRowId:$e,onRowOrderChange:Q,rowReordering:wn}),{aggregationResult:ta,isLoading:xm}=Ll({rows:io,columns:bt,aggregationModel:mt?ka:rt,isServerSide:Sl({dataSource:K,paginationMode:xe,sortingMode:we,filterMode:le}),dataSource:K,filterModel:Lt,sortModel:ht,serverAggregationResults:em}),Or=Object.keys(rt).length>0&&!mt;Jg({apiRef:xn,hasAggregation:Or,aggregationResult:ta,aggregationModel:rt,isRowGrouping:Jt,rowGroupingHandlers:kr,rowMetaMap:qe,columns:bt,getRowId:$e,hierarchyField:Ir});const Ge=Sa({rowHeight:Pt,pagination:wt,paginatedUnpinnedRows:lo,sortedUnpinnedRows:xt,expandedRowIds:Nr,getDetailPanelHeight:ie,detailPanelHeights:gm,pinnedTopRowsLength:ze.length,pinnedBottomRowsLength:lt.length,pinnedTopRows:ze,pinnedBottomRows:lt,visibleOrderedColumns:Us,pinnedColumns:yr,columnWidths:Pr,viewportWidth:Oe.dimensions.viewportWidth||1e3,checkboxSelection:h,hasDetailPanel:yn,rowReordering:wn,pinCheckboxColumn:ue,pinExpandColumn:q,paginationMode:xe,isLoading:Oe.dataSource.loading,pageSize:it.pageSize,getRowId:$e}),vn=nf({pinnedTopRows:ze,centerRows:Fr,pinnedBottomRows:lt,columns:Us,leftPinnedColumns:Ge.leftPinnedCols,unpinnedColumns:Ge.unpinnedColsWithWidth,rightPinnedColumns:Ge.rightPinnedCols,expandedRowIds:yn?Nr:void 0,rowMetaMap:qe,getRowId:$e}),na=s.useMemo(()=>[...Ge.leftPinnedCols,...Ge.unpinnedColsWithWidth,...Ge.rightPinnedCols],[Ge.leftPinnedCols,Ge.unpinnedColsWithWidth,Ge.rightPinnedCols]),Sn=tp({enabled:E&&!xr,model:It.cellSelectionModel,onModelChange:It.handleCellSelectionModelChange,getPendingModel:It.getPendingCellSelectionModel,allRenderableRows:Cn,getRowId:$e,navigationColumns:ro,columnIndexMap:Ar,spanning:vn,rowMetaMap:qe,layout:Ge,rowHeight:Pt,pinnedTopRowCount:ze.length,viewportRef:bn,containerRef:Tt,localeText:je,showStats:M}),ym=Xu({apiRef:xn,containerRef:Tt,viewportRef:bn,copyColumns:na,getRowId:$e,disableClipboardCopy:C,getCellRangeCopyText:Sn.enabled?Sn.getCopyText:void 0,layout:Ge,rowHeight:Pt,orderedColumns:Lr,onColumnResize:Xs}),{handleScroll:Cm,setViewportElement:vm,maxContentHeight:Sm,virtualization:Ft}=Vu({viewport:{onRowsScrollEnd:Ie,overscanRowCount:pt,autoHeight:u,setDimensions:im},viewportRef:bn,containerRef:Tt,layout:Ge,viewportWidth:Oe.dimensions.viewportWidth,viewportHeight:Oe.dimensions.viewportHeight,virtualization:{autoHeight:u,rowReordering:wn,hasDetailPanel:yn,checkboxSelection:h,pinCheckboxColumn:ue,pinExpandColumn:q}}),{handleSort:oa,handleSortAdd:ra}=jc({sortModel:ht,onSortModelChange:zh}),ia=h||!b,{focusedCell:la,setFocusedCell:sa,viewportTabIndex:_m,ensureGridFocus:km,handleFocus:Em,handleBlur:Mm,handleKeyDown:Nm,handleMouseDownCapture:Im}=cc({allRenderableRows:Cn,navigationColumns:ro,checkboxSelection:h,selectedRowIds:Mr,handleSelectionChange:ea,handleDetailPanelToggle:Rs,editingHandlers:Er,setKeyboardMode:vr,sortModel:ht,handleSort:oa,handleSortAdd:ra,multiSort:fe,isCellEditable:oe,pagination:wt,pageSize:it.pageSize,virtualization:Ft,viewportRef:bn,pinnedTopRowCount:ze.length,getRowId:$e,rowMetaMap:qe,getSpanOrigin:vn.getSpanOrigin,onRowActivate:Qs,toggleRowExpansion:Zt?.toggleExpansion,handleSelectAll:Zs.selectAll,rowSelectionEnabled:ia,multipleRowSelectionEnabled:!w,pinCheckboxColumn:ue,pinExpandColumn:q,rowHeight:Pt,cellSelection:Sn.keyboard,headerFilters:br}),{handleCellClick:Lm,handleHeaderClick:Am}=op({ensureGridFocus:km,setKeyboardMode:vr,setFocusedCell:sa,getRowId:$e,onCellClick:k}),Pm=Fu({props:e,apiRef:xn,containerRef:Tt,viewportRef:bn,selection:Sn,model:It.cellSelectionModel,getPendingModel:It.getPendingCellSelectionModel,focusedCell:la,setFocusedCell:sa,allRenderableRows:Cn,getRowId:$e,navigationColumns:ro,columnIndexMap:Ar,isCellEditable:oe,rowMetaMap:qe,getSpanOrigin:vn.getSpanOrigin,isEditing:Er.editingCell!==null,batchEdit:fm,channel:um,layout:Ge,rowHeight:Pt,pinnedTopRowCount:ze.length}),{handleHideColumn:Tm,handlePinColumn:Fm}=qc({columnVisibilityModel:At,onColumnVisibilityModelChange:hr,pinnedColumns:mr,onPinnedColumnsChange:Kh}),{ariaRows:Om,spanRowWindow:Dm,visibleRows:aa,renderColumns:$m}=Md({aria:{columnGroupingModel:Le,headerFilterRow:br,pinnedTopCount:ze.length,pinnedBottomCount:lt.length,pagination:wt,paginationMode:xe,paginationModel:it,paginationRowCount:Js,paginatedUnpinnedRowCount:lo.length,sortedUnpinnedRowCount:xt.length},spanning:vn,virtualization:Ft,layout:Ge,pinnedTopRows:ze,pinnedBottomRows:lt,paginatedUnpinnedRows:lo,sortedUnpinnedRows:xt,pagination:wt,getRowId:$e});Bc({paginationRequested:W,isRowGrouping:Jt,autoHeight:u,viewportHeight:Oe.dimensions.viewportHeight,renderedRowCount:aa.length,totalRowCount:ze.length+Fr.length+lt.length,pinnedRowsIgnored:to&&!!(ee?.top?.length||ee?.bottom?.length),scrollHeight:Ft.totalHeight,maxContentHeight:Sm,reachableRowCount:_c(Ft.cumulativeHeights,Ft.virtualContainerHeight),unpinnedRowCount:Ft.cumulativeHeights.length,listViewWithoutColumn:Se&&!be,listViewRowCount:xr&&be?Cn.length:0});const Gm=rf(Le,wm),Hm=s.useMemo(()=>Ks.some(_n=>!!_n.rowSpan),[Ks]),{columnsPanel:Bm,aiAssistantPanel:Wm,toolbarProps:Vm}=vp({apiRef:xn,containerRef:Tt,localeText:je,aiAssistant:{options:Be,columns:bt,onApply:gr,onError:Wh},toolbar:{toolbar:se?.toolbar,toolbarSlotProps:ye?.toolbar,orderedColumns:Lr,baseColumns:pr,aggregationModel:rt,onAggregationModelChange:Rh,pivotMode:ke,pivotModelProp:De,onPivotModelChangeProp:Ne,pivotModel:Gs,onPivotModelChange:Uh,filterModel:Lt,onFilterModelChange:$s,columnVisibilityModel:At,onColumnVisibilityModelChange:hr,disableColumnReorder:te,columnGroupingModel:Le,moveColumn:js,resetColumnOrder:qs}}),zm={setViewportElement:vm,handleScroll:Cm,ariaLabel:p,ariaRows:Om,navigationColumnCount:ro.length,rowSelectionEnabled:ia,disableMultipleRowSelection:w,cellSelection:Sn,effectiveLoading:_r,viewportTabIndex:_m,setKeyboardMode:vr,handleMouseDownCapture:Im,handleKeyDown:Nm,handleFocus:Em,handleBlur:Mm,effectivePinnedColumns:yr,virtualization:Ft,renderColumns:$m,renderedDataColumns:na,columnGroupingModel:Le,checkboxSelection:h,rowSelection:Zs,sortModel:ht,handleSort:oa,handleSortAdd:ra,multiSort:fe,handleColumnResize:Xs,handleColumnAutosize:ym,columnWidths:Pr,focusedCell:la,columnIndexMap:Ar,handleHeaderClick:Am,headerReorderHandlers:Gm,rowReordering:wn,hasDetailPanel:yn,pinCheckboxColumn:ue,pinExpandColumn:q,aggregationModel:rt,handleHideColumn:Tm,columnsPanel:Bm,handlePinColumn:Fm,wrapHeaderText:l,headerHeight:Ws,showHeaderFilters:br,filterModel:Lt,handleFilterModelChange:$s,localeText:je,editingHandlers:Er,isCellEditable:oe,selectedRowIds:Mr,handleRowClick:Qs,onRowDoubleClick:L,handleCellClick:Lm,handleSelectionChange:ea,expandedRowIds:Nr,getDetailPanelContent:de,getDetailPanelHeight:ie,handleDetailPanelToggle:Rs,reportDetailPanelHeight:pm,spanning:vn,rowMetaMap:qe,fillHandle:Pm,pinnedTopRows:ze,pinnedBottomRows:lt,pinnedRows:ee,getRowIdOf:$e,showEmptyState:!_r&&!Oe.dataSource.error&&Ys.length===0,effectiveNoRowsLabel:Vh,spanRowWindow:Dm,visibleRows:aa,baseColumns:pr,viewportWidth:Oe.dimensions.viewportWidth,rowReorderHandlers:bm,paginationMode:xe,dataSourceLoading:Oe.dataSource.loading,sortedUnpinnedRowCount:xt.length,pageSize:it.pageSize,unpinnedRowsLength:Ge.unpinnedRowsLength,showAggregationFooter:Or&&kr.rootAggregationPosition!==null,aggregationResult:ta,effectiveRowHeight:Pt,isAggregationLoading:xm,containerRef:Tt,className:x,autoHeight:u,height:m,style:y,hasRowSpanning:Hm,listView:xr,headerFilterHeight:c,slots:se,slotProps:ye,toolbarProps:Vm,aiAssistantPanel:Wm,orderedColumns:Lr,columnVisibilityModel:At,disableColumnReorder:te,handleColumnVisibilityModelChange:hr,moveColumn:js,resetColumnOrder:qs,listViewColumn:be,allRenderableRows:Cn,dataRows:io,pagination:wt,effectivePaginationModel:it,currentPage:Tr.currentPage,pageSizeOptions:z,columnsByField:Cr.byField,paginationRowCount:Js,handlePaginationModelChange:wr,onRowsScrollEnd:Ie,toggleExpansion:Zt?.toggleExpansion,showCellSelectionStats:M,apiRef:Sr.apiRef,hasAggregation:Or,isHierarchyEnabled:to,dataSourceError:Oe.dataSource.error,filteredRowCount:Ys.length,onRetry:K?zs.fetchRows:void 0};return d.jsx(Wg,{...zm})}function _p({rows:e=5,columns:t=5}){return d.jsx("div",{className:"ogx__skeleton",children:Array.from({length:e}).map((n,o)=>d.jsx("div",{className:"ogx__skeleton-row",children:Array.from({length:t}).map((r,i)=>d.jsx("div",{className:"ogx__skeleton-cell",children:d.jsx("div",{className:"ogx__skeleton-content"})},i))},o))})}const kp=300;function jt(e){return"field"in e&&!("items"in e)}function cs(e,t){return e.find(n=>jt(n)&&n.field===t)}function ds(e,t){return Object.is(e,t)?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>ds(n,t[o])):!1}function Ep(e,t){return e===t?!0:jt(e)&&jt(t)?e.id===t.id&&e.field===t.field&&e.operator===t.operator&&ds(e.value,t.value):!jt(e)&&!jt(t)?e.id===t.id&&e.logicOperator===t.logicOperator&&ur(e.items,t.items):!1}function ur(e,t){return e===t?!0:e.length===t.length&&e.every((n,o)=>Ep(n,t[o]))}function Mp(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function us(e,t){return Object.is(e.value,t)?!0:t!=null&&String(e.value).toLowerCase()===String(t).toLowerCase()}function fs(e,t){return _o(e,t.type)}function gs(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function Np(e,t){if(!Dt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const Ip=({col:e,item:t,resetToken:n,onChange:o})=>{const r=s.useId(),i=s.useMemo(()=>Qr(e.type),[e.type]),l=i[0],a=t?.operator??l,c=i.includes(a)?i:[a,...i],u=!!t,g=e.headerName||e.field,[m,x]=s.useState(null),[y,p]=s.useState(n);y!==n&&(p(n),x(null));const f=s.useRef(o),h=s.useRef(t),b=s.useRef(e);s.useLayoutEffect(()=>{f.current=o,h.current=t,b.current=e});const w=s.useCallback((I,P)=>({id:h.current?.id??`${e.field}-${Date.now()}`,field:e.field,operator:I,value:P}),[e.field]),C=s.useCallback(I=>{const P=h.current;if(P?I===fs(P.value,b.current):I.trim()==="")return;const B=P?.operator??l;f.current(w(B,gs(I,B)))},[l,w]),E=s.useRef(null),S=s.useRef(C);s.useLayoutEffect(()=>{E.current=m,S.current=C}),s.useEffect(()=>()=>{const I=E.current;E.current=null,I!==null&&S.current(I)},[]),s.useEffect(()=>{if(m===null)return;const I=setTimeout(()=>{E.current=null,C(m),x(null)},kp);return()=>clearTimeout(I)},[m,C]);const N=I=>{const P=m!==null?gs(m,I):t?.value;x(null),o(w(I,Np(P,I)))},M=()=>{x(null),o(null)},_=!Dt.has(a),F=Mp(e),A=`ogx-filter__value-input${u?" ogx-filter__value-input--active":""}`,L=`Filter value for ${g}`;let k=null;if(_&&e.type==="boolean")k=d.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${A} ogx-filter__value-select`,value:t?.value==null?"":String(t.value),onChange:I=>{I.target.value===""?o(null):o(w(a,I.target.value))},"aria-label":L,children:[d.jsx("option",{value:"",children:"Any"}),d.jsx("option",{value:"true",children:"true"}),d.jsx("option",{value:"false",children:"false"})]});else if(_&&e.type==="singleSelect"&&F.length>0&&a==="isAnyOf"){const I=Array.isArray(t?.value)?t.value:t?.value==null||t.value===""?[]:[t.value];k=d.jsx("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${A} ogx-filter__value-multiselect`,multiple:!0,size:Math.min(F.length,4),value:F.filter(P=>I.some(v=>us(P,v))).map(P=>P.key),onChange:P=>{const v=new Set(Array.from(P.target.selectedOptions,B=>B.value));o(w("isAnyOf",F.filter(B=>v.has(B.key)).map(B=>B.value)))},"aria-label":L,children:F.map(P=>d.jsx("option",{value:P.key,children:P.label},P.key))})}else if(_&&e.type==="singleSelect"&&F.length>0&&(a==="is"||a==="not")){const I=F.find(P=>us(P,t?.value));k=d.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${A} ogx-filter__value-select`,value:I?.key??"",onChange:P=>{const v=F.find(B=>B.key===P.target.value);o(w(a,v?v.value:""))},"aria-label":L,children:[d.jsx("option",{value:"",children:"Any"}),F.map(P=>d.jsx("option",{value:P.key,children:P.label},P.key))]})}else _&&(k=d.jsx(et,{id:`${r}-val`,name:`filter-val-${e.field}`,inputClassName:A,type:e.type==="date"?"date":"text",value:m??fs(t?.value,e),onChange:I=>x(I.target.value),placeholder:e.type==="number"?"Number…":"Value…","aria-label":L}));return d.jsxs("div",{className:`ogx-filter__row${u?" ogx-filter__row--active":""}`,children:[d.jsx("span",{className:"ogx-filter__col-label",title:e.field,children:g}),d.jsxs("div",{className:"ogx-filter__controls",children:[d.jsx("select",{id:`${r}-op`,name:`filter-op-${e.field}`,className:`ogx-filter__op-select${u?" ogx-filter__op-select--active":""}`,value:a,onChange:I=>N(I.target.value),"aria-label":`Filter operator for ${g}`,children:c.map(I=>d.jsx("option",{value:I,children:I},I))}),k,u&&d.jsx("button",{type:"button",className:"ogx-filter__row-clear",onClick:M,"aria-label":`Clear filter for ${g}`,title:"Clear",children:"×"})]})]})},ps=({filterModel:e,columns:t,onFilterModelChange:n})=>{const o=s.useMemo(()=>e.items??[],[e.items]),r=e.logicOperator??"and",[i,l]=s.useState(null),[a,c]=s.useState(o),[u,g]=s.useState(0);if(a!==o){c(o);const h=!ur(a,o),b=i!==null&&ur(i,o);h&&!b&&g(w=>w+1)}const m=s.useCallback((h,b)=>{const w=o.findIndex(E=>jt(E)&&E.field===h);let C;if(w===-1){if(!b)return;C=[...o,b]}else b?C=o.map((E,S)=>S===w?b:E):C=o.filter((E,S)=>S!==w);l(C),n({...e,items:C})},[o,e,n]),x=s.useCallback(h=>{n({...e,logicOperator:h})},[e,n]),y=t.filter(h=>h.filterable!==!1),p=y.filter(h=>cs(o,h.field)).length,f=o.length-p;return d.jsxs(d.Fragment,{children:[o.length>1&&d.jsxs("div",{className:"ogx-filter__logic-bar",children:[d.jsx("span",{className:"ogx-filter__logic-label",children:"Match:"}),d.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>x("and"),"aria-pressed":r==="and",children:"ALL (AND)"}),d.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>x("or"),"aria-pressed":r==="or",children:"ANY (OR)"})]}),f>0&&d.jsx("div",{className:"ogx-filter__hidden-note",role:"note",children:f===1?"1 more condition (a filter group or a second condition on a column) is applied and not shown here.":`${f} more conditions (filter groups or further conditions on a column) are applied and not shown here.`}),y.length===0?d.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):y.map(h=>d.jsx(Ip,{col:h,item:cs(o,h.field),resetToken:u,onChange:b=>m(h.field,b)},h.field))]})},hs=["sum","avg","count","min","max"];function ms(){return d.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:[d.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),d.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),d.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),d.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",fill:"currentColor",opacity:"0.25"}),d.jsx("path",{d:"M17 14v-4M17 10l-2 2 2 2"})]})}function Lp({anchorRef:e,columns:t,model:n,onChange:o,onClose:r}){const i=s.useRef(null),[l,a]=s.useState({top:0,right:0}),[c,u]=s.useState(null);s.useLayoutEffect(()=>{u(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const g=s.useCallback(()=>Nn(e.current,Mt()),[e]);s.useEffect(()=>{a(g());const v=()=>a(g());return window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[g]),s.useEffect(()=>{function v(W){i.current&&!i.current.contains(W.target)&&e.current&&!e.current.contains(W.target)&&r()}function B(W){W.key==="Escape"&&r()}return document.addEventListener("mousedown",v),document.addEventListener("keydown",B),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",B)}},[e,r]);const m=new Set(n.rowFields),x=new Set(n.columnFields),y=new Set(n.valueFields.map(v=>v.field)),p=v=>m.has(v)||x.has(v)||y.has(v),f=v=>t.find(B=>B.field===v),h=v=>f(v)?.headerName??v,b=v=>{const B=f(v)?.availableAggregationFunctions;return B?hs.filter(W=>B.includes(W)):hs},w=v=>v.aggregable!==!1&&(v.type==="number"||v.aggregable===!0)&&b(v.field).length>0,C=v=>v.groupable!==!1;function E(v){m.has(v)||o({...n,rowFields:[...n.rowFields,v]})}function S(v){x.has(v)||o({...n,columnFields:[...n.columnFields,v]})}function N(v){y.has(v)||o({...n,valueFields:[...n.valueFields,{field:v,aggFn:b(v)[0]??"sum"}]})}function M(v){o({...n,rowFields:n.rowFields.filter((B,W)=>W!==v)})}function _(v){o({...n,columnFields:n.columnFields.filter((B,W)=>W!==v)})}function F(v){o({...n,valueFields:n.valueFields.filter((B,W)=>W!==v)})}function A(v,B){o({...n,valueFields:n.valueFields.map((W,J)=>J===v?{...W,aggFn:B}:W)})}function L(){o({rowFields:[],columnFields:[],valueFields:[]})}const k=n.rowFields.length+n.columnFields.length+n.valueFields.length,I=t.filter(v=>!p(v.field)&&(C(v)||w(v))),P=d.jsxs("div",{ref:i,className:"ogx-pivot-panel",role:"dialog","aria-label":"Pivot configuration",style:{top:l.top,right:l.right,left:l.left},children:[d.jsxs("div",{className:"ogx-pivot-panel__header",children:[d.jsxs("span",{className:"ogx-pivot-panel__title",children:[d.jsx(ms,{}),"Pivot Mode"]}),k>0&&d.jsx("button",{type:"button",className:"ogx-pivot-panel__reset-btn",onClick:L,title:"Reset pivot",children:"Reset"})]}),d.jsxs("div",{className:"ogx-pivot-panel__body",children:[d.jsxs("div",{className:"ogx-pivot-zone",children:[d.jsxs("span",{className:"ogx-pivot-zone__label",children:[d.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--row"}),"Row Fields"]}),d.jsx("div",{className:`ogx-pivot-chips${n.rowFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — each becomes a row label",children:n.rowFields.map((v,B)=>d.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[h(v),d.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>M(B),title:`Remove ${h(v)}`,"aria-label":`Remove ${h(v)} from Row Fields`,children:"×"})]},`${B}:${v}`))})]}),d.jsxs("div",{className:"ogx-pivot-zone",children:[d.jsxs("span",{className:"ogx-pivot-zone__label",children:[d.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--col"}),"Column Fields"]}),d.jsx("div",{className:`ogx-pivot-chips${n.columnFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — unique values become column headers",children:n.columnFields.map((v,B)=>d.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[h(v),d.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>_(B),title:`Remove ${h(v)}`,"aria-label":`Remove ${h(v)} from Column Fields`,children:"×"})]},`${B}:${v}`))})]}),d.jsxs("div",{className:"ogx-pivot-zone",children:[d.jsxs("span",{className:"ogx-pivot-zone__label",children:[d.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--value"}),"Value Fields (aggregated)"]}),d.jsx("div",{className:`ogx-pivot-chips${n.valueFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add numeric fields here — values are aggregated",children:n.valueFields.map((v,B)=>{const W=b(v.field),J=W.includes(v.aggFn)?W:[v.aggFn,...W];return d.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[h(v.field),d.jsx("select",{className:"ogx-pivot-chip__fn-select",value:v.aggFn,onChange:G=>A(B,G.target.value),title:"Aggregation function","aria-label":`Aggregation function for ${h(v.field)}`,children:J.map(G=>d.jsx("option",{value:G,children:G.toUpperCase()},G))}),d.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>F(B),title:`Remove ${h(v.field)}`,"aria-label":`Remove ${h(v.field)} (${v.aggFn.toUpperCase()}) from Value Fields`,children:"×"})]},`${B}:${v.field}:${v.aggFn}`)})})]}),d.jsx("hr",{className:"ogx-pivot-panel__divider"}),d.jsxs("div",{children:[d.jsx("div",{className:"ogx-pivot-panel__fields-label",children:"Available Fields"}),d.jsxs("div",{className:"ogx-pivot-fields",children:[I.map(v=>{const B=w(v),W=C(v),J=v.headerName??v.field;return d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[d.jsx("span",{className:`ogx-pivot-field-btn${B?" ogx-pivot-field-btn--numeric":""}`,children:J}),d.jsxs("div",{className:"ogx-pivot-field-actions",children:[W&&d.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>E(v.field),title:"Add to Row Fields","aria-label":`Add ${J} to Row Fields`,children:"Row"}),W&&d.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>S(v.field),title:"Add to Column Fields","aria-label":`Add ${J} to Column Fields`,children:"Col"}),B&&d.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>N(v.field),title:"Add to Value Fields","aria-label":`Add ${J} to Value Fields`,children:"Val"})]})]},v.field)}),I.length===0&&d.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return c?st.createPortal(P,c):null}function Ap(){return d.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("circle",{cx:"11",cy:"11",r:"8"}),d.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Pp(){return d.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function ws(e){return e.trim().split(/\s+/).filter(Boolean).join(" ")}function Tp({value:e="",onChange:t,placeholder:n="Search...",debounceMs:o=250}){const[r,i]=s.useState(()=>e.length>0),[l,a]=s.useState(e),c=s.useRef(null),u=s.useRef(null),g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t},[t]);const m=s.useRef(e),x=s.useRef(e);s.useEffect(()=>{e!==x.current&&(x.current=e,ws(e)!==ws(m.current)&&(a(e),m.current=e,i(e.length>0)))},[e]),s.useEffect(()=>{const w=setTimeout(()=>{l!==m.current&&(m.current=l,g.current(l))},o);return()=>clearTimeout(w)},[l,o]);const y=s.useRef(l);s.useLayoutEffect(()=>{y.current=l}),s.useEffect(()=>()=>{const w=y.current;w!==m.current&&(m.current=w,g.current(w))},[]);const p=s.useCallback(()=>{i(!0),requestAnimationFrame(()=>c.current?.focus())},[]),f=s.useCallback(w=>{w.stopPropagation(),a(""),m.current="",g.current(""),c.current?.focus()},[]),h=s.useCallback(()=>{i(!0)},[]),b=s.useCallback(()=>{setTimeout(()=>{u.current&&document.activeElement&&u.current.contains(document.activeElement)||l||i(!1)},150)},[l]);return s.useEffect(()=>{const w=C=>{u.current&&!u.current.contains(C.target)&&(l||i(!1))};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[l]),d.jsxs("div",{ref:u,className:`ogx-global-search${r?" ogx-global-search--expanded":""}`,onClick:r?void 0:p,children:[d.jsx("div",{className:"ogx-global-search__icon-wrapper",children:d.jsx(Ap,{})}),d.jsx(et,{ref:c,inputClassName:"ogx-global-search__input",value:l,onChange:w=>a(w.target.value),onFocus:h,onBlur:b,placeholder:n,"aria-label":"Global Search",autoComplete:"off"}),l&&d.jsx("button",{type:"button",className:"ogx-global-search__clear",onClick:f,"aria-label":"Clear search",children:d.jsx(Pp,{})})]})}const Jn=8;function gn({title:e,children:t,placement:n="top",enterDelay:o=200,leaveDelay:r=0}){const[i,l]=s.useState(!1),[a,c]=s.useState({top:0,left:0}),[u,g]=s.useState(null),m=s.useRef(null),x=s.useRef(null),y=s.useId(),p=s.useCallback(()=>{if(!x.current)return;const S=x.current.getBoundingClientRect(),N=S.left+S.width/2,M=S.top+S.height/2;switch(n){case"bottom":c({top:S.bottom+Jn,left:N});break;case"left":c({top:M,left:S.left-Jn});break;case"right":c({top:M,left:S.right+Jn});break;default:c({top:S.top-Jn,left:N})}},[n]),f=s.useCallback(()=>{m.current&&clearTimeout(m.current),m.current=null},[]);s.useLayoutEffect(()=>{if(!i)return;p();const S=N=>{N.key==="Escape"&&(f(),l(!1))};return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),document.addEventListener("keydown",S),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p),document.removeEventListener("keydown",S)}},[i,p,f]),s.useEffect(()=>f,[f]);const h=()=>{f(),m.current=setTimeout(()=>{g(x.current?.closest(".ogx-theme-provider")??document.body),l(!0)},o)},b=()=>{f(),m.current=setTimeout(()=>{l(!1)},r)},w=s.useCallback(S=>{x.current=S?S.firstElementChild??S:null},[]),C=i&&!!e&&u!==null;let E=t;if(C&&s.isValidElement(t)){const S=t,N=S.props["aria-describedby"];E=s.cloneElement(S,{"aria-describedby":N?`${N} ${y}`:y})}return d.jsxs(d.Fragment,{children:[d.jsx("span",{ref:w,style:{display:"inline-block",lineHeight:0},onMouseEnter:h,onMouseLeave:b,onFocus:h,onBlur:b,children:E}),C&&u&&st.createPortal(d.jsx("div",{id:y,role:"tooltip",className:`ogx-tooltip ogx-tooltip--${n}`,style:{top:a.top,left:a.left,position:"fixed",zIndex:99999},children:e}),u)]})}const Fp=Object.keys(at);function Op(e){return Object.prototype.hasOwnProperty.call(at,e)}function bs(e){return e.availableAggregationFunctions?Array.from(new Set(e.availableAggregationFunctions.filter(Op))):Fp}function xs(){return d.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:d.jsx("path",{d:"M18 4H6l6 8-6 8h12"})})}function Dp(){return d.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",children:[d.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.25"}),d.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),d.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function ys(){return d.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:d.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function $p({anchorRef:e,aggregationModel:t,aggregableColumns:n,onFunctionChange:o,onClearAll:r,onClose:i,activeCount:l}){const a=s.useRef(null),[c,u]=s.useState({top:0,right:0}),[g,m]=s.useState(null);s.useLayoutEffect(()=>{m(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const x=s.useCallback(()=>Nn(e.current,Mt()),[e]);s.useEffect(()=>{u(x());const p=()=>u(x());return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[x]),s.useEffect(()=>{function p(f){a.current&&!a.current.contains(f.target)&&e.current&&!e.current.contains(f.target)&&i()}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[e,i]),s.useEffect(()=>{function p(f){f.key==="Escape"&&i()}return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[i]);const y=d.jsxs("div",{ref:a,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:c.top,right:c.right,left:c.left,width:400,maxWidth:"calc(100vw - 24px)"},children:[d.jsxs("div",{className:"ogx-toolbar__panel-header",children:[d.jsxs("span",{className:"ogx-toolbar__panel-title",children:[d.jsx(xs,{}),"Summaries"]}),l>0&&d.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:r,title:"Clear all summaries",children:"Clear all"})]}),d.jsx("div",{className:"ogx-toolbar__panel-body",children:n.length===0?d.jsxs("p",{className:"ogx-toolbar__empty",children:["No aggregable columns.",d.jsx("br",{}),"Set ",d.jsx("code",{children:"aggregable: true"})," on a column to enable."]}):n.map(p=>{const f=t[p.field]||"none";return d.jsxs("div",{className:"ogx-toolbar__agg-row",children:[d.jsx("span",{className:"ogx-toolbar__agg-label",title:p.field,children:p.headerName||p.field}),d.jsx("div",{className:"ogx-toolbar__agg-pills",children:["none",...bs(p)].map(h=>d.jsx("button",{type:"button",className:`ogx-toolbar__pill${f===h?" ogx-toolbar__pill--active":""}`,onClick:()=>o(p.field,h),"aria-pressed":f===h,children:h},h))})]},p.field)})})]});return g?st.createPortal(y,g):null}function Gp({anchorRef:e,columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:a,onClose:c,showNonHideableColumns:u}){const g=s.useRef(null),[m,x]=s.useState({top:0,right:0}),[y,p]=s.useState(null);s.useLayoutEffect(()=>{p(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const f=s.useCallback(()=>Nn(e.current,Mt()),[e]);s.useEffect(()=>{x(f());const b=()=>x(f());return window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[f]),s.useEffect(()=>{function b(w){g.current&&!g.current.contains(w.target)&&e.current&&!e.current.contains(w.target)&&c()}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[e,c]),s.useEffect(()=>{function b(w){w.key==="Escape"&&c()}return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[c]);const h=d.jsx("div",{ref:g,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:m.top,right:m.right,left:m.left,width:280,padding:0},children:d.jsx(Qo,{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:a,showNonHideableColumns:u})});return y?st.createPortal(h,y):null}function Hp({anchorRef:e,columns:t,filterModel:n,onFilterModelChange:o,onClose:r}){const i=s.useRef(null),[l,a]=s.useState({top:0,right:0}),c=s.useRef(r);s.useLayoutEffect(()=>{c.current=r},[r]);const[u,g]=s.useState(null);s.useLayoutEffect(()=>{g(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const m=s.useCallback(()=>Nn(e.current,Mt()),[e]);s.useEffect(()=>{a(m());const f=()=>a(m());return window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[m]),s.useEffect(()=>{function f(h){h.key==="Escape"&&c.current()}return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[]);const x=n.items?.length??0,y=()=>{o({...n,items:[],logicOperator:"and"})},p=d.jsxs("div",{ref:i,className:"ogx-toolbar__panel ogx-toolbar__panel--filter",role:"dialog","aria-label":"Advanced filters",style:{top:l.top,right:l.right,left:l.left,width:540,maxWidth:"calc(100vw - 24px)"},children:[d.jsxs("div",{className:"ogx-toolbar__panel-header",children:[d.jsxs("span",{className:"ogx-toolbar__panel-title",children:[d.jsx(ys,{}),"Filters",x>0&&d.jsx("span",{className:"ogx-toolbar__panel-count",children:x})]}),d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[x>0&&d.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:y,title:"Clear all filters",children:"Clear all"}),d.jsx("button",{type:"button",className:"ogx-toolbar__close-btn",onClick:()=>c.current(),title:"Close filters","aria-label":"Close filters panel",children:"Close"})]})]}),d.jsx("div",{className:"ogx-toolbar__panel-body ogx-toolbar__panel-body--filter",children:d.jsx(ps,{columns:t,filterModel:n,onFilterModelChange:o})})]});return u?st.createPortal(p,u):null}const Bp={rowFields:[],columnFields:[],valueFields:[]},Wp=[];function Vp({columns:e=Wp,baseColumns:t,aggregationModel:n={},onAggregationModelChange:o,pivotModel:r,onPivotModelChange:i,filterModel:l,onFilterModelChange:a,columnVisibilityModel:c={},onColumnVisibilityModelChange:u,onColumnReorder:g,onColumnOrderReset:m,forceColumnsOpen:x,onColumnsPanelClose:y,forceFiltersOpen:p,onFiltersPanelClose:f,children:h,rightContent:b,style:w,renderColumnsButton:C,renderFilterButton:E,renderAggregationButton:S,renderExportButton:N,renderQuickFilter:M,className:_,showNonHideableColumns:F,onAiAssistantToggle:A,aiAssistantOpen:L=!1,aiAssistantLabel:k="Ask AI"}){const[I,P]=s.useState(x?"columns":null),v=I==="summaries",B=I==="pivot",W=I==="columns",J=I==="filters",G=le=>{I==="columns"&&le!=="columns"&&y?.(),I==="filters"&&le!=="filters"&&f?.(),P(le)},z=le=>G(I===le?null:le),H=le=>{I===le&&G(null)},[re,ee]=s.useState(x);re!==x&&(ee(x),x&&P("columns"));const[de,ie]=s.useState(p);de!==p&&(ie(p),p&&a&&P("filters"));const ae=s.useContext(Al),R=x!==void 0&&!!u;s.useEffect(()=>{if(!(!ae||!R))return ae.registerColumnsPanel()},[ae,R]);const ue=p!==void 0&&!!a;s.useEffect(()=>{if(!(!ae||!ue))return ae.registerFiltersPanel()},[ae,ue]);const q=s.useRef(null),te=s.useRef(null),V=s.useRef(null),U=s.useRef(null),ce=s.useRef(null),ge=s.useRef(null),Q=s.useRef(null),D=s.useRef(null),T=r??Bp,$=T.rowFields.length>0||T.columnFields.length>0||T.valueFields.length>0,O=t?new Set(t.map(le=>le.field)):null,Z=e.filter(le=>le.aggregable!==!1&&(le.type==="number"||le.aggregable===!0)&&bs(le).length>0&&(!O||O.has(le.field))),j=Object.keys(n).filter(le=>n[le]&&n[le]!=="none").length,ne=s.useCallback((le,xe)=>{if(!o)return;const Ce={...n};xe==="none"?delete Ce[le]:Ce[le]=xe,o(Ce)},[n,o]),X=s.useCallback(()=>{o?.({})},[o]),Y=s.useCallback(le=>{if(!a)return;const xe=le.trim().split(/\s+/).filter(Boolean),Ce={...l||{},quickFilterValues:xe,items:l?.items||[]};a(Ce)},[l,a]),oe=(l?.quickFilterValues??[]).join(" "),he=l?.items?.length||0,me=new Set(e.filter(le=>c[le.field]!==!1).map(le=>le.field)),K=s.useCallback((le,xe)=>{if(!u)return;const Ce={...c,[le]:xe};u(Ce)},[c,u]),fe=s.useCallback(()=>{if(!u)return;const le={...c};e.forEach(xe=>{xe.hideable!==!1&&(le[xe.field]=!0)}),u(le)},[e,c,u]),we=s.useCallback(()=>{if(!u)return;const le={...c};e.forEach(xe=>{xe.hideable!==!1&&(le[xe.field]=!1)}),u(le)},[e,c,u]);return d.jsxs("div",{className:["ogx-toolbar",_].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:w,children:[h&&d.jsx("div",{className:"ogx-toolbar__left",children:h}),d.jsx("div",{className:"ogx-toolbar__spacer"}),d.jsxs("div",{className:"ogx-toolbar__actions",children:[A&&d.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:d.jsxs("button",{type:"button",ref:te,className:`ogx-toolbar__icon-btn ogx-toolbar__ai-btn${L?" ogx-toolbar__icon-btn--active":""}`,"aria-haspopup":"dialog","aria-expanded":L,onClick:()=>{G(null),A(te.current)},children:[d.jsx(Pl,{}),k]})}),a&&d.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:M?M({value:oe,onChange:Y}):d.jsx(Tp,{value:oe,onChange:Y,placeholder:"Search..."})}),u&&d.jsxs("div",{ref:ge,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[C?C({onClick:()=>z("columns"),isOpen:W,activeCount:e.length-me.size}):d.jsx(gn,{title:"Columns",children:d.jsx("button",{type:"button",ref:U,className:`ogx-toolbar__icon-btn${W?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns","aria-haspopup":"dialog","aria-expanded":W,onClick:()=>z("columns"),children:d.jsx(Dp,{})})}),W&&d.jsx(Gp,{anchorRef:C?ge:U,columns:e,visibleColumns:me,onVisibilityChange:K,onShowAll:fe,onHideAll:we,onColumnReorder:g,onColumnOrderReset:m,onClose:()=>H("columns"),showNonHideableColumns:F})]}),a&&d.jsxs("div",{ref:Q,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[E?E({onClick:()=>z("filters"),isOpen:J,activeCount:he}):d.jsx(gn,{title:"Filters",children:d.jsxs("button",{type:"button",ref:ce,className:`ogx-toolbar__icon-btn${J?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters","aria-haspopup":"dialog","aria-expanded":J,onClick:()=>z("filters"),children:[d.jsx(ys,{}),he>0&&d.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),J&&d.jsx(Hp,{anchorRef:E?Q:ce,columns:e,filterModel:l||{items:[]},onFilterModelChange:a,onClose:()=>H("filters")})]}),i&&d.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[d.jsx(gn,{title:"Pivot",children:d.jsxs("button",{type:"button",ref:V,className:`ogx-toolbar__icon-btn${B?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-haspopup":"dialog","aria-expanded":B,onClick:()=>z("pivot"),children:[d.jsx(ms,{}),$&&d.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),B&&d.jsx(Lp,{anchorRef:V,columns:t??e,model:T,onChange:le=>{i?.(le)},onClose:()=>H("pivot")})]}),o&&d.jsxs("div",{ref:D,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[S?S({onClick:()=>z("summaries"),isOpen:v,activeCount:j}):d.jsx(gn,{title:"Summaries",children:d.jsxs("button",{type:"button",ref:q,className:`ogx-toolbar__icon-btn${v?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-haspopup":"dialog","aria-expanded":v,onClick:()=>z("summaries"),children:[d.jsx(xs,{}),j>0&&d.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${j} active summaries`})]})}),v&&d.jsx($p,{anchorRef:S?D:q,aggregationModel:n,aggregableColumns:Z,onFunctionChange:ne,onClearAll:X,onClose:()=>H("summaries"),activeCount:j})]}),N&&N(),b]})]})}function zp(){const[e]=s.useState(zi);return s.useRef(e)}function qt(e,t){if(e.groupLabel!==void 0)return e.groupLabel;const n=e.groupField??"",o=t.find(r=>r.field===n)?.groupingValueFormatter;return o?o({field:n,value:e.groupValue}):`${n}: ${String(e.groupValue??"")}`}const Rp=new Set([8364,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,381,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,382,376]);function Kp(e){return e>=8192&&e<=8202||e===8239||e===8287||e===12288?" ":e>=8203&&e<=8205||e===8288||e===65279?"":e===8208||e===8209||e===8210||e===8722?"-":null}function Up(e){let t="",n=!1;for(const o of e){const r=o.codePointAt(0)??0;if(r<=255||Rp.has(r)){t+=o;continue}const i=Kp(r);i!==null?t+=i:(t+="?",n=!0)}return{text:t,lossy:n}}const jp={sliceMs:30,renderChunkRows:40},qp=2e4;function Cs(){return new Promise(e=>setTimeout(e,0))}function Xp(){return new DOMException("PDF export was aborted","AbortError")}const Xt=()=>typeof performance<"u"?performance.now():Date.now(),vs=e=>Math.max(2,Math.floor(e/2)*2),Yp=[79,70,229],Jp=[255,255,255];function Ss(e,t){const n=e.trim().replace(/^#/,""),o=/^[a-f\d]{3}$/i.test(n)?n.split("").map(i=>i+i).join(""):n,r=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);return r?[parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16)]:t}function _s(e,t){return dn(e,t,cn(e,t))}function ks(e){return(typeof e.width=="number"?e.width:void 0)??(e.flex??1)*100}function Zp(e,t){const n=e.reduce((r,i)=>r+ks(i),0),o={};return e.forEach((r,i)=>{o[i]={cellWidth:ks(r)/n*t}}),o}const Qp=new Set(["isEmpty","isNotEmpty"]);function eh(e,t){const o=t.find(l=>l.field===e.field)?.headerName??e.field;if(Qp.has(e.operator))return`${o} ${e.operator}`;const{value:r}=e;if(r==null||r===""||Array.isArray(r)&&r.length===0)return null;const i=Array.isArray(r)?r.map(String).join(", "):String(r);return`${o} ${e.operator} "${i}"`}function Es(e,t,n,o){const r=e.map(l=>"items"in l?Es(l.items,l.logicOperator,n,!0):eh(l,n)).filter(l=>!!l);if(r.length===0)return"";const i=r.join(t==="or"?" OR ":" AND ");return o&&r.length>1?`(${i})`:i}function th(e,t){const n=[],o=Es(e.items??[],e.logicOperator??"and",t,!1);o&&n.push(o);const r=(e.quickFilterValues??[]).filter(i=>i.trim()!=="");return r.length>0&&n.push(`Search: ${r.map(i=>`"${i}"`).join(" ")}`),n.join(" • ")}const nh=1.15*.3528;function oh(e,t,n={}){return rh(e,t,n,jp)}async function rh(e,t,n,o){const{signal:r,onProgress:i}=n,l=()=>{if(r?.aborted)throw Xp()};l();let a,c;try{const[X,Y]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);a=X.default,c=Y.default}catch{throw new Error("exportToPdf requires 'jspdf' and 'jspdf-autotable'. Run: npm install jspdf jspdf-autotable")}const{fileName:u="export",title:g,logoUrl:m,orientation:x="landscape",selectedRows:y,getRowId:p,aggregationResult:f,aggregationModel:h,filterModel:b,alternateRowColor:w=!0,headerBackgroundColor:C="#4f46e5",headerTextColor:E="#ffffff",fontSize:S=9,groupedRows:N,font:M,maxRows:_=qp}=n;l();let F=Xt();const A=async()=>{Xt()-F<o.sliceMs||(await Cs(),l(),F=Xt())},L=(X,Y,oe)=>{i?.({phase:X,done:Y,total:oe})},k=new a({orientation:x,unit:"mm",format:"a4"}),I=k.internal.pageSize.getWidth(),P=k.internal.pageSize.getHeight(),v=14,B=I-v*2;let W="helvetica";M&&(k.addFileToVFS(`${M.name}-normal.ttf`,M.data),k.addFont(`${M.name}-normal.ttf`,M.name,"normal"),M.boldData&&k.addFileToVFS(`${M.name}-bold.ttf`,M.boldData),k.addFont(M.boldData?`${M.name}-bold.ttf`:`${M.name}-normal.ttf`,M.name,"bold"),W=M.name);let J=!1;const G=X=>{if(M)return X;const Y=Up(X);return Y.lossy&&(J=!0),Y.text},z=(X,Y,oe,he,me)=>{const K=k.splitTextToSize(G(X),he);return k.text(K.length===1?K[0]:K,Y,oe),Math.max(0,K.length-1)*me*nh},H=Et(t),re=an(N,y),ee=sn(e,y,p);let de=v;if(g){let X=v,Y=v+8;if(m)try{k.addImage(m,"PNG",X,v,10,10),X+=14}catch{}const oe=I-v-X;k.setFontSize(16),k.setFont(W,"bold"),k.setTextColor(30,41,59),Y+=z(g,X,Y,oe,16),Y+=6,k.setFontSize(8),k.setFont(W,"normal"),k.setTextColor(100,116,139);const he=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),me=re?N.filter(K=>K.type==="leaf").length:ee.length;if(k.text(G(`Exported: ${he} • ${me} row${me!==1?"s":""}`),X,Y),Y+=5,b){const K=th(b,t);K&&(Y+=z(`Filters: ${K}`,X,Y,oe,8),Y+=5)}k.setDrawColor(226,232,240),k.setLineWidth(.3),k.line(v,Y+2,I-v,Y+2),de=Y+6}const ie=[H.map(X=>G(X.headerName??X.field))],ae=h||{},R=X=>H.map(Y=>zo(Y,ae[Y.field],X[Y.field],X)),ue=[];let q;const te=X=>{ue.push(X.map(G))};if(re){const X=N.length;L("prepare",0,X);for(let Y=0;Y<X;Y++){const oe=N[Y],he=" ".repeat(oe.depth*2);if(oe.type==="group-header"){const me=`${he}${qt(oe,t)}`;te(H.map((K,fe)=>fe===0?me:""))}else if(oe.type==="leaf"&&oe.row){const me=oe.row;te(H.map((K,fe)=>(fe===0?he:"")+_s(me,K)))}else if(oe.type==="group-subtotal"&&oe.aggregatedValues){const me=R(oe.aggregatedValues);te(me.map((K,fe)=>fe===0?`${he}${Wt("Subtotal",K)}`:K))}else oe.type==="grand-total"&&oe.aggregatedValues&&(q=[R(oe.aggregatedValues).map((K,fe)=>fe===0?Wt("Grand Total",K):K).map(G)]);(Y&63)===63&&(L("prepare",Y+1,X),await A())}L("prepare",X,X)}else{const X=ee.length;L("prepare",0,X);for(let oe=0;oe<X;oe++)te(H.map(he=>_s(ee[oe],he))),(oe&63)===63&&(L("prepare",oe+1,X),await A());const Y=h?Bt(ee,dt(y),t,f,h):null;if(Y&&h){const oe=H.some(me=>h[me.field]);q=[R(Y).map((me,K)=>K===0&&oe?Wt("TOTAL",me):me).map(G)]}L("prepare",X,X)}l(),ue.length>_&&process.env.NODE_ENV!=="production"&&console.warn(`[exportToPdf] Exporting ${ue.length} table rows (maxRows: ${_}). PDFs this large are slow to build and open and can reach tens of MB. Prefer exportToCsv or exportToExcelAdvanced for full-dataset exports, or pass a larger \`maxRows\` to silence this warning.`),J&&console.warn('[exportToPdf] Some characters cannot be drawn with the built-in Helvetica font and were replaced with "?". Pass the `font` option (a Unicode .ttf, e.g. Noto Sans) to draw them.');const V=Zp(H,B),[U,ce,ge]=Ss(C,Yp),[Q,D,T]=Ss(E,Jp),$={head:ie,styles:{fontSize:S,cellPadding:3,font:W,overflow:"linebreak"},headStyles:{fillColor:[U,ce,ge],textColor:[Q,D,T],fontStyle:"bold"},...w?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...q?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:V,showHead:"everyPage",margin:{top:v,left:v,right:v,bottom:v+6}},O=ue.length;L("render",0,O);let Z=0,j=vs(o.renderChunkRows);do{const X=ue.slice(Z,Z+j),Y=Z===0,oe=Z+X.length>=O,he=Y?de:k.lastAutoTable.finalY;let me=!0;const K=Xt();c(k,{...$,body:X,...oe&&q?{foot:q}:{},startY:Y?de:v,showFoot:oe&&q?"lastPage":"never",...Y?{}:{willDrawPage:we=>{me?(me=!1,we.settings.showHead="never",we.cursor&&(we.cursor.y=he)):we.settings.showHead="everyPage"}}}),Z+=X.length,L("render",Z,O);const fe=Xt()-K;j=vs(fe>0?Math.min(j*4,j*(o.sliceMs/fe)):j*4),oe||(await Cs(),l(),F=Xt())}while(Z<O);const ne=k.getNumberOfPages();for(let X=1;X<=ne;X++)k.setPage(X),k.setFontSize(8),k.setTextColor(150,150,150),k.text(`Page ${X} of ${ne}`,I-v,P-8,{align:"right"}),await A();l(),L("save",0,1),k.save(`${u}.pdf`),L("save",1,1)}function pn(e,t){const n=cn(e,t),o=dn(e,t,n);return{text:o,raw:n,fromNonText:Pd(n,o,!!t.valueFormatter)}}function Yt(e,t,n){return e.map(o=>zo(o,n[o.field],t[o.field],t))}const ih="\uFEFF";function lh(e,t,n={}){const{fileName:o="export.csv",includeHeaders:r=!0,delimiter:i=",",selectedRows:l,groupedRows:a,escapeFormulas:c=!0,bom:u=!0}=n,g=Et(t),m=n.aggregationModel||{},x=(f,h=!1)=>Zn(c?Rn(f,h):f,i),y=()=>g.map(f=>x(f.headerName||f.field)).join(i)+`
|
|
8
|
-
`;let
|
|
9
|
-
`}else if(f.type==="leaf"&&f.row){const b=f.row,
|
|
10
|
-
`}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const b=f.aggregatedValues,
|
|
11
|
-
`}});else{const f=
|
|
12
|
-
`});const
|
|
13
|
-
`;const
|
|
14
|
-
`}}
|
|
15
|
-
`)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}const
|
|
3
|
+
`).forEach(z=>console.warn(z))},[C]);const E=r&&!o;s.useEffect(()=>{process.env.NODE_ENV==="production"||!E||console.warn("[OpenGridX] treeData is set without getTreeDataPath, so the rows are shown as a flat list. Pass getTreeDataPath={(row) => row.path} to build the tree.")},[E]);const _=s.useMemo(()=>g==="server"?null:Tn(l,u),[g,l,u]),I=s.useMemo(()=>hd(y,_),[y,_]),M=`${r}|${i}`,[S,F]=s.useState(()=>({configKey:M,overrides:new Map})),P=S.configKey===M?S.overrides:el,L=s.useCallback(z=>((z?.children?.length??0)>0||(z?.serverChildrenCount??0)>0)&&(i===-1||(z?.depth??0)<i),[i]),k=s.useMemo(()=>{const z=new Set;return x&&h.forEach((V,ie)=>{(P.get(ie)??L(V))&&z.add(ie)}),z},[x,h,P,L]),N=s.useCallback(z=>{const V=!k.has(z);if(F(ie=>{const te=ie.configKey===M?ie.overrides:el,ce=new Map(te);return ce.set(z,V),{configKey:M,overrides:ce}}),V&&a){const ie=h.get(z);ie&&a(ie)}},[k,M,h,a]),T=p!=="server"&&!!(c&&c.length>0),v=s.useCallback(z=>{if(!x)return null;const V=z?.labelField,ie=z?.expandAll??!1,{visible:te,visibleChildren:ce}=I,oe=T&&c?c:[],de=(Y,H)=>{if(b.has(Y))return{value:H.field===V?h.get(Y)?.label:void 0};const R=m.get(Y),ae=u?.byField.get(H.field),ge=R?Ee(R,H.field,ae):void 0,J=ae?.sortComparator;return{value:ge,type:ae?.type,comparator:J,params:J&&R?{id:Y,field:H.field,row:R,value:ge}:void 0}},X=[],ne=new Set,se=Y=>{const H=Y.filter(ae=>te.has(ae)),R=oe.length>0?ci(H,oe,de):H;for(const ae of R){if(ne.has(ae))continue;const ge=m.get(ae);if(!ge)continue;ne.add(ae),X.push(ge);const J=ce.get(ae);J&&J.length>0&&(ie||k.has(ae))&&se(J)}};return se(f),X},[x,I,T,c,b,h,m,u,f,k]),W=s.useCallback(z=>k.has(z),[k]),B=s.useCallback(z=>h.get(z),[h]),Q=s.useCallback(z=>{const V=[];let ie=z;for(;ie!==null;){const te=h.get(ie);if(!te)break;V.unshift(te.groupingKey),ie=te.parentId}return V},[h]),$=s.useMemo(()=>{const z=new Map,{visibleChildren:V,descendantCounts:ie}=I;return h.forEach((te,ce)=>{const oe=(te.children?.length??0)===0&&(te.serverChildrenCount??0)>0,de=b.has(ce),X={hasChildren:(V.get(ce)?.length??0)>0||oe,treeDepth:te.depth,descendantCount:oe?void 0:ie.get(ce)??0,isGroupRow:de,isExpanded:k.has(ce)};de&&(X.groupLabel=te.label),z.set(ce,X)}),z},[h,b,I,k]);return s.useMemo(()=>({treeNodes:h,groupingRows:w,toggleExpansion:N,isGroupExpanded:W,getVisibleRows:v,getNode:B,getNodePath:Q,rowMetaMap:$}),[h,w,N,W,v,B,Q,$])}class wd{base;top;constructor(t,n){this.base=t,this.top=n}get size(){return this.base.size+this.top.size}get(t){const n=this.top.get(t);return n!==void 0||this.top.has(t)?n:this.base.get(t)}has(t){return this.top.has(t)||this.base.has(t)}forEach(t,n){this.base.forEach((o,r)=>t.call(n,o,r,this)),this.top.forEach((o,r)=>t.call(n,o,r,this))}*entries(){yield*this.base.entries(),yield*this.top.entries()}*keys(){yield*this.base.keys(),yield*this.top.keys()}*values(){yield*this.base.values(),yield*this.top.values()}[Symbol.iterator](){return this.entries()}}const rl=e=>e===null?"footer":"inline";function il(e,t){return go(()=>e(t),rl(t),"getAggregationPosition","getAggregationPosition threw; the default position is used")}function bd(e,t,n){const o=`${t}: ${String(n)}`,r=e?.groupingValueFormatter;return r?go(()=>r({field:t,value:n}),o,`groupingValueFormatter:${t}`,`groupingValueFormatter for column "${t}" threw; the group is labelled "${t}: value"`):o}const xd=[],yd={},ll=new Map,Ze="";function Cd(e){if(typeof e=="string")return e;if(e===null)return`${Ze}null`;if(e===void 0)return`${Ze}undefined`;if(e instanceof Date)return`${Ze}date:${e.getTime()}`;if(typeof e=="object")try{return`${Ze}object:${JSON.stringify(e)}`}catch{return`${Ze}object:${String(e)}`}return`${Ze}${typeof e}:${String(e)}`}const vd=(e,t,n)=>`auto-group-${e}-${t}-${n??"root"}`,Sd=e=>`${e}${Ze}footer`,_d=e=>e==="footer"?"f":e===null?"n":"i",kd=e=>e==="f"?"footer":e==="n"?null:"inline";function Ed(e){const{rows:t,getRowId:n,columns:o,rowGroupingModel:r=xd,aggregationModel:i=yd,defaultGroupingExpansionDepth:l=0,filterModel:c,sortModel:a,getAggregationPosition:u=rl,columnLookup:g,filterMode:p="client",sortingMode:x="client"}=e,y=r.join(Ze),h=s.useMemo(()=>y===""?[]:y.split(Ze),[y]),f=JSON.stringify(Object.entries(i)),w=s.useMemo(()=>Object.fromEntries(JSON.parse(f)),[f]),b=Object.keys(w).length>0,m=s.useMemo(()=>{const Y=new Map;return(o??[]).forEach(H=>Y.set(H.field,H)),Y},[o]),C=h.length>0,E=s.useMemo(()=>h.filter(Y=>m.get(Y)?.groupable!==!1),[h,m]),I=`${E.join(Ze)}|${l}`,[M,S]=s.useState(()=>({configKey:I,overrides:new Map})),F=M.configKey===I?M.overrides:ll,P=s.useMemo(()=>{if(!C||p==="server")return null;const Y=Tn(c,g);return Y?new Set(t.filter(H=>Y(H))):null},[C,t,p,c,g]),L=s.useMemo(()=>{const Y=new Map,H=[],R=[],ae=new Map,ge=new Map,J=new Map;if(!C)return{treeNodes:Y,rootIds:H,groupIds:R,groupRowVariants:ae,groupingRows:ge,rowLookup:J};const O=(A,G,D)=>{if(G>=E.length)return(P?A.filter(re=>P.has(re)):A).map(re=>{const me=n(re);return J.set(me,re),Y.set(me,{id:me,parentId:D,depth:G,groupingKey:"",isExpanded:!1}),me});const U=E[G],q=m.get(U),ee=new Map;for(const j of A){const re=Ee(j,U,q),me=Cd(re);let pe=ee.get(me);pe||(pe={value:re,rows:[]},ee.set(me,pe)),pe.rows.push(j)}const Z=[];return ee.forEach((j,re)=>{const me=P?j.rows.filter(Ce=>P.has(Ce)):j.rows;if(me.length===0)return;const pe=vd(U,re,D);Z.push(pe),R.push(pe);const K=b?Ln(me,w,m,"useRowGrouping"):{},fe={[U]:j.value,...K,id:pe},we={[U]:j.value,id:pe},le=b?{...K,id:Sd(pe)}:null;ae.set(pe,{inline:fe,bare:we,footer:le}),ge.set(pe,fe),le&&ge.set(le.id,le);const be={id:pe,parentId:D,depth:G,groupingKey:String(j.value),groupingField:U,groupingValue:j.value,aggregatedValues:K,isExpanded:!1,children:[],label:bd(q,U,j.value),descendantCount:me.length};Y.set(pe,be),be.children=O(j.rows,G+1,pe)}),Z};return H.push(...O(t,0,null)),{treeNodes:Y,rootIds:H,groupIds:R,groupRowVariants:ae,groupingRows:ge,rowLookup:J}},[C,t,P,E,b,w,n,m]),{treeNodes:k,rootIds:N,groupIds:T,groupRowVariants:v,groupingRows:W,rowLookup:B}=L,Q=s.useCallback(Y=>!!(Y?.children&&Y.children.length>0)&&(l===-1||(Y?.depth??0)<l),[l]),$=s.useMemo(()=>{const Y=new Set;for(const H of T){const R=k.get(H);!R?.children||R.children.length===0||(F.get(H)??Q(R))&&Y.add(H)}return Y},[T,k,F,Q]),z=s.useCallback(Y=>{S(H=>{const R=H.configKey===I?H.overrides:ll,ae=R.get(Y)??Q(k.get(Y)),ge=new Map(R);return ge.set(Y,!ae),{configKey:I,overrides:ge}})},[I,k,Q]),V=s.useCallback(Y=>$.has(Y),[$]),ie=b?T.map(Y=>{const H=k.get(Y);return H?_d(il(u,{...H,isExpanded:$.has(Y)})):"i"}).join(""):"",te=s.useMemo(()=>{const Y=new Map;return T.forEach((H,R)=>Y.set(H,kd(ie[R]))),Y},[T,ie]),ce=b?il(u,null):"footer",oe=x!=="server"&&!!(a&&a.length>0),de=s.useCallback(Y=>{if(!C)return null;const H=Y?.labelField,R=Y?.expandAll??!1,ae=oe&&a?a:[],ge=(G,D)=>{const U=k.get(G),q=v.get(G);if(U&&q){const me=U.groupingField??"";if(D.field===me||D.field===H){const pe=g?.byField.get(me),K=pe?.sortComparator;return{value:U.groupingValue,type:pe?.type,comparator:K,params:K?{id:G,field:me,row:q.inline,value:U.groupingValue}:void 0}}return U.aggregatedValues&&Object.prototype.hasOwnProperty.call(U.aggregatedValues,D.field)?{value:U.aggregatedValues[D.field],type:g?.byField.get(D.field)?.type}:{value:void 0}}const ee=B.get(G),Z=g?.byField.get(D.field),j=ee?Ee(ee,D.field,Z):void 0,re=Z?.sortComparator;return{value:j,type:Z?.type,comparator:re,params:re&&ee?{id:G,field:D.field,row:ee,value:j}:void 0}},J=[],O=new Set,A=G=>{const D=ae.length>0?ci(G,ae,ge):G;for(const U of D){if(O.has(U))continue;O.add(U);const q=v.get(U);if(!q){const me=B.get(U);me&&J.push(me);continue}const ee=k.get(U),Z=$.has(U),j=te.has(U)?te.get(U)??null:"inline",re=j==="inline"||j==="footer"&&!Z;J.push(re?q.inline:q.bare),(Z||R)&&ee?.children&&(A(ee.children),Z&&!R&&j==="footer"&&q.footer&&J.push(q.footer))}};return A(N),J},[C,oe,a,k,v,B,g,$,te,N]),X=s.useCallback(Y=>k.get(Y),[k]),ne=s.useMemo(()=>{const Y=new Map;return k.forEach((H,R)=>{v.has(R)||Y.set(R,{hasChildren:!1,treeDepth:H.depth,isGroupRow:!1})}),Y},[k,v]),se=s.useMemo(()=>{const Y=new Map;return v.forEach((H,R)=>{const ae=k.get(R);if(!ae)return;const ge={hasChildren:!0,treeDepth:ae.depth,groupingField:ae.groupingField,groupingValue:ae.groupingValue,groupLabel:ae.label,descendantCount:ae.descendantCount,isGroupRow:!0,isExpanded:$.has(R)};Y.set(R,ge),H.footer&&te.get(R)==="footer"&&Y.set(H.footer.id,{...ge,hasChildren:!1,treeDepth:ae.depth+1,isExpanded:void 0,isGroupFooter:!0})}),new wd(ne,Y)},[ne,k,v,$,te]);return s.useMemo(()=>({treeNodes:k,groupingRows:W,toggleExpansion:z,isGroupExpanded:V,getVisibleRows:de,getNode:X,rowMetaMap:se,aggregationPositions:te,rootAggregationPosition:ce}),[k,W,z,V,de,X,se,te,ce])}const Md=new Map;function Id(e){const{rows:t,getRowId:n,getTreeDataPath:o,isTreeDataRequested:r,isTreeData:i,columns:l,rowGroupingModel:c,isRowGrouping:a,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:p,sortModel:x,getAggregationPosition:y,columnLookup:h,filterMode:f,sortingMode:w}=e,b=md({rows:t,getRowId:n,getTreeDataPath:o,treeData:r,defaultGroupingExpansionDepth:g,filterModel:p,sortModel:x,columnLookup:h,filterMode:f,sortingMode:w}),m=Ed({rows:t,getRowId:n,columns:l,rowGroupingModel:c,aggregationModel:u,defaultGroupingExpansionDepth:g,filterModel:p,sortModel:x,getAggregationPosition:y,columnLookup:h,filterMode:f,sortingMode:w}),C=i?b:a?m:null,E=s.useMemo(()=>i?b.rowMetaMap:a?m.rowMetaMap:Md,[i,b.rowMetaMap,a,m.rowMetaMap]);return{treeDataHandlers:b,rowGroupingHandlers:m,activeHierarchyHandlers:C,rowMetaMap:E}}function Nd(e){const{spanning:t,renderContext:n,offsetTop:o,cumulativeHeights:r}=e;return s.useMemo(()=>{if(!t.hasRowSpan)return{renderContext:n,offsetTop:o};let i=Math.max(0,n.firstRowIndex);for(let l=t.getCenterRowSpanStart(i);l<i;l=t.getCenterRowSpanStart(i))i=l;return i>=n.firstRowIndex?{renderContext:n,offsetTop:o}:{renderContext:{...n,firstRowIndex:i},offsetTop:i>0?r[i-1]??0:0}},[t,n,o,r])}function Ld(e){const{spanning:t,firstColumnIndex:n,lastColumnIndex:o,virtualColumns:r,layout:i,rows:l}=e;return s.useMemo(()=>{if(!t.hasColSpan||i.unpinnedColsWithWidth.length===0)return r;let c=n,a=o,u=!0;for(;u;){u=!1;for(const{row:b,id:m}of l){const C=t.getUnpinnedColSpanRanges(m??b.id);if(C)for(let E=0;E<C.length;E+=2){const _=C[E],I=C[E+1];I<c||_>a||(_<c&&(c=_,u=!0),I>a&&(a=I,u=!0))}}}if(c===n&&a===o)return r;const{leftPinnedCols:g,unpinnedColsWithWidth:p,rightPinnedCols:x,unpinnedAccWidths:y,unpinnedTotalWidth:h}=i,f=c>0?y[c-1]:0,w=h-y[a];return[...g,...f>0?[{field:"__spacer_left__",width:f,isSpacer:!0}]:[],...p.slice(c,a+1),...w>0?[{field:"__spacer_right__",width:w,isSpacer:!0}]:[],...x]},[t,n,o,r,i,l])}function Pd(e){const{headerRowCount:t,pinnedTopCount:n,pinnedBottomCount:o,pageRowCount:r,totalCenterRowCount:i,pageOffset:l}=e;return{rowCount:t+n+i+o,topBase:t+1,centerOffset:t+l+1,bottomBase:t+n+i+1,bottomRowIndexOffset:n+r}}function sl(e){if(!e)return 0;let t=0;const n=(o,r)=>{t=Math.max(t,r);for(const i of o.children)typeof i!="string"&&n(i,r+1)};return e.forEach(o=>n(o,1)),t}function al(e){const t=new Map;if(!e)return t;const n=(o,r)=>{const i=[...r,o];for(const l of o.children)typeof l=="string"?t.has(l)||t.set(l,i):n(l,i)};return e.forEach(o=>n(o,[])),t}function Ro(e,t,n){if(!e||e.length===0)return!0;const o=al(e),r=o.get(t),i=o.get(n);return(r?.[r.length-1]??null)===(i?.[i.length-1]??null)}function Td(e,t,n){const o=[];let r=0,i=null,l=null;for(const c of e){const a=c.isSpacer?null:t.get(c.field)?.[n]??null;(i===null||l!==a||i.pinned!==c.pinned)&&(i={key:`${a?a.groupId:"filler"}-${n}-${c.field}`,isGroup:a!==null,label:a?.headerName??"",headerClassName:a?.headerClassName,width:0,flexGrow:0,fields:[],firstDataIndex:r,pinned:c.pinned},l=a,o.push(i)),i.width+=c.width,i.flexGrow+=c.flex??0,c.isSpacer||(i.fields.push(c.field),r++)}return o}function Ad(e){const{columnGroupingModel:t,headerFilterRow:n=!1,pinnedTopCount:o,pinnedBottomCount:r,pagination:i,paginationMode:l,paginationModel:c,paginationRowCount:a,paginatedUnpinnedRowCount:u,sortedUnpinnedRowCount:g}=e,{page:p,pageSize:x}=c;return s.useMemo(()=>Pd({headerRowCount:1+sl(t)+(n?1:0),pinnedTopCount:o,pinnedBottomCount:r,pageRowCount:i?u:g,totalCenterRowCount:i&&l==="server"?Math.max(a,u):g,pageOffset:i?p*x:0}),[t,n,o,r,i,u,g,l,a,p,x])}const Fd=e=>e.id;function Od(e){const{renderContext:t,pinnedTopRows:n,pinnedBottomRows:o,paginatedUnpinnedRows:r,sortedUnpinnedRows:i,pagination:l,getRowId:c=Fd}=e;return s.useMemo(()=>{const{firstRowIndex:a,lastRowIndex:u}=t,g=l?r:i,p=n.length,x=n.map((C,E)=>({row:C,id:c(C),rowIndex:E,pinned:"top"})),y=o.map((C,E)=>({row:C,id:c(C),rowIndex:p+g.length+E,pinned:"bottom"})),h=Math.max(0,a),f=Math.min(g.length,u+1),w=g.slice(h,f).map((C,E)=>({row:C,id:c(C),rowIndex:p+h+E})),b=[...x,...w,...y],m=new Set;return b.filter(C=>m.has(C.id)?!1:(m.add(C.id),!0))},[t,n,o,r,i,l,c])}function Dd(e){const{aria:t,spanning:n,virtualization:o,layout:r,pinnedTopRows:i,pinnedBottomRows:l,paginatedUnpinnedRows:c,sortedUnpinnedRows:a,pagination:u,getRowId:g}=e,p=Ad(t),x=Nd({spanning:n,renderContext:o.renderContext,offsetTop:o.offsetTop,cumulativeHeights:r.cumulativeHeights}),y=Od({renderContext:x.renderContext,pinnedTopRows:i,pinnedBottomRows:l,paginatedUnpinnedRows:c,sortedUnpinnedRows:a,pagination:u,getRowId:g}),h=Ld({spanning:n,firstColumnIndex:o.renderContext.firstColumnIndex,lastColumnIndex:o.renderContext.lastColumnIndex,virtualColumns:o.virtualColumns,layout:r,rows:y});return{ariaRows:p,spanRowWindow:x,visibleRows:y,renderColumns:h}}const $d=new Set(["__group__","__check__","__actions__"]);function kt(e){return e.filter(t=>t.exportable!==!1&&!t.isSpacer&&!Je(t.field)&&!$d.has(t.field))}function dt(e){return!!e&&e.length>0}function cl(e,t,n=o=>o.id){const o=new Set(t);return e.filter(r=>o.has(n(r)))}function an(e,t,n){return dt(t)?cl(e,t,n):e}function cn(e,t){return!!e&&e.length>0&&!dt(t)}function Bt(e,t,n,o,r){if(!o)return null;if(!t||!r||Object.keys(r).length===0)return o;const i=new Map(n.map(l=>[l.field,l]));return Ln(e,r,i,"export")}function dn(e,t){return Ee(e,t.field,t)}function un(e,t,n){if(!t.valueFormatter)return En(n,t);if(n==null)try{return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}catch{return""}return String(t.valueFormatter({value:n,row:e,field:t.field})??"")}function Uo(e,t,n,o){return n==null?"":Pn(n,t??"",e,o)}function Wt(e,t){return t?`${e}: ${t}`:e}function dl(e,t){const n={};return t.forEach(o=>{Object.prototype.hasOwnProperty.call(e,o.field)&&(n[o.field]=e[o.field])}),n}const Gd=/^[=+\-@\t\r]/,Hd=/^[-+]?(?=[\d.,\s]*\d)[\d.,\s]*%?$/;function Kn(e,t=!1){return t||!Gd.test(e)||Hd.test(e)?e:`'${e}`}const Bd=/^[\d\s.,'%+\-()\p{Sc}]*$/u;function Wd(e,t,n){return Vt(e)?!n||Bd.test(t):!1}function Vt(e){return typeof e=="number"||typeof e=="bigint"||typeof e=="boolean"||e instanceof Date}function Fe(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Vd(e){let t=0,n=e.length;for(;t<n&&e[t]==="'";)t++;for(;n>t&&e[n-1]==="'";)n--;return e.slice(t,n)}const zd=/[\\/?*:[\]]/g,ul=31;function jo(e,t=new Set){let n=Vd(String(e??"").replace(zd,"-").trim()).trim();n||(n="Sheet"),n=n.slice(0,ul).trim();const o=i=>t.has(i.toLowerCase())||i.toLowerCase()==="history";let r=n;for(let i=2;o(r);i++){const l=` (${i})`;r=`${n.slice(0,ul-l.length).trim()}${l}`}return t.add(r.toLowerCase()),r}const Kd=new Set([Ye,vt,Ct]),Rd=/[\t\n\r"]/;function qo(e){return Rd.test(e)?`"${e.replace(/"/g,'""')}"`:e}function Ud(e){return kt(e).filter(t=>!Kd.has(t.field))}function jd(e,t){const n=t.map(r=>qo(r.headerName||r.field)).join(" "),o=e.map(r=>t.map(i=>qo(un(r,i,Ee(r,i.field,i)))).join(" "));return[n,...o].join(`
|
|
4
|
+
`)}function qd(e,t){const n=Ee(e,t.field,t);try{return un(e,t,n)}catch{return n==null?"":String(n)}}function Xd(e,t,n){const o=new Array(e.length);for(let r=0;r<e.length;r++){const i=e[r],l=new Array(t.length);for(let c=0;c<t.length;c++){const a=t[c];l[c]=n?.(i,a)?"":qo(qd(i,a))}o[r]=l.join(" ")}return o.join(`
|
|
5
|
+
`)}function fl(e){if(typeof document.execCommand!="function")return!1;const t=document.activeElement instanceof HTMLElement?document.activeElement:null,n=document.getSelection(),o=[];if(n)for(let l=0;l<n.rangeCount;l++)o.push(n.getRangeAt(l));const r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.setAttribute("aria-hidden","true"),r.style.cssText="position:fixed;top:-9999px;left:-9999px;opacity:0;",document.body.appendChild(r);let i=!1;try{r.focus({preventScroll:!0}),r.select(),i=document.execCommand("copy")}finally{document.body.removeChild(r),t&&t.isConnected&&t.focus({preventScroll:!0}),n&&(n.removeAllRanges(),o.forEach(l=>n.addRange(l)))}return i}async function Xo(e){const t=typeof navigator<"u"?navigator.clipboard:void 0;if(t&&typeof t.writeText=="function")try{await t.writeText(e);return}catch(n){if(fl(e))return;throw n}if(!fl(e))throw new Error("Clipboard API not available and fallback failed.")}function Yd(e){if(!(e.ctrlKey||e.metaKey)||e.altKey||e.shiftKey)return!1;const t=e.key??"";return t.toLowerCase()==="c"?!0:e.code==="KeyC"&&!/^[a-z]$/i.test(t)}function Jd(e){const t=s.useRef(e);s.useLayoutEffect(()=>{t.current=e});const n=s.useCallback(async()=>{const{getSelectedRowIds:r,getColumns:i,getRows:l,getRowId:c}=t.current,a=new Set(r());if(a.size===0)return;const u=l().filter(p=>a.has(c(p)));if(u.length===0)return;const g=jd(u,Ud(i()));await Xo(g)},[]),o=!!e.disableKeyboardShortcut;return s.useEffect(()=>{if(o)return;const r=i=>{if(i.defaultPrevented||!Yd(i))return;const l=document.activeElement,c=l?.tagName.toLowerCase(),a=l?.type;if(c==="input"&&a!=="checkbox"&&a!=="radio"||c==="textarea"||c==="select"||l?.isContentEditable)return;const{getRootElement:u}=t.current;if(u){const y=u();if(!y||!l||!y.contains(l))return}const g=window.getSelection();if(g&&!g.isCollapsed&&g.toString()!=="")return;const{getShortcutText:p}=t.current;(p?()=>{const y=p();return y===null?Promise.resolve():Xo(y)}:n)().catch(y=>{console.error("[OpenGridX] Failed to copy to clipboard:",y)})};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[n,o]),{copySelectedRows:n}}function Zd(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useRef(null),r=s.useRef(null),i=s.useRef(null),{selection:l,model:c,focusedCell:a,setFocusedCell:u,containerRef:g}=e,p=l.range?.anchor??null,x=l.resolved?.anchorRow;s.useLayoutEffect(()=>{l.reportFocus(a);const y=!ct(o.current,p),h=!Ao(r.current,a);if(o.current=p,r.current=a,!!l.enabled){if(l.range&&!l.resolved){i.current!==c&&(i.current=c,l.setModel([],"dataChange"));return}if(y&&p){(!a||a.id!==p.id||a.field!==p.field)&&u({id:p.id,field:p.field,rowIndex:x});return}if(h&&a&&a.id!==null&&Ue(a.field)&&!ct(p,{id:a.id,field:a.field})){const f={id:a.id,field:a.field},w=g.current?.classList.contains("ogx--kb")??!1;l.setModel([{anchor:f,head:f}],w?"keyboard":"pointer")}}},[l,c,p,x,a,u,g]),s.useLayoutEffect(()=>{const y=t.current,h=()=>n.current;y.getCellSelectionModel=()=>{const{selection:f,getPendingModel:w,model:b}=h();return f.enabled?w()??b:[]},y.setCellSelectionModel=f=>{h().selection.setModel(f,"api")},y.selectCellRange=(f,w)=>{h().selection.setModel([{anchor:f,head:w}],"api")},y.clearCellSelection=()=>{h().selection.setModel([],"clear")},y.getSelectedCells=()=>h().selection.getSelectedCells(),y.copySelectedCells=async()=>{const{selection:f}=h();if(!f.enabled)return;const w=f.getCopyText();w!==null&&await Xo(w)}},[t])}function We(e){try{return{ok:!0,value:e()}}catch(t){return{ok:!1,error:t}}}const ot={ok:!1},Oe=e=>({ok:!0,value:e});function Qd(e){const t=[];if(e==="")return t;let n=[],o="",r=0;const i=e.length;let l=!0;for(;r<i;){const c=e[r];if(l&&c==='"'){let a=r+1,u="",g=!1;for(;a<i;){const p=e[a];if(p==='"'){if(e[a+1]==='"'){u+='"',a+=2;continue}g=!0,a+=1;break}u+=p,a+=1}if(!g){o+=c,r+=1,l=!1;continue}o+=u,r=a,l=!1;continue}l=!1,c===" "?(n.push(o),o="",l=!0,r+=1):c===`
|
|
6
|
+
`||c==="\r"?(n.push(o),t.push(n),n=[],o="",l=!0,r+=c==="\r"&&e[r+1]===`
|
|
7
|
+
`?2:1):(o+=c,r+=1)}return(!l||n.length>0||o!=="")&&(n.push(o),t.push(n)),t}const eu=/^\d+(?:\.\d*)?(?:e[+-]?\d+)?$/i,tu=/^\.\d+(?:e[+-]?\d+)?$/i,nu=/^\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,ou=/[\p{Sc}\s]/gu;function ru(e){let t=e.replace(ou,"");if(t==="")return e.trim()===""?Oe(null):ot;let n=!1;t.startsWith("(")&&t.endsWith(")")&&(n=!0,t=t.slice(1,-1)),(t.startsWith("-")||t.startsWith("+")||t.startsWith("−"))&&(t[0]!=="+"&&(n=!n),t=t.slice(1));let o=!1;if(t.endsWith("%")&&(o=!0,t=t.slice(0,-1)),nu.test(t))t=t.split(",").join("");else if(!eu.test(t)&&!tu.test(t))return ot;let r=Number(t);return Number.isFinite(r)?(o&&(r/=100),n&&(r=-r),Oe(r)):ot}const iu=/^(\d{4}-\d{2}-\d{2})/,gl=e=>String(e).padStart(2,"0");function lu(e){const t=e.trimEnd();if(t.endsWith("Z")||t.endsWith("z"))return!0;const n=t.indexOf("T");if(n<0)return!1;for(let o=t.length-1;o>n;o--){const r=t[o];if(r==="+"||r==="-")return!0;if(!(r>="0"&&r<="9")&&r!==":")return!1}return!1}const su=e=>`${e.getFullYear()}-${gl(e.getMonth()+1)}-${gl(e.getDate())}`;function au(e,t){const n=e.trim();if(n==="")return Oe(null);const o=Qt(n);if(!o)return ot;if(typeof t=="number")return Oe(o.getTime());if(typeof t=="string"){const r=su(o);if(!iu.test(t)||t.length<=10)return Oe(r);const i=lu(t)?new Date(t):null;return i&&!Number.isNaN(i.getTime())?Oe(new Date(o.getFullYear(),o.getMonth(),o.getDate(),i.getHours(),i.getMinutes(),i.getSeconds(),i.getMilliseconds()).toISOString()):Oe(r+t.slice(10))}return Oe(o)}const cu=new Set(["true","yes","1"]),du=new Set(["false","no","0"]);function uu(e,t){const n=e.trim().toLowerCase();return n===""?Oe(null):t?.trueLabel!==void 0&&n===t.trueLabel.trim().toLowerCase()?Oe(!0):t?.falseLabel!==void 0&&n===t.falseLabel.trim().toLowerCase()?Oe(!1):cu.has(n)?Oe(!0):du.has(n)?Oe(!1):ot}function fu(e,t){const n=e.trim();if(n==="")return Oe(null);if(!t||t.length===0)return ot;const o=n.toLowerCase();for(const r of t){const i=typeof r=="object"?r.value:r;if(String(i).toLowerCase()===o)return Oe(i)}for(const r of t)if(typeof r=="object"&&r.label.toLowerCase()===o)return Oe(r.value);return ot}function gu(e,t,n){switch(t?.type){case"number":return ru(e);case"date":return au(e,n?.current);case"boolean":return uu(e,n?.booleanLabels);case"singleSelect":return fu(e,t.valueOptions);default:return Oe(e)}}function pu(e,t,n,o){const{valueParser:r}=t;if(!r)return gu(e,t,o);let i;try{i=r(e,{row:n,field:t.field,colDef:t})}catch{return ot}return i===void 0?ot:Oe(i)}function Yo(e,t,n){const{rowIds:o,rowIndexById:r}=Vo(e,t,"renderable"),i=n.filter(a=>Ue(a.field)),l=new Map;i.forEach((a,u)=>{l.set(a.field,u)});const c=n.filter(a=>Je(a.field)).length;return{rows:e,rowIds:o,rowIndexById:r,columns:i,colIndexByField:l,dataColumnOffset:c}}function Jo(e,t,n,o,r){const i=e.rowIds[o],l=e.columns[r];if(!l||Re(i,t.rowMetaMap))return!1;const c=t.getSpanOrigin?.(i,l.field);return c&&(c.rowId!==i||c.field!==l.field)?!1:xo({row:n,field:l.field,value:Ee(n,l.field,l),colDef:l,rowIndex:o,colIndex:e.dataColumnOffset+r,rowMeta:t.rowMetaMap?.get(i)},t.isCellEditable)}function hu(e,t){let n=1/0,o=-1/0,r=1/0,i=-1/0;for(const l of t){const c=e.rowIndexById.get(l.id),a=e.colIndexByField.get(l.field);c===void 0||a===void 0||(c<n&&(n=c),c>o&&(o=c),a<r&&(r=a),a>i&&(i=a))}return n===1/0?null:{top:n,bottom:o,left:r,right:i}}function pl(e,t){return{anchor:{id:e.rowIds[t.top],field:e.columns[t.left].field},head:{id:e.rowIds[t.bottom],field:e.columns[t.right].field}}}function mu(e){const t=e?.type;return t===void 0||t==="string"||t==="image"}const hl=1e4,Rn=()=>({updated:[],failed:[],skipped:[]});function wu(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Pasting ${e} cells. Pastes above ${hl} cells can be slow; consider importing the data instead.`)}function bu(e){const{apiRef:t,containerRef:n,selection:o,disableClipboardPaste:r,disableRangeClear:i}=e,l=s.useRef(e);s.useLayoutEffect(()=>{l.current=e});const c=s.useCallback(()=>{const{allRenderableRows:h,getRowId:f,navigationColumns:w}=l.current;return Yo(h,f,w)},[]),a=s.useCallback(()=>{const{selection:h}=l.current;return h.enabled?h.getCurrentRange().resolved:null},[]),u=s.useCallback(h=>{const f=a();if(f&&h.rowIds[f.top]!==void 0&&h.columns[f.left])return{id:h.rowIds[f.top],field:h.columns[f.left].field};const w=l.current.focusedCell;return w&&w.id!==null&&Ue(w.field)?{id:w.id,field:w.field}:null},[a]),g=s.useCallback(async(h,f,w)=>{const b=c(),m=f??u(b);let C=h;const{onBeforeClipboardPaste:E}=l.current;if(E){const oe=We(()=>E({text:C,anchor:m}));if(!oe.ok)return yt("onBeforeClipboardPaste","onBeforeClipboardPaste threw; the paste was cancelled",oe.error),Rn();if(oe.value===!1)return Rn();typeof oe.value=="string"&&(C=oe.value)}if(!m)return Rn();const _=Qd(C),I=b.rowIndexById.get(m.id),M=b.colIndexByField.get(m.field);if(_.length===0||I===void 0||M===void 0)return Rn();const S=b.rowIds.length-1,F=b.columns.length-1,P=f?null:a(),L=P&&St(P)>1?P:null,k=_.length===1&&_[0].length===1,N=_.reduce((oe,de)=>Math.max(oe,de.length),0);let T;k&&L?T=L:T={top:I,left:M,bottom:Math.min(I+_.length-1,S,L?L.bottom:S),right:Math.min(M+N-1,F,L?L.right:F)};const v=St(T);v>hl&&wu(v);const{batchEdit:W,isCellEditable:B,rowMetaMap:Q,getSpanOrigin:$}=l.current,z={isCellEditable:B,rowMetaMap:Q,getSpanOrigin:$},V=[],ie=[];for(let oe=T.top;oe<=T.bottom;oe++){const de=b.rowIds[oe],X=W.getRow(de)??b.rows[oe],ne=k?_[0]:_[oe-T.top];for(let se=T.left;se<=T.right;se++){const Y=k?_[0][0]:ne?.[se-T.left];if(Y===void 0)continue;const H=b.columns[se];if(!Jo(b,z,X,oe,se)){ie.push({id:de,field:H.field,reason:"notEditable"});continue}const R=pu(Y,H,X,{current:Ee(X,H.field,H)});if(!R.ok){ie.push({id:de,field:H.field,reason:"invalidValue"});continue}V.push({id:de,field:H.field,value:R.value})}}if(l.current.selection.enabled){const{anchor:oe,head:de}=pl(b,T);l.current.selection.setModel([{anchor:oe,head:de}],w?"keyboard":"api")}const te=await W.applyEdits(V,"paste"),ce={updated:te.result.updated,failed:te.result.failed,skipped:[...ie,...te.result.skipped]};return l.current.onClipboardPaste?.({...ce,text:C}),ce},[c,u,a]),p=s.useCallback(()=>{const h=a();if(!h||St(h)<=1)return!1;const f=c(),{batchEdit:w,isCellEditable:b,rowMetaMap:m,getSpanOrigin:C}=l.current,E={isCellEditable:b,rowMetaMap:m,getSpanOrigin:C},_=[];for(let I=h.top;I<=h.bottom;I++){const M=f.rowIds[I];if(M===void 0)continue;const S=w.getRow(M)??f.rows[I];for(let F=h.left;F<=h.right;F++){const P=f.columns[F];!P||!Jo(f,E,S,I,F)||_.push({id:M,field:P.field,value:mu(P)?"":null})}}return w.applyEdits(_,"clear"),!0},[a,c]),x=o.enabled&&!r,y=o.enabled&&!i;s.useEffect(()=>{const h=n.current;if(!h||!x&&!y)return;const f=I=>{const M=l.current.viewportRef.current;if(!M||I.defaultPrevented||l.current.isEditing)return!1;const S=Dn(I.target,M);return S==="grid"||S==="control"};let w=null;const b=()=>{if(!w)return;const{textarea:I,restore:M,timer:S}=w;w=null,window.clearTimeout(S);const F=document.activeElement===I;I.remove(),F&&M&&M.isConnected&&M.focus({preventScroll:!0})},m=()=>{b();const I=document.createElement("textarea");I.setAttribute("aria-hidden","true"),I.tabIndex=-1,I.className="ogx__paste-capture",I.style.cssText="position:fixed;top:0;left:-10000px;width:1px;height:1px;opacity:0;",h.appendChild(I);const M=document.activeElement instanceof HTMLElement?document.activeElement:null;w={textarea:I,restore:M,timer:window.setTimeout(b,250)},I.focus({preventScroll:!0})},C=I=>w!==null&&I.target===w.textarea,E=I=>{if(C(I)){const S=I.clipboardData?I.clipboardData.getData("text/plain"):"";I.preventDefault(),b(),S!==""&&g(S,void 0,!0);return}if(!x||!f(I)||!l.current.navigationColumns.some(S=>S.editable))return;const M=I.clipboardData?I.clipboardData.getData("text/plain"):"";M!==""&&(I.preventDefault(),g(M,void 0,!0))},_=I=>{if((I.ctrlKey||I.metaKey)&&!I.altKey&&!I.shiftKey&&(I.key==="v"||I.key==="V"||I.code==="KeyV")){x&&f(I)&&l.current.navigationColumns.some(M=>M.editable)&&m();return}!y||I.key!=="Delete"&&I.key!=="Backspace"||I.ctrlKey||I.metaKey||I.altKey||I.shiftKey||f(I)&&p()&&I.preventDefault()};return h.addEventListener("paste",E),h.addEventListener("keydown",_),()=>{b(),h.removeEventListener("paste",E),h.removeEventListener("keydown",_)}},[n,x,y,g,p]),s.useLayoutEffect(()=>{t.current.pasteText=(h,f)=>g(h,f,!1)},[t,g])}const xu=100;function yu(){const e=s.useRef(null),t=s.useCallback((o,r)=>{const i=e.current;i&&i(o,r)},[]),n=s.useCallback(o=>{e.current=o},[]);return s.useMemo(()=>({emit:t,setListener:n}),[t,n])}const ml=()=>({updated:[],failed:[],skipped:[]});function Cu(e){if(e.altKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t),o=t==="z"||!n&&e.code==="KeyZ",r=t==="y"||!n&&e.code==="KeyY";return o?e.shiftKey?"redo":"undo":r&&e.ctrlKey&&!e.shiftKey?"redo":null}function vu(e){const{apiRef:t,enabled:n,channel:o,containerRef:r}=e,i=s.useRef(e);s.useLayoutEffect(()=>{i.current=e});const l=s.useRef([]),c=s.useRef([]),a=s.useRef({canUndo:!1,canRedo:!1,size:0}),u=s.useRef(Promise.resolve()),g=s.useCallback(()=>{const b={canUndo:l.current.length>0,canRedo:c.current.length>0,size:l.current.length},m=a.current;m.canUndo===b.canUndo&&m.canRedo===b.canRedo&&m.size===b.size||(a.current=b,i.current.onHistoryChange?.(b))},[]),p=s.useCallback(b=>{if(!i.current.enabled||b.length===0)return;const m=l.current;m.push(b);const C=Math.max(1,i.current.limit);m.length>C&&m.splice(0,m.length-C),c.current=[],g()},[g]);s.useLayoutEffect(()=>(o.setListener(n?p:null),()=>o.setListener(null)),[o,n,p]);const x=s.useCallback(()=>{l.current=[],c.current=[],g()},[g]);s.useEffect(()=>{n||x()},[n,x]);const y=s.useCallback(b=>{const m=i.current,C=Yo(m.allRenderableRows,m.getRowId,m.navigationColumns),E=hu(C,b);if(!E)return;const{anchor:_,head:I}=pl(C,E);m.selection.enabled?m.selection.setModel([{anchor:_,head:I}],"keyboard"):m.setFocusedCell({id:_.id,field:_.field,rowIndex:E.top});const M=m.viewportRef.current;M&&(Nn(M,E.top-m.pinnedTopRowCount,m.layout.cumulativeHeights,m.layout.pinnedBottomHeight,m.rowHeight),bo(M,m.layout.unpinnedColsWithWidth.findIndex(S=>S.field===_.field),m.layout))},[]),h=s.useCallback(b=>{const m=async()=>{if(!i.current.enabled)return ml();const E=b==="undo"?l:c,_=b==="undo"?c:l,I=E.current.pop();if(!I)return ml();g();const M=I.map(P=>b==="undo"?{id:P.id,field:P.field,value:P.before,expect:{value:P.after}}:{id:P.id,field:P.field,value:P.after,expect:{value:P.before}}),S=await i.current.batchEdit.applyEdits(M,b);S.committed.length>0&&_.current.push(b==="undo"?S.committed.map(P=>({id:P.id,field:P.field,before:P.after,after:P.before})):S.committed);const F=new Set(S.result.failed.map(P=>P.id));if(F.size>0){const P=I.filter(L=>F.has(L.id));P.length>0&&E.current.push(P)}return g(),S.committed.length>0&&y(S.committed),S.result},C=u.current.then(m,m);return u.current=C,C},[g,y]),f=s.useCallback(()=>h("undo"),[h]),w=s.useCallback(()=>h("redo"),[h]);s.useEffect(()=>{const b=r.current;if(!b||!n)return;const m=C=>{if(C.defaultPrevented)return;const E=Cu(C);if(!E)return;const _=i.current.viewportRef.current;if(!_||i.current.isEditing)return;const I=Dn(C.target,_);I!=="grid"&&I!=="control"||(C.preventDefault(),E==="undo"?f():w())};return b.addEventListener("keydown",m),()=>b.removeEventListener("keydown",m)},[r,n,f,w]),s.useLayoutEffect(()=>{const b=t.current;b.undo=f,b.redo=w,b.canUndo=()=>i.current.enabled&&l.current.length>0,b.canRedo=()=>i.current.enabled&&c.current.length>0,b.clearHistory=x},[t,f,w,x])}function Su(e){const t=String(e);if(t.includes("e")||t.includes("E"))return null;const n=t.indexOf(".");return n===-1?0:t.length-n-1}function Zo(e,t){return t===null?e:Number(e.toFixed(Math.min(t,20)))}function _u(e,t){let n=0;for(const l of e){const c=Su(l);n=c===null||n===null?null:Math.max(n,c)}const o=Zo(e[1]-e[0],n);for(let l=2;l<e.length;l++)if(Zo(e[l]-e[l-1],n)!==o)return null;const r=e[e.length-1],i=[];for(let l=1;l<=t;l++)i.push(Zo(r+o*l,n));return i}const ku=864e5,wl=e=>((e.getHours()*60+e.getMinutes())*60+e.getSeconds())*1e3+e.getMilliseconds(),Eu=e=>Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/ku),Mu=e=>e.getFullYear()*12+e.getMonth(),Iu=(e,t)=>new Date(e,t+1,0).getDate();function Qo(e){const t=e[1]-e[0];for(let n=2;n<e.length;n++)if(e[n]-e[n-1]!==t)return null;return t}function Nu(e,t){const n=e[e.length-1],o=e.every(l=>wl(l)===wl(n));if(o&&e.every(l=>l.getDate()===n.getDate())){const l=Qo(e.map(Mu));if(l!==null&&l!==0){const c=[];for(let a=1;a<=t;a++){const u=n.getMonth()+l*a,g=n.getFullYear()+Math.floor(u/12),p=(u%12+12)%12,x=new Date(n.getTime());x.setFullYear(g,p,Math.min(n.getDate(),Iu(g,p))),c.push(x)}return c}}if(o){const l=Qo(e.map(Eu));if(l===null)return null;const c=[];for(let a=1;a<=t;a++){const u=new Date(n.getTime());u.setDate(n.getDate()+l*a),c.push(u)}return c}const r=Qo(e.map(l=>l.getTime()));if(r===null)return null;const i=[];for(let l=1;l<=t;l++)i.push(new Date(n.getTime()+r*l));return i}const Lu=e=>typeof e=="number"&&Number.isFinite(e),Pu=e=>e instanceof Date&&!Number.isNaN(e.getTime());function Tu(e,t){return e.length<2?null:e.every(Lu)?_u(e,t):e.every(Pu)?Nu(e,t):null}const Au=e=>e instanceof Date?new Date(e.getTime()):e;function Fu(e,t,n){if(e.length===0||t<=0)return[];const o=n?Tu(e,t):null;if(o)return o;const r=[];for(let i=0;i<t;i++)r.push(Au(e[i%e.length]));return r}function Ou(e,t,n,o){const r=t.row>e.bottom||t.row<e.top,i=t.col>e.right||t.col<e.left;return!r&&!i?null:r&&(!i||Math.abs(o)>=Math.abs(n))?t.row>e.bottom?{rect:{...e,bottom:t.row},direction:"down"}:{rect:{...e,top:t.row},direction:"up"}:t.col>e.right?{rect:{...e,right:t.col},direction:"right"}:{rect:{...e,left:t.col},direction:"left"}}function Du(e,t,n){const o=(a,u)=>{const g=[];if(a<=u)for(let p=a;p<=u;p++)g.push(p);else for(let p=a;p>=u;p--)g.push(p);return g},i=n==="down"||n==="up"?o(e.left,e.right):o(e.top,e.bottom);let l,c;switch(n){case"down":l=o(e.top,e.bottom),c=t.bottom>e.bottom?o(e.bottom+1,t.bottom):[];break;case"up":l=o(e.bottom,e.top),c=t.top<e.top?o(e.top-1,t.top):[];break;case"right":l=o(e.left,e.right),c=t.right>e.right?o(e.right+1,t.right):[];break;default:l=o(e.right,e.left),c=t.left<e.left?o(e.left-1,t.left):[]}return i.map(a=>({line:a,source:l,targets:c}))}function $u(e,t,n){const o=n.row===e.top||n.row===e.bottom,r=n.col===e.left||n.col===e.right;let i=n.row,l=n.col;return(!o||!r)&&(t==="down"||t==="up"?(i=t==="down"?e.top:e.bottom,l=n.col===e.right?e.right:e.left):(l=t==="right"?e.left:e.right,i=n.row===e.bottom?e.bottom:e.top)),{anchor:{row:i,col:l},head:{row:i===e.top?e.bottom:e.top,col:l===e.left?e.right:e.left}}}function Gu(e,t,n,o){const r=t(e.bottom),i=n[e.right];if(r===void 0||i===void 0)return null;const l=o?.(r,i);if(!l||l.rowId===r&&l.field===i)return{row:e.bottom,field:i};for(let c=e.bottom;c>=Math.max(0,e.bottom-Hu);c--)if(t(c)===l.rowId)return{row:c,field:l.field};return null}const Hu=1e3,Bu="ogx__cell-fill-handle";function Wu(e){if(e.altKey||e.shiftKey||!(e.ctrlKey||e.metaKey))return null;const t=(e.key??"").toLowerCase(),n=/^[a-z]$/.test(t);return t==="d"||!n&&e.code==="KeyD"?"down":t==="r"||!n&&e.code==="KeyR"?"right":null}function Vu(e){const{containerRef:t,viewportRef:n,selection:o,disableFillHandle:r,isEditing:i,allRenderableRows:l,getRowId:c,navigationColumns:a,columnIndexMap:u,getSpanOrigin:g}=e,p=s.useRef(e);s.useLayoutEffect(()=>{p.current=e});const x=o.enabled&&!r,y=s.useMemo(()=>a.some(S=>S.editable),[a]),h=o.resolved,f=s.useMemo(()=>{if(!x||!y||!h)return null;const S=a.filter(k=>Ue(k.field)).map(k=>k.field),P=Gu(h,k=>{const N=l[k];return N===void 0?void 0:c(N)},S,g);if(!P)return null;const L=u.get(P.field);return L===void 0?null:{row:P.row,col:L}},[x,y,h,l,c,a,u,g]),w=s.useRef(!0);s.useEffect(()=>(w.current=!0,()=>{w.current=!1}),[]);const b=s.useCallback(()=>{const S=p.current;return Yo(S.allRenderableRows,S.getRowId,S.navigationColumns)},[]),m=s.useCallback((S,F,P,L,k)=>{const N=$u(F,P,L),T=v=>({id:S.rowIds[v.row],field:S.columns[v.col].field});p.current.selection.setModel([{anchor:T(N.anchor),head:T(N.head)}],k)},[]),C=s.useCallback(async(S,F,P,L,k,N,T)=>{const{batchEdit:v,isCellEditable:W,rowMetaMap:B,getSpanOrigin:Q}=p.current,$={isCellEditable:W,rowMetaMap:B,getSpanOrigin:Q},z=L==="down"||L==="up",V=de=>{const X=S.rowIds[de];return X===void 0?void 0:v.getRow(X)??S.rows[de]},ie=[],te=[];for(const de of Du(F,P,L)){if(de.targets.length===0)continue;const X=Y=>z?{r:Y,c:de.line}:{r:de.line,c:Y},ne=[];for(const Y of de.source){const{r:H,c:R}=X(Y),ae=V(H),ge=S.columns[R];!ae||!ge||Re(S.rowIds[H],B)||ne.push(Ee(ae,ge.field,ge))}if(ne.length===0)continue;const se=Fu(ne,de.targets.length,!k);de.targets.forEach((Y,H)=>{const{r:R,c:ae}=X(Y),ge=V(R),J=S.columns[ae],O=S.rowIds[R];if(!ge||!J||O===void 0)return;if(!Jo(S,$,ge,R,ae)){te.push({id:O,field:J.field,reason:"notEditable"});return}let A=se[H];const G=J.fillValue;if(G){const D=We(()=>G.call(J,{row:ge,id:O,field:J.field,colDef:J,direction:L,sourceValues:ne.slice(),index:H,value:A,copy:k}));if(!D.ok){yt(`fillValue:${J.field}`,`fillValue of column "${J.field}" threw; the cell was skipped`,D.error),te.push({id:O,field:J.field,reason:"invalidValue"});return}A=D.value}ie.push({id:O,field:J.field,value:A})})}m(S,P,L,N,T);const ce=await v.applyEdits(ie,"fill"),oe={updated:ce.result.updated,failed:ce.result.failed,skipped:[...te,...ce.result.skipped],direction:L};return p.current.onFill?.(oe),oe},[m]),E=s.useRef(null),_=s.useCallback((S,F,P)=>{const L=E.current,k=p.current.viewportRef.current;if(!L||!k)return;const N=L.ctx,T=N.rowIndexById.get(S.id),v=N.colIndexByField.get(S.field);if(T===void 0||v===void 0)return;const W=F-L.x+k.scrollLeft-L.scrollLeft,B=P-L.y+k.scrollTop-L.scrollTop,Q=Ou(L.source,{row:T,col:v},W,B);L.target=Q,Q?m(N,Q.rect,Q.direction,L.anchor,"pointer"):p.current.selection.setModel(L.sourceModel,"pointer")},[m]),I=s.useCallback(({cancelled:S,altKey:F})=>{const P=E.current;if(E.current=null,!P||!w.current)return;const L=P.ctx;if(S||!P.target){p.current.selection.setModel(P.sourceModel,"pointer");return}C(L,P.source,P.target.rect,P.target.direction,F,P.anchor,"pointer")},[C]),M=x&&y;return s.useEffect(()=>{const S=n.current;if(!S||!M)return;const F=P=>{if(P.button!==0||!(P.target instanceof Element))return;const L=P.target.closest(`.${Bu}`);if(!L||L.closest(".ogx__viewport")!==S||p.current.isEditing)return;const{selection:k}=p.current,{range:N,resolved:T}=k.getCurrentRange();if(!N||!T)return;const v=b(),W=v.rowIds[T.bottom],B=v.columns[T.right];if(W===void 0||!B)return;P.preventDefault();const Q=S.ownerDocument;S.contains(Q.activeElement)||S.focus({preventScroll:!0}),We(()=>S.setPointerCapture(P.pointerId)),E.current={source:{top:T.top,bottom:T.bottom,left:T.left,right:T.right},sourceModel:[N],anchor:{row:T.anchorRow,col:T.anchorCol},ctx:v,x:P.clientX,y:P.clientY,scrollLeft:S.scrollLeft,scrollTop:S.scrollTop,target:null},k.startTrackedDrag({start:{id:W,field:B.field},x:P.clientX,y:P.clientY,pointerId:P.pointerId,onTrack:_,onEnd:I})};return S.addEventListener("pointerdown",F),()=>S.removeEventListener("pointerdown",F)},[n,M,b,_,I]),s.useEffect(()=>{const S=t.current;if(!S||!x)return;const F=P=>{if(P.defaultPrevented)return;const L=Wu(P);if(!L)return;const k=p.current.viewportRef.current;if(!k||p.current.isEditing)return;const N=Dn(P.target,k);if(N!=="grid"&&N!=="control")return;const{range:T,resolved:v}=p.current.selection.getCurrentRange();if(!T||!v)return;P.preventDefault();const W={top:v.top,bottom:v.bottom,left:v.left,right:v.right},B=L==="down"?{...W,bottom:W.top}:{...W,right:W.left};(L==="down"?W.bottom===W.top:W.right===W.left)||C(b(),B,W,L,!0,{row:v.anchorRow,col:v.anchorCol},"keyboard")};return S.addEventListener("keydown",F),()=>S.removeEventListener("keydown",F)},[t,x,C,b]),{handle:i?null:f}}function zu(e){const{props:t,apiRef:n,containerRef:o,viewportRef:r,selection:i,model:l,getPendingModel:c,focusedCell:a,setFocusedCell:u,allRenderableRows:g,getRowId:p,navigationColumns:x,columnIndexMap:y,isCellEditable:h,rowMetaMap:f,getSpanOrigin:w,isEditing:b,batchEdit:m,channel:C,layout:E,rowHeight:_,pinnedTopRowCount:I}=e,{disableClipboardPaste:M=!1,disableRangeClear:S=!1,onClipboardPaste:F,onBeforeClipboardPaste:P,undoRedo:L=!1,disableFillHandle:k=!1,onFill:N,onHistoryChange:T}=t;return Zd({apiRef:n,selection:i,model:l,getPendingModel:c,focusedCell:a,setFocusedCell:u,containerRef:o}),bu({apiRef:n,containerRef:o,viewportRef:r,selection:i,disableClipboardPaste:M,disableRangeClear:S,focusedCell:a,allRenderableRows:g,getRowId:p,navigationColumns:x,isCellEditable:h,rowMetaMap:f,getSpanOrigin:w,isEditing:b,batchEdit:m,onClipboardPaste:F,onBeforeClipboardPaste:P}),vu({apiRef:n,enabled:!!L,limit:typeof L=="object"&&L.limit||xu,onHistoryChange:T,channel:C,batchEdit:m,isEditing:b,containerRef:o,viewportRef:r,selection:i,setFocusedCell:u,allRenderableRows:g,getRowId:p,navigationColumns:x,layout:E,rowHeight:_,pinnedTopRowCount:I}),Vu({containerRef:o,viewportRef:r,selection:i,disableFillHandle:k,isEditing:b,allRenderableRows:g,getRowId:p,navigationColumns:x,columnIndexMap:y,isCellEditable:h,rowMetaMap:f,getSpanOrigin:w,batchEdit:m,onFill:N})}const Ku=100;function bl(e){const{scrollTop:t,scrollHeight:n,clientHeight:o}=e;return n-t-o>=Ku?null:{visibleTop:t,visibleBottom:t+o,viewportHeight:o}}function Ru(e){return e<.5?3:e<3?5:e<15?12:e<40?20:30}function Uu(e){const{onRowsScrollEnd:t,overscanRowCount:n=3,rowCount:o=0,autoHeight:r=!1}=e,i=s.useRef({scrollTop:0,scrollLeft:0,velocity:0}),l=s.useRef({scrollTop:0,scrollLeft:0,time:0}),c=s.useRef(null),a=s.useRef(null),u=s.useRef(null),g=s.useRef(!0),p=s.useRef(t),[x,y]=s.useState({scrollTop:0,scrollLeft:0,velocityOverscan:0});s.useEffect(()=>{p.current=t},[t]),s.useEffect(()=>()=>{c.current!==null&&cancelAnimationFrame(c.current),a.current!==null&&clearTimeout(a.current)},[]);const h=s.useCallback(b=>{const m=bl(b);if(!m){g.current=!0;return}if(!g.current)return;const C=p.current;C&&(g.current=!1,C(m))},[]),f=s.useCallback(b=>{const m=b.currentTarget,C=performance.now(),E=Ot(m),_=Math.abs(m.scrollTop-l.current.scrollTop)+Math.abs(E-l.current.scrollLeft),I=C-l.current.time,M=I>0?_/I:0,S=m.scrollTop!==l.current.scrollTop;l.current={scrollTop:m.scrollTop,scrollLeft:E,time:C},i.current={scrollTop:m.scrollTop,scrollLeft:E,velocity:M},c.current!==null&&cancelAnimationFrame(c.current),c.current=requestAnimationFrame(()=>{c.current=null;const{scrollTop:F,scrollLeft:P,velocity:L}=i.current;y({scrollTop:F,scrollLeft:P,velocityOverscan:Ru(L)})}),a.current!==null&&clearTimeout(a.current),a.current=setTimeout(()=>{a.current=null,y(F=>F.velocityOverscan===0?F:{...F,velocityOverscan:0})},200),S&&h(m)},[h]);s.useEffect(()=>{g.current=!0;const b=u.current;!b||r||o<=0||b.clientHeight===0||h(b)},[o,r,h]),s.useEffect(()=>{const b=u.current?.ownerDocument??(typeof document>"u"?null:document);if(!b||typeof MutationObserver>"u")return;const m=new MutationObserver(()=>{const C=u.current;if(!C)return;const E={scrollTop:C.scrollTop,scrollLeft:Ot(C)},_=i.current;E.scrollTop===_.scrollTop&&E.scrollLeft===_.scrollLeft||(i.current={..._,...E},l.current={...l.current,...E},y(I=>({...I,...E})))});return m.observe(b.documentElement,{attributes:!0,attributeFilter:["dir"],subtree:!0}),()=>m.disconnect()},[]);const w=s.useCallback(b=>{if(u.current=b,!b)return;const{scrollTop:m,scrollLeft:C}=i.current;if(m===0&&C===0)return;b.scrollTop=m,en(b,C);const E={scrollTop:b.scrollTop,scrollLeft:Ot(b)};(E.scrollTop!==m||E.scrollLeft!==C)&&(i.current={...i.current,...E},l.current={...l.current,...E},y(_=>({..._,...E})))},[]);return{scrollTop:x.scrollTop,scrollLeft:x.scrollLeft,overscanRows:Math.max(x.velocityOverscan,n),handleScroll:f,attachViewport:w}}function ju(e){const t=s.useRef(null);return s.useCallback(n=>{if(t.current?.disconnect(),t.current=null,!n||typeof ResizeObserver>"u")return;const o=new ResizeObserver(r=>{for(const i of r){const{width:l,height:c}=i.contentRect;e(l,c)}});o.observe(n),t.current=o},[e])}function qu(e){const{setDimensions:t,viewportRef:n,...o}=e,{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:c,attachViewport:a}=Uu(o),u=ju(t),g=s.useCallback(p=>{n.current=p,u(p),a(p)},[n,u,a]);return{scrollTop:r,scrollLeft:i,overscanRows:l,handleScroll:c,setViewportElement:g}}function Xu(e){const[t,n]=s.useState(void 0);return s.useLayoutEffect(()=>{const o=Lc(e.current?.ownerDocument);n(r=>r===o?r:o)},[e]),t}function Yu(e){const{layout:t,scrollTop:n,scrollLeft:o,viewportWidth:r,viewportHeight:i,autoHeight:l,rowReordering:c,hasDetailPanel:a,checkboxSelection:u,pinCheckboxColumn:g,pinExpandColumn:p,overscanRows:x=5,maxContentHeight:y=1/0}=e;return s.useMemo(()=>{const{unpinnedAccWidths:h,unpinnedColsWithWidth:f,leftPinnedCols:w,rightPinnedCols:b,totalWidth:m,leftWidth:C,rightWidth:E,unpinnedTotalWidth:_,systemColumnsWidth:I,cumulativeHeights:M,pinnedTopHeight:S,pinnedBottomHeight:F,unpinnedRowsHeight:P,rowHeights:L,unpinnedRowsLength:k}=t,N=r||1e3,T=l?S+P+F+50:i||600,v=6,W=Math.max(0,o-C),B=o+N-C;let Q=0,$=f.length-1,z=0,V=h.length-1;for(;z<=V;){const O=z+V>>>1;h[O]<W?z=O+1:V=O-1}Q=Math.max(0,z-v);for(let O=Q;O<h.length;O++){if((O===0?0:h[O-1])>B){$=Math.min(f.length-1,O+v);break}$=Math.min(f.length-1,O+v)}const ie=Q>0?h[Q-1]:0,te=_-h[$],ce=[...w,...ie>0?[{field:"__spacer_left__",width:ie,isSpacer:!0}]:[],...f.slice(Q,$+1),...te>0?[{field:"__spacer_right__",width:te,isSpacer:!0}]:[],...b],de=N>0&&m>N?16:0,X=S+P+F+de+2,ne=X-S-F,se=Number.isFinite(y)?Math.max(0,Math.min(ne,y-S-F)):ne;let Y=0,H=k-1,R=0,ae=0,ge=M.length-1;for(;ae<=ge;){const O=ae+ge>>>1;M[O]<n?ae=O+1:ge=O-1}Y=Math.max(0,ae-x),R=Y>0?M[Y-1]:0;for(let O=Y;O<M.length;O++)if(M[O]>=n+T){H=Math.min(k-1,O+x);break}const J=(c?48:0)+(a&&p?48:0)+(u&&g?48:0);return{renderContext:{firstRowIndex:Y,lastRowIndex:H,firstColumnIndex:Q,lastColumnIndex:$},offsetTop:R,offsetLeft:0,totalHeight:X,virtualContainerHeight:se,pinnedTopHeight:S,pinnedBottomHeight:F,totalWidth:m,rowHeights:L,cumulativeHeights:M,virtualColumns:ce,columnMetrics:{leftPinnedWidth:C,rightPinnedWidth:E,unpinnedAccWidths:h,unpinnedCols:f,totalSpecialsWidth:I,pinnedSpecialsWidth:J}}},[t,n,o,r,i,l,c,a,u,g,p,x,y])}function Ju(e){const{viewport:t,viewportRef:n,containerRef:o,layout:r,viewportWidth:i,viewportHeight:l,virtualization:c}=e,{scrollTop:a,scrollLeft:u,overscanRows:g,handleScroll:p,setViewportElement:x}=qu({...t,rowCount:r.unpinnedRowsLength,viewportRef:n}),y=Xu(o),h=Yu({layout:r,scrollTop:a,scrollLeft:u,viewportWidth:i,viewportHeight:l,...c,overscanRows:g,maxContentHeight:y??1/0});return{handleScroll:p,setViewportElement:x,maxContentHeight:y,virtualization:h}}function Zu(e){const{apiRef:t,columns:n,getRowId:o,containerRef:r,disableKeyboardShortcut:i,getCellRangeCopyText:l}=e,c=s.useCallback(()=>r.current,[r]),{copySelectedRows:a}=Jd({getSelectedRowIds:()=>t.current.getSelectedRows(),getColumns:()=>n,getRows:()=>t.current.getAllFilteredRows(),getRowId:o,getRootElement:c,disableKeyboardShortcut:i,getShortcutText:l});s.useLayoutEffect(()=>{t.current.copySelectedRows=a},[a,t])}function Qu(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{t.current.scrollToIndexes=({rowIndex:o,colIndex:r})=>{const{viewportRef:i,layout:l,rowHeight:c}=n.current,a=i.current;if(a&&(o!==void 0&&o>=0&&Nn(a,o,l.cumulativeHeights,l.pinnedBottomHeight,c),r!==void 0&&r>=0)){const g=[...l.leftPinnedCols,...l.unpinnedColsWithWidth,...l.rightPinnedCols][r];if(!g)return;bo(a,l.unpinnedColsWithWidth.findIndex(p=>p.field===g.field),l)}}},[t])}const xl=50;function er(e,t,n,o){const r=Math.min(n??xl,t),i=Math.max(o??1/0,t);return Math.max(r,Math.min(i,e))}const ef=".ogx";function yl(e,t){const n=t.style.cssText;t.style.width="max-content",t.style.minWidth="0",t.style.maxWidth="none",t.style.flex="none";const o=t.getBoundingClientRect().width;t.style.cssText=n;const r=getComputedStyle(e),i=[r.paddingLeft,r.paddingRight,r.borderLeftWidth,r.borderRightWidth].reduce((l,c)=>l+(parseFloat(c)||0),0);return o+i}function tf(e,t){const n=typeof CSS<"u"&&CSS.escape?CSS.escape(t):t.replace(/["\\]/g,"\\$&"),o=l=>l.closest(ef)===e;let r=null;const i=l=>{r=r===null?l:Math.max(r,l)};return e.querySelectorAll(`[role="columnheader"][data-field="${n}"]`).forEach(l=>{if(!o(l))return;const c=l.querySelector(".ogx__header-cell-content");c&&i(yl(l,c))}),e.querySelectorAll(`[role="gridcell"][data-field="${n}"]`).forEach(l=>{if(!o(l)||l.hasAttribute("aria-colspan"))return;const c=l.querySelector(":scope > .ogx__cell-content");c&&i(yl(l,c))}),r===null?null:Math.ceil(r)}function nf(e,t,n){return Math.max(t??xl,Math.min(n??1/0,e))}function of(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e});const o=s.useCallback(i=>{const{containerRef:l,columns:c,onColumnResize:a}=n.current,u=l.current;if(!u)return;const g=[];for(const p of i??c.map(x=>x.field)){const x=c.find(h=>h.field===p);if(!x||x.resizable===!1)continue;const y=tf(u,p);y!==null&&g.push([p,nf(y,x.minWidth,x.maxWidth)])}for(const[p,x]of g)a(p,x)},[]),r=s.useCallback(i=>o([i]),[o]);return s.useLayoutEffect(()=>{t.current.autosizeColumn=r,t.current.autosizeColumns=o},[t,r,o]),r}function rf(e){const{apiRef:t,containerRef:n,viewportRef:o,copyColumns:r,getRowId:i,disableClipboardCopy:l,getCellRangeCopyText:c,layout:a,rowHeight:u,orderedColumns:g,onColumnResize:p}=e;return Zu({apiRef:t,columns:r,getRowId:i,containerRef:n,disableKeyboardShortcut:l,getCellRangeCopyText:c}),Qu({apiRef:t,viewportRef:o,layout:a,rowHeight:u}),of({apiRef:t,containerRef:n,columns:g,onColumnResize:p})}class Cl extends Error{}function ut(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function vl(e){return typeof e=="object"&&e!==null&&typeof e.then=="function"}function Sl(e,t){t?t(e):process.env.NODE_ENV!=="production"&&e instanceof Cl&&console.error(e.message)}function _l(e,t){return new Cl(`[OpenGridX] processRowUpdate must return the updated row object (or a Promise of it); it returned ${e===null?"null":typeof e}. ${t}`)}function kl(e,t,n,o){return n?.valueSetter?n.valueSetter({value:t.value,row:e,field:t.field}):(n?.valueGetter&&process.env.NODE_ENV!=="production"&&!o.has(t.field)&&(o.add(t.field),console.warn(`[OpenGridX] Column "${t.field}" is editable and has a valueGetter but no valueSetter. The edited value was written to row["${t.field}"], which the valueGetter may ignore, so the cell can keep showing the old value. Add a valueSetter that maps the value back onto the row.`)),{...e,[t.field]:t.value})}function lf(e){const t=s.useRef(e),n=s.useRef(new Map),o=s.useRef(new Set);s.useLayoutEffect(()=>{t.current=e,n.current.clear()});const r=s.useCallback(a=>{const u=n.current.get(a);return u===void 0?t.current.rowsLookup.get(a):u},[]),i=s.useCallback(a=>{a.size!==0&&(a.forEach((u,g)=>{n.current.set(g,u)}),t.current.replaceRows(a))},[]),l=s.useCallback((a,u)=>{i(new Map([[a,u]]))},[i]),c=s.useCallback((a,u)=>{const{columns:g,processRowUpdate:p}=t.current,x=_=>Sl(_,t.current.onProcessRowUpdateError),y=new Map,h=new Map;g.forEach((_,I)=>{y.set(_.field,I),h.set(_.field,_)});const f=[],w=new Map;for(const _ of a){const I=r(_.id);if(I===void 0){f.push({id:_.id,field:_.field,reason:"missing"});continue}const M=h.get(_.field);if(_.expect&&!ut(Ee(I,_.field,M),_.expect.value)){f.push({id:_.id,field:_.field,reason:"changed"});continue}let S=w.get(_.id);S||(S={id:_.id,row:I,cells:[]},w.set(_.id,S));const F=y.get(_.field)??Number.MAX_SAFE_INTEGER,P=S.cells.findIndex(k=>k.field===_.field),L={field:_.field,value:_.value,colDef:M,order:F};P===-1?S.cells.push(L):S.cells[P]=L}const b=[],m=[],C=o.current;w.forEach(_=>{const{id:I,row:M}=_,S=_.cells.filter(L=>!ut(Ee(M,L.field,L.colDef),L.value)).sort((L,k)=>L.order-k.order);if(_.cells=S,S.length===0)return;const F=We(()=>{let L=M;for(const k of S)L=kl(L,k,k.colDef,C);return p?p(L,M):L});if(!F.ok){b.push({id:I,ok:!1,error:F.error});return}const P=F.value;vl(P)?m.push(Promise.resolve(P).then(L=>({id:I,ok:!0,processed:L}),L=>({id:I,ok:!1,error:L}))):b.push({id:I,ok:!0,processed:P})});const E=_=>{const I=new Map;_.forEach(L=>{I.set(L.id,L)});const M=[],S=[],F=[],P=new Map;return w.forEach(L=>{const k=I.get(L.id);if(!k)return;if(!k.ok){S.push({id:L.id,error:k.error}),x(k.error);return}const N=k.processed;if(typeof N!="object"||N===null){const v=_l(N,"The row was not saved.");S.push({id:L.id,error:v}),x(v);return}const T=N;P.set(L.id,T),M.push(L.id);for(const v of L.cells){const W=Ee(L.row,v.field,v.colDef),B=Ee(T,v.field,v.colDef);ut(W,B)||F.push({id:L.id,field:v.field,before:W,after:B})}}),i(P),F.length>0&&u!=="undo"&&u!=="redo"&&t.current.onCommitted?.(F,u),{result:{updated:M,failed:S,skipped:f},committed:F}};return m.length===0?Promise.resolve(E(b)):Promise.all(m).then(_=>E([...b,..._]))},[r,i]);return s.useMemo(()=>({applyEdits:c,getRow:r,storeRow:l}),[c,r,l])}const zt=Promise.resolve();function sf(e){const[t,n]=s.useState(null),o=s.useRef(null),r=s.useRef(0),i=s.useRef(new Map),l=s.useRef(new Set),c=s.useRef(!1),a=s.useRef(e);s.useLayoutEffect(()=>{a.current=e}),s.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]);const u=s.useCallback(f=>{o.current=f,n(f)},[]),g=s.useRef(null),p=s.useCallback((f,w)=>{const b=i.current.get(f);if(b)return ut(b.value,w.value)?b.promise:b.promise.then(()=>{const $=o.current;if(!(r.current!==f||!$||ut($.value,b.value)))return g.current?.(f,$)});const m=()=>r.current===f&&o.current!==null;if(ut(w.value,w.originalValue))return m()&&u(null),zt;const{rows:C,getRowId:E,columns:_,processRowUpdate:I}=a.current,M=C.find($=>E($)===w.id);if(!M)return m()&&u(null),zt;const S=$=>Sl($,a.current.onProcessRowUpdateError),F=_?.find($=>$.field===w.field),P=$=>{if(typeof $!="object"||$===null){S(_l($,"The edit was not saved and the editor stays open."));return}a.current.onRowChange?.($,w.id);const{onCommitted:z}=a.current;if(z){const ie=Ee(M,w.field,F),te=Ee($,w.field,F);ut(ie,te)||z([{id:w.id,field:w.field,before:ie,after:te}])}const V=o.current;r.current!==f||!V||(ut(V.value,w.value)?u(null):u({...V,originalValue:w.value}))};let L,k;const N=new Promise(($,z)=>{L=$,k=z}),T={value:w.value,promise:N};i.current.set(f,T);const v=()=>{i.current.get(f)===T&&i.current.delete(f)},W=We(()=>{const $=kl(M,w,F,l.current);return I?I($,M):$});if(!W.ok)return v(),S(W.error),L(),N;const B=W.value,Q=$=>{v();try{P($),L()}catch(z){k(z)}};return vl(B)?Promise.resolve(B).then(Q,$=>{v(),S($),L()}):Q(B),N},[u]);s.useLayoutEffect(()=>{g.current=p},[p]);const x=s.useCallback(f=>{const w=o.current;if(w){if(w.id===f.id&&w.field===f.field)return;p(r.current,w)}r.current+=1,u({id:f.id,field:f.field,value:f.value,originalValue:f.value})},[p,u]),y=s.useCallback(f=>{const w=o.current;return!w||!c.current||f?.id!==void 0&&f.id!==w.id||f?.field!==void 0&&f.field!==w.field?zt:f?.cancel?(u(null),zt):p(r.current,w)},[p,u]),h=s.useCallback(f=>{const w=o.current;!w||w.id!==f.id||w.field!==f.field||u({...w,value:f.value})},[u]);return s.useMemo(()=>({editingCell:t,startCellEdit:x,stopCellEdit:y,setEditCellValue:h}),[t,x,y,h])}function af(e){const{rowsLookup:t,rows:n,getRowId:o,columns:r,processRowUpdate:i,onProcessRowUpdateError:l,replaceRows:c}=e,a=yu(),u=lf({rowsLookup:t,columns:r,processRowUpdate:i,onProcessRowUpdateError:l,replaceRows:c,onCommitted:a.emit}),g=sf({rows:n,getRowId:o,columns:r,processRowUpdate:i,onProcessRowUpdateError:l,onRowChange:(p,x)=>{u.storeRow(x,p)},onCommitted:p=>a.emit(p,"edit")});return{editCommitChannel:a,batchEdit:u,editingHandlers:g}}const cf=e=>e.id,df={hasColSpan:!1,hasRowSpan:!1,colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},getSpanOrigin:()=>null,getUnpinnedColSpanRanges:()=>{},getCenterRowSpanStart:e=>e},El="\0",Ml="";function Il(e){if(typeof e!="number"||Number.isNaN(e))return 1;if(e===1/0)return Number.MAX_SAFE_INTEGER;if(!Number.isFinite(e))return 1;const t=Math.floor(e);return t<1?1:t}function uf(e){return e.map(t=>t.field).join(El)}function ff(e){const{pinnedTopRows:t,centerRows:n,pinnedBottomRows:o,columns:r,leftPinnedColumns:i,unpinnedColumns:l,rightPinnedColumns:c,expandedRowIds:a,rowMetaMap:u,getRowId:g=cf}=e,p=s.useMemo(()=>r.some(b=>b.colSpan!==void 0&&b.colSpan!==null),[r]),x=s.useMemo(()=>r.some(b=>b.rowSpan!==void 0&&b.rowSpan!==null),[r]),y=p||x,h=y?[i,l,c].map(uf).join(Ml):"",f=s.useMemo(()=>{if(!h)return{columns:[],leftCount:0,unpinnedCount:0};const b=new Map(r.map(_=>[_.field,_])),m=h.split(Ml).map(_=>_?_.split(El):[]),C=[];let E=0;for(const _ of m){E+=_.length;for(const I of _){const M=b.get(I)??{field:I};C.push({colDef:M,field:I,sectionEnd:E,hasColSpan:M.colSpan!==void 0&&M.colSpan!==null,hasRowSpan:M.rowSpan!==void 0&&M.rowSpan!==null})}}return{columns:C,leftCount:m[0].length,unpinnedCount:m[1].length}},[h,r]),w=s.useMemo(()=>{if(!y||f.columns.length===0)return null;const b={colspanMap:new Map,rowSpanningCaches:{spannedCells:{},hiddenCells:{},hiddenCellOriginMap:{}},hiddenOriginFields:new Map,unpinnedRanges:new Map,centerRowSpanStart:new Map},C={spanColumns:f,expandedRowIds:a,rowMetaMap:u,getRowId:g,warned:new Set,out:b};return tr(t,0,!1,C),tr(n,t.length,!0,C),tr(o,t.length+n.length,!1,C),b},[y,f,t,n,o,a,u,g]);return s.useMemo(()=>{if(!w)return df;const{colspanMap:b,rowSpanningCaches:m,hiddenOriginFields:C,unpinnedRanges:E,centerRowSpanStart:_}=w,I=f.columns;return{hasColSpan:p,hasRowSpan:x,colspanMap:b,rowSpanningCaches:m,getSpanOrigin:(M,S)=>{const F=b.get(M)?.[S];if(F?.spannedByColSpan)return{rowId:M,field:I[F.leftVisibleCellIndex].field};const P=m.hiddenCellOriginMap[M]?.[S];return P===void 0?null:{rowId:P,field:C.get(M)?.[S]??S}},getUnpinnedColSpanRanges:M=>E.get(M),getCenterRowSpanStart:M=>_.get(M)??M}},[w,p,x,f])}function tr(e,t,n,o){const{spanColumns:r,expandedRowIds:i,rowMetaMap:l,getRowId:c,warned:a,out:u}=o,{columns:g,leftCount:p,unpinnedCount:x}=r,y=g.length,{colspanMap:h,rowSpanningCaches:f,hiddenOriginFields:w,unpinnedRanges:b,centerRowSpanStart:m}=u,C=new Int32Array(y),E=new Array(y),_=new Array(y),I=new Int32Array(y);let M=0;const S=[];g.forEach((L,k)=>{(L.hasColSpan||L.hasRowSpan)&&S.push(k)});const F=(L,k,N)=>{const T=g[N].field;if(Kt(f.hiddenCells,L,T,!0),Kt(f.hiddenCellOriginMap,L,T,E[N]),_[N]!==T&&Kt(w,L,T,_[N]),n){const v=m.get(k);(v===void 0||I[N]<v)&&m.set(k,I[N])}},P=(L,k,N)=>{const T=g[N],v=c(L),W=gf(L,v,T.colDef,t+k,N,l,a);let B=1;if(T.hasColSpan){const $=Math.min(Nl(T.colDef.colSpan,W,"colSpan",T.field,a),T.sectionEnd-N);for(;B<$&&C[N+B]<=k;)B++}let Q=1;if(T.hasRowSpan){Q=Math.min(Nl(T.colDef.rowSpan,W,"rowSpan",T.field,a),e.length-k);for(let $=1;$<Q;$++)if(Re(c(e[k+$]),l)){Q=$;break}if(Q>1&&i&&i.size>0){for(let $=0;$<Q-1;$++)if(i.has(c(e[k+$]))){Q=$+1;break}}}if(B>1){Kt(h,v,T.field,{spannedByColSpan:!1,cellProps:{colSpan:B}});for(let $=1;$<B;$++){const z=g[N+$];Kt(h,v,z.field,{spannedByColSpan:!0,leftVisibleCellIndex:N,rightVisibleCellIndex:N+B-1})}if(N>=p&&N<p+x){let $=b.get(v);$||($=[],b.set(v,$)),$.push(N-p,N+B-1-p)}}if(Q>1){Kt(f.spannedCells,v,T.field,Q);for(let $=N;$<N+B;$++)C[$]=k+Q,E[$]=v,_[$]=T.field,I[$]=k;k+Q>M&&(M=k+Q)}return B};for(let L=0;L<e.length;L++){const k=e[L];if(!k||Re(c(k),l))continue;if(M<=L){let T=0;for(const v of S)v>=T&&(T=v+P(k,L,v));continue}let N=0;for(;N<y;)C[N]>L?(F(c(k),L,N),N++):g[N].hasColSpan||g[N].hasRowSpan?N+=P(k,L,N):N++}}function gf(e,t,n,o,r,i,l){const c=e[n.field];let a=c;if(n.valueGetter)try{a=n.valueGetter({row:e,field:n.field,value:c})}catch(u){Ll(l,`valueGetter:${n.field}`,`valueGetter for column "${n.field}" threw while computing its span`,u),a=void 0}return{row:e,value:a,field:n.field,colDef:n,rowIndex:o,colIndex:r,rowMeta:i?.get(t)}}function Nl(e,t,n,o,r){if(typeof e=="number")return Il(e);if(typeof e!="function")return 1;try{return Il(e(t))}catch(i){return Ll(r,`${n}:${o}`,`${n} for column "${o}" threw; the cell is rendered without a span`,i),1}}function Ll(e,t,n,o){process.env.NODE_ENV==="production"||e.has(t)||(e.add(t),console.warn(`[OpenGridX] ${n}.`,o))}function Kt(e,t,n,o){if(e instanceof Map){let i=e.get(t);i||(i={},e.set(t,i)),i[n]=o;return}let r=e[t];r||(r={},e[t]=r),r[n]=o}function pf(e,t){const{draggedColumn:n,onDragOver:o,onDrop:r,onDragEnd:i}=t,l=s.useMemo(()=>{if(!e||e.length===0)return null;const c=a=>n===null||Ro(e,n,a);return{onDragOver:o&&(a=>c(a)?o(a):()=>{}),onDrop:r&&(a=>c(a)?r(a):u=>{u.preventDefault(),i?.()})}},[e,n,o,r,i]);return l?{...t,...l}:t}function Pl({dataSource:e,paginationMode:t,sortingMode:n,filterMode:o}){return!!e&&(t==="server"||t==="infinite"||n==="server"||o==="server")}const Tl=Number.MAX_SAFE_INTEGER,hf="An unexpected error occurred while loading the data.";function Al(e){return typeof e=="string"&&e?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"&&e.message?e.message:hf}const mf=300,Fl=e=>e.id;function wf(e,t){return e==="infinite"?"infinite":e==="server"?t?"all":"page":"all"}function Ol(e,t){const n=new Set,o=[];return e.forEach(r=>{const i=t(r);n.has(i)||(n.add(i),o.push({id:i,row:r}))}),o}function Dl(e,t,n){const o=new Set(e.map(n)),r=t.filter(i=>!o.has(i.id)).map(i=>i.row);return r.length===0?e:[...e,...r]}function bf(e){const{dataSource:t,sortModel:n,filterModel:o,paginationModel:r,paginationMode:i,sortingMode:l,filterMode:c,aggregationModel:a,rowGroupingActive:u=!1}=e,g=wf(i,u),p=!!t&&i==="server"&&u,x=s.useRef(!1);s.useEffect(()=>{process.env.NODE_ENV==="production"||x.current||!p||(x.current=!0,console.warn("[OpenGridX] `rowGroupingModel` turns pagination off, so the dataSource with `paginationMode: 'server'` is asked for every row (startRow 0, endRow Number.MAX_SAFE_INTEGER) instead of one page. See docs/features/data-source.md."))},[p]);const y=t?.getRows,h=Pl({dataSource:t,paginationMode:i,sortingMode:l,filterMode:c}),f=JSON.stringify([g,g!=="all"||l==="server"?n:null,g!=="all"||c==="server"?o:null,h?a??null:null,g==="all"?null:r.pageSize]),w=g==="all"?0:r.page,b=g==="all"?0:r.pageSize,m=s.useRef({params:e,kind:g});s.useLayoutEffect(()=>{m.current={params:e,kind:g}});const C=s.useRef(0),E=s.useRef(0),_=s.useRef(null),I=s.useRef({page:0,loadedEnd:0,inFlightEnd:null}),M=s.useRef(null),S=s.useRef(!1),F=s.useRef(0),P=s.useRef(!1),L=s.useRef(new Set),k=s.useCallback(()=>{const z=S.current||F.current>0;z!==P.current&&(P.current=z,m.current.params.setDataSourceLoading(z))},[]),N=s.useCallback(()=>{M.current!==null&&(clearTimeout(M.current),M.current=null)},[]),T=s.useCallback(()=>{C.current++,I.current.inFlightEnd=null,S.current=!1},[]),v=s.useCallback(()=>{E.current++,L.current.clear(),F.current=0},[]),W=s.useCallback(async()=>{const{params:z,kind:V}=m.current,ie=z.dataSource;if(!ie)return!1;const te=I.current,ce=z.paginationModel.pageSize;let oe,de;if(V==="infinite"){if(te.inFlightEnd!==null)return!1;if(oe=te.loadedEnd,de=(te.page+1)*ce,de<=oe)return S.current=!1,k(),!1;te.inFlightEnd=de}else V==="page"?(oe=z.paginationModel.page*ce,de=oe+ce):(oe=0,de=Tl);const X=++C.current;S.current=!0,k(),z.setDataSourceError(null);let ne;try{ne=await ie.getRows({startRow:oe,endRow:de,sortModel:z.sortModel,filterModel:z.filterModel,groupKeys:[],aggregationModel:z.aggregationModel})}catch(se){return X!==C.current||(te.inFlightEnd=null,S.current=!1,m.current.params.setDataSourceError(se),console.error("Data Source Error:",se),k()),!1}if(X!==C.current)return!1;try{const{params:se}=m.current,Y=se.getRowId??Fl,H=Ol(ne.rows,Y);if(V==="infinite"&&oe>0?se.setRows(R=>Dl(R,H,Y),!0):(se.setRows(H.map(R=>R.row),!0),v()),ne.aggregationResults&&se.onAggregationResults?.(ne.aggregationResults),ne.rowCount!==void 0&&se.setRowCount(ne.rowCount),V==="infinite"&&(te.inFlightEnd=null,te.loadedEnd=oe+ne.rows.length,ne.rows.length>=de-oe&&(te.page+1)*ce>de))return!0}catch(se){return te.inFlightEnd=null,S.current=!1,m.current.params.setDataSourceError(se),console.error("Data Source Error:",se),k(),!1}return S.current=!1,k(),!1},[k,v]),B=s.useCallback(async()=>{for(;await W(););},[W]);s.useLayoutEffect(()=>{if(!y){_.current&&(_.current=null,N(),T(),v(),m.current.params.setDataSourceError(null),k());return}const z=_.current,V=I.current;if(!z||z.key!==f||z.getRows!==y){_.current={key:f,getRows:y},T(),v();const ie=g==="infinite"&&z!==null&&w!==0;if(V.page=ie?0:w,V.loadedEnd=0,ie){const{params:te}=m.current;te.onPaginationModelChange?.({...te.paginationModel,page:0})}}else g==="infinite"?(w<V.page&&(T(),V.loadedEnd=0),V.page=w):T();if(g==="infinite"){const ie=V.inFlightEnd!==null;if(ie||(V.page+1)*b<=V.loadedEnd){S.current=ie,k();return}}return S.current=!0,k(),M.current=setTimeout(()=>{M.current=null,B()},mf),N},[y,f,g,w,b,N,T,v,k,B]),s.useEffect(()=>()=>{T(),v()},[T,v]);const Q=s.useCallback(()=>(N(),B()),[N,B]),$=s.useCallback(async(z,V,ie)=>{const{params:te}=m.current,ce=te.dataSource;if(!ce)return;const oe=JSON.stringify(V),de=L.current;if(de.has(oe))return;const X=E.current;de.add(oe),F.current++,k();try{const ne=await ce.getRows({startRow:0,endRow:Tl,sortModel:te.sortModel,filterModel:te.filterModel,groupKeys:V,aggregationModel:te.aggregationModel});if(X!==E.current)return;if(ne.rows.length>0){const{params:se}=m.current,Y=se.getRowId??Fl,H=Ol(ne.rows,Y);se.setRows(R=>Dl(R,H,Y),!0)}}catch(ne){if(X!==E.current)return;de.delete(oe),console.error("Failed to fetch children:",ne),ie?.(ne)}finally{X===E.current&&(F.current--,k())}},[k]);return{fetchRows:Q,fetchChildren:$}}function xf(e){return(e.serverChildrenCount??0)>0&&(e.children?.length??0)===0}function yf({enabled:e,treeNodes:t,isGroupExpanded:n,getNodePath:o,toggleExpansion:r,fetchChildren:i}){const l=s.useRef({isGroupExpanded:n,toggleExpansion:r});s.useLayoutEffect(()=>{l.current={isGroupExpanded:n,toggleExpansion:r}}),s.useEffect(()=>{e&&t.forEach((c,a)=>{!xf(c)||!n(a)||i(a,o(a),()=>{const{isGroupExpanded:u,toggleExpansion:g}=l.current;u(a)&&g(a)})})},[e,t,n,o,i])}const $l={};function Cf(e){const t=JSON.stringify(e),[n,o]=s.useState(null),r=s.useCallback(i=>o({modelKey:t,results:i}),[t]);return[n&&n.modelKey===t?n.results:null,r]}function Gl(e){const{rows:t,columns:n,aggregationModel:o,isServerSide:r,dataSource:i,filterModel:l,sortModel:c,serverAggregationResults:a}=e,u=Object.keys(o).length>0,g=s.useMemo(()=>{const _=new Map;return(n??[]).forEach(I=>_.set(I.field,I)),_},[n]),p=s.useMemo(()=>r||!u?$l:Ln(t,o,g,"useAggregation"),[t,g,o,r,u]),x=JSON.stringify([o,l??null,c??[]]),y=r&&u&&!!i?.getAggregations&&!a,h=s.useRef({aggregationModel:o,filterModel:l,sortModel:c});s.useEffect(()=>{h.current={aggregationModel:o,filterModel:l,sortModel:c}});const[f,w]=s.useState(null);s.useEffect(()=>{const _=i?.getAggregations;if(!y||!_)return;let I=!1;const M=h.current,S={sortModel:M.sortModel??[],filterModel:M.filterModel??{items:[]},groupKeys:[],aggregationModel:M.aggregationModel};let F;try{F=Promise.resolve(_(S))}catch(P){F=Promise.reject(P)}return F.then(P=>{I||w({key:x,result:P,error:null})},P=>{I||(console.error("[useAggregation] Server aggregation error:",P),w({key:x,result:null,error:P}))}),()=>{I=!0}},[y,i,x]);const b=f&&f.key===x?f:null,m=y&&b===null,C=y?b?.error??null:null;return{aggregationResult:s.useMemo(()=>r?a&&Object.keys(a).length>0?a:b?.result??$l:p,[r,p,a,b]),isLoading:m,error:C}}const vf={items:[]},Sf=[];function _f(e){const{rows:t,columns:n,pivotMode:o,pivotModel:r,filterModel:i,sortModel:l,hasDataSource:c,hierarchyRequested:a}=e,u=o&&!c,g=s.useMemo(()=>new Set(n.map(b=>b.field)),[n]),p=s.useMemo(()=>Lo(n),[n]),x=s.useMemo(()=>tc(i,g),[i,g]),y=s.useMemo(()=>u?ko(t,x.source,p):t,[u,t,x.source,p]),h=s.useMemo(()=>u?vi(y,n,r,{outputFilterModel:x.output,sortModel:l}):To,[u,y,n,r,x.output,l]),f=u&&h.isValid,w=s.useRef({dataSource:!1,hierarchy:!1});return s.useEffect(()=>{process.env.NODE_ENV!=="production"&&(o&&c&&!w.current.dataSource&&(w.current.dataSource=!0,console.warn("[OpenGridX] `pivotMode` is ignored when a `dataSource` is set: pivoting is client-side and the grid only holds the rows of one server page. Pivot on the server, or pass the full dataset as `rows`.")),f&&a&&!w.current.hierarchy&&(w.current.hierarchy=!0,console.warn("[OpenGridX] `treeData` and `rowGroupingModel` are turned off while `pivotMode` is active: the pivot rows are already grouped by the pivot row fields.")))},[o,c,f,a]),{isActive:f,rows:f?h.pivotRows:t,columns:f?h.pivotColumns:n,pipelineFilterModel:f?vf:i,pipelineSortModel:f?Sf:l}}const Hl=s.createContext(null);function kf(e){if(typeof e!="function")return!1;const t=e.prototype;return!(typeof t=="object"&&t!==null&&"isReactComponent"in t)}function Ef({render:e,toolbarProps:t}){"use no memo";return d.jsx(d.Fragment,{children:e(t)})}function Mf({component:e,toolbarProps:t}){if(kf(e))return d.jsx(Ef,{render:e,toolbarProps:t},`fn:${e.toString()}`);const n=e;return d.jsx(n,{...t})}const Qe=({variant:e="text",size:t="medium",color:n="default",disabled:o=!1,className:r="",type:i="button",children:l,...c})=>{const a=["ogx-button",`ogx-button--${e}`,`ogx-button--${t}`,`ogx-button--${n}`,o&&"ogx-button--disabled",r].filter(Boolean).join(" ");return d.jsx("button",{type:i,className:a,disabled:o,...c,children:l})},et=s.forwardRef(function({fullWidth:t=!1,error:n=!1,startAdornment:o,endAdornment:r,className:i="",inputClassName:l="",variant:c="field",...a},u){const g=["ogx-input-wrapper",c==="cell"&&"ogx-input-wrapper--cell",t&&"ogx-input-wrapper--full-width",n&&"ogx-input-wrapper--error",a.disabled&&"ogx-input-wrapper--disabled",i].filter(Boolean).join(" "),p=["ogx-input",l].filter(Boolean).join(" ");return d.jsxs("div",{className:g,children:[o&&d.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--start",children:o}),d.jsx("input",{ref:u,className:p,"aria-invalid":n?!0:void 0,...a}),r&&d.jsx("div",{className:"ogx-input__adornment ogx-input__adornment--end",children:r})]})});et.displayName="Input";function If(){if(typeof window>"u")return null;const e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function Nf(e){const[t,n]=s.useState(!1),o=s.useRef(null),r=s.useRef(e);s.useLayoutEffect(()=>{r.current=e}),s.useEffect(()=>()=>{const l=o.current;o.current=null,l&&We(()=>l.abort())},[]);const i=s.useCallback(()=>{const l=o.current;if(l){We(()=>l.stop());return}const c=If();if(!c)return;const a=We(()=>new c);if(!a.ok)return;const u=a.value;u.lang=typeof navigator>"u"?"en-US":navigator.language,u.interimResults=!1,u.maxAlternatives=1,u.onresult=p=>{const x=p.results[0],y=x&&x[0]?x[0].transcript:"";y&&r.current(y)};const g=()=>{o.current===u&&(o.current=null),n(!1)};u.onend=g,u.onerror=g,o.current=u,n(!0),We(()=>u.start()).ok||g()},[]);return{listening:t,toggle:i}}function Bl(){return d.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:[d.jsx("path",{d:"M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9z"}),d.jsx("path",{d:"M19 15l.8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8z"})]})}function Lf(){return d.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",focusable:"false",children:[d.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),d.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}function Pf(e){const{status:t,statusText:n,message:o,errors:r,chips:i,history:l,suggestions:c,placeholder:a,voiceAvailable:u,canUndo:g,submit:p,stop:x,undo:y,removeChip:h,close:f}=e,[w,b]=s.useState(""),m=s.useRef(null),C=Nf(b),E=t==="running";s.useEffect(()=>{m.current&&m.current.focus()},[]);const _=S=>{b(S),p(S)},I=S=>()=>{S(),m.current&&m.current.focus()},M=S=>{S.preventDefault(),E||p(w)};return d.jsxs("div",{className:"ogx-ai-panel",role:"dialog","aria-label":"Ask AI",children:[d.jsxs("div",{className:"ogx-ai-panel__header",children:[d.jsxs("span",{className:"ogx-ai-panel__title",children:[d.jsx(Bl,{}),"Ask AI"]}),d.jsx(Qe,{size:"small",className:"ogx-ai-panel__close","aria-label":"Close",onClick:f,children:"×"})]}),d.jsxs("form",{className:"ogx-ai-panel__form",onSubmit:M,children:[d.jsx(et,{ref:m,className:"ogx-ai-panel__input",value:w,placeholder:a,"aria-label":"Prompt",autoComplete:"off",onChange:S=>b(S.target.value)}),u&&d.jsx(Qe,{size:"small",variant:"outlined",className:`ogx-ai-panel__mic${C.listening?" ogx-ai-panel__mic--on":""}`,"aria-label":C.listening?"Stop dictation":"Dictate a prompt","aria-pressed":C.listening,onClick:C.toggle,children:d.jsx(Lf,{})}),E?d.jsx(Qe,{size:"small",variant:"outlined",onClick:I(x),children:"Stop"},"stop"):d.jsx(Qe,{size:"small",variant:"contained",color:"primary",type:"submit",disabled:w.trim()==="",children:"Ask"},"ask")]}),c.length>0&&d.jsx("div",{className:"ogx-ai-panel__suggestions","aria-label":"Suggestions",role:"group",children:c.map(S=>d.jsx("button",{type:"button",className:"ogx-ai-panel__suggestion",disabled:E,onClick:()=>_(S),children:S},S))}),n&&d.jsx("div",{className:`ogx-ai-panel__status ogx-ai-panel__status--${t}`,children:n}),o&&d.jsx("p",{className:"ogx-ai-panel__message",children:o}),(i.length>0||g)&&d.jsxs("div",{className:"ogx-ai-panel__changes",children:[d.jsx("ul",{className:"ogx-ai-panel__chips","aria-label":"Applied changes",children:i.map(S=>d.jsxs("li",{className:"ogx-ai-chip","data-part":S.part,children:[d.jsx("span",{className:"ogx-ai-chip__label",children:S.label}),d.jsx("button",{type:"button",className:"ogx-ai-chip__remove","aria-label":`Remove ${S.label}`,onClick:I(()=>h(S.id)),children:"×"})]},S.id))}),g&&d.jsx(Qe,{size:"small",variant:"outlined",className:"ogx-ai-panel__undo",onClick:I(y),children:"Undo"})]}),r.length>0&&d.jsx("ul",{className:"ogx-ai-panel__errors","aria-label":"Ignored",children:r.map((S,F)=>d.jsx("li",{children:S.path?`Ignored: ${S.message}`:S.message},`${S.path}:${F}`))}),l.length>0&&d.jsxs("div",{className:"ogx-ai-panel__history",children:[d.jsx("div",{className:"ogx-ai-panel__history-title",children:"Earlier"}),d.jsx("ul",{children:l.map((S,F)=>d.jsx("li",{children:d.jsx("button",{type:"button",className:"ogx-ai-panel__history-item",onClick:()=>b(S.prompt),children:S.prompt})},`${F}:${S.prompt}`))})]})]})}function Tf({panelProps:e,slot:t,slotProps:n}){const o=r=>{r.key==="Escape"&&(r.stopPropagation(),e.close())};return d.jsx("div",{className:"ogx-ai-anchor",onKeyDown:o,children:t?d.jsx(t,{...e,...n}):d.jsx(Pf,{...e})})}function Wl(e,t){typeof e=="function"?e(t):e&&(e.current=t)}const ft=s.forwardRef(function({indeterminate:t=!1,label:n,className:o="",inputClassName:r="",inputRef:i,...l},c){const a=s.useRef(null),u=s.useCallback(p=>{a.current=p,Wl(i,p),Wl(c,p)},[i,c]);s.useEffect(()=>{a.current&&(a.current.indeterminate=t)},[t]);const g=["ogx-checkbox-wrapper",l.disabled&&"ogx-checkbox-wrapper--disabled",o].filter(Boolean).join(" ");return d.jsxs("label",{className:g,children:[d.jsx("input",{ref:u,type:"checkbox",className:["ogx-checkbox__input",r].filter(Boolean).join(" "),...l}),d.jsxs("span",{className:"ogx-checkbox__box",children:[l.checked&&!t&&d.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:d.jsx("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})}),t&&d.jsx("svg",{className:"ogx-checkbox__icon",viewBox:"0 0 24 24","aria-hidden":"true",children:d.jsx("path",{d:"M19 13H5v-2h14v2z"})})]}),n&&d.jsx("span",{className:"ogx-checkbox__label",children:n})]})});ft.displayName="Checkbox";function Af(){return d.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("circle",{cx:"11",cy:"11",r:"8"}),d.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Ff(){return d.jsxs("svg",{className:"ogx-column-visibility-panel__drag-handle",width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:[d.jsx("circle",{cx:"9",cy:"5",r:"1.5"}),d.jsx("circle",{cx:"15",cy:"5",r:"1.5"}),d.jsx("circle",{cx:"9",cy:"12",r:"1.5"}),d.jsx("circle",{cx:"15",cy:"12",r:"1.5"}),d.jsx("circle",{cx:"9",cy:"19",r:"1.5"}),d.jsx("circle",{cx:"15",cy:"19",r:"1.5"})]})}function nr(e){const{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:c,showNonHideableColumns:a}=e,[u,g]=s.useState(""),p=s.useId(),[x,y]=s.useState(null),h=s.useRef(null),f=s.useMemo(()=>t.filter(S=>S.hideable!==!1),[t]),w=f.every(S=>n.has(S.field)),b=s.useMemo(()=>{const S=a?t:f;if(!u)return S;const F=u.toLowerCase();return S.filter(P=>(P.headerName||P.field).toLowerCase().includes(F))},[t,f,u,a]),m=S=>{S.target.checked?r():i()},C=S=>F=>{h.current=S,F.dataTransfer.effectAllowed="move",F.dataTransfer.setDragImage(F.currentTarget.closest(".ogx-column-visibility-panel__item"),20,20)},E=S=>F=>{F.preventDefault(),F.dataTransfer.dropEffect="move",S!==h.current&&y(S)},_=()=>{y(null)},I=S=>F=>{F.preventDefault();const P=h.current;y(null),h.current=null,P&&P!==S&&l&&l(P,S)},M=()=>{y(null),h.current=null};return d.jsxs("div",{className:"ogx-column-visibility-panel",children:[d.jsx("div",{className:"ogx-column-visibility-panel__search-section",children:d.jsxs("div",{className:"ogx-column-visibility-panel__search-container",children:[d.jsx(Af,{}),d.jsx(et,{autoComplete:"off",inputClassName:"ogx-column-visibility-panel__search-input",placeholder:"Search",value:u,onChange:S=>g(S.target.value)})]})}),d.jsx("div",{className:"ogx-column-visibility-panel__list",children:b.map((S,F)=>{const P=`${p}-col-${F}`,L=n.has(S.field),k=S.hideable!==!1,N=x===S.field,T=!!l&&!u;return d.jsxs("div",{className:["ogx-column-visibility-panel__item",!k&&"ogx-column-visibility-panel__item--disabled",N&&"ogx-column-visibility-panel__item--drag-over"].filter(Boolean).join(" "),draggable:T,onDragOver:T?E(S.field):void 0,onDragLeave:T?_:void 0,onDrop:T?I(S.field):void 0,onDragEnd:T?M:void 0,children:[T&&d.jsx("span",{className:"ogx-column-visibility-panel__drag-handle-wrapper",draggable:!0,onDragStart:C(S.field),title:"Drag to reorder",children:d.jsx(Ff,{})}),d.jsxs("div",{className:"ogx-column-visibility-panel__item-label",style:{display:"flex",alignItems:"center",gap:"var(--ogx-spacing-md)",flex:1,cursor:k?"pointer":"not-allowed"},children:[d.jsx(ft,{id:P,checked:L,onChange:v=>o(S.field,v.target.checked),disabled:!k}),d.jsx("label",{htmlFor:P,className:"ogx-column-visibility-panel__label",children:S.headerName||S.field})]})]},S.field)})}),d.jsxs("div",{className:"ogx-column-visibility-panel__footer",children:[d.jsxs("div",{className:"ogx-column-visibility-panel__item",children:[d.jsx(ft,{id:`${p}-all`,checked:w,onChange:m}),d.jsx("label",{htmlFor:`${p}-all`,className:"ogx-column-visibility-panel__label",children:"Show/Hide All"})]}),d.jsx("button",{type:"button",className:"ogx-column-visibility-panel__reset-btn",onClick:()=>{r(),c?.()},children:"Reset"})]})]})}function Et(){return document.documentElement.clientWidth||window.innerWidth}function Vl(){return document.documentElement.clientHeight||window.innerHeight}function Of({isOpen:e,containerRef:t,panelRef:n,columns:o,columnVisibilityModel:r,disableColumnReorder:i,onClose:l,onColumnVisibilityChange:c,onColumnMove:a,onColumnOrderReset:u,columnGroupingModel:g}){const[p,x]=s.useState(null);if(s.useLayoutEffect(()=>{if(!e||!t.current)return;const h=t.current.getBoundingClientRect();x({top:h.top+8,right:Et()-h.right+8,target:t.current.closest(".ogx-theme-provider")||document.body})},[e,t]),!e||!p)return null;const y=i?void 0:(h,f)=>{Ro(g,h,f)&&a(h,f)};return st.createPortal(d.jsxs("div",{ref:n,style:{position:"fixed",top:p.top,right:p.right,zIndex:9999,display:"inline-block"},children:[d.jsx("button",{type:"button",onClick:l,style:{position:"absolute",top:-12,right:-12,width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",background:"#334155",color:"#fff",border:"none",borderRadius:"50%",cursor:"pointer",fontSize:14,lineHeight:1,zIndex:1,boxShadow:"0 1px 4px rgba(0,0,0,0.2)"},"aria-label":"Close",children:"×"}),d.jsx(nr,{columns:o,visibleColumns:new Set(o.filter(h=>r[h.field]!==!1).map(h=>h.field)),onVisibilityChange:(h,f)=>{c({...r,[h]:f})},onShowAll:()=>{const h={...r};o.forEach(f=>{f.hideable!==!1&&(h[f.field]=!0)}),c(h)},onHideAll:()=>{const h={...r};o.forEach(f=>{f.hideable!==!1&&(h[f.field]=!1)}),c(h)},onColumnReorder:y,onColumnOrderReset:i?void 0:u})]}),p.target)}function or(e){const t=s.useId(),{page:n,pageSize:o,rowCount:r,onPageChange:i,onPageSizeChange:l,pageSizeOptions:c=[10,25,50,100],showFirstButton:a=!0,showLastButton:u=!0,localeText:g}=e,p=Bn(o),x=$o(r,p),y=Gi(n,x),h=c.includes(p)?c:[...c,p].sort((k,N)=>k-N),f=y*p,w=Math.min(f+p,r),b=r===0?0:`${f+1}–${w}`,m=g?.paginationRowsPerPage??"Rows per page:",C=g?.paginationOf?g.paginationOf(r===0?0:f+1,w,r):`${b} of ${r}`,E=g?.paginationPage?g.paginationPage(y+1,x):`Page ${y+1} of ${x}`,_=()=>{i(0)},I=()=>{i(Math.max(0,y-1))},M=()=>{i(Math.min(x-1,y+1))},S=()=>{i(x-1)},F=k=>{const N=parseInt(k.target.value,10);l(N)},P=y===0,L=y>=x-1;return d.jsxs("div",{className:"ogx-pagination",role:"navigation","aria-label":"Pagination",children:[d.jsxs("div",{className:"ogx-pagination__page-size",children:[d.jsx("label",{htmlFor:t,className:"ogx-pagination__label",children:m}),d.jsx("select",{id:t,className:"ogx-pagination__select",value:p,onChange:F,children:h.map(k=>d.jsx("option",{value:k,children:k},k))})]}),d.jsx("div",{className:"ogx-pagination__info","aria-live":"polite","aria-atomic":"true",children:C}),d.jsxs("div",{className:"ogx-pagination__actions",children:[a&&d.jsx(Qe,{variant:"text",size:"small",onClick:_,disabled:P,"aria-label":"Go to first page",title:"First page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z"})})}),d.jsx(Qe,{variant:"text",size:"small",onClick:I,disabled:P,"aria-label":"Go to previous page",title:"Previous page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"})})}),d.jsx("div",{className:"ogx-pagination__page-info","aria-current":"page",children:E}),d.jsx(Qe,{variant:"text",size:"small",onClick:M,disabled:L,"aria-label":"Go to next page",title:"Next page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),u&&d.jsx(Qe,{variant:"text",size:"small",onClick:S,disabled:L,"aria-label":"Go to last page",title:"Last page",children:d.jsx("svg",{className:"ogx-pagination__icon",width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:d.jsx("path",{d:"M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z"})})})]})]})}function Df({row:e,rowId:t,rowIndex:n,ariaRowIndex:o,listViewColumn:r,gridColumn:i,rowMeta:l,isSelected:c=!1,checkboxSelection:a=!1,rowHeight:u,onRowClick:g,onRowDoubleClick:p,onSelectionChange:x,tabIndex:y=-1,onFocus:h,onToggleExpansion:f}){const w=t??e.id,b=r.field,m=Ee(e,b,i),C=po(e,b,m,i)??En(m,i),E=l?.isGroupRow===!0||Re(w),_={row:e,value:m,formattedValue:C,field:b,colDef:i??r,rowIndex:n,colIndex:0,rowMeta:l},I=M=>{M.stopPropagation(),x?.(w,M.target.checked)};return d.jsxs("div",{className:`ogx-list-view__row${c?" ogx-list-view__row--selected":""}`,style:u?{minHeight:u}:void 0,onClick:()=>g?.(e),onDoubleClick:p?()=>p(e):void 0,role:"row","aria-rowindex":o??n+1,"aria-selected":c,"aria-level":l?.treeDepth!==void 0?l.treeDepth+1:void 0,"aria-expanded":l?.hasChildren?l.isExpanded===!0:void 0,"data-rowindex":n,tabIndex:y,onFocus:h?M=>{M.target===M.currentTarget&&h(n)}:void 0,children:[a&&d.jsx("div",{className:"ogx-list-view__checkbox",onClick:M=>M.stopPropagation(),children:!E&&d.jsx(ft,{checked:c,onChange:I,"aria-label":`Select row ${w}`,tabIndex:-1})}),l&&f&&d.jsx("div",{className:"ogx-list-view__expand",style:{paddingInlineStart:(l.treeDepth??0)*16},onClick:M=>M.stopPropagation(),onDoubleClick:M=>M.stopPropagation(),children:l.hasChildren&&d.jsx(Wo,{isExpanded:l.isExpanded===!0,onClick:()=>f(w),tabIndex:-1})}),d.jsx("div",{className:"ogx-list-view__cell",role:"gridcell",children:d.jsx(_t,{field:b,resetKey:e,renderFn:()=>{const M=r.renderCell(_);return M===void 0&&E?l?.groupLabel:M}})})]})}function $f(e,t){const n=s.useRef(!0),o=s.useRef(e);s.useEffect(()=>{o.current=e},[e]),s.useEffect(()=>{n.current=!0},[t]);const r=s.useCallback(i=>{const l=bl(i.currentTarget);if(!l){n.current=!0;return}if(!n.current)return;const c=o.current;c&&(n.current=!1,c(l))},[]);return e?r:void 0}const Gf=e=>e.id;function Hf({ariaLabel:e,allRenderableRows:t,dataRowCount:n,pinnedTopRowCount:o,pinnedBottomRowCount:r,unpinnedRowCount:i,pagination:l,effectivePaginationModel:c,currentPage:a,pageSizeOptions:u,selectedRowIds:g,listViewColumn:p,columnsByField:x,rowMetaMap:y,noRowsLabel:h,rowHeight:f,checkboxSelection:w,paginationMode:b,serverRowCount:m,paginationSlot:C,paginationSlotProps:E,localeText:_,onRowClick:I,onRowDoubleClick:M,onSelectionChange:S,onPaginationModelChange:F,onRowsScrollEnd:P,getRowId:L=Gf,multiselectable:k=!1,loading:N=!1,loadingOverlay:T,noRowsOverlay:v,showPaginationControls:W=!0,selectable:B=!1,onToggleExpansion:Q}){const $=C||or,z=s.useRef(null),[V,ie]=s.useState(null),te=V===null?-1:t.findIndex(O=>L(O)===V),ce=te===-1?0:te,oe=O=>{const A=t[O];A&&(ie(L(A)),z.current?.querySelector(`:scope > [role="row"][data-rowindex="${O}"]`)?.focus())},de=O=>{const A=O.target;if(A.getAttribute("role")!=="row"||A.parentElement!==z.current)return;const G=Number(A.getAttribute("data-rowindex")),D=t[G];if(!D)return;const U=L(D),q=t.length-1,ee=y.get(U),Z=!!(ee?.hasChildren&&Q);if(O.altKey&&(O.key==="ArrowRight"||O.key==="ArrowLeft")){O.preventDefault();const j=Mn(O.key,Xe(O.currentTarget))==="ArrowRight";Z&&j!==(ee?.isExpanded===!0)&&Q?.(U);return}switch(O.key){case"ArrowDown":O.preventDefault(),oe(Math.min(G+1,q));return;case"ArrowUp":O.preventDefault(),oe(Math.max(G-1,0));return;case"Home":O.preventDefault(),oe(0);return;case"End":O.preventDefault(),oe(q);return;case"PageDown":O.preventDefault(),oe(Math.min(G+10,q));return;case"PageUp":O.preventDefault(),oe(Math.max(G-10,0));return;case"Enter":case" ":if(O.preventDefault(),O.key===" "&&O.shiftKey){B&&!ee?.isGroupRow&&S(U,!g.has(U));return}Z?Q?.(U):I({row:D,id:U,rowIndex:G});return}},X=b==="server",ne=X?m||0:i,se=X?m||0:n,Y=Bn(c.pageSize),H=$o(ne,Y),R=l?a*Y:0,ae=t.length-o-r,ge=O=>{if(O<o)return O+1;const A=O-o;return A<ae?o+R+A+1:o+ne+(A-ae)+1},J=$f(P,t.length);return d.jsxs("div",{className:"ogx-list-view",role:"grid","aria-label":e||"Data grid list view","aria-rowcount":se,"aria-multiselectable":k,children:[d.jsx("div",{className:"ogx-list-view__toolbar",children:d.jsxs("span",{children:[se," ",se===1?"item":"items",l?` · page ${a+1} of ${H}`:"",g.size>0?` · ${g.size} selected`:""]})}),d.jsx("div",{className:"ogx-list-view__rows",tabIndex:-1,onScroll:J,onKeyDown:de,ref:z,children:t.length===0&&N?d.jsx("div",{className:"ogx-list-view__loading",children:T??d.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})}):t.length===0&&v?d.jsx("div",{className:"ogx-list-view__empty",children:v}):t.length===0?d.jsxs("div",{className:"ogx-list-view__empty",children:[d.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[d.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),d.jsx("path",{d:"M3 9h18M9 21V9"})]}),h]}):t.map((O,A)=>{const G=L(O);return d.jsx(Df,{row:O,rowId:G,rowIndex:A,ariaRowIndex:ge(A),listViewColumn:p,gridColumn:x.get(p.field),rowMeta:y.get(G),isSelected:g.has(G),checkboxSelection:w,rowHeight:f,onRowClick:D=>I({row:D,id:G,rowIndex:A}),onRowDoubleClick:M?D=>M({row:D,id:G,rowIndex:A}):void 0,onSelectionChange:S,tabIndex:A===ce?0:-1,onToggleExpansion:Q,onFocus:D=>ie(L(t[D]))},G)})}),l&&W&&d.jsx($,{page:a,pageSize:c.pageSize,rowCount:ne,pageSizeOptions:u,onPageChange:O=>F({...c,page:O}),onPageSizeChange:O=>F({...c,pageSize:O,page:0}),localeText:_,...E})]})}const Bf=16;function Wf(e){e.preventDefault(),e.stopPropagation()}function Vf(){const e=t=>{t.stopPropagation(),t.preventDefault()};window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}),0)}function zf(e){const{field:t,currentWidth:n,onResize:o,onAutosize:r,minWidth:i,maxWidth:l,edge:c="end"}=e,[a,u]=s.useState(!1),g=s.useRef(null);s.useEffect(()=>()=>{g.current=null},[]);const p=s.useCallback((m,C)=>{const E=(C-m.startX)*(m.rtl?-1:1),_=m.startWidth+(c==="start"?-E:E);return er(_,m.startWidth,i,l)},[c,i,l]),x=s.useCallback(m=>{if(m.button===0){m.stopPropagation(),g.current={pointerId:m.pointerId,startX:m.clientX,startWidth:n,rtl:Xe(m.currentTarget),lastUpdate:0,moved:!1},u(!0);try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}}},[n]),y=s.useCallback(m=>{const C=g.current;if(!C||m.pointerId!==C.pointerId||(m.clientX!==C.startX&&(C.moved=!0),!C.moved))return;const E=Date.now();E-C.lastUpdate>=Bf&&(C.lastUpdate=E,o(t,p(C,m.clientX)))},[t,o,p]),h=s.useCallback((m,C)=>{const E=g.current;if(!(!E||m.pointerId!==E.pointerId)){if(g.current=null,u(!1),m.currentTarget.hasPointerCapture?.(m.pointerId))try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}(E.moved||m.clientX!==E.startX)&&(Vf(),C&&o(t,p(E,m.clientX)))}},[t,o,p]),f=s.useCallback(m=>{if(m.key==="Enter"&&r){m.preventDefault(),m.stopPropagation(),r(t);return}if(m.key!=="ArrowLeft"&&m.key!=="ArrowRight")return;m.preventDefault(),m.stopPropagation();const C=Mn(m.key,Xe(m.currentTarget)),E=(m.shiftKey?50:10)*(C==="ArrowRight"?1:-1);o(t,er(n+E,n,i,l))},[t,n,o,r,i,l]),w=s.useCallback(m=>{m.preventDefault(),m.stopPropagation(),r?.(t)},[t,r]),b=["ogx-column-resize-handle",c==="start"&&"ogx-column-resize-handle--start",a&&"ogx-column-resize-handle--dragging"].filter(Boolean).join(" ");return d.jsx("div",{className:b,onPointerDown:x,onMouseDown:Wf,onPointerMove:y,onPointerUp:m=>h(m,!0),onPointerCancel:m=>h(m,!1),onClick:m=>m.stopPropagation(),onDragStart:m=>{m.preventDefault(),m.stopPropagation()},onDoubleClick:w,onKeyDown:f,role:"separator","aria-orientation":"vertical","aria-label":`Resize ${t} column`,"aria-valuenow":Math.round(n),"aria-valuemin":Math.round(Math.min(i??50,n)),"aria-valuemax":l,tabIndex:-1,children:d.jsx("div",{className:"ogx-column-resize-handle__line"})})}function Rt(){return d.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"currentColor",children:d.jsx("circle",{cx:"4",cy:"4",r:"4"})})}function Ut(){return d.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:d.jsx("circle",{cx:"4",cy:"4",r:"3"})})}function Kf(){return d.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",children:[d.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.3"}),d.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),d.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function Rf(){return d.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),d.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function Uf(){return d.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),d.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function jf(){return d.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:d.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}function qf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.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"}),d.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"}),d.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function Xf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"4",y1:"2",x2:"4",y2:"22"}),d.jsx("polyline",{points:"11 8 4 12 11 16"}),d.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}function Yf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"20",y1:"2",x2:"20",y2:"22"}),d.jsx("polyline",{points:"13 8 20 12 13 16"}),d.jsx("line",{x1:"20",y1:"12",x2:"4",y2:"12"})]})}function Jf(){return d.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"}),d.jsx("line",{x1:"4",y1:"4",x2:"4",y2:"20"}),d.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"})]})}const zl=e=>e?Array.from(e.querySelectorAll('[role="menuitem"], [role="menuitemradio"]')):[];function Zf({colDef:e,sortModel:t,onSort:n,onHide:o,onPin:r,pinnedColumns:i,onManageColumns:l,onClose:c,anchorEl:a}){const u=s.useRef(null),g=s.useCallback(v=>{v&&(a?.closest('[role="columnheader"]')??a)?.focus({preventScroll:!0}),c()},[a,c]),p=v=>{const W=zl(u.current),B=W.indexOf(v.target);let Q=-1;if(v.key==="ArrowDown")Q=B+1>=W.length?0:B+1;else if(v.key==="ArrowUp")Q=B<=0?W.length-1:B-1;else if(v.key==="Home")Q=0;else if(v.key==="End")Q=W.length-1;else if(v.key==="Tab"){v.preventDefault(),g(!0);return}else return;v.preventDefault(),W[Q]?.focus()},[x,y]=s.useState({position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"});s.useLayoutEffect(()=>{if(!a||!u.current)return;const v=a.getBoundingClientRect(),W=u.current.getBoundingClientRect(),B=Et(),Q=Vl(),$=8;let z=v.left;z+W.width+$>B&&(z=B-W.width-$),z<$&&(z=$);let V=v.bottom+4;V+W.height+$>Q&&(V=v.top-W.height-4),y({position:"fixed",zIndex:1300,top:V,left:z,visibility:"visible"})},[a]);const h=x.visibility==="visible";s.useLayoutEffect(()=>{h&&zl(u.current)[0]?.focus({preventScroll:!0})},[h]),s.useEffect(()=>{function v(B){u.current&&!u.current.contains(B.target)&&a&&!a.contains(B.target)&&c()}function W(B){B.key==="Escape"&&g(!0)}return document.addEventListener("mousedown",v),document.addEventListener("keydown",W),window.addEventListener("scroll",c,!0),window.addEventListener("resize",c),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",W),window.removeEventListener("scroll",c,!0),window.removeEventListener("resize",c)}},[a,c,g]);const f=v=>{n?.(e.field,v),g(!0)},w=!!o&&e.hideable!==!1,b=!!r&&e.pinnable!==!1,m=()=>{w&&o?.(e.field),g(!0)},C=v=>{b&&r?.(e.field,v),g(!0)},E=t?.find(v=>v.field===e.field)?.sort,_=E==null,I=i?.left?.includes(e.field)??!1,M=i?.right?.includes(e.field)??!1,S=!I&&!M,F=Xe(a),P=F?"right":"left",L=F?"left":"right",k=F?M:I,N=F?I:M,T=e.headerName||e.field;return st.createPortal(d.jsxs("div",{ref:u,className:"ogx-column-menu",style:x,role:"menu","aria-label":`Column options for ${T}`,onKeyDown:p,children:[n&&e.sortable!==!1&&d.jsxs(d.Fragment,{children:[d.jsxs("button",{type:"button",className:`ogx-menu-item${E==="asc"?" ogx-menu-item--active":""}`,onClick:()=>f("asc"),role:"menuitemradio","aria-checked":E==="asc",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="asc"?d.jsx(Rt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Rf,{})}),"Sort Ascending"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${E==="desc"?" ogx-menu-item--active":""}`,onClick:()=>f("desc"),role:"menuitemradio","aria-checked":E==="desc",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:E==="desc"?d.jsx(Rt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Uf,{})}),"Sort Descending"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${_?" ogx-menu-item--active":""}`,onClick:()=>f(null),role:"menuitemradio","aria-checked":_,children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:_?d.jsx(Rt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(jf,{})}),"Unsort"]}),d.jsx("div",{className:"ogx-menu-divider"})]}),b&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"ogx-menu-section-label","aria-hidden":"true",children:"Pin column"}),d.jsxs("button",{type:"button",className:`ogx-menu-item${k?" ogx-menu-item--active":""}`,onClick:()=>C(P),role:"menuitemradio","aria-checked":k,"aria-label":"Pin to left",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:k?d.jsx(Rt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Xf,{})}),"Pin to Left"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${N?" ogx-menu-item--active":""}`,onClick:()=>C(L),role:"menuitemradio","aria-checked":N,"aria-label":"Pin to right",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:N?d.jsx(Rt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Yf,{})}),"Pin to Right"]}),d.jsxs("button",{type:"button",className:`ogx-menu-item${S?" ogx-menu-item--active":""}`,onClick:()=>C(null),role:"menuitemradio","aria-checked":S,"aria-label":"Unpin column",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true",children:S?d.jsx(Rt,{}):d.jsx(Ut,{})}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Jf,{})}),"Unpin"]}),d.jsx("div",{className:"ogx-menu-divider"})]}),w&&d.jsxs(d.Fragment,{children:[d.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:m,role:"menuitem","aria-label":`Hide ${T} column`,children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(qf,{})}),"Hide Column"]}),d.jsx("div",{className:"ogx-menu-divider"})]}),d.jsxs("button",{type:"button",className:"ogx-menu-item",onClick:()=>{l?.(),g(!1)},role:"menuitem","aria-label":"Manage all columns",children:[d.jsx("span",{className:"ogx-menu-item__indicator","aria-hidden":"true"}),d.jsx("span",{className:"ogx-menu-item__icon","aria-hidden":"true",children:d.jsx(Kf,{})}),"Manage columns"]})]}),a?.closest(".ogx-theme-provider")||document.body)}const Qf=16,eg=16;function tg(e,t=!1){const n=Number.isFinite(e)?e-eg:0,o=Math.floor(n/Qf)-(t?1:0);return Math.max(1,o)}function ng(e,t){return e??t??!1}function Kl(e,t,n,o){const r={width:t[e.field]??e.width??100,minWidth:e.minWidth,maxWidth:e.maxWidth,flexGrow:e.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",position:n?"sticky":"relative"};return n==="left"?r.insetInlineStart=o:n==="right"&&(r.insetInlineEnd=o),r}const og="header:",rg=40,ig=300,lg="__group__",Rl=[];function rr(e){return`${og}${e}`}function ir(e){return"items"in e&&Array.isArray(e.items)}function sg(e){return e.isSpacer||Je(e.field)||e.field===lg?!1:e.headerFilter!==!1&&e.filterable!==!1&&e.type!=="image"}function Un(e){if(e.headerFilterOperator)return e.headerFilterOperator;switch(e.type){case"number":return"=";case"date":case"boolean":case"singleSelect":return"is";default:return"contains"}}function ag(e){const t=ii(e.type),n=Un(e);return t.includes(n)?t:[n,...t]}function Ul(e,t){return e.items.some(n=>ir(n)?Ul(n,t):n.field===t)}function cg(e){return(e?.logicOperator??"and")==="or"&&(e?.items?.length??0)>0}function jl(e,t){const n=e?.items??Rl;if(cg(e))return{kind:"custom"};const o=rr(t);let r;for(const i of n){if(ir(i)){if(Ul(i,t))return{kind:"custom"};continue}if(i.field===t){if(i.id!==o||r)return{kind:"custom"};r=i}}return{kind:"editable",item:r}}function dg(e,t,n){const o=e??{items:[]};if(jl(o,t).kind!=="editable")return o;const r=rr(t),i=o.items??Rl,l=i.findIndex(u=>!ir(u)&&u.id===r),c=n?{...n,id:r,field:t}:null;let a;if(l===-1){if(!c)return o;if(i.length===0&&o.logicOperator==="or")return{...o,logicOperator:"and",items:[c]};a=[...i,c]}else c?a=i.map((u,g)=>g===l?c:u):a=i.filter((u,g)=>g!==l);return{...o,items:a}}function lr(e,t,n){const o=Dt.has(t);return!o&&Co(n)&&t===Un(e)?null:{id:rr(e.field),field:e.field,operator:t,value:o?void 0:n}}function ql(e,t){if(!Dt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const ug={contains:"∋",equals:"=",startsWith:"a…",endsWith:"…a",isEmpty:"∅",isNotEmpty:"!∅",isAnyOf:"∈","=":"=","!=":"≠",">":">",">=":"≥","<":"<","<=":"≤",is:"=",not:"≠",after:">",onOrAfter:"≥",before:"<",onOrBefore:"≤"},fg={contains:"Contains",equals:"Equals",startsWith:"Starts with",endsWith:"Ends with",isEmpty:"Is empty",isNotEmpty:"Is not empty",isAnyOf:"Is any of","=":"Equals","!=":"Does not equal",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",is:"Is",not:"Is not",after:"After",onOrAfter:"On or after",before:"Before",onOrBefore:"On or before"};function gg(e){const t=e?.headerFilterOperators;return{custom:e?.headerFilterCustom??"Custom filter",customTooltip:e?.headerFilterCustomTooltip??"Set in the filter panel",cellLabel:e?.headerFilterCellLabel??(n=>`Filter ${n}`),valueLabel:e?.headerFilterValueLabel??(n=>`Filter value for ${n}`),operatorButtonLabel:e?.headerFilterOperatorButtonLabel??((n,o)=>`Filter operator for ${n}: ${o}`),operatorMenuLabel:e?.headerFilterOperatorMenuLabel??(n=>`Filter operator for ${n}`),clearLabel:e?.headerFilterClearLabel??(n=>`Clear filter for ${n}`),clearTooltip:e?.headerFilterClearTooltip??"Clear",any:e?.headerFilterAny??"Any",yes:e?.headerFilterTrue??"Yes",no:e?.headerFilterFalse??"No",operator:n=>t?.[n]??fg[n]??n}}function Xl(e){return(e.valueOptions??[]).map((t,n)=>t!==null&&typeof t=="object"?{key:String(n),value:t.value,label:t.label}:{key:String(n),value:t,label:String(t)})}function sr(e,t){const n=Array.isArray(t)?t[0]:t;return Object.is(e.value,n)?!0:n!=null&&String(e.value).toLowerCase()===String(n).toLowerCase()}function jn(e,t){return t==="isAnyOf"?e.split(",").map(n=>n.trim()).filter(n=>n!==""):e}function ar(e,t){return Object.is(e,t)?!0:e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>ar(n,t[o])):!1}const pg={position:"fixed",zIndex:1300,top:0,left:0,visibility:"hidden"},Yl=e=>e?Array.from(e.querySelectorAll('[role="menuitemradio"]')):[];function hg({anchorEl:e,columnLabel:t,operators:n,current:o,onSelect:r,onClose:i,locale:l}){const c=s.useRef(null),[a,u]=s.useState(pg);s.useLayoutEffect(()=>{const y=c.current;if(!y)return;const h=e.getBoundingClientRect(),f=y.getBoundingClientRect(),w=8;let b=Math.min(h.left,Et()-f.width-w);b<w&&(b=w);let m=h.bottom+4;m+f.height+w>Vl()&&(m=h.top-f.height-4),u({position:"fixed",zIndex:1300,top:m,left:b,visibility:"visible"})},[e]);const g=a.visibility==="visible";s.useLayoutEffect(()=>{if(!g)return;const y=Yl(c.current);(y.find(h=>h.getAttribute("aria-checked")==="true")??y[0])?.focus({preventScroll:!0})},[g]);const p=s.useRef(i);s.useLayoutEffect(()=>{p.current=i}),s.useEffect(()=>{const y=e.ownerDocument,h=y.defaultView;function f(m){const C=m.target;c.current?.contains(C)||e.contains(C)||p.current(!1)}function w(m){c.current?.contains(m.target)||p.current(!1)}function b(){p.current(!1)}return y.addEventListener("mousedown",f),h?.addEventListener("scroll",w,!0),h?.addEventListener("resize",b),()=>{y.removeEventListener("mousedown",f),h?.removeEventListener("scroll",w,!0),h?.removeEventListener("resize",b)}},[e]);const x=y=>{y.stopPropagation();const h=Yl(c.current),f=h.indexOf(y.target);let w=-1;switch(y.key){case"ArrowDown":w=f+1>=h.length?0:f+1;break;case"ArrowUp":w=f<=0?h.length-1:f-1;break;case"Home":w=0;break;case"End":w=h.length-1;break;case"Escape":case"Tab":y.preventDefault(),i(!0);return;default:return}y.preventDefault(),h[w]?.focus()};return st.createPortal(d.jsx("div",{ref:c,className:"ogx-column-menu ogx__header-filter-menu",style:a,role:"menu","aria-label":l.operatorMenuLabel(t),onKeyDown:x,children:n.map(y=>d.jsx("button",{type:"button",role:"menuitemradio","aria-checked":y===o,tabIndex:-1,className:`ogx-menu-item${y===o?" ogx-menu-item--active":""}`,onClick:()=>r(y),children:l.operator(y)},y))}),e.closest(".ogx-theme-provider")??e.ownerDocument.body)}function Jl(e,t){return e===t?!0:!e||!t?!1:e.operator===t.operator&&ar(e.value,t.value)}function mg(){return d.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[d.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"}),d.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"})]})}function wg({colDef:e,state:t,style:n,className:o,ariaColIndex:r,onItemChange:i,onOpenFilterPanel:l,locale:c}){const a=e.headerName||e.field,u=t.kind==="editable"?t.item:void 0,g=u?.operator??Un(e),p=Xl(e),x=e.type==="boolean"||e.type==="singleSelect"&&p.length>0,y=!Dt.has(g),[h,f]=s.useState(null),[w,b]=s.useState(null),[m,C]=s.useState(void 0),[E,_]=s.useState(u);if(E!==u){_(u);const X=m!==void 0&&Jl(m??void 0,u);!Jl(E,u)&&!X&&f(null)}const I=s.useRef(null),M=s.useRef(null),S=s.useRef(null),F=s.useRef(null),P=s.useRef(null),L=s.useRef({item:u,colDef:e,onItemChange:i});s.useLayoutEffect(()=>{L.current={item:u,colDef:e,onItemChange:i}});const k=s.useCallback(X=>{const{item:ne,colDef:se,onItemChange:Y}=L.current;if(ne?X===Eo(ne.value,se.type):X.trim()==="")return;const R=ne?.operator??Un(se),ae=lr(se,R,jn(X,R));C(ae),Y(se.field,ae)},[]),N=s.useRef(null);s.useLayoutEffect(()=>{N.current=h}),s.useEffect(()=>()=>{const X=N.current;N.current=null,X!==null&&k(X)},[k]),s.useEffect(()=>{if(h===null)return;const X=setTimeout(()=>{N.current=null,k(h),f(null)},ig);return()=>clearTimeout(X)},[h,k]);const T=()=>I.current?.focus({preventScroll:!0}),v=()=>(M.current??S.current)?.focus({preventScroll:!0}),W=X=>{C(X),i(e.field,X)},B=X=>{f(null),W(lr(e,g,X))},Q=()=>{f(null),W(null)},$=()=>{P.current&&b(P.current)},z=X=>{b(null),X&&(M.current||S.current?v():T())},V=X=>{const ne=h!==null?jn(h,X):u?.value;f(null),b(null),W(lr(e,X,ql(ne,X))),requestAnimationFrame(()=>{M.current||S.current?v():T()})},ie=t.kind==="custom",te=!ie&&y&&!x,ce=X=>{const ne=X.currentTarget,se=X.target;if(!ne.contains(se)||X.nativeEvent.isComposing)return;const{key:Y}=X,H=se===ne;if((X.altKey&&Y==="ArrowDown"||(X.ctrlKey||X.metaKey)&&Y==="Enter")&&!ie&&se!==S.current){X.preventDefault(),X.stopPropagation(),$();return}if(!H){Y==="Escape"&&(X.preventDefault(),X.stopPropagation(),T());return}if(Y==="Enter"||Y===" "||Y==="Spacebar"){X.preventDefault(),X.stopPropagation(),ie?F.current?.click():M.current||S.current?v():$();return}if((Y==="Delete"||Y==="Backspace")&&u){X.preventDefault(),X.stopPropagation(),Q();return}te&&e.type!=="date"&&Y.length===1&&!X.ctrlKey&&!X.metaKey&&!X.altKey&&(X.preventDefault(),X.stopPropagation(),M.current?.focus({preventScroll:!0}),f(Y))};let oe=null;if(ie)oe=l?d.jsx("button",{ref:F,type:"button",className:"ogx__header-filter-custom",tabIndex:-1,onClick:l,title:c.customTooltip,children:c.custom}):d.jsx("span",{className:"ogx__header-filter-custom",title:c.customTooltip,children:c.custom});else{let X;if(!y)X=d.jsx("span",{className:"ogx__header-filter-operator-label",children:c.operator(g)});else if(e.type==="boolean")X=d.jsxs("select",{ref:S,className:"ogx__header-filter-select",tabIndex:-1,value:u?.value==null||u.value===""?"":String(u.value),onChange:se=>B(se.target.value===""?"":se.target.value==="true"),"aria-label":c.valueLabel(a),children:[d.jsx("option",{value:"",children:c.any}),d.jsx("option",{value:"true",children:c.yes}),d.jsx("option",{value:"false",children:c.no})]});else if(x){const se=p.find(Y=>sr(Y,u?.value));X=d.jsxs("select",{ref:S,className:"ogx__header-filter-select",tabIndex:-1,value:se?.key??"",onChange:Y=>{const H=p.find(R=>R.key===Y.target.value);B(ql(H?H.value:"",g))},"aria-label":c.valueLabel(a),children:[d.jsx("option",{value:"",children:c.any}),p.map(Y=>d.jsx("option",{value:Y.key,children:Y.label},Y.key))]})}else X=d.jsx(et,{ref:M,className:"ogx__header-filter-input-wrapper",inputClassName:"ogx__header-filter-input",type:e.type==="date"?"date":"text",inputMode:e.type==="number"?"decimal":void 0,tabIndex:-1,autoComplete:"off",value:h??Eo(u?.value,e.type),onChange:se=>f(se.target.value),"aria-label":c.valueLabel(a)});const ne=c.operator(g);oe=d.jsxs(d.Fragment,{children:[d.jsx("button",{ref:P,type:"button",className:`ogx__header-filter-operator${w?" ogx__header-filter-operator--open":""}`,tabIndex:-1,"aria-haspopup":"menu","aria-expanded":w!==null,"aria-label":c.operatorButtonLabel(a,ne),title:ne,onClick:()=>w?b(null):$(),children:ug[g]??"?"}),X,u&&d.jsx("button",{type:"button",className:"ogx__header-filter-clear",tabIndex:-1,"aria-label":c.clearLabel(a),title:c.clearTooltip,onClick:()=>{Q(),T()},children:d.jsx(mg,{})}),w&&d.jsx(hg,{anchorEl:w,columnLabel:a,locale:c,operators:ag(e),current:g,onSelect:V,onClose:z})]})}const de=["ogx__header-filter-cell",u&&"ogx__header-filter-cell--active",ie&&"ogx__header-filter-cell--custom",o].filter(Boolean).join(" ");return d.jsx("div",{ref:I,className:de,style:n,role:"columnheader","aria-label":c.cellLabel(a),"aria-colindex":r,"data-field":e.field,tabIndex:-1,onKeyDown:ce,children:oe})}function cr({field:e,ariaColIndex:t,sticky:n,left:o,focused:r}){return d.jsx("div",{className:["ogx__header-filter-cell","ogx__header-filter-cell--system",n&&"ogx__header-filter-cell--pinned ogx__header-filter-cell--pinned-left",r&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" "),style:{width:He,minWidth:He,maxWidth:He,position:n?"sticky":void 0,insetInlineStart:n?o:void 0},role:"columnheader","aria-colindex":t,"data-field":e,tabIndex:-1})}function bg(e){const{columns:t,columnWidths:n,pinnedColumns:o,pinnedPositions:r,pinnedEdges:i,rowReordering:l,hasDetailPanel:c,checkboxSelection:a,pinExpandColumn:u,pinCheckboxColumn:g,columnIndexMap:p,ariaRowIndex:x,filterModel:y,onFilterModelChange:h,onOpenFilterPanel:f,focusedField:w,localeText:b}=e,m=s.useRef({filterModel:y,onFilterModelChange:h});s.useLayoutEffect(()=>{m.current={filterModel:y,onFilterModelChange:h}});const C=s.useCallback((L,k)=>{const{filterModel:N,onFilterModelChange:T}=m.current;if(!T)return;const v=dg(N,L,k);v!==N&&(m.current={filterModel:v,onFilterModelChange:T},T(v))},[]),E=gg(b),_=l?1:0,I=c?_+1:_,M=a?I+1:I,S=M,F=l?He:0,P=F+(c&&u?He:0);return d.jsxs("div",{className:"ogx__header-filter-row",role:"row","aria-rowindex":x,children:[l&&d.jsx(cr,{field:Ct,ariaColIndex:_,sticky:!0,left:0,focused:w===Ct}),c&&d.jsx(cr,{field:vt,ariaColIndex:I,sticky:u,left:F,focused:w===vt}),a&&d.jsx(cr,{field:Ye,ariaColIndex:M,sticky:g,left:P,focused:w===Ye}),t.map((L,k)=>{if(L.isSpacer)return d.jsx("div",{style:{width:L.width,minWidth:L.width,flexShrink:0},"aria-hidden":"true"},L.field);const N=tt(L.field,o),T=Kl(L,n,N,N?r[L.field]:void 0),v=S+(p?.get(L.field)??k)+1,W=[N&&"ogx__header-filter-cell--pinned",N&&`ogx__header-filter-cell--pinned-${N}`,N==="left"&&L.field===i.lastLeft&&"ogx__header-filter-cell--pinned-left-last",N==="right"&&L.field===i.firstRight&&"ogx__header-filter-cell--pinned-right-first",w===L.field&&"ogx__header-filter-cell--focused"].filter(Boolean).join(" ");return sg(L)?d.jsx(wg,{colDef:L,state:jl(y,L.field),style:T,className:W,ariaColIndex:v,onItemChange:C,onOpenFilterPanel:f,locale:E},L.field):d.jsx("div",{className:`ogx__header-filter-cell ogx__header-filter-cell--empty ${W}`,style:T,role:"columnheader","aria-label":`No filter for ${L.headerName||L.field}`,"aria-colindex":v,"data-field":L.field,tabIndex:-1},L.field)})]})}function xg(){return d.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",fill:"currentColor",width:"18",height:"18",children:d.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 yg(){return d.jsx("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"currentColor",children:d.jsx("path",{d:"M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z"})})}function Zl(e){const{columns:t,allColumns:n,columnGroupingModel:o,checkboxSelection:r=!1,allSelected:i=!1,someSelected:l=!1,onSelectAll:c,onSort:a,sortModel:u=[],onColumnResize:g,onColumnAutosize:p,columnWidths:x={},pinnedColumns:y,hasDetailPanel:h=!1,pinCheckboxColumn:f=!0,pinExpandColumn:w=!0,rowReordering:b=!1,aggregationModel:m,draggedColumn:C,dragOverColumn:E,onDragStart:_,onDragOver:I,onDragEnd:M,onDrop:S,focusedCell:F,onHeaderClick:P,onSortAdd:L,multiSort:k=!1,onHideColumn:N,onPinColumn:T,onManageColumns:v,columnIndexMap:W,wrapHeaderText:B=!1,headerHeight:Q=56,headerFilters:$=!1,filterModel:z,onFilterModelChange:V,onOpenFilterPanel:ie,localeText:te}=e,ce=s.useId(),[oe,de]=s.useState(null),X=K=>fe=>{fe.stopPropagation(),de({colDef:K,anchorEl:fe.currentTarget})},ne=s.useCallback(()=>{de(null)},[]),se=K=>fe=>{if(fe.altKey&&(fe.key==="ArrowLeft"||fe.key==="ArrowRight")&&fe.target===fe.currentTarget){if(K.resizable===!1||!g)return;fe.preventDefault(),fe.stopPropagation();const Ce=xt(K,x),ye=Mn(fe.key,Xe(fe.currentTarget)),ue=(fe.shiftKey?50:10)*(ye==="ArrowRight"?1:-1);g(K.field,er(Ce+ue,Ce,K.minWidth,K.maxWidth));return}if(!(fe.altKey&&fe.key==="ArrowDown"||(fe.ctrlKey||fe.metaKey)&&fe.key==="Enter")||K.disableColumnMenu||fe.target!==fe.currentTarget)return;fe.preventDefault(),fe.stopPropagation();const be=fe.currentTarget.querySelector(".ogx__menu-icon-btn")??fe.currentTarget;de({colDef:K,anchorEl:be})},Y=K=>F?.id===null&&!F.headerFilter&&F.field===K,H=b?1:0,R=h?H+1:H,ae=r?R+1:R,ge=K=>fe=>{if(K.sortable===!1)return;const we=u.find(be=>be.field===K.field);let le="asc";we&&(we.sort==="asc"?le="desc":le=null),(fe.shiftKey||k)&&L?L(K.field,le):a&&a(K.field,le)},J=(K,fe)=>{const we=u.some(be=>be.field===K);L&&(fe===null||we||k||!a)?L(K,fe):a?.(K,fe)},O=K=>{const fe=u.find(le=>le.field===K);if(!fe)return null;const we=u.length>1?u.indexOf(fe)+1:null;return d.jsx("span",{className:`ogx__sort-icon ogx__sort-icon--${fe.sort}`,"aria-hidden":"true",children:we!==null&&d.jsx("span",{className:"ogx__sort-badge",children:we})})},A=s.useMemo(()=>uo(t,x,y,r,f,h,w,b),[t,x,y,r,f,h,w,b]),G=s.useMemo(()=>fo(t,y),[t,y]),D=sl(o),U=s.useMemo(()=>al(o),[o]),q=s.useMemo(()=>D===0?[]:(n??t).map(K=>({field:K.field,width:xt(K,x),flex:K.isSpacer?0:K.flex,pinned:K.isSpacer?null:tt(K.field,y),isSpacer:K.isSpacer})),[D,n,t,x,y]),re=(b?48:0)+(h?48:0)+(r?48:0),me=(b||h||r)&&(!h||w)&&(!r||f),pe=(b?1:0)+(h?1:0)+(r?1:0);return d.jsxs("div",{className:"ogx__header-wrap",children:[D>0&&Array.from({length:D},(K,fe)=>{const we=Td(q,U,fe);return d.jsxs("div",{className:"ogx-col-group-row",role:"row","aria-rowindex":fe+1,children:[re>0&&d.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${me?" ogx-col-group-cell--pinned ogx-col-group-cell--pinned-left":""}`,style:{width:re,minWidth:re,flexShrink:0,position:me?"sticky":void 0,insetInlineStart:me?0:void 0},"aria-hidden":"true"}),we.map((le,be)=>{const Ce=le.pinned?` ogx-col-group-cell--pinned ogx-col-group-cell--pinned-${le.pinned}`:"",ye={width:le.width,minWidth:le.width,flexShrink:0,flexGrow:le.flexGrow};return le.pinned==="left"?(ye.position="sticky",ye.insetInlineStart=A[le.fields[0]]):le.pinned==="right"&&(ye.position="sticky",ye.insetInlineEnd=A[le.fields[le.fields.length-1]],we[be-1]?.pinned!=="right"&&(ye.marginInlineStart="auto")),le.isGroup?d.jsx("div",{role:"columnheader","aria-colspan":le.fields.length,"aria-colindex":pe+le.firstDataIndex+1,className:`ogx-col-group-cell ogx-col-group-cell--group${Ce}${le.headerClassName?` ${le.headerClassName}`:""}`,style:ye,title:le.label,children:d.jsx("span",{className:"ogx-col-group-cell__label",children:le.label})},le.key):d.jsx("div",{className:`ogx-col-group-cell ogx-col-group-cell--filler${Ce}`,style:ye,"aria-hidden":"true"},le.key)})]},`ogx-grp-${fe}`)}),d.jsxs("div",{className:"ogx__header",role:"row","aria-rowindex":D+1,children:[b&&d.jsx("div",{className:`ogx__header-cell ogx__header-cell--pinned ogx__header-cell--pinned-left ${Y("__reorder_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Row reorder handle","aria-colindex":H,"data-field":"__reorder_col__",tabIndex:-1,title:"Drag to reorder rows",style:{minWidth:48,maxWidth:48,position:"sticky",insetInlineStart:0}}),h&&d.jsx("div",{className:`ogx__header-cell ogx__header-cell--expand ${w?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${Y("__expand_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-label":"Expand row details","aria-colindex":R,"data-field":"__expand_col__",tabIndex:-1,style:{minWidth:48,maxWidth:48,position:w?"sticky":void 0,insetInlineStart:w?b?48:0:void 0}}),r&&d.jsx("div",{className:`ogx__header-cell ogx__header-cell--checkbox ${f?"ogx__header-cell--pinned ogx__header-cell--pinned-left":""} ${Y("__checkbox_col__")?"ogx__header-cell--focused":""}`,role:"columnheader","aria-colindex":ae,"data-field":"__checkbox_col__",style:{position:f?"sticky":void 0,insetInlineStart:f?(b?48:0)+(h&&w?48:0):void 0},children:c&&d.jsx(ft,{id:ce,name:ce,checked:i,indeterminate:l,onChange:K=>c(K.target.checked),"aria-label":i?"Deselect all rows":"Select all rows",tabIndex:-1,onMouseDown:K=>K.preventDefault()})}),t.map((K,fe)=>{if(K.isSpacer)return d.jsx("div",{style:{width:K.width,minWidth:K.width,flexShrink:0},"aria-hidden":"true"},K.field);const we=K.sortable!==!1,le=u.findIndex(Be=>Be.field===K.field),be=le!==-1,Ce=be?u[le].sort:null,ye=W?.get(K.field)??fe,ue=we?le===0?Ce==="asc"?"ascending":"descending":"none":void 0,ke=be&&u.length>1?`Sorted ${Ce==="asc"?"ascending":"descending"}, sort priority ${le+1} of ${u.length}`:void 0,Ae=K.resizable!==!1,Le=tt(K.field,y),Me=Le!==null,Ie=C===K.field,Pe=E===K.field,he=ng(K.wrapHeaderText,B),ve=m?.[K.field],_e=["ogx__header-cell",`ogx__header-cell--align-${K.headerAlign||K.align||"left"}`,we&&"ogx__header-cell--sortable",be&&"ogx__header-cell--sorted",Me&&"ogx__header-cell--pinned",Me&&`ogx__header-cell--pinned-${Le}`,Le==="left"&&K.field===G.lastLeft&&"ogx__header-cell--pinned-left-last",Le==="right"&&K.field===G.firstRight&&"ogx__header-cell--pinned-right-first",Ie&&"ogx__header-cell--dragging",Pe&&"ogx__header-cell--drag-over",he&&"ogx__header-cell--wrap",Y(K.field)&&"ogx__header-cell--focused",K.headerClassName].filter(Boolean).join(" "),xe={...Kl(K,x,Le,Le?A[K.field]:void 0),zIndex:K.zIndex,opacity:Ie?.5:1},Ne=K.renderHeader?K.renderHeader({field:K.field,colDef:K,colIndex:ye}):K.headerName||K.field,ze=Be=>{if(Be.target.closest(".ogx-column-resize-handle")){Be.stopPropagation();return}P?.(K.field),we&&ge(K)(Be)},je=_&&!Me?_(K.field):void 0,Mt=I&&!Me?I(K.field):void 0,It=S&&!Me?S(K.field):void 0;return d.jsxs("div",{className:_e,style:xe,title:K.description??(he&&typeof Ne=="string"?Ne:void 0),onClick:ze,role:"columnheader",draggable:!!je,onDragStart:je,onDragOver:Mt,onDragEnd:M,onDrop:It,onKeyDown:se(K),"aria-sort":ue,"aria-description":ke,"aria-colindex":pe+ye+1,"data-field":K.field,tabIndex:-1,children:[d.jsxs("div",{className:"ogx__header-cell-content",children:[Ie&&d.jsx("div",{className:"ogx__header-drag-icon",children:d.jsx(yg,{})}),d.jsxs("div",{className:"ogx__header-cell-title-wrapper",children:[d.jsx("span",{className:"ogx__header-cell-title",style:he?{WebkitLineClamp:tg(Q,!!ve)}:void 0,children:Ne}),ve&&d.jsx("span",{className:"ogx__header-cell-aggregation",children:ve})]}),we&&O(K.field),!K.disableColumnMenu&&d.jsx("button",{type:"button",className:"ogx__menu-icon-btn",onClick:X(K),"aria-label":`Open column menu for ${K.headerName||K.field}`,"aria-haspopup":"menu",tabIndex:-1,children:d.jsx(xg,{})})]}),Ae&&g&&d.jsx(zf,{field:K.field,currentWidth:xt(K,x),onResize:g,onAutosize:p,minWidth:K.minWidth,maxWidth:K.maxWidth,edge:Le==="right"?"start":"end"})]},K.field)}),oe&&d.jsx(Zf,{colDef:oe.colDef,sortModel:u,onSort:a||L?J:void 0,onHide:N,onPin:T,pinnedColumns:y,onManageColumns:v,onClose:ne,anchorEl:oe.anchorEl})]}),$&&d.jsx(bg,{columns:t,columnWidths:x,pinnedColumns:y,pinnedPositions:A,pinnedEdges:G,rowReordering:b,hasDetailPanel:h,checkboxSelection:r,pinExpandColumn:w,pinCheckboxColumn:f,columnIndexMap:W,ariaRowIndex:D+2,filterModel:z,onFilterModelChange:V,onOpenFilterPanel:ie,localeText:te,focusedField:F?.id===null&&F.headerFilter?F.field:null})]})}function fn(e){return e.headerName||e.field}function Cg(e){return e.nativeEvent.isComposing||e.keyCode===229}function gn(e,t,n=!0){return o=>{if(Cg(o)){o.stopPropagation();return}n&&o.key==="Enter"&&(o.stopPropagation(),e()),o.key==="Escape"&&(o.stopPropagation(),t())}}function vg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(String(e??"")),c=s.useRef(null);return s.useEffect(()=>{c.current?.focus(),c.current?.select()},[]),d.jsx(et,{ref:c,variant:"cell",type:"text",inputClassName:"ogx__edit-input","aria-label":fn(t),value:i,onChange:a=>{l(a.target.value),n(a.target.value)},onBlur:o,onKeyDown:gn(o,r)})}function Sg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i,l]=s.useState(typeof e=="number"?e:""),c=s.useRef(null);return s.useEffect(()=>{c.current?.focus(),c.current?.select()},[]),d.jsx(et,{ref:c,variant:"cell",type:"number",inputClassName:"ogx__edit-input ogx__edit-input--number","aria-label":fn(t),value:i,onChange:a=>{const u=a.target.value===""?"":Number(a.target.value);l(u),n(u===""?null:u)},onBlur:o,onKeyDown:gn(o,r)})}function _g({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=()=>{n(!e),o()};return d.jsx("div",{className:"ogx__edit-boolean",onMouseDown:c=>c.preventDefault(),children:d.jsx(ft,{ref:i,inputClassName:"ogx__edit-checkbox","aria-label":fn(t),checked:!!e,onChange:l,onMouseDown:c=>c.preventDefault(),onBlur:o,onKeyDown:gn(o,r,!1)})})}const dr=e=>typeof e=="object"?e.value:e,kg=e=>typeof e=="object"?e.label:String(e);function Eg(e,t){return e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():Object.is(e,t)}function Mg({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const i=s.useRef(null);s.useEffect(()=>{i.current?.focus()},[]);const l=t.valueOptions??[],c=l.map(g=>String(dr(g)));let a=l.findIndex(g=>Eg(dr(g),e));a===-1&&e!==null&&e!==void 0&&(a=c.indexOf(String(e)));const u=a===-1;return d.jsxs("select",{ref:i,className:"ogx__edit-select","aria-label":fn(t),value:u?"":c[a],onChange:g=>{const p=c.indexOf(g.target.value);n(p===-1?null:dr(l[p]))},onBlur:o,onKeyDown:gn(o,r),children:[u&&d.jsx("option",{value:""}),l.map((g,p)=>d.jsx("option",{value:c[p],children:kg(g)},p))]})}const Ql=e=>String(e).padStart(2,"0"),es=/^(\d{4}-\d{2}-\d{2})/;function ur(e){if(e instanceof Date)return Number.isNaN(e.getTime())?"":`${e.getFullYear()}-${Ql(e.getMonth()+1)}-${Ql(e.getDate())}`;if(typeof e=="string"){const t=es.exec(e);return t?t[1]:e===""?"":ur(new Date(e))}return typeof e=="number"?ur(new Date(e)):""}function Ig(e,t){if(e==="")return null;const[n,o,r]=e.split("-").map(Number),i=l=>{const c=new Date(l.getTime());return c.setFullYear(n,o-1,r),c};return t instanceof Date&&!Number.isNaN(t.getTime())?i(t):typeof t=="number"&&Number.isFinite(t)?i(new Date(t)).getTime():typeof t=="string"&&es.test(t)&&t.length>10?e+t.slice(10):e}function Ng({value:e,colDef:t,onValueChange:n,onCommit:o,onCancel:r}){const[i]=s.useState(e),[l,c]=s.useState(()=>ur(e)),a=s.useRef(null);return s.useEffect(()=>{a.current?.focus()},[]),d.jsx(et,{ref:a,variant:"cell",type:"date",inputClassName:"ogx__edit-input","aria-label":fn(t),value:l,onChange:u=>{c(u.target.value),n(Ig(u.target.value,i))},onBlur:o,onKeyDown:gn(o,r)})}function Lg(e){const{colDef:t}=e;switch(t.type){case"number":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(Sg,{...e})});case"boolean":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(_g,{...e})});case"singleSelect":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(Mg,{...e})});case"date":return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(Ng,{...e})});default:return d.jsx("div",{className:"ogx__edit-cell",children:d.jsx(vg,{...e})})}}function Pg(e){const{onCellClick:t,onCellEditStart:n,onCellValueChange:o,value:r,row:i,colDef:l,rowIndex:c,colIndex:a,ariaColIndex:u,isSelected:g,onClick:p,width:x,pinnedPosition:y,pinnedOffset:h,isPinnedEdge:f,isFocused:w,isFocusVisible:b,isEditable:m,isEditing:C,onEditStart:E,onEditStop:_,onValueChange:I,colSpanInfo:M,rowSpan:S,isHiddenByRowSpan:F,rowMeta:P,valueError:L,rangeFlags:k=0}=e,N=s.useCallback(J=>{o?o(l.field,J):I?.(J)},[o,I,l.field]),T=P?.isGroupRow===!0,{formattedValue:v,error:W}=s.useMemo(()=>{const J=l.valueFormatter;if(J&&!(T&&r==null)){const O=We(()=>J({value:r,row:i,field:l.field}));return O.ok?{formattedValue:O.value}:{formattedValue:"",error:O.error??new Error("valueFormatter failed")}}return{formattedValue:En(r,l)}},[r,i,l,T]),B=s.useMemo(()=>{if(!l.cellClassName)return"";const J=l.cellClassName;if(typeof J=="function"){const O=We(()=>J({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:c,colIndex:a,rowMeta:P}));return O.ok&&O.value||""}return l.cellClassName},[l,r,v,i,c,a,P]),Q=L??W,$=l.field,z=s.useCallback(()=>{_?.(!1,$)},[_,$]),V=s.useCallback(()=>{_?.(!0,$)},[_,$]),ie=s.useMemo(()=>[i,l.renderCell,r],[i,l.renderCell,r]),te=s.useRef(!1);if(s.useEffect(()=>{if(!(!C||!_))return te.current=!0,()=>{te.current=!1,queueMicrotask(()=>{te.current||_(!1,$)})}},[C,_,$]),M?.spannedByColSpan)return null;const ce=M?.cellProps.colSpan??1,oe=ce>1,de=(oe?M?.cellProps.width:void 0)??x??l.width??100,X={width:"var(--width)","--width":typeof de=="number"?`${de}px`:de,flexGrow:(oe?M?.cellProps.flexGrow:void 0)??l.flex??0,flexShrink:0,flexBasis:"auto",boxSizing:"border-box",minWidth:oe?void 0:l.minWidth,maxWidth:oe?void 0:l.maxWidth};if(F)return d.jsx("div",{className:"ogx__cell ogx__cell--hidden",style:X,role:"presentation","data-field":l.field,"data-colindex":a});const ne=J=>{C||(t&&t({row:i,field:l.field,value:r,colDef:l,rowIndex:c,colIndex:a}),p?.(J))},se=()=>{C||!m||(n?n(l.field,r):E?.())},Y=l.renderEditCell,H=y!=null,R=["ogx__cell",`ogx__cell--align-${l.align||"left"}`,g&&"ogx__cell--selected",w&&"ogx__cell--focused",w&&b&&"ogx__cell--focus-visible",l.type&&`ogx__cell--type-${l.type}`,H&&"ogx__cell--pinned",H&&`ogx__cell--pinned-${y}`,H&&f&&`ogx__cell--pinned-${y}-${y==="left"?"last":"first"}`,C&&"ogx__cell--editing",S&&S>1&&"ogx__cell--spanned",(k&Oo)!==0&&"ogx__cell--range",(k&Ni)!==0&&"ogx__cell--range-top",(k&Li)!==0&&"ogx__cell--range-bottom",(k&Pi)!==0&&"ogx__cell--range-left",(k&Ti)!==0&&"ogx__cell--range-right",B].filter(Boolean).join(" "),ae=S||1,ge={...X,position:H?"sticky":void 0,zIndex:l.zIndex??(H?3:void 0),padding:C?0:void 0};return ae>1&&(ge.height=`calc(var(--height) * ${ae} - var(--border-width, 1px))`,ge.zIndex=10,H&&(ge.zIndex=40)),H&&h!==void 0&&(y==="left"?ge.insetInlineStart=h:ge.insetInlineEnd=h),d.jsxs("div",{className:R,style:ge,onClick:ne,onDoubleClick:se,role:"gridcell","aria-colindex":u??a+1,"aria-readonly":!m||void 0,tabIndex:-1,"data-field":l.field,"data-colindex":a,...ce>1?{"aria-colspan":ce}:{},...ae>1?{"aria-rowspan":ae}:{},...(k&Oo)!==0?{"aria-selected":!0}:{},children:[d.jsx("div",{className:"ogx__cell-content",children:C&&(o||I)&&_?Y?d.jsx(_t,{field:l.field,resetKey:i,renderFn:()=>Y({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:c,colIndex:a,rowMeta:P,onValueChange:N,onCommit:z,onCancel:V})}):d.jsx(Lg,{value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:c,colIndex:a,rowMeta:P,onValueChange:N,onCommit:z,onCancel:V}):Q!==void 0?d.jsx(_t,{field:l.field,resetKey:i,renderFn:()=>{throw Q}}):l.renderCell?d.jsx(_t,{field:l.field,resetKey:ie,renderFn:()=>l.renderCell({value:r,formattedValue:v,row:i,field:l.field,colDef:l,rowIndex:c,colIndex:a,rowMeta:P})}):l.type==="image"&&typeof r=="string"&&r!==""?d.jsx("img",{className:"ogx__cell-image",src:r,alt:l.headerName??l.field,loading:"lazy"}):v}),(k&Ai)!==0&&!C&&d.jsx("div",{className:"ogx__cell-fill-handle","aria-hidden":"true"})]})}const ts=s.memo(Pg),Tg=({className:e="",...t})=>d.jsx("button",{type:"button",className:`ogx-drag-handle ${e}`,"aria-label":"Drag to reorder row",...t,children:d.jsx("svg",{viewBox:"0 0 24 24",width:"20",height:"20",fill:"currentColor","aria-hidden":"true",children:d.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 Ag(e){const{rowId:t,content:n,height:o,isExpanded:r,onHeightChange:i,id:l,colSpan:c}=e,a=s.useRef(null),u=o==="auto";if(s.useLayoutEffect(()=>{const p=a.current;if(!p||!u||!r||!i)return;const x=()=>{p.getClientRects().length!==0&&i(t,p.offsetHeight)};if(x(),typeof ResizeObserver>"u")return;const y=new ResizeObserver(x);return y.observe(p),()=>y.disconnect()},[u,r,i,t]),!r)return null;const g={height:u?"auto":`${o}px`,overflow:u?"visible":"auto"};return d.jsx("div",{ref:a,className:"ogx__detail-panel",style:g,role:"row",id:l,children:d.jsx("div",{className:"ogx__detail-panel-content",role:"gridcell","aria-colspan":c,children:n})})}const fr=12;function Fg(e,t,n,o){let r=0,i=0,l=0;for(let c=t;c<e.length&&l<n;c++){const a=e[c];if(a.isSpacer)break;r+=xt(a,o),i+=a.flex??0,l++}return{spannedByColSpan:!1,cellProps:{colSpan:l,width:r,flexGrow:i}}}function Og(e){const{row:t,skeleton:n=!1,rowId:o,columns:r,rowIndex:i,isSelected:l=!1,checkboxSelection:c=!1,onRowClick:a,onRowDoubleClick:u,onCellClick:g,onSelectionChange:p,columnWidths:x={},pinnedColumns:y,pinnedRows:h,hasDetailPanel:f=!1,isDetailPanelExpanded:w=!1,onDetailPanelToggle:b,detailPanelContent:m,detailPanelHeight:C=ho,onDetailPanelHeightChange:E,pinCheckboxColumn:_=!0,pinExpandColumn:I=!0,rowReordering:M=!1,onDragStart:S,onDragOver:F,onDragEnd:P,onDrop:L,isDragging:k,isDragOver:N,editingCell:T,onEditStart:v,onEditStop:W,onEditCellValueChange:B,isCellEditable:Q,focusedCellField:$,isFocusVisible:z,colspanMap:V,rowSpanningCaches:ie,rowHeight:te=52,rowMeta:ce,columnIndexMap:oe,ariaRowIndex:de,cellRange:X}=e,ne=o??t.id,se=s.useId(),Y=s.useId(),H=s.useMemo(()=>uo(r,x,y,c,_,f,I,M),[r,x,y,c,_,f,I,M]),R=s.useMemo(()=>fo(r,y),[r,y]),ae=ce?.hasChildren===!0,ge=ce?.isGroupRow===!0,J=f&&!ge,O=!ge&&!Re(ne),A=s.useCallback((ue,ke)=>{v?.({id:ne,field:ue,value:ke})},[ne,v]),G=s.useCallback((ue,ke)=>{B?.({id:ne,field:ue,value:ke})},[B,ne]),D=s.useCallback((ue,ke)=>{W?.({cancel:ue,id:ne,field:ke})},[W,ne]);if(n){const ue=Math.max(r.length,5);return d.jsx("div",{className:"ogx__row ogx__row--skeleton",role:"row","aria-hidden":"true",style:{height:te,minHeight:te},children:Array.from({length:ue}).map((ke,Ae)=>d.jsx("div",{className:"ogx__skeleton-cell",children:d.jsx("div",{className:"ogx__skeleton-bar"})},Ae))})}const U=ue=>{ue.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||a?.({row:t,id:ne,rowIndex:i})},q=ue=>{ue.target.closest(".ogx-checkbox-wrapper, .ogx-expand-icon, .ogx-drag-handle, .ogx__edit-cell, .ogx__cell--editing")||u?.({row:t,id:ne,rowIndex:i})},ee=ue=>{ue.stopPropagation(),p?.(ne,ue.target.checked)},Z=ue=>{ue.stopPropagation(),b?.(ne)},j=M?1:0,re=f?j+1:j,me=c?re+1:re,pe=me,K=oe?.size??r.filter(ue=>!ue.isSpacer).length,fe=ce!==void 0,we=ce?.hasChildren===!0,le=Vr(ne,h),be=le==="top",Ce=le==="bottom",ye=["ogx__row",l&&"ogx__row--selected",i%2===0&&"ogx__row--even",i%2===1&&"ogx__row--odd",be&&"ogx__row--pinned-top",Ce&&"ogx__row--pinned-bottom",k&&"ogx__row--dragging",N&&"ogx__row--drag-over",ae&&"ogx__row--group",ce?.isGroupFooter&&"ogx__row--group-footer"].filter(Boolean).join(" ");return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:ye,onClick:U,onDoubleClick:u?q:void 0,role:"row","aria-rowindex":de??i+2,"aria-selected":l,"aria-level":fe?(ce?.treeDepth??0)+1:void 0,"aria-expanded":we?ce?.isExpanded===!0:void 0,"data-rowindex":i,onDragOver:F?F(ne):void 0,onDrop:L?L(ne):void 0,style:{maxHeight:`${te}px`,minHeight:`${te}px`,"--height":`${te}px`,"--border-width":"1px"},children:[M&&d.jsx("div",{className:`ogx__cell ogx__cell--drag-handle ${$==="__reorder_col__"?"ogx__cell--focused":""} ${$==="__reorder_col__"&&z?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":S?"Drag to reorder row":void 0,"aria-colindex":j,"data-field":"__reorder_col__",tabIndex:-1,style:{position:"sticky",insetInlineStart:0,zIndex:fr},draggable:!!S,onDragStart:S?S(ne):void 0,onDragEnd:P,onClick:ue=>ue.stopPropagation(),children:S&&d.jsx(Tg,{})}),f&&d.jsx("div",{className:`ogx__cell ogx__cell--expand ${I?"ogx__cell--pinned-left":""} ${$==="__expand_col__"?"ogx__cell--focused":""} ${$==="__expand_col__"&&z?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-label":J?w?"Collapse row details":"Expand row details":void 0,"aria-expanded":J?w:void 0,"aria-controls":J&&w?Y:void 0,"aria-colindex":re,"data-field":"__expand_col__",style:{position:I?"sticky":void 0,insetInlineStart:I?M?48:0:void 0,zIndex:I?fr:void 0},tabIndex:-1,onClick:ue=>{ue.stopPropagation(),g?.({row:t,field:"__expand_col__",value:w,colDef:{field:"__expand_col__",width:48},rowIndex:i,colIndex:-1})},children:J&&d.jsx(Wo,{isExpanded:w,onClick:Z,variant:"plus-minus",tabIndex:-1})}),c&&d.jsx("div",{className:`ogx__cell ogx__cell--checkbox ${_?"ogx__cell--pinned-left":""} ${$==="__checkbox_col__"?"ogx__cell--focused":""} ${$==="__checkbox_col__"&&z?"ogx__cell--focus-visible":""}`,role:"gridcell","aria-colindex":me,"data-field":"__checkbox_col__",style:{position:_?"sticky":void 0,insetInlineStart:_?(M?48:0)+(f&&I?48:0):void 0,zIndex:_?fr:void 0},tabIndex:-1,onClick:ue=>{ue.stopPropagation(),g?.({row:t,field:"__checkbox_col__",value:l,colDef:{field:"__checkbox_col__",width:48},rowIndex:i,colIndex:-1})},children:O&&d.jsx(ft,{id:se,name:`ogx-select-row-${ne}`,checked:l,onChange:ee,onClick:ue=>ue.stopPropagation(),"aria-label":l?`Deselect row ${ne}`:`Select row ${ne}`,tabIndex:-1,onMouseDown:ue=>ue.preventDefault()})}),r.map((ue,ke)=>{if(ue.isSpacer)return d.jsx("div",{style:{width:ue.width,minWidth:ue.width,flexShrink:0},"aria-hidden":"true"},ue.field);let Ae,Le;ge?Ae=t[ue.field]:{value:Ae,error:Le}=Kr(t,ue.field,ue);const Me=oe?.get(ue.field)??ke,Ie=x[ue.field]??ue.width,Pe=tt(ue.field,y),he=!!v&&xo({row:t,field:ue.field,value:Ae,colDef:ue,rowIndex:i,colIndex:Me,rowMeta:ce},Q),ve=T?.id===ne&&T?.field===ue.field,_e=ve?T?.value:Ae,xe=V?.get(ne)?.[ue.field],Ne=xe&&!xe.spannedByColSpan&&xe.cellProps.colSpan>1?Fg(r,Me,xe.cellProps.colSpan,x):xe,ze=Ne&&!Ne.spannedByColSpan?r[Me+Ne.cellProps.colSpan-1]?.field??ue.field:ue.field,je=Pe==="right"?ze:ue.field,Mt=Pe?H[je]:void 0,It=Pe==="left"&&ze===R.lastLeft||Pe==="right"&&ue.field===R.firstRight,Be=ie?.spannedCells[ne]?.[ue.field],to=ie?.hiddenCells[ne]?.[ue.field]||!1,br=X&&!to&&ue.field!==Mi?uc(X,Me,Ne&&!Ne.spannedByColSpan?Ne.cellProps.colSpan:1,Be??1):void 0;return d.jsx(ts,{value:_e,row:t,colDef:ue,rowIndex:i,colIndex:Me,ariaColIndex:pe+Me+1,isSelected:l,onCellClick:g,width:Ie,pinnedPosition:Pe,pinnedOffset:Mt,isPinnedEdge:It,isFocused:$===ue.field,isFocusVisible:z,isEditable:he,isEditing:ve,onCellEditStart:A,onEditStop:D,onCellValueChange:G,colSpanInfo:Ne,rowSpan:Be,isHiddenByRowSpan:to,rowMeta:ce,valueError:Le,rangeFlags:br},ue.field)})]}),J&&d.jsx(Ag,{id:Y,colSpan:pe+K,row:t,rowId:ne,rowIndex:i,content:m,height:C,isExpanded:w,onHeightChange:E})]})}function Dg(e,t){const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const o of n)if(o==="cellRange"){if(!dc(e.cellRange,t.cellRange))return!1}else if(!Object.is(e[o],t[o]))return!1;return!0}const qn=s.memo(Og,Dg);function ns({getContent:e,params:t}){return d.jsx(_t,{field:"detail panel",renderFn:()=>e(t),resetKey:t.row})}const $g=e=>e.id;function os({rows:e,position:t,columns:n,selectedRowIds:o,checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:c,onSelectionChange:a,columnWidths:u,pinnedColumns:g,pinnedRows:p,hasDetailPanel:x,expandedRowIds:y,getDetailPanelContent:h,getDetailPanelHeight:f,onDetailPanelToggle:w,onDetailPanelHeightChange:b,pinCheckboxColumn:m,pinExpandColumn:C,focusedCell:E,colspanMap:_,rowSpanningCaches:I,rowHeight:M,rowMetaMap:S,getRowId:F=$g,rowIndexOffset:P=0,ariaRowIndexBase:L,columnIndexMap:k,editingHandlers:N,isCellEditable:T,rowReordering:v=!1,cellRange:W,cellRangeHasRowSpan:B=!1,fillHandle:Q}){return e.length===0?null:d.jsx("div",{className:`ogx__pinned-rows ogx__pinned-rows--${t}`,role:"rowgroup",children:e.map(($,z)=>{const V=F($),ie=P+z;return d.jsx(qn,{row:$,rowId:V,columns:n,rowIndex:ie,ariaRowIndex:L!==void 0?L+z:void 0,columnIndexMap:k,isSelected:o.has(V),checkboxSelection:r,onRowClick:i,onRowDoubleClick:l,onCellClick:c,onSelectionChange:a,columnWidths:u,pinnedColumns:g,pinnedRows:p,hasDetailPanel:x,isDetailPanelExpanded:y.has(V),detailPanelContent:y.has(V)&&h?d.jsx(ns,{getContent:h,params:{row:$,id:V,rowIndex:ie}}):null,detailPanelHeight:y.has(V)?mo(wo(f,{row:$,id:V,rowIndex:ie})):void 0,onDetailPanelHeightChange:b,onDetailPanelToggle:w,pinCheckboxColumn:m,pinExpandColumn:C,focusedCellField:E?.id===V?E.field:null,colspanMap:_,rowSpanningCaches:I,rowHeight:M,rowMeta:S.get(V),editingCell:N?.editingCell,onEditStart:N?.startCellEdit,onEditStop:N?.stopCellEdit,onEditCellValueChange:N?.setEditCellValue,isCellEditable:T,rowReordering:v,cellRange:Ii(W,ie,B,Q)},V)})})}const Gg=({columns:e,rowHeight:t,checkboxSelection:n=!1,hasDetailPanel:o=!1,rowReordering:r=!1})=>d.jsxs("div",{className:"ogx__row ogx__skeleton-row",style:{height:t},role:"row",children:[n&&d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:d.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),o&&d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:d.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),r&&d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:48,minWidth:48},children:d.jsx("div",{className:"ogx-skeleton-box",style:{width:18,height:18,borderRadius:2}})}),e.map((i,l)=>{const c=typeof i.width=="number"?i.width:150,a=Math.min(c*.7,c-20);return d.jsx("div",{className:"ogx__cell ogx__skeleton-cell",style:{width:c,minWidth:i.minWidth,maxWidth:i.maxWidth,insetInlineStart:i.left,insetInlineEnd:i.right,position:i.isSpacer?"relative":i.pinned?"sticky":"relative",zIndex:i.zIndex},children:!i.isSpacer&&d.jsx("div",{className:"ogx-skeleton-box",style:{width:a,height:16,borderRadius:4}})},i.field||l)})]});function Hg({virtualContainerHeight:e,offsetTop:t,effectiveLoading:n,visibleRows:o,baseColumns:r,virtualColumns:i,viewportWidth:l,checkboxSelection:c,hasDetailPanel:a,rowReordering:u,rowHeight:g,selectedRowIds:p,onRowClick:x,onRowDoubleClick:y,onCellClick:h,onSelectionChange:f,columnWidths:w,pinnedColumns:b,expandedRowIds:m,getDetailPanelContent:C,getDetailPanelHeight:E,onDetailPanelToggle:_,onDetailPanelHeightChange:I,pinCheckboxColumn:M,pinExpandColumn:S,rowReorderHandlers:F,editingHandlers:P,isCellEditable:L,focusedCell:k,colspanMap:N,rowSpanningCaches:T,paginationMode:v,dataSourceLoading:W,sortedUnpinnedRowCount:B,infiniteScrollSkeletonCount:Q,unpinnedRowsLength:$,lastRenderedRowIndex:z,rowMetaMap:V,loadingOverlay:ie,ariaRowIndexOffset:te,columnIndexMap:ce,cellRange:oe,cellRangeHasRowSpan:de=!1,fillHandle:X}){const ne=r.length>0?r:(()=>{const H=(l||1e3)-(c?48:0)-(a?48:0)-(u?48:0),R=150,ae=Math.max(1,Math.ceil(H/R));return Array.from({length:ae},(ge,J)=>({field:`placeholder_${J}`,headerName:"",width:R}))})(),se=o.filter(H=>!H.pinned),Y=v==="infinite"&&W&&B>0&&z>=$-1;return d.jsx("div",{className:"ogx__virtual-container",style:{height:`${e}px`},role:"presentation",children:d.jsxs("div",{className:"ogx__rows",style:{transform:`translateY(${t}px)`},role:"rowgroup",children:[n&&o.length===0&&ie?d.jsx("div",{className:"ogx__loading-overlay",style:{width:l||void 0},children:ie}):n&&o.length===0?Array.from({length:10}).map((H,R)=>d.jsx(Gg,{columns:ne,rowHeight:g,checkboxSelection:c,hasDetailPanel:a,rowReordering:u},`skeleton-${R}`)):se.map(({row:H,id:R,rowIndex:ae})=>d.jsx(qn,{row:H,rowId:R,columns:i,rowIndex:ae,ariaRowIndex:te!==void 0?ae+te:void 0,columnIndexMap:ce,isSelected:p.has(R),checkboxSelection:c,onRowClick:x,onRowDoubleClick:y,onCellClick:h,onSelectionChange:f,columnWidths:w,pinnedColumns:b,hasDetailPanel:a,isDetailPanelExpanded:m.has(R),detailPanelContent:m.has(R)&&C?d.jsx(ns,{getContent:C,params:{row:H,id:R,rowIndex:ae}}):null,detailPanelHeight:m.has(R)?mo(wo(E,{row:H,id:R,rowIndex:ae})):void 0,onDetailPanelHeightChange:I,onDetailPanelToggle:_,pinCheckboxColumn:M,pinExpandColumn:S,rowReordering:u,onDragStart:F.canReorderRow(R)?F.onDragStart:void 0,onDragOver:F.onDragOver,onDragEnd:F.onDragEnd,onDrop:F.onDrop,isDragging:F.draggedRowId===R,isDragOver:F.dragOverRowId===R,editingCell:P.editingCell,onEditStart:P.startCellEdit,onEditStop:P.stopCellEdit,onEditCellValueChange:P.setEditCellValue,isCellEditable:L,focusedCellField:k!=null&&k.id===R?k.field:null,colspanMap:N,rowSpanningCaches:T,rowHeight:g,rowMeta:V.get(R),cellRange:Ii(oe,ae,de,X)},R)),Y&&d.jsx("div",{className:"ogx__skeleton-group",children:Array.from({length:Q}).map((H,R)=>d.jsx(qn,{row:{id:`__skeleton_${R}__`},skeleton:!0,columns:i,rowIndex:$+R,rowHeight:g},`__skeleton_${R}__`))})]})})}function Bg({noRowsLabel:e,width:t,overlay:n}){return n?d.jsx("div",{className:"ogx__empty",style:{width:t},children:n}):d.jsxs("div",{className:"ogx__empty",style:{width:t},children:[d.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[d.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),d.jsx("path",{d:"M3 9h18M9 21V9"})]}),d.jsx("span",{children:e})]})}const rs=48;function Wg({columns:e,aggregationModel:t,aggregationResult:n,columnWidths:o,rowHeight:r,checkboxSelection:i,hasDetailPanel:l,rowReordering:c,pinCheckboxColumn:a=!0,pinExpandColumn:u=!0,pinnedColumns:g,loading:p=!1}){const x=s.useMemo(()=>uo(e,o,g,i,a,l,u,c),[e,o,g,i,a,l,u,c]),{lastLeft:y,firstRight:h}=s.useMemo(()=>fo(e,g),[e,g]),f=c?rs:0,w=f+(l&&u?rs:0),b=(m,C,E)=>d.jsx("div",{className:`ogx__aggregation-spacer${C?" ogx__aggregation-spacer--pinned":""}`,style:C?{insetInlineStart:E}:void 0,"aria-hidden":"true"},m);return d.jsxs("div",{className:`ogx__aggregation-footer${p?" ogx__aggregation-footer--loading":""}`,role:"row","aria-label":"Aggregation totals","aria-live":"polite","aria-busy":p||void 0,style:{minHeight:`${r}px`},children:[c&&b("__reorder_col__",!0,0),l&&b("__expand_col__",u,f),i&&b("__checkbox_col__",a,w),e.map(m=>{if(m.isSpacer){const L=typeof m.width=="number"?m.width:0;return d.jsx("div",{style:{width:L,minWidth:L,flexShrink:0},"aria-hidden":"true"},m.field)}const C=t[m.field],E=C&&yo(m,C)?C:void 0,_=n[m.field],I=xt(m,o,120),M=tt(m.field,g),S=M?x[m.field]:void 0,F=["ogx__aggregation-cell",M==="left"&&"ogx__aggregation-cell--pinned-left",M==="right"&&"ogx__aggregation-cell--pinned-right",M==="left"&&m.field===y&&"ogx__aggregation-cell--pinned-left-last",M==="right"&&m.field===h&&"ogx__aggregation-cell--pinned-right-first"].filter(Boolean).join(" "),P={width:I,minWidth:I,maxWidth:I,textAlign:m.align||"left"};return M==="left"&&S!==void 0&&(P.insetInlineStart=S),M==="right"&&S!==void 0&&(P.insetInlineEnd=S),d.jsx("div",{className:F,role:"gridcell",style:P,children:E?d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"ogx__aggregation-label",children:E}),d.jsx("span",{className:"ogx__aggregation-value",children:Pn(_,E,m,n)})]}):null},m.field)})]})}function Vg(e){const{setViewportElement:t,handleScroll:n,ariaLabel:o,ariaRows:r,navigationColumnCount:i,rowSelectionEnabled:l,disableMultipleRowSelection:c,cellSelection:a,effectiveLoading:u,viewportTabIndex:g,setKeyboardMode:p,handleMouseDownCapture:x,handleKeyDown:y,handleFocus:h,handleBlur:f,effectivePinnedColumns:w,virtualization:b,renderColumns:m,renderedDataColumns:C,columnGroupingModel:E,checkboxSelection:_,rowSelection:I,sortModel:M,handleSort:S,handleSortAdd:F,multiSort:P,handleColumnResize:L,handleColumnAutosize:k,columnWidths:N,focusedCell:T,columnIndexMap:v,handleHeaderClick:W,headerReorderHandlers:B,rowReordering:Q,hasDetailPanel:$,pinCheckboxColumn:z,pinExpandColumn:V,aggregationModel:ie,handleHideColumn:te,columnsPanel:ce,handlePinColumn:oe,wrapHeaderText:de,headerHeight:X,showHeaderFilters:ne,filterModel:se,handleFilterModelChange:Y,localeText:H,editingHandlers:R,isCellEditable:ae,selectedRowIds:ge,handleRowClick:J,onRowDoubleClick:O,handleCellClick:A,handleSelectionChange:G,expandedRowIds:D,getDetailPanelContent:U,getDetailPanelHeight:q,handleDetailPanelToggle:ee,reportDetailPanelHeight:Z,spanning:j,rowMetaMap:re,fillHandle:me,pinnedTopRows:pe,pinnedBottomRows:K,pinnedRows:fe,getRowIdOf:we,showEmptyState:le,effectiveNoRowsLabel:be,noRowsOverlay:Ce,loadingOverlay:ye,spanRowWindow:ue,visibleRows:ke,baseColumns:Ae,viewportWidth:Le,rowReorderHandlers:Me,paginationMode:Ie,dataSourceLoading:Pe,sortedUnpinnedRowCount:he,pageSize:ve,unpinnedRowsLength:_e,showAggregationFooter:xe,aggregationResult:Ne,effectiveRowHeight:ze,isAggregationLoading:je}=e,{allSelected:Mt,someSelected:It}=I,Be={rowReordering:Q,columnIndexMap:v,editingHandlers:R,isCellEditable:ae,selectedRowIds:ge,checkboxSelection:_,onRowClick:J,onRowDoubleClick:O,onCellClick:A,onSelectionChange:G,columnWidths:N,pinnedColumns:w,hasDetailPanel:$,expandedRowIds:D,getDetailPanelContent:U,getDetailPanelHeight:q,onDetailPanelToggle:ee,onDetailPanelHeightChange:Z,pinCheckboxColumn:z,pinExpandColumn:V,focusedCell:T,colspanMap:j.colspanMap,rowSpanningCaches:j.rowSpanningCaches,rowHeight:ze,rowMetaMap:re,cellRange:a.displayRange,cellRangeHasRowSpan:a.hasRowSpan,fillHandle:me.handle};return d.jsx("div",{ref:t,className:"ogx__viewport",onScroll:n,role:"grid","aria-label":o||"Data grid","aria-rowcount":r.rowCount,"aria-colcount":i,"aria-multiselectable":l&&!c||a.enabled,"aria-busy":u,tabIndex:g,onKeyDownCapture:()=>{p(!0)},onMouseDownCapture:x,onMouseDown:a.handleMouseDown,onClickCapture:a.handleClickCapture,onKeyDown:y,onFocus:h,onBlur:f,children:d.jsxs("div",{className:"ogx__content",style:{width:w?.right?.length?`max(100%, ${b.totalWidth}px)`:b.totalWidth},role:"presentation",children:[d.jsxs("div",{className:"ogx__sticky-top",role:"presentation",children:[d.jsx(Zl,{columns:m,allColumns:C,columnGroupingModel:E,checkboxSelection:_,allSelected:Mt,someSelected:It,onSelectAll:I.selectAll,sortModel:M,onSort:S,onSortAdd:F,multiSort:P,onColumnResize:L,onColumnAutosize:k,columnWidths:N,pinnedColumns:w,focusedCell:T,columnIndexMap:v,onHeaderClick:W,onDragStart:B.onDragStart,onDragOver:B.onDragOver,onDragEnd:B.onDragEnd,onDrop:B.onDrop,draggedColumn:B.draggedColumn,dragOverColumn:B.dragOverColumn,rowReordering:Q,hasDetailPanel:$,pinCheckboxColumn:z,pinExpandColumn:V,aggregationModel:ie,onHideColumn:te,onManageColumns:ce.openColumnsPanel,onPinColumn:oe,wrapHeaderText:de,headerHeight:X,headerFilters:ne,filterModel:se,onFilterModelChange:Y,onOpenFilterPanel:ce.openFiltersPanel,localeText:H}),d.jsx(os,{...Be,rows:pe,position:"top",ariaRowIndexBase:r.topBase,columns:m,pinnedRows:fe,getRowId:we})]}),le&&d.jsx(Bg,{noRowsLabel:be,width:b.totalWidth,overlay:Ce}),d.jsx(Hg,{...Be,virtualContainerHeight:b.virtualContainerHeight,offsetTop:ue.offsetTop,effectiveLoading:u,visibleRows:ke,baseColumns:Ae,virtualColumns:m,viewportWidth:Le,rowReorderHandlers:Me,paginationMode:Ie,dataSourceLoading:Pe,sortedUnpinnedRowCount:he,infiniteScrollSkeletonCount:Math.min(ve,20),unpinnedRowsLength:_e,lastRenderedRowIndex:ue.renderContext.lastRowIndex,ariaRowIndexOffset:r.centerOffset,loadingOverlay:ye}),d.jsxs("div",{className:"ogx__sticky-bottom",role:"presentation",children:[d.jsx(os,{...Be,rows:K,position:"bottom",rowIndexOffset:r.bottomRowIndexOffset,ariaRowIndexBase:r.bottomBase,columns:m,pinnedRows:fe,getRowId:we}),xe&&d.jsx(Wg,{columns:b.virtualColumns,aggregationModel:ie,aggregationResult:Ne,columnWidths:N,rowHeight:ze,checkboxSelection:_,hasDetailPanel:$,rowReordering:Q,pinCheckboxColumn:z,pinExpandColumn:V,pinnedColumns:w,loading:je})]})]})})}function is({count:e,sum:t,average:n}){return d.jsxs("div",{className:"ogx__cell-selection-stats",children:[d.jsxs("span",{className:"ogx__cell-selection-stat",children:[d.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Count"}),d.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"count",children:e.toLocaleString()})]}),t!==null&&d.jsxs("span",{className:"ogx__cell-selection-stat",children:[d.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Sum"}),d.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"sum",children:nn(t,"sum")})]}),n!==null&&d.jsxs("span",{className:"ogx__cell-selection-stat",children:[d.jsx("span",{className:"ogx__cell-selection-stat-label",children:"Average"}),d.jsx("span",{className:"ogx__cell-selection-stat-value","data-stat":"average",children:nn(n,"avg")})]})]})}function zg({stats:e,apiRef:t,slot:n,slotProps:o}){const r=n??is;return d.jsx("div",{className:"ogx__cell-selection-stats-area","aria-hidden":e?void 0:!0,children:e&&d.jsx(r,{apiRef:t,...e,...o})})}function Kg({paginationSlot:e,paginationSlotProps:t,page:n,paginationModel:o,rowCount:r,pageSizeOptions:i,onPaginationModelChange:l,localeText:c}){const a=e||or;return d.jsx(a,{page:n,pageSize:o.pageSize,rowCount:r,pageSizeOptions:i,onPageChange:u=>l({...o,page:u}),onPageSizeChange:u=>l({...o,pageSize:u,page:0}),localeText:$i(c),...t})}function Rg({loading:e,error:t,noRowsLabel:n,filteredRowCount:o,dataRowCount:r,filterModel:i,cellSelectionAnnouncement:l,aiAssistantAnnouncement:c}){return d.jsxs("div",{className:"ogx-aria-live-status",role:"status","aria-live":"polite",children:[e?"Loading data...":"",t?`Error: ${Al(t)}`:"",!e&&!t&&(o===0?n:i&&((i.quickFilterValues?.length||0)>0||(i.items?.length||0)>0)?`${r} ${r===1?"row":"rows"} found`:""),l?d.jsxs("span",{className:"ogx-aria-live-status__cells",children:[" ",l]}):null,c?d.jsxs("span",{className:"ogx-aria-live-status__ai",children:[" ",c]}):null]})}function Ug({overlay:e}){return e?d.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows ogx__loading-overlay--custom",children:e}):d.jsx("div",{className:"ogx__loading-overlay ogx__loading-overlay--over-rows",children:d.jsx("div",{className:"ogx__loading-bar",role:"progressbar","aria-label":"Loading data"})})}function jg({error:e,onRetry:t}){if(!e)return null;const n=Al(e);return d.jsxs("div",{className:"ogx-error-overlay","aria-live":"assertive",role:"alert",children:[d.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:[d.jsx("circle",{cx:"12",cy:"12",r:"10"}),d.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),d.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),d.jsx("div",{className:"ogx-error-overlay__title",children:"Oops! Something went wrong"}),d.jsx("div",{className:"ogx-error-overlay__message",children:n}),t&&d.jsx("button",{type:"button",onClick:t,className:"ogx-button ogx-button--primary",children:"Retry"})]})}function qg(e){const{containerRef:t,className:n,autoHeight:o,height:r,style:i,hasRowSpanning:l,listView:c,headerFilterHeight:a,slots:u,slotProps:g,toolbarProps:p,aiAssistantPanel:x,orderedColumns:y,columnVisibilityModel:h,disableColumnReorder:f,handleColumnVisibilityModelChange:w,moveColumn:b,resetColumnOrder:m,listViewColumn:C,allRenderableRows:E,dataRows:_,pagination:I,effectivePaginationModel:M,currentPage:S,pageSizeOptions:F,columnsByField:P,paginationRowCount:L,handlePaginationModelChange:k,onRowsScrollEnd:N,toggleExpansion:T,showCellSelectionStats:v,apiRef:W,hasAggregation:B,isHierarchyEnabled:Q,dataSourceError:$,filteredRowCount:z,onRetry:V,...ie}=e,{effectiveRowHeight:te,headerHeight:ce,showHeaderFilters:oe,effectiveLoading:de,columnsPanel:X,columnGroupingModel:ne,ariaLabel:se,pinnedTopRows:Y,pinnedBottomRows:H,sortedUnpinnedRowCount:R,effectiveNoRowsLabel:ae,checkboxSelection:ge,paginationMode:J,localeText:O,getRowIdOf:A,rowSelectionEnabled:G,disableMultipleRowSelection:D,cellSelection:U,aggregationModel:q,aggregationResult:ee,filterModel:Z,selectedRowIds:j,rowMetaMap:re,handleRowClick:me,onRowDoubleClick:pe,handleSelectionChange:K}=ie,fe=u?.noRowsOverlay,we=u?.loadingOverlay,le=we?d.jsx(we,{...g?.loadingOverlay}):void 0,be=fe?d.jsx(fe,{...g?.noRowsOverlay}):void 0,Ce=u?.footer,ye=de&&E.length>0&&J!=="infinite",ue=u?.toolbar;return d.jsxs("div",{ref:t,className:["ogx",n,o&&"ogx--auto-height",!o&&r===void 0&&i?.height===void 0&&"ogx--fill",l&&"ogx--row-spanning",c&&"ogx--list-view"].filter(Boolean).join(" "),style:{...i,height:r??i?.height,"--ogx-row-height":`${te}px`,"--ogx-header-height":`${ce}px`,...oe?{"--ogx-header-filter-height":`${a}px`}:void 0},"aria-busy":de,children:[ue&&p&&d.jsx(Hl.Provider,{value:X.toolbarHost,children:d.jsx(Mf,{component:ue,toolbarProps:p})}),x.panelProps&&d.jsx(Tf,{panelProps:x.panelProps,slot:u?.aiAssistantPanel,slotProps:g?.aiAssistantPanel}),d.jsx(Of,{isOpen:X.standalonePanelOpen,containerRef:t,panelRef:X.standalonePanelRef,columns:y,columnVisibilityModel:h,disableColumnReorder:f,onClose:X.closeStandalonePanel,onColumnVisibilityChange:w,onColumnMove:b,onColumnOrderReset:m,columnGroupingModel:ne}),c&&C&&d.jsx(Hf,{ariaLabel:se,allRenderableRows:E,dataRowCount:_.length,pinnedTopRowCount:Y.length,pinnedBottomRowCount:H.length,unpinnedRowCount:R,pagination:I,effectivePaginationModel:M,currentPage:S,pageSizeOptions:F,selectedRowIds:j,listViewColumn:C,columnsByField:P,rowMetaMap:re,noRowsLabel:ae,rowHeight:te,checkboxSelection:ge,paginationMode:J,serverRowCount:L,paginationSlot:u?.pagination,paginationSlotProps:g?.pagination,localeText:$i(O),onRowClick:me,onRowDoubleClick:pe,onSelectionChange:K,onPaginationModelChange:k,onRowsScrollEnd:N,getRowId:A,multiselectable:G&&!D,selectable:G,onToggleExpansion:T,loading:de,loadingOverlay:le,noRowsOverlay:be,showPaginationControls:!Ce}),!c&&d.jsx(Vg,{...ie,loadingOverlay:le,noRowsOverlay:be}),U.enabled&&v&&d.jsx(zg,{stats:U.stats,apiRef:W,slot:u?.cellSelectionStats,slotProps:g?.cellSelectionStats}),Ce&&d.jsx(Ce,{apiRef:W,aggregationModel:q,aggregationResult:B?ee:null,rowCount:Q&&J!=="server"?_.length:L,pagination:I,paginationModel:M,pageSizeOptions:F,onPaginationModelChange:k,...g?.footer}),!c&&!Ce&&I&&d.jsx(Kg,{paginationSlot:u?.pagination,paginationSlotProps:g?.pagination,page:S,paginationModel:M,rowCount:L,pageSizeOptions:F,onPaginationModelChange:k,localeText:O}),d.jsx(Rg,{loading:de,error:$,noRowsLabel:ae,filteredRowCount:z,dataRowCount:_.length,filterModel:Z,cellSelectionAnnouncement:U.announcement,aiAssistantAnnouncement:x.announcement}),ye&&d.jsx(Ug,{overlay:le}),d.jsx(jg,{error:$,onRetry:V})]})}function Xg(e){const{baseColumns:t,pinnedColumns:n,hasGroupingColumn:o,groupingColDef:r,isTreeData:i,getTreeDataPath:l}=e,c=s.useMemo(()=>o?{...n,left:["__group__",...(n?.left??[]).filter(u=>u!=="__group__")]}:n,[o,n]);return{activeColumns:s.useMemo(()=>o?[{headerName:"Group",width:220,...i&&l?{valueGetter:({row:u})=>{const g=l(u);return g[g.length-1]}}:{},...r,field:"__group__",hideable:!1,sortable:!1,filterable:!1,pinnable:!1,exportable:!1},...t]:t,[r,o,i,l,t]),effectivePinnedColumns:c}}function Yg(e){return e.id}function Jg(e){const t=s.useCallback(r=>e.get(r)??r.id,[e]),n=s.useRef(t);s.useLayoutEffect(()=>{n.current=t});const o=s.useCallback(r=>n.current(r),[]);return{getRowIdOf:t,getRowIdOfInEvents:o}}function Zg(e,t){s.useLayoutEffect(()=>{e&&(e.current=t.current)},[e,t])}function Qg(e){const{hierarchyHandlers:t,pinnedTopRows:n,sortedUnpinnedRows:o,pinnedBottomRows:r,rowMetaMap:i,getRowId:l,hierarchyField:c,dataRows:a}=e,u=t?.getVisibleRows({expandAll:!0,labelField:c});if(!u)return[...n,...o,...r];const g=a?new Set(a):null;return u.filter(p=>!i.get(l(p))?.isGroupRow&&(!g||g.has(p)))}function ep(e,t){if(e===t)return!0;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;const o=e,r=t;return n.every(i=>Object.prototype.hasOwnProperty.call(t,i)&&Object.is(o[i],r[i]))}function tp(e,t){return e===t?!0:e.length!==t.length?!1:e.every((n,o)=>ep(n,t[o]))}function np(e){const[t,n]=s.useState(e),o=tp(t,e);return o||n(e),o?t:e}function op(e){const{rows:t,getRowId:n,rowMetaMap:o,columns:r,aggregationModel:i,aggregationResult:l,isSubtotalHidden:c}=e,a=Object.keys(i).length>0,u=new Map(r.map(y=>[y.field,y])),g=[],p=[],x=y=>{for(;p.length>0&&p[p.length-1].header.depth>=y;){const h=p.pop();a&&!c?.(h.id)&&g.push({type:"group-subtotal",depth:h.header.depth,groupField:h.header.groupField,groupValue:h.header.groupValue,groupLabel:h.header.groupLabel,aggregatedValues:Ln(h.leaves,i,u,"getGroupedExportRows")})}};for(const y of t){const h=n(y),f=o.get(h);if(!f?.isGroupFooter)if(f?.isGroupRow){const w=f.treeDepth??0;x(w);const b={type:"group-header",depth:w,groupField:f.groupingField,groupValue:f.groupingValue,groupLabel:f.groupLabel};g.push(b),p.push({id:h,header:b,leaves:[]})}else g.push({type:"leaf",depth:f?.treeDepth??p.length,row:y}),p.forEach(w=>w.leaves.push(y))}return x(0),a&&l&&g.push({type:"grand-total",depth:0,aggregatedValues:l}),g}function rp(e){const{apiRef:t}=e,n=s.useRef(e);s.useLayoutEffect(()=>{n.current=e}),s.useLayoutEffect(()=>{const o=()=>n.current;t.current.getAggregationResult=()=>o().hasAggregation?o().aggregationResult:null,t.current.getAggregationModel=()=>o().hasAggregation?o().aggregationModel:null,t.current.getGroupedExportRows=()=>{const{hasAggregation:r,aggregationResult:i,aggregationModel:l,isRowGrouping:c,rowGroupingHandlers:a,rowMetaMap:u,columns:g,getRowId:p,hierarchyField:x}=o();return c?op({rows:a.getVisibleRows({expandAll:!0,labelField:x})??[],getRowId:p,rowMetaMap:u,columns:g,aggregationModel:l,aggregationResult:r&&a.rootAggregationPosition!==null?i:null,isSubtotalHidden:y=>a.aggregationPositions.get(y)===null}):null}},[t])}const ls="ogx--range-dragging",gt=32,ip=40,lp=300;function ss(e,t){if(!e||e.nodeType!==1)return null;const n=e.closest(".ogx__cell[data-field]");if(!n||n.closest(".ogx__viewport")!==t)return null;const o=n.closest(".ogx__detail-panel");if(o&&t.contains(o))return null;const r=n.closest('[role="row"][data-rowindex]');if(!r)return null;const i=Number(r.getAttribute("data-rowindex")),l=n.dataset.field;return!Number.isInteger(i)||!l?null:{rowIndex:i,field:l,element:n}}function gr(e){const t=e.getSelection();t&&t.rangeCount>0&&t.removeAllRanges()}const as=(e,t,n)=>Math.min(Math.max(e,t),n),Xn=e=>Math.min(ip,Math.max(2,Math.round(e/2)));function sp(e){process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] Copying ${e} cells. For ranges this large, exportToCsv or exportToExcel is the better tool.`)}function ap(e){const{enabled:t,model:n,allRenderableRows:o,getRowId:r,navigationColumns:i,columnIndexMap:l,spanning:c,rowMetaMap:a,localeText:u,showStats:g}=e,p=t&&n.length>0?n[0]:null,x=s.useMemo(()=>t?i.filter(A=>Ue(A.field)):[],[t,i]),y=s.useMemo(()=>{if(!c.hasColSpan&&!c.hasRowSpan)return;const{colspanMap:A,rowSpanningCaches:G,getSpanOrigin:D}=c;return{getSpanOrigin:D,getColSpan:(U,q)=>{const ee=A.get(U)?.[q];return ee&&!ee.spannedByColSpan?ee.cellProps.colSpan:1},getRowSpan:(U,q)=>G.spannedCells[U]?.[q]??1}},[c]),h=s.useMemo(()=>{if(!t)return null;const{rowIds:A,rowIndexById:G}=Vo(o,r,"renderable"),D=x.map(U=>U.field);return{rowIds:A,rowIndexById:G,fields:D,colIndexByField:new Map(D.map((U,q)=>[U,q])),spans:y}},[t,o,r,x,y]),f=s.useMemo(()=>p&&h?Gn(p,h):null,[p,h]),w=f!==null&&St(f)>1,b=s.useMemo(()=>{if(!f||!w||!h)return null;const A=l.get(h.fields[f.left]),G=l.get(h.fields[f.right]);return A===void 0||G===void 0?null:{top:f.top,bottom:f.bottom,left:A,right:G}},[f,w,h,l]),m=s.useCallback(A=>Re(A,a),[a]),C=s.useCallback((A,G,D)=>{if(h)for(let U=A.top;U<=A.bottom;U++){const q=o[U],ee=h.rowIds[U];if(!(!q||m(ee))){G(q,ee);for(let Z=A.left;Z<=A.right;Z++){const j=x[Z],re=y?.getSpanOrigin(ee,j.field);D(q,ee,j,re!=null&&(re.rowId!==ee||re.field!==j.field))}}}},[h,o,x,y,m]),E={...e,range:p,resolved:f,context:h,rangeColumns:x,forEachCell:C},_=s.useRef(E);s.useLayoutEffect(()=>{_.current=E});const I=s.useRef(null),M=s.useCallback(A=>{I.current=A},[]),S=s.useCallback(()=>{const{getPendingModel:A,model:G}=_.current;return A()??G},[]),F=s.useCallback(()=>{const{context:A,range:G,resolved:D,enabled:U}=_.current,q=U?S()[0]??null:null;return!q||!A?{range:null,resolved:null}:q===G?{range:q,resolved:D}:{range:q,resolved:Gn(q,A)}},[S]),P=s.useCallback((A,G)=>{if(!_.current.enabled)return;const D=A.length>1?A.slice(0,1):A;sc(D,S())||_.current.onModelChange(D,G)},[S]),L=s.useCallback((A,G,D)=>{P([{anchor:A,head:G}],D)},[P]),k=s.useCallback((A,G)=>{const{viewportRef:D,layout:U,rowHeight:q,pinnedTopRowCount:ee}=_.current,Z=D.current;Z&&(Nn(Z,A-ee,U.cumulativeHeights,U.pinnedBottomHeight,q),bo(Z,U.unpinnedColsWithWidth.findIndex(j=>j.field===G),U))},[]),N=s.useCallback((A,G,D,U)=>{const{context:q}=_.current,{range:ee,resolved:Z}=F();if(!q||U.id===null||!Ue(U.field))return!1;const j=q.rowIndexById.get(U.id),re=q.colIndexByField.get(U.field);if(j===void 0||re===void 0)return!1;const me=ee&&Z&&ct(ee.anchor,{id:U.id,field:U.field})?{range:ee,resolved:Z}:null,pe=me?me.range.anchor:{id:U.id,field:U.field},K=me?.resolved??Gn({anchor:pe,head:pe},q);if(!K)return!1;const fe=cc(K,A,G,D,q.rowIds.length-1,q.fields.length-1);if(!fe)return!0;const we={id:q.rowIds[fe.row],field:q.fields[fe.col]};return L(pe,we,"keyboard"),k(fe.row,we.field),!0},[F,L,k]),T=s.useCallback(()=>{const{range:A,resolved:G}=F();return!A||!G||St(G)<=1?!1:(L(A.anchor,A.anchor,"keyboard"),!0)},[F,L]),v=s.useCallback(()=>{const{context:A}=_.current;return!A||A.rowIds.length===0||A.fields.length===0?!1:(L({id:A.rowIds[0],field:A.fields[0]},{id:A.rowIds[A.rowIds.length-1],field:A.fields[A.fields.length-1]},"selectAll"),!0)},[L]),W=s.useCallback(()=>{const{context:A}=_.current,{range:G,resolved:D}=F();if(!A)return null;if(D)return D;if(G)return null;const U=I.current;return!U||U.id===null||!Ue(U.field)?null:Gn({anchor:{id:U.id,field:U.field},head:{id:U.id,field:U.field}},A)},[F]),B=s.useCallback(()=>{const A=W();if(!A)return null;const{rangeColumns:G,forEachCell:D}=_.current,U=St(A);U>gc&&sp(U);const q=[];if(D(A,me=>{q.push(me)},()=>{}),q.length===0)return null;const ee=G.slice(A.left,A.right+1),Z=_.current.context?.spans,j=_.current.getRowId;return Xd(q,ee,Z?(me,pe)=>{const K=j(me),fe=Z.getSpanOrigin(K,pe.field);return fe!==null&&(fe.rowId!==K||fe.field!==pe.field)}:void 0)},[W]),Q=s.useCallback(()=>{const{forEachCell:A}=_.current,{resolved:G}=F();if(!G)return[];const D=[];return A(G,()=>{},(U,q,ee,Z)=>{Z||D.push({id:q,field:ee.field,value:Ee(U,ee.field,ee)})}),D},[F]),$=s.useRef(null),z=s.useRef(!1);s.useEffect(()=>()=>$.current?.stop(),[]);const V=s.useCallback((A,G,D)=>{const U=_.current.context;if(!U)return null;const q=A.ownerDocument;if(typeof q.elementFromPoint!="function")return null;const ee=ss(q.elementFromPoint(G,D),A);if(!ee)return null;const Z=U.rowIds[ee.rowIndex];if(Z===void 0)return null;const j=Ue(ee.field)?ee.field:U.fields[0];return j===void 0?null:{id:Z,field:j}},[]),ie=s.useCallback((A,G)=>{const{context:D,layout:U,pinnedTopRowCount:q}=_.current,ee=U.cumulativeHeights;if(!D||ee.length===0||A<0)return null;let Z=0,j=ee.length-1;for(;Z<j;){const me=Z+j>>1;ee[me]>A?j=me:Z=me+1}const re=D.rowIds[Z+q];return re===void 0?null:{id:re,field:G}},[]),te=s.useRef(()=>{}),ce=s.useCallback(A=>{const G=$.current,D=_.current.viewportRef.current;if(!G||!D)return;G.frame=0;const{layout:U}=_.current,q=D.getBoundingClientRect(),ee=D.clientWidth,Z=D.clientHeight,j=D.querySelector(":scope > .ogx__content > .ogx__sticky-top"),re=D.querySelector(":scope > .ogx__content > .ogx__sticky-bottom"),me=j?.querySelector(":scope > .ogx__header-wrap"),pe=j?j.getBoundingClientRect().bottom:q.top,K=Math.min(q.top+Z,re?re.getBoundingClientRect().top:q.top+Z),fe=me?me.getBoundingClientRect().bottom:pe;G.rtl===void 0&&(G.rtl=Xe(D));const we=G.rtl,le=we?q.right-ee:q.left,be=U.pinnedSystemColumnsWidth+U.leftWidth,Ce=le+(we?U.rightWidth:be),ye=le+ee-(we?be:U.rightWidth),ue=as(G.x,le+1,le+ee-2);let ke=G.y;(ke<q.top||ke>q.top+Z||ke<fe)&&(ke=as(ke,pe+1,Math.max(pe+1,K-2)));const Ae=typeof D.ownerDocument.elementFromPoint=="function",Me=V(D,ue,ke)??(Ae&&G.moved?ie(ke-q.top-(j?j.getBoundingClientRect().height:0)+D.scrollTop,G.head.field):null);if(Me&&!ct(Me,G.head)&&(G.head=Me,!G.moved&&!ct(Me,G.anchor)&&(G.moved=!0,_.current.containerRef.current?.classList.add(ls),gr(D.ownerDocument)),G.onTrack||L(G.anchor,Me,"pointer")),G.onTrack&&G.onTrack(G.head,G.x,G.y),!A)return;const Ie=G.y<pe||G.y>K||G.x<le||G.x>le+ee;if(!G.moved&&!Ie)return;let Pe=0,he=0;G.y<pe+gt?Pe=-Xn(pe+gt-G.y):G.y>K-gt&&(Pe=Xn(G.y-(K-gt))),G.x<Ce+gt?he=-Xn(Ce+gt-G.x):G.x>ye-gt&&(he=Xn(G.x-(ye-gt)));const ve=Pe<0&&D.scrollTop>0||Pe>0&&D.scrollTop+Z<D.scrollHeight-1,_e=D.scrollWidth-ee,xe=we?-_e:0,Ne=he<0&&D.scrollLeft>xe||he>0&&D.scrollLeft<xe+_e-1;!ve&&!Ne||(ve&&(D.scrollTop+=Pe),Ne&&(D.scrollLeft+=he),G.frame=requestAnimationFrame(()=>te.current(!0)))},[V,ie,L]);s.useLayoutEffect(()=>{te.current=ce},[ce]);const oe=s.useCallback((A,G,D,U,q,ee)=>{$.current?.stop();const Z=ee?"pointermove":"mousemove",j=ee?"pointerup":"mouseup",re=ye=>!ee||ye.pointerId===ee.pointerId,me=ye=>{const ue=$.current;if(!(!ue||!re(ye))){if(ye.buttons===0){ue.stop();return}ue.x=ye.clientX,ue.y=ye.clientY,ue.moved&&(ye.preventDefault(),gr(q)),ue.frame||(ue.frame=requestAnimationFrame(()=>ce(!0)))}},pe=ye=>{const ue=$.current;if(!ue||!re(ye))return;ue.x=ye.clientX,ue.y=ye.clientY,ce(!1);const ke=ue.moved;ue.stop(!1,ye.altKey),ke&&gr(q),ke&&(z.current=!0,setTimeout(()=>{z.current=!1},0))},K=ye=>{re(ye)&&$.current?.stop()},fe=ye=>{ye.key!=="Escape"||!$.current||(ye.preventDefault(),ye.stopPropagation(),$.current.stop())},we=q.defaultView,le=()=>$.current?.stop();let be=!1;const Ce={anchor:A,head:G,x:D,y:U,frame:0,moved:!1,onTrack:ee?.onTrack,stop:(ye=!0,ue=!1)=>{Ce.frame&&cancelAnimationFrame(Ce.frame),Ce.frame=0,q.removeEventListener(Z,me,!0),q.removeEventListener(j,pe,!0),ee&&(q.removeEventListener("pointercancel",K,!0),q.removeEventListener("keydown",fe,!0)),we?.removeEventListener("blur",le),_.current.containerRef.current?.classList.remove(ls),$.current===Ce&&($.current=null),be||(be=!0,ee&&ee.onEnd({cancelled:ye,altKey:ue}))}};$.current=Ce,q.addEventListener(Z,me,!0),q.addEventListener(j,pe,!0),ee&&(q.addEventListener("pointercancel",K,!0),q.addEventListener("keydown",fe,!0)),we?.addEventListener("blur",le)},[ce]),de=s.useCallback(A=>{const G=_.current.viewportRef.current;if(!G||!_.current.enabled)return;const{start:D,x:U,y:q,pointerId:ee,onTrack:Z,onEnd:j}=A;oe(D,D,U,q,G.ownerDocument,{pointerId:ee,onTrack:Z,onEnd:j})},[oe]),X=s.useCallback(A=>{if(A.button!==0||A.defaultPrevented)return;const{context:G}=_.current;if(!G)return;const D=A.currentTarget,U=ss(A.target,D);if(!U||!Ue(U.field)||A.target.closest?.(".ogx__cell-fill-handle")||U.element.classList.contains("ogx__cell--editing")||Si(A.target))return;const q=G.rowIds[U.rowIndex];if(q===void 0)return;const ee={id:q,field:U.field};let Z=ee;if(A.shiftKey){const j=S()[0],re=I.current;j&&G.rowIndexById.has(j.anchor.id)&&G.colIndexByField.has(j.anchor.field)?Z=j.anchor:re&&re.id!==null&&Ue(re.field)&&(Z={id:re.id,field:re.field}),A.preventDefault(),z.current=!0;const me=D.ownerDocument;D.contains(me.activeElement)||D.focus({preventScroll:!0})}if(L(Z,ee,"pointer"),oe(Z,ee,A.clientX,A.clientY,D.ownerDocument),A.shiftKey){const j=$.current;j&&!ct(Z,ee)&&(j.moved=!0)}},[S,L,oe]),ne=s.useCallback(A=>{z.current&&(z.current=!1,A.stopPropagation(),A.preventDefault())},[]),se=f?f.right-f.left+1:0,Y=f?f.bottom-f.top+1:0,H=u?.cellSelectionAnnouncement??fc,R=w?H(Y*se,Y,se):"",[ae,ge]=s.useState("");s.useEffect(()=>{if(!t)return;const A=setTimeout(()=>ge(R),lp);return()=>clearTimeout(A)},[t,R]);const J=s.useMemo(()=>{if(!g||!f||!w)return null;const A=[];C(f,()=>{},(D,U,q,ee)=>{ee||A.push(Ee(D,q.field,q))});const G=A.filter(D=>typeof D=="number"&&!Number.isNaN(D));return{cellCount:St(f),rowCount:f.bottom-f.top+1,columnCount:f.right-f.left+1,count:at.count(A),numericCount:G.length,sum:G.length?at.sum(G):null,average:G.length?at.avg(G):null}},[g,f,w,C]),O=s.useMemo(()=>t?{extendSelection:N,collapseSelection:T,selectAllCells:v}:void 0,[t,N,T,v]);return{enabled:t,range:p,resolved:f,displayRange:b,hasRowSpan:c.hasRowSpan,handleMouseDown:t?X:void 0,handleClickCapture:t?ne:void 0,extendSelection:N,collapseSelection:T,selectAllCells:v,keyboard:O,getCopyText:B,getSelectedCells:Q,announcement:t?ae:"",stats:J,reportFocus:M,setModel:P,getCurrentRange:F,startTrackedDrag:de}}function cp(e){return s.useCallback(t=>{e.current?.classList.toggle("ogx--kb",t)},[e])}function dp(e){const{ensureGridFocus:t,setKeyboardMode:n,setFocusedCell:o,getRowId:r,onCellClick:i}=e,l=s.useCallback(a=>{t(),n(!1),o({id:r(a.row),field:a.field,rowIndex:a.rowIndex}),i?.(a)},[i,n,o,t,r]),c=s.useCallback(a=>{t(),o({id:null,field:a}),n(!1)},[t,o,n]);return{handleCellClick:l,handleHeaderClick:c}}function up(){const[e,t]=s.useState(!1),[n,o]=s.useState(!1),r=s.useRef(null),i=s.useRef(0),[l,c]=s.useState(0),[a,u]=s.useState(!1),g=s.useMemo(()=>({registerColumnsPanel:()=>(i.current+=1,()=>{i.current-=1}),registerFiltersPanel:()=>(c(w=>w+1),()=>c(w=>w-1))}),[]),p=s.useCallback(()=>u(!0),[]),x=s.useCallback(()=>u(!1),[]),y=s.useCallback(()=>{i.current>0?t(!0):o(!0)},[]),h=s.useCallback(()=>t(!1),[]),f=s.useCallback(()=>o(!1),[]);return s.useEffect(()=>{if(!n)return;function w(m){r.current&&!r.current.contains(m.target)&&o(!1)}function b(m){m.key==="Escape"&&o(!1)}return document.addEventListener("mousedown",w),document.addEventListener("keydown",b),()=>{document.removeEventListener("mousedown",w),document.removeEventListener("keydown",b)}},[n]),{toolbarHost:g,toolbarPanelRequested:e,closeToolbarPanel:h,standalonePanelOpen:n,closeStandalonePanel:f,standalonePanelRef:r,openColumnsPanel:y,toolbarFiltersRequested:a,closeToolbarFiltersPanel:x,openFiltersPanel:l>0?p:void 0}}const fp=Symbol.for("opengridx.ai.validated");function gp(e){return typeof e=="object"&&e!==null&&e[fp]===!0}const Yn=["filter","sort","grouping","aggregation","pivot","columnVisibility"],pr={filter:"filterModel",sort:"sortModel",grouping:"rowGroupingModel",aggregation:"aggregationModel",pivot:"pivotModel",columnVisibility:"columnVisibilityModel"};function cs(e){return Yn.map(t=>pr[t]).filter(t=>e[t]!==void 0)}function pp(e,t){const n={},o=[];for(const r of Yn){const i=pr[r];e[i]!==void 0&&(t.includes(r)?Object.assign(n,{[i]:e[i]}):o.push({path:i,message:"Part not allowed"}))}return{state:n,errors:o}}function hp(e,t){const n=e[t];if(Array.isArray(n))return n.length===0;if(t==="filterModel"){const o=e.filterModel;return!o||(o.items??[]).length===0&&(o.quickFilterValues??[]).length===0}if(t==="pivotModel"){const o=e.pivotModel;return!o||o.rowFields.length===0&&o.columnFields.length===0&&o.valueFields.length===0}return typeof n=="object"&&n!==null&&Object.keys(n).length===0}function mp(e){let t=e.length;for(const n of[".","["]){const o=e.indexOf(n);o>=0&&o<t&&(t=o)}return e.slice(0,t)}function wp(e,t){const n=new Set(t.map(r=>mp(typeof r.path=="string"?r.path:""))),o={};for(const r of cs(e))n.has(r)&&hp(e,r)||Object.assign(o,{[r]:e[r]});return o}function bp(e,t){const n={};for(const o of cs(e))Object.assign(n,{[o]:t[o]});return n}function ds(e,t){const n={};for(const o of Yn.map(r=>pr[r]))!(o in t)&&e[o]===void 0||(e[o]===void 0?Object.assign(n,{[o]:t[o]}):o==="columnVisibilityModel"?n.columnVisibilityModel={...t.columnVisibilityModel,...e.columnVisibilityModel}:Object.assign(n,{[o]:e[o]}));return n}function hr(e,t){t.filterModel&&e.setFilterModel(t.filterModel),t.sortModel&&e.setSortModel(t.sortModel),t.rowGroupingModel&&e.setRowGroupingModel(t.rowGroupingModel),t.aggregationModel&&e.setAggregationModel(t.aggregationModel),t.pivotModel&&e.setPivotModel(t.pivotModel),t.columnVisibilityModel&&e.setColumnVisibilityModel(t.columnVisibilityModel)}function us(e){return Array.isArray(e)?e.map(us).join(", "):e instanceof Date?e.toISOString().slice(0,10):e==null?"":String(e)}function fs(e,t){return"items"in e?`(${e.items.map(n=>fs(n,t)).join(` ${e.logicOperator} `)})`:[t(e.field),e.operator,us(e.value)].filter(Boolean).join(" ")}const xp={sum:"Sum",avg:"Average",count:"Count",min:"Min",max:"Max",unique:"Unique"};function gs(e,t){const n=[],{filterModel:o,sortModel:r,rowGroupingModel:i,aggregationModel:l,pivotModel:c,columnVisibilityModel:a}=e;if(o){const u=o.items??[];u.forEach((p,x)=>n.push({id:`filter:${x}`,part:"filter",label:fs(p,t)}));const g=o.quickFilterValues??[];g.length>0&&n.push({id:"filter:quick",part:"filter",label:`Search: ${g.join(" ")}`}),u.length===0&&g.length===0&&n.push({id:"filter:clear",part:"filter",label:"No filters"})}if(r&&(r.forEach((u,g)=>n.push({id:`sort:${g}`,part:"sort",label:`Sort: ${t(u.field)}, ${u.sort==="desc"?"descending":"ascending"}`})),r.length===0&&n.push({id:"sort:clear",part:"sort",label:"No sorting"})),i&&(i.forEach((u,g)=>n.push({id:`grouping:${g}`,part:"grouping",label:`Group: ${t(u)}`})),i.length===0&&n.push({id:"grouping:clear",part:"grouping",label:"No grouping"})),l){const u=Object.keys(l);u.forEach(g=>{const p=l[g];n.push({id:`aggregation:${g}`,part:"aggregation",label:`${xp[p]??p}: ${t(g)}`})}),u.length===0&&n.push({id:"aggregation:clear",part:"aggregation",label:"No summaries"})}if(c){const u=[...c.rowFields,...c.columnFields,...c.valueFields.map(g=>g.field)];n.push({id:"pivot",part:"pivot",label:u.length>0?`Pivot: ${u.map(t).join(", ")}`:"No pivot"})}if(a)for(const u of Object.keys(a))n.push({id:`columnVisibility:${u}`,part:"columnVisibility",label:`${a[u]?"Show":"Hide"}: ${t(u)}`});return n}function yp(e,t){const n={...e},o=t.indexOf(":"),r=o<0?t:t.slice(0,o),i=o<0?"":t.slice(o+1),l=Number(i);if(r==="filter"&&n.filterModel){const c={...n.filterModel};i==="quick"?delete c.quickFilterValues:i==="clear"?c.items=[]:c.items=(c.items??[]).filter((a,u)=>u!==l),(c.items??[]).length===0&&(c.quickFilterValues??[]).length===0?delete n.filterModel:n.filterModel=c}else if(r==="sort"&&n.sortModel)n.sortModel=n.sortModel.filter((c,a)=>a!==l),(n.sortModel.length===0||i==="clear")&&delete n.sortModel;else if(r==="grouping"&&n.rowGroupingModel)n.rowGroupingModel=n.rowGroupingModel.filter((c,a)=>a!==l),(n.rowGroupingModel.length===0||i==="clear")&&delete n.rowGroupingModel;else if(r==="aggregation"&&n.aggregationModel){const c={...n.aggregationModel};delete c[i],Object.keys(c).length===0?delete n.aggregationModel:n.aggregationModel=c}else if(r==="columnVisibility"&&n.columnVisibilityModel){const c={...n.columnVisibilityModel};delete c[i],Object.keys(c).length===0?delete n.columnVisibilityModel:n.columnVisibilityModel=c}else r==="pivot"&&delete n.pivotModel;return n}const Cp="Ask about this table…",vp=[],Jn=[],ps="The reply was not validated";function Sp(){return typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)}function _p(e){return typeof e=="object"&&e!==null&&e.name==="AbortError"}function kp(e){return e instanceof Error&&e.message?e.message:"Unknown error"}function Ep(e,t){const n=e===0?"No changes":`Applied ${e} ${e===1?"change":"changes"}`;return t>0?`${n}, ${t} ignored`:n}function hs(e,t,n){if(!e)return;const o=We(()=>e(t));!o.ok&&process.env.NODE_ENV!=="production"&&console.warn(`[OpenGridX] ${n} threw.`,o.error)}function Mp(e){const{apiRef:t,options:n,columns:o}=e,r=!!n,[i,l]=s.useState(!1),[c,a]=s.useState("idle"),[u,g]=s.useState(""),[p,x]=s.useState(null),[y,h]=s.useState(Jn),[f,w]=s.useState(null),[b,m]=s.useState([]),C=s.useRef(null),E=s.useRef(null),_=s.useRef({params:e,applied:f,history:b,open:i});s.useLayoutEffect(()=>{_.current={params:e,applied:f,history:b,open:i}});const I=s.useMemo(()=>{const z=new Map(o.map(V=>[V.field,V.headerName||V.field]));return V=>z.get(V)??V},[o]),M=s.useMemo(()=>f?gs(f.state,I):[],[f,I]),S=s.useCallback(()=>{const z=C.current;C.current=null,z&&z.abort()},[]);s.useEffect(()=>S,[S]);const F=s.useCallback(z=>{if(!_.current.params.options)return;const V=typeof document>"u"?null:document.activeElement;E.current=z??(V instanceof HTMLElement?V:null),l(!0)},[]),P=s.useCallback(()=>{C.current&&(S(),a("stopped"),g("Stopped")),l(!1);const z=E.current;E.current=null,z&&z.isConnected&&z.focus()},[S]),L=s.useCallback(z=>{_.current.open?P():F(z)},[F,P]),k=s.useCallback((z,V)=>{a("error"),g(z),x(null),h(Jn),hs(_.current.params.onError,V,"onAiAssistantError")},[]),N=s.useCallback((z,V)=>{const{params:ie}=_.current;if(!(typeof V=="object"&&V!==null)||!gp(V.state)){process.env.NODE_ENV!=="production"&&console.warn("[OpenGridX] aiAssistant: the onPrompt result was not applied because its state was not validated. Return the result of createGridAiPromptHandler, or pass the model reply through validateGridAiState (from @opencorestack/opengridx/ai) and return its state."),k(ps,new Error(ps));return}const ce=pp(V.state,ie.options?.parts??Yn),oe=[...Array.isArray(V.errors)?V.errors:[],...ce.errors],de=wp(ce.state,oe),X=t.current,ne=bp(de,X.getGridAiState());hr(X,ds(de,ne)),w({state:de,previous:ne}),h(oe),x(typeof V.message=="string"&&V.message?V.message:null),m(se=>[...se,{prompt:z,applied:de}]),a("applied"),g(Ep(gs(de,se=>se).length,oe.length)),hs(ie.onApply,V,"onAiAssistantApply")},[t,k]),T=s.useCallback(z=>{const V=z.trim(),{params:ie,history:te}=_.current,ce=ie.options?.onPrompt;if(!V||!ce)return;S();const oe=new AbortController;C.current=oe,a("running"),g("Thinking…"),x(null),h(Jn);const de={currentState:t.current.getGridAiState(),history:te,signal:oe.signal},X=We(()=>ce(V,de));(X.ok?Promise.resolve(X.value):Promise.reject(X.error)).then(se=>{C.current===oe&&(C.current=null,N(V,se))},se=>{if(C.current===oe){if(C.current=null,oe.signal.aborted||_p(se)){a("stopped"),g("Stopped");return}k(`The assistant could not answer: ${kp(se)}`,se)}})},[t,S,N,k]),v=s.useCallback(()=>{C.current&&(S(),a("stopped"),g("Stopped"))},[S]),W=s.useCallback(()=>{const z=_.current.applied;z&&(hr(t.current,z.previous),w(null),h(Jn),x(null),a("idle"),g("Undone"))},[t]),B=s.useCallback(z=>{const V=_.current.applied;if(!V)return;const ie=yp(V.state,z);hr(t.current,ds(ie,V.previous)),w({state:ie,previous:V.previous}),g("Change removed")},[t]);s.useLayoutEffect(()=>{const z=t.current;z.openAiAssistant=()=>F(),z.closeAiAssistant=()=>{_.current.open&&P()}},[t,F,P]);const Q=r&&i,$=s.useMemo(()=>!Q||!n?null:{status:c,statusText:u,message:p,errors:y,chips:M,history:b,suggestions:n.suggestions??vp,placeholder:n.placeholder??Cp,voiceAvailable:n.voice!==!1&&Sp(),canUndo:f!==null,submit:T,stop:v,undo:W,removeChip:B,close:P},[Q,n,c,u,p,y,M,b,f,T,v,W,B,P]);return{enabled:r,open:Q,openPanel:F,togglePanel:L,closePanel:P,panelProps:$,announcement:r?u:""}}function Ip(e){const{toolbar:t,toolbarSlotProps:n,apiRef:o,orderedColumns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:c,pivotMode:a,pivotModelProp:u,onPivotModelChangeProp:g,pivotModel:p,onPivotModelChange:x,filterModel:y,onFilterModelChange:h,columnVisibilityModel:f,onColumnVisibilityModelChange:w,disableColumnReorder:b,columnGroupingModel:m,moveColumn:C,resetColumnOrder:E,forceColumnsOpen:_,onColumnsPanelClose:I,aiAssistantEnabled:M=!1,aiAssistantOpen:S=!1,onAiAssistantToggle:F,aiAssistantLabel:P,forceFiltersOpen:L,onFiltersPanelClose:k}=e;return s.useMemo(()=>t?{apiRef:o,columns:r,baseColumns:i,aggregationModel:l,onAggregationModelChange:c,...a||u||g?{pivotModel:p,onPivotModelChange:x}:{},filterModel:y,onFilterModelChange:h,columnVisibilityModel:f,onColumnVisibilityModelChange:w,onColumnReorder:b?void 0:(T,v)=>{Ro(m,T,v)&&C(T,v)},onColumnOrderReset:b?void 0:E,forceColumnsOpen:_,onColumnsPanelClose:I,...M&&F?{onAiAssistantToggle:F,aiAssistantOpen:S,...P?{aiAssistantLabel:P}:{}}:{},forceFiltersOpen:L,onFiltersPanelClose:k,...n}:null,[t,b,C,E,r,o,i,l,c,a,u,g,p,x,y,h,f,w,_,I,n,m,M,S,F,P,L,k])}function Np(e){const{apiRef:t,containerRef:n,aiAssistant:o,toolbar:r,localeText:i}=e,l=up();Xc(n);const c=Mp({apiRef:t,...o}),a=Ip({...r,apiRef:t,forceColumnsOpen:l.toolbarPanelRequested,onColumnsPanelClose:l.closeToolbarPanel,aiAssistantEnabled:c.enabled,aiAssistantOpen:c.open,onAiAssistantToggle:c.togglePanel,aiAssistantLabel:i?.aiAssistantButton,forceFiltersOpen:l.toolbarFiltersRequested,onFiltersPanelClose:l.closeToolbarFiltersPanel});return{columnsPanel:l,aiAssistantPanel:c,toolbarProps:a}}function Lp(e){const{rows:t,columns:n,getRowId:o,rowHeight:r,headerHeight:i,wrapHeaderText:l=!1,headerFilters:c=!1,headerFilterHeight:a=rg,autoHeight:u=!1,density:g,height:p,className:x="",style:y,ariaLabel:h,loading:f=!1,checkboxSelection:w=!1,disableRowSelectionOnClick:b=!1,disableMultipleRowSelection:m=!1,disableClipboardCopy:C=!1,cellSelection:E=!1,cellSelectionModel:_,onCellSelectionModelChange:I,showCellSelectionStats:M=!1,rowSelectionModel:S,onRowSelectionModelChange:F,onRowClick:P,onRowDoubleClick:L,onCellClick:k,filterModel:N,onFilterModelChange:T,sortModel:v,onSortModelChange:W,pagination:B=!1,paginationModel:Q,onPaginationModelChange:$,pageSizeOptions:z=[10,25,50,100],pinnedColumns:V,onPinnedColumnsChange:ie,pinnedRows:te,getDetailPanelContent:ce,getDetailPanelHeight:oe,detailPanelExpandedRowIds:de,onDetailPanelExpandedRowIdsChange:X,pinCheckboxColumn:ne=!0,pinExpandColumn:se=!0,disableColumnReorder:Y=!1,columnOrder:H,onColumnOrderChange:R,onColumnOrderModelChange:ae,rowReordering:ge=!1,onRowOrderChange:J,treeData:O=!1,getTreeDataPath:A,defaultGroupingExpansionDepth:G,groupingColDef:D,rowGroupingModel:U,onRowGroupingModelChange:q,aggregationModel:ee,onAggregationModelChange:Z,getAggregationPosition:j,isCellEditable:re,processRowUpdate:me,onProcessRowUpdateError:pe,dataSource:K,multiSort:fe=!1,sortingMode:we="client",filterMode:le="client",paginationMode:be="client",rowCount:Ce,slots:ye,slotProps:ue,pivotMode:ke=!1,pivotModel:Ae,onPivotModelChange:Le,onRowsScrollEnd:Me,initialState:Ie,onStateChange:Pe,columnVisibilityModel:he,onColumnVisibilityModelChange:ve,listView:_e=!1,listViewColumn:xe,columnGroupingModel:Ne,noRowsLabel:ze="No Data",localeText:je,apiRef:Mt,overscanRowCount:It=3,aiAssistant:Be,onAiAssistantApply:to,onAiAssistantError:br}=e,xr=np(n),jh=je?.noRowsLabel??ze,Nt=Cc({initialState:Ie,sortModel:v,onSortModelChange:W,filterModel:N,onFilterModelChange:T,aggregationModel:ee,onAggregationModelChange:Z,rowGroupingModel:U,onRowGroupingModelChange:q,columnVisibilityModel:he,onColumnVisibilityModelChange:ve,pinnedColumns:V,onPinnedColumnsChange:ie,pivotModel:Ae,onPivotModelChange:Le,paginationModel:Q,onPaginationModelChange:$,pageSizeOptions:z,rowSelectionModel:S,onRowSelectionModelChange:F,density:g,cellSelectionModel:_,onCellSelectionModelChange:I}),{sortModel:pt,handleSortModelChange:qh,filterModel:Lt,handleFilterModelChange:Ws,aggregationModel:rt,handleAggregationModelChange:Xh,columnVisibilityModel:Pt,handleColumnVisibilityModelChange:yr,pinnedColumns:Cr,handlePinnedColumnsChange:Yh,currentPivotModel:Vs,handlePivotModelChange:Jh,effectivePaginationModel:it,handlePaginationModelChange:vr,selectedRowIds:Zh,handleRowSelectionModelChange:Qh,density:zs,rowGroupingModel:Ks}=Nt,wn=_f({rows:t,columns:xr,pivotMode:ke,pivotModel:Vs,filterModel:Lt,sortModel:pt,hasDataSource:!!K,hierarchyRequested:O||Ks.length>0}),ht=wn.isActive,Sr=c&&!ht,{rowReordering:bn,hierarchyRowGroupingModel:em,isTreeDataRequested:tm,isTreeData:no,isRowGrouping:Jt,isHierarchyEnabled:oo,hasGroupingColumn:nm,pagination:mt,listView:_r}=wc({rowGroupingModel:Ks,treeData:O,hasTreeDataPath:!!A,isPivotActive:ht,rowReordering:ge,hasGroupingColDef:!!D,pagination:B,paginationMode:be,listView:_e,hasListViewColumn:!!xe}),{rowHeight:Tt,headerHeight:Rs}=Ec({rowHeight:r,headerHeight:i,density:zs}),om=wn.rows,rm=wn.columns,{activeColumns:wt,effectivePinnedColumns:kr}=Xg({baseColumns:rm,pinnedColumns:Cr,hasGroupingColumn:nm,groupingColDef:D,isTreeData:no,getTreeDataPath:A}),Er=id(wt,Pt),[im,lm]=Cf(rt),At=s.useRef(null),xn=s.useRef(null),Us=!ht&&o||Yg,Mr=cp(At),Ir=dd({rows:om,getRowId:Us,columns:wt,rowHeight:Tt,headerHeight:Rs,columnVisibilityModel:Pt,initialState:e.initialState,syncRows:!K}),{state:De,apiRef:yn,setRows:sm,replaceRows:am,setColumns:cm,setDimensions:dm,setDataSourceLoading:um,setDataSourceError:fm,setRowCount:gm}=Ir,{getRowIdOf:$e,getRowIdOfInEvents:pm}=Jg(De.rows.idByRow);Zg(Mt,yn);const hm=De.dataSource.loading,Nr=f||hm,ro=De.rows.rows,{treeDataHandlers:io,rowGroupingHandlers:Lr,activeHierarchyHandlers:Zt,rowMetaMap:qe}=Id({rows:ro,getRowId:$e,getTreeDataPath:A,isTreeDataRequested:tm,isTreeData:no,columns:wt,rowGroupingModel:em,isRowGrouping:Jt,aggregationModel:rt,defaultGroupingExpansionDepth:G,filterModel:Lt,sortModel:pt,getAggregationPosition:j,columnLookup:Er,filterMode:le,sortingMode:we}),{editCommitChannel:mm,batchEdit:wm,editingHandlers:Pr}=af({rowsLookup:De.rows.idRowsLookup,rows:ro,getRowId:$e,columns:wt,processRowUpdate:me,onProcessRowUpdateError:pe,replaceRows:am}),Tr=Yc({selectedRowIds:Zh,rowsLookup:De.rows.idRowsLookup,rowMetaMap:qe,enabled:!K&&!ht&&be==="client"&&le==="client",onSelectionModelChange:Qh}),js=bf({dataSource:K,sortModel:pt,filterModel:Lt,paginationModel:it,paginationMode:be,sortingMode:we,filterMode:le,aggregationModel:rt,rowGroupingActive:Jt,getRowId:Us,setRows:sm,setRowCount:gm,setDataSourceLoading:um,setDataSourceError:fm,onAggregationResults:lm,onPaginationModelChange:vr});yf({enabled:no&&!!K,treeNodes:io.treeNodes,isGroupExpanded:io.isGroupExpanded,getNodePath:io.getNodePath,toggleExpansion:io.toggleExpansion,fetchChildren:js.fetchChildren});const{hasDetailPanel:Cn,expandedRowIds:Ar,handleDetailPanelToggle:qs,detailPanelHeights:bm,reportDetailPanelHeight:xm}=Bc({hasDetailPanel:!!ce,controlledExpandedRowIds:de,onDetailPanelExpandedRowIdsChange:X,rowMetaMap:qe}),{effectiveColumns:Xs,hierarchyField:Fr,orderedColumns:Or,visibleOrderedColumns:Ys,renderOrderedColumns:ym,navigationColumns:lo,columnIndexMap:Dr,columnWidths:$r,effectiveColumnOrder:Cm,columnReorderHandlers:vm,moveColumn:Js,resetColumnOrder:Zs,handleColumnResize:Qs}=Gc({activeColumns:wt,isHierarchyEnabled:oo,isRowGrouping:Jt,isTreeData:no,activeHierarchyHandlers:Zt,columnVisibilityModel:Pt,columnOrder:H,onColumnOrderChange:R,onColumnOrderModelChange:ae,disableColumnReorder:Y,pivotMode:ht,checkboxSelection:w,hasDetailPanel:Cn,rowReordering:bn,initialState:Ie,setColumns:cm,pinnedColumns:kr,getRowId:pm,aggregationModel:rt,groupingRows:Jt?Lr.groupingRows:void 0});zc({onStateChange:Pe,sortModel:pt,filterModel:Lt,effectivePaginationModel:it,columnWidths:$r,effectiveColumnOrder:Cm,columnVisibilityModel:Pt,pinnedColumns:Cr,density:zs});const Gr=Ic({effectiveRows:ro,activeHierarchyHandlers:Zt,filterMode:le,filterModel:wn.pipelineFilterModel,sortModel:wn.pipelineSortModel,sortingMode:we,pagination:mt,paginationMode:be,effectivePaginationModel:it,pinnedRows:te,getRowId:$e,columnLookup:Er,hierarchyField:Fr}),{filteredRows:ea,dataRows:so,pinnedTopRows:Ke,pinnedBottomRows:lt,sortedUnpinnedRows:bt,paginatedUnpinnedRows:ao,allRenderableRows:vn}=Gr,Hr=mt?ao:bt;ld({paginationModel:it,currentPage:Gr.currentPage,enabled:mt&&!Nr&&bt.length>0,onPaginationModelChange:vr});const ta=Mc({paginationMode:be,hasDataSource:!!K,dataSourceRowCount:De.pagination.rowCount,rowCountProp:Ce,clientRowCount:bt.length}),{rowSelection:na,handleRowClick:oa,handleSelectionChange:ra}=rd({controlledState:Nt,interactions:{dataRows:so,getRowId:$e,isPivotActive:ht,disableRowSelectionOnClick:b,isHierarchyEnabled:oo,rowMetaMap:qe,activeHierarchyHandlers:Zt,onRowClick:P},api:{apiRef:Ir.apiRef,multiSort:fe,selectedRowIds:Tr,disableMultipleRowSelection:m,isSyntheticRowId:Wr=>Re(Wr,qe),getVisibleRows:()=>[...Ke,...Hr,...lt],getAllFilteredRows:()=>Qg({hierarchyHandlers:Zt,pinnedTopRows:Ke,sortedUnpinnedRows:bt,pinnedBottomRows:lt,rowMetaMap:qe,getRowId:$e,hierarchyField:Fr,dataRows:so}),visibleColumns:ym}}),Sm=ud({rows:ro,indexById:De.rows.indexById,onRowOrderChange:J,rowReordering:bn}),{aggregationResult:ia,isLoading:_m}=Gl({rows:so,columns:wt,aggregationModel:ht?La:rt,isServerSide:Pl({dataSource:K,paginationMode:be,sortingMode:we,filterMode:le}),dataSource:K,filterModel:Lt,sortModel:pt,serverAggregationResults:im}),Br=Object.keys(rt).length>0&&!ht;rp({apiRef:yn,hasAggregation:Br,aggregationResult:ia,aggregationModel:rt,isRowGrouping:Jt,rowGroupingHandlers:Lr,rowMetaMap:qe,columns:wt,getRowId:$e,hierarchyField:Fr});const Ge=Ia({rowHeight:Tt,pagination:mt,paginatedUnpinnedRows:ao,sortedUnpinnedRows:bt,expandedRowIds:Ar,getDetailPanelHeight:oe,detailPanelHeights:bm,pinnedTopRowsLength:Ke.length,pinnedBottomRowsLength:lt.length,pinnedTopRows:Ke,pinnedBottomRows:lt,visibleOrderedColumns:Ys,pinnedColumns:kr,columnWidths:$r,viewportWidth:De.dimensions.viewportWidth||1e3,checkboxSelection:w,hasDetailPanel:Cn,rowReordering:bn,pinCheckboxColumn:ne,pinExpandColumn:se,paginationMode:be,isLoading:De.dataSource.loading,pageSize:it.pageSize,getRowId:$e}),Sn=ff({pinnedTopRows:Ke,centerRows:Hr,pinnedBottomRows:lt,columns:Ys,leftPinnedColumns:Ge.leftPinnedCols,unpinnedColumns:Ge.unpinnedColsWithWidth,rightPinnedColumns:Ge.rightPinnedCols,expandedRowIds:Cn?Ar:void 0,rowMetaMap:qe,getRowId:$e}),la=s.useMemo(()=>[...Ge.leftPinnedCols,...Ge.unpinnedColsWithWidth,...Ge.rightPinnedCols],[Ge.leftPinnedCols,Ge.unpinnedColsWithWidth,Ge.rightPinnedCols]),_n=ap({enabled:E&&!_r,model:Nt.cellSelectionModel,onModelChange:Nt.handleCellSelectionModelChange,getPendingModel:Nt.getPendingCellSelectionModel,allRenderableRows:vn,getRowId:$e,navigationColumns:lo,columnIndexMap:Dr,spanning:Sn,rowMetaMap:qe,layout:Ge,rowHeight:Tt,pinnedTopRowCount:Ke.length,viewportRef:xn,containerRef:At,localeText:je,showStats:M}),km=rf({apiRef:yn,containerRef:At,viewportRef:xn,copyColumns:la,getRowId:$e,disableClipboardCopy:C,getCellRangeCopyText:_n.enabled?_n.getCopyText:void 0,layout:Ge,rowHeight:Tt,orderedColumns:Or,onColumnResize:Qs}),{handleScroll:Em,setViewportElement:Mm,maxContentHeight:Im,virtualization:Ft}=Ju({viewport:{onRowsScrollEnd:Me,overscanRowCount:It,autoHeight:u,setDimensions:dm},viewportRef:xn,containerRef:At,layout:Ge,viewportWidth:De.dimensions.viewportWidth,viewportHeight:De.dimensions.viewportHeight,virtualization:{autoHeight:u,rowReordering:bn,hasDetailPanel:Cn,checkboxSelection:w,pinCheckboxColumn:ne,pinExpandColumn:se}}),{handleSort:sa,handleSortAdd:aa}=td({sortModel:pt,onSortModelChange:qh}),ca=w||!b,{focusedCell:da,setFocusedCell:ua,viewportTabIndex:Nm,ensureGridFocus:Lm,handleFocus:Pm,handleBlur:Tm,handleKeyDown:Am,handleMouseDownCapture:Fm}=mc({allRenderableRows:vn,navigationColumns:lo,checkboxSelection:w,selectedRowIds:Tr,handleSelectionChange:ra,handleDetailPanelToggle:qs,editingHandlers:Pr,setKeyboardMode:Mr,sortModel:pt,handleSort:sa,handleSortAdd:aa,multiSort:fe,isCellEditable:re,pagination:mt,pageSize:it.pageSize,virtualization:Ft,viewportRef:xn,pinnedTopRowCount:Ke.length,getRowId:$e,rowMetaMap:qe,getSpanOrigin:Sn.getSpanOrigin,onRowActivate:oa,toggleRowExpansion:Zt?.toggleExpansion,handleSelectAll:na.selectAll,rowSelectionEnabled:ca,multipleRowSelectionEnabled:!m,pinCheckboxColumn:ne,pinExpandColumn:se,rowHeight:Tt,cellSelection:_n.keyboard,headerFilters:Sr}),{handleCellClick:Om,handleHeaderClick:Dm}=dp({ensureGridFocus:Lm,setKeyboardMode:Mr,setFocusedCell:ua,getRowId:$e,onCellClick:k}),$m=zu({props:e,apiRef:yn,containerRef:At,viewportRef:xn,selection:_n,model:Nt.cellSelectionModel,getPendingModel:Nt.getPendingCellSelectionModel,focusedCell:da,setFocusedCell:ua,allRenderableRows:vn,getRowId:$e,navigationColumns:lo,columnIndexMap:Dr,isCellEditable:re,rowMetaMap:qe,getSpanOrigin:Sn.getSpanOrigin,isEditing:Pr.editingCell!==null,batchEdit:wm,channel:mm,layout:Ge,rowHeight:Tt,pinnedTopRowCount:Ke.length}),{handleHideColumn:Gm,handlePinColumn:Hm}=nd({columnVisibilityModel:Pt,onColumnVisibilityModelChange:yr,pinnedColumns:Cr,onPinnedColumnsChange:Yh}),{ariaRows:Bm,spanRowWindow:Wm,visibleRows:fa,renderColumns:Vm}=Dd({aria:{columnGroupingModel:Ne,headerFilterRow:Sr,pinnedTopCount:Ke.length,pinnedBottomCount:lt.length,pagination:mt,paginationMode:be,paginationModel:it,paginationRowCount:ta,paginatedUnpinnedRowCount:ao.length,sortedUnpinnedRowCount:bt.length},spanning:Sn,virtualization:Ft,layout:Ge,pinnedTopRows:Ke,pinnedBottomRows:lt,paginatedUnpinnedRows:ao,sortedUnpinnedRows:bt,pagination:mt,getRowId:$e});jc({paginationRequested:B,isRowGrouping:Jt,autoHeight:u,viewportHeight:De.dimensions.viewportHeight,renderedRowCount:fa.length,totalRowCount:Ke.length+Hr.length+lt.length,pinnedRowsIgnored:oo&&!!(te?.top?.length||te?.bottom?.length),scrollHeight:Ft.totalHeight,maxContentHeight:Im,reachableRowCount:Pc(Ft.cumulativeHeights,Ft.virtualContainerHeight),unpinnedRowCount:Ft.cumulativeHeights.length,listViewWithoutColumn:_e&&!xe,listViewRowCount:_r&&xe?vn.length:0});const zm=pf(Ne,vm),Km=s.useMemo(()=>Xs.some(Wr=>!!Wr.rowSpan),[Xs]),{columnsPanel:Rm,aiAssistantPanel:Um,toolbarProps:jm}=Np({apiRef:yn,containerRef:At,localeText:je,aiAssistant:{options:Be,columns:wt,onApply:to,onError:br},toolbar:{toolbar:ye?.toolbar,toolbarSlotProps:ue?.toolbar,orderedColumns:Or,baseColumns:xr,aggregationModel:rt,onAggregationModelChange:Xh,pivotMode:ke,pivotModelProp:Ae,onPivotModelChangeProp:Le,pivotModel:Vs,onPivotModelChange:Jh,filterModel:Lt,onFilterModelChange:Ws,columnVisibilityModel:Pt,onColumnVisibilityModelChange:yr,disableColumnReorder:Y,columnGroupingModel:Ne,moveColumn:Js,resetColumnOrder:Zs}}),qm={setViewportElement:Mm,handleScroll:Em,ariaLabel:h,ariaRows:Bm,navigationColumnCount:lo.length,rowSelectionEnabled:ca,disableMultipleRowSelection:m,cellSelection:_n,effectiveLoading:Nr,viewportTabIndex:Nm,setKeyboardMode:Mr,handleMouseDownCapture:Fm,handleKeyDown:Am,handleFocus:Pm,handleBlur:Tm,effectivePinnedColumns:kr,virtualization:Ft,renderColumns:Vm,renderedDataColumns:la,columnGroupingModel:Ne,checkboxSelection:w,rowSelection:na,sortModel:pt,handleSort:sa,handleSortAdd:aa,multiSort:fe,handleColumnResize:Qs,handleColumnAutosize:km,columnWidths:$r,focusedCell:da,columnIndexMap:Dr,handleHeaderClick:Dm,headerReorderHandlers:zm,rowReordering:bn,hasDetailPanel:Cn,pinCheckboxColumn:ne,pinExpandColumn:se,aggregationModel:rt,handleHideColumn:Gm,columnsPanel:Rm,handlePinColumn:Hm,wrapHeaderText:l,headerHeight:Rs,showHeaderFilters:Sr,filterModel:Lt,handleFilterModelChange:Ws,localeText:je,editingHandlers:Pr,isCellEditable:re,selectedRowIds:Tr,handleRowClick:oa,onRowDoubleClick:L,handleCellClick:Om,handleSelectionChange:ra,expandedRowIds:Ar,getDetailPanelContent:ce,getDetailPanelHeight:oe,handleDetailPanelToggle:qs,reportDetailPanelHeight:xm,spanning:Sn,rowMetaMap:qe,fillHandle:$m,pinnedTopRows:Ke,pinnedBottomRows:lt,pinnedRows:te,getRowIdOf:$e,showEmptyState:!Nr&&!De.dataSource.error&&ea.length===0,effectiveNoRowsLabel:jh,spanRowWindow:Wm,visibleRows:fa,baseColumns:xr,viewportWidth:De.dimensions.viewportWidth,rowReorderHandlers:Sm,paginationMode:be,dataSourceLoading:De.dataSource.loading,sortedUnpinnedRowCount:bt.length,pageSize:it.pageSize,unpinnedRowsLength:Ge.unpinnedRowsLength,showAggregationFooter:Br&&Lr.rootAggregationPosition!==null,aggregationResult:ia,effectiveRowHeight:Tt,isAggregationLoading:_m,containerRef:At,className:x,autoHeight:u,height:p,style:y,hasRowSpanning:Km,listView:_r,headerFilterHeight:a,slots:ye,slotProps:ue,toolbarProps:jm,aiAssistantPanel:Um,orderedColumns:Or,columnVisibilityModel:Pt,disableColumnReorder:Y,handleColumnVisibilityModelChange:yr,moveColumn:Js,resetColumnOrder:Zs,listViewColumn:xe,allRenderableRows:vn,dataRows:so,pagination:mt,effectivePaginationModel:it,currentPage:Gr.currentPage,pageSizeOptions:z,columnsByField:Er.byField,paginationRowCount:ta,handlePaginationModelChange:vr,onRowsScrollEnd:Me,toggleExpansion:Zt?.toggleExpansion,showCellSelectionStats:M,apiRef:Ir.apiRef,hasAggregation:Br,isHierarchyEnabled:oo,dataSourceError:De.dataSource.error,filteredRowCount:ea.length,onRetry:K?js.fetchRows:void 0};return d.jsx(qg,{...qm})}function Pp({rows:e=5,columns:t=5}){return d.jsx("div",{className:"ogx__skeleton",children:Array.from({length:e}).map((n,o)=>d.jsx("div",{className:"ogx__skeleton-row",children:Array.from({length:t}).map((r,i)=>d.jsx("div",{className:"ogx__skeleton-cell",children:d.jsx("div",{className:"ogx__skeleton-content"})},i))},o))})}const Tp=300;function jt(e){return"field"in e&&!("items"in e)}function ms(e,t){return e.find(n=>jt(n)&&n.field===t)}function Ap(e,t){return e===t?!0:jt(e)&&jt(t)?e.id===t.id&&e.field===t.field&&e.operator===t.operator&&ar(e.value,t.value):!jt(e)&&!jt(t)?e.id===t.id&&e.logicOperator===t.logicOperator&&mr(e.items,t.items):!1}function mr(e,t){return e===t?!0:e.length===t.length&&e.every((n,o)=>Ap(n,t[o]))}function ws(e,t){return Eo(e,t.type)}function Fp(e,t){if(!Dt.has(t))return t==="isAnyOf"?e==null||e===""?[]:Array.isArray(e)?e:[e]:Array.isArray(e)?e.length>0?e[0]:"":e??""}const Op=({col:e,item:t,resetToken:n,onChange:o})=>{const r=s.useId(),i=s.useMemo(()=>ii(e.type),[e.type]),l=i[0],c=t?.operator??l,a=i.includes(c)?i:[c,...i],u=!!t,g=e.headerName||e.field,[p,x]=s.useState(null),[y,h]=s.useState(n);y!==n&&(h(n),x(null));const f=s.useRef(o),w=s.useRef(t),b=s.useRef(e);s.useLayoutEffect(()=>{f.current=o,w.current=t,b.current=e});const m=s.useCallback((N,T)=>({id:w.current?.id??`${e.field}-${Date.now()}`,field:e.field,operator:N,value:T}),[e.field]),C=s.useCallback(N=>{const T=w.current;if(T?N===ws(T.value,b.current):N.trim()==="")return;const W=T?.operator??l;f.current(m(W,jn(N,W)))},[l,m]),E=s.useRef(null),_=s.useRef(C);s.useLayoutEffect(()=>{E.current=p,_.current=C}),s.useEffect(()=>()=>{const N=E.current;E.current=null,N!==null&&_.current(N)},[]),s.useEffect(()=>{if(p===null)return;const N=setTimeout(()=>{E.current=null,C(p),x(null)},Tp);return()=>clearTimeout(N)},[p,C]);const I=N=>{const T=p!==null?jn(p,N):t?.value;x(null),o(m(N,Fp(T,N)))},M=()=>{x(null),o(null)},S=!Dt.has(c),F=Xl(e),P=`ogx-filter__value-input${u?" ogx-filter__value-input--active":""}`,L=`Filter value for ${g}`;let k=null;if(S&&e.type==="boolean")k=d.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${P} ogx-filter__value-select`,value:t?.value==null?"":String(t.value),onChange:N=>{N.target.value===""?o(null):o(m(c,N.target.value))},"aria-label":L,children:[d.jsx("option",{value:"",children:"Any"}),d.jsx("option",{value:"true",children:"true"}),d.jsx("option",{value:"false",children:"false"})]});else if(S&&e.type==="singleSelect"&&F.length>0&&c==="isAnyOf"){const N=Array.isArray(t?.value)?t.value:t?.value==null||t.value===""?[]:[t.value];k=d.jsx("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${P} ogx-filter__value-multiselect`,multiple:!0,size:Math.min(F.length,4),value:F.filter(T=>N.some(v=>sr(T,v))).map(T=>T.key),onChange:T=>{const v=new Set(Array.from(T.target.selectedOptions,W=>W.value));o(m("isAnyOf",F.filter(W=>v.has(W.key)).map(W=>W.value)))},"aria-label":L,children:F.map(T=>d.jsx("option",{value:T.key,children:T.label},T.key))})}else if(S&&e.type==="singleSelect"&&F.length>0&&(c==="is"||c==="not")){const N=F.find(T=>sr(T,t?.value));k=d.jsxs("select",{id:`${r}-val`,name:`filter-val-${e.field}`,className:`${P} ogx-filter__value-select`,value:N?.key??"",onChange:T=>{const v=F.find(W=>W.key===T.target.value);o(m(c,v?v.value:""))},"aria-label":L,children:[d.jsx("option",{value:"",children:"Any"}),F.map(T=>d.jsx("option",{value:T.key,children:T.label},T.key))]})}else S&&(k=d.jsx(et,{id:`${r}-val`,name:`filter-val-${e.field}`,inputClassName:P,type:e.type==="date"?"date":"text",value:p??ws(t?.value,e),onChange:N=>x(N.target.value),placeholder:e.type==="number"?"Number…":"Value…","aria-label":L}));return d.jsxs("div",{className:`ogx-filter__row${u?" ogx-filter__row--active":""}`,children:[d.jsx("span",{className:"ogx-filter__col-label",title:e.field,children:g}),d.jsxs("div",{className:"ogx-filter__controls",children:[d.jsx("select",{id:`${r}-op`,name:`filter-op-${e.field}`,className:`ogx-filter__op-select${u?" ogx-filter__op-select--active":""}`,value:c,onChange:N=>I(N.target.value),"aria-label":`Filter operator for ${g}`,children:a.map(N=>d.jsx("option",{value:N,children:N},N))}),k,u&&d.jsx("button",{type:"button",className:"ogx-filter__row-clear",onClick:M,"aria-label":`Clear filter for ${g}`,title:"Clear",children:"×"})]})]})},bs=({filterModel:e,columns:t,onFilterModelChange:n})=>{const o=s.useMemo(()=>e.items??[],[e.items]),r=e.logicOperator??"and",[i,l]=s.useState(null),[c,a]=s.useState(o),[u,g]=s.useState(0);if(c!==o){a(o);const w=!mr(c,o),b=i!==null&&mr(i,o);w&&!b&&g(m=>m+1)}const p=s.useCallback((w,b)=>{const m=o.findIndex(E=>jt(E)&&E.field===w);let C;if(m===-1){if(!b)return;C=[...o,b]}else b?C=o.map((E,_)=>_===m?b:E):C=o.filter((E,_)=>_!==m);l(C),n({...e,items:C})},[o,e,n]),x=s.useCallback(w=>{n({...e,logicOperator:w})},[e,n]),y=t.filter(w=>w.filterable!==!1),h=y.filter(w=>ms(o,w.field)).length,f=o.length-h;return d.jsxs(d.Fragment,{children:[o.length>1&&d.jsxs("div",{className:"ogx-filter__logic-bar",children:[d.jsx("span",{className:"ogx-filter__logic-label",children:"Match:"}),d.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="and"?" ogx-filter__logic-pill--active":""}`,onClick:()=>x("and"),"aria-pressed":r==="and",children:"ALL (AND)"}),d.jsx("button",{type:"button",className:`ogx-filter__logic-pill${r==="or"?" ogx-filter__logic-pill--active":""}`,onClick:()=>x("or"),"aria-pressed":r==="or",children:"ANY (OR)"})]}),f>0&&d.jsx("div",{className:"ogx-filter__hidden-note",role:"note",children:f===1?"1 more condition (a filter group or a second condition on a column) is applied and not shown here.":`${f} more conditions (filter groups or further conditions on a column) are applied and not shown here.`}),y.length===0?d.jsx("div",{className:"ogx-filter__empty",children:"No filterable columns."}):y.map(w=>d.jsx(Op,{col:w,item:ms(o,w.field),resetToken:u,onChange:b=>p(w.field,b)},w.field))]})},xs=["sum","avg","count","min","max"];function ys(){return d.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:[d.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),d.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),d.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),d.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1",fill:"currentColor",opacity:"0.25"}),d.jsx("path",{d:"M17 14v-4M17 10l-2 2 2 2"})]})}function Dp({anchorRef:e,columns:t,model:n,onChange:o,onClose:r}){const i=s.useRef(null),[l,c]=s.useState({top:0,right:0}),[a,u]=s.useState(null);s.useLayoutEffect(()=>{u(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const g=s.useCallback(()=>In(e.current,Et()),[e]);s.useEffect(()=>{c(g());const v=()=>c(g());return window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[g]),s.useEffect(()=>{function v(B){i.current&&!i.current.contains(B.target)&&e.current&&!e.current.contains(B.target)&&r()}function W(B){B.key==="Escape"&&r()}return document.addEventListener("mousedown",v),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",W)}},[e,r]);const p=new Set(n.rowFields),x=new Set(n.columnFields),y=new Set(n.valueFields.map(v=>v.field)),h=v=>p.has(v)||x.has(v)||y.has(v),f=v=>t.find(W=>W.field===v),w=v=>f(v)?.headerName??v,b=v=>{const W=f(v)?.availableAggregationFunctions;return W?xs.filter(B=>W.includes(B)):xs},m=v=>v.aggregable!==!1&&(v.type==="number"||v.aggregable===!0)&&b(v.field).length>0,C=v=>v.groupable!==!1;function E(v){p.has(v)||o({...n,rowFields:[...n.rowFields,v]})}function _(v){x.has(v)||o({...n,columnFields:[...n.columnFields,v]})}function I(v){y.has(v)||o({...n,valueFields:[...n.valueFields,{field:v,aggFn:b(v)[0]??"sum"}]})}function M(v){o({...n,rowFields:n.rowFields.filter((W,B)=>B!==v)})}function S(v){o({...n,columnFields:n.columnFields.filter((W,B)=>B!==v)})}function F(v){o({...n,valueFields:n.valueFields.filter((W,B)=>B!==v)})}function P(v,W){o({...n,valueFields:n.valueFields.map((B,Q)=>Q===v?{...B,aggFn:W}:B)})}function L(){o({rowFields:[],columnFields:[],valueFields:[]})}const k=n.rowFields.length+n.columnFields.length+n.valueFields.length,N=t.filter(v=>!h(v.field)&&(C(v)||m(v))),T=d.jsxs("div",{ref:i,className:"ogx-pivot-panel",role:"dialog","aria-label":"Pivot configuration",style:{top:l.top,right:l.right,left:l.left},children:[d.jsxs("div",{className:"ogx-pivot-panel__header",children:[d.jsxs("span",{className:"ogx-pivot-panel__title",children:[d.jsx(ys,{}),"Pivot Mode"]}),k>0&&d.jsx("button",{type:"button",className:"ogx-pivot-panel__reset-btn",onClick:L,title:"Reset pivot",children:"Reset"})]}),d.jsxs("div",{className:"ogx-pivot-panel__body",children:[d.jsxs("div",{className:"ogx-pivot-zone",children:[d.jsxs("span",{className:"ogx-pivot-zone__label",children:[d.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--row"}),"Row Fields"]}),d.jsx("div",{className:`ogx-pivot-chips${n.rowFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — each becomes a row label",children:n.rowFields.map((v,W)=>d.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--row",children:[w(v),d.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>M(W),title:`Remove ${w(v)}`,"aria-label":`Remove ${w(v)} from Row Fields`,children:"×"})]},`${W}:${v}`))})]}),d.jsxs("div",{className:"ogx-pivot-zone",children:[d.jsxs("span",{className:"ogx-pivot-zone__label",children:[d.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--col"}),"Column Fields"]}),d.jsx("div",{className:`ogx-pivot-chips${n.columnFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add fields here — unique values become column headers",children:n.columnFields.map((v,W)=>d.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--col",children:[w(v),d.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>S(W),title:`Remove ${w(v)}`,"aria-label":`Remove ${w(v)} from Column Fields`,children:"×"})]},`${W}:${v}`))})]}),d.jsxs("div",{className:"ogx-pivot-zone",children:[d.jsxs("span",{className:"ogx-pivot-zone__label",children:[d.jsx("span",{className:"ogx-pivot-zone__dot ogx-pivot-zone__dot--value"}),"Value Fields (aggregated)"]}),d.jsx("div",{className:`ogx-pivot-chips${n.valueFields.length===0?" ogx-pivot-chips--empty":""}`,"data-placeholder":"Add numeric fields here — values are aggregated",children:n.valueFields.map((v,W)=>{const B=b(v.field),Q=B.includes(v.aggFn)?B:[v.aggFn,...B];return d.jsxs("span",{className:"ogx-pivot-chip ogx-pivot-chip--value",children:[w(v.field),d.jsx("select",{className:"ogx-pivot-chip__fn-select",value:v.aggFn,onChange:$=>P(W,$.target.value),title:"Aggregation function","aria-label":`Aggregation function for ${w(v.field)}`,children:Q.map($=>d.jsx("option",{value:$,children:$.toUpperCase()},$))}),d.jsx("button",{type:"button",className:"ogx-pivot-chip__remove",onClick:()=>F(W),title:`Remove ${w(v.field)}`,"aria-label":`Remove ${w(v.field)} (${v.aggFn.toUpperCase()}) from Value Fields`,children:"×"})]},`${W}:${v.field}:${v.aggFn}`)})})]}),d.jsx("hr",{className:"ogx-pivot-panel__divider"}),d.jsxs("div",{children:[d.jsx("div",{className:"ogx-pivot-panel__fields-label",children:"Available Fields"}),d.jsxs("div",{className:"ogx-pivot-fields",children:[N.map(v=>{const W=m(v),B=C(v),Q=v.headerName??v.field;return d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[d.jsx("span",{className:`ogx-pivot-field-btn${W?" ogx-pivot-field-btn--numeric":""}`,children:Q}),d.jsxs("div",{className:"ogx-pivot-field-actions",children:[B&&d.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--row",onClick:()=>E(v.field),title:"Add to Row Fields","aria-label":`Add ${Q} to Row Fields`,children:"Row"}),B&&d.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--col",onClick:()=>_(v.field),title:"Add to Column Fields","aria-label":`Add ${Q} to Column Fields`,children:"Col"}),W&&d.jsx("button",{type:"button",className:"ogx-pivot-add-btn ogx-pivot-add-btn--value",onClick:()=>I(v.field),title:"Add to Value Fields","aria-label":`Add ${Q} to Value Fields`,children:"Val"})]})]},v.field)}),N.length===0&&d.jsx("span",{style:{fontSize:12,color:"var(--ogx-color-gray-400, #94a3b8)"},children:"All fields are in use."})]})]})]})]});return a?st.createPortal(T,a):null}function $p(){return d.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("circle",{cx:"11",cy:"11",r:"8"}),d.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Gp(){return d.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Cs(e){return e.trim().split(/\s+/).filter(Boolean).join(" ")}function Hp({value:e="",onChange:t,placeholder:n="Search...",debounceMs:o=250}){const[r,i]=s.useState(()=>e.length>0),[l,c]=s.useState(e),a=s.useRef(null),u=s.useRef(null),g=s.useRef(t);s.useLayoutEffect(()=>{g.current=t},[t]);const p=s.useRef(e),x=s.useRef(e);s.useEffect(()=>{e!==x.current&&(x.current=e,Cs(e)!==Cs(p.current)&&(c(e),p.current=e,i(e.length>0)))},[e]),s.useEffect(()=>{const m=setTimeout(()=>{l!==p.current&&(p.current=l,g.current(l))},o);return()=>clearTimeout(m)},[l,o]);const y=s.useRef(l);s.useLayoutEffect(()=>{y.current=l}),s.useEffect(()=>()=>{const m=y.current;m!==p.current&&(p.current=m,g.current(m))},[]);const h=s.useCallback(()=>{i(!0),requestAnimationFrame(()=>a.current?.focus())},[]),f=s.useCallback(m=>{m.stopPropagation(),c(""),p.current="",g.current(""),a.current?.focus()},[]),w=s.useCallback(()=>{i(!0)},[]),b=s.useCallback(()=>{setTimeout(()=>{u.current&&document.activeElement&&u.current.contains(document.activeElement)||l||i(!1)},150)},[l]);return s.useEffect(()=>{const m=C=>{u.current&&!u.current.contains(C.target)&&(l||i(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[l]),d.jsxs("div",{ref:u,className:`ogx-global-search${r?" ogx-global-search--expanded":""}`,onClick:r?void 0:h,children:[d.jsx("div",{className:"ogx-global-search__icon-wrapper",children:d.jsx($p,{})}),d.jsx(et,{ref:a,inputClassName:"ogx-global-search__input",value:l,onChange:m=>c(m.target.value),onFocus:w,onBlur:b,placeholder:n,"aria-label":"Global Search",autoComplete:"off"}),l&&d.jsx("button",{type:"button",className:"ogx-global-search__clear",onClick:f,"aria-label":"Clear search",children:d.jsx(Gp,{})})]})}const Zn=8;function pn({title:e,children:t,placement:n="top",enterDelay:o=200,leaveDelay:r=0}){const[i,l]=s.useState(!1),[c,a]=s.useState({top:0,left:0}),[u,g]=s.useState(null),p=s.useRef(null),x=s.useRef(null),y=s.useId(),h=s.useCallback(()=>{if(!x.current)return;const _=x.current.getBoundingClientRect(),I=_.left+_.width/2,M=_.top+_.height/2;switch(n){case"bottom":a({top:_.bottom+Zn,left:I});break;case"left":a({top:M,left:_.left-Zn});break;case"right":a({top:M,left:_.right+Zn});break;default:a({top:_.top-Zn,left:I})}},[n]),f=s.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null},[]);s.useLayoutEffect(()=>{if(!i)return;h();const _=I=>{I.key==="Escape"&&(f(),l(!1))};return window.addEventListener("scroll",h,!0),window.addEventListener("resize",h),document.addEventListener("keydown",_),()=>{window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h),document.removeEventListener("keydown",_)}},[i,h,f]),s.useEffect(()=>f,[f]);const w=()=>{f(),p.current=setTimeout(()=>{g(x.current?.closest(".ogx-theme-provider")??document.body),l(!0)},o)},b=()=>{f(),p.current=setTimeout(()=>{l(!1)},r)},m=s.useCallback(_=>{x.current=_?_.firstElementChild??_:null},[]),C=i&&!!e&&u!==null;let E=t;if(C&&s.isValidElement(t)){const _=t,I=_.props["aria-describedby"];E=s.cloneElement(_,{"aria-describedby":I?`${I} ${y}`:y})}return d.jsxs(d.Fragment,{children:[d.jsx("span",{ref:m,style:{display:"inline-block",lineHeight:0},onMouseEnter:w,onMouseLeave:b,onFocus:w,onBlur:b,children:E}),C&&u&&st.createPortal(d.jsx("div",{id:y,role:"tooltip",className:`ogx-tooltip ogx-tooltip--${n}`,style:{top:c.top,left:c.left,position:"fixed",zIndex:99999},children:e}),u)]})}const Bp=Object.keys(at);function Wp(e){return Object.prototype.hasOwnProperty.call(at,e)}function vs(e){return e.availableAggregationFunctions?Array.from(new Set(e.availableAggregationFunctions.filter(Wp))):Bp}function Ss(){return d.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:d.jsx("path",{d:"M18 4H6l6 8-6 8h12"})})}function Vp(){return d.jsxs("svg",{focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",children:[d.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("rect",{x:"8.5",y:"4",width:"7",height:"16",fill:"currentColor",opacity:"0.25"}),d.jsx("line",{x1:"8.5",y1:"4",x2:"8.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"15.5",y1:"4",x2:"15.5",y2:"20",stroke:"currentColor",strokeWidth:"1.8"}),d.jsx("line",{x1:"2",y1:"9",x2:"22",y2:"9",stroke:"currentColor",strokeWidth:"1.2"}),d.jsx("line",{x1:"2",y1:"14",x2:"22",y2:"14",stroke:"currentColor",strokeWidth:"1.2"})]})}function _s(){return d.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:d.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}function zp({anchorRef:e,aggregationModel:t,aggregableColumns:n,onFunctionChange:o,onClearAll:r,onClose:i,activeCount:l}){const c=s.useRef(null),[a,u]=s.useState({top:0,right:0}),[g,p]=s.useState(null);s.useLayoutEffect(()=>{p(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const x=s.useCallback(()=>In(e.current,Et()),[e]);s.useEffect(()=>{u(x());const h=()=>u(x());return window.addEventListener("scroll",h,!0),window.addEventListener("resize",h),()=>{window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h)}},[x]),s.useEffect(()=>{function h(f){c.current&&!c.current.contains(f.target)&&e.current&&!e.current.contains(f.target)&&i()}return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[e,i]),s.useEffect(()=>{function h(f){f.key==="Escape"&&i()}return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[i]);const y=d.jsxs("div",{ref:c,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Summaries configuration",style:{top:a.top,right:a.right,left:a.left,width:400,maxWidth:"calc(100vw - 24px)"},children:[d.jsxs("div",{className:"ogx-toolbar__panel-header",children:[d.jsxs("span",{className:"ogx-toolbar__panel-title",children:[d.jsx(Ss,{}),"Summaries"]}),l>0&&d.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:r,title:"Clear all summaries",children:"Clear all"})]}),d.jsx("div",{className:"ogx-toolbar__panel-body",children:n.length===0?d.jsxs("p",{className:"ogx-toolbar__empty",children:["No aggregable columns.",d.jsx("br",{}),"Set ",d.jsx("code",{children:"aggregable: true"})," on a column to enable."]}):n.map(h=>{const f=t[h.field]||"none";return d.jsxs("div",{className:"ogx-toolbar__agg-row",children:[d.jsx("span",{className:"ogx-toolbar__agg-label",title:h.field,children:h.headerName||h.field}),d.jsx("div",{className:"ogx-toolbar__agg-pills",children:["none",...vs(h)].map(w=>d.jsx("button",{type:"button",className:`ogx-toolbar__pill${f===w?" ogx-toolbar__pill--active":""}`,onClick:()=>o(h.field,w),"aria-pressed":f===w,children:w},w))})]},h.field)})})]});return g?st.createPortal(y,g):null}function Kp({anchorRef:e,columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:c,onClose:a,showNonHideableColumns:u}){const g=s.useRef(null),[p,x]=s.useState({top:0,right:0}),[y,h]=s.useState(null);s.useLayoutEffect(()=>{h(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const f=s.useCallback(()=>In(e.current,Et()),[e]);s.useEffect(()=>{x(f());const b=()=>x(f());return window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[f]),s.useEffect(()=>{function b(m){g.current&&!g.current.contains(m.target)&&e.current&&!e.current.contains(m.target)&&a()}return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[e,a]),s.useEffect(()=>{function b(m){m.key==="Escape"&&a()}return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[a]);const w=d.jsx("div",{ref:g,className:"ogx-toolbar__panel",role:"dialog","aria-label":"Column visibility",style:{top:p.top,right:p.right,left:p.left,width:280,padding:0},children:d.jsx(nr,{columns:t,visibleColumns:n,onVisibilityChange:o,onShowAll:r,onHideAll:i,onColumnReorder:l,onColumnOrderReset:c,showNonHideableColumns:u})});return y?st.createPortal(w,y):null}function Rp({anchorRef:e,columns:t,filterModel:n,onFilterModelChange:o,onClose:r}){const i=s.useRef(null),[l,c]=s.useState({top:0,right:0}),a=s.useRef(r);s.useLayoutEffect(()=>{a.current=r},[r]);const[u,g]=s.useState(null);s.useLayoutEffect(()=>{g(e.current?.closest(".ogx-theme-provider")??document.body)},[e]);const p=s.useCallback(()=>In(e.current,Et()),[e]);s.useEffect(()=>{c(p());const f=()=>c(p());return window.addEventListener("scroll",f,!0),window.addEventListener("resize",f),()=>{window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",f)}},[p]),s.useEffect(()=>{function f(w){w.key==="Escape"&&a.current()}return document.addEventListener("keydown",f),()=>document.removeEventListener("keydown",f)},[]);const x=n.items?.length??0,y=()=>{o({...n,items:[],logicOperator:"and"})},h=d.jsxs("div",{ref:i,className:"ogx-toolbar__panel ogx-toolbar__panel--filter",role:"dialog","aria-label":"Advanced filters",style:{top:l.top,right:l.right,left:l.left,width:540,maxWidth:"calc(100vw - 24px)"},children:[d.jsxs("div",{className:"ogx-toolbar__panel-header",children:[d.jsxs("span",{className:"ogx-toolbar__panel-title",children:[d.jsx(_s,{}),"Filters",x>0&&d.jsx("span",{className:"ogx-toolbar__panel-count",children:x})]}),d.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[x>0&&d.jsx("button",{type:"button",className:"ogx-toolbar__clear-btn",onClick:y,title:"Clear all filters",children:"Clear all"}),d.jsx("button",{type:"button",className:"ogx-toolbar__close-btn",onClick:()=>a.current(),title:"Close filters","aria-label":"Close filters panel",children:"Close"})]})]}),d.jsx("div",{className:"ogx-toolbar__panel-body ogx-toolbar__panel-body--filter",children:d.jsx(bs,{columns:t,filterModel:n,onFilterModelChange:o})})]});return u?st.createPortal(h,u):null}const Up={rowFields:[],columnFields:[],valueFields:[]},jp=[];function qp({columns:e=jp,baseColumns:t,aggregationModel:n={},onAggregationModelChange:o,pivotModel:r,onPivotModelChange:i,filterModel:l,onFilterModelChange:c,columnVisibilityModel:a={},onColumnVisibilityModelChange:u,onColumnReorder:g,onColumnOrderReset:p,forceColumnsOpen:x,onColumnsPanelClose:y,forceFiltersOpen:h,onFiltersPanelClose:f,children:w,rightContent:b,style:m,renderColumnsButton:C,renderFilterButton:E,renderAggregationButton:_,renderExportButton:I,renderQuickFilter:M,className:S,showNonHideableColumns:F,onAiAssistantToggle:P,aiAssistantOpen:L=!1,aiAssistantLabel:k="Ask AI"}){const[N,T]=s.useState(x?"columns":null),v=N==="summaries",W=N==="pivot",B=N==="columns",Q=N==="filters",$=le=>{N==="columns"&&le!=="columns"&&y?.(),N==="filters"&&le!=="filters"&&f?.(),T(le)},z=le=>$(N===le?null:le),V=le=>{N===le&&$(null)},[ie,te]=s.useState(x);ie!==x&&(te(x),x&&T("columns"));const[ce,oe]=s.useState(h);ce!==h&&(oe(h),h&&c&&T("filters"));const de=s.useContext(Hl),X=x!==void 0&&!!u;s.useEffect(()=>{if(!(!de||!X))return de.registerColumnsPanel()},[de,X]);const ne=h!==void 0&&!!c;s.useEffect(()=>{if(!(!de||!ne))return de.registerFiltersPanel()},[de,ne]);const se=s.useRef(null),Y=s.useRef(null),H=s.useRef(null),R=s.useRef(null),ae=s.useRef(null),ge=s.useRef(null),J=s.useRef(null),O=s.useRef(null),A=r??Up,G=A.rowFields.length>0||A.columnFields.length>0||A.valueFields.length>0,D=t?new Set(t.map(le=>le.field)):null,U=e.filter(le=>le.aggregable!==!1&&(le.type==="number"||le.aggregable===!0)&&vs(le).length>0&&(!D||D.has(le.field))),q=Object.keys(n).filter(le=>n[le]&&n[le]!=="none").length,ee=s.useCallback((le,be)=>{if(!o)return;const Ce={...n};be==="none"?delete Ce[le]:Ce[le]=be,o(Ce)},[n,o]),Z=s.useCallback(()=>{o?.({})},[o]),j=s.useCallback(le=>{if(!c)return;const be=le.trim().split(/\s+/).filter(Boolean),Ce={...l||{},quickFilterValues:be,items:l?.items||[]};c(Ce)},[l,c]),re=(l?.quickFilterValues??[]).join(" "),me=l?.items?.length||0,pe=new Set(e.filter(le=>a[le.field]!==!1).map(le=>le.field)),K=s.useCallback((le,be)=>{if(!u)return;const Ce={...a,[le]:be};u(Ce)},[a,u]),fe=s.useCallback(()=>{if(!u)return;const le={...a};e.forEach(be=>{be.hideable!==!1&&(le[be.field]=!0)}),u(le)},[e,a,u]),we=s.useCallback(()=>{if(!u)return;const le={...a};e.forEach(be=>{be.hideable!==!1&&(le[be.field]=!1)}),u(le)},[e,a,u]);return d.jsxs("div",{className:["ogx-toolbar",S].filter(Boolean).join(" "),role:"toolbar","aria-label":"Grid toolbar",style:m,children:[w&&d.jsx("div",{className:"ogx-toolbar__left",children:w}),d.jsx("div",{className:"ogx-toolbar__spacer"}),d.jsxs("div",{className:"ogx-toolbar__actions",children:[P&&d.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:d.jsxs("button",{type:"button",ref:Y,className:`ogx-toolbar__icon-btn ogx-toolbar__ai-btn${L?" ogx-toolbar__icon-btn--active":""}`,"aria-haspopup":"dialog","aria-expanded":L,onClick:()=>{$(null),P(Y.current)},children:[d.jsx(Bl,{}),k]})}),c&&d.jsx("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:M?M({value:re,onChange:j}):d.jsx(Hp,{value:re,onChange:j,placeholder:"Search..."})}),u&&d.jsxs("div",{ref:ge,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[C?C({onClick:()=>z("columns"),isOpen:B,activeCount:e.length-pe.size}):d.jsx(pn,{title:"Columns",children:d.jsx("button",{type:"button",ref:R,className:`ogx-toolbar__icon-btn${B?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Manage columns","aria-haspopup":"dialog","aria-expanded":B,onClick:()=>z("columns"),children:d.jsx(Vp,{})})}),B&&d.jsx(Kp,{anchorRef:C?ge:R,columns:e,visibleColumns:pe,onVisibilityChange:K,onShowAll:fe,onHideAll:we,onColumnReorder:g,onColumnOrderReset:p,onClose:()=>V("columns"),showNonHideableColumns:F})]}),c&&d.jsxs("div",{ref:J,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[E?E({onClick:()=>z("filters"),isOpen:Q,activeCount:me}):d.jsx(pn,{title:"Filters",children:d.jsxs("button",{type:"button",ref:ae,className:`ogx-toolbar__icon-btn${Q?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Advanced filters","aria-haspopup":"dialog","aria-expanded":Q,onClick:()=>z("filters"),children:[d.jsx(_s,{}),me>0&&d.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Filters active"})]})}),Q&&d.jsx(Rp,{anchorRef:E?J:ae,columns:e,filterModel:l||{items:[]},onFilterModelChange:c,onClose:()=>V("filters")})]}),i&&d.jsxs("div",{className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[d.jsx(pn,{title:"Pivot",children:d.jsxs("button",{type:"button",ref:H,className:`ogx-toolbar__icon-btn${W?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure pivot","aria-haspopup":"dialog","aria-expanded":W,onClick:()=>z("pivot"),children:[d.jsx(ys,{}),G&&d.jsx("span",{className:"ogx-toolbar__dot","aria-label":"Pivot active"})]})}),W&&d.jsx(Dp,{anchorRef:H,columns:t??e,model:A,onChange:le=>{i?.(le)},onClose:()=>V("pivot")})]}),o&&d.jsxs("div",{ref:O,className:"ogx-toolbar__dropdown-wrapper",style:{marginRight:4},children:[_?_({onClick:()=>z("summaries"),isOpen:v,activeCount:q}):d.jsx(pn,{title:"Summaries",children:d.jsxs("button",{type:"button",ref:se,className:`ogx-toolbar__icon-btn${v?" ogx-toolbar__icon-btn--active":""}`,"aria-label":"Configure summaries","aria-haspopup":"dialog","aria-expanded":v,onClick:()=>z("summaries"),children:[d.jsx(Ss,{}),q>0&&d.jsx("span",{className:"ogx-toolbar__dot","aria-label":`${q} active summaries`})]})}),v&&d.jsx(zp,{anchorRef:_?O:se,aggregationModel:n,aggregableColumns:U,onFunctionChange:ee,onClearAll:Z,onClose:()=>V("summaries"),activeCount:q})]}),I&&I(),b]})]})}function Xp(){const[e]=s.useState(Yi);return s.useRef(e)}function qt(e,t){if(e.groupLabel!==void 0)return e.groupLabel;const n=e.groupField??"",o=t.find(r=>r.field===n)?.groupingValueFormatter;return o?o({field:n,value:e.groupValue}):`${n}: ${String(e.groupValue??"")}`}const Yp=new Set([8364,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,381,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,382,376]);function Jp(e){return e>=8192&&e<=8202||e===8239||e===8287||e===12288?" ":e>=8203&&e<=8205||e===8288||e===65279?"":e===8208||e===8209||e===8210||e===8722?"-":null}function Zp(e){let t="",n=!1;for(const o of e){const r=o.codePointAt(0)??0;if(r<=255||Yp.has(r)){t+=o;continue}const i=Jp(r);i!==null?t+=i:(t+="?",n=!0)}return{text:t,lossy:n}}const Qp={sliceMs:30,renderChunkRows:40},eh=2e4;function ks(){return new Promise(e=>setTimeout(e,0))}function th(){return new DOMException("PDF export was aborted","AbortError")}const Xt=()=>typeof performance<"u"?performance.now():Date.now(),Es=e=>Math.max(2,Math.floor(e/2)*2),nh=[79,70,229],oh=[255,255,255];function Ms(e,t){const n=e.trim().replace(/^#/,""),o=/^[a-f\d]{3}$/i.test(n)?n.split("").map(i=>i+i).join(""):n,r=/^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o);return r?[parseInt(r[1],16),parseInt(r[2],16),parseInt(r[3],16)]:t}function Is(e,t){return un(e,t,dn(e,t))}function Ns(e){return(typeof e.width=="number"?e.width:void 0)??(e.flex??1)*100}function rh(e,t){const n=e.reduce((r,i)=>r+Ns(i),0),o={};return e.forEach((r,i)=>{o[i]={cellWidth:Ns(r)/n*t}}),o}const ih=new Set(["isEmpty","isNotEmpty"]);function lh(e,t){const o=t.find(l=>l.field===e.field)?.headerName??e.field;if(ih.has(e.operator))return`${o} ${e.operator}`;const{value:r}=e;if(r==null||r===""||Array.isArray(r)&&r.length===0)return null;const i=Array.isArray(r)?r.map(String).join(", "):String(r);return`${o} ${e.operator} "${i}"`}function Ls(e,t,n,o){const r=e.map(l=>"items"in l?Ls(l.items,l.logicOperator,n,!0):lh(l,n)).filter(l=>!!l);if(r.length===0)return"";const i=r.join(t==="or"?" OR ":" AND ");return o&&r.length>1?`(${i})`:i}function sh(e,t){const n=[],o=Ls(e.items??[],e.logicOperator??"and",t,!1);o&&n.push(o);const r=(e.quickFilterValues??[]).filter(i=>i.trim()!=="");return r.length>0&&n.push(`Search: ${r.map(i=>`"${i}"`).join(" ")}`),n.join(" • ")}const ah=1.15*.3528;function ch(e,t,n={}){return dh(e,t,n,Qp)}async function dh(e,t,n,o){const{signal:r,onProgress:i}=n,l=()=>{if(r?.aborted)throw th()};l();let c,a;try{const[Z,j]=await Promise.all([import("jspdf"),import("jspdf-autotable")]);c=Z.default,a=j.default}catch{throw new Error("exportToPdf requires 'jspdf' and 'jspdf-autotable'. Run: npm install jspdf jspdf-autotable")}const{fileName:u="export",title:g,logoUrl:p,orientation:x="landscape",selectedRows:y,getRowId:h,aggregationResult:f,aggregationModel:w,filterModel:b,alternateRowColor:m=!0,headerBackgroundColor:C="#4f46e5",headerTextColor:E="#ffffff",fontSize:_=9,groupedRows:I,font:M,maxRows:S=eh}=n;l();let F=Xt();const P=async()=>{Xt()-F<o.sliceMs||(await ks(),l(),F=Xt())},L=(Z,j,re)=>{i?.({phase:Z,done:j,total:re})},k=new c({orientation:x,unit:"mm",format:"a4"}),N=k.internal.pageSize.getWidth(),T=k.internal.pageSize.getHeight(),v=14,W=N-v*2;let B="helvetica";M&&(k.addFileToVFS(`${M.name}-normal.ttf`,M.data),k.addFont(`${M.name}-normal.ttf`,M.name,"normal"),M.boldData&&k.addFileToVFS(`${M.name}-bold.ttf`,M.boldData),k.addFont(M.boldData?`${M.name}-bold.ttf`:`${M.name}-normal.ttf`,M.name,"bold"),B=M.name);let Q=!1;const $=Z=>{if(M)return Z;const j=Zp(Z);return j.lossy&&(Q=!0),j.text},z=(Z,j,re,me,pe)=>{const K=k.splitTextToSize($(Z),me);return k.text(K.length===1?K[0]:K,j,re),Math.max(0,K.length-1)*pe*ah},V=kt(t),ie=cn(I,y),te=an(e,y,h);let ce=v;if(g){let Z=v,j=v+8;if(p)try{k.addImage(p,"PNG",Z,v,10,10),Z+=14}catch{}const re=N-v-Z;k.setFontSize(16),k.setFont(B,"bold"),k.setTextColor(30,41,59),j+=z(g,Z,j,re,16),j+=6,k.setFontSize(8),k.setFont(B,"normal"),k.setTextColor(100,116,139);const me=new Date().toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),pe=ie?I.filter(K=>K.type==="leaf").length:te.length;if(k.text($(`Exported: ${me} • ${pe} row${pe!==1?"s":""}`),Z,j),j+=5,b){const K=sh(b,t);K&&(j+=z(`Filters: ${K}`,Z,j,re,8),j+=5)}k.setDrawColor(226,232,240),k.setLineWidth(.3),k.line(v,j+2,N-v,j+2),ce=j+6}const oe=[V.map(Z=>$(Z.headerName??Z.field))],de=w||{},X=Z=>V.map(j=>Uo(j,de[j.field],Z[j.field],Z)),ne=[];let se;const Y=Z=>{ne.push(Z.map($))};if(ie){const Z=I.length;L("prepare",0,Z);for(let j=0;j<Z;j++){const re=I[j],me=" ".repeat(re.depth*2);if(re.type==="group-header"){const pe=`${me}${qt(re,t)}`;Y(V.map((K,fe)=>fe===0?pe:""))}else if(re.type==="leaf"&&re.row){const pe=re.row;Y(V.map((K,fe)=>(fe===0?me:"")+Is(pe,K)))}else if(re.type==="group-subtotal"&&re.aggregatedValues){const pe=X(re.aggregatedValues);Y(pe.map((K,fe)=>fe===0?`${me}${Wt("Subtotal",K)}`:K))}else re.type==="grand-total"&&re.aggregatedValues&&(se=[X(re.aggregatedValues).map((K,fe)=>fe===0?Wt("Grand Total",K):K).map($)]);(j&63)===63&&(L("prepare",j+1,Z),await P())}L("prepare",Z,Z)}else{const Z=te.length;L("prepare",0,Z);for(let re=0;re<Z;re++)Y(V.map(me=>Is(te[re],me))),(re&63)===63&&(L("prepare",re+1,Z),await P());const j=w?Bt(te,dt(y),t,f,w):null;if(j&&w){const re=V.some(pe=>w[pe.field]);se=[X(j).map((pe,K)=>K===0&&re?Wt("TOTAL",pe):pe).map($)]}L("prepare",Z,Z)}l(),ne.length>S&&process.env.NODE_ENV!=="production"&&console.warn(`[exportToPdf] Exporting ${ne.length} table rows (maxRows: ${S}). PDFs this large are slow to build and open and can reach tens of MB. Prefer exportToCsv or exportToExcelAdvanced for full-dataset exports, or pass a larger \`maxRows\` to silence this warning.`),Q&&console.warn('[exportToPdf] Some characters cannot be drawn with the built-in Helvetica font and were replaced with "?". Pass the `font` option (a Unicode .ttf, e.g. Noto Sans) to draw them.');const H=rh(V,W),[R,ae,ge]=Ms(C,nh),[J,O,A]=Ms(E,oh),G={head:oe,styles:{fontSize:_,cellPadding:3,font:B,overflow:"linebreak"},headStyles:{fillColor:[R,ae,ge],textColor:[J,O,A],fontStyle:"bold"},...m?{alternateRowStyles:{fillColor:[248,250,252]}}:{},...se?{footStyles:{fillColor:[241,245,249],fontStyle:"bold",textColor:[0,0,0]}}:{},columnStyles:H,showHead:"everyPage",margin:{top:v,left:v,right:v,bottom:v+6}},D=ne.length;L("render",0,D);let U=0,q=Es(o.renderChunkRows);do{const Z=ne.slice(U,U+q),j=U===0,re=U+Z.length>=D,me=j?ce:k.lastAutoTable.finalY;let pe=!0;const K=Xt();a(k,{...G,body:Z,...re&&se?{foot:se}:{},startY:j?ce:v,showFoot:re&&se?"lastPage":"never",...j?{}:{willDrawPage:we=>{pe?(pe=!1,we.settings.showHead="never",we.cursor&&(we.cursor.y=me)):we.settings.showHead="everyPage"}}}),U+=Z.length,L("render",U,D);const fe=Xt()-K;q=Es(fe>0?Math.min(q*4,q*(o.sliceMs/fe)):q*4),re||(await ks(),l(),F=Xt())}while(U<D);const ee=k.getNumberOfPages();for(let Z=1;Z<=ee;Z++)k.setPage(Z),k.setFontSize(8),k.setTextColor(150,150,150),k.text(`Page ${Z} of ${ee}`,N-v,T-8,{align:"right"}),await P();l(),L("save",0,1),k.save(`${u}.pdf`),L("save",1,1)}function hn(e,t){const n=dn(e,t),o=un(e,t,n);return{text:o,raw:n,fromNonText:Wd(n,o,!!t.valueFormatter)}}function Yt(e,t,n){return e.map(o=>Uo(o,n[o.field],t[o.field],t))}const uh="\uFEFF";function fh(e,t,n={}){const{fileName:o="export.csv",includeHeaders:r=!0,delimiter:i=",",selectedRows:l,groupedRows:c,escapeFormulas:a=!0,bom:u=!0}=n,g=kt(t),p=n.aggregationModel||{},x=(f,w=!1)=>Qn(a?Kn(f,w):f,i),y=()=>g.map(f=>x(f.headerName||f.field)).join(i)+`
|
|
8
|
+
`;let h="";if(cn(c,l))r&&(h+=y()),c.forEach(f=>{const w=" ".repeat(f.depth);if(f.type==="group-header"){const b=qt(f,t),m=Qn(w+(a?Kn(b):b),i);h+=g.map((C,E)=>E===0?m:"").join(i)+`
|
|
9
|
+
`}else if(f.type==="leaf"&&f.row){const b=f.row,m=g.map((C,E)=>{const _=hn(b,C),I=a?Kn(_.text,_.fromNonText):_.text;return Qn((E===0?w:"")+I,i)});h+=m.join(i)+`
|
|
10
|
+
`}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const b=f.aggregatedValues,m=f.type==="grand-total"?"Grand Total":`${w}Subtotal`,C=Yt(g,b,p),E=g.map((_,I)=>I===0?Qn(Wt(m,C[0]),i):x(C[I],Vt(b[_.field])));h+=E.join(i)+`
|
|
11
|
+
`}});else{const f=an(e,l,n.getRowId);if(f.length===0){console.warn("No rows to export");return}r&&(h+=y()),f.forEach(b=>{const m=g.map(C=>{const E=hn(b,C);return x(E.text,E.fromNonText)});h+=m.join(i)+`
|
|
12
|
+
`});const w=Bt(f,dt(l),t,n.aggregationResult,n.aggregationModel);if(w){const b=g.map(C=>x(p[C.field]?p[C.field].toUpperCase():""));h+=b.join(i)+`
|
|
13
|
+
`;const m=Yt(g,w,p);h+=g.map((C,E)=>x(m[E],Vt(w[C.field]))).join(i)+`
|
|
14
|
+
`}}wr((u?uh:"")+h,o,"text/csv;charset=utf-8;")}function Qn(e,t){return t!==""&&e.includes(t)||e.includes('"')||e.includes(`
|
|
15
|
+
`)||e.includes("\r")?`"${e.replace(/"/g,'""')}"`:e}const eo="ogx-xls-text";function gh(e,t){return e.type!=="number"&&e.type!=="date"&&e.type!=="boolean"&&!Vt(t)}function ph(e){if(!/\.xlsx$/i.test(e))return e;const t=e.replace(/\.xlsx$/i,".xls");return console.warn(`[exportToExcel] "${e}" renamed to "${t}": exportToExcel writes an HTML table that Excel refuses to open as .xlsx. Use exportToExcelAdvanced for a real .xlsx file.`),t}function hh(e,t,n={}){const{fileName:o="export.xls",sheetName:r="Sheet1",includeHeaders:i=!0,selectedRows:l,groupedRows:c,escapeFormulas:a=!0}=n,u=kt(t),g=n.aggregationModel||{},p=(w,b=!1)=>Fe(a?Kn(w,b):w),x=w=>`<td class="${eo}">${w}</td>`;let h=`<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>${Fe(jo(r))}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta charset="UTF-8"><style>.${eo}{mso-number-format:"\\@";}</style></head><body><table border="1">`;i&&(h+="<thead><tr>",u.forEach(w=>{h+=`<th class="${eo}">${p(w.headerName||w.field)}</th>`}),h+="</tr></thead>"),h+="<tbody>";const f=(w,b,m="")=>{const C=m+p(w.text,w.fromNonText);return gh(b,w.raw)?x(C):`<td>${C}</td>`};if(cn(c,l))c.forEach(w=>{const b=" ".repeat(w.depth*2);if(w.type==="group-header")h+='<tr style="font-weight:bold;background:#e8eaf6;">',h+=`<td colspan="${u.length}" class="${eo}">${Fe(b)}${p(qt(w,t))}</td>`,h+="</tr>";else if(w.type==="leaf"&&w.row){const m=w.row;h+="<tr>",u.forEach((C,E)=>{h+=f(hn(m,C),C,E===0?Fe(b):"")}),h+="</tr>"}else if((w.type==="group-subtotal"||w.type==="grand-total")&&w.aggregatedValues){const m=w.aggregatedValues,C=w.type==="grand-total"?"Grand Total":`${b}Subtotal`,E=Yt(u,m,g);h+='<tr style="font-weight:bold;background:#f5f5f5;">',u.forEach((_,I)=>{if(I===0){h+=x(Fe(Wt(C,E[0])));return}h+=E[I]?`<td style="text-align:right;">${p(E[I],Vt(m[_.field]))}</td>`:"<td></td>"}),h+="</tr>"}});else{const w=an(e,l,n.getRowId);if(w.length===0){console.warn("No rows to export");return}w.forEach(m=>{h+="<tr>",u.forEach(C=>{h+=f(hn(m,C),C)}),h+="</tr>"});const b=Bt(w,dt(l),t,n.aggregationResult,n.aggregationModel);if(b){h+='<tr style="font-size: 11px; color: #666; background-color: #f5f5f5;">',u.forEach(C=>{h+=g[C.field]?`<td style="text-align:right;font-weight:bold;">${Fe(g[C.field].toUpperCase())}</td>`:"<td></td>"}),h+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">';const m=Yt(u,b,g);u.forEach((C,E)=>{h+=m[E]?`<td style="text-align:right;">${p(m[E],Vt(b[C.field]))}</td>`:"<td></td>"}),h+="</tr>"}}h+="</tbody></table></body></html>",wr(h,ph(o),"application/vnd.ms-excel")}function mh(e,t,n={}){const{fileName:o="export.json",pretty:r=!0,selectedRows:i,groupedRows:l}=n,c=kt(t),a=g=>{const p={};return c.forEach(x=>{p[x.field]=dn(g,x)}),p};let u;if(cn(l,i)){const g=[],p=[];let x;l.forEach(y=>{if(y.type==="group-header"){const h={group:qt(y,t),field:y.groupField??"",value:y.groupValue,rows:[],children:[]};for(;g.length>y.depth;)g.pop();g.length===0?p.push(h):(g[g.length-1].children??=[]).push(h),g.push(h)}else y.type==="leaf"&&y.row?g.length>0&&g[g.length-1].rows.push(a(y.row)):y.type==="group-subtotal"&&y.aggregatedValues&&g.length>0?(g[g.length-1].subtotals=dl(y.aggregatedValues,c),g.pop()):y.type==="grand-total"&&y.aggregatedValues&&(x=dl(y.aggregatedValues,c))}),u=x?{groups:p,grandTotal:x}:{groups:p}}else{const g=an(e,i,n.getRowId);if(g.length===0){console.warn("No rows to export");return}const p=g.map(a),x=Bt(g,dt(i),t,n.aggregationResult,n.aggregationModel);if(x){const y=n.aggregationModel||{},h={};c.forEach(w=>{y[w.field]&&(h[w.field]=y[w.field].toUpperCase())});const f={};c.forEach(w=>{x[w.field]!==void 0&&x[w.field]!==null&&(f[w.field]=x[w.field])}),u={data:p,aggregation:{labels:h,values:f}}}else u=p}wr(r?JSON.stringify(u,null,2):JSON.stringify(u),o,"application/json;charset=utf-8;")}const wh=/^(?:https?:|data:image\/|blob:)/i,bh=/^[a-z][a-z\d+.-]*:/i;function xh(e){const t=e.trim();return t?wh.test(t)?t:bh.test(t)?null:t:null}async function yh(e,t,n){const o=window.open("","_blank");if(!o){console.error("Failed to open print window. Please check your popup blocker settings.");return}o.document.write(`
|
|
16
16
|
<!DOCTYPE html>
|
|
17
17
|
<html>
|
|
18
18
|
<head>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
</div>
|
|
33
33
|
</body>
|
|
34
34
|
</html>
|
|
35
|
-
`),o.document.close(),await new Promise(r=>setTimeout(r,100));try{let r="Print",i,l,
|
|
35
|
+
`),o.document.close(),await new Promise(r=>setTimeout(r,100));try{let r="Print",i,l,c=null,a=null,u;typeof n=="string"?r=n:typeof n=="object"&&(r=n.title||"Print",i=n.selectedRows,l=n.getRowId,c=n.aggregationResult||null,a=n.aggregationModel||null,u=n.groupedRows);const g=kt(t),p=a||{};let x=`<!DOCTYPE html><html><head><title>${Fe(r||"Print")}</title><style>
|
|
36
36
|
body{font-family:Arial,sans-serif;margin:20px;}
|
|
37
37
|
h1{font-size:24px;margin-bottom:20px;}
|
|
38
38
|
table{border-collapse:collapse;width:100%;}
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
tr.group-subtotal{background:#f0f4ff;font-style:italic;}
|
|
44
44
|
tr.grand-total{background:#f5f5f5;font-weight:bold;}
|
|
45
45
|
@media print{body{margin:0;}@page{margin:1cm;}}
|
|
46
|
-
</style></head><body>`;r&&(x+=`<h1>${Te(r)}</h1>`),x+="<table><thead><tr>",g.forEach(f=>{x+=`<th>${Te(f.headerName||f.field)}</th>`}),x+="</tr></thead><tbody>";const y=(f,h,b="",w=!1)=>{const{text:C}=pn(f,h),E=h.type==="image"?gh(C):null;if(E!==null){const S=`<img src="${Te(E)}" alt="${Te(h.headerName||h.field)}" style="max-height:40px;border-radius:4px;">`;return w?`<td><div style="display:flex;justify-content:center;">${S}</div></td>`:`<td>${S}</td>`}return`<td>${b}${Te(C)}</td>`};if(an(u,i))u.forEach(f=>{const h=" ".repeat(f.depth*4);if(f.type==="group-header")x+=`<tr class="group-header"><td colspan="${g.length}">${h}${Te(qt(f,t))}</td></tr>`;else if(f.type==="leaf"&&f.row){const b=f.row;x+="<tr>",g.forEach((w,C)=>{x+=y(b,w,C===0?h:"")}),x+="</tr>"}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const b=f.type==="grand-total",w=Yt(g,f.aggregatedValues,m);x+=`<tr class="${b?"grand-total":"group-subtotal"}">`,g.forEach((C,E)=>{if(E===0){x+=`<td>${b?"":h}${Te(Wt(b?"Grand Total":"Subtotal",w[0]))}</td>`;return}x+=w[E]?`<td style="text-align:right;">${Te(w[E])}</td>`:"<td></td>"}),x+="</tr>"}});else{const f=sn(e,i,l);if(f.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}f.forEach(b=>{x+="<tr>",g.forEach(w=>{x+=y(b,w,"",!0)}),x+="</tr>"});const h=Bt(f,dt(i),t,a,c);h&&(x+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',g.forEach(b=>{x+=m[b.field]?`<td style="text-align:right;font-weight:bold;">${Te(m[b.field].toUpperCase())}</td>`:"<td></td>"}),x+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',Yt(g,h,m).forEach(b=>{x+=b?`<td style="text-align:right;">${Te(b)}</td>`:"<td></td>"}),x+="</tr></tfoot>")}x+="</tbody></table></body></html>",o.document.open(),o.document.write(x),o.document.close(),o.document.title=r||"Print Preview",o.focus();let p=!1;o.onload=()=>{p||(p=!0,o.print(),setTimeout(()=>{o.close()},100))},setTimeout(()=>{!p&&o&&!o.closed&&(p=!0,o.print(),setTimeout(()=>{o.closed||o.close()},100))},500)}catch(r){if(console.error("Print generation failed:",r),o&&!o.closed){const i=r instanceof Error?r.message:String(r);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${Te(i)}</p></div>`}}}function fr(e,t,n){const o=new Blob([e],{type:n}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function hh(e,t){return e.type==="number"?"number":e.type==="boolean"?"boolean":e.type==="date"?"date":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date?"date":"string"}function hn(e){return Number.isNaN(e.getTime())?null:new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}const mh=/^(\d{4})-(\d{2})-(\d{2})$/,wh=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/i,bh=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;function xh(e){if(e instanceof Date)return hn(e);if(typeof e=="number")return Number.isFinite(e)?hn(new Date(e)):null;if(typeof e!="string")return;const t=e.trim(),n=mh.exec(t);if(n){const[o,r,i]=[Number(n[1]),Number(n[2]),Number(n[3])],l=new Date(Date.UTC(o,r-1,i));return l.getUTCMonth()===r-1&&l.getUTCDate()===i?l:void 0}if(wh.test(t)){const o=new Date(t.replace(" ","T"));return Number.isNaN(o.getTime())?void 0:hn(o)}}function yh(e,t){if(t==null||t==="")return null;if(e==="number"){if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="bigint"){const n=Number(t);return Number.isSafeInteger(n)?n:void 0}if(typeof t=="string"&&bh.test(t.trim())){const n=Number(t.trim());return Number.isFinite(n)?n:void 0}return}if(e==="boolean"){if(typeof t=="boolean")return t;if(typeof t=="string"){const n=t.trim().toLowerCase();if(n==="true")return!0;if(n==="false")return!1}return}return xh(t)}function Ms(e){if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:null;if(e instanceof Date)return hn(e);if(typeof e=="object")try{return JSON.stringify(e)??String(e)}catch{return String(e)}return String(e)}function Ch(e,t){const n=cn(e,t),o=hh(t,n);if(o!=="string"){const r=yh(o,n);if(r!=null)return r;if(!t.valueFormatter)return r===null?null:Ms(n)}return t.valueFormatter?dn(e,t,n):Ms(n)}const Ns="#,##0",vh="#,##0.##";function Sh(e){return Number.isInteger(e)?Ns:vh}function Is(e,t){if(t?.numFmt)return t.numFmt;if(e.type==="date")return"yyyy-mm-dd"}function Ls(e,t,n){if(!(t?.numFmt||typeof n!="number"||e.type!=="number"))return Sh(n)}function _h(e,t){if(t!=null)return t;const n=e.width??120;return Math.min(60,Math.max(8,(n-5)/7))}function kh(e){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e.length>=6&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56?"gif":null}function As(e,t){const n=cn(e,t);return typeof n=="string"&&n?n:null}async function Eh(e){const t=await Promise.allSettled(e.map(async o=>{let r;if(o.startsWith("data:")){const l=o.slice(o.indexOf(",")+1),a=atob(l);r=new Uint8Array(a.length);for(let c=0;c<a.length;c++)r[c]=a.charCodeAt(c)}else{const l=await fetch(o,{mode:"cors"});if(!l.ok)throw new Error(`HTTP ${l.status}`);r=new Uint8Array(await l.arrayBuffer())}const i=kh(r);if(!i)throw new Error("unsupported image format (only PNG, JPEG and GIF can be embedded)");return{url:o,buffer:r.slice().buffer,ext:i}})),n=new Map;return t.forEach((o,r)=>{o.status==="fulfilled"?n.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${e[r]}" (CORS/network error or unsupported format — raw URL written as fallback):`,o.reason)}),n}async function Mh(e,t,n={}){const{fileName:o="export.xlsx",sheets:r,columnStyles:i={},headerFillColor:l="#f1f5f9",headerTextColor:a="#334155",headerFontSize:c=10,bodyFontSize:u=10,aggregationResult:g=null,aggregationModel:m=null,selectedRows:x,getRowId:y,groupedRows:p,groupHeaderFillColor:f="#e8eaf6",groupSubtotalFillColor:h="#f0f4ff"}=n;let b;try{b=(await import("exceljs")).default}catch{throw new Error("exportToExcelAdvanced requires 'exceljs'. Run: npm install exceljs")}const w=new b.Workbook;w.creator="OpenGridX",w.created=new Date;const C=t,E=Et(C),S=e,N=dt(x)?tl(S,x,y):[],M=r??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],_=new Set,F=new Map,A=(v,B)=>{const W=B[v.field],J=m?.[v.field];if(W==null)return{value:null};const G=Kr(v,J,W);return typeof G=="number"?Number.isFinite(G)?Rr(J)?{value:G,numFmt:Ns}:{value:G,numFmt:Ls(v,i[v.field],G)}:{value:null}:G instanceof Date?{value:hn(G)}:{value:zo(v,J,W,B)}};for(const v of M){if("type"in v&&v.type==="summary"){if(!g||!m)continue;const Q=w.addWorksheet(Ro(v.name??"Summary",_));Q.addRow(["Summary / Aggregation Totals"]),Q.getRow(1).font={bold:!0,size:c+2,color:{argb:Ve(a)}},Q.addRow([]),Q.addRow(["Column","Function","Value"]).eachCell(T=>{T.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(l)}},T.font={bold:!0,size:c,color:{argb:Ve(a)}},T.border=Ps()}),E.forEach(T=>{const $=m[T.field];if($==null||g[T.field]==null)return;const{value:O,numFmt:Z}=A(T,g),ne=Q.addRow([T.headerName??T.field,$.toUpperCase(),O]).getCell(3),X=Z??Is(T,i[T.field]);X&&(ne.numFmt=X),ne.alignment={horizontal:"right"},ne.font={bold:!0,size:u}}),Q.getColumn(1).width=20,Q.getColumn(2).width=12,Q.getColumn(3).width=18;continue}const B=v,{name:W="Data",rows:J="all",includeHeaders:G=!0,includeSummary:z=!1,autoFilter:H=!0,frozenHeader:re=!0,alternateRowColor:ee="#f8fafc"}=B,de=J==="all"&&!!(p&&p.length>0),ie=J==="selected"?N:de?p.flatMap(Q=>Q.type==="leaf"&&Q.row?[Q.row]:[]):S,ae=E.filter(Q=>i[Q.field]?.embedImage);if(ae.length>0){const Q=[],D=new Set;if(ie.forEach(T=>{ae.forEach($=>{const O=As(T,$);O&&!F.has(O)&&!D.has(O)&&(Q.push(O),D.add(O))})}),Q.length>0){const T=await Eh(Q);for(const[$,{buffer:O,extension:Z}]of T){const j=w.addImage({buffer:O,extension:Z});F.set($,j)}}}const R=w.addWorksheet(Ro(W,_));R.columns=E.map(Q=>({key:Q.field,width:_h(Q,i[Q.field]?.width),style:{numFmt:Is(Q,i[Q.field])}}));const ue=(Q,D)=>{E.forEach((T,$)=>D(Q.getCell($+1),T,$+1))};if(G){const Q=E.map(T=>T.headerName??T.field),D=R.addRow(Q);D.height=20,ue(D,(T,$)=>{T.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(l)}},T.font={bold:!0,size:c,color:{argb:Ve(a)}},T.alignment={horizontal:i[$.field]?.alignment??($.type==="number"?"right":"left"),vertical:"middle"},T.border=Ps()}),H&&(R.autoFilter={from:{row:1,column:1},to:{row:1,column:E.length}}),re?R.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:R.views=[{showGridLines:!1}]}let q=G?1:0;const te=(Q,D,T)=>{const $=E.map(j=>i[j.field]?.embedImage?"":Ch(Q,j)),O=R.addRow($);O.font={size:u},T>0&&(O.outlineLevel=T);const Z=!!ee&&D%2===1;if(ue(O,(j,ne,X)=>{const Y=Ls(ne,i[ne.field],$[X-1]);Y&&(j.numFmt=Y),Z&&ee&&(j.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(ee)}}),j.alignment={horizontal:i[ne.field]?.alignment??(ne.type==="number"?"right":"left"),vertical:"middle"},j.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}}}),ae.length>0){const j=ae.reduce((Y,oe)=>Math.max(Y,i[oe.field]?.imageHeight??40),0),ne=Math.ceil(j/1.333),X=ne*1.333;O.height=ne,ae.forEach(Y=>{const oe=E.indexOf(Y),he=As(Q,Y),me=he?F.get(he):void 0;if(me===void 0){O.getCell(oe+1).value=he??"";return}const K=i[Y.field],fe=K?.imageWidth??40,we=K?.imageHeight??40,xe=(R.getColumn(oe+1).width??8)*7+5,Ce=Math.max(0,xe-fe)/2,se=Math.max(0,X-we)/2;R.addImage(me,{tl:{col:oe,row:q,nativeColOff:Math.floor(Ce*9525),nativeRowOff:Math.floor(se*9525)},ext:{width:fe,height:we},editAs:"oneCell"})})}else O.height=16;q++},V=Q=>qt(Q,C),U=(Q,D,T,$,O)=>{const Z=E.map((ne,X)=>X===0&&D[ne.field]==null?{value:Q}:A(ne,D)),j=R.addRow(Z.map(ne=>ne.value));j.height=18,$>0&&(j.outlineLevel=$),j.font={bold:O,italic:!O,size:u,color:{argb:Ve(a)}},ue(j,(ne,X,Y)=>{const oe=Z[Y-1].numFmt;oe&&(ne.numFmt=oe),ne.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(T)}},ne.alignment={horizontal:Y===1?"left":X.type==="number"?"right":"left",vertical:"middle"},ne.border=Ts()}),q++};let ce=!1;if(de){let Q=0;p.forEach(D=>{if(D.type==="group-header"){const T=R.addRow([V(D)]);T.height=18,D.depth>0&&(T.outlineLevel=D.depth),T.font={bold:!0,size:u,color:{argb:Ve(a)}};for(let $=1;$<=E.length;$++)T.getCell($).fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(f)}};T.getCell(1).alignment={horizontal:"left",vertical:"middle",indent:D.depth},q++,Q=0}else D.type==="leaf"&&D.row?te(D.row,Q++,D.depth):D.type==="group-subtotal"&&D.aggregatedValues?U("Subtotal",D.aggregatedValues,h,D.depth,!1):D.type==="grand-total"&&D.aggregatedValues&&(U("Grand Total",D.aggregatedValues,l,0,!0),ce=!0)}),R.properties.outlineProperties={summaryBelow:!0,summaryRight:!1}}else ie.forEach((Q,D)=>te(Q,D,0));const ge=Bt(ie,J==="selected",C,g,m);if(z&&!ce&&ge&&m){const Q=E.map(O=>{const Z=m[O.field];return Z?Z.toUpperCase():""}),D=R.addRow(Q);D.height=16,D.font={size:u-1,italic:!0,color:{argb:"FF94a3b8"}},ue(D,O=>{O.alignment={horizontal:"right",vertical:"middle"},O.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const T=E.map(O=>m[O.field]==null?{value:null}:A(O,ge)),$=R.addRow(T.map(O=>O.value));$.height=18,$.font={bold:!0,size:u,color:{argb:Ve(a)}},ue($,(O,Z,j)=>{const ne=T[j-1].numFmt;ne&&(O.numFmt=ne),O.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(l)}},O.alignment={horizontal:"right",vertical:"middle"},O.border=Ts()})}}const L=await w.xlsx.writeBuffer(),k=new Blob([L],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),I=URL.createObjectURL(k),P=document.createElement("a");P.href=I,P.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(P),P.click(),document.body.removeChild(P),URL.revokeObjectURL(I)}function Ve(e){const t=e.replace("#","");return t.length===3?"FF"+t.split("").map(n=>n+n).join(""):t.length===6?"FF"+t:"FF"+t.padEnd(6,"0")}function Ps(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function Ts(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}function Nh(e,t,n,o){return s.useMemo(()=>o?mi(e,t,n):Lo,[e,t,n,o])}const Fs={"--ogx-grid-row-selected-background":"var(--ogx-color-primary-light)","--ogx-grid-row-selected-hover-background":"color-mix(in srgb, var(--ogx-color-primary) 14%, var(--ogx-color-primary-light))","--ogx-grid-cell-focus-border":"var(--ogx-color-primary)","--ogx-range-background":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-range-border":"var(--ogx-color-primary)","--ogx-fill-handle-color":"var(--ogx-range-border)","--ogx-toolbar-btn-primary-bg":"var(--ogx-color-primary)","--ogx-toolbar-btn-primary-hover":"var(--ogx-color-primary-dark)","--ogx-toolbar-input-focus-border":"var(--ogx-color-primary)","--ogx-toolbar-input-focus-shadow":"0 0 0 3px color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-bg":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-text":"var(--ogx-color-primary-dark)","--ogx-overlay-item-selected-bg":"color-mix(in srgb, var(--ogx-color-primary) 8%, transparent)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary-dark)"},Os={"--ogx-color-primary":"#3b82f6","--ogx-color-primary-dark":"#2563eb","--ogx-color-primary-light":"#eff6ff","--ogx-color-primary-focus":"rgba(59, 130, 246, 0.5)","--ogx-color-secondary":"#8b5cf6","--ogx-color-secondary-dark":"#7c3aed","--ogx-color-secondary-light":"#f5f3ff","--ogx-color-white":"#ffffff","--ogx-color-black":"#0f172a","--ogx-color-gray-50":"#f8fafc","--ogx-color-gray-100":"#f1f5f9","--ogx-color-gray-200":"#e2e8f0","--ogx-color-gray-300":"#cbd5e1","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#64748b","--ogx-color-gray-600":"#475569","--ogx-color-gray-700":"#334155","--ogx-color-gray-800":"#1e293b","--ogx-color-gray-900":"#0f172a","--ogx-border-color":"#e2e8f0","--ogx-border-color-hover":"#cbd5e1","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.05)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02)","--ogx-grid-background":"#ffffff","--ogx-grid-border-color":"#e2e8f0","--ogx-grid-header-background":"#f8fafc","--ogx-grid-header-text":"#334155","--ogx-grid-header-hover-background":"#f1f5f9","--ogx-grid-header-sorted-background":"#f8fafc","--ogx-grid-row-text":"#1e293b","--ogx-grid-row-hover-background":"#f8fafc","--ogx-grid-row-alternate-background":"transparent","--ogx-checkbox-bg":"#ffffff","--ogx-checkbox-border":"#94a3b8","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.05)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.05)",...{"--ogx-toolbar-background":"var(--ogx-grid-header-background)","--ogx-toolbar-text":"var(--ogx-grid-header-text)","--ogx-toolbar-border":"var(--ogx-grid-border-color)","--ogx-toolbar-btn-bg":"transparent","--ogx-toolbar-btn-hover":"var(--ogx-grid-header-hover-background)","--ogx-toolbar-btn-text":"var(--ogx-grid-header-text)","--ogx-toolbar-input-bg":"var(--ogx-grid-background)","--ogx-toolbar-input-text":"var(--ogx-grid-row-text)","--ogx-toolbar-chip-bg":"transparent","--ogx-toolbar-chip-text":"var(--ogx-grid-row-text)"},"--ogx-toolbar-btn-primary-text":"#ffffff","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-text":"#ef4444","--ogx-toolbar-input-border":"#cbd5e1","--ogx-overlay-background":"#ffffff","--ogx-overlay-text":"#1e293b","--ogx-overlay-border":"#e2e8f0","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.06)","--ogx-overlay-item-hover-bg":"#f8fafc","--ogx-overlay-item-hover-text":"#0f172a","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-overlay-item-danger-text":"#ef4444","--ogx-scrollbar-thumb":"#cbd5e1","--ogx-scrollbar-track":"transparent","--ogx-scrollbar-size":"8px","--ogx-skeleton-base":"#f1f5f9","--ogx-skeleton-highlight":"#ffffff",...Fs},Ih={...Os,"--ogx-color-primary":"#60a5fa","--ogx-color-primary-dark":"#3b82f6","--ogx-color-primary-light":"#1e3a5f","--ogx-color-primary-focus":"rgba(96, 165, 250, 0.4)","--ogx-color-white":"#0f172a","--ogx-color-black":"#f8fafc","--ogx-color-gray-50":"#1e293b","--ogx-color-gray-100":"#334155","--ogx-color-gray-200":"#475569","--ogx-color-gray-300":"#64748b","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#cbd5e1","--ogx-color-gray-600":"#e2e8f0","--ogx-color-gray-700":"#e2e8f0","--ogx-color-gray-800":"#f1f5f9","--ogx-color-gray-900":"#f8fafc","--ogx-border-color":"#334155","--ogx-border-color-hover":"#475569","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.3)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.3)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.3)","--ogx-grid-background":"#0f172a","--ogx-grid-border-color":"#334155","--ogx-grid-header-background":"#1e293b","--ogx-grid-header-text":"#e2e8f0","--ogx-grid-header-hover-background":"#334155","--ogx-grid-header-sorted-background":"#1e3a5f","--ogx-grid-row-text":"#cbd5e1","--ogx-grid-row-hover-background":"#1e293b","--ogx-grid-row-alternate-background":"#162032","--ogx-checkbox-bg":"#1e293b","--ogx-checkbox-border":"#64748b","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.25)","--ogx-toolbar-btn-danger-text":"#fca5a5","--ogx-toolbar-input-border":"#334155","--ogx-overlay-background":"#1e293b","--ogx-overlay-text":"#cbd5e1","--ogx-overlay-border":"#334155","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3), 0 0 0 1px rgba(0,0,0,0.2)","--ogx-overlay-item-hover-bg":"#334155","--ogx-overlay-item-hover-text":"#f1f5f9","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-overlay-item-danger-text":"#fca5a5","--ogx-scrollbar-thumb":"#475569","--ogx-skeleton-base":"#1e293b","--ogx-skeleton-highlight":"#334155",...Fs,"--ogx-toolbar-chip-active-text":"var(--ogx-color-primary)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary)"},Lh=[50,100,200,300,400,500,600,700,800,900];function Ah(e){const t={};function n(o,r){r!==void 0&&(t[o]=r)}if(e.colors){const o=e.colors;if(n("--ogx-color-primary",o.primary),n("--ogx-color-primary-dark",o.primaryDark),n("--ogx-color-primary-light",o.primaryLight),n("--ogx-color-primary-focus",o.primaryFocus),n("--ogx-color-secondary",o.secondary),n("--ogx-color-secondary-dark",o.secondaryDark),n("--ogx-color-secondary-light",o.secondaryLight),n("--ogx-color-success",o.success),n("--ogx-color-warning",o.warning),n("--ogx-color-error",o.error),n("--ogx-color-info",o.info),n("--ogx-color-white",o.white),n("--ogx-color-black",o.black),o.gray)for(const r of Lh)n(`--ogx-color-gray-${r}`,o.gray[r])}if(e.typography){const o=e.typography;n("--ogx-font-family",o.fontFamily),n("--ogx-font-family-mono",o.fontFamilyMono),n("--ogx-font-size-xs",o.fontSizeXs),n("--ogx-font-size-sm",o.fontSizeSm),n("--ogx-font-size-md",o.fontSizeMd),n("--ogx-font-size-lg",o.fontSizeLg),n("--ogx-font-size-xl",o.fontSizeXl)}if(e.spacing){const o=e.spacing;n("--ogx-spacing-xs",o.xs),n("--ogx-spacing-sm",o.sm),n("--ogx-spacing-md",o.md),n("--ogx-spacing-lg",o.lg),n("--ogx-spacing-xl",o.xl),n("--ogx-spacing-xxl",o.xxl)}if(e.borders){const o=e.borders;n("--ogx-border-width-thin",o.widthThin),n("--ogx-border-width-medium",o.widthMedium),n("--ogx-border-width-thick",o.widthThick),n("--ogx-border-radius-sm",o.radiusSm),n("--ogx-border-radius-md",o.radiusMd),n("--ogx-border-radius-lg",o.radiusLg),n("--ogx-border-radius-xl",o.radiusXl),n("--ogx-border-color",o.color),n("--ogx-border-color-hover",o.colorHover)}if(e.shadows){const o=e.shadows;n("--ogx-shadow-sm",o.sm),n("--ogx-shadow-md",o.md),n("--ogx-shadow-lg",o.lg),n("--ogx-shadow-xl",o.xl)}if(e.grid){const o=e.grid;n("--ogx-grid-row-height-compact",o.rowHeightCompact),n("--ogx-grid-row-height-standard",o.rowHeightStandard),n("--ogx-row-height",o.rowHeightStandard),n("--ogx-grid-row-height-comfortable",o.rowHeightComfortable),n("--ogx-grid-header-height",o.headerHeight),n("--ogx-header-height",o.headerHeight),n("--ogx-grid-cell-padding-x",o.cellPaddingX),n("--ogx-grid-cell-padding-y",o.cellPaddingY),n("--ogx-grid-cell-font-size",o.cellFontSize),n("--ogx-grid-header-font-size",o.headerFontSize),n("--ogx-grid-header-font-family",o.headerFontFamily),n("--ogx-grid-header-font-weight",o.headerFontWeight),n("--ogx-grid-cell-font-family",o.cellFontFamily),n("--ogx-grid-cell-font-weight",o.cellFontWeight),n("--ogx-grid-header-padding-x",o.headerPaddingX),n("--ogx-grid-border-width",o.borderWidth),n("--ogx-grid-border-radius",o.borderRadius),n("--ogx-grid-column-divider-width",o.columnDividerWidth),n("--ogx-grid-header-column-divider-width",o.headerColumnDividerWidth),n("--ogx-grid-row-divider-width",o.rowDividerWidth),n("--ogx-grid-column-divider-color",o.columnDividerColor),n("--ogx-grid-row-divider-color",o.rowDividerColor),n("--ogx-grid-background",o.background),n("--ogx-grid-border-color",o.borderColor),n("--ogx-grid-header-background",o.headerBackground),n("--ogx-grid-header-text",o.headerText),n("--ogx-grid-header-hover-background",o.headerHoverBackground),n("--ogx-grid-header-sorted-background",o.headerSortedBackground),n("--ogx-grid-row-text",o.rowText),n("--ogx-grid-row-hover-background",o.rowHoverBackground),n("--ogx-grid-row-alternate-background",o.rowAlternateBackground),n("--ogx-grid-row-selected-background",o.rowSelectedBackground),n("--ogx-grid-row-selected-hover-background",o.rowSelectedHoverBackground),n("--ogx-grid-cell-focus-border",o.cellFocusBorder),n("--ogx-range-background",o.rangeBackground),n("--ogx-range-border",o.rangeBorder),n("--ogx-fill-handle-color",o.fillHandleColor),n("--ogx-grid-pinned-left-shadow",o.pinnedLeftShadow),n("--ogx-grid-pinned-right-shadow",o.pinnedRightShadow),n("--ogx-checkbox-bg",o.checkboxBg),n("--ogx-checkbox-border",o.checkboxBorder)}if(e.transitions){const o=e.transitions;n("--ogx-transition-duration-fast",o.durationFast),n("--ogx-transition-duration-normal",o.durationNormal),n("--ogx-transition-duration-slow",o.durationSlow),n("--ogx-transition-easing",o.easing)}if(e.toolbar){const o=e.toolbar;n("--ogx-toolbar-background",o.background),n("--ogx-toolbar-text",o.text),n("--ogx-toolbar-border",o.border),n("--ogx-toolbar-btn-bg",o.buttonBackground),n("--ogx-toolbar-btn-hover",o.buttonHoverBackground),n("--ogx-toolbar-btn-text",o.buttonText),n("--ogx-toolbar-btn-primary-bg",o.buttonPrimaryBackground),n("--ogx-toolbar-btn-primary-hover",o.buttonPrimaryHoverBackground),n("--ogx-toolbar-btn-primary-text",o.buttonPrimaryText),n("--ogx-toolbar-btn-danger-bg",o.buttonDangerBackground),n("--ogx-toolbar-btn-danger-hover",o.buttonDangerHoverBackground),n("--ogx-toolbar-btn-danger-text",o.buttonDangerText),n("--ogx-toolbar-input-bg",o.inputBackground),n("--ogx-toolbar-input-text",o.inputText),n("--ogx-toolbar-input-border",o.inputBorder),n("--ogx-toolbar-input-focus-border",o.inputFocusBorder),n("--ogx-toolbar-input-focus-shadow",o.inputFocusShadow),n("--ogx-toolbar-chip-bg",o.chipBackground),n("--ogx-toolbar-chip-text",o.chipText),n("--ogx-toolbar-chip-active-bg",o.chipActiveBackground),n("--ogx-toolbar-chip-active-text",o.chipActiveText)}if(e.overlays){const o=e.overlays;n("--ogx-overlay-background",o.background),n("--ogx-overlay-text",o.text),n("--ogx-overlay-border",o.border),n("--ogx-overlay-shadow",o.shadow),n("--ogx-overlay-item-hover-bg",o.itemHoverBackground),n("--ogx-overlay-item-hover-text",o.itemHoverText),n("--ogx-overlay-item-selected-bg",o.itemSelectedBackground),n("--ogx-overlay-item-selected-text",o.itemSelectedText),n("--ogx-overlay-item-danger-bg",o.itemDangerBackground),n("--ogx-overlay-item-danger-text",o.itemDangerText),n("--ogx-overlay-font-family",o.fontFamily),n("--ogx-overlay-font-weight",o.fontWeight),n("--ogx-overlay-font-size",o.fontSize)}if(e.scrollbar){const o=e.scrollbar;n("--ogx-scrollbar-thumb",o.thumbColor),n("--ogx-scrollbar-track",o.trackColor),n("--ogx-scrollbar-size",o.size)}if(e.skeleton){const o=e.skeleton;n("--ogx-skeleton-base",o.baseColor),n("--ogx-skeleton-highlight",o.highlightColor)}return t}function Ph({theme:e,children:t,className:n,style:o}){const r=s.useMemo(()=>({...e.mode==="dark"?Ih:Os,...Ah(e)}),[e]);return d.jsx(Li.Provider,{value:e,children:d.jsx("div",{className:`ogx-theme-provider ${n||""}`.trim(),style:{...o,...r},children:t})})}const Th={mode:"dark",colors:{primary:"#60a5fa",primaryDark:"#3b82f6",primaryLight:"#1e3a5f",primaryFocus:"rgba(96, 165, 250, 0.4)"},grid:{background:"#0f172a",headerBackground:"#1e293b",headerText:"#e2e8f0",headerHoverBackground:"#334155",headerSortedBackground:"#1e3a5f",rowText:"#cbd5e1",borderColor:"#334155",rowHoverBackground:"#1e293b",rowAlternateBackground:"#162032",rowSelectedBackground:"#1e3a5f",rowSelectedHoverBackground:"#1d4ed8",cellFocusBorder:"#60a5fa",rangeBackground:"rgba(96, 165, 250, 0.18)",rangeBorder:"#60a5fa",checkboxBg:"#1e293b",checkboxBorder:"#64748b"},borders:{color:"#334155",colorHover:"#475569"},shadows:{sm:"0 1px 2px 0 rgba(0, 0, 0, 0.3)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.3)"},toolbar:{background:"#1e293b",text:"#cbd5e1",border:"#334155",buttonBackground:"transparent",buttonHoverBackground:"#334155",buttonText:"#e2e8f0",buttonPrimaryBackground:"#3b82f6",buttonPrimaryHoverBackground:"#2563eb",buttonPrimaryText:"#ffffff",buttonDangerBackground:"rgba(239, 68, 68, 0.15)",buttonDangerHoverBackground:"rgba(239, 68, 68, 0.25)",buttonDangerText:"#fca5a5",inputBackground:"#0f172a",inputText:"#f8fafc",inputBorder:"#334155",inputFocusBorder:"#60a5fa",inputFocusShadow:"0 0 0 3px rgba(96, 165, 250, 0.2)",chipBackground:"#1e293b",chipText:"#94a3b8",chipActiveBackground:"rgba(96, 165, 250, 0.2)",chipActiveText:"#60a5fa"},overlays:{background:"#1e293b",text:"#f8fafc",border:"#334155",shadow:"0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3)",itemHoverBackground:"#334155",itemHoverText:"#ffffff",itemSelectedBackground:"rgba(96, 165, 250, 0.15)",itemSelectedText:"#60a5fa",itemDangerBackground:"rgba(239, 68, 68, 0.15)",itemDangerText:"#fca5a5"},scrollbar:{thumbColor:"rgba(148, 163, 184, 0.2)",trackColor:"transparent"},skeleton:{baseColor:"#1e293b",highlightColor:"#334155"}},Fh={colors:{primary:"#e11d48",primaryDark:"#be123c",primaryLight:"#fff1f2",primaryFocus:"rgba(225, 29, 72, 0.4)"},grid:{headerBackground:"#fff1f2",headerHoverBackground:"#ffe4e6",headerSortedBackground:"#fecdd3",rowAlternateBackground:"#fff8f8",rowSelectedBackground:"#ffe4e6",rowSelectedHoverBackground:"#fecdd3",cellFocusBorder:"#e11d48",rangeBackground:"rgba(225, 29, 72, 0.10)",rangeBorder:"#e11d48"}},Oh={colors:{primary:"#059669",primaryDark:"#047857",primaryLight:"#ecfdf5",primaryFocus:"rgba(5, 150, 105, 0.4)"},grid:{headerBackground:"#ecfdf5",headerHoverBackground:"#d1fae5",headerSortedBackground:"#a7f3d0",rowAlternateBackground:"#f6fdf9",rowSelectedBackground:"#d1fae5",rowSelectedHoverBackground:"#a7f3d0",cellFocusBorder:"#059669",rangeBackground:"rgba(5, 150, 105, 0.12)",rangeBorder:"#059669"}},Dh={colors:{primary:"#d97706",primaryDark:"#b45309",primaryLight:"#fffbeb",primaryFocus:"rgba(217, 119, 6, 0.4)"},grid:{headerBackground:"#fffbeb",headerHoverBackground:"#fef3c7",headerSortedBackground:"#fde68a",rowAlternateBackground:"#fffdf5",rowSelectedBackground:"#fef3c7",rowSelectedHoverBackground:"#fde68a",cellFocusBorder:"#d97706",rangeBackground:"rgba(217, 119, 6, 0.12)",rangeBorder:"#d97706"}},$h={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px",cellFontSize:"12px",headerFontSize:"12px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function Gh(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}function Ds(e,t){try{const n=t.getItem(e);return n?JSON.parse(n):void 0}catch{return}}function Hh(e,t,n,o){try{const r=n?Object.fromEntries(Object.entries(t).filter(([i])=>n.includes(i))):t;o.setItem(e,JSON.stringify(r))}catch{}}function Bh(e){const t=typeof e=="string"?{key:e}:e,{key:n,debounceMs:o=300,include:r,storage:i}=t,[l]=s.useState(Gh),a=i??l,c=s.useRef(r),u=s.useRef(a);s.useLayoutEffect(()=>{c.current=r,u.current=a});const[g,m]=s.useState(()=>({key:n,state:a?Ds(n,a):void 0}));let x=g.state;g.key!==n&&(x=a?Ds(n,a):void 0,m({key:n,state:x}));const y=s.useRef(null),p=s.useRef(null),f=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null);const w=p.current;p.current=null;const C=u.current;w&&C&&Hh(w.key,w.state,c.current,C)},[]),h=s.useCallback(w=>{p.current&&p.current.key!==n&&f(),p.current={key:n,state:w},y.current&&clearTimeout(y.current),y.current=setTimeout(f,o)},[n,f,o]);s.useEffect(()=>f,[f]);const b=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null),p.current=null;const w=u.current;if(w)try{w.removeItem(n)}catch{}},[n]);return s.useMemo(()=>({initialState:x,onStateChange:h,clearState:b}),[x,h,b])}_e.Button=Qe,_e.Cell=ql,_e.CellSelectionStats=Zl,_e.Checkbox=ft,_e.ColumnVisibilityPanel=Qo,_e.DataGrid=Sp,_e.DataGridThemeProvider=Ph,_e.FilterPanel=ps,_e.GridToolbar=Vp,_e.GridTooltip=gn,_e.Header=Kl,_e.Input=et,_e.Pagination=er,_e.Row=jn,_e.Skeleton=_p,_e.amberTheme=Dh,_e.compactTheme=$h,_e.darkTheme=Th,_e.emeraldTheme=Oh,_e.exportToCsv=lh,_e.exportToExcel=ch,_e.exportToExcelAdvanced=Mh,_e.exportToJson=dh,_e.exportToPdf=oh,_e.formatAggregationValue=nn,_e.printGrid=ph,_e.roseTheme=Fh,_e.useAggregation=Ll,_e.useGridApiRef=zp,_e.useGridStateStorage=Bh,_e.usePivot=Nh,Object.defineProperty(_e,Symbol.toStringTag,{value:"Module"})}));
|
|
46
|
+
</style></head><body>`;r&&(x+=`<h1>${Fe(r)}</h1>`),x+="<table><thead><tr>",g.forEach(f=>{x+=`<th>${Fe(f.headerName||f.field)}</th>`}),x+="</tr></thead><tbody>";const y=(f,w,b="",m=!1)=>{const{text:C}=hn(f,w),E=w.type==="image"?xh(C):null;if(E!==null){const _=`<img src="${Fe(E)}" alt="${Fe(w.headerName||w.field)}" style="max-height:40px;border-radius:4px;">`;return m?`<td><div style="display:flex;justify-content:center;">${_}</div></td>`:`<td>${_}</td>`}return`<td>${b}${Fe(C)}</td>`};if(cn(u,i))u.forEach(f=>{const w=" ".repeat(f.depth*4);if(f.type==="group-header")x+=`<tr class="group-header"><td colspan="${g.length}">${w}${Fe(qt(f,t))}</td></tr>`;else if(f.type==="leaf"&&f.row){const b=f.row;x+="<tr>",g.forEach((m,C)=>{x+=y(b,m,C===0?w:"")}),x+="</tr>"}else if((f.type==="group-subtotal"||f.type==="grand-total")&&f.aggregatedValues){const b=f.type==="grand-total",m=Yt(g,f.aggregatedValues,p);x+=`<tr class="${b?"grand-total":"group-subtotal"}">`,g.forEach((C,E)=>{if(E===0){x+=`<td>${b?"":w}${Fe(Wt(b?"Grand Total":"Subtotal",m[0]))}</td>`;return}x+=m[E]?`<td style="text-align:right;">${Fe(m[E])}</td>`:"<td></td>"}),x+="</tr>"}});else{const f=an(e,i,l);if(f.length===0){o.document.body.innerHTML="<h3>No rows to export</h3>";return}f.forEach(b=>{x+="<tr>",g.forEach(m=>{x+=y(b,m,"",!0)}),x+="</tr>"});const w=Bt(f,dt(i),t,c,a);w&&(x+='<tfoot><tr style="font-size:11px;color:#666;background-color:#f5f5f5;">',g.forEach(b=>{x+=p[b.field]?`<td style="text-align:right;font-weight:bold;">${Fe(p[b.field].toUpperCase())}</td>`:"<td></td>"}),x+='</tr><tr style="font-weight:bold;background-color:#f5f5f5;">',Yt(g,w,p).forEach(b=>{x+=b?`<td style="text-align:right;">${Fe(b)}</td>`:"<td></td>"}),x+="</tr></tfoot>")}x+="</tbody></table></body></html>",o.document.open(),o.document.write(x),o.document.close(),o.document.title=r||"Print Preview",o.focus();let h=!1;o.onload=()=>{h||(h=!0,o.print(),setTimeout(()=>{o.close()},100))},setTimeout(()=>{!h&&o&&!o.closed&&(h=!0,o.print(),setTimeout(()=>{o.closed||o.close()},100))},500)}catch(r){if(console.error("Print generation failed:",r),o&&!o.closed){const i=r instanceof Error?r.message:String(r);o.document.body.innerHTML=`<div style="color: red; padding: 20px;"><h3>Error Generating Print Preview</h3><p>${Fe(i)}</p></div>`}}}function wr(e,t,n){const o=new Blob([e],{type:n}),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}function Ch(e,t){return e.type==="number"?"number":e.type==="boolean"?"boolean":e.type==="date"?"date":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t instanceof Date?"date":"string"}function mn(e){return Number.isNaN(e.getTime())?null:new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}const vh=/^(\d{4})-(\d{2})-(\d{2})$/,Sh=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$/i,_h=/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i;function kh(e){if(e instanceof Date)return mn(e);if(typeof e=="number")return Number.isFinite(e)?mn(new Date(e)):null;if(typeof e!="string")return;const t=e.trim(),n=vh.exec(t);if(n){const[o,r,i]=[Number(n[1]),Number(n[2]),Number(n[3])],l=new Date(Date.UTC(o,r-1,i));return l.getUTCMonth()===r-1&&l.getUTCDate()===i?l:void 0}if(Sh.test(t)){const o=new Date(t.replace(" ","T"));return Number.isNaN(o.getTime())?void 0:mn(o)}}function Eh(e,t){if(t==null||t==="")return null;if(e==="number"){if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="bigint"){const n=Number(t);return Number.isSafeInteger(n)?n:void 0}if(typeof t=="string"&&_h.test(t.trim())){const n=Number(t.trim());return Number.isFinite(n)?n:void 0}return}if(e==="boolean"){if(typeof t=="boolean")return t;if(typeof t=="string"){const n=t.trim().toLowerCase();if(n==="true")return!0;if(n==="false")return!1}return}return kh(t)}function Ps(e){if(e==null)return null;if(typeof e=="string"||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)?e:null;if(e instanceof Date)return mn(e);if(typeof e=="object")try{return JSON.stringify(e)??String(e)}catch{return String(e)}return String(e)}function Mh(e,t){const n=dn(e,t),o=Ch(t,n);if(o!=="string"){const r=Eh(o,n);if(r!=null)return r;if(!t.valueFormatter)return r===null?null:Ps(n)}return t.valueFormatter?un(e,t,n):Ps(n)}const Ts="#,##0",Ih="#,##0.##";function Nh(e){return Number.isInteger(e)?Ts:Ih}function As(e,t){if(t?.numFmt)return t.numFmt;if(e.type==="date")return"yyyy-mm-dd"}function Fs(e,t,n){if(!(t?.numFmt||typeof n!="number"||e.type!=="number"))return Nh(n)}function Lh(e,t){if(t!=null)return t;const n=e.width??120;return Math.min(60,Math.max(8,(n-5)/7))}function Ph(e){return e.length>=8&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71?"png":e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255?"jpeg":e.length>=6&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56?"gif":null}function Os(e,t){const n=dn(e,t);return typeof n=="string"&&n?n:null}async function Th(e){const t=await Promise.allSettled(e.map(async o=>{let r;if(o.startsWith("data:")){const l=o.slice(o.indexOf(",")+1),c=atob(l);r=new Uint8Array(c.length);for(let a=0;a<c.length;a++)r[a]=c.charCodeAt(a)}else{const l=await fetch(o,{mode:"cors"});if(!l.ok)throw new Error(`HTTP ${l.status}`);r=new Uint8Array(await l.arrayBuffer())}const i=Ph(r);if(!i)throw new Error("unsupported image format (only PNG, JPEG and GIF can be embedded)");return{url:o,buffer:r.slice().buffer,ext:i}})),n=new Map;return t.forEach((o,r)=>{o.status==="fulfilled"?n.set(o.value.url,{buffer:o.value.buffer,extension:o.value.ext}):console.warn(`[exportToExcelAdvanced] Cannot embed image "${e[r]}" (CORS/network error or unsupported format — raw URL written as fallback):`,o.reason)}),n}async function Ah(e,t,n={}){const{fileName:o="export.xlsx",sheets:r,columnStyles:i={},headerFillColor:l="#f1f5f9",headerTextColor:c="#334155",headerFontSize:a=10,bodyFontSize:u=10,aggregationResult:g=null,aggregationModel:p=null,selectedRows:x,getRowId:y,groupedRows:h,groupHeaderFillColor:f="#e8eaf6",groupSubtotalFillColor:w="#f0f4ff"}=n;let b;try{b=(await import("exceljs")).default}catch{throw new Error("exportToExcelAdvanced requires 'exceljs'. Run: npm install exceljs")}const m=new b.Workbook;m.creator="OpenGridX",m.created=new Date;const C=t,E=kt(C),_=e,I=dt(x)?cl(_,x,y):[],M=r??[{name:"Data",rows:"all",includeHeaders:!0,includeSummary:!1}],S=new Set,F=new Map,P=(v,W)=>{const B=W[v.field],Q=p?.[v.field];if(B==null)return{value:null};const $=Jr(v,Q,B);return typeof $=="number"?Number.isFinite($)?Yr(Q)?{value:$,numFmt:Ts}:{value:$,numFmt:Fs(v,i[v.field],$)}:{value:null}:$ instanceof Date?{value:mn($)}:{value:Uo(v,Q,B,W)}};for(const v of M){if("type"in v&&v.type==="summary"){if(!g||!p)continue;const J=m.addWorksheet(jo(v.name??"Summary",S));J.addRow(["Summary / Aggregation Totals"]),J.getRow(1).font={bold:!0,size:a+2,color:{argb:Ve(c)}},J.addRow([]),J.addRow(["Column","Function","Value"]).eachCell(A=>{A.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(l)}},A.font={bold:!0,size:a,color:{argb:Ve(c)}},A.border=Ds()}),E.forEach(A=>{const G=p[A.field];if(G==null||g[A.field]==null)return;const{value:D,numFmt:U}=P(A,g),ee=J.addRow([A.headerName??A.field,G.toUpperCase(),D]).getCell(3),Z=U??As(A,i[A.field]);Z&&(ee.numFmt=Z),ee.alignment={horizontal:"right"},ee.font={bold:!0,size:u}}),J.getColumn(1).width=20,J.getColumn(2).width=12,J.getColumn(3).width=18;continue}const W=v,{name:B="Data",rows:Q="all",includeHeaders:$=!0,includeSummary:z=!1,autoFilter:V=!0,frozenHeader:ie=!0,alternateRowColor:te="#f8fafc"}=W,ce=Q==="all"&&!!(h&&h.length>0),oe=Q==="selected"?I:ce?h.flatMap(J=>J.type==="leaf"&&J.row?[J.row]:[]):_,de=E.filter(J=>i[J.field]?.embedImage);if(de.length>0){const J=[],O=new Set;if(oe.forEach(A=>{de.forEach(G=>{const D=Os(A,G);D&&!F.has(D)&&!O.has(D)&&(J.push(D),O.add(D))})}),J.length>0){const A=await Th(J);for(const[G,{buffer:D,extension:U}]of A){const q=m.addImage({buffer:D,extension:U});F.set(G,q)}}}const X=m.addWorksheet(jo(B,S));X.columns=E.map(J=>({key:J.field,width:Lh(J,i[J.field]?.width),style:{numFmt:As(J,i[J.field])}}));const ne=(J,O)=>{E.forEach((A,G)=>O(J.getCell(G+1),A,G+1))};if($){const J=E.map(A=>A.headerName??A.field),O=X.addRow(J);O.height=20,ne(O,(A,G)=>{A.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(l)}},A.font={bold:!0,size:a,color:{argb:Ve(c)}},A.alignment={horizontal:i[G.field]?.alignment??(G.type==="number"?"right":"left"),vertical:"middle"},A.border=Ds()}),V&&(X.autoFilter={from:{row:1,column:1},to:{row:1,column:E.length}}),ie?X.views=[{state:"frozen",ySplit:1,showGridLines:!1}]:X.views=[{showGridLines:!1}]}let se=$?1:0;const Y=(J,O,A)=>{const G=E.map(q=>i[q.field]?.embedImage?"":Mh(J,q)),D=X.addRow(G);D.font={size:u},A>0&&(D.outlineLevel=A);const U=!!te&&O%2===1;if(ne(D,(q,ee,Z)=>{const j=Fs(ee,i[ee.field],G[Z-1]);j&&(q.numFmt=j),U&&te&&(q.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(te)}}),q.alignment={horizontal:i[ee.field]?.alignment??(ee.type==="number"?"right":"left"),vertical:"middle"},q.border={bottom:{style:"thin",color:{argb:"FFf1f5f9"}}}}),de.length>0){const q=de.reduce((j,re)=>Math.max(j,i[re.field]?.imageHeight??40),0),ee=Math.ceil(q/1.333),Z=ee*1.333;D.height=ee,de.forEach(j=>{const re=E.indexOf(j),me=Os(J,j),pe=me?F.get(me):void 0;if(pe===void 0){D.getCell(re+1).value=me??"";return}const K=i[j.field],fe=K?.imageWidth??40,we=K?.imageHeight??40,be=(X.getColumn(re+1).width??8)*7+5,Ce=Math.max(0,be-fe)/2,ye=Math.max(0,Z-we)/2;X.addImage(pe,{tl:{col:re,row:se,nativeColOff:Math.floor(Ce*9525),nativeRowOff:Math.floor(ye*9525)},ext:{width:fe,height:we},editAs:"oneCell"})})}else D.height=16;se++},H=J=>qt(J,C),R=(J,O,A,G,D)=>{const U=E.map((ee,Z)=>Z===0&&O[ee.field]==null?{value:J}:P(ee,O)),q=X.addRow(U.map(ee=>ee.value));q.height=18,G>0&&(q.outlineLevel=G),q.font={bold:D,italic:!D,size:u,color:{argb:Ve(c)}},ne(q,(ee,Z,j)=>{const re=U[j-1].numFmt;re&&(ee.numFmt=re),ee.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(A)}},ee.alignment={horizontal:j===1?"left":Z.type==="number"?"right":"left",vertical:"middle"},ee.border=$s()}),se++};let ae=!1;if(ce){let J=0;h.forEach(O=>{if(O.type==="group-header"){const A=X.addRow([H(O)]);A.height=18,O.depth>0&&(A.outlineLevel=O.depth),A.font={bold:!0,size:u,color:{argb:Ve(c)}};for(let G=1;G<=E.length;G++)A.getCell(G).fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(f)}};A.getCell(1).alignment={horizontal:"left",vertical:"middle",indent:O.depth},se++,J=0}else O.type==="leaf"&&O.row?Y(O.row,J++,O.depth):O.type==="group-subtotal"&&O.aggregatedValues?R("Subtotal",O.aggregatedValues,w,O.depth,!1):O.type==="grand-total"&&O.aggregatedValues&&(R("Grand Total",O.aggregatedValues,l,0,!0),ae=!0)}),X.properties.outlineProperties={summaryBelow:!0,summaryRight:!1}}else oe.forEach((J,O)=>Y(J,O,0));const ge=Bt(oe,Q==="selected",C,g,p);if(z&&!ae&&ge&&p){const J=E.map(D=>{const U=p[D.field];return U?U.toUpperCase():""}),O=X.addRow(J);O.height=16,O.font={size:u-1,italic:!0,color:{argb:"FF94a3b8"}},ne(O,D=>{D.alignment={horizontal:"right",vertical:"middle"},D.border={top:{style:"thin",color:{argb:"FFcbd5e1"}}}});const A=E.map(D=>p[D.field]==null?{value:null}:P(D,ge)),G=X.addRow(A.map(D=>D.value));G.height=18,G.font={bold:!0,size:u,color:{argb:Ve(c)}},ne(G,(D,U,q)=>{const ee=A[q-1].numFmt;ee&&(D.numFmt=ee),D.fill={type:"pattern",pattern:"solid",fgColor:{argb:Ve(l)}},D.alignment={horizontal:"right",vertical:"middle"},D.border=$s()})}}const L=await m.xlsx.writeBuffer(),k=new Blob([L],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),N=URL.createObjectURL(k),T=document.createElement("a");T.href=N,T.download=o.endsWith(".xlsx")?o:`${o}.xlsx`,document.body.appendChild(T),T.click(),document.body.removeChild(T),URL.revokeObjectURL(N)}function Ve(e){const t=e.replace("#","");return t.length===3?"FF"+t.split("").map(n=>n+n).join(""):t.length===6?"FF"+t:"FF"+t.padEnd(6,"0")}function Ds(){return{bottom:{style:"medium",color:{argb:"FFcbd5e1"}}}}function $s(){return{top:{style:"medium",color:{argb:"FFcbd5e1"}}}}function Fh(e,t,n,o){return s.useMemo(()=>o?vi(e,t,n):To,[e,t,n,o])}const Gs={"--ogx-grid-row-selected-background":"var(--ogx-color-primary-light)","--ogx-grid-row-selected-hover-background":"color-mix(in srgb, var(--ogx-color-primary) 14%, var(--ogx-color-primary-light))","--ogx-grid-cell-focus-border":"var(--ogx-color-primary)","--ogx-range-background":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-range-border":"var(--ogx-color-primary)","--ogx-fill-handle-color":"var(--ogx-range-border)","--ogx-toolbar-btn-primary-bg":"var(--ogx-color-primary)","--ogx-toolbar-btn-primary-hover":"var(--ogx-color-primary-dark)","--ogx-toolbar-input-focus-border":"var(--ogx-color-primary)","--ogx-toolbar-input-focus-shadow":"0 0 0 3px color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-bg":"color-mix(in srgb, var(--ogx-color-primary) 12%, transparent)","--ogx-toolbar-chip-active-text":"var(--ogx-color-primary-dark)","--ogx-overlay-item-selected-bg":"color-mix(in srgb, var(--ogx-color-primary) 8%, transparent)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary-dark)"},Hs={"--ogx-color-primary":"#3b82f6","--ogx-color-primary-dark":"#2563eb","--ogx-color-primary-light":"#eff6ff","--ogx-color-primary-focus":"rgba(59, 130, 246, 0.5)","--ogx-color-secondary":"#8b5cf6","--ogx-color-secondary-dark":"#7c3aed","--ogx-color-secondary-light":"#f5f3ff","--ogx-color-white":"#ffffff","--ogx-color-black":"#0f172a","--ogx-color-gray-50":"#f8fafc","--ogx-color-gray-100":"#f1f5f9","--ogx-color-gray-200":"#e2e8f0","--ogx-color-gray-300":"#cbd5e1","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#64748b","--ogx-color-gray-600":"#475569","--ogx-color-gray-700":"#334155","--ogx-color-gray-800":"#1e293b","--ogx-color-gray-900":"#0f172a","--ogx-border-color":"#e2e8f0","--ogx-border-color-hover":"#cbd5e1","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.05)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02)","--ogx-grid-background":"#ffffff","--ogx-grid-border-color":"#e2e8f0","--ogx-grid-header-background":"#f8fafc","--ogx-grid-header-text":"#334155","--ogx-grid-header-hover-background":"#f1f5f9","--ogx-grid-header-sorted-background":"#f8fafc","--ogx-grid-row-text":"#1e293b","--ogx-grid-row-hover-background":"#f8fafc","--ogx-grid-row-alternate-background":"transparent","--ogx-checkbox-bg":"#ffffff","--ogx-checkbox-border":"#94a3b8","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.05)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.05)",...{"--ogx-toolbar-background":"var(--ogx-grid-header-background)","--ogx-toolbar-text":"var(--ogx-grid-header-text)","--ogx-toolbar-border":"var(--ogx-grid-border-color)","--ogx-toolbar-btn-bg":"transparent","--ogx-toolbar-btn-hover":"var(--ogx-grid-header-hover-background)","--ogx-toolbar-btn-text":"var(--ogx-grid-header-text)","--ogx-toolbar-input-bg":"var(--ogx-grid-background)","--ogx-toolbar-input-text":"var(--ogx-grid-row-text)","--ogx-toolbar-chip-bg":"transparent","--ogx-toolbar-chip-text":"var(--ogx-grid-row-text)"},"--ogx-toolbar-btn-primary-text":"#ffffff","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-text":"#ef4444","--ogx-toolbar-input-border":"#cbd5e1","--ogx-overlay-background":"#ffffff","--ogx-overlay-text":"#1e293b","--ogx-overlay-border":"#e2e8f0","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.06)","--ogx-overlay-item-hover-bg":"#f8fafc","--ogx-overlay-item-hover-text":"#0f172a","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.08)","--ogx-overlay-item-danger-text":"#ef4444","--ogx-scrollbar-thumb":"#cbd5e1","--ogx-scrollbar-track":"transparent","--ogx-scrollbar-size":"8px","--ogx-skeleton-base":"#f1f5f9","--ogx-skeleton-highlight":"#ffffff",...Gs},Oh={...Hs,"--ogx-color-primary":"#60a5fa","--ogx-color-primary-dark":"#3b82f6","--ogx-color-primary-light":"#1e3a5f","--ogx-color-primary-focus":"rgba(96, 165, 250, 0.4)","--ogx-color-white":"#0f172a","--ogx-color-black":"#f8fafc","--ogx-color-gray-50":"#1e293b","--ogx-color-gray-100":"#334155","--ogx-color-gray-200":"#475569","--ogx-color-gray-300":"#64748b","--ogx-color-gray-400":"#94a3b8","--ogx-color-gray-500":"#cbd5e1","--ogx-color-gray-600":"#e2e8f0","--ogx-color-gray-700":"#e2e8f0","--ogx-color-gray-800":"#f1f5f9","--ogx-color-gray-900":"#f8fafc","--ogx-border-color":"#334155","--ogx-border-color-hover":"#475569","--ogx-shadow-sm":"0 1px 2px 0 rgba(0, 0, 0, 0.3)","--ogx-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.3)","--ogx-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.3)","--ogx-grid-background":"#0f172a","--ogx-grid-border-color":"#334155","--ogx-grid-header-background":"#1e293b","--ogx-grid-header-text":"#e2e8f0","--ogx-grid-header-hover-background":"#334155","--ogx-grid-header-sorted-background":"#1e3a5f","--ogx-grid-row-text":"#cbd5e1","--ogx-grid-row-hover-background":"#1e293b","--ogx-grid-row-alternate-background":"#162032","--ogx-checkbox-bg":"#1e293b","--ogx-checkbox-border":"#64748b","--ogx-grid-pinned-left-shadow":"4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-grid-pinned-right-shadow":"-4px 0 24px -4px rgba(0, 0, 0, 0.3)","--ogx-toolbar-btn-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-toolbar-btn-danger-hover":"rgba(239, 68, 68, 0.25)","--ogx-toolbar-btn-danger-text":"#fca5a5","--ogx-toolbar-input-border":"#334155","--ogx-overlay-background":"#1e293b","--ogx-overlay-text":"#cbd5e1","--ogx-overlay-border":"#334155","--ogx-overlay-shadow":"0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3), 0 0 0 1px rgba(0,0,0,0.2)","--ogx-overlay-item-hover-bg":"#334155","--ogx-overlay-item-hover-text":"#f1f5f9","--ogx-overlay-item-danger-bg":"rgba(239, 68, 68, 0.15)","--ogx-overlay-item-danger-text":"#fca5a5","--ogx-scrollbar-thumb":"#475569","--ogx-skeleton-base":"#1e293b","--ogx-skeleton-highlight":"#334155",...Gs,"--ogx-toolbar-chip-active-text":"var(--ogx-color-primary)","--ogx-overlay-item-selected-text":"var(--ogx-color-primary)"},Dh=[50,100,200,300,400,500,600,700,800,900];function $h(e){const t={};function n(o,r){r!==void 0&&(t[o]=r)}if(e.colors){const o=e.colors;if(n("--ogx-color-primary",o.primary),n("--ogx-color-primary-dark",o.primaryDark),n("--ogx-color-primary-light",o.primaryLight),n("--ogx-color-primary-focus",o.primaryFocus),n("--ogx-color-secondary",o.secondary),n("--ogx-color-secondary-dark",o.secondaryDark),n("--ogx-color-secondary-light",o.secondaryLight),n("--ogx-color-success",o.success),n("--ogx-color-warning",o.warning),n("--ogx-color-error",o.error),n("--ogx-color-info",o.info),n("--ogx-color-white",o.white),n("--ogx-color-black",o.black),o.gray)for(const r of Dh)n(`--ogx-color-gray-${r}`,o.gray[r])}if(e.typography){const o=e.typography;n("--ogx-font-family",o.fontFamily),n("--ogx-font-family-mono",o.fontFamilyMono),n("--ogx-font-size-xs",o.fontSizeXs),n("--ogx-font-size-sm",o.fontSizeSm),n("--ogx-font-size-md",o.fontSizeMd),n("--ogx-font-size-lg",o.fontSizeLg),n("--ogx-font-size-xl",o.fontSizeXl)}if(e.spacing){const o=e.spacing;n("--ogx-spacing-xs",o.xs),n("--ogx-spacing-sm",o.sm),n("--ogx-spacing-md",o.md),n("--ogx-spacing-lg",o.lg),n("--ogx-spacing-xl",o.xl),n("--ogx-spacing-xxl",o.xxl)}if(e.borders){const o=e.borders;n("--ogx-border-width-thin",o.widthThin),n("--ogx-border-width-medium",o.widthMedium),n("--ogx-border-width-thick",o.widthThick),n("--ogx-border-radius-sm",o.radiusSm),n("--ogx-border-radius-md",o.radiusMd),n("--ogx-border-radius-lg",o.radiusLg),n("--ogx-border-radius-xl",o.radiusXl),n("--ogx-border-color",o.color),n("--ogx-border-color-hover",o.colorHover)}if(e.shadows){const o=e.shadows;n("--ogx-shadow-sm",o.sm),n("--ogx-shadow-md",o.md),n("--ogx-shadow-lg",o.lg),n("--ogx-shadow-xl",o.xl)}if(e.grid){const o=e.grid;n("--ogx-grid-row-height-compact",o.rowHeightCompact),n("--ogx-grid-row-height-standard",o.rowHeightStandard),n("--ogx-row-height",o.rowHeightStandard),n("--ogx-grid-row-height-comfortable",o.rowHeightComfortable),n("--ogx-grid-header-height",o.headerHeight),n("--ogx-header-height",o.headerHeight),n("--ogx-grid-cell-padding-x",o.cellPaddingX),n("--ogx-grid-cell-padding-y",o.cellPaddingY),n("--ogx-grid-cell-font-size",o.cellFontSize),n("--ogx-grid-header-font-size",o.headerFontSize),n("--ogx-grid-header-font-family",o.headerFontFamily),n("--ogx-grid-header-font-weight",o.headerFontWeight),n("--ogx-grid-cell-font-family",o.cellFontFamily),n("--ogx-grid-cell-font-weight",o.cellFontWeight),n("--ogx-grid-header-padding-x",o.headerPaddingX),n("--ogx-grid-border-width",o.borderWidth),n("--ogx-grid-border-radius",o.borderRadius),n("--ogx-grid-column-divider-width",o.columnDividerWidth),n("--ogx-grid-header-column-divider-width",o.headerColumnDividerWidth),n("--ogx-grid-row-divider-width",o.rowDividerWidth),n("--ogx-grid-column-divider-color",o.columnDividerColor),n("--ogx-grid-row-divider-color",o.rowDividerColor),n("--ogx-grid-background",o.background),n("--ogx-grid-border-color",o.borderColor),n("--ogx-grid-header-background",o.headerBackground),n("--ogx-grid-header-text",o.headerText),n("--ogx-grid-header-hover-background",o.headerHoverBackground),n("--ogx-grid-header-sorted-background",o.headerSortedBackground),n("--ogx-grid-row-text",o.rowText),n("--ogx-grid-row-hover-background",o.rowHoverBackground),n("--ogx-grid-row-alternate-background",o.rowAlternateBackground),n("--ogx-grid-row-selected-background",o.rowSelectedBackground),n("--ogx-grid-row-selected-hover-background",o.rowSelectedHoverBackground),n("--ogx-grid-cell-focus-border",o.cellFocusBorder),n("--ogx-range-background",o.rangeBackground),n("--ogx-range-border",o.rangeBorder),n("--ogx-fill-handle-color",o.fillHandleColor),n("--ogx-grid-pinned-left-shadow",o.pinnedLeftShadow),n("--ogx-grid-pinned-right-shadow",o.pinnedRightShadow),n("--ogx-checkbox-bg",o.checkboxBg),n("--ogx-checkbox-border",o.checkboxBorder)}if(e.transitions){const o=e.transitions;n("--ogx-transition-duration-fast",o.durationFast),n("--ogx-transition-duration-normal",o.durationNormal),n("--ogx-transition-duration-slow",o.durationSlow),n("--ogx-transition-easing",o.easing)}if(e.toolbar){const o=e.toolbar;n("--ogx-toolbar-background",o.background),n("--ogx-toolbar-text",o.text),n("--ogx-toolbar-border",o.border),n("--ogx-toolbar-btn-bg",o.buttonBackground),n("--ogx-toolbar-btn-hover",o.buttonHoverBackground),n("--ogx-toolbar-btn-text",o.buttonText),n("--ogx-toolbar-btn-primary-bg",o.buttonPrimaryBackground),n("--ogx-toolbar-btn-primary-hover",o.buttonPrimaryHoverBackground),n("--ogx-toolbar-btn-primary-text",o.buttonPrimaryText),n("--ogx-toolbar-btn-danger-bg",o.buttonDangerBackground),n("--ogx-toolbar-btn-danger-hover",o.buttonDangerHoverBackground),n("--ogx-toolbar-btn-danger-text",o.buttonDangerText),n("--ogx-toolbar-input-bg",o.inputBackground),n("--ogx-toolbar-input-text",o.inputText),n("--ogx-toolbar-input-border",o.inputBorder),n("--ogx-toolbar-input-focus-border",o.inputFocusBorder),n("--ogx-toolbar-input-focus-shadow",o.inputFocusShadow),n("--ogx-toolbar-chip-bg",o.chipBackground),n("--ogx-toolbar-chip-text",o.chipText),n("--ogx-toolbar-chip-active-bg",o.chipActiveBackground),n("--ogx-toolbar-chip-active-text",o.chipActiveText)}if(e.overlays){const o=e.overlays;n("--ogx-overlay-background",o.background),n("--ogx-overlay-text",o.text),n("--ogx-overlay-border",o.border),n("--ogx-overlay-shadow",o.shadow),n("--ogx-overlay-item-hover-bg",o.itemHoverBackground),n("--ogx-overlay-item-hover-text",o.itemHoverText),n("--ogx-overlay-item-selected-bg",o.itemSelectedBackground),n("--ogx-overlay-item-selected-text",o.itemSelectedText),n("--ogx-overlay-item-danger-bg",o.itemDangerBackground),n("--ogx-overlay-item-danger-text",o.itemDangerText),n("--ogx-overlay-font-family",o.fontFamily),n("--ogx-overlay-font-weight",o.fontWeight),n("--ogx-overlay-font-size",o.fontSize)}if(e.scrollbar){const o=e.scrollbar;n("--ogx-scrollbar-thumb",o.thumbColor),n("--ogx-scrollbar-track",o.trackColor),n("--ogx-scrollbar-size",o.size)}if(e.skeleton){const o=e.skeleton;n("--ogx-skeleton-base",o.baseColor),n("--ogx-skeleton-highlight",o.highlightColor)}return t}function Gh({theme:e,children:t,className:n,style:o}){const r=s.useMemo(()=>({...e.mode==="dark"?Oh:Hs,...$h(e)}),[e]);return d.jsx(Di.Provider,{value:e,children:d.jsx("div",{className:`ogx-theme-provider ${n||""}`.trim(),style:{...o,...r},children:t})})}const Hh={mode:"dark",colors:{primary:"#60a5fa",primaryDark:"#3b82f6",primaryLight:"#1e3a5f",primaryFocus:"rgba(96, 165, 250, 0.4)"},grid:{background:"#0f172a",headerBackground:"#1e293b",headerText:"#e2e8f0",headerHoverBackground:"#334155",headerSortedBackground:"#1e3a5f",rowText:"#cbd5e1",borderColor:"#334155",rowHoverBackground:"#1e293b",rowAlternateBackground:"#162032",rowSelectedBackground:"#1e3a5f",rowSelectedHoverBackground:"#1d4ed8",cellFocusBorder:"#60a5fa",rangeBackground:"rgba(96, 165, 250, 0.18)",rangeBorder:"#60a5fa",checkboxBg:"#1e293b",checkboxBorder:"#64748b"},borders:{color:"#334155",colorHover:"#475569"},shadows:{sm:"0 1px 2px 0 rgba(0, 0, 0, 0.3)",md:"0 4px 6px -1px rgba(0, 0, 0, 0.3)"},toolbar:{background:"#1e293b",text:"#cbd5e1",border:"#334155",buttonBackground:"transparent",buttonHoverBackground:"#334155",buttonText:"#e2e8f0",buttonPrimaryBackground:"#3b82f6",buttonPrimaryHoverBackground:"#2563eb",buttonPrimaryText:"#ffffff",buttonDangerBackground:"rgba(239, 68, 68, 0.15)",buttonDangerHoverBackground:"rgba(239, 68, 68, 0.25)",buttonDangerText:"#fca5a5",inputBackground:"#0f172a",inputText:"#f8fafc",inputBorder:"#334155",inputFocusBorder:"#60a5fa",inputFocusShadow:"0 0 0 3px rgba(96, 165, 250, 0.2)",chipBackground:"#1e293b",chipText:"#94a3b8",chipActiveBackground:"rgba(96, 165, 250, 0.2)",chipActiveText:"#60a5fa"},overlays:{background:"#1e293b",text:"#f8fafc",border:"#334155",shadow:"0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3)",itemHoverBackground:"#334155",itemHoverText:"#ffffff",itemSelectedBackground:"rgba(96, 165, 250, 0.15)",itemSelectedText:"#60a5fa",itemDangerBackground:"rgba(239, 68, 68, 0.15)",itemDangerText:"#fca5a5"},scrollbar:{thumbColor:"rgba(148, 163, 184, 0.2)",trackColor:"transparent"},skeleton:{baseColor:"#1e293b",highlightColor:"#334155"}},Bh={colors:{primary:"#e11d48",primaryDark:"#be123c",primaryLight:"#fff1f2",primaryFocus:"rgba(225, 29, 72, 0.4)"},grid:{headerBackground:"#fff1f2",headerHoverBackground:"#ffe4e6",headerSortedBackground:"#fecdd3",rowAlternateBackground:"#fff8f8",rowSelectedBackground:"#ffe4e6",rowSelectedHoverBackground:"#fecdd3",cellFocusBorder:"#e11d48",rangeBackground:"rgba(225, 29, 72, 0.10)",rangeBorder:"#e11d48"}},Wh={colors:{primary:"#059669",primaryDark:"#047857",primaryLight:"#ecfdf5",primaryFocus:"rgba(5, 150, 105, 0.4)"},grid:{headerBackground:"#ecfdf5",headerHoverBackground:"#d1fae5",headerSortedBackground:"#a7f3d0",rowAlternateBackground:"#f6fdf9",rowSelectedBackground:"#d1fae5",rowSelectedHoverBackground:"#a7f3d0",cellFocusBorder:"#059669",rangeBackground:"rgba(5, 150, 105, 0.12)",rangeBorder:"#059669"}},Vh={colors:{primary:"#d97706",primaryDark:"#b45309",primaryLight:"#fffbeb",primaryFocus:"rgba(217, 119, 6, 0.4)"},grid:{headerBackground:"#fffbeb",headerHoverBackground:"#fef3c7",headerSortedBackground:"#fde68a",rowAlternateBackground:"#fffdf5",rowSelectedBackground:"#fef3c7",rowSelectedHoverBackground:"#fde68a",cellFocusBorder:"#d97706",rangeBackground:"rgba(217, 119, 6, 0.12)",rangeBorder:"#d97706"}},zh={grid:{rowHeightCompact:"28px",rowHeightStandard:"36px",rowHeightComfortable:"48px",headerHeight:"40px",cellPaddingX:"8px",cellPaddingY:"4px",cellFontSize:"12px",headerFontSize:"12px"},typography:{fontSizeSm:"0.8rem",fontSizeMd:"0.875rem"}};function Kh(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}function Bs(e,t){try{const n=t.getItem(e);return n?JSON.parse(n):void 0}catch{return}}function Rh(e,t,n,o){try{const r=n?Object.fromEntries(Object.entries(t).filter(([i])=>n.includes(i))):t;o.setItem(e,JSON.stringify(r))}catch{}}function Uh(e){const t=typeof e=="string"?{key:e}:e,{key:n,debounceMs:o=300,include:r,storage:i}=t,[l]=s.useState(Kh),c=i??l,a=s.useRef(r),u=s.useRef(c);s.useLayoutEffect(()=>{a.current=r,u.current=c});const[g,p]=s.useState(()=>({key:n,state:c?Bs(n,c):void 0}));let x=g.state;g.key!==n&&(x=c?Bs(n,c):void 0,p({key:n,state:x}));const y=s.useRef(null),h=s.useRef(null),f=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null);const m=h.current;h.current=null;const C=u.current;m&&C&&Rh(m.key,m.state,a.current,C)},[]),w=s.useCallback(m=>{h.current&&h.current.key!==n&&f(),h.current={key:n,state:m},y.current&&clearTimeout(y.current),y.current=setTimeout(f,o)},[n,f,o]);s.useEffect(()=>f,[f]);const b=s.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null),h.current=null;const m=u.current;if(m)try{m.removeItem(n)}catch{}},[n]);return s.useMemo(()=>({initialState:x,onStateChange:w,clearState:b}),[x,w,b])}Se.Button=Qe,Se.Cell=ts,Se.CellSelectionStats=is,Se.Checkbox=ft,Se.ColumnVisibilityPanel=nr,Se.DataGrid=Lp,Se.DataGridThemeProvider=Gh,Se.FilterPanel=bs,Se.GridToolbar=qp,Se.GridTooltip=pn,Se.Header=Zl,Se.Input=et,Se.Pagination=or,Se.Row=qn,Se.Skeleton=Pp,Se.amberTheme=Vh,Se.compactTheme=zh,Se.darkTheme=Hh,Se.emeraldTheme=Wh,Se.exportToCsv=fh,Se.exportToExcel=hh,Se.exportToExcelAdvanced=Ah,Se.exportToJson=mh,Se.exportToPdf=ch,Se.formatAggregationValue=nn,Se.printGrid=yh,Se.roseTheme=Bh,Se.useAggregation=Gl,Se.useGridApiRef=Xp,Se.useGridStateStorage=Uh,Se.usePivot=Fh,Object.defineProperty(Se,Symbol.toStringTag,{value:"Module"})}));
|
|
47
47
|
//# sourceMappingURL=opengridx.umd.js.map
|