dts-universal-report-module 1.0.8 → 1.0.10
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 +6270 -6190
- package/dist/index.js +25 -25
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),Ts=require("xlsx"),w=require("@mui/icons-material"),r=require("@mui/material"),ui=require("react-dom"),Is=require("@emotion/react"),kt=require("react-dnd"),Xo=require("react-dnd-html5-backend");function pi(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 go=pi(u),Qr=pi(Ts),Ve={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}},xi="urm_dev_config";function zs(){try{const t=localStorage.getItem(xi);if(!t)return Ve;const o=JSON.parse(t),n={sort:{...Ve.sort,...o.sort},filter:{...Ve.filter,...o.filter},columns:{...Ve.columns,...o.columns},grouping:{...Ve.grouping,...o.grouping},export:{...Ve.export,...o.export},views:{...Ve.views,...o.views},dates:{...Ve.dates,...o.dates},display:{...Ve.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ve}}function Es(t){try{localStorage.setItem(xi,JSON.stringify(t))}catch{}}function Bs(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 mi=u.createContext(Ve);function Kt(){return u.useContext(mi)}const Ds=/^\d{4}-\d{2}-\d{2}$/,Os=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,As=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ms=9783072e5,_s=41024448e5,$s=978307200,Rs=4102444800;function Ws(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Ms&&t<=_s?"timestamp_ms":Number.isInteger(t)&&t>=$s&&t<=Rs?"timestamp_s":"unknown":typeof t!="string"?"unknown":Os.test(t)||Ds.test(t)?"iso":As.test(t.trim())?"locale_string":"unknown"}function Ps(t,o){const n=o.map(d=>d[t]).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 l=Ws(d);i[l]++}const a=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/a>=c)return d;return"unknown"}function Ns(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 mn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ls=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ae(t){return String(t).padStart(2,"0")}function Fs(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,a=Math.floor(n/1e3),c=Math.floor(a/60),d=Math.floor(c/60),l=Math.floor(d/24),p=Math.floor(l/7),x=Math.floor(l/30),f=Math.floor(l/365);let b;return a<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:p<5?b=`${p} week${p!==1?"s":""}`:x<12?b=`${x} month${x!==1?"s":""}`:b=`${f} year${f!==1?"s":""}`,a<60?b:i?`${b} ago`:`in ${b}`}function Vs(t,o){const n=t.getFullYear(),i=t.getMonth(),a=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${Ae(i+1)}-${Ae(a)}`;case"DD/MM/YYYY":return`${Ae(a)}/${Ae(i+1)}/${n}`;case"MM/DD/YYYY":return`${Ae(i+1)}/${Ae(a)}/${n}`;case"MMM DD, YYYY":return`${mn[i]} ${Ae(a)}, ${n}`;case"DD MMM YYYY":return`${Ae(a)} ${mn[i]} ${n}`;case"MMMM D, YYYY":return`${Ls[i]} ${a}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Ae(i+1)}-${Ae(a)} ${Ae(c)}:${Ae(d)}`;case"DD/MM/YYYY HH:mm":return`${Ae(a)}/${Ae(i+1)}/${n} ${Ae(c)}:${Ae(d)}`;case"MM/DD/YYYY HH:mm":return`${Ae(i+1)}/${Ae(a)}/${n} ${Ae(c)}:${Ae(d)}`;case"relative":return Fs(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Hs(t,o,n){if(!n||o==="unknown")return String(t);const i=Ns(t,o);return!i||isNaN(i.getTime())?String(t):Vs(i,n)}function Us(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 fi(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const a of Object.keys(t)){const c=o?`${o}.${a}`:a,d=t[a];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,fi(d,c,n+1)):i[c]=d}return i}function ao(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:fi(o))}function Pr(t){if(!Array.isArray(t)||t.length===0)return[];const o=ao(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let p=0;o.forEach(m=>{typeof m=="object"&&m!==null&&d in m&&(p++,l.add(Us(m[d])))});const x=p===o.length,f=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const m=Array.from(l).filter(g=>g!=="null");m.length===1&&(b=m[0])}i.push({name:d,type:b,required:x,hasConflict:f})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Ps(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Ys(t){return t.some(o=>o.hasConflict)}function Ue(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 fn(t){return t==null}function Gs(t){return(o,n,i)=>{const a=fn(o),c=fn(n);if(a&&c)return 0;if(a)return 1;if(c)return-1;let d=0;switch(t){case"number":const l=Number(o),p=Number(n);d=l-p;break;case"boolean":d=(o?1:0)-(n?1:0);break;case"string":d=String(o).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(o).localeCompare(String(n));break}return i==="asc"?d:-d}}function qs(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((a,c)=>a.priority-c.priority);return[...t].sort((a,c)=>{for(const d of i){const l=o.find(f=>f.name===d.column);if(!l)continue;const x=Gs(l.type)(a[d.column],c[d.column],d.direction);if(x!==0)return x}return 0})}function Js(t){return t===null?"asc":t==="asc"?"desc":null}function Ks(t){return t==="string"||t==="boolean"}function Xs(t){return t.filter(o=>Ks(o.type))}function Zs(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const a=t.map(c=>c[i.name]).filter(c=>typeof c=="number");a.length>0&&(n[i.name]=a.reduce((c,d)=>c+d,0))}}),n}function Qs(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=hi(t,n.levels,o);return gi(i,n.collapsedGroups||[])}function hi(t,o,n,i="",a=0){if(a>=o.length)return t;const c=o[a].column,d=new Map;t.forEach(x=>{const f=x[c],b=f==null?"(empty)":String(f);d.has(b)||d.set(b,[]),d.get(b).push(x)});const l=[];return Array.from(d.keys()).sort().forEach(x=>{const f=d.get(x),b=`${c}:${x}`,m=i?`${i}|${b}`:b,g=Zs(f,n),z=a<o.length-1?hi(f,o,n,m,a+1):f,y={key:m,level:a,column:c,value:x,rowCount:f.length,aggregates:g,children:z};l.push(y)}),l}function gi(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const a=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:a}),!a&&i.children&&gi(i.children,o,n)}else n.push(i);return n}function ea(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(a=>a!==o):[...n,o];return{...t,collapsedGroups:i}}function yi(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function bi(t,o,n){return`${o}: ${n}`}function Hr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(a=>a.column),i=t.filter(a=>!n.includes(a));return[...n,...i]}function vi(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),a=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(a);let p=0;for(const x of n)d.has(x)?c.push(x):l.has(x)&&p<a.length?(c.push(a[p]),p++):l.has(x)||c.push(x);for(let x=p;x<a.length;x++)c.includes(a[x])||c.push(a[x]);return c}return[...t]}function $o(t){const o={},n=[],i={};return t.forEach(a=>{o[a.name]=!0,n.push(a.name),i[a.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 ta(t,o,n,i,a,c,d,l){const p={},x=[],f={};n.forEach(g=>{p[g.name]=!0,x.push(g.name),f[g.name]=170});const m=vi(a||x,d||null,l||x);return{filters:t||[],sortStack:o||[],columnVisibility:i||p,columnOrder:m,columnWidths:c||f,grouping:d||null}}function ra(t,o){const n=m=>{if(m==null)return m;if(Array.isArray(m))return m.map(g=>n(g));if(typeof m=="object"){const g={};return Object.keys(m).sort().forEach(z=>{g[z]=n(m[z])}),g}return m},i=m=>JSON.stringify(n(m));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack))return!0;const a=t.columnVisibility??{},c=o.columnVisibility??{};if(i(a)!==i(c))return!0;const d=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(d!==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 m=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==m)return!0}const f=t.columnWidths??{},b=o.columnWidths??{};return i(f)!==i(b)||i(t.grouping)!==i(o.grouping)}function oa(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function na(t,o){var y,C,v;const n=[],i=JSON.stringify(t.filters),a=JSON.stringify(o.filters);if(i!==a){const k=t.filters.length,S=o.filters.length;k>S?n.push({category:"filters",label:"Filters Added",description:`${k-S} new filter${k-S>1?"s":""} added`}):k<S?n.push({category:"filters",label:"Filters Removed",description:`${S-k} filter${S-k>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const c=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(c!==d){const k=t.sortStack.length,S=o.sortStack.length;k>S?n.push({category:"sorting",label:"Sorting Added",description:`${k-S} new sort rule${k-S>1?"s":""} added`}):k<S?n.push({category:"sorting",label:"Sorting Removed",description:`${S-k} sort rule${S-k>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 k=Object.values(t.columnVisibility).filter(T=>T).length,S=Object.values(o.columnVisibility).filter(T=>T).length;k>S?n.push({category:"visibility",label:"Columns Shown",description:`${k-S} column${k-S>1?"s":""} made visible`}):k<S?n.push({category:"visibility",label:"Columns Hidden",description:`${S-k} column${S-k>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const x=JSON.stringify(t.columnOrder),f=JSON.stringify(o.columnOrder);x!==f&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),m=JSON.stringify(o.columnWidths);if(b!==m){const k=Object.keys(t.columnWidths).filter(S=>t.columnWidths[S]!==o.columnWidths[S]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${k} column width${k>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),z=JSON.stringify(o.grouping);if(g!==z){const k=(y=t.grouping)==null?void 0:y.enabled,S=(C=o.grouping)==null?void 0:C.enabled;if(k&&!S){const T=((v=t.grouping)==null?void 0:v.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${T} grouping level${T>1?"s":""} added`})}else!k&&S?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 hn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function gn(t){return`[${t}]`}const qt={warn(t,o,...n){hn()&&console.warn(gn(t),o,...n)},error(t,o,...n){hn()&&console.error(gn(t),o,...n)}},Si="urm_report_";function ia(t,o){try{const n=`${Si}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){qt.error("urm:persistence","Failed to save report state",n)}}function sa(t){try{const o=`${Si}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return qt.error("urm:persistence","Failed to load report state",o),null}}function yo(t,o,n=0){const i=[];for(const a of t){const c=o.includes(a.key);if(i.push({type:"group",key:a.key,level:n,column:a.column,value:a.value,rowCount:a.rowCount,aggregates:a.aggregates,collapsed:c}),!c&&a.children&&a.children.length>0){const d=a.children[0];if(aa(d)){const l=a.children,p=yo(l,o,n+1);i.push(...p)}else{const l=a.children;for(const p of l)i.push({type:"row",parentGroupKey:a.key,level:n+1,data:p})}}}return i}function aa(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 Zo(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function Qo(t,o){const n=new Date,i=n.getFullYear(),a=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${a}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function po(t,o,n,i,a,c,d){let l,p;c?(l={...c},p=d||o.map(f=>f.name)):a?(l={...a.snapshot.columnVisibility},p=d||[...a.snapshot.columnOrder]):(l={},p=[],o.forEach(f=>{l[f.name]=!0,p.push(f.name)}));const x=Object.entries(l).filter(([f,b])=>!b).map(([f,b])=>f);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:p,grouping:(a==null?void 0:a.snapshot.grouping)??null,hiddenColumns:x,viewMeta:a?{id:a.id,name:a.name,isDefault:a.isDefault}:void 0}}function xo(t,o="export",n){const{data:i,columnOrder:a,grouping:c}=t,d=a.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=yo(i);l=Zo(b)}else l=i;const p=d.join(","),x=l.map(b=>d.map(m=>{const g=b[m];if(g==null)return"";const z=String(g);return z.includes(",")||z.includes('"')||z.includes(`
|
|
2
|
-
`)?`"${
|
|
3
|
-
`);ji(f,Qo(o,"csv"),"text/csv;charset=utf-8;")}function mo(t,o="export",n){const{data:i,columnOrder:a,grouping:c}=t,d=a.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=yo(i);l=Zo(b)}else l=i;const p=[d,...l.map(b=>d.map(m=>b[m]??""))],x=Qr.utils.aoa_to_sheet(p),f=Qr.utils.book_new();Qr.utils.book_append_sheet(f,x,"Data"),Qr.writeFile(f,Qo(o,"xlsx"))}function fo(t,o="export",n){const{data:i,appliedFilters:a,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:p,grouping:x}=t;let f;if(x&&x.enabled){const g=yo(i);f=Zo(g)}else f=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:a.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:x||{},hiddenColumns:l,columnOrder:p,exportConfig:n||{scope:"visible"}},data:f},m=JSON.stringify(b,null,2);ji(m,Qo(o,"json"),"application/json;charset=utf-8;")}function ji(t,o,n){const i=new Blob([t],{type:n}),a=URL.createObjectURL(i),c=document.createElement("a");c.href=a,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(a)}const yn=10;function la(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.query.toLowerCase()===n.toLowerCase());let a;return i!==-1?a=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:a=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],a.length>yn&&(a=[...a].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,yn)),a}function ca(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function da(t,o){return t.filter(n=>n.query!==o)}function ua(t){const o=t.filter(i=>i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed);return[...o,...n]}const pa={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 xa(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function ct(t,o){return pa[o].includes(t)}function dt(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 ma(t){return t==="viewer"}const bn=1e3;function Go(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function xt(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Go(n)}const fa={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 Ro(t){if(!t||!t.column)return"a filter";const o=xt(t.column),n=fa[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function vn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${xt(n.column)}"`).join(", ")}`}function ha(t){var a,c,d;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: ${Ro(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Ro(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 "${xt(p==null?void 0:p.column)}"`,detail:`Previously filtered "${xt(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Ro(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?xt(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?xt(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: ${vn(i)}`};case"group_level_removed":{const l=n,p=(c=(a=l==null?void 0:l.levels)==null?void 0:a[0])!=null&&c.column?xt(l.levels[0].column):"";return{summary:p?`Group level removed: "${p}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${vn(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: "${xt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${xt(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: "${xt(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,x=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",f=(i==null?void 0:i.viewName)??"",b=typeof p=="number"?` (${p.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:f?`${Go(x)} · View: "${f}"`:Go(x)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.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:ya(o)}}}function ga(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ci(t,o,n,i,a,c){return{id:ga(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:a,newState:c}}function wi(t,o){const n=[o,...t];return n.length>bn?n.slice(0,bn):n}function ya(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 ba(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function va(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function Sa(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),a=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return a<1?"Just now":a<60?`${a} minute${a>1?"s":""} ago`:c<24?`${c} hour${c>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const Sn=100;function ja(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ca(t){var c;const o=(c=t.views)==null?void 0:c.find(d=>d.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],a=vi(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:a,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function wa(t,o,n,i){return{id:ja(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function ka(t,o){const n=t||[];if(n.length>=Sn)throw new Error(`Maximum of ${Sn} presets reached. Please delete old presets first.`);return[...n,o]}function Ta(t,o){return(t||[]).filter(i=>i.id!==o)}function jn(t,o){if(t)return t.find(n=>n.id===o)}function Ia(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function za(t){const o=t.columnOrder,n=Hr(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 Ea(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ba={MAX_CACHE_ENTRIES:3};function Da(t,o){let n=null;return function(...a){const c=()=>{n=null,t(...a)};n&&clearTimeout(n),n=setTimeout(c,o)}}class eo{constructor(o=Ba.MAX_CACHE_ENTRIES){this.cache=new Map,this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const a=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];a&&this.cache.delete(a)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Oa{constructor(){this.metrics=new Map}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),a=this.end(o);return{result:i,duration:a}}async measureAsync(o,n){this.start(o);const i=await n(),a=this.end(o);return{result:i,duration:a}}}function wt(t,o,n,i){const a=n instanceof Error?n.message:n,c={type:t,context:o,message:a,details:i,timestamp:Date.now(),recoverable:Aa(t,o)};return process.env.NODE_ENV==="development"&&qt.error("urm:error-handling","[Report Error]",{type:t,context:o,message:a,details:i}),c}function Aa(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Ma(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 _a(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 $a(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 Ra(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 ki(t,o){const n=[],i=[],a=new Set(o.map(c=>c.name));return t.forEach(c=>{a.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function Ti(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],a=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):a.push(c.column)}),i.length===0?{validGrouping:null,invalidColumns:a}:{validGrouping:{...t,levels:i},invalidColumns:a}}function Wa(t,o){const n=[],i=new Set(o.map(c=>c.name)),a={...t};if(a.filters&&Array.isArray(a.filters)){const c=a.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});a.filters=c.length>0?c:void 0}if(a.sortStack&&Array.isArray(a.sortStack)){const{validRules:c,invalidColumns:d}=ki(a.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),a.sortStack=c.length>0?c:void 0}if(a.grouping){const{validGrouping:c,invalidColumns:d}=Ti(a.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),a.grouping=c}if(a.columnVisibility){const c={};Object.entries(a.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),a.columnVisibility=Object.keys(c).length>0?c:void 0}if(a.columnOrder&&Array.isArray(a.columnOrder)){const c=a.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});a.columnOrder=c.length>0?c:void 0}if(a.columnWidths){const c={};Object.entries(a.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),a.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:a,warnings:n}}function Pa(t,o){return wt("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function Cn(t,o,n,i){const a=Ci(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return wi(i||[],a)}function Na(t){return t==null}function La(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Na(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=>La(n[i.column],i)))}function wn(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 to(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 a=n.toLowerCase().trim(),c=o.filter(d=>i.includes(d.name));return t.filter(d=>c.some(l=>{const p=d[l.name];return p==null?!1:String(p).toLowerCase().includes(a)}))}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 Ya({data:t,sortStack:o,schema:n}){return{sortedData:u.useMemo(()=>!o||o.length===0?t:qs(t,n,o),[t,o,n])}}function Ga({data:t,grouping:o,schema:n}){const i=u.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:Qs(t,n,o),[t,o,n]),a=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:a}}function qa({schema:t,columnVisibility:o,columnOrder:n}){const i=u.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),a=u.useMemo(()=>Object.entries(o).filter(([l,p])=>!p).map(([l,p])=>l),[o]),c=u.useMemo(()=>n.map(l=>t.find(x=>x.name===l)||{name:l,type:"string"}),[n,t]),d=u.useMemo(()=>i.map(l=>t.find(x=>x.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:a,allColumns:c,visibleColumnSchemas:d,hiddenCount:a.length}}function Ja({views:t,activeViewId:o,currentState:n}){const i=u.useMemo(()=>t.find(x=>x.id===o),[t,o]),a=u.useMemo(()=>i?ra(n,i.snapshot):!1,[i,n]),c=u.useMemo(()=>t.find(x=>x.isDefault),[t]),d=u.useMemo(()=>t.filter(x=>!x.isDefault&&!x.isDeleted),[t]),l=u.useMemo(()=>t.filter(x=>x.isFavorite&&!x.isDeleted),[t]),p=u.useMemo(()=>t.filter(x=>x.isDeleted),[t]);return{activeView:i,isDirty:a,defaultView:c,customViews:d,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[a,c]=u.useState(i),d=t.length,l=Math.ceil(d/n),p=u.useMemo(()=>{if(!o)return t;const g=(a-1)*n,z=g+n;return t.slice(g,z)},[t,o,a,n]),x=u.useCallback(g=>{const z=Math.max(1,Math.min(g,l));c(z)},[l]),f=u.useCallback(()=>{a<l&&c(a+1)},[a,l]),b=u.useCallback(()=>{a>1&&c(a-1)},[a]),m=u.useCallback(()=>{c(1)},[]);return{paginatedData:p,currentPage:a,totalPages:l,pageSize:n,totalRows:d,goToPage:x,nextPage:f,prevPage:b,resetPage:m,hasNextPage:a<l,hasPrevPage:a>1}}function Xa(t){const{rawData:o,schema:n,filters:i,sortStack:a,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:p,columnWidths:x,views:f,activeViewId:b,pagination:m}=t,g=u.useMemo(()=>({filters:i,sortStack:a,grouping:c,columnVisibility:l,columnOrder:p,columnWidths:x}),[i,a,c,l,p,x]),z=Ja({views:f,activeViewId:b,currentState:g}),y=qa({schema:n,columnVisibility:l,columnOrder:p}),{filteredData:C}=Va({data:o,filters:i}),{sortedData:v}=Ya({data:C,sortStack:a,schema:n}),{groupedData:k,isGrouped:S}=Ga({data:v,grouping:c,schema:n}),{searchedData:T}=Ua({data:k,searchQuery:d,schema:n,visibleColumns:y.visibleColumns}),s=Ka({data:T,enabled:(m==null?void 0:m.enabled)||!1,pageSize:(m==null?void 0:m.pageSize)||100,initialPage:(m==null?void 0:m.currentPage)||1}),M=m!=null&&m.enabled?s.paginatedData:T,B=u.useMemo(()=>({totalRows:o.length,filteredRows:C.length,sortedRows:v.length,groupedRows:S?k.length:v.length,searchedRows:T.length,visibleRows:M.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:a.length,isGrouped:S}),[o.length,C.length,v.length,k.length,T.length,M.length,y.hiddenCount,i.length,a.length,S]);return{data:M,filteredData:C,sortedData:v,groupedData:k,searchedData:T,viewEngine:z,columnEngine:y,paginationEngine:s,metrics:B,isGrouped:S,isPaginated:(m==null?void 0:m.enabled)||!1}}let Za=0;function Qa(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Za++,writable:!1,enumerable:!1,configurable:!1})}const ut="user-demo-001";function el(t={}){var ln,cn,dn,un,pn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:a,reportName:c,sharedReportId:d,config:l={}}=t,[p,x]=u.useState([]),f=Kt(),[b,m]=u.useState(""),[g,z]=u.useState(!1),[y,C]=u.useState(!1),[v,k]=u.useState({message:"",severity:"info",open:!1}),S=(j,E="info")=>{k({message:j,severity:E,open:!0})},T=()=>k(j=>({...j,open:!1})),s=p.find(j=>j.id===b),[M,B]=u.useState("idle"),[$,G]=u.useState(!1),[Z,ee]=u.useState(!1),[h,R]=u.useState(!1),[W,H]=u.useState(!1),[K,de]=u.useState(!1),[ue,te]=u.useState(!1),[A,V]=u.useState(void 0),[q,re]=u.useState(null),[Q,le]=u.useState(null),[oe,N]=u.useState(!1),[ne,ce]=u.useState(!1),[se,fe]=u.useState(null),[J,Me]=u.useState(!1),[Ne,et]=u.useState(!1),[Qt,gr]=u.useState({enabled:!1,levels:[],collapsedGroups:[]}),[$t,ot]=u.useState(""),[Le,Ee]=u.useState(new Set),[mt,nt]=u.useState(1),[tt,Ge]=u.useState(15),[ft,er]=u.useState(!1),[qe,Je]=u.useState(!1),[$e,tr]=u.useState(!1),[ht,zt]=u.useState(null),[rr,it]=u.useState(!1),[yr,br]=u.useState(null),[vr,Rt]=u.useState(null);u.useRef(new Oa),u.useRef(new eo),u.useRef(new eo),u.useRef(new eo),u.useRef(new eo);const[Sr,jr]=u.useState(null),Ke=u.useRef(null),be=u.useMemo(()=>s?xa(s.permissions,ut):"owner",[s]),Cr=ma(be),or=u.useMemo(()=>!(s!=null&&s.uploadedData)||!(s!=null&&s.schema)?{totalRows:0,totalColumns:0}:Ea(s.uploadedData,s.schema),[s==null?void 0:s.uploadedData,s==null?void 0:s.schema]),rt=u.useCallback(()=>{s&&(Ke.current=_a(s))},[s]),L=u.useCallback((j,E)=>{x(_=>_.map(O=>O.id===j?{...O,...E}:O))},[]),Fe=u.useCallback(j=>{if(!s)return;jr(j);const E=Cn(s.id,ut,j,s.auditHistory||[]);L(s.id,{auditHistory:E}),S(j.message,"error"),j.recoverable&&Ke.current&&setTimeout(()=>{$a(s,Ke.current,L),S("Previous state restored","success")},100)},[s,L]),ve=u.useCallback((j,E,_,O)=>{if(!s)return;const Y=Ci(s.id,ut,j,E,_,O),U=s.auditHistory||[],pe=wi(U,Y);setTimeout(()=>{L(s.id,{auditHistory:pe})},0)},[s,L]);u.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const j=$o(s.schema);(()=>{try{const E=localStorage.getItem("urm_dev_config");return E?JSON.parse(E):null}catch{return null}})(),L(s.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})}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id,L]),u.useEffect(()=>{if(i&&n&&!y&&p.length===0){const j=ao(i),E={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:j,schema:Pr(j),permissions:{owner:ut,editors:[],viewers:[]}};x([E]),m(E.id),C(!0),B("confirmed")}},[i,n,y,p.length,o,c]),u.useEffect(()=>{if(!a||y)return;let j=!1,E=null;const _=async()=>{try{B("uploading");let O;if(a.type==="api"){const U=await fetch(a.url,{headers:a.headers||{}});if(!U.ok)throw new Error(`HTTP ${U.status}: ${U.statusText}`);O=await U.json()}else O=await a.fetch();if(j)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const Y=Pr(O);if(y)x(U=>U.map(pe=>pe.id===b?{...pe,uploadedData:O}:pe)),B("confirmed");else{const U={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${a.type==="api"?a.url:"callback"}`,schemaLocked:!0,uploadedData:ao(O),schema:Pr(ao(O)),permissions:{owner:ut,editors:[],viewers:[]}};x([U]),m(U.id),C(!0),B("confirmed")}}catch(O){j||(B("error"),s&&L(s.id,{uploadError:(O==null?void 0:O.message)||"Failed to load data from source"}))}};return _(),a.refreshInterval&&a.refreshInterval>0&&(E=setInterval(_,a.refreshInterval)),()=>{j=!0,E&&clearInterval(E)}},[a,c,o]);const Re=(ln=s==null?void 0:s.views)==null?void 0:ln.find(j=>j.id===s.activeViewId),wr=u.useMemo(()=>s!=null&&s.uploadedData?(s.uploadedData.forEach(Qa),s.showFavoritesOnly?!s.favoriteRowIndices||s.favoriteRowIndices.length===0?[]:s.uploadedData.filter((j,E)=>s.favoriteRowIndices.includes(E)):s.uploadedData):[],[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),Wt=u.useMemo(()=>{var E;if(!(s!=null&&s.uploadedData)||!((E=s==null?void 0:s.favoriteRowIndices)!=null&&E.length))return new Set;const j=new Set;return s.favoriteRowIndices.forEach(_=>{const O=s.uploadedData[_];O!==void 0&&j.add(O)}),j},[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),gt=Xa({rawData:wr,schema:(s==null?void 0:s.schema)||[],filters:(s==null?void 0:s.filters)||[],sortStack:(s==null?void 0:s.sortStack)||[],grouping:(s==null?void 0:s.grouping)||null,searchQuery:$t||"",columnVisibility:(s==null?void 0:s.columnVisibility)||(Re==null?void 0:Re.snapshot.columnVisibility)||{},columnOrder:(s==null?void 0:s.columnOrder)||(Re==null?void 0:Re.snapshot.columnOrder)||[],columnWidths:(s==null?void 0:s.columnWidths)||(Re==null?void 0:Re.snapshot.columnWidths)||{},views:(s==null?void 0:s.views)||[],activeViewId:(s==null?void 0:s.activeViewId)||"",pagination:{enabled:!0,pageSize:tt,currentPage:mt}}),{data:Pt=[],searchedData:Nt=[],groupedData:Et=[],metrics:kr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Lt=!1,paginationEngine:Oe}=gt||{},X=((cn=gt.viewEngine)==null?void 0:cn.activeView)||Re,yt=((dn=gt.viewEngine)==null?void 0:dn.isDirty)||!1;u.useEffect(()=>{if(!(!X||!s)&&!s.columnOrder){const j=X.snapshot.columnOrder,E=Hr(j,X.snapshot.grouping);L(s.id,{columnOrder:E})}},[s==null?void 0:s.activeViewId]);const he=u.useMemo(()=>!(s!=null&&s.schema)||!X?null:ta(s.filters||[],s.sortStack||[],s.schema,s.columnVisibility,s.columnOrder,s.columnWidths,s.grouping,X.snapshot.columnOrder),[s==null?void 0:s.filters,s==null?void 0:s.sortStack,s==null?void 0:s.schema,s==null?void 0:s.columnVisibility,s==null?void 0:s.columnOrder,s==null?void 0:s.columnWidths,s==null?void 0:s.grouping,X]),Se=u.useMemo(()=>!X||!he||!yt?[]:na(he,X.snapshot),[X,he,yt]),Xe=u.useCallback((j,E,_)=>{const O={id:`report-${Date.now()}`,name:j,description:E,schemaLocked:!1,permissions:{owner:ut,editors:[],viewers:[]}};if(_&&Array.isArray(_)&&_.length>0){const Y=Pr(_),U=$o(Y);O.uploadedData=_,O.schema=Y,O.schemaLocked=!0,O.views=[U],O.activeViewId=U.id,O.sortStack=U.snapshot.sortStack,O.filters=U.snapshot.filters,O.columnVisibility=U.snapshot.columnVisibility,O.columnOrder=U.snapshot.columnOrder,O.columnWidths=U.snapshot.columnWidths,O.grouping=U.snapshot.grouping}x(Y=>[...Y,O]),m(O.id),z(!1),B("confirmed")},[]),Tr=u.useCallback(j=>{s&&(B("uploading"),setTimeout(()=>{const E=Pr(j);L(s.id,{uploadedData:j,schema:E,uploadError:void 0}),B("preview")},500))},[s,L]),bt=u.useCallback(j=>{s&&(L(s.id,{uploadError:j}),B("idle"))},[s,L]),We=u.useCallback(()=>{s&&(L(s.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),B("idle"))},[s,L]),nr=u.useCallback(()=>{s&&(L(s.id,{schemaLocked:!0}),B("confirmed"))},[s,L]),Ir=u.useCallback(j=>{if(!s)return;if(!ct("edit_sorting",be)){S(dt("edit_sorting"),"error");return}const E=s.sortStack??[],_=E.find(O=>O.column===j);if(_){const O=Js(_.direction);if(O===null){const Y=E.filter(U=>U.column!==j).map((U,pe)=>({...U,priority:pe+1}));L(s.id,{sortStack:Y.length>0?Y:void 0})}else{const Y=E.map(U=>U.column===j?{...U,direction:O}:U);L(s.id,{sortStack:Y})}}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:j,direction:"asc",priority:E.length+1};L(s.id,{sortStack:[...E,O]})}},[s,be,L]),ir=u.useCallback(j=>{if(s)if(s.schema){const{validRules:E,invalidColumns:_}=ki(j,s.schema);_.length>0&&S(`Removed invalid sort columns: ${_.join(", ")}`),rt();try{L(s.id,{sortStack:E.length>0?E:void 0})}catch(O){const Y=wt("processing","sorting",O);Fe(Y)}}else L(s.id,{sortStack:j.length>0?j:void 0})},[s,L,rt,Fe]),vt=u.useCallback(j=>{if(!s)return;const E=s.sortStack??[],_=E.find(O=>O.column===j);if(!(_&&_.direction==="asc"))if(_){const O=E.map(Y=>Y.column===j?{...Y,direction:"asc"}:Y);L(s.id,{sortStack:O})}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:j,direction:"asc",priority:E.length+1};L(s.id,{sortStack:[...E,O]})}},[s,L]),zr=u.useCallback(j=>{if(!s)return;const E=s.sortStack??[],_=E.find(O=>O.column===j);if(!(_&&_.direction==="desc"))if(_){const O=E.map(Y=>Y.column===j?{...Y,direction:"desc"}:Y);L(s.id,{sortStack:O})}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:j,direction:"desc",priority:E.length+1};L(s.id,{sortStack:[...E,O]})}},[s,L]),Bt=u.useCallback(j=>{var _;if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const E=(_=s.schema)==null?void 0:_.find(O=>O.name===j.column);if(E&&j.value!==void 0){const O=Ra(E.type,j.operator,j.value);if(!O.isValid){S(O.errorMessage||"Invalid filter value","error");return}}rt();try{const O=s.filters??[];ve("filters","filter_added",O,[...O,j]),L(s.id,{filters:[...O,j]})}catch(O){const Y=wt("processing","filters",O);Fe(Y)}},[s,be,L,rt,Fe,ve]),Ft=u.useCallback((j,E)=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const _=s.filters??[],O=[..._];ve("filters","filter_updated",_[j],E),O[j]=E,L(s.id,{filters:O})},[s,be,L,ve]),St=u.useCallback(j=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const E=s.filters??[],_=E.filter((O,Y)=>Y!==j);ve("filters","filter_removed",E[j],null),L(s.id,{filters:_.length>0?_:void 0})},[s,be,L,ve]),sr=u.useCallback(()=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const j=s.filters??[];ve("filters","filter_cleared",j,null),L(s.id,{filters:void 0})},[s,be,L,ve]),Be=u.useCallback(j=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const E=s.filters??[];ve("filters","filter_cleared",E,j),L(s.id,{filters:j.length>0?j:void 0})},[s,be,L,ve]),Pe=u.useCallback(j=>{var Y;if(!s)return;const E=(Y=s.views)==null?void 0:Y.find(U=>U.id===j);if(!E)return;const _=E.snapshot.columnOrder,O=Hr(_,E.snapshot.grouping);L(s.id,{filters:E.snapshot.filters.length>0?[...E.snapshot.filters]:void 0,sortStack:E.snapshot.sortStack.length>0?[...E.snapshot.sortStack]:void 0,columnVisibility:{...E.snapshot.columnVisibility},columnOrder:O,columnWidths:{...E.snapshot.columnWidths},grouping:E.snapshot.grouping,activeViewId:j}),Ee(new Set),R(!1)},[s,L]),Vt=u.useCallback((j,E,_)=>{var xn;if(!(s!=null&&s.schema)||!he)return;const O=s.views??[],Y=O.filter(_o=>!_o.isDeleted).length,U=((xn=f.views)==null?void 0:xn.maxViews)??10;if(Y>=U){S(`View limit reached — you can have at most ${U} saved views. Delete an existing view to create a new one.`,"error");return}const pe={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:j,description:E||void 0,isDefault:_,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:ut,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...he}},ke=_?O.map(_o=>({..._o,isDefault:!1})):O;L(s.id,{views:[...ke,pe],activeViewId:pe.id}),S(`"${j}" view created`,"success")},[s,he,L]),st=u.useCallback(()=>{var E;if(!X||!he||X.isDefault||!s)return;const j=(E=s.views)==null?void 0:E.map(_=>_.id===X.id?{..._,snapshot:{...he}}:_);L(s.id,{views:j}),S(`"${X.name}" view updated`,"success")},[X,he,s,L]),Er=u.useCallback(j=>{var O;if(!X||!he||!s)return;const E=j??he.columnWidths,_=(O=s.views)==null?void 0:O.map(Y=>Y.id===X.id?{...Y,snapshot:{...Y.snapshot,columnVisibility:he.columnVisibility,columnOrder:he.columnOrder,columnWidths:E},updatedAt:Date.now()}:Y);L(s.id,{views:_,columnWidths:E}),S(`Column configuration saved to "${X.name}"`,"success")},[X,he,s,L]),Br=u.useCallback(j=>{var U,pe;if(!he||!s||!X)return;const E=j??he.columnWidths,_={...X,snapshot:{...X.snapshot,columnVisibility:he.columnVisibility,columnOrder:he.columnOrder,columnWidths:E},updatedAt:Date.now()},O=(U=s.views)==null?void 0:U.map(ke=>ke.id===X.id?_:{...ke,snapshot:{...ke.snapshot,columnVisibility:he.columnVisibility,columnOrder:he.columnOrder,columnWidths:E},updatedAt:Date.now()});L(s.id,{views:O,columnWidths:E});const Y=(((pe=s.views)==null?void 0:pe.length)||0)-1;S(`Column configuration saved to current view and ${Y} other view${Y===1?"":"s"}`,"success")},[he,s,X,L]),Dr=u.useCallback(()=>{H(!0)},[]),Or=u.useCallback(()=>{if(!X||!s)return;const j=X.snapshot.columnOrder,E=Hr(j,X.snapshot.grouping);L(s.id,{filters:X.snapshot.filters.length>0?[...X.snapshot.filters]:void 0,sortStack:X.snapshot.sortStack.length>0?[...X.snapshot.sortStack]:void 0,columnVisibility:{...X.snapshot.columnVisibility},columnOrder:E,columnWidths:{...X.snapshot.columnWidths},grouping:X.snapshot.grouping}),S("Changes reverted to last saved state","success")},[X,s,L]),Ar=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(O=>({...O,isDefault:O.id===j}));L(s.id,{views:E});const _=s.views.find(O=>O.id===j);_&&S(`"${_.name}" set as default view`,"success")},[s,L]),Mr=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(O=>O.id===j?{...O,isFavorite:!O.isFavorite,updatedAt:Date.now()}:O);L(s.id,{views:E});const _=s.views.find(O=>O.id===j);_&&!_.isFavorite?S(`"${_.name}" added to favorites`,"success"):_&&S(`"${_.name}" removed from favorites`,"info")},[s,L]),ar=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(U=>U.id===j?{...U,isDeleted:!0,updatedAt:Date.now()}:U),_=s.activeViewId===j,O=E.find(U=>U.isDefault&&!U.isDeleted);L(s.id,{views:E,activeViewId:_&&O?O.id:s.activeViewId,filters:_&&O?O.snapshot.filters.length>0?O.snapshot.filters:void 0:s.filters,sortStack:_&&O?O.snapshot.sortStack.length>0?O.snapshot.sortStack:void 0:s.sortStack});const Y=s.views.find(U=>U.id===j);Y&&S(`"${Y.name}" moved to Recently Deleted`,"info")},[s,L]),_r=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(O=>O.id===j?{...O,isDeleted:!1,updatedAt:Date.now()}:O);L(s.id,{views:E});const _=s.views.find(O=>O.id===j);_&&S(`"${_.name}" restored`,"success")},[s,L]),lr=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.find(ke=>ke.id===j),_=s.views.filter(ke=>!ke.isDeleted||ke.id===j);if((E==null?void 0:E.isDefault)&&_.filter(ke=>ke.isDefault).length===1){S("Cannot delete the last default view","error");return}const Y=s.views.filter(ke=>ke.id!==j),U=s.activeViewId===j,pe=Y.find(ke=>ke.isDefault&&!ke.isDeleted);L(s.id,{views:Y,activeViewId:U&&pe?pe.id:s.activeViewId,filters:U&&pe?pe.snapshot.filters.length>0?pe.snapshot.filters:void 0:s.filters,sortStack:U&&pe?pe.snapshot.sortStack.length>0?pe.snapshot.sortStack:void 0:s.sortStack}),E&&S(`"${E.name}" permanently deleted`,"success")},[s,L]),$r=u.useCallback(j=>{re(j),de(!0),R(!1)},[]),Dt=u.useCallback((j,E)=>{if(!q||!(s!=null&&s.views))return;const _=s.views.map(O=>O.id===q?{...O,name:j,description:E||void 0}:O);L(s.id,{views:_}),re(null)},[q,s,L]),_e=u.useCallback(j=>{le(j),te(!0),R(!1)},[]),at=u.useCallback(()=>{if(!Q||!(s!=null&&s.views))return;const j=s.views.filter(O=>O.id!==Q),E=s.activeViewId===Q,_=j.find(O=>O.isDefault);L(s.id,{views:j,activeViewId:E&&_?_.id:s.activeViewId,filters:E&&_?_.snapshot.filters.length>0?_.snapshot.filters:void 0:s.filters,sortStack:E&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:s.sortStack}),le(null),te(!1)},[Q,s,L]),Ot=u.useCallback(j=>{var Y;if(!(s!=null&&s.views))return;if(!(((Y=f.views)==null?void 0:Y.isAdmin)??!1)){S("Only administrators can promote views to Global.","error");return}const _=s.views.find(U=>U.id===j);if(!_)return;if(_.scope==="global"){S(`"${_.name}" is already a Global View.`,"info");return}const O=s.views.map(U=>U.id===j?{...U,scope:"global",isDefault:!0,updatedAt:Date.now()}:U.scope==="global"&&U.isDefault?{...U,isDefault:!1}:U);L(s.id,{views:O}),S(`"${_.name}" promoted to Global View and set as default.`,"success")},[s,f,L]);u.useEffect(()=>{Oe!=null&&Oe.resetPage?Oe.resetPage():nt(1)},[s==null?void 0:s.filters,$t,s==null?void 0:s.activeViewId]),u.useEffect(()=>{Oe&&Oe.currentPage!==mt&&nt(Oe.currentPage)},[Oe==null?void 0:Oe.currentPage]);const Rr=u.useCallback(j=>{Oe!=null&&Oe.goToPage&&Oe.goToPage(j),nt(j)},[Oe]),jt=u.useCallback(j=>{const E=(mt-1)*tt,_=Math.floor(E/j)+1;Ge(j),nt(_)},[mt,tt]),cr=u.useCallback((j,E)=>{if(!s)return;if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}const O={...s.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{},[j]:E};L(s.id,{columnVisibility:O})},[s,X,be,L]),Ht=u.useCallback(j=>{if(s){if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}L(s.id,{columnOrder:j})}},[s,be,L]),Ut=u.useCallback((j,E)=>{if(!s)return;if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}const O={...s.columnWidths||(X==null?void 0:X.snapshot.columnWidths)||{},[j]:E};L(s.id,{columnWidths:O})},[s,X,be,L]),I=u.useCallback(j=>{if(!s)return;const _=(s.filters??[]).filter(O=>O.column!==j);L(s.id,{filters:_.length>0?_:void 0})},[s,L]),F=u.useCallback(()=>{if(!X||!(s!=null&&s.schema))return;const j={},E=[],_={};s.schema.forEach(O=>{j[O.name]=!0,E.push(O.name),_[O.name]=170}),L(s.id,{columnVisibility:j,columnOrder:E,columnWidths:_,filters:void 0,sortStack:void 0}),S("Reset to default layout - all filters and sorts cleared","success")},[X,s,L]),ie=u.useCallback(Da(j=>{ot(j)},300),[]),we=u.useCallback(j=>{ie(j)},[ie]),ae=u.useCallback(j=>{if(!j.trim()||!s)return;const E=s.searchHistory||[],_=la(E,j);L(s.id,{searchHistory:_})},[s,L]),lt=u.useCallback(j=>{if(!s)return;const E=s.searchHistory||[],_=ca(E,j);L(s.id,{searchHistory:_})},[s,L]),Mo=u.useCallback(j=>{if(!s)return;const E=s.searchHistory||[],_=da(E,j);L(s.id,{searchHistory:_})},[s,L]),Wr=u.useCallback(j=>{const E=j==null?void 0:j.__urm_row_id__;Ee(_=>{const O=new Set(_);if(E!==void 0){const Y=Array.from(O).find(U=>(U==null?void 0:U.__urm_row_id__)===E);Y!==void 0?O.delete(Y):O.add(j)}else{const Y=JSON.stringify(j),U=Array.from(O).find(pe=>JSON.stringify(pe)===Y);U!==void 0?O.delete(U):O.add(j)}return O})},[]),rs=u.useCallback((j,E)=>{Ee(_=>{const O=new Set(_);for(const Y of E)j?O.add(Y):O.delete(Y);return O})},[]),os=u.useCallback((j,E,_)=>{Ee(O=>{const Y=new Set(O),U=Math.min(j,E),pe=Math.max(j,E);for(let ke=U;ke<=pe;ke++)_[ke]!==void 0&&Y.add(_[ke]);return Y})},[]),ns=u.useCallback(()=>{Ee(new Set)},[]),is=u.useCallback(j=>{const E=j==null?void 0:j.__urm_row_id__;Ee(_=>{const O=new Set(_);if(E!==void 0){const Y=Array.from(O).find(U=>(U==null?void 0:U.__urm_row_id__)===E);Y!==void 0&&O.delete(Y)}else O.delete(j);return O})},[]),ss=u.useCallback(j=>{if(!(s!=null&&s.uploadedData))return;const E=s.uploadedData.indexOf(j);if(E===-1)return;const _=s.favoriteRowIndices||[],Y=_.includes(E)?_.filter(U=>U!==E):[..._,E];L(s.id,{favoriteRowIndices:Y})},[s,L]),as=u.useCallback((j,E)=>{if(!(s!=null&&s.uploadedData))return;const _=s.favoriteRowIndices||[],O=j.map(U=>s.uploadedData.indexOf(U)).filter(U=>U!==-1),Y=E?[..._,...O.filter(U=>!_.includes(U))]:_.filter(U=>!O.includes(U));L(s.id,{favoriteRowIndices:Y})},[s,L]),ls=u.useCallback(()=>{if(!s)return;const j=s.favoriteRowIndices||[],E=!s.showFavoritesOnly;if(E&&j.length===0){S("No rows marked as favorite","warning");return}if(L(s.id,{showFavoritesOnly:E}),E&&Le.size>0){const _=new Set(j.map(Y=>{var U,pe;return(pe=(U=s.uploadedData)==null?void 0:U[Y])==null?void 0:pe.__urm_row_id__}).filter(Y=>Y!==void 0)),O=new Set(Array.from(Le).filter(Y=>(Y==null?void 0:Y.__urm_row_id__)!==void 0&&_.has(Y.__urm_row_id__)));Ee(O)}S(E?`Showing ${j.length} favorite row${j.length===1?"":"s"}`:"Showing all data","info")},[s,L,Le]),cs=u.useCallback(j=>{if(s){if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}if(j&&s.schema){const{validGrouping:E,invalidColumns:_}=Ti(j,s.schema);_.length>0&&S(`Removed invalid grouping columns: ${_.join(", ")}`,"warning"),rt();try{const O=s.grouping;E===null?ve("grouping","group_cleared",O,null):O?ve("grouping","group_reordered",O,E):ve("grouping","group_level_added",null,E);const Y=(X==null?void 0:X.snapshot.columnOrder)||s.columnOrder||[],U=Hr(Y,E);L(s.id,{grouping:E,columnOrder:U}),JSON.stringify(U)!==JSON.stringify(s.columnOrder)&&ve("columns","column_reordered",s.columnOrder,U),et(!1)}catch(O){const Y=wt("processing","grouping",O);Fe(Y)}}else{const E=s.grouping;ve("grouping","group_cleared",E,null);const _=(X==null?void 0:X.snapshot.columnOrder)||s.columnOrder||[];L(s.id,{grouping:j,columnOrder:[..._]}),JSON.stringify(_)!==JSON.stringify(s.columnOrder)&&ve("columns","column_reordered",s.columnOrder,_),et(!1)}}},[s,X,be,L,rt,Fe,ve]),ds=u.useCallback(j=>{if(!s)return;const E=s.grouping;if(!E)return;const _=ea(E,j);L(s.id,{grouping:_})},[s,L]),us=u.useCallback(()=>{it(!0)},[]),dr=u.useCallback(j=>{s!=null&&s.schema&&(N(!0),setTimeout(()=>{try{let E;j.scope==="visible"?E=Nt:E=s.uploadedData||[];let _;j.columnScope==="all"?(_={},s.schema.forEach(ke=>{_[ke.name]=!0})):_=s.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{};const O=s.columnOrder||(X==null?void 0:X.snapshot.columnOrder),Y=po(E,s.schema,s.filters??[],s.sortStack??[],X,_,O),U=s.name;let pe;switch(j.format){case"csv":xo(Y,U,j),pe="export_csv";break;case"excel":mo(Y,U,j),pe="export_excel";break;case"json":fo(Y,U,j),pe="export_json";break}ve("export",pe,null,{format:j.format,scope:j.scope,columnScope:j.columnScope,rowCount:E.length,viewName:(X==null?void 0:X.name)||"Default View"}),S(`Export completed successfully (${j.format.toUpperCase()})`,"success")}catch(E){const _=Pa(E,{onRetry:()=>dr(j)});S(`Export failed: ${_.message}`,{action:{label:"Retry",onClick:()=>dr(j)}});const O=Cn(s.id,ut,_,s.auditHistory||[]);L(s.id,{auditHistory:O}),qt.error("urm:report-engine","Export failed",E)}finally{N(!1)}},500))},[s,X,Nt,L,ve]),ps=u.useCallback(j=>{if(s!=null&&s.schema){if(yt&&X&&!X.isDefault){fe(j.format),ce(!0),it(!1);return}dr(j),it(!1)}},[s,X,yt,dr]),Zr=u.useCallback(j=>{dr({format:j,scope:"visible",columnScope:"visible"})},[dr]),xs=u.useCallback(()=>{se&&Zr(se),ce(!1),fe(null)},[se,Zr]),ms=u.useCallback(()=>{st(),se&&Zr(se),ce(!1),fe(null)},[st,se,Zr]),fs=u.useCallback(()=>{ce(!1),fe(null)},[]),hs=u.useCallback(j=>{!(s!=null&&s.schema)||Le.size===0||(N(!0),setTimeout(()=>{try{const E=Array.from(Le),_=po(E,s.schema,s.filters??[],s.sortStack??[],X),O=`${s.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(j){case"csv":xo(_,O);break;case"excel":mo(_,O);break;case"json":fo(_,O);break}S(`Exported ${E.length} selected rows`,"info")}catch(E){S("Export failed. Please try again.","error"),qt.error("urm:report-engine","Bulk export failed",E)}finally{N(!1)}},500))},[s,X,Le,Et]),gs=u.useCallback((j,E)=>{if(s)try{const _=Ca(s),O=wa(j,E,ut,_),Y=ka(s.presets,O);L(s.id,{presets:Y}),ve("presets","preset_created",null,{presetId:O.id,name:O.name}),Je(!1),S(`Preset "${j}" saved successfully`,"success")}catch(_){S(_ instanceof Error?_.message:"Failed to create preset","error")}},[s,L,ve]),ys=u.useCallback(()=>{zt(null),S("Exited preset view","info")},[]),bs=u.useCallback(()=>{tr(!0)},[]),vs=u.useCallback((j,E)=>{if(!s)return;const _=Ta(s.presets,j);L(s.id,{presets:_}),ve("presets","preset_deleted",{presetId:j,name:E},null),ht===j&&zt(null),S(`Preset "${E}" deleted`,"success")},[s,ht,L,ve]);u.useEffect(()=>{if(!d||p.length===0)return;const j=p.find(E=>E.id===d);j&&j.id!==b&&m(j.id)},[d,p,b]),u.useEffect(()=>{if(!s)return;const j=Ia();if(j&&s.presets&&s.schemaLocked&&s.schema){const E=jn(s.presets,j);if(E){const{sanitizedConfig:_,warnings:O}=Wa(E.config,s.schema);O.length>0&&O.forEach(U=>S(U,"warning"));const Y=za(_);L(s.id,Y),zt(j),ve("presets","preset_applied",null,{presetId:E.id,name:E.name}),S(`Loaded preset: ${E.name}`,"info")}else S("Preset not found","info")}},[s==null?void 0:s.schemaLocked]);const Ss=ht?jn(s==null?void 0:s.presets,ht):void 0;u.useEffect(()=>{s!=null&&s.views&&s.views.length>0&&s.activeViewId&&ia(s.id,{views:s.views,activeViewId:s.activeViewId})},[s==null?void 0:s.views,s==null?void 0:s.activeViewId,s==null?void 0:s.id]),u.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const j=sa(s.id);if(j&&j.views.length>0){const E=j.views.find(_=>_.id===j.activeViewId);if(E)L(s.id,{views:j.views,activeViewId:j.activeViewId,filters:E.snapshot.filters.length>0?E.snapshot.filters:void 0,sortStack:E.snapshot.sortStack.length>0?E.snapshot.sortStack:void 0});else{const _=j.views.find(O=>O.isDefault)||$o(s.schema);L(s.id,{views:j.views,activeViewId:_.id,filters:_.snapshot.filters.length>0?_.snapshot.filters:void 0,sortStack:_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0})}}}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id]);const js=u.useCallback(j=>{var O;const E=(s==null?void 0:s.filters)??[],_=((O=f.filter)==null?void 0:O.maxConditions)??3;if(E.length>=_){S(`Filter limit reached — maximum ${_} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}V(j),G(!0)},[s,f,S]),Cs=u.useCallback(()=>{G(!1),V(void 0)},[]),ws=(un=s==null?void 0:s.views)==null?void 0:un.find(j=>j.id===q),ks=(pn=s==null?void 0:s.views)==null?void 0:pn.find(j=>j.id===Q);return{reports:p,activeReport:s,activeReportId:b,setActiveReportId:m,isModalOpen:g,setIsModalOpen:z,createReport:Xe,updateReport:L,uploadState:M,handleFileUpload:Tr,handleUploadError:bt,handleRetry:We,handleConfirm:nr,paginatedData:Pt,processedData:Nt,displayData:Et,tableMetrics:kr,isGrouped:Lt,tableEngine:gt,activeView:X,isDirty:yt,currentTableState:he,viewChanges:Se,filters:s==null?void 0:s.filters,showFilterPanel:$,setShowFilterPanel:G,filterFocusColumn:A,handleAddFilter:Bt,handleUpdateFilter:Ft,handleRemoveFilter:St,handleClearAllFilters:sr,handleReplaceFilters:Be,handleOpenFilterForColumn:js,handleCloseFilterPanel:Cs,handleClearFiltersForColumn:I,sortStack:s==null?void 0:s.sortStack,showSortPanel:Z,setShowSortPanel:ee,handleSort:Ir,handleUpdateSortStack:ir,handleSortAscending:vt,handleSortDescending:zr,views:s==null?void 0:s.views,showManageViews:h,setShowManageViews:R,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:K,setShowEditViewModal:de,showDeleteConfirmation:ue,setShowDeleteConfirmation:te,editingView:ws,deletingView:ks,editingViewId:q,deletingViewId:Q,handleSelectView:Pe,handleCreateView:Vt,handleUpdateCurrentView:st,handleSaveColumnConfigToCurrentView:Er,handleSaveColumnConfigToAllViews:Br,handleSaveAsNewView:Dr,handleRevertChanges:Or,handleToggleDefault:Ar,handleToggleFavorite:Mr,handleSoftDelete:ar,handleRestoreView:_r,handlePermanentDelete:lr,handleEditView:$r,handleSaveEditView:Dt,handleDeleteView:_e,handleConfirmDelete:at,handlePromoteToGlobal:Ot,showManageColumns:J,setShowManageColumns:Me,columnVisibility:s==null?void 0:s.columnVisibility,columnOrder:s==null?void 0:s.columnOrder,columnWidths:s==null?void 0:s.columnWidths,handleUpdateColumnVisibility:cr,handleUpdateColumnOrder:Ht,handleUpdateColumnWidth:Ut,handleResetColumnLayout:F,showGroupPanel:Ne,setShowGroupPanel:et,grouping:s==null?void 0:s.grouping,groupingState:Qt,handleGroup:cs,handleToggleGroupCollapse:ds,searchQuery:$t,searchHistory:ua((s==null?void 0:s.searchHistory)||[]),handleSearchChange:we,handleAddToSearchHistory:ae,handleToggleSearchFavourite:lt,handleDeleteSearchHistory:Mo,selectedRowIds:Le,handleToggleRowSelection:Wr,handleToggleAllRows:rs,handleRangeSelection:os,handleClearSelection:ns,handleUpdateSelectionAfterDelete:is,favoriteRowIndices:(s==null?void 0:s.favoriteRowIndices)||[],resolvedFavoritesSet:Wt,showFavoritesOnly:(s==null?void 0:s.showFavoritesOnly)||!1,handleToggleRowFavorite:ss,handleBulkSetFavorites:as,handleToggleFavoritesFilter:ls,currentPage:mt,pageSize:tt,paginationEngine:Oe,handlePageChange:Rr,handlePageSizeChange:jt,isExporting:oe,showExportModal:rr,setShowExportModal:it,showDirtyExportWarning:ne,handleExport:us,handleExportWithConfig:ps,handleExportSelected:hs,handleExportAnyway:xs,handleSaveAndExport:ms,handleCancelExport:fs,showAuditHistory:ft,setShowAuditHistory:er,auditHistory:s==null?void 0:s.auditHistory,showCreatePreset:qe,setShowCreatePreset:Je,showManagePresets:$e,setShowManagePresets:tr,activePreset:Ss,activePresetId:ht,handleOpenManagePresets:bs,handleCreatePreset:gs,handleClearActivePreset:ys,handleDeletePresetById:vs,userRole:be,isViewerRole:Cr,currentUserId:ut,featureLimitWarning:vr,setFeatureLimitWarning:Rt,datasetMeta:or,reportError:Sr,setReportError:jr,handleError:Fe,schema:s==null?void 0:s.schema,hasSchemaConflicts:s!=null&&s.schema?Ys(s.schema):!1,snack:v,handleSnackClose:T,showSnack:S}}const Ii=u.createContext(void 0);function en(t){const{children:o,initialData:n,data:i,reportName:a,dataSource:c,mode:d="builder",autoLoad:l=!0,config:p,devConfig:x,showDevPanel:f=!1,sharedReportId:b}=t,g=el({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:a,sharedReportId:b,config:p}),[z,y]=u.useState(()=>zs()),C=(()=>{const T=Bs(z,x,!!x);return{...T,display:{...T.display,showDevPanel:f||T.display.showDevPanel}}})(),v=u.useCallback(S=>{y(S),Es(S)},[]),k={...g,activeDevConfig:C,handleDevConfigChange:v};return e.jsx(mi.Provider,{value:C,children:e.jsx(Ii.Provider,{value:k,children:o})})}function bo(){const t=u.useContext(Ii);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 a=o.find(c=>c.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(w.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&&a?"pointer":"default","&:hover":o.length>0&&a?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),a&&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(a.id),children:a.name}),e.jsx(r.Tooltip,{title:a.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(w.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(w.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Jt(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 ro={exports:{}},oo={exports:{}},xe={};/** @license React v16.13.1
|
|
1
|
+
"use strict";var Os=Object.defineProperty;var As=(t,o,n)=>o in t?Os(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n;var Ur=(t,o,n)=>As(t,typeof o!="symbol"?o+"":o,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),_s=require("xlsx"),T=require("@mui/icons-material"),r=require("@mui/material"),gi=require("react-dom"),Ms=require("@emotion/react"),Ot=require("react-dnd"),sn=require("react-dnd-html5-backend");function yi(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 To=yi(p),ao=yi(_s),qe={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}},bi="urm_dev_config";function $s(){try{const t=localStorage.getItem(bi);if(!t)return qe;const o=JSON.parse(t),n={sort:{...qe.sort,...o.sort},filter:{...qe.filter,...o.filter},columns:{...qe.columns,...o.columns},grouping:{...qe.grouping,...o.grouping},export:{...qe.export,...o.export},views:{...qe.views,...o.views},dates:{...qe.dates,...o.dates},display:{...qe.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return qe}}function Rs(t){try{localStorage.setItem(bi,JSON.stringify(t))}catch{}}function Ws(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 vi=p.createContext(qe);function or(){return p.useContext(vi)}const Ps=/^\d{4}-\d{2}-\d{2}$/,Ns=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Ls=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Fs=9783072e5,Vs=41024448e5,Hs=978307200,Us=4102444800;function Ys(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Fs&&t<=Vs?"timestamp_ms":Number.isInteger(t)&&t>=Hs&&t<=Us?"timestamp_s":"unknown":typeof t!="string"?"unknown":Ns.test(t)||Ps.test(t)?"iso":Ls.test(t.trim())?"locale_string":"unknown"}function Gs(t,o){const n=o.map(d=>d[t]).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 l=Ys(d);i[l]++}const a=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/a>=c)return d;return"unknown"}function qs(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 Sn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Js=["January","February","March","April","May","June","July","August","September","October","November","December"];function _e(t){return String(t).padStart(2,"0")}function Ks(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,a=Math.floor(n/1e3),c=Math.floor(a/60),d=Math.floor(c/60),l=Math.floor(d/24),u=Math.floor(l/7),m=Math.floor(l/30),f=Math.floor(l/365);let b;return a<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:u<5?b=`${u} week${u!==1?"s":""}`:m<12?b=`${m} month${m!==1?"s":""}`:b=`${f} year${f!==1?"s":""}`,a<60?b:i?`${b} ago`:`in ${b}`}function Xs(t,o){const n=t.getFullYear(),i=t.getMonth(),a=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${_e(i+1)}-${_e(a)}`;case"DD/MM/YYYY":return`${_e(a)}/${_e(i+1)}/${n}`;case"MM/DD/YYYY":return`${_e(i+1)}/${_e(a)}/${n}`;case"MMM DD, YYYY":return`${Sn[i]} ${_e(a)}, ${n}`;case"DD MMM YYYY":return`${_e(a)} ${Sn[i]} ${n}`;case"MMMM D, YYYY":return`${Js[i]} ${a}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${_e(i+1)}-${_e(a)} ${_e(c)}:${_e(d)}`;case"DD/MM/YYYY HH:mm":return`${_e(a)}/${_e(i+1)}/${n} ${_e(c)}:${_e(d)}`;case"MM/DD/YYYY HH:mm":return`${_e(i+1)}/${_e(a)}/${n} ${_e(c)}:${_e(d)}`;case"relative":return Ks(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Zs(t,o,n){if(!n||o==="unknown")return String(t);const i=qs(t,o);return!i||isNaN(i.getTime())?String(t):Xs(i,n)}function Qs(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 Si(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const a of Object.keys(t)){const c=o?`${o}.${a}`:a,d=t[a];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,Si(d,c,n+1)):i[c]=d}return i}function ho(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:Si(o))}function Yr(t){if(!Array.isArray(t)||t.length===0)return[];const o=ho(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let u=0;o.forEach(x=>{typeof x=="object"&&x!==null&&d in x&&(u++,l.add(Qs(x[d])))});const m=u===o.length,f=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const x=Array.from(l).filter(g=>g!=="null");x.length===1&&(b=x[0])}i.push({name:d,type:b,required:m,hasConflict:f})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Gs(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function ea(t){return t.some(o=>o.hasConflict)}function Ke(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 jn(t){return t==null}function ta(t){return(o,n,i)=>{const a=jn(o),c=jn(n);if(a&&c)return 0;if(a)return 1;if(c)return-1;let d=0;switch(t){case"number":const l=Number(o),u=Number(n);d=l-u;break;case"boolean":d=(o?1:0)-(n?1:0);break;case"string":d=String(o).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(o).localeCompare(String(n));break}return i==="asc"?d:-d}}function ra(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((a,c)=>a.priority-c.priority);return[...t].sort((a,c)=>{for(const d of i){const l=o.find(f=>f.name===d.column);if(!l)continue;const m=ta(l.type)(a[d.column],c[d.column],d.direction);if(m!==0)return m}return 0})}function oa(t){return t===null?"asc":t==="asc"?"desc":null}function na(t){return t==="string"||t==="boolean"}function ia(t){return t.filter(o=>na(o.type))}function sa(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const a=t.map(c=>c[i.name]).filter(c=>typeof c=="number");a.length>0&&(n[i.name]=a.reduce((c,d)=>c+d,0))}}),n}function aa(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=ji(t,n.levels,o);return Ci(i,n.collapsedGroups||[])}function ji(t,o,n,i="",a=0){if(a>=o.length)return t;const c=o[a].column,d=new Map;t.forEach(m=>{const f=m[c],b=f==null?"(empty)":String(f);d.has(b)||d.set(b,[]),d.get(b).push(m)});const l=[];return Array.from(d.keys()).sort().forEach(m=>{const f=d.get(m),b=`${c}:${m}`,x=i?`${i}|${b}`:b,g=sa(f,n),B=a<o.length-1?ji(f,o,n,x,a+1):f,y={key:x,level:a,column:c,value:m,rowCount:f.length,aggregates:g,children:B};l.push(y)}),l}function Ci(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const a=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:a}),!a&&i.children&&Ci(i.children,o,n)}else n.push(i);return n}function la(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(a=>a!==o):[...n,o];return{...t,collapsedGroups:i}}function wi(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function ki(t,o,n){return`${o}: ${n}`}function Xr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(a=>a.column),i=t.filter(a=>!n.includes(a));return[...n,...i]}function Ti(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),a=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(a);let u=0;for(const m of n)d.has(m)?c.push(m):l.has(m)&&u<a.length?(c.push(a[u]),u++):l.has(m)||c.push(m);for(let m=u;m<a.length;m++)c.includes(a[m])||c.push(a[m]);return c}return[...t]}function Ho(t){const o={},n=[],i={};return t.forEach(a=>{o[a.name]=!0,n.push(a.name),i[a.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 ca(t,o,n,i,a,c,d,l){const u={},m=[],f={};n.forEach(g=>{u[g.name]=!0,m.push(g.name),f[g.name]=170});const x=Ti(a||m,d||null,l||m);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:x,columnWidths:c||f,grouping:d||null}}function da(t,o){const n=x=>{if(x==null)return x;if(Array.isArray(x))return x.map(g=>n(g));if(typeof x=="object"){const g={};return Object.keys(x).sort().forEach(B=>{g[B]=n(x[B])}),g}return x},i=x=>JSON.stringify(n(x));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack))return!0;const a=t.columnVisibility??{},c=o.columnVisibility??{};if(i(a)!==i(c))return!0;const d=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(d!==l)return!1;const u=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==u){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const x=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==x)return!0}const f=t.columnWidths??{},b=o.columnWidths??{};return i(f)!==i(b)||i(t.grouping)!==i(o.grouping)}function ua(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function pa(t,o){var y,j,S;const n=[],i=JSON.stringify(t.filters),a=JSON.stringify(o.filters);if(i!==a){const k=t.filters.length,v=o.filters.length;k>v?n.push({category:"filters",label:"Filters Added",description:`${k-v} new filter${k-v>1?"s":""} added`}):k<v?n.push({category:"filters",label:"Filters Removed",description:`${v-k} filter${v-k>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const c=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(c!==d){const k=t.sortStack.length,v=o.sortStack.length;k>v?n.push({category:"sorting",label:"Sorting Added",description:`${k-v} new sort rule${k-v>1?"s":""} added`}):k<v?n.push({category:"sorting",label:"Sorting Removed",description:`${v-k} sort rule${v-k>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(t.columnVisibility),u=JSON.stringify(o.columnVisibility);if(l!==u){const k=Object.values(t.columnVisibility).filter(w=>w).length,v=Object.values(o.columnVisibility).filter(w=>w).length;k>v?n.push({category:"visibility",label:"Columns Shown",description:`${k-v} column${k-v>1?"s":""} made visible`}):k<v?n.push({category:"visibility",label:"Columns Hidden",description:`${v-k} column${v-k>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const m=JSON.stringify(t.columnOrder),f=JSON.stringify(o.columnOrder);m!==f&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),x=JSON.stringify(o.columnWidths);if(b!==x){const k=Object.keys(t.columnWidths).filter(v=>t.columnWidths[v]!==o.columnWidths[v]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${k} column width${k>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),B=JSON.stringify(o.grouping);if(g!==B){const k=(y=t.grouping)==null?void 0:y.enabled,v=(j=o.grouping)==null?void 0:j.enabled;if(k&&!v){const w=((S=t.grouping)==null?void 0:S.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${w} grouping level${w>1?"s":""} added`})}else!k&&v?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 Cn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function wn(t){return`[${t}]`}const tr={warn(t,o,...n){Cn()&&console.warn(wn(t),o,...n)},error(t,o,...n){Cn()&&console.error(wn(t),o,...n)}},Ii="urm_report_";function xa(t,o){try{const n=`${Ii}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){tr.error("urm:persistence","Failed to save report state",n)}}function ma(t){try{const o=`${Ii}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return tr.error("urm:persistence","Failed to load report state",o),null}}function Io(t,o,n=0){const i=[];for(const a of t){const c=o.includes(a.key);if(i.push({type:"group",key:a.key,level:n,column:a.column,value:a.value,rowCount:a.rowCount,aggregates:a.aggregates,collapsed:c}),!c&&a.children&&a.children.length>0){const d=a.children[0];if(fa(d)){const l=a.children,u=Io(l,o,n+1);i.push(...u)}else{const l=a.children;for(const u of l)i.push({type:"row",parentGroupKey:a.key,level:n+1,data:u})}}}return i}function fa(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 an(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function ln(t,o){const n=new Date,i=n.getFullYear(),a=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${a}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function vo(t,o,n,i,a,c,d){let l,u;c?(l={...c},u=d||o.map(f=>f.name)):a?(l={...a.snapshot.columnVisibility},u=d||[...a.snapshot.columnOrder]):(l={},u=[],o.forEach(f=>{l[f.name]=!0,u.push(f.name)}));const m=Object.entries(l).filter(([f,b])=>!b).map(([f,b])=>f);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:u,grouping:(a==null?void 0:a.snapshot.grouping)??null,hiddenColumns:m,viewMeta:a?{id:a.id,name:a.name,isDefault:a.isDefault}:void 0}}function So(t,o="export",n){const{data:i,columnOrder:a,grouping:c}=t,d=a.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=c.collapsedGroups??[],x=Io(i,b);l=an(x)}else l=i;const u=d.join(","),m=l.map(b=>d.map(x=>{const g=b[x];if(g==null)return"";const B=String(g);return B.includes(",")||B.includes('"')||B.includes(`
|
|
2
|
+
`)?`"${B.replace(/"/g,'""')}"`:B}).join(",")),f=[u,...m].join(`
|
|
3
|
+
`);zi(f,ln(o,"csv"),"text/csv;charset=utf-8;")}function jo(t,o="export",n){const{data:i,columnOrder:a,grouping:c}=t,d=a.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=c.collapsedGroups??[],x=Io(i,b);l=an(x)}else l=i;const u=[d,...l.map(b=>d.map(x=>b[x]??""))],m=ao.utils.aoa_to_sheet(u),f=ao.utils.book_new();ao.utils.book_append_sheet(f,m,"Data"),ao.writeFile(f,ln(o,"xlsx"))}function Co(t,o="export",n){const{data:i,appliedFilters:a,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:u,grouping:m}=t;let f;if(m&&m.enabled){const g=m.collapsedGroups??[],B=Io(i,g);f=an(B)}else f=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:a.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:m||{},hiddenColumns:l,columnOrder:u,exportConfig:n||{scope:"visible"}},data:f},x=JSON.stringify(b,null,2);zi(x,ln(o,"json"),"application/json;charset=utf-8;")}function zi(t,o,n){const i=new Blob([t],{type:n}),a=URL.createObjectURL(i),c=document.createElement("a");c.href=a,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(a)}const kn=10;function ha(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.query.toLowerCase()===n.toLowerCase());let a;return i!==-1?a=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:a=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],a.length>kn&&(a=[...a].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,kn)),a}function ga(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ya(t,o){return t.filter(n=>n.query!==o)}function ba(t){const o=t.filter(i=>i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed);return[...o,...n]}const va={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 Sa(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function ht(t,o){return va[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 ja(t){return t==="viewer"}const Tn=1e3;function tn(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 tn(n)}const Ca={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 Uo(t){if(!t||!t.column)return"a filter";const o=vt(t.column),n=Ca[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function In(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${vt(n.column)}"`).join(", ")}`}function wa(t){var a,c,d;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: ${Uo(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Uo(n)}`};case"filter_updated":{const l=n,u=i;return(l==null?void 0:l.column)!==(u==null?void 0:u.column)?{summary:`Filter changed on "${vt(u==null?void 0:u.column)}"`,detail:`Previously filtered "${vt(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Uo(u)}`}}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):"",u=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${u}`:"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: ${In(i)}`};case"group_level_removed":{const l=n,u=(c=(a=l==null?void 0:l.levels)==null?void 0:a[0])!=null&&c.column?vt(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${In(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:[],u=Array.isArray(i)?i:[];return l.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 l=(i==null?void 0:i.column)??"",u=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${vt(l)}"`:"Column resized",detail:u?`New width: ${u}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)??"",u=(i==null?void 0:i.name)??"";return l&&u?{summary:`Switched to view "${u}"`,detail:`From "${l}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="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)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:f?`${tn(m)} · View: "${f}"`:tn(m)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.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)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&u?{summary:`Theme changed from "${l}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{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:Ta(o)}}}function ka(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Bi(t,o,n,i,a,c){return{id:ka(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:a,newState:c}}function Ei(t,o){const n=[o,...t];return n.length>Tn?n.slice(0,Tn):n}function Ta(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 Ia(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function za(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),a=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return a<1?"Just now":a<60?`${a} minute${a>1?"s":""} ago`:c<24?`${c} hour${c>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const zn=100;function Ba(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ea(t){var c;const o=(c=t.views)==null?void 0:c.find(d=>d.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],a=Ti(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:a,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Da(t,o,n,i){return{id:Ba(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function Oa(t,o){const n=t||[];if(n.length>=zn)throw new Error(`Maximum of ${zn} presets reached. Please delete old presets first.`);return[...n,o]}function Aa(t,o){return(t||[]).filter(i=>i.id!==o)}function Bn(t,o){if(t)return t.find(n=>n.id===o)}function _a(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Ma(t){const o=t.columnOrder,n=Xr(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 $a(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ra={MAX_CACHE_ENTRIES:3};function Wa(t,o){let n=null;return function(...a){const c=()=>{n=null,t(...a)};n&&clearTimeout(n),n=setTimeout(c,o)}}class lo{constructor(o=Ra.MAX_CACHE_ENTRIES){Ur(this,"cache",new Map);Ur(this,"maxEntries");this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const a=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];a&&this.cache.delete(a)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Pa{constructor(){Ur(this,"metrics",new Map)}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),a=this.end(o);return{result:i,duration:a}}async measureAsync(o,n){this.start(o);const i=await n(),a=this.end(o);return{result:i,duration:a}}}function Dt(t,o,n,i){const a=n instanceof Error?n.message:n,c={type:t,context:o,message:a,details:i,timestamp:Date.now(),recoverable:Na(t,o)};return process.env.NODE_ENV==="development"&&tr.error("urm:error-handling","[Report Error]",{type:t,context:o,message:a,details:i}),c}function Na(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function La(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 Fa(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 Va(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 Ha(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 Di(t,o){const n=[],i=[],a=new Set(o.map(c=>c.name));return t.forEach(c=>{a.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function Oi(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],a=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):a.push(c.column)}),i.length===0?{validGrouping:null,invalidColumns:a}:{validGrouping:{...t,levels:i},invalidColumns:a}}function Ua(t,o){const n=[],i=new Set(o.map(c=>c.name)),a={...t};if(a.filters&&Array.isArray(a.filters)){const c=a.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});a.filters=c.length>0?c:void 0}if(a.sortStack&&Array.isArray(a.sortStack)){const{validRules:c,invalidColumns:d}=Di(a.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),a.sortStack=c.length>0?c:void 0}if(a.grouping){const{validGrouping:c,invalidColumns:d}=Oi(a.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),a.grouping=c}if(a.columnVisibility){const c={};Object.entries(a.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),a.columnVisibility=Object.keys(c).length>0?c:void 0}if(a.columnOrder&&Array.isArray(a.columnOrder)){const c=a.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});a.columnOrder=c.length>0?c:void 0}if(a.columnWidths){const c={};Object.entries(a.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),a.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:a,warnings:n}}function Ya(t,o){return Dt("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function En(t,o,n,i){const a=Bi(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Ei(i||[],a)}function Ga(t){return t==null}function qa(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Ga(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 Ja(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>qa(n[i.column],i)))}function Dn(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 co(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Ka({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:Ja(t,o),[t,o])}}function Xa(t,o,n,i){if(!n||n.trim()==="")return t;const a=n.toLowerCase().trim(),c=o.filter(d=>i.includes(d.name));return t.filter(d=>c.some(l=>{const u=d[l.name];return u==null?!1:String(u).toLowerCase().includes(a)}))}function Za({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Xa(t,n,o,i),[t,o,n,i])}}function Qa({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:ra(t,n,o),[t,o,n])}}function el({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:aa(t,n,o),[t,o,n]),a=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:a}}function tl({schema:t,columnVisibility:o,columnOrder:n}){const i=p.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),a=p.useMemo(()=>Object.entries(o).filter(([l,u])=>!u).map(([l,u])=>l),[o]),c=p.useMemo(()=>n.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[n,t]),d=p.useMemo(()=>i.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:a,allColumns:c,visibleColumnSchemas:d,hiddenCount:a.length}}function rl({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(m=>m.id===o),[t,o]),a=p.useMemo(()=>i?da(n,i.snapshot):!1,[i,n]),c=p.useMemo(()=>t.find(m=>m.isDefault),[t]),d=p.useMemo(()=>t.filter(m=>!m.isDefault&&!m.isDeleted),[t]),l=p.useMemo(()=>t.filter(m=>m.isFavorite&&!m.isDeleted),[t]),u=p.useMemo(()=>t.filter(m=>m.isDeleted),[t]);return{activeView:i,isDirty:a,defaultView:c,customViews:d,favoriteViews:l,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function ol({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[a,c]=p.useState(i),d=t.length,l=Math.ceil(d/n),u=p.useMemo(()=>{if(!o)return t;const g=(a-1)*n,B=g+n;return t.slice(g,B)},[t,o,a,n]),m=p.useCallback(g=>{const B=Math.max(1,Math.min(g,l));c(B)},[l]),f=p.useCallback(()=>{a<l&&c(a+1)},[a,l]),b=p.useCallback(()=>{a>1&&c(a-1)},[a]),x=p.useCallback(()=>{c(1)},[]);return{paginatedData:u,currentPage:a,totalPages:l,pageSize:n,totalRows:d,goToPage:m,nextPage:f,prevPage:b,resetPage:x,hasNextPage:a<l,hasPrevPage:a>1}}function nl(t){const{rawData:o,schema:n,filters:i,sortStack:a,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:u,columnWidths:m,views:f,activeViewId:b,pagination:x}=t,g=p.useMemo(()=>({filters:i,sortStack:a,grouping:c,columnVisibility:l,columnOrder:u,columnWidths:m}),[i,a,c,l,u,m]),B=rl({views:f,activeViewId:b,currentState:g}),y=tl({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:j}=Ka({data:o,filters:i}),{sortedData:S}=Qa({data:j,sortStack:a,schema:n}),{groupedData:k,isGrouped:v}=el({data:S,grouping:c,schema:n}),{searchedData:w}=Za({data:k,searchQuery:d,schema:n,visibleColumns:y.visibleColumns}),s=ol({data:w,enabled:(x==null?void 0:x.enabled)||!1,pageSize:(x==null?void 0:x.pageSize)||100,initialPage:(x==null?void 0:x.currentPage)||1}),_=x!=null&&x.enabled?s.paginatedData:w,I=p.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:S.length,groupedRows:v?k.length:S.length,searchedRows:w.length,visibleRows:_.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:a.length,isGrouped:v}),[o.length,j.length,S.length,k.length,w.length,_.length,y.hiddenCount,i.length,a.length,v]);return{data:_,filteredData:j,sortedData:S,groupedData:k,searchedData:w,viewEngine:B,columnEngine:y,paginationEngine:s,metrics:I,isGrouped:v,isPaginated:(x==null?void 0:x.enabled)||!1}}let il=0;function sl(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:il++,writable:!1,enumerable:!1,configurable:!1})}const yt="user-demo-001";function al(t={}){var hn,gn,yn,bn,vn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:a,reportName:c,sharedReportId:d,config:l={}}=t,[u,m]=p.useState([]),f=or(),[b,x]=p.useState(""),[g,B]=p.useState(!1),[y,j]=p.useState(!1),[S,k]=p.useState({message:"",severity:"info",open:!1}),v=(C,D="info")=>{k({message:C,severity:D,open:!0})},w=()=>k(C=>({...C,open:!1})),s=u.find(C=>C.id===b),[_,I]=p.useState("idle"),[R,q]=p.useState(!1),[Q,te]=p.useState(!1),[h,$]=p.useState(!1),[W,F]=p.useState(!1),[X,xe]=p.useState(!1),[me,Y]=p.useState(!1),[A,V]=p.useState(void 0),[oe,J]=p.useState(null),[ee,le]=p.useState(null),[ie,N]=p.useState(!1),[se,ce]=p.useState(!1),[ae,ge]=p.useState(null),[K,Me]=p.useState(!1),[Ue,nt]=p.useState(!1),[sr,Tr]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[Ft,ut]=p.useState(""),[Fe,Be]=p.useState(new Set),[Mt,St]=p.useState(null),[Ze,He]=p.useState(1),[Qe,ar]=p.useState(15),[et,it]=p.useState(!1),[We,lr]=p.useState(!1),[Ir,Vt]=p.useState(!1),[pt,jt]=p.useState(null),[cr,Ct]=p.useState(!1),[io,dr]=p.useState(null),[zr,wt]=p.useState(null);p.useRef(new Pa),p.useRef(new lo),p.useRef(new lo),p.useRef(new lo),p.useRef(new lo);const[st,Br]=p.useState(null),Ht=p.useRef(null),je=p.useMemo(()=>s?Sa(s.permissions,yt):"owner",[s]),Er=ja(je),ur=p.useMemo(()=>!(s!=null&&s.uploadedData)||!(s!=null&&s.schema)?{totalRows:0,totalColumns:0}:$a(s.uploadedData,s.schema),[s==null?void 0:s.uploadedData,s==null?void 0:s.schema]),at=p.useCallback(()=>{s&&(Ht.current=Fa(s))},[s]),L=p.useCallback((C,D)=>{m(M=>M.map(O=>O.id===C?{...O,...D}:O))},[]),Ye=p.useCallback(C=>{if(!s)return;Br(C);const D=En(s.id,yt,C,s.auditHistory||[]);L(s.id,{auditHistory:D}),v(C.message,"error"),C.recoverable&&Ht.current&&setTimeout(()=>{Va(s,Ht.current,L),v("Previous state restored","success")},100)},[s,L]),Ce=p.useCallback((C,D,M,O)=>{if(!s)return;const G=Bi(s.id,yt,C,D,M,O),H=s.auditHistory||[],re=Ei(H,G);setTimeout(()=>{L(s.id,{auditHistory:re})},0)},[s,L]);p.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const C=Ho(s.schema);(()=>{try{const D=localStorage.getItem("urm_dev_config");return D?JSON.parse(D):null}catch{return null}})(),L(s.id,{views:[C],activeViewId:C.id,filters:C.snapshot.filters,sortStack:C.snapshot.sortStack,columnVisibility:C.snapshot.columnVisibility,columnOrder:C.snapshot.columnOrder,columnWidths:C.snapshot.columnWidths,grouping:C.snapshot.grouping})}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id,L]),p.useEffect(()=>{if(i&&n&&!y&&u.length===0){const C=ho(i),D={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Yr(C),permissions:{owner:yt,editors:[],viewers:[]}};m([D]),x(D.id),j(!0),I("confirmed")}},[i,n,y,u.length,o,c]),p.useEffect(()=>{if(!a||y)return;let C=!1,D=null;const M=async()=>{try{I("uploading");let O;if(a.type==="api"){const H=await fetch(a.url,{headers:a.headers||{}});if(!H.ok)throw new Error(`HTTP ${H.status}: ${H.statusText}`);O=await H.json()}else O=await a.fetch();if(C)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const G=Yr(O);if(y)m(H=>H.map(re=>re.id===b?{...re,uploadedData:O}:re)),I("confirmed");else{const H={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${a.type==="api"?a.url:"callback"}`,schemaLocked:!0,uploadedData:ho(O),schema:Yr(ho(O)),permissions:{owner:yt,editors:[],viewers:[]}};m([H]),x(H.id),j(!0),I("confirmed")}}catch(O){C||(I("error"),s&&L(s.id,{uploadError:(O==null?void 0:O.message)||"Failed to load data from source"}))}};return M(),a.refreshInterval&&a.refreshInterval>0&&(D=setInterval(M,a.refreshInterval)),()=>{C=!0,D&&clearInterval(D)}},[a,c,o]);const Ve=(hn=s==null?void 0:s.views)==null?void 0:hn.find(C=>C.id===s.activeViewId),Dr=p.useMemo(()=>s!=null&&s.uploadedData?(s.uploadedData.forEach(sl),s.showFavoritesOnly?!s.favoriteRowIndices||s.favoriteRowIndices.length===0?[]:s.uploadedData.filter((C,D)=>s.favoriteRowIndices.includes(D)):s.uploadedData):[],[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),Ut=p.useMemo(()=>{var D;if(!(s!=null&&s.uploadedData)||!((D=s==null?void 0:s.favoriteRowIndices)!=null&&D.length))return new Set;const C=new Set;return s.favoriteRowIndices.forEach(M=>{const O=s.uploadedData[M];O!==void 0&&C.add(O)}),C},[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),kt=nl({rawData:Dr,schema:(s==null?void 0:s.schema)||[],filters:(s==null?void 0:s.filters)||[],sortStack:(s==null?void 0:s.sortStack)||[],grouping:(s==null?void 0:s.grouping)||null,searchQuery:Ft||"",columnVisibility:(s==null?void 0:s.columnVisibility)||(Ve==null?void 0:Ve.snapshot.columnVisibility)||{},columnOrder:(s==null?void 0:s.columnOrder)||(Ve==null?void 0:Ve.snapshot.columnOrder)||[],columnWidths:(s==null?void 0:s.columnWidths)||(Ve==null?void 0:Ve.snapshot.columnWidths)||{},views:(s==null?void 0:s.views)||[],activeViewId:(s==null?void 0:s.activeViewId)||"",pagination:{enabled:!0,pageSize:Qe,currentPage:Ze}}),{data:$t=[],searchedData:Yt=[],groupedData:Gt=[],metrics:Or={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:qt=!1,paginationEngine:$e}=kt||{},Z=((gn=kt.viewEngine)==null?void 0:gn.activeView)||Ve,Tt=((yn=kt.viewEngine)==null?void 0:yn.isDirty)||!1;p.useEffect(()=>{if(!(!Z||!s)&&!s.columnOrder){const C=Z.snapshot.columnOrder,D=Xr(C,Z.snapshot.grouping);L(s.id,{columnOrder:D})}},[s==null?void 0:s.activeViewId]);const we=p.useMemo(()=>!(s!=null&&s.schema)||!Z?null:ca(s.filters||[],s.sortStack||[],s.schema,s.columnVisibility,s.columnOrder,s.columnWidths,s.grouping,Z.snapshot.columnOrder),[s==null?void 0:s.filters,s==null?void 0:s.sortStack,s==null?void 0:s.schema,s==null?void 0:s.columnVisibility,s==null?void 0:s.columnOrder,s==null?void 0:s.columnWidths,s==null?void 0:s.grouping,Z]),ke=p.useMemo(()=>!Z||!we||!Tt?[]:pa(we,Z.snapshot),[Z,we,Tt]),lt=p.useCallback((C,D,M)=>{const O={id:`report-${Date.now()}`,name:C,description:D,schemaLocked:!1,permissions:{owner:yt,editors:[],viewers:[]}};if(M&&Array.isArray(M)&&M.length>0){const G=Yr(M),H=Ho(G);O.uploadedData=M,O.schema=G,O.schemaLocked=!0,O.views=[H],O.activeViewId=H.id,O.sortStack=H.snapshot.sortStack,O.filters=H.snapshot.filters,O.columnVisibility=H.snapshot.columnVisibility,O.columnOrder=H.snapshot.columnOrder,O.columnWidths=H.snapshot.columnWidths,O.grouping=H.snapshot.grouping}m(G=>[...G,O]),x(O.id),B(!1),I("confirmed")},[]),pr=p.useCallback(C=>{s&&(I("uploading"),setTimeout(()=>{const D=Yr(C);L(s.id,{uploadedData:C,schema:D,uploadError:void 0}),I("preview")},500))},[s,L]),xt=p.useCallback(C=>{s&&(L(s.id,{uploadError:C}),I("idle"))},[s,L]),Ge=p.useCallback(()=>{s&&(L(s.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),I("idle"))},[s,L]),xr=p.useCallback(()=>{s&&(L(s.id,{schemaLocked:!0}),I("confirmed"))},[s,L]),mr=p.useCallback(C=>{if(!s)return;if(!ht("edit_sorting",je)){v(gt("edit_sorting"),"error");return}const D=s.sortStack??[],M=D.find(O=>O.column===C);if(M){const O=oa(M.direction);if(O===null){const G=D.filter(H=>H.column!==C).map((H,re)=>({...H,priority:re+1}));L(s.id,{sortStack:G.length>0?G:void 0})}else{const G=O,H=D.map(re=>re.column===C?{...re,direction:G}:re);L(s.id,{sortStack:H})}}else{if(D.length>=f.sort.maxLevels){v(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:C,direction:"asc",priority:D.length+1};L(s.id,{sortStack:[...D,O]})}},[s,je,L]),fr=p.useCallback(C=>{if(s)if(s.schema){const{validRules:D,invalidColumns:M}=Di(C,s.schema);M.length>0&&v(`Removed invalid sort columns: ${M.join(", ")}`),at();try{L(s.id,{sortStack:D.length>0?D:void 0})}catch(O){const G=Dt("processing","sorting",O);Ye(G)}}else L(s.id,{sortStack:C.length>0?C:void 0})},[s,L,at,Ye]),It=p.useCallback(C=>{if(!s)return;const D=s.sortStack??[],M=D.find(O=>O.column===C);if(!(M&&M.direction==="asc"))if(M){const O=D.map(G=>G.column===C?{...G,direction:"asc"}:G);L(s.id,{sortStack:O})}else{if(D.length>=f.sort.maxLevels){v(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:C,direction:"asc",priority:D.length+1};L(s.id,{sortStack:[...D,O]})}},[s,L]),Ar=p.useCallback(C=>{if(!s)return;const D=s.sortStack??[],M=D.find(O=>O.column===C);if(!(M&&M.direction==="desc"))if(M){const O=D.map(G=>G.column===C?{...G,direction:"desc"}:G);L(s.id,{sortStack:O})}else{if(D.length>=f.sort.maxLevels){v(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:C,direction:"desc",priority:D.length+1};L(s.id,{sortStack:[...D,O]})}},[s,L]),Rt=p.useCallback(C=>{var M;if(!s)return;if(!ht("edit_filters",je)){v(gt("edit_filters"),"error");return}const D=(M=s.schema)==null?void 0:M.find(O=>O.name===C.column);if(D&&C.value!==void 0){const O=Ha(D.type,C.operator,C.value);if(!O.isValid){v(O.errorMessage||"Invalid filter value","error");return}}at();try{const O=s.filters??[];Ce("filters","filter_added",O,[...O,C]),L(s.id,{filters:[...O,C]})}catch(O){const G=Dt("processing","filters",O);Ye(G)}},[s,je,L,at,Ye,Ce]),Jt=p.useCallback((C,D)=>{if(!s)return;if(!ht("edit_filters",je)){v(gt("edit_filters"),"error");return}const M=s.filters??[],O=[...M];Ce("filters","filter_updated",M[C],D),O[C]=D,L(s.id,{filters:O})},[s,je,L,Ce]),tt=p.useCallback(C=>{if(!s)return;if(!ht("edit_filters",je)){v(gt("edit_filters"),"error");return}const D=s.filters??[],M=D.filter((O,G)=>G!==C);Ce("filters","filter_removed",D[C],null),L(s.id,{filters:M.length>0?M:void 0})},[s,je,L,Ce]),ct=p.useCallback(()=>{if(!s)return;if(!ht("edit_filters",je)){v(gt("edit_filters"),"error");return}const C=s.filters??[];Ce("filters","filter_cleared",C,null),L(s.id,{filters:void 0})},[s,je,L,Ce]),Pe=p.useCallback(C=>{if(!s)return;if(!ht("edit_filters",je)){v(gt("edit_filters"),"error");return}const D=s.filters??[];Ce("filters","filter_cleared",D,C),L(s.id,{filters:C.length>0?C:void 0})},[s,je,L,Ce]),mt=p.useCallback(C=>{var G;if(!s)return;const D=(G=s.views)==null?void 0:G.find(H=>H.id===C);if(!D)return;const M=D.snapshot.columnOrder,O=Xr(M,D.snapshot.grouping);L(s.id,{filters:D.snapshot.filters.length>0?[...D.snapshot.filters]:void 0,sortStack:D.snapshot.sortStack.length>0?[...D.snapshot.sortStack]:void 0,columnVisibility:{...D.snapshot.columnVisibility},columnOrder:O,columnWidths:{...D.snapshot.columnWidths},grouping:D.snapshot.grouping,activeViewId:C}),Be(new Set),$(!1)},[s,L]),hr=p.useCallback((C,D,M)=>{var Zt;if(!(s!=null&&s.schema)||!we)return;const O=s.views??[],G=O.filter(Hr=>!Hr.isDeleted).length,H=((Zt=f.views)==null?void 0:Zt.maxViews)??10;if(G>=H){v(`View limit reached — you can have at most ${H} saved views. Delete an existing view to create a new one.`,"error");return}const re={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:D||void 0,isDefault:M,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:yt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...we}},he=M?O.map(Hr=>({...Hr,isDefault:!1})):O;L(s.id,{views:[...he,re],activeViewId:re.id}),v(`"${C}" view created`,"success")},[s,we,L]),ft=p.useCallback(()=>{var D;if(!Z||!we||Z.isDefault||!s)return;const C=(D=s.views)==null?void 0:D.map(M=>M.id===Z.id?{...M,snapshot:{...we}}:M);L(s.id,{views:C}),v(`"${Z.name}" view updated`,"success")},[Z,we,s,L]),_r=p.useCallback(C=>{var O;if(!Z||!we||!s)return;const D=C??we.columnWidths,M=(O=s.views)==null?void 0:O.map(G=>G.id===Z.id?{...G,snapshot:{...G.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:D},updatedAt:Date.now()}:G);L(s.id,{views:M,columnWidths:D}),v(`Column configuration saved to "${Z.name}"`,"success")},[Z,we,s,L]),Mr=p.useCallback(C=>{var H,re;if(!we||!s||!Z)return;const D=C??we.columnWidths,M={...Z,snapshot:{...Z.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:D},updatedAt:Date.now()},O=(H=s.views)==null?void 0:H.map(he=>he.id===Z.id?M:{...he,snapshot:{...he.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:D},updatedAt:Date.now()});L(s.id,{views:O,columnWidths:D});const G=(((re=s.views)==null?void 0:re.length)||0)-1;v(`Column configuration saved to current view and ${G} other view${G===1?"":"s"}`,"success")},[we,s,Z,L]),$r=p.useCallback(()=>{F(!0)},[]),Rr=p.useCallback(()=>{if(!Z||!s)return;const C=Z.snapshot.columnOrder,D=Xr(C,Z.snapshot.grouping);L(s.id,{filters:Z.snapshot.filters.length>0?[...Z.snapshot.filters]:void 0,sortStack:Z.snapshot.sortStack.length>0?[...Z.snapshot.sortStack]:void 0,columnVisibility:{...Z.snapshot.columnVisibility},columnOrder:D,columnWidths:{...Z.snapshot.columnWidths},grouping:Z.snapshot.grouping}),v("Changes reverted to last saved state","success")},[Z,s,L]),gr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.map(O=>({...O,isDefault:O.id===C}));L(s.id,{views:D});const M=s.views.find(O=>O.id===C);M&&v(`"${M.name}" set as default view`,"success")},[s,L]),Wr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.map(O=>O.id===C?{...O,isFavorite:!O.isFavorite,updatedAt:Date.now()}:O);L(s.id,{views:D});const M=s.views.find(O=>O.id===C);M&&!M.isFavorite?v(`"${M.name}" added to favorites`,"success"):M&&v(`"${M.name}" removed from favorites`,"info")},[s,L]),Pr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.map(H=>H.id===C?{...H,isDeleted:!0,updatedAt:Date.now()}:H),M=s.activeViewId===C,O=D.find(H=>H.isDefault&&!H.isDeleted);L(s.id,{views:D,activeViewId:M&&O?O.id:s.activeViewId,filters:M&&O?O.snapshot.filters.length>0?O.snapshot.filters:void 0:s.filters,sortStack:M&&O?O.snapshot.sortStack.length>0?O.snapshot.sortStack:void 0:s.sortStack});const G=s.views.find(H=>H.id===C);G&&v(`"${G.name}" moved to Recently Deleted`,"info")},[s,L]),Nr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.map(O=>O.id===C?{...O,isDeleted:!1,updatedAt:Date.now()}:O);L(s.id,{views:D});const M=s.views.find(O=>O.id===C);M&&v(`"${M.name}" restored`,"success")},[s,L]),Wt=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.find(he=>he.id===C),M=s.views.filter(he=>!he.isDeleted||he.id===C);if((D==null?void 0:D.isDefault)&&M.filter(he=>he.isDefault).length===1){v("Cannot delete the last default view","error");return}const G=s.views.filter(he=>he.id!==C),H=s.activeViewId===C,re=G.find(he=>he.isDefault&&!he.isDeleted);L(s.id,{views:G,activeViewId:H&&re?re.id:s.activeViewId,filters:H&&re?re.snapshot.filters.length>0?re.snapshot.filters:void 0:s.filters,sortStack:H&&re?re.snapshot.sortStack.length>0?re.snapshot.sortStack:void 0:s.sortStack}),D&&v(`"${D.name}" permanently deleted`,"success")},[s,L]),yr=p.useCallback(C=>{J(C),xe(!0),$(!1)},[]),Lr=p.useCallback((C,D)=>{if(!oe||!(s!=null&&s.views))return;const M=s.views.map(O=>O.id===oe?{...O,name:C,description:D||void 0}:O);L(s.id,{views:M}),J(null)},[oe,s,L]),Kt=p.useCallback(C=>{le(C),Y(!0),$(!1)},[]),Ae=p.useCallback(()=>{if(!ee||!(s!=null&&s.views))return;const C=s.views.filter(O=>O.id!==ee),D=s.activeViewId===ee,M=C.find(O=>O.isDefault);L(s.id,{views:C,activeViewId:D&&M?M.id:s.activeViewId,filters:D&&M?M.snapshot.filters.length>0?M.snapshot.filters:void 0:s.filters,sortStack:D&&M?M.snapshot.sortStack.length>0?M.snapshot.sortStack:void 0:s.sortStack}),le(null),Y(!1)},[ee,s,L]),dt=p.useCallback(C=>{var G;if(!(s!=null&&s.views))return;if(!(((G=f.views)==null?void 0:G.isAdmin)??!1)){v("Only administrators can promote views to Global.","error");return}const M=s.views.find(H=>H.id===C);if(!M)return;if(M.scope==="global"){v(`"${M.name}" is already a Global View.`,"info");return}const O=s.views.map(H=>H.id===C?{...H,scope:"global",isDefault:!0,updatedAt:Date.now()}:H.scope==="global"&&H.isDefault?{...H,isDefault:!1}:H);L(s.id,{views:O}),v(`"${M.name}" promoted to Global View and set as default.`,"success")},[s,f,L]);p.useEffect(()=>{$e!=null&&$e.resetPage?$e.resetPage():He(1)},[s==null?void 0:s.filters,Ft,s==null?void 0:s.activeViewId]),p.useEffect(()=>{$e&&$e.currentPage!==Ze&&He($e.currentPage)},[$e==null?void 0:$e.currentPage]);const Xt=p.useCallback(C=>{$e!=null&&$e.goToPage&&$e.goToPage(C),He(C)},[$e]),Fr=p.useCallback(C=>{const D=(Ze-1)*Qe,M=Math.floor(D/C)+1;ar(C),He(M)},[Ze,Qe]),zt=p.useCallback((C,D)=>{if(!s)return;if(!ht("edit_columns",je)){v(gt("edit_columns"),"error");return}const O={...s.columnVisibility||(Z==null?void 0:Z.snapshot.columnVisibility)||{},[C]:D};L(s.id,{columnVisibility:O})},[s,Z,je,L]),ue=p.useCallback(C=>{if(s){if(!ht("edit_columns",je)){v(gt("edit_columns"),"error");return}L(s.id,{columnOrder:C})}},[s,je,L]),fe=p.useCallback((C,D)=>{if(!s)return;if(!ht("edit_columns",je)){v(gt("edit_columns"),"error");return}const O={...s.columnWidths||(Z==null?void 0:Z.snapshot.columnWidths)||{},[C]:D};L(s.id,{columnWidths:O})},[s,Z,je,L]),Re=p.useCallback(C=>{if(!s)return;const M=(s.filters??[]).filter(O=>O.column!==C);L(s.id,{filters:M.length>0?M:void 0})},[s,L]),E=p.useCallback(()=>{if(!Z||!(s!=null&&s.schema))return;const C={},D=[],M={};s.schema.forEach(O=>{C[O.name]=!0,D.push(O.name),M[O.name]=170}),L(s.id,{columnVisibility:C,columnOrder:D,columnWidths:M,filters:void 0,sortStack:void 0}),v("Reset to default layout - all filters and sorts cleared","success")},[Z,s,L]),U=p.useCallback(Wa(C=>{ut(C)},300),[]),pe=p.useCallback(C=>{U(C)},[U]),Ne=p.useCallback(C=>{if(!C.trim()||!s)return;const D=s.searchHistory||[],M=ha(D,C);L(s.id,{searchHistory:M})},[s,L]),de=p.useCallback(C=>{if(!s)return;const D=s.searchHistory||[],M=ga(D,C);L(s.id,{searchHistory:M})},[s,L]),Bt=p.useCallback(C=>{if(!s)return;const D=s.searchHistory||[],M=ya(D,C);L(s.id,{searchHistory:M})},[s,L]),Vo=p.useCallback(C=>{const D=C==null?void 0:C.__urm_row_id__;Be(M=>{const O=new Set(M);if(D!==void 0){const G=Array.from(O).find(H=>(H==null?void 0:H.__urm_row_id__)===D);G!==void 0?O.delete(G):O.add(C)}else{const G=JSON.stringify(C),H=Array.from(O).find(re=>JSON.stringify(re)===G);H!==void 0?O.delete(H):O.add(C)}return O})},[]),ls=p.useCallback((C,D)=>{Be(M=>{const O=new Set(M);for(const G of D)C?O.add(G):O.delete(G);return O})},[]),cs=p.useCallback((C,D,M)=>{Be(O=>{const G=new Set(O),H=Math.min(C,D),re=Math.max(C,D);for(let he=H;he<=re;he++)M[he]!==void 0&&G.add(M[he]);return G})},[]),ds=p.useCallback(()=>{Be(new Set),St(null)},[]),us=p.useCallback(C=>{const D=C==null?void 0:C.__urm_row_id__;Be(M=>{const O=new Set(M);if(D!==void 0){const G=Array.from(O).find(H=>(H==null?void 0:H.__urm_row_id__)===D);G!==void 0&&O.delete(G)}else O.delete(C);return O})},[]),ps=p.useCallback(C=>{if(!(s!=null&&s.uploadedData))return;const D=s.uploadedData.indexOf(C);if(D===-1)return;const M=s.favoriteRowIndices||[],G=M.includes(D)?M.filter(H=>H!==D):[...M,D];L(s.id,{favoriteRowIndices:G})},[s,L]),xs=p.useCallback((C,D)=>{if(!(s!=null&&s.uploadedData))return;const M=s.favoriteRowIndices||[],O=C.map(H=>s.uploadedData.indexOf(H)).filter(H=>H!==-1),G=D?[...M,...O.filter(H=>!M.includes(H))]:M.filter(H=>!O.includes(H));L(s.id,{favoriteRowIndices:G})},[s,L]),ms=p.useCallback(()=>{if(!s)return;const C=s.favoriteRowIndices||[],D=!s.showFavoritesOnly;if(D&&C.length===0){v("No rows marked as favorite","warning");return}if(L(s.id,{showFavoritesOnly:D}),D){if(St(new Set(Fe)),Fe.size>0){const M=new Set(C.map(G=>{var H,re;return(re=(H=s.uploadedData)==null?void 0:H[G])==null?void 0:re.__urm_row_id__}).filter(G=>G!==void 0)),O=new Set(Array.from(Fe).filter(G=>(G==null?void 0:G.__urm_row_id__)!==void 0&&M.has(G.__urm_row_id__)));Be(O)}v(`Showing ${C.length} favorite row${C.length===1?"":"s"}`,"info")}else{if(Mt!==null){const M=new Set(Array.from(Fe).map(re=>re==null?void 0:re.__urm_row_id__).filter(Boolean)),O=new Set(Array.from(Mt).map(re=>re==null?void 0:re.__urm_row_id__).filter(Boolean)),G=new Set(C.map(re=>{var he,Zt;return(Zt=(he=s.uploadedData)==null?void 0:he[re])==null?void 0:Zt.__urm_row_id__}).filter(re=>re!==void 0)),H=new Set;Array.from(Mt).forEach(re=>{const he=re==null?void 0:re.__urm_row_id__;if(he===void 0)return;const Zt=G.has(he),Hr=M.has(he);Zt&&!Hr||H.add(re)}),Array.from(Fe).forEach(re=>{const he=re==null?void 0:re.__urm_row_id__;he!==void 0&&(O.has(he)||H.add(re))}),Be(H),St(null)}v("Showing all data","info")}},[s,L,Fe,Mt]),fs=p.useCallback(C=>{if(s){if(!ht("edit_columns",je)){v(gt("edit_columns"),"error");return}if(C&&s.schema){const{validGrouping:D,invalidColumns:M}=Oi(C,s.schema);M.length>0&&v(`Removed invalid grouping columns: ${M.join(", ")}`,"warning"),at();try{const O=s.grouping;D===null?Ce("grouping","group_cleared",O,null):O?Ce("grouping","group_reordered",O,D):Ce("grouping","group_level_added",null,D);const G=(Z==null?void 0:Z.snapshot.columnOrder)||s.columnOrder||[],H=Xr(G,D);L(s.id,{grouping:D,columnOrder:H}),JSON.stringify(H)!==JSON.stringify(s.columnOrder)&&Ce("columns","column_reordered",s.columnOrder,H),nt(!1)}catch(O){const G=Dt("processing","grouping",O);Ye(G)}}else{const D=s.grouping;Ce("grouping","group_cleared",D,null);const M=(Z==null?void 0:Z.snapshot.columnOrder)||s.columnOrder||[];L(s.id,{grouping:C,columnOrder:[...M]}),JSON.stringify(M)!==JSON.stringify(s.columnOrder)&&Ce("columns","column_reordered",s.columnOrder,M),nt(!1)}}},[s,Z,je,L,at,Ye,Ce]),hs=p.useCallback(C=>{if(!s)return;const D=s.grouping;if(!D)return;const M=la(D,C);L(s.id,{grouping:M})},[s,L]),gs=p.useCallback(()=>{Ct(!0)},[]),Vr=p.useCallback(C=>{s!=null&&s.schema&&(N(!0),setTimeout(()=>{try{let D;C.scope==="visible"?D=Yt:D=s.uploadedData||[];let M;C.columnScope==="all"?(M={},(s.schema??[]).forEach(he=>{M[he.name]=!0})):M=s.columnVisibility||(Z==null?void 0:Z.snapshot.columnVisibility)||{};const O=s.columnOrder||(Z==null?void 0:Z.snapshot.columnOrder),G=vo(D,s.schema,s.filters??[],s.sortStack??[],Z,M,O),H=s.name;let re;switch(C.format){case"csv":So(G,H,C),re="export_csv";break;case"excel":jo(G,H,C),re="export_excel";break;case"json":Co(G,H,C),re="export_json";break}Ce("export",re,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:D.length,viewName:(Z==null?void 0:Z.name)||"Default View"}),v(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(D){const M=Ya(D,{onRetry:()=>Vr(C)});v(`Export failed: ${M.message}. Click Export to retry.`,"error");const O=En(s.id,yt,M,s.auditHistory||[]);L(s.id,{auditHistory:O}),tr.error("urm:report-engine","Export failed",D)}finally{N(!1)}},500))},[s,Z,Yt,L,Ce]),ys=p.useCallback(C=>{if(s!=null&&s.schema){if(Tt&&Z&&!Z.isDefault){ge(C.format),ce(!0),Ct(!1);return}Vr(C),Ct(!1)}},[s,Z,Tt,Vr]),so=p.useCallback(C=>{Vr({format:C,scope:"visible",columnScope:"visible"})},[Vr]),bs=p.useCallback(()=>{ae&&so(ae),ce(!1),ge(null)},[ae,so]),vs=p.useCallback(()=>{ft(),ae&&so(ae),ce(!1),ge(null)},[ft,ae,so]),Ss=p.useCallback(()=>{ce(!1),ge(null)},[]),js=p.useCallback(C=>{!(s!=null&&s.schema)||Fe.size===0||(N(!0),setTimeout(()=>{try{const D=Array.from(Fe),M=vo(D,s.schema,s.filters??[],s.sortStack??[],Z),O=`${s.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":So(M,O);break;case"excel":jo(M,O);break;case"json":Co(M,O);break}v(`Exported ${D.length} selected rows`,"info")}catch(D){v("Export failed. Please try again.","error"),tr.error("urm:report-engine","Bulk export failed",D)}finally{N(!1)}},500))},[s,Z,Fe,Gt]),Cs=p.useCallback((C,D)=>{if(s)try{const M=Ea(s),O=Da(C,D,yt,M),G=Oa(s.presets,O);L(s.id,{presets:G}),Ce("presets","preset_created",null,{presetId:O.id,name:O.name}),lr(!1),v(`Preset "${C}" saved successfully`,"success")}catch(M){v(M instanceof Error?M.message:"Failed to create preset","error")}},[s,L,Ce]),ws=p.useCallback(()=>{jt(null),v("Exited preset view","info")},[]),ks=p.useCallback(()=>{Vt(!0)},[]),Ts=p.useCallback((C,D)=>{if(!s)return;const M=Aa(s.presets,C);L(s.id,{presets:M}),Ce("presets","preset_deleted",{presetId:C,name:D},null),pt===C&&jt(null),v(`Preset "${D}" deleted`,"success")},[s,pt,L,Ce]);p.useEffect(()=>{if(!d||u.length===0)return;const C=u.find(D=>D.id===d);C&&C.id!==b&&x(C.id)},[d,u,b]),p.useEffect(()=>{if(!s)return;const C=_a();if(C&&s.presets&&s.schemaLocked&&s.schema){const D=Bn(s.presets,C);if(D){const{sanitizedConfig:M,warnings:O}=Ua(D.config,s.schema);O.length>0&&O.forEach(H=>v(H,"warning"));const G=Ma(M);L(s.id,G),jt(C),Ce("presets","preset_applied",null,{presetId:D.id,name:D.name}),v(`Loaded preset: ${D.name}`,"info")}else v("Preset not found","info")}},[s==null?void 0:s.schemaLocked]);const Is=pt?Bn(s==null?void 0:s.presets,pt):void 0;p.useEffect(()=>{s!=null&&s.views&&s.views.length>0&&s.activeViewId&&xa(s.id,{views:s.views,activeViewId:s.activeViewId})},[s==null?void 0:s.views,s==null?void 0:s.activeViewId,s==null?void 0:s.id]),p.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const C=ma(s.id);if(C&&C.views.length>0){const D=C.views.find(M=>M.id===C.activeViewId);if(D)L(s.id,{views:C.views,activeViewId:C.activeViewId,filters:D.snapshot.filters.length>0?D.snapshot.filters:void 0,sortStack:D.snapshot.sortStack.length>0?D.snapshot.sortStack:void 0});else{const M=C.views.find(O=>O.isDefault)||Ho(s.schema);L(s.id,{views:C.views,activeViewId:M.id,filters:M.snapshot.filters.length>0?M.snapshot.filters:void 0,sortStack:M.snapshot.sortStack.length>0?M.snapshot.sortStack:void 0})}}}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id]);const zs=p.useCallback(C=>{var O;const D=(s==null?void 0:s.filters)??[],M=((O=f.filter)==null?void 0:O.maxConditions)??3;if(D.length>=M){v(`Filter limit reached — maximum ${M} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}V(C),q(!0)},[s,f,v]),Bs=p.useCallback(()=>{q(!1),V(void 0)},[]),Es=(bn=s==null?void 0:s.views)==null?void 0:bn.find(C=>C.id===oe),Ds=(vn=s==null?void 0:s.views)==null?void 0:vn.find(C=>C.id===ee);return{reports:u,activeReport:s,activeReportId:b,setActiveReportId:x,isModalOpen:g,setIsModalOpen:B,createReport:lt,updateReport:L,uploadState:_,handleFileUpload:pr,handleUploadError:xt,handleRetry:Ge,handleConfirm:xr,paginatedData:$t,processedData:Yt,displayData:Gt,tableMetrics:Or,isGrouped:qt,tableEngine:kt,activeView:Z,isDirty:Tt,currentTableState:we,viewChanges:ke,filters:s==null?void 0:s.filters,showFilterPanel:R,setShowFilterPanel:q,filterFocusColumn:A,handleAddFilter:Rt,handleUpdateFilter:Jt,handleRemoveFilter:tt,handleClearAllFilters:ct,handleReplaceFilters:Pe,handleOpenFilterForColumn:zs,handleCloseFilterPanel:Bs,handleClearFiltersForColumn:Re,sortStack:s==null?void 0:s.sortStack,showSortPanel:Q,setShowSortPanel:te,handleSort:mr,handleUpdateSortStack:fr,handleSortAscending:It,handleSortDescending:Ar,views:s==null?void 0:s.views,showManageViews:h,setShowManageViews:$,showCreateViewModal:W,setShowCreateViewModal:F,showEditViewModal:X,setShowEditViewModal:xe,showDeleteConfirmation:me,setShowDeleteConfirmation:Y,editingView:Es,deletingView:Ds,editingViewId:oe,deletingViewId:ee,handleSelectView:mt,handleCreateView:hr,handleUpdateCurrentView:ft,handleSaveColumnConfigToCurrentView:_r,handleSaveColumnConfigToAllViews:Mr,handleSaveAsNewView:$r,handleRevertChanges:Rr,handleToggleDefault:gr,handleToggleFavorite:Wr,handleSoftDelete:Pr,handleRestoreView:Nr,handlePermanentDelete:Wt,handleEditView:yr,handleSaveEditView:Lr,handleDeleteView:Kt,handleConfirmDelete:Ae,handlePromoteToGlobal:dt,showManageColumns:K,setShowManageColumns:Me,columnVisibility:s==null?void 0:s.columnVisibility,columnOrder:s==null?void 0:s.columnOrder,columnWidths:s==null?void 0:s.columnWidths,handleUpdateColumnVisibility:zt,handleUpdateColumnOrder:ue,handleUpdateColumnWidth:fe,handleResetColumnLayout:E,showGroupPanel:Ue,setShowGroupPanel:nt,grouping:s==null?void 0:s.grouping,groupingState:sr,handleGroup:fs,handleToggleGroupCollapse:hs,searchQuery:Ft,searchHistory:ba((s==null?void 0:s.searchHistory)||[]),handleSearchChange:pe,handleAddToSearchHistory:Ne,handleToggleSearchFavourite:de,handleDeleteSearchHistory:Bt,selectedRowIds:Fe,handleToggleRowSelection:Vo,handleToggleAllRows:ls,handleRangeSelection:cs,handleClearSelection:ds,handleUpdateSelectionAfterDelete:us,favoriteRowIndices:(s==null?void 0:s.favoriteRowIndices)||[],resolvedFavoritesSet:Ut,showFavoritesOnly:(s==null?void 0:s.showFavoritesOnly)||!1,handleToggleRowFavorite:ps,handleBulkSetFavorites:xs,handleToggleFavoritesFilter:ms,currentPage:Ze,pageSize:Qe,paginationEngine:$e,handlePageChange:Xt,handlePageSizeChange:Fr,isExporting:ie,showExportModal:cr,setShowExportModal:Ct,showDirtyExportWarning:se,handleExport:gs,handleExportWithConfig:ys,handleExportSelected:js,handleExportAnyway:bs,handleSaveAndExport:vs,handleCancelExport:Ss,showAuditHistory:et,setShowAuditHistory:it,auditHistory:s==null?void 0:s.auditHistory,showCreatePreset:We,setShowCreatePreset:lr,showManagePresets:Ir,setShowManagePresets:Vt,activePreset:Is,activePresetId:pt,handleOpenManagePresets:ks,handleCreatePreset:Cs,handleClearActivePreset:ws,handleDeletePresetById:Ts,userRole:je,isViewerRole:Er,currentUserId:yt,featureLimitWarning:zr,setFeatureLimitWarning:wt,datasetMeta:ur,reportError:st,setReportError:Br,handleError:Ye,schema:s==null?void 0:s.schema,hasSchemaConflicts:s!=null&&s.schema?ea(s.schema):!1,snack:S,handleSnackClose:w,showSnack:v}}const Ai=p.createContext(void 0);function cn(t){const{children:o,initialData:n,data:i,reportName:a,dataSource:c,mode:d="builder",autoLoad:l=!0,config:u,devConfig:m,showDevPanel:f=!1,sharedReportId:b}=t,g=al({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:a,sharedReportId:b,config:u}),[B,y]=p.useState(()=>$s()),j=(()=>{const w=Ws(B,m,!!m);return{...w,display:{...w.display,showDevPanel:f||w.display.showDevPanel}}})(),S=p.useCallback(v=>{y(v),Rs(v)},[]),k={...g,activeDevConfig:j,handleDevConfigChange:S};return e.jsx(vi.Provider,{value:j,children:e.jsx(Ai.Provider,{value:k,children:o})})}function zo(){const t=p.useContext(Ai);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function ll({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const a=o.find(c=>c.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(T.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&&a?"pointer":"default","&:hover":o.length>0&&a?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),a&&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(a.id),children:a.name}),e.jsx(r.Tooltip,{title:a.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(T.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(T.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function rr(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 cl="$$material";function dl(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var uo={exports:{}},po={exports:{}},ye={};/** @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 On;function ul(){if(On)return ye;On=1;var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,a=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,x=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,B=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,k=t?Symbol.for("react.scope"):60119;function v(s){if(typeof s=="object"&&s!==null){var _=s.$$typeof;switch(_){case o:switch(s=s.type,s){case u:case m:case i:case c:case a:case b:return s;default:switch(s=s&&s.$$typeof,s){case l:case f:case B:case g:case d:return s;default:return _}}case n:return _}}}function w(s){return v(s)===m}return ye.AsyncMode=u,ye.ConcurrentMode=m,ye.ContextConsumer=l,ye.ContextProvider=d,ye.Element=o,ye.ForwardRef=f,ye.Fragment=i,ye.Lazy=B,ye.Memo=g,ye.Portal=n,ye.Profiler=c,ye.StrictMode=a,ye.Suspense=b,ye.isAsyncMode=function(s){return w(s)||v(s)===u},ye.isConcurrentMode=w,ye.isContextConsumer=function(s){return v(s)===l},ye.isContextProvider=function(s){return v(s)===d},ye.isElement=function(s){return typeof s=="object"&&s!==null&&s.$$typeof===o},ye.isForwardRef=function(s){return v(s)===f},ye.isFragment=function(s){return v(s)===i},ye.isLazy=function(s){return v(s)===B},ye.isMemo=function(s){return v(s)===g},ye.isPortal=function(s){return v(s)===n},ye.isProfiler=function(s){return v(s)===c},ye.isStrictMode=function(s){return v(s)===a},ye.isSuspense=function(s){return v(s)===b},ye.isValidElementType=function(s){return typeof s=="string"||typeof s=="function"||s===i||s===m||s===c||s===a||s===b||s===x||typeof s=="object"&&s!==null&&(s.$$typeof===B||s.$$typeof===g||s.$$typeof===d||s.$$typeof===l||s.$$typeof===f||s.$$typeof===j||s.$$typeof===S||s.$$typeof===k||s.$$typeof===y)},ye.typeOf=v,ye}var be={};/** @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 An;function pl(){return An||(An=1,process.env.NODE_ENV!=="production"&&(function(){var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,a=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,x=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,B=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,k=t?Symbol.for("react.scope"):60119;function v(K){return typeof K=="string"||typeof K=="function"||K===i||K===m||K===c||K===a||K===b||K===x||typeof K=="object"&&K!==null&&(K.$$typeof===B||K.$$typeof===g||K.$$typeof===d||K.$$typeof===l||K.$$typeof===f||K.$$typeof===j||K.$$typeof===S||K.$$typeof===k||K.$$typeof===y)}function w(K){if(typeof K=="object"&&K!==null){var Me=K.$$typeof;switch(Me){case o:var Ue=K.type;switch(Ue){case u:case m:case i:case c:case a:case b:return Ue;default:var nt=Ue&&Ue.$$typeof;switch(nt){case l:case f:case B:case g:case d:return nt;default:return Me}}case n:return Me}}}var s=u,_=m,I=l,R=d,q=o,Q=f,te=i,h=B,$=g,W=n,F=c,X=a,xe=b,me=!1;function Y(K){return me||(me=!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.")),A(K)||w(K)===u}function A(K){return w(K)===m}function V(K){return w(K)===l}function oe(K){return w(K)===d}function J(K){return typeof K=="object"&&K!==null&&K.$$typeof===o}function ee(K){return w(K)===f}function le(K){return w(K)===i}function ie(K){return w(K)===B}function N(K){return w(K)===g}function se(K){return w(K)===n}function ce(K){return w(K)===c}function ae(K){return w(K)===a}function ge(K){return w(K)===b}be.AsyncMode=s,be.ConcurrentMode=_,be.ContextConsumer=I,be.ContextProvider=R,be.Element=q,be.ForwardRef=Q,be.Fragment=te,be.Lazy=h,be.Memo=$,be.Portal=W,be.Profiler=F,be.StrictMode=X,be.Suspense=xe,be.isAsyncMode=Y,be.isConcurrentMode=A,be.isContextConsumer=V,be.isContextProvider=oe,be.isElement=J,be.isForwardRef=ee,be.isFragment=le,be.isLazy=ie,be.isMemo=N,be.isPortal=se,be.isProfiler=ce,be.isStrictMode=ae,be.isSuspense=ge,be.isValidElementType=v,be.typeOf=w})()),be}var _n;function _i(){return _n||(_n=1,process.env.NODE_ENV==="production"?po.exports=ul():po.exports=pl()),po.exports}/*
|
|
18
18
|
object-assign
|
|
19
19
|
(c) Sindre Sorhus
|
|
20
20
|
@license MIT
|
|
21
|
-
*/var
|
|
22
|
-
Valid keys: `+JSON.stringify(Object.keys(A),null," "));var
|
|
21
|
+
*/var Yo,Mn;function xl(){if(Mn)return Yo;Mn=1;var t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(c){if(c==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(c)}function a(){try{if(!Object.assign)return!1;var c=new String("abc");if(c[5]="de",Object.getOwnPropertyNames(c)[0]==="5")return!1;for(var d={},l=0;l<10;l++)d["_"+String.fromCharCode(l)]=l;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 Yo=a()?Object.assign:function(c,d){for(var l,u=i(c),m,f=1;f<arguments.length;f++){l=Object(arguments[f]);for(var b in l)o.call(l,b)&&(u[b]=l[b]);if(t){m=t(l);for(var x=0;x<m.length;x++)n.call(l,m[x])&&(u[m[x]]=l[m[x]])}}return u},Yo}var Go,$n;function dn(){if($n)return Go;$n=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Go=t,Go}var qo,Rn;function Mi(){return Rn||(Rn=1,qo=Function.call.bind(Object.prototype.hasOwnProperty)),qo}var Jo,Wn;function ml(){if(Wn)return Jo;Wn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=dn(),n={},i=Mi();t=function(c){var d="Warning: "+c;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function a(c,d,l,u,m){if(process.env.NODE_ENV!=="production"){for(var f in c)if(i(c,f)){var b;try{if(typeof c[f]!="function"){var x=Error((u||"React class")+": "+l+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof c[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}b=c[f](d,f,u,l,null,o)}catch(B){b=B}if(b&&!(b instanceof Error)&&t((u||"React class")+": type specification of "+l+" `"+f+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof b+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),b instanceof Error&&!(b.message in n)){n[b.message]=!0;var g=m?m():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return a.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Jo=a,Jo}var Ko,Pn;function fl(){if(Pn)return Ko;Pn=1;var t=_i(),o=xl(),n=dn(),i=Mi(),a=ml(),c=function(){};process.env.NODE_ENV!=="production"&&(c=function(l){var u="Warning: "+l;typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}});function d(){return null}return Ko=function(l,u){var m=typeof Symbol=="function"&&Symbol.iterator,f="@@iterator";function b(A){var V=A&&(m&&A[m]||A[f]);if(typeof V=="function")return V}var x="<<anonymous>>",g={array:S("array"),bigint:S("bigint"),bool:S("boolean"),func:S("function"),number:S("number"),object:S("object"),string:S("string"),symbol:S("symbol"),any:k(),arrayOf:v,element:w(),elementType:s(),instanceOf:_,node:Q(),objectOf:R,oneOf:I,oneOfType:q,shape:h,exact:$};function B(A,V){return A===V?A!==0||1/A===1/V:A!==A&&V!==V}function y(A,V){this.message=A,this.data=V&&typeof V=="object"?V:{},this.stack=""}y.prototype=Error.prototype;function j(A){if(process.env.NODE_ENV!=="production")var V={},oe=0;function J(le,ie,N,se,ce,ae,ge){if(se=se||x,ae=ae||N,ge!==n){if(u){var K=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 K.name="Invariant Violation",K}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var Me=se+":"+N;!V[Me]&&oe<3&&(c("You are manually calling a React.PropTypes validation function for the `"+ae+"` prop on `"+se+"`. 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."),V[Me]=!0,oe++)}}return ie[N]==null?le?ie[N]===null?new y("The "+ce+" `"+ae+"` is marked as required "+("in `"+se+"`, but its value is `null`.")):new y("The "+ce+" `"+ae+"` is marked as required in "+("`"+se+"`, but its value is `undefined`.")):null:A(ie,N,se,ce,ae)}var ee=J.bind(null,!1);return ee.isRequired=J.bind(null,!0),ee}function S(A){function V(oe,J,ee,le,ie,N){var se=oe[J],ce=X(se);if(ce!==A){var ae=xe(se);return new y("Invalid "+le+" `"+ie+"` of type "+("`"+ae+"` supplied to `"+ee+"`, expected ")+("`"+A+"`."),{expectedType:A})}return null}return j(V)}function k(){return j(d)}function v(A){function V(oe,J,ee,le,ie){if(typeof A!="function")return new y("Property `"+ie+"` of component `"+ee+"` has invalid PropType notation inside arrayOf.");var N=oe[J];if(!Array.isArray(N)){var se=X(N);return new y("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected an array."))}for(var ce=0;ce<N.length;ce++){var ae=A(N,ce,ee,le,ie+"["+ce+"]",n);if(ae instanceof Error)return ae}return null}return j(V)}function w(){function A(V,oe,J,ee,le){var ie=V[oe];if(!l(ie)){var N=X(ie);return new y("Invalid "+ee+" `"+le+"` of type "+("`"+N+"` supplied to `"+J+"`, expected a single ReactElement."))}return null}return j(A)}function s(){function A(V,oe,J,ee,le){var ie=V[oe];if(!t.isValidElementType(ie)){var N=X(ie);return new y("Invalid "+ee+" `"+le+"` of type "+("`"+N+"` supplied to `"+J+"`, expected a single ReactElement type."))}return null}return j(A)}function _(A){function V(oe,J,ee,le,ie){if(!(oe[J]instanceof A)){var N=A.name||x,se=Y(oe[J]);return new y("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected ")+("instance of `"+N+"`."))}return null}return j(V)}function I(A){if(!Array.isArray(A))return process.env.NODE_ENV!=="production"&&(arguments.length>1?c("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])."):c("Invalid argument supplied to oneOf, expected an array.")),d;function V(oe,J,ee,le,ie){for(var N=oe[J],se=0;se<A.length;se++)if(B(N,A[se]))return null;var ce=JSON.stringify(A,function(ge,K){var Me=xe(K);return Me==="symbol"?String(K):K});return new y("Invalid "+le+" `"+ie+"` of value `"+String(N)+"` "+("supplied to `"+ee+"`, expected one of "+ce+"."))}return j(V)}function R(A){function V(oe,J,ee,le,ie){if(typeof A!="function")return new y("Property `"+ie+"` of component `"+ee+"` has invalid PropType notation inside objectOf.");var N=oe[J],se=X(N);if(se!=="object")return new y("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected an object."));for(var ce in N)if(i(N,ce)){var ae=A(N,ce,ee,le,ie+"."+ce,n);if(ae instanceof Error)return ae}return null}return j(V)}function q(A){if(!Array.isArray(A))return process.env.NODE_ENV!=="production"&&c("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var V=0;V<A.length;V++){var oe=A[V];if(typeof oe!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+me(oe)+" at index "+V+"."),d}function J(ee,le,ie,N,se){for(var ce=[],ae=0;ae<A.length;ae++){var ge=A[ae],K=ge(ee,le,ie,N,se,n);if(K==null)return null;K.data&&i(K.data,"expectedType")&&ce.push(K.data.expectedType)}var Me=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new y("Invalid "+N+" `"+se+"` supplied to "+("`"+ie+"`"+Me+"."))}return j(J)}function Q(){function A(V,oe,J,ee,le){return W(V[oe])?null:new y("Invalid "+ee+" `"+le+"` supplied to "+("`"+J+"`, expected a ReactNode."))}return j(A)}function te(A,V,oe,J,ee){return new y((A||"React class")+": "+V+" type `"+oe+"."+J+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ee+"`.")}function h(A){function V(oe,J,ee,le,ie){var N=oe[J],se=X(N);if(se!=="object")return new y("Invalid "+le+" `"+ie+"` of type `"+se+"` "+("supplied to `"+ee+"`, expected `object`."));for(var ce in A){var ae=A[ce];if(typeof ae!="function")return te(ee,le,ie,ce,xe(ae));var ge=ae(N,ce,ee,le,ie+"."+ce,n);if(ge)return ge}return null}return j(V)}function $(A){function V(oe,J,ee,le,ie){var N=oe[J],se=X(N);if(se!=="object")return new y("Invalid "+le+" `"+ie+"` of type `"+se+"` "+("supplied to `"+ee+"`, expected `object`."));var ce=o({},oe[J],A);for(var ae in ce){var ge=A[ae];if(i(A,ae)&&typeof ge!="function")return te(ee,le,ie,ae,xe(ge));if(!ge)return new y("Invalid "+le+" `"+ie+"` key `"+ae+"` supplied to `"+ee+"`.\nBad object: "+JSON.stringify(oe[J],null," ")+`
|
|
22
|
+
Valid keys: `+JSON.stringify(Object.keys(A),null," "));var K=ge(N,ae,ee,le,ie+"."+ae,n);if(K)return K}return null}return j(V)}function W(A){switch(typeof A){case"number":case"string":case"undefined":return!0;case"boolean":return!A;case"object":if(Array.isArray(A))return A.every(W);if(A===null||l(A))return!0;var V=b(A);if(V){var oe=V.call(A),J;if(V!==A.entries){for(;!(J=oe.next()).done;)if(!W(J.value))return!1}else for(;!(J=oe.next()).done;){var ee=J.value;if(ee&&!W(ee[1]))return!1}}else return!1;return!0;default:return!1}}function F(A,V){return A==="symbol"?!0:V?V["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&V instanceof Symbol:!1}function X(A){var V=typeof A;return Array.isArray(A)?"array":A instanceof RegExp?"object":F(V,A)?"symbol":V}function xe(A){if(typeof A>"u"||A===null)return""+A;var V=X(A);if(V==="object"){if(A instanceof Date)return"date";if(A instanceof RegExp)return"regexp"}return V}function me(A){var V=xe(A);switch(V){case"array":case"object":return"an "+V;case"boolean":case"date":case"regexp":return"a "+V;default:return V}}function Y(A){return!A.constructor||!A.constructor.name?x:A.constructor.name}return g.checkPropTypes=a,g.resetWarningCache=a.resetWarningCache,g.PropTypes=g,g},Ko}var Xo,Nn;function hl(){if(Nn)return Xo;Nn=1;var t=dn();function o(){}function n(){}return n.resetWarningCache=o,Xo=function(){function i(d,l,u,m,f,b){if(b!==t){var x=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 x.name="Invariant Violation",x}}i.isRequired=i;function a(){return i}var c={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:a,element:i,elementType:i,instanceOf:a,node:i,objectOf:a,oneOf:a,oneOfType:a,shape:a,exact:a,checkPropTypes:n,resetWarningCache:o};return c.PropTypes=c,c},Xo}var Ln;function gl(){if(Ln)return uo.exports;if(Ln=1,process.env.NODE_ENV!=="production"){var t=_i(),o=!0;uo.exports=fl()(t.isElement,o)}else uo.exports=hl()();return uo.exports}var yl=gl();const Gr=dl(yl);var xo={exports:{}},Te={};/**
|
|
23
23
|
* @license React
|
|
24
24
|
* react-is.production.js
|
|
25
25
|
*
|
|
@@ -27,7 +27,7 @@ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var J=fe(N,se,Q,le,oe+".
|
|
|
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 Fn;function bl(){if(Fn)return Te;Fn=1;var t=Symbol.for("react.transitional.element"),o=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),d=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),x=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function B(y){if(typeof y=="object"&&y!==null){var j=y.$$typeof;switch(j){case t:switch(y=y.type,y){case n:case a:case i:case u:case m:case x:return y;default:switch(y=y&&y.$$typeof,y){case d:case l:case b:case f:return y;case c:return y;default:return j}}case o:return j}}}return Te.ContextConsumer=c,Te.ContextProvider=d,Te.Element=t,Te.ForwardRef=l,Te.Fragment=n,Te.Lazy=b,Te.Memo=f,Te.Portal=o,Te.Profiler=a,Te.StrictMode=i,Te.Suspense=u,Te.SuspenseList=m,Te.isContextConsumer=function(y){return B(y)===c},Te.isContextProvider=function(y){return B(y)===d},Te.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},Te.isForwardRef=function(y){return B(y)===l},Te.isFragment=function(y){return B(y)===n},Te.isLazy=function(y){return B(y)===b},Te.isMemo=function(y){return B(y)===f},Te.isPortal=function(y){return B(y)===o},Te.isProfiler=function(y){return B(y)===a},Te.isStrictMode=function(y){return B(y)===i},Te.isSuspense=function(y){return B(y)===u},Te.isSuspenseList=function(y){return B(y)===m},Te.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===a||y===i||y===u||y===m||typeof y=="object"&&y!==null&&(y.$$typeof===b||y.$$typeof===f||y.$$typeof===d||y.$$typeof===c||y.$$typeof===l||y.$$typeof===g||y.getModuleId!==void 0)},Te.typeOf=B,Te}var Ie={};/**
|
|
31
31
|
* @license React
|
|
32
32
|
* react-is.development.js
|
|
33
33
|
*
|
|
@@ -35,16 +35,16 @@ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var J=fe(N,se,Q,le,oe+".
|
|
|
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,a]=n,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(a).up(c)}function
|
|
38
|
+
*/var Vn;function vl(){return Vn||(Vn=1,process.env.NODE_ENV!=="production"&&(function(){function t(y){if(typeof y=="object"&&y!==null){var j=y.$$typeof;switch(j){case o:switch(y=y.type,y){case i:case c:case a:case m:case f:case g:return y;default:switch(y=y&&y.$$typeof,y){case l:case u:case x:case b:return y;case d:return y;default:return j}}case n:return j}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),B=Symbol.for("react.client.reference");Ie.ContextConsumer=d,Ie.ContextProvider=l,Ie.Element=o,Ie.ForwardRef=u,Ie.Fragment=i,Ie.Lazy=x,Ie.Memo=b,Ie.Portal=n,Ie.Profiler=c,Ie.StrictMode=a,Ie.Suspense=m,Ie.SuspenseList=f,Ie.isContextConsumer=function(y){return t(y)===d},Ie.isContextProvider=function(y){return t(y)===l},Ie.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===o},Ie.isForwardRef=function(y){return t(y)===u},Ie.isFragment=function(y){return t(y)===i},Ie.isLazy=function(y){return t(y)===x},Ie.isMemo=function(y){return t(y)===b},Ie.isPortal=function(y){return t(y)===n},Ie.isProfiler=function(y){return t(y)===c},Ie.isStrictMode=function(y){return t(y)===a},Ie.isSuspense=function(y){return t(y)===m},Ie.isSuspenseList=function(y){return t(y)===f},Ie.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===i||y===c||y===a||y===m||y===f||typeof y=="object"&&y!==null&&(y.$$typeof===x||y.$$typeof===b||y.$$typeof===l||y.$$typeof===d||y.$$typeof===u||y.$$typeof===B||y.getModuleId!==void 0)},Ie.typeOf=t})()),Ie}var Hn;function Sl(){return Hn||(Hn=1,process.env.NODE_ENV==="production"?xo.exports=bl():xo.exports=vl()),xo.exports}var $i=Sl();function Pt(t){if(typeof t!="object"||t===null)return!1;const o=Object.getPrototypeOf(t);return(o===null||o===Object.prototype||Object.getPrototypeOf(o)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function Ri(t){if(To.isValidElement(t)||$i.isValidElementType(t)||!Pt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Ri(t[n])}),o}function Xe(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Pt(t)&&Pt(o)&&Object.keys(o).forEach(a=>{To.isValidElement(o[a])||$i.isValidElementType(o[a])?i[a]=o[a]:Pt(o[a])&&Object.prototype.hasOwnProperty.call(t,a)&&Pt(t[a])?i[a]=Xe(t[a],o[a],n):n.clone?i[a]=Pt(o[a])?Ri(o[a]):o[a]:i[a]=o[a]}),i}const jl=t=>{const o=Object.keys(t).map(n=>({key:n,val:t[n]}))||[];return o.sort((n,i)=>n.val-i.val),o.reduce((n,i)=>({...n,[i.key]:i.val}),{})};function Cl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...a}=t,c=jl(o),d=Object.keys(c);function l(x){return`@media (min-width:${typeof o[x]=="number"?o[x]:x}${n})`}function u(x){return`@media (max-width:${(typeof o[x]=="number"?o[x]:x)-i/100}${n})`}function m(x,g){const B=d.indexOf(g);return`@media (min-width:${typeof o[x]=="number"?o[x]:x}${n}) and (max-width:${(B!==-1&&typeof o[d[B]]=="number"?o[d[B]]:g)-i/100}${n})`}function f(x){return d.indexOf(x)+1<d.length?m(x,d[d.indexOf(x)+1]):l(x)}function b(x){const g=d.indexOf(x);return g===0?l(d[1]):g===d.length-1?u(d[g]):m(x,d[d.indexOf(x)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:u,between:m,only:f,not:b,unit:n,...a}}function Un(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,a)=>{var d,l;const c=/min-width:\s*([0-9.]+)/;return+(((d=i.match(c))==null?void 0:d[1])||0)-+(((l=a.match(c))==null?void 0:l[1])||0)});return n.length?n.reduce((i,a)=>{const c=o[a];return delete i[a],i[a]=c,i},{...o}):o}function wl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function kl(t,o){const n=o.match(/^@([^/]+)?\/?(.+)?$/);if(!n){if(process.env.NODE_ENV!=="production")throw new Error(`MUI: The provided shorthand ${`(${o})`} 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,a]=n,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(a).up(c)}function Tl(t){const o=(c,d)=>c.replace("@media",d?`@container ${d}`:"@container");function n(c,d){c.up=(...l)=>o(t.breakpoints.up(...l),d),c.down=(...l)=>o(t.breakpoints.down(...l),d),c.between=(...l)=>o(t.breakpoints.between(...l),d),c.only=(...l)=>o(t.breakpoints.only(...l),d),c.not=(...l)=>{const u=o(t.breakpoints.not(...l),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={},a=c=>(n(i,c),i);return n(a),{...t,containerQueries:a}}const Il={borderRadius:4},Lt=process.env.NODE_ENV!=="production"?Gr.oneOfType([Gr.number,Gr.string,Gr.object,Gr.array]):{};function to(t,o){return o?Xe(t,o,{clone:!1}):t}const Bo={xs:0,sm:600,md:900,lg:1200,xl:1536},Yn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${Bo[t]}px)`},zl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:Bo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function At(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Yn;return o.reduce((d,l,u)=>(d[c.up(c.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Yn;return Object.keys(o).reduce((d,l)=>{if(wl(c.keys,l)){const u=kl(i.containerQueries?i:zl,l);u&&(d[u]=n(o[l],l))}else if(Object.keys(c.values||Bo).includes(l)){const u=c.up(l);d[u]=n(o[l],l)}else{const u=l;d[u]=o[u]}return d},{})}return n(o)}function Bl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,a)=>{const c=t.up(a);return i[c]={},i},{}))||{}}function Gn(t,o){return t.reduce((n,i)=>{const a=n[i];return(!a||Object.keys(a).length===0)&&delete n[i],n},o)}function Wi(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":rr(7));return t.charAt(0).toUpperCase()+t.slice(1)}function Eo(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((a,c)=>a&&a[c]?a[c]:null,t);if(i!=null)return i}return o.split(".").reduce((i,a)=>i&&i[a]!=null?i[a]:null,t)}function wo(t,o,n,i=n){let a;return typeof t=="function"?a=t(n):Array.isArray(t)?a=t[n]||i:a=Eo(t,n)||i,o&&(a=o(a,i,t)),a}function Oe(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:a}=t,c=d=>{if(d[o]==null)return null;const l=d[o],u=d.theme,m=Eo(u,i)||{};return At(d,l,b=>{let x=wo(m,a,b);return b===x&&typeof b=="string"&&(x=wo(m,a,`${o}${b==="default"?"":Wi(b)}`,b)),n===!1?x:{[n]:x}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Lt}:{},c.filterProps=[o],c}function El(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const Dl={m:"margin",p:"padding"},Ol={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},qn={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},Al=El(t=>{if(t.length>2)if(qn[t])t=qn[t];else return[t];const[o,n]=t.split(""),i=Dl[o],a=Ol[n]||"";return Array.isArray(a)?a.map(c=>i+c):[i+a]}),Do=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],Oo=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],_l=[...Do,...Oo];function oo(t,o,n,i){const a=Eo(t,o,!0)??n;return typeof a=="number"||typeof a=="string"?c=>typeof c=="string"?c:(process.env.NODE_ENV!=="production"&&typeof c!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${c}.`),typeof a=="string"?a.startsWith("var(")&&c===0?0:a.startsWith("var(")&&c===1?a:`calc(${c} * ${a})`:a*c):Array.isArray(a)?c=>{if(typeof c=="string")return c;const d=Math.abs(c);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>a.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(a)}.`,`${d} > ${a.length-1}, you need to add the missing values.`].join(`
|
|
40
40
|
`)):console.error([`MUI: The \`theme.${o}\` 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.${o}\` as a number.`].join(`
|
|
41
41
|
`)));const l=a[d];return c>=0?l:typeof l=="number"?-l:typeof l=="string"&&l.startsWith("var(")?`calc(-1 * ${l})`:`-${l}`}:typeof a=="function"?a:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${o}\` value (${a}) is invalid.`,"It should be a number, an array or a function."].join(`
|
|
42
|
-
`)),()=>{})}function rn(t){return Kr(t,"spacing",8,"spacing")}function Xr(t,o){return typeof o=="string"||o==null?o:t(o)}function zl(t,o){return n=>t.reduce((i,a)=>(i[a]=Xr(o,n),i),{})}function El(t,o,n,i){if(!o.includes(n))return null;const a=Tl(n),c=zl(a,i),d=t[n];return Tt(t,d,c)}function Ai(t,o){const n=rn(t.theme);return Object.keys(t).map(i=>El(t,o,i,n)).reduce(qr,{})}function Ie(t){return Ai(t,jo)}Ie.propTypes=process.env.NODE_ENV!=="production"?jo.reduce((t,o)=>(t[o]=_t,t),{}):{};Ie.filterProps=jo;function ze(t){return Ai(t,Co)}ze.propTypes=process.env.NODE_ENV!=="production"?Co.reduce((t,o)=>(t[o]=_t,t),{}):{};ze.filterProps=Co;process.env.NODE_ENV!=="production"&&Il.reduce((t,o)=>(t[o]=_t,t),{});function Mi(t=8,o=rn({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(c=>{const d=o(c);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function wo(...t){const o=t.reduce((i,a)=>(a.filterProps.forEach(c=>{i[c]=a}),i),{}),n=i=>Object.keys(i).reduce((a,c)=>o[c]?qr(a,o[c](i)):a,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,a)=>Object.assign(i,a.propTypes),{}):{},n.filterProps=t.reduce((i,a)=>i.concat(a.filterProps),[]),n}function Ze(t){return typeof t!="number"?t:`${t}px solid`}function Qe(t,o){return De({prop:t,themeKey:"borders",transform:o})}const Bl=Qe("border",Ze),Dl=Qe("borderTop",Ze),Ol=Qe("borderRight",Ze),Al=Qe("borderBottom",Ze),Ml=Qe("borderLeft",Ze),_l=Qe("borderColor"),$l=Qe("borderTopColor"),Rl=Qe("borderRightColor"),Wl=Qe("borderBottomColor"),Pl=Qe("borderLeftColor"),Nl=Qe("outline",Ze),Ll=Qe("outlineColor"),ko=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=Kr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Xr(o,i)});return Tt(t,t.borderRadius,n)}return null};ko.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:_t}:{};ko.filterProps=["borderRadius"];wo(Bl,Dl,Ol,Al,Ml,_l,$l,Rl,Wl,Pl,ko,Nl,Ll);const To=t=>{if(t.gap!==void 0&&t.gap!==null){const o=Kr(t.theme,"spacing",8,"gap"),n=i=>({gap:Xr(o,i)});return Tt(t,t.gap,n)}return null};To.propTypes=process.env.NODE_ENV!=="production"?{gap:_t}:{};To.filterProps=["gap"];const Io=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=Kr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Xr(o,i)});return Tt(t,t.columnGap,n)}return null};Io.propTypes=process.env.NODE_ENV!=="production"?{columnGap:_t}:{};Io.filterProps=["columnGap"];const zo=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=Kr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Xr(o,i)});return Tt(t,t.rowGap,n)}return null};zo.propTypes=process.env.NODE_ENV!=="production"?{rowGap:_t}:{};zo.filterProps=["rowGap"];const Fl=De({prop:"gridColumn"}),Vl=De({prop:"gridRow"}),Hl=De({prop:"gridAutoFlow"}),Ul=De({prop:"gridAutoColumns"}),Yl=De({prop:"gridAutoRows"}),Gl=De({prop:"gridTemplateColumns"}),ql=De({prop:"gridTemplateRows"}),Jl=De({prop:"gridTemplateAreas"}),Kl=De({prop:"gridArea"});wo(To,Io,zo,Fl,Vl,Hl,Ul,Yl,Gl,ql,Jl,Kl);function hr(t,o){return o==="grey"?o:t}const Xl=De({prop:"color",themeKey:"palette",transform:hr}),Zl=De({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:hr}),Ql=De({prop:"backgroundColor",themeKey:"palette",transform:hr});wo(Xl,Zl,Ql);function He(t){return t<=1&&t!==0?`${t*100}%`:t}const ec=De({prop:"width",transform:He}),on=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var a,c,d,l,p;const i=((d=(c=(a=t.theme)==null?void 0:a.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||vo[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:He(n)}};return Tt(t,t.maxWidth,o)}return null};on.filterProps=["maxWidth"];const tc=De({prop:"minWidth",transform:He}),rc=De({prop:"height",transform:He}),oc=De({prop:"maxHeight",transform:He}),nc=De({prop:"minHeight",transform:He});De({prop:"size",cssProperty:"width",transform:He});De({prop:"size",cssProperty:"height",transform:He});const ic=De({prop:"boxSizing"});wo(ec,on,tc,rc,oc,nc,ic);const Eo={border:{themeKey:"borders",transform:Ze},borderTop:{themeKey:"borders",transform:Ze},borderRight:{themeKey:"borders",transform:Ze},borderBottom:{themeKey:"borders",transform:Ze},borderLeft:{themeKey:"borders",transform:Ze},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Ze},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:ko},color:{themeKey:"palette",transform:hr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:hr},backgroundColor:{themeKey:"palette",transform:hr},p:{style:ze},pt:{style:ze},pr:{style:ze},pb:{style:ze},pl:{style:ze},px:{style:ze},py:{style:ze},padding:{style:ze},paddingTop:{style:ze},paddingRight:{style:ze},paddingBottom:{style:ze},paddingLeft:{style:ze},paddingX:{style:ze},paddingY:{style:ze},paddingInline:{style:ze},paddingInlineStart:{style:ze},paddingInlineEnd:{style:ze},paddingBlock:{style:ze},paddingBlockStart:{style:ze},paddingBlockEnd:{style:ze},m:{style:Ie},mt:{style:Ie},mr:{style:Ie},mb:{style:Ie},ml:{style:Ie},mx:{style:Ie},my:{style:Ie},margin:{style:Ie},marginTop:{style:Ie},marginRight:{style:Ie},marginBottom:{style:Ie},marginLeft:{style:Ie},marginX:{style:Ie},marginY:{style:Ie},marginInline:{style:Ie},marginInlineStart:{style:Ie},marginInlineEnd:{style:Ie},marginBlock:{style:Ie},marginBlockStart:{style:Ie},marginBlockEnd:{style:Ie},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:To},rowGap:{style:zo},columnGap:{style:Io},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:He},maxWidth:{style:on},minWidth:{transform:He},height:{transform:He},maxHeight:{transform:He},minHeight:{transform:He},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,a)=>i.concat(Object.keys(a)),[]),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,a,c){const d={[n]:i,theme:a},l=c[n];if(!l)return{[n]:i};const{cssProperty:p=n,themeKey:x,transform:f,style:b}=l;if(i==null)return null;if(x==="typography"&&i==="inherit")return{[n]:i};const m=So(a,x)||{};return b?b(d):Tt(d,i,z=>{let y=ho(m,f,z);return z===y&&typeof z=="string"&&(y=ho(m,f,`${n}${z==="default"?"":Oi(z)}`,z)),p===!1?y:{[p]:y}})}function o(n){const{sx:i,theme:a={},nested:c}=n||{};if(!i)return null;const d=a.unstable_sxConfig??Eo;function l(p){let x=p;if(typeof p=="function")x=p(a);else if(typeof p!="object")return p;if(!x)return null;const f=jl(a.breakpoints),b=Object.keys(f);let m=f;return Object.keys(x).forEach(g=>{const z=ac(x[g],a);if(z!=null)if(typeof z=="object")if(d[g])m=qr(m,t(g,z,a,d));else{const y=Tt({theme:a},z,C=>({[g]:C}));sc(y,z)?m[g]=o({sx:z,theme:a,nested:!0}):m=qr(m,y)}else m=qr(m,t(g,z,a,d))}),!c&&a.modularCssLayers?{"@layer sx":Wn(a,Nn(b,m))}:Wn(a,Nn(b,m))}return Array.isArray(i)?i.map(l):l(i)}return o}const Bo=lc();Bo.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 a=n.getColorSchemeSelector(t);return a==="&"?o:((a.includes("data-")||a.includes("."))&&(a=`*:where(${a.replace(/\s*&$/,"")}) &`),{[a]:o})}return n.palette.mode===t?o:{}}function _i(t={},...o){const{breakpoints:n={},palette:i={},spacing:a,shape:c={},...d}=t,l=hl(n),p=Mi(a);let x=Ye({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:p,shape:{...vl,...c}},d);return x=bl(x),x.applyStyles=cc,x=o.reduce((f,b)=>Ye(f,b),x),x.unstable_sxConfig={...Eo,...d==null?void 0:d.unstable_sxConfig},x.unstable_sx=function(b){return Bo({sx:b,theme:this})},x}function dc(t){return Object.keys(t).length===0}function uc(t=null){const o=go.useContext(Is.ThemeContext);return!o||dc(o)?t:o}const pc=_i();function xc(t=pc){return uc(t)}const Fn=t=>t,mc=()=>{let t=Fn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Fn}}},fc=mc(),hc={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=hc[o];return i?`${n}-${i}`:`${fc.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 nn(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,a)=>a<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Mt(t){if(t.type)return t;if(t.charAt(0)==="#")return Mt(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 \`${k}\` property.`:
|
|
47
|
-
\`color.main\` should be a string, but \`${JSON.stringify(
|
|
42
|
+
`)),()=>{})}function un(t){return oo(t,"spacing",8,"spacing")}function no(t,o){return typeof o=="string"||o==null?o:t(o)}function Ml(t,o){return n=>t.reduce((i,a)=>(i[a]=no(o,n),i),{})}function $l(t,o,n,i){if(!o.includes(n))return null;const a=Al(n),c=Ml(a,i),d=t[n];return At(t,d,c)}function Pi(t,o){const n=un(t.theme);return Object.keys(t).map(i=>$l(t,o,i,n)).reduce(to,{})}function Ee(t){return Pi(t,Do)}Ee.propTypes=process.env.NODE_ENV!=="production"?Do.reduce((t,o)=>(t[o]=Lt,t),{}):{};Ee.filterProps=Do;function De(t){return Pi(t,Oo)}De.propTypes=process.env.NODE_ENV!=="production"?Oo.reduce((t,o)=>(t[o]=Lt,t),{}):{};De.filterProps=Oo;process.env.NODE_ENV!=="production"&&_l.reduce((t,o)=>(t[o]=Lt,t),{});function Ni(t=8,o=un({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(c=>{const d=o(c);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function Ao(...t){const o=t.reduce((i,a)=>(a.filterProps.forEach(c=>{i[c]=a}),i),{}),n=i=>Object.keys(i).reduce((a,c)=>o[c]?to(a,o[c](i)):a,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,a)=>Object.assign(i,a.propTypes),{}):{},n.filterProps=t.reduce((i,a)=>i.concat(a.filterProps),[]),n}function rt(t){return typeof t!="number"?t:`${t}px solid`}function ot(t,o){return Oe({prop:t,themeKey:"borders",transform:o})}const Rl=ot("border",rt),Wl=ot("borderTop",rt),Pl=ot("borderRight",rt),Nl=ot("borderBottom",rt),Ll=ot("borderLeft",rt),Fl=ot("borderColor"),Vl=ot("borderTopColor"),Hl=ot("borderRightColor"),Ul=ot("borderBottomColor"),Yl=ot("borderLeftColor"),Gl=ot("outline",rt),ql=ot("outlineColor"),_o=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=oo(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:no(o,i)});return At(t,t.borderRadius,n)}return null};_o.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Lt}:{};_o.filterProps=["borderRadius"];Ao(Rl,Wl,Pl,Nl,Ll,Fl,Vl,Hl,Ul,Yl,_o,Gl,ql);const Mo=t=>{if(t.gap!==void 0&&t.gap!==null){const o=oo(t.theme,"spacing",8,"gap"),n=i=>({gap:no(o,i)});return At(t,t.gap,n)}return null};Mo.propTypes=process.env.NODE_ENV!=="production"?{gap:Lt}:{};Mo.filterProps=["gap"];const $o=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=oo(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:no(o,i)});return At(t,t.columnGap,n)}return null};$o.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Lt}:{};$o.filterProps=["columnGap"];const Ro=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=oo(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:no(o,i)});return At(t,t.rowGap,n)}return null};Ro.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Lt}:{};Ro.filterProps=["rowGap"];const Jl=Oe({prop:"gridColumn"}),Kl=Oe({prop:"gridRow"}),Xl=Oe({prop:"gridAutoFlow"}),Zl=Oe({prop:"gridAutoColumns"}),Ql=Oe({prop:"gridAutoRows"}),ec=Oe({prop:"gridTemplateColumns"}),tc=Oe({prop:"gridTemplateRows"}),rc=Oe({prop:"gridTemplateAreas"}),oc=Oe({prop:"gridArea"});Ao(Mo,$o,Ro,Jl,Kl,Xl,Zl,Ql,ec,tc,rc,oc);function kr(t,o){return o==="grey"?o:t}const nc=Oe({prop:"color",themeKey:"palette",transform:kr}),ic=Oe({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:kr}),sc=Oe({prop:"backgroundColor",themeKey:"palette",transform:kr});Ao(nc,ic,sc);function Je(t){return t<=1&&t!==0?`${t*100}%`:t}const ac=Oe({prop:"width",transform:Je}),pn=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var a,c,d,l,u;const i=((d=(c=(a=t.theme)==null?void 0:a.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||Bo[n];return i?((u=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Je(n)}};return At(t,t.maxWidth,o)}return null};pn.filterProps=["maxWidth"];const lc=Oe({prop:"minWidth",transform:Je}),cc=Oe({prop:"height",transform:Je}),dc=Oe({prop:"maxHeight",transform:Je}),uc=Oe({prop:"minHeight",transform:Je});Oe({prop:"size",cssProperty:"width",transform:Je});Oe({prop:"size",cssProperty:"height",transform:Je});const pc=Oe({prop:"boxSizing"});Ao(ac,pn,lc,cc,dc,uc,pc);const Wo={border:{themeKey:"borders",transform:rt},borderTop:{themeKey:"borders",transform:rt},borderRight:{themeKey:"borders",transform:rt},borderBottom:{themeKey:"borders",transform:rt},borderLeft:{themeKey:"borders",transform:rt},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:rt},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:_o},color:{themeKey:"palette",transform:kr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:kr},backgroundColor:{themeKey:"palette",transform:kr},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:Ee},mt:{style:Ee},mr:{style:Ee},mb:{style:Ee},ml:{style:Ee},mx:{style:Ee},my:{style:Ee},margin:{style:Ee},marginTop:{style:Ee},marginRight:{style:Ee},marginBottom:{style:Ee},marginLeft:{style:Ee},marginX:{style:Ee},marginY:{style:Ee},marginInline:{style:Ee},marginInlineStart:{style:Ee},marginInlineEnd:{style:Ee},marginBlock:{style:Ee},marginBlockStart:{style:Ee},marginBlockEnd:{style:Ee},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:Mo},rowGap:{style:Ro},columnGap:{style:$o},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Je},maxWidth:{style:pn},minWidth:{transform:Je},height:{transform:Je},maxHeight:{transform:Je},minHeight:{transform:Je},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 xc(...t){const o=t.reduce((i,a)=>i.concat(Object.keys(a)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function mc(t,o){return typeof t=="function"?t(o):t}function fc(){function t(n,i,a,c){const d={[n]:i,theme:a},l=c[n];if(!l)return{[n]:i};const{cssProperty:u=n,themeKey:m,transform:f,style:b}=l;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const x=Eo(a,m)||{};return b?b(d):At(d,i,B=>{let y=wo(x,f,B);return B===y&&typeof B=="string"&&(y=wo(x,f,`${n}${B==="default"?"":Wi(B)}`,B)),u===!1?y:{[u]:y}})}function o(n){const{sx:i,theme:a={},nested:c}=n||{};if(!i)return null;const d=a.unstable_sxConfig??Wo;function l(u){let m=u;if(typeof u=="function")m=u(a);else if(typeof u!="object")return u;if(!m)return null;const f=Bl(a.breakpoints),b=Object.keys(f);let x=f;return Object.keys(m).forEach(g=>{const B=mc(m[g],a);if(B!=null)if(typeof B=="object")if(d[g])x=to(x,t(g,B,a,d));else{const y=At({theme:a},B,j=>({[g]:j}));xc(y,B)?x[g]=o({sx:B,theme:a,nested:!0}):x=to(x,y)}else x=to(x,t(g,B,a,d))}),!c&&a.modularCssLayers?{"@layer sx":Un(a,Gn(b,x))}:Un(a,Gn(b,x))}return Array.isArray(i)?i.map(l):l(i)}return o}const Po=fc();Po.filterProps=["sx"];function hc(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let a=n.getColorSchemeSelector(t);return a==="&"?o:((a.includes("data-")||a.includes("."))&&(a=`*:where(${a.replace(/\s*&$/,"")}) &`),{[a]:o})}return n.palette.mode===t?o:{}}function Li(t={},...o){const{breakpoints:n={},palette:i={},spacing:a,shape:c={},...d}=t,l=Cl(n),u=Ni(a);let m=Xe({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...Il,...c}},d);return m=Tl(m),m.applyStyles=hc,m=o.reduce((f,b)=>Xe(f,b),m),m.unstable_sxConfig={...Wo,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(b){return Po({sx:b,theme:this})},m}function gc(t){return Object.keys(t).length===0}function yc(t=null){const o=To.useContext(Ms.ThemeContext);return!o||gc(o)?t:o}const bc=Li();function vc(t=bc){return yc(t)}const Jn=t=>t,Sc=()=>{let t=Jn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Jn}}},jc=Sc(),Cc={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 wc(t,o,n="Mui"){const i=Cc[o];return i?`${n}-${i}`:`${jc.generate(t)}-${o}`}function kc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function xn(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}].`),kc(t,o,n)}function Tc(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,a)=>a<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Nt(t){if(t.type)return t;if(t.charAt(0)==="#")return Nt(Tc(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().`:rr(9,t));let i=t.substring(o+1,t.length-1),a;if(n==="color"){if(i=i.split(" "),a=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(a))throw new Error(process.env.NODE_ENV!=="production"?`MUI: unsupported \`${a}\` color space.
|
|
44
|
+
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:rr(10,a))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:a}}const Ic=t=>{const o=Nt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Zr=(t,o)=>{try{return Ic(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function No(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((a,c)=>c<3?parseInt(a,10):a):o.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),o.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${o}(${i})`}function Fi(t){t=Nt(t);const{values:o}=t,n=o[0],i=o[1]/100,a=o[2]/100,c=i*Math.min(a,1-a),d=(m,f=(m+n/30)%12)=>a-c*Math.max(Math.min(f-3,9-f,1),-1);let l="rgb";const u=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return t.type==="hsla"&&(l+="a",u.push(o[3])),No({type:l,values:u})}function rn(t){t=Nt(t);let o=t.type==="hsl"||t.type==="hsla"?Nt(Fi(t)).values:t.values;return o=o.map(n=>(t.type!=="color"&&(n/=255),n<=.03928?n/12.92:((n+.055)/1.055)**2.4)),Number((.2126*o[0]+.7152*o[1]+.0722*o[2]).toFixed(3))}function Kn(t,o){const n=rn(t),i=rn(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function z(t,o){return t=Nt(t),o=xn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,No(t)}function Qt(t,o,n){try{return z(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Lo(t,o){if(t=Nt(t),o=xn(o),t.type.includes("hsl"))t.values[2]*=1-o;else if(t.type.includes("rgb")||t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]*=1-o;return No(t)}function ve(t,o,n){try{return Lo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Fo(t,o){if(t=Nt(t),o=xn(o),t.type.includes("hsl"))t.values[2]+=(100-t.values[2])*o;else if(t.type.includes("rgb"))for(let n=0;n<3;n+=1)t.values[n]+=(255-t.values[n])*o;else if(t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]+=(1-t.values[n])*o;return No(t)}function Se(t,o,n){try{return Fo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function zc(t,o=.15){return rn(t)>.5?Lo(t,o):Fo(t,o)}function mo(t,o,n){try{return zc(t,o)}catch{return t}}function Bc(t=""){function o(...i){if(!i.length)return"";const a=i[0];return typeof a=="string"&&!a.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)?`, var(--${t?`${t}-`:""}${a}${o(...i.slice(1))})`:`, ${a}`}return(i,...a)=>`var(--${t?`${t}-`:""}${i}${o(...a)})`}const Xn=(t,o,n,i=[])=>{let a=t;o.forEach((c,d)=>{d===o.length-1?Array.isArray(a)?a[Number(c)]=n:a&&typeof a=="object"&&(a[c]=n):a&&typeof a=="object"&&(a[c]||(a[c]=i.includes(c)?[]:{}),a=a[c])})},Ec=(t,o,n)=>{function i(a,c=[],d=[]){Object.entries(a).forEach(([l,u])=>{(!n||n&&!n([...c,l]))&&u!=null&&(typeof u=="object"&&Object.keys(u).length>0?i(u,[...c,l],Array.isArray(u)?[...d,l]:d):o([...c,l],u,d))})}i(t)},Dc=(t,o)=>typeof o=="number"?["lineHeight","fontWeight","opacity","zIndex"].some(i=>t.includes(i))||t[t.length-1].toLowerCase().includes("opacity")?o:`${o}px`:o;function Zo(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},a={},c={},d={};return Ec(t,(l,u,m)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const f=`--${n?`${n}-`:""}${l.join("-")}`,b=Dc(l,u);Object.assign(a,{[f]:b}),Xn(c,l,`var(${f})`,m),Xn(d,l,`var(${f}, ${b})`,m)}},l=>l[0]==="vars"),{css:a,vars:c,varsWithDefaults:d}}function Oc(t,o={}){const{getSelector:n=S,disableCssColorScheme:i,colorSchemeSelector:a,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:u="light",...m}=t,{vars:f,css:b,varsWithDefaults:x}=Zo(m,o);let g=x;const B={},{[u]:y,...j}=d;if(Object.entries(j||{}).forEach(([w,s])=>{const{vars:_,css:I,varsWithDefaults:R}=Zo(s,o);g=Xe(g,R),B[w]={css:I,vars:_}}),y){const{css:w,vars:s,varsWithDefaults:_}=Zo(y,o);g=Xe(g,_),B[u]={css:w,vars:s}}function S(w,s){var I,R;let _=a;if(a==="class"&&(_=".%s"),a==="data"&&(_="[data-%s]"),a!=null&&a.startsWith("data-")&&!a.includes("%s")&&(_=`[${a}="%s"]`),w){if(_==="media")return t.defaultColorScheme===w?":root":{[`@media (prefers-color-scheme: ${((R=(I=d[w])==null?void 0:I.palette)==null?void 0:R.mode)||w})`]:{":root":s}};if(_)return t.defaultColorScheme===w?`:root, ${_.replace("%s",String(w))}`:_.replace("%s",String(w))}return":root"}return{vars:g,generateThemeVars:()=>{let w={...f};return Object.entries(B).forEach(([,{vars:s}])=>{w=Xe(w,s)}),w},generateStyleSheets:()=>{var q,Q;const w=[],s=t.defaultColorScheme||"light";function _(te,h){Object.keys(h).length&&w.push(typeof te=="string"?{[te]:{...h}}:te)}_(n(void 0,{...b}),b);const{[s]:I,...R}=B;if(I){const{css:te}=I,h=(Q=(q=d[s])==null?void 0:q.palette)==null?void 0:Q.mode,$=!i&&h?{colorScheme:h,...te}:{...te};_(n(s,{...$}),$)}return Object.entries(R).forEach(([te,{css:h}])=>{var F,X;const $=(X=(F=d[te])==null?void 0:F.palette)==null?void 0:X.mode,W=!i&&$?{colorScheme:$,...h}:{...h};_(n(te,{...W}),W)}),c&&w.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)"}}),w}}}function Ac(t){return function(n){return t==="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})`):t?t.startsWith("data-")&&!t.includes("%s")?`[${t}="${n}"] &`:t==="class"?`.${n} &`:t==="data"?`[data-${n}] &`:`${t.replace("%s",n)} &`:"&"}}const ro={black:"#000",white:"#fff"},_c={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"},br={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},vr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},qr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},Sr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},jr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},Cr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Vi(){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:ro.white,default:ro.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 Hi=Vi();function Ui(){return{text:{primary:ro.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:ro.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 on=Ui();function Zn(t,o,n,i){const a=i.light||i,c=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Fo(t.main,a):o==="dark"&&(t.dark=Lo(t.main,c)))}function Qn(t,o,n,i,a){const c=a.light||a,d=a.dark||a*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(c*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function Mc(t="light"){return t==="dark"?{main:Sr[200],light:Sr[50],dark:Sr[400]}:{main:Sr[700],light:Sr[400],dark:Sr[800]}}function $c(t="light"){return t==="dark"?{main:br[200],light:br[50],dark:br[400]}:{main:br[500],light:br[300],dark:br[700]}}function Rc(t="light"){return t==="dark"?{main:vr[500],light:vr[300],dark:vr[700]}:{main:vr[700],light:vr[400],dark:vr[800]}}function Wc(t="light"){return t==="dark"?{main:jr[400],light:jr[300],dark:jr[700]}:{main:jr[700],light:jr[500],dark:jr[900]}}function Pc(t="light"){return t==="dark"?{main:Cr[400],light:Cr[300],dark:Cr[700]}:{main:Cr[800],light:Cr[500],dark:Cr[900]}}function Nc(t="light"){return t==="dark"?{main:qr[400],light:qr[300],dark:qr[700]}:{main:"#ed6c02",light:qr[500],dark:qr[900]}}function Lc(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function mn(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:a,...c}=t,d=t.primary||Mc(o),l=t.secondary||$c(o),u=t.error||Rc(o),m=t.info||Wc(o),f=t.success||Pc(o),b=t.warning||Nc(o);function x(j){if(a)return Lc(j);const S=Kn(j,on.text.primary)>=n?on.text.primary:Hi.text.primary;if(process.env.NODE_ENV!=="production"){const k=Kn(j,S);k<3&&console.error([`MUI: The contrast ratio of ${k}:1 for ${S} on ${j}`,"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 S}const g=({color:j,name:S,mainShade:k=500,lightShade:v=300,darkShade:w=700})=>{if(j={...j},!j.main&&j[k]&&(j.main=j[k]),!j.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
|
|
46
|
+
The color object needs to have a \`main\` property or a \`${k}\` property.`:rr(11,S?` (${S})`:"",k));if(typeof j.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
|
|
47
|
+
\`color.main\` should be a string, but \`${JSON.stringify(j.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
|
+
} });`:rr(12,S?` (${S})`:"",JSON.stringify(j.main)));return a?(Qn(a,j,"light",v,i),Qn(a,j,"dark",w,i)):(Zn(j,"light",v,i),Zn(j,"dark",w,i)),j.contrastText||(j.contrastText=x(j.main)),j};let B;return o==="light"?B=Vi():o==="dark"&&(B=Ui()),process.env.NODE_ENV!=="production"&&(B||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),Xe({common:{...ro},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:u,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:m,name:"info"}),success:g({color:f,name:"success"}),grey:_c,contrastThreshold:n,getContrastText:x,augmentColor:g,tonalOffset:i,...B},c)}function Fc(t){const o={};return Object.entries(t).forEach(i=>{const[a,c]=i;typeof c=="object"&&(o[a]=`${c.fontStyle?`${c.fontStyle} `:""}${c.fontVariant?`${c.fontVariant} `:""}${c.fontWeight?`${c.fontWeight} `:""}${c.fontStretch?`${c.fontStretch} `:""}${c.fontSize||""}${c.lineHeight?`/${c.lineHeight} `:""}${c.fontFamily||""}`)}),o}function Vc(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Hc(t){return Math.round(t*1e5)/1e5}const ei={textTransform:"uppercase"},ti='"Roboto", "Helvetica", "Arial", sans-serif';function Uc(t,o){const{fontFamily:n=ti,fontSize:i=14,fontWeightLight:a=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:u=16,allVariants:m,pxToRem:f,...b}=typeof o=="function"?o(t):o;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 x=i/14,g=f||(j=>`${j/u*x}rem`),B=(j,S,k,v,w)=>({fontFamily:n,fontWeight:j,fontSize:g(S),lineHeight:k,...n===ti?{letterSpacing:`${Hc(v/S)}em`}:{},...w,...m}),y={h1:B(a,96,1.167,-1.5),h2:B(a,60,1.2,-.5),h3:B(c,48,1.167,0),h4:B(c,34,1.235,.25),h5:B(c,24,1.334,0),h6:B(d,20,1.6,.15),subtitle1:B(c,16,1.75,.15),subtitle2:B(d,14,1.57,.1),body1:B(c,16,1.5,.15),body2:B(c,14,1.43,.15),button:B(d,14,1.75,.4,ei),caption:B(c,12,1.66,.4),overline:B(c,12,2.66,1,ei),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Xe({htmlFontSize:u,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:a,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...y},b,{clone:!1})}const Yc=.2,Gc=.14,qc=.12;function ze(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Yc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Gc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${qc})`].join(",")}const Jc=["none",ze(0,2,1,-1,0,1,1,0,0,1,3,0),ze(0,3,1,-2,0,2,2,0,0,1,5,0),ze(0,3,3,-2,0,3,4,0,0,1,8,0),ze(0,2,4,-1,0,4,5,0,0,1,10,0),ze(0,3,5,-1,0,5,8,0,0,1,14,0),ze(0,3,5,-1,0,6,10,0,0,1,18,0),ze(0,4,5,-2,0,7,10,1,0,2,16,1),ze(0,5,5,-3,0,8,10,1,0,3,14,2),ze(0,5,6,-3,0,9,12,1,0,3,16,2),ze(0,6,6,-3,0,10,14,1,0,4,18,3),ze(0,6,7,-4,0,11,15,1,0,4,20,3),ze(0,7,8,-4,0,12,17,2,0,5,22,4),ze(0,7,8,-4,0,13,19,2,0,5,24,4),ze(0,7,9,-4,0,14,21,2,0,5,26,4),ze(0,8,9,-5,0,15,22,2,0,6,28,5),ze(0,8,10,-5,0,16,24,2,0,6,30,5),ze(0,8,11,-5,0,17,26,2,0,6,32,5),ze(0,9,11,-5,0,18,28,2,0,7,34,6),ze(0,9,12,-6,0,19,29,2,0,7,36,6),ze(0,10,13,-6,0,20,31,3,0,8,38,7),ze(0,10,13,-6,0,21,33,3,0,8,40,7),ze(0,10,14,-6,0,22,35,3,0,8,42,7),ze(0,11,14,-7,0,23,36,3,0,9,44,8),ze(0,11,15,-7,0,24,38,3,0,9,46,8)],Kc={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)"},Xc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function ri(t){return`${Math.round(t)}ms`}function Zc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Qc(t){const o={...Kc,...t.easing},n={...Xc,...t.duration};return{getAutoHeightDuration:Zc,create:(a=["all"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:u=0,...m}=c;if(process.env.NODE_ENV!=="production"){const f=x=>typeof x=="string",b=x=>!Number.isNaN(parseFloat(x));!f(a)&&!Array.isArray(a)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!f(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),f(l)||console.error('MUI: Argument "easing" must be a string.'),!b(u)&&!f(u)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof c!="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(a)?a:[a]).map(f=>`${f} ${typeof d=="string"?d:ri(d)} ${l} ${typeof u=="string"?u:ri(u)}`).join(",")},...t,easing:o,duration:n}}const ed={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function td(t){return Pt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Yi(t={}){const o={...t};function n(i){const a=Object.entries(i);for(let c=0;c<a.length;c++){const[d,l]=a[c];!td(l)||d.startsWith("unstable_")?delete i[d]:Pt(l)&&(i[d]={...l},n(i[d]))}}return n(o),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
|
|
61
61
|
|
|
62
62
|
const theme = ${JSON.stringify(o,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 pt=t=>{try{return t()}catch{}},id=(t="mui")=>jc(t);function Uo(t,o,n,i,a){if(!n)return;n=n===!0?{}:n;const c=a==="dark"?"dark":"light";if(!i){o[a]=Qc({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=Ko({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[a]={...n,palette:d,opacity:{...Li(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Fi(c)},l}function sd(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:a=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=ed,colorSchemeSelector:p=n.light&&n.dark?"media":void 0,rootSelector:x=":root",...f}=t,b=Object.keys(n)[0],m=i||(n.light&&b!=="light"?"light":b),g=id(c),{[m]:z,light:y,dark:C,...v}=n,k={...v};let S=z;if((m==="dark"&&!("dark"in n)||m==="light"&&!("light"in n))&&(S=!0),!S)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${m}\` option is either missing or invalid.`:Jt(21,m));let T;d&&(T="oklch");const s=Uo(T,k,S,f,m);y&&!k.light&&Uo(T,k,y,void 0,"light"),C&&!k.dark&&Uo(T,k,C,void 0,"dark");let M={defaultColorScheme:m,...s,cssVarPrefix:c,colorSchemeSelector:p,rootSelector:x,getCssVar:g,colorSchemes:k,font:{..._c(s.typography),...s.font},spacing:nd(f.spacing)};Object.keys(M.colorSchemes).forEach(ee=>{const h=M.colorSchemes[ee].palette,R=H=>{const K=H.split("-"),de=K[1],ue=K[2];return g(H,h[de][ue])};h.mode==="light"&&(P(h.common,"background","#fff"),P(h.common,"onBackground","#000")),h.mode==="dark"&&(P(h.common,"background","#000"),P(h.common,"onBackground","#fff"));function W(H,K,de){if(T){let ue;return H===Yt&&(ue=`transparent ${((1-de)*100).toFixed(0)}%`),H===ge&&(ue=`#000 ${(de*100).toFixed(0)}%`),H===ye&&(ue=`#fff ${(de*100).toFixed(0)}%`),`color-mix(in ${T}, ${K}, ${ue})`}return H(K,de)}if(od(h,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),h.mode==="light"){P(h.Alert,"errorColor",W(ge,h.error.light,.6)),P(h.Alert,"infoColor",W(ge,h.info.light,.6)),P(h.Alert,"successColor",W(ge,h.success.light,.6)),P(h.Alert,"warningColor",W(ge,h.warning.light,.6)),P(h.Alert,"errorFilledBg",R("palette-error-main")),P(h.Alert,"infoFilledBg",R("palette-info-main")),P(h.Alert,"successFilledBg",R("palette-success-main")),P(h.Alert,"warningFilledBg",R("palette-warning-main")),P(h.Alert,"errorFilledColor",pt(()=>h.getContrastText(h.error.main))),P(h.Alert,"infoFilledColor",pt(()=>h.getContrastText(h.info.main))),P(h.Alert,"successFilledColor",pt(()=>h.getContrastText(h.success.main))),P(h.Alert,"warningFilledColor",pt(()=>h.getContrastText(h.warning.main))),P(h.Alert,"errorStandardBg",W(ye,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(ye,h.info.light,.9)),P(h.Alert,"successStandardBg",W(ye,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(ye,h.warning.light,.9)),P(h.Alert,"errorIconColor",R("palette-error-main")),P(h.Alert,"infoIconColor",R("palette-info-main")),P(h.Alert,"successIconColor",R("palette-success-main")),P(h.Alert,"warningIconColor",R("palette-warning-main")),P(h.AppBar,"defaultBg",R("palette-grey-100")),P(h.Avatar,"defaultBg",R("palette-grey-400")),P(h.Button,"inheritContainedBg",R("palette-grey-300")),P(h.Button,"inheritContainedHoverBg",R("palette-grey-A100")),P(h.Chip,"defaultBorder",R("palette-grey-400")),P(h.Chip,"defaultAvatarColor",R("palette-grey-700")),P(h.Chip,"defaultIconColor",R("palette-grey-700")),P(h.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),P(h.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),P(h.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),P(h.LinearProgress,"primaryBg",W(ye,h.primary.main,.62)),P(h.LinearProgress,"secondaryBg",W(ye,h.secondary.main,.62)),P(h.LinearProgress,"errorBg",W(ye,h.error.main,.62)),P(h.LinearProgress,"infoBg",W(ye,h.info.main,.62)),P(h.LinearProgress,"successBg",W(ye,h.success.main,.62)),P(h.LinearProgress,"warningBg",W(ye,h.warning.main,.62)),P(h.Skeleton,"bg",T?W(Yt,h.text.primary,.11):`rgba(${R("palette-text-primaryChannel")} / 0.11)`),P(h.Slider,"primaryTrack",W(ye,h.primary.main,.62)),P(h.Slider,"secondaryTrack",W(ye,h.secondary.main,.62)),P(h.Slider,"errorTrack",W(ye,h.error.main,.62)),P(h.Slider,"infoTrack",W(ye,h.info.main,.62)),P(h.Slider,"successTrack",W(ye,h.success.main,.62)),P(h.Slider,"warningTrack",W(ye,h.warning.main,.62));const H=T?W(ge,h.background.default,.6825):io(h.background.default,.8);P(h.SnackbarContent,"bg",H),P(h.SnackbarContent,"color",pt(()=>T?Jo.text.primary:h.getContrastText(H))),P(h.SpeedDialAction,"fabHoverBg",io(h.background.paper,.15)),P(h.StepConnector,"border",R("palette-grey-400")),P(h.StepContent,"border",R("palette-grey-400")),P(h.Switch,"defaultColor",R("palette-common-white")),P(h.Switch,"defaultDisabledColor",R("palette-grey-100")),P(h.Switch,"primaryDisabledColor",W(ye,h.primary.main,.62)),P(h.Switch,"secondaryDisabledColor",W(ye,h.secondary.main,.62)),P(h.Switch,"errorDisabledColor",W(ye,h.error.main,.62)),P(h.Switch,"infoDisabledColor",W(ye,h.info.main,.62)),P(h.Switch,"successDisabledColor",W(ye,h.success.main,.62)),P(h.Switch,"warningDisabledColor",W(ye,h.warning.main,.62)),P(h.TableCell,"border",W(ye,W(Yt,h.divider,1),.88)),P(h.Tooltip,"bg",W(Yt,h.grey[700],.92))}if(h.mode==="dark"){P(h.Alert,"errorColor",W(ye,h.error.light,.6)),P(h.Alert,"infoColor",W(ye,h.info.light,.6)),P(h.Alert,"successColor",W(ye,h.success.light,.6)),P(h.Alert,"warningColor",W(ye,h.warning.light,.6)),P(h.Alert,"errorFilledBg",R("palette-error-dark")),P(h.Alert,"infoFilledBg",R("palette-info-dark")),P(h.Alert,"successFilledBg",R("palette-success-dark")),P(h.Alert,"warningFilledBg",R("palette-warning-dark")),P(h.Alert,"errorFilledColor",pt(()=>h.getContrastText(h.error.dark))),P(h.Alert,"infoFilledColor",pt(()=>h.getContrastText(h.info.dark))),P(h.Alert,"successFilledColor",pt(()=>h.getContrastText(h.success.dark))),P(h.Alert,"warningFilledColor",pt(()=>h.getContrastText(h.warning.dark))),P(h.Alert,"errorStandardBg",W(ge,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(ge,h.info.light,.9)),P(h.Alert,"successStandardBg",W(ge,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(ge,h.warning.light,.9)),P(h.Alert,"errorIconColor",R("palette-error-main")),P(h.Alert,"infoIconColor",R("palette-info-main")),P(h.Alert,"successIconColor",R("palette-success-main")),P(h.Alert,"warningIconColor",R("palette-warning-main")),P(h.AppBar,"defaultBg",R("palette-grey-900")),P(h.AppBar,"darkBg",R("palette-background-paper")),P(h.AppBar,"darkColor",R("palette-text-primary")),P(h.Avatar,"defaultBg",R("palette-grey-600")),P(h.Button,"inheritContainedBg",R("palette-grey-800")),P(h.Button,"inheritContainedHoverBg",R("palette-grey-700")),P(h.Chip,"defaultBorder",R("palette-grey-700")),P(h.Chip,"defaultAvatarColor",R("palette-grey-300")),P(h.Chip,"defaultIconColor",R("palette-grey-300")),P(h.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),P(h.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),P(h.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),P(h.LinearProgress,"primaryBg",W(ge,h.primary.main,.5)),P(h.LinearProgress,"secondaryBg",W(ge,h.secondary.main,.5)),P(h.LinearProgress,"errorBg",W(ge,h.error.main,.5)),P(h.LinearProgress,"infoBg",W(ge,h.info.main,.5)),P(h.LinearProgress,"successBg",W(ge,h.success.main,.5)),P(h.LinearProgress,"warningBg",W(ge,h.warning.main,.5)),P(h.Skeleton,"bg",T?W(Yt,h.text.primary,.13):`rgba(${R("palette-text-primaryChannel")} / 0.13)`),P(h.Slider,"primaryTrack",W(ge,h.primary.main,.5)),P(h.Slider,"secondaryTrack",W(ge,h.secondary.main,.5)),P(h.Slider,"errorTrack",W(ge,h.error.main,.5)),P(h.Slider,"infoTrack",W(ge,h.info.main,.5)),P(h.Slider,"successTrack",W(ge,h.success.main,.5)),P(h.Slider,"warningTrack",W(ge,h.warning.main,.5));const H=T?W(ye,h.background.default,.985):io(h.background.default,.98);P(h.SnackbarContent,"bg",H),P(h.SnackbarContent,"color",pt(()=>T?Wi.text.primary:h.getContrastText(H))),P(h.SpeedDialAction,"fabHoverBg",io(h.background.paper,.15)),P(h.StepConnector,"border",R("palette-grey-600")),P(h.StepContent,"border",R("palette-grey-600")),P(h.Switch,"defaultColor",R("palette-grey-300")),P(h.Switch,"defaultDisabledColor",R("palette-grey-600")),P(h.Switch,"primaryDisabledColor",W(ge,h.primary.main,.55)),P(h.Switch,"secondaryDisabledColor",W(ge,h.secondary.main,.55)),P(h.Switch,"errorDisabledColor",W(ge,h.error.main,.55)),P(h.Switch,"infoDisabledColor",W(ge,h.info.main,.55)),P(h.Switch,"successDisabledColor",W(ge,h.success.main,.55)),P(h.Switch,"warningDisabledColor",W(ge,h.warning.main,.55)),P(h.TableCell,"border",W(ge,W(Yt,h.divider,1),.68)),P(h.Tooltip,"bg",W(Yt,h.grey[700],.92))}Ct(h.background,"default"),Ct(h.background,"paper"),Ct(h.common,"background"),Ct(h.common,"onBackground"),Ct(h,"divider"),Object.keys(h).forEach(H=>{const K=h[H];H!=="tonalOffset"&&K&&typeof K=="object"&&(K.main&&P(h[H],"mainChannel",Ur(Yr(K.main))),K.light&&P(h[H],"lightChannel",Ur(Yr(K.light))),K.dark&&P(h[H],"darkChannel",Ur(Yr(K.dark))),K.contrastText&&P(h[H],"contrastTextChannel",Ur(Yr(K.contrastText))),H==="text"&&(Ct(h[H],"primary"),Ct(h[H],"secondary")),H==="action"&&(K.active&&Ct(h[H],"active"),K.selected&&Ct(h[H],"selected")))})}),M=o.reduce((ee,h)=>Ye(ee,h),M);const B={prefix:c,disableCssColorScheme:a,shouldSkipGeneratingVar:l,getSelector:rd(M),enableContrastVars:d},{vars:$,generateThemeVars:G,generateStyleSheets:Z}=kc(M,B);return M.vars=$,Object.entries(M.colorSchemes[M.defaultColorScheme]).forEach(([ee,h])=>{M[ee]=h}),M.generateThemeVars=G,M.generateStyleSheets=Z,M.generateSpacing=function(){return Mi(f.spacing,rn(this))},M.getColorSchemeSelector=Tc(p),M.spacing=M.generateSpacing(),M.shouldSkipGeneratingVar=l,M.unstable_sxConfig={...Eo,...f==null?void 0:f.unstable_sxConfig},M.unstable_sx=function(h){return Bo({sx:h,theme:this})},M.toRuntimeSource=Ni,M}function Xn(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:sn({...n===!0?{}:n.palette,mode:o})})}function ad(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:a=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",p=a==null?void 0:a[l],x={...a,...n?{[l]:{...typeof p!="boolean"&&p,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return Ko(t,...o);let f=n;"palette"in t||x[l]&&(x[l]!==!0?f=x[l].palette:l==="dark"&&(f={mode:"dark"}));const b=Ko({...t,palette:f},...o);return b.defaultColorScheme=l,b.colorSchemes=x,b.palette.mode==="light"&&(b.colorSchemes.light={...x.light!==!0&&x.light,palette:b.palette},Xn(b,"dark",x.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:b.palette},Xn(b,"light",x.light)),b}return!n&&!("light"in x)&&l==="light"&&(x.light=!0),sd({...d,colorSchemes:x,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const ld=ad();function It(){const t=xc(ld);return process.env.NODE_ENV!=="production"&&go.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 a=new AbortController,c=setTimeout(()=>a.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:a.signal})}catch(x){throw clearTimeout(c),(x==null?void 0:x.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(c)}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 l;try{l=await d.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 f=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(f)p=l[f];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({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:a}){const[c,d]=u.useState(""),[l,p]=u.useState(!1),[x,f]=u.useState(""),[b,m]=u.useState(null),[g,z]=u.useState(null),[y,C]=u.useState(!1),[v,k]=u.useState(""),S=u.useRef(null),[T,s]=u.useState("json"),[M,B]=u.useState(""),[$,G]=u.useState(""),[Z,ee]=u.useState(""),[h,R]=u.useState("idle"),[W,H]=u.useState(""),[K,de]=u.useState(null),[ue,te]=u.useState(0),A=async N=>{if(k(""),!N.name.endsWith(".json")){k("Only .json files are allowed");return}const ne=10*1024*1024;if(N.size>ne){k("File size exceeds 10MB limit");return}try{const ce=await N.text();let se;try{se=JSON.parse(ce)}catch{k("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(se)){k("JSON must be an array of objects");return}if(se.length===0){k("No data rows found in JSON file");return}m(N),z(se)}catch{k("Network error — please try again")}},V=N=>{N.preventDefault();const ne=N.dataTransfer.files[0];ne&&A(ne)},q=async()=>{if(M.trim()){R("loading"),H("");try{const N=await cd(M.trim(),$.trim()||void 0,Z.trim()||void 0);de(N.data),te(N.data.length),R("ready")}catch(N){H((N==null?void 0:N.message)||"Connection failed"),R("error")}}},re=()=>{if(!c.trim()){p(!0);return}const N=T==="api"?K:i||g;N&&(n(c.trim(),x.trim(),N),Q())},Q=()=>{d(""),p(!1),f(""),m(null),z(null),k(""),s("json"),B(""),G(""),ee(""),R("idle"),H(""),de(null),te(0),o()},le=i||g,oe=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:Q,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},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:Q,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.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:c,onChange:N=>{d(N.target.value),l&&N.target.value.trim()&&p(!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}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:x,onChange:N=>f(N.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:T==="json"?0:1,onChange:(N,ne)=>{s(ne===0?"json":"api"),R("idle"),H("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(w.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(w.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),T==="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:N=>D(N.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:N=>D(N.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.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:a||`${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:()=>C(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:V,onDragOver:N=>N.preventDefault(),onPaste:N=>N.preventDefault(),onClick:()=>{var N;return(N=S.current)==null?void 0:N.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":v?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?N=>D(N.palette.success.main,.04):v?N=>D(N.palette.error.main,.04):N=>D(N.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?N=>D(N.palette.success.main,.08):v?N=>D(N.palette.error.main,.08):N=>D(N.palette.primary.main,.08),borderColor:g?"success.dark":v?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:S,type:"file",accept:".json",sx:{display:"none"},onChange:N=>{var ne;return((ne=N.target.files)==null?void 0:ne[0])&&A(N.target.files[0])}}),g?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:N=>D(N.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(w.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:b==null?void 0:b.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:N=>D(N.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(w.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"}),v&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:N=>D(N.palette.error.main,.08),border:1,borderColor:N=>D(N.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:v})})]})]})]})}),T==="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:M,onChange:N=>{B(N.target.value),R("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:$,onChange:N=>G(N.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(w.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:Z,onChange:N=>ee(N.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:!M.trim()||h==="loading",onClick:q,startIcon:h==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(w.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:N=>D(N.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:h==="loading"?"Connecting...":"Test Connection & Load Data"}),h==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:N=>D(N.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.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:[ue.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:M})]})]}),h==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:N=>D(N.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.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:Q,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:N=>D(N.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:re,disabled:T==="json"&&!le||T==="api"&&h!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:y,onClose:()=>C(!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:()=>C(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.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(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const rd=t=>{if(!Number.isNaN(+t))return+t;const o=t.match(/\d*\.?\d+/g);if(!o)return 0;let n=0;for(let i=0;i<o.length;i+=1)n+=+o[i];return n};function od(t){Object.assign(t,{alpha(o,n){const i=this||t;return i.colorSpace?`oklch(from ${o} l c h / ${typeof n=="string"?`calc(${n})`:n})`:i.vars?`rgba(${o.replace(/var\(--([^,\s)]+)(?:,[^)]+)?\)+/g,"var(--$1Channel)")} / ${typeof n=="string"?`calc(${n})`:n})`:z(o,rd(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${oi(n)})`:Fo(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${oi(n)})`:Lo(o,n)}})}function nn(t={},...o){const{breakpoints:n,mixins:i={},spacing:a,palette:c={},transitions:d={},typography:l={},shape:u,colorSpace:m,...f}=t;if(t.vars&&t.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.":rr(20));const b=mn({...c,colorSpace:m}),x=Li(t);let g=Xe(x,{mixins:Vc(x.breakpoints,i),palette:b,shadows:Jc.slice(),typography:Uc(b,l),transitions:Qc(d),zIndex:{...ed}});if(g=Xe(g,f),g=o.reduce((B,y)=>Xe(B,y),g),process.env.NODE_ENV!=="production"){const B=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],y=(j,S)=>{let k;for(k in j){const v=j[k];if(B.includes(k)&&Object.keys(v).length>0){if(process.env.NODE_ENV!=="production"){const w=wc("",k);console.error([`MUI: The \`${S}\` component increases the CSS specificity of the \`${k}\` internal state.`,"You can not override it like this: ",JSON.stringify(j,null,2),"",`Instead, you need to use the '&.${w}' syntax:`,JSON.stringify({root:{[`&.${w}`]:v}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
|
|
68
|
+
`))}j[k]={}}}};Object.keys(g.components).forEach(j=>{const S=g.components[j].styleOverrides;S&&j.startsWith("Mui")&&y(S,j)})}return g.unstable_sxConfig={...Wo,...f==null?void 0:f.unstable_sxConfig},g.unstable_sx=function(y){return Po({sx:y,theme:this})},g.toRuntimeSource=Yi,od(g),g}function nd(t){let o;return t<1?o=5.11916*t**2:o=4.5*Math.log(t+1)+2,Math.round(o*10)/1e3}const id=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=nd(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Gi(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function qi(t){return t==="dark"?id:[]}function sd(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:a,...c}=t,d=mn({...o,colorSpace:a});return{palette:d,opacity:{...Gi(d.mode),...n},overlays:i||qi(d.mode),...c}}function ad(t){var o;return!!t[0].match(/(cssVarPrefix|colorSchemeSelector|modularCssLayers|rootSelector|typography|mixins|breakpoints|direction|transitions)/)||!!t[0].match(/sxConfig$/)||t[0]==="palette"&&!!((o=t[1])!=null&&o.match(/(mode|contrastThreshold|tonalOffset)/))}const ld=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],cd=t=>(o,n)=>{const i=t.rootSelector||":root",a=t.colorSchemeSelector;let c=a;if(a==="class"&&(c=".%s"),a==="data"&&(c="[data-%s]"),a!=null&&a.startsWith("data-")&&!a.includes("%s")&&(c=`[${a}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return ld(t.cssVarPrefix).forEach(l=>{d[l]=n[l],delete n[l]}),c==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:d}}:c?{[c.replace("%s",o)]:d,[`${i}, ${c.replace("%s",o)}`]:n}:{[i]:{...n,...d}}}if(c&&c!=="media")return`${i}, ${c.replace("%s",String(o))}`}else if(o){if(c==="media")return{[`@media (prefers-color-scheme: ${String(o)})`]:{[i]:n}};if(c)return c.replace("%s",String(o))}return i};function dd(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function P(t,o,n){!t[o]&&n&&(t[o]=n)}function Qr(t){return typeof t!="string"||!t.startsWith("hsl")?t:Fi(t)}function Et(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Zr(Qr(t[o]),`MUI: Can't create \`palette.${o}Channel\` because \`palette.${o}\` 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.${o}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function ud(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{}},pd=(t="mui")=>Bc(t);function Qo(t,o,n,i,a){if(!n)return;n=n===!0?{}:n;const c=a==="dark"?"dark":"light";if(!i){o[a]=sd({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=nn({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[a]={...n,palette:d,opacity:{...Gi(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||qi(c)},l}function xd(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:a=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=ad,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...f}=t,b=Object.keys(n)[0],x=i||(n.light&&b!=="light"?"light":b),g=pd(c),{[x]:B,light:y,dark:j,...S}=n,k={...S};let v=B;if((x==="dark"&&!("dark"in n)||x==="light"&&!("light"in n))&&(v=!0),!v)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${x}\` option is either missing or invalid.`:rr(21,x));let w;d&&(w="oklch");const s=Qo(w,k,v,f,x);y&&!k.light&&Qo(w,k,y,void 0,"light"),j&&!k.dark&&Qo(w,k,j,void 0,"dark");let _={defaultColorScheme:x,...s,cssVarPrefix:c,colorSchemeSelector:u,rootSelector:m,getCssVar:g,colorSchemes:k,font:{...Fc(s.typography),...s.font},spacing:ud(f.spacing)};Object.keys(_.colorSchemes).forEach(te=>{const h=_.colorSchemes[te].palette,$=F=>{const X=F.split("-"),xe=X[1],me=X[2];return g(F,h[xe][me])};h.mode==="light"&&(P(h.common,"background","#fff"),P(h.common,"onBackground","#000")),h.mode==="dark"&&(P(h.common,"background","#000"),P(h.common,"onBackground","#fff"));function W(F,X,xe){if(w){let me;return F===Qt&&(me=`transparent ${((1-xe)*100).toFixed(0)}%`),F===ve&&(me=`#000 ${(xe*100).toFixed(0)}%`),F===Se&&(me=`#fff ${(xe*100).toFixed(0)}%`),`color-mix(in ${w}, ${X}, ${me})`}return F(X,xe)}if(dd(h,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),h.mode==="light"){P(h.Alert,"errorColor",W(ve,h.error.light,.6)),P(h.Alert,"infoColor",W(ve,h.info.light,.6)),P(h.Alert,"successColor",W(ve,h.success.light,.6)),P(h.Alert,"warningColor",W(ve,h.warning.light,.6)),P(h.Alert,"errorFilledBg",$("palette-error-main")),P(h.Alert,"infoFilledBg",$("palette-info-main")),P(h.Alert,"successFilledBg",$("palette-success-main")),P(h.Alert,"warningFilledBg",$("palette-warning-main")),P(h.Alert,"errorFilledColor",bt(()=>h.getContrastText(h.error.main))),P(h.Alert,"infoFilledColor",bt(()=>h.getContrastText(h.info.main))),P(h.Alert,"successFilledColor",bt(()=>h.getContrastText(h.success.main))),P(h.Alert,"warningFilledColor",bt(()=>h.getContrastText(h.warning.main))),P(h.Alert,"errorStandardBg",W(Se,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(Se,h.info.light,.9)),P(h.Alert,"successStandardBg",W(Se,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(Se,h.warning.light,.9)),P(h.Alert,"errorIconColor",$("palette-error-main")),P(h.Alert,"infoIconColor",$("palette-info-main")),P(h.Alert,"successIconColor",$("palette-success-main")),P(h.Alert,"warningIconColor",$("palette-warning-main")),P(h.AppBar,"defaultBg",$("palette-grey-100")),P(h.Avatar,"defaultBg",$("palette-grey-400")),P(h.Button,"inheritContainedBg",$("palette-grey-300")),P(h.Button,"inheritContainedHoverBg",$("palette-grey-A100")),P(h.Chip,"defaultBorder",$("palette-grey-400")),P(h.Chip,"defaultAvatarColor",$("palette-grey-700")),P(h.Chip,"defaultIconColor",$("palette-grey-700")),P(h.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),P(h.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),P(h.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),P(h.LinearProgress,"primaryBg",W(Se,h.primary.main,.62)),P(h.LinearProgress,"secondaryBg",W(Se,h.secondary.main,.62)),P(h.LinearProgress,"errorBg",W(Se,h.error.main,.62)),P(h.LinearProgress,"infoBg",W(Se,h.info.main,.62)),P(h.LinearProgress,"successBg",W(Se,h.success.main,.62)),P(h.LinearProgress,"warningBg",W(Se,h.warning.main,.62)),P(h.Skeleton,"bg",w?W(Qt,h.text.primary,.11):`rgba(${$("palette-text-primaryChannel")} / 0.11)`),P(h.Slider,"primaryTrack",W(Se,h.primary.main,.62)),P(h.Slider,"secondaryTrack",W(Se,h.secondary.main,.62)),P(h.Slider,"errorTrack",W(Se,h.error.main,.62)),P(h.Slider,"infoTrack",W(Se,h.info.main,.62)),P(h.Slider,"successTrack",W(Se,h.success.main,.62)),P(h.Slider,"warningTrack",W(Se,h.warning.main,.62));const F=w?W(ve,h.background.default,.6825):mo(h.background.default,.8);P(h.SnackbarContent,"bg",F),P(h.SnackbarContent,"color",bt(()=>w?on.text.primary:h.getContrastText(F))),P(h.SpeedDialAction,"fabHoverBg",mo(h.background.paper,.15)),P(h.StepConnector,"border",$("palette-grey-400")),P(h.StepContent,"border",$("palette-grey-400")),P(h.Switch,"defaultColor",$("palette-common-white")),P(h.Switch,"defaultDisabledColor",$("palette-grey-100")),P(h.Switch,"primaryDisabledColor",W(Se,h.primary.main,.62)),P(h.Switch,"secondaryDisabledColor",W(Se,h.secondary.main,.62)),P(h.Switch,"errorDisabledColor",W(Se,h.error.main,.62)),P(h.Switch,"infoDisabledColor",W(Se,h.info.main,.62)),P(h.Switch,"successDisabledColor",W(Se,h.success.main,.62)),P(h.Switch,"warningDisabledColor",W(Se,h.warning.main,.62)),P(h.TableCell,"border",W(Se,W(Qt,h.divider,1),.88)),P(h.Tooltip,"bg",W(Qt,h.grey[700],.92))}if(h.mode==="dark"){P(h.Alert,"errorColor",W(Se,h.error.light,.6)),P(h.Alert,"infoColor",W(Se,h.info.light,.6)),P(h.Alert,"successColor",W(Se,h.success.light,.6)),P(h.Alert,"warningColor",W(Se,h.warning.light,.6)),P(h.Alert,"errorFilledBg",$("palette-error-dark")),P(h.Alert,"infoFilledBg",$("palette-info-dark")),P(h.Alert,"successFilledBg",$("palette-success-dark")),P(h.Alert,"warningFilledBg",$("palette-warning-dark")),P(h.Alert,"errorFilledColor",bt(()=>h.getContrastText(h.error.dark))),P(h.Alert,"infoFilledColor",bt(()=>h.getContrastText(h.info.dark))),P(h.Alert,"successFilledColor",bt(()=>h.getContrastText(h.success.dark))),P(h.Alert,"warningFilledColor",bt(()=>h.getContrastText(h.warning.dark))),P(h.Alert,"errorStandardBg",W(ve,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(ve,h.info.light,.9)),P(h.Alert,"successStandardBg",W(ve,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(ve,h.warning.light,.9)),P(h.Alert,"errorIconColor",$("palette-error-main")),P(h.Alert,"infoIconColor",$("palette-info-main")),P(h.Alert,"successIconColor",$("palette-success-main")),P(h.Alert,"warningIconColor",$("palette-warning-main")),P(h.AppBar,"defaultBg",$("palette-grey-900")),P(h.AppBar,"darkBg",$("palette-background-paper")),P(h.AppBar,"darkColor",$("palette-text-primary")),P(h.Avatar,"defaultBg",$("palette-grey-600")),P(h.Button,"inheritContainedBg",$("palette-grey-800")),P(h.Button,"inheritContainedHoverBg",$("palette-grey-700")),P(h.Chip,"defaultBorder",$("palette-grey-700")),P(h.Chip,"defaultAvatarColor",$("palette-grey-300")),P(h.Chip,"defaultIconColor",$("palette-grey-300")),P(h.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),P(h.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),P(h.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),P(h.LinearProgress,"primaryBg",W(ve,h.primary.main,.5)),P(h.LinearProgress,"secondaryBg",W(ve,h.secondary.main,.5)),P(h.LinearProgress,"errorBg",W(ve,h.error.main,.5)),P(h.LinearProgress,"infoBg",W(ve,h.info.main,.5)),P(h.LinearProgress,"successBg",W(ve,h.success.main,.5)),P(h.LinearProgress,"warningBg",W(ve,h.warning.main,.5)),P(h.Skeleton,"bg",w?W(Qt,h.text.primary,.13):`rgba(${$("palette-text-primaryChannel")} / 0.13)`),P(h.Slider,"primaryTrack",W(ve,h.primary.main,.5)),P(h.Slider,"secondaryTrack",W(ve,h.secondary.main,.5)),P(h.Slider,"errorTrack",W(ve,h.error.main,.5)),P(h.Slider,"infoTrack",W(ve,h.info.main,.5)),P(h.Slider,"successTrack",W(ve,h.success.main,.5)),P(h.Slider,"warningTrack",W(ve,h.warning.main,.5));const F=w?W(Se,h.background.default,.985):mo(h.background.default,.98);P(h.SnackbarContent,"bg",F),P(h.SnackbarContent,"color",bt(()=>w?Hi.text.primary:h.getContrastText(F))),P(h.SpeedDialAction,"fabHoverBg",mo(h.background.paper,.15)),P(h.StepConnector,"border",$("palette-grey-600")),P(h.StepContent,"border",$("palette-grey-600")),P(h.Switch,"defaultColor",$("palette-grey-300")),P(h.Switch,"defaultDisabledColor",$("palette-grey-600")),P(h.Switch,"primaryDisabledColor",W(ve,h.primary.main,.55)),P(h.Switch,"secondaryDisabledColor",W(ve,h.secondary.main,.55)),P(h.Switch,"errorDisabledColor",W(ve,h.error.main,.55)),P(h.Switch,"infoDisabledColor",W(ve,h.info.main,.55)),P(h.Switch,"successDisabledColor",W(ve,h.success.main,.55)),P(h.Switch,"warningDisabledColor",W(ve,h.warning.main,.55)),P(h.TableCell,"border",W(ve,W(Qt,h.divider,1),.68)),P(h.Tooltip,"bg",W(Qt,h.grey[700],.92))}Et(h.background,"default"),Et(h.background,"paper"),Et(h.common,"background"),Et(h.common,"onBackground"),Et(h,"divider"),Object.keys(h).forEach(F=>{const X=h[F];F!=="tonalOffset"&&X&&typeof X=="object"&&(X.main&&P(h[F],"mainChannel",Zr(Qr(X.main))),X.light&&P(h[F],"lightChannel",Zr(Qr(X.light))),X.dark&&P(h[F],"darkChannel",Zr(Qr(X.dark))),X.contrastText&&P(h[F],"contrastTextChannel",Zr(Qr(X.contrastText))),F==="text"&&(Et(h[F],"primary"),Et(h[F],"secondary")),F==="action"&&(X.active&&Et(h[F],"active"),X.selected&&Et(h[F],"selected")))})}),_=o.reduce((te,h)=>Xe(te,h),_);const I={prefix:c,disableCssColorScheme:a,shouldSkipGeneratingVar:l,getSelector:cd(_),enableContrastVars:d},{vars:R,generateThemeVars:q,generateStyleSheets:Q}=Oc(_,I);return _.vars=R,Object.entries(_.colorSchemes[_.defaultColorScheme]).forEach(([te,h])=>{_[te]=h}),_.generateThemeVars=q,_.generateStyleSheets=Q,_.generateSpacing=function(){return Ni(f.spacing,un(this))},_.getColorSchemeSelector=Ac(u),_.spacing=_.generateSpacing(),_.shouldSkipGeneratingVar=l,_.unstable_sxConfig={...Wo,...f==null?void 0:f.unstable_sxConfig},_.unstable_sx=function(h){return Po({sx:h,theme:this})},_.toRuntimeSource=Yi,_}function ni(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:mn({...n===!0?{}:n.palette,mode:o})})}function md(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:a=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",u=a==null?void 0:a[l],m={...a,...n?{[l]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return nn(t,...o);let f=n;"palette"in t||m[l]&&(m[l]!==!0?f=m[l].palette:l==="dark"&&(f={mode:"dark"}));const b=nn({...t,palette:f},...o);return b.defaultColorScheme=l,b.colorSchemes=m,b.palette.mode==="light"&&(b.colorSchemes.light={...m.light!==!0&&m.light,palette:b.palette},ni(b,"dark",m.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:b.palette},ni(b,"light",m.light)),b}return!n&&!("light"in m)&&l==="light"&&(m.light=!0),xd({...d,colorSchemes:m,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const fd=md();function _t(){const t=vc(fd);return process.env.NODE_ENV!=="production"&&To.useDebugValue(t),t[cl]||t}async function hd(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 a=new AbortController,c=setTimeout(()=>a.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:a.signal})}catch(m){throw clearTimeout(c),(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(c)}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 l;try{l=await d.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(l))u=l;else if(n&&l[n]&&Array.isArray(l[n]))u=l[n];else{const f=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(f)u=l[f];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:u,source:t,fetchedAt:new Date().toISOString()}}function gd(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 yd={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}]};function ne(t,o){return gd(t,yd[o])}function bd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:a}){const[c,d]=p.useState(""),[l,u]=p.useState(!1),[m,f]=p.useState(""),[b,x]=p.useState(null),[g,B]=p.useState(null),[y,j]=p.useState(!1),[S,k]=p.useState(""),v=p.useRef(null),[w,s]=p.useState("json"),[_,I]=p.useState(""),[R,q]=p.useState(""),[Q,te]=p.useState(""),[h,$]=p.useState("idle"),[W,F]=p.useState(""),[X,xe]=p.useState(null),[me,Y]=p.useState(0),A=async N=>{if(k(""),!N.name.endsWith(".json")){k("Only .json files are allowed");return}const se=10*1024*1024;if(N.size>se){k("File size exceeds 10MB limit");return}try{const ce=await N.text();let ae;try{ae=JSON.parse(ce)}catch{k("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ae)){k("JSON must be an array of objects");return}if(ae.length===0){k("No data rows found in JSON file");return}x(N),B(ae)}catch{k("Network error — please try again")}},V=N=>{N.preventDefault();const se=N.dataTransfer.files[0];se&&A(se)},oe=async()=>{if(_.trim()){$("loading"),F("");try{const N=await hd(_.trim(),R.trim()||void 0,Q.trim()||void 0);xe(N.data),Y(N.data.length),$("ready")}catch(N){F((N==null?void 0:N.message)||"Connection failed"),$("error")}}},J=()=>{if(!c.trim()){u(!0);return}const N=w==="api"?X:i||g;N&&(n(c.trim(),m.trim(),N),ee())},ee=()=>{d(""),u(!1),f(""),x(null),B(null),k(""),s("json"),I(""),q(""),te(""),$("idle"),F(""),xe(null),Y(0),o()},le=i||g,ie=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:ee,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:N=>ne(N,"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:ee,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(T.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:c,onChange:N=>{d(N.target.value),l&&N.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:ie,helperText:ie?"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:m,onChange:N=>f(N.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:w==="json"?0:1,onChange:(N,se)=>{s(se===0?"json":"api"),$("idle"),F("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(T.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(T.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),w==="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:N=>z(N.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:N=>z(N.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(T.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:a||`${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(T.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:V,onDragOver:N=>N.preventDefault(),onPaste:N=>N.preventDefault(),onClick:()=>{var N;return(N=v.current)==null?void 0:N.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":S?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?N=>z(N.palette.success.main,.04):S?N=>z(N.palette.error.main,.04):N=>z(N.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?N=>z(N.palette.success.main,.08):S?N=>z(N.palette.error.main,.08):N=>z(N.palette.primary.main,.08),borderColor:g?"success.dark":S?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:v,type:"file",accept:".json",sx:{display:"none"},onChange:N=>{var se;return((se=N.target.files)==null?void 0:se[0])&&A(N.target.files[0])}}),g?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:N=>z(N.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(T.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:b==null?void 0:b.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:N=>z(N.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(T.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"}),S&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:N=>z(N.palette.error.main,.08),border:1,borderColor:N=>z(N.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:S})})]})]})]})}),w==="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:_,onChange:N=>{I(N.target.value),$("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:N=>q(N.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.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}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:Q,onChange:N=>te(N.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:!_.trim()||h==="loading",onClick:oe,startIcon:h==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(T.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:N=>z(N.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:h==="loading"?"Connecting...":"Test Connection & Load Data"}),h==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:N=>z(N.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(T.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:[me.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:_})]})]}),h==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:N=>z(N.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(T.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:ee,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:N=>z(N.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:J,disabled:w==="json"&&!le||w==="api"&&h!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:y,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(T.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:`[
|
|
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
|
-
]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>
|
|
79
|
+
]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>j(!1),variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2}},children:"Got it"})})]})]})}function Ji({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:n=>ne(n,"menu"),display:"flex",flexDirection:"column"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["JSON Format Guide",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(T.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,sx:{overflowY:"auto",flex:1},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:3,py:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Expected JSON Structure"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["The uploaded JSON must be an ",e.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."]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Example JSON"}),e.jsx(r.Paper,{elevation:0,sx:{p:2,bgcolor:"action.hover",border:1,borderColor:"divider",borderRadius:1,overflowX:"auto"},children:e.jsx(r.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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"#ffffff",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Got it"})})]}):null}function ud({onFileUpload:t,onError:o,isUploading:n}){const[i,a]=u.useState(!1),[c,d]=u.useState(""),[l,p]=u.useState(!1),x=u.useRef(null),f=async v=>{if(!v.name.endsWith(".json")){o("Only .json files are allowed");return}const k=10*1024*1024;if(v.size>k){o("File size exceeds 10MB limit");return}d(v.name);try{const S=await v.text();let T;try{T=JSON.parse(S)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(T)){o("JSON must be an array of objects");return}if(T.length===0){o("No data rows found in JSON file");return}t(T)}catch{o("Network error — please try again")}finally{d("")}},b=v=>{v.preventDefault(),a(!0)},m=v=>{v.preventDefault(),a(!1)},g=v=>{v.preventDefault(),a(!1);const k=v.dataTransfer.files[0];k&&f(k)},z=()=>{var v;(v=x.current)==null||v.click()},y=v=>{var S;const k=(S=v.target.files)==null?void 0:S[0];k&&f(k)},C=v=>{v.stopPropagation(),p(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:m,onDrop:g,onPaste:v=>v.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?v=>D(v.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:x,type:"file",accept:".json",onChange:y,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..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:v=>D(v.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.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:C,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:e.jsx(w.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(Vi,{isOpen:l,onClose:()=>p(!1)})]})}function pd({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?a=>D(a.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(w.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 xd({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=>D(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=>D(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.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(w.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Hi({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=>D(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(w.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 md({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:a,onDeleteHistory:c,disabled:d}){const[l,p]=u.useState(!1),[x,f]=u.useState(!1),[b,m]=u.useState(-1),g=u.useRef(null),z=u.useRef(null);u.useEffect(()=>{function $(G){g.current&&!g.current.contains(G.target)&&(p(!1),f(!1))}return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[]);const y=u.useCallback(()=>{f(!0),m(-1),n.length>0&&p(!0)},[n.length]),C=u.useCallback($=>{o($),m(-1)},[o]),v=u.useCallback($=>{var G;o($),i($),p(!1),(G=z.current)==null||G.blur()},[o,i]),k=u.useCallback($=>{m(-1),v($)},[v]),S=u.useCallback($=>{var G;$.key==="Enter"?b>=0&&b<n.length?($.preventDefault(),k(n[b].query)):t.trim()&&v(t.trim()):$.key==="Escape"?(p(!1),m(-1),(G=z.current)==null||G.blur()):$.key==="ArrowDown"?($.preventDefault(),n.length>0&&(l||p(!0),m(Z=>Z<n.length-1?Z+1:Z))):$.key==="ArrowUp"&&($.preventDefault(),m(Z=>Z>0?Z-1:-1))},[b,n,t,l,k,v]),T=u.useCallback(()=>{var $;o(""),($=z.current)==null||$.focus()},[o]),s=u.useMemo(()=>n.filter($=>$.isFavourite),[n]),M=u.useMemo(()=>n.filter($=>!$.isFavourite),[n]),B=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:z,size:"small",fullWidth:!0,value:t,onChange:$=>C($.target.value),onFocus:y,onKeyDown:S,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.30)`,transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.50)`},"&.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(w.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:T,edge:"end",sx:{mr:-.5},children:e.jsx(w.Close,{sx:{fontSize:16}})})}):null}}),B&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[s.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"}),s.map(($,G)=>e.jsx(Zn,{entry:$,isSelected:b===G,onClick:()=>k($.query),onToggleFavourite:()=>a($.query),onDelete:()=>c($.query)},`fav-${$.query}`))]}),M.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[s.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"}),M.map(($,G)=>{const Z=s.length+G;return e.jsx(Zn,{entry:$,isSelected:b===Z,onClick:()=>k($.query),onToggleFavourite:()=>a($.query),onDelete:()=>c($.query)},`recent-${$.query}`)})]})]})]})}const Zn=u.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:a,onDelete:c}){const d=u.useCallback(p=>{p.stopPropagation(),a()},[a]),l=u.useCallback(p=>{p.stopPropagation(),c()},[c]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?p=>D(p.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?p=>D(p.palette.primary.main,.12):"action.hover"}},children:[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:d,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(w.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(w.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(w.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function fd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:a,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:p,onPermanentDelete:x,isReadOnly:f,isAdmin:b=!1}){const m=It(),[g,z]=u.useState(!1),[y,C]=u.useState(!1),[v,k]=u.useState({top:0,left:0}),[S,T]=u.useState(null),s=u.useRef(null),M=u.useRef(null),B=t.find(A=>A.id===o),$=B==null?void 0:B.isDefault,G=t.filter(A=>A.scope==="global"&&!A.isDeleted),Z=t.filter(A=>A.scope!=="global"&&!A.isDeleted),ee=t.filter(A=>A.isFavorite&&!A.isDeleted).sort((A,V)=>(V.updatedAt||0)-(A.updatedAt||0)),h=t.filter(A=>A.isDeleted);u.useEffect(()=>{if(g&&M.current){const A=M.current.getBoundingClientRect();k({top:A.bottom+window.scrollY+8,left:A.right+window.scrollX-320})}},[g]),u.useEffect(()=>{const A=V=>{s.current&&!s.current.contains(V.target)&&M.current&&!M.current.contains(V.target)&&z(!1)};return g&&document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[g]);const R=A=>{if(n&&A!==o){T(A),z(!1);return}i(A),z(!1)},W=()=>{S&&(i(S),T(null))},H=()=>{T(null)},K=(A,V=!1)=>{const q=A.scope==="global",re=!f&&(!q||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===A.id?m.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===A.id?m.palette.primary.light+"20":m.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>R(A.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,textTransform:"none",justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===A.id&&e.jsx(w.Check,{sx:{fontSize:16,flexShrink:0}}),o!==A.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===A.id?m.palette.primary.dark:m.palette.text.primary,fontWeight:o===A.id?500:400},children:A.name}),V&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[re&&l&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),l(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:A.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(w.Star,{sx:{fontSize:16}})}),re&&d&&!A.isDefault&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),d(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Set as default",children:e.jsx(w.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},A.id)},de=A=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:m.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:m.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:A.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[p&&e.jsx(r.IconButton,{onClick:V=>{V.stopPropagation(),p(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Restore view",children:e.jsx(w.Undo,{sx:{fontSize:16,color:"success.main"}})}),x&&e.jsx(r.IconButton,{onClick:V=>{V.stopPropagation(),x(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Delete permanently",children:e.jsx(w.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},A.id),ue=n||!$,te=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:M,onClick:()=>z(!g),size:"small",sx:{position:"relative",color:ue?"warning.main":"text.secondary",bgcolor:ue?D(m.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ue?D(m.palette.warning.main,.2):D(m.palette.text.primary,.06),color:ue?"warning.dark":"text.primary"}},title:`View: ${(B==null?void 0:B.name)||"Default View"}`,children:[e.jsx(w.Visibility,{sx:{fontSize:20}}),te&&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"}})]}),g&&ui.createPortal(e.jsxs(r.Box,{ref:s,sx:{position:"fixed",width:"320px",backgroundColor:m.palette.background.paper,border:`1px solid ${m.palette.divider}`,borderRadius:1,boxShadow:m.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:v.top,left:v.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:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),G.map(A=>K(A,A.isDefault))]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.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:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(w.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),ee.map(A=>K(A))]})]}),Z.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.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:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),Z.map(A=>K(A))]})]}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>C(!y),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",h.length,")"]}),e.jsx(w.ChevronRight,{sx:{fontSize:16}})]}),y&&e.jsx(r.Box,{sx:{backgroundColor:m.palette.grey[50]},children:h.map(A=>de(A))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{a(),z(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsx(w.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),z(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsx(w.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:S!==null,onClose:H,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(w.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:H,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function hd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:a,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:p,onSortDescending:x,onRemoveSort:f,onFilter:b,onClearFilter:m,onGroupByColumn:g,onHideColumn:z,onManageColumns:y,onManageViews:C,onResetLayout:v,onClose:k}){var ee,h;const T=It().palette,s=u.useRef(null);u.useEffect(()=>{if(!s.current)return;const R=s.current,W=R.getBoundingClientRect(),H=window.innerWidth,K=window.innerHeight;W.right>H-8&&(R.style.left=`${H-W.width-8}px`),W.bottom>K-8&&(R.style.top=`${K-W.height-8}px`)},[l]),u.useEffect(()=>{const R=H=>{s.current&&!s.current.contains(H.target)&&k()},W=H=>{H.key==="Escape"&&k()};return document.addEventListener("mousedown",R),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",R),document.removeEventListener("keydown",W)}},[k]);const M=u.useCallback(R=>()=>{R(),k()},[k]),B=(n==null?void 0:n.direction)==="asc",$=(n==null?void 0:n.direction)==="desc",G=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",Z=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return ui.createPortal(e.jsxs(r.Paper,{ref:s,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:1400,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",boxShadow:`0 4px 20px ${D(((ee=T.common)==null?void 0:ee.black)??"#000",.12)}, 0 1px 4px ${D(((h=T.common)==null?void 0:h.black)??"#000",.06)}`},children:[!c&&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:M(()=>p(t)),sx:{p:.625,borderRadius:"6px",color:B?"primary.main":"text.secondary",bgcolor:B?D(T.primary.main,.1):"transparent","&:hover":{bgcolor:D(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${Z})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:M(()=>x(t)),sx:{p:.625,borderRadius:"6px",color:$?"primary.main":"text.secondary",bgcolor:$?D(T.primary.main,.1):"transparent","&:hover":{bgcolor:D(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.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:!a,onClick:M(()=>f(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(T.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(w.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:M(()=>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(w.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&&!c&&e.jsxs(r.MenuItem,{onClick:M(()=>m(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(T.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(w.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&g&&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:M(()=>g(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.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:[!c&&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:M(()=>z(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(w.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:M(y),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:M(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),C&&e.jsxs(r.MenuItem,{onClick:M(C),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!c&&d&&v&&e.jsxs(r.MenuItem,{onClick:M(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(T.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(w.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const gd=176,Qn="COLUMN_HEADER",yd=u.memo(function({column:o,index:n,sortRule:i,hasFilters:a,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:p,onColumnClick:x,onMoveColumn:f,onResizeStart:b,onSortAscending:m,onSortDescending:g,onRemoveSort:z,onOpenFilterForColumn:y,onClearFiltersForColumn:C,onGroupByColumn:v,onHideColumn:k,onManageColumns:S,onManageViews:T,onResetLayout:s}){const M=u.useRef(null),[B,$]=u.useState(!1),[G,Z]=u.useState({x:0,y:0}),[{handlerId:ee,isOver:h},R]=kt.useDrop({accept:Qn,collect(q){return{handlerId:q.getHandlerId(),isOver:q.isOver()}},hover(q,re){var se;if(!M.current)return;const Q=q.index,le=n;if(Q===le)return;const oe=(se=M.current)==null?void 0:se.getBoundingClientRect(),N=(oe.right-oe.left)/2,ne=re.getClientOffset(),ce=((ne==null?void 0:ne.x)??0)-oe.left;Q<le&&ce<N||Q>le&&ce>N||(f(Q,le),q.index=le)}}),[{isDragging:W},H]=kt.useDrag({type:Qn,item:()=>({index:n,columnName:o.name}),collect:q=>({isDragging:q.isDragging()})});H(R(M));const K=u.useCallback(q=>{q.preventDefault(),q.stopPropagation(),Z({x:q.clientX,y:q.clientY}),$(!0)},[]),de=u.useCallback(()=>$(!1),[]),ue=u.useCallback(()=>{x(o.name)},[x,o.name]),te=u.useCallback(q=>{q.stopPropagation(),y(o.name)},[y,o.name]),A=u.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(w.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]),V=u.useCallback(()=>a?e.jsx(w.FilterList,{onClick:te,title:"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,[a,te]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:M,"data-handler-id":ee,"data-column-index":n,onClick:ue,onContextMenu:K,sx:{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?q=>D(q.palette.primary.main,.08):"action.hover",boxShadow:"0 1px 0 rgba(0,0,0,0.08)",backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:q=>D(q.palette.primary.main,.1),color:"primary.dark"},width:p?`${p}px`:`${gd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Ue(o.name),A(),V()]}),e.jsx(r.Box,{sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),b(q,o.name)},onClick:q=>q.stopPropagation(),children:e.jsx(r.Box,{sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),h&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),B&&e.jsx(hd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:a,isInSortStack:c,isReadOnly:d,hasModifications:l,position:G,onSortAscending:m,onSortDescending:g,onRemoveSort:z,onFilter:y,onClearFilter:C,onGroupByColumn:v,onHideColumn:k,onManageColumns:S,onManageViews:T,onResetLayout:s,onClose:de})]})});function bd({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:a,onClearSelection:c,onBulkSetFavorites:d}){const[l,p]=u.useState(null),x=u.useMemo(()=>Array.from(o),[o]),f=u.useMemo(()=>x.filter(v=>n.has(v)),[x,n]),b=u.useMemo(()=>x.filter(v=>!n.has(v)),[x,n]),m=f.length>0,g=b.length>0;if(t===0)return null;const z=()=>{d&&d(x,!0)},y=()=>{d&&d(x,!1)},C=v=>{a(v),p(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:v=>D(v.palette.primary.main,.08),borderBottom:v=>`1px solid ${D(v.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(w.Close,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:v=>D(v.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:v=>p(v.currentTarget),startIcon:e.jsx(w.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>D(v.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:v=>D(v.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:l,open:!!l,onClose:()=>p(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:180,borderRadius:1.5}},children:[e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:z,startIcon:e.jsx(w.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>D(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>D(v.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&m&&e.jsx(r.Button,{onClick:y,startIcon:e.jsx(w.Star,{sx:{fontSize:16,color:"#fbbc04"}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>D(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>D(v.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const vd={active:{bg:"#e6f4ea",color:"#137333"},completed:{bg:"#e6f4ea",color:"#137333"},approved:{bg:"#e6f4ea",color:"#137333"},success:{bg:"#e6f4ea",color:"#137333"},done:{bg:"#e6f4ea",color:"#137333"},contract:{bg:"#e8eaf6",color:"#3949ab"},"in progress":{bg:"#e8eaf6",color:"#3949ab"},"in review":{bg:"#e8eaf6",color:"#3949ab"},review:{bg:"#e8eaf6",color:"#3949ab"},pending:{bg:"#e8eaf6",color:"#3949ab"},"on leave":{bg:"#fce8e6",color:"#c5221f"},"on hold":{bg:"#fff8e1",color:"#e65100"},probation:{bg:"#fff8e1",color:"#e65100"},cancelled:{bg:"#fce8e6",color:"#c5221f"},rejected:{bg:"#fce8e6",color:"#c5221f"},blocked:{bg:"#fce8e6",color:"#c5221f"},inactive:{bg:"#f1f3f4",color:"text.secondary"},"not started":{bg:"#f1f3f4",color:"text.secondary"},paused:{bg:"#f1f3f4",color:"text.secondary"}},Sd={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function jd(t){const o=t.toLowerCase().trim(),n=vd[o]||{bg:"#f1f3f4",color:"text.secondary"};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.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function Cd(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 jd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const a=Sd[n.toLowerCase().trim()];return a?e.jsx(r.Box,{component:"span",sx:{color:a,fontWeight:600,fontSize:"0.8125rem"},children:n}):e.jsx(r.Box,{component:"span",sx:{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 wd(t){const o=t.find(a=>{const c=a.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(c)})||t[0]||null,n=t.find(a=>{const c=a.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(c)&&a!==o})||null,i=t.filter(a=>a!==o&&a!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function kd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:a,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:p,onEdit:x,onDuplicate:f,onDelete:b}){const[m,g]=u.useState(null),[z,y]=u.useState(!1),{primaryCol:C,idCol:v,bodyColumns:k}=u.useMemo(()=>wd(n),[n]),S=C?t[C.name]:null,T=v?t[v.name]:null,s=z||i||a||!!m;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":M=>D(M.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?M=>`0 0 0 3px ${D(M.palette.primary.main,.15)}, 0 2px 8px ${D(M.palette.common.black,.08)}`:z?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:z&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:M=>D(M.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:S!=null&&S!==""?String(S):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:[k.map(M=>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:Ue(M.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:Cd(M,t[M.name])})]},M.name)),k.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:M=>D(M.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:T?.85:0,userSelect:"none"},children:T?String(T):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:s?1:0,transition:"opacity 0.15s ease"},onClick:M=>M.stopPropagation(),children:[l&&e.jsx(r.Tooltip,{title:a?"Remove from favorites":"Add to favorites",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),l(t)},sx:{width:28,height:28,color:a?"#fbbc04":"action.disabled","&:hover":{bgcolor:M=>D(M.palette.warning.main,.1),color:"#fbbc04"}},children:a?e.jsx(w.Star,{sx:{fontSize:17}}):e.jsx(w.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),g(M.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:M=>D(M.palette.text.primary,.08)}},children:e.jsx(w.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!m,anchorEl:m,onClose:()=>g(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:"0 4px 20px rgba(60,64,67,0.15), 0 1px 6px rgba(60,64,67,0.1)"}},onClick:M=>M.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{p(t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{x(t,o),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{b(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(w.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Td({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:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:a=>D(a.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:bi(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:a=>D(a.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(([a,c])=>yi(c)).filter(Boolean).join(" • ")})]})}function Id({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:a,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:p,onToggleRowSelection:x,onToggleRowFavorite:f,onToggleGroupCollapse:b,onViewRow:m,onEditRow:g,onDuplicateRow:z,onDeleteRow:y}){const C=u.useMemo(()=>{const v=new Set;return i.forEach(k=>{const S=k==null?void 0:k.__urm_row_id__;S!==void 0&&v.add(S)}),v},[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,{children:[p&&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(v=>{const k=l.find(S=>S.column===v.name);return e.jsxs(r.Box,{onClick:()=>p(v.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:k?"primary.main":"divider",bgcolor:k?S=>D(S.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:S=>D(S.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:k?600:400,color:k?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ue(v.name)}),k?k.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(w.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(w.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},v.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((v,k)=>d&&v.isGroupHeader?e.jsx(Td,{row:v,grouping:n,onToggleCollapse:b||(()=>{})},`group-${v.groupKey}`):e.jsx(kd,{row:v,rowIndex:k,visibleColumns:o,isSelected:C.has(v==null?void 0:v.__urm_row_id__),isFavorite:a.has(v),isReadOnly:c,onToggleSelection:()=>x(v),onToggleFavorite:f,onView:m,onEdit:g,onDuplicate:z,onDelete:y},`card-${k}`))})]})}const ei=[10,15,25,50,100];function zd(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 Ed({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:a,onPageSizeChange:c}){var R;const l=It().palette,p=Math.ceil(n/o),[x,f]=u.useState(String(t)),[b,m]=u.useState(null),[g,z]=u.useState(!1),y=u.useRef(null);u.useEffect(()=>{g||(f(String(t)),m(null))},[t,g]);const C=u.useCallback(()=>{const W=zd(x,p);if(W){m(W);return}const H=parseInt(x.trim(),10);m(null),z(!1),H!==t&&a(H)},[x,p,t,a]),v=u.useCallback(W=>{var H;W.key==="Enter"?(W.preventDefault(),C()):W.key==="Escape"&&(f(String(t)),m(null),z(!1),(H=y.current)==null||H.blur())},[C,t]),k=u.useCallback(()=>{f(String(t)),m(null),z(!1)},[t]),S=u.useCallback(()=>{z(!0),m(null),setTimeout(()=>{var W;return(W=y.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ei))return null;const T=()=>{f(String(t)),m(null),z(!1)},s=()=>{T(),a(1)},M=()=>{T(),t>1&&a(t-1)},B=()=>{T(),t<p&&a(t+1)},$=()=>{T(),a(p)},G=(t-1)*o+1,Z=Math.min(t*o,n),ee=`${Math.max(2,String(p).length+.5)}ch`,h={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=>c(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:ei.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,"–",Z," 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:[b&&e.jsx(r.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:D(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${D(((R=l.common)==null?void 0:R.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:D(l.error.main,.4)}},children:e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:b})}),e.jsx(r.InputBase,{inputRef:y,value:x,onChange:W=>{f(W.target.value),b&&m(null)},onKeyDown:v,onFocus:S,onBlur:k,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:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":g?"primary.main":"divider",borderRadius:"4px",bgcolor:b?D(l.error.main,.04):g?D(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:b?"error.main":"text.secondary"},"&:focus-within":{boxShadow:b?`0 0 0 2px ${D(l.error.main,.2)}`:`0 0 0 2px ${D(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:s,disabled:t===1,size:"small",title:"First page",sx:h,children:e.jsx(w.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:M,disabled:t===1,size:"small",title:"Previous page",sx:h,children:e.jsx(w.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:B,disabled:t===p,size:"small",title:"Next page",sx:h,children:e.jsx(w.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:$,disabled:t===p,size:"small",title:"Last page",sx:h,children:e.jsx(w.LastPage,{sx:{fontSize:20}})})]})]})]})}function Bd(){return e.jsx(r.Chip,{icon:e.jsx(w.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const Ui="urm_hint_seen_";function Dd(t){try{return localStorage.getItem(Ui+t)==="true"}catch{return!1}}function Od(t){try{localStorage.setItem(Ui+t,"true")}catch{}}function ti(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 ri(t){const o={fontSize:11};switch(t){case"number":return e.jsx(w.Numbers,{sx:o});case"boolean":return e.jsx(w.CheckBox,{sx:o});case"array":return e.jsx(w.DataArray,{sx:o});case"object":return e.jsx(w.DataObject,{sx:o});default:return e.jsx(w.TextFields,{sx:o})}}function oi(t,o){var n,i;switch(t){case"number":return{bg:D(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:D(((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:D(o.secondary.main,.08),color:o.secondary.main};default:return{bg:D(o.text.secondary,.07),color:o.text.secondary}}}function Ad({open:t,onClose:o,row:n,schema:i,reportName:a}){var b,m;const d=It().palette;if(!n)return null;const l=i.filter(g=>g.name in n),p=l.filter(g=>g.type!=="object"&&g.type!=="array"),x=l.filter(g=>g.type==="object"||g.type==="array"),f=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${D(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${D(((m=d.common)==null?void 0:m.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:D(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.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"}),a&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a," · ",f," ",f===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(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:D(d.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:x.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:p.map((g,z)=>{const y=n[g.name],C=ti(y,g.type),v=!C,k=oi(g.type,d),S=z===p.length-1&&p.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:S?"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:k.bg,color:k.color,flexShrink:0},children:ri(g.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:Ue(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:v?400:500,color:v?"text.disabled":"text.primary",fontStyle:v?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:v?"No value":C})]},g.name)})}),x.map(g=>{const z=n[g.name],y=ti(z,g.type),C=!y,v=oi(g.type,d);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:v.bg,color:v.color},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ue(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:v.bg,color:v.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:D(d.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:C?"text.disabled":"text.primary",fontStyle:C?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:C?"No value":y})]},g.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(w.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",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:3,py:.75,borderRadius:"8px",minWidth:80},children:"Close"})})]})}function Md({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},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:"#fce8e6",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.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:"#f1f3f4",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:"#fce8e6",border:"1px solid #f28b82"},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:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",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(w.DeleteForever,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Yo(t){const o={fontSize:11};switch(t){case"number":return e.jsx(w.Numbers,{sx:o});case"boolean":return e.jsx(w.CheckBox,{sx:o});case"array":return e.jsx(w.DataArray,{sx:o});case"object":return e.jsx(w.DataObject,{sx:o});default:return e.jsx(w.TextFields,{sx:o})}}function ni(t,o){var n,i;switch(t){case"number":return{bg:D(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:D(((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:D(o.secondary.main,.08),color:o.secondary.main};default:return{bg:D(o.text.secondary,.07),color:o.text.secondary}}}function _d({open:t,onClose:o,onSave:n,row:i,schema:a,reportName:c}){var C,v,k;const l=It().palette,[p,x]=u.useState({});if(u.useEffect(()=>{t&&i&&x({...i})},[t,i]),!i)return null;const f=a.filter(S=>S.name in i),b=f.filter(S=>S.type!=="object"&&S.type!=="array"),m=f.filter(S=>S.type==="object"||S.type==="array"),g=(S,T)=>{x(s=>({...s,[S]:T}))},z=()=>{const S={...p};f.forEach(T=>{const s=p[T.name];if(T.type==="number"){const M=Number(s);S[T.name]=isNaN(M)?i[T.name]:M}else T.type==="boolean"&&(S[T.name]=!!s)}),n(S),o()},y=f.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${D(((C=l.common)==null?void 0:C.black)??"#000",.14)}, 0 2px 8px ${D(((v=l.common)==null?void 0:v.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:D(((k=l.warning)==null?void 0:k.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.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"}),c&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c," · ",y," ",y===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(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:D(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[b.length>0&&e.jsxs(r.Box,{children:[b.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:b.map((S,T)=>{const s=p[S.name],M=ni(S.type,l),B=S.type==="boolean",$=!B&&T===b.filter(Z=>Z.type!=="boolean").length-1&&b.filter(Z=>Z.type!=="boolean").length%2!==0,G=B||$;return S.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:M.bg,color:M.color},children:Yo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ue(S.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:s?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!s,onChange:Z=>g(S.name,Z.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},S.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 ${D(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:D(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:M.bg,color:M.color},children:Yo(S.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:Ue(S.name)})]}),e.jsx(r.TextField,{value:s??"",onChange:Z=>g(S.name,Z.target.value),type:S.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${S.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:S.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},S.name)})})]}),m.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(w.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:m.map(S=>{const T=i[S.name];let s="";try{s=T==null?"":JSON.stringify(T,null,2)}catch{s=String(T)}const M=ni(S.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:D(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:M.bg,color:M.color},children:Yo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ue(S.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:D(l.text.secondary,.07),color:"text.secondary",border:"none"}})]}),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:s?"text.primary":"text.disabled",fontStyle:s?"normal":"italic",bgcolor:D(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:s||"No value"})]},S.name)})})]}),f.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(w.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:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:z,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const ii=170,$d={active:{bg:"success.lighter",color:"success.dark"},completed:{bg:"success.lighter",color:"success.dark"},approved:{bg:"success.lighter",color:"success.dark"},success:{bg:"success.lighter",color:"success.dark"},done:{bg:"success.lighter",color:"success.dark"},contract:{bg:"primary.lighter",color:"primary.main"},"in progress":{bg:"primary.lighter",color:"primary.main"},"in review":{bg:"primary.lighter",color:"primary.main"},review:{bg:"primary.lighter",color:"primary.main"},pending:{bg:"primary.lighter",color:"primary.main"},"on leave":{bg:"error.lighter",color:"error.dark"},"on hold":{bg:"warning.lighter",color:"warning.dark"},probation:{bg:"warning.lighter",color:"warning.dark"},cancelled:{bg:"error.lighter",color:"error.dark"},rejected:{bg:"error.lighter",color:"error.dark"},blocked:{bg:"error.lighter",color:"error.dark"},inactive:{bg:"action.selected",color:"text.secondary"},"not started":{bg:"action.selected",color:"text.secondary"},paused:{bg:"action.selected",color:"text.secondary"},good:{bg:"success.lighter",color:"success.dark"},excellent:{bg:"success.lighter",color:"success.dark"},average:{bg:"warning.lighter",color:"warning.dark"},moderate:{bg:"warning.lighter",color:"warning.dark"},poor:{bg:"error.lighter",color:"error.dark"},bad:{bg:"error.lighter",color:"error.dark"},critical:{bg:"error.lighter",color:"error.dark"},open:{bg:"primary.lighter",color:"primary.main"},closed:{bg:"action.selected",color:"text.secondary"},verified:{bg:"success.lighter",color:"success.dark"},unverified:{bg:"warning.lighter",color:"warning.dark"}},Rd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Wd(t){const o=t.toLowerCase().trim(),n=$d[o]||{bg:"grey.100",color:"grey.600"};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.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Pd(t){const o=t.toLowerCase().trim(),n=Rd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Nd(t){return e.jsx(r.Box,{component:"span",sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.8125rem",fontWeight:400,letterSpacing:"0.04em"},children:t})}function Ld(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),a=o.findIndex(x=>x.name===t.name),c=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),d=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),l=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),p=a===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||p&&!l}function Fd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Vd(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const a=String(o),c=t.name.toLowerCase().replace(/[_\s-]/g,""),d=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(d)return Wd(a);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Pd(a);const p=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(a);if(p)return Nd(a);if(n&&!d&&!l&&!p)return Fd(a);if(t.type==="date"){const x=t.dateFormat??"iso",f=Hs(o,x,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:f})}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:"grey.400"},children:"[ ]"});const x=o.slice(0,3).map(f=>typeof f=="object"?JSON.stringify(f):String(f)).join(", ");return e.jsxs(r.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[x,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const x=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:x,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:x.length>40?x.slice(0,40)+"…":x})}return a}function Hd({schema:t,data:o,sortStack:n=[],filters:i=[],views:a=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:p={},columnOrder:x=[],columnWidths:f={},grouping:b=null,onSort:m,onSortAscending:g,onSortDescending:z,onOpenFilters:y,onOpenSort:C,onOpenFilterForColumn:v,onSelectView:k,onCreateView:S,onManageViews:T,onUpdateCurrentView:s,onSaveAsNewView:M,onToggleDefault:B,onToggleFavorite:$,onRestoreView:G,onPermanentDelete:Z,isAdmin:ee=!1,onExport:h,onOpenColumns:R,onUpdateColumnWidth:W,onUpdateColumnOrder:H,onUpdateColumnVisibility:K,onClearFiltersForColumn:de,onResetLayout:ue,onOpenGroup:te,onGroupByColumn:A,onToggleGroupCollapse:V,onOpenAuditHistory:q,onOpenScheduledReports:re,searchQuery:Q,searchHistory:le=[],onAddToSearchHistory:oe,onToggleSearchFavourite:N,onDeleteSearchHistory:ne,selectedRowIds:ce=new Set,onSearchChange:se,onToggleRowSelection:fe,onToggleAllRows:J,onRangeSelection:Me,onClearSelection:Ne,onExportSelected:et,currentPage:Qt=1,pageSize:gr=15,totalRowsBeforePagination:$t=o.length,onPageChange:ot,onPageSizeChange:Le,isReadOnly:Ee=!1,userRole:mt,reportName:nt,onEditRow:tt,onDuplicateRow:Ge,onDeleteRow:ft,favoriteRowIndices:er=[],resolvedFavoritesSet:qe=new Set,showFavoritesOnly:Je=!1,onToggleRowFavorite:$e,onBulkSetFavorites:tr,showDevPanel:ht=!1,onOpenDevConfig:zt,onToggleFavoritesFilter:rr}){var Ut;const[it,yr]=u.useState(null),[br,vr]=u.useState(0),[Rt,Sr]=u.useState(0),Ke=((Ut=Kt().dates)==null?void 0:Ut.displayFormat)??null,[be,Cr]=u.useState(null),[or,rt]=u.useState(null),[L,Fe]=u.useState(null),[ve,Re]=u.useState(!1),[wr,Wt]=u.useState(!1),[gt,Pt]=u.useState(null),[Nt,Et]=u.useState(""),[kr,Lt]=u.useState(!1),[Oe,X]=u.useState(null),[yt,he]=u.useState(null),[Se,Xe]=u.useState(null),[Tr,bt]=u.useState(null),[We,nr]=u.useState("list"),[Ir,ir]=u.useState(!1),[vt,zr]=u.useState(()=>!Dd("toolbar_search"));u.useRef(null);const Bt=u.useRef(null),Ft=u.useRef(null),St=u.useCallback(()=>{Od("toolbar_search"),zr(!1)},[]);u.useEffect(()=>{if(!vt)return;const I=setTimeout(St,2e3);return()=>clearTimeout(I)},[vt,St]);const sr=u.useMemo(()=>x.length>0?x.map(I=>t.find(F=>F.name===I)).filter(I=>I!==void 0):t,[x,t]),Be=u.useMemo(()=>sr.filter(I=>p[I.name]!==!1),[sr,p]),Pe=u.useMemo(()=>t.filter(I=>p[I.name]===!1).length,[t,p]),Vt=u.useMemo(()=>t.map(I=>I.name),[t]),st=u.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(Vt),[x,Vt]),Er=u.useCallback((I,F)=>{I.preventDefault(),I.stopPropagation(),yr(F),vr(I.clientX),Sr(f[F]||150)},[f]);u.useEffect(()=>{if(!it)return;const I=ie=>{const we=ie.clientX-br,ae=Math.max(100,Math.min(600,Rt+we));W==null||W(it,ae)},F=()=>{yr(null)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",F),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",F)}},[it,br,Rt,W]);const Br=u.useCallback(I=>I==null?"-":typeof I=="object"?JSON.stringify(I):typeof I=="boolean"?I?"true":"false":String(I),[]);u.useCallback(I=>{const F=n.find(ie=>ie.column===I);return F?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[F.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:14}}):e.jsx(w.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:F.priority})]}):null},[n]),u.useCallback(I=>i.some(ie=>ie.column===I)?e.jsx(r.IconButton,{size:"small",onClick:ie=>{ie.stopPropagation(),v==null||v(I)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(w.FilterList,{sx:{fontSize:14}})}):null,[i,v]);const Dr=u.useCallback(I=>{m&&m(I)},[m]),Or=u.useCallback((I,F)=>{if(!H)return;const ie=[...x.length>0?x:t.map(ae=>ae.name)],[we]=ie.splice(I,1);ie.splice(F,0,we),H(ie)},[H,x,t]),Ar=u.useCallback(I=>{if(!m)return;const F=n.find(ie=>ie.column===I);(!F||F.direction!=="asc")&&m(I)},[m,n]),Mr=u.useCallback(I=>{if(!m)return;const F=n.find(ie=>ie.column===I);F?F.direction==="asc"&&m(I):(m(I),setTimeout(()=>m(I),0))},[m,n]),ar=u.useCallback(I=>{if(!m)return;const F=n.find(ie=>ie.column===I);F&&(F.direction==="asc"?(m(I),setTimeout(()=>m(I),0)):F.direction==="desc"&&m(I))},[m,n]),_r=u.useCallback(I=>{K&&K(I,!1)},[K]),lr=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],$r=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(p).some(I=>I===!1),Dt=(Qt-1)*gr,_e=o,at=u.useMemo(()=>{const I=new Set;return ce.forEach(F=>{const ie=F==null?void 0:F.__urm_row_id__;ie!==void 0&&I.add(ie)}),I},[ce]);u.useEffect(()=>{const I=F=>{!J||!Ne||F.target instanceof HTMLInputElement||F.target instanceof HTMLTextAreaElement||((F.ctrlKey||F.metaKey)&&F.key==="a"&&(F.preventDefault(),J(!0,_e)),F.key==="Escape"&&(F.preventDefault(),Ne()))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[J,Ne,_e]);const Ot=u.useCallback((I,F)=>{fe&&(F.shiftKey&&be!==null?(F.preventDefault(),Me&&Me(be,I,_e)):(fe(_e[I]),Cr(I)))},[fe,be,Me,_e]);!u.useMemo(()=>_e.length>0&&at.size>0&&_e.every(I=>at.has(I==null?void 0:I.__urm_row_id__)),[_e,at])&&_e.some(I=>at.has(I==null?void 0:I.__urm_row_id__));const jt=fe&&J,cr=u.useCallback(I=>{var we;const F=I.groupLevel,ie=F*24;return e.jsx(r.TableRow,{onClick:()=>V==null?void 0:V(I.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Be.length+(jt?1:0),sx:{pl:`${ie+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[I.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:bi(F,((we=b==null?void 0:b.levels[F])==null?void 0:we.column)||"",I.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:ae=>D(ae.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[I.rowCount," ",I.rowCount===1?"row":"rows"]}),Object.keys(I.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(I.aggregates).map(([ae,lt])=>yi(lt)).filter(Boolean).join(" • ")})]})})},I.groupKey)},[Be,jt,b,V]),Ht=u.useCallback((I,F)=>{const ie=at.has(I==null?void 0:I.__urm_row_id__),we=or===F;return e.jsxs(r.TableRow,{"data-row-index":F,onMouseEnter:()=>rt(F),onMouseLeave:()=>rt(null),onClick:ae=>{!fe||ae.target.closest("[data-row-action-btn]")||Ot(F,ae)},onContextMenu:ae=>{ae.preventDefault(),ae.stopPropagation(),Xe({mouseX:ae.clientX,mouseY:ae.clientY,row:I,rowIndex:F})},sx:{height:34,cursor:"pointer",bgcolor:ie?ae=>D(ae.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:ie?ae=>D(ae.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Be.map((ae,lt)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...lt===Be.length-1&&{pr:`${$e?56:20}px`},fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:f[ae.name]?`${f[ae.name]}px`:`${ae.type==="date"?Math.max(ii,180):ii}px`},children:Vd(ae,I[ae.name],Ld(ae,Be),Ke)},ae.name)),e.jsx(r.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:$e?56:20,minWidth:$e?56:20,maxWidth:$e?56:20,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:we||qe.has(I)?ae=>`linear-gradient(to right, transparent, ${ie?`rgba(${ae.palette.mode==="dark","237,108,2"},0.12)`:ae.palette.background.paper} 32px)`:"transparent",opacity:we||qe.has(I)?1:0,transition:"opacity 0.12s ease, background 0.12s ease",zIndex:10,verticalAlign:"middle"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:[$e&&e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ae=>{ae.stopPropagation(),ae.preventDefault(),$e(I)},title:qe.has(I)?"Remove from favorites":"Add to favorites",sx:{color:qe.has(I)?"warning.main":"text.secondary","&:hover":{bgcolor:ae=>D(ae.palette.warning.main,.08),color:"warning.main"}},children:qe.has(I)?e.jsx(w.Star,{sx:{fontSize:18}}):e.jsx(w.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ae=>{ae.stopPropagation(),ae.preventDefault(),Xe({anchorEl:ae.currentTarget,row:I,rowIndex:F})},sx:{color:"text.secondary",opacity:we?1:0,transition:"opacity 0.12s ease",pointerEvents:we?"auto":"none","&:hover":{bgcolor:ae=>D(ae.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(w.MoreVert,{sx:{fontSize:18}})})]})})]},F)},[ce,Dt,or,Ot,Be,f,Br,tt,Ge,ft,fe,$e,qe,Fe,Re,Xe]);return e.jsxs(kt.DndProvider,{backend:Xo.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[jt&&et&&Ne&&e.jsx(bd,{selectedCount:at.size,selectedRowIds:ce,resolvedFavoritesSet:qe,viewMode:We,onExportSelected:et,onClearSelection:Ne,onBulkSetFavorites:tr}),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:[Ee&&e.jsx(Bd,{}),se&&oe&&N&&ne&&e.jsx(r.Tooltip,{open:vt,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:St},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(md,{value:Q||"",onChange:I=>{vt&&St(),se(I)},searchHistory:le,onAddToHistory:oe,onToggleFavourite:N,onDeleteHistory:ne,disabled:Ee})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>ir(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:I=>D(I.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})})}),rr&&e.jsx(r.Tooltip,{title:Je?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:rr,size:"small",disabled:Ee,sx:{position:"relative",color:Je?"warning.main":"text.secondary",bgcolor:Je?I=>D(I.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Je?I=>D(I.palette.warning.main,.2):I=>D(I.palette.text.primary,.06),color:Je?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[Je?e.jsx(w.Star,{sx:{fontSize:20}}):e.jsx(w.StarBorder,{sx:{fontSize:20}}),Je&&er.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:"warning.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:er.length})]})}),ht&&zt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:zt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:I=>D(I.palette.text.secondary,.3),"&:hover":{bgcolor:I=>D(I.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(w.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),k&&S&&T&&s&&a.length>0&&e.jsx(fd,{views:a||[],activeViewId:c||"",isDirty:d,onSelectView:k,onCreateView:S,onManageViews:T,onToggleDefault:B,onToggleFavorite:$,onRestoreView:G,onPermanentDelete:Z,isAdmin:ee,isReadOnly:Ee}),!Ee&&C&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:C,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.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:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Ee&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.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:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Ee&&R&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:R,size:"small",sx:{position:"relative",color:Pe>0||st?"primary.main":"text.secondary",bgcolor:Pe>0||st?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Pe>0||st?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:Pe>0||st?"primary.main":"text.primary"}},children:[e.jsx(w.ViewColumn,{sx:{fontSize:20}}),Pe>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:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:Pe})]})}),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:()=>nr("list"),sx:{borderRadius:1,color:We==="list"?"primary.main":"text.secondary",bgcolor:We==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:We==="list"?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:We==="list"?"primary.main":"text.primary"}},children:e.jsx(w.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>nr("grid"),sx:{borderRadius:1,color:We==="grid"?"primary.main":"text.secondary",bgcolor:We==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:We==="grid"?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:We==="grid"?"primary.main":"text.primary"}},children:e.jsx(w.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:I=>bt(I.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:I=>D(I.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!Tr,anchorEl:Tr,onClose:()=>bt(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:[h&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(),bt(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Ee&&te&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{te(),bt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),q&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{q(),bt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),re&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{re(),bt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.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:[We==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Id,{data:_e,visibleColumns:Be,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:qe,isReadOnly:Ee,isGrouped:!!lr,sortStack:n,onSort:m,onToggleRowSelection:fe||(()=>{}),onToggleRowFavorite:$e,onToggleGroupCollapse:V,onViewRow:I=>{Fe(I),Re(!0)},onEditRow:(I,F)=>{X(I),he(F),Lt(!0)},onDuplicateRow:(I,F)=>Ge==null?void 0:Ge(I,F),onDeleteRow:(I,F)=>{Pt(F);const ie=Object.values(F).find(we=>we!=null&&we!=="");Et(ie?String(ie):""),Wt(!0)}})}),We==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Bt,onScroll:I=>{Ft.current&&(Ft.current.scrollLeft=I.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",width:"100%",minWidth:`${Be.reduce((I,F)=>I+(f[F.name]||170),$e?56:20)}px`},children:[e.jsxs("colgroup",{children:[Be.map(I=>e.jsx("col",{style:{width:`${f[I.name]||170}px`}},I.name)),e.jsx("col",{style:{width:`${$e?56:20}px`}})]}),e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Be.map((I,F)=>e.jsx(yd,{column:I,index:F,sortRule:n.find(ie=>ie.column===I.name),hasFilters:i.some(ie=>ie.column===I.name),isInSortStack:n.some(ie=>ie.column===I.name),isReadOnly:Ee,hasModifications:$r,width:f[I.name],onColumnClick:Dr,onMoveColumn:Or,onResizeStart:Er,onSortAscending:g||Ar,onSortDescending:z||Mr,onRemoveSort:ar,onOpenFilterForColumn:v||(()=>{}),onClearFiltersForColumn:de||(()=>{}),onGroupByColumn:A,onHideColumn:_r,onManageColumns:R||(()=>{}),onManageViews:T,onResetLayout:ue},I.name)),e.jsx(r.TableCell,{sx:{width:$e?56:20,minWidth:$e?56:20,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),e.jsx(r.Box,{ref:Ft,onScroll:I=>{Bt.current&&(Bt.current.scrollLeft=I.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:I=>I.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:I=>I.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",width:"100%",minWidth:`${Be.reduce((I,F)=>I+(f[F.name]||170),$e?56:20)}px`},children:[e.jsxs("colgroup",{children:[Be.map(I=>e.jsx("col",{style:{width:`${f[I.name]||170}px`}},I.name)),e.jsx("col",{style:{width:`${$e?56:20}px`}})]}),e.jsx(r.TableBody,{children:_e.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Be.length+(jt?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):lr?_e.map((I,F)=>I.isGroupHeader?cr(I):Ht(I,F)):_e.map((I,F)=>Ht(I,F))})]})})]}),ot&&Le&&e.jsx(Ed,{currentPage:Qt,pageSize:gr,totalRows:$t,totalFields:t.length,onPageChange:ot,onPageSizeChange:Le}),!(ot&&Le)&&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 ",_e.length," ",_e.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!Se,onClose:()=>Xe(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:170,py:.5,borderRadius:1.5,boxShadow:3}},children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Se&&(Fe(Se.row),Re(!0)),Xe(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Se&&(X(Se.row),he(Se.rowIndex),Lt(!0)),Xe(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Se&&(Ge==null||Ge(Se.rowIndex,Se.row)),Xe(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{if(Se){Pt(Se.row);const I=Object.values(Se.row).find(F=>F!=null&&F!=="");Et(I?String(I):""),Wt(!0)}Xe(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(w.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Ad,{open:ve,onClose:()=>{Re(!1),Fe(null)},row:L,schema:t,reportName:nt}),e.jsx(_d,{open:kr,onClose:()=>{Lt(!1),X(null),he(null)},onSave:I=>{yt!==null&&(tt==null||tt(yt,I))},row:Oe,schema:t,reportName:nt}),e.jsx(Md,{open:wr,onClose:()=>{Wt(!1),Pt(null)},onConfirm:()=>{gt!==null&&(ft==null||ft(gt))},rowPreview:Nt}),e.jsx(Vi,{isOpen:Ir,onClose:()=>ir(!1)})]})}function Xt({content:t,isDev:o=!1}){const[n,i]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:a=>i(a.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:a=>D(a.palette.primary.main,.08)}},children:e.jsx(w.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:a=>D(a.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((a,c)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:a},c))}),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:a=>D(a.palette.warning.main,.08),border:"1px solid",borderColor:a=>D(a.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 Zt={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 Ud({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:a,onClearAll:c,onReplaceFilters:d,onClose:l,focusColumn:p}){const[x,f]=u.useState(""),[b,m]=u.useState(""),[g,z]=u.useState(""),[y,C]=u.useState([]),v=Kt();u.useEffect(()=>{C([...o])},[o]),u.useEffect(()=>{p&&f(p)},[p]);const k=u.useCallback(()=>{f(""),m(""),z("")},[]),S=u.useMemo(()=>t.filter(R=>R.type!=="mixed"&&R.type!=="null"&&R.type!=="array"&&R.type!=="object"),[t]),T=t.find(R=>R.name===x),s=u.useMemo(()=>{const R=T?wn(T.type):[],W=v.filter.allowedOperators;return W.length>0?R.filter(H=>W.includes(H.value)):R},[T]),M=u.useCallback(()=>!(!x||!b||to(b)&&!g.trim()||y.length>=v.filter.maxConditions),[x,b,g,y,v]),B=u.useCallback(()=>{if(!M())return;const R={column:x,operator:b};if(to(b)){const H=T==null?void 0:T.type;R.value=H==="number"?Number(g):g}if(y.some(H=>H.column===R.column&&H.operator===R.operator&&H.value===R.value)){k();return}C([...y,R]),k()},[M,x,b,T,g,y,k]),$=u.useCallback(R=>{C(y.filter((W,H)=>H!==R))},[y]),G=u.useMemo(()=>y.length!==o.length?!0:JSON.stringify(y)!==JSON.stringify(o),[y,o]),Z=u.useCallback(()=>{d(y),l()},[y,d,l]),ee=u.useCallback(()=>{C([...o]),k(),l()},[o,k,l]),h=u.useCallback(R=>{var de;const W=t.find(ue=>ue.name===R.column);if(!W)return"";const K=((de=wn(W.type).find(ue=>ue.value===R.operator))==null?void 0:de.label)||R.operator;return to(R.operator)?`${R.column} ${K.toLowerCase()} "${R.value}"`:`${R.column} ${K.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:ee,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:R=>R.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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(Xt,{content:Zt.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:"grey.100",color:"text.primary"}},children:e.jsx(w.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:y.length>=v.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:x,onChange:R=>{f(R.target.value),m(""),z("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:S.map(R=>e.jsxs(r.MenuItem,{value:R.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:W=>D(W.palette.primary.main,.2)}}},children:[Ue(R.name)," (",R.type,")"]},R.name))})]}),x&&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:b,onChange:R=>{m(R.target.value),z("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:s.map(R=>e.jsx(r.MenuItem,{value:R.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:W=>D(W.palette.primary.main,.2)}}},children:R.label},R.value))})]}),b&&to(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(T==null?void 0:T.type)==="number"?"number":"text",value:g,onChange:R=>z(R.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:"grey.300",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:B,disabled:!M(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add another filter"}),y.length>=v.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 ",v.filter.maxConditions," filters allowed. Remove an existing filter to add a new one."]})]}),y.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 (",y.length,")"]}),e.jsx(r.Button,{onClick:()=>{c(),l()},sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,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:y.map((R,W)=>e.jsx(r.Chip,{label:h(R),onDelete:()=>$(W),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:H=>`1px solid ${D(H.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:H=>D(H.palette.primary.main,.2),borderColor:"#aecbfa"},"& .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:"grey.50"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Z,disabled:!G,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"grey.300",color:"grey.500"}},children:"Apply filter"})]})]})})}const si="SORT_RULE";function Yd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:a}){const c=u.useRef(null),[{handlerId:d},l]=kt.useDrop({accept:si,collect(f){return{handlerId:f.getHandlerId()}},hover(f,b){var k;if(!c.current)return;const m=f.index,g=o;if(m===g)return;const z=(k=c.current)==null?void 0:k.getBoundingClientRect(),y=(z.bottom-z.top)/2,C=b.getClientOffset(),v=((C==null?void 0:C.y)??0)-z.top;m<g&&v<y||m>g&&v>y||(a(m,g),f.index=g)}}),[{isDragging:p},x]=kt.useDrag({type:si,item:()=>({index:o}),collect:f=>({isDragging:f.isDragging()})});return x(l(c)),e.jsxs(r.Box,{ref:c,"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:p?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)",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:"0 1px 2px 0 rgba(25, 103, 210, 0.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:f=>n(o,f.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",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:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:f=>D(f.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:f=>D(f.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:"rgba(217, 48, 37, 0.08)",transform:"scale(1.1)"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]})}function Gd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[a,c]=u.useState(""),[d,l]=u.useState([]);u.useEffect(()=>{l([...o])},[o]);const p=u.useMemo(()=>JSON.stringify(d)!==JSON.stringify(o),[d,o]),x=Kt(),f=u.useCallback(()=>!(d.length>=x.sort.maxLevels||!a||d.some(S=>S.column===a)),[d,a]),b=u.useCallback(()=>{if(!f())return;const S=d.length+1,T={column:a,direction:"asc",priority:S};l([...d,T]),c("")},[f,a,d]),m=u.useCallback(S=>{const s=d.filter((M,B)=>B!==S).map((M,B)=>({...M,priority:B+1}));l(s)},[d]),g=u.useCallback((S,T)=>{const s=[...d];s[S]={...s[S],direction:T},l(s)},[d]),z=u.useCallback((S,T)=>{const s=[...d],[M]=s.splice(S,1);s.splice(T,0,M);const B=s.map(($,G)=>({...$,priority:G+1}));l(B)},[d]),y=u.useCallback(()=>{n([]),i()},[n,i]),C=u.useCallback(()=>{n(d),i()},[d,n,i]),v=u.useCallback(()=>{l([...o]),c(""),i()},[o,i]),k=t.filter(S=>!d.some(T=>T.column===S.name));return e.jsx(kt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:v,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:S=>S.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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(Xt,{content:Zt.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:v,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:d.length>=x.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:a,onChange:S=>c(S.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:k.map(S=>e.jsx(r.MenuItem,{value:S.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:T=>D(T.palette.primary.main,.2)}}},children:Ue(S.name)},S.name))})]}),e.jsx(r.Button,{onClick:b,disabled:!f(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),d.length>=x.sort.maxLevels&&e.jsxs(r.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",x.sort.maxLevels," sort levels allowed"]})]}),d.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 (",d.length,"/",x.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:y,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((S,T)=>e.jsx(Yd,{rule:S,index:T,onToggleDirection:g,onRemove:m,onMove:z},`${S.column}-${T}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:v,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:C,variant:"contained",disabled:!p||d.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function qd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:a,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:p,isAdmin:x=!1,onClose:f}){var S,T;const m=It().palette,g=t.filter(s=>!s.isDeleted),z=t.filter(s=>s.isDeleted),y=g.filter(s=>s.scope==="global"),C=g.filter(s=>s.scope!=="global"),v=s=>{var Z,ee,h,R,W;const M=s.scope==="global",B=s.id===o,$=x||!M,G=x&&!M;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:B?"primary.main":"divider",bgcolor:B?D(m.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:B?"primary.main":D(m.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(s.id),f()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:B?600:500,color:B?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.name}),s.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[M&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(w.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:D(((Z=m.info)==null?void 0:Z.main)??m.primary.main,.1),color:((ee=m.info)==null?void 0:ee.main)??m.primary.main,border:`1px solid ${D(((h=m.info)==null?void 0:h.main)??m.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),s.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:D(m.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:H=>{H.stopPropagation(),p(s.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((R=m.info)==null?void 0:R.main)??m.primary.main,bgcolor:D(((W=m.info)==null?void 0:W.main)??m.primary.main,.08)}},children:e.jsx(w.Language,{sx:{fontSize:16}})})}),$&&e.jsx(r.Tooltip,{title:M&&!x?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:M&&!x,onClick:H=>{H.stopPropagation(),a(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:D(m.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:M&&!x?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:M&&!x,onClick:H=>{H.stopPropagation(),c(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:D(m.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})})]})]})},s.id)},k=s=>{var M;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:D(m.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:s.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[d&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),d(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:D(((M=m.success)==null?void 0:M.main)??"#2e7d32",.08)}},children:e.jsx(w.Undo,{sx:{fontSize:15}})})}),l&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),l(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:D(m.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]},s.id)};return e.jsxs(r.Dialog,{open:!0,onClose:f,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"14px",maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${D(((S=m.common)==null?void 0:S.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"}),x&&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:f,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.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",disableElevation:!0,startIcon:e.jsx(w.Add,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",borderRadius:"7px",fontWeight:500},children:"Create New View"})}),y.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(w.Language,{sx:{fontSize:14,color:((T=m.info)==null?void 0:T.main)??m.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:y.map(v)})]}),C.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:C.map(v)})]}),z.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:z.map(k)})]}),g.length===0&&z.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:f,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const so=50;function ai({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:a="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:p=10}){const[x,f]=u.useState(a),[b,m]=u.useState(!1),[g,z]=u.useState(c),[y,C]=u.useState(d),v=()=>{if(!x.trim()){m(!0);return}if(x.trim().length>so){m(!0);return}o(x.trim(),g.trim(),y),n()},k=T=>{T.key==="Enter"&&!T.shiftKey?v():T.key==="Escape"&&n()},S=()=>i&&a?`Update ${a} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[S(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.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:x,onChange:T=>{T.target.value.length<=so&&f(T.target.value),b&&T.target.value.trim()&&m(!1)},onKeyDown:k,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:so},error:b&&!x.trim(),helperText:b&&!x.trim()?"View name is required":`${x.length} / ${so}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:T=>z(T.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: ",oa(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:y,onChange:T=>C(T.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:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:v,variant:"contained",disabled:l&&!i,startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:i?"Save Changes":"Create Report View"})]})]})}function Jd({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},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(w.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(w.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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete View"})]})]})}const lo=100,co=600,li="COLUMN";function Kd({column:t,index:o,isVisible:n,width:i,onToggleVisibility:a,onWidthChange:c,moveColumn:d}){const l=u.useRef(null),[p,x]=u.useState(i.toString());u.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:f},b]=kt.useDrop({accept:li,collect(k){return{handlerId:k.getHandlerId()}},hover(k,S){var Z;if(!l.current)return;const T=k.index,s=o;if(T===s)return;const M=(Z=l.current)==null?void 0:Z.getBoundingClientRect(),B=(M.bottom-M.top)/2,$=S.getClientOffset(),G=(($==null?void 0:$.y)??0)-M.top;T<s&&G<B||T>s&&G>B||(d(T,s),k.index=s)}}),[{isDragging:m},g]=kt.useDrag({type:li,item:()=>({index:o}),collect:k=>({isDragging:k.isDragging()})});g(b(l));const z=()=>{const k=parseInt(p);if(isNaN(k)){x(i.toString()),c(t.name,i);return}const S=Math.max(lo,Math.min(co,k));x(S.toString()),c(t.name,S)},y=k=>{if(k===""||/^\d+$/.test(k)){x(k);const S=parseInt(k);if(!isNaN(S)&&S>=lo){const T=Math.min(co,S);c(t.name,T)}}},C=k=>{k.key==="Enter"&&(k.preventDefault(),z(),k.target.blur())},v=k=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[k]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":f,sx:{opacity:m?.4:1,bgcolor:n?"background.paper":"grey.50",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"grey.50":"grey.100"},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(w.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ue(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:`${v(t.type)}15`,color:v(t.type),border:`1px solid ${v(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:k=>y(k.target.value),onBlur:z,onKeyDown:C,placeholder:"150",size:"small",inputProps:{min:lo,max:co,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&: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:()=>a(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:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(w.Visibility,{sx:{fontSize:20}}):e.jsx(w.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?"#e6f4ea":"grey.100",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Xd({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:a=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:p,onResetLayout:x,onSaveToCurrentView:f,onSaveToAllViews:b,onSelectView:m,onClose:g}){const[z,y]=u.useState(!1),[C,v]=u.useState(n),[k,S]=u.useState(i),[T,s]=u.useState("all"),[M,B]=u.useState(null);u.useEffect(()=>{v(n)},[n]),u.useEffect(()=>{S(i)},[i]);const $=(te,A)=>{S(V=>({...V,[te]:A})),p==null||p(te,A)},G=(te,A)=>{const V=[...C],[q]=V.splice(te,1);V.splice(A,0,q),v(V),l(V)},Z=()=>{x(),y(!1)},h=C.map(te=>t.find(A=>A.name===te)).filter(te=>te!==void 0).filter(te=>{const A=o[te.name]??!0;return T==="active"?A:T==="hidden"?!A:!0}),R=Object.values(o).filter(te=>te).length,W=t.length,H=a.find(te=>te.id===c),K=a.filter(te=>!te.isDeleted),de=K.length>1,ue=u.useMemo(()=>{if(!H)return!1;const te=H.snapshot,A=te.columnVisibility??{},V=JSON.stringify(o)!==JSON.stringify(A),q=te.columnOrder??[],re=n??[],Q=JSON.stringify(re)!==JSON.stringify(q)&&!(re.length===0&&q.length===0),le=te.columnWidths??{},oe=JSON.stringify(k)!==JSON.stringify(le);return V||Q||oe},[H,o,n,k]);return e.jsx(kt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:te=>te.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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.jsxs(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(Xt,{content:Zt.columns,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5},children:[R," of ",W," columns visible • Drag to reorder"]})]}),K.length>0&&m&&e.jsxs(r.Box,{sx:{ml:2},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",color:"text.secondary",mb:.75,display:"block",textTransform:"uppercase",fontWeight:600,letterSpacing:"0.1em"},children:"View:"}),e.jsx(r.Button,{onClick:te=>B(te.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(H==null?void 0:H.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:M,open:!!M,onClose:()=>B(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:K.map(te=>e.jsx(r.MenuItem,{onClick:()=>{m(te.id),B(null)},selected:te.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:A=>D(A.palette.primary.main,.2)}}},children:te.name},te.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:T,onChange:(te,A)=>s(A),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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:"grey.50",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:"grey.50",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:"grey.50",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: ${lo}px, max: ${co}px)`,arrow:!0,placement:"top",children:e.jsx(w.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:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:h.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"})})}):h.map((te,A)=>e.jsx(Kd,{column:te,index:A,isVisible:o[te.name]??!0,width:k[te.name]||170,onToggleVisibility:d,onWidthChange:$,moveColumn:G},te.name))})]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!0),disabled:!ue,variant:"outlined",startIcon:e.jsx(w.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[f&&e.jsx(r.Button,{onClick:()=>{f(k),g()},disabled:!ue,variant:"contained",startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&de&&e.jsx(r.Button,{onClick:()=>{b(k),g()},disabled:!ue||!de,variant:"contained",startIcon:e.jsx(w.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),z&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1400},children:e.jsxs(r.Paper,{onClick:te=>te.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:"12px",bgcolor:"background.paper",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"},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:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,borderRadius:"4px","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Z,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function Zd({schema:t,grouping:o,onApply:n,onClose:i}){var M;const[a,c]=u.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=u.useState(""),[p,x]=u.useState(null),f=u.useMemo(()=>Xs(t),[t]),b=u.useMemo(()=>f.filter(B=>!a.levels.some(($,G)=>$.column===B.name&&G!==p)),[f,a.levels,p]),m=Kt(),g=a.levels.length<m.grouping.maxLevels&&b.length>0,z=u.useCallback(()=>{!g||!d||(c({...a,levels:[...a.levels,{column:d}],enabled:!0}),l(""))},[g,d,a]),y=u.useCallback(B=>{const $=a.levels.filter((G,Z)=>Z!==B);if($.length===0){n(null),i();return}c({...a,levels:$,enabled:$.length>0})},[a,n,i]),C=u.useCallback(B=>{x(B),l(a.levels[B].column)},[a.levels]),v=u.useCallback(()=>{if(p===null||!d)return;const B=[...a.levels];B[p]={column:d},c({...a,levels:B}),x(null),l("")},[p,d,a]),k=u.useCallback(()=>{x(null),l("")},[]),S=u.useCallback((B,$)=>{const G=$==="up"?B-1:B+1;if(G<0||G>=a.levels.length)return;const Z=[...a.levels],[ee]=Z.splice(B,1);Z.splice(G,0,ee),c({...a,levels:Z})},[a]),T=u.useCallback(()=>{n(null),i()},[n,i]),s=u.useCallback(()=>{a.levels.length===0?n(null):n({...a,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[a,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:B=>B.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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(Xt,{content:Zt.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:"grey.100",color:"text.primary"}},children:e.jsx(w.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:d,onChange:B=>l(B.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:$=>D($.palette.primary.main,.2)}}},children:[Ue(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsx(r.Button,{onClick:z,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),a.levels.length>=m.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"}),f.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:"1px solid #fdd663",bgcolor:"#fef7e0","& .MuiAlert-icon":{color:"#ea8600"}},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:d,onChange:B=>l(B.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&: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:a.levels[p].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[a.levels[p].column," (",(M=t.find(B=>B.name===a.levels[p].column))==null?void 0:M.type.toUpperCase(),")"]}),b.filter(B=>B.name!==a.levels[p].column).map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[Ue(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:v,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"#ea8600",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"#c96e00",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)"}},children:"Save"}),e.jsx(r.Button,{onClick:k,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),a.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:T,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:a.levels.map((B,$)=>{const G=t.find(Z=>Z.name===B.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:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1)"}},children:[e.jsx(r.Chip,{label:`L${$+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.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:B.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:()=>S($,"up"),disabled:$===0,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(w.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"down"),disabled:$===a.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>C($),sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100",color:"primary.main"}},children:e.jsx(w.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y($),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(w.Delete,{sx:{fontSize:18}})})]})]},$)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:s,variant:"contained",disabled:a.levels.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const Qd={filters:w.FilterList,sorting:w.UnfoldMore,visibility:w.Visibility,order:w.ViewColumn,widths:w.Straighten,grouping:w.Layers};function eu({changes:t,onClose:o}){const n=i=>({filters:"primary",sorting:"secondary",visibility:"success",order:"warning",widths:"info",grouping:"error"})[i]||"default";return e.jsxs(r.Dialog,{open:!0,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["View Changes Summary",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,children:t.length===0?e.jsx(r.Box,{sx:{textAlign:"center",py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No changes detected"})}):e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"The following modifications have been made to this view:"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:t.map((i,a)=>{const c=Qd[i.category];return e.jsxs(r.Paper,{elevation:0,sx:{display:"flex",gap:1.5,p:1.5,border:1,borderColor:"divider",borderRadius:1},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:1,bgcolor:`${n(i.category)}.lighter`,color:`${n(i.category)}.main`,flexShrink:0},children:e.jsx(c,{sx:{fontSize:16}})}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:i.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:i.description})]})]},a)})})]})}),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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})}function tu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:a,onCancel:c}){const[d,l]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:"primary.lighter",borderBottom:p=>`1px solid ${D(p.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:"rgba(60, 64, 67, 0.08)",color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:a,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:"0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px rgba(60, 64, 67, 0.15)"}},children:"Save as new view"})]})]})}),d&&e.jsx(eu,{changes:n,onClose:()=>l(!1)})]})}function ru({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(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(w.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(w.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(w.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const ci=[{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 ou(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 nu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function iu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var z,y,C,v;const a=It().palette,[c,d]=u.useState("1h"),[l,p]=u.useState(!1),x=[...t].sort((k,S)=>new Date(S.timestamp).getTime()-new Date(k.timestamp).getTime()),f=ci.find(k=>k.key===c),b=ou(t,f.ms),m=()=>p(!0),g=()=>{n&&(n(nu(t,f.ms)),p(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:D(((z=a.common)==null?void 0:z.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:k=>k.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"16px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${D(((y=a.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${D(((C=a.common)==null?void 0:C.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(Xt,{content:Zt.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[x.length," event",x.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:c,onChange:k=>d(k.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:D(a.text.primary,.3)}},children:ci.map(k=>e.jsx(r.MenuItem,{value:k.key,sx:{fontSize:"0.8125rem"},children:k.label},k.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:m,sx:{textTransform:"none",fontSize:"0.75rem",fontWeight:500,borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:D(a.error.main,.5),"&:hover":{bgcolor:D(a.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(w.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:D(a.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D(a.text.primary,.14),borderRadius:3}},children:x.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(w.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:x.map(k=>{const S=va(k.feature),{summary:T,detail:s}=ha(k);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:D(a.text.primary,.18)}},children:[e.jsx(r.Chip,{label:ba(k.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:D(S,.1),color:S,border:`1px solid ${D(S,.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:T}),s&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:s}),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(w.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:Sa(k.timestamp)})]}),k.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(w.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:k.user})]})]})]})]},k.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>p(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${D(((v=a.common)==null?void 0:v.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:D(a.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.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:[b," audit record",b!==1?"s":""]})," ",f.key==="all"?"from all time":`from the ${f.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:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",disableElevation:!0,startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function su({onSave:t,onClose:o}){const[n,i]=u.useState(""),[a,c]=u.useState(""),[d,l]=u.useState(""),[p,x]=u.useState([]),[f,b]=u.useState(""),[m,g]=u.useState(""),z=s=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s),y=()=>{const s=d.trim();if(s){if(!z(s)){g("Please enter a valid email address");return}if(p.includes(s)){g("This email is already added");return}x([...p,s]),l(""),g("")}},C=s=>{x(p.filter(M=>M!==s))},v=s=>{s.key==="Enter"&&(s.preventDefault(),y())},k=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),a.trim(),p.length>0?p:void 0)},S=s=>{i(s),f&&b("")},T=s=>{l(s),m&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:s=>s.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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:"grey.100",color:"text.primary"}},children:e.jsx(w.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(w.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:s=>`1px solid ${D(s.palette.primary.main,.3)}`,bgcolor:"primary.lighter","& .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:s=>S(s.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:"grey.300"},"&: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:a,onChange:s=>c(s.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:"grey.300"},"&: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:d,onChange:s=>T(s.target.value),onKeyPress:v,placeholder:"Enter email address",error:!!m,helperText:m,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&: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:y,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",px:2,py:1.25,minHeight:40,borderRadius:"4px",flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:"Add"})]}),p.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:p.map(s=>e.jsx(r.Chip,{label:s,onDelete:()=>C(s),deleteIcon:e.jsx(w.Delete,{sx:{fontSize:16}}),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},s))}),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:"grey.50"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:k,variant:"contained",startIcon:e.jsx(w.Share,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function au({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(w.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(w.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 lu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:a}){const[c,d]=u.useState(null),l=p=>new Date(p).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:a,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:p=>p.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"common.white",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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:a,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(w.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:"#bdc1c6"}}},children:t.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[e.jsx(w.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:"#80868b",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(p=>e.jsxs(r.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"common.white",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)"}},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:p.name}),p.description&&e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:p.description})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[e.jsx(r.Chip,{label:`Created ${l(p.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}}),e.jsx(r.Chip,{label:`By ${p.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),e.jsx(r.Divider,{sx:{my:1.5,borderColor:"#f1f3f4"}}),e.jsx(r.Box,{sx:{display:"flex",gap:1},children:e.jsx(r.Button,{onClick:()=>i(p.id,p.name),variant:"outlined",size:"small",startIcon:e.jsx(w.Delete,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:"4px","&:hover":{borderColor:"error.main",bgcolor:"rgba(217, 48, 37, 0.04)"}},children:"Delete"})})]},p.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:a,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})})}const Yi={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},cu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],du=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function uu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const a=du.some(l=>l.test(i.name));let c=!1;const d=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);d.length>0&&(c=d.filter(p=>cu.some(x=>x.test(p))).length/d.length>.6),(a||c)&&n.push(i.name)}return n}function an(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),a=o.map(d=>{const l=n.map(x=>String(x[d]??"")).filter(x=>x.length>0);if(l.length===0)return 5;const p=l.reduce((x,f)=>x+f.length,0);return Math.ceil(p/l.length)+1}).reduce((d,l)=>d+l,0)+1;return o.reduce((d,l)=>d+l.length+1,0)+a*t.length}function pu(t,o){const n=an(t,o);return Math.ceil(n*3.5)}function xu(t,o){const n=an(t,o);return Math.ceil(n*.7)}function mu(t,o,n){switch(t){case"csv":return an(o,n);case"excel":return xu(o,n);case"json":return pu(o,n)}}function di(t,o){return Math.ceil(t/o)}function fu(t,o,n,i,a=Yi){const c=[],d=mu(t,o,n),l=o.length;if(l>a.maxRowsHard){const f=di(l,a.maxRows);c.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${a.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${f} smaller exports of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:a.maxRowsHard})}else if(l>a.maxRows){const f=di(l,a.maxRows);c.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 ${f} smaller export${f>1?"s":""} of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:a.maxRows})}if(d>a.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Gr(d)} exceeds the ${Gr(a.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:a.maxFileSizeHardBytes}):d>a.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Gr(d)}`,detail:`This exceeds the recommended ${Gr(a.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:a.maxFileSizeBytes}),t!=="excel"){const f=uu(i.filter(b=>n.includes(b.name)),o);if(f.length>0){const b=f.length>a.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${f.length>1?"s":""} detected: ${f.map(m=>`"${m.replace(/_/g," ")}"`).join(", ")}`,detail:b?`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:a.maxImageColumns})}}const p=c.some(f=>f.severity==="error"),x=c.some(f=>f.severity==="warning");return{violations:c,hasBlockingViolation:p,hasWarning:x,estimatedBytes:d}}function Gr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function hu({violation:t}){const n=It().palette,i=t.severity==="error",a=i?n.error.main:n.warning.main,c=D(i?n.error.main:n.warning.main,.06),d=i?D(n.error.main,.25):D(n.warning.main,.3),l=i?w.ErrorOutline:w.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:c,border:"1px solid",borderColor:d},children:[e.jsx(l,{sx:{fontSize:17,color:a,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(w.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 gu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:a,schema:c,sampleRows:d=[],allRows:l=[],processedRows:p=[],onExport:x,onClose:f}){var R,W,H;const m=It().palette,g=Kt(),[z,y]=u.useState(g.export.allowedFormats[0]||"csv"),[C,v]=u.useState("visible"),[k,S]=u.useState("visible"),T=C==="visible"?o:t,s=k==="visible"?i:a,M=u.useMemo(()=>C==="visible"?p.length>0?p:new Array(o):l.length>0?l:new Array(t),[C,o,t,p,l]),B=u.useMemo(()=>k==="all"?c.map(K=>K.name):c.map(K=>K.name).slice(0,i),[k,c,i]),$=u.useMemo(()=>fu(z,M,B,c,Yi),[z,M,B,c]),G=()=>{$.hasBlockingViolation||(x({format:z,scope:C,columnScope:k}),f())},Z={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"}},h={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:f,sx:{position:"fixed",inset:0,bgcolor:D(((R=m.common)==null?void 0:R.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:K=>K.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:"14px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${D(((W=m.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${D(((H=m.common)==null?void 0:H.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(Xt,{content:Zt.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.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:D(m.text.primary,.15),borderRadius:3}},children:[$.violations.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:$.violations.map((K,de)=>e.jsx(hu,{violation:K},de))}),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:z,onChange:K=>y(K.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:h}),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}}),g.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:h}),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}}),g.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:h}),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:C,onChange:K=>v(K.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),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:h}),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:k,onChange:K=>S(K.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),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:h}),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 ",a," 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:Z[z]},{label:"Rows to export",value:T.toLocaleString()},{label:"Columns to export",value:String(s)},{label:"Estimated file size",value:Gr($.estimatedBytes),highlight:$.hasBlockingViolation?"error.main":$.hasWarning?"warning.main":void 0}].map(({label:K,value:de,highlight:ue})=>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:K}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:ue??"text.primary"},children:de})]},K))})]})]}),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:D(m.text.primary,.015)},children:[$.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(w.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:f,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:G,disabled:$.hasBlockingViolation,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.Download,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"8px"},children:["Download ",Z[z]]})]})]})})}function yu({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(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(w.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 bu({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 c=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(w.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Ma(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:c.severity,icon:c.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${c.severity}.main`},children:e.jsx(w.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${c.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:d}),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 vu extends u.Component{constructor(o){super(o),this.handleReset=()=>{this.setState({hasError:!1,error:null})},this.state={hasError:!1,error:null}}static getDerivedStateFromError(o){return{hasError:!0,error:o}}componentDidCatch(o,n){qt.error("urm:error-boundary","Caught unhandled component error",o,n),this.props.onError&&this.props.onError(o,n)}render(){var o,n;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsx(r.Paper,{sx:{bgcolor:i=>D(i.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(w.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:((o=this.state.error)==null?void 0:o.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:i=>D(i.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:170},children:(n=this.state.error)==null?void 0:n.stack}),e.jsx(r.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:e.jsx(w.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Su({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(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(w.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Fr({children:t,feature:o,onError:n}){return e.jsx(vu,{context:o,onError:(i,a)=>{n&&n(i)},fallback:e.jsx(Su,{feature:o}),children:t})}const ju=[{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"}],Cu=[{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 Vr({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 wu({open:t,onClose:o,config:n,onApply:i}){const[a,c]=u.useState(0),[d,l]=u.useState(n),p=()=>l(n),x=()=>l(Ve),f=()=>{i(d),o()},b={sort:C=>l(v=>({...v,sort:{...v.sort,...C}})),filter:C=>l(v=>({...v,filter:{...v.filter,...C}})),columns:C=>l(v=>({...v,columns:{...v.columns,...C}})),grouping:C=>l(v=>({...v,grouping:{...v.grouping,...C}})),export:C=>l(v=>({...v,export:{...v.export,...C}}))},m=C=>{const v=d.filter.allowedOperators,k=v.includes(C)?v.filter(S=>S!==C):[...v,C];k.length!==0&&b.filter({allowedOperators:k})},g=C=>{const v=d.export.allowedFormats,k=v.includes(C)?v.filter(S=>S!==C):[...v,C];k.length!==0&&b.export({allowedFormats:k})},z=[{label:"Sort",icon:e.jsx(w.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(w.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(w.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(w.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(w.Download,{sx:{fontSize:17}})}],y=C=>JSON.stringify(d[C])===JSON.stringify(Ve[C]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:p},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.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:C=>D(C.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(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:a,onChange:(C,v)=>c(v),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:z.map((C,v)=>e.jsx(r.Tab,{label:C.label,icon:C.icon,iconPosition:"start"},v))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Vr,{active:a===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"}),!y("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:d.sort.maxLevels,onChange:(C,v)=>b.sort({maxLevels:v}),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(Vr,{active:a===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"}),!y("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:d.filter.maxConditions,onChange:(C,v)=>b.filter({maxConditions:v}),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(C=>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:C}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:ju.filter(v=>v.group===C).map(v=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(v.value),onChange:()=>m(v.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:v.label}),sx:{mr:1.5}},v.value))})]},C))]})]}),e.jsxs(Vr,{active:a===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"}),!y("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:d.columns.maxVisible,onChange:(C,v)=>b.columns({maxVisible:v}),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:d.columns.minColumnWidth,onChange:(C,v)=>b.columns({minColumnWidth:v}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:C=>`${C}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:d.columns.maxColumnWidth,onChange:(C,v)=>b.columns({maxColumnWidth:v}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:C=>`${C}px`})]})]})]})]}),e.jsxs(Vr,{active:a===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"}),!y("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(C=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:C}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===C?"primary.main":"divider",bgcolor:d.grouping.maxLevels===C?v=>D(v.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:v=>D(v.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:d.grouping.maxLevels===C?"primary.main":"text.secondary"},children:C}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][C-1]})]},C))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowNested,onChange:C=>b.grouping({allowNested:C.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow nested groups"})}),e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowCollapse,onChange:C=>b.grouping({allowCollapse:C.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(Vr,{active:a===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"}),!y("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:Cu.map(C=>e.jsxs(r.Box,{onClick:()=>g(C.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(C.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(C.value)?v=>D(v.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(C.value),onChange:()=>g(C.value),onClick:v=>v.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:C.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:C.desc})]})]},C.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:C=>D(C.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(w.RestartAlt,{sx:{fontSize:18}}),onClick:x,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:C=>D(C.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:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:f,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const ku=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Tu={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 uo(t,o,n,i,a=new Date){const[c,d]=o.split(":").map(Number),l=new Date(a);if(l.setSeconds(0,0),l.setHours(c,d,0,0),t==="daily")return l<=a&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const p=n??1,x=l.getDay();let f=p-x;return f<0&&(f+=7),f===0&&l<=a&&(f=7),l.setDate(l.getDate()+f),l.toISOString()}if(t==="monthly"){const p=Math.min(i??1,28);return l.setDate(p),l<=a&&(l.setMonth(l.getMonth()+1),l.setDate(p)),l.toISOString()}return l.toISOString()}function Iu(t){const o=Gi(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${ku[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Tu[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Gi(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function zu(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),a=Math.floor(n%86400/3600),c=Math.floor(n%3600/60);return i>0?`in ${i}d ${a}h`:a>0?`in ${a}h ${c}m`:c>0?`in ${c}m`:"in less than a minute"}function Eu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),a=Gi(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${a}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${a}`}function qi(t){return`urm_schedules_${t}`}function Ji(t){try{const o=localStorage.getItem(qi(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 Ki(t,o){try{localStorage.setItem(qi(t),JSON.stringify(o))}catch{}}const Bu=[{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"}],Du=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Xi={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Gt={"& .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 Ou({initial:t=Xi,isEditing:o=!1,onSave:n,onBack:i}){const[a,c]=u.useState(t),[d,l]=u.useState(!1),[p,x]=u.useState(!1),f=(g,z)=>c(y=>({...y,[g]:z})),b=a.email.trim().length>0&&!Du.test(a.email.trim()),m=a.name.trim().length>0&&/^\d{2}:\d{2}$/.test(a.time)&&(a.frequency!=="monthly"||a.dayOfMonth>=1&&a.dayOfMonth<=28)&&!b;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:g=>D(g.palette.text.primary,.06)}},children:e.jsx(w.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:a.name,onChange:g=>{f("name",g.target.value),d&&g.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!a.name.trim(),helperText:d&&!a.name.trim()?"Schedule name is required":`${a.name.length}/50`,sx:Gt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Gt,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:a.frequency,label:"Frequency",onChange:g=>f("frequency",g.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"})]})]}),a.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Gt,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:a.dayOfWeek,label:"Day of week",onChange:g=>f("dayOfWeek",Number(g.target.value)),children:Bu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),a.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:a.dayOfMonth,onChange:g=>f("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:a.dayOfMonth<1||a.dayOfMonth>28,helperText:a.dayOfMonth<1||a.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Gt}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:a.time,onChange:g=>f("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Gt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Gt,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:a.format,label:"Export format",onChange:g=>f("format",g.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:a.scope,onChange:g=>f("scope",g.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:a.email,onChange:g=>f("email",g.target.value),onBlur:()=>x(!0),placeholder:"user@company.com",error:p&&b,helperText:p&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Gt}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(w.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:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>D(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>m&&n(a),disabled:!m,size:"small",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Au({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:i=>{var a;return`0 8px 32px ${D(((a=i.palette.common)==null?void 0:a.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=>D(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.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:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:"Delete"})]})]})}function Mu({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:a,onDelete:c}){const d=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:d?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:d?l=>D(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:d?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:d?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:d?l=>D(l.palette.success.main,.1):l=>D(l.palette.text.primary,.06),color:d?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:Iu(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=>D(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=>D(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(w.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>D(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),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:[d&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",zu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Eu(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:()=>a(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>D(l.palette.primary.main,.08)}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:d?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:d?"warning.main":"success.main","&:hover":{bgcolor:d?l=>D(l.palette.warning.main,.08):l=>D(l.palette.success.main,.08)}},children:d?e.jsx(w.Pause,{sx:{fontSize:15}}):e.jsx(w.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=>D(l.palette.primary.main,.08)}},children:e.jsx(w.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>c(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>D(l.palette.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]})]})}function _u({open:t,onClose:o,reportId:n,reportName:i,onRunNow:a}){const[c,d]=u.useState([]),[l,p]=u.useState({type:"list"}),[x,f]=u.useState(0),[b,m]=u.useState(null);u.useEffect(()=>{t&&(d(Ji(n)),p({type:"list"}))},[t,n]),u.useEffect(()=>{if(!t)return;const B=setInterval(()=>f($=>$+1),3e4);return()=>clearInterval(B)},[t]);const g=u.useCallback(B=>{d(B),Ki(n,B)},[n]),z=B=>{const $=uo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth),G={id:`sched-${Date.now()}`,reportId:n,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:$,runCount:0};g([...c,G]),p({type:"list"})},y=B=>{if(l.type!=="edit")return;const $=l.schedule,G=uo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth);g(c.map(Z=>Z.id===$.id?{...$,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,nextRunAt:G}:Z)),p({type:"list"})},C=B=>{g(c.map($=>{if($.id!==B)return $;const G=$.isActive?$.nextRunAt:uo($.frequency,$.time,$.dayOfWeek,$.dayOfMonth);return{...$,isActive:!$.isActive,nextRunAt:G}}))},v=B=>{a(B);const $=new Date().toISOString();g(c.map(G=>G.id===B.id?{...G,lastRunAt:$,runCount:G.runCount+1}:G))},k=B=>{const $=c.find(G=>G.id===B)??null;m($)},S=()=>{b&&(g(c.filter(B=>B.id!==b.id)),m(null))},T=B=>({name:B.name,frequency:B.frequency,dayOfWeek:B.dayOfWeek??1,dayOfMonth:B.dayOfMonth??1,time:B.time,format:B.format,scope:B.scope,email:B.email??""}),s=l.type!=="list",M=c.filter(B=>B.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:s,PaperProps:{sx:{borderRadius:"12px",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:B=>D(B.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.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(Xt,{content:Zt.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:B=>D(B.palette.text.primary,.06)}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[s&&e.jsx(Ou,{initial:l.type==="edit"?T(l.schedule):Xi,isEditing:l.type==="edit",onSave:l.type==="edit"?y:z,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:c.length===0?"No schedules yet":`${M} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(w.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",disableElevation:!0,onClick:()=>p({type:"create"}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),c.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(w.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:c.map(B=>e.jsx(Mu,{schedule:B,tick:x,onToggle:C,onRunNow:v,onEdit:$=>p({type:"edit",schedule:$}),onDelete:k},B.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:B=>D(B.palette.warning.main,.06),border:"1px solid",borderColor:B=>D(B.palette.warning.main,.2)},children:[e.jsx(w.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:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:B=>D(B.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Au,{scheduleName:b.name,onConfirm:S,onCancel:()=>m(null)})]})}const $u=6e4;function Ru({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:x,onFired:f}){const b=u.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:x,onFired:f});u.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:x,onFired:f}});const m=u.useCallback(g=>{var B,$;const{reportName:z,uploadedData:y,processedData:C,schema:v,activeView:k,columnVisibility:S,columnOrder:T,filters:s,sortStack:M}=b.current;try{const G=g.scope==="all"?y:C,Z=po(G,v,s,M,k,S,T),ee=`${g.name}_scheduled`;switch(g.format){case"csv":xo(Z,ee,{scope:g.scope});break;case"excel":mo(Z,ee,{scope:g.scope});break;case"json":fo(Z,ee,{scope:g.scope});break}if(g.email){const h=encodeURIComponent(`Scheduled Report: ${g.name}`),R=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
|
|
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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:n=>ne(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>ne(n,"hoverButton")},"&:active":{boxShadow:n=>ne(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function vd({onFileUpload:t,onError:o,isUploading:n}){const[i,a]=p.useState(!1),[c,d]=p.useState(""),[l,u]=p.useState(!1),m=p.useRef(null),f=async S=>{if(!S.name.endsWith(".json")){o("Only .json files are allowed");return}const k=10*1024*1024;if(S.size>k){o("File size exceeds 10MB limit");return}d(S.name);try{const v=await S.text();let w;try{w=JSON.parse(v)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(w)){o("JSON must be an array of objects");return}if(w.length===0){o("No data rows found in JSON file");return}t(w)}catch{o("Network error — please try again")}finally{d("")}},b=S=>{S.preventDefault(),a(!0)},x=S=>{S.preventDefault(),a(!1)},g=S=>{S.preventDefault(),a(!1);const k=S.dataTransfer.files[0];k&&f(k)},B=()=>{var S;(S=m.current)==null||S.click()},y=S=>{var v;const k=(v=S.target.files)==null?void 0:v[0];k&&f(k)},j=S=>{S.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:x,onDrop:g,onPaste:S=>S.preventDefault(),onClick:B,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?S=>z(S.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:m,type:"file",accept:".json",onChange:y,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..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:S=>z(S.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(T.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(T.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(Ji,{isOpen:l,onClose:()=>u(!1)})]})}function Sd({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?a=>z(a.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(T.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 jd({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(T.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(T.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Ki({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(T.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 Cd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:a,onDeleteHistory:c,disabled:d}){const[l,u]=p.useState(!1),[m,f]=p.useState(!1),[b,x]=p.useState(-1),g=p.useRef(null),B=p.useRef(null);p.useEffect(()=>{function R(q){g.current&&!g.current.contains(q.target)&&(u(!1),f(!1))}return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);const y=p.useCallback(()=>{f(!0),x(-1),n.length>0&&u(!0)},[n.length]),j=p.useCallback(R=>{o(R),x(-1)},[o]),S=p.useCallback(R=>{var q;o(R),i(R),u(!1),(q=B.current)==null||q.blur()},[o,i]),k=p.useCallback(R=>{x(-1),S(R)},[S]),v=p.useCallback(R=>{var q;R.key==="Enter"?b>=0&&b<n.length?(R.preventDefault(),k(n[b].query)):t.trim()&&S(t.trim()):R.key==="Escape"?(u(!1),x(-1),(q=B.current)==null||q.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(l||u(!0),x(Q=>Q<n.length-1?Q+1:Q))):R.key==="ArrowUp"&&(R.preventDefault(),x(Q=>Q>0?Q-1:-1))},[b,n,t,l,k,S]),w=p.useCallback(()=>{var R;o(""),(R=B.current)==null||R.focus()},[o]),s=p.useMemo(()=>n.filter(R=>R.isFavourite),[n]),_=p.useMemo(()=>n.filter(R=>!R.isFavourite),[n]),I=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:B,size:"small",fullWidth:!0,value:t,onChange:R=>j(R.target.value),onFocus:y,onKeyDown:v,placeholder:"Search data...",disabled:d,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(T.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:w,edge:"end",sx:{mr:-.5},children:e.jsx(T.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:[s.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"}),s.map((R,q)=>e.jsx(ii,{entry:R,isSelected:b===q,onClick:()=>k(R.query),onToggleFavourite:()=>a(R.query),onDelete:()=>c(R.query)},`fav-${R.query}`))]}),_.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[s.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"}),_.map((R,q)=>{const Q=s.length+q;return e.jsx(ii,{entry:R,isSelected:b===Q,onClick:()=>k(R.query),onToggleFavourite:()=>a(R.query),onDelete:()=>c(R.query)},`recent-${R.query}`)})]})]})]})}const ii=p.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:a,onDelete:c}){const d=p.useCallback(u=>{u.stopPropagation(),a()},[a]),l=p.useCallback(u=>{u.stopPropagation(),c()},[c]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?u=>z(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>z(u.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:d,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(T.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(T.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(T.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function wd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:a,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:u,onPermanentDelete:m,isReadOnly:f,isAdmin:b=!1}){const x=_t(),[g,B]=p.useState(!1),[y,j]=p.useState(!1),[S,k]=p.useState({top:0,left:0}),[v,w]=p.useState(null),s=p.useRef(null),_=p.useRef(null),I=t.find(A=>A.id===o),R=I==null?void 0:I.isDefault,q=t.filter(A=>A.scope==="global"&&!A.isDeleted),Q=t.filter(A=>A.scope!=="global"&&!A.isDeleted),te=t.filter(A=>A.isFavorite&&!A.isDeleted).sort((A,V)=>(V.updatedAt||0)-(A.updatedAt||0)),h=t.filter(A=>A.isDeleted);p.useEffect(()=>{if(g&&_.current){const A=_.current.getBoundingClientRect();k({top:A.bottom+window.scrollY+8,left:A.right+window.scrollX-320})}},[g]),p.useEffect(()=>{const A=V=>{s.current&&!s.current.contains(V.target)&&_.current&&!_.current.contains(V.target)&&B(!1)};return g&&document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[g]);const $=A=>{if(n&&A!==o){w(A),B(!1);return}i(A),B(!1)},W=()=>{v&&(i(v),w(null))},F=()=>{w(null)},X=(A,V=!1)=>{const oe=A.scope==="global",J=!f&&(!oe||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===A.id?x.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===A.id?x.palette.primary.light+"20":x.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>$(A.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,textTransform:"none",justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===A.id&&e.jsx(T.Check,{sx:{fontSize:16,flexShrink:0}}),o!==A.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===A.id?x.palette.primary.dark:x.palette.text.primary,fontWeight:o===A.id?500:400},children:A.name}),V&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:x.palette.text.secondary,backgroundColor:x.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[J&&l&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),l(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:A.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(T.Star,{sx:{fontSize:16}})}),J&&d&&!A.isDefault&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),d(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:"Set as default",children:e.jsx(T.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},A.id)},xe=A=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:x.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:x.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:A.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[u&&e.jsx(r.IconButton,{onClick:V=>{V.stopPropagation(),u(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:"Restore view",children:e.jsx(T.Undo,{sx:{fontSize:16,color:"success.main"}})}),m&&e.jsx(r.IconButton,{onClick:V=>{V.stopPropagation(),m(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:"Delete permanently",children:e.jsx(T.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},A.id),me=n||!R,Y=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:_,onClick:()=>B(!g),size:"small",sx:{position:"relative",color:me?"warning.main":"text.secondary",bgcolor:me?z(x.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:me?z(x.palette.warning.main,.2):z(x.palette.text.primary,.06),color:me?"warning.dark":"text.primary"}},title:`View: ${(I==null?void 0:I.name)||"Default View"}`,children:[e.jsx(T.Visibility,{sx:{fontSize:20}}),Y&&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"}})]}),g&&gi.createPortal(e.jsxs(r.Box,{ref:s,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:S.top,left:S.left},children:[q.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"}),q.map(A=>X(A,A.isDefault))]}),te.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(T.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),te.map(A=>X(A))]})]}),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(A=>X(A))]})]}),h.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(!y),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.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",h.length,")"]}),e.jsx(T.ChevronRight,{sx:{fontSize:16}})]}),y&&e.jsx(r.Box,{sx:{backgroundColor:x.palette.grey[50]},children:h.map(A=>xe(A))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{a(),B(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:x.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[50]}},children:[e.jsx(T.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),B(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:x.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[50]}},children:[e.jsx(T.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:v!==null,onClose:F,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(T.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:F,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function kd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:a,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:u,onSortDescending:m,onRemoveSort:f,onFilter:b,onClearFilter:x,onGroupByColumn:g,onHideColumn:B,onManageColumns:y,onManageViews:j,onResetLayout:S,onClose:k}){var te,h;const w=_t().palette,s=p.useRef(null);p.useEffect(()=>{if(!s.current)return;const $=s.current,W=$.getBoundingClientRect(),F=window.innerWidth,X=window.innerHeight;W.right>F-8&&($.style.left=`${F-W.width-8}px`),W.bottom>X-8&&($.style.top=`${X-W.height-8}px`)},[l]),p.useEffect(()=>{const $=F=>{s.current&&!s.current.contains(F.target)&&k()},W=F=>{F.key==="Escape"&&k()};return document.addEventListener("mousedown",$),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",$),document.removeEventListener("keydown",W)}},[k]);const _=p.useCallback($=>()=>{$(),k()},[k]),I=(n==null?void 0:n.direction)==="asc",R=(n==null?void 0:n.direction)==="desc",q=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",Q=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return gi.createPortal(e.jsxs(r.Paper,{ref:s,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:1400,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",boxShadow:`0 4px 20px ${z(((te=w.common)==null?void 0:te.black)??"#000",.12)}, 0 1px 4px ${z(((h=w.common)==null?void 0:h.black)??"#000",.06)}`},children:[!c&&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 (${q})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:_(()=>u(t)),sx:{p:.625,borderRadius:"6px",color:I?"primary.main":"text.secondary",bgcolor:I?z(w.primary.main,.1):"transparent","&:hover":{bgcolor:z(w.primary.main,.08),color:"primary.main"}},children:e.jsx(T.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${Q})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:_(()=>m(t)),sx:{p:.625,borderRadius:"6px",color:R?"primary.main":"text.secondary",bgcolor:R?z(w.primary.main,.1):"transparent","&:hover":{bgcolor:z(w.primary.main,.08),color:"primary.main"}},children:e.jsx(T.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:!a,onClick:_(()=>f(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:z(w.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(T.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:_(()=>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(T.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&&!c&&e.jsxs(r.MenuItem,{onClick:_(()=>x(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:z(w.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(T.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&g&&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:_(()=>g(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(T.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:[!c&&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:_(()=>B(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(T.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:_(y),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:z(w.primary.main,.08),color:"primary.main"}},children:e.jsx(T.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:_(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(T.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),j&&e.jsxs(r.MenuItem,{onClick:_(j),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(T.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!c&&d&&S&&e.jsxs(r.MenuItem,{onClick:_(S),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:z(w.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(T.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const Td=176,si="COLUMN_HEADER",Id=p.memo(function({column:o,index:n,sortRule:i,hasFilters:a,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:u,onColumnClick:m,onMoveColumn:f,onColumnDragEnd:b,onResizeStart:x,onSortAscending:g,onSortDescending:B,onRemoveSort:y,onOpenFilterForColumn:j,onClearFiltersForColumn:S,onGroupByColumn:k,onHideColumn:v,onManageColumns:w,onManageViews:s,onResetLayout:_}){const I=p.useRef(null),[R,q]=p.useState(!1),[Q,te]=p.useState({x:0,y:0}),[{handlerId:h,isOver:$},W]=Ot.useDrop({accept:si,collect(J){return{handlerId:J.getHandlerId(),isOver:J.isOver()}},hover(J,ee){var ge;if(!I.current)return;const le=J.index,ie=n;if(le===ie)return;const N=(ge=I.current)==null?void 0:ge.getBoundingClientRect(),se=(N.right-N.left)/2,ce=ee.getClientOffset(),ae=((ce==null?void 0:ce.x)??0)-N.left;le<ie&&ae<se||le>ie&&ae>se||(f(le,ie),J.index=ie)}}),[{isDragging:F},X]=Ot.useDrag({type:si,item:()=>({index:n,columnName:o.name}),collect:J=>({isDragging:J.isDragging()}),end:()=>{b==null||b()}});X(W(I));const xe=p.useCallback(J=>{J.preventDefault(),J.stopPropagation(),te({x:J.clientX,y:J.clientY}),q(!0)},[]),me=p.useCallback(()=>q(!1),[]),Y=p.useCallback(()=>{m(o.name)},[m,o.name]),A=p.useCallback(J=>{J.stopPropagation(),j(o.name)},[j,o.name]),V=p.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(T.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(T.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]),oe=p.useCallback(()=>a?e.jsx(T.FilterList,{onClick:A,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,[a,A]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:I,"data-handler-id":h,"data-column-index":n,onClick:Y,onContextMenu:xe,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:F?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:$?J=>z(J.palette.primary.main,.08):"action.hover",boxShadow:"0 1px 0 rgba(0,0,0,0.08)",backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:J=>z(J.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${Td}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Ke(o.name),V(),oe()]}),e.jsx(r.Box,{draggable:!1,onDragStart:J=>J.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:J=>{J.preventDefault(),J.stopPropagation(),x(J,o.name)},onClick:J=>J.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"}})}),$&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),R&&e.jsx(kd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:a,isInSortStack:c,isReadOnly:d,hasModifications:l,position:Q,onSortAscending:g,onSortDescending:B,onRemoveSort:y,onFilter:j,onClearFilter:S,onGroupByColumn:k,onHideColumn:v,onManageColumns:w,onManageViews:s,onResetLayout:_,onClose:me})]})});function zd({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:a,onClearSelection:c,onBulkSetFavorites:d}){const[l,u]=p.useState(null),m=p.useMemo(()=>Array.from(o),[o]),f=p.useMemo(()=>m.filter(S=>n.has(S)),[m,n]),b=p.useMemo(()=>m.filter(S=>!n.has(S)),[m,n]),x=f.length>0,g=b.length>0;if(t===0)return null;const B=()=>{d&&d(m,!0)},y=()=>{d&&d(m,!1)},j=S=>{a(S),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:S=>z(S.palette.primary.main,.08),borderBottom:S=>`1px solid ${z(S.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(T.Close,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:S=>z(S.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:S=>u(S.currentTarget),startIcon:e.jsx(T.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:S=>z(S.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:S=>z(S.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:l,open:!!l,onClose:()=>u(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:180,borderRadius:1.5}},children:[e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:B,startIcon:e.jsx(T.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:S=>z(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>z(S.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&x&&e.jsx(r.Button,{onClick:y,startIcon:e.jsx(T.Star,{sx:{fontSize:16,color:"#fbbc04"}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:S=>z(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>z(S.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const Bd={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 ko(t,o){const n=Bd[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 Ed(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 Dd={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 Od(t,o){const n=Dd[o];return n?t.palette[n.hue][n.shade]:t.palette.text.secondary}function Le(t){return z(t.palette.primary.main,t.palette.mode==="dark"?.24:.12)}function Ad(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=>ko(n,o).bg,color:n=>ko(n,o).color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function _d(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 Ad(n);if(/\b(priority|severity|urgency)\b/.test(i)){const a=n.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:c=>{const d=Ed(c,a);return d?{color:d,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 Md(t){const o=t.find(a=>{const c=a.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(c)})||t[0]||null,n=t.find(a=>{const c=a.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(c)&&a!==o})||null,i=t.filter(a=>a!==o&&a!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function $d({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:a,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:u,onEdit:m,onDuplicate:f,onDelete:b}){const[x,g]=p.useState(null),[B,y]=p.useState(!1),{primaryCol:j,idCol:S,bodyColumns:k}=p.useMemo(()=>Md(n),[n]),v=j?t[j.name]:null,w=S?t[S.name]:null,s=B||i||a||!!x;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":_=>z(_.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?_=>`0 0 0 3px ${z(_.palette.primary.main,.15)}, 0 2px 8px ${z(_.palette.common.black,.08)}`:B?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:B&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:_=>z(_.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:v!=null&&v!==""?String(v):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:[k.map(_=>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:Ke(_.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:_d(_,t[_.name])})]},_.name)),k.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:_=>z(_.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:w?.85:0,userSelect:"none"},children:w?String(w):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:s?1:0,transition:"opacity 0.15s ease"},onClick:_=>_.stopPropagation(),children:[l&&e.jsx(r.Tooltip,{title:a?"Remove from favorites":"Add to favorites",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:_=>{_.stopPropagation(),l(t)},sx:{width:28,height:28,color:a?"warning.main":"action.disabled","&:hover":{bgcolor:_=>z(_.palette.warning.main,.1),color:"warning.main"}},children:a?e.jsx(T.Star,{sx:{fontSize:17}}):e.jsx(T.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:_=>{_.stopPropagation(),g(_.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:_=>z(_.palette.text.primary,.08)}},children:e.jsx(T.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!x,anchorEl:x,onClose:()=>g(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:"0 4px 20px rgba(60,64,67,0.15), 0 1px 6px rgba(60,64,67,0.1)"}},onClick:_=>_.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{u(t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(T.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{m(t,o),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(T.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(T.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{b(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(T.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Rd({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:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:a=>z(a.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(T.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(T.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:ki(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:a=>z(a.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(([a,c])=>wi(c)).filter(Boolean).join(" • ")})]})}function Wd({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:a,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:u,onToggleRowSelection:m,onToggleRowFavorite:f,onToggleGroupCollapse:b,onViewRow:x,onEditRow:g,onDuplicateRow:B,onDeleteRow:y}){const j=p.useMemo(()=>{const S=new Set;return i.forEach(k=>{const v=k==null?void 0:k.__urm_row_id__;v!==void 0&&S.add(v)}),S},[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,{children:[u&&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(S=>{const k=l.find(v=>v.column===S.name);return e.jsxs(r.Box,{onClick:()=>u(S.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:k?"primary.main":"divider",bgcolor:k?v=>z(v.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:v=>z(v.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:k?600:400,color:k?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ke(S.name)}),k?k.direction==="asc"?e.jsx(T.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(T.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(T.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},S.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((S,k)=>d&&S.isGroupHeader?e.jsx(Rd,{row:S,grouping:n,onToggleCollapse:b||(()=>{})},`group-${S.groupKey}`):e.jsx($d,{row:S,rowIndex:k,visibleColumns:o,isSelected:j.has(S==null?void 0:S.__urm_row_id__),isFavorite:a.has(S),isReadOnly:c,onToggleSelection:()=>m(S),onToggleFavorite:f,onView:x,onEdit:g,onDuplicate:B,onDelete:y},`card-${k}`))})]})}const ai=[10,15,25,50,100];function Pd(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 Nd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:a,onPageSizeChange:c}){var $;const l=_t().palette,u=Math.ceil(n/o),[m,f]=p.useState(String(t)),[b,x]=p.useState(null),[g,B]=p.useState(!1),y=p.useRef(null);p.useEffect(()=>{g||(f(String(t)),x(null))},[t,g]);const j=p.useCallback(()=>{const W=Pd(m,u);if(W){x(W);return}const F=parseInt(m.trim(),10);x(null),B(!1),F!==t&&a(F)},[m,u,t,a]),S=p.useCallback(W=>{var F;W.key==="Enter"?(W.preventDefault(),j()):W.key==="Escape"&&(f(String(t)),x(null),B(!1),(F=y.current)==null||F.blur())},[j,t]),k=p.useCallback(()=>{f(String(t)),x(null),B(!1)},[t]),v=p.useCallback(()=>{B(!0),x(null),setTimeout(()=>{var W;return(W=y.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ai))return null;const w=()=>{f(String(t)),x(null),B(!1)},s=()=>{w(),a(1)},_=()=>{w(),t>1&&a(t-1)},I=()=>{w(),t<u&&a(t+1)},R=()=>{w(),a(u)},q=(t-1)*o+1,Q=Math.min(t*o,n),te=`${Math.max(2,String(u).length+.5)}ch`,h={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=>c(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:ai.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:[q,"–",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:[b&&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((($=l.common)==null?void 0:$.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:b})}),e.jsx(r.InputBase,{inputRef:y,value:m,onChange:W=>{f(W.target.value),b&&x(null)},onKeyDown:S,onFocus:v,onBlur:k,inputProps:{"aria-label":`Page number, 1 to ${u}`,style:{textAlign:"center",padding:"2px 0",width:te,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":g?"primary.main":"divider",borderRadius:"4px",bgcolor:b?z(l.error.main,.04):g?z(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:b?"error.main":"text.secondary"},"&:focus-within":{boxShadow:b?`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 ",u]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{onClick:s,disabled:t===1,size:"small",title:"First page",sx:h,children:e.jsx(T.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:_,disabled:t===1,size:"small",title:"Previous page",sx:h,children:e.jsx(T.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:I,disabled:t===u,size:"small",title:"Next page",sx:h,children:e.jsx(T.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:R,disabled:t===u,size:"small",title:"Last page",sx:h,children:e.jsx(T.LastPage,{sx:{fontSize:20}})})]})]})]})}function Ld(){return e.jsx(r.Chip,{icon:e.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 Xi="urm_hint_seen_";function Fd(t){try{return localStorage.getItem(Xi+t)==="true"}catch{return!1}}function Vd(t){try{localStorage.setItem(Xi+t,"true")}catch{}}function li(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 ci(t){const o={fontSize:11};switch(t){case"number":return e.jsx(T.Numbers,{sx:o});case"boolean":return e.jsx(T.CheckBox,{sx:o});case"array":return e.jsx(T.DataArray,{sx:o});case"object":return e.jsx(T.DataObject,{sx:o});default:return e.jsx(T.TextFields,{sx:o})}}function di(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 Hd({open:t,onClose:o,row:n,schema:i,reportName:a}){var b,x;const d=_t().palette;if(!n)return null;const l=i.filter(g=>g.name in n),u=l.filter(g=>g.type!=="object"&&g.type!=="array"),m=l.filter(g=>g.type==="object"||g.type==="array"),f=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${z(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${z(((x=d.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(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(T.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"}),a&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a," · ",f," ",f===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(T.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:z(d.text.primary,.015)},children:[u.length>0&&e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"1px",bgcolor:"divider",m:2,mb:m.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:u.map((g,B)=>{const y=n[g.name],j=li(y,g.type),S=!j,k=di(g.type,d),v=B===u.length-1&&u.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:v?"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:k.bg,color:k.color,flexShrink:0},children:ci(g.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:Ke(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:S?400:500,color:S?"text.disabled":"text.primary",fontStyle:S?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:S?"No value":j})]},g.name)})}),m.map(g=>{const B=n[g.name],y=li(B,g.type),j=!y,S=di(g.type,d);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:S.bg,color:S.color},children:ci(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ke(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:S.bg,color:S.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:z(d.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":y})]},g.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(T.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",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:3,py:.75,borderRadius:"8px",minWidth:80},children:"Close"})})]})}function Ud({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:a=>ne(a,"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:a=>z(a.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(T.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(T.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:a=>z(a.palette.error.main,.1),border:a=>`1px solid ${z(a.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:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",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(T.DeleteForever,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:a=>ne(a,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:a=>ne(a,"hoverButton")},"&:active":{boxShadow:a=>ne(a,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function en(t){const o={fontSize:11};switch(t){case"number":return e.jsx(T.Numbers,{sx:o});case"boolean":return e.jsx(T.CheckBox,{sx:o});case"array":return e.jsx(T.DataArray,{sx:o});case"object":return e.jsx(T.DataObject,{sx:o});default:return e.jsx(T.TextFields,{sx:o})}}function ui(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 Yd({open:t,onClose:o,onSave:n,row:i,schema:a,reportName:c}){var j,S,k;const l=_t().palette,[u,m]=p.useState({});if(p.useEffect(()=>{t&&i&&m({...i})},[t,i]),!i)return null;const f=a.filter(v=>v.name in i),b=f.filter(v=>v.type!=="object"&&v.type!=="array"),x=f.filter(v=>v.type==="object"||v.type==="array"),g=(v,w)=>{m(s=>({...s,[v]:w}))},B=()=>{const v={...u};f.forEach(w=>{const s=u[w.name];if(w.type==="number"){const _=Number(s);v[w.name]=isNaN(_)?i[w.name]:_}else w.type==="boolean"&&(v[w.name]=!!s)}),n(v),o()},y=f.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",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(((S=l.common)==null?void 0:S.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(((k=l.warning)==null?void 0:k.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(T.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"}),c&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c," · ",y," ",y===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(T.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:[b.length>0&&e.jsxs(r.Box,{children:[b.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:b.map((v,w)=>{const s=u[v.name],_=ui(v.type,l),I=v.type==="boolean",R=!I&&w===b.filter(Q=>Q.type!=="boolean").length-1&&b.filter(Q=>Q.type!=="boolean").length%2!==0,q=I||R;return v.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:_.bg,color:_.color},children:en(v.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ke(v.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:s?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!s,onChange:Q=>g(v.name,Q.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},v.name):e.jsxs(r.Box,{sx:{gridColumn:q?"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:_.bg,color:_.color},children:en(v.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:Ke(v.name)})]}),e.jsx(r.TextField,{value:s??"",onChange:Q=>g(v.name,Q.target.value),type:v.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${v.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:v.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},v.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(T.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:x.map(v=>{const w=i[v.name];let s="";try{s=w==null?"":JSON.stringify(w,null,2)}catch{s=String(w)}const _=ui(v.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:_.bg,color:_.color},children:en(v.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ke(v.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:s?"text.primary":"text.disabled",fontStyle:s?"normal":"italic",bgcolor:z(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:s||"No value"})]},v.name)})})]}),f.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(T.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:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:B,variant:"contained",disableElevation:!0,startIcon:e.jsx(T.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const wr=176,Gd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function qd(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=>ko(n,o).bg,color:n=>ko(n,o).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Jd(t){const o=t.toLowerCase().trim(),n=Gd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Kd(t){return e.jsx(r.Box,{component:"span",sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.8125rem",fontWeight:400,letterSpacing:"0.04em"},children:t})}function Xd(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),a=o.findIndex(m=>m.name===t.name),c=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),d=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),l=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),u=a===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||u&&!l}function Zd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Qd(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const a=String(o),c=t.name.toLowerCase().replace(/[_\s-]/g,""),d=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(d)return qd(a);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Jd(a);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(a);if(u)return Kd(a);if(n&&!d&&!l&&!u)return Zd(a);if(t.type==="date"){const m=t.dateFormat??"iso",f=Zs(o,m,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:f})}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:"grey.400"},children:"[ ]"});const m=o.slice(0,3).map(f=>typeof f=="object"?JSON.stringify(f):String(f)).join(", ");return e.jsxs(r.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[m,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const m=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:m,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:m.length>40?m.slice(0,40)+"…":m})}return a}function eu({schema:t,data:o,sortStack:n=[],filters:i=[],views:a=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:u={},columnOrder:m=[],columnWidths:f={},grouping:b=null,onSort:x,onSortAscending:g,onSortDescending:B,onOpenFilters:y,onOpenSort:j,onOpenFilterForColumn:S,onSelectView:k,onCreateView:v,onManageViews:w,onUpdateCurrentView:s,onSaveAsNewView:_,onToggleDefault:I,onToggleFavorite:R,onRestoreView:q,onPermanentDelete:Q,isAdmin:te=!1,onExport:h,onOpenColumns:$,onUpdateColumnWidth:W,onUpdateColumnOrder:F,onUpdateColumnVisibility:X,onClearFiltersForColumn:xe,onResetLayout:me,onOpenGroup:Y,onGroupByColumn:A,onToggleGroupCollapse:V,onOpenAuditHistory:oe,onOpenScheduledReports:J,searchQuery:ee,searchHistory:le=[],onAddToSearchHistory:ie,onToggleSearchFavourite:N,onDeleteSearchHistory:se,selectedRowIds:ce=new Set,onSearchChange:ae,onToggleRowSelection:ge,onToggleAllRows:K,onRangeSelection:Me,onClearSelection:Ue,onExportSelected:nt,currentPage:sr=1,pageSize:Tr=15,totalRowsBeforePagination:Ft=o.length,onPageChange:ut,onPageSizeChange:Fe,isReadOnly:Be=!1,userRole:Mt,reportName:St,onEditRow:Ze,onDuplicateRow:He,onDeleteRow:Qe,favoriteRowIndices:ar=[],resolvedFavoritesSet:et=new Set,showFavoritesOnly:it=!1,onToggleRowFavorite:We,onBulkSetFavorites:lr,showDevPanel:Ir=!1,onOpenDevConfig:Vt,onToggleFavoritesFilter:pt}){var Re;const[jt,cr]=p.useState(null),[Ct,io]=p.useState(0),[dr,zr]=p.useState(0),[wt,st]=p.useState(null),Ht=((Re=or().dates)==null?void 0:Re.displayFormat)??null,[je,Er]=p.useState(null),[ur,at]=p.useState(null),[L,Ye]=p.useState(null),[Ce,Ve]=p.useState(!1),[Dr,Ut]=p.useState(!1),[kt,$t]=p.useState(null),[Yt,Gt]=p.useState(""),[Or,qt]=p.useState(!1),[$e,Z]=p.useState(null),[Tt,we]=p.useState(null),[ke,lt]=p.useState(null),[pr,xt]=p.useState(null),[Ge,xr]=p.useState("list"),[mr,fr]=p.useState(!1),[It,Ar]=p.useState(()=>!Fd("toolbar_search"));p.useRef(null);const Rt=p.useRef(null),Jt=p.useRef(null),tt=p.useCallback(()=>{Vd("toolbar_search"),Ar(!1)},[]);p.useEffect(()=>{if(!It)return;const E=setTimeout(tt,2e3);return()=>clearTimeout(E)},[It,tt]);const ct=p.useMemo(()=>{const E=wt??m;return E.length>0?E.map(U=>t.find(pe=>pe.name===U)).filter(U=>U!==void 0):t},[wt,m,t]),Pe=p.useMemo(()=>ct.filter(E=>u[E.name]!==!1),[ct,u]),mt=p.useMemo(()=>t.filter(E=>u[E.name]===!1).length,[t,u]),hr=p.useMemo(()=>t.map(E=>E.name),[t]),ft=p.useMemo(()=>m.length===0?!1:JSON.stringify(m)!==JSON.stringify(hr),[m,hr]),_r=p.useCallback((E,U)=>{E.preventDefault(),E.stopPropagation(),cr(U),io(E.clientX),zr(f[U]||150)},[f]);p.useEffect(()=>{if(!jt)return;const E=pe=>{const Ne=pe.clientX-Ct,de=Math.max(100,Math.min(600,dr+Ne));W==null||W(jt,de)},U=()=>{cr(null)};return document.addEventListener("mousemove",E),document.addEventListener("mouseup",U),()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",U)}},[jt,Ct,dr,W]);const Mr=p.useCallback(E=>E==null?"-":typeof E=="object"?JSON.stringify(E):typeof E=="boolean"?E?"true":"false":String(E),[]);p.useCallback(E=>{const U=n.find(pe=>pe.column===E);return U?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[U.direction==="asc"?e.jsx(T.ArrowUpward,{sx:{fontSize:14}}):e.jsx(T.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:U.priority})]}):null},[n]),p.useCallback(E=>i.some(pe=>pe.column===E)?e.jsx(r.IconButton,{size:"small",onClick:pe=>{pe.stopPropagation(),S==null||S(E)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(T.FilterList,{sx:{fontSize:14}})}):null,[i,S]);const $r=p.useCallback(E=>{x&&x(E)},[x]),Rr=p.useCallback((E,U)=>{st(pe=>{const de=[...pe??(m.length>0?m:t.map(Vo=>Vo.name))],[Bt]=de.splice(E,1);return de.splice(U,0,Bt),de})},[m,t]),gr=p.useCallback(()=>{wt&&F&&F(wt),st(null)},[wt,F]),Wr=p.useCallback(E=>{if(!x)return;const U=n.find(pe=>pe.column===E);(!U||U.direction!=="asc")&&x(E)},[x,n]),Pr=p.useCallback(E=>{if(!x)return;const U=n.find(pe=>pe.column===E);U?U.direction==="asc"&&x(E):(x(E),setTimeout(()=>x(E),0))},[x,n]),Nr=p.useCallback(E=>{if(!x)return;const U=n.find(pe=>pe.column===E);U&&(U.direction==="asc"?(x(E),setTimeout(()=>x(E),0)):U.direction==="desc"&&x(E))},[x,n]),Wt=p.useCallback(E=>{X&&X(E,!1)},[X]),yr=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Lr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(E=>E===!1),Kt=(sr-1)*Tr,Ae=o,dt=p.useMemo(()=>{const E=new Set;return ce.forEach(U=>{const pe=U==null?void 0:U.__urm_row_id__;pe!==void 0&&E.add(pe)}),E},[ce]);p.useEffect(()=>{const E=U=>{!K||!Ue||U.target instanceof HTMLInputElement||U.target instanceof HTMLTextAreaElement||((U.ctrlKey||U.metaKey)&&U.key==="a"&&(U.preventDefault(),K(!0,Ae)),U.key==="Escape"&&(U.preventDefault(),Ue()))};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[K,Ue,Ae]);const Xt=p.useCallback((E,U)=>{ge&&(U.shiftKey&&je!==null?(U.preventDefault(),Me&&Me(je,E,Ae)):(ge(Ae[E]),Er(E)))},[ge,je,Me,Ae]);!p.useMemo(()=>Ae.length>0&&dt.size>0&&Ae.every(E=>dt.has(E==null?void 0:E.__urm_row_id__)),[Ae,dt])&&Ae.some(E=>dt.has(E==null?void 0:E.__urm_row_id__));const zt=ge&&K,ue=p.useCallback(E=>{var Ne;const U=E.groupLevel,pe=U*24;return e.jsx(r.TableRow,{onClick:()=>V==null?void 0:V(E.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Pe.length+(zt?1:0),sx:{pl:`${pe+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[E.isCollapsed?e.jsx(T.ChevronRight,{sx:{fontSize:16}}):e.jsx(T.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:ki(U,((Ne=b==null?void 0:b.levels[U])==null?void 0:Ne.column)||"",E.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:de=>z(de.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[E.rowCount," ",E.rowCount===1?"row":"rows"]}),Object.keys(E.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(E.aggregates).map(([de,Bt])=>wi(Bt)).filter(Boolean).join(" • ")})]})})},E.groupKey)},[Pe,zt,b,V]),fe=p.useCallback((E,U)=>{const pe=dt.has(E==null?void 0:E.__urm_row_id__),Ne=ur===U;return e.jsxs(r.TableRow,{"data-row-index":U,onMouseEnter:()=>at(U),onMouseLeave:()=>at(null),onClick:de=>{!ge||de.target.closest("[data-row-action-btn]")||Xt(U,de)},onContextMenu:de=>{de.preventDefault(),de.stopPropagation(),lt({mouseX:de.clientX,mouseY:de.clientY,row:E,rowIndex:U})},sx:{height:34,cursor:"pointer",bgcolor:pe?de=>z(de.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:pe?de=>z(de.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Pe.map((de,Bt)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...Bt===Pe.length-1&&{pr:`${We?76:40}px`},fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:f[de.name]?`${f[de.name]}px`:`${de.type==="date"?Math.max(wr,180):wr}px`},children:Qd(de,E[de.name],Xd(de,Pe),Ht)},de.name)),e.jsx(r.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:We?76:40,minWidth:We?76:40,maxWidth:We?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:Ne||et.has(E)?de=>`linear-gradient(to right, transparent, ${pe?`rgba(${de.palette.mode==="dark","237,108,2"},0.12)`:de.palette.background.paper} 32px)`:"transparent",opacity:Ne||et.has(E)?1:0,transition:"opacity 0.12s ease, background 0.12s ease",zIndex:10,verticalAlign:"middle"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:[We&&e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:de=>{de.stopPropagation(),de.preventDefault(),We(E)},title:et.has(E)?"Remove from favorites":"Add to favorites",sx:{color:et.has(E)?"warning.main":"text.secondary","&:hover":{bgcolor:de=>z(de.palette.warning.main,.08),color:"warning.main"}},children:et.has(E)?e.jsx(T.Star,{sx:{fontSize:18}}):e.jsx(T.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:de=>{de.stopPropagation(),de.preventDefault(),lt({anchorEl:de.currentTarget,row:E,rowIndex:U})},sx:{color:"text.secondary",opacity:Ne?1:0,transition:"opacity 0.12s ease",pointerEvents:Ne?"auto":"none","&:hover":{bgcolor:de=>z(de.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(T.MoreVert,{sx:{fontSize:18}})})]})})]},U)},[ce,Kt,ur,Xt,Pe,f,Mr,Ze,He,Qe,ge,We,et,Ye,Ve,lt]);return e.jsxs(Ot.DndProvider,{backend:sn.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[zt&&nt&&Ue&&e.jsx(zd,{selectedCount:dt.size,selectedRowIds:ce,resolvedFavoritesSet:et,viewMode:Ge,onExportSelected:nt,onClearSelection:Ue,onBulkSetFavorites:lr}),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:[Be&&e.jsx(Ld,{}),ae&&ie&&N&&se&&e.jsx(r.Tooltip,{open:It,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:tt},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(Cd,{value:ee||"",onChange:E=>{It&&tt(),ae(E)},searchHistory:le,onAddToHistory:ie,onToggleFavourite:N,onDeleteHistory:se,disabled:Be})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>fr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:E=>z(E.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(T.InfoOutlined,{sx:{fontSize:20}})})}),pt&&e.jsx(r.Tooltip,{title:it?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:pt,size:"small",disabled:Be,sx:{position:"relative",color:it?"warning.main":"text.secondary",bgcolor:it?E=>z(E.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:it?E=>z(E.palette.warning.main,.2):E=>z(E.palette.text.primary,.06),color:it?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[it?e.jsx(T.Star,{sx:{fontSize:20}}):e.jsx(T.StarBorder,{sx:{fontSize:20}}),it&&ar.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:"warning.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:ar.length})]})}),Ir&&Vt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:Vt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:E=>z(E.palette.text.secondary,.3),"&:hover":{bgcolor:E=>z(E.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(T.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),k&&v&&w&&s&&a.length>0&&e.jsx(wd,{views:a||[],activeViewId:c||"",isDirty:d,onSelectView:k,onCreateView:v,onManageViews:w,onToggleDefault:I,onToggleFavorite:R,onRestoreView:q,onPermanentDelete:Q,isAdmin:te,isReadOnly:Be}),!Be&&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?E=>Le(E):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?E=>z(E.palette.primary.main,.2):E=>z(E.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(T.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:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Be&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?E=>Le(E):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?E=>z(E.palette.primary.main,.2):E=>z(E.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(T.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:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Be&&$&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:$,size:"small",sx:{position:"relative",color:mt>0||ft?"primary.main":"text.secondary",bgcolor:mt>0||ft?E=>Le(E):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:mt>0||ft?E=>z(E.palette.primary.main,.2):E=>z(E.palette.text.primary,.06),color:mt>0||ft?"primary.main":"text.primary"}},children:[e.jsx(T.ViewColumn,{sx:{fontSize:20}}),mt>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:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:mt})]})}),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:()=>xr("list"),sx:{borderRadius:1,color:Ge==="list"?"primary.main":"text.secondary",bgcolor:Ge==="list"?E=>Le(E):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ge==="list"?E=>z(E.palette.primary.main,.2):E=>z(E.palette.text.primary,.06),color:Ge==="list"?"primary.main":"text.primary"}},children:e.jsx(T.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>xr("grid"),sx:{borderRadius:1,color:Ge==="grid"?"primary.main":"text.secondary",bgcolor:Ge==="grid"?E=>Le(E):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ge==="grid"?E=>z(E.palette.primary.main,.2):E=>z(E.palette.text.primary,.06),color:Ge==="grid"?"primary.main":"text.primary"}},children:e.jsx(T.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:E=>xt(E.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:E=>z(E.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(T.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!pr,anchorEl:pr,onClose:()=>xt(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:[h&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(),xt(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Be&&Y&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Y(),xt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),oe&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{oe(),xt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),J&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{J(),xt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.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:[Ge==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Wd,{data:Ae,visibleColumns:Pe,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:et,isReadOnly:Be,isGrouped:!!yr,sortStack:n,onSort:x,onToggleRowSelection:ge||(()=>{}),onToggleRowFavorite:We,onToggleGroupCollapse:V,onViewRow:E=>{Ye(E),Ve(!0)},onEditRow:(E,U)=>{Z(E),we(U),qt(!0)},onDuplicateRow:(E,U)=>He==null?void 0:He(E,U),onDeleteRow:(E,U)=>{$t(U);const pe=Object.values(U).find(Ne=>Ne!=null&&Ne!=="");Gt(pe?String(pe):""),Ut(!0)}})}),Ge==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Rt,onScroll:E=>{Jt.current&&(Jt.current.scrollLeft=E.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:`${Pe.reduce((E,U)=>E+(f[U.name]||(U.type==="date"?180:wr)),We?76:40)}px`},children:[e.jsxs("colgroup",{children:[Pe.map(E=>e.jsx("col",{style:{width:`${f[E.name]||(E.type==="date"?180:wr)}px`}},E.name)),e.jsx("col",{style:{width:`${We?76:40}px`}})]}),e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Pe.map((E,U)=>e.jsx(Id,{column:E,index:U,sortRule:n.find(pe=>pe.column===E.name),hasFilters:i.some(pe=>pe.column===E.name),isInSortStack:n.some(pe=>pe.column===E.name),isReadOnly:Be,hasModifications:Lr,width:f[E.name],onColumnClick:$r,onMoveColumn:Rr,onColumnDragEnd:gr,onResizeStart:_r,onSortAscending:g||Wr,onSortDescending:B||Pr,onRemoveSort:Nr,onOpenFilterForColumn:S||(()=>{}),onClearFiltersForColumn:xe||(()=>{}),onGroupByColumn:A,onHideColumn:Wt,onManageColumns:$||(()=>{}),onManageViews:w,onResetLayout:me},E.name)),e.jsx(r.TableCell,{sx:{width:We?76:40,minWidth:We?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),e.jsx(r.Box,{ref:Jt,onScroll:E=>{Rt.current&&(Rt.current.scrollLeft=E.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:E=>E.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:E=>E.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:`${Pe.reduce((E,U)=>E+(f[U.name]||(U.type==="date"?180:wr)),We?76:40)}px`},children:[e.jsxs("colgroup",{children:[Pe.map(E=>e.jsx("col",{style:{width:`${f[E.name]||(E.type==="date"?180:wr)}px`}},E.name)),e.jsx("col",{style:{width:`${We?76:40}px`}})]}),e.jsx(r.TableBody,{children:Ae.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Pe.length+(zt?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):yr?Ae.map((E,U)=>E.isGroupHeader?ue(E):fe(E,U)):Ae.map((E,U)=>fe(E,U))})]})})]}),ut&&Fe&&e.jsx(Nd,{currentPage:sr,pageSize:Tr,totalRows:Ft,totalFields:t.length,onPageChange:ut,onPageSizeChange:Fe}),!(ut&&Fe)&&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 ",Ae.length," ",Ae.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!ke,onClose:()=>lt(null),anchorEl:(ke==null?void 0:ke.anchorEl)||null,anchorReference:ke!=null&&ke.anchorEl?"anchorEl":"anchorPosition",anchorPosition:ke&&!ke.anchorEl?{top:ke.mouseY,left:ke.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:ke!=null&&ke.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:()=>{ke&&(Ye(ke.row),Ve(!0)),lt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ke&&(Z(ke.row),we(ke.rowIndex),qt(!0)),lt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ke&&(He==null||He(ke.rowIndex,ke.row)),lt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(T.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{if(ke){$t(ke.row);const E=Object.values(ke.row).find(U=>U!=null&&U!=="");Gt(E?String(E):""),Ut(!0)}lt(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(T.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Hd,{open:Ce,onClose:()=>{Ve(!1),Ye(null)},row:L,schema:t,reportName:St}),e.jsx(Yd,{open:Or,onClose:()=>{qt(!1),Z(null),we(null)},onSave:E=>{Tt!==null&&(Ze==null||Ze(Tt,E))},row:$e,schema:t,reportName:St}),e.jsx(Ud,{open:Dr,onClose:()=>{Ut(!1),$t(null)},onConfirm:()=>{kt!==null&&(Qe==null||Qe(kt))},rowPreview:Yt}),e.jsx(Ji,{isOpen:mr,onClose:()=>fr(!1)})]})}function nr({content:t,isDev:o=!1}){const[n,i]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:a=>i(a.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:a=>z(a.palette.primary.main,.08)}},children:e.jsx(T.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:a=>z(a.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((a,c)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:a},c))}),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:a=>z(a.palette.warning.main,.08),border:"1px solid",borderColor:a=>z(a.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 ir={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 tu({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:a,onClearAll:c,onReplaceFilters:d,onClose:l,focusColumn:u}){const[m,f]=p.useState(""),[b,x]=p.useState(""),[g,B]=p.useState(""),[y,j]=p.useState([]),S=or();p.useEffect(()=>{j([...o])},[o]),p.useEffect(()=>{u&&f(u)},[u]);const k=p.useCallback(()=>{f(""),x(""),B("")},[]),v=p.useMemo(()=>t.filter($=>$.type!=="mixed"&&$.type!=="null"&&$.type!=="array"&&$.type!=="object"),[t]),w=t.find($=>$.name===m),s=p.useMemo(()=>{const $=w?Dn(w.type):[],W=S.filter.allowedOperators;return W.length>0?$.filter(F=>W.includes(F.value)):$},[w]),_=p.useCallback(()=>!(!m||!b||co(b)&&!g.trim()||y.length>=S.filter.maxConditions),[m,b,g,y,S]),I=p.useCallback(()=>{if(!_())return;const $={column:m,operator:b};if(co(b)){const F=w==null?void 0:w.type;$.value=F==="number"?Number(g):g}if(y.some(F=>F.column===$.column&&F.operator===$.operator&&F.value===$.value)){k();return}j([...y,$]),k()},[_,m,b,w,g,y,k]),R=p.useCallback($=>{j(y.filter((W,F)=>F!==$))},[y]),q=p.useMemo(()=>y.length!==o.length?!0:JSON.stringify(y)!==JSON.stringify(o),[y,o]),Q=p.useCallback(()=>{d(y),l()},[y,d,l]),te=p.useCallback(()=>{j([...o]),k(),l()},[o,k,l]),h=p.useCallback($=>{var xe;const W=t.find(me=>me.name===$.column);if(!W)return"";const X=((xe=Dn(W.type).find(me=>me.value===$.operator))==null?void 0:xe.label)||$.operator;return co($.operator)?`${$.column} ${X.toLowerCase()} "${$.value}"`:`${$.column} ${X.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:te,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:$=>z($.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:$=>$.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:$=>$.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:$=>ne($,"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(nr,{content:ir.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:te,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(T.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:y.length>=S.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:m,onChange:$=>{f($.target.value),x(""),B("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:v.map($=>e.jsxs(r.MenuItem,{value:$.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:W=>Le(W),"&:hover":{bgcolor:W=>z(W.palette.primary.main,.2)}}},children:[Ke($.name)," (",$.type,")"]},$.name))})]}),m&&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:b,onChange:$=>{x($.target.value),B("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:s.map($=>e.jsx(r.MenuItem,{value:$.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:W=>Le(W),"&:hover":{bgcolor:W=>z(W.palette.primary.main,.2)}}},children:$.label},$.value))})]}),b&&co(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(w==null?void 0:w.type)==="number"?"number":"text",value:g,onChange:$=>B($.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:"grey.300",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:!_(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add another filter"}),y.length>=S.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 ",S.filter.maxConditions," filters allowed. Remove an existing filter to add a new one."]})]}),y.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 (",y.length,")"]}),e.jsx(r.Button,{onClick:()=>{c(),l()},sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,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:y.map(($,W)=>e.jsx(r.Chip,{label:h($),onDelete:()=>R(W),sx:{bgcolor:F=>Le(F),color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:F=>`1px solid ${z(F.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:F=>z(F.palette.primary.main,.2),borderColor:F=>z(F.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:"grey.50"},children:[e.jsx(r.Button,{onClick:te,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Q,disabled:!q,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:$=>ne($,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:$=>ne($,"hoverButton")},"&:active":{boxShadow:$=>ne($,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"grey.300",color:"grey.500"}},children:"Apply filter"})]})]})})}const pi="SORT_RULE";function ru({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:a}){const c=p.useRef(null),[{handlerId:d},l]=Ot.useDrop({accept:pi,collect(f){return{handlerId:f.getHandlerId()}},hover(f,b){var k;if(!c.current)return;const x=f.index,g=o;if(x===g)return;const B=(k=c.current)==null?void 0:k.getBoundingClientRect(),y=(B.bottom-B.top)/2,j=b.getClientOffset(),S=((j==null?void 0:j.y)??0)-B.top;x<g&&S<y||x>g&&S>y||(a(x,g),f.index=g)}}),[{isDragging:u},m]=Ot.useDrag({type:pi,item:()=>({index:o}),collect:f=>({isDragging:f.isDragging()})});return m(l(c)),e.jsxs(r.Box,{ref:c,"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:"grey.50",borderColor:"grey.300",boxShadow:f=>ne(f,"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:"0 1px 2px 0 rgba(25, 103, 210, 0.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:f=>n(o,f.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",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:"grey.100"},"&.Mui-selected":{bgcolor:f=>Le(f),"&:hover":{bgcolor:f=>z(f.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:f=>Le(f),"&:hover":{bgcolor:f=>z(f.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:"rgba(217, 48, 37, 0.08)",transform:"scale(1.1)"}},children:e.jsx(T.Close,{sx:{fontSize:18}})})]})}function ou({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[a,c]=p.useState(""),[d,l]=p.useState([]);p.useEffect(()=>{l([...o])},[o]);const u=p.useMemo(()=>JSON.stringify(d)!==JSON.stringify(o),[d,o]),m=or(),f=p.useCallback(()=>!(d.length>=m.sort.maxLevels||!a||d.some(v=>v.column===a)),[d,a]),b=p.useCallback(()=>{if(!f())return;const v=d.length+1,w={column:a,direction:"asc",priority:v};l([...d,w]),c("")},[f,a,d]),x=p.useCallback(v=>{const s=d.filter((_,I)=>I!==v).map((_,I)=>({..._,priority:I+1}));l(s)},[d]),g=p.useCallback((v,w)=>{const s=[...d];s[v]={...s[v],direction:w},l(s)},[d]),B=p.useCallback((v,w)=>{const s=[...d],[_]=s.splice(v,1);s.splice(w,0,_);const I=s.map((R,q)=>({...R,priority:q+1}));l(I)},[d]),y=p.useCallback(()=>{n([]),i()},[n,i]),j=p.useCallback(()=>{n(d),i()},[d,n,i]),S=p.useCallback(()=>{l([...o]),c(""),i()},[o,i]),k=t.filter(v=>!d.some(w=>w.column===v.name));return e.jsx(Ot.DndProvider,{backend:sn.HTML5Backend,children:e.jsx(r.Box,{onClick:S,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:"12px",bgcolor:"background.paper",outline:"none",boxShadow:v=>ne(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(nr,{content:ir.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:S,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(T.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:d.length>=m.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:a,onChange:v=>c(v.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:k.map(v=>e.jsx(r.MenuItem,{value:v.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:w=>Le(w),"&:hover":{bgcolor:w=>z(w.palette.primary.main,.2)}}},children:Ke(v.name)},v.name))})]}),e.jsx(r.Button,{onClick:b,disabled:!f(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),d.length>=m.sort.maxLevels&&e.jsxs(r.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&&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 (",d.length,"/",m.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:y,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((v,w)=>e.jsx(ru,{rule:v,index:w,onToggleDirection:g,onRemove:x,onMove:B},`${v.column}-${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:"grey.50"},children:[e.jsx(r.Button,{onClick:S,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:j,variant:"contained",disabled:!u||d.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:v=>ne(v,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:v=>ne(v,"hoverButton")},"&:active":{boxShadow:v=>ne(v,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function nu({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:a,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:u,isAdmin:m=!1,onClose:f}){var v,w;const x=_t().palette,g=t.filter(s=>!s.isDeleted),B=t.filter(s=>s.isDeleted),y=g.filter(s=>s.scope==="global"),j=g.filter(s=>s.scope!=="global"),S=s=>{var Q,te,h,$,W;const _=s.scope==="global",I=s.id===o,R=m||!_,q=m&&!_;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(s.id),f()},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:s.name}),s.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[_&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(T.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:((te=x.info)==null?void 0:te.main)??x.primary.main,border:`1px solid ${z(((h=x.info)==null?void 0:h.main)??x.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),s.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:[q&&u&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:F=>{F.stopPropagation(),u(s.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:(($=x.info)==null?void 0:$.main)??x.primary.main,bgcolor:z(((W=x.info)==null?void 0:W.main)??x.primary.main,.08)}},children:e.jsx(T.Language,{sx:{fontSize:16}})})}),R&&e.jsx(r.Tooltip,{title:_&&!m?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:_&&!m,onClick:F=>{F.stopPropagation(),a(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:z(x.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(T.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:_&&!m?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:_&&!m,onClick:F=>{F.stopPropagation(),c(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:z(x.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(T.Delete,{sx:{fontSize:15}})})})})]})]})},s.id)},k=s=>{var _;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:s.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[d&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:I=>{I.stopPropagation(),d(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:z(((_=x.success)==null?void 0:_.main)??"#2e7d32",.08)}},children:e.jsx(T.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(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:z(x.error.main,.08)}},children:e.jsx(T.Delete,{sx:{fontSize:15}})})})]})]},s.id)};return e.jsxs(r.Dialog,{open:!0,onClose:f,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"14px",maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${z(((v=x.common)==null?void 0:v.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"}),m&&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:f,size:"small",sx:{color:"text.secondary"},children:e.jsx(T.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",disableElevation:!0,startIcon:e.jsx(T.Add,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",borderRadius:"7px",fontWeight:500},children:"Create New View"})}),y.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(T.Language,{sx:{fontSize:14,color:((w=x.info)==null?void 0:w.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:y.map(S)})]}),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(S)})]}),B.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:B.map(k)})]}),g.length===0&&B.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:f,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const fo=50;function xi({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:a="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:u=10}){const[m,f]=p.useState(a),[b,x]=p.useState(!1),[g,B]=p.useState(c),[y,j]=p.useState(d),S=()=>{if(!m.trim()){x(!0);return}if(m.trim().length>fo){x(!0);return}o(m.trim(),g.trim(),y),n()},k=w=>{w.key==="Enter"&&!w.shiftKey?S():w.key==="Escape"&&n()},v=()=>i&&a?`Update ${a} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:w=>ne(w,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[v(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(T.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 ",u," saved views. Delete an existing view before creating a new one."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:m,onChange:w=>{w.target.value.length<=fo&&f(w.target.value),b&&w.target.value.trim()&&x(!1)},onKeyDown:k,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:fo},error:b&&!m.trim(),helperText:b&&!m.trim()?"View name is required":`${m.length} / ${fo}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:w=>B(w.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: ",ua(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:y,onChange:w=>j(w.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:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:S,variant:"contained",disabled:l&&!i,startIcon:e.jsx(T.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:w=>ne(w,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:w=>ne(w,"hoverButton")},"&:active":{boxShadow:w=>ne(w,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:i?"Save Changes":"Create Report View"})]})]})}function iu({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:i=>ne(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(T.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(T.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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:i=>ne(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>ne(i,"hoverButton")},"&:active":{boxShadow:i=>ne(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const go=100,yo=600,mi="COLUMN";function su({column:t,index:o,isVisible:n,width:i,onToggleVisibility:a,onWidthChange:c,moveColumn:d}){const l=p.useRef(null),[u,m]=p.useState(i.toString());p.useEffect(()=>{m(i.toString())},[i]);const[{handlerId:f},b]=Ot.useDrop({accept:mi,collect(k){return{handlerId:k.getHandlerId()}},hover(k,v){var Q;if(!l.current)return;const w=k.index,s=o;if(w===s)return;const _=(Q=l.current)==null?void 0:Q.getBoundingClientRect(),I=(_.bottom-_.top)/2,R=v.getClientOffset(),q=((R==null?void 0:R.y)??0)-_.top;w<s&&q<I||w>s&&q>I||(d(w,s),k.index=s)}}),[{isDragging:x},g]=Ot.useDrag({type:mi,item:()=>({index:o}),collect:k=>({isDragging:k.isDragging()})});g(b(l));const B=()=>{const k=parseInt(u);if(isNaN(k)){m(i.toString()),c(t.name,i);return}const v=Math.max(go,Math.min(yo,k));m(v.toString()),c(t.name,v)},y=k=>{if(k===""||/^\d+$/.test(k)){m(k);const v=parseInt(k);if(!isNaN(v)&&v>=go){const w=Math.min(yo,v);c(t.name,w)}}},j=k=>{k.key==="Enter"&&(k.preventDefault(),B(),k.target.blur())},S=k=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[k]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":f,sx:{opacity:x?.4:1,bgcolor:n?"background.paper":"grey.50",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"grey.50":"grey.100"},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(T.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ke(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:`${S(t.type)}15`,color:S(t.type),border:`1px solid ${S(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:u,onChange:k=>y(k.target.value),onBlur:B,onKeyDown:j,placeholder:"150",size:"small",inputProps:{min:go,max:yo,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&: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:()=>a(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:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(T.Visibility,{sx:{fontSize:20}}):e.jsx(T.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?k=>z(k.palette.success.main,.12):"grey.100",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function au({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:a=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:u,onResetLayout:m,onSaveToCurrentView:f,onSaveToAllViews:b,onSelectView:x,onClose:g}){const[B,y]=p.useState(!1),[j,S]=p.useState(n),[k,v]=p.useState(i),[w,s]=p.useState("all"),[_,I]=p.useState(null);p.useEffect(()=>{S(n)},[n]),p.useEffect(()=>{v(i)},[i]);const R=(Y,A)=>{v(V=>({...V,[Y]:A})),u==null||u(Y,A)},q=(Y,A)=>{const V=[...j],[oe]=V.splice(Y,1);V.splice(A,0,oe),S(V),l(V)},Q=()=>{m(),y(!1)},h=j.map(Y=>t.find(A=>A.name===Y)).filter(Y=>Y!==void 0).filter(Y=>{const A=o[Y.name]??!0;return w==="active"?A:w==="hidden"?!A:!0}),$=Object.values(o).filter(Y=>Y).length,W=t.length,F=a.find(Y=>Y.id===c),X=a.filter(Y=>!Y.isDeleted),xe=X.length>1,me=p.useMemo(()=>{if(!F)return!1;const Y=F.snapshot,A=Y.columnVisibility??{},V=JSON.stringify(o)!==JSON.stringify(A),oe=Y.columnOrder??[],J=n??[],ee=JSON.stringify(J)!==JSON.stringify(oe)&&!(J.length===0&&oe.length===0),le=Y.columnWidths??{},ie=JSON.stringify(k)!==JSON.stringify(le);return V||ee||ie},[F,o,n,k]);return e.jsx(Ot.DndProvider,{backend:sn.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:Y=>z(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:e.jsxs(r.Paper,{onClick:Y=>Y.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:Y=>ne(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:[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.jsxs(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(nr,{content:ir.columns,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5},children:[$," of ",W," columns visible • Drag to reorder"]})]}),X.length>0&&x&&e.jsxs(r.Box,{sx:{ml:2},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",color:"text.secondary",mb:.75,display:"block",textTransform:"uppercase",fontWeight:600,letterSpacing:"0.1em"},children:"View:"}),e.jsx(r.Button,{onClick:Y=>I(Y.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(T.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(F==null?void 0:F.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:_,open:!!_,onClose:()=>I(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:Y=>ne(Y,"small")}},children:X.map(Y=>e.jsx(r.MenuItem,{onClick:()=>{x(Y.id),I(null)},selected:Y.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:A=>Le(A),"&:hover":{bgcolor:A=>z(A.palette.primary.main,.2)}}},children:Y.name},Y.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(T.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:w,onChange:(Y,A)=>s(A),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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},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:"grey.50",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:"grey.50",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:"grey.50",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: ${go}px, max: ${yo}px)`,arrow:!0,placement:"top",children:e.jsx(T.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:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:h.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"})})}):h.map((Y,A)=>e.jsx(su,{column:Y,index:A,isVisible:o[Y.name]??!0,width:k[Y.name]||170,onToggleVisibility:d,onWidthChange:R,moveColumn:q},Y.name))})]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!0),disabled:!me,variant:"outlined",startIcon:e.jsx(T.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[f&&e.jsx(r.Button,{onClick:()=>{f(k),g()},disabled:!me,variant:"contained",startIcon:e.jsx(T.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:Y=>ne(Y,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:Y=>ne(Y,"hoverButton")},"&:active":{boxShadow:Y=>ne(Y,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&xe&&e.jsx(r.Button,{onClick:()=>{b(k),g()},disabled:!me||!xe,variant:"contained",startIcon:e.jsx(T.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:Y=>ne(Y,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:Y=>ne(Y,"hoverButton")},"&:active":{boxShadow:Y=>ne(Y,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),B&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:Y=>z(Y.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:Y=>Y.zIndex.tooltip},children:e.jsxs(r.Paper,{onClick:Y=>Y.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:"12px",bgcolor:"background.paper",boxShadow:Y=>ne(Y,"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:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,borderRadius:"4px","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Q,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:"4px",boxShadow:Y=>ne(Y,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:Y=>ne(Y,"hoverButton")},"&:active":{boxShadow:Y=>ne(Y,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function lu({schema:t,grouping:o,onApply:n,onClose:i}){var _;const[a,c]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=p.useState(""),[u,m]=p.useState(null),f=p.useMemo(()=>ia(t),[t]),b=p.useMemo(()=>f.filter(I=>!a.levels.some((R,q)=>R.column===I.name&&q!==u)),[f,a.levels,u]),x=or(),g=a.levels.length<x.grouping.maxLevels&&b.length>0,B=p.useCallback(()=>{!g||!d||(c({...a,levels:[...a.levels,{column:d}],enabled:!0}),l(""))},[g,d,a]),y=p.useCallback(I=>{const R=a.levels.filter((q,Q)=>Q!==I);if(R.length===0){n(null),i();return}c({...a,levels:R,enabled:R.length>0})},[a,n,i]),j=p.useCallback(I=>{m(I),l(a.levels[I].column)},[a.levels]),S=p.useCallback(()=>{if(u===null||!d)return;const I=[...a.levels];I[u]={column:d},c({...a,levels:I}),m(null),l("")},[u,d,a]),k=p.useCallback(()=>{m(null),l("")},[]),v=p.useCallback((I,R)=>{const q=R==="up"?I-1:I+1;if(q<0||q>=a.levels.length)return;const Q=[...a.levels],[te]=Q.splice(I,1);Q.splice(q,0,te),c({...a,levels:Q})},[a]),w=p.useCallback(()=>{n(null),i()},[n,i]),s=p.useCallback(()=>{a.levels.length===0?n(null):n({...a,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[a,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:"12px",bgcolor:"background.paper",outline:"none",boxShadow:I=>ne(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(nr,{content:ir.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:"grey.100",color:"text.primary"}},children:e.jsx(T.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Stack,{spacing:2.5,children:[u===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:d,onChange:I=>l(I.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(I=>e.jsxs(r.MenuItem,{value:I.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:R=>Le(R),"&:hover":{bgcolor:R=>z(R.palette.primary.main,.2)}}},children:[Ke(I.name)," (",I.type.toUpperCase(),")"]},I.name))]})}),e.jsx(r.Button,{onClick:B,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(T.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),a.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"}),f.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."})]}),u!==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 ",u+1]}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:I=>l(I.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&: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:a.levels[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:I=>Le(I)}},children:[a.levels[u].column," (",(_=t.find(I=>I.name===a.levels[u].column))==null?void 0:_.type.toUpperCase(),")"]}),b.filter(I=>I.name!==a.levels[u].column).map(I=>e.jsxs(r.MenuItem,{value:I.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:R=>Le(R)}},children:[Ke(I.name)," (",I.type.toUpperCase(),")"]},I.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:S,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"warning.main",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"warning.dark",boxShadow:I=>ne(I,"pressedButton")}},children:"Save"}),e.jsx(r.Button,{onClick:k,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),a.levels.length>0&&u===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:w,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,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:a.levels.map((I,R)=>{const q=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:"grey.50",borderColor:"grey.300",boxShadow:Q=>ne(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:"0 1px 2px 0 rgba(25, 103, 210, 0.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:q==null?void 0:q.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>v(R,"up"),disabled:R===0,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(T.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>v(R,"down"),disabled:R===a.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(T.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(R),sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100",color:"primary.main"}},children:e.jsx(T.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y(R),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(T.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:"grey.50"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:s,variant:"contained",disabled:a.levels.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:I=>ne(I,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:I=>ne(I,"hoverButton")},"&:active":{boxShadow:I=>ne(I,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const cu={filters:T.FilterList,sorting:T.UnfoldMore,visibility:T.Visibility,order:T.ViewColumn,widths:T.Straighten,grouping:T.Layers};function du({changes:t,onClose:o}){const n=i=>({filters:"primary",sorting:"secondary",visibility:"success",order:"warning",widths:"info",grouping:"error"})[i]||"default";return e.jsxs(r.Dialog,{open:!0,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:i=>ne(i,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["View Changes Summary",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(T.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,children:t.length===0?e.jsx(r.Box,{sx:{textAlign:"center",py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No changes detected"})}):e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"The following modifications have been made to this view:"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:t.map((i,a)=>{const c=cu[i.category];return e.jsxs(r.Paper,{elevation:0,sx:{display:"flex",gap:1.5,p:1.5,border:1,borderColor:"divider",borderRadius:1},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:1,bgcolor:`${n(i.category)}.lighter`,color:`${n(i.category)}.main`,flexShrink:0},children:e.jsx(c,{sx:{fontSize:16}})}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:i.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:i.description})]})]},a)})})]})}),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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:i=>ne(i,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:i=>ne(i,"hoverButton")},"&:active":{boxShadow:i=>ne(i,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})}function uu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:a,onCancel:c}){const[d,l]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:u=>Le(u),borderBottom:u=>`1px solid ${z(u.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:u=>z(u.palette.common.black,.08),color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:a,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:u=>ne(u,"restButton")}},children:"Save as new view"})]})]})}),d&&e.jsx(du,{changes:n,onClose:()=>l(!1)})]})}function pu({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(T.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(T.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(T.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(T.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const fi=[{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 xu(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 mu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function fu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var B,y,j,S;const i=_t(),a=i.palette,[c,d]=p.useState("1h"),[l,u]=p.useState(!1),m=[...t].sort((k,v)=>new Date(v.timestamp).getTime()-new Date(k.timestamp).getTime()),f=fi.find(k=>k.key===c),b=xu(t,f.ms),x=()=>u(!0),g=()=>{n&&(n(mu(t,f.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:z(((B=a.common)==null?void 0:B.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:k=>k.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"16px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${z(((y=a.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${z(((j=a.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(nr,{content:ir.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[m.length," event",m.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:c,onChange:k=>d(k.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:z(a.text.primary,.3)}},children:fi.map(k=>e.jsx(r.MenuItem,{value:k.key,sx:{fontSize:"0.8125rem"},children:k.label},k.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(T.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:x,sx:{textTransform:"none",fontSize:"0.75rem",fontWeight:500,borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:z(a.error.main,.5),"&:hover":{bgcolor:z(a.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(T.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:z(a.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:z(a.text.primary,.14),borderRadius:3}},children:m.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(T.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:m.map(k=>{const v=Od(i,k.feature),{summary:w,detail:s}=wa(k);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(a.text.primary,.18)}},children:[e.jsx(r.Chip,{label:Ia(k.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:z(v,.1),color:v,border:`1px solid ${z(v,.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:w}),s&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:s}),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(T.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:za(k.timestamp)})]}),k.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(T.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:k.user})]})]})]})]},k.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${z(((S=a.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:z(a.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(T.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:[b," audit record",b!==1?"s":""]})," ",f.key==="all"?"from all time":`from the ${f.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:()=>u(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",disableElevation:!0,startIcon:e.jsx(T.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function hu({onSave:t,onClose:o}){const[n,i]=p.useState(""),[a,c]=p.useState(""),[d,l]=p.useState(""),[u,m]=p.useState([]),[f,b]=p.useState(""),[x,g]=p.useState(""),B=s=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s),y=()=>{const s=d.trim();if(s){if(!B(s)){g("Please enter a valid email address");return}if(u.includes(s)){g("This email is already added");return}m([...u,s]),l(""),g("")}},j=s=>{m(u.filter(_=>_!==s))},S=s=>{s.key==="Enter"&&(s.preventDefault(),y())},k=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),a.trim(),u.length>0?u:void 0)},v=s=>{i(s),f&&b("")},w=s=>{l(s),x&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:s=>z(s.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:s=>s.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:s=>s.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:s=>ne(s,"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:"grey.100",color:"text.primary"}},children:e.jsx(T.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:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(T.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:s=>`1px solid ${z(s.palette.primary.main,.3)}`,bgcolor:s=>Le(s),"& .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:s=>v(s.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:"grey.300"},"&: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:a,onChange:s=>c(s.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:"grey.300"},"&: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:d,onChange:s=>w(s.target.value),onKeyPress:S,placeholder:"Enter email address",error:!!x,helperText:x,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(T.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&: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:y,variant:"outlined",startIcon:e.jsx(T.Add,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",px:2,py:1.25,minHeight:40,borderRadius:"4px",flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:"Add"})]}),u.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:u.map(s=>e.jsx(r.Chip,{label:s,onDelete:()=>j(s),deleteIcon:e.jsx(T.Delete,{sx:{fontSize:16}}),sx:{bgcolor:_=>Le(_),color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},s))}),e.jsx(r.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"})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:k,variant:"contained",startIcon:e.jsx(T.Share,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:s=>ne(s,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:s=>ne(s,"hoverButton")},"&:active":{boxShadow:s=>ne(s,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function gu({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(T.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(T.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 yu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:a}){const[c,d]=p.useState(null),l=u=>new Date(u).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:a,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:u=>u.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"common.white",outline:"none",boxShadow:u=>ne(u,"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:a,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(T.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:u=>z(u.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(T.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(u=>e.jsxs(r.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"common.white",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:m=>ne(m,"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:u.name}),u.description&&e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:u.description})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[e.jsx(r.Chip,{label:`Created ${l(u.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 ${u.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(u.id,u.name),variant:"outlined",size:"small",startIcon:e.jsx(T.Delete,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:"4px","&:hover":{borderColor:"error.main",bgcolor:"rgba(217, 48, 37, 0.04)"}},children:"Delete"})})]},u.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:a,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:u=>ne(u,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:u=>ne(u,"hoverButton")},"&:active":{boxShadow:u=>ne(u,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const Zi={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},bu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],vu=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function Su(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const a=vu.some(l=>l.test(i.name));let c=!1;const d=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);d.length>0&&(c=d.filter(u=>bu.some(m=>m.test(u))).length/d.length>.6),(a||c)&&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)),a=o.map(d=>{const l=n.map(m=>String(m[d]??"")).filter(m=>m.length>0);if(l.length===0)return 5;const u=l.reduce((m,f)=>m+f.length,0);return Math.ceil(u/l.length)+1}).reduce((d,l)=>d+l,0)+1;return o.reduce((d,l)=>d+l.length+1,0)+a*t.length}function ju(t,o){const n=fn(t,o);return Math.ceil(n*3.5)}function Cu(t,o){const n=fn(t,o);return Math.ceil(n*.7)}function wu(t,o,n){switch(t){case"csv":return fn(o,n);case"excel":return Cu(o,n);case"json":return ju(o,n)}}function hi(t,o){return Math.ceil(t/o)}function ku(t,o,n,i,a=Zi){const c=[],d=wu(t,o,n),l=o.length;if(l>a.maxRowsHard){const f=hi(l,a.maxRows);c.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${a.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${f} smaller exports of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:a.maxRowsHard})}else if(l>a.maxRows){const f=hi(l,a.maxRows);c.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 ${f} smaller export${f>1?"s":""} of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:a.maxRows})}if(d>a.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${eo(d)} exceeds the ${eo(a.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:a.maxFileSizeHardBytes}):d>a.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${eo(d)}`,detail:`This exceeds the recommended ${eo(a.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:a.maxFileSizeBytes}),t!=="excel"){const f=Su(i.filter(b=>n.includes(b.name)),o);if(f.length>0){const b=f.length>a.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${f.length>1?"s":""} detected: ${f.map(x=>`"${x.replace(/_/g," ")}"`).join(", ")}`,detail:b?`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:a.maxImageColumns})}}const u=c.some(f=>f.severity==="error"),m=c.some(f=>f.severity==="warning");return{violations:c,hasBlockingViolation:u,hasWarning:m,estimatedBytes:d}}function eo(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Tu({violation:t}){const n=_t().palette,i=t.severity==="error",a=i?n.error.main:n.warning.main,c=z(i?n.error.main:n.warning.main,.06),d=i?z(n.error.main,.25):z(n.warning.main,.3),l=i?T.ErrorOutline:T.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:c,border:"1px solid",borderColor:d},children:[e.jsx(l,{sx:{fontSize:17,color:a,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(T.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 Iu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:a,schema:c,sampleRows:d=[],allRows:l=[],processedRows:u=[],onExport:m,onClose:f}){var $,W,F;const x=_t().palette,g=or(),[B,y]=p.useState(g.export.allowedFormats[0]||"csv"),[j,S]=p.useState("visible"),[k,v]=p.useState("visible"),w=j==="visible"?o:t,s=k==="visible"?i:a,_=p.useMemo(()=>j==="visible"?u.length>0?u:new Array(o):l.length>0?l:new Array(t),[j,o,t,u,l]),I=p.useMemo(()=>k==="all"?c.map(X=>X.name):c.map(X=>X.name).slice(0,i),[k,c,i]),R=p.useMemo(()=>ku(B,_,I,c,Zi),[B,_,I,c]),q=()=>{R.hasBlockingViolation||(m({format:B,scope:j,columnScope:k}),f())},Q={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},te={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 e.jsx(r.Box,{onClick:f,sx:{position:"fixed",inset:0,bgcolor:z((($=x.common)==null?void 0:$.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,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:"14px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${z(((W=x.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${z(((F=x.common)==null?void 0:F.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(nr,{content:ir.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(T.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,xe)=>e.jsx(Tu,{violation:X},xe))}),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:B,onChange:X=>y(X.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:h}),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:{...te,mb:.5}}),g.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:h}),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:{...te,mb:.5}}),g.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:h}),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:te})]})]}),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=>S(X.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),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:{...te,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:h}),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:te})]})]}),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:k,onChange:X=>v(X.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),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:{...te,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:h}),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 ",a," columns (including hidden)"]})]}),sx:te})]})]}),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[B]},{label:"Rows to export",value:w.toLocaleString()},{label:"Columns to export",value:String(s)},{label:"Estimated file size",value:eo(R.estimatedBytes),highlight:R.hasBlockingViolation?"error.main":R.hasWarning?"warning.main":void 0}].map(({label:X,value:xe,highlight:me})=>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:me??"text.primary"},children:xe})]},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(T.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:f,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:q,disabled:R.hasBlockingViolation,variant:"contained",disableElevation:!0,startIcon:e.jsx(T.Download,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"8px"},children:["Download ",Q[B]]})]})]})})}function zu({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(T.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(T.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 Bu({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){p.useEffect(()=>{if(n){const l=setTimeout(()=>{o()},i);return()=>clearTimeout(l)}},[n,i,o]);const c=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(T.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(T.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(T.InfoOutlined,{sx:{fontSize:20}})}}})(),d=La(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:c.severity,icon:c.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${c.severity}.main`},children:e.jsx(T.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${c.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:d}),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 Eu extends p.Component{constructor(n){super(n);Ur(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){tr.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:a=>z(a.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(T.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:a=>z(a.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(T.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Du({feature:t}){const[o,n]=p.useState(!0);return p.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(T.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(T.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Jr({children:t,feature:o,onError:n}){return e.jsx(Eu,{context:o,onError:(i,a)=>{n&&n(i)},fallback:e.jsx(Du,{feature:o}),children:t})}const Ou=[{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"}],Au=[{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 Kr({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 _u({open:t,onClose:o,config:n,onApply:i}){const[a,c]=p.useState(0),[d,l]=p.useState(n),u=()=>l(n),m=()=>l(qe),f=()=>{i(d),o()},b={sort:j=>l(S=>({...S,sort:{...S.sort,...j}})),filter:j=>l(S=>({...S,filter:{...S.filter,...j}})),columns:j=>l(S=>({...S,columns:{...S.columns,...j}})),grouping:j=>l(S=>({...S,grouping:{...S.grouping,...j}})),export:j=>l(S=>({...S,export:{...S.export,...j}}))},x=j=>{const S=d.filter.allowedOperators,k=S.includes(j)?S.filter(v=>v!==j):[...S,j];k.length!==0&&b.filter({allowedOperators:k})},g=j=>{const S=d.export.allowedFormats,k=S.includes(j)?S.filter(v=>v!==j):[...S,j];k.length!==0&&b.export({allowedFormats:k})},B=[{label:"Sort",icon:e.jsx(T.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(T.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(T.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(T.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(T.Download,{sx:{fontSize:17}})}],y=j=>JSON.stringify(d[j])===JSON.stringify(qe[j]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.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(T.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:a,onChange:(j,S)=>c(S),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:B.map((j,S)=>e.jsx(r.Tab,{label:j.label,icon:j.icon,iconPosition:"start"},S))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Kr,{active:a===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"}),!y("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:d.sort.maxLevels,onChange:(j,S)=>b.sort({maxLevels:S}),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(Kr,{active:a===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"}),!y("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:d.filter.maxConditions,onChange:(j,S)=>b.filter({maxConditions:S}),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:Ou.filter(S=>S.group===j).map(S=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(S.value),onChange:()=>x(S.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:S.label}),sx:{mr:1.5}},S.value))})]},j))]})]}),e.jsxs(Kr,{active:a===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"}),!y("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:d.columns.maxVisible,onChange:(j,S)=>b.columns({maxVisible:S}),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:d.columns.minColumnWidth,onChange:(j,S)=>b.columns({minColumnWidth:S}),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:d.columns.maxColumnWidth,onChange:(j,S)=>b.columns({maxColumnWidth:S}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]})]})]})]}),e.jsxs(Kr,{active:a===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"}),!y("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:()=>b.grouping({maxLevels:j}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===j?"primary.main":"divider",bgcolor:d.grouping.maxLevels===j?S=>z(S.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:S=>z(S.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:d.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:d.grouping.allowNested,onChange:j=>b.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:d.grouping.allowCollapse,onChange:j=>b.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(Kr,{active:a===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"}),!y("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:Au.map(j=>e.jsxs(r.Box,{onClick:()=>g(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:d.export.allowedFormats.includes(j.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(j.value)?S=>z(S.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(j.value),onChange:()=>g(j.value),onClick:S=>S.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(T.RestartAlt,{sx:{fontSize:18}}),onClick:m,size:"small",sx:{textTransform:"none",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:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:f,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Mu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],$u={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 bo(t,o,n,i,a=new Date){const[c,d]=o.split(":").map(Number),l=new Date(a);if(l.setSeconds(0,0),l.setHours(c,d,0,0),t==="daily")return l<=a&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const u=n??1,m=l.getDay();let f=u-m;return f<0&&(f+=7),f===0&&l<=a&&(f=7),l.setDate(l.getDate()+f),l.toISOString()}if(t==="monthly"){const u=Math.min(i??1,28);return l.setDate(u),l<=a&&(l.setMonth(l.getMonth()+1),l.setDate(u)),l.toISOString()}return l.toISOString()}function Ru(t){const o=Qi(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${Mu[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${$u[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Qi(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Wu(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),a=Math.floor(n%86400/3600),c=Math.floor(n%3600/60);return i>0?`in ${i}d ${a}h`:a>0?`in ${a}h ${c}m`:c>0?`in ${c}m`:"in less than a minute"}function Pu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),a=Qi(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${a}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${a}`}function es(t){return`urm_schedules_${t}`}function ts(t){try{const o=localStorage.getItem(es(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 rs(t,o){try{localStorage.setItem(es(t),JSON.stringify(o))}catch{}}const Nu=[{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"}],Lu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,os={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},er={"& .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 Fu({initial:t=os,isEditing:o=!1,onSave:n,onBack:i}){const[a,c]=p.useState(t),[d,l]=p.useState(!1),[u,m]=p.useState(!1),f=(g,B)=>c(y=>({...y,[g]:B})),b=a.email.trim().length>0&&!Lu.test(a.email.trim()),x=a.name.trim().length>0&&/^\d{2}:\d{2}$/.test(a.time)&&(a.frequency!=="monthly"||a.dayOfMonth>=1&&a.dayOfMonth<=28)&&!b;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:g=>z(g.palette.text.primary,.06)}},children:e.jsx(T.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:a.name,onChange:g=>{f("name",g.target.value),d&&g.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!a.name.trim(),helperText:d&&!a.name.trim()?"Schedule name is required":`${a.name.length}/50`,sx:er}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:er,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:a.frequency,label:"Frequency",onChange:g=>f("frequency",g.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"})]})]}),a.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:er,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:a.dayOfWeek,label:"Day of week",onChange:g=>f("dayOfWeek",Number(g.target.value)),children:Nu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),a.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:a.dayOfMonth,onChange:g=>f("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:a.dayOfMonth<1||a.dayOfMonth>28,helperText:a.dayOfMonth<1||a.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:er}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:a.time,onChange:g=>f("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:er}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:er,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:a.format,label:"Export format",onChange:g=>f("format",g.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:a.scope,onChange:g=>f("scope",g.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:a.email,onChange:g=>f("email",g.target.value),onBlur:()=>m(!0),placeholder:"user@company.com",error:u&&b,helperText:u&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(T.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:er}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(T.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:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>z(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>x&&n(a),disabled:!x,size:"small",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Vu({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:i=>{var a;return`0 8px 32px ${z(((a=i.palette.common)==null?void 0:a.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(T.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:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:"Delete"})]})]})}function Hu({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:a,onDelete:c}){const d=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:d?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:d?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:d?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:d?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:d?l=>z(l.palette.success.main,.1):l=>z(l.palette.text.primary,.06),color:d?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:Ru(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(T.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:[d&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",Wu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Pu(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:()=>a(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>z(l.palette.primary.main,.08)}},children:e.jsx(T.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:d?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:d?"warning.main":"success.main","&:hover":{bgcolor:d?l=>z(l.palette.warning.main,.08):l=>z(l.palette.success.main,.08)}},children:d?e.jsx(T.Pause,{sx:{fontSize:15}}):e.jsx(T.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(T.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>c(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>z(l.palette.error.main,.08)}},children:e.jsx(T.Delete,{sx:{fontSize:15}})})})]})]})]})}function Uu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:a}){const[c,d]=p.useState([]),[l,u]=p.useState({type:"list"}),[m,f]=p.useState(0),[b,x]=p.useState(null);p.useEffect(()=>{t&&(d(ts(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const I=setInterval(()=>f(R=>R+1),3e4);return()=>clearInterval(I)},[t]);const g=p.useCallback(I=>{d(I),rs(n,I)},[n]),B=I=>{const R=bo(I.frequency,I.time,I.dayOfWeek,I.dayOfMonth),q={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};g([...c,q]),u({type:"list"})},y=I=>{if(l.type!=="edit")return;const R=l.schedule,q=bo(I.frequency,I.time,I.dayOfWeek,I.dayOfMonth);g(c.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:q}:Q)),u({type:"list"})},j=I=>{g(c.map(R=>{if(R.id!==I)return R;const q=R.isActive?R.nextRunAt:bo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:q}}))},S=I=>{a(I);const R=new Date().toISOString();g(c.map(q=>q.id===I.id?{...q,lastRunAt:R,runCount:q.runCount+1}:q))},k=I=>{const R=c.find(q=>q.id===I)??null;x(R)},v=()=>{b&&(g(c.filter(I=>I.id!==b.id)),x(null))},w=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??""}),s=l.type!=="list",_=c.filter(I=>I.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:s,PaperProps:{sx:{borderRadius:"12px",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(T.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(nr,{content:ir.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(T.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[s&&e.jsx(Fu,{initial:l.type==="edit"?w(l.schedule):os,isEditing:l.type==="edit",onSave:l.type==="edit"?y:B,onBack:()=>u({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:c.length===0?"No schedules yet":`${_} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(T.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",disableElevation:!0,onClick:()=>u({type:"create"}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),c.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(T.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:c.map(I=>e.jsx(Hu,{schedule:I,tick:m,onToggle:j,onRunNow:S,onEdit:R=>u({type:"edit",schedule:R}),onDelete:k},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(T.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:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:I=>z(I.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Vu,{scheduleName:b.name,onConfirm:v,onCancel:()=>x(null)})]})}const Yu=6e4;function Gu({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:f}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:f});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:f}});const x=p.useCallback(g=>{var I,R;const{reportName:B,uploadedData:y,processedData:j,schema:S,activeView:k,columnVisibility:v,columnOrder:w,filters:s,sortStack:_}=b.current;try{const q=g.scope==="all"?y:j,Q=vo(q,S,s,_,k,v,w),te=`${g.name}_scheduled`;switch(g.format){case"csv":So(Q,te,{scope:g.scope});break;case"excel":jo(Q,te,{scope:g.scope});break;case"json":Co(Q,te,{scope:g.scope});break}if(g.email){const h=encodeURIComponent(`Scheduled Report: ${g.name}`),$=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
|
|
90
90
|
|
|
91
|
-
Report: ${
|
|
91
|
+
Report: ${B}
|
|
92
92
|
Format: ${g.format.toUpperCase()}
|
|
93
93
|
Generated: ${new Date().toLocaleString()}
|
|
94
94
|
|
|
95
|
-
The file has been downloaded to your device.`);window.open(`mailto:${g.email}?subject=${h}&body=${R}`,"_blank")}($=(B=b.current).onFired)==null||$.call(B,g)}catch(G){qt.error("urm:scheduler",`Export failed for schedule: ${g.name}`,G)}},[]);u.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:y}=b.current;if(!y)return;const C=Ji(y),v=new Date;let k=!1;const S=C.map(T=>{if(!T.isActive)return T;if(new Date(T.nextRunAt)<=v){m(T);const M=uo(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth,v);return k=!0,{...T,lastRunAt:v.toISOString(),nextRunAt:M,runCount:T.runCount+1}}return T});k&&Ki(y,S)};g();const z=setInterval(g,$u);return()=>clearInterval(z)},[t,m])}function Zi({reportEngine:t}){var Rr,jt,cr,Ht,Ut;const{activeReport:o,paginatedData:n,processedData:i,displayData:a,tableMetrics:c,tableEngine:d,activeView:l,isDirty:p,currentTableState:x,viewChanges:f,showFilterPanel:b,setShowFilterPanel:m,filterFocusColumn:g,handleAddFilter:z,handleUpdateFilter:y,handleRemoveFilter:C,handleClearAllFilters:v,handleReplaceFilters:k,handleOpenFilterForColumn:S,handleCloseFilterPanel:T,handleClearFiltersForColumn:s,showSortPanel:M,setShowSortPanel:B,handleSort:$,handleUpdateSortStack:G,handleSortAscending:Z,handleSortDescending:ee,showManageViews:h,setShowManageViews:R,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:K,setShowEditViewModal:de,showDeleteConfirmation:ue,setShowDeleteConfirmation:te,editingView:A,deletingView:V,handleSelectView:q,handleCreateView:re,handleUpdateCurrentView:Q,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:oe,handleSaveAsNewView:N,handleRevertChanges:ne,handleToggleDefault:ce,handleToggleFavorite:se,handleSoftDelete:fe,handleRestoreView:J,handlePermanentDelete:Me,handleEditView:Ne,handleSaveEditView:et,handleConfirmDelete:Qt,handlePromoteToGlobal:gr,showManageColumns:$t,setShowManageColumns:ot,handleUpdateColumnVisibility:Le,handleUpdateColumnOrder:Ee,handleUpdateColumnWidth:mt,handleResetColumnLayout:nt,showGroupPanel:tt,setShowGroupPanel:Ge,handleGroup:ft,handleToggleGroupCollapse:er,searchQuery:qe,searchHistory:Je,handleSearchChange:$e,handleAddToSearchHistory:tr,handleToggleSearchFavourite:ht,handleDeleteSearchHistory:zt,selectedRowIds:rr,handleToggleRowSelection:it,handleToggleAllRows:yr,handleRangeSelection:br,handleClearSelection:vr,handleUpdateSelectionAfterDelete:Rt,currentPage:Sr,pageSize:jr,paginationEngine:Ke,handlePageChange:be,handlePageSizeChange:Cr,isExporting:or,showExportModal:rt,setShowExportModal:L,showDirtyExportWarning:Fe,handleExport:ve,handleExportWithConfig:Re,handleExportSelected:wr,handleExportAnyway:Wt,handleSaveAndExport:gt,handleCancelExport:Pt,showAuditHistory:Nt,setShowAuditHistory:Et,showCreatePreset:kr,setShowCreatePreset:Lt,showManagePresets:Oe,setShowManagePresets:X,generatedPreset:yt,activePreset:he,handleOpenManagePresets:Se,handleCreatePreset:Xe,handleCopyPresetLink:Tr,handleOpenPreset:bt,handleClearActivePreset:We,handleOpenPresetById:nr,handleCopyPresetLinkById:Ir,handleDeletePresetById:ir,isViewerRole:vt,userRole:zr,featureLimitWarning:Bt,setFeatureLimitWarning:Ft,reportError:St,setReportError:sr,handleError:Be,updateReport:Pe,showSnack:Vt,favoriteRowIndices:st,resolvedFavoritesSet:Er,showFavoritesOnly:Br,handleToggleRowFavorite:Dr,handleBulkSetFavorites:Or,handleToggleFavoritesFilter:Ar}=t,[Mr,ar]=u.useState(!1);Ru({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:l,columnVisibility:(o==null?void 0:o.columnVisibility)||((Rr=l==null?void 0:l.snapshot)==null?void 0:Rr.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((jt=l==null?void 0:l.snapshot)==null?void 0:jt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:I=>{Vt(`Scheduled export "${I.name}" completed`,"success")}});const _r=u.useCallback((I,F)=>{if(!(o!=null&&o.uploadedData))return;const ie=[...o.uploadedData];ie[I]=F,Pe(o.id,{uploadedData:ie})},[o,Pe]),lr=u.useCallback(I=>{if(!(o!=null&&o.uploadedData))return;const F=o.uploadedData.indexOf(I);if(F===-1)return;const ie=o.uploadedData.filter((ae,lt)=>lt!==F),we=(o.favoriteRowIndices||[]).filter(ae=>ae!==F).map(ae=>ae>F?ae-1:ae);Pe(o.id,{uploadedData:ie,favoriteRowIndices:we}),Rt(I)},[o,Pe,Rt]),$r=u.useCallback((I,F)=>{if(!(o!=null&&o.uploadedData))return;const ie=o.uploadedData.indexOf(F),we=ie!==-1?ie+1:I+1,ae=[...o.uploadedData];ae.splice(we,0,{...F});const Mo=(o.favoriteRowIndices??[]).map(Wr=>Wr>=we?Wr+1:Wr);Pe(o.id,{uploadedData:ae,favoriteRowIndices:Mo})},[o,Pe]),Dt=Kt(),{handleDevConfigChange:_e}=bo(),[at,Ot]=u.useState(!1);return u.useEffect(()=>{const I=F=>{F.ctrlKey&&F.shiftKey&&F.key==="D"&&(F.preventDefault(),Ot(!0))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]),!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:[!vt&&p&&l&&e.jsx(tu,{viewName:l.name,isDefaultView:l.isDefault,changes:f,onSaveToCurrentView:l.isDefault?void 0:Q,onSaveAsNewView:N,onCancel:ne}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[Bt&&e.jsx(yu,{warning:Bt,onDismiss:()=>Ft(null)}),St&&e.jsx(bu,{error:St,onDismiss:()=>sr(null)}),Fe&&e.jsx(ru,{onExportAnyway:Wt,onSaveAndExport:gt,onCancel:Pt}),e.jsx(Hd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:p,isExporting:or,columnVisibility:o.columnVisibility||(l==null?void 0:l.snapshot.columnVisibility),columnOrder:o.columnOrder||(l==null?void 0:l.snapshot.columnOrder),columnWidths:o.columnWidths||(l==null?void 0:l.snapshot.columnWidths),grouping:o.grouping,onSort:$,onSortAscending:Z,onSortDescending:ee,onOpenFilters:()=>m(!0),onOpenSort:()=>B(!0),onOpenFilterForColumn:S,onSelectView:q,onCreateView:()=>H(!0),onManageViews:()=>R(!0),onUpdateCurrentView:Q,onSaveAsNewView:N,onToggleDefault:ce,onToggleFavorite:se,onRestoreView:J,onPermanentDelete:Me,onExport:ve,onOpenColumns:()=>ot(!0),onUpdateColumnWidth:mt,onUpdateColumnOrder:Ee,onUpdateColumnVisibility:Le,onClearFiltersForColumn:s,onResetLayout:nt,onOpenGroup:()=>Ge(!0),onGroupByColumn:I=>{ft({enabled:!0,column:I,showCounts:!0})},onToggleGroupCollapse:er,onOpenAuditHistory:()=>Et(!0),onOpenScheduledReports:()=>ar(!0),searchQuery:qe,searchHistory:Je,onAddToSearchHistory:tr,onToggleSearchFavourite:ht,onDeleteSearchHistory:zt,selectedRowIds:rr,onSearchChange:$e,onToggleRowSelection:it,onToggleAllRows:yr,onRangeSelection:br,onClearSelection:vr,onExportSelected:wr,currentPage:(Ke==null?void 0:Ke.currentPage)||Sr,pageSize:(Ke==null?void 0:Ke.pageSize)||jr,onPageChange:be,onPageSizeChange:Cr,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:vt,userRole:zr,reportName:o.name,onEditRow:_r,onDeleteRow:lr,onDuplicateRow:$r,favoriteRowIndices:st,resolvedFavoritesSet:Er,showFavoritesOnly:Br,onToggleRowFavorite:Dr,onBulkSetFavorites:Or,onToggleFavoritesFilter:Ar,showDevPanel:Dt.display.showDevPanel,onOpenDevConfig:()=>Ot(!0)})]}),b&&e.jsx(Fr,{feature:"Filters",onError:I=>{const F=wt("ui","filters",I);Be(F)},children:e.jsx(Ud,{schema:o.schema,filters:o.filters??[],onAddFilter:z,onUpdateFilter:y,onRemoveFilter:C,onClearAll:v,onReplaceFilters:k,onClose:T,focusColumn:g})}),M&&e.jsx(Fr,{feature:"Sorting",onError:I=>{const F=wt("ui","sorting",I);Be(F)},children:e.jsx(Gd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:G,onClose:()=>B(!1)})}),h&&e.jsx(Fr,{feature:"Views",onError:I=>{const F=wt("ui","views",I);Be(F)},children:e.jsx(qd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:q,onCreateView:()=>{R(!1),H(!0)},onEditView:Ne,onDeleteView:fe,onRestoreView:J,onPermanentDelete:Me,onPromoteToGlobal:gr,isAdmin:((cr=Dt.views)==null?void 0:cr.isAdmin)??!1,onClose:()=>R(!1)})}),W&&x&&(()=>{var ie;const I=(o.views??[]).filter(we=>!we.isDeleted).length,F=((ie=Dt.views)==null?void 0:ie.maxViews)??10;return e.jsx(ai,{currentSnapshot:x,onSave:re,onClose:()=>H(!1),atViewLimit:I>=F,maxViews:F})})(),K&&A&&e.jsx(ai,{currentSnapshot:A.snapshot,onSave:et,onClose:()=>{de(!1)},isEditMode:!0,initialName:A.name,initialDescription:A.description,initialIsDefault:A.isDefault}),ue&&V&&e.jsx(Jd,{viewName:V.name,onConfirm:Qt,onCancel:()=>{te(!1)}}),$t&&l&&e.jsx(Xd,{schema:o.schema,columnVisibility:o.columnVisibility||l.snapshot.columnVisibility,columnOrder:o.columnOrder||l.snapshot.columnOrder,columnWidths:o.columnWidths||l.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:Le,onUpdateColumnOrder:Ee,onUpdateColumnWidth:mt,onResetLayout:nt,onSelectView:I=>{q(I)},onSaveToCurrentView:I=>{le(I),ot(!1)},onSaveToAllViews:I=>{oe(I),ot(!1)},onClose:()=>ot(!1)}),tt&&e.jsx(Fr,{feature:"Grouping",onError:I=>{const F=wt("ui","grouping",I);Be(F)},children:e.jsx(Zd,{schema:o.schema,grouping:o.grouping||null,onApply:ft,onClose:()=>Ge(!1)})}),Nt&&e.jsx(iu,{auditHistory:o.auditHistory||[],onClose:()=>Et(!1)}),kr&&e.jsx(su,{onSave:Xe,onClose:()=>Lt(!1)}),Oe&&e.jsx(lu,{presets:o.presets||[],reportId:o.id,onOpenPreset:nr,onCopyLink:Ir,onDeletePreset:ir,onClose:()=>X(!1)}),he&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(au,{presetName:he.name,onClear:We})}),rt&&e.jsx(Fr,{feature:"Export",onError:I=>{const F=wt("ui","export",I);Be(F)},children:e.jsx(gu,{totalRows:(c==null?void 0:c.totalRows)||((Ht=o.uploadedData)==null?void 0:Ht.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Ut=d==null?void 0:d.columnEngine)==null?void 0:Ut.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(c==null?void 0:c.isGrouped)||!1,schema:o.schema,allRows:o.uploadedData||[],processedRows:i||[],onExport:Re,onClose:()=>{L(!1)}})}),o&&e.jsx(_u,{open:Mr,onClose:()=>ar(!1),reportId:o.id,reportName:o.name,onRunNow:I=>{const F=I.scope==="all"?o.uploadedData||[]:i||[],ie=po(F,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);I.format==="csv"&&xo(ie,I.name),I.format==="excel"&&mo(ie,I.name),I.format==="json"&&fo(ie,I.name),Vt(`"${I.name}" exported successfully`,"success")}}),e.jsx(wu,{open:at,onClose:()=>Ot(!1),config:Dt,onApply:_e})]})}function Qi({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(a,c)=>{c!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(r.Alert,{severity:n,variant:"filled",sx:{width:"100%",boxShadow:3},children:o})})}function es({hasExternalData:t=!1}){const o=bo(),{reports:n,activeReportId:i,activeReport:a,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:p,setIsModalOpen:x,setActiveReportId:f,createReport:b,handleFileUpload:m,handleUploadError:g,handleRetry:z,handleConfirm:y,snack:C,handleSnackClose:v}=o,k=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(tl,{onCreateReport:()=>x(!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:k?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(Hi,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):a?e.jsx(e.Fragment,{children:a.schemaLocked&&a.schema&&a.uploadedData&&a.views?e.jsx(Zi,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&a.schema&&a.uploadedData?e.jsx(pd,{schema:a.schema,onConfirm:y,hasConflicts:l}):a.uploadError?e.jsx(xd,{error:a.uploadError,onRetry:z}):e.jsx(ud,{onFileUpload:m,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(dd,{isOpen:p,onClose:()=>x(!1),onCreate:b}),e.jsx(Qi,{open:C.open,message:C.message,severity:C.severity,onClose:v})]})}function Wu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:a}={}){return e.jsx(en,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:a,children:e.jsx(es,{hasExternalData:!!(t||o)})})}function ts(){const t=bo(),{snack:o,handleSnackClose:n}=t;return e.jsxs(r.Box,{sx:{minHeight:"100vh"},children:[e.jsx(r.Box,{component:"main",children:t.activeReport?e.jsx(Zi,{reportEngine:t}):e.jsx(Hi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(Qi,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Pu({data:t,autoLoad:o=!0,config:n}){return e.jsx(en,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(ts,{})})}exports.URMBuilder=Wu;exports.URMBuilderRaw=es;exports.URMProvider=en;exports.URMViewer=Pu;exports.URMViewerRaw=ts;exports.useURMContext=bo;
|
|
95
|
+
The file has been downloaded to your device.`);window.open(`mailto:${g.email}?subject=${h}&body=${$}`,"_blank")}(R=(I=b.current).onFired)==null||R.call(I,g)}catch(q){tr.error("urm:scheduler",`Export failed for schedule: ${g.name}`,q)}},[]);p.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:y}=b.current;if(!y)return;const j=ts(y),S=new Date;let k=!1;const v=j.map(w=>{if(!w.isActive)return w;if(new Date(w.nextRunAt)<=S){x(w);const _=bo(w.frequency,w.time,w.dayOfWeek,w.dayOfMonth,S);return k=!0,{...w,lastRunAt:S.toISOString(),nextRunAt:_,runCount:w.runCount+1}}return w});k&&rs(y,v)};g();const B=setInterval(g,Yu);return()=>clearInterval(B)},[t,x])}function ns({reportEngine:t}){var Ae,dt,Xt,Fr,zt;const{activeReport:o,paginatedData:n,processedData:i,displayData:a,tableMetrics:c,tableEngine:d,activeView:l,isDirty:u,currentTableState:m,viewChanges:f,showFilterPanel:b,setShowFilterPanel:x,filterFocusColumn:g,handleAddFilter:B,handleUpdateFilter:y,handleRemoveFilter:j,handleClearAllFilters:S,handleReplaceFilters:k,handleOpenFilterForColumn:v,handleCloseFilterPanel:w,handleClearFiltersForColumn:s,showSortPanel:_,setShowSortPanel:I,handleSort:R,handleUpdateSortStack:q,handleSortAscending:Q,handleSortDescending:te,showManageViews:h,setShowManageViews:$,showCreateViewModal:W,setShowCreateViewModal:F,showEditViewModal:X,setShowEditViewModal:xe,showDeleteConfirmation:me,setShowDeleteConfirmation:Y,editingView:A,deletingView:V,handleSelectView:oe,handleCreateView:J,handleUpdateCurrentView:ee,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:ie,handleSaveAsNewView:N,handleRevertChanges:se,handleToggleDefault:ce,handleToggleFavorite:ae,handleSoftDelete:ge,handleRestoreView:K,handlePermanentDelete:Me,handleEditView:Ue,handleSaveEditView:nt,handleConfirmDelete:sr,handlePromoteToGlobal:Tr,showManageColumns:Ft,setShowManageColumns:ut,handleUpdateColumnVisibility:Fe,handleUpdateColumnOrder:Be,handleUpdateColumnWidth:Mt,handleResetColumnLayout:St,showGroupPanel:Ze,setShowGroupPanel:He,handleGroup:Qe,handleToggleGroupCollapse:ar,searchQuery:et,searchHistory:it,handleSearchChange:We,handleAddToSearchHistory:lr,handleToggleSearchFavourite:Ir,handleDeleteSearchHistory:Vt,selectedRowIds:pt,handleToggleRowSelection:jt,handleToggleAllRows:cr,handleRangeSelection:Ct,handleClearSelection:io,handleUpdateSelectionAfterDelete:dr,currentPage:zr,pageSize:wt,paginationEngine:st,handlePageChange:Br,handlePageSizeChange:Ht,isExporting:je,showExportModal:Er,setShowExportModal:ur,showDirtyExportWarning:at,handleExport:L,handleExportWithConfig:Ye,handleExportSelected:Ce,handleExportAnyway:Ve,handleSaveAndExport:Dr,handleCancelExport:Ut,showAuditHistory:kt,setShowAuditHistory:$t,showCreatePreset:Yt,setShowCreatePreset:Gt,showManagePresets:Or,setShowManagePresets:qt,generatedPreset:$e,activePreset:Z,handleOpenManagePresets:Tt,handleCreatePreset:we,handleCopyPresetLink:ke,handleOpenPreset:lt,handleClearActivePreset:pr,handleOpenPresetById:xt,handleCopyPresetLinkById:Ge,handleDeletePresetById:xr,isViewerRole:mr,userRole:fr,featureLimitWarning:It,setFeatureLimitWarning:Ar,reportError:Rt,setReportError:Jt,handleError:tt,updateReport:ct,showSnack:Pe,favoriteRowIndices:mt,resolvedFavoritesSet:hr,showFavoritesOnly:ft,handleToggleRowFavorite:_r,handleBulkSetFavorites:Mr,handleToggleFavoritesFilter:$r}=t,[Rr,gr]=p.useState(!1);Gu({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:l,columnVisibility:(o==null?void 0:o.columnVisibility)||((Ae=l==null?void 0:l.snapshot)==null?void 0:Ae.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((dt=l==null?void 0:l.snapshot)==null?void 0:dt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:ue=>{Pe(`Scheduled export "${ue.name}" completed`,"success")}});const Wr=p.useCallback((ue,fe)=>{if(!(o!=null&&o.uploadedData))return;const Re=[...o.uploadedData];Re[ue]=fe,ct(o.id,{uploadedData:Re})},[o,ct]),Pr=p.useCallback(ue=>{if(!(o!=null&&o.uploadedData))return;const fe=o.uploadedData.indexOf(ue);if(fe===-1)return;const Re=o.uploadedData.filter((U,pe)=>pe!==fe),E=(o.favoriteRowIndices||[]).filter(U=>U!==fe).map(U=>U>fe?U-1:U);ct(o.id,{uploadedData:Re,favoriteRowIndices:E}),dr(ue)},[o,ct,dr]),Nr=p.useCallback((ue,fe)=>{if(!(o!=null&&o.uploadedData))return;const Re=o.uploadedData.indexOf(fe),E=Re!==-1?Re+1:ue+1,U=[...o.uploadedData];U.splice(E,0,{...fe});const Ne=(o.favoriteRowIndices??[]).map(de=>de>=E?de+1:de);ct(o.id,{uploadedData:U,favoriteRowIndices:Ne})},[o,ct]),Wt=or(),{handleDevConfigChange:yr}=zo(),[Lr,Kt]=p.useState(!1);return p.useEffect(()=>{const ue=fe=>{fe.ctrlKey&&fe.shiftKey&&fe.key==="D"&&(fe.preventDefault(),Kt(!0))};return document.addEventListener("keydown",ue),()=>document.removeEventListener("keydown",ue)},[]),!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:[!mr&&u&&l&&e.jsx(uu,{viewName:l.name,isDefaultView:l.isDefault,changes:f,onSaveToCurrentView:l.isDefault?void 0:ee,onSaveAsNewView:N,onCancel:se}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[It&&e.jsx(zu,{warning:It,onDismiss:()=>Ar(null)}),Rt&&e.jsx(Bu,{error:Rt,onDismiss:()=>Jt(null)}),at&&e.jsx(pu,{onExportAnyway:Ve,onSaveAndExport:Dr,onCancel:Ut}),e.jsx(eu,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:u,isExporting:je,columnVisibility:o.columnVisibility||(l==null?void 0:l.snapshot.columnVisibility),columnOrder:o.columnOrder||(l==null?void 0:l.snapshot.columnOrder),columnWidths:o.columnWidths||(l==null?void 0:l.snapshot.columnWidths),grouping:o.grouping,onSort:R,onSortAscending:Q,onSortDescending:te,onOpenFilters:()=>x(!0),onOpenSort:()=>I(!0),onOpenFilterForColumn:v,onSelectView:oe,onCreateView:()=>F(!0),onManageViews:()=>$(!0),onUpdateCurrentView:ee,onSaveAsNewView:N,onToggleDefault:ce,onToggleFavorite:ae,onRestoreView:K,onPermanentDelete:Me,onExport:L,onOpenColumns:()=>ut(!0),onUpdateColumnWidth:Mt,onUpdateColumnOrder:Be,onUpdateColumnVisibility:Fe,onClearFiltersForColumn:s,onResetLayout:St,onOpenGroup:()=>He(!0),onGroupByColumn:ue=>{Qe({enabled:!0,column:ue,showCounts:!0})},onToggleGroupCollapse:ar,onOpenAuditHistory:()=>$t(!0),onOpenScheduledReports:()=>gr(!0),searchQuery:et,searchHistory:it,onAddToSearchHistory:lr,onToggleSearchFavourite:Ir,onDeleteSearchHistory:Vt,selectedRowIds:pt,onSearchChange:We,onToggleRowSelection:jt,onToggleAllRows:cr,onRangeSelection:Ct,onClearSelection:io,onExportSelected:Ce,currentPage:(st==null?void 0:st.currentPage)||zr,pageSize:(st==null?void 0:st.pageSize)||wt,onPageChange:Br,onPageSizeChange:Ht,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:mr,userRole:fr,reportName:o.name,onEditRow:Wr,onDeleteRow:Pr,onDuplicateRow:Nr,favoriteRowIndices:mt,resolvedFavoritesSet:hr,showFavoritesOnly:ft,onToggleRowFavorite:_r,onBulkSetFavorites:Mr,onToggleFavoritesFilter:$r,showDevPanel:Wt.display.showDevPanel,onOpenDevConfig:()=>Kt(!0)})]}),b&&e.jsx(Jr,{feature:"Filters",onError:ue=>{const fe=Dt("ui","filters",ue);tt(fe)},children:e.jsx(tu,{schema:o.schema,filters:o.filters??[],onAddFilter:B,onUpdateFilter:y,onRemoveFilter:j,onClearAll:S,onReplaceFilters:k,onClose:w,focusColumn:g})}),_&&e.jsx(Jr,{feature:"Sorting",onError:ue=>{const fe=Dt("ui","sorting",ue);tt(fe)},children:e.jsx(ou,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:q,onClose:()=>I(!1)})}),h&&e.jsx(Jr,{feature:"Views",onError:ue=>{const fe=Dt("ui","views",ue);tt(fe)},children:e.jsx(nu,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:oe,onCreateView:()=>{$(!1),F(!0)},onEditView:Ue,onDeleteView:ge,onRestoreView:K,onPermanentDelete:Me,onPromoteToGlobal:Tr,isAdmin:((Xt=Wt.views)==null?void 0:Xt.isAdmin)??!1,onClose:()=>$(!1)})}),W&&m&&(()=>{var Re;const ue=(o.views??[]).filter(E=>!E.isDeleted).length,fe=((Re=Wt.views)==null?void 0:Re.maxViews)??10;return e.jsx(xi,{currentSnapshot:m,onSave:J,onClose:()=>F(!1),atViewLimit:ue>=fe,maxViews:fe})})(),X&&A&&e.jsx(xi,{currentSnapshot:A.snapshot,onSave:nt,onClose:()=>{xe(!1)},isEditMode:!0,initialName:A.name,initialDescription:A.description,initialIsDefault:A.isDefault}),me&&V&&e.jsx(iu,{viewName:V.name,onConfirm:sr,onCancel:()=>{Y(!1)}}),Ft&&l&&e.jsx(au,{schema:o.schema,columnVisibility:o.columnVisibility||l.snapshot.columnVisibility,columnOrder:o.columnOrder||l.snapshot.columnOrder,columnWidths:o.columnWidths||l.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:Fe,onUpdateColumnOrder:Be,onUpdateColumnWidth:Mt,onResetLayout:St,onSelectView:ue=>{oe(ue)},onSaveToCurrentView:ue=>{le(ue),ut(!1)},onSaveToAllViews:ue=>{ie(ue),ut(!1)},onClose:()=>ut(!1)}),Ze&&e.jsx(Jr,{feature:"Grouping",onError:ue=>{const fe=Dt("ui","grouping",ue);tt(fe)},children:e.jsx(lu,{schema:o.schema,grouping:o.grouping||null,onApply:Qe,onClose:()=>He(!1)})}),kt&&e.jsx(fu,{auditHistory:o.auditHistory||[],onClose:()=>$t(!1)}),Yt&&e.jsx(hu,{onSave:we,onClose:()=>Gt(!1)}),Or&&e.jsx(yu,{presets:o.presets||[],reportId:o.id,onOpenPreset:xt,onDeletePreset:xr,onClose:()=>qt(!1)}),Z&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(gu,{presetName:Z.name,onClear:pr})}),Er&&e.jsx(Jr,{feature:"Export",onError:ue=>{const fe=Dt("ui","export",ue);tt(fe)},children:e.jsx(Iu,{totalRows:(c==null?void 0:c.totalRows)||((Fr=o.uploadedData)==null?void 0:Fr.length)||0,visibleRows:(c==null?void 0:c.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:(c==null?void 0:c.isGrouped)||!1,schema:o.schema,allRows:o.uploadedData||[],processedRows:i||[],onExport:Ye,onClose:()=>{ur(!1)}})}),o&&e.jsx(Uu,{open:Rr,onClose:()=>gr(!1),reportId:o.id,reportName:o.name,onRunNow:ue=>{const fe=ue.scope==="all"?o.uploadedData||[]:i||[],Re=vo(fe,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);ue.format==="csv"&&So(Re,ue.name),ue.format==="excel"&&jo(Re,ue.name),ue.format==="json"&&Co(Re,ue.name),Pe(`"${ue.name}" exported successfully`,"success")}}),e.jsx(_u,{open:Lr,onClose:()=>Kt(!1),config:Wt,onApply:yr})]})}function is({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(a,c)=>{c!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(r.Alert,{severity:n,variant:"filled",sx:{width:"100%",boxShadow:3},children:o})})}function ss({hasExternalData:t=!1}){const o=zo(),{reports:n,activeReportId:i,activeReport:a,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:u,setIsModalOpen:m,setActiveReportId:f,createReport:b,handleFileUpload:x,handleUploadError:g,handleRetry:B,handleConfirm:y,snack:j,handleSnackClose:S}=o,k=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(ll,{onCreateReport:()=>m(!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:k?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(Ki,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):a?e.jsx(e.Fragment,{children:a.schemaLocked&&a.schema&&a.uploadedData&&a.views?e.jsx(ns,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&a.schema&&a.uploadedData?e.jsx(Sd,{schema:a.schema,onConfirm:y,hasConflicts:l}):a.uploadError?e.jsx(jd,{error:a.uploadError,onRetry:B}):e.jsx(vd,{onFileUpload:x,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(bd,{isOpen:u,onClose:()=>m(!1),onCreate:b}),e.jsx(is,{open:j.open,message:j.message,severity:j.severity,onClose:S})]})}function qu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:a}={}){return e.jsx(cn,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:a,children:e.jsx(ss,{hasExternalData:!!(t||o)})})}function as(){const t=zo(),{snack:o,handleSnackClose:n}=t;return e.jsxs(r.Box,{sx:{minHeight:"100vh"},children:[e.jsx(r.Box,{component:"main",children:t.activeReport?e.jsx(ns,{reportEngine:t}):e.jsx(Ki,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(is,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Ju({data:t,autoLoad:o=!0,config:n}){return e.jsx(cn,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(as,{})})}exports.URMBuilder=qu;exports.URMBuilderRaw=ss;exports.URMProvider=cn;exports.URMViewer=Ju;exports.URMViewerRaw=as;exports.useURMContext=zo;
|