dts-universal-report-module 1.1.1 → 1.1.2
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 +7931 -8561
- package/dist/index.js +28 -28
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";var Is=Object.defineProperty;var Bs=(t,o,n)=>o in t?Is(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n;var wn=(t,o,n)=>Bs(t,typeof o!="symbol"?o+"":o,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),Es=require("xlsx"),B=require("@mui/icons-material"),r=require("@mui/material"),ji=require("react-dom"),Ds=require("@emotion/react"),Dt=require("react-dnd"),an=require("react-dnd-html5-backend");function Ci(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const vo=Ci(u),ro=Ci(Es),Ge={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"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},wi="urm_dev_config";function Os(){try{const t=localStorage.getItem(wi);if(!t)return Ge;const o=JSON.parse(t),n={sort:{...Ge.sort,...o.sort},filter:{...Ge.filter,...o.filter},columns:{...Ge.columns,...o.columns},grouping:{...Ge.grouping,...o.grouping},export:{...Ge.export,...o.export},views:{...Ge.views,...o.views},dates:{...Ge.dates,...o.dates},display:{...Ge.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ge}}function $s(t){try{localStorage.setItem(wi,JSON.stringify(t))}catch{}}function As(t,o,n){if(!n||!o)return t;const i={sort:{...t.sort,...o.sort},filter:{...t.filter,...o.filter},columns:{...t.columns,...o.columns},grouping:{...t.grouping,...o.grouping},export:{...t.export,...o.export},views:{...t.views,...o.views},dates:{...t.dates,...o.dates},display:{...t.display,...o.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const ki=u.createContext(Ge);function dr(){return u.useContext(ki)}const Ms=/^\d{4}-\d{2}-\d{2}$/,Rs=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,_s=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ws=9783072e5,Ps=41024448e5,Ls=978307200,Ns=4102444800;function Fs(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Ws&&t<=Ps?"timestamp_ms":Number.isInteger(t)&&t>=Ls&&t<=Ns?"timestamp_s":"unknown":typeof t!="string"?"unknown":Rs.test(t)||Ms.test(t)?"iso":_s.test(t.trim())?"locale_string":"unknown"}function Vs(t,o){const n=o.map(c=>c[t]).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=Fs(c);i[l]++}const s=n.length,d=.7;for(const c of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[c]/s>=d)return c;return"unknown"}function Hs(t,o){if(t==null||t==="")return null;try{switch(o){case"timestamp_ms":{const n=new Date(Number(t));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(t)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const kn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Us=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ae(t){return String(t).padStart(2,"0")}function Gs(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),d=Math.floor(s/60),c=Math.floor(d/60),l=Math.floor(c/24),p=Math.floor(l/7),f=Math.floor(l/30),m=Math.floor(l/365);let h;return s<60?h="just now":d<60?h=`${d} minute${d!==1?"s":""}`:c<24?h=`${c} hour${c!==1?"s":""}`:l<7?h=`${l} day${l!==1?"s":""}`:p<5?h=`${p} week${p!==1?"s":""}`:f<12?h=`${f} month${f!==1?"s":""}`:h=`${m} year${m!==1?"s":""}`,s<60?h:i?`${h} ago`:`in ${h}`}function Ys(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),d=t.getHours(),c=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${Ae(i+1)}-${Ae(s)}`;case"DD/MM/YYYY":return`${Ae(s)}/${Ae(i+1)}/${n}`;case"MM/DD/YYYY":return`${Ae(i+1)}/${Ae(s)}/${n}`;case"MMM DD, YYYY":return`${kn[i]} ${Ae(s)}, ${n}`;case"DD MMM YYYY":return`${Ae(s)} ${kn[i]} ${n}`;case"MMMM D, YYYY":return`${Us[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Ae(i+1)}-${Ae(s)} ${Ae(d)}:${Ae(c)}`;case"DD/MM/YYYY HH:mm":return`${Ae(s)}/${Ae(i+1)}/${n} ${Ae(d)}:${Ae(c)}`;case"MM/DD/YYYY HH:mm":return`${Ae(i+1)}/${Ae(s)}/${n} ${Ae(d)}:${Ae(c)}`;case"relative":return Gs(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function qs(t,o,n){if(!n||o==="unknown")return String(t);const i=Hs(t,o);return!i||isNaN(i.getTime())?String(t):Ys(i,n)}function Js(t){return t==null?"null":Array.isArray(t)?"array":typeof t=="object"?"object":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="string"?"string":"mixed"}function Ti(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const d=o?`${o}.${s}`:s,c=t[s];c!==null&&typeof c=="object"&&!Array.isArray(c)&&n<2?Object.assign(i,Ti(c,d,n+1)):i[d]=c}return i}function co(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:Ti(o))}function Rr(t){if(!Array.isArray(t)||t.length===0)return[];const o=co(t),n=new Set;o.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;o.forEach(x=>{typeof x=="object"&&x!==null&&c in x&&(p++,l.add(Js(x[c])))});const f=p===o.length,m=l.size>1&&!l.has("null");let h="mixed";if(l.size===1)h=Array.from(l)[0];else if(l.size===2&&l.has("null")){const x=Array.from(l).filter(b=>b!=="null");x.length===1&&(h=x[0])}i.push({name:c,type:h,required:f,hasConflict:m})});const d=o.slice(0,50);for(const c of i){if(c.type!=="string"&&c.type!=="number")continue;const l=Vs(c.name,d);l!=="unknown"&&(c.type="date",c.dateFormat=l)}return i}function Ks(t){return t.some(o=>o.hasConflict)}function qe(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function Tn(t){return t==null}function Xs(t){return(o,n,i)=>{const s=Tn(o),d=Tn(n);if(s&&d)return 0;if(s)return 1;if(d)return-1;let c=0;switch(t){case"number":const l=Number(o),p=Number(n);c=l-p;break;case"boolean":c=(o?1:0)-(n?1:0);break;case"string":c=String(o).localeCompare(String(n));break;case"array":case"object":c=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:c=String(o).localeCompare(String(n));break}return i==="asc"?c:-c}}function Qs(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,d)=>s.priority-d.priority);return[...t].sort((s,d)=>{for(const c of i){const l=o.find(m=>m.name===c.column);if(!l)continue;const f=Xs(l.type)(s[c.column],d[c.column],c.direction);if(f!==0)return f}return 0})}function Zs(t){return t===null?"asc":t==="asc"?"desc":null}function ea(t){return t==="string"||t==="boolean"}function ta(t){return t.filter(o=>ea(o.type))}function ra(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(d=>d[i.name]).filter(d=>typeof d=="number");s.length>0&&(n[i.name]=s.reduce((d,c)=>d+c,0))}}),n}function oa(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=zi(t,n.levels,o);return Ii(i,n.collapsedGroups||[])}function zi(t,o,n,i="",s=0){if(s>=o.length)return t;const d=o[s].column,c=new Map;t.forEach(f=>{const m=f[d],h=m==null?"(empty)":String(m);c.has(h)||c.set(h,[]),c.get(h).push(f)});const l=[];return Array.from(c.keys()).sort().forEach(f=>{const m=c.get(f),h=`${d}:${f}`,x=i?`${i}|${h}`:h,b=ra(m,n),E=s<o.length-1?zi(m,o,n,x,s+1):m,g={key:x,level:s,column:d,value:f,rowCount:m.length,aggregates:b,children:E};l.push(g)}),l}function Ii(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const s=o.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:s}),!s&&i.children&&Ii(i.children,o,n)}else n.push(i);return n}function na(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function Bi(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function Ei(t,o,n){return`${o}: ${n}`}function Nr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(s=>s.column),i=t.filter(s=>!n.includes(s));return[...n,...i]}function Di(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(d=>d.column),s=t.filter(d=>!i.includes(d));if(n){const d=[],c=new Set(i),l=new Set(s);let p=0;for(const f of n)c.has(f)?d.push(f):l.has(f)&&p<s.length?(d.push(s[p]),p++):l.has(f)||d.push(f);for(let f=p;f<s.length;f++)d.includes(s[f])||d.push(s[f]);return d}return[...t]}function Uo(t){const o={},n=[],i={};return t.forEach(s=>{o[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:[],sortStack:[],columnVisibility:o,columnOrder:n,columnWidths:i,grouping:null}}}function ia(t,o,n,i,s,d,c,l){const p={},f=[],m={};n.forEach(b=>{p[b.name]=!0,f.push(b.name),m[b.name]=170});const x=Di(s||f,c||null,l||f);return{filters:t||[],sortStack:o||[],columnVisibility:i||p,columnOrder:x,columnWidths:d||m,grouping:c||null}}function sa(t,o){const n=x=>{if(x==null)return x;if(Array.isArray(x))return x.map(b=>n(b));if(typeof x=="object"){const b={};return Object.keys(x).sort().forEach(E=>{b[E]=n(x[E])}),b}return x},i=x=>JSON.stringify(n(x));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack))return!0;const s=t.columnVisibility??{},d=o.columnVisibility??{};if(i(s)!==i(d))return!0;const c=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(c!==l)return!1;const p=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==p){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const x=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==x)return!0}const m=t.columnWidths??{},h=o.columnWidths??{};return i(m)!==i(h)||i(t.grouping)!==i(o.grouping)}function aa(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function la(t,o){var g,j,k;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const v=t.filters.length,C=o.filters.length;v>C?n.push({category:"filters",label:"Filters Added",description:`${v-C} new filter${v-C>1?"s":""} added`}):v<C?n.push({category:"filters",label:"Filters Removed",description:`${C-v} filter${C-v>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const d=JSON.stringify(t.sortStack),c=JSON.stringify(o.sortStack);if(d!==c){const v=t.sortStack.length,C=o.sortStack.length;v>C?n.push({category:"sorting",label:"Sorting Added",description:`${v-C} new sort rule${v-C>1?"s":""} added`}):v<C?n.push({category:"sorting",label:"Sorting Removed",description:`${C-v} sort rule${C-v>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(t.columnVisibility),p=JSON.stringify(o.columnVisibility);if(l!==p){const v=Object.values(t.columnVisibility).filter(S=>S).length,C=Object.values(o.columnVisibility).filter(S=>S).length;v>C?n.push({category:"visibility",label:"Columns Shown",description:`${v-C} column${v-C>1?"s":""} made visible`}):v<C?n.push({category:"visibility",label:"Columns Hidden",description:`${C-v} column${C-v>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const f=JSON.stringify(t.columnOrder),m=JSON.stringify(o.columnOrder);f!==m&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const h=JSON.stringify(t.columnWidths),x=JSON.stringify(o.columnWidths);if(h!==x){const v=Object.keys(t.columnWidths).filter(C=>t.columnWidths[C]!==o.columnWidths[C]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${v} column width${v>1?"s":""} modified`})}const b=JSON.stringify(t.grouping),E=JSON.stringify(o.grouping);if(b!==E){const v=(g=t.grouping)==null?void 0:g.enabled,C=(j=o.grouping)==null?void 0:j.enabled;if(v&&!C){const S=((k=t.grouping)==null?void 0:k.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${S} grouping level${S>1?"s":""} added`})}else!v&&C?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 zn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function In(t){return`[${t}]`}const lr={warn(t,o,...n){zn()&&console.warn(In(t),o,...n)},error(t,o,...n){zn()&&console.error(In(t),o,...n)}},Oi="urm_report_";function ca(t,o){try{const n=`${Oi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){lr.error("urm:persistence","Failed to save report state",n)}}function da(t){try{const o=`${Oi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return lr.error("urm:persistence","Failed to load report state",o),null}}function So(t,o,n=0){const i=[];for(const s of t){const d=o.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:d}),!d&&s.children&&s.children.length>0){const c=s.children[0];if(ua(c)){const l=s.children,p=So(l,o,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 ua(t){return t&&typeof t=="object"&&"key"in t&&"level"in t&&"column"in t&&"value"in t&&"rowCount"in t&&"aggregates"in t&&"children"in t}function ln(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function cn(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),d=String(n.getDate()).padStart(2,"0"),c=`${i}-${s}-${d}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${c}.${o}`}function mo(t,o,n,i,s,d,c){let l,p;d?(l={...d},p=c||o.map(m=>m.name)):s?(l={...s.snapshot.columnVisibility},p=c||[...s.snapshot.columnOrder]):(l={},p=[],o.forEach(m=>{l[m.name]=!0,p.push(m.name)}));const f=Object.entries(l).filter(([m,h])=>!h).map(([m,h])=>m);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:p,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:f,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function ho(t,o="export",n){const{data:i,columnOrder:s,grouping:d}=t,c=s.filter(h=>t.columnVisibility[h]);let l;if(d&&d.enabled){const h=d.collapsedGroups??[],x=So(i,h);l=ln(x)}else l=i;const p=c.join(","),f=l.map(h=>c.map(x=>{const b=h[x];if(b==null)return"";const E=String(b);return E.includes(",")||E.includes('"')||E.includes(`
|
|
2
|
-
`)?`"${
|
|
3
|
-
`);$i(m,cn(o,"csv"),"text/csv;charset=utf-8;")}function fo(t,o="export",n){const{data:i,columnOrder:s,grouping:d}=t,c=s.filter(h=>t.columnVisibility[h]);let l;if(d&&d.enabled){const h=d.collapsedGroups??[],x=So(i,h);l=ln(x)}else l=i;const p=[c,...l.map(h=>c.map(x=>h[x]??""))],f=ro.utils.aoa_to_sheet(p),m=ro.utils.book_new();ro.utils.book_append_sheet(m,f,"Data"),ro.writeFile(m,cn(o,"xlsx"))}function go(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:d,viewMeta:c,hiddenColumns:l,columnOrder:p,grouping:f}=t;let m;if(f&&f.enabled){const b=f.collapsedGroups??[],E=So(i,b);m=ln(E)}else m=i;const h={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(c==null?void 0:c.name)||"Default View",filters:s.map(b=>({field:b.column,operator:b.operator,value:b.value})),sortStack:d.map(b=>({field:b.column,direction:b.direction,priority:b.priority})),grouping:f||{},hiddenColumns:l,columnOrder:p,exportConfig:n||{scope:"visible"}},data:m},x=JSON.stringify(h,null,2);$i(x,cn(o,"json"),"application/json;charset=utf-8;")}function $i(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),d=document.createElement("a");d.href=s,d.download=o,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(s)}const Bn=10;function pa(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(d=>d.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],s.length>Bn&&(s=[...s].sort((c,l)=>c.isFavourite&&!l.isFavourite?-1:!c.isFavourite&&l.isFavourite?1:l.lastUsed-c.lastUsed).slice(0,Bn)),s}function xa(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ma(t,o){return t.filter(n=>n.query!==o)}function ha(t){const o=t.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...o,...n]}const fa={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 ga(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function ft(t,o){return fa[o].includes(t)}function gt(t){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"}[t]||"perform this action"}.`}function ya(t){return t==="viewer"}const En=1e3;function rn(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function vt(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return rn(n)}const ba={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 Go(t){if(!t||!t.column)return"a filter";const o=vt(t.column),n=ba[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function Dn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${vt(n.column)}"`).join(", ")}`}function va(t){var s,d,c;const{action:o,previousState:n,newState:i}=t;switch(o){case"filter_added":{const l=i&&Array.isArray(i)?i[i.length-1]:i;return{summary:`Filter added: ${Go(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Go(n)}`};case"filter_updated":{const l=n,p=i;return(l==null?void 0:l.column)!==(p==null?void 0:p.column)?{summary:`Filter changed on "${vt(p==null?void 0:p.column)}"`,detail:`Previously filtered "${vt(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Go(p)}`}}case"filter_cleared":{const l=Array.isArray(n)?n.length: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?vt(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?vt(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: ${Dn(i)}`};case"group_level_removed":{const l=n,p=(d=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&d.column?vt(l.levels[0].column):"";return{summary:p?`Group level removed: "${p}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${Dn(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: "${vt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${vt(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: "${vt(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":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",p=i==null?void 0:i.rowCount,f=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",m=(i==null?void 0:i.viewName)??"",h=typeof p=="number"?` (${p.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${h}`,detail:m?`${rn(f)} · View: "${m}"`:rn(f)}}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:ja(o)}}}function Sa(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ai(t,o,n,i,s,d){return{id:Sa(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:d}}function Mi(t,o){const n=[o,...t];return n.length>En?n.slice(0,En):n}function ja(t){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",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[t]||t}function Ca(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function wa(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),d=Math.floor(i/36e5),c=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:d<24?`${d} hour${d>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const On=100;function ka(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ta(t){var d;const o=(d=t.views)==null?void 0:d.find(c=>c.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],s=Di(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:s,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function za(t,o,n,i){return{id:ka(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function Ia(t,o){const n=t||[];if(n.length>=On)throw new Error(`Maximum of ${On} presets reached. Please delete old presets first.`);return[...n,o]}function Ba(t,o){return(t||[]).filter(i=>i.id!==o)}function $n(t,o){if(t)return t.find(n=>n.id===o)}function Ea(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Da(t){const o=t.columnOrder,n=Nr(o,t.grouping);return{filters:t.filters.length>0?[...t.filters]:void 0,sortStack:t.sortStack.length>0?[...t.sortStack]:void 0,columnVisibility:{...t.columnVisibility},columnOrder:n,columnWidths:{...t.columnWidths},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Oa(t,o){return{totalRows:t.length,totalColumns:o.length}}function Et(t,o,n,i){const s=n instanceof Error?n.message:n,d={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:$a(t,o)};return process.env.NODE_ENV==="development"&&lr.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),d}function $a(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Aa(t){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"}[t.context]||"An error occurred";return t.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function Ma(t){return{filters:t.filters?[...t.filters]:void 0,sortStack:t.sortStack?[...t.sortStack]:void 0,grouping:t.grouping?{...t.grouping}:void 0,columnVisibility:t.columnVisibility?{...t.columnVisibility}:void 0,columnOrder:t.columnOrder?[...t.columnOrder]:void 0,columnWidths:t.columnWidths?{...t.columnWidths}:void 0,activeViewId:t.activeViewId}}function Ra(t,o,n){n(t.id,{filters:o.filters,sortStack:o.sortStack,grouping:o.grouping,columnVisibility:o.columnVisibility,columnOrder:o.columnOrder,columnWidths:o.columnWidths,activeViewId:o.activeViewId})}function _a(t,o,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(o)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:t==="number"&&["gt","gte","lt","lte","equals"].includes(o)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:t==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function Ri(t,o){const n=[],i=[],s=new Set(o.map(d=>d.name));return t.forEach(d=>{s.has(d.column)?n.push(d):i.push(d.column)}),{validRules:n,invalidColumns:i}}function _i(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(d=>d.name)),i=[],s=[];return t.levels.forEach(d=>{n.has(d.column)?i.push(d):s.push(d.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...t,levels:i},invalidColumns:s}}function Wa(t,o){const n=[],i=new Set(o.map(d=>d.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const d=s.filters.filter(c=>{const l=i.has(c.column);return l||n.push(`Filter for column "${c.column}" ignored (column not found)`),l});s.filters=d.length>0?d:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:d,invalidColumns:c}=Ri(s.sortStack,o);c.length>0&&n.push(`Sort rules for columns ignored: ${c.join(", ")}`),s.sortStack=d.length>0?d:void 0}if(s.grouping){const{validGrouping:d,invalidColumns:c}=_i(s.grouping,o);c.length>0&&n.push(`Grouping for columns ignored: ${c.join(", ")}`),s.grouping=d}if(s.columnVisibility){const d={};Object.entries(s.columnVisibility).forEach(([c,l])=>{i.has(c)?d[c]=l:n.push(`Column visibility for "${c}" ignored (column not found)`)}),s.columnVisibility=Object.keys(d).length>0?d:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const d=s.columnOrder.filter(c=>{const l=i.has(c);return l||n.push(`Column "${c}" in order ignored (column not found)`),l});s.columnOrder=d.length>0?d:void 0}if(s.columnWidths){const d={};Object.entries(s.columnWidths).forEach(([c,l])=>{i.has(c)?d[c]=l:n.push(`Column width for "${c}" ignored (column not found)`)}),s.columnWidths=Object.keys(d).length>0?d:void 0}return{sanitizedConfig:s,warnings:n}}function Pa(t,o){return Et("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function An(t,o,n,i){const s=Ai(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Mi(i||[],s)}function La(t){return t==null}function Na(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(La(t))return!1;switch(n){case"equals":return String(t)===String(i);case"contains":return String(t).toLowerCase().includes(String(i).toLowerCase());case"startsWith":return String(t).toLowerCase().startsWith(String(i).toLowerCase());case"endsWith":return String(t).toLowerCase().endsWith(String(i).toLowerCase());case"gt":return Number(t)>Number(i);case"lt":return Number(t)<Number(i);case"gte":return Number(t)>=Number(i);case"lte":return Number(t)<=Number(i);case"isTrue":return t===!0;case"isFalse":return t===!1;default:return!0}}function Fa(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Na(n[i.column],i)))}function Mn(t){switch(t){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"mixed":case"null":case"array":case"object":default:return[]}}function oo(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Va({data:t,filters:o}){return{filteredData:u.useMemo(()=>!o||o.length===0?t:Fa(t,o),[t,o])}}function Ha(t,o,n,i){if(!n||n.trim()==="")return t;const s=n.toLowerCase().trim(),d=o.filter(c=>i.includes(c.name));return t.filter(c=>d.some(l=>{const p=c[l.name];return p==null?!1:String(p).toLowerCase().includes(s)}))}function Ua({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:u.useMemo(()=>!o||o.trim()===""?t:Ha(t,n,o,i),[t,o,n,i])}}function Ga({data:t,sortStack:o,schema:n}){return{sortedData:u.useMemo(()=>!o||o.length===0?t:Qs(t,n,o),[t,o,n])}}function Ya({data:t,grouping:o,schema:n}){const i=u.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:oa(t,n,o),[t,o,n]),s=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function qa({schema:t,columnVisibility:o,columnOrder:n}){const i=u.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),s=u.useMemo(()=>Object.entries(o).filter(([l,p])=>!p).map(([l,p])=>l),[o]),d=u.useMemo(()=>n.map(l=>t.find(f=>f.name===l)||{name:l,type:"string"}),[n,t]),c=u.useMemo(()=>i.map(l=>t.find(f=>f.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:d,visibleColumnSchemas:c,hiddenCount:s.length}}function Ja({views:t,activeViewId:o,currentState:n}){const i=u.useMemo(()=>t.find(f=>f.id===o),[t,o]),s=u.useMemo(()=>i?sa(n,i.snapshot):!1,[i,n]),d=u.useMemo(()=>t.find(f=>f.isDefault),[t]),c=u.useMemo(()=>t.filter(f=>!f.isDefault&&!f.isDeleted),[t]),l=u.useMemo(()=>t.filter(f=>f.isFavorite&&!f.isDeleted),[t]),p=u.useMemo(()=>t.filter(f=>f.isDeleted),[t]);return{activeView:i,isDirty:s,defaultView:d,customViews:c,favoriteViews:l,deletedViews:p,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function Ka({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,d]=u.useState(i),c=t.length,l=Math.ceil(c/n),p=u.useMemo(()=>{if(!o)return t;const b=(s-1)*n,E=b+n;return t.slice(b,E)},[t,o,s,n]),f=u.useCallback(b=>{const E=Math.max(1,Math.min(b,l));d(E)},[l]),m=u.useCallback(()=>{s<l&&d(s+1)},[s,l]),h=u.useCallback(()=>{s>1&&d(s-1)},[s]),x=u.useCallback(()=>{d(1)},[]);return{paginatedData:p,currentPage:s,totalPages:l,pageSize:n,totalRows:c,goToPage:f,nextPage:m,prevPage:h,resetPage:x,hasNextPage:s<l,hasPrevPage:s>1}}function Xa(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:d,searchQuery:c,columnVisibility:l,columnOrder:p,columnWidths:f,views:m,activeViewId:h,pagination:x}=t,b=u.useMemo(()=>({filters:i,sortStack:s,grouping:d,columnVisibility:l,columnOrder:p,columnWidths:f}),[i,s,d,l,p,f]),E=Ja({views:m,activeViewId:h,currentState:b}),g=qa({schema:n,columnVisibility:l,columnOrder:p}),{filteredData:j}=Va({data:o,filters:i}),{sortedData:k}=Ga({data:j,sortStack:s,schema:n}),{groupedData:v,isGrouped:C}=Ya({data:k,grouping:d,schema:n}),{searchedData:S}=Ua({data:v,searchQuery:c,schema:n,visibleColumns:g.visibleColumns}),w=Ka({data:S,enabled:(x==null?void 0:x.enabled)||!1,pageSize:(x==null?void 0:x.pageSize)||100,initialPage:(x==null?void 0:x.currentPage)||1}),a=x!=null&&x.enabled?w.paginatedData:S,I=u.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:k.length,groupedRows:C?v.length:k.length,searchedRows:S.length,visibleRows:a.length,hiddenColumns:g.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:C}),[o.length,j.length,k.length,v.length,S.length,a.length,g.hiddenCount,i.length,s.length,C]);return{data:a,filteredData:j,sortedData:k,groupedData:v,searchedData:S,viewEngine:E,columnEngine:g,paginationEngine:w,metrics:I,isGrouped:C,isPaginated:(x==null?void 0:x.enabled)||!1}}let Qa=0;function Za(t){t!==null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Qa++,writable:!1,enumerable:!1,configurable:!1})}const yt="user-demo-001";function el(t={}){var yn,bn,vn,Sn,jn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:d,sharedReportId:c,config:l={}}=t,[p,f]=u.useState([]),m=dr(),[h,x]=u.useState(""),[b,E]=u.useState(!1),[g,j]=u.useState(!1),[k,v]=u.useState({message:"",severity:"info",open:!1}),C=(T,$="info")=>{v({message:T,severity:$,open:!0})},S=()=>v(T=>({...T,open:!1})),w=l.notifDurationMs??2e3,a=p.find(T=>T.id===h),[I,R]=u.useState("idle"),[G,q]=u.useState(!1),[ee,y]=u.useState(!1),[M,W]=u.useState(!1),[V,X]=u.useState(!1),[ue,ce]=u.useState(!1),[F,O]=u.useState(!1),[H,re]=u.useState(void 0),[U,te]=u.useState(null),[se,ne]=u.useState(null),[P,ie]=u.useState(!1),[de,ae]=u.useState(!1),[ge,K]=u.useState(null),[Ee,Ue]=u.useState(!1),[it,St]=u.useState(!1),[et,xr]=u.useState({enabled:!1,levels:[],collapsedGroups:[]}),[jt,mr]=u.useState(""),[st,qt]=u.useState(""),[Me,at]=u.useState(new Set),[lt,tt]=u.useState(1),[Ve,At]=u.useState(15),[Er,hr]=u.useState(!1),[Jt,Kt]=u.useState(!1),[fr,gr]=u.useState(!1),[ct,Xt]=u.useState(null),[Ct,dt]=u.useState(!1),[Kr,Dr]=u.useState(null),[Ke,yr]=u.useState(null),Mt=u.useRef(null),Te=u.useMemo(()=>a?ga(a.permissions,yt):"owner",[a]),Or=ya(Te),Rt=u.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:Oa(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),ut=u.useCallback(()=>{a&&(Mt.current=Ma(a))},[a]),N=u.useCallback((T,$)=>{f(_=>_.map(A=>A.id===T?{...A,...$}:A))},[]),rt=u.useCallback(T=>{if(!a)return;yr(T);const $=An(a.id,yt,T,a.auditHistory||[]);N(a.id,{auditHistory:$}),C(T.message,"error"),T.recoverable&&Mt.current&&setTimeout(()=>{Ra(a,Mt.current,N),C("Previous state restored","success")},100)},[a,N]),be=u.useCallback((T,$,_,A)=>{if(!a)return;const Z=Ai(a.id,yt,T,$,_,A),J=a.auditHistory||[],he=Mi(J,Z);setTimeout(()=>{N(a.id,{auditHistory:he})},0)},[a,N]);u.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const T=Uo(a.schema);(()=>{try{const $=localStorage.getItem("urm_dev_config");return $?JSON.parse($):null}catch{return null}})(),N(a.id,{views:[T],activeViewId:T.id,filters:T.snapshot.filters,sortStack:T.snapshot.sortStack,columnVisibility:T.snapshot.columnVisibility,columnOrder:T.snapshot.columnOrder,columnWidths:T.snapshot.columnWidths,grouping:T.snapshot.grouping})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,N]),u.useEffect(()=>{if(i&&n&&!g&&p.length===0){const T=co(i),$={id:`auto-report-${Date.now()}`,name:d||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:T,schema:Rr(T),permissions:{owner:yt,editors:[],viewers:[]}};f([$]),x($.id),j(!0),R("confirmed")}},[i,n,g,p.length,o,d]),u.useEffect(()=>{if(!s||g)return;let T=!1,$=null;const _=async()=>{try{R("uploading");let A;if(s.type==="api"){const J=await fetch(s.url,{headers:s.headers||{}});if(!J.ok)throw new Error(`HTTP ${J.status}: ${J.statusText}`);A=await J.json()}else A=await s.fetch();if(T)return;if(!Array.isArray(A))throw new Error("Data source must return an array of objects");const Z=Rr(A);if(g)f(J=>J.map(he=>he.id===h?{...he,uploadedData:A}:he)),R("confirmed");else{const J={id:`auto-report-${Date.now()}`,name:d||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:co(A),schema:Rr(co(A)),permissions:{owner:yt,editors:[],viewers:[]}};f([J]),x(J.id),j(!0),R("confirmed")}}catch(A){T||(R("error"),a&&N(a.id,{uploadError:(A==null?void 0:A.message)||"Failed to load data from source"}))}};return _(),s.refreshInterval&&s.refreshInterval>0&&($=setInterval(_,s.refreshInterval)),()=>{T=!0,$&&clearInterval($)}},[s,d,o]);const Fe=(yn=a==null?void 0:a.views)==null?void 0:yn.find(T=>T.id===a.activeViewId),Qt=u.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(Za),a.uploadedData):[],[a==null?void 0:a.uploadedData]),_t=Xa({rawData:Qt,schema:(a==null?void 0:a.schema)||[],filters:(a==null?void 0:a.filters)||[],sortStack:(a==null?void 0:a.sortStack)||[],grouping:(a==null?void 0:a.grouping)||null,searchQuery:st||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Fe==null?void 0:Fe.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Fe==null?void 0:Fe.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Fe==null?void 0:Fe.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:Ve,currentPage:lt}}),{data:br=[],searchedData:Wt=[],groupedData:Pt=[],metrics:$r={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Zt=!1,paginationEngine:ze}=_t||{},Q=((bn=_t.viewEngine)==null?void 0:bn.activeView)||Fe,fe=((vn=_t.viewEngine)==null?void 0:vn.isDirty)||!1;u.useEffect(()=>{if(!(!Q||!a)&&!a.columnOrder){const T=Q.snapshot.columnOrder,$=Nr(T,Q.snapshot.grouping);N(a.id,{columnOrder:$})}},[a==null?void 0:a.activeViewId]);const me=u.useMemo(()=>!(a!=null&&a.schema)||!Q?null:ia(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,Q.snapshot.columnOrder),[a==null?void 0:a.filters,a==null?void 0:a.sortStack,a==null?void 0:a.schema,a==null?void 0:a.columnVisibility,a==null?void 0:a.columnOrder,a==null?void 0:a.columnWidths,a==null?void 0:a.grouping,Q]),vr=u.useMemo(()=>!Q||!me||!fe?[]:la(me,Q.snapshot),[Q,me,fe]),Xe=u.useCallback((T,$,_)=>{const A={id:`report-${Date.now()}`,name:T,description:$,schemaLocked:!1,permissions:{owner:yt,editors:[],viewers:[]}};if(_&&Array.isArray(_)&&_.length>0){const Z=Rr(_),J=Uo(Z);A.uploadedData=_,A.schema=Z,A.schemaLocked=!0,A.views=[J],A.activeViewId=J.id,A.sortStack=J.snapshot.sortStack,A.filters=J.snapshot.filters,A.columnVisibility=J.snapshot.columnVisibility,A.columnOrder=J.snapshot.columnOrder,A.columnWidths=J.snapshot.columnWidths,A.grouping=J.snapshot.grouping}f(Z=>[...Z,A]),x(A.id),E(!1),R("confirmed")},[]),Lt=u.useCallback(T=>{a&&(R("uploading"),setTimeout(()=>{const $=Rr(T);N(a.id,{uploadedData:T,schema:$,uploadError:void 0}),R("preview")},500))},[a,N]),pt=u.useCallback(T=>{a&&(N(a.id,{uploadError:T}),R("idle"))},[a,N]),er=u.useCallback(()=>{a&&(N(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),R("idle"))},[a,N]),Sr=u.useCallback(()=>{a&&(N(a.id,{schemaLocked:!0}),R("confirmed"))},[a,N]),ot=u.useCallback(T=>{if(!a)return;if(!ft("edit_sorting",Te)){C(gt("edit_sorting"),"error");return}const $=a.sortStack??[],_=$.find(A=>A.column===T);if(_){const A=Zs(_.direction);if(A===null){const Z=$.filter(J=>J.column!==T).map((J,he)=>({...J,priority:he+1}));N(a.id,{sortStack:Z.length>0?Z:void 0})}else{const Z=A,J=$.map(he=>he.column===T?{...he,direction:Z}:he);N(a.id,{sortStack:J})}}else{if($.length>=m.sort.maxLevels){C(`Sort limit reached — maximum ${m.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const A={column:T,direction:"asc",priority:$.length+1};N(a.id,{sortStack:[...$,A]})}},[a,Te,N]),He=u.useCallback(T=>{if(a)if(a.schema){const{validRules:$,invalidColumns:_}=Ri(T,a.schema);_.length>0&&C(`Removed invalid sort columns: ${_.join(", ")}`),ut();try{N(a.id,{sortStack:$.length>0?$:void 0})}catch(A){const Z=Et("processing","sorting",A);rt(Z)}}else N(a.id,{sortStack:T.length>0?T:void 0})},[a,N,ut,rt]),xt=u.useCallback(T=>{if(!a)return;const $=a.sortStack??[],_=$.find(A=>A.column===T);if(!(_&&_.direction==="asc"))if(_){const A=$.map(Z=>Z.column===T?{...Z,direction:"asc"}:Z);N(a.id,{sortStack:A})}else{if($.length>=m.sort.maxLevels){C(`Sort limit reached — maximum ${m.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const A={column:T,direction:"asc",priority:$.length+1};N(a.id,{sortStack:[...$,A]})}},[a,N]),mt=u.useCallback(T=>{if(!a)return;const $=a.sortStack??[],_=$.find(A=>A.column===T);if(!(_&&_.direction==="desc"))if(_){const A=$.map(Z=>Z.column===T?{...Z,direction:"desc"}:Z);N(a.id,{sortStack:A})}else{if($.length>=m.sort.maxLevels){C(`Sort limit reached — maximum ${m.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const A={column:T,direction:"desc",priority:$.length+1};N(a.id,{sortStack:[...$,A]})}},[a,N]),tr=u.useCallback(T=>{var _;if(!a)return;if(!ft("edit_filters",Te)){C(gt("edit_filters"),"error");return}const $=(_=a.schema)==null?void 0:_.find(A=>A.name===T.column);if($&&T.value!==void 0){const A=_a($.type,T.operator,T.value);if(!A.isValid){C(A.errorMessage||"Invalid filter value","error");return}}ut();try{const A=a.filters??[];be("filters","filter_added",A,[...A,T]),N(a.id,{filters:[...A,T]})}catch(A){const Z=Et("processing","filters",A);rt(Z)}},[a,Te,N,ut,rt,be]),Nt=u.useCallback((T,$)=>{if(!a)return;if(!ft("edit_filters",Te)){C(gt("edit_filters"),"error");return}const _=a.filters??[],A=[..._];be("filters","filter_updated",_[T],$),A[T]=$,N(a.id,{filters:A})},[a,Te,N,be]),jr=u.useCallback(T=>{if(!a)return;if(!ft("edit_filters",Te)){C(gt("edit_filters"),"error");return}const $=a.filters??[],_=$.filter((A,Z)=>Z!==T);be("filters","filter_removed",$[T],null),N(a.id,{filters:_.length>0?_:void 0})},[a,Te,N,be]),Ft=u.useCallback(()=>{if(!a)return;if(!ft("edit_filters",Te)){C(gt("edit_filters"),"error");return}const T=a.filters??[];be("filters","filter_cleared",T,null),N(a.id,{filters:void 0})},[a,Te,N,be]),rr=u.useCallback(T=>{if(!a)return;if(!ft("edit_filters",Te)){C(gt("edit_filters"),"error");return}const $=a.filters??[];be("filters","filter_cleared",$,T),N(a.id,{filters:T.length>0?T:void 0})},[a,Te,N,be]),Ar=u.useCallback(T=>{var Z;if(!a)return;const $=(Z=a.views)==null?void 0:Z.find(J=>J.id===T);if(!$)return;const _=$.snapshot.columnOrder,A=Nr(_,$.snapshot.grouping);N(a.id,{filters:$.snapshot.filters.length>0?[...$.snapshot.filters]:void 0,sortStack:$.snapshot.sortStack.length>0?[...$.snapshot.sortStack]:void 0,columnVisibility:{...$.snapshot.columnVisibility},columnOrder:A,columnWidths:{...$.snapshot.columnWidths},grouping:$.snapshot.grouping,activeViewId:T}),at(new Set),W(!1)},[a,N]),wt=u.useCallback((T,$,_)=>{var Cn;if(!(a!=null&&a.schema)||!me)return;const A=a.views??[],Z=A.filter(Ho=>!Ho.isDeleted).length,J=((Cn=m.views)==null?void 0:Cn.maxViews)??10;if(Z>=J){C(`View limit reached — you can have at most ${J} saved views. Delete an existing view to create a new one.`,"error");return}const he={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:T,description:$||void 0,isDefault:_,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:yt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...me}},Ie=_?A.map(Ho=>({...Ho,isDefault:!1})):A;N(a.id,{views:[...Ie,he],activeViewId:he.id}),C(`"${T}" view created`,"success")},[a,me,N]),ht=u.useCallback(()=>{var $;if(!Q||!me||!a)return;const T=($=a.views)==null?void 0:$.map(_=>_.id===Q.id?{..._,snapshot:{...me}}:_);N(a.id,{views:T}),C(`"${Q.name}" view updated`,"success")},[Q,me,a,N]),Cr=u.useCallback(T=>{var A;if(!Q||!me||!a)return;const $=T??me.columnWidths,_=(A=a.views)==null?void 0:A.map(Z=>Z.id===Q.id?{...Z,snapshot:{...Z.snapshot,columnVisibility:me.columnVisibility,columnOrder:me.columnOrder,columnWidths:$},updatedAt:Date.now()}:Z);N(a.id,{views:_,columnWidths:$}),C(`Column configuration saved to "${Q.name}"`,"success")},[Q,me,a,N]),Le=u.useCallback(T=>{var J,he;if(!me||!a||!Q)return;const $=T??me.columnWidths,_={...Q,snapshot:{...Q.snapshot,columnVisibility:me.columnVisibility,columnOrder:me.columnOrder,columnWidths:$},updatedAt:Date.now()},A=(J=a.views)==null?void 0:J.map(Ie=>Ie.id===Q.id?_:{...Ie,snapshot:{...Ie.snapshot,columnVisibility:me.columnVisibility,columnOrder:me.columnOrder,columnWidths:$},updatedAt:Date.now()});N(a.id,{views:A,columnWidths:$});const Z=(((he=a.views)==null?void 0:he.length)||0)-1;C(`Column configuration saved to current view and ${Z} other view${Z===1?"":"s"}`,"success")},[me,a,Q,N]),kt=u.useCallback(()=>{X(!0)},[]),Tt=u.useCallback(()=>{if(!Q||!a)return;const T=Q.snapshot.columnOrder,$=Nr(T,Q.snapshot.grouping);N(a.id,{filters:Q.snapshot.filters.length>0?[...Q.snapshot.filters]:void 0,sortStack:Q.snapshot.sortStack.length>0?[...Q.snapshot.sortStack]:void 0,columnVisibility:{...Q.snapshot.columnVisibility},columnOrder:$,columnWidths:{...Q.snapshot.columnWidths},grouping:Q.snapshot.grouping}),C("Changes reverted to last saved state","success")},[Q,a,N]),nt=u.useCallback(T=>{if(!(a!=null&&a.views))return;const $=a.views.map(A=>({...A,isDefault:A.id===T}));N(a.id,{views:$});const _=a.views.find(A=>A.id===T);_&&C(`"${_.name}" set as default view`,"success")},[a,N]),or=u.useCallback(T=>{if(!(a!=null&&a.views))return;const $=a.views.map(A=>A.id===T?{...A,isFavorite:!A.isFavorite,updatedAt:Date.now()}:A);N(a.id,{views:$});const _=a.views.find(A=>A.id===T);_&&!_.isFavorite?C(`"${_.name}" added to favorites`,"success"):_&&C(`"${_.name}" removed from favorites`,"info")},[a,N]),zt=u.useCallback(T=>{if(!(a!=null&&a.views))return;const $=a.views.map(J=>J.id===T?{...J,isDeleted:!0,updatedAt:Date.now()}:J),_=a.activeViewId===T,A=$.find(J=>J.isDefault&&!J.isDeleted);N(a.id,{views:$,activeViewId:_&&A?A.id:a.activeViewId,filters:_&&A?A.snapshot.filters.length>0?A.snapshot.filters:void 0:a.filters,sortStack:_&&A?A.snapshot.sortStack.length>0?A.snapshot.sortStack:void 0:a.sortStack});const Z=a.views.find(J=>J.id===T);Z&&C(`"${Z.name}" moved to Recently Deleted`,"info")},[a,N]),le=u.useCallback(T=>{if(!(a!=null&&a.views))return;const $=a.views.map(A=>A.id===T?{...A,isDeleted:!1,updatedAt:Date.now()}:A);N(a.id,{views:$});const _=a.views.find(A=>A.id===T);_&&C(`"${_.name}" restored`,"success")},[a,N]),ye=u.useCallback(T=>{if(!(a!=null&&a.views))return;const $=a.views.find(Ie=>Ie.id===T),_=a.views.filter(Ie=>!Ie.isDeleted||Ie.id===T);if(($==null?void 0:$.isDefault)&&_.filter(Ie=>Ie.isDefault).length===1){C("Cannot delete the last default view","error");return}const Z=a.views.filter(Ie=>Ie.id!==T),J=a.activeViewId===T,he=Z.find(Ie=>Ie.isDefault&&!Ie.isDeleted);N(a.id,{views:Z,activeViewId:J&&he?he.id:a.activeViewId,filters:J&&he?he.snapshot.filters.length>0?he.snapshot.filters:void 0:a.filters,sortStack:J&&he?he.snapshot.sortStack.length>0?he.snapshot.sortStack:void 0:a.sortStack}),$&&C(`"${$.name}" permanently deleted`,"success")},[a,N]),Re=u.useCallback(T=>{te(T),ce(!0),W(!1)},[]),Vt=u.useCallback((T,$)=>{if(!U||!(a!=null&&a.views))return;const _=a.views.map(A=>A.id===U?{...A,name:T,description:$||void 0}:A);N(a.id,{views:_}),te(null)},[U,a,N]),Ht=u.useCallback(T=>{ne(T),O(!0),W(!1)},[]),_o=u.useCallback(()=>{if(!se||!(a!=null&&a.views))return;const T=a.views.filter(A=>A.id!==se),$=a.activeViewId===se,_=T.find(A=>A.isDefault);N(a.id,{views:T,activeViewId:$&&_?_.id:a.activeViewId,filters:$&&_?_.snapshot.filters.length>0?_.snapshot.filters:void 0:a.filters,sortStack:$&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:a.sortStack}),ne(null),O(!1)},[se,a,N]),Wo=u.useCallback(T=>{var Z;if(!(a!=null&&a.views))return;if(!(((Z=m.views)==null?void 0:Z.isAdmin)??!1)){C("Only administrators can promote views to Global.","error");return}const _=a.views.find(J=>J.id===T);if(!_)return;if(_.scope==="global"){C(`"${_.name}" is already a Global View.`,"info");return}const A=a.views.map(J=>J.id===T?{...J,scope:"global",isDefault:!0,updatedAt:Date.now()}:J.scope==="global"&&J.isDefault?{...J,isDefault:!1}:J);N(a.id,{views:A}),C(`"${_.name}" promoted to Global View and set as default.`,"success")},[a,m,N]);u.useEffect(()=>{ze!=null&&ze.resetPage?ze.resetPage():tt(1)},[a==null?void 0:a.filters,st,a==null?void 0:a.activeViewId]),u.useEffect(()=>{ze&&ze.currentPage!==lt&&tt(ze.currentPage)},[ze==null?void 0:ze.currentPage]);const Po=u.useCallback(T=>{ze!=null&&ze.goToPage&&ze.goToPage(T),tt(T)},[ze]),Lo=u.useCallback(T=>{const $=(lt-1)*Ve,_=Math.floor($/T)+1;At(T),tt(_),ze==null||ze.goToPage(_)},[lt,Ve,ze]),Xr=u.useCallback((T,$)=>{if(!a)return;if(!ft("edit_columns",Te)){C(gt("edit_columns"),"error");return}const A={...a.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{},[T]:$};N(a.id,{columnVisibility:A})},[a,Q,Te,N]),No=u.useCallback(T=>{if(a){if(!ft("edit_columns",Te)){C(gt("edit_columns"),"error");return}N(a.id,{columnOrder:T})}},[a,Te,N]),Fo=u.useCallback((T,$)=>{if(!a)return;if(!ft("edit_columns",Te)){C(gt("edit_columns"),"error");return}const A={...a.columnWidths||(Q==null?void 0:Q.snapshot.columnWidths)||{},[T]:$};N(a.id,{columnWidths:A})},[a,Q,Te,N]),We=u.useCallback(T=>{if(!a)return;const _=(a.filters??[]).filter(A=>A.column!==T);N(a.id,{filters:_.length>0?_:void 0})},[a,N]),It=u.useCallback(()=>{if(!Q||!(a!=null&&a.schema))return;const T={},$=[],_={};a.schema.forEach(A=>{T[A.name]=!0,$.push(A.name),_[A.name]=170}),N(a.id,{columnVisibility:T,columnOrder:$,columnWidths:_,filters:void 0,sortStack:void 0}),C("Reset to default layout - all filters and sorts cleared","success")},[Q,a,N]);u.useEffect(()=>{const T=setTimeout(()=>qt(jt),300);return()=>clearTimeout(T)},[jt]);const Qr=u.useCallback(T=>{mr(T)},[]),gn=u.useCallback(T=>{if(!T.trim()||!a)return;const $=a.searchHistory||[],_=pa($,T);N(a.id,{searchHistory:_})},[a,N]),Mr=u.useCallback(T=>{if(!a)return;const $=a.searchHistory||[],_=xa($,T);N(a.id,{searchHistory:_})},[a,N]),Vo=u.useCallback(T=>{if(!a)return;const $=a.searchHistory||[],_=ma($,T);N(a.id,{searchHistory:_})},[a,N]),Zr=u.useCallback(T=>{const $=T==null?void 0:T.__urm_row_id__;at(_=>{const A=new Set(_);if($!==void 0){const Z=Array.from(A).find(J=>(J==null?void 0:J.__urm_row_id__)===$);Z!==void 0?A.delete(Z):A.add(T)}else{const Z=JSON.stringify(T),J=Array.from(A).find(he=>JSON.stringify(he)===Z);J!==void 0?A.delete(J):A.add(T)}return A})},[]),eo=u.useCallback((T,$)=>{at(_=>{const A=new Set(_);for(const Z of $)T?A.add(Z):A.delete(Z);return A})},[]),D=u.useCallback((T,$,_)=>{at(A=>{const Z=new Set(A),J=Math.min(T,$),he=Math.max(T,$);for(let Ie=J;Ie<=he;Ie++)_[Ie]!==void 0&&Z.add(_[Ie]);return Z})},[]),Y=u.useCallback(()=>{at(new Set)},[]),pe=u.useCallback(T=>{const $=T==null?void 0:T.__urm_row_id__;at(_=>{const A=new Set(_);if($!==void 0){const Z=Array.from(A).find(J=>(J==null?void 0:J.__urm_row_id__)===$);Z!==void 0&&A.delete(Z)}else A.delete(T);return A})},[]),Ne=u.useCallback(T=>{if(a){if(!ft("edit_columns",Te)){C(gt("edit_columns"),"error");return}if(T&&a.schema){const{validGrouping:$,invalidColumns:_}=_i(T,a.schema);_.length>0&&C(`Removed invalid grouping columns: ${_.join(", ")}`,"warning"),ut();try{const A=a.grouping;$===null?be("grouping","group_cleared",A,null):A?be("grouping","group_reordered",A,$):be("grouping","group_level_added",null,$);const Z=(Q==null?void 0:Q.snapshot.columnOrder)||a.columnOrder||[],J=Nr(Z,$);N(a.id,{grouping:$,columnOrder:J}),JSON.stringify(J)!==JSON.stringify(a.columnOrder)&&be("columns","column_reordered",a.columnOrder,J),St(!1)}catch(A){const Z=Et("processing","grouping",A);rt(Z)}}else{const $=a.grouping;be("grouping","group_cleared",$,null);const _=(Q==null?void 0:Q.snapshot.columnOrder)||a.columnOrder||[];N(a.id,{grouping:T,columnOrder:[..._]}),JSON.stringify(_)!==JSON.stringify(a.columnOrder)&&be("columns","column_reordered",a.columnOrder,_),St(!1)}}},[a,Q,Te,N,ut,rt,be]),xe=u.useCallback(T=>{if(!a)return;const $=a.grouping;if(!$)return;const _=na($,T);N(a.id,{grouping:_})},[a,N]),nr=u.useCallback(()=>{dt(!0)},[]),ir=u.useCallback(T=>{a!=null&&a.schema&&(ie(!0),setTimeout(()=>{try{let $;T.scope==="visible"?$=Wt:$=a.uploadedData||[];let _;T.columnScope==="all"?(_={},(a.schema??[]).forEach(Ie=>{_[Ie.name]=!0})):_=a.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{};const A=a.columnOrder||(Q==null?void 0:Q.snapshot.columnOrder),Z=mo($,a.schema,a.filters??[],a.sortStack??[],Q,_,A),J=a.name;let he;switch(T.format){case"csv":ho(Z,J,T),he="export_csv";break;case"excel":fo(Z,J,T),he="export_excel";break;case"json":go(Z,J,T),he="export_json";break}be("export",he,null,{format:T.format,scope:T.scope,columnScope:T.columnScope,rowCount:$.length,viewName:(Q==null?void 0:Q.name)||"Default View"}),C(`Export completed successfully (${T.format.toUpperCase()})`,"success")}catch($){const _=Pa($,{onRetry:()=>ir(T)});C(`Export failed: ${_.message}. Click Export to retry.`,"error");const A=An(a.id,yt,_,a.auditHistory||[]);N(a.id,{auditHistory:A}),lr.error("urm:report-engine","Export failed",$)}finally{ie(!1)}},500))},[a,Q,Wt,N,be]),ms=u.useCallback(T=>{if(a!=null&&a.schema){if(fe&&Q&&!Q.isDefault){K(T.format),ae(!0),dt(!1);return}ir(T),dt(!1)}},[a,Q,fe,ir]),to=u.useCallback(T=>{ir({format:T,scope:"visible",columnScope:"visible"})},[ir]),hs=u.useCallback(()=>{ge&&to(ge),ae(!1),K(null)},[ge,to]),fs=u.useCallback(()=>{ht(),ge&&to(ge),ae(!1),K(null)},[ht,ge,to]),gs=u.useCallback(()=>{ae(!1),K(null)},[]),ys=u.useCallback(T=>{!(a!=null&&a.schema)||Me.size===0||(ie(!0),setTimeout(()=>{try{const $=Array.from(Me),_=mo($,a.schema,a.filters??[],a.sortStack??[],Q),A=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(T){case"csv":ho(_,A);break;case"excel":fo(_,A);break;case"json":go(_,A);break}C(`Exported ${$.length} selected rows`,"info")}catch($){C("Export failed. Please try again.","error"),lr.error("urm:report-engine","Bulk export failed",$)}finally{ie(!1)}},500))},[a,Q,Me,Pt]),bs=u.useCallback((T,$)=>{if(a)try{const _=Ta(a),A=za(T,$,yt,_),Z=Ia(a.presets,A);N(a.id,{presets:Z}),be("presets","preset_created",null,{presetId:A.id,name:A.name}),Kt(!1),C(`Preset "${T}" saved successfully`,"success")}catch(_){C(_ instanceof Error?_.message:"Failed to create preset","error")}},[a,N,be]),vs=u.useCallback(()=>{Xt(null),C("Exited preset view","info")},[]),Ss=u.useCallback(()=>{gr(!0)},[]),js=u.useCallback((T,$)=>{if(!a)return;const _=Ba(a.presets,T);N(a.id,{presets:_}),be("presets","preset_deleted",{presetId:T,name:$},null),ct===T&&Xt(null),C(`Preset "${$}" deleted`,"success")},[a,ct,N,be]);u.useEffect(()=>{if(!c||p.length===0)return;const T=p.find($=>$.id===c);T&&T.id!==h&&x(T.id)},[c,p,h]),u.useEffect(()=>{if(!a)return;const T=Ea();if(T&&a.presets&&a.schemaLocked&&a.schema){const $=$n(a.presets,T);if($){const{sanitizedConfig:_,warnings:A}=Wa($.config,a.schema);A.length>0&&A.forEach(J=>C(J,"warning"));const Z=Da(_);N(a.id,Z),Xt(T),be("presets","preset_applied",null,{presetId:$.id,name:$.name}),C(`Loaded preset: ${$.name}`,"info")}else C("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const Cs=ct?$n(a==null?void 0:a.presets,ct):void 0;u.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&ca(a.id,{views:a.views,activeViewId:a.activeViewId})},[a==null?void 0:a.views,a==null?void 0:a.activeViewId,a==null?void 0:a.id]),u.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const T=da(a.id);if(T&&T.views.length>0){const $=T.views.find(_=>_.id===T.activeViewId);if($)N(a.id,{views:T.views,activeViewId:T.activeViewId,filters:$.snapshot.filters.length>0?$.snapshot.filters:void 0,sortStack:$.snapshot.sortStack.length>0?$.snapshot.sortStack:void 0});else{const _=T.views.find(A=>A.isDefault)||Uo(a.schema);N(a.id,{views:T.views,activeViewId:_.id,filters:_.snapshot.filters.length>0?_.snapshot.filters:void 0,sortStack:_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const ws=u.useCallback(T=>{var A;const $=(a==null?void 0:a.filters)??[],_=((A=m.filter)==null?void 0:A.maxConditions)??3;if($.length>=_){C(`Filter limit reached — maximum ${_} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}re(T),q(!0)},[a,m,C]),ks=u.useCallback(()=>{q(!1),re(void 0)},[]),Ts=(Sn=a==null?void 0:a.views)==null?void 0:Sn.find(T=>T.id===U),zs=(jn=a==null?void 0:a.views)==null?void 0:jn.find(T=>T.id===se);return{reports:p,activeReport:a,activeReportId:h,setActiveReportId:x,isModalOpen:b,setIsModalOpen:E,createReport:Xe,updateReport:N,uploadState:I,handleFileUpload:Lt,handleUploadError:pt,handleRetry:er,handleConfirm:Sr,paginatedData:br,processedData:Wt,displayData:Pt,tableMetrics:$r,isGrouped:Zt,tableEngine:_t,activeView:Q,isDirty:fe,currentTableState:me,viewChanges:vr,filters:a==null?void 0:a.filters,showFilterPanel:G,setShowFilterPanel:q,filterFocusColumn:H,handleAddFilter:tr,handleUpdateFilter:Nt,handleRemoveFilter:jr,handleClearAllFilters:Ft,handleReplaceFilters:rr,handleOpenFilterForColumn:ws,handleCloseFilterPanel:ks,handleClearFiltersForColumn:We,sortStack:a==null?void 0:a.sortStack,showSortPanel:ee,setShowSortPanel:y,handleSort:ot,handleUpdateSortStack:He,handleSortAscending:xt,handleSortDescending:mt,views:a==null?void 0:a.views,showManageViews:M,setShowManageViews:W,showCreateViewModal:V,setShowCreateViewModal:X,showEditViewModal:ue,setShowEditViewModal:ce,showDeleteConfirmation:F,setShowDeleteConfirmation:O,editingView:Ts,deletingView:zs,editingViewId:U,deletingViewId:se,handleSelectView:Ar,handleCreateView:wt,handleUpdateCurrentView:ht,handleSaveColumnConfigToCurrentView:Cr,handleSaveColumnConfigToAllViews:Le,handleSaveAsNewView:kt,handleRevertChanges:Tt,handleToggleDefault:nt,handleToggleFavorite:or,handleSoftDelete:zt,handleRestoreView:le,handlePermanentDelete:ye,handleEditView:Re,handleSaveEditView:Vt,handleDeleteView:Ht,handleConfirmDelete:_o,handlePromoteToGlobal:Wo,showManageColumns:Ee,setShowManageColumns:Ue,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:Xr,handleUpdateColumnOrder:No,handleUpdateColumnWidth:Fo,handleResetColumnLayout:It,showGroupPanel:it,setShowGroupPanel:St,grouping:a==null?void 0:a.grouping,groupingState:et,handleGroup:Ne,handleToggleGroupCollapse:xe,searchQuery:jt,debouncedSearchQuery:st,searchHistory:ha((a==null?void 0:a.searchHistory)||[]),handleSearchChange:Qr,handleAddToSearchHistory:gn,handleToggleSearchFavourite:Mr,handleDeleteSearchHistory:Vo,selectedRowIds:Me,handleToggleRowSelection:Zr,handleToggleAllRows:eo,handleRangeSelection:D,handleClearSelection:Y,handleUpdateSelectionAfterDelete:pe,currentPage:lt,pageSize:Ve,paginationEngine:ze,handlePageChange:Po,handlePageSizeChange:Lo,isExporting:P,showExportModal:Ct,setShowExportModal:dt,showDirtyExportWarning:de,handleExport:nr,handleExportWithConfig:ms,handleExportSelected:ys,handleExportAnyway:hs,handleSaveAndExport:fs,handleCancelExport:gs,showAuditHistory:Er,setShowAuditHistory:hr,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:Jt,setShowCreatePreset:Kt,showManagePresets:fr,setShowManagePresets:gr,activePreset:Cs,activePresetId:ct,handleOpenManagePresets:Ss,handleCreatePreset:bs,handleClearActivePreset:vs,handleDeletePresetById:js,userRole:Te,isViewerRole:Or,currentUserId:yt,featureLimitWarning:Kr,setFeatureLimitWarning:Dr,datasetMeta:Rt,reportError:Ke,setReportError:yr,handleError:rt,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?Ks(a.schema):!1,snack:k,handleSnackClose:S,showSnack:C,snackDurationMs:w}}const Wi=u.createContext(void 0);function dn(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:d,mode:c="builder",autoLoad:l=!0,config:p,devConfig:f,showDevPanel:m=!1,sharedReportId:h}=t,b=el({mode:c,autoLoad:l,initialData:i||n,dataSource:d,reportName:s,sharedReportId:h,config:p}),[E,g]=u.useState(()=>Os()),j=(()=>{const S=As(E,f,!!f);return{...S,display:{...S.display,showDevPanel:m||S.display.showDevPanel}}})(),k=u.useCallback(C=>{g(C),$s(C)},[]),v={...b,activeDevConfig:j,handleDevConfigChange:k};return e.jsx(ki.Provider,{value:j,children:e.jsx(Wi.Provider,{value:v,children:o})})}function jo(){const t=u.useContext(Wi);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function tl({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const s=o.find(d=>d.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(B.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",color:"text.primary",letterSpacing:"-0.01em",cursor:o.length>0&&s?"pointer":"default","&:hover":o.length>0&&s?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),s&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(s.id),children:s.name}),e.jsx(r.Tooltip,{title:s.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(B.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:e.jsx(r.Button,{variant:"contained",startIcon:e.jsx(B.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function cr(t,...o){const n=new URL(`https://mui.com/production-error/?code=${t}`);return o.forEach(i=>n.searchParams.append("args[]",i)),`Minified MUI error #${t}; visit ${n} for the full message.`}const rl="$$material";function ol(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var no={exports:{}},io={exports:{}},ve={};/** @license React v16.13.1
|
|
1
|
+
"use strict";var Xs=Object.defineProperty;var Qs=(e,r,n)=>r in e?Xs(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var Kn=(e,r,n)=>Qs(e,typeof r!="symbol"?r+"":r,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),p=require("react"),Zs=require("xlsx"),T=require("@mui/icons-material"),o=require("@mui/material"),Vi=require("react-dom"),ea=require("@emotion/react"),Pt=require("react-dnd"),zn=require("react-dnd-html5-backend");function Hi(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 Do=Hi(p),po=Hi(Zs),Ke={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"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},Ui="urm_dev_config";function ta(){try{const e=localStorage.getItem(Ui);if(!e)return Ke;const r=JSON.parse(e),n={sort:{...Ke.sort,...r.sort},filter:{...Ke.filter,...r.filter},columns:{...Ke.columns,...r.columns},grouping:{...Ke.grouping,...r.grouping},export:{...Ke.export,...r.export},views:{...Ke.views,...r.views},dates:{...Ke.dates,...r.dates},display:{...Ke.display,...r.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ke}}function ra(e){try{localStorage.setItem(Ui,JSON.stringify(e))}catch{}}function oa(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 Gi=p.createContext(Ke);function Sr(){return p.useContext(Gi)}const na=/^\d{4}-\d{2}-\d{2}$/,ia=/^\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}$/,aa=9783072e5,la=41024448e5,ca=978307200,da=4102444800;function ua(e){return e==null||e===""?"unknown":typeof e=="number"?Number.isInteger(e)&&e>=aa&&e<=la?"timestamp_ms":Number.isInteger(e)&&e>=ca&&e<=da?"timestamp_s":"unknown":typeof e!="string"?"unknown":ia.test(e)||na.test(e)?"iso":sa.test(e.trim())?"locale_string":"unknown"}function pa(e,r){const n=r.map(d=>d[e]).filter(d=>d!=null&&d!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const d of n){const c=ua(d);i[c]++}const s=n.length,l=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/s>=l)return d;return"unknown"}function xa(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 Xn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ma=["January","February","March","April","May","June","July","August","September","October","November","December"];function _e(e){return String(e).padStart(2,"0")}function fa(e){const r=Date.now()-e.getTime(),n=Math.abs(r),i=r>0,s=Math.floor(n/1e3),l=Math.floor(s/60),d=Math.floor(l/60),c=Math.floor(d/24),u=Math.floor(c/7),m=Math.floor(c/30),f=Math.floor(c/365);let x;return s<60?x="just now":l<60?x=`${l} minute${l!==1?"s":""}`:d<24?x=`${d} hour${d!==1?"s":""}`:c<7?x=`${c} day${c!==1?"s":""}`:u<5?x=`${u} week${u!==1?"s":""}`:m<12?x=`${m} month${m!==1?"s":""}`:x=`${f} year${f!==1?"s":""}`,s<60?x:i?`${x} ago`:`in ${x}`}function ha(e,r){const n=e.getFullYear(),i=e.getMonth(),s=e.getDate(),l=e.getHours(),d=e.getMinutes();switch(r){case"YYYY-MM-DD":return`${n}-${_e(i+1)}-${_e(s)}`;case"DD/MM/YYYY":return`${_e(s)}/${_e(i+1)}/${n}`;case"MM/DD/YYYY":return`${_e(i+1)}/${_e(s)}/${n}`;case"MMM DD, YYYY":return`${Xn[i]} ${_e(s)}, ${n}`;case"DD MMM YYYY":return`${_e(s)} ${Xn[i]} ${n}`;case"MMMM D, YYYY":return`${ma[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${_e(i+1)}-${_e(s)} ${_e(l)}:${_e(d)}`;case"DD/MM/YYYY HH:mm":return`${_e(s)}/${_e(i+1)}/${n} ${_e(l)}:${_e(d)}`;case"MM/DD/YYYY HH:mm":return`${_e(i+1)}/${_e(s)}/${n} ${_e(l)}:${_e(d)}`;case"relative":return fa(e);case"locale":return e.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return e.toLocaleDateString()}}function ga(e,r,n){if(!n||r==="unknown")return String(e);const i=xa(e,r);return!i||isNaN(i.getTime())?String(e):ha(i,n)}function ya(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 Yi(e,r="",n=0){if(n>2)return{[r]:e};const i={};for(const s of Object.keys(e)){const l=r?`${r}.${s}`:s,d=e[s];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,Yi(d,l,n+1)):i[l]=d}return i}function bo(e){return e.map(r=>typeof r!="object"||r===null||Array.isArray(r)?r:Yi(r))}function Hr(e){if(!Array.isArray(e)||e.length===0)return[];const r=bo(e),n=new Set;r.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(c=>n.add(c))});const i=[];n.forEach(d=>{const c=new Set;let u=0;r.forEach(v=>{typeof v=="object"&&v!==null&&d in v&&(u++,c.add(ya(v[d])))});const m=u===r.length,f=c.size>1&&!c.has("null");let x="mixed";if(c.size===1)x=Array.from(c)[0];else if(c.size===2&&c.has("null")){const v=Array.from(c).filter(b=>b!=="null");v.length===1&&(x=v[0])}i.push({name:d,type:x,required:m,hasConflict:f})});const l=r.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const c=pa(d.name,l);c!=="unknown"&&(d.type="date",d.dateFormat=c)}return i}function ba(e){return e.some(r=>r.hasConflict)}function Qe(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 Qn(e){return e==null}function va(e){return(r,n,i)=>{const s=Qn(r),l=Qn(n);if(s&&l)return 0;if(s)return 1;if(l)return-1;let d=0;switch(e){case"number":const c=Number(r),u=Number(n);d=c-u;break;case"boolean":d=(r?1:0)-(n?1:0);break;case"string":d=String(r).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(r).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(r).localeCompare(String(n));break}return i==="asc"?d:-d}}function Sa(e,r,n){if(!n||n.length===0)return e;const i=[...n].sort((s,l)=>s.priority-l.priority);return[...e].sort((s,l)=>{for(const d of i){const c=r.find(f=>f.name===d.column);if(!c)continue;const m=va(c.type)(s[d.column],l[d.column],d.direction);if(m!==0)return m}return 0})}function Ca(e){return e===null?"asc":e==="asc"?"desc":null}function ja(e){return e==="string"||e==="boolean"}function wa(e){return e.filter(r=>ja(r.type))}function ka(e,r){const n={};return r.forEach(i=>{if(i.type==="number"){const s=e.map(l=>l[i.name]).filter(l=>typeof l=="number");s.length>0&&(n[i.name]=s.reduce((l,d)=>l+d,0))}}),n}function Ta(e,r,n){if(!n.enabled||n.levels.length===0)return e;const i=En(e,n.levels,r);return qi(i,n.collapsedGroups||[])}function En(e,r,n,i="",s=0){if(s>=r.length)return e;const l=r[s].column,d=new Map;e.forEach(m=>{const f=m[l],x=f==null?"(empty)":String(f);d.has(x)||d.set(x,[]),d.get(x).push(m)});const c=[];return Array.from(d.keys()).sort().forEach(m=>{const f=d.get(m),x=`${l}:${m}`,v=i?`${i}|${x}`:x,b=ka(f,n),z=s<r.length-1?En(f,r,n,v,s+1):f,S={key:v,level:s,column:l,value:m,rowCount:f.length,aggregates:b,children:z};c.push(S)}),c}function qi(e,r,n=[]){for(const i of e)if("key"in i&&"level"in i&&"children"in i){const s=r.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:s}),!s&&i.children&&qi(i.children,r,n)}else n.push(i);return n}function Ia(e,r,n){if(!n.enabled||n.levels.length===0)return[];const i=En(e,n.levels,r),s=[],l=d=>{for(const c of d)"key"in c&&"level"in c&&"children"in c&&(s.push(c.key),l(c.children))};return l(i),s}function za(e,r){const n=e.collapsedGroups||[],i=n.includes(r)?n.filter(s=>s!==r):[...n,r];return{...e,collapsedGroups:i}}function Ji(e,r){return e==null?"":typeof e=="number"?`Σ ${e.toLocaleString()}`:String(e)}function Ki(e,r,n){return`${r}: ${n}`}function Wr(){return`flt_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Re(e){return"children"in e}function St(){return{id:Wr(),operator:"and",children:[]}}function Oe(e){return e?Array.isArray(e)?{id:Wr(),operator:"and",children:e.map(r=>({...r,id:r.id??Wr()}))}:e:St()}function dt(e){return e?Re(e)?e.children.reduce((r,n)=>r+dt(n),0):1:0}function vo(e,r){if(e.id===r)return e;for(const n of e.children){if(n.id===r)return n;if(Re(n)){const i=vo(n,r);if(i)return i}}}function Pr(e,r,n){return e.id===r?{...e,children:[...e.children,n]}:{...e,children:e.children.map(i=>Re(i)?Pr(i,r,n):i)}}function Bn(e,r,n){return{...e,children:e.children.map(i=>i.id===r&&!Re(i)?{...i,...n}:Re(i)?Bn(i,r,n):i)}}function Dn(e,r,n){return e.id===r?{...e,operator:n}:{...e,children:e.children.map(i=>Re(i)?Dn(i,r,n):i)}}function On(e,r){const n=e.children.filter(i=>i.id!==r).map(i=>Re(i)?On(i,r):i).filter(i=>!Re(i)||i.children.length>0);return{...e,children:n}}function Sn(e,r){return e?Re(e)?e.children.some(n=>Sn(n,r)):e.column===r:!1}function Xi(e,r){const n=e.children.filter(i=>Re(i)||i.column!==r).map(i=>Re(i)?Xi(i,r):i).filter(i=>!Re(i)||i.children.length>0);return{...e,children:n}}function Qi(e){return e?Re(e)?e.children.flatMap(Qi):[e]:[]}function Zr(e){if(!e)return null;if(!Re(e)){const{id:i,...s}=e;return s}const{id:r,...n}=e;return{...n,children:e.children.map(Zr)}}function qr(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 $n(e,r,n){if(!r||!r.enabled||!r.levels||r.levels.length===0)return[...e];const i=r.levels.map(l=>l.column),s=e.filter(l=>!i.includes(l));if(n){const l=[],d=new Set(i),c=new Set(s);let u=0;for(const m of n)d.has(m)?l.push(m):c.has(m)&&u<s.length?(l.push(s[u]),u++):c.has(m)||l.push(m);for(let m=u;m<s.length;m++)l.includes(s[m])||l.push(s[m]);return l}return[...e]}function ln(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:St(),sortStack:[],columnVisibility:r,columnOrder:n,columnWidths:i,grouping:null}}}function Ea(e,r,n,i,s,l,d,c){const u={},m=[],f={};n.forEach(b=>{u[b.name]=!0,m.push(b.name),f[b.name]=170});const v=$n(s||m,d||null,c||m);return{filters:Oe(e),sortStack:r||[],columnVisibility:i||u,columnOrder:v,columnWidths:l||f,grouping:d||null}}function Ba(e,r){const n=b=>{if(b==null)return b;if(Array.isArray(b))return b.map(z=>n(z));if(typeof b=="object"){const z={};return Object.keys(b).sort().forEach(S=>{z[S]=n(b[S])}),z}return b},i=b=>JSON.stringify(n(b));if(i(Zr(e.filters))!==i(Zr(r.filters))||i(e.sortStack)!==i(r.sortStack))return!0;const s=e.columnVisibility??{},l=r.columnVisibility??{};if(i(s)!==i(l))return!0;const d=$n(e.columnOrder||[],e.grouping||null,r.columnOrder||[]),c=[...d].sort().join(","),u=[...r.columnOrder||[]].sort().join(",");if(c!==u)return!1;const m=[...r.columnOrder||[]].sort().join(",");if((r.columnOrder||[]).join(",")!==m){if(d.join(",")!==(r.columnOrder||[]).join(","))return!0}else{const b=[...d].sort().join(",");if(d.join(",")!==b)return!0}const x=e.columnWidths??{},v=r.columnWidths??{};return i(x)!==i(v)||i(e.grouping)!==i(r.grouping)}function Da(e){return!e||e.length===0?"None":e.sort((r,n)=>r.priority-n.priority).map(r=>`${r.column} ${r.direction==="asc"?"↑":"↓"}`).join(", ")}function Oa(e,r){var S,y,w;const n=[],i=JSON.stringify(Zr(e.filters)),s=JSON.stringify(Zr(r.filters));if(i!==s){const C=dt(e.filters),E=dt(r.filters);C>E?n.push({category:"filters",label:"Filters Added",description:`${C-E} new filter${C-E>1?"s":""} added`}):C<E?n.push({category:"filters",label:"Filters Removed",description:`${E-C} filter${E-C>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const l=JSON.stringify(e.sortStack),d=JSON.stringify(r.sortStack);if(l!==d){const C=e.sortStack.length,E=r.sortStack.length;C>E?n.push({category:"sorting",label:"Sorting Added",description:`${C-E} new sort rule${C-E>1?"s":""} added`}):C<E?n.push({category:"sorting",label:"Sorting Removed",description:`${E-C} sort rule${E-C>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const c=JSON.stringify(e.columnVisibility),u=JSON.stringify(r.columnVisibility);if(c!==u){const C=Object.values(e.columnVisibility).filter(g=>g).length,E=Object.values(r.columnVisibility).filter(g=>g).length;C>E?n.push({category:"visibility",label:"Columns Shown",description:`${C-E} column${C-E>1?"s":""} made visible`}):C<E?n.push({category:"visibility",label:"Columns Hidden",description:`${E-C} column${E-C>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const m=JSON.stringify(e.columnOrder),f=JSON.stringify(r.columnOrder);m!==f&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const x=JSON.stringify(e.columnWidths),v=JSON.stringify(r.columnWidths);if(x!==v){const C=Object.keys(e.columnWidths).filter(E=>e.columnWidths[E]!==r.columnWidths[E]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${C} column width${C>1?"s":""} modified`})}const b=JSON.stringify(e.grouping),z=JSON.stringify(r.grouping);if(b!==z){const C=(S=e.grouping)==null?void 0:S.enabled,E=(y=r.grouping)==null?void 0:y.enabled;if(C&&!E){const g=((w=e.grouping)==null?void 0:w.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${g} grouping level${g>1?"s":""} added`})}else!C&&E?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 Zn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function ei(e){return`[${e}]`}const Et={warn(e,r,...n){Zn()&&console.warn(ei(e),r,...n)},error(e,r,...n){Zn()&&console.error(ei(e),r,...n)}},Zi="urm_report_";function $a(e,r){try{const n=`${Zi}${e}`;localStorage.setItem(n,JSON.stringify(r))}catch(n){Et.error("urm:persistence","Failed to save report state",n)}}function Aa(e){try{const r=`${Zi}${e}`,n=localStorage.getItem(r);return n?JSON.parse(n):null}catch(r){return Et.error("urm:persistence","Failed to load report state",r),null}}function Oo(e,r,n=0){const i=[];for(const s of e){const l=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:l}),!l&&s.children&&s.children.length>0){const d=s.children[0];if(_a(d)){const c=s.children,u=Oo(c,r,n+1);i.push(...u)}else{const c=s.children;for(const u of c)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:u})}}}return i}function _a(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 _n(e,r){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),l=String(n.getDate()).padStart(2,"0"),d=`${i}-${s}-${l}`;return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${r}`}function wo(e,r,n,i,s,l,d){let c,u;l?(c={...l},u=d||r.map(f=>f.name)):s?(c={...s.snapshot.columnVisibility},u=d||[...s.snapshot.columnOrder]):(c={},u=[],r.forEach(f=>{c[f.name]=!0,u.push(f.name)}));const m=Object.entries(c).filter(([f,x])=>!x).map(([f,x])=>f);return{data:e,schema:r,appliedFilters:n,appliedSortStack:i,columnVisibility:c,columnOrder:u,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:m,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function ko(e,r="export",n){const{data:i,columnOrder:s,grouping:l}=e,d=s.filter(x=>e.columnVisibility[x]);let c;if(l&&l.enabled){const x=l.collapsedGroups??[],v=Oo(i,x);c=An(v)}else c=i;const u=d.join(","),m=c.map(x=>d.map(v=>{const b=x[v];if(b==null)return"";const z=String(b);return z.includes(",")||z.includes('"')||z.includes(`
|
|
2
|
+
`)?`"${z.replace(/"/g,'""')}"`:z}).join(",")),f=[u,...m].join(`
|
|
3
|
+
`);es(f,_n(r,"csv"),"text/csv;charset=utf-8;")}function To(e,r="export",n){const{data:i,columnOrder:s,grouping:l}=e,d=s.filter(x=>e.columnVisibility[x]);let c;if(l&&l.enabled){const x=l.collapsedGroups??[],v=Oo(i,x);c=An(v)}else c=i;const u=[d,...c.map(x=>d.map(v=>x[v]??""))],m=po.utils.aoa_to_sheet(u),f=po.utils.book_new();po.utils.book_append_sheet(f,m,"Data"),po.writeFile(f,_n(r,"xlsx"))}function Io(e,r="export",n){const{data:i,appliedFilters:s,appliedSortStack:l,viewMeta:d,hiddenColumns:c,columnOrder:u,grouping:m}=e;let f;if(m&&m.enabled){const b=m.collapsedGroups??[],z=Oo(i,b);f=An(z)}else f=i;const x={meta:{exportedAt:new Date().toISOString(),reportName:r,view:(d==null?void 0:d.name)||"Default View",filters:Qi(s).map(b=>({field:b.column,operator:b.operator,value:b.value})),sortStack:l.map(b=>({field:b.column,direction:b.direction,priority:b.priority})),grouping:m||{},hiddenColumns:c,columnOrder:u,exportConfig:n||{scope:"visible"}},data:f},v=JSON.stringify(x,null,2);es(v,_n(r,"json"),"application/json;charset=utf-8;")}function es(e,r,n){const i=new Blob([e],{type:n}),s=URL.createObjectURL(i),l=document.createElement("a");l.href=s,l.download=r,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(s)}const ti=10;function Ma(e,r){const n=r.trim();if(!n)return e;const i=e.findIndex(l=>l.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>ti&&(s=[...s].sort((d,c)=>d.isFavourite&&!c.isFavourite?-1:!d.isFavourite&&c.isFavourite?1:c.lastUsed-d.lastUsed).slice(0,ti)),s}function Ra(e,r){return e.map(n=>n.query===r?{...n,isFavourite:!n.isFavourite}:n)}function Wa(e,r){return e.filter(n=>n.query!==r)}function Pa(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 Na={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 La(e,r){return!e||e.owner===r?"owner":e.editors.includes(r)?"editor":(e.viewers.includes(r),"viewer")}function at(e,r){return Na[r].includes(e)}function lt(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 Fa(e){return e==="viewer"}const ri=1e3;function Cn(e){return e&&e.charAt(0).toUpperCase()+e.slice(1)}function zt(e){if(!e)return"";const n=e.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Cn(n)}const Va={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 Ha(e){if(!e||!e.column)return"a filter";const r=zt(e.column),n=Va[e.operator]??e.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(e.operator)?`"${r}" ${n}`:`"${r}" ${n} "${e.value}"`}function cn(e){return e?typeof e=="string"?e:"children"in e?"a condition group":Ha(e):"a filter"}function oi(e){return!e||!e.enabled||e.levels.length===0?"grouping removed":`grouped by ${e.levels.map(n=>`"${zt(n.column)}"`).join(", ")}`}function Ua(e){var s,l,d;const{action:r,previousState:n,newState:i}=e;switch(r){case"filter_added":return{summary:`Filter added: ${cn(i)}`};case"filter_removed":return{summary:`Filter removed: ${cn(n)}`};case"filter_updated":{if(typeof i=="string")return{summary:`Filter updated: ${i}`};const c=n,u=i;return c!=null&&c.column&&(u!=null&&u.column)&&c.column!==u.column?{summary:`Filter changed on "${zt(u.column)}"`,detail:`Previously filtered "${zt(c.column)}"`}:{summary:`Filter updated: ${cn(u)}`}}case"filter_cleared":{const c=n&&typeof n=="object"&&"count"in n?n.count:0;return{summary:c>0?`All filters cleared (${c} filter${c!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const c=i!=null&&i.column?zt(i.column):"",u=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:c?`Sort added: "${c}" ${u}`:"Sort level added"}}case"sort_level_removed":{const c=n!=null&&n.column?zt(n.column):"";return{summary:c?`Sort removed: "${c}"`:"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: ${oi(i)}`};case"group_level_removed":{const c=n,u=(l=(s=c==null?void 0:c.levels)==null?void 0:s[0])!=null&&l.column?zt(c.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${oi(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const c=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:c?`Column hidden: "${zt(c)}"`:"Column hidden"}}case"column_shown":{const c=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:c?`Column shown: "${zt(c)}"`:"Column made visible"}}case"column_reordered":{const c=Array.isArray(n)?n:[],u=Array.isArray(i)?i:[];return c.length>0&&u.length>0?{summary:"Column order changed",detail:`${u.length} column${u.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const c=(i==null?void 0:i.column)??"",u=(i==null?void 0:i.width)??"";return{summary:c?`Column resized: "${zt(c)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const c=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:c?`View created: "${c}"`:"New view created"}}case"view_updated":{const c=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:c?`View updated: "${c}"`:"View updated"}}case"view_deleted":{const c=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:c?`View deleted: "${c}"`:"View deleted"}}case"view_set_default":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Default view set to "${c}"`:"Default view changed"}}case"view_switched":{const c=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return c&&u?{summary:`Switched to view "${u}"`,detail:`From "${c}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const c=r==="export_csv"?"CSV":r==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,m=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",f=(i==null?void 0:i.viewName)??"",x=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${c}${x}`,detail:f?`${Cn(m)} · View: "${f}"`:Cn(m)}}case"export_triggered":{const c=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:c?`Export triggered: ${c}`:"Export triggered"}}case"preset_created":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Preset created: "${c}"`:"New preset created"}}case"preset_applied":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Preset applied: "${c}"`:"Preset applied"}}case"preset_deleted":{const c=(n==null?void 0:n.name)??"";return{summary:c?`Preset deleted: "${c}"`:"Preset deleted"}}case"preset_link_copied":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Preset link copied: "${c}"`:"Preset link copied to clipboard"}}case"theme_changed":{const c=typeof n=="string"?n:(n==null?void 0:n.theme)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return c&&u?{summary:`Theme changed from "${c}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{summary:"Theme changed"}}case"error_occurred":{const c=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:c?`Details: ${String(c).slice(0,120)}`:void 0}}default:return{summary:Ya(r)}}}function Ga(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function ts(e,r,n,i,s,l){return{id:Ga(),user:r,reportId:e,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:l}}function rs(e,r){const n=[r,...e];return n.length>ri?n.slice(0,ri):n}function Ya(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",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 qa(e){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[e]||e}function Ja(e){const r=new Date(e),i=new Date().getTime()-r.getTime(),s=Math.floor(i/6e4),l=Math.floor(i/36e5),d=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:l<24?`${l} hour${l>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:r.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const ni=100;function Ka(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Xa(e){var l;const r=(l=e.views)==null?void 0:l.find(d=>d.id===e.activeViewId),n=r==null?void 0:r.snapshot.columnOrder,i=e.columnOrder||[],s=$n(i,e.grouping||null,n);return{filters:Oe(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 Qa(e,r,n,i){return{id:Ka(),name:e,description:r,createdBy:n,createdAt:Date.now(),config:i}}function Za(e,r){const n=e||[];if(n.length>=ni)throw new Error(`Maximum of ${ni} presets reached. Please delete old presets first.`);return[...n,r]}function el(e,r){return(e||[]).filter(i=>i.id!==r)}function ii(e,r){if(e)return e.find(n=>n.id===r)}function tl(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function rl(e){const r=e.columnOrder,n=qr(r,e.grouping);return{filters:Oe(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 ol(e){try{if(navigator.clipboard&&navigator.clipboard.writeText)return await navigator.clipboard.writeText(e),!0}catch(r){Et.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){Et.error("urm:presets","execCommand copy failed",i)}return document.body.removeChild(r),n}catch(r){return Et.error("urm:presets","Fallback copy method failed",r),!1}}function nl(e,r){return{totalRows:e.length,totalColumns:r.length}}function Zt(e,r,n,i){const s=n instanceof Error?n.message:n,l={type:e,context:r,message:s,details:i,timestamp:Date.now(),recoverable:il(e,r)};return process.env.NODE_ENV==="development"&&Et.error("urm:error-handling","[Report Error]",{type:e,context:r,message:s,details:i}),l}function il(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 al(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 ll(e,r,n){n(e.id,{filters:Oe(r.filters),sortStack:r.sortStack,grouping:r.grouping,columnVisibility:r.columnVisibility,columnOrder:r.columnOrder,columnWidths:r.columnWidths,activeViewId:r.activeViewId})}function cl(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 os(e,r){const n=[],i=[],s=new Set(r.map(l=>l.name));return e.forEach(l=>{s.has(l.column)?n.push(l):i.push(l.column)}),{validRules:n,invalidColumns:i}}function ns(e,r){if(!e||!e.levels||e.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(r.map(l=>l.name)),i=[],s=[];return e.levels.forEach(l=>{n.has(l.column)?i.push(l):s.push(l.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...e,levels:i},invalidColumns:s}}function dl(e,r){const n=[],i=new Set(r.map(l=>l.name)),s={...e};if(s.filters){const l=d=>{const c=d.children.filter(u=>{if(Re(u))return!0;const m=i.has(u.column);return m||n.push(`Filter for column "${u.column}" ignored (column not found)`),m}).map(u=>Re(u)?l(u):u).filter(u=>!Re(u)||u.children.length>0);return{...d,children:c}};s.filters=l(Oe(s.filters))}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:l,invalidColumns:d}=os(s.sortStack,r);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),s.sortStack=l.length>0?l:void 0}if(s.grouping){const{validGrouping:l,invalidColumns:d}=ns(s.grouping,r);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),s.grouping=l}if(s.columnVisibility){const l={};Object.entries(s.columnVisibility).forEach(([d,c])=>{i.has(d)?l[d]=c:n.push(`Column visibility for "${d}" ignored (column not found)`)}),s.columnVisibility=Object.keys(l).length>0?l:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const l=s.columnOrder.filter(d=>{const c=i.has(d);return c||n.push(`Column "${d}" in order ignored (column not found)`),c});s.columnOrder=l.length>0?l:void 0}if(s.columnWidths){const l={};Object.entries(s.columnWidths).forEach(([d,c])=>{i.has(d)?l[d]=c:n.push(`Column width for "${d}" ignored (column not found)`)}),s.columnWidths=Object.keys(l).length>0?l:void 0}return{sanitizedConfig:s,warnings:n}}function ul(e,r){return Zt("processing","export",e,{retryAvailable:!!(r!=null&&r.onRetry)})}function si(e,r,n,i){const s=ts(e,r,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return rs(i||[],s)}function pl(e){return e==null}function xl(e,r,n){const{operator:i,value:s}=r;if(i==="NULL")return e==null;if(i==="NOT_NULL")return e!=null;if(pl(e))return!1;if(n==="date"){const l=new Date(e).getTime(),d=new Date(s).getTime();switch(i){case"equals":return l===d;case"gt":return l>d;case"lt":return l<d;case"gte":return l>=d;case"lte":return l<=d;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 jn(e,r,n){var s;if(Re(r))return r.children.length===0?!0:r.operator==="and"?r.children.every(l=>jn(e,l,n)):r.children.some(l=>jn(e,l,n));const i=((s=n.find(l=>l.name===r.column))==null?void 0:s.type)??"string";return xl(e[r.column],r,i)}function ml(e,r,n){return!r||r.children.length===0?e:e.filter(i=>jn(i,r,n))}function zo(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 fl(e){return e!=="isTrue"&&e!=="isFalse"&&e!=="NULL"&&e!=="NOT_NULL"}function hl({data:e,filters:r,schema:n}){return{filteredData:p.useMemo(()=>!r||r.children.length===0?e:ml(e,r,n),[e,r,n])}}function gl(e,r,n,i){if(!n||n.trim()==="")return e;const s=n.toLowerCase().trim(),l=r.filter(d=>i.includes(d.name));return e.filter(d=>l.some(c=>{const u=d[c.name];return u==null?!1:String(u).toLowerCase().includes(s)}))}function yl({data:e,searchQuery:r,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!r||r.trim()===""?e:gl(e,n,r,i),[e,r,n,i])}}function bl({data:e,sortStack:r,schema:n}){return{sortedData:p.useMemo(()=>!r||r.length===0?e:Sa(e,n,r),[e,r,n])}}function vl({data:e,grouping:r,schema:n}){const i=p.useMemo(()=>!r||!r.enabled||r.levels.length===0?e:Ta(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 Sl({schema:e,columnVisibility:r,columnOrder:n}){const i=p.useMemo(()=>n.filter(c=>r[c]!==!1),[n,r]),s=p.useMemo(()=>Object.entries(r).filter(([c,u])=>!u).map(([c,u])=>c),[r]),l=p.useMemo(()=>n.map(c=>e.find(m=>m.name===c)||{name:c,type:"string"}),[n,e]),d=p.useMemo(()=>i.map(c=>e.find(m=>m.name===c)||{name:c,type:"string"}),[i,e]);return{visibleColumns:i,hiddenColumns:s,allColumns:l,visibleColumnSchemas:d,hiddenCount:s.length}}function Cl({views:e,activeViewId:r,currentState:n}){const i=p.useMemo(()=>e.find(m=>m.id===r),[e,r]),s=p.useMemo(()=>i?Ba(n,i.snapshot):!1,[i,n]),l=p.useMemo(()=>e.find(m=>m.isDefault),[e]),d=p.useMemo(()=>e.filter(m=>!m.isDefault&&!m.isDeleted),[e]),c=p.useMemo(()=>e.filter(m=>m.isFavorite&&!m.isDeleted),[e]),u=p.useMemo(()=>e.filter(m=>m.isDeleted),[e]);return{activeView:i,isDirty:s,defaultView:l,customViews:d,favoriteViews:c,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function jl({data:e,enabled:r=!1,pageSize:n=100,initialPage:i=1}){const[s,l]=p.useState(i),d=e.length,c=Math.ceil(d/n),u=p.useMemo(()=>{if(!r)return e;const b=(s-1)*n,z=b+n;return e.slice(b,z)},[e,r,s,n]),m=p.useCallback(b=>{const z=Math.max(1,Math.min(b,c));l(z)},[c]),f=p.useCallback(()=>{s<c&&l(s+1)},[s,c]),x=p.useCallback(()=>{s>1&&l(s-1)},[s]),v=p.useCallback(()=>{l(1)},[]);return{paginatedData:u,currentPage:s,totalPages:c,pageSize:n,totalRows:d,goToPage:m,nextPage:f,prevPage:x,resetPage:v,hasNextPage:s<c,hasPrevPage:s>1}}function wl(e){const{rawData:r,schema:n,filters:i,sortStack:s,grouping:l,searchQuery:d,columnVisibility:c,columnOrder:u,columnWidths:m,views:f,activeViewId:x,pagination:v}=e,b=p.useMemo(()=>({filters:i,sortStack:s,grouping:l,columnVisibility:c,columnOrder:u,columnWidths:m}),[i,s,l,c,u,m]),z=Cl({views:f,activeViewId:x,currentState:b}),S=Sl({schema:n,columnVisibility:c,columnOrder:u}),{filteredData:y}=hl({data:r,filters:i,schema:n}),{sortedData:w}=bl({data:y,sortStack:s,schema:n}),{groupedData:C,isGrouped:E}=vl({data:w,grouping:l,schema:n}),{searchedData:g}=yl({data:C,searchQuery:d,schema:n,visibleColumns:S.visibleColumns}),k=jl({data:g,enabled:(v==null?void 0:v.enabled)||!1,pageSize:(v==null?void 0:v.pageSize)||100,initialPage:(v==null?void 0:v.currentPage)||1}),L=v!=null&&v.enabled?k.paginatedData:g,a=p.useMemo(()=>({totalRows:r.length,filteredRows:y.length,sortedRows:w.length,groupedRows:E?C.length:w.length,searchedRows:g.length,visibleRows:L.length,hiddenColumns:S.hiddenCount,activeFilters:dt(i),activeSorts:s.length,isGrouped:E}),[r.length,y.length,w.length,C.length,g.length,L.length,S.hiddenCount,i,s.length,E]);return{data:L,filteredData:y,sortedData:w,groupedData:C,searchedData:g,viewEngine:z,columnEngine:S,paginationEngine:k,metrics:a,isGrouped:E,isPaginated:(v==null?void 0:v.enabled)||!1}}let kl=0;function Tl(e){e!==null&&e.__urm_row_id__===void 0&&Object.defineProperty(e,"__urm_row_id__",{value:kl++,writable:!1,enumerable:!1,configurable:!1})}const vt="user-demo-001";function Il(e={}){var Un,Gn,Yn,qn,Jn;const{mode:r="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:l,sharedReportId:d,sharedViewId:c,config:u={}}=e,[m,f]=p.useState([]),x=Sr(),[v,b]=p.useState(""),[z,S]=p.useState(!1),[y,w]=p.useState(!1),[C,E]=p.useState({message:"",severity:"info",open:!1}),g=(j,I="info")=>{E({message:j,severity:I,open:!0})},k=()=>E(j=>({...j,open:!1})),L=u.notifDurationMs??2e3,a=m.find(j=>j.id===v),[_,F]=p.useState("idle"),[X,re]=p.useState(!1),[h,V]=p.useState(!1),[W,Q]=p.useState(!1),[Z,pe]=p.useState(!1),[he,N]=p.useState(!1),[R,H]=p.useState(void 0),[G,ae]=p.useState(null),[ee,ne]=p.useState(null),[oe,O]=p.useState(!1),[te,ce]=p.useState(!1),[ie,Ie]=p.useState(null),[q,Me]=p.useState(!1),[et,tt]=p.useState(!1),[rr,Ft]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[Vt,rt]=p.useState(""),[pt,or]=p.useState(""),[Ct,Je]=p.useState(new Set),[jt,Bt]=p.useState(1),[Ht,nr]=p.useState(15),[ir,He]=p.useState(!1),[no,sr]=p.useState(!1),[Ut,ot]=p.useState(!1),[nt,ar]=p.useState(null),[lr,wt]=p.useState(!1),[wr,xt]=p.useState(null),[Nr,cr]=p.useState(null),dr=p.useRef(null),me=p.useMemo(()=>a?La(a.permissions,vt):"owner",[a]),kr=Fa(me),io=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:nl(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),kt=p.useCallback(()=>{a&&(dr.current=al(a))},[a]),P=p.useCallback((j,I)=>{f(A=>A.map($=>$.id===j?{...$,...I}:$))},[]),mt=p.useCallback(j=>{if(!a)return;cr(j);const I=si(a.id,vt,j,a.auditHistory||[]);P(a.id,{auditHistory:I}),g(j.message,"error"),j.recoverable&&dr.current&&setTimeout(()=>{ll(a,dr.current,P),g("Previous state restored","success")},100)},[a,P]),fe=p.useCallback((j,I,A,$)=>{if(!a)return;const U=ts(a.id,vt,j,I,A,$),Y=a.auditHistory||[],de=rs(Y,U);setTimeout(()=>{P(a.id,{auditHistory:de})},0)},[a,P]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const j=ln(a.schema);(()=>{try{const I=localStorage.getItem("urm_dev_config");return I?JSON.parse(I):null}catch{return null}})(),P(a.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})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,P]),p.useEffect(()=>{if(i&&n&&!y&&m.length===0){const j=bo(i),I={id:`auto-report-${Date.now()}`,name:l||(r==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:j,schema:Hr(j),permissions:{owner:vt,editors:[],viewers:[]}};f([I]),b(I.id),w(!0),F("confirmed")}},[i,n,y,m.length,r,l]),p.useEffect(()=>{if(!s||y)return;let j=!1,I=null;const A=async()=>{try{F("uploading");let $;if(s.type==="api"){const Y=await fetch(s.url,{headers:s.headers||{}});if(!Y.ok)throw new Error(`HTTP ${Y.status}: ${Y.statusText}`);$=await Y.json()}else $=await s.fetch();if(j)return;if(!Array.isArray($))throw new Error("Data source must return an array of objects");const U=Hr($);if(y)f(Y=>Y.map(de=>de.id===v?{...de,uploadedData:$}:de)),F("confirmed");else{const Y={id:`auto-report-${Date.now()}`,name:l||(r==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:bo($),schema:Hr(bo($)),permissions:{owner:vt,editors:[],viewers:[]}};f([Y]),b(Y.id),w(!0),F("confirmed")}}catch($){j||(F("error"),a&&P(a.id,{uploadError:($==null?void 0:$.message)||"Failed to load data from source"}))}};return A(),s.refreshInterval&&s.refreshInterval>0&&(I=setInterval(A,s.refreshInterval)),()=>{j=!0,I&&clearInterval(I)}},[s,l,r]);const Le=(Un=a==null?void 0:a.views)==null?void 0:Un.find(j=>j.id===a.activeViewId),Dt=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(Tl),a.uploadedData):[],[a==null?void 0:a.uploadedData]),ft=wl({rawData:Dt,schema:(a==null?void 0:a.schema)||[],filters:Oe(a==null?void 0:a.filters),sortStack:(a==null?void 0:a.sortStack)||[],grouping:(a==null?void 0:a.grouping)||null,searchQuery:pt||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Le==null?void 0:Le.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Le==null?void 0:Le.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Le==null?void 0:Le.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:Ht,currentPage:jt}}),{data:Gt=[],searchedData:Tt=[],groupedData:Tr=[],sortedData:Yt=[],metrics:ur={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:qt=!1,paginationEngine:ze}=ft||{},K=((Gn=ft.viewEngine)==null?void 0:Gn.activeView)||Le,Ot=((Yn=ft.viewEngine)==null?void 0:Yn.isDirty)||!1;p.useEffect(()=>{if(!(!K||!a)&&!a.columnOrder){const j=K.snapshot.columnOrder,I=qr(j,K.snapshot.grouping);P(a.id,{columnOrder:I})}},[a==null?void 0:a.activeViewId]);const we=p.useMemo(()=>!(a!=null&&a.schema)||!K?null:Ea(a.filters,a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,K.snapshot.columnOrder),[a==null?void 0:a.filters,a==null?void 0:a.sortStack,a==null?void 0:a.schema,a==null?void 0:a.columnVisibility,a==null?void 0:a.columnOrder,a==null?void 0:a.columnWidths,a==null?void 0:a.grouping,K]),Ir=p.useMemo(()=>!K||!we||!Ot?[]:Oa(we,K.snapshot),[K,we,Ot]),pr=p.useCallback((j,I,A)=>{const $={id:`report-${Date.now()}`,name:j,description:I,schemaLocked:!1,permissions:{owner:vt,editors:[],viewers:[]}};if(A&&Array.isArray(A)&&A.length>0){const U=Hr(A),Y=ln(U);$.uploadedData=A,$.schema=U,$.schemaLocked=!0,$.views=[Y],$.activeViewId=Y.id,$.sortStack=Y.snapshot.sortStack,$.filters=Y.snapshot.filters,$.columnVisibility=Y.snapshot.columnVisibility,$.columnOrder=Y.snapshot.columnOrder,$.columnWidths=Y.snapshot.columnWidths,$.grouping=Y.snapshot.grouping}f(U=>[...U,$]),b($.id),S(!1),F("confirmed")},[]),Se=p.useCallback(j=>{a&&(F("uploading"),setTimeout(()=>{const I=Hr(j);P(a.id,{uploadedData:j,schema:I,uploadError:void 0}),F("preview")},500))},[a,P]),Fe=p.useCallback(j=>{a&&(P(a.id,{uploadError:j}),F("idle"))},[a,P]),xr=p.useCallback(()=>{a&&(P(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),F("idle"))},[a,P]),it=p.useCallback(()=>{a&&(P(a.id,{schemaLocked:!0}),F("confirmed"))},[a,P]),ht=p.useCallback(j=>{if(!a)return;if(!at("edit_sorting",me)){g(lt("edit_sorting"),"error");return}const I=a.sortStack??[],A=I.find($=>$.column===j);if(A){const $=Ca(A.direction);if($===null){const U=I.filter(Y=>Y.column!==j).map((Y,de)=>({...Y,priority:de+1}));P(a.id,{sortStack:U.length>0?U:void 0})}else{const U=$,Y=I.map(de=>de.column===j?{...de,direction:U}:de);P(a.id,{sortStack:Y})}}else{if(I.length>=x.sort.maxLevels){g(`Sort limit reached — maximum ${x.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const $={column:j,direction:"asc",priority:I.length+1};P(a.id,{sortStack:[...I,$]})}},[a,me,P]),Ve=p.useCallback(j=>{if(a)if(a.schema){const{validRules:I,invalidColumns:A}=os(j,a.schema);A.length>0&&g(`Removed invalid sort columns: ${A.join(", ")}`),kt();try{P(a.id,{sortStack:I.length>0?I:void 0})}catch($){const U=Zt("processing","sorting",$);mt(U)}}else P(a.id,{sortStack:j.length>0?j:void 0})},[a,P,kt,mt]),mr=p.useCallback(j=>{if(!a)return;const I=a.sortStack??[],A=I.find($=>$.column===j);if(!(A&&A.direction==="asc"))if(A){const $=I.map(U=>U.column===j?{...U,direction:"asc"}:U);P(a.id,{sortStack:$})}else{if(I.length>=x.sort.maxLevels){g(`Sort limit reached — maximum ${x.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const $={column:j,direction:"asc",priority:I.length+1};P(a.id,{sortStack:[...I,$]})}},[a,P]),zr=p.useCallback(j=>{if(!a)return;const I=a.sortStack??[],A=I.find($=>$.column===j);if(!(A&&A.direction==="desc"))if(A){const $=I.map(U=>U.column===j?{...U,direction:"desc"}:U);P(a.id,{sortStack:$})}else{if(I.length>=x.sort.maxLevels){g(`Sort limit reached — maximum ${x.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const $={column:j,direction:"desc",priority:I.length+1};P(a.id,{sortStack:[...I,$]})}},[a,P]),gt=p.useCallback((j,I)=>{var $;if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const A=($=a.schema)==null?void 0:$.find(U=>U.name===I.column);if(A&&I.value!==void 0){const U=cl(A.type,I.operator,I.value);if(!U.isValid){g(U.errorMessage||"Invalid filter value","error");return}}kt();try{const U=Oe(a.filters),Y={...I,id:Wr()},de=Pr(U,j,Y);fe("filters","filter_added",null,Y),P(a.id,{filters:de})}catch(U){const Y=Zt("processing","filters",U);mt(Y)}},[a,me,P,kt,mt,fe]),Ue=p.useCallback(j=>{if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const I=Oe(a.filters),A=Pr(I,j,St());fe("filters","filter_added",null,"a condition group"),P(a.id,{filters:A})},[a,me,P,fe]),Er=p.useCallback((j,I)=>{if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const A=Oe(a.filters),$=vo(A,j),U=Bn(A,j,I),Y=vo(U,j);fe("filters","filter_updated",$,Y),P(a.id,{filters:U})},[a,me,P,fe]),Lr=p.useCallback((j,I)=>{if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const A=Oe(a.filters),$=Dn(A,j,I);fe("filters","filter_updated",null,`group operator changed to ${I.toUpperCase()}`),P(a.id,{filters:$})},[a,me,P,fe]),$t=p.useCallback(j=>{if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const I=Oe(a.filters),A=vo(I,j),$=On(I,j);fe("filters","filter_removed",A,null),P(a.id,{filters:$})},[a,me,P,fe]),Jt=p.useCallback(()=>{if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const j=Oe(a.filters);fe("filters","filter_cleared",{count:dt(j)},null),P(a.id,{filters:St()})},[a,me,P,fe]),Fr=p.useCallback(j=>{if(!a)return;if(!at("edit_filters",me)){g(lt("edit_filters"),"error");return}const I=Oe(a.filters);fe("filters","filter_cleared",{count:dt(I)},{count:dt(j)}),P(a.id,{filters:j})},[a,me,P,fe]),st=p.useCallback(j=>{var U;if(!a)return;const I=(U=a.views)==null?void 0:U.find(Y=>Y.id===j);if(!I)return;const A=I.snapshot.columnOrder,$=qr(A,I.snapshot.grouping);P(a.id,{filters:I.snapshot.filters,sortStack:I.snapshot.sortStack.length>0?[...I.snapshot.sortStack]:void 0,columnVisibility:{...I.snapshot.columnVisibility},columnOrder:$,columnWidths:{...I.snapshot.columnWidths},grouping:I.snapshot.grouping,activeViewId:j}),Je(new Set)},[a,P]),Kt=p.useCallback((j,I,A)=>{var We;if(!(a!=null&&a.schema)||!we)return;const $=a.views??[],U=$.filter(an=>!an.isDeleted).length,Y=((We=x.views)==null?void 0:We.maxViews)??10;if(U>=Y){g(`View limit reached — you can have at most ${Y} saved views. Delete an existing view to create a new one.`,"error");return}const de={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:j,description:I||void 0,isDefault:A,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:vt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...we}},ye=A?$.map(an=>({...an,isDefault:!1})):$;P(a.id,{views:[...ye,de],activeViewId:de.id}),g(`"${j}" view created`,"success")},[a,we,P]),Br=p.useCallback(j=>{var de;if(!(a!=null&&a.views))return;const I=a.views.find(ye=>ye.id===j);if(!I)return;const A=a.views,$=A.filter(ye=>!ye.isDeleted).length,U=((de=x.views)==null?void 0:de.maxViews)??10;if($>=U){g(`View limit reached — you can have at most ${U} saved views. Delete an existing view to create a new one.`,"error");return}const Y={...I,id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:`${I.name} (copy)`,scope:"personal",isDefault:!1,isFavorite:!1,isDeleted:!1,createdBy:vt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...I.snapshot}};P(a.id,{views:[...A,Y]}),g(`"${Y.name}" created`,"success")},[a,x,P]),At=p.useCallback(()=>{var I;if(!K||!we||!a)return;const j=(I=a.views)==null?void 0:I.map(A=>A.id===K.id?{...A,snapshot:{...we}}:A);P(a.id,{views:j}),g(`"${K.name}" view updated`,"success")},[K,we,a,P]),_t=p.useCallback(j=>{var $;if(!K||!we||!a)return;const I=j??we.columnWidths,A=($=a.views)==null?void 0:$.map(U=>U.id===K.id?{...U,snapshot:{...U.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:I},updatedAt:Date.now()}:U);P(a.id,{views:A,columnWidths:I}),g(`Column configuration saved to "${K.name}"`,"success")},[K,we,a,P]),fr=p.useCallback(j=>{var Y,de;if(!we||!a||!K)return;const I=j??we.columnWidths,A={...K,snapshot:{...K.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:I},updatedAt:Date.now()},$=(Y=a.views)==null?void 0:Y.map(ye=>ye.id===K.id?A:{...ye,snapshot:{...ye.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:I},updatedAt:Date.now()});P(a.id,{views:$,columnWidths:I});const U=(((de=a.views)==null?void 0:de.length)||0)-1;g(`Column configuration saved to current view and ${U} other view${U===1?"":"s"}`,"success")},[we,a,K,P]),le=p.useCallback(()=>{Q(!0)},[]),ge=p.useCallback(()=>{if(!K||!a)return;const j=K.snapshot.columnOrder,I=qr(j,K.snapshot.grouping);P(a.id,{filters:K.snapshot.filters,sortStack:K.snapshot.sortStack.length>0?[...K.snapshot.sortStack]:void 0,columnVisibility:{...K.snapshot.columnVisibility},columnOrder:I,columnWidths:{...K.snapshot.columnWidths},grouping:K.snapshot.grouping}),g("Changes reverted to last saved state","success")},[K,a,P]),Ae=p.useCallback(j=>{if(!(a!=null&&a.views))return;const I=a.views.map($=>({...$,isDefault:$.id===j}));P(a.id,{views:I});const A=a.views.find($=>$.id===j);A&&g(`"${A.name}" set as default view`,"success")},[a,P]),yt=p.useCallback(j=>{if(!(a!=null&&a.views))return;const I=a.views.map($=>$.id===j?{...$,isFavorite:!$.isFavorite,updatedAt:Date.now()}:$);P(a.id,{views:I});const A=a.views.find($=>$.id===j);A&&!A.isFavorite?g(`"${A.name}" added to favorites`,"success"):A&&g(`"${A.name}" removed from favorites`,"info")},[a,P]),bt=p.useCallback(j=>{if(!(a!=null&&a.views))return;const I=a.views.find(We=>We.id===j),A=a.views.filter(We=>!We.isDeleted||We.id===j);if((I==null?void 0:I.isDefault)&&A.filter(We=>We.isDefault).length===1){g("Cannot delete the last default view","error");return}const U=a.views.map(We=>We.id===j?{...We,isDeleted:!0,updatedAt:Date.now()}:We),Y=a.activeViewId===j,de=U.find(We=>We.isDefault&&!We.isDeleted);P(a.id,{views:U,activeViewId:Y&&de?de.id:a.activeViewId,filters:Y&&de?de.snapshot.filters:a.filters,sortStack:Y&&de?de.snapshot.sortStack.length>0?de.snapshot.sortStack:void 0:a.sortStack});const ye=a.views.find(We=>We.id===j);ye&&g(`"${ye.name}" moved to Recently Deleted`,"info")},[a,P]),Xt=p.useCallback(j=>{if(!(a!=null&&a.views))return;const I=a.views.map($=>$.id===j?{...$,isDeleted:!1,updatedAt:Date.now()}:$);P(a.id,{views:I});const A=a.views.find($=>$.id===j);A&&g(`"${A.name}" restored`,"success")},[a,P]),so=p.useCallback(j=>{if(!(a!=null&&a.views))return;const I=a.views.find(ye=>ye.id===j),A=a.views.filter(ye=>!ye.isDeleted||ye.id===j);if((I==null?void 0:I.isDefault)&&A.filter(ye=>ye.isDefault).length===1){g("Cannot delete the last default view","error");return}const U=a.views.filter(ye=>ye.id!==j),Y=a.activeViewId===j,de=U.find(ye=>ye.isDefault&&!ye.isDeleted);P(a.id,{views:U,activeViewId:Y&&de?de.id:a.activeViewId,filters:Y&&de?de.snapshot.filters:a.filters,sortStack:Y&&de?de.snapshot.sortStack.length>0?de.snapshot.sortStack:void 0:a.sortStack}),I&&g(`"${I.name}" permanently deleted`,"success")},[a,P]),Dr=p.useCallback(j=>{ae(j),pe(!0)},[]),qo=p.useCallback(async j=>{if(!a)return;const I=new URLSearchParams(window.location.search);I.set("reportId",a.id),I.set("view",j);const A=`${window.location.origin}${window.location.pathname}?${I.toString()}`,$=await ol(A);g($?"Link copied to clipboard":"Failed to copy link",$?"success":"error")},[a]),Jo=p.useCallback((j,I)=>{if(!G||!(a!=null&&a.views))return;const A=a.views.map($=>$.id===G?{...$,name:j,description:I||void 0}:$);P(a.id,{views:A}),ae(null)},[G,a,P]),Ko=p.useCallback(j=>{ne(j),N(!0)},[]),Xo=p.useCallback(()=>{if(!ee||!(a!=null&&a.views))return;const j=a.views.filter($=>$.id!==ee),I=a.activeViewId===ee,A=j.find($=>$.isDefault);P(a.id,{views:j,activeViewId:I&&A?A.id:a.activeViewId,filters:I&&A?A.snapshot.filters:a.filters,sortStack:I&&A?A.snapshot.sortStack.length>0?A.snapshot.sortStack:void 0:a.sortStack}),ne(null),N(!1)},[ee,a,P]),Qo=p.useCallback(j=>{var U;if(!(a!=null&&a.views))return;if(!(((U=x.views)==null?void 0:U.isAdmin)??!1)){g("Only administrators can promote views to Global.","error");return}const A=a.views.find(Y=>Y.id===j);if(!A)return;if(A.scope==="global"){g(`"${A.name}" is already a Global View.`,"info");return}const $=a.views.map(Y=>Y.id===j?{...Y,scope:"global",isDefault:!0,updatedAt:Date.now()}:Y.scope==="global"&&Y.isDefault?{...Y,isDefault:!1}:Y);P(a.id,{views:$}),g(`"${A.name}" promoted to Global View and set as default.`,"success")},[a,x,P]);p.useEffect(()=>{ze!=null&&ze.resetPage?ze.resetPage():Bt(1)},[a==null?void 0:a.filters,pt,a==null?void 0:a.activeViewId]),p.useEffect(()=>{ze&&ze.currentPage!==jt&&Bt(ze.currentPage)},[ze==null?void 0:ze.currentPage]);const Zo=p.useCallback(j=>{ze!=null&&ze.goToPage&&ze.goToPage(j),Bt(j)},[ze]),en=p.useCallback(j=>{const I=(jt-1)*Ht,A=Math.floor(I/j)+1;nr(j),Bt(A),ze==null||ze.goToPage(A)},[jt,Ht,ze]),tn=p.useCallback((j,I)=>{if(!a)return;if(!at("edit_columns",me)){g(lt("edit_columns"),"error");return}const $={...a.columnVisibility||(K==null?void 0:K.snapshot.columnVisibility)||{},[j]:I};P(a.id,{columnVisibility:$})},[a,K,me,P]),rn=p.useCallback(j=>{if(a){if(!at("edit_columns",me)){g(lt("edit_columns"),"error");return}P(a.id,{columnOrder:j})}},[a,me,P]),hr=p.useCallback((j,I)=>{if(!a)return;if(!at("edit_columns",me)){g(lt("edit_columns"),"error");return}const $={...a.columnWidths||(K==null?void 0:K.snapshot.columnWidths)||{},[j]:I};P(a.id,{columnWidths:$})},[a,K,me,P]),Mt=p.useCallback(j=>{if(!a)return;const I=Oe(a.filters),A=Xi(I,j);P(a.id,{filters:A})},[a,P]),on=p.useCallback(()=>{if(!K||!(a!=null&&a.schema))return;const j={},I=[],A={};a.schema.forEach($=>{j[$.name]=!0,I.push($.name),A[$.name]=170}),P(a.id,{columnVisibility:j,columnOrder:I,columnWidths:A,filters:void 0,sortStack:void 0}),g("Reset to default layout - all filters and sorts cleared","success")},[K,a,P]);p.useEffect(()=>{const j=setTimeout(()=>or(Vt),300);return()=>clearTimeout(j)},[Vt]);const nn=p.useCallback(j=>{rt(j)},[]),Pe=p.useCallback(j=>{if(!j.trim()||!a)return;const I=a.searchHistory||[],A=Ma(I,j);P(a.id,{searchHistory:A})},[a,P]),Rt=p.useCallback(j=>{if(!a)return;const I=a.searchHistory||[],A=Ra(I,j);P(a.id,{searchHistory:A})},[a,P]),ao=p.useCallback(j=>{if(!a)return;const I=a.searchHistory||[],A=Wa(I,j);P(a.id,{searchHistory:A})},[a,P]),Vn=p.useCallback(j=>{const I=j==null?void 0:j.__urm_row_id__;Je(A=>{const $=new Set(A);if(I!==void 0){const U=Array.from($).find(Y=>(Y==null?void 0:Y.__urm_row_id__)===I);U!==void 0?$.delete(U):$.add(j)}else{const U=JSON.stringify(j),Y=Array.from($).find(de=>JSON.stringify(de)===U);Y!==void 0?$.delete(Y):$.add(j)}return $})},[]),Vr=p.useCallback((j,I)=>{Je(A=>{const $=new Set(A);for(const U of I)j?$.add(U):$.delete(U);return $})},[]),sn=p.useCallback((j,I,A)=>{Je($=>{const U=new Set($),Y=Math.min(j,I),de=Math.max(j,I);for(let ye=Y;ye<=de;ye++)A[ye]!==void 0&&U.add(A[ye]);return U})},[]),lo=p.useCallback(()=>{Je(new Set)},[]),co=p.useCallback(j=>{const I=j==null?void 0:j.__urm_row_id__;Je(A=>{const $=new Set(A);if(I!==void 0){const U=Array.from($).find(Y=>(Y==null?void 0:Y.__urm_row_id__)===I);U!==void 0&&$.delete(U)}else $.delete(j);return $})},[]),B=p.useCallback(j=>{if(a){if(!at("edit_columns",me)){g(lt("edit_columns"),"error");return}if(j&&a.schema){const{validGrouping:I,invalidColumns:A}=ns(j,a.schema);A.length>0&&g(`Removed invalid grouping columns: ${A.join(", ")}`,"warning"),kt();try{const $=a.grouping;I===null?fe("grouping","group_cleared",$,null):$?fe("grouping","group_reordered",$,I):fe("grouping","group_level_added",null,I);const U=(K==null?void 0:K.snapshot.columnOrder)||a.columnOrder||[],Y=qr(U,I);P(a.id,{grouping:I,columnOrder:Y}),JSON.stringify(Y)!==JSON.stringify(a.columnOrder)&&fe("columns","column_reordered",a.columnOrder,Y),tt(!1)}catch($){const U=Zt("processing","grouping",$);mt(U)}}else{const I=a.grouping;fe("grouping","group_cleared",I,null);const A=(K==null?void 0:K.snapshot.columnOrder)||a.columnOrder||[];P(a.id,{grouping:j,columnOrder:[...A]}),JSON.stringify(A)!==JSON.stringify(a.columnOrder)&&fe("columns","column_reordered",a.columnOrder,A),tt(!1)}}},[a,K,me,P,kt,mt,fe]),J=p.useCallback(j=>{if(!a)return;const I=a.grouping;if(!I)return;const A=za(I,j);P(a.id,{grouping:A})},[a,P]),xe=p.useCallback(()=>{a!=null&&a.grouping&&P(a.id,{grouping:{...a.grouping,collapsedGroups:[]}})},[a,P]),Ge=p.useCallback(()=>{if(!(a!=null&&a.grouping)||!a.schema)return;const j=Ia(Yt,a.schema,a.grouping);P(a.id,{grouping:{...a.grouping,collapsedGroups:j}})},[a,Yt,P]),Ye=p.useCallback(()=>{wt(!0)},[]),ue=p.useCallback(j=>{a!=null&&a.schema&&(O(!0),setTimeout(()=>{try{let I;j.scope==="visible"?I=Tt:I=a.uploadedData||[];let A;j.columnScope==="all"?(A={},(a.schema??[]).forEach(ye=>{A[ye.name]=!0})):A=a.columnVisibility||(K==null?void 0:K.snapshot.columnVisibility)||{};const $=a.columnOrder||(K==null?void 0:K.snapshot.columnOrder),U=wo(I,a.schema,Oe(a.filters),a.sortStack??[],K,A,$),Y=a.name;let de;switch(j.format){case"csv":ko(U,Y,j),de="export_csv";break;case"excel":To(U,Y,j),de="export_excel";break;case"json":Io(U,Y,j),de="export_json";break}fe("export",de,null,{format:j.format,scope:j.scope,columnScope:j.columnScope,rowCount:I.length,viewName:(K==null?void 0:K.name)||"Default View"}),g(`Export completed successfully (${j.format.toUpperCase()})`,"success")}catch(I){const A=ul(I,{onRetry:()=>ue(j)});g(`Export failed: ${A.message}. Click Export to retry.`,"error");const $=si(a.id,vt,A,a.auditHistory||[]);P(a.id,{auditHistory:$}),Et.error("urm:report-engine","Export failed",I)}finally{O(!1)}},500))},[a,K,Tt,P,fe]),gr=p.useCallback(j=>{if(a!=null&&a.schema){if(Ot&&K&&!K.isDefault){Ie(j.format),ce(!0),wt(!1);return}ue(j),wt(!1)}},[a,K,Ot,ue]),uo=p.useCallback(j=>{ue({format:j,scope:"visible",columnScope:"visible"})},[ue]),Ws=p.useCallback(()=>{ie&&uo(ie),ce(!1),Ie(null)},[ie,uo]),Ps=p.useCallback(()=>{At(),ie&&uo(ie),ce(!1),Ie(null)},[At,ie,uo]),Ns=p.useCallback(()=>{ce(!1),Ie(null)},[]),Ls=p.useCallback(j=>{!(a!=null&&a.schema)||Ct.size===0||(O(!0),setTimeout(()=>{try{const I=Array.from(Ct),A=wo(I,a.schema,Oe(a.filters),a.sortStack??[],K),$=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(j){case"csv":ko(A,$);break;case"excel":To(A,$);break;case"json":Io(A,$);break}g(`Exported ${I.length} selected rows`,"info")}catch(I){g("Export failed. Please try again.","error"),Et.error("urm:report-engine","Bulk export failed",I)}finally{O(!1)}},500))},[a,K,Ct,Tr]),Fs=p.useCallback((j,I)=>{if(a)try{const A=Xa(a),$=Qa(j,I,vt,A),U=Za(a.presets,$);P(a.id,{presets:U}),fe("presets","preset_created",null,{presetId:$.id,name:$.name}),sr(!1),g(`Preset "${j}" saved successfully`,"success")}catch(A){g(A instanceof Error?A.message:"Failed to create preset","error")}},[a,P,fe]),Vs=p.useCallback(()=>{ar(null),g("Exited preset view","info")},[]),Hs=p.useCallback(()=>{ot(!0)},[]),Us=p.useCallback((j,I)=>{if(!a)return;const A=el(a.presets,j);P(a.id,{presets:A}),fe("presets","preset_deleted",{presetId:j,name:I},null),nt===j&&ar(null),g(`Preset "${I}" deleted`,"success")},[a,nt,P,fe]);p.useEffect(()=>{if(!d||m.length===0)return;const j=m.find(I=>I.id===d);j&&j.id!==v&&b(j.id)},[d,m,v]);const Hn=p.useRef(!1);p.useEffect(()=>{var I;if(!c||Hn.current||!a||a.id!==d)return;const j=(I=a.views)==null?void 0:I.find(A=>A.id===c&&!A.isDeleted);j&&st(j.id),Hn.current=!0},[c,d,a,st]),p.useEffect(()=>{if(!a)return;const j=tl();if(j&&a.presets&&a.schemaLocked&&a.schema){const I=ii(a.presets,j);if(I){const{sanitizedConfig:A,warnings:$}=dl(I.config,a.schema);$.length>0&&$.forEach(Y=>g(Y,"warning"));const U=rl(A);P(a.id,U),ar(j),fe("presets","preset_applied",null,{presetId:I.id,name:I.name}),g(`Loaded preset: ${I.name}`,"info")}else g("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const Gs=nt?ii(a==null?void 0:a.presets,nt):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&$a(a.id,{views:a.views,activeViewId:a.activeViewId})},[a==null?void 0:a.views,a==null?void 0:a.activeViewId,a==null?void 0:a.id]),p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const j=Aa(a.id);if(j&&j.views.length>0){const I=j.views.find(A=>A.id===j.activeViewId);if(I)P(a.id,{views:j.views,activeViewId:j.activeViewId,filters:Oe(I.snapshot.filters),sortStack:I.snapshot.sortStack.length>0?I.snapshot.sortStack:void 0});else{const A=j.views.find($=>$.isDefault)||ln(a.schema);P(a.id,{views:j.views,activeViewId:A.id,filters:Oe(A.snapshot.filters),sortStack:A.snapshot.sortStack.length>0?A.snapshot.sortStack:void 0})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const Ys=p.useCallback(j=>{var $;const I=Oe(a==null?void 0:a.filters),A=(($=x.filter)==null?void 0:$.maxConditions)??3;if(dt(I)>=A){g(`Filter limit reached — maximum ${A} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}H(j),re(!0)},[a,x,g]),qs=p.useCallback(()=>{re(!1),H(void 0)},[]),Js=(qn=a==null?void 0:a.views)==null?void 0:qn.find(j=>j.id===G),Ks=(Jn=a==null?void 0:a.views)==null?void 0:Jn.find(j=>j.id===ee);return{reports:m,activeReport:a,activeReportId:v,setActiveReportId:b,isModalOpen:z,setIsModalOpen:S,createReport:pr,updateReport:P,uploadState:_,handleFileUpload:Se,handleUploadError:Fe,handleRetry:xr,handleConfirm:it,paginatedData:Gt,processedData:Tt,displayData:Tr,tableMetrics:ur,isGrouped:qt,tableEngine:ft,activeView:K,isDirty:Ot,currentTableState:we,viewChanges:Ir,filters:a==null?void 0:a.filters,showFilterPanel:X,setShowFilterPanel:re,filterFocusColumn:R,handleAddCondition:gt,handleAddGroup:Ue,handleUpdateCondition:Er,handleSetGroupOperator:Lr,handleRemoveFilterNode:$t,handleClearAllFilters:Jt,handleReplaceFilters:Fr,handleOpenFilterForColumn:Ys,handleCloseFilterPanel:qs,handleClearFiltersForColumn:Mt,sortStack:a==null?void 0:a.sortStack,showSortPanel:h,setShowSortPanel:V,handleSort:ht,handleUpdateSortStack:Ve,handleSortAscending:mr,handleSortDescending:zr,views:a==null?void 0:a.views,showCreateViewModal:W,setShowCreateViewModal:Q,showEditViewModal:Z,setShowEditViewModal:pe,showDeleteConfirmation:he,setShowDeleteConfirmation:N,editingView:Js,deletingView:Ks,editingViewId:G,deletingViewId:ee,handleSelectView:st,handleCreateView:Kt,handleCloneView:Br,handleUpdateCurrentView:At,handleSaveColumnConfigToCurrentView:_t,handleSaveColumnConfigToAllViews:fr,handleSaveAsNewView:le,handleRevertChanges:ge,handleToggleDefault:Ae,handleToggleFavorite:yt,handleSoftDelete:bt,handleRestoreView:Xt,handlePermanentDelete:so,handleEditView:Dr,handleCopyViewLink:qo,handleSaveEditView:Jo,handleDeleteView:Ko,handleConfirmDelete:Xo,handlePromoteToGlobal:Qo,showManageColumns:q,setShowManageColumns:Me,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:tn,handleUpdateColumnOrder:rn,handleUpdateColumnWidth:hr,handleResetColumnLayout:on,showGroupPanel:et,setShowGroupPanel:tt,grouping:a==null?void 0:a.grouping,groupingState:rr,handleGroup:B,handleToggleGroupCollapse:J,handleExpandAllGroups:xe,handleCollapseAllGroups:Ge,searchQuery:Vt,debouncedSearchQuery:pt,searchHistory:Pa((a==null?void 0:a.searchHistory)||[]),handleSearchChange:nn,handleAddToSearchHistory:Pe,handleToggleSearchFavourite:Rt,handleDeleteSearchHistory:ao,selectedRowIds:Ct,handleToggleRowSelection:Vn,handleToggleAllRows:Vr,handleRangeSelection:sn,handleClearSelection:lo,handleUpdateSelectionAfterDelete:co,currentPage:jt,pageSize:Ht,paginationEngine:ze,handlePageChange:Zo,handlePageSizeChange:en,isExporting:oe,showExportModal:lr,setShowExportModal:wt,showDirtyExportWarning:te,handleExport:Ye,handleExportWithConfig:gr,handleExportSelected:Ls,handleExportAnyway:Ws,handleSaveAndExport:Ps,handleCancelExport:Ns,showAuditHistory:ir,setShowAuditHistory:He,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:no,setShowCreatePreset:sr,showManagePresets:Ut,setShowManagePresets:ot,activePreset:Gs,activePresetId:nt,handleOpenManagePresets:Hs,handleCreatePreset:Fs,handleClearActivePreset:Vs,handleDeletePresetById:Us,userRole:me,isViewerRole:kr,currentUserId:vt,featureLimitWarning:wr,setFeatureLimitWarning:xt,datasetMeta:io,reportError:Nr,setReportError:cr,handleError:mt,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?ba(a.schema):!1,snack:C,handleSnackClose:k,showSnack:g,snackDurationMs:L}}const is=p.createContext(void 0);function Mn(e){const{children:r,initialData:n,data:i,reportName:s,dataSource:l,mode:d="builder",autoLoad:c=!0,config:u,devConfig:m,showDevPanel:f=!1,sharedReportId:x,sharedViewId:v}=e,z=Il({mode:d,autoLoad:c,initialData:i||n,dataSource:l,reportName:s,sharedReportId:x,sharedViewId:v,config:u}),[S,y]=p.useState(()=>ta()),w=(()=>{const k=oa(S,m,!!m);return{...k,display:{...k.display,showDevPanel:f||k.display.showDevPanel}}})(),C=p.useCallback(g=>{y(g),ra(g)},[]),E={...z,activeDevConfig:w,handleDevConfigChange:C};return t.jsx(Gi.Provider,{value:w,children:t.jsx(is.Provider,{value:E,children:r})})}function $o(){const e=p.useContext(is);if(e===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return e}function zl({onCreateReport:e,reports:r=[],activeReportId:n,onReportClick:i}){const s=r.find(l=>l.id===n);return t.jsx(o.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},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(T.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[t.jsx(o.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",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:500,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(T.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(T.Add,{sx:{fontSize:18}}),onClick:e,sx:{borderRadius:"20px",px:3,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function vr(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 El="$$material";function Bl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var xo={exports:{}},mo={exports:{}},be={};/** @license React v16.13.1
|
|
4
4
|
* react-is.production.min.js
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
7
|
*
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/var
|
|
10
|
+
*/var ai;function Dl(){if(ai)return be;ai=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,l=e?Symbol.for("react.profiler"):60114,d=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,u=e?Symbol.for("react.async_mode"):60111,m=e?Symbol.for("react.concurrent_mode"):60111,f=e?Symbol.for("react.forward_ref"):60112,x=e?Symbol.for("react.suspense"):60113,v=e?Symbol.for("react.suspense_list"):60120,b=e?Symbol.for("react.memo"):60115,z=e?Symbol.for("react.lazy"):60116,S=e?Symbol.for("react.block"):60121,y=e?Symbol.for("react.fundamental"):60117,w=e?Symbol.for("react.responder"):60118,C=e?Symbol.for("react.scope"):60119;function E(k){if(typeof k=="object"&&k!==null){var L=k.$$typeof;switch(L){case r:switch(k=k.type,k){case u:case m:case i:case l:case s:case x:return k;default:switch(k=k&&k.$$typeof,k){case c:case f:case z:case b:case d:return k;default:return L}}case n:return L}}}function g(k){return E(k)===m}return be.AsyncMode=u,be.ConcurrentMode=m,be.ContextConsumer=c,be.ContextProvider=d,be.Element=r,be.ForwardRef=f,be.Fragment=i,be.Lazy=z,be.Memo=b,be.Portal=n,be.Profiler=l,be.StrictMode=s,be.Suspense=x,be.isAsyncMode=function(k){return g(k)||E(k)===u},be.isConcurrentMode=g,be.isContextConsumer=function(k){return E(k)===c},be.isContextProvider=function(k){return E(k)===d},be.isElement=function(k){return typeof k=="object"&&k!==null&&k.$$typeof===r},be.isForwardRef=function(k){return E(k)===f},be.isFragment=function(k){return E(k)===i},be.isLazy=function(k){return E(k)===z},be.isMemo=function(k){return E(k)===b},be.isPortal=function(k){return E(k)===n},be.isProfiler=function(k){return E(k)===l},be.isStrictMode=function(k){return E(k)===s},be.isSuspense=function(k){return E(k)===x},be.isValidElementType=function(k){return typeof k=="string"||typeof k=="function"||k===i||k===m||k===l||k===s||k===x||k===v||typeof k=="object"&&k!==null&&(k.$$typeof===z||k.$$typeof===b||k.$$typeof===d||k.$$typeof===c||k.$$typeof===f||k.$$typeof===y||k.$$typeof===w||k.$$typeof===C||k.$$typeof===S)},be.typeOf=E,be}var ve={};/** @license React v16.13.1
|
|
11
11
|
* react-is.development.js
|
|
12
12
|
*
|
|
13
13
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
17
|
+
*/var li;function Ol(){return li||(li=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,l=e?Symbol.for("react.profiler"):60114,d=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,u=e?Symbol.for("react.async_mode"):60111,m=e?Symbol.for("react.concurrent_mode"):60111,f=e?Symbol.for("react.forward_ref"):60112,x=e?Symbol.for("react.suspense"):60113,v=e?Symbol.for("react.suspense_list"):60120,b=e?Symbol.for("react.memo"):60115,z=e?Symbol.for("react.lazy"):60116,S=e?Symbol.for("react.block"):60121,y=e?Symbol.for("react.fundamental"):60117,w=e?Symbol.for("react.responder"):60118,C=e?Symbol.for("react.scope"):60119;function E(q){return typeof q=="string"||typeof q=="function"||q===i||q===m||q===l||q===s||q===x||q===v||typeof q=="object"&&q!==null&&(q.$$typeof===z||q.$$typeof===b||q.$$typeof===d||q.$$typeof===c||q.$$typeof===f||q.$$typeof===y||q.$$typeof===w||q.$$typeof===C||q.$$typeof===S)}function g(q){if(typeof q=="object"&&q!==null){var Me=q.$$typeof;switch(Me){case r:var et=q.type;switch(et){case u:case m:case i:case l:case s:case x:return et;default:var tt=et&&et.$$typeof;switch(tt){case c:case f:case z:case b:case d:return tt;default:return Me}}case n:return Me}}}var k=u,L=m,a=c,_=d,F=r,X=f,re=i,h=z,V=b,W=n,Q=l,Z=s,pe=x,he=!1;function N(q){return he||(he=!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.")),R(q)||g(q)===u}function R(q){return g(q)===m}function H(q){return g(q)===c}function G(q){return g(q)===d}function ae(q){return typeof q=="object"&&q!==null&&q.$$typeof===r}function ee(q){return g(q)===f}function ne(q){return g(q)===i}function oe(q){return g(q)===z}function O(q){return g(q)===b}function te(q){return g(q)===n}function ce(q){return g(q)===l}function ie(q){return g(q)===s}function Ie(q){return g(q)===x}ve.AsyncMode=k,ve.ConcurrentMode=L,ve.ContextConsumer=a,ve.ContextProvider=_,ve.Element=F,ve.ForwardRef=X,ve.Fragment=re,ve.Lazy=h,ve.Memo=V,ve.Portal=W,ve.Profiler=Q,ve.StrictMode=Z,ve.Suspense=pe,ve.isAsyncMode=N,ve.isConcurrentMode=R,ve.isContextConsumer=H,ve.isContextProvider=G,ve.isElement=ae,ve.isForwardRef=ee,ve.isFragment=ne,ve.isLazy=oe,ve.isMemo=O,ve.isPortal=te,ve.isProfiler=ce,ve.isStrictMode=ie,ve.isSuspense=Ie,ve.isValidElementType=E,ve.typeOf=g})()),ve}var ci;function ss(){return ci||(ci=1,process.env.NODE_ENV==="production"?mo.exports=Dl():mo.exports=Ol()),mo.exports}/*
|
|
18
18
|
object-assign
|
|
19
19
|
(c) Sindre Sorhus
|
|
20
20
|
@license MIT
|
|
21
|
-
*/var
|
|
22
|
-
Valid keys: `+JSON.stringify(Object.keys(
|
|
21
|
+
*/var dn,di;function $l(){if(di)return dn;di=1;var e=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(l){if(l==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(l)}function s(){try{if(!Object.assign)return!1;var l=new String("abc");if(l[5]="de",Object.getOwnPropertyNames(l)[0]==="5")return!1;for(var d={},c=0;c<10;c++)d["_"+String.fromCharCode(c)]=c;var u=Object.getOwnPropertyNames(d).map(function(f){return d[f]});if(u.join("")!=="0123456789")return!1;var m={};return"abcdefghijklmnopqrst".split("").forEach(function(f){m[f]=f}),Object.keys(Object.assign({},m)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return dn=s()?Object.assign:function(l,d){for(var c,u=i(l),m,f=1;f<arguments.length;f++){c=Object(arguments[f]);for(var x in c)r.call(c,x)&&(u[x]=c[x]);if(e){m=e(c);for(var v=0;v<m.length;v++)n.call(c,m[v])&&(u[m[v]]=c[m[v]])}}return u},dn}var un,ui;function Rn(){if(ui)return un;ui=1;var e="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return un=e,un}var pn,pi;function as(){return pi||(pi=1,pn=Function.call.bind(Object.prototype.hasOwnProperty)),pn}var xn,xi;function Al(){if(xi)return xn;xi=1;var e=function(){};if(process.env.NODE_ENV!=="production"){var r=Rn(),n={},i=as();e=function(l){var d="Warning: "+l;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function s(l,d,c,u,m){if(process.env.NODE_ENV!=="production"){for(var f in l)if(i(l,f)){var x;try{if(typeof l[f]!="function"){var v=Error((u||"React class")+": "+c+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof l[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw v.name="Invariant Violation",v}x=l[f](d,f,u,c,null,r)}catch(z){x=z}if(x&&!(x instanceof Error)&&e((u||"React class")+": type specification of "+c+" `"+f+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof x+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),x instanceof Error&&!(x.message in n)){n[x.message]=!0;var b=m?m():"";e("Failed "+c+" type: "+x.message+(b??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},xn=s,xn}var mn,mi;function _l(){if(mi)return mn;mi=1;var e=ss(),r=$l(),n=Rn(),i=as(),s=Al(),l=function(){};process.env.NODE_ENV!=="production"&&(l=function(c){var u="Warning: "+c;typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}});function d(){return null}return mn=function(c,u){var m=typeof Symbol=="function"&&Symbol.iterator,f="@@iterator";function x(R){var H=R&&(m&&R[m]||R[f]);if(typeof H=="function")return H}var v="<<anonymous>>",b={array:w("array"),bigint:w("bigint"),bool:w("boolean"),func:w("function"),number:w("number"),object:w("object"),string:w("string"),symbol:w("symbol"),any:C(),arrayOf:E,element:g(),elementType:k(),instanceOf:L,node:X(),objectOf:_,oneOf:a,oneOfType:F,shape:h,exact:V};function z(R,H){return R===H?R!==0||1/R===1/H:R!==R&&H!==H}function S(R,H){this.message=R,this.data=H&&typeof H=="object"?H:{},this.stack=""}S.prototype=Error.prototype;function y(R){if(process.env.NODE_ENV!=="production")var H={},G=0;function ae(ne,oe,O,te,ce,ie,Ie){if(te=te||v,ie=ie||O,Ie!==n){if(u){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 Me=te+":"+O;!H[Me]&&G<3&&(l("You are manually calling a React.PropTypes validation function for the `"+ie+"` 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."),H[Me]=!0,G++)}}return oe[O]==null?ne?oe[O]===null?new S("The "+ce+" `"+ie+"` is marked as required "+("in `"+te+"`, but its value is `null`.")):new S("The "+ce+" `"+ie+"` is marked as required in "+("`"+te+"`, but its value is `undefined`.")):null:R(oe,O,te,ce,ie)}var ee=ae.bind(null,!1);return ee.isRequired=ae.bind(null,!0),ee}function w(R){function H(G,ae,ee,ne,oe,O){var te=G[ae],ce=Z(te);if(ce!==R){var ie=pe(te);return new S("Invalid "+ne+" `"+oe+"` of type "+("`"+ie+"` supplied to `"+ee+"`, expected ")+("`"+R+"`."),{expectedType:R})}return null}return y(H)}function C(){return y(d)}function E(R){function H(G,ae,ee,ne,oe){if(typeof R!="function")return new S("Property `"+oe+"` of component `"+ee+"` has invalid PropType notation inside arrayOf.");var O=G[ae];if(!Array.isArray(O)){var te=Z(O);return new S("Invalid "+ne+" `"+oe+"` of type "+("`"+te+"` supplied to `"+ee+"`, expected an array."))}for(var ce=0;ce<O.length;ce++){var ie=R(O,ce,ee,ne,oe+"["+ce+"]",n);if(ie instanceof Error)return ie}return null}return y(H)}function g(){function R(H,G,ae,ee,ne){var oe=H[G];if(!c(oe)){var O=Z(oe);return new S("Invalid "+ee+" `"+ne+"` of type "+("`"+O+"` supplied to `"+ae+"`, expected a single ReactElement."))}return null}return y(R)}function k(){function R(H,G,ae,ee,ne){var oe=H[G];if(!e.isValidElementType(oe)){var O=Z(oe);return new S("Invalid "+ee+" `"+ne+"` of type "+("`"+O+"` supplied to `"+ae+"`, expected a single ReactElement type."))}return null}return y(R)}function L(R){function H(G,ae,ee,ne,oe){if(!(G[ae]instanceof R)){var O=R.name||v,te=N(G[ae]);return new S("Invalid "+ne+" `"+oe+"` of type "+("`"+te+"` supplied to `"+ee+"`, expected ")+("instance of `"+O+"`."))}return null}return y(H)}function a(R){if(!Array.isArray(R))return process.env.NODE_ENV!=="production"&&(arguments.length>1?l("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])."):l("Invalid argument supplied to oneOf, expected an array.")),d;function H(G,ae,ee,ne,oe){for(var O=G[ae],te=0;te<R.length;te++)if(z(O,R[te]))return null;var ce=JSON.stringify(R,function(Ie,q){var Me=pe(q);return Me==="symbol"?String(q):q});return new S("Invalid "+ne+" `"+oe+"` of value `"+String(O)+"` "+("supplied to `"+ee+"`, expected one of "+ce+"."))}return y(H)}function _(R){function H(G,ae,ee,ne,oe){if(typeof R!="function")return new S("Property `"+oe+"` of component `"+ee+"` has invalid PropType notation inside objectOf.");var O=G[ae],te=Z(O);if(te!=="object")return new S("Invalid "+ne+" `"+oe+"` of type "+("`"+te+"` supplied to `"+ee+"`, expected an object."));for(var ce in O)if(i(O,ce)){var ie=R(O,ce,ee,ne,oe+"."+ce,n);if(ie instanceof Error)return ie}return null}return y(H)}function F(R){if(!Array.isArray(R))return process.env.NODE_ENV!=="production"&&l("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var H=0;H<R.length;H++){var G=R[H];if(typeof G!="function")return l("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+he(G)+" at index "+H+"."),d}function ae(ee,ne,oe,O,te){for(var ce=[],ie=0;ie<R.length;ie++){var Ie=R[ie],q=Ie(ee,ne,oe,O,te,n);if(q==null)return null;q.data&&i(q.data,"expectedType")&&ce.push(q.data.expectedType)}var Me=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new S("Invalid "+O+" `"+te+"` supplied to "+("`"+oe+"`"+Me+"."))}return y(ae)}function X(){function R(H,G,ae,ee,ne){return W(H[G])?null:new S("Invalid "+ee+" `"+ne+"` supplied to "+("`"+ae+"`, expected a ReactNode."))}return y(R)}function re(R,H,G,ae,ee){return new S((R||"React class")+": "+H+" type `"+G+"."+ae+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ee+"`.")}function h(R){function H(G,ae,ee,ne,oe){var O=G[ae],te=Z(O);if(te!=="object")return new S("Invalid "+ne+" `"+oe+"` of type `"+te+"` "+("supplied to `"+ee+"`, expected `object`."));for(var ce in R){var ie=R[ce];if(typeof ie!="function")return re(ee,ne,oe,ce,pe(ie));var Ie=ie(O,ce,ee,ne,oe+"."+ce,n);if(Ie)return Ie}return null}return y(H)}function V(R){function H(G,ae,ee,ne,oe){var O=G[ae],te=Z(O);if(te!=="object")return new S("Invalid "+ne+" `"+oe+"` of type `"+te+"` "+("supplied to `"+ee+"`, expected `object`."));var ce=r({},G[ae],R);for(var ie in ce){var Ie=R[ie];if(i(R,ie)&&typeof Ie!="function")return re(ee,ne,oe,ie,pe(Ie));if(!Ie)return new S("Invalid "+ne+" `"+oe+"` key `"+ie+"` supplied to `"+ee+"`.\nBad object: "+JSON.stringify(G[ae],null," ")+`
|
|
22
|
+
Valid keys: `+JSON.stringify(Object.keys(R),null," "));var q=Ie(O,ie,ee,ne,oe+"."+ie,n);if(q)return q}return null}return y(H)}function W(R){switch(typeof R){case"number":case"string":case"undefined":return!0;case"boolean":return!R;case"object":if(Array.isArray(R))return R.every(W);if(R===null||c(R))return!0;var H=x(R);if(H){var G=H.call(R),ae;if(H!==R.entries){for(;!(ae=G.next()).done;)if(!W(ae.value))return!1}else for(;!(ae=G.next()).done;){var ee=ae.value;if(ee&&!W(ee[1]))return!1}}else return!1;return!0;default:return!1}}function Q(R,H){return R==="symbol"?!0:H?H["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&H instanceof Symbol:!1}function Z(R){var H=typeof R;return Array.isArray(R)?"array":R instanceof RegExp?"object":Q(H,R)?"symbol":H}function pe(R){if(typeof R>"u"||R===null)return""+R;var H=Z(R);if(H==="object"){if(R instanceof Date)return"date";if(R instanceof RegExp)return"regexp"}return H}function he(R){var H=pe(R);switch(H){case"array":case"object":return"an "+H;case"boolean":case"date":case"regexp":return"a "+H;default:return H}}function N(R){return!R.constructor||!R.constructor.name?v:R.constructor.name}return b.checkPropTypes=s,b.resetWarningCache=s.resetWarningCache,b.PropTypes=b,b},mn}var fn,fi;function Ml(){if(fi)return fn;fi=1;var e=Rn();function r(){}function n(){}return n.resetWarningCache=r,fn=function(){function i(d,c,u,m,f,x){if(x!==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 l={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 l.PropTypes=l,l},fn}var hi;function Rl(){if(hi)return xo.exports;if(hi=1,process.env.NODE_ENV!=="production"){var e=ss(),r=!0;xo.exports=_l()(e.isElement,r)}else xo.exports=Ml()();return xo.exports}var Wl=Rl();const Ur=Bl(Wl);var fo={exports:{}},ke={};/**
|
|
23
23
|
* @license React
|
|
24
24
|
* react-is.production.js
|
|
25
25
|
*
|
|
@@ -27,7 +27,7 @@ Valid keys: `+JSON.stringify(Object.keys(O),null," "));var K=ge(P,ae,te,se,ne+"
|
|
|
27
27
|
*
|
|
28
28
|
* This source code is licensed under the MIT license found in the
|
|
29
29
|
* LICENSE file in the root directory of this source tree.
|
|
30
|
-
*/var
|
|
30
|
+
*/var gi;function Pl(){if(gi)return ke;gi=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),l=Symbol.for("react.consumer"),d=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),v=Symbol.for("react.view_transition"),b=Symbol.for("react.client.reference");function z(S){if(typeof S=="object"&&S!==null){var y=S.$$typeof;switch(y){case e:switch(S=S.type,S){case n:case s:case i:case u:case m:case v:return S;default:switch(S=S&&S.$$typeof,S){case d:case c:case x:case f:return S;case l:return S;default:return y}}case r:return y}}}return ke.ContextConsumer=l,ke.ContextProvider=d,ke.Element=e,ke.ForwardRef=c,ke.Fragment=n,ke.Lazy=x,ke.Memo=f,ke.Portal=r,ke.Profiler=s,ke.StrictMode=i,ke.Suspense=u,ke.SuspenseList=m,ke.isContextConsumer=function(S){return z(S)===l},ke.isContextProvider=function(S){return z(S)===d},ke.isElement=function(S){return typeof S=="object"&&S!==null&&S.$$typeof===e},ke.isForwardRef=function(S){return z(S)===c},ke.isFragment=function(S){return z(S)===n},ke.isLazy=function(S){return z(S)===x},ke.isMemo=function(S){return z(S)===f},ke.isPortal=function(S){return z(S)===r},ke.isProfiler=function(S){return z(S)===s},ke.isStrictMode=function(S){return z(S)===i},ke.isSuspense=function(S){return z(S)===u},ke.isSuspenseList=function(S){return z(S)===m},ke.isValidElementType=function(S){return typeof S=="string"||typeof S=="function"||S===n||S===s||S===i||S===u||S===m||typeof S=="object"&&S!==null&&(S.$$typeof===x||S.$$typeof===f||S.$$typeof===d||S.$$typeof===l||S.$$typeof===c||S.$$typeof===b||S.getModuleId!==void 0)},ke.typeOf=z,ke}var Te={};/**
|
|
31
31
|
* @license React
|
|
32
32
|
* react-is.development.js
|
|
33
33
|
*
|
|
@@ -35,16 +35,16 @@ Valid keys: `+JSON.stringify(Object.keys(O),null," "));var K=ge(P,ae,te,se,ne+"
|
|
|
35
35
|
*
|
|
36
36
|
* This source code is licensed under the MIT license found in the
|
|
37
37
|
* LICENSE file in the root directory of this source tree.
|
|
38
|
-
*/var
|
|
39
|
-
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,s]=n,
|
|
40
|
-
`)):console.error([`MUI: The \`theme.${
|
|
41
|
-
`)));const
|
|
42
|
-
`)),()=>{})}function pn(t){return Yr(t,"spacing",8,"spacing")}function qr(t,o){return typeof o=="string"||o==null?o:t(o)}function Il(t,o){return n=>t.reduce((i,s)=>(i[s]=qr(o,n),i),{})}function Bl(t,o,n,i){if(!o.includes(n))return null;const s=Tl(n),d=Il(s,i),c=t[n];return Ot(t,c,d)}function Hi(t,o){const n=pn(t.theme);return Object.keys(t).map(i=>Bl(t,o,i,n)).reduce(Ur,{})}function De(t){return Hi(t,ko)}De.propTypes=process.env.NODE_ENV!=="production"?ko.reduce((t,o)=>(t[o]=Yt,t),{}):{};De.filterProps=ko;function Oe(t){return Hi(t,To)}Oe.propTypes=process.env.NODE_ENV!=="production"?To.reduce((t,o)=>(t[o]=Yt,t),{}):{};Oe.filterProps=To;process.env.NODE_ENV!=="production"&&zl.reduce((t,o)=>(t[o]=Yt,t),{});function Ui(t=8,o=pn({spacing:t})){if(t.mui)return t;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(d=>{const c=o(d);return typeof c=="number"?`${c}px`:c}).join(" "));return n.mui=!0,n}function zo(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(d=>{i[d]=s}),i),{}),n=i=>Object.keys(i).reduce((s,d)=>o[d]?Ur(s,o[d](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=t.reduce((i,s)=>i.concat(s.filterProps),[]),n}function Qe(t){return typeof t!="number"?t:`${t}px solid`}function Ze(t,o){return $e({prop:t,themeKey:"borders",transform:o})}const El=Ze("border",Qe),Dl=Ze("borderTop",Qe),Ol=Ze("borderRight",Qe),$l=Ze("borderBottom",Qe),Al=Ze("borderLeft",Qe),Ml=Ze("borderColor"),Rl=Ze("borderTopColor"),_l=Ze("borderRightColor"),Wl=Ze("borderBottomColor"),Pl=Ze("borderLeftColor"),Ll=Ze("outline",Qe),Nl=Ze("outlineColor"),Io=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=Yr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:qr(o,i)});return Ot(t,t.borderRadius,n)}return null};Io.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Yt}:{};Io.filterProps=["borderRadius"];zo(El,Dl,Ol,$l,Al,Ml,Rl,_l,Wl,Pl,Io,Ll,Nl);const Bo=t=>{if(t.gap!==void 0&&t.gap!==null){const o=Yr(t.theme,"spacing",8,"gap"),n=i=>({gap:qr(o,i)});return Ot(t,t.gap,n)}return null};Bo.propTypes=process.env.NODE_ENV!=="production"?{gap:Yt}:{};Bo.filterProps=["gap"];const Eo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=Yr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:qr(o,i)});return Ot(t,t.columnGap,n)}return null};Eo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Yt}:{};Eo.filterProps=["columnGap"];const Do=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=Yr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:qr(o,i)});return Ot(t,t.rowGap,n)}return null};Do.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Yt}:{};Do.filterProps=["rowGap"];const Fl=$e({prop:"gridColumn"}),Vl=$e({prop:"gridRow"}),Hl=$e({prop:"gridAutoFlow"}),Ul=$e({prop:"gridAutoColumns"}),Gl=$e({prop:"gridAutoRows"}),Yl=$e({prop:"gridTemplateColumns"}),ql=$e({prop:"gridTemplateRows"}),Jl=$e({prop:"gridTemplateAreas"}),Kl=$e({prop:"gridArea"});zo(Bo,Eo,Do,Fl,Vl,Hl,Ul,Gl,Yl,ql,Jl,Kl);function Br(t,o){return o==="grey"?o:t}const Xl=$e({prop:"color",themeKey:"palette",transform:Br}),Ql=$e({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:Br}),Zl=$e({prop:"backgroundColor",themeKey:"palette",transform:Br});zo(Xl,Ql,Zl);function Ye(t){return t<=1&&t!==0?`${t*100}%`:t}const ec=$e({prop:"width",transform:Ye}),xn=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,d,c,l,p;const i=((c=(d=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:d.values)==null?void 0:c[n])||Co[n];return i?((p=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:p.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Ye(n)}};return Ot(t,t.maxWidth,o)}return null};xn.filterProps=["maxWidth"];const tc=$e({prop:"minWidth",transform:Ye}),rc=$e({prop:"height",transform:Ye}),oc=$e({prop:"maxHeight",transform:Ye}),nc=$e({prop:"minHeight",transform:Ye});$e({prop:"size",cssProperty:"width",transform:Ye});$e({prop:"size",cssProperty:"height",transform:Ye});const ic=$e({prop:"boxSizing"});zo(ec,xn,tc,rc,oc,nc,ic);const Oo={border:{themeKey:"borders",transform:Qe},borderTop:{themeKey:"borders",transform:Qe},borderRight:{themeKey:"borders",transform:Qe},borderBottom:{themeKey:"borders",transform:Qe},borderLeft:{themeKey:"borders",transform:Qe},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Qe},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Io},color:{themeKey:"palette",transform:Br},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:Br},backgroundColor:{themeKey:"palette",transform:Br},p:{style:Oe},pt:{style:Oe},pr:{style:Oe},pb:{style:Oe},pl:{style:Oe},px:{style:Oe},py:{style:Oe},padding:{style:Oe},paddingTop:{style:Oe},paddingRight:{style:Oe},paddingBottom:{style:Oe},paddingLeft:{style:Oe},paddingX:{style:Oe},paddingY:{style:Oe},paddingInline:{style:Oe},paddingInlineStart:{style:Oe},paddingInlineEnd:{style:Oe},paddingBlock:{style:Oe},paddingBlockStart:{style:Oe},paddingBlockEnd:{style:Oe},m:{style:De},mt:{style:De},mr:{style:De},mb:{style:De},ml:{style:De},mx:{style:De},my:{style:De},margin:{style:De},marginTop:{style:De},marginRight:{style:De},marginBottom:{style:De},marginLeft:{style:De},marginX:{style:De},marginY:{style:De},marginInline:{style:De},marginInlineStart:{style:De},marginInlineEnd:{style:De},marginBlock:{style:De},marginBlockStart:{style:De},marginBlockEnd:{style:De},displayPrint:{cssProperty:!1,transform:t=>({"@media print":{display:t}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:Bo},rowGap:{style:Do},columnGap:{style:Eo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ye},maxWidth:{style:xn},minWidth:{transform:Ye},height:{transform:Ye},maxHeight:{transform:Ye},minHeight:{transform:Ye},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 sc(...t){const o=t.reduce((i,s)=>i.concat(Object.keys(s)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function ac(t,o){return typeof t=="function"?t(o):t}function lc(){function t(n,i,s,d){const c={[n]:i,theme:s},l=d[n];if(!l)return{[n]:i};const{cssProperty:p=n,themeKey:f,transform:m,style:h}=l;if(i==null)return null;if(f==="typography"&&i==="inherit")return{[n]:i};const x=wo(s,f)||{};return h?h(c):Ot(c,i,E=>{let g=yo(x,m,E);return E===g&&typeof E=="string"&&(g=yo(x,m,`${n}${E==="default"?"":Vi(E)}`,E)),p===!1?g:{[p]:g}})}function o(n){const{sx:i,theme:s={},nested:d}=n||{};if(!i)return null;const c=s.unstable_sxConfig??Oo;function l(p){let f=p;if(typeof p=="function")f=p(s);else if(typeof p!="object")return p;if(!f)return null;const m=jl(s.breakpoints),h=Object.keys(m);let x=m;return Object.keys(f).forEach(b=>{const E=ac(f[b],s);if(E!=null)if(typeof E=="object")if(c[b])x=Ur(x,t(b,E,s,c));else{const g=Ot({theme:s},E,j=>({[b]:j}));sc(g,E)?x[b]=o({sx:E,theme:s,nested:!0}):x=Ur(x,g)}else x=Ur(x,t(b,E,s,c))}),!d&&s.modularCssLayers?{"@layer sx":Jn(s,Xn(h,x))}:Jn(s,Xn(h,x))}return Array.isArray(i)?i.map(l):l(i)}return o}const $o=lc();$o.filterProps=["sx"];function cc(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let s=n.getColorSchemeSelector(t);return s==="&"?o:((s.includes("data-")||s.includes("."))&&(s=`*:where(${s.replace(/\s*&$/,"")}) &`),{[s]:o})}return n.palette.mode===t?o:{}}function Gi(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:d={},...c}=t,l=fl(n),p=Ui(s);let f=Je({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:p,shape:{...vl,...d}},c);return f=bl(f),f.applyStyles=cc,f=o.reduce((m,h)=>Je(m,h),f),f.unstable_sxConfig={...Oo,...c==null?void 0:c.unstable_sxConfig},f.unstable_sx=function(h){return $o({sx:h,theme:this})},f}function dc(t){return Object.keys(t).length===0}function uc(t=null){const o=vo.useContext(Ds.ThemeContext);return!o||dc(o)?t:o}const pc=Gi();function xc(t=pc){return uc(t)}const Zn=t=>t,mc=()=>{let t=Zn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Zn}}},hc=mc(),fc={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 gc(t,o,n="Mui"){const i=fc[o];return i?`${n}-${i}`:`${hc.generate(t)}-${o}`}function yc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function mn(t,o=0,n=1){return process.env.NODE_ENV!=="production"&&(t<o||t>n)&&console.error(`MUI: The value provided ${t} is out of range [${o}, ${n}].`),yc(t,o,n)}function bc(t){t=t.slice(1);const o=new RegExp(`.{1,${t.length>=6?2:1}}`,"g");let n=t.match(o);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&t.length!==t.trim().length&&console.error(`MUI: The color: "${t}" 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 Gt(t){if(t.type)return t;if(t.charAt(0)==="#")return Gt(bc(t));const o=t.indexOf("("),n=t.substring(0,o);if(!["rgb","rgba","hsl","hsla","color"].includes(n))throw new Error(process.env.NODE_ENV!=="production"?`MUI: Unsupported \`${t}\` color.
|
|
43
|
-
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().`:
|
|
44
|
-
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:
|
|
45
|
-
`))}return
|
|
46
|
-
The color object needs to have a \`main\` property or a \`${
|
|
47
|
-
\`color.main\` should be a string, but \`${JSON.stringify(
|
|
38
|
+
*/var yi;function Nl(){return yi||(yi=1,process.env.NODE_ENV!=="production"&&(function(){function e(S){if(typeof S=="object"&&S!==null){var y=S.$$typeof;switch(y){case r:switch(S=S.type,S){case i:case l:case s:case m:case f:case b:return S;default:switch(S=S&&S.$$typeof,S){case c:case u:case v:case x:return S;case d:return S;default:return y}}case n:return y}}}var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),c=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),x=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),b=Symbol.for("react.view_transition"),z=Symbol.for("react.client.reference");Te.ContextConsumer=d,Te.ContextProvider=c,Te.Element=r,Te.ForwardRef=u,Te.Fragment=i,Te.Lazy=v,Te.Memo=x,Te.Portal=n,Te.Profiler=l,Te.StrictMode=s,Te.Suspense=m,Te.SuspenseList=f,Te.isContextConsumer=function(S){return e(S)===d},Te.isContextProvider=function(S){return e(S)===c},Te.isElement=function(S){return typeof S=="object"&&S!==null&&S.$$typeof===r},Te.isForwardRef=function(S){return e(S)===u},Te.isFragment=function(S){return e(S)===i},Te.isLazy=function(S){return e(S)===v},Te.isMemo=function(S){return e(S)===x},Te.isPortal=function(S){return e(S)===n},Te.isProfiler=function(S){return e(S)===l},Te.isStrictMode=function(S){return e(S)===s},Te.isSuspense=function(S){return e(S)===m},Te.isSuspenseList=function(S){return e(S)===f},Te.isValidElementType=function(S){return typeof S=="string"||typeof S=="function"||S===i||S===l||S===s||S===m||S===f||typeof S=="object"&&S!==null&&(S.$$typeof===v||S.$$typeof===x||S.$$typeof===c||S.$$typeof===d||S.$$typeof===u||S.$$typeof===z||S.getModuleId!==void 0)},Te.typeOf=e})()),Te}var bi;function Ll(){return bi||(bi=1,process.env.NODE_ENV==="production"?fo.exports=Pl():fo.exports=Nl()),fo.exports}var ls=Ll();function Qt(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 cs(e){if(Do.isValidElement(e)||ls.isValidElementType(e)||!Qt(e))return e;const r={};return Object.keys(e).forEach(n=>{r[n]=cs(e[n])}),r}function Ze(e,r,n={clone:!0}){const i=n.clone?{...e}:e;return Qt(e)&&Qt(r)&&Object.keys(r).forEach(s=>{Do.isValidElement(r[s])||ls.isValidElementType(r[s])?i[s]=r[s]:Qt(r[s])&&Object.prototype.hasOwnProperty.call(e,s)&&Qt(e[s])?i[s]=Ze(e[s],r[s],n):n.clone?i[s]=Qt(r[s])?cs(r[s]):r[s]:i[s]=r[s]}),i}const Fl=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 Vl(e){const{values:r={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=e,l=Fl(r),d=Object.keys(l);function c(v){return`@media (min-width:${typeof r[v]=="number"?r[v]:v}${n})`}function u(v){return`@media (max-width:${(typeof r[v]=="number"?r[v]:v)-i/100}${n})`}function m(v,b){const z=d.indexOf(b);return`@media (min-width:${typeof r[v]=="number"?r[v]:v}${n}) and (max-width:${(z!==-1&&typeof r[d[z]]=="number"?r[d[z]]:b)-i/100}${n})`}function f(v){return d.indexOf(v)+1<d.length?m(v,d[d.indexOf(v)+1]):c(v)}function x(v){const b=d.indexOf(v);return b===0?c(d[1]):b===d.length-1?u(d[b]):m(v,d[d.indexOf(v)+1]).replace("@media","@media not all and")}return{keys:d,values:l,up:c,down:u,between:m,only:f,not:x,unit:n,...s}}function vi(e,r){if(!e.containerQueries)return r;const n=Object.keys(r).filter(i=>i.startsWith("@container")).sort((i,s)=>{var d,c;const l=/min-width:\s*([0-9.]+)/;return+(((d=i.match(l))==null?void 0:d[1])||0)-+(((c=s.match(l))==null?void 0:c[1])||0)});return n.length?n.reduce((i,s)=>{const l=r[s];return delete i[s],i[s]=l,i},{...r}):r}function Hl(e,r){return r==="@"||r.startsWith("@")&&(e.some(n=>r.startsWith(`@${n}`))||!!r.match(/^@\d/))}function Ul(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>\`.
|
|
39
|
+
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,s]=n,l=Number.isNaN(+i)?i||0:+i;return e.containerQueries(s).up(l)}function Gl(e){const r=(l,d)=>l.replace("@media",d?`@container ${d}`:"@container");function n(l,d){l.up=(...c)=>r(e.breakpoints.up(...c),d),l.down=(...c)=>r(e.breakpoints.down(...c),d),l.between=(...c)=>r(e.breakpoints.between(...c),d),l.only=(...c)=>r(e.breakpoints.only(...c),d),l.not=(...c)=>{const u=r(e.breakpoints.not(...c),d);return u.includes("not all and")?u.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):u}}const i={},s=l=>(n(i,l),i);return n(s),{...e,containerQueries:s}}const Yl={borderRadius:4},tr=process.env.NODE_ENV!=="production"?Ur.oneOfType([Ur.number,Ur.string,Ur.object,Ur.array]):{};function Qr(e,r){return r?Ze(e,r,{clone:!1}):e}const Ao={xs:0,sm:600,md:900,lg:1200,xl:1536},Si={keys:["xs","sm","md","lg","xl"],up:e=>`@media (min-width:${Ao[e]}px)`},ql={containerQueries:e=>({up:r=>{let n=typeof r=="number"?r:Ao[r]||r;return typeof n=="number"&&(n=`${n}px`),e?`@container ${e} (min-width:${n})`:`@container (min-width:${n})`}})};function Nt(e,r,n){const i=e.theme||{};if(Array.isArray(r)){const l=i.breakpoints||Si;return r.reduce((d,c,u)=>(d[l.up(l.keys[u])]=n(r[u]),d),{})}if(typeof r=="object"){const l=i.breakpoints||Si;return Object.keys(r).reduce((d,c)=>{if(Hl(l.keys,c)){const u=Ul(i.containerQueries?i:ql,c);u&&(d[u]=n(r[c],c))}else if(Object.keys(l.values||Ao).includes(c)){const u=l.up(c);d[u]=n(r[c],c)}else{const u=c;d[u]=r[u]}return d},{})}return n(r)}function Jl(e={}){var n;return((n=e.keys)==null?void 0:n.reduce((i,s)=>{const l=e.up(s);return i[l]={},i},{}))||{}}function Ci(e,r){return e.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},r)}function ds(e){if(typeof e!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":vr(7));return e.charAt(0).toUpperCase()+e.slice(1)}function _o(e,r,n=!0){if(!r||typeof r!="string")return null;if(e&&e.vars&&n){const i=`vars.${r}`.split(".").reduce((s,l)=>s&&s[l]?s[l]:null,e);if(i!=null)return i}return r.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,e)}function Eo(e,r,n,i=n){let s;return typeof e=="function"?s=e(n):Array.isArray(e)?s=e[n]||i:s=_o(e,n)||i,r&&(s=r(s,i,e)),s}function $e(e){const{prop:r,cssProperty:n=e.prop,themeKey:i,transform:s}=e,l=d=>{if(d[r]==null)return null;const c=d[r],u=d.theme,m=_o(u,i)||{};return Nt(d,c,x=>{let v=Eo(m,s,x);return x===v&&typeof x=="string"&&(v=Eo(m,s,`${r}${x==="default"?"":ds(x)}`,x)),n===!1?v:{[n]:v}})};return l.propTypes=process.env.NODE_ENV!=="production"?{[r]:tr}:{},l.filterProps=[r],l}function Kl(e){const r={};return n=>(r[n]===void 0&&(r[n]=e(n)),r[n])}const Xl={m:"margin",p:"padding"},Ql={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},ji={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},Zl=Kl(e=>{if(e.length>2)if(ji[e])e=ji[e];else return[e];const[r,n]=e.split(""),i=Xl[r],s=Ql[n]||"";return Array.isArray(s)?s.map(l=>i+l):[i+s]}),Mo=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],Ro=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],ec=[...Mo,...Ro];function to(e,r,n,i){const s=_o(e,r,!0)??n;return typeof s=="number"||typeof s=="string"?l=>typeof l=="string"?l:(process.env.NODE_ENV!=="production"&&typeof l!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${l}.`),typeof s=="string"?s.startsWith("var(")&&l===0?0:s.startsWith("var(")&&l===1?s:`calc(${l} * ${s})`:s*l):Array.isArray(s)?l=>{if(typeof l=="string")return l;const d=Math.abs(l);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>s.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${d} > ${s.length-1}, you need to add the missing values.`].join(`
|
|
40
|
+
`)):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(`
|
|
41
|
+
`)));const c=s[d];return l>=0?c:typeof c=="number"?-c:typeof c=="string"&&c.startsWith("var(")?`calc(-1 * ${c})`:`-${c}`}: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(`
|
|
42
|
+
`)),()=>{})}function Wn(e){return to(e,"spacing",8,"spacing")}function ro(e,r){return typeof r=="string"||r==null?r:e(r)}function tc(e,r){return n=>e.reduce((i,s)=>(i[s]=ro(r,n),i),{})}function rc(e,r,n,i){if(!r.includes(n))return null;const s=Zl(n),l=tc(s,i),d=e[n];return Nt(e,d,l)}function us(e,r){const n=Wn(e.theme);return Object.keys(e).map(i=>rc(e,r,i,n)).reduce(Qr,{})}function Be(e){return us(e,Mo)}Be.propTypes=process.env.NODE_ENV!=="production"?Mo.reduce((e,r)=>(e[r]=tr,e),{}):{};Be.filterProps=Mo;function De(e){return us(e,Ro)}De.propTypes=process.env.NODE_ENV!=="production"?Ro.reduce((e,r)=>(e[r]=tr,e),{}):{};De.filterProps=Ro;process.env.NODE_ENV!=="production"&&ec.reduce((e,r)=>(e[r]=tr,e),{});function ps(e=8,r=Wn({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(l=>{const d=r(l);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function Wo(...e){const r=e.reduce((i,s)=>(s.filterProps.forEach(l=>{i[l]=s}),i),{}),n=i=>Object.keys(i).reduce((s,l)=>r[l]?Qr(s,r[l](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 ct(e){return typeof e!="number"?e:`${e}px solid`}function ut(e,r){return $e({prop:e,themeKey:"borders",transform:r})}const oc=ut("border",ct),nc=ut("borderTop",ct),ic=ut("borderRight",ct),sc=ut("borderBottom",ct),ac=ut("borderLeft",ct),lc=ut("borderColor"),cc=ut("borderTopColor"),dc=ut("borderRightColor"),uc=ut("borderBottomColor"),pc=ut("borderLeftColor"),xc=ut("outline",ct),mc=ut("outlineColor"),Po=e=>{if(e.borderRadius!==void 0&&e.borderRadius!==null){const r=to(e.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:ro(r,i)});return Nt(e,e.borderRadius,n)}return null};Po.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:tr}:{};Po.filterProps=["borderRadius"];Wo(oc,nc,ic,sc,ac,lc,cc,dc,uc,pc,Po,xc,mc);const No=e=>{if(e.gap!==void 0&&e.gap!==null){const r=to(e.theme,"spacing",8,"gap"),n=i=>({gap:ro(r,i)});return Nt(e,e.gap,n)}return null};No.propTypes=process.env.NODE_ENV!=="production"?{gap:tr}:{};No.filterProps=["gap"];const Lo=e=>{if(e.columnGap!==void 0&&e.columnGap!==null){const r=to(e.theme,"spacing",8,"columnGap"),n=i=>({columnGap:ro(r,i)});return Nt(e,e.columnGap,n)}return null};Lo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:tr}:{};Lo.filterProps=["columnGap"];const Fo=e=>{if(e.rowGap!==void 0&&e.rowGap!==null){const r=to(e.theme,"spacing",8,"rowGap"),n=i=>({rowGap:ro(r,i)});return Nt(e,e.rowGap,n)}return null};Fo.propTypes=process.env.NODE_ENV!=="production"?{rowGap:tr}:{};Fo.filterProps=["rowGap"];const fc=$e({prop:"gridColumn"}),hc=$e({prop:"gridRow"}),gc=$e({prop:"gridAutoFlow"}),yc=$e({prop:"gridAutoColumns"}),bc=$e({prop:"gridAutoRows"}),vc=$e({prop:"gridTemplateColumns"}),Sc=$e({prop:"gridTemplateRows"}),Cc=$e({prop:"gridTemplateAreas"}),jc=$e({prop:"gridArea"});Wo(No,Lo,Fo,fc,hc,gc,yc,bc,vc,Sc,Cc,jc);function Rr(e,r){return r==="grey"?r:e}const wc=$e({prop:"color",themeKey:"palette",transform:Rr}),kc=$e({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:Rr}),Tc=$e({prop:"backgroundColor",themeKey:"palette",transform:Rr});Wo(wc,kc,Tc);function Xe(e){return e<=1&&e!==0?`${e*100}%`:e}const Ic=$e({prop:"width",transform:Xe}),Pn=e=>{if(e.maxWidth!==void 0&&e.maxWidth!==null){const r=n=>{var s,l,d,c,u;const i=((d=(l=(s=e.theme)==null?void 0:s.breakpoints)==null?void 0:l.values)==null?void 0:d[n])||Ao[n];return i?((u=(c=e.theme)==null?void 0:c.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${e.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Xe(n)}};return Nt(e,e.maxWidth,r)}return null};Pn.filterProps=["maxWidth"];const zc=$e({prop:"minWidth",transform:Xe}),Ec=$e({prop:"height",transform:Xe}),Bc=$e({prop:"maxHeight",transform:Xe}),Dc=$e({prop:"minHeight",transform:Xe});$e({prop:"size",cssProperty:"width",transform:Xe});$e({prop:"size",cssProperty:"height",transform:Xe});const Oc=$e({prop:"boxSizing"});Wo(Ic,Pn,zc,Ec,Bc,Dc,Oc);const Vo={border:{themeKey:"borders",transform:ct},borderTop:{themeKey:"borders",transform:ct},borderRight:{themeKey:"borders",transform:ct},borderBottom:{themeKey:"borders",transform:ct},borderLeft:{themeKey:"borders",transform:ct},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:ct},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Po},color:{themeKey:"palette",transform:Rr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:Rr},backgroundColor:{themeKey:"palette",transform:Rr},p:{style:De},pt:{style:De},pr:{style:De},pb:{style:De},pl:{style:De},px:{style:De},py:{style:De},padding:{style:De},paddingTop:{style:De},paddingRight:{style:De},paddingBottom:{style:De},paddingLeft:{style:De},paddingX:{style:De},paddingY:{style:De},paddingInline:{style:De},paddingInlineStart:{style:De},paddingInlineEnd:{style:De},paddingBlock:{style:De},paddingBlockStart:{style:De},paddingBlockEnd:{style:De},m:{style:Be},mt:{style:Be},mr:{style:Be},mb:{style:Be},ml:{style:Be},mx:{style:Be},my:{style:Be},margin:{style:Be},marginTop:{style:Be},marginRight:{style:Be},marginBottom:{style:Be},marginLeft:{style:Be},marginX:{style:Be},marginY:{style:Be},marginInline:{style:Be},marginInlineStart:{style:Be},marginInlineEnd:{style:Be},marginBlock:{style:Be},marginBlockStart:{style:Be},marginBlockEnd:{style:Be},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:No},rowGap:{style:Fo},columnGap:{style:Lo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Xe},maxWidth:{style:Pn},minWidth:{transform:Xe},height:{transform:Xe},maxHeight:{transform:Xe},minHeight:{transform:Xe},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 $c(...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 Ac(e,r){return typeof e=="function"?e(r):e}function _c(){function e(n,i,s,l){const d={[n]:i,theme:s},c=l[n];if(!c)return{[n]:i};const{cssProperty:u=n,themeKey:m,transform:f,style:x}=c;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const v=_o(s,m)||{};return x?x(d):Nt(d,i,z=>{let S=Eo(v,f,z);return z===S&&typeof z=="string"&&(S=Eo(v,f,`${n}${z==="default"?"":ds(z)}`,z)),u===!1?S:{[u]:S}})}function r(n){const{sx:i,theme:s={},nested:l}=n||{};if(!i)return null;const d=s.unstable_sxConfig??Vo;function c(u){let m=u;if(typeof u=="function")m=u(s);else if(typeof u!="object")return u;if(!m)return null;const f=Jl(s.breakpoints),x=Object.keys(f);let v=f;return Object.keys(m).forEach(b=>{const z=Ac(m[b],s);if(z!=null)if(typeof z=="object")if(d[b])v=Qr(v,e(b,z,s,d));else{const S=Nt({theme:s},z,y=>({[b]:y}));$c(S,z)?v[b]=r({sx:z,theme:s,nested:!0}):v=Qr(v,S)}else v=Qr(v,e(b,z,s,d))}),!l&&s.modularCssLayers?{"@layer sx":vi(s,Ci(x,v))}:vi(s,Ci(x,v))}return Array.isArray(i)?i.map(c):c(i)}return r}const Ho=_c();Ho.filterProps=["sx"];function Mc(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 xs(e={},...r){const{breakpoints:n={},palette:i={},spacing:s,shape:l={},...d}=e,c=Vl(n),u=ps(s);let m=Ze({breakpoints:c,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...Yl,...l}},d);return m=Gl(m),m.applyStyles=Mc,m=r.reduce((f,x)=>Ze(f,x),m),m.unstable_sxConfig={...Vo,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(x){return Ho({sx:x,theme:this})},m}function Rc(e){return Object.keys(e).length===0}function Wc(e=null){const r=Do.useContext(ea.ThemeContext);return!r||Rc(r)?e:r}const Pc=xs();function Nc(e=Pc){return Wc(e)}const wi=e=>e,Lc=()=>{let e=wi;return{configure(r){e=r},generate(r){return e(r)},reset(){e=wi}}},Fc=Lc(),Vc={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 Hc(e,r,n="Mui"){const i=Vc[r];return i?`${n}-${i}`:`${Fc.generate(e)}-${r}`}function Uc(e,r=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(r,Math.min(e,n))}function Nn(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}].`),Uc(e,r,n)}function Gc(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 er(e){if(e.type)return e;if(e.charAt(0)==="#")return er(Gc(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.
|
|
43
|
+
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().`:vr(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.
|
|
44
|
+
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:vr(10,s))}else i=i.split(",");return i=i.map(l=>parseFloat(l)),{type:n,values:i,colorSpace:s}}const Yc=e=>{const r=er(e);return r.values.slice(0,3).map((n,i)=>r.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Jr=(e,r)=>{try{return Yc(e)}catch{return r&&process.env.NODE_ENV!=="production"&&console.warn(r),e}};function Uo(e){const{type:r,colorSpace:n}=e;let{values:i}=e;return r.includes("rgb")?i=i.map((s,l)=>l<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 ms(e){e=er(e);const{values:r}=e,n=r[0],i=r[1]/100,s=r[2]/100,l=i*Math.min(s,1-s),d=(m,f=(m+n/30)%12)=>s-l*Math.max(Math.min(f-3,9-f,1),-1);let c="rgb";const u=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return e.type==="hsla"&&(c+="a",u.push(r[3])),Uo({type:c,values:u})}function wn(e){e=er(e);let r=e.type==="hsl"||e.type==="hsla"?er(ms(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 ki(e,r){const n=wn(e),i=wn(r);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function D(e,r){return e=er(e),r=Nn(r),(e.type==="rgb"||e.type==="hsl")&&(e.type+="a"),e.type==="color"?e.values[3]=`/${r}`:e.values[3]=r,Uo(e)}function yr(e,r,n){try{return D(e,r)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),e}}function Go(e,r){if(e=er(e),r=Nn(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 Uo(e)}function Ce(e,r,n){try{return Go(e,r)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),e}}function Yo(e,r){if(e=er(e),r=Nn(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 Uo(e)}function je(e,r,n){try{return Yo(e,r)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),e}}function qc(e,r=.15){return wn(e)>.5?Go(e,r):Yo(e,r)}function ho(e,r,n){try{return qc(e,r)}catch{return e}}function Jc(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 Ti=(e,r,n,i=[])=>{let s=e;r.forEach((l,d)=>{d===r.length-1?Array.isArray(s)?s[Number(l)]=n:s&&typeof s=="object"&&(s[l]=n):s&&typeof s=="object"&&(s[l]||(s[l]=i.includes(l)?[]:{}),s=s[l])})},Kc=(e,r,n)=>{function i(s,l=[],d=[]){Object.entries(s).forEach(([c,u])=>{(!n||n&&!n([...l,c]))&&u!=null&&(typeof u=="object"&&Object.keys(u).length>0?i(u,[...l,c],Array.isArray(u)?[...d,c]:d):r([...l,c],u,d))})}i(e)},Xc=(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 hn(e,r){const{prefix:n,shouldSkipGeneratingVar:i}=r||{},s={},l={},d={};return Kc(e,(c,u,m)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(c,u))){const f=`--${n?`${n}-`:""}${c.join("-")}`,x=Xc(c,u);Object.assign(s,{[f]:x}),Ti(l,c,`var(${f})`,m),Ti(d,c,`var(${f}, ${x})`,m)}},c=>c[0]==="vars"),{css:s,vars:l,varsWithDefaults:d}}function Qc(e,r={}){const{getSelector:n=w,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:l}=r,{colorSchemes:d={},components:c,defaultColorScheme:u="light",...m}=e,{vars:f,css:x,varsWithDefaults:v}=hn(m,r);let b=v;const z={},{[u]:S,...y}=d;if(Object.entries(y||{}).forEach(([g,k])=>{const{vars:L,css:a,varsWithDefaults:_}=hn(k,r);b=Ze(b,_),z[g]={css:a,vars:L}}),S){const{css:g,vars:k,varsWithDefaults:L}=hn(S,r);b=Ze(b,L),z[u]={css:g,vars:k}}function w(g,k){var a,_;let L=s;if(s==="class"&&(L=".%s"),s==="data"&&(L="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(L=`[${s}="%s"]`),g){if(L==="media")return e.defaultColorScheme===g?":root":{[`@media (prefers-color-scheme: ${((_=(a=d[g])==null?void 0:a.palette)==null?void 0:_.mode)||g})`]:{":root":k}};if(L)return e.defaultColorScheme===g?`:root, ${L.replace("%s",String(g))}`:L.replace("%s",String(g))}return":root"}return{vars:b,generateThemeVars:()=>{let g={...f};return Object.entries(z).forEach(([,{vars:k}])=>{g=Ze(g,k)}),g},generateStyleSheets:()=>{var F,X;const g=[],k=e.defaultColorScheme||"light";function L(re,h){Object.keys(h).length&&g.push(typeof re=="string"?{[re]:{...h}}:re)}L(n(void 0,{...x}),x);const{[k]:a,..._}=z;if(a){const{css:re}=a,h=(X=(F=d[k])==null?void 0:F.palette)==null?void 0:X.mode,V=!i&&h?{colorScheme:h,...re}:{...re};L(n(k,{...V}),V)}return Object.entries(_).forEach(([re,{css:h}])=>{var Q,Z;const V=(Z=(Q=d[re])==null?void 0:Q.palette)==null?void 0:Z.mode,W=!i&&V?{colorScheme:V,...h}:{...h};L(n(re,{...W}),W)}),l&&g.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)"}}),g}}}function Zc(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 eo={black:"#000",white:"#fff"},ed={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"},Or={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},$r={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Gr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},Ar={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},_r={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},Mr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function fs(){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:eo.white,default:eo.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=fs();function gs(){return{text:{primary:eo.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:eo.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 kn=gs();function Ii(e,r,n,i){const s=i.light||i,l=i.dark||i*1.5;e[r]||(e.hasOwnProperty(n)?e[r]=e[n]:r==="light"?e.light=Yo(e.main,s):r==="dark"&&(e.dark=Go(e.main,l)))}function zi(e,r,n,i,s){const l=s.light||s,d=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 ${(l*100).toFixed(0)}%)`:n==="dark"&&(r.dark=`color-mix(in ${e}, ${r.main}, #000 ${(d*100).toFixed(0)}%)`))}function td(e="light"){return e==="dark"?{main:Ar[200],light:Ar[50],dark:Ar[400]}:{main:Ar[700],light:Ar[400],dark:Ar[800]}}function rd(e="light"){return e==="dark"?{main:Or[200],light:Or[50],dark:Or[400]}:{main:Or[500],light:Or[300],dark:Or[700]}}function od(e="light"){return e==="dark"?{main:$r[500],light:$r[300],dark:$r[700]}:{main:$r[700],light:$r[400],dark:$r[800]}}function nd(e="light"){return e==="dark"?{main:_r[400],light:_r[300],dark:_r[700]}:{main:_r[700],light:_r[500],dark:_r[900]}}function id(e="light"){return e==="dark"?{main:Mr[400],light:Mr[300],dark:Mr[700]}:{main:Mr[800],light:Mr[500],dark:Mr[900]}}function sd(e="light"){return e==="dark"?{main:Gr[400],light:Gr[300],dark:Gr[700]}:{main:"#ed6c02",light:Gr[500],dark:Gr[900]}}function ad(e){return`oklch(from ${e} var(--__l) 0 h / var(--__a))`}function Ln(e){const{mode:r="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...l}=e,d=e.primary||td(r),c=e.secondary||rd(r),u=e.error||od(r),m=e.info||nd(r),f=e.success||id(r),x=e.warning||sd(r);function v(y){if(s)return ad(y);const w=ki(y,kn.text.primary)>=n?kn.text.primary:hs.text.primary;if(process.env.NODE_ENV!=="production"){const C=ki(y,w);C<3&&console.error([`MUI: The contrast ratio of ${C}:1 for ${w} on ${y}`,"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(`
|
|
45
|
+
`))}return w}const b=({color:y,name:w,mainShade:C=500,lightShade:E=300,darkShade:g=700})=>{if(y={...y},!y.main&&y[C]&&(y.main=y[C]),!y.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${w?` (${w})`:""} provided to augmentColor(color) is invalid.
|
|
46
|
+
The color object needs to have a \`main\` property or a \`${C}\` property.`:vr(11,w?` (${w})`:"",C));if(typeof y.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${w?` (${w})`:""} provided to augmentColor(color) is invalid.
|
|
47
|
+
\`color.main\` should be a string, but \`${JSON.stringify(y.main)}\` was provided instead.
|
|
48
48
|
|
|
49
49
|
Did you intend to use one of the following approaches?
|
|
50
50
|
|
|
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
|
|
|
56
56
|
|
|
57
57
|
const theme2 = createTheme({ palette: {
|
|
58
58
|
primary: { main: green[500] },
|
|
59
|
-
} });`:
|
|
60
|
-
`)),Object.keys(
|
|
59
|
+
} });`:vr(12,w?` (${w})`:"",JSON.stringify(y.main)));return s?(zi(s,y,"light",E,i),zi(s,y,"dark",g,i)):(Ii(y,"light",E,i),Ii(y,"dark",g,i)),y.contrastText||(y.contrastText=v(y.main)),y};let z;return r==="light"?z=fs():r==="dark"&&(z=gs()),process.env.NODE_ENV!=="production"&&(z||console.error(`MUI: The palette mode \`${r}\` is not supported.`)),Ze({common:{...eo},mode:r,primary:b({color:d,name:"primary"}),secondary:b({color:c,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:b({color:u,name:"error"}),warning:b({color:x,name:"warning"}),info:b({color:m,name:"info"}),success:b({color:f,name:"success"}),grey:ed,contrastThreshold:n,getContrastText:v,augmentColor:b,tonalOffset:i,...z},l)}function ld(e){const r={};return Object.entries(e).forEach(i=>{const[s,l]=i;typeof l=="object"&&(r[s]=`${l.fontStyle?`${l.fontStyle} `:""}${l.fontVariant?`${l.fontVariant} `:""}${l.fontWeight?`${l.fontWeight} `:""}${l.fontStretch?`${l.fontStretch} `:""}${l.fontSize||""}${l.lineHeight?`/${l.lineHeight} `:""}${l.fontFamily||""}`)}),r}function cd(e,r){return{toolbar:{minHeight:56,[e.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[e.up("sm")]:{minHeight:64}},...r}}function dd(e){return Math.round(e*1e5)/1e5}const Ei={textTransform:"uppercase"},Bi='"Roboto", "Helvetica", "Arial", sans-serif';function ud(e,r){const{fontFamily:n=Bi,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:l=400,fontWeightMedium:d=500,fontWeightBold:c=700,htmlFontSize:u=16,allVariants:m,pxToRem:f,...x}=typeof r=="function"?r(e):r;process.env.NODE_ENV!=="production"&&(typeof i!="number"&&console.error("MUI: `fontSize` is required to be a number."),typeof u!="number"&&console.error("MUI: `htmlFontSize` is required to be a number."));const v=i/14,b=f||(y=>`${y/u*v}rem`),z=(y,w,C,E,g)=>({fontFamily:n,fontWeight:y,fontSize:b(w),lineHeight:C,...n===Bi?{letterSpacing:`${dd(E/w)}em`}:{},...g,...m}),S={h1:z(s,96,1.167,-1.5),h2:z(s,60,1.2,-.5),h3:z(l,48,1.167,0),h4:z(l,34,1.235,.25),h5:z(l,24,1.334,0),h6:z(d,20,1.6,.15),subtitle1:z(l,16,1.75,.15),subtitle2:z(d,14,1.57,.1),body1:z(l,16,1.5,.15),body2:z(l,14,1.43,.15),button:z(d,14,1.75,.4,Ei),caption:z(l,12,1.66,.4),overline:z(l,12,2.66,1,Ei),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Ze({htmlFontSize:u,pxToRem:b,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:l,fontWeightMedium:d,fontWeightBold:c,...S},x,{clone:!1})}const pd=.2,xd=.14,md=.12;function Ee(...e){return[`${e[0]}px ${e[1]}px ${e[2]}px ${e[3]}px rgba(0,0,0,${pd})`,`${e[4]}px ${e[5]}px ${e[6]}px ${e[7]}px rgba(0,0,0,${xd})`,`${e[8]}px ${e[9]}px ${e[10]}px ${e[11]}px rgba(0,0,0,${md})`].join(",")}const fd=["none",Ee(0,2,1,-1,0,1,1,0,0,1,3,0),Ee(0,3,1,-2,0,2,2,0,0,1,5,0),Ee(0,3,3,-2,0,3,4,0,0,1,8,0),Ee(0,2,4,-1,0,4,5,0,0,1,10,0),Ee(0,3,5,-1,0,5,8,0,0,1,14,0),Ee(0,3,5,-1,0,6,10,0,0,1,18,0),Ee(0,4,5,-2,0,7,10,1,0,2,16,1),Ee(0,5,5,-3,0,8,10,1,0,3,14,2),Ee(0,5,6,-3,0,9,12,1,0,3,16,2),Ee(0,6,6,-3,0,10,14,1,0,4,18,3),Ee(0,6,7,-4,0,11,15,1,0,4,20,3),Ee(0,7,8,-4,0,12,17,2,0,5,22,4),Ee(0,7,8,-4,0,13,19,2,0,5,24,4),Ee(0,7,9,-4,0,14,21,2,0,5,26,4),Ee(0,8,9,-5,0,15,22,2,0,6,28,5),Ee(0,8,10,-5,0,16,24,2,0,6,30,5),Ee(0,8,11,-5,0,17,26,2,0,6,32,5),Ee(0,9,11,-5,0,18,28,2,0,7,34,6),Ee(0,9,12,-6,0,19,29,2,0,7,36,6),Ee(0,10,13,-6,0,20,31,3,0,8,38,7),Ee(0,10,13,-6,0,21,33,3,0,8,40,7),Ee(0,10,14,-6,0,22,35,3,0,8,42,7),Ee(0,11,14,-7,0,23,36,3,0,9,44,8),Ee(0,11,15,-7,0,24,38,3,0,9,46,8)],hd={easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)",easeOut:"cubic-bezier(0.0, 0, 0.2, 1)",easeIn:"cubic-bezier(0.4, 0, 1, 1)",sharp:"cubic-bezier(0.4, 0, 0.6, 1)"},gd={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function Di(e){return`${Math.round(e)}ms`}function yd(e){if(!e)return 0;const r=e/36;return Math.min(Math.round((4+15*r**.25+r/5)*10),3e3)}function bd(e){const r={...hd,...e.easing},n={...gd,...e.duration};return{getAutoHeightDuration:yd,create:(s=["all"],l={})=>{const{duration:d=n.standard,easing:c=r.easeInOut,delay:u=0,...m}=l;if(process.env.NODE_ENV!=="production"){const f=v=>typeof v=="string",x=v=>!Number.isNaN(parseFloat(v));!f(s)&&!Array.isArray(s)&&console.error('MUI: Argument "props" must be a string or Array.'),!x(d)&&!f(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),f(c)||console.error('MUI: Argument "easing" must be a string.'),!x(u)&&!f(u)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof l!="object"&&console.error(["MUI: Secong argument of transition.create must be an object.","Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join(`
|
|
60
|
+
`)),Object.keys(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(f=>`${f} ${typeof d=="string"?d:Di(d)} ${c} ${typeof u=="string"?u:Di(u)}`).join(",")},...e,easing:r,duration:n}}const vd={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function Sd(e){return Qt(e)||typeof e>"u"||typeof e=="string"||typeof e=="boolean"||typeof e=="number"||Array.isArray(e)}function ys(e={}){const r={...e};function n(i){const s=Object.entries(i);for(let l=0;l<s.length;l++){const[d,c]=s[l];!Sd(c)||d.startsWith("unstable_")?delete i[d]:Qt(c)&&(i[d]={...c},n(i[d]))}}return n(r),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
|
|
61
61
|
|
|
62
|
-
const theme = ${JSON.stringify(
|
|
62
|
+
const theme = ${JSON.stringify(r,null,2)};
|
|
63
63
|
|
|
64
64
|
theme.breakpoints = createBreakpoints(theme.breakpoints || {});
|
|
65
65
|
theme.transitions = createTransitions(theme.transitions || {});
|
|
66
66
|
|
|
67
|
-
export default theme;`}function
|
|
68
|
-
`))}
|
|
69
|
-
To suppress this warning, you need to explicitly provide the \`palette.${o}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function nd(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const bt=t=>{try{return t()}catch{}},id=(t="mui")=>jc(t);function en(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const d=s==="dark"?"dark":"light";if(!i){o[s]=Zc({...n,palette:{mode:d,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:c,...l}=sn({...i,palette:{mode:d,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:c,opacity:{...Qi(d),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Zi(d)},l}function sd(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:d="mui",nativeColor:c=!1,shouldSkipGeneratingVar:l=ed,colorSchemeSelector:p=n.light&&n.dark?"media":void 0,rootSelector:f=":root",...m}=t,h=Object.keys(n)[0],x=i||(n.light&&h!=="light"?"light":h),b=id(d),{[x]:E,light:g,dark:j,...k}=n,v={...k};let C=E;if((x==="dark"&&!("dark"in n)||x==="light"&&!("light"in n))&&(C=!0),!C)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${x}\` option is either missing or invalid.`:cr(21,x));let S;c&&(S="oklch");const w=en(S,v,C,m,x);g&&!v.light&&en(S,v,g,void 0,"light"),j&&!v.dark&&en(S,v,j,void 0,"dark");let a={defaultColorScheme:x,...w,cssVarPrefix:d,colorSchemeSelector:p,rootSelector:f,getCssVar:b,colorSchemes:v,font:{...Mc(w.typography),...w.font},spacing:nd(m.spacing)};Object.keys(a.colorSchemes).forEach(ee=>{const y=a.colorSchemes[ee].palette,M=V=>{const X=V.split("-"),ue=X[1],ce=X[2];return b(V,y[ue][ce])};y.mode==="light"&&(L(y.common,"background","#fff"),L(y.common,"onBackground","#000")),y.mode==="dark"&&(L(y.common,"background","#000"),L(y.common,"onBackground","#fff"));function W(V,X,ue){if(S){let ce;return V===sr&&(ce=`transparent ${((1-ue)*100).toFixed(0)}%`),V===je&&(ce=`#000 ${(ue*100).toFixed(0)}%`),V===Ce&&(ce=`#fff ${(ue*100).toFixed(0)}%`),`color-mix(in ${S}, ${X}, ${ce})`}return V(X,ue)}if(od(y,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),y.mode==="light"){L(y.Alert,"errorColor",W(je,y.error.light,.6)),L(y.Alert,"infoColor",W(je,y.info.light,.6)),L(y.Alert,"successColor",W(je,y.success.light,.6)),L(y.Alert,"warningColor",W(je,y.warning.light,.6)),L(y.Alert,"errorFilledBg",M("palette-error-main")),L(y.Alert,"infoFilledBg",M("palette-info-main")),L(y.Alert,"successFilledBg",M("palette-success-main")),L(y.Alert,"warningFilledBg",M("palette-warning-main")),L(y.Alert,"errorFilledColor",bt(()=>y.getContrastText(y.error.main))),L(y.Alert,"infoFilledColor",bt(()=>y.getContrastText(y.info.main))),L(y.Alert,"successFilledColor",bt(()=>y.getContrastText(y.success.main))),L(y.Alert,"warningFilledColor",bt(()=>y.getContrastText(y.warning.main))),L(y.Alert,"errorStandardBg",W(Ce,y.error.light,.9)),L(y.Alert,"infoStandardBg",W(Ce,y.info.light,.9)),L(y.Alert,"successStandardBg",W(Ce,y.success.light,.9)),L(y.Alert,"warningStandardBg",W(Ce,y.warning.light,.9)),L(y.Alert,"errorIconColor",M("palette-error-main")),L(y.Alert,"infoIconColor",M("palette-info-main")),L(y.Alert,"successIconColor",M("palette-success-main")),L(y.Alert,"warningIconColor",M("palette-warning-main")),L(y.AppBar,"defaultBg",M("palette-grey-100")),L(y.Avatar,"defaultBg",M("palette-grey-400")),L(y.Button,"inheritContainedBg",M("palette-grey-300")),L(y.Button,"inheritContainedHoverBg",M("palette-grey-A100")),L(y.Chip,"defaultBorder",M("palette-grey-400")),L(y.Chip,"defaultAvatarColor",M("palette-grey-700")),L(y.Chip,"defaultIconColor",M("palette-grey-700")),L(y.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),L(y.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),L(y.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),L(y.LinearProgress,"primaryBg",W(Ce,y.primary.main,.62)),L(y.LinearProgress,"secondaryBg",W(Ce,y.secondary.main,.62)),L(y.LinearProgress,"errorBg",W(Ce,y.error.main,.62)),L(y.LinearProgress,"infoBg",W(Ce,y.info.main,.62)),L(y.LinearProgress,"successBg",W(Ce,y.success.main,.62)),L(y.LinearProgress,"warningBg",W(Ce,y.warning.main,.62)),L(y.Skeleton,"bg",S?W(sr,y.text.primary,.11):`rgba(${M("palette-text-primaryChannel")} / 0.11)`),L(y.Slider,"primaryTrack",W(Ce,y.primary.main,.62)),L(y.Slider,"secondaryTrack",W(Ce,y.secondary.main,.62)),L(y.Slider,"errorTrack",W(Ce,y.error.main,.62)),L(y.Slider,"infoTrack",W(Ce,y.info.main,.62)),L(y.Slider,"successTrack",W(Ce,y.success.main,.62)),L(y.Slider,"warningTrack",W(Ce,y.warning.main,.62));const V=S?W(je,y.background.default,.6825):ao(y.background.default,.8);L(y.SnackbarContent,"bg",V),L(y.SnackbarContent,"color",bt(()=>S?nn.text.primary:y.getContrastText(V))),L(y.SpeedDialAction,"fabHoverBg",ao(y.background.paper,.15)),L(y.StepConnector,"border",M("palette-grey-400")),L(y.StepContent,"border",M("palette-grey-400")),L(y.Switch,"defaultColor",M("palette-common-white")),L(y.Switch,"defaultDisabledColor",M("palette-grey-100")),L(y.Switch,"primaryDisabledColor",W(Ce,y.primary.main,.62)),L(y.Switch,"secondaryDisabledColor",W(Ce,y.secondary.main,.62)),L(y.Switch,"errorDisabledColor",W(Ce,y.error.main,.62)),L(y.Switch,"infoDisabledColor",W(Ce,y.info.main,.62)),L(y.Switch,"successDisabledColor",W(Ce,y.success.main,.62)),L(y.Switch,"warningDisabledColor",W(Ce,y.warning.main,.62)),L(y.TableCell,"border",W(Ce,W(sr,y.divider,1),.88)),L(y.Tooltip,"bg",W(sr,y.grey[700],.92))}if(y.mode==="dark"){L(y.Alert,"errorColor",W(Ce,y.error.light,.6)),L(y.Alert,"infoColor",W(Ce,y.info.light,.6)),L(y.Alert,"successColor",W(Ce,y.success.light,.6)),L(y.Alert,"warningColor",W(Ce,y.warning.light,.6)),L(y.Alert,"errorFilledBg",M("palette-error-dark")),L(y.Alert,"infoFilledBg",M("palette-info-dark")),L(y.Alert,"successFilledBg",M("palette-success-dark")),L(y.Alert,"warningFilledBg",M("palette-warning-dark")),L(y.Alert,"errorFilledColor",bt(()=>y.getContrastText(y.error.dark))),L(y.Alert,"infoFilledColor",bt(()=>y.getContrastText(y.info.dark))),L(y.Alert,"successFilledColor",bt(()=>y.getContrastText(y.success.dark))),L(y.Alert,"warningFilledColor",bt(()=>y.getContrastText(y.warning.dark))),L(y.Alert,"errorStandardBg",W(je,y.error.light,.9)),L(y.Alert,"infoStandardBg",W(je,y.info.light,.9)),L(y.Alert,"successStandardBg",W(je,y.success.light,.9)),L(y.Alert,"warningStandardBg",W(je,y.warning.light,.9)),L(y.Alert,"errorIconColor",M("palette-error-main")),L(y.Alert,"infoIconColor",M("palette-info-main")),L(y.Alert,"successIconColor",M("palette-success-main")),L(y.Alert,"warningIconColor",M("palette-warning-main")),L(y.AppBar,"defaultBg",M("palette-grey-900")),L(y.AppBar,"darkBg",M("palette-background-paper")),L(y.AppBar,"darkColor",M("palette-text-primary")),L(y.Avatar,"defaultBg",M("palette-grey-600")),L(y.Button,"inheritContainedBg",M("palette-grey-800")),L(y.Button,"inheritContainedHoverBg",M("palette-grey-700")),L(y.Chip,"defaultBorder",M("palette-grey-700")),L(y.Chip,"defaultAvatarColor",M("palette-grey-300")),L(y.Chip,"defaultIconColor",M("palette-grey-300")),L(y.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),L(y.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),L(y.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),L(y.LinearProgress,"primaryBg",W(je,y.primary.main,.5)),L(y.LinearProgress,"secondaryBg",W(je,y.secondary.main,.5)),L(y.LinearProgress,"errorBg",W(je,y.error.main,.5)),L(y.LinearProgress,"infoBg",W(je,y.info.main,.5)),L(y.LinearProgress,"successBg",W(je,y.success.main,.5)),L(y.LinearProgress,"warningBg",W(je,y.warning.main,.5)),L(y.Skeleton,"bg",S?W(sr,y.text.primary,.13):`rgba(${M("palette-text-primaryChannel")} / 0.13)`),L(y.Slider,"primaryTrack",W(je,y.primary.main,.5)),L(y.Slider,"secondaryTrack",W(je,y.secondary.main,.5)),L(y.Slider,"errorTrack",W(je,y.error.main,.5)),L(y.Slider,"infoTrack",W(je,y.info.main,.5)),L(y.Slider,"successTrack",W(je,y.success.main,.5)),L(y.Slider,"warningTrack",W(je,y.warning.main,.5));const V=S?W(Ce,y.background.default,.985):ao(y.background.default,.98);L(y.SnackbarContent,"bg",V),L(y.SnackbarContent,"color",bt(()=>S?Ji.text.primary:y.getContrastText(V))),L(y.SpeedDialAction,"fabHoverBg",ao(y.background.paper,.15)),L(y.StepConnector,"border",M("palette-grey-600")),L(y.StepContent,"border",M("palette-grey-600")),L(y.Switch,"defaultColor",M("palette-grey-300")),L(y.Switch,"defaultDisabledColor",M("palette-grey-600")),L(y.Switch,"primaryDisabledColor",W(je,y.primary.main,.55)),L(y.Switch,"secondaryDisabledColor",W(je,y.secondary.main,.55)),L(y.Switch,"errorDisabledColor",W(je,y.error.main,.55)),L(y.Switch,"infoDisabledColor",W(je,y.info.main,.55)),L(y.Switch,"successDisabledColor",W(je,y.success.main,.55)),L(y.Switch,"warningDisabledColor",W(je,y.warning.main,.55)),L(y.TableCell,"border",W(je,W(sr,y.divider,1),.68)),L(y.Tooltip,"bg",W(sr,y.grey[700],.92))}Bt(y.background,"default"),Bt(y.background,"paper"),Bt(y.common,"background"),Bt(y.common,"onBackground"),Bt(y,"divider"),Object.keys(y).forEach(V=>{const X=y[V];V!=="tonalOffset"&&X&&typeof X=="object"&&(X.main&&L(y[V],"mainChannel",Fr(Vr(X.main))),X.light&&L(y[V],"lightChannel",Fr(Vr(X.light))),X.dark&&L(y[V],"darkChannel",Fr(Vr(X.dark))),X.contrastText&&L(y[V],"contrastTextChannel",Fr(Vr(X.contrastText))),V==="text"&&(Bt(y[V],"primary"),Bt(y[V],"secondary")),V==="action"&&(X.active&&Bt(y[V],"active"),X.selected&&Bt(y[V],"selected")))})}),a=o.reduce((ee,y)=>Je(ee,y),a);const I={prefix:d,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:rd(a),enableContrastVars:c},{vars:R,generateThemeVars:G,generateStyleSheets:q}=kc(a,I);return a.vars=R,Object.entries(a.colorSchemes[a.defaultColorScheme]).forEach(([ee,y])=>{a[ee]=y}),a.generateThemeVars=G,a.generateStyleSheets=q,a.generateSpacing=function(){return Ui(m.spacing,pn(this))},a.getColorSchemeSelector=Tc(p),a.spacing=a.generateSpacing(),a.shouldSkipGeneratingVar=l,a.unstable_sxConfig={...Oo,...m==null?void 0:m.unstable_sxConfig},a.unstable_sx=function(y){return $o({sx:y,theme:this})},a.toRuntimeSource=Xi,a}function li(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:hn({...n===!0?{}:n.palette,mode:o})})}function ad(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:d=n==null?void 0:n.mode,...c}=t,l=d||"light",p=s==null?void 0:s[l],f={...s,...n?{[l]:{...typeof p!="boolean"&&p,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return sn(t,...o);let m=n;"palette"in t||f[l]&&(f[l]!==!0?m=f[l].palette:l==="dark"&&(m={mode:"dark"}));const h=sn({...t,palette:m},...o);return h.defaultColorScheme=l,h.colorSchemes=f,h.palette.mode==="light"&&(h.colorSchemes.light={...f.light!==!0&&f.light,palette:h.palette},li(h,"dark",f.dark)),h.palette.mode==="dark"&&(h.colorSchemes.dark={...f.dark!==!0&&f.dark,palette:h.palette},li(h,"light",f.light)),h}return!n&&!("light"in f)&&l==="light"&&(f.light=!0),sd({...c,colorSchemes:f,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const ld=ad();function $t(){const t=xc(ld);return process.env.NODE_ENV!=="production"&&vo.useDebugValue(t),t[rl]||t}async function cd(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const s=new AbortController,d=setTimeout(()=>s.abort(),3e4);let c;try{c=await fetch(t,{headers:i,signal:s.signal})}catch(f){throw clearTimeout(d),(f==null?void 0:f.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(d)}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 m=["data","results","items","records"].find(h=>l[h]&&Array.isArray(l[h]));if(m)p=l[m];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:p,source:t,fetchedAt:new Date().toISOString()}}function dd(t,o){return o.map(n=>`${n.x}px ${n.y}px ${n.blur}px ${n.spread}px ${z(t.palette.common.black,n.opacity)}`).join(", ")}const ud={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 oe(t,o){return dd(t,ud[o])}function _e(t){return`${Number(t.shape.borderRadius)*1.5}px`}function Jr(t){return`${Number(t.shape.borderRadius)}px`}function pd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[d,c]=u.useState(""),[l,p]=u.useState(!1),[f,m]=u.useState(""),[h,x]=u.useState(null),[b,E]=u.useState(null),[g,j]=u.useState(!1),[k,v]=u.useState(""),C=u.useRef(null),[S,w]=u.useState("json"),[a,I]=u.useState(""),[R,G]=u.useState(""),[q,ee]=u.useState(""),[y,M]=u.useState("idle"),[W,V]=u.useState(""),[X,ue]=u.useState(null),[ce,F]=u.useState(0),O=async P=>{if(v(""),!P.name.endsWith(".json")){v("Only .json files are allowed");return}const ie=10*1024*1024;if(P.size>ie){v("File size exceeds 10MB limit");return}try{const de=await P.text();let ae;try{ae=JSON.parse(de)}catch{v("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ae)){v("JSON must be an array of objects");return}if(ae.length===0){v("No data rows found in JSON file");return}x(P),E(ae)}catch{v("Network error — please try again")}},H=P=>{P.preventDefault();const ie=P.dataTransfer.files[0];ie&&O(ie)},re=async()=>{if(a.trim()){M("loading"),V("");try{const P=await cd(a.trim(),R.trim()||void 0,q.trim()||void 0);ue(P.data),F(P.data.length),M("ready")}catch(P){V((P==null?void 0:P.message)||"Connection failed"),M("error")}}},U=()=>{if(!d.trim()){p(!0);return}const P=S==="api"?X:i||b;P&&(n(d.trim(),f.trim(),P),te())},te=()=>{c(""),p(!1),m(""),x(null),E(null),v(""),w("json"),I(""),G(""),ee(""),M("idle"),V(""),ue(null),F(0),o()},se=i||b,ne=l&&!d.trim();return d.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:te,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:P=>_e(P),width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:P=>oe(P,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:te,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[e.jsx(r.TextField,{label:"Report name",required:!0,fullWidth:!0,value:d,onChange:P=>{c(P.target.value),l&&P.target.value.trim()&&p(!1)},placeholder:"Enter report name",autoFocus:!0,error:ne,helperText:ne?"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}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:f,onChange:P=>m(P.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}}}}),e.jsxs(r.Tabs,{value:S==="json"?0:1,onChange:(P,ie)=>{w(ie===0?"json":"api"),M("idle"),V("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(B.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}}),e.jsx(r.Tab,{label:"Connect API",icon:e.jsx(B.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),S==="json"&&e.jsx(r.Box,{children:i?e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:P=>z(P.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:P=>z(P.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(B.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(B.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:H,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=C.current)==null?void 0:P.click()},sx:{position:"relative",border:"1.5px",borderStyle:b?"solid":"dashed",borderColor:b?"success.main":k?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:b?P=>z(P.palette.success.main,.04):k?P=>z(P.palette.error.main,.04):P=>z(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:b?P=>z(P.palette.success.main,.08):k?P=>z(P.palette.error.main,.08):P=>z(P.palette.primary.main,.08),borderColor:b?"success.dark":k?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:C,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var ie;return((ie=P.target.files)==null?void 0:ie[0])&&O(P.target.files[0])}}),b?e.jsxs(r.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:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:P=>z(P.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(B.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:h==null?void 0:h.name}),e.jsx(r.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):e.jsxs(r.Box,{children:[e.jsx(r.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:P=>z(P.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(B.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),k&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:P=>z(P.palette.error.main,.08),border:1,borderColor:P=>z(P.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:k})})]})]})]})}),S==="api"&&e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx(r.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:a,onChange:P=>{I(P.target.value),M("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}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:R,onChange:P=>G(P.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(B.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}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:q,onChange:P=>ee(P.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}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!a.trim()||y==="loading",onClick:re,startIcon:y==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(B.Api,{}),sx:{fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:P=>z(P.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:y==="loading"?"Connecting...":"Test Connection & Load Data"}),y==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:P=>z(P.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(B.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[ce.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:a})]})]}),y==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>z(P.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(B.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:W})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:te,variant:"text",sx:{color:"primary.main",fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>z(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:U,disabled:S==="json"&&!se||S==="api"&&y!=="ready",variant:"contained",sx:{fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64,"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:g,onClose:()=>j(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",e.jsx(r.IconButton,{onClick:()=>j(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.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."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.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:`[
|
|
67
|
+
export default theme;`}function Oi(e){return typeof e=="number"?`${(e*100).toFixed(0)}%`:`calc((${e}) * 100%)`}const Cd=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 jd(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,Cd(n))},lighten(r,n){const i=this||e;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${r}, #fff ${Oi(n)})`:Yo(r,n)},darken(r,n){const i=this||e;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${r}, #000 ${Oi(n)})`:Go(r,n)}})}function Tn(e={},...r){const{breakpoints:n,mixins:i={},spacing:s,palette:l={},transitions:d={},typography:c={},shape:u,colorSpace:m,...f}=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.":vr(20));const x=Ln({...l,colorSpace:m}),v=xs(e);let b=Ze(v,{mixins:cd(v.breakpoints,i),palette:x,shadows:fd.slice(),typography:ud(x,c),transitions:bd(d),zIndex:{...vd}});if(b=Ze(b,f),b=r.reduce((z,S)=>Ze(z,S),b),process.env.NODE_ENV!=="production"){const z=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],S=(y,w)=>{let C;for(C in y){const E=y[C];if(z.includes(C)&&Object.keys(E).length>0){if(process.env.NODE_ENV!=="production"){const g=Hc("",C);console.error([`MUI: The \`${w}\` component increases the CSS specificity of the \`${C}\` internal state.`,"You can not override it like this: ",JSON.stringify(y,null,2),"",`Instead, you need to use the '&.${g}' syntax:`,JSON.stringify({root:{[`&.${g}`]:E}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
|
|
68
|
+
`))}y[C]={}}}};Object.keys(b.components).forEach(y=>{const w=b.components[y].styleOverrides;w&&y.startsWith("Mui")&&S(w,y)})}return b.unstable_sxConfig={...Vo,...f==null?void 0:f.unstable_sxConfig},b.unstable_sx=function(S){return Ho({sx:S,theme:this})},b.toRuntimeSource=ys,jd(b),b}function wd(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 kd=[...Array(25)].map((e,r)=>{if(r===0)return"none";const n=wd(r);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function bs(e){return{inputPlaceholder:e==="dark"?.5:.42,inputUnderline:e==="dark"?.7:.42,switchTrackDisabled:e==="dark"?.2:.12,switchTrack:e==="dark"?.3:.38}}function vs(e){return e==="dark"?kd:[]}function Td(e){const{palette:r={mode:"light"},opacity:n,overlays:i,colorSpace:s,...l}=e,d=Ln({...r,colorSpace:s});return{palette:d,opacity:{...bs(d.mode),...n},overlays:i||vs(d.mode),...l}}function Id(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 zd=e=>[...[...Array(25)].map((r,n)=>`--${e?`${e}-`:""}overlays-${n}`),`--${e?`${e}-`:""}palette-AppBar-darkBg`,`--${e?`${e}-`:""}palette-AppBar-darkColor`],Ed=e=>(r,n)=>{const i=e.rootSelector||":root",s=e.colorSchemeSelector;let l=s;if(s==="class"&&(l=".%s"),s==="data"&&(l="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(l=`[${s}="%s"]`),e.defaultColorScheme===r){if(r==="dark"){const d={};return zd(e.cssVarPrefix).forEach(c=>{d[c]=n[c],delete n[c]}),l==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:d}}:l?{[l.replace("%s",r)]:d,[`${i}, ${l.replace("%s",r)}`]:n}:{[i]:{...n,...d}}}if(l&&l!=="media")return`${i}, ${l.replace("%s",String(r))}`}else if(r){if(l==="media")return{[`@media (prefers-color-scheme: ${String(r)})`]:{[i]:n}};if(l)return l.replace("%s",String(r))}return i};function Bd(e,r){r.forEach(n=>{e[n]||(e[n]={})})}function M(e,r,n){!e[r]&&n&&(e[r]=n)}function Kr(e){return typeof e!="string"||!e.startsWith("hsl")?e:ms(e)}function Wt(e,r){`${r}Channel`in e||(e[`${r}Channel`]=Jr(Kr(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().
|
|
69
|
+
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 Dd(e){return typeof e=="number"?`${e}px`:typeof e=="string"||typeof e=="function"||Array.isArray(e)?e:"8px"}const It=e=>{try{return e()}catch{}},Od=(e="mui")=>Jc(e);function gn(e,r,n,i,s){if(!n)return;n=n===!0?{}:n;const l=s==="dark"?"dark":"light";if(!i){r[s]=Td({...n,palette:{mode:l,...n==null?void 0:n.palette},colorSpace:e});return}const{palette:d,...c}=Tn({...i,palette:{mode:l,...n==null?void 0:n.palette},colorSpace:e});return r[s]={...n,palette:d,opacity:{...bs(l),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||vs(l)},c}function $d(e={},...r){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:l="mui",nativeColor:d=!1,shouldSkipGeneratingVar:c=Id,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...f}=e,x=Object.keys(n)[0],v=i||(n.light&&x!=="light"?"light":x),b=Od(l),{[v]:z,light:S,dark:y,...w}=n,C={...w};let E=z;if((v==="dark"&&!("dark"in n)||v==="light"&&!("light"in n))&&(E=!0),!E)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${v}\` option is either missing or invalid.`:vr(21,v));let g;d&&(g="oklch");const k=gn(g,C,E,f,v);S&&!C.light&&gn(g,C,S,void 0,"light"),y&&!C.dark&&gn(g,C,y,void 0,"dark");let L={defaultColorScheme:v,...k,cssVarPrefix:l,colorSchemeSelector:u,rootSelector:m,getCssVar:b,colorSchemes:C,font:{...ld(k.typography),...k.font},spacing:Dd(f.spacing)};Object.keys(L.colorSchemes).forEach(re=>{const h=L.colorSchemes[re].palette,V=Q=>{const Z=Q.split("-"),pe=Z[1],he=Z[2];return b(Q,h[pe][he])};h.mode==="light"&&(M(h.common,"background","#fff"),M(h.common,"onBackground","#000")),h.mode==="dark"&&(M(h.common,"background","#000"),M(h.common,"onBackground","#fff"));function W(Q,Z,pe){if(g){let he;return Q===yr&&(he=`transparent ${((1-pe)*100).toFixed(0)}%`),Q===Ce&&(he=`#000 ${(pe*100).toFixed(0)}%`),Q===je&&(he=`#fff ${(pe*100).toFixed(0)}%`),`color-mix(in ${g}, ${Z}, ${he})`}return Q(Z,pe)}if(Bd(h,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),h.mode==="light"){M(h.Alert,"errorColor",W(Ce,h.error.light,.6)),M(h.Alert,"infoColor",W(Ce,h.info.light,.6)),M(h.Alert,"successColor",W(Ce,h.success.light,.6)),M(h.Alert,"warningColor",W(Ce,h.warning.light,.6)),M(h.Alert,"errorFilledBg",V("palette-error-main")),M(h.Alert,"infoFilledBg",V("palette-info-main")),M(h.Alert,"successFilledBg",V("palette-success-main")),M(h.Alert,"warningFilledBg",V("palette-warning-main")),M(h.Alert,"errorFilledColor",It(()=>h.getContrastText(h.error.main))),M(h.Alert,"infoFilledColor",It(()=>h.getContrastText(h.info.main))),M(h.Alert,"successFilledColor",It(()=>h.getContrastText(h.success.main))),M(h.Alert,"warningFilledColor",It(()=>h.getContrastText(h.warning.main))),M(h.Alert,"errorStandardBg",W(je,h.error.light,.9)),M(h.Alert,"infoStandardBg",W(je,h.info.light,.9)),M(h.Alert,"successStandardBg",W(je,h.success.light,.9)),M(h.Alert,"warningStandardBg",W(je,h.warning.light,.9)),M(h.Alert,"errorIconColor",V("palette-error-main")),M(h.Alert,"infoIconColor",V("palette-info-main")),M(h.Alert,"successIconColor",V("palette-success-main")),M(h.Alert,"warningIconColor",V("palette-warning-main")),M(h.AppBar,"defaultBg",V("palette-grey-100")),M(h.Avatar,"defaultBg",V("palette-grey-400")),M(h.Button,"inheritContainedBg",V("palette-grey-300")),M(h.Button,"inheritContainedHoverBg",V("palette-grey-A100")),M(h.Chip,"defaultBorder",V("palette-grey-400")),M(h.Chip,"defaultAvatarColor",V("palette-grey-700")),M(h.Chip,"defaultIconColor",V("palette-grey-700")),M(h.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),M(h.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),M(h.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),M(h.LinearProgress,"primaryBg",W(je,h.primary.main,.62)),M(h.LinearProgress,"secondaryBg",W(je,h.secondary.main,.62)),M(h.LinearProgress,"errorBg",W(je,h.error.main,.62)),M(h.LinearProgress,"infoBg",W(je,h.info.main,.62)),M(h.LinearProgress,"successBg",W(je,h.success.main,.62)),M(h.LinearProgress,"warningBg",W(je,h.warning.main,.62)),M(h.Skeleton,"bg",g?W(yr,h.text.primary,.11):`rgba(${V("palette-text-primaryChannel")} / 0.11)`),M(h.Slider,"primaryTrack",W(je,h.primary.main,.62)),M(h.Slider,"secondaryTrack",W(je,h.secondary.main,.62)),M(h.Slider,"errorTrack",W(je,h.error.main,.62)),M(h.Slider,"infoTrack",W(je,h.info.main,.62)),M(h.Slider,"successTrack",W(je,h.success.main,.62)),M(h.Slider,"warningTrack",W(je,h.warning.main,.62));const Q=g?W(Ce,h.background.default,.6825):ho(h.background.default,.8);M(h.SnackbarContent,"bg",Q),M(h.SnackbarContent,"color",It(()=>g?kn.text.primary:h.getContrastText(Q))),M(h.SpeedDialAction,"fabHoverBg",ho(h.background.paper,.15)),M(h.StepConnector,"border",V("palette-grey-400")),M(h.StepContent,"border",V("palette-grey-400")),M(h.Switch,"defaultColor",V("palette-common-white")),M(h.Switch,"defaultDisabledColor",V("palette-grey-100")),M(h.Switch,"primaryDisabledColor",W(je,h.primary.main,.62)),M(h.Switch,"secondaryDisabledColor",W(je,h.secondary.main,.62)),M(h.Switch,"errorDisabledColor",W(je,h.error.main,.62)),M(h.Switch,"infoDisabledColor",W(je,h.info.main,.62)),M(h.Switch,"successDisabledColor",W(je,h.success.main,.62)),M(h.Switch,"warningDisabledColor",W(je,h.warning.main,.62)),M(h.TableCell,"border",W(je,W(yr,h.divider,1),.88)),M(h.Tooltip,"bg",W(yr,h.grey[700],.92))}if(h.mode==="dark"){M(h.Alert,"errorColor",W(je,h.error.light,.6)),M(h.Alert,"infoColor",W(je,h.info.light,.6)),M(h.Alert,"successColor",W(je,h.success.light,.6)),M(h.Alert,"warningColor",W(je,h.warning.light,.6)),M(h.Alert,"errorFilledBg",V("palette-error-dark")),M(h.Alert,"infoFilledBg",V("palette-info-dark")),M(h.Alert,"successFilledBg",V("palette-success-dark")),M(h.Alert,"warningFilledBg",V("palette-warning-dark")),M(h.Alert,"errorFilledColor",It(()=>h.getContrastText(h.error.dark))),M(h.Alert,"infoFilledColor",It(()=>h.getContrastText(h.info.dark))),M(h.Alert,"successFilledColor",It(()=>h.getContrastText(h.success.dark))),M(h.Alert,"warningFilledColor",It(()=>h.getContrastText(h.warning.dark))),M(h.Alert,"errorStandardBg",W(Ce,h.error.light,.9)),M(h.Alert,"infoStandardBg",W(Ce,h.info.light,.9)),M(h.Alert,"successStandardBg",W(Ce,h.success.light,.9)),M(h.Alert,"warningStandardBg",W(Ce,h.warning.light,.9)),M(h.Alert,"errorIconColor",V("palette-error-main")),M(h.Alert,"infoIconColor",V("palette-info-main")),M(h.Alert,"successIconColor",V("palette-success-main")),M(h.Alert,"warningIconColor",V("palette-warning-main")),M(h.AppBar,"defaultBg",V("palette-grey-900")),M(h.AppBar,"darkBg",V("palette-background-paper")),M(h.AppBar,"darkColor",V("palette-text-primary")),M(h.Avatar,"defaultBg",V("palette-grey-600")),M(h.Button,"inheritContainedBg",V("palette-grey-800")),M(h.Button,"inheritContainedHoverBg",V("palette-grey-700")),M(h.Chip,"defaultBorder",V("palette-grey-700")),M(h.Chip,"defaultAvatarColor",V("palette-grey-300")),M(h.Chip,"defaultIconColor",V("palette-grey-300")),M(h.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),M(h.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),M(h.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),M(h.LinearProgress,"primaryBg",W(Ce,h.primary.main,.5)),M(h.LinearProgress,"secondaryBg",W(Ce,h.secondary.main,.5)),M(h.LinearProgress,"errorBg",W(Ce,h.error.main,.5)),M(h.LinearProgress,"infoBg",W(Ce,h.info.main,.5)),M(h.LinearProgress,"successBg",W(Ce,h.success.main,.5)),M(h.LinearProgress,"warningBg",W(Ce,h.warning.main,.5)),M(h.Skeleton,"bg",g?W(yr,h.text.primary,.13):`rgba(${V("palette-text-primaryChannel")} / 0.13)`),M(h.Slider,"primaryTrack",W(Ce,h.primary.main,.5)),M(h.Slider,"secondaryTrack",W(Ce,h.secondary.main,.5)),M(h.Slider,"errorTrack",W(Ce,h.error.main,.5)),M(h.Slider,"infoTrack",W(Ce,h.info.main,.5)),M(h.Slider,"successTrack",W(Ce,h.success.main,.5)),M(h.Slider,"warningTrack",W(Ce,h.warning.main,.5));const Q=g?W(je,h.background.default,.985):ho(h.background.default,.98);M(h.SnackbarContent,"bg",Q),M(h.SnackbarContent,"color",It(()=>g?hs.text.primary:h.getContrastText(Q))),M(h.SpeedDialAction,"fabHoverBg",ho(h.background.paper,.15)),M(h.StepConnector,"border",V("palette-grey-600")),M(h.StepContent,"border",V("palette-grey-600")),M(h.Switch,"defaultColor",V("palette-grey-300")),M(h.Switch,"defaultDisabledColor",V("palette-grey-600")),M(h.Switch,"primaryDisabledColor",W(Ce,h.primary.main,.55)),M(h.Switch,"secondaryDisabledColor",W(Ce,h.secondary.main,.55)),M(h.Switch,"errorDisabledColor",W(Ce,h.error.main,.55)),M(h.Switch,"infoDisabledColor",W(Ce,h.info.main,.55)),M(h.Switch,"successDisabledColor",W(Ce,h.success.main,.55)),M(h.Switch,"warningDisabledColor",W(Ce,h.warning.main,.55)),M(h.TableCell,"border",W(Ce,W(yr,h.divider,1),.68)),M(h.Tooltip,"bg",W(yr,h.grey[700],.92))}Wt(h.background,"default"),Wt(h.background,"paper"),Wt(h.common,"background"),Wt(h.common,"onBackground"),Wt(h,"divider"),Object.keys(h).forEach(Q=>{const Z=h[Q];Q!=="tonalOffset"&&Z&&typeof Z=="object"&&(Z.main&&M(h[Q],"mainChannel",Jr(Kr(Z.main))),Z.light&&M(h[Q],"lightChannel",Jr(Kr(Z.light))),Z.dark&&M(h[Q],"darkChannel",Jr(Kr(Z.dark))),Z.contrastText&&M(h[Q],"contrastTextChannel",Jr(Kr(Z.contrastText))),Q==="text"&&(Wt(h[Q],"primary"),Wt(h[Q],"secondary")),Q==="action"&&(Z.active&&Wt(h[Q],"active"),Z.selected&&Wt(h[Q],"selected")))})}),L=r.reduce((re,h)=>Ze(re,h),L);const a={prefix:l,disableCssColorScheme:s,shouldSkipGeneratingVar:c,getSelector:Ed(L),enableContrastVars:d},{vars:_,generateThemeVars:F,generateStyleSheets:X}=Qc(L,a);return L.vars=_,Object.entries(L.colorSchemes[L.defaultColorScheme]).forEach(([re,h])=>{L[re]=h}),L.generateThemeVars=F,L.generateStyleSheets=X,L.generateSpacing=function(){return ps(f.spacing,Wn(this))},L.getColorSchemeSelector=Zc(u),L.spacing=L.generateSpacing(),L.shouldSkipGeneratingVar=c,L.unstable_sxConfig={...Vo,...f==null?void 0:f.unstable_sxConfig},L.unstable_sx=function(h){return Ho({sx:h,theme:this})},L.toRuntimeSource=ys,L}function $i(e,r,n){e.colorSchemes&&n&&(e.colorSchemes[r]={...n!==!0&&n,palette:Ln({...n===!0?{}:n.palette,mode:r})})}function Ad(e={},...r){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:l=n==null?void 0:n.mode,...d}=e,c=l||"light",u=s==null?void 0:s[c],m={...s,...n?{[c]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in e))return Tn(e,...r);let f=n;"palette"in e||m[c]&&(m[c]!==!0?f=m[c].palette:c==="dark"&&(f={mode:"dark"}));const x=Tn({...e,palette:f},...r);return x.defaultColorScheme=c,x.colorSchemes=m,x.palette.mode==="light"&&(x.colorSchemes.light={...m.light!==!0&&m.light,palette:x.palette},$i(x,"dark",m.dark)),x.palette.mode==="dark"&&(x.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:x.palette},$i(x,"light",m.light)),x}return!n&&!("light"in m)&&c==="light"&&(m.light=!0),$d({...d,colorSchemes:m,defaultColorScheme:c,...typeof i!="boolean"&&i},...r)}const _d=Ad();function Lt(){const e=Nc(_d);return process.env.NODE_ENV!=="production"&&Do.useDebugValue(e),e[El]||e}async function Md(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,l=setTimeout(()=>s.abort(),3e4);let d;try{d=await fetch(e,{headers:i,signal:s.signal})}catch(m){throw clearTimeout(l),(m==null?void 0:m.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(l)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let c;try{c=await d.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(c))u=c;else if(n&&c[n]&&Array.isArray(c[n]))u=c[n];else{const f=["data","results","items","records"].find(x=>c[x]&&Array.isArray(c[x]));if(f)u=c[f];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:u,source:e,fetchedAt:new Date().toISOString()}}function Rd(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 Wd={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 se(e,r){return Rd(e,Wd[r])}function Ne(e){return`${Number(e.shape.borderRadius)*1.5}px`}function oo(e){return`${Number(e.shape.borderRadius)}px`}function Pd({isOpen:e,onClose:r,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[l,d]=p.useState(""),[c,u]=p.useState(!1),[m,f]=p.useState(""),[x,v]=p.useState(null),[b,z]=p.useState(null),[S,y]=p.useState(!1),[w,C]=p.useState(""),E=p.useRef(null),[g,k]=p.useState("json"),[L,a]=p.useState(""),[_,F]=p.useState(""),[X,re]=p.useState(""),[h,V]=p.useState("idle"),[W,Q]=p.useState(""),[Z,pe]=p.useState(null),[he,N]=p.useState(0),R=async O=>{if(C(""),!O.name.endsWith(".json")){C("Only .json files are allowed");return}const te=10*1024*1024;if(O.size>te){C("File size exceeds 10MB limit");return}try{const ce=await O.text();let ie;try{ie=JSON.parse(ce)}catch{C("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ie)){C("JSON must be an array of objects");return}if(ie.length===0){C("No data rows found in JSON file");return}v(O),z(ie)}catch{C("Network error — please try again")}},H=O=>{O.preventDefault();const te=O.dataTransfer.files[0];te&&R(te)},G=async()=>{if(L.trim()){V("loading"),Q("");try{const O=await Md(L.trim(),_.trim()||void 0,X.trim()||void 0);pe(O.data),N(O.data.length),V("ready")}catch(O){Q((O==null?void 0:O.message)||"Connection failed"),V("error")}}},ae=()=>{if(!l.trim()){u(!0);return}const O=g==="api"?Z:i||b;O&&(n(l.trim(),m.trim(),O),ee())},ee=()=>{d(""),u(!1),f(""),v(null),z(null),C(""),k("json"),a(""),F(""),re(""),V("idle"),Q(""),pe(null),N(0),r()},ne=i||b,oe=c&&!l.trim();return l.trim(),t.jsxs(t.Fragment,{children:[t.jsxs(o.Dialog,{open:e,onClose:ee,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:O=>Ne(O),width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:O=>se(O,"menu")}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",t.jsx(o.IconButton,{onClick:ee,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx(T.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:l,onChange:O=>{d(O.target.value),c&&O.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:oe,helperText:oe?"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:m,onChange:O=>f(O.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:g==="json"?0:1,onChange:(O,te)=>{k(te===0?"json":"api"),V("idle"),Q("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[t.jsx(o.Tab,{label:"Upload JSON",icon:t.jsx(T.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}}),t.jsx(o.Tab,{label:"Connect API",icon:t.jsx(T.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),g==="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:O=>D(O.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[t.jsx(o.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:O=>D(O.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(T.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:()=>y(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:t.jsx(T.Info,{sx:{fontSize:16}})})]}),t.jsxs(o.Box,{onDrop:H,onDragOver:O=>O.preventDefault(),onPaste:O=>O.preventDefault(),onClick:()=>{var O;return(O=E.current)==null?void 0:O.click()},sx:{position:"relative",border:"1.5px",borderStyle:b?"solid":"dashed",borderColor:b?"success.main":w?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:b?O=>D(O.palette.success.main,.04):w?O=>D(O.palette.error.main,.04):O=>D(O.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:b?O=>D(O.palette.success.main,.08):w?O=>D(O.palette.error.main,.08):O=>D(O.palette.primary.main,.08),borderColor:b?"success.dark":w?"error.dark":"primary.dark"}},children:[t.jsx(o.Box,{component:"input",ref:E,type:"file",accept:".json",sx:{display:"none"},onChange:O=>{var te;return((te=O.target.files)==null?void 0:te[0])&&R(O.target.files[0])}}),b?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:O=>D(O.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:t.jsx(T.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:x==null?void 0:x.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:O=>D(O.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:t.jsx(T.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"}),w&&t.jsx(o.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:O=>D(O.palette.error.main,.08),border:1,borderColor:O=>D(O.palette.error.main,.2)},children:t.jsx(o.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:w})})]})]})]})}),g==="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:L,onChange:O=>{a(O.target.value),V("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:_,onChange:O=>F(O.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:t.jsx(o.InputAdornment,{position:"start",children:t.jsx(T.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:X,onChange:O=>re(O.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:!L.trim()||h==="loading",onClick:G,startIcon:h==="loading"?t.jsx(o.CircularProgress,{size:16,color:"inherit"}):t.jsx(T.Api,{}),sx:{fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:O=>D(O.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:h==="loading"?"Connecting...":"Test Connection & Load Data"}),h==="ready"&&t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:O=>D(O.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx(T.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:[he.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:L})]})]}),h==="error"&&t.jsxs(o.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:O=>D(O.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[t.jsx(T.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:W})]})]})]})]})}),t.jsxs(o.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[t.jsx(o.Button,{onClick:ee,variant:"text",sx:{color:"primary.main",fontSize:"0.875rem",borderRadius:O=>`${O.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:O=>D(O.palette.primary.main,.04)}},children:"Cancel"}),t.jsx(o.Button,{onClick:ae,disabled:g==="json"&&!ne||g==="api"&&h!=="ready",variant:"contained",sx:{fontSize:"0.875rem",borderRadius:O=>`${O.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64,"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),t.jsxs(o.Dialog,{open:S,onClose:()=>y(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",t.jsx(o.IconButton,{onClick:()=>y(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:t.jsx(T.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:`[
|
|
70
70
|
{
|
|
71
71
|
"id": 1,
|
|
72
72
|
"customerName": "John Smith",
|
|
@@ -76,7 +76,7 @@ To suppress this warning, you need to explicitly provide the \`palette.${o}Chann
|
|
|
76
76
|
"memberSince": "2024-01-15",
|
|
77
77
|
"status": "active"
|
|
78
78
|
}
|
|
79
|
-
]`})]}),
|
|
79
|
+
]`})]}),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:()=>y(!1),variant:"contained",sx:{fontSize:"0.875rem",borderRadius:O=>`${O.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64},children:"Got it"})})]})]})}function Ss({isOpen:e,onClose:r}){return e?t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:n=>Ne(n),maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:n=>se(n,"menu"),display:"flex",flexDirection:"column"}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["JSON Format Guide",t.jsx(o.IconButton,{onClick:r,size:"small",sx:{color:"text.secondary"},children:t.jsx(T.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:`[
|
|
80
80
|
{
|
|
81
81
|
"Active Sessions": 33,
|
|
82
82
|
"Active State": true,
|
|
@@ -86,10 +86,10 @@ To suppress this warning, you need to explicitly provide the \`palette.${o}Chann
|
|
|
86
86
|
"Region": "Europe",
|
|
87
87
|
"Subscription Type": "Basic"
|
|
88
88
|
}
|
|
89
|
-
]`})})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Supported Column Types"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"The system automatically detects column types from your data:"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Number:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Numeric values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"33"}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"42.5"}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Boolean:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["True/false values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"true"}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"false"}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"String:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Text values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Europe"'}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Analytics Pro"'}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Date:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["ISO date strings (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"2024-08-22"'}),")"]})]})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Notes"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2.5,"& li":{fontSize:"body2.fontSize",color:"text.secondary",mb:.5}},children:[e.jsx("li",{children:"Each object in the array represents one row in the report."}),e.jsx("li",{children:"The keys of the JSON objects become report columns."}),e.jsx("li",{children:"All objects should have consistent keys for proper column detection."}),e.jsx("li",{children:"Column names are case-sensitive and preserve spacing."})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,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=>oe(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>oe(n,"hoverButton")},"&:active":{boxShadow:n=>oe(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function xd({onFileUpload:t,onError:o,isUploading:n}){const[i,s]=u.useState(!1),[d,c]=u.useState(""),[l,p]=u.useState(!1),f=u.useRef(null),m=async k=>{if(!k.name.endsWith(".json")){o("Only .json files are allowed");return}const v=10*1024*1024;if(k.size>v){o("File size exceeds 10MB limit");return}c(k.name);try{const C=await k.text();let S;try{S=JSON.parse(C)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(S)){o("JSON must be an array of objects");return}if(S.length===0){o("No data rows found in JSON file");return}t(S)}catch{o("Network error — please try again")}finally{c("")}},h=k=>{k.preventDefault(),s(!0)},x=k=>{k.preventDefault(),s(!1)},b=k=>{k.preventDefault(),s(!1);const v=k.dataTransfer.files[0];v&&m(v)},E=()=>{var k;(k=f.current)==null||k.click()},g=k=>{var C;const v=(C=k.target.files)==null?void 0:C[0];v&&m(v)},j=k=>{k.stopPropagation(),p(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:h,onDragLeave:x,onDrop:b,onPaste:k=>k.preventDefault(),onClick:E,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?k=>z(k.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:[e.jsx(r.Box,{component:"input",ref:f,type:"file",accept:".json",onChange:g,sx:{display:"none"}}),n?e.jsxs(e.Fragment,{children:[e.jsx(r.CircularProgress,{size:32,sx:{mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:.5},children:"Uploading..."}),d&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:d})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:k=>z(k.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(B.UploadFile,{sx:{fontSize:32,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:1.5},children:[e.jsx(r.Button,{variant:"contained",sx:{fontWeight:500},children:"Upload Data (JSON)"}),e.jsx(r.IconButton,{onClick:j,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:e.jsx(B.InfoOutlined,{sx:{fontSize:16}})})]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",maxWidth:500},children:"Upload structured JSON data to generate your report."}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1},children:"Click to browse or drag and drop a JSON file here"})]})]}),e.jsx(es,{isOpen:l,onClose:()=>p(!1)})]})}function md({schema:t,onConfirm:o,hasConflicts:n}){return e.jsxs(r.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[e.jsxs(r.Box,{sx:{mb:2},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontWeight:600,mb:.5},children:"Schema Preview"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&e.jsxs(r.Alert,{severity:"warning",sx:{mb:2},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),e.jsx(r.TableContainer,{sx:{mb:3},children:e.jsxs(r.Table,{children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{bgcolor:"action.hover"},children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),e.jsx(r.TableBody,{children:t.map(i=>e.jsxs(r.TableRow,{sx:{bgcolor:i.hasConflict?s=>z(s.palette.warning.main,.12):"transparent"},children:[e.jsxs(r.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&e.jsx(r.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(B.Lock,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Schema will be locked for this report"})]}),e.jsx(r.Button,{variant:"contained",onClick:o,disabled:n,sx:{fontWeight:500},children:"Generate Table"})]})]})}function hd({error:t,onRetry:o}){return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderColor:"error.light",bgcolor:n=>z(n.palette.error.main,.12),borderRadius:1,px:2,py:6},children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:n=>z(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(B.ErrorOutline,{color:"error",sx:{fontSize:32}})}),e.jsx(r.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:600,mb:1},children:"Upload Failed"}),e.jsx(r.Typography,{variant:"body2",color:"error.main",sx:{textAlign:"center",maxWidth:500,mb:3},children:t}),e.jsx(r.Button,{variant:"contained",color:"error",startIcon:e.jsx(B.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function ts({title:t,description:o,showIcon:n=!0}){return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",px:3,py:8},children:[n&&e.jsx(r.Box,{sx:{width:80,height:80,borderRadius:"50%",bgcolor:i=>z(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(B.Description,{sx:{fontSize:36,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:500,mb:1,color:"text.primary",fontSize:"1.125rem"},children:t}),e.jsx(r.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:"0.875rem",lineHeight:1.5},children:o})]})}function fd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:d,disabled:c}){const[l,p]=u.useState(!1),[f,m]=u.useState(!1),[h,x]=u.useState(-1),b=u.useRef(null),E=u.useRef(null);u.useEffect(()=>{function R(G){b.current&&!b.current.contains(G.target)&&(p(!1),m(!1))}return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);const g=u.useCallback(()=>{m(!0),x(-1),n.length>0&&p(!0)},[n.length]),j=u.useCallback(R=>{o(R),x(-1)},[o]),k=u.useCallback(R=>{var G;o(R),i(R),p(!1),(G=E.current)==null||G.blur()},[o,i]),v=u.useCallback(R=>{x(-1),k(R)},[k]),C=u.useCallback(R=>{var G;R.key==="Enter"?h>=0&&h<n.length?(R.preventDefault(),v(n[h].query)):t.trim()&&k(t.trim()):R.key==="Escape"?(p(!1),x(-1),(G=E.current)==null||G.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(l||p(!0),x(q=>q<n.length-1?q+1:q))):R.key==="ArrowUp"&&(R.preventDefault(),x(q=>q>0?q-1:-1))},[h,n,t,l,v,k]),S=u.useCallback(()=>{var R;o(""),(R=E.current)==null||R.focus()},[o]),w=u.useMemo(()=>n.filter(R=>R.isFavourite),[n]),a=u.useMemo(()=>n.filter(R=>!R.isFavourite),[n]),I=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:b,children:[e.jsx(r.TextField,{inputRef:E,size:"small",fullWidth:!0,value:t,onChange:R=>j(R.target.value),onFocus:g,onKeyDown:C,placeholder:"Search data...",disabled:c,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:R=>z(R.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:R=>z(R.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:e.jsx(r.InputAdornment,{position:"start",sx:{ml:.5},children:e.jsx(B.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:S,edge:"end",sx:{mr:-.5},children:e.jsx(B.Close,{sx:{fontSize:16}})})}):null}}),I&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[w.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),w.map((R,G)=>e.jsx(ci,{entry:R,isSelected:h===G,onClick:()=>v(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>d(R.query)},`fav-${R.query}`))]}),a.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[w.length>0&&e.jsx(r.Divider,{}),e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),a.map((R,G)=>{const q=w.length+G;return e.jsx(ci,{entry:R,isSelected:h===q,onClick:()=>v(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>d(R.query)},`recent-${R.query}`)})]})]})]})}const ci=u.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:d}){const c=u.useCallback(p=>{p.stopPropagation(),s()},[s]),l=u.useCallback(p=>{p.stopPropagation(),d()},[d]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?p=>z(p.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?p=>z(p.palette.primary.main,.12):"action.hover"}},children:[e.jsx(r.Box,{sx:{flex:1,minWidth:0},onClick:i,children:e.jsx(r.Typography,{variant:"body2",noWrap:!0,children:o.query})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[e.jsx(r.IconButton,{size:"small",onClick:c,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(B.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(B.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),e.jsx(r.IconButton,{size:"small",onClick:l,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:e.jsx(B.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function gd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:d,onToggleDefault:c,onToggleFavorite:l,onRestoreView:p,onPermanentDelete:f,isReadOnly:m,isAdmin:h=!1}){const x=$t(),[b,E]=u.useState(!1),[g,j]=u.useState(!1),[k,v]=u.useState({top:0,left:0}),[C,S]=u.useState(null),w=u.useRef(null),a=u.useRef(null),I=t.find(O=>O.id===o),R=I==null?void 0:I.isDefault,G=t.filter(O=>O.scope==="global"&&!O.isDeleted),q=t.filter(O=>O.scope!=="global"&&!O.isDeleted),ee=t.filter(O=>O.isFavorite&&!O.isDeleted).sort((O,H)=>(H.updatedAt||0)-(O.updatedAt||0)),y=t.filter(O=>O.isDeleted);u.useEffect(()=>{if(b&&a.current){const O=a.current.getBoundingClientRect();v({top:O.bottom+window.scrollY+8,left:O.right+window.scrollX-320})}},[b]),u.useEffect(()=>{const O=H=>{w.current&&!w.current.contains(H.target)&&a.current&&!a.current.contains(H.target)&&E(!1)};return b&&document.addEventListener("mousedown",O),()=>{document.removeEventListener("mousedown",O)}},[b]);const M=O=>{if(n&&O!==o){S(O),E(!1);return}i(O),E(!1)},W=()=>{C&&(i(C),S(null))},V=()=>{S(null)},X=(O,H=!1)=>{const re=O.scope==="global",U=!m&&(!re||h);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===O.id?z(x.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===O.id?z(x.palette.primary.main,.12):x.palette.action.hover}},children:[e.jsxs(r.Button,{onClick:()=>M(O.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:[o===O.id&&e.jsx(B.Check,{sx:{fontSize:16,flexShrink:0}}),o!==O.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===O.id?x.palette.primary.dark:x.palette.text.primary,fontWeight:o===O.id?500:400},children:O.name}),H&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:x.palette.text.secondary,backgroundColor:x.palette.action.selected,px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[U&&l&&e.jsx(r.IconButton,{onClick:te=>{te.stopPropagation(),l(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},title:O.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(B.Star,{sx:{fontSize:16}})}),U&&c&&!O.isDefault&&e.jsx(r.IconButton,{onClick:te=>{te.stopPropagation(),c(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},title:"Set as default",children:e.jsx(B.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},O.id)},ue=O=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:x.palette.action.hover},children:[e.jsx(r.Typography,{sx:{color:x.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:O.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[p&&e.jsx(r.IconButton,{onClick:H=>{H.stopPropagation(),p(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},title:"Restore view",children:e.jsx(B.Undo,{sx:{fontSize:16,color:"success.main"}})}),f&&e.jsx(r.IconButton,{onClick:H=>{H.stopPropagation(),f(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},title:"Delete permanently",children:e.jsx(B.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},O.id),ce=n||!R,F=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.Button,{ref:a,onClick:()=>E(!b),variant:"outlined",size:"small",endIcon:e.jsx(B.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{position:"relative",minWidth:140,maxWidth:220,justifyContent:"space-between",fontSize:"0.8125rem",textTransform:"none",color:ce?"warning.main":"text.primary",borderColor:ce?"warning.main":"divider",bgcolor:ce?z(x.palette.warning.main,.12):"transparent",borderRadius:1,py:.5,px:1.25,transition:"all 0.15s ease","&:hover":{borderColor:ce?"warning.dark":"primary.main",bgcolor:ce?z(x.palette.warning.main,.2):z(x.palette.text.primary,.06),color:ce?"warning.dark":"text.primary"}},title:`View: ${(I==null?void 0:I.name)||"Default View"}`,children:[e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(I==null?void 0:I.name)||"Default View"}),F&&e.jsx(r.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"}})]}),b&&ji.createPortal(e.jsxs(r.Box,{ref:w,sx:{position:"fixed",width:"320px",backgroundColor:x.palette.background.paper,border:`1px solid ${x.palette.divider}`,borderRadius:1,boxShadow:x.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:k.top,left:k.left},children:[G.length>0&&e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),G.map(O=>X(O,O.isDefault))]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(B.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),ee.map(O=>X(O))]})]}),q.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),q.map(O=>X(O))]})]}),y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>j(!g),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",y.length,")"]}),e.jsx(B.ChevronRight,{sx:{fontSize:16}})]}),g&&e.jsx(r.Box,{sx:{backgroundColor:x.palette.action.hover},children:y.map(O=>ue(O))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{s(),E(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:x.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},children:[e.jsx(B.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{d(),E(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:x.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.action.hover}},children:[e.jsx(B.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:C!==null,onClose:V,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:Jr(x)}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(B.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:V,variant:"text",children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",children:"Discard & switch"})]})]})]})}function yd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:d=!1,hasModifications:c=!1,position:l,onSortAscending:p,onSortDescending:f,onRemoveSort:m,onFilter:h,onClearFilter:x,onGroupByColumn:b,onHideColumn:E,onManageColumns:g,onManageViews:j,onResetLayout:k,onClose:v}){var ee,y;const C=$t(),S=C.palette,w=u.useRef(null);u.useEffect(()=>{if(!w.current)return;const M=w.current,W=M.getBoundingClientRect(),V=window.innerWidth,X=window.innerHeight;W.right>V-8&&(M.style.left=`${V-W.width-8}px`),W.bottom>X-8&&(M.style.top=`${X-W.height-8}px`)},[l]),u.useEffect(()=>{const M=V=>{w.current&&!w.current.contains(V.target)&&v()},W=V=>{V.key==="Escape"&&v()};return document.addEventListener("mousedown",M),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",W)}},[v]);const a=u.useCallback(M=>()=>{M(),v()},[v]),I=(n==null?void 0:n.direction)==="asc",R=(n==null?void 0:n.direction)==="desc",G=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",q=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return ji.createPortal(e.jsxs(r.Paper,{ref:w,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:C.zIndex.tooltip,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:Jr(C),overflow:"hidden",boxShadow:`0 4px 20px ${z(((ee=S.common)==null?void 0:ee.black)??"#000",.12)}, 0 1px 4px ${z(((y=S.common)==null?void 0:y.black)??"#000",.06)}`},children:[!d&&e.jsxs(r.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary"},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[e.jsx(r.Tooltip,{title:`Sort Ascending (${G})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:a(()=>p(t)),sx:{p:.625,borderRadius:"6px",color:I?"primary.main":"text.secondary",bgcolor:I?z(S.primary.main,.1):"transparent","&:hover":{bgcolor:z(S.primary.main,.08),color:"primary.main"}},children:e.jsx(B.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${q})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:a(()=>f(t)),sx:{p:.625,borderRadius:"6px",color:R?"primary.main":"text.secondary",bgcolor:R?z(S.primary.main,.1):"transparent","&:hover":{bgcolor:z(S.primary.main,.08),color:"primary.main"}},children:e.jsx(B.ArrowDownward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:!s,onClick:a(()=>m(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:z(S.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(B.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:a(()=>h(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.FilterList,{sx:{fontSize:16,color:i?"primary.main":"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Filter by Column",primaryTypographyProps:{fontSize:"0.8125rem",fontWeight:i?600:400,color:i?"primary.main":"text.primary"}})]}),i&&!d&&e.jsxs(r.MenuItem,{onClick:a(()=>x(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:z(S.warning.main,.06),"& .MuiListItemText-primary":{color:"warning.main"},"& .MuiListItemIcon-root svg":{color:"warning.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!d&&b&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.25}}),e.jsx(r.MenuList,{dense:!0,sx:{py:.5},children:e.jsxs(r.MenuItem,{onClick:a(()=>b(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.GroupWorkOutlined,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Group By Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]})})]}),e.jsx(r.Divider,{sx:{my:.25}}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[!d&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(r.MenuItem,{onClick:a(()=>E(t)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),e.jsx(r.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:a(g),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:z(S.primary.main,.08),color:"primary.main"}},children:e.jsx(B.Settings,{sx:{fontSize:16}})})})]}),d&&e.jsxs(r.MenuItem,{onClick:a(g),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),j&&e.jsxs(r.MenuItem,{onClick:a(j),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!d&&c&&k&&e.jsxs(r.MenuItem,{onClick:a(k),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:z(S.error.main,.05),"& .MuiListItemText-primary":{color:"error.main"},"& .MuiListItemIcon-root svg":{color:"error.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(B.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const bd=176,di="COLUMN_HEADER",vd=u.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:d,isReadOnly:c=!1,hasModifications:l=!1,width:p,onColumnClick:f,onMoveColumn:m,onColumnDragEnd:h,onResizeStart:x,onSortAscending:b,onSortDescending:E,onRemoveSort:g,onOpenFilterForColumn:j,onClearFiltersForColumn:k,onGroupByColumn:v,onHideColumn:C,onManageColumns:S,onManageViews:w,onResetLayout:a}){const I=u.useRef(null),[R,G]=u.useState(!1),[q,ee]=u.useState({x:0,y:0}),[{handlerId:y,isOver:M},W]=Dt.useDrop({accept:di,collect(U){return{handlerId:U.getHandlerId(),isOver:U.isOver()}},hover(U,te){var ge;if(!I.current)return;const se=U.index,ne=n;if(se===ne)return;const P=(ge=I.current)==null?void 0:ge.getBoundingClientRect(),ie=(P.right-P.left)/2,de=te.getClientOffset(),ae=((de==null?void 0:de.x)??0)-P.left;se<ne&&ae<ie||se>ne&&ae>ie||(m(se,ne),U.index=ne)}}),[{isDragging:V},X]=Dt.useDrag({type:di,item:()=>({index:n,columnName:o.name}),collect:U=>({isDragging:U.isDragging()}),end:()=>{h==null||h()}});X(W(I));const ue=u.useCallback(U=>{U.preventDefault(),U.stopPropagation(),ee({x:U.clientX,y:U.clientY}),G(!0)},[]),ce=u.useCallback(()=>G(!1),[]),F=u.useCallback(()=>{f(o.name)},[f,o.name]),O=u.useCallback(U=>{U.stopPropagation(),j(o.name)},[j,o.name]),H=u.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(B.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(B.ArrowDownward,{sx:{fontSize:13,color:"primary.main"}}),e.jsx(r.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]),re=u.useCallback(()=>s?e.jsx(B.FilterList,{onClick:O,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,O]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:I,"data-handler-id":y,"data-column-index":n,onClick:F,onContextMenu:ue,sx:{position:"sticky",top:0,zIndex:5,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"visible",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:V?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:M?U=>z(U.palette.primary.main,.08):"action.hover",boxShadow:U=>`0 1px 0 ${z(U.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:U=>z(U.palette.primary.main,.1),color:"primary.dark"},width:p?`${p}px`:`${bd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[qe(o.name),H(),re()]}),e.jsx(r.Box,{draggable:!1,onDragStart:U=>U.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:U=>{U.preventDefault(),U.stopPropagation(),x(U,o.name)},onClick:U=>U.stopPropagation(),children:e.jsx(r.Box,{draggable:!1,sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),M&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),R&&e.jsx(yd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:d,isReadOnly:c,hasModifications:l,position:q,onSortAscending:b,onSortDescending:E,onRemoveSort:g,onFilter:j,onClearFilter:k,onGroupByColumn:v,onHideColumn:C,onManageColumns:S,onManageViews:w,onResetLayout:a,onClose:ce})]})}),Sd={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 bo(t,o){const n=Sd[o.toLowerCase().trim()];if(!n||n==="neutral")return{bg:t.palette.action.selected,color:t.palette.text.secondary};const i=t.palette[n];return{bg:z(i.main,t.palette.mode==="dark"?.24:.12),color:t.palette.mode==="dark"?i.light:i.dark}}function jd(t,o){switch(o.toLowerCase().trim()){case"low":return t.palette.text.secondary;case"medium":return t.palette.warning.main;case"high":return t.palette.warning.dark;case"critical":case"urgent":return t.palette.error.main;default:return}}const Cd={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 wd(t,o){const n=Cd[o];return n?t.palette[n.hue][n.shade]:t.palette.text.secondary}function Pe(t){return z(t.palette.primary.main,t.palette.mode==="dark"?.24:.12)}function kd(t){const o=t.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:500,bgcolor:n=>bo(n,o).bg,color:n=>bo(n,o).color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function Td(t,o){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontSize:"0.8125rem"},children:"—"});const n=String(o),i=t.name.toLowerCase();if(/\b(status|state|stage)\b/.test(i))return kd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=n.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:d=>{const c=jd(d,s);return c?{color:c,fontWeight:600,fontSize:"0.8125rem"}:{fontSize:"0.8125rem"}},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function zd(t){const o=t.find(s=>{const d=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(d)})||t[0]||null,n=t.find(s=>{const d=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(d)&&s!==o})||null,i=t.filter(s=>s!==o&&s!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function Id({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isReadOnly:s,onToggleSelection:d,onView:c,onEdit:l,onDuplicate:p,onDelete:f}){const[m,h]=u.useState(null),[x,b]=u.useState(!1),{primaryCol:E,idCol:g,bodyColumns:j}=u.useMemo(()=>zd(n),[n]),k=E?t[E.name]:null,v=g?t[g.name]:null,C=x||i||!!m;return e.jsxs(r.Box,{onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":S=>z(S.palette.divider,.8),borderWidth:i?2:1,borderRadius:"12px",cursor:"pointer",transition:"box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease",overflow:"hidden",minHeight:180,boxShadow:i?S=>`0 0 0 3px ${z(S.palette.primary.main,.15)}, 0 2px 8px ${z(S.palette.common.black,.08)}`:x?S=>oe(S,"cardHover"):S=>oe(S,"cardRest"),transform:x&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:S=>z(S.palette.primary.main,.03)}},children:[e.jsx(r.Box,{sx:{px:2,pt:2,pb:1.5},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,fontSize:"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:k!=null&&k!==""?String(k):e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})}),e.jsx(r.Box,{sx:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}),e.jsxs(r.Box,{sx:{px:2,py:1.5,flex:1,display:"flex",flexDirection:"column",gap:1},children:[j.map(S=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minHeight:22},children:[e.jsx(r.Typography,{sx:{color:"text.secondary",fontWeight:500,fontSize:"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",minWidth:68,flexShrink:0,lineHeight:1},children:qe(S.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:Td(S,t[S.name])})]},S.name)),j.length===0&&e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic"},children:"No additional fields visible"})]}),e.jsxs(r.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:S=>z(S.palette.action.hover,.1),minHeight:40},children:[e.jsx(r.Typography,{sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.75rem",fontWeight:400,letterSpacing:"0.04em",opacity:v?.85:0,userSelect:"none"},children:v?String(v):" "}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:C?1:0,transition:"opacity 0.15s ease"},onClick:S=>S.stopPropagation(),children:e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:S=>{S.stopPropagation(),h(S.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:S=>z(S.palette.text.primary,.08)}},children:e.jsx(B.MoreVert,{sx:{fontSize:17}})})})})]}),e.jsxs(r.Popover,{open:!!m,anchorEl:m,onClose:()=>h(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:S=>oe(S,"popover")}},onClick:S=>S.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{c(t),h(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(B.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!s&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{l(t,o),h(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(B.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!s&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{p(o,t),h(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(B.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!s&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(o,t),h(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(B.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Bd({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.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=>oe(s,"flatHover"),"&:hover":{bgcolor:s=>z(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(B.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(B.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:Ei(t.groupLevel,((i=o==null?void 0:o.levels[t.groupLevel])==null?void 0:i.column)||"",t.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:s=>z(s.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[t.rowCount," ",t.rowCount===1?"row":"rows"]}),Object.keys(t.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(t.aggregates).map(([s,d])=>Bi(d)).filter(Boolean).join(" • ")})]})}function Ed({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,isReadOnly:s,isGrouped:d,sortStack:c=[],onSort:l,onToggleRowSelection:p,onToggleGroupCollapse:f,onViewRow:m,onEditRow:h,onDuplicateRow:x,onDeleteRow:b}){const E=u.useMemo(()=>{const g=new Set;return i.forEach(j=>{const k=j==null?void 0:j.__urm_row_id__;k!==void 0&&g.add(k)}),g},[i]);return t.length===0?e.jsx(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):e.jsxs(r.Box,{sx:{fontFamily:g=>g.typography.fontFamily},children:[l&&o.length>0&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,px:2,py:1,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper",flexWrap:"wrap"},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontWeight:500,mr:.5,whiteSpace:"nowrap"},children:"Sort by:"}),o.map(g=>{const j=c.find(k=>k.column===g.name);return e.jsxs(r.Box,{onClick:()=>l(g.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:j?"primary.main":"divider",bgcolor:j?k=>z(k.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:k=>z(k.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:j?600:400,color:j?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:qe(g.name)}),j?j.direction==="asc"?e.jsx(B.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(B.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(B.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},g.name)})]}),e.jsx(r.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(272px, 1fr))",gap:1.5,alignContent:"start"},children:t.map((g,j)=>d&&g.isGroupHeader?e.jsx(Bd,{row:g,grouping:n,onToggleCollapse:f||(()=>{})},`group-${g.groupKey}`):e.jsx(Id,{row:g,rowIndex:j,visibleColumns:o,isSelected:E.has(g==null?void 0:g.__urm_row_id__),isReadOnly:s,onToggleSelection:()=>p(g),onView:m,onEdit:h,onDuplicate:x,onDelete:b},`card-${j}`))})]})}const ui=[10,15,25,50,100];function Dd(t,o){const n=t.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>o?"Entered page number is out of range":null}function Od({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:d}){var M;const l=$t().palette,p=Math.ceil(n/o),[f,m]=u.useState(String(t)),[h,x]=u.useState(null),[b,E]=u.useState(!1),g=u.useRef(null);u.useEffect(()=>{b||(m(String(t)),x(null))},[t,b]);const j=u.useCallback(()=>{const W=Dd(f,p);if(W){x(W);return}const V=parseInt(f.trim(),10);x(null),E(!1),V!==t&&s(V)},[f,p,t,s]),k=u.useCallback(W=>{var V;W.key==="Enter"?(W.preventDefault(),j()):W.key==="Escape"&&(m(String(t)),x(null),E(!1),(V=g.current)==null||V.blur())},[j,t]),v=u.useCallback(()=>{m(String(t)),x(null),E(!1)},[t]),C=u.useCallback(()=>{E(!0),x(null),setTimeout(()=>{var W;return(W=g.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ui))return null;const S=()=>{m(String(t)),x(null),E(!1)},w=()=>{S(),s(1)},a=()=>{S(),t>1&&s(t-1)},I=()=>{S(),t<p&&s(t+1)},R=()=>{S(),s(p)},G=(t-1)*o+1,q=Math.min(t*o,n),ee=`${Math.max(2,String(p).length+.5)}ch`,y={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return e.jsxs(r.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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),e.jsx(r.Select,{value:o,onChange:W=>d(Number(W.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:ui.map(W=>e.jsx(r.MenuItem,{value:W,sx:{fontSize:"0.8125rem"},children:W},W))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[G,"–",q," of ",n]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),e.jsxs(r.Box,{sx:{position:"relative"},children:[h&&e.jsx(r.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:z(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${z(((M=l.common)==null?void 0:M.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:z(l.error.main,.4)}},children:e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:h})}),e.jsx(r.InputBase,{inputRef:g,value:f,onChange:W=>{m(W.target.value),h&&x(null)},onKeyDown:k,onFocus:C,onBlur:v,inputProps:{"aria-label":`Page number, 1 to ${p}`,style:{textAlign:"center",padding:"2px 0",width:ee,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:h?"error.main":"text.primary",border:"1px solid",borderColor:h?"error.main":b?"primary.main":"divider",borderRadius:"4px",bgcolor:h?z(l.error.main,.04):b?z(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:h?"error.main":"text.secondary"},"&:focus-within":{boxShadow:h?`0 0 0 2px ${z(l.error.main,.2)}`:`0 0 0 2px ${z(l.primary.main,.2)}`}}})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",p]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{onClick:w,disabled:t===1,size:"small",title:"First page",sx:y,children:e.jsx(B.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:a,disabled:t===1,size:"small",title:"Previous page",sx:y,children:e.jsx(B.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:I,disabled:t===p,size:"small",title:"Next page",sx:y,children:e.jsx(B.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:R,disabled:t===p,size:"small",title:"Last page",sx:y,children:e.jsx(B.LastPage,{sx:{fontSize:20}})})]})]})]})}function $d(){return e.jsx(r.Chip,{icon:e.jsx(B.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const rs="urm_hint_seen_";function Ad(t){try{return localStorage.getItem(rs+t)==="true"}catch{return!1}}function Md(t){try{localStorage.setItem(rs+t,"true")}catch{}}function pi(t,o){if(t==null||t==="")return"";if(o==="boolean")return t?"True":"False";if(o==="object"||o==="array")try{return JSON.stringify(t,null,2)}catch{return String(t)}return String(t)}function xi(t){const o={fontSize:11};switch(t){case"number":return e.jsx(B.Numbers,{sx:o});case"boolean":return e.jsx(B.CheckBox,{sx:o});case"array":return e.jsx(B.DataArray,{sx:o});case"object":return e.jsx(B.DataObject,{sx:o});default:return e.jsx(B.TextFields,{sx:o})}}function mi(t,o){var n,i;switch(t){case"number":return{bg:z(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:z(((n=o.success)==null?void 0:n.main)??"#2e7d32",.08),color:((i=o.success)==null?void 0:i.main)??"#2e7d32"};case"array":case"object":return{bg:z(o.secondary.main,.08),color:o.secondary.main};default:return{bg:z(o.text.secondary,.07),color:o.text.secondary}}}function Rd({open:t,onClose:o,row:n,schema:i,reportName:s}){var h,x;const d=$t(),c=d.palette;if(!n)return null;const l=i.filter(b=>b.name in n),p=l.filter(b=>b.type!=="object"&&b.type!=="array"),f=l.filter(b=>b.type==="object"||b.type==="array"),m=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:_e(d),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${z(((h=c.common)==null?void 0:h.black)??"#000",.14)}, 0 2px 8px ${z(((x=c.common)==null?void 0:x.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:z(c.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(B.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"View Record"}),s&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s," · ",m," ",m===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:z(c.text.primary,.015)},children:[p.length>0&&e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"1px",bgcolor:"divider",m:2,mb:f.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:p.map((b,E)=>{const g=n[b.name],j=pi(g,b.type),k=!j,v=mi(b.type,c),C=E===p.length-1&&p.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:C?"span 2":"span 1",display:"flex",flexDirection:"column",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:v.bg,color:v.color,flexShrink:0},children:xi(b.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:qe(b.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:k?400:500,color:k?"text.disabled":"text.primary",fontStyle:k?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:b.type==="number"?'"Roboto Mono", monospace':"inherit"},children:k?"No value":j})]},b.name)})}),f.map(b=>{const E=n[b.name],g=pi(E,b.type),j=!g,k=mi(b.type,c);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:k.bg,color:k.color},children:xi(b.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:qe(b.name)}),e.jsx(r.Chip,{label:b.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:k.bg,color:k.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:z(c.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:j?"text.disabled":"text.primary",fontStyle:j?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:j?"No value":g})]},b.name)}),l.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(B.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{fontSize:"0.8125rem",px:3,py:.75,borderRadius:b=>`${b.shape.borderRadius}px`,minWidth:80},children:"Close"})})]})}function _d({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:s=>_e(s),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:s=>oe(s,"menu")}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:s=>z(s.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(B.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:[i?`"${i}"`:"This record"," will be permanently removed."]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:s=>z(s.palette.error.main,.1),border:s=>`1px solid ${z(s.palette.error.main,.5)}`},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"error.main",fontWeight:500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:s=>`${s.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(B.DeleteForever,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"error.contrastText",px:3,py:.875,minHeight:36,borderRadius:s=>`${s.shape.borderRadius}px`,boxShadow:s=>oe(s,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:s=>oe(s,"hoverButton")},"&:active":{boxShadow:s=>oe(s,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function tn(t){const o={fontSize:11};switch(t){case"number":return e.jsx(B.Numbers,{sx:o});case"boolean":return e.jsx(B.CheckBox,{sx:o});case"array":return e.jsx(B.DataArray,{sx:o});case"object":return e.jsx(B.DataObject,{sx:o});default:return e.jsx(B.TextFields,{sx:o})}}function hi(t,o){var n,i;switch(t){case"number":return{bg:z(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:z(((n=o.success)==null?void 0:n.main)??"#2e7d32",.08),color:((i=o.success)==null?void 0:i.main)??"#2e7d32"};case"array":case"object":return{bg:z(o.secondary.main,.08),color:o.secondary.main};default:return{bg:z(o.text.secondary,.07),color:o.text.secondary}}}function Wd({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:d}){var j,k,v;const c=$t(),l=c.palette,[p,f]=u.useState({});if(u.useEffect(()=>{t&&i&&f({...i})},[t,i]),!i)return null;const m=s.filter(C=>C.name in i),h=m.filter(C=>C.type!=="object"&&C.type!=="array"),x=m.filter(C=>C.type==="object"||C.type==="array"),b=(C,S)=>{f(w=>({...w,[C]:S}))},E=()=>{const C={...p};m.forEach(S=>{const w=p[S.name];if(S.type==="number"){const a=Number(w);C[S.name]=isNaN(a)?i[S.name]:a}else S.type==="boolean"&&(C[S.name]=!!w)}),n(C),o()},g=m.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:_e(c),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${z(((j=l.common)==null?void 0:j.black)??"#000",.14)}, 0 2px 8px ${z(((k=l.common)==null?void 0:k.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:z(((v=l.warning)==null?void 0:v.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(B.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),d&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d," · ",g," ",g===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:z(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[h.length>0&&e.jsxs(r.Box,{children:[h.length>1&&e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em",mb:1.25},children:"Fields"}),e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1.5},children:h.map((C,S)=>{const w=p[C.name],a=hi(C.type,l),I=C.type==="boolean",R=!I&&S===h.filter(q=>q.type!=="boolean").length-1&&h.filter(q=>q.type!=="boolean").length%2!==0,G=I||R;return C.type==="boolean"?e.jsxs(r.Box,{sx:{gridColumn:"span 2",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",px:2,py:1.5,display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,transition:"border-color 0.15s","&:hover":{borderColor:"primary.main"}},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.25},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:a.bg,color:a.color},children:tn(C.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:qe(C.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:w?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!w,onChange:q=>b(C.name,q.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},C.name):e.jsxs(r.Box,{sx:{gridColumn:G?"span 2":"span 1",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",transition:"border-color 0.15s","&:focus-within":{borderColor:"primary.main",boxShadow:`0 0 0 2px ${z(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:z(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:a.bg,color:a.color},children:tn(C.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:qe(C.name)})]}),e.jsx(r.TextField,{value:w??"",onChange:q=>b(C.name,q.target.value),type:C.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${C.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:C.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},C.name)})})]}),x.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em"},children:"Read-only Fields"}),e.jsx(r.Tooltip,{title:"Object and array fields cannot be edited directly",arrow:!0,children:e.jsx(B.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:x.map(C=>{const S=i[C.name];let w="";try{w=S==null?"":JSON.stringify(S,null,2)}catch{w=String(S)}const a=hi(C.type,l);return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",opacity:.8},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:z(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:a.bg,color:a.color},children:tn(C.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:qe(C.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:z(l.text.secondary,.07),color:"text.secondary",border:"none"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:w?"text.primary":"text.disabled",fontStyle:w?"normal":"italic",bgcolor:z(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:w||"No value"})]},C.name)})})]}),m.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(B.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",px:2,borderRadius:C=>`${C.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:E,variant:"contained",startIcon:e.jsx(B.SaveOutlined,{sx:{fontSize:15}}),sx:{fontSize:"0.8125rem",px:2.5,borderRadius:C=>`${C.shape.borderRadius}px`,minWidth:90},children:"Save"})]})]})}const Pd=176,Ld=170,Nd=40;function os(t){return t.type==="date"?180:Pd}function Fd(t,o){return o!=null&&o!==Ld&&o!==os(t)}function Vd(t,o,n){return u.useMemo(()=>{const i=t.map(h=>({name:h.name,width:o[h.name]??os(h),explicit:Fd(h,o[h.name])})),s={};i.forEach(h=>{s[h.name]=h.width});const d=i.reduce((h,x)=>h+x.width,0),l=Math.max(0,n-Nd)-d;if(l<=0)return{widths:s,fillerWidth:0};const p=i.filter(h=>!h.explicit);if(p.length===0)return{widths:s,fillerWidth:l};const f=p.reduce((h,x)=>h+x.width,0)||1;let m=0;return p.forEach((h,x)=>{const E=x===p.length-1?h.width+l-m:Math.round(h.width+l*h.width/f);s[h.name]=E,m+=E-h.width}),{widths:s,fillerWidth:0}},[t,o,n])}const fi=176,Hd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Ud(t){const o=t.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:500,bgcolor:n=>bo(n,o).bg,color:n=>bo(n,o).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Gd(t){const o=t.toLowerCase().trim(),n=Hd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Yd(t,o){const n=o.trim();if(!n)return t;const i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=t.split(new RegExp(`(${i})`,"gi"));return s.length===1?t:s.map((d,c)=>d.toLowerCase()===n.toLowerCase()?e.jsx(r.Box,{component:"mark",sx:{bgcolor:"warning.light",color:"inherit",px:"1px",borderRadius:"2px"},children:d},c):d)}function qd(t,o,n,i=""){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled"},children:"—"});const s=String(o);if(/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase()))return Ud(s);if(/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase()))return Gd(s);if(t.type==="date"){const l=t.dateFormat??"iso",p=qs(o,l,n??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:p})}if(t.type==="number"&&typeof o=="number")return o.toLocaleString();if(typeof o=="boolean")return o?"Yes":"No";if(Array.isArray(o)){if(o.length===0)return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled"},children:"[ ]"});const l=o.slice(0,3).map(p=>typeof p=="object"?JSON.stringify(p):String(p)).join(", ");return e.jsxs(r.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[l,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const l=JSON.stringify(o);return e.jsx(r.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 Yd(s,i)}function Jd({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:d="",isDirty:c=!1,isExporting:l=!1,columnVisibility:p={},columnOrder:f=[],columnWidths:m={},grouping:h=null,onSort:x,onSortAscending:b,onSortDescending:E,onOpenFilters:g,onOpenSort:j,onOpenFilterForColumn:k,onSelectView:v,onCreateView:C,onManageViews:S,onUpdateCurrentView:w,onSaveAsNewView:a,onDiscardChanges:I,onToggleDefault:R,onToggleFavorite:G,onRestoreView:q,onPermanentDelete:ee,isAdmin:y=!1,onExport:M,onOpenColumns:W,onUpdateColumnWidth:V,onUpdateColumnOrder:X,onUpdateColumnVisibility:ue,onClearFiltersForColumn:ce,onResetLayout:F,onOpenGroup:O,onGroupByColumn:H,onToggleGroupCollapse:re,onOpenAuditHistory:U,onOpenScheduledReports:te,searchQuery:se,highlightQuery:ne="",searchHistory:P=[],onAddToSearchHistory:ie,onToggleSearchFavourite:de,onDeleteSearchHistory:ae,selectedRowIds:ge=new Set,onSearchChange:K,onToggleRowSelection:Ee,onToggleAllRows:Ue,onRangeSelection:it,onClearSelection:St,onExportSelected:et,currentPage:xr=1,pageSize:jt=15,totalRowsBeforePagination:mr=o.length,onPageChange:st,onPageSizeChange:qt,isReadOnly:Me=!1,userRole:at,reportName:lt,onEditRow:tt,onDuplicateRow:Ve,onDeleteRow:At,showDevPanel:Er=!1,onOpenDevConfig:hr}){var eo;const[Jt,Kt]=u.useState(null),[fr,gr]=u.useState(0),[ct,Xt]=u.useState(0),[Ct,dt]=u.useState(null),Dr=((eo=dr().dates)==null?void 0:eo.displayFormat)??null,[Ke,yr]=u.useState(null),[Mt,Te]=u.useState(null),[Or,Rt]=u.useState(null),[ut,N]=u.useState(!1),[rt,be]=u.useState(!1),[Fe,Qt]=u.useState(null),[_t,br]=u.useState(""),[Wt,Pt]=u.useState(!1),[$r,Zt]=u.useState(null),[ze,Q]=u.useState(null),[fe,me]=u.useState(null),[vr,Xe]=u.useState(null),Lt=u.useRef(null),pt=u.useCallback(()=>{Lt.current&&(clearTimeout(Lt.current),Lt.current=null)},[]),er=u.useCallback(()=>{pt(),Lt.current=setTimeout(()=>Xe(null),200)},[pt]);u.useEffect(()=>pt,[pt]);const[Sr,ot]=u.useState(null),[He,xt]=u.useState("list"),[mt,tr]=u.useState(!1),[Nt,jr]=u.useState(()=>!Ad("toolbar_search")),Ft=u.useRef(null),rr=u.useRef(null),[Ar,wt]=u.useState(0);u.useLayoutEffect(()=>{const D=Ft.current;if(!D)return;wt(D.clientWidth);const Y=new ResizeObserver(pe=>{wt(pe[0].contentRect.width)});return Y.observe(D),()=>Y.disconnect()},[]);const ht=u.useCallback(()=>{Md("toolbar_search"),jr(!1)},[]);u.useEffect(()=>{if(!Nt)return;const D=setTimeout(ht,2e3);return()=>clearTimeout(D)},[Nt,ht]);const Cr=u.useMemo(()=>{const D=Ct??f;return D.length>0?D.map(Y=>t.find(pe=>pe.name===Y)).filter(Y=>Y!==void 0):t},[Ct,f,t]),Le=u.useMemo(()=>Cr.filter(D=>p[D.name]!==!1),[Cr,p]),{widths:kt,fillerWidth:Tt}=Vd(Le,m,Ar),nt=u.useMemo(()=>t.filter(D=>p[D.name]===!1).length,[t,p]),or=u.useMemo(()=>t.map(D=>D.name),[t]),zt=u.useMemo(()=>f.length===0?!1:JSON.stringify(f)!==JSON.stringify(or),[f,or]),le=u.useCallback((D,Y)=>{D.preventDefault(),D.stopPropagation(),Kt(Y),gr(D.clientX),Xt(m[Y]||150)},[m]);u.useEffect(()=>{if(!Jt)return;const D=pe=>{const Ne=pe.clientX-fr,xe=Math.max(100,Math.min(600,ct+Ne));V==null||V(Jt,xe)},Y=()=>{Kt(null)};return document.addEventListener("mousemove",D),document.addEventListener("mouseup",Y),()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",Y)}},[Jt,fr,ct,V]);const ye=u.useCallback(D=>D==null?"-":typeof D=="object"?JSON.stringify(D):typeof D=="boolean"?D?"true":"false":String(D),[]);u.useCallback(D=>{const Y=n.find(pe=>pe.column===D);return Y?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[Y.direction==="asc"?e.jsx(B.ArrowUpward,{sx:{fontSize:14}}):e.jsx(B.ArrowDownward,{sx:{fontSize:14}}),e.jsx(r.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:Y.priority})]}):null},[n]),u.useCallback(D=>i.some(pe=>pe.column===D)?e.jsx(r.IconButton,{size:"small",onClick:pe=>{pe.stopPropagation(),k==null||k(D)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(B.FilterList,{sx:{fontSize:14}})}):null,[i,k]);const Re=u.useCallback(D=>{x&&x(D)},[x]),Vt=u.useCallback((D,Y)=>{dt(pe=>{const xe=[...pe??(f.length>0?f:t.map(ir=>ir.name))],[nr]=xe.splice(D,1);return xe.splice(Y,0,nr),xe})},[f,t]),Ht=u.useCallback(()=>{Ct&&X&&X(Ct),dt(null)},[Ct,X]),_o=u.useCallback(D=>{if(!x)return;const Y=n.find(pe=>pe.column===D);(!Y||Y.direction!=="asc")&&x(D)},[x,n]),Wo=u.useCallback(D=>{if(!x)return;const Y=n.find(pe=>pe.column===D);Y?Y.direction==="asc"&&x(D):(x(D),setTimeout(()=>x(D),0))},[x,n]),Po=u.useCallback(D=>{if(!x)return;const Y=n.find(pe=>pe.column===D);Y&&(Y.direction==="asc"?(x(D),setTimeout(()=>x(D),0)):Y.direction==="desc"&&x(D))},[x,n]),Lo=u.useCallback(D=>{ue&&ue(D,!1)},[ue]),Xr=(h==null?void 0:h.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],No=n.length>0||i.length>0||((h==null?void 0:h.enabled)??!1)||Object.values(p).some(D=>D===!1),Fo=(xr-1)*jt,We=o,It=u.useMemo(()=>{const D=new Set;return ge.forEach(Y=>{const pe=Y==null?void 0:Y.__urm_row_id__;pe!==void 0&&D.add(pe)}),D},[ge]);u.useEffect(()=>{const D=Y=>{!Ue||!St||Y.target instanceof HTMLInputElement||Y.target instanceof HTMLTextAreaElement||((Y.ctrlKey||Y.metaKey)&&Y.key==="a"&&(Y.preventDefault(),Ue(!0,We)),Y.key==="Escape"&&(Y.preventDefault(),St()))};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[Ue,St,We]);const Qr=u.useCallback((D,Y)=>{Ee&&(Y.shiftKey&&Ke!==null?(Y.preventDefault(),it&&it(Ke,D,We)):(Ee(We[D]),yr(D)))},[Ee,Ke,it,We]);!u.useMemo(()=>We.length>0&&It.size>0&&We.every(D=>It.has(D==null?void 0:D.__urm_row_id__)),[We,It])&&We.some(D=>It.has(D==null?void 0:D.__urm_row_id__));const Mr=Ee&&Ue,Vo=u.useCallback(D=>{var Ne;const Y=D.groupLevel,pe=Y*24;return e.jsx(r.TableRow,{onClick:()=>re==null?void 0:re(D.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Le.length+(Mr?1:0),sx:{pl:`${pe+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[D.isCollapsed?e.jsx(B.ChevronRight,{sx:{fontSize:16}}):e.jsx(B.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:Ei(Y,((Ne=h==null?void 0:h.levels[Y])==null?void 0:Ne.column)||"",D.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:xe=>z(xe.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[D.rowCount," ",D.rowCount===1?"row":"rows"]}),Object.keys(D.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(D.aggregates).map(([xe,nr])=>Bi(nr)).filter(Boolean).join(" • ")})]})})},D.groupKey)},[Le,Mr,h,re]),Zr=u.useCallback((D,Y)=>{const pe=It.has(D==null?void 0:D.__urm_row_id__),Ne=Mt===Y;return e.jsxs(r.TableRow,{"data-row-index":Y,onMouseEnter:()=>Te(Y),onMouseLeave:()=>Te(null),onClick:xe=>{!Ee||xe.target.closest("[data-row-action-btn]")||Qr(Y,xe)},onContextMenu:xe=>{xe.preventDefault(),xe.stopPropagation(),Xe(null),me({mouseX:xe.clientX,mouseY:xe.clientY,row:D,rowIndex:Y})},sx:{height:34,cursor:"pointer",bgcolor:pe?xe=>z(xe.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:pe?xe=>z(xe.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Le.map(xe=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:m[xe.name]?`${m[xe.name]}px`:`${xe.type==="date"?Math.max(fi,180):fi}px`},children:qd(xe,D[xe.name],Dr,ne)},xe.name)),e.jsx(r.TableCell,{sx:{p:0,border:"none",borderBottom:"1px solid",borderColor:"divider"}}),e.jsx(r.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:40,minWidth:40,maxWidth:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:Ne?xe=>`linear-gradient(to right, transparent, ${pe?z(xe.palette.warning.main,.12):xe.palette.background.paper} 32px)`:"transparent",opacity:Ne?1:0,transition:"opacity 0.12s ease, background 0.12s ease",zIndex:10,verticalAlign:"middle"},children:e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:xe=>{xe.stopPropagation(),xe.preventDefault(),Xe(null),me({anchorEl:xe.currentTarget,row:D,rowIndex:Y})},sx:{color:"text.secondary",opacity:Ne?1:0,transition:"opacity 0.12s ease",pointerEvents:Ne?"auto":"none","&:hover":{bgcolor:xe=>z(xe.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(B.MoreVert,{sx:{fontSize:18}})})})})]},Y)},[ge,Fo,Mt,Qr,Le,m,ne,ye,tt,Ve,At,Ee,Rt,N,me]);return e.jsxs(Dt.DndProvider,{backend:an.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(r.Box,{sx:{position:"sticky",top:0,zIndex:10,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",px:2,py:0,height:56,display:"flex",alignItems:"center",gap:1},children:[Me&&e.jsx($d,{}),K&&ie&&de&&ae&&e.jsx(r.Tooltip,{open:Nt,title:e.jsxs(r.Box,{sx:{p:.5},children:[e.jsx(r.Typography,{variant:"caption",sx:{display:"block",fontWeight:500,mb:.25},children:"💡 Search tip"}),e.jsx(r.Typography,{variant:"caption",children:"Type to search across all columns instantly"})]}),placement:"bottom-start",arrow:!0,PopperProps:{onClick:ht},componentsProps:{tooltip:{sx:{bgcolor:"primary.main","& .MuiTooltip-arrow":{color:"primary.main"},maxWidth:220,cursor:"pointer",userSelect:"none"}}},children:e.jsx(r.Box,{component:"span",children:e.jsx(fd,{value:se||"",onChange:D=>{Nt&&ht(),K(D)},searchHistory:P,onAddToHistory:ie,onToggleFavourite:de,onDeleteHistory:ae,disabled:Me})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>tr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:D=>z(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(B.InfoOutlined,{sx:{fontSize:20}})})}),v&&C&&S&&w&&s.length>0&&e.jsx(gd,{views:s||[],activeViewId:d||"",isDirty:c,onSelectView:v,onCreateView:C,onManageViews:S,onToggleDefault:R,onToggleFavorite:G,onRestoreView:q,onPermanentDelete:ee,isAdmin:y,isReadOnly:Me}),c&&!Me&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,ml:1},children:[I&&e.jsx(r.Button,{onClick:I,size:"small",variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",minWidth:0,px:1},children:"Discard"}),a&&e.jsx(r.Button,{onClick:a,size:"small",variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",minWidth:0,px:1},children:"Save as new view"}),w&&e.jsx(r.Button,{onClick:w,size:"small",variant:"contained",sx:{fontSize:"0.8125rem",px:2,boxShadow:"none"},children:"Save"})]}),Er&&hr&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:hr,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:D=>z(D.palette.text.secondary,.3),"&:hover":{bgcolor:D=>z(D.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(B.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),!Me&&j&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:j,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?D=>Pe(D):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?D=>z(D.palette.primary.main,.2):D=>z(D.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(B.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.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})]})}),!Me&&g&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:g,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?D=>Pe(D):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?D=>z(D.palette.primary.main,.2):D=>z(D.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(B.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.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:i.length})]})}),!Me&&W&&e.jsx(r.Tooltip,{title:"Show/Hide Columns",children:e.jsxs(r.IconButton,{onClick:W,size:"small",sx:{position:"relative",color:nt>0||zt?"primary.main":"text.secondary",bgcolor:nt>0||zt?D=>Pe(D):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:nt>0||zt?D=>z(D.palette.primary.main,.2):D=>z(D.palette.text.primary,.06),color:nt>0||zt?"primary.main":"text.primary"}},children:[e.jsx(B.ViewColumn,{sx:{fontSize:20}}),nt>0&&e.jsx(r.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:nt})]})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"List view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>xt("list"),sx:{borderRadius:1,color:He==="list"?"primary.main":"text.secondary",bgcolor:He==="list"?D=>Pe(D):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:He==="list"?D=>z(D.palette.primary.main,.2):D=>z(D.palette.text.primary,.06),color:He==="list"?"primary.main":"text.primary"}},children:e.jsx(B.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>xt("grid"),sx:{borderRadius:1,color:He==="grid"?"primary.main":"text.secondary",bgcolor:He==="grid"?D=>Pe(D):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:He==="grid"?D=>z(D.palette.primary.main,.2):D=>z(D.palette.text.primary,.06),color:He==="grid"?"primary.main":"text.primary"}},children:e.jsx(B.GridView,{sx:{fontSize:20}})})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"Settings",children:e.jsx(r.IconButton,{onClick:D=>ot(D.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:D=>z(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(B.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!Sr,anchorEl:Sr,onClose:()=>ot(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:[M&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{M(),ot(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Me&&O&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{O(),ot(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),U&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{U(),ot(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),te&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{te(),ot(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Scheduled Reports"})]})]}),e.jsxs(r.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[He==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Ed,{data:We,visibleColumns:Le,grouping:h,selectedRowIds:ge,isReadOnly:Me,isGrouped:!!Xr,sortStack:n,onSort:x,onToggleRowSelection:Ee||(()=>{}),onToggleGroupCollapse:re,onViewRow:D=>{Rt(D),N(!0)},onEditRow:(D,Y)=>{Zt(D),Q(Y),Pt(!0)},onDuplicateRow:(D,Y)=>Ve==null?void 0:Ve(D,Y),onDeleteRow:(D,Y)=>{Qt(Y);const pe=Object.values(Y).find(Ne=>Ne!=null&&Ne!=="");br(pe?String(pe):""),be(!0)}})}),He==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Ft,onScroll:D=>{rr.current&&(rr.current.scrollLeft=D.target.scrollLeft)},sx:{overflowX:"auto",overflowY:"hidden",flexShrink:0,scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(kt).reduce((D,Y)=>D+Y,0)+Tt+40}px`},children:[e.jsxs("colgroup",{children:[Le.map(D=>e.jsx("col",{style:{width:`${kt[D.name]}px`}},D.name)),e.jsx("col",{style:{width:`${Tt}px`}}),e.jsx("col",{style:{width:"40px"}})]}),e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Le.map((D,Y)=>e.jsx(vd,{column:D,index:Y,sortRule:n.find(pe=>pe.column===D.name),hasFilters:i.some(pe=>pe.column===D.name),isInSortStack:n.some(pe=>pe.column===D.name),isReadOnly:Me,hasModifications:No,width:m[D.name],onColumnClick:Re,onMoveColumn:Vt,onColumnDragEnd:Ht,onResizeStart:le,onSortAscending:b||_o,onSortDescending:E||Wo,onRemoveSort:Po,onOpenFilterForColumn:k||(()=>{}),onClearFiltersForColumn:ce||(()=>{}),onGroupByColumn:H,onHideColumn:Lo,onManageColumns:W||(()=>{}),onManageViews:S,onResetLayout:F},D.name)),e.jsx(r.TableCell,{sx:{p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}}),e.jsx(r.TableCell,{sx:{width:40,minWidth:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),e.jsx(r.Box,{ref:rr,onScroll:D=>{Ft.current&&(Ft.current.scrollLeft=D.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:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(kt).reduce((D,Y)=>D+Y,0)+Tt+40}px`},children:[e.jsxs("colgroup",{children:[Le.map(D=>e.jsx("col",{style:{width:`${kt[D.name]}px`}},D.name)),e.jsx("col",{style:{width:`${Tt}px`}}),e.jsx("col",{style:{width:"40px"}})]}),e.jsx(r.TableBody,{children:We.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Le.length+(Mr?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):Xr?We.map((D,Y)=>D.isGroupHeader?Vo(D):Zr(D,Y)):We.map((D,Y)=>Zr(D,Y))})]})})]}),st&&qt&&e.jsx(Od,{currentPage:xr,pageSize:jt,totalRows:mr,totalFields:t.length,onPageChange:st,onPageSizeChange:qt}),!(st&&qt)&&e.jsx(r.Box,{sx:{px:3,py:1.5,bgcolor:"action.hover",borderTop:1,borderColor:"divider"},children:e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Showing ",We.length," ",We.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!fe,onClose:()=>{me(null),Xe(null)},anchorEl:(fe==null?void 0:fe.anchorEl)||null,anchorReference:fe!=null&&fe.anchorEl?"anchorEl":"anchorPosition",anchorPosition:fe&&!fe.anchorEl?{top:fe.mouseY,left:fe.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:fe!=null&&fe.anchorEl?{vertical:"top",horizontal:"right"}:{vertical:"top",horizontal:"left"},PaperProps:{sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3}},children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{fe&&(Rt(fe.row),N(!0)),me(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{fe&&(Zt(fe.row),Q(fe.rowIndex),Pt(!0)),me(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{fe&&(Ve==null||Ve(fe.rowIndex,fe.row)),me(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),It.size>0&&et&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onMouseEnter:D=>{pt(),Xe(D.currentTarget)},onMouseLeave:er,sx:{py:1,px:2,gap:1.5,justifyContent:"space-between"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(B.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsxs(r.Typography,{variant:"body2",children:["Export Selected (",It.size,")"]})]}),e.jsx(B.ChevronRight,{sx:{fontSize:18,color:"text.secondary"}})]}),e.jsx(r.Popper,{open:!!vr,anchorEl:vr,placement:"right-start",transition:!0,sx:{zIndex:D=>D.zIndex.modal+1},modifiers:[{name:"offset",options:{offset:[0,0]}}],children:({TransitionProps:D})=>e.jsx(r.Grow,{...D,timeout:150,children:e.jsx(r.Paper,{onMouseEnter:pt,onMouseLeave:er,sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3},children:e.jsxs(r.MenuList,{dense:!0,autoFocusItem:!1,children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{et("csv"),Xe(null),me(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.TableChart,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"CSV"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{et("excel"),Xe(null),me(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.TableChart,{sx:{fontSize:18,color:"success.main"}}),e.jsx(r.Typography,{variant:"body2",children:"Excel"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{et("json"),Xe(null),me(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(B.DataObject,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"JSON"})]})]})})})})]}),e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{if(fe){Qt(fe.row);const D=Object.values(fe.row).find(Y=>Y!=null&&Y!=="");br(D?String(D):""),be(!0)}me(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(B.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Rd,{open:ut,onClose:()=>{N(!1),Rt(null)},row:Or,schema:t,reportName:lt}),e.jsx(Wd,{open:Wt,onClose:()=>{Pt(!1),Zt(null),Q(null)},onSave:D=>{ze!==null&&(tt==null||tt(ze,D))},row:$r,schema:t,reportName:lt}),e.jsx(_d,{open:rt,onClose:()=>{be(!1),Qt(null)},onConfirm:()=>{Fe!==null&&(At==null||At(Fe))},rowPreview:_t}),e.jsx(es,{isOpen:mt,onClose:()=>tr(!1)})]})}function ur({content:t,isDev:o=!1}){const[n,i]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:s=>i(s.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:s=>z(s.palette.primary.main,.08)}},children:e.jsx(B.InfoOutlined,{sx:{fontSize:15}})}),e.jsxs(r.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:[e.jsx(r.Box,{sx:{px:2,py:1.5,bgcolor:s=>z(s.palette.primary.main,.06)},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"primary.main",fontSize:"0.875rem"},children:t.title})}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.6},children:t.description}),t.tips&&t.tips.length>0&&e.jsx(r.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:t.tips.map((s,d)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},d))}),o&&t.devNote&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:s=>z(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>z(s.palette.warning.main,.2)},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:500,display:"block",mb:.25},children:"Dev note"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.5},children:t.devNote})]})]})]})]})]})}const pr={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."}};function Kd({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:d,onReplaceFilters:c,onClose:l,focusColumn:p}){const[f,m]=u.useState(""),[h,x]=u.useState(""),[b,E]=u.useState(""),[g,j]=u.useState([]),k=dr();u.useEffect(()=>{j([...o])},[o]),u.useEffect(()=>{p&&m(p)},[p]);const v=u.useCallback(()=>{m(""),x(""),E("")},[]),C=u.useMemo(()=>t.filter(M=>M.type!=="mixed"&&M.type!=="null"&&M.type!=="array"&&M.type!=="object"),[t]),S=t.find(M=>M.name===f),w=u.useMemo(()=>{const M=S?Mn(S.type):[],W=k.filter.allowedOperators;return W.length>0?M.filter(V=>W.includes(V.value)):M},[S]),a=u.useCallback(()=>!(!f||!h||oo(h)&&!b.trim()||g.length>=k.filter.maxConditions),[f,h,b,g,k]),I=u.useCallback(()=>{if(!a())return;const M={column:f,operator:h};if(oo(h)){const V=S==null?void 0:S.type;M.value=V==="number"?Number(b):b}if(g.some(V=>V.column===M.column&&V.operator===M.operator&&V.value===M.value)){v();return}j([...g,M]),v()},[a,f,h,S,b,g,v]),R=u.useCallback(M=>{j(g.filter((W,V)=>V!==M))},[g]),G=u.useMemo(()=>g.length!==o.length?!0:JSON.stringify(g)!==JSON.stringify(o),[g,o]),q=u.useCallback(()=>{c(g),l()},[g,c,l]),ee=u.useCallback(()=>{j([...o]),v(),l()},[o,v,l]),y=u.useCallback(M=>{var ue;const W=t.find(ce=>ce.name===M.column);if(!W)return"";const X=((ue=Mn(W.type).find(ce=>ce.value===M.operator))==null?void 0:ue.label)||M.operator;return oo(M.operator)?`${M.column} ${X.toLowerCase()} "${M.value}"`:`${M.column} ${X.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:ee,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:M=>z(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:e.jsxs(r.Paper,{onClick:M=>M.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:M=>_e(M),bgcolor:"background.paper",outline:"none",boxShadow:M=>oe(M,"menu"),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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Filter columns"}),e.jsx(ur,{content:pr.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:M=>z(M.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:M=>z(M.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:g.length>=k.filter.maxConditions,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Column"}),e.jsx(r.Select,{value:f,onChange:M=>{m(M.target.value),x(""),E("")},label:"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"}},children:C.map(M=>e.jsxs(r.MenuItem,{value:M.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Pe(W),"&:hover":{bgcolor:W=>z(W.palette.primary.main,.2)}}},children:[qe(M.name)," (",M.type,")"]},M.name))})]}),f&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Operator"}),e.jsx(r.Select,{value:h,onChange:M=>{x(M.target.value),E("")},label:"Operator",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"}},children:w.map(M=>e.jsx(r.MenuItem,{value:M.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Pe(W),"&:hover":{bgcolor:W=>z(W.palette.primary.main,.2)}}},children:M.label},M.value))})]}),h&&oo(h)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(S==null?void 0:S.type)==="number"?"number":"text",value:b,onChange:M=>E(M.target.value),label:"Value",placeholder:"Enter value...",sx:{"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:I,disabled:!a(),sx:{mt:1.5,fontSize:"0.875rem",color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"text.disabled"}},children:"+ Add another filter"}),g.length>=k.filter.maxConditions&&e.jsxs(r.Typography,{variant:"caption",sx:{display:"block",mt:.75,color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Filter limit reached — maximum ",k.filter.maxConditions," filters allowed. Remove an existing filter to add a new one."]})]}),g.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Active filters (",g.length,")"]}),e.jsx(r.Button,{onClick:()=>{d(),l()},sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:g.map((M,W)=>e.jsx(r.Chip,{label:y(M),onDelete:()=>R(W),sx:{bgcolor:V=>Pe(V),color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:V=>`1px solid ${z(V.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:V=>z(V.palette.primary.main,.2),borderColor:V=>z(V.palette.primary.main,.5)},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},W))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:M=>`${M.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:q,disabled:!G,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=>oe(M,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:M=>oe(M,"hoverButton")},"&:active":{boxShadow:M=>oe(M,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})})}const gi="SORT_RULE";function Xd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const d=u.useRef(null),[{handlerId:c},l]=Dt.useDrop({accept:gi,collect(m){return{handlerId:m.getHandlerId()}},hover(m,h){var v;if(!d.current)return;const x=m.index,b=o;if(x===b)return;const E=(v=d.current)==null?void 0:v.getBoundingClientRect(),g=(E.bottom-E.top)/2,j=h.getClientOffset(),k=((j==null?void 0:j.y)??0)-E.top;x<b&&k<g||x>b&&k>g||(s(x,b),m.index=b)}}),[{isDragging:p},f]=Dt.useDrag({type:gi,item:()=>({index:o}),collect:m=>({isDragging:m.isDragging()})});return f(l(d)),e.jsxs(r.Box,{ref:d,"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:m=>oe(m,"restButtonLight"),transform:"translateY(-1px)"}},children:[e.jsx(r.Chip,{label:t.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:m=>`0 1px 2px 0 ${z(m.palette.primary.main,.3)}`,"& .MuiChip-label":{px:0}}}),e.jsxs(r.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:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:m=>n(o,m.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:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:m=>Pe(m),"&:hover":{bgcolor:m=>z(m.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:m=>Pe(m),"&:hover":{bgcolor:m=>z(m.palette.primary.main,.2)}}},children:"Descending"})]})}),e.jsx(r.IconButton,{onClick:()=>i(o),size:"small",sx:{p:.5,color:"text.secondary",transition:"all 0.2s ease","&:hover":{color:"error.main",bgcolor:m=>z(m.palette.error.main,.08),transform:"scale(1.1)"}},children:e.jsx(B.Close,{sx:{fontSize:18}})})]})}function Qd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,d]=u.useState(""),[c,l]=u.useState([]);u.useEffect(()=>{l([...o])},[o]);const p=u.useMemo(()=>JSON.stringify(c)!==JSON.stringify(o),[c,o]),f=dr(),m=u.useCallback(v=>{if(!v||c.length>=f.sort.maxLevels)return;const C={column:v,direction:"asc",priority:c.length+1};l([...c,C]),d("")},[c,f.sort.maxLevels]),h=u.useCallback(v=>{const S=c.filter((w,a)=>a!==v).map((w,a)=>({...w,priority:a+1}));l(S)},[c]),x=u.useCallback((v,C)=>{const S=[...c];S[v]={...S[v],direction:C},l(S)},[c]),b=u.useCallback((v,C)=>{const S=[...c],[w]=S.splice(v,1);S.splice(C,0,w);const a=S.map((I,R)=>({...I,priority:R+1}));l(a)},[c]),E=u.useCallback(()=>{n([]),i()},[n,i]),g=u.useCallback(()=>{n(c),i()},[c,n,i]),j=u.useCallback(()=>{l([...o]),d(""),i()},[o,i]),k=t.filter(v=>!c.some(C=>C.column===v.name));return e.jsx(Dt.DndProvider,{backend:an.HTML5Backend,children:e.jsx(r.Box,{onClick:j,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:v=>z(v.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:v=>v.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:v=>v.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:v=>_e(v),bgcolor:"background.paper",outline:"none",boxShadow:v=>oe(v,"menu"),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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),e.jsx(ur,{content:pr.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:j,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:v=>z(v.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:v=>z(v.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:c.length>=f.sort.maxLevels,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Select column..."}),e.jsx(r.Select,{value:s,onChange:v=>m(v.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:k.map(v=>e.jsx(r.MenuItem,{value:v.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:C=>Pe(C),"&:hover":{bgcolor:C=>z(C.palette.primary.main,.2)}}},children:qe(v.name)},v.name))})]}),c.length>=f.sort.maxLevels&&e.jsxs(r.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",f.sort.maxLevels," sort levels allowed"]})]}),c.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",c.length,"/",f.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:E,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"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map((v,C)=>e.jsx(Xd,{rule:v,index:C,onToggleDirection:x,onRemove:h,onMove:b},`${v.column}-${C}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:j,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:v=>`${v.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:g,variant:"contained",disabled:!p||c.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:v=>`${v.shape.borderRadius}px`,boxShadow:v=>oe(v,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:v=>oe(v,"hoverButton")},"&:active":{boxShadow:v=>oe(v,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function Zd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:d,onRestoreView:c,onPermanentDelete:l,onPromoteToGlobal:p,isAdmin:f=!1,onClose:m}){var C,S;const h=$t(),x=h.palette,b=t.filter(w=>!w.isDeleted),E=t.filter(w=>w.isDeleted),g=b.filter(w=>w.scope==="global"),j=b.filter(w=>w.scope!=="global"),k=w=>{var q,ee,y,M,W;const a=w.scope==="global",I=w.id===o,R=f||!a,G=f&&!a;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:I?"primary.main":"divider",bgcolor:I?z(x.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:I?"primary.main":z(x.text.primary,.22)}},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.75,py:1.25,gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,minWidth:0,cursor:"pointer",display:"flex",alignItems:"center",gap:1},onClick:()=>{n(w.id),m()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:I?600:500,color:I?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w.name}),w.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[a&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(B.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:z(((q=x.info)==null?void 0:q.main)??x.primary.main,.1),color:((ee=x.info)==null?void 0:ee.main)??x.primary.main,border:`1px solid ${z(((y=x.info)==null?void 0:y.main)??x.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),w.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:z(x.text.secondary,.08),color:"text.secondary","& .MuiChip-label":{px:.75}}})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[G&&p&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:V=>{V.stopPropagation(),p(w.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((M=x.info)==null?void 0:M.main)??x.primary.main,bgcolor:z(((W=x.info)==null?void 0:W.main)??x.primary.main,.08)}},children:e.jsx(B.Language,{sx:{fontSize:16}})})}),R&&e.jsx(r.Tooltip,{title:a&&!f?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:a&&!f,onClick:V=>{V.stopPropagation(),s(w.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:z(x.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(B.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:a&&!f?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:a&&!f,onClick:V=>{V.stopPropagation(),d(w.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:z(x.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(B.Delete,{sx:{fontSize:15}})})})})]})]})},w.id)},v=w=>{var a;return e.jsxs(r.Paper,{variant:"outlined",sx:{px:1.75,py:1.25,borderRadius:"8px",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:z(x.text.primary,.02)},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",color:"text.disabled",textDecoration:"line-through",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[c&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:I=>{I.stopPropagation(),c(w.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:z(((a=x.success)==null?void 0:a.main)??"#2e7d32",.08)}},children:e.jsx(B.Undo,{sx:{fontSize:15}})})}),l&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:I=>{I.stopPropagation(),l(w.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:z(x.error.main,.08)}},children:e.jsx(B.Delete,{sx:{fontSize:15}})})})]})]},w.id)};return e.jsxs(r.Dialog,{open:!0,onClose:m,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:_e(h),maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${z(((C=x.common)==null?void 0:C.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600},children:"Manage Views"}),f&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:"Admin mode — you can promote Personal Views to Global"})]}),e.jsx(r.IconButton,{onClick:m,size:"small",sx:{color:"text.secondary"},children:e.jsx(B.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",startIcon:e.jsx(B.Add,{sx:{fontSize:16}}),size:"small",sx:{borderRadius:w=>`${w.shape.borderRadius}px`},children:"Create New View"})}),g.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1},children:[e.jsx(B.Language,{sx:{fontSize:14,color:((S=x.info)==null?void 0:S.main)??x.primary.main}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Global Views"}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:"— visible to all users"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:g.map(k)})]}),j.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Personal Views"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:j.map(k)})]}),E.length>0&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.disabled",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Recently Deleted"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:E.map(v)})]}),b.length===0&&E.length===0&&e.jsx(r.Box,{sx:{py:4,textAlign:"center",color:"text.disabled"},children:e.jsx(r.Typography,{variant:"body2",children:"No views created yet"})})]}),e.jsx(r.DialogActions,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:m,variant:"contained",sx:{fontSize:"0.875rem",borderRadius:w=>`${w.shape.borderRadius}px`,px:3},children:"Close"})})]})}const lo=50;function yi({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:d="",initialIsDefault:c=!1,atViewLimit:l=!1,maxViews:p=10}){const[f,m]=u.useState(s),[h,x]=u.useState(!1),[b,E]=u.useState(d),[g,j]=u.useState(c),k=()=>{if(!f.trim()){x(!0);return}if(f.trim().length>lo){x(!0);return}o(f.trim(),b.trim(),g),n()},v=S=>{S.key==="Enter"&&!S.shiftKey?k():S.key==="Escape"&&n()},C=()=>i&&s?`Update ${s} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:S=>_e(S),boxShadow:S=>oe(S,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[C(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&e.jsxs(r.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."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:f,onChange:S=>{S.target.value.length<=lo&&m(S.target.value),h&&S.target.value.trim()&&x(!1)},onKeyDown:v,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:lo},error:h&&!f.trim(),helperText:h&&!f.trim()?"View name is required":`${f.length} / ${lo}`}),e.jsx(r.TextField,{label:"Description (optional)",value:b,onChange:S=>E(S.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),e.jsxs(r.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1},children:"This view will capture:"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[e.jsxs("li",{children:[t.filters.length," filter",t.filters.length!==1?"s":""]}),e.jsxs("li",{children:["Sorting: ",aa(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:g,onChange:S=>j(S.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:S=>`${S.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:k,variant:"contained",disabled:l&&!i,startIcon:e.jsx(B.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:S=>`${S.shape.borderRadius}px`,boxShadow:S=>oe(S,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:S=>oe(S,"hoverButton")},"&:active":{boxShadow:S=>oe(S,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function eu({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>_e(i),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:i=>oe(i,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["Delete View",e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,mt:1},children:[e.jsx(B.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.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"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",sx:{fontSize:"0.875rem",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>oe(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>oe(i,"hoverButton")},"&:active":{boxShadow:i=>oe(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const uo=100,po=600,bi="COLUMN";function tu({column:t,index:o,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:d,moveColumn:c}){const l=u.useRef(null),[p,f]=u.useState(i.toString());u.useEffect(()=>{f(i.toString())},[i]);const[{handlerId:m},h]=Dt.useDrop({accept:bi,collect(v){return{handlerId:v.getHandlerId()}},hover(v,C){var q;if(!l.current)return;const S=v.index,w=o;if(S===w)return;const a=(q=l.current)==null?void 0:q.getBoundingClientRect(),I=(a.bottom-a.top)/2,R=C.getClientOffset(),G=((R==null?void 0:R.y)??0)-a.top;S<w&&G<I||S>w&&G>I||(c(S,w),v.index=w)}}),[{isDragging:x},b]=Dt.useDrag({type:bi,item:()=>({index:o}),collect:v=>({isDragging:v.isDragging()})});b(h(l));const E=()=>{const v=parseInt(p);if(isNaN(v)){f(i.toString()),d(t.name,i);return}const C=Math.max(uo,Math.min(po,v));f(C.toString()),d(t.name,C)},g=v=>{if(v===""||/^\d+$/.test(v)){f(v);const C=parseInt(v);if(!isNaN(C)&&C>=uo){const S=Math.min(po,C);d(t.name,S)}}},j=v=>{v.key==="Enter"&&(v.preventDefault(),E(),v.target.blur())},k=v=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[v]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":m,sx:{opacity:x?.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:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(B.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:qe(t.name)})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsx(r.Chip,{label:t.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${k(t.type)}15`,color:k(t.type),border:`1px solid ${k(t.type)}30`,"& .MuiChip-label":{px:1}}})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.TextField,{type:"number",value:p,onChange:v=>g(v.target.value),onBlur:E,onKeyDown:j,placeholder:"150",size:"small",inputProps:{min:uo,max:po,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}}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"px"})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.IconButton,{onClick:()=>s(t.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?e.jsx(B.Visibility,{sx:{fontSize:20}}):e.jsx(B.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?v=>z(v.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function ru({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:d="",onUpdateColumnVisibility:c,onUpdateColumnOrder:l,onUpdateColumnWidth:p,onResetLayout:f,onSaveToCurrentView:m,onSaveToAllViews:h,onSelectView:x,onClose:b}){const[E,g]=u.useState(!1),[j,k]=u.useState(n),[v,C]=u.useState(i),[S,w]=u.useState("all"),[a,I]=u.useState(null);u.useEffect(()=>{k(n)},[n]),u.useEffect(()=>{C(i)},[i]);const R=(F,O)=>{C(H=>({...H,[F]:O})),p==null||p(F,O)},G=(F,O)=>{const H=[...j],[re]=H.splice(F,1);H.splice(O,0,re),k(H),l(H)},q=()=>{f(),g(!1)},y=j.map(F=>t.find(O=>O.name===F)).filter(F=>F!==void 0).filter(F=>{const O=o[F.name]??!0;return S==="active"?O:S==="hidden"?!O:!0}),M=Object.values(o).filter(F=>F).length,W=t.length,V=s.find(F=>F.id===d),X=s.filter(F=>!F.isDeleted),ue=X.length>1,ce=u.useMemo(()=>{if(!V)return!1;const F=V.snapshot,O=F.columnVisibility??{},H=JSON.stringify(o)!==JSON.stringify(O),re=F.columnOrder??[],U=n??[],te=JSON.stringify(U)!==JSON.stringify(re)&&!(U.length===0&&re.length===0),se=F.columnWidths??{},ne=JSON.stringify(v)!==JSON.stringify(se);return H||te||ne},[V,o,n,v]);return e.jsx(Dt.DndProvider,{backend:an.HTML5Backend,children:e.jsx(r.Box,{onClick:b,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:F=>z(F.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:F=>F.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:F=>F.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:F=>_e(F),bgcolor:"background.paper",outline:"none",boxShadow:F=>oe(F,"menu"),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:[e.jsxs(r.Box,{sx:{px:3,pt:2,pb:1.5,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsx(r.Box,{sx:{flex:1},children:e.jsxs(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",e.jsx(ur,{content:pr.columns,isDev:process.env.NODE_ENV==="development"})]})}),X.length>0&&x&&e.jsxs(r.Box,{sx:{ml:2},children:[e.jsx(r.Button,{onClick:F=>I(F.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(B.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",fontSize:"0.875rem",color:"text.primary",borderColor:"divider",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(V==null?void 0:V.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:a,open:!!a,onClose:()=>I(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:F=>oe(F,"small")}},children:X.map(F=>e.jsx(r.MenuItem,{onClick:()=>{x(F.id),I(null)},selected:F.id===d,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:O=>Pe(O),"&:hover":{bgcolor:O=>z(O.palette.primary.main,.2)}}},children:F.name},F.id))})]}),e.jsx(r.IconButton,{onClick:b,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:S,onChange:(F,O)=>w(O),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:"primary.main",height:3}},children:[e.jsx(r.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}})]})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:F=>z(F.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:F=>z(F.palette.text.primary,.3)}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.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"}),e.jsx(r.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"}),e.jsx(r.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:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${uo}px, max: ${po}px)`,arrow:!0,placement:"top",children:e.jsx(B.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),e.jsx(r.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"})]})}),e.jsx(r.TableBody,{children:y.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:4,align:"center",sx:{py:6,borderBottom:"none"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):y.map((F,O)=>e.jsx(tu,{column:F,index:O,isVisible:o[F.name]??!0,width:v[F.name]||170,onToggleVisibility:c,onWidthChange:R,moveColumn:G},F.name))})]})}),e.jsx(r.Box,{sx:{px:3,py:1,borderTop:"1px solid divider",bgcolor:"background.default",flexShrink:0},children:e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:[M," of ",W," columns visible • Drag to reorder"]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:()=>g(!0),disabled:!ce,variant:"outlined",startIcon:e.jsx(B.Undo,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",px:2.5,py:.875,minHeight:36,borderRadius:F=>`${F.shape.borderRadius}px`,"&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Reset"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[m&&e.jsx(r.Button,{onClick:()=>{m(v),b()},disabled:!ce,variant:"contained",startIcon:e.jsx(B.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>oe(F,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:F=>oe(F,"hoverButton")},"&:active":{boxShadow:F=>oe(F,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to current view"}),h&&ue&&e.jsx(r.Button,{onClick:()=>{h(v),b()},disabled:!ce||!ue,variant:"contained",startIcon:e.jsx(B.GridView,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>oe(F,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:F=>oe(F,"hoverButton")},"&:active":{boxShadow:F=>oe(F,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to all views"})]})]}),E&&e.jsx(r.Box,{onClick:()=>g(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:F=>z(F.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:F=>F.zIndex.tooltip},children:e.jsxs(r.Paper,{onClick:F=>F.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:F=>Jr(F),bgcolor:"background.paper",boxShadow:F=>oe(F,"menu")},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.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."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:()=>g(!1),variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,borderRadius:F=>`${F.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:q,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>oe(F,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:F=>oe(F,"hoverButton")},"&:active":{boxShadow:F=>oe(F,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function ou({schema:t,grouping:o,onApply:n,onClose:i}){var a;const[s,d]=u.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[c,l]=u.useState(""),[p,f]=u.useState(null),m=u.useMemo(()=>ta(t),[t]),h=u.useMemo(()=>m.filter(I=>!s.levels.some((R,G)=>R.column===I.name&&G!==p)),[m,s.levels,p]),x=dr(),b=s.levels.length<x.grouping.maxLevels&&h.length>0,E=u.useCallback(()=>{!b||!c||(d({...s,levels:[...s.levels,{column:c}],enabled:!0}),l(""))},[b,c,s]),g=u.useCallback(I=>{const R=s.levels.filter((G,q)=>q!==I);if(R.length===0){n(null),i();return}d({...s,levels:R,enabled:R.length>0})},[s,n,i]),j=u.useCallback(I=>{f(I),l(s.levels[I].column)},[s.levels]),k=u.useCallback(()=>{if(p===null||!c)return;const I=[...s.levels];I[p]={column:c},d({...s,levels:I}),f(null),l("")},[p,c,s]),v=u.useCallback(()=>{f(null),l("")},[]),C=u.useCallback((I,R)=>{const G=R==="up"?I-1:I+1;if(G<0||G>=s.levels.length)return;const q=[...s.levels],[ee]=q.splice(I,1);q.splice(G,0,ee),d({...s,levels:q})},[s]),S=u.useCallback(()=>{n(null),i()},[n,i]),w=u.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[s,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:I=>z(I.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:I=>I.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:I=>I.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:I=>_e(I),bgcolor:"background.paper",outline:"none",boxShadow:I=>oe(I,"menu"),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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),e.jsx(ur,{content:pr.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:I=>z(I.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:I=>z(I.palette.text.primary,.3)}}},children:e.jsxs(r.Stack,{spacing:2.5,children:[p===null&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:c,onChange:I=>l(I.target.value),disabled:!b,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:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),h.map(I=>e.jsxs(r.MenuItem,{value:I.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:R=>Pe(R),"&:hover":{bgcolor:R=>z(R.palette.primary.main,.2)}}},children:[qe(I.name)," (",I.type.toUpperCase(),")"]},I.name))]})}),e.jsx(r.Button,{onClick:E,disabled:!b||!c,variant:"outlined",startIcon:e.jsx(B.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"action.hover"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Add group level"}),s.levels.length>=x.grouping.maxLevels&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),m.length===0&&e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),p!==null&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px",border:I=>`1px solid ${z(I.palette.warning.main,.5)}`,bgcolor:I=>z(I.palette.warning.main,.12),"& .MuiAlert-icon":{color:"warning.main"}},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1.5,fontSize:"0.875rem",color:"text.primary"},children:["Edit Group Level ",p+1]}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:c,onChange:I=>l(I.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:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:s.levels[p].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:I=>Pe(I)}},children:[s.levels[p].column," (",(a=t.find(I=>I.name===s.levels[p].column))==null?void 0:a.type.toUpperCase(),")"]}),h.filter(I=>I.name!==s.levels[p].column).map(I=>e.jsxs(r.MenuItem,{value:I.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:R=>Pe(R)}},children:[qe(I.name)," (",I.type.toUpperCase(),")"]},I.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:k,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:I=>oe(I,"pressedButton")}},children:"Save"}),e.jsx(r.Button,{onClick:v,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&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),e.jsx(r.Button,{onClick:S,size:"small",sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:s.levels.map((I,R)=>{const G=t.find(q=>q.name===I.column);return e.jsxs(r.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=>oe(q,"pressedButtonLight")}},children:[e.jsx(r.Chip,{label:`L${R+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 ${z(q.palette.primary.main,.3)}`}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:I.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:G==null?void 0:G.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>C(R,"up"),disabled:R===0,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(B.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>C(R,"down"),disabled:R===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(B.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(R),sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover",color:"primary.main"}},children:e.jsx(B.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>g(R),sx:{color:"text.secondary","&:hover":{bgcolor:q=>z(q.palette.error.main,.08),color:"error.main"}},children:e.jsx(B.Delete,{sx:{fontSize:18}})})]})]},R)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:I=>`${I.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.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:I=>`${I.shape.borderRadius}px`,boxShadow:I=>oe(I,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:I=>oe(I,"hoverButton")},"&:active":{boxShadow:I=>oe(I,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}function nu({onExportAnyway:t,onSaveAndExport:o,onCancel:n}){return e.jsx(r.Box,{sx:{mb:2,mx:3,mt:2},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(B.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(B.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,mb:.5},children:"You are exporting with unsaved view changes"}),e.jsx(r.Typography,{variant:"body2",sx:{mb:1.5},children:"Your current view has unsaved changes. Choose how to proceed:"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,variant:"contained",color:"primary",startIcon:e.jsx(B.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(B.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const vi=[{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 iu(t,o){if(o===null)return t.length;const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()>=n).length}function su(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function au({auditHistory:t,onClose:o,onClearAuditHistory:n}){var E,g,j,k;const i=$t(),s=i.palette,[d,c]=u.useState("1h"),[l,p]=u.useState(!1),f=[...t].sort((v,C)=>new Date(C.timestamp).getTime()-new Date(v.timestamp).getTime()),m=vi.find(v=>v.key===d),h=iu(t,m.ms),x=()=>p(!0),b=()=>{n&&(n(su(t,m.ms)),p(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:z(((E=s.common)==null?void 0:E.black)??"#000",.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:e.jsxs(r.Paper,{onClick:v=>v.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:_e(i),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${z(((g=s.common)==null?void 0:g.black)??"#000",.14)}, 0 2px 8px ${z(((j=s.common)==null?void 0:j.black)??"#000",.08)}`,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:[e.jsxs(r.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,borderBottom:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),e.jsx(ur,{content:pr.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[f.length," event",f.length!==1?"s":""," recorded"]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Select,{value:d,onChange:v=>c(v.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:z(s.text.primary,.3)}},children:vi.map(v=>e.jsx(r.MenuItem,{value:v.key,sx:{fontSize:"0.8125rem"},children:v.label},v.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(B.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:x,sx:{fontSize:"0.75rem",borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:z(s.error.main,.5),"&:hover":{bgcolor:z(s.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:z(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:z(s.text.primary,.14),borderRadius:3}},children:f.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(B.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",color:"text.secondary",fontWeight:500},children:"No audit events yet"}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:f.map(v=>{const C=wd(i,v.feature),{summary:S,detail:w}=va(v);return e.jsxs(r.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:z(s.text.primary,.18)}},children:[e.jsx(r.Chip,{label:Ca(v.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:z(C,.1),color:C,border:`1px solid ${z(C,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:S}),w&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:w}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(B.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:wa(v.timestamp)})]}),v.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(B.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:v.user})]})]})]})]},v.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>p(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:Jr(i),boxShadow:`0 8px 32px ${z(((k=s.common)==null?void 0:k.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:z(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(B.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["You are about to permanently remove"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:[h," audit record",h!==1?"s":""]})," ",m.key==="all"?"from all time":`from the ${m.label.toLowerCase()}`,". This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:()=>p(!1),variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:b,variant:"contained",color:"error",startIcon:e.jsx(B.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{fontSize:"0.8125rem",borderRadius:"7px",px:2},children:["Clear ",h," Record",h!==1?"s":""]})]})]})]})}function lu({onSave:t,onClose:o}){const[n,i]=u.useState(""),[s,d]=u.useState(""),[c,l]=u.useState(""),[p,f]=u.useState([]),[m,h]=u.useState(""),[x,b]=u.useState(""),E=w=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(w),g=()=>{const w=c.trim();if(w){if(!E(w)){b("Please enter a valid email address");return}if(p.includes(w)){b("This email is already added");return}f([...p,w]),l(""),b("")}},j=w=>{f(p.filter(a=>a!==w))},k=w=>{w.key==="Enter"&&(w.preventDefault(),g())},v=()=>{if(!n.trim()){h("Preset name is required");return}t(n.trim(),s.trim(),p.length>0?p:void 0)},C=w=>{i(w),m&&h("")},S=w=>{l(w),x&&b("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:w=>z(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:e.jsxs(r.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=>_e(w),bgcolor:"background.paper",outline:"none",boxShadow:w=>oe(w,"menu"),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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.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=>z(w.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:w=>z(w.palette.text.primary,.3)}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(B.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:w=>`1px solid ${z(w.palette.primary.main,.3)}`,bgcolor:w=>Pe(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."}),e.jsx(r.Typography,{variant:"body2",sx:{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."}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),e.jsx(r.TextField,{required:!0,value:n,onChange:w=>C(w.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!m,helperText:m,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}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value:s,onChange:w=>d(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}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:c,onChange:w=>S(w.target.value),onKeyPress:k,placeholder:"Enter email address",error:!!x,helperText:x,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(B.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}}}),e.jsx(r.Button,{onClick:g,variant:"outlined",startIcon:e.jsx(B.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&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:p.map(w=>e.jsx(r.Chip,{label:w,onDelete:()=>j(w),deleteIcon:e.jsx(B.Delete,{sx:{fontSize:16}}),sx:{bgcolor:a=>Pe(a),color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},w))}),e.jsx(r.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"})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:o,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"}),e.jsx(r.Button,{onClick:v,variant:"contained",startIcon:e.jsx(B.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=>oe(w,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:w=>oe(w,"hoverButton")},"&:active":{boxShadow:w=>oe(w,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function cu({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(B.Link,{sx:{fontSize:14}}),label:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Preset:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600},children:t})]}),onDelete:o,deleteIcon:e.jsx(r.IconButton,{size:"small",title:"Exit preset view",sx:{p:0},children:e.jsx(B.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>z(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 du({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:s}){const d=c=>new Date(c).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:c=>z(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:e.jsxs(r.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=>_e(c),bgcolor:"background.paper",outline:"none",boxShadow:c=>oe(c,"menu"),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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[t.length," saved ",t.length===1?"preset":"presets"]})]}),e.jsx(r.IconButton,{onClick:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.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=>z(c.palette.text.primary,.2)}}},children:t.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[e.jsx(B.Share,{sx:{fontSize:48,color:"divider",mb:2}}),e.jsx(r.Typography,{variant:"body1",sx:{fontSize:"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.disabled",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:t.map(c=>e.jsxs(r.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=>oe(l,"restButtonLight")}},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary",mb:.5},children:c.name}),c.description&&e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:c.description})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[e.jsx(r.Chip,{label:`Created ${d(c.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"action.hover",color:"text.secondary","& .MuiChip-label":{px:1}}}),e.jsx(r.Chip,{label:`By ${c.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"action.hover",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),e.jsx(r.Divider,{sx:{my:1.5,borderColor:"divider"}}),e.jsx(r.Box,{sx:{display:"flex",gap:1},children:e.jsx(r.Button,{onClick:()=>i(c.id,c.name),variant:"outlined",size:"small",startIcon:e.jsx(B.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=>z(l.palette.error.main,.04)}},children:"Delete"})})]},c.id))})}),e.jsx(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:e.jsx(r.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=>oe(c,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:c=>oe(c,"hoverButton")},"&:active":{boxShadow:c=>oe(c,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const ns={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},uu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],pu=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function xu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=pu.some(l=>l.test(i.name));let d=!1;const c=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);c.length>0&&(d=c.filter(p=>uu.some(f=>f.test(p))).length/c.length>.6),(s||d)&&n.push(i.name)}return n}function fn(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),s=o.map(c=>{const l=n.map(f=>String(f[c]??"")).filter(f=>f.length>0);if(l.length===0)return 5;const p=l.reduce((f,m)=>f+m.length,0);return Math.ceil(p/l.length)+1}).reduce((c,l)=>c+l,0)+1;return o.reduce((c,l)=>c+l.length+1,0)+s*t.length}function mu(t,o){const n=fn(t,o);return Math.ceil(n*3.5)}function hu(t,o){const n=fn(t,o);return Math.ceil(n*.7)}function fu(t,o,n){switch(t){case"csv":return fn(o,n);case"excel":return hu(o,n);case"json":return mu(o,n)}}function Si(t,o){return Math.ceil(t/o)}function gu(t,o,n,i,s=ns){const d=[],c=fu(t,o,n),l=o.length;if(l>s.maxRowsHard){const m=Si(l,s.maxRows);d.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 ${m} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:m,value:l,limit:s.maxRowsHard})}else if(l>s.maxRows){const m=Si(l,s.maxRows);d.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 ${m} smaller export${m>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:m,value:l,limit:s.maxRows})}if(c>s.maxFileSizeHardBytes?d.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Hr(c)} exceeds the ${Hr(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&&d.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Hr(c)}`,detail:`This exceeds the recommended ${Hr(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:c,limit:s.maxFileSizeBytes}),t!=="excel"){const m=xu(i.filter(h=>n.includes(h.name)),o);if(m.length>0){const h=m.length>s.maxImageColumns;d.push({type:"image_columns",severity:h?"error":"warning",message:`Image column${m.length>1?"s":""} detected: ${m.map(x=>`"${x.replace(/_/g," ")}"`).join(", ")}`,detail:h?`Exporting ${m.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:m.length,limit:s.maxImageColumns})}}const p=d.some(m=>m.severity==="error"),f=d.some(m=>m.severity==="warning");return{violations:d,hasBlockingViolation:p,hasWarning:f,estimatedBytes:c}}function Hr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function yu({violation:t}){const n=$t().palette,i=t.severity==="error",s=i?n.error.main:n.warning.main,d=z(i?n.error.main:n.warning.main,.06),c=i?z(n.error.main,.25):z(n.warning.main,.3),l=i?B.ErrorOutline:B.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:d,border:"1px solid",borderColor:c},children:[e.jsx(l,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:t.message}),t.detail&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:t.detail}),t.suggestedBatches&&t.suggestedBatches>1&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[e.jsx(B.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function bu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:d,sampleRows:c=[],allRows:l=[],processedRows:p=[],onExport:f,onClose:m}){var M,W,V;const h=$t(),x=h.palette,b=dr(),[E,g]=u.useState(b.export.allowedFormats[0]||"csv"),[j,k]=u.useState("visible"),[v,C]=u.useState("visible"),S=j==="visible"?o:t,w=v==="visible"?i:s,a=u.useMemo(()=>j==="visible"?p.length>0?p:new Array(o):l.length>0?l:new Array(t),[j,o,t,p,l]),I=u.useMemo(()=>v==="all"?d.map(X=>X.name):d.map(X=>X.name).slice(0,i),[v,d,i]),R=u.useMemo(()=>gu(E,a,I,d,ns),[E,a,I,d]),G=()=>{R.hasBlockingViolation||(f({format:E,scope:j,columnScope:v}),m())},q={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},ee={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},y={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:m,sx:{position:"fixed",inset:0,bgcolor:z(((M=x.common)==null?void 0:M.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:h.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:X=>X.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:_e(h),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${z(((W=x.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${z(((V=x.common)==null?void 0:V.black)??"#000",.08)}`,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:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(ur,{content:pr.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:m,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(B.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflowY:"auto",px:3,py:2.5,display:"flex",flexDirection:"column",gap:2.5,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:z(x.text.primary,.15),borderRadius:3}},children:[R.violations.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:R.violations.map((X,ue)=>e.jsx(yu,{violation:X},ue))}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Format"}),e.jsxs(r.RadioGroup,{value:E,onChange:X=>g(X.target.value),children:[b.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Comma-separated values, compatible with Excel"})]}),sx:{...ee,mb:.5}}),b.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Native Excel format with formatting support"})]}),sx:{...ee,mb:.5}}),b.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"JSON"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Structured data with metadata and filters"})]}),sx:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Rows"}),e.jsxs(r.RadioGroup,{value:j,onChange:X=>k(X.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",o.toLocaleString()," rows (filtered and searched)"]})]}),sx:{...ee,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",t.toLocaleString()," rows (complete original dataset)"]})]}),sx:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Columns"}),e.jsxs(r.RadioGroup,{value:v,onChange:X=>C(X.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible columns only"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",i," visible column",i!==1?"s":""]})]}),sx:{...ee,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:y}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",s," columns (including hidden)"]})]}),sx:ee})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Divider,{sx:{mb:2}}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[{label:"Format",value:q[E]},{label:"Rows to export",value:S.toLocaleString()},{label:"Columns to export",value:String(w)},{label:"Estimated file size",value:Hr(R.estimatedBytes),highlight:R.hasBlockingViolation?"error.main":R.hasWarning?"warning.main":void 0}].map(({label:X,value:ue,highlight:ce})=>e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary"},children:X}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:ce??"text.primary"},children:ue})]},X))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:z(x.text.primary,.015)},children:[R.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(B.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"error.main",fontWeight:500},children:"Reduce rows or columns to enable download"})]}),e.jsx(r.Button,{onClick:m,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:G,disabled:R.hasBlockingViolation,variant:"contained",startIcon:e.jsx(B.Download,{sx:{fontSize:16}}),sx:{fontSize:"0.875rem",px:2.5,borderRadius:"8px"},children:["Download ",q[E]]})]})]})})}function vu({warning:t,onDismiss:o}){return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(B.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(B.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:t.message}),e.jsxs(r.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",t.type==="filter"?"filters":t.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function Su({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){u.useEffect(()=>{if(n){const l=setTimeout(()=>{o()},i);return()=>clearTimeout(l)}},[n,i,o]);const d=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(B.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(B.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(B.InfoOutlined,{sx:{fontSize:20}})}}})(),c=Aa(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:d.severity,icon:d.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${d.severity}.main`},children:e.jsx(B.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${d.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:c}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class ju extends u.Component{constructor(n){super(n);wn(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){lr.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:e.jsx(r.Paper,{sx:{bgcolor:s=>z(s.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(B.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.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"&&e.jsx(r.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:s=>z(s.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:170},children:(i=this.state.error)==null?void 0:i.stack}),e.jsx(r.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:e.jsx(B.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Cu({feature:t}){const[o,n]=u.useState(!0);return u.useEffect(()=>{const i=setTimeout(()=>n(!1),5e3);return()=>clearTimeout(i)},[]),e.jsx(r.Collapse,{in:o,unmountOnExit:!0,children:e.jsxs(r.Alert,{severity:"warning",sx:{m:1},icon:e.jsx(B.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(B.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Pr({children:t,feature:o,onError:n}){return e.jsx(ju,{context:o,onError:i=>{n&&n(i)},fallback:e.jsx(Cu,{feature:o}),children:t})}const wu=[{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"}],ku=[{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"}];function Lr({children:t,active:o}){return e.jsx(r.Box,{hidden:!o,sx:{pt:2.5,pb:1,display:o?"flex":"none",flexDirection:"column",gap:2.5},children:t})}function Tu({open:t,onClose:o,config:n,onApply:i}){const[s,d]=u.useState(0),[c,l]=u.useState(n),p=()=>l(n),f=()=>l(Ge),m=()=>{i(c),o()},h={sort:j=>l(k=>({...k,sort:{...k.sort,...j}})),filter:j=>l(k=>({...k,filter:{...k.filter,...j}})),columns:j=>l(k=>({...k,columns:{...k.columns,...j}})),grouping:j=>l(k=>({...k,grouping:{...k.grouping,...j}})),export:j=>l(k=>({...k,export:{...k.export,...j}}))},x=j=>{const k=c.filter.allowedOperators,v=k.includes(j)?k.filter(C=>C!==j):[...k,j];v.length!==0&&h.filter({allowedOperators:v})},b=j=>{const k=c.export.allowedFormats,v=k.includes(j)?k.filter(C=>C!==j):[...k,j];v.length!==0&&h.export({allowedFormats:v})},E=[{label:"Sort",icon:e.jsx(B.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(B.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(B.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(B.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(B.Download,{sx:{fontSize:17}})}],g=j=>JSON.stringify(c[j])===JSON.stringify(Ge[j]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:p},PaperProps:{sx:{borderRadius:j=>_e(j),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:j=>`0 8px 32px ${z(j.palette.common.black,.2)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:j=>z(j.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem"},children:"⚙️"}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle1",sx:{fontWeight:600,lineHeight:1.2},children:"Developer Configuration"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"Set runtime constraints · Ctrl+Shift+D"})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary"},children:e.jsx(B.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:s,onChange:(j,k)=>d(k),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:E.map((j,k)=>e.jsx(r.Tab,{label:j.label,icon:j.icon,iconPosition:"start"},k))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Lr,{active:s===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!g("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:c.sort.maxLevels,onChange:(j,k)=>h.sort({maxLevels:k}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(Lr,{active:s===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!g("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:c.filter.maxConditions,onChange:(j,k)=>h.filter({maxConditions:k}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),e.jsx(r.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(j=>e.jsxs(r.Box,{sx:{mb:1.5},children:[e.jsx(r.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:j}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:wu.filter(k=>k.group===j).map(k=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:c.filter.allowedOperators.includes(k.value),onChange:()=>x(k.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:k.label}),sx:{mr:1.5}},k.value))})]},j))]})]}),e.jsxs(Lr,{active:s===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!g("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:c.columns.maxVisible,onChange:(j,k)=>h.columns({maxVisible:k}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:c.columns.minColumnWidth,onChange:(j,k)=>h.columns({minColumnWidth:k}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),e.jsx(r.Slider,{value:c.columns.maxColumnWidth,onChange:(j,k)=>h.columns({maxColumnWidth:k}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]})]})]})]}),e.jsxs(Lr,{active:s===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!g("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(j=>e.jsxs(r.Box,{onClick:()=>h.grouping({maxLevels:j}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:c.grouping.maxLevels===j?"primary.main":"divider",bgcolor:c.grouping.maxLevels===j?k=>z(k.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:k=>z(k.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:c.grouping.maxLevels===j?"primary.main":"text.secondary"},children:j}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][j-1]})]},j))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:c.grouping.allowNested,onChange:j=>h.grouping({allowNested:j.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow nested groups"})}),e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:c.grouping.allowCollapse,onChange:j=>h.grouping({allowCollapse:j.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),e.jsx(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),e.jsx(Lr,{active:s===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!g("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.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."}),e.jsx(r.FormGroup,{sx:{gap:1},children:ku.map(j=>e.jsxs(r.Box,{onClick:()=>b(j.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(j.value)?"primary.main":"divider",bgcolor:c.export.allowedFormats.includes(j.value)?k=>z(k.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:c.export.allowedFormats.includes(j.value),onChange:()=>b(j.value),onClick:k=>k.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:j.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:j.desc})]})]},j.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:j=>z(j.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(B.RestartAlt,{sx:{fontSize:18}}),onClick:f,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:j=>z(j.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:m,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const zu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Iu={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(t,o,n,i,s=new Date){const[d,c]=o.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(d,c,0,0),t==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const p=n??1,f=l.getDay();let m=p-f;return m<0&&(m+=7),m===0&&l<=s&&(m=7),l.setDate(l.getDate()+m),l.toISOString()}if(t==="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 Bu(t){const o=is(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${zu[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Iu[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function is(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Eu(t){const o=new Date(t).getTime()-Date.now();if(o<=0)return"now";const n=Math.floor(o/1e3),i=Math.floor(n/86400),s=Math.floor(n%86400/3600),d=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${d}m`:d>0?`in ${d}m`:"in less than a minute"}function Du(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=is(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${s}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${s}`}function ss(t){return`urm_schedules_${t}`}function as(t){try{const o=localStorage.getItem(ss(t));return o?JSON.parse(o).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 ls(t,o){try{localStorage.setItem(ss(t),JSON.stringify(o))}catch{}}const Ou=[{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"}],$u=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,cs={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},ar={"& .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 Au({initial:t=cs,isEditing:o=!1,onSave:n,onBack:i}){const[s,d]=u.useState(t),[c,l]=u.useState(!1),[p,f]=u.useState(!1),m=(b,E)=>d(g=>({...g,[b]:E})),h=s.email.trim().length>0&&!$u.test(s.email.trim()),x=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.dayOfMonth<=28)&&!h;return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[e.jsx(r.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:b=>z(b.palette.text.primary,.06)}},children:e.jsx(B.ArrowBack,{sx:{fontSize:18}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:o?"Edit schedule":"New schedule"})]}),e.jsx(r.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:b=>{m("name",b.target.value),c&&b.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:ar}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:ar,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:s.frequency,label:"Frequency",onChange:b=>m("frequency",b.target.value),children:[e.jsx(r.MenuItem,{value:"daily",children:"Daily"}),e.jsx(r.MenuItem,{value:"weekly",children:"Weekly"}),e.jsx(r.MenuItem,{value:"monthly",children:"Monthly"})]})]}),s.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:ar,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:s.dayOfWeek,label:"Day of week",onChange:b=>m("dayOfWeek",Number(b.target.value)),children:Ou.map(b=>e.jsx(r.MenuItem,{value:b.value,children:b.label},b.value))})]}),s.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:b=>m("dayOfMonth",Number(b.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:ar}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:b=>m("time",b.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:ar}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:ar,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:s.format,label:"Export format",onChange:b=>m("format",b.target.value),children:[e.jsx(r.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),e.jsx(r.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),e.jsx(r.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),e.jsxs(r.RadioGroup,{row:!0,value:s.scope,onChange:b=>m("scope",b.target.value),sx:{gap:2},children:[e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"All rows"})}),e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:s.email,onChange:b=>m("email",b.target.value),onBlur:()=>f(!0),placeholder:"user@company.com",error:p&&h,helperText:p&&h?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(B.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:ar}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(B.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.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."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:b=>z(b.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>x&&n(s),disabled:!x,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Mu({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>Jr(i),boxShadow:i=>{var s;return`0 8px 32px ${z(((s=i.palette.common)==null?void 0:s.black)??"#000",.14)}`}}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:i=>z(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(B.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:i=>`${i.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",sx:{fontSize:"0.8125rem",borderRadius:i=>`${i.shape.borderRadius}px`,px:2},children:"Delete"})]})]})}function Ru({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:s,onDelete:d}){const c=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:c?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:c?l=>z(l.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:c?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:c?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:c?l=>z(l.palette.success.main,.1):l=>z(l.palette.text.primary,.06),color:c?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:Bu(t)}),e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5,mb:1},children:[e.jsx(r.Chip,{label:t.format.toUpperCase(),size:"small",sx:{height:20,fontSize:"0.6875rem",fontWeight:500,bgcolor:l=>z(l.palette.primary.main,.08),color:"primary.main"}}),e.jsx(r.Chip,{label:t.scope==="all"?"All rows":"Filtered rows",size:"small",sx:{height:20,fontSize:"0.6875rem",bgcolor:l=>z(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(B.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>z(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[c&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",Eu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Du(t.lastRunAt)," · ",t.runCount," run",t.runCount!==1?"s":""]}):e.jsx(r.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[e.jsx(r.Tooltip,{title:"Edit",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>s(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>z(l.palette.primary.main,.08)}},children:e.jsx(B.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:c?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:c?"warning.main":"success.main","&:hover":{bgcolor:c?l=>z(l.palette.warning.main,.08):l=>z(l.palette.success.main,.08)}},children:c?e.jsx(B.Pause,{sx:{fontSize:15}}):e.jsx(B.PlayArrow,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Export now",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>i(t),sx:{color:"primary.main","&:hover":{bgcolor:l=>z(l.palette.primary.main,.08)}},children:e.jsx(B.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>d(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>z(l.palette.error.main,.08)}},children:e.jsx(B.Delete,{sx:{fontSize:15}})})})]})]})]})}function _u({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[d,c]=u.useState([]),[l,p]=u.useState({type:"list"}),[f,m]=u.useState(0),[h,x]=u.useState(null);u.useEffect(()=>{t&&(c(as(n)),p({type:"list"}))},[t,n]),u.useEffect(()=>{if(!t)return;const I=setInterval(()=>m(R=>R+1),3e4);return()=>clearInterval(I)},[t]);const b=u.useCallback(I=>{c(I),ls(n,I)},[n]),E=I=>{const R=xo(I.frequency,I.time,I.dayOfWeek,I.dayOfMonth),G={id:`sched-${Date.now()}`,reportId:n,name:I.name.trim(),frequency:I.frequency,dayOfWeek:I.frequency==="weekly"?I.dayOfWeek:void 0,dayOfMonth:I.frequency==="monthly"?I.dayOfMonth:void 0,time:I.time,format:I.format,scope:I.scope,email:I.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:R,runCount:0};b([...d,G]),p({type:"list"})},g=I=>{if(l.type!=="edit")return;const R=l.schedule,G=xo(I.frequency,I.time,I.dayOfWeek,I.dayOfMonth);b(d.map(q=>q.id===R.id?{...R,name:I.name.trim(),frequency:I.frequency,dayOfWeek:I.frequency==="weekly"?I.dayOfWeek:void 0,dayOfMonth:I.frequency==="monthly"?I.dayOfMonth:void 0,time:I.time,format:I.format,scope:I.scope,email:I.email.trim()||void 0,nextRunAt:G}:q)),p({type:"list"})},j=I=>{b(d.map(R=>{if(R.id!==I)return R;const G=R.isActive?R.nextRunAt:xo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:G}}))},k=I=>{s(I);const R=new Date().toISOString();b(d.map(G=>G.id===I.id?{...G,lastRunAt:R,runCount:G.runCount+1}:G))},v=I=>{const R=d.find(G=>G.id===I)??null;x(R)},C=()=>{h&&(b(d.filter(I=>I.id!==h.id)),x(null))},S=I=>({name:I.name,frequency:I.frequency,dayOfWeek:I.dayOfWeek??1,dayOfMonth:I.dayOfMonth??1,time:I.time,format:I.format,scope:I.scope,email:I.email??""}),w=l.type!=="list",a=d.filter(I=>I.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:w,PaperProps:{sx:{borderRadius:I=>_e(I),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:I=>z(I.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(B.Schedule,{sx:{fontSize:17,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"baseline",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,lineHeight:1},children:"Scheduled Reports"}),e.jsx(ur,{content:pr.schedule,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",sx:{lineHeight:1},children:["· ",i]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary","&:hover":{bgcolor:I=>z(I.palette.text.primary,.06)}},children:e.jsx(B.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[w&&e.jsx(Au,{initial:l.type==="edit"?S(l.schedule):cs,isEditing:l.type==="edit",onSave:l.type==="edit"?g:E,onBack:()=>p({type:"list"})}),l.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:d.length===0?"No schedules yet":`${a} of ${d.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(B.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",onClick:()=>p({type:"create"}),sx:{fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),d.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(B.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.secondary"},children:"No scheduled reports yet"}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map(I=>e.jsx(Ru,{schedule:I,tick:f,onToggle:j,onRunNow:k,onEdit:R=>p({type:"edit",schedule:R}),onDelete:v},I.id))})]})]}),l.type==="list"&&e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.25,borderTop:"1px solid",borderColor:"divider",flexShrink:0,display:"flex",alignItems:"center",gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75,px:1.25,py:.75,borderRadius:"8px",bgcolor:I=>z(I.palette.warning.main,.06),border:"1px solid",borderColor:I=>z(I.palette.warning.main,.2)},children:[e.jsx(B.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:I=>z(I.palette.text.primary,.06)}},children:"Close"})]})]}),h&&e.jsx(Mu,{scheduleName:h.name,onConfirm:C,onCancel:()=>x(null)})]})}const Wu=6e4;function Pu({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:d,columnVisibility:c,columnOrder:l,filters:p,sortStack:f,onFired:m}){const h=u.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:d,columnVisibility:c,columnOrder:l,filters:p,sortStack:f,onFired:m});u.useEffect(()=>{h.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:d,columnVisibility:c,columnOrder:l,filters:p,sortStack:f,onFired:m}});const x=u.useCallback(b=>{var I,R;const{reportName:E,uploadedData:g,processedData:j,schema:k,activeView:v,columnVisibility:C,columnOrder:S,filters:w,sortStack:a}=h.current;try{const G=b.scope==="all"?g:j,q=mo(G,k,w,a,v,C,S),ee=`${b.name}_scheduled`;switch(b.format){case"csv":ho(q,ee,{scope:b.scope});break;case"excel":fo(q,ee,{scope:b.scope});break;case"json":go(q,ee,{scope:b.scope});break}if(b.email){const y=encodeURIComponent(`Scheduled Report: ${b.name}`),M=encodeURIComponent(`Your scheduled report "${b.name}" has been generated.
|
|
89
|
+
]`})})]}),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:500,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:500,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:500,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:500,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=>se(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>se(n,"hoverButton")},"&:active":{boxShadow:n=>se(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function Nd({onFileUpload:e,onError:r,isUploading:n}){const[i,s]=p.useState(!1),[l,d]=p.useState(""),[c,u]=p.useState(!1),m=p.useRef(null),f=async w=>{if(!w.name.endsWith(".json")){r("Only .json files are allowed");return}const C=10*1024*1024;if(w.size>C){r("File size exceeds 10MB limit");return}d(w.name);try{const E=await w.text();let g;try{g=JSON.parse(E)}catch{r("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(g)){r("JSON must be an array of objects");return}if(g.length===0){r("No data rows found in JSON file");return}e(g)}catch{r("Network error — please try again")}finally{d("")}},x=w=>{w.preventDefault(),s(!0)},v=w=>{w.preventDefault(),s(!1)},b=w=>{w.preventDefault(),s(!1);const C=w.dataTransfer.files[0];C&&f(C)},z=()=>{var w;(w=m.current)==null||w.click()},S=w=>{var E;const C=(E=w.target.files)==null?void 0:E[0];C&&f(C)},y=w=>{w.stopPropagation(),u(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs(o.Box,{onDragOver:x,onDragLeave:v,onDrop:b,onPaste:w=>w.preventDefault(),onClick:z,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?w=>D(w.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:m,type:"file",accept:".json",onChange:S,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:500,mb:.5},children:"Uploading..."}),l&&t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:l})]}):t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:w=>D(w.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:t.jsx(T.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:y,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:t.jsx(T.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(Ss,{isOpen:c,onClose:()=>u(!1)})]})}function Ld({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:600,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:600},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(T.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 Fd({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(T.ErrorOutline,{color:"error",sx:{fontSize:32}})}),t.jsx(o.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:600,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(T.Upload,{sx:{fontSize:16}}),onClick:r,sx:{fontWeight:500},children:"Try Again"})]})}function Cs({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(T.Description,{sx:{fontSize:36,color:"primary.main"}})}),t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:500,mb:1,color:"text.primary",fontSize:"1.125rem"},children:e}),t.jsx(o.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:"0.875rem",lineHeight:1.5},children:r})]})}function Vd({value:e,onChange:r,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:l,disabled:d}){const[c,u]=p.useState(!1),[m,f]=p.useState(!1),[x,v]=p.useState(-1),b=p.useRef(null),z=p.useRef(null);p.useEffect(()=>{function _(F){b.current&&!b.current.contains(F.target)&&(u(!1),f(!1))}return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[]);const S=p.useCallback(()=>{f(!0),v(-1),n.length>0&&u(!0)},[n.length]),y=p.useCallback(_=>{r(_),v(-1)},[r]),w=p.useCallback(_=>{var F;r(_),i(_),u(!1),(F=z.current)==null||F.blur()},[r,i]),C=p.useCallback(_=>{v(-1),w(_)},[w]),E=p.useCallback(_=>{var F;_.key==="Enter"?x>=0&&x<n.length?(_.preventDefault(),C(n[x].query)):e.trim()&&w(e.trim()):_.key==="Escape"?(u(!1),v(-1),(F=z.current)==null||F.blur()):_.key==="ArrowDown"?(_.preventDefault(),n.length>0&&(c||u(!0),v(X=>X<n.length-1?X+1:X))):_.key==="ArrowUp"&&(_.preventDefault(),v(X=>X>0?X-1:-1))},[x,n,e,c,C,w]),g=p.useCallback(()=>{var _;r(""),(_=z.current)==null||_.focus()},[r]),k=p.useMemo(()=>n.filter(_=>_.isFavourite),[n]),L=p.useMemo(()=>n.filter(_=>!_.isFavourite),[n]),a=c&&n.length>0;return t.jsxs(o.Box,{sx:{position:"relative",width:240},ref:b,children:[t.jsx(o.TextField,{inputRef:z,size:"small",fullWidth:!0,value:e,onChange:_=>y(_.target.value),onFocus:S,onKeyDown:E,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:_=>D(_.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:_=>D(_.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(T.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:e?t.jsx(o.InputAdornment,{position:"end",children:t.jsx(o.IconButton,{size:"small",onClick:g,edge:"end",sx:{mr:-.5},children:t.jsx(T.Close,{sx:{fontSize:16}})})}):null}}),a&&t.jsxs(o.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[k.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:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),k.map((_,F)=>t.jsx(Ai,{entry:_,isSelected:x===F,onClick:()=>C(_.query),onToggleFavourite:()=>s(_.query),onDelete:()=>l(_.query)},`fav-${_.query}`))]}),L.length>0&&t.jsxs(o.Box,{sx:{py:1},children:[k.length>0&&t.jsx(o.Divider,{}),t.jsx(o.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),L.map((_,F)=>{const X=k.length+F;return t.jsx(Ai,{entry:_,isSelected:x===X,onClick:()=>C(_.query),onToggleFavourite:()=>s(_.query),onDelete:()=>l(_.query)},`recent-${_.query}`)})]})]})]})}const Ai=p.memo(function({entry:r,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:l}){const d=p.useCallback(u=>{u.stopPropagation(),s()},[s]),c=p.useCallback(u=>{u.stopPropagation(),l()},[l]);return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?u=>D(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>D(u.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:d,title:r.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:r.isFavourite?t.jsx(T.Star,{sx:{fontSize:14,color:"warning.light"}}):t.jsx(T.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),t.jsx(o.IconButton,{size:"small",onClick:c,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:t.jsx(T.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function Hd({views:e,activeViewId:r,isDirty:n,onSelectView:i,onCreateView:s,onToggleDefault:l,onToggleFavorite:d,onRestoreView:c,onPermanentDelete:u,onEditView:m,onCloneView:f,onCopyLink:x,onDeleteView:v,onPromoteToGlobal:b,isReadOnly:z,isAdmin:S=!1}){const y=Lt(),[w,C]=p.useState(!1),[E,g]=p.useState(!1),[k,L]=p.useState({top:0,left:0}),[a,_]=p.useState(null),[F,X]=p.useState(null),re=p.useRef(null),h=p.useRef(null),V=e.find(O=>O.id===r),W=V==null?void 0:V.isDefault,Q=(O,te)=>O.name.localeCompare(te.name),Z=e.filter(O=>O.scope==="global"&&!O.isDeleted).sort(Q),pe=e.filter(O=>O.scope!=="global"&&!O.isDeleted).sort(Q),he=e.filter(O=>O.isFavorite&&!O.isDeleted).sort(Q),N=e.filter(O=>O.isDeleted);p.useEffect(()=>{if(w&&h.current){const O=h.current.getBoundingClientRect();L({top:O.bottom+window.scrollY+8,left:O.right+window.scrollX-320})}},[w]),p.useEffect(()=>{const O=te=>{re.current&&!re.current.contains(te.target)&&h.current&&!h.current.contains(te.target)&&C(!1)};return w&&document.addEventListener("mousedown",O),()=>{document.removeEventListener("mousedown",O)}},[w]);const R=O=>{if(n&&O!==r){_(O),C(!1);return}i(O),C(!1)},H=()=>{a&&(i(a),_(null))},G=()=>{_(null)},ae=(O,te=!1)=>{const ce=O.scope==="global",ie=!z&&(!ce||S),Ie=S&&!ce;return t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:r===O.id?D(y.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:r===O.id?D(y.palette.primary.main,.12):y.palette.action.hover}},children:[t.jsxs(o.Button,{onClick:()=>R(O.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===O.id&&t.jsx(T.Check,{sx:{fontSize:16,flexShrink:0}}),r!==O.id&&t.jsx(o.Box,{sx:{width:"16px",flexShrink:0}}),t.jsx(o.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:r===O.id?y.palette.primary.dark:y.palette.text.primary,fontWeight:r===O.id?500:400},children:O.name}),te&&t.jsx(o.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:y.palette.text.secondary,backgroundColor:y.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:[ie&&d&&t.jsx(o.IconButton,{onClick:q=>{q.stopPropagation(),d(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},title:O.isFavorite?"Remove from favorites":"Add to favorites",children:t.jsx(T.Star,{sx:{fontSize:16}})}),ie&&l&&!O.isDefault&&t.jsx(o.IconButton,{onClick:q=>{q.stopPropagation(),l(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},title:"Set as default",children:t.jsx(T.RadioButtonUnchecked,{sx:{fontSize:16}})}),(ie||Ie)&&(m||f||x||v||Ie&&b)&&t.jsx(o.IconButton,{onClick:q=>{q.stopPropagation(),X({el:q.currentTarget,view:O})},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},title:"More actions",children:t.jsx(T.MoreVert,{sx:{fontSize:16}})})]})]},O.id)},ee=O=>t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:y.palette.action.hover},children:[t.jsx(o.Typography,{sx:{color:y.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:O.name}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[c&&t.jsx(o.IconButton,{onClick:te=>{te.stopPropagation(),c(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},title:"Restore view",children:t.jsx(T.Undo,{sx:{fontSize:16,color:"success.main"}})}),u&&t.jsx(o.IconButton,{onClick:te=>{te.stopPropagation(),u(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},title:"Delete permanently",children:t.jsx(T.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},O.id),ne=n||!W,oe=n;return t.jsxs(o.Box,{sx:{position:"relative"},children:[t.jsxs(o.Button,{ref:h,onClick:()=>C(!w),variant:"outlined",size:"small",endIcon:t.jsx(T.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{position:"relative",minWidth:140,maxWidth:220,justifyContent:"space-between",fontSize:"0.8125rem",textTransform:"none",color:ne?"warning.main":"text.primary",borderColor:ne?"warning.main":"divider",bgcolor:ne?D(y.palette.warning.main,.12):"transparent",borderRadius:1,py:.5,px:1.25,transition:"all 0.15s ease","&:hover":{borderColor:ne?"warning.dark":"primary.main",bgcolor:ne?D(y.palette.warning.main,.2):D(y.palette.text.primary,.06),color:ne?"warning.dark":"text.primary"}},title:`View: ${(V==null?void 0:V.name)||"Default View"}`,children:[t.jsx(o.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(V==null?void 0:V.name)||"Default View"}),oe&&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"}})]}),w&&Vi.createPortal(t.jsxs(o.Box,{ref:re,sx:{position:"fixed",width:"320px",backgroundColor:y.palette.background.paper,border:`1px solid ${y.palette.divider}`,borderRadius:1,boxShadow:y.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:k.top,left:k.left},children:[Z.length>0&&t.jsxs(o.Box,{sx:{py:.5},children:[t.jsx(o.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:y.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),Z.map(O=>ae(O,O.isDefault))]}),he.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${y.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:y.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[t.jsx(T.Star,{sx:{fontSize:12,color:"warning.light"}}),t.jsx(o.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),he.map(O=>ae(O))]})]}),pe.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${y.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsx(o.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:y.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),pe.map(O=>ae(O))]})]}),N.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{sx:{borderTop:`1px solid ${y.palette.divider}`}}),t.jsxs(o.Box,{sx:{py:.5},children:[t.jsxs(o.Button,{onClick:()=>g(!E),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:y.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},children:[t.jsxs(o.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",N.length,")"]}),t.jsx(T.ChevronRight,{sx:{fontSize:16}})]}),E&&t.jsx(o.Box,{sx:{backgroundColor:y.palette.action.hover},children:N.map(O=>ee(O))})]})]}),t.jsx(o.Box,{sx:{borderTop:`1px solid ${y.palette.divider}`}}),t.jsxs(o.Button,{onClick:()=>{s(),C(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:y.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:y.palette.action.hover}},children:[t.jsx(T.Add,{sx:{fontSize:16}}),t.jsx(o.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),t.jsxs(o.Popover,{open:!!F,anchorEl:(F==null?void 0:F.el)||null,onClose:()=>X(null),disablePortal:!0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[m&&t.jsxs(o.MenuItem,{onClick:()=>{F&&m(F.view.id),X(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx(T.Edit,{sx:{fontSize:18}}),"Edit"]}),x&&t.jsxs(o.MenuItem,{onClick:()=>{F&&x(F.view.id),X(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx(T.Link,{sx:{fontSize:18}}),"Copy Link"]}),f&&t.jsxs(o.MenuItem,{onClick:()=>{F&&f(F.view.id),X(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx(T.ContentCopy,{sx:{fontSize:18}}),"Clone"]}),b&&S&&(F==null?void 0:F.view.scope)!=="global"&&t.jsxs(o.MenuItem,{onClick:()=>{F&&b(F.view.id),X(null)},sx:{gap:1.5,fontSize:"body2.fontSize"},children:[t.jsx(T.Language,{sx:{fontSize:18}}),"Promote to Global"]}),v&&[t.jsx(o.Divider,{},"delete-divider"),t.jsxs(o.MenuItem,{onClick:()=>{F&&v(F.view.id),X(null)},sx:{gap:1.5,fontSize:"body2.fontSize",color:"error.main"},children:[t.jsx(T.Delete,{sx:{fontSize:18}}),"Delete"]},"delete-item")]]})]}),document.body),t.jsxs(o.Dialog,{open:a!==null,onClose:G,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:oo(y)}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[t.jsx(T.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:G,variant:"text",children:"Stay here"}),t.jsx(o.Button,{onClick:H,variant:"contained",color:"warning",children:"Discard & switch"})]})]})]})}function Ud({columnName:e,columnType:r="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:l=!1,hasModifications:d=!1,position:c,onSortAscending:u,onSortDescending:m,onRemoveSort:f,onFilter:x,onClearFilter:v,onGroupByColumn:b,onHideColumn:z,onManageColumns:S,onResetLayout:y,onClose:w}){var X,re;const C=Lt(),E=C.palette,g=p.useRef(null);p.useEffect(()=>{if(!g.current)return;const h=g.current,V=h.getBoundingClientRect(),W=window.innerWidth,Q=window.innerHeight;V.right>W-8&&(h.style.left=`${W-V.width-8}px`),V.bottom>Q-8&&(h.style.top=`${Q-V.height-8}px`)},[c]),p.useEffect(()=>{const h=W=>{g.current&&!g.current.contains(W.target)&&w()},V=W=>{W.key==="Escape"&&w()};return document.addEventListener("mousedown",h),document.addEventListener("keydown",V),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",V)}},[w]);const k=p.useCallback(h=>()=>{h(),w()},[w]),L=(n==null?void 0:n.direction)==="asc",a=(n==null?void 0:n.direction)==="desc",_=r==="number"?"0→9":r==="boolean"?"F→T":"A→Z",F=r==="number"?"9→0":r==="boolean"?"T→F":"Z→A";return Vi.createPortal(t.jsxs(o.Paper,{ref:g,elevation:0,sx:{position:"fixed",left:`${c.x}px`,top:`${c.y}px`,zIndex:C.zIndex.tooltip,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:oo(C),overflow:"hidden",boxShadow:`0 4px 20px ${D(((X=E.common)==null?void 0:X.black)??"#000",.12)}, 0 1px 4px ${D(((re=E.common)==null?void 0:re.black)??"#000",.06)}`},children:[!l&&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:"0.8125rem",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 (${_})`,placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:k(()=>u(e)),sx:{p:.625,borderRadius:"6px",color:L?"primary.main":"text.secondary",bgcolor:L?D(E.primary.main,.1):"transparent","&:hover":{bgcolor:D(E.primary.main,.08),color:"primary.main"}},children:t.jsx(T.ArrowUpward,{sx:{fontSize:16}})})}),t.jsx(o.Tooltip,{title:`Sort Descending (${F})`,placement:"top",arrow:!0,children:t.jsx(o.IconButton,{size:"small",onClick:k(()=>m(e)),sx:{p:.625,borderRadius:"6px",color:a?"primary.main":"text.secondary",bgcolor:a?D(E.primary.main,.1):"transparent","&:hover":{bgcolor:D(E.primary.main,.08),color:"primary.main"}},children:t.jsx(T.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:k(()=>f(e)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(E.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:t.jsx(T.Close,{sx:{fontSize:16}})})})})]})]}),t.jsxs(o.MenuList,{dense:!0,sx:{py:.5},children:[t.jsxs(o.MenuItem,{onClick:k(()=>x(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx(T.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&&!l&&t.jsxs(o.MenuItem,{onClick:k(()=>v(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(E.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(T.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!l&&b&&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:k(()=>b(e)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx(T.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:[!l&&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:k(()=>z(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(T.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:k(S),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(E.primary.main,.08),color:"primary.main"}},children:t.jsx(T.Settings,{sx:{fontSize:16}})})})]}),l&&t.jsxs(o.MenuItem,{onClick:k(S),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[t.jsx(o.ListItemIcon,{sx:{minWidth:28},children:t.jsx(T.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!l&&d&&y&&t.jsxs(o.MenuItem,{onClick:k(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(E.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(T.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),t.jsx(o.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const Gd=176,_i="COLUMN_HEADER",Yd=p.memo(function({column:r,index:n,sortRule:i,hasFilters:s,isInSortStack:l,isReadOnly:d=!1,hasModifications:c=!1,width:u,onColumnClick:m,onMoveColumn:f,onColumnDragEnd:x,onResizeStart:v,onSortAscending:b,onSortDescending:z,onRemoveSort:S,onOpenFilterForColumn:y,onClearFiltersForColumn:w,onGroupByColumn:C,onHideColumn:E,onManageColumns:g,onResetLayout:k}){const L=p.useRef(null),[a,_]=p.useState(!1),[F,X]=p.useState({x:0,y:0}),[{handlerId:re,isOver:h},V]=Pt.useDrop({accept:_i,collect(G){return{handlerId:G.getHandlerId(),isOver:G.isOver()}},hover(G,ae){var ie;if(!L.current)return;const ee=G.index,ne=n;if(ee===ne)return;const oe=(ie=L.current)==null?void 0:ie.getBoundingClientRect(),O=(oe.right-oe.left)/2,te=ae.getClientOffset(),ce=((te==null?void 0:te.x)??0)-oe.left;ee<ne&&ce<O||ee>ne&&ce>O||(f(ee,ne),G.index=ne)}}),[{isDragging:W},Q]=Pt.useDrag({type:_i,item:()=>({index:n,columnName:r.name}),collect:G=>({isDragging:G.isDragging()}),end:()=>{x==null||x()}});Q(V(L));const Z=p.useCallback(G=>{G.preventDefault(),G.stopPropagation(),X({x:G.clientX,y:G.clientY}),_(!0)},[]),pe=p.useCallback(()=>_(!1),[]),he=p.useCallback(()=>{m(r.name)},[m,r.name]),N=p.useCallback(G=>{G.stopPropagation(),y(r.name)},[y,r.name]),R=p.useCallback(()=>i?t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?t.jsx(T.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):t.jsx(T.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]),H=p.useCallback(()=>s?t.jsx(T.FilterList,{onClick:N,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,N]);return t.jsxs(t.Fragment,{children:[t.jsxs(o.TableCell,{ref:L,"data-handler-id":re,"data-column-index":n,onClick:he,onContextMenu:Z,sx:{position:"sticky",top:0,zIndex:5,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"visible",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:W?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:h?G=>D(G.palette.primary.main,.08):"action.hover",boxShadow:G=>`0 1px 0 ${D(G.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:G=>D(G.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${Gd}px`},children:[t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Qe(r.name),R(),H()]}),t.jsx(o.Box,{draggable:!1,onDragStart:G=>G.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:G=>{G.preventDefault(),G.stopPropagation(),v(G,r.name)},onClick:G=>G.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"}})}),h&&t.jsx(o.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),a&&t.jsx(Ud,{columnName:r.name,columnType:r.type,currentSort:i,hasFilters:s,isInSortStack:l,isReadOnly:d,hasModifications:c,position:F,onSortAscending:b,onSortDescending:z,onRemoveSort:S,onFilter:y,onClearFilter:w,onGroupByColumn:C,onHideColumn:E,onManageColumns:g,onResetLayout:k,onClose:pe})]})}),qd={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 Bo(e,r){const n=qd[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 Jd(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.warning.dark;case"critical":case"urgent":return e.palette.error.main;default:return}}const Kd={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 Xd(e,r){const n=Kd[r];return n?e.palette[n.hue][n.shade]:e.palette.text.secondary}function qe(e){return D(e.palette.primary.main,e.palette.mode==="dark"?.24:.12)}function Qd(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:500,bgcolor:n=>Bo(n,r).bg,color:n=>Bo(n,r).color,whiteSpace:"nowrap",lineHeight:1.5},children:e})}function Zd(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 Qd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=n.toLowerCase().trim();return t.jsx(o.Box,{component:"span",sx:l=>{const d=Jd(l,s);return d?{color:d,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 eu(e){const r=e.find(s=>{const l=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(l)})||e[0]||null,n=e.find(s=>{const l=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(l)&&s!==r})||null,i=e.filter(s=>s!==r&&s!==n).slice(0,4);return{primaryCol:r,idCol:n,bodyColumns:i}}function tu({row:e,rowIndex:r,visibleColumns:n,isSelected:i,isReadOnly:s,onToggleSelection:l,onView:d,onEdit:c,onDuplicate:u,onDelete:m}){const[f,x]=p.useState(null),[v,b]=p.useState(!1),{primaryCol:z,idCol:S,bodyColumns:y}=p.useMemo(()=>eu(n),[n]),w=z?e[z.name]:null,C=S?e[S.name]:null,E=v||i||!!f;return t.jsxs(o.Box,{onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),onClick:()=>l(r),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":g=>D(g.palette.divider,.8),borderWidth:i?2:1,borderRadius:"12px",cursor:"pointer",transition:"box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease",overflow:"hidden",minHeight:180,boxShadow:i?g=>`0 0 0 3px ${D(g.palette.primary.main,.15)}, 0 2px 8px ${D(g.palette.common.black,.08)}`:v?g=>se(g,"cardHover"):g=>se(g,"cardRest"),transform:v&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:g=>D(g.palette.primary.main,.03)}},children:[t.jsx(o.Box,{sx:{px:2,pt:2,pb:1.5},children:t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,fontSize:"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:w!=null&&w!==""?String(w):t.jsx(o.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})}),t.jsx(o.Box,{sx:{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:[y.map(g=>t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{sx:{color:"text.secondary",fontWeight:500,fontSize:"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1.2,mb:.25},children:Qe(g.name)}),t.jsx(o.Box,{sx:{lineHeight:1.3,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},title:String(e[g.name]??""),children:Zd(g,e[g.name])})]},g.name)),y.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:g=>D(g.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:C?.85:0,userSelect:"none"},children:C?String(C):" "}),t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:E?1:0,transition:"opacity 0.15s ease"},onClick:g=>g.stopPropagation(),children:t.jsx(o.Tooltip,{title:"More actions",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:g=>{g.stopPropagation(),x(g.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:g=>D(g.palette.text.primary,.08)}},children:t.jsx(T.MoreVert,{sx:{fontSize:17}})})})})]}),t.jsxs(o.Popover,{open:!!f,anchorEl:f,onClose:()=>x(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:g=>se(g,"popover")}},onClick:g=>g.stopPropagation(),children:[t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{d(e),x(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[t.jsx(T.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"View"})]}),!s&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{c(e,r),x(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[t.jsx(T.Edit,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Edit"})]}),!s&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{u(r,e),x(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[t.jsx(T.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Duplicate"})]}),!s&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5,mx:.5}}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{m(r,e),x(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[t.jsx(T.Delete,{sx:{fontSize:18,color:"error.main"}}),t.jsx(o.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function ru({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=>se(s,"flatHover"),"&:hover":{bgcolor:s=>D(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[e.isCollapsed?t.jsx(T.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):t.jsx(T.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:Ki(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,l])=>Ji(l)).filter(Boolean).join(" • ")})]})}function ou({data:e,visibleColumns:r,grouping:n,selectedRowIds:i,isReadOnly:s,isGrouped:l,onToggleRowSelection:d,onToggleGroupCollapse:c,onViewRow:u,onEditRow:m,onDuplicateRow:f,onDeleteRow:x}){const v=p.useMemo(()=>{const b=new Set;return i.forEach(z=>{const S=z==null?void 0:z.__urm_row_id__;S!==void 0&&b.add(S)}),b},[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:b=>b.typography.fontFamily},children:t.jsx(o.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:1.5,alignContent:"start"},children:e.map((b,z)=>l&&b.isGroupHeader?t.jsx(ru,{row:b,grouping:n,onToggleCollapse:c||(()=>{})},`group-${b.groupKey}`):t.jsx(tu,{row:b,rowIndex:z,visibleColumns:r,isSelected:v.has(b==null?void 0:b.__urm_row_id__),isReadOnly:s,onToggleSelection:()=>d(b),onView:u,onEdit:m,onDuplicate:f,onDelete:x},`card-${z}`))})})}const Mi=[10,15,25,50,100];function nu(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 iu({currentPage:e,pageSize:r,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:l}){var V;const c=Lt().palette,u=Math.ceil(n/r),[m,f]=p.useState(String(e)),[x,v]=p.useState(null),[b,z]=p.useState(!1),S=p.useRef(null);p.useEffect(()=>{b||(f(String(e)),v(null))},[e,b]);const y=p.useCallback(()=>{const W=nu(m,u);if(W){v(W);return}const Q=parseInt(m.trim(),10);v(null),z(!1),Q!==e&&s(Q)},[m,u,e,s]),w=p.useCallback(W=>{var Q;W.key==="Enter"?(W.preventDefault(),y()):W.key==="Escape"&&(f(String(e)),v(null),z(!1),(Q=S.current)==null||Q.blur())},[y,e]),C=p.useCallback(()=>{f(String(e)),v(null),z(!1)},[e]),E=p.useCallback(()=>{z(!0),v(null),setTimeout(()=>{var W;return(W=S.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...Mi))return null;const g=()=>{f(String(e)),v(null),z(!1)},k=()=>{g(),s(1)},L=()=>{g(),e>1&&s(e-1)},a=()=>{g(),e<u&&s(e+1)},_=()=>{g(),s(u)},F=(e-1)*r+1,X=Math.min(e*r,n),re=`${Math.max(2,String(u).length+.5)}ch`,h={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:"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:"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:"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),t.jsx(o.Select,{value:r,onChange:W=>l(Number(W.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:Mi.map(W=>t.jsx(o.MenuItem,{value:W,sx:{fontSize:"0.8125rem"},children:W},W))})]}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[F,"–",X," of ",n]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[t.jsx(o.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),t.jsxs(o.Box,{sx:{position:"relative"},children:[x&&t.jsx(o.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:D(c.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${D(((V=c.common)==null?void 0:V.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:D(c.error.main,.4)}},children:t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:x})}),t.jsx(o.InputBase,{inputRef:S,value:m,onChange:W=>{f(W.target.value),x&&v(null)},onKeyDown:w,onFocus:E,onBlur:C,inputProps:{"aria-label":`Page number, 1 to ${u}`,style:{textAlign:"center",padding:"2px 0",width:re,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:x?"error.main":"text.primary",border:"1px solid",borderColor:x?"error.main":b?"primary.main":"divider",borderRadius:"4px",bgcolor:x?D(c.error.main,.04):b?D(c.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:x?"error.main":"text.secondary"},"&:focus-within":{boxShadow:x?`0 0 0 2px ${D(c.error.main,.2)}`:`0 0 0 2px ${D(c.primary.main,.2)}`}}})]}),t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",u]})]}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(o.IconButton,{onClick:k,disabled:e===1,size:"small",title:"First page",sx:h,children:t.jsx(T.FirstPage,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:L,disabled:e===1,size:"small",title:"Previous page",sx:h,children:t.jsx(T.ChevronLeft,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:a,disabled:e===u,size:"small",title:"Next page",sx:h,children:t.jsx(T.ChevronRight,{sx:{fontSize:20}})}),t.jsx(o.IconButton,{onClick:_,disabled:e===u,size:"small",title:"Last page",sx:h,children:t.jsx(T.LastPage,{sx:{fontSize:20}})})]})]})]})}function su(){return t.jsx(o.Chip,{icon:t.jsx(T.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const js="urm_hint_seen_";function au(e){try{return localStorage.getItem(js+e)==="true"}catch{return!1}}function lu(e){try{localStorage.setItem(js+e,"true")}catch{}}const ws={"& .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 In(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 ks({row:e,schema:r}){const i=Lt().palette,s=r.filter(c=>c.name in e),l=s.filter(c=>c.type!=="object"&&c.type!=="array"),d=s.filter(c=>c.type==="object"||c.type==="array");return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.map(c=>t.jsx(o.TextField,{label:Qe(c.name),value:In(e[c.name],c.type)||"No value",size:"small",fullWidth:!0,InputProps:{readOnly:!0},sx:ws},c.name)),d.map(c=>{const u=In(e[c.name],c.type);return t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:Qe(c.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:u?"text.primary":"text.disabled",fontStyle:u?"normal":"italic",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:160,overflowY:"auto"},children:u||"No value"})]},c.name)}),s.length===0&&t.jsx(o.Typography,{variant:"body2",sx:{color:"text.disabled",textAlign:"center",py:3},children:"No fields to display"})]})}function cu({open:e,onClose:r,row:n,schema:i,reportName:s}){var u,m;const l=Lt(),d=l.palette;if(!n)return null;const c=i.filter(f=>f.name in n).length;return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:Ne(l),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${D(((u=d.common)==null?void 0:u.black)??"#000",.14)}, 0 2px 8px ${D(((m=d.common)==null?void 0:m.black)??"#000",.08)}`,overflow:"hidden"}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},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(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(T.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"View Record"}),s&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s," · ",c," ",c===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(T.Close,{sx:{fontSize:18}})})]}),t.jsx(o.Divider,{}),t.jsx(o.DialogContent,{sx:{overflowY:"auto",flex:1,bgcolor:D(d.text.primary,.015)},children:t.jsx(ks,{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:f=>`${f.shape.borderRadius}px`,minWidth:80},children:"Close"})})]})}function du({open:e,onClose:r,onConfirm:n,row:i,schema:s}){return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:l=>Ne(l),maxHeight:"min(720px, calc(100vh - 80px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:l=>se(l,"menu")}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},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(T.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),t.jsx(o.Typography,{variant:"body2",sx:{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(T.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(ks,{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:"0.8125rem",color:"error.main",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(T.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=>se(l,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:l=>se(l,"hoverButton")},"&:active":{boxShadow:l=>se(l,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function uu({open:e,onClose:r,onSave:n,row:i,schema:s,reportName:l}){var y,w,C;const d=Lt(),c=d.palette,[u,m]=p.useState({});if(p.useEffect(()=>{e&&i&&m({...i})},[e,i]),!i)return null;const f=s.filter(E=>E.name in i),x=f.filter(E=>E.type!=="object"&&E.type!=="array"),v=f.filter(E=>E.type==="object"||E.type==="array"),b=(E,g)=>{m(k=>({...k,[E]:g}))},z=()=>{const E={...u};f.forEach(g=>{const k=u[g.name];if(g.type==="number"){const L=Number(k);E[g.name]=isNaN(L)?i[g.name]:L}else g.type==="boolean"&&(E[g.name]=!!k)}),n(E),r()},S=f.length;return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:Ne(d),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${D(((y=c.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${D(((w=c.common)==null?void 0:w.black)??"#000",.08)}`,overflow:"hidden"}},children:[t.jsxs(o.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},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=c.warning)==null?void 0:C.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(T.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),t.jsxs(o.Box,{sx:{minWidth:0},children:[t.jsx(o.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),l&&t.jsxs(o.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[l," · ",S," ",S===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(T.Close,{sx:{fontSize:18}})})]}),t.jsx(o.Divider,{}),t.jsxs(o.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:D(c.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[x.map(E=>{const g=u[E.name];return E.type==="boolean"?t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:Qe(E.name)}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(o.Switch,{checked:!!g,onChange:k=>b(E.name,k.target.checked),size:"small"}),t.jsx(o.Typography,{variant:"body2",sx:{color:"text.secondary"},children:g?"Enabled":"Disabled"})]})]},E.name):t.jsx(o.TextField,{label:Qe(E.name),value:g??"",onChange:k=>b(E.name,k.target.value),type:E.type==="number"?"number":"text",size:"small",fullWidth:!0,sx:ws},E.name)}),v.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:v.map(E=>{const g=In(i[E.name],E.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:{fontWeight:500,color:"text.secondary"},children:Qe(E.name)}),t.jsx(o.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:D(c.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(T.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(c.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:g?"text.primary":"text.disabled",fontStyle:g?"normal":"italic",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:160,overflowY:"auto"},children:g||"No value"})]},E.name)})}),f.length===0&&t.jsxs(o.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[t.jsx(T.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:E=>`${E.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:z,variant:"contained",startIcon:t.jsx(T.SaveOutlined,{sx:{fontSize:15}}),sx:{fontSize:"0.8125rem",px:2.5,borderRadius:E=>`${E.shape.borderRadius}px`,minWidth:90},children:"Save"})]})]})}const pu=176,xu=170,mu=40;function Ts(e){return e.type==="date"?180:pu}function fu(e,r){return r!=null&&r!==xu&&r!==Ts(e)}function hu(e,r,n){return p.useMemo(()=>{const i=e.map(x=>({name:x.name,width:r[x.name]??Ts(x),explicit:fu(x,r[x.name])})),s={};i.forEach(x=>{s[x.name]=x.width});const l=i.reduce((x,v)=>x+v.width,0),c=Math.max(0,n-mu)-l;if(c<=0)return{widths:s,fillerWidth:0};const u=i.filter(x=>!x.explicit);if(u.length===0)return{widths:s,fillerWidth:c};const m=u.reduce((x,v)=>x+v.width,0)||1;let f=0;return u.forEach((x,v)=>{const z=v===u.length-1?x.width+c-f:Math.round(x.width+c*x.width/m);s[x.name]=z,f+=z-x.width}),{widths:s,fillerWidth:0}},[e,r,n])}const Ri=176,yn=32,bn=24,gu=St(),yu={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function bu(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:500,bgcolor:n=>Bo(n,r).bg,color:n=>Bo(n,r).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:e})}function vu(e){const r=e.toLowerCase().trim(),n=yu[r];return n?t.jsx(o.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:e}):e}function Su(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((l,d)=>l.toLowerCase()===n.toLowerCase()?t.jsx(o.Box,{component:"mark",sx:{bgcolor:"warning.light",color:"inherit",px:"1px",borderRadius:"2px"},children:l},d):l)}function Cu(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 bu(s);if(/\b(priority|severity|urgency|importance|criticality)\b/.test(e.name.toLowerCase()))return vu(s);if(e.type==="date"){const c=e.dateFormat??"iso",u=ga(r,c,n??null);return t.jsx(o.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:u})}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 c=r.slice(0,3).map(u=>typeof u=="object"?JSON.stringify(u):String(u)).join(", ");return t.jsxs(o.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[c,r.length>3?` +${r.length-3} more`:""]})}if(typeof r=="object"){const c=JSON.stringify(r);return t.jsx(o.Box,{component:"span",title:c,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:c.length>40?c.slice(0,40)+"…":c})}return Su(s,i)}function ju({schema:e,data:r,sortStack:n=[],filters:i=gu,views:s=[],activeViewId:l="",isDirty:d=!1,isExporting:c=!1,columnVisibility:u={},columnOrder:m=[],columnWidths:f={},grouping:x=null,onSort:v,onSortAscending:b,onSortDescending:z,onOpenFilters:S,onOpenSort:y,onOpenFilterForColumn:w,onSelectView:C,onCreateView:E,onUpdateCurrentView:g,onSaveAsNewView:k,onDiscardChanges:L,onToggleDefault:a,onToggleFavorite:_,onRestoreView:F,onPermanentDelete:X,onEditView:re,onCloneView:h,onCopyLink:V,onDeleteView:W,onPromoteToGlobal:Q,isAdmin:Z=!1,onExport:pe,onOpenColumns:he,onUpdateColumnWidth:N,onUpdateColumnOrder:R,onUpdateColumnVisibility:H,onClearFiltersForColumn:G,onResetLayout:ae,onOpenGroup:ee,onGroupByColumn:ne,onToggleGroupCollapse:oe,onExpandAllGroups:O,onCollapseAllGroups:te,onOpenAuditHistory:ce,onOpenScheduledReports:ie,searchQuery:Ie,highlightQuery:q="",searchHistory:Me=[],onAddToSearchHistory:et,onToggleSearchFavourite:tt,onDeleteSearchHistory:rr,selectedRowIds:Ft=new Set,onSearchChange:Vt,onToggleRowSelection:rt,onToggleAllRows:pt,onRangeSelection:or,onClearSelection:Ct,onExportSelected:Je,currentPage:jt=1,pageSize:Bt=15,totalRowsBeforePagination:Ht=r.length,onPageChange:nr,onPageSizeChange:ir,isReadOnly:He=!1,userRole:no,reportName:sr,onEditRow:Ut,onDuplicateRow:ot,onDeleteRow:nt,showDevPanel:ar=!1,onOpenDevConfig:lr}){var co;const[wt,wr]=p.useState(null),[xt,Nr]=p.useState(0),[cr,dr]=p.useState(0),[me,kr]=p.useState(null),kt=((co=Sr().dates)==null?void 0:co.displayFormat)??null,[P,mt]=p.useState(null),[fe,Le]=p.useState(null),[Dt,ft]=p.useState(null),[Gt,Tt]=p.useState(!1),[Tr,Yt]=p.useState(!1),[ur,qt]=p.useState(null),[ze,K]=p.useState(!1),[Ot,we]=p.useState(null),[Ir,pr]=p.useState(null),[Se,Fe]=p.useState(null),[xr,it]=p.useState(null),ht=p.useRef(null),Ve=p.useCallback(()=>{ht.current&&(clearTimeout(ht.current),ht.current=null)},[]),mr=p.useCallback(()=>{Ve(),ht.current=setTimeout(()=>it(null),200)},[Ve]);p.useEffect(()=>Ve,[Ve]);const[zr,gt]=p.useState(null),[Ue,Er]=p.useState("list"),[Lr,$t]=p.useState(!1),[Jt,Fr]=p.useState(()=>!au("toolbar_search")),st=p.useRef(null),Kt=p.useRef(null),[Br,At]=p.useState(0);p.useLayoutEffect(()=>{const B=st.current;if(!B)return;At(B.clientWidth);const J=new ResizeObserver(xe=>{At(xe[0].contentRect.width)});return J.observe(B),()=>J.disconnect()},[]);const _t=p.useCallback(()=>{lu("toolbar_search"),Fr(!1)},[]);p.useEffect(()=>{if(!Jt)return;const B=setTimeout(_t,2e3);return()=>clearTimeout(B)},[Jt,_t]);const fr=p.useMemo(()=>{const B=me??m;return B.length>0?B.map(J=>e.find(xe=>xe.name===J)).filter(J=>J!==void 0):e},[me,m,e]),le=p.useMemo(()=>fr.filter(B=>u[B.name]!==!1),[fr,u]),ge=p.useMemo(()=>new Set(((x==null?void 0:x.levels)??[]).map(B=>B.column)),[x]),Ae=p.useMemo(()=>!(x!=null&&x.enabled)||x.levels.length===0||le.length>0&&ge.has(le[0].name)?0:(x.levels.length-1)*yn+bn,[x,le,ge]),{widths:yt,fillerWidth:bt}=hu(le,f,Br),Xt=p.useMemo(()=>e.filter(B=>u[B.name]===!1).length,[e,u]),so=p.useMemo(()=>e.map(B=>B.name),[e]),Dr=p.useMemo(()=>m.length===0?!1:JSON.stringify(m)!==JSON.stringify(so),[m,so]),qo=p.useCallback((B,J)=>{B.preventDefault(),B.stopPropagation(),wr(J),Nr(B.clientX),dr(f[J]||150)},[f]);p.useEffect(()=>{if(!wt)return;const B=xe=>{const Ge=xe.clientX-xt,Ye=Math.max(100,Math.min(600,cr+Ge));N==null||N(wt,Ye)},J=()=>{wr(null)};return document.addEventListener("mousemove",B),document.addEventListener("mouseup",J),()=>{document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",J)}},[wt,xt,cr,N]);const Jo=p.useCallback(B=>B==null?"-":typeof B=="object"?JSON.stringify(B):typeof B=="boolean"?B?"true":"false":String(B),[]);p.useCallback(B=>{const J=n.find(xe=>xe.column===B);return J?t.jsxs(o.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[J.direction==="asc"?t.jsx(T.ArrowUpward,{sx:{fontSize:14}}):t.jsx(T.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:J.priority})]}):null},[n]),p.useCallback(B=>Sn(i,B)?t.jsx(o.IconButton,{size:"small",onClick:xe=>{xe.stopPropagation(),w==null||w(B)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:t.jsx(T.FilterList,{sx:{fontSize:14}})}):null,[i,w]);const Ko=p.useCallback(B=>{v&&v(B)},[v]),Xo=p.useCallback((B,J)=>{kr(xe=>{const Ye=[...xe??(m.length>0?m:e.map(gr=>gr.name))],[ue]=Ye.splice(B,1);return Ye.splice(J,0,ue),Ye})},[m,e]),Qo=p.useCallback(()=>{me&&R&&R(me),kr(null)},[me,R]),Zo=p.useCallback(B=>{if(!v)return;const J=n.find(xe=>xe.column===B);(!J||J.direction!=="asc")&&v(B)},[v,n]),en=p.useCallback(B=>{if(!v)return;const J=n.find(xe=>xe.column===B);J?J.direction==="asc"&&v(B):(v(B),setTimeout(()=>v(B),0))},[v,n]),tn=p.useCallback(B=>{if(!v)return;const J=n.find(xe=>xe.column===B);J&&(J.direction==="asc"?(v(B),setTimeout(()=>v(B),0)):J.direction==="desc"&&v(B))},[v,n]),rn=p.useCallback(B=>{H&&H(B,!1)},[H]),hr=(x==null?void 0:x.enabled)&&r.length>0&&r[0]&&"isGroupHeader"in r[0],Mt=p.useMemo(()=>dt(i),[i]),on=n.length>0||Mt>0||((x==null?void 0:x.enabled)??!1)||Object.values(u).some(B=>B===!1),nn=(jt-1)*Bt,Pe=r,Rt=p.useMemo(()=>{const B=new Set;return Ft.forEach(J=>{const xe=J==null?void 0:J.__urm_row_id__;xe!==void 0&&B.add(xe)}),B},[Ft]);p.useEffect(()=>{const B=J=>{!pt||!Ct||J.target instanceof HTMLInputElement||J.target instanceof HTMLTextAreaElement||((J.ctrlKey||J.metaKey)&&J.key==="a"&&(J.preventDefault(),pt(!0,Pe)),J.key==="Escape"&&(J.preventDefault(),Ct()))};return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[pt,Ct,Pe]);const ao=p.useCallback((B,J)=>{rt&&(J.shiftKey&&P!==null?(J.preventDefault(),or&&or(P,B,Pe)):(rt(Pe[B]),mt(B)))},[rt,P,or,Pe]);!p.useMemo(()=>Pe.length>0&&Rt.size>0&&Pe.every(B=>Rt.has(B==null?void 0:B.__urm_row_id__)),[Pe,Rt])&&Pe.some(B=>Rt.has(B==null?void 0:B.__urm_row_id__));const Vr=rt&&pt,sn=p.useCallback(B=>{var Ge;const J=B.groupLevel,xe=J*yn;return t.jsx(o.TableRow,{onClick:()=>oe==null?void 0:oe(B.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:t.jsxs(o.TableCell,{colSpan:le.length+(Vr?1:0),sx:{pl:`${xe+bn}px`,position:"relative"},children:[Array.from({length:J}).map((Ye,ue)=>t.jsx(o.Box,{sx:{position:"absolute",left:`${bn+ue*yn+8}px`,top:0,bottom:0,width:"1px",bgcolor:"divider"}},ue)),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[B.isCollapsed?t.jsx(T.ChevronRight,{sx:{fontSize:16}}):t.jsx(T.KeyboardArrowDown,{sx:{fontSize:16}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:Ki(J,((Ge=x==null?void 0:x.levels[J])==null?void 0:Ge.column)||"",B.groupValue)}),t.jsxs(o.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:Ye=>D(Ye.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[B.rowCount," ",B.rowCount===1?"row":"rows"]}),Object.keys(B.aggregates).length>0&&t.jsx(o.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(B.aggregates).map(([Ye,ue])=>Ji(ue)).filter(Boolean).join(" • ")})]})]})},B.groupKey)},[le,Vr,x,oe]),lo=p.useCallback((B,J)=>{const xe=Rt.has(B==null?void 0:B.__urm_row_id__),Ge=fe===J,Ye=Gt&&(B==null?void 0:B.__urm_row_id__)===(Dt==null?void 0:Dt.__urm_row_id__);return t.jsxs(o.TableRow,{"data-row-index":J,onMouseEnter:()=>Le(J),onMouseLeave:()=>Le(null),onClick:ue=>{!rt||ue.target.closest("[data-row-action-btn]")||ao(J,ue)},onContextMenu:ue=>{ue.preventDefault(),ue.stopPropagation(),it(null),Fe({mouseX:ue.clientX,mouseY:ue.clientY,row:B,rowIndex:J})},sx:{height:34,cursor:"pointer",bgcolor:xe?ue=>D(ue.palette.warning.main,.12):Ye?ue=>D(ue.palette.info.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:xe?ue=>D(ue.palette.warning.main,.2):Ye?ue=>D(ue.palette.info.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[le.map((ue,gr)=>t.jsx(o.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:f[ue.name]?`${f[ue.name]}px`:`${ue.type==="date"?Math.max(Ri,180):Ri}px`,...gr===0&&Ae>0?{pl:`${Ae}px`}:{}},children:hr&&ge.has(ue.name)?null:Cu(ue,B[ue.name],kt,q)},ue.name)),t.jsx(o.TableCell,{sx:{p:0,border:"none",borderBottom:"1px solid",borderColor:"divider"}}),t.jsx(o.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:40,minWidth:40,maxWidth:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:Ge?ue=>`linear-gradient(to right, transparent, ${xe?D(ue.palette.warning.main,.12):ue.palette.background.paper} 32px)`:"transparent",opacity:Ge?1:0,transition:"opacity 0.12s ease, background 0.12s ease",zIndex:10,verticalAlign:"middle"},children:t.jsx(o.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:t.jsx(o.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ue=>{ue.stopPropagation(),ue.preventDefault(),it(null),Fe({anchorEl:ue.currentTarget,row:B,rowIndex:J})},sx:{color:"text.secondary",opacity:Ge?1:0,transition:"opacity 0.12s ease",pointerEvents:Ge?"auto":"none","&:hover":{bgcolor:ue=>D(ue.palette.text.primary,.08),color:"text.primary"}},children:t.jsx(T.MoreVert,{sx:{fontSize:18}})})})})]},J)},[Ft,nn,fe,ao,le,f,q,Jo,Ut,ot,nt,rt,ft,Tt,Dt,Gt,Fe,hr,ge,Ae]);return t.jsxs(Pt.DndProvider,{backend:zn.HTML5Backend,children:[t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[t.jsxs(o.Box,{sx:{position:"sticky",top:0,zIndex:10,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",px:2,py:0,height:56,display:"flex",alignItems:"center",gap:1},children:[He&&t.jsx(su,{}),Vt&&et&&tt&&rr&&t.jsx(o.Tooltip,{open:Jt,title:t.jsxs(o.Box,{sx:{p:.5},children:[t.jsx(o.Typography,{variant:"caption",sx:{display:"block",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:_t},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(Vd,{value:Ie||"",onChange:B=>{Jt&&_t(),Vt(B)},searchHistory:Me,onAddToHistory:et,onToggleFavourite:tt,onDeleteHistory:rr,disabled:He})})}),t.jsx(o.Tooltip,{title:"JSON format guide",children:t.jsx(o.IconButton,{size:"small",onClick:()=>$t(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:B=>D(B.palette.text.primary,.06),color:"text.primary"}},children:t.jsx(T.InfoOutlined,{sx:{fontSize:20}})})}),C&&E&&g&&s.length>0&&t.jsx(Hd,{views:s||[],activeViewId:l||"",isDirty:d,onSelectView:C,onCreateView:E,onToggleDefault:a,onToggleFavorite:_,onRestoreView:F,onPermanentDelete:X,onEditView:re,onCloneView:h,onCopyLink:V,onDeleteView:W,onPromoteToGlobal:Q,isAdmin:Z,isReadOnly:He}),d&&!He&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,ml:1},children:[g&&t.jsx(o.Button,{onClick:g,size:"small",variant:"contained",sx:{fontSize:"0.8125rem",px:2,boxShadow:"none"},children:"Save"}),k&&t.jsx(o.Button,{onClick:k,size:"small",variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",minWidth:0,px:1},children:"Save as new view"}),L&&t.jsx(o.Button,{onClick:L,size:"small",variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",minWidth:0,px:1},children:"Discard"})]}),ar&&lr&&t.jsx(o.Tooltip,{title:"Developer configuration",children:t.jsx(o.IconButton,{size:"small",onClick:lr,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:B=>D(B.palette.text.secondary,.3),"&:hover":{bgcolor:B=>D(B.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:t.jsx(T.DisplaySettings,{sx:{fontSize:20}})})}),t.jsx(o.Box,{sx:{flexGrow:1}}),!He&&y&&t.jsx(o.Tooltip,{title:"Sort",children:t.jsxs(o.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?B=>qe(B):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?B=>D(B.palette.primary.main,.2):B=>D(B.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[t.jsx(T.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})]})}),!He&&S&&t.jsx(o.Tooltip,{title:"Filter",children:t.jsxs(o.IconButton,{onClick:S,size:"small",sx:{position:"relative",color:Mt>0?"primary.main":"text.secondary",bgcolor:Mt>0?B=>qe(B):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Mt>0?B=>D(B.palette.primary.main,.2):B=>D(B.palette.text.primary,.06),color:Mt>0?"primary.main":"text.primary"}},children:[t.jsx(T.FilterList,{sx:{fontSize:20}}),Mt>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:Mt})]})}),!He&&he&&t.jsx(o.Tooltip,{title:"Show/Hide Columns",children:t.jsxs(o.IconButton,{onClick:he,size:"small",sx:{position:"relative",color:Xt>0||Dr?"primary.main":"text.secondary",bgcolor:Xt>0||Dr?B=>qe(B):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Xt>0||Dr?B=>D(B.palette.primary.main,.2):B=>D(B.palette.text.primary,.06),color:Xt>0||Dr?"primary.main":"text.primary"}},children:[t.jsx(T.ViewColumn,{sx:{fontSize:20}}),Xt>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:Xt})]})}),hr&&(O||te)&&(()=>{var xe;const B=(((xe=x==null?void 0:x.collapsedGroups)==null?void 0:xe.length)??0)>0,J=B?O:te;return J?t.jsx(o.Tooltip,{title:B?"Expand all groups":"Collapse all groups",children:t.jsx(o.IconButton,{onClick:J,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:Ge=>D(Ge.palette.text.primary,.06),color:"text.primary"}},children:B?t.jsx(T.UnfoldMore,{sx:{fontSize:20}}):t.jsx(T.UnfoldLess,{sx:{fontSize:20}})})}):null})(),t.jsx(o.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),t.jsx(o.Tooltip,{title:"List view",children:t.jsx(o.IconButton,{size:"small",onClick:()=>Er("list"),sx:{borderRadius:1,color:Ue==="list"?"primary.main":"text.secondary",bgcolor:Ue==="list"?B=>qe(B):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ue==="list"?B=>D(B.palette.primary.main,.2):B=>D(B.palette.text.primary,.06),color:Ue==="list"?"primary.main":"text.primary"}},children:t.jsx(T.TableRows,{sx:{fontSize:20}})})}),t.jsx(o.Tooltip,{title:"Grid view",children:t.jsx(o.IconButton,{size:"small",onClick:()=>Er("grid"),sx:{borderRadius:1,color:Ue==="grid"?"primary.main":"text.secondary",bgcolor:Ue==="grid"?B=>qe(B):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ue==="grid"?B=>D(B.palette.primary.main,.2):B=>D(B.palette.text.primary,.06),color:Ue==="grid"?"primary.main":"text.primary"}},children:t.jsx(T.GridView,{sx:{fontSize:20}})})}),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:B=>gt(B.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:B=>D(B.palette.text.primary,.06),color:"text.primary"}},children:t.jsx(T.Settings,{sx:{fontSize:20}})})})]}),t.jsxs(o.Popover,{open:!!zr,anchorEl:zr,onClose:()=>gt(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:[pe&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{pe(),gt(null)},disabled:c,sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.Download,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Export"})]}),!He&&ee&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ee(),gt(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.Layers,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Grouping"})]}),ce&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ce(),gt(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.History,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Audit History"})]}),ie&&t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{ie(),gt(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Scheduled Reports"})]})]}),t.jsxs(o.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[Ue==="grid"&&t.jsx(o.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:t.jsx(ou,{data:Pe,visibleColumns:le,grouping:x,selectedRowIds:Ft,isReadOnly:He,isGrouped:!!hr,onToggleRowSelection:rt||(()=>{}),onToggleGroupCollapse:oe,onViewRow:B=>{ft(B),Tt(!0)},onEditRow:(B,J)=>{we(B),pr(J),K(!0)},onDuplicateRow:(B,J)=>ot==null?void 0:ot(B,J),onDeleteRow:(B,J)=>{qt(J),Yt(!0)}})}),Ue==="list"&&t.jsxs(o.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[t.jsx(o.Box,{ref:st,onScroll:B=>{Kt.current&&(Kt.current.scrollLeft=B.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(yt).reduce((B,J)=>B+J,0)+bt+40}px`},children:[t.jsxs("colgroup",{children:[le.map(B=>t.jsx("col",{style:{width:`${yt[B.name]}px`}},B.name)),t.jsx("col",{style:{width:`${bt}px`}}),t.jsx("col",{style:{width:"40px"}})]}),t.jsx(o.TableHead,{children:t.jsxs(o.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[le.map((B,J)=>t.jsx(Yd,{column:B,index:J,sortRule:n.find(xe=>xe.column===B.name),hasFilters:Sn(i,B.name),isInSortStack:n.some(xe=>xe.column===B.name),isReadOnly:He,hasModifications:on,width:f[B.name],onColumnClick:Ko,onMoveColumn:Xo,onColumnDragEnd:Qo,onResizeStart:qo,onSortAscending:b||Zo,onSortDescending:z||en,onRemoveSort:tn,onOpenFilterForColumn:w||(()=>{}),onClearFiltersForColumn:G||(()=>{}),onGroupByColumn:ne,onHideColumn:rn,onManageColumns:he||(()=>{}),onResetLayout:ae},B.name)),t.jsx(o.TableCell,{sx:{p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}}),t.jsx(o.TableCell,{sx:{width:40,minWidth:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),t.jsx(o.Box,{ref:Kt,onScroll:B=>{st.current&&(st.current.scrollLeft=B.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:B=>B.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:B=>B.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:t.jsxs(o.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Object.values(yt).reduce((B,J)=>B+J,0)+bt+40}px`},children:[t.jsxs("colgroup",{children:[le.map(B=>t.jsx("col",{style:{width:`${yt[B.name]}px`}},B.name)),t.jsx("col",{style:{width:`${bt}px`}}),t.jsx("col",{style:{width:"40px"}})]}),t.jsx(o.TableBody,{children:Pe.length===0?t.jsx(o.TableRow,{children:t.jsx(o.TableCell,{colSpan:le.length+(Vr?1:0),align:"center",sx:{py:4},children:t.jsx(o.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):hr?Pe.map((B,J)=>B.isGroupHeader?sn(B):lo(B,J)):Pe.map((B,J)=>lo(B,J))})]})})]}),nr&&ir&&t.jsx(iu,{currentPage:jt,pageSize:Bt,totalRows:Ht,totalFields:e.length,onPageChange:nr,onPageSizeChange:ir}),!(nr&&ir)&&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 ",Pe.length," ",Pe.length===1?"row":"rows"]})})]})]}),t.jsxs(o.Popover,{open:!!Se,onClose:()=>{Fe(null),it(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:[t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(ft(Se.row),Tt(!0)),Fe(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"View"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(we(Se.row),pr(Se.rowIndex),K(!0)),Fe(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.Edit,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Edit"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(ot==null||ot(Se.rowIndex,Se.row)),Fe(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"Duplicate"})]}),Rt.size>0&&Je&&t.jsxs(t.Fragment,{children:[t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.MenuItem,{dense:!0,onMouseEnter:B=>{Ve(),it(B.currentTarget)},onMouseLeave:mr,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(T.Download,{sx:{fontSize:18,color:"text.secondary"}}),t.jsxs(o.Typography,{variant:"body2",children:["Export Selected (",Rt.size,")"]})]}),t.jsx(T.ChevronRight,{sx:{fontSize:18,color:"text.secondary"}})]}),t.jsx(o.Popper,{open:!!xr,anchorEl:xr,placement:"right-start",transition:!0,sx:{zIndex:B=>B.zIndex.modal+1},modifiers:[{name:"offset",options:{offset:[0,0]}}],children:({TransitionProps:B})=>t.jsx(o.Grow,{...B,timeout:150,children:t.jsx(o.Paper,{onMouseEnter:Ve,onMouseLeave:mr,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:()=>{Je("csv"),it(null),Fe(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.TableChart,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"CSV"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Je("excel"),it(null),Fe(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.TableChart,{sx:{fontSize:18,color:"success.main"}}),t.jsx(o.Typography,{variant:"body2",children:"Excel"})]}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Je("json"),it(null),Fe(null)},sx:{py:1,px:2,gap:1.5},children:[t.jsx(T.DataObject,{sx:{fontSize:18,color:"text.secondary"}}),t.jsx(o.Typography,{variant:"body2",children:"JSON"})]})]})})})})]}),t.jsx(o.Divider,{sx:{my:.5}}),t.jsxs(o.MenuItem,{dense:!0,onClick:()=>{Se&&(qt(Se.row),Yt(!0)),Fe(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[t.jsx(T.Delete,{sx:{fontSize:18,color:"error.main"}}),t.jsx(o.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),t.jsx(cu,{open:Gt,onClose:()=>{Tt(!1),ft(null)},row:Dt,schema:e,reportName:sr}),t.jsx(uu,{open:ze,onClose:()=>{K(!1),we(null),pr(null)},onSave:B=>{Ir!==null&&(Ut==null||Ut(Ir,B))},row:Ot,schema:e,reportName:sr}),t.jsx(du,{open:Tr,onClose:()=>{Yt(!1),qt(null)},onConfirm:()=>{ur!==null&&(nt==null||nt(ur))},row:ur,schema:e}),t.jsx(Ss,{isOpen:Lr,onClose:()=>$t(!1)})]})}function Cr({content:e,isDev:r=!1}){const[n,i]=p.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(T.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:600,color:"primary.main",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:"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,l)=>t.jsx(o.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},l))}),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:500,display:"block",mb:.25},children:"Dev note"}),t.jsx(o.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.5},children:e.devNote})]})]})]})]})]})}const jr={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."}},vn=40;function wu({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 ku({condition:e,schema:r,availableColumns:n,devConfig:i,onUpdate:s}){const l=r.find(u=>u.name===e.column),d=p.useMemo(()=>{const u=l?zo(l.type):[],m=i.filter.allowedOperators;return m.length>0?u.filter(f=>m.includes(f.value)):u},[l,i]),c=fl(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:u=>{var x;const m=r.find(v=>v.name===u.target.value),f=m?zo(m.type):[];s({column:u.target.value,operator:((x=f[0])==null?void 0:x.value)??e.operator,value:void 0})},displayEmpty:!0,sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper"},children:n.map(u=>t.jsx(o.MenuItem,{value:u.name,sx:{fontSize:"0.875rem"},children:Qe(u.name)},u.name))})}),t.jsx(o.FormControl,{size:"small",sx:{minWidth:130,flex:"1 1 130px"},children:t.jsx(o.Select,{value:e.operator,onChange:u=>s({operator:u.target.value,value:void 0}),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper"},children:d.map(u=>t.jsx(o.MenuItem,{value:u.value,sx:{fontSize:"0.875rem"},children:u.label},u.value))})}),c&&(l==null?void 0:l.type)==="date"&&t.jsx(o.TextField,{size:"small",type:"date",value:e.value??"",onChange:u=>s({value:u.target.value}),sx:{minWidth:160,flex:"1 1 160px","& .MuiInputBase-root":{height:36,fontSize:"0.875rem"}}}),c&&(l==null?void 0:l.type)!=="date"&&t.jsx(o.TextField,{size:"small",type:(l==null?void 0:l.type)==="number"?"number":"text",value:e.value??"",onChange:u=>s({value:(l==null?void 0:l.type)==="number"?Number(u.target.value):u.target.value}),placeholder:"Value…",sx:{minWidth:160,flex:"1 1 160px","& .MuiInputBase-root":{height:36,fontSize:"0.875rem"}}})]})}function Is({group:e,depth:r,schema:n,availableColumns:i,devConfig:s,maxConditions:l,totalConditions:d,onChange:c}){const u=d>=l;return t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[e.children.map((m,f)=>t.jsxs(o.Box,{sx:{display:"flex",alignItems:"stretch",gap:1},children:[t.jsxs(o.Box,{sx:{width:vn,flexShrink:0,position:"relative",display:"flex",justifyContent:"center"},children:[f<e.children.length-1&&t.jsx(o.Box,{sx:{position:"absolute",top:0,bottom:0,left:"50%",width:"1px",bgcolor:"divider"}}),f>0&&t.jsx(wu,{operator:e.operator,onSelect:x=>c(v=>Dn(v,e.id,x))}),f>0&&t.jsx(o.Box,{sx:{position:"absolute",top:13,left:"50%",width:vn/2,height:"1px",bgcolor:"divider"}})]}),t.jsx(o.Box,{sx:{flex:1,minWidth:0,pt:f>0?1:0},children:Re(m)?t.jsx(Tu,{group:m,depth:r+1,schema:n,availableColumns:i,devConfig:s,maxConditions:l,totalConditions:d,onChange:c}):t.jsx(ku,{condition:m,schema:n,availableColumns:i,devConfig:s,onUpdate:x=>c(v=>Bn(v,m.id,x))})}),t.jsx(o.IconButton,{size:"small",onClick:()=>c(x=>On(x,m.id)),sx:{mt:f>0?1:.25,color:"text.secondary",flexShrink:0},children:t.jsx(T.Close,{sx:{fontSize:16}})})]},m.id)),t.jsxs(o.Box,{sx:{display:"flex",gap:2,pl:`${vn}px`},children:[t.jsx(o.Button,{size:"small",disabled:u||i.length===0,onClick:()=>c(m=>{var f,x,v;return Pr(m,e.id,{id:Wr(),column:((f=i[0])==null?void 0:f.name)??"",operator:((v=zo(((x=i[0])==null?void 0:x.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:u,onClick:()=>c(m=>Pr(m,e.id,St())),sx:{fontSize:"0.8125rem",color:"text.secondary",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",textDecoration:"underline"}},children:"+ Add group"})]})]})}function Tu(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(Is,{...e})})}function Iu({schema:e,filters:r,onReplaceFilters:n,onClose:i,focusColumn:s}){const[l,d]=p.useState(r??St()),c=Sr(),u=p.useMemo(()=>e.filter(y=>y.type!=="mixed"&&y.type!=="null"&&y.type!=="array"&&y.type!=="object"),[e]);p.useEffect(()=>{var w;const y=r??St();if(s&&y.children.length===0){const C=e.find(E=>E.name===s);if(C){d(Pr(y,y.id,{id:Wr(),column:s,operator:((w=zo(C.type)[0])==null?void 0:w.value)??"equals"}));return}}d(y)},[r,s,e]);const m=dt(l),f=c.filter.maxConditions,x=p.useCallback(y=>{d(w=>y(w))},[]),v=p.useMemo(()=>JSON.stringify(l)!==JSON.stringify(r??St()),[l,r]),b=p.useCallback(()=>{n(l),i()},[l,n,i]),z=p.useCallback(()=>{d(r??St()),i()},[r,i]),S=p.useCallback(()=>{n(St()),i()},[n,i]);return t.jsx(o.Box,{onClick:z,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:y=>D(y.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:y=>y.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:y=>y.stopPropagation(),elevation:0,sx:{position:"relative",width:640,maxWidth:"calc(100vw - 120px)",maxHeight:"min(620px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:y=>Ne(y),bgcolor:"background.paper",outline:"none",boxShadow:y=>se(y,"menu"),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,borderBottom:"1px solid divider",flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",lineHeight:1.5},children:"Filter columns"}),t.jsx(Cr,{content:jr.filter,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:z,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx(T.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:y=>D(y.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:y=>D(y.palette.text.primary,.3)}}},children:[m===0&&t.jsxs(o.Typography,{variant:"body2",sx:{color:"text.disabled",fontSize:"0.875rem",mb:2},children:["No conditions yet — add one below to start filtering",s?` on "${Qe(s)}"`:"","."]}),t.jsx(Is,{group:l,depth:0,schema:e,availableColumns:u,devConfig:c,maxConditions:f,totalConditions:m,onChange:x}),m>=f&&t.jsxs(o.Typography,{variant:"caption",sx:{display:"block",mt:1.5,color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Filter limit reached — maximum ",f," 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:S,disabled:m===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:z,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:y=>`${y.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:b,disabled:!v,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:y=>`${y.shape.borderRadius}px`,boxShadow:y=>se(y,"restButton"),"&:hover":{bgcolor:"primary.dark"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})]})})}const Wi="SORT_RULE";function zu({rule:e,index:r,onToggleDirection:n,onRemove:i,onMove:s}){const l=p.useRef(null),[{handlerId:d},c]=Pt.useDrop({accept:Wi,collect(f){return{handlerId:f.getHandlerId()}},hover(f,x){var C;if(!l.current)return;const v=f.index,b=r;if(v===b)return;const z=(C=l.current)==null?void 0:C.getBoundingClientRect(),S=(z.bottom-z.top)/2,y=x.getClientOffset(),w=((y==null?void 0:y.y)??0)-z.top;v<b&&w<S||v>b&&w>S||(s(v,b),f.index=b)}}),[{isDragging:u},m]=Pt.useDrag({type:Wi,item:()=>({index:r}),collect:f=>({isDragging:f.isDragging()})});return m(c(l)),t.jsxs(o.Box,{ref:l,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:f=>se(f,"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:f=>`0 1px 2px 0 ${D(f.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:"0.875rem",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:f=>n(r,f.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:f=>qe(f),"&:hover":{bgcolor:f=>D(f.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:f=>qe(f),"&:hover":{bgcolor:f=>D(f.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:f=>D(f.palette.error.main,.08),transform:"scale(1.1)"}},children:t.jsx(T.Close,{sx:{fontSize:18}})})]})}function Eu({schema:e,sortStack:r,onUpdateSortStack:n,onClose:i}){const[s,l]=p.useState(""),[d,c]=p.useState([]);p.useEffect(()=>{c([...r])},[r]);const u=p.useMemo(()=>JSON.stringify(d)!==JSON.stringify(r),[d,r]),m=Sr(),f=p.useCallback(C=>{if(!C||d.length>=m.sort.maxLevels)return;const E={column:C,direction:"asc",priority:d.length+1};c([...d,E]),l(""),setTimeout(()=>{var g;return(g=document.activeElement)==null?void 0:g.blur()},0)},[d,m.sort.maxLevels]),x=p.useCallback(C=>{const g=d.filter((k,L)=>L!==C).map((k,L)=>({...k,priority:L+1}));c(g)},[d]),v=p.useCallback((C,E)=>{const g=[...d];g[C]={...g[C],direction:E},c(g)},[d]),b=p.useCallback((C,E)=>{const g=[...d],[k]=g.splice(C,1);g.splice(E,0,k);const L=g.map((a,_)=>({...a,priority:_+1}));c(L)},[d]),z=p.useCallback(()=>{n([]),i()},[n,i]),S=p.useCallback(()=>{n(d),i()},[d,n,i]),y=p.useCallback(()=>{c([...r]),l(""),i()},[r,i]),w=e.filter(C=>!d.some(E=>E.column===C.name));return t.jsx(Pt.DndProvider,{backend:zn.HTML5Backend,children:t.jsx(o.Box,{onClick:y,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:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:C=>Ne(C),bgcolor:"background.paper",outline:"none",boxShadow:C=>se(C,"menu"),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,borderBottom:"1px solid divider",flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),t.jsx(Cr,{content:jr.sort,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:y,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx(T.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:C=>D(C.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:C=>D(C.palette.text.primary,.3)}}},children:[t.jsxs(o.Box,{sx:{mb:2.5},children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",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:d.length>=m.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:C=>f(C.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:w.map(C=>t.jsx(o.MenuItem,{value:C.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:E=>qe(E),"&:hover":{bgcolor:E=>D(E.palette.primary.main,.2)}}},children:Qe(C.name)},C.name))})]}),d.length>=m.sort.maxLevels&&t.jsxs(o.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",m.sort.maxLevels," sort levels allowed"]})]}),d.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:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",d.length,"/",m.sort.maxLevels,")"]}),t.jsx(o.Button,{onClick:z,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:d.map((C,E)=>t.jsx(zu,{rule:C,index:E,onToggleDirection:v,onRemove:x,onMove:b},`${C.column}-${E}`))})]})]}),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:y,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:C=>`${C.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:S,variant:"contained",disabled:!u||d.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:C=>`${C.shape.borderRadius}px`,boxShadow:C=>se(C,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:C=>se(C,"hoverButton")},"&:active":{boxShadow:C=>se(C,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}const go=50;function Pi({currentSnapshot:e,onSave:r,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:l="",initialIsDefault:d=!1,atViewLimit:c=!1,maxViews:u=10}){const[m,f]=p.useState(s),[x,v]=p.useState(!1),[b,z]=p.useState(l),[S,y]=p.useState(d),w=()=>{if(!m.trim()){v(!0);return}if(m.trim().length>go){v(!0);return}r(m.trim(),b.trim(),S),n()},C=g=>{g.key==="Enter"&&!g.shiftKey?w():g.key==="Escape"&&n()},E=()=>i&&s?`Update ${s} view`:"Create New Report View";return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:g=>Ne(g),boxShadow:g=>se(g,"menu")}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[E(),t.jsx(o.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:t.jsx(T.Close,{sx:{fontSize:20}})})]}),t.jsx(o.DialogContent,{children:t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[c&&!i&&t.jsxs(o.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",u," saved views. Delete an existing view before creating a new one."]}),t.jsx(o.TextField,{label:"View Name",required:!0,value:m,onChange:g=>{g.target.value.length<=go&&f(g.target.value),x&&g.target.value.trim()&&v(!1)},onKeyDown:C,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:c&&!i,inputProps:{maxLength:go},error:x&&!m.trim(),helperText:x&&!m.trim()?"View name is required":`${m.length} / ${go}`}),t.jsx(o.TextField,{label:"Description (optional)",value:b,onChange:g=>z(g.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: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:[dt(e.filters)," filter",dt(e.filters)!==1?"s":""]}),t.jsxs("li",{children:["Sorting: ",Da(e.sortStack)]}),t.jsx("li",{children:"Column order & visibility"})]})]}),!i&&t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:S,onChange:g=>y(g.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:g=>`${g.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:c&&!i,startIcon:t.jsx(T.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:g=>`${g.shape.borderRadius}px`,boxShadow:g=>se(g,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:g=>se(g,"hoverButton")},"&:active":{boxShadow:g=>se(g,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function Bu({viewName:e,onConfirm:r,onCancel:n}){return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>Ne(i),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:i=>se(i,"menu")}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["Delete View",t.jsx(o.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:t.jsx(T.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(T.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=>se(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>se(i,"hoverButton")},"&:active":{boxShadow:i=>se(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const So=100,Co=600,Ni="COLUMN";function Du({column:e,index:r,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:l,moveColumn:d}){const c=p.useRef(null),[u,m]=p.useState(i.toString());p.useEffect(()=>{m(i.toString())},[i]);const[{handlerId:f},x]=Pt.useDrop({accept:Ni,collect(C){return{handlerId:C.getHandlerId()}},hover(C,E){var X;if(!c.current)return;const g=C.index,k=r;if(g===k)return;const L=(X=c.current)==null?void 0:X.getBoundingClientRect(),a=(L.bottom-L.top)/2,_=E.getClientOffset(),F=((_==null?void 0:_.y)??0)-L.top;g<k&&F<a||g>k&&F>a||(d(g,k),C.index=k)}}),[{isDragging:v},b]=Pt.useDrag({type:Ni,item:()=>({index:r}),collect:C=>({isDragging:C.isDragging()})});b(x(c));const z=()=>{const C=parseInt(u);if(isNaN(C)){m(i.toString()),l(e.name,i);return}const E=Math.max(So,Math.min(Co,C));m(E.toString()),l(e.name,E)},S=C=>{if(C===""||/^\d+$/.test(C)){m(C);const E=parseInt(C);if(!isNaN(E)&&E>=So){const g=Math.min(Co,E);l(e.name,g)}}},y=C=>{C.key==="Enter"&&(C.preventDefault(),z(),C.target.blur())},w=C=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[C]||"text.secondary";return t.jsxs(o.TableRow,{ref:c,"data-handler-id":f,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(T.DragIndicator,{sx:{fontSize:20}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Qe(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:`${w(e.type)}15`,color:w(e.type),border:`1px solid ${w(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:u,onChange:C=>S(C.target.value),onBlur:z,onKeyDown:y,placeholder:"150",size:"small",inputProps:{min:So,max:Co,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:"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(T.Visibility,{sx:{fontSize:20}}):t.jsx(T.VisibilityOff,{sx:{fontSize:20}})}),t.jsx(o.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?C=>D(C.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Ou({schema:e,columnVisibility:r,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:l="",onUpdateColumnVisibility:d,onUpdateColumnOrder:c,onUpdateColumnWidth:u,onResetLayout:m,onSaveToCurrentView:f,onSaveToAllViews:x,onSelectView:v,onClose:b}){const[z,S]=p.useState(!1),[y,w]=p.useState(n),[C,E]=p.useState(i),[g,k]=p.useState("all"),[L,a]=p.useState(null);p.useEffect(()=>{w(n)},[n]),p.useEffect(()=>{E(i)},[i]);const _=(N,R)=>{E(H=>({...H,[N]:R})),u==null||u(N,R)},F=(N,R)=>{const H=[...y],[G]=H.splice(N,1);H.splice(R,0,G),w(H),c(H)},X=()=>{m(),S(!1)},h=y.map(N=>e.find(R=>R.name===N)).filter(N=>N!==void 0).filter(N=>{const R=r[N.name]??!0;return g==="active"?R:g==="hidden"?!R:!0}),V=Object.values(r).filter(N=>N).length,W=e.length,Q=s.find(N=>N.id===l),Z=s.filter(N=>!N.isDeleted),pe=Z.length>1,he=p.useMemo(()=>{if(!Q)return!1;const N=Q.snapshot,R=N.columnVisibility??{},H=JSON.stringify(r)!==JSON.stringify(R),G=N.columnOrder??[],ae=n??[],ee=JSON.stringify(ae)!==JSON.stringify(G)&&!(ae.length===0&&G.length===0),ne=N.columnWidths??{},oe=JSON.stringify(C)!==JSON.stringify(ne);return H||ee||oe},[Q,r,n,C]);return t.jsx(Pt.DndProvider,{backend:zn.HTML5Backend,children:t.jsx(o.Box,{onClick:b,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:N=>D(N.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:N=>N.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:N=>N.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:N=>Ne(N),bgcolor:"background.paper",outline:"none",boxShadow:N=>se(N,"menu"),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,borderBottom:"1px solid divider",flexShrink:0},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:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",t.jsx(Cr,{content:jr.columns,isDev:process.env.NODE_ENV==="development"})]})}),Z.length>0&&v&&t.jsxs(o.Box,{sx:{ml:2},children:[t.jsx(o.Button,{onClick:N=>a(N.currentTarget),variant:"outlined",size:"small",endIcon:t.jsx(T.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",fontSize:"0.875rem",color:"text.primary",borderColor:"divider",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:t.jsx(o.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(Q==null?void 0:Q.name)||"Select View"})}),t.jsx(o.Menu,{anchorEl:L,open:!!L,onClose:()=>a(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:N=>se(N,"small")}},children:Z.map(N=>t.jsx(o.MenuItem,{onClick:()=>{v(N.id),a(null)},selected:N.id===l,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:R=>qe(R),"&:hover":{bgcolor:R=>D(R.palette.primary.main,.2)}}},children:N.name},N.id))})]}),t.jsx(o.IconButton,{onClick:b,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(T.Close,{sx:{fontSize:20}})})]}),t.jsxs(o.Tabs,{value:g,onChange:(N,R)=>k(R),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:"primary.main",height:3}},children:[t.jsx(o.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),t.jsx(o.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),t.jsx(o.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}})]})]}),t.jsx(o.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:N=>D(N.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:N=>D(N.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: ${So}px, max: ${Co}px)`,arrow:!0,placement:"top",children:t.jsx(T.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:h.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:"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):h.map((N,R)=>t.jsx(Du,{column:N,index:R,isVisible:r[N.name]??!0,width:C[N.name]||170,onToggleVisibility:d,onWidthChange:_,moveColumn:F},N.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:"0.8125rem",color:"text.secondary"},children:[V," of ",W," columns visible • Drag to reorder"]})}),t.jsxs(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:()=>S(!0),disabled:!he,variant:"outlined",startIcon:t.jsx(T.Undo,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",px:2.5,py:.875,minHeight:36,borderRadius:N=>`${N.shape.borderRadius}px`,"&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Reset"}),t.jsxs(o.Stack,{direction:"row",spacing:1.25,children:[f&&t.jsx(o.Button,{onClick:()=>{f(C),b()},disabled:!he,variant:"contained",startIcon:t.jsx(T.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:N=>`${N.shape.borderRadius}px`,boxShadow:N=>se(N,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:N=>se(N,"hoverButton")},"&:active":{boxShadow:N=>se(N,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to current view"}),x&&pe&&t.jsx(o.Button,{onClick:()=>{x(C),b()},disabled:!he||!pe,variant:"contained",startIcon:t.jsx(T.GridView,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:N=>`${N.shape.borderRadius}px`,boxShadow:N=>se(N,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:N=>se(N,"hoverButton")},"&:active":{boxShadow:N=>se(N,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to all views"})]})]}),z&&t.jsx(o.Box,{onClick:()=>S(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:N=>D(N.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:N=>N.zIndex.tooltip},children:t.jsxs(o.Paper,{onClick:N=>N.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:N=>oo(N),bgcolor:"background.paper",boxShadow:N=>se(N,"menu")},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:()=>S(!1),variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,borderRadius:N=>`${N.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:X,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:N=>`${N.shape.borderRadius}px`,boxShadow:N=>se(N,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:N=>se(N,"hoverButton")},"&:active":{boxShadow:N=>se(N,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function $u({schema:e,grouping:r,onApply:n,onClose:i}){var L;const[s,l]=p.useState(r||{enabled:!1,levels:[],collapsedGroups:[]}),[d,c]=p.useState(""),[u,m]=p.useState(null),f=p.useMemo(()=>wa(e),[e]),x=p.useMemo(()=>f.filter(a=>!s.levels.some((_,F)=>_.column===a.name&&F!==u)),[f,s.levels,u]),v=Sr(),b=s.levels.length<v.grouping.maxLevels&&x.length>0,z=p.useCallback(a=>{!b||!a||(l({...s,levels:[...s.levels,{column:a}],enabled:!0}),c(""),setTimeout(()=>{var _;return(_=document.activeElement)==null?void 0:_.blur()},0))},[b,s]),S=p.useCallback(a=>{const _=s.levels.filter((F,X)=>X!==a);if(_.length===0){n(null),i();return}l({...s,levels:_,enabled:_.length>0})},[s,n,i]),y=p.useCallback(a=>{m(a),c(s.levels[a].column)},[s.levels]),w=p.useCallback(()=>{if(u===null||!d)return;const a=[...s.levels];a[u]={column:d},l({...s,levels:a}),m(null),c("")},[u,d,s]),C=p.useCallback(()=>{m(null),c("")},[]),E=p.useCallback((a,_)=>{const F=_==="up"?a-1:a+1;if(F<0||F>=s.levels.length)return;const X=[...s.levels],[re]=X.splice(a,1);X.splice(F,0,re),l({...s,levels:X})},[s]),g=p.useCallback(()=>{n(null),i()},[n,i]),k=p.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:a=>D(a.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:a=>a.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:a=>a.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:a=>Ne(a),bgcolor:"background.paper",outline:"none",boxShadow:a=>se(a,"menu"),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,borderBottom:"1px solid divider",flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),t.jsx(Cr,{content:jr.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(T.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:a=>D(a.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:a=>D(a.palette.text.primary,.3)}}},children:t.jsxs(o.Stack,{spacing:2.5,children:[u===null&&t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",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:d,onChange:a=>z(a.target.value),disabled:!b,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..."}),x.map(a=>t.jsxs(o.MenuItem,{value:a.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:_=>qe(_),"&:hover":{bgcolor:_=>D(_.palette.primary.main,.2)}}},children:[Qe(a.name)," (",a.type.toUpperCase(),")"]},a.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:"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),f.length===0&&t.jsx(o.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),u!==null&&t.jsxs(o.Alert,{severity:"warning",sx:{borderRadius:"8px",border:a=>`1px solid ${D(a.palette.warning.main,.5)}`,bgcolor:a=>D(a.palette.warning.main,.12),"& .MuiAlert-icon":{color:"warning.main"}},children:[t.jsxs(o.Typography,{variant:"body2",sx:{fontWeight:500,mb:1.5,fontSize:"0.875rem",color:"text.primary"},children:["Edit Group Level ",u+1]}),t.jsx(o.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:t.jsxs(o.Select,{value:d,onChange:a=>c(a.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[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:a=>qe(a)}},children:[s.levels[u].column," (",(L=e.find(a=>a.name===s.levels[u].column))==null?void 0:L.type.toUpperCase(),")"]}),x.filter(a=>a.name!==s.levels[u].column).map(a=>t.jsxs(o.MenuItem,{value:a.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:_=>qe(_)}},children:[Qe(a.name)," (",a.type.toUpperCase(),")"]},a.name))]})}),t.jsxs(o.Stack,{direction:"row",spacing:1.5,children:[t.jsx(o.Button,{onClick:w,disabled:!d,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:a=>se(a,"pressedButton")}},children:"Save"}),t.jsx(o.Button,{onClick:C,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&&u===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:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),t.jsx(o.Button,{onClick:g,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((a,_)=>{const F=e.find(X=>X.name===a.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:X=>se(X,"pressedButtonLight")}},children:[t.jsx(o.Chip,{label:`L${_+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:X=>`0 1px 2px 0 ${D(X.palette.primary.main,.3)}`}}),t.jsxs(o.Box,{sx:{flex:1},children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:a.column}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:F==null?void 0:F.type.toUpperCase()})]}),t.jsxs(o.Stack,{direction:"row",spacing:.5,children:[t.jsx(o.IconButton,{size:"small",onClick:()=>E(_,"up"),disabled:_===0,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:t.jsx(T.KeyboardArrowUp,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>E(_,"down"),disabled:_===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:t.jsx(T.KeyboardArrowDown,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>y(_),sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover",color:"primary.main"}},children:t.jsx(T.Edit,{sx:{fontSize:18}})}),t.jsx(o.IconButton,{size:"small",onClick:()=>S(_),sx:{color:"text.secondary","&:hover":{bgcolor:X=>D(X.palette.error.main,.08),color:"error.main"}},children:t.jsx(T.Delete,{sx:{fontSize:18}})})]})]},_)})})]})]})}),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:a=>`${a.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:k,variant:"contained",disabled:s.levels.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:a=>`${a.shape.borderRadius}px`,boxShadow:a=>se(a,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:a=>se(a,"hoverButton")},"&:active":{boxShadow:a=>se(a,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}function Au({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(T.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:t.jsx(T.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[t.jsx(o.Typography,{variant:"subtitle2",sx:{fontWeight:600,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(T.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),t.jsx(o.Button,{onClick:e,variant:"contained",color:"warning",startIcon:t.jsx(T.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const Li=[{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 _u(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 Mu(e,r){if(r===null)return[];const n=Date.now()-r;return e.filter(i=>new Date(i.timestamp).getTime()<n)}function Ru({auditHistory:e,onClose:r,onClearAuditHistory:n}){var z,S,y,w;const i=Lt(),s=i.palette,[l,d]=p.useState("1h"),[c,u]=p.useState(!1),m=[...e].sort((C,E)=>new Date(E.timestamp).getTime()-new Date(C.timestamp).getTime()),f=Li.find(C=>C.key===l),x=_u(e,f.ms),v=()=>u(!0),b=()=>{n&&(n(Mu(e,f.ms)),u(!1))};return t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{onClick:r,sx:{position:"fixed",inset:0,bgcolor:D(((z=s.common)==null?void 0:z.black)??"#000",.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:C=>C.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:Ne(i),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${D(((S=s.common)==null?void 0:S.black)??"#000",.14)}, 0 2px 8px ${D(((y=s.common)==null?void 0:y.black)??"#000",.08)}`,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,borderBottom:"1px solid",borderColor:"divider"},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:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),t.jsx(Cr,{content:jr.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),t.jsxs(o.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[m.length," event",m.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:l,onChange:C=>d(C.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:Li.map(C=>t.jsx(o.MenuItem,{value:C.key,sx:{fontSize:"0.8125rem"},children:C.label},C.key))}),t.jsx(o.Button,{size:"small",variant:"outlined",color:"error",startIcon:t.jsx(T.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(T.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:m.length===0?t.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[t.jsx(T.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),t.jsx(o.Typography,{sx:{fontSize:"0.9375rem",color:"text.secondary",fontWeight:500},children:"No audit events yet"}),t.jsx(o.Typography,{sx:{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:m.map(C=>{const E=Xd(i,C.feature),{summary:g,detail:k}=Ua(C);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:qa(C.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:D(E,.1),color:E,border:`1px solid ${D(E,.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:g}),k&&t.jsx(o.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:k}),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(T.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:Ja(C.timestamp)})]}),C.user&&t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[t.jsx(T.Person,{sx:{fontSize:11,color:"text.disabled"}}),t.jsx(o.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:C.user})]})]})]})]},C.id)})})})]})}),t.jsxs(o.Dialog,{open:c,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:oo(i),boxShadow:`0 8px 32px ${D(((w=s.common)==null?void 0:w.black)??"#000",.14)}`}},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(T.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),t.jsx(o.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),t.jsxs(o.Typography,{sx:{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:[x," audit record",x!==1?"s":""]})," ",f.key==="all"?"from all time":`from the ${f.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:()=>u(!1),variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),t.jsxs(o.Button,{onClick:b,variant:"contained",color:"error",startIcon:t.jsx(T.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{fontSize:"0.8125rem",borderRadius:"7px",px:2},children:["Clear ",x," Record",x!==1?"s":""]})]})]})]})}function Wu({onSave:e,onClose:r}){const[n,i]=p.useState(""),[s,l]=p.useState(""),[d,c]=p.useState(""),[u,m]=p.useState([]),[f,x]=p.useState(""),[v,b]=p.useState(""),z=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),S=()=>{const k=d.trim();if(k){if(!z(k)){b("Please enter a valid email address");return}if(u.includes(k)){b("This email is already added");return}m([...u,k]),c(""),b("")}},y=k=>{m(u.filter(L=>L!==k))},w=k=>{k.key==="Enter"&&(k.preventDefault(),S())},C=()=>{if(!n.trim()){x("Preset name is required");return}e(n.trim(),s.trim(),u.length>0?u:void 0)},E=k=>{i(k),f&&x("")},g=k=>{c(k),v&&b("")};return t.jsx(o.Box,{onClick:r,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:k=>D(k.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:k=>k.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:k=>k.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:k=>Ne(k),bgcolor:"background.paper",outline:"none",boxShadow:k=>se(k,"menu"),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,borderBottom:"1px solid divider",flexShrink:0},children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,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(T.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:k=>D(k.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:k=>D(k.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(T.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:k=>`1px solid ${D(k.palette.primary.main,.3)}`,bgcolor:k=>qe(k),"& .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:"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:"0.6875rem",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:k=>E(k.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!f,helperText:f,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:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),t.jsx(o.TextField,{value:s,onChange:k=>l(k.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:"0.6875rem",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:d,onChange:k=>g(k.target.value),onKeyPress:w,placeholder:"Enter email address",error:!!v,helperText:v,fullWidth:!0,size:"small",InputProps:{startAdornment:t.jsx(T.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:S,variant:"outlined",startIcon:t.jsx(T.Add,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",px:2,py:1.25,minHeight:40,borderRadius:k=>`${k.shape.borderRadius}px`,flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:"Add"})]}),u.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:u.map(k=>t.jsx(o.Chip,{label:k,onDelete:()=>y(k),deleteIcon:t.jsx(T.Delete,{sx:{fontSize:16}}),sx:{bgcolor:L=>qe(L),color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},k))}),t.jsx(o.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:u.length>0?`An email with the shareable link will be sent to ${u.length} recipient${u.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:k=>`${k.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),t.jsx(o.Button,{onClick:C,variant:"contained",startIcon:t.jsx(T.Share,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:k=>`${k.shape.borderRadius}px`,boxShadow:k=>se(k,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:k=>se(k,"hoverButton")},"&:active":{boxShadow:k=>se(k,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function Pu({presetName:e,onClear:r}){return t.jsx(o.Chip,{icon:t.jsx(T.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(T.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 Nu({presets:e,reportId:r,onOpenPreset:n,onDeletePreset:i,onClose:s}){const l=d=>new Date(d).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:d=>D(d.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:d=>d.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:d=>d.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:d=>Ne(d),bgcolor:"background.paper",outline:"none",boxShadow:d=>se(d,"menu"),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,borderBottom:"1px solid divider",flexShrink:0},children:[t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),t.jsxs(o.Typography,{variant:"caption",sx:{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(T.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:d=>D(d.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(T.Share,{sx:{fontSize:48,color:"divider",mb:2}}),t.jsx(o.Typography,{variant:"body1",sx:{fontSize:"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),t.jsx(o.Typography,{variant:"body2",sx:{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(d=>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:c=>se(c,"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:"0.9375rem",fontWeight:500,color:"text.primary",mb:.5},children:d.name}),d.description&&t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:d.description})]})}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[t.jsx(o.Chip,{label:`Created ${l(d.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 ${d.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(d.id,d.name),variant:"outlined",size:"small",startIcon:t.jsx(T.Delete,{sx:{fontSize:16}}),sx:{fontSize:"0.8125rem",color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:c=>`${c.shape.borderRadius}px`,"&:hover":{borderColor:"error.main",bgcolor:c=>D(c.palette.error.main,.04)}},children:"Delete"})})]},d.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:d=>`${d.shape.borderRadius}px`,boxShadow:d=>se(d,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:d=>se(d,"hoverButton")},"&:active":{boxShadow:d=>se(d,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const zs={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},Lu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],Fu=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function Vu(e,r){const n=[];for(const i of e){if(i.type!=="string")continue;const s=Fu.some(c=>c.test(i.name));let l=!1;const d=r.slice(0,10).map(c=>c[i.name]).filter(c=>typeof c=="string"&&c.length>0);d.length>0&&(l=d.filter(u=>Lu.some(m=>m.test(u))).length/d.length>.6),(s||l)&&n.push(i.name)}return n}function Fn(e,r){if(e.length===0||r.length===0)return 0;const n=e.slice(0,Math.min(50,e.length)),s=r.map(d=>{const c=n.map(m=>String(m[d]??"")).filter(m=>m.length>0);if(c.length===0)return 5;const u=c.reduce((m,f)=>m+f.length,0);return Math.ceil(u/c.length)+1}).reduce((d,c)=>d+c,0)+1;return r.reduce((d,c)=>d+c.length+1,0)+s*e.length}function Hu(e,r){const n=Fn(e,r);return Math.ceil(n*3.5)}function Uu(e,r){const n=Fn(e,r);return Math.ceil(n*.7)}function Gu(e,r,n){switch(e){case"csv":return Fn(r,n);case"excel":return Uu(r,n);case"json":return Hu(r,n)}}function Fi(e,r){return Math.ceil(e/r)}function Yu(e,r,n,i,s=zs){const l=[],d=Gu(e,r,n),c=r.length;if(c>s.maxRowsHard){const f=Fi(c,s.maxRows);l.push({type:"row_count",severity:"error",message:`Export blocked: ${c.toLocaleString()} rows exceeds the maximum of ${s.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${f} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:c,limit:s.maxRowsHard})}else if(c>s.maxRows){const f=Fi(c,s.maxRows);l.push({type:"row_count",severity:"warning",message:`Large export: ${c.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${f} smaller export${f>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:c,limit:s.maxRows})}if(d>s.maxFileSizeHardBytes?l.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Xr(d)} exceeds the ${Xr(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:d,limit:s.maxFileSizeHardBytes}):d>s.maxFileSizeBytes&&l.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Xr(d)}`,detail:`This exceeds the recommended ${Xr(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:s.maxFileSizeBytes}),e!=="excel"){const f=Vu(i.filter(x=>n.includes(x.name)),r);if(f.length>0){const x=f.length>s.maxImageColumns;l.push({type:"image_columns",severity:x?"error":"warning",message:`Image column${f.length>1?"s":""} detected: ${f.map(v=>`"${v.replace(/_/g," ")}"`).join(", ")}`,detail:x?`Exporting ${f.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:f.length,limit:s.maxImageColumns})}}const u=l.some(f=>f.severity==="error"),m=l.some(f=>f.severity==="warning");return{violations:l,hasBlockingViolation:u,hasWarning:m,estimatedBytes:d}}function Xr(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function qu({violation:e}){const n=Lt().palette,i=e.severity==="error",s=i?n.error.main:n.warning.main,l=D(i?n.error.main:n.warning.main,.06),d=i?D(n.error.main,.25):D(n.warning.main,.3),c=i?T.ErrorOutline:T.WarningAmberOutlined;return t.jsxs(o.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:l,border:"1px solid",borderColor:d},children:[t.jsx(c,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:e.message}),e.detail&&t.jsx(o.Typography,{sx:{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(T.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),t.jsxs(o.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",e.suggestedBatches," exports"]})]})]})]})}function Ju({totalRows:e,visibleRows:r,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:l,sampleRows:d=[],allRows:c=[],processedRows:u=[],onExport:m,onClose:f}){var V,W,Q;const x=Lt(),v=x.palette,b=Sr(),[z,S]=p.useState(b.export.allowedFormats[0]||"csv"),[y,w]=p.useState("visible"),[C,E]=p.useState("visible"),g=y==="visible"?r:e,k=C==="visible"?i:s,L=p.useMemo(()=>y==="visible"?u.length>0?u:new Array(r):c.length>0?c:new Array(e),[y,r,e,u,c]),a=p.useMemo(()=>C==="all"?l.map(Z=>Z.name):l.map(Z=>Z.name).slice(0,i),[C,l,i]),_=p.useMemo(()=>Yu(z,L,a,l,zs),[z,L,a,l]),F=()=>{_.hasBlockingViolation||(m({format:z,scope:y,columnScope:C}),f())},X={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},re={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},h={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return t.jsx(o.Box,{onClick:f,sx:{position:"fixed",inset:0,bgcolor:D(((V=v.common)==null?void 0:V.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:x.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:t.jsxs(o.Paper,{onClick:Z=>Z.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:Ne(x),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${D(((W=v.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${D(((Q=v.common)==null?void 0:Q.black)??"#000",.08)}`,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:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),t.jsx(Cr,{content:jr.export,isDev:process.env.NODE_ENV==="development"})]}),t.jsx(o.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:t.jsx(T.Close,{sx:{fontSize:18}})})]}),t.jsxs(o.Box,{sx:{flex:1,overflowY:"auto",px:3,py:2.5,display:"flex",flexDirection:"column",gap:2.5,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D(v.text.primary,.15),borderRadius:3}},children:[_.violations.length>0&&t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:_.violations.map((Z,pe)=>t.jsx(qu,{violation:Z},pe))}),t.jsxs(o.FormControl,{component:"fieldset",children:[t.jsx(o.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Format"}),t.jsxs(o.RadioGroup,{value:z,onChange:Z=>S(Z.target.value),children:[b.export.allowedFormats.includes("csv")&&t.jsx(o.FormControlLabel,{value:"csv",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(T.TableChart,{sx:{fontSize:16,color:"text.secondary"}}),t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),t.jsx(o.Tooltip,{title:"Comma-separated values, compatible with Excel",arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:{...re,mb:.5}}),b.export.allowedFormats.includes("excel")&&t.jsx(o.FormControlLabel,{value:"excel",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(T.TableChart,{sx:{fontSize:16,color:"success.main"}}),t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),t.jsx(o.Tooltip,{title:"Native Excel format with formatting support",arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:{...re,mb:.5}}),b.export.allowedFormats.includes("json")&&t.jsx(o.FormControlLabel,{value:"json",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(T.DataObject,{sx:{fontSize:16,color:"text.secondary"}}),t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"JSON"}),t.jsx(o.Tooltip,{title:"Structured data with metadata and filters",arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:re})]})]}),t.jsxs(o.FormControl,{component:"fieldset",children:[t.jsx(o.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Rows"}),t.jsxs(o.RadioGroup,{value:y,onChange:Z=>w(Z.target.value),children:[t.jsx(o.FormControlLabel,{value:"visible",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible rows"}),t.jsx(o.Tooltip,{title:`Export ${r.toLocaleString()} rows (filtered and searched)`,arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:{...re,mb:.5}}),t.jsx(o.FormControlLabel,{value:"all",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All rows"}),t.jsx(o.Tooltip,{title:`Export ${e.toLocaleString()} rows (complete original dataset)`,arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:re})]})]}),t.jsxs(o.FormControl,{component:"fieldset",children:[t.jsx(o.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Columns"}),t.jsxs(o.RadioGroup,{value:C,onChange:Z=>E(Z.target.value),children:[t.jsx(o.FormControlLabel,{value:"visible",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible columns only"}),t.jsx(o.Tooltip,{title:`Export ${i} visible column${i!==1?"s":""}`,arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:{...re,mb:.5}}),t.jsx(o.FormControlLabel,{value:"all",control:t.jsx(o.Radio,{size:"small",sx:h}),label:t.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),t.jsx(o.Tooltip,{title:`Export all ${s} columns (including hidden)`,arrow:!0,children:t.jsx(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),sx:re})]})]}),t.jsxs(o.Box,{children:[t.jsx(o.Divider,{sx:{mb:2}}),t.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[{label:"Format",value:X[z]},{label:"Rows to export",value:g.toLocaleString()},{label:"Columns to export",value:String(k)},{label:"Estimated file size",value:Xr(_.estimatedBytes),highlight:_.hasBlockingViolation?"error.main":_.hasWarning?"warning.main":void 0}].map(({label:Z,value:pe,highlight:he})=>t.jsxs(o.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx(o.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary"},children:Z}),t.jsx(o.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:he??"text.primary"},children:pe})]},Z))})]})]}),t.jsxs(o.Box,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:D(v.text.primary,.015)},children:[_.hasBlockingViolation&&t.jsxs(o.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[t.jsx(T.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),t.jsx(o.Typography,{sx:{fontSize:"0.75rem",color:"error.main",fontWeight:500},children:"Reduce rows or columns to enable download"})]}),t.jsx(o.Button,{onClick:f,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),t.jsxs(o.Button,{onClick:F,disabled:_.hasBlockingViolation,variant:"contained",startIcon:t.jsx(T.Download,{sx:{fontSize:16}}),sx:{fontSize:"0.875rem",px:2.5,borderRadius:"8px"},children:["Download ",X[z]]})]})]})})}function Ku({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(T.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:"warning.main"},children:t.jsx(T.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 Xu({error:e,onDismiss:r,autoDismiss:n=!0,autoDismissDelay:i=5e3}){p.useEffect(()=>{if(n){const c=setTimeout(()=>{r()},i);return()=>clearTimeout(c)}},[n,i,r]);const l=(()=>{switch(e.type){case"system":return{severity:"error",icon:t.jsx(T.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:t.jsx(T.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:t.jsx(T.InfoOutlined,{sx:{fontSize:20}})}}})(),d=sl(e);return t.jsx(o.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:t.jsxs(o.Alert,{severity:l.severity,icon:l.icon,action:t.jsx(o.IconButton,{size:"small",onClick:r,sx:{color:`${l.severity}.main`},children:t.jsx(T.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${l.severity}.main`,boxShadow:3},children:[t.jsxs(o.AlertTitle,{sx:{fontWeight:600},children:[e.context.charAt(0).toUpperCase()+e.context.slice(1)," Error"]}),t.jsx(o.Box,{sx:{fontSize:"body2.fontSize"},children:d}),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 Qu extends p.Component{constructor(n){super(n);Kn(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){Et.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(T.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:600},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(T.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Zu({feature:e}){const[r,n]=p.useState(!0);return p.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(T.Warning,{sx:{fontSize:20}}),action:t.jsx(o.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:t.jsx(T.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(Qu,{context:r,onError:i=>{n&&n(i)},fallback:t.jsx(Zu,{feature:r}),children:e})}const ep=[{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"}],tp=[{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"}];function Yr({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 rp({open:e,onClose:r,config:n,onApply:i}){const[s,l]=p.useState(0),[d,c]=p.useState(n),u=()=>c(n),m=()=>c(Ke),f=()=>{i(d),r()},x={sort:y=>c(w=>({...w,sort:{...w.sort,...y}})),filter:y=>c(w=>({...w,filter:{...w.filter,...y}})),columns:y=>c(w=>({...w,columns:{...w.columns,...y}})),grouping:y=>c(w=>({...w,grouping:{...w.grouping,...y}})),export:y=>c(w=>({...w,export:{...w.export,...y}}))},v=y=>{const w=d.filter.allowedOperators,C=w.includes(y)?w.filter(E=>E!==y):[...w,y];C.length!==0&&x.filter({allowedOperators:C})},b=y=>{const w=d.export.allowedFormats,C=w.includes(y)?w.filter(E=>E!==y):[...w,y];C.length!==0&&x.export({allowedFormats:C})},z=[{label:"Sort",icon:t.jsx(T.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:t.jsx(T.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:t.jsx(T.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:t.jsx(T.Layers,{sx:{fontSize:17}})},{label:"Export",icon:t.jsx(T.Download,{sx:{fontSize:17}})}],S=y=>JSON.stringify(d[y])===JSON.stringify(Ke[y]);return t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:y=>Ne(y),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:y=>`0 8px 32px ${D(y.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:y=>D(y.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(T.Close,{sx:{fontSize:20}})})]}),t.jsx(o.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:t.jsx(o.Tabs,{value:s,onChange:(y,w)=>l(w),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:z.map((y,w)=>t.jsx(o.Tab,{label:y.label,icon:y.icon,iconPosition:"start"},w))})}),t.jsxs(o.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[t.jsxs(Yr,{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"}),!S("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:d.sort.maxLevels,onChange:(y,w)=>x.sort({maxLevels:w}),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(Yr,{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"}),!S("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:d.filter.maxConditions,onChange:(y,w)=>x.filter({maxConditions:w}),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(y=>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:y}),t.jsx(o.FormGroup,{row:!0,sx:{gap:.5},children:ep.filter(w=>w.group===y).map(w=>t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(w.value),onChange:()=>v(w.value)}),label:t.jsx(o.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:w.label}),sx:{mr:1.5}},w.value))})]},y))]})]}),t.jsxs(Yr,{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"}),!S("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:d.columns.maxVisible,onChange:(y,w)=>x.columns({maxVisible:w}),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:d.columns.minColumnWidth,onChange:(y,w)=>x.columns({minColumnWidth:w}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:y=>`${y}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:d.columns.maxColumnWidth,onChange:(y,w)=>x.columns({maxColumnWidth:w}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:y=>`${y}px`})]})]})]})]}),t.jsxs(Yr,{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"}),!S("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(y=>t.jsxs(o.Box,{onClick:()=>x.grouping({maxLevels:y}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===y?"primary.main":"divider",bgcolor:d.grouping.maxLevels===y?w=>D(w.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:w=>D(w.palette.primary.main,.04)}},children:[t.jsx(o.Typography,{variant:"h5",sx:{fontWeight:700,color:d.grouping.maxLevels===y?"primary.main":"text.secondary"},children:y}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][y-1]})]},y))}),t.jsxs(o.FormGroup,{row:!0,sx:{gap:2},children:[t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:d.grouping.allowNested,onChange:y=>x.grouping({allowNested:y.target.checked})}),label:t.jsx(o.Typography,{variant:"body2",children:"Allow nested groups"})}),t.jsx(o.FormControlLabel,{control:t.jsx(o.Checkbox,{checked:d.grouping.allowCollapse,onChange:y=>x.grouping({allowCollapse:y.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(Yr,{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"}),!S("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:tp.map(y=>t.jsxs(o.Box,{onClick:()=>b(y.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:d.export.allowedFormats.includes(y.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(y.value)?w=>D(w.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[t.jsx(o.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(y.value),onChange:()=>b(y.value),onClick:w=>w.stopPropagation()}),t.jsxs(o.Box,{children:[t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500},children:y.label}),t.jsx(o.Typography,{variant:"caption",color:"text.secondary",children:y.desc})]})]},y.value))})]})})]}),t.jsxs(o.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:y=>D(y.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[t.jsx(o.Button,{startIcon:t.jsx(T.RestartAlt,{sx:{fontSize:18}}),onClick:m,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:y=>D(y.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:f,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const op=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],np={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 jo(e,r,n,i,s=new Date){const[l,d]=r.split(":").map(Number),c=new Date(s);if(c.setSeconds(0,0),c.setHours(l,d,0,0),e==="daily")return c<=s&&c.setDate(c.getDate()+1),c.toISOString();if(e==="weekly"){const u=n??1,m=c.getDay();let f=u-m;return f<0&&(f+=7),f===0&&c<=s&&(f=7),c.setDate(c.getDate()+f),c.toISOString()}if(e==="monthly"){const u=Math.min(i??1,28);return c.setDate(u),c<=s&&(c.setMonth(c.getMonth()+1),c.setDate(u)),c.toISOString()}return c.toISOString()}function ip(e){const r=Es(e.time);return e.frequency==="daily"?`Daily at ${r}`:e.frequency==="weekly"?`Every ${op[e.dayOfWeek??1]} at ${r}`:e.frequency==="monthly"?`Monthly on the ${np[e.dayOfMonth??1]??`${e.dayOfMonth}th`} at ${r}`:r}function Es(e){const[r,n]=e.split(":").map(Number),i=r>=12?"PM":"AM";return`${r%12||12}:${String(n).padStart(2,"0")} ${i}`}function sp(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),l=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${l}m`:l>0?`in ${l}m`:"in less than a minute"}function ap(e){const r=new Date(e),n=new Date,i=r.toDateString()===n.toDateString(),s=Es(`${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 Bs(e){return`urm_schedules_${e}`}function Ds(e){try{const r=localStorage.getItem(Bs(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 Os(e,r){try{localStorage.setItem(Bs(e),JSON.stringify(r))}catch{}}const lp=[{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"}],cp=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,$s={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},br={"& .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 dp({initial:e=$s,isEditing:r=!1,onSave:n,onBack:i}){const[s,l]=p.useState(e),[d,c]=p.useState(!1),[u,m]=p.useState(!1),f=(b,z)=>l(S=>({...S,[b]:z})),x=s.email.trim().length>0&&!cp.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)&&!x;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:b=>D(b.palette.text.primary,.06)}},children:t.jsx(T.ArrowBack,{sx:{fontSize:18}})}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:600},children:r?"Edit schedule":"New schedule"})]}),t.jsx(o.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:b=>{f("name",b.target.value),d&&b.target.value.trim()&&c(!1)},onBlur:()=>c(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!s.name.trim(),helperText:d&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:br}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:br,children:[t.jsx(o.InputLabel,{children:"Frequency"}),t.jsxs(o.Select,{value:s.frequency,label:"Frequency",onChange:b=>f("frequency",b.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:br,children:[t.jsx(o.InputLabel,{children:"Day of week"}),t.jsx(o.Select,{value:s.dayOfWeek,label:"Day of week",onChange:b=>f("dayOfWeek",Number(b.target.value)),children:lp.map(b=>t.jsx(o.MenuItem,{value:b.value,children:b.label},b.value))})]}),s.frequency==="monthly"&&t.jsx(o.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:b=>f("dayOfMonth",Number(b.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:br}),t.jsx(o.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:b=>f("time",b.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:br}),t.jsxs(o.FormControl,{size:"small",fullWidth:!0,sx:br,children:[t.jsx(o.InputLabel,{children:"Export format"}),t.jsxs(o.Select,{value:s.format,label:"Export format",onChange:b=>f("format",b.target.value),children:[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:b=>f("scope",b.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:b=>f("email",b.target.value),onBlur:()=>m(!0),placeholder:"user@company.com",error:u&&x,helperText:u&&x?"Enter a valid email address":void 0,InputProps:{startAdornment:t.jsx(T.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:br}),t.jsxs(o.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[t.jsx(T.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:b=>D(b.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 up({scheduleName:e,onConfirm:r,onCancel:n}){return t.jsxs(o.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>oo(i),boxShadow:i=>{var s;return`0 8px 32px ${D(((s=i.palette.common)==null?void 0:s.black)??"#000",.14)}`}}},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(T.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),t.jsx(o.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),t.jsxs(o.Typography,{sx:{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 pp({schedule:e,tick:r,onToggle:n,onRunNow:i,onEdit:s,onDelete:l}){const d=e.isActive;return t.jsxs(o.Box,{sx:{border:"1px solid",borderColor:d?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:d?c=>D(c.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:d?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),t.jsx(o.Chip,{label:d?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:d?c=>D(c.palette.success.main,.1):c=>D(c.palette.text.primary,.06),color:d?"success.dark":"text.secondary"}})]}),t.jsx(o.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:ip(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:c=>D(c.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:c=>D(c.palette.text.primary,.06),color:"text.secondary"}}),e.email&&t.jsx(o.Chip,{icon:t.jsx(T.Email,{sx:{fontSize:11}}),label:e.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:c=>D(c.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:[d&&t.jsxs(o.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",sp(e.nextRunAt)]}),e.lastRunAt?t.jsxs(o.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",ap(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:c=>D(c.palette.primary.main,.08)}},children:t.jsx(T.Edit,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:d?"Pause":"Resume",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>n(e.id),sx:{color:d?"warning.main":"success.main","&:hover":{bgcolor:d?c=>D(c.palette.warning.main,.08):c=>D(c.palette.success.main,.08)}},children:d?t.jsx(T.Pause,{sx:{fontSize:15}}):t.jsx(T.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:c=>D(c.palette.primary.main,.08)}},children:t.jsx(T.Download,{sx:{fontSize:15}})})}),t.jsx(o.Tooltip,{title:"Delete",placement:"top",children:t.jsx(o.IconButton,{size:"small",onClick:()=>l(e.id),sx:{color:"error.main","&:hover":{bgcolor:c=>D(c.palette.error.main,.08)}},children:t.jsx(T.Delete,{sx:{fontSize:15}})})})]})]})]})}function xp({open:e,onClose:r,reportId:n,reportName:i,onRunNow:s}){const[l,d]=p.useState([]),[c,u]=p.useState({type:"list"}),[m,f]=p.useState(0),[x,v]=p.useState(null);p.useEffect(()=>{e&&(d(Ds(n)),u({type:"list"}))},[e,n]),p.useEffect(()=>{if(!e)return;const a=setInterval(()=>f(_=>_+1),3e4);return()=>clearInterval(a)},[e]);const b=p.useCallback(a=>{d(a),Os(n,a)},[n]),z=a=>{const _=jo(a.frequency,a.time,a.dayOfWeek,a.dayOfMonth),F={id:`sched-${Date.now()}`,reportId:n,name:a.name.trim(),frequency:a.frequency,dayOfWeek:a.frequency==="weekly"?a.dayOfWeek:void 0,dayOfMonth:a.frequency==="monthly"?a.dayOfMonth:void 0,time:a.time,format:a.format,scope:a.scope,email:a.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:_,runCount:0};b([...l,F]),u({type:"list"})},S=a=>{if(c.type!=="edit")return;const _=c.schedule,F=jo(a.frequency,a.time,a.dayOfWeek,a.dayOfMonth);b(l.map(X=>X.id===_.id?{..._,name:a.name.trim(),frequency:a.frequency,dayOfWeek:a.frequency==="weekly"?a.dayOfWeek:void 0,dayOfMonth:a.frequency==="monthly"?a.dayOfMonth:void 0,time:a.time,format:a.format,scope:a.scope,email:a.email.trim()||void 0,nextRunAt:F}:X)),u({type:"list"})},y=a=>{b(l.map(_=>{if(_.id!==a)return _;const F=_.isActive?_.nextRunAt:jo(_.frequency,_.time,_.dayOfWeek,_.dayOfMonth);return{..._,isActive:!_.isActive,nextRunAt:F}}))},w=a=>{s(a);const _=new Date().toISOString();b(l.map(F=>F.id===a.id?{...F,lastRunAt:_,runCount:F.runCount+1}:F))},C=a=>{const _=l.find(F=>F.id===a)??null;v(_)},E=()=>{x&&(b(l.filter(a=>a.id!==x.id)),v(null))},g=a=>({name:a.name,frequency:a.frequency,dayOfWeek:a.dayOfWeek??1,dayOfMonth:a.dayOfMonth??1,time:a.time,format:a.format,scope:a.scope,email:a.email??""}),k=c.type!=="list",L=l.filter(a=>a.isActive).length;return t.jsxs(t.Fragment,{children:[t.jsxs(o.Dialog,{open:e,onClose:r,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:k,PaperProps:{sx:{borderRadius:a=>Ne(a),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[t.jsxs(o.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},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:a=>D(a.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(T.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:600,lineHeight:1},children:"Scheduled Reports"}),t.jsx(Cr,{content:jr.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:a=>D(a.palette.text.primary,.06)}},children:t.jsx(T.Close,{sx:{fontSize:18}})})]}),t.jsxs(o.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[k&&t.jsx(dp,{initial:c.type==="edit"?g(c.schedule):$s,isEditing:c.type==="edit",onSave:c.type==="edit"?S:z,onBack:()=>u({type:"list"})}),c.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:l.length===0?"No schedules yet":`${L} of ${l.length} active`}),t.jsx(o.Button,{startIcon:t.jsx(T.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",onClick:()=>u({type:"create"}),sx:{fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),l.length===0?t.jsxs(o.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[t.jsx(T.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),t.jsx(o.Typography,{variant:"body2",sx:{fontWeight:500,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:l.map(a=>t.jsx(pp,{schedule:a,tick:m,onToggle:y,onRunNow:w,onEdit:_=>u({type:"edit",schedule:_}),onDelete:C},a.id))})]})]}),c.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:a=>D(a.palette.warning.main,.06),border:"1px solid",borderColor:a=>D(a.palette.warning.main,.2)},children:[t.jsx(T.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:a=>D(a.palette.text.primary,.06)}},children:"Close"})]})]}),x&&t.jsx(up,{scheduleName:x.name,onConfirm:E,onCancel:()=>v(null)})]})}const mp=6e4;function fp({reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:l,columnVisibility:d,columnOrder:c,filters:u,sortStack:m,onFired:f}){const x=p.useRef({reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:l,columnVisibility:d,columnOrder:c,filters:u,sortStack:m,onFired:f});p.useEffect(()=>{x.current={reportId:e,reportName:r,uploadedData:n,processedData:i,schema:s,activeView:l,columnVisibility:d,columnOrder:c,filters:u,sortStack:m,onFired:f}});const v=p.useCallback(b=>{var a,_;const{reportName:z,uploadedData:S,processedData:y,schema:w,activeView:C,columnVisibility:E,columnOrder:g,filters:k,sortStack:L}=x.current;try{const F=b.scope==="all"?S:y,X=wo(F,w,k,L,C,E,g),re=`${b.name}_scheduled`;switch(b.format){case"csv":ko(X,re,{scope:b.scope});break;case"excel":To(X,re,{scope:b.scope});break;case"json":Io(X,re,{scope:b.scope});break}if(b.email){const h=encodeURIComponent(`Scheduled Report: ${b.name}`),V=encodeURIComponent(`Your scheduled report "${b.name}" has been generated.
|
|
90
90
|
|
|
91
|
-
Report: ${
|
|
91
|
+
Report: ${z}
|
|
92
92
|
Format: ${b.format.toUpperCase()}
|
|
93
93
|
Generated: ${new Date().toLocaleString()}
|
|
94
94
|
|
|
95
|
-
The file has been downloaded to your device.`);window.open(`mailto:${b.email}?subject=${y}&body=${M}`,"_blank")}(R=(I=h.current).onFired)==null||R.call(I,b)}catch(G){lr.error("urm:scheduler",`Export failed for schedule: ${b.name}`,G)}},[]);u.useEffect(()=>{if(!t)return;const b=()=>{const{reportId:g}=h.current;if(!g)return;const j=as(g),k=new Date;let v=!1;const C=j.map(S=>{if(!S.isActive)return S;if(new Date(S.nextRunAt)<=k){x(S);const a=xo(S.frequency,S.time,S.dayOfWeek,S.dayOfMonth,k);return v=!0,{...S,lastRunAt:k.toISOString(),nextRunAt:a,runCount:S.runCount+1}}return S});v&&ls(g,C)};b();const E=setInterval(b,Wu);return()=>clearInterval(E)},[t,x])}function ds({reportEngine:t}){var kt,Tt,nt,or,zt;const{activeReport:o,paginatedData:n,processedData:i,tableMetrics:s,tableEngine:d,activeView:c,isDirty:l,currentTableState:p,showFilterPanel:f,setShowFilterPanel:m,filterFocusColumn:h,handleAddFilter:x,handleUpdateFilter:b,handleRemoveFilter:E,handleClearAllFilters:g,handleReplaceFilters:j,handleOpenFilterForColumn:k,handleCloseFilterPanel:v,handleClearFiltersForColumn:C,showSortPanel:S,setShowSortPanel:w,handleSort:a,handleUpdateSortStack:I,handleSortAscending:R,handleSortDescending:G,showManageViews:q,setShowManageViews:ee,showCreateViewModal:y,setShowCreateViewModal:M,showEditViewModal:W,setShowEditViewModal:V,showDeleteConfirmation:X,setShowDeleteConfirmation:ue,editingView:ce,deletingView:F,handleSelectView:O,handleCreateView:H,handleUpdateCurrentView:re,handleSaveColumnConfigToCurrentView:U,handleSaveColumnConfigToAllViews:te,handleSaveAsNewView:se,handleRevertChanges:ne,handleToggleDefault:P,handleToggleFavorite:ie,handleSoftDelete:de,handleRestoreView:ae,handlePermanentDelete:ge,handleEditView:K,handleSaveEditView:Ee,handleConfirmDelete:Ue,handlePromoteToGlobal:it,showManageColumns:St,setShowManageColumns:et,handleUpdateColumnVisibility:xr,handleUpdateColumnOrder:jt,handleUpdateColumnWidth:mr,handleResetColumnLayout:st,showGroupPanel:qt,setShowGroupPanel:Me,handleGroup:at,handleToggleGroupCollapse:lt,searchQuery:tt,debouncedSearchQuery:Ve,searchHistory:At,handleSearchChange:Er,handleAddToSearchHistory:hr,handleToggleSearchFavourite:Jt,handleDeleteSearchHistory:Kt,selectedRowIds:fr,handleToggleRowSelection:gr,handleToggleAllRows:ct,handleRangeSelection:Xt,handleClearSelection:Ct,handleUpdateSelectionAfterDelete:dt,currentPage:Kr,pageSize:Dr,paginationEngine:Ke,handlePageChange:yr,handlePageSizeChange:Mt,isExporting:Te,showExportModal:Or,setShowExportModal:Rt,showDirtyExportWarning:ut,handleExport:N,handleExportWithConfig:rt,handleExportSelected:be,handleExportAnyway:Fe,handleSaveAndExport:Qt,handleCancelExport:_t,showAuditHistory:br,setShowAuditHistory:Wt,showCreatePreset:Pt,setShowCreatePreset:$r,showManagePresets:Zt,setShowManagePresets:ze,activePreset:Q,handleCreatePreset:fe,handleClearActivePreset:me,handleOpenPresetById:vr,handleDeletePresetById:Xe,isViewerRole:Lt,userRole:pt,featureLimitWarning:er,setFeatureLimitWarning:Sr,reportError:ot,setReportError:He,handleError:xt,updateReport:mt,showSnack:tr}=t,[Nt,jr]=u.useState(!1);Pu({reportId:o==null?void 0:o.id,reportName:(o==null?void 0:o.name)||"Report",uploadedData:(o==null?void 0:o.uploadedData)||[],processedData:i||[],schema:(o==null?void 0:o.schema)||[],activeView:c,columnVisibility:(o==null?void 0:o.columnVisibility)||((kt=c==null?void 0:c.snapshot)==null?void 0:kt.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((Tt=c==null?void 0:c.snapshot)==null?void 0:Tt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:le=>{tr(`Scheduled export "${le.name}" completed`,"success")}});const Ft=u.useCallback((le,ye)=>{if(!(o!=null&&o.uploadedData))return;const Re=[...o.uploadedData];Re[le]=ye,mt(o.id,{uploadedData:Re})},[o,mt]),rr=u.useCallback(le=>{if(!(o!=null&&o.uploadedData))return;const ye=o.uploadedData.indexOf(le);if(ye===-1)return;const Re=o.uploadedData.filter((Vt,Ht)=>Ht!==ye);mt(o.id,{uploadedData:Re}),dt(le)},[o,mt,dt]),Ar=u.useCallback((le,ye)=>{if(!(o!=null&&o.uploadedData))return;const Re=o.uploadedData.indexOf(ye),Vt=Re!==-1?Re+1:le+1,Ht=[...o.uploadedData];Ht.splice(Vt,0,{...ye}),mt(o.id,{uploadedData:Ht})},[o,mt]),wt=dr(),{handleDevConfigChange:ht}=jo(),[Cr,Le]=u.useState(!1);return u.useEffect(()=>{const le=ye=>{ye.ctrlKey&&ye.shiftKey&&ye.key==="D"&&(ye.preventDefault(),Le(!0))};return document.addEventListener("keydown",le),()=>document.removeEventListener("keydown",le)},[]),!o||!o.schemaLocked||!o.schema||!o.uploadedData||!o.views?null:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[er&&e.jsx(vu,{warning:er,onDismiss:()=>Sr(null)}),ot&&e.jsx(Su,{error:ot,onDismiss:()=>He(null)}),ut&&e.jsx(nu,{onExportAnyway:Fe,onSaveAndExport:Qt,onCancel:_t}),e.jsx(Jd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:l,isExporting:Te,columnVisibility:o.columnVisibility||(c==null?void 0:c.snapshot.columnVisibility),columnOrder:o.columnOrder||(c==null?void 0:c.snapshot.columnOrder),columnWidths:o.columnWidths||(c==null?void 0:c.snapshot.columnWidths),grouping:o.grouping,onSort:a,onSortAscending:R,onSortDescending:G,onOpenFilters:()=>m(!0),onOpenSort:()=>w(!0),onOpenFilterForColumn:k,onSelectView:O,onCreateView:()=>M(!0),onManageViews:()=>ee(!0),onUpdateCurrentView:re,onSaveAsNewView:se,onDiscardChanges:ne,onToggleDefault:P,onToggleFavorite:ie,onRestoreView:ae,onPermanentDelete:ge,onExport:N,onOpenColumns:()=>et(!0),onUpdateColumnWidth:mr,onUpdateColumnOrder:jt,onUpdateColumnVisibility:xr,onClearFiltersForColumn:C,onResetLayout:st,onOpenGroup:()=>Me(!0),onGroupByColumn:le=>{at({enabled:!0,levels:[{column:le}],collapsedGroups:[]})},onToggleGroupCollapse:lt,onOpenAuditHistory:()=>Wt(!0),onOpenScheduledReports:()=>jr(!0),searchQuery:tt,highlightQuery:Ve,searchHistory:At,onAddToSearchHistory:hr,onToggleSearchFavourite:Jt,onDeleteSearchHistory:Kt,selectedRowIds:fr,onSearchChange:Er,onToggleRowSelection:gr,onToggleAllRows:ct,onRangeSelection:Xt,onClearSelection:Ct,onExportSelected:be,currentPage:(Ke==null?void 0:Ke.currentPage)||Kr,pageSize:(Ke==null?void 0:Ke.pageSize)||Dr,onPageChange:yr,onPageSizeChange:Mt,totalRowsBeforePagination:(s==null?void 0:s.searchedRows)||i.length,isReadOnly:Lt,userRole:pt,reportName:o.name,onEditRow:Ft,onDeleteRow:rr,onDuplicateRow:Ar,showDevPanel:wt.display.showDevPanel,onOpenDevConfig:()=>Le(!0)})]}),f&&e.jsx(Pr,{feature:"Filters",onError:le=>{const ye=Et("ui","filters",le);xt(ye)},children:e.jsx(Kd,{schema:o.schema,filters:o.filters??[],onAddFilter:x,onUpdateFilter:b,onRemoveFilter:E,onClearAll:g,onReplaceFilters:j,onClose:v,focusColumn:h})}),S&&e.jsx(Pr,{feature:"Sorting",onError:le=>{const ye=Et("ui","sorting",le);xt(ye)},children:e.jsx(Qd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:I,onClose:()=>w(!1)})}),q&&e.jsx(Pr,{feature:"Views",onError:le=>{const ye=Et("ui","views",le);xt(ye)},children:e.jsx(Zd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:O,onCreateView:()=>{ee(!1),M(!0)},onEditView:K,onDeleteView:de,onRestoreView:ae,onPermanentDelete:ge,onPromoteToGlobal:it,isAdmin:((nt=wt.views)==null?void 0:nt.isAdmin)??!1,onClose:()=>ee(!1)})}),y&&p&&(()=>{var Re;const le=(o.views??[]).filter(Vt=>!Vt.isDeleted).length,ye=((Re=wt.views)==null?void 0:Re.maxViews)??10;return e.jsx(yi,{currentSnapshot:p,onSave:H,onClose:()=>M(!1),atViewLimit:le>=ye,maxViews:ye})})(),W&&ce&&e.jsx(yi,{currentSnapshot:ce.snapshot,onSave:Ee,onClose:()=>{V(!1)},isEditMode:!0,initialName:ce.name,initialDescription:ce.description,initialIsDefault:ce.isDefault}),X&&F&&e.jsx(eu,{viewName:F.name,onConfirm:Ue,onCancel:()=>{ue(!1)}}),St&&c&&e.jsx(ru,{schema:o.schema,columnVisibility:o.columnVisibility||c.snapshot.columnVisibility,columnOrder:o.columnOrder||c.snapshot.columnOrder,columnWidths:o.columnWidths||c.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:xr,onUpdateColumnOrder:jt,onUpdateColumnWidth:mr,onResetLayout:st,onSelectView:le=>{O(le)},onSaveToCurrentView:le=>{U(le),et(!1)},onSaveToAllViews:le=>{te(le),et(!1)},onClose:()=>et(!1)}),qt&&e.jsx(Pr,{feature:"Grouping",onError:le=>{const ye=Et("ui","grouping",le);xt(ye)},children:e.jsx(ou,{schema:o.schema,grouping:o.grouping||null,onApply:at,onClose:()=>Me(!1)})}),br&&e.jsx(au,{auditHistory:o.auditHistory||[],onClose:()=>Wt(!1)}),Pt&&e.jsx(lu,{onSave:fe,onClose:()=>$r(!1)}),Zt&&e.jsx(du,{presets:o.presets||[],reportId:o.id,onOpenPreset:vr,onDeletePreset:Xe,onClose:()=>ze(!1)}),Q&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(cu,{presetName:Q.name,onClear:me})}),Or&&e.jsx(Pr,{feature:"Export",onError:le=>{const ye=Et("ui","export",le);xt(ye)},children:e.jsx(bu,{totalRows:(s==null?void 0:s.totalRows)||((or=o.uploadedData)==null?void 0:or.length)||0,visibleRows:(s==null?void 0:s.searchedRows)||i.length,visibleColumnsCount:((zt=d==null?void 0:d.columnEngine)==null?void 0:zt.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(s==null?void 0:s.isGrouped)||!1,schema:o.schema,allRows:o.uploadedData||[],processedRows:i||[],onExport:rt,onClose:()=>{Rt(!1)}})}),o&&e.jsx(_u,{open:Nt,onClose:()=>jr(!1),reportId:o.id,reportName:o.name,onRunNow:le=>{const ye=le.scope==="all"?o.uploadedData||[]:i||[],Re=mo(ye,o.schema||[],o.filters||[],o.sortStack||[],c,o.columnVisibility,o.columnOrder);le.format==="csv"&&ho(Re,le.name),le.format==="excel"&&fo(Re,le.name),le.format==="json"&&go(Re,le.name),tr(`"${le.name}" exported successfully`,"success")}}),e.jsx(Tu,{open:Cr,onClose:()=>Le(!1),config:wt,onApply:ht})]})}const Lu={error:"err",warning:"warn",info:"info",success:"suc"};function us({open:t,message:o,severity:n,onClose:i,autoHideDurationMs:s}){var v,C;const d=r.useTheme(),c=d.tokens,l=(c==null?void 0:c.notifPosition)??"top-right",p=(c==null?void 0:c.notifStyle)??"toast",f=(c==null?void 0:c.notifAccent)??"severity",m=(c==null?void 0:c.notifAutoDismiss)??!0,h=(c==null?void 0:c.toastW)??252,x=l.startsWith("top")?"top":"bottom",b=l.endsWith("center")?"center":l.endsWith("left")?"left":"right",E=Lu[n],g=((v=c==null?void 0:c.status)==null?void 0:v[`${E}Soft`])??d.palette[n].light,j=((C=c==null?void 0:c.status)==null?void 0:C[`${E}Txt`])??d.palette[n].dark,k=f==="primary"?d.palette.primary.main:f==="mono"?d.palette.text.secondary:j;return e.jsx(r.Snackbar,{open:t,autoHideDuration:m?s??2e3:void 0,onClose:(S,w)=>{w!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:x,horizontal:b},children:e.jsx(r.Alert,{severity:n,icon:!1,onClose:m?void 0:i,sx:{width:h,alignItems:"flex-start",bgcolor:g,color:j,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 ${k}`:void 0,borderRadius:`${d.shape.borderRadius}px`},children:o})})}function ps({hasExternalData:t=!1}){const o=jo(),{reports:n,activeReportId:i,activeReport:s,uploadState:d,hasSchemaConflicts:c,isModalOpen:l,setIsModalOpen:p,setActiveReportId:f,createReport:m,handleFileUpload:h,handleUploadError:x,handleRetry:b,handleConfirm:E,snack:g,handleSnackClose:j,snackDurationMs:k}=o,v=t&&d==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(tl,{onCreateReport:()=>p(!0),reports:n,activeReportId:i,onReportClick:f}),e.jsx(r.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:v?e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[e.jsx(r.CircularProgress,{size:40,thickness:3}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{minWidth:260,textAlign:"center"},children:"Fetching API data — please wait..."})]}):n.length===0?e.jsx(ts,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):s?e.jsx(e.Fragment,{children:s.schemaLocked&&s.schema&&s.uploadedData&&s.views?e.jsx(ds,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:d==="preview"&&s.schema&&s.uploadedData?e.jsx(md,{schema:s.schema,onConfirm:E,hasConflicts:c}):s.uploadError?e.jsx(hd,{error:s.uploadError,onRetry:b}):e.jsx(xd,{onFileUpload:h,onError:x,isUploading:d==="uploading"})})}):null}),!t&&e.jsx(pd,{isOpen:l,onClose:()=>p(!1),onCreate:m}),e.jsx(us,{open:g.open,message:g.message,severity:g.severity,onClose:j,autoHideDurationMs:k})]})}function Nu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(dn,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(ps,{hasExternalData:!!(t||o)})})}function xs(){const t=jo(),{snack:o,handleSnackClose:n,snackDurationMs:i}=t;return e.jsxs(r.Box,{sx:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[e.jsx(r.Box,{component:"main",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:t.activeReport?e.jsx(ds,{reportEngine:t}):e.jsx(ts,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(us,{open:o.open,message:o.message,severity:o.severity,onClose:n,autoHideDurationMs:i})]})}function Fu({data:t,autoLoad:o=!0,config:n}){return e.jsx(dn,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(xs,{})})}exports.URMBuilder=Nu;exports.URMBuilderRaw=ps;exports.URMProvider=dn;exports.URMViewer=Fu;exports.URMViewerRaw=xs;exports.useURMContext=jo;
|
|
95
|
+
The file has been downloaded to your device.`);window.open(`mailto:${b.email}?subject=${h}&body=${V}`,"_blank")}(_=(a=x.current).onFired)==null||_.call(a,b)}catch(F){Et.error("urm:scheduler",`Export failed for schedule: ${b.name}`,F)}},[]);p.useEffect(()=>{if(!e)return;const b=()=>{const{reportId:S}=x.current;if(!S)return;const y=Ds(S),w=new Date;let C=!1;const E=y.map(g=>{if(!g.isActive)return g;if(new Date(g.nextRunAt)<=w){v(g);const L=jo(g.frequency,g.time,g.dayOfWeek,g.dayOfMonth,w);return C=!0,{...g,lastRunAt:w.toISOString(),nextRunAt:L,runCount:g.runCount+1}}return g});C&&Os(S,E)};b();const z=setInterval(b,mp);return()=>clearInterval(z)},[e,v])}function As({reportEngine:e}){var Kt,Br,At,_t,fr;const{activeReport:r,paginatedData:n,processedData:i,tableMetrics:s,tableEngine:l,activeView:d,isDirty:c,currentTableState:u,showFilterPanel:m,setShowFilterPanel:f,filterFocusColumn:x,handleReplaceFilters:v,handleOpenFilterForColumn:b,handleCloseFilterPanel:z,handleClearFiltersForColumn:S,showSortPanel:y,setShowSortPanel:w,handleSort:C,handleUpdateSortStack:E,handleSortAscending:g,handleSortDescending:k,showCreateViewModal:L,setShowCreateViewModal:a,showEditViewModal:_,setShowEditViewModal:F,showDeleteConfirmation:X,setShowDeleteConfirmation:re,editingView:h,deletingView:V,handleSelectView:W,handleCreateView:Q,handleUpdateCurrentView:Z,handleSaveColumnConfigToCurrentView:pe,handleSaveColumnConfigToAllViews:he,handleSaveAsNewView:N,handleRevertChanges:R,handleToggleDefault:H,handleToggleFavorite:G,handleSoftDelete:ae,handleRestoreView:ee,handlePermanentDelete:ne,handleEditView:oe,handleCloneView:O,handleCopyViewLink:te,handleSaveEditView:ce,handleConfirmDelete:ie,handlePromoteToGlobal:Ie,showManageColumns:q,setShowManageColumns:Me,handleUpdateColumnVisibility:et,handleUpdateColumnOrder:tt,handleUpdateColumnWidth:rr,handleResetColumnLayout:Ft,showGroupPanel:Vt,setShowGroupPanel:rt,handleGroup:pt,handleToggleGroupCollapse:or,handleExpandAllGroups:Ct,handleCollapseAllGroups:Je,searchQuery:jt,debouncedSearchQuery:Bt,searchHistory:Ht,handleSearchChange:nr,handleAddToSearchHistory:ir,handleToggleSearchFavourite:He,handleDeleteSearchHistory:no,selectedRowIds:sr,handleToggleRowSelection:Ut,handleToggleAllRows:ot,handleRangeSelection:nt,handleClearSelection:ar,handleUpdateSelectionAfterDelete:lr,currentPage:wt,pageSize:wr,paginationEngine:xt,handlePageChange:Nr,handlePageSizeChange:cr,isExporting:dr,showExportModal:me,setShowExportModal:kr,showDirtyExportWarning:io,handleExport:kt,handleExportWithConfig:P,handleExportSelected:mt,handleExportAnyway:fe,handleSaveAndExport:Le,handleCancelExport:Dt,showAuditHistory:ft,setShowAuditHistory:Gt,showCreatePreset:Tt,setShowCreatePreset:Tr,showManagePresets:Yt,setShowManagePresets:ur,activePreset:qt,handleCreatePreset:ze,handleClearActivePreset:K,handleOpenPresetById:Ot,handleDeletePresetById:we,isViewerRole:Ir,userRole:pr,featureLimitWarning:Se,setFeatureLimitWarning:Fe,reportError:xr,setReportError:it,handleError:ht,updateReport:Ve,showSnack:mr}=e,[zr,gt]=p.useState(!1);fp({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:d,columnVisibility:(r==null?void 0:r.columnVisibility)||((Kt=d==null?void 0:d.snapshot)==null?void 0:Kt.columnVisibility)||{},columnOrder:(r==null?void 0:r.columnOrder)||((Br=d==null?void 0:d.snapshot)==null?void 0:Br.columnOrder)||[],filters:Oe(r==null?void 0:r.filters),sortStack:(r==null?void 0:r.sortStack)||[],onFired:le=>{mr(`Scheduled export "${le.name}" completed`,"success")}});const Ue=p.useCallback((le,ge)=>{if(!(r!=null&&r.uploadedData))return;const Ae=[...r.uploadedData];Ae[le]=ge,Ve(r.id,{uploadedData:Ae})},[r,Ve]),Er=p.useCallback(le=>{if(!(r!=null&&r.uploadedData))return;const ge=r.uploadedData.indexOf(le);if(ge===-1)return;const Ae=r.uploadedData.filter((yt,bt)=>bt!==ge);Ve(r.id,{uploadedData:Ae}),lr(le)},[r,Ve,lr]),Lr=p.useCallback((le,ge)=>{if(!(r!=null&&r.uploadedData))return;const Ae=r.uploadedData.indexOf(ge),yt=Ae!==-1?Ae+1:le+1,bt=[...r.uploadedData];bt.splice(yt,0,{...ge}),Ve(r.id,{uploadedData:bt})},[r,Ve]),$t=Sr(),{handleDevConfigChange:Jt}=$o(),[Fr,st]=p.useState(!1);return p.useEffect(()=>{const le=ge=>{ge.ctrlKey&&ge.shiftKey&&ge.key==="D"&&(ge.preventDefault(),st(!0))};return document.addEventListener("keydown",le),()=>document.removeEventListener("keydown",le)},[]),!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:[Se&&t.jsx(Ku,{warning:Se,onDismiss:()=>Fe(null)}),xr&&t.jsx(Xu,{error:xr,onDismiss:()=>it(null)}),io&&t.jsx(Au,{onExportAnyway:fe,onSaveAndExport:Le,onCancel:Dt}),t.jsx(ju,{schema:r.schema,data:n,sortStack:r.sortStack,filters:r.filters,views:r.views,activeViewId:r.activeViewId,isDirty:c,isExporting:dr,columnVisibility:r.columnVisibility||(d==null?void 0:d.snapshot.columnVisibility),columnOrder:r.columnOrder||(d==null?void 0:d.snapshot.columnOrder),columnWidths:r.columnWidths||(d==null?void 0:d.snapshot.columnWidths),grouping:r.grouping,onSort:C,onSortAscending:g,onSortDescending:k,onOpenFilters:()=>f(!0),onOpenSort:()=>w(!0),onOpenFilterForColumn:b,onSelectView:W,onCreateView:()=>a(!0),onUpdateCurrentView:Z,onSaveAsNewView:N,onDiscardChanges:R,onToggleDefault:H,onToggleFavorite:G,onRestoreView:ee,onPermanentDelete:ne,onEditView:oe,onCloneView:O,onCopyLink:te,onDeleteView:ae,onPromoteToGlobal:Ie,isAdmin:((At=$t.views)==null?void 0:At.isAdmin)??!1,onExport:kt,onOpenColumns:()=>Me(!0),onUpdateColumnWidth:rr,onUpdateColumnOrder:tt,onUpdateColumnVisibility:et,onClearFiltersForColumn:S,onResetLayout:Ft,onOpenGroup:()=>rt(!0),onGroupByColumn:le=>{pt({enabled:!0,levels:[{column:le}],collapsedGroups:[]})},onToggleGroupCollapse:or,onExpandAllGroups:Ct,onCollapseAllGroups:Je,onOpenAuditHistory:()=>Gt(!0),onOpenScheduledReports:()=>gt(!0),searchQuery:jt,highlightQuery:Bt,searchHistory:Ht,onAddToSearchHistory:ir,onToggleSearchFavourite:He,onDeleteSearchHistory:no,selectedRowIds:sr,onSearchChange:nr,onToggleRowSelection:Ut,onToggleAllRows:ot,onRangeSelection:nt,onClearSelection:ar,onExportSelected:mt,currentPage:(xt==null?void 0:xt.currentPage)||wt,pageSize:(xt==null?void 0:xt.pageSize)||wr,onPageChange:Nr,onPageSizeChange:cr,totalRowsBeforePagination:(s==null?void 0:s.searchedRows)||i.length,isReadOnly:Ir,userRole:pr,reportName:r.name,onEditRow:Ue,onDeleteRow:Er,onDuplicateRow:Lr,showDevPanel:$t.display.showDevPanel,onOpenDevConfig:()=>st(!0)})]}),m&&t.jsx(yo,{feature:"Filters",onError:le=>{const ge=Zt("ui","filters",le);ht(ge)},children:t.jsx(Iu,{schema:r.schema,filters:r.filters,onReplaceFilters:v,onClose:z,focusColumn:x})}),y&&t.jsx(yo,{feature:"Sorting",onError:le=>{const ge=Zt("ui","sorting",le);ht(ge)},children:t.jsx(Eu,{schema:r.schema,sortStack:r.sortStack??[],onUpdateSortStack:E,onClose:()=>w(!1)})}),L&&u&&(()=>{var Ae;const le=(r.views??[]).filter(yt=>!yt.isDeleted).length,ge=((Ae=$t.views)==null?void 0:Ae.maxViews)??10;return t.jsx(Pi,{currentSnapshot:u,onSave:Q,onClose:()=>a(!1),atViewLimit:le>=ge,maxViews:ge})})(),_&&h&&t.jsx(Pi,{currentSnapshot:h.snapshot,onSave:ce,onClose:()=>{F(!1)},isEditMode:!0,initialName:h.name,initialDescription:h.description,initialIsDefault:h.isDefault}),X&&V&&t.jsx(Bu,{viewName:V.name,onConfirm:ie,onCancel:()=>{re(!1)}}),q&&d&&t.jsx(Ou,{schema:r.schema,columnVisibility:r.columnVisibility||d.snapshot.columnVisibility,columnOrder:r.columnOrder||d.snapshot.columnOrder,columnWidths:r.columnWidths||d.snapshot.columnWidths,views:r.views,activeViewId:r.activeViewId,onUpdateColumnVisibility:et,onUpdateColumnOrder:tt,onUpdateColumnWidth:rr,onResetLayout:Ft,onSelectView:le=>{W(le)},onSaveToCurrentView:le=>{pe(le),Me(!1)},onSaveToAllViews:le=>{he(le),Me(!1)},onClose:()=>Me(!1)}),Vt&&t.jsx(yo,{feature:"Grouping",onError:le=>{const ge=Zt("ui","grouping",le);ht(ge)},children:t.jsx($u,{schema:r.schema,grouping:r.grouping||null,onApply:pt,onClose:()=>rt(!1)})}),ft&&t.jsx(Ru,{auditHistory:r.auditHistory||[],onClose:()=>Gt(!1)}),Tt&&t.jsx(Wu,{onSave:ze,onClose:()=>Tr(!1)}),Yt&&t.jsx(Nu,{presets:r.presets||[],reportId:r.id,onOpenPreset:Ot,onDeletePreset:we,onClose:()=>ur(!1)}),qt&&t.jsx(o.Box,{sx:{mt:2},children:t.jsx(Pu,{presetName:qt.name,onClear:K})}),me&&t.jsx(yo,{feature:"Export",onError:le=>{const ge=Zt("ui","export",le);ht(ge)},children:t.jsx(Ju,{totalRows:(s==null?void 0:s.totalRows)||((_t=r.uploadedData)==null?void 0:_t.length)||0,visibleRows:(s==null?void 0:s.searchedRows)||i.length,visibleColumnsCount:((fr=l==null?void 0:l.columnEngine)==null?void 0:fr.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:P,onClose:()=>{kr(!1)}})}),r&&t.jsx(xp,{open:zr,onClose:()=>gt(!1),reportId:r.id,reportName:r.name,onRunNow:le=>{const ge=le.scope==="all"?r.uploadedData||[]:i||[],Ae=wo(ge,r.schema||[],Oe(r.filters),r.sortStack||[],d,r.columnVisibility,r.columnOrder);le.format==="csv"&&ko(Ae,le.name),le.format==="excel"&&To(Ae,le.name),le.format==="json"&&Io(Ae,le.name),mr(`"${le.name}" exported successfully`,"success")}}),t.jsx(rp,{open:Fr,onClose:()=>st(!1),config:$t,onApply:Jt})]})}const hp={error:"err",warning:"warn",info:"info",success:"suc"};function _s({open:e,message:r,severity:n,onClose:i,autoHideDurationMs:s}){var C,E;const l=o.useTheme(),d=l.tokens,c=(d==null?void 0:d.notifPosition)??"top-right",u=(d==null?void 0:d.notifStyle)??"toast",m=(d==null?void 0:d.notifAccent)??"severity",f=(d==null?void 0:d.notifAutoDismiss)??!0,x=(d==null?void 0:d.toastW)??252,v=c.startsWith("top")?"top":"bottom",b=c.endsWith("center")?"center":c.endsWith("left")?"left":"right",z=hp[n],S=((C=d==null?void 0:d.status)==null?void 0:C[`${z}Soft`])??l.palette[n].light,y=((E=d==null?void 0:d.status)==null?void 0:E[`${z}Txt`])??l.palette[n].dark,w=m==="primary"?l.palette.primary.main:m==="mono"?l.palette.text.secondary:y;return t.jsx(o.Snackbar,{open:e,autoHideDuration:f?s??2e3:void 0,onClose:(g,k)=>{k!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:v,horizontal:b},children:t.jsx(o.Alert,{severity:n,icon:!1,onClose:f?void 0:i,sx:{width:x,alignItems:"flex-start",bgcolor:S,color:y,boxShadow:u==="inline"?"none":(d==null?void 0:d.cardShadow)??3,border:u==="inline"?"1px solid":u==="toast"?(d==null?void 0:d.cardBorder)??"1px solid":"none",borderColor:"divider",borderLeft:u==="banner"?`4px solid ${w}`:void 0,borderRadius:`${l.shape.borderRadius}px`},children:r})})}function Ms({hasExternalData:e=!1}){const r=$o(),{reports:n,activeReportId:i,activeReport:s,uploadState:l,hasSchemaConflicts:d,isModalOpen:c,setIsModalOpen:u,setActiveReportId:m,createReport:f,handleFileUpload:x,handleUploadError:v,handleRetry:b,handleConfirm:z,snack:S,handleSnackClose:y,snackDurationMs:w}=r,C=e&&l==="uploading"&&n.length===0;return t.jsxs(o.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsx(zl,{onCreateReport:()=>u(!0),reports:n,activeReportId:i,onReportClick:m}),t.jsx(o.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:C?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(Cs,{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(As,{reportEngine:r}):t.jsx(o.Box,{sx:{p:3},children:l==="preview"&&s.schema&&s.uploadedData?t.jsx(Ld,{schema:s.schema,onConfirm:z,hasConflicts:d}):s.uploadError?t.jsx(Fd,{error:s.uploadError,onRetry:b}):t.jsx(Nd,{onFileUpload:x,onError:v,isUploading:l==="uploading"})})}):null}),!e&&t.jsx(Pd,{isOpen:c,onClose:()=>u(!1),onCreate:f}),t.jsx(_s,{open:S.open,message:S.message,severity:S.severity,onClose:y,autoHideDurationMs:w})]})}function gp({data:e,dataSource:r,reportName:n,autoLoad:i=!0,config:s}={}){return t.jsx(Mn,{mode:"builder",data:e,dataSource:r,reportName:n,autoLoad:i,config:s,children:t.jsx(Ms,{hasExternalData:!!(e||r)})})}function Rs(){const e=$o(),{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(As,{reportEngine:e}):t.jsx(Cs,{title:"No report data",description:"This viewer requires report data to be loaded."})}),t.jsx(_s,{open:r.open,message:r.message,severity:r.severity,onClose:n,autoHideDurationMs:i})]})}function yp({data:e,autoLoad:r=!0,config:n}){return t.jsx(Mn,{data:e,mode:"viewer",autoLoad:r,config:n,children:t.jsx(Rs,{})})}exports.URMBuilder=gp;exports.URMBuilderRaw=Ms;exports.URMProvider=Mn;exports.URMViewer=yp;exports.URMViewerRaw=Rs;exports.useURMContext=$o;
|