dts-universal-report-module 1.3.2 → 1.3.4
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/dist/index.esm.js +1864 -1826
- package/dist/index.js +15 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var pa=Object.defineProperty;var ha=(e,r,n)=>r in e?pa(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var Ci=(e,r,n)=>ha(e,typeof r!="symbol"?r+"":r,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),f=require("react"),fa=require("xlsx"),$=require("@mui/icons-material"),o=require("@mui/material"),bs=require("react-dom"),ma=require("@emotion/react"),Zt=require("react-dnd"),ni=require("react-dnd-html5-backend");function vs(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const sn=vs(f),No=vs(fa),ht={sort:{maxLevels:5},filter:{maxConditions:3,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json","pdf"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},Ss="urm_dev_config";function xa(){try{const e=localStorage.getItem(Ss);if(!e)return ht;const r=JSON.parse(e),n={sort:{...ht.sort,...r.sort},filter:{...ht.filter,...r.filter},columns:{...ht.columns,...r.columns},grouping:{...ht.grouping,...r.grouping},export:{...ht.export,...r.export},views:{...ht.views,...r.views},dates:{...ht.dates,...r.dates},display:{...ht.display,...r.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return ht}}function ga(e){try{localStorage.setItem(Ss,JSON.stringify(e))}catch{}}function ya(e,r,n){if(!n||!r)return e;const i={sort:{...e.sort,...r.sort},filter:{...e.filter,...r.filter},columns:{...e.columns,...r.columns},grouping:{...e.grouping,...r.grouping},export:{...e.export,...r.export},views:{...e.views,...r.views},dates:{...e.dates,...r.dates},display:{...e.display,...r.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const Cs=f.createContext(ht);function Dr(){return f.useContext(Cs)}const ba=/^\d{4}-\d{2}-\d{2}$/,va=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Sa=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ca=9783072e5,ja=41024448e5,wa=978307200,ka=4102444800;function za(e){return e==null||e===""?"unknown":typeof e=="number"?Number.isInteger(e)&&e>=Ca&&e<=ja?"timestamp_ms":Number.isInteger(e)&&e>=wa&&e<=ka?"timestamp_s":"unknown":typeof e!="string"?"unknown":va.test(e)||ba.test(e)?"iso":Sa.test(e.trim())?"locale_string":"unknown"}function Ta(e,r){const n=r.map(c=>c[e]).filter(c=>c!=null&&c!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const c of n){const l=za(c);i[l]++}const s=n.length,a=.7;for(const c of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[c]/s>=a)return c;return"unknown"}function Ba(e,r){if(e==null||e==="")return null;try{switch(r){case"timestamp_ms":{const n=new Date(Number(e));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(e)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(e));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(e));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const ji=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ia=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ue(e){return String(e).padStart(2,"0")}function Ea(e){const r=Date.now()-e.getTime(),n=Math.abs(r),i=r>0,s=Math.floor(n/1e3),a=Math.floor(s/60),c=Math.floor(a/60),l=Math.floor(c/24),p=Math.floor(l/7),x=Math.floor(l/30),y=Math.floor(l/365);let g;return s<60?g="just now":a<60?g=`${a} minute${a!==1?"s":""}`:c<24?g=`${c} hour${c!==1?"s":""}`:l<7?g=`${l} day${l!==1?"s":""}`:p<5?g=`${p} week${p!==1?"s":""}`:x<12?g=`${x} month${x!==1?"s":""}`:g=`${y} year${y!==1?"s":""}`,s<60?g:i?`${g} ago`:`in ${g}`}function Da(e,r){const n=e.getFullYear(),i=e.getMonth(),s=e.getDate(),a=e.getHours(),c=e.getMinutes();switch(r){case"YYYY-MM-DD":return`${n}-${Ue(i+1)}-${Ue(s)}`;case"DD/MM/YYYY":return`${Ue(s)}/${Ue(i+1)}/${n}`;case"MM/DD/YYYY":return`${Ue(i+1)}/${Ue(s)}/${n}`;case"MMM DD, YYYY":return`${ji[i]} ${Ue(s)}, ${n}`;case"DD MMM YYYY":return`${Ue(s)} ${ji[i]} ${n}`;case"MMMM D, YYYY":return`${Ia[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Ue(i+1)}-${Ue(s)} ${Ue(a)}:${Ue(c)}`;case"DD/MM/YYYY HH:mm":return`${Ue(s)}/${Ue(i+1)}/${n} ${Ue(a)}:${Ue(c)}`;case"MM/DD/YYYY HH:mm":return`${Ue(i+1)}/${Ue(s)}/${n} ${Ue(a)}:${Ue(c)}`;case"relative":return Ea(e);case"locale":return e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return e.toLocaleDateString()}}function $a(e,r,n){if(!n||r==="unknown")return String(e);const i=Ba(e,r);return!i||isNaN(i.getTime())?String(e):Da(i,n)}function _a(e){return e==null?"null":Array.isArray(e)?"array":typeof e=="object"?"object":typeof e=="number"?"number":typeof e=="boolean"?"boolean":typeof e=="string"?"string":"mixed"}function js(e,r="",n=0){if(n>2)return{[r]:e};const i={};for(const s of Object.keys(e)){const a=r?`${r}.${s}`:s,c=e[s];c!==null&&typeof c=="object"&&!Array.isArray(c)&&n<2?Object.assign(i,js(c,a,n+1)):i[a]=c}return i}function So(e){return e.map(r=>typeof r!="object"||r===null||Array.isArray(r)?r:js(r))}function go(e){if(!Array.isArray(e)||e.length===0)return[];const r=So(e),n=new Set;r.forEach(c=>{typeof c=="object"&&c!==null&&Object.keys(c).forEach(l=>n.add(l))});const i=[];n.forEach(c=>{const l=new Set;let p=0;r.forEach(v=>{typeof v=="object"&&v!==null&&c in v&&(p++,l.add(_a(v[c])))});const x=p===r.length,y=l.size>1&&!l.has("null");let g="mixed";if(l.size===1)g=Array.from(l)[0];else if(l.size===2&&l.has("null")){const v=Array.from(l).filter(S=>S!=="null");v.length===1&&(g=v[0])}i.push({name:c,type:g,required:x,hasConflict:y})});const a=r.slice(0,50);for(const c of i){if(c.type!=="string"&&c.type!=="number")continue;const l=Ta(c.name,a);l!=="unknown"&&(c.type="date",c.dateFormat=l)}return i}function wi(e,r){return!r||r.length===0?e:e.filter(n=>!r.includes(n.name))}function Oa(e){return e.some(r=>r.hasConflict)}function lt(e){if(!e)return"";const n=e.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function ki(e){return e==null}function Ma(e){return(r,n,i)=>{const s=ki(r),a=ki(n);if(s&&a)return 0;if(s)return 1;if(a)return-1;let c=0;switch(e){case"number":const l=Number(r),p=Number(n);c=l-p;break;case"boolean":c=(r?1:0)-(n?1:0);break;case"string":c=String(r).localeCompare(String(n));break;case"array":case"object":c=JSON.stringify(r).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:c=String(r).localeCompare(String(n));break}return i==="asc"?c:-c}}function Wa(e,r,n){if(!n||n.length===0)return e;const i=[...n].sort((s,a)=>s.priority-a.priority);return[...e].sort((s,a)=>{for(const c of i){const l=r.find(y=>y.name===c.column);if(!l)continue;const x=Ma(l.type)(s[c.column],a[c.column],c.direction);if(x!==0)return x}return 0})}function Aa(e){return e===null?"asc":e==="asc"?"desc":null}function Ra(e){return e==="string"||e==="boolean"}function Pa(e){return e.filter(r=>Ra(r.type))}function Na(e,r){const n={};return r.forEach(i=>{if(i.type==="number"){const s=e.map(a=>a[i.name]).filter(a=>typeof a=="number");s.length>0&&(n[i.name]=s.reduce((a,c)=>a+c,0))}}),n}function La(e,r,n){if(!n.enabled||n.levels.length===0)return e;const i=ii(e,n.levels,r);return ws(i,n.collapsedGroups||[])}function ii(e,r,n,i="",s=0){if(s>=r.length)return e;const a=r[s].column,c=new Map;e.forEach(x=>{const y=x[a],g=y==null?"(empty)":String(y);c.has(g)||c.set(g,[]),c.get(g).push(x)});const l=[];return Array.from(c.keys()).sort().forEach(x=>{const y=c.get(x),g=`${a}:${x}`,v=i?`${i}|${g}`:g,S=Na(y,n),k=s<r.length-1?ii(y,r,n,v,s+1):y,b={key:v,level:s,column:a,value:x,rowCount:y.length,aggregates:S,children:k};l.push(b)}),l}function ws(e,r,n=[],i=0){for(const s of e)if("key"in s&&"level"in s&&"children"in s){const a=r.includes(s.key);n.push({isGroupHeader:!0,groupKey:s.key,groupLevel:s.level,groupColumn:s.column,groupValue:s.value,rowCount:s.rowCount,aggregates:s.aggregates,isCollapsed:a}),!a&&s.children&&ws(s.children,r,n,i+1)}else n.push({...s,__urm_is_grouped_data_row__:!0,__urm_group_level__:i});return n}function zi(e,r,n){if(!n.enabled||n.levels.length===0)return[];const i=ii(e,n.levels,r),s=[],a=c=>{for(const l of c)"key"in l&&"level"in l&&"children"in l&&(s.push(l.key),a(l.children))};return a(i),s}function Fa(e,r){const n=e.collapsedGroups||[],i=n.includes(r)?n.filter(s=>s!==r):[...n,r];return{...e,collapsedGroups:i}}function ks(e,r){return e==null?"":typeof e=="number"?`Σ ${e.toLocaleString()}`:String(e)}function Va(e,r,n){const i=r?lt(r):"",s=String(n??"");return i?`${i}: ${s}`:s}function no(){return`flt_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ye(e){return"children"in e}function _t(){return{id:no(),operator:"and",children:[]}}function Le(e){return e?Array.isArray(e)?{id:no(),operator:"and",children:e.map(r=>({...r,id:r.id??no()}))}:e:_t()}function Ct(e){return e?Ye(e)?e.children.reduce((r,n)=>r+Ct(n),0):1:0}function qo(e,r){if(e.id===r)return e;for(const n of e.children){if(n.id===r)return n;if(Ye(n)){const i=qo(n,r);if(i)return i}}}function io(e,r,n){return e.id===r?{...e,children:[...e.children,n]}:{...e,children:e.children.map(i=>Ye(i)?io(i,r,n):i)}}function si(e,r,n){return{...e,children:e.children.map(i=>i.id===r&&!Ye(i)?{...i,...n}:Ye(i)?si(i,r,n):i)}}function ai(e,r,n){return e.id===r?{...e,operator:n}:{...e,children:e.children.map(i=>Ye(i)?ai(i,r,n):i)}}function li(e,r){const n=e.children.filter(i=>i.id!==r).map(i=>Ye(i)?li(i,r):i).filter(i=>!Ye(i)||i.children.length>0);return{...e,children:n}}function Xn(e,r){return e?Ye(e)?e.children.some(n=>Xn(n,r)):e.column===r:!1}function zs(e,r){const n=e.children.filter(i=>Ye(i)||i.column!==r).map(i=>Ye(i)?zs(i,r):i).filter(i=>!Ye(i)||i.children.length>0);return{...e,children:n}}function Ts(e){return e?Ye(e)?e.children.flatMap(Ts):[e]:[]}function To(e){if(!e)return null;if(!Ye(e)){const{id:i,...s}=e;return s}const{id:r,...n}=e;return{...n,children:e.children.map(To)}}function Co(e,r){if(!r||!r.enabled||!r.levels||r.levels.length===0)return[...e];const n=r.levels.map(s=>s.column),i=e.filter(s=>!n.includes(s));return[...n,...i]}function ci(e,r,n){if(!r||!r.enabled||!r.levels||r.levels.length===0)return[...e];const i=r.levels.map(a=>a.column),s=e.filter(a=>!i.includes(a));if(n){const a=[],c=new Set(i),l=new Set(s);let p=0;for(const x of n)c.has(x)?a.push(x):l.has(x)&&p<s.length?(a.push(s[p]),p++):l.has(x)||a.push(x);for(let x=p;x<s.length;x++)a.includes(s[x])||a.push(s[x]);return a}return[...e]}function Nn(e){const r={},n=[],i={};return e.forEach(s=>{r[s.name]=!0,n.push(s.name),i[s.name]=170}),{id:"default-view",name:"Default View",description:"Unfiltered, unsorted baseline view",isDefault:!0,snapshot:{filters:_t(),sortStack:[],columnVisibility:r,columnOrder:n,columnWidths:i,grouping:null}}}function Ha(e,r,n,i,s,a,c,l){const p={},x=[],y={};n.forEach(S=>{p[S.name]=!0,x.push(S.name),y[S.name]=170});const v=ci(s||x,c||null,l||x);return{filters:Le(e),sortStack:r||[],columnVisibility:i||p,columnOrder:v,columnWidths:a||y,grouping:c||null}}function Ua(e,r){const n=S=>{if(S==null)return S;if(Array.isArray(S))return S.map(k=>n(k));if(typeof S=="object"){const k={};return Object.keys(S).sort().forEach(b=>{k[b]=n(S[b])}),k}return S},i=S=>JSON.stringify(n(S));if(i(To(e.filters))!==i(To(r.filters))||i(e.sortStack)!==i(r.sortStack))return!0;const s=e.columnVisibility??{},a=r.columnVisibility??{};if(i(s)!==i(a))return!0;const c=ci(e.columnOrder||[],e.grouping||null,r.columnOrder||[]),l=[...c].sort().join(","),p=[...r.columnOrder||[]].sort().join(",");if(l!==p)return!1;const x=[...r.columnOrder||[]].sort().join(",");if((r.columnOrder||[]).join(",")!==x){if(c.join(",")!==(r.columnOrder||[]).join(","))return!0}else{const S=[...c].sort().join(",");if(c.join(",")!==S)return!0}const g=e.columnWidths??{},v=r.columnWidths??{};return i(g)!==i(v)||i(e.grouping)!==i(r.grouping)}function Ga(e){return!e||e.length===0?"None":e.sort((r,n)=>r.priority-n.priority).map(r=>`${r.column} ${r.direction==="asc"?"↑":"↓"}`).join(", ")}function Ya(e,r){var b,m,z;const n=[],i=JSON.stringify(To(e.filters)),s=JSON.stringify(To(r.filters));if(i!==s){const h=Ct(e.filters),B=Ct(r.filters);h>B?n.push({category:"filters",label:"Filters Added",description:`${h-B} new filter${h-B>1?"s":""} added`}):h<B?n.push({category:"filters",label:"Filters Removed",description:`${B-h} filter${B-h>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const a=JSON.stringify(e.sortStack),c=JSON.stringify(r.sortStack);if(a!==c){const h=e.sortStack.length,B=r.sortStack.length;h>B?n.push({category:"sorting",label:"Sorting Added",description:`${h-B} new sort rule${h-B>1?"s":""} added`}):h<B?n.push({category:"sorting",label:"Sorting Removed",description:`${B-h} sort rule${B-h>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(e.columnVisibility),p=JSON.stringify(r.columnVisibility);if(l!==p){const h=Object.values(e.columnVisibility).filter(T=>T).length,B=Object.values(r.columnVisibility).filter(T=>T).length;h>B?n.push({category:"visibility",label:"Columns Shown",description:`${h-B} column${h-B>1?"s":""} made visible`}):h<B?n.push({category:"visibility",label:"Columns Hidden",description:`${B-h} column${B-h>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const x=JSON.stringify(e.columnOrder),y=JSON.stringify(r.columnOrder);x!==y&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const g=JSON.stringify(e.columnWidths),v=JSON.stringify(r.columnWidths);if(g!==v){const h=Object.keys(e.columnWidths).filter(B=>e.columnWidths[B]!==r.columnWidths[B]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${h} column width${h>1?"s":""} modified`})}const S=JSON.stringify(e.grouping),k=JSON.stringify(r.grouping);if(S!==k){const h=(b=e.grouping)==null?void 0:b.enabled,B=(m=r.grouping)==null?void 0:m.enabled;if(h&&!B){const T=((z=e.grouping)==null?void 0:z.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${T} grouping level${T>1?"s":""} added`})}else!h&&B?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function Ti(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function Bi(e){return`[${e}]`}const Lt={warn(e,r,...n){Ti()&&console.warn(Bi(e),r,...n)},error(e,r,...n){Ti()&&console.error(Bi(e),r,...n)}},Bs="urm_report_";function qa(e,r){try{const n=`${Bs}${e}`;localStorage.setItem(n,JSON.stringify(r))}catch(n){Lt.error("urm:persistence","Failed to save report state",n)}}function Ja(e){try{const r=`${Bs}${e}`,n=localStorage.getItem(r);return n?JSON.parse(n):null}catch(r){return Lt.error("urm:persistence","Failed to load report state",r),null}}function Io(e,r,n=0){const i=[];for(const s of e){const a=r.includes(s.key);if(i.push({type:"group",key:s.key,level:n,column:s.column,value:s.value,rowCount:s.rowCount,aggregates:s.aggregates,collapsed:a}),!a&&s.children&&s.children.length>0){const c=s.children[0];if(Ka(c)){const l=s.children,p=Io(l,r,n+1);i.push(...p)}else{const l=s.children;for(const p of l)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:p})}}}return i}function Ka(e){return e&&typeof e=="object"&&"key"in e&&"level"in e&&"column"in e&&"value"in e&&"rowCount"in e&&"aggregates"in e&&"children"in e}function an(e){return e.filter(r=>r.type==="row").map(r=>r.type==="row"?r.data:null).filter(r=>r!==null)}function ln(e,r){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0"),c=`${i}-${s}-${a}`;return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${c}.${r}`}function Qo(e,r,n,i,s,a,c){let l,p;a?(l={...a},p=c||r.map(y=>y.name)):s?(l={...s.snapshot.columnVisibility},p=c||[...s.snapshot.columnOrder]):(l={},p=[],r.forEach(y=>{l[y.name]=!0,p.push(y.name)}));const x=Object.entries(l).filter(([y,g])=>!g).map(([y,g])=>y);return{data:e,schema:r,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:p,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:x,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function Zo(e,r="export",n){const{data:i,columnOrder:s,grouping:a}=e,c=s.filter(g=>e.columnVisibility[g]);let l;if(a&&a.enabled){const g=a.collapsedGroups??[],v=Io(i,g);l=an(v)}else l=i;const p=c.join(","),x=l.map(g=>c.map(v=>{const S=g[v];if(S==null)return"";const k=String(S);return k.includes(",")||k.includes('"')||k.includes(`
|
|
1
|
+
"use strict";var pa=Object.defineProperty;var ha=(e,r,n)=>r in e?pa(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var Ci=(e,r,n)=>ha(e,typeof r!="symbol"?r+"":r,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),f=require("react"),fa=require("xlsx"),$=require("@mui/icons-material"),o=require("@mui/material"),bs=require("react-dom"),ma=require("@emotion/react"),Zt=require("react-dnd"),ni=require("react-dnd-html5-backend");function vs(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const sn=vs(f),No=vs(fa),ht={sort:{maxLevels:5},filter:{maxConditions:3,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json","pdf"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},Ss="urm_dev_config";function xa(){try{const e=localStorage.getItem(Ss);if(!e)return ht;const r=JSON.parse(e),n={sort:{...ht.sort,...r.sort},filter:{...ht.filter,...r.filter},columns:{...ht.columns,...r.columns},grouping:{...ht.grouping,...r.grouping},export:{...ht.export,...r.export},views:{...ht.views,...r.views},dates:{...ht.dates,...r.dates},display:{...ht.display,...r.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return ht}}function ga(e){try{localStorage.setItem(Ss,JSON.stringify(e))}catch{}}function ya(e,r,n){if(!n||!r)return e;const i={sort:{...e.sort,...r.sort},filter:{...e.filter,...r.filter},columns:{...e.columns,...r.columns},grouping:{...e.grouping,...r.grouping},export:{...e.export,...r.export},views:{...e.views,...r.views},dates:{...e.dates,...r.dates},display:{...e.display,...r.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const Cs=f.createContext(ht);function Dr(){return f.useContext(Cs)}const ba=/^\d{4}-\d{2}-\d{2}$/,va=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Sa=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ca=9783072e5,ja=41024448e5,wa=978307200,ka=4102444800;function za(e){return e==null||e===""?"unknown":typeof e=="number"?Number.isInteger(e)&&e>=Ca&&e<=ja?"timestamp_ms":Number.isInteger(e)&&e>=wa&&e<=ka?"timestamp_s":"unknown":typeof e!="string"?"unknown":va.test(e)||ba.test(e)?"iso":Sa.test(e.trim())?"locale_string":"unknown"}function Ta(e,r){const n=r.map(c=>c[e]).filter(c=>c!=null&&c!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const c of n){const l=za(c);i[l]++}const s=n.length,a=.7;for(const c of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[c]/s>=a)return c;return"unknown"}function Ba(e,r){if(e==null||e==="")return null;try{switch(r){case"timestamp_ms":{const n=new Date(Number(e));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(e)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(e));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(e));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const ji=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ia=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ue(e){return String(e).padStart(2,"0")}function Ea(e){const r=Date.now()-e.getTime(),n=Math.abs(r),i=r>0,s=Math.floor(n/1e3),a=Math.floor(s/60),c=Math.floor(a/60),l=Math.floor(c/24),p=Math.floor(l/7),x=Math.floor(l/30),y=Math.floor(l/365);let g;return s<60?g="just now":a<60?g=`${a} minute${a!==1?"s":""}`:c<24?g=`${c} hour${c!==1?"s":""}`:l<7?g=`${l} day${l!==1?"s":""}`:p<5?g=`${p} week${p!==1?"s":""}`:x<12?g=`${x} month${x!==1?"s":""}`:g=`${y} year${y!==1?"s":""}`,s<60?g:i?`${g} ago`:`in ${g}`}function Da(e,r){const n=e.getFullYear(),i=e.getMonth(),s=e.getDate(),a=e.getHours(),c=e.getMinutes();switch(r){case"YYYY-MM-DD":return`${n}-${Ue(i+1)}-${Ue(s)}`;case"DD/MM/YYYY":return`${Ue(s)}/${Ue(i+1)}/${n}`;case"MM/DD/YYYY":return`${Ue(i+1)}/${Ue(s)}/${n}`;case"MMM DD, YYYY":return`${ji[i]} ${Ue(s)}, ${n}`;case"DD MMM YYYY":return`${Ue(s)} ${ji[i]} ${n}`;case"MMMM D, YYYY":return`${Ia[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Ue(i+1)}-${Ue(s)} ${Ue(a)}:${Ue(c)}`;case"DD/MM/YYYY HH:mm":return`${Ue(s)}/${Ue(i+1)}/${n} ${Ue(a)}:${Ue(c)}`;case"MM/DD/YYYY HH:mm":return`${Ue(i+1)}/${Ue(s)}/${n} ${Ue(a)}:${Ue(c)}`;case"relative":return Ea(e);case"locale":return e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return e.toLocaleDateString()}}function $a(e,r,n){if(!n||r==="unknown")return String(e);const i=Ba(e,r);return!i||isNaN(i.getTime())?String(e):Da(i,n)}function _a(e){return e==null?"null":Array.isArray(e)?"array":typeof e=="object"?"object":typeof e=="number"?"number":typeof e=="boolean"?"boolean":typeof e=="string"?"string":"mixed"}function js(e,r="",n=0){if(n>2)return{[r]:e};const i={};for(const s of Object.keys(e)){const a=r?`${r}.${s}`:s,c=e[s];c!==null&&typeof c=="object"&&!Array.isArray(c)&&n<2?Object.assign(i,js(c,a,n+1)):i[a]=c}return i}function oo(e){return e.map(r=>typeof r!="object"||r===null||Array.isArray(r)?r:js(r))}function yo(e){if(!Array.isArray(e)||e.length===0)return[];const r=oo(e),n=new Set;r.forEach(c=>{typeof c=="object"&&c!==null&&Object.keys(c).forEach(l=>n.add(l))});const i=[];n.forEach(c=>{const l=new Set;let p=0;r.forEach(v=>{typeof v=="object"&&v!==null&&c in v&&(p++,l.add(_a(v[c])))});const x=p===r.length,y=l.size>1&&!l.has("null");let g="mixed";if(l.size===1)g=Array.from(l)[0];else if(l.size===2&&l.has("null")){const v=Array.from(l).filter(S=>S!=="null");v.length===1&&(g=v[0])}i.push({name:c,type:g,required:x,hasConflict:y})});const a=r.slice(0,50);for(const c of i){if(c.type!=="string"&&c.type!=="number")continue;const l=Ta(c.name,a);l!=="unknown"&&(c.type="date",c.dateFormat=l)}return i}function wi(e,r){return!r||r.length===0?e:e.filter(n=>!r.includes(n.name))}function Oa(e){return e.some(r=>r.hasConflict)}function lt(e){if(!e)return"";const n=e.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function ki(e){return e==null}function Ma(e){return(r,n,i)=>{const s=ki(r),a=ki(n);if(s&&a)return 0;if(s)return 1;if(a)return-1;let c=0;switch(e){case"number":const l=Number(r),p=Number(n);c=l-p;break;case"boolean":c=(r?1:0)-(n?1:0);break;case"string":c=String(r).localeCompare(String(n));break;case"array":case"object":c=JSON.stringify(r).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:c=String(r).localeCompare(String(n));break}return i==="asc"?c:-c}}function Wa(e,r,n){if(!n||n.length===0)return e;const i=[...n].sort((s,a)=>s.priority-a.priority);return[...e].sort((s,a)=>{for(const c of i){const l=r.find(y=>y.name===c.column);if(!l)continue;const x=Ma(l.type)(s[c.column],a[c.column],c.direction);if(x!==0)return x}return 0})}function Aa(e){return e===null?"asc":e==="asc"?"desc":null}function Ra(e){return e==="string"||e==="boolean"}function Pa(e){return e.filter(r=>Ra(r.type))}function Na(e,r){const n={};return r.forEach(i=>{if(i.type==="number"){const s=e.map(a=>a[i.name]).filter(a=>typeof a=="number");s.length>0&&(n[i.name]=s.reduce((a,c)=>a+c,0))}}),n}function La(e,r,n){if(!n.enabled||n.levels.length===0)return e;const i=ii(e,n.levels,r);return ws(i,n.collapsedGroups||[])}function ii(e,r,n,i="",s=0){if(s>=r.length)return e;const a=r[s].column,c=new Map;e.forEach(x=>{const y=x[a],g=y==null?"(empty)":String(y);c.has(g)||c.set(g,[]),c.get(g).push(x)});const l=[];return Array.from(c.keys()).sort().forEach(x=>{const y=c.get(x),g=`${a}:${x}`,v=i?`${i}|${g}`:g,S=Na(y,n),k=s<r.length-1?ii(y,r,n,v,s+1):y,b={key:v,level:s,column:a,value:x,rowCount:y.length,aggregates:S,children:k};l.push(b)}),l}function ws(e,r,n=[],i=0){for(const s of e)if("key"in s&&"level"in s&&"children"in s){const a=r.includes(s.key);n.push({isGroupHeader:!0,groupKey:s.key,groupLevel:s.level,groupColumn:s.column,groupValue:s.value,rowCount:s.rowCount,aggregates:s.aggregates,isCollapsed:a}),!a&&s.children&&ws(s.children,r,n,i+1)}else n.push({...s,__urm_is_grouped_data_row__:!0,__urm_group_level__:i});return n}function zi(e,r,n){if(!n.enabled||n.levels.length===0)return[];const i=ii(e,n.levels,r),s=[],a=c=>{for(const l of c)"key"in l&&"level"in l&&"children"in l&&(s.push(l.key),a(l.children))};return a(i),s}function Fa(e,r){const n=e.collapsedGroups||[],i=n.includes(r)?n.filter(s=>s!==r):[...n,r];return{...e,collapsedGroups:i}}function ks(e,r){return e==null?"":typeof e=="number"?`Σ ${e.toLocaleString()}`:String(e)}function Va(e,r,n){const i=r?lt(r):"",s=String(n??"");return i?`${i}: ${s}`:s}function io(){return`flt_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ye(e){return"children"in e}function _t(){return{id:io(),operator:"and",children:[]}}function Le(e){return e?Array.isArray(e)?{id:io(),operator:"and",children:e.map(r=>({...r,id:r.id??io()}))}:e:_t()}function Ct(e){return e?Ye(e)?e.children.reduce((r,n)=>r+Ct(n),0):1:0}function qo(e,r){if(e.id===r)return e;for(const n of e.children){if(n.id===r)return n;if(Ye(n)){const i=qo(n,r);if(i)return i}}}function so(e,r,n){return e.id===r?{...e,children:[...e.children,n]}:{...e,children:e.children.map(i=>Ye(i)?so(i,r,n):i)}}function si(e,r,n){return{...e,children:e.children.map(i=>i.id===r&&!Ye(i)?{...i,...n}:Ye(i)?si(i,r,n):i)}}function ai(e,r,n){return e.id===r?{...e,operator:n}:{...e,children:e.children.map(i=>Ye(i)?ai(i,r,n):i)}}function li(e,r){const n=e.children.filter(i=>i.id!==r).map(i=>Ye(i)?li(i,r):i).filter(i=>!Ye(i)||i.children.length>0);return{...e,children:n}}function Xn(e,r){return e?Ye(e)?e.children.some(n=>Xn(n,r)):e.column===r:!1}function zs(e,r){const n=e.children.filter(i=>Ye(i)||i.column!==r).map(i=>Ye(i)?zs(i,r):i).filter(i=>!Ye(i)||i.children.length>0);return{...e,children:n}}function Ts(e){return e?Ye(e)?e.children.flatMap(Ts):[e]:[]}function To(e){if(!e)return null;if(!Ye(e)){const{id:i,...s}=e;return s}const{id:r,...n}=e;return{...n,children:e.children.map(To)}}function Co(e,r){if(!r||!r.enabled||!r.levels||r.levels.length===0)return[...e];const n=r.levels.map(s=>s.column),i=e.filter(s=>!n.includes(s));return[...n,...i]}function ci(e,r,n){if(!r||!r.enabled||!r.levels||r.levels.length===0)return[...e];const i=r.levels.map(a=>a.column),s=e.filter(a=>!i.includes(a));if(n){const a=[],c=new Set(i),l=new Set(s);let p=0;for(const x of n)c.has(x)?a.push(x):l.has(x)&&p<s.length?(a.push(s[p]),p++):l.has(x)||a.push(x);for(let x=p;x<s.length;x++)a.includes(s[x])||a.push(s[x]);return a}return[...e]}function Nn(e){const r={},n=[],i={};return e.forEach(s=>{r[s.name]=!0,n.push(s.name),i[s.name]=170}),{id:"default-view",name:"Default View",description:"Unfiltered, unsorted baseline view",isDefault:!0,snapshot:{filters:_t(),sortStack:[],columnVisibility:r,columnOrder:n,columnWidths:i,grouping:null}}}function Ha(e,r,n,i,s,a,c,l){const p={},x=[],y={};n.forEach(S=>{p[S.name]=!0,x.push(S.name),y[S.name]=170});const v=ci(s||x,c||null,l||x);return{filters:Le(e),sortStack:r||[],columnVisibility:i||p,columnOrder:v,columnWidths:a||y,grouping:c||null}}function Ua(e,r){const n=S=>{if(S==null)return S;if(Array.isArray(S))return S.map(k=>n(k));if(typeof S=="object"){const k={};return Object.keys(S).sort().forEach(b=>{k[b]=n(S[b])}),k}return S},i=S=>JSON.stringify(n(S));if(i(To(e.filters))!==i(To(r.filters))||i(e.sortStack)!==i(r.sortStack))return!0;const s=e.columnVisibility??{},a=r.columnVisibility??{};if(i(s)!==i(a))return!0;const c=ci(e.columnOrder||[],e.grouping||null,r.columnOrder||[]),l=[...c].sort().join(","),p=[...r.columnOrder||[]].sort().join(",");if(l!==p)return!1;const x=[...r.columnOrder||[]].sort().join(",");if((r.columnOrder||[]).join(",")!==x){if(c.join(",")!==(r.columnOrder||[]).join(","))return!0}else{const S=[...c].sort().join(",");if(c.join(",")!==S)return!0}const g=e.columnWidths??{},v=r.columnWidths??{};return i(g)!==i(v)||i(e.grouping)!==i(r.grouping)}function Ga(e){return!e||e.length===0?"None":e.sort((r,n)=>r.priority-n.priority).map(r=>`${r.column} ${r.direction==="asc"?"↑":"↓"}`).join(", ")}function Ya(e,r){var b,m,z;const n=[],i=JSON.stringify(To(e.filters)),s=JSON.stringify(To(r.filters));if(i!==s){const h=Ct(e.filters),B=Ct(r.filters);h>B?n.push({category:"filters",label:"Filters Added",description:`${h-B} new filter${h-B>1?"s":""} added`}):h<B?n.push({category:"filters",label:"Filters Removed",description:`${B-h} filter${B-h>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const a=JSON.stringify(e.sortStack),c=JSON.stringify(r.sortStack);if(a!==c){const h=e.sortStack.length,B=r.sortStack.length;h>B?n.push({category:"sorting",label:"Sorting Added",description:`${h-B} new sort rule${h-B>1?"s":""} added`}):h<B?n.push({category:"sorting",label:"Sorting Removed",description:`${B-h} sort rule${B-h>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(e.columnVisibility),p=JSON.stringify(r.columnVisibility);if(l!==p){const h=Object.values(e.columnVisibility).filter(T=>T).length,B=Object.values(r.columnVisibility).filter(T=>T).length;h>B?n.push({category:"visibility",label:"Columns Shown",description:`${h-B} column${h-B>1?"s":""} made visible`}):h<B?n.push({category:"visibility",label:"Columns Hidden",description:`${B-h} column${B-h>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const x=JSON.stringify(e.columnOrder),y=JSON.stringify(r.columnOrder);x!==y&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const g=JSON.stringify(e.columnWidths),v=JSON.stringify(r.columnWidths);if(g!==v){const h=Object.keys(e.columnWidths).filter(B=>e.columnWidths[B]!==r.columnWidths[B]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${h} column width${h>1?"s":""} modified`})}const S=JSON.stringify(e.grouping),k=JSON.stringify(r.grouping);if(S!==k){const h=(b=e.grouping)==null?void 0:b.enabled,B=(m=r.grouping)==null?void 0:m.enabled;if(h&&!B){const T=((z=e.grouping)==null?void 0:z.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${T} grouping level${T>1?"s":""} added`})}else!h&&B?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function Ti(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function Bi(e){return`[${e}]`}const Lt={warn(e,r,...n){Ti()&&console.warn(Bi(e),r,...n)},error(e,r,...n){Ti()&&console.error(Bi(e),r,...n)}},Bs="urm_report_";function qa(e,r){try{const n=`${Bs}${e}`;localStorage.setItem(n,JSON.stringify(r))}catch(n){Lt.error("urm:persistence","Failed to save report state",n)}}function Ja(e){try{const r=`${Bs}${e}`,n=localStorage.getItem(r);return n?JSON.parse(n):null}catch(r){return Lt.error("urm:persistence","Failed to load report state",r),null}}function Io(e,r,n=0){const i=[];for(const s of e){const a=r.includes(s.key);if(i.push({type:"group",key:s.key,level:n,column:s.column,value:s.value,rowCount:s.rowCount,aggregates:s.aggregates,collapsed:a}),!a&&s.children&&s.children.length>0){const c=s.children[0];if(Ka(c)){const l=s.children,p=Io(l,r,n+1);i.push(...p)}else{const l=s.children;for(const p of l)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:p})}}}return i}function Ka(e){return e&&typeof e=="object"&&"key"in e&&"level"in e&&"column"in e&&"value"in e&&"rowCount"in e&&"aggregates"in e&&"children"in e}function an(e){return e.filter(r=>r.type==="row").map(r=>r.type==="row"?r.data:null).filter(r=>r!==null)}function ln(e,r){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0"),c=`${i}-${s}-${a}`;return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${c}.${r}`}function Qo(e,r,n,i,s,a,c){let l,p;a?(l={...a},p=c||r.map(y=>y.name)):s?(l={...s.snapshot.columnVisibility},p=c||[...s.snapshot.columnOrder]):(l={},p=[],r.forEach(y=>{l[y.name]=!0,p.push(y.name)}));const x=Object.entries(l).filter(([y,g])=>!g).map(([y,g])=>y);return{data:e,schema:r,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:p,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:x,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function Zo(e,r="export",n){const{data:i,columnOrder:s,grouping:a}=e,c=s.filter(g=>e.columnVisibility[g]);let l;if(a&&a.enabled){const g=a.collapsedGroups??[],v=Io(i,g);l=an(v)}else l=i;const p=c.join(","),x=l.map(g=>c.map(v=>{const S=g[v];if(S==null)return"";const k=String(S);return k.includes(",")||k.includes('"')||k.includes(`
|
|
2
2
|
`)?`"${k.replace(/"/g,'""')}"`:k}).join(",")),y=[p,...x].join(`
|
|
3
|
-
`);di(y,ln(r,"csv"),"text/csv;charset=utf-8;")}function en(e,r="export",n){const{data:i,columnOrder:s,grouping:a}=e,c=s.filter(g=>e.columnVisibility[g]);let l;if(a&&a.enabled){const g=a.collapsedGroups??[],v=Io(i,g);l=an(v)}else l=i;const p=[c,...l.map(g=>c.map(v=>g[v]??""))],x=No.utils.aoa_to_sheet(p),y=No.utils.book_new();No.utils.book_append_sheet(y,x,"Data"),No.writeFile(y,ln(r,"xlsx"))}function tn(e,r="export",n){const{data:i,appliedFilters:s,appliedSortStack:a,viewMeta:c,hiddenColumns:l,columnOrder:p,grouping:x}=e,y=p.filter(k=>e.columnVisibility[k]);let g;if(x&&x.enabled){const k=x.collapsedGroups??[],b=Io(i,k);g=an(b)}else g=i;g=g.map(k=>{const b={};return y.forEach(m=>{b[m]=k[m]}),b});const v={meta:{exportedAt:new Date().toISOString(),reportName:r,view:(c==null?void 0:c.name)||"Default View",filters:Ts(s).map(k=>({field:k.column,operator:k.operator,value:k.value})),sortStack:a.map(k=>({field:k.column,direction:k.direction,priority:k.priority})),grouping:x||{},hiddenColumns:l,columnOrder:p,exportConfig:n||{scope:"visible"}},data:g},S=JSON.stringify(v,null,2);di(S,ln(r,"json"),"application/json;charset=utf-8;")}function di(e,r,n){const i=new Blob([e],{type:n}),s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=r,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}function ui(e,r="export",n){var b;const{data:i,columnOrder:s,grouping:a}=e,c=s.filter(m=>e.columnVisibility[m]);let l;if(a&&a.enabled){const m=a.collapsedGroups??[],z=Io(i,m);l=an(z)}else l=i;const p=new Date().toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),x=c.map(m=>`<th>${Lo(m)}</th>`).join(""),y=l.map((m,z)=>{const h=c.map(B=>{const T=m[B],
|
|
3
|
+
`);di(y,ln(r,"csv"),"text/csv;charset=utf-8;")}function en(e,r="export",n){const{data:i,columnOrder:s,grouping:a}=e,c=s.filter(g=>e.columnVisibility[g]);let l;if(a&&a.enabled){const g=a.collapsedGroups??[],v=Io(i,g);l=an(v)}else l=i;const p=[c,...l.map(g=>c.map(v=>g[v]??""))],x=No.utils.aoa_to_sheet(p),y=No.utils.book_new();No.utils.book_append_sheet(y,x,"Data"),No.writeFile(y,ln(r,"xlsx"))}function tn(e,r="export",n){const{data:i,appliedFilters:s,appliedSortStack:a,viewMeta:c,hiddenColumns:l,columnOrder:p,grouping:x}=e,y=p.filter(k=>e.columnVisibility[k]);let g;if(x&&x.enabled){const k=x.collapsedGroups??[],b=Io(i,k);g=an(b)}else g=i;g=g.map(k=>{const b={};return y.forEach(m=>{b[m]=k[m]}),b});const v={meta:{exportedAt:new Date().toISOString(),reportName:r,view:(c==null?void 0:c.name)||"Default View",filters:Ts(s).map(k=>({field:k.column,operator:k.operator,value:k.value})),sortStack:a.map(k=>({field:k.column,direction:k.direction,priority:k.priority})),grouping:x||{},hiddenColumns:l,columnOrder:p,exportConfig:n||{scope:"visible"}},data:g},S=JSON.stringify(v,null,2);di(S,ln(r,"json"),"application/json;charset=utf-8;")}function di(e,r,n){const i=new Blob([e],{type:n}),s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=r,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}function ui(e,r="export",n){var b;const{data:i,columnOrder:s,grouping:a}=e,c=s.filter(m=>e.columnVisibility[m]);let l;if(a&&a.enabled){const m=a.collapsedGroups??[],z=Io(i,m);l=an(z)}else l=i;const p=new Date().toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),x=c.map(m=>`<th>${Lo(m)}</th>`).join(""),y=l.map((m,z)=>{const h=c.map(B=>{const T=m[B],w=T==null?"":String(T);return`<td>${Lo(w)}</td>`}).join("");return`<tr class="${z%2===0?"even":"odd"}">${h}</tr>`}).join(""),g=`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8" />
|
|
@@ -102,26 +102,26 @@
|
|
|
102
102
|
};
|
|
103
103
|
<\/script>
|
|
104
104
|
</body>
|
|
105
|
-
</html>`;try{const m=document.createElement("iframe");m.style.position="fixed",m.style.right="0",m.style.bottom="0",m.style.width="0",m.style.height="0",m.style.border="0",document.body.appendChild(m);const z=((b=m.contentWindow)==null?void 0:b.document)||m.contentDocument;if(z){z.open(),z.write(g),z.close(),setTimeout(()=>{var h,B;try{(h=m.contentWindow)==null||h.focus(),(B=m.contentWindow)==null||B.print()}catch{}setTimeout(()=>{document.body.removeChild(m)},3e3)},300);return}}catch{}const v=new Blob([g],{type:"text/html;charset=utf-8;"}),S=URL.createObjectURL(v);window.open(S,"_blank")||di(g,ln(r,"html"),"text/html;charset=utf-8;")}function Lo(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const Ii=10;function Xa(e,r){const n=r.trim();if(!n)return e;const i=e.findIndex(a=>a.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...e[i],lastUsed:Date.now()},...e.slice(0,i),...e.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...e],s.length>Ii&&(s=[...s].sort((c,l)=>c.isFavourite&&!l.isFavourite?-1:!c.isFavourite&&l.isFavourite?1:l.lastUsed-c.lastUsed).slice(0,Ii)),s}function Qa(e,r){return e.map(n=>n.query===r?{...n,isFavourite:!n.isFavourite}:n)}function Za(e,r){return e.filter(n=>n.query!==r)}function el(e){const r=e.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=e.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...r,...n]}const tl={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function rl(e,r){return!e||e.owner===r?"owner":e.editors.includes(r)?"editor":(e.viewers.includes(r),"viewer")}function bt(e,r){return tl[r].includes(e)}function vt(e){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data",promote_global_view:"promote views to global"}[e]||"perform this action"}.`}function ol(e){return e==="viewer"}const Ei=1e3;function Qn(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}function Nt(e){if(!e)return"";const n=e.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Qn(n)}const nl={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function il(e){if(!e||!e.column)return"a filter";const r=Nt(e.column),n=nl[e.operator]??e.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(e.operator)?`"${r}" ${n}`:`"${r}" ${n} "${e.value}"`}function Ln(e){return e?typeof e=="string"?e:"children"in e?"a condition group":il(e):"a filter"}function Di(e){return!e||!e.enabled||e.levels.length===0?"grouping removed":`grouped by ${e.levels.map(n=>`"${Nt(n.column)}"`).join(", ")}`}function sl(e){var s,a,c;const{action:r,previousState:n,newState:i}=e;switch(r){case"filter_added":return{summary:`Filter added: ${Ln(i)}`};case"filter_removed":return{summary:`Filter removed: ${Ln(n)}`};case"filter_updated":{if(typeof i=="string")return{summary:`Filter updated: ${i}`};const l=n,p=i;return l!=null&&l.column&&(p!=null&&p.column)&&l.column!==p.column?{summary:`Filter changed on "${Nt(p.column)}"`,detail:`Previously filtered "${Nt(l.column)}"`}:{summary:`Filter updated: ${Ln(p)}`}}case"filter_cleared":{const l=n&&typeof n=="object"&&"count"in n?n.count:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?Nt(i.column):"",p=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${p}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?Nt(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${Di(i)}`};case"group_level_removed":{const l=n,p=(a=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&a.column?Nt(l.levels[0].column):"";return{summary:p?`Group level removed: "${p}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${Di(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${Nt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${Nt(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],p=Array.isArray(i)?i:[];return l.length>0&&p.length>0?{summary:"Column order changed",detail:`${p.length} column${p.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",p=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${Nt(l)}"`:"Column resized",detail:p?`New width: ${p}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",p=(i==null?void 0:i.name)??"";return l&&p?{summary:`Switched to view "${p}"`,detail:`From "${l}"`}:p?{summary:`Switched to view "${p}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":case"export_pdf":{const l=r==="export_csv"?"CSV":r==="export_excel"?"Excel":r==="export_json"?"JSON":"PDF",p=i==null?void 0:i.rowCount,x=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",y=(i==null?void 0:i.viewName)??"",g=typeof p=="number"?` (${p.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${g}`,detail:y?`${Qn(x)} · View: "${y}"`:Qn(x)}}case"export_triggered":{const l=((c=i==null?void 0:i.format)==null?void 0:c.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",p=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&p?{summary:`Theme changed from "${l}" to "${p}"`}:p?{summary:`Theme changed to "${p}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:ll(r)}}}function al(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Is(e,r,n,i,s,a){return{id:al(),user:r,reportId:e,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:a}}function Es(e,r){const n=[r,...e];return n.length>Ei?n.slice(0,Ei):n}function ll(e){return{filter_added:"Filter Added",filter_removed:"Filter Removed",filter_updated:"Filter Updated",filter_cleared:"All Filters Cleared",sort_level_added:"Sort Level Added",sort_level_removed:"Sort Level Removed",sort_reordered:"Sort Reordered",sort_cleared:"All Sorting Cleared",group_level_added:"Group Level Added",group_level_removed:"Group Level Removed",group_reordered:"Group Reordered",group_cleared:"All Grouping Cleared",column_hidden:"Column Hidden",column_shown:"Column Shown",column_reordered:"Columns Reordered",column_resized:"Column Resized",view_created:"View Created",view_updated:"View Updated",view_deleted:"View Deleted",view_set_default:"View Set as Default",view_switched:"View Switched",theme_changed:"Theme Changed",export_triggered:"Export Triggered",export_csv:"Exported as CSV",export_excel:"Exported as Excel",export_json:"Exported as JSON",export_pdf:"Exported as PDF",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[e]||e}function cl(e){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[e]||e}function dl(e){const r=new Date(e),i=new Date().getTime()-r.getTime(),s=Math.floor(i/6e4),a=Math.floor(i/36e5),c=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:a<24?`${a} hour${a>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const $i=100;function ul(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function pl(e){var a;const r=(a=e.views)==null?void 0:a.find(c=>c.id===e.activeViewId),n=r==null?void 0:r.snapshot.columnOrder,i=e.columnOrder||[],s=ci(i,e.grouping||null,n);return{filters:Le(e.filters),sortStack:e.sortStack?[...e.sortStack]:[],columnVisibility:e.columnVisibility?{...e.columnVisibility}:{},columnOrder:s,columnWidths:e.columnWidths?{...e.columnWidths}:{},grouping:e.grouping?{...e.grouping}:null,activeViewId:e.activeViewId}}function hl(e,r,n,i){return{id:ul(),name:e,description:r,createdBy:n,createdAt:Date.now(),config:i}}function fl(e,r){const n=e||[];if(n.length>=$i)throw new Error(`Maximum of ${$i} presets reached. Please delete old presets first.`);return[...n,r]}function ml(e,r){return(e||[]).filter(i=>i.id!==r)}function _i(e,r){if(e)return e.find(n=>n.id===r)}function xl(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function gl(e){const r=e.columnOrder,n=Co(r,e.grouping);return{filters:Le(e.filters),sortStack:e.sortStack.length>0?[...e.sortStack]:void 0,columnVisibility:{...e.columnVisibility},columnOrder:n,columnWidths:{...e.columnWidths},grouping:e.grouping?{...e.grouping}:null,activeViewId:e.activeViewId}}async function yl(e){try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(e),!0}catch(r){Lt.warn("urm:presets","Clipboard API blocked, using fallback method",r)}try{const r=document.createElement("textarea");r.value=e,r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="2em",r.style.height="2em",r.style.padding="0",r.style.border="none",r.style.outline="none",r.style.boxShadow="none",r.style.background="transparent",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();let n=!1;try{n=document.execCommand("copy")}catch(i){Lt.error("urm:presets","execCommand copy failed",i)}return document.body.removeChild(r),n}catch(r){return Lt.error("urm:presets","Fallback copy method failed",r),!1}}function bl(e,r){return{totalRows:e.length,totalColumns:r.length}}function ur(e,r,n,i){const s=n instanceof Error?n.message:n,a={type:e,context:r,message:s,details:i,timestamp:Date.now(),recoverable:vl(e,r)};return process.env.NODE_ENV==="development"&&Lt.error("urm:error-handling","[Report Error]",{type:e,context:r,message:s,details:i}),a}function vl(e,r){return e==="ui"?!0:r==="export"?!1:e==="processing"&&["filters","sorting","grouping","columns"].includes(r)?!0:e!=="system"}function Sl(e){const n={filters:"There was an issue applying filters",sorting:"Sorting could not be applied",grouping:"Grouping configuration failed",columns:"Column configuration could not be updated",views:"View operation failed",presets:"Preset could not be applied",export:"Export failed",upload:"File upload failed",search:"Search operation failed"}[e.context]||"An error occurred";return e.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function Cl(e){return{filters:e.filters,sortStack:e.sortStack?[...e.sortStack]:void 0,grouping:e.grouping?{...e.grouping}:void 0,columnVisibility:e.columnVisibility?{...e.columnVisibility}:void 0,columnOrder:e.columnOrder?[...e.columnOrder]:void 0,columnWidths:e.columnWidths?{...e.columnWidths}:void 0,activeViewId:e.activeViewId}}function jl(e,r,n){n(e.id,{filters:Le(r.filters),sortStack:r.sortStack,grouping:r.grouping,columnVisibility:r.columnVisibility,columnOrder:r.columnOrder,columnWidths:r.columnWidths,activeViewId:r.activeViewId})}function wl(e,r,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(r)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:e==="number"&&["gt","gte","lt","lte","equals"].includes(r)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:e==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function Ds(e,r){const n=[],i=[],s=new Set(r.map(a=>a.name));return e.forEach(a=>{s.has(a.column)?n.push(a):i.push(a.column)}),{validRules:n,invalidColumns:i}}function $s(e,r){if(!e||!e.levels||e.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(r.map(a=>a.name)),i=[],s=[];return e.levels.forEach(a=>{n.has(a.column)?i.push(a):s.push(a.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...e,levels:i},invalidColumns:s}}function kl(e,r){const n=[],i=new Set(r.map(a=>a.name)),s={...e};if(s.filters){const a=c=>{const l=c.children.filter(p=>{if(Ye(p))return!0;const x=i.has(p.column);return x||n.push(`Filter for column "${p.column}" ignored (column not found)`),x}).map(p=>Ye(p)?a(p):p).filter(p=>!Ye(p)||p.children.length>0);return{...c,children:l}};s.filters=a(Le(s.filters))}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:a,invalidColumns:c}=Ds(s.sortStack,r);c.length>0&&n.push(`Sort rules for columns ignored: ${c.join(", ")}`),s.sortStack=a.length>0?a:void 0}if(s.grouping){const{validGrouping:a,invalidColumns:c}=$s(s.grouping,r);c.length>0&&n.push(`Grouping for columns ignored: ${c.join(", ")}`),s.grouping=a}if(s.columnVisibility){const a={};Object.entries(s.columnVisibility).forEach(([c,l])=>{i.has(c)?a[c]=l:n.push(`Column visibility for "${c}" ignored (column not found)`)}),s.columnVisibility=Object.keys(a).length>0?a:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const a=s.columnOrder.filter(c=>{const l=i.has(c);return l||n.push(`Column "${c}" in order ignored (column not found)`),l});s.columnOrder=a.length>0?a:void 0}if(s.columnWidths){const a={};Object.entries(s.columnWidths).forEach(([c,l])=>{i.has(c)?a[c]=l:n.push(`Column width for "${c}" ignored (column not found)`)}),s.columnWidths=Object.keys(a).length>0?a:void 0}return{sanitizedConfig:s,warnings:n}}function zl(e,r){return ur("processing","export",e,{retryAvailable:!!(r!=null&&r.onRetry)})}function Oi(e,r,n,i){const s=Is(e,r,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Es(i||[],s)}function Tl(e){return e==null}function Bl(e,r,n){const{operator:i,value:s}=r;if(i==="NULL")return e==null;if(i==="NOT_NULL")return e!=null;if(Tl(e))return!1;if(n==="date"){const a=new Date(e).getTime(),c=new Date(s).getTime();switch(i){case"equals":return a===c;case"gt":return a>c;case"lt":return a<c;case"gte":return a>=c;case"lte":return a<=c;default:return!0}}switch(i){case"equals":return String(e)===String(s);case"contains":return String(e).toLowerCase().includes(String(s).toLowerCase());case"startsWith":return String(e).toLowerCase().startsWith(String(s).toLowerCase());case"endsWith":return String(e).toLowerCase().endsWith(String(s).toLowerCase());case"gt":return Number(e)>Number(s);case"lt":return Number(e)<Number(s);case"gte":return Number(e)>=Number(s);case"lte":return Number(e)<=Number(s);case"isTrue":return e===!0;case"isFalse":return e===!1;default:return!0}}function Zn(e,r,n){var s;if(Ye(r))return r.children.length===0?!0:r.operator==="and"?r.children.every(a=>Zn(e,a,n)):r.children.some(a=>Zn(e,a,n));const i=((s=n.find(a=>a.name===r.column))==null?void 0:s.type)??"string";return Bl(e[r.column],r,i)}function Il(e,r,n){return!r||r.children.length===0?e:e.filter(i=>Zn(i,r,n))}function rn(e){switch(e){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"date":return[{value:"equals",label:"Is"},{value:"gt",label:"After"},{value:"lt",label:"Before"},{value:"gte",label:"On or after"},{value:"lte",label:"On or before"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function El(e){return e!=="isTrue"&&e!=="isFalse"&&e!=="NULL"&&e!=="NOT_NULL"}function Dl({data:e,filters:r,schema:n}){return{filteredData:f.useMemo(()=>!r||r.children.length===0?e:Il(e,r,n),[e,r,n])}}function $l(e,r,n,i){if(!n||n.trim()==="")return e;const s=n.toLowerCase().trim(),a=r.filter(c=>i.includes(c.name));return e.filter(c=>a.some(l=>{const p=c[l.name];return p==null?!1:String(p).toLowerCase().includes(s)}))}function _l({data:e,searchQuery:r,schema:n,visibleColumns:i,mode:s="client"}){return{searchedData:f.useMemo(()=>s==="server"||!r||r.trim()===""?e:$l(e,n,r,i),[e,r,n,i,s])}}function Ol({data:e,sortStack:r,schema:n}){return{sortedData:f.useMemo(()=>!r||r.length===0?e:Wa(e,n,r),[e,r,n])}}function Ml({data:e,grouping:r,schema:n}){const i=f.useMemo(()=>!r||!r.enabled||r.levels.length===0?e:La(e,n,r),[e,r,n]),s=(r==null?void 0:r.enabled)&&((r==null?void 0:r.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function Wl({schema:e,columnVisibility:r,columnOrder:n}){const i=f.useMemo(()=>n.filter(l=>r[l]!==!1),[n,r]),s=f.useMemo(()=>Object.entries(r).filter(([l,p])=>!p).map(([l,p])=>l),[r]),a=f.useMemo(()=>n.map(l=>e.find(x=>x.name===l)||{name:l,type:"string"}),[n,e]),c=f.useMemo(()=>i.map(l=>e.find(x=>x.name===l)||{name:l,type:"string"}),[i,e]);return{visibleColumns:i,hiddenColumns:s,allColumns:a,visibleColumnSchemas:c,hiddenCount:s.length}}function Al({views:e,activeViewId:r,currentState:n}){const i=f.useMemo(()=>e.find(x=>x.id===r),[e,r]),s=f.useMemo(()=>i?Ua(n,i.snapshot):!1,[i,n]),a=f.useMemo(()=>e.find(x=>x.isDefault),[e]),c=f.useMemo(()=>e.filter(x=>!x.isDefault&&!x.isDeleted),[e]),l=f.useMemo(()=>e.filter(x=>x.isFavorite&&!x.isDeleted),[e]),p=f.useMemo(()=>e.filter(x=>x.isDeleted),[e]);return{activeView:i,isDirty:s,defaultView:a,customViews:c,favoriteViews:l,deletedViews:p,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function Rl(e,r,n){if(!e||e.length===0)return[];if(r<=0)return e.slice(0,n);const i=e.slice(r,n);if(i.length===0)return[];const s=i[0],a=!!(s.__isGroupHeader||s.isGroupHeader),c=a?s.groupLevel??0:s.__urm_group_level__??0;if(c===0&&a)return i;const l=c-1;if(l<0)return i;const p={};let x=l+1;for(let g=r-1;g>=0;g--){const v=e[g];if(v.__isGroupHeader||v.isGroupHeader){const S=v.groupLevel??0;if(S<=l&&p[S]===void 0&&(p[S]=v,x--,x<=0))break}}const y=[];for(let g=0;g<=l;g++)p[g]&&y.push({...p[g],__urm_is_continuation_header__:!0});return[...y,...i]}function Pl({data:e,enabled:r=!1,pageSize:n=100,initialPage:i=1}){const[s,a]=f.useState(i),c=e.length,l=Math.max(1,Math.ceil(c/n));f.useEffect(()=>{s>l&&a(l)},[s,l]);const p=f.useMemo(()=>{if(!r)return e;const S=(s-1)*n,k=S+n;return Rl(e,S,k)},[e,r,s,n]),x=f.useCallback(S=>{const k=Math.max(1,Math.min(S,l));a(k)},[l]),y=f.useCallback(()=>{s<l&&a(S=>Math.min(S+1,l))},[l]),g=f.useCallback(()=>{s>1&&a(S=>Math.max(S-1,1))},[]),v=f.useCallback(()=>{a(1)},[]);return{paginatedData:p,currentPage:s,totalPages:l,pageSize:n,totalRows:c,goToPage:x,nextPage:y,prevPage:g,resetPage:v,hasNextPage:s<l,hasPrevPage:s>1}}function Nl(e){const{rawData:r,schema:n,filters:i,sortStack:s,grouping:a,searchQuery:c,searchMode:l,columnVisibility:p,columnOrder:x,columnWidths:y,views:g,activeViewId:v,pagination:S}=e,k=f.useMemo(()=>({filters:i,sortStack:s,grouping:a,columnVisibility:p,columnOrder:x,columnWidths:y}),[i,s,a,p,x,y]),b=Al({views:g,activeViewId:v,currentState:k}),m=Wl({schema:n,columnVisibility:p,columnOrder:x}),{filteredData:z}=Dl({data:r,filters:i,schema:n}),{sortedData:h}=Ol({data:z,sortStack:s,schema:n}),{groupedData:B,isGrouped:T}=Ml({data:h,grouping:a,schema:n}),{searchedData:j}=_l({data:B,searchQuery:c,schema:n,visibleColumns:m.visibleColumns,mode:l}),P=Pl({data:j,enabled:(S==null?void 0:S.enabled)||!1,pageSize:(S==null?void 0:S.pageSize)||100,initialPage:(S==null?void 0:S.currentPage)||1}),_=S!=null&&S.enabled?P.paginatedData:j,M=f.useMemo(()=>({totalRows:r.length,filteredRows:z.length,sortedRows:h.length,groupedRows:T?B.length:h.length,searchedRows:j.length,visibleRows:_.length,hiddenColumns:m.hiddenCount,activeFilters:Ct(i),activeSorts:s.length,isGrouped:T}),[r.length,z.length,h.length,B.length,j.length,_.length,m.hiddenCount,i,s.length,T]);return{data:_,filteredData:z,sortedData:h,groupedData:B,searchedData:j,viewEngine:b,columnEngine:m,paginationEngine:P,metrics:M,isGrouped:T,isPaginated:(S==null?void 0:S.enabled)||!1}}let Ll=0;function Fl(e,r){e!==null&&e.__urm_row_id__===void 0&&Object.defineProperty(e,"__urm_row_id__",{value:r?r(e):Ll++,writable:!1,enumerable:!1,configurable:!1})}const $t="user-demo-001";function Vl(e={}){var Po,yi,bi,vi,Si;const{mode:r="builder",autoLoad:n=!0,initialData:i,dataSource:s,pagination:a,search:c,scheduler:l,reportName:p,reportId:x,sharedReportId:y,sharedViewId:g,viewPersistence:v,config:S={}}=e,k=(v==null?void 0:v.mode)??"local",b=(a==null?void 0:a.mode)??"client",m=(c==null?void 0:c.mode)??"client",[z,h]=f.useState([]),B=Dr(),[T,j]=f.useState(""),[P,_]=f.useState(!1),[M,G]=f.useState(!1),[q,R]=f.useState({message:"",severity:"info",open:!1}),u=(w,D="info")=>{R({message:w,severity:D,open:!0})},A=()=>R(w=>({...w,open:!1})),F=S.notifDurationMs??2e3,d=z.find(w=>w.id===T),[ne,U]=f.useState("idle"),[re,xe]=f.useState(!1),[V,X]=f.useState(!1),[ae,le]=f.useState(!1),[ie,Q]=f.useState(!1),[de,I]=f.useState(!1),[te,he]=f.useState(void 0),[se,ze]=f.useState(null),[Y,We]=f.useState(null),[kt,dt]=f.useState(!1),[Or,Ot]=f.useState(!1),[ot,Ft]=f.useState(null),[qe,zt]=f.useState(!1),[fr,xt]=f.useState(!1),[tr,so]=f.useState({enabled:!1,levels:[],collapsedGroups:[]}),[rr,ao]=f.useState(""),[Tt,mr]=f.useState(""),[Je,Mt]=f.useState(new Set),[Vt,tt]=f.useState(1),[Qe,Wt]=f.useState(15),[lo,Mr]=f.useState(!1),[xr,Ve]=f.useState(!1),[ke,or]=f.useState(!1),[At,gr]=f.useState(null),[yr,Ht]=f.useState(!1),[nr,Ze]=f.useState(null),[ir,gt]=f.useState(null),Wr=f.useRef(null),ee=f.useMemo(()=>d?rl(d.permissions,$t):"owner",[d]),br=ol(ee),Ar=f.useMemo(()=>!(d!=null&&d.uploadedData)||!(d!=null&&d.schema)?{totalRows:0,totalColumns:0}:bl(d.uploadedData,d.schema),[d==null?void 0:d.uploadedData,d==null?void 0:d.schema]),Bt=f.useCallback(()=>{d&&(Wr.current=Cl(d))},[d]),H=f.useCallback((w,D)=>{h(W=>W.map(O=>O.id===w?{...O,...D}:O))},[]),ut=f.useCallback(w=>{if(!d)return;gt(w);const D=Oi(d.id,$t,w,d.auditHistory||[]);H(d.id,{auditHistory:D}),u(w.message,"error"),w.recoverable&&Wr.current&&setTimeout(()=>{jl(d,Wr.current,H),u("Previous state restored","success")},100)},[d,H]),we=f.useCallback((w,D,W,O)=>{if(!d)return;const J=Is(d.id,$t,w,D,W,O),K=d.auditHistory||[],ue=Es(K,J);setTimeout(()=>{H(d.id,{auditHistory:ue})},0)},[d,H]);f.useEffect(()=>{if(d!=null&&d.schemaLocked&&d.schema&&(!d.views||d.views.length===0)){const w=Nn(d.schema);(()=>{try{const D=localStorage.getItem("urm_dev_config");return D?JSON.parse(D):null}catch{return null}})(),H(d.id,{views:[w],activeViewId:w.id,filters:w.snapshot.filters,sortStack:w.snapshot.sortStack,columnVisibility:w.snapshot.columnVisibility,columnOrder:w.snapshot.columnOrder,columnWidths:w.snapshot.columnWidths,grouping:w.snapshot.grouping})}},[d==null?void 0:d.schemaLocked,d==null?void 0:d.schema,d==null?void 0:d.id,H]),f.useEffect(()=>{if(i&&n&&!M&&z.length===0){const w=So(i),D={id:x||`auto-report-${Date.now()}`,name:p||(r==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:w,schema:wi(go(w),S.hiddenColumns),permissions:{owner:$t,editors:[],viewers:[]}};h([D]),j(D.id),G(!0),U("confirmed")}},[i,n,M,z.length,r,p,x]),f.useEffect(()=>{b!=="server"||!M||!T||H(T,{uploadedData:So(i||[])})},[i,b,M,T]),f.useEffect(()=>{b==="server"&&((a==null?void 0:a.page)!==void 0&&tt(a.page),(a==null?void 0:a.pageSize)!==void 0&&Wt(a.pageSize))},[a==null?void 0:a.page,a==null?void 0:a.pageSize,b]),f.useEffect(()=>{if(!s||M)return;let w=!1,D=null;const W=async()=>{try{U("uploading");let O;if(s.type==="api"){const K=await fetch(s.url,{headers:s.headers||{}});if(!K.ok)throw new Error(`HTTP ${K.status}: ${K.statusText}`);O=await K.json()}else O=await s.fetch();if(w)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const J=go(O);if(M)h(K=>K.map(ue=>ue.id===T?{...ue,uploadedData:O}:ue)),U("confirmed");else{const K={id:x||`auto-report-${Date.now()}`,name:p||(r==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:So(O),schema:wi(go(So(O)),S.hiddenColumns),permissions:{owner:$t,editors:[],viewers:[]}};h([K]),j(K.id),G(!0),U("confirmed")}}catch(O){w||(U("error"),d&&H(d.id,{uploadError:(O==null?void 0:O.message)||"Failed to load data from source"}))}};return W(),s.refreshInterval&&s.refreshInterval>0&&(D=setInterval(W,s.refreshInterval)),()=>{w=!0,D&&clearInterval(D)}},[s,p,r,x]);const Ke=(Po=d==null?void 0:d.views)==null?void 0:Po.find(w=>w.id===d.activeViewId),sr=f.useMemo(()=>d!=null&&d.uploadedData?(d.uploadedData.forEach(w=>Fl(w,S.getRowId)),d.uploadedData):[],[d==null?void 0:d.uploadedData]);f.useEffect(()=>{Mt(w=>{if(w.size===0)return w;const D=new Set(sr.map(O=>O==null?void 0:O.__urm_row_id__)),W=new Set(Array.from(w).filter(O=>D.has(O==null?void 0:O.__urm_row_id__)));return W.size===w.size?w:W})},[sr]);const vr=Nl({rawData:sr,schema:(d==null?void 0:d.schema)||[],filters:Le(d==null?void 0:d.filters),sortStack:(d==null?void 0:d.sortStack)||[],grouping:(d==null?void 0:d.grouping)||null,searchQuery:Tt||"",searchMode:m,columnVisibility:(d==null?void 0:d.columnVisibility)||(Ke==null?void 0:Ke.snapshot.columnVisibility)||{},columnOrder:(d==null?void 0:d.columnOrder)||(Ke==null?void 0:Ke.snapshot.columnOrder)||[],columnWidths:(d==null?void 0:d.columnWidths)||(Ke==null?void 0:Ke.snapshot.columnWidths)||{},views:(d==null?void 0:d.views)||[],activeViewId:(d==null?void 0:d.activeViewId)||"",pagination:{enabled:b==="client",pageSize:Qe,currentPage:Vt}}),{data:co=[],searchedData:Ut=[],groupedData:Sr=[],sortedData:Gt=[],metrics:ar={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Yt=!1,paginationEngine:be}=vr||{},yt=b==="server"?(a==null?void 0:a.totalRows)??0:ar.searchedRows,Z=((yi=vr.viewEngine)==null?void 0:yi.activeView)||Ke,pe=((bi=vr.viewEngine)==null?void 0:bi.isDirty)||!1;f.useEffect(()=>{if(!(!Z||!d)&&!d.columnOrder){const w=Z.snapshot.columnOrder,D=Co(w,Z.snapshot.grouping);H(d.id,{columnOrder:D})}},[d==null?void 0:d.activeViewId]);const ye=f.useMemo(()=>!(d!=null&&d.schema)||!Z?null:Ha(d.filters,d.sortStack||[],d.schema,d.columnVisibility,d.columnOrder,d.columnWidths,d.grouping,Z.snapshot.columnOrder),[d==null?void 0:d.filters,d==null?void 0:d.sortStack,d==null?void 0:d.schema,d==null?void 0:d.columnVisibility,d==null?void 0:d.columnOrder,d==null?void 0:d.columnWidths,d==null?void 0:d.grouping,Z]),Cr=f.useMemo(()=>!Z||!ye||!pe?[]:Ya(ye,Z.snapshot),[Z,ye,pe]),jr=f.useCallback((w,D,W)=>{const O={id:`report-${Date.now()}`,name:w,description:D,schemaLocked:!1,permissions:{owner:$t,editors:[],viewers:[]}};if(W&&Array.isArray(W)&&W.length>0){const J=go(W),K=Nn(J);O.uploadedData=W,O.schema=J,O.schemaLocked=!0,O.views=[K],O.activeViewId=K.id,O.sortStack=K.snapshot.sortStack,O.filters=K.snapshot.filters,O.columnVisibility=K.snapshot.columnVisibility,O.columnOrder=K.snapshot.columnOrder,O.columnWidths=K.snapshot.columnWidths,O.grouping=K.snapshot.grouping}h(J=>[...J,O]),j(O.id),_(!1),U("confirmed")},[]),uo=f.useCallback(w=>{d&&(U("uploading"),setTimeout(()=>{const D=go(w);H(d.id,{uploadedData:w,schema:D,uploadError:void 0}),U("preview")},500))},[d,H]),Rr=f.useCallback(w=>{d&&(H(d.id,{uploadError:w}),U("idle"))},[d,H]),po=f.useCallback(()=>{d&&(H(d.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),U("idle"))},[d,H]),qt=f.useCallback(()=>{d&&(H(d.id,{schemaLocked:!0}),U("confirmed"))},[d,H]),Pr=f.useCallback(w=>{if(!d)return;if(!bt("edit_sorting",ee)){u(vt("edit_sorting"),"error");return}const D=d.sortStack??[],W=D.find(O=>O.column===w);if(W){const O=Aa(W.direction);if(O===null){const J=D.filter(K=>K.column!==w).map((K,ue)=>({...K,priority:ue+1}));H(d.id,{sortStack:J.length>0?J:void 0})}else{const J=O,K=D.map(ue=>ue.column===w?{...ue,direction:J}:ue);H(d.id,{sortStack:K})}}else{if(D.length>=B.sort.maxLevels){u(`Sort limit reached — maximum ${B.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:w,direction:"asc",priority:D.length+1};H(d.id,{sortStack:[...D,O]})}},[d,ee,H]),Nr=f.useCallback(w=>{if(d)if(d.schema){const{validRules:D,invalidColumns:W}=Ds(w,d.schema);W.length>0&&u(`Removed invalid sort columns: ${W.join(", ")}`),Bt();try{H(d.id,{sortStack:D.length>0?D:void 0})}catch(O){const J=ur("processing","sorting",O);ut(J)}}else H(d.id,{sortStack:w.length>0?w:void 0})},[d,H,Bt,ut]),ve=f.useCallback(w=>{if(!d)return;const D=d.sortStack??[],W=D.find(O=>O.column===w);if(!(W&&W.direction==="asc"))if(W){const O=D.map(J=>J.column===w?{...J,direction:"asc"}:J);H(d.id,{sortStack:O})}else{if(D.length>=B.sort.maxLevels){u(`Sort limit reached — maximum ${B.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:w,direction:"asc",priority:D.length+1};H(d.id,{sortStack:[...D,O]})}},[d,H]),Ge=f.useCallback(w=>{if(!d)return;const D=d.sortStack??[],W=D.find(O=>O.column===w);if(!(W&&W.direction==="desc"))if(W){const O=D.map(J=>J.column===w?{...J,direction:"desc"}:J);H(d.id,{sortStack:O})}else{if(D.length>=B.sort.maxLevels){u(`Sort limit reached — maximum ${B.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:w,direction:"desc",priority:D.length+1};H(d.id,{sortStack:[...D,O]})}},[d,H]),wr=f.useCallback((w,D)=>{var O;if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const W=(O=d.schema)==null?void 0:O.find(J=>J.name===D.column);if(W&&D.value!==void 0){const J=wl(W.type,D.operator,D.value);if(!J.isValid){u(J.errorMessage||"Invalid filter value","error");return}}Bt();try{const J=Le(d.filters),K={...D,id:no()},ue=io(J,w,K);we("filters","filter_added",null,K),H(d.id,{filters:ue})}catch(J){const K=ur("processing","filters",J);ut(K)}},[d,ee,H,Bt,ut,we]),st=f.useCallback(w=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const D=Le(d.filters),W=io(D,w,_t());we("filters","filter_added",null,"a condition group"),H(d.id,{filters:W})},[d,ee,H,we]),Jt=f.useCallback((w,D)=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const W=Le(d.filters),O=qo(W,w),J=si(W,w,D),K=qo(J,w);we("filters","filter_updated",O,K),H(d.id,{filters:J})},[d,ee,H,we]),It=f.useCallback((w,D)=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const W=Le(d.filters),O=ai(W,w,D);we("filters","filter_updated",null,`group operator changed to ${D.toUpperCase()}`),H(d.id,{filters:O})},[d,ee,H,we]),kr=f.useCallback(w=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const D=Le(d.filters),W=qo(D,w),O=li(D,w);we("filters","filter_removed",W,null),H(d.id,{filters:O})},[d,ee,H,we]),me=f.useCallback(()=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const w=Le(d.filters);we("filters","filter_cleared",{count:Ct(w)},null),H(d.id,{filters:_t()})},[d,ee,H,we]),Se=f.useCallback(w=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const D=Le(d.filters);we("filters","filter_cleared",{count:Ct(D)},{count:Ct(w)}),H(d.id,{filters:w})},[d,ee,H,we]),Ne=f.useCallback(w=>{var J;if(!d)return;const D=(J=d.views)==null?void 0:J.find(K=>K.id===w);if(!D)return;const W=D.snapshot.columnOrder,O=Co(W,D.snapshot.grouping);H(d.id,{filters:D.snapshot.filters,sortStack:D.snapshot.sortStack.length>0?[...D.snapshot.sortStack]:void 0,columnVisibility:{...D.snapshot.columnVisibility},columnOrder:O,columnWidths:{...D.snapshot.columnWidths},grouping:D.snapshot.grouping,activeViewId:w}),Mt(new Set)},[d,H]),nt=f.useCallback((w,D,W)=>{var He;if(!(d!=null&&d.schema)||!ye)return;const O=d.views??[],J=O.filter(Pn=>!Pn.isDeleted).length,K=((He=B.views)==null?void 0:He.maxViews)??10;if(J>=K){u(`View limit reached — you can have at most ${K} saved views. Delete an existing view to create a new one.`,"error");return}const ue={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:w,description:D||void 0,isDefault:W,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:$t,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...ye}},je=W?O.map(Pn=>({...Pn,isDefault:!1})):O;H(d.id,{views:[...je,ue],activeViewId:ue.id}),u(`"${w}" view created`,"success")},[d,ye,H]),Et=f.useCallback(w=>{var ue;if(!(d!=null&&d.views))return;const D=d.views.find(je=>je.id===w);if(!D)return;const W=d.views,O=W.filter(je=>!je.isDeleted).length,J=((ue=B.views)==null?void 0:ue.maxViews)??10;if(O>=J){u(`View limit reached — you can have at most ${J} saved views. Delete an existing view to create a new one.`,"error");return}const K={...D,id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:`${D.name} (copy)`,scope:"personal",isDefault:!1,isFavorite:!1,isDeleted:!1,createdBy:$t,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...D.snapshot}};H(d.id,{views:[...W,K]}),u(`"${K.name}" created`,"success")},[d,B,H]),zr=f.useCallback(()=>{var D;if(!Z||!ye||!d)return;const w=(D=d.views)==null?void 0:D.map(W=>W.id===Z.id?{...W,snapshot:{...ye}}:W);H(d.id,{views:w}),u(`"${Z.name}" view updated`,"success")},[Z,ye,d,H]),Lr=f.useCallback(w=>{var O;if(!Z||!ye||!d)return;const D=w??ye.columnWidths,W=(O=d.views)==null?void 0:O.map(J=>J.id===Z.id?{...J,snapshot:{...J.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:D},updatedAt:Date.now()}:J);H(d.id,{views:W,columnWidths:D}),u(`Column configuration saved to "${Z.name}"`,"success")},[Z,ye,d,H]),Fr=f.useCallback(w=>{var K,ue;if(!ye||!d||!Z)return;const D=w??ye.columnWidths,W={...Z,snapshot:{...Z.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:D},updatedAt:Date.now()},O=(K=d.views)==null?void 0:K.map(je=>je.id===Z.id?W:{...je,snapshot:{...je.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:D},updatedAt:Date.now()});H(d.id,{views:O,columnWidths:D});const J=(((ue=d.views)==null?void 0:ue.length)||0)-1;u(`Column configuration saved to current view and ${J} other view${J===1?"":"s"}`,"success")},[ye,d,Z,H]),kn=f.useCallback(()=>{le(!0)},[]),Vr=f.useCallback(()=>{if(!Z||!d)return;const w=Z.snapshot.columnOrder,D=Co(w,Z.snapshot.grouping);H(d.id,{filters:Z.snapshot.filters,sortStack:Z.snapshot.sortStack.length>0?[...Z.snapshot.sortStack]:void 0,columnVisibility:{...Z.snapshot.columnVisibility},columnOrder:D,columnWidths:{...Z.snapshot.columnWidths},grouping:Z.snapshot.grouping}),u("Changes reverted to last saved state","success")},[Z,d,H]),ho=f.useCallback(w=>{if(!(d!=null&&d.views))return;const D=d.views.map(O=>({...O,isDefault:O.id===w}));H(d.id,{views:D});const W=d.views.find(O=>O.id===w);W&&u(`"${W.name}" set as default view`,"success")},[d,H]),zn=f.useCallback(w=>{if(!(d!=null&&d.views))return;const D=d.views.map(O=>O.id===w?{...O,isFavorite:!O.isFavorite,updatedAt:Date.now()}:O);H(d.id,{views:D});const W=d.views.find(O=>O.id===w);W&&!W.isFavorite?u(`"${W.name}" added to favorites`,"success"):W&&u(`"${W.name}" removed from favorites`,"info")},[d,H]),_o=f.useCallback(w=>{if(!(d!=null&&d.views))return;const D=d.views.find(He=>He.id===w),W=d.views.filter(He=>!He.isDeleted||He.id===w);if((D==null?void 0:D.isDefault)&&W.filter(He=>He.isDefault).length===1){u("Cannot delete the last default view","error");return}const J=d.views.map(He=>He.id===w?{...He,isDeleted:!0,updatedAt:Date.now()}:He),K=d.activeViewId===w,ue=J.find(He=>He.isDefault&&!He.isDeleted);H(d.id,{views:J,activeViewId:K&&ue?ue.id:d.activeViewId,filters:K&&ue?ue.snapshot.filters:d.filters,sortStack:K&&ue?ue.snapshot.sortStack.length>0?ue.snapshot.sortStack:void 0:d.sortStack});const je=d.views.find(He=>He.id===w);je&&u(`"${je.name}" moved to Recently Deleted`,"info")},[d,H]),Hr=f.useCallback(w=>{if(!(d!=null&&d.views))return;const D=d.views.map(O=>O.id===w?{...O,isDeleted:!1,updatedAt:Date.now()}:O);H(d.id,{views:D});const W=d.views.find(O=>O.id===w);W&&u(`"${W.name}" restored`,"success")},[d,H]),Oo=f.useCallback(w=>{if(!(d!=null&&d.views))return;const D=d.views.find(je=>je.id===w),W=d.views.filter(je=>!je.isDeleted||je.id===w);if((D==null?void 0:D.isDefault)&&W.filter(je=>je.isDefault).length===1){u("Cannot delete the last default view","error");return}const J=d.views.filter(je=>je.id!==w),K=d.activeViewId===w,ue=J.find(je=>je.isDefault&&!je.isDeleted);H(d.id,{views:J,activeViewId:K&&ue?ue.id:d.activeViewId,filters:K&&ue?ue.snapshot.filters:d.filters,sortStack:K&&ue?ue.snapshot.sortStack.length>0?ue.snapshot.sortStack:void 0:d.sortStack}),D&&u(`"${D.name}" permanently deleted`,"success")},[d,H]),Ur=f.useCallback(w=>{ze(w),Q(!0)},[]),Gr=f.useCallback(async w=>{if(!d)return;const D=new URLSearchParams(window.location.search);D.set("reportId",d.id),D.set("view",w);const W=`${window.location.origin}${window.location.pathname}?${D.toString()}`,O=await yl(W);u(O?"Link copied to clipboard":"Failed to copy link",O?"success":"error")},[d]),fo=f.useCallback((w,D)=>{if(!se||!(d!=null&&d.views))return;const W=d.views.map(O=>O.id===se?{...O,name:w,description:D||void 0}:O);H(d.id,{views:W}),ze(null)},[se,d,H]),Yr=f.useCallback(w=>{We(w),I(!0)},[]),qr=f.useCallback(()=>{if(!Y||!(d!=null&&d.views))return;const w=d.views.filter(O=>O.id!==Y),D=d.activeViewId===Y,W=w.find(O=>O.isDefault);H(d.id,{views:w,activeViewId:D&&W?W.id:d.activeViewId,filters:D&&W?W.snapshot.filters:d.filters,sortStack:D&&W?W.snapshot.sortStack.length>0?W.snapshot.sortStack:void 0:d.sortStack}),We(null),I(!1)},[Y,d,H]),lr=f.useCallback(w=>{var J;if(!(d!=null&&d.views))return;if(!(((J=B.views)==null?void 0:J.isAdmin)??!1)){u("Only administrators can promote views to Global.","error");return}const W=d.views.find(K=>K.id===w);if(!W)return;if(W.scope==="global"){u(`"${W.name}" is already a Global View.`,"info");return}const O=d.views.map(K=>K.id===w?{...K,scope:"global",isDefault:!0,updatedAt:Date.now()}:K.scope==="global"&&K.isDefault?{...K,isDefault:!1}:K);H(d.id,{views:O}),u(`"${W.name}" promoted to Global View and set as default.`,"success")},[d,B,H]),mo=f.useRef(!0);f.useEffect(()=>{var w;if(mo.current){mo.current=!1;return}if(b==="server"){tt(1),(w=a==null?void 0:a.onPaginationChange)==null||w.call(a,1,Qe);return}be!=null&&be.resetPage?be.resetPage():tt(1)},[d==null?void 0:d.filters,Tt,d==null?void 0:d.activeViewId,d==null?void 0:d.grouping]);const Jr=f.useCallback(w=>{var D;if(b==="server"){tt(w),(D=a==null?void 0:a.onPaginationChange)==null||D.call(a,w,Qe);return}be!=null&&be.goToPage&&be.goToPage(w),tt(w)},[b,a,Qe,be]),Tn=f.useCallback(w=>{var O;const D=(Vt-1)*Qe,W=Math.floor(D/w)+1;if(b==="server"){Wt(w),tt(W),(O=a==null?void 0:a.onPaginationChange)==null||O.call(a,W,w);return}Wt(w),tt(W),be==null||be.goToPage(W)},[Vt,Qe,b,a,be]),Bn=f.useCallback((w,D)=>{if(!d)return;if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}const O={...d.columnVisibility||(Z==null?void 0:Z.snapshot.columnVisibility)||{},[w]:D};H(d.id,{columnVisibility:O})},[d,Z,ee,H]),In=f.useCallback(w=>{if(d){if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}H(d.id,{columnOrder:w})}},[d,ee,H]),En=f.useCallback((w,D)=>{if(!d)return;if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}const O={...d.columnWidths||(Z==null?void 0:Z.snapshot.columnWidths)||{},[w]:D};H(d.id,{columnWidths:O})},[d,Z,ee,H]),Dn=f.useCallback(w=>{if(!d)return;const D=Le(d.filters),W=zs(D,w);H(d.id,{filters:W})},[d,H]),$n=f.useCallback(()=>{if(!Z||!(d!=null&&d.schema))return;const w={},D=[],W={};d.schema.forEach(O=>{w[O.name]=!0,D.push(O.name),W[O.name]=170}),H(d.id,{columnVisibility:w,columnOrder:D,columnWidths:W,filters:void 0,sortStack:void 0}),u("Reset to default layout - all filters and sorts cleared","success")},[Z,d,H]);f.useEffect(()=>{const w=setTimeout(()=>mr(rr),300);return()=>clearTimeout(w)},[rr]),f.useEffect(()=>{var w;m==="server"&&((w=c==null?void 0:c.onSearchChange)==null||w.call(c,Tt))},[Tt,m,c]);const _n=f.useCallback(w=>{ao(w)},[]),On=f.useCallback(w=>{if(!w.trim()||!d)return;const D=d.searchHistory||[],W=Xa(D,w);H(d.id,{searchHistory:W})},[d,H]),Mn=f.useCallback(w=>{if(!d)return;const D=d.searchHistory||[],W=Qa(D,w);H(d.id,{searchHistory:W})},[d,H]),Kr=f.useCallback(w=>{if(!d)return;const D=d.searchHistory||[],W=Za(D,w);H(d.id,{searchHistory:W})},[d,H]);f.useEffect(()=>{if(!S.onSelectionChange)return;const w=Array.from(Je);S.onSelectionChange(w,w.map(D=>D==null?void 0:D.__urm_row_id__))},[Je,S.onSelectionChange]);const Kt=f.useCallback(w=>{const D=w==null?void 0:w.__urm_row_id__;Mt(W=>{const O=new Set(W);if(D!==void 0){const J=Array.from(O).find(K=>(K==null?void 0:K.__urm_row_id__)===D);J!==void 0?O.delete(J):O.add(w)}else{const J=JSON.stringify(w),K=Array.from(O).find(ue=>JSON.stringify(ue)===J);K!==void 0?O.delete(K):O.add(w)}return O})},[]),Wn=f.useCallback((w,D)=>{Mt(W=>{const O=new Set(W);for(const J of D)w?O.add(J):O.delete(J);return O})},[]),An=f.useCallback((w,D,W)=>{Mt(O=>{const J=new Set(O),K=Math.min(w,D),ue=Math.max(w,D);for(let je=K;je<=ue;je++)W[je]!==void 0&&J.add(W[je]);return J})},[]),Me=f.useCallback(()=>{Mt(new Set)},[]),at=f.useCallback(w=>{const D=w==null?void 0:w.__urm_row_id__;Mt(W=>{const O=new Set(W);if(D!==void 0){const J=Array.from(O).find(K=>(K==null?void 0:K.__urm_row_id__)===D);J!==void 0&&O.delete(J)}else O.delete(w);return O})},[]),xo=f.useCallback(w=>{var D,W;if(d){if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}if(w&&d.schema){const{validGrouping:O,invalidColumns:J}=$s(w,d.schema);J.length>0&&u(`Removed invalid grouping columns: ${J.join(", ")}`,"warning"),Bt();try{const K=d.grouping;O===null?we("grouping","group_cleared",K,null):K?we("grouping","group_reordered",K,O):we("grouping","group_level_added",null,O);const ue=(Z==null?void 0:Z.snapshot.columnOrder)||d.columnOrder||[],je=Co(ue,O),He=O.levels.length>0?{...O,collapsedGroups:zi(Gt,d.schema,O)}:O;H(d.id,{grouping:He,columnOrder:je}),tt(1),be==null||be.resetPage(),b==="server"&&((D=a==null?void 0:a.onPaginationChange)==null||D.call(a,1,Qe)),JSON.stringify(je)!==JSON.stringify(d.columnOrder)&&we("columns","column_reordered",d.columnOrder,je),xt(!1)}catch(K){const ue=ur("processing","grouping",K);ut(ue)}}else{const O=d.grouping;we("grouping","group_cleared",O,null);const J=(Z==null?void 0:Z.snapshot.columnOrder)||d.columnOrder||[];H(d.id,{grouping:w,columnOrder:J}),tt(1),be==null||be.resetPage(),b==="server"&&((W=a==null?void 0:a.onPaginationChange)==null||W.call(a,1,Qe)),JSON.stringify(J)!==JSON.stringify(d.columnOrder)&&we("columns","column_reordered",d.columnOrder,J),xt(!1)}}},[d,Z,ee,H,Bt,ut,we,Gt]),Mo=f.useCallback(w=>{if(!d)return;const D=d.grouping;if(!D)return;const W=Fa(D,w);H(d.id,{grouping:W})},[d,H]),Rn=f.useCallback(()=>{d!=null&&d.grouping&&H(d.id,{grouping:{...d.grouping,collapsedGroups:[]}})},[d,H]),Dt=f.useCallback(()=>{if(!(d!=null&&d.grouping)||!d.schema)return;const w=zi(Gt,d.schema,d.grouping);H(d.id,{grouping:{...d.grouping,collapsedGroups:w}})},[d,Gt,H]),Tr=f.useCallback(()=>{Ht(!0)},[]),pt=f.useCallback(w=>{d!=null&&d.schema&&(dt(!0),setTimeout(()=>{try{let D;w.scope==="visible"?D=Ut:D=d.uploadedData||[];let W;w.columnScope==="all"?(W={},(d.schema??[]).forEach(je=>{W[je.name]=!0})):W=d.columnVisibility||(Z==null?void 0:Z.snapshot.columnVisibility)||{};const O=d.columnOrder||(Z==null?void 0:Z.snapshot.columnOrder),J=Qo(D,d.schema,Le(d.filters),d.sortStack??[],Z,W,O),K=d.name;let ue;switch(w.format){case"csv":Zo(J,K,w),ue="export_csv";break;case"excel":en(J,K,w),ue="export_excel";break;case"json":tn(J,K,w),ue="export_json";break;case"pdf":ui(J,K,w),ue="export_pdf";break}we("export",ue,null,{format:w.format,scope:w.scope,columnScope:w.columnScope,rowCount:D.length,viewName:(Z==null?void 0:Z.name)||"Default View"}),u(`Export completed successfully (${w.format.toUpperCase()})`,"success")}catch(D){const W=zl(D,{onRetry:()=>pt(w)});u(`Export failed: ${W.message}. Click Export to retry.`,"error");const O=Oi(d.id,$t,W,d.auditHistory||[]);H(d.id,{auditHistory:O}),Lt.error("urm:report-engine","Export failed",D)}finally{dt(!1)}},500))},[d,Z,Ut,H,we]),Wo=f.useCallback(w=>{if(d!=null&&d.schema){if(pe&&Z&&!Z.isDefault){Ft(w.format),Ot(!0),Ht(!1);return}pt(w),Ht(!1)}},[d,Z,pe,pt]),Xr=f.useCallback(w=>{pt({format:w,scope:"visible",columnScope:"visible"})},[pt]),Ao=f.useCallback(()=>{ot&&Xr(ot),Ot(!1),Ft(null)},[ot,Xr]),Ro=f.useCallback(()=>{zr(),ot&&Xr(ot),Ot(!1),Ft(null)},[zr,ot,Xr]),C=f.useCallback(()=>{Ot(!1),Ft(null)},[]),N=f.useCallback(w=>{!(d!=null&&d.schema)||Je.size===0||(dt(!0),setTimeout(()=>{try{const D=Array.from(Je),W=Qo(D,d.schema,Le(d.filters),d.sortStack??[],Z),O=`${d.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(w){case"csv":Zo(W,O);break;case"excel":en(W,O);break;case"json":tn(W,O);break}u(`Exported ${D.length} selected rows`,"info")}catch(D){u("Export failed. Please try again.","error"),Lt.error("urm:report-engine","Bulk export failed",D)}finally{dt(!1)}},500))},[d,Z,Je,Sr]),oe=f.useCallback((w,D)=>{if(d)try{const W=pl(d),O=hl(w,D,$t,W),J=fl(d.presets,O);H(d.id,{presets:J}),we("presets","preset_created",null,{presetId:O.id,name:O.name}),Ve(!1),u(`Preset "${w}" saved successfully`,"success")}catch(W){u(W instanceof Error?W.message:"Failed to create preset","error")}},[d,H,we]),Ce=f.useCallback(()=>{gr(null),u("Exited preset view","info")},[]),Ae=f.useCallback(()=>{or(!0)},[]),rt=f.useCallback((w,D)=>{if(!d)return;const W=ml(d.presets,w);H(d.id,{presets:W}),we("presets","preset_deleted",{presetId:w,name:D},null),At===w&&gr(null),u(`Preset "${D}" deleted`,"success")},[d,At,H,we]);f.useEffect(()=>{if(!y||z.length===0)return;const w=z.find(D=>D.id===y);w&&w.id!==T&&j(w.id)},[y,z,T]);const Xe=f.useRef(!1);f.useEffect(()=>{var D;if(!g||Xe.current||!d||d.id!==y)return;const w=(D=d.views)==null?void 0:D.find(W=>W.id===g&&!W.isDeleted);w&&Ne(w.id),Xe.current=!0},[g,y,d,Ne]),f.useEffect(()=>{if(!d)return;const w=xl();if(w&&d.presets&&d.schemaLocked&&d.schema){const D=_i(d.presets,w);if(D){const{sanitizedConfig:W,warnings:O}=kl(D.config,d.schema);O.length>0&&O.forEach(K=>u(K,"warning"));const J=gl(W);H(d.id,J),gr(w),we("presets","preset_applied",null,{presetId:D.id,name:D.name}),u(`Loaded preset: ${D.name}`,"info")}else u("Preset not found","info")}},[d==null?void 0:d.schemaLocked]);const fe=At?_i(d==null?void 0:d.presets,At):void 0;f.useEffect(()=>{var w;d!=null&&d.views&&d.views.length>0&&d.activeViewId&&(k==="api"?(w=v==null?void 0:v.onViewsChange)==null||w.call(v,d.views,d.activeViewId):qa(d.id,{views:d.views,activeViewId:d.activeViewId}))},[d==null?void 0:d.views,d==null?void 0:d.activeViewId,d==null?void 0:d.id,k]),f.useEffect(()=>{if(d!=null&&d.schemaLocked&&d.schema&&(!d.views||d.views.length===0)){const w=k==="api"?v!=null&&v.views&&v.views.length>0?{views:v.views,activeViewId:v.activeViewId??v.views[0].id}:null:Ja(d.id);if(w&&w.views.length>0){const D=w.views.find(W=>W.id===w.activeViewId);if(D)H(d.id,{views:w.views,activeViewId:w.activeViewId,filters:Le(D.snapshot.filters),sortStack:D.snapshot.sortStack.length>0?D.snapshot.sortStack:void 0});else{const W=w.views.find(O=>O.isDefault)||Nn(d.schema);H(d.id,{views:w.views,activeViewId:W.id,filters:Le(W.snapshot.filters),sortStack:W.snapshot.sortStack.length>0?W.snapshot.sortStack:void 0})}}}},[d==null?void 0:d.schemaLocked,d==null?void 0:d.schema,d==null?void 0:d.id,k,v]);const Rt=f.useCallback(w=>{var O;const D=Le(d==null?void 0:d.filters),W=((O=B.filter)==null?void 0:O.maxConditions)??3;if(Ct(D)>=W){u(`Filter limit reached — maximum ${W} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}he(w),xe(!0)},[d,B,u]),Xt=f.useCallback(()=>{xe(!1),he(void 0)},[]),_e=(vi=d==null?void 0:d.views)==null?void 0:vi.find(w=>w.id===se),cr=(Si=d==null?void 0:d.views)==null?void 0:Si.find(w=>w.id===Y);return{reports:z,activeReport:d,activeReportId:T,setActiveReportId:j,isModalOpen:P,setIsModalOpen:_,createReport:jr,updateReport:H,uploadState:ne,handleFileUpload:uo,handleUploadError:Rr,handleRetry:po,handleConfirm:qt,paginatedData:co,processedData:Ut,displayData:Sr,tableMetrics:ar,isGrouped:Yt,tableEngine:vr,activeView:Z,isDirty:pe,currentTableState:ye,viewChanges:Cr,filters:d==null?void 0:d.filters,showFilterPanel:re,setShowFilterPanel:xe,filterFocusColumn:te,handleAddCondition:wr,handleAddGroup:st,handleUpdateCondition:Jt,handleSetGroupOperator:It,handleRemoveFilterNode:kr,handleClearAllFilters:me,handleReplaceFilters:Se,handleOpenFilterForColumn:Rt,handleCloseFilterPanel:Xt,handleClearFiltersForColumn:Dn,sortStack:d==null?void 0:d.sortStack,showSortPanel:V,setShowSortPanel:X,handleSort:Pr,handleUpdateSortStack:Nr,handleSortAscending:ve,handleSortDescending:Ge,views:d==null?void 0:d.views,showCreateViewModal:ae,setShowCreateViewModal:le,showEditViewModal:ie,setShowEditViewModal:Q,showDeleteConfirmation:de,setShowDeleteConfirmation:I,editingView:_e,deletingView:cr,editingViewId:se,deletingViewId:Y,handleSelectView:Ne,handleCreateView:nt,handleCloneView:Et,handleUpdateCurrentView:zr,handleSaveColumnConfigToCurrentView:Lr,handleSaveColumnConfigToAllViews:Fr,handleSaveAsNewView:kn,handleRevertChanges:Vr,handleToggleDefault:ho,handleToggleFavorite:zn,handleSoftDelete:_o,handleRestoreView:Hr,handlePermanentDelete:Oo,handleEditView:Ur,handleCopyViewLink:Gr,handleSaveEditView:fo,handleDeleteView:Yr,handleConfirmDelete:qr,handlePromoteToGlobal:lr,showManageColumns:qe,setShowManageColumns:zt,columnVisibility:d==null?void 0:d.columnVisibility,columnOrder:d==null?void 0:d.columnOrder,columnWidths:d==null?void 0:d.columnWidths,handleUpdateColumnVisibility:Bn,handleUpdateColumnOrder:In,handleUpdateColumnWidth:En,handleResetColumnLayout:$n,showGroupPanel:fr,setShowGroupPanel:xt,grouping:d==null?void 0:d.grouping,groupingState:tr,handleGroup:xo,handleToggleGroupCollapse:Mo,handleExpandAllGroups:Rn,handleCollapseAllGroups:Dt,searchQuery:rr,debouncedSearchQuery:Tt,searchHistory:el((d==null?void 0:d.searchHistory)||[]),handleSearchChange:_n,handleAddToSearchHistory:On,handleToggleSearchFavourite:Mn,handleDeleteSearchHistory:Kr,selectedRowIds:Je,handleToggleRowSelection:Kt,handleToggleAllRows:Wn,handleRangeSelection:An,handleClearSelection:Me,handleUpdateSelectionAfterDelete:at,currentPage:Vt,pageSize:Qe,paginationEngine:be,paginationMode:b,paginationTotalRows:yt,handlePageChange:Jr,handlePageSizeChange:Tn,isExporting:kt,showExportModal:yr,setShowExportModal:Ht,showDirtyExportWarning:Or,handleExport:Tr,handleExportWithConfig:Wo,handleExportSelected:N,handleExportAnyway:Ao,handleSaveAndExport:Ro,handleCancelExport:C,showAuditHistory:lo,setShowAuditHistory:Mr,auditHistory:d==null?void 0:d.auditHistory,showCreatePreset:xr,setShowCreatePreset:Ve,showManagePresets:ke,setShowManagePresets:or,activePreset:fe,activePresetId:At,handleOpenManagePresets:Ae,handleCreatePreset:oe,handleClearActivePreset:Ce,handleDeletePresetById:rt,userRole:ee,isViewerRole:br,currentUserId:$t,featureLimitWarning:nr,setFeatureLimitWarning:Ze,datasetMeta:Ar,reportError:ir,setReportError:gt,handleError:ut,schema:d==null?void 0:d.schema,hasSchemaConflicts:d!=null&&d.schema?Oa(d.schema):!1,snack:q,handleSnackClose:A,showSnack:u,snackDurationMs:F,config:S,scheduler:l}}const _s=f.createContext(void 0);function pi(e){const{children:r,initialData:n,data:i,reportName:s,reportId:a,dataSource:c,pagination:l,search:p,scheduler:x,mode:y="builder",autoLoad:g=!0,config:v,devConfig:S,showDevPanel:k=!1,sharedReportId:b,sharedViewId:m,viewPersistence:z}=e,B=Vl({mode:y,autoLoad:g,initialData:i||n,dataSource:c,pagination:l,search:p,scheduler:x,reportName:s,reportId:a,sharedReportId:b,sharedViewId:m,viewPersistence:z,config:v}),[T,j]=f.useState(()=>xa()),P=(()=>{const q=ya(T,S,!!S);return{...q,display:{...q.display,showDevPanel:k||q.display.showDevPanel}}})(),_=f.useCallback(G=>{j(G),ga(G)},[]),M={...B,activeDevConfig:P,handleDevConfigChange:_};return t.jsx(Cs.Provider,{value:P,children:t.jsx(_s.Provider,{value:M,children:r})})}function cn(){const e=f.useContext(_s);if(e===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return e}function Hl({onCreateReport:e,reports:r=[],activeReportId:n,onReportClick:i}){const s=r.find(a=>a.id===n);return t.jsx(o.Box,{component:"header",sx:a=>{var y,g,v;const c=((v=(g=(y=a.components)==null?void 0:y.MuiCardHeader)==null?void 0:g.styleOverrides)==null?void 0:v.root)||{},l=c.backgroundColor&&c.backgroundColor!=="transparent"?c.backgroundColor:a.palette.background.paper,p=c.borderBottom&&c.borderBottom!=="none"?c.borderBottom:"1px solid",x=c.boxShadow&&c.boxShadow!=="none"?c.boxShadow:void 0;return{position:"sticky",top:0,zIndex:50,borderBottom:p,borderColor:p!=="none"?"divider":void 0,boxShadow:x,bgcolor:l}},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[t.jsxs(o.Breadcrumbs,{separator:t.jsx($.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[t.jsx(o.Typography,{variant:"h6",component:"h1",sx:{fontWeight:a=>a.typography.h6.fontWeight||500,fontSize:a=>a.typography.h6.fontSize||"1.375rem",color:a=>a.typography.h6.color||"text.primary",letterSpacing:"-0.01em",cursor:r.length>0&&s?"pointer":"default","&:hover":r.length>0&&s?{color:"primary.main"}:{}},onClick:()=>{r.length>0},children:"Reports"}),s&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.Typography,{sx:{fontWeight:a=>a.typography.h6.fontWeight||500,fontSize:a=>a.typography.h6.fontSize||"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(s.id),children:s.name}),t.jsx(o.Tooltip,{title:s.description||"No description",arrow:!0,placement:"bottom",children:t.jsx($.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:t.jsx(o.Button,{variant:"contained",startIcon:t.jsx($.Add,{sx:{fontSize:18}}),onClick:e,sx:{borderRadius:"20px",px:3,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Er(e,...r){const n=new URL(`https://mui.com/production-error/?code=${e}`);return r.forEach(i=>n.searchParams.append("args[]",i)),`Minified MUI error #${e}; visit ${n} for the full message.`}const Ul="$$material";function Gl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fo={exports:{}},Vo={exports:{}},Te={};/** @license React v16.13.1
|
|
105
|
+
</html>`;try{const m=document.createElement("iframe");m.style.position="fixed",m.style.right="0",m.style.bottom="0",m.style.width="0",m.style.height="0",m.style.border="0",document.body.appendChild(m);const z=((b=m.contentWindow)==null?void 0:b.document)||m.contentDocument;if(z){z.open(),z.write(g),z.close(),setTimeout(()=>{var h,B;try{(h=m.contentWindow)==null||h.focus(),(B=m.contentWindow)==null||B.print()}catch{}setTimeout(()=>{document.body.removeChild(m)},3e3)},300);return}}catch{}const v=new Blob([g],{type:"text/html;charset=utf-8;"}),S=URL.createObjectURL(v);window.open(S,"_blank")||di(g,ln(r,"html"),"text/html;charset=utf-8;")}function Lo(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const Ii=10;function Xa(e,r){const n=r.trim();if(!n)return e;const i=e.findIndex(a=>a.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...e[i],lastUsed:Date.now()},...e.slice(0,i),...e.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...e],s.length>Ii&&(s=[...s].sort((c,l)=>c.isFavourite&&!l.isFavourite?-1:!c.isFavourite&&l.isFavourite?1:l.lastUsed-c.lastUsed).slice(0,Ii)),s}function Qa(e,r){return e.map(n=>n.query===r?{...n,isFavourite:!n.isFavourite}:n)}function Za(e,r){return e.filter(n=>n.query!==r)}function el(e){const r=e.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=e.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...r,...n]}const tl={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function rl(e,r){return!e||e.owner===r?"owner":e.editors.includes(r)?"editor":(e.viewers.includes(r),"viewer")}function bt(e,r){return tl[r].includes(e)}function vt(e){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data",promote_global_view:"promote views to global"}[e]||"perform this action"}.`}function ol(e){return e==="viewer"}const Ei=1e3;function Qn(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}function Nt(e){if(!e)return"";const n=e.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Qn(n)}const nl={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function il(e){if(!e||!e.column)return"a filter";const r=Nt(e.column),n=nl[e.operator]??e.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(e.operator)?`"${r}" ${n}`:`"${r}" ${n} "${e.value}"`}function Ln(e){return e?typeof e=="string"?e:"children"in e?"a condition group":il(e):"a filter"}function Di(e){return!e||!e.enabled||e.levels.length===0?"grouping removed":`grouped by ${e.levels.map(n=>`"${Nt(n.column)}"`).join(", ")}`}function sl(e){var s,a,c;const{action:r,previousState:n,newState:i}=e;switch(r){case"filter_added":return{summary:`Filter added: ${Ln(i)}`};case"filter_removed":return{summary:`Filter removed: ${Ln(n)}`};case"filter_updated":{if(typeof i=="string")return{summary:`Filter updated: ${i}`};const l=n,p=i;return l!=null&&l.column&&(p!=null&&p.column)&&l.column!==p.column?{summary:`Filter changed on "${Nt(p.column)}"`,detail:`Previously filtered "${Nt(l.column)}"`}:{summary:`Filter updated: ${Ln(p)}`}}case"filter_cleared":{const l=n&&typeof n=="object"&&"count"in n?n.count:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?Nt(i.column):"",p=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${p}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?Nt(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${Di(i)}`};case"group_level_removed":{const l=n,p=(a=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&a.column?Nt(l.levels[0].column):"";return{summary:p?`Group level removed: "${p}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${Di(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${Nt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${Nt(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],p=Array.isArray(i)?i:[];return l.length>0&&p.length>0?{summary:"Column order changed",detail:`${p.length} column${p.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",p=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${Nt(l)}"`:"Column resized",detail:p?`New width: ${p}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",p=(i==null?void 0:i.name)??"";return l&&p?{summary:`Switched to view "${p}"`,detail:`From "${l}"`}:p?{summary:`Switched to view "${p}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":case"export_pdf":{const l=r==="export_csv"?"CSV":r==="export_excel"?"Excel":r==="export_json"?"JSON":"PDF",p=i==null?void 0:i.rowCount,x=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",y=(i==null?void 0:i.viewName)??"",g=typeof p=="number"?` (${p.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${g}`,detail:y?`${Qn(x)} · View: "${y}"`:Qn(x)}}case"export_triggered":{const l=((c=i==null?void 0:i.format)==null?void 0:c.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",p=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&p?{summary:`Theme changed from "${l}" to "${p}"`}:p?{summary:`Theme changed to "${p}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:ll(r)}}}function al(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Is(e,r,n,i,s,a){return{id:al(),user:r,reportId:e,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:a}}function Es(e,r){const n=[r,...e];return n.length>Ei?n.slice(0,Ei):n}function ll(e){return{filter_added:"Filter Added",filter_removed:"Filter Removed",filter_updated:"Filter Updated",filter_cleared:"All Filters Cleared",sort_level_added:"Sort Level Added",sort_level_removed:"Sort Level Removed",sort_reordered:"Sort Reordered",sort_cleared:"All Sorting Cleared",group_level_added:"Group Level Added",group_level_removed:"Group Level Removed",group_reordered:"Group Reordered",group_cleared:"All Grouping Cleared",column_hidden:"Column Hidden",column_shown:"Column Shown",column_reordered:"Columns Reordered",column_resized:"Column Resized",view_created:"View Created",view_updated:"View Updated",view_deleted:"View Deleted",view_set_default:"View Set as Default",view_switched:"View Switched",theme_changed:"Theme Changed",export_triggered:"Export Triggered",export_csv:"Exported as CSV",export_excel:"Exported as Excel",export_json:"Exported as JSON",export_pdf:"Exported as PDF",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[e]||e}function cl(e){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[e]||e}function dl(e){const r=new Date(e),i=new Date().getTime()-r.getTime(),s=Math.floor(i/6e4),a=Math.floor(i/36e5),c=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:a<24?`${a} hour${a>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const $i=100;function ul(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function pl(e){var a;const r=(a=e.views)==null?void 0:a.find(c=>c.id===e.activeViewId),n=r==null?void 0:r.snapshot.columnOrder,i=e.columnOrder||[],s=ci(i,e.grouping||null,n);return{filters:Le(e.filters),sortStack:e.sortStack?[...e.sortStack]:[],columnVisibility:e.columnVisibility?{...e.columnVisibility}:{},columnOrder:s,columnWidths:e.columnWidths?{...e.columnWidths}:{},grouping:e.grouping?{...e.grouping}:null,activeViewId:e.activeViewId}}function hl(e,r,n,i){return{id:ul(),name:e,description:r,createdBy:n,createdAt:Date.now(),config:i}}function fl(e,r){const n=e||[];if(n.length>=$i)throw new Error(`Maximum of ${$i} presets reached. Please delete old presets first.`);return[...n,r]}function ml(e,r){return(e||[]).filter(i=>i.id!==r)}function _i(e,r){if(e)return e.find(n=>n.id===r)}function xl(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function gl(e){const r=e.columnOrder,n=Co(r,e.grouping);return{filters:Le(e.filters),sortStack:e.sortStack.length>0?[...e.sortStack]:void 0,columnVisibility:{...e.columnVisibility},columnOrder:n,columnWidths:{...e.columnWidths},grouping:e.grouping?{...e.grouping}:null,activeViewId:e.activeViewId}}async function yl(e){try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(e),!0}catch(r){Lt.warn("urm:presets","Clipboard API blocked, using fallback method",r)}try{const r=document.createElement("textarea");r.value=e,r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="2em",r.style.height="2em",r.style.padding="0",r.style.border="none",r.style.outline="none",r.style.boxShadow="none",r.style.background="transparent",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();let n=!1;try{n=document.execCommand("copy")}catch(i){Lt.error("urm:presets","execCommand copy failed",i)}return document.body.removeChild(r),n}catch(r){return Lt.error("urm:presets","Fallback copy method failed",r),!1}}function bl(e,r){return{totalRows:e.length,totalColumns:r.length}}function ur(e,r,n,i){const s=n instanceof Error?n.message:n,a={type:e,context:r,message:s,details:i,timestamp:Date.now(),recoverable:vl(e,r)};return process.env.NODE_ENV==="development"&&Lt.error("urm:error-handling","[Report Error]",{type:e,context:r,message:s,details:i}),a}function vl(e,r){return e==="ui"?!0:r==="export"?!1:e==="processing"&&["filters","sorting","grouping","columns"].includes(r)?!0:e!=="system"}function Sl(e){const n={filters:"There was an issue applying filters",sorting:"Sorting could not be applied",grouping:"Grouping configuration failed",columns:"Column configuration could not be updated",views:"View operation failed",presets:"Preset could not be applied",export:"Export failed",upload:"File upload failed",search:"Search operation failed"}[e.context]||"An error occurred";return e.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function Cl(e){return{filters:e.filters,sortStack:e.sortStack?[...e.sortStack]:void 0,grouping:e.grouping?{...e.grouping}:void 0,columnVisibility:e.columnVisibility?{...e.columnVisibility}:void 0,columnOrder:e.columnOrder?[...e.columnOrder]:void 0,columnWidths:e.columnWidths?{...e.columnWidths}:void 0,activeViewId:e.activeViewId}}function jl(e,r,n){n(e.id,{filters:Le(r.filters),sortStack:r.sortStack,grouping:r.grouping,columnVisibility:r.columnVisibility,columnOrder:r.columnOrder,columnWidths:r.columnWidths,activeViewId:r.activeViewId})}function wl(e,r,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(r)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:e==="number"&&["gt","gte","lt","lte","equals"].includes(r)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:e==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function Ds(e,r){const n=[],i=[],s=new Set(r.map(a=>a.name));return e.forEach(a=>{s.has(a.column)?n.push(a):i.push(a.column)}),{validRules:n,invalidColumns:i}}function $s(e,r){if(!e||!e.levels||e.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(r.map(a=>a.name)),i=[],s=[];return e.levels.forEach(a=>{n.has(a.column)?i.push(a):s.push(a.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...e,levels:i},invalidColumns:s}}function kl(e,r){const n=[],i=new Set(r.map(a=>a.name)),s={...e};if(s.filters){const a=c=>{const l=c.children.filter(p=>{if(Ye(p))return!0;const x=i.has(p.column);return x||n.push(`Filter for column "${p.column}" ignored (column not found)`),x}).map(p=>Ye(p)?a(p):p).filter(p=>!Ye(p)||p.children.length>0);return{...c,children:l}};s.filters=a(Le(s.filters))}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:a,invalidColumns:c}=Ds(s.sortStack,r);c.length>0&&n.push(`Sort rules for columns ignored: ${c.join(", ")}`),s.sortStack=a.length>0?a:void 0}if(s.grouping){const{validGrouping:a,invalidColumns:c}=$s(s.grouping,r);c.length>0&&n.push(`Grouping for columns ignored: ${c.join(", ")}`),s.grouping=a}if(s.columnVisibility){const a={};Object.entries(s.columnVisibility).forEach(([c,l])=>{i.has(c)?a[c]=l:n.push(`Column visibility for "${c}" ignored (column not found)`)}),s.columnVisibility=Object.keys(a).length>0?a:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const a=s.columnOrder.filter(c=>{const l=i.has(c);return l||n.push(`Column "${c}" in order ignored (column not found)`),l});s.columnOrder=a.length>0?a:void 0}if(s.columnWidths){const a={};Object.entries(s.columnWidths).forEach(([c,l])=>{i.has(c)?a[c]=l:n.push(`Column width for "${c}" ignored (column not found)`)}),s.columnWidths=Object.keys(a).length>0?a:void 0}return{sanitizedConfig:s,warnings:n}}function zl(e,r){return ur("processing","export",e,{retryAvailable:!!(r!=null&&r.onRetry)})}function Oi(e,r,n,i){const s=Is(e,r,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Es(i||[],s)}function Tl(e){return e==null}function Bl(e,r,n){const{operator:i,value:s}=r;if(i==="NULL")return e==null;if(i==="NOT_NULL")return e!=null;if(Tl(e))return!1;if(n==="date"){const a=new Date(e).getTime(),c=new Date(s).getTime();switch(i){case"equals":return a===c;case"gt":return a>c;case"lt":return a<c;case"gte":return a>=c;case"lte":return a<=c;default:return!0}}switch(i){case"equals":return String(e).toLowerCase()===String(s).toLowerCase();case"contains":return String(e).toLowerCase().includes(String(s).toLowerCase());case"startsWith":return String(e).toLowerCase().startsWith(String(s).toLowerCase());case"endsWith":return String(e).toLowerCase().endsWith(String(s).toLowerCase());case"gt":return Number(e)>Number(s);case"lt":return Number(e)<Number(s);case"gte":return Number(e)>=Number(s);case"lte":return Number(e)<=Number(s);case"isTrue":return e===!0;case"isFalse":return e===!1;default:return!0}}function Zn(e,r,n){var s;if(Ye(r))return r.children.length===0?!0:r.operator==="and"?r.children.every(a=>Zn(e,a,n)):r.children.some(a=>Zn(e,a,n));const i=((s=n.find(a=>a.name===r.column))==null?void 0:s.type)??"string";return Bl(e[r.column],r,i)}function Il(e,r,n){return!r||r.children.length===0?e:e.filter(i=>Zn(i,r,n))}function rn(e){switch(e){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"date":return[{value:"equals",label:"Is"},{value:"gt",label:"After"},{value:"lt",label:"Before"},{value:"gte",label:"On or after"},{value:"lte",label:"On or before"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function El(e){return e!=="isTrue"&&e!=="isFalse"&&e!=="NULL"&&e!=="NOT_NULL"}function Dl({data:e,filters:r,schema:n}){return{filteredData:f.useMemo(()=>!r||r.children.length===0?e:Il(e,r,n),[e,r,n])}}function $l(e,r,n,i){if(!n||n.trim()==="")return e;const s=n.toLowerCase().trim(),a=r.filter(c=>i.includes(c.name));return e.filter(c=>a.some(l=>{const p=c[l.name];return p==null?!1:String(p).toLowerCase().includes(s)}))}function _l({data:e,searchQuery:r,schema:n,visibleColumns:i,mode:s="client"}){return{searchedData:f.useMemo(()=>s==="server"||!r||r.trim()===""?e:$l(e,n,r,i),[e,r,n,i,s])}}function Ol({data:e,sortStack:r,schema:n}){return{sortedData:f.useMemo(()=>!r||r.length===0?e:Wa(e,n,r),[e,r,n])}}function Ml({data:e,grouping:r,schema:n}){const i=f.useMemo(()=>!r||!r.enabled||r.levels.length===0?e:La(e,n,r),[e,r,n]),s=(r==null?void 0:r.enabled)&&((r==null?void 0:r.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function Wl({schema:e,columnVisibility:r,columnOrder:n}){const i=f.useMemo(()=>n.filter(l=>r[l]!==!1),[n,r]),s=f.useMemo(()=>Object.entries(r).filter(([l,p])=>!p).map(([l,p])=>l),[r]),a=f.useMemo(()=>n.map(l=>e.find(x=>x.name===l)||{name:l,type:"string"}),[n,e]),c=f.useMemo(()=>i.map(l=>e.find(x=>x.name===l)||{name:l,type:"string"}),[i,e]);return{visibleColumns:i,hiddenColumns:s,allColumns:a,visibleColumnSchemas:c,hiddenCount:s.length}}function Al({views:e,activeViewId:r,currentState:n}){const i=f.useMemo(()=>e.find(x=>x.id===r),[e,r]),s=f.useMemo(()=>i?Ua(n,i.snapshot):!1,[i,n]),a=f.useMemo(()=>e.find(x=>x.isDefault),[e]),c=f.useMemo(()=>e.filter(x=>!x.isDefault&&!x.isDeleted),[e]),l=f.useMemo(()=>e.filter(x=>x.isFavorite&&!x.isDeleted),[e]),p=f.useMemo(()=>e.filter(x=>x.isDeleted),[e]);return{activeView:i,isDirty:s,defaultView:a,customViews:c,favoriteViews:l,deletedViews:p,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function Rl(e,r,n){if(!e||e.length===0)return[];if(r<=0)return e.slice(0,n);const i=e.slice(r,n);if(i.length===0)return[];const s=i[0],a=!!(s.__isGroupHeader||s.isGroupHeader),c=a?s.groupLevel??0:s.__urm_group_level__??0;if(c===0&&a)return i;const l=c-1;if(l<0)return i;const p={};let x=l+1;for(let g=r-1;g>=0;g--){const v=e[g];if(v.__isGroupHeader||v.isGroupHeader){const S=v.groupLevel??0;if(S<=l&&p[S]===void 0&&(p[S]=v,x--,x<=0))break}}const y=[];for(let g=0;g<=l;g++)p[g]&&y.push({...p[g],__urm_is_continuation_header__:!0});return[...y,...i]}function Pl({data:e,enabled:r=!1,pageSize:n=100,initialPage:i=1}){const[s,a]=f.useState(i),c=e.length,l=Math.max(1,Math.ceil(c/n));f.useEffect(()=>{s>l&&a(l)},[s,l]);const p=f.useMemo(()=>{if(!r)return e;const S=(s-1)*n,k=S+n;return Rl(e,S,k)},[e,r,s,n]),x=f.useCallback(S=>{const k=Math.max(1,Math.min(S,l));a(k)},[l]),y=f.useCallback(()=>{s<l&&a(S=>Math.min(S+1,l))},[l]),g=f.useCallback(()=>{s>1&&a(S=>Math.max(S-1,1))},[]),v=f.useCallback(()=>{a(1)},[]);return{paginatedData:p,currentPage:s,totalPages:l,pageSize:n,totalRows:c,goToPage:x,nextPage:y,prevPage:g,resetPage:v,hasNextPage:s<l,hasPrevPage:s>1}}function Nl(e){const{rawData:r,schema:n,filters:i,sortStack:s,grouping:a,searchQuery:c,searchMode:l,columnVisibility:p,columnOrder:x,columnWidths:y,views:g,activeViewId:v,pagination:S}=e,k=f.useMemo(()=>({filters:i,sortStack:s,grouping:a,columnVisibility:p,columnOrder:x,columnWidths:y}),[i,s,a,p,x,y]),b=Al({views:g,activeViewId:v,currentState:k}),m=Wl({schema:n,columnVisibility:p,columnOrder:x}),{filteredData:z}=Dl({data:r,filters:i,schema:n}),{sortedData:h}=Ol({data:z,sortStack:s,schema:n}),{groupedData:B,isGrouped:T}=Ml({data:h,grouping:a,schema:n}),{searchedData:w}=_l({data:B,searchQuery:c,schema:n,visibleColumns:m.visibleColumns,mode:l}),P=Pl({data:w,enabled:(S==null?void 0:S.enabled)||!1,pageSize:(S==null?void 0:S.pageSize)||100,initialPage:(S==null?void 0:S.currentPage)||1}),O=S!=null&&S.enabled?P.paginatedData:w,M=f.useMemo(()=>({totalRows:r.length,filteredRows:z.length,sortedRows:h.length,groupedRows:T?B.length:h.length,searchedRows:w.length,visibleRows:O.length,hiddenColumns:m.hiddenCount,activeFilters:Ct(i),activeSorts:s.length,isGrouped:T}),[r.length,z.length,h.length,B.length,w.length,O.length,m.hiddenCount,i,s.length,T]);return{data:O,filteredData:z,sortedData:h,groupedData:B,searchedData:w,viewEngine:b,columnEngine:m,paginationEngine:P,metrics:M,isGrouped:T,isPaginated:(S==null?void 0:S.enabled)||!1}}let Ll=0;function Fl(e,r){e!==null&&e.__urm_row_id__===void 0&&Object.defineProperty(e,"__urm_row_id__",{value:r?r(e):Ll++,writable:!1,enumerable:!1,configurable:!1})}const $t="user-demo-001";function Vl(e={}){var Po,yi,bi,vi,Si;const{mode:r="builder",autoLoad:n=!0,initialData:i,dataSource:s,pagination:a,search:c,scheduler:l,reportName:p,reportId:x,sharedReportId:y,sharedViewId:g,viewPersistence:v,config:S={}}=e,k=(v==null?void 0:v.mode)??"local",b=(a==null?void 0:a.mode)??"client",m=(c==null?void 0:c.mode)??"client",[z,h]=f.useState([]),B=Dr(),[T,w]=f.useState(""),[P,O]=f.useState(!1),[M,Y]=f.useState(!1),[J,R]=f.useState({message:"",severity:"info",open:!1}),u=(j,E="info")=>{R({message:j,severity:E,open:!0})},A=()=>R(j=>({...j,open:!1})),F=S.notifDurationMs??2e3,d=z.find(j=>j.id===T),[ne,U]=f.useState("idle"),[re,ge]=f.useState(!1),[V,X]=f.useState(!1),[ce,de]=f.useState(!1),[ie,Q]=f.useState(!1),[pe,I]=f.useState(!1),[te,fe]=f.useState(void 0),[ae,ze]=f.useState(null),[q,We]=f.useState(null),[kt,dt]=f.useState(!1),[Or,Ot]=f.useState(!1),[ot,Ft]=f.useState(null),[qe,zt]=f.useState(!1),[fr,xt]=f.useState(!1),[tr,ao]=f.useState({enabled:!1,levels:[],collapsedGroups:[]}),[rr,lo]=f.useState(""),[Tt,mr]=f.useState(""),[Je,Mt]=f.useState(new Set),[Vt,Qe]=f.useState(1),[Ze,Wt]=f.useState(15),[co,Mr]=f.useState(!1),[xr,Ve]=f.useState(!1),[ke,or]=f.useState(!1),[At,gr]=f.useState(null),[yr,Ht]=f.useState(!1),[nr,et]=f.useState(null),[ir,gt]=f.useState(null),Wr=f.useRef(null),ee=f.useMemo(()=>d?rl(d.permissions,$t):"owner",[d]),br=ol(ee),Ar=f.useMemo(()=>!(d!=null&&d.uploadedData)||!(d!=null&&d.schema)?{totalRows:0,totalColumns:0}:bl(d.uploadedData,d.schema),[d==null?void 0:d.uploadedData,d==null?void 0:d.schema]),Bt=f.useCallback(()=>{d&&(Wr.current=Cl(d))},[d]),H=f.useCallback((j,E)=>{h(W=>W.map(_=>_.id===j?{..._,...E}:_))},[]),ut=f.useCallback(j=>{if(!d)return;gt(j);const E=Oi(d.id,$t,j,d.auditHistory||[]);H(d.id,{auditHistory:E}),u(j.message,"error"),j.recoverable&&Wr.current&&setTimeout(()=>{jl(d,Wr.current,H),u("Previous state restored","success")},100)},[d,H]),se=f.useCallback((j,E,W,_)=>{if(!d)return;const G=Is(d.id,$t,j,E,W,_),K=d.auditHistory||[],le=Es(K,G);setTimeout(()=>{H(d.id,{auditHistory:le})},0)},[d,H]);f.useEffect(()=>{if(d!=null&&d.schemaLocked&&d.schema&&(!d.views||d.views.length===0)){const j=Nn(d.schema);(()=>{try{const E=localStorage.getItem("urm_dev_config");return E?JSON.parse(E):null}catch{return null}})(),H(d.id,{views:[j],activeViewId:j.id,filters:j.snapshot.filters,sortStack:j.snapshot.sortStack,columnVisibility:j.snapshot.columnVisibility,columnOrder:j.snapshot.columnOrder,columnWidths:j.snapshot.columnWidths,grouping:j.snapshot.grouping})}},[d==null?void 0:d.schemaLocked,d==null?void 0:d.schema,d==null?void 0:d.id,H]),f.useEffect(()=>{if(i&&n&&!M&&z.length===0){const j=oo(i),E={id:x||`auto-report-${Date.now()}`,name:p||(r==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:j,schema:wi(yo(j),S.hiddenColumns),permissions:{owner:$t,editors:[],viewers:[]}};h([E]),w(E.id),Y(!0),U("confirmed")}},[i,n,M,z.length,r,p,x]),f.useEffect(()=>{b!=="server"||!M||!T||H(T,{uploadedData:oo(i||[])})},[i,b,M,T]),f.useEffect(()=>{b==="server"&&((a==null?void 0:a.page)!==void 0&&Qe(a.page),(a==null?void 0:a.pageSize)!==void 0&&Wt(a.pageSize))},[a==null?void 0:a.page,a==null?void 0:a.pageSize,b]),f.useEffect(()=>{if(!s||M)return;let j=!1,E=null;const W=async()=>{try{U("uploading");let _;if(s.type==="api"){const K=await fetch(s.url,{headers:s.headers||{}});if(!K.ok)throw new Error(`HTTP ${K.status}: ${K.statusText}`);_=await K.json()}else _=await s.fetch();if(j)return;if(!Array.isArray(_))throw new Error("Data source must return an array of objects");const G=yo(_);if(M)h(K=>K.map(le=>le.id===T?{...le,uploadedData:oo(_)}:le)),U("confirmed");else{const K={id:x||`auto-report-${Date.now()}`,name:p||(r==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:oo(_),schema:wi(yo(oo(_)),S.hiddenColumns),permissions:{owner:$t,editors:[],viewers:[]}};h([K]),w(K.id),Y(!0),U("confirmed")}}catch(_){j||(U("error"),d&&H(d.id,{uploadError:(_==null?void 0:_.message)||"Failed to load data from source"}))}};return W(),s.refreshInterval&&s.refreshInterval>0&&(E=setInterval(W,s.refreshInterval)),()=>{j=!0,E&&clearInterval(E)}},[s,p,r,x]);const Ke=(Po=d==null?void 0:d.views)==null?void 0:Po.find(j=>j.id===d.activeViewId),sr=f.useMemo(()=>d!=null&&d.uploadedData?(d.uploadedData.forEach(j=>Fl(j,S.getRowId)),d.uploadedData):[],[d==null?void 0:d.uploadedData]);f.useEffect(()=>{Mt(j=>{if(j.size===0)return j;const E=new Set(sr.map(_=>_==null?void 0:_.__urm_row_id__)),W=new Set(Array.from(j).filter(_=>E.has(_==null?void 0:_.__urm_row_id__)));return W.size===j.size?j:W})},[sr]);const vr=Nl({rawData:sr,schema:(d==null?void 0:d.schema)||[],filters:Le(d==null?void 0:d.filters),sortStack:(d==null?void 0:d.sortStack)||[],grouping:(d==null?void 0:d.grouping)||null,searchQuery:Tt||"",searchMode:m,columnVisibility:(d==null?void 0:d.columnVisibility)||(Ke==null?void 0:Ke.snapshot.columnVisibility)||{},columnOrder:(d==null?void 0:d.columnOrder)||(Ke==null?void 0:Ke.snapshot.columnOrder)||[],columnWidths:(d==null?void 0:d.columnWidths)||(Ke==null?void 0:Ke.snapshot.columnWidths)||{},views:(d==null?void 0:d.views)||[],activeViewId:(d==null?void 0:d.activeViewId)||"",pagination:{enabled:b==="client",pageSize:Ze,currentPage:Vt}}),{data:uo=[],searchedData:Ut=[],groupedData:Sr=[],sortedData:Gt=[],metrics:ar={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Yt=!1,paginationEngine:ve}=vr||{},yt=b==="server"?(a==null?void 0:a.totalRows)??0:ar.searchedRows,Z=((yi=vr.viewEngine)==null?void 0:yi.activeView)||Ke,he=((bi=vr.viewEngine)==null?void 0:bi.isDirty)||!1;f.useEffect(()=>{if(!(!Z||!d)&&!d.columnOrder){const j=Z.snapshot.columnOrder,E=Co(j,Z.snapshot.grouping);H(d.id,{columnOrder:E})}},[d==null?void 0:d.activeViewId]);const be=f.useMemo(()=>!(d!=null&&d.schema)||!Z?null:Ha(d.filters,d.sortStack||[],d.schema,d.columnVisibility,d.columnOrder,d.columnWidths,d.grouping,Z.snapshot.columnOrder),[d==null?void 0:d.filters,d==null?void 0:d.sortStack,d==null?void 0:d.schema,d==null?void 0:d.columnVisibility,d==null?void 0:d.columnOrder,d==null?void 0:d.columnWidths,d==null?void 0:d.grouping,Z]),Cr=f.useMemo(()=>!Z||!be||!he?[]:Ya(be,Z.snapshot),[Z,be,he]),jr=f.useCallback((j,E,W)=>{const _={id:`report-${Date.now()}`,name:j,description:E,schemaLocked:!1,permissions:{owner:$t,editors:[],viewers:[]}};if(W&&Array.isArray(W)&&W.length>0){const G=yo(W),K=Nn(G);_.uploadedData=W,_.schema=G,_.schemaLocked=!0,_.views=[K],_.activeViewId=K.id,_.sortStack=K.snapshot.sortStack,_.filters=K.snapshot.filters,_.columnVisibility=K.snapshot.columnVisibility,_.columnOrder=K.snapshot.columnOrder,_.columnWidths=K.snapshot.columnWidths,_.grouping=K.snapshot.grouping}h(G=>[...G,_]),w(_.id),O(!1),U("confirmed")},[]),po=f.useCallback(j=>{d&&(U("uploading"),setTimeout(()=>{const E=yo(j);H(d.id,{uploadedData:j,schema:E,uploadError:void 0}),U("preview")},500))},[d,H]),Rr=f.useCallback(j=>{d&&(H(d.id,{uploadError:j}),U("idle"))},[d,H]),ho=f.useCallback(()=>{d&&(H(d.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),U("idle"))},[d,H]),qt=f.useCallback(()=>{d&&(H(d.id,{schemaLocked:!0}),U("confirmed"))},[d,H]),Pr=f.useCallback(j=>{if(!d)return;if(!bt("edit_sorting",ee)){u(vt("edit_sorting"),"error");return}const E=d.sortStack??[],W=E.find(_=>_.column===j);if(W){const _=Aa(W.direction);if(_===null){const G=E.filter(K=>K.column!==j).map((K,le)=>({...K,priority:le+1}));se("sorting","sort_level_removed",W,null),H(d.id,{sortStack:G.length>0?G:void 0})}else{const G=_,K=E.map(le=>le.column===j?{...le,direction:G}:le);se("sorting","sort_reordered",{column:j,direction:W.direction},{column:j,direction:G}),H(d.id,{sortStack:K})}}else{if(E.length>=B.sort.maxLevels){u(`Sort limit reached — maximum ${B.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const _={column:j,direction:"asc",priority:E.length+1};se("sorting","sort_level_added",null,_),H(d.id,{sortStack:[...E,_]})}},[d,ee,H,se]),Nr=f.useCallback(j=>{if(!d)return;const E=d.sortStack??[],W=j.length===0?"sort_cleared":"sort_reordered";if(d.schema){const{validRules:_,invalidColumns:G}=Ds(j,d.schema);G.length>0&&u(`Removed invalid sort columns: ${G.join(", ")}`),Bt();try{se("sorting",W,E,_.length>0?_:null),H(d.id,{sortStack:_.length>0?_:void 0})}catch(K){const le=ur("processing","sorting",K);ut(le)}}else se("sorting",W,E,j.length>0?j:null),H(d.id,{sortStack:j.length>0?j:void 0})},[d,H,Bt,ut,se]),Se=f.useCallback(j=>{if(!d)return;const E=d.sortStack??[],W=E.find(_=>_.column===j);if(!(W&&W.direction==="asc"))if(W){const _=E.map(G=>G.column===j?{...G,direction:"asc"}:G);se("sorting","sort_reordered",{column:j,direction:W.direction},{column:j,direction:"asc"}),H(d.id,{sortStack:_})}else{if(E.length>=B.sort.maxLevels){u(`Sort limit reached — maximum ${B.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const _={column:j,direction:"asc",priority:E.length+1};se("sorting","sort_level_added",null,_),H(d.id,{sortStack:[...E,_]})}},[d,H,se]),Ge=f.useCallback(j=>{if(!d)return;const E=d.sortStack??[],W=E.find(_=>_.column===j);if(!(W&&W.direction==="desc"))if(W){const _=E.map(G=>G.column===j?{...G,direction:"desc"}:G);se("sorting","sort_reordered",{column:j,direction:W.direction},{column:j,direction:"desc"}),H(d.id,{sortStack:_})}else{if(E.length>=B.sort.maxLevels){u(`Sort limit reached — maximum ${B.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const _={column:j,direction:"desc",priority:E.length+1};se("sorting","sort_level_added",null,_),H(d.id,{sortStack:[...E,_]})}},[d,H,se]),wr=f.useCallback((j,E)=>{var _;if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const W=(_=d.schema)==null?void 0:_.find(G=>G.name===E.column);if(W&&E.value!==void 0){const G=wl(W.type,E.operator,E.value);if(!G.isValid){u(G.errorMessage||"Invalid filter value","error");return}}Bt();try{const G=Le(d.filters),K={...E,id:io()},le=so(G,j,K);se("filters","filter_added",null,K),H(d.id,{filters:le})}catch(G){const K=ur("processing","filters",G);ut(K)}},[d,ee,H,Bt,ut,se]),st=f.useCallback(j=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const E=Le(d.filters),W=so(E,j,_t());se("filters","filter_added",null,"a condition group"),H(d.id,{filters:W})},[d,ee,H,se]),Jt=f.useCallback((j,E)=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const W=Le(d.filters),_=qo(W,j),G=si(W,j,E),K=qo(G,j);se("filters","filter_updated",_,K),H(d.id,{filters:G})},[d,ee,H,se]),It=f.useCallback((j,E)=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const W=Le(d.filters),_=ai(W,j,E);se("filters","filter_updated",null,`group operator changed to ${E.toUpperCase()}`),H(d.id,{filters:_})},[d,ee,H,se]),kr=f.useCallback(j=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const E=Le(d.filters),W=qo(E,j),_=li(E,j);se("filters","filter_removed",W,null),H(d.id,{filters:_})},[d,ee,H,se]),xe=f.useCallback(()=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const j=Le(d.filters);se("filters","filter_cleared",{count:Ct(j)},null),H(d.id,{filters:_t()})},[d,ee,H,se]),Ce=f.useCallback(j=>{if(!d)return;if(!bt("edit_filters",ee)){u(vt("edit_filters"),"error");return}const E=Le(d.filters);se("filters","filter_cleared",{count:Ct(E)},{count:Ct(j)}),H(d.id,{filters:j})},[d,ee,H,se]),Ne=f.useCallback(j=>{var G;if(!d)return;const E=(G=d.views)==null?void 0:G.find(K=>K.id===j);if(!E)return;const W=E.snapshot.columnOrder,_=Co(W,E.snapshot.grouping);se("views","view_switched",{previousViewId:d.activeViewId},{viewId:j,name:E.name}),H(d.id,{filters:E.snapshot.filters,sortStack:E.snapshot.sortStack.length>0?[...E.snapshot.sortStack]:void 0,columnVisibility:{...E.snapshot.columnVisibility},columnOrder:_,columnWidths:{...E.snapshot.columnWidths},grouping:E.snapshot.grouping,activeViewId:j}),Mt(new Set)},[d,H,se]),nt=f.useCallback((j,E,W)=>{var He;if(!(d!=null&&d.schema)||!be)return;const _=d.views??[],G=_.filter(Pn=>!Pn.isDeleted).length,K=((He=B.views)==null?void 0:He.maxViews)??10;if(G>=K){u(`View limit reached — you can have at most ${K} saved views. Delete an existing view to create a new one.`,"error");return}const le={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:j,description:E||void 0,isDefault:W,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:$t,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...be}},we=W?_.map(Pn=>({...Pn,isDefault:!1})):_;se("views","view_created",null,{viewId:le.id,name:j,isDefault:W}),H(d.id,{views:[...we,le],activeViewId:le.id}),u(`"${j}" view created`,"success")},[d,be,H,se]),Et=f.useCallback(j=>{var le;if(!(d!=null&&d.views))return;const E=d.views.find(we=>we.id===j);if(!E)return;const W=d.views,_=W.filter(we=>!we.isDeleted).length,G=((le=B.views)==null?void 0:le.maxViews)??10;if(_>=G){u(`View limit reached — you can have at most ${G} saved views. Delete an existing view to create a new one.`,"error");return}const K={...E,id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:`${E.name} (copy)`,scope:"personal",isDefault:!1,isFavorite:!1,isDeleted:!1,createdBy:$t,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...E.snapshot}};H(d.id,{views:[...W,K]}),u(`"${K.name}" created`,"success")},[d,B,H]),zr=f.useCallback(()=>{var E;if(!Z||!be||!d)return;const j=(E=d.views)==null?void 0:E.map(W=>W.id===Z.id?{...W,snapshot:{...be}}:W);H(d.id,{views:j}),u(`"${Z.name}" view updated`,"success")},[Z,be,d,H]),Lr=f.useCallback(j=>{var _;if(!Z||!be||!d)return;const E=j??be.columnWidths,W=(_=d.views)==null?void 0:_.map(G=>G.id===Z.id?{...G,snapshot:{...G.snapshot,columnVisibility:be.columnVisibility,columnOrder:be.columnOrder,columnWidths:E},updatedAt:Date.now()}:G);H(d.id,{views:W,columnWidths:E}),u(`Column configuration saved to "${Z.name}"`,"success")},[Z,be,d,H]),Fr=f.useCallback(j=>{var K,le;if(!be||!d||!Z)return;const E=j??be.columnWidths,W={...Z,snapshot:{...Z.snapshot,columnVisibility:be.columnVisibility,columnOrder:be.columnOrder,columnWidths:E},updatedAt:Date.now()},_=(K=d.views)==null?void 0:K.map(we=>we.id===Z.id?W:{...we,snapshot:{...we.snapshot,columnVisibility:be.columnVisibility,columnOrder:be.columnOrder,columnWidths:E},updatedAt:Date.now()});H(d.id,{views:_,columnWidths:E});const G=(((le=d.views)==null?void 0:le.length)||0)-1;u(`Column configuration saved to current view and ${G} other view${G===1?"":"s"}`,"success")},[be,d,Z,H]),kn=f.useCallback(()=>{de(!0)},[]),Vr=f.useCallback(()=>{if(!Z||!d)return;const j=Z.snapshot.columnOrder,E=Co(j,Z.snapshot.grouping);H(d.id,{filters:Z.snapshot.filters,sortStack:Z.snapshot.sortStack.length>0?[...Z.snapshot.sortStack]:void 0,columnVisibility:{...Z.snapshot.columnVisibility},columnOrder:E,columnWidths:{...Z.snapshot.columnWidths},grouping:Z.snapshot.grouping}),u("Changes reverted to last saved state","success")},[Z,d,H]),fo=f.useCallback(j=>{if(!(d!=null&&d.views))return;const E=d.views.map(_=>({..._,isDefault:_.id===j}));H(d.id,{views:E});const W=d.views.find(_=>_.id===j);W&&u(`"${W.name}" set as default view`,"success")},[d,H]),zn=f.useCallback(j=>{if(!(d!=null&&d.views))return;const E=d.views.map(_=>_.id===j?{..._,isFavorite:!_.isFavorite,updatedAt:Date.now()}:_);H(d.id,{views:E});const W=d.views.find(_=>_.id===j);W&&!W.isFavorite?u(`"${W.name}" added to favorites`,"success"):W&&u(`"${W.name}" removed from favorites`,"info")},[d,H]),_o=f.useCallback(j=>{if(!(d!=null&&d.views))return;const E=d.views.find(He=>He.id===j),W=d.views.filter(He=>!He.isDeleted||He.id===j);if((E==null?void 0:E.isDefault)&&W.filter(He=>He.isDefault).length===1){u("Cannot delete the last default view","error");return}const G=d.views.map(He=>He.id===j?{...He,isDeleted:!0,updatedAt:Date.now()}:He),K=d.activeViewId===j,le=G.find(He=>He.isDefault&&!He.isDeleted);H(d.id,{views:G,activeViewId:K&&le?le.id:d.activeViewId,filters:K&&le?le.snapshot.filters:d.filters,sortStack:K&&le?le.snapshot.sortStack.length>0?le.snapshot.sortStack:void 0:d.sortStack});const we=d.views.find(He=>He.id===j);we&&u(`"${we.name}" moved to Recently Deleted`,"info")},[d,H]),Hr=f.useCallback(j=>{if(!(d!=null&&d.views))return;const E=d.views.map(_=>_.id===j?{..._,isDeleted:!1,updatedAt:Date.now()}:_);H(d.id,{views:E});const W=d.views.find(_=>_.id===j);W&&u(`"${W.name}" restored`,"success")},[d,H]),Oo=f.useCallback(j=>{if(!(d!=null&&d.views))return;const E=d.views.find(we=>we.id===j),W=d.views.filter(we=>!we.isDeleted||we.id===j);if((E==null?void 0:E.isDefault)&&W.filter(we=>we.isDefault).length===1){u("Cannot delete the last default view","error");return}const G=d.views.filter(we=>we.id!==j),K=d.activeViewId===j,le=G.find(we=>we.isDefault&&!we.isDeleted);H(d.id,{views:G,activeViewId:K&&le?le.id:d.activeViewId,filters:K&&le?le.snapshot.filters:d.filters,sortStack:K&&le?le.snapshot.sortStack.length>0?le.snapshot.sortStack:void 0:d.sortStack}),E&&u(`"${E.name}" permanently deleted`,"success")},[d,H]),Ur=f.useCallback(j=>{ze(j),Q(!0)},[]),Gr=f.useCallback(async j=>{if(!d)return;const E=new URLSearchParams(window.location.search);E.set("reportId",d.id),E.set("view",j);const W=`${window.location.origin}${window.location.pathname}?${E.toString()}`,_=await yl(W);u(_?"Link copied to clipboard":"Failed to copy link",_?"success":"error")},[d]),mo=f.useCallback((j,E)=>{if(!ae||!(d!=null&&d.views))return;const W=d.views.map(_=>_.id===ae?{..._,name:j,description:E||void 0}:_);H(d.id,{views:W}),ze(null)},[ae,d,H]),Yr=f.useCallback(j=>{We(j),I(!0)},[]),qr=f.useCallback(()=>{if(!q||!(d!=null&&d.views))return;const j=d.views.find(G=>G.id===q),E=d.views.filter(G=>G.id!==q),W=d.activeViewId===q,_=E.find(G=>G.isDefault);se("views","view_deleted",{viewId:q,name:j==null?void 0:j.name},null),H(d.id,{views:E,activeViewId:W&&_?_.id:d.activeViewId,filters:W&&_?_.snapshot.filters:d.filters,sortStack:W&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:d.sortStack}),We(null),I(!1)},[q,d,H,se]),lr=f.useCallback(j=>{var G;if(!(d!=null&&d.views))return;if(!(((G=B.views)==null?void 0:G.isAdmin)??!1)){u("Only administrators can promote views to Global.","error");return}const W=d.views.find(K=>K.id===j);if(!W)return;if(W.scope==="global"){u(`"${W.name}" is already a Global View.`,"info");return}const _=d.views.map(K=>K.id===j?{...K,scope:"global",isDefault:!0,updatedAt:Date.now()}:K.scope==="global"&&K.isDefault?{...K,isDefault:!1}:K);H(d.id,{views:_}),u(`"${W.name}" promoted to Global View and set as default.`,"success")},[d,B,H]),xo=f.useRef(!0);f.useEffect(()=>{var j;if(xo.current){xo.current=!1;return}if(b==="server"){Qe(1),(j=a==null?void 0:a.onPaginationChange)==null||j.call(a,1,Ze);return}ve!=null&&ve.resetPage?ve.resetPage():Qe(1)},[d==null?void 0:d.filters,Tt,d==null?void 0:d.activeViewId,d==null?void 0:d.grouping]);const Jr=f.useCallback(j=>{var E;if(b==="server"){Qe(j),(E=a==null?void 0:a.onPaginationChange)==null||E.call(a,j,Ze);return}ve!=null&&ve.goToPage&&ve.goToPage(j),Qe(j)},[b,a,Ze,ve]),Tn=f.useCallback(j=>{var _;const E=(Vt-1)*Ze,W=Math.floor(E/j)+1;if(b==="server"){Wt(j),Qe(W),(_=a==null?void 0:a.onPaginationChange)==null||_.call(a,W,j);return}Wt(j),Qe(W),ve==null||ve.goToPage(W)},[Vt,Ze,b,a,ve]),Bn=f.useCallback((j,E)=>{if(!d)return;if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}const _={...d.columnVisibility||(Z==null?void 0:Z.snapshot.columnVisibility)||{},[j]:E};se("columns",E?"column_shown":"column_hidden",{columnName:j,visible:!E},{columnName:j,visible:E}),H(d.id,{columnVisibility:_})},[d,Z,ee,H,se]),In=f.useCallback(j=>{if(d){if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}se("columns","column_reordered",d.columnOrder,j),H(d.id,{columnOrder:j})}},[d,ee,H,se]),En=f.useCallback((j,E)=>{if(!d)return;if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}const W=d.columnWidths||(Z==null?void 0:Z.snapshot.columnWidths)||{},_={...W,[j]:E};se("columns","column_resized",{columnName:j,width:W[j]},{columnName:j,width:E}),H(d.id,{columnWidths:_})},[d,Z,ee,H,se]),Dn=f.useCallback(j=>{if(!d)return;const E=Le(d.filters),W=zs(E,j);H(d.id,{filters:W})},[d,H]),$n=f.useCallback(()=>{if(!Z||!(d!=null&&d.schema))return;const j={},E=[],W={};d.schema.forEach(_=>{j[_.name]=!0,E.push(_.name),W[_.name]=170}),H(d.id,{columnVisibility:j,columnOrder:E,columnWidths:W,filters:void 0,sortStack:void 0}),u("Reset to default layout - all filters and sorts cleared","success")},[Z,d,H]);f.useEffect(()=>{const j=setTimeout(()=>mr(rr),300);return()=>clearTimeout(j)},[rr]),f.useEffect(()=>{var j;m==="server"&&((j=c==null?void 0:c.onSearchChange)==null||j.call(c,Tt))},[Tt,m,c]);const _n=f.useCallback(j=>{lo(j),Qe(1)},[]),On=f.useCallback(j=>{if(!j.trim()||!d)return;const E=d.searchHistory||[],W=Xa(E,j);H(d.id,{searchHistory:W})},[d,H]),Mn=f.useCallback(j=>{if(!d)return;const E=d.searchHistory||[],W=Qa(E,j);H(d.id,{searchHistory:W})},[d,H]),Kr=f.useCallback(j=>{if(!d)return;const E=d.searchHistory||[],W=Za(E,j);H(d.id,{searchHistory:W})},[d,H]);f.useEffect(()=>{if(!S.onSelectionChange)return;const j=Array.from(Je);S.onSelectionChange(j,j.map(E=>E==null?void 0:E.__urm_row_id__))},[Je,S.onSelectionChange]);const Kt=f.useCallback(j=>{const E=j==null?void 0:j.__urm_row_id__;Mt(W=>{const _=new Set(W);if(E!==void 0){const G=Array.from(_).find(K=>(K==null?void 0:K.__urm_row_id__)===E);G!==void 0?_.delete(G):_.add(j)}else{const G=JSON.stringify(j),K=Array.from(_).find(le=>JSON.stringify(le)===G);K!==void 0?_.delete(K):_.add(j)}return _})},[]),Wn=f.useCallback((j,E)=>{Mt(W=>{const _=new Set(W);for(const G of E)j?_.add(G):_.delete(G);return _})},[]),An=f.useCallback((j,E,W)=>{Mt(_=>{const G=new Set(_),K=Math.min(j,E),le=Math.max(j,E);for(let we=K;we<=le;we++)W[we]!==void 0&&G.add(W[we]);return G})},[]),Me=f.useCallback(()=>{Mt(new Set)},[]),at=f.useCallback(j=>{const E=j==null?void 0:j.__urm_row_id__;Mt(W=>{const _=new Set(W);if(E!==void 0){const G=Array.from(_).find(K=>(K==null?void 0:K.__urm_row_id__)===E);G!==void 0&&_.delete(G)}else _.delete(j);return _})},[]),go=f.useCallback(j=>{var E,W;if(d){if(!bt("edit_columns",ee)){u(vt("edit_columns"),"error");return}if(j&&d.schema){const{validGrouping:_,invalidColumns:G}=$s(j,d.schema);G.length>0&&u(`Removed invalid grouping columns: ${G.join(", ")}`,"warning"),Bt();try{const K=d.grouping;_===null?se("grouping","group_cleared",K,null):K?se("grouping","group_reordered",K,_):se("grouping","group_level_added",null,_);const le=(Z==null?void 0:Z.snapshot.columnOrder)||d.columnOrder||[],we=Co(le,_),He=_.levels.length>0?{..._,collapsedGroups:zi(Gt,d.schema,_)}:_;H(d.id,{grouping:He,columnOrder:we}),Qe(1),ve==null||ve.resetPage(),b==="server"&&((E=a==null?void 0:a.onPaginationChange)==null||E.call(a,1,Ze)),JSON.stringify(we)!==JSON.stringify(d.columnOrder)&&se("columns","column_reordered",d.columnOrder,we),xt(!1)}catch(K){const le=ur("processing","grouping",K);ut(le)}}else{const _=d.grouping;se("grouping","group_cleared",_,null);const G=(Z==null?void 0:Z.snapshot.columnOrder)||d.columnOrder||[];H(d.id,{grouping:j,columnOrder:G}),Qe(1),ve==null||ve.resetPage(),b==="server"&&((W=a==null?void 0:a.onPaginationChange)==null||W.call(a,1,Ze)),JSON.stringify(G)!==JSON.stringify(d.columnOrder)&&se("columns","column_reordered",d.columnOrder,G),xt(!1)}}},[d,Z,ee,H,Bt,ut,se,Gt]),Mo=f.useCallback(j=>{if(!d)return;const E=d.grouping;if(!E)return;const W=Fa(E,j);H(d.id,{grouping:W})},[d,H]),Rn=f.useCallback(()=>{d!=null&&d.grouping&&H(d.id,{grouping:{...d.grouping,collapsedGroups:[]}})},[d,H]),Dt=f.useCallback(()=>{if(!(d!=null&&d.grouping)||!d.schema)return;const j=zi(Gt,d.schema,d.grouping);H(d.id,{grouping:{...d.grouping,collapsedGroups:j}})},[d,Gt,H]),Tr=f.useCallback(()=>{Ht(!0)},[]),pt=f.useCallback(j=>{d!=null&&d.schema&&(dt(!0),setTimeout(()=>{try{let E;j.scope==="visible"?E=Ut:E=d.uploadedData||[];let W;j.columnScope==="all"?(W={},(d.schema??[]).forEach(we=>{W[we.name]=!0})):W=d.columnVisibility||(Z==null?void 0:Z.snapshot.columnVisibility)||{};const _=d.columnOrder||(Z==null?void 0:Z.snapshot.columnOrder),G=Qo(E,d.schema,Le(d.filters),d.sortStack??[],Z,W,_),K=d.name;let le;switch(j.format){case"csv":Zo(G,K,j),le="export_csv";break;case"excel":en(G,K,j),le="export_excel";break;case"json":tn(G,K,j),le="export_json";break;case"pdf":ui(G,K,j),le="export_pdf";break}se("export",le,null,{format:j.format,scope:j.scope,columnScope:j.columnScope,rowCount:E.length,viewName:(Z==null?void 0:Z.name)||"Default View"}),u(`Export completed successfully (${j.format.toUpperCase()})`,"success")}catch(E){const W=zl(E,{onRetry:()=>pt(j)});u(`Export failed: ${W.message}. Click Export to retry.`,"error");const _=Oi(d.id,$t,W,d.auditHistory||[]);H(d.id,{auditHistory:_}),Lt.error("urm:report-engine","Export failed",E)}finally{dt(!1)}},500))},[d,Z,Ut,H,se]),Wo=f.useCallback(j=>{if(d!=null&&d.schema){if(he&&Z&&!Z.isDefault){Ft(j.format),Ot(!0),Ht(!1);return}pt(j),Ht(!1)}},[d,Z,he,pt]),Xr=f.useCallback(j=>{pt({format:j,scope:"visible",columnScope:"visible"})},[pt]),Ao=f.useCallback(()=>{ot&&Xr(ot),Ot(!1),Ft(null)},[ot,Xr]),Ro=f.useCallback(()=>{zr(),ot&&Xr(ot),Ot(!1),Ft(null)},[zr,ot,Xr]),C=f.useCallback(()=>{Ot(!1),Ft(null)},[]),N=f.useCallback(j=>{!(d!=null&&d.schema)||Je.size===0||(dt(!0),setTimeout(()=>{try{const E=Array.from(Je),W=Qo(E,d.schema,Le(d.filters),d.sortStack??[],Z),_=`${d.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(j){case"csv":Zo(W,_);break;case"excel":en(W,_);break;case"json":tn(W,_);break}u(`Exported ${E.length} selected rows`,"info")}catch(E){u("Export failed. Please try again.","error"),Lt.error("urm:report-engine","Bulk export failed",E)}finally{dt(!1)}},500))},[d,Z,Je,Sr]),oe=f.useCallback((j,E)=>{if(d)try{const W=pl(d),_=hl(j,E,$t,W),G=fl(d.presets,_);H(d.id,{presets:G}),se("presets","preset_created",null,{presetId:_.id,name:_.name}),Ve(!1),u(`Preset "${j}" saved successfully`,"success")}catch(W){u(W instanceof Error?W.message:"Failed to create preset","error")}},[d,H,se]),je=f.useCallback(()=>{gr(null),u("Exited preset view","info")},[]),Ae=f.useCallback(()=>{or(!0)},[]),rt=f.useCallback((j,E)=>{if(!d)return;const W=ml(d.presets,j);H(d.id,{presets:W}),se("presets","preset_deleted",{presetId:j,name:E},null),At===j&&gr(null),u(`Preset "${E}" deleted`,"success")},[d,At,H,se]);f.useEffect(()=>{if(!y||z.length===0)return;const j=z.find(E=>E.id===y);j&&j.id!==T&&w(j.id)},[y,z,T]);const Xe=f.useRef(!1);f.useEffect(()=>{var E;if(!g||Xe.current||!d||d.id!==y)return;const j=(E=d.views)==null?void 0:E.find(W=>W.id===g&&!W.isDeleted);j&&Ne(j.id),Xe.current=!0},[g,y,d,Ne]),f.useEffect(()=>{if(!d)return;const j=xl();if(j&&d.presets&&d.schemaLocked&&d.schema){const E=_i(d.presets,j);if(E){const{sanitizedConfig:W,warnings:_}=kl(E.config,d.schema);_.length>0&&_.forEach(K=>u(K,"warning"));const G=gl(W);H(d.id,G),gr(j),se("presets","preset_applied",null,{presetId:E.id,name:E.name}),u(`Loaded preset: ${E.name}`,"info")}else u("Preset not found","info")}},[d==null?void 0:d.schemaLocked]);const me=At?_i(d==null?void 0:d.presets,At):void 0;f.useEffect(()=>{var j;d!=null&&d.views&&d.views.length>0&&d.activeViewId&&(k==="api"?(j=v==null?void 0:v.onViewsChange)==null||j.call(v,d.views,d.activeViewId):qa(d.id,{views:d.views,activeViewId:d.activeViewId}))},[d==null?void 0:d.views,d==null?void 0:d.activeViewId,d==null?void 0:d.id,k]),f.useEffect(()=>{if(d!=null&&d.schemaLocked&&d.schema&&(!d.views||d.views.length===0)){const j=k==="api"?v!=null&&v.views&&v.views.length>0?{views:v.views,activeViewId:v.activeViewId??v.views[0].id}:null:Ja(d.id);if(j&&j.views.length>0){const E=j.views.find(W=>W.id===j.activeViewId);if(E)H(d.id,{views:j.views,activeViewId:j.activeViewId,filters:Le(E.snapshot.filters),sortStack:E.snapshot.sortStack.length>0?E.snapshot.sortStack:void 0});else{const W=j.views.find(_=>_.isDefault)||Nn(d.schema);H(d.id,{views:j.views,activeViewId:W.id,filters:Le(W.snapshot.filters),sortStack:W.snapshot.sortStack.length>0?W.snapshot.sortStack:void 0})}}}},[d==null?void 0:d.schemaLocked,d==null?void 0:d.schema,d==null?void 0:d.id,k,v]);const Rt=f.useCallback(j=>{var _;const E=Le(d==null?void 0:d.filters),W=((_=B.filter)==null?void 0:_.maxConditions)??3;if(Ct(E)>=W){u(`Filter limit reached — maximum ${W} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}fe(j),ge(!0)},[d,B,u]),Xt=f.useCallback(()=>{ge(!1),fe(void 0)},[]),_e=(vi=d==null?void 0:d.views)==null?void 0:vi.find(j=>j.id===ae),cr=(Si=d==null?void 0:d.views)==null?void 0:Si.find(j=>j.id===q);return{reports:z,activeReport:d,activeReportId:T,setActiveReportId:w,isModalOpen:P,setIsModalOpen:O,createReport:jr,updateReport:H,uploadState:ne,handleFileUpload:po,handleUploadError:Rr,handleRetry:ho,handleConfirm:qt,paginatedData:uo,processedData:Ut,displayData:Sr,tableMetrics:ar,isGrouped:Yt,tableEngine:vr,activeView:Z,isDirty:he,currentTableState:be,viewChanges:Cr,filters:d==null?void 0:d.filters,showFilterPanel:re,setShowFilterPanel:ge,filterFocusColumn:te,handleAddCondition:wr,handleAddGroup:st,handleUpdateCondition:Jt,handleSetGroupOperator:It,handleRemoveFilterNode:kr,handleClearAllFilters:xe,handleReplaceFilters:Ce,handleOpenFilterForColumn:Rt,handleCloseFilterPanel:Xt,handleClearFiltersForColumn:Dn,sortStack:d==null?void 0:d.sortStack,showSortPanel:V,setShowSortPanel:X,handleSort:Pr,handleUpdateSortStack:Nr,handleSortAscending:Se,handleSortDescending:Ge,views:d==null?void 0:d.views,showCreateViewModal:ce,setShowCreateViewModal:de,showEditViewModal:ie,setShowEditViewModal:Q,showDeleteConfirmation:pe,setShowDeleteConfirmation:I,editingView:_e,deletingView:cr,editingViewId:ae,deletingViewId:q,handleSelectView:Ne,handleCreateView:nt,handleCloneView:Et,handleUpdateCurrentView:zr,handleSaveColumnConfigToCurrentView:Lr,handleSaveColumnConfigToAllViews:Fr,handleSaveAsNewView:kn,handleRevertChanges:Vr,handleToggleDefault:fo,handleToggleFavorite:zn,handleSoftDelete:_o,handleRestoreView:Hr,handlePermanentDelete:Oo,handleEditView:Ur,handleCopyViewLink:Gr,handleSaveEditView:mo,handleDeleteView:Yr,handleConfirmDelete:qr,handlePromoteToGlobal:lr,showManageColumns:qe,setShowManageColumns:zt,columnVisibility:d==null?void 0:d.columnVisibility,columnOrder:d==null?void 0:d.columnOrder,columnWidths:d==null?void 0:d.columnWidths,handleUpdateColumnVisibility:Bn,handleUpdateColumnOrder:In,handleUpdateColumnWidth:En,handleResetColumnLayout:$n,showGroupPanel:fr,setShowGroupPanel:xt,grouping:d==null?void 0:d.grouping,groupingState:tr,handleGroup:go,handleToggleGroupCollapse:Mo,handleExpandAllGroups:Rn,handleCollapseAllGroups:Dt,searchQuery:rr,debouncedSearchQuery:Tt,searchHistory:el((d==null?void 0:d.searchHistory)||[]),handleSearchChange:_n,handleAddToSearchHistory:On,handleToggleSearchFavourite:Mn,handleDeleteSearchHistory:Kr,selectedRowIds:Je,handleToggleRowSelection:Kt,handleToggleAllRows:Wn,handleRangeSelection:An,handleClearSelection:Me,handleUpdateSelectionAfterDelete:at,currentPage:Vt,pageSize:Ze,paginationEngine:ve,paginationMode:b,paginationTotalRows:yt,handlePageChange:Jr,handlePageSizeChange:Tn,isExporting:kt,showExportModal:yr,setShowExportModal:Ht,showDirtyExportWarning:Or,handleExport:Tr,handleExportWithConfig:Wo,handleExportSelected:N,handleExportAnyway:Ao,handleSaveAndExport:Ro,handleCancelExport:C,showAuditHistory:co,setShowAuditHistory:Mr,auditHistory:d==null?void 0:d.auditHistory,showCreatePreset:xr,setShowCreatePreset:Ve,showManagePresets:ke,setShowManagePresets:or,activePreset:me,activePresetId:At,handleOpenManagePresets:Ae,handleCreatePreset:oe,handleClearActivePreset:je,handleDeletePresetById:rt,userRole:ee,isViewerRole:br,currentUserId:$t,featureLimitWarning:nr,setFeatureLimitWarning:et,datasetMeta:Ar,reportError:ir,setReportError:gt,handleError:ut,schema:d==null?void 0:d.schema,hasSchemaConflicts:d!=null&&d.schema?Oa(d.schema):!1,snack:J,handleSnackClose:A,showSnack:u,snackDurationMs:F,config:S,scheduler:l}}const _s=f.createContext(void 0);function pi(e){const{children:r,initialData:n,data:i,reportName:s,reportId:a,dataSource:c,pagination:l,search:p,scheduler:x,mode:y="builder",autoLoad:g=!0,config:v,devConfig:S,showDevPanel:k=!1,sharedReportId:b,sharedViewId:m,viewPersistence:z}=e,B=Vl({mode:y,autoLoad:g,initialData:i||n,dataSource:c,pagination:l,search:p,scheduler:x,reportName:s,reportId:a,sharedReportId:b,sharedViewId:m,viewPersistence:z,config:v}),[T,w]=f.useState(()=>xa()),P=(()=>{const J=ya(T,S,!!S);return{...J,display:{...J.display,showDevPanel:k||J.display.showDevPanel}}})(),O=f.useCallback(Y=>{w(Y),ga(Y)},[]),M={...B,activeDevConfig:P,handleDevConfigChange:O};return t.jsx(Cs.Provider,{value:P,children:t.jsx(_s.Provider,{value:M,children:r})})}function cn(){const e=f.useContext(_s);if(e===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return e}function Hl({onCreateReport:e,reports:r=[],activeReportId:n,onReportClick:i}){const s=r.find(a=>a.id===n);return t.jsx(o.Box,{component:"header",sx:a=>{var y,g,v;const c=((v=(g=(y=a.components)==null?void 0:y.MuiCardHeader)==null?void 0:g.styleOverrides)==null?void 0:v.root)||{},l=c.backgroundColor&&c.backgroundColor!=="transparent"?c.backgroundColor:a.palette.background.paper,p=c.borderBottom&&c.borderBottom!=="none"?c.borderBottom:"1px solid",x=c.boxShadow&&c.boxShadow!=="none"?c.boxShadow:void 0;return{position:"sticky",top:0,zIndex:50,borderBottom:p,borderColor:p!=="none"?"divider":void 0,boxShadow:x,bgcolor:l}},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[t.jsxs(o.Breadcrumbs,{separator:t.jsx($.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[t.jsx(o.Typography,{variant:"h6",component:"h1",sx:{fontWeight:a=>a.typography.h6.fontWeight||500,fontSize:a=>a.typography.h6.fontSize||"1.375rem",color:a=>a.typography.h6.color||"text.primary",letterSpacing:"-0.01em",cursor:r.length>0&&s?"pointer":"default","&:hover":r.length>0&&s?{color:"primary.main"}:{}},onClick:()=>{r.length>0},children:"Reports"}),s&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.Typography,{sx:{fontWeight:a=>a.typography.h6.fontWeight||500,fontSize:a=>a.typography.h6.fontSize||"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(s.id),children:s.name}),t.jsx(o.Tooltip,{title:s.description||"No description",arrow:!0,placement:"bottom",children:t.jsx($.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:t.jsx(o.Button,{variant:"contained",startIcon:t.jsx($.Add,{sx:{fontSize:18}}),onClick:e,sx:{borderRadius:"20px",px:3,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Er(e,...r){const n=new URL(`https://mui.com/production-error/?code=${e}`);return r.forEach(i=>n.searchParams.append("args[]",i)),`Minified MUI error #${e}; visit ${n} for the full message.`}const Ul="$$material";function Gl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Fo={exports:{}},Vo={exports:{}},Te={};/** @license React v16.13.1
|
|
106
106
|
* react-is.production.min.js
|
|
107
107
|
*
|
|
108
108
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
109
109
|
*
|
|
110
110
|
* This source code is licensed under the MIT license found in the
|
|
111
111
|
* LICENSE file in the root directory of this source tree.
|
|
112
|
-
*/var Mi;function Yl(){if(Mi)return Te;Mi=1;var e=typeof Symbol=="function"&&Symbol.for,r=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,i=e?Symbol.for("react.fragment"):60107,s=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,c=e?Symbol.for("react.provider"):60109,l=e?Symbol.for("react.context"):60110,p=e?Symbol.for("react.async_mode"):60111,x=e?Symbol.for("react.concurrent_mode"):60111,y=e?Symbol.for("react.forward_ref"):60112,g=e?Symbol.for("react.suspense"):60113,v=e?Symbol.for("react.suspense_list"):60120,S=e?Symbol.for("react.memo"):60115,k=e?Symbol.for("react.lazy"):60116,b=e?Symbol.for("react.block"):60121,m=e?Symbol.for("react.fundamental"):60117,z=e?Symbol.for("react.responder"):60118,h=e?Symbol.for("react.scope"):60119;function B(
|
|
112
|
+
*/var Mi;function Yl(){if(Mi)return Te;Mi=1;var e=typeof Symbol=="function"&&Symbol.for,r=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,i=e?Symbol.for("react.fragment"):60107,s=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,c=e?Symbol.for("react.provider"):60109,l=e?Symbol.for("react.context"):60110,p=e?Symbol.for("react.async_mode"):60111,x=e?Symbol.for("react.concurrent_mode"):60111,y=e?Symbol.for("react.forward_ref"):60112,g=e?Symbol.for("react.suspense"):60113,v=e?Symbol.for("react.suspense_list"):60120,S=e?Symbol.for("react.memo"):60115,k=e?Symbol.for("react.lazy"):60116,b=e?Symbol.for("react.block"):60121,m=e?Symbol.for("react.fundamental"):60117,z=e?Symbol.for("react.responder"):60118,h=e?Symbol.for("react.scope"):60119;function B(w){if(typeof w=="object"&&w!==null){var P=w.$$typeof;switch(P){case r:switch(w=w.type,w){case p:case x:case i:case a:case s:case g:return w;default:switch(w=w&&w.$$typeof,w){case l:case y:case k:case S:case c:return w;default:return P}}case n:return P}}}function T(w){return B(w)===x}return Te.AsyncMode=p,Te.ConcurrentMode=x,Te.ContextConsumer=l,Te.ContextProvider=c,Te.Element=r,Te.ForwardRef=y,Te.Fragment=i,Te.Lazy=k,Te.Memo=S,Te.Portal=n,Te.Profiler=a,Te.StrictMode=s,Te.Suspense=g,Te.isAsyncMode=function(w){return T(w)||B(w)===p},Te.isConcurrentMode=T,Te.isContextConsumer=function(w){return B(w)===l},Te.isContextProvider=function(w){return B(w)===c},Te.isElement=function(w){return typeof w=="object"&&w!==null&&w.$$typeof===r},Te.isForwardRef=function(w){return B(w)===y},Te.isFragment=function(w){return B(w)===i},Te.isLazy=function(w){return B(w)===k},Te.isMemo=function(w){return B(w)===S},Te.isPortal=function(w){return B(w)===n},Te.isProfiler=function(w){return B(w)===a},Te.isStrictMode=function(w){return B(w)===s},Te.isSuspense=function(w){return B(w)===g},Te.isValidElementType=function(w){return typeof w=="string"||typeof w=="function"||w===i||w===x||w===a||w===s||w===g||w===v||typeof w=="object"&&w!==null&&(w.$$typeof===k||w.$$typeof===S||w.$$typeof===c||w.$$typeof===l||w.$$typeof===y||w.$$typeof===m||w.$$typeof===z||w.$$typeof===h||w.$$typeof===b)},Te.typeOf=B,Te}var Be={};/** @license React v16.13.1
|
|
113
113
|
* react-is.development.js
|
|
114
114
|
*
|
|
115
115
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
116
116
|
*
|
|
117
117
|
* This source code is licensed under the MIT license found in the
|
|
118
118
|
* LICENSE file in the root directory of this source tree.
|
|
119
|
-
*/var Wi;function ql(){return Wi||(Wi=1,process.env.NODE_ENV!=="production"&&(function(){var e=typeof Symbol=="function"&&Symbol.for,r=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,i=e?Symbol.for("react.fragment"):60107,s=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,c=e?Symbol.for("react.provider"):60109,l=e?Symbol.for("react.context"):60110,p=e?Symbol.for("react.async_mode"):60111,x=e?Symbol.for("react.concurrent_mode"):60111,y=e?Symbol.for("react.forward_ref"):60112,g=e?Symbol.for("react.suspense"):60113,v=e?Symbol.for("react.suspense_list"):60120,S=e?Symbol.for("react.memo"):60115,k=e?Symbol.for("react.lazy"):60116,b=e?Symbol.for("react.block"):60121,m=e?Symbol.for("react.fundamental"):60117,z=e?Symbol.for("react.responder"):60118,h=e?Symbol.for("react.scope"):60119;function B(
|
|
119
|
+
*/var Wi;function ql(){return Wi||(Wi=1,process.env.NODE_ENV!=="production"&&(function(){var e=typeof Symbol=="function"&&Symbol.for,r=e?Symbol.for("react.element"):60103,n=e?Symbol.for("react.portal"):60106,i=e?Symbol.for("react.fragment"):60107,s=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,c=e?Symbol.for("react.provider"):60109,l=e?Symbol.for("react.context"):60110,p=e?Symbol.for("react.async_mode"):60111,x=e?Symbol.for("react.concurrent_mode"):60111,y=e?Symbol.for("react.forward_ref"):60112,g=e?Symbol.for("react.suspense"):60113,v=e?Symbol.for("react.suspense_list"):60120,S=e?Symbol.for("react.memo"):60115,k=e?Symbol.for("react.lazy"):60116,b=e?Symbol.for("react.block"):60121,m=e?Symbol.for("react.fundamental"):60117,z=e?Symbol.for("react.responder"):60118,h=e?Symbol.for("react.scope"):60119;function B(q){return typeof q=="string"||typeof q=="function"||q===i||q===x||q===a||q===s||q===g||q===v||typeof q=="object"&&q!==null&&(q.$$typeof===k||q.$$typeof===S||q.$$typeof===c||q.$$typeof===l||q.$$typeof===y||q.$$typeof===m||q.$$typeof===z||q.$$typeof===h||q.$$typeof===b)}function T(q){if(typeof q=="object"&&q!==null){var We=q.$$typeof;switch(We){case r:var kt=q.type;switch(kt){case p:case x:case i:case a:case s:case g:return kt;default:var dt=kt&&kt.$$typeof;switch(dt){case l:case y:case k:case S:case c:return dt;default:return We}}case n:return We}}}var w=p,P=x,O=l,M=c,Y=r,J=y,R=i,u=k,A=S,F=n,d=a,ne=s,U=g,re=!1;function ge(q){return re||(re=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),V(q)||T(q)===p}function V(q){return T(q)===x}function X(q){return T(q)===l}function ce(q){return T(q)===c}function de(q){return typeof q=="object"&&q!==null&&q.$$typeof===r}function ie(q){return T(q)===y}function Q(q){return T(q)===i}function pe(q){return T(q)===k}function I(q){return T(q)===S}function te(q){return T(q)===n}function fe(q){return T(q)===a}function ae(q){return T(q)===s}function ze(q){return T(q)===g}Be.AsyncMode=w,Be.ConcurrentMode=P,Be.ContextConsumer=O,Be.ContextProvider=M,Be.Element=Y,Be.ForwardRef=J,Be.Fragment=R,Be.Lazy=u,Be.Memo=A,Be.Portal=F,Be.Profiler=d,Be.StrictMode=ne,Be.Suspense=U,Be.isAsyncMode=ge,Be.isConcurrentMode=V,Be.isContextConsumer=X,Be.isContextProvider=ce,Be.isElement=de,Be.isForwardRef=ie,Be.isFragment=Q,Be.isLazy=pe,Be.isMemo=I,Be.isPortal=te,Be.isProfiler=fe,Be.isStrictMode=ae,Be.isSuspense=ze,Be.isValidElementType=B,Be.typeOf=T})()),Be}var Ai;function Os(){return Ai||(Ai=1,process.env.NODE_ENV==="production"?Vo.exports=Yl():Vo.exports=ql()),Vo.exports}/*
|
|
120
120
|
object-assign
|
|
121
121
|
(c) Sindre Sorhus
|
|
122
122
|
@license MIT
|
|
123
|
-
*/var Fn,Ri;function Jl(){if(Ri)return Fn;Ri=1;var e=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(a){if(a==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(a)}function s(){try{if(!Object.assign)return!1;var a=new String("abc");if(a[5]="de",Object.getOwnPropertyNames(a)[0]==="5")return!1;for(var c={},l=0;l<10;l++)c["_"+String.fromCharCode(l)]=l;var p=Object.getOwnPropertyNames(c).map(function(y){return c[y]});if(p.join("")!=="0123456789")return!1;var x={};return"abcdefghijklmnopqrst".split("").forEach(function(y){x[y]=y}),Object.keys(Object.assign({},x)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return Fn=s()?Object.assign:function(a,c){for(var l,p=i(a),x,y=1;y<arguments.length;y++){l=Object(arguments[y]);for(var g in l)r.call(l,g)&&(p[g]=l[g]);if(e){x=e(l);for(var v=0;v<x.length;v++)n.call(l,x[v])&&(p[x[v]]=l[x[v]])}}return p},Fn}var Vn,Pi;function hi(){if(Pi)return Vn;Pi=1;var e="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Vn=e,Vn}var Hn,Ni;function Ms(){return Ni||(Ni=1,Hn=Function.call.bind(Object.prototype.hasOwnProperty)),Hn}var Un,Li;function Kl(){if(Li)return Un;Li=1;var e=function(){};if(process.env.NODE_ENV!=="production"){var r=hi(),n={},i=Ms();e=function(a){var c="Warning: "+a;typeof console<"u"&&console.error(c);try{throw new Error(c)}catch{}}}function s(a,c,l,p,x){if(process.env.NODE_ENV!=="production"){for(var y in a)if(i(a,y)){var g;try{if(typeof a[y]!="function"){var v=Error((p||"React class")+": "+l+" type `"+y+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof a[y]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw v.name="Invariant Violation",v}g=a[y](c,y,p,l,null,r)}catch(k){g=k}if(g&&!(g instanceof Error)&&e((p||"React class")+": type specification of "+l+" `"+y+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof g+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),g instanceof Error&&!(g.message in n)){n[g.message]=!0;var S=x?x():"";e("Failed "+l+" type: "+g.message+(S??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Un=s,Un}var Gn,Fi;function Xl(){if(Fi)return Gn;Fi=1;var e=Os(),r=Jl(),n=hi(),i=Ms(),s=Kl(),a=function(){};process.env.NODE_ENV!=="production"&&(a=function(l){var p="Warning: "+l;typeof console<"u"&&console.error(p);try{throw new Error(p)}catch{}});function c(){return null}return Gn=function(l,p){var x=typeof Symbol=="function"&&Symbol.iterator,y="@@iterator";function g(V){var X=V&&(x&&V[x]||V[y]);if(typeof X=="function")return X}var v="<<anonymous>>",S={array:z("array"),bigint:z("bigint"),bool:z("boolean"),func:z("function"),number:z("number"),object:z("object"),string:z("string"),symbol:z("symbol"),any:h(),arrayOf:B,element:T(),elementType:
|
|
124
|
-
Valid keys: `+JSON.stringify(Object.keys(V),null," "));var
|
|
123
|
+
*/var Fn,Ri;function Jl(){if(Ri)return Fn;Ri=1;var e=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(a){if(a==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(a)}function s(){try{if(!Object.assign)return!1;var a=new String("abc");if(a[5]="de",Object.getOwnPropertyNames(a)[0]==="5")return!1;for(var c={},l=0;l<10;l++)c["_"+String.fromCharCode(l)]=l;var p=Object.getOwnPropertyNames(c).map(function(y){return c[y]});if(p.join("")!=="0123456789")return!1;var x={};return"abcdefghijklmnopqrst".split("").forEach(function(y){x[y]=y}),Object.keys(Object.assign({},x)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return Fn=s()?Object.assign:function(a,c){for(var l,p=i(a),x,y=1;y<arguments.length;y++){l=Object(arguments[y]);for(var g in l)r.call(l,g)&&(p[g]=l[g]);if(e){x=e(l);for(var v=0;v<x.length;v++)n.call(l,x[v])&&(p[x[v]]=l[x[v]])}}return p},Fn}var Vn,Pi;function hi(){if(Pi)return Vn;Pi=1;var e="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Vn=e,Vn}var Hn,Ni;function Ms(){return Ni||(Ni=1,Hn=Function.call.bind(Object.prototype.hasOwnProperty)),Hn}var Un,Li;function Kl(){if(Li)return Un;Li=1;var e=function(){};if(process.env.NODE_ENV!=="production"){var r=hi(),n={},i=Ms();e=function(a){var c="Warning: "+a;typeof console<"u"&&console.error(c);try{throw new Error(c)}catch{}}}function s(a,c,l,p,x){if(process.env.NODE_ENV!=="production"){for(var y in a)if(i(a,y)){var g;try{if(typeof a[y]!="function"){var v=Error((p||"React class")+": "+l+" type `"+y+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof a[y]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw v.name="Invariant Violation",v}g=a[y](c,y,p,l,null,r)}catch(k){g=k}if(g&&!(g instanceof Error)&&e((p||"React class")+": type specification of "+l+" `"+y+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof g+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),g instanceof Error&&!(g.message in n)){n[g.message]=!0;var S=x?x():"";e("Failed "+l+" type: "+g.message+(S??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Un=s,Un}var Gn,Fi;function Xl(){if(Fi)return Gn;Fi=1;var e=Os(),r=Jl(),n=hi(),i=Ms(),s=Kl(),a=function(){};process.env.NODE_ENV!=="production"&&(a=function(l){var p="Warning: "+l;typeof console<"u"&&console.error(p);try{throw new Error(p)}catch{}});function c(){return null}return Gn=function(l,p){var x=typeof Symbol=="function"&&Symbol.iterator,y="@@iterator";function g(V){var X=V&&(x&&V[x]||V[y]);if(typeof X=="function")return X}var v="<<anonymous>>",S={array:z("array"),bigint:z("bigint"),bool:z("boolean"),func:z("function"),number:z("number"),object:z("object"),string:z("string"),symbol:z("symbol"),any:h(),arrayOf:B,element:T(),elementType:w(),instanceOf:P,node:J(),objectOf:M,oneOf:O,oneOfType:Y,shape:u,exact:A};function k(V,X){return V===X?V!==0||1/V===1/X:V!==V&&X!==X}function b(V,X){this.message=V,this.data=X&&typeof X=="object"?X:{},this.stack=""}b.prototype=Error.prototype;function m(V){if(process.env.NODE_ENV!=="production")var X={},ce=0;function de(Q,pe,I,te,fe,ae,ze){if(te=te||v,ae=ae||I,ze!==n){if(p){var q=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw q.name="Invariant Violation",q}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var We=te+":"+I;!X[We]&&ce<3&&(a("You are manually calling a React.PropTypes validation function for the `"+ae+"` prop on `"+te+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),X[We]=!0,ce++)}}return pe[I]==null?Q?pe[I]===null?new b("The "+fe+" `"+ae+"` is marked as required "+("in `"+te+"`, but its value is `null`.")):new b("The "+fe+" `"+ae+"` is marked as required in "+("`"+te+"`, but its value is `undefined`.")):null:V(pe,I,te,fe,ae)}var ie=de.bind(null,!1);return ie.isRequired=de.bind(null,!0),ie}function z(V){function X(ce,de,ie,Q,pe,I){var te=ce[de],fe=ne(te);if(fe!==V){var ae=U(te);return new b("Invalid "+Q+" `"+pe+"` of type "+("`"+ae+"` supplied to `"+ie+"`, expected ")+("`"+V+"`."),{expectedType:V})}return null}return m(X)}function h(){return m(c)}function B(V){function X(ce,de,ie,Q,pe){if(typeof V!="function")return new b("Property `"+pe+"` of component `"+ie+"` has invalid PropType notation inside arrayOf.");var I=ce[de];if(!Array.isArray(I)){var te=ne(I);return new b("Invalid "+Q+" `"+pe+"` of type "+("`"+te+"` supplied to `"+ie+"`, expected an array."))}for(var fe=0;fe<I.length;fe++){var ae=V(I,fe,ie,Q,pe+"["+fe+"]",n);if(ae instanceof Error)return ae}return null}return m(X)}function T(){function V(X,ce,de,ie,Q){var pe=X[ce];if(!l(pe)){var I=ne(pe);return new b("Invalid "+ie+" `"+Q+"` of type "+("`"+I+"` supplied to `"+de+"`, expected a single ReactElement."))}return null}return m(V)}function w(){function V(X,ce,de,ie,Q){var pe=X[ce];if(!e.isValidElementType(pe)){var I=ne(pe);return new b("Invalid "+ie+" `"+Q+"` of type "+("`"+I+"` supplied to `"+de+"`, expected a single ReactElement type."))}return null}return m(V)}function P(V){function X(ce,de,ie,Q,pe){if(!(ce[de]instanceof V)){var I=V.name||v,te=ge(ce[de]);return new b("Invalid "+Q+" `"+pe+"` of type "+("`"+te+"` supplied to `"+ie+"`, expected ")+("instance of `"+I+"`."))}return null}return m(X)}function O(V){if(!Array.isArray(V))return process.env.NODE_ENV!=="production"&&(arguments.length>1?a("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):a("Invalid argument supplied to oneOf, expected an array.")),c;function X(ce,de,ie,Q,pe){for(var I=ce[de],te=0;te<V.length;te++)if(k(I,V[te]))return null;var fe=JSON.stringify(V,function(ze,q){var We=U(q);return We==="symbol"?String(q):q});return new b("Invalid "+Q+" `"+pe+"` of value `"+String(I)+"` "+("supplied to `"+ie+"`, expected one of "+fe+"."))}return m(X)}function M(V){function X(ce,de,ie,Q,pe){if(typeof V!="function")return new b("Property `"+pe+"` of component `"+ie+"` has invalid PropType notation inside objectOf.");var I=ce[de],te=ne(I);if(te!=="object")return new b("Invalid "+Q+" `"+pe+"` of type "+("`"+te+"` supplied to `"+ie+"`, expected an object."));for(var fe in I)if(i(I,fe)){var ae=V(I,fe,ie,Q,pe+"."+fe,n);if(ae instanceof Error)return ae}return null}return m(X)}function Y(V){if(!Array.isArray(V))return process.env.NODE_ENV!=="production"&&a("Invalid argument supplied to oneOfType, expected an instance of array."),c;for(var X=0;X<V.length;X++){var ce=V[X];if(typeof ce!="function")return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+re(ce)+" at index "+X+"."),c}function de(ie,Q,pe,I,te){for(var fe=[],ae=0;ae<V.length;ae++){var ze=V[ae],q=ze(ie,Q,pe,I,te,n);if(q==null)return null;q.data&&i(q.data,"expectedType")&&fe.push(q.data.expectedType)}var We=fe.length>0?", expected one of type ["+fe.join(", ")+"]":"";return new b("Invalid "+I+" `"+te+"` supplied to "+("`"+pe+"`"+We+"."))}return m(de)}function J(){function V(X,ce,de,ie,Q){return F(X[ce])?null:new b("Invalid "+ie+" `"+Q+"` supplied to "+("`"+de+"`, expected a ReactNode."))}return m(V)}function R(V,X,ce,de,ie){return new b((V||"React class")+": "+X+" type `"+ce+"."+de+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ie+"`.")}function u(V){function X(ce,de,ie,Q,pe){var I=ce[de],te=ne(I);if(te!=="object")return new b("Invalid "+Q+" `"+pe+"` of type `"+te+"` "+("supplied to `"+ie+"`, expected `object`."));for(var fe in V){var ae=V[fe];if(typeof ae!="function")return R(ie,Q,pe,fe,U(ae));var ze=ae(I,fe,ie,Q,pe+"."+fe,n);if(ze)return ze}return null}return m(X)}function A(V){function X(ce,de,ie,Q,pe){var I=ce[de],te=ne(I);if(te!=="object")return new b("Invalid "+Q+" `"+pe+"` of type `"+te+"` "+("supplied to `"+ie+"`, expected `object`."));var fe=r({},ce[de],V);for(var ae in fe){var ze=V[ae];if(i(V,ae)&&typeof ze!="function")return R(ie,Q,pe,ae,U(ze));if(!ze)return new b("Invalid "+Q+" `"+pe+"` key `"+ae+"` supplied to `"+ie+"`.\nBad object: "+JSON.stringify(ce[de],null," ")+`
|
|
124
|
+
Valid keys: `+JSON.stringify(Object.keys(V),null," "));var q=ze(I,ae,ie,Q,pe+"."+ae,n);if(q)return q}return null}return m(X)}function F(V){switch(typeof V){case"number":case"string":case"undefined":return!0;case"boolean":return!V;case"object":if(Array.isArray(V))return V.every(F);if(V===null||l(V))return!0;var X=g(V);if(X){var ce=X.call(V),de;if(X!==V.entries){for(;!(de=ce.next()).done;)if(!F(de.value))return!1}else for(;!(de=ce.next()).done;){var ie=de.value;if(ie&&!F(ie[1]))return!1}}else return!1;return!0;default:return!1}}function d(V,X){return V==="symbol"?!0:X?X["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&X instanceof Symbol:!1}function ne(V){var X=typeof V;return Array.isArray(V)?"array":V instanceof RegExp?"object":d(X,V)?"symbol":X}function U(V){if(typeof V>"u"||V===null)return""+V;var X=ne(V);if(X==="object"){if(V instanceof Date)return"date";if(V instanceof RegExp)return"regexp"}return X}function re(V){var X=U(V);switch(X){case"array":case"object":return"an "+X;case"boolean":case"date":case"regexp":return"a "+X;default:return X}}function ge(V){return!V.constructor||!V.constructor.name?v:V.constructor.name}return S.checkPropTypes=s,S.resetWarningCache=s.resetWarningCache,S.PropTypes=S,S},Gn}var Yn,Vi;function Ql(){if(Vi)return Yn;Vi=1;var e=hi();function r(){}function n(){}return n.resetWarningCache=r,Yn=function(){function i(c,l,p,x,y,g){if(g!==e){var v=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw v.name="Invariant Violation",v}}i.isRequired=i;function s(){return i}var a={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:s,element:i,elementType:i,instanceOf:s,node:i,objectOf:s,oneOf:s,oneOfType:s,shape:s,exact:s,checkPropTypes:n,resetWarningCache:r};return a.PropTypes=a,a},Yn}var Hi;function Zl(){if(Hi)return Fo.exports;if(Hi=1,process.env.NODE_ENV!=="production"){var e=Os(),r=!0;Fo.exports=Xl()(e.isElement,r)}else Fo.exports=Ql()();return Fo.exports}var ec=Zl();const bo=Gl(ec);var Ho={exports:{}},De={};/**
|
|
125
125
|
* @license React
|
|
126
126
|
* react-is.production.js
|
|
127
127
|
*
|
|
@@ -138,12 +138,12 @@ Valid keys: `+JSON.stringify(Object.keys(V),null," "));var Y=ze(I,se,ie,Q,de+".
|
|
|
138
138
|
* This source code is licensed under the MIT license found in the
|
|
139
139
|
* LICENSE file in the root directory of this source tree.
|
|
140
140
|
*/var Gi;function rc(){return Gi||(Gi=1,process.env.NODE_ENV!=="production"&&(function(){function e(b){if(typeof b=="object"&&b!==null){var m=b.$$typeof;switch(m){case r:switch(b=b.type,b){case i:case a:case s:case x:case y:case S:return b;default:switch(b=b&&b.$$typeof,b){case l:case p:case v:case g:return b;case c:return b;default:return m}}case n:return m}}}var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),l=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),y=Symbol.for("react.suspense_list"),g=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),S=Symbol.for("react.view_transition"),k=Symbol.for("react.client.reference");$e.ContextConsumer=c,$e.ContextProvider=l,$e.Element=r,$e.ForwardRef=p,$e.Fragment=i,$e.Lazy=v,$e.Memo=g,$e.Portal=n,$e.Profiler=a,$e.StrictMode=s,$e.Suspense=x,$e.SuspenseList=y,$e.isContextConsumer=function(b){return e(b)===c},$e.isContextProvider=function(b){return e(b)===l},$e.isElement=function(b){return typeof b=="object"&&b!==null&&b.$$typeof===r},$e.isForwardRef=function(b){return e(b)===p},$e.isFragment=function(b){return e(b)===i},$e.isLazy=function(b){return e(b)===v},$e.isMemo=function(b){return e(b)===g},$e.isPortal=function(b){return e(b)===n},$e.isProfiler=function(b){return e(b)===a},$e.isStrictMode=function(b){return e(b)===s},$e.isSuspense=function(b){return e(b)===x},$e.isSuspenseList=function(b){return e(b)===y},$e.isValidElementType=function(b){return typeof b=="string"||typeof b=="function"||b===i||b===a||b===s||b===x||b===y||typeof b=="object"&&b!==null&&(b.$$typeof===v||b.$$typeof===g||b.$$typeof===l||b.$$typeof===c||b.$$typeof===p||b.$$typeof===k||b.getModuleId!==void 0)},$e.typeOf=e})()),$e}var Yi;function oc(){return Yi||(Yi=1,process.env.NODE_ENV==="production"?Ho.exports=tc():Ho.exports=rc()),Ho.exports}var Ws=oc();function dr(e){if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return(r===null||r===Object.prototype||Object.getPrototypeOf(r)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function As(e){if(sn.isValidElement(e)||Ws.isValidElementType(e)||!dr(e))return e;const r={};return Object.keys(e).forEach(n=>{r[n]=As(e[n])}),r}function mt(e,r,n={clone:!0}){const i=n.clone?{...e}:e;return dr(e)&&dr(r)&&Object.keys(r).forEach(s=>{sn.isValidElement(r[s])||Ws.isValidElementType(r[s])?i[s]=r[s]:dr(r[s])&&Object.prototype.hasOwnProperty.call(e,s)&&dr(e[s])?i[s]=mt(e[s],r[s],n):n.clone?i[s]=dr(r[s])?As(r[s]):r[s]:i[s]=r[s]}),i}const nc=e=>{const r=Object.keys(e).map(n=>({key:n,val:e[n]}))||[];return r.sort((n,i)=>n.val-i.val),r.reduce((n,i)=>({...n,[i.key]:i.val}),{})};function ic(e){const{values:r={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=e,a=nc(r),c=Object.keys(a);function l(v){return`@media (min-width:${typeof r[v]=="number"?r[v]:v}${n})`}function p(v){return`@media (max-width:${(typeof r[v]=="number"?r[v]:v)-i/100}${n})`}function x(v,S){const k=c.indexOf(S);return`@media (min-width:${typeof r[v]=="number"?r[v]:v}${n}) and (max-width:${(k!==-1&&typeof r[c[k]]=="number"?r[c[k]]:S)-i/100}${n})`}function y(v){return c.indexOf(v)+1<c.length?x(v,c[c.indexOf(v)+1]):l(v)}function g(v){const S=c.indexOf(v);return S===0?l(c[1]):S===c.length-1?p(c[S]):x(v,c[c.indexOf(v)+1]).replace("@media","@media not all and")}return{keys:c,values:a,up:l,down:p,between:x,only:y,not:g,unit:n,...s}}function qi(e,r){if(!e.containerQueries)return r;const n=Object.keys(r).filter(i=>i.startsWith("@container")).sort((i,s)=>{var c,l;const a=/min-width:\s*([0-9.]+)/;return+(((c=i.match(a))==null?void 0:c[1])||0)-+(((l=s.match(a))==null?void 0:l[1])||0)});return n.length?n.reduce((i,s)=>{const a=r[s];return delete i[s],i[s]=a,i},{...r}):r}function sc(e,r){return r==="@"||r.startsWith("@")&&(e.some(n=>r.startsWith(`@${n}`))||!!r.match(/^@\d/))}function ac(e,r){const n=r.match(/^@([^/]+)?\/?(.+)?$/);if(!n){if(process.env.NODE_ENV!=="production")throw new Error(`MUI: The provided shorthand ${`(${r})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
|
|
141
|
-
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,s]=n,a=Number.isNaN(+i)?i||0:+i;return e.containerQueries(s).up(a)}function lc(e){const r=(a,c)=>a.replace("@media",c?`@container ${c}`:"@container");function n(a,c){a.up=(...l)=>r(e.breakpoints.up(...l),c),a.down=(...l)=>r(e.breakpoints.down(...l),c),a.between=(...l)=>r(e.breakpoints.between(...l),c),a.only=(...l)=>r(e.breakpoints.only(...l),c),a.not=(...l)=>{const p=r(e.breakpoints.not(...l),c);return p.includes("not all and")?p.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):p}}const i={},s=a=>(n(i,a),i);return n(s),{...e,containerQueries:s}}const cc={borderRadius:4},hr=process.env.NODE_ENV!=="production"?
|
|
141
|
+
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,s]=n,a=Number.isNaN(+i)?i||0:+i;return e.containerQueries(s).up(a)}function lc(e){const r=(a,c)=>a.replace("@media",c?`@container ${c}`:"@container");function n(a,c){a.up=(...l)=>r(e.breakpoints.up(...l),c),a.down=(...l)=>r(e.breakpoints.down(...l),c),a.between=(...l)=>r(e.breakpoints.between(...l),c),a.only=(...l)=>r(e.breakpoints.only(...l),c),a.not=(...l)=>{const p=r(e.breakpoints.not(...l),c);return p.includes("not all and")?p.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):p}}const i={},s=a=>(n(i,a),i);return n(s),{...e,containerQueries:s}}const cc={borderRadius:4},hr=process.env.NODE_ENV!=="production"?bo.oneOfType([bo.number,bo.string,bo.object,bo.array]):{};function zo(e,r){return r?mt(e,r,{clone:!1}):e}const dn={xs:0,sm:600,md:900,lg:1200,xl:1536},Ji={keys:["xs","sm","md","lg","xl"],up:e=>`@media (min-width:${dn[e]}px)`},dc={containerQueries:e=>({up:r=>{let n=typeof r=="number"?r:dn[r]||r;return typeof n=="number"&&(n=`${n}px`),e?`@container ${e} (min-width:${n})`:`@container (min-width:${n})`}})};function er(e,r,n){const i=e.theme||{};if(Array.isArray(r)){const a=i.breakpoints||Ji;return r.reduce((c,l,p)=>(c[a.up(a.keys[p])]=n(r[p]),c),{})}if(typeof r=="object"){const a=i.breakpoints||Ji;return Object.keys(r).reduce((c,l)=>{if(sc(a.keys,l)){const p=ac(i.containerQueries?i:dc,l);p&&(c[p]=n(r[l],l))}else if(Object.keys(a.values||dn).includes(l)){const p=a.up(l);c[p]=n(r[l],l)}else{const p=l;c[p]=r[p]}return c},{})}return n(r)}function uc(e={}){var n;return((n=e.keys)==null?void 0:n.reduce((i,s)=>{const a=e.up(s);return i[a]={},i},{}))||{}}function Ki(e,r){return e.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},r)}function Rs(e){if(typeof e!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":Er(7));return e.charAt(0).toUpperCase()+e.slice(1)}function un(e,r,n=!0){if(!r||typeof r!="string")return null;if(e&&e.vars&&n){const i=`vars.${r}`.split(".").reduce((s,a)=>s&&s[a]?s[a]:null,e);if(i!=null)return i}return r.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,e)}function on(e,r,n,i=n){let s;return typeof e=="function"?s=e(n):Array.isArray(e)?s=e[n]||i:s=un(e,n)||i,r&&(s=r(s,i,e)),s}function Fe(e){const{prop:r,cssProperty:n=e.prop,themeKey:i,transform:s}=e,a=c=>{if(c[r]==null)return null;const l=c[r],p=c.theme,x=un(p,i)||{};return er(c,l,g=>{let v=on(x,s,g);return g===v&&typeof g=="string"&&(v=on(x,s,`${r}${g==="default"?"":Rs(g)}`,g)),n===!1?v:{[n]:v}})};return a.propTypes=process.env.NODE_ENV!=="production"?{[r]:hr}:{},a.filterProps=[r],a}function pc(e){const r={};return n=>(r[n]===void 0&&(r[n]=e(n)),r[n])}const hc={m:"margin",p:"padding"},fc={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Xi={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},mc=pc(e=>{if(e.length>2)if(Xi[e])e=Xi[e];else return[e];const[r,n]=e.split(""),i=hc[r],s=fc[n]||"";return Array.isArray(s)?s.map(a=>i+a):[i+s]}),pn=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],hn=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],xc=[...pn,...hn];function Eo(e,r,n,i){const s=un(e,r,!0)??n;return typeof s=="number"||typeof s=="string"?a=>typeof a=="string"?a:(process.env.NODE_ENV!=="production"&&typeof a!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${a}.`),typeof s=="string"?s.startsWith("var(")&&a===0?0:s.startsWith("var(")&&a===1?s:`calc(${a} * ${s})`:s*a):Array.isArray(s)?a=>{if(typeof a=="string")return a;const c=Math.abs(a);process.env.NODE_ENV!=="production"&&(Number.isInteger(c)?c>s.length-1&&console.error([`MUI: The value provided (${c}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${c} > ${s.length-1}, you need to add the missing values.`].join(`
|
|
142
142
|
`)):console.error([`MUI: The \`theme.${r}\` array type cannot be combined with non integer values.You should either use an integer value that can be used as index, or define the \`theme.${r}\` as a number.`].join(`
|
|
143
143
|
`)));const l=s[c];return a>=0?l:typeof l=="number"?-l:typeof l=="string"&&l.startsWith("var(")?`calc(-1 * ${l})`:`-${l}`}:typeof s=="function"?s:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${r}\` value (${s}) is invalid.`,"It should be a number, an array or a function."].join(`
|
|
144
|
-
`)),()=>{})}function fi(e){return Eo(e,"spacing",8,"spacing")}function Do(e,r){return typeof r=="string"||r==null?r:e(r)}function gc(e,r){return n=>e.reduce((i,s)=>(i[s]=Do(r,n),i),{})}function yc(e,r,n,i){if(!r.includes(n))return null;const s=mc(n),a=gc(s,i),c=e[n];return er(e,c,a)}function Ps(e,r){const n=fi(e.theme);return Object.keys(e).map(i=>yc(e,r,i,n)).reduce(zo,{})}function Re(e){return Ps(e,pn)}Re.propTypes=process.env.NODE_ENV!=="production"?pn.reduce((e,r)=>(e[r]=hr,e),{}):{};Re.filterProps=pn;function Pe(e){return Ps(e,hn)}Pe.propTypes=process.env.NODE_ENV!=="production"?hn.reduce((e,r)=>(e[r]=hr,e),{}):{};Pe.filterProps=hn;process.env.NODE_ENV!=="production"&&xc.reduce((e,r)=>(e[r]=hr,e),{});function Ns(e=8,r=fi({spacing:e})){if(e.mui)return e;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(a=>{const c=r(a);return typeof c=="number"?`${c}px`:c}).join(" "));return n.mui=!0,n}function fn(...e){const r=e.reduce((i,s)=>(s.filterProps.forEach(a=>{i[a]=s}),i),{}),n=i=>Object.keys(i).reduce((s,a)=>r[a]?zo(s,r[a](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?e.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=e.reduce((i,s)=>i.concat(s.filterProps),[]),n}function St(e){return typeof e!="number"?e:`${e}px solid`}function wt(e,r){return Fe({prop:e,themeKey:"borders",transform:r})}const bc=wt("border",St),vc=wt("borderTop",St),Sc=wt("borderRight",St),Cc=wt("borderBottom",St),jc=wt("borderLeft",St),wc=wt("borderColor"),kc=wt("borderTopColor"),zc=wt("borderRightColor"),Tc=wt("borderBottomColor"),Bc=wt("borderLeftColor"),Ic=wt("outline",St),Ec=wt("outlineColor"),mn=e=>{if(e.borderRadius!==void 0&&e.borderRadius!==null){const r=Eo(e.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Do(r,i)});return er(e,e.borderRadius,n)}return null};mn.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:hr}:{};mn.filterProps=["borderRadius"];fn(bc,vc,Sc,Cc,jc,wc,kc,zc,Tc,Bc,mn,Ic,Ec);const xn=e=>{if(e.gap!==void 0&&e.gap!==null){const r=Eo(e.theme,"spacing",8,"gap"),n=i=>({gap:Do(r,i)});return er(e,e.gap,n)}return null};xn.propTypes=process.env.NODE_ENV!=="production"?{gap:hr}:{};xn.filterProps=["gap"];const gn=e=>{if(e.columnGap!==void 0&&e.columnGap!==null){const r=Eo(e.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Do(r,i)});return er(e,e.columnGap,n)}return null};gn.propTypes=process.env.NODE_ENV!=="production"?{columnGap:hr}:{};gn.filterProps=["columnGap"];const yn=e=>{if(e.rowGap!==void 0&&e.rowGap!==null){const r=Eo(e.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Do(r,i)});return er(e,e.rowGap,n)}return null};yn.propTypes=process.env.NODE_ENV!=="production"?{rowGap:hr}:{};yn.filterProps=["rowGap"];const Dc=Fe({prop:"gridColumn"}),$c=Fe({prop:"gridRow"}),_c=Fe({prop:"gridAutoFlow"}),Oc=Fe({prop:"gridAutoColumns"}),Mc=Fe({prop:"gridAutoRows"}),Wc=Fe({prop:"gridTemplateColumns"}),Ac=Fe({prop:"gridTemplateRows"}),Rc=Fe({prop:"gridTemplateAreas"}),Pc=Fe({prop:"gridArea"});fn(xn,gn,yn,Dc,$c,_c,Oc,Mc,Wc,Ac,Rc,Pc);function oo(e,r){return r==="grey"?r:e}const Nc=Fe({prop:"color",themeKey:"palette",transform:oo}),Lc=Fe({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:oo}),Fc=Fe({prop:"backgroundColor",themeKey:"palette",transform:oo});fn(Nc,Lc,Fc);function ft(e){return e<=1&&e!==0?`${e*100}%`:e}const Vc=Fe({prop:"width",transform:ft}),mi=e=>{if(e.maxWidth!==void 0&&e.maxWidth!==null){const r=n=>{var s,a,c,l,p;const i=((c=(a=(s=e.theme)==null?void 0:s.breakpoints)==null?void 0:a.values)==null?void 0:c[n])||dn[n];return i?((p=(l=e.theme)==null?void 0:l.breakpoints)==null?void 0:p.unit)!=="px"?{maxWidth:`${i}${e.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:ft(n)}};return er(e,e.maxWidth,r)}return null};mi.filterProps=["maxWidth"];const Hc=Fe({prop:"minWidth",transform:ft}),Uc=Fe({prop:"height",transform:ft}),Gc=Fe({prop:"maxHeight",transform:ft}),Yc=Fe({prop:"minHeight",transform:ft});Fe({prop:"size",cssProperty:"width",transform:ft});Fe({prop:"size",cssProperty:"height",transform:ft});const qc=Fe({prop:"boxSizing"});fn(Vc,mi,Hc,Uc,Gc,Yc,qc);const bn={border:{themeKey:"borders",transform:St},borderTop:{themeKey:"borders",transform:St},borderRight:{themeKey:"borders",transform:St},borderBottom:{themeKey:"borders",transform:St},borderLeft:{themeKey:"borders",transform:St},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:St},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:mn},color:{themeKey:"palette",transform:oo},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:oo},backgroundColor:{themeKey:"palette",transform:oo},p:{style:Pe},pt:{style:Pe},pr:{style:Pe},pb:{style:Pe},pl:{style:Pe},px:{style:Pe},py:{style:Pe},padding:{style:Pe},paddingTop:{style:Pe},paddingRight:{style:Pe},paddingBottom:{style:Pe},paddingLeft:{style:Pe},paddingX:{style:Pe},paddingY:{style:Pe},paddingInline:{style:Pe},paddingInlineStart:{style:Pe},paddingInlineEnd:{style:Pe},paddingBlock:{style:Pe},paddingBlockStart:{style:Pe},paddingBlockEnd:{style:Pe},m:{style:Re},mt:{style:Re},mr:{style:Re},mb:{style:Re},ml:{style:Re},mx:{style:Re},my:{style:Re},margin:{style:Re},marginTop:{style:Re},marginRight:{style:Re},marginBottom:{style:Re},marginLeft:{style:Re},marginX:{style:Re},marginY:{style:Re},marginInline:{style:Re},marginInlineStart:{style:Re},marginInlineEnd:{style:Re},marginBlock:{style:Re},marginBlockStart:{style:Re},marginBlockEnd:{style:Re},displayPrint:{cssProperty:!1,transform:e=>({"@media print":{display:e}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:xn},rowGap:{style:yn},columnGap:{style:gn},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:ft},maxWidth:{style:mi},minWidth:{transform:ft},height:{transform:ft},maxHeight:{transform:ft},minHeight:{transform:ft},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function Jc(...e){const r=e.reduce((i,s)=>i.concat(Object.keys(s)),[]),n=new Set(r);return e.every(i=>n.size===Object.keys(i).length)}function Kc(e,r){return typeof e=="function"?e(r):e}function Xc(){function e(n,i,s,a){const c={[n]:i,theme:s},l=a[n];if(!l)return{[n]:i};const{cssProperty:p=n,themeKey:x,transform:y,style:g}=l;if(i==null)return null;if(x==="typography"&&i==="inherit")return{[n]:i};const v=un(s,x)||{};return g?g(c):er(c,i,k=>{let b=on(v,y,k);return k===b&&typeof k=="string"&&(b=on(v,y,`${n}${k==="default"?"":Rs(k)}`,k)),p===!1?b:{[p]:b}})}function r(n){const{sx:i,theme:s={},nested:a}=n||{};if(!i)return null;const c=s.unstable_sxConfig??bn;function l(p){let x=p;if(typeof p=="function")x=p(s);else if(typeof p!="object")return p;if(!x)return null;const y=uc(s.breakpoints),g=Object.keys(y);let v=y;return Object.keys(x).forEach(S=>{const k=Kc(x[S],s);if(k!=null)if(typeof k=="object")if(c[S])v=zo(v,e(S,k,s,c));else{const b=er({theme:s},k,m=>({[S]:m}));Jc(b,k)?v[S]=r({sx:k,theme:s,nested:!0}):v=zo(v,b)}else v=zo(v,e(S,k,s,c))}),!a&&s.modularCssLayers?{"@layer sx":qi(s,Ki(g,v))}:qi(s,Ki(g,v))}return Array.isArray(i)?i.map(l):l(i)}return r}const vn=Xc();vn.filterProps=["sx"];function Qc(e,r){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[e])||typeof n.getColorSchemeSelector!="function")return{};let s=n.getColorSchemeSelector(e);return s==="&"?r:((s.includes("data-")||s.includes("."))&&(s=`*:where(${s.replace(/\s*&$/,"")}) &`),{[s]:r})}return n.palette.mode===e?r:{}}function Ls(e={},...r){const{breakpoints:n={},palette:i={},spacing:s,shape:a={},...c}=e,l=ic(n),p=Ns(s);let x=mt({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:p,shape:{...cc,...a}},c);return x=lc(x),x.applyStyles=Qc,x=r.reduce((y,g)=>mt(y,g),x),x.unstable_sxConfig={...bn,...c==null?void 0:c.unstable_sxConfig},x.unstable_sx=function(g){return vn({sx:g,theme:this})},x}function Zc(e){return Object.keys(e).length===0}function ed(e=null){const r=sn.useContext(ma.ThemeContext);return!r||Zc(r)?e:r}const td=Ls();function rd(e=td){return ed(e)}const Qi=e=>e,od=()=>{let e=Qi;return{configure(r){e=r},generate(r){return e(r)},reset(){e=Qi}}},nd=od(),id={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function sd(e,r,n="Mui"){const i=id[r];return i?`${n}-${i}`:`${nd.generate(e)}-${r}`}function ad(e,r=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(r,Math.min(e,n))}function xi(e,r=0,n=1){return process.env.NODE_ENV!=="production"&&(e<r||e>n)&&console.error(`MUI: The value provided ${e} is out of range [${r}, ${n}].`),ad(e,r,n)}function ld(e){e=e.slice(1);const r=new RegExp(`.{1,${e.length>=6?2:1}}`,"g");let n=e.match(r);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&e.length!==e.trim().length&&console.error(`MUI: The color: "${e}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,s)=>s<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function pr(e){if(e.type)return e;if(e.charAt(0)==="#")return pr(ld(e));const r=e.indexOf("("),n=e.substring(0,r);if(!["rgb","rgba","hsl","hsla","color"].includes(n))throw new Error(process.env.NODE_ENV!=="production"?`MUI: Unsupported \`${e}\` color.
|
|
144
|
+
`)),()=>{})}function fi(e){return Eo(e,"spacing",8,"spacing")}function Do(e,r){return typeof r=="string"||r==null?r:e(r)}function gc(e,r){return n=>e.reduce((i,s)=>(i[s]=Do(r,n),i),{})}function yc(e,r,n,i){if(!r.includes(n))return null;const s=mc(n),a=gc(s,i),c=e[n];return er(e,c,a)}function Ps(e,r){const n=fi(e.theme);return Object.keys(e).map(i=>yc(e,r,i,n)).reduce(zo,{})}function Re(e){return Ps(e,pn)}Re.propTypes=process.env.NODE_ENV!=="production"?pn.reduce((e,r)=>(e[r]=hr,e),{}):{};Re.filterProps=pn;function Pe(e){return Ps(e,hn)}Pe.propTypes=process.env.NODE_ENV!=="production"?hn.reduce((e,r)=>(e[r]=hr,e),{}):{};Pe.filterProps=hn;process.env.NODE_ENV!=="production"&&xc.reduce((e,r)=>(e[r]=hr,e),{});function Ns(e=8,r=fi({spacing:e})){if(e.mui)return e;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(a=>{const c=r(a);return typeof c=="number"?`${c}px`:c}).join(" "));return n.mui=!0,n}function fn(...e){const r=e.reduce((i,s)=>(s.filterProps.forEach(a=>{i[a]=s}),i),{}),n=i=>Object.keys(i).reduce((s,a)=>r[a]?zo(s,r[a](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?e.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=e.reduce((i,s)=>i.concat(s.filterProps),[]),n}function St(e){return typeof e!="number"?e:`${e}px solid`}function wt(e,r){return Fe({prop:e,themeKey:"borders",transform:r})}const bc=wt("border",St),vc=wt("borderTop",St),Sc=wt("borderRight",St),Cc=wt("borderBottom",St),jc=wt("borderLeft",St),wc=wt("borderColor"),kc=wt("borderTopColor"),zc=wt("borderRightColor"),Tc=wt("borderBottomColor"),Bc=wt("borderLeftColor"),Ic=wt("outline",St),Ec=wt("outlineColor"),mn=e=>{if(e.borderRadius!==void 0&&e.borderRadius!==null){const r=Eo(e.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Do(r,i)});return er(e,e.borderRadius,n)}return null};mn.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:hr}:{};mn.filterProps=["borderRadius"];fn(bc,vc,Sc,Cc,jc,wc,kc,zc,Tc,Bc,mn,Ic,Ec);const xn=e=>{if(e.gap!==void 0&&e.gap!==null){const r=Eo(e.theme,"spacing",8,"gap"),n=i=>({gap:Do(r,i)});return er(e,e.gap,n)}return null};xn.propTypes=process.env.NODE_ENV!=="production"?{gap:hr}:{};xn.filterProps=["gap"];const gn=e=>{if(e.columnGap!==void 0&&e.columnGap!==null){const r=Eo(e.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Do(r,i)});return er(e,e.columnGap,n)}return null};gn.propTypes=process.env.NODE_ENV!=="production"?{columnGap:hr}:{};gn.filterProps=["columnGap"];const yn=e=>{if(e.rowGap!==void 0&&e.rowGap!==null){const r=Eo(e.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Do(r,i)});return er(e,e.rowGap,n)}return null};yn.propTypes=process.env.NODE_ENV!=="production"?{rowGap:hr}:{};yn.filterProps=["rowGap"];const Dc=Fe({prop:"gridColumn"}),$c=Fe({prop:"gridRow"}),_c=Fe({prop:"gridAutoFlow"}),Oc=Fe({prop:"gridAutoColumns"}),Mc=Fe({prop:"gridAutoRows"}),Wc=Fe({prop:"gridTemplateColumns"}),Ac=Fe({prop:"gridTemplateRows"}),Rc=Fe({prop:"gridTemplateAreas"}),Pc=Fe({prop:"gridArea"});fn(xn,gn,yn,Dc,$c,_c,Oc,Mc,Wc,Ac,Rc,Pc);function no(e,r){return r==="grey"?r:e}const Nc=Fe({prop:"color",themeKey:"palette",transform:no}),Lc=Fe({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:no}),Fc=Fe({prop:"backgroundColor",themeKey:"palette",transform:no});fn(Nc,Lc,Fc);function ft(e){return e<=1&&e!==0?`${e*100}%`:e}const Vc=Fe({prop:"width",transform:ft}),mi=e=>{if(e.maxWidth!==void 0&&e.maxWidth!==null){const r=n=>{var s,a,c,l,p;const i=((c=(a=(s=e.theme)==null?void 0:s.breakpoints)==null?void 0:a.values)==null?void 0:c[n])||dn[n];return i?((p=(l=e.theme)==null?void 0:l.breakpoints)==null?void 0:p.unit)!=="px"?{maxWidth:`${i}${e.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:ft(n)}};return er(e,e.maxWidth,r)}return null};mi.filterProps=["maxWidth"];const Hc=Fe({prop:"minWidth",transform:ft}),Uc=Fe({prop:"height",transform:ft}),Gc=Fe({prop:"maxHeight",transform:ft}),Yc=Fe({prop:"minHeight",transform:ft});Fe({prop:"size",cssProperty:"width",transform:ft});Fe({prop:"size",cssProperty:"height",transform:ft});const qc=Fe({prop:"boxSizing"});fn(Vc,mi,Hc,Uc,Gc,Yc,qc);const bn={border:{themeKey:"borders",transform:St},borderTop:{themeKey:"borders",transform:St},borderRight:{themeKey:"borders",transform:St},borderBottom:{themeKey:"borders",transform:St},borderLeft:{themeKey:"borders",transform:St},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:St},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:mn},color:{themeKey:"palette",transform:no},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:no},backgroundColor:{themeKey:"palette",transform:no},p:{style:Pe},pt:{style:Pe},pr:{style:Pe},pb:{style:Pe},pl:{style:Pe},px:{style:Pe},py:{style:Pe},padding:{style:Pe},paddingTop:{style:Pe},paddingRight:{style:Pe},paddingBottom:{style:Pe},paddingLeft:{style:Pe},paddingX:{style:Pe},paddingY:{style:Pe},paddingInline:{style:Pe},paddingInlineStart:{style:Pe},paddingInlineEnd:{style:Pe},paddingBlock:{style:Pe},paddingBlockStart:{style:Pe},paddingBlockEnd:{style:Pe},m:{style:Re},mt:{style:Re},mr:{style:Re},mb:{style:Re},ml:{style:Re},mx:{style:Re},my:{style:Re},margin:{style:Re},marginTop:{style:Re},marginRight:{style:Re},marginBottom:{style:Re},marginLeft:{style:Re},marginX:{style:Re},marginY:{style:Re},marginInline:{style:Re},marginInlineStart:{style:Re},marginInlineEnd:{style:Re},marginBlock:{style:Re},marginBlockStart:{style:Re},marginBlockEnd:{style:Re},displayPrint:{cssProperty:!1,transform:e=>({"@media print":{display:e}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:xn},rowGap:{style:yn},columnGap:{style:gn},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:ft},maxWidth:{style:mi},minWidth:{transform:ft},height:{transform:ft},maxHeight:{transform:ft},minHeight:{transform:ft},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function Jc(...e){const r=e.reduce((i,s)=>i.concat(Object.keys(s)),[]),n=new Set(r);return e.every(i=>n.size===Object.keys(i).length)}function Kc(e,r){return typeof e=="function"?e(r):e}function Xc(){function e(n,i,s,a){const c={[n]:i,theme:s},l=a[n];if(!l)return{[n]:i};const{cssProperty:p=n,themeKey:x,transform:y,style:g}=l;if(i==null)return null;if(x==="typography"&&i==="inherit")return{[n]:i};const v=un(s,x)||{};return g?g(c):er(c,i,k=>{let b=on(v,y,k);return k===b&&typeof k=="string"&&(b=on(v,y,`${n}${k==="default"?"":Rs(k)}`,k)),p===!1?b:{[p]:b}})}function r(n){const{sx:i,theme:s={},nested:a}=n||{};if(!i)return null;const c=s.unstable_sxConfig??bn;function l(p){let x=p;if(typeof p=="function")x=p(s);else if(typeof p!="object")return p;if(!x)return null;const y=uc(s.breakpoints),g=Object.keys(y);let v=y;return Object.keys(x).forEach(S=>{const k=Kc(x[S],s);if(k!=null)if(typeof k=="object")if(c[S])v=zo(v,e(S,k,s,c));else{const b=er({theme:s},k,m=>({[S]:m}));Jc(b,k)?v[S]=r({sx:k,theme:s,nested:!0}):v=zo(v,b)}else v=zo(v,e(S,k,s,c))}),!a&&s.modularCssLayers?{"@layer sx":qi(s,Ki(g,v))}:qi(s,Ki(g,v))}return Array.isArray(i)?i.map(l):l(i)}return r}const vn=Xc();vn.filterProps=["sx"];function Qc(e,r){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[e])||typeof n.getColorSchemeSelector!="function")return{};let s=n.getColorSchemeSelector(e);return s==="&"?r:((s.includes("data-")||s.includes("."))&&(s=`*:where(${s.replace(/\s*&$/,"")}) &`),{[s]:r})}return n.palette.mode===e?r:{}}function Ls(e={},...r){const{breakpoints:n={},palette:i={},spacing:s,shape:a={},...c}=e,l=ic(n),p=Ns(s);let x=mt({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:p,shape:{...cc,...a}},c);return x=lc(x),x.applyStyles=Qc,x=r.reduce((y,g)=>mt(y,g),x),x.unstable_sxConfig={...bn,...c==null?void 0:c.unstable_sxConfig},x.unstable_sx=function(g){return vn({sx:g,theme:this})},x}function Zc(e){return Object.keys(e).length===0}function ed(e=null){const r=sn.useContext(ma.ThemeContext);return!r||Zc(r)?e:r}const td=Ls();function rd(e=td){return ed(e)}const Qi=e=>e,od=()=>{let e=Qi;return{configure(r){e=r},generate(r){return e(r)},reset(){e=Qi}}},nd=od(),id={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function sd(e,r,n="Mui"){const i=id[r];return i?`${n}-${i}`:`${nd.generate(e)}-${r}`}function ad(e,r=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(r,Math.min(e,n))}function xi(e,r=0,n=1){return process.env.NODE_ENV!=="production"&&(e<r||e>n)&&console.error(`MUI: The value provided ${e} is out of range [${r}, ${n}].`),ad(e,r,n)}function ld(e){e=e.slice(1);const r=new RegExp(`.{1,${e.length>=6?2:1}}`,"g");let n=e.match(r);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&e.length!==e.trim().length&&console.error(`MUI: The color: "${e}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,s)=>s<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function pr(e){if(e.type)return e;if(e.charAt(0)==="#")return pr(ld(e));const r=e.indexOf("("),n=e.substring(0,r);if(!["rgb","rgba","hsl","hsla","color"].includes(n))throw new Error(process.env.NODE_ENV!=="production"?`MUI: Unsupported \`${e}\` color.
|
|
145
145
|
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().`:Er(9,e));let i=e.substring(r+1,e.length-1),s;if(n==="color"){if(i=i.split(" "),s=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),!["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].includes(s))throw new Error(process.env.NODE_ENV!=="production"?`MUI: unsupported \`${s}\` color space.
|
|
146
|
-
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:Er(10,s))}else i=i.split(",");return i=i.map(a=>parseFloat(a)),{type:n,values:i,colorSpace:s}}const cd=e=>{const r=pr(e);return r.values.slice(0,3).map((n,i)=>r.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},jo=(e,r)=>{try{return cd(e)}catch{return r&&process.env.NODE_ENV!=="production"&&console.warn(r),e}};function Sn(e){const{type:r,colorSpace:n}=e;let{values:i}=e;return r.includes("rgb")?i=i.map((s,a)=>a<3?parseInt(s,10):s):r.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),r.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${r}(${i})`}function Fs(e){e=pr(e);const{values:r}=e,n=r[0],i=r[1]/100,s=r[2]/100,a=i*Math.min(s,1-s),c=(x,y=(x+n/30)%12)=>s-a*Math.max(Math.min(y-3,9-y,1),-1);let l="rgb";const p=[Math.round(c(0)*255),Math.round(c(8)*255),Math.round(c(4)*255)];return e.type==="hsla"&&(l+="a",p.push(r[3])),Sn({type:l,values:p})}function ei(e){e=pr(e);let r=e.type==="hsl"||e.type==="hsla"?pr(Fs(e)).values:e.values;return r=r.map(n=>(e.type!=="color"&&(n/=255),n<=.03928?n/12.92:((n+.055)/1.055)**2.4)),Number((.2126*r[0]+.7152*r[1]+.0722*r[2]).toFixed(3))}function Zi(e,r){const n=ei(e),i=ei(r);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function
|
|
146
|
+
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:Er(10,s))}else i=i.split(",");return i=i.map(a=>parseFloat(a)),{type:n,values:i,colorSpace:s}}const cd=e=>{const r=pr(e);return r.values.slice(0,3).map((n,i)=>r.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},jo=(e,r)=>{try{return cd(e)}catch{return r&&process.env.NODE_ENV!=="production"&&console.warn(r),e}};function Sn(e){const{type:r,colorSpace:n}=e;let{values:i}=e;return r.includes("rgb")?i=i.map((s,a)=>a<3?parseInt(s,10):s):r.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),r.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${r}(${i})`}function Fs(e){e=pr(e);const{values:r}=e,n=r[0],i=r[1]/100,s=r[2]/100,a=i*Math.min(s,1-s),c=(x,y=(x+n/30)%12)=>s-a*Math.max(Math.min(y-3,9-y,1),-1);let l="rgb";const p=[Math.round(c(0)*255),Math.round(c(8)*255),Math.round(c(4)*255)];return e.type==="hsla"&&(l+="a",p.push(r[3])),Sn({type:l,values:p})}function ei(e){e=pr(e);let r=e.type==="hsl"||e.type==="hsla"?pr(Fs(e)).values:e.values;return r=r.map(n=>(e.type!=="color"&&(n/=255),n<=.03928?n/12.92:((n+.055)/1.055)**2.4)),Number((.2126*r[0]+.7152*r[1]+.0722*r[2]).toFixed(3))}function Zi(e,r){const n=ei(e),i=ei(r);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function D(e,r){return e=pr(e),r=xi(r),(e.type==="rgb"||e.type==="hsl")&&(e.type+="a"),e.type==="color"?e.values[3]=`/${r}`:e.values[3]=r,Sn(e)}function Br(e,r,n){try{return D(e,r)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),e}}function Cn(e,r){if(e=pr(e),r=xi(r),e.type.includes("hsl"))e.values[2]*=1-r;else if(e.type.includes("rgb")||e.type.includes("color"))for(let n=0;n<3;n+=1)e.values[n]*=1-r;return Sn(e)}function Ie(e,r,n){try{return Cn(e,r)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),e}}function jn(e,r){if(e=pr(e),r=xi(r),e.type.includes("hsl"))e.values[2]+=(100-e.values[2])*r;else if(e.type.includes("rgb"))for(let n=0;n<3;n+=1)e.values[n]+=(255-e.values[n])*r;else if(e.type.includes("color"))for(let n=0;n<3;n+=1)e.values[n]+=(1-e.values[n])*r;return Sn(e)}function Ee(e,r,n){try{return jn(e,r)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),e}}function dd(e,r=.15){return ei(e)>.5?Cn(e,r):jn(e,r)}function Uo(e,r,n){try{return dd(e,r)}catch{return e}}function ud(e=""){function r(...i){if(!i.length)return"";const s=i[0];return typeof s=="string"&&!s.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)?`, var(--${e?`${e}-`:""}${s}${r(...i.slice(1))})`:`, ${s}`}return(i,...s)=>`var(--${e?`${e}-`:""}${i}${r(...s)})`}const es=(e,r,n,i=[])=>{let s=e;r.forEach((a,c)=>{c===r.length-1?Array.isArray(s)?s[Number(a)]=n:s&&typeof s=="object"&&(s[a]=n):s&&typeof s=="object"&&(s[a]||(s[a]=i.includes(a)?[]:{}),s=s[a])})},pd=(e,r,n)=>{function i(s,a=[],c=[]){Object.entries(s).forEach(([l,p])=>{(!n||n&&!n([...a,l]))&&p!=null&&(typeof p=="object"&&Object.keys(p).length>0?i(p,[...a,l],Array.isArray(p)?[...c,l]:c):r([...a,l],p,c))})}i(e)},hd=(e,r)=>typeof r=="number"?["lineHeight","fontWeight","opacity","zIndex"].some(i=>e.includes(i))||e[e.length-1].toLowerCase().includes("opacity")?r:`${r}px`:r;function qn(e,r){const{prefix:n,shouldSkipGeneratingVar:i}=r||{},s={},a={},c={};return pd(e,(l,p,x)=>{if((typeof p=="string"||typeof p=="number")&&(!i||!i(l,p))){const y=`--${n?`${n}-`:""}${l.join("-")}`,g=hd(l,p);Object.assign(s,{[y]:g}),es(a,l,`var(${y})`,x),es(c,l,`var(${y}, ${g})`,x)}},l=>l[0]==="vars"),{css:s,vars:a,varsWithDefaults:c}}function fd(e,r={}){const{getSelector:n=z,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:a}=r,{colorSchemes:c={},components:l,defaultColorScheme:p="light",...x}=e,{vars:y,css:g,varsWithDefaults:v}=qn(x,r);let S=v;const k={},{[p]:b,...m}=c;if(Object.entries(m||{}).forEach(([T,w])=>{const{vars:P,css:O,varsWithDefaults:M}=qn(w,r);S=mt(S,M),k[T]={css:O,vars:P}}),b){const{css:T,vars:w,varsWithDefaults:P}=qn(b,r);S=mt(S,P),k[p]={css:T,vars:w}}function z(T,w){var O,M;let P=s;if(s==="class"&&(P=".%s"),s==="data"&&(P="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(P=`[${s}="%s"]`),T){if(P==="media")return e.defaultColorScheme===T?":root":{[`@media (prefers-color-scheme: ${((M=(O=c[T])==null?void 0:O.palette)==null?void 0:M.mode)||T})`]:{":root":w}};if(P)return e.defaultColorScheme===T?`:root, ${P.replace("%s",String(T))}`:P.replace("%s",String(T))}return":root"}return{vars:S,generateThemeVars:()=>{let T={...y};return Object.entries(k).forEach(([,{vars:w}])=>{T=mt(T,w)}),T},generateStyleSheets:()=>{var Y,J;const T=[],w=e.defaultColorScheme||"light";function P(R,u){Object.keys(u).length&&T.push(typeof R=="string"?{[R]:{...u}}:R)}P(n(void 0,{...g}),g);const{[w]:O,...M}=k;if(O){const{css:R}=O,u=(J=(Y=c[w])==null?void 0:Y.palette)==null?void 0:J.mode,A=!i&&u?{colorScheme:u,...R}:{...R};P(n(w,{...A}),A)}return Object.entries(M).forEach(([R,{css:u}])=>{var d,ne;const A=(ne=(d=c[R])==null?void 0:d.palette)==null?void 0:ne.mode,F=!i&&A?{colorScheme:A,...u}:{...u};P(n(R,{...F}),F)}),a&&T.push({":root":{"--__l-threshold":"0.7","--__l":"clamp(0, (l / var(--__l-threshold) - 1) * -infinity, 1)","--__a":"clamp(0.87, (l / var(--__l-threshold) - 1) * -infinity, 1)"}}),T}}}function md(e){return function(n){return e==="media"?(process.env.NODE_ENV!=="production"&&n!=="light"&&n!=="dark"&&console.error(`MUI: @media (prefers-color-scheme) supports only 'light' or 'dark', but receive '${n}'.`),`@media (prefers-color-scheme: ${n})`):e?e.startsWith("data-")&&!e.includes("%s")?`[${e}="${n}"] &`:e==="class"?`.${n} &`:e==="data"?`[data-${n}] &`:`${e.replace("%s",n)} &`:"&"}}const Bo={black:"#000",white:"#fff"},xd={50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121",A100:"#f5f5f5",A200:"#eeeeee",A400:"#bdbdbd",A700:"#616161"},Qr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},Zr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},vo={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},eo={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},to={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},ro={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Vs(){return{text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:Bo.white,default:Bo.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}}}const Hs=Vs();function Us(){return{text:{primary:Bo.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:Bo.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}}}const ti=Us();function ts(e,r,n,i){const s=i.light||i,a=i.dark||i*1.5;e[r]||(e.hasOwnProperty(n)?e[r]=e[n]:r==="light"?e.light=jn(e.main,s):r==="dark"&&(e.dark=Cn(e.main,a)))}function rs(e,r,n,i,s){const a=s.light||s,c=s.dark||s*1.5;r[n]||(r.hasOwnProperty(i)?r[n]=r[i]:n==="light"?r.light=`color-mix(in ${e}, ${r.main}, #fff ${(a*100).toFixed(0)}%)`:n==="dark"&&(r.dark=`color-mix(in ${e}, ${r.main}, #000 ${(c*100).toFixed(0)}%)`))}function gd(e="light"){return e==="dark"?{main:eo[200],light:eo[50],dark:eo[400]}:{main:eo[700],light:eo[400],dark:eo[800]}}function yd(e="light"){return e==="dark"?{main:Qr[200],light:Qr[50],dark:Qr[400]}:{main:Qr[500],light:Qr[300],dark:Qr[700]}}function bd(e="light"){return e==="dark"?{main:Zr[500],light:Zr[300],dark:Zr[700]}:{main:Zr[700],light:Zr[400],dark:Zr[800]}}function vd(e="light"){return e==="dark"?{main:to[400],light:to[300],dark:to[700]}:{main:to[700],light:to[500],dark:to[900]}}function Sd(e="light"){return e==="dark"?{main:ro[400],light:ro[300],dark:ro[700]}:{main:ro[800],light:ro[500],dark:ro[900]}}function Cd(e="light"){return e==="dark"?{main:vo[400],light:vo[300],dark:vo[700]}:{main:"#ed6c02",light:vo[500],dark:vo[900]}}function jd(e){return`oklch(from ${e} var(--__l) 0 h / var(--__a))`}function gi(e){const{mode:r="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...a}=e,c=e.primary||gd(r),l=e.secondary||yd(r),p=e.error||bd(r),x=e.info||vd(r),y=e.success||Sd(r),g=e.warning||Cd(r);function v(m){if(s)return jd(m);const z=Zi(m,ti.text.primary)>=n?ti.text.primary:Hs.text.primary;if(process.env.NODE_ENV!=="production"){const h=Zi(m,z);h<3&&console.error([`MUI: The contrast ratio of ${h}:1 for ${z} on ${m}`,"falls below the WCAG recommended absolute minimum contrast ratio of 3:1.","https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast"].join(`
|
|
147
147
|
`))}return z}const S=({color:m,name:z,mainShade:h=500,lightShade:B=300,darkShade:T=700})=>{if(m={...m},!m.main&&m[h]&&(m.main=m[h]),!m.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${z?` (${z})`:""} provided to augmentColor(color) is invalid.
|
|
148
148
|
The color object needs to have a \`main\` property or a \`${h}\` property.`:Er(11,z?` (${z})`:"",h));if(typeof m.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${z?` (${z})`:""} provided to augmentColor(color) is invalid.
|
|
149
149
|
\`color.main\` should be a string, but \`${JSON.stringify(m.main)}\` was provided instead.
|
|
@@ -166,9 +166,9 @@ const theme = ${JSON.stringify(r,null,2)};
|
|
|
166
166
|
theme.breakpoints = createBreakpoints(theme.breakpoints || {});
|
|
167
167
|
theme.transitions = createTransitions(theme.transitions || {});
|
|
168
168
|
|
|
169
|
-
export default theme;`}function ss(e){return typeof e=="number"?`${(e*100).toFixed(0)}%`:`calc((${e}) * 100%)`}const Rd=e=>{if(!Number.isNaN(+e))return+e;const r=e.match(/\d*\.?\d+/g);if(!r)return 0;let n=0;for(let i=0;i<r.length;i+=1)n+=+r[i];return n};function Pd(e){Object.assign(e,{alpha(r,n){const i=this||e;return i.colorSpace?`oklch(from ${r} l c h / ${typeof n=="string"?`calc(${n})`:n})`:i.vars?`rgba(${r.replace(/var\(--([^,\s)]+)(?:,[^)]+)?\)+/g,"var(--$1Channel)")} / ${typeof n=="string"?`calc(${n})`:n})`:
|
|
169
|
+
export default theme;`}function ss(e){return typeof e=="number"?`${(e*100).toFixed(0)}%`:`calc((${e}) * 100%)`}const Rd=e=>{if(!Number.isNaN(+e))return+e;const r=e.match(/\d*\.?\d+/g);if(!r)return 0;let n=0;for(let i=0;i<r.length;i+=1)n+=+r[i];return n};function Pd(e){Object.assign(e,{alpha(r,n){const i=this||e;return i.colorSpace?`oklch(from ${r} l c h / ${typeof n=="string"?`calc(${n})`:n})`:i.vars?`rgba(${r.replace(/var\(--([^,\s)]+)(?:,[^)]+)?\)+/g,"var(--$1Channel)")} / ${typeof n=="string"?`calc(${n})`:n})`:D(r,Rd(n))},lighten(r,n){const i=this||e;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${r}, #fff ${ss(n)})`:jn(r,n)},darken(r,n){const i=this||e;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${r}, #000 ${ss(n)})`:Cn(r,n)}})}function ri(e={},...r){const{breakpoints:n,mixins:i={},spacing:s,palette:a={},transitions:c={},typography:l={},shape:p,colorSpace:x,...y}=e;if(e.vars&&e.generateThemeVars===void 0)throw new Error(process.env.NODE_ENV!=="production"?"MUI: `vars` is a private field used for CSS variables support.\nPlease use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.":Er(20));const g=gi({...a,colorSpace:x}),v=Ls(e);let S=mt(v,{mixins:kd(v.breakpoints,i),palette:g,shadows:Dd.slice(),typography:Td(g,l),transitions:Md(c),zIndex:{...Wd}});if(S=mt(S,y),S=r.reduce((k,b)=>mt(k,b),S),process.env.NODE_ENV!=="production"){const k=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],b=(m,z)=>{let h;for(h in m){const B=m[h];if(k.includes(h)&&Object.keys(B).length>0){if(process.env.NODE_ENV!=="production"){const T=sd("",h);console.error([`MUI: The \`${z}\` component increases the CSS specificity of the \`${h}\` internal state.`,"You can not override it like this: ",JSON.stringify(m,null,2),"",`Instead, you need to use the '&.${T}' syntax:`,JSON.stringify({root:{[`&.${T}`]:B}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
|
|
170
170
|
`))}m[h]={}}}};Object.keys(S.components).forEach(m=>{const z=S.components[m].styleOverrides;z&&m.startsWith("Mui")&&b(z,m)})}return S.unstable_sxConfig={...bn,...y==null?void 0:y.unstable_sxConfig},S.unstable_sx=function(b){return vn({sx:b,theme:this})},S.toRuntimeSource=Gs,Pd(S),S}function Nd(e){let r;return e<1?r=5.11916*e**2:r=4.5*Math.log(e+1)+2,Math.round(r*10)/1e3}const Ld=[...Array(25)].map((e,r)=>{if(r===0)return"none";const n=Nd(r);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ys(e){return{inputPlaceholder:e==="dark"?.5:.42,inputUnderline:e==="dark"?.7:.42,switchTrackDisabled:e==="dark"?.2:.12,switchTrack:e==="dark"?.3:.38}}function qs(e){return e==="dark"?Ld:[]}function Fd(e){const{palette:r={mode:"light"},opacity:n,overlays:i,colorSpace:s,...a}=e,c=gi({...r,colorSpace:s});return{palette:c,opacity:{...Ys(c.mode),...n},overlays:i||qs(c.mode),...a}}function Vd(e){var r;return!!e[0].match(/(cssVarPrefix|colorSchemeSelector|modularCssLayers|rootSelector|typography|mixins|breakpoints|direction|transitions)/)||!!e[0].match(/sxConfig$/)||e[0]==="palette"&&!!((r=e[1])!=null&&r.match(/(mode|contrastThreshold|tonalOffset)/))}const Hd=e=>[...[...Array(25)].map((r,n)=>`--${e?`${e}-`:""}overlays-${n}`),`--${e?`${e}-`:""}palette-AppBar-darkBg`,`--${e?`${e}-`:""}palette-AppBar-darkColor`],Ud=e=>(r,n)=>{const i=e.rootSelector||":root",s=e.colorSchemeSelector;let a=s;if(s==="class"&&(a=".%s"),s==="data"&&(a="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(a=`[${s}="%s"]`),e.defaultColorScheme===r){if(r==="dark"){const c={};return Hd(e.cssVarPrefix).forEach(l=>{c[l]=n[l],delete n[l]}),a==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:c}}:a?{[a.replace("%s",r)]:c,[`${i}, ${a.replace("%s",r)}`]:n}:{[i]:{...n,...c}}}if(a&&a!=="media")return`${i}, ${a.replace("%s",String(r))}`}else if(r){if(a==="media")return{[`@media (prefers-color-scheme: ${String(r)})`]:{[i]:n}};if(a)return a.replace("%s",String(r))}return i};function Gd(e,r){r.forEach(n=>{e[n]||(e[n]={})})}function L(e,r,n){!e[r]&&n&&(e[r]=n)}function wo(e){return typeof e!="string"||!e.startsWith("hsl")?e:Fs(e)}function Qt(e,r){`${r}Channel`in e||(e[`${r}Channel`]=jo(wo(e[r]),`MUI: Can't create \`palette.${r}Channel\` because \`palette.${r}\` is not one of these formats: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().
|
|
171
|
-
To suppress this warning, you need to explicitly provide the \`palette.${r}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function Yd(e){return typeof e=="number"?`${e}px`:typeof e=="string"||typeof e=="function"||Array.isArray(e)?e:"8px"}const Pt=e=>{try{return e()}catch{}},qd=(e="mui")=>ud(e);function Jn(e,r,n,i,s){if(!n)return;n=n===!0?{}:n;const a=s==="dark"?"dark":"light";if(!i){r[s]=Fd({...n,palette:{mode:a,...n==null?void 0:n.palette},colorSpace:e});return}const{palette:c,...l}=ri({...i,palette:{mode:a,...n==null?void 0:n.palette},colorSpace:e});return r[s]={...n,palette:c,opacity:{...Ys(a),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||qs(a)},l}function Jd(e={},...r){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:a="mui",nativeColor:c=!1,shouldSkipGeneratingVar:l=Vd,colorSchemeSelector:p=n.light&&n.dark?"media":void 0,rootSelector:x=":root",...y}=e,g=Object.keys(n)[0],v=i||(n.light&&g!=="light"?"light":g),S=qd(a),{[v]:k,light:b,dark:m,...z}=n,h={...z};let B=k;if((v==="dark"&&!("dark"in n)||v==="light"&&!("light"in n))&&(B=!0),!B)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${v}\` option is either missing or invalid.`:Er(21,v));let T;c&&(T="oklch");const j=Jn(T,h,B,y,v);b&&!h.light&&Jn(T,h,b,void 0,"light"),m&&!h.dark&&Jn(T,h,m,void 0,"dark");let P={defaultColorScheme:v,...j,cssVarPrefix:a,colorSchemeSelector:p,rootSelector:x,getCssVar:S,colorSchemes:h,font:{...wd(j.typography),...j.font},spacing:Yd(y.spacing)};Object.keys(P.colorSchemes).forEach(R=>{const u=P.colorSchemes[R].palette,A=d=>{const ne=d.split("-"),U=ne[1],re=ne[2];return S(d,u[U][re])};u.mode==="light"&&(L(u.common,"background","#fff"),L(u.common,"onBackground","#000")),u.mode==="dark"&&(L(u.common,"background","#000"),L(u.common,"onBackground","#fff"));function F(d,ne,U){if(T){let re;return d===Br&&(re=`transparent ${((1-U)*100).toFixed(0)}%`),d===Ie&&(re=`#000 ${(U*100).toFixed(0)}%`),d===Ee&&(re=`#fff ${(U*100).toFixed(0)}%`),`color-mix(in ${T}, ${ne}, ${re})`}return d(ne,U)}if(Gd(u,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),u.mode==="light"){L(u.Alert,"errorColor",F(Ie,u.error.light,.6)),L(u.Alert,"infoColor",F(Ie,u.info.light,.6)),L(u.Alert,"successColor",F(Ie,u.success.light,.6)),L(u.Alert,"warningColor",F(Ie,u.warning.light,.6)),L(u.Alert,"errorFilledBg",A("palette-error-main")),L(u.Alert,"infoFilledBg",A("palette-info-main")),L(u.Alert,"successFilledBg",A("palette-success-main")),L(u.Alert,"warningFilledBg",A("palette-warning-main")),L(u.Alert,"errorFilledColor",Pt(()=>u.getContrastText(u.error.main))),L(u.Alert,"infoFilledColor",Pt(()=>u.getContrastText(u.info.main))),L(u.Alert,"successFilledColor",Pt(()=>u.getContrastText(u.success.main))),L(u.Alert,"warningFilledColor",Pt(()=>u.getContrastText(u.warning.main))),L(u.Alert,"errorStandardBg",F(Ee,u.error.light,.9)),L(u.Alert,"infoStandardBg",F(Ee,u.info.light,.9)),L(u.Alert,"successStandardBg",F(Ee,u.success.light,.9)),L(u.Alert,"warningStandardBg",F(Ee,u.warning.light,.9)),L(u.Alert,"errorIconColor",A("palette-error-main")),L(u.Alert,"infoIconColor",A("palette-info-main")),L(u.Alert,"successIconColor",A("palette-success-main")),L(u.Alert,"warningIconColor",A("palette-warning-main")),L(u.AppBar,"defaultBg",A("palette-grey-100")),L(u.Avatar,"defaultBg",A("palette-grey-400")),L(u.Button,"inheritContainedBg",A("palette-grey-300")),L(u.Button,"inheritContainedHoverBg",A("palette-grey-A100")),L(u.Chip,"defaultBorder",A("palette-grey-400")),L(u.Chip,"defaultAvatarColor",A("palette-grey-700")),L(u.Chip,"defaultIconColor",A("palette-grey-700")),L(u.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),L(u.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),L(u.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),L(u.LinearProgress,"primaryBg",F(Ee,u.primary.main,.62)),L(u.LinearProgress,"secondaryBg",F(Ee,u.secondary.main,.62)),L(u.LinearProgress,"errorBg",F(Ee,u.error.main,.62)),L(u.LinearProgress,"infoBg",F(Ee,u.info.main,.62)),L(u.LinearProgress,"successBg",F(Ee,u.success.main,.62)),L(u.LinearProgress,"warningBg",F(Ee,u.warning.main,.62)),L(u.Skeleton,"bg",T?F(Br,u.text.primary,.11):`rgba(${A("palette-text-primaryChannel")} / 0.11)`),L(u.Slider,"primaryTrack",F(Ee,u.primary.main,.62)),L(u.Slider,"secondaryTrack",F(Ee,u.secondary.main,.62)),L(u.Slider,"errorTrack",F(Ee,u.error.main,.62)),L(u.Slider,"infoTrack",F(Ee,u.info.main,.62)),L(u.Slider,"successTrack",F(Ee,u.success.main,.62)),L(u.Slider,"warningTrack",F(Ee,u.warning.main,.62));const d=T?F(Ie,u.background.default,.6825):Uo(u.background.default,.8);L(u.SnackbarContent,"bg",d),L(u.SnackbarContent,"color",Pt(()=>T?ti.text.primary:u.getContrastText(d))),L(u.SpeedDialAction,"fabHoverBg",Uo(u.background.paper,.15)),L(u.StepConnector,"border",A("palette-grey-400")),L(u.StepContent,"border",A("palette-grey-400")),L(u.Switch,"defaultColor",A("palette-common-white")),L(u.Switch,"defaultDisabledColor",A("palette-grey-100")),L(u.Switch,"primaryDisabledColor",F(Ee,u.primary.main,.62)),L(u.Switch,"secondaryDisabledColor",F(Ee,u.secondary.main,.62)),L(u.Switch,"errorDisabledColor",F(Ee,u.error.main,.62)),L(u.Switch,"infoDisabledColor",F(Ee,u.info.main,.62)),L(u.Switch,"successDisabledColor",F(Ee,u.success.main,.62)),L(u.Switch,"warningDisabledColor",F(Ee,u.warning.main,.62)),L(u.TableCell,"border",F(Ee,F(Br,u.divider,1),.88)),L(u.Tooltip,"bg",F(Br,u.grey[700],.92))}if(u.mode==="dark"){L(u.Alert,"errorColor",F(Ee,u.error.light,.6)),L(u.Alert,"infoColor",F(Ee,u.info.light,.6)),L(u.Alert,"successColor",F(Ee,u.success.light,.6)),L(u.Alert,"warningColor",F(Ee,u.warning.light,.6)),L(u.Alert,"errorFilledBg",A("palette-error-dark")),L(u.Alert,"infoFilledBg",A("palette-info-dark")),L(u.Alert,"successFilledBg",A("palette-success-dark")),L(u.Alert,"warningFilledBg",A("palette-warning-dark")),L(u.Alert,"errorFilledColor",Pt(()=>u.getContrastText(u.error.dark))),L(u.Alert,"infoFilledColor",Pt(()=>u.getContrastText(u.info.dark))),L(u.Alert,"successFilledColor",Pt(()=>u.getContrastText(u.success.dark))),L(u.Alert,"warningFilledColor",Pt(()=>u.getContrastText(u.warning.dark))),L(u.Alert,"errorStandardBg",F(Ie,u.error.light,.9)),L(u.Alert,"infoStandardBg",F(Ie,u.info.light,.9)),L(u.Alert,"successStandardBg",F(Ie,u.success.light,.9)),L(u.Alert,"warningStandardBg",F(Ie,u.warning.light,.9)),L(u.Alert,"errorIconColor",A("palette-error-main")),L(u.Alert,"infoIconColor",A("palette-info-main")),L(u.Alert,"successIconColor",A("palette-success-main")),L(u.Alert,"warningIconColor",A("palette-warning-main")),L(u.AppBar,"defaultBg",A("palette-grey-900")),L(u.AppBar,"darkBg",A("palette-background-paper")),L(u.AppBar,"darkColor",A("palette-text-primary")),L(u.Avatar,"defaultBg",A("palette-grey-600")),L(u.Button,"inheritContainedBg",A("palette-grey-800")),L(u.Button,"inheritContainedHoverBg",A("palette-grey-700")),L(u.Chip,"defaultBorder",A("palette-grey-700")),L(u.Chip,"defaultAvatarColor",A("palette-grey-300")),L(u.Chip,"defaultIconColor",A("palette-grey-300")),L(u.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),L(u.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),L(u.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),L(u.LinearProgress,"primaryBg",F(Ie,u.primary.main,.5)),L(u.LinearProgress,"secondaryBg",F(Ie,u.secondary.main,.5)),L(u.LinearProgress,"errorBg",F(Ie,u.error.main,.5)),L(u.LinearProgress,"infoBg",F(Ie,u.info.main,.5)),L(u.LinearProgress,"successBg",F(Ie,u.success.main,.5)),L(u.LinearProgress,"warningBg",F(Ie,u.warning.main,.5)),L(u.Skeleton,"bg",T?F(Br,u.text.primary,.13):`rgba(${A("palette-text-primaryChannel")} / 0.13)`),L(u.Slider,"primaryTrack",F(Ie,u.primary.main,.5)),L(u.Slider,"secondaryTrack",F(Ie,u.secondary.main,.5)),L(u.Slider,"errorTrack",F(Ie,u.error.main,.5)),L(u.Slider,"infoTrack",F(Ie,u.info.main,.5)),L(u.Slider,"successTrack",F(Ie,u.success.main,.5)),L(u.Slider,"warningTrack",F(Ie,u.warning.main,.5));const d=T?F(Ee,u.background.default,.985):Uo(u.background.default,.98);L(u.SnackbarContent,"bg",d),L(u.SnackbarContent,"color",Pt(()=>T?Hs.text.primary:u.getContrastText(d))),L(u.SpeedDialAction,"fabHoverBg",Uo(u.background.paper,.15)),L(u.StepConnector,"border",A("palette-grey-600")),L(u.StepContent,"border",A("palette-grey-600")),L(u.Switch,"defaultColor",A("palette-grey-300")),L(u.Switch,"defaultDisabledColor",A("palette-grey-600")),L(u.Switch,"primaryDisabledColor",F(Ie,u.primary.main,.55)),L(u.Switch,"secondaryDisabledColor",F(Ie,u.secondary.main,.55)),L(u.Switch,"errorDisabledColor",F(Ie,u.error.main,.55)),L(u.Switch,"infoDisabledColor",F(Ie,u.info.main,.55)),L(u.Switch,"successDisabledColor",F(Ie,u.success.main,.55)),L(u.Switch,"warningDisabledColor",F(Ie,u.warning.main,.55)),L(u.TableCell,"border",F(Ie,F(Br,u.divider,1),.68)),L(u.Tooltip,"bg",F(Br,u.grey[700],.92))}Qt(u.background,"default"),Qt(u.background,"paper"),Qt(u.common,"background"),Qt(u.common,"onBackground"),Qt(u,"divider"),Object.keys(u).forEach(d=>{const ne=u[d];d!=="tonalOffset"&&ne&&typeof ne=="object"&&(ne.main&&L(u[d],"mainChannel",jo(wo(ne.main))),ne.light&&L(u[d],"lightChannel",jo(wo(ne.light))),ne.dark&&L(u[d],"darkChannel",jo(wo(ne.dark))),ne.contrastText&&L(u[d],"contrastTextChannel",jo(wo(ne.contrastText))),d==="text"&&(Qt(u[d],"primary"),Qt(u[d],"secondary")),d==="action"&&(ne.active&&Qt(u[d],"active"),ne.selected&&Qt(u[d],"selected")))})}),P=r.reduce((R,u)=>mt(R,u),P);const _={prefix:a,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:Ud(P),enableContrastVars:c},{vars:M,generateThemeVars:G,generateStyleSheets:q}=fd(P,_);return P.vars=M,Object.entries(P.colorSchemes[P.defaultColorScheme]).forEach(([R,u])=>{P[R]=u}),P.generateThemeVars=G,P.generateStyleSheets=q,P.generateSpacing=function(){return Ns(y.spacing,fi(this))},P.getColorSchemeSelector=md(p),P.spacing=P.generateSpacing(),P.shouldSkipGeneratingVar=l,P.unstable_sxConfig={...bn,...y==null?void 0:y.unstable_sxConfig},P.unstable_sx=function(u){return vn({sx:u,theme:this})},P.toRuntimeSource=Gs,P}function as(e,r,n){e.colorSchemes&&n&&(e.colorSchemes[r]={...n!==!0&&n,palette:gi({...n===!0?{}:n.palette,mode:r})})}function Kd(e={},...r){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:a=n==null?void 0:n.mode,...c}=e,l=a||"light",p=s==null?void 0:s[l],x={...s,...n?{[l]:{...typeof p!="boolean"&&p,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in e))return ri(e,...r);let y=n;"palette"in e||x[l]&&(x[l]!==!0?y=x[l].palette:l==="dark"&&(y={mode:"dark"}));const g=ri({...e,palette:y},...r);return g.defaultColorScheme=l,g.colorSchemes=x,g.palette.mode==="light"&&(g.colorSchemes.light={...x.light!==!0&&x.light,palette:g.palette},as(g,"dark",x.dark)),g.palette.mode==="dark"&&(g.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:g.palette},as(g,"light",x.light)),g}return!n&&!("light"in x)&&l==="light"&&(x.light=!0),Jd({...c,colorSchemes:x,defaultColorScheme:l,...typeof i!="boolean"&&i},...r)}const Xd=Kd();function ct(){const e=rd(Xd);return process.env.NODE_ENV!=="production"&&sn.useDebugValue(e),e[Ul]||e}async function Qd(e,r,n){try{new URL(e)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};r&&(i.Authorization=`Bearer ${r}`);const s=new AbortController,a=setTimeout(()=>s.abort(),3e4);let c;try{c=await fetch(e,{headers:i,signal:s.signal})}catch(x){throw clearTimeout(a),(x==null?void 0:x.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(a)}if(c.status===401)throw new Error("Authentication failed (401) — check your API key");if(!c.ok)throw new Error(`API error ${c.status}: ${c.statusText}`);let l;try{l=await c.json()}catch{throw new Error("Response is not valid JSON")}let p;if(Array.isArray(l))p=l;else if(n&&l[n]&&Array.isArray(l[n]))p=l[n];else{const y=["data","results","items","records"].find(g=>l[g]&&Array.isArray(l[g]));if(y)p=l[y];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:p,source:e,fetchedAt:new Date().toISOString()}}function Zd(e,r){return r.map(n=>`${n.x}px ${n.y}px ${n.blur}px ${n.spread}px ${E(e.palette.common.black,n.opacity)}`).join(", ")}const eu={menu:[{x:0,y:8,blur:16,spread:4,opacity:.12},{x:0,y:4,blur:16,spread:0,opacity:.08},{x:0,y:0,blur:0,spread:1,opacity:.05}],restButton:[{x:0,y:1,blur:2,spread:0,opacity:.3},{x:0,y:1,blur:3,spread:1,opacity:.15}],restButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1},{x:0,y:1,blur:3,spread:1,opacity:.05}],hoverButton:[{x:0,y:1,blur:3,spread:0,opacity:.3},{x:0,y:4,blur:8,spread:3,opacity:.15}],pressedButton:[{x:0,y:1,blur:2,spread:0,opacity:.3}],pressedButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1}],small:[{x:0,y:2,blur:6,spread:0,opacity:.15}],cardRest:[{x:0,y:1,blur:3,spread:0,opacity:.08},{x:0,y:1,blur:2,spread:0,opacity:.06}],cardHover:[{x:0,y:4,blur:16,spread:0,opacity:.15},{x:0,y:1,blur:4,spread:0,opacity:.08}],popover:[{x:0,y:4,blur:20,spread:0,opacity:.15},{x:0,y:1,blur:6,spread:0,opacity:.1}],flatHover:[{x:0,y:1,blur:2,spread:0,opacity:.06}]};function ge(e,r){return Zd(e,eu[r])}function et(e){return`${Number(e.shape.borderRadius)*1.5}px`}function $o(e){return`${Number(e.shape.borderRadius)}px`}function ls(e){const r=e.tokens;return{containerPad:`${(r==null?void 0:r.containerPad)??16}px`,cardGap:`${(r==null?void 0:r.cardGap)??12}px`}}function it(e){const r=e.tokens,n=(r==null?void 0:r.highlight)||e.palette.primary.main;return{main:n,bg:`var(--highlight-bg, ${E(n,.08)})`,hoverBg:`var(--highlight-hover, ${E(n,.12)})`}}function ce(e,r="menu"){const n=e.tokens;return{paper:{boxShadow:(n==null?void 0:n.cardBodyShadow)||ge(e,r),border:n!=null&&n.cardBodyBorder&&n.cardBodyBorder!=="none"?n.cardBodyBorder:"none"},header:{backgroundColor:(n==null?void 0:n.cardHdrBg)||"transparent",borderBottom:(n==null?void 0:n.cardHdrBorder)||"none",boxShadow:(n==null?void 0:n.cardHdrAccent)||"none"}}}function tu({isOpen:e,onClose:r,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[a,c]=f.useState(""),[l,p]=f.useState(!1),[x,y]=f.useState(""),[g,v]=f.useState(null),[S,k]=f.useState(null),[b,m]=f.useState(!1),[z,h]=f.useState(""),B=f.useRef(null),[T,j]=f.useState("json"),[P,_]=f.useState(""),[M,G]=f.useState(""),[q,R]=f.useState(""),[u,A]=f.useState("idle"),[F,d]=f.useState(""),[ne,U]=f.useState(null),[re,xe]=f.useState(0),V=async I=>{if(h(""),!I.name.endsWith(".json")){h("Only .json files are allowed");return}const te=10*1024*1024;if(I.size>te){h("File size exceeds 10MB limit");return}try{const he=await I.text();let se;try{se=JSON.parse(he)}catch{h("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(se)){h("JSON must be an array of objects");return}if(se.length===0){h("No data rows found in JSON file");return}v(I),k(se)}catch{h("Network error — please try again")}},X=I=>{I.preventDefault();const te=I.dataTransfer.files[0];te&&V(te)},ae=async()=>{if(P.trim()){A("loading"),d("");try{const I=await Qd(P.trim(),M.trim()||void 0,q.trim()||void 0);U(I.data),xe(I.data.length),A("ready")}catch(I){d((I==null?void 0:I.message)||"Connection failed"),A("error")}}},le=()=>{if(!a.trim()){p(!0);return}const I=T==="api"?ne:i||S;I&&(n(a.trim(),x.trim(),I),ie())},ie=()=>{c(""),p(!1),y(""),v(null),k(null),h(""),j("json"),_(""),G(""),R(""),A("idle"),d(""),U(null),xe(0),r()},Q=i||S,de=l&&!a.trim();return a.trim(),t.jsxs(t.Fragment,{children:[t.jsxs(o.Dialog,{open:e,onClose:ie,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:I=>({borderRadius:et(I),width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",...ce(I).paper})},children:[t.jsxs(o.DialogTitle,{sx:I=>({display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:te=>te.typography.h6.fontWeight||500,fontSize:te=>te.typography.h6.fontSize||"1.125rem",color:"text.primary",letterSpacing:"-0.01em",...ce(I).header}),children:["Create new report",t.jsx(o.IconButton,{onClick:ie,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsx(o.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[t.jsx(o.TextField,{label:"Report name",required:!0,fullWidth:!0,value:a,onChange:I=>{c(I.target.value),l&&I.target.value.trim()&&p(!1)},placeholder:"Enter report name",autoFocus:!0,error:de,helperText:de?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsx(o.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:x,onChange:I=>y(I.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsxs(o.Tabs,{value:T==="json"?0:1,onChange:(I,te)=>{j(te===0?"json":"api"),A("idle"),d("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40,"& .MuiTabs-indicator":{height:3,bgcolor:"primary.main"}},children:[t.jsx(o.Tab,{label:"Upload JSON",icon:t.jsx($.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5,borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:I=>`var(--highlight-hover, ${E(I.palette.primary.main,.15)})`},"&:hover":{bgcolor:I=>`var(--highlight-hover, ${E(I.palette.primary.main,.08)})`}}}),t.jsx(o.Tab,{label:"Connect API",icon:t.jsx($.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5,borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:I=>`var(--highlight-hover, ${E(I.palette.primary.main,.15)})`},"&:hover":{bgcolor:I=>`var(--highlight-hover, ${E(I.palette.primary.main,.08)})`}}})]}),T==="json"&&t.jsx(o.Box,{children:i?t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:I=>E(I.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:I=>E(I.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),t.jsx(o.IconButton,{size:"small",onClick:()=>m(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:t.jsx($.Info,{sx:{fontSize:16}})})]}),t.jsxs(o.Box,{onDrop:X,onDragOver:I=>I.preventDefault(),onPaste:I=>I.preventDefault(),onClick:()=>{var I;return(I=B.current)==null?void 0:I.click()},sx:{position:"relative",border:"1.5px",borderStyle:S?"solid":"dashed",borderColor:S?"success.main":z?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:S?I=>E(I.palette.success.main,.04):z?I=>E(I.palette.error.main,.04):I=>E(I.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:S?I=>E(I.palette.success.main,.08):z?I=>E(I.palette.error.main,.08):I=>E(I.palette.primary.main,.08),borderColor:S?"success.dark":z?"error.dark":"primary.dark"}},children:[t.jsx(o.Box,{component:"input",ref:B,type:"file",accept:".json",sx:{display:"none"},onChange:I=>{var te;return((te=I.target.files)==null?void 0:te[0])&&V(I.target.files[0])}}),S?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[t.jsx(o.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:I=>E(I.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:t.jsx($.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:g==null?void 0:g.name}),t.jsx(o.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):t.jsxs(o.Box,{children:[t.jsx(o.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:I=>E(I.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:t.jsx($.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),t.jsx(o.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),z&&t.jsx(o.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:I=>E(I.palette.error.main,.08),border:1,borderColor:I=>E(I.palette.error.main,.2)},children:t.jsx(o.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:z})})]})]})]})}),T==="api"&&t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[t.jsx(o.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:P,onChange:I=>{_(I.target.value),A("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsx(o.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:M,onChange:I=>G(I.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:t.jsx(o.InputAdornment,{position:"start",children:t.jsx($.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsx(o.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:q,onChange:I=>R(I.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),t.jsx(o.Button,{variant:"outlined",fullWidth:!0,disabled:!P.trim()||u==="loading",onClick:ae,startIcon:u==="loading"?t.jsx(o.CircularProgress,{size:16,color:"inherit"}):t.jsx($.Api,{}),sx:{fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:I=>E(I.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:u==="loading"?"Connecting...":"Test Connection & Load Data"}),u==="ready"&&t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:I=>E(I.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx($.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),t.jsxs(o.Box,{children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[re.toLocaleString()," records loaded — ready to create"]}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:P})]})]}),u==="error"&&t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:I=>E(I.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx($.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:F})]})]})]})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[t.jsx(o.Button,{onClick:ie,variant:"text",sx:{color:"primary.main",fontSize:"0.875rem",borderRadius:I=>`${I.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:I=>E(I.palette.primary.main,.04)}},children:"Cancel"}),t.jsx(o.Button,{onClick:le,disabled:T==="json"&&!Q||T==="api"&&u!=="ready",variant:"contained",sx:{fontSize:"0.875rem",borderRadius:I=>`${I.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64,"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),t.jsxs(o.Dialog,{open:b,onClose:()=>m(!1),maxWidth:"sm",PaperProps:{sx:I=>({borderRadius:3,width:560,maxHeight:"80vh",...ce(I).paper})},children:[t.jsxs(o.DialogTitle,{sx:I=>({display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em",...ce(I).header}),children:["JSON format guide",t.jsx(o.IconButton,{onClick:()=>m(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{sx:{px:3,py:2},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),t.jsx(o.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),t.jsx(o.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
|
|
171
|
+
To suppress this warning, you need to explicitly provide the \`palette.${r}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function Yd(e){return typeof e=="number"?`${e}px`:typeof e=="string"||typeof e=="function"||Array.isArray(e)?e:"8px"}const Pt=e=>{try{return e()}catch{}},qd=(e="mui")=>ud(e);function Jn(e,r,n,i,s){if(!n)return;n=n===!0?{}:n;const a=s==="dark"?"dark":"light";if(!i){r[s]=Fd({...n,palette:{mode:a,...n==null?void 0:n.palette},colorSpace:e});return}const{palette:c,...l}=ri({...i,palette:{mode:a,...n==null?void 0:n.palette},colorSpace:e});return r[s]={...n,palette:c,opacity:{...Ys(a),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||qs(a)},l}function Jd(e={},...r){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:a="mui",nativeColor:c=!1,shouldSkipGeneratingVar:l=Vd,colorSchemeSelector:p=n.light&&n.dark?"media":void 0,rootSelector:x=":root",...y}=e,g=Object.keys(n)[0],v=i||(n.light&&g!=="light"?"light":g),S=qd(a),{[v]:k,light:b,dark:m,...z}=n,h={...z};let B=k;if((v==="dark"&&!("dark"in n)||v==="light"&&!("light"in n))&&(B=!0),!B)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${v}\` option is either missing or invalid.`:Er(21,v));let T;c&&(T="oklch");const w=Jn(T,h,B,y,v);b&&!h.light&&Jn(T,h,b,void 0,"light"),m&&!h.dark&&Jn(T,h,m,void 0,"dark");let P={defaultColorScheme:v,...w,cssVarPrefix:a,colorSchemeSelector:p,rootSelector:x,getCssVar:S,colorSchemes:h,font:{...wd(w.typography),...w.font},spacing:Yd(y.spacing)};Object.keys(P.colorSchemes).forEach(R=>{const u=P.colorSchemes[R].palette,A=d=>{const ne=d.split("-"),U=ne[1],re=ne[2];return S(d,u[U][re])};u.mode==="light"&&(L(u.common,"background","#fff"),L(u.common,"onBackground","#000")),u.mode==="dark"&&(L(u.common,"background","#000"),L(u.common,"onBackground","#fff"));function F(d,ne,U){if(T){let re;return d===Br&&(re=`transparent ${((1-U)*100).toFixed(0)}%`),d===Ie&&(re=`#000 ${(U*100).toFixed(0)}%`),d===Ee&&(re=`#fff ${(U*100).toFixed(0)}%`),`color-mix(in ${T}, ${ne}, ${re})`}return d(ne,U)}if(Gd(u,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),u.mode==="light"){L(u.Alert,"errorColor",F(Ie,u.error.light,.6)),L(u.Alert,"infoColor",F(Ie,u.info.light,.6)),L(u.Alert,"successColor",F(Ie,u.success.light,.6)),L(u.Alert,"warningColor",F(Ie,u.warning.light,.6)),L(u.Alert,"errorFilledBg",A("palette-error-main")),L(u.Alert,"infoFilledBg",A("palette-info-main")),L(u.Alert,"successFilledBg",A("palette-success-main")),L(u.Alert,"warningFilledBg",A("palette-warning-main")),L(u.Alert,"errorFilledColor",Pt(()=>u.getContrastText(u.error.main))),L(u.Alert,"infoFilledColor",Pt(()=>u.getContrastText(u.info.main))),L(u.Alert,"successFilledColor",Pt(()=>u.getContrastText(u.success.main))),L(u.Alert,"warningFilledColor",Pt(()=>u.getContrastText(u.warning.main))),L(u.Alert,"errorStandardBg",F(Ee,u.error.light,.9)),L(u.Alert,"infoStandardBg",F(Ee,u.info.light,.9)),L(u.Alert,"successStandardBg",F(Ee,u.success.light,.9)),L(u.Alert,"warningStandardBg",F(Ee,u.warning.light,.9)),L(u.Alert,"errorIconColor",A("palette-error-main")),L(u.Alert,"infoIconColor",A("palette-info-main")),L(u.Alert,"successIconColor",A("palette-success-main")),L(u.Alert,"warningIconColor",A("palette-warning-main")),L(u.AppBar,"defaultBg",A("palette-grey-100")),L(u.Avatar,"defaultBg",A("palette-grey-400")),L(u.Button,"inheritContainedBg",A("palette-grey-300")),L(u.Button,"inheritContainedHoverBg",A("palette-grey-A100")),L(u.Chip,"defaultBorder",A("palette-grey-400")),L(u.Chip,"defaultAvatarColor",A("palette-grey-700")),L(u.Chip,"defaultIconColor",A("palette-grey-700")),L(u.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),L(u.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),L(u.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),L(u.LinearProgress,"primaryBg",F(Ee,u.primary.main,.62)),L(u.LinearProgress,"secondaryBg",F(Ee,u.secondary.main,.62)),L(u.LinearProgress,"errorBg",F(Ee,u.error.main,.62)),L(u.LinearProgress,"infoBg",F(Ee,u.info.main,.62)),L(u.LinearProgress,"successBg",F(Ee,u.success.main,.62)),L(u.LinearProgress,"warningBg",F(Ee,u.warning.main,.62)),L(u.Skeleton,"bg",T?F(Br,u.text.primary,.11):`rgba(${A("palette-text-primaryChannel")} / 0.11)`),L(u.Slider,"primaryTrack",F(Ee,u.primary.main,.62)),L(u.Slider,"secondaryTrack",F(Ee,u.secondary.main,.62)),L(u.Slider,"errorTrack",F(Ee,u.error.main,.62)),L(u.Slider,"infoTrack",F(Ee,u.info.main,.62)),L(u.Slider,"successTrack",F(Ee,u.success.main,.62)),L(u.Slider,"warningTrack",F(Ee,u.warning.main,.62));const d=T?F(Ie,u.background.default,.6825):Uo(u.background.default,.8);L(u.SnackbarContent,"bg",d),L(u.SnackbarContent,"color",Pt(()=>T?ti.text.primary:u.getContrastText(d))),L(u.SpeedDialAction,"fabHoverBg",Uo(u.background.paper,.15)),L(u.StepConnector,"border",A("palette-grey-400")),L(u.StepContent,"border",A("palette-grey-400")),L(u.Switch,"defaultColor",A("palette-common-white")),L(u.Switch,"defaultDisabledColor",A("palette-grey-100")),L(u.Switch,"primaryDisabledColor",F(Ee,u.primary.main,.62)),L(u.Switch,"secondaryDisabledColor",F(Ee,u.secondary.main,.62)),L(u.Switch,"errorDisabledColor",F(Ee,u.error.main,.62)),L(u.Switch,"infoDisabledColor",F(Ee,u.info.main,.62)),L(u.Switch,"successDisabledColor",F(Ee,u.success.main,.62)),L(u.Switch,"warningDisabledColor",F(Ee,u.warning.main,.62)),L(u.TableCell,"border",F(Ee,F(Br,u.divider,1),.88)),L(u.Tooltip,"bg",F(Br,u.grey[700],.92))}if(u.mode==="dark"){L(u.Alert,"errorColor",F(Ee,u.error.light,.6)),L(u.Alert,"infoColor",F(Ee,u.info.light,.6)),L(u.Alert,"successColor",F(Ee,u.success.light,.6)),L(u.Alert,"warningColor",F(Ee,u.warning.light,.6)),L(u.Alert,"errorFilledBg",A("palette-error-dark")),L(u.Alert,"infoFilledBg",A("palette-info-dark")),L(u.Alert,"successFilledBg",A("palette-success-dark")),L(u.Alert,"warningFilledBg",A("palette-warning-dark")),L(u.Alert,"errorFilledColor",Pt(()=>u.getContrastText(u.error.dark))),L(u.Alert,"infoFilledColor",Pt(()=>u.getContrastText(u.info.dark))),L(u.Alert,"successFilledColor",Pt(()=>u.getContrastText(u.success.dark))),L(u.Alert,"warningFilledColor",Pt(()=>u.getContrastText(u.warning.dark))),L(u.Alert,"errorStandardBg",F(Ie,u.error.light,.9)),L(u.Alert,"infoStandardBg",F(Ie,u.info.light,.9)),L(u.Alert,"successStandardBg",F(Ie,u.success.light,.9)),L(u.Alert,"warningStandardBg",F(Ie,u.warning.light,.9)),L(u.Alert,"errorIconColor",A("palette-error-main")),L(u.Alert,"infoIconColor",A("palette-info-main")),L(u.Alert,"successIconColor",A("palette-success-main")),L(u.Alert,"warningIconColor",A("palette-warning-main")),L(u.AppBar,"defaultBg",A("palette-grey-900")),L(u.AppBar,"darkBg",A("palette-background-paper")),L(u.AppBar,"darkColor",A("palette-text-primary")),L(u.Avatar,"defaultBg",A("palette-grey-600")),L(u.Button,"inheritContainedBg",A("palette-grey-800")),L(u.Button,"inheritContainedHoverBg",A("palette-grey-700")),L(u.Chip,"defaultBorder",A("palette-grey-700")),L(u.Chip,"defaultAvatarColor",A("palette-grey-300")),L(u.Chip,"defaultIconColor",A("palette-grey-300")),L(u.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),L(u.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),L(u.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),L(u.LinearProgress,"primaryBg",F(Ie,u.primary.main,.5)),L(u.LinearProgress,"secondaryBg",F(Ie,u.secondary.main,.5)),L(u.LinearProgress,"errorBg",F(Ie,u.error.main,.5)),L(u.LinearProgress,"infoBg",F(Ie,u.info.main,.5)),L(u.LinearProgress,"successBg",F(Ie,u.success.main,.5)),L(u.LinearProgress,"warningBg",F(Ie,u.warning.main,.5)),L(u.Skeleton,"bg",T?F(Br,u.text.primary,.13):`rgba(${A("palette-text-primaryChannel")} / 0.13)`),L(u.Slider,"primaryTrack",F(Ie,u.primary.main,.5)),L(u.Slider,"secondaryTrack",F(Ie,u.secondary.main,.5)),L(u.Slider,"errorTrack",F(Ie,u.error.main,.5)),L(u.Slider,"infoTrack",F(Ie,u.info.main,.5)),L(u.Slider,"successTrack",F(Ie,u.success.main,.5)),L(u.Slider,"warningTrack",F(Ie,u.warning.main,.5));const d=T?F(Ee,u.background.default,.985):Uo(u.background.default,.98);L(u.SnackbarContent,"bg",d),L(u.SnackbarContent,"color",Pt(()=>T?Hs.text.primary:u.getContrastText(d))),L(u.SpeedDialAction,"fabHoverBg",Uo(u.background.paper,.15)),L(u.StepConnector,"border",A("palette-grey-600")),L(u.StepContent,"border",A("palette-grey-600")),L(u.Switch,"defaultColor",A("palette-grey-300")),L(u.Switch,"defaultDisabledColor",A("palette-grey-600")),L(u.Switch,"primaryDisabledColor",F(Ie,u.primary.main,.55)),L(u.Switch,"secondaryDisabledColor",F(Ie,u.secondary.main,.55)),L(u.Switch,"errorDisabledColor",F(Ie,u.error.main,.55)),L(u.Switch,"infoDisabledColor",F(Ie,u.info.main,.55)),L(u.Switch,"successDisabledColor",F(Ie,u.success.main,.55)),L(u.Switch,"warningDisabledColor",F(Ie,u.warning.main,.55)),L(u.TableCell,"border",F(Ie,F(Br,u.divider,1),.68)),L(u.Tooltip,"bg",F(Br,u.grey[700],.92))}Qt(u.background,"default"),Qt(u.background,"paper"),Qt(u.common,"background"),Qt(u.common,"onBackground"),Qt(u,"divider"),Object.keys(u).forEach(d=>{const ne=u[d];d!=="tonalOffset"&&ne&&typeof ne=="object"&&(ne.main&&L(u[d],"mainChannel",jo(wo(ne.main))),ne.light&&L(u[d],"lightChannel",jo(wo(ne.light))),ne.dark&&L(u[d],"darkChannel",jo(wo(ne.dark))),ne.contrastText&&L(u[d],"contrastTextChannel",jo(wo(ne.contrastText))),d==="text"&&(Qt(u[d],"primary"),Qt(u[d],"secondary")),d==="action"&&(ne.active&&Qt(u[d],"active"),ne.selected&&Qt(u[d],"selected")))})}),P=r.reduce((R,u)=>mt(R,u),P);const O={prefix:a,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:Ud(P),enableContrastVars:c},{vars:M,generateThemeVars:Y,generateStyleSheets:J}=fd(P,O);return P.vars=M,Object.entries(P.colorSchemes[P.defaultColorScheme]).forEach(([R,u])=>{P[R]=u}),P.generateThemeVars=Y,P.generateStyleSheets=J,P.generateSpacing=function(){return Ns(y.spacing,fi(this))},P.getColorSchemeSelector=md(p),P.spacing=P.generateSpacing(),P.shouldSkipGeneratingVar=l,P.unstable_sxConfig={...bn,...y==null?void 0:y.unstable_sxConfig},P.unstable_sx=function(u){return vn({sx:u,theme:this})},P.toRuntimeSource=Gs,P}function as(e,r,n){e.colorSchemes&&n&&(e.colorSchemes[r]={...n!==!0&&n,palette:gi({...n===!0?{}:n.palette,mode:r})})}function Kd(e={},...r){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:a=n==null?void 0:n.mode,...c}=e,l=a||"light",p=s==null?void 0:s[l],x={...s,...n?{[l]:{...typeof p!="boolean"&&p,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in e))return ri(e,...r);let y=n;"palette"in e||x[l]&&(x[l]!==!0?y=x[l].palette:l==="dark"&&(y={mode:"dark"}));const g=ri({...e,palette:y},...r);return g.defaultColorScheme=l,g.colorSchemes=x,g.palette.mode==="light"&&(g.colorSchemes.light={...x.light!==!0&&x.light,palette:g.palette},as(g,"dark",x.dark)),g.palette.mode==="dark"&&(g.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:g.palette},as(g,"light",x.light)),g}return!n&&!("light"in x)&&l==="light"&&(x.light=!0),Jd({...c,colorSchemes:x,defaultColorScheme:l,...typeof i!="boolean"&&i},...r)}const Xd=Kd();function ct(){const e=rd(Xd);return process.env.NODE_ENV!=="production"&&sn.useDebugValue(e),e[Ul]||e}async function Qd(e,r,n){try{new URL(e)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};r&&(i.Authorization=`Bearer ${r}`);const s=new AbortController,a=setTimeout(()=>s.abort(),3e4);let c;try{c=await fetch(e,{headers:i,signal:s.signal})}catch(x){throw clearTimeout(a),(x==null?void 0:x.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(a)}if(c.status===401)throw new Error("Authentication failed (401) — check your API key");if(!c.ok)throw new Error(`API error ${c.status}: ${c.statusText}`);let l;try{l=await c.json()}catch{throw new Error("Response is not valid JSON")}let p;if(Array.isArray(l))p=l;else if(n&&l[n]&&Array.isArray(l[n]))p=l[n];else{const y=["data","results","items","records"].find(g=>l[g]&&Array.isArray(l[g]));if(y)p=l[y];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:p,source:e,fetchedAt:new Date().toISOString()}}function Zd(e,r){return r.map(n=>`${n.x}px ${n.y}px ${n.blur}px ${n.spread}px ${D(e.palette.common.black,n.opacity)}`).join(", ")}const eu={menu:[{x:0,y:8,blur:16,spread:4,opacity:.12},{x:0,y:4,blur:16,spread:0,opacity:.08},{x:0,y:0,blur:0,spread:1,opacity:.05}],restButton:[{x:0,y:1,blur:2,spread:0,opacity:.3},{x:0,y:1,blur:3,spread:1,opacity:.15}],restButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1},{x:0,y:1,blur:3,spread:1,opacity:.05}],hoverButton:[{x:0,y:1,blur:3,spread:0,opacity:.3},{x:0,y:4,blur:8,spread:3,opacity:.15}],pressedButton:[{x:0,y:1,blur:2,spread:0,opacity:.3}],pressedButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1}],small:[{x:0,y:2,blur:6,spread:0,opacity:.15}],cardRest:[{x:0,y:1,blur:3,spread:0,opacity:.08},{x:0,y:1,blur:2,spread:0,opacity:.06}],cardHover:[{x:0,y:4,blur:16,spread:0,opacity:.15},{x:0,y:1,blur:4,spread:0,opacity:.08}],popover:[{x:0,y:4,blur:20,spread:0,opacity:.15},{x:0,y:1,blur:6,spread:0,opacity:.1}],flatHover:[{x:0,y:1,blur:2,spread:0,opacity:.06}]};function ye(e,r){return Zd(e,eu[r])}function tt(e){return`${Number(e.shape.borderRadius)*1.5}px`}function $o(e){return`${Number(e.shape.borderRadius)}px`}function ls(e){const r=e.tokens;return{containerPad:`${(r==null?void 0:r.containerPad)??16}px`,cardGap:`${(r==null?void 0:r.cardGap)??12}px`}}function it(e){const r=e.tokens,n=(r==null?void 0:r.highlight)||e.palette.primary.main;return{main:n,bg:`var(--highlight-bg, ${D(n,.08)})`,hoverBg:`var(--highlight-hover, ${D(n,.12)})`}}function ue(e,r="menu"){const n=e.tokens;return{paper:{boxShadow:(n==null?void 0:n.cardBodyShadow)||ye(e,r),border:n!=null&&n.cardBodyBorder&&n.cardBodyBorder!=="none"?n.cardBodyBorder:"none"},header:{backgroundColor:(n==null?void 0:n.cardHdrBg)||"transparent",borderBottom:(n==null?void 0:n.cardHdrBorder)||"none",boxShadow:(n==null?void 0:n.cardHdrAccent)||"none"}}}function tu({isOpen:e,onClose:r,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[a,c]=f.useState(""),[l,p]=f.useState(!1),[x,y]=f.useState(""),[g,v]=f.useState(null),[S,k]=f.useState(null),[b,m]=f.useState(!1),[z,h]=f.useState(""),B=f.useRef(null),[T,w]=f.useState("json"),[P,O]=f.useState(""),[M,Y]=f.useState(""),[J,R]=f.useState(""),[u,A]=f.useState("idle"),[F,d]=f.useState(""),[ne,U]=f.useState(null),[re,ge]=f.useState(0),V=async I=>{if(h(""),!I.name.endsWith(".json")){h("Only .json files are allowed");return}const te=10*1024*1024;if(I.size>te){h("File size exceeds 10MB limit");return}try{const fe=await I.text();let ae;try{ae=JSON.parse(fe)}catch{h("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ae)){h("JSON must be an array of objects");return}if(ae.length===0){h("No data rows found in JSON file");return}v(I),k(ae)}catch{h("Network error — please try again")}},X=I=>{I.preventDefault();const te=I.dataTransfer.files[0];te&&V(te)},ce=async()=>{if(P.trim()){A("loading"),d("");try{const I=await Qd(P.trim(),M.trim()||void 0,J.trim()||void 0);U(I.data),ge(I.data.length),A("ready")}catch(I){d((I==null?void 0:I.message)||"Connection failed"),A("error")}}},de=()=>{if(!a.trim()){p(!0);return}const I=T==="api"?ne:i||S;I&&(n(a.trim(),x.trim(),I),ie())},ie=()=>{c(""),p(!1),y(""),v(null),k(null),h(""),w("json"),O(""),Y(""),R(""),A("idle"),d(""),U(null),ge(0),r()},Q=i||S,pe=l&&!a.trim();return a.trim(),t.jsxs(t.Fragment,{children:[t.jsxs(o.Dialog,{open:e,onClose:ie,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:I=>({borderRadius:tt(I),width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",...ue(I).paper})},children:[t.jsxs(o.DialogTitle,{sx:I=>({display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:te=>te.typography.h6.fontWeight||500,fontSize:te=>te.typography.h6.fontSize||"1.125rem",color:"text.primary",letterSpacing:"-0.01em",...ue(I).header}),children:["Create new report",t.jsx(o.IconButton,{onClick:ie,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsx(o.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[t.jsx(o.TextField,{label:"Report name",required:!0,fullWidth:!0,value:a,onChange:I=>{c(I.target.value),l&&I.target.value.trim()&&p(!1)},placeholder:"Enter report name",autoFocus:!0,error:pe,helperText:pe?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsx(o.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:x,onChange:I=>y(I.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsxs(o.Tabs,{value:T==="json"?0:1,onChange:(I,te)=>{w(te===0?"json":"api"),A("idle"),d("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40,"& .MuiTabs-indicator":{height:3,bgcolor:"primary.main"}},children:[t.jsx(o.Tab,{label:"Upload JSON",icon:t.jsx($.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5,borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:I=>`var(--highlight-hover, ${D(I.palette.primary.main,.15)})`},"&:hover":{bgcolor:I=>`var(--highlight-hover, ${D(I.palette.primary.main,.08)})`}}}),t.jsx(o.Tab,{label:"Connect API",icon:t.jsx($.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5,borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:I=>`var(--highlight-hover, ${D(I.palette.primary.main,.15)})`},"&:hover":{bgcolor:I=>`var(--highlight-hover, ${D(I.palette.primary.main,.08)})`}}})]}),T==="json"&&t.jsx(o.Box,{children:i?t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:I=>D(I.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:I=>D(I.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),t.jsx(o.IconButton,{size:"small",onClick:()=>m(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:t.jsx($.Info,{sx:{fontSize:16}})})]}),t.jsxs(o.Box,{onDrop:X,onDragOver:I=>I.preventDefault(),onPaste:I=>I.preventDefault(),onClick:()=>{var I;return(I=B.current)==null?void 0:I.click()},sx:{position:"relative",border:"1.5px",borderStyle:S?"solid":"dashed",borderColor:S?"success.main":z?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:S?I=>D(I.palette.success.main,.04):z?I=>D(I.palette.error.main,.04):I=>D(I.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:S?I=>D(I.palette.success.main,.08):z?I=>D(I.palette.error.main,.08):I=>D(I.palette.primary.main,.08),borderColor:S?"success.dark":z?"error.dark":"primary.dark"}},children:[t.jsx(o.Box,{component:"input",ref:B,type:"file",accept:".json",sx:{display:"none"},onChange:I=>{var te;return((te=I.target.files)==null?void 0:te[0])&&V(I.target.files[0])}}),S?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[t.jsx(o.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:I=>D(I.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:t.jsx($.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:g==null?void 0:g.name}),t.jsx(o.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):t.jsxs(o.Box,{children:[t.jsx(o.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:I=>D(I.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:t.jsx($.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),t.jsx(o.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),z&&t.jsx(o.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:I=>D(I.palette.error.main,.08),border:1,borderColor:I=>D(I.palette.error.main,.2)},children:t.jsx(o.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:z})})]})]})]})}),T==="api"&&t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[t.jsx(o.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:P,onChange:I=>{O(I.target.value),A("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsx(o.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:M,onChange:I=>Y(I.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:t.jsx(o.InputAdornment,{position:"start",children:t.jsx($.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),t.jsx(o.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:J,onChange:I=>R(I.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),t.jsx(o.Button,{variant:"outlined",fullWidth:!0,disabled:!P.trim()||u==="loading",onClick:ce,startIcon:u==="loading"?t.jsx(o.CircularProgress,{size:16,color:"inherit"}):t.jsx($.Api,{}),sx:{fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:I=>D(I.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:u==="loading"?"Connecting...":"Test Connection & Load Data"}),u==="ready"&&t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:I=>D(I.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx($.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),t.jsxs(o.Box,{children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[re.toLocaleString()," records loaded — ready to create"]}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:P})]})]}),u==="error"&&t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:I=>D(I.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx($.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:F})]})]})]})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[t.jsx(o.Button,{onClick:ie,variant:"text",sx:{color:"primary.main",fontSize:"0.875rem",borderRadius:I=>`${I.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:I=>D(I.palette.primary.main,.04)}},children:"Cancel"}),t.jsx(o.Button,{onClick:de,disabled:T==="json"&&!Q||T==="api"&&u!=="ready",variant:"contained",sx:{fontSize:"0.875rem",borderRadius:I=>`${I.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64,"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),t.jsxs(o.Dialog,{open:b,onClose:()=>m(!1),maxWidth:"sm",PaperProps:{sx:I=>({borderRadius:3,width:560,maxHeight:"80vh",...ue(I).paper})},children:[t.jsxs(o.DialogTitle,{sx:I=>({display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em",...ue(I).header}),children:["JSON format guide",t.jsx(o.IconButton,{onClick:()=>m(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{sx:{px:3,py:2},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),t.jsx(o.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),t.jsx(o.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
|
|
172
172
|
{
|
|
173
173
|
"id": 1,
|
|
174
174
|
"customerName": "John Smith",
|
|
@@ -178,7 +178,7 @@ To suppress this warning, you need to explicitly provide the \`palette.${r}Chann
|
|
|
178
178
|
"memberSince": "2024-01-15",
|
|
179
179
|
"status": "active"
|
|
180
180
|
}
|
|
181
|
-
]`})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),t.jsx(o.DialogActions,{sx:{px:3,py:2},children:t.jsx(o.Button,{onClick:()=>m(!1),variant:"contained",sx:{fontSize:"0.875rem",borderRadius:I=>`${I.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64},children:"Got it"})})]})]})}function Js({isOpen:e,onClose:r}){return e?t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"md",fullWidth:!0,PaperProps:{sx:n=>({borderRadius:
|
|
181
|
+
]`})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),t.jsx(o.DialogActions,{sx:{px:3,py:2},children:t.jsx(o.Button,{onClick:()=>m(!1),variant:"contained",sx:{fontSize:"0.875rem",borderRadius:I=>`${I.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64},children:"Got it"})})]})]})}function Js({isOpen:e,onClose:r}){return e?t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"md",fullWidth:!0,PaperProps:{sx:n=>({borderRadius:tt(n),maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",...ue(n).paper})},children:[t.jsxs(o.DialogTitle,{sx:n=>({display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,...ue(n).header}),children:["JSON Format Guide",t.jsx(o.IconButton,{onClick:r,size:"small",sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{dividers:!0,sx:{overflowY:"auto",flex:1},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:3,py:1},children:[t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Expected JSON Structure"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["The uploaded JSON must be an ",t.jsx("strong",{children:"array of objects"}),". Each object represents a single row in your report, and the keys of each object become the column names."]})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Example JSON"}),t.jsx(o.Paper,{elevation:0,sx:{p:2,bgcolor:"action.hover",border:1,borderColor:"divider",borderRadius:1,overflowX:"auto"},children:t.jsx(o.Box,{component:"pre",sx:{fontSize:"caption.fontSize",fontFamily:"monospace",m:0},children:`[
|
|
182
182
|
{
|
|
183
183
|
"Active Sessions": 33,
|
|
184
184
|
"Active State": true,
|
|
@@ -188,10 +188,10 @@ To suppress this warning, you need to explicitly provide the \`palette.${r}Chann
|
|
|
188
188
|
"Region": "Europe",
|
|
189
189
|
"Subscription Type": "Basic"
|
|
190
190
|
}
|
|
191
|
-
]`})})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Supported Column Types"}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"The system automatically detects column types from your data:"}),t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"Number:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["Numeric values (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"33"}),","," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"42.5"}),")"]})]}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"Boolean:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["True/false values (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"true"}),","," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"false"}),")"]})]}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"String:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["Text values (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Europe"'}),","," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Analytics Pro"'}),")"]})]}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"Date:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["ISO date strings (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"2024-08-22"'}),")"]})]})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Notes"}),t.jsxs(o.Box,{component:"ul",sx:{m:0,pl:2.5,"& li":{fontSize:"body2.fontSize",color:"text.secondary",mb:.5}},children:[t.jsx("li",{children:"Each object in the array represents one row in the report."}),t.jsx("li",{children:"The keys of the JSON objects become report columns."}),t.jsx("li",{children:"All objects should have consistent keys for proper column detection."}),t.jsx("li",{children:"Column names are case-sensitive and preserve spacing."})]})]})]})}),t.jsx(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:t.jsx(o.Button,{onClick:r,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:n=>`${n.shape.borderRadius}px`,boxShadow:n=>ge(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>ge(n,"hoverButton")},"&:active":{boxShadow:n=>ge(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function ru({onFileUpload:e,onError:r,isUploading:n}){const[i,s]=f.useState(!1),[a,c]=f.useState(""),[l,p]=f.useState(!1),x=f.useRef(null),y=async z=>{if(!z.name.endsWith(".json")){r("Only .json files are allowed");return}const h=10*1024*1024;if(z.size>h){r("File size exceeds 10MB limit");return}c(z.name);try{const B=await z.text();let T;try{T=JSON.parse(B)}catch{r("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(T)){r("JSON must be an array of objects");return}if(T.length===0){r("No data rows found in JSON file");return}e(T)}catch{r("Network error — please try again")}finally{c("")}},g=z=>{z.preventDefault(),s(!0)},v=z=>{z.preventDefault(),s(!1)},S=z=>{z.preventDefault(),s(!1);const h=z.dataTransfer.files[0];h&&y(h)},k=()=>{var z;(z=x.current)==null||z.click()},b=z=>{var B;const h=(B=z.target.files)==null?void 0:B[0];h&&y(h)},m=z=>{z.stopPropagation(),p(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{onDragOver:g,onDragLeave:v,onDrop:S,onPaste:z=>z.preventDefault(),onClick:k,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?z=>E(z.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[t.jsx(o.Box,{component:"input",ref:x,type:"file",accept:".json",onChange:b,sx:{display:"none"}}),n?t.jsxs(t.Fragment,{children:[t.jsx(o.CircularProgress,{size:32,sx:{mb:2}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:z=>z.typography.body2.fontWeight||500,fontSize:z=>z.typography.body2.fontSize||"0.875rem",mb:.5},children:"Uploading..."}),a&&t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:a})]}):t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:z=>E(z.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.UploadFile,{sx:{fontSize:32,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:1.5},children:[t.jsx(o.Button,{variant:"contained",sx:{fontWeight:500},children:"Upload Data (JSON)"}),t.jsx(o.IconButton,{onClick:m,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:t.jsx($.InfoOutlined,{sx:{fontSize:16}})})]}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",maxWidth:500},children:"Upload structured JSON data to generate your report."}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1},children:"Click to browse or drag and drop a JSON file here"})]})]}),t.jsx(Js,{isOpen:l,onClose:()=>p(!1)})]})}function ou({schema:e,onConfirm:r,hasConflicts:n}){return t.jsxs(o.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[t.jsxs(o.Box,{sx:{mb:2},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontWeight:i=>i.typography.h6.fontWeight||600,fontSize:i=>i.typography.h6.fontSize||"1.25rem",mb:.5},children:"Schema Preview"}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&t.jsxs(o.Alert,{severity:"warning",sx:{mb:2},children:[t.jsx(o.AlertTitle,{sx:{fontWeight:i=>i.typography.h6.fontWeight||600,fontSize:i=>i.typography.subtitle2.fontSize||"0.875rem"},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),t.jsx(o.TableContainer,{sx:{mb:3},children:t.jsxs(o.Table,{children:[t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{sx:{bgcolor:"action.hover"},children:[t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),t.jsx(o.TableBody,{children:e.map(i=>t.jsxs(o.TableRow,{sx:{bgcolor:i.hasConflict?s=>E(s.palette.warning.main,.12):"transparent"},children:[t.jsxs(o.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&t.jsx(o.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),t.jsx(o.TableCell,{children:t.jsx(o.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),t.jsx(o.TableCell,{children:t.jsx(o.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx($.Lock,{sx:{fontSize:16}}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"Schema will be locked for this report"})]}),t.jsx(o.Button,{variant:"contained",onClick:r,disabled:n,sx:{fontWeight:500},children:"Generate Table"})]})]})}function nu({error:e,onRetry:r}){return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderColor:"error.light",bgcolor:n=>E(n.palette.error.main,.12),borderRadius:1,px:2,py:6},children:[t.jsx(o.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:n=>E(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.ErrorOutline,{color:"error",sx:{fontSize:32}})}),t.jsx(o.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:n=>n.typography.h6.fontWeight||600,fontSize:n=>n.typography.h6.fontSize||"1.25rem",mb:1},children:"Upload Failed"}),t.jsx(o.Typography,{variant:"body2",color:"error.main",sx:{textAlign:"center",maxWidth:500,mb:3},children:e}),t.jsx(o.Button,{variant:"contained",color:"error",startIcon:t.jsx($.Upload,{sx:{fontSize:16}}),onClick:r,sx:{fontWeight:500},children:"Try Again"})]})}function Ks({title:e,description:r,showIcon:n=!0}){return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",px:3,py:8},children:[n&&t.jsx(o.Box,{sx:{width:80,height:80,borderRadius:"50%",bgcolor:i=>E(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:t.jsx($.Description,{sx:{fontSize:36,color:"primary.main"}})}),t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:i=>i.typography.h5.fontWeight||500,mb:1,color:i=>i.typography.h5.color||"text.primary",fontSize:i=>i.typography.h5.fontSize||"1.125rem"},children:e}),t.jsx(o.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:i=>i.typography.body2.fontSize||"0.875rem",lineHeight:1.5},children:r})]})}function iu({value:e,onChange:r,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:a,disabled:c}){const[l,p]=f.useState(!1),[x,y]=f.useState(!1),[g,v]=f.useState(-1),S=f.useRef(null),k=f.useRef(null);f.useEffect(()=>{function M(G){S.current&&!S.current.contains(G.target)&&(p(!1),y(!1))}return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]);const b=f.useCallback(()=>{y(!0),v(-1),n.length>0&&p(!0)},[n.length]),m=f.useCallback(M=>{r(M),v(-1)},[r]),z=f.useCallback(M=>{var G;r(M),i(M),p(!1),(G=k.current)==null||G.blur()},[r,i]),h=f.useCallback(M=>{v(-1),z(M)},[z]),B=f.useCallback(M=>{var G;M.key==="Enter"?g>=0&&g<n.length?(M.preventDefault(),h(n[g].query)):e.trim()&&z(e.trim()):M.key==="Escape"?(p(!1),v(-1),(G=k.current)==null||G.blur()):M.key==="ArrowDown"?(M.preventDefault(),n.length>0&&(l||p(!0),v(q=>q<n.length-1?q+1:q))):M.key==="ArrowUp"&&(M.preventDefault(),v(q=>q>0?q-1:-1))},[g,n,e,l,h,z]),T=f.useCallback(()=>{var M;r(""),(M=k.current)==null||M.focus()},[r]),j=f.useMemo(()=>n.filter(M=>M.isFavourite),[n]),P=f.useMemo(()=>n.filter(M=>!M.isFavourite),[n]),_=l&&n.length>0;return t.jsxs(o.Box,{sx:{position:"relative",width:240},ref:S,children:[t.jsx(o.TextField,{inputRef:k,size:"small",fullWidth:!0,value:e,onChange:M=>m(M.target.value),onFocus:b,onKeyDown:B,placeholder:"Search data...",disabled:c,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:M=>E(M.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:M=>E(M.palette.text.primary,.5)},"&.Mui-focused":{bgcolor:"background.paper"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px",color:"text.primary"}},InputProps:{startAdornment:t.jsx(o.InputAdornment,{position:"start",sx:{ml:.5},children:t.jsx($.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:e?t.jsx(o.InputAdornment,{position:"end",children:t.jsx(o.IconButton,{size:"small",onClick:T,edge:"end",sx:{mr:-.5},children:t.jsx($.Close,{sx:{fontSize:16}})})}):null}}),_&&t.jsxs(o.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[j.length>0&&t.jsxs(o.Box,{sx:{py:1},children:[t.jsx(o.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:M=>M.typography.caption.fontWeight||600,fontSize:M=>M.typography.caption.fontSize||"0.75rem",textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),j.map((M,G)=>t.jsx(cs,{entry:M,isSelected:g===G,onClick:()=>h(M.query),onToggleFavourite:()=>s(M.query),onDelete:()=>a(M.query)},`fav-${M.query}`))]}),P.length>0&&t.jsxs(o.Box,{sx:{py:1},children:[j.length>0&&t.jsx(o.Divider,{}),t.jsx(o.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:M=>M.typography.caption.fontWeight||600,fontSize:M=>M.typography.caption.fontSize||"0.75rem",textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),P.map((M,G)=>{const q=j.length+G;return t.jsx(cs,{entry:M,isSelected:g===q,onClick:()=>h(M.query),onToggleFavourite:()=>s(M.query),onDelete:()=>a(M.query)},`recent-${M.query}`)})]})]})]})}const cs=f.memo(function({entry:r,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:a}){const c=f.useCallback(p=>{p.stopPropagation(),s()},[s]),l=f.useCallback(p=>{p.stopPropagation(),a()},[a]);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?p=>E(p.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?p=>E(p.palette.primary.main,.12):"action.hover"}},children:[t.jsx(o.Box,{sx:{flex:1,minWidth:0},onClick:i,children:t.jsx(o.Typography,{variant:"body2",noWrap:!0,children:r.query})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[t.jsx(o.IconButton,{size:"small",onClick:c,title:r.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:r.isFavourite?t.jsx($.Star,{sx:{fontSize:14,color:"warning.light"}}):t.jsx($.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),t.jsx(o.IconButton,{size:"small",onClick:l,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:t.jsx($.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function su({views:e,activeViewId:r,isDirty:n,onSelectView:i,onCreateView:s,onToggleDefault:a,onToggleFavorite:c,onRestoreView:l,onPermanentDelete:p,onEditView:x,onCloneView:y,onCopyLink:g,onDeleteView:v,onPromoteToGlobal:S,isReadOnly:k,isAdmin:b=!1}){const m=ct(),[z,h]=f.useState(!1),[B,T]=f.useState(!1),[j,P]=f.useState({top:0,left:0}),[_,M]=f.useState(null),[G,q]=f.useState(null),R=f.useRef(null),u=f.useRef(null),A=e.find(I=>I.id===r),F=A==null?void 0:A.isDefault,d=(I,te)=>I.name.localeCompare(te.name),ne=e.filter(I=>I.scope==="global"&&!I.isDeleted).sort(d),U=e.filter(I=>I.scope!=="global"&&!I.isDeleted).sort(d),re=e.filter(I=>I.isFavorite&&!I.isDeleted).sort(d),xe=e.filter(I=>I.isDeleted);f.useEffect(()=>{if(z&&u.current){const I=u.current.getBoundingClientRect();P({top:I.bottom+window.scrollY+8,left:I.right+window.scrollX-320})}},[z]),f.useEffect(()=>{const I=te=>{R.current&&!R.current.contains(te.target)&&u.current&&!u.current.contains(te.target)&&h(!1)};return z&&document.addEventListener("mousedown",I),()=>{document.removeEventListener("mousedown",I)}},[z]);const V=I=>{if(n&&I!==r){M(I),h(!1);return}i(I),h(!1)},X=()=>{_&&(i(_),M(null))},ae=()=>{M(null)},le=(I,te=!1)=>{const he=I.scope==="global",se=!k&&(!he||b),ze=b&&!he;return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:r===I.id?E(m.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:r===I.id?E(m.palette.primary.main,.12):m.palette.action.hover}},children:[t.jsxs(o.Button,{onClick:()=>V(I.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[r===I.id&&t.jsx($.Check,{sx:{fontSize:16,flexShrink:0}}),r!==I.id&&t.jsx(o.Box,{sx:{width:"16px",flexShrink:0}}),t.jsx(o.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:r===I.id?m.palette.primary.dark:m.palette.text.primary,fontWeight:r===I.id?Y=>Y.typography.body2.fontWeight||500:400,fontSize:Y=>Y.typography.body2.fontSize||"0.875rem"},children:I.name}),te&&t.jsx(o.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.action.selected,px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[se&&c&&t.jsx(o.IconButton,{onClick:Y=>{Y.stopPropagation(),c(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:I.isFavorite?"Remove from favorites":"Add to favorites",children:t.jsx($.Star,{sx:{fontSize:16}})}),se&&a&&!I.isDefault&&t.jsx(o.IconButton,{onClick:Y=>{Y.stopPropagation(),a(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Set as default",children:t.jsx($.RadioButtonUnchecked,{sx:{fontSize:16}})}),(se||ze)&&(x||y||g||v||ze&&S)&&t.jsx(o.IconButton,{onClick:Y=>{Y.stopPropagation(),q({el:Y.currentTarget,view:I})},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"More actions",children:t.jsx($.MoreVert,{sx:{fontSize:16}})})]})]},I.id)},ie=I=>t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:m.palette.action.hover},children:[t.jsx(o.Typography,{sx:{color:m.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:I.name}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[l&&t.jsx(o.IconButton,{onClick:te=>{te.stopPropagation(),l(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Restore view",children:t.jsx($.Undo,{sx:{fontSize:16,color:"success.main"}})}),p&&t.jsx(o.IconButton,{onClick:te=>{te.stopPropagation(),p(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Delete permanently",children:t.jsx($.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},I.id),Q=n||!F,de=n;return t.jsxs(o.Box,{sx:{position:"relative"},children:[t.jsxs(o.Button,{ref:u,onClick:()=>h(!z),variant:"outlined",size:"small",endIcon:t.jsx($.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{position:"relative",minWidth:140,maxWidth:220,justifyContent:"space-between",fontSize:"0.8125rem",textTransform:"none",color:Q?"warning.main":"text.primary",borderColor:Q?"warning.main":"divider",bgcolor:Q?E(m.palette.warning.main,.12):"transparent",borderRadius:1,py:.5,px:1.25,transition:"all 0.15s ease","&:hover":{borderColor:Q?"warning.dark":"primary.main",bgcolor:Q?E(m.palette.warning.main,.2):E(m.palette.text.primary,.06),color:Q?"warning.dark":"text.primary"}},title:`View: ${(A==null?void 0:A.name)||"Default View"}`,children:[t.jsx(o.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(A==null?void 0:A.name)||"Default View"}),de&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),z&&bs.createPortal(t.jsxs(o.Box,{ref:R,sx:{position:"fixed",width:"320px",backgroundColor:m.palette.background.paper,border:`1px solid ${m.palette.divider}`,borderRadius:1,boxShadow:m.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:j.top,left:j.left},children:[ne.length>0&&t.jsxs(o.Box,{sx:{py:.5},children:[t.jsx(o.Typography,{sx:{px:2,py:1,fontSize:I=>I.typography.caption.fontSize||"caption.fontSize",fontWeight:I=>I.typography.caption.fontWeight||600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),ne.map(I=>le(I,I.isDefault))]}),re.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsxs(o.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[t.jsx($.Star,{sx:{fontSize:12,color:"warning.light"}}),t.jsx(o.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),re.map(I=>le(I))]})]}),U.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsx(o.Typography,{sx:{px:2,py:1,fontSize:I=>I.typography.caption.fontSize||"caption.fontSize",fontWeight:I=>I.typography.caption.fontWeight||600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),U.map(I=>le(I))]})]}),xe.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsxs(o.Button,{onClick:()=>T(!B),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[t.jsxs(o.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",xe.length,")"]}),t.jsx($.ChevronRight,{sx:{fontSize:16}})]}),B&&t.jsx(o.Box,{sx:{backgroundColor:m.palette.action.hover},children:xe.map(I=>ie(I))})]})]}),t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Button,{onClick:()=>{s(),h(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[t.jsx($.Add,{sx:{fontSize:16}}),t.jsx(o.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),t.jsxs(o.Popover,{open:!!G,anchorEl:(G==null?void 0:G.el)||null,onClose:()=>q(null),disablePortal:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[x&&t.jsxs(o.MenuItem,{onClick:()=>{G&&x(G.view.id),q(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.Edit,{sx:{fontSize:18}}),"Edit"]}),g&&t.jsxs(o.MenuItem,{onClick:()=>{G&&g(G.view.id),q(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.Link,{sx:{fontSize:18}}),"Copy Link"]}),y&&t.jsxs(o.MenuItem,{onClick:()=>{G&&y(G.view.id),q(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.ContentCopy,{sx:{fontSize:18}}),"Clone"]}),S&&b&&(G==null?void 0:G.view.scope)!=="global"&&t.jsxs(o.MenuItem,{onClick:()=>{G&&S(G.view.id),q(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.Language,{sx:{fontSize:18}}),"Promote to Global"]}),v&&[t.jsx(o.Divider,{},"delete-divider"),t.jsxs(o.MenuItem,{onClick:()=>{G&&v(G.view.id),q(null)},sx:{gap:1.5,fontSize:"body2.fontSize",color:"error.main"},children:[t.jsx($.Delete,{sx:{fontSize:18}}),"Delete"]},"delete-item")]]})]}),document.body),t.jsxs(o.Dialog,{open:_!==null,onClose:ae,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:$o(m)}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[t.jsx($.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),t.jsx(o.DialogContent,{children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),t.jsxs(o.DialogActions,{sx:{px:3,pb:2,gap:1},children:[t.jsx(o.Button,{onClick:ae,variant:"text",children:"Stay here"}),t.jsx(o.Button,{onClick:X,variant:"contained",color:"warning",children:"Discard & switch"})]})]})]})}function au({columnName:e,columnType:r="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:a=!1,hasModifications:c=!1,position:l,onSortAscending:p,onSortDescending:x,onRemoveSort:y,onFilter:g,onClearFilter:v,onGroupByColumn:S,onHideColumn:k,onManageColumns:b,onResetLayout:m,onClose:z}){const h=ct(),B=h.palette,T=f.useRef(null);f.useEffect(()=>{if(!T.current)return;const q=T.current,R=q.getBoundingClientRect(),u=window.innerWidth,A=window.innerHeight;R.right>u-8&&(q.style.left=`${u-R.width-8}px`),R.bottom>A-8&&(q.style.top=`${A-R.height-8}px`)},[l]),f.useEffect(()=>{const q=u=>{T.current&&!T.current.contains(u.target)&&z()},R=u=>{u.key==="Escape"&&z()};return document.addEventListener("mousedown",q),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",q),document.removeEventListener("keydown",R)}},[z]);const j=f.useCallback(q=>()=>{q(),z()},[z]),P=(n==null?void 0:n.direction)==="asc",_=(n==null?void 0:n.direction)==="desc",M=r==="number"?"0→9":r==="boolean"?"F→T":"A→Z",G=r==="number"?"9→0":r==="boolean"?"T→F":"Z→A";return bs.createPortal(t.jsxs(o.Paper,{ref:T,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:h.zIndex.tooltip,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:$o(h),overflow:"hidden",boxShadow:`0 4px 20px ${E(B.common.black,.12)}, 0 1px 4px ${E(B.common.black,.06)}`},children:[!a&&t.jsxs(o.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[t.jsx(o.Typography,{sx:{fontSize:q=>q.typography.body2.fontSize||"0.8125rem",fontWeight:q=>q.typography.body2.fontWeight||500,color:"text.primary"},children:"Sorting"}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[t.jsx(o.Tooltip,{title:`Sort Ascending (${M})`,placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:j(()=>p(e)),sx:{p:.625,borderRadius:"6px",color:P?"primary.main":"text.secondary",bgcolor:P?E(B.primary.main,.1):"transparent","&:hover":{bgcolor:E(B.primary.main,.08),color:"primary.main"}},children:t.jsx($.ArrowUpward,{sx:{fontSize:16}})})}),t.jsx(o.Tooltip,{title:`Sort Descending (${G})`,placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:j(()=>x(e)),sx:{p:.625,borderRadius:"6px",color:_?"primary.main":"text.secondary",bgcolor:_?E(B.primary.main,.1):"transparent","&:hover":{bgcolor:E(B.primary.main,.08),color:"primary.main"}},children:t.jsx($.ArrowDownward,{sx:{fontSize:16}})})}),t.jsx(o.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:t.jsx("span",{children:t.jsx(o.IconButton,{size:"small",disabled:!s,onClick:j(()=>y(e)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(B.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:t.jsx($.Close,{sx:{fontSize:16}})})})})]})]}),t.jsxs(o.MenuList,{dense:!0,sx:{py:.5},children:[t.jsxs(o.MenuItem,{onClick:j(()=>g(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.FilterList,{sx:{fontSize:16,color:i?"primary.main":"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Filter by Column",primaryTypographyProps:{fontSize:"0.8125rem",fontWeight:i?600:400,color:i?"primary.main":"text.primary"}})]}),i&&!a&&t.jsxs(o.MenuItem,{onClick:j(()=>v(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(B.warning.main,.06),"& .MuiListItemText-primary":{color:"warning.main"},"& .MuiListItemIcon-root svg":{color:"warning.main"}}},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!a&&S&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.25}}),t.jsx(o.MenuList,{dense:!0,sx:{py:.5},children:t.jsxs(o.MenuItem,{onClick:j(()=>S(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.GroupWorkOutlined,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Group By Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]})})]}),t.jsx(o.Divider,{sx:{my:.25}}),t.jsxs(o.MenuList,{dense:!0,sx:{py:.5},children:[!a&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[t.jsxs(o.MenuItem,{onClick:j(()=>k(e)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),t.jsx(o.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:j(b),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(B.primary.main,.08),color:"primary.main"}},children:t.jsx($.Settings,{sx:{fontSize:16}})})})]}),a&&t.jsxs(o.MenuItem,{onClick:j(b),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!a&&c&&m&&t.jsxs(o.MenuItem,{onClick:j(m),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(B.error.main,.05),"& .MuiListItemText-primary":{color:"error.main"},"& .MuiListItemIcon-root svg":{color:"error.main"}}},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const lu=176,ds="COLUMN_HEADER",cu=f.memo(function({column:r,index:n,sortRule:i,hasFilters:s,isInSortStack:a,isReadOnly:c=!1,isGrouped:l=!1,hasModifications:p=!1,width:x,onColumnClick:y,onMoveColumn:g,onColumnDragEnd:v,onResizeStart:S,onSortAscending:k,onSortDescending:b,onRemoveSort:m,onOpenFilterForColumn:z,onClearFiltersForColumn:h,onGroupByColumn:B,onHideColumn:T,onManageColumns:j,onResetLayout:P}){const M=ct().urmTable,G=f.useRef(null),[q,R]=f.useState(!1),[u,A]=f.useState({x:0,y:0}),[{handlerId:F,isOver:d},ne]=Zt.useDrop({accept:ds,collect(Q){return{handlerId:Q.getHandlerId(),isOver:Q.isOver()}},hover(Q,de){var We;if(!G.current)return;const I=Q.index,te=n;if(I===te)return;const he=(We=G.current)==null?void 0:We.getBoundingClientRect(),se=(he.right-he.left)/2,ze=de.getClientOffset(),Y=((ze==null?void 0:ze.x)??0)-he.left;I<te&&Y<se||I>te&&Y>se||(g(I,te),Q.index=te)}}),[{isDragging:U},re]=Zt.useDrag({type:ds,item:()=>({index:n,columnName:r.name}),collect:Q=>({isDragging:Q.isDragging()}),end:()=>{v==null||v()}});re(ne(G));const xe=f.useCallback(Q=>{Q.preventDefault(),Q.stopPropagation(),A({x:Q.clientX,y:Q.clientY}),R(!0)},[]),V=f.useCallback(()=>R(!1),[]),X=f.useCallback(()=>{l||y(r.name)},[y,r.name,l]),ae=f.useCallback(Q=>{Q.stopPropagation(),z(r.name)},[z,r.name]),le=f.useCallback(()=>i?t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?t.jsx($.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):t.jsx($.ArrowDownward,{sx:{fontSize:13,color:"primary.main"}}),t.jsx(o.Box,{sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"0.6rem",fontWeight:700,borderRadius:"50%",lineHeight:1},children:i.priority})]}):null,[i]),ie=f.useCallback(()=>s?t.jsx($.FilterList,{onClick:ae,titleAccess:"Active filter on this column — click to edit",sx:{ml:.5,fontSize:13,color:"primary.main",cursor:"pointer",flexShrink:0,"&:hover":{transform:"scale(1.15)"},transition:"transform 0.12s ease"}}):null,[s,ae]);return t.jsxs(t.Fragment,{children:[t.jsxs(o.TableCell,{ref:G,"data-handler-id":F,"data-column-index":n,onClick:X,onContextMenu:xe,sx:{position:"sticky",top:0,zIndex:5,textAlign:(M==null?void 0:M.cellAlignH)??"left",verticalAlign:(M==null?void 0:M.cellAlignV)??"middle",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"visible",cursor:"pointer",userSelect:"none",color:(M==null?void 0:M.headerColor)??"text.secondary",opacity:U?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:d?Q=>E(Q.palette.primary.main,.08):(M==null?void 0:M.headerBg)??"action.hover",boxShadow:Q=>`0 1px 0 ${E(Q.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:(M==null?void 0:M.rowDivider)??"1px solid",borderRight:M==null?void 0:M.colDivider,borderColor:"divider",py:0,px:l?0:(M==null?void 0:M.cellPaddingX)??2,"&:hover":{bgcolor:Q=>E(Q.palette.primary.main,.1),color:"text.primary"},width:l?"32px":x?`${x}px`:`${lu}px`,minWidth:l?"32px":void 0,maxWidth:l?"32px":void 0},children:[!l&&t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[lt(r.name),le(),ie()]}),!l&&t.jsx(o.Box,{draggable:!1,onDragStart:Q=>Q.preventDefault(),sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:Q=>{Q.preventDefault(),Q.stopPropagation(),S(Q,r.name)},onClick:Q=>Q.stopPropagation(),children:t.jsx(o.Box,{draggable:!1,sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),d&&t.jsx(o.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),q&&t.jsx(au,{columnName:r.name,columnType:r.type,currentSort:i,hasFilters:s,isInSortStack:a,isReadOnly:c,hasModifications:p,position:u,onSortAscending:k,onSortDescending:b,onRemoveSort:m,onFilter:z,onClearFilter:h,onGroupByColumn:B,onHideColumn:T,onManageColumns:j,onResetLayout:P,onClose:V})]})}),du={active:"success",completed:"success",approved:"success",success:"success",done:"success",contract:"info","in progress":"info","in review":"info",review:"info",pending:"info","on leave":"error","on hold":"warning",probation:"warning",cancelled:"error",rejected:"error",blocked:"error",inactive:"neutral","not started":"neutral",paused:"neutral"};function nn(e,r){const n=du[r.toLowerCase().trim()];if(!n||n==="neutral")return{bg:e.palette.action.selected,color:e.palette.text.secondary};const i=e.palette[n];return{bg:E(i.main,e.palette.mode==="dark"?.24:.12),color:e.palette.mode==="dark"?i.light:i.dark}}function uu(e,r){switch(r.toLowerCase().trim()){case"low":return e.palette.text.secondary;case"medium":return e.palette.warning.main;case"high":return e.palette.mode==="dark"?e.palette.warning.light:e.palette.warning.dark;case"critical":case"urgent":return e.palette.error.main;default:return}}const pu={filters:{hue:"primary",shade:"main"},sorting:{hue:"secondary",shade:"main"},grouping:{hue:"success",shade:"main"},columns:{hue:"warning",shade:"main"},views:{hue:"error",shade:"main"},theme:{hue:"info",shade:"main"},export:{hue:"primary",shade:"dark"},presets:{hue:"secondary",shade:"dark"},system:{hue:"error",shade:"dark"}};function hu(e,r){const n=pu[r];return n?e.palette[n.hue][n.shade]:e.palette.text.secondary}function jt(e){return E(e.palette.primary.main,e.palette.mode==="dark"?.24:.12)}function fu(e){const r=e.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:n=>{var i;return(i=n.tokens)!=null&&i.statusBold?700:500},bgcolor:n=>nn(n,r).bg,color:n=>nn(n,r).color,whiteSpace:"nowrap",lineHeight:1.5},children:e})}function mu(e,r){if(r==null||r==="")return t.jsx(o.Box,{component:"span",sx:{color:"text.disabled",fontSize:"0.875rem"},children:"—"});const n=String(r),i=e.name.toLowerCase();if(/\b(status|state|stage)\b/.test(i))return fu(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=n.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:a=>{const c=uu(a,s);return c?{color:c,fontWeight:600,fontSize:"0.875rem"}:{fontSize:"0.875rem"}},children:n})}return typeof r=="boolean"?t.jsx(o.Box,{component:"span",sx:{fontSize:"0.875rem"},children:r?"Yes":"No"}):typeof r=="object"?t.jsx(o.Box,{component:"span",sx:{fontSize:"0.875rem"},children:JSON.stringify(r)}):t.jsx(o.Box,{component:"span",sx:{fontSize:"0.875rem"},children:n})}function xu(e){const r=e.find(s=>{const a=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(a)})||e[0]||null,n=e.find(s=>{const a=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(a)&&s!==r})||null,i=e.filter(s=>s!==r&&s!==n).slice(0,4);return{primaryCol:r,idCol:n,bodyColumns:i}}function gu({row:e,rowIndex:r,visibleColumns:n,isSelected:i,onCardClick:s,onCardDoubleClick:a,onCardContextMenu:c,onOpenRowMenu:l,onToggleSelection:p,hideCheckbox:x}){const[y,g]=f.useState(!1),{primaryCol:v,idCol:S,bodyColumns:k}=f.useMemo(()=>xu(n),[n]),b=v?e[v.name]:null,m=S?e[S.name]:null,z=y||i;return t.jsxs(o.Box,{onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),onClick:h=>s(r,h),onDoubleClick:h=>a(e,r,h),onContextMenu:h=>{h.preventDefault(),h.stopPropagation(),c(e,r,h)},sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:h=>{var T,j,P,_;const B=(_=(P=(j=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:j.styleOverrides)==null?void 0:P.root)==null?void 0:_.border;return i?"2px solid":B&&B!=="none"?B:"1px solid"},borderColor:i?h=>it(h).main:h=>{var T,j,P,_;const B=(_=(P=(j=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:j.styleOverrides)==null?void 0:P.root)==null?void 0:_.border;return B&&B!=="none"?"inherit":E(h.palette.divider,.8)},borderWidth:i?2:void 0,borderRadius:h=>{var T,j,P,_;const B=(_=(P=(j=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:j.styleOverrides)==null?void 0:P.root)==null?void 0:_.borderRadius;return B!==void 0?typeof B=="number"?`${B}px`:B:`${h.shape.borderRadius}px`},cursor:"pointer",transition:"box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease",overflow:"hidden",minHeight:180,boxShadow:i?h=>`0 0 0 3px ${E(it(h).main,.15)}, 0 2px 8px ${E(h.palette.common.black,.08)}`:y?h=>{var T,j,P,_;const B=(_=(P=(j=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:j.styleOverrides)==null?void 0:P.root)==null?void 0:_.boxShadow;return B&&B!=="none"?B:ge(h,"cardHover")}:h=>{var T,j,P,_;const B=(_=(P=(j=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:j.styleOverrides)==null?void 0:P.root)==null?void 0:_.boxShadow;return B&&B!=="none"?B:ge(h,"cardRest")},transform:y&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:h=>E(it(h).main,.03)}},children:[t.jsxs(o.Box,{sx:h=>{var _,M,G,q;const B=((G=(M=(_=h.components)==null?void 0:_.MuiCardHeader)==null?void 0:M.styleOverrides)==null?void 0:G.root)||{},T=(B.backgroundColor&&B.backgroundColor!=="transparent"?B.backgroundColor:void 0)??((q=h.tokens)==null?void 0:q.cardHdrHex)??"transparent",j=B.borderBottom&&B.borderBottom!=="none"?B.borderBottom:void 0,P=B.boxShadow&&B.boxShadow!=="none"?B.boxShadow:void 0;return{px:2,pt:1.75,pb:1.5,bgcolor:T,borderBottom:j,boxShadow:P,display:"flex",alignItems:"center",gap:.5}},children:[!x&&t.jsx(o.Checkbox,{size:"small",checked:i,onClick:h=>h.stopPropagation(),onChange:()=>p(e),sx:{p:.25,opacity:z?1:0,transition:"opacity 0.15s ease"}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:h=>h.typography.body2.fontWeight||600,fontSize:h=>h.typography.body1.fontSize||"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:b!=null&&b!==""?String(b):t.jsx(o.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})]}),t.jsx(o.Box,{sx:h=>{var j,P,_;const B=((_=(P=(j=h.components)==null?void 0:j.MuiCardHeader)==null?void 0:P.styleOverrides)==null?void 0:_.root)||{};return B.borderBottom&&B.borderBottom!=="none"?{display:"none"}:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}}),t.jsxs(o.Box,{sx:{px:2,py:1.5,flex:1,display:"grid",gridTemplateColumns:"repeat(2, 1fr)",columnGap:1.5,rowGap:1,alignContent:"start"},children:[k.map(h=>t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{sx:{color:"text.secondary",fontWeight:B=>B.typography.body2.fontWeight||500,fontSize:B=>B.typography.caption.fontSize||"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1.2,mb:.25},children:lt(h.name)}),t.jsx(o.Box,{sx:{lineHeight:1.3,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},title:String(e[h.name]??""),children:mu(h,e[h.name])})]},h.name)),k.length===0&&t.jsx(o.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic",gridColumn:"1 / -1"},children:"No additional fields visible"})]}),t.jsxs(o.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:h=>E(h.palette.action.hover,.1),minHeight:40},children:[t.jsx(o.Typography,{sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.75rem",fontWeight:400,letterSpacing:"0.04em",opacity:m?.85:0,userSelect:"none"},children:m?String(m):" "}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:z?1:0,transition:"opacity 0.15s ease"},onClick:h=>h.stopPropagation(),children:t.jsx(o.Tooltip,{title:"More actions",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:h=>{h.stopPropagation(),l(e,r,h.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:h=>E(h.palette.text.primary,.08)}},children:t.jsx($.MoreVert,{sx:{fontSize:17}})})})})]})]})}function yu({row:e,grouping:r,onToggleCollapse:n}){var i;return t.jsxs(o.Box,{onClick:()=>n(e.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:s=>ge(s,"flatHover"),"&:hover":{bgcolor:s=>E(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[e.isCollapsed?t.jsx($.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):t.jsx($.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:s=>s.typography.h5.fontWeight||600,color:s=>s.typography.h5.color||"text.primary"},children:Va(e.groupLevel,((i=r==null?void 0:r.levels[e.groupLevel])==null?void 0:i.column)||"",e.groupValue)}),t.jsxs(o.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:s=>E(s.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[e.rowCount," ",e.rowCount===1?"row":"rows"]}),Object.keys(e.aggregates).length>0&&t.jsx(o.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(e.aggregates).map(([s,a])=>ks(a)).filter(Boolean).join(" • ")})]})}function bu({data:e,visibleColumns:r,grouping:n,selectedRowIds:i,isGrouped:s,onToggleGroupCollapse:a,onCardClick:c,onCardDoubleClick:l,onCardContextMenu:p,onOpenRowMenu:x,onToggleSelection:y,hideSelectionCheckboxes:g}){const v=f.useMemo(()=>{const S=new Set;return i.forEach(k=>{const b=k==null?void 0:k.__urm_row_id__;b!==void 0&&S.add(b)}),S},[i]);return e.length===0?t.jsx(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):t.jsx(o.Box,{sx:{fontFamily:S=>S.typography.fontFamily},children:t.jsx(o.Box,{sx:{p:S=>ls(S).containerPad,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:S=>ls(S).cardGap,alignContent:"start"},children:e.map((S,k)=>s&&S.isGroupHeader?t.jsx(yu,{row:S,grouping:n,onToggleCollapse:a||(()=>{})},`group-${S.groupKey}`):t.jsx(gu,{row:S,rowIndex:k,visibleColumns:r,isSelected:v.has(S==null?void 0:S.__urm_row_id__),onCardClick:c,onCardDoubleClick:l,onCardContextMenu:p,onOpenRowMenu:x,onToggleSelection:y,hideCheckbox:g},`card-${k}`))})})}const us=[10,15,25,50,100];function vu(e,r){const n=e.trim();if(n==="")return"Page number is required";if(!/^-?\d+$/.test(n))return"Must be a number";const i=parseInt(n,10);return i<1?"Page number must be at least 1":i>r?"Entered page number is out of range":null}function Su({currentPage:e,pageSize:r,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:a}){const l=ct().palette,p=Math.ceil(n/r),[x,y]=f.useState(String(e)),[g,v]=f.useState(null),[S,k]=f.useState(!1),b=f.useRef(null);f.useEffect(()=>{S||(y(String(e)),v(null))},[e,S]);const m=f.useCallback(()=>{const A=vu(x,p);if(A){v(A);return}const F=parseInt(x.trim(),10);v(null),k(!1),F!==e&&s(F)},[x,p,e,s]),z=f.useCallback(A=>{var F;A.key==="Enter"?(A.preventDefault(),m()):A.key==="Escape"&&(y(String(e)),v(null),k(!1),(F=b.current)==null||F.blur())},[m,e]),h=f.useCallback(()=>{y(String(e)),v(null),k(!1)},[e]),B=f.useCallback(()=>{k(!0),v(null),setTimeout(()=>{var A;return(A=b.current)==null?void 0:A.select()},0)},[]);if(n<=Math.min(...us))return null;const T=()=>{y(String(e)),v(null),k(!1)},j=()=>{T(),s(1)},P=()=>{T(),e>1&&s(e-1)},_=()=>{T(),e<p&&s(e+1)},M=()=>{T(),s(p)},G=(e-1)*r+1,q=Math.min(e*r,n),R=`${Math.max(2,String(p).length+.5)}ch`,u={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:3,px:2,py:1,borderTop:"1px solid",borderColor:"divider",bgcolor:"background.paper",minHeight:48},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",t.jsx(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",t.jsx(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),t.jsx(o.Select,{value:r,onChange:A=>a(Number(A.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:us.map(A=>t.jsx(o.MenuItem,{value:A,sx:{fontSize:"0.8125rem"},children:A},A))})]}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[G,"–",q," of ",n]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),t.jsxs(o.Box,{sx:{position:"relative"},children:[g&&t.jsx(o.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:E(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${E(l.common.black,.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:E(l.error.main,.4)}},children:t.jsx(o.Typography,{sx:{fontSize:A=>A.typography.caption.fontSize||"0.6875rem",fontWeight:A=>A.typography.caption.fontWeight||500,color:"error.main",lineHeight:1.3},children:g})}),t.jsx(o.InputBase,{inputRef:b,value:x,onChange:A=>{y(A.target.value),g&&v(null)},onKeyDown:z,onFocus:B,onBlur:h,inputProps:{"aria-label":`Page number, 1 to ${p}`,style:{textAlign:"center",padding:"2px 0",width:R,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:g?"error.main":"text.primary",border:"1px solid",borderColor:g?"error.main":S?"primary.main":"divider",borderRadius:"4px",bgcolor:g?E(l.error.main,.04):S?E(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:g?"error.main":"text.secondary"},"&:focus-within":{boxShadow:g?`0 0 0 2px ${E(l.error.main,.2)}`:`0 0 0 2px ${E(l.primary.main,.2)}`}}})]}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",p]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.IconButton,{onClick:j,disabled:e===1,size:"small",title:"First page",sx:u,children:t.jsx($.FirstPage,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:P,disabled:e===1,size:"small",title:"Previous page",sx:u,children:t.jsx($.ChevronLeft,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:_,disabled:e===p,size:"small",title:"Next page",sx:u,children:t.jsx($.ChevronRight,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:M,disabled:e===p,size:"small",title:"Last page",sx:u,children:t.jsx($.LastPage,{sx:{fontSize:20}})})]})]})]})}function Cu(){return t.jsx(o.Chip,{icon:t.jsx($.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:e=>e.typography.caption.fontSize||"caption.fontSize",fontWeight:e=>e.typography.caption.fontWeight||500}})}const Xs="urm_hint_seen_";function ju(e){try{return localStorage.getItem(Xs+e)==="true"}catch{return!1}}function wu(e){try{localStorage.setItem(Xs+e,"true")}catch{}}const Qs={"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:"8px"},"& .MuiInputLabel-root":{fontSize:"0.875rem"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:.5},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}};function oi(e,r){if(e==null||e==="")return"";if(r==="boolean")return e?"True":"False";if(r==="object"||r==="array")try{return JSON.stringify(e,null,2)}catch{return String(e)}return String(e)}function Zs({row:e,schema:r}){const i=ct().palette,s=r.filter(l=>l.name in e),a=s.filter(l=>l.type!=="object"&&l.type!=="array"),c=s.filter(l=>l.type==="object"||l.type==="array");return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[a.map(l=>t.jsx(o.TextField,{label:lt(l.name),value:oi(e[l.name],l.type)||"No value",size:"small",fullWidth:!0,InputProps:{readOnly:!0},sx:Qs},l.name)),c.map(l=>{const p=oi(e[l.name],l.type);return t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:x=>x.typography.caption.fontWeight||500,fontSize:x=>x.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mb:.75},children:lt(l.name)}),t.jsx(o.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,borderRadius:"8px",border:"1px solid",borderColor:"divider",bgcolor:E(i.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:p?"text.primary":"text.disabled",fontStyle:p?"normal":"italic",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:160,overflowY:"auto"},children:p||"No value"})]},l.name)}),s.length===0&&t.jsx(o.Typography,{variant:"body2",sx:{color:"text.disabled",textAlign:"center",py:3,fontSize:l=>l.typography.body2.fontSize||"0.875rem"},children:"No fields to display"})]})}function ku({open:e,onClose:r,row:n,schema:i,reportName:s}){const a=ct(),c=a.palette;if(!n)return null;const l=i.filter(x=>x.name in n).length,p=ce(a);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:et(a),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",overflow:"hidden",...p.paper}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:2,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0,...p.header},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:E(c.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:x=>x.typography.h6.fontSize||"1rem",fontWeight:x=>x.typography.h6.fontWeight||600,color:x=>x.typography.h6.color||"text.primary",lineHeight:1.3},children:"View Record"}),s&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:x=>x.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s," · ",l," ",l===1?"field":"fields"]})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsx(o.Divider,{}),t.jsx(o.DialogContent,{sx:{overflowY:"auto",flex:1,bgcolor:E(c.text.primary,.015)},children:t.jsx(Zs,{row:n,schema:i})}),t.jsx(o.Divider,{}),t.jsx(o.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:t.jsx(o.Button,{onClick:r,variant:"contained",sx:{fontSize:"0.8125rem",px:3,py:.75,borderRadius:x=>`${x.shape.borderRadius}px`,minWidth:80},children:"Close"})})]})}function zu({open:e,onClose:r,onConfirm:n,row:i,schema:s}){const a=ct(),c=ce(a);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:et(a),maxHeight:"min(720px, calc(100vh - 80px))",my:"auto",display:"flex",flexDirection:"column",...c.paper}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",...c.header},children:[t.jsxs(o.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[t.jsx(o.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:l=>E(l.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:l=>l.typography.h6.fontSize||"1.125rem",fontWeight:l=>l.typography.h6.fontWeight||500,color:l=>l.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:l=>l.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"This record will be permanently removed."})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.DialogContent,{sx:{px:3,pb:2,overflowY:"auto",flex:1,display:"flex",flexDirection:"column",gap:2},children:[i&&s&&t.jsx(Zs,{row:i,schema:s}),t.jsx(o.Box,{sx:{p:2,borderRadius:"8px",bgcolor:l=>E(l.palette.error.main,.1),border:l=>`1px solid ${E(l.palette.error.main,.5)}`},children:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:l=>l.typography.body2.fontSize||"0.8125rem",color:"error.main",fontWeight:l=>l.typography.body2.fontWeight||500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})]}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:r,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:l=>`${l.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:()=>{n(),r()},variant:"contained",startIcon:t.jsx($.DeleteForever,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"error.contrastText",px:3,py:.875,minHeight:36,borderRadius:l=>`${l.shape.borderRadius}px`,boxShadow:l=>ge(l,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:l=>ge(l,"hoverButton")},"&:active":{boxShadow:l=>ge(l,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Tu({open:e,onClose:r,onSave:n,row:i,schema:s,reportName:a}){var z;const c=ct(),l=c.palette,[p,x]=f.useState({});if(f.useEffect(()=>{e&&i&&x({...i})},[e,i]),!i)return null;const y=s.filter(h=>h.name in i),g=y.filter(h=>h.type!=="object"&&h.type!=="array"),v=y.filter(h=>h.type==="object"||h.type==="array"),S=(h,B)=>{x(T=>({...T,[h]:B}))},k=()=>{const h={...p};y.forEach(B=>{const T=p[B.name];if(B.type==="number"){const j=Number(T);h[B.name]=isNaN(j)?i[B.name]:j}else B.type==="boolean"&&(h[B.name]=!!T)}),n(h),r()},b=y.length,m=ce(c);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:et(c),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",overflow:"hidden",...m.paper}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:2,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0,...m.header},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:E(((z=l.warning)==null?void 0:z.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{sx:{fontSize:h=>h.typography.h6.fontSize||"1rem",fontWeight:h=>h.typography.h6.fontWeight||600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),a&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:h=>h.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a," · ",b," ",b===1?"field":"fields"]})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:E(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[g.map(h=>{const B=p[h.name];return h.type==="boolean"?t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:T=>T.typography.caption.fontWeight||500,fontSize:T=>T.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mb:.75},children:lt(h.name)}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Switch,{checked:!!B,onChange:T=>S(h.name,T.target.checked),size:"small"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:T=>T.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:B?"Enabled":"Disabled"})]})]},h.name):t.jsx(o.TextField,{label:lt(h.name),value:B??"",onChange:T=>S(h.name,T.target.value),type:h.type==="number"?"number":"text",size:"small",fullWidth:!0,sx:Qs},h.name)}),v.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:v.map(h=>{const B=oi(i[h.name],h.type);return t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.75},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:T=>T.typography.caption.fontSize||"0.75rem",fontWeight:T=>T.typography.caption.fontWeight||500,color:"text.secondary"},children:lt(h.name)}),t.jsx(o.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:E(l.text.secondary,.07),color:"text.secondary",border:"none"}}),t.jsx(o.Tooltip,{title:"Object and array fields cannot be edited directly",arrow:!0,children:t.jsx($.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),t.jsx(o.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,borderRadius:"8px",border:"1px solid",borderColor:"divider",bgcolor:E(l.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:B?"text.primary":"text.disabled",fontStyle:B?"normal":"italic",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:160,overflowY:"auto"},children:B||"No value"})]},h.name)})}),y.length===0&&t.jsxs(o.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[t.jsx($.EditOutlined,{sx:{fontSize:40,opacity:.4}}),t.jsx(o.Typography,{variant:"body2",children:"No editable fields"})]})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:r,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",px:2,borderRadius:h=>`${h.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:k,variant:"contained",startIcon:t.jsx($.SaveOutlined,{sx:{fontSize:15}}),sx:{fontSize:"0.8125rem",px:2.5,borderRadius:h=>`${h.shape.borderRadius}px`,minWidth:90},children:"Save"})]})]})}const Bu=176,Iu=170,Eu=40,Du=32;function ea(e){return e.type==="date"?180:Bu}function $u(e,r){return r!=null&&r!==Iu&&r!==ea(e)}function _u(e,r,n,i){return f.useMemo(()=>{const s=e.map(v=>i!=null&&i.has(v.name)?{name:v.name,width:Du,explicit:!0}:{name:v.name,width:r[v.name]??ea(v),explicit:$u(v,r[v.name])}),a={};s.forEach(v=>{a[v.name]=v.width});const c=s.reduce((v,S)=>v+S.width,0),p=Math.max(0,n-Eu)-c;if(p<=0)return{widths:a,fillerWidth:0};const x=s.filter(v=>!v.explicit);if(x.length===0)return{widths:a,fillerWidth:p};const y=x.reduce((v,S)=>v+S.width,0)||1;let g=0;return x.forEach((v,S)=>{const b=S===x.length-1?v.width+p-g:Math.round(v.width+p*v.width/y);a[v.name]=b,g+=b-v.width}),{widths:a,fillerWidth:0}},[e,r,n,i])}const ps=176,Ou=_t(),Mu={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Wu(e){const r=e.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:n=>{var i;return(i=n.tokens)!=null&&i.statusBold?700:500},bgcolor:n=>nn(n,r).bg,color:n=>nn(n,r).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:e})}function Au(e){const r=e.toLowerCase().trim(),n=Mu[r];return n?t.jsx(o.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:e}):e}function Ru(e,r){const n=r.trim();if(!n)return e;const i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=e.split(new RegExp(`(${i})`,"gi"));return s.length===1?e:s.map((a,c)=>a.toLowerCase()===n.toLowerCase()?t.jsx(o.Box,{component:"mark",sx:{bgcolor:"warning.light",color:"inherit",px:"1px",borderRadius:"2px"},children:a},c):a)}function Pu(e,r,n,i=""){if(r==null||r==="")return t.jsx(o.Box,{component:"span",sx:{color:"text.disabled"},children:"—"});const s=String(r);if(/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(e.name.toLowerCase()))return Wu(s);if(/\b(priority|severity|urgency|importance|criticality)\b/.test(e.name.toLowerCase()))return Au(s);if(e.type==="date"){const l=e.dateFormat??"iso",p=$a(r,l,n??null);return t.jsx(o.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:p})}if(e.type==="number"&&typeof r=="number")return r.toLocaleString();if(typeof r=="boolean")return r?"Yes":"No";if(Array.isArray(r)){if(r.length===0)return t.jsx(o.Box,{component:"span",sx:{color:"text.disabled"},children:"[ ]"});const l=r.slice(0,3).map(p=>typeof p=="object"?JSON.stringify(p):String(p)).join(", ");return t.jsxs(o.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[l,r.length>3?` +${r.length-3} more`:""]})}if(typeof r=="object"){const l=JSON.stringify(r);return t.jsx(o.Box,{component:"span",title:l,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:l.length>40?l.slice(0,40)+"…":l})}return Ru(s,i)}function Nu({schema:e,data:r,sortStack:n=[],filters:i=Ou,views:s=[],activeViewId:a="",isDirty:c=!1,isExporting:l=!1,columnVisibility:p={},columnOrder:x=[],columnWidths:y={},grouping:g=null,classTokens:v={},onSort:S,onSortAscending:k,onSortDescending:b,onOpenFilters:m,onOpenSort:z,onOpenFilterForColumn:h,onSelectView:B,onCreateView:T,onUpdateCurrentView:j,onSaveAsNewView:P,onDiscardChanges:_,onToggleDefault:M,onToggleFavorite:G,onRestoreView:q,onPermanentDelete:R,onEditView:u,onCloneView:A,onCopyLink:F,onDeleteView:d,onPromoteToGlobal:ne,isAdmin:U=!1,onExport:re,onOpenColumns:xe,onUpdateColumnWidth:V,onUpdateColumnOrder:X,onUpdateColumnVisibility:ae,onClearFiltersForColumn:le,onResetLayout:ie,onOpenGroup:Q,onGroupByColumn:de,onToggleGroupCollapse:I,onExpandAllGroups:te,onCollapseAllGroups:he,onOpenAuditHistory:se,onOpenScheduledReports:ze,searchQuery:Y,highlightQuery:We="",searchHistory:kt=[],onAddToSearchHistory:dt,onToggleSearchFavourite:Or,onDeleteSearchHistory:Ot,selectedRowIds:ot=new Set,onSearchChange:Ft,onToggleRowSelection:qe,onToggleAllRows:zt,onRangeSelection:fr,onClearSelection:xt,onExportSelected:tr,currentPage:so=1,pageSize:rr=15,totalRowsBeforePagination:ao=r.length,onPageChange:Tt,onPageSizeChange:mr,isReadOnly:Je=!1,userRole:Mt,reportName:Vt,onEditRow:tt,onDuplicateRow:Qe,onDeleteRow:Wt,showDevPanel:lo=!1,onOpenDevConfig:Mr,rowActions:xr,hideDefaultRowActions:Ve,hideToolbarActions:ke,customSettingsActions:or,viewOptions:At,defaultViewMode:gr,bulkActions:yr,hideSelectionCheckboxes:Ht,rowClickBehavior:nr="select",openModalOn:Ze,onRowClick:ir,onRowRightClick:gt}){var Ro;const ee=ct().urmTable,[br,Ar]=f.useState(null),[Bt,H]=f.useState(0),[ut,we]=f.useState(0),[Ke,sr]=f.useState(null),co=((Ro=Dr().dates)==null?void 0:Ro.displayFormat)??null,[Ut,Sr]=f.useState(null),[Gt,ar]=f.useState(null),[Yt,be]=f.useState(null),[yt,Z]=f.useState(!1),[pe,ye]=f.useState(!1),[Cr,jr]=f.useState(null),[uo,Rr]=f.useState(!1),[po,qt]=f.useState(null),[Pr,Nr]=f.useState(null),[ve,Ge]=f.useState(null),[wr,st]=f.useState(null),Jt=f.useRef(null),It=f.useCallback(()=>{Jt.current&&(clearTimeout(Jt.current),Jt.current=null)},[]),kr=f.useCallback(()=>{It(),Jt.current=setTimeout(()=>st(null),200)},[It]);f.useEffect(()=>It,[It]);const[me,Se]=f.useState(null),Ne=f.useMemo(()=>At??["list","grid"],[At]),[nt,Et]=f.useState(()=>gr??Ne[0]??"list"),[zr,Lr]=f.useState(!1),[Fr,kn]=f.useState(()=>!ju("toolbar_search")),Vr=f.useRef(null),ho=f.useRef(null),[zn,_o]=f.useState(0);f.useLayoutEffect(()=>{const C=Vr.current;if(!C)return;_o(C.clientWidth);const N=new ResizeObserver(oe=>{_o(oe[0].contentRect.width)});return N.observe(C),()=>N.disconnect()},[]);const Hr=f.useCallback(()=>{wu("toolbar_search"),kn(!1)},[]);f.useEffect(()=>{if(!Fr)return;const C=setTimeout(Hr,2e3);return()=>clearTimeout(C)},[Fr,Hr]);const Oo=f.useMemo(()=>{const C=Ke??x;return C.length>0?C.map(N=>e.find(oe=>oe.name===N)).filter(N=>N!==void 0):e},[Ke,x,e]),Ur=f.useMemo(()=>Oo.filter(C=>p[C.name]!==!1),[Oo,p]),Gr=f.useMemo(()=>new Set(((g==null?void 0:g.levels)??[]).map(C=>C.column)),[g]),fo=!!(g!=null&&g.enabled&&(g!=null&&g.levels)&&g.levels.length>0),Yr=f.useMemo(()=>{if(!fo)return Ur;const C=((g==null?void 0:g.levels)??[]).map(oe=>e.find(Ce=>Ce.name===oe.column)).filter(oe=>oe!==void 0),N=Ur.filter(oe=>!Gr.has(oe.name));return[...C,...N]},[Ur,fo,Gr,g,e]),{widths:qr}=_u(Yr,y,zn,fo?Gr:void 0),lr=f.useMemo(()=>e.filter(C=>p[C.name]===!1).length,[e,p]),mo=f.useMemo(()=>e.map(C=>C.name),[e]),Jr=f.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(mo),[x,mo]),Tn=f.useCallback((C,N)=>{C.preventDefault(),C.stopPropagation(),Ar(N),H(C.clientX),we(y[N]||150)},[y]);f.useEffect(()=>{if(!br)return;const C=oe=>{const Ce=oe.clientX-Bt,Ae=Math.max(100,Math.min(600,ut+Ce));V==null||V(br,Ae)},N=()=>{Ar(null)};return document.addEventListener("mousemove",C),document.addEventListener("mouseup",N),()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",N)}},[br,Bt,ut,V]);const Bn=f.useCallback(C=>C==null?"-":typeof C=="object"?JSON.stringify(C):typeof C=="boolean"?C?"true":"false":String(C),[]);f.useCallback(C=>{const N=n.find(oe=>oe.column===C);return N?t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[N.direction==="asc"?t.jsx($.ArrowUpward,{sx:{fontSize:14}}):t.jsx($.ArrowDownward,{sx:{fontSize:14}}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"caption.fontSize",fontWeight:"bold",borderRadius:"50%"},children:N.priority})]}):null},[n]),f.useCallback(C=>Xn(i,C)?t.jsx(o.IconButton,{size:"small",onClick:oe=>{oe.stopPropagation(),h==null||h(C)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:t.jsx($.FilterList,{sx:{fontSize:14}})}):null,[i,h]);const In=f.useCallback(C=>{S&&S(C)},[S]),En=f.useCallback((C,N)=>{sr(oe=>{const Ae=[...oe??(x.length>0?x:e.map(Xe=>Xe.name))],[rt]=Ae.splice(C,1);return Ae.splice(N,0,rt),Ae})},[x,e]),Dn=f.useCallback(()=>{Ke&&X&&X(Ke),sr(null)},[Ke,X]),$n=f.useCallback(C=>{if(!S)return;const N=n.find(oe=>oe.column===C);(!N||N.direction!=="asc")&&S(C)},[S,n]),_n=f.useCallback(C=>{if(!S)return;const N=n.find(oe=>oe.column===C);N?N.direction==="asc"&&S(C):(S(C),setTimeout(()=>S(C),0))},[S,n]),On=f.useCallback(C=>{if(!S)return;const N=n.find(oe=>oe.column===C);N&&(N.direction==="asc"?(S(C),setTimeout(()=>S(C),0)):N.direction==="desc"&&S(C))},[S,n]),Mn=f.useCallback(C=>{ae&&ae(C,!1)},[ae]),Kr=!!(g!=null&&g.enabled&&(g!=null&&g.levels)&&g.levels.length>0),Kt=f.useMemo(()=>Ct(i),[i]),Wn=n.length>0||Kt>0||((g==null?void 0:g.enabled)??!1)||Object.values(p).some(C=>C===!1),An=(so-1)*rr,Me=r,at=f.useMemo(()=>{const C=new Set;return ot.forEach(N=>{const oe=N==null?void 0:N.__urm_row_id__;oe!==void 0&&C.add(oe)}),C},[ot]);f.useEffect(()=>{const C=N=>{!zt||!xt||N.target instanceof HTMLInputElement||N.target instanceof HTMLTextAreaElement||((N.ctrlKey||N.metaKey)&&N.key==="a"&&(N.preventDefault(),zt(!0,Me)),N.key==="Escape"&&(N.preventDefault(),xt()))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[zt,xt,Me]);const xo=f.useCallback((C,N)=>{ir==null||ir(Me[C],C,N),(nr==="activate"||nr==="both")&&(be(Me[C]),Z(!0)),nr!=="activate"&&qe&&(N.shiftKey&&Ut!==null?(N.preventDefault(),fr&&fr(Ut,C,Me)):(qe(Me[C]),Sr(C)))},[qe,Ut,fr,Me,ir,nr,be,Z]),Mo=f.useMemo(()=>Me.length>0&&at.size>0&&Me.every(C=>at.has(C==null?void 0:C.__urm_row_id__)),[Me,at]),Rn=!Mo&&Me.some(C=>at.has(C==null?void 0:C.__urm_row_id__)),Dt=!!(qe&&zt&&!Ht),Tr=f.useMemo(()=>!(g!=null&&g.enabled)||!(g!=null&&g.levels)?new Set:new Set(g.levels.map(C=>C.column)),[g]),pt=f.useMemo(()=>Yr,[Yr]),Wo=f.useMemo(()=>{const C=new Map;if(!(g!=null&&g.enabled)||!Me)return C;let N=[];for(const oe of Me)if(oe.__isGroupHeader||oe.isGroupHeader){const Ce=oe.groupLevel??0;N[Ce]=oe.groupKey,N=N.slice(0,Ce+1),C.has(oe.groupKey)||C.set(oe.groupKey,[])}else if(oe.__urm_is_grouped_data_row__)for(const Ce of N)Ce&&C.has(Ce)&&C.get(Ce).push(oe);return C},[g,Me]),Xr=f.useCallback(C=>{const N=C.groupLevel,oe=N===0?v.groupRowLevel0||"urm-group-level-0":N===1?v.groupRowLevel1||"urm-group-level-1":v.groupRowLevel2||"urm-group-level-2",Ce=N===0?_e=>_e.palette.mode==="dark"?E(_e.palette.action.hover,.12):"#f1f5f9":_e=>_e.palette.mode==="dark"?E(_e.palette.action.hover,.06):"#f8fafc",Ae=String(C.groupValue??"(empty)"),rt=`${C.rowCount} ${C.rowCount===1?"item":"items"}`,Xe=Wo.get(C.groupKey)||[],fe=Xe.filter(_e=>at.has(_e==null?void 0:_e.__urm_row_id__)).length,Rt=Xe.length>0&&fe===Xe.length,Xt=fe>0&&fe<Xe.length;return t.jsxs(o.TableRow,{onClick:()=>I==null?void 0:I(C.groupKey),className:`urm-group-header-row urm-group-level-${N} ${oe} ${v.groupRow||""}`,sx:{bgcolor:Ce,"&:hover":{bgcolor:_e=>E(_e.palette.text.primary,.07)},cursor:"pointer",borderTop:"1px solid",borderBottom:"1px solid",borderColor:"divider",position:"relative"},children:[Dt&&t.jsx(o.TableCell,{padding:"checkbox",onClick:_e=>_e.stopPropagation(),sx:{borderBottom:"1px solid",borderColor:"divider",verticalAlign:"middle",bgcolor:"inherit"},children:t.jsx(o.Checkbox,{size:"small",checked:Rt,indeterminate:Xt,onChange:()=>{if(!qe)return;const _e=!Rt;Xe.forEach(cr=>{const Po=at.has(cr==null?void 0:cr.__urm_row_id__);_e!==Po&&qe(cr)})}})}),t.jsxs(o.TableCell,{colSpan:pt.length-Tr.size+(!Dt&&Tr.size===0?1:0),className:`urm-group-cell ${v.groupCellFirst||""} ${v.groupCell||""}`,sx:{pl:`${N*24+16}px`,position:"relative",py:1.25,borderBottom:"1px solid",borderColor:"divider"},children:[N>0&&t.jsx(o.Box,{sx:{position:"absolute",left:`${N*24+4}px`,top:0,bottom:0,width:"1px",bgcolor:"divider"}}),t.jsxs(o.Box,{className:`urm-group-content ${v.groupContent||""}`,sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Box,{className:`urm-group-caret ${v.groupCaret||""}`,sx:{color:"text.secondary",display:"inline-flex",alignItems:"center"},children:C.isCollapsed?t.jsx($.ChevronRight,{sx:{fontSize:18}}):t.jsx($.KeyboardArrowDown,{sx:{fontSize:18}})}),t.jsx(o.Typography,{variant:"body2",className:`urm-group-title ${v.groupTitle||""}`,sx:{fontWeight:N===0?600:500,fontSize:N===0?"0.9375rem":"0.875rem",color:"text.primary",whiteSpace:"nowrap"},children:Ae}),!!C.__urm_is_continuation_header__&&t.jsx(o.Box,{className:"urm-group-continuation-badge",sx:{px:1,py:.25,fontSize:"0.7rem",fontWeight:500,lineHeight:1,whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",bgcolor:_e=>E(_e.palette.text.secondary,.05),color:"text.secondary",borderRadius:"10px",border:"1px dashed",borderColor:"divider",ml:.5},children:"Continued"}),t.jsx(o.Box,{className:`urm-group-count ${v.groupBadge||""} ${v.groupCount||""}`,sx:{px:1.25,py:.25,fontSize:"0.75rem",fontWeight:500,lineHeight:1,whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",bgcolor:_e=>E(_e.palette.text.secondary,.08),color:"text.secondary",borderRadius:"12px",ml:.5},children:rt}),Object.keys(C.aggregates||{}).length>0&&t.jsxs(o.Typography,{variant:"caption",className:`urm-group-aggregates ${v.groupAggregates||""}`,sx:{ml:1.5,color:"text.secondary",fontWeight:500},children:["(",Object.entries(C.aggregates).map(([_e,cr])=>ks(cr)).filter(Boolean).join(" • "),")"]})]})]})]},C.groupKey)},[Tr,pt,Dt,g,e,I,v,ee,Wo,at,qe]),Ao=f.useCallback((C,N)=>{const oe=at.has(C==null?void 0:C.__urm_row_id__),Ce=Gt===N,Ae=yt&&(C==null?void 0:C.__urm_row_id__)===(Yt==null?void 0:Yt.__urm_row_id__),rt=!!(C!=null&&C.__urm_is_grouped_data_row__),Xe=rt?C.__urm_group_level__??(g==null?void 0:g.levels.length)??1:0;return t.jsxs(o.TableRow,{"data-row-index":N,className:rt?`urm-data-row-grouped ${v.dataRowGrouped||""}`:"",onMouseEnter:()=>ar(N),onMouseLeave:()=>ar(null),onClick:fe=>{fe.target.closest("[data-row-action-btn]")||xo(N,fe)},onDoubleClick:()=>{Ze!=null&&Ze.includes("doubleClick")&&(be(C),Z(!0))},onContextMenu:fe=>{fe.preventDefault(),fe.stopPropagation(),gt==null||gt(C,N,fe),st(null),Ge({mouseX:fe.clientX,mouseY:fe.clientY,row:C,rowIndex:N}),Ze!=null&&Ze.includes("rightClick")&&(be(C),Z(!0))},sx:{cursor:"pointer",bgcolor:oe?fe=>it(fe).bg:Ae?fe=>E(fe.palette.info.main,.12):ee!=null&&ee.striped&&N%2===1?ee.stripeBg:"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:oe?fe=>it(fe).hoverBg:Ae?fe=>E(fe.palette.info.main,.2):fe=>`var(--highlight-hover-row, ${E(it(fe).main,.04)})`},borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider"},children:[Dt&&t.jsx(o.TableCell,{padding:"checkbox",onClick:fe=>fe.stopPropagation(),sx:{borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider",verticalAlign:(ee==null?void 0:ee.cellAlignV)??"middle"},children:t.jsx(o.Checkbox,{size:"small",checked:oe,onChange:()=>qe==null?void 0:qe(C)})}),pt.map((fe,Rt)=>{const Xt=Rt===0,_e=Tr.has(fe.name);return t.jsxs(o.TableCell,{className:rt&&Xt?`urm-data-cell-grouped ${v.dataCellGrouped||""}`:"",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:(ee==null?void 0:ee.rowPaddingY)??"6px",px:_e?0:(ee==null?void 0:ee.cellPaddingX)??2,position:"relative",textAlign:(ee==null?void 0:ee.cellAlignH)??"left",verticalAlign:(ee==null?void 0:ee.cellAlignV)??"middle",fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderRight:ee==null?void 0:ee.colDivider,borderColor:"divider",width:void 0,minWidth:y[fe.name]?`${y[fe.name]}px`:`${fe.type==="date"?Math.max(ps,180):ps}px`},children:[rt&&Xt&&Xe>0&&t.jsx(o.Box,{sx:{position:"absolute",left:4,top:0,bottom:0,width:"1px",bgcolor:"divider"}}),!_e&&t.jsx(o.Box,{sx:{display:"flex",alignItems:"center"},children:t.jsx("span",{className:`urm-item-title ${v.itemTitle||""}`,children:Pu(fe,C[fe.name],co,We)})})]},fe.name)}),t.jsx(o.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:0,minWidth:0,maxWidth:0,p:0,border:"none",background:"transparent",opacity:Ce?1:0,transition:"opacity 0.12s ease",zIndex:10},children:t.jsx(o.Box,{sx:{position:"absolute",right:8,top:0,bottom:0,display:"flex",alignItems:"center",justifyContent:"flex-end",zIndex:10},children:t.jsx(o.IconButton,{"data-row-action-btn":"true",size:"small",onClick:fe=>{fe.stopPropagation(),fe.preventDefault(),st(null),Ge({anchorEl:fe.currentTarget,row:C,rowIndex:N})},sx:{color:"text.secondary",opacity:Ce?1:0,transition:"opacity 0.12s ease",pointerEvents:Ce?"auto":"none","&:hover":{bgcolor:fe=>E(fe.palette.text.primary,.08),color:"text.primary"}},children:t.jsx($.MoreVert,{sx:{fontSize:18}})})})})]},N)},[ot,An,Gt,xo,Yr,y,We,Bn,tt,Qe,Wt,qe,Dt,be,Z,Yt,yt,Ge,Kr,Gr,gt,Ze]);return t.jsxs(Zt.DndProvider,{backend:ni.HTML5Backend,children:[t.jsxs(o.Box,{sx:C=>{var rt,Xe,fe;const N=((fe=(Xe=(rt=C.components)==null?void 0:rt.MuiCard)==null?void 0:Xe.styleOverrides)==null?void 0:fe.root)||{},oe=N.border&&N.border!=="none"?N.border:"1px solid",Ce=N.borderRadius!==void 0?typeof N.borderRadius=="number"?`${N.borderRadius}px`:N.borderRadius:`${C.shape.borderRadius}px`,Ae=N.boxShadow&&N.boxShadow!=="none"?N.boxShadow:ge(C,"cardRest");return{display:"flex",flexDirection:"column",height:"100%",bgcolor:"background.paper",border:oe,borderColor:oe!=="none"?"divider":void 0,borderRadius:Ce,boxShadow:Ae,overflow:"hidden"}},children:[t.jsxs(o.Box,{sx:C=>{var rt,Xe,fe,Rt,Xt;const N=((fe=(Xe=(rt=C.components)==null?void 0:rt.MuiCardHeader)==null?void 0:Xe.styleOverrides)==null?void 0:fe.root)||{},oe=(N.backgroundColor&&N.backgroundColor!=="transparent"?N.backgroundColor:void 0)??((Rt=C.tokens)==null?void 0:Rt.cardHdrHex)??((Xt=C.urmTable)==null?void 0:Xt.headerBg)??C.palette.background.paper,Ce=N.borderBottom&&N.borderBottom!=="none"?N.borderBottom:"1px solid",Ae=N.boxShadow&&N.boxShadow!=="none"?N.boxShadow:void 0;return{position:"sticky",top:0,zIndex:10,bgcolor:oe,borderBottom:Ce,borderColor:Ce!=="none"?"divider":void 0,boxShadow:Ae,px:2,py:0,minHeight:56,display:"flex",alignItems:"center",gap:1}},children:[Je&&t.jsx(Cu,{}),Ft&&dt&&Or&&Ot&&!(ke!=null&&ke.includes("search"))&&t.jsx(o.Tooltip,{open:Fr,title:t.jsxs(o.Box,{sx:{p:.5},children:[t.jsx(o.Typography,{variant:"caption",sx:{display:"block",fontWeight:C=>C.typography.caption.fontWeight||500,mb:.25},children:"💡 Search tip"}),t.jsx(o.Typography,{variant:"caption",children:"Type to search across all columns instantly"})]}),placement:"bottom-start",arrow:!0,PopperProps:{onClick:Hr},componentsProps:{tooltip:{sx:{bgcolor:"primary.main","& .MuiTooltip-arrow":{color:"primary.main"},maxWidth:220,cursor:"pointer",userSelect:"none"}}},children:t.jsx(o.Box,{component:"span",children:t.jsx(iu,{value:Y||"",onChange:C=>{Fr&&Hr(),Ft(C)},searchHistory:kt,onAddToHistory:dt,onToggleFavourite:Or,onDeleteHistory:Ot,disabled:Je})})}),t.jsx(o.Tooltip,{title:"JSON format guide",children:t.jsx(o.IconButton,{size:"small",onClick:()=>Lr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:C=>E(C.palette.text.primary,.06),color:"text.primary"}},children:t.jsx($.InfoOutlined,{sx:{fontSize:20}})})}),B&&T&&j&&s.length>0&&t.jsx(su,{views:s||[],activeViewId:a||"",isDirty:c,onSelectView:B,onCreateView:T,onToggleDefault:M,onToggleFavorite:G,onRestoreView:q,onPermanentDelete:R,onEditView:u,onCloneView:A,onCopyLink:F,onDeleteView:d,onPromoteToGlobal:ne,isAdmin:U,isReadOnly:Je}),c&&!Je&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25,ml:1},children:[j&&t.jsx(o.Button,{onClick:j,size:"small",variant:"contained",sx:{fontSize:"0.8125rem",fontWeight:500,px:2.25,py:.75,borderRadius:"10px",bgcolor:C=>`var(--urm-btn-save-current-bg, ${C.palette.primary.main})`,color:C=>`var(--urm-btn-save-current-color, ${C.palette.primary.contrastText})`,textTransform:"none",boxShadow:C=>ge(C,"restButton"),"&:hover":{bgcolor:C=>`var(--urm-btn-save-current-hover-bg, ${C.palette.primary.dark})`,boxShadow:C=>ge(C,"hoverButton")}},children:"Save current view"}),P&&t.jsx(o.Button,{onClick:P,size:"small",variant:"outlined",sx:{fontSize:"0.8125rem",fontWeight:500,px:2.25,py:.75,borderRadius:"10px",borderColor:C=>`var(--urm-btn-save-new-border, ${C.palette.primary.main})`,color:C=>`var(--urm-btn-save-new-color, ${C.palette.primary.main})`,bgcolor:C=>`var(--urm-btn-save-new-bg, ${C.palette.background.paper})`,borderWidth:"1.5px",textTransform:"none","&:hover":{borderWidth:"1.5px",borderColor:C=>`var(--urm-btn-save-new-hover-border, ${C.palette.primary.dark})`,bgcolor:C=>`var(--urm-btn-save-new-hover-bg, ${E(C.palette.primary.main,.08)})`}},children:"Save new view"}),_&&t.jsx(o.Button,{onClick:_,size:"small",variant:"contained",sx:{fontSize:"0.8125rem",fontWeight:500,px:2.25,py:.75,borderRadius:"10px",bgcolor:C=>`var(--urm-btn-discard-bg, ${E(C.palette.text.primary,.12)})`,color:C=>`var(--urm-btn-discard-color, ${C.palette.text.primary})`,textTransform:"none",boxShadow:"none","&:hover":{bgcolor:C=>`var(--urm-btn-discard-hover-bg, ${E(C.palette.text.primary,.18)})`,boxShadow:"none"}},children:"Discard"})]}),lo&&Mr&&t.jsx(o.Tooltip,{title:"Developer configuration",children:t.jsx(o.IconButton,{size:"small",onClick:Mr,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:C=>E(C.palette.text.secondary,.3),"&:hover":{bgcolor:C=>E(C.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:t.jsx($.DisplaySettings,{sx:{fontSize:20}})})}),t.jsx(o.Box,{sx:{flexGrow:1}}),!Je&&z&&!(ke!=null&&ke.includes("sort"))&&t.jsx(o.Tooltip,{title:"Sort",children:t.jsxs(o.IconButton,{onClick:z,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?C=>jt(C):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?C=>E(C.palette.primary.main,.2):C=>E(C.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[t.jsx($.SwapVert,{sx:{fontSize:20}}),n.length>0&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Je&&m&&!(ke!=null&&ke.includes("filter"))&&t.jsx(o.Tooltip,{title:"Filter",children:t.jsxs(o.IconButton,{onClick:m,size:"small",sx:{position:"relative",color:Kt>0?"primary.main":"text.secondary",bgcolor:Kt>0?C=>jt(C):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Kt>0?C=>E(C.palette.primary.main,.2):C=>E(C.palette.text.primary,.06),color:Kt>0?"primary.main":"text.primary"}},children:[t.jsx($.FilterList,{sx:{fontSize:20}}),Kt>0&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:Kt})]})}),!Je&&xe&&!(ke!=null&&ke.includes("columns"))&&t.jsx(o.Tooltip,{title:"Show/Hide Columns",children:t.jsxs(o.IconButton,{onClick:xe,size:"small",sx:{position:"relative",color:lr>0||Jr?"primary.main":"text.secondary",bgcolor:lr>0||Jr?C=>jt(C):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:lr>0||Jr?C=>E(C.palette.primary.main,.2):C=>E(C.palette.text.primary,.06),color:lr>0||Jr?"primary.main":"text.primary"}},children:[t.jsx($.ViewColumn,{sx:{fontSize:20}}),lr>0&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:lr})]})}),Kr&&(te||he)&&(()=>{var oe;const C=(((oe=g==null?void 0:g.collapsedGroups)==null?void 0:oe.length)??0)>0,N=C?te:he;return N?t.jsx(o.Tooltip,{title:C?"Expand all groups":"Collapse all groups",children:t.jsx(o.IconButton,{onClick:N,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:Ce=>E(Ce.palette.text.primary,.06),color:"text.primary"}},children:C?t.jsx($.UnfoldMore,{sx:{fontSize:20}}):t.jsx($.UnfoldLess,{sx:{fontSize:20}})})}):null})(),Ne.length>1&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),Ne.map(C=>{const N=nt===C,oe=C==="list"?t.jsx($.TableRows,{sx:{fontSize:20}}):t.jsx($.GridView,{sx:{fontSize:20}}),Ce=C==="list"?"List view":"Grid view";return t.jsx(o.Tooltip,{title:Ce,children:t.jsx(o.IconButton,{size:"small",onClick:()=>Et(C),sx:{borderRadius:1,color:N?"primary.main":"text.secondary",bgcolor:N?Ae=>jt(Ae):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:N?Ae=>E(Ae.palette.primary.main,.2):Ae=>E(Ae.palette.text.primary,.06),color:N?"primary.main":"text.primary"}},children:oe})},C)})]}),!(ke!=null&&ke.includes("settings"))&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),t.jsx(o.Tooltip,{title:"Settings",children:t.jsx(o.IconButton,{onClick:C=>Se(C.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:C=>E(C.palette.text.primary,.06),color:"text.primary"}},children:t.jsx($.Settings,{sx:{fontSize:20}})})})]})]}),t.jsxs(o.Popover,{open:!!me,anchorEl:me,onClose:()=>Se(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:200,py:.5,borderRadius:1.5,boxShadow:3}},children:[re&&!(ke!=null&&ke.includes("export"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{re(),Se(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Download,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Export"})]}),!Je&&Q&&!(ke!=null&&ke.includes("grouping"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Q(),Se(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Layers,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Grouping"})]}),se&&!(ke!=null&&ke.includes("auditHistory"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{se(),Se(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.History,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Audit History"})]}),ze&&!(ke!=null&&ke.includes("scheduledReports"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ze(),Se(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Scheduled Reports"})]}),or==null?void 0:or.map(C=>t.jsxs(o.MenuItem,{dense:!0,disabled:C.disabled,onClick:()=>{C.onClick(),Se(null)},sx:{py:1,px:2,gap:1.5},children:[C.icon,t.jsx(o.Typography,{variant:"body2",children:C.label})]},C.key))]}),t.jsxs(o.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[yr&&yr.length>0&&at.size>0&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,px:2,py:1,bgcolor:C=>it(C).bg,borderBottom:"1px solid",borderColor:"divider"},children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:C=>C.typography.body2.fontWeight||600,mr:1},children:[at.size," selected"]}),t.jsx(o.Button,{size:"small",onClick:()=>xt==null?void 0:xt(),children:"Clear"}),yr.map(C=>{var oe,Ce;const N=Array.from(ot);return(oe=C.hidden)!=null&&oe.call(C,N)?null:t.jsx(o.Button,{size:"small",variant:"outlined",startIcon:C.icon,disabled:(Ce=C.disabled)==null?void 0:Ce.call(C,N),onClick:()=>C.onClick(N),children:C.label},C.key)})]}),nt!=="list"&&t.jsx(o.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:t.jsx(bu,{data:Me,visibleColumns:Ur,grouping:g,selectedRowIds:ot,isGrouped:!!Kr,onToggleGroupCollapse:I,onCardClick:(C,N)=>xo(C,N),onCardDoubleClick:C=>{Ze!=null&&Ze.includes("doubleClick")&&(be(C),Z(!0))},onCardContextMenu:(C,N,oe)=>{gt==null||gt(C,N,oe),st(null),Ge({mouseX:oe.clientX,mouseY:oe.clientY,row:C,rowIndex:N}),Ze!=null&&Ze.includes("rightClick")&&(be(C),Z(!0))},onOpenRowMenu:(C,N,oe)=>Ge({anchorEl:oe,row:C,rowIndex:N}),onToggleSelection:C=>qe==null?void 0:qe(C),hideSelectionCheckboxes:Ht})}),nt==="list"&&t.jsxs(o.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[t.jsx(o.Box,{ref:Vr,onScroll:C=>{ho.current&&(ho.current.scrollLeft=C.target.scrollLeft)},sx:{overflowX:"auto",overflowY:"hidden",flexShrink:0,scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:t.jsxs(o.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(qr).reduce((C,N)=>C+N,0)}px`},children:[t.jsxs("colgroup",{children:[Dt&&t.jsx("col",{style:{width:"40px"}}),pt.map(C=>t.jsx("col",{style:{width:`${qr[C.name]}px`}},C.name))]}),t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{sx:{bgcolor:(ee==null?void 0:ee.headerBg)??"action.hover",borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider"},children:[Dt&&t.jsx(o.TableCell,{padding:"checkbox",sx:{borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider",verticalAlign:(ee==null?void 0:ee.cellAlignV)??"middle"},children:t.jsx(o.Checkbox,{size:"small",checked:Mo,indeterminate:Rn,onChange:C=>zt==null?void 0:zt(C.target.checked,Me)})}),pt.map((C,N)=>{const oe=Tr.has(C.name);return t.jsx(cu,{column:C,index:N,isGrouped:oe,sortRule:n.find(Ce=>Ce.column===C.name),hasFilters:Xn(i,C.name),isInSortStack:n.some(Ce=>Ce.column===C.name),isReadOnly:Je,hasModifications:Wn,width:oe?32:y[C.name],onColumnClick:In,onMoveColumn:En,onColumnDragEnd:Dn,onResizeStart:Tn,onSortAscending:k||$n,onSortDescending:b||_n,onRemoveSort:On,onOpenFilterForColumn:h||(()=>{}),onClearFiltersForColumn:le||(()=>{}),onGroupByColumn:de,onHideColumn:Mn,onManageColumns:xe||(()=>{}),onResetLayout:ie},C.name)})]})})]})}),t.jsx(o.Box,{ref:ho,onScroll:C=>{Vr.current&&(Vr.current.scrollLeft=C.target.scrollLeft)},sx:{flex:1,overflowY:"auto",overflowX:"auto",minHeight:0,bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:C=>E(C.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:C=>E(C.palette.text.primary,.3)}}},children:t.jsxs(o.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(qr).reduce((C,N)=>C+N,0)}px`},children:[t.jsxs("colgroup",{children:[Dt&&t.jsx("col",{style:{width:"40px"}}),pt.map(C=>t.jsx("col",{style:{width:`${qr[C.name]}px`}},C.name))]}),t.jsx(o.TableBody,{children:Me.length===0?t.jsx(o.TableRow,{children:t.jsx(o.TableCell,{colSpan:pt.length+(Dt?1:0),align:"center",sx:{py:4},children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):Kr?Me.map((C,N)=>C.isGroupHeader?Xr(C):Ao(C,N)):Me.map((C,N)=>Ao(C,N))})]})})]}),Tt&&mr&&t.jsx(Su,{currentPage:so,pageSize:rr,totalRows:ao,totalFields:e.length,onPageChange:Tt,onPageSizeChange:mr}),!(Tt&&mr)&&t.jsx(o.Box,{sx:{px:3,py:1.5,bgcolor:"action.hover",borderTop:1,borderColor:"divider"},children:t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["Showing ",Me.length," ",Me.length===1?"row":"rows"]})})]})]}),t.jsxs(o.Popover,{open:!!ve,onClose:()=>{Ge(null),st(null)},anchorEl:(ve==null?void 0:ve.anchorEl)||null,anchorReference:ve!=null&&ve.anchorEl?"anchorEl":"anchorPosition",anchorPosition:ve&&!ve.anchorEl?{top:ve.mouseY,left:ve.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:ve!=null&&ve.anchorEl?{vertical:"top",horizontal:"right"}:{vertical:"top",horizontal:"left"},PaperProps:{sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3}},children:[!(Ve!=null&&Ve.includes("view"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ve&&(be(ve.row),Z(!0)),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"View"})]}),!(Ve!=null&&Ve.includes("edit"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ve&&(qt(ve.row),Nr(ve.rowIndex),Rr(!0)),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Edit,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Edit"})]}),!(Ve!=null&&Ve.includes("duplicate"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ve&&(Qe==null||Qe(ve.rowIndex,ve.row)),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Duplicate"})]}),ve&&(xr==null?void 0:xr.map(C=>{var N,oe;return(N=C.hidden)!=null&&N.call(C,ve.row)?null:t.jsxs(o.MenuItem,{dense:!0,disabled:(oe=C.disabled)==null?void 0:oe.call(C,ve.row),onClick:()=>{C.onClick(ve.row,ve.rowIndex),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[C.icon,t.jsx(o.Typography,{variant:"body2",children:C.label})]},C.key)})),at.size>0&&tr&&!(Ve!=null&&Ve.includes("export"))&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.MenuItem,{dense:!0,onMouseEnter:C=>{It(),st(C.currentTarget)},onMouseLeave:kr,sx:{py:1,px:2,gap:1.5,justifyContent:"space-between"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx($.Download,{sx:{fontSize:18,color:"text.secondary"}}),t.jsxs(o.Typography,{variant:"body2",children:["Export Selected (",at.size,")"]})]}),t.jsx($.ChevronRight,{sx:{fontSize:18,color:"text.secondary"}})]}),t.jsx(o.Popper,{open:!!wr,anchorEl:wr,placement:"right-start",transition:!0,sx:{zIndex:C=>C.zIndex.modal+1},modifiers:[{name:"offset",options:{offset:[0,0]}}],children:({TransitionProps:C})=>t.jsx(o.Grow,{...C,timeout:150,children:t.jsx(o.Paper,{onMouseEnter:It,onMouseLeave:kr,sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3},children:t.jsxs(o.MenuList,{dense:!0,autoFocusItem:!1,children:[t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{tr("csv"),st(null),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.TableChart,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"CSV"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{tr("excel"),st(null),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.TableChart,{sx:{fontSize:18,color:"success.main"}}),t.jsx(o.Typography,{variant:"body2",children:"Excel"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{tr("json"),st(null),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.DataObject,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"JSON"})]})]})})})})]}),!(Ve!=null&&Ve.includes("delete"))&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ve&&(jr(ve.row),ye(!0)),Ge(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[t.jsx($.Delete,{sx:{fontSize:18,color:"error.main"}}),t.jsx(o.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]}),t.jsx(ku,{open:yt,onClose:()=>{Z(!1),be(null)},row:Yt,schema:e,reportName:Vt}),t.jsx(Tu,{open:uo,onClose:()=>{Rr(!1),qt(null),Nr(null)},onSave:C=>{Pr!==null&&(tt==null||tt(Pr,C))},row:po,schema:e,reportName:Vt}),t.jsx(zu,{open:pe,onClose:()=>{ye(!1),jr(null)},onConfirm:()=>{Cr!==null&&(Wt==null||Wt(Cr))},row:Cr,schema:e}),t.jsx(Js,{isOpen:zr,onClose:()=>Lr(!1)})]})}function $r({content:e,isDev:r=!1}){const[n,i]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(o.IconButton,{size:"small",onClick:s=>i(s.currentTarget),"aria-label":`Help: ${e.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:s=>E(s.palette.primary.main,.08)}},children:t.jsx($.InfoOutlined,{sx:{fontSize:15}})}),t.jsxs(o.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:{width:280,borderRadius:"10px",boxShadow:4,p:0,overflow:"hidden"}},children:[t.jsx(o.Box,{sx:{px:2,py:1.5,bgcolor:s=>E(s.palette.primary.main,.06)},children:t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:s=>s.typography.body2.fontWeight||600,color:"primary.main",fontSize:s=>s.typography.body2.fontSize||"0.875rem"},children:e.title})}),t.jsx(o.Divider,{}),t.jsxs(o.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:s=>s.typography.body2.fontSize||"0.8125rem",lineHeight:1.6},children:e.description}),e.tips&&e.tips.length>0&&t.jsx(o.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:e.tips.map((s,a)=>t.jsx(o.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},a))}),r&&e.devNote&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:s=>E(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>E(s.palette.warning.main,.2)},children:[t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:s=>s.typography.caption.fontWeight||500,fontSize:s=>s.typography.caption.fontSize||"0.75rem",display:"block",mb:.25},children:"Dev note"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",fontSize:s=>s.typography.caption.fontSize||"0.75rem",lineHeight:1.5},children:e.devNote})]})]})]})]})]})}const _r={filter:{title:"Filter columns",description:"Narrow down rows by setting conditions on any column. Only rows matching all active filters are shown.",tips:["Add multiple conditions to combine filters (AND logic)",'Use "Contains" for partial text matches','Use "Is empty" to find missing values',"Clear all filters to return to the full dataset"],devNote:"Max filter conditions controlled by DevConfig → Filter → maxConditions. Allowed operators also configurable."},sort:{title:"Sort columns",description:"Order rows by one or more columns. Drag levels to set sort priority — the first level is applied first.",tips:["Add multiple sort levels for multi-column sorting","Drag the ⋮⋮ handle to reorder sort priority","Each level can be ascending (A→Z, 0→9) or descending"],devNote:"Max sort levels controlled by DevConfig → Sort → maxLevels."},grouping:{title:"Group data",description:"Organize rows into collapsible groups by one or more column values. Each unique value becomes a group header.",tips:["Add up to 3 nesting levels for hierarchical grouping","Click a group header to collapse or expand it","Aggregates (count) are shown on each group header","Combine grouping with filters and sort for focused views"],devNote:"Max group levels controlled by DevConfig → Grouping → maxLevels. allowNested and allowCollapse also configurable."},columns:{title:"Manage columns",description:"Control which columns are visible, their display order, and their widths.",tips:["Drag rows to reorder columns","Toggle the eye icon to show or hide a column","Drag the resize handle in the table header to resize","Reset to restore default visibility and order"],devNote:"Max visible columns and width range controlled by DevConfig → Columns."},export:{title:"Export data",description:"Download the report data as a file. Choose between CSV, Excel, or JSON format.",tips:["CSV: universal format, opens in any spreadsheet app","Excel: formatted .xlsx file with native Excel support","JSON: structured data including metadata","Export visible rows only (after filters) or all rows"],devNote:"Allowed export formats controlled by DevConfig → Export → allowedFormats."},schedule:{title:"Scheduled reports",description:"Set up automatic exports that run at a specified time — daily, weekly, or monthly.",tips:["The browser tab must remain open for the schedule to fire","Each schedule triggers a file download automatically","Add an email address to open a notification in your mail app","Pause a schedule without deleting it"],devNote:"Schedules are stored in localStorage per-report. Key: urm_schedules_{reportId}."},auditHistory:{title:"Audit history",description:"A full log of all changes made to this report — filters applied, sorts changed, views saved, exports triggered, and more.",tips:["Each entry shows the action, timestamp, and who performed it","Use audit history to trace back unexpected changes"],devNote:"Audit entries are stored per-report in IndexedDB via the persistence layer."}},Kn=40;function Lu({operator:e,onSelect:r}){return t.jsxs(o.Select,{value:e,onChange:n=>r(n.target.value),size:"small",variant:"outlined",sx:{position:"relative",zIndex:1,mt:1,width:58,height:24,fontSize:"0.6875rem",fontWeight:700,color:"primary.main",bgcolor:"background.paper",borderRadius:"6px","& .MuiSelect-select":{py:0,px:1,display:"flex",alignItems:"center"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"}},children:[t.jsx(o.MenuItem,{value:"and",sx:{fontSize:"0.75rem",fontWeight:600},children:"AND"}),t.jsx(o.MenuItem,{value:"or",sx:{fontSize:"0.75rem",fontWeight:600},children:"OR"})]})}function Fu({condition:e,schema:r,availableColumns:n,devConfig:i,onUpdate:s}){const a=r.find(p=>p.name===e.column),c=f.useMemo(()=>{const p=a?rn(a.type):[],x=i.filter.allowedOperators;return x.length>0?p.filter(y=>x.includes(y.value)):p},[a,i]),l=El(e.operator);return t.jsxs(o.Box,{sx:{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},children:[t.jsx(o.FormControl,{size:"small",sx:{minWidth:150,flex:"1 1 150px"},children:t.jsx(o.Select,{value:e.column,onChange:p=>{var g;const x=r.find(v=>v.name===p.target.value),y=x?rn(x.type):[];s({column:p.target.value,operator:((g=y[0])==null?void 0:g.value)??e.operator,value:void 0})},displayEmpty:!0,sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper"},children:n.map(p=>t.jsx(o.MenuItem,{value:p.name,sx:{fontSize:"0.875rem"},children:lt(p.name)},p.name))})}),t.jsx(o.FormControl,{size:"small",sx:{minWidth:130,flex:"1 1 130px"},children:t.jsx(o.Select,{value:e.operator,onChange:p=>s({operator:p.target.value,value:void 0}),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper"},children:c.map(p=>t.jsx(o.MenuItem,{value:p.value,sx:{fontSize:"0.875rem"},children:p.label},p.value))})}),l&&(a==null?void 0:a.type)==="date"&&t.jsx(o.TextField,{size:"small",type:"date",value:e.value??"",onChange:p=>s({value:p.target.value}),sx:{minWidth:160,flex:"1 1 160px","& .MuiInputBase-root":{height:36,fontSize:"0.875rem"}}}),l&&(a==null?void 0:a.type)!=="date"&&t.jsx(o.TextField,{size:"small",type:(a==null?void 0:a.type)==="number"?"number":"text",value:e.value??"",onChange:p=>s({value:(a==null?void 0:a.type)==="number"?Number(p.target.value):p.target.value}),placeholder:"Value…",sx:{minWidth:160,flex:"1 1 160px","& .MuiInputBase-root":{height:36,fontSize:"0.875rem"}}})]})}function ta({group:e,depth:r,schema:n,availableColumns:i,devConfig:s,maxConditions:a,totalConditions:c,onChange:l}){const p=c>=a;return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[e.children.map((x,y)=>t.jsxs(o.Box,{sx:{display:"flex",alignItems:"stretch",gap:1},children:[t.jsxs(o.Box,{sx:{width:Kn,flexShrink:0,position:"relative",display:"flex",justifyContent:"center"},children:[y<e.children.length-1&&t.jsx(o.Box,{sx:{position:"absolute",top:0,bottom:0,left:"50%",width:"1px",bgcolor:"divider"}}),y>0&&t.jsx(Lu,{operator:e.operator,onSelect:g=>l(v=>ai(v,e.id,g))}),y>0&&t.jsx(o.Box,{sx:{position:"absolute",top:13,left:"50%",width:Kn/2,height:"1px",bgcolor:"divider"}})]}),t.jsx(o.Box,{sx:{flex:1,minWidth:0,pt:y>0?1:0},children:Ye(x)?t.jsx(Vu,{group:x,depth:r+1,schema:n,availableColumns:i,devConfig:s,maxConditions:a,totalConditions:c,onChange:l}):t.jsx(Fu,{condition:x,schema:n,availableColumns:i,devConfig:s,onUpdate:g=>l(v=>si(v,x.id,g))})}),t.jsx(o.IconButton,{size:"small",onClick:()=>l(g=>li(g,x.id)),sx:{mt:y>0?1:.25,color:"text.secondary",flexShrink:0},children:t.jsx($.Close,{sx:{fontSize:16}})})]},x.id)),t.jsxs(o.Box,{sx:{display:"flex",gap:2,pl:`${Kn}px`},children:[t.jsx(o.Button,{size:"small",disabled:p||i.length===0,onClick:()=>l(x=>{var y,g,v;return io(x,e.id,{id:no(),column:((y=i[0])==null?void 0:y.name)??"",operator:((v=rn(((g=i[0])==null?void 0:g.type)??"string")[0])==null?void 0:v.value)??"equals"})}),sx:{fontSize:"0.8125rem",color:"primary.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",textDecoration:"underline"}},children:"+ Add condition"}),t.jsx(o.Button,{size:"small",disabled:p,onClick:()=>l(x=>io(x,e.id,_t())),sx:{fontSize:"0.8125rem",color:"text.secondary",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",textDecoration:"underline"}},children:"+ Add group"})]})]})}function Vu(e){return t.jsx(o.Box,{sx:{position:"relative",border:"1px solid",borderColor:r=>E(r.palette.primary.main,.2),borderLeft:"3px solid",borderLeftColor:"primary.main",bgcolor:r=>E(r.palette.primary.main,r.palette.mode==="dark"?.06:.03),borderRadius:"8px",p:1.25},children:t.jsx(ta,{...e})})}function Hu({schema:e,filters:r,onReplaceFilters:n,onClose:i,focusColumn:s}){const[a,c]=f.useState(r??_t()),l=Dr(),p=f.useMemo(()=>e.filter(m=>m.type!=="mixed"&&m.type!=="null"&&m.type!=="array"&&m.type!=="object"),[e]);f.useEffect(()=>{var z;const m=r??_t();if(s&&m.children.length===0){const h=e.find(B=>B.name===s);if(h){c(io(m,m.id,{id:no(),column:s,operator:((z=rn(h.type)[0])==null?void 0:z.value)??"equals"}));return}}c(m)},[r,s,e]);const x=Ct(a),y=l.filter.maxConditions,g=f.useCallback(m=>{c(z=>m(z))},[]),v=f.useMemo(()=>JSON.stringify(a)!==JSON.stringify(r??_t()),[a,r]),S=f.useCallback(()=>{n(a),i()},[a,n,i]),k=f.useCallback(()=>{c(r??_t()),i()},[r,i]),b=f.useCallback(()=>{n(_t()),i()},[n,i]);return t.jsx(o.Box,{onClick:k,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:m=>E(m.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:m=>m.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:m=>m.stopPropagation(),elevation:0,sx:{position:"relative",width:640,maxWidth:"calc(100vw - 120px)",maxHeight:"min(620px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:m=>et(m),bgcolor:"background.paper",outline:"none",boxShadow:m=>ce(m).paper.boxShadow,border:m=>ce(m).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:m=>ce(m).header.backgroundColor,borderBottom:m=>ce(m).header.borderBottom,boxShadow:m=>ce(m).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:m=>m.typography.h6.fontSize||"1.125rem",fontWeight:m=>m.typography.h6.fontWeight||500,color:m=>m.typography.h6.color||"text.primary",lineHeight:1.5},children:"Filter columns"}),t.jsx($r,{content:_r.filter,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:k,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:m=>E(m.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:m=>E(m.palette.text.primary,.3)}}},children:[x===0&&t.jsxs(o.Typography,{variant:"body2",sx:{color:"text.disabled",fontSize:m=>m.typography.body2.fontSize||"0.875rem",mb:2},children:["No conditions yet — add one below to start filtering",s?` on "${lt(s)}"`:"","."]}),t.jsx(ta,{group:a,depth:0,schema:e,availableColumns:p,devConfig:l,maxConditions:y,totalConditions:x,onChange:g}),x>=y&&t.jsxs(o.Typography,{variant:"caption",sx:{display:"block",mt:1.5,color:"warning.dark",fontSize:m=>m.typography.caption.fontSize||"0.75rem",fontWeight:m=>m.typography.caption.fontWeight||500},children:["Filter limit reached — maximum ",y," conditions allowed. Remove one to add another."]})]}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",alignItems:"center",gap:1.5,justifyContent:"space-between",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:b,disabled:x===0,sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"text.disabled"}},children:"Clear all"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1.5},children:[t.jsx(o.Button,{onClick:k,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:m=>`${m.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:S,disabled:!v,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:m=>`${m.shape.borderRadius}px`,boxShadow:m=>ge(m,"restButton"),"&:hover":{bgcolor:"primary.dark"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})]})})}const hs="SORT_RULE";function Uu({rule:e,index:r,onToggleDirection:n,onRemove:i,onMove:s}){const a=f.useRef(null),[{handlerId:c},l]=Zt.useDrop({accept:hs,collect(y){return{handlerId:y.getHandlerId()}},hover(y,g){var h;if(!a.current)return;const v=y.index,S=r;if(v===S)return;const k=(h=a.current)==null?void 0:h.getBoundingClientRect(),b=(k.bottom-k.top)/2,m=g.getClientOffset(),z=((m==null?void 0:m.y)??0)-k.top;v<S&&z<b||v>S&&z>b||(s(v,S),y.index=S)}}),[{isDragging:p},x]=Zt.useDrag({type:hs,item:()=>({index:r}),collect:y=>({isDragging:y.isDragging()})});return x(l(a)),t.jsxs(o.Box,{ref:a,"data-handler-id":c,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:p?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:y=>ge(y,"restButtonLight"),transform:"translateY(-1px)"}},children:[t.jsx(o.Chip,{label:e.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:y=>`0 1px 2px 0 ${E(y.palette.primary.main,.3)}`,"& .MuiChip-label":{px:0}}}),t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[t.jsx(o.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),t.jsx(o.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),t.jsx(o.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:y=>y.typography.body2.fontSize||"0.875rem",fontWeight:y=>y.typography.body2.fontWeight||400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:e.column}),t.jsx(o.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:t.jsxs(o.Select,{value:e.direction,onChange:y=>n(r,y.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[t.jsx(o.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:y=>jt(y),"&:hover":{bgcolor:y=>E(y.palette.primary.main,.2)}}},children:"Ascending"}),t.jsx(o.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:y=>jt(y),"&:hover":{bgcolor:y=>E(y.palette.primary.main,.2)}}},children:"Descending"})]})}),t.jsx(o.IconButton,{onClick:()=>i(r),size:"small",sx:{p:.5,color:"text.secondary",transition:"all 0.2s ease","&:hover":{color:"error.main",bgcolor:y=>E(y.palette.error.main,.08),transform:"scale(1.1)"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]})}function Gu({schema:e,sortStack:r,onUpdateSortStack:n,onClose:i}){const[s,a]=f.useState(""),[c,l]=f.useState([]);f.useEffect(()=>{l([...r])},[r]);const p=f.useMemo(()=>JSON.stringify(c)!==JSON.stringify(r),[c,r]),x=Dr(),y=f.useCallback(h=>{if(!h||c.length>=x.sort.maxLevels)return;const B={column:h,direction:"asc",priority:c.length+1};l([...c,B]),a(""),setTimeout(()=>{var T;return(T=document.activeElement)==null?void 0:T.blur()},0)},[c,x.sort.maxLevels]),g=f.useCallback(h=>{const T=c.filter((j,P)=>P!==h).map((j,P)=>({...j,priority:P+1}));l(T)},[c]),v=f.useCallback((h,B)=>{const T=[...c];T[h]={...T[h],direction:B},l(T)},[c]),S=f.useCallback((h,B)=>{const T=[...c],[j]=T.splice(h,1);T.splice(B,0,j);const P=T.map((_,M)=>({..._,priority:M+1}));l(P)},[c]),k=f.useCallback(()=>{n([]),i()},[n,i]),b=f.useCallback(()=>{n(c),i()},[c,n,i]),m=f.useCallback(()=>{l([...r]),a(""),i()},[r,i]),z=e.filter(h=>!c.some(B=>B.column===h.name));return t.jsx(Zt.DndProvider,{backend:ni.HTML5Backend,children:t.jsx(o.Box,{onClick:m,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:h=>E(h.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:h=>h.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:h=>h.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:h=>et(h),bgcolor:"background.paper",outline:"none",boxShadow:h=>ce(h).paper.boxShadow,border:h=>ce(h).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:h=>ce(h).header.backgroundColor,borderBottom:h=>ce(h).header.borderBottom,boxShadow:h=>ce(h).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:h=>h.typography.h6.fontSize||"1.125rem",fontWeight:h=>h.typography.h6.fontWeight||500,color:h=>h.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),t.jsx($r,{content:_r.sort,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:m,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:h=>E(h.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:h=>E(h.palette.text.primary,.3)}}},children:[t.jsxs(o.Box,{sx:{mb:2.5},children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:h=>h.typography.caption.fontSize||"0.6875rem",fontWeight:h=>h.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,disabled:c.length>=x.sort.maxLevels,children:[t.jsx(o.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Select column..."}),t.jsx(o.Select,{value:s,onChange:h=>y(h.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:z.map(h=>t.jsx(o.MenuItem,{value:h.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:B=>jt(B),"&:hover":{bgcolor:B=>E(B.palette.primary.main,.2)}}},children:lt(h.name)},h.name))})]}),c.length>=x.sort.maxLevels&&t.jsxs(o.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:h=>h.typography.caption.fontSize||"0.75rem",fontWeight:h=>h.typography.caption.fontWeight||500},children:["Maximum ",x.sort.maxLevels," sort levels allowed"]})]}),c.length>0&&t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[t.jsxs(o.Typography,{variant:"overline",sx:{fontSize:h=>h.typography.caption.fontSize||"0.6875rem",fontWeight:h=>h.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",c.length,"/",x.sort.maxLevels,")"]}),t.jsx(o.Button,{onClick:k,sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map((h,B)=>t.jsx(Uu,{rule:h,index:B,onToggleDirection:v,onRemove:g,onMove:S},`${h.column}-${B}`))})]})]}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:m,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:h=>`${h.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:b,variant:"contained",disabled:!p||c.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:h=>`${h.shape.borderRadius}px`,boxShadow:h=>ge(h,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:h=>ge(h,"hoverButton")},"&:active":{boxShadow:h=>ge(h,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}const Go=50;function fs({currentSnapshot:e,onSave:r,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:a="",initialIsDefault:c=!1,atViewLimit:l=!1,maxViews:p=10}){const[x,y]=f.useState(s),[g,v]=f.useState(!1),[S,k]=f.useState(a),[b,m]=f.useState(c),z=()=>{if(!x.trim()){v(!0);return}if(x.trim().length>Go){v(!0);return}r(x.trim(),S.trim(),b),n()},h=T=>{T.key==="Enter"&&!T.shiftKey?z():T.key==="Escape"&&n()},B=()=>i&&s?`Update ${s} view`:"Create New Report View";return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:T=>({mt:8,borderRadius:et(T),...ce(T).paper})},children:[t.jsxs(o.DialogTitle,{sx:T=>({display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,...ce(T).header}),children:[B(),t.jsx(o.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&t.jsxs(o.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",p," saved views. Delete an existing view before creating a new one."]}),t.jsx(o.TextField,{label:"View Name",required:!0,value:x,onChange:T=>{T.target.value.length<=Go&&y(T.target.value),g&&T.target.value.trim()&&v(!1)},onKeyDown:h,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:Go},error:g&&!x.trim(),helperText:g&&!x.trim()?"View name is required":`${x.length} / ${Go}`}),t.jsx(o.TextField,{label:"Description (optional)",value:S,onChange:T=>k(T.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),t.jsxs(o.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:T=>T.typography.body2.fontWeight||500,mb:1},children:"This view will capture:"}),t.jsxs(o.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[t.jsxs("li",{children:[Ct(e.filters)," filter",Ct(e.filters)!==1?"s":""]}),t.jsxs("li",{children:["Sorting: ",Ga(e.sortStack)]}),t.jsx("li",{children:"Column order & visibility"})]})]}),!i&&t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:b,onChange:T=>m(T.target.checked),size:"small"}),label:t.jsx(o.Typography,{variant:"body2",children:"Set as default view"})})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:z,variant:"contained",disabled:l&&!i,startIcon:t.jsx($.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,boxShadow:T=>ge(T,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:T=>ge(T,"hoverButton")},"&:active":{boxShadow:T=>ge(T,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function Yu({viewName:e,onConfirm:r,onCancel:n}){return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:i=>({borderRadius:et(i),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",...ce(i).paper})},children:[t.jsxs(o.DialogTitle,{sx:i=>({display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,...ce(i).header}),children:["Delete View",t.jsx(o.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,mt:1},children:[t.jsx($.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),t.jsxs(o.Box,{children:[t.jsxs(o.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",t.jsxs("strong",{children:['"',e,'"']}),"?"]}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:r,variant:"contained",color:"error",sx:{fontSize:"0.875rem",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>ge(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>ge(i,"hoverButton")},"&:active":{boxShadow:i=>ge(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const Jo=100,Ko=600,ms="COLUMN";function qu({column:e,index:r,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:a,moveColumn:c}){const l=f.useRef(null),[p,x]=f.useState(i.toString());f.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:y},g]=Zt.useDrop({accept:ms,collect(h){return{handlerId:h.getHandlerId()}},hover(h,B){var q;if(!l.current)return;const T=h.index,j=r;if(T===j)return;const P=(q=l.current)==null?void 0:q.getBoundingClientRect(),_=(P.bottom-P.top)/2,M=B.getClientOffset(),G=((M==null?void 0:M.y)??0)-P.top;T<j&&G<_||T>j&&G>_||(c(T,j),h.index=j)}}),[{isDragging:v},S]=Zt.useDrag({type:ms,item:()=>({index:r}),collect:h=>({isDragging:h.isDragging()})});S(g(l));const k=()=>{const h=parseInt(p);if(isNaN(h)){x(i.toString()),a(e.name,i);return}const B=Math.max(Jo,Math.min(Ko,h));x(B.toString()),a(e.name,B)},b=h=>{if(h===""||/^\d+$/.test(h)){x(h);const B=parseInt(h);if(!isNaN(B)&&B>=Jo){const T=Math.min(Ko,B);a(e.name,T)}}},m=h=>{h.key==="Enter"&&(h.preventDefault(),k(),h.target.blur())},z=h=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[h]||"text.secondary";return t.jsxs(o.TableRow,{ref:l,"data-handler-id":y,sx:{opacity:v?.4:1,bgcolor:n?"background.paper":"action.hover",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"action.hover":"action.selected"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[t.jsx(o.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:t.jsx($.DragIndicator,{sx:{fontSize:20}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:h=>h.typography.body2.fontWeight||400,fontSize:h=>h.typography.body2.fontSize||"0.875rem",color:n?"text.primary":"text.secondary"},children:lt(e.name)})]})}),t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsx(o.Chip,{label:e.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${z(e.type)}15`,color:z(e.type),border:`1px solid ${z(e.type)}30`,"& .MuiChip-label":{px:1}}})}),t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.TextField,{type:"number",value:p,onChange:h=>b(h.target.value),onBlur:k,onKeyDown:m,placeholder:"150",size:"small",inputProps:{min:Jo,max:Ko,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"},"& input[type=number]::-webkit-inner-spin-button":{opacity:1},"& input[type=number]::-webkit-outer-spin-button":{opacity:1}}}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:h=>h.typography.caption.fontSize||"0.75rem",color:"text.secondary"},children:"px"})]})}),t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[t.jsx(o.IconButton,{onClick:()=>s(e.name,!n),title:n?"Hide column":"Show column",size:"small",sx:{p:.75,color:n?"primary.main":"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:n?"primary.dark":"primary.main"}},children:n?t.jsx($.Visibility,{sx:{fontSize:20}}):t.jsx($.VisibilityOff,{sx:{fontSize:20}})}),t.jsx(o.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?h=>E(h.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Ju({schema:e,columnVisibility:r,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:a="",onUpdateColumnVisibility:c,onUpdateColumnOrder:l,onUpdateColumnWidth:p,onResetLayout:x,onClose:y}){const[g,v]=f.useState(!1),[S,k]=f.useState(n),[b,m]=f.useState(i),[z,h]=f.useState("all");f.useEffect(()=>{k(n)},[n]),f.useEffect(()=>{m(i)},[i]);const B=(u,A)=>{m(F=>({...F,[u]:A})),p==null||p(u,A)},T=(u,A)=>{const F=[...S],[d]=F.splice(u,1);F.splice(A,0,d),k(F),l(F)},j=()=>{x(),v(!1)},_=S.map(u=>e.find(A=>A.name===u)).filter(u=>u!==void 0).filter(u=>{const A=r[u.name]??!0;return z==="active"?A:z==="hidden"?!A:!0}),M=Object.values(r).filter(u=>u).length,G=e.length,q=s.find(u=>u.id===a),R=f.useMemo(()=>{if(!q)return!1;const u=q.snapshot,A=u.columnVisibility??{},F=JSON.stringify(r)!==JSON.stringify(A),d=u.columnOrder??[],ne=n??[],U=JSON.stringify(ne)!==JSON.stringify(d)&&!(ne.length===0&&d.length===0),re=u.columnWidths??{},xe=JSON.stringify(b)!==JSON.stringify(re);return F||U||xe},[q,r,n,b]);return t.jsx(Zt.DndProvider,{backend:ni.HTML5Backend,children:t.jsx(o.Box,{onClick:y,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:u=>E(u.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:u=>u.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:u=>u.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:u=>et(u),bgcolor:"background.paper",outline:"none",boxShadow:u=>ce(u).paper.boxShadow,border:u=>ce(u).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2,pb:1.5,flexShrink:0,bgcolor:u=>ce(u).header.backgroundColor,borderBottom:u=>ce(u).header.borderBottom,boxShadow:u=>ce(u).header.boxShadow},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[t.jsx(o.Box,{sx:{flex:1},children:t.jsxs(o.Typography,{variant:"h6",sx:{fontSize:u=>u.typography.h6.fontSize||"1.125rem",fontWeight:u=>u.typography.h6.fontWeight||500,color:u=>u.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",t.jsx($r,{content:_r.columns,isDev:process.env.NODE_ENV==="development"})]})}),t.jsx(o.IconButton,{onClick:y,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Tabs,{value:z,onChange:(u,A)=>h(A),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:u=>it(u).main,height:3}},children:[t.jsx(o.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,px:2,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary",borderRadius:"8px 8px 0 0","&.Mui-selected":{borderBottomColor:"text.primary",fontWeight:600,bgcolor:u=>it(u).hoverBg},"&:hover":{color:"text.primary",bgcolor:u=>it(u).bg}}}),t.jsx(o.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,px:2,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary",borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:u=>it(u).hoverBg},"&:hover":{color:"text.primary",bgcolor:u=>it(u).bg}}}),t.jsx(o.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,px:2,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary",borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:u=>it(u).hoverBg},"&:hover":{color:"text.primary",bgcolor:u=>it(u).bg}}})]})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:u=>E(u.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:u=>E(u.palette.text.primary,.3)}}},children:t.jsxs(o.Table,{stickyHeader:!0,sx:{minWidth:650},children:[t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{children:[t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",t.jsx(o.Tooltip,{title:`Column width in pixels (min: ${Jo}px, max: ${Ko}px)`,arrow:!0,placement:"top",children:t.jsx($.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),t.jsx(o.TableBody,{children:_.length===0?t.jsx(o.TableRow,{children:t.jsx(o.TableCell,{colSpan:4,align:"center",sx:{py:6,borderBottom:"none"},children:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:u=>u.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):_.map((u,A)=>t.jsx(qu,{column:u,index:A,isVisible:r[u.name]??!0,width:b[u.name]||170,onToggleVisibility:c,onWidthChange:B,moveColumn:T},u.name))})]})}),t.jsx(o.Box,{sx:{px:3,py:1,borderTop:"1px solid divider",bgcolor:"background.default",flexShrink:0},children:t.jsxs(o.Typography,{variant:"body2",sx:{fontSize:u=>u.typography.body2.fontSize||"0.8125rem",color:"text.secondary"},children:[M," of ",G," columns visible • Drag to reorder"]})}),t.jsx(o.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"action.hover"},children:t.jsx(o.Button,{onClick:()=>v(!0),disabled:!R,variant:"outlined",startIcon:t.jsx($.Undo,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",px:2.5,py:.875,minHeight:36,borderRadius:u=>`${u.shape.borderRadius}px`,"&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Reset"})}),g&&t.jsx(o.Box,{onClick:()=>v(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:u=>E(u.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:u=>u.zIndex.tooltip},children:t.jsxs(o.Paper,{onClick:u=>u.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:u=>$o(u),bgcolor:"background.paper",boxShadow:u=>ce(u).paper.boxShadow,border:u=>ce(u).paper.border},children:[t.jsxs(o.Box,{sx:{px:3,py:2.5},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:()=>v(!1),variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,borderRadius:u=>`${u.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:j,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:u=>`${u.shape.borderRadius}px`,boxShadow:u=>ge(u,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:u=>ge(u,"hoverButton")},"&:active":{boxShadow:u=>ge(u,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function Ku({schema:e,grouping:r,onApply:n,onClose:i}){var P;const[s,a]=f.useState(r||{enabled:!1,levels:[],collapsedGroups:[]}),[c,l]=f.useState(""),[p,x]=f.useState(null),y=f.useMemo(()=>Pa(e),[e]),g=f.useMemo(()=>y.filter(_=>!s.levels.some((M,G)=>M.column===_.name&&G!==p)),[y,s.levels,p]),v=Dr(),S=s.levels.length<v.grouping.maxLevels&&g.length>0,k=f.useCallback(_=>{!S||!_||(a({...s,levels:[...s.levels,{column:_}],enabled:!0}),l(""),setTimeout(()=>{var M;return(M=document.activeElement)==null?void 0:M.blur()},0))},[S,s]),b=f.useCallback(_=>{const M=s.levels.filter((G,q)=>q!==_);if(M.length===0){n(null),i();return}a({...s,levels:M,enabled:M.length>0})},[s,n,i]),m=f.useCallback(_=>{x(_),l(s.levels[_].column)},[s.levels]),z=f.useCallback(()=>{if(p===null||!c)return;const _=[...s.levels];_[p]={column:c},a({...s,levels:_}),x(null),l("")},[p,c,s]),h=f.useCallback(()=>{x(null),l("")},[]),B=f.useCallback((_,M)=>{const G=M==="up"?_-1:_+1;if(G<0||G>=s.levels.length)return;const q=[...s.levels],[R]=q.splice(_,1);q.splice(G,0,R),a({...s,levels:q})},[s]),T=f.useCallback(()=>{n(null),i()},[n,i]),j=f.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(r==null?void 0:r.collapsedGroups)||[]}),i()},[s,r,n,i]);return t.jsx(o.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:_=>E(_.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:_=>_.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:_=>_.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:_=>et(_),bgcolor:"background.paper",outline:"none",boxShadow:_=>ce(_).paper.boxShadow,border:_=>ce(_).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:_=>ce(_).header.backgroundColor,borderBottom:_=>ce(_).header.borderBottom,boxShadow:_=>ce(_).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:_=>_.typography.h6.fontSize||"1.125rem",fontWeight:_=>_.typography.h6.fontWeight||500,color:_=>_.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),t.jsx($r,{content:_r.grouping,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:_=>E(_.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:_=>E(_.palette.text.primary,.3)}}},children:t.jsxs(o.Stack,{spacing:2.5,children:[p===null&&t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:_=>_.typography.caption.fontSize||"0.6875rem",fontWeight:_=>_.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),t.jsx(o.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:t.jsxs(o.Select,{value:c,onChange:_=>k(_.target.value),disabled:!S,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:[t.jsx(o.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),g.map(_=>t.jsxs(o.MenuItem,{value:_.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:M=>jt(M),"&:hover":{bgcolor:M=>E(M.palette.primary.main,.2)}}},children:[lt(_.name)," (",_.type.toUpperCase(),")"]},_.name))]})}),s.levels.length>=v.grouping.maxLevels&&t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:_=>_.typography.caption.fontSize||"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),y.length===0&&t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:_=>_.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),p!==null&&t.jsxs(o.Alert,{severity:"warning",sx:{borderRadius:"8px",border:_=>`1px solid ${E(_.palette.warning.main,.5)}`,bgcolor:_=>E(_.palette.warning.main,.12),"& .MuiAlert-icon":{color:"warning.main"}},children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:_=>_.typography.body2.fontWeight||500,mb:1.5,fontSize:_=>_.typography.body2.fontSize||"0.875rem",color:"text.primary"},children:["Edit Group Level ",p+1]}),t.jsx(o.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:t.jsxs(o.Select,{value:c,onChange:_=>l(_.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[t.jsx(o.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),t.jsxs(o.MenuItem,{value:s.levels[p].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:_=>jt(_)}},children:[s.levels[p].column," (",(P=e.find(_=>_.name===s.levels[p].column))==null?void 0:P.type.toUpperCase(),")"]}),g.filter(_=>_.name!==s.levels[p].column).map(_=>t.jsxs(o.MenuItem,{value:_.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:M=>jt(M)}},children:[lt(_.name)," (",_.type.toUpperCase(),")"]},_.name))]})}),t.jsxs(o.Stack,{direction:"row",spacing:1.5,children:[t.jsx(o.Button,{onClick:z,disabled:!c,variant:"contained",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",bgcolor:"warning.main",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"warning.dark",boxShadow:_=>ge(_,"pressedButton")}},children:"Save"}),t.jsx(o.Button,{onClick:h,variant:"outlined",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",py:.875,"&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},children:"Cancel"})]})]}),s.levels.length>0&&p===null&&t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.5},children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:_=>_.typography.caption.fontSize||"0.6875rem",fontWeight:_=>_.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),t.jsx(o.Button,{onClick:T,size:"small",sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),t.jsx(o.Stack,{spacing:1.5,children:s.levels.map((_,M)=>{const G=e.find(q=>q.name===_.column);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:q=>ge(q,"pressedButtonLight")}},children:[t.jsx(o.Chip,{label:`L${M+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:q=>`0 1px 2px 0 ${E(q.palette.primary.main,.3)}`}}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:q=>q.typography.body2.fontWeight||500,fontSize:q=>q.typography.body2.fontSize||"0.875rem",color:"text.primary"},children:_.column}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:q=>q.typography.caption.fontSize||"0.75rem",color:"text.secondary"},children:G==null?void 0:G.type.toUpperCase()})]}),t.jsxs(o.Stack,{direction:"row",spacing:.5,children:[t.jsx(o.IconButton,{size:"small",onClick:()=>B(M,"up"),disabled:M===0,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:t.jsx($.KeyboardArrowUp,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>B(M,"down"),disabled:M===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:t.jsx($.KeyboardArrowDown,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>m(M),sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover",color:"primary.main"}},children:t.jsx($.Edit,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>b(M),sx:{color:"text.secondary","&:hover":{bgcolor:q=>E(q.palette.error.main,.08),color:"error.main"}},children:t.jsx($.Delete,{sx:{fontSize:18}})})]})]},M)})})]})]})}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:i,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:_=>`${_.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:j,variant:"contained",disabled:s.levels.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:_=>`${_.shape.borderRadius}px`,boxShadow:_=>ge(_,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:_=>ge(_,"hoverButton")},"&:active":{boxShadow:_=>ge(_,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}function Xu({onExportAnyway:e,onSaveAndExport:r,onCancel:n}){return t.jsx(o.Box,{sx:{mb:2,mx:3,mt:2},children:t.jsxs(o.Alert,{severity:"warning",icon:t.jsx($.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:t.jsx($.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:i=>i.typography.h6.fontWeight||600,fontSize:i=>i.typography.h6.fontSize||"1rem",mb:.5},children:"You are exporting with unsaved view changes"}),t.jsx(o.Typography,{variant:"body2",sx:{mb:1.5},children:"Your current view has unsaved changes. Choose how to proceed:"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Button,{onClick:r,variant:"contained",color:"primary",startIcon:t.jsx($.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),t.jsx(o.Button,{onClick:e,variant:"contained",color:"warning",startIcon:t.jsx($.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const xs=[{key:"1h",label:"Last 1 Hour",ms:3600*1e3},{key:"24h",label:"Last 24 Hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 Days",ms:10080*60*1e3},{key:"30d",label:"Last 30 Days",ms:720*60*60*1e3},{key:"all",label:"All Time",ms:null}];function Qu(e,r){if(r===null)return e.length;const n=Date.now()-r;return e.filter(i=>new Date(i.timestamp).getTime()>=n).length}function Zu(e,r){if(r===null)return[];const n=Date.now()-r;return e.filter(i=>new Date(i.timestamp).getTime()<n)}function ep({auditHistory:e,onClose:r,onClearAuditHistory:n}){const i=ct(),s=i.palette,[a,c]=f.useState("1h"),[l,p]=f.useState(!1),x=[...e].sort((k,b)=>new Date(b.timestamp).getTime()-new Date(k.timestamp).getTime()),y=xs.find(k=>k.key===a),g=Qu(e,y.ms),v=()=>p(!0),S=()=>{n&&(n(Zu(e,y.ms)),p(!1))};return t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{onClick:r,sx:{position:"fixed",inset:0,bgcolor:E(s.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:i.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:k=>k.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:et(i),bgcolor:"background.paper",overflow:"hidden",...ce(i).paper,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,...ce(i).header},children:[t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body1.fontSize||"0.9375rem",fontWeight:k=>k.typography.h6.fontWeight||600,color:"text.primary"},children:"Audit History"}),t.jsx($r,{content:_r.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),t.jsxs(o.Typography,{sx:{fontSize:k=>k.typography.caption.fontSize||"0.75rem",color:"text.secondary",mt:.125},children:[x.length," event",x.length!==1?"s":""," recorded"]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&e.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Select,{value:a,onChange:k=>c(k.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:E(s.text.primary,.3)}},children:xs.map(k=>t.jsx(o.MenuItem,{value:k.key,sx:{fontSize:"0.8125rem"},children:k.label},k.key))}),t.jsx(o.Button,{size:"small",variant:"outlined",color:"error",startIcon:t.jsx($.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:v,sx:{fontSize:"0.75rem",borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:E(s.error.main,.5),"&:hover":{bgcolor:E(s.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),t.jsx(o.IconButton,{onClick:r,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:17}})})]})]}),t.jsx(o.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:E(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:E(s.text.primary,.14),borderRadius:3}},children:x.length===0?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[t.jsx($.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body1.fontSize||"0.9375rem",color:"text.secondary",fontWeight:k=>k.typography.body2.fontWeight||500},children:"No audit events yet"}),t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body2.fontSize||"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:x.map(k=>{const b=hu(i,k.feature),{summary:m,detail:z}=sl(k);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.25,px:1.5,py:1.25,borderRadius:"10px",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",transition:"border-color 0.15s","&:hover":{borderColor:E(s.text.primary,.18)}},children:[t.jsx(o.Chip,{label:cl(k.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:E(b,.1),color:b,border:`1px solid ${E(b,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),t.jsxs(o.Box,{sx:{flex:1,minWidth:0},children:[t.jsx(o.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:m}),z&&t.jsx(o.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:z}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[t.jsx($.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:dl(k.timestamp)})]}),k.user&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[t.jsx($.Person,{sx:{fontSize:11,color:"text.disabled"}}),t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:k.user})]})]})]})]},k.id)})})})]})}),t.jsxs(o.Dialog,{open:l,onClose:()=>p(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:$o(i),...ce(i).paper}},children:[t.jsxs(o.DialogContent,{sx:{pt:3,pb:2,px:3},children:[t.jsx(o.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:E(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body1.fontSize||"0.9375rem",fontWeight:k=>k.typography.h6.fontWeight||600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),t.jsxs(o.Typography,{sx:{fontSize:k=>k.typography.body2.fontSize||"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["You are about to permanently remove"," ",t.jsxs(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:[g," audit record",g!==1?"s":""]})," ",y.key==="all"?"from all time":`from the ${y.label.toLowerCase()}`,". This action cannot be undone."]})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[t.jsx(o.Button,{onClick:()=>p(!1),variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),t.jsxs(o.Button,{onClick:S,variant:"contained",color:"error",startIcon:t.jsx($.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{fontSize:"0.8125rem",borderRadius:"7px",px:2},children:["Clear ",g," Record",g!==1?"s":""]})]})]})]})}function tp({onSave:e,onClose:r}){const[n,i]=f.useState(""),[s,a]=f.useState(""),[c,l]=f.useState(""),[p,x]=f.useState([]),[y,g]=f.useState(""),[v,S]=f.useState(""),k=j=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(j),b=()=>{const j=c.trim();if(j){if(!k(j)){S("Please enter a valid email address");return}if(p.includes(j)){S("This email is already added");return}x([...p,j]),l(""),S("")}},m=j=>{x(p.filter(P=>P!==j))},z=j=>{j.key==="Enter"&&(j.preventDefault(),b())},h=()=>{if(!n.trim()){g("Preset name is required");return}e(n.trim(),s.trim(),p.length>0?p:void 0)},B=j=>{i(j),y&&g("")},T=j=>{l(j),v&&S("")};return t.jsx(o.Box,{onClick:r,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:j=>E(j.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:j=>j.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:j=>j.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:j=>et(j),bgcolor:"background.paper",outline:"none",boxShadow:j=>ce(j).paper.boxShadow,border:j=>ce(j).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:j=>ce(j).header.backgroundColor,borderBottom:j=>ce(j).header.borderBottom,boxShadow:j=>ce(j).header.boxShadow,flexShrink:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:j=>j.typography.h6.fontSize||"1.125rem",fontWeight:j=>j.typography.h6.fontWeight||500,color:j=>j.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),t.jsx(o.IconButton,{onClick:r,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:j=>E(j.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:j=>E(j.palette.text.primary,.3)}}},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[t.jsx(o.Alert,{severity:"info",icon:t.jsx($.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:j=>`1px solid ${E(j.palette.primary.main,.3)}`,bgcolor:j=>jt(j),"& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:j=>j.typography.body2.fontSize||"0.875rem",color:"text.secondary",lineHeight:1.6},children:"Save the current report configuration and generate a shareable link that others can use to view the same filters, sorting, and column layout."}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:j=>j.typography.caption.fontSize||"0.6875rem",fontWeight:j=>j.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),t.jsx(o.TextField,{required:!0,value:n,onChange:j=>B(j.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!y,helperText:y,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:j=>j.typography.caption.fontSize||"0.6875rem",fontWeight:j=>j.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),t.jsx(o.TextField,{value:s,onChange:j=>a(j.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:j=>j.typography.caption.fontSize||"0.6875rem",fontWeight:j=>j.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[t.jsx(o.TextField,{value:c,onChange:j=>T(j.target.value),onKeyPress:z,placeholder:"Enter email address",error:!!v,helperText:v,fullWidth:!0,size:"small",InputProps:{startAdornment:t.jsx($.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),t.jsx(o.Button,{onClick:b,variant:"outlined",startIcon:t.jsx($.Add,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",px:2,py:1.25,minHeight:40,borderRadius:j=>`${j.shape.borderRadius}px`,flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:"Add"})]}),p.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:p.map(j=>t.jsx(o.Chip,{label:j,onDelete:()=>m(j),deleteIcon:t.jsx($.Delete,{sx:{fontSize:16}}),sx:{bgcolor:P=>jt(P),color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},j))}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:p.length>0?`An email with the shareable link will be sent to ${p.length} recipient${p.length>1?"s":""}`:"Add email addresses to send the shareable link automatically"})]})]})}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:r,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:j=>`${j.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:h,variant:"contained",startIcon:t.jsx($.Share,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:j=>`${j.shape.borderRadius}px`,boxShadow:j=>ge(j,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:j=>ge(j,"hoverButton")},"&:active":{boxShadow:j=>ge(j,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function rp({presetName:e,onClear:r}){return t.jsx(o.Chip,{icon:t.jsx($.Link,{sx:{fontSize:14}}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Preset:"," ",t.jsx(o.Box,{component:"span",sx:{fontWeight:600},children:e})]}),onDelete:r,deleteIcon:t.jsx(o.IconButton,{size:"small",title:"Exit preset view",sx:{p:0},children:t.jsx($.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>E(n.palette.primary.main,.12),borderColor:"primary.light",border:1,fontSize:"body2.fontSize",fontWeight:500,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.main"}}}})}function op({presets:e,reportId:r,onOpenPreset:n,onDeletePreset:i,onClose:s}){const a=c=>new Date(c).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return t.jsx(o.Box,{onClick:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:c=>E(c.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:c=>c.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:c=>c.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:c=>et(c),bgcolor:"background.paper",outline:"none",boxShadow:c=>ce(c).paper.boxShadow,border:c=>ce(c).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:c=>ce(c).header.backgroundColor,borderBottom:c=>ce(c).header.borderBottom,boxShadow:c=>ce(c).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:c=>c.typography.h6.fontSize||"1.125rem",fontWeight:c=>c.typography.h6.fontWeight||500,color:c=>c.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:c=>c.typography.caption.fontSize||"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[e.length," saved ",e.length===1?"preset":"presets"]})]}),t.jsx(o.IconButton,{onClick:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:c=>E(c.palette.text.primary,.2)}}},children:e.length===0?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[t.jsx($.Share,{sx:{fontSize:48,color:"divider",mb:2}}),t.jsx(o.Typography,{variant:"body1",sx:{fontSize:c=>c.typography.body2.fontSize||"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:c=>c.typography.body2.fontSize||"0.8125rem",color:"text.disabled",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:e.map(c=>t.jsxs(o.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"background.paper",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:l=>ge(l,"restButtonLight")}},children:[t.jsx(o.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:t.jsxs(o.Box,{sx:{flex:1,minWidth:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:l=>l.typography.body1.fontSize||"0.9375rem",fontWeight:l=>l.typography.h6.fontWeight||500,color:"text.primary",mb:.5},children:c.name}),c.description&&t.jsx(o.Typography,{variant:"body2",sx:{fontSize:l=>l.typography.body2.fontSize||"0.8125rem",color:"text.secondary",lineHeight:1.5},children:c.description})]})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[t.jsx(o.Chip,{label:`Created ${a(c.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"action.hover",color:"text.secondary","& .MuiChip-label":{px:1}}}),t.jsx(o.Chip,{label:`By ${c.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"action.hover",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),t.jsx(o.Divider,{sx:{my:1.5,borderColor:"divider"}}),t.jsx(o.Box,{sx:{display:"flex",gap:1},children:t.jsx(o.Button,{onClick:()=>i(c.id,c.name),variant:"outlined",size:"small",startIcon:t.jsx($.Delete,{sx:{fontSize:16}}),sx:{fontSize:"0.8125rem",color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:l=>`${l.shape.borderRadius}px`,"&:hover":{borderColor:"error.main",bgcolor:l=>E(l.palette.error.main,.04)}},children:"Delete"})})]},c.id))})}),t.jsx(o.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:t.jsx(o.Button,{onClick:s,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:c=>`${c.shape.borderRadius}px`,boxShadow:c=>ge(c,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:c=>ge(c,"hoverButton")},"&:active":{boxShadow:c=>ge(c,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const ra={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},np=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],ip=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function sp(e,r){const n=[];for(const i of e){if(i.type!=="string")continue;const s=ip.some(l=>l.test(i.name));let a=!1;const c=r.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);c.length>0&&(a=c.filter(p=>np.some(x=>x.test(p))).length/c.length>.6),(s||a)&&n.push(i.name)}return n}function wn(e,r){if(e.length===0||r.length===0)return 0;const n=e.slice(0,Math.min(50,e.length)),s=r.map(c=>{const l=n.map(x=>String(x[c]??"")).filter(x=>x.length>0);if(l.length===0)return 5;const p=l.reduce((x,y)=>x+y.length,0);return Math.ceil(p/l.length)+1}).reduce((c,l)=>c+l,0)+1;return r.reduce((c,l)=>c+l.length+1,0)+s*e.length}function ap(e,r){const n=wn(e,r);return Math.ceil(n*3.5)}function lp(e,r){const n=wn(e,r);return Math.ceil(n*.7)}function cp(e,r){const n=wn(e,r);return Math.ceil(n*2)}function dp(e,r,n){switch(e){case"csv":return wn(r,n);case"excel":return lp(r,n);case"json":return ap(r,n);case"pdf":return cp(r,n)}}function gs(e,r){return Math.ceil(e/r)}function up(e,r,n,i,s=ra){const a=[],c=dp(e,r,n),l=r.length;if(l>s.maxRowsHard){const y=gs(l,s.maxRows);a.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${s.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${y} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:y,value:l,limit:s.maxRowsHard})}else if(l>s.maxRows){const y=gs(l,s.maxRows);a.push({type:"row_count",severity:"warning",message:`Large export: ${l.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${y} smaller export${y>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:y,value:l,limit:s.maxRows})}if(c>s.maxFileSizeHardBytes?a.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${ko(c)} exceeds the ${ko(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:c,limit:s.maxFileSizeHardBytes}):c>s.maxFileSizeBytes&&a.push({type:"file_size",severity:"warning",message:`Large file: estimated ${ko(c)}`,detail:`This exceeds the recommended ${ko(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:c,limit:s.maxFileSizeBytes}),e!=="excel"){const y=sp(i.filter(g=>n.includes(g.name)),r);if(y.length>0){const g=y.length>s.maxImageColumns;a.push({type:"image_columns",severity:g?"error":"warning",message:`Image column${y.length>1?"s":""} detected: ${y.map(v=>`"${v.replace(/_/g," ")}"`).join(", ")}`,detail:g?`Exporting ${y.length} image columns may produce a very large file. Consider hiding these columns before exporting.`:"Image URL columns are included in the export as plain text links — not embedded images.",value:y.length,limit:s.maxImageColumns})}}const p=a.some(y=>y.severity==="error"),x=a.some(y=>y.severity==="warning");return{violations:a,hasBlockingViolation:p,hasWarning:x,estimatedBytes:c}}function ko(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function pp({violation:e}){const n=ct().palette,i=e.severity==="error",s=i?n.error.main:n.warning.main,a=E(i?n.error.main:n.warning.main,.06),c=i?E(n.error.main,.25):E(n.warning.main,.3),l=i?$.ErrorOutline:$.WarningAmberOutlined;return t.jsxs(o.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"10px",bgcolor:a,border:"1px solid",borderColor:c},children:[t.jsx(l,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{sx:{fontSize:p=>p.typography.body2.fontSize||"0.8125rem",fontWeight:p=>p.typography.body2.fontWeight||600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:e.message}),e.detail&&t.jsx(o.Typography,{sx:{fontSize:p=>p.typography.caption.fontSize||"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:e.detail}),e.suggestedBatches&&e.suggestedBatches>1&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[t.jsx($.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),t.jsxs(o.Typography,{sx:{fontSize:p=>p.typography.caption.fontSize||"0.75rem",color:"text.secondary",fontWeight:p=>p.typography.body2.fontWeight||500},children:["Suggestion: split into ",e.suggestedBatches," exports"]})]})]})]})}function hp({format:e}){const r=ct(),n={csv:{color:r.palette.primary.main,bg:r.palette.primary.main,label:"CSV"},excel:{color:r.palette.success.main,bg:r.palette.success.main,label:"XLSX"},json:{color:r.palette.text.secondary,bg:r.palette.text.secondary,label:"JSON"},pdf:{color:r.palette.error.main,bg:r.palette.error.main,label:"PDF"}}[e];return t.jsxs(o.Box,{sx:{width:44,height:52,position:"relative",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",mb:1},children:[t.jsxs("svg",{width:"38",height:"46",viewBox:"0 0 38 46",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.jsx("path",{d:"M5 2C3.34315 2 2 3.34315 2 5V41C2 42.6569 3.34315 44 5 44H33C34.6569 44 36 42.6569 36 41V13L25 2H5Z",fill:r.palette.background.paper,stroke:n.color,strokeWidth:"2.5",strokeLinejoin:"round"}),t.jsx("path",{d:"M24 2V13H36",fill:E(r.palette.text.primary,.05),stroke:n.color,strokeWidth:"2.5",strokeLinejoin:"round"})]}),t.jsx(o.Box,{sx:{position:"absolute",bottom:8,left:3,right:3,bgcolor:n.bg,color:r.palette.primary.contrastText,fontSize:"0.625rem",fontWeight:800,py:.25,borderRadius:"3px",textAlign:"center",letterSpacing:"0.05em"},children:n.label})]})}function ys({checked:e}){const r=ct();return t.jsx(o.Box,{sx:{width:20,height:20,borderRadius:"50%",border:e?`2px solid var(--urm-export-card-selected-border, ${r.palette.primary.main})`:`2px solid var(--urm-export-radio-border, ${r.palette.divider})`,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:r.palette.background.paper,transition:"all 0.15s ease",flexShrink:0},children:e&&t.jsx(o.Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:`var(--urm-export-card-selected-border, ${r.palette.primary.main})`}})})}function fp({totalRows:e,visibleRows:r,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:a,sampleRows:c=[],allRows:l=[],processedRows:p=[],initialFormat:x,initialScope:y="visible",initialColumnScope:g="visible",classTokens:v={},onExport:S,onClose:k}){const b=ct(),m=b.palette,z=Dr(),h=f.useMemo(()=>{var ae,le,ie,Q,de;const U=((ie=(le=(ae=b.components)==null?void 0:ae.MuiCard)==null?void 0:le.styleOverrides)==null?void 0:ie.root)||{},re=U.border&&U.border!=="none"?U.border:(Q=b.tokens)!=null&&Q.cardBodyBorder&&b.tokens.cardBodyBorder!=="none"?b.tokens.cardBodyBorder:m.divider,xe=U.borderRadius!==void 0?typeof U.borderRadius=="number"?`${U.borderRadius}px`:U.borderRadius:`${b.shape.borderRadius}px`,V=U.boxShadow&&U.boxShadow!=="none"?U.boxShadow:((de=b.tokens)==null?void 0:de.cardBodyShadow)||ge(b,"menu"),X=it(b);return{sectionBorder:`var(--urm-export-section-border, ${re})`,sectionTitleColor:`var(--urm-export-section-title-color, ${m.text.primary})`,sectionTitleBg:`var(--urm-export-section-title-bg, ${m.background.paper})`,cardBg:`var(--urm-export-card-bg, ${m.background.paper})`,cardBorder:`var(--urm-export-card-border, ${re})`,cardRadius:xe,cardShadow:V,cardHoverBg:`var(--urm-export-card-hover-bg, ${m.mode==="dark"?E(m.common.white,.08):E(m.common.black,.04)})`,cardSelectedBg:`var(--urm-export-card-selected-bg, ${E(X.main,m.mode==="dark"?.16:.08)})`,cardSelectedBorder:`var(--urm-export-card-selected-border, ${X.main})`,cardSelectedColor:`var(--urm-export-card-selected-color, ${m.mode==="dark"?m.primary.light:m.primary.main})`,primaryBtnBg:`var(--urm-export-primary-btn-bg, ${m.primary.main})`,primaryBtnHoverBg:`var(--urm-export-primary-btn-hover-bg, ${m.primary.dark})`,primaryBtnColor:`var(--urm-export-primary-btn-color, ${m.primary.contrastText})`,sectionPadding:`var(--urm-export-section-padding, ${b.spacing(2)})`,optionGap:`var(--urm-export-option-gap, ${b.spacing(1.5)})`}},[m,b]),B=x||z.export.allowedFormats[0]||"csv",[T,j]=f.useState(B),[P,_]=f.useState(y),[M,G]=f.useState(g),q=P==="visible"?r:e,R=M==="visible"?i:s,u=f.useMemo(()=>P==="visible"?p.length>0?p:new Array(r):l.length>0?l:new Array(e),[P,r,e,p,l]),A=f.useMemo(()=>M==="all"?a.map(U=>U.name):a.map(U=>U.name).slice(0,i),[M,a,i]),F=f.useMemo(()=>up(T,u,A,a,ra),[T,u,A,a]),d=()=>{F.hasBlockingViolation||(S({format:T,scope:P,columnScope:M}),k())},ne={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON",pdf:"PDF"};return t.jsx(o.Box,{onClick:k,className:`urm-export-backdrop ${v.modalBackdrop||""}`,sx:{position:"fixed",inset:0,bgcolor:E(m.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:b.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:U=>U.stopPropagation(),elevation:0,className:`urm-export-paper ${v.modalPaper||""}`,sx:{width:540,maxWidth:"calc(100vw - 32px)",maxHeight:"min(760px, calc(100vh - 48px))",display:"flex",flexDirection:"column",borderRadius:et(b),bgcolor:h.sectionTitleBg,overflow:"hidden",border:`1px solid ${h.cardBorder}`,boxShadow:h.cardShadow,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{className:`urm-export-header ${v.modalHeader||""}`,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,pt:2.5,pb:1.5,flexShrink:0,bgcolor:U=>ce(U).header.backgroundColor,borderBottom:U=>ce(U).header.borderBottom,boxShadow:U=>ce(U).header.boxShadow},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Typography,{className:`urm-export-title ${v.modalTitle||""}`,sx:{fontSize:"1.125rem",fontWeight:700,color:m.text.primary},children:"Export Report"}),t.jsx($r,{content:_r.export,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:k,size:"small",className:`urm-export-close ${v.modalCloseButton||""}`,sx:{color:m.text.secondary,borderRadius:"50%","&:hover":{bgcolor:m.action.hover,color:m.text.primary}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Box,{className:`urm-export-content ${v.modalContent||""}`,sx:{flex:1,overflowY:"auto",px:3,pb:2.5,pt:.5,display:"flex",flexDirection:"column",gap:h.optionGap,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:E(m.text.primary,.15),borderRadius:3}},children:[F.violations.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:F.violations.map((U,re)=>t.jsx(pp,{violation:U},re))}),t.jsxs(o.Box,{className:`urm-export-section ${v.sectionContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Choose File Format"}),t.jsx(o.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:h.optionGap},children:[{id:"csv",title:"CSV",info:"Comma-separated values, compatible with Excel",allowed:z.export.allowedFormats.includes("csv")},{id:"excel",title:"Excel (.xlsx)",info:"Native Excel format with formatting support",allowed:z.export.allowedFormats.includes("excel")},{id:"json",title:"JSON",info:"Structured data with metadata and filters",allowed:z.export.allowedFormats.includes("json")},{id:"pdf",title:"PDF",info:"Print-ready PDF document",allowed:z.export.allowedFormats.includes("pdf")}].filter(U=>U.allowed).map(U=>{const re=T===U.id;return t.jsxs(o.Box,{onClick:()=>j(U.id),className:`urm-export-format-card ${re?v.formatCardSelected||"":v.formatCard||""}`,sx:{position:"relative",display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",p:1.75,borderRadius:h.cardRadius,border:re?`2px solid ${h.cardSelectedBorder}`:`1px solid ${h.cardBorder}`,boxShadow:re?void 0:h.cardShadow,bgcolor:re?h.cardSelectedBg:h.cardBg,cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:re?h.cardSelectedBorder:E(m.text.primary,.25),bgcolor:re?h.cardSelectedBg:h.cardHoverBg}},children:[re&&t.jsx(o.Box,{sx:{position:"absolute",top:8,right:8,width:20,height:20,borderRadius:"50%",bgcolor:h.cardSelectedBorder,color:m.primary.contrastText,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:`0 2px 4px ${E(m.primary.main,.3)}`},children:t.jsx($.Check,{sx:{fontSize:13,strokeWidth:2}})}),t.jsx(hp,{format:U.id}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.Typography,{sx:{fontSize:"0.875rem",fontWeight:700,color:re?h.cardSelectedColor:m.text.primary},children:U.title}),t.jsx(o.Tooltip,{title:U.info,arrow:!0,placement:"top",children:t.jsx(o.Box,{component:"span",onClick:xe=>xe.stopPropagation(),sx:{display:"inline-flex",cursor:"help",color:m.text.secondary,"&:hover":{color:m.text.primary}},children:t.jsx($.InfoOutlined,{sx:{fontSize:13}})})})]})]},U.id)})})]}),t.jsxs(o.Box,{className:`urm-export-section ${v.sectionContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Select Rows Range"}),t.jsx(o.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:h.optionGap},children:[{value:"visible",label:"Visible rows",icon:t.jsx($.VisibilityOutlined,{sx:{fontSize:20}}),info:`Export ${r.toLocaleString()} rows (filtered and searched)`},{value:"all",label:"All rows",icon:t.jsx($.TableChartOutlined,{sx:{fontSize:20}}),info:`Export ${e.toLocaleString()} rows (complete original dataset)`}].map(U=>{const re=P===U.value;return t.jsxs(o.Box,{onClick:()=>_(U.value),className:`urm-export-row-card ${re?v.rowCardSelected||"":v.rowCard||""}`,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:1.5,borderRadius:h.cardRadius,border:re?`2px solid ${h.cardSelectedBorder}`:`1px solid ${h.cardBorder}`,boxShadow:re?void 0:h.cardShadow,bgcolor:re?h.cardSelectedBg:h.cardBg,cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:re?h.cardSelectedBorder:E(m.text.primary,.25),bgcolor:re?h.cardSelectedBg:h.cardHoverBg}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx(ys,{checked:re}),t.jsx(o.Box,{sx:{color:re?h.cardSelectedColor:m.text.secondary,display:"flex"},children:U.icon}),t.jsx(o.Typography,{sx:{fontSize:"0.875rem",fontWeight:600,color:re?h.cardSelectedColor:m.text.primary},children:U.label})]}),t.jsx(o.Tooltip,{title:U.info,arrow:!0,placement:"top",children:t.jsx(o.Box,{component:"span",onClick:xe=>xe.stopPropagation(),sx:{display:"inline-flex",cursor:"help",color:m.text.secondary,"&:hover":{color:m.text.primary}},children:t.jsx($.InfoOutlined,{sx:{fontSize:16}})})})]},U.value)})})]}),t.jsxs(o.Box,{className:`urm-export-section ${v.sectionContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Select Columns Range"}),t.jsx(o.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:h.optionGap},children:[{value:"visible",label:"Visible columns",icon:t.jsx($.SwapVertOutlined,{sx:{fontSize:20}}),info:`Export ${i} visible column${i!==1?"s":""}`},{value:"all",label:"All columns",icon:t.jsx($.TableChartOutlined,{sx:{fontSize:20}}),info:`Export all ${s} columns (including hidden)`}].map(U=>{const re=M===U.value;return t.jsxs(o.Box,{onClick:()=>G(U.value),className:`urm-export-column-card ${re?v.columnCardSelected||"":v.columnCard||""}`,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:1.5,borderRadius:h.cardRadius,border:re?`2px solid ${h.cardSelectedBorder}`:`1px solid ${h.cardBorder}`,boxShadow:re?void 0:h.cardShadow,bgcolor:re?h.cardSelectedBg:h.cardBg,cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:re?h.cardSelectedBorder:E(m.text.primary,.25),bgcolor:re?h.cardSelectedBg:h.cardHoverBg}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx(ys,{checked:re}),t.jsx(o.Box,{sx:{color:re?h.cardSelectedColor:m.text.secondary,display:"flex"},children:U.icon}),t.jsx(o.Typography,{sx:{fontSize:"0.875rem",fontWeight:600,color:re?h.cardSelectedColor:m.text.primary},children:U.label})]}),t.jsx(o.Tooltip,{title:U.info,arrow:!0,placement:"top",children:t.jsx(o.Box,{component:"span",onClick:xe=>xe.stopPropagation(),sx:{display:"inline-flex",cursor:"help",color:m.text.secondary,"&:hover":{color:m.text.primary}},children:t.jsx($.InfoOutlined,{sx:{fontSize:16}})})})]},U.value)})})]}),t.jsxs(o.Box,{className:`urm-export-summary ${v.summaryContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Export Summary"}),t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[{icon:t.jsx($.InsertDriveFileOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Format",value:ne[T]},{icon:t.jsx($.FormatListNumberedOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Rows to Export",value:q.toLocaleString()},{icon:t.jsx($.SwapVertOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Columns to Export",value:String(R)},{icon:t.jsx($.InsertDriveFileOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Estimated File Size",value:`~${ko(F.estimatedBytes)}`,highlight:F.hasBlockingViolation?"error.main":F.hasWarning?"warning.main":void 0}].map(({icon:U,label:re,value:xe,highlight:V})=>t.jsxs(o.Box,{className:`urm-export-summary-row ${v.summaryRow||""}`,sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[U,t.jsx(o.Typography,{className:`urm-export-summary-label ${v.summaryLabel||""}`,sx:{fontSize:"0.8125rem",color:m.text.secondary,fontWeight:500},children:re})]}),t.jsx(o.Typography,{className:`urm-export-summary-value ${v.summaryValue||""}`,sx:{fontWeight:700,fontSize:"0.8125rem",color:V??m.text.primary},children:xe})]},re))})]})]}),t.jsxs(o.Box,{className:`urm-export-footer ${v.footer||""}`,sx:{px:3,py:2,display:"flex",alignItems:"center",justifyContent:"flex-end",gap:1.5,flexShrink:0},children:[F.hasBlockingViolation&&t.jsxs(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[t.jsx($.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),t.jsx(o.Typography,{sx:{fontSize:U=>U.typography.caption.fontSize||"0.75rem",color:"error.main",fontWeight:U=>U.typography.body2.fontWeight||500},children:"Reduce rows or columns to enable download"})]}),t.jsx(o.Button,{onClick:k,variant:"outlined",className:`urm-export-cancel-btn ${v.cancelButton||""}`,sx:{fontSize:"0.875rem",fontWeight:600,color:m.text.primary,borderColor:h.cardBorder,px:3,py:1,borderRadius:"8px",textTransform:"none","&:hover":{bgcolor:h.cardHoverBg,borderColor:E(m.text.primary,.3)}},children:"Cancel"}),t.jsxs(o.Button,{onClick:d,disabled:F.hasBlockingViolation,variant:"contained",className:`urm-export-download-btn ${v.downloadButton||""}`,startIcon:t.jsx($.Download,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",fontWeight:600,bgcolor:h.primaryBtnBg,color:h.primaryBtnColor,px:3,py:1,borderRadius:"8px",textTransform:"none",boxShadow:`0 2px 6px ${E(m.primary.main,.25)}`,"&:hover":{bgcolor:h.primaryBtnHoverBg},"&.Mui-disabled":{bgcolor:E(m.primary.main,.4),color:h.primaryBtnColor}},children:["Download ",ne[T]]})]})]})})}function mp({warning:e,onDismiss:r}){return t.jsx(o.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:t.jsxs(o.Alert,{severity:"warning",icon:t.jsx($.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"warning.main"},children:t.jsx($.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[t.jsx(o.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),t.jsx(o.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:e.message}),t.jsxs(o.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",e.type==="filter"?"filters":e.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function xp({error:e,onDismiss:r,autoDismiss:n=!0,autoDismissDelay:i=5e3}){f.useEffect(()=>{if(n){const l=setTimeout(()=>{r()},i);return()=>clearTimeout(l)}},[n,i,r]);const a=(()=>{switch(e.type){case"system":return{severity:"error",icon:t.jsx($.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:t.jsx($.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:t.jsx($.InfoOutlined,{sx:{fontSize:20}})}}})(),c=Sl(e);return t.jsx(o.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:t.jsxs(o.Alert,{severity:a.severity,icon:a.icon,action:t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:`${a.severity}.main`},children:t.jsx($.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${a.severity}.main`,boxShadow:3},children:[t.jsxs(o.AlertTitle,{sx:{fontWeight:l=>l.typography.h6.fontWeight||600,fontSize:l=>l.typography.subtitle2.fontSize||"0.875rem"},children:[e.context.charAt(0).toUpperCase()+e.context.slice(1)," Error"]}),t.jsx(o.Box,{sx:{fontSize:"body2.fontSize"},children:c}),e.details&&process.env.NODE_ENV==="development"&&t.jsx(o.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(e.details,null,2)})]})})}class gp extends f.Component{constructor(n){super(n);Ci(this,"handleReset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){Lt.error("urm:error-boundary","Caught unhandled component error",n,i),this.props.onError&&this.props.onError(n,i)}render(){var n,i;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsx(o.Paper,{sx:{bgcolor:s=>E(s.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx($.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:s=>s.typography.h6.fontWeight||600,fontSize:s=>s.typography.h6.fontSize||"1.25rem"},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),t.jsx(o.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((n=this.state.error)==null?void 0:n.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&t.jsx(o.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:s=>E(s.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:170},children:(i=this.state.error)==null?void 0:i.stack}),t.jsx(o.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:t.jsx($.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function yp({feature:e}){const[r,n]=f.useState(!0);return f.useEffect(()=>{const i=setTimeout(()=>n(!1),5e3);return()=>clearTimeout(i)},[]),t.jsx(o.Collapse,{in:r,unmountOnExit:!0,children:t.jsxs(o.Alert,{severity:"warning",sx:{m:1},icon:t.jsx($.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:t.jsx($.Close,{sx:{fontSize:16}})}),children:[t.jsxs(o.AlertTitle,{children:[e," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Yo({children:e,feature:r,onError:n}){return t.jsx(gp,{context:r,onError:i=>{n&&n(i)},fallback:t.jsx(yp,{feature:r}),children:e})}const bp=[{value:"equals",label:"Equals",group:"Text"},{value:"contains",label:"Contains",group:"Text"},{value:"startsWith",label:"Starts with",group:"Text"},{value:"endsWith",label:"Ends with",group:"Text"},{value:"gt",label:"Greater than (>)",group:"Numeric"},{value:"lt",label:"Less than (<)",group:"Numeric"},{value:"gte",label:"At least (≥)",group:"Numeric"},{value:"lte",label:"At most (≤)",group:"Numeric"},{value:"isTrue",label:"Is true",group:"Boolean"},{value:"isFalse",label:"Is false",group:"Boolean"},{value:"NULL",label:"Is empty (NULL)",group:"Null checks"},{value:"NOT_NULL",label:"Is not empty",group:"Null checks"}],vp=[{value:"csv",label:"CSV",desc:"Comma-separated values"},{value:"excel",label:"Excel (.xlsx)",desc:"Native Excel format"},{value:"json",label:"JSON",desc:"Structured data with metadata"},{value:"pdf",label:"PDF",desc:"Print-ready PDF document"}];function vo({children:e,active:r}){return t.jsx(o.Box,{hidden:!r,sx:{pt:2.5,pb:1,display:r?"flex":"none",flexDirection:"column",gap:2.5},children:e})}function Sp({open:e,onClose:r,config:n,onApply:i}){const[s,a]=f.useState(0),[c,l]=f.useState(n),p=()=>l(n),x=()=>l(ht),y=()=>{i(c),r()},g={sort:m=>l(z=>({...z,sort:{...z.sort,...m}})),filter:m=>l(z=>({...z,filter:{...z.filter,...m}})),columns:m=>l(z=>({...z,columns:{...z.columns,...m}})),grouping:m=>l(z=>({...z,grouping:{...z.grouping,...m}})),export:m=>l(z=>({...z,export:{...z.export,...m}}))},v=m=>{const z=c.filter.allowedOperators,h=z.includes(m)?z.filter(B=>B!==m):[...z,m];h.length!==0&&g.filter({allowedOperators:h})},S=m=>{const z=c.export.allowedFormats,h=z.includes(m)?z.filter(B=>B!==m):[...z,m];h.length!==0&&g.export({allowedFormats:h})},k=[{label:"Sort",icon:t.jsx($.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:t.jsx($.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:t.jsx($.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:t.jsx($.Layers,{sx:{fontSize:17}})},{label:"Export",icon:t.jsx($.Download,{sx:{fontSize:17}})}],b=m=>JSON.stringify(c[m])===JSON.stringify(ht[m]);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:p},PaperProps:{sx:{borderRadius:m=>et(m),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:m=>`0 8px 32px ${E(m.palette.common.black,.2)}`}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx(o.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:m=>E(m.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem"},children:"⚙️"}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle1",sx:{fontWeight:600,lineHeight:1.2},children:"Developer Configuration"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"Set runtime constraints · Ctrl+Shift+D"})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:t.jsx(o.Tabs,{value:s,onChange:(m,z)=>a(z),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:k.map((m,z)=>t.jsx(o.Tab,{label:m.label,icon:m.icon,iconPosition:"start"},z))})}),t.jsxs(o.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[t.jsxs(vo,{active:s===0,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!b("sort")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),t.jsx(o.Slider,{value:c.sort.maxLevels,onChange:(m,z)=>g.sort({maxLevels:z}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),t.jsxs(o.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",t.jsx("strong",{children:"5"}),"."]})]}),t.jsxs(vo,{active:s===1,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!b("filter")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),t.jsx(o.Slider,{value:c.filter.maxConditions,onChange:(m,z)=>g.filter({maxConditions:z}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),t.jsx(o.Divider,{}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(m=>t.jsxs(o.Box,{sx:{mb:1.5},children:[t.jsx(o.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:m}),t.jsx(o.FormGroup,{row:!0,sx:{gap:.5},children:bp.filter(z=>z.group===m).map(z=>t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{size:"small",checked:c.filter.allowedOperators.includes(z.value),onChange:()=>v(z.value)}),label:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:z.label}),sx:{mr:1.5}},z.value))})]},m))]})]}),t.jsxs(vo,{active:s===2,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!b("columns")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),t.jsx(o.Slider,{value:c.columns.maxVisible,onChange:(m,z)=>g.columns({maxVisible:z}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),t.jsx(o.Divider,{}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),t.jsxs(o.Box,{sx:{display:"flex",gap:2},children:[t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),t.jsx(o.Slider,{value:c.columns.minColumnWidth,onChange:(m,z)=>g.columns({minColumnWidth:z}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:m=>`${m}px`})]}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),t.jsx(o.Slider,{value:c.columns.maxColumnWidth,onChange:(m,z)=>g.columns({maxColumnWidth:z}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:m=>`${m}px`})]})]})]})]}),t.jsxs(vo,{active:s===3,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!b("grouping")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(m=>t.jsxs(o.Box,{onClick:()=>g.grouping({maxLevels:m}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:c.grouping.maxLevels===m?"primary.main":"divider",bgcolor:c.grouping.maxLevels===m?z=>E(z.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:z=>E(z.palette.primary.main,.04)}},children:[t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:700,color:c.grouping.maxLevels===m?"primary.main":"text.secondary"},children:m}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][m-1]})]},m))}),t.jsxs(o.FormGroup,{row:!0,sx:{gap:2},children:[t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:c.grouping.allowNested,onChange:m=>g.grouping({allowNested:m.target.checked})}),label:t.jsx(o.Typography,{variant:"body2",children:"Allow nested groups"})}),t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:c.grouping.allowCollapse,onChange:m=>g.grouping({allowCollapse:m.target.checked})}),label:t.jsx(o.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),t.jsx(o.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),t.jsx(vo,{active:s===4,children:t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!b("export")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),t.jsx(o.FormGroup,{sx:{gap:1},children:vp.map(m=>t.jsxs(o.Box,{onClick:()=>S(m.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:c.export.allowedFormats.includes(m.value)?"primary.main":"divider",bgcolor:c.export.allowedFormats.includes(m.value)?z=>E(z.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[t.jsx(o.Checkbox,{size:"small",checked:c.export.allowedFormats.includes(m.value),onChange:()=>S(m.value),onClick:z=>z.stopPropagation()}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500},children:m.label}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:m.desc})]})]},m.value))})]})})]}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:m=>E(m.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[t.jsx(o.Button,{startIcon:t.jsx($.RestartAlt,{sx:{fontSize:18}}),onClick:x,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:m=>E(m.palette.text.primary,.06)}},children:"Reset to defaults"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Button,{onClick:r,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),t.jsx(o.Button,{onClick:y,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Cp=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],jp={1:"1st",2:"2nd",3:"3rd",4:"4th",5:"5th",6:"6th",7:"7th",8:"8th",9:"9th",10:"10th",11:"11th",12:"12th",13:"13th",14:"14th",15:"15th",16:"16th",17:"17th",18:"18th",19:"19th",20:"20th",21:"21st",22:"22nd",23:"23rd",24:"24th",25:"25th",26:"26th",27:"27th",28:"28th"};function Xo(e,r,n,i,s=new Date){const[a,c]=r.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(a,c,0,0),e==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(e==="weekly"){const p=n??1,x=l.getDay();let y=p-x;return y<0&&(y+=7),y===0&&l<=s&&(y=7),l.setDate(l.getDate()+y),l.toISOString()}if(e==="monthly"){const p=Math.min(i??1,28);return l.setDate(p),l<=s&&(l.setMonth(l.getMonth()+1),l.setDate(p)),l.toISOString()}return l.toISOString()}function wp(e){const r=oa(e.time);return e.frequency==="daily"?`Daily at ${r}`:e.frequency==="weekly"?`Every ${Cp[e.dayOfWeek??1]} at ${r}`:e.frequency==="monthly"?`Monthly on the ${jp[e.dayOfMonth??1]??`${e.dayOfMonth}th`} at ${r}`:r}function oa(e){const[r,n]=e.split(":").map(Number),i=r>=12?"PM":"AM";return`${r%12||12}:${String(n).padStart(2,"0")} ${i}`}function kp(e){const r=new Date(e).getTime()-Date.now();if(r<=0)return"now";const n=Math.floor(r/1e3),i=Math.floor(n/86400),s=Math.floor(n%86400/3600),a=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${a}m`:a>0?`in ${a}m`:"in less than a minute"}function zp(e){const r=new Date(e),n=new Date,i=r.toDateString()===n.toDateString(),s=oa(`${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`);return i?`Today at ${s}`:`${r.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${s}`}function na(e){return`urm_schedules_${e}`}function ia(e){try{const r=localStorage.getItem(na(e));return r?JSON.parse(r).map(i=>({...i,runCount:typeof i.runCount=="number"?i.runCount:0,isActive:typeof i.isActive=="boolean"?i.isActive:!0,createdAt:i.createdAt||new Date().toISOString()})):[]}catch{return[]}}function sa(e,r){try{localStorage.setItem(na(e),JSON.stringify(r))}catch{}}const Tp=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"}],Bp=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,aa={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"pdf",scope:"all",email:""},Ir={"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:"8px"},"& .MuiInputLabel-root":{fontSize:"0.875rem"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:.5},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}};function Ip({initial:e=aa,isEditing:r=!1,onSave:n,onBack:i}){const[s,a]=f.useState(e),[c,l]=f.useState(!1),[p,x]=f.useState(!1),y=(S,k)=>a(b=>({...b,[S]:k})),g=s.email.trim().length>0&&!Bp.test(s.email.trim()),v=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.dayOfMonth<=28)&&!g;return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[t.jsx(o.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:S=>E(S.palette.text.primary,.06)}},children:t.jsx($.ArrowBack,{sx:{fontSize:18}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:S=>S.typography.body2.fontWeight||600,fontSize:S=>S.typography.body2.fontSize||"0.875rem"},children:r?"Edit schedule":"New schedule"})]}),t.jsx(o.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:S=>{y("name",S.target.value),c&&S.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:c&&!s.name.trim(),helperText:c&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:Ir}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:Ir,children:[t.jsx(o.InputLabel,{children:"Frequency"}),t.jsxs(o.Select,{value:s.frequency,label:"Frequency",onChange:S=>y("frequency",S.target.value),children:[t.jsx(o.MenuItem,{value:"daily",children:"Daily"}),t.jsx(o.MenuItem,{value:"weekly",children:"Weekly"}),t.jsx(o.MenuItem,{value:"monthly",children:"Monthly"})]})]}),s.frequency==="weekly"&&t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:Ir,children:[t.jsx(o.InputLabel,{children:"Day of week"}),t.jsx(o.Select,{value:s.dayOfWeek,label:"Day of week",onChange:S=>y("dayOfWeek",Number(S.target.value)),children:Tp.map(S=>t.jsx(o.MenuItem,{value:S.value,children:S.label},S.value))})]}),s.frequency==="monthly"&&t.jsx(o.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:S=>y("dayOfMonth",Number(S.target.value)),inputProps:{min:1,max:28},error:s.dayOfMonth<1||s.dayOfMonth>28,helperText:s.dayOfMonth<1||s.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Ir}),t.jsx(o.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:S=>y("time",S.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Ir}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:Ir,children:[t.jsx(o.InputLabel,{children:"Export format"}),t.jsxs(o.Select,{value:s.format,label:"Export format",onChange:S=>y("format",S.target.value),children:[t.jsx(o.MenuItem,{value:"pdf",children:"PDF — Print-ready document"}),t.jsx(o.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),t.jsx(o.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),t.jsx(o.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),t.jsxs(o.RadioGroup,{row:!0,value:s.scope,onChange:S=>y("scope",S.target.value),sx:{gap:2},children:[t.jsx(o.FormControlLabel,{value:"all",control:t.jsx(o.Radio,{size:"small"}),label:t.jsx(o.Typography,{variant:"body2",children:"All rows"})}),t.jsx(o.FormControlLabel,{value:"visible",control:t.jsx(o.Radio,{size:"small"}),label:t.jsx(o.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:s.email,onChange:S=>y("email",S.target.value),onBlur:()=>x(!0),placeholder:"user@company.com",error:p&&g,helperText:p&&g?"Enter a valid email address":void 0,InputProps:{startAdornment:t.jsx($.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Ir}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[t.jsx($.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),t.jsx(o.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[t.jsx(o.Button,{onClick:i,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:S=>E(S.palette.text.primary,.06)}},children:"Cancel"}),t.jsx(o.Button,{onClick:()=>v&&n(s),disabled:!v,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:r?"Save changes":"Create schedule"})]})]})}function Ep({scheduleName:e,onConfirm:r,onCancel:n}){return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:i=>({borderRadius:$o(i),...ce(i).paper})},children:[t.jsxs(o.DialogContent,{sx:{pt:3,pb:2,px:3},children:[t.jsx(o.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:i=>E(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),t.jsx(o.Typography,{sx:{fontSize:i=>i.typography.body1.fontSize||"0.9375rem",fontWeight:i=>i.typography.h6.fontWeight||600,color:"text.primary",mb:1},children:"Delete Schedule"}),t.jsxs(o.Typography,{sx:{fontSize:i=>i.typography.body2.fontSize||"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",t.jsxs(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',e,'"']}),"? This action cannot be undone."]})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[t.jsx(o.Button,{onClick:n,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:i=>`${i.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),t.jsx(o.Button,{onClick:r,variant:"contained",color:"error",sx:{fontSize:"0.8125rem",borderRadius:i=>`${i.shape.borderRadius}px`,px:2},children:"Delete"})]})]})}function Dp({schedule:e,tick:r,onToggle:n,onRunNow:i,onEdit:s,onDelete:a}){const c=e.isActive;return t.jsxs(o.Box,{sx:{border:"1px solid",borderColor:c?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:c?l=>E(l.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:c?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),t.jsx(o.Chip,{label:c?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:c?l=>E(l.palette.success.main,.1):l=>E(l.palette.text.primary,.06),color:c?"success.dark":"text.secondary"}})]}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:wp(e)}),t.jsxs(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5,mb:1},children:[t.jsx(o.Chip,{label:e.format.toUpperCase(),size:"small",sx:{height:20,fontSize:"0.6875rem",fontWeight:500,bgcolor:l=>E(l.palette.primary.main,.08),color:"primary.main"}}),t.jsx(o.Chip,{label:e.scope==="all"?"All rows":"Filtered rows",size:"small",sx:{height:20,fontSize:"0.6875rem",bgcolor:l=>E(l.palette.text.primary,.06),color:"text.secondary"}}),e.email&&t.jsx(o.Chip,{icon:t.jsx($.Email,{sx:{fontSize:11}}),label:e.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>E(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[t.jsxs(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[c&&t.jsxs(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",kp(e.nextRunAt)]}),e.lastRunAt?t.jsxs(o.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",zp(e.lastRunAt)," · ",e.runCount," run",e.runCount!==1?"s":""]}):t.jsx(o.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[t.jsx(o.Tooltip,{title:"Edit",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>s(e),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>E(l.palette.primary.main,.08)}},children:t.jsx($.Edit,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:c?"Pause":"Resume",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>n(e.id),sx:{color:c?"warning.main":"success.main","&:hover":{bgcolor:c?l=>E(l.palette.warning.main,.08):l=>E(l.palette.success.main,.08)}},children:c?t.jsx($.Pause,{sx:{fontSize:15}}):t.jsx($.PlayArrow,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:"Export now",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>i(e),sx:{color:"primary.main","&:hover":{bgcolor:l=>E(l.palette.primary.main,.08)}},children:t.jsx($.Download,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:"Delete",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>a(e.id),sx:{color:"error.main","&:hover":{bgcolor:l=>E(l.palette.error.main,.08)}},children:t.jsx($.Delete,{sx:{fontSize:15}})})})]})]})]})}function $p({open:e,onClose:r,reportId:n,reportName:i,onRunNow:s,schedulerConfig:a}){const l=((a==null?void 0:a.mode)??"local")==="api",[p,x]=f.useState([]),y=l?(a==null?void 0:a.schedules)??[]:p,[g,v]=f.useState({type:"list"}),[S,k]=f.useState(0),[b,m]=f.useState(null);f.useEffect(()=>{e&&(l||x(ia(n)),v({type:"list"}))},[e,n,l]),f.useEffect(()=>{if(!e)return;const R=setInterval(()=>k(u=>u+1),3e4);return()=>clearInterval(R)},[e]);const z=f.useCallback(R=>{x(R),sa(n,R)},[n]),h=R=>{var F;const u=Xo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth),A={id:`sched-${Date.now()}`,reportId:n,name:R.name.trim(),frequency:R.frequency,dayOfWeek:R.frequency==="weekly"?R.dayOfWeek:void 0,dayOfMonth:R.frequency==="monthly"?R.dayOfMonth:void 0,time:R.time,format:R.format,scope:R.scope,email:R.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:u,runCount:0};l?(F=a==null?void 0:a.onScheduleCreate)==null||F.call(a,A):z([...y,A]),v({type:"list"})},B=R=>{var d;if(g.type!=="edit")return;const u=g.schedule,A=Xo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth),F={...u,name:R.name.trim(),frequency:R.frequency,dayOfWeek:R.frequency==="weekly"?R.dayOfWeek:void 0,dayOfMonth:R.frequency==="monthly"?R.dayOfMonth:void 0,time:R.time,format:R.format,scope:R.scope,email:R.email.trim()||void 0,nextRunAt:A};l?(d=a==null?void 0:a.onScheduleUpdate)==null||d.call(a,F):z(y.map(ne=>ne.id===u.id?F:ne)),v({type:"list"})},T=R=>{var ne;const u=y.find(U=>U.id===R);if(!u)return;const A=!u.isActive,F=A?Xo(u.frequency,u.time,u.dayOfWeek,u.dayOfMonth):u.nextRunAt,d={...u,isActive:A,nextRunAt:F};l?(ne=a==null?void 0:a.onScheduleToggle)==null||ne.call(a,R,A):z(y.map(U=>U.id===R?d:U))},j=R=>{if(s(R),!l){const u=new Date().toISOString();z(y.map(A=>A.id===R.id?{...A,lastRunAt:u,runCount:A.runCount+1}:A))}},P=R=>{const u=y.find(A=>A.id===R)??null;m(u)},_=()=>{var R;b&&(l?(R=a==null?void 0:a.onScheduleDelete)==null||R.call(a,b.id):z(y.filter(u=>u.id!==b.id)),m(null))},M=R=>({name:R.name,frequency:R.frequency,dayOfWeek:R.dayOfWeek??1,dayOfMonth:R.dayOfMonth??1,time:R.time,format:R.format,scope:R.scope,email:R.email??""}),G=g.type!=="list",q=y.filter(R=>R.isActive).length;return t.jsxs(t.Fragment,{children:[t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:G,PaperProps:{sx:R=>({borderRadius:et(R),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",...ce(R).paper})},children:[t.jsxs(o.DialogTitle,{sx:R=>({display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,flexShrink:0,minHeight:0,...ce(R).header}),children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[t.jsx(o.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:R=>E(R.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.Schedule,{sx:{fontSize:17,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"baseline",gap:.75},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:R=>R.typography.h6.fontWeight||600,fontSize:R=>R.typography.subtitle2.fontSize||"0.875rem",lineHeight:1},children:"Scheduled Reports"}),t.jsx($r,{content:_r.schedule,isDev:process.env.NODE_ENV==="development"})]}),t.jsxs(o.Typography,{variant:"caption",color:"text.secondary",sx:{lineHeight:1},children:["· ",i]})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"text.secondary","&:hover":{bgcolor:R=>E(R.palette.text.primary,.06)}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsxs(o.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[G&&t.jsx(Ip,{initial:g.type==="edit"?M(g.schedule):aa,isEditing:g.type==="edit",onSave:g.type==="edit"?B:h,onBack:()=>v({type:"list"})}),g.type==="list"&&t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:y.length===0?"No schedules yet":`${q} of ${y.length} active`}),t.jsx(o.Button,{startIcon:t.jsx($.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",onClick:()=>v({type:"create"}),sx:{fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),y.length===0?t.jsxs(o.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[t.jsx($.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:R=>R.typography.body2.fontWeight||500,fontSize:R=>R.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"No scheduled reports yet"}),t.jsx(o.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:y.map(R=>t.jsx(Dp,{schedule:R,tick:S,onToggle:T,onRunNow:j,onEdit:u=>v({type:"edit",schedule:u}),onDelete:P},R.id))})]})]}),g.type==="list"&&t.jsxs(o.DialogActions,{sx:{px:2.5,py:1.25,borderTop:"1px solid",borderColor:"divider",flexShrink:0,display:"flex",alignItems:"center",gap:1},children:[t.jsxs(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75,px:1.25,py:.75,borderRadius:"8px",bgcolor:R=>E(R.palette.warning.main,.06),border:"1px solid",borderColor:R=>E(R.palette.warning.main,.2)},children:[t.jsx($.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),t.jsx(o.Button,{onClick:r,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:R=>E(R.palette.text.primary,.06)}},children:"Close"})]})]}),b&&t.jsx(Ep,{scheduleName:b.name,onConfirm:_,onCancel:()=>m(null)})]})}const _p=6e4;function Op({reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:a,columnVisibility:c,columnOrder:l,filters:p,sortStack:x,onFired:y,schedulerConfig:g}){const v=(g==null?void 0:g.mode)??"local",S=f.useRef({reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:a,columnVisibility:c,columnOrder:l,filters:p,sortStack:x,onFired:y,schedulerConfig:g,schedulerMode:v});f.useEffect(()=>{S.current={reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:a,columnVisibility:c,columnOrder:l,filters:p,sortStack:x,onFired:y,schedulerConfig:g,schedulerMode:v}});const k=f.useCallback(b=>{var R,u,A,F,d;const{reportName:m,uploadedData:z,processedData:h,schema:B,activeView:T,columnVisibility:j,columnOrder:P,filters:_,sortStack:M,schedulerConfig:G,schedulerMode:q}=S.current;try{const ne=b.scope==="all"?z:h;if(q==="api"){const xe=(P.length>0?P:B.map(X=>X.name)).filter(X=>j[X]!==!1),V={schedule:b,triggeredAt:new Date().toISOString(),rows:ne,columns:xe,format:b.format,reportName:m};(R=G==null?void 0:G.onScheduleFire)==null||R.call(G,V),(A=(u=S.current).onFired)==null||A.call(u,b);return}const U=Qo(ne,B,_,M,T,j,P),re=`${b.name}_scheduled`;switch(b.format){case"csv":Zo(U,re,{scope:b.scope});break;case"excel":en(U,re,{scope:b.scope});break;case"json":tn(U,re,{scope:b.scope});break;case"pdf":ui(U,re,{scope:b.scope});break}if(G!=null&&G.onScheduleFire){const xe=(P.length>0?P:B.map(V=>V.name)).filter(V=>j[V]!==!1);G.onScheduleFire({schedule:b,triggeredAt:new Date().toISOString(),rows:ne,columns:xe,format:b.format,reportName:m})}if(b.email){const xe=encodeURIComponent(`Scheduled Report: ${b.name}`),V=encodeURIComponent(`Your scheduled report "${b.name}" has been generated.
|
|
191
|
+
]`})})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Supported Column Types"}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"The system automatically detects column types from your data:"}),t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"Number:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["Numeric values (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"33"}),","," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"42.5"}),")"]})]}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"Boolean:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["True/false values (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"true"}),","," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"false"}),")"]})]}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"String:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["Text values (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Europe"'}),","," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Analytics Pro"'}),")"]})]}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:n=>n.typography.body2.fontWeight||500,fontSize:n=>n.typography.body2.fontSize||"0.875rem",minWidth:80},children:"Date:"}),t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["ISO date strings (e.g.,"," ",t.jsx(o.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"2024-08-22"'}),")"]})]})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Notes"}),t.jsxs(o.Box,{component:"ul",sx:{m:0,pl:2.5,"& li":{fontSize:"body2.fontSize",color:"text.secondary",mb:.5}},children:[t.jsx("li",{children:"Each object in the array represents one row in the report."}),t.jsx("li",{children:"The keys of the JSON objects become report columns."}),t.jsx("li",{children:"All objects should have consistent keys for proper column detection."}),t.jsx("li",{children:"Column names are case-sensitive and preserve spacing."})]})]})]})}),t.jsx(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:t.jsx(o.Button,{onClick:r,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:n=>`${n.shape.borderRadius}px`,boxShadow:n=>ye(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>ye(n,"hoverButton")},"&:active":{boxShadow:n=>ye(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function ru({onFileUpload:e,onError:r,isUploading:n}){const[i,s]=f.useState(!1),[a,c]=f.useState(""),[l,p]=f.useState(!1),x=f.useRef(null),y=async z=>{if(!z.name.endsWith(".json")){r("Only .json files are allowed");return}const h=10*1024*1024;if(z.size>h){r("File size exceeds 10MB limit");return}c(z.name);try{const B=await z.text();let T;try{T=JSON.parse(B)}catch{r("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(T)){r("JSON must be an array of objects");return}if(T.length===0){r("No data rows found in JSON file");return}e(T)}catch{r("Network error — please try again")}finally{c("")}},g=z=>{z.preventDefault(),s(!0)},v=z=>{z.preventDefault(),s(!1)},S=z=>{z.preventDefault(),s(!1);const h=z.dataTransfer.files[0];h&&y(h)},k=()=>{var z;(z=x.current)==null||z.click()},b=z=>{var B;const h=(B=z.target.files)==null?void 0:B[0];h&&y(h)},m=z=>{z.stopPropagation(),p(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{onDragOver:g,onDragLeave:v,onDrop:S,onPaste:z=>z.preventDefault(),onClick:k,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?z=>D(z.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[t.jsx(o.Box,{component:"input",ref:x,type:"file",accept:".json",onChange:b,sx:{display:"none"}}),n?t.jsxs(t.Fragment,{children:[t.jsx(o.CircularProgress,{size:32,sx:{mb:2}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:z=>z.typography.body2.fontWeight||500,fontSize:z=>z.typography.body2.fontSize||"0.875rem",mb:.5},children:"Uploading..."}),a&&t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:a})]}):t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:z=>D(z.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.UploadFile,{sx:{fontSize:32,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:1.5},children:[t.jsx(o.Button,{variant:"contained",sx:{fontWeight:500},children:"Upload Data (JSON)"}),t.jsx(o.IconButton,{onClick:m,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:t.jsx($.InfoOutlined,{sx:{fontSize:16}})})]}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",maxWidth:500},children:"Upload structured JSON data to generate your report."}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1},children:"Click to browse or drag and drop a JSON file here"})]})]}),t.jsx(Js,{isOpen:l,onClose:()=>p(!1)})]})}function ou({schema:e,onConfirm:r,hasConflicts:n}){return t.jsxs(o.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[t.jsxs(o.Box,{sx:{mb:2},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontWeight:i=>i.typography.h6.fontWeight||600,fontSize:i=>i.typography.h6.fontSize||"1.25rem",mb:.5},children:"Schema Preview"}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&t.jsxs(o.Alert,{severity:"warning",sx:{mb:2},children:[t.jsx(o.AlertTitle,{sx:{fontWeight:i=>i.typography.h6.fontWeight||600,fontSize:i=>i.typography.subtitle2.fontSize||"0.875rem"},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),t.jsx(o.TableContainer,{sx:{mb:3},children:t.jsxs(o.Table,{children:[t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{sx:{bgcolor:"action.hover"},children:[t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),t.jsx(o.TableBody,{children:e.map(i=>t.jsxs(o.TableRow,{sx:{bgcolor:i.hasConflict?s=>D(s.palette.warning.main,.12):"transparent"},children:[t.jsxs(o.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&t.jsx(o.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),t.jsx(o.TableCell,{children:t.jsx(o.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),t.jsx(o.TableCell,{children:t.jsx(o.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx($.Lock,{sx:{fontSize:16}}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"Schema will be locked for this report"})]}),t.jsx(o.Button,{variant:"contained",onClick:r,disabled:n,sx:{fontWeight:500},children:"Generate Table"})]})]})}function nu({error:e,onRetry:r}){return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderColor:"error.light",bgcolor:n=>D(n.palette.error.main,.12),borderRadius:1,px:2,py:6},children:[t.jsx(o.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:n=>D(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.ErrorOutline,{color:"error",sx:{fontSize:32}})}),t.jsx(o.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:n=>n.typography.h6.fontWeight||600,fontSize:n=>n.typography.h6.fontSize||"1.25rem",mb:1},children:"Upload Failed"}),t.jsx(o.Typography,{variant:"body2",color:"error.main",sx:{textAlign:"center",maxWidth:500,mb:3},children:e}),t.jsx(o.Button,{variant:"contained",color:"error",startIcon:t.jsx($.Upload,{sx:{fontSize:16}}),onClick:r,sx:{fontWeight:500},children:"Try Again"})]})}function Ks({title:e,description:r,showIcon:n=!0}){return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",px:3,py:8},children:[n&&t.jsx(o.Box,{sx:{width:80,height:80,borderRadius:"50%",bgcolor:i=>D(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:t.jsx($.Description,{sx:{fontSize:36,color:"primary.main"}})}),t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:i=>i.typography.h5.fontWeight||500,mb:1,color:i=>i.typography.h5.color||"text.primary",fontSize:i=>i.typography.h5.fontSize||"1.125rem"},children:e}),t.jsx(o.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:i=>i.typography.body2.fontSize||"0.875rem",lineHeight:1.5},children:r})]})}function iu({value:e,onChange:r,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:a,disabled:c}){const[l,p]=f.useState(!1),[x,y]=f.useState(!1),[g,v]=f.useState(-1),S=f.useRef(null),k=f.useRef(null);f.useEffect(()=>{function M(Y){S.current&&!S.current.contains(Y.target)&&(p(!1),y(!1))}return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[]);const b=f.useCallback(()=>{y(!0),v(-1),n.length>0&&p(!0)},[n.length]),m=f.useCallback(M=>{r(M),v(-1)},[r]),z=f.useCallback(M=>{var Y;r(M),i(M),p(!1),(Y=k.current)==null||Y.blur()},[r,i]),h=f.useCallback(M=>{v(-1),z(M)},[z]),B=f.useCallback(M=>{var Y;M.key==="Enter"?g>=0&&g<n.length?(M.preventDefault(),h(n[g].query)):e.trim()&&z(e.trim()):M.key==="Escape"?(p(!1),v(-1),(Y=k.current)==null||Y.blur()):M.key==="ArrowDown"?(M.preventDefault(),n.length>0&&(l||p(!0),v(J=>J<n.length-1?J+1:J))):M.key==="ArrowUp"&&(M.preventDefault(),v(J=>J>0?J-1:-1))},[g,n,e,l,h,z]),T=f.useCallback(()=>{var M;r(""),(M=k.current)==null||M.focus()},[r]),w=f.useMemo(()=>n.filter(M=>M.isFavourite),[n]),P=f.useMemo(()=>n.filter(M=>!M.isFavourite),[n]),O=l&&n.length>0;return t.jsxs(o.Box,{sx:{position:"relative",width:240},ref:S,children:[t.jsx(o.TextField,{inputRef:k,size:"small",fullWidth:!0,value:e,onChange:M=>m(M.target.value),onFocus:b,onKeyDown:B,placeholder:"Search data...",disabled:c,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:M=>D(M.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:M=>D(M.palette.text.primary,.5)},"&.Mui-focused":{bgcolor:"background.paper"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px",color:"text.primary"}},InputProps:{startAdornment:t.jsx(o.InputAdornment,{position:"start",sx:{ml:.5},children:t.jsx($.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:e?t.jsx(o.InputAdornment,{position:"end",children:t.jsx(o.IconButton,{size:"small",onClick:T,edge:"end",sx:{mr:-.5},children:t.jsx($.Close,{sx:{fontSize:16}})})}):null}}),O&&t.jsxs(o.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[w.length>0&&t.jsxs(o.Box,{sx:{py:1},children:[t.jsx(o.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:M=>M.typography.caption.fontWeight||600,fontSize:M=>M.typography.caption.fontSize||"0.75rem",textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),w.map((M,Y)=>t.jsx(cs,{entry:M,isSelected:g===Y,onClick:()=>h(M.query),onToggleFavourite:()=>s(M.query),onDelete:()=>a(M.query)},`fav-${M.query}`))]}),P.length>0&&t.jsxs(o.Box,{sx:{py:1},children:[w.length>0&&t.jsx(o.Divider,{}),t.jsx(o.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:M=>M.typography.caption.fontWeight||600,fontSize:M=>M.typography.caption.fontSize||"0.75rem",textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),P.map((M,Y)=>{const J=w.length+Y;return t.jsx(cs,{entry:M,isSelected:g===J,onClick:()=>h(M.query),onToggleFavourite:()=>s(M.query),onDelete:()=>a(M.query)},`recent-${M.query}`)})]})]})]})}const cs=f.memo(function({entry:r,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:a}){const c=f.useCallback(p=>{p.stopPropagation(),s()},[s]),l=f.useCallback(p=>{p.stopPropagation(),a()},[a]);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?p=>D(p.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?p=>D(p.palette.primary.main,.12):"action.hover"}},children:[t.jsx(o.Box,{sx:{flex:1,minWidth:0},onClick:i,children:t.jsx(o.Typography,{variant:"body2",noWrap:!0,children:r.query})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[t.jsx(o.IconButton,{size:"small",onClick:c,title:r.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:r.isFavourite?t.jsx($.Star,{sx:{fontSize:14,color:"warning.light"}}):t.jsx($.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),t.jsx(o.IconButton,{size:"small",onClick:l,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:t.jsx($.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function su({views:e,activeViewId:r,isDirty:n,onSelectView:i,onCreateView:s,onToggleDefault:a,onToggleFavorite:c,onRestoreView:l,onPermanentDelete:p,onEditView:x,onCloneView:y,onCopyLink:g,onDeleteView:v,onPromoteToGlobal:S,isReadOnly:k,isAdmin:b=!1}){const m=ct(),[z,h]=f.useState(!1),[B,T]=f.useState(!1),[w,P]=f.useState({top:0,left:0}),[O,M]=f.useState(null),[Y,J]=f.useState(null),R=f.useRef(null),u=f.useRef(null),A=e.find(I=>I.id===r),F=A==null?void 0:A.isDefault,d=(I,te)=>I.name.localeCompare(te.name),ne=e.filter(I=>I.scope==="global"&&!I.isDeleted).sort(d),U=e.filter(I=>I.scope!=="global"&&!I.isDeleted).sort(d),re=e.filter(I=>I.isFavorite&&!I.isDeleted).sort(d),ge=e.filter(I=>I.isDeleted);f.useEffect(()=>{if(z&&u.current){const I=u.current.getBoundingClientRect();P({top:I.bottom+window.scrollY+8,left:I.right+window.scrollX-320})}},[z]),f.useEffect(()=>{const I=te=>{R.current&&!R.current.contains(te.target)&&u.current&&!u.current.contains(te.target)&&h(!1)};return z&&document.addEventListener("mousedown",I),()=>{document.removeEventListener("mousedown",I)}},[z]);const V=I=>{if(n&&I!==r){M(I),h(!1);return}i(I),h(!1)},X=()=>{O&&(i(O),M(null))},ce=()=>{M(null)},de=(I,te=!1)=>{const fe=I.scope==="global",ae=!k&&(!fe||b),ze=b&&!fe;return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:r===I.id?D(m.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:r===I.id?D(m.palette.primary.main,.12):m.palette.action.hover}},children:[t.jsxs(o.Button,{onClick:()=>V(I.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[r===I.id&&t.jsx($.Check,{sx:{fontSize:16,flexShrink:0}}),r!==I.id&&t.jsx(o.Box,{sx:{width:"16px",flexShrink:0}}),t.jsx(o.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:r===I.id?m.palette.primary.dark:m.palette.text.primary,fontWeight:r===I.id?q=>q.typography.body2.fontWeight||500:400,fontSize:q=>q.typography.body2.fontSize||"0.875rem"},children:I.name}),te&&t.jsx(o.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.action.selected,px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[ae&&c&&t.jsx(o.IconButton,{onClick:q=>{q.stopPropagation(),c(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:I.isFavorite?"Remove from favorites":"Add to favorites",children:t.jsx($.Star,{sx:{fontSize:16}})}),ae&&a&&!I.isDefault&&t.jsx(o.IconButton,{onClick:q=>{q.stopPropagation(),a(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Set as default",children:t.jsx($.RadioButtonUnchecked,{sx:{fontSize:16}})}),(ae||ze)&&(x||y||g||v||ze&&S)&&t.jsx(o.IconButton,{onClick:q=>{q.stopPropagation(),J({el:q.currentTarget,view:I})},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"More actions",children:t.jsx($.MoreVert,{sx:{fontSize:16}})})]})]},I.id)},ie=I=>t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:m.palette.action.hover},children:[t.jsx(o.Typography,{sx:{color:m.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:I.name}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[l&&t.jsx(o.IconButton,{onClick:te=>{te.stopPropagation(),l(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Restore view",children:t.jsx($.Undo,{sx:{fontSize:16,color:"success.main"}})}),p&&t.jsx(o.IconButton,{onClick:te=>{te.stopPropagation(),p(I.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Delete permanently",children:t.jsx($.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},I.id),Q=n||!F,pe=n;return t.jsxs(o.Box,{sx:{position:"relative"},children:[t.jsxs(o.Button,{ref:u,onClick:()=>h(!z),variant:"outlined",size:"small",endIcon:t.jsx($.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{position:"relative",minWidth:140,maxWidth:220,justifyContent:"space-between",fontSize:"0.8125rem",textTransform:"none",color:Q?"warning.main":"text.primary",borderColor:Q?"warning.main":"divider",bgcolor:Q?D(m.palette.warning.main,.12):"transparent",borderRadius:1,py:.5,px:1.25,transition:"all 0.15s ease","&:hover":{borderColor:Q?"warning.dark":"primary.main",bgcolor:Q?D(m.palette.warning.main,.2):D(m.palette.text.primary,.06),color:Q?"warning.dark":"text.primary"}},title:`View: ${(A==null?void 0:A.name)||"Default View"}`,children:[t.jsx(o.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(A==null?void 0:A.name)||"Default View"}),pe&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),z&&bs.createPortal(t.jsxs(o.Box,{ref:R,sx:{position:"fixed",width:"320px",backgroundColor:m.palette.background.paper,border:`1px solid ${m.palette.divider}`,borderRadius:1,boxShadow:m.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:w.top,left:w.left},children:[ne.length>0&&t.jsxs(o.Box,{sx:{py:.5},children:[t.jsx(o.Typography,{sx:{px:2,py:1,fontSize:I=>I.typography.caption.fontSize||"caption.fontSize",fontWeight:I=>I.typography.caption.fontWeight||600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),ne.map(I=>de(I,I.isDefault))]}),re.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsxs(o.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[t.jsx($.Star,{sx:{fontSize:12,color:"warning.light"}}),t.jsx(o.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),re.map(I=>de(I))]})]}),U.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsx(o.Typography,{sx:{px:2,py:1,fontSize:I=>I.typography.caption.fontSize||"caption.fontSize",fontWeight:I=>I.typography.caption.fontWeight||600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),U.map(I=>de(I))]})]}),ge.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsxs(o.Button,{onClick:()=>T(!B),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[t.jsxs(o.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",ge.length,")"]}),t.jsx($.ChevronRight,{sx:{fontSize:16}})]}),B&&t.jsx(o.Box,{sx:{backgroundColor:m.palette.action.hover},children:ge.map(I=>ie(I))})]})]}),t.jsx(o.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),t.jsxs(o.Button,{onClick:()=>{s(),h(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[t.jsx($.Add,{sx:{fontSize:16}}),t.jsx(o.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),t.jsxs(o.Popover,{open:!!Y,anchorEl:(Y==null?void 0:Y.el)||null,onClose:()=>J(null),disablePortal:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[x&&t.jsxs(o.MenuItem,{onClick:()=>{Y&&x(Y.view.id),J(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.Edit,{sx:{fontSize:18}}),"Edit"]}),g&&t.jsxs(o.MenuItem,{onClick:()=>{Y&&g(Y.view.id),J(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.Link,{sx:{fontSize:18}}),"Copy Link"]}),y&&t.jsxs(o.MenuItem,{onClick:()=>{Y&&y(Y.view.id),J(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.ContentCopy,{sx:{fontSize:18}}),"Clone"]}),S&&b&&(Y==null?void 0:Y.view.scope)!=="global"&&t.jsxs(o.MenuItem,{onClick:()=>{Y&&S(Y.view.id),J(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx($.Language,{sx:{fontSize:18}}),"Promote to Global"]}),v&&[t.jsx(o.Divider,{},"delete-divider"),t.jsxs(o.MenuItem,{onClick:()=>{Y&&v(Y.view.id),J(null)},sx:{gap:1.5,fontSize:"body2.fontSize",color:"error.main"},children:[t.jsx($.Delete,{sx:{fontSize:18}}),"Delete"]},"delete-item")]]})]}),document.body),t.jsxs(o.Dialog,{open:O!==null,onClose:ce,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:$o(m)}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[t.jsx($.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),t.jsx(o.DialogContent,{children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),t.jsxs(o.DialogActions,{sx:{px:3,pb:2,gap:1},children:[t.jsx(o.Button,{onClick:ce,variant:"text",children:"Stay here"}),t.jsx(o.Button,{onClick:X,variant:"contained",color:"warning",children:"Discard & switch"})]})]})]})}function au({columnName:e,columnType:r="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:a=!1,hasModifications:c=!1,position:l,onSortAscending:p,onSortDescending:x,onRemoveSort:y,onFilter:g,onClearFilter:v,onGroupByColumn:S,onHideColumn:k,onManageColumns:b,onResetLayout:m,onClose:z}){const h=ct(),B=h.palette,T=f.useRef(null);f.useEffect(()=>{if(!T.current)return;const J=T.current,R=J.getBoundingClientRect(),u=window.innerWidth,A=window.innerHeight;R.right>u-8&&(J.style.left=`${u-R.width-8}px`),R.bottom>A-8&&(J.style.top=`${A-R.height-8}px`)},[l]),f.useEffect(()=>{const J=u=>{T.current&&!T.current.contains(u.target)&&z()},R=u=>{u.key==="Escape"&&z()};return document.addEventListener("mousedown",J),document.addEventListener("keydown",R),()=>{document.removeEventListener("mousedown",J),document.removeEventListener("keydown",R)}},[z]);const w=f.useCallback(J=>()=>{J(),z()},[z]),P=(n==null?void 0:n.direction)==="asc",O=(n==null?void 0:n.direction)==="desc",M=r==="number"?"0→9":r==="boolean"?"F→T":"A→Z",Y=r==="number"?"9→0":r==="boolean"?"T→F":"Z→A";return bs.createPortal(t.jsxs(o.Paper,{ref:T,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:h.zIndex.tooltip,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:$o(h),overflow:"hidden",boxShadow:`0 4px 20px ${D(B.common.black,.12)}, 0 1px 4px ${D(B.common.black,.06)}`},children:[!a&&t.jsxs(o.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[t.jsx(o.Typography,{sx:{fontSize:J=>J.typography.body2.fontSize||"0.8125rem",fontWeight:J=>J.typography.body2.fontWeight||500,color:"text.primary"},children:"Sorting"}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[t.jsx(o.Tooltip,{title:`Sort Ascending (${M})`,placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:w(()=>p(e)),sx:{p:.625,borderRadius:"6px",color:P?"primary.main":"text.secondary",bgcolor:P?D(B.primary.main,.1):"transparent","&:hover":{bgcolor:D(B.primary.main,.08),color:"primary.main"}},children:t.jsx($.ArrowUpward,{sx:{fontSize:16}})})}),t.jsx(o.Tooltip,{title:`Sort Descending (${Y})`,placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:w(()=>x(e)),sx:{p:.625,borderRadius:"6px",color:O?"primary.main":"text.secondary",bgcolor:O?D(B.primary.main,.1):"transparent","&:hover":{bgcolor:D(B.primary.main,.08),color:"primary.main"}},children:t.jsx($.ArrowDownward,{sx:{fontSize:16}})})}),t.jsx(o.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:t.jsx("span",{children:t.jsx(o.IconButton,{size:"small",disabled:!s,onClick:w(()=>y(e)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(B.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:t.jsx($.Close,{sx:{fontSize:16}})})})})]})]}),t.jsxs(o.MenuList,{dense:!0,sx:{py:.5},children:[t.jsxs(o.MenuItem,{onClick:w(()=>g(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.FilterList,{sx:{fontSize:16,color:i?"primary.main":"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Filter by Column",primaryTypographyProps:{fontSize:"0.8125rem",fontWeight:i?600:400,color:i?"primary.main":"text.primary"}})]}),i&&!a&&t.jsxs(o.MenuItem,{onClick:w(()=>v(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(B.warning.main,.06),"& .MuiListItemText-primary":{color:"warning.main"},"& .MuiListItemIcon-root svg":{color:"warning.main"}}},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!a&&S&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.25}}),t.jsx(o.MenuList,{dense:!0,sx:{py:.5},children:t.jsxs(o.MenuItem,{onClick:w(()=>S(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.GroupWorkOutlined,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Group By Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]})})]}),t.jsx(o.Divider,{sx:{my:.25}}),t.jsxs(o.MenuList,{dense:!0,sx:{py:.5},children:[!a&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[t.jsxs(o.MenuItem,{onClick:w(()=>k(e)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),t.jsx(o.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:w(b),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(B.primary.main,.08),color:"primary.main"}},children:t.jsx($.Settings,{sx:{fontSize:16}})})})]}),a&&t.jsxs(o.MenuItem,{onClick:w(b),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!a&&c&&m&&t.jsxs(o.MenuItem,{onClick:w(m),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(B.error.main,.05),"& .MuiListItemText-primary":{color:"error.main"},"& .MuiListItemIcon-root svg":{color:"error.main"}}},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx($.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const lu=176,ds="COLUMN_HEADER",cu=f.memo(function({column:r,index:n,sortRule:i,hasFilters:s,isInSortStack:a,isReadOnly:c=!1,isGrouped:l=!1,hasModifications:p=!1,width:x,onColumnClick:y,onMoveColumn:g,onColumnDragEnd:v,onResizeStart:S,onSortAscending:k,onSortDescending:b,onRemoveSort:m,onOpenFilterForColumn:z,onClearFiltersForColumn:h,onGroupByColumn:B,onHideColumn:T,onManageColumns:w,onResetLayout:P}){const M=ct().urmTable,Y=f.useRef(null),[J,R]=f.useState(!1),[u,A]=f.useState({x:0,y:0}),[{handlerId:F,isOver:d},ne]=Zt.useDrop({accept:ds,collect(Q){return{handlerId:Q.getHandlerId(),isOver:Q.isOver()}},hover(Q,pe){var We;if(!Y.current)return;const I=Q.index,te=n;if(I===te)return;const fe=(We=Y.current)==null?void 0:We.getBoundingClientRect(),ae=(fe.right-fe.left)/2,ze=pe.getClientOffset(),q=((ze==null?void 0:ze.x)??0)-fe.left;I<te&&q<ae||I>te&&q>ae||(g(I,te),Q.index=te)}}),[{isDragging:U},re]=Zt.useDrag({type:ds,item:()=>({index:n,columnName:r.name}),collect:Q=>({isDragging:Q.isDragging()}),end:()=>{v==null||v()}});re(ne(Y));const ge=f.useCallback(Q=>{Q.preventDefault(),Q.stopPropagation(),A({x:Q.clientX,y:Q.clientY}),R(!0)},[]),V=f.useCallback(()=>R(!1),[]),X=f.useCallback(()=>{l||y(r.name)},[y,r.name,l]),ce=f.useCallback(Q=>{Q.stopPropagation(),z(r.name)},[z,r.name]),de=f.useCallback(()=>i?t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?t.jsx($.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):t.jsx($.ArrowDownward,{sx:{fontSize:13,color:"primary.main"}}),t.jsx(o.Box,{sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"0.6rem",fontWeight:700,borderRadius:"50%",lineHeight:1},children:i.priority})]}):null,[i]),ie=f.useCallback(()=>s?t.jsx($.FilterList,{onClick:ce,titleAccess:"Active filter on this column — click to edit",sx:{ml:.5,fontSize:13,color:"primary.main",cursor:"pointer",flexShrink:0,"&:hover":{transform:"scale(1.15)"},transition:"transform 0.12s ease"}}):null,[s,ce]);return t.jsxs(t.Fragment,{children:[t.jsxs(o.TableCell,{ref:Y,"data-handler-id":F,"data-column-index":n,onClick:X,onContextMenu:ge,sx:{position:"sticky",top:0,zIndex:5,textAlign:(M==null?void 0:M.cellAlignH)??"left",verticalAlign:(M==null?void 0:M.cellAlignV)??"middle",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"visible",cursor:"pointer",userSelect:"none",color:(M==null?void 0:M.headerColor)??"text.secondary",opacity:U?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:d?Q=>D(Q.palette.primary.main,.08):(M==null?void 0:M.headerBg)??"action.hover",boxShadow:Q=>`0 1px 0 ${D(Q.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:(M==null?void 0:M.rowDivider)??"1px solid",borderRight:M==null?void 0:M.colDivider,borderColor:"divider",py:0,px:l?0:(M==null?void 0:M.cellPaddingX)??2,"&:hover":{bgcolor:Q=>D(Q.palette.primary.main,.1),color:"text.primary"},width:l?"32px":x?`${x}px`:`${lu}px`,minWidth:l?"32px":void 0,maxWidth:l?"32px":void 0},children:[!l&&t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[lt(r.name),de(),ie()]}),!l&&t.jsx(o.Box,{draggable:!1,onDragStart:Q=>Q.preventDefault(),sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:Q=>{Q.preventDefault(),Q.stopPropagation(),S(Q,r.name)},onClick:Q=>Q.stopPropagation(),children:t.jsx(o.Box,{draggable:!1,sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),d&&t.jsx(o.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),J&&t.jsx(au,{columnName:r.name,columnType:r.type,currentSort:i,hasFilters:s,isInSortStack:a,isReadOnly:c,hasModifications:p,position:u,onSortAscending:k,onSortDescending:b,onRemoveSort:m,onFilter:z,onClearFilter:h,onGroupByColumn:B,onHideColumn:T,onManageColumns:w,onResetLayout:P,onClose:V})]})}),du={active:"success",completed:"success",approved:"success",success:"success",done:"success",contract:"info","in progress":"info","in review":"info",review:"info",pending:"info","on leave":"error","on hold":"warning",probation:"warning",cancelled:"error",rejected:"error",blocked:"error",inactive:"neutral","not started":"neutral",paused:"neutral"};function nn(e,r){const n=du[r.toLowerCase().trim()];if(!n||n==="neutral")return{bg:e.palette.action.selected,color:e.palette.text.secondary};const i=e.palette[n];return{bg:D(i.main,e.palette.mode==="dark"?.24:.12),color:e.palette.mode==="dark"?i.light:i.dark}}function uu(e,r){switch(r.toLowerCase().trim()){case"low":return e.palette.text.secondary;case"medium":return e.palette.warning.main;case"high":return e.palette.mode==="dark"?e.palette.warning.light:e.palette.warning.dark;case"critical":case"urgent":return e.palette.error.main;default:return}}const pu={filters:{hue:"primary",shade:"main"},sorting:{hue:"secondary",shade:"main"},grouping:{hue:"success",shade:"main"},columns:{hue:"warning",shade:"main"},views:{hue:"error",shade:"main"},theme:{hue:"info",shade:"main"},export:{hue:"primary",shade:"dark"},presets:{hue:"secondary",shade:"dark"},system:{hue:"error",shade:"dark"}};function hu(e,r){const n=pu[r];return n?e.palette[n.hue][n.shade]:e.palette.text.secondary}function jt(e){return D(e.palette.primary.main,e.palette.mode==="dark"?.24:.12)}function fu(e){const r=e.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:n=>{var i;return(i=n.tokens)!=null&&i.statusBold?700:500},bgcolor:n=>nn(n,r).bg,color:n=>nn(n,r).color,whiteSpace:"nowrap",lineHeight:1.5},children:e})}function mu(e,r){if(r==null||r==="")return t.jsx(o.Box,{component:"span",sx:{color:"text.disabled",fontSize:"0.875rem"},children:"—"});const n=String(r),i=e.name.toLowerCase();if(/\b(status|state|stage)\b/.test(i))return fu(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=n.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:a=>{const c=uu(a,s);return c?{color:c,fontWeight:600,fontSize:"0.875rem"}:{fontSize:"0.875rem"}},children:n})}return typeof r=="boolean"?t.jsx(o.Box,{component:"span",sx:{fontSize:"0.875rem"},children:r?"Yes":"No"}):typeof r=="object"?t.jsx(o.Box,{component:"span",sx:{fontSize:"0.875rem"},children:JSON.stringify(r)}):t.jsx(o.Box,{component:"span",sx:{fontSize:"0.875rem"},children:n})}function xu(e){const r=e.find(s=>{const a=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(a)})||e[0]||null,n=e.find(s=>{const a=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(a)&&s!==r})||null,i=e.filter(s=>s!==r&&s!==n).slice(0,4);return{primaryCol:r,idCol:n,bodyColumns:i}}function gu({row:e,rowIndex:r,visibleColumns:n,isSelected:i,onCardClick:s,onCardDoubleClick:a,onCardContextMenu:c,onOpenRowMenu:l,onToggleSelection:p,hideCheckbox:x}){const[y,g]=f.useState(!1),{primaryCol:v,idCol:S,bodyColumns:k}=f.useMemo(()=>xu(n),[n]),b=v?e[v.name]:null,m=S?e[S.name]:null,z=y||i;return t.jsxs(o.Box,{onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),onClick:h=>s(r,h),onDoubleClick:h=>a(e,r,h),onContextMenu:h=>{h.preventDefault(),h.stopPropagation(),c(e,r,h)},sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:h=>{var T,w,P,O;const B=(O=(P=(w=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:w.styleOverrides)==null?void 0:P.root)==null?void 0:O.border;return i?"2px solid":B&&B!=="none"?B:"1px solid"},borderColor:i?h=>it(h).main:h=>{var T,w,P,O;const B=(O=(P=(w=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:w.styleOverrides)==null?void 0:P.root)==null?void 0:O.border;return B&&B!=="none"?"inherit":D(h.palette.divider,.8)},borderWidth:i?2:void 0,borderRadius:h=>{var T,w,P,O;const B=(O=(P=(w=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:w.styleOverrides)==null?void 0:P.root)==null?void 0:O.borderRadius;return B!==void 0?typeof B=="number"?`${B}px`:B:`${h.shape.borderRadius}px`},cursor:"pointer",transition:"box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease",overflow:"hidden",minHeight:180,boxShadow:i?h=>`0 0 0 3px ${D(it(h).main,.15)}, 0 2px 8px ${D(h.palette.common.black,.08)}`:y?h=>{var T,w,P,O;const B=(O=(P=(w=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:w.styleOverrides)==null?void 0:P.root)==null?void 0:O.boxShadow;return B&&B!=="none"?B:ye(h,"cardHover")}:h=>{var T,w,P,O;const B=(O=(P=(w=(T=h.components)==null?void 0:T.MuiCard)==null?void 0:w.styleOverrides)==null?void 0:P.root)==null?void 0:O.boxShadow;return B&&B!=="none"?B:ye(h,"cardRest")},transform:y&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:h=>D(it(h).main,.03)}},children:[t.jsxs(o.Box,{sx:h=>{var O,M,Y,J;const B=((Y=(M=(O=h.components)==null?void 0:O.MuiCardHeader)==null?void 0:M.styleOverrides)==null?void 0:Y.root)||{},T=(B.backgroundColor&&B.backgroundColor!=="transparent"?B.backgroundColor:void 0)??((J=h.tokens)==null?void 0:J.cardHdrHex)??"transparent",w=B.borderBottom&&B.borderBottom!=="none"?B.borderBottom:void 0,P=B.boxShadow&&B.boxShadow!=="none"?B.boxShadow:void 0;return{px:2,pt:1.75,pb:1.5,bgcolor:T,borderBottom:w,boxShadow:P,display:"flex",alignItems:"center",gap:.5}},children:[!x&&t.jsx(o.Checkbox,{size:"small",checked:i,onClick:h=>h.stopPropagation(),onChange:()=>p(e),sx:{p:.25,opacity:z?1:0,transition:"opacity 0.15s ease"}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:h=>h.typography.body2.fontWeight||600,fontSize:h=>h.typography.body1.fontSize||"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:b!=null&&b!==""?String(b):t.jsx(o.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})]}),t.jsx(o.Box,{sx:h=>{var w,P,O;const B=((O=(P=(w=h.components)==null?void 0:w.MuiCardHeader)==null?void 0:P.styleOverrides)==null?void 0:O.root)||{};return B.borderBottom&&B.borderBottom!=="none"?{display:"none"}:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}}),t.jsxs(o.Box,{sx:{px:2,py:1.5,flex:1,display:"grid",gridTemplateColumns:"repeat(2, 1fr)",columnGap:1.5,rowGap:1,alignContent:"start"},children:[k.map(h=>t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{sx:{color:"text.secondary",fontWeight:B=>B.typography.body2.fontWeight||500,fontSize:B=>B.typography.caption.fontSize||"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1.2,mb:.25},children:lt(h.name)}),t.jsx(o.Box,{sx:{lineHeight:1.3,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},title:String(e[h.name]??""),children:mu(h,e[h.name])})]},h.name)),k.length===0&&t.jsx(o.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic",gridColumn:"1 / -1"},children:"No additional fields visible"})]}),t.jsxs(o.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:h=>D(h.palette.action.hover,.1),minHeight:40},children:[t.jsx(o.Typography,{sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.75rem",fontWeight:400,letterSpacing:"0.04em",opacity:m?.85:0,userSelect:"none"},children:m?String(m):" "}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:z?1:0,transition:"opacity 0.15s ease"},onClick:h=>h.stopPropagation(),children:t.jsx(o.Tooltip,{title:"More actions",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:h=>{h.stopPropagation(),l(e,r,h.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:h=>D(h.palette.text.primary,.08)}},children:t.jsx($.MoreVert,{sx:{fontSize:17}})})})})]})]})}function yu({row:e,grouping:r,onToggleCollapse:n}){var i;return t.jsxs(o.Box,{onClick:()=>n(e.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:s=>ye(s,"flatHover"),"&:hover":{bgcolor:s=>D(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[e.isCollapsed?t.jsx($.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):t.jsx($.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:s=>s.typography.h5.fontWeight||600,color:s=>s.typography.h5.color||"text.primary"},children:Va(e.groupLevel,((i=r==null?void 0:r.levels[e.groupLevel])==null?void 0:i.column)||"",e.groupValue)}),t.jsxs(o.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:s=>D(s.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[e.rowCount," ",e.rowCount===1?"row":"rows"]}),Object.keys(e.aggregates).length>0&&t.jsx(o.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(e.aggregates).map(([s,a])=>ks(a)).filter(Boolean).join(" • ")})]})}function bu({data:e,visibleColumns:r,grouping:n,selectedRowIds:i,isGrouped:s,onToggleGroupCollapse:a,onCardClick:c,onCardDoubleClick:l,onCardContextMenu:p,onOpenRowMenu:x,onToggleSelection:y,hideSelectionCheckboxes:g}){const v=f.useMemo(()=>{const S=new Set;return i.forEach(k=>{const b=k==null?void 0:k.__urm_row_id__;b!==void 0&&S.add(b)}),S},[i]);return e.length===0?t.jsx(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):t.jsx(o.Box,{sx:{fontFamily:S=>S.typography.fontFamily},children:t.jsx(o.Box,{sx:{p:S=>ls(S).containerPad,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:S=>ls(S).cardGap,alignContent:"start"},children:e.map((S,k)=>s&&S.isGroupHeader?t.jsx(yu,{row:S,grouping:n,onToggleCollapse:a||(()=>{})},`group-${S.groupKey}`):t.jsx(gu,{row:S,rowIndex:k,visibleColumns:r,isSelected:v.has(S==null?void 0:S.__urm_row_id__),onCardClick:c,onCardDoubleClick:l,onCardContextMenu:p,onOpenRowMenu:x,onToggleSelection:y,hideCheckbox:g},`card-${k}`))})})}const us=[10,15,25,50,100];function vu(e,r){const n=e.trim();if(n==="")return"Page number is required";if(!/^-?\d+$/.test(n))return"Must be a number";const i=parseInt(n,10);return i<1?"Page number must be at least 1":i>r?"Entered page number is out of range":null}function Su({currentPage:e,pageSize:r,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:a}){const l=ct().palette,p=Math.ceil(n/r),[x,y]=f.useState(String(e)),[g,v]=f.useState(null),[S,k]=f.useState(!1),b=f.useRef(null);f.useEffect(()=>{S||(y(String(e)),v(null))},[e,S]);const m=f.useCallback(()=>{const A=vu(x,p);if(A){v(A);return}const F=parseInt(x.trim(),10);v(null),k(!1),F!==e&&s(F)},[x,p,e,s]),z=f.useCallback(A=>{var F;A.key==="Enter"?(A.preventDefault(),m()):A.key==="Escape"&&(y(String(e)),v(null),k(!1),(F=b.current)==null||F.blur())},[m,e]),h=f.useCallback(()=>{y(String(e)),v(null),k(!1)},[e]),B=f.useCallback(()=>{k(!0),v(null),setTimeout(()=>{var A;return(A=b.current)==null?void 0:A.select()},0)},[]);if(n<=Math.min(...us))return null;const T=()=>{y(String(e)),v(null),k(!1)},w=()=>{T(),s(1)},P=()=>{T(),e>1&&s(e-1)},O=()=>{T(),e<p&&s(e+1)},M=()=>{T(),s(p)},Y=(e-1)*r+1,J=Math.min(e*r,n),R=`${Math.max(2,String(p).length+.5)}ch`,u={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:3,px:2,py:1,borderTop:"1px solid",borderColor:"divider",bgcolor:"background.paper",minHeight:48},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",t.jsx(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",t.jsx(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),t.jsx(o.Select,{value:r,onChange:A=>a(Number(A.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:us.map(A=>t.jsx(o.MenuItem,{value:A,sx:{fontSize:"0.8125rem"},children:A},A))})]}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[Y,"–",J," of ",n]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),t.jsxs(o.Box,{sx:{position:"relative"},children:[g&&t.jsx(o.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:D(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${D(l.common.black,.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:D(l.error.main,.4)}},children:t.jsx(o.Typography,{sx:{fontSize:A=>A.typography.caption.fontSize||"0.6875rem",fontWeight:A=>A.typography.caption.fontWeight||500,color:"error.main",lineHeight:1.3},children:g})}),t.jsx(o.InputBase,{inputRef:b,value:x,onChange:A=>{y(A.target.value),g&&v(null)},onKeyDown:z,onFocus:B,onBlur:h,inputProps:{"aria-label":`Page number, 1 to ${p}`,style:{textAlign:"center",padding:"2px 0",width:R,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:g?"error.main":"text.primary",border:"1px solid",borderColor:g?"error.main":S?"primary.main":"divider",borderRadius:"4px",bgcolor:g?D(l.error.main,.04):S?D(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:g?"error.main":"text.secondary"},"&:focus-within":{boxShadow:g?`0 0 0 2px ${D(l.error.main,.2)}`:`0 0 0 2px ${D(l.primary.main,.2)}`}}})]}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:A=>A.typography.body2.fontSize||"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",p]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.IconButton,{onClick:w,disabled:e===1,size:"small",title:"First page",sx:u,children:t.jsx($.FirstPage,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:P,disabled:e===1,size:"small",title:"Previous page",sx:u,children:t.jsx($.ChevronLeft,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:O,disabled:e===p,size:"small",title:"Next page",sx:u,children:t.jsx($.ChevronRight,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:M,disabled:e===p,size:"small",title:"Last page",sx:u,children:t.jsx($.LastPage,{sx:{fontSize:20}})})]})]})]})}function Cu(){return t.jsx(o.Chip,{icon:t.jsx($.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:e=>e.typography.caption.fontSize||"caption.fontSize",fontWeight:e=>e.typography.caption.fontWeight||500}})}const Xs="urm_hint_seen_";function ju(e){try{return localStorage.getItem(Xs+e)==="true"}catch{return!1}}function wu(e){try{localStorage.setItem(Xs+e,"true")}catch{}}const Qs={"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:"8px"},"& .MuiInputLabel-root":{fontSize:"0.875rem"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:.5},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}};function oi(e,r){if(e==null||e==="")return"";if(r==="boolean")return e?"True":"False";if(r==="object"||r==="array")try{return JSON.stringify(e,null,2)}catch{return String(e)}return String(e)}function Zs({row:e,schema:r}){const i=ct().palette,s=r.filter(l=>l.name in e),a=s.filter(l=>l.type!=="object"&&l.type!=="array"),c=s.filter(l=>l.type==="object"||l.type==="array");return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[a.map(l=>t.jsx(o.TextField,{label:lt(l.name),value:oi(e[l.name],l.type)||"No value",size:"small",fullWidth:!0,InputProps:{readOnly:!0},sx:Qs},l.name)),c.map(l=>{const p=oi(e[l.name],l.type);return t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:x=>x.typography.caption.fontWeight||500,fontSize:x=>x.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mb:.75},children:lt(l.name)}),t.jsx(o.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,borderRadius:"8px",border:"1px solid",borderColor:"divider",bgcolor:D(i.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:p?"text.primary":"text.disabled",fontStyle:p?"normal":"italic",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:160,overflowY:"auto"},children:p||"No value"})]},l.name)}),s.length===0&&t.jsx(o.Typography,{variant:"body2",sx:{color:"text.disabled",textAlign:"center",py:3,fontSize:l=>l.typography.body2.fontSize||"0.875rem"},children:"No fields to display"})]})}function ku({open:e,onClose:r,row:n,schema:i,reportName:s}){const a=ct(),c=a.palette;if(!n)return null;const l=i.filter(x=>x.name in n).length,p=ue(a);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:tt(a),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",overflow:"hidden",...p.paper}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:2,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0,...p.header},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:D(c.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:x=>x.typography.h6.fontSize||"1rem",fontWeight:x=>x.typography.h6.fontWeight||600,color:x=>x.typography.h6.color||"text.primary",lineHeight:1.3},children:"View Record"}),s&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:x=>x.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s," · ",l," ",l===1?"field":"fields"]})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsx(o.Divider,{}),t.jsx(o.DialogContent,{sx:{overflowY:"auto",flex:1,bgcolor:D(c.text.primary,.015)},children:t.jsx(Zs,{row:n,schema:i})}),t.jsx(o.Divider,{}),t.jsx(o.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:t.jsx(o.Button,{onClick:r,variant:"contained",sx:{fontSize:"0.8125rem",px:3,py:.75,borderRadius:x=>`${x.shape.borderRadius}px`,minWidth:80},children:"Close"})})]})}function zu({open:e,onClose:r,onConfirm:n,row:i,schema:s}){const a=ct(),c=ue(a);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:tt(a),maxHeight:"min(720px, calc(100vh - 80px))",my:"auto",display:"flex",flexDirection:"column",...c.paper}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between",...c.header},children:[t.jsxs(o.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[t.jsx(o.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:l=>D(l.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:l=>l.typography.h6.fontSize||"1.125rem",fontWeight:l=>l.typography.h6.fontWeight||500,color:l=>l.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:l=>l.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"This record will be permanently removed."})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.DialogContent,{sx:{px:3,pb:2,overflowY:"auto",flex:1,display:"flex",flexDirection:"column",gap:2},children:[i&&s&&t.jsx(Zs,{row:i,schema:s}),t.jsx(o.Box,{sx:{p:2,borderRadius:"8px",bgcolor:l=>D(l.palette.error.main,.1),border:l=>`1px solid ${D(l.palette.error.main,.5)}`},children:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:l=>l.typography.body2.fontSize||"0.8125rem",color:"error.main",fontWeight:l=>l.typography.body2.fontWeight||500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})]}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:r,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:l=>`${l.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:()=>{n(),r()},variant:"contained",startIcon:t.jsx($.DeleteForever,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"error.contrastText",px:3,py:.875,minHeight:36,borderRadius:l=>`${l.shape.borderRadius}px`,boxShadow:l=>ye(l,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:l=>ye(l,"hoverButton")},"&:active":{boxShadow:l=>ye(l,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Tu({open:e,onClose:r,onSave:n,row:i,schema:s,reportName:a}){var z;const c=ct(),l=c.palette,[p,x]=f.useState({});if(f.useEffect(()=>{e&&i&&x({...i})},[e,i]),!i)return null;const y=s.filter(h=>h.name in i),g=y.filter(h=>h.type!=="object"&&h.type!=="array"),v=y.filter(h=>h.type==="object"||h.type==="array"),S=(h,B)=>{x(T=>({...T,[h]:B}))},k=()=>{const h={...p};y.forEach(B=>{const T=p[B.name];if(B.type==="number"){const w=Number(T);h[B.name]=isNaN(w)?i[B.name]:w}else B.type==="boolean"&&(h[B.name]=!!T)}),n(h),r()},b=y.length,m=ue(c);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:tt(c),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",overflow:"hidden",...m.paper}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:2,display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0,...m.header},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:D(((z=l.warning)==null?void 0:z.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{sx:{fontSize:h=>h.typography.h6.fontSize||"1rem",fontWeight:h=>h.typography.h6.fontWeight||600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),a&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:h=>h.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a," · ",b," ",b===1?"field":"fields"]})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:D(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[g.map(h=>{const B=p[h.name];return h.type==="boolean"?t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:T=>T.typography.caption.fontWeight||500,fontSize:T=>T.typography.caption.fontSize||"0.75rem",color:"text.secondary",display:"block",mb:.75},children:lt(h.name)}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Switch,{checked:!!B,onChange:T=>S(h.name,T.target.checked),size:"small"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:T=>T.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:B?"Enabled":"Disabled"})]})]},h.name):t.jsx(o.TextField,{label:lt(h.name),value:B??"",onChange:T=>S(h.name,T.target.value),type:h.type==="number"?"number":"text",size:"small",fullWidth:!0,sx:Qs},h.name)}),v.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:v.map(h=>{const B=oi(i[h.name],h.type);return t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.75},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:T=>T.typography.caption.fontSize||"0.75rem",fontWeight:T=>T.typography.caption.fontWeight||500,color:"text.secondary"},children:lt(h.name)}),t.jsx(o.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:D(l.text.secondary,.07),color:"text.secondary",border:"none"}}),t.jsx(o.Tooltip,{title:"Object and array fields cannot be edited directly",arrow:!0,children:t.jsx($.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),t.jsx(o.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,borderRadius:"8px",border:"1px solid",borderColor:"divider",bgcolor:D(l.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:B?"text.primary":"text.disabled",fontStyle:B?"normal":"italic",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:160,overflowY:"auto"},children:B||"No value"})]},h.name)})}),y.length===0&&t.jsxs(o.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[t.jsx($.EditOutlined,{sx:{fontSize:40,opacity:.4}}),t.jsx(o.Typography,{variant:"body2",children:"No editable fields"})]})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:r,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",px:2,borderRadius:h=>`${h.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:k,variant:"contained",startIcon:t.jsx($.SaveOutlined,{sx:{fontSize:15}}),sx:{fontSize:"0.8125rem",px:2.5,borderRadius:h=>`${h.shape.borderRadius}px`,minWidth:90},children:"Save"})]})]})}const Bu=176,Iu=170,Eu=40,Du=32;function ea(e){return e.type==="date"?180:Bu}function $u(e,r){return r!=null&&r!==Iu&&r!==ea(e)}function _u(e,r,n,i){return f.useMemo(()=>{const s=e.map(v=>i!=null&&i.has(v.name)?{name:v.name,width:Du,explicit:!0}:{name:v.name,width:r[v.name]??ea(v),explicit:$u(v,r[v.name])}),a={};s.forEach(v=>{a[v.name]=v.width});const c=s.reduce((v,S)=>v+S.width,0),p=Math.max(0,n-Eu)-c;if(p<=0)return{widths:a,fillerWidth:0};const x=s.filter(v=>!v.explicit);if(x.length===0)return{widths:a,fillerWidth:p};const y=x.reduce((v,S)=>v+S.width,0)||1;let g=0;return x.forEach((v,S)=>{const b=S===x.length-1?v.width+p-g:Math.round(v.width+p*v.width/y);a[v.name]=b,g+=b-v.width}),{widths:a,fillerWidth:0}},[e,r,n,i])}const ps=176,Ou=_t(),Mu={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Wu(e){const r=e.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:n=>{var i;return(i=n.tokens)!=null&&i.statusBold?700:500},bgcolor:n=>nn(n,r).bg,color:n=>nn(n,r).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:e})}function Au(e){const r=e.toLowerCase().trim(),n=Mu[r];return n?t.jsx(o.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:e}):e}function Ru(e,r){const n=r.trim();if(!n)return e;const i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=e.split(new RegExp(`(${i})`,"gi"));return s.length===1?e:s.map((a,c)=>a.toLowerCase()===n.toLowerCase()?t.jsx(o.Box,{component:"mark",sx:{bgcolor:"warning.light",color:"inherit",px:"1px",borderRadius:"2px"},children:a},c):a)}function Pu(e,r,n,i=""){if(r==null||r==="")return t.jsx(o.Box,{component:"span",sx:{color:"text.disabled"},children:"—"});const s=String(r);if(/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(e.name.toLowerCase()))return Wu(s);if(/\b(priority|severity|urgency|importance|criticality)\b/.test(e.name.toLowerCase()))return Au(s);if(e.type==="date"){const l=e.dateFormat??"iso",p=$a(r,l,n??null);return t.jsx(o.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:p})}if(e.type==="number"&&typeof r=="number")return r.toLocaleString();if(typeof r=="boolean")return r?"Yes":"No";if(Array.isArray(r)){if(r.length===0)return t.jsx(o.Box,{component:"span",sx:{color:"text.disabled"},children:"[ ]"});const l=r.slice(0,3).map(p=>typeof p=="object"?JSON.stringify(p):String(p)).join(", ");return t.jsxs(o.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[l,r.length>3?` +${r.length-3} more`:""]})}if(typeof r=="object"){const l=JSON.stringify(r);return t.jsx(o.Box,{component:"span",title:l,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:l.length>40?l.slice(0,40)+"…":l})}return Ru(s,i)}function Nu({schema:e,data:r,sortStack:n=[],filters:i=Ou,views:s=[],activeViewId:a="",isDirty:c=!1,isExporting:l=!1,columnVisibility:p={},columnOrder:x=[],columnWidths:y={},grouping:g=null,classTokens:v={},onSort:S,onSortAscending:k,onSortDescending:b,onOpenFilters:m,onOpenSort:z,onOpenFilterForColumn:h,onSelectView:B,onCreateView:T,onUpdateCurrentView:w,onSaveAsNewView:P,onDiscardChanges:O,onToggleDefault:M,onToggleFavorite:Y,onRestoreView:J,onPermanentDelete:R,onEditView:u,onCloneView:A,onCopyLink:F,onDeleteView:d,onPromoteToGlobal:ne,isAdmin:U=!1,onExport:re,onOpenColumns:ge,onUpdateColumnWidth:V,onUpdateColumnOrder:X,onUpdateColumnVisibility:ce,onClearFiltersForColumn:de,onResetLayout:ie,onOpenGroup:Q,onGroupByColumn:pe,onToggleGroupCollapse:I,onExpandAllGroups:te,onCollapseAllGroups:fe,onOpenAuditHistory:ae,onOpenScheduledReports:ze,searchQuery:q,highlightQuery:We="",searchHistory:kt=[],onAddToSearchHistory:dt,onToggleSearchFavourite:Or,onDeleteSearchHistory:Ot,selectedRowIds:ot=new Set,onSearchChange:Ft,onToggleRowSelection:qe,onToggleAllRows:zt,onRangeSelection:fr,onClearSelection:xt,onExportSelected:tr,currentPage:ao=1,pageSize:rr=15,totalRowsBeforePagination:lo=r.length,onPageChange:Tt,onPageSizeChange:mr,isReadOnly:Je=!1,userRole:Mt,reportName:Vt,onEditRow:Qe,onDuplicateRow:Ze,onDeleteRow:Wt,showDevPanel:co=!1,onOpenDevConfig:Mr,rowActions:xr,hideDefaultRowActions:Ve,hideToolbarActions:ke,customSettingsActions:or,viewOptions:At,defaultViewMode:gr,bulkActions:yr,hideSelectionCheckboxes:Ht,rowClickBehavior:nr="select",openModalOn:et,onRowClick:ir,onRowRightClick:gt}){var Ro;const ee=ct().urmTable,[br,Ar]=f.useState(null),[Bt,H]=f.useState(0),[ut,se]=f.useState(0),[Ke,sr]=f.useState(null),uo=((Ro=Dr().dates)==null?void 0:Ro.displayFormat)??null,[Ut,Sr]=f.useState(null),[Gt,ar]=f.useState(null),[Yt,ve]=f.useState(null),[yt,Z]=f.useState(!1),[he,be]=f.useState(!1),[Cr,jr]=f.useState(null),[po,Rr]=f.useState(!1),[ho,qt]=f.useState(null),[Pr,Nr]=f.useState(null),[Se,Ge]=f.useState(null),[wr,st]=f.useState(null),Jt=f.useRef(null),It=f.useCallback(()=>{Jt.current&&(clearTimeout(Jt.current),Jt.current=null)},[]),kr=f.useCallback(()=>{It(),Jt.current=setTimeout(()=>st(null),200)},[It]);f.useEffect(()=>It,[It]);const[xe,Ce]=f.useState(null),Ne=f.useMemo(()=>At??["list","grid"],[At]),[nt,Et]=f.useState(()=>gr??Ne[0]??"list"),[zr,Lr]=f.useState(!1),[Fr,kn]=f.useState(()=>!ju("toolbar_search")),Vr=f.useRef(null),fo=f.useRef(null),[zn,_o]=f.useState(0);f.useLayoutEffect(()=>{const C=Vr.current;if(!C)return;_o(C.clientWidth);const N=new ResizeObserver(oe=>{_o(oe[0].contentRect.width)});return N.observe(C),()=>N.disconnect()},[]);const Hr=f.useCallback(()=>{wu("toolbar_search"),kn(!1)},[]);f.useEffect(()=>{if(!Fr)return;const C=setTimeout(Hr,2e3);return()=>clearTimeout(C)},[Fr,Hr]);const Oo=f.useMemo(()=>{const C=Ke??x;return C.length>0?C.map(N=>e.find(oe=>oe.name===N)).filter(N=>N!==void 0):e},[Ke,x,e]),Ur=f.useMemo(()=>Oo.filter(C=>p[C.name]!==!1),[Oo,p]),Gr=f.useMemo(()=>new Set(((g==null?void 0:g.levels)??[]).map(C=>C.column)),[g]),mo=!!(g!=null&&g.enabled&&(g!=null&&g.levels)&&g.levels.length>0),Yr=f.useMemo(()=>{if(!mo)return Ur;const C=((g==null?void 0:g.levels)??[]).map(oe=>e.find(je=>je.name===oe.column)).filter(oe=>oe!==void 0),N=Ur.filter(oe=>!Gr.has(oe.name));return[...C,...N]},[Ur,mo,Gr,g,e]),{widths:qr}=_u(Yr,y,zn,mo?Gr:void 0),lr=f.useMemo(()=>e.filter(C=>p[C.name]===!1).length,[e,p]),xo=f.useMemo(()=>e.map(C=>C.name),[e]),Jr=f.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(xo),[x,xo]),Tn=f.useCallback((C,N)=>{C.preventDefault(),C.stopPropagation(),Ar(N),H(C.clientX),se(y[N]||150)},[y]);f.useEffect(()=>{if(!br)return;const C=oe=>{const je=oe.clientX-Bt,Ae=Math.max(100,Math.min(600,ut+je));V==null||V(br,Ae)},N=()=>{Ar(null)};return document.addEventListener("mousemove",C),document.addEventListener("mouseup",N),()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",N)}},[br,Bt,ut,V]);const Bn=f.useCallback(C=>C==null?"-":typeof C=="object"?JSON.stringify(C):typeof C=="boolean"?C?"true":"false":String(C),[]);f.useCallback(C=>{const N=n.find(oe=>oe.column===C);return N?t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[N.direction==="asc"?t.jsx($.ArrowUpward,{sx:{fontSize:14}}):t.jsx($.ArrowDownward,{sx:{fontSize:14}}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"caption.fontSize",fontWeight:"bold",borderRadius:"50%"},children:N.priority})]}):null},[n]),f.useCallback(C=>Xn(i,C)?t.jsx(o.IconButton,{size:"small",onClick:oe=>{oe.stopPropagation(),h==null||h(C)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:t.jsx($.FilterList,{sx:{fontSize:14}})}):null,[i,h]);const In=f.useCallback(C=>{S&&S(C)},[S]),En=f.useCallback((C,N)=>{sr(oe=>{const Ae=[...oe??(x.length>0?x:e.map(Xe=>Xe.name))],[rt]=Ae.splice(C,1);return Ae.splice(N,0,rt),Ae})},[x,e]),Dn=f.useCallback(()=>{Ke&&X&&X(Ke),sr(null)},[Ke,X]),$n=f.useCallback(C=>{if(!S)return;const N=n.find(oe=>oe.column===C);(!N||N.direction!=="asc")&&S(C)},[S,n]),_n=f.useCallback(C=>{if(!S)return;const N=n.find(oe=>oe.column===C);N?N.direction==="asc"&&S(C):(S(C),setTimeout(()=>S(C),0))},[S,n]),On=f.useCallback(C=>{if(!S)return;const N=n.find(oe=>oe.column===C);N&&(N.direction==="asc"?(S(C),setTimeout(()=>S(C),0)):N.direction==="desc"&&S(C))},[S,n]),Mn=f.useCallback(C=>{ce&&ce(C,!1)},[ce]),Kr=!!(g!=null&&g.enabled&&(g!=null&&g.levels)&&g.levels.length>0),Kt=f.useMemo(()=>Ct(i),[i]),Wn=n.length>0||Kt>0||((g==null?void 0:g.enabled)??!1)||Object.values(p).some(C=>C===!1),An=(ao-1)*rr,Me=r,at=f.useMemo(()=>{const C=new Set;return ot.forEach(N=>{const oe=N==null?void 0:N.__urm_row_id__;oe!==void 0&&C.add(oe)}),C},[ot]);f.useEffect(()=>{const C=N=>{!zt||!xt||N.target instanceof HTMLInputElement||N.target instanceof HTMLTextAreaElement||((N.ctrlKey||N.metaKey)&&N.key==="a"&&(N.preventDefault(),zt(!0,Me)),N.key==="Escape"&&(N.preventDefault(),xt()))};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[zt,xt,Me]);const go=f.useCallback((C,N)=>{ir==null||ir(Me[C],C,N),(nr==="activate"||nr==="both")&&(ve(Me[C]),Z(!0)),nr!=="activate"&&qe&&(N.shiftKey&&Ut!==null?(N.preventDefault(),fr&&fr(Ut,C,Me)):(qe(Me[C]),Sr(C)))},[qe,Ut,fr,Me,ir,nr,ve,Z]),Mo=f.useMemo(()=>Me.length>0&&at.size>0&&Me.every(C=>at.has(C==null?void 0:C.__urm_row_id__)),[Me,at]),Rn=!Mo&&Me.some(C=>at.has(C==null?void 0:C.__urm_row_id__)),Dt=!!(qe&&zt&&!Ht),Tr=f.useMemo(()=>!(g!=null&&g.enabled)||!(g!=null&&g.levels)?new Set:new Set(g.levels.map(C=>C.column)),[g]),pt=f.useMemo(()=>Yr,[Yr]),Wo=f.useMemo(()=>{const C=new Map;if(!(g!=null&&g.enabled)||!Me)return C;let N=[];for(const oe of Me)if(oe.__isGroupHeader||oe.isGroupHeader){const je=oe.groupLevel??0;N[je]=oe.groupKey,N=N.slice(0,je+1),C.has(oe.groupKey)||C.set(oe.groupKey,[])}else if(oe.__urm_is_grouped_data_row__)for(const je of N)je&&C.has(je)&&C.get(je).push(oe);return C},[g,Me]),Xr=f.useCallback(C=>{const N=C.groupLevel,oe=N===0?v.groupRowLevel0||"urm-group-level-0":N===1?v.groupRowLevel1||"urm-group-level-1":v.groupRowLevel2||"urm-group-level-2",je=N===0?_e=>_e.palette.mode==="dark"?D(_e.palette.action.hover,.12):"#f1f5f9":_e=>_e.palette.mode==="dark"?D(_e.palette.action.hover,.06):"#f8fafc",Ae=String(C.groupValue??"(empty)"),rt=`${C.rowCount} ${C.rowCount===1?"item":"items"}`,Xe=Wo.get(C.groupKey)||[],me=Xe.filter(_e=>at.has(_e==null?void 0:_e.__urm_row_id__)).length,Rt=Xe.length>0&&me===Xe.length,Xt=me>0&&me<Xe.length;return t.jsxs(o.TableRow,{onClick:()=>I==null?void 0:I(C.groupKey),className:`urm-group-header-row urm-group-level-${N} ${oe} ${v.groupRow||""}`,sx:{bgcolor:je,"&:hover":{bgcolor:_e=>D(_e.palette.text.primary,.07)},cursor:"pointer",borderTop:"1px solid",borderBottom:"1px solid",borderColor:"divider",position:"relative"},children:[Dt&&t.jsx(o.TableCell,{padding:"checkbox",onClick:_e=>_e.stopPropagation(),sx:{borderBottom:"1px solid",borderColor:"divider",verticalAlign:"middle",bgcolor:"inherit"},children:t.jsx(o.Checkbox,{size:"small",checked:Rt,indeterminate:Xt,onChange:()=>{if(!qe)return;const _e=!Rt;Xe.forEach(cr=>{const Po=at.has(cr==null?void 0:cr.__urm_row_id__);_e!==Po&&qe(cr)})}})}),t.jsxs(o.TableCell,{colSpan:pt.length-Tr.size+(!Dt&&Tr.size===0?1:0),className:`urm-group-cell ${v.groupCellFirst||""} ${v.groupCell||""}`,sx:{pl:`${N*24+16}px`,position:"relative",py:1.25,borderBottom:"1px solid",borderColor:"divider"},children:[N>0&&t.jsx(o.Box,{sx:{position:"absolute",left:`${N*24+4}px`,top:0,bottom:0,width:"1px",bgcolor:"divider"}}),t.jsxs(o.Box,{className:`urm-group-content ${v.groupContent||""}`,sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Box,{className:`urm-group-caret ${v.groupCaret||""}`,sx:{color:"text.secondary",display:"inline-flex",alignItems:"center"},children:C.isCollapsed?t.jsx($.ChevronRight,{sx:{fontSize:18}}):t.jsx($.KeyboardArrowDown,{sx:{fontSize:18}})}),t.jsx(o.Typography,{variant:"body2",className:`urm-group-title ${v.groupTitle||""}`,sx:{fontWeight:N===0?600:500,fontSize:N===0?"0.9375rem":"0.875rem",color:"text.primary",whiteSpace:"nowrap"},children:Ae}),!!C.__urm_is_continuation_header__&&t.jsx(o.Box,{className:"urm-group-continuation-badge",sx:{px:1,py:.25,fontSize:"0.7rem",fontWeight:500,lineHeight:1,whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",bgcolor:_e=>D(_e.palette.text.secondary,.05),color:"text.secondary",borderRadius:"10px",border:"1px dashed",borderColor:"divider",ml:.5},children:"Continued"}),t.jsx(o.Box,{className:`urm-group-count ${v.groupBadge||""} ${v.groupCount||""}`,sx:{px:1.25,py:.25,fontSize:"0.75rem",fontWeight:500,lineHeight:1,whiteSpace:"nowrap",display:"inline-flex",alignItems:"center",bgcolor:_e=>D(_e.palette.text.secondary,.08),color:"text.secondary",borderRadius:"12px",ml:.5},children:rt}),Object.keys(C.aggregates||{}).length>0&&t.jsxs(o.Typography,{variant:"caption",className:`urm-group-aggregates ${v.groupAggregates||""}`,sx:{ml:1.5,color:"text.secondary",fontWeight:500},children:["(",Object.entries(C.aggregates).map(([_e,cr])=>ks(cr)).filter(Boolean).join(" • "),")"]})]})]})]},C.groupKey)},[Tr,pt,Dt,g,e,I,v,ee,Wo,at,qe]),Ao=f.useCallback((C,N)=>{const oe=at.has(C==null?void 0:C.__urm_row_id__),je=Gt===N,Ae=yt&&(C==null?void 0:C.__urm_row_id__)===(Yt==null?void 0:Yt.__urm_row_id__),rt=!!(C!=null&&C.__urm_is_grouped_data_row__),Xe=rt?C.__urm_group_level__??(g==null?void 0:g.levels.length)??1:0;return t.jsxs(o.TableRow,{"data-row-index":N,className:rt?`urm-data-row-grouped ${v.dataRowGrouped||""}`:"",onMouseEnter:()=>ar(N),onMouseLeave:()=>ar(null),onClick:me=>{me.target.closest("[data-row-action-btn]")||go(N,me)},onDoubleClick:()=>{et!=null&&et.includes("doubleClick")&&(ve(C),Z(!0))},onContextMenu:me=>{me.preventDefault(),me.stopPropagation(),gt==null||gt(C,N,me),st(null),Ge({mouseX:me.clientX,mouseY:me.clientY,row:C,rowIndex:N}),et!=null&&et.includes("rightClick")&&(ve(C),Z(!0))},sx:{cursor:"pointer",bgcolor:oe?me=>it(me).bg:Ae?me=>D(me.palette.info.main,.12):ee!=null&&ee.striped&&N%2===1?ee.stripeBg:"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:oe?me=>it(me).hoverBg:Ae?me=>D(me.palette.info.main,.2):me=>`var(--highlight-hover-row, ${D(it(me).main,.04)})`},borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider"},children:[Dt&&t.jsx(o.TableCell,{padding:"checkbox",onClick:me=>me.stopPropagation(),sx:{borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider",verticalAlign:(ee==null?void 0:ee.cellAlignV)??"middle"},children:t.jsx(o.Checkbox,{size:"small",checked:oe,onChange:()=>qe==null?void 0:qe(C)})}),pt.map((me,Rt)=>{const Xt=Rt===0,_e=Tr.has(me.name);return t.jsxs(o.TableCell,{className:rt&&Xt?`urm-data-cell-grouped ${v.dataCellGrouped||""}`:"",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:(ee==null?void 0:ee.rowPaddingY)??"6px",px:_e?0:(ee==null?void 0:ee.cellPaddingX)??2,position:"relative",textAlign:(ee==null?void 0:ee.cellAlignH)??"left",verticalAlign:(ee==null?void 0:ee.cellAlignV)??"middle",fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderRight:ee==null?void 0:ee.colDivider,borderColor:"divider",width:void 0,minWidth:y[me.name]?`${y[me.name]}px`:`${me.type==="date"?Math.max(ps,180):ps}px`},children:[rt&&Xt&&Xe>0&&t.jsx(o.Box,{sx:{position:"absolute",left:4,top:0,bottom:0,width:"1px",bgcolor:"divider"}}),!_e&&t.jsx(o.Box,{sx:{display:"flex",alignItems:"center"},children:t.jsx("span",{className:`urm-item-title ${v.itemTitle||""}`,children:Pu(me,C[me.name],uo,We)})})]},me.name)}),t.jsx(o.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:0,minWidth:0,maxWidth:0,p:0,border:"none",background:"transparent",opacity:je?1:0,transition:"opacity 0.12s ease",zIndex:10},children:t.jsx(o.Box,{sx:{position:"absolute",right:8,top:0,bottom:0,display:"flex",alignItems:"center",justifyContent:"flex-end",zIndex:10},children:t.jsx(o.IconButton,{"data-row-action-btn":"true",size:"small",onClick:me=>{me.stopPropagation(),me.preventDefault(),st(null),Ge({anchorEl:me.currentTarget,row:C,rowIndex:N})},sx:{color:"text.secondary",opacity:je?1:0,transition:"opacity 0.12s ease",pointerEvents:je?"auto":"none","&:hover":{bgcolor:me=>D(me.palette.text.primary,.08),color:"text.primary"}},children:t.jsx($.MoreVert,{sx:{fontSize:18}})})})})]},N)},[ot,An,Gt,go,Yr,y,We,Bn,Qe,Ze,Wt,qe,Dt,ve,Z,Yt,yt,Ge,Kr,Gr,gt,et]);return t.jsxs(Zt.DndProvider,{backend:ni.HTML5Backend,children:[t.jsxs(o.Box,{sx:C=>{var rt,Xe,me;const N=((me=(Xe=(rt=C.components)==null?void 0:rt.MuiCard)==null?void 0:Xe.styleOverrides)==null?void 0:me.root)||{},oe=N.border&&N.border!=="none"?N.border:"1px solid",je=N.borderRadius!==void 0?typeof N.borderRadius=="number"?`${N.borderRadius}px`:N.borderRadius:`${C.shape.borderRadius}px`,Ae=N.boxShadow&&N.boxShadow!=="none"?N.boxShadow:ye(C,"cardRest");return{display:"flex",flexDirection:"column",height:"100%",bgcolor:"background.paper",border:oe,borderColor:oe!=="none"?"divider":void 0,borderRadius:je,boxShadow:Ae,overflow:"hidden"}},children:[t.jsxs(o.Box,{sx:C=>{var rt,Xe,me,Rt,Xt;const N=((me=(Xe=(rt=C.components)==null?void 0:rt.MuiCardHeader)==null?void 0:Xe.styleOverrides)==null?void 0:me.root)||{},oe=(N.backgroundColor&&N.backgroundColor!=="transparent"?N.backgroundColor:void 0)??((Rt=C.tokens)==null?void 0:Rt.cardHdrHex)??((Xt=C.urmTable)==null?void 0:Xt.headerBg)??C.palette.background.paper,je=N.borderBottom&&N.borderBottom!=="none"?N.borderBottom:"1px solid",Ae=N.boxShadow&&N.boxShadow!=="none"?N.boxShadow:void 0;return{position:"sticky",top:0,zIndex:10,bgcolor:oe,borderBottom:je,borderColor:je!=="none"?"divider":void 0,boxShadow:Ae,px:2,py:0,minHeight:56,display:"flex",alignItems:"center",gap:1}},children:[Je&&t.jsx(Cu,{}),Ft&&dt&&Or&&Ot&&!(ke!=null&&ke.includes("search"))&&t.jsx(o.Tooltip,{open:Fr,title:t.jsxs(o.Box,{sx:{p:.5},children:[t.jsx(o.Typography,{variant:"caption",sx:{display:"block",fontWeight:C=>C.typography.caption.fontWeight||500,mb:.25},children:"💡 Search tip"}),t.jsx(o.Typography,{variant:"caption",children:"Type to search across all columns instantly"})]}),placement:"bottom-start",arrow:!0,PopperProps:{onClick:Hr},componentsProps:{tooltip:{sx:{bgcolor:"primary.main","& .MuiTooltip-arrow":{color:"primary.main"},maxWidth:220,cursor:"pointer",userSelect:"none"}}},children:t.jsx(o.Box,{component:"span",children:t.jsx(iu,{value:q||"",onChange:C=>{Fr&&Hr(),Ft(C)},searchHistory:kt,onAddToHistory:dt,onToggleFavourite:Or,onDeleteHistory:Ot,disabled:Je})})}),t.jsx(o.Tooltip,{title:"JSON format guide",children:t.jsx(o.IconButton,{size:"small",onClick:()=>Lr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:C=>D(C.palette.text.primary,.06),color:"text.primary"}},children:t.jsx($.InfoOutlined,{sx:{fontSize:20}})})}),B&&T&&w&&s.length>0&&t.jsx(su,{views:s||[],activeViewId:a||"",isDirty:c,onSelectView:B,onCreateView:T,onToggleDefault:M,onToggleFavorite:Y,onRestoreView:J,onPermanentDelete:R,onEditView:u,onCloneView:A,onCopyLink:F,onDeleteView:d,onPromoteToGlobal:ne,isAdmin:U,isReadOnly:Je}),c&&!Je&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25,ml:1},children:[w&&t.jsx(o.Button,{onClick:w,size:"small",variant:"contained",sx:{fontSize:"0.8125rem",fontWeight:500,px:2.25,py:.75,borderRadius:"10px",bgcolor:C=>`var(--urm-btn-save-current-bg, ${C.palette.primary.main})`,color:C=>`var(--urm-btn-save-current-color, ${C.palette.primary.contrastText})`,textTransform:"none",boxShadow:C=>ye(C,"restButton"),"&:hover":{bgcolor:C=>`var(--urm-btn-save-current-hover-bg, ${C.palette.primary.dark})`,boxShadow:C=>ye(C,"hoverButton")}},children:"Save current view"}),P&&t.jsx(o.Button,{onClick:P,size:"small",variant:"outlined",sx:{fontSize:"0.8125rem",fontWeight:500,px:2.25,py:.75,borderRadius:"10px",borderColor:C=>`var(--urm-btn-save-new-border, ${C.palette.primary.main})`,color:C=>`var(--urm-btn-save-new-color, ${C.palette.primary.main})`,bgcolor:C=>`var(--urm-btn-save-new-bg, ${C.palette.background.paper})`,borderWidth:"1.5px",textTransform:"none","&:hover":{borderWidth:"1.5px",borderColor:C=>`var(--urm-btn-save-new-hover-border, ${C.palette.primary.dark})`,bgcolor:C=>`var(--urm-btn-save-new-hover-bg, ${D(C.palette.primary.main,.08)})`}},children:"Save new view"}),O&&t.jsx(o.Button,{onClick:O,size:"small",variant:"contained",sx:{fontSize:"0.8125rem",fontWeight:500,px:2.25,py:.75,borderRadius:"10px",bgcolor:C=>`var(--urm-btn-discard-bg, ${D(C.palette.text.primary,.12)})`,color:C=>`var(--urm-btn-discard-color, ${C.palette.text.primary})`,textTransform:"none",boxShadow:"none","&:hover":{bgcolor:C=>`var(--urm-btn-discard-hover-bg, ${D(C.palette.text.primary,.18)})`,boxShadow:"none"}},children:"Discard"})]}),co&&Mr&&t.jsx(o.Tooltip,{title:"Developer configuration",children:t.jsx(o.IconButton,{size:"small",onClick:Mr,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:C=>D(C.palette.text.secondary,.3),"&:hover":{bgcolor:C=>D(C.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:t.jsx($.DisplaySettings,{sx:{fontSize:20}})})}),t.jsx(o.Box,{sx:{flexGrow:1}}),!Je&&z&&!(ke!=null&&ke.includes("sort"))&&t.jsx(o.Tooltip,{title:"Sort",children:t.jsxs(o.IconButton,{onClick:z,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?C=>jt(C):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?C=>D(C.palette.primary.main,.2):C=>D(C.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[t.jsx($.SwapVert,{sx:{fontSize:20}}),n.length>0&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Je&&m&&!(ke!=null&&ke.includes("filter"))&&t.jsx(o.Tooltip,{title:"Filter",children:t.jsxs(o.IconButton,{onClick:m,size:"small",sx:{position:"relative",color:Kt>0?"primary.main":"text.secondary",bgcolor:Kt>0?C=>jt(C):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Kt>0?C=>D(C.palette.primary.main,.2):C=>D(C.palette.text.primary,.06),color:Kt>0?"primary.main":"text.primary"}},children:[t.jsx($.FilterList,{sx:{fontSize:20}}),Kt>0&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:Kt})]})}),!Je&&ge&&!(ke!=null&&ke.includes("columns"))&&t.jsx(o.Tooltip,{title:"Show/Hide Columns",children:t.jsxs(o.IconButton,{onClick:ge,size:"small",sx:{position:"relative",color:lr>0||Jr?"primary.main":"text.secondary",bgcolor:lr>0||Jr?C=>jt(C):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:lr>0||Jr?C=>D(C.palette.primary.main,.2):C=>D(C.palette.text.primary,.06),color:lr>0||Jr?"primary.main":"text.primary"}},children:[t.jsx($.ViewColumn,{sx:{fontSize:20}}),lr>0&&t.jsx(o.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:lr})]})}),Kr&&(te||fe)&&(()=>{var oe;const C=(((oe=g==null?void 0:g.collapsedGroups)==null?void 0:oe.length)??0)>0,N=C?te:fe;return N?t.jsx(o.Tooltip,{title:C?"Expand all groups":"Collapse all groups",children:t.jsx(o.IconButton,{onClick:N,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:je=>D(je.palette.text.primary,.06),color:"text.primary"}},children:C?t.jsx($.UnfoldMore,{sx:{fontSize:20}}):t.jsx($.UnfoldLess,{sx:{fontSize:20}})})}):null})(),Ne.length>1&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),Ne.map(C=>{const N=nt===C,oe=C==="list"?t.jsx($.TableRows,{sx:{fontSize:20}}):t.jsx($.GridView,{sx:{fontSize:20}}),je=C==="list"?"List view":"Grid view";return t.jsx(o.Tooltip,{title:je,children:t.jsx(o.IconButton,{size:"small",onClick:()=>Et(C),sx:{borderRadius:1,color:N?"primary.main":"text.secondary",bgcolor:N?Ae=>jt(Ae):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:N?Ae=>D(Ae.palette.primary.main,.2):Ae=>D(Ae.palette.text.primary,.06),color:N?"primary.main":"text.primary"}},children:oe})},C)})]}),!(ke!=null&&ke.includes("settings"))&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),t.jsx(o.Tooltip,{title:"Settings",children:t.jsx(o.IconButton,{onClick:C=>Ce(C.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:C=>D(C.palette.text.primary,.06),color:"text.primary"}},children:t.jsx($.Settings,{sx:{fontSize:20}})})})]})]}),t.jsxs(o.Popover,{open:!!xe,anchorEl:xe,onClose:()=>Ce(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:200,py:.5,borderRadius:1.5,boxShadow:3}},children:[re&&!(ke!=null&&ke.includes("export"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{re(),Ce(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Download,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Export"})]}),!Je&&Q&&!(ke!=null&&ke.includes("grouping"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Q(),Ce(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Layers,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Grouping"})]}),ae&&!(ke!=null&&ke.includes("auditHistory"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ae(),Ce(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.History,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Audit History"})]}),ze&&!(ke!=null&&ke.includes("scheduledReports"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ze(),Ce(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Scheduled Reports"})]}),or==null?void 0:or.map(C=>t.jsxs(o.MenuItem,{dense:!0,disabled:C.disabled,onClick:()=>{C.onClick(),Ce(null)},sx:{py:1,px:2,gap:1.5},children:[C.icon,t.jsx(o.Typography,{variant:"body2",children:C.label})]},C.key))]}),t.jsxs(o.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[yr&&yr.length>0&&at.size>0&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,px:2,py:1,bgcolor:C=>it(C).bg,borderBottom:"1px solid",borderColor:"divider"},children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:C=>C.typography.body2.fontWeight||600,mr:1},children:[at.size," selected"]}),t.jsx(o.Button,{size:"small",onClick:()=>xt==null?void 0:xt(),children:"Clear"}),yr.map(C=>{var oe,je;const N=Array.from(ot);return(oe=C.hidden)!=null&&oe.call(C,N)?null:t.jsx(o.Button,{size:"small",variant:"outlined",startIcon:C.icon,disabled:(je=C.disabled)==null?void 0:je.call(C,N),onClick:()=>C.onClick(N),children:C.label},C.key)})]}),nt!=="list"&&t.jsx(o.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:t.jsx(bu,{data:Me,visibleColumns:Ur,grouping:g,selectedRowIds:ot,isGrouped:!!Kr,onToggleGroupCollapse:I,onCardClick:(C,N)=>go(C,N),onCardDoubleClick:C=>{et!=null&&et.includes("doubleClick")&&(ve(C),Z(!0))},onCardContextMenu:(C,N,oe)=>{gt==null||gt(C,N,oe),st(null),Ge({mouseX:oe.clientX,mouseY:oe.clientY,row:C,rowIndex:N}),et!=null&&et.includes("rightClick")&&(ve(C),Z(!0))},onOpenRowMenu:(C,N,oe)=>Ge({anchorEl:oe,row:C,rowIndex:N}),onToggleSelection:C=>qe==null?void 0:qe(C),hideSelectionCheckboxes:Ht})}),nt==="list"&&t.jsxs(o.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[t.jsx(o.Box,{ref:Vr,onScroll:C=>{fo.current&&(fo.current.scrollLeft=C.target.scrollLeft)},sx:{overflowX:"auto",overflowY:"hidden",flexShrink:0,scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:t.jsxs(o.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(qr).reduce((C,N)=>C+N,0)}px`},children:[t.jsxs("colgroup",{children:[Dt&&t.jsx("col",{style:{width:"40px"}}),pt.map(C=>t.jsx("col",{style:{width:`${qr[C.name]}px`}},C.name))]}),t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{sx:{bgcolor:(ee==null?void 0:ee.headerBg)??"action.hover",borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider"},children:[Dt&&t.jsx(o.TableCell,{padding:"checkbox",sx:{borderBottom:(ee==null?void 0:ee.rowDivider)??"1px solid",borderColor:"divider",verticalAlign:(ee==null?void 0:ee.cellAlignV)??"middle"},children:t.jsx(o.Checkbox,{size:"small",checked:Mo,indeterminate:Rn,onChange:C=>zt==null?void 0:zt(C.target.checked,Me)})}),pt.map((C,N)=>{const oe=Tr.has(C.name);return t.jsx(cu,{column:C,index:N,isGrouped:oe,sortRule:n.find(je=>je.column===C.name),hasFilters:Xn(i,C.name),isInSortStack:n.some(je=>je.column===C.name),isReadOnly:Je,hasModifications:Wn,width:oe?32:y[C.name],onColumnClick:In,onMoveColumn:En,onColumnDragEnd:Dn,onResizeStart:Tn,onSortAscending:k||$n,onSortDescending:b||_n,onRemoveSort:On,onOpenFilterForColumn:h||(()=>{}),onClearFiltersForColumn:de||(()=>{}),onGroupByColumn:pe,onHideColumn:Mn,onManageColumns:ge||(()=>{}),onResetLayout:ie},C.name)})]})})]})}),t.jsx(o.Box,{ref:fo,onScroll:C=>{Vr.current&&(Vr.current.scrollLeft=C.target.scrollLeft)},sx:{flex:1,overflowY:"auto",overflowX:"auto",minHeight:0,bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:C=>D(C.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:C=>D(C.palette.text.primary,.3)}}},children:t.jsxs(o.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(qr).reduce((C,N)=>C+N,0)}px`},children:[t.jsxs("colgroup",{children:[Dt&&t.jsx("col",{style:{width:"40px"}}),pt.map(C=>t.jsx("col",{style:{width:`${qr[C.name]}px`}},C.name))]}),t.jsx(o.TableBody,{children:Me.length===0?t.jsx(o.TableRow,{children:t.jsx(o.TableCell,{colSpan:pt.length+(Dt?1:0),align:"center",sx:{py:4},children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):Kr?Me.map((C,N)=>C.isGroupHeader?Xr(C):Ao(C,N)):Me.map((C,N)=>Ao(C,N))})]})})]}),Tt&&mr&&t.jsx(Su,{currentPage:ao,pageSize:rr,totalRows:lo,totalFields:e.length,onPageChange:Tt,onPageSizeChange:mr}),!(Tt&&mr)&&t.jsx(o.Box,{sx:{px:3,py:1.5,bgcolor:"action.hover",borderTop:1,borderColor:"divider"},children:t.jsxs(o.Typography,{variant:"body2",color:"text.secondary",children:["Showing ",Me.length," ",Me.length===1?"row":"rows"]})})]})]}),t.jsxs(o.Popover,{open:!!Se,onClose:()=>{Ge(null),st(null)},anchorEl:(Se==null?void 0:Se.anchorEl)||null,anchorReference:Se!=null&&Se.anchorEl?"anchorEl":"anchorPosition",anchorPosition:Se&&!Se.anchorEl?{top:Se.mouseY,left:Se.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:Se!=null&&Se.anchorEl?{vertical:"top",horizontal:"right"}:{vertical:"top",horizontal:"left"},PaperProps:{sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3}},children:[!(Ve!=null&&Ve.includes("view"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(ve(Se.row),Z(!0)),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"View"})]}),!(Ve!=null&&Ve.includes("edit"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(qt(Se.row),Nr(Se.rowIndex),Rr(!0)),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.Edit,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Edit"})]}),!(Ve!=null&&Ve.includes("duplicate"))&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(Ze==null||Ze(Se.rowIndex,Se.row)),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Duplicate"})]}),Se&&(xr==null?void 0:xr.map(C=>{var N,oe;return(N=C.hidden)!=null&&N.call(C,Se.row)?null:t.jsxs(o.MenuItem,{dense:!0,disabled:(oe=C.disabled)==null?void 0:oe.call(C,Se.row),onClick:()=>{C.onClick(Se.row,Se.rowIndex),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[C.icon,t.jsx(o.Typography,{variant:"body2",children:C.label})]},C.key)})),at.size>0&&tr&&!(Ve!=null&&Ve.includes("export"))&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.MenuItem,{dense:!0,onMouseEnter:C=>{It(),st(C.currentTarget)},onMouseLeave:kr,sx:{py:1,px:2,gap:1.5,justifyContent:"space-between"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx($.Download,{sx:{fontSize:18,color:"text.secondary"}}),t.jsxs(o.Typography,{variant:"body2",children:["Export Selected (",at.size,")"]})]}),t.jsx($.ChevronRight,{sx:{fontSize:18,color:"text.secondary"}})]}),t.jsx(o.Popper,{open:!!wr,anchorEl:wr,placement:"right-start",transition:!0,sx:{zIndex:C=>C.zIndex.modal+1},modifiers:[{name:"offset",options:{offset:[0,0]}}],children:({TransitionProps:C})=>t.jsx(o.Grow,{...C,timeout:150,children:t.jsx(o.Paper,{onMouseEnter:It,onMouseLeave:kr,sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3},children:t.jsxs(o.MenuList,{dense:!0,autoFocusItem:!1,children:[t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{tr("csv"),st(null),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.TableChart,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"CSV"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{tr("excel"),st(null),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.TableChart,{sx:{fontSize:18,color:"success.main"}}),t.jsx(o.Typography,{variant:"body2",children:"Excel"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{tr("json"),st(null),Ge(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx($.DataObject,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"JSON"})]})]})})})})]}),!(Ve!=null&&Ve.includes("delete"))&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(jr(Se.row),be(!0)),Ge(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[t.jsx($.Delete,{sx:{fontSize:18,color:"error.main"}}),t.jsx(o.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]}),t.jsx(ku,{open:yt,onClose:()=>{Z(!1),ve(null)},row:Yt,schema:e,reportName:Vt}),t.jsx(Tu,{open:po,onClose:()=>{Rr(!1),qt(null),Nr(null)},onSave:C=>{Pr!==null&&(Qe==null||Qe(Pr,C))},row:ho,schema:e,reportName:Vt}),t.jsx(zu,{open:he,onClose:()=>{be(!1),jr(null)},onConfirm:()=>{Cr!==null&&(Wt==null||Wt(Cr))},row:Cr,schema:e}),t.jsx(Js,{isOpen:zr,onClose:()=>Lr(!1)})]})}function $r({content:e,isDev:r=!1}){const[n,i]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(o.IconButton,{size:"small",onClick:s=>i(s.currentTarget),"aria-label":`Help: ${e.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:s=>D(s.palette.primary.main,.08)}},children:t.jsx($.InfoOutlined,{sx:{fontSize:15}})}),t.jsxs(o.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:{width:280,borderRadius:"10px",boxShadow:4,p:0,overflow:"hidden"}},children:[t.jsx(o.Box,{sx:{px:2,py:1.5,bgcolor:s=>D(s.palette.primary.main,.06)},children:t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:s=>s.typography.body2.fontWeight||600,color:"primary.main",fontSize:s=>s.typography.body2.fontSize||"0.875rem"},children:e.title})}),t.jsx(o.Divider,{}),t.jsxs(o.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:s=>s.typography.body2.fontSize||"0.8125rem",lineHeight:1.6},children:e.description}),e.tips&&e.tips.length>0&&t.jsx(o.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:e.tips.map((s,a)=>t.jsx(o.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},a))}),r&&e.devNote&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:s=>D(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>D(s.palette.warning.main,.2)},children:[t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:s=>s.typography.caption.fontWeight||500,fontSize:s=>s.typography.caption.fontSize||"0.75rem",display:"block",mb:.25},children:"Dev note"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",fontSize:s=>s.typography.caption.fontSize||"0.75rem",lineHeight:1.5},children:e.devNote})]})]})]})]})]})}const _r={filter:{title:"Filter columns",description:"Narrow down rows by setting conditions on any column. Only rows matching all active filters are shown.",tips:["Add multiple conditions to combine filters (AND logic)",'Use "Contains" for partial text matches','Use "Is empty" to find missing values',"Clear all filters to return to the full dataset"],devNote:"Max filter conditions controlled by DevConfig → Filter → maxConditions. Allowed operators also configurable."},sort:{title:"Sort columns",description:"Order rows by one or more columns. Drag levels to set sort priority — the first level is applied first.",tips:["Add multiple sort levels for multi-column sorting","Drag the ⋮⋮ handle to reorder sort priority","Each level can be ascending (A→Z, 0→9) or descending"],devNote:"Max sort levels controlled by DevConfig → Sort → maxLevels."},grouping:{title:"Group data",description:"Organize rows into collapsible groups by one or more column values. Each unique value becomes a group header.",tips:["Add up to 3 nesting levels for hierarchical grouping","Click a group header to collapse or expand it","Aggregates (count) are shown on each group header","Combine grouping with filters and sort for focused views"],devNote:"Max group levels controlled by DevConfig → Grouping → maxLevels. allowNested and allowCollapse also configurable."},columns:{title:"Manage columns",description:"Control which columns are visible, their display order, and their widths.",tips:["Drag rows to reorder columns","Toggle the eye icon to show or hide a column","Drag the resize handle in the table header to resize","Reset to restore default visibility and order"],devNote:"Max visible columns and width range controlled by DevConfig → Columns."},export:{title:"Export data",description:"Download the report data as a file. Choose between CSV, Excel, or JSON format.",tips:["CSV: universal format, opens in any spreadsheet app","Excel: formatted .xlsx file with native Excel support","JSON: structured data including metadata","Export visible rows only (after filters) or all rows"],devNote:"Allowed export formats controlled by DevConfig → Export → allowedFormats."},schedule:{title:"Scheduled reports",description:"Set up automatic exports that run at a specified time — daily, weekly, or monthly.",tips:["The browser tab must remain open for the schedule to fire","Each schedule triggers a file download automatically","Add an email address to open a notification in your mail app","Pause a schedule without deleting it"],devNote:"Schedules are stored in localStorage per-report. Key: urm_schedules_{reportId}."},auditHistory:{title:"Audit history",description:"A full log of all changes made to this report — filters applied, sorts changed, views saved, exports triggered, and more.",tips:["Each entry shows the action, timestamp, and who performed it","Use audit history to trace back unexpected changes"],devNote:"Audit entries are stored per-report in IndexedDB via the persistence layer."}},Kn=40;function Lu({operator:e,onSelect:r}){return t.jsxs(o.Select,{value:e,onChange:n=>r(n.target.value),size:"small",variant:"outlined",sx:{position:"relative",zIndex:1,mt:1,width:58,height:24,fontSize:"0.6875rem",fontWeight:700,color:"primary.main",bgcolor:"background.paper",borderRadius:"6px","& .MuiSelect-select":{py:0,px:1,display:"flex",alignItems:"center"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"}},children:[t.jsx(o.MenuItem,{value:"and",sx:{fontSize:"0.75rem",fontWeight:600},children:"AND"}),t.jsx(o.MenuItem,{value:"or",sx:{fontSize:"0.75rem",fontWeight:600},children:"OR"})]})}function Fu({condition:e,schema:r,availableColumns:n,devConfig:i,onUpdate:s}){const a=r.find(p=>p.name===e.column),c=f.useMemo(()=>{const p=a?rn(a.type):[],x=i.filter.allowedOperators;return x.length>0?p.filter(y=>x.includes(y.value)):p},[a,i]),l=El(e.operator);return t.jsxs(o.Box,{sx:{display:"flex",gap:1,alignItems:"center",flexWrap:"wrap"},children:[t.jsx(o.FormControl,{size:"small",sx:{minWidth:150,flex:"1 1 150px"},children:t.jsx(o.Select,{value:e.column,onChange:p=>{var g;const x=r.find(v=>v.name===p.target.value),y=x?rn(x.type):[];s({column:p.target.value,operator:((g=y[0])==null?void 0:g.value)??e.operator,value:void 0})},displayEmpty:!0,sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper"},children:n.map(p=>t.jsx(o.MenuItem,{value:p.name,sx:{fontSize:"0.875rem"},children:lt(p.name)},p.name))})}),t.jsx(o.FormControl,{size:"small",sx:{minWidth:130,flex:"1 1 130px"},children:t.jsx(o.Select,{value:e.operator,onChange:p=>s({operator:p.target.value,value:void 0}),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper"},children:c.map(p=>t.jsx(o.MenuItem,{value:p.value,sx:{fontSize:"0.875rem"},children:p.label},p.value))})}),l&&(a==null?void 0:a.type)==="date"&&t.jsx(o.TextField,{size:"small",type:"date",value:e.value??"",onChange:p=>s({value:p.target.value}),sx:{minWidth:160,flex:"1 1 160px","& .MuiInputBase-root":{height:36,fontSize:"0.875rem"}}}),l&&(a==null?void 0:a.type)!=="date"&&t.jsx(o.TextField,{size:"small",type:(a==null?void 0:a.type)==="number"?"number":"text",value:e.value??"",onChange:p=>s({value:(a==null?void 0:a.type)==="number"?Number(p.target.value):p.target.value}),placeholder:"Value…",sx:{minWidth:160,flex:"1 1 160px","& .MuiInputBase-root":{height:36,fontSize:"0.875rem"}}})]})}function ta({group:e,depth:r,schema:n,availableColumns:i,devConfig:s,maxConditions:a,totalConditions:c,onChange:l}){const p=c>=a;return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[e.children.map((x,y)=>t.jsxs(o.Box,{sx:{display:"flex",alignItems:"stretch",gap:1},children:[t.jsxs(o.Box,{sx:{width:Kn,flexShrink:0,position:"relative",display:"flex",justifyContent:"center"},children:[y<e.children.length-1&&t.jsx(o.Box,{sx:{position:"absolute",top:0,bottom:0,left:"50%",width:"1px",bgcolor:"divider"}}),y>0&&t.jsx(Lu,{operator:e.operator,onSelect:g=>l(v=>ai(v,e.id,g))}),y>0&&t.jsx(o.Box,{sx:{position:"absolute",top:13,left:"50%",width:Kn/2,height:"1px",bgcolor:"divider"}})]}),t.jsx(o.Box,{sx:{flex:1,minWidth:0,pt:y>0?1:0},children:Ye(x)?t.jsx(Vu,{group:x,depth:r+1,schema:n,availableColumns:i,devConfig:s,maxConditions:a,totalConditions:c,onChange:l}):t.jsx(Fu,{condition:x,schema:n,availableColumns:i,devConfig:s,onUpdate:g=>l(v=>si(v,x.id,g))})}),t.jsx(o.IconButton,{size:"small",onClick:()=>l(g=>li(g,x.id)),sx:{mt:y>0?1:.25,color:"text.secondary",flexShrink:0},children:t.jsx($.Close,{sx:{fontSize:16}})})]},x.id)),t.jsxs(o.Box,{sx:{display:"flex",gap:2,pl:`${Kn}px`},children:[t.jsx(o.Button,{size:"small",disabled:p||i.length===0,onClick:()=>l(x=>{var y,g,v;return so(x,e.id,{id:io(),column:((y=i[0])==null?void 0:y.name)??"",operator:((v=rn(((g=i[0])==null?void 0:g.type)??"string")[0])==null?void 0:v.value)??"equals"})}),sx:{fontSize:"0.8125rem",color:"primary.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",textDecoration:"underline"}},children:"+ Add condition"}),t.jsx(o.Button,{size:"small",disabled:p,onClick:()=>l(x=>so(x,e.id,_t())),sx:{fontSize:"0.8125rem",color:"text.secondary",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",textDecoration:"underline"}},children:"+ Add group"})]})]})}function Vu(e){return t.jsx(o.Box,{sx:{position:"relative",border:"1px solid",borderColor:r=>D(r.palette.primary.main,.2),borderLeft:"3px solid",borderLeftColor:"primary.main",bgcolor:r=>D(r.palette.primary.main,r.palette.mode==="dark"?.06:.03),borderRadius:"8px",p:1.25},children:t.jsx(ta,{...e})})}function Hu({schema:e,filters:r,onReplaceFilters:n,onClose:i,focusColumn:s}){const[a,c]=f.useState(r??_t()),l=Dr(),p=f.useMemo(()=>e.filter(m=>m.type!=="mixed"&&m.type!=="null"&&m.type!=="array"&&m.type!=="object"),[e]);f.useEffect(()=>{var z;const m=r??_t();if(s&&m.children.length===0){const h=e.find(B=>B.name===s);if(h){c(so(m,m.id,{id:io(),column:s,operator:((z=rn(h.type)[0])==null?void 0:z.value)??"equals"}));return}}c(m)},[r,s,e]);const x=Ct(a),y=l.filter.maxConditions,g=f.useCallback(m=>{c(z=>m(z))},[]),v=f.useMemo(()=>JSON.stringify(a)!==JSON.stringify(r??_t()),[a,r]),S=f.useCallback(()=>{n(a),i()},[a,n,i]),k=f.useCallback(()=>{c(r??_t()),i()},[r,i]),b=f.useCallback(()=>{n(_t()),i()},[n,i]);return t.jsx(o.Box,{onClick:k,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:m=>D(m.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:m=>m.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:m=>m.stopPropagation(),elevation:0,sx:{position:"relative",width:640,maxWidth:"calc(100vw - 120px)",maxHeight:"min(620px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:m=>tt(m),bgcolor:"background.paper",outline:"none",boxShadow:m=>ue(m).paper.boxShadow,border:m=>ue(m).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:m=>ue(m).header.backgroundColor,borderBottom:m=>ue(m).header.borderBottom,boxShadow:m=>ue(m).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:m=>m.typography.h6.fontSize||"1.125rem",fontWeight:m=>m.typography.h6.fontWeight||500,color:m=>m.typography.h6.color||"text.primary",lineHeight:1.5},children:"Filter columns"}),t.jsx($r,{content:_r.filter,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:k,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:m=>D(m.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:m=>D(m.palette.text.primary,.3)}}},children:[x===0&&t.jsxs(o.Typography,{variant:"body2",sx:{color:"text.disabled",fontSize:m=>m.typography.body2.fontSize||"0.875rem",mb:2},children:["No conditions yet — add one below to start filtering",s?` on "${lt(s)}"`:"","."]}),t.jsx(ta,{group:a,depth:0,schema:e,availableColumns:p,devConfig:l,maxConditions:y,totalConditions:x,onChange:g}),x>=y&&t.jsxs(o.Typography,{variant:"caption",sx:{display:"block",mt:1.5,color:"warning.dark",fontSize:m=>m.typography.caption.fontSize||"0.75rem",fontWeight:m=>m.typography.caption.fontWeight||500},children:["Filter limit reached — maximum ",y," conditions allowed. Remove one to add another."]})]}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",alignItems:"center",gap:1.5,justifyContent:"space-between",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:b,disabled:x===0,sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"text.disabled"}},children:"Clear all"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1.5},children:[t.jsx(o.Button,{onClick:k,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:m=>`${m.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:S,disabled:!v,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:m=>`${m.shape.borderRadius}px`,boxShadow:m=>ye(m,"restButton"),"&:hover":{bgcolor:"primary.dark"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})]})})}const hs="SORT_RULE";function Uu({rule:e,index:r,onToggleDirection:n,onRemove:i,onMove:s}){const a=f.useRef(null),[{handlerId:c},l]=Zt.useDrop({accept:hs,collect(y){return{handlerId:y.getHandlerId()}},hover(y,g){var h;if(!a.current)return;const v=y.index,S=r;if(v===S)return;const k=(h=a.current)==null?void 0:h.getBoundingClientRect(),b=(k.bottom-k.top)/2,m=g.getClientOffset(),z=((m==null?void 0:m.y)??0)-k.top;v<S&&z<b||v>S&&z>b||(s(v,S),y.index=S)}}),[{isDragging:p},x]=Zt.useDrag({type:hs,item:()=>({index:r}),collect:y=>({isDragging:y.isDragging()})});return x(l(a)),t.jsxs(o.Box,{ref:a,"data-handler-id":c,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:p?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:y=>ye(y,"restButtonLight"),transform:"translateY(-1px)"}},children:[t.jsx(o.Chip,{label:e.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:y=>`0 1px 2px 0 ${D(y.palette.primary.main,.3)}`,"& .MuiChip-label":{px:0}}}),t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[t.jsx(o.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),t.jsx(o.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),t.jsx(o.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:y=>y.typography.body2.fontSize||"0.875rem",fontWeight:y=>y.typography.body2.fontWeight||400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:e.column}),t.jsx(o.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:t.jsxs(o.Select,{value:e.direction,onChange:y=>n(r,y.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[t.jsx(o.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:y=>jt(y),"&:hover":{bgcolor:y=>D(y.palette.primary.main,.2)}}},children:"Ascending"}),t.jsx(o.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:y=>jt(y),"&:hover":{bgcolor:y=>D(y.palette.primary.main,.2)}}},children:"Descending"})]})}),t.jsx(o.IconButton,{onClick:()=>i(r),size:"small",sx:{p:.5,color:"text.secondary",transition:"all 0.2s ease","&:hover":{color:"error.main",bgcolor:y=>D(y.palette.error.main,.08),transform:"scale(1.1)"}},children:t.jsx($.Close,{sx:{fontSize:18}})})]})}function Gu({schema:e,sortStack:r,onUpdateSortStack:n,onClose:i}){const[s,a]=f.useState(""),[c,l]=f.useState([]);f.useEffect(()=>{l([...r])},[r]);const p=f.useMemo(()=>JSON.stringify(c)!==JSON.stringify(r),[c,r]),x=Dr(),y=f.useCallback(h=>{if(!h||c.length>=x.sort.maxLevels)return;const B={column:h,direction:"asc",priority:c.length+1};l([...c,B]),a(""),setTimeout(()=>{var T;return(T=document.activeElement)==null?void 0:T.blur()},0)},[c,x.sort.maxLevels]),g=f.useCallback(h=>{const T=c.filter((w,P)=>P!==h).map((w,P)=>({...w,priority:P+1}));l(T)},[c]),v=f.useCallback((h,B)=>{const T=[...c];T[h]={...T[h],direction:B},l(T)},[c]),S=f.useCallback((h,B)=>{const T=[...c],[w]=T.splice(h,1);T.splice(B,0,w);const P=T.map((O,M)=>({...O,priority:M+1}));l(P)},[c]),k=f.useCallback(()=>{n([]),i()},[n,i]),b=f.useCallback(()=>{n(c),i()},[c,n,i]),m=f.useCallback(()=>{l([...r]),a(""),i()},[r,i]),z=e.filter(h=>!c.some(B=>B.column===h.name));return t.jsx(Zt.DndProvider,{backend:ni.HTML5Backend,children:t.jsx(o.Box,{onClick:m,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:h=>D(h.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:h=>h.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:h=>h.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:h=>tt(h),bgcolor:"background.paper",outline:"none",boxShadow:h=>ue(h).paper.boxShadow,border:h=>ue(h).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:h=>ue(h).header.backgroundColor,borderBottom:h=>ue(h).header.borderBottom,boxShadow:h=>ue(h).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:h=>h.typography.h6.fontSize||"1.125rem",fontWeight:h=>h.typography.h6.fontWeight||500,color:h=>h.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),t.jsx($r,{content:_r.sort,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:m,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:h=>D(h.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:h=>D(h.palette.text.primary,.3)}}},children:[t.jsxs(o.Box,{sx:{mb:2.5},children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:h=>h.typography.caption.fontSize||"0.6875rem",fontWeight:h=>h.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,disabled:c.length>=x.sort.maxLevels,children:[t.jsx(o.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Select column..."}),t.jsx(o.Select,{value:s,onChange:h=>y(h.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:z.map(h=>t.jsx(o.MenuItem,{value:h.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:B=>jt(B),"&:hover":{bgcolor:B=>D(B.palette.primary.main,.2)}}},children:lt(h.name)},h.name))})]}),c.length>=x.sort.maxLevels&&t.jsxs(o.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:h=>h.typography.caption.fontSize||"0.75rem",fontWeight:h=>h.typography.caption.fontWeight||500},children:["Maximum ",x.sort.maxLevels," sort levels allowed"]})]}),c.length>0&&t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[t.jsxs(o.Typography,{variant:"overline",sx:{fontSize:h=>h.typography.caption.fontSize||"0.6875rem",fontWeight:h=>h.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",c.length,"/",x.sort.maxLevels,")"]}),t.jsx(o.Button,{onClick:k,sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map((h,B)=>t.jsx(Uu,{rule:h,index:B,onToggleDirection:v,onRemove:g,onMove:S},`${h.column}-${B}`))})]})]}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:m,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:h=>`${h.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:b,variant:"contained",disabled:!p||c.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:h=>`${h.shape.borderRadius}px`,boxShadow:h=>ye(h,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:h=>ye(h,"hoverButton")},"&:active":{boxShadow:h=>ye(h,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}const Go=50;function fs({currentSnapshot:e,onSave:r,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:a="",initialIsDefault:c=!1,atViewLimit:l=!1,maxViews:p=10}){const[x,y]=f.useState(s),[g,v]=f.useState(!1),[S,k]=f.useState(a),[b,m]=f.useState(c),z=()=>{if(!x.trim()){v(!0);return}if(x.trim().length>Go){v(!0);return}r(x.trim(),S.trim(),b),n()},h=T=>{T.key==="Enter"&&!T.shiftKey?z():T.key==="Escape"&&n()},B=()=>i&&s?`Update ${s} view`:"Create New Report View";return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:T=>({mt:8,borderRadius:tt(T),...ue(T).paper})},children:[t.jsxs(o.DialogTitle,{sx:T=>({display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,...ue(T).header}),children:[B(),t.jsx(o.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&t.jsxs(o.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",p," saved views. Delete an existing view before creating a new one."]}),t.jsx(o.TextField,{label:"View Name",required:!0,value:x,onChange:T=>{T.target.value.length<=Go&&y(T.target.value),g&&T.target.value.trim()&&v(!1)},onKeyDown:h,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:Go},error:g&&!x.trim(),helperText:g&&!x.trim()?"View name is required":`${x.length} / ${Go}`}),t.jsx(o.TextField,{label:"Description (optional)",value:S,onChange:T=>k(T.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),t.jsxs(o.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:T=>T.typography.body2.fontWeight||500,mb:1},children:"This view will capture:"}),t.jsxs(o.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[t.jsxs("li",{children:[Ct(e.filters)," filter",Ct(e.filters)!==1?"s":""]}),t.jsxs("li",{children:["Sorting: ",Ga(e.sortStack)]}),t.jsx("li",{children:"Column order & visibility"})]})]}),!i&&t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:b,onChange:T=>m(T.target.checked),size:"small"}),label:t.jsx(o.Typography,{variant:"body2",children:"Set as default view"})})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:z,variant:"contained",disabled:l&&!i,startIcon:t.jsx($.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,boxShadow:T=>ye(T,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:T=>ye(T,"hoverButton")},"&:active":{boxShadow:T=>ye(T,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function Yu({viewName:e,onConfirm:r,onCancel:n}){return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:i=>({borderRadius:tt(i),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",...ue(i).paper})},children:[t.jsxs(o.DialogTitle,{sx:i=>({display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,...ue(i).header}),children:["Delete View",t.jsx(o.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,mt:1},children:[t.jsx($.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),t.jsxs(o.Box,{children:[t.jsxs(o.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",t.jsxs("strong",{children:['"',e,'"']}),"?"]}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[t.jsx(o.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:r,variant:"contained",color:"error",sx:{fontSize:"0.875rem",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>ye(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>ye(i,"hoverButton")},"&:active":{boxShadow:i=>ye(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const Jo=100,Ko=600,ms="COLUMN";function qu({column:e,index:r,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:a,moveColumn:c}){const l=f.useRef(null),[p,x]=f.useState(i.toString());f.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:y},g]=Zt.useDrop({accept:ms,collect(h){return{handlerId:h.getHandlerId()}},hover(h,B){var J;if(!l.current)return;const T=h.index,w=r;if(T===w)return;const P=(J=l.current)==null?void 0:J.getBoundingClientRect(),O=(P.bottom-P.top)/2,M=B.getClientOffset(),Y=((M==null?void 0:M.y)??0)-P.top;T<w&&Y<O||T>w&&Y>O||(c(T,w),h.index=w)}}),[{isDragging:v},S]=Zt.useDrag({type:ms,item:()=>({index:r}),collect:h=>({isDragging:h.isDragging()})});S(g(l));const k=()=>{const h=parseInt(p);if(isNaN(h)){x(i.toString()),a(e.name,i);return}const B=Math.max(Jo,Math.min(Ko,h));x(B.toString()),a(e.name,B)},b=h=>{if(h===""||/^\d+$/.test(h)){x(h);const B=parseInt(h);if(!isNaN(B)&&B>=Jo){const T=Math.min(Ko,B);a(e.name,T)}}},m=h=>{h.key==="Enter"&&(h.preventDefault(),k(),h.target.blur())},z=h=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[h]||"text.secondary";return t.jsxs(o.TableRow,{ref:l,"data-handler-id":y,sx:{opacity:v?.4:1,bgcolor:n?"background.paper":"action.hover",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"action.hover":"action.selected"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[t.jsx(o.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:t.jsx($.DragIndicator,{sx:{fontSize:20}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:h=>h.typography.body2.fontWeight||400,fontSize:h=>h.typography.body2.fontSize||"0.875rem",color:n?"text.primary":"text.secondary"},children:lt(e.name)})]})}),t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsx(o.Chip,{label:e.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${z(e.type)}15`,color:z(e.type),border:`1px solid ${z(e.type)}30`,"& .MuiChip-label":{px:1}}})}),t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.TextField,{type:"number",value:p,onChange:h=>b(h.target.value),onBlur:k,onKeyDown:m,placeholder:"150",size:"small",inputProps:{min:Jo,max:Ko,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"},"& input[type=number]::-webkit-inner-spin-button":{opacity:1},"& input[type=number]::-webkit-outer-spin-button":{opacity:1}}}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:h=>h.typography.caption.fontSize||"0.75rem",color:"text.secondary"},children:"px"})]})}),t.jsx(o.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[t.jsx(o.IconButton,{onClick:()=>s(e.name,!n),title:n?"Hide column":"Show column",size:"small",sx:{p:.75,color:n?"primary.main":"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:n?"primary.dark":"primary.main"}},children:n?t.jsx($.Visibility,{sx:{fontSize:20}}):t.jsx($.VisibilityOff,{sx:{fontSize:20}})}),t.jsx(o.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?h=>D(h.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Ju({schema:e,columnVisibility:r,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:a="",onUpdateColumnVisibility:c,onUpdateColumnOrder:l,onUpdateColumnWidth:p,onResetLayout:x,onClose:y}){const[g,v]=f.useState(!1),[S,k]=f.useState(n),[b,m]=f.useState(i),[z,h]=f.useState("all");f.useEffect(()=>{k(n)},[n]),f.useEffect(()=>{m(i)},[i]);const B=(u,A)=>{m(F=>({...F,[u]:A})),p==null||p(u,A)},T=(u,A)=>{const F=[...S],[d]=F.splice(u,1);F.splice(A,0,d),k(F),l(F)},w=()=>{x(),v(!1)},O=S.map(u=>e.find(A=>A.name===u)).filter(u=>u!==void 0).filter(u=>{const A=r[u.name]??!0;return z==="active"?A:z==="hidden"?!A:!0}),M=Object.values(r).filter(u=>u).length,Y=e.length,J=s.find(u=>u.id===a),R=f.useMemo(()=>{if(!J)return!1;const u=J.snapshot,A=u.columnVisibility??{},F=JSON.stringify(r)!==JSON.stringify(A),d=u.columnOrder??[],ne=n??[],U=JSON.stringify(ne)!==JSON.stringify(d)&&!(ne.length===0&&d.length===0),re=u.columnWidths??{},ge=JSON.stringify(b)!==JSON.stringify(re);return F||U||ge},[J,r,n,b]);return t.jsx(Zt.DndProvider,{backend:ni.HTML5Backend,children:t.jsx(o.Box,{onClick:y,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:u=>D(u.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:u=>u.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:u=>u.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:u=>tt(u),bgcolor:"background.paper",outline:"none",boxShadow:u=>ue(u).paper.boxShadow,border:u=>ue(u).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2,pb:1.5,flexShrink:0,bgcolor:u=>ue(u).header.backgroundColor,borderBottom:u=>ue(u).header.borderBottom,boxShadow:u=>ue(u).header.boxShadow},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[t.jsx(o.Box,{sx:{flex:1},children:t.jsxs(o.Typography,{variant:"h6",sx:{fontSize:u=>u.typography.h6.fontSize||"1.125rem",fontWeight:u=>u.typography.h6.fontWeight||500,color:u=>u.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",t.jsx($r,{content:_r.columns,isDev:process.env.NODE_ENV==="development"})]})}),t.jsx(o.IconButton,{onClick:y,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Tabs,{value:z,onChange:(u,A)=>h(A),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:u=>it(u).main,height:3}},children:[t.jsx(o.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,px:2,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary",borderRadius:"8px 8px 0 0","&.Mui-selected":{borderBottomColor:"text.primary",fontWeight:600,bgcolor:u=>it(u).hoverBg},"&:hover":{color:"text.primary",bgcolor:u=>it(u).bg}}}),t.jsx(o.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,px:2,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary",borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:u=>it(u).hoverBg},"&:hover":{color:"text.primary",bgcolor:u=>it(u).bg}}}),t.jsx(o.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,px:2,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary",borderRadius:"8px 8px 0 0","&.Mui-selected":{color:"text.primary",fontWeight:600,bgcolor:u=>it(u).hoverBg},"&:hover":{color:"text.primary",bgcolor:u=>it(u).bg}}})]})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:u=>D(u.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:u=>D(u.palette.text.primary,.3)}}},children:t.jsxs(o.Table,{stickyHeader:!0,sx:{minWidth:650},children:[t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{children:[t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",t.jsx(o.Tooltip,{title:`Column width in pixels (min: ${Jo}px, max: ${Ko}px)`,arrow:!0,placement:"top",children:t.jsx($.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),t.jsx(o.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),t.jsx(o.TableBody,{children:O.length===0?t.jsx(o.TableRow,{children:t.jsx(o.TableCell,{colSpan:4,align:"center",sx:{py:6,borderBottom:"none"},children:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:u=>u.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):O.map((u,A)=>t.jsx(qu,{column:u,index:A,isVisible:r[u.name]??!0,width:b[u.name]||170,onToggleVisibility:c,onWidthChange:B,moveColumn:T},u.name))})]})}),t.jsx(o.Box,{sx:{px:3,py:1,borderTop:"1px solid divider",bgcolor:"background.default",flexShrink:0},children:t.jsxs(o.Typography,{variant:"body2",sx:{fontSize:u=>u.typography.body2.fontSize||"0.8125rem",color:"text.secondary"},children:[M," of ",Y," columns visible • Drag to reorder"]})}),t.jsx(o.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"action.hover"},children:t.jsx(o.Button,{onClick:()=>v(!0),disabled:!R,variant:"outlined",startIcon:t.jsx($.Undo,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",px:2.5,py:.875,minHeight:36,borderRadius:u=>`${u.shape.borderRadius}px`,"&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Reset"})}),g&&t.jsx(o.Box,{onClick:()=>v(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:u=>D(u.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:u=>u.zIndex.tooltip},children:t.jsxs(o.Paper,{onClick:u=>u.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:u=>$o(u),bgcolor:"background.paper",boxShadow:u=>ue(u).paper.boxShadow,border:u=>ue(u).paper.border},children:[t.jsxs(o.Box,{sx:{px:3,py:2.5},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:()=>v(!1),variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,borderRadius:u=>`${u.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:w,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:u=>`${u.shape.borderRadius}px`,boxShadow:u=>ye(u,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:u=>ye(u,"hoverButton")},"&:active":{boxShadow:u=>ye(u,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function Ku({schema:e,grouping:r,onApply:n,onClose:i}){var P;const[s,a]=f.useState(r||{enabled:!1,levels:[],collapsedGroups:[]}),[c,l]=f.useState(""),[p,x]=f.useState(null),y=f.useMemo(()=>Pa(e),[e]),g=f.useMemo(()=>y.filter(O=>!s.levels.some((M,Y)=>M.column===O.name&&Y!==p)),[y,s.levels,p]),v=Dr(),S=s.levels.length<v.grouping.maxLevels&&g.length>0,k=f.useCallback(O=>{!S||!O||(a({...s,levels:[...s.levels,{column:O}],enabled:!0}),l(""),setTimeout(()=>{var M;return(M=document.activeElement)==null?void 0:M.blur()},0))},[S,s]),b=f.useCallback(O=>{const M=s.levels.filter((Y,J)=>J!==O);if(M.length===0){n(null),i();return}a({...s,levels:M,enabled:M.length>0})},[s,n,i]),m=f.useCallback(O=>{x(O),l(s.levels[O].column)},[s.levels]),z=f.useCallback(()=>{if(p===null||!c)return;const O=[...s.levels];O[p]={column:c},a({...s,levels:O}),x(null),l("")},[p,c,s]),h=f.useCallback(()=>{x(null),l("")},[]),B=f.useCallback((O,M)=>{const Y=M==="up"?O-1:O+1;if(Y<0||Y>=s.levels.length)return;const J=[...s.levels],[R]=J.splice(O,1);J.splice(Y,0,R),a({...s,levels:J})},[s]),T=f.useCallback(()=>{n(null),i()},[n,i]),w=f.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(r==null?void 0:r.collapsedGroups)||[]}),i()},[s,r,n,i]);return t.jsx(o.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:O=>D(O.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:O=>O.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:O=>O.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:O=>tt(O),bgcolor:"background.paper",outline:"none",boxShadow:O=>ue(O).paper.boxShadow,border:O=>ue(O).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:O=>ue(O).header.backgroundColor,borderBottom:O=>ue(O).header.borderBottom,boxShadow:O=>ue(O).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:O=>O.typography.h6.fontSize||"1.125rem",fontWeight:O=>O.typography.h6.fontWeight||500,color:O=>O.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),t.jsx($r,{content:_r.grouping,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:O=>D(O.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:O=>D(O.palette.text.primary,.3)}}},children:t.jsxs(o.Stack,{spacing:2.5,children:[p===null&&t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:O=>O.typography.caption.fontSize||"0.6875rem",fontWeight:O=>O.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),t.jsx(o.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:t.jsxs(o.Select,{value:c,onChange:O=>k(O.target.value),disabled:!S,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:[t.jsx(o.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),g.map(O=>t.jsxs(o.MenuItem,{value:O.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:M=>jt(M),"&:hover":{bgcolor:M=>D(M.palette.primary.main,.2)}}},children:[lt(O.name)," (",O.type.toUpperCase(),")"]},O.name))]})}),s.levels.length>=v.grouping.maxLevels&&t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:O=>O.typography.caption.fontSize||"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),y.length===0&&t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:O=>O.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),p!==null&&t.jsxs(o.Alert,{severity:"warning",sx:{borderRadius:"8px",border:O=>`1px solid ${D(O.palette.warning.main,.5)}`,bgcolor:O=>D(O.palette.warning.main,.12),"& .MuiAlert-icon":{color:"warning.main"}},children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:O=>O.typography.body2.fontWeight||500,mb:1.5,fontSize:O=>O.typography.body2.fontSize||"0.875rem",color:"text.primary"},children:["Edit Group Level ",p+1]}),t.jsx(o.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:t.jsxs(o.Select,{value:c,onChange:O=>l(O.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[t.jsx(o.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),t.jsxs(o.MenuItem,{value:s.levels[p].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:O=>jt(O)}},children:[s.levels[p].column," (",(P=e.find(O=>O.name===s.levels[p].column))==null?void 0:P.type.toUpperCase(),")"]}),g.filter(O=>O.name!==s.levels[p].column).map(O=>t.jsxs(o.MenuItem,{value:O.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:M=>jt(M)}},children:[lt(O.name)," (",O.type.toUpperCase(),")"]},O.name))]})}),t.jsxs(o.Stack,{direction:"row",spacing:1.5,children:[t.jsx(o.Button,{onClick:z,disabled:!c,variant:"contained",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",bgcolor:"warning.main",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"warning.dark",boxShadow:O=>ye(O,"pressedButton")}},children:"Save"}),t.jsx(o.Button,{onClick:h,variant:"outlined",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",py:.875,"&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},children:"Cancel"})]})]}),s.levels.length>0&&p===null&&t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.5},children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:O=>O.typography.caption.fontSize||"0.6875rem",fontWeight:O=>O.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),t.jsx(o.Button,{onClick:T,size:"small",sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),t.jsx(o.Stack,{spacing:1.5,children:s.levels.map((O,M)=>{const Y=e.find(J=>J.name===O.column);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:J=>ye(J,"pressedButtonLight")}},children:[t.jsx(o.Chip,{label:`L${M+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:J=>`0 1px 2px 0 ${D(J.palette.primary.main,.3)}`}}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:J=>J.typography.body2.fontWeight||500,fontSize:J=>J.typography.body2.fontSize||"0.875rem",color:"text.primary"},children:O.column}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:J=>J.typography.caption.fontSize||"0.75rem",color:"text.secondary"},children:Y==null?void 0:Y.type.toUpperCase()})]}),t.jsxs(o.Stack,{direction:"row",spacing:.5,children:[t.jsx(o.IconButton,{size:"small",onClick:()=>B(M,"up"),disabled:M===0,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:t.jsx($.KeyboardArrowUp,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>B(M,"down"),disabled:M===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:t.jsx($.KeyboardArrowDown,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>m(M),sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover",color:"primary.main"}},children:t.jsx($.Edit,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>b(M),sx:{color:"text.secondary","&:hover":{bgcolor:J=>D(J.palette.error.main,.08),color:"error.main"}},children:t.jsx($.Delete,{sx:{fontSize:18}})})]})]},M)})})]})]})}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:i,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:O=>`${O.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:w,variant:"contained",disabled:s.levels.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:O=>`${O.shape.borderRadius}px`,boxShadow:O=>ye(O,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:O=>ye(O,"hoverButton")},"&:active":{boxShadow:O=>ye(O,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}function Xu({onExportAnyway:e,onSaveAndExport:r,onCancel:n}){return t.jsx(o.Box,{sx:{mb:2,mx:3,mt:2},children:t.jsxs(o.Alert,{severity:"warning",icon:t.jsx($.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:t.jsx($.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:i=>i.typography.h6.fontWeight||600,fontSize:i=>i.typography.h6.fontSize||"1rem",mb:.5},children:"You are exporting with unsaved view changes"}),t.jsx(o.Typography,{variant:"body2",sx:{mb:1.5},children:"Your current view has unsaved changes. Choose how to proceed:"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Button,{onClick:r,variant:"contained",color:"primary",startIcon:t.jsx($.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),t.jsx(o.Button,{onClick:e,variant:"contained",color:"warning",startIcon:t.jsx($.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const xs=[{key:"1h",label:"Last 1 Hour",ms:3600*1e3},{key:"24h",label:"Last 24 Hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 Days",ms:10080*60*1e3},{key:"30d",label:"Last 30 Days",ms:720*60*60*1e3},{key:"all",label:"All Time",ms:null}];function Qu(e,r){if(r===null)return e.length;const n=Date.now()-r;return e.filter(i=>new Date(i.timestamp).getTime()>=n).length}function Zu(e,r){if(r===null)return[];const n=Date.now()-r;return e.filter(i=>new Date(i.timestamp).getTime()<n)}function ep({auditHistory:e,onClose:r,onClearAuditHistory:n}){const i=ct(),s=i.palette,[a,c]=f.useState("1h"),[l,p]=f.useState(!1),x=[...e].sort((k,b)=>new Date(b.timestamp).getTime()-new Date(k.timestamp).getTime()),y=xs.find(k=>k.key===a),g=Qu(e,y.ms),v=()=>p(!0),S=()=>{n&&(n(Zu(e,y.ms)),p(!1))};return t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{onClick:r,sx:{position:"fixed",inset:0,bgcolor:D(s.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:i.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:k=>k.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:tt(i),bgcolor:"background.paper",overflow:"hidden",...ue(i).paper,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,...ue(i).header},children:[t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body1.fontSize||"0.9375rem",fontWeight:k=>k.typography.h6.fontWeight||600,color:"text.primary"},children:"Audit History"}),t.jsx($r,{content:_r.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),t.jsxs(o.Typography,{sx:{fontSize:k=>k.typography.caption.fontSize||"0.75rem",color:"text.secondary",mt:.125},children:[x.length," event",x.length!==1?"s":""," recorded"]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&e.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Select,{value:a,onChange:k=>c(k.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:D(s.text.primary,.3)}},children:xs.map(k=>t.jsx(o.MenuItem,{value:k.key,sx:{fontSize:"0.8125rem"},children:k.label},k.key))}),t.jsx(o.Button,{size:"small",variant:"outlined",color:"error",startIcon:t.jsx($.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:v,sx:{fontSize:"0.75rem",borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:D(s.error.main,.5),"&:hover":{bgcolor:D(s.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),t.jsx(o.IconButton,{onClick:r,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:17}})})]})]}),t.jsx(o.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:D(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D(s.text.primary,.14),borderRadius:3}},children:x.length===0?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[t.jsx($.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body1.fontSize||"0.9375rem",color:"text.secondary",fontWeight:k=>k.typography.body2.fontWeight||500},children:"No audit events yet"}),t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body2.fontSize||"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:x.map(k=>{const b=hu(i,k.feature),{summary:m,detail:z}=sl(k);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.25,px:1.5,py:1.25,borderRadius:"10px",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",transition:"border-color 0.15s","&:hover":{borderColor:D(s.text.primary,.18)}},children:[t.jsx(o.Chip,{label:cl(k.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:D(b,.1),color:b,border:`1px solid ${D(b,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),t.jsxs(o.Box,{sx:{flex:1,minWidth:0},children:[t.jsx(o.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:m}),z&&t.jsx(o.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:z}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[t.jsx($.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:dl(k.timestamp)})]}),k.user&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[t.jsx($.Person,{sx:{fontSize:11,color:"text.disabled"}}),t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:k.user})]})]})]})]},k.id)})})})]})}),t.jsxs(o.Dialog,{open:l,onClose:()=>p(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:$o(i),...ue(i).paper}},children:[t.jsxs(o.DialogContent,{sx:{pt:3,pb:2,px:3},children:[t.jsx(o.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:D(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),t.jsx(o.Typography,{sx:{fontSize:k=>k.typography.body1.fontSize||"0.9375rem",fontWeight:k=>k.typography.h6.fontWeight||600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),t.jsxs(o.Typography,{sx:{fontSize:k=>k.typography.body2.fontSize||"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["You are about to permanently remove"," ",t.jsxs(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:[g," audit record",g!==1?"s":""]})," ",y.key==="all"?"from all time":`from the ${y.label.toLowerCase()}`,". This action cannot be undone."]})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[t.jsx(o.Button,{onClick:()=>p(!1),variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),t.jsxs(o.Button,{onClick:S,variant:"contained",color:"error",startIcon:t.jsx($.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{fontSize:"0.8125rem",borderRadius:"7px",px:2},children:["Clear ",g," Record",g!==1?"s":""]})]})]})]})}function tp({onSave:e,onClose:r}){const[n,i]=f.useState(""),[s,a]=f.useState(""),[c,l]=f.useState(""),[p,x]=f.useState([]),[y,g]=f.useState(""),[v,S]=f.useState(""),k=w=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(w),b=()=>{const w=c.trim();if(w){if(!k(w)){S("Please enter a valid email address");return}if(p.includes(w)){S("This email is already added");return}x([...p,w]),l(""),S("")}},m=w=>{x(p.filter(P=>P!==w))},z=w=>{w.key==="Enter"&&(w.preventDefault(),b())},h=()=>{if(!n.trim()){g("Preset name is required");return}e(n.trim(),s.trim(),p.length>0?p:void 0)},B=w=>{i(w),y&&g("")},T=w=>{l(w),v&&S("")};return t.jsx(o.Box,{onClick:r,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:w=>D(w.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:w=>w.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:w=>w.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:w=>tt(w),bgcolor:"background.paper",outline:"none",boxShadow:w=>ue(w).paper.boxShadow,border:w=>ue(w).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:w=>ue(w).header.backgroundColor,borderBottom:w=>ue(w).header.borderBottom,boxShadow:w=>ue(w).header.boxShadow,flexShrink:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:w=>w.typography.h6.fontSize||"1.125rem",fontWeight:w=>w.typography.h6.fontWeight||500,color:w=>w.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),t.jsx(o.IconButton,{onClick:r,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:w=>D(w.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:w=>D(w.palette.text.primary,.3)}}},children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[t.jsx(o.Alert,{severity:"info",icon:t.jsx($.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:w=>`1px solid ${D(w.palette.primary.main,.3)}`,bgcolor:w=>jt(w),"& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:w=>w.typography.body2.fontSize||"0.875rem",color:"text.secondary",lineHeight:1.6},children:"Save the current report configuration and generate a shareable link that others can use to view the same filters, sorting, and column layout."}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:w=>w.typography.caption.fontSize||"0.6875rem",fontWeight:w=>w.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),t.jsx(o.TextField,{required:!0,value:n,onChange:w=>B(w.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!y,helperText:y,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:w=>w.typography.caption.fontSize||"0.6875rem",fontWeight:w=>w.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),t.jsx(o.TextField,{value:s,onChange:w=>a(w.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:w=>w.typography.caption.fontSize||"0.6875rem",fontWeight:w=>w.typography.caption.fontWeight||600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[t.jsx(o.TextField,{value:c,onChange:w=>T(w.target.value),onKeyPress:z,placeholder:"Enter email address",error:!!v,helperText:v,fullWidth:!0,size:"small",InputProps:{startAdornment:t.jsx($.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),t.jsx(o.Button,{onClick:b,variant:"outlined",startIcon:t.jsx($.Add,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",px:2,py:1.25,minHeight:40,borderRadius:w=>`${w.shape.borderRadius}px`,flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:"Add"})]}),p.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:p.map(w=>t.jsx(o.Chip,{label:w,onDelete:()=>m(w),deleteIcon:t.jsx($.Delete,{sx:{fontSize:16}}),sx:{bgcolor:P=>jt(P),color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},w))}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:p.length>0?`An email with the shareable link will be sent to ${p.length} recipient${p.length>1?"s":""}`:"Add email addresses to send the shareable link automatically"})]})]})}),t.jsxs(o.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[t.jsx(o.Button,{onClick:r,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:w=>`${w.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:h,variant:"contained",startIcon:t.jsx($.Share,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:w=>`${w.shape.borderRadius}px`,boxShadow:w=>ye(w,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:w=>ye(w,"hoverButton")},"&:active":{boxShadow:w=>ye(w,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function rp({presetName:e,onClear:r}){return t.jsx(o.Chip,{icon:t.jsx($.Link,{sx:{fontSize:14}}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Preset:"," ",t.jsx(o.Box,{component:"span",sx:{fontWeight:600},children:e})]}),onDelete:r,deleteIcon:t.jsx(o.IconButton,{size:"small",title:"Exit preset view",sx:{p:0},children:t.jsx($.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>D(n.palette.primary.main,.12),borderColor:"primary.light",border:1,fontSize:"body2.fontSize",fontWeight:500,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.main"}}}})}function op({presets:e,reportId:r,onOpenPreset:n,onDeletePreset:i,onClose:s}){const a=c=>new Date(c).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return t.jsx(o.Box,{onClick:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:c=>D(c.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:c=>c.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:c=>c.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:c=>tt(c),bgcolor:"background.paper",outline:"none",boxShadow:c=>ue(c).paper.boxShadow,border:c=>ue(c).paper.border,overflow:"hidden",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,bgcolor:c=>ue(c).header.backgroundColor,borderBottom:c=>ue(c).header.borderBottom,boxShadow:c=>ue(c).header.boxShadow,flexShrink:0},children:[t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:c=>c.typography.h6.fontSize||"1.125rem",fontWeight:c=>c.typography.h6.fontWeight||500,color:c=>c.typography.h6.color||"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:c=>c.typography.caption.fontSize||"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[e.length," saved ",e.length===1?"preset":"presets"]})]}),t.jsx(o.IconButton,{onClick:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto",px:3,py:2,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:c=>D(c.palette.text.primary,.2)}}},children:e.length===0?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[t.jsx($.Share,{sx:{fontSize:48,color:"divider",mb:2}}),t.jsx(o.Typography,{variant:"body1",sx:{fontSize:c=>c.typography.body2.fontSize||"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),t.jsx(o.Typography,{variant:"body2",sx:{fontSize:c=>c.typography.body2.fontSize||"0.8125rem",color:"text.disabled",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:e.map(c=>t.jsxs(o.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"background.paper",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:l=>ye(l,"restButtonLight")}},children:[t.jsx(o.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:t.jsxs(o.Box,{sx:{flex:1,minWidth:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:l=>l.typography.body1.fontSize||"0.9375rem",fontWeight:l=>l.typography.h6.fontWeight||500,color:"text.primary",mb:.5},children:c.name}),c.description&&t.jsx(o.Typography,{variant:"body2",sx:{fontSize:l=>l.typography.body2.fontSize||"0.8125rem",color:"text.secondary",lineHeight:1.5},children:c.description})]})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[t.jsx(o.Chip,{label:`Created ${a(c.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"action.hover",color:"text.secondary","& .MuiChip-label":{px:1}}}),t.jsx(o.Chip,{label:`By ${c.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"action.hover",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),t.jsx(o.Divider,{sx:{my:1.5,borderColor:"divider"}}),t.jsx(o.Box,{sx:{display:"flex",gap:1},children:t.jsx(o.Button,{onClick:()=>i(c.id,c.name),variant:"outlined",size:"small",startIcon:t.jsx($.Delete,{sx:{fontSize:16}}),sx:{fontSize:"0.8125rem",color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:l=>`${l.shape.borderRadius}px`,"&:hover":{borderColor:"error.main",bgcolor:l=>D(l.palette.error.main,.04)}},children:"Delete"})})]},c.id))})}),t.jsx(o.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:t.jsx(o.Button,{onClick:s,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:c=>`${c.shape.borderRadius}px`,boxShadow:c=>ye(c,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:c=>ye(c,"hoverButton")},"&:active":{boxShadow:c=>ye(c,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const ra={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},np=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],ip=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function sp(e,r){const n=[];for(const i of e){if(i.type!=="string")continue;const s=ip.some(l=>l.test(i.name));let a=!1;const c=r.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);c.length>0&&(a=c.filter(p=>np.some(x=>x.test(p))).length/c.length>.6),(s||a)&&n.push(i.name)}return n}function wn(e,r){if(e.length===0||r.length===0)return 0;const n=e.slice(0,Math.min(50,e.length)),s=r.map(c=>{const l=n.map(x=>String(x[c]??"")).filter(x=>x.length>0);if(l.length===0)return 5;const p=l.reduce((x,y)=>x+y.length,0);return Math.ceil(p/l.length)+1}).reduce((c,l)=>c+l,0)+1;return r.reduce((c,l)=>c+l.length+1,0)+s*e.length}function ap(e,r){const n=wn(e,r);return Math.ceil(n*3.5)}function lp(e,r){const n=wn(e,r);return Math.ceil(n*.7)}function cp(e,r){const n=wn(e,r);return Math.ceil(n*2)}function dp(e,r,n){switch(e){case"csv":return wn(r,n);case"excel":return lp(r,n);case"json":return ap(r,n);case"pdf":return cp(r,n)}}function gs(e,r){return Math.ceil(e/r)}function up(e,r,n,i,s=ra){const a=[],c=dp(e,r,n),l=r.length;if(l>s.maxRowsHard){const y=gs(l,s.maxRows);a.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${s.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${y} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:y,value:l,limit:s.maxRowsHard})}else if(l>s.maxRows){const y=gs(l,s.maxRows);a.push({type:"row_count",severity:"warning",message:`Large export: ${l.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${y} smaller export${y>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:y,value:l,limit:s.maxRows})}if(c>s.maxFileSizeHardBytes?a.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${ko(c)} exceeds the ${ko(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:c,limit:s.maxFileSizeHardBytes}):c>s.maxFileSizeBytes&&a.push({type:"file_size",severity:"warning",message:`Large file: estimated ${ko(c)}`,detail:`This exceeds the recommended ${ko(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:c,limit:s.maxFileSizeBytes}),e!=="excel"){const y=sp(i.filter(g=>n.includes(g.name)),r);if(y.length>0){const g=y.length>s.maxImageColumns;a.push({type:"image_columns",severity:g?"error":"warning",message:`Image column${y.length>1?"s":""} detected: ${y.map(v=>`"${v.replace(/_/g," ")}"`).join(", ")}`,detail:g?`Exporting ${y.length} image columns may produce a very large file. Consider hiding these columns before exporting.`:"Image URL columns are included in the export as plain text links — not embedded images.",value:y.length,limit:s.maxImageColumns})}}const p=a.some(y=>y.severity==="error"),x=a.some(y=>y.severity==="warning");return{violations:a,hasBlockingViolation:p,hasWarning:x,estimatedBytes:c}}function ko(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function pp({violation:e}){const n=ct().palette,i=e.severity==="error",s=i?n.error.main:n.warning.main,a=D(i?n.error.main:n.warning.main,.06),c=i?D(n.error.main,.25):D(n.warning.main,.3),l=i?$.ErrorOutline:$.WarningAmberOutlined;return t.jsxs(o.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"10px",bgcolor:a,border:"1px solid",borderColor:c},children:[t.jsx(l,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{sx:{fontSize:p=>p.typography.body2.fontSize||"0.8125rem",fontWeight:p=>p.typography.body2.fontWeight||600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:e.message}),e.detail&&t.jsx(o.Typography,{sx:{fontSize:p=>p.typography.caption.fontSize||"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:e.detail}),e.suggestedBatches&&e.suggestedBatches>1&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[t.jsx($.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),t.jsxs(o.Typography,{sx:{fontSize:p=>p.typography.caption.fontSize||"0.75rem",color:"text.secondary",fontWeight:p=>p.typography.body2.fontWeight||500},children:["Suggestion: split into ",e.suggestedBatches," exports"]})]})]})]})}function hp({format:e}){const r=ct(),n={csv:{color:r.palette.primary.main,bg:r.palette.primary.main,label:"CSV"},excel:{color:r.palette.success.main,bg:r.palette.success.main,label:"XLSX"},json:{color:r.palette.text.secondary,bg:r.palette.text.secondary,label:"JSON"},pdf:{color:r.palette.error.main,bg:r.palette.error.main,label:"PDF"}}[e];return t.jsxs(o.Box,{sx:{width:44,height:52,position:"relative",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",mb:1},children:[t.jsxs("svg",{width:"38",height:"46",viewBox:"0 0 38 46",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.jsx("path",{d:"M5 2C3.34315 2 2 3.34315 2 5V41C2 42.6569 3.34315 44 5 44H33C34.6569 44 36 42.6569 36 41V13L25 2H5Z",fill:r.palette.background.paper,stroke:n.color,strokeWidth:"2.5",strokeLinejoin:"round"}),t.jsx("path",{d:"M24 2V13H36",fill:D(r.palette.text.primary,.05),stroke:n.color,strokeWidth:"2.5",strokeLinejoin:"round"})]}),t.jsx(o.Box,{sx:{position:"absolute",bottom:8,left:3,right:3,bgcolor:n.bg,color:r.palette.primary.contrastText,fontSize:"0.625rem",fontWeight:800,py:.25,borderRadius:"3px",textAlign:"center",letterSpacing:"0.05em"},children:n.label})]})}function ys({checked:e}){const r=ct();return t.jsx(o.Box,{sx:{width:20,height:20,borderRadius:"50%",border:e?`2px solid var(--urm-export-card-selected-border, ${r.palette.primary.main})`:`2px solid var(--urm-export-radio-border, ${r.palette.divider})`,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:r.palette.background.paper,transition:"all 0.15s ease",flexShrink:0},children:e&&t.jsx(o.Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:`var(--urm-export-card-selected-border, ${r.palette.primary.main})`}})})}function fp({totalRows:e,visibleRows:r,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:a,sampleRows:c=[],allRows:l=[],processedRows:p=[],initialFormat:x,initialScope:y="visible",initialColumnScope:g="visible",classTokens:v={},onExport:S,onClose:k}){const b=ct(),m=b.palette,z=Dr(),h=f.useMemo(()=>{var ce,de,ie,Q,pe;const U=((ie=(de=(ce=b.components)==null?void 0:ce.MuiCard)==null?void 0:de.styleOverrides)==null?void 0:ie.root)||{},re=U.border&&U.border!=="none"?U.border:(Q=b.tokens)!=null&&Q.cardBodyBorder&&b.tokens.cardBodyBorder!=="none"?b.tokens.cardBodyBorder:m.divider,ge=U.borderRadius!==void 0?typeof U.borderRadius=="number"?`${U.borderRadius}px`:U.borderRadius:`${b.shape.borderRadius}px`,V=U.boxShadow&&U.boxShadow!=="none"?U.boxShadow:((pe=b.tokens)==null?void 0:pe.cardBodyShadow)||ye(b,"menu"),X=it(b);return{sectionBorder:`var(--urm-export-section-border, ${re})`,sectionTitleColor:`var(--urm-export-section-title-color, ${m.text.primary})`,sectionTitleBg:`var(--urm-export-section-title-bg, ${m.background.paper})`,cardBg:`var(--urm-export-card-bg, ${m.background.paper})`,cardBorder:`var(--urm-export-card-border, ${re})`,cardRadius:ge,cardShadow:V,cardHoverBg:`var(--urm-export-card-hover-bg, ${m.mode==="dark"?D(m.common.white,.08):D(m.common.black,.04)})`,cardSelectedBg:`var(--urm-export-card-selected-bg, ${D(X.main,m.mode==="dark"?.16:.08)})`,cardSelectedBorder:`var(--urm-export-card-selected-border, ${X.main})`,cardSelectedColor:`var(--urm-export-card-selected-color, ${m.mode==="dark"?m.primary.light:m.primary.main})`,primaryBtnBg:`var(--urm-export-primary-btn-bg, ${m.primary.main})`,primaryBtnHoverBg:`var(--urm-export-primary-btn-hover-bg, ${m.primary.dark})`,primaryBtnColor:`var(--urm-export-primary-btn-color, ${m.primary.contrastText})`,sectionPadding:`var(--urm-export-section-padding, ${b.spacing(2)})`,optionGap:`var(--urm-export-option-gap, ${b.spacing(1.5)})`}},[m,b]),B=x||z.export.allowedFormats[0]||"csv",[T,w]=f.useState(B),[P,O]=f.useState(y),[M,Y]=f.useState(g),J=P==="visible"?r:e,R=M==="visible"?i:s,u=f.useMemo(()=>P==="visible"?p.length>0?p:new Array(r):l.length>0?l:new Array(e),[P,r,e,p,l]),A=f.useMemo(()=>M==="all"?a.map(U=>U.name):a.map(U=>U.name).slice(0,i),[M,a,i]),F=f.useMemo(()=>up(T,u,A,a,ra),[T,u,A,a]),d=()=>{F.hasBlockingViolation||(S({format:T,scope:P,columnScope:M}),k())},ne={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON",pdf:"PDF"};return t.jsx(o.Box,{onClick:k,className:`urm-export-backdrop ${v.modalBackdrop||""}`,sx:{position:"fixed",inset:0,bgcolor:D(m.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:b.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:U=>U.stopPropagation(),elevation:0,className:`urm-export-paper ${v.modalPaper||""}`,sx:{width:540,maxWidth:"calc(100vw - 32px)",maxHeight:"min(760px, calc(100vh - 48px))",display:"flex",flexDirection:"column",borderRadius:tt(b),bgcolor:h.sectionTitleBg,overflow:"hidden",border:`1px solid ${h.cardBorder}`,boxShadow:h.cardShadow,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[t.jsxs(o.Box,{className:`urm-export-header ${v.modalHeader||""}`,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,pt:2.5,pb:1.5,flexShrink:0,bgcolor:U=>ue(U).header.backgroundColor,borderBottom:U=>ue(U).header.borderBottom,boxShadow:U=>ue(U).header.boxShadow},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Typography,{className:`urm-export-title ${v.modalTitle||""}`,sx:{fontSize:"1.125rem",fontWeight:700,color:m.text.primary},children:"Export Report"}),t.jsx($r,{content:_r.export,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:k,size:"small",className:`urm-export-close ${v.modalCloseButton||""}`,sx:{color:m.text.secondary,borderRadius:"50%","&:hover":{bgcolor:m.action.hover,color:m.text.primary}},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Box,{className:`urm-export-content ${v.modalContent||""}`,sx:{flex:1,overflowY:"auto",px:3,pb:2.5,pt:.5,display:"flex",flexDirection:"column",gap:h.optionGap,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D(m.text.primary,.15),borderRadius:3}},children:[F.violations.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:F.violations.map((U,re)=>t.jsx(pp,{violation:U},re))}),t.jsxs(o.Box,{className:`urm-export-section ${v.sectionContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Choose File Format"}),t.jsx(o.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:h.optionGap},children:[{id:"csv",title:"CSV",info:"Comma-separated values, compatible with Excel",allowed:z.export.allowedFormats.includes("csv")},{id:"excel",title:"Excel (.xlsx)",info:"Native Excel format with formatting support",allowed:z.export.allowedFormats.includes("excel")},{id:"json",title:"JSON",info:"Structured data with metadata and filters",allowed:z.export.allowedFormats.includes("json")},{id:"pdf",title:"PDF",info:"Print-ready PDF document",allowed:z.export.allowedFormats.includes("pdf")}].filter(U=>U.allowed).map(U=>{const re=T===U.id;return t.jsxs(o.Box,{onClick:()=>w(U.id),className:`urm-export-format-card ${re?v.formatCardSelected||"":v.formatCard||""}`,sx:{position:"relative",display:"flex",flexDirection:"column",alignItems:"center",textAlign:"center",p:1.75,borderRadius:h.cardRadius,border:re?`2px solid ${h.cardSelectedBorder}`:`1px solid ${h.cardBorder}`,boxShadow:re?void 0:h.cardShadow,bgcolor:re?h.cardSelectedBg:h.cardBg,cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:re?h.cardSelectedBorder:D(m.text.primary,.25),bgcolor:re?h.cardSelectedBg:h.cardHoverBg}},children:[re&&t.jsx(o.Box,{sx:{position:"absolute",top:8,right:8,width:20,height:20,borderRadius:"50%",bgcolor:h.cardSelectedBorder,color:m.primary.contrastText,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:`0 2px 4px ${D(m.primary.main,.3)}`},children:t.jsx($.Check,{sx:{fontSize:13,strokeWidth:2}})}),t.jsx(hp,{format:U.id}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.Typography,{sx:{fontSize:"0.875rem",fontWeight:700,color:re?h.cardSelectedColor:m.text.primary},children:U.title}),t.jsx(o.Tooltip,{title:U.info,arrow:!0,placement:"top",children:t.jsx(o.Box,{component:"span",onClick:ge=>ge.stopPropagation(),sx:{display:"inline-flex",cursor:"help",color:m.text.secondary,"&:hover":{color:m.text.primary}},children:t.jsx($.InfoOutlined,{sx:{fontSize:13}})})})]})]},U.id)})})]}),t.jsxs(o.Box,{className:`urm-export-section ${v.sectionContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Select Rows Range"}),t.jsx(o.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:h.optionGap},children:[{value:"visible",label:"Visible rows",icon:t.jsx($.VisibilityOutlined,{sx:{fontSize:20}}),info:`Export ${r.toLocaleString()} rows (filtered and searched)`},{value:"all",label:"All rows",icon:t.jsx($.TableChartOutlined,{sx:{fontSize:20}}),info:`Export ${e.toLocaleString()} rows (complete original dataset)`}].map(U=>{const re=P===U.value;return t.jsxs(o.Box,{onClick:()=>O(U.value),className:`urm-export-row-card ${re?v.rowCardSelected||"":v.rowCard||""}`,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:1.5,borderRadius:h.cardRadius,border:re?`2px solid ${h.cardSelectedBorder}`:`1px solid ${h.cardBorder}`,boxShadow:re?void 0:h.cardShadow,bgcolor:re?h.cardSelectedBg:h.cardBg,cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:re?h.cardSelectedBorder:D(m.text.primary,.25),bgcolor:re?h.cardSelectedBg:h.cardHoverBg}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx(ys,{checked:re}),t.jsx(o.Box,{sx:{color:re?h.cardSelectedColor:m.text.secondary,display:"flex"},children:U.icon}),t.jsx(o.Typography,{sx:{fontSize:"0.875rem",fontWeight:600,color:re?h.cardSelectedColor:m.text.primary},children:U.label})]}),t.jsx(o.Tooltip,{title:U.info,arrow:!0,placement:"top",children:t.jsx(o.Box,{component:"span",onClick:ge=>ge.stopPropagation(),sx:{display:"inline-flex",cursor:"help",color:m.text.secondary,"&:hover":{color:m.text.primary}},children:t.jsx($.InfoOutlined,{sx:{fontSize:16}})})})]},U.value)})})]}),t.jsxs(o.Box,{className:`urm-export-section ${v.sectionContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Select Columns Range"}),t.jsx(o.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:h.optionGap},children:[{value:"visible",label:"Visible columns",icon:t.jsx($.SwapVertOutlined,{sx:{fontSize:20}}),info:`Export ${i} visible column${i!==1?"s":""}`},{value:"all",label:"All columns",icon:t.jsx($.TableChartOutlined,{sx:{fontSize:20}}),info:`Export all ${s} columns (including hidden)`}].map(U=>{const re=M===U.value;return t.jsxs(o.Box,{onClick:()=>Y(U.value),className:`urm-export-column-card ${re?v.columnCardSelected||"":v.columnCard||""}`,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:1.5,borderRadius:h.cardRadius,border:re?`2px solid ${h.cardSelectedBorder}`:`1px solid ${h.cardBorder}`,boxShadow:re?void 0:h.cardShadow,bgcolor:re?h.cardSelectedBg:h.cardBg,cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:re?h.cardSelectedBorder:D(m.text.primary,.25),bgcolor:re?h.cardSelectedBg:h.cardHoverBg}},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx(ys,{checked:re}),t.jsx(o.Box,{sx:{color:re?h.cardSelectedColor:m.text.secondary,display:"flex"},children:U.icon}),t.jsx(o.Typography,{sx:{fontSize:"0.875rem",fontWeight:600,color:re?h.cardSelectedColor:m.text.primary},children:U.label})]}),t.jsx(o.Tooltip,{title:U.info,arrow:!0,placement:"top",children:t.jsx(o.Box,{component:"span",onClick:ge=>ge.stopPropagation(),sx:{display:"inline-flex",cursor:"help",color:m.text.secondary,"&:hover":{color:m.text.primary}},children:t.jsx($.InfoOutlined,{sx:{fontSize:16}})})})]},U.value)})})]}),t.jsxs(o.Box,{className:`urm-export-summary ${v.summaryContainer||""}`,sx:{position:"relative",border:`1.5px solid ${h.sectionBorder}`,borderRadius:"12px",p:h.sectionPadding,pt:2.25,bgcolor:h.sectionTitleBg,mt:1.5},children:[t.jsx(o.Typography,{className:`urm-export-section-title ${v.sectionTitle||""}`,sx:{position:"absolute",top:-11,left:14,bgcolor:h.sectionTitleBg,px:.75,fontSize:"0.8125rem",fontWeight:600,color:h.sectionTitleColor,lineHeight:1,zIndex:1},children:"Export Summary"}),t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[{icon:t.jsx($.InsertDriveFileOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Format",value:ne[T]},{icon:t.jsx($.FormatListNumberedOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Rows to Export",value:J.toLocaleString()},{icon:t.jsx($.SwapVertOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Columns to Export",value:String(R)},{icon:t.jsx($.InsertDriveFileOutlined,{sx:{fontSize:18,color:m.text.secondary}}),label:"Estimated File Size",value:`~${ko(F.estimatedBytes)}`,highlight:F.hasBlockingViolation?"error.main":F.hasWarning?"warning.main":void 0}].map(({icon:U,label:re,value:ge,highlight:V})=>t.jsxs(o.Box,{className:`urm-export-summary-row ${v.summaryRow||""}`,sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[U,t.jsx(o.Typography,{className:`urm-export-summary-label ${v.summaryLabel||""}`,sx:{fontSize:"0.8125rem",color:m.text.secondary,fontWeight:500},children:re})]}),t.jsx(o.Typography,{className:`urm-export-summary-value ${v.summaryValue||""}`,sx:{fontWeight:700,fontSize:"0.8125rem",color:V??m.text.primary},children:ge})]},re))})]})]}),t.jsxs(o.Box,{className:`urm-export-footer ${v.footer||""}`,sx:{px:3,py:2,display:"flex",alignItems:"center",justifyContent:"flex-end",gap:1.5,flexShrink:0},children:[F.hasBlockingViolation&&t.jsxs(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[t.jsx($.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),t.jsx(o.Typography,{sx:{fontSize:U=>U.typography.caption.fontSize||"0.75rem",color:"error.main",fontWeight:U=>U.typography.body2.fontWeight||500},children:"Reduce rows or columns to enable download"})]}),t.jsx(o.Button,{onClick:k,variant:"outlined",className:`urm-export-cancel-btn ${v.cancelButton||""}`,sx:{fontSize:"0.875rem",fontWeight:600,color:m.text.primary,borderColor:h.cardBorder,px:3,py:1,borderRadius:"8px",textTransform:"none","&:hover":{bgcolor:h.cardHoverBg,borderColor:D(m.text.primary,.3)}},children:"Cancel"}),t.jsxs(o.Button,{onClick:d,disabled:F.hasBlockingViolation,variant:"contained",className:`urm-export-download-btn ${v.downloadButton||""}`,startIcon:t.jsx($.Download,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",fontWeight:600,bgcolor:h.primaryBtnBg,color:h.primaryBtnColor,px:3,py:1,borderRadius:"8px",textTransform:"none",boxShadow:`0 2px 6px ${D(m.primary.main,.25)}`,"&:hover":{bgcolor:h.primaryBtnHoverBg},"&.Mui-disabled":{bgcolor:D(m.primary.main,.4),color:h.primaryBtnColor}},children:["Download ",ne[T]]})]})]})})}function mp({warning:e,onDismiss:r}){return t.jsx(o.Box,{sx:{position:"fixed",bottom:16,right:16,zIndex:50,maxWidth:448},children:t.jsxs(o.Alert,{severity:"warning",icon:t.jsx($.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"warning.main"},children:t.jsx($.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[t.jsx(o.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),t.jsx(o.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:e.message}),t.jsxs(o.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",e.type==="filter"?"filters":e.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function xp({error:e,onDismiss:r,autoDismiss:n=!0,autoDismissDelay:i=3e4}){f.useEffect(()=>{if(n){const l=setTimeout(()=>{r()},i);return()=>clearTimeout(l)}},[n,i,r]);const a=(()=>{switch(e.type){case"system":return{severity:"error",icon:t.jsx($.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:t.jsx($.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:t.jsx($.InfoOutlined,{sx:{fontSize:20}})}}})(),c=Sl(e);return t.jsx(o.Box,{sx:{position:"fixed",bottom:16,right:16,zIndex:50,maxWidth:448},children:t.jsxs(o.Alert,{severity:a.severity,icon:a.icon,action:t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:`${a.severity}.main`},children:t.jsx($.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${a.severity}.main`,boxShadow:3},children:[t.jsxs(o.AlertTitle,{sx:{fontWeight:l=>l.typography.h6.fontWeight||600,fontSize:l=>l.typography.subtitle2.fontSize||"0.875rem"},children:[e.context.charAt(0).toUpperCase()+e.context.slice(1)," Error"]}),t.jsx(o.Box,{sx:{fontSize:"body2.fontSize"},children:c}),e.details&&process.env.NODE_ENV==="development"&&t.jsx(o.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(e.details,null,2)})]})})}class gp extends f.Component{constructor(n){super(n);Ci(this,"handleReset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,i){Lt.error("urm:error-boundary","Caught unhandled component error",n,i),this.props.onError&&this.props.onError(n,i)}render(){var n,i;return this.state.hasError?this.props.fallback?this.props.fallback:t.jsx(o.Paper,{sx:{bgcolor:s=>D(s.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx($.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:s=>s.typography.h6.fontWeight||600,fontSize:s=>s.typography.h6.fontSize||"1.25rem"},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),t.jsx(o.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((n=this.state.error)==null?void 0:n.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&t.jsx(o.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:s=>D(s.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:170},children:(i=this.state.error)==null?void 0:i.stack}),t.jsx(o.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:t.jsx($.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function yp({feature:e}){const[r,n]=f.useState(!0);return f.useEffect(()=>{const i=setTimeout(()=>n(!1),5e3);return()=>clearTimeout(i)},[]),t.jsx(o.Collapse,{in:r,unmountOnExit:!0,children:t.jsxs(o.Alert,{severity:"warning",sx:{m:1},icon:t.jsx($.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:t.jsx($.Close,{sx:{fontSize:16}})}),children:[t.jsxs(o.AlertTitle,{children:[e," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Yo({children:e,feature:r,onError:n}){return t.jsx(gp,{context:r,onError:i=>{n&&n(i)},fallback:t.jsx(yp,{feature:r}),children:e})}const bp=[{value:"equals",label:"Equals",group:"Text"},{value:"contains",label:"Contains",group:"Text"},{value:"startsWith",label:"Starts with",group:"Text"},{value:"endsWith",label:"Ends with",group:"Text"},{value:"gt",label:"Greater than (>)",group:"Numeric"},{value:"lt",label:"Less than (<)",group:"Numeric"},{value:"gte",label:"At least (≥)",group:"Numeric"},{value:"lte",label:"At most (≤)",group:"Numeric"},{value:"isTrue",label:"Is true",group:"Boolean"},{value:"isFalse",label:"Is false",group:"Boolean"},{value:"NULL",label:"Is empty (NULL)",group:"Null checks"},{value:"NOT_NULL",label:"Is not empty",group:"Null checks"}],vp=[{value:"csv",label:"CSV",desc:"Comma-separated values"},{value:"excel",label:"Excel (.xlsx)",desc:"Native Excel format"},{value:"json",label:"JSON",desc:"Structured data with metadata"},{value:"pdf",label:"PDF",desc:"Print-ready PDF document"}];function So({children:e,active:r}){return t.jsx(o.Box,{hidden:!r,sx:{pt:2.5,pb:1,display:r?"flex":"none",flexDirection:"column",gap:2.5},children:e})}function Sp({open:e,onClose:r,config:n,onApply:i}){const[s,a]=f.useState(0),[c,l]=f.useState(n),p=()=>l(n),x=()=>l(ht),y=()=>{i(c),r()},g={sort:m=>l(z=>({...z,sort:{...z.sort,...m}})),filter:m=>l(z=>({...z,filter:{...z.filter,...m}})),columns:m=>l(z=>({...z,columns:{...z.columns,...m}})),grouping:m=>l(z=>({...z,grouping:{...z.grouping,...m}})),export:m=>l(z=>({...z,export:{...z.export,...m}}))},v=m=>{const z=c.filter.allowedOperators,h=z.includes(m)?z.filter(B=>B!==m):[...z,m];h.length!==0&&g.filter({allowedOperators:h})},S=m=>{const z=c.export.allowedFormats,h=z.includes(m)?z.filter(B=>B!==m):[...z,m];h.length!==0&&g.export({allowedFormats:h})},k=[{label:"Sort",icon:t.jsx($.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:t.jsx($.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:t.jsx($.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:t.jsx($.Layers,{sx:{fontSize:17}})},{label:"Export",icon:t.jsx($.Download,{sx:{fontSize:17}})}],b=m=>JSON.stringify(c[m])===JSON.stringify(ht[m]);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:p},PaperProps:{sx:{borderRadius:m=>tt(m),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:m=>`0 8px 32px ${D(m.palette.common.black,.2)}`}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[t.jsx(o.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:m=>D(m.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem"},children:"⚙️"}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"subtitle1",sx:{fontWeight:600,lineHeight:1.2},children:"Developer Configuration"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"Set runtime constraints · Ctrl+Shift+D"})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"text.secondary"},children:t.jsx($.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:t.jsx(o.Tabs,{value:s,onChange:(m,z)=>a(z),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:k.map((m,z)=>t.jsx(o.Tab,{label:m.label,icon:m.icon,iconPosition:"start"},z))})}),t.jsxs(o.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[t.jsxs(So,{active:s===0,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!b("sort")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),t.jsx(o.Slider,{value:c.sort.maxLevels,onChange:(m,z)=>g.sort({maxLevels:z}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),t.jsxs(o.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",t.jsx("strong",{children:"5"}),"."]})]}),t.jsxs(So,{active:s===1,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!b("filter")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),t.jsx(o.Slider,{value:c.filter.maxConditions,onChange:(m,z)=>g.filter({maxConditions:z}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),t.jsx(o.Divider,{}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(m=>t.jsxs(o.Box,{sx:{mb:1.5},children:[t.jsx(o.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:m}),t.jsx(o.FormGroup,{row:!0,sx:{gap:.5},children:bp.filter(z=>z.group===m).map(z=>t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{size:"small",checked:c.filter.allowedOperators.includes(z.value),onChange:()=>v(z.value)}),label:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:z.label}),sx:{mr:1.5}},z.value))})]},m))]})]}),t.jsxs(So,{active:s===2,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!b("columns")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),t.jsx(o.Slider,{value:c.columns.maxVisible,onChange:(m,z)=>g.columns({maxVisible:z}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),t.jsx(o.Divider,{}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),t.jsxs(o.Box,{sx:{display:"flex",gap:2},children:[t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),t.jsx(o.Slider,{value:c.columns.minColumnWidth,onChange:(m,z)=>g.columns({minColumnWidth:z}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:m=>`${m}px`})]}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),t.jsx(o.Slider,{value:c.columns.maxColumnWidth,onChange:(m,z)=>g.columns({maxColumnWidth:z}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:m=>`${m}px`})]})]})]})]}),t.jsxs(So,{active:s===3,children:[t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!b("grouping")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(m=>t.jsxs(o.Box,{onClick:()=>g.grouping({maxLevels:m}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:c.grouping.maxLevels===m?"primary.main":"divider",bgcolor:c.grouping.maxLevels===m?z=>D(z.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:z=>D(z.palette.primary.main,.04)}},children:[t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:700,color:c.grouping.maxLevels===m?"primary.main":"text.secondary"},children:m}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][m-1]})]},m))}),t.jsxs(o.FormGroup,{row:!0,sx:{gap:2},children:[t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:c.grouping.allowNested,onChange:m=>g.grouping({allowNested:m.target.checked})}),label:t.jsx(o.Typography,{variant:"body2",children:"Allow nested groups"})}),t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:c.grouping.allowCollapse,onChange:m=>g.grouping({allowCollapse:m.target.checked})}),label:t.jsx(o.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),t.jsx(o.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),t.jsx(So,{active:s===4,children:t.jsxs(o.Box,{children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!b("export")&&t.jsx(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),t.jsx(o.FormGroup,{sx:{gap:1},children:vp.map(m=>t.jsxs(o.Box,{onClick:()=>S(m.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:c.export.allowedFormats.includes(m.value)?"primary.main":"divider",bgcolor:c.export.allowedFormats.includes(m.value)?z=>D(z.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[t.jsx(o.Checkbox,{size:"small",checked:c.export.allowedFormats.includes(m.value),onChange:()=>S(m.value),onClick:z=>z.stopPropagation()}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500},children:m.label}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:m.desc})]})]},m.value))})]})})]}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:m=>D(m.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[t.jsx(o.Button,{startIcon:t.jsx($.RestartAlt,{sx:{fontSize:18}}),onClick:x,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:m=>D(m.palette.text.primary,.06)}},children:"Reset to defaults"}),t.jsxs(o.Box,{sx:{display:"flex",gap:1},children:[t.jsx(o.Button,{onClick:r,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),t.jsx(o.Button,{onClick:y,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Cp=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],jp={1:"1st",2:"2nd",3:"3rd",4:"4th",5:"5th",6:"6th",7:"7th",8:"8th",9:"9th",10:"10th",11:"11th",12:"12th",13:"13th",14:"14th",15:"15th",16:"16th",17:"17th",18:"18th",19:"19th",20:"20th",21:"21st",22:"22nd",23:"23rd",24:"24th",25:"25th",26:"26th",27:"27th",28:"28th"};function Xo(e,r,n,i,s=new Date){const[a,c]=r.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(a,c,0,0),e==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(e==="weekly"){const p=n??1,x=l.getDay();let y=p-x;return y<0&&(y+=7),y===0&&l<=s&&(y=7),l.setDate(l.getDate()+y),l.toISOString()}if(e==="monthly"){const p=Math.min(i??1,28);return l.setDate(p),l<=s&&(l.setMonth(l.getMonth()+1),l.setDate(p)),l.toISOString()}return l.toISOString()}function wp(e){const r=oa(e.time);return e.frequency==="daily"?`Daily at ${r}`:e.frequency==="weekly"?`Every ${Cp[e.dayOfWeek??1]} at ${r}`:e.frequency==="monthly"?`Monthly on the ${jp[e.dayOfMonth??1]??`${e.dayOfMonth}th`} at ${r}`:r}function oa(e){const[r,n]=e.split(":").map(Number),i=r>=12?"PM":"AM";return`${r%12||12}:${String(n).padStart(2,"0")} ${i}`}function kp(e){const r=new Date(e).getTime()-Date.now();if(r<=0)return"now";const n=Math.floor(r/1e3),i=Math.floor(n/86400),s=Math.floor(n%86400/3600),a=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${a}m`:a>0?`in ${a}m`:"in less than a minute"}function zp(e){const r=new Date(e),n=new Date,i=r.toDateString()===n.toDateString(),s=oa(`${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`);return i?`Today at ${s}`:`${r.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${s}`}function na(e){return`urm_schedules_${e}`}function ia(e){try{const r=localStorage.getItem(na(e));return r?JSON.parse(r).map(i=>({...i,runCount:typeof i.runCount=="number"?i.runCount:0,isActive:typeof i.isActive=="boolean"?i.isActive:!0,createdAt:i.createdAt||new Date().toISOString()})):[]}catch{return[]}}function sa(e,r){try{localStorage.setItem(na(e),JSON.stringify(r))}catch{}}const Tp=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"}],Bp=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,aa={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"pdf",scope:"all",email:""},Ir={"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:"8px"},"& .MuiInputLabel-root":{fontSize:"0.875rem"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:.5},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}};function Ip({initial:e=aa,isEditing:r=!1,onSave:n,onBack:i}){const[s,a]=f.useState(e),[c,l]=f.useState(!1),[p,x]=f.useState(!1),y=(S,k)=>a(b=>({...b,[S]:k})),g=s.email.trim().length>0&&!Bp.test(s.email.trim()),v=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.dayOfMonth<=28)&&!g;return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[t.jsx(o.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:S=>D(S.palette.text.primary,.06)}},children:t.jsx($.ArrowBack,{sx:{fontSize:18}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:S=>S.typography.body2.fontWeight||600,fontSize:S=>S.typography.body2.fontSize||"0.875rem"},children:r?"Edit schedule":"New schedule"})]}),t.jsx(o.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:S=>{y("name",S.target.value),c&&S.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:c&&!s.name.trim(),helperText:c&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:Ir}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:Ir,children:[t.jsx(o.InputLabel,{children:"Frequency"}),t.jsxs(o.Select,{value:s.frequency,label:"Frequency",onChange:S=>y("frequency",S.target.value),children:[t.jsx(o.MenuItem,{value:"daily",children:"Daily"}),t.jsx(o.MenuItem,{value:"weekly",children:"Weekly"}),t.jsx(o.MenuItem,{value:"monthly",children:"Monthly"})]})]}),s.frequency==="weekly"&&t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:Ir,children:[t.jsx(o.InputLabel,{children:"Day of week"}),t.jsx(o.Select,{value:s.dayOfWeek,label:"Day of week",onChange:S=>y("dayOfWeek",Number(S.target.value)),children:Tp.map(S=>t.jsx(o.MenuItem,{value:S.value,children:S.label},S.value))})]}),s.frequency==="monthly"&&t.jsx(o.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:S=>y("dayOfMonth",Number(S.target.value)),inputProps:{min:1,max:28},error:s.dayOfMonth<1||s.dayOfMonth>28,helperText:s.dayOfMonth<1||s.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Ir}),t.jsx(o.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:S=>y("time",S.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Ir}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:Ir,children:[t.jsx(o.InputLabel,{children:"Export format"}),t.jsxs(o.Select,{value:s.format,label:"Export format",onChange:S=>y("format",S.target.value),children:[t.jsx(o.MenuItem,{value:"pdf",children:"PDF — Print-ready document"}),t.jsx(o.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),t.jsx(o.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),t.jsx(o.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),t.jsxs(o.RadioGroup,{row:!0,value:s.scope,onChange:S=>y("scope",S.target.value),sx:{gap:2},children:[t.jsx(o.FormControlLabel,{value:"all",control:t.jsx(o.Radio,{size:"small"}),label:t.jsx(o.Typography,{variant:"body2",children:"All rows"})}),t.jsx(o.FormControlLabel,{value:"visible",control:t.jsx(o.Radio,{size:"small"}),label:t.jsx(o.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:s.email,onChange:S=>y("email",S.target.value),onBlur:()=>x(!0),placeholder:"user@company.com",error:p&&g,helperText:p&&g?"Enter a valid email address":void 0,InputProps:{startAdornment:t.jsx($.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Ir}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[t.jsx($.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),t.jsx(o.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[t.jsx(o.Button,{onClick:i,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:S=>D(S.palette.text.primary,.06)}},children:"Cancel"}),t.jsx(o.Button,{onClick:()=>v&&n(s),disabled:!v,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:r?"Save changes":"Create schedule"})]})]})}function Ep({scheduleName:e,onConfirm:r,onCancel:n}){return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:i=>({borderRadius:$o(i),...ue(i).paper})},children:[t.jsxs(o.DialogContent,{sx:{pt:3,pb:2,px:3},children:[t.jsx(o.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:i=>D(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx($.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),t.jsx(o.Typography,{sx:{fontSize:i=>i.typography.body1.fontSize||"0.9375rem",fontWeight:i=>i.typography.h6.fontWeight||600,color:"text.primary",mb:1},children:"Delete Schedule"}),t.jsxs(o.Typography,{sx:{fontSize:i=>i.typography.body2.fontSize||"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",t.jsxs(o.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',e,'"']}),"? This action cannot be undone."]})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[t.jsx(o.Button,{onClick:n,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:i=>`${i.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),t.jsx(o.Button,{onClick:r,variant:"contained",color:"error",sx:{fontSize:"0.8125rem",borderRadius:i=>`${i.shape.borderRadius}px`,px:2},children:"Delete"})]})]})}function Dp({schedule:e,tick:r,onToggle:n,onRunNow:i,onEdit:s,onDelete:a}){const c=e.isActive;return t.jsxs(o.Box,{sx:{border:"1px solid",borderColor:c?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:c?l=>D(l.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:c?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),t.jsx(o.Chip,{label:c?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:c?l=>D(l.palette.success.main,.1):l=>D(l.palette.text.primary,.06),color:c?"success.dark":"text.secondary"}})]}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:wp(e)}),t.jsxs(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5,mb:1},children:[t.jsx(o.Chip,{label:e.format.toUpperCase(),size:"small",sx:{height:20,fontSize:"0.6875rem",fontWeight:500,bgcolor:l=>D(l.palette.primary.main,.08),color:"primary.main"}}),t.jsx(o.Chip,{label:e.scope==="all"?"All rows":"Filtered rows",size:"small",sx:{height:20,fontSize:"0.6875rem",bgcolor:l=>D(l.palette.text.primary,.06),color:"text.secondary"}}),e.email&&t.jsx(o.Chip,{icon:t.jsx($.Email,{sx:{fontSize:11}}),label:e.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>D(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[t.jsxs(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[c&&t.jsxs(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",kp(e.nextRunAt)]}),e.lastRunAt?t.jsxs(o.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",zp(e.lastRunAt)," · ",e.runCount," run",e.runCount!==1?"s":""]}):t.jsx(o.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[t.jsx(o.Tooltip,{title:"Edit",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>s(e),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>D(l.palette.primary.main,.08)}},children:t.jsx($.Edit,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:c?"Pause":"Resume",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>n(e.id),sx:{color:c?"warning.main":"success.main","&:hover":{bgcolor:c?l=>D(l.palette.warning.main,.08):l=>D(l.palette.success.main,.08)}},children:c?t.jsx($.Pause,{sx:{fontSize:15}}):t.jsx($.PlayArrow,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:"Export now",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>i(e),sx:{color:"primary.main","&:hover":{bgcolor:l=>D(l.palette.primary.main,.08)}},children:t.jsx($.Download,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:"Delete",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>a(e.id),sx:{color:"error.main","&:hover":{bgcolor:l=>D(l.palette.error.main,.08)}},children:t.jsx($.Delete,{sx:{fontSize:15}})})})]})]})]})}function $p({open:e,onClose:r,reportId:n,reportName:i,onRunNow:s,schedulerConfig:a}){const l=((a==null?void 0:a.mode)??"local")==="api",[p,x]=f.useState([]),y=l?(a==null?void 0:a.schedules)??[]:p,[g,v]=f.useState({type:"list"}),[S,k]=f.useState(0),[b,m]=f.useState(null);f.useEffect(()=>{e&&(l||x(ia(n)),v({type:"list"}))},[e,n,l]),f.useEffect(()=>{if(!e)return;const R=setInterval(()=>k(u=>u+1),3e4);return()=>clearInterval(R)},[e]);const z=f.useCallback(R=>{x(R),sa(n,R)},[n]),h=R=>{var F;const u=Xo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth),A={id:`sched-${Date.now()}`,reportId:n,name:R.name.trim(),frequency:R.frequency,dayOfWeek:R.frequency==="weekly"?R.dayOfWeek:void 0,dayOfMonth:R.frequency==="monthly"?R.dayOfMonth:void 0,time:R.time,format:R.format,scope:R.scope,email:R.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:u,runCount:0};l?(F=a==null?void 0:a.onScheduleCreate)==null||F.call(a,A):z([...y,A]),v({type:"list"})},B=R=>{var d;if(g.type!=="edit")return;const u=g.schedule,A=Xo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth),F={...u,name:R.name.trim(),frequency:R.frequency,dayOfWeek:R.frequency==="weekly"?R.dayOfWeek:void 0,dayOfMonth:R.frequency==="monthly"?R.dayOfMonth:void 0,time:R.time,format:R.format,scope:R.scope,email:R.email.trim()||void 0,nextRunAt:A};l?(d=a==null?void 0:a.onScheduleUpdate)==null||d.call(a,F):z(y.map(ne=>ne.id===u.id?F:ne)),v({type:"list"})},T=R=>{var ne;const u=y.find(U=>U.id===R);if(!u)return;const A=!u.isActive,F=A?Xo(u.frequency,u.time,u.dayOfWeek,u.dayOfMonth):u.nextRunAt,d={...u,isActive:A,nextRunAt:F};l?(ne=a==null?void 0:a.onScheduleToggle)==null||ne.call(a,R,A):z(y.map(U=>U.id===R?d:U))},w=R=>{if(s(R),!l){const u=new Date().toISOString();z(y.map(A=>A.id===R.id?{...A,lastRunAt:u,runCount:A.runCount+1}:A))}},P=R=>{const u=y.find(A=>A.id===R)??null;m(u)},O=()=>{var R;b&&(l?(R=a==null?void 0:a.onScheduleDelete)==null||R.call(a,b.id):z(y.filter(u=>u.id!==b.id)),m(null))},M=R=>({name:R.name,frequency:R.frequency,dayOfWeek:R.dayOfWeek??1,dayOfMonth:R.dayOfMonth??1,time:R.time,format:R.format,scope:R.scope,email:R.email??""}),Y=g.type!=="list",J=y.filter(R=>R.isActive).length;return t.jsxs(t.Fragment,{children:[t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:Y,PaperProps:{sx:R=>({borderRadius:tt(R),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",...ue(R).paper})},children:[t.jsxs(o.DialogTitle,{sx:R=>({display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,flexShrink:0,minHeight:0,...ue(R).header}),children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[t.jsx(o.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:R=>D(R.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx($.Schedule,{sx:{fontSize:17,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"baseline",gap:.75},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:R=>R.typography.h6.fontWeight||600,fontSize:R=>R.typography.subtitle2.fontSize||"0.875rem",lineHeight:1},children:"Scheduled Reports"}),t.jsx($r,{content:_r.schedule,isDev:process.env.NODE_ENV==="development"})]}),t.jsxs(o.Typography,{variant:"caption",color:"text.secondary",sx:{lineHeight:1},children:["· ",i]})]})]}),t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"text.secondary","&:hover":{bgcolor:R=>D(R.palette.text.primary,.06)}},children:t.jsx($.Close,{sx:{fontSize:18}})})]}),t.jsxs(o.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[Y&&t.jsx(Ip,{initial:g.type==="edit"?M(g.schedule):aa,isEditing:g.type==="edit",onSave:g.type==="edit"?B:h,onBack:()=>v({type:"list"})}),g.type==="list"&&t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:y.length===0?"No schedules yet":`${J} of ${y.length} active`}),t.jsx(o.Button,{startIcon:t.jsx($.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",onClick:()=>v({type:"create"}),sx:{fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),y.length===0?t.jsxs(o.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[t.jsx($.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:R=>R.typography.body2.fontWeight||500,fontSize:R=>R.typography.body2.fontSize||"0.875rem",color:"text.secondary"},children:"No scheduled reports yet"}),t.jsx(o.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:y.map(R=>t.jsx(Dp,{schedule:R,tick:S,onToggle:T,onRunNow:w,onEdit:u=>v({type:"edit",schedule:u}),onDelete:P},R.id))})]})]}),g.type==="list"&&t.jsxs(o.DialogActions,{sx:{px:2.5,py:1.25,borderTop:"1px solid",borderColor:"divider",flexShrink:0,display:"flex",alignItems:"center",gap:1},children:[t.jsxs(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75,px:1.25,py:.75,borderRadius:"8px",bgcolor:R=>D(R.palette.warning.main,.06),border:"1px solid",borderColor:R=>D(R.palette.warning.main,.2)},children:[t.jsx($.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),t.jsx(o.Button,{onClick:r,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:R=>D(R.palette.text.primary,.06)}},children:"Close"})]})]}),b&&t.jsx(Ep,{scheduleName:b.name,onConfirm:O,onCancel:()=>m(null)})]})}const _p=6e4;function Op({reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:a,columnVisibility:c,columnOrder:l,filters:p,sortStack:x,onFired:y,schedulerConfig:g}){const v=(g==null?void 0:g.mode)??"local",S=f.useRef({reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:a,columnVisibility:c,columnOrder:l,filters:p,sortStack:x,onFired:y,schedulerConfig:g,schedulerMode:v});f.useEffect(()=>{S.current={reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:a,columnVisibility:c,columnOrder:l,filters:p,sortStack:x,onFired:y,schedulerConfig:g,schedulerMode:v}});const k=f.useCallback(b=>{var R,u,A,F,d;const{reportName:m,uploadedData:z,processedData:h,schema:B,activeView:T,columnVisibility:w,columnOrder:P,filters:O,sortStack:M,schedulerConfig:Y,schedulerMode:J}=S.current;try{const ne=b.scope==="all"?z:h;if(J==="api"){const ge=(P.length>0?P:B.map(X=>X.name)).filter(X=>w[X]!==!1),V={schedule:b,triggeredAt:new Date().toISOString(),rows:ne,columns:ge,format:b.format,reportName:m};(R=Y==null?void 0:Y.onScheduleFire)==null||R.call(Y,V),(A=(u=S.current).onFired)==null||A.call(u,b);return}const U=Qo(ne,B,O,M,T,w,P),re=`${b.name}_scheduled`;switch(b.format){case"csv":Zo(U,re,{scope:b.scope});break;case"excel":en(U,re,{scope:b.scope});break;case"json":tn(U,re,{scope:b.scope});break;case"pdf":ui(U,re,{scope:b.scope});break}if(Y!=null&&Y.onScheduleFire){const ge=(P.length>0?P:B.map(V=>V.name)).filter(V=>w[V]!==!1);Y.onScheduleFire({schedule:b,triggeredAt:new Date().toISOString(),rows:ne,columns:ge,format:b.format,reportName:m})}if(b.email){const ge=encodeURIComponent(`Scheduled Report: ${b.name}`),V=encodeURIComponent(`Your scheduled report "${b.name}" has been generated.
|
|
192
192
|
|
|
193
193
|
Report: ${m}
|
|
194
194
|
Format: ${b.format.toUpperCase()}
|
|
195
195
|
Generated: ${new Date().toLocaleString()}
|
|
196
196
|
|
|
197
|
-
The file has been downloaded to your device.`);window.open(`mailto:${b.email}?subject=${xe}&body=${V}`,"_blank")}(d=(F=S.current).onFired)==null||d.call(F,b)}catch(ne){Lt.error("urm:scheduler",`Export failed for schedule: ${b.name}`,ne)}},[]);f.useEffect(()=>{if(!e)return;const b=()=>{const{reportId:z,schedulerMode:h,schedulerConfig:B}=S.current;if(!z)return;const T=h==="api"?(B==null?void 0:B.schedules)??[]:ia(z),j=new Date;let P=!1;const _=T.map(M=>{if(!M.isActive)return M;if(new Date(M.nextRunAt)<=j){k(M);const q=Xo(M.frequency,M.time,M.dayOfWeek,M.dayOfMonth,j);return P=!0,{...M,lastRunAt:j.toISOString(),nextRunAt:q,runCount:M.runCount+1}}return M});P&&h==="local"&&sa(z,_)};b();const m=setInterval(b,_p);return()=>clearInterval(m)},[e,k])}function la({reportEngine:e}){var Ge,wr,st,Jt,It,kr;const{activeReport:r,paginatedData:n,processedData:i,tableMetrics:s,tableEngine:a,activeView:c,isDirty:l,currentTableState:p,showFilterPanel:x,setShowFilterPanel:y,filterFocusColumn:g,handleReplaceFilters:v,handleOpenFilterForColumn:S,handleCloseFilterPanel:k,handleClearFiltersForColumn:b,showSortPanel:m,setShowSortPanel:z,handleSort:h,handleUpdateSortStack:B,handleSortAscending:T,handleSortDescending:j,showCreateViewModal:P,setShowCreateViewModal:_,showEditViewModal:M,setShowEditViewModal:G,showDeleteConfirmation:q,setShowDeleteConfirmation:R,editingView:u,deletingView:A,handleSelectView:F,handleCreateView:d,handleUpdateCurrentView:ne,handleSaveAsNewView:U,handleRevertChanges:re,handleToggleDefault:xe,handleToggleFavorite:V,handleSoftDelete:X,handleRestoreView:ae,handlePermanentDelete:le,handleEditView:ie,handleCloneView:Q,handleCopyViewLink:de,handleSaveEditView:I,handleConfirmDelete:te,handlePromoteToGlobal:he,showManageColumns:se,setShowManageColumns:ze,handleUpdateColumnVisibility:Y,handleUpdateColumnOrder:We,handleUpdateColumnWidth:kt,handleResetColumnLayout:dt,showGroupPanel:Or,setShowGroupPanel:Ot,handleGroup:ot,handleToggleGroupCollapse:Ft,handleExpandAllGroups:qe,handleCollapseAllGroups:zt,searchQuery:fr,debouncedSearchQuery:xt,searchHistory:tr,handleSearchChange:so,handleAddToSearchHistory:rr,handleToggleSearchFavourite:ao,handleDeleteSearchHistory:Tt,selectedRowIds:mr,handleToggleRowSelection:Je,handleToggleAllRows:Mt,handleRangeSelection:Vt,handleClearSelection:tt,handleUpdateSelectionAfterDelete:Qe,currentPage:Wt,pageSize:lo,paginationTotalRows:Mr,handlePageChange:xr,handlePageSizeChange:Ve,isExporting:ke,showExportModal:or,setShowExportModal:At,showDirtyExportWarning:gr,handleExport:yr,handleExportWithConfig:Ht,handleExportSelected:nr,handleExportAnyway:Ze,handleSaveAndExport:ir,handleCancelExport:gt,showAuditHistory:Wr,setShowAuditHistory:ee,showCreatePreset:br,setShowCreatePreset:Ar,showManagePresets:Bt,setShowManagePresets:H,activePreset:ut,handleCreatePreset:we,handleClearActivePreset:Ke,handleOpenPresetById:sr,handleDeletePresetById:vr,isViewerRole:co,userRole:Ut,featureLimitWarning:Sr,setFeatureLimitWarning:Gt,reportError:ar,setReportError:Yt,handleError:be,updateReport:yt,showSnack:Z,config:pe,scheduler:ye}=e,[Cr,jr]=f.useState(!1);Op({reportId:r==null?void 0:r.id,reportName:(r==null?void 0:r.name)||"Report",uploadedData:(r==null?void 0:r.uploadedData)||[],processedData:i||[],schema:(r==null?void 0:r.schema)||[],activeView:c,columnVisibility:(r==null?void 0:r.columnVisibility)||((Ge=c==null?void 0:c.snapshot)==null?void 0:Ge.columnVisibility)||{},columnOrder:(r==null?void 0:r.columnOrder)||((wr=c==null?void 0:c.snapshot)==null?void 0:wr.columnOrder)||[],filters:Le(r==null?void 0:r.filters),sortStack:(r==null?void 0:r.sortStack)||[],onFired:me=>{Z(`Scheduled export "${me.name}" completed`,"success")},schedulerConfig:ye});const uo=f.useCallback((me,Se)=>{if(!(r!=null&&r.uploadedData))return;const Ne=[...r.uploadedData];Ne[me]=Se,yt(r.id,{uploadedData:Ne})},[r,yt]),Rr=f.useCallback(me=>{if(!(r!=null&&r.uploadedData))return;const Se=r.uploadedData.indexOf(me);if(Se===-1)return;const Ne=r.uploadedData.filter((nt,Et)=>Et!==Se);yt(r.id,{uploadedData:Ne}),Qe(me)},[r,yt,Qe]),po=f.useCallback((me,Se)=>{if(!(r!=null&&r.uploadedData))return;const Ne=r.uploadedData.indexOf(Se),nt=Ne!==-1?Ne+1:me+1,Et=[...r.uploadedData];Et.splice(nt,0,{...Se}),yt(r.id,{uploadedData:Et})},[r,yt]),qt=Dr(),{handleDevConfigChange:Pr}=cn(),[Nr,ve]=f.useState(!1);return f.useEffect(()=>{const me=Se=>{Se.ctrlKey&&Se.shiftKey&&Se.key==="D"&&(Se.preventDefault(),ve(!0))};return document.addEventListener("keydown",me),()=>document.removeEventListener("keydown",me)},[]),!r||!r.schemaLocked||!r.schema||!r.uploadedData||!r.views?null:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[t.jsxs(o.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[Sr&&t.jsx(mp,{warning:Sr,onDismiss:()=>Gt(null)}),ar&&t.jsx(xp,{error:ar,onDismiss:()=>Yt(null)}),gr&&t.jsx(Xu,{onExportAnyway:Ze,onSaveAndExport:ir,onCancel:gt}),t.jsx(Nu,{schema:r.schema,data:n,sortStack:r.sortStack,filters:r.filters,views:r.views,activeViewId:r.activeViewId,isDirty:l,isExporting:ke,columnVisibility:r.columnVisibility||(c==null?void 0:c.snapshot.columnVisibility),columnOrder:r.columnOrder||(c==null?void 0:c.snapshot.columnOrder),columnWidths:r.columnWidths||(c==null?void 0:c.snapshot.columnWidths),grouping:r.grouping,onSort:h,onSortAscending:T,onSortDescending:j,onOpenFilters:()=>y(!0),onOpenSort:()=>z(!0),onOpenFilterForColumn:S,onSelectView:F,onCreateView:()=>_(!0),onUpdateCurrentView:ne,onSaveAsNewView:U,onDiscardChanges:re,onToggleDefault:xe,onToggleFavorite:V,onRestoreView:ae,onPermanentDelete:le,onEditView:ie,onCloneView:Q,onCopyLink:de,onDeleteView:X,onPromoteToGlobal:he,isAdmin:((st=qt.views)==null?void 0:st.isAdmin)??!1,onExport:yr,onOpenColumns:()=>ze(!0),onUpdateColumnWidth:kt,onUpdateColumnOrder:We,onUpdateColumnVisibility:Y,onClearFiltersForColumn:b,onResetLayout:dt,onOpenGroup:()=>Ot(!0),onGroupByColumn:(Jt=pe==null?void 0:pe.hideToolbarActions)!=null&&Jt.includes("grouping")?void 0:me=>{ot({enabled:!0,levels:[{column:me}],collapsedGroups:[]})},onToggleGroupCollapse:Ft,onExpandAllGroups:qe,onCollapseAllGroups:zt,onOpenAuditHistory:()=>ee(!0),onOpenScheduledReports:()=>jr(!0),searchQuery:fr,highlightQuery:xt,searchHistory:tr,onAddToSearchHistory:rr,onToggleSearchFavourite:ao,onDeleteSearchHistory:Tt,selectedRowIds:mr,onSearchChange:so,onToggleRowSelection:Je,onToggleAllRows:Mt,onRangeSelection:Vt,onClearSelection:tt,onExportSelected:nr,currentPage:Wt,pageSize:lo,onPageChange:xr,onPageSizeChange:Ve,totalRowsBeforePagination:Mr,isReadOnly:co,userRole:Ut,reportName:r.name,onEditRow:uo,onDeleteRow:Rr,onDuplicateRow:po,rowActions:pe==null?void 0:pe.rowActions,hideDefaultRowActions:pe==null?void 0:pe.hideDefaultRowActions,hideToolbarActions:pe==null?void 0:pe.hideToolbarActions,customSettingsActions:pe==null?void 0:pe.customSettingsActions,viewOptions:pe==null?void 0:pe.viewOptions,defaultViewMode:pe==null?void 0:pe.defaultViewMode,bulkActions:pe==null?void 0:pe.bulkActions,hideSelectionCheckboxes:pe==null?void 0:pe.hideSelectionCheckboxes,rowClickBehavior:pe==null?void 0:pe.rowClickBehavior,openModalOn:pe==null?void 0:pe.openModalOn,onRowClick:pe==null?void 0:pe.onRowClick,onRowRightClick:pe==null?void 0:pe.onRowRightClick,showDevPanel:qt.display.showDevPanel,onOpenDevConfig:()=>ve(!0)})]}),x&&t.jsx(Yo,{feature:"Filters",onError:me=>{const Se=ur("ui","filters",me);be(Se)},children:t.jsx(Hu,{schema:r.schema,filters:r.filters,onReplaceFilters:v,onClose:k,focusColumn:g})}),m&&t.jsx(Yo,{feature:"Sorting",onError:me=>{const Se=ur("ui","sorting",me);be(Se)},children:t.jsx(Gu,{schema:r.schema,sortStack:r.sortStack??[],onUpdateSortStack:B,onClose:()=>z(!1)})}),P&&p&&(()=>{var Ne;const me=(r.views??[]).filter(nt=>!nt.isDeleted).length,Se=((Ne=qt.views)==null?void 0:Ne.maxViews)??10;return t.jsx(fs,{currentSnapshot:p,onSave:d,onClose:()=>_(!1),atViewLimit:me>=Se,maxViews:Se})})(),M&&u&&t.jsx(fs,{currentSnapshot:u.snapshot,onSave:I,onClose:()=>{G(!1)},isEditMode:!0,initialName:u.name,initialDescription:u.description,initialIsDefault:u.isDefault}),q&&A&&t.jsx(Yu,{viewName:A.name,onConfirm:te,onCancel:()=>{R(!1)}}),se&&c&&t.jsx(Ju,{schema:r.schema,columnVisibility:r.columnVisibility||c.snapshot.columnVisibility,columnOrder:r.columnOrder||c.snapshot.columnOrder,columnWidths:r.columnWidths||c.snapshot.columnWidths,views:r.views,activeViewId:r.activeViewId,onUpdateColumnVisibility:Y,onUpdateColumnOrder:We,onUpdateColumnWidth:kt,onResetLayout:dt,onClose:()=>ze(!1)}),Or&&t.jsx(Yo,{feature:"Grouping",onError:me=>{const Se=ur("ui","grouping",me);be(Se)},children:t.jsx(Ku,{schema:r.schema,grouping:r.grouping||null,onApply:ot,onClose:()=>Ot(!1)})}),Wr&&t.jsx(ep,{auditHistory:r.auditHistory||[],onClose:()=>ee(!1)}),br&&t.jsx(tp,{onSave:we,onClose:()=>Ar(!1)}),Bt&&t.jsx(op,{presets:r.presets||[],reportId:r.id,onOpenPreset:sr,onDeletePreset:vr,onClose:()=>H(!1)}),ut&&t.jsx(o.Box,{sx:{mt:2},children:t.jsx(rp,{presetName:ut.name,onClear:Ke})}),or&&t.jsx(Yo,{feature:"Export",onError:me=>{const Se=ur("ui","export",me);be(Se)},children:t.jsx(fp,{totalRows:(s==null?void 0:s.totalRows)||((It=r.uploadedData)==null?void 0:It.length)||0,visibleRows:(s==null?void 0:s.searchedRows)||i.length,visibleColumnsCount:((kr=a==null?void 0:a.columnEngine)==null?void 0:kr.visibleColumns.length)||r.schema.length,totalColumnsCount:r.schema.length,hasGrouping:(s==null?void 0:s.isGrouped)||!1,schema:r.schema,allRows:r.uploadedData||[],processedRows:i||[],onExport:Ht,onClose:()=>{At(!1)}})}),r&&t.jsx($p,{open:Cr,onClose:()=>jr(!1),reportId:r.id,reportName:r.name,schedulerConfig:ye,onRunNow:me=>{var Et;const Se=(ye==null?void 0:ye.mode)??"local",Ne=me.scope==="all"?r.uploadedData||[]:i||[],nt=Qo(Ne,r.schema||[],Le(r.filters),r.sortStack||[],c,r.columnVisibility,r.columnOrder);if(Se==="api"){const zr=(r.columnOrder||[]).filter(Lr=>(r.columnVisibility??{})[Lr]!==!1);(Et=ye==null?void 0:ye.onScheduleFire)==null||Et.call(ye,{schedule:me,triggeredAt:new Date().toISOString(),rows:Ne,columns:zr,format:me.format,reportName:r.name})}else me.format==="csv"&&Zo(nt,me.name),me.format==="excel"&&en(nt,me.name),me.format==="json"&&tn(nt,me.name),me.format==="pdf"&&ui(nt,me.name);Z(`"${me.name}" exported successfully`,"success")}}),t.jsx(Sp,{open:Nr,onClose:()=>ve(!1),config:qt,onApply:Pr})]})}const Mp={error:"err",warning:"warn",info:"info",success:"suc"};function ca({open:e,message:r,severity:n,onClose:i,autoHideDurationMs:s}){var B,T,j,P;const a=o.useTheme(),c=a.tokens,l=(c==null?void 0:c.notifPosition)??"top-right",p=(c==null?void 0:c.notifStyle)??"toast",x=(c==null?void 0:c.notifAccent)??"severity",y=(c==null?void 0:c.notifAutoDismiss)??!0,g=(c==null?void 0:c.toastW)??252,v=l.startsWith("top")?"top":"bottom",S=l.endsWith("center")?"center":l.endsWith("left")?"left":"right",k=Mp[n],b=((B=c==null?void 0:c.status)==null?void 0:B[`${k}Soft`])??a.palette[n].light,m=((T=c==null?void 0:c.status)==null?void 0:T[`${k}Txt`])??a.palette[n].dark,z=x==="primary"?a.palette.primary.main:x==="mono"?a.palette.text.secondary:m,h=p==="toast"?(c==null?void 0:c.toastBg)??a.palette.background.paper:b;return t.jsx(o.Snackbar,{open:e,autoHideDuration:y?s??(c!=null&&c.autoDismissSec?c.autoDismissSec*1e3:2e3):void 0,onClose:(_,M)=>{M!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:v,horizontal:S},children:t.jsx(o.Alert,{severity:n,icon:p==="toast"?t.jsx(o.Box,{sx:{width:30,height:30,borderRadius:`${Math.max(Math.round((Number(a.shape.borderRadius)||4)*.6),2)}px`,bgcolor:((j=c==null?void 0:c.status)==null?void 0:j[`${k}Soft`])??a.palette[n].light,color:((P=c==null?void 0:c.status)==null?void 0:P[`${k}Txt`])??a.palette[n].dark,display:"grid",placeItems:"center",flexShrink:0,fontSize:"15px",fontWeight:800,mt:-.5,ml:-.5},children:n==="error"||n==="warning"?"!":n==="success"?"✓":"i"}):void 0,action:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[y&&(c==null?void 0:c.autoDismissSec)&&t.jsx(o.Box,{sx:{px:1,py:.25,borderRadius:"999px",bgcolor:E(z,.14),color:z,fontSize:"0.7rem",fontWeight:800,fontVariantNumeric:"tabular-nums"},children:`${c.autoDismissSec}s`}),t.jsx(o.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",p:.25},children:t.jsx($.Close,{sx:{fontSize:16}})})]}),sx:{width:g,alignItems:"flex-start",bgcolor:h,color:m,boxShadow:p==="inline"?"none":(c==null?void 0:c.cardShadow)??3,border:p==="inline"?"1px solid":p==="toast"?(c==null?void 0:c.cardBorder)??"1px solid":"none",borderColor:"divider",borderLeft:p==="banner"?`4px solid ${z}`:void 0,borderRadius:`${a.shape.borderRadius}px`,"& .MuiAlert-icon":{color:z}},children:t.jsxs(o.Box,{children:[p==="toast"&&t.jsx(o.Box,{sx:{fontWeight:700,mb:"2px",fontSize:"0.875rem",color:a.palette.text.primary},children:n==="error"?"Error":n==="warning"?"Warning":n==="success"?"Success":"Info"}),t.jsx(o.Box,{sx:{fontSize:"0.8125rem",lineHeight:1.4},children:r})]})})})}function da({hasExternalData:e=!1}){const r=cn(),{reports:n,activeReportId:i,activeReport:s,uploadState:a,hasSchemaConflicts:c,isModalOpen:l,setIsModalOpen:p,setActiveReportId:x,createReport:y,handleFileUpload:g,handleUploadError:v,handleRetry:S,handleConfirm:k,snack:b,handleSnackClose:m,snackDurationMs:z}=r,h=e&&a==="uploading"&&n.length===0;return t.jsxs(o.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsx(Hl,{onCreateReport:()=>p(!0),reports:n,activeReportId:i,onReportClick:x}),t.jsx(o.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:h?t.jsxs(o.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[t.jsx(o.CircularProgress,{size:40,thickness:3}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{minWidth:260,textAlign:"center"},children:"Fetching API data — please wait..."})]}):n.length===0?t.jsx(Ks,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):s?t.jsx(t.Fragment,{children:s.schemaLocked&&s.schema&&s.uploadedData&&s.views?t.jsx(la,{reportEngine:r}):t.jsx(o.Box,{sx:{p:3},children:a==="preview"&&s.schema&&s.uploadedData?t.jsx(ou,{schema:s.schema,onConfirm:k,hasConflicts:c}):s.uploadError?t.jsx(nu,{error:s.uploadError,onRetry:S}):t.jsx(ru,{onFileUpload:g,onError:v,isUploading:a==="uploading"})})}):null}),!e&&t.jsx(tu,{isOpen:l,onClose:()=>p(!1),onCreate:y}),t.jsx(ca,{open:b.open,message:b.message,severity:b.severity,onClose:m,autoHideDurationMs:z})]})}function Wp({data:e,dataSource:r,pagination:n,search:i,reportName:s,reportId:a,autoLoad:c=!0,config:l}={}){return t.jsx(pi,{mode:"builder",data:e,dataSource:r,pagination:n,search:i,reportName:s,reportId:a,autoLoad:c,config:l,children:t.jsx(da,{hasExternalData:!!(e||r)})})}function ua(){const e=cn(),{snack:r,handleSnackClose:n,snackDurationMs:i}=e;return t.jsxs(o.Box,{sx:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[t.jsx(o.Box,{component:"main",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:e.activeReport?t.jsx(la,{reportEngine:e}):t.jsx(Ks,{title:"No report data",description:"This viewer requires report data to be loaded."})}),t.jsx(ca,{open:r.open,message:r.message,severity:r.severity,onClose:n,autoHideDurationMs:i})]})}function Ap({data:e,reportId:r,pagination:n,search:i,autoLoad:s=!0,config:a}){return t.jsx(pi,{data:e,reportId:r,pagination:n,search:i,mode:"viewer",autoLoad:s,config:a,children:t.jsx(ua,{})})}exports.URMBuilder=Wp;exports.URMBuilderRaw=da;exports.URMProvider=pi;exports.URMViewer=Ap;exports.URMViewerRaw=ua;exports.useURMContext=cn;
|
|
197
|
+
The file has been downloaded to your device.`);window.open(`mailto:${b.email}?subject=${ge}&body=${V}`,"_blank")}(d=(F=S.current).onFired)==null||d.call(F,b)}catch(ne){Lt.error("urm:scheduler",`Export failed for schedule: ${b.name}`,ne)}},[]);f.useEffect(()=>{if(!e)return;const b=()=>{const{reportId:z,schedulerMode:h,schedulerConfig:B}=S.current;if(!z)return;const T=h==="api"?(B==null?void 0:B.schedules)??[]:ia(z),w=new Date;let P=!1;const O=T.map(M=>{if(!M.isActive)return M;if(new Date(M.nextRunAt)<=w){k(M);const J=Xo(M.frequency,M.time,M.dayOfWeek,M.dayOfMonth,w);return P=!0,{...M,lastRunAt:w.toISOString(),nextRunAt:J,runCount:M.runCount+1}}return M});P&&h==="local"&&sa(z,O)};b();const m=setInterval(b,_p);return()=>clearInterval(m)},[e,k])}function la({reportEngine:e}){var Ge,wr,st,Jt,It,kr;const{activeReport:r,paginatedData:n,processedData:i,tableMetrics:s,tableEngine:a,activeView:c,isDirty:l,currentTableState:p,showFilterPanel:x,setShowFilterPanel:y,filterFocusColumn:g,handleReplaceFilters:v,handleOpenFilterForColumn:S,handleCloseFilterPanel:k,handleClearFiltersForColumn:b,showSortPanel:m,setShowSortPanel:z,handleSort:h,handleUpdateSortStack:B,handleSortAscending:T,handleSortDescending:w,showCreateViewModal:P,setShowCreateViewModal:O,showEditViewModal:M,setShowEditViewModal:Y,showDeleteConfirmation:J,setShowDeleteConfirmation:R,editingView:u,deletingView:A,handleSelectView:F,handleCreateView:d,handleUpdateCurrentView:ne,handleSaveAsNewView:U,handleRevertChanges:re,handleToggleDefault:ge,handleToggleFavorite:V,handleSoftDelete:X,handleRestoreView:ce,handlePermanentDelete:de,handleEditView:ie,handleCloneView:Q,handleCopyViewLink:pe,handleSaveEditView:I,handleConfirmDelete:te,handlePromoteToGlobal:fe,showManageColumns:ae,setShowManageColumns:ze,handleUpdateColumnVisibility:q,handleUpdateColumnOrder:We,handleUpdateColumnWidth:kt,handleResetColumnLayout:dt,showGroupPanel:Or,setShowGroupPanel:Ot,handleGroup:ot,handleToggleGroupCollapse:Ft,handleExpandAllGroups:qe,handleCollapseAllGroups:zt,searchQuery:fr,debouncedSearchQuery:xt,searchHistory:tr,handleSearchChange:ao,handleAddToSearchHistory:rr,handleToggleSearchFavourite:lo,handleDeleteSearchHistory:Tt,selectedRowIds:mr,handleToggleRowSelection:Je,handleToggleAllRows:Mt,handleRangeSelection:Vt,handleClearSelection:Qe,handleUpdateSelectionAfterDelete:Ze,currentPage:Wt,pageSize:co,paginationTotalRows:Mr,handlePageChange:xr,handlePageSizeChange:Ve,isExporting:ke,showExportModal:or,setShowExportModal:At,showDirtyExportWarning:gr,handleExport:yr,handleExportWithConfig:Ht,handleExportSelected:nr,handleExportAnyway:et,handleSaveAndExport:ir,handleCancelExport:gt,showAuditHistory:Wr,setShowAuditHistory:ee,showCreatePreset:br,setShowCreatePreset:Ar,showManagePresets:Bt,setShowManagePresets:H,activePreset:ut,handleCreatePreset:se,handleClearActivePreset:Ke,handleOpenPresetById:sr,handleDeletePresetById:vr,isViewerRole:uo,userRole:Ut,featureLimitWarning:Sr,setFeatureLimitWarning:Gt,reportError:ar,setReportError:Yt,handleError:ve,updateReport:yt,showSnack:Z,config:he,scheduler:be}=e,[Cr,jr]=f.useState(!1);Op({reportId:r==null?void 0:r.id,reportName:(r==null?void 0:r.name)||"Report",uploadedData:(r==null?void 0:r.uploadedData)||[],processedData:i||[],schema:(r==null?void 0:r.schema)||[],activeView:c,columnVisibility:(r==null?void 0:r.columnVisibility)||((Ge=c==null?void 0:c.snapshot)==null?void 0:Ge.columnVisibility)||{},columnOrder:(r==null?void 0:r.columnOrder)||((wr=c==null?void 0:c.snapshot)==null?void 0:wr.columnOrder)||[],filters:Le(r==null?void 0:r.filters),sortStack:(r==null?void 0:r.sortStack)||[],onFired:xe=>{Z(`Scheduled export "${xe.name}" completed`,"success")},schedulerConfig:be});const po=f.useCallback((xe,Ce)=>{if(!(r!=null&&r.uploadedData))return;const Ne=[...r.uploadedData];Ne[xe]=Ce,yt(r.id,{uploadedData:Ne})},[r,yt]),Rr=f.useCallback(xe=>{if(!(r!=null&&r.uploadedData))return;const Ce=r.uploadedData.indexOf(xe);if(Ce===-1)return;const Ne=r.uploadedData.filter((nt,Et)=>Et!==Ce);yt(r.id,{uploadedData:Ne}),Ze(xe)},[r,yt,Ze]),ho=f.useCallback((xe,Ce)=>{if(!(r!=null&&r.uploadedData))return;const Ne=r.uploadedData.indexOf(Ce),nt=Ne!==-1?Ne+1:xe+1,Et=[...r.uploadedData];Et.splice(nt,0,{...Ce}),yt(r.id,{uploadedData:Et})},[r,yt]),qt=Dr(),{handleDevConfigChange:Pr}=cn(),[Nr,Se]=f.useState(!1);return f.useEffect(()=>{const xe=Ce=>{Ce.ctrlKey&&Ce.shiftKey&&Ce.key==="D"&&(Ce.preventDefault(),Se(!0))};return document.addEventListener("keydown",xe),()=>document.removeEventListener("keydown",xe)},[]),!r||!r.schemaLocked||!r.schema||!r.uploadedData||!r.views?null:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[t.jsxs(o.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[Sr&&t.jsx(mp,{warning:Sr,onDismiss:()=>Gt(null)}),ar&&t.jsx(xp,{error:ar,onDismiss:()=>Yt(null)}),gr&&t.jsx(Xu,{onExportAnyway:et,onSaveAndExport:ir,onCancel:gt}),t.jsx(Nu,{schema:r.schema,data:n,sortStack:r.sortStack,filters:r.filters,views:r.views,activeViewId:r.activeViewId,isDirty:l,isExporting:ke,columnVisibility:r.columnVisibility||(c==null?void 0:c.snapshot.columnVisibility),columnOrder:r.columnOrder||(c==null?void 0:c.snapshot.columnOrder),columnWidths:r.columnWidths||(c==null?void 0:c.snapshot.columnWidths),grouping:r.grouping,onSort:h,onSortAscending:T,onSortDescending:w,onOpenFilters:()=>y(!0),onOpenSort:()=>z(!0),onOpenFilterForColumn:S,onSelectView:F,onCreateView:()=>O(!0),onUpdateCurrentView:ne,onSaveAsNewView:U,onDiscardChanges:re,onToggleDefault:ge,onToggleFavorite:V,onRestoreView:ce,onPermanentDelete:de,onEditView:ie,onCloneView:Q,onCopyLink:pe,onDeleteView:X,onPromoteToGlobal:fe,isAdmin:((st=qt.views)==null?void 0:st.isAdmin)??!1,onExport:yr,onOpenColumns:()=>ze(!0),onUpdateColumnWidth:kt,onUpdateColumnOrder:We,onUpdateColumnVisibility:q,onClearFiltersForColumn:b,onResetLayout:dt,onOpenGroup:()=>Ot(!0),onGroupByColumn:(Jt=he==null?void 0:he.hideToolbarActions)!=null&&Jt.includes("grouping")?void 0:xe=>{ot({enabled:!0,levels:[{column:xe}],collapsedGroups:[]})},onToggleGroupCollapse:Ft,onExpandAllGroups:qe,onCollapseAllGroups:zt,onOpenAuditHistory:()=>ee(!0),onOpenScheduledReports:()=>jr(!0),searchQuery:fr,highlightQuery:xt,searchHistory:tr,onAddToSearchHistory:rr,onToggleSearchFavourite:lo,onDeleteSearchHistory:Tt,selectedRowIds:mr,onSearchChange:ao,onToggleRowSelection:Je,onToggleAllRows:Mt,onRangeSelection:Vt,onClearSelection:Qe,onExportSelected:nr,currentPage:Wt,pageSize:co,onPageChange:xr,onPageSizeChange:Ve,totalRowsBeforePagination:Mr,isReadOnly:uo,userRole:Ut,reportName:r.name,onEditRow:po,onDeleteRow:Rr,onDuplicateRow:ho,rowActions:he==null?void 0:he.rowActions,hideDefaultRowActions:he==null?void 0:he.hideDefaultRowActions,hideToolbarActions:he==null?void 0:he.hideToolbarActions,customSettingsActions:he==null?void 0:he.customSettingsActions,viewOptions:he==null?void 0:he.viewOptions,defaultViewMode:he==null?void 0:he.defaultViewMode,bulkActions:he==null?void 0:he.bulkActions,hideSelectionCheckboxes:he==null?void 0:he.hideSelectionCheckboxes,rowClickBehavior:he==null?void 0:he.rowClickBehavior,openModalOn:he==null?void 0:he.openModalOn,onRowClick:he==null?void 0:he.onRowClick,onRowRightClick:he==null?void 0:he.onRowRightClick,showDevPanel:qt.display.showDevPanel,onOpenDevConfig:()=>Se(!0)})]}),x&&t.jsx(Yo,{feature:"Filters",onError:xe=>{const Ce=ur("ui","filters",xe);ve(Ce)},children:t.jsx(Hu,{schema:r.schema,filters:r.filters,onReplaceFilters:v,onClose:k,focusColumn:g})}),m&&t.jsx(Yo,{feature:"Sorting",onError:xe=>{const Ce=ur("ui","sorting",xe);ve(Ce)},children:t.jsx(Gu,{schema:r.schema,sortStack:r.sortStack??[],onUpdateSortStack:B,onClose:()=>z(!1)})}),P&&p&&(()=>{var Ne;const xe=(r.views??[]).filter(nt=>!nt.isDeleted).length,Ce=((Ne=qt.views)==null?void 0:Ne.maxViews)??10;return t.jsx(fs,{currentSnapshot:p,onSave:d,onClose:()=>O(!1),atViewLimit:xe>=Ce,maxViews:Ce})})(),M&&u&&t.jsx(fs,{currentSnapshot:u.snapshot,onSave:I,onClose:()=>{Y(!1)},isEditMode:!0,initialName:u.name,initialDescription:u.description,initialIsDefault:u.isDefault}),J&&A&&t.jsx(Yu,{viewName:A.name,onConfirm:te,onCancel:()=>{R(!1)}}),ae&&c&&t.jsx(Ju,{schema:r.schema,columnVisibility:r.columnVisibility||c.snapshot.columnVisibility,columnOrder:r.columnOrder||c.snapshot.columnOrder,columnWidths:r.columnWidths||c.snapshot.columnWidths,views:r.views,activeViewId:r.activeViewId,onUpdateColumnVisibility:q,onUpdateColumnOrder:We,onUpdateColumnWidth:kt,onResetLayout:dt,onClose:()=>ze(!1)}),Or&&t.jsx(Yo,{feature:"Grouping",onError:xe=>{const Ce=ur("ui","grouping",xe);ve(Ce)},children:t.jsx(Ku,{schema:r.schema,grouping:r.grouping||null,onApply:ot,onClose:()=>Ot(!1)})}),Wr&&t.jsx(ep,{auditHistory:r.auditHistory||[],onClose:()=>ee(!1)}),br&&t.jsx(tp,{onSave:se,onClose:()=>Ar(!1)}),Bt&&t.jsx(op,{presets:r.presets||[],reportId:r.id,onOpenPreset:sr,onDeletePreset:vr,onClose:()=>H(!1)}),ut&&t.jsx(o.Box,{sx:{mt:2},children:t.jsx(rp,{presetName:ut.name,onClear:Ke})}),or&&t.jsx(Yo,{feature:"Export",onError:xe=>{const Ce=ur("ui","export",xe);ve(Ce)},children:t.jsx(fp,{totalRows:(s==null?void 0:s.totalRows)||((It=r.uploadedData)==null?void 0:It.length)||0,visibleRows:(s==null?void 0:s.searchedRows)||i.length,visibleColumnsCount:((kr=a==null?void 0:a.columnEngine)==null?void 0:kr.visibleColumns.length)||r.schema.length,totalColumnsCount:r.schema.length,hasGrouping:(s==null?void 0:s.isGrouped)||!1,schema:r.schema,allRows:r.uploadedData||[],processedRows:i||[],onExport:Ht,onClose:()=>{At(!1)}})}),r&&t.jsx($p,{open:Cr,onClose:()=>jr(!1),reportId:r.id,reportName:r.name,schedulerConfig:be,onRunNow:xe=>{var Et;const Ce=(be==null?void 0:be.mode)??"local",Ne=xe.scope==="all"?r.uploadedData||[]:i||[],nt=Qo(Ne,r.schema||[],Le(r.filters),r.sortStack||[],c,r.columnVisibility,r.columnOrder);if(Ce==="api"){const zr=(r.columnOrder||[]).filter(Lr=>(r.columnVisibility??{})[Lr]!==!1);(Et=be==null?void 0:be.onScheduleFire)==null||Et.call(be,{schedule:xe,triggeredAt:new Date().toISOString(),rows:Ne,columns:zr,format:xe.format,reportName:r.name})}else xe.format==="csv"&&Zo(nt,xe.name),xe.format==="excel"&&en(nt,xe.name),xe.format==="json"&&tn(nt,xe.name),xe.format==="pdf"&&ui(nt,xe.name);Z(`"${xe.name}" exported successfully`,"success")}}),t.jsx(Sp,{open:Nr,onClose:()=>Se(!1),config:qt,onApply:Pr})]})}const Mp={error:"err",warning:"warn",info:"info",success:"suc"};function ca({open:e,message:r,severity:n,onClose:i,autoHideDurationMs:s}){var B,T,w,P;const a=o.useTheme(),c=a.tokens,l=(c==null?void 0:c.notifPosition)??"bottom-right",p=(c==null?void 0:c.notifStyle)??"toast",x=(c==null?void 0:c.notifAccent)??"severity",y=(c==null?void 0:c.notifAutoDismiss)??!0,g=(c==null?void 0:c.toastW)??252,v=l.startsWith("top")?"top":"bottom",S=l.endsWith("center")?"center":l.endsWith("left")?"left":"right",k=Mp[n],b=((B=c==null?void 0:c.status)==null?void 0:B[`${k}Soft`])??a.palette[n].light,m=((T=c==null?void 0:c.status)==null?void 0:T[`${k}Txt`])??a.palette[n].dark,z=x==="primary"?a.palette.primary.main:x==="mono"?a.palette.text.secondary:m,h=p==="toast"?(c==null?void 0:c.toastBg)??a.palette.background.paper:b;return t.jsx(o.Snackbar,{open:e,autoHideDuration:y?s??(c!=null&&c.autoDismissSec?c.autoDismissSec*1e3:3e4):void 0,onClose:(O,M)=>{M!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:v,horizontal:S},children:t.jsx(o.Alert,{severity:n,icon:p==="toast"?t.jsx(o.Box,{sx:{width:30,height:30,borderRadius:`${Math.max(Math.round((Number(a.shape.borderRadius)||4)*.6),2)}px`,bgcolor:((w=c==null?void 0:c.status)==null?void 0:w[`${k}Soft`])??a.palette[n].light,color:((P=c==null?void 0:c.status)==null?void 0:P[`${k}Txt`])??a.palette[n].dark,display:"grid",placeItems:"center",flexShrink:0,fontSize:"15px",fontWeight:800,mt:-.5,ml:-.5},children:n==="error"||n==="warning"?"!":n==="success"?"✓":"i"}):void 0,action:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[y&&(c==null?void 0:c.autoDismissSec)&&t.jsx(o.Box,{sx:{px:1,py:.25,borderRadius:"999px",bgcolor:D(z,.14),color:z,fontSize:"0.7rem",fontWeight:800,fontVariantNumeric:"tabular-nums"},children:`${c.autoDismissSec}s`}),t.jsx(o.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",p:.25},children:t.jsx($.Close,{sx:{fontSize:16}})})]}),sx:{width:g,alignItems:"flex-start",bgcolor:h,color:m,boxShadow:p==="inline"?"none":(c==null?void 0:c.cardShadow)??3,border:p==="inline"?"1px solid":p==="toast"?(c==null?void 0:c.cardBorder)??"1px solid":"none",borderColor:"divider",borderLeft:p==="banner"?`4px solid ${z}`:void 0,borderRadius:`${a.shape.borderRadius}px`,"& .MuiAlert-icon":{color:z}},children:t.jsxs(o.Box,{children:[p==="toast"&&t.jsx(o.Box,{sx:{fontWeight:700,mb:"2px",fontSize:"0.875rem",color:a.palette.text.primary},children:n==="error"?"Error":n==="warning"?"Warning":n==="success"?"Success":"Info"}),t.jsx(o.Box,{sx:{fontSize:"0.8125rem",lineHeight:1.4},children:r})]})})})}function da({hasExternalData:e=!1}){const r=cn(),{reports:n,activeReportId:i,activeReport:s,uploadState:a,hasSchemaConflicts:c,isModalOpen:l,setIsModalOpen:p,setActiveReportId:x,createReport:y,handleFileUpload:g,handleUploadError:v,handleRetry:S,handleConfirm:k,snack:b,handleSnackClose:m,snackDurationMs:z}=r,h=e&&a==="uploading"&&n.length===0;return t.jsxs(o.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsx(Hl,{onCreateReport:()=>p(!0),reports:n,activeReportId:i,onReportClick:x}),t.jsx(o.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:h?t.jsxs(o.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[t.jsx(o.CircularProgress,{size:40,thickness:3}),t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{minWidth:260,textAlign:"center"},children:"Fetching API data — please wait..."})]}):n.length===0?t.jsx(Ks,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):s?t.jsx(t.Fragment,{children:s.schemaLocked&&s.schema&&s.uploadedData&&s.views?t.jsx(la,{reportEngine:r}):t.jsx(o.Box,{sx:{p:3},children:a==="preview"&&s.schema&&s.uploadedData?t.jsx(ou,{schema:s.schema,onConfirm:k,hasConflicts:c}):s.uploadError?t.jsx(nu,{error:s.uploadError,onRetry:S}):t.jsx(ru,{onFileUpload:g,onError:v,isUploading:a==="uploading"})})}):null}),!e&&t.jsx(tu,{isOpen:l,onClose:()=>p(!1),onCreate:y}),t.jsx(ca,{open:b.open,message:b.message,severity:b.severity,onClose:m,autoHideDurationMs:z})]})}function Wp({data:e,dataSource:r,pagination:n,search:i,reportName:s,reportId:a,autoLoad:c=!0,config:l}={}){return t.jsx(pi,{mode:"builder",data:e,dataSource:r,pagination:n,search:i,reportName:s,reportId:a,autoLoad:c,config:l,children:t.jsx(da,{hasExternalData:!!(e||r)})})}function ua(){const e=cn(),{snack:r,handleSnackClose:n,snackDurationMs:i}=e;return t.jsxs(o.Box,{sx:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[t.jsx(o.Box,{component:"main",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:e.activeReport?t.jsx(la,{reportEngine:e}):t.jsx(Ks,{title:"No report data",description:"This viewer requires report data to be loaded."})}),t.jsx(ca,{open:r.open,message:r.message,severity:r.severity,onClose:n,autoHideDurationMs:i})]})}function Ap({data:e,reportId:r,pagination:n,search:i,autoLoad:s=!0,config:a}){return t.jsx(pi,{data:e,reportId:r,pagination:n,search:i,mode:"viewer",autoLoad:s,config:a,children:t.jsx(ua,{})})}exports.URMBuilder=Wp;exports.URMBuilderRaw=da;exports.URMProvider=pi;exports.URMViewer=Ap;exports.URMViewerRaw=ua;exports.useURMContext=cn;
|