dts-universal-report-module 1.0.13 → 1.0.14

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.
Files changed (3) hide show
  1. package/dist/index.esm.js +4639 -4610
  2. package/dist/index.js +24 -24
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,25 +1,25 @@
1
- "use strict";var $s=Object.defineProperty;var _s=(t,o,n)=>o in t?$s(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n;var Yr=(t,o,n)=>_s(t,typeof o!="symbol"?o+"":o,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),Ms=require("xlsx"),z=require("@mui/icons-material"),r=require("@mui/material"),bi=require("react-dom"),Rs=require("@emotion/react"),At=require("react-dnd"),ln=require("react-dnd-html5-backend");function vi(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 zo=vi(p),co=vi(Ms),Je={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}},Si="urm_dev_config";function Ws(){try{const t=localStorage.getItem(Si);if(!t)return Je;const o=JSON.parse(t),n={sort:{...Je.sort,...o.sort},filter:{...Je.filter,...o.filter},columns:{...Je.columns,...o.columns},grouping:{...Je.grouping,...o.grouping},export:{...Je.export,...o.export},views:{...Je.views,...o.views},dates:{...Je.dates,...o.dates},display:{...Je.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Je}}function Ps(t){try{localStorage.setItem(Si,JSON.stringify(t))}catch{}}function Ns(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 ji=p.createContext(Je);function nr(){return p.useContext(ji)}const Ls=/^\d{4}-\d{2}-\d{2}$/,Fs=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Vs=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Hs=9783072e5,Us=41024448e5,Ys=978307200,Gs=4102444800;function qs(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Hs&&t<=Us?"timestamp_ms":Number.isInteger(t)&&t>=Ys&&t<=Gs?"timestamp_s":"unknown":typeof t!="string"?"unknown":Fs.test(t)||Ls.test(t)?"iso":Vs.test(t.trim())?"locale_string":"unknown"}function Js(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=qs(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 Ks(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 Cn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Xs=["January","February","March","April","May","June","July","August","September","October","November","December"];function $e(t){return String(t).padStart(2,"0")}function Zs(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),x=Math.floor(l/30),h=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":""}`:x<12?b=`${x} month${x!==1?"s":""}`:b=`${h} year${h!==1?"s":""}`,a<60?b:i?`${b} ago`:`in ${b}`}function Qs(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`${Cn[i]} ${$e(a)}, ${n}`;case"DD MMM YYYY":return`${$e(a)} ${Cn[i]} ${n}`;case"MMMM D, YYYY":return`${Xs[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 Zs(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function ea(t,o,n){if(!n||o==="unknown")return String(t);const i=Ks(t,o);return!i||isNaN(i.getTime())?String(t):Qs(i,n)}function ta(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 Ci(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,Ci(d,c,n+1)):i[c]=d}return i}function yo(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:Ci(o))}function Gr(t){if(!Array.isArray(t)||t.length===0)return[];const o=yo(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(m=>{typeof m=="object"&&m!==null&&d in m&&(u++,l.add(ta(m[d])))});const x=u===o.length,h=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(y=>y!=="null");m.length===1&&(b=m[0])}i.push({name:d,type:b,required:x,hasConflict:h})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Js(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function ra(t){return t.some(o=>o.hasConflict)}function Xe(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 wn(t){return t==null}function oa(t){return(o,n,i)=>{const a=wn(o),c=wn(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 na(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(h=>h.name===d.column);if(!l)continue;const x=oa(l.type)(a[d.column],c[d.column],d.direction);if(x!==0)return x}return 0})}function ia(t){return t===null?"asc":t==="asc"?"desc":null}function sa(t){return t==="string"||t==="boolean"}function aa(t){return t.filter(o=>sa(o.type))}function la(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 ca(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=wi(t,n.levels,o);return ki(i,n.collapsedGroups||[])}function wi(t,o,n,i="",a=0){if(a>=o.length)return t;const c=o[a].column,d=new Map;t.forEach(x=>{const h=x[c],b=h==null?"(empty)":String(h);d.has(b)||d.set(b,[]),d.get(b).push(x)});const l=[];return Array.from(d.keys()).sort().forEach(x=>{const h=d.get(x),b=`${c}:${x}`,m=i?`${i}|${b}`:b,y=la(h,n),B=a<o.length-1?wi(h,o,n,m,a+1):h,v={key:m,level:a,column:c,value:x,rowCount:h.length,aggregates:y,children:B};l.push(v)}),l}function ki(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&&ki(i.children,o,n)}else n.push(i);return n}function da(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(a=>a!==o):[...n,o];return{...t,collapsedGroups:i}}function Ti(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function Ii(t,o,n){return`${o}: ${n}`}function Zr(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 zi(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 x of n)d.has(x)?c.push(x):l.has(x)&&u<a.length?(c.push(a[u]),u++):l.has(x)||c.push(x);for(let x=u;x<a.length;x++)c.includes(a[x])||c.push(a[x]);return c}return[...t]}function Yo(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 ua(t,o,n,i,a,c,d,l){const u={},x=[],h={};n.forEach(y=>{u[y.name]=!0,x.push(y.name),h[y.name]=170});const m=zi(a||x,d||null,l||x);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:m,columnWidths:c||h,grouping:d||null}}function pa(t,o){const n=m=>{if(m==null)return m;if(Array.isArray(m))return m.map(y=>n(y));if(typeof m=="object"){const y={};return Object.keys(m).sort().forEach(B=>{y[B]=n(m[B])}),y}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 u=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==u){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const m=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==m)return!0}const h=t.columnWidths??{},b=o.columnWidths??{};return i(h)!==i(b)||i(t.grouping)!==i(o.grouping)}function xa(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function ma(t,o){var v,j,S;const n=[],i=JSON.stringify(t.filters),a=JSON.stringify(o.filters);if(i!==a){const I=t.filters.length,f=o.filters.length;I>f?n.push({category:"filters",label:"Filters Added",description:`${I-f} new filter${I-f>1?"s":""} added`}):I<f?n.push({category:"filters",label:"Filters Removed",description:`${f-I} filter${f-I>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 I=t.sortStack.length,f=o.sortStack.length;I>f?n.push({category:"sorting",label:"Sorting Added",description:`${I-f} new sort rule${I-f>1?"s":""} added`}):I<f?n.push({category:"sorting",label:"Sorting Removed",description:`${f-I} sort rule${f-I>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 I=Object.values(t.columnVisibility).filter(w=>w).length,f=Object.values(o.columnVisibility).filter(w=>w).length;I>f?n.push({category:"visibility",label:"Columns Shown",description:`${I-f} column${I-f>1?"s":""} made visible`}):I<f?n.push({category:"visibility",label:"Columns Hidden",description:`${f-I} column${f-I>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const x=JSON.stringify(t.columnOrder),h=JSON.stringify(o.columnOrder);x!==h&&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 I=Object.keys(t.columnWidths).filter(f=>t.columnWidths[f]!==o.columnWidths[f]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${I} column width${I>1?"s":""} modified`})}const y=JSON.stringify(t.grouping),B=JSON.stringify(o.grouping);if(y!==B){const I=(v=t.grouping)==null?void 0:v.enabled,f=(j=o.grouping)==null?void 0:j.enabled;if(I&&!f){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!I&&f?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 kn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function Tn(t){return`[${t}]`}const rr={warn(t,o,...n){kn()&&console.warn(Tn(t),o,...n)},error(t,o,...n){kn()&&console.error(Tn(t),o,...n)}},Bi="urm_report_";function ha(t,o){try{const n=`${Bi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){rr.error("urm:persistence","Failed to save report state",n)}}function fa(t){try{const o=`${Bi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return rr.error("urm:persistence","Failed to load report state",o),null}}function Bo(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(ga(d)){const l=a.children,u=Bo(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 ga(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 cn(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function dn(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 jo(t,o,n,i,a,c,d){let l,u;c?(l={...c},u=d||o.map(h=>h.name)):a?(l={...a.snapshot.columnVisibility},u=d||[...a.snapshot.columnOrder]):(l={},u=[],o.forEach(h=>{l[h.name]=!0,u.push(h.name)}));const x=Object.entries(l).filter(([h,b])=>!b).map(([h,b])=>h);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:u,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 Co(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??[],m=Bo(i,b);l=cn(m)}else l=i;const u=d.join(","),x=l.map(b=>d.map(m=>{const y=b[m];if(y==null)return"";const B=String(y);return B.includes(",")||B.includes('"')||B.includes(`
1
+ "use strict";var $s=Object.defineProperty;var _s=(t,o,n)=>o in t?$s(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n;var Yr=(t,o,n)=>_s(t,typeof o!="symbol"?o+"":o,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),Ms=require("xlsx"),z=require("@mui/icons-material"),r=require("@mui/material"),bi=require("react-dom"),Rs=require("@emotion/react"),Dt=require("react-dnd"),ln=require("react-dnd-html5-backend");function vi(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 zo=vi(p),co=vi(Ms),Ke={sort:{maxLevels:5},filter:{maxConditions:3,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},Si="urm_dev_config";function Ws(){try{const t=localStorage.getItem(Si);if(!t)return Ke;const o=JSON.parse(t),n={sort:{...Ke.sort,...o.sort},filter:{...Ke.filter,...o.filter},columns:{...Ke.columns,...o.columns},grouping:{...Ke.grouping,...o.grouping},export:{...Ke.export,...o.export},views:{...Ke.views,...o.views},dates:{...Ke.dates,...o.dates},display:{...Ke.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ke}}function Ps(t){try{localStorage.setItem(Si,JSON.stringify(t))}catch{}}function Ns(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 ji=p.createContext(Ke);function ar(){return p.useContext(ji)}const Ls=/^\d{4}-\d{2}-\d{2}$/,Fs=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Vs=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Hs=9783072e5,Us=41024448e5,Ys=978307200,Gs=4102444800;function qs(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Hs&&t<=Us?"timestamp_ms":Number.isInteger(t)&&t>=Ys&&t<=Gs?"timestamp_s":"unknown":typeof t!="string"?"unknown":Fs.test(t)||Ls.test(t)?"iso":Vs.test(t.trim())?"locale_string":"unknown"}function Js(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 c=qs(d);i[c]++}const s=n.length,l=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/s>=l)return d;return"unknown"}function Ks(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 Cn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Xs=["January","February","March","April","May","June","July","August","September","October","November","December"];function _e(t){return String(t).padStart(2,"0")}function Zs(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),l=Math.floor(s/60),d=Math.floor(l/60),c=Math.floor(d/24),u=Math.floor(c/7),x=Math.floor(c/30),h=Math.floor(c/365);let b;return s<60?b="just now":l<60?b=`${l} minute${l!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:c<7?b=`${c} day${c!==1?"s":""}`:u<5?b=`${u} week${u!==1?"s":""}`:x<12?b=`${x} month${x!==1?"s":""}`:b=`${h} year${h!==1?"s":""}`,s<60?b:i?`${b} ago`:`in ${b}`}function Qs(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),l=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${_e(i+1)}-${_e(s)}`;case"DD/MM/YYYY":return`${_e(s)}/${_e(i+1)}/${n}`;case"MM/DD/YYYY":return`${_e(i+1)}/${_e(s)}/${n}`;case"MMM DD, YYYY":return`${Cn[i]} ${_e(s)}, ${n}`;case"DD MMM YYYY":return`${_e(s)} ${Cn[i]} ${n}`;case"MMMM D, YYYY":return`${Xs[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${_e(i+1)}-${_e(s)} ${_e(l)}:${_e(d)}`;case"DD/MM/YYYY HH:mm":return`${_e(s)}/${_e(i+1)}/${n} ${_e(l)}:${_e(d)}`;case"MM/DD/YYYY HH:mm":return`${_e(i+1)}/${_e(s)}/${n} ${_e(l)}:${_e(d)}`;case"relative":return Zs(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function ea(t,o,n){if(!n||o==="unknown")return String(t);const i=Ks(t,o);return!i||isNaN(i.getTime())?String(t):Qs(i,n)}function ta(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 Ci(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const l=o?`${o}.${s}`:s,d=t[s];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,Ci(d,l,n+1)):i[l]=d}return i}function yo(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:Ci(o))}function Gr(t){if(!Array.isArray(t)||t.length===0)return[];const o=yo(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(c=>n.add(c))});const i=[];n.forEach(d=>{const c=new Set;let u=0;o.forEach(m=>{typeof m=="object"&&m!==null&&d in m&&(u++,c.add(ta(m[d])))});const x=u===o.length,h=c.size>1&&!c.has("null");let b="mixed";if(c.size===1)b=Array.from(c)[0];else if(c.size===2&&c.has("null")){const m=Array.from(c).filter(g=>g!=="null");m.length===1&&(b=m[0])}i.push({name:d,type:b,required:x,hasConflict:h})});const l=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const c=Js(d.name,l);c!=="unknown"&&(d.type="date",d.dateFormat=c)}return i}function ra(t){return t.some(o=>o.hasConflict)}function Ze(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 wn(t){return t==null}function oa(t){return(o,n,i)=>{const s=wn(o),l=wn(n);if(s&&l)return 0;if(s)return 1;if(l)return-1;let d=0;switch(t){case"number":const c=Number(o),u=Number(n);d=c-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 na(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,l)=>s.priority-l.priority);return[...t].sort((s,l)=>{for(const d of i){const c=o.find(h=>h.name===d.column);if(!c)continue;const x=oa(c.type)(s[d.column],l[d.column],d.direction);if(x!==0)return x}return 0})}function ia(t){return t===null?"asc":t==="asc"?"desc":null}function sa(t){return t==="string"||t==="boolean"}function aa(t){return t.filter(o=>sa(o.type))}function la(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(l=>l[i.name]).filter(l=>typeof l=="number");s.length>0&&(n[i.name]=s.reduce((l,d)=>l+d,0))}}),n}function ca(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=wi(t,n.levels,o);return ki(i,n.collapsedGroups||[])}function wi(t,o,n,i="",s=0){if(s>=o.length)return t;const l=o[s].column,d=new Map;t.forEach(x=>{const h=x[l],b=h==null?"(empty)":String(h);d.has(b)||d.set(b,[]),d.get(b).push(x)});const c=[];return Array.from(d.keys()).sort().forEach(x=>{const h=d.get(x),b=`${l}:${x}`,m=i?`${i}|${b}`:b,g=la(h,n),B=s<o.length-1?wi(h,o,n,m,s+1):h,v={key:m,level:s,column:l,value:x,rowCount:h.length,aggregates:g,children:B};c.push(v)}),c}function ki(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const s=o.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:s}),!s&&i.children&&ki(i.children,o,n)}else n.push(i);return n}function da(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function Ti(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function Ii(t,o,n){return`${o}: ${n}`}function Zr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(s=>s.column),i=t.filter(s=>!n.includes(s));return[...n,...i]}function zi(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(l=>l.column),s=t.filter(l=>!i.includes(l));if(n){const l=[],d=new Set(i),c=new Set(s);let u=0;for(const x of n)d.has(x)?l.push(x):c.has(x)&&u<s.length?(l.push(s[u]),u++):c.has(x)||l.push(x);for(let x=u;x<s.length;x++)l.includes(s[x])||l.push(s[x]);return l}return[...t]}function Yo(t){const o={},n=[],i={};return t.forEach(s=>{o[s.name]=!0,n.push(s.name),i[s.name]=170}),{id:"default-view",name:"Default View",description:"Unfiltered, unsorted baseline view",isDefault:!0,snapshot:{filters:[],sortStack:[],columnVisibility:o,columnOrder:n,columnWidths:i,grouping:null}}}function ua(t,o,n,i,s,l,d,c){const u={},x=[],h={};n.forEach(g=>{u[g.name]=!0,x.push(g.name),h[g.name]=170});const m=zi(s||x,d||null,c||x);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:m,columnWidths:l||h,grouping:d||null}}function pa(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(B=>{g[B]=n(m[B])}),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 s=t.columnVisibility??{},l=o.columnVisibility??{};if(i(s)!==i(l))return!0;const d=[...t.columnOrder||[]].sort().join(","),c=[...o.columnOrder||[]].sort().join(",");if(d!==c)return!1;const u=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==u){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const m=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==m)return!0}const h=t.columnWidths??{},b=o.columnWidths??{};return i(h)!==i(b)||i(t.grouping)!==i(o.grouping)}function xa(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function ma(t,o){var v,j,S;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const I=t.filters.length,y=o.filters.length;I>y?n.push({category:"filters",label:"Filters Added",description:`${I-y} new filter${I-y>1?"s":""} added`}):I<y?n.push({category:"filters",label:"Filters Removed",description:`${y-I} filter${y-I>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const l=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(l!==d){const I=t.sortStack.length,y=o.sortStack.length;I>y?n.push({category:"sorting",label:"Sorting Added",description:`${I-y} new sort rule${I-y>1?"s":""} added`}):I<y?n.push({category:"sorting",label:"Sorting Removed",description:`${y-I} sort rule${y-I>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const c=JSON.stringify(t.columnVisibility),u=JSON.stringify(o.columnVisibility);if(c!==u){const I=Object.values(t.columnVisibility).filter(C=>C).length,y=Object.values(o.columnVisibility).filter(C=>C).length;I>y?n.push({category:"visibility",label:"Columns Shown",description:`${I-y} column${I-y>1?"s":""} made visible`}):I<y?n.push({category:"visibility",label:"Columns Hidden",description:`${y-I} column${y-I>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const x=JSON.stringify(t.columnOrder),h=JSON.stringify(o.columnOrder);x!==h&&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 I=Object.keys(t.columnWidths).filter(y=>t.columnWidths[y]!==o.columnWidths[y]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${I} column width${I>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),B=JSON.stringify(o.grouping);if(g!==B){const I=(v=t.grouping)==null?void 0:v.enabled,y=(j=o.grouping)==null?void 0:j.enabled;if(I&&!y){const C=((S=t.grouping)==null?void 0:S.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${C} grouping level${C>1?"s":""} added`})}else!I&&y?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 kn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function Tn(t){return`[${t}]`}const ir={warn(t,o,...n){kn()&&console.warn(Tn(t),o,...n)},error(t,o,...n){kn()&&console.error(Tn(t),o,...n)}},Bi="urm_report_";function ha(t,o){try{const n=`${Bi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){ir.error("urm:persistence","Failed to save report state",n)}}function fa(t){try{const o=`${Bi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return ir.error("urm:persistence","Failed to load report state",o),null}}function Bo(t,o,n=0){const i=[];for(const s of t){const l=o.includes(s.key);if(i.push({type:"group",key:s.key,level:n,column:s.column,value:s.value,rowCount:s.rowCount,aggregates:s.aggregates,collapsed:l}),!l&&s.children&&s.children.length>0){const d=s.children[0];if(ga(d)){const c=s.children,u=Bo(c,o,n+1);i.push(...u)}else{const c=s.children;for(const u of c)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:u})}}}return i}function ga(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 cn(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function dn(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),l=String(n.getDate()).padStart(2,"0"),d=`${i}-${s}-${l}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function jo(t,o,n,i,s,l,d){let c,u;l?(c={...l},u=d||o.map(h=>h.name)):s?(c={...s.snapshot.columnVisibility},u=d||[...s.snapshot.columnOrder]):(c={},u=[],o.forEach(h=>{c[h.name]=!0,u.push(h.name)}));const x=Object.entries(c).filter(([h,b])=>!b).map(([h,b])=>h);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:c,columnOrder:u,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:x,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function Co(t,o="export",n){const{data:i,columnOrder:s,grouping:l}=t,d=s.filter(b=>t.columnVisibility[b]);let c;if(l&&l.enabled){const b=l.collapsedGroups??[],m=Bo(i,b);c=cn(m)}else c=i;const u=d.join(","),x=c.map(b=>d.map(m=>{const g=b[m];if(g==null)return"";const B=String(g);return B.includes(",")||B.includes('"')||B.includes(`
2
2
  `)?`"${B.replace(/"/g,'""')}"`:B}).join(",")),h=[u,...x].join(`
3
- `);Ei(h,dn(o,"csv"),"text/csv;charset=utf-8;")}function wo(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??[],m=Bo(i,b);l=cn(m)}else l=i;const u=[d,...l.map(b=>d.map(m=>b[m]??""))],x=co.utils.aoa_to_sheet(u),h=co.utils.book_new();co.utils.book_append_sheet(h,x,"Data"),co.writeFile(h,dn(o,"xlsx"))}function ko(t,o="export",n){const{data:i,appliedFilters:a,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:u,grouping:x}=t;let h;if(x&&x.enabled){const y=x.collapsedGroups??[],B=Bo(i,y);h=cn(B)}else h=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:a.map(y=>({field:y.column,operator:y.operator,value:y.value})),sortStack:c.map(y=>({field:y.column,direction:y.direction,priority:y.priority})),grouping:x||{},hiddenColumns:l,columnOrder:u,exportConfig:n||{scope:"visible"}},data:h},m=JSON.stringify(b,null,2);Ei(m,dn(o,"json"),"application/json;charset=utf-8;")}function Ei(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 In=10;function ya(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>In&&(a=[...a].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,In)),a}function ba(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function va(t,o){return t.filter(n=>n.query!==o)}function Sa(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 ja={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 Ca(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function gt(t,o){return ja[o].includes(t)}function yt(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 wa(t){return t==="viewer"}const zn=1e3;function on(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function St(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return on(n)}const ka={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function Go(t){if(!t||!t.column)return"a filter";const o=St(t.column),n=ka[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function Bn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${St(n.column)}"`).join(", ")}`}function Ta(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: ${Go(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Go(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 "${St(u==null?void 0:u.column)}"`,detail:`Previously filtered "${St(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Go(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?St(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?St(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: ${Bn(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?St(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${Bn(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: "${St(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${St(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: "${St(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,x=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",h=(i==null?void 0:i.viewName)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:h?`${on(x)} · View: "${h}"`:on(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)??"",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:za(o)}}}function Ia(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Di(t,o,n,i,a,c){return{id:Ia(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:a,newState:c}}function Oi(t,o){const n=[o,...t];return n.length>zn?n.slice(0,zn):n}function za(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 Ea(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 En=100;function Da(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Oa(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=zi(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 Aa(t,o,n,i){return{id:Da(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function $a(t,o){const n=t||[];if(n.length>=En)throw new Error(`Maximum of ${En} presets reached. Please delete old presets first.`);return[...n,o]}function _a(t,o){return(t||[]).filter(i=>i.id!==o)}function Dn(t,o){if(t)return t.find(n=>n.id===o)}function Ma(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Ra(t){const o=t.columnOrder,n=Zr(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 Wa(t,o){return{totalRows:t.length,totalColumns:o.length}}const Pa={MAX_CACHE_ENTRIES:3};function Na(t,o){let n=null;return function(...a){const c=()=>{n=null,t(...a)};n&&clearTimeout(n),n=setTimeout(c,o)}}class uo{constructor(o=Pa.MAX_CACHE_ENTRIES){Yr(this,"cache",new Map);Yr(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 La{constructor(){Yr(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 Ot(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:Fa(t,o)};return process.env.NODE_ENV==="development"&&rr.error("urm:error-handling","[Report Error]",{type:t,context:o,message:a,details:i}),c}function Fa(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Va(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 Ha(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 Ua(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 Ya(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 Ai(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 $i(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 Ga(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}=Ai(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}=$i(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 qa(t,o){return Ot("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function On(t,o,n,i){const a=Di(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Oi(i||[],a)}function Ja(t){return t==null}function Ka(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Ja(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 Xa(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Ka(n[i.column],i)))}function An(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 po(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Za({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:Xa(t,o),[t,o])}}function Qa(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 el({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Qa(t,n,o,i),[t,o,n,i])}}function tl({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:na(t,n,o),[t,o,n])}}function rl({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:ca(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 ol({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(x=>x.name===l)||{name:l,type:"string"}),[n,t]),d=p.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 nl({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(x=>x.id===o),[t,o]),a=p.useMemo(()=>i?pa(n,i.snapshot):!1,[i,n]),c=p.useMemo(()=>t.find(x=>x.isDefault),[t]),d=p.useMemo(()=>t.filter(x=>!x.isDefault&&!x.isDeleted),[t]),l=p.useMemo(()=>t.filter(x=>x.isFavorite&&!x.isDeleted),[t]),u=p.useMemo(()=>t.filter(x=>x.isDeleted),[t]);return{activeView:i,isDirty:a,defaultView:c,customViews:d,favoriteViews:l,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function il({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 y=(a-1)*n,B=y+n;return t.slice(y,B)},[t,o,a,n]),x=p.useCallback(y=>{const B=Math.max(1,Math.min(y,l));c(B)},[l]),h=p.useCallback(()=>{a<l&&c(a+1)},[a,l]),b=p.useCallback(()=>{a>1&&c(a-1)},[a]),m=p.useCallback(()=>{c(1)},[]);return{paginatedData:u,currentPage:a,totalPages:l,pageSize:n,totalRows:d,goToPage:x,nextPage:h,prevPage:b,resetPage:m,hasNextPage:a<l,hasPrevPage:a>1}}function sl(t){const{rawData:o,schema:n,filters:i,sortStack:a,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:u,columnWidths:x,views:h,activeViewId:b,pagination:m}=t,y=p.useMemo(()=>({filters:i,sortStack:a,grouping:c,columnVisibility:l,columnOrder:u,columnWidths:x}),[i,a,c,l,u,x]),B=nl({views:h,activeViewId:b,currentState:y}),v=ol({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:j}=Za({data:o,filters:i}),{sortedData:S}=tl({data:j,sortStack:a,schema:n}),{groupedData:I,isGrouped:f}=rl({data:S,grouping:c,schema:n}),{searchedData:w}=el({data:I,searchQuery:d,schema:n,visibleColumns:v.visibleColumns}),s=il({data:w,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!=null&&m.enabled?s.paginatedData:w,T=p.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:S.length,groupedRows:f?I.length:S.length,searchedRows:w.length,visibleRows:$.length,hiddenColumns:v.hiddenCount,activeFilters:i.length,activeSorts:a.length,isGrouped:f}),[o.length,j.length,S.length,I.length,w.length,$.length,v.hiddenCount,i.length,a.length,f]);return{data:$,filteredData:j,sortedData:S,groupedData:I,searchedData:w,viewEngine:B,columnEngine:v,paginationEngine:s,metrics:T,isGrouped:f,isPaginated:(m==null?void 0:m.enabled)||!1}}let al=0;function ll(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:al++,writable:!1,enumerable:!1,configurable:!1})}const bt="user-demo-001";function cl(t={}){var yn,bn,vn,Sn,jn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:a,reportName:c,sharedReportId:d,config:l={}}=t,[u,x]=p.useState([]),h=nr(),[b,m]=p.useState(""),[y,B]=p.useState(!1),[v,j]=p.useState(!1),[S,I]=p.useState({message:"",severity:"info",open:!1}),f=(C,D="info")=>{I({message:C,severity:D,open:!0})},w=()=>I(C=>({...C,open:!1})),s=u.find(C=>C.id===b),[$,T]=p.useState("idle"),[R,q]=p.useState(!1),[X,te]=p.useState(!1),[g,_]=p.useState(!1),[W,V]=p.useState(!1),[Z,xe]=p.useState(!1),[me,F]=p.useState(!1),[A,H]=p.useState(void 0),[ne,J]=p.useState(null),[ee,le]=p.useState(null),[ie,P]=p.useState(!1),[se,ce]=p.useState(!1),[ae,ge]=p.useState(null),[K,_e]=p.useState(!1),[Ye,it]=p.useState(!1),[ar,Ir]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[Vt,pt]=p.useState(""),[Ve,Be]=p.useState(new Set),[Mt,jt]=p.useState(null),[Qe,Ue]=p.useState(1),[et,lr]=p.useState(15),[tt,st]=p.useState(!1),[Pe,cr]=p.useState(!1),[zr,Ht]=p.useState(!1),[xt,Ct]=p.useState(null),[dr,wt]=p.useState(!1),[ao,ur]=p.useState(null),[Br,kt]=p.useState(null);p.useRef(new La),p.useRef(new uo),p.useRef(new uo),p.useRef(new uo),p.useRef(new uo);const[at,Er]=p.useState(null),Ut=p.useRef(null),je=p.useMemo(()=>s?Ca(s.permissions,bt):"owner",[s]),Dr=wa(je),pr=p.useMemo(()=>!(s!=null&&s.uploadedData)||!(s!=null&&s.schema)?{totalRows:0,totalColumns:0}:Wa(s.uploadedData,s.schema),[s==null?void 0:s.uploadedData,s==null?void 0:s.schema]),lt=p.useCallback(()=>{s&&(Ut.current=Ha(s))},[s]),L=p.useCallback((C,D)=>{x(M=>M.map(O=>O.id===C?{...O,...D}:O))},[]),Ge=p.useCallback(C=>{if(!s)return;Er(C);const D=On(s.id,bt,C,s.auditHistory||[]);L(s.id,{auditHistory:D}),f(C.message,"error"),C.recoverable&&Ut.current&&setTimeout(()=>{Ua(s,Ut.current,L),f("Previous state restored","success")},100)},[s,L]),Ce=p.useCallback((C,D,M,O)=>{if(!s)return;const G=Di(s.id,bt,C,D,M,O),U=s.auditHistory||[],oe=Oi(U,G);setTimeout(()=>{L(s.id,{auditHistory:oe})},0)},[s,L]);p.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const C=Yo(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&&!v&&u.length===0){const C=yo(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:Gr(C),permissions:{owner:bt,editors:[],viewers:[]}};x([D]),m(D.id),j(!0),T("confirmed")}},[i,n,v,u.length,o,c]),p.useEffect(()=>{if(!a||v)return;let C=!1,D=null;const M=async()=>{try{T("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(C)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const G=Gr(O);if(v)x(U=>U.map(oe=>oe.id===b?{...oe,uploadedData:O}:oe)),T("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:yo(O),schema:Gr(yo(O)),permissions:{owner:bt,editors:[],viewers:[]}};x([U]),m(U.id),j(!0),T("confirmed")}}catch(O){C||(T("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 He=(yn=s==null?void 0:s.views)==null?void 0:yn.find(C=>C.id===s.activeViewId),Or=p.useMemo(()=>s!=null&&s.uploadedData?(s.uploadedData.forEach(ll),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]),Yt=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]),Tt=sl({rawData:Or,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:Vt||"",columnVisibility:(s==null?void 0:s.columnVisibility)||(He==null?void 0:He.snapshot.columnVisibility)||{},columnOrder:(s==null?void 0:s.columnOrder)||(He==null?void 0:He.snapshot.columnOrder)||[],columnWidths:(s==null?void 0:s.columnWidths)||(He==null?void 0:He.snapshot.columnWidths)||{},views:(s==null?void 0:s.views)||[],activeViewId:(s==null?void 0:s.activeViewId)||"",pagination:{enabled:!0,pageSize:et,currentPage:Qe}}),{data:Rt=[],searchedData:Gt=[],groupedData:qt=[],metrics:Ar={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Jt=!1,paginationEngine:Me}=Tt||{},Q=((bn=Tt.viewEngine)==null?void 0:bn.activeView)||He,It=((vn=Tt.viewEngine)==null?void 0:vn.isDirty)||!1;p.useEffect(()=>{if(!(!Q||!s)&&!s.columnOrder){const C=Q.snapshot.columnOrder,D=Zr(C,Q.snapshot.grouping);L(s.id,{columnOrder:D})}},[s==null?void 0:s.activeViewId]);const we=p.useMemo(()=>!(s!=null&&s.schema)||!Q?null:ua(s.filters||[],s.sortStack||[],s.schema,s.columnVisibility,s.columnOrder,s.columnWidths,s.grouping,Q.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,Q]),ke=p.useMemo(()=>!Q||!we||!It?[]:ma(we,Q.snapshot),[Q,we,It]),ct=p.useCallback((C,D,M)=>{const O={id:`report-${Date.now()}`,name:C,description:D,schemaLocked:!1,permissions:{owner:bt,editors:[],viewers:[]}};if(M&&Array.isArray(M)&&M.length>0){const G=Gr(M),U=Yo(G);O.uploadedData=M,O.schema=G,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(G=>[...G,O]),m(O.id),B(!1),T("confirmed")},[]),xr=p.useCallback(C=>{s&&(T("uploading"),setTimeout(()=>{const D=Gr(C);L(s.id,{uploadedData:C,schema:D,uploadError:void 0}),T("preview")},500))},[s,L]),mt=p.useCallback(C=>{s&&(L(s.id,{uploadError:C}),T("idle"))},[s,L]),qe=p.useCallback(()=>{s&&(L(s.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),T("idle"))},[s,L]),mr=p.useCallback(()=>{s&&(L(s.id,{schemaLocked:!0}),T("confirmed"))},[s,L]),hr=p.useCallback(C=>{if(!s)return;if(!gt("edit_sorting",je)){f(yt("edit_sorting"),"error");return}const D=s.sortStack??[],M=D.find(O=>O.column===C);if(M){const O=ia(M.direction);if(O===null){const G=D.filter(U=>U.column!==C).map((U,oe)=>({...U,priority:oe+1}));L(s.id,{sortStack:G.length>0?G:void 0})}else{const G=O,U=D.map(oe=>oe.column===C?{...oe,direction:G}:oe);L(s.id,{sortStack:U})}}else{if(D.length>=h.sort.maxLevels){f(`Sort limit reached — maximum ${h.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}=Ai(C,s.schema);M.length>0&&f(`Removed invalid sort columns: ${M.join(", ")}`),lt();try{L(s.id,{sortStack:D.length>0?D:void 0})}catch(O){const G=Ot("processing","sorting",O);Ge(G)}}else L(s.id,{sortStack:C.length>0?C:void 0})},[s,L,lt,Ge]),zt=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>=h.sort.maxLevels){f(`Sort limit reached — maximum ${h.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]),$r=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>=h.sort.maxLevels){f(`Sort limit reached — maximum ${h.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]),Wt=p.useCallback(C=>{var M;if(!s)return;if(!gt("edit_filters",je)){f(yt("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=Ya(D.type,C.operator,C.value);if(!O.isValid){f(O.errorMessage||"Invalid filter value","error");return}}lt();try{const O=s.filters??[];Ce("filters","filter_added",O,[...O,C]),L(s.id,{filters:[...O,C]})}catch(O){const G=Ot("processing","filters",O);Ge(G)}},[s,je,L,lt,Ge,Ce]),Kt=p.useCallback((C,D)=>{if(!s)return;if(!gt("edit_filters",je)){f(yt("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]),rt=p.useCallback(C=>{if(!s)return;if(!gt("edit_filters",je)){f(yt("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]),dt=p.useCallback(()=>{if(!s)return;if(!gt("edit_filters",je)){f(yt("edit_filters"),"error");return}const C=s.filters??[];Ce("filters","filter_cleared",C,null),L(s.id,{filters:void 0})},[s,je,L,Ce]),Ne=p.useCallback(C=>{if(!s)return;if(!gt("edit_filters",je)){f(yt("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]),ht=p.useCallback(C=>{var G;if(!s)return;const D=(G=s.views)==null?void 0:G.find(U=>U.id===C);if(!D)return;const M=D.snapshot.columnOrder,O=Zr(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]),gr=p.useCallback((C,D,M)=>{var Qt;if(!(s!=null&&s.schema)||!we)return;const O=s.views??[],G=O.filter(Ur=>!Ur.isDeleted).length,U=((Qt=h.views)==null?void 0:Qt.maxViews)??10;if(G>=U){f(`View limit reached — you can have at most ${U} saved views. Delete an existing view to create a new one.`,"error");return}const oe={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:bt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...we}},fe=M?O.map(Ur=>({...Ur,isDefault:!1})):O;L(s.id,{views:[...fe,oe],activeViewId:oe.id}),f(`"${C}" view created`,"success")},[s,we,L]),ft=p.useCallback(()=>{var D;if(!Q||!we||Q.isDefault||!s)return;const C=(D=s.views)==null?void 0:D.map(M=>M.id===Q.id?{...M,snapshot:{...we}}:M);L(s.id,{views:C}),f(`"${Q.name}" view updated`,"success")},[Q,we,s,L]),_r=p.useCallback(C=>{var O;if(!Q||!we||!s)return;const D=C??we.columnWidths,M=(O=s.views)==null?void 0:O.map(G=>G.id===Q.id?{...G,snapshot:{...G.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:D},updatedAt:Date.now()}:G);L(s.id,{views:M,columnWidths:D}),f(`Column configuration saved to "${Q.name}"`,"success")},[Q,we,s,L]),Mr=p.useCallback(C=>{var U,oe;if(!we||!s||!Q)return;const D=C??we.columnWidths,M={...Q,snapshot:{...Q.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:D},updatedAt:Date.now()},O=(U=s.views)==null?void 0:U.map(fe=>fe.id===Q.id?M:{...fe,snapshot:{...fe.snapshot,columnVisibility:we.columnVisibility,columnOrder:we.columnOrder,columnWidths:D},updatedAt:Date.now()});L(s.id,{views:O,columnWidths:D});const G=(((oe=s.views)==null?void 0:oe.length)||0)-1;f(`Column configuration saved to current view and ${G} other view${G===1?"":"s"}`,"success")},[we,s,Q,L]),Rr=p.useCallback(()=>{V(!0)},[]),Wr=p.useCallback(()=>{if(!Q||!s)return;const C=Q.snapshot.columnOrder,D=Zr(C,Q.snapshot.grouping);L(s.id,{filters:Q.snapshot.filters.length>0?[...Q.snapshot.filters]:void 0,sortStack:Q.snapshot.sortStack.length>0?[...Q.snapshot.sortStack]:void 0,columnVisibility:{...Q.snapshot.columnVisibility},columnOrder:D,columnWidths:{...Q.snapshot.columnWidths},grouping:Q.snapshot.grouping}),f("Changes reverted to last saved state","success")},[Q,s,L]),yr=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&&f(`"${M.name}" set as default view`,"success")},[s,L]),Pr=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?f(`"${M.name}" added to favorites`,"success"):M&&f(`"${M.name}" removed from favorites`,"info")},[s,L]),Nr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.map(U=>U.id===C?{...U,isDeleted:!0,updatedAt:Date.now()}:U),M=s.activeViewId===C,O=D.find(U=>U.isDefault&&!U.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(U=>U.id===C);G&&f(`"${G.name}" moved to Recently Deleted`,"info")},[s,L]),Lr=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&&f(`"${M.name}" restored`,"success")},[s,L]),Pt=p.useCallback(C=>{if(!(s!=null&&s.views))return;const D=s.views.find(fe=>fe.id===C),M=s.views.filter(fe=>!fe.isDeleted||fe.id===C);if((D==null?void 0:D.isDefault)&&M.filter(fe=>fe.isDefault).length===1){f("Cannot delete the last default view","error");return}const G=s.views.filter(fe=>fe.id!==C),U=s.activeViewId===C,oe=G.find(fe=>fe.isDefault&&!fe.isDeleted);L(s.id,{views:G,activeViewId:U&&oe?oe.id:s.activeViewId,filters:U&&oe?oe.snapshot.filters.length>0?oe.snapshot.filters:void 0:s.filters,sortStack:U&&oe?oe.snapshot.sortStack.length>0?oe.snapshot.sortStack:void 0:s.sortStack}),D&&f(`"${D.name}" permanently deleted`,"success")},[s,L]),br=p.useCallback(C=>{J(C),xe(!0),_(!1)},[]),Fr=p.useCallback((C,D)=>{if(!ne||!(s!=null&&s.views))return;const M=s.views.map(O=>O.id===ne?{...O,name:C,description:D||void 0}:O);L(s.id,{views:M}),J(null)},[ne,s,L]),Xt=p.useCallback(C=>{le(C),F(!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),F(!1)},[ee,s,L]),ut=p.useCallback(C=>{var G;if(!(s!=null&&s.views))return;if(!(((G=h.views)==null?void 0:G.isAdmin)??!1)){f("Only administrators can promote views to Global.","error");return}const M=s.views.find(U=>U.id===C);if(!M)return;if(M.scope==="global"){f(`"${M.name}" is already a Global View.`,"info");return}const O=s.views.map(U=>U.id===C?{...U,scope:"global",isDefault:!0,updatedAt:Date.now()}:U.scope==="global"&&U.isDefault?{...U,isDefault:!1}:U);L(s.id,{views:O}),f(`"${M.name}" promoted to Global View and set as default.`,"success")},[s,h,L]);p.useEffect(()=>{Me!=null&&Me.resetPage?Me.resetPage():Ue(1)},[s==null?void 0:s.filters,Vt,s==null?void 0:s.activeViewId]),p.useEffect(()=>{Me&&Me.currentPage!==Qe&&Ue(Me.currentPage)},[Me==null?void 0:Me.currentPage]);const Zt=p.useCallback(C=>{Me!=null&&Me.goToPage&&Me.goToPage(C),Ue(C)},[Me]),Vr=p.useCallback(C=>{const D=(Qe-1)*et,M=Math.floor(D/C)+1;lr(C),Ue(M)},[Qe,et]),Bt=p.useCallback((C,D)=>{if(!s)return;if(!gt("edit_columns",je)){f(yt("edit_columns"),"error");return}const O={...s.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{},[C]:D};L(s.id,{columnVisibility:O})},[s,Q,je,L]),ue=p.useCallback(C=>{if(s){if(!gt("edit_columns",je)){f(yt("edit_columns"),"error");return}L(s.id,{columnOrder:C})}},[s,je,L]),he=p.useCallback((C,D)=>{if(!s)return;if(!gt("edit_columns",je)){f(yt("edit_columns"),"error");return}const O={...s.columnWidths||(Q==null?void 0:Q.snapshot.columnWidths)||{},[C]:D};L(s.id,{columnWidths:O})},[s,Q,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(!Q||!(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}),f("Reset to default layout - all filters and sorts cleared","success")},[Q,s,L]),Y=p.useCallback(Na(C=>{pt(C)},300),[]),pe=p.useCallback(C=>{Y(C)},[Y]),Le=p.useCallback(C=>{if(!C.trim()||!s)return;const D=s.searchHistory||[],M=ya(D,C);L(s.id,{searchHistory:M})},[s,L]),de=p.useCallback(C=>{if(!s)return;const D=s.searchHistory||[],M=ba(D,C);L(s.id,{searchHistory:M})},[s,L]),Et=p.useCallback(C=>{if(!s)return;const D=s.searchHistory||[],M=va(D,C);L(s.id,{searchHistory:M})},[s,L]),Uo=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(U=>(U==null?void 0:U.__urm_row_id__)===D);G!==void 0?O.delete(G):O.add(C)}else{const G=JSON.stringify(C),U=Array.from(O).find(oe=>JSON.stringify(oe)===G);U!==void 0?O.delete(U):O.add(C)}return O})},[]),ds=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})},[]),us=p.useCallback((C,D,M)=>{Be(O=>{const G=new Set(O),U=Math.min(C,D),oe=Math.max(C,D);for(let fe=U;fe<=oe;fe++)M[fe]!==void 0&&G.add(M[fe]);return G})},[]),ps=p.useCallback(()=>{Be(new Set),jt(null)},[]),xs=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(U=>(U==null?void 0:U.__urm_row_id__)===D);G!==void 0&&O.delete(G)}else O.delete(C);return O})},[]),ms=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(U=>U!==D):[...M,D];L(s.id,{favoriteRowIndices:G})},[s,L]),hs=p.useCallback((C,D)=>{if(!(s!=null&&s.uploadedData))return;const M=s.favoriteRowIndices||[],O=C.map(U=>s.uploadedData.indexOf(U)).filter(U=>U!==-1),G=D?[...M,...O.filter(U=>!M.includes(U))]:M.filter(U=>!O.includes(U));L(s.id,{favoriteRowIndices:G})},[s,L]),fs=p.useCallback(()=>{if(!s)return;const C=s.favoriteRowIndices||[],D=!s.showFavoritesOnly;if(D&&C.length===0){f("No rows marked as favorite","warning");return}if(L(s.id,{showFavoritesOnly:D}),D){if(jt(new Set(Ve)),Ve.size>0){const M=new Set(C.map(G=>{var U,oe;return(oe=(U=s.uploadedData)==null?void 0:U[G])==null?void 0:oe.__urm_row_id__}).filter(G=>G!==void 0)),O=new Set(Array.from(Ve).filter(G=>(G==null?void 0:G.__urm_row_id__)!==void 0&&M.has(G.__urm_row_id__)));Be(O)}f(`Showing ${C.length} favorite row${C.length===1?"":"s"}`,"info")}else{if(Mt!==null){const M=new Set(Array.from(Ve).map(oe=>oe==null?void 0:oe.__urm_row_id__).filter(Boolean)),O=new Set(Array.from(Mt).map(oe=>oe==null?void 0:oe.__urm_row_id__).filter(Boolean)),G=new Set(C.map(oe=>{var fe,Qt;return(Qt=(fe=s.uploadedData)==null?void 0:fe[oe])==null?void 0:Qt.__urm_row_id__}).filter(oe=>oe!==void 0)),U=new Set;Array.from(Mt).forEach(oe=>{const fe=oe==null?void 0:oe.__urm_row_id__;if(fe===void 0)return;const Qt=G.has(fe),Ur=M.has(fe);Qt&&!Ur||U.add(oe)}),Array.from(Ve).forEach(oe=>{const fe=oe==null?void 0:oe.__urm_row_id__;fe!==void 0&&(O.has(fe)||U.add(oe))}),Be(U),jt(null)}f("Showing all data","info")}},[s,L,Ve,Mt]),gs=p.useCallback(C=>{if(s){if(!gt("edit_columns",je)){f(yt("edit_columns"),"error");return}if(C&&s.schema){const{validGrouping:D,invalidColumns:M}=$i(C,s.schema);M.length>0&&f(`Removed invalid grouping columns: ${M.join(", ")}`,"warning"),lt();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=(Q==null?void 0:Q.snapshot.columnOrder)||s.columnOrder||[],U=Zr(G,D);L(s.id,{grouping:D,columnOrder:U}),JSON.stringify(U)!==JSON.stringify(s.columnOrder)&&Ce("columns","column_reordered",s.columnOrder,U),it(!1)}catch(O){const G=Ot("processing","grouping",O);Ge(G)}}else{const D=s.grouping;Ce("grouping","group_cleared",D,null);const M=(Q==null?void 0:Q.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),it(!1)}}},[s,Q,je,L,lt,Ge,Ce]),ys=p.useCallback(C=>{if(!s)return;const D=s.grouping;if(!D)return;const M=da(D,C);L(s.id,{grouping:M})},[s,L]),bs=p.useCallback(()=>{wt(!0)},[]),Hr=p.useCallback(C=>{s!=null&&s.schema&&(P(!0),setTimeout(()=>{try{let D;C.scope==="visible"?D=Gt:D=s.uploadedData||[];let M;C.columnScope==="all"?(M={},(s.schema??[]).forEach(fe=>{M[fe.name]=!0})):M=s.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{};const O=s.columnOrder||(Q==null?void 0:Q.snapshot.columnOrder),G=jo(D,s.schema,s.filters??[],s.sortStack??[],Q,M,O),U=s.name;let oe;switch(C.format){case"csv":Co(G,U,C),oe="export_csv";break;case"excel":wo(G,U,C),oe="export_excel";break;case"json":ko(G,U,C),oe="export_json";break}Ce("export",oe,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:D.length,viewName:(Q==null?void 0:Q.name)||"Default View"}),f(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(D){const M=qa(D,{onRetry:()=>Hr(C)});f(`Export failed: ${M.message}. Click Export to retry.`,"error");const O=On(s.id,bt,M,s.auditHistory||[]);L(s.id,{auditHistory:O}),rr.error("urm:report-engine","Export failed",D)}finally{P(!1)}},500))},[s,Q,Gt,L,Ce]),vs=p.useCallback(C=>{if(s!=null&&s.schema){if(It&&Q&&!Q.isDefault){ge(C.format),ce(!0),wt(!1);return}Hr(C),wt(!1)}},[s,Q,It,Hr]),lo=p.useCallback(C=>{Hr({format:C,scope:"visible",columnScope:"visible"})},[Hr]),Ss=p.useCallback(()=>{ae&&lo(ae),ce(!1),ge(null)},[ae,lo]),js=p.useCallback(()=>{ft(),ae&&lo(ae),ce(!1),ge(null)},[ft,ae,lo]),Cs=p.useCallback(()=>{ce(!1),ge(null)},[]),ws=p.useCallback(C=>{!(s!=null&&s.schema)||Ve.size===0||(P(!0),setTimeout(()=>{try{const D=Array.from(Ve),M=jo(D,s.schema,s.filters??[],s.sortStack??[],Q),O=`${s.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":Co(M,O);break;case"excel":wo(M,O);break;case"json":ko(M,O);break}f(`Exported ${D.length} selected rows`,"info")}catch(D){f("Export failed. Please try again.","error"),rr.error("urm:report-engine","Bulk export failed",D)}finally{P(!1)}},500))},[s,Q,Ve,qt]),ks=p.useCallback((C,D)=>{if(s)try{const M=Oa(s),O=Aa(C,D,bt,M),G=$a(s.presets,O);L(s.id,{presets:G}),Ce("presets","preset_created",null,{presetId:O.id,name:O.name}),cr(!1),f(`Preset "${C}" saved successfully`,"success")}catch(M){f(M instanceof Error?M.message:"Failed to create preset","error")}},[s,L,Ce]),Ts=p.useCallback(()=>{Ct(null),f("Exited preset view","info")},[]),Is=p.useCallback(()=>{Ht(!0)},[]),zs=p.useCallback((C,D)=>{if(!s)return;const M=_a(s.presets,C);L(s.id,{presets:M}),Ce("presets","preset_deleted",{presetId:C,name:D},null),xt===C&&Ct(null),f(`Preset "${D}" deleted`,"success")},[s,xt,L,Ce]);p.useEffect(()=>{if(!d||u.length===0)return;const C=u.find(D=>D.id===d);C&&C.id!==b&&m(C.id)},[d,u,b]),p.useEffect(()=>{if(!s)return;const C=Ma();if(C&&s.presets&&s.schemaLocked&&s.schema){const D=Dn(s.presets,C);if(D){const{sanitizedConfig:M,warnings:O}=Ga(D.config,s.schema);O.length>0&&O.forEach(U=>f(U,"warning"));const G=Ra(M);L(s.id,G),Ct(C),Ce("presets","preset_applied",null,{presetId:D.id,name:D.name}),f(`Loaded preset: ${D.name}`,"info")}else f("Preset not found","info")}},[s==null?void 0:s.schemaLocked]);const Bs=xt?Dn(s==null?void 0:s.presets,xt):void 0;p.useEffect(()=>{s!=null&&s.views&&s.views.length>0&&s.activeViewId&&ha(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=fa(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)||Yo(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 Es=p.useCallback(C=>{var O;const D=(s==null?void 0:s.filters)??[],M=((O=h.filter)==null?void 0:O.maxConditions)??3;if(D.length>=M){f(`Filter limit reached — maximum ${M} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}H(C),q(!0)},[s,h,f]),Ds=p.useCallback(()=>{q(!1),H(void 0)},[]),Os=(Sn=s==null?void 0:s.views)==null?void 0:Sn.find(C=>C.id===ne),As=(jn=s==null?void 0:s.views)==null?void 0:jn.find(C=>C.id===ee);return{reports:u,activeReport:s,activeReportId:b,setActiveReportId:m,isModalOpen:y,setIsModalOpen:B,createReport:ct,updateReport:L,uploadState:$,handleFileUpload:xr,handleUploadError:mt,handleRetry:qe,handleConfirm:mr,paginatedData:Rt,processedData:Gt,displayData:qt,tableMetrics:Ar,isGrouped:Jt,tableEngine:Tt,activeView:Q,isDirty:It,currentTableState:we,viewChanges:ke,filters:s==null?void 0:s.filters,showFilterPanel:R,setShowFilterPanel:q,filterFocusColumn:A,handleAddFilter:Wt,handleUpdateFilter:Kt,handleRemoveFilter:rt,handleClearAllFilters:dt,handleReplaceFilters:Ne,handleOpenFilterForColumn:Es,handleCloseFilterPanel:Ds,handleClearFiltersForColumn:Re,sortStack:s==null?void 0:s.sortStack,showSortPanel:X,setShowSortPanel:te,handleSort:hr,handleUpdateSortStack:fr,handleSortAscending:zt,handleSortDescending:$r,views:s==null?void 0:s.views,showManageViews:g,setShowManageViews:_,showCreateViewModal:W,setShowCreateViewModal:V,showEditViewModal:Z,setShowEditViewModal:xe,showDeleteConfirmation:me,setShowDeleteConfirmation:F,editingView:Os,deletingView:As,editingViewId:ne,deletingViewId:ee,handleSelectView:ht,handleCreateView:gr,handleUpdateCurrentView:ft,handleSaveColumnConfigToCurrentView:_r,handleSaveColumnConfigToAllViews:Mr,handleSaveAsNewView:Rr,handleRevertChanges:Wr,handleToggleDefault:yr,handleToggleFavorite:Pr,handleSoftDelete:Nr,handleRestoreView:Lr,handlePermanentDelete:Pt,handleEditView:br,handleSaveEditView:Fr,handleDeleteView:Xt,handleConfirmDelete:Ae,handlePromoteToGlobal:ut,showManageColumns:K,setShowManageColumns:_e,columnVisibility:s==null?void 0:s.columnVisibility,columnOrder:s==null?void 0:s.columnOrder,columnWidths:s==null?void 0:s.columnWidths,handleUpdateColumnVisibility:Bt,handleUpdateColumnOrder:ue,handleUpdateColumnWidth:he,handleResetColumnLayout:E,showGroupPanel:Ye,setShowGroupPanel:it,grouping:s==null?void 0:s.grouping,groupingState:ar,handleGroup:gs,handleToggleGroupCollapse:ys,searchQuery:Vt,searchHistory:Sa((s==null?void 0:s.searchHistory)||[]),handleSearchChange:pe,handleAddToSearchHistory:Le,handleToggleSearchFavourite:de,handleDeleteSearchHistory:Et,selectedRowIds:Ve,handleToggleRowSelection:Uo,handleToggleAllRows:ds,handleRangeSelection:us,handleClearSelection:ps,handleUpdateSelectionAfterDelete:xs,favoriteRowIndices:(s==null?void 0:s.favoriteRowIndices)||[],resolvedFavoritesSet:Yt,showFavoritesOnly:(s==null?void 0:s.showFavoritesOnly)||!1,handleToggleRowFavorite:ms,handleBulkSetFavorites:hs,handleToggleFavoritesFilter:fs,currentPage:Qe,pageSize:et,paginationEngine:Me,handlePageChange:Zt,handlePageSizeChange:Vr,isExporting:ie,showExportModal:dr,setShowExportModal:wt,showDirtyExportWarning:se,handleExport:bs,handleExportWithConfig:vs,handleExportSelected:ws,handleExportAnyway:Ss,handleSaveAndExport:js,handleCancelExport:Cs,showAuditHistory:tt,setShowAuditHistory:st,auditHistory:s==null?void 0:s.auditHistory,showCreatePreset:Pe,setShowCreatePreset:cr,showManagePresets:zr,setShowManagePresets:Ht,activePreset:Bs,activePresetId:xt,handleOpenManagePresets:Is,handleCreatePreset:ks,handleClearActivePreset:Ts,handleDeletePresetById:zs,userRole:je,isViewerRole:Dr,currentUserId:bt,featureLimitWarning:Br,setFeatureLimitWarning:kt,datasetMeta:pr,reportError:at,setReportError:Er,handleError:Ge,schema:s==null?void 0:s.schema,hasSchemaConflicts:s!=null&&s.schema?ra(s.schema):!1,snack:S,handleSnackClose:w,showSnack:f}}const _i=p.createContext(void 0);function un(t){const{children:o,initialData:n,data:i,reportName:a,dataSource:c,mode:d="builder",autoLoad:l=!0,config:u,devConfig:x,showDevPanel:h=!1,sharedReportId:b}=t,y=cl({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:a,sharedReportId:b,config:u}),[B,v]=p.useState(()=>Ws()),j=(()=>{const w=Ns(B,x,!!x);return{...w,display:{...w.display,showDevPanel:h||w.display.showDevPanel}}})(),S=p.useCallback(f=>{v(f),Ps(f)},[]),I={...y,activeDevConfig:j,handleDevConfigChange:S};return e.jsx(ji.Provider,{value:j,children:e.jsx(_i.Provider,{value:I,children:o})})}function Eo(){const t=p.useContext(_i);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function dl({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(z.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(z.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(z.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function or(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 ul="$$material";function pl(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var xo={exports:{}},mo={exports:{}},ye={};/** @license React v16.13.1
3
+ `);Ei(h,dn(o,"csv"),"text/csv;charset=utf-8;")}function wo(t,o="export",n){const{data:i,columnOrder:s,grouping:l}=t,d=s.filter(b=>t.columnVisibility[b]);let c;if(l&&l.enabled){const b=l.collapsedGroups??[],m=Bo(i,b);c=cn(m)}else c=i;const u=[d,...c.map(b=>d.map(m=>b[m]??""))],x=co.utils.aoa_to_sheet(u),h=co.utils.book_new();co.utils.book_append_sheet(h,x,"Data"),co.writeFile(h,dn(o,"xlsx"))}function ko(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:l,viewMeta:d,hiddenColumns:c,columnOrder:u,grouping:x}=t;let h;if(x&&x.enabled){const g=x.collapsedGroups??[],B=Bo(i,g);h=cn(B)}else h=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:s.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:l.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:x||{},hiddenColumns:c,columnOrder:u,exportConfig:n||{scope:"visible"}},data:h},m=JSON.stringify(b,null,2);Ei(m,dn(o,"json"),"application/json;charset=utf-8;")}function Ei(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),l=document.createElement("a");l.href=s,l.download=o,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(s)}const In=10;function ya(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(l=>l.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],s.length>In&&(s=[...s].sort((d,c)=>d.isFavourite&&!c.isFavourite?-1:!d.isFavourite&&c.isFavourite?1:c.lastUsed-d.lastUsed).slice(0,In)),s}function ba(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function va(t,o){return t.filter(n=>n.query!==o)}function Sa(t){const o=t.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...o,...n]}const ja={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 Ca(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function yt(t,o){return ja[o].includes(t)}function bt(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 wa(t){return t==="viewer"}const zn=1e3;function on(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function jt(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return on(n)}const ka={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function Go(t){if(!t||!t.column)return"a filter";const o=jt(t.column),n=ka[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function Bn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${jt(n.column)}"`).join(", ")}`}function Ta(t){var s,l,d;const{action:o,previousState:n,newState:i}=t;switch(o){case"filter_added":{const c=i&&Array.isArray(i)?i[i.length-1]:i;return{summary:`Filter added: ${Go(c)}`}}case"filter_removed":return{summary:`Filter removed: ${Go(n)}`};case"filter_updated":{const c=n,u=i;return(c==null?void 0:c.column)!==(u==null?void 0:u.column)?{summary:`Filter changed on "${jt(u==null?void 0:u.column)}"`,detail:`Previously filtered "${jt(c==null?void 0:c.column)}"`}:{summary:`Filter updated: ${Go(u)}`}}case"filter_cleared":{const c=Array.isArray(n)?n.length:0;return{summary:c>0?`All filters cleared (${c} filter${c!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const c=i!=null&&i.column?jt(i.column):"",u=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:c?`Sort added: "${c}" ${u}`:"Sort level added"}}case"sort_level_removed":{const c=n!=null&&n.column?jt(n.column):"";return{summary:c?`Sort removed: "${c}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${Bn(i)}`};case"group_level_removed":{const c=n,u=(l=(s=c==null?void 0:c.levels)==null?void 0:s[0])!=null&&l.column?jt(c.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${Bn(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const c=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:c?`Column hidden: "${jt(c)}"`:"Column hidden"}}case"column_shown":{const c=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:c?`Column shown: "${jt(c)}"`:"Column made visible"}}case"column_reordered":{const c=Array.isArray(n)?n:[],u=Array.isArray(i)?i:[];return c.length>0&&u.length>0?{summary:"Column order changed",detail:`${u.length} column${u.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const c=(i==null?void 0:i.column)??"",u=(i==null?void 0:i.width)??"";return{summary:c?`Column resized: "${jt(c)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const c=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:c?`View created: "${c}"`:"New view created"}}case"view_updated":{const c=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:c?`View updated: "${c}"`:"View updated"}}case"view_deleted":{const c=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:c?`View deleted: "${c}"`:"View deleted"}}case"view_set_default":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Default view set to "${c}"`:"Default view changed"}}case"view_switched":{const c=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return c&&u?{summary:`Switched to view "${u}"`,detail:`From "${c}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const c=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,x=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",h=(i==null?void 0:i.viewName)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${c}${b}`,detail:h?`${on(x)} · View: "${h}"`:on(x)}}case"export_triggered":{const c=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:c?`Export triggered: ${c}`:"Export triggered"}}case"preset_created":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Preset created: "${c}"`:"New preset created"}}case"preset_applied":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Preset applied: "${c}"`:"Preset applied"}}case"preset_deleted":{const c=(n==null?void 0:n.name)??"";return{summary:c?`Preset deleted: "${c}"`:"Preset deleted"}}case"preset_link_copied":{const c=(i==null?void 0:i.name)??"";return{summary:c?`Preset link copied: "${c}"`:"Preset link copied to clipboard"}}case"theme_changed":{const c=typeof n=="string"?n:(n==null?void 0:n.theme)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return c&&u?{summary:`Theme changed from "${c}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{summary:"Theme changed"}}case"error_occurred":{const c=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:c?`Details: ${String(c).slice(0,120)}`:void 0}}default:return{summary:za(o)}}}function Ia(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Di(t,o,n,i,s,l){return{id:Ia(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:l}}function Oi(t,o){const n=[o,...t];return n.length>zn?n.slice(0,zn):n}function za(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 Ea(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),l=Math.floor(i/36e5),d=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:l<24?`${l} hour${l>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const En=100;function Da(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Oa(t){var l;const o=(l=t.views)==null?void 0:l.find(d=>d.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],s=zi(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:s,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Aa(t,o,n,i){return{id:Da(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function $a(t,o){const n=t||[];if(n.length>=En)throw new Error(`Maximum of ${En} presets reached. Please delete old presets first.`);return[...n,o]}function _a(t,o){return(t||[]).filter(i=>i.id!==o)}function Dn(t,o){if(t)return t.find(n=>n.id===o)}function Ma(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Ra(t){const o=t.columnOrder,n=Zr(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 Wa(t,o){return{totalRows:t.length,totalColumns:o.length}}const Pa={MAX_CACHE_ENTRIES:3};function Na(t,o){let n=null;return function(...s){const l=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(l,o)}}class uo{constructor(o=Pa.MAX_CACHE_ENTRIES){Yr(this,"cache",new Map);Yr(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 s=(i=Array.from(this.cache.entries()).sort((l,d)=>l[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];s&&this.cache.delete(s)}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 La{constructor(){Yr(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(),s=this.end(o);return{result:i,duration:s}}async measureAsync(o,n){this.start(o);const i=await n(),s=this.end(o);return{result:i,duration:s}}}function Et(t,o,n,i){const s=n instanceof Error?n.message:n,l={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:Fa(t,o)};return process.env.NODE_ENV==="development"&&ir.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),l}function Fa(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Va(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 Ha(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 Ua(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 Ya(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 Ai(t,o){const n=[],i=[],s=new Set(o.map(l=>l.name));return t.forEach(l=>{s.has(l.column)?n.push(l):i.push(l.column)}),{validRules:n,invalidColumns:i}}function $i(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(l=>l.name)),i=[],s=[];return t.levels.forEach(l=>{n.has(l.column)?i.push(l):s.push(l.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...t,levels:i},invalidColumns:s}}function Ga(t,o){const n=[],i=new Set(o.map(l=>l.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const l=s.filters.filter(d=>{const c=i.has(d.column);return c||n.push(`Filter for column "${d.column}" ignored (column not found)`),c});s.filters=l.length>0?l:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:l,invalidColumns:d}=Ai(s.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),s.sortStack=l.length>0?l:void 0}if(s.grouping){const{validGrouping:l,invalidColumns:d}=$i(s.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),s.grouping=l}if(s.columnVisibility){const l={};Object.entries(s.columnVisibility).forEach(([d,c])=>{i.has(d)?l[d]=c:n.push(`Column visibility for "${d}" ignored (column not found)`)}),s.columnVisibility=Object.keys(l).length>0?l:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const l=s.columnOrder.filter(d=>{const c=i.has(d);return c||n.push(`Column "${d}" in order ignored (column not found)`),c});s.columnOrder=l.length>0?l:void 0}if(s.columnWidths){const l={};Object.entries(s.columnWidths).forEach(([d,c])=>{i.has(d)?l[d]=c:n.push(`Column width for "${d}" ignored (column not found)`)}),s.columnWidths=Object.keys(l).length>0?l:void 0}return{sanitizedConfig:s,warnings:n}}function qa(t,o){return Et("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function On(t,o,n,i){const s=Di(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Oi(i||[],s)}function Ja(t){return t==null}function Ka(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Ja(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 Xa(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Ka(n[i.column],i)))}function An(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 po(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Za({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:Xa(t,o),[t,o])}}function Qa(t,o,n,i){if(!n||n.trim()==="")return t;const s=n.toLowerCase().trim(),l=o.filter(d=>i.includes(d.name));return t.filter(d=>l.some(c=>{const u=d[c.name];return u==null?!1:String(u).toLowerCase().includes(s)}))}function el({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Qa(t,n,o,i),[t,o,n,i])}}function tl({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:na(t,n,o),[t,o,n])}}function rl({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:ca(t,n,o),[t,o,n]),s=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function ol({schema:t,columnVisibility:o,columnOrder:n}){const i=p.useMemo(()=>n.filter(c=>o[c]!==!1),[n,o]),s=p.useMemo(()=>Object.entries(o).filter(([c,u])=>!u).map(([c,u])=>c),[o]),l=p.useMemo(()=>n.map(c=>t.find(x=>x.name===c)||{name:c,type:"string"}),[n,t]),d=p.useMemo(()=>i.map(c=>t.find(x=>x.name===c)||{name:c,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:l,visibleColumnSchemas:d,hiddenCount:s.length}}function nl({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(x=>x.id===o),[t,o]),s=p.useMemo(()=>i?pa(n,i.snapshot):!1,[i,n]),l=p.useMemo(()=>t.find(x=>x.isDefault),[t]),d=p.useMemo(()=>t.filter(x=>!x.isDefault&&!x.isDeleted),[t]),c=p.useMemo(()=>t.filter(x=>x.isFavorite&&!x.isDeleted),[t]),u=p.useMemo(()=>t.filter(x=>x.isDeleted),[t]);return{activeView:i,isDirty:s,defaultView:l,customViews:d,favoriteViews:c,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function il({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,l]=p.useState(i),d=t.length,c=Math.ceil(d/n),u=p.useMemo(()=>{if(!o)return t;const g=(s-1)*n,B=g+n;return t.slice(g,B)},[t,o,s,n]),x=p.useCallback(g=>{const B=Math.max(1,Math.min(g,c));l(B)},[c]),h=p.useCallback(()=>{s<c&&l(s+1)},[s,c]),b=p.useCallback(()=>{s>1&&l(s-1)},[s]),m=p.useCallback(()=>{l(1)},[]);return{paginatedData:u,currentPage:s,totalPages:c,pageSize:n,totalRows:d,goToPage:x,nextPage:h,prevPage:b,resetPage:m,hasNextPage:s<c,hasPrevPage:s>1}}function sl(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:l,searchQuery:d,columnVisibility:c,columnOrder:u,columnWidths:x,views:h,activeViewId:b,pagination:m}=t,g=p.useMemo(()=>({filters:i,sortStack:s,grouping:l,columnVisibility:c,columnOrder:u,columnWidths:x}),[i,s,l,c,u,x]),B=nl({views:h,activeViewId:b,currentState:g}),v=ol({schema:n,columnVisibility:c,columnOrder:u}),{filteredData:j}=Za({data:o,filters:i}),{sortedData:S}=tl({data:j,sortStack:s,schema:n}),{groupedData:I,isGrouped:y}=rl({data:S,grouping:l,schema:n}),{searchedData:C}=el({data:I,searchQuery:d,schema:n,visibleColumns:v.visibleColumns}),a=il({data:C,enabled:(m==null?void 0:m.enabled)||!1,pageSize:(m==null?void 0:m.pageSize)||100,initialPage:(m==null?void 0:m.currentPage)||1}),A=m!=null&&m.enabled?a.paginatedData:C,T=p.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:S.length,groupedRows:y?I.length:S.length,searchedRows:C.length,visibleRows:A.length,hiddenColumns:v.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:y}),[o.length,j.length,S.length,I.length,C.length,A.length,v.hiddenCount,i.length,s.length,y]);return{data:A,filteredData:j,sortedData:S,groupedData:I,searchedData:C,viewEngine:B,columnEngine:v,paginationEngine:a,metrics:T,isGrouped:y,isPaginated:(m==null?void 0:m.enabled)||!1}}let al=0;function ll(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:al++,writable:!1,enumerable:!1,configurable:!1})}const vt="user-demo-001";function cl(t={}){var yn,bn,vn,Sn,jn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:l,sharedReportId:d,config:c={}}=t,[u,x]=p.useState([]),h=ar(),[b,m]=p.useState(""),[g,B]=p.useState(!1),[v,j]=p.useState(!1),[S,I]=p.useState({message:"",severity:"info",open:!1}),y=(w,E="info")=>{I({message:w,severity:E,open:!0})},C=()=>I(w=>({...w,open:!1})),a=u.find(w=>w.id===b),[A,T]=p.useState("idle"),[R,G]=p.useState(!1),[X,te]=p.useState(!1),[f,_]=p.useState(!1),[W,V]=p.useState(!1),[Z,xe]=p.useState(!1),[he,L]=p.useState(!1),[$,H]=p.useState(void 0),[ne,q]=p.useState(null),[ee,le]=p.useState(null),[ie,P]=p.useState(!1),[se,ce]=p.useState(!1),[ae,ge]=p.useState(null),[K,Re]=p.useState(!1),[Ye,it]=p.useState(!1),[dr,Br]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[ut,$t]=p.useState(""),[Ne,Ee]=p.useState(new Set),[_t,Mt]=p.useState(null),[Je,Ue]=p.useState(1),[st,ur]=p.useState(15),[et,at]=p.useState(!1),[We,pr]=p.useState(!1),[Er,Ht]=p.useState(!1),[pt,Ct]=p.useState(null),[xr,wt]=p.useState(!1),[Dr,Or]=p.useState(null),[Ar,Ge]=p.useState(null);p.useRef(new La),p.useRef(new uo),p.useRef(new uo),p.useRef(new uo),p.useRef(new uo);const[mr,$r]=p.useState(null),Ut=p.useRef(null),Ce=p.useMemo(()=>a?Ca(a.permissions,vt):"owner",[a]),_r=wa(Ce),hr=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:Wa(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),lt=p.useCallback(()=>{a&&(Ut.current=Ha(a))},[a]),F=p.useCallback((w,E)=>{x(M=>M.map(O=>O.id===w?{...O,...E}:O))},[]),qe=p.useCallback(w=>{if(!a)return;$r(w);const E=On(a.id,vt,w,a.auditHistory||[]);F(a.id,{auditHistory:E}),y(w.message,"error"),w.recoverable&&Ut.current&&setTimeout(()=>{Ua(a,Ut.current,F),y("Previous state restored","success")},100)},[a,F]),we=p.useCallback((w,E,M,O)=>{if(!a)return;const Y=Di(a.id,vt,w,E,M,O),U=a.auditHistory||[],oe=Oi(U,Y);setTimeout(()=>{F(a.id,{auditHistory:oe})},0)},[a,F]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const w=Yo(a.schema);(()=>{try{const E=localStorage.getItem("urm_dev_config");return E?JSON.parse(E):null}catch{return null}})(),F(a.id,{views:[w],activeViewId:w.id,filters:w.snapshot.filters,sortStack:w.snapshot.sortStack,columnVisibility:w.snapshot.columnVisibility,columnOrder:w.snapshot.columnOrder,columnWidths:w.snapshot.columnWidths,grouping:w.snapshot.grouping})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,F]),p.useEffect(()=>{if(i&&n&&!v&&u.length===0){const w=yo(i),E={id:`auto-report-${Date.now()}`,name:l||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:w,schema:Gr(w),permissions:{owner:vt,editors:[],viewers:[]}};x([E]),m(E.id),j(!0),T("confirmed")}},[i,n,v,u.length,o,l]),p.useEffect(()=>{if(!s||v)return;let w=!1,E=null;const M=async()=>{try{T("uploading");let O;if(s.type==="api"){const U=await fetch(s.url,{headers:s.headers||{}});if(!U.ok)throw new Error(`HTTP ${U.status}: ${U.statusText}`);O=await U.json()}else O=await s.fetch();if(w)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const Y=Gr(O);if(v)x(U=>U.map(oe=>oe.id===b?{...oe,uploadedData:O}:oe)),T("confirmed");else{const U={id:`auto-report-${Date.now()}`,name:l||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:yo(O),schema:Gr(yo(O)),permissions:{owner:vt,editors:[],viewers:[]}};x([U]),m(U.id),j(!0),T("confirmed")}}catch(O){w||(T("error"),a&&F(a.id,{uploadError:(O==null?void 0:O.message)||"Failed to load data from source"}))}};return M(),s.refreshInterval&&s.refreshInterval>0&&(E=setInterval(M,s.refreshInterval)),()=>{w=!0,E&&clearInterval(E)}},[s,l,o]);const Le=(yn=a==null?void 0:a.views)==null?void 0:yn.find(w=>w.id===a.activeViewId),Mr=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(ll),a.showFavoritesOnly?!a.favoriteRowIndices||a.favoriteRowIndices.length===0?[]:a.uploadedData.filter((w,E)=>a.favoriteRowIndices.includes(E)):a.uploadedData):[],[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),Yt=p.useMemo(()=>{var E;if(!(a!=null&&a.uploadedData)||!((E=a==null?void 0:a.favoriteRowIndices)!=null&&E.length))return new Set;const w=new Set;return a.favoriteRowIndices.forEach(M=>{const O=a.uploadedData[M];O!==void 0&&w.add(O)}),w},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),xt=sl({rawData:Mr,schema:(a==null?void 0:a.schema)||[],filters:(a==null?void 0:a.filters)||[],sortStack:(a==null?void 0:a.sortStack)||[],grouping:(a==null?void 0:a.grouping)||null,searchQuery:ut||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Le==null?void 0:Le.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Le==null?void 0:Le.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Le==null?void 0:Le.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:st,currentPage:Je}}),{data:Gt=[],searchedData:qt=[],groupedData:Jt=[],metrics:Rr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Rt=!1,paginationEngine:$e}=xt||{},Q=((bn=xt.viewEngine)==null?void 0:bn.activeView)||Le,mt=((vn=xt.viewEngine)==null?void 0:vn.isDirty)||!1;p.useEffect(()=>{if(!(!Q||!a)&&!a.columnOrder){const w=Q.snapshot.columnOrder,E=Zr(w,Q.snapshot.grouping);F(a.id,{columnOrder:E})}},[a==null?void 0:a.activeViewId]);const ke=p.useMemo(()=>!(a!=null&&a.schema)||!Q?null:ua(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,Q.snapshot.columnOrder),[a==null?void 0:a.filters,a==null?void 0:a.sortStack,a==null?void 0:a.schema,a==null?void 0:a.columnVisibility,a==null?void 0:a.columnOrder,a==null?void 0:a.columnWidths,a==null?void 0:a.grouping,Q]),ye=p.useMemo(()=>!Q||!ke||!mt?[]:ma(ke,Q.snapshot),[Q,ke,mt]),tt=p.useCallback((w,E,M)=>{const O={id:`report-${Date.now()}`,name:w,description:E,schemaLocked:!1,permissions:{owner:vt,editors:[],viewers:[]}};if(M&&Array.isArray(M)&&M.length>0){const Y=Gr(M),U=Yo(Y);O.uploadedData=M,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),B(!1),T("confirmed")},[]),Kt=p.useCallback(w=>{a&&(T("uploading"),setTimeout(()=>{const E=Gr(w);F(a.id,{uploadedData:w,schema:E,uploadError:void 0}),T("preview")},500))},[a,F]),ht=p.useCallback(w=>{a&&(F(a.id,{uploadError:w}),T("idle"))},[a,F]),Ve=p.useCallback(()=>{a&&(F(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),T("idle"))},[a,F]),fr=p.useCallback(()=>{a&&(F(a.id,{schemaLocked:!0}),T("confirmed"))},[a,F]),kt=p.useCallback(w=>{if(!a)return;if(!yt("edit_sorting",Ce)){y(bt("edit_sorting"),"error");return}const E=a.sortStack??[],M=E.find(O=>O.column===w);if(M){const O=ia(M.direction);if(O===null){const Y=E.filter(U=>U.column!==w).map((U,oe)=>({...U,priority:oe+1}));F(a.id,{sortStack:Y.length>0?Y:void 0})}else{const Y=O,U=E.map(oe=>oe.column===w?{...oe,direction:Y}:oe);F(a.id,{sortStack:U})}}else{if(E.length>=h.sort.maxLevels){y(`Sort limit reached — maximum ${h.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:w,direction:"asc",priority:E.length+1};F(a.id,{sortStack:[...E,O]})}},[a,Ce,F]),ct=p.useCallback(w=>{if(a)if(a.schema){const{validRules:E,invalidColumns:M}=Ai(w,a.schema);M.length>0&&y(`Removed invalid sort columns: ${M.join(", ")}`),lt();try{F(a.id,{sortStack:E.length>0?E:void 0})}catch(O){const Y=Et("processing","sorting",O);qe(Y)}}else F(a.id,{sortStack:w.length>0?w:void 0})},[a,F,lt,qe]),Tt=p.useCallback(w=>{if(!a)return;const E=a.sortStack??[],M=E.find(O=>O.column===w);if(!(M&&M.direction==="asc"))if(M){const O=E.map(Y=>Y.column===w?{...Y,direction:"asc"}:Y);F(a.id,{sortStack:O})}else{if(E.length>=h.sort.maxLevels){y(`Sort limit reached — maximum ${h.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:w,direction:"asc",priority:E.length+1};F(a.id,{sortStack:[...E,O]})}},[a,F]),Wr=p.useCallback(w=>{if(!a)return;const E=a.sortStack??[],M=E.find(O=>O.column===w);if(!(M&&M.direction==="desc"))if(M){const O=E.map(Y=>Y.column===w?{...Y,direction:"desc"}:Y);F(a.id,{sortStack:O})}else{if(E.length>=h.sort.maxLevels){y(`Sort limit reached — maximum ${h.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:w,direction:"desc",priority:E.length+1};F(a.id,{sortStack:[...E,O]})}},[a,F]),Xt=p.useCallback(w=>{var M;if(!a)return;if(!yt("edit_filters",Ce)){y(bt("edit_filters"),"error");return}const E=(M=a.schema)==null?void 0:M.find(O=>O.name===w.column);if(E&&w.value!==void 0){const O=Ya(E.type,w.operator,w.value);if(!O.isValid){y(O.errorMessage||"Invalid filter value","error");return}}lt();try{const O=a.filters??[];we("filters","filter_added",O,[...O,w]),F(a.id,{filters:[...O,w]})}catch(O){const Y=Et("processing","filters",O);qe(Y)}},[a,Ce,F,lt,qe,we]),Zt=p.useCallback((w,E)=>{if(!a)return;if(!yt("edit_filters",Ce)){y(bt("edit_filters"),"error");return}const M=a.filters??[],O=[...M];we("filters","filter_updated",M[w],E),O[w]=E,F(a.id,{filters:O})},[a,Ce,F,we]),Wt=p.useCallback(w=>{if(!a)return;if(!yt("edit_filters",Ce)){y(bt("edit_filters"),"error");return}const E=a.filters??[],M=E.filter((O,Y)=>Y!==w);we("filters","filter_removed",E[w],null),F(a.id,{filters:M.length>0?M:void 0})},[a,Ce,F,we]),gr=p.useCallback(()=>{if(!a)return;if(!yt("edit_filters",Ce)){y(bt("edit_filters"),"error");return}const w=a.filters??[];we("filters","filter_cleared",w,null),F(a.id,{filters:void 0})},[a,Ce,F,we]),Fe=p.useCallback(w=>{if(!a)return;if(!yt("edit_filters",Ce)){y(bt("edit_filters"),"error");return}const E=a.filters??[];we("filters","filter_cleared",E,w),F(a.id,{filters:w.length>0?w:void 0})},[a,Ce,F,we]),ft=p.useCallback(w=>{var Y;if(!a)return;const E=(Y=a.views)==null?void 0:Y.find(U=>U.id===w);if(!E)return;const M=E.snapshot.columnOrder,O=Zr(M,E.snapshot.grouping);F(a.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:w}),Ee(new Set),_(!1)},[a,F]),Qt=p.useCallback((w,E,M)=>{var rr;if(!(a!=null&&a.schema)||!ke)return;const O=a.views??[],Y=O.filter(Ur=>!Ur.isDeleted).length,U=((rr=h.views)==null?void 0:rr.maxViews)??10;if(Y>=U){y(`View limit reached — you can have at most ${U} saved views. Delete an existing view to create a new one.`,"error");return}const oe={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:w,description:E||void 0,isDefault:M,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:vt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...ke}},fe=M?O.map(Ur=>({...Ur,isDefault:!1})):O;F(a.id,{views:[...fe,oe],activeViewId:oe.id}),y(`"${w}" view created`,"success")},[a,ke,F]),gt=p.useCallback(()=>{var E;if(!Q||!ke||Q.isDefault||!a)return;const w=(E=a.views)==null?void 0:E.map(M=>M.id===Q.id?{...M,snapshot:{...ke}}:M);F(a.id,{views:w}),y(`"${Q.name}" view updated`,"success")},[Q,ke,a,F]),Pr=p.useCallback(w=>{var O;if(!Q||!ke||!a)return;const E=w??ke.columnWidths,M=(O=a.views)==null?void 0:O.map(Y=>Y.id===Q.id?{...Y,snapshot:{...Y.snapshot,columnVisibility:ke.columnVisibility,columnOrder:ke.columnOrder,columnWidths:E},updatedAt:Date.now()}:Y);F(a.id,{views:M,columnWidths:E}),y(`Column configuration saved to "${Q.name}"`,"success")},[Q,ke,a,F]),Nr=p.useCallback(w=>{var U,oe;if(!ke||!a||!Q)return;const E=w??ke.columnWidths,M={...Q,snapshot:{...Q.snapshot,columnVisibility:ke.columnVisibility,columnOrder:ke.columnOrder,columnWidths:E},updatedAt:Date.now()},O=(U=a.views)==null?void 0:U.map(fe=>fe.id===Q.id?M:{...fe,snapshot:{...fe.snapshot,columnVisibility:ke.columnVisibility,columnOrder:ke.columnOrder,columnWidths:E},updatedAt:Date.now()});F(a.id,{views:O,columnWidths:E});const Y=(((oe=a.views)==null?void 0:oe.length)||0)-1;y(`Column configuration saved to current view and ${Y} other view${Y===1?"":"s"}`,"success")},[ke,a,Q,F]),Pt=p.useCallback(()=>{V(!0)},[]),Lr=p.useCallback(()=>{if(!Q||!a)return;const w=Q.snapshot.columnOrder,E=Zr(w,Q.snapshot.grouping);F(a.id,{filters:Q.snapshot.filters.length>0?[...Q.snapshot.filters]:void 0,sortStack:Q.snapshot.sortStack.length>0?[...Q.snapshot.sortStack]:void 0,columnVisibility:{...Q.snapshot.columnVisibility},columnOrder:E,columnWidths:{...Q.snapshot.columnWidths},grouping:Q.snapshot.grouping}),y("Changes reverted to last saved state","success")},[Q,a,F]),Fr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map(O=>({...O,isDefault:O.id===w}));F(a.id,{views:E});const M=a.views.find(O=>O.id===w);M&&y(`"${M.name}" set as default view`,"success")},[a,F]),er=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map(O=>O.id===w?{...O,isFavorite:!O.isFavorite,updatedAt:Date.now()}:O);F(a.id,{views:E});const M=a.views.find(O=>O.id===w);M&&!M.isFavorite?y(`"${M.name}" added to favorites`,"success"):M&&y(`"${M.name}" removed from favorites`,"info")},[a,F]),yr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map(U=>U.id===w?{...U,isDeleted:!0,updatedAt:Date.now()}:U),M=a.activeViewId===w,O=E.find(U=>U.isDefault&&!U.isDeleted);F(a.id,{views:E,activeViewId:M&&O?O.id:a.activeViewId,filters:M&&O?O.snapshot.filters.length>0?O.snapshot.filters:void 0:a.filters,sortStack:M&&O?O.snapshot.sortStack.length>0?O.snapshot.sortStack:void 0:a.sortStack});const Y=a.views.find(U=>U.id===w);Y&&y(`"${Y.name}" moved to Recently Deleted`,"info")},[a,F]),br=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map(O=>O.id===w?{...O,isDeleted:!1,updatedAt:Date.now()}:O);F(a.id,{views:E});const M=a.views.find(O=>O.id===w);M&&y(`"${M.name}" restored`,"success")},[a,F]),vr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.find(fe=>fe.id===w),M=a.views.filter(fe=>!fe.isDeleted||fe.id===w);if((E==null?void 0:E.isDefault)&&M.filter(fe=>fe.isDefault).length===1){y("Cannot delete the last default view","error");return}const Y=a.views.filter(fe=>fe.id!==w),U=a.activeViewId===w,oe=Y.find(fe=>fe.isDefault&&!fe.isDeleted);F(a.id,{views:Y,activeViewId:U&&oe?oe.id:a.activeViewId,filters:U&&oe?oe.snapshot.filters.length>0?oe.snapshot.filters:void 0:a.filters,sortStack:U&&oe?oe.snapshot.sortStack.length>0?oe.snapshot.sortStack:void 0:a.sortStack}),E&&y(`"${E.name}" permanently deleted`,"success")},[a,F]),tr=p.useCallback(w=>{q(w),xe(!0),_(!1)},[]),Sr=p.useCallback((w,E)=>{if(!ne||!(a!=null&&a.views))return;const M=a.views.map(O=>O.id===ne?{...O,name:w,description:E||void 0}:O);F(a.id,{views:M}),q(null)},[ne,a,F]),ue=p.useCallback(w=>{le(w),L(!0),_(!1)},[]),de=p.useCallback(()=>{if(!ee||!(a!=null&&a.views))return;const w=a.views.filter(O=>O.id!==ee),E=a.activeViewId===ee,M=w.find(O=>O.isDefault);F(a.id,{views:w,activeViewId:E&&M?M.id:a.activeViewId,filters:E&&M?M.snapshot.filters.length>0?M.snapshot.filters:void 0:a.filters,sortStack:E&&M?M.snapshot.sortStack.length>0?M.snapshot.sortStack:void 0:a.sortStack}),le(null),L(!1)},[ee,a,F]),Be=p.useCallback(w=>{var Y;if(!(a!=null&&a.views))return;if(!(((Y=h.views)==null?void 0:Y.isAdmin)??!1)){y("Only administrators can promote views to Global.","error");return}const M=a.views.find(U=>U.id===w);if(!M)return;if(M.scope==="global"){y(`"${M.name}" is already a Global View.`,"info");return}const O=a.views.map(U=>U.id===w?{...U,scope:"global",isDefault:!0,updatedAt:Date.now()}:U.scope==="global"&&U.isDefault?{...U,isDefault:!1}:U);F(a.id,{views:O}),y(`"${M.name}" promoted to Global View and set as default.`,"success")},[a,h,F]);p.useEffect(()=>{$e!=null&&$e.resetPage?$e.resetPage():Ue(1)},[a==null?void 0:a.filters,ut,a==null?void 0:a.activeViewId]),p.useEffect(()=>{$e&&$e.currentPage!==Je&&Ue($e.currentPage)},[$e==null?void 0:$e.currentPage]);const dt=p.useCallback(w=>{$e!=null&&$e.goToPage&&$e.goToPage(w),Ue(w)},[$e]),rt=p.useCallback(w=>{const E=(Je-1)*st,M=Math.floor(E/w)+1;ur(w),Ue(M)},[Je,st]),It=p.useCallback((w,E)=>{if(!a)return;if(!yt("edit_columns",Ce)){y(bt("edit_columns"),"error");return}const O={...a.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{},[w]:E};F(a.id,{columnVisibility:O})},[a,Q,Ce,F]),Vr=p.useCallback(w=>{if(a){if(!yt("edit_columns",Ce)){y(bt("edit_columns"),"error");return}F(a.id,{columnOrder:w})}},[a,Ce,F]),Nt=p.useCallback((w,E)=>{if(!a)return;if(!yt("edit_columns",Ce)){y(bt("edit_columns"),"error");return}const O={...a.columnWidths||(Q==null?void 0:Q.snapshot.columnWidths)||{},[w]:E};F(a.id,{columnWidths:O})},[a,Q,Ce,F]),ao=p.useCallback(w=>{if(!a)return;const M=(a.filters??[]).filter(O=>O.column!==w);F(a.id,{filters:M.length>0?M:void 0})},[a,F]),D=p.useCallback(()=>{if(!Q||!(a!=null&&a.schema))return;const w={},E=[],M={};a.schema.forEach(O=>{w[O.name]=!0,E.push(O.name),M[O.name]=170}),F(a.id,{columnVisibility:w,columnOrder:E,columnWidths:M,filters:void 0,sortStack:void 0}),y("Reset to default layout - all filters and sorts cleared","success")},[Q,a,F]),J=p.useCallback(Na(w=>{$t(w)},300),[]),me=p.useCallback(w=>{J(w)},[J]),He=p.useCallback(w=>{if(!w.trim()||!a)return;const E=a.searchHistory||[],M=ya(E,w);F(a.id,{searchHistory:M})},[a,F]),pe=p.useCallback(w=>{if(!a)return;const E=a.searchHistory||[],M=ba(E,w);F(a.id,{searchHistory:M})},[a,F]),zt=p.useCallback(w=>{if(!a)return;const E=a.searchHistory||[],M=va(E,w);F(a.id,{searchHistory:M})},[a,F]),Uo=p.useCallback(w=>{const E=w==null?void 0:w.__urm_row_id__;Ee(M=>{const O=new Set(M);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(w)}else{const Y=JSON.stringify(w),U=Array.from(O).find(oe=>JSON.stringify(oe)===Y);U!==void 0?O.delete(U):O.add(w)}return O})},[]),ds=p.useCallback((w,E)=>{Ee(M=>{const O=new Set(M);for(const Y of E)w?O.add(Y):O.delete(Y);return O})},[]),us=p.useCallback((w,E,M)=>{Ee(O=>{const Y=new Set(O),U=Math.min(w,E),oe=Math.max(w,E);for(let fe=U;fe<=oe;fe++)M[fe]!==void 0&&Y.add(M[fe]);return Y})},[]),ps=p.useCallback(()=>{Ee(new Set),Mt(null)},[]),xs=p.useCallback(w=>{const E=w==null?void 0:w.__urm_row_id__;Ee(M=>{const O=new Set(M);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(w);return O})},[]),ms=p.useCallback(w=>{if(!(a!=null&&a.uploadedData))return;const E=a.uploadedData.indexOf(w);if(E===-1)return;const M=a.favoriteRowIndices||[],Y=M.includes(E)?M.filter(U=>U!==E):[...M,E];F(a.id,{favoriteRowIndices:Y})},[a,F]),hs=p.useCallback((w,E)=>{if(!(a!=null&&a.uploadedData))return;const M=a.favoriteRowIndices||[],O=w.map(U=>a.uploadedData.indexOf(U)).filter(U=>U!==-1),Y=E?[...M,...O.filter(U=>!M.includes(U))]:M.filter(U=>!O.includes(U));F(a.id,{favoriteRowIndices:Y})},[a,F]),fs=p.useCallback(()=>{if(!a)return;const w=a.favoriteRowIndices||[],E=!a.showFavoritesOnly;if(E&&w.length===0){y("No rows marked as favorite","warning");return}if(F(a.id,{showFavoritesOnly:E}),E){if(Mt(new Set(Ne)),Ne.size>0){const M=new Set(w.map(Y=>{var U,oe;return(oe=(U=a.uploadedData)==null?void 0:U[Y])==null?void 0:oe.__urm_row_id__}).filter(Y=>Y!==void 0)),O=new Set(Array.from(Ne).filter(Y=>(Y==null?void 0:Y.__urm_row_id__)!==void 0&&M.has(Y.__urm_row_id__)));Ee(O)}y(`Showing ${w.length} favorite row${w.length===1?"":"s"}`,"info")}else{if(_t!==null){const M=new Set(Array.from(Ne).map(oe=>oe==null?void 0:oe.__urm_row_id__).filter(Boolean)),O=new Set(Array.from(_t).map(oe=>oe==null?void 0:oe.__urm_row_id__).filter(Boolean)),Y=new Set(w.map(oe=>{var fe,rr;return(rr=(fe=a.uploadedData)==null?void 0:fe[oe])==null?void 0:rr.__urm_row_id__}).filter(oe=>oe!==void 0)),U=new Set;Array.from(_t).forEach(oe=>{const fe=oe==null?void 0:oe.__urm_row_id__;if(fe===void 0)return;const rr=Y.has(fe),Ur=M.has(fe);rr&&!Ur||U.add(oe)}),Array.from(Ne).forEach(oe=>{const fe=oe==null?void 0:oe.__urm_row_id__;fe!==void 0&&(O.has(fe)||U.add(oe))}),Ee(U),Mt(null)}y("Showing all data","info")}},[a,F,Ne,_t]),gs=p.useCallback(w=>{if(a){if(!yt("edit_columns",Ce)){y(bt("edit_columns"),"error");return}if(w&&a.schema){const{validGrouping:E,invalidColumns:M}=$i(w,a.schema);M.length>0&&y(`Removed invalid grouping columns: ${M.join(", ")}`,"warning"),lt();try{const O=a.grouping;E===null?we("grouping","group_cleared",O,null):O?we("grouping","group_reordered",O,E):we("grouping","group_level_added",null,E);const Y=(Q==null?void 0:Q.snapshot.columnOrder)||a.columnOrder||[],U=Zr(Y,E);F(a.id,{grouping:E,columnOrder:U}),JSON.stringify(U)!==JSON.stringify(a.columnOrder)&&we("columns","column_reordered",a.columnOrder,U),it(!1)}catch(O){const Y=Et("processing","grouping",O);qe(Y)}}else{const E=a.grouping;we("grouping","group_cleared",E,null);const M=(Q==null?void 0:Q.snapshot.columnOrder)||a.columnOrder||[];F(a.id,{grouping:w,columnOrder:[...M]}),JSON.stringify(M)!==JSON.stringify(a.columnOrder)&&we("columns","column_reordered",a.columnOrder,M),it(!1)}}},[a,Q,Ce,F,lt,qe,we]),ys=p.useCallback(w=>{if(!a)return;const E=a.grouping;if(!E)return;const M=da(E,w);F(a.id,{grouping:M})},[a,F]),bs=p.useCallback(()=>{wt(!0)},[]),Hr=p.useCallback(w=>{a!=null&&a.schema&&(P(!0),setTimeout(()=>{try{let E;w.scope==="visible"?E=qt:E=a.uploadedData||[];let M;w.columnScope==="all"?(M={},(a.schema??[]).forEach(fe=>{M[fe.name]=!0})):M=a.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{};const O=a.columnOrder||(Q==null?void 0:Q.snapshot.columnOrder),Y=jo(E,a.schema,a.filters??[],a.sortStack??[],Q,M,O),U=a.name;let oe;switch(w.format){case"csv":Co(Y,U,w),oe="export_csv";break;case"excel":wo(Y,U,w),oe="export_excel";break;case"json":ko(Y,U,w),oe="export_json";break}we("export",oe,null,{format:w.format,scope:w.scope,columnScope:w.columnScope,rowCount:E.length,viewName:(Q==null?void 0:Q.name)||"Default View"}),y(`Export completed successfully (${w.format.toUpperCase()})`,"success")}catch(E){const M=qa(E,{onRetry:()=>Hr(w)});y(`Export failed: ${M.message}. Click Export to retry.`,"error");const O=On(a.id,vt,M,a.auditHistory||[]);F(a.id,{auditHistory:O}),ir.error("urm:report-engine","Export failed",E)}finally{P(!1)}},500))},[a,Q,qt,F,we]),vs=p.useCallback(w=>{if(a!=null&&a.schema){if(mt&&Q&&!Q.isDefault){ge(w.format),ce(!0),wt(!1);return}Hr(w),wt(!1)}},[a,Q,mt,Hr]),lo=p.useCallback(w=>{Hr({format:w,scope:"visible",columnScope:"visible"})},[Hr]),Ss=p.useCallback(()=>{ae&&lo(ae),ce(!1),ge(null)},[ae,lo]),js=p.useCallback(()=>{gt(),ae&&lo(ae),ce(!1),ge(null)},[gt,ae,lo]),Cs=p.useCallback(()=>{ce(!1),ge(null)},[]),ws=p.useCallback(w=>{!(a!=null&&a.schema)||Ne.size===0||(P(!0),setTimeout(()=>{try{const E=Array.from(Ne),M=jo(E,a.schema,a.filters??[],a.sortStack??[],Q),O=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(w){case"csv":Co(M,O);break;case"excel":wo(M,O);break;case"json":ko(M,O);break}y(`Exported ${E.length} selected rows`,"info")}catch(E){y("Export failed. Please try again.","error"),ir.error("urm:report-engine","Bulk export failed",E)}finally{P(!1)}},500))},[a,Q,Ne,Jt]),ks=p.useCallback((w,E)=>{if(a)try{const M=Oa(a),O=Aa(w,E,vt,M),Y=$a(a.presets,O);F(a.id,{presets:Y}),we("presets","preset_created",null,{presetId:O.id,name:O.name}),pr(!1),y(`Preset "${w}" saved successfully`,"success")}catch(M){y(M instanceof Error?M.message:"Failed to create preset","error")}},[a,F,we]),Ts=p.useCallback(()=>{Ct(null),y("Exited preset view","info")},[]),Is=p.useCallback(()=>{Ht(!0)},[]),zs=p.useCallback((w,E)=>{if(!a)return;const M=_a(a.presets,w);F(a.id,{presets:M}),we("presets","preset_deleted",{presetId:w,name:E},null),pt===w&&Ct(null),y(`Preset "${E}" deleted`,"success")},[a,pt,F,we]);p.useEffect(()=>{if(!d||u.length===0)return;const w=u.find(E=>E.id===d);w&&w.id!==b&&m(w.id)},[d,u,b]),p.useEffect(()=>{if(!a)return;const w=Ma();if(w&&a.presets&&a.schemaLocked&&a.schema){const E=Dn(a.presets,w);if(E){const{sanitizedConfig:M,warnings:O}=Ga(E.config,a.schema);O.length>0&&O.forEach(U=>y(U,"warning"));const Y=Ra(M);F(a.id,Y),Ct(w),we("presets","preset_applied",null,{presetId:E.id,name:E.name}),y(`Loaded preset: ${E.name}`,"info")}else y("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const Bs=pt?Dn(a==null?void 0:a.presets,pt):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&ha(a.id,{views:a.views,activeViewId:a.activeViewId})},[a==null?void 0:a.views,a==null?void 0:a.activeViewId,a==null?void 0:a.id]),p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const w=fa(a.id);if(w&&w.views.length>0){const E=w.views.find(M=>M.id===w.activeViewId);if(E)F(a.id,{views:w.views,activeViewId:w.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 M=w.views.find(O=>O.isDefault)||Yo(a.schema);F(a.id,{views:w.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})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const Es=p.useCallback(w=>{var O;const E=(a==null?void 0:a.filters)??[],M=((O=h.filter)==null?void 0:O.maxConditions)??3;if(E.length>=M){y(`Filter limit reached — maximum ${M} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}H(w),G(!0)},[a,h,y]),Ds=p.useCallback(()=>{G(!1),H(void 0)},[]),Os=(Sn=a==null?void 0:a.views)==null?void 0:Sn.find(w=>w.id===ne),As=(jn=a==null?void 0:a.views)==null?void 0:jn.find(w=>w.id===ee);return{reports:u,activeReport:a,activeReportId:b,setActiveReportId:m,isModalOpen:g,setIsModalOpen:B,createReport:tt,updateReport:F,uploadState:A,handleFileUpload:Kt,handleUploadError:ht,handleRetry:Ve,handleConfirm:fr,paginatedData:Gt,processedData:qt,displayData:Jt,tableMetrics:Rr,isGrouped:Rt,tableEngine:xt,activeView:Q,isDirty:mt,currentTableState:ke,viewChanges:ye,filters:a==null?void 0:a.filters,showFilterPanel:R,setShowFilterPanel:G,filterFocusColumn:$,handleAddFilter:Xt,handleUpdateFilter:Zt,handleRemoveFilter:Wt,handleClearAllFilters:gr,handleReplaceFilters:Fe,handleOpenFilterForColumn:Es,handleCloseFilterPanel:Ds,handleClearFiltersForColumn:ao,sortStack:a==null?void 0:a.sortStack,showSortPanel:X,setShowSortPanel:te,handleSort:kt,handleUpdateSortStack:ct,handleSortAscending:Tt,handleSortDescending:Wr,views:a==null?void 0:a.views,showManageViews:f,setShowManageViews:_,showCreateViewModal:W,setShowCreateViewModal:V,showEditViewModal:Z,setShowEditViewModal:xe,showDeleteConfirmation:he,setShowDeleteConfirmation:L,editingView:Os,deletingView:As,editingViewId:ne,deletingViewId:ee,handleSelectView:ft,handleCreateView:Qt,handleUpdateCurrentView:gt,handleSaveColumnConfigToCurrentView:Pr,handleSaveColumnConfigToAllViews:Nr,handleSaveAsNewView:Pt,handleRevertChanges:Lr,handleToggleDefault:Fr,handleToggleFavorite:er,handleSoftDelete:yr,handleRestoreView:br,handlePermanentDelete:vr,handleEditView:tr,handleSaveEditView:Sr,handleDeleteView:ue,handleConfirmDelete:de,handlePromoteToGlobal:Be,showManageColumns:K,setShowManageColumns:Re,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:It,handleUpdateColumnOrder:Vr,handleUpdateColumnWidth:Nt,handleResetColumnLayout:D,showGroupPanel:Ye,setShowGroupPanel:it,grouping:a==null?void 0:a.grouping,groupingState:dr,handleGroup:gs,handleToggleGroupCollapse:ys,searchQuery:ut,searchHistory:Sa((a==null?void 0:a.searchHistory)||[]),handleSearchChange:me,handleAddToSearchHistory:He,handleToggleSearchFavourite:pe,handleDeleteSearchHistory:zt,selectedRowIds:Ne,handleToggleRowSelection:Uo,handleToggleAllRows:ds,handleRangeSelection:us,handleClearSelection:ps,handleUpdateSelectionAfterDelete:xs,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:Yt,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:ms,handleBulkSetFavorites:hs,handleToggleFavoritesFilter:fs,currentPage:Je,pageSize:st,paginationEngine:$e,handlePageChange:dt,handlePageSizeChange:rt,isExporting:ie,showExportModal:xr,setShowExportModal:wt,showDirtyExportWarning:se,handleExport:bs,handleExportWithConfig:vs,handleExportSelected:ws,handleExportAnyway:Ss,handleSaveAndExport:js,handleCancelExport:Cs,showAuditHistory:et,setShowAuditHistory:at,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:We,setShowCreatePreset:pr,showManagePresets:Er,setShowManagePresets:Ht,activePreset:Bs,activePresetId:pt,handleOpenManagePresets:Is,handleCreatePreset:ks,handleClearActivePreset:Ts,handleDeletePresetById:zs,userRole:Ce,isViewerRole:_r,currentUserId:vt,featureLimitWarning:Ar,setFeatureLimitWarning:Ge,datasetMeta:hr,reportError:mr,setReportError:$r,handleError:qe,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?ra(a.schema):!1,snack:S,handleSnackClose:C,showSnack:y}}const _i=p.createContext(void 0);function un(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:l,mode:d="builder",autoLoad:c=!0,config:u,devConfig:x,showDevPanel:h=!1,sharedReportId:b}=t,g=cl({mode:d,autoLoad:c,initialData:i||n,dataSource:l,reportName:s,sharedReportId:b,config:u}),[B,v]=p.useState(()=>Ws()),j=(()=>{const C=Ns(B,x,!!x);return{...C,display:{...C.display,showDevPanel:h||C.display.showDevPanel}}})(),S=p.useCallback(y=>{v(y),Ps(y)},[]),I={...g,activeDevConfig:j,handleDevConfigChange:S};return e.jsx(ji.Provider,{value:j,children:e.jsx(_i.Provider,{value:I,children:o})})}function Eo(){const t=p.useContext(_i);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function dl({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const s=o.find(l=>l.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(z.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",color:"text.primary",letterSpacing:"-0.01em",cursor:o.length>0&&s?"pointer":"default","&:hover":o.length>0&&s?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),s&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(s.id),children:s.name}),e.jsx(r.Tooltip,{title:s.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(z.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(z.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function sr(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 ul="$$material";function pl(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var xo={exports:{}},mo={exports:{}},be={};/** @license React v16.13.1
4
4
  * react-is.production.min.js
5
5
  *
6
6
  * Copyright (c) Facebook, Inc. and its affiliates.
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */var $n;function xl(){if($n)return ye;$n=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,x=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,m=t?Symbol.for("react.suspense_list"):60120,y=t?Symbol.for("react.memo"):60115,B=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,I=t?Symbol.for("react.scope"):60119;function f(s){if(typeof s=="object"&&s!==null){var $=s.$$typeof;switch($){case o:switch(s=s.type,s){case u:case x:case i:case c:case a:case b:return s;default:switch(s=s&&s.$$typeof,s){case l:case h:case B:case y:case d:return s;default:return $}}case n:return $}}}function w(s){return f(s)===x}return ye.AsyncMode=u,ye.ConcurrentMode=x,ye.ContextConsumer=l,ye.ContextProvider=d,ye.Element=o,ye.ForwardRef=h,ye.Fragment=i,ye.Lazy=B,ye.Memo=y,ye.Portal=n,ye.Profiler=c,ye.StrictMode=a,ye.Suspense=b,ye.isAsyncMode=function(s){return w(s)||f(s)===u},ye.isConcurrentMode=w,ye.isContextConsumer=function(s){return f(s)===l},ye.isContextProvider=function(s){return f(s)===d},ye.isElement=function(s){return typeof s=="object"&&s!==null&&s.$$typeof===o},ye.isForwardRef=function(s){return f(s)===h},ye.isFragment=function(s){return f(s)===i},ye.isLazy=function(s){return f(s)===B},ye.isMemo=function(s){return f(s)===y},ye.isPortal=function(s){return f(s)===n},ye.isProfiler=function(s){return f(s)===c},ye.isStrictMode=function(s){return f(s)===a},ye.isSuspense=function(s){return f(s)===b},ye.isValidElementType=function(s){return typeof s=="string"||typeof s=="function"||s===i||s===x||s===c||s===a||s===b||s===m||typeof s=="object"&&s!==null&&(s.$$typeof===B||s.$$typeof===y||s.$$typeof===d||s.$$typeof===l||s.$$typeof===h||s.$$typeof===j||s.$$typeof===S||s.$$typeof===I||s.$$typeof===v)},ye.typeOf=f,ye}var be={};/** @license React v16.13.1
10
+ */var $n;function xl(){if($n)return be;$n=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,s=t?Symbol.for("react.strict_mode"):60108,l=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,c=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,x=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,m=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,B=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,I=t?Symbol.for("react.scope"):60119;function y(a){if(typeof a=="object"&&a!==null){var A=a.$$typeof;switch(A){case o:switch(a=a.type,a){case u:case x:case i:case l:case s:case b:return a;default:switch(a=a&&a.$$typeof,a){case c:case h:case B:case g:case d:return a;default:return A}}case n:return A}}}function C(a){return y(a)===x}return be.AsyncMode=u,be.ConcurrentMode=x,be.ContextConsumer=c,be.ContextProvider=d,be.Element=o,be.ForwardRef=h,be.Fragment=i,be.Lazy=B,be.Memo=g,be.Portal=n,be.Profiler=l,be.StrictMode=s,be.Suspense=b,be.isAsyncMode=function(a){return C(a)||y(a)===u},be.isConcurrentMode=C,be.isContextConsumer=function(a){return y(a)===c},be.isContextProvider=function(a){return y(a)===d},be.isElement=function(a){return typeof a=="object"&&a!==null&&a.$$typeof===o},be.isForwardRef=function(a){return y(a)===h},be.isFragment=function(a){return y(a)===i},be.isLazy=function(a){return y(a)===B},be.isMemo=function(a){return y(a)===g},be.isPortal=function(a){return y(a)===n},be.isProfiler=function(a){return y(a)===l},be.isStrictMode=function(a){return y(a)===s},be.isSuspense=function(a){return y(a)===b},be.isValidElementType=function(a){return typeof a=="string"||typeof a=="function"||a===i||a===x||a===l||a===s||a===b||a===m||typeof a=="object"&&a!==null&&(a.$$typeof===B||a.$$typeof===g||a.$$typeof===d||a.$$typeof===c||a.$$typeof===h||a.$$typeof===j||a.$$typeof===S||a.$$typeof===I||a.$$typeof===v)},be.typeOf=y,be}var ve={};/** @license React v16.13.1
11
11
  * react-is.development.js
12
12
  *
13
13
  * Copyright (c) Facebook, Inc. and its affiliates.
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var _n;function ml(){return _n||(_n=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,x=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,m=t?Symbol.for("react.suspense_list"):60120,y=t?Symbol.for("react.memo"):60115,B=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,I=t?Symbol.for("react.scope"):60119;function f(K){return typeof K=="string"||typeof K=="function"||K===i||K===x||K===c||K===a||K===b||K===m||typeof K=="object"&&K!==null&&(K.$$typeof===B||K.$$typeof===y||K.$$typeof===d||K.$$typeof===l||K.$$typeof===h||K.$$typeof===j||K.$$typeof===S||K.$$typeof===I||K.$$typeof===v)}function w(K){if(typeof K=="object"&&K!==null){var _e=K.$$typeof;switch(_e){case o:var Ye=K.type;switch(Ye){case u:case x:case i:case c:case a:case b:return Ye;default:var it=Ye&&Ye.$$typeof;switch(it){case l:case h:case B:case y:case d:return it;default:return _e}}case n:return _e}}}var s=u,$=x,T=l,R=d,q=o,X=h,te=i,g=B,_=y,W=n,V=c,Z=a,xe=b,me=!1;function F(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)===x}function H(K){return w(K)===l}function ne(K){return w(K)===d}function J(K){return typeof K=="object"&&K!==null&&K.$$typeof===o}function ee(K){return w(K)===h}function le(K){return w(K)===i}function ie(K){return w(K)===B}function P(K){return w(K)===y}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=T,be.ContextProvider=R,be.Element=q,be.ForwardRef=X,be.Fragment=te,be.Lazy=g,be.Memo=_,be.Portal=W,be.Profiler=V,be.StrictMode=Z,be.Suspense=xe,be.isAsyncMode=F,be.isConcurrentMode=A,be.isContextConsumer=H,be.isContextProvider=ne,be.isElement=J,be.isForwardRef=ee,be.isFragment=le,be.isLazy=ie,be.isMemo=P,be.isPortal=se,be.isProfiler=ce,be.isStrictMode=ae,be.isSuspense=ge,be.isValidElementType=f,be.typeOf=w})()),be}var Mn;function Mi(){return Mn||(Mn=1,process.env.NODE_ENV==="production"?mo.exports=xl():mo.exports=ml()),mo.exports}/*
17
+ */var _n;function ml(){return _n||(_n=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,s=t?Symbol.for("react.strict_mode"):60108,l=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,c=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,x=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,m=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,B=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,I=t?Symbol.for("react.scope"):60119;function y(K){return typeof K=="string"||typeof K=="function"||K===i||K===x||K===l||K===s||K===b||K===m||typeof K=="object"&&K!==null&&(K.$$typeof===B||K.$$typeof===g||K.$$typeof===d||K.$$typeof===c||K.$$typeof===h||K.$$typeof===j||K.$$typeof===S||K.$$typeof===I||K.$$typeof===v)}function C(K){if(typeof K=="object"&&K!==null){var Re=K.$$typeof;switch(Re){case o:var Ye=K.type;switch(Ye){case u:case x:case i:case l:case s:case b:return Ye;default:var it=Ye&&Ye.$$typeof;switch(it){case c:case h:case B:case g:case d:return it;default:return Re}}case n:return Re}}}var a=u,A=x,T=c,R=d,G=o,X=h,te=i,f=B,_=g,W=n,V=l,Z=s,xe=b,he=!1;function L(K){return he||(he=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),$(K)||C(K)===u}function $(K){return C(K)===x}function H(K){return C(K)===c}function ne(K){return C(K)===d}function q(K){return typeof K=="object"&&K!==null&&K.$$typeof===o}function ee(K){return C(K)===h}function le(K){return C(K)===i}function ie(K){return C(K)===B}function P(K){return C(K)===g}function se(K){return C(K)===n}function ce(K){return C(K)===l}function ae(K){return C(K)===s}function ge(K){return C(K)===b}ve.AsyncMode=a,ve.ConcurrentMode=A,ve.ContextConsumer=T,ve.ContextProvider=R,ve.Element=G,ve.ForwardRef=X,ve.Fragment=te,ve.Lazy=f,ve.Memo=_,ve.Portal=W,ve.Profiler=V,ve.StrictMode=Z,ve.Suspense=xe,ve.isAsyncMode=L,ve.isConcurrentMode=$,ve.isContextConsumer=H,ve.isContextProvider=ne,ve.isElement=q,ve.isForwardRef=ee,ve.isFragment=le,ve.isLazy=ie,ve.isMemo=P,ve.isPortal=se,ve.isProfiler=ce,ve.isStrictMode=ae,ve.isSuspense=ge,ve.isValidElementType=y,ve.typeOf=C})()),ve}var Mn;function Mi(){return Mn||(Mn=1,process.env.NODE_ENV==="production"?mo.exports=xl():mo.exports=ml()),mo.exports}/*
18
18
  object-assign
19
19
  (c) Sindre Sorhus
20
20
  @license MIT
21
- */var qo,Rn;function hl(){if(Rn)return qo;Rn=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(h){return d[h]});if(u.join("")!=="0123456789")return!1;var x={};return"abcdefghijklmnopqrst".split("").forEach(function(h){x[h]=h}),Object.keys(Object.assign({},x)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return qo=a()?Object.assign:function(c,d){for(var l,u=i(c),x,h=1;h<arguments.length;h++){l=Object(arguments[h]);for(var b in l)o.call(l,b)&&(u[b]=l[b]);if(t){x=t(l);for(var m=0;m<x.length;m++)n.call(l,x[m])&&(u[x[m]]=l[x[m]])}}return u},qo}var Jo,Wn;function pn(){if(Wn)return Jo;Wn=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Jo=t,Jo}var Ko,Pn;function Ri(){return Pn||(Pn=1,Ko=Function.call.bind(Object.prototype.hasOwnProperty)),Ko}var Xo,Nn;function fl(){if(Nn)return Xo;Nn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=pn(),n={},i=Ri();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,x){if(process.env.NODE_ENV!=="production"){for(var h in c)if(i(c,h)){var b;try{if(typeof c[h]!="function"){var m=Error((u||"React class")+": "+l+" type `"+h+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof c[h]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw m.name="Invariant Violation",m}b=c[h](d,h,u,l,null,o)}catch(B){b=B}if(b&&!(b instanceof Error)&&t((u||"React class")+": type specification of "+l+" `"+h+"` 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 y=x?x():"";t("Failed "+l+" type: "+b.message+(y??""))}}}}return a.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Xo=a,Xo}var Zo,Ln;function gl(){if(Ln)return Zo;Ln=1;var t=Mi(),o=hl(),n=pn(),i=Ri(),a=fl(),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 Zo=function(l,u){var x=typeof Symbol=="function"&&Symbol.iterator,h="@@iterator";function b(A){var H=A&&(x&&A[x]||A[h]);if(typeof H=="function")return H}var m="<<anonymous>>",y={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:I(),arrayOf:f,element:w(),elementType:s(),instanceOf:$,node:X(),objectOf:R,oneOf:T,oneOfType:q,shape:g,exact:_};function B(A,H){return A===H?A!==0||1/A===1/H:A!==A&&H!==H}function v(A,H){this.message=A,this.data=H&&typeof H=="object"?H:{},this.stack=""}v.prototype=Error.prototype;function j(A){if(process.env.NODE_ENV!=="production")var H={},ne=0;function J(le,ie,P,se,ce,ae,ge){if(se=se||m,ae=ae||P,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 _e=se+":"+P;!H[_e]&&ne<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."),H[_e]=!0,ne++)}}return ie[P]==null?le?ie[P]===null?new v("The "+ce+" `"+ae+"` is marked as required "+("in `"+se+"`, but its value is `null`.")):new v("The "+ce+" `"+ae+"` is marked as required in "+("`"+se+"`, but its value is `undefined`.")):null:A(ie,P,se,ce,ae)}var ee=J.bind(null,!1);return ee.isRequired=J.bind(null,!0),ee}function S(A){function H(ne,J,ee,le,ie,P){var se=ne[J],ce=Z(se);if(ce!==A){var ae=xe(se);return new v("Invalid "+le+" `"+ie+"` of type "+("`"+ae+"` supplied to `"+ee+"`, expected ")+("`"+A+"`."),{expectedType:A})}return null}return j(H)}function I(){return j(d)}function f(A){function H(ne,J,ee,le,ie){if(typeof A!="function")return new v("Property `"+ie+"` of component `"+ee+"` has invalid PropType notation inside arrayOf.");var P=ne[J];if(!Array.isArray(P)){var se=Z(P);return new v("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected an array."))}for(var ce=0;ce<P.length;ce++){var ae=A(P,ce,ee,le,ie+"["+ce+"]",n);if(ae instanceof Error)return ae}return null}return j(H)}function w(){function A(H,ne,J,ee,le){var ie=H[ne];if(!l(ie)){var P=Z(ie);return new v("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+J+"`, expected a single ReactElement."))}return null}return j(A)}function s(){function A(H,ne,J,ee,le){var ie=H[ne];if(!t.isValidElementType(ie)){var P=Z(ie);return new v("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+J+"`, expected a single ReactElement type."))}return null}return j(A)}function $(A){function H(ne,J,ee,le,ie){if(!(ne[J]instanceof A)){var P=A.name||m,se=F(ne[J]);return new v("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected ")+("instance of `"+P+"`."))}return null}return j(H)}function T(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 H(ne,J,ee,le,ie){for(var P=ne[J],se=0;se<A.length;se++)if(B(P,A[se]))return null;var ce=JSON.stringify(A,function(ge,K){var _e=xe(K);return _e==="symbol"?String(K):K});return new v("Invalid "+le+" `"+ie+"` of value `"+String(P)+"` "+("supplied to `"+ee+"`, expected one of "+ce+"."))}return j(H)}function R(A){function H(ne,J,ee,le,ie){if(typeof A!="function")return new v("Property `"+ie+"` of component `"+ee+"` has invalid PropType notation inside objectOf.");var P=ne[J],se=Z(P);if(se!=="object")return new v("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected an object."));for(var ce in P)if(i(P,ce)){var ae=A(P,ce,ee,le,ie+"."+ce,n);if(ae instanceof Error)return ae}return null}return j(H)}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 H=0;H<A.length;H++){var ne=A[H];if(typeof ne!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+me(ne)+" at index "+H+"."),d}function J(ee,le,ie,P,se){for(var ce=[],ae=0;ae<A.length;ae++){var ge=A[ae],K=ge(ee,le,ie,P,se,n);if(K==null)return null;K.data&&i(K.data,"expectedType")&&ce.push(K.data.expectedType)}var _e=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new v("Invalid "+P+" `"+se+"` supplied to "+("`"+ie+"`"+_e+"."))}return j(J)}function X(){function A(H,ne,J,ee,le){return W(H[ne])?null:new v("Invalid "+ee+" `"+le+"` supplied to "+("`"+J+"`, expected a ReactNode."))}return j(A)}function te(A,H,ne,J,ee){return new v((A||"React class")+": "+H+" type `"+ne+"."+J+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ee+"`.")}function g(A){function H(ne,J,ee,le,ie){var P=ne[J],se=Z(P);if(se!=="object")return new v("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(P,ce,ee,le,ie+"."+ce,n);if(ge)return ge}return null}return j(H)}function _(A){function H(ne,J,ee,le,ie){var P=ne[J],se=Z(P);if(se!=="object")return new v("Invalid "+le+" `"+ie+"` of type `"+se+"` "+("supplied to `"+ee+"`, expected `object`."));var ce=o({},ne[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 v("Invalid "+le+" `"+ie+"` key `"+ae+"` supplied to `"+ee+"`.\nBad object: "+JSON.stringify(ne[J],null," ")+`
22
- Valid keys: `+JSON.stringify(Object.keys(A),null," "));var K=ge(P,ae,ee,le,ie+"."+ae,n);if(K)return K}return null}return j(H)}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 H=b(A);if(H){var ne=H.call(A),J;if(H!==A.entries){for(;!(J=ne.next()).done;)if(!W(J.value))return!1}else for(;!(J=ne.next()).done;){var ee=J.value;if(ee&&!W(ee[1]))return!1}}else return!1;return!0;default:return!1}}function V(A,H){return A==="symbol"?!0:H?H["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&H instanceof Symbol:!1}function Z(A){var H=typeof A;return Array.isArray(A)?"array":A instanceof RegExp?"object":V(H,A)?"symbol":H}function xe(A){if(typeof A>"u"||A===null)return""+A;var H=Z(A);if(H==="object"){if(A instanceof Date)return"date";if(A instanceof RegExp)return"regexp"}return H}function me(A){var H=xe(A);switch(H){case"array":case"object":return"an "+H;case"boolean":case"date":case"regexp":return"a "+H;default:return H}}function F(A){return!A.constructor||!A.constructor.name?m:A.constructor.name}return y.checkPropTypes=a,y.resetWarningCache=a.resetWarningCache,y.PropTypes=y,y},Zo}var Qo,Fn;function yl(){if(Fn)return Qo;Fn=1;var t=pn();function o(){}function n(){}return n.resetWarningCache=o,Qo=function(){function i(d,l,u,x,h,b){if(b!==t){var m=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 m.name="Invariant Violation",m}}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},Qo}var Vn;function bl(){if(Vn)return xo.exports;if(Vn=1,process.env.NODE_ENV!=="production"){var t=Mi(),o=!0;xo.exports=gl()(t.isElement,o)}else xo.exports=yl()();return xo.exports}var vl=bl();const qr=pl(vl);var ho={exports:{}},Te={};/**
21
+ */var qo,Rn;function hl(){if(Rn)return qo;Rn=1;var t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(l){if(l==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(l)}function s(){try{if(!Object.assign)return!1;var l=new String("abc");if(l[5]="de",Object.getOwnPropertyNames(l)[0]==="5")return!1;for(var d={},c=0;c<10;c++)d["_"+String.fromCharCode(c)]=c;var u=Object.getOwnPropertyNames(d).map(function(h){return d[h]});if(u.join("")!=="0123456789")return!1;var x={};return"abcdefghijklmnopqrst".split("").forEach(function(h){x[h]=h}),Object.keys(Object.assign({},x)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return qo=s()?Object.assign:function(l,d){for(var c,u=i(l),x,h=1;h<arguments.length;h++){c=Object(arguments[h]);for(var b in c)o.call(c,b)&&(u[b]=c[b]);if(t){x=t(c);for(var m=0;m<x.length;m++)n.call(c,x[m])&&(u[x[m]]=c[x[m]])}}return u},qo}var Jo,Wn;function pn(){if(Wn)return Jo;Wn=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Jo=t,Jo}var Ko,Pn;function Ri(){return Pn||(Pn=1,Ko=Function.call.bind(Object.prototype.hasOwnProperty)),Ko}var Xo,Nn;function fl(){if(Nn)return Xo;Nn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=pn(),n={},i=Ri();t=function(l){var d="Warning: "+l;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function s(l,d,c,u,x){if(process.env.NODE_ENV!=="production"){for(var h in l)if(i(l,h)){var b;try{if(typeof l[h]!="function"){var m=Error((u||"React class")+": "+c+" type `"+h+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof l[h]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw m.name="Invariant Violation",m}b=l[h](d,h,u,c,null,o)}catch(B){b=B}if(b&&!(b instanceof Error)&&t((u||"React class")+": type specification of "+c+" `"+h+"` 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=x?x():"";t("Failed "+c+" type: "+b.message+(g??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Xo=s,Xo}var Zo,Ln;function gl(){if(Ln)return Zo;Ln=1;var t=Mi(),o=hl(),n=pn(),i=Ri(),s=fl(),l=function(){};process.env.NODE_ENV!=="production"&&(l=function(c){var u="Warning: "+c;typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}});function d(){return null}return Zo=function(c,u){var x=typeof Symbol=="function"&&Symbol.iterator,h="@@iterator";function b($){var H=$&&(x&&$[x]||$[h]);if(typeof H=="function")return H}var m="<<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:I(),arrayOf:y,element:C(),elementType:a(),instanceOf:A,node:X(),objectOf:R,oneOf:T,oneOfType:G,shape:f,exact:_};function B($,H){return $===H?$!==0||1/$===1/H:$!==$&&H!==H}function v($,H){this.message=$,this.data=H&&typeof H=="object"?H:{},this.stack=""}v.prototype=Error.prototype;function j($){if(process.env.NODE_ENV!=="production")var H={},ne=0;function q(le,ie,P,se,ce,ae,ge){if(se=se||m,ae=ae||P,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 Re=se+":"+P;!H[Re]&&ne<3&&(l("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."),H[Re]=!0,ne++)}}return ie[P]==null?le?ie[P]===null?new v("The "+ce+" `"+ae+"` is marked as required "+("in `"+se+"`, but its value is `null`.")):new v("The "+ce+" `"+ae+"` is marked as required in "+("`"+se+"`, but its value is `undefined`.")):null:$(ie,P,se,ce,ae)}var ee=q.bind(null,!1);return ee.isRequired=q.bind(null,!0),ee}function S($){function H(ne,q,ee,le,ie,P){var se=ne[q],ce=Z(se);if(ce!==$){var ae=xe(se);return new v("Invalid "+le+" `"+ie+"` of type "+("`"+ae+"` supplied to `"+ee+"`, expected ")+("`"+$+"`."),{expectedType:$})}return null}return j(H)}function I(){return j(d)}function y($){function H(ne,q,ee,le,ie){if(typeof $!="function")return new v("Property `"+ie+"` of component `"+ee+"` has invalid PropType notation inside arrayOf.");var P=ne[q];if(!Array.isArray(P)){var se=Z(P);return new v("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected an array."))}for(var ce=0;ce<P.length;ce++){var ae=$(P,ce,ee,le,ie+"["+ce+"]",n);if(ae instanceof Error)return ae}return null}return j(H)}function C(){function $(H,ne,q,ee,le){var ie=H[ne];if(!c(ie)){var P=Z(ie);return new v("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+q+"`, expected a single ReactElement."))}return null}return j($)}function a(){function $(H,ne,q,ee,le){var ie=H[ne];if(!t.isValidElementType(ie)){var P=Z(ie);return new v("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+q+"`, expected a single ReactElement type."))}return null}return j($)}function A($){function H(ne,q,ee,le,ie){if(!(ne[q]instanceof $)){var P=$.name||m,se=L(ne[q]);return new v("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected ")+("instance of `"+P+"`."))}return null}return j(H)}function T($){if(!Array.isArray($))return process.env.NODE_ENV!=="production"&&(arguments.length>1?l("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):l("Invalid argument supplied to oneOf, expected an array.")),d;function H(ne,q,ee,le,ie){for(var P=ne[q],se=0;se<$.length;se++)if(B(P,$[se]))return null;var ce=JSON.stringify($,function(ge,K){var Re=xe(K);return Re==="symbol"?String(K):K});return new v("Invalid "+le+" `"+ie+"` of value `"+String(P)+"` "+("supplied to `"+ee+"`, expected one of "+ce+"."))}return j(H)}function R($){function H(ne,q,ee,le,ie){if(typeof $!="function")return new v("Property `"+ie+"` of component `"+ee+"` has invalid PropType notation inside objectOf.");var P=ne[q],se=Z(P);if(se!=="object")return new v("Invalid "+le+" `"+ie+"` of type "+("`"+se+"` supplied to `"+ee+"`, expected an object."));for(var ce in P)if(i(P,ce)){var ae=$(P,ce,ee,le,ie+"."+ce,n);if(ae instanceof Error)return ae}return null}return j(H)}function G($){if(!Array.isArray($))return process.env.NODE_ENV!=="production"&&l("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var H=0;H<$.length;H++){var ne=$[H];if(typeof ne!="function")return l("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+he(ne)+" at index "+H+"."),d}function q(ee,le,ie,P,se){for(var ce=[],ae=0;ae<$.length;ae++){var ge=$[ae],K=ge(ee,le,ie,P,se,n);if(K==null)return null;K.data&&i(K.data,"expectedType")&&ce.push(K.data.expectedType)}var Re=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new v("Invalid "+P+" `"+se+"` supplied to "+("`"+ie+"`"+Re+"."))}return j(q)}function X(){function $(H,ne,q,ee,le){return W(H[ne])?null:new v("Invalid "+ee+" `"+le+"` supplied to "+("`"+q+"`, expected a ReactNode."))}return j($)}function te($,H,ne,q,ee){return new v(($||"React class")+": "+H+" type `"+ne+"."+q+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ee+"`.")}function f($){function H(ne,q,ee,le,ie){var P=ne[q],se=Z(P);if(se!=="object")return new v("Invalid "+le+" `"+ie+"` of type `"+se+"` "+("supplied to `"+ee+"`, expected `object`."));for(var ce in $){var ae=$[ce];if(typeof ae!="function")return te(ee,le,ie,ce,xe(ae));var ge=ae(P,ce,ee,le,ie+"."+ce,n);if(ge)return ge}return null}return j(H)}function _($){function H(ne,q,ee,le,ie){var P=ne[q],se=Z(P);if(se!=="object")return new v("Invalid "+le+" `"+ie+"` of type `"+se+"` "+("supplied to `"+ee+"`, expected `object`."));var ce=o({},ne[q],$);for(var ae in ce){var ge=$[ae];if(i($,ae)&&typeof ge!="function")return te(ee,le,ie,ae,xe(ge));if(!ge)return new v("Invalid "+le+" `"+ie+"` key `"+ae+"` supplied to `"+ee+"`.\nBad object: "+JSON.stringify(ne[q],null," ")+`
22
+ Valid keys: `+JSON.stringify(Object.keys($),null," "));var K=ge(P,ae,ee,le,ie+"."+ae,n);if(K)return K}return null}return j(H)}function W($){switch(typeof $){case"number":case"string":case"undefined":return!0;case"boolean":return!$;case"object":if(Array.isArray($))return $.every(W);if($===null||c($))return!0;var H=b($);if(H){var ne=H.call($),q;if(H!==$.entries){for(;!(q=ne.next()).done;)if(!W(q.value))return!1}else for(;!(q=ne.next()).done;){var ee=q.value;if(ee&&!W(ee[1]))return!1}}else return!1;return!0;default:return!1}}function V($,H){return $==="symbol"?!0:H?H["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&H instanceof Symbol:!1}function Z($){var H=typeof $;return Array.isArray($)?"array":$ instanceof RegExp?"object":V(H,$)?"symbol":H}function xe($){if(typeof $>"u"||$===null)return""+$;var H=Z($);if(H==="object"){if($ instanceof Date)return"date";if($ instanceof RegExp)return"regexp"}return H}function he($){var H=xe($);switch(H){case"array":case"object":return"an "+H;case"boolean":case"date":case"regexp":return"a "+H;default:return H}}function L($){return!$.constructor||!$.constructor.name?m:$.constructor.name}return g.checkPropTypes=s,g.resetWarningCache=s.resetWarningCache,g.PropTypes=g,g},Zo}var Qo,Fn;function yl(){if(Fn)return Qo;Fn=1;var t=pn();function o(){}function n(){}return n.resetWarningCache=o,Qo=function(){function i(d,c,u,x,h,b){if(b!==t){var m=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 m.name="Invariant Violation",m}}i.isRequired=i;function s(){return i}var l={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:s,element:i,elementType:i,instanceOf:s,node:i,objectOf:s,oneOf:s,oneOfType:s,shape:s,exact:s,checkPropTypes:n,resetWarningCache:o};return l.PropTypes=l,l},Qo}var Vn;function bl(){if(Vn)return xo.exports;if(Vn=1,process.env.NODE_ENV!=="production"){var t=Mi(),o=!0;xo.exports=gl()(t.isElement,o)}else xo.exports=yl()();return xo.exports}var vl=bl();const qr=pl(vl);var ho={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 K=ge(P,ae,ee,le,ie+"
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 Hn;function Sl(){if(Hn)return Te;Hn=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"),x=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),m=Symbol.for("react.view_transition"),y=Symbol.for("react.client.reference");function B(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case t:switch(v=v.type,v){case n:case a:case i:case u:case x:case m:return v;default:switch(v=v&&v.$$typeof,v){case d:case l:case b:case h:return v;case c:return v;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=h,Te.Portal=o,Te.Profiler=a,Te.StrictMode=i,Te.Suspense=u,Te.SuspenseList=x,Te.isContextConsumer=function(v){return B(v)===c},Te.isContextProvider=function(v){return B(v)===d},Te.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===t},Te.isForwardRef=function(v){return B(v)===l},Te.isFragment=function(v){return B(v)===n},Te.isLazy=function(v){return B(v)===b},Te.isMemo=function(v){return B(v)===h},Te.isPortal=function(v){return B(v)===o},Te.isProfiler=function(v){return B(v)===a},Te.isStrictMode=function(v){return B(v)===i},Te.isSuspense=function(v){return B(v)===u},Te.isSuspenseList=function(v){return B(v)===x},Te.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===n||v===a||v===i||v===u||v===x||typeof v=="object"&&v!==null&&(v.$$typeof===b||v.$$typeof===h||v.$$typeof===d||v.$$typeof===c||v.$$typeof===l||v.$$typeof===y||v.getModuleId!==void 0)},Te.typeOf=B,Te}var Ie={};/**
30
+ */var Hn;function Sl(){if(Hn)return Te;Hn=1;var t=Symbol.for("react.transitional.element"),o=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),l=Symbol.for("react.consumer"),d=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),x=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),m=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function B(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case t:switch(v=v.type,v){case n:case s:case i:case u:case x:case m:return v;default:switch(v=v&&v.$$typeof,v){case d:case c:case b:case h:return v;case l:return v;default:return j}}case o:return j}}}return Te.ContextConsumer=l,Te.ContextProvider=d,Te.Element=t,Te.ForwardRef=c,Te.Fragment=n,Te.Lazy=b,Te.Memo=h,Te.Portal=o,Te.Profiler=s,Te.StrictMode=i,Te.Suspense=u,Te.SuspenseList=x,Te.isContextConsumer=function(v){return B(v)===l},Te.isContextProvider=function(v){return B(v)===d},Te.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===t},Te.isForwardRef=function(v){return B(v)===c},Te.isFragment=function(v){return B(v)===n},Te.isLazy=function(v){return B(v)===b},Te.isMemo=function(v){return B(v)===h},Te.isPortal=function(v){return B(v)===o},Te.isProfiler=function(v){return B(v)===s},Te.isStrictMode=function(v){return B(v)===i},Te.isSuspense=function(v){return B(v)===u},Te.isSuspenseList=function(v){return B(v)===x},Te.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===n||v===s||v===i||v===u||v===x||typeof v=="object"&&v!==null&&(v.$$typeof===b||v.$$typeof===h||v.$$typeof===d||v.$$typeof===l||v.$$typeof===c||v.$$typeof===g||v.getModuleId!==void 0)},Te.typeOf=B,Te}var Ie={};/**
31
31
  * @license React
32
32
  * react-is.development.js
33
33
  *
@@ -35,15 +35,15 @@ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var K=ge(P,ae,ee,le,ie+"
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 Un;function jl(){return Un||(Un=1,process.env.NODE_ENV!=="production"&&(function(){function t(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case o:switch(v=v.type,v){case i:case c:case a:case x:case h:case y:return v;default:switch(v=v&&v.$$typeof,v){case l:case u:case m:case b:return v;case d:return v;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"),x=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),y=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=m,Ie.Memo=b,Ie.Portal=n,Ie.Profiler=c,Ie.StrictMode=a,Ie.Suspense=x,Ie.SuspenseList=h,Ie.isContextConsumer=function(v){return t(v)===d},Ie.isContextProvider=function(v){return t(v)===l},Ie.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===o},Ie.isForwardRef=function(v){return t(v)===u},Ie.isFragment=function(v){return t(v)===i},Ie.isLazy=function(v){return t(v)===m},Ie.isMemo=function(v){return t(v)===b},Ie.isPortal=function(v){return t(v)===n},Ie.isProfiler=function(v){return t(v)===c},Ie.isStrictMode=function(v){return t(v)===a},Ie.isSuspense=function(v){return t(v)===x},Ie.isSuspenseList=function(v){return t(v)===h},Ie.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===i||v===c||v===a||v===x||v===h||typeof v=="object"&&v!==null&&(v.$$typeof===m||v.$$typeof===b||v.$$typeof===l||v.$$typeof===d||v.$$typeof===u||v.$$typeof===B||v.getModuleId!==void 0)},Ie.typeOf=t})()),Ie}var Yn;function Cl(){return Yn||(Yn=1,process.env.NODE_ENV==="production"?ho.exports=Sl():ho.exports=jl()),ho.exports}var Wi=Cl();function Nt(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 Pi(t){if(zo.isValidElement(t)||Wi.isValidElementType(t)||!Nt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Pi(t[n])}),o}function Ze(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Nt(t)&&Nt(o)&&Object.keys(o).forEach(a=>{zo.isValidElement(o[a])||Wi.isValidElementType(o[a])?i[a]=o[a]:Nt(o[a])&&Object.prototype.hasOwnProperty.call(t,a)&&Nt(t[a])?i[a]=Ze(t[a],o[a],n):n.clone?i[a]=Nt(o[a])?Pi(o[a]):o[a]:i[a]=o[a]}),i}const wl=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 kl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...a}=t,c=wl(o),d=Object.keys(c);function l(m){return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n})`}function u(m){return`@media (max-width:${(typeof o[m]=="number"?o[m]:m)-i/100}${n})`}function x(m,y){const B=d.indexOf(y);return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n}) and (max-width:${(B!==-1&&typeof o[d[B]]=="number"?o[d[B]]:y)-i/100}${n})`}function h(m){return d.indexOf(m)+1<d.length?x(m,d[d.indexOf(m)+1]):l(m)}function b(m){const y=d.indexOf(m);return y===0?l(d[1]):y===d.length-1?u(d[y]):x(m,d[d.indexOf(m)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:u,between:x,only:h,not:b,unit:n,...a}}function Gn(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 Tl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function Il(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 zl(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 Bl={borderRadius:4},Ft=process.env.NODE_ENV!=="production"?qr.oneOfType([qr.number,qr.string,qr.object,qr.array]):{};function ro(t,o){return o?Ze(t,o,{clone:!1}):t}const Do={xs:0,sm:600,md:900,lg:1200,xl:1536},qn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${Do[t]}px)`},El={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:Do[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function $t(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||qn;return o.reduce((d,l,u)=>(d[c.up(c.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const c=i.breakpoints||qn;return Object.keys(o).reduce((d,l)=>{if(Tl(c.keys,l)){const u=Il(i.containerQueries?i:El,l);u&&(d[u]=n(o[l],l))}else if(Object.keys(c.values||Do).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 Dl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,a)=>{const c=t.up(a);return i[c]={},i},{}))||{}}function Jn(t,o){return t.reduce((n,i)=>{const a=n[i];return(!a||Object.keys(a).length===0)&&delete n[i],n},o)}function Ni(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":or(7));return t.charAt(0).toUpperCase()+t.slice(1)}function Oo(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 To(t,o,n,i=n){let a;return typeof t=="function"?a=t(n):Array.isArray(t)?a=t[n]||i:a=Oo(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,x=Oo(u,i)||{};return $t(d,l,b=>{let m=To(x,a,b);return b===m&&typeof b=="string"&&(m=To(x,a,`${o}${b==="default"?"":Ni(b)}`,b)),n===!1?m:{[n]:m}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Ft}:{},c.filterProps=[o],c}function Ol(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const Al={m:"margin",p:"padding"},$l={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Kn={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},_l=Ol(t=>{if(t.length>2)if(Kn[t])t=Kn[t];else return[t];const[o,n]=t.split(""),i=Al[o],a=$l[n]||"";return Array.isArray(a)?a.map(c=>i+c):[i+a]}),Ao=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],$o=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Ml=[...Ao,...$o];function no(t,o,n,i){const a=Oo(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(`
38
+ */var Un;function jl(){return Un||(Un=1,process.env.NODE_ENV!=="production"&&(function(){function t(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case o:switch(v=v.type,v){case i:case l:case s:case x:case h:case g:return v;default:switch(v=v&&v.$$typeof,v){case c:case u:case m:case b:return v;case d:return v;default:return j}}case n:return j}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),c=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),B=Symbol.for("react.client.reference");Ie.ContextConsumer=d,Ie.ContextProvider=c,Ie.Element=o,Ie.ForwardRef=u,Ie.Fragment=i,Ie.Lazy=m,Ie.Memo=b,Ie.Portal=n,Ie.Profiler=l,Ie.StrictMode=s,Ie.Suspense=x,Ie.SuspenseList=h,Ie.isContextConsumer=function(v){return t(v)===d},Ie.isContextProvider=function(v){return t(v)===c},Ie.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===o},Ie.isForwardRef=function(v){return t(v)===u},Ie.isFragment=function(v){return t(v)===i},Ie.isLazy=function(v){return t(v)===m},Ie.isMemo=function(v){return t(v)===b},Ie.isPortal=function(v){return t(v)===n},Ie.isProfiler=function(v){return t(v)===l},Ie.isStrictMode=function(v){return t(v)===s},Ie.isSuspense=function(v){return t(v)===x},Ie.isSuspenseList=function(v){return t(v)===h},Ie.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===i||v===l||v===s||v===x||v===h||typeof v=="object"&&v!==null&&(v.$$typeof===m||v.$$typeof===b||v.$$typeof===c||v.$$typeof===d||v.$$typeof===u||v.$$typeof===B||v.getModuleId!==void 0)},Ie.typeOf=t})()),Ie}var Yn;function Cl(){return Yn||(Yn=1,process.env.NODE_ENV==="production"?ho.exports=Sl():ho.exports=jl()),ho.exports}var Wi=Cl();function Lt(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 Pi(t){if(zo.isValidElement(t)||Wi.isValidElementType(t)||!Lt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Pi(t[n])}),o}function Qe(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Lt(t)&&Lt(o)&&Object.keys(o).forEach(s=>{zo.isValidElement(o[s])||Wi.isValidElementType(o[s])?i[s]=o[s]:Lt(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Lt(t[s])?i[s]=Qe(t[s],o[s],n):n.clone?i[s]=Lt(o[s])?Pi(o[s]):o[s]:i[s]=o[s]}),i}const wl=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 kl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=t,l=wl(o),d=Object.keys(l);function c(m){return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n})`}function u(m){return`@media (max-width:${(typeof o[m]=="number"?o[m]:m)-i/100}${n})`}function x(m,g){const B=d.indexOf(g);return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n}) and (max-width:${(B!==-1&&typeof o[d[B]]=="number"?o[d[B]]:g)-i/100}${n})`}function h(m){return d.indexOf(m)+1<d.length?x(m,d[d.indexOf(m)+1]):c(m)}function b(m){const g=d.indexOf(m);return g===0?c(d[1]):g===d.length-1?u(d[g]):x(m,d[d.indexOf(m)+1]).replace("@media","@media not all and")}return{keys:d,values:l,up:c,down:u,between:x,only:h,not:b,unit:n,...s}}function Gn(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,s)=>{var d,c;const l=/min-width:\s*([0-9.]+)/;return+(((d=i.match(l))==null?void 0:d[1])||0)-+(((c=s.match(l))==null?void 0:c[1])||0)});return n.length?n.reduce((i,s)=>{const l=o[s];return delete i[s],i[s]=l,i},{...o}):o}function Tl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function Il(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,s]=n,l=Number.isNaN(+i)?i||0:+i;return t.containerQueries(s).up(l)}function zl(t){const o=(l,d)=>l.replace("@media",d?`@container ${d}`:"@container");function n(l,d){l.up=(...c)=>o(t.breakpoints.up(...c),d),l.down=(...c)=>o(t.breakpoints.down(...c),d),l.between=(...c)=>o(t.breakpoints.between(...c),d),l.only=(...c)=>o(t.breakpoints.only(...c),d),l.not=(...c)=>{const u=o(t.breakpoints.not(...c),d);return u.includes("not all and")?u.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):u}}const i={},s=l=>(n(i,l),i);return n(s),{...t,containerQueries:s}}const Bl={borderRadius:4},Vt=process.env.NODE_ENV!=="production"?qr.oneOfType([qr.number,qr.string,qr.object,qr.array]):{};function ro(t,o){return o?Qe(t,o,{clone:!1}):t}const Do={xs:0,sm:600,md:900,lg:1200,xl:1536},qn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${Do[t]}px)`},El={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:Do[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function Ot(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const l=i.breakpoints||qn;return o.reduce((d,c,u)=>(d[l.up(l.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const l=i.breakpoints||qn;return Object.keys(o).reduce((d,c)=>{if(Tl(l.keys,c)){const u=Il(i.containerQueries?i:El,c);u&&(d[u]=n(o[c],c))}else if(Object.keys(l.values||Do).includes(c)){const u=l.up(c);d[u]=n(o[c],c)}else{const u=c;d[u]=o[u]}return d},{})}return n(o)}function Dl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const l=t.up(s);return i[l]={},i},{}))||{}}function Jn(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function Ni(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":sr(7));return t.charAt(0).toUpperCase()+t.slice(1)}function Oo(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((s,l)=>s&&s[l]?s[l]:null,t);if(i!=null)return i}return o.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,t)}function To(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=Oo(t,n)||i,o&&(s=o(s,i,t)),s}function Ae(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:s}=t,l=d=>{if(d[o]==null)return null;const c=d[o],u=d.theme,x=Oo(u,i)||{};return Ot(d,c,b=>{let m=To(x,s,b);return b===m&&typeof b=="string"&&(m=To(x,s,`${o}${b==="default"?"":Ni(b)}`,b)),n===!1?m:{[n]:m}})};return l.propTypes=process.env.NODE_ENV!=="production"?{[o]:Vt}:{},l.filterProps=[o],l}function Ol(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const Al={m:"margin",p:"padding"},$l={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Kn={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},_l=Ol(t=>{if(t.length>2)if(Kn[t])t=Kn[t];else return[t];const[o,n]=t.split(""),i=Al[o],s=$l[n]||"";return Array.isArray(s)?s.map(l=>i+l):[i+s]}),Ao=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],$o=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Ml=[...Ao,...$o];function no(t,o,n,i){const s=Oo(t,o,!0)??n;return typeof s=="number"||typeof s=="string"?l=>typeof l=="string"?l:(process.env.NODE_ENV!=="production"&&typeof l!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${l}.`),typeof s=="string"?s.startsWith("var(")&&l===0?0:s.startsWith("var(")&&l===1?s:`calc(${l} * ${s})`:s*l):Array.isArray(s)?l=>{if(typeof l=="string")return l;const d=Math.abs(l);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>s.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${d} > ${s.length-1}, you need to add the missing values.`].join(`
40
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
- `)));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 xn(t){return no(t,"spacing",8,"spacing")}function io(t,o){return typeof o=="string"||o==null?o:t(o)}function Rl(t,o){return n=>t.reduce((i,a)=>(i[a]=io(o,n),i),{})}function Wl(t,o,n,i){if(!o.includes(n))return null;const a=_l(n),c=Rl(a,i),d=t[n];return $t(t,d,c)}function Li(t,o){const n=xn(t.theme);return Object.keys(t).map(i=>Wl(t,o,i,n)).reduce(ro,{})}function Ee(t){return Li(t,Ao)}Ee.propTypes=process.env.NODE_ENV!=="production"?Ao.reduce((t,o)=>(t[o]=Ft,t),{}):{};Ee.filterProps=Ao;function De(t){return Li(t,$o)}De.propTypes=process.env.NODE_ENV!=="production"?$o.reduce((t,o)=>(t[o]=Ft,t),{}):{};De.filterProps=$o;process.env.NODE_ENV!=="production"&&Ml.reduce((t,o)=>(t[o]=Ft,t),{});function Fi(t=8,o=xn({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 _o(...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]?ro(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 ot(t){return typeof t!="number"?t:`${t}px solid`}function nt(t,o){return Oe({prop:t,themeKey:"borders",transform:o})}const Pl=nt("border",ot),Nl=nt("borderTop",ot),Ll=nt("borderRight",ot),Fl=nt("borderBottom",ot),Vl=nt("borderLeft",ot),Hl=nt("borderColor"),Ul=nt("borderTopColor"),Yl=nt("borderRightColor"),Gl=nt("borderBottomColor"),ql=nt("borderLeftColor"),Jl=nt("outline",ot),Kl=nt("outlineColor"),Mo=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=no(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:io(o,i)});return $t(t,t.borderRadius,n)}return null};Mo.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Ft}:{};Mo.filterProps=["borderRadius"];_o(Pl,Nl,Ll,Fl,Vl,Hl,Ul,Yl,Gl,ql,Mo,Jl,Kl);const Ro=t=>{if(t.gap!==void 0&&t.gap!==null){const o=no(t.theme,"spacing",8,"gap"),n=i=>({gap:io(o,i)});return $t(t,t.gap,n)}return null};Ro.propTypes=process.env.NODE_ENV!=="production"?{gap:Ft}:{};Ro.filterProps=["gap"];const Wo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=no(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:io(o,i)});return $t(t,t.columnGap,n)}return null};Wo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Ft}:{};Wo.filterProps=["columnGap"];const Po=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=no(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:io(o,i)});return $t(t,t.rowGap,n)}return null};Po.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Ft}:{};Po.filterProps=["rowGap"];const Xl=Oe({prop:"gridColumn"}),Zl=Oe({prop:"gridRow"}),Ql=Oe({prop:"gridAutoFlow"}),ec=Oe({prop:"gridAutoColumns"}),tc=Oe({prop:"gridAutoRows"}),rc=Oe({prop:"gridTemplateColumns"}),oc=Oe({prop:"gridTemplateRows"}),nc=Oe({prop:"gridTemplateAreas"}),ic=Oe({prop:"gridArea"});_o(Ro,Wo,Po,Xl,Zl,Ql,ec,tc,rc,oc,nc,ic);function Tr(t,o){return o==="grey"?o:t}const sc=Oe({prop:"color",themeKey:"palette",transform:Tr}),ac=Oe({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:Tr}),lc=Oe({prop:"backgroundColor",themeKey:"palette",transform:Tr});_o(sc,ac,lc);function Ke(t){return t<=1&&t!==0?`${t*100}%`:t}const cc=Oe({prop:"width",transform:Ke}),mn=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])||Do[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:Ke(n)}};return $t(t,t.maxWidth,o)}return null};mn.filterProps=["maxWidth"];const dc=Oe({prop:"minWidth",transform:Ke}),uc=Oe({prop:"height",transform:Ke}),pc=Oe({prop:"maxHeight",transform:Ke}),xc=Oe({prop:"minHeight",transform:Ke});Oe({prop:"size",cssProperty:"width",transform:Ke});Oe({prop:"size",cssProperty:"height",transform:Ke});const mc=Oe({prop:"boxSizing"});_o(cc,mn,dc,uc,pc,xc,mc);const No={border:{themeKey:"borders",transform:ot},borderTop:{themeKey:"borders",transform:ot},borderRight:{themeKey:"borders",transform:ot},borderBottom:{themeKey:"borders",transform:ot},borderLeft:{themeKey:"borders",transform:ot},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:ot},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Mo},color:{themeKey:"palette",transform:Tr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:Tr},backgroundColor:{themeKey:"palette",transform:Tr},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:Ro},rowGap:{style:Po},columnGap:{style:Wo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ke},maxWidth:{style:mn},minWidth:{transform:Ke},height:{transform:Ke},maxHeight:{transform:Ke},minHeight:{transform:Ke},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 hc(...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 fc(t,o){return typeof t=="function"?t(o):t}function gc(){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:x,transform:h,style:b}=l;if(i==null)return null;if(x==="typography"&&i==="inherit")return{[n]:i};const m=Oo(a,x)||{};return b?b(d):$t(d,i,B=>{let v=To(m,h,B);return B===v&&typeof B=="string"&&(v=To(m,h,`${n}${B==="default"?"":Ni(B)}`,B)),u===!1?v:{[u]:v}})}function o(n){const{sx:i,theme:a={},nested:c}=n||{};if(!i)return null;const d=a.unstable_sxConfig??No;function l(u){let x=u;if(typeof u=="function")x=u(a);else if(typeof u!="object")return u;if(!x)return null;const h=Dl(a.breakpoints),b=Object.keys(h);let m=h;return Object.keys(x).forEach(y=>{const B=fc(x[y],a);if(B!=null)if(typeof B=="object")if(d[y])m=ro(m,t(y,B,a,d));else{const v=$t({theme:a},B,j=>({[y]:j}));hc(v,B)?m[y]=o({sx:B,theme:a,nested:!0}):m=ro(m,v)}else m=ro(m,t(y,B,a,d))}),!c&&a.modularCssLayers?{"@layer sx":Gn(a,Jn(b,m))}:Gn(a,Jn(b,m))}return Array.isArray(i)?i.map(l):l(i)}return o}const Lo=gc();Lo.filterProps=["sx"];function yc(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 Vi(t={},...o){const{breakpoints:n={},palette:i={},spacing:a,shape:c={},...d}=t,l=kl(n),u=Fi(a);let x=Ze({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...Bl,...c}},d);return x=zl(x),x.applyStyles=yc,x=o.reduce((h,b)=>Ze(h,b),x),x.unstable_sxConfig={...No,...d==null?void 0:d.unstable_sxConfig},x.unstable_sx=function(b){return Lo({sx:b,theme:this})},x}function bc(t){return Object.keys(t).length===0}function vc(t=null){const o=zo.useContext(Rs.ThemeContext);return!o||bc(o)?t:o}const Sc=Vi();function jc(t=Sc){return vc(t)}const Xn=t=>t,Cc=()=>{let t=Xn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Xn}}},wc=Cc(),kc={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 Tc(t,o,n="Mui"){const i=kc[o];return i?`${n}-${i}`:`${wc.generate(t)}-${o}`}function Ic(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function hn(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}].`),Ic(t,o,n)}function zc(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 Lt(t){if(t.type)return t;if(t.charAt(0)==="#")return Lt(zc(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().`:or(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.`:or(10,a))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:a}}const Bc=t=>{const o=Lt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Qr=(t,o)=>{try{return Bc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function Fo(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 Hi(t){t=Lt(t);const{values:o}=t,n=o[0],i=o[1]/100,a=o[2]/100,c=i*Math.min(a,1-a),d=(x,h=(x+n/30)%12)=>a-c*Math.max(Math.min(h-3,9-h,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])),Fo({type:l,values:u})}function nn(t){t=Lt(t);let o=t.type==="hsl"||t.type==="hsla"?Lt(Hi(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 Zn(t,o){const n=nn(t),i=nn(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function k(t,o){return t=Lt(t),o=hn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,Fo(t)}function er(t,o,n){try{return k(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Vo(t,o){if(t=Lt(t),o=hn(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 Fo(t)}function ve(t,o,n){try{return Vo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Ho(t,o){if(t=Lt(t),o=hn(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 Fo(t)}function Se(t,o,n){try{return Ho(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Ec(t,o=.15){return nn(t)>.5?Vo(t,o):Ho(t,o)}function fo(t,o,n){try{return Ec(t,o)}catch{return t}}function Dc(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 Qn=(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])})},Oc=(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)},Ac=(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 en(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},a={},c={},d={};return Oc(t,(l,u,x)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const h=`--${n?`${n}-`:""}${l.join("-")}`,b=Ac(l,u);Object.assign(a,{[h]:b}),Qn(c,l,`var(${h})`,x),Qn(d,l,`var(${h}, ${b})`,x)}},l=>l[0]==="vars"),{css:a,vars:c,varsWithDefaults:d}}function $c(t,o={}){const{getSelector:n=S,disableCssColorScheme:i,colorSchemeSelector:a,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:u="light",...x}=t,{vars:h,css:b,varsWithDefaults:m}=en(x,o);let y=m;const B={},{[u]:v,...j}=d;if(Object.entries(j||{}).forEach(([w,s])=>{const{vars:$,css:T,varsWithDefaults:R}=en(s,o);y=Ze(y,R),B[w]={css:T,vars:$}}),v){const{css:w,vars:s,varsWithDefaults:$}=en(v,o);y=Ze(y,$),B[u]={css:w,vars:s}}function S(w,s){var T,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=(T=d[w])==null?void 0:T.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:y,generateThemeVars:()=>{let w={...h};return Object.entries(B).forEach(([,{vars:s}])=>{w=Ze(w,s)}),w},generateStyleSheets:()=>{var q,X;const w=[],s=t.defaultColorScheme||"light";function $(te,g){Object.keys(g).length&&w.push(typeof te=="string"?{[te]:{...g}}:te)}$(n(void 0,{...b}),b);const{[s]:T,...R}=B;if(T){const{css:te}=T,g=(X=(q=d[s])==null?void 0:q.palette)==null?void 0:X.mode,_=!i&&g?{colorScheme:g,...te}:{...te};$(n(s,{..._}),_)}return Object.entries(R).forEach(([te,{css:g}])=>{var V,Z;const _=(Z=(V=d[te])==null?void 0:V.palette)==null?void 0:Z.mode,W=!i&&_?{colorScheme:_,...g}:{...g};$(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 _c(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 oo={black:"#000",white:"#fff"},Mc={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"},vr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},Sr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Jr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},jr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},Cr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},wr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Ui(){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:oo.white,default:oo.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 Yi=Ui();function Gi(){return{text:{primary:oo.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:oo.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 sn=Gi();function ei(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=Ho(t.main,a):o==="dark"&&(t.dark=Vo(t.main,c)))}function ti(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 Rc(t="light"){return t==="dark"?{main:jr[200],light:jr[50],dark:jr[400]}:{main:jr[700],light:jr[400],dark:jr[800]}}function Wc(t="light"){return t==="dark"?{main:vr[200],light:vr[50],dark:vr[400]}:{main:vr[500],light:vr[300],dark:vr[700]}}function Pc(t="light"){return t==="dark"?{main:Sr[500],light:Sr[300],dark:Sr[700]}:{main:Sr[700],light:Sr[400],dark:Sr[800]}}function Nc(t="light"){return t==="dark"?{main:Cr[400],light:Cr[300],dark:Cr[700]}:{main:Cr[700],light:Cr[500],dark:Cr[900]}}function Lc(t="light"){return t==="dark"?{main:wr[400],light:wr[300],dark:wr[700]}:{main:wr[800],light:wr[500],dark:wr[900]}}function Fc(t="light"){return t==="dark"?{main:Jr[400],light:Jr[300],dark:Jr[700]}:{main:"#ed6c02",light:Jr[500],dark:Jr[900]}}function Vc(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function fn(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:a,...c}=t,d=t.primary||Rc(o),l=t.secondary||Wc(o),u=t.error||Pc(o),x=t.info||Nc(o),h=t.success||Lc(o),b=t.warning||Fc(o);function m(j){if(a)return Vc(j);const S=Zn(j,sn.text.primary)>=n?sn.text.primary:Yi.text.primary;if(process.env.NODE_ENV!=="production"){const I=Zn(j,S);I<3&&console.error([`MUI: The contrast ratio of ${I}: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 y=({color:j,name:S,mainShade:I=500,lightShade:f=300,darkShade:w=700})=>{if(j={...j},!j.main&&j[I]&&(j.main=j[I]),!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 \`${I}\` property.`:or(11,S?` (${S})`:"",I));if(typeof j.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
41
+ `)));const c=s[d];return l>=0?c:typeof c=="number"?-c:typeof c=="string"&&c.startsWith("var(")?`calc(-1 * ${c})`:`-${c}`}:typeof s=="function"?s:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${o}\` value (${s}) is invalid.`,"It should be a number, an array or a function."].join(`
42
+ `)),()=>{})}function xn(t){return no(t,"spacing",8,"spacing")}function io(t,o){return typeof o=="string"||o==null?o:t(o)}function Rl(t,o){return n=>t.reduce((i,s)=>(i[s]=io(o,n),i),{})}function Wl(t,o,n,i){if(!o.includes(n))return null;const s=_l(n),l=Rl(s,i),d=t[n];return Ot(t,d,l)}function Li(t,o){const n=xn(t.theme);return Object.keys(t).map(i=>Wl(t,o,i,n)).reduce(ro,{})}function De(t){return Li(t,Ao)}De.propTypes=process.env.NODE_ENV!=="production"?Ao.reduce((t,o)=>(t[o]=Vt,t),{}):{};De.filterProps=Ao;function Oe(t){return Li(t,$o)}Oe.propTypes=process.env.NODE_ENV!=="production"?$o.reduce((t,o)=>(t[o]=Vt,t),{}):{};Oe.filterProps=$o;process.env.NODE_ENV!=="production"&&Ml.reduce((t,o)=>(t[o]=Vt,t),{});function Fi(t=8,o=xn({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(l=>{const d=o(l);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function _o(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(l=>{i[l]=s}),i),{}),n=i=>Object.keys(i).reduce((s,l)=>o[l]?ro(s,o[l](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=t.reduce((i,s)=>i.concat(s.filterProps),[]),n}function ot(t){return typeof t!="number"?t:`${t}px solid`}function nt(t,o){return Ae({prop:t,themeKey:"borders",transform:o})}const Pl=nt("border",ot),Nl=nt("borderTop",ot),Ll=nt("borderRight",ot),Fl=nt("borderBottom",ot),Vl=nt("borderLeft",ot),Hl=nt("borderColor"),Ul=nt("borderTopColor"),Yl=nt("borderRightColor"),Gl=nt("borderBottomColor"),ql=nt("borderLeftColor"),Jl=nt("outline",ot),Kl=nt("outlineColor"),Mo=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=no(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:io(o,i)});return Ot(t,t.borderRadius,n)}return null};Mo.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Vt}:{};Mo.filterProps=["borderRadius"];_o(Pl,Nl,Ll,Fl,Vl,Hl,Ul,Yl,Gl,ql,Mo,Jl,Kl);const Ro=t=>{if(t.gap!==void 0&&t.gap!==null){const o=no(t.theme,"spacing",8,"gap"),n=i=>({gap:io(o,i)});return Ot(t,t.gap,n)}return null};Ro.propTypes=process.env.NODE_ENV!=="production"?{gap:Vt}:{};Ro.filterProps=["gap"];const Wo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=no(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:io(o,i)});return Ot(t,t.columnGap,n)}return null};Wo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Vt}:{};Wo.filterProps=["columnGap"];const Po=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=no(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:io(o,i)});return Ot(t,t.rowGap,n)}return null};Po.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Vt}:{};Po.filterProps=["rowGap"];const Xl=Ae({prop:"gridColumn"}),Zl=Ae({prop:"gridRow"}),Ql=Ae({prop:"gridAutoFlow"}),ec=Ae({prop:"gridAutoColumns"}),tc=Ae({prop:"gridAutoRows"}),rc=Ae({prop:"gridTemplateColumns"}),oc=Ae({prop:"gridTemplateRows"}),nc=Ae({prop:"gridTemplateAreas"}),ic=Ae({prop:"gridArea"});_o(Ro,Wo,Po,Xl,Zl,Ql,ec,tc,rc,oc,nc,ic);function zr(t,o){return o==="grey"?o:t}const sc=Ae({prop:"color",themeKey:"palette",transform:zr}),ac=Ae({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:zr}),lc=Ae({prop:"backgroundColor",themeKey:"palette",transform:zr});_o(sc,ac,lc);function Xe(t){return t<=1&&t!==0?`${t*100}%`:t}const cc=Ae({prop:"width",transform:Xe}),mn=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,l,d,c,u;const i=((d=(l=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:l.values)==null?void 0:d[n])||Do[n];return i?((u=(c=t.theme)==null?void 0:c.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Xe(n)}};return Ot(t,t.maxWidth,o)}return null};mn.filterProps=["maxWidth"];const dc=Ae({prop:"minWidth",transform:Xe}),uc=Ae({prop:"height",transform:Xe}),pc=Ae({prop:"maxHeight",transform:Xe}),xc=Ae({prop:"minHeight",transform:Xe});Ae({prop:"size",cssProperty:"width",transform:Xe});Ae({prop:"size",cssProperty:"height",transform:Xe});const mc=Ae({prop:"boxSizing"});_o(cc,mn,dc,uc,pc,xc,mc);const No={border:{themeKey:"borders",transform:ot},borderTop:{themeKey:"borders",transform:ot},borderRight:{themeKey:"borders",transform:ot},borderBottom:{themeKey:"borders",transform:ot},borderLeft:{themeKey:"borders",transform:ot},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:ot},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Mo},color:{themeKey:"palette",transform:zr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:zr},backgroundColor:{themeKey:"palette",transform:zr},p:{style:Oe},pt:{style:Oe},pr:{style:Oe},pb:{style:Oe},pl:{style:Oe},px:{style:Oe},py:{style:Oe},padding:{style:Oe},paddingTop:{style:Oe},paddingRight:{style:Oe},paddingBottom:{style:Oe},paddingLeft:{style:Oe},paddingX:{style:Oe},paddingY:{style:Oe},paddingInline:{style:Oe},paddingInlineStart:{style:Oe},paddingInlineEnd:{style:Oe},paddingBlock:{style:Oe},paddingBlockStart:{style:Oe},paddingBlockEnd:{style:Oe},m:{style:De},mt:{style:De},mr:{style:De},mb:{style:De},ml:{style:De},mx:{style:De},my:{style:De},margin:{style:De},marginTop:{style:De},marginRight:{style:De},marginBottom:{style:De},marginLeft:{style:De},marginX:{style:De},marginY:{style:De},marginInline:{style:De},marginInlineStart:{style:De},marginInlineEnd:{style:De},marginBlock:{style:De},marginBlockStart:{style:De},marginBlockEnd:{style:De},displayPrint:{cssProperty:!1,transform:t=>({"@media print":{display:t}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:Ro},rowGap:{style:Po},columnGap:{style:Wo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Xe},maxWidth:{style:mn},minWidth:{transform:Xe},height:{transform:Xe},maxHeight:{transform:Xe},minHeight:{transform:Xe},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function hc(...t){const o=t.reduce((i,s)=>i.concat(Object.keys(s)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function fc(t,o){return typeof t=="function"?t(o):t}function gc(){function t(n,i,s,l){const d={[n]:i,theme:s},c=l[n];if(!c)return{[n]:i};const{cssProperty:u=n,themeKey:x,transform:h,style:b}=c;if(i==null)return null;if(x==="typography"&&i==="inherit")return{[n]:i};const m=Oo(s,x)||{};return b?b(d):Ot(d,i,B=>{let v=To(m,h,B);return B===v&&typeof B=="string"&&(v=To(m,h,`${n}${B==="default"?"":Ni(B)}`,B)),u===!1?v:{[u]:v}})}function o(n){const{sx:i,theme:s={},nested:l}=n||{};if(!i)return null;const d=s.unstable_sxConfig??No;function c(u){let x=u;if(typeof u=="function")x=u(s);else if(typeof u!="object")return u;if(!x)return null;const h=Dl(s.breakpoints),b=Object.keys(h);let m=h;return Object.keys(x).forEach(g=>{const B=fc(x[g],s);if(B!=null)if(typeof B=="object")if(d[g])m=ro(m,t(g,B,s,d));else{const v=Ot({theme:s},B,j=>({[g]:j}));hc(v,B)?m[g]=o({sx:B,theme:s,nested:!0}):m=ro(m,v)}else m=ro(m,t(g,B,s,d))}),!l&&s.modularCssLayers?{"@layer sx":Gn(s,Jn(b,m))}:Gn(s,Jn(b,m))}return Array.isArray(i)?i.map(c):c(i)}return o}const Lo=gc();Lo.filterProps=["sx"];function yc(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let s=n.getColorSchemeSelector(t);return s==="&"?o:((s.includes("data-")||s.includes("."))&&(s=`*:where(${s.replace(/\s*&$/,"")}) &`),{[s]:o})}return n.palette.mode===t?o:{}}function Vi(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:l={},...d}=t,c=kl(n),u=Fi(s);let x=Qe({breakpoints:c,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...Bl,...l}},d);return x=zl(x),x.applyStyles=yc,x=o.reduce((h,b)=>Qe(h,b),x),x.unstable_sxConfig={...No,...d==null?void 0:d.unstable_sxConfig},x.unstable_sx=function(b){return Lo({sx:b,theme:this})},x}function bc(t){return Object.keys(t).length===0}function vc(t=null){const o=zo.useContext(Rs.ThemeContext);return!o||bc(o)?t:o}const Sc=Vi();function jc(t=Sc){return vc(t)}const Xn=t=>t,Cc=()=>{let t=Xn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Xn}}},wc=Cc(),kc={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 Tc(t,o,n="Mui"){const i=kc[o];return i?`${n}-${i}`:`${wc.generate(t)}-${o}`}function Ic(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function hn(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}].`),Ic(t,o,n)}function zc(t){t=t.slice(1);const o=new RegExp(`.{1,${t.length>=6?2:1}}`,"g");let n=t.match(o);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&t.length!==t.trim().length&&console.error(`MUI: The color: "${t}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,s)=>s<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Ft(t){if(t.type)return t;if(t.charAt(0)==="#")return Ft(zc(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().`:sr(9,t));let i=t.substring(o+1,t.length-1),s;if(n==="color"){if(i=i.split(" "),s=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),!["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].includes(s))throw new Error(process.env.NODE_ENV!=="production"?`MUI: unsupported \`${s}\` color space.
44
+ The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:sr(10,s))}else i=i.split(",");return i=i.map(l=>parseFloat(l)),{type:n,values:i,colorSpace:s}}const Bc=t=>{const o=Ft(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Qr=(t,o)=>{try{return Bc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function Fo(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((s,l)=>l<3?parseInt(s,10):s):o.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),o.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${o}(${i})`}function Hi(t){t=Ft(t);const{values:o}=t,n=o[0],i=o[1]/100,s=o[2]/100,l=i*Math.min(s,1-s),d=(x,h=(x+n/30)%12)=>s-l*Math.max(Math.min(h-3,9-h,1),-1);let c="rgb";const u=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return t.type==="hsla"&&(c+="a",u.push(o[3])),Fo({type:c,values:u})}function nn(t){t=Ft(t);let o=t.type==="hsl"||t.type==="hsla"?Ft(Hi(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 Zn(t,o){const n=nn(t),i=nn(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function k(t,o){return t=Ft(t),o=hn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,Fo(t)}function or(t,o,n){try{return k(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Vo(t,o){if(t=Ft(t),o=hn(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 Fo(t)}function Se(t,o,n){try{return Vo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Ho(t,o){if(t=Ft(t),o=hn(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 Fo(t)}function je(t,o,n){try{return Ho(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Ec(t,o=.15){return nn(t)>.5?Vo(t,o):Ho(t,o)}function fo(t,o,n){try{return Ec(t,o)}catch{return t}}function Dc(t=""){function o(...i){if(!i.length)return"";const s=i[0];return typeof s=="string"&&!s.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)?`, var(--${t?`${t}-`:""}${s}${o(...i.slice(1))})`:`, ${s}`}return(i,...s)=>`var(--${t?`${t}-`:""}${i}${o(...s)})`}const Qn=(t,o,n,i=[])=>{let s=t;o.forEach((l,d)=>{d===o.length-1?Array.isArray(s)?s[Number(l)]=n:s&&typeof s=="object"&&(s[l]=n):s&&typeof s=="object"&&(s[l]||(s[l]=i.includes(l)?[]:{}),s=s[l])})},Oc=(t,o,n)=>{function i(s,l=[],d=[]){Object.entries(s).forEach(([c,u])=>{(!n||n&&!n([...l,c]))&&u!=null&&(typeof u=="object"&&Object.keys(u).length>0?i(u,[...l,c],Array.isArray(u)?[...d,c]:d):o([...l,c],u,d))})}i(t)},Ac=(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 en(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},l={},d={};return Oc(t,(c,u,x)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(c,u))){const h=`--${n?`${n}-`:""}${c.join("-")}`,b=Ac(c,u);Object.assign(s,{[h]:b}),Qn(l,c,`var(${h})`,x),Qn(d,c,`var(${h}, ${b})`,x)}},c=>c[0]==="vars"),{css:s,vars:l,varsWithDefaults:d}}function $c(t,o={}){const{getSelector:n=S,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:l}=o,{colorSchemes:d={},components:c,defaultColorScheme:u="light",...x}=t,{vars:h,css:b,varsWithDefaults:m}=en(x,o);let g=m;const B={},{[u]:v,...j}=d;if(Object.entries(j||{}).forEach(([C,a])=>{const{vars:A,css:T,varsWithDefaults:R}=en(a,o);g=Qe(g,R),B[C]={css:T,vars:A}}),v){const{css:C,vars:a,varsWithDefaults:A}=en(v,o);g=Qe(g,A),B[u]={css:C,vars:a}}function S(C,a){var T,R;let A=s;if(s==="class"&&(A=".%s"),s==="data"&&(A="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(A=`[${s}="%s"]`),C){if(A==="media")return t.defaultColorScheme===C?":root":{[`@media (prefers-color-scheme: ${((R=(T=d[C])==null?void 0:T.palette)==null?void 0:R.mode)||C})`]:{":root":a}};if(A)return t.defaultColorScheme===C?`:root, ${A.replace("%s",String(C))}`:A.replace("%s",String(C))}return":root"}return{vars:g,generateThemeVars:()=>{let C={...h};return Object.entries(B).forEach(([,{vars:a}])=>{C=Qe(C,a)}),C},generateStyleSheets:()=>{var G,X;const C=[],a=t.defaultColorScheme||"light";function A(te,f){Object.keys(f).length&&C.push(typeof te=="string"?{[te]:{...f}}:te)}A(n(void 0,{...b}),b);const{[a]:T,...R}=B;if(T){const{css:te}=T,f=(X=(G=d[a])==null?void 0:G.palette)==null?void 0:X.mode,_=!i&&f?{colorScheme:f,...te}:{...te};A(n(a,{..._}),_)}return Object.entries(R).forEach(([te,{css:f}])=>{var V,Z;const _=(Z=(V=d[te])==null?void 0:V.palette)==null?void 0:Z.mode,W=!i&&_?{colorScheme:_,...f}:{...f};A(n(te,{...W}),W)}),l&&C.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)"}}),C}}}function _c(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 oo={black:"#000",white:"#fff"},Mc={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"},jr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},Cr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Jr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},wr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},kr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},Tr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Ui(){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:oo.white,default:oo.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 Yi=Ui();function Gi(){return{text:{primary:oo.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:oo.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 sn=Gi();function ei(t,o,n,i){const s=i.light||i,l=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Ho(t.main,s):o==="dark"&&(t.dark=Vo(t.main,l)))}function ti(t,o,n,i,s){const l=s.light||s,d=s.dark||s*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(l*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function Rc(t="light"){return t==="dark"?{main:wr[200],light:wr[50],dark:wr[400]}:{main:wr[700],light:wr[400],dark:wr[800]}}function Wc(t="light"){return t==="dark"?{main:jr[200],light:jr[50],dark:jr[400]}:{main:jr[500],light:jr[300],dark:jr[700]}}function Pc(t="light"){return t==="dark"?{main:Cr[500],light:Cr[300],dark:Cr[700]}:{main:Cr[700],light:Cr[400],dark:Cr[800]}}function Nc(t="light"){return t==="dark"?{main:kr[400],light:kr[300],dark:kr[700]}:{main:kr[700],light:kr[500],dark:kr[900]}}function Lc(t="light"){return t==="dark"?{main:Tr[400],light:Tr[300],dark:Tr[700]}:{main:Tr[800],light:Tr[500],dark:Tr[900]}}function Fc(t="light"){return t==="dark"?{main:Jr[400],light:Jr[300],dark:Jr[700]}:{main:"#ed6c02",light:Jr[500],dark:Jr[900]}}function Vc(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function fn(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...l}=t,d=t.primary||Rc(o),c=t.secondary||Wc(o),u=t.error||Pc(o),x=t.info||Nc(o),h=t.success||Lc(o),b=t.warning||Fc(o);function m(j){if(s)return Vc(j);const S=Zn(j,sn.text.primary)>=n?sn.text.primary:Yi.text.primary;if(process.env.NODE_ENV!=="production"){const I=Zn(j,S);I<3&&console.error([`MUI: The contrast ratio of ${I}: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:I=500,lightShade:y=300,darkShade:C=700})=>{if(j={...j},!j.main&&j[I]&&(j.main=j[I]),!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 \`${I}\` property.`:sr(11,S?` (${S})`:"",I));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
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?
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
56
56
 
57
57
  const theme2 = createTheme({ palette: {
58
58
  primary: { main: green[500] },
59
- } });`:or(12,S?` (${S})`:"",JSON.stringify(j.main)));return a?(ti(a,j,"light",f,i),ti(a,j,"dark",w,i)):(ei(j,"light",f,i),ei(j,"dark",w,i)),j.contrastText||(j.contrastText=m(j.main)),j};let B;return o==="light"?B=Ui():o==="dark"&&(B=Gi()),process.env.NODE_ENV!=="production"&&(B||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),Ze({common:{...oo},mode:o,primary:y({color:d,name:"primary"}),secondary:y({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:y({color:u,name:"error"}),warning:y({color:b,name:"warning"}),info:y({color:x,name:"info"}),success:y({color:h,name:"success"}),grey:Mc,contrastThreshold:n,getContrastText:m,augmentColor:y,tonalOffset:i,...B},c)}function Hc(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 Uc(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Yc(t){return Math.round(t*1e5)/1e5}const ri={textTransform:"uppercase"},oi='"Roboto", "Helvetica", "Arial", sans-serif';function Gc(t,o){const{fontFamily:n=oi,fontSize:i=14,fontWeightLight:a=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:u=16,allVariants:x,pxToRem:h,...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 m=i/14,y=h||(j=>`${j/u*m}rem`),B=(j,S,I,f,w)=>({fontFamily:n,fontWeight:j,fontSize:y(S),lineHeight:I,...n===oi?{letterSpacing:`${Yc(f/S)}em`}:{},...w,...x}),v={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,ri),caption:B(c,12,1.66,.4),overline:B(c,12,2.66,1,ri),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Ze({htmlFontSize:u,pxToRem:y,fontFamily:n,fontSize:i,fontWeightLight:a,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...v},b,{clone:!1})}const qc=.2,Jc=.14,Kc=.12;function ze(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${qc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Jc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Kc})`].join(",")}const Xc=["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)],Zc={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)"},Qc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function ni(t){return`${Math.round(t)}ms`}function ed(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function td(t){const o={...Zc,...t.easing},n={...Qc,...t.duration};return{getAutoHeightDuration:ed,create:(a=["all"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:u=0,...x}=c;if(process.env.NODE_ENV!=="production"){const h=m=>typeof m=="string",b=m=>!Number.isNaN(parseFloat(m));!h(a)&&!Array.isArray(a)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!h(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),h(l)||console.error('MUI: Argument "easing" must be a string.'),!b(u)&&!h(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(x).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(x).join(",")}].`)}return(Array.isArray(a)?a:[a]).map(h=>`${h} ${typeof d=="string"?d:ni(d)} ${l} ${typeof u=="string"?u:ni(u)}`).join(",")},...t,easing:o,duration:n}}const rd={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function od(t){return Nt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function qi(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];!od(l)||d.startsWith("unstable_")?delete i[d]:Nt(l)&&(i[d]={...l},n(i[d]))}}return n(o),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
59
+ } });`:sr(12,S?` (${S})`:"",JSON.stringify(j.main)));return s?(ti(s,j,"light",y,i),ti(s,j,"dark",C,i)):(ei(j,"light",y,i),ei(j,"dark",C,i)),j.contrastText||(j.contrastText=m(j.main)),j};let B;return o==="light"?B=Ui():o==="dark"&&(B=Gi()),process.env.NODE_ENV!=="production"&&(B||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),Qe({common:{...oo},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:c,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:u,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:x,name:"info"}),success:g({color:h,name:"success"}),grey:Mc,contrastThreshold:n,getContrastText:m,augmentColor:g,tonalOffset:i,...B},l)}function Hc(t){const o={};return Object.entries(t).forEach(i=>{const[s,l]=i;typeof l=="object"&&(o[s]=`${l.fontStyle?`${l.fontStyle} `:""}${l.fontVariant?`${l.fontVariant} `:""}${l.fontWeight?`${l.fontWeight} `:""}${l.fontStretch?`${l.fontStretch} `:""}${l.fontSize||""}${l.lineHeight?`/${l.lineHeight} `:""}${l.fontFamily||""}`)}),o}function Uc(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Yc(t){return Math.round(t*1e5)/1e5}const ri={textTransform:"uppercase"},oi='"Roboto", "Helvetica", "Arial", sans-serif';function Gc(t,o){const{fontFamily:n=oi,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:l=400,fontWeightMedium:d=500,fontWeightBold:c=700,htmlFontSize:u=16,allVariants:x,pxToRem:h,...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 m=i/14,g=h||(j=>`${j/u*m}rem`),B=(j,S,I,y,C)=>({fontFamily:n,fontWeight:j,fontSize:g(S),lineHeight:I,...n===oi?{letterSpacing:`${Yc(y/S)}em`}:{},...C,...x}),v={h1:B(s,96,1.167,-1.5),h2:B(s,60,1.2,-.5),h3:B(l,48,1.167,0),h4:B(l,34,1.235,.25),h5:B(l,24,1.334,0),h6:B(d,20,1.6,.15),subtitle1:B(l,16,1.75,.15),subtitle2:B(d,14,1.57,.1),body1:B(l,16,1.5,.15),body2:B(l,14,1.43,.15),button:B(d,14,1.75,.4,ri),caption:B(l,12,1.66,.4),overline:B(l,12,2.66,1,ri),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Qe({htmlFontSize:u,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:l,fontWeightMedium:d,fontWeightBold:c,...v},b,{clone:!1})}const qc=.2,Jc=.14,Kc=.12;function ze(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${qc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Jc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Kc})`].join(",")}const Xc=["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)],Zc={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)"},Qc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function ni(t){return`${Math.round(t)}ms`}function ed(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function td(t){const o={...Zc,...t.easing},n={...Qc,...t.duration};return{getAutoHeightDuration:ed,create:(s=["all"],l={})=>{const{duration:d=n.standard,easing:c=o.easeInOut,delay:u=0,...x}=l;if(process.env.NODE_ENV!=="production"){const h=m=>typeof m=="string",b=m=>!Number.isNaN(parseFloat(m));!h(s)&&!Array.isArray(s)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!h(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),h(c)||console.error('MUI: Argument "easing" must be a string.'),!b(u)&&!h(u)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof l!="object"&&console.error(["MUI: Secong argument of transition.create must be an object.","Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join(`
60
+ `)),Object.keys(x).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(x).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(h=>`${h} ${typeof d=="string"?d:ni(d)} ${c} ${typeof u=="string"?u:ni(u)}`).join(",")},...t,easing:o,duration:n}}const rd={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function od(t){return Lt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function qi(t={}){const o={...t};function n(i){const s=Object.entries(i);for(let l=0;l<s.length;l++){const[d,c]=s[l];!od(c)||d.startsWith("unstable_")?delete i[d]:Lt(c)&&(i[d]={...c},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 ii(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const nd=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 id(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})`:k(o,nd(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${ii(n)})`:Ho(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${ii(n)})`:Vo(o,n)}})}function an(t={},...o){const{breakpoints:n,mixins:i={},spacing:a,palette:c={},transitions:d={},typography:l={},shape:u,colorSpace:x,...h}=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.":or(20));const b=fn({...c,colorSpace:x}),m=Vi(t);let y=Ze(m,{mixins:Uc(m.breakpoints,i),palette:b,shadows:Xc.slice(),typography:Gc(b,l),transitions:td(d),zIndex:{...rd}});if(y=Ze(y,h),y=o.reduce((B,v)=>Ze(B,v),y),process.env.NODE_ENV!=="production"){const B=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],v=(j,S)=>{let I;for(I in j){const f=j[I];if(B.includes(I)&&Object.keys(f).length>0){if(process.env.NODE_ENV!=="production"){const w=Tc("",I);console.error([`MUI: The \`${S}\` component increases the CSS specificity of the \`${I}\` 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}`]:f}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
68
- `))}j[I]={}}}};Object.keys(y.components).forEach(j=>{const S=y.components[j].styleOverrides;S&&j.startsWith("Mui")&&v(S,j)})}return y.unstable_sxConfig={...No,...h==null?void 0:h.unstable_sxConfig},y.unstable_sx=function(v){return Lo({sx:v,theme:this})},y.toRuntimeSource=qi,id(y),y}function sd(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 ad=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=sd(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ji(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Ki(t){return t==="dark"?ad:[]}function ld(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:a,...c}=t,d=fn({...o,colorSpace:a});return{palette:d,opacity:{...Ji(d.mode),...n},overlays:i||Ki(d.mode),...c}}function cd(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 dd=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],ud=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 dd(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 pd(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function N(t,o,n){!t[o]&&n&&(t[o]=n)}function eo(t){return typeof t!="string"||!t.startsWith("hsl")?t:Hi(t)}function Dt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Qr(eo(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 xd(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const vt=t=>{try{return t()}catch{}},md=(t="mui")=>Dc(t);function tn(t,o,n,i,a){if(!n)return;n=n===!0?{}:n;const c=a==="dark"?"dark":"light";if(!i){o[a]=ld({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=an({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[a]={...n,palette:d,opacity:{...Ji(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Ki(c)},l}function hd(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:a=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=cd,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:x=":root",...h}=t,b=Object.keys(n)[0],m=i||(n.light&&b!=="light"?"light":b),y=md(c),{[m]:B,light:v,dark:j,...S}=n,I={...S};let f=B;if((m==="dark"&&!("dark"in n)||m==="light"&&!("light"in n))&&(f=!0),!f)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${m}\` option is either missing or invalid.`:or(21,m));let w;d&&(w="oklch");const s=tn(w,I,f,h,m);v&&!I.light&&tn(w,I,v,void 0,"light"),j&&!I.dark&&tn(w,I,j,void 0,"dark");let $={defaultColorScheme:m,...s,cssVarPrefix:c,colorSchemeSelector:u,rootSelector:x,getCssVar:y,colorSchemes:I,font:{...Hc(s.typography),...s.font},spacing:xd(h.spacing)};Object.keys($.colorSchemes).forEach(te=>{const g=$.colorSchemes[te].palette,_=V=>{const Z=V.split("-"),xe=Z[1],me=Z[2];return y(V,g[xe][me])};g.mode==="light"&&(N(g.common,"background","#fff"),N(g.common,"onBackground","#000")),g.mode==="dark"&&(N(g.common,"background","#000"),N(g.common,"onBackground","#fff"));function W(V,Z,xe){if(w){let me;return V===er&&(me=`transparent ${((1-xe)*100).toFixed(0)}%`),V===ve&&(me=`#000 ${(xe*100).toFixed(0)}%`),V===Se&&(me=`#fff ${(xe*100).toFixed(0)}%`),`color-mix(in ${w}, ${Z}, ${me})`}return V(Z,xe)}if(pd(g,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),g.mode==="light"){N(g.Alert,"errorColor",W(ve,g.error.light,.6)),N(g.Alert,"infoColor",W(ve,g.info.light,.6)),N(g.Alert,"successColor",W(ve,g.success.light,.6)),N(g.Alert,"warningColor",W(ve,g.warning.light,.6)),N(g.Alert,"errorFilledBg",_("palette-error-main")),N(g.Alert,"infoFilledBg",_("palette-info-main")),N(g.Alert,"successFilledBg",_("palette-success-main")),N(g.Alert,"warningFilledBg",_("palette-warning-main")),N(g.Alert,"errorFilledColor",vt(()=>g.getContrastText(g.error.main))),N(g.Alert,"infoFilledColor",vt(()=>g.getContrastText(g.info.main))),N(g.Alert,"successFilledColor",vt(()=>g.getContrastText(g.success.main))),N(g.Alert,"warningFilledColor",vt(()=>g.getContrastText(g.warning.main))),N(g.Alert,"errorStandardBg",W(Se,g.error.light,.9)),N(g.Alert,"infoStandardBg",W(Se,g.info.light,.9)),N(g.Alert,"successStandardBg",W(Se,g.success.light,.9)),N(g.Alert,"warningStandardBg",W(Se,g.warning.light,.9)),N(g.Alert,"errorIconColor",_("palette-error-main")),N(g.Alert,"infoIconColor",_("palette-info-main")),N(g.Alert,"successIconColor",_("palette-success-main")),N(g.Alert,"warningIconColor",_("palette-warning-main")),N(g.AppBar,"defaultBg",_("palette-grey-100")),N(g.Avatar,"defaultBg",_("palette-grey-400")),N(g.Button,"inheritContainedBg",_("palette-grey-300")),N(g.Button,"inheritContainedHoverBg",_("palette-grey-A100")),N(g.Chip,"defaultBorder",_("palette-grey-400")),N(g.Chip,"defaultAvatarColor",_("palette-grey-700")),N(g.Chip,"defaultIconColor",_("palette-grey-700")),N(g.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),N(g.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),N(g.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),N(g.LinearProgress,"primaryBg",W(Se,g.primary.main,.62)),N(g.LinearProgress,"secondaryBg",W(Se,g.secondary.main,.62)),N(g.LinearProgress,"errorBg",W(Se,g.error.main,.62)),N(g.LinearProgress,"infoBg",W(Se,g.info.main,.62)),N(g.LinearProgress,"successBg",W(Se,g.success.main,.62)),N(g.LinearProgress,"warningBg",W(Se,g.warning.main,.62)),N(g.Skeleton,"bg",w?W(er,g.text.primary,.11):`rgba(${_("palette-text-primaryChannel")} / 0.11)`),N(g.Slider,"primaryTrack",W(Se,g.primary.main,.62)),N(g.Slider,"secondaryTrack",W(Se,g.secondary.main,.62)),N(g.Slider,"errorTrack",W(Se,g.error.main,.62)),N(g.Slider,"infoTrack",W(Se,g.info.main,.62)),N(g.Slider,"successTrack",W(Se,g.success.main,.62)),N(g.Slider,"warningTrack",W(Se,g.warning.main,.62));const V=w?W(ve,g.background.default,.6825):fo(g.background.default,.8);N(g.SnackbarContent,"bg",V),N(g.SnackbarContent,"color",vt(()=>w?sn.text.primary:g.getContrastText(V))),N(g.SpeedDialAction,"fabHoverBg",fo(g.background.paper,.15)),N(g.StepConnector,"border",_("palette-grey-400")),N(g.StepContent,"border",_("palette-grey-400")),N(g.Switch,"defaultColor",_("palette-common-white")),N(g.Switch,"defaultDisabledColor",_("palette-grey-100")),N(g.Switch,"primaryDisabledColor",W(Se,g.primary.main,.62)),N(g.Switch,"secondaryDisabledColor",W(Se,g.secondary.main,.62)),N(g.Switch,"errorDisabledColor",W(Se,g.error.main,.62)),N(g.Switch,"infoDisabledColor",W(Se,g.info.main,.62)),N(g.Switch,"successDisabledColor",W(Se,g.success.main,.62)),N(g.Switch,"warningDisabledColor",W(Se,g.warning.main,.62)),N(g.TableCell,"border",W(Se,W(er,g.divider,1),.88)),N(g.Tooltip,"bg",W(er,g.grey[700],.92))}if(g.mode==="dark"){N(g.Alert,"errorColor",W(Se,g.error.light,.6)),N(g.Alert,"infoColor",W(Se,g.info.light,.6)),N(g.Alert,"successColor",W(Se,g.success.light,.6)),N(g.Alert,"warningColor",W(Se,g.warning.light,.6)),N(g.Alert,"errorFilledBg",_("palette-error-dark")),N(g.Alert,"infoFilledBg",_("palette-info-dark")),N(g.Alert,"successFilledBg",_("palette-success-dark")),N(g.Alert,"warningFilledBg",_("palette-warning-dark")),N(g.Alert,"errorFilledColor",vt(()=>g.getContrastText(g.error.dark))),N(g.Alert,"infoFilledColor",vt(()=>g.getContrastText(g.info.dark))),N(g.Alert,"successFilledColor",vt(()=>g.getContrastText(g.success.dark))),N(g.Alert,"warningFilledColor",vt(()=>g.getContrastText(g.warning.dark))),N(g.Alert,"errorStandardBg",W(ve,g.error.light,.9)),N(g.Alert,"infoStandardBg",W(ve,g.info.light,.9)),N(g.Alert,"successStandardBg",W(ve,g.success.light,.9)),N(g.Alert,"warningStandardBg",W(ve,g.warning.light,.9)),N(g.Alert,"errorIconColor",_("palette-error-main")),N(g.Alert,"infoIconColor",_("palette-info-main")),N(g.Alert,"successIconColor",_("palette-success-main")),N(g.Alert,"warningIconColor",_("palette-warning-main")),N(g.AppBar,"defaultBg",_("palette-grey-900")),N(g.AppBar,"darkBg",_("palette-background-paper")),N(g.AppBar,"darkColor",_("palette-text-primary")),N(g.Avatar,"defaultBg",_("palette-grey-600")),N(g.Button,"inheritContainedBg",_("palette-grey-800")),N(g.Button,"inheritContainedHoverBg",_("palette-grey-700")),N(g.Chip,"defaultBorder",_("palette-grey-700")),N(g.Chip,"defaultAvatarColor",_("palette-grey-300")),N(g.Chip,"defaultIconColor",_("palette-grey-300")),N(g.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),N(g.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),N(g.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),N(g.LinearProgress,"primaryBg",W(ve,g.primary.main,.5)),N(g.LinearProgress,"secondaryBg",W(ve,g.secondary.main,.5)),N(g.LinearProgress,"errorBg",W(ve,g.error.main,.5)),N(g.LinearProgress,"infoBg",W(ve,g.info.main,.5)),N(g.LinearProgress,"successBg",W(ve,g.success.main,.5)),N(g.LinearProgress,"warningBg",W(ve,g.warning.main,.5)),N(g.Skeleton,"bg",w?W(er,g.text.primary,.13):`rgba(${_("palette-text-primaryChannel")} / 0.13)`),N(g.Slider,"primaryTrack",W(ve,g.primary.main,.5)),N(g.Slider,"secondaryTrack",W(ve,g.secondary.main,.5)),N(g.Slider,"errorTrack",W(ve,g.error.main,.5)),N(g.Slider,"infoTrack",W(ve,g.info.main,.5)),N(g.Slider,"successTrack",W(ve,g.success.main,.5)),N(g.Slider,"warningTrack",W(ve,g.warning.main,.5));const V=w?W(Se,g.background.default,.985):fo(g.background.default,.98);N(g.SnackbarContent,"bg",V),N(g.SnackbarContent,"color",vt(()=>w?Yi.text.primary:g.getContrastText(V))),N(g.SpeedDialAction,"fabHoverBg",fo(g.background.paper,.15)),N(g.StepConnector,"border",_("palette-grey-600")),N(g.StepContent,"border",_("palette-grey-600")),N(g.Switch,"defaultColor",_("palette-grey-300")),N(g.Switch,"defaultDisabledColor",_("palette-grey-600")),N(g.Switch,"primaryDisabledColor",W(ve,g.primary.main,.55)),N(g.Switch,"secondaryDisabledColor",W(ve,g.secondary.main,.55)),N(g.Switch,"errorDisabledColor",W(ve,g.error.main,.55)),N(g.Switch,"infoDisabledColor",W(ve,g.info.main,.55)),N(g.Switch,"successDisabledColor",W(ve,g.success.main,.55)),N(g.Switch,"warningDisabledColor",W(ve,g.warning.main,.55)),N(g.TableCell,"border",W(ve,W(er,g.divider,1),.68)),N(g.Tooltip,"bg",W(er,g.grey[700],.92))}Dt(g.background,"default"),Dt(g.background,"paper"),Dt(g.common,"background"),Dt(g.common,"onBackground"),Dt(g,"divider"),Object.keys(g).forEach(V=>{const Z=g[V];V!=="tonalOffset"&&Z&&typeof Z=="object"&&(Z.main&&N(g[V],"mainChannel",Qr(eo(Z.main))),Z.light&&N(g[V],"lightChannel",Qr(eo(Z.light))),Z.dark&&N(g[V],"darkChannel",Qr(eo(Z.dark))),Z.contrastText&&N(g[V],"contrastTextChannel",Qr(eo(Z.contrastText))),V==="text"&&(Dt(g[V],"primary"),Dt(g[V],"secondary")),V==="action"&&(Z.active&&Dt(g[V],"active"),Z.selected&&Dt(g[V],"selected")))})}),$=o.reduce((te,g)=>Ze(te,g),$);const T={prefix:c,disableCssColorScheme:a,shouldSkipGeneratingVar:l,getSelector:ud($),enableContrastVars:d},{vars:R,generateThemeVars:q,generateStyleSheets:X}=$c($,T);return $.vars=R,Object.entries($.colorSchemes[$.defaultColorScheme]).forEach(([te,g])=>{$[te]=g}),$.generateThemeVars=q,$.generateStyleSheets=X,$.generateSpacing=function(){return Fi(h.spacing,xn(this))},$.getColorSchemeSelector=_c(u),$.spacing=$.generateSpacing(),$.shouldSkipGeneratingVar=l,$.unstable_sxConfig={...No,...h==null?void 0:h.unstable_sxConfig},$.unstable_sx=function(g){return Lo({sx:g,theme:this})},$.toRuntimeSource=qi,$}function si(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:fn({...n===!0?{}:n.palette,mode:o})})}function fd(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],x={...a,...n?{[l]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return an(t,...o);let h=n;"palette"in t||x[l]&&(x[l]!==!0?h=x[l].palette:l==="dark"&&(h={mode:"dark"}));const b=an({...t,palette:h},...o);return b.defaultColorScheme=l,b.colorSchemes=x,b.palette.mode==="light"&&(b.colorSchemes.light={...x.light!==!0&&x.light,palette:b.palette},si(b,"dark",x.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:b.palette},si(b,"light",x.light)),b}return!n&&!("light"in x)&&l==="light"&&(x.light=!0),hd({...d,colorSchemes:x,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const gd=fd();function _t(){const t=jc(gd);return process.env.NODE_ENV!=="production"&&zo.useDebugValue(t),t[ul]||t}async function yd(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 u;if(Array.isArray(l))u=l;else if(n&&l[n]&&Array.isArray(l[n]))u=l[n];else{const h=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(h)u=l[h];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 bd(t,o){return o.map(n=>`${n.x}px ${n.y}px ${n.blur}px ${n.spread}px ${k(t.palette.common.black,n.opacity)}`).join(", ")}const vd={menu:[{x:0,y:8,blur:16,spread:4,opacity:.12},{x:0,y:4,blur:16,spread:0,opacity:.08},{x:0,y:0,blur:0,spread:1,opacity:.05}],restButton:[{x:0,y:1,blur:2,spread:0,opacity:.3},{x:0,y:1,blur:3,spread:1,opacity:.15}],restButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1},{x:0,y:1,blur:3,spread:1,opacity:.05}],hoverButton:[{x:0,y:1,blur:3,spread:0,opacity:.3},{x:0,y:4,blur:8,spread:3,opacity:.15}],pressedButton:[{x:0,y:1,blur:2,spread:0,opacity:.3}],pressedButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1}],small:[{x:0,y:2,blur:6,spread:0,opacity:.15}],cardRest:[{x:0,y:1,blur:3,spread:0,opacity:.08},{x:0,y:1,blur:2,spread:0,opacity:.06}],cardHover:[{x:0,y:4,blur:16,spread:0,opacity:.15},{x:0,y:1,blur:4,spread:0,opacity:.08}],popover:[{x:0,y:4,blur:20,spread:0,opacity:.15},{x:0,y:1,blur:6,spread:0,opacity:.1}],flatHover:[{x:0,y:1,blur:2,spread:0,opacity:.06}]};function re(t,o){return bd(t,vd[o])}function We(t){return`${Number(t.shape.borderRadius)*1.5}px`}function so(t){return`${Number(t.shape.borderRadius)}px`}function Sd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:a}){const[c,d]=p.useState(""),[l,u]=p.useState(!1),[x,h]=p.useState(""),[b,m]=p.useState(null),[y,B]=p.useState(null),[v,j]=p.useState(!1),[S,I]=p.useState(""),f=p.useRef(null),[w,s]=p.useState("json"),[$,T]=p.useState(""),[R,q]=p.useState(""),[X,te]=p.useState(""),[g,_]=p.useState("idle"),[W,V]=p.useState(""),[Z,xe]=p.useState(null),[me,F]=p.useState(0),A=async P=>{if(I(""),!P.name.endsWith(".json")){I("Only .json files are allowed");return}const se=10*1024*1024;if(P.size>se){I("File size exceeds 10MB limit");return}try{const ce=await P.text();let ae;try{ae=JSON.parse(ce)}catch{I("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ae)){I("JSON must be an array of objects");return}if(ae.length===0){I("No data rows found in JSON file");return}m(P),B(ae)}catch{I("Network error — please try again")}},H=P=>{P.preventDefault();const se=P.dataTransfer.files[0];se&&A(se)},ne=async()=>{if($.trim()){_("loading"),V("");try{const P=await yd($.trim(),R.trim()||void 0,X.trim()||void 0);xe(P.data),F(P.data.length),_("ready")}catch(P){V((P==null?void 0:P.message)||"Connection failed"),_("error")}}},J=()=>{if(!c.trim()){u(!0);return}const P=w==="api"?Z:i||y;P&&(n(c.trim(),x.trim(),P),ee())},ee=()=>{d(""),u(!1),h(""),m(null),B(null),I(""),s("json"),T(""),q(""),te(""),_("idle"),V(""),xe(null),F(0),o()},le=i||y,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:P=>We(P),width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:P=>re(P,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:P=>{d(P.target.value),l&&P.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:x,onChange:P=>h(P.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsxs(r.Tabs,{value:w==="json"?0:1,onChange:(P,se)=>{s(se===0?"json":"api"),_("idle"),V("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(z.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(z.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:P=>k(P.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:P=>k(P.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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(z.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:H,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=f.current)==null?void 0:P.click()},sx:{position:"relative",border:"1.5px",borderStyle:y?"solid":"dashed",borderColor:y?"success.main":S?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:y?P=>k(P.palette.success.main,.04):S?P=>k(P.palette.error.main,.04):P=>k(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:y?P=>k(P.palette.success.main,.08):S?P=>k(P.palette.error.main,.08):P=>k(P.palette.primary.main,.08),borderColor:y?"success.dark":S?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:f,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var se;return((se=P.target.files)==null?void 0:se[0])&&A(P.target.files[0])}}),y?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:P=>k(P.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(z.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:P=>k(P.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(z.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:P=>k(P.palette.error.main,.08),border:1,borderColor:P=>k(P.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:P=>{T(P.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:P=>q(P.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(z.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:X,onChange:P=>te(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!$.trim()||g==="loading",onClick:ne,startIcon:g==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(z.Api,{}),sx:{fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:P=>k(P.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:g==="loading"?"Connecting...":"Test Connection & Load Data"}),g==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:P=>k(P.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(z.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:$})]})]}),g==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>k(P.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(z.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:{color:"primary.main",fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>k(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:J,disabled:w==="json"&&!le||w==="api"&&g!=="ready",variant:"contained",sx:{fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64,"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:v,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(z.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 ii(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const nd=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 id(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})`:k(o,nd(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${ii(n)})`:Ho(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${ii(n)})`:Vo(o,n)}})}function an(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:l={},transitions:d={},typography:c={},shape:u,colorSpace:x,...h}=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.":sr(20));const b=fn({...l,colorSpace:x}),m=Vi(t);let g=Qe(m,{mixins:Uc(m.breakpoints,i),palette:b,shadows:Xc.slice(),typography:Gc(b,c),transitions:td(d),zIndex:{...rd}});if(g=Qe(g,h),g=o.reduce((B,v)=>Qe(B,v),g),process.env.NODE_ENV!=="production"){const B=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],v=(j,S)=>{let I;for(I in j){const y=j[I];if(B.includes(I)&&Object.keys(y).length>0){if(process.env.NODE_ENV!=="production"){const C=Tc("",I);console.error([`MUI: The \`${S}\` component increases the CSS specificity of the \`${I}\` internal state.`,"You can not override it like this: ",JSON.stringify(j,null,2),"",`Instead, you need to use the '&.${C}' syntax:`,JSON.stringify({root:{[`&.${C}`]:y}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
68
+ `))}j[I]={}}}};Object.keys(g.components).forEach(j=>{const S=g.components[j].styleOverrides;S&&j.startsWith("Mui")&&v(S,j)})}return g.unstable_sxConfig={...No,...h==null?void 0:h.unstable_sxConfig},g.unstable_sx=function(v){return Lo({sx:v,theme:this})},g.toRuntimeSource=qi,id(g),g}function sd(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 ad=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=sd(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ji(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Ki(t){return t==="dark"?ad:[]}function ld(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...l}=t,d=fn({...o,colorSpace:s});return{palette:d,opacity:{...Ji(d.mode),...n},overlays:i||Ki(d.mode),...l}}function cd(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 dd=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],ud=t=>(o,n)=>{const i=t.rootSelector||":root",s=t.colorSchemeSelector;let l=s;if(s==="class"&&(l=".%s"),s==="data"&&(l="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(l=`[${s}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return dd(t.cssVarPrefix).forEach(c=>{d[c]=n[c],delete n[c]}),l==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:d}}:l?{[l.replace("%s",o)]:d,[`${i}, ${l.replace("%s",o)}`]:n}:{[i]:{...n,...d}}}if(l&&l!=="media")return`${i}, ${l.replace("%s",String(o))}`}else if(o){if(l==="media")return{[`@media (prefers-color-scheme: ${String(o)})`]:{[i]:n}};if(l)return l.replace("%s",String(o))}return i};function pd(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function N(t,o,n){!t[o]&&n&&(t[o]=n)}function eo(t){return typeof t!="string"||!t.startsWith("hsl")?t:Hi(t)}function Bt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Qr(eo(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 xd(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const St=t=>{try{return t()}catch{}},md=(t="mui")=>Dc(t);function tn(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const l=s==="dark"?"dark":"light";if(!i){o[s]=ld({...n,palette:{mode:l,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...c}=an({...i,palette:{mode:l,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:d,opacity:{...Ji(l),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Ki(l)},c}function hd(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:l="mui",nativeColor:d=!1,shouldSkipGeneratingVar:c=cd,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:x=":root",...h}=t,b=Object.keys(n)[0],m=i||(n.light&&b!=="light"?"light":b),g=md(l),{[m]:B,light:v,dark:j,...S}=n,I={...S};let y=B;if((m==="dark"&&!("dark"in n)||m==="light"&&!("light"in n))&&(y=!0),!y)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${m}\` option is either missing or invalid.`:sr(21,m));let C;d&&(C="oklch");const a=tn(C,I,y,h,m);v&&!I.light&&tn(C,I,v,void 0,"light"),j&&!I.dark&&tn(C,I,j,void 0,"dark");let A={defaultColorScheme:m,...a,cssVarPrefix:l,colorSchemeSelector:u,rootSelector:x,getCssVar:g,colorSchemes:I,font:{...Hc(a.typography),...a.font},spacing:xd(h.spacing)};Object.keys(A.colorSchemes).forEach(te=>{const f=A.colorSchemes[te].palette,_=V=>{const Z=V.split("-"),xe=Z[1],he=Z[2];return g(V,f[xe][he])};f.mode==="light"&&(N(f.common,"background","#fff"),N(f.common,"onBackground","#000")),f.mode==="dark"&&(N(f.common,"background","#000"),N(f.common,"onBackground","#fff"));function W(V,Z,xe){if(C){let he;return V===or&&(he=`transparent ${((1-xe)*100).toFixed(0)}%`),V===Se&&(he=`#000 ${(xe*100).toFixed(0)}%`),V===je&&(he=`#fff ${(xe*100).toFixed(0)}%`),`color-mix(in ${C}, ${Z}, ${he})`}return V(Z,xe)}if(pd(f,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),f.mode==="light"){N(f.Alert,"errorColor",W(Se,f.error.light,.6)),N(f.Alert,"infoColor",W(Se,f.info.light,.6)),N(f.Alert,"successColor",W(Se,f.success.light,.6)),N(f.Alert,"warningColor",W(Se,f.warning.light,.6)),N(f.Alert,"errorFilledBg",_("palette-error-main")),N(f.Alert,"infoFilledBg",_("palette-info-main")),N(f.Alert,"successFilledBg",_("palette-success-main")),N(f.Alert,"warningFilledBg",_("palette-warning-main")),N(f.Alert,"errorFilledColor",St(()=>f.getContrastText(f.error.main))),N(f.Alert,"infoFilledColor",St(()=>f.getContrastText(f.info.main))),N(f.Alert,"successFilledColor",St(()=>f.getContrastText(f.success.main))),N(f.Alert,"warningFilledColor",St(()=>f.getContrastText(f.warning.main))),N(f.Alert,"errorStandardBg",W(je,f.error.light,.9)),N(f.Alert,"infoStandardBg",W(je,f.info.light,.9)),N(f.Alert,"successStandardBg",W(je,f.success.light,.9)),N(f.Alert,"warningStandardBg",W(je,f.warning.light,.9)),N(f.Alert,"errorIconColor",_("palette-error-main")),N(f.Alert,"infoIconColor",_("palette-info-main")),N(f.Alert,"successIconColor",_("palette-success-main")),N(f.Alert,"warningIconColor",_("palette-warning-main")),N(f.AppBar,"defaultBg",_("palette-grey-100")),N(f.Avatar,"defaultBg",_("palette-grey-400")),N(f.Button,"inheritContainedBg",_("palette-grey-300")),N(f.Button,"inheritContainedHoverBg",_("palette-grey-A100")),N(f.Chip,"defaultBorder",_("palette-grey-400")),N(f.Chip,"defaultAvatarColor",_("palette-grey-700")),N(f.Chip,"defaultIconColor",_("palette-grey-700")),N(f.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),N(f.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),N(f.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),N(f.LinearProgress,"primaryBg",W(je,f.primary.main,.62)),N(f.LinearProgress,"secondaryBg",W(je,f.secondary.main,.62)),N(f.LinearProgress,"errorBg",W(je,f.error.main,.62)),N(f.LinearProgress,"infoBg",W(je,f.info.main,.62)),N(f.LinearProgress,"successBg",W(je,f.success.main,.62)),N(f.LinearProgress,"warningBg",W(je,f.warning.main,.62)),N(f.Skeleton,"bg",C?W(or,f.text.primary,.11):`rgba(${_("palette-text-primaryChannel")} / 0.11)`),N(f.Slider,"primaryTrack",W(je,f.primary.main,.62)),N(f.Slider,"secondaryTrack",W(je,f.secondary.main,.62)),N(f.Slider,"errorTrack",W(je,f.error.main,.62)),N(f.Slider,"infoTrack",W(je,f.info.main,.62)),N(f.Slider,"successTrack",W(je,f.success.main,.62)),N(f.Slider,"warningTrack",W(je,f.warning.main,.62));const V=C?W(Se,f.background.default,.6825):fo(f.background.default,.8);N(f.SnackbarContent,"bg",V),N(f.SnackbarContent,"color",St(()=>C?sn.text.primary:f.getContrastText(V))),N(f.SpeedDialAction,"fabHoverBg",fo(f.background.paper,.15)),N(f.StepConnector,"border",_("palette-grey-400")),N(f.StepContent,"border",_("palette-grey-400")),N(f.Switch,"defaultColor",_("palette-common-white")),N(f.Switch,"defaultDisabledColor",_("palette-grey-100")),N(f.Switch,"primaryDisabledColor",W(je,f.primary.main,.62)),N(f.Switch,"secondaryDisabledColor",W(je,f.secondary.main,.62)),N(f.Switch,"errorDisabledColor",W(je,f.error.main,.62)),N(f.Switch,"infoDisabledColor",W(je,f.info.main,.62)),N(f.Switch,"successDisabledColor",W(je,f.success.main,.62)),N(f.Switch,"warningDisabledColor",W(je,f.warning.main,.62)),N(f.TableCell,"border",W(je,W(or,f.divider,1),.88)),N(f.Tooltip,"bg",W(or,f.grey[700],.92))}if(f.mode==="dark"){N(f.Alert,"errorColor",W(je,f.error.light,.6)),N(f.Alert,"infoColor",W(je,f.info.light,.6)),N(f.Alert,"successColor",W(je,f.success.light,.6)),N(f.Alert,"warningColor",W(je,f.warning.light,.6)),N(f.Alert,"errorFilledBg",_("palette-error-dark")),N(f.Alert,"infoFilledBg",_("palette-info-dark")),N(f.Alert,"successFilledBg",_("palette-success-dark")),N(f.Alert,"warningFilledBg",_("palette-warning-dark")),N(f.Alert,"errorFilledColor",St(()=>f.getContrastText(f.error.dark))),N(f.Alert,"infoFilledColor",St(()=>f.getContrastText(f.info.dark))),N(f.Alert,"successFilledColor",St(()=>f.getContrastText(f.success.dark))),N(f.Alert,"warningFilledColor",St(()=>f.getContrastText(f.warning.dark))),N(f.Alert,"errorStandardBg",W(Se,f.error.light,.9)),N(f.Alert,"infoStandardBg",W(Se,f.info.light,.9)),N(f.Alert,"successStandardBg",W(Se,f.success.light,.9)),N(f.Alert,"warningStandardBg",W(Se,f.warning.light,.9)),N(f.Alert,"errorIconColor",_("palette-error-main")),N(f.Alert,"infoIconColor",_("palette-info-main")),N(f.Alert,"successIconColor",_("palette-success-main")),N(f.Alert,"warningIconColor",_("palette-warning-main")),N(f.AppBar,"defaultBg",_("palette-grey-900")),N(f.AppBar,"darkBg",_("palette-background-paper")),N(f.AppBar,"darkColor",_("palette-text-primary")),N(f.Avatar,"defaultBg",_("palette-grey-600")),N(f.Button,"inheritContainedBg",_("palette-grey-800")),N(f.Button,"inheritContainedHoverBg",_("palette-grey-700")),N(f.Chip,"defaultBorder",_("palette-grey-700")),N(f.Chip,"defaultAvatarColor",_("palette-grey-300")),N(f.Chip,"defaultIconColor",_("palette-grey-300")),N(f.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),N(f.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),N(f.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),N(f.LinearProgress,"primaryBg",W(Se,f.primary.main,.5)),N(f.LinearProgress,"secondaryBg",W(Se,f.secondary.main,.5)),N(f.LinearProgress,"errorBg",W(Se,f.error.main,.5)),N(f.LinearProgress,"infoBg",W(Se,f.info.main,.5)),N(f.LinearProgress,"successBg",W(Se,f.success.main,.5)),N(f.LinearProgress,"warningBg",W(Se,f.warning.main,.5)),N(f.Skeleton,"bg",C?W(or,f.text.primary,.13):`rgba(${_("palette-text-primaryChannel")} / 0.13)`),N(f.Slider,"primaryTrack",W(Se,f.primary.main,.5)),N(f.Slider,"secondaryTrack",W(Se,f.secondary.main,.5)),N(f.Slider,"errorTrack",W(Se,f.error.main,.5)),N(f.Slider,"infoTrack",W(Se,f.info.main,.5)),N(f.Slider,"successTrack",W(Se,f.success.main,.5)),N(f.Slider,"warningTrack",W(Se,f.warning.main,.5));const V=C?W(je,f.background.default,.985):fo(f.background.default,.98);N(f.SnackbarContent,"bg",V),N(f.SnackbarContent,"color",St(()=>C?Yi.text.primary:f.getContrastText(V))),N(f.SpeedDialAction,"fabHoverBg",fo(f.background.paper,.15)),N(f.StepConnector,"border",_("palette-grey-600")),N(f.StepContent,"border",_("palette-grey-600")),N(f.Switch,"defaultColor",_("palette-grey-300")),N(f.Switch,"defaultDisabledColor",_("palette-grey-600")),N(f.Switch,"primaryDisabledColor",W(Se,f.primary.main,.55)),N(f.Switch,"secondaryDisabledColor",W(Se,f.secondary.main,.55)),N(f.Switch,"errorDisabledColor",W(Se,f.error.main,.55)),N(f.Switch,"infoDisabledColor",W(Se,f.info.main,.55)),N(f.Switch,"successDisabledColor",W(Se,f.success.main,.55)),N(f.Switch,"warningDisabledColor",W(Se,f.warning.main,.55)),N(f.TableCell,"border",W(Se,W(or,f.divider,1),.68)),N(f.Tooltip,"bg",W(or,f.grey[700],.92))}Bt(f.background,"default"),Bt(f.background,"paper"),Bt(f.common,"background"),Bt(f.common,"onBackground"),Bt(f,"divider"),Object.keys(f).forEach(V=>{const Z=f[V];V!=="tonalOffset"&&Z&&typeof Z=="object"&&(Z.main&&N(f[V],"mainChannel",Qr(eo(Z.main))),Z.light&&N(f[V],"lightChannel",Qr(eo(Z.light))),Z.dark&&N(f[V],"darkChannel",Qr(eo(Z.dark))),Z.contrastText&&N(f[V],"contrastTextChannel",Qr(eo(Z.contrastText))),V==="text"&&(Bt(f[V],"primary"),Bt(f[V],"secondary")),V==="action"&&(Z.active&&Bt(f[V],"active"),Z.selected&&Bt(f[V],"selected")))})}),A=o.reduce((te,f)=>Qe(te,f),A);const T={prefix:l,disableCssColorScheme:s,shouldSkipGeneratingVar:c,getSelector:ud(A),enableContrastVars:d},{vars:R,generateThemeVars:G,generateStyleSheets:X}=$c(A,T);return A.vars=R,Object.entries(A.colorSchemes[A.defaultColorScheme]).forEach(([te,f])=>{A[te]=f}),A.generateThemeVars=G,A.generateStyleSheets=X,A.generateSpacing=function(){return Fi(h.spacing,xn(this))},A.getColorSchemeSelector=_c(u),A.spacing=A.generateSpacing(),A.shouldSkipGeneratingVar=c,A.unstable_sxConfig={...No,...h==null?void 0:h.unstable_sxConfig},A.unstable_sx=function(f){return Lo({sx:f,theme:this})},A.toRuntimeSource=qi,A}function si(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:fn({...n===!0?{}:n.palette,mode:o})})}function fd(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:l=n==null?void 0:n.mode,...d}=t,c=l||"light",u=s==null?void 0:s[c],x={...s,...n?{[c]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return an(t,...o);let h=n;"palette"in t||x[c]&&(x[c]!==!0?h=x[c].palette:c==="dark"&&(h={mode:"dark"}));const b=an({...t,palette:h},...o);return b.defaultColorScheme=c,b.colorSchemes=x,b.palette.mode==="light"&&(b.colorSchemes.light={...x.light!==!0&&x.light,palette:b.palette},si(b,"dark",x.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:b.palette},si(b,"light",x.light)),b}return!n&&!("light"in x)&&c==="light"&&(x.light=!0),hd({...d,colorSchemes:x,defaultColorScheme:c,...typeof i!="boolean"&&i},...o)}const gd=fd();function At(){const t=jc(gd);return process.env.NODE_ENV!=="production"&&zo.useDebugValue(t),t[ul]||t}async function yd(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const s=new AbortController,l=setTimeout(()=>s.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:s.signal})}catch(x){throw clearTimeout(l),(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(l)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let c;try{c=await d.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(c))u=c;else if(n&&c[n]&&Array.isArray(c[n]))u=c[n];else{const h=["data","results","items","records"].find(b=>c[b]&&Array.isArray(c[b]));if(h)u=c[h];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 bd(t,o){return o.map(n=>`${n.x}px ${n.y}px ${n.blur}px ${n.spread}px ${k(t.palette.common.black,n.opacity)}`).join(", ")}const vd={menu:[{x:0,y:8,blur:16,spread:4,opacity:.12},{x:0,y:4,blur:16,spread:0,opacity:.08},{x:0,y:0,blur:0,spread:1,opacity:.05}],restButton:[{x:0,y:1,blur:2,spread:0,opacity:.3},{x:0,y:1,blur:3,spread:1,opacity:.15}],restButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1},{x:0,y:1,blur:3,spread:1,opacity:.05}],hoverButton:[{x:0,y:1,blur:3,spread:0,opacity:.3},{x:0,y:4,blur:8,spread:3,opacity:.15}],pressedButton:[{x:0,y:1,blur:2,spread:0,opacity:.3}],pressedButtonLight:[{x:0,y:1,blur:2,spread:0,opacity:.1}],small:[{x:0,y:2,blur:6,spread:0,opacity:.15}],cardRest:[{x:0,y:1,blur:3,spread:0,opacity:.08},{x:0,y:1,blur:2,spread:0,opacity:.06}],cardHover:[{x:0,y:4,blur:16,spread:0,opacity:.15},{x:0,y:1,blur:4,spread:0,opacity:.08}],popover:[{x:0,y:4,blur:20,spread:0,opacity:.15},{x:0,y:1,blur:6,spread:0,opacity:.1}],flatHover:[{x:0,y:1,blur:2,spread:0,opacity:.06}]};function re(t,o){return bd(t,vd[o])}function Me(t){return`${Number(t.shape.borderRadius)*1.5}px`}function so(t){return`${Number(t.shape.borderRadius)}px`}function Sd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[l,d]=p.useState(""),[c,u]=p.useState(!1),[x,h]=p.useState(""),[b,m]=p.useState(null),[g,B]=p.useState(null),[v,j]=p.useState(!1),[S,I]=p.useState(""),y=p.useRef(null),[C,a]=p.useState("json"),[A,T]=p.useState(""),[R,G]=p.useState(""),[X,te]=p.useState(""),[f,_]=p.useState("idle"),[W,V]=p.useState(""),[Z,xe]=p.useState(null),[he,L]=p.useState(0),$=async P=>{if(I(""),!P.name.endsWith(".json")){I("Only .json files are allowed");return}const se=10*1024*1024;if(P.size>se){I("File size exceeds 10MB limit");return}try{const ce=await P.text();let ae;try{ae=JSON.parse(ce)}catch{I("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ae)){I("JSON must be an array of objects");return}if(ae.length===0){I("No data rows found in JSON file");return}m(P),B(ae)}catch{I("Network error — please try again")}},H=P=>{P.preventDefault();const se=P.dataTransfer.files[0];se&&$(se)},ne=async()=>{if(A.trim()){_("loading"),V("");try{const P=await yd(A.trim(),R.trim()||void 0,X.trim()||void 0);xe(P.data),L(P.data.length),_("ready")}catch(P){V((P==null?void 0:P.message)||"Connection failed"),_("error")}}},q=()=>{if(!l.trim()){u(!0);return}const P=C==="api"?Z:i||g;P&&(n(l.trim(),x.trim(),P),ee())},ee=()=>{d(""),u(!1),h(""),m(null),B(null),I(""),a("json"),T(""),G(""),te(""),_("idle"),V(""),xe(null),L(0),o()},le=i||g,ie=c&&!l.trim();return l.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:ee,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:P=>Me(P),width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:P=>re(P,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:l,onChange:P=>{d(P.target.value),c&&P.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:x,onChange:P=>h(P.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsxs(r.Tabs,{value:C==="json"?0:1,onChange:(P,se)=>{a(se===0?"json":"api"),_("idle"),V("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(z.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(z.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),C==="json"&&e.jsx(r.Box,{children:i?e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:P=>k(P.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:P=>k(P.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(z.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:H,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=y.current)==null?void 0:P.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?P=>k(P.palette.success.main,.04):S?P=>k(P.palette.error.main,.04):P=>k(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?P=>k(P.palette.success.main,.08):S?P=>k(P.palette.error.main,.08):P=>k(P.palette.primary.main,.08),borderColor:g?"success.dark":S?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:y,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var se;return((se=P.target.files)==null?void 0:se[0])&&$(P.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:P=>k(P.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(z.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:P=>k(P.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(z.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:P=>k(P.palette.error.main,.08),border:1,borderColor:P=>k(P.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:S})})]})]})]})}),C==="api"&&e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx(r.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:A,onChange:P=>{T(P.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:P=>G(P.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(z.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:X,onChange:P=>te(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!A.trim()||f==="loading",onClick:ne,startIcon:f==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(z.Api,{}),sx:{fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:P=>k(P.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:f==="loading"?"Connecting...":"Test Connection & Load Data"}),f==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:P=>k(P.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(z.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:[he.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:A})]})]}),f==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>k(P.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(z.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:{color:"primary.main",fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>k(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:q,disabled:C==="json"&&!le||C==="api"&&f!=="ready",variant:"contained",sx:{fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64,"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:v,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(z.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:()=>j(!1),variant:"contained",sx:{fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64},children:"Got it"})})]})]})}function Xi({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:n=>We(n),maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:n=>re(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(z.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:`[
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",sx:{fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64},children:"Got it"})})]})]})}function Xi({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:n=>Me(n),maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:n=>re(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(z.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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:n=>`${n.shape.borderRadius}px`,boxShadow:n=>re(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>re(n,"hoverButton")},"&:active":{boxShadow:n=>re(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function jd({onFileUpload:t,onError:o,isUploading:n}){const[i,a]=p.useState(!1),[c,d]=p.useState(""),[l,u]=p.useState(!1),x=p.useRef(null),h=async S=>{if(!S.name.endsWith(".json")){o("Only .json files are allowed");return}const I=10*1024*1024;if(S.size>I){o("File size exceeds 10MB limit");return}d(S.name);try{const f=await S.text();let w;try{w=JSON.parse(f)}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)},m=S=>{S.preventDefault(),a(!1)},y=S=>{S.preventDefault(),a(!1);const I=S.dataTransfer.files[0];I&&h(I)},B=()=>{var S;(S=x.current)==null||S.click()},v=S=>{var f;const I=(f=S.target.files)==null?void 0:f[0];I&&h(I)},j=S=>{S.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:m,onDrop:y,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=>k(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:x,type:"file",accept:".json",onChange:v,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=>k(S.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.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(z.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(Xi,{isOpen:l,onClose:()=>u(!1)})]})}function Cd({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=>k(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(z.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 wd({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=>k(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=>k(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.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(z.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Zi({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=>k(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(z.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 kd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:a,onDeleteHistory:c,disabled:d}){const[l,u]=p.useState(!1),[x,h]=p.useState(!1),[b,m]=p.useState(-1),y=p.useRef(null),B=p.useRef(null);p.useEffect(()=>{function R(q){y.current&&!y.current.contains(q.target)&&(u(!1),h(!1))}return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);const v=p.useCallback(()=>{h(!0),m(-1),n.length>0&&u(!0)},[n.length]),j=p.useCallback(R=>{o(R),m(-1)},[o]),S=p.useCallback(R=>{var q;o(R),i(R),u(!1),(q=B.current)==null||q.blur()},[o,i]),I=p.useCallback(R=>{m(-1),S(R)},[S]),f=p.useCallback(R=>{var q;R.key==="Enter"?b>=0&&b<n.length?(R.preventDefault(),I(n[b].query)):t.trim()&&S(t.trim()):R.key==="Escape"?(u(!1),m(-1),(q=B.current)==null||q.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(l||u(!0),m(X=>X<n.length-1?X+1:X))):R.key==="ArrowUp"&&(R.preventDefault(),m(X=>X>0?X-1:-1))},[b,n,t,l,I,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]),T=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:y,children:[e.jsx(r.TextField,{inputRef:B,size:"small",fullWidth:!0,value:t,onChange:R=>j(R.target.value),onFocus:v,onKeyDown:f,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:R=>k(R.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:R=>k(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(z.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(z.Close,{sx:{fontSize:16}})})}):null}}),T&&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(ai,{entry:R,isSelected:b===q,onClick:()=>I(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 X=s.length+q;return e.jsx(ai,{entry:R,isSelected:b===X,onClick:()=>I(R.query),onToggleFavourite:()=>a(R.query),onDelete:()=>c(R.query)},`recent-${R.query}`)})]})]})]})}const ai=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=>k(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>k(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(z.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(z.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(z.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function Td({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:a,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:u,onPermanentDelete:x,isReadOnly:h,isAdmin:b=!1}){const m=_t(),[y,B]=p.useState(!1),[v,j]=p.useState(!1),[S,I]=p.useState({top:0,left:0}),[f,w]=p.useState(null),s=p.useRef(null),$=p.useRef(null),T=t.find(A=>A.id===o),R=T==null?void 0:T.isDefault,q=t.filter(A=>A.scope==="global"&&!A.isDeleted),X=t.filter(A=>A.scope!=="global"&&!A.isDeleted),te=t.filter(A=>A.isFavorite&&!A.isDeleted).sort((A,H)=>(H.updatedAt||0)-(A.updatedAt||0)),g=t.filter(A=>A.isDeleted);p.useEffect(()=>{if(y&&$.current){const A=$.current.getBoundingClientRect();I({top:A.bottom+window.scrollY+8,left:A.right+window.scrollX-320})}},[y]),p.useEffect(()=>{const A=H=>{s.current&&!s.current.contains(H.target)&&$.current&&!$.current.contains(H.target)&&B(!1)};return y&&document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[y]);const _=A=>{if(n&&A!==o){w(A),B(!1);return}i(A),B(!1)},W=()=>{f&&(i(f),w(null))},V=()=>{w(null)},Z=(A,H=!1)=>{const ne=A.scope==="global",J=!h&&(!ne||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?k(m.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===A.id?k(m.palette.primary.main,.12):m.palette.action.hover}},children:[e.jsxs(r.Button,{onClick:()=>_(A.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===A.id&&e.jsx(z.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}),H&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.action.selected,px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),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:m.palette.action.hover}},title:A.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(z.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:m.palette.action.hover}},title:"Set as default",children:e.jsx(z.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:m.palette.action.hover},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:[u&&e.jsx(r.IconButton,{onClick:H=>{H.stopPropagation(),u(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Restore view",children:e.jsx(z.Undo,{sx:{fontSize:16,color:"success.main"}})}),x&&e.jsx(r.IconButton,{onClick:H=>{H.stopPropagation(),x(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Delete permanently",children:e.jsx(z.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},A.id),me=n||!R,F=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:$,onClick:()=>B(!y),size:"small",sx:{position:"relative",color:me?"warning.main":"text.secondary",bgcolor:me?k(m.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:me?k(m.palette.warning.main,.2):k(m.palette.text.primary,.06),color:me?"warning.dark":"text.primary"}},title:`View: ${(T==null?void 0:T.name)||"Default View"}`,children:[e.jsx(z.Visibility,{sx:{fontSize:20}}),F&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),y&&bi.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: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:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),q.map(A=>Z(A,A.isDefault))]}),te.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(z.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),te.map(A=>Z(A))]})]}),X.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"}),X.map(A=>Z(A))]})]}),g.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:()=>j(!v),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",g.length,")"]}),e.jsx(z.ChevronRight,{sx:{fontSize:16}})]}),v&&e.jsx(r.Box,{sx:{backgroundColor:m.palette.action.hover},children:g.map(A=>xe(A))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.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:m.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[e.jsx(z.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:m.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[e.jsx(z.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:f!==null,onClose:V,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:so(m)}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(z.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:V,variant:"text",children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",children:"Discard & switch"})]})]})]})}function Id({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:a,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:u,onSortDescending:x,onRemoveSort:h,onFilter:b,onClearFilter:m,onGroupByColumn:y,onHideColumn:B,onManageColumns:v,onManageViews:j,onResetLayout:S,onClose:I}){var te,g;const f=_t(),w=f.palette,s=p.useRef(null);p.useEffect(()=>{if(!s.current)return;const _=s.current,W=_.getBoundingClientRect(),V=window.innerWidth,Z=window.innerHeight;W.right>V-8&&(_.style.left=`${V-W.width-8}px`),W.bottom>Z-8&&(_.style.top=`${Z-W.height-8}px`)},[l]),p.useEffect(()=>{const _=V=>{s.current&&!s.current.contains(V.target)&&I()},W=V=>{V.key==="Escape"&&I()};return document.addEventListener("mousedown",_),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",W)}},[I]);const $=p.useCallback(_=>()=>{_(),I()},[I]),T=(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",X=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return bi.createPortal(e.jsxs(r.Paper,{ref:s,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:f.zIndex.tooltip,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:so(f),overflow:"hidden",boxShadow:`0 4px 20px ${k(((te=w.common)==null?void 0:te.black)??"#000",.12)}, 0 1px 4px ${k(((g=w.common)==null?void 0:g.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:T?"primary.main":"text.secondary",bgcolor:T?k(w.primary.main,.1):"transparent","&:hover":{bgcolor:k(w.primary.main,.08),color:"primary.main"}},children:e.jsx(z.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${X})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:$(()=>x(t)),sx:{p:.625,borderRadius:"6px",color:R?"primary.main":"text.secondary",bgcolor:R?k(w.primary.main,.1):"transparent","&:hover":{bgcolor:k(w.primary.main,.08),color:"primary.main"}},children:e.jsx(z.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:$(()=>h(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:k(w.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(z.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(z.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(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:k(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(z.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&y&&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:$(()=>y(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(z.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(z.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:$(v),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:k(w.primary.main,.08),color:"primary.main"}},children:e.jsx(z.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:$(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(z.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(z.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:k(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(z.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const zd=176,li="COLUMN_HEADER",Bd=p.memo(function({column:o,index:n,sortRule:i,hasFilters:a,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:u,onColumnClick:x,onMoveColumn:h,onColumnDragEnd:b,onResizeStart:m,onSortAscending:y,onSortDescending:B,onRemoveSort:v,onOpenFilterForColumn:j,onClearFiltersForColumn:S,onGroupByColumn:I,onHideColumn:f,onManageColumns:w,onManageViews:s,onResetLayout:$}){const T=p.useRef(null),[R,q]=p.useState(!1),[X,te]=p.useState({x:0,y:0}),[{handlerId:g,isOver:_},W]=At.useDrop({accept:li,collect(J){return{handlerId:J.getHandlerId(),isOver:J.isOver()}},hover(J,ee){var ge;if(!T.current)return;const le=J.index,ie=n;if(le===ie)return;const P=(ge=T.current)==null?void 0:ge.getBoundingClientRect(),se=(P.right-P.left)/2,ce=ee.getClientOffset(),ae=((ce==null?void 0:ce.x)??0)-P.left;le<ie&&ae<se||le>ie&&ae>se||(h(le,ie),J.index=ie)}}),[{isDragging:V},Z]=At.useDrag({type:li,item:()=>({index:n,columnName:o.name}),collect:J=>({isDragging:J.isDragging()}),end:()=>{b==null||b()}});Z(W(T));const xe=p.useCallback(J=>{J.preventDefault(),J.stopPropagation(),te({x:J.clientX,y:J.clientY}),q(!0)},[]),me=p.useCallback(()=>q(!1),[]),F=p.useCallback(()=>{x(o.name)},[x,o.name]),A=p.useCallback(J=>{J.stopPropagation(),j(o.name)},[j,o.name]),H=p.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(z.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(z.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]),ne=p.useCallback(()=>a?e.jsx(z.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:T,"data-handler-id":g,"data-column-index":n,onClick:F,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:V?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:_?J=>k(J.palette.primary.main,.08):"action.hover",boxShadow:J=>`0 1px 0 ${k(J.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:J=>k(J.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${zd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Xe(o.name),H(),ne()]}),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(),m(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(Id,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:a,isInSortStack:c,isReadOnly:d,hasModifications:l,position:X,onSortAscending:y,onSortDescending:B,onRemoveSort:v,onFilter:j,onClearFilter:S,onGroupByColumn:I,onHideColumn:f,onManageColumns:w,onManageViews:s,onResetLayout:$,onClose:me})]})});function Ed({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:a,onClearSelection:c,onBulkSetFavorites:d}){const[l,u]=p.useState(null),x=p.useMemo(()=>Array.from(o),[o]),h=p.useMemo(()=>x.filter(S=>n.has(S)),[x,n]),b=p.useMemo(()=>x.filter(S=>!n.has(S)),[x,n]),m=h.length>0,y=b.length>0;if(t===0)return null;const B=()=>{d&&d(x,!0)},v=()=>{d&&d(x,!1)},j=S=>{a(S),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:S=>k(S.palette.primary.main,.08),borderBottom:S=>`1px solid ${k(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(z.Close,{sx:{fontSize:16}}),size:"small",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:S=>k(S.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:S=>u(S.currentTarget),startIcon:e.jsx(z.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>k(S.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:S=>k(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&&y&&e.jsx(r.Button,{onClick:B,startIcon:e.jsx(z.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>k(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>k(S.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&m&&e.jsx(r.Button,{onClick:v,startIcon:e.jsx(z.Star,{sx:{fontSize:16,color:"warning.main"}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>k(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>k(S.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const Dd={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 Io(t,o){const n=Dd[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:k(i.main,t.palette.mode==="dark"?.24:.12),color:t.palette.mode==="dark"?i.light:i.dark}}function Od(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 Ad={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 $d(t,o){const n=Ad[o];return n?t.palette[n.hue][n.shade]:t.palette.text.secondary}function Fe(t){return k(t.palette.primary.main,t.palette.mode==="dark"?.24:.12)}function _d(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=>Io(n,o).bg,color:n=>Io(n,o).color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function Md(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 _d(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=Od(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 Rd(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 Wd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:a,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:u,onEdit:x,onDuplicate:h,onDelete:b}){const[m,y]=p.useState(null),[B,v]=p.useState(!1),{primaryCol:j,idCol:S,bodyColumns:I}=p.useMemo(()=>Rd(n),[n]),f=j?t[j.name]:null,w=S?t[S.name]:null,s=B||i||a||!!m;return e.jsxs(r.Box,{onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":$=>k($.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 ${k($.palette.primary.main,.15)}, 0 2px 8px ${k($.palette.common.black,.08)}`:B?$=>re($,"cardHover"):$=>re($,"cardRest"),transform:B&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:$=>k($.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:f!=null&&f!==""?String(f):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:[I.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:Xe($.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:Md($,t[$.name])})]},$.name)),I.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:$=>k($.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:$=>k($.palette.warning.main,.1),color:"warning.main"}},children:a?e.jsx(z.Star,{sx:{fontSize:17}}):e.jsx(z.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:$=>{$.stopPropagation(),y($.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:$=>k($.palette.text.primary,.08)}},children:e.jsx(z.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!m,anchorEl:m,onClose:()=>y(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:$=>re($,"popover")}},onClick:$=>$.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{u(t),y(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(z.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),y(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(z.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(o,t),y(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(z.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),y(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(z.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Pd({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:a=>re(a,"flatHover"),"&:hover":{bgcolor:a=>k(a.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(z.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(z.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:Ii(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=>k(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])=>Ti(c)).filter(Boolean).join(" • ")})]})}function Nd({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:a,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:u,onToggleRowSelection:x,onToggleRowFavorite:h,onToggleGroupCollapse:b,onViewRow:m,onEditRow:y,onDuplicateRow:B,onDeleteRow:v}){const j=p.useMemo(()=>{const S=new Set;return i.forEach(I=>{const f=I==null?void 0:I.__urm_row_id__;f!==void 0&&S.add(f)}),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 I=l.find(f=>f.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:I?"primary.main":"divider",bgcolor:I?f=>k(f.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:f=>k(f.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:I?600:400,color:I?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Xe(S.name)}),I?I.direction==="asc"?e.jsx(z.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(z.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(z.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,I)=>d&&S.isGroupHeader?e.jsx(Pd,{row:S,grouping:n,onToggleCollapse:b||(()=>{})},`group-${S.groupKey}`):e.jsx(Wd,{row:S,rowIndex:I,visibleColumns:o,isSelected:j.has(S==null?void 0:S.__urm_row_id__),isFavorite:a.has(S),isReadOnly:c,onToggleSelection:()=>x(S),onToggleFavorite:h,onView:m,onEdit:y,onDuplicate:B,onDelete:v},`card-${I}`))})]})}const ci=[10,15,25,50,100];function Ld(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 Fd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:a,onPageSizeChange:c}){var _;const l=_t().palette,u=Math.ceil(n/o),[x,h]=p.useState(String(t)),[b,m]=p.useState(null),[y,B]=p.useState(!1),v=p.useRef(null);p.useEffect(()=>{y||(h(String(t)),m(null))},[t,y]);const j=p.useCallback(()=>{const W=Ld(x,u);if(W){m(W);return}const V=parseInt(x.trim(),10);m(null),B(!1),V!==t&&a(V)},[x,u,t,a]),S=p.useCallback(W=>{var V;W.key==="Enter"?(W.preventDefault(),j()):W.key==="Escape"&&(h(String(t)),m(null),B(!1),(V=v.current)==null||V.blur())},[j,t]),I=p.useCallback(()=>{h(String(t)),m(null),B(!1)},[t]),f=p.useCallback(()=>{B(!0),m(null),setTimeout(()=>{var W;return(W=v.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ci))return null;const w=()=>{h(String(t)),m(null),B(!1)},s=()=>{w(),a(1)},$=()=>{w(),t>1&&a(t-1)},T=()=>{w(),t<u&&a(t+1)},R=()=>{w(),a(u)},q=(t-1)*o+1,X=Math.min(t*o,n),te=`${Math.max(2,String(u).length+.5)}ch`,g={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:ci.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,"–",X," 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:k(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${k(((_=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:k(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:v,value:x,onChange:W=>{h(W.target.value),b&&m(null)},onKeyDown:S,onFocus:f,onBlur:I,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":y?"primary.main":"divider",borderRadius:"4px",bgcolor:b?k(l.error.main,.04):y?k(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 ${k(l.error.main,.2)}`:`0 0 0 2px ${k(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:g,children:e.jsx(z.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:$,disabled:t===1,size:"small",title:"Previous page",sx:g,children:e.jsx(z.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:T,disabled:t===u,size:"small",title:"Next page",sx:g,children:e.jsx(z.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:R,disabled:t===u,size:"small",title:"Last page",sx:g,children:e.jsx(z.LastPage,{sx:{fontSize:20}})})]})]})]})}function Vd(){return e.jsx(r.Chip,{icon:e.jsx(z.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const Qi="urm_hint_seen_";function Hd(t){try{return localStorage.getItem(Qi+t)==="true"}catch{return!1}}function Ud(t){try{localStorage.setItem(Qi+t,"true")}catch{}}function di(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 ui(t){const o={fontSize:11};switch(t){case"number":return e.jsx(z.Numbers,{sx:o});case"boolean":return e.jsx(z.CheckBox,{sx:o});case"array":return e.jsx(z.DataArray,{sx:o});case"object":return e.jsx(z.DataObject,{sx:o});default:return e.jsx(z.TextFields,{sx:o})}}function pi(t,o){var n,i;switch(t){case"number":return{bg:k(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:k(((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:k(o.secondary.main,.08),color:o.secondary.main};default:return{bg:k(o.text.secondary,.07),color:o.text.secondary}}}function Yd({open:t,onClose:o,row:n,schema:i,reportName:a}){var b,m;const c=_t(),d=c.palette;if(!n)return null;const l=i.filter(y=>y.name in n),u=l.filter(y=>y.type!=="object"&&y.type!=="array"),x=l.filter(y=>y.type==="object"||y.type==="array"),h=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:We(c),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${k(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${k(((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:k(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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," · ",h," ",h===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(z.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:k(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:x.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:u.map((y,B)=>{const v=n[y.name],j=di(v,y.type),S=!j,I=pi(y.type,d),f=B===u.length-1&&u.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:f?"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:I.bg,color:I.color,flexShrink:0},children:ui(y.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:Xe(y.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:y.type==="number"?'"Roboto Mono", monospace':"inherit"},children:S?"No value":j})]},y.name)})}),x.map(y=>{const B=n[y.name],v=di(B,y.type),j=!v,S=pi(y.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:ui(y.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Xe(y.name)}),e.jsx(r.Chip,{label:y.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:k(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":v})]},y.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(z.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{fontSize:"0.8125rem",px:3,py:.75,borderRadius:y=>`${y.shape.borderRadius}px`,minWidth:80},children:"Close"})})]})}function Gd({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:a=>We(a),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:a=>re(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=>k(a.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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(z.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=>k(a.palette.error.main,.1),border:a=>`1px solid ${k(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:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:a=>`${a.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(z.DeleteForever,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"error.contrastText",px:3,py:.875,minHeight:36,borderRadius:a=>`${a.shape.borderRadius}px`,boxShadow:a=>re(a,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:a=>re(a,"hoverButton")},"&:active":{boxShadow:a=>re(a,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function rn(t){const o={fontSize:11};switch(t){case"number":return e.jsx(z.Numbers,{sx:o});case"boolean":return e.jsx(z.CheckBox,{sx:o});case"array":return e.jsx(z.DataArray,{sx:o});case"object":return e.jsx(z.DataObject,{sx:o});default:return e.jsx(z.TextFields,{sx:o})}}function xi(t,o){var n,i;switch(t){case"number":return{bg:k(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:k(((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:k(o.secondary.main,.08),color:o.secondary.main};default:return{bg:k(o.text.secondary,.07),color:o.text.secondary}}}function qd({open:t,onClose:o,onSave:n,row:i,schema:a,reportName:c}){var j,S,I;const d=_t(),l=d.palette,[u,x]=p.useState({});if(p.useEffect(()=>{t&&i&&x({...i})},[t,i]),!i)return null;const h=a.filter(f=>f.name in i),b=h.filter(f=>f.type!=="object"&&f.type!=="array"),m=h.filter(f=>f.type==="object"||f.type==="array"),y=(f,w)=>{x(s=>({...s,[f]:w}))},B=()=>{const f={...u};h.forEach(w=>{const s=u[w.name];if(w.type==="number"){const $=Number(s);f[w.name]=isNaN($)?i[w.name]:$}else w.type==="boolean"&&(f[w.name]=!!s)}),n(f),o()},v=h.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:We(d),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${k(((j=l.common)==null?void 0:j.black)??"#000",.14)}, 0 2px 8px ${k(((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:k(((I=l.warning)==null?void 0:I.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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," · ",v," ",v===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(z.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:k(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((f,w)=>{const s=u[f.name],$=xi(f.type,l),T=f.type==="boolean",R=!T&&w===b.filter(X=>X.type!=="boolean").length-1&&b.filter(X=>X.type!=="boolean").length%2!==0,q=T||R;return f.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:rn(f.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Xe(f.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:X=>y(f.name,X.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},f.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 ${k(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:k(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:rn(f.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:Xe(f.name)})]}),e.jsx(r.TextField,{value:s??"",onChange:X=>y(f.name,X.target.value),type:f.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${f.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:f.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},f.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(z.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:m.map(f=>{const w=i[f.name];let s="";try{s=w==null?"":JSON.stringify(w,null,2)}catch{s=String(w)}const $=xi(f.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:k(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:rn(f.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Xe(f.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:k(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:k(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:s||"No value"})]},f.name)})})]}),h.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(z.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",px:2,borderRadius:f=>`${f.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:B,variant:"contained",startIcon:e.jsx(z.SaveOutlined,{sx:{fontSize:15}}),sx:{fontSize:"0.8125rem",px:2.5,borderRadius:f=>`${f.shape.borderRadius}px`,minWidth:90},children:"Save"})]})]})}const kr=176,Jd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Kd(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=>Io(n,o).bg,color:n=>Io(n,o).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Xd(t){const o=t.toLowerCase().trim(),n=Jd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Zd(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 Qd(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"),u=a===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||u&&!l}function eu(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function tu(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled"},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 Kd(a);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Xd(a);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(a);if(u)return Zd(a);if(n&&!d&&!l&&!u)return eu(a);if(t.type==="date"){const x=t.dateFormat??"iso",h=ea(o,x,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:h})}if(t.type==="number"&&typeof o=="number")return o.toLocaleString();if(typeof o=="boolean")return o?"Yes":"No";if(Array.isArray(o)){if(o.length===0)return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled"},children:"[ ]"});const x=o.slice(0,3).map(h=>typeof h=="object"?JSON.stringify(h):String(h)).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 ru({schema:t,data:o,sortStack:n=[],filters:i=[],views:a=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:u={},columnOrder:x=[],columnWidths:h={},grouping:b=null,onSort:m,onSortAscending:y,onSortDescending:B,onOpenFilters:v,onOpenSort:j,onOpenFilterForColumn:S,onSelectView:I,onCreateView:f,onManageViews:w,onUpdateCurrentView:s,onSaveAsNewView:$,onToggleDefault:T,onToggleFavorite:R,onRestoreView:q,onPermanentDelete:X,isAdmin:te=!1,onExport:g,onOpenColumns:_,onUpdateColumnWidth:W,onUpdateColumnOrder:V,onUpdateColumnVisibility:Z,onClearFiltersForColumn:xe,onResetLayout:me,onOpenGroup:F,onGroupByColumn:A,onToggleGroupCollapse:H,onOpenAuditHistory:ne,onOpenScheduledReports:J,searchQuery:ee,searchHistory:le=[],onAddToSearchHistory:ie,onToggleSearchFavourite:P,onDeleteSearchHistory:se,selectedRowIds:ce=new Set,onSearchChange:ae,onToggleRowSelection:ge,onToggleAllRows:K,onRangeSelection:_e,onClearSelection:Ye,onExportSelected:it,currentPage:ar=1,pageSize:Ir=15,totalRowsBeforePagination:Vt=o.length,onPageChange:pt,onPageSizeChange:Ve,isReadOnly:Be=!1,userRole:Mt,reportName:jt,onEditRow:Qe,onDuplicateRow:Ue,onDeleteRow:et,favoriteRowIndices:lr=[],resolvedFavoritesSet:tt=new Set,showFavoritesOnly:st=!1,onToggleRowFavorite:Pe,onBulkSetFavorites:cr,showDevPanel:zr=!1,onOpenDevConfig:Ht,onToggleFavoritesFilter:xt}){var Re;const[Ct,dr]=p.useState(null),[wt,ao]=p.useState(0),[ur,Br]=p.useState(0),[kt,at]=p.useState(null),Ut=((Re=nr().dates)==null?void 0:Re.displayFormat)??null,[je,Dr]=p.useState(null),[pr,lt]=p.useState(null),[L,Ge]=p.useState(null),[Ce,He]=p.useState(!1),[Or,Yt]=p.useState(!1),[Tt,Rt]=p.useState(null),[Gt,qt]=p.useState(""),[Ar,Jt]=p.useState(!1),[Me,Q]=p.useState(null),[It,we]=p.useState(null),[ke,ct]=p.useState(null),[xr,mt]=p.useState(null),[qe,mr]=p.useState("list"),[hr,fr]=p.useState(!1),[zt,$r]=p.useState(()=>!Hd("toolbar_search"));p.useRef(null);const Wt=p.useRef(null),Kt=p.useRef(null),rt=p.useCallback(()=>{Ud("toolbar_search"),$r(!1)},[]);p.useEffect(()=>{if(!zt)return;const E=setTimeout(rt,2e3);return()=>clearTimeout(E)},[zt,rt]);const dt=p.useMemo(()=>{const E=kt??x;return E.length>0?E.map(Y=>t.find(pe=>pe.name===Y)).filter(Y=>Y!==void 0):t},[kt,x,t]),Ne=p.useMemo(()=>dt.filter(E=>u[E.name]!==!1),[dt,u]),ht=p.useMemo(()=>t.filter(E=>u[E.name]===!1).length,[t,u]),gr=p.useMemo(()=>t.map(E=>E.name),[t]),ft=p.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(gr),[x,gr]),_r=p.useCallback((E,Y)=>{E.preventDefault(),E.stopPropagation(),dr(Y),ao(E.clientX),Br(h[Y]||150)},[h]);p.useEffect(()=>{if(!Ct)return;const E=pe=>{const Le=pe.clientX-wt,de=Math.max(100,Math.min(600,ur+Le));W==null||W(Ct,de)},Y=()=>{dr(null)};return document.addEventListener("mousemove",E),document.addEventListener("mouseup",Y),()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",Y)}},[Ct,wt,ur,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 Y=n.find(pe=>pe.column===E);return Y?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[Y.direction==="asc"?e.jsx(z.ArrowUpward,{sx:{fontSize:14}}):e.jsx(z.ArrowDownward,{sx:{fontSize:14}}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"caption.fontSize",fontWeight:"bold",borderRadius:"50%"},children:Y.priority})]}):null},[n]),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(z.FilterList,{sx:{fontSize:14}})}):null,[i,S]);const Rr=p.useCallback(E=>{m&&m(E)},[m]),Wr=p.useCallback((E,Y)=>{at(pe=>{const de=[...pe??(x.length>0?x:t.map(Uo=>Uo.name))],[Et]=de.splice(E,1);return de.splice(Y,0,Et),de})},[x,t]),yr=p.useCallback(()=>{kt&&V&&V(kt),at(null)},[kt,V]),Pr=p.useCallback(E=>{if(!m)return;const Y=n.find(pe=>pe.column===E);(!Y||Y.direction!=="asc")&&m(E)},[m,n]),Nr=p.useCallback(E=>{if(!m)return;const Y=n.find(pe=>pe.column===E);Y?Y.direction==="asc"&&m(E):(m(E),setTimeout(()=>m(E),0))},[m,n]),Lr=p.useCallback(E=>{if(!m)return;const Y=n.find(pe=>pe.column===E);Y&&(Y.direction==="asc"?(m(E),setTimeout(()=>m(E),0)):Y.direction==="desc"&&m(E))},[m,n]),Pt=p.useCallback(E=>{Z&&Z(E,!1)},[Z]),br=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Fr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(E=>E===!1),Xt=(ar-1)*Ir,Ae=o,ut=p.useMemo(()=>{const E=new Set;return ce.forEach(Y=>{const pe=Y==null?void 0:Y.__urm_row_id__;pe!==void 0&&E.add(pe)}),E},[ce]);p.useEffect(()=>{const E=Y=>{!K||!Ye||Y.target instanceof HTMLInputElement||Y.target instanceof HTMLTextAreaElement||((Y.ctrlKey||Y.metaKey)&&Y.key==="a"&&(Y.preventDefault(),K(!0,Ae)),Y.key==="Escape"&&(Y.preventDefault(),Ye()))};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[K,Ye,Ae]);const Zt=p.useCallback((E,Y)=>{ge&&(Y.shiftKey&&je!==null?(Y.preventDefault(),_e&&_e(je,E,Ae)):(ge(Ae[E]),Dr(E)))},[ge,je,_e,Ae]);!p.useMemo(()=>Ae.length>0&&ut.size>0&&Ae.every(E=>ut.has(E==null?void 0:E.__urm_row_id__)),[Ae,ut])&&Ae.some(E=>ut.has(E==null?void 0:E.__urm_row_id__));const Bt=ge&&K,ue=p.useCallback(E=>{var Le;const Y=E.groupLevel,pe=Y*24;return e.jsx(r.TableRow,{onClick:()=>H==null?void 0:H(E.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Ne.length+(Bt?1:0),sx:{pl:`${pe+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[E.isCollapsed?e.jsx(z.ChevronRight,{sx:{fontSize:16}}):e.jsx(z.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:Ii(Y,((Le=b==null?void 0:b.levels[Y])==null?void 0:Le.column)||"",E.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:de=>k(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,Et])=>Ti(Et)).filter(Boolean).join(" • ")})]})})},E.groupKey)},[Ne,Bt,b,H]),he=p.useCallback((E,Y)=>{const pe=ut.has(E==null?void 0:E.__urm_row_id__),Le=pr===Y;return e.jsxs(r.TableRow,{"data-row-index":Y,onMouseEnter:()=>lt(Y),onMouseLeave:()=>lt(null),onClick:de=>{!ge||de.target.closest("[data-row-action-btn]")||Zt(Y,de)},onContextMenu:de=>{de.preventDefault(),de.stopPropagation(),ct({mouseX:de.clientX,mouseY:de.clientY,row:E,rowIndex:Y})},sx:{height:34,cursor:"pointer",bgcolor:pe?de=>k(de.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:pe?de=>k(de.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Ne.map((de,Et)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...Et===Ne.length-1&&{pr:`${Pe?76:40}px`},fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:h[de.name]?`${h[de.name]}px`:`${de.type==="date"?Math.max(kr,180):kr}px`},children:tu(de,E[de.name],Qd(de,Ne),Ut)},de.name)),e.jsx(r.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:Pe?76:40,minWidth:Pe?76:40,maxWidth:Pe?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:Le||tt.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:Le||tt.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:[Pe&&e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:de=>{de.stopPropagation(),de.preventDefault(),Pe(E)},title:tt.has(E)?"Remove from favorites":"Add to favorites",sx:{color:tt.has(E)?"warning.main":"text.secondary","&:hover":{bgcolor:de=>k(de.palette.warning.main,.08),color:"warning.main"}},children:tt.has(E)?e.jsx(z.Star,{sx:{fontSize:18}}):e.jsx(z.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:de=>{de.stopPropagation(),de.preventDefault(),ct({anchorEl:de.currentTarget,row:E,rowIndex:Y})},sx:{color:"text.secondary",opacity:Le?1:0,transition:"opacity 0.12s ease",pointerEvents:Le?"auto":"none","&:hover":{bgcolor:de=>k(de.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(z.MoreVert,{sx:{fontSize:18}})})]})})]},Y)},[ce,Xt,pr,Zt,Ne,h,Mr,Qe,Ue,et,ge,Pe,tt,Ge,He,ct]);return e.jsxs(At.DndProvider,{backend:ln.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[Bt&&it&&Ye&&e.jsx(Ed,{selectedCount:ut.size,selectedRowIds:ce,resolvedFavoritesSet:tt,viewMode:qe,onExportSelected:it,onClearSelection:Ye,onBulkSetFavorites:cr}),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(Vd,{}),ae&&ie&&P&&se&&e.jsx(r.Tooltip,{open:zt,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:rt},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(kd,{value:ee||"",onChange:E=>{zt&&rt(),ae(E)},searchHistory:le,onAddToHistory:ie,onToggleFavourite:P,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=>k(E.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(z.InfoOutlined,{sx:{fontSize:20}})})}),xt&&e.jsx(r.Tooltip,{title:st?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:xt,size:"small",disabled:Be,sx:{position:"relative",color:st?"warning.main":"text.secondary",bgcolor:st?E=>k(E.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:st?E=>k(E.palette.warning.main,.2):E=>k(E.palette.text.primary,.06),color:st?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[st?e.jsx(z.Star,{sx:{fontSize:20}}):e.jsx(z.StarBorder,{sx:{fontSize:20}}),st&&lr.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:lr.length})]})}),zr&&Ht&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:Ht,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:E=>k(E.palette.text.secondary,.3),"&:hover":{bgcolor:E=>k(E.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(z.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),I&&f&&w&&s&&a.length>0&&e.jsx(Td,{views:a||[],activeViewId:c||"",isDirty:d,onSelectView:I,onCreateView:f,onManageViews:w,onToggleDefault:T,onToggleFavorite:R,onRestoreView:q,onPermanentDelete:X,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=>Fe(E):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?E=>k(E.palette.primary.main,.2):E=>k(E.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(z.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&&v&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:v,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?E=>Fe(E):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?E=>k(E.palette.primary.main,.2):E=>k(E.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(z.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:ht>0||ft?"primary.main":"text.secondary",bgcolor:ht>0||ft?E=>Fe(E):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ht>0||ft?E=>k(E.palette.primary.main,.2):E=>k(E.palette.text.primary,.06),color:ht>0||ft?"primary.main":"text.primary"}},children:[e.jsx(z.ViewColumn,{sx:{fontSize:20}}),ht>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:ht})]})}),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:()=>mr("list"),sx:{borderRadius:1,color:qe==="list"?"primary.main":"text.secondary",bgcolor:qe==="list"?E=>Fe(E):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:qe==="list"?E=>k(E.palette.primary.main,.2):E=>k(E.palette.text.primary,.06),color:qe==="list"?"primary.main":"text.primary"}},children:e.jsx(z.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>mr("grid"),sx:{borderRadius:1,color:qe==="grid"?"primary.main":"text.secondary",bgcolor:qe==="grid"?E=>Fe(E):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:qe==="grid"?E=>k(E.palette.primary.main,.2):E=>k(E.palette.text.primary,.06),color:qe==="grid"?"primary.main":"text.primary"}},children:e.jsx(z.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=>mt(E.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:E=>k(E.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(z.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!xr,anchorEl:xr,onClose:()=>mt(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:[g&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{g(),mt(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Be&&F&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{F(),mt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),ne&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ne(),mt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.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(),mt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.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:[qe==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Nd,{data:Ae,visibleColumns:Ne,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:tt,isReadOnly:Be,isGrouped:!!br,sortStack:n,onSort:m,onToggleRowSelection:ge||(()=>{}),onToggleRowFavorite:Pe,onToggleGroupCollapse:H,onViewRow:E=>{Ge(E),He(!0)},onEditRow:(E,Y)=>{Q(E),we(Y),Jt(!0)},onDuplicateRow:(E,Y)=>Ue==null?void 0:Ue(E,Y),onDeleteRow:(E,Y)=>{Rt(Y);const pe=Object.values(Y).find(Le=>Le!=null&&Le!=="");qt(pe?String(pe):""),Yt(!0)}})}),qe==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Wt,onScroll:E=>{Kt.current&&(Kt.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:`${Ne.reduce((E,Y)=>E+(h[Y.name]||(Y.type==="date"?180:kr)),Pe?76:40)}px`},children:[e.jsxs("colgroup",{children:[Ne.map(E=>e.jsx("col",{style:{width:`${h[E.name]||(E.type==="date"?180:kr)}px`}},E.name)),e.jsx("col",{style:{width:`${Pe?76:40}px`}})]}),e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Ne.map((E,Y)=>e.jsx(Bd,{column:E,index:Y,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:Fr,width:h[E.name],onColumnClick:Rr,onMoveColumn:Wr,onColumnDragEnd:yr,onResizeStart:_r,onSortAscending:y||Pr,onSortDescending:B||Nr,onRemoveSort:Lr,onOpenFilterForColumn:S||(()=>{}),onClearFiltersForColumn:xe||(()=>{}),onGroupByColumn:A,onHideColumn:Pt,onManageColumns:_||(()=>{}),onManageViews:w,onResetLayout:me},E.name)),e.jsx(r.TableCell,{sx:{width:Pe?76:40,minWidth:Pe?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),e.jsx(r.Box,{ref:Kt,onScroll:E=>{Wt.current&&(Wt.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:`${Ne.reduce((E,Y)=>E+(h[Y.name]||(Y.type==="date"?180:kr)),Pe?76:40)}px`},children:[e.jsxs("colgroup",{children:[Ne.map(E=>e.jsx("col",{style:{width:`${h[E.name]||(E.type==="date"?180:kr)}px`}},E.name)),e.jsx("col",{style:{width:`${Pe?76:40}px`}})]}),e.jsx(r.TableBody,{children:Ae.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Ne.length+(Bt?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):br?Ae.map((E,Y)=>E.isGroupHeader?ue(E):he(E,Y)):Ae.map((E,Y)=>he(E,Y))})]})})]}),pt&&Ve&&e.jsx(Fd,{currentPage:ar,pageSize:Ir,totalRows:Vt,totalFields:t.length,onPageChange:pt,onPageSizeChange:Ve}),!(pt&&Ve)&&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:()=>ct(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&&(Ge(ke.row),He(!0)),ct(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ke&&(Q(ke.row),we(ke.rowIndex),Jt(!0)),ct(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ke&&(Ue==null||Ue(ke.rowIndex,ke.row)),ct(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.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){Rt(ke.row);const E=Object.values(ke.row).find(Y=>Y!=null&&Y!=="");qt(E?String(E):""),Yt(!0)}ct(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(z.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Yd,{open:Ce,onClose:()=>{He(!1),Ge(null)},row:L,schema:t,reportName:jt}),e.jsx(qd,{open:Ar,onClose:()=>{Jt(!1),Q(null),we(null)},onSave:E=>{It!==null&&(Qe==null||Qe(It,E))},row:Me,schema:t,reportName:jt}),e.jsx(Gd,{open:Or,onClose:()=>{Yt(!1),Rt(null)},onConfirm:()=>{Tt!==null&&(et==null||et(Tt))},rowPreview:Gt}),e.jsx(Xi,{isOpen:hr,onClose:()=>fr(!1)})]})}function ir({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=>k(a.palette.primary.main,.08)}},children:e.jsx(z.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=>k(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=>k(a.palette.warning.main,.08),border:"1px solid",borderColor:a=>k(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 sr={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 ou({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:a,onClearAll:c,onReplaceFilters:d,onClose:l,focusColumn:u}){const[x,h]=p.useState(""),[b,m]=p.useState(""),[y,B]=p.useState(""),[v,j]=p.useState([]),S=nr();p.useEffect(()=>{j([...o])},[o]),p.useEffect(()=>{u&&h(u)},[u]);const I=p.useCallback(()=>{h(""),m(""),B("")},[]),f=p.useMemo(()=>t.filter(_=>_.type!=="mixed"&&_.type!=="null"&&_.type!=="array"&&_.type!=="object"),[t]),w=t.find(_=>_.name===x),s=p.useMemo(()=>{const _=w?An(w.type):[],W=S.filter.allowedOperators;return W.length>0?_.filter(V=>W.includes(V.value)):_},[w]),$=p.useCallback(()=>!(!x||!b||po(b)&&!y.trim()||v.length>=S.filter.maxConditions),[x,b,y,v,S]),T=p.useCallback(()=>{if(!$())return;const _={column:x,operator:b};if(po(b)){const V=w==null?void 0:w.type;_.value=V==="number"?Number(y):y}if(v.some(V=>V.column===_.column&&V.operator===_.operator&&V.value===_.value)){I();return}j([...v,_]),I()},[$,x,b,w,y,v,I]),R=p.useCallback(_=>{j(v.filter((W,V)=>V!==_))},[v]),q=p.useMemo(()=>v.length!==o.length?!0:JSON.stringify(v)!==JSON.stringify(o),[v,o]),X=p.useCallback(()=>{d(v),l()},[v,d,l]),te=p.useCallback(()=>{j([...o]),I(),l()},[o,I,l]),g=p.useCallback(_=>{var xe;const W=t.find(me=>me.name===_.column);if(!W)return"";const Z=((xe=An(W.type).find(me=>me.value===_.operator))==null?void 0:xe.label)||_.operator;return po(_.operator)?`${_.column} ${Z.toLowerCase()} "${_.value}"`:`${_.column} ${Z.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:te,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:_=>k(_.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:_=>We(_),bgcolor:"background.paper",outline:"none",boxShadow:_=>re(_,"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(ir,{content:sr.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:"action.hover",color:"text.primary"}},children:e.jsx(z.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:_=>k(_.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:_=>k(_.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:v.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:x,onChange:_=>{h(_.target.value),m(""),B("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:f.map(_=>e.jsxs(r.MenuItem,{value:_.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Fe(W),"&:hover":{bgcolor:W=>k(W.palette.primary.main,.2)}}},children:[Xe(_.name)," (",_.type,")"]},_.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:_=>{m(_.target.value),B("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:s.map(_=>e.jsx(r.MenuItem,{value:_.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Fe(W),"&:hover":{bgcolor:W=>k(W.palette.primary.main,.2)}}},children:_.label},_.value))})]}),b&&po(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(w==null?void 0:w.type)==="number"?"number":"text",value:y,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:"divider",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:T,disabled:!$(),sx:{mt:1.5,fontSize:"0.875rem",color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"text.disabled"}},children:"+ Add another filter"}),v.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."]})]}),v.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 (",v.length,")"]}),e.jsx(r.Button,{onClick:()=>{c(),l()},sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:v.map((_,W)=>e.jsx(r.Chip,{label:g(_),onDelete:()=>R(W),sx:{bgcolor:V=>Fe(V),color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:V=>`1px solid ${k(V.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:V=>k(V.palette.primary.main,.2),borderColor:V=>k(V.palette.primary.main,.5)},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},W))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:te,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:_=>`${_.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:X,disabled:!q,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:_=>`${_.shape.borderRadius}px`,boxShadow:_=>re(_,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:_=>re(_,"hoverButton")},"&:active":{boxShadow:_=>re(_,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})})}const mi="SORT_RULE";function nu({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:a}){const c=p.useRef(null),[{handlerId:d},l]=At.useDrop({accept:mi,collect(h){return{handlerId:h.getHandlerId()}},hover(h,b){var I;if(!c.current)return;const m=h.index,y=o;if(m===y)return;const B=(I=c.current)==null?void 0:I.getBoundingClientRect(),v=(B.bottom-B.top)/2,j=b.getClientOffset(),S=((j==null?void 0:j.y)??0)-B.top;m<y&&S<v||m>y&&S>v||(a(m,y),h.index=y)}}),[{isDragging:u},x]=At.useDrag({type:mi,item:()=>({index:o}),collect:h=>({isDragging:h.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:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:h=>re(h,"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:h=>`0 1px 2px 0 ${k(h.palette.primary.main,.3)}`,"& .MuiChip-label":{px:0}}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:h=>n(o,h.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:h=>Fe(h),"&:hover":{bgcolor:h=>k(h.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:h=>Fe(h),"&:hover":{bgcolor:h=>k(h.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:h=>k(h.palette.error.main,.08),transform:"scale(1.1)"}},children:e.jsx(z.Close,{sx:{fontSize:18}})})]})}function iu({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]),x=nr(),h=p.useCallback(()=>!(d.length>=x.sort.maxLevels||!a||d.some(f=>f.column===a)),[d,a]),b=p.useCallback(()=>{if(!h())return;const f=d.length+1,w={column:a,direction:"asc",priority:f};l([...d,w]),c("")},[h,a,d]),m=p.useCallback(f=>{const s=d.filter(($,T)=>T!==f).map(($,T)=>({...$,priority:T+1}));l(s)},[d]),y=p.useCallback((f,w)=>{const s=[...d];s[f]={...s[f],direction:w},l(s)},[d]),B=p.useCallback((f,w)=>{const s=[...d],[$]=s.splice(f,1);s.splice(w,0,$);const T=s.map((R,q)=>({...R,priority:q+1}));l(T)},[d]),v=p.useCallback(()=>{n([]),i()},[n,i]),j=p.useCallback(()=>{n(d),i()},[d,n,i]),S=p.useCallback(()=>{l([...o]),c(""),i()},[o,i]),I=t.filter(f=>!d.some(w=>w.column===f.name));return e.jsx(At.DndProvider,{backend:ln.HTML5Backend,children:e.jsx(r.Box,{onClick:S,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:f=>k(f.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:f=>f.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:f=>f.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:f=>We(f),bgcolor:"background.paper",outline:"none",boxShadow:f=>re(f,"menu"),animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{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(ir,{content:sr.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:"action.hover",color:"text.primary"}},children:e.jsx(z.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:f=>k(f.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:f=>k(f.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled: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:f=>c(f.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:I.map(f=>e.jsx(r.MenuItem,{value:f.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:w=>Fe(w),"&:hover":{bgcolor:w=>k(w.palette.primary.main,.2)}}},children:Xe(f.name)},f.name))})]}),e.jsx(r.Button,{onClick:b,disabled:!h(),sx:{mt:1.5,fontSize:"0.875rem",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:"text.disabled"}},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:v,sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((f,w)=>e.jsx(nu,{rule:f,index:w,onToggleDirection:y,onRemove:m,onMove:B},`${f.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:"action.hover"},children:[e.jsx(r.Button,{onClick:S,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:f=>`${f.shape.borderRadius}px`,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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:f=>`${f.shape.borderRadius}px`,boxShadow:f=>re(f,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:f=>re(f,"hoverButton")},"&:active":{boxShadow:f=>re(f,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function su({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:a,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:u,isAdmin:x=!1,onClose:h}){var f,w;const b=_t(),m=b.palette,y=t.filter(s=>!s.isDeleted),B=t.filter(s=>s.isDeleted),v=y.filter(s=>s.scope==="global"),j=y.filter(s=>s.scope!=="global"),S=s=>{var X,te,g,_,W;const $=s.scope==="global",T=s.id===o,R=x||!$,q=x&&!$;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:T?"primary.main":"divider",bgcolor:T?k(m.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:T?"primary.main":k(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),h()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:T?600:500,color:T?"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(z.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:k(((X=m.info)==null?void 0:X.main)??m.primary.main,.1),color:((te=m.info)==null?void 0:te.main)??m.primary.main,border:`1px solid ${k(((g=m.info)==null?void 0:g.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:k(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:[q&&u&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:V=>{V.stopPropagation(),u(s.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((_=m.info)==null?void 0:_.main)??m.primary.main,bgcolor:k(((W=m.info)==null?void 0:W.main)??m.primary.main,.08)}},children:e.jsx(z.Language,{sx:{fontSize:16}})})}),R&&e.jsx(r.Tooltip,{title:$&&!x?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:$&&!x,onClick:V=>{V.stopPropagation(),a(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:k(m.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(z.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:$&&!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:$&&!x,onClick:V=>{V.stopPropagation(),c(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:k(m.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})})]})]})},s.id)},I=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:k(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:T=>{T.stopPropagation(),d(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:k((($=m.success)==null?void 0:$.main)??"#2e7d32",.08)}},children:e.jsx(z.Undo,{sx:{fontSize:15}})})}),l&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:T=>{T.stopPropagation(),l(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:k(m.error.main,.08)}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})]})]},s.id)};return e.jsxs(r.Dialog,{open:!0,onClose:h,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:We(b),maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${k(((f=m.common)==null?void 0:f.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:h,size:"small",sx:{color:"text.secondary"},children:e.jsx(z.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",startIcon:e.jsx(z.Add,{sx:{fontSize:16}}),size:"small",sx:{borderRadius:s=>`${s.shape.borderRadius}px`},children:"Create New View"})}),v.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(z.Language,{sx:{fontSize:14,color:((w=m.info)==null?void 0:w.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:v.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(I)})]}),y.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:h,variant:"contained",sx:{fontSize:"0.875rem",borderRadius:s=>`${s.shape.borderRadius}px`,px:3},children:"Close"})})]})}const go=50;function hi({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:a="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:u=10}){const[x,h]=p.useState(a),[b,m]=p.useState(!1),[y,B]=p.useState(c),[v,j]=p.useState(d),S=()=>{if(!x.trim()){m(!0);return}if(x.trim().length>go){m(!0);return}o(x.trim(),y.trim(),v),n()},I=w=>{w.key==="Enter"&&!w.shiftKey?S():w.key==="Escape"&&n()},f=()=>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:w=>We(w),boxShadow:w=>re(w,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[f(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(z.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:x,onChange:w=>{w.target.value.length<=go&&h(w.target.value),b&&w.target.value.trim()&&m(!1)},onKeyDown:I,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:go},error:b&&!x.trim(),helperText:b&&!x.trim()?"View name is required":`${x.length} / ${go}`}),e.jsx(r.TextField,{label:"Description (optional)",value:y,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: ",xa(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:v,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:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:w=>`${w.shape.borderRadius}px`,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(z.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:w=>`${w.shape.borderRadius}px`,boxShadow:w=>re(w,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:w=>re(w,"hoverButton")},"&:active":{boxShadow:w=>re(w,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function au({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>We(i),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:i=>re(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(z.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(z.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",sx:{fontSize:"0.875rem",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>re(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>re(i,"hoverButton")},"&:active":{boxShadow:i=>re(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const bo=100,vo=600,fi="COLUMN";function lu({column:t,index:o,isVisible:n,width:i,onToggleVisibility:a,onWidthChange:c,moveColumn:d}){const l=p.useRef(null),[u,x]=p.useState(i.toString());p.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:h},b]=At.useDrop({accept:fi,collect(I){return{handlerId:I.getHandlerId()}},hover(I,f){var X;if(!l.current)return;const w=I.index,s=o;if(w===s)return;const $=(X=l.current)==null?void 0:X.getBoundingClientRect(),T=($.bottom-$.top)/2,R=f.getClientOffset(),q=((R==null?void 0:R.y)??0)-$.top;w<s&&q<T||w>s&&q>T||(d(w,s),I.index=s)}}),[{isDragging:m},y]=At.useDrag({type:fi,item:()=>({index:o}),collect:I=>({isDragging:I.isDragging()})});y(b(l));const B=()=>{const I=parseInt(u);if(isNaN(I)){x(i.toString()),c(t.name,i);return}const f=Math.max(bo,Math.min(vo,I));x(f.toString()),c(t.name,f)},v=I=>{if(I===""||/^\d+$/.test(I)){x(I);const f=parseInt(I);if(!isNaN(f)&&f>=bo){const w=Math.min(vo,f);c(t.name,w)}}},j=I=>{I.key==="Enter"&&(I.preventDefault(),B(),I.target.blur())},S=I=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[I]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":h,sx:{opacity:m?.4:1,bgcolor:n?"background.paper":"action.hover",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"action.hover":"action.selected"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(z.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Xe(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:I=>v(I.target.value),onBlur:B,onKeyDown:j,placeholder:"150",size:"small",inputProps:{min:bo,max:vo,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"},"& input[type=number]::-webkit-inner-spin-button":{opacity:1},"& input[type=number]::-webkit-outer-spin-button":{opacity:1}}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"px"})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.IconButton,{onClick:()=>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:"action.hover",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(z.Visibility,{sx:{fontSize:20}}):e.jsx(z.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?I=>k(I.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function cu({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:a=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:u,onResetLayout:x,onSaveToCurrentView:h,onSaveToAllViews:b,onSelectView:m,onClose:y}){const[B,v]=p.useState(!1),[j,S]=p.useState(n),[I,f]=p.useState(i),[w,s]=p.useState("all"),[$,T]=p.useState(null);p.useEffect(()=>{S(n)},[n]),p.useEffect(()=>{f(i)},[i]);const R=(F,A)=>{f(H=>({...H,[F]:A})),u==null||u(F,A)},q=(F,A)=>{const H=[...j],[ne]=H.splice(F,1);H.splice(A,0,ne),S(H),l(H)},X=()=>{x(),v(!1)},g=j.map(F=>t.find(A=>A.name===F)).filter(F=>F!==void 0).filter(F=>{const A=o[F.name]??!0;return w==="active"?A:w==="hidden"?!A:!0}),_=Object.values(o).filter(F=>F).length,W=t.length,V=a.find(F=>F.id===c),Z=a.filter(F=>!F.isDeleted),xe=Z.length>1,me=p.useMemo(()=>{if(!V)return!1;const F=V.snapshot,A=F.columnVisibility??{},H=JSON.stringify(o)!==JSON.stringify(A),ne=F.columnOrder??[],J=n??[],ee=JSON.stringify(J)!==JSON.stringify(ne)&&!(J.length===0&&ne.length===0),le=F.columnWidths??{},ie=JSON.stringify(I)!==JSON.stringify(le);return H||ee||ie},[V,o,n,I]);return e.jsx(At.DndProvider,{backend:ln.HTML5Backend,children:e.jsx(r.Box,{onClick:y,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:F=>k(F.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:F=>F.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:F=>F.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:F=>We(F),bgcolor:"background.paper",outline:"none",boxShadow:F=>re(F,"menu"),animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2,pb:1.5,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.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(ir,{content:sr.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"]})]}),Z.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:F=>T(F.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(z.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",fontSize:"0.875rem",color:"text.primary",borderColor:"divider",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(V==null?void 0:V.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:$,open:!!$,onClose:()=>T(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:F=>re(F,"small")}},children:Z.map(F=>e.jsx(r.MenuItem,{onClick:()=>{m(F.id),T(null)},selected:F.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:A=>Fe(A),"&:hover":{bgcolor:A=>k(A.palette.primary.main,.2)}}},children:F.name},F.id))})]}),e.jsx(r.IconButton,{onClick:y,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:w,onChange:(F,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:F=>k(F.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:F=>k(F.palette.text.primary,.3)}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"action.hover",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:"action.hover",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:"action.hover",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: ${bo}px, max: ${vo}px)`,arrow:!0,placement:"top",children:e.jsx(z.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:"action.hover",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:g.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"})})}):g.map((F,A)=>e.jsx(lu,{column:F,index:A,isVisible:o[F.name]??!0,width:I[F.name]||170,onToggleVisibility:d,onWidthChange:R,moveColumn:q},F.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:"action.hover"},children:[e.jsx(r.Button,{onClick:()=>v(!0),disabled:!me,variant:"outlined",startIcon:e.jsx(z.Undo,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",px:2.5,py:.875,minHeight:36,borderRadius:F=>`${F.shape.borderRadius}px`,"&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[h&&e.jsx(r.Button,{onClick:()=>{h(I),y()},disabled:!me,variant:"contained",startIcon:e.jsx(z.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>re(F,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:F=>re(F,"hoverButton")},"&:active":{boxShadow:F=>re(F,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to current view"}),b&&xe&&e.jsx(r.Button,{onClick:()=>{b(I),y()},disabled:!me||!xe,variant:"contained",startIcon:e.jsx(z.GridView,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>re(F,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:F=>re(F,"hoverButton")},"&:active":{boxShadow:F=>re(F,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to all views"})]})]}),B&&e.jsx(r.Box,{onClick:()=>v(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:F=>k(F.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:F=>F.zIndex.tooltip},children:e.jsxs(r.Paper,{onClick:F=>F.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:F=>so(F),bgcolor:"background.paper",boxShadow:F=>re(F,"menu")},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:()=>v(!1),variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,borderRadius:F=>`${F.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:X,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>re(F,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:F=>re(F,"hoverButton")},"&:active":{boxShadow:F=>re(F,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function du({schema:t,grouping:o,onApply:n,onClose:i}){var $;const[a,c]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=p.useState(""),[u,x]=p.useState(null),h=p.useMemo(()=>aa(t),[t]),b=p.useMemo(()=>h.filter(T=>!a.levels.some((R,q)=>R.column===T.name&&q!==u)),[h,a.levels,u]),m=nr(),y=a.levels.length<m.grouping.maxLevels&&b.length>0,B=p.useCallback(()=>{!y||!d||(c({...a,levels:[...a.levels,{column:d}],enabled:!0}),l(""))},[y,d,a]),v=p.useCallback(T=>{const R=a.levels.filter((q,X)=>X!==T);if(R.length===0){n(null),i();return}c({...a,levels:R,enabled:R.length>0})},[a,n,i]),j=p.useCallback(T=>{x(T),l(a.levels[T].column)},[a.levels]),S=p.useCallback(()=>{if(u===null||!d)return;const T=[...a.levels];T[u]={column:d},c({...a,levels:T}),x(null),l("")},[u,d,a]),I=p.useCallback(()=>{x(null),l("")},[]),f=p.useCallback((T,R)=>{const q=R==="up"?T-1:T+1;if(q<0||q>=a.levels.length)return;const X=[...a.levels],[te]=X.splice(T,1);X.splice(q,0,te),c({...a,levels:X})},[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:T=>k(T.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:T=>T.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:T=>T.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:T=>We(T),bgcolor:"background.paper",outline:"none",boxShadow:T=>re(T,"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(ir,{content:sr.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:T=>k(T.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:T=>k(T.palette.text.primary,.3)}}},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:T=>l(T.target.value),disabled:!y,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(T=>e.jsxs(r.MenuItem,{value:T.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:R=>Fe(R),"&:hover":{bgcolor:R=>k(R.palette.primary.main,.2)}}},children:[Xe(T.name)," (",T.type.toUpperCase(),")"]},T.name))]})}),e.jsx(r.Button,{onClick:B,disabled:!y||!d,variant:"outlined",startIcon:e.jsx(z.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"action.hover"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Add group level"}),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"}),h.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:T=>`1px solid ${k(T.palette.warning.main,.5)}`,bgcolor:T=>k(T.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:T=>l(T.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:a.levels[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:T=>Fe(T)}},children:[a.levels[u].column," (",($=t.find(T=>T.name===a.levels[u].column))==null?void 0:$.type.toUpperCase(),")"]}),b.filter(T=>T.name!==a.levels[u].column).map(T=>e.jsxs(r.MenuItem,{value:T.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:R=>Fe(R)}},children:[Xe(T.name)," (",T.type.toUpperCase(),")"]},T.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:{fontSize:"0.875rem",bgcolor:"warning.main",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"warning.dark",boxShadow:T=>re(T,"pressedButton")}},children:"Save"}),e.jsx(r.Button,{onClick:I,variant:"outlined",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",py:.875,"&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},children:"Cancel"})]})]}),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:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:a.levels.map((T,R)=>{const q=t.find(X=>X.name===T.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:X=>re(X,"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:X=>`0 1px 2px 0 ${k(X.palette.primary.main,.3)}`}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:T.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:()=>f(R,"up"),disabled:R===0,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(z.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>f(R,"down"),disabled:R===a.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(z.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(R),sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover",color:"primary.main"}},children:e.jsx(z.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>v(R),sx:{color:"text.secondary","&:hover":{bgcolor:X=>k(X.palette.error.main,.08),color:"error.main"}},children:e.jsx(z.Delete,{sx:{fontSize:18}})})]})]},R)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,boxShadow:T=>re(T,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:T=>re(T,"hoverButton")},"&:active":{boxShadow:T=>re(T,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const uu={filters:z.FilterList,sorting:z.UnfoldMore,visibility:z.Visibility,order:z.ViewColumn,widths:z.Straighten,grouping:z.Layers};function pu({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:i=>We(i),boxShadow:i=>re(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(z.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=uu[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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>re(i,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:i=>re(i,"hoverButton")},"&:active":{boxShadow:i=>re(i,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})}function xu({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=>Fe(u),borderBottom:u=>`1px solid ${k(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:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:u=>k(u.palette.common.black,.08),color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:a,variant:"contained",size:"small",sx:{fontSize:"0.875rem",px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:u=>re(u,"restButton")}},children:"Save as new view"})]})]})}),d&&e.jsx(pu,{changes:n,onClose:()=>l(!1)})]})}function mu({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(z.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(z.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(z.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(z.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const gi=[{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 hu(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 fu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function gu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var B,v,j,S;const i=_t(),a=i.palette,[c,d]=p.useState("1h"),[l,u]=p.useState(!1),x=[...t].sort((I,f)=>new Date(f.timestamp).getTime()-new Date(I.timestamp).getTime()),h=gi.find(I=>I.key===c),b=hu(t,h.ms),m=()=>u(!0),y=()=>{n&&(n(fu(t,h.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:k(((B=a.common)==null?void 0:B.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:i.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:I=>I.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:We(i),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${k(((v=a.common)==null?void 0:v.black)??"#000",.14)}, 0 2px 8px ${k(((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(ir,{content:sr.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:I=>d(I.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:k(a.text.primary,.3)}},children:gi.map(I=>e.jsx(r.MenuItem,{value:I.key,sx:{fontSize:"0.8125rem"},children:I.label},I.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(z.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:m,sx:{fontSize:"0.75rem",borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:k(a.error.main,.5),"&:hover":{bgcolor:k(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(z.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:k(a.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:k(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(z.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(I=>{const f=$d(i,I.feature),{summary:w,detail:s}=Ta(I);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:k(a.text.primary,.18)}},children:[e.jsx(r.Chip,{label:Ba(I.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:k(f,.1),color:f,border:`1px solid ${k(f,.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(z.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:Ea(I.timestamp)})]}),I.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(z.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:I.user})]})]})]})]},I.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:so(i),boxShadow:`0 8px 32px ${k(((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:k(a.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.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":""]})," ",h.key==="all"?"from all time":`from the ${h.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:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:y,variant:"contained",color:"error",startIcon:e.jsx(z.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{fontSize:"0.8125rem",borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function yu({onSave:t,onClose:o}){const[n,i]=p.useState(""),[a,c]=p.useState(""),[d,l]=p.useState(""),[u,x]=p.useState([]),[h,b]=p.useState(""),[m,y]=p.useState(""),B=s=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s),v=()=>{const s=d.trim();if(s){if(!B(s)){y("Please enter a valid email address");return}if(u.includes(s)){y("This email is already added");return}x([...u,s]),l(""),y("")}},j=s=>{x(u.filter($=>$!==s))},S=s=>{s.key==="Enter"&&(s.preventDefault(),v())},I=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),a.trim(),u.length>0?u:void 0)},f=s=>{i(s),h&&b("")},w=s=>{l(s),m&&y("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:s=>k(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:s=>We(s),bgcolor:"background.paper",outline:"none",boxShadow:s=>re(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:"action.hover",color:"text.primary"}},children:e.jsx(z.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:s=>k(s.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:s=>k(s.palette.text.primary,.3)}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(z.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:s=>`1px solid ${k(s.palette.primary.main,.3)}`,bgcolor:s=>Fe(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=>f(s.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!h,helperText:h,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value: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:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:d,onChange:s=>w(s.target.value),onKeyPress:S,placeholder:"Enter email address",error:!!m,helperText:m,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(z.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),e.jsx(r.Button,{onClick:v,variant:"outlined",startIcon:e.jsx(z.Add,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",px:2,py:1.25,minHeight:40,borderRadius:s=>`${s.shape.borderRadius}px`,flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},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(z.Delete,{sx:{fontSize:16}}),sx:{bgcolor:$=>Fe($),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:"action.hover"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:s=>`${s.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:I,variant:"contained",startIcon:e.jsx(z.Share,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:s=>`${s.shape.borderRadius}px`,boxShadow:s=>re(s,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:s=>re(s,"hoverButton")},"&:active":{boxShadow:s=>re(s,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function bu({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(z.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(z.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>k(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 vu({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:u=>k(u.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:u=>u.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children: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:u=>We(u),bgcolor:"background.paper",outline:"none",boxShadow:u=>re(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(z.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=>k(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(z.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:"background.paper",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:x=>re(x,"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(z.Delete,{sx:{fontSize:16}}),sx:{fontSize:"0.8125rem",color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:x=>`${x.shape.borderRadius}px`,"&:hover":{borderColor:"error.main",bgcolor:x=>k(x.palette.error.main,.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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:u=>`${u.shape.borderRadius}px`,boxShadow:u=>re(u,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:u=>re(u,"hoverButton")},"&:active":{boxShadow:u=>re(u,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const es={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},Su=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],ju=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function Cu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const a=ju.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=>Su.some(x=>x.test(u))).length/d.length>.6),(a||c)&&n.push(i.name)}return n}function gn(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 u=l.reduce((x,h)=>x+h.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 wu(t,o){const n=gn(t,o);return Math.ceil(n*3.5)}function ku(t,o){const n=gn(t,o);return Math.ceil(n*.7)}function Tu(t,o,n){switch(t){case"csv":return gn(o,n);case"excel":return ku(o,n);case"json":return wu(o,n)}}function yi(t,o){return Math.ceil(t/o)}function Iu(t,o,n,i,a=es){const c=[],d=Tu(t,o,n),l=o.length;if(l>a.maxRowsHard){const h=yi(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 ${h} smaller exports of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:a.maxRowsHard})}else if(l>a.maxRows){const h=yi(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 ${h} smaller export${h>1?"s":""} of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:a.maxRows})}if(d>a.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${to(d)} exceeds the ${to(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 ${to(d)}`,detail:`This exceeds the recommended ${to(a.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:a.maxFileSizeBytes}),t!=="excel"){const h=Cu(i.filter(b=>n.includes(b.name)),o);if(h.length>0){const b=h.length>a.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${h.length>1?"s":""} detected: ${h.map(m=>`"${m.replace(/_/g," ")}"`).join(", ")}`,detail:b?`Exporting ${h.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:h.length,limit:a.maxImageColumns})}}const u=c.some(h=>h.severity==="error"),x=c.some(h=>h.severity==="warning");return{violations:c,hasBlockingViolation:u,hasWarning:x,estimatedBytes:d}}function to(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function zu({violation:t}){const n=_t().palette,i=t.severity==="error",a=i?n.error.main:n.warning.main,c=k(i?n.error.main:n.warning.main,.06),d=i?k(n.error.main,.25):k(n.warning.main,.3),l=i?z.ErrorOutline:z.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(z.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function Bu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:a,schema:c,sampleRows:d=[],allRows:l=[],processedRows:u=[],onExport:x,onClose:h}){var _,W,V;const b=_t(),m=b.palette,y=nr(),[B,v]=p.useState(y.export.allowedFormats[0]||"csv"),[j,S]=p.useState("visible"),[I,f]=p.useState("visible"),w=j==="visible"?o:t,s=I==="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]),T=p.useMemo(()=>I==="all"?c.map(Z=>Z.name):c.map(Z=>Z.name).slice(0,i),[I,c,i]),R=p.useMemo(()=>Iu(B,$,T,c,es),[B,$,T,c]),q=()=>{R.hasBlockingViolation||(x({format:B,scope:j,columnScope:I}),h())},X={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"}},g={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:h,sx:{position:"fixed",inset:0,bgcolor:k(((_=m.common)==null?void 0:_.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:b.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:Z=>Z.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:We(b),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${k(((W=m.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${k(((V=m.common)==null?void 0:V.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(ir,{content:sr.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:h,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:k(m.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((Z,xe)=>e.jsx(zu,{violation:Z},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:Z=>v(Z.target.value),children:[y.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:g}),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}}),y.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:g}),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}}),y.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:g}),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:Z=>S(Z.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:g}),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:g}),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:I,onChange:Z=>f(Z.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:g}),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:g}),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:X[B]},{label:"Rows to export",value:w.toLocaleString()},{label:"Columns to export",value:String(s)},{label:"Estimated file size",value:to(R.estimatedBytes),highlight:R.hasBlockingViolation?"error.main":R.hasWarning?"warning.main":void 0}].map(({label:Z,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:Z}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:me??"text.primary"},children:xe})]},Z))})]})]}),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:k(m.text.primary,.015)},children:[R.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(z.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:h,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:q,disabled:R.hasBlockingViolation,variant:"contained",startIcon:e.jsx(z.Download,{sx:{fontSize:16}}),sx:{fontSize:"0.875rem",px:2.5,borderRadius:"8px"},children:["Download ",X[B]]})]})]})})}function Eu({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(z.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(z.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 Du({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(z.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(z.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(z.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Va(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(z.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 Ou extends p.Component{constructor(n){super(n);Yr(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){rr.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=>k(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(z.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=>k(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(z.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Au({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(z.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(z.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Kr({children:t,feature:o,onError:n}){return e.jsx(Ou,{context:o,onError:(i,a)=>{n&&n(i)},fallback:e.jsx(Au,{feature:o}),children:t})}const $u=[{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"}],_u=[{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 Xr({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 Mu({open:t,onClose:o,config:n,onApply:i}){const[a,c]=p.useState(0),[d,l]=p.useState(n),u=()=>l(n),x=()=>l(Je),h=()=>{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}}))},m=j=>{const S=d.filter.allowedOperators,I=S.includes(j)?S.filter(f=>f!==j):[...S,j];I.length!==0&&b.filter({allowedOperators:I})},y=j=>{const S=d.export.allowedFormats,I=S.includes(j)?S.filter(f=>f!==j):[...S,j];I.length!==0&&b.export({allowedFormats:I})},B=[{label:"Sort",icon:e.jsx(z.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(z.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(z.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(z.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(z.Download,{sx:{fontSize:17}})}],v=j=>JSON.stringify(d[j])===JSON.stringify(Je[j]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:j=>We(j),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:j=>`0 8px 32px ${k(j.palette.common.black,.2)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:j=>k(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(z.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(Xr,{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"}),!v("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(Xr,{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"}),!v("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:$u.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:()=>m(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(Xr,{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"}),!v("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(Xr,{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"}),!v("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=>k(S.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:S=>k(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(Xr,{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"}),!v("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:_u.map(j=>e.jsxs(r.Box,{onClick:()=>y(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=>k(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:()=>y(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=>k(j.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(z.RestartAlt,{sx:{fontSize:18}}),onClick:x,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:j=>k(j.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:h,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Ru=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Wu={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 So(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,x=l.getDay();let h=u-x;return h<0&&(h+=7),h===0&&l<=a&&(h=7),l.setDate(l.getDate()+h),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 Pu(t){const o=ts(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${Ru[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Wu[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function ts(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Nu(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 Lu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),a=ts(`${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 rs(t){return`urm_schedules_${t}`}function os(t){try{const o=localStorage.getItem(rs(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 ns(t,o){try{localStorage.setItem(rs(t),JSON.stringify(o))}catch{}}const Fu=[{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"}],Vu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,is={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},tr={"& .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 Hu({initial:t=is,isEditing:o=!1,onSave:n,onBack:i}){const[a,c]=p.useState(t),[d,l]=p.useState(!1),[u,x]=p.useState(!1),h=(y,B)=>c(v=>({...v,[y]:B})),b=a.email.trim().length>0&&!Vu.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:y=>k(y.palette.text.primary,.06)}},children:e.jsx(z.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:y=>{h("name",y.target.value),d&&y.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:tr}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:tr,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:a.frequency,label:"Frequency",onChange:y=>h("frequency",y.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:tr,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:a.dayOfWeek,label:"Day of week",onChange:y=>h("dayOfWeek",Number(y.target.value)),children:Fu.map(y=>e.jsx(r.MenuItem,{value:y.value,children:y.label},y.value))})]}),a.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:a.dayOfMonth,onChange:y=>h("dayOfMonth",Number(y.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:tr}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:a.time,onChange:y=>h("time",y.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:tr}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:tr,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:a.format,label:"Export format",onChange:y=>h("format",y.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:y=>h("scope",y.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:y=>h("email",y.target.value),onBlur:()=>x(!0),placeholder:"user@company.com",error:u&&b,helperText:u&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(z.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:tr}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(z.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:y=>k(y.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>m&&n(a),disabled:!m,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Uu({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>so(i),boxShadow:i=>{var a;return`0 8px 32px ${k(((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=>k(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:i=>`${i.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",sx:{fontSize:"0.8125rem",borderRadius:i=>`${i.shape.borderRadius}px`,px:2},children:"Delete"})]})]})}function Yu({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=>k(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=>k(l.palette.success.main,.1):l=>k(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:Pu(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=>k(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=>k(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(z.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>k(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: ",Nu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Lu(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=>k(l.palette.primary.main,.08)}},children:e.jsx(z.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=>k(l.palette.warning.main,.08):l=>k(l.palette.success.main,.08)}},children:d?e.jsx(z.Pause,{sx:{fontSize:15}}):e.jsx(z.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=>k(l.palette.primary.main,.08)}},children:e.jsx(z.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=>k(l.palette.error.main,.08)}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})]})]})]})}function Gu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:a}){const[c,d]=p.useState([]),[l,u]=p.useState({type:"list"}),[x,h]=p.useState(0),[b,m]=p.useState(null);p.useEffect(()=>{t&&(d(os(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const T=setInterval(()=>h(R=>R+1),3e4);return()=>clearInterval(T)},[t]);const y=p.useCallback(T=>{d(T),ns(n,T)},[n]),B=T=>{const R=So(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth),q={id:`sched-${Date.now()}`,reportId:n,name:T.name.trim(),frequency:T.frequency,dayOfWeek:T.frequency==="weekly"?T.dayOfWeek:void 0,dayOfMonth:T.frequency==="monthly"?T.dayOfMonth:void 0,time:T.time,format:T.format,scope:T.scope,email:T.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:R,runCount:0};y([...c,q]),u({type:"list"})},v=T=>{if(l.type!=="edit")return;const R=l.schedule,q=So(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth);y(c.map(X=>X.id===R.id?{...R,name:T.name.trim(),frequency:T.frequency,dayOfWeek:T.frequency==="weekly"?T.dayOfWeek:void 0,dayOfMonth:T.frequency==="monthly"?T.dayOfMonth:void 0,time:T.time,format:T.format,scope:T.scope,email:T.email.trim()||void 0,nextRunAt:q}:X)),u({type:"list"})},j=T=>{y(c.map(R=>{if(R.id!==T)return R;const q=R.isActive?R.nextRunAt:So(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:q}}))},S=T=>{a(T);const R=new Date().toISOString();y(c.map(q=>q.id===T.id?{...q,lastRunAt:R,runCount:q.runCount+1}:q))},I=T=>{const R=c.find(q=>q.id===T)??null;m(R)},f=()=>{b&&(y(c.filter(T=>T.id!==b.id)),m(null))},w=T=>({name:T.name,frequency:T.frequency,dayOfWeek:T.dayOfWeek??1,dayOfMonth:T.dayOfMonth??1,time:T.time,format:T.format,scope:T.scope,email:T.email??""}),s=l.type!=="list",$=c.filter(T=>T.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:T=>We(T),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:T=>k(T.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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(ir,{content:sr.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:T=>k(T.palette.text.primary,.06)}},children:e.jsx(z.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[s&&e.jsx(Hu,{initial:l.type==="edit"?w(l.schedule):is,isEditing:l.type==="edit",onSave:l.type==="edit"?v: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(z.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",onClick:()=>u({type:"create"}),sx:{fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),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(z.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(T=>e.jsx(Yu,{schedule:T,tick:x,onToggle:j,onRunNow:S,onEdit:R=>u({type:"edit",schedule:R}),onDelete:I},T.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:T=>k(T.palette.warning.main,.06),border:"1px solid",borderColor:T=>k(T.palette.warning.main,.2)},children:[e.jsx(z.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:T=>k(T.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Uu,{scheduleName:b.name,onConfirm:f,onCancel:()=>m(null)})]})}const qu=6e4;function Ju({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:x,onFired:h}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:x,onFired:h});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:x,onFired:h}});const m=p.useCallback(y=>{var T,R;const{reportName:B,uploadedData:v,processedData:j,schema:S,activeView:I,columnVisibility:f,columnOrder:w,filters:s,sortStack:$}=b.current;try{const q=y.scope==="all"?v:j,X=jo(q,S,s,$,I,f,w),te=`${y.name}_scheduled`;switch(y.format){case"csv":Co(X,te,{scope:y.scope});break;case"excel":wo(X,te,{scope:y.scope});break;case"json":ko(X,te,{scope:y.scope});break}if(y.email){const g=encodeURIComponent(`Scheduled Report: ${y.name}`),_=encodeURIComponent(`Your scheduled report "${y.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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:n=>`${n.shape.borderRadius}px`,boxShadow:n=>re(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>re(n,"hoverButton")},"&:active":{boxShadow:n=>re(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function jd({onFileUpload:t,onError:o,isUploading:n}){const[i,s]=p.useState(!1),[l,d]=p.useState(""),[c,u]=p.useState(!1),x=p.useRef(null),h=async S=>{if(!S.name.endsWith(".json")){o("Only .json files are allowed");return}const I=10*1024*1024;if(S.size>I){o("File size exceeds 10MB limit");return}d(S.name);try{const y=await S.text();let C;try{C=JSON.parse(y)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(C)){o("JSON must be an array of objects");return}if(C.length===0){o("No data rows found in JSON file");return}t(C)}catch{o("Network error — please try again")}finally{d("")}},b=S=>{S.preventDefault(),s(!0)},m=S=>{S.preventDefault(),s(!1)},g=S=>{S.preventDefault(),s(!1);const I=S.dataTransfer.files[0];I&&h(I)},B=()=>{var S;(S=x.current)==null||S.click()},v=S=>{var y;const I=(y=S.target.files)==null?void 0:y[0];I&&h(I)},j=S=>{S.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:m,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=>k(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:x,type:"file",accept:".json",onChange:v,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..."}),l&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:l})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:S=>k(S.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.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(z.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(Xi,{isOpen:c,onClose:()=>u(!1)})]})}function Cd({schema:t,onConfirm:o,hasConflicts:n}){return e.jsxs(r.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[e.jsxs(r.Box,{sx:{mb:2},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontWeight:600,mb:.5},children:"Schema Preview"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&e.jsxs(r.Alert,{severity:"warning",sx:{mb:2},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),e.jsx(r.TableContainer,{sx:{mb:3},children:e.jsxs(r.Table,{children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{bgcolor:"action.hover"},children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),e.jsx(r.TableBody,{children:t.map(i=>e.jsxs(r.TableRow,{sx:{bgcolor:i.hasConflict?s=>k(s.palette.warning.main,.12):"transparent"},children:[e.jsxs(r.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&e.jsx(r.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(z.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 wd({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=>k(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=>k(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.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(z.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Zi({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=>k(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(z.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 kd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:l,disabled:d}){const[c,u]=p.useState(!1),[x,h]=p.useState(!1),[b,m]=p.useState(-1),g=p.useRef(null),B=p.useRef(null);p.useEffect(()=>{function R(G){g.current&&!g.current.contains(G.target)&&(u(!1),h(!1))}return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);const v=p.useCallback(()=>{h(!0),m(-1),n.length>0&&u(!0)},[n.length]),j=p.useCallback(R=>{o(R),m(-1)},[o]),S=p.useCallback(R=>{var G;o(R),i(R),u(!1),(G=B.current)==null||G.blur()},[o,i]),I=p.useCallback(R=>{m(-1),S(R)},[S]),y=p.useCallback(R=>{var G;R.key==="Enter"?b>=0&&b<n.length?(R.preventDefault(),I(n[b].query)):t.trim()&&S(t.trim()):R.key==="Escape"?(u(!1),m(-1),(G=B.current)==null||G.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(c||u(!0),m(X=>X<n.length-1?X+1:X))):R.key==="ArrowUp"&&(R.preventDefault(),m(X=>X>0?X-1:-1))},[b,n,t,c,I,S]),C=p.useCallback(()=>{var R;o(""),(R=B.current)==null||R.focus()},[o]),a=p.useMemo(()=>n.filter(R=>R.isFavourite),[n]),A=p.useMemo(()=>n.filter(R=>!R.isFavourite),[n]),T=c&&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:v,onKeyDown:y,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:R=>k(R.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:R=>k(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(z.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:C,edge:"end",sx:{mr:-.5},children:e.jsx(z.Close,{sx:{fontSize:16}})})}):null}}),T&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[a.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"}),a.map((R,G)=>e.jsx(ai,{entry:R,isSelected:b===G,onClick:()=>I(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>l(R.query)},`fav-${R.query}`))]}),A.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[a.length>0&&e.jsx(r.Divider,{}),e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),A.map((R,G)=>{const X=a.length+G;return e.jsx(ai,{entry:R,isSelected:b===X,onClick:()=>I(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>l(R.query)},`recent-${R.query}`)})]})]})]})}const ai=p.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:l}){const d=p.useCallback(u=>{u.stopPropagation(),s()},[s]),c=p.useCallback(u=>{u.stopPropagation(),l()},[l]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?u=>k(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>k(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(z.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(z.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),e.jsx(r.IconButton,{size:"small",onClick:c,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:e.jsx(z.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function Td({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:l,onToggleDefault:d,onToggleFavorite:c,onRestoreView:u,onPermanentDelete:x,isReadOnly:h,isAdmin:b=!1}){const m=At(),[g,B]=p.useState(!1),[v,j]=p.useState(!1),[S,I]=p.useState({top:0,left:0}),[y,C]=p.useState(null),a=p.useRef(null),A=p.useRef(null),T=t.find($=>$.id===o),R=T==null?void 0:T.isDefault,G=t.filter($=>$.scope==="global"&&!$.isDeleted),X=t.filter($=>$.scope!=="global"&&!$.isDeleted),te=t.filter($=>$.isFavorite&&!$.isDeleted).sort(($,H)=>(H.updatedAt||0)-($.updatedAt||0)),f=t.filter($=>$.isDeleted);p.useEffect(()=>{if(g&&A.current){const $=A.current.getBoundingClientRect();I({top:$.bottom+window.scrollY+8,left:$.right+window.scrollX-320})}},[g]),p.useEffect(()=>{const $=H=>{a.current&&!a.current.contains(H.target)&&A.current&&!A.current.contains(H.target)&&B(!1)};return g&&document.addEventListener("mousedown",$),()=>{document.removeEventListener("mousedown",$)}},[g]);const _=$=>{if(n&&$!==o){C($),B(!1);return}i($),B(!1)},W=()=>{y&&(i(y),C(null))},V=()=>{C(null)},Z=($,H=!1)=>{const ne=$.scope==="global",q=!h&&(!ne||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===$.id?k(m.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===$.id?k(m.palette.primary.main,.12):m.palette.action.hover}},children:[e.jsxs(r.Button,{onClick:()=>_($.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===$.id&&e.jsx(z.Check,{sx:{fontSize:16,flexShrink:0}}),o!==$.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===$.id?m.palette.primary.dark:m.palette.text.primary,fontWeight:o===$.id?500:400},children:$.name}),H&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.action.selected,px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[q&&c&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),c($.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:$.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(z.Star,{sx:{fontSize:16}})}),q&&d&&!$.isDefault&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),d($.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Set as default",children:e.jsx(z.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},$.id)},xe=$=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:m.palette.action.hover},children:[e.jsx(r.Typography,{sx:{color:m.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:$.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[u&&e.jsx(r.IconButton,{onClick:H=>{H.stopPropagation(),u($.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Restore view",children:e.jsx(z.Undo,{sx:{fontSize:16,color:"success.main"}})}),x&&e.jsx(r.IconButton,{onClick:H=>{H.stopPropagation(),x($.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},title:"Delete permanently",children:e.jsx(z.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},$.id),he=n||!R,L=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:A,onClick:()=>B(!g),size:"small",sx:{position:"relative",color:he?"warning.main":"text.secondary",bgcolor:he?k(m.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:he?k(m.palette.warning.main,.2):k(m.palette.text.primary,.06),color:he?"warning.dark":"text.primary"}},title:`View: ${(T==null?void 0:T.name)||"Default View"}`,children:[e.jsx(z.Visibility,{sx:{fontSize:20}}),L&&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&&bi.createPortal(e.jsxs(r.Box,{ref:a,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:S.top,left:S.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($=>Z($,$.isDefault))]}),te.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(z.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),te.map($=>Z($))]})]}),X.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"}),X.map($=>Z($))]})]}),f.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:()=>j(!v),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",f.length,")"]}),e.jsx(z.ChevronRight,{sx:{fontSize:16}})]}),v&&e.jsx(r.Box,{sx:{backgroundColor:m.palette.action.hover},children:f.map($=>xe($))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{s(),B(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[e.jsx(z.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{l(),B(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.action.hover}},children:[e.jsx(z.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:y!==null,onClose:V,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:so(m)}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(z.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:V,variant:"text",children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",children:"Discard & switch"})]})]})]})}function Id({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:l=!1,hasModifications:d=!1,position:c,onSortAscending:u,onSortDescending:x,onRemoveSort:h,onFilter:b,onClearFilter:m,onGroupByColumn:g,onHideColumn:B,onManageColumns:v,onManageViews:j,onResetLayout:S,onClose:I}){var te,f;const y=At(),C=y.palette,a=p.useRef(null);p.useEffect(()=>{if(!a.current)return;const _=a.current,W=_.getBoundingClientRect(),V=window.innerWidth,Z=window.innerHeight;W.right>V-8&&(_.style.left=`${V-W.width-8}px`),W.bottom>Z-8&&(_.style.top=`${Z-W.height-8}px`)},[c]),p.useEffect(()=>{const _=V=>{a.current&&!a.current.contains(V.target)&&I()},W=V=>{V.key==="Escape"&&I()};return document.addEventListener("mousedown",_),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",W)}},[I]);const A=p.useCallback(_=>()=>{_(),I()},[I]),T=(n==null?void 0:n.direction)==="asc",R=(n==null?void 0:n.direction)==="desc",G=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",X=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return bi.createPortal(e.jsxs(r.Paper,{ref:a,elevation:0,sx:{position:"fixed",left:`${c.x}px`,top:`${c.y}px`,zIndex:y.zIndex.tooltip,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:so(y),overflow:"hidden",boxShadow:`0 4px 20px ${k(((te=C.common)==null?void 0:te.black)??"#000",.12)}, 0 1px 4px ${k(((f=C.common)==null?void 0:f.black)??"#000",.06)}`},children:[!l&&e.jsxs(r.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary"},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[e.jsx(r.Tooltip,{title:`Sort Ascending (${G})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(()=>u(t)),sx:{p:.625,borderRadius:"6px",color:T?"primary.main":"text.secondary",bgcolor:T?k(C.primary.main,.1):"transparent","&:hover":{bgcolor:k(C.primary.main,.08),color:"primary.main"}},children:e.jsx(z.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${X})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(()=>x(t)),sx:{p:.625,borderRadius:"6px",color:R?"primary.main":"text.secondary",bgcolor:R?k(C.primary.main,.1):"transparent","&:hover":{bgcolor:k(C.primary.main,.08),color:"primary.main"}},children:e.jsx(z.ArrowDownward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:!s,onClick:A(()=>h(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:k(C.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(z.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:A(()=>b(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(z.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&&!l&&e.jsxs(r.MenuItem,{onClick:A(()=>m(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:k(C.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(z.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!l&&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:A(()=>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(z.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:[!l&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(r.MenuItem,{onClick:A(()=>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(z.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),e.jsx(r.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(v),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:k(C.primary.main,.08),color:"primary.main"}},children:e.jsx(z.Settings,{sx:{fontSize:16}})})})]}),l&&e.jsxs(r.MenuItem,{onClick:A(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(z.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),j&&e.jsxs(r.MenuItem,{onClick:A(j),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(z.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!l&&d&&S&&e.jsxs(r.MenuItem,{onClick:A(S),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:k(C.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(z.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const zd=176,li="COLUMN_HEADER",Bd=p.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:l,isReadOnly:d=!1,hasModifications:c=!1,width:u,onColumnClick:x,onMoveColumn:h,onColumnDragEnd:b,onResizeStart:m,onSortAscending:g,onSortDescending:B,onRemoveSort:v,onOpenFilterForColumn:j,onClearFiltersForColumn:S,onGroupByColumn:I,onHideColumn:y,onManageColumns:C,onManageViews:a,onResetLayout:A}){const T=p.useRef(null),[R,G]=p.useState(!1),[X,te]=p.useState({x:0,y:0}),[{handlerId:f,isOver:_},W]=Dt.useDrop({accept:li,collect(q){return{handlerId:q.getHandlerId(),isOver:q.isOver()}},hover(q,ee){var ge;if(!T.current)return;const le=q.index,ie=n;if(le===ie)return;const P=(ge=T.current)==null?void 0:ge.getBoundingClientRect(),se=(P.right-P.left)/2,ce=ee.getClientOffset(),ae=((ce==null?void 0:ce.x)??0)-P.left;le<ie&&ae<se||le>ie&&ae>se||(h(le,ie),q.index=ie)}}),[{isDragging:V},Z]=Dt.useDrag({type:li,item:()=>({index:n,columnName:o.name}),collect:q=>({isDragging:q.isDragging()}),end:()=>{b==null||b()}});Z(W(T));const xe=p.useCallback(q=>{q.preventDefault(),q.stopPropagation(),te({x:q.clientX,y:q.clientY}),G(!0)},[]),he=p.useCallback(()=>G(!1),[]),L=p.useCallback(()=>{x(o.name)},[x,o.name]),$=p.useCallback(q=>{q.stopPropagation(),j(o.name)},[j,o.name]),H=p.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(z.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(z.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]),ne=p.useCallback(()=>s?e.jsx(z.FilterList,{onClick:$,titleAccess:"Active filter on this column — click to edit",sx:{ml:.5,fontSize:13,color:"primary.main",cursor:"pointer",flexShrink:0,"&:hover":{transform:"scale(1.15)"},transition:"transform 0.12s ease"}}):null,[s,$]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:T,"data-handler-id":f,"data-column-index":n,onClick:L,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:V?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:_?q=>k(q.palette.primary.main,.08):"action.hover",boxShadow:q=>`0 1px 0 ${k(q.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:q=>k(q.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${zd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Ze(o.name),H(),ne()]}),e.jsx(r.Box,{draggable:!1,onDragStart:q=>q.preventDefault(),sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),m(q,o.name)},onClick:q=>q.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(Id,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:l,isReadOnly:d,hasModifications:c,position:X,onSortAscending:g,onSortDescending:B,onRemoveSort:v,onFilter:j,onClearFilter:S,onGroupByColumn:I,onHideColumn:y,onManageColumns:C,onManageViews:a,onResetLayout:A,onClose:he})]})});function Ed({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:s,onClearSelection:l,onBulkSetFavorites:d}){const[c,u]=p.useState(null),x=p.useMemo(()=>Array.from(o),[o]),h=p.useMemo(()=>x.filter(S=>n.has(S)),[x,n]),b=p.useMemo(()=>x.filter(S=>!n.has(S)),[x,n]),m=h.length>0,g=b.length>0;if(t===0)return null;const B=()=>{d&&d(x,!0)},v=()=>{d&&d(x,!1)},j=S=>{s(S),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:S=>k(S.palette.primary.main,.08),borderBottom:S=>`1px solid ${k(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:l,startIcon:e.jsx(z.Close,{sx:{fontSize:16}}),size:"small",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:S=>k(S.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:S=>u(S.currentTarget),startIcon:e.jsx(z.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>k(S.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:S=>k(S.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:c,open:!!c,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(z.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>k(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>k(S.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&m&&e.jsx(r.Button,{onClick:v,startIcon:e.jsx(z.Star,{sx:{fontSize:16,color:"warning.main"}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>k(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>k(S.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const Dd={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 Io(t,o){const n=Dd[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:k(i.main,t.palette.mode==="dark"?.24:.12),color:t.palette.mode==="dark"?i.light:i.dark}}function Od(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 Ad={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 $d(t,o){const n=Ad[o];return n?t.palette[n.hue][n.shade]:t.palette.text.secondary}function Pe(t){return k(t.palette.primary.main,t.palette.mode==="dark"?.24:.12)}function _d(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=>Io(n,o).bg,color:n=>Io(n,o).color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function Md(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 _d(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=n.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:l=>{const d=Od(l,s);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 Rd(t){const o=t.find(s=>{const l=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(l)})||t[0]||null,n=t.find(s=>{const l=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(l)&&s!==o})||null,i=t.filter(s=>s!==o&&s!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function Wd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:s,isReadOnly:l,onToggleSelection:d,onToggleFavorite:c,onView:u,onEdit:x,onDuplicate:h,onDelete:b}){const[m,g]=p.useState(null),[B,v]=p.useState(!1),{primaryCol:j,idCol:S,bodyColumns:I}=p.useMemo(()=>Rd(n),[n]),y=j?t[j.name]:null,C=S?t[S.name]:null,a=B||i||s||!!m;return e.jsxs(r.Box,{onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":A=>k(A.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?A=>`0 0 0 3px ${k(A.palette.primary.main,.15)}, 0 2px 8px ${k(A.palette.common.black,.08)}`:B?A=>re(A,"cardHover"):A=>re(A,"cardRest"),transform:B&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:A=>k(A.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:y!=null&&y!==""?String(y):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:[I.map(A=>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:Ze(A.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:Md(A,t[A.name])})]},A.name)),I.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:A=>k(A.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:C?.85:0,userSelect:"none"},children:C?String(C):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:a?1:0,transition:"opacity 0.15s ease"},onClick:A=>A.stopPropagation(),children:[c&&e.jsx(r.Tooltip,{title:s?"Remove from favorites":"Add to favorites",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:A=>{A.stopPropagation(),c(t)},sx:{width:28,height:28,color:s?"warning.main":"action.disabled","&:hover":{bgcolor:A=>k(A.palette.warning.main,.1),color:"warning.main"}},children:s?e.jsx(z.Star,{sx:{fontSize:17}}):e.jsx(z.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:A=>{A.stopPropagation(),g(A.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:A=>k(A.palette.text.primary,.08)}},children:e.jsx(z.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:A=>re(A,"popover")}},onClick:A=>A.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(z.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!l&&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(z.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!l&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(z.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!l&&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(z.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Pd({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:s=>re(s,"flatHover"),"&:hover":{bgcolor:s=>k(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(z.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(z.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:Ii(t.groupLevel,((i=o==null?void 0:o.levels[t.groupLevel])==null?void 0:i.column)||"",t.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:s=>k(s.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[t.rowCount," ",t.rowCount===1?"row":"rows"]}),Object.keys(t.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(t.aggregates).map(([s,l])=>Ti(l)).filter(Boolean).join(" • ")})]})}function Nd({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:s,isReadOnly:l,isGrouped:d,sortStack:c=[],onSort:u,onToggleRowSelection:x,onToggleRowFavorite:h,onToggleGroupCollapse:b,onViewRow:m,onEditRow:g,onDuplicateRow:B,onDeleteRow:v}){const j=p.useMemo(()=>{const S=new Set;return i.forEach(I=>{const y=I==null?void 0:I.__urm_row_id__;y!==void 0&&S.add(y)}),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 I=c.find(y=>y.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:I?"primary.main":"divider",bgcolor:I?y=>k(y.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:y=>k(y.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:I?600:400,color:I?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ze(S.name)}),I?I.direction==="asc"?e.jsx(z.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(z.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(z.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,I)=>d&&S.isGroupHeader?e.jsx(Pd,{row:S,grouping:n,onToggleCollapse:b||(()=>{})},`group-${S.groupKey}`):e.jsx(Wd,{row:S,rowIndex:I,visibleColumns:o,isSelected:j.has(S==null?void 0:S.__urm_row_id__),isFavorite:s.has(S),isReadOnly:l,onToggleSelection:()=>x(S),onToggleFavorite:h,onView:m,onEdit:g,onDuplicate:B,onDelete:v},`card-${I}`))})]})}const ci=[10,15,25,50,100];function Ld(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 Fd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:l}){var _;const c=At().palette,u=Math.ceil(n/o),[x,h]=p.useState(String(t)),[b,m]=p.useState(null),[g,B]=p.useState(!1),v=p.useRef(null);p.useEffect(()=>{g||(h(String(t)),m(null))},[t,g]);const j=p.useCallback(()=>{const W=Ld(x,u);if(W){m(W);return}const V=parseInt(x.trim(),10);m(null),B(!1),V!==t&&s(V)},[x,u,t,s]),S=p.useCallback(W=>{var V;W.key==="Enter"?(W.preventDefault(),j()):W.key==="Escape"&&(h(String(t)),m(null),B(!1),(V=v.current)==null||V.blur())},[j,t]),I=p.useCallback(()=>{h(String(t)),m(null),B(!1)},[t]),y=p.useCallback(()=>{B(!0),m(null),setTimeout(()=>{var W;return(W=v.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ci))return null;const C=()=>{h(String(t)),m(null),B(!1)},a=()=>{C(),s(1)},A=()=>{C(),t>1&&s(t-1)},T=()=>{C(),t<u&&s(t+1)},R=()=>{C(),s(u)},G=(t-1)*o+1,X=Math.min(t*o,n),te=`${Math.max(2,String(u).length+.5)}ch`,f={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=>l(Number(W.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:ci.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,"–",X," 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:k(c.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${k(((_=c.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:k(c.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:v,value:x,onChange:W=>{h(W.target.value),b&&m(null)},onKeyDown:S,onFocus:y,onBlur:I,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?k(c.error.main,.04):g?k(c.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 ${k(c.error.main,.2)}`:`0 0 0 2px ${k(c.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:a,disabled:t===1,size:"small",title:"First page",sx:f,children:e.jsx(z.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:A,disabled:t===1,size:"small",title:"Previous page",sx:f,children:e.jsx(z.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:T,disabled:t===u,size:"small",title:"Next page",sx:f,children:e.jsx(z.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:R,disabled:t===u,size:"small",title:"Last page",sx:f,children:e.jsx(z.LastPage,{sx:{fontSize:20}})})]})]})]})}function Vd(){return e.jsx(r.Chip,{icon:e.jsx(z.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const Qi="urm_hint_seen_";function Hd(t){try{return localStorage.getItem(Qi+t)==="true"}catch{return!1}}function Ud(t){try{localStorage.setItem(Qi+t,"true")}catch{}}function di(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 ui(t){const o={fontSize:11};switch(t){case"number":return e.jsx(z.Numbers,{sx:o});case"boolean":return e.jsx(z.CheckBox,{sx:o});case"array":return e.jsx(z.DataArray,{sx:o});case"object":return e.jsx(z.DataObject,{sx:o});default:return e.jsx(z.TextFields,{sx:o})}}function pi(t,o){var n,i;switch(t){case"number":return{bg:k(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:k(((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:k(o.secondary.main,.08),color:o.secondary.main};default:return{bg:k(o.text.secondary,.07),color:o.text.secondary}}}function Yd({open:t,onClose:o,row:n,schema:i,reportName:s}){var b,m;const l=At(),d=l.palette;if(!n)return null;const c=i.filter(g=>g.name in n),u=c.filter(g=>g.type!=="object"&&g.type!=="array"),x=c.filter(g=>g.type==="object"||g.type==="array"),h=c.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:Me(l),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${k(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${k(((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:k(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"View Record"}),s&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s," · ",h," ",h===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(z.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:k(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:x.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:u.map((g,B)=>{const v=n[g.name],j=di(v,g.type),S=!j,I=pi(g.type,d),y=B===u.length-1&&u.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:y?"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:I.bg,color:I.color,flexShrink:0},children:ui(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:Ze(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)})}),x.map(g=>{const B=n[g.name],v=di(B,g.type),j=!v,S=pi(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:ui(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ze(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:k(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":v})]},g.name)}),c.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(z.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{fontSize:"0.8125rem",px:3,py:.75,borderRadius:g=>`${g.shape.borderRadius}px`,minWidth:80},children:"Close"})})]})}function Gd({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:s=>Me(s),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:s=>re(s,"menu")}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:s=>k(s.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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(z.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:s=>k(s.palette.error.main,.1),border:s=>`1px solid ${k(s.palette.error.main,.5)}`},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"error.main",fontWeight:500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:s=>`${s.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(z.DeleteForever,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"error.contrastText",px:3,py:.875,minHeight:36,borderRadius:s=>`${s.shape.borderRadius}px`,boxShadow:s=>re(s,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:s=>re(s,"hoverButton")},"&:active":{boxShadow:s=>re(s,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function rn(t){const o={fontSize:11};switch(t){case"number":return e.jsx(z.Numbers,{sx:o});case"boolean":return e.jsx(z.CheckBox,{sx:o});case"array":return e.jsx(z.DataArray,{sx:o});case"object":return e.jsx(z.DataObject,{sx:o});default:return e.jsx(z.TextFields,{sx:o})}}function xi(t,o){var n,i;switch(t){case"number":return{bg:k(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:k(((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:k(o.secondary.main,.08),color:o.secondary.main};default:return{bg:k(o.text.secondary,.07),color:o.text.secondary}}}function qd({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:l}){var j,S,I;const d=At(),c=d.palette,[u,x]=p.useState({});if(p.useEffect(()=>{t&&i&&x({...i})},[t,i]),!i)return null;const h=s.filter(y=>y.name in i),b=h.filter(y=>y.type!=="object"&&y.type!=="array"),m=h.filter(y=>y.type==="object"||y.type==="array"),g=(y,C)=>{x(a=>({...a,[y]:C}))},B=()=>{const y={...u};h.forEach(C=>{const a=u[C.name];if(C.type==="number"){const A=Number(a);y[C.name]=isNaN(A)?i[C.name]:A}else C.type==="boolean"&&(y[C.name]=!!a)}),n(y),o()},v=h.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:Me(d),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${k(((j=c.common)==null?void 0:j.black)??"#000",.14)}, 0 2px 8px ${k(((S=c.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:k(((I=c.warning)==null?void 0:I.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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"}),l&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[l," · ",v," ",v===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(z.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:k(c.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((y,C)=>{const a=u[y.name],A=xi(y.type,c),T=y.type==="boolean",R=!T&&C===b.filter(X=>X.type!=="boolean").length-1&&b.filter(X=>X.type!=="boolean").length%2!==0,G=T||R;return y.type==="boolean"?e.jsxs(r.Box,{sx:{gridColumn:"span 2",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",px:2,py:1.5,display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,transition:"border-color 0.15s","&:hover":{borderColor:"primary.main"}},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.25},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:rn(y.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ze(y.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:a?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!a,onChange:X=>g(y.name,X.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},y.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 ${k(c.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:k(c.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:rn(y.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:Ze(y.name)})]}),e.jsx(r.TextField,{value:a??"",onChange:X=>g(y.name,X.target.value),type:y.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${y.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:y.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},y.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(z.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:m.map(y=>{const C=i[y.name];let a="";try{a=C==null?"":JSON.stringify(C,null,2)}catch{a=String(C)}const A=xi(y.type,c);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:k(c.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:rn(y.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ze(y.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:k(c.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:a?"text.primary":"text.disabled",fontStyle:a?"normal":"italic",bgcolor:k(c.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:a||"No value"})]},y.name)})})]}),h.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(z.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",px:2,borderRadius:y=>`${y.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:B,variant:"contained",startIcon:e.jsx(z.SaveOutlined,{sx:{fontSize:15}}),sx:{fontSize:"0.8125rem",px:2.5,borderRadius:y=>`${y.shape.borderRadius}px`,minWidth:90},children:"Save"})]})]})}const Ir=176,Jd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Kd(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=>Io(n,o).bg,color:n=>Io(n,o).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Xd(t){const o=t.toLowerCase().trim(),n=Jd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Zd(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 Qd(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),s=o.findIndex(x=>x.name===t.name),l=/(\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"),c=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=s===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return l||d&&!c||u&&!c}function eu(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function tu(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled"},children:"—"});const s=String(o),l=t.name.toLowerCase().replace(/[_\s-]/g,""),d=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(d)return Kd(s);const c=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(c)return Xd(s);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(l)||/^[A-Z]{2,8}-\d{2,}$/.test(s);if(u)return Zd(s);if(n&&!d&&!c&&!u)return eu(s);if(t.type==="date"){const x=t.dateFormat??"iso",h=ea(o,x,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:h})}if(t.type==="number"&&typeof o=="number")return o.toLocaleString();if(typeof o=="boolean")return o?"Yes":"No";if(Array.isArray(o)){if(o.length===0)return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled"},children:"[ ]"});const x=o.slice(0,3).map(h=>typeof h=="object"?JSON.stringify(h):String(h)).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 s}function ru({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:l="",isDirty:d=!1,isExporting:c=!1,columnVisibility:u={},columnOrder:x=[],columnWidths:h={},grouping:b=null,onSort:m,onSortAscending:g,onSortDescending:B,onOpenFilters:v,onOpenSort:j,onOpenFilterForColumn:S,onSelectView:I,onCreateView:y,onManageViews:C,onUpdateCurrentView:a,onSaveAsNewView:A,onToggleDefault:T,onToggleFavorite:R,onRestoreView:G,onPermanentDelete:X,isAdmin:te=!1,onExport:f,onOpenColumns:_,onUpdateColumnWidth:W,onUpdateColumnOrder:V,onUpdateColumnVisibility:Z,onClearFiltersForColumn:xe,onResetLayout:he,onOpenGroup:L,onGroupByColumn:$,onToggleGroupCollapse:H,onOpenAuditHistory:ne,onOpenScheduledReports:q,searchQuery:ee,searchHistory:le=[],onAddToSearchHistory:ie,onToggleSearchFavourite:P,onDeleteSearchHistory:se,selectedRowIds:ce=new Set,onSearchChange:ae,onToggleRowSelection:ge,onToggleAllRows:K,onRangeSelection:Re,onClearSelection:Ye,onExportSelected:it,currentPage:dr=1,pageSize:Br=15,totalRowsBeforePagination:ut=o.length,onPageChange:$t,onPageSizeChange:Ne,isReadOnly:Ee=!1,userRole:_t,reportName:Mt,onEditRow:Je,onDuplicateRow:Ue,onDeleteRow:st,favoriteRowIndices:ur=[],resolvedFavoritesSet:et=new Set,showFavoritesOnly:at=!1,onToggleRowFavorite:We,onBulkSetFavorites:pr,showDevPanel:Er=!1,onOpenDevConfig:Ht,onToggleFavoritesFilter:pt}){var ao;const[Ct,xr]=p.useState(null),[wt,Dr]=p.useState(0),[Or,Ar]=p.useState(0),[Ge,mr]=p.useState(null),Ut=((ao=ar().dates)==null?void 0:ao.displayFormat)??null,[Ce,_r]=p.useState(null),[hr,lt]=p.useState(null),[F,qe]=p.useState(null),[we,Le]=p.useState(!1),[Mr,Yt]=p.useState(!1),[xt,Gt]=p.useState(null),[qt,Jt]=p.useState(""),[Rr,Rt]=p.useState(!1),[$e,Q]=p.useState(null),[mt,ke]=p.useState(null),[ye,tt]=p.useState(null),[Kt,ht]=p.useState(null),[Ve,fr]=p.useState("list"),[kt,ct]=p.useState(!1),[Tt,Wr]=p.useState(()=>!Hd("toolbar_search"));p.useRef(null);const Xt=p.useRef(null),Zt=p.useRef(null),Wt=p.useCallback(()=>{Ud("toolbar_search"),Wr(!1)},[]);p.useEffect(()=>{if(!Tt)return;const D=setTimeout(Wt,2e3);return()=>clearTimeout(D)},[Tt,Wt]);const gr=p.useMemo(()=>{const D=Ge??x;return D.length>0?D.map(J=>t.find(me=>me.name===J)).filter(J=>J!==void 0):t},[Ge,x,t]),Fe=p.useMemo(()=>gr.filter(D=>u[D.name]!==!1),[gr,u]),ft=p.useMemo(()=>t.filter(D=>u[D.name]===!1).length,[t,u]),Qt=p.useMemo(()=>t.map(D=>D.name),[t]),gt=p.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(Qt),[x,Qt]),Pr=p.useCallback((D,J)=>{D.preventDefault(),D.stopPropagation(),xr(J),Dr(D.clientX),Ar(h[J]||150)},[h]);p.useEffect(()=>{if(!Ct)return;const D=me=>{const He=me.clientX-wt,pe=Math.max(100,Math.min(600,Or+He));W==null||W(Ct,pe)},J=()=>{xr(null)};return document.addEventListener("mousemove",D),document.addEventListener("mouseup",J),()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",J)}},[Ct,wt,Or,W]);const Nr=p.useCallback(D=>D==null?"-":typeof D=="object"?JSON.stringify(D):typeof D=="boolean"?D?"true":"false":String(D),[]);p.useCallback(D=>{const J=n.find(me=>me.column===D);return J?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[J.direction==="asc"?e.jsx(z.ArrowUpward,{sx:{fontSize:14}}):e.jsx(z.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:J.priority})]}):null},[n]),p.useCallback(D=>i.some(me=>me.column===D)?e.jsx(r.IconButton,{size:"small",onClick:me=>{me.stopPropagation(),S==null||S(D)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(z.FilterList,{sx:{fontSize:14}})}):null,[i,S]);const Pt=p.useCallback(D=>{m&&m(D)},[m]),Lr=p.useCallback((D,J)=>{mr(me=>{const pe=[...me??(x.length>0?x:t.map(Uo=>Uo.name))],[zt]=pe.splice(D,1);return pe.splice(J,0,zt),pe})},[x,t]),Fr=p.useCallback(()=>{Ge&&V&&V(Ge),mr(null)},[Ge,V]),er=p.useCallback(D=>{if(!m)return;const J=n.find(me=>me.column===D);(!J||J.direction!=="asc")&&m(D)},[m,n]),yr=p.useCallback(D=>{if(!m)return;const J=n.find(me=>me.column===D);J?J.direction==="asc"&&m(D):(m(D),setTimeout(()=>m(D),0))},[m,n]),br=p.useCallback(D=>{if(!m)return;const J=n.find(me=>me.column===D);J&&(J.direction==="asc"?(m(D),setTimeout(()=>m(D),0)):J.direction==="desc"&&m(D))},[m,n]),vr=p.useCallback(D=>{Z&&Z(D,!1)},[Z]),tr=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Sr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(D=>D===!1),ue=(dr-1)*Br,de=o,Be=p.useMemo(()=>{const D=new Set;return ce.forEach(J=>{const me=J==null?void 0:J.__urm_row_id__;me!==void 0&&D.add(me)}),D},[ce]);p.useEffect(()=>{const D=J=>{!K||!Ye||J.target instanceof HTMLInputElement||J.target instanceof HTMLTextAreaElement||((J.ctrlKey||J.metaKey)&&J.key==="a"&&(J.preventDefault(),K(!0,de)),J.key==="Escape"&&(J.preventDefault(),Ye()))};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[K,Ye,de]);const dt=p.useCallback((D,J)=>{ge&&(J.shiftKey&&Ce!==null?(J.preventDefault(),Re&&Re(Ce,D,de)):(ge(de[D]),_r(D)))},[ge,Ce,Re,de]);!p.useMemo(()=>de.length>0&&Be.size>0&&de.every(D=>Be.has(D==null?void 0:D.__urm_row_id__)),[de,Be])&&de.some(D=>Be.has(D==null?void 0:D.__urm_row_id__));const It=ge&&K,Vr=p.useCallback(D=>{var He;const J=D.groupLevel,me=J*24;return e.jsx(r.TableRow,{onClick:()=>H==null?void 0:H(D.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Fe.length+(It?1:0),sx:{pl:`${me+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[D.isCollapsed?e.jsx(z.ChevronRight,{sx:{fontSize:16}}):e.jsx(z.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:Ii(J,((He=b==null?void 0:b.levels[J])==null?void 0:He.column)||"",D.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:pe=>k(pe.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[D.rowCount," ",D.rowCount===1?"row":"rows"]}),Object.keys(D.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(D.aggregates).map(([pe,zt])=>Ti(zt)).filter(Boolean).join(" • ")})]})})},D.groupKey)},[Fe,It,b,H]),Nt=p.useCallback((D,J)=>{const me=Be.has(D==null?void 0:D.__urm_row_id__),He=hr===J;return e.jsxs(r.TableRow,{"data-row-index":J,onMouseEnter:()=>lt(J),onMouseLeave:()=>lt(null),onClick:pe=>{!ge||pe.target.closest("[data-row-action-btn]")||dt(J,pe)},onContextMenu:pe=>{pe.preventDefault(),pe.stopPropagation(),tt({mouseX:pe.clientX,mouseY:pe.clientY,row:D,rowIndex:J})},sx:{height:34,cursor:"pointer",bgcolor:me?pe=>k(pe.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:me?pe=>k(pe.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Fe.map((pe,zt)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...zt===Fe.length-1&&{pr:`${We?76:40}px`},fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:h[pe.name]?`${h[pe.name]}px`:`${pe.type==="date"?Math.max(Ir,180):Ir}px`},children:tu(pe,D[pe.name],Qd(pe,Fe),Ut)},pe.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:He||et.has(D)?pe=>`linear-gradient(to right, transparent, ${me?k(pe.palette.warning.main,.12):pe.palette.background.paper} 32px)`:"transparent",opacity:He||et.has(D)?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:pe=>{pe.stopPropagation(),pe.preventDefault(),We(D)},title:et.has(D)?"Remove from favorites":"Add to favorites",sx:{color:et.has(D)?"warning.main":"text.secondary","&:hover":{bgcolor:pe=>k(pe.palette.warning.main,.08),color:"warning.main"}},children:et.has(D)?e.jsx(z.Star,{sx:{fontSize:18}}):e.jsx(z.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:pe=>{pe.stopPropagation(),pe.preventDefault(),tt({anchorEl:pe.currentTarget,row:D,rowIndex:J})},sx:{color:"text.secondary",opacity:He?1:0,transition:"opacity 0.12s ease",pointerEvents:He?"auto":"none","&:hover":{bgcolor:pe=>k(pe.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(z.MoreVert,{sx:{fontSize:18}})})]})})]},J)},[ce,ue,hr,dt,Fe,h,Nr,Je,Ue,st,ge,We,et,qe,Le,tt]);return e.jsxs(Dt.DndProvider,{backend:ln.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[It&&it&&Ye&&e.jsx(Ed,{selectedCount:Be.size,selectedRowIds:ce,resolvedFavoritesSet:et,viewMode:Ve,onExportSelected:it,onClearSelection:Ye,onBulkSetFavorites:pr}),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(Vd,{}),ae&&ie&&P&&se&&e.jsx(r.Tooltip,{open:Tt,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:Wt},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(kd,{value:ee||"",onChange:D=>{Tt&&Wt(),ae(D)},searchHistory:le,onAddToHistory:ie,onToggleFavourite:P,onDeleteHistory:se,disabled:Ee})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>ct(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:D=>k(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(z.InfoOutlined,{sx:{fontSize:20}})})}),pt&&e.jsx(r.Tooltip,{title:at?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:pt,size:"small",disabled:Ee,sx:{position:"relative",color:at?"warning.main":"text.secondary",bgcolor:at?D=>k(D.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:at?D=>k(D.palette.warning.main,.2):D=>k(D.palette.text.primary,.06),color:at?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[at?e.jsx(z.Star,{sx:{fontSize:20}}):e.jsx(z.StarBorder,{sx:{fontSize:20}}),at&&ur.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:"warning.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:ur.length})]})}),Er&&Ht&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:Ht,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:D=>k(D.palette.text.secondary,.3),"&:hover":{bgcolor:D=>k(D.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(z.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),I&&y&&C&&a&&s.length>0&&e.jsx(Td,{views:s||[],activeViewId:l||"",isDirty:d,onSelectView:I,onCreateView:y,onManageViews:C,onToggleDefault:T,onToggleFavorite:R,onRestoreView:G,onPermanentDelete:X,isAdmin:te,isReadOnly:Ee}),!Ee&&j&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:j,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?D=>Pe(D):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?D=>k(D.palette.primary.main,.2):D=>k(D.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(z.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Ee&&v&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:v,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?D=>Pe(D):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?D=>k(D.palette.primary.main,.2):D=>k(D.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(z.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Ee&&_&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:_,size:"small",sx:{position:"relative",color:ft>0||gt?"primary.main":"text.secondary",bgcolor:ft>0||gt?D=>Pe(D):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ft>0||gt?D=>k(D.palette.primary.main,.2):D=>k(D.palette.text.primary,.06),color:ft>0||gt?"primary.main":"text.primary"}},children:[e.jsx(z.ViewColumn,{sx:{fontSize:20}}),ft>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:ft})]})}),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:()=>fr("list"),sx:{borderRadius:1,color:Ve==="list"?"primary.main":"text.secondary",bgcolor:Ve==="list"?D=>Pe(D):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ve==="list"?D=>k(D.palette.primary.main,.2):D=>k(D.palette.text.primary,.06),color:Ve==="list"?"primary.main":"text.primary"}},children:e.jsx(z.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>fr("grid"),sx:{borderRadius:1,color:Ve==="grid"?"primary.main":"text.secondary",bgcolor:Ve==="grid"?D=>Pe(D):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ve==="grid"?D=>k(D.palette.primary.main,.2):D=>k(D.palette.text.primary,.06),color:Ve==="grid"?"primary.main":"text.primary"}},children:e.jsx(z.GridView,{sx:{fontSize:20}})})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"Settings",children:e.jsx(r.IconButton,{onClick:D=>ht(D.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:D=>k(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(z.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!Kt,anchorEl:Kt,onClose:()=>ht(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:[f&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(),ht(null)},disabled:c,sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Ee&&L&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{L(),ht(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),ne&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ne(),ht(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),q&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{q(),ht(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.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:[Ve==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Nd,{data:de,visibleColumns:Fe,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:et,isReadOnly:Ee,isGrouped:!!tr,sortStack:n,onSort:m,onToggleRowSelection:ge||(()=>{}),onToggleRowFavorite:We,onToggleGroupCollapse:H,onViewRow:D=>{qe(D),Le(!0)},onEditRow:(D,J)=>{Q(D),ke(J),Rt(!0)},onDuplicateRow:(D,J)=>Ue==null?void 0:Ue(D,J),onDeleteRow:(D,J)=>{Gt(J);const me=Object.values(J).find(He=>He!=null&&He!=="");Jt(me?String(me):""),Yt(!0)}})}),Ve==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Xt,onScroll:D=>{Zt.current&&(Zt.current.scrollLeft=D.target.scrollLeft)},sx:{overflowX:"auto",overflowY:"hidden",flexShrink:0,scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Fe.reduce((D,J)=>D+(h[J.name]||(J.type==="date"?180:Ir)),We?76:40)}px`},children:[e.jsxs("colgroup",{children:[Fe.map(D=>e.jsx("col",{style:{width:`${h[D.name]||(D.type==="date"?180:Ir)}px`}},D.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:[Fe.map((D,J)=>e.jsx(Bd,{column:D,index:J,sortRule:n.find(me=>me.column===D.name),hasFilters:i.some(me=>me.column===D.name),isInSortStack:n.some(me=>me.column===D.name),isReadOnly:Ee,hasModifications:Sr,width:h[D.name],onColumnClick:Pt,onMoveColumn:Lr,onColumnDragEnd:Fr,onResizeStart:Pr,onSortAscending:g||er,onSortDescending:B||yr,onRemoveSort:br,onOpenFilterForColumn:S||(()=>{}),onClearFiltersForColumn:xe||(()=>{}),onGroupByColumn:$,onHideColumn:vr,onManageColumns:_||(()=>{}),onManageViews:C,onResetLayout:he},D.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:Zt,onScroll:D=>{Xt.current&&(Xt.current.scrollLeft=D.target.scrollLeft)},sx:{flex:1,overflowY:"auto",overflowX:"auto",minHeight:0,bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${Fe.reduce((D,J)=>D+(h[J.name]||(J.type==="date"?180:Ir)),We?76:40)}px`},children:[e.jsxs("colgroup",{children:[Fe.map(D=>e.jsx("col",{style:{width:`${h[D.name]||(D.type==="date"?180:Ir)}px`}},D.name)),e.jsx("col",{style:{width:`${We?76:40}px`}})]}),e.jsx(r.TableBody,{children:de.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Fe.length+(It?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):tr?de.map((D,J)=>D.isGroupHeader?Vr(D):Nt(D,J)):de.map((D,J)=>Nt(D,J))})]})})]}),$t&&Ne&&e.jsx(Fd,{currentPage:dr,pageSize:Br,totalRows:ut,totalFields:t.length,onPageChange:$t,onPageSizeChange:Ne}),!($t&&Ne)&&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 ",de.length," ",de.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!ye,onClose:()=>tt(null),anchorEl:(ye==null?void 0:ye.anchorEl)||null,anchorReference:ye!=null&&ye.anchorEl?"anchorEl":"anchorPosition",anchorPosition:ye&&!ye.anchorEl?{top:ye.mouseY,left:ye.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:ye!=null&&ye.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:()=>{ye&&(qe(ye.row),Le(!0)),tt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ye&&(Q(ye.row),ke(ye.rowIndex),Rt(!0)),tt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{ye&&(Ue==null||Ue(ye.rowIndex,ye.row)),tt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(z.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(ye){Gt(ye.row);const D=Object.values(ye.row).find(J=>J!=null&&J!=="");Jt(D?String(D):""),Yt(!0)}tt(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(z.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Yd,{open:we,onClose:()=>{Le(!1),qe(null)},row:F,schema:t,reportName:Mt}),e.jsx(qd,{open:Rr,onClose:()=>{Rt(!1),Q(null),ke(null)},onSave:D=>{mt!==null&&(Je==null||Je(mt,D))},row:$e,schema:t,reportName:Mt}),e.jsx(Gd,{open:Mr,onClose:()=>{Yt(!1),Gt(null)},onConfirm:()=>{xt!==null&&(st==null||st(xt))},rowPreview:qt}),e.jsx(Xi,{isOpen:kt,onClose:()=>ct(!1)})]})}function lr({content:t,isDev:o=!1}){const[n,i]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:s=>i(s.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:s=>k(s.palette.primary.main,.08)}},children:e.jsx(z.InfoOutlined,{sx:{fontSize:15}})}),e.jsxs(r.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:{width:280,borderRadius:"10px",boxShadow:4,p:0,overflow:"hidden"}},children:[e.jsx(r.Box,{sx:{px:2,py:1.5,bgcolor:s=>k(s.palette.primary.main,.06)},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"primary.main",fontSize:"0.875rem"},children:t.title})}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.6},children:t.description}),t.tips&&t.tips.length>0&&e.jsx(r.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:t.tips.map((s,l)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},l))}),o&&t.devNote&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:s=>k(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>k(s.palette.warning.main,.2)},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:500,display:"block",mb:.25},children:"Dev note"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.5},children:t.devNote})]})]})]})]})]})}const cr={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 ou({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:l,onReplaceFilters:d,onClose:c,focusColumn:u}){const[x,h]=p.useState(""),[b,m]=p.useState(""),[g,B]=p.useState(""),[v,j]=p.useState([]),S=ar();p.useEffect(()=>{j([...o])},[o]),p.useEffect(()=>{u&&h(u)},[u]);const I=p.useCallback(()=>{h(""),m(""),B("")},[]),y=p.useMemo(()=>t.filter(_=>_.type!=="mixed"&&_.type!=="null"&&_.type!=="array"&&_.type!=="object"),[t]),C=t.find(_=>_.name===x),a=p.useMemo(()=>{const _=C?An(C.type):[],W=S.filter.allowedOperators;return W.length>0?_.filter(V=>W.includes(V.value)):_},[C]),A=p.useCallback(()=>!(!x||!b||po(b)&&!g.trim()||v.length>=S.filter.maxConditions),[x,b,g,v,S]),T=p.useCallback(()=>{if(!A())return;const _={column:x,operator:b};if(po(b)){const V=C==null?void 0:C.type;_.value=V==="number"?Number(g):g}if(v.some(V=>V.column===_.column&&V.operator===_.operator&&V.value===_.value)){I();return}j([...v,_]),I()},[A,x,b,C,g,v,I]),R=p.useCallback(_=>{j(v.filter((W,V)=>V!==_))},[v]),G=p.useMemo(()=>v.length!==o.length?!0:JSON.stringify(v)!==JSON.stringify(o),[v,o]),X=p.useCallback(()=>{d(v),c()},[v,d,c]),te=p.useCallback(()=>{j([...o]),I(),c()},[o,I,c]),f=p.useCallback(_=>{var xe;const W=t.find(he=>he.name===_.column);if(!W)return"";const Z=((xe=An(W.type).find(he=>he.value===_.operator))==null?void 0:xe.label)||_.operator;return po(_.operator)?`${_.column} ${Z.toLowerCase()} "${_.value}"`:`${_.column} ${Z.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:te,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:_=>k(_.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:_=>Me(_),bgcolor:"background.paper",outline:"none",boxShadow:_=>re(_,"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(lr,{content:cr.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:"action.hover",color:"text.primary"}},children:e.jsx(z.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:_=>k(_.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:_=>k(_.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:v.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:x,onChange:_=>{h(_.target.value),m(""),B("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:y.map(_=>e.jsxs(r.MenuItem,{value:_.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Pe(W),"&:hover":{bgcolor:W=>k(W.palette.primary.main,.2)}}},children:[Ze(_.name)," (",_.type,")"]},_.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:_=>{m(_.target.value),B("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:a.map(_=>e.jsx(r.MenuItem,{value:_.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Pe(W),"&:hover":{bgcolor:W=>k(W.palette.primary.main,.2)}}},children:_.label},_.value))})]}),b&&po(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(C==null?void 0:C.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:"divider",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:T,disabled:!A(),sx:{mt:1.5,fontSize:"0.875rem",color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"text.disabled"}},children:"+ Add another filter"}),v.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."]})]}),v.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 (",v.length,")"]}),e.jsx(r.Button,{onClick:()=>{l(),c()},sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:v.map((_,W)=>e.jsx(r.Chip,{label:f(_),onDelete:()=>R(W),sx:{bgcolor:V=>Pe(V),color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:V=>`1px solid ${k(V.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:V=>k(V.palette.primary.main,.2),borderColor:V=>k(V.palette.primary.main,.5)},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},W))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:te,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:_=>`${_.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:X,disabled:!G,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:_=>`${_.shape.borderRadius}px`,boxShadow:_=>re(_,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:_=>re(_,"hoverButton")},"&:active":{boxShadow:_=>re(_,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})})}const mi="SORT_RULE";function nu({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const l=p.useRef(null),[{handlerId:d},c]=Dt.useDrop({accept:mi,collect(h){return{handlerId:h.getHandlerId()}},hover(h,b){var I;if(!l.current)return;const m=h.index,g=o;if(m===g)return;const B=(I=l.current)==null?void 0:I.getBoundingClientRect(),v=(B.bottom-B.top)/2,j=b.getClientOffset(),S=((j==null?void 0:j.y)??0)-B.top;m<g&&S<v||m>g&&S>v||(s(m,g),h.index=g)}}),[{isDragging:u},x]=Dt.useDrag({type:mi,item:()=>({index:o}),collect:h=>({isDragging:h.isDragging()})});return x(c(l)),e.jsxs(r.Box,{ref:l,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:h=>re(h,"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:h=>`0 1px 2px 0 ${k(h.palette.primary.main,.3)}`,"& .MuiChip-label":{px:0}}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:h=>n(o,h.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:h=>Pe(h),"&:hover":{bgcolor:h=>k(h.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:h=>Pe(h),"&:hover":{bgcolor:h=>k(h.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:h=>k(h.palette.error.main,.08),transform:"scale(1.1)"}},children:e.jsx(z.Close,{sx:{fontSize:18}})})]})}function iu({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,l]=p.useState(""),[d,c]=p.useState([]);p.useEffect(()=>{c([...o])},[o]);const u=p.useMemo(()=>JSON.stringify(d)!==JSON.stringify(o),[d,o]),x=ar(),h=p.useCallback(()=>!(d.length>=x.sort.maxLevels||!s||d.some(y=>y.column===s)),[d,s]),b=p.useCallback(()=>{if(!h())return;const y=d.length+1,C={column:s,direction:"asc",priority:y};c([...d,C]),l("")},[h,s,d]),m=p.useCallback(y=>{const a=d.filter((A,T)=>T!==y).map((A,T)=>({...A,priority:T+1}));c(a)},[d]),g=p.useCallback((y,C)=>{const a=[...d];a[y]={...a[y],direction:C},c(a)},[d]),B=p.useCallback((y,C)=>{const a=[...d],[A]=a.splice(y,1);a.splice(C,0,A);const T=a.map((R,G)=>({...R,priority:G+1}));c(T)},[d]),v=p.useCallback(()=>{n([]),i()},[n,i]),j=p.useCallback(()=>{n(d),i()},[d,n,i]),S=p.useCallback(()=>{c([...o]),l(""),i()},[o,i]),I=t.filter(y=>!d.some(C=>C.column===y.name));return e.jsx(Dt.DndProvider,{backend:ln.HTML5Backend,children:e.jsx(r.Box,{onClick:S,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:y=>k(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:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:y=>Me(y),bgcolor:"background.paper",outline:"none",boxShadow:y=>re(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:{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(lr,{content:cr.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:"action.hover",color:"text.primary"}},children:e.jsx(z.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:y=>k(y.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:y=>k(y.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled: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:s,onChange:y=>l(y.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:I.map(y=>e.jsx(r.MenuItem,{value:y.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:C=>Pe(C),"&:hover":{bgcolor:C=>k(C.palette.primary.main,.2)}}},children:Ze(y.name)},y.name))})]}),e.jsx(r.Button,{onClick:b,disabled:!h(),sx:{mt:1.5,fontSize:"0.875rem",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:"text.disabled"}},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:v,sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((y,C)=>e.jsx(nu,{rule:y,index:C,onToggleDirection:g,onRemove:m,onMove:B},`${y.column}-${C}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:S,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:y=>`${y.shape.borderRadius}px`,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:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:y=>`${y.shape.borderRadius}px`,boxShadow:y=>re(y,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:y=>re(y,"hoverButton")},"&:active":{boxShadow:y=>re(y,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function su({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:l,onRestoreView:d,onPermanentDelete:c,onPromoteToGlobal:u,isAdmin:x=!1,onClose:h}){var y,C;const b=At(),m=b.palette,g=t.filter(a=>!a.isDeleted),B=t.filter(a=>a.isDeleted),v=g.filter(a=>a.scope==="global"),j=g.filter(a=>a.scope!=="global"),S=a=>{var X,te,f,_,W;const A=a.scope==="global",T=a.id===o,R=x||!A,G=x&&!A;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:T?"primary.main":"divider",bgcolor:T?k(m.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:T?"primary.main":k(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(a.id),h()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:T?600:500,color:T?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),a.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[A&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(z.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:k(((X=m.info)==null?void 0:X.main)??m.primary.main,.1),color:((te=m.info)==null?void 0:te.main)??m.primary.main,border:`1px solid ${k(((f=m.info)==null?void 0:f.main)??m.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),a.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:k(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&&u&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:V=>{V.stopPropagation(),u(a.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((_=m.info)==null?void 0:_.main)??m.primary.main,bgcolor:k(((W=m.info)==null?void 0:W.main)??m.primary.main,.08)}},children:e.jsx(z.Language,{sx:{fontSize:16}})})}),R&&e.jsx(r.Tooltip,{title:A&&!x?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:A&&!x,onClick:V=>{V.stopPropagation(),s(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:k(m.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(z.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:A&&!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:A&&!x,onClick:V=>{V.stopPropagation(),l(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:k(m.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})})]})]})},a.id)},I=a=>{var A;return e.jsxs(r.Paper,{variant:"outlined",sx:{px:1.75,py:1.25,borderRadius:"8px",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:k(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:a.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:T=>{T.stopPropagation(),d(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:k(((A=m.success)==null?void 0:A.main)??"#2e7d32",.08)}},children:e.jsx(z.Undo,{sx:{fontSize:15}})})}),c&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:T=>{T.stopPropagation(),c(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:k(m.error.main,.08)}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})]})]},a.id)};return e.jsxs(r.Dialog,{open:!0,onClose:h,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:Me(b),maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${k(((y=m.common)==null?void 0:y.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:h,size:"small",sx:{color:"text.secondary"},children:e.jsx(z.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",startIcon:e.jsx(z.Add,{sx:{fontSize:16}}),size:"small",sx:{borderRadius:a=>`${a.shape.borderRadius}px`},children:"Create New View"})}),v.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(z.Language,{sx:{fontSize:14,color:((C=m.info)==null?void 0:C.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:v.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(I)})]}),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:h,variant:"contained",sx:{fontSize:"0.875rem",borderRadius:a=>`${a.shape.borderRadius}px`,px:3},children:"Close"})})]})}const go=50;function hi({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:l="",initialIsDefault:d=!1,atViewLimit:c=!1,maxViews:u=10}){const[x,h]=p.useState(s),[b,m]=p.useState(!1),[g,B]=p.useState(l),[v,j]=p.useState(d),S=()=>{if(!x.trim()){m(!0);return}if(x.trim().length>go){m(!0);return}o(x.trim(),g.trim(),v),n()},I=C=>{C.key==="Enter"&&!C.shiftKey?S():C.key==="Escape"&&n()},y=()=>i&&s?`Update ${s} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:C=>Me(C),boxShadow:C=>re(C,"menu")}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[y(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(z.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[c&&!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:x,onChange:C=>{C.target.value.length<=go&&h(C.target.value),b&&C.target.value.trim()&&m(!1)},onKeyDown:I,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:c&&!i,inputProps:{maxLength:go},error:b&&!x.trim(),helperText:b&&!x.trim()?"View name is required":`${x.length} / ${go}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:C=>B(C.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: ",xa(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:v,onChange:C=>j(C.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:C=>`${C.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:S,variant:"contained",disabled:c&&!i,startIcon:e.jsx(z.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:C=>`${C.shape.borderRadius}px`,boxShadow:C=>re(C,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:C=>re(C,"hoverButton")},"&:active":{boxShadow:C=>re(C,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function au({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>Me(i),maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:i=>re(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(z.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(z.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",sx:{fontSize:"0.875rem",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>re(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>re(i,"hoverButton")},"&:active":{boxShadow:i=>re(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const bo=100,vo=600,fi="COLUMN";function lu({column:t,index:o,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:l,moveColumn:d}){const c=p.useRef(null),[u,x]=p.useState(i.toString());p.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:h},b]=Dt.useDrop({accept:fi,collect(I){return{handlerId:I.getHandlerId()}},hover(I,y){var X;if(!c.current)return;const C=I.index,a=o;if(C===a)return;const A=(X=c.current)==null?void 0:X.getBoundingClientRect(),T=(A.bottom-A.top)/2,R=y.getClientOffset(),G=((R==null?void 0:R.y)??0)-A.top;C<a&&G<T||C>a&&G>T||(d(C,a),I.index=a)}}),[{isDragging:m},g]=Dt.useDrag({type:fi,item:()=>({index:o}),collect:I=>({isDragging:I.isDragging()})});g(b(c));const B=()=>{const I=parseInt(u);if(isNaN(I)){x(i.toString()),l(t.name,i);return}const y=Math.max(bo,Math.min(vo,I));x(y.toString()),l(t.name,y)},v=I=>{if(I===""||/^\d+$/.test(I)){x(I);const y=parseInt(I);if(!isNaN(y)&&y>=bo){const C=Math.min(vo,y);l(t.name,C)}}},j=I=>{I.key==="Enter"&&(I.preventDefault(),B(),I.target.blur())},S=I=>({string:"primary.main",number:"success.main",boolean:"secondary.main",array:"info.main",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[I]||"text.secondary";return e.jsxs(r.TableRow,{ref:c,"data-handler-id":h,sx:{opacity:m?.4:1,bgcolor:n?"background.paper":"action.hover",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"action.hover":"action.selected"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(z.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ze(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:I=>v(I.target.value),onBlur:B,onKeyDown:j,placeholder:"150",size:"small",inputProps:{min:bo,max:vo,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"},"& input[type=number]::-webkit-inner-spin-button":{opacity:1},"& input[type=number]::-webkit-outer-spin-button":{opacity:1}}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"px"})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.IconButton,{onClick:()=>s(t.name,!n),title:n?"Hide column":"Show column",size:"small",sx:{p:.75,color:n?"primary.main":"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(z.Visibility,{sx:{fontSize:20}}):e.jsx(z.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?I=>k(I.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function cu({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:l="",onUpdateColumnVisibility:d,onUpdateColumnOrder:c,onUpdateColumnWidth:u,onResetLayout:x,onSaveToCurrentView:h,onSaveToAllViews:b,onSelectView:m,onClose:g}){const[B,v]=p.useState(!1),[j,S]=p.useState(n),[I,y]=p.useState(i),[C,a]=p.useState("all"),[A,T]=p.useState(null);p.useEffect(()=>{S(n)},[n]),p.useEffect(()=>{y(i)},[i]);const R=(L,$)=>{y(H=>({...H,[L]:$})),u==null||u(L,$)},G=(L,$)=>{const H=[...j],[ne]=H.splice(L,1);H.splice($,0,ne),S(H),c(H)},X=()=>{x(),v(!1)},f=j.map(L=>t.find($=>$.name===L)).filter(L=>L!==void 0).filter(L=>{const $=o[L.name]??!0;return C==="active"?$:C==="hidden"?!$:!0}),_=Object.values(o).filter(L=>L).length,W=t.length,V=s.find(L=>L.id===l),Z=s.filter(L=>!L.isDeleted),xe=Z.length>1,he=p.useMemo(()=>{if(!V)return!1;const L=V.snapshot,$=L.columnVisibility??{},H=JSON.stringify(o)!==JSON.stringify($),ne=L.columnOrder??[],q=n??[],ee=JSON.stringify(q)!==JSON.stringify(ne)&&!(q.length===0&&ne.length===0),le=L.columnWidths??{},ie=JSON.stringify(I)!==JSON.stringify(le);return H||ee||ie},[V,o,n,I]);return e.jsx(Dt.DndProvider,{backend:ln.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:L=>k(L.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:L=>L.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:L=>L.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:L=>Me(L),bgcolor:"background.paper",outline:"none",boxShadow:L=>re(L,"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(lr,{content:cr.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"]})]}),Z.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:L=>T(L.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(z.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",fontSize:"0.875rem",color:"text.primary",borderColor:"divider",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(V==null?void 0:V.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:A,open:!!A,onClose:()=>T(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:L=>re(L,"small")}},children:Z.map(L=>e.jsx(r.MenuItem,{onClick:()=>{m(L.id),T(null)},selected:L.id===l,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:$=>Pe($),"&:hover":{bgcolor:$=>k($.palette.primary.main,.2)}}},children:L.name},L.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:C,onChange:(L,$)=>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:L=>k(L.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:L=>k(L.palette.text.primary,.3)}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${bo}px, max: ${vo}px)`,arrow:!0,placement:"top",children:e.jsx(z.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:f.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"})})}):f.map((L,$)=>e.jsx(lu,{column:L,index:$,isVisible:o[L.name]??!0,width:I[L.name]||170,onToggleVisibility:d,onWidthChange:R,moveColumn:G},L.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:"action.hover"},children:[e.jsx(r.Button,{onClick:()=>v(!0),disabled:!he,variant:"outlined",startIcon:e.jsx(z.Undo,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",px:2.5,py:.875,minHeight:36,borderRadius:L=>`${L.shape.borderRadius}px`,"&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[h&&e.jsx(r.Button,{onClick:()=>{h(I),g()},disabled:!he,variant:"contained",startIcon:e.jsx(z.Save,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:L=>`${L.shape.borderRadius}px`,boxShadow:L=>re(L,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:L=>re(L,"hoverButton")},"&:active":{boxShadow:L=>re(L,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to current view"}),b&&xe&&e.jsx(r.Button,{onClick:()=>{b(I),g()},disabled:!he||!xe,variant:"contained",startIcon:e.jsx(z.GridView,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:L=>`${L.shape.borderRadius}px`,boxShadow:L=>re(L,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:L=>re(L,"hoverButton")},"&:active":{boxShadow:L=>re(L,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to all views"})]})]}),B&&e.jsx(r.Box,{onClick:()=>v(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:L=>k(L.palette.common.black,.5),display:"flex",alignItems:"center",justifyContent:"center",zIndex:L=>L.zIndex.tooltip},children:e.jsxs(r.Paper,{onClick:L=>L.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:L=>so(L),bgcolor:"background.paper",boxShadow:L=>re(L,"menu")},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:()=>v(!1),variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,borderRadius:L=>`${L.shape.borderRadius}px`,"&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:X,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:L=>`${L.shape.borderRadius}px`,boxShadow:L=>re(L,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:L=>re(L,"hoverButton")},"&:active":{boxShadow:L=>re(L,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function du({schema:t,grouping:o,onApply:n,onClose:i}){var A;const[s,l]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,c]=p.useState(""),[u,x]=p.useState(null),h=p.useMemo(()=>aa(t),[t]),b=p.useMemo(()=>h.filter(T=>!s.levels.some((R,G)=>R.column===T.name&&G!==u)),[h,s.levels,u]),m=ar(),g=s.levels.length<m.grouping.maxLevels&&b.length>0,B=p.useCallback(()=>{!g||!d||(l({...s,levels:[...s.levels,{column:d}],enabled:!0}),c(""))},[g,d,s]),v=p.useCallback(T=>{const R=s.levels.filter((G,X)=>X!==T);if(R.length===0){n(null),i();return}l({...s,levels:R,enabled:R.length>0})},[s,n,i]),j=p.useCallback(T=>{x(T),c(s.levels[T].column)},[s.levels]),S=p.useCallback(()=>{if(u===null||!d)return;const T=[...s.levels];T[u]={column:d},l({...s,levels:T}),x(null),c("")},[u,d,s]),I=p.useCallback(()=>{x(null),c("")},[]),y=p.useCallback((T,R)=>{const G=R==="up"?T-1:T+1;if(G<0||G>=s.levels.length)return;const X=[...s.levels],[te]=X.splice(T,1);X.splice(G,0,te),l({...s,levels:X})},[s]),C=p.useCallback(()=>{n(null),i()},[n,i]),a=p.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[s,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:T=>k(T.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:T=>T.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:T=>T.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:T=>Me(T),bgcolor:"background.paper",outline:"none",boxShadow:T=>re(T,"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(lr,{content:cr.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:T=>k(T.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:T=>k(T.palette.text.primary,.3)}}},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:T=>c(T.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"action.hover"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(T=>e.jsxs(r.MenuItem,{value:T.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:R=>Pe(R),"&:hover":{bgcolor:R=>k(R.palette.primary.main,.2)}}},children:[Ze(T.name)," (",T.type.toUpperCase(),")"]},T.name))]})}),e.jsx(r.Button,{onClick:B,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(z.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"action.hover"},"&.Mui-disabled":{color:"text.disabled",borderColor:"divider"}},children:"Add group level"}),s.levels.length>=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"}),h.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:T=>`1px solid ${k(T.palette.warning.main,.5)}`,bgcolor:T=>k(T.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:T=>c(T.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:s.levels[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:T=>Pe(T)}},children:[s.levels[u].column," (",(A=t.find(T=>T.name===s.levels[u].column))==null?void 0:A.type.toUpperCase(),")"]}),b.filter(T=>T.name!==s.levels[u].column).map(T=>e.jsxs(r.MenuItem,{value:T.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:R=>Pe(R)}},children:[Ze(T.name)," (",T.type.toUpperCase(),")"]},T.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:{fontSize:"0.875rem",bgcolor:"warning.main",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"warning.dark",boxShadow:T=>re(T,"pressedButton")}},children:"Save"}),e.jsx(r.Button,{onClick:I,variant:"outlined",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",borderColor:"divider",py:.875,"&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},children:"Cancel"})]})]}),s.levels.length>0&&u===null&&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:C,size:"small",sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:s.levels.map((T,R)=>{const G=t.find(X=>X.name===T.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:X=>re(X,"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:X=>`0 1px 2px 0 ${k(X.palette.primary.main,.3)}`}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:T.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:()=>y(R,"up"),disabled:R===0,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(z.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y(R,"down"),disabled:R===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(z.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(R),sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover",color:"primary.main"}},children:e.jsx(z.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>v(R),sx:{color:"text.secondary","&:hover":{bgcolor:X=>k(X.palette.error.main,.08),color:"error.main"}},children:e.jsx(z.Delete,{sx:{fontSize:18}})})]})]},R)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:a,variant:"contained",disabled:s.levels.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:T=>`${T.shape.borderRadius}px`,boxShadow:T=>re(T,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:T=>re(T,"hoverButton")},"&:active":{boxShadow:T=>re(T,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const uu={filters:z.FilterList,sorting:z.UnfoldMore,visibility:z.Visibility,order:z.ViewColumn,widths:z.Straighten,grouping:z.Layers};function pu({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:i=>Me(i),boxShadow:i=>re(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(z.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,s)=>{const l=uu[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(l,{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})]})]},s)})})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:i=>`${i.shape.borderRadius}px`,boxShadow:i=>re(i,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:i=>re(i,"hoverButton")},"&:active":{boxShadow:i=>re(i,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})}function xu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:s,onCancel:l}){const[d,c]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:u=>Pe(u),borderBottom:u=>`1px solid ${k(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:l,variant:"text",size:"small",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:u=>k(u.palette.common.black,.08),color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:s,variant:"contained",size:"small",sx:{fontSize:"0.875rem",px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:u=>re(u,"restButton")}},children:"Save as new view"})]})]})}),d&&e.jsx(pu,{changes:n,onClose:()=>c(!1)})]})}function mu({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(z.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(z.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(z.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(z.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const gi=[{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 hu(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 fu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function gu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var B,v,j,S;const i=At(),s=i.palette,[l,d]=p.useState("1h"),[c,u]=p.useState(!1),x=[...t].sort((I,y)=>new Date(y.timestamp).getTime()-new Date(I.timestamp).getTime()),h=gi.find(I=>I.key===l),b=hu(t,h.ms),m=()=>u(!0),g=()=>{n&&(n(fu(t,h.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:k(((B=s.common)==null?void 0:B.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:i.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:I=>I.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:Me(i),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${k(((v=s.common)==null?void 0:v.black)??"#000",.14)}, 0 2px 8px ${k(((j=s.common)==null?void 0:j.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,borderBottom:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),e.jsx(lr,{content:cr.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:l,onChange:I=>d(I.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:k(s.text.primary,.3)}},children:gi.map(I=>e.jsx(r.MenuItem,{value:I.key,sx:{fontSize:"0.8125rem"},children:I.label},I.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(z.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:m,sx:{fontSize:"0.75rem",borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:k(s.error.main,.5),"&:hover":{bgcolor:k(s.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:k(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:k(s.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(z.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(I=>{const y=$d(i,I.feature),{summary:C,detail:a}=Ta(I);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:k(s.text.primary,.18)}},children:[e.jsx(r.Chip,{label:Ba(I.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:k(y,.1),color:y,border:`1px solid ${k(y,.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:C}),a&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:a}),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(z.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:Ea(I.timestamp)})]}),I.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(z.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:I.user})]})]})]})]},I.id)})})})]})}),e.jsxs(r.Dialog,{open:c,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:so(i),boxShadow:`0 8px 32px ${k(((S=s.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:k(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.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":""]})," ",h.key==="all"?"from all time":`from the ${h.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:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",startIcon:e.jsx(z.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{fontSize:"0.8125rem",borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function yu({onSave:t,onClose:o}){const[n,i]=p.useState(""),[s,l]=p.useState(""),[d,c]=p.useState(""),[u,x]=p.useState([]),[h,b]=p.useState(""),[m,g]=p.useState(""),B=a=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a),v=()=>{const a=d.trim();if(a){if(!B(a)){g("Please enter a valid email address");return}if(u.includes(a)){g("This email is already added");return}x([...u,a]),c(""),g("")}},j=a=>{x(u.filter(A=>A!==a))},S=a=>{a.key==="Enter"&&(a.preventDefault(),v())},I=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),s.trim(),u.length>0?u:void 0)},y=a=>{i(a),h&&b("")},C=a=>{c(a),m&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:a=>k(a.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:a=>a.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:a=>a.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:a=>Me(a),bgcolor:"background.paper",outline:"none",boxShadow:a=>re(a,"menu"),animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:a=>k(a.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:a=>k(a.palette.text.primary,.3)}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(z.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:a=>`1px solid ${k(a.palette.primary.main,.3)}`,bgcolor:a=>Pe(a),"& .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:a=>y(a.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!h,helperText:h,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value:s,onChange:a=>l(a.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:d,onChange:a=>C(a.target.value),onKeyPress:S,placeholder:"Enter email address",error:!!m,helperText:m,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(z.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),e.jsx(r.Button,{onClick:v,variant:"outlined",startIcon:e.jsx(z.Add,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",color:"primary.main",borderColor:"divider",px:2,py:1.25,minHeight:40,borderRadius:a=>`${a.shape.borderRadius}px`,flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"action.hover"}},children:"Add"})]}),u.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:u.map(a=>e.jsx(r.Chip,{label:a,onDelete:()=>j(a),deleteIcon:e.jsx(z.Delete,{sx:{fontSize:16}}),sx:{bgcolor:A=>Pe(A),color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},a))}),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:"action.hover"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:a=>`${a.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:I,variant:"contained",startIcon:e.jsx(z.Share,{sx:{fontSize:18}}),sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:a=>`${a.shape.borderRadius}px`,boxShadow:a=>re(a,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:a=>re(a,"hoverButton")},"&:active":{boxShadow:a=>re(a,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function bu({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(z.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(z.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>k(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 vu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:s}){const[l,d]=p.useState(null),c=u=>new Date(u).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:u=>k(u.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:u=>u.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children: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:u=>Me(u),bgcolor:"background.paper",outline:"none",boxShadow:u=>re(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:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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=>k(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(z.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:"background.paper",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:x=>re(x,"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 ${c(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(z.Delete,{sx:{fontSize:16}}),sx:{fontSize:"0.8125rem",color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:x=>`${x.shape.borderRadius}px`,"&:hover":{borderColor:"error.main",bgcolor:x=>k(x.palette.error.main,.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:s,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",px:3,py:.875,minHeight:36,borderRadius:u=>`${u.shape.borderRadius}px`,boxShadow:u=>re(u,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:u=>re(u,"hoverButton")},"&:active":{boxShadow:u=>re(u,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const es={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},Su=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],ju=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function Cu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=ju.some(c=>c.test(i.name));let l=!1;const d=o.slice(0,10).map(c=>c[i.name]).filter(c=>typeof c=="string"&&c.length>0);d.length>0&&(l=d.filter(u=>Su.some(x=>x.test(u))).length/d.length>.6),(s||l)&&n.push(i.name)}return n}function gn(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),s=o.map(d=>{const c=n.map(x=>String(x[d]??"")).filter(x=>x.length>0);if(c.length===0)return 5;const u=c.reduce((x,h)=>x+h.length,0);return Math.ceil(u/c.length)+1}).reduce((d,c)=>d+c,0)+1;return o.reduce((d,c)=>d+c.length+1,0)+s*t.length}function wu(t,o){const n=gn(t,o);return Math.ceil(n*3.5)}function ku(t,o){const n=gn(t,o);return Math.ceil(n*.7)}function Tu(t,o,n){switch(t){case"csv":return gn(o,n);case"excel":return ku(o,n);case"json":return wu(o,n)}}function yi(t,o){return Math.ceil(t/o)}function Iu(t,o,n,i,s=es){const l=[],d=Tu(t,o,n),c=o.length;if(c>s.maxRowsHard){const h=yi(c,s.maxRows);l.push({type:"row_count",severity:"error",message:`Export blocked: ${c.toLocaleString()} rows exceeds the maximum of ${s.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${h} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:c,limit:s.maxRowsHard})}else if(c>s.maxRows){const h=yi(c,s.maxRows);l.push({type:"row_count",severity:"warning",message:`Large export: ${c.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${h} smaller export${h>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:c,limit:s.maxRows})}if(d>s.maxFileSizeHardBytes?l.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${to(d)} exceeds the ${to(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:d,limit:s.maxFileSizeHardBytes}):d>s.maxFileSizeBytes&&l.push({type:"file_size",severity:"warning",message:`Large file: estimated ${to(d)}`,detail:`This exceeds the recommended ${to(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:s.maxFileSizeBytes}),t!=="excel"){const h=Cu(i.filter(b=>n.includes(b.name)),o);if(h.length>0){const b=h.length>s.maxImageColumns;l.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${h.length>1?"s":""} detected: ${h.map(m=>`"${m.replace(/_/g," ")}"`).join(", ")}`,detail:b?`Exporting ${h.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:h.length,limit:s.maxImageColumns})}}const u=l.some(h=>h.severity==="error"),x=l.some(h=>h.severity==="warning");return{violations:l,hasBlockingViolation:u,hasWarning:x,estimatedBytes:d}}function to(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function zu({violation:t}){const n=At().palette,i=t.severity==="error",s=i?n.error.main:n.warning.main,l=k(i?n.error.main:n.warning.main,.06),d=i?k(n.error.main,.25):k(n.warning.main,.3),c=i?z.ErrorOutline:z.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:l,border:"1px solid",borderColor:d},children:[e.jsx(c,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:t.message}),t.detail&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:t.detail}),t.suggestedBatches&&t.suggestedBatches>1&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[e.jsx(z.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function Bu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:l,sampleRows:d=[],allRows:c=[],processedRows:u=[],onExport:x,onClose:h}){var _,W,V;const b=At(),m=b.palette,g=ar(),[B,v]=p.useState(g.export.allowedFormats[0]||"csv"),[j,S]=p.useState("visible"),[I,y]=p.useState("visible"),C=j==="visible"?o:t,a=I==="visible"?i:s,A=p.useMemo(()=>j==="visible"?u.length>0?u:new Array(o):c.length>0?c:new Array(t),[j,o,t,u,c]),T=p.useMemo(()=>I==="all"?l.map(Z=>Z.name):l.map(Z=>Z.name).slice(0,i),[I,l,i]),R=p.useMemo(()=>Iu(B,A,T,l,es),[B,A,T,l]),G=()=>{R.hasBlockingViolation||(x({format:B,scope:j,columnScope:I}),h())},X={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"}},f={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:h,sx:{position:"fixed",inset:0,bgcolor:k(((_=m.common)==null?void 0:_.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:b.zIndex.modal,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:Z=>Z.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:Me(b),bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${k(((W=m.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${k(((V=m.common)==null?void 0:V.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(lr,{content:cr.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:h,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(z.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:k(m.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((Z,xe)=>e.jsx(zu,{violation:Z},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:Z=>v(Z.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:f}),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:f}),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:f}),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:Z=>S(Z.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:f}),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:f}),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:I,onChange:Z=>y(Z.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:f}),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:f}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",s," columns (including hidden)"]})]}),sx: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:X[B]},{label:"Rows to export",value:C.toLocaleString()},{label:"Columns to export",value:String(a)},{label:"Estimated file size",value:to(R.estimatedBytes),highlight:R.hasBlockingViolation?"error.main":R.hasWarning?"warning.main":void 0}].map(({label:Z,value:xe,highlight:he})=>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:Z}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:he??"text.primary"},children:xe})]},Z))})]})]}),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:k(m.text.primary,.015)},children:[R.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(z.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:h,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:G,disabled:R.hasBlockingViolation,variant:"contained",startIcon:e.jsx(z.Download,{sx:{fontSize:16}}),sx:{fontSize:"0.875rem",px:2.5,borderRadius:"8px"},children:["Download ",X[B]]})]})]})})}function Eu({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(z.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(z.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 Du({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){p.useEffect(()=>{if(n){const c=setTimeout(()=>{o()},i);return()=>clearTimeout(c)}},[n,i,o]);const l=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(z.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(z.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(z.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Va(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:l.severity,icon:l.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${l.severity}.main`},children:e.jsx(z.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${l.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 Ou extends p.Component{constructor(n){super(n);Yr(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){ir.error("urm:error-boundary","Caught unhandled component error",n,i),this.props.onError&&this.props.onError(n,i)}render(){var n,i;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsx(r.Paper,{sx:{bgcolor:s=>k(s.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(z.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((n=this.state.error)==null?void 0:n.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:s=>k(s.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:170},children:(i=this.state.error)==null?void 0:i.stack}),e.jsx(r.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:e.jsx(z.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Au({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(z.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(z.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Kr({children:t,feature:o,onError:n}){return e.jsx(Ou,{context:o,onError:(i,s)=>{n&&n(i)},fallback:e.jsx(Au,{feature:o}),children:t})}const $u=[{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"}],_u=[{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 Xr({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 Mu({open:t,onClose:o,config:n,onApply:i}){const[s,l]=p.useState(0),[d,c]=p.useState(n),u=()=>c(n),x=()=>c(Ke),h=()=>{i(d),o()},b={sort:j=>c(S=>({...S,sort:{...S.sort,...j}})),filter:j=>c(S=>({...S,filter:{...S.filter,...j}})),columns:j=>c(S=>({...S,columns:{...S.columns,...j}})),grouping:j=>c(S=>({...S,grouping:{...S.grouping,...j}})),export:j=>c(S=>({...S,export:{...S.export,...j}}))},m=j=>{const S=d.filter.allowedOperators,I=S.includes(j)?S.filter(y=>y!==j):[...S,j];I.length!==0&&b.filter({allowedOperators:I})},g=j=>{const S=d.export.allowedFormats,I=S.includes(j)?S.filter(y=>y!==j):[...S,j];I.length!==0&&b.export({allowedFormats:I})},B=[{label:"Sort",icon:e.jsx(z.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(z.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(z.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(z.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(z.Download,{sx:{fontSize:17}})}],v=j=>JSON.stringify(d[j])===JSON.stringify(Ke[j]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:j=>Me(j),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:j=>`0 8px 32px ${k(j.palette.common.black,.2)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:j=>k(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(z.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:s,onChange:(j,S)=>l(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(Xr,{active:s===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!v("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(Xr,{active:s===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!v("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:$u.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:()=>m(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(Xr,{active:s===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!v("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(Xr,{active:s===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!v("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=>k(S.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:S=>k(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(Xr,{active:s===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!v("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:_u.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=>k(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=>k(j.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(z.RestartAlt,{sx:{fontSize:18}}),onClick:x,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:j=>k(j.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:h,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Ru=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Wu={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 So(t,o,n,i,s=new Date){const[l,d]=o.split(":").map(Number),c=new Date(s);if(c.setSeconds(0,0),c.setHours(l,d,0,0),t==="daily")return c<=s&&c.setDate(c.getDate()+1),c.toISOString();if(t==="weekly"){const u=n??1,x=c.getDay();let h=u-x;return h<0&&(h+=7),h===0&&c<=s&&(h=7),c.setDate(c.getDate()+h),c.toISOString()}if(t==="monthly"){const u=Math.min(i??1,28);return c.setDate(u),c<=s&&(c.setMonth(c.getMonth()+1),c.setDate(u)),c.toISOString()}return c.toISOString()}function Pu(t){const o=ts(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${Ru[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Wu[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function ts(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Nu(t){const o=new Date(t).getTime()-Date.now();if(o<=0)return"now";const n=Math.floor(o/1e3),i=Math.floor(n/86400),s=Math.floor(n%86400/3600),l=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${l}m`:l>0?`in ${l}m`:"in less than a minute"}function Lu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=ts(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${s}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${s}`}function rs(t){return`urm_schedules_${t}`}function os(t){try{const o=localStorage.getItem(rs(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 ns(t,o){try{localStorage.setItem(rs(t),JSON.stringify(o))}catch{}}const Fu=[{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"}],Vu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,is={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},nr={"& .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 Hu({initial:t=is,isEditing:o=!1,onSave:n,onBack:i}){const[s,l]=p.useState(t),[d,c]=p.useState(!1),[u,x]=p.useState(!1),h=(g,B)=>l(v=>({...v,[g]:B})),b=s.email.trim().length>0&&!Vu.test(s.email.trim()),m=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.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=>k(g.palette.text.primary,.06)}},children:e.jsx(z.ArrowBack,{sx:{fontSize:18}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:o?"Edit schedule":"New schedule"})]}),e.jsx(r.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:g=>{h("name",g.target.value),d&&g.target.value.trim()&&c(!1)},onBlur:()=>c(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!s.name.trim(),helperText:d&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:nr}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:nr,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:s.frequency,label:"Frequency",onChange:g=>h("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"})]})]}),s.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:nr,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:s.dayOfWeek,label:"Day of week",onChange:g=>h("dayOfWeek",Number(g.target.value)),children:Fu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),s.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:g=>h("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:s.dayOfMonth<1||s.dayOfMonth>28,helperText:s.dayOfMonth<1||s.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:nr}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:g=>h("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:nr}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:nr,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:s.format,label:"Export format",onChange:g=>h("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:s.scope,onChange:g=>h("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:s.email,onChange:g=>h("email",g.target.value),onBlur:()=>x(!0),placeholder:"user@company.com",error:u&&b,helperText:u&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(z.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:nr}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(z.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>k(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>m&&n(s),disabled:!m,size:"small",variant:"contained",sx:{fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Uu({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>so(i),boxShadow:i=>{var s;return`0 8px 32px ${k(((s=i.palette.common)==null?void 0:s.black)??"#000",.14)}`}}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:i=>k(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(z.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{fontSize:"0.8125rem",color:"text.secondary",borderRadius:i=>`${i.shape.borderRadius}px`,"&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",sx:{fontSize:"0.8125rem",borderRadius:i=>`${i.shape.borderRadius}px`,px:2},children:"Delete"})]})]})}function Yu({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:s,onDelete:l}){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?c=>k(c.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?c=>k(c.palette.success.main,.1):c=>k(c.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:Pu(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:c=>k(c.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:c=>k(c.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(z.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:c=>k(c.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: ",Nu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Lu(t.lastRunAt)," · ",t.runCount," run",t.runCount!==1?"s":""]}):e.jsx(r.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[e.jsx(r.Tooltip,{title:"Edit",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>s(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:c=>k(c.palette.primary.main,.08)}},children:e.jsx(z.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?c=>k(c.palette.warning.main,.08):c=>k(c.palette.success.main,.08)}},children:d?e.jsx(z.Pause,{sx:{fontSize:15}}):e.jsx(z.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:c=>k(c.palette.primary.main,.08)}},children:e.jsx(z.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>l(t.id),sx:{color:"error.main","&:hover":{bgcolor:c=>k(c.palette.error.main,.08)}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})]})]})]})}function Gu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[l,d]=p.useState([]),[c,u]=p.useState({type:"list"}),[x,h]=p.useState(0),[b,m]=p.useState(null);p.useEffect(()=>{t&&(d(os(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const T=setInterval(()=>h(R=>R+1),3e4);return()=>clearInterval(T)},[t]);const g=p.useCallback(T=>{d(T),ns(n,T)},[n]),B=T=>{const R=So(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth),G={id:`sched-${Date.now()}`,reportId:n,name:T.name.trim(),frequency:T.frequency,dayOfWeek:T.frequency==="weekly"?T.dayOfWeek:void 0,dayOfMonth:T.frequency==="monthly"?T.dayOfMonth:void 0,time:T.time,format:T.format,scope:T.scope,email:T.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:R,runCount:0};g([...l,G]),u({type:"list"})},v=T=>{if(c.type!=="edit")return;const R=c.schedule,G=So(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth);g(l.map(X=>X.id===R.id?{...R,name:T.name.trim(),frequency:T.frequency,dayOfWeek:T.frequency==="weekly"?T.dayOfWeek:void 0,dayOfMonth:T.frequency==="monthly"?T.dayOfMonth:void 0,time:T.time,format:T.format,scope:T.scope,email:T.email.trim()||void 0,nextRunAt:G}:X)),u({type:"list"})},j=T=>{g(l.map(R=>{if(R.id!==T)return R;const G=R.isActive?R.nextRunAt:So(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:G}}))},S=T=>{s(T);const R=new Date().toISOString();g(l.map(G=>G.id===T.id?{...G,lastRunAt:R,runCount:G.runCount+1}:G))},I=T=>{const R=l.find(G=>G.id===T)??null;m(R)},y=()=>{b&&(g(l.filter(T=>T.id!==b.id)),m(null))},C=T=>({name:T.name,frequency:T.frequency,dayOfWeek:T.dayOfWeek??1,dayOfMonth:T.dayOfMonth??1,time:T.time,format:T.format,scope:T.scope,email:T.email??""}),a=c.type!=="list",A=l.filter(T=>T.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:a,PaperProps:{sx:{borderRadius:T=>Me(T),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:T=>k(T.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(z.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(lr,{content:cr.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:T=>k(T.palette.text.primary,.06)}},children:e.jsx(z.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[a&&e.jsx(Hu,{initial:c.type==="edit"?C(c.schedule):is,isEditing:c.type==="edit",onSave:c.type==="edit"?v:B,onBack:()=>u({type:"list"})}),c.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:l.length===0?"No schedules yet":`${A} of ${l.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(z.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",onClick:()=>u({type:"create"}),sx:{fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),l.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(z.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:l.map(T=>e.jsx(Yu,{schedule:T,tick:x,onToggle:j,onRunNow:S,onEdit:R=>u({type:"edit",schedule:R}),onDelete:I},T.id))})]})]}),c.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:T=>k(T.palette.warning.main,.06),border:"1px solid",borderColor:T=>k(T.palette.warning.main,.2)},children:[e.jsx(z.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:T=>k(T.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Uu,{scheduleName:b.name,onConfirm:y,onCancel:()=>m(null)})]})}const qu=6e4;function Ju({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:l,columnVisibility:d,columnOrder:c,filters:u,sortStack:x,onFired:h}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:l,columnVisibility:d,columnOrder:c,filters:u,sortStack:x,onFired:h});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:l,columnVisibility:d,columnOrder:c,filters:u,sortStack:x,onFired:h}});const m=p.useCallback(g=>{var T,R;const{reportName:B,uploadedData:v,processedData:j,schema:S,activeView:I,columnVisibility:y,columnOrder:C,filters:a,sortStack:A}=b.current;try{const G=g.scope==="all"?v:j,X=jo(G,S,a,A,I,y,C),te=`${g.name}_scheduled`;switch(g.format){case"csv":Co(X,te,{scope:g.scope});break;case"excel":wo(X,te,{scope:g.scope});break;case"json":ko(X,te,{scope:g.scope});break}if(g.email){const f=encodeURIComponent(`Scheduled Report: ${g.name}`),_=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
90
90
 
91
91
  Report: ${B}
92
- Format: ${y.format.toUpperCase()}
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:${y.email}?subject=${g}&body=${_}`,"_blank")}(R=(T=b.current).onFired)==null||R.call(T,y)}catch(q){rr.error("urm:scheduler",`Export failed for schedule: ${y.name}`,q)}},[]);p.useEffect(()=>{if(!t)return;const y=()=>{const{reportId:v}=b.current;if(!v)return;const j=os(v),S=new Date;let I=!1;const f=j.map(w=>{if(!w.isActive)return w;if(new Date(w.nextRunAt)<=S){m(w);const $=So(w.frequency,w.time,w.dayOfWeek,w.dayOfMonth,S);return I=!0,{...w,lastRunAt:S.toISOString(),nextRunAt:$,runCount:w.runCount+1}}return w});I&&ns(v,f)};y();const B=setInterval(y,qu);return()=>clearInterval(B)},[t,m])}function ss({reportEngine:t}){var Ae,ut,Zt,Vr,Bt;const{activeReport:o,paginatedData:n,processedData:i,displayData:a,tableMetrics:c,tableEngine:d,activeView:l,isDirty:u,currentTableState:x,viewChanges:h,showFilterPanel:b,setShowFilterPanel:m,filterFocusColumn:y,handleAddFilter:B,handleUpdateFilter:v,handleRemoveFilter:j,handleClearAllFilters:S,handleReplaceFilters:I,handleOpenFilterForColumn:f,handleCloseFilterPanel:w,handleClearFiltersForColumn:s,showSortPanel:$,setShowSortPanel:T,handleSort:R,handleUpdateSortStack:q,handleSortAscending:X,handleSortDescending:te,showManageViews:g,setShowManageViews:_,showCreateViewModal:W,setShowCreateViewModal:V,showEditViewModal:Z,setShowEditViewModal:xe,showDeleteConfirmation:me,setShowDeleteConfirmation:F,editingView:A,deletingView:H,handleSelectView:ne,handleCreateView:J,handleUpdateCurrentView:ee,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:ie,handleSaveAsNewView:P,handleRevertChanges:se,handleToggleDefault:ce,handleToggleFavorite:ae,handleSoftDelete:ge,handleRestoreView:K,handlePermanentDelete:_e,handleEditView:Ye,handleSaveEditView:it,handleConfirmDelete:ar,handlePromoteToGlobal:Ir,showManageColumns:Vt,setShowManageColumns:pt,handleUpdateColumnVisibility:Ve,handleUpdateColumnOrder:Be,handleUpdateColumnWidth:Mt,handleResetColumnLayout:jt,showGroupPanel:Qe,setShowGroupPanel:Ue,handleGroup:et,handleToggleGroupCollapse:lr,searchQuery:tt,searchHistory:st,handleSearchChange:Pe,handleAddToSearchHistory:cr,handleToggleSearchFavourite:zr,handleDeleteSearchHistory:Ht,selectedRowIds:xt,handleToggleRowSelection:Ct,handleToggleAllRows:dr,handleRangeSelection:wt,handleClearSelection:ao,handleUpdateSelectionAfterDelete:ur,currentPage:Br,pageSize:kt,paginationEngine:at,handlePageChange:Er,handlePageSizeChange:Ut,isExporting:je,showExportModal:Dr,setShowExportModal:pr,showDirtyExportWarning:lt,handleExport:L,handleExportWithConfig:Ge,handleExportSelected:Ce,handleExportAnyway:He,handleSaveAndExport:Or,handleCancelExport:Yt,showAuditHistory:Tt,setShowAuditHistory:Rt,showCreatePreset:Gt,setShowCreatePreset:qt,showManagePresets:Ar,setShowManagePresets:Jt,generatedPreset:Me,activePreset:Q,handleOpenManagePresets:It,handleCreatePreset:we,handleCopyPresetLink:ke,handleOpenPreset:ct,handleClearActivePreset:xr,handleOpenPresetById:mt,handleCopyPresetLinkById:qe,handleDeletePresetById:mr,isViewerRole:hr,userRole:fr,featureLimitWarning:zt,setFeatureLimitWarning:$r,reportError:Wt,setReportError:Kt,handleError:rt,updateReport:dt,showSnack:Ne,favoriteRowIndices:ht,resolvedFavoritesSet:gr,showFavoritesOnly:ft,handleToggleRowFavorite:_r,handleBulkSetFavorites:Mr,handleToggleFavoritesFilter:Rr}=t,[Wr,yr]=p.useState(!1);Ju({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)||((ut=l==null?void 0:l.snapshot)==null?void 0:ut.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:ue=>{Ne(`Scheduled export "${ue.name}" completed`,"success")}});const Pr=p.useCallback((ue,he)=>{if(!(o!=null&&o.uploadedData))return;const Re=[...o.uploadedData];Re[ue]=he,dt(o.id,{uploadedData:Re})},[o,dt]),Nr=p.useCallback(ue=>{if(!(o!=null&&o.uploadedData))return;const he=o.uploadedData.indexOf(ue);if(he===-1)return;const Re=o.uploadedData.filter((Y,pe)=>pe!==he),E=(o.favoriteRowIndices||[]).filter(Y=>Y!==he).map(Y=>Y>he?Y-1:Y);dt(o.id,{uploadedData:Re,favoriteRowIndices:E}),ur(ue)},[o,dt,ur]),Lr=p.useCallback((ue,he)=>{if(!(o!=null&&o.uploadedData))return;const Re=o.uploadedData.indexOf(he),E=Re!==-1?Re+1:ue+1,Y=[...o.uploadedData];Y.splice(E,0,{...he});const Le=(o.favoriteRowIndices??[]).map(de=>de>=E?de+1:de);dt(o.id,{uploadedData:Y,favoriteRowIndices:Le})},[o,dt]),Pt=nr(),{handleDevConfigChange:br}=Eo(),[Fr,Xt]=p.useState(!1);return p.useEffect(()=>{const ue=he=>{he.ctrlKey&&he.shiftKey&&he.key==="D"&&(he.preventDefault(),Xt(!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:[!hr&&u&&l&&e.jsx(xu,{viewName:l.name,isDefaultView:l.isDefault,changes:h,onSaveToCurrentView:l.isDefault?void 0:ee,onSaveAsNewView:P,onCancel:se}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[zt&&e.jsx(Eu,{warning:zt,onDismiss:()=>$r(null)}),Wt&&e.jsx(Du,{error:Wt,onDismiss:()=>Kt(null)}),lt&&e.jsx(mu,{onExportAnyway:He,onSaveAndExport:Or,onCancel:Yt}),e.jsx(ru,{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:X,onSortDescending:te,onOpenFilters:()=>m(!0),onOpenSort:()=>T(!0),onOpenFilterForColumn:f,onSelectView:ne,onCreateView:()=>V(!0),onManageViews:()=>_(!0),onUpdateCurrentView:ee,onSaveAsNewView:P,onToggleDefault:ce,onToggleFavorite:ae,onRestoreView:K,onPermanentDelete:_e,onExport:L,onOpenColumns:()=>pt(!0),onUpdateColumnWidth:Mt,onUpdateColumnOrder:Be,onUpdateColumnVisibility:Ve,onClearFiltersForColumn:s,onResetLayout:jt,onOpenGroup:()=>Ue(!0),onGroupByColumn:ue=>{et({enabled:!0,column:ue,showCounts:!0})},onToggleGroupCollapse:lr,onOpenAuditHistory:()=>Rt(!0),onOpenScheduledReports:()=>yr(!0),searchQuery:tt,searchHistory:st,onAddToSearchHistory:cr,onToggleSearchFavourite:zr,onDeleteSearchHistory:Ht,selectedRowIds:xt,onSearchChange:Pe,onToggleRowSelection:Ct,onToggleAllRows:dr,onRangeSelection:wt,onClearSelection:ao,onExportSelected:Ce,currentPage:(at==null?void 0:at.currentPage)||Br,pageSize:(at==null?void 0:at.pageSize)||kt,onPageChange:Er,onPageSizeChange:Ut,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:hr,userRole:fr,reportName:o.name,onEditRow:Pr,onDeleteRow:Nr,onDuplicateRow:Lr,favoriteRowIndices:ht,resolvedFavoritesSet:gr,showFavoritesOnly:ft,onToggleRowFavorite:_r,onBulkSetFavorites:Mr,onToggleFavoritesFilter:Rr,showDevPanel:Pt.display.showDevPanel,onOpenDevConfig:()=>Xt(!0)})]}),b&&e.jsx(Kr,{feature:"Filters",onError:ue=>{const he=Ot("ui","filters",ue);rt(he)},children:e.jsx(ou,{schema:o.schema,filters:o.filters??[],onAddFilter:B,onUpdateFilter:v,onRemoveFilter:j,onClearAll:S,onReplaceFilters:I,onClose:w,focusColumn:y})}),$&&e.jsx(Kr,{feature:"Sorting",onError:ue=>{const he=Ot("ui","sorting",ue);rt(he)},children:e.jsx(iu,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:q,onClose:()=>T(!1)})}),g&&e.jsx(Kr,{feature:"Views",onError:ue=>{const he=Ot("ui","views",ue);rt(he)},children:e.jsx(su,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:ne,onCreateView:()=>{_(!1),V(!0)},onEditView:Ye,onDeleteView:ge,onRestoreView:K,onPermanentDelete:_e,onPromoteToGlobal:Ir,isAdmin:((Zt=Pt.views)==null?void 0:Zt.isAdmin)??!1,onClose:()=>_(!1)})}),W&&x&&(()=>{var Re;const ue=(o.views??[]).filter(E=>!E.isDeleted).length,he=((Re=Pt.views)==null?void 0:Re.maxViews)??10;return e.jsx(hi,{currentSnapshot:x,onSave:J,onClose:()=>V(!1),atViewLimit:ue>=he,maxViews:he})})(),Z&&A&&e.jsx(hi,{currentSnapshot:A.snapshot,onSave:it,onClose:()=>{xe(!1)},isEditMode:!0,initialName:A.name,initialDescription:A.description,initialIsDefault:A.isDefault}),me&&H&&e.jsx(au,{viewName:H.name,onConfirm:ar,onCancel:()=>{F(!1)}}),Vt&&l&&e.jsx(cu,{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:Ve,onUpdateColumnOrder:Be,onUpdateColumnWidth:Mt,onResetLayout:jt,onSelectView:ue=>{ne(ue)},onSaveToCurrentView:ue=>{le(ue),pt(!1)},onSaveToAllViews:ue=>{ie(ue),pt(!1)},onClose:()=>pt(!1)}),Qe&&e.jsx(Kr,{feature:"Grouping",onError:ue=>{const he=Ot("ui","grouping",ue);rt(he)},children:e.jsx(du,{schema:o.schema,grouping:o.grouping||null,onApply:et,onClose:()=>Ue(!1)})}),Tt&&e.jsx(gu,{auditHistory:o.auditHistory||[],onClose:()=>Rt(!1)}),Gt&&e.jsx(yu,{onSave:we,onClose:()=>qt(!1)}),Ar&&e.jsx(vu,{presets:o.presets||[],reportId:o.id,onOpenPreset:mt,onDeletePreset:mr,onClose:()=>Jt(!1)}),Q&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(bu,{presetName:Q.name,onClear:xr})}),Dr&&e.jsx(Kr,{feature:"Export",onError:ue=>{const he=Ot("ui","export",ue);rt(he)},children:e.jsx(Bu,{totalRows:(c==null?void 0:c.totalRows)||((Vr=o.uploadedData)==null?void 0:Vr.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Bt=d==null?void 0:d.columnEngine)==null?void 0:Bt.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:Ge,onClose:()=>{pr(!1)}})}),o&&e.jsx(Gu,{open:Wr,onClose:()=>yr(!1),reportId:o.id,reportName:o.name,onRunNow:ue=>{const he=ue.scope==="all"?o.uploadedData||[]:i||[],Re=jo(he,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);ue.format==="csv"&&Co(Re,ue.name),ue.format==="excel"&&wo(Re,ue.name),ue.format==="json"&&ko(Re,ue.name),Ne(`"${ue.name}" exported successfully`,"success")}}),e.jsx(Mu,{open:Fr,onClose:()=>Xt(!1),config:Pt,onApply:br})]})}function as({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 ls({hasExternalData:t=!1}){const o=Eo(),{reports:n,activeReportId:i,activeReport:a,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:u,setIsModalOpen:x,setActiveReportId:h,createReport:b,handleFileUpload:m,handleUploadError:y,handleRetry:B,handleConfirm:v,snack:j,handleSnackClose:S}=o,I=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(dl,{onCreateReport:()=>x(!0),reports:n,activeReportId:i,onReportClick:h}),e.jsx(r.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:I?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(Zi,{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(ss,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&a.schema&&a.uploadedData?e.jsx(Cd,{schema:a.schema,onConfirm:v,hasConflicts:l}):a.uploadError?e.jsx(wd,{error:a.uploadError,onRetry:B}):e.jsx(jd,{onFileUpload:m,onError:y,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(Sd,{isOpen:u,onClose:()=>x(!1),onCreate:b}),e.jsx(as,{open:j.open,message:j.message,severity:j.severity,onClose:S})]})}function Ku({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:a}={}){return e.jsx(un,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:a,children:e.jsx(ls,{hasExternalData:!!(t||o)})})}function cs(){const t=Eo(),{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(ss,{reportEngine:t}):e.jsx(Zi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(as,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Xu({data:t,autoLoad:o=!0,config:n}){return e.jsx(un,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(cs,{})})}exports.URMBuilder=Ku;exports.URMBuilderRaw=ls;exports.URMProvider=un;exports.URMViewer=Xu;exports.URMViewerRaw=cs;exports.useURMContext=Eo;
95
+ The file has been downloaded to your device.`);window.open(`mailto:${g.email}?subject=${f}&body=${_}`,"_blank")}(R=(T=b.current).onFired)==null||R.call(T,g)}catch(G){ir.error("urm:scheduler",`Export failed for schedule: ${g.name}`,G)}},[]);p.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:v}=b.current;if(!v)return;const j=os(v),S=new Date;let I=!1;const y=j.map(C=>{if(!C.isActive)return C;if(new Date(C.nextRunAt)<=S){m(C);const A=So(C.frequency,C.time,C.dayOfWeek,C.dayOfMonth,S);return I=!0,{...C,lastRunAt:S.toISOString(),nextRunAt:A,runCount:C.runCount+1}}return C});I&&ns(v,y)};g();const B=setInterval(g,qu);return()=>clearInterval(B)},[t,m])}function ss({reportEngine:t}){var yr,br,vr,tr,Sr;const{activeReport:o,paginatedData:n,processedData:i,tableMetrics:s,tableEngine:l,activeView:d,isDirty:c,currentTableState:u,viewChanges:x,showFilterPanel:h,setShowFilterPanel:b,filterFocusColumn:m,handleAddFilter:g,handleUpdateFilter:B,handleRemoveFilter:v,handleClearAllFilters:j,handleReplaceFilters:S,handleOpenFilterForColumn:I,handleCloseFilterPanel:y,handleClearFiltersForColumn:C,showSortPanel:a,setShowSortPanel:A,handleSort:T,handleUpdateSortStack:R,handleSortAscending:G,handleSortDescending:X,showManageViews:te,setShowManageViews:f,showCreateViewModal:_,setShowCreateViewModal:W,showEditViewModal:V,setShowEditViewModal:Z,showDeleteConfirmation:xe,setShowDeleteConfirmation:he,editingView:L,deletingView:$,handleSelectView:H,handleCreateView:ne,handleUpdateCurrentView:q,handleSaveColumnConfigToCurrentView:ee,handleSaveColumnConfigToAllViews:le,handleSaveAsNewView:ie,handleRevertChanges:P,handleToggleDefault:se,handleToggleFavorite:ce,handleSoftDelete:ae,handleRestoreView:ge,handlePermanentDelete:K,handleEditView:Re,handleSaveEditView:Ye,handleConfirmDelete:it,handlePromoteToGlobal:dr,showManageColumns:Br,setShowManageColumns:ut,handleUpdateColumnVisibility:$t,handleUpdateColumnOrder:Ne,handleUpdateColumnWidth:Ee,handleResetColumnLayout:_t,showGroupPanel:Mt,setShowGroupPanel:Je,handleGroup:Ue,handleToggleGroupCollapse:st,searchQuery:ur,searchHistory:et,handleSearchChange:at,handleAddToSearchHistory:We,handleToggleSearchFavourite:pr,handleDeleteSearchHistory:Er,selectedRowIds:Ht,handleToggleRowSelection:pt,handleToggleAllRows:Ct,handleRangeSelection:xr,handleClearSelection:wt,handleUpdateSelectionAfterDelete:Dr,currentPage:Or,pageSize:Ar,paginationEngine:Ge,handlePageChange:mr,handlePageSizeChange:$r,isExporting:Ut,showExportModal:Ce,setShowExportModal:_r,showDirtyExportWarning:hr,handleExport:lt,handleExportWithConfig:F,handleExportSelected:qe,handleExportAnyway:we,handleSaveAndExport:Le,handleCancelExport:Mr,showAuditHistory:Yt,setShowAuditHistory:xt,showCreatePreset:Gt,setShowCreatePreset:qt,showManagePresets:Jt,setShowManagePresets:Rr,activePreset:Rt,handleCreatePreset:$e,handleClearActivePreset:Q,handleOpenPresetById:mt,handleDeletePresetById:ke,isViewerRole:ye,userRole:tt,featureLimitWarning:Kt,setFeatureLimitWarning:ht,reportError:Ve,setReportError:fr,handleError:kt,updateReport:ct,showSnack:Tt,favoriteRowIndices:Wr,resolvedFavoritesSet:Xt,showFavoritesOnly:Zt,handleToggleRowFavorite:Wt,handleBulkSetFavorites:gr,handleToggleFavoritesFilter:Fe}=t,[ft,Qt]=p.useState(!1);Ju({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:d,columnVisibility:(o==null?void 0:o.columnVisibility)||((yr=d==null?void 0:d.snapshot)==null?void 0:yr.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((br=d==null?void 0:d.snapshot)==null?void 0:br.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:ue=>{Tt(`Scheduled export "${ue.name}" completed`,"success")}});const gt=p.useCallback((ue,de)=>{if(!(o!=null&&o.uploadedData))return;const Be=[...o.uploadedData];Be[ue]=de,ct(o.id,{uploadedData:Be})},[o,ct]),Pr=p.useCallback(ue=>{if(!(o!=null&&o.uploadedData))return;const de=o.uploadedData.indexOf(ue);if(de===-1)return;const Be=o.uploadedData.filter((rt,It)=>It!==de),dt=(o.favoriteRowIndices||[]).filter(rt=>rt!==de).map(rt=>rt>de?rt-1:rt);ct(o.id,{uploadedData:Be,favoriteRowIndices:dt}),Dr(ue)},[o,ct,Dr]),Nr=p.useCallback((ue,de)=>{if(!(o!=null&&o.uploadedData))return;const Be=o.uploadedData.indexOf(de),dt=Be!==-1?Be+1:ue+1,rt=[...o.uploadedData];rt.splice(dt,0,{...de});const Vr=(o.favoriteRowIndices??[]).map(Nt=>Nt>=dt?Nt+1:Nt);ct(o.id,{uploadedData:rt,favoriteRowIndices:Vr})},[o,ct]),Pt=ar(),{handleDevConfigChange:Lr}=Eo(),[Fr,er]=p.useState(!1);return p.useEffect(()=>{const ue=de=>{de.ctrlKey&&de.shiftKey&&de.key==="D"&&(de.preventDefault(),er(!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:[!ye&&c&&d&&e.jsx(xu,{viewName:d.name,isDefaultView:d.isDefault,changes:x,onSaveToCurrentView:d.isDefault?void 0:q,onSaveAsNewView:ie,onCancel:P}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[Kt&&e.jsx(Eu,{warning:Kt,onDismiss:()=>ht(null)}),Ve&&e.jsx(Du,{error:Ve,onDismiss:()=>fr(null)}),hr&&e.jsx(mu,{onExportAnyway:we,onSaveAndExport:Le,onCancel:Mr}),e.jsx(ru,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:c,isExporting:Ut,columnVisibility:o.columnVisibility||(d==null?void 0:d.snapshot.columnVisibility),columnOrder:o.columnOrder||(d==null?void 0:d.snapshot.columnOrder),columnWidths:o.columnWidths||(d==null?void 0:d.snapshot.columnWidths),grouping:o.grouping,onSort:T,onSortAscending:G,onSortDescending:X,onOpenFilters:()=>b(!0),onOpenSort:()=>A(!0),onOpenFilterForColumn:I,onSelectView:H,onCreateView:()=>W(!0),onManageViews:()=>f(!0),onUpdateCurrentView:q,onSaveAsNewView:ie,onToggleDefault:se,onToggleFavorite:ce,onRestoreView:ge,onPermanentDelete:K,onExport:lt,onOpenColumns:()=>ut(!0),onUpdateColumnWidth:Ee,onUpdateColumnOrder:Ne,onUpdateColumnVisibility:$t,onClearFiltersForColumn:C,onResetLayout:_t,onOpenGroup:()=>Je(!0),onGroupByColumn:ue=>{Ue({enabled:!0,column:ue,showCounts:!0})},onToggleGroupCollapse:st,onOpenAuditHistory:()=>xt(!0),onOpenScheduledReports:()=>Qt(!0),searchQuery:ur,searchHistory:et,onAddToSearchHistory:We,onToggleSearchFavourite:pr,onDeleteSearchHistory:Er,selectedRowIds:Ht,onSearchChange:at,onToggleRowSelection:pt,onToggleAllRows:Ct,onRangeSelection:xr,onClearSelection:wt,onExportSelected:qe,currentPage:(Ge==null?void 0:Ge.currentPage)||Or,pageSize:(Ge==null?void 0:Ge.pageSize)||Ar,onPageChange:mr,onPageSizeChange:$r,totalRowsBeforePagination:(s==null?void 0:s.searchedRows)||i.length,isReadOnly:ye,userRole:tt,reportName:o.name,onEditRow:gt,onDeleteRow:Pr,onDuplicateRow:Nr,favoriteRowIndices:Wr,resolvedFavoritesSet:Xt,showFavoritesOnly:Zt,onToggleRowFavorite:Wt,onBulkSetFavorites:gr,onToggleFavoritesFilter:Fe,showDevPanel:Pt.display.showDevPanel,onOpenDevConfig:()=>er(!0)})]}),h&&e.jsx(Kr,{feature:"Filters",onError:ue=>{const de=Et("ui","filters",ue);kt(de)},children:e.jsx(ou,{schema:o.schema,filters:o.filters??[],onAddFilter:g,onUpdateFilter:B,onRemoveFilter:v,onClearAll:j,onReplaceFilters:S,onClose:y,focusColumn:m})}),a&&e.jsx(Kr,{feature:"Sorting",onError:ue=>{const de=Et("ui","sorting",ue);kt(de)},children:e.jsx(iu,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:R,onClose:()=>A(!1)})}),te&&e.jsx(Kr,{feature:"Views",onError:ue=>{const de=Et("ui","views",ue);kt(de)},children:e.jsx(su,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:H,onCreateView:()=>{f(!1),W(!0)},onEditView:Re,onDeleteView:ae,onRestoreView:ge,onPermanentDelete:K,onPromoteToGlobal:dr,isAdmin:((vr=Pt.views)==null?void 0:vr.isAdmin)??!1,onClose:()=>f(!1)})}),_&&u&&(()=>{var Be;const ue=(o.views??[]).filter(dt=>!dt.isDeleted).length,de=((Be=Pt.views)==null?void 0:Be.maxViews)??10;return e.jsx(hi,{currentSnapshot:u,onSave:ne,onClose:()=>W(!1),atViewLimit:ue>=de,maxViews:de})})(),V&&L&&e.jsx(hi,{currentSnapshot:L.snapshot,onSave:Ye,onClose:()=>{Z(!1)},isEditMode:!0,initialName:L.name,initialDescription:L.description,initialIsDefault:L.isDefault}),xe&&$&&e.jsx(au,{viewName:$.name,onConfirm:it,onCancel:()=>{he(!1)}}),Br&&d&&e.jsx(cu,{schema:o.schema,columnVisibility:o.columnVisibility||d.snapshot.columnVisibility,columnOrder:o.columnOrder||d.snapshot.columnOrder,columnWidths:o.columnWidths||d.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:$t,onUpdateColumnOrder:Ne,onUpdateColumnWidth:Ee,onResetLayout:_t,onSelectView:ue=>{H(ue)},onSaveToCurrentView:ue=>{ee(ue),ut(!1)},onSaveToAllViews:ue=>{le(ue),ut(!1)},onClose:()=>ut(!1)}),Mt&&e.jsx(Kr,{feature:"Grouping",onError:ue=>{const de=Et("ui","grouping",ue);kt(de)},children:e.jsx(du,{schema:o.schema,grouping:o.grouping||null,onApply:Ue,onClose:()=>Je(!1)})}),Yt&&e.jsx(gu,{auditHistory:o.auditHistory||[],onClose:()=>xt(!1)}),Gt&&e.jsx(yu,{onSave:$e,onClose:()=>qt(!1)}),Jt&&e.jsx(vu,{presets:o.presets||[],reportId:o.id,onOpenPreset:mt,onDeletePreset:ke,onClose:()=>Rr(!1)}),Rt&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(bu,{presetName:Rt.name,onClear:Q})}),Ce&&e.jsx(Kr,{feature:"Export",onError:ue=>{const de=Et("ui","export",ue);kt(de)},children:e.jsx(Bu,{totalRows:(s==null?void 0:s.totalRows)||((tr=o.uploadedData)==null?void 0:tr.length)||0,visibleRows:(s==null?void 0:s.searchedRows)||i.length,visibleColumnsCount:((Sr=l==null?void 0:l.columnEngine)==null?void 0:Sr.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(s==null?void 0:s.isGrouped)||!1,schema:o.schema,allRows:o.uploadedData||[],processedRows:i||[],onExport:F,onClose:()=>{_r(!1)}})}),o&&e.jsx(Gu,{open:ft,onClose:()=>Qt(!1),reportId:o.id,reportName:o.name,onRunNow:ue=>{const de=ue.scope==="all"?o.uploadedData||[]:i||[],Be=jo(de,o.schema||[],o.filters||[],o.sortStack||[],d,o.columnVisibility,o.columnOrder);ue.format==="csv"&&Co(Be,ue.name),ue.format==="excel"&&wo(Be,ue.name),ue.format==="json"&&ko(Be,ue.name),Tt(`"${ue.name}" exported successfully`,"success")}}),e.jsx(Mu,{open:Fr,onClose:()=>er(!1),config:Pt,onApply:Lr})]})}const Ku={error:"err",warning:"warn",info:"info",success:"suc"};function as({open:t,message:o,severity:n,onClose:i}){var S,I;const s=r.useTheme(),l=s.tokens,d=(l==null?void 0:l.notifPosition)??"top-right",c=(l==null?void 0:l.notifStyle)??"toast",u=(l==null?void 0:l.notifAccent)??"severity",x=(l==null?void 0:l.notifAutoDismiss)??!0,h=(l==null?void 0:l.toastW)??252,b=d.startsWith("top")?"top":"bottom",m=d.endsWith("center")?"center":d.endsWith("left")?"left":"right",g=Ku[n],B=((S=l==null?void 0:l.status)==null?void 0:S[`${g}Soft`])??s.palette[n].light,v=((I=l==null?void 0:l.status)==null?void 0:I[`${g}Txt`])??s.palette[n].dark,j=u==="primary"?s.palette.primary.main:u==="mono"?s.palette.text.secondary:v;return e.jsx(r.Snackbar,{open:t,autoHideDuration:x?2e3:void 0,onClose:(y,C)=>{C!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:b,horizontal:m},children:e.jsx(r.Alert,{severity:n,icon:!1,onClose:x?void 0:i,sx:{width:h,alignItems:"flex-start",bgcolor:B,color:v,boxShadow:c==="inline"?"none":(l==null?void 0:l.cardShadow)??3,border:c==="inline"?"1px solid":c==="toast"?(l==null?void 0:l.cardBorder)??"1px solid":"none",borderColor:"divider",borderLeft:c==="banner"?`4px solid ${j}`:void 0,borderRadius:`${s.shape.borderRadius}px`},children:o})})}function ls({hasExternalData:t=!1}){const o=Eo(),{reports:n,activeReportId:i,activeReport:s,uploadState:l,schema:d,hasSchemaConflicts:c,isModalOpen:u,setIsModalOpen:x,setActiveReportId:h,createReport:b,handleFileUpload:m,handleUploadError:g,handleRetry:B,handleConfirm:v,snack:j,handleSnackClose:S}=o,I=t&&l==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(dl,{onCreateReport:()=>x(!0),reports:n,activeReportId:i,onReportClick:h}),e.jsx(r.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:I?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(Zi,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):s?e.jsx(e.Fragment,{children:s.schemaLocked&&s.schema&&s.uploadedData&&s.views?e.jsx(ss,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:l==="preview"&&s.schema&&s.uploadedData?e.jsx(Cd,{schema:s.schema,onConfirm:v,hasConflicts:c}):s.uploadError?e.jsx(wd,{error:s.uploadError,onRetry:B}):e.jsx(jd,{onFileUpload:m,onError:g,isUploading:l==="uploading"})})}):null}),!t&&e.jsx(Sd,{isOpen:u,onClose:()=>x(!1),onCreate:b}),e.jsx(as,{open:j.open,message:j.message,severity:j.severity,onClose:S})]})}function Xu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(un,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(ls,{hasExternalData:!!(t||o)})})}function cs(){const t=Eo(),{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(ss,{reportEngine:t}):e.jsx(Zi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(as,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Zu({data:t,autoLoad:o=!0,config:n}){return e.jsx(un,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(cs,{})})}exports.URMBuilder=Xu;exports.URMBuilderRaw=ls;exports.URMProvider=un;exports.URMViewer=Zu;exports.URMViewerRaw=cs;exports.useURMContext=Eo;