dts-universal-report-module 1.0.13 → 1.0.15

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 +6451 -6422
  2. package/dist/index.js +26 -26
  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(`
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
1
+ "use strict";var Os=Object.defineProperty;var $s=(t,o,n)=>o in t?Os(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n;var Sn=(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"),As=require("xlsx"),z=require("@mui/icons-material"),r=require("@mui/material"),yi=require("react-dom"),_s=require("@emotion/react"),$t=require("react-dnd"),sn=require("react-dnd-html5-backend");function bi(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const To=bi(p),lo=bi(As),Ge={sort:{maxLevels:5},filter:{maxConditions:3,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},vi="urm_dev_config";function Ms(){try{const t=localStorage.getItem(vi);if(!t)return Ge;const o=JSON.parse(t),n={sort:{...Ge.sort,...o.sort},filter:{...Ge.filter,...o.filter},columns:{...Ge.columns,...o.columns},grouping:{...Ge.grouping,...o.grouping},export:{...Ge.export,...o.export},views:{...Ge.views,...o.views},dates:{...Ge.dates,...o.dates},display:{...Ge.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ge}}function Rs(t){try{localStorage.setItem(vi,JSON.stringify(t))}catch{}}function Ws(t,o,n){if(!n||!o)return t;const i={sort:{...t.sort,...o.sort},filter:{...t.filter,...o.filter},columns:{...t.columns,...o.columns},grouping:{...t.grouping,...o.grouping},export:{...t.export,...o.export},views:{...t.views,...o.views},dates:{...t.dates,...o.dates},display:{...t.display,...o.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const Si=p.createContext(Ge);function cr(){return p.useContext(Si)}const Ps=/^\d{4}-\d{2}-\d{2}$/,Ns=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Ls=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Fs=9783072e5,Vs=41024448e5,Hs=978307200,Us=4102444800;function Ys(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Fs&&t<=Vs?"timestamp_ms":Number.isInteger(t)&&t>=Hs&&t<=Us?"timestamp_s":"unknown":typeof t!="string"?"unknown":Ns.test(t)||Ps.test(t)?"iso":Ls.test(t.trim())?"locale_string":"unknown"}function Gs(t,o){const n=o.map(c=>c[t]).filter(c=>c!=null&&c!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const c of n){const l=Ys(c);i[l]++}const s=n.length,d=.7;for(const c of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[c]/s>=d)return c;return"unknown"}function qs(t,o){if(t==null||t==="")return null;try{switch(o){case"timestamp_ms":{const n=new Date(Number(t));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(t)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const jn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Js=["January","February","March","April","May","June","July","August","September","October","November","December"];function _e(t){return String(t).padStart(2,"0")}function Ks(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),d=Math.floor(s/60),c=Math.floor(d/60),l=Math.floor(c/24),u=Math.floor(l/7),x=Math.floor(l/30),h=Math.floor(l/365);let b;return s<60?b="just now":d<60?b=`${d} minute${d!==1?"s":""}`:c<24?b=`${c} hour${c!==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":""}`,s<60?b:i?`${b} ago`:`in ${b}`}function Xs(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),d=t.getHours(),c=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${_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`${jn[i]} ${_e(s)}, ${n}`;case"DD MMM YYYY":return`${_e(s)} ${jn[i]} ${n}`;case"MMMM D, YYYY":return`${Js[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${_e(i+1)}-${_e(s)} ${_e(d)}:${_e(c)}`;case"DD/MM/YYYY HH:mm":return`${_e(s)}/${_e(i+1)}/${n} ${_e(d)}:${_e(c)}`;case"MM/DD/YYYY HH:mm":return`${_e(i+1)}/${_e(s)}/${n} ${_e(d)}:${_e(c)}`;case"relative":return Ks(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Zs(t,o,n){if(!n||o==="unknown")return String(t);const i=qs(t,o);return!i||isNaN(i.getTime())?String(t):Xs(i,n)}function Qs(t){return t==null?"null":Array.isArray(t)?"array":typeof t=="object"?"object":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="string"?"string":"mixed"}function ji(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const d=o?`${o}.${s}`:s,c=t[s];c!==null&&typeof c=="object"&&!Array.isArray(c)&&n<2?Object.assign(i,ji(c,d,n+1)):i[d]=c}return i}function fo(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:ji(o))}function Yr(t){if(!Array.isArray(t)||t.length===0)return[];const o=fo(t),n=new Set;o.forEach(c=>{typeof c=="object"&&c!==null&&Object.keys(c).forEach(l=>n.add(l))});const i=[];n.forEach(c=>{const l=new Set;let u=0;o.forEach(m=>{typeof m=="object"&&m!==null&&c in m&&(u++,l.add(Qs(m[c])))});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:c,type:b,required:x,hasConflict:h})});const d=o.slice(0,50);for(const c of i){if(c.type!=="string"&&c.type!=="number")continue;const l=Gs(c.name,d);l!=="unknown"&&(c.type="date",c.dateFormat=l)}return i}function ea(t){return t.some(o=>o.hasConflict)}function Je(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 Cn(t){return t==null}function ta(t){return(o,n,i)=>{const s=Cn(o),d=Cn(n);if(s&&d)return 0;if(s)return 1;if(d)return-1;let c=0;switch(t){case"number":const l=Number(o),u=Number(n);c=l-u;break;case"boolean":c=(o?1:0)-(n?1:0);break;case"string":c=String(o).localeCompare(String(n));break;case"array":case"object":c=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:c=String(o).localeCompare(String(n));break}return i==="asc"?c:-c}}function ra(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,d)=>s.priority-d.priority);return[...t].sort((s,d)=>{for(const c of i){const l=o.find(h=>h.name===c.column);if(!l)continue;const x=ta(l.type)(s[c.column],d[c.column],c.direction);if(x!==0)return x}return 0})}function oa(t){return t===null?"asc":t==="asc"?"desc":null}function na(t){return t==="string"||t==="boolean"}function ia(t){return t.filter(o=>na(o.type))}function sa(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(d=>d[i.name]).filter(d=>typeof d=="number");s.length>0&&(n[i.name]=s.reduce((d,c)=>d+c,0))}}),n}function aa(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=Ci(t,n.levels,o);return wi(i,n.collapsedGroups||[])}function Ci(t,o,n,i="",s=0){if(s>=o.length)return t;const d=o[s].column,c=new Map;t.forEach(x=>{const h=x[d],b=h==null?"(empty)":String(h);c.has(b)||c.set(b,[]),c.get(b).push(x)});const l=[];return Array.from(c.keys()).sort().forEach(x=>{const h=c.get(x),b=`${d}:${x}`,m=i?`${i}|${b}`:b,y=sa(h,n),D=s<o.length-1?Ci(h,o,n,m,s+1):h,v={key:m,level:s,column:d,value:x,rowCount:h.length,aggregates:y,children:D};l.push(v)}),l}function wi(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&&wi(i.children,o,n)}else n.push(i);return n}function la(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function ki(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function Ti(t,o,n){return`${o}: ${n}`}function Xr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(s=>s.column),i=t.filter(s=>!n.includes(s));return[...n,...i]}function Ii(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(d=>d.column),s=t.filter(d=>!i.includes(d));if(n){const d=[],c=new Set(i),l=new Set(s);let u=0;for(const x of n)c.has(x)?d.push(x):l.has(x)&&u<s.length?(d.push(s[u]),u++):l.has(x)||d.push(x);for(let x=u;x<s.length;x++)d.includes(s[x])||d.push(s[x]);return d}return[...t]}function Ho(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 ca(t,o,n,i,s,d,c,l){const u={},x=[],h={};n.forEach(y=>{u[y.name]=!0,x.push(y.name),h[y.name]=170});const m=Ii(s||x,c||null,l||x);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:m,columnWidths:d||h,grouping:c||null}}function da(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(D=>{y[D]=n(m[D])}),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 s=t.columnVisibility??{},d=o.columnVisibility??{};if(i(s)!==i(d))return!0;const c=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(c!==l)return!1;const 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 ua(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function pa(t,o){var v,C,S;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){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 d=JSON.stringify(t.sortStack),c=JSON.stringify(o.sortStack);if(d!==c){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(k=>k).length,f=Object.values(o.columnVisibility).filter(k=>k).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),D=JSON.stringify(o.grouping);if(y!==D){const I=(v=t.grouping)==null?void 0:v.enabled,f=(C=o.grouping)==null?void 0:C.enabled;if(I&&!f){const k=((S=t.grouping)==null?void 0:S.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${k} grouping level${k>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 wn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function kn(t){return`[${t}]`}const ar={warn(t,o,...n){wn()&&console.warn(kn(t),o,...n)},error(t,o,...n){wn()&&console.error(kn(t),o,...n)}},zi="urm_report_";function xa(t,o){try{const n=`${zi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){ar.error("urm:persistence","Failed to save report state",n)}}function ma(t){try{const o=`${zi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return ar.error("urm:persistence","Failed to load report state",o),null}}function Io(t,o,n=0){const i=[];for(const s of t){const d=o.includes(s.key);if(i.push({type:"group",key:s.key,level:n,column:s.column,value:s.value,rowCount:s.rowCount,aggregates:s.aggregates,collapsed:d}),!d&&s.children&&s.children.length>0){const c=s.children[0];if(ha(c)){const l=s.children,u=Io(l,o,n+1);i.push(...u)}else{const l=s.children;for(const u of l)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:u})}}}return i}function ha(t){return t&&typeof t=="object"&&"key"in t&&"level"in t&&"column"in t&&"value"in t&&"rowCount"in t&&"aggregates"in t&&"children"in t}function an(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function ln(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),d=String(n.getDate()).padStart(2,"0"),c=`${i}-${s}-${d}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${c}.${o}`}function vo(t,o,n,i,s,d,c){let l,u;d?(l={...d},u=c||o.map(h=>h.name)):s?(l={...s.snapshot.columnVisibility},u=c||[...s.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:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:x,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function So(t,o="export",n){const{data:i,columnOrder:s,grouping:d}=t,c=s.filter(b=>t.columnVisibility[b]);let l;if(d&&d.enabled){const b=d.collapsedGroups??[],m=Io(i,b);l=an(m)}else l=i;const u=c.join(","),x=l.map(b=>c.map(m=>{const y=b[m];if(y==null)return"";const D=String(y);return D.includes(",")||D.includes('"')||D.includes(`
2
+ `)?`"${D.replace(/"/g,'""')}"`:D}).join(",")),h=[u,...x].join(`
3
+ `);Bi(h,ln(o,"csv"),"text/csv;charset=utf-8;")}function jo(t,o="export",n){const{data:i,columnOrder:s,grouping:d}=t,c=s.filter(b=>t.columnVisibility[b]);let l;if(d&&d.enabled){const b=d.collapsedGroups??[],m=Io(i,b);l=an(m)}else l=i;const u=[c,...l.map(b=>c.map(m=>b[m]??""))],x=lo.utils.aoa_to_sheet(u),h=lo.utils.book_new();lo.utils.book_append_sheet(h,x,"Data"),lo.writeFile(h,ln(o,"xlsx"))}function Co(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:d,viewMeta:c,hiddenColumns:l,columnOrder:u,grouping:x}=t;let h;if(x&&x.enabled){const y=x.collapsedGroups??[],D=Io(i,y);h=an(D)}else h=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(c==null?void 0:c.name)||"Default View",filters:s.map(y=>({field:y.column,operator:y.operator,value:y.value})),sortStack:d.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);Bi(m,ln(o,"json"),"application/json;charset=utf-8;")}function Bi(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),d=document.createElement("a");d.href=s,d.download=o,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(s)}const Tn=10;function fa(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(d=>d.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],s.length>Tn&&(s=[...s].sort((c,l)=>c.isFavourite&&!l.isFavourite?-1:!c.isFavourite&&l.isFavourite?1:l.lastUsed-c.lastUsed).slice(0,Tn)),s}function ga(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ya(t,o){return t.filter(n=>n.query!==o)}function ba(t){const o=t.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...o,...n]}const va={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function Sa(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function ft(t,o){return va[o].includes(t)}function gt(t){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data",promote_global_view:"promote views to global"}[t]||"perform this action"}.`}function ja(t){return t==="viewer"}const In=1e3;function tn(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function vt(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return tn(n)}const Ca={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function Uo(t){if(!t||!t.column)return"a filter";const o=vt(t.column),n=Ca[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function zn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${vt(n.column)}"`).join(", ")}`}function wa(t){var s,d,c;const{action:o,previousState:n,newState:i}=t;switch(o){case"filter_added":{const l=i&&Array.isArray(i)?i[i.length-1]:i;return{summary:`Filter added: ${Uo(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Uo(n)}`};case"filter_updated":{const l=n,u=i;return(l==null?void 0:l.column)!==(u==null?void 0:u.column)?{summary:`Filter changed on "${vt(u==null?void 0:u.column)}"`,detail:`Previously filtered "${vt(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Uo(u)}`}}case"filter_cleared":{const l=Array.isArray(n)?n.length:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?vt(i.column):"",u=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${u}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?vt(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${zn(i)}`};case"group_level_removed":{const l=n,u=(d=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&d.column?vt(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${zn(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${vt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${vt(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],u=Array.isArray(i)?i:[];return l.length>0&&u.length>0?{summary:"Column order changed",detail:`${u.length} column${u.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",u=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${vt(l)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return l&&u?{summary:`Switched to view "${u}"`,detail:`From "${l}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,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?`${tn(x)} · View: "${h}"`:tn(x)}}case"export_triggered":{const l=((c=i==null?void 0:i.format)==null?void 0:c.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&u?{summary:`Theme changed from "${l}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:Ta(o)}}}function ka(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Di(t,o,n,i,s,d){return{id:ka(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:d}}function Ei(t,o){const n=[o,...t];return n.length>In?n.slice(0,In):n}function Ta(t){return{filter_added:"Filter Added",filter_removed:"Filter Removed",filter_updated:"Filter Updated",filter_cleared:"All Filters Cleared",sort_level_added:"Sort Level Added",sort_level_removed:"Sort Level Removed",sort_reordered:"Sort Reordered",sort_cleared:"All Sorting Cleared",group_level_added:"Group Level Added",group_level_removed:"Group Level Removed",group_reordered:"Group Reordered",group_cleared:"All Grouping Cleared",column_hidden:"Column Hidden",column_shown:"Column Shown",column_reordered:"Columns Reordered",column_resized:"Column Resized",view_created:"View Created",view_updated:"View Updated",view_deleted:"View Deleted",view_set_default:"View Set as Default",view_switched:"View Switched",theme_changed:"Theme Changed",export_triggered:"Export Triggered",export_csv:"Exported as CSV",export_excel:"Exported as Excel",export_json:"Exported as JSON",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[t]||t}function Ia(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function za(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),d=Math.floor(i/36e5),c=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:d<24?`${d} hour${d>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const Bn=100;function Ba(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Da(t){var d;const o=(d=t.views)==null?void 0:d.find(c=>c.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],s=Ii(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 Ea(t,o,n,i){return{id:Ba(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function Oa(t,o){const n=t||[];if(n.length>=Bn)throw new Error(`Maximum of ${Bn} 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 Aa(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function _a(t){const o=t.columnOrder,n=Xr(o,t.grouping);return{filters:t.filters.length>0?[...t.filters]:void 0,sortStack:t.sortStack.length>0?[...t.sortStack]:void 0,columnVisibility:{...t.columnVisibility},columnOrder:n,columnWidths:{...t.columnWidths},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Ma(t,o){return{totalRows:t.length,totalColumns:o.length}}function Ra(t,o){let n=null;return function(...s){const d=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(d,o)}}function Ot(t,o,n,i){const s=n instanceof Error?n.message:n,d={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:Wa(t,o)};return process.env.NODE_ENV==="development"&&ar.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),d}function Wa(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Pa(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 Na(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 La(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 Fa(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 Oi(t,o){const n=[],i=[],s=new Set(o.map(d=>d.name));return t.forEach(d=>{s.has(d.column)?n.push(d):i.push(d.column)}),{validRules:n,invalidColumns:i}}function $i(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(d=>d.name)),i=[],s=[];return t.levels.forEach(d=>{n.has(d.column)?i.push(d):s.push(d.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...t,levels:i},invalidColumns:s}}function Va(t,o){const n=[],i=new Set(o.map(d=>d.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const d=s.filters.filter(c=>{const l=i.has(c.column);return l||n.push(`Filter for column "${c.column}" ignored (column not found)`),l});s.filters=d.length>0?d:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:d,invalidColumns:c}=Oi(s.sortStack,o);c.length>0&&n.push(`Sort rules for columns ignored: ${c.join(", ")}`),s.sortStack=d.length>0?d:void 0}if(s.grouping){const{validGrouping:d,invalidColumns:c}=$i(s.grouping,o);c.length>0&&n.push(`Grouping for columns ignored: ${c.join(", ")}`),s.grouping=d}if(s.columnVisibility){const d={};Object.entries(s.columnVisibility).forEach(([c,l])=>{i.has(c)?d[c]=l:n.push(`Column visibility for "${c}" ignored (column not found)`)}),s.columnVisibility=Object.keys(d).length>0?d:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const d=s.columnOrder.filter(c=>{const l=i.has(c);return l||n.push(`Column "${c}" in order ignored (column not found)`),l});s.columnOrder=d.length>0?d:void 0}if(s.columnWidths){const d={};Object.entries(s.columnWidths).forEach(([c,l])=>{i.has(c)?d[c]=l:n.push(`Column width for "${c}" ignored (column not found)`)}),s.columnWidths=Object.keys(d).length>0?d:void 0}return{sanitizedConfig:s,warnings:n}}function Ha(t,o){return Ot("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function En(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 Ei(i||[],s)}function Ua(t){return t==null}function Ya(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Ua(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 Ga(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Ya(n[i.column],i)))}function On(t){switch(t){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function co(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function qa({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:Ga(t,o),[t,o])}}function Ja(t,o,n,i){if(!n||n.trim()==="")return t;const s=n.toLowerCase().trim(),d=o.filter(c=>i.includes(c.name));return t.filter(c=>d.some(l=>{const u=c[l.name];return u==null?!1:String(u).toLowerCase().includes(s)}))}function Ka({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Ja(t,n,o,i),[t,o,n,i])}}function Xa({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:ra(t,n,o),[t,o,n])}}function Za({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:aa(t,n,o),[t,o,n]),s=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function Qa({schema:t,columnVisibility:o,columnOrder:n}){const i=p.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),s=p.useMemo(()=>Object.entries(o).filter(([l,u])=>!u).map(([l,u])=>l),[o]),d=p.useMemo(()=>n.map(l=>t.find(x=>x.name===l)||{name:l,type:"string"}),[n,t]),c=p.useMemo(()=>i.map(l=>t.find(x=>x.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:d,visibleColumnSchemas:c,hiddenCount:s.length}}function el({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(x=>x.id===o),[t,o]),s=p.useMemo(()=>i?da(n,i.snapshot):!1,[i,n]),d=p.useMemo(()=>t.find(x=>x.isDefault),[t]),c=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:s,defaultView:d,customViews:c,favoriteViews:l,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function tl({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,d]=p.useState(i),c=t.length,l=Math.ceil(c/n),u=p.useMemo(()=>{if(!o)return t;const y=(s-1)*n,D=y+n;return t.slice(y,D)},[t,o,s,n]),x=p.useCallback(y=>{const D=Math.max(1,Math.min(y,l));d(D)},[l]),h=p.useCallback(()=>{s<l&&d(s+1)},[s,l]),b=p.useCallback(()=>{s>1&&d(s-1)},[s]),m=p.useCallback(()=>{d(1)},[]);return{paginatedData:u,currentPage:s,totalPages:l,pageSize:n,totalRows:c,goToPage:x,nextPage:h,prevPage:b,resetPage:m,hasNextPage:s<l,hasPrevPage:s>1}}function rl(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:d,searchQuery:c,columnVisibility:l,columnOrder:u,columnWidths:x,views:h,activeViewId:b,pagination:m}=t,y=p.useMemo(()=>({filters:i,sortStack:s,grouping:d,columnVisibility:l,columnOrder:u,columnWidths:x}),[i,s,d,l,u,x]),D=el({views:h,activeViewId:b,currentState:y}),v=Qa({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:C}=qa({data:o,filters:i}),{sortedData:S}=Xa({data:C,sortStack:s,schema:n}),{groupedData:I,isGrouped:f}=Za({data:S,grouping:d,schema:n}),{searchedData:k}=Ka({data:I,searchQuery:c,schema:n,visibleColumns:v.visibleColumns}),j=tl({data:k,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?j.paginatedData:k,B=p.useMemo(()=>({totalRows:o.length,filteredRows:C.length,sortedRows:S.length,groupedRows:f?I.length:S.length,searchedRows:k.length,visibleRows:a.length,hiddenColumns:v.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:f}),[o.length,C.length,S.length,I.length,k.length,a.length,v.hiddenCount,i.length,s.length,f]);return{data:a,filteredData:C,sortedData:S,groupedData:I,searchedData:k,viewEngine:D,columnEngine:v,paginationEngine:j,metrics:B,isGrouped:f,isPaginated:(m==null?void 0:m.enabled)||!1}}let ol=0;function nl(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:ol++,writable:!1,enumerable:!1,configurable:!1})}const yt="user-demo-001";function il(t={}){var fn,gn,yn,bn,vn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:d,sharedReportId:c,config:l={}}=t,[u,x]=p.useState([]),h=cr(),[b,m]=p.useState(""),[y,D]=p.useState(!1),[v,C]=p.useState(!1),[S,I]=p.useState({message:"",severity:"info",open:!1}),f=(w,E="info")=>{I({message:w,severity:E,open:!0})},k=()=>I(w=>({...w,open:!1})),j=l.notifDurationMs??2e3,a=u.find(w=>w.id===b),[B,R]=p.useState("idle"),[q,K]=p.useState(!1),[ee,g]=p.useState(!1),[M,W]=p.useState(!1),[V,Z]=p.useState(!1),[xe,me]=p.useState(!1),[F,A]=p.useState(!1),[H,se]=p.useState(void 0),[G,re]=p.useState(null),[ae,ne]=p.useState(null),[P,ie]=p.useState(!1),[de,le]=p.useState(!1),[fe,J]=p.useState(null),[Re,He]=p.useState(!1),[St,Mt]=p.useState(!1),[pr,Gt]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[pt,Rt]=p.useState(""),[ze,Xe]=p.useState(new Set),[jt,ot]=p.useState(null),[Le,nt]=p.useState(1),[Ct,Ze]=p.useState(15),[it,We]=p.useState(!1),[$r,xr]=p.useState(!1),[mr,qt]=p.useState(!1),[st,Wt]=p.useState(null),[hr,wt]=p.useState(!1),[fr,Ar]=p.useState(null),[Ue,Jt]=p.useState(null),gr=p.useRef(null),Ie=p.useMemo(()=>a?Sa(a.permissions,yt):"owner",[a]),Kt=ja(Ie),_r=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:Ma(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),at=p.useCallback(()=>{a&&(gr.current=Na(a))},[a]),L=p.useCallback((w,E)=>{x(_=>_.map($=>$.id===w?{...$,...E}:$))},[]),lt=p.useCallback(w=>{if(!a)return;Jt(w);const E=En(a.id,yt,w,a.auditHistory||[]);L(a.id,{auditHistory:E}),f(w.message,"error"),w.recoverable&&gr.current&&setTimeout(()=>{La(a,gr.current,L),f("Previous state restored","success")},100)},[a,L]),ye=p.useCallback((w,E,_,$)=>{if(!a)return;const Y=Di(a.id,yt,w,E,_,$),U=a.auditHistory||[],oe=Ei(U,Y);setTimeout(()=>{L(a.id,{auditHistory:oe})},0)},[a,L]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const w=Ho(a.schema);(()=>{try{const E=localStorage.getItem("urm_dev_config");return E?JSON.parse(E):null}catch{return null}})(),L(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,L]),p.useEffect(()=>{if(i&&n&&!v&&u.length===0){const w=fo(i),E={id:`auto-report-${Date.now()}`,name:d||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:w,schema:Yr(w),permissions:{owner:yt,editors:[],viewers:[]}};x([E]),m(E.id),C(!0),R("confirmed")}},[i,n,v,u.length,o,d]),p.useEffect(()=>{if(!s||v)return;let w=!1,E=null;const _=async()=>{try{R("uploading");let $;if(s.type==="api"){const U=await fetch(s.url,{headers:s.headers||{}});if(!U.ok)throw new Error(`HTTP ${U.status}: ${U.statusText}`);$=await U.json()}else $=await s.fetch();if(w)return;if(!Array.isArray($))throw new Error("Data source must return an array of objects");const Y=Yr($);if(v)x(U=>U.map(oe=>oe.id===b?{...oe,uploadedData:$}:oe)),R("confirmed");else{const U={id:`auto-report-${Date.now()}`,name:d||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:fo($),schema:Yr(fo($)),permissions:{owner:yt,editors:[],viewers:[]}};x([U]),m(U.id),C(!0),R("confirmed")}}catch($){w||(R("error"),a&&L(a.id,{uploadError:($==null?void 0:$.message)||"Failed to load data from source"}))}};return _(),s.refreshInterval&&s.refreshInterval>0&&(E=setInterval(_,s.refreshInterval)),()=>{w=!0,E&&clearInterval(E)}},[s,d,o]);const Ye=(fn=a==null?void 0:a.views)==null?void 0:fn.find(w=>w.id===a.activeViewId),Pt=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(nl),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]),Mr=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(_=>{const $=a.uploadedData[_];$!==void 0&&w.add($)}),w},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),xt=rl({rawData:Pt,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:pt||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Ye==null?void 0:Ye.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Ye==null?void 0:Ye.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Ye==null?void 0:Ye.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:Ct,currentPage:Le}}),{data:Xt=[],searchedData:kt=[],groupedData:yr=[],metrics:br={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Rr=!1,paginationEngine:De}=xt||{},Q=((gn=xt.viewEngine)==null?void 0:gn.activeView)||Ye,ct=((yn=xt.viewEngine)==null?void 0:yn.isDirty)||!1;p.useEffect(()=>{if(!(!Q||!a)&&!a.columnOrder){const w=Q.snapshot.columnOrder,E=Xr(w,Q.snapshot.grouping);L(a.id,{columnOrder:E})}},[a==null?void 0:a.activeViewId]);const Te=p.useMemo(()=>!(a!=null&&a.schema)||!Q?null:ca(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]),Zt=p.useMemo(()=>!Q||!Te||!ct?[]:pa(Te,Q.snapshot),[Q,Te,ct]),be=p.useCallback((w,E,_)=>{const $={id:`report-${Date.now()}`,name:w,description:E,schemaLocked:!1,permissions:{owner:yt,editors:[],viewers:[]}};if(_&&Array.isArray(_)&&_.length>0){const Y=Yr(_),U=Ho(Y);$.uploadedData=_,$.schema=Y,$.schemaLocked=!0,$.views=[U],$.activeViewId=U.id,$.sortStack=U.snapshot.sortStack,$.filters=U.snapshot.filters,$.columnVisibility=U.snapshot.columnVisibility,$.columnOrder=U.snapshot.columnOrder,$.columnWidths=U.snapshot.columnWidths,$.grouping=U.snapshot.grouping}x(Y=>[...Y,$]),m($.id),D(!1),R("confirmed")},[]),Qe=p.useCallback(w=>{a&&(R("uploading"),setTimeout(()=>{const E=Yr(w);L(a.id,{uploadedData:w,schema:E,uploadError:void 0}),R("preview")},500))},[a,L]),Qt=p.useCallback(w=>{a&&(L(a.id,{uploadError:w}),R("idle"))},[a,L]),mt=p.useCallback(()=>{a&&(L(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),R("idle"))},[a,L]),Fe=p.useCallback(()=>{a&&(L(a.id,{schemaLocked:!0}),R("confirmed"))},[a,L]),vr=p.useCallback(w=>{if(!a)return;if(!ft("edit_sorting",Ie)){f(gt("edit_sorting"),"error");return}const E=a.sortStack??[],_=E.find($=>$.column===w);if(_){const $=oa(_.direction);if($===null){const Y=E.filter(U=>U.column!==w).map((U,oe)=>({...U,priority:oe+1}));L(a.id,{sortStack:Y.length>0?Y:void 0})}else{const Y=$,U=E.map(oe=>oe.column===w?{...oe,direction:Y}:oe);L(a.id,{sortStack:U})}}else{if(E.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 $={column:w,direction:"asc",priority:E.length+1};L(a.id,{sortStack:[...E,$]})}},[a,Ie,L]),Tt=p.useCallback(w=>{if(a)if(a.schema){const{validRules:E,invalidColumns:_}=Oi(w,a.schema);_.length>0&&f(`Removed invalid sort columns: ${_.join(", ")}`),at();try{L(a.id,{sortStack:E.length>0?E:void 0})}catch($){const Y=Ot("processing","sorting",$);lt(Y)}}else L(a.id,{sortStack:w.length>0?w:void 0})},[a,L,at,lt]),dt=p.useCallback(w=>{if(!a)return;const E=a.sortStack??[],_=E.find($=>$.column===w);if(!(_&&_.direction==="asc"))if(_){const $=E.map(Y=>Y.column===w?{...Y,direction:"asc"}:Y);L(a.id,{sortStack:$})}else{if(E.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 $={column:w,direction:"asc",priority:E.length+1};L(a.id,{sortStack:[...E,$]})}},[a,L]),It=p.useCallback(w=>{if(!a)return;const E=a.sortStack??[],_=E.find($=>$.column===w);if(!(_&&_.direction==="desc"))if(_){const $=E.map(Y=>Y.column===w?{...Y,direction:"desc"}:Y);L(a.id,{sortStack:$})}else{if(E.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 $={column:w,direction:"desc",priority:E.length+1};L(a.id,{sortStack:[...E,$]})}},[a,L]),Wr=p.useCallback(w=>{var _;if(!a)return;if(!ft("edit_filters",Ie)){f(gt("edit_filters"),"error");return}const E=(_=a.schema)==null?void 0:_.find($=>$.name===w.column);if(E&&w.value!==void 0){const $=Fa(E.type,w.operator,w.value);if(!$.isValid){f($.errorMessage||"Invalid filter value","error");return}}at();try{const $=a.filters??[];ye("filters","filter_added",$,[...$,w]),L(a.id,{filters:[...$,w]})}catch($){const Y=Ot("processing","filters",$);lt(Y)}},[a,Ie,L,at,lt,ye]),er=p.useCallback((w,E)=>{if(!a)return;if(!ft("edit_filters",Ie)){f(gt("edit_filters"),"error");return}const _=a.filters??[],$=[..._];ye("filters","filter_updated",_[w],E),$[w]=E,L(a.id,{filters:$})},[a,Ie,L,ye]),tr=p.useCallback(w=>{if(!a)return;if(!ft("edit_filters",Ie)){f(gt("edit_filters"),"error");return}const E=a.filters??[],_=E.filter(($,Y)=>Y!==w);ye("filters","filter_removed",E[w],null),L(a.id,{filters:_.length>0?_:void 0})},[a,Ie,L,ye]),Nt=p.useCallback(()=>{if(!a)return;if(!ft("edit_filters",Ie)){f(gt("edit_filters"),"error");return}const w=a.filters??[];ye("filters","filter_cleared",w,null),L(a.id,{filters:void 0})},[a,Ie,L,ye]),Sr=p.useCallback(w=>{if(!a)return;if(!ft("edit_filters",Ie)){f(gt("edit_filters"),"error");return}const E=a.filters??[];ye("filters","filter_cleared",E,w),L(a.id,{filters:w.length>0?w:void 0})},[a,Ie,L,ye]),Ne=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 _=E.snapshot.columnOrder,$=Xr(_,E.snapshot.grouping);L(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:$,columnWidths:{...E.snapshot.columnWidths},grouping:E.snapshot.grouping,activeViewId:w}),Xe(new Set),W(!1)},[a,L]),ht=p.useCallback((w,E,_)=>{var nr;if(!(a!=null&&a.schema)||!Te)return;const $=a.views??[],Y=$.filter(Ur=>!Ur.isDeleted).length,U=((nr=h.views)==null?void 0:nr.maxViews)??10;if(Y>=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:w,description:E||void 0,isDefault:_,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:yt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...Te}},ge=_?$.map(Ur=>({...Ur,isDefault:!1})):$;L(a.id,{views:[...ge,oe],activeViewId:oe.id}),f(`"${w}" view created`,"success")},[a,Te,L]),zt=p.useCallback(()=>{var E;if(!Q||!Te||Q.isDefault||!a)return;const w=(E=a.views)==null?void 0:E.map(_=>_.id===Q.id?{..._,snapshot:{...Te}}:_);L(a.id,{views:w}),f(`"${Q.name}" view updated`,"success")},[Q,Te,a,L]),Lt=p.useCallback(w=>{var $;if(!Q||!Te||!a)return;const E=w??Te.columnWidths,_=($=a.views)==null?void 0:$.map(Y=>Y.id===Q.id?{...Y,snapshot:{...Y.snapshot,columnVisibility:Te.columnVisibility,columnOrder:Te.columnOrder,columnWidths:E},updatedAt:Date.now()}:Y);L(a.id,{views:_,columnWidths:E}),f(`Column configuration saved to "${Q.name}"`,"success")},[Q,Te,a,L]),Pr=p.useCallback(w=>{var U,oe;if(!Te||!a||!Q)return;const E=w??Te.columnWidths,_={...Q,snapshot:{...Q.snapshot,columnVisibility:Te.columnVisibility,columnOrder:Te.columnOrder,columnWidths:E},updatedAt:Date.now()},$=(U=a.views)==null?void 0:U.map(ge=>ge.id===Q.id?_:{...ge,snapshot:{...ge.snapshot,columnVisibility:Te.columnVisibility,columnOrder:Te.columnOrder,columnWidths:E},updatedAt:Date.now()});L(a.id,{views:$,columnWidths:E});const Y=(((oe=a.views)==null?void 0:oe.length)||0)-1;f(`Column configuration saved to current view and ${Y} other view${Y===1?"":"s"}`,"success")},[Te,a,Q,L]),Nr=p.useCallback(()=>{Z(!0)},[]),Ft=p.useCallback(()=>{if(!Q||!a)return;const w=Q.snapshot.columnOrder,E=Xr(w,Q.snapshot.grouping);L(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}),f("Changes reverted to last saved state","success")},[Q,a,L]),Lr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map($=>({...$,isDefault:$.id===w}));L(a.id,{views:E});const _=a.views.find($=>$.id===w);_&&f(`"${_.name}" set as default view`,"success")},[a,L]),Fr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map($=>$.id===w?{...$,isFavorite:!$.isFavorite,updatedAt:Date.now()}:$);L(a.id,{views:E});const _=a.views.find($=>$.id===w);_&&!_.isFavorite?f(`"${_.name}" added to favorites`,"success"):_&&f(`"${_.name}" removed from favorites`,"info")},[a,L]),rr=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),_=a.activeViewId===w,$=E.find(U=>U.isDefault&&!U.isDeleted);L(a.id,{views:E,activeViewId:_&&$?$.id:a.activeViewId,filters:_&&$?$.snapshot.filters.length>0?$.snapshot.filters:void 0:a.filters,sortStack:_&&$?$.snapshot.sortStack.length>0?$.snapshot.sortStack:void 0:a.sortStack});const Y=a.views.find(U=>U.id===w);Y&&f(`"${Y.name}" moved to Recently Deleted`,"info")},[a,L]),jr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.map($=>$.id===w?{...$,isDeleted:!1,updatedAt:Date.now()}:$);L(a.id,{views:E});const _=a.views.find($=>$.id===w);_&&f(`"${_.name}" restored`,"success")},[a,L]),Cr=p.useCallback(w=>{if(!(a!=null&&a.views))return;const E=a.views.find(ge=>ge.id===w),_=a.views.filter(ge=>!ge.isDeleted||ge.id===w);if((E==null?void 0:E.isDefault)&&_.filter(ge=>ge.isDefault).length===1){f("Cannot delete the last default view","error");return}const Y=a.views.filter(ge=>ge.id!==w),U=a.activeViewId===w,oe=Y.find(ge=>ge.isDefault&&!ge.isDeleted);L(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&&f(`"${E.name}" permanently deleted`,"success")},[a,L]),wr=p.useCallback(w=>{re(w),me(!0),W(!1)},[]),or=p.useCallback((w,E)=>{if(!G||!(a!=null&&a.views))return;const _=a.views.map($=>$.id===G?{...$,name:w,description:E||void 0}:$);L(a.id,{views:_}),re(null)},[G,a,L]),kr=p.useCallback(w=>{ne(w),A(!0),W(!1)},[]),ue=p.useCallback(()=>{if(!ae||!(a!=null&&a.views))return;const w=a.views.filter($=>$.id!==ae),E=a.activeViewId===ae,_=w.find($=>$.isDefault);L(a.id,{views:w,activeViewId:E&&_?_.id:a.activeViewId,filters:E&&_?_.snapshot.filters.length>0?_.snapshot.filters:void 0:a.filters,sortStack:E&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:a.sortStack}),ne(null),A(!1)},[ae,a,L]),ce=p.useCallback(w=>{var Y;if(!(a!=null&&a.views))return;if(!(((Y=h.views)==null?void 0:Y.isAdmin)??!1)){f("Only administrators can promote views to Global.","error");return}const _=a.views.find(U=>U.id===w);if(!_)return;if(_.scope==="global"){f(`"${_.name}" is already a Global View.`,"info");return}const $=a.views.map(U=>U.id===w?{...U,scope:"global",isDefault:!0,updatedAt:Date.now()}:U.scope==="global"&&U.isDefault?{...U,isDefault:!1}:U);L(a.id,{views:$}),f(`"${_.name}" promoted to Global View and set as default.`,"success")},[a,h,L]);p.useEffect(()=>{De!=null&&De.resetPage?De.resetPage():nt(1)},[a==null?void 0:a.filters,pt,a==null?void 0:a.activeViewId]),p.useEffect(()=>{De&&De.currentPage!==Le&&nt(De.currentPage)},[De==null?void 0:De.currentPage]);const Ee=p.useCallback(w=>{De!=null&&De.goToPage&&De.goToPage(w),nt(w)},[De]),ut=p.useCallback(w=>{const E=(Le-1)*Ct,_=Math.floor(E/w)+1;Ze(w),nt(_)},[Le,Ct]),et=p.useCallback((w,E)=>{if(!a)return;if(!ft("edit_columns",Ie)){f(gt("edit_columns"),"error");return}const $={...a.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{},[w]:E};L(a.id,{columnVisibility:$})},[a,Q,Ie,L]),Bt=p.useCallback(w=>{if(a){if(!ft("edit_columns",Ie)){f(gt("edit_columns"),"error");return}L(a.id,{columnOrder:w})}},[a,Ie,L]),Vr=p.useCallback((w,E)=>{if(!a)return;if(!ft("edit_columns",Ie)){f(gt("edit_columns"),"error");return}const $={...a.columnWidths||(Q==null?void 0:Q.snapshot.columnWidths)||{},[w]:E};L(a.id,{columnWidths:$})},[a,Q,Ie,L]),Vt=p.useCallback(w=>{if(!a)return;const _=(a.filters??[]).filter($=>$.column!==w);L(a.id,{filters:_.length>0?_:void 0})},[a,L]),so=p.useCallback(()=>{if(!Q||!(a!=null&&a.schema))return;const w={},E=[],_={};a.schema.forEach($=>{w[$.name]=!0,E.push($.name),_[$.name]=170}),L(a.id,{columnVisibility:w,columnOrder:E,columnWidths:_,filters:void 0,sortStack:void 0}),f("Reset to default layout - all filters and sorts cleared","success")},[Q,a,L]),O=p.useCallback(Ra(w=>{Rt(w)},300),[]),X=p.useCallback(w=>{O(w)},[O]),he=p.useCallback(w=>{if(!w.trim()||!a)return;const E=a.searchHistory||[],_=fa(E,w);L(a.id,{searchHistory:_})},[a,L]),Ve=p.useCallback(w=>{if(!a)return;const E=a.searchHistory||[],_=ga(E,w);L(a.id,{searchHistory:_})},[a,L]),pe=p.useCallback(w=>{if(!a)return;const E=a.searchHistory||[],_=ya(E,w);L(a.id,{searchHistory:_})},[a,L]),Dt=p.useCallback(w=>{const E=w==null?void 0:w.__urm_row_id__;Xe(_=>{const $=new Set(_);if(E!==void 0){const Y=Array.from($).find(U=>(U==null?void 0:U.__urm_row_id__)===E);Y!==void 0?$.delete(Y):$.add(w)}else{const Y=JSON.stringify(w),U=Array.from($).find(oe=>JSON.stringify(oe)===Y);U!==void 0?$.delete(U):$.add(w)}return $})},[]),Vo=p.useCallback((w,E)=>{Xe(_=>{const $=new Set(_);for(const Y of E)w?$.add(Y):$.delete(Y);return $})},[]),cs=p.useCallback((w,E,_)=>{Xe($=>{const Y=new Set($),U=Math.min(w,E),oe=Math.max(w,E);for(let ge=U;ge<=oe;ge++)_[ge]!==void 0&&Y.add(_[ge]);return Y})},[]),ds=p.useCallback(()=>{Xe(new Set),ot(null)},[]),us=p.useCallback(w=>{const E=w==null?void 0:w.__urm_row_id__;Xe(_=>{const $=new Set(_);if(E!==void 0){const Y=Array.from($).find(U=>(U==null?void 0:U.__urm_row_id__)===E);Y!==void 0&&$.delete(Y)}else $.delete(w);return $})},[]),ps=p.useCallback(w=>{if(!(a!=null&&a.uploadedData))return;const E=a.uploadedData.indexOf(w);if(E===-1)return;const _=a.favoriteRowIndices||[],Y=_.includes(E)?_.filter(U=>U!==E):[..._,E];L(a.id,{favoriteRowIndices:Y})},[a,L]),xs=p.useCallback((w,E)=>{if(!(a!=null&&a.uploadedData))return;const _=a.favoriteRowIndices||[],$=w.map(U=>a.uploadedData.indexOf(U)).filter(U=>U!==-1),Y=E?[..._,...$.filter(U=>!_.includes(U))]:_.filter(U=>!$.includes(U));L(a.id,{favoriteRowIndices:Y})},[a,L]),ms=p.useCallback(()=>{if(!a)return;const w=a.favoriteRowIndices||[],E=!a.showFavoritesOnly;if(E&&w.length===0){f("No rows marked as favorite","warning");return}if(L(a.id,{showFavoritesOnly:E}),E){if(ot(new Set(ze)),ze.size>0){const _=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)),$=new Set(Array.from(ze).filter(Y=>(Y==null?void 0:Y.__urm_row_id__)!==void 0&&_.has(Y.__urm_row_id__)));Xe($)}f(`Showing ${w.length} favorite row${w.length===1?"":"s"}`,"info")}else{if(jt!==null){const _=new Set(Array.from(ze).map(oe=>oe==null?void 0:oe.__urm_row_id__).filter(Boolean)),$=new Set(Array.from(jt).map(oe=>oe==null?void 0:oe.__urm_row_id__).filter(Boolean)),Y=new Set(w.map(oe=>{var ge,nr;return(nr=(ge=a.uploadedData)==null?void 0:ge[oe])==null?void 0:nr.__urm_row_id__}).filter(oe=>oe!==void 0)),U=new Set;Array.from(jt).forEach(oe=>{const ge=oe==null?void 0:oe.__urm_row_id__;if(ge===void 0)return;const nr=Y.has(ge),Ur=_.has(ge);nr&&!Ur||U.add(oe)}),Array.from(ze).forEach(oe=>{const ge=oe==null?void 0:oe.__urm_row_id__;ge!==void 0&&($.has(ge)||U.add(oe))}),Xe(U),ot(null)}f("Showing all data","info")}},[a,L,ze,jt]),hs=p.useCallback(w=>{if(a){if(!ft("edit_columns",Ie)){f(gt("edit_columns"),"error");return}if(w&&a.schema){const{validGrouping:E,invalidColumns:_}=$i(w,a.schema);_.length>0&&f(`Removed invalid grouping columns: ${_.join(", ")}`,"warning"),at();try{const $=a.grouping;E===null?ye("grouping","group_cleared",$,null):$?ye("grouping","group_reordered",$,E):ye("grouping","group_level_added",null,E);const Y=(Q==null?void 0:Q.snapshot.columnOrder)||a.columnOrder||[],U=Xr(Y,E);L(a.id,{grouping:E,columnOrder:U}),JSON.stringify(U)!==JSON.stringify(a.columnOrder)&&ye("columns","column_reordered",a.columnOrder,U),Mt(!1)}catch($){const Y=Ot("processing","grouping",$);lt(Y)}}else{const E=a.grouping;ye("grouping","group_cleared",E,null);const _=(Q==null?void 0:Q.snapshot.columnOrder)||a.columnOrder||[];L(a.id,{grouping:w,columnOrder:[..._]}),JSON.stringify(_)!==JSON.stringify(a.columnOrder)&&ye("columns","column_reordered",a.columnOrder,_),Mt(!1)}}},[a,Q,Ie,L,at,lt,ye]),fs=p.useCallback(w=>{if(!a)return;const E=a.grouping;if(!E)return;const _=la(E,w);L(a.id,{grouping:_})},[a,L]),gs=p.useCallback(()=>{wt(!0)},[]),Hr=p.useCallback(w=>{a!=null&&a.schema&&(ie(!0),setTimeout(()=>{try{let E;w.scope==="visible"?E=kt:E=a.uploadedData||[];let _;w.columnScope==="all"?(_={},(a.schema??[]).forEach(ge=>{_[ge.name]=!0})):_=a.columnVisibility||(Q==null?void 0:Q.snapshot.columnVisibility)||{};const $=a.columnOrder||(Q==null?void 0:Q.snapshot.columnOrder),Y=vo(E,a.schema,a.filters??[],a.sortStack??[],Q,_,$),U=a.name;let oe;switch(w.format){case"csv":So(Y,U,w),oe="export_csv";break;case"excel":jo(Y,U,w),oe="export_excel";break;case"json":Co(Y,U,w),oe="export_json";break}ye("export",oe,null,{format:w.format,scope:w.scope,columnScope:w.columnScope,rowCount:E.length,viewName:(Q==null?void 0:Q.name)||"Default View"}),f(`Export completed successfully (${w.format.toUpperCase()})`,"success")}catch(E){const _=Ha(E,{onRetry:()=>Hr(w)});f(`Export failed: ${_.message}. Click Export to retry.`,"error");const $=En(a.id,yt,_,a.auditHistory||[]);L(a.id,{auditHistory:$}),ar.error("urm:report-engine","Export failed",E)}finally{ie(!1)}},500))},[a,Q,kt,L,ye]),ys=p.useCallback(w=>{if(a!=null&&a.schema){if(ct&&Q&&!Q.isDefault){J(w.format),le(!0),wt(!1);return}Hr(w),wt(!1)}},[a,Q,ct,Hr]),ao=p.useCallback(w=>{Hr({format:w,scope:"visible",columnScope:"visible"})},[Hr]),bs=p.useCallback(()=>{fe&&ao(fe),le(!1),J(null)},[fe,ao]),vs=p.useCallback(()=>{zt(),fe&&ao(fe),le(!1),J(null)},[zt,fe,ao]),Ss=p.useCallback(()=>{le(!1),J(null)},[]),js=p.useCallback(w=>{!(a!=null&&a.schema)||ze.size===0||(ie(!0),setTimeout(()=>{try{const E=Array.from(ze),_=vo(E,a.schema,a.filters??[],a.sortStack??[],Q),$=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(w){case"csv":So(_,$);break;case"excel":jo(_,$);break;case"json":Co(_,$);break}f(`Exported ${E.length} selected rows`,"info")}catch(E){f("Export failed. Please try again.","error"),ar.error("urm:report-engine","Bulk export failed",E)}finally{ie(!1)}},500))},[a,Q,ze,yr]),Cs=p.useCallback((w,E)=>{if(a)try{const _=Da(a),$=Ea(w,E,yt,_),Y=Oa(a.presets,$);L(a.id,{presets:Y}),ye("presets","preset_created",null,{presetId:$.id,name:$.name}),xr(!1),f(`Preset "${w}" saved successfully`,"success")}catch(_){f(_ instanceof Error?_.message:"Failed to create preset","error")}},[a,L,ye]),ws=p.useCallback(()=>{Wt(null),f("Exited preset view","info")},[]),ks=p.useCallback(()=>{qt(!0)},[]),Ts=p.useCallback((w,E)=>{if(!a)return;const _=$a(a.presets,w);L(a.id,{presets:_}),ye("presets","preset_deleted",{presetId:w,name:E},null),st===w&&Wt(null),f(`Preset "${E}" deleted`,"success")},[a,st,L,ye]);p.useEffect(()=>{if(!c||u.length===0)return;const w=u.find(E=>E.id===c);w&&w.id!==b&&m(w.id)},[c,u,b]),p.useEffect(()=>{if(!a)return;const w=Aa();if(w&&a.presets&&a.schemaLocked&&a.schema){const E=Dn(a.presets,w);if(E){const{sanitizedConfig:_,warnings:$}=Va(E.config,a.schema);$.length>0&&$.forEach(U=>f(U,"warning"));const Y=_a(_);L(a.id,Y),Wt(w),ye("presets","preset_applied",null,{presetId:E.id,name:E.name}),f(`Loaded preset: ${E.name}`,"info")}else f("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const Is=st?Dn(a==null?void 0:a.presets,st):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&xa(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=ma(a.id);if(w&&w.views.length>0){const E=w.views.find(_=>_.id===w.activeViewId);if(E)L(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 _=w.views.find($=>$.isDefault)||Ho(a.schema);L(a.id,{views:w.views,activeViewId:_.id,filters:_.snapshot.filters.length>0?_.snapshot.filters:void 0,sortStack:_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const zs=p.useCallback(w=>{var $;const E=(a==null?void 0:a.filters)??[],_=(($=h.filter)==null?void 0:$.maxConditions)??3;if(E.length>=_){f(`Filter limit reached — maximum ${_} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}se(w),K(!0)},[a,h,f]),Bs=p.useCallback(()=>{K(!1),se(void 0)},[]),Ds=(bn=a==null?void 0:a.views)==null?void 0:bn.find(w=>w.id===G),Es=(vn=a==null?void 0:a.views)==null?void 0:vn.find(w=>w.id===ae);return{reports:u,activeReport:a,activeReportId:b,setActiveReportId:m,isModalOpen:y,setIsModalOpen:D,createReport:be,updateReport:L,uploadState:B,handleFileUpload:Qe,handleUploadError:Qt,handleRetry:mt,handleConfirm:Fe,paginatedData:Xt,processedData:kt,displayData:yr,tableMetrics:br,isGrouped:Rr,tableEngine:xt,activeView:Q,isDirty:ct,currentTableState:Te,viewChanges:Zt,filters:a==null?void 0:a.filters,showFilterPanel:q,setShowFilterPanel:K,filterFocusColumn:H,handleAddFilter:Wr,handleUpdateFilter:er,handleRemoveFilter:tr,handleClearAllFilters:Nt,handleReplaceFilters:Sr,handleOpenFilterForColumn:zs,handleCloseFilterPanel:Bs,handleClearFiltersForColumn:Vt,sortStack:a==null?void 0:a.sortStack,showSortPanel:ee,setShowSortPanel:g,handleSort:vr,handleUpdateSortStack:Tt,handleSortAscending:dt,handleSortDescending:It,views:a==null?void 0:a.views,showManageViews:M,setShowManageViews:W,showCreateViewModal:V,setShowCreateViewModal:Z,showEditViewModal:xe,setShowEditViewModal:me,showDeleteConfirmation:F,setShowDeleteConfirmation:A,editingView:Ds,deletingView:Es,editingViewId:G,deletingViewId:ae,handleSelectView:Ne,handleCreateView:ht,handleUpdateCurrentView:zt,handleSaveColumnConfigToCurrentView:Lt,handleSaveColumnConfigToAllViews:Pr,handleSaveAsNewView:Nr,handleRevertChanges:Ft,handleToggleDefault:Lr,handleToggleFavorite:Fr,handleSoftDelete:rr,handleRestoreView:jr,handlePermanentDelete:Cr,handleEditView:wr,handleSaveEditView:or,handleDeleteView:kr,handleConfirmDelete:ue,handlePromoteToGlobal:ce,showManageColumns:Re,setShowManageColumns:He,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:et,handleUpdateColumnOrder:Bt,handleUpdateColumnWidth:Vr,handleResetColumnLayout:so,showGroupPanel:St,setShowGroupPanel:Mt,grouping:a==null?void 0:a.grouping,groupingState:pr,handleGroup:hs,handleToggleGroupCollapse:fs,searchQuery:pt,searchHistory:ba((a==null?void 0:a.searchHistory)||[]),handleSearchChange:X,handleAddToSearchHistory:he,handleToggleSearchFavourite:Ve,handleDeleteSearchHistory:pe,selectedRowIds:ze,handleToggleRowSelection:Dt,handleToggleAllRows:Vo,handleRangeSelection:cs,handleClearSelection:ds,handleUpdateSelectionAfterDelete:us,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:Mr,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:ps,handleBulkSetFavorites:xs,handleToggleFavoritesFilter:ms,currentPage:Le,pageSize:Ct,paginationEngine:De,handlePageChange:Ee,handlePageSizeChange:ut,isExporting:P,showExportModal:hr,setShowExportModal:wt,showDirtyExportWarning:de,handleExport:gs,handleExportWithConfig:ys,handleExportSelected:js,handleExportAnyway:bs,handleSaveAndExport:vs,handleCancelExport:Ss,showAuditHistory:it,setShowAuditHistory:We,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:$r,setShowCreatePreset:xr,showManagePresets:mr,setShowManagePresets:qt,activePreset:Is,activePresetId:st,handleOpenManagePresets:ks,handleCreatePreset:Cs,handleClearActivePreset:ws,handleDeletePresetById:Ts,userRole:Ie,isViewerRole:Kt,currentUserId:yt,featureLimitWarning:fr,setFeatureLimitWarning:Ar,datasetMeta:_r,reportError:Ue,setReportError:Jt,handleError:lt,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?ea(a.schema):!1,snack:S,handleSnackClose:k,showSnack:f,snackDurationMs:j}}const Ai=p.createContext(void 0);function cn(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:d,mode:c="builder",autoLoad:l=!0,config:u,devConfig:x,showDevPanel:h=!1,sharedReportId:b}=t,y=il({mode:c,autoLoad:l,initialData:i||n,dataSource:d,reportName:s,sharedReportId:b,config:u}),[D,v]=p.useState(()=>Ms()),C=(()=>{const k=Ws(D,x,!!x);return{...k,display:{...k.display,showDevPanel:h||k.display.showDevPanel}}})(),S=p.useCallback(f=>{v(f),Rs(f)},[]),I={...y,activeDevConfig:C,handleDevConfigChange:S};return e.jsx(Si.Provider,{value:C,children:e.jsx(Ai.Provider,{value:I,children:o})})}function zo(){const t=p.useContext(Ai);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function sl({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const s=o.find(d=>d.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(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 lr(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 al="$$material";function ll(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var uo={exports:{}},po={exports:{}},ve={};/** @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 cl(){if($n)return ve;$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,d=t?Symbol.for("react.profiler"):60114,c=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,D=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,C=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,I=t?Symbol.for("react.scope"):60119;function f(j){if(typeof j=="object"&&j!==null){var a=j.$$typeof;switch(a){case o:switch(j=j.type,j){case u:case x:case i:case d:case s:case b:return j;default:switch(j=j&&j.$$typeof,j){case l:case h:case D:case y:case c:return j;default:return a}}case n:return a}}}function k(j){return f(j)===x}return ve.AsyncMode=u,ve.ConcurrentMode=x,ve.ContextConsumer=l,ve.ContextProvider=c,ve.Element=o,ve.ForwardRef=h,ve.Fragment=i,ve.Lazy=D,ve.Memo=y,ve.Portal=n,ve.Profiler=d,ve.StrictMode=s,ve.Suspense=b,ve.isAsyncMode=function(j){return k(j)||f(j)===u},ve.isConcurrentMode=k,ve.isContextConsumer=function(j){return f(j)===l},ve.isContextProvider=function(j){return f(j)===c},ve.isElement=function(j){return typeof j=="object"&&j!==null&&j.$$typeof===o},ve.isForwardRef=function(j){return f(j)===h},ve.isFragment=function(j){return f(j)===i},ve.isLazy=function(j){return f(j)===D},ve.isMemo=function(j){return f(j)===y},ve.isPortal=function(j){return f(j)===n},ve.isProfiler=function(j){return f(j)===d},ve.isStrictMode=function(j){return f(j)===s},ve.isSuspense=function(j){return f(j)===b},ve.isValidElementType=function(j){return typeof j=="string"||typeof j=="function"||j===i||j===x||j===d||j===s||j===b||j===m||typeof j=="object"&&j!==null&&(j.$$typeof===D||j.$$typeof===y||j.$$typeof===c||j.$$typeof===l||j.$$typeof===h||j.$$typeof===C||j.$$typeof===S||j.$$typeof===I||j.$$typeof===v)},ve.typeOf=f,ve}var Se={};/** @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 An;function dl(){return An||(An=1,process.env.NODE_ENV!=="production"&&(function(){var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,s=t?Symbol.for("react.strict_mode"):60108,d=t?Symbol.for("react.profiler"):60114,c=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,D=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,C=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,I=t?Symbol.for("react.scope"):60119;function f(J){return typeof J=="string"||typeof J=="function"||J===i||J===x||J===d||J===s||J===b||J===m||typeof J=="object"&&J!==null&&(J.$$typeof===D||J.$$typeof===y||J.$$typeof===c||J.$$typeof===l||J.$$typeof===h||J.$$typeof===C||J.$$typeof===S||J.$$typeof===I||J.$$typeof===v)}function k(J){if(typeof J=="object"&&J!==null){var Re=J.$$typeof;switch(Re){case o:var He=J.type;switch(He){case u:case x:case i:case d:case s:case b:return He;default:var St=He&&He.$$typeof;switch(St){case l:case h:case D:case y:case c:return St;default:return Re}}case n:return Re}}}var j=u,a=x,B=l,R=c,q=o,K=h,ee=i,g=D,M=y,W=n,V=d,Z=s,xe=b,me=!1;function F(J){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(J)||k(J)===u}function A(J){return k(J)===x}function H(J){return k(J)===l}function se(J){return k(J)===c}function G(J){return typeof J=="object"&&J!==null&&J.$$typeof===o}function re(J){return k(J)===h}function ae(J){return k(J)===i}function ne(J){return k(J)===D}function P(J){return k(J)===y}function ie(J){return k(J)===n}function de(J){return k(J)===d}function le(J){return k(J)===s}function fe(J){return k(J)===b}Se.AsyncMode=j,Se.ConcurrentMode=a,Se.ContextConsumer=B,Se.ContextProvider=R,Se.Element=q,Se.ForwardRef=K,Se.Fragment=ee,Se.Lazy=g,Se.Memo=M,Se.Portal=W,Se.Profiler=V,Se.StrictMode=Z,Se.Suspense=xe,Se.isAsyncMode=F,Se.isConcurrentMode=A,Se.isContextConsumer=H,Se.isContextProvider=se,Se.isElement=G,Se.isForwardRef=re,Se.isFragment=ae,Se.isLazy=ne,Se.isMemo=P,Se.isPortal=ie,Se.isProfiler=de,Se.isStrictMode=le,Se.isSuspense=fe,Se.isValidElementType=f,Se.typeOf=k})()),Se}var _n;function _i(){return _n||(_n=1,process.env.NODE_ENV==="production"?po.exports=cl():po.exports=dl()),po.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 Yo,Mn;function ul(){if(Mn)return Yo;Mn=1;var t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(d){if(d==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(d)}function s(){try{if(!Object.assign)return!1;var d=new String("abc");if(d[5]="de",Object.getOwnPropertyNames(d)[0]==="5")return!1;for(var c={},l=0;l<10;l++)c["_"+String.fromCharCode(l)]=l;var u=Object.getOwnPropertyNames(c).map(function(h){return c[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 Yo=s()?Object.assign:function(d,c){for(var l,u=i(d),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},Yo}var Go,Rn;function dn(){if(Rn)return Go;Rn=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Go=t,Go}var qo,Wn;function Mi(){return Wn||(Wn=1,qo=Function.call.bind(Object.prototype.hasOwnProperty)),qo}var Jo,Pn;function pl(){if(Pn)return Jo;Pn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=dn(),n={},i=Mi();t=function(d){var c="Warning: "+d;typeof console<"u"&&console.error(c);try{throw new Error(c)}catch{}}}function s(d,c,l,u,x){if(process.env.NODE_ENV!=="production"){for(var h in d)if(i(d,h)){var b;try{if(typeof d[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 d[h]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw m.name="Invariant Violation",m}b=d[h](c,h,u,l,null,o)}catch(D){b=D}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 s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Jo=s,Jo}var Ko,Nn;function xl(){if(Nn)return Ko;Nn=1;var t=_i(),o=ul(),n=dn(),i=Mi(),s=pl(),d=function(){};process.env.NODE_ENV!=="production"&&(d=function(l){var u="Warning: "+l;typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}});function c(){return null}return Ko=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:k(),elementType:j(),instanceOf:a,node:K(),objectOf:R,oneOf:B,oneOfType:q,shape:g,exact:M};function D(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 C(A){if(process.env.NODE_ENV!=="production")var H={},se=0;function G(ae,ne,P,ie,de,le,fe){if(ie=ie||m,le=le||P,fe!==n){if(u){var J=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 J.name="Invariant Violation",J}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var Re=ie+":"+P;!H[Re]&&se<3&&(d("You are manually calling a React.PropTypes validation function for the `"+le+"` prop on `"+ie+"`. 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,se++)}}return ne[P]==null?ae?ne[P]===null?new v("The "+de+" `"+le+"` is marked as required "+("in `"+ie+"`, but its value is `null`.")):new v("The "+de+" `"+le+"` is marked as required in "+("`"+ie+"`, but its value is `undefined`.")):null:A(ne,P,ie,de,le)}var re=G.bind(null,!1);return re.isRequired=G.bind(null,!0),re}function S(A){function H(se,G,re,ae,ne,P){var ie=se[G],de=Z(ie);if(de!==A){var le=xe(ie);return new v("Invalid "+ae+" `"+ne+"` of type "+("`"+le+"` supplied to `"+re+"`, expected ")+("`"+A+"`."),{expectedType:A})}return null}return C(H)}function I(){return C(c)}function f(A){function H(se,G,re,ae,ne){if(typeof A!="function")return new v("Property `"+ne+"` of component `"+re+"` has invalid PropType notation inside arrayOf.");var P=se[G];if(!Array.isArray(P)){var ie=Z(P);return new v("Invalid "+ae+" `"+ne+"` of type "+("`"+ie+"` supplied to `"+re+"`, expected an array."))}for(var de=0;de<P.length;de++){var le=A(P,de,re,ae,ne+"["+de+"]",n);if(le instanceof Error)return le}return null}return C(H)}function k(){function A(H,se,G,re,ae){var ne=H[se];if(!l(ne)){var P=Z(ne);return new v("Invalid "+re+" `"+ae+"` of type "+("`"+P+"` supplied to `"+G+"`, expected a single ReactElement."))}return null}return C(A)}function j(){function A(H,se,G,re,ae){var ne=H[se];if(!t.isValidElementType(ne)){var P=Z(ne);return new v("Invalid "+re+" `"+ae+"` of type "+("`"+P+"` supplied to `"+G+"`, expected a single ReactElement type."))}return null}return C(A)}function a(A){function H(se,G,re,ae,ne){if(!(se[G]instanceof A)){var P=A.name||m,ie=F(se[G]);return new v("Invalid "+ae+" `"+ne+"` of type "+("`"+ie+"` supplied to `"+re+"`, expected ")+("instance of `"+P+"`."))}return null}return C(H)}function B(A){if(!Array.isArray(A))return process.env.NODE_ENV!=="production"&&(arguments.length>1?d("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])."):d("Invalid argument supplied to oneOf, expected an array.")),c;function H(se,G,re,ae,ne){for(var P=se[G],ie=0;ie<A.length;ie++)if(D(P,A[ie]))return null;var de=JSON.stringify(A,function(fe,J){var Re=xe(J);return Re==="symbol"?String(J):J});return new v("Invalid "+ae+" `"+ne+"` of value `"+String(P)+"` "+("supplied to `"+re+"`, expected one of "+de+"."))}return C(H)}function R(A){function H(se,G,re,ae,ne){if(typeof A!="function")return new v("Property `"+ne+"` of component `"+re+"` has invalid PropType notation inside objectOf.");var P=se[G],ie=Z(P);if(ie!=="object")return new v("Invalid "+ae+" `"+ne+"` of type "+("`"+ie+"` supplied to `"+re+"`, expected an object."));for(var de in P)if(i(P,de)){var le=A(P,de,re,ae,ne+"."+de,n);if(le instanceof Error)return le}return null}return C(H)}function q(A){if(!Array.isArray(A))return process.env.NODE_ENV!=="production"&&d("Invalid argument supplied to oneOfType, expected an instance of array."),c;for(var H=0;H<A.length;H++){var se=A[H];if(typeof se!="function")return d("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+me(se)+" at index "+H+"."),c}function G(re,ae,ne,P,ie){for(var de=[],le=0;le<A.length;le++){var fe=A[le],J=fe(re,ae,ne,P,ie,n);if(J==null)return null;J.data&&i(J.data,"expectedType")&&de.push(J.data.expectedType)}var Re=de.length>0?", expected one of type ["+de.join(", ")+"]":"";return new v("Invalid "+P+" `"+ie+"` supplied to "+("`"+ne+"`"+Re+"."))}return C(G)}function K(){function A(H,se,G,re,ae){return W(H[se])?null:new v("Invalid "+re+" `"+ae+"` supplied to "+("`"+G+"`, expected a ReactNode."))}return C(A)}function ee(A,H,se,G,re){return new v((A||"React class")+": "+H+" type `"+se+"."+G+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+re+"`.")}function g(A){function H(se,G,re,ae,ne){var P=se[G],ie=Z(P);if(ie!=="object")return new v("Invalid "+ae+" `"+ne+"` of type `"+ie+"` "+("supplied to `"+re+"`, expected `object`."));for(var de in A){var le=A[de];if(typeof le!="function")return ee(re,ae,ne,de,xe(le));var fe=le(P,de,re,ae,ne+"."+de,n);if(fe)return fe}return null}return C(H)}function M(A){function H(se,G,re,ae,ne){var P=se[G],ie=Z(P);if(ie!=="object")return new v("Invalid "+ae+" `"+ne+"` of type `"+ie+"` "+("supplied to `"+re+"`, expected `object`."));var de=o({},se[G],A);for(var le in de){var fe=A[le];if(i(A,le)&&typeof fe!="function")return ee(re,ae,ne,le,xe(fe));if(!fe)return new v("Invalid "+ae+" `"+ne+"` key `"+le+"` supplied to `"+re+"`.\nBad object: "+JSON.stringify(se[G],null," ")+`
22
+ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var J=fe(P,le,re,ae,ne+"."+le,n);if(J)return J}return null}return C(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 se=H.call(A),G;if(H!==A.entries){for(;!(G=se.next()).done;)if(!W(G.value))return!1}else for(;!(G=se.next()).done;){var re=G.value;if(re&&!W(re[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=s,y.resetWarningCache=s.resetWarningCache,y.PropTypes=y,y},Ko}var Xo,Ln;function ml(){if(Ln)return Xo;Ln=1;var t=dn();function o(){}function n(){}return n.resetWarningCache=o,Xo=function(){function i(c,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 s(){return i}var d={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 d.PropTypes=d,d},Xo}var Fn;function hl(){if(Fn)return uo.exports;if(Fn=1,process.env.NODE_ENV!=="production"){var t=_i(),o=!0;uo.exports=xl()(t.isElement,o)}else uo.exports=ml()();return uo.exports}var fl=hl();const Gr=ll(fl);var xo={exports:{}},we={};/**
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 Vn;function gl(){if(Vn)return we;Vn=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"),d=Symbol.for("react.consumer"),c=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 D(v){if(typeof v=="object"&&v!==null){var C=v.$$typeof;switch(C){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 c:case l:case b:case h:return v;case d:return v;default:return C}}case o:return C}}}return we.ContextConsumer=d,we.ContextProvider=c,we.Element=t,we.ForwardRef=l,we.Fragment=n,we.Lazy=b,we.Memo=h,we.Portal=o,we.Profiler=s,we.StrictMode=i,we.Suspense=u,we.SuspenseList=x,we.isContextConsumer=function(v){return D(v)===d},we.isContextProvider=function(v){return D(v)===c},we.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===t},we.isForwardRef=function(v){return D(v)===l},we.isFragment=function(v){return D(v)===n},we.isLazy=function(v){return D(v)===b},we.isMemo=function(v){return D(v)===h},we.isPortal=function(v){return D(v)===o},we.isProfiler=function(v){return D(v)===s},we.isStrictMode=function(v){return D(v)===i},we.isSuspense=function(v){return D(v)===u},we.isSuspenseList=function(v){return D(v)===x},we.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===c||v.$$typeof===d||v.$$typeof===l||v.$$typeof===y||v.getModuleId!==void 0)},we.typeOf=D,we}var ke={};/**
31
31
  * @license React
32
32
  * react-is.development.js
33
33
  *
@@ -35,16 +35,16 @@ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var 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 Hn;function yl(){return Hn||(Hn=1,process.env.NODE_ENV!=="production"&&(function(){function t(v){if(typeof v=="object"&&v!==null){var C=v.$$typeof;switch(C){case o:switch(v=v.type,v){case i:case d:case s: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 c:return v;default:return C}}case n:return C}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),d=Symbol.for("react.profiler"),c=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"),D=Symbol.for("react.client.reference");ke.ContextConsumer=c,ke.ContextProvider=l,ke.Element=o,ke.ForwardRef=u,ke.Fragment=i,ke.Lazy=m,ke.Memo=b,ke.Portal=n,ke.Profiler=d,ke.StrictMode=s,ke.Suspense=x,ke.SuspenseList=h,ke.isContextConsumer=function(v){return t(v)===c},ke.isContextProvider=function(v){return t(v)===l},ke.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===o},ke.isForwardRef=function(v){return t(v)===u},ke.isFragment=function(v){return t(v)===i},ke.isLazy=function(v){return t(v)===m},ke.isMemo=function(v){return t(v)===b},ke.isPortal=function(v){return t(v)===n},ke.isProfiler=function(v){return t(v)===d},ke.isStrictMode=function(v){return t(v)===s},ke.isSuspense=function(v){return t(v)===x},ke.isSuspenseList=function(v){return t(v)===h},ke.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===i||v===d||v===s||v===x||v===h||typeof v=="object"&&v!==null&&(v.$$typeof===m||v.$$typeof===b||v.$$typeof===l||v.$$typeof===c||v.$$typeof===u||v.$$typeof===D||v.getModuleId!==void 0)},ke.typeOf=t})()),ke}var Un;function bl(){return Un||(Un=1,process.env.NODE_ENV==="production"?xo.exports=gl():xo.exports=yl()),xo.exports}var Ri=bl();function Ht(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 Wi(t){if(To.isValidElement(t)||Ri.isValidElementType(t)||!Ht(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Wi(t[n])}),o}function Ke(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Ht(t)&&Ht(o)&&Object.keys(o).forEach(s=>{To.isValidElement(o[s])||Ri.isValidElementType(o[s])?i[s]=o[s]:Ht(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Ht(t[s])?i[s]=Ke(t[s],o[s],n):n.clone?i[s]=Ht(o[s])?Wi(o[s]):o[s]:i[s]=o[s]}),i}const vl=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 Sl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=t,d=vl(o),c=Object.keys(d);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 D=c.indexOf(y);return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n}) and (max-width:${(D!==-1&&typeof o[c[D]]=="number"?o[c[D]]:y)-i/100}${n})`}function h(m){return c.indexOf(m)+1<c.length?x(m,c[c.indexOf(m)+1]):l(m)}function b(m){const y=c.indexOf(m);return y===0?l(c[1]):y===c.length-1?u(c[y]):x(m,c[c.indexOf(m)+1]).replace("@media","@media not all and")}return{keys:c,values:d,up:l,down:u,between:x,only:h,not:b,unit:n,...s}}function Yn(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,s)=>{var c,l;const d=/min-width:\s*([0-9.]+)/;return+(((c=i.match(d))==null?void 0:c[1])||0)-+(((l=s.match(d))==null?void 0:l[1])||0)});return n.length?n.reduce((i,s)=>{const d=o[s];return delete i[s],i[s]=d,i},{...o}):o}function jl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function Cl(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,d=Number.isNaN(+i)?i||0:+i;return t.containerQueries(s).up(d)}function wl(t){const o=(d,c)=>d.replace("@media",c?`@container ${c}`:"@container");function n(d,c){d.up=(...l)=>o(t.breakpoints.up(...l),c),d.down=(...l)=>o(t.breakpoints.down(...l),c),d.between=(...l)=>o(t.breakpoints.between(...l),c),d.only=(...l)=>o(t.breakpoints.only(...l),c),d.not=(...l)=>{const u=o(t.breakpoints.not(...l),c);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=d=>(n(i,d),i);return n(s),{...t,containerQueries:s}}const kl={borderRadius:4},Yt=process.env.NODE_ENV!=="production"?Gr.oneOfType([Gr.number,Gr.string,Gr.object,Gr.array]):{};function to(t,o){return o?Ke(t,o,{clone:!1}):t}const Bo={xs:0,sm:600,md:900,lg:1200,xl:1536},Gn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${Bo[t]}px)`},Tl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:Bo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function At(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const d=i.breakpoints||Gn;return o.reduce((c,l,u)=>(c[d.up(d.keys[u])]=n(o[u]),c),{})}if(typeof o=="object"){const d=i.breakpoints||Gn;return Object.keys(o).reduce((c,l)=>{if(jl(d.keys,l)){const u=Cl(i.containerQueries?i:Tl,l);u&&(c[u]=n(o[l],l))}else if(Object.keys(d.values||Bo).includes(l)){const u=d.up(l);c[u]=n(o[l],l)}else{const u=l;c[u]=o[u]}return c},{})}return n(o)}function Il(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const d=t.up(s);return i[d]={},i},{}))||{}}function qn(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function Pi(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":lr(7));return t.charAt(0).toUpperCase()+t.slice(1)}function Do(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((s,d)=>s&&s[d]?s[d]:null,t);if(i!=null)return i}return o.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,t)}function wo(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=Do(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,d=c=>{if(c[o]==null)return null;const l=c[o],u=c.theme,x=Do(u,i)||{};return At(c,l,b=>{let m=wo(x,s,b);return b===m&&typeof b=="string"&&(m=wo(x,s,`${o}${b==="default"?"":Pi(b)}`,b)),n===!1?m:{[n]:m}})};return d.propTypes=process.env.NODE_ENV!=="production"?{[o]:Yt}:{},d.filterProps=[o],d}function zl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const Bl={m:"margin",p:"padding"},Dl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Jn={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},El=zl(t=>{if(t.length>2)if(Jn[t])t=Jn[t];else return[t];const[o,n]=t.split(""),i=Bl[o],s=Dl[n]||"";return Array.isArray(s)?s.map(d=>i+d):[i+s]}),Eo=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],Oo=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Ol=[...Eo,...Oo];function oo(t,o,n,i){const s=Do(t,o,!0)??n;return typeof s=="number"||typeof s=="string"?d=>typeof d=="string"?d:(process.env.NODE_ENV!=="production"&&typeof d!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${d}.`),typeof s=="string"?s.startsWith("var(")&&d===0?0:s.startsWith("var(")&&d===1?s:`calc(${d} * ${s})`:s*d):Array.isArray(s)?d=>{if(typeof d=="string")return d;const c=Math.abs(d);process.env.NODE_ENV!=="production"&&(Number.isInteger(c)?c>s.length-1&&console.error([`MUI: The value provided (${c}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${c} > ${s.length-1}, you need to add the missing values.`].join(`
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.
47
- \`color.main\` should be a string, but \`${JSON.stringify(j.main)}\` was provided instead.
41
+ `)));const l=s[c];return d>=0?l:typeof l=="number"?-l:typeof l=="string"&&l.startsWith("var(")?`calc(-1 * ${l})`:`-${l}`}:typeof s=="function"?s:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${o}\` value (${s}) is invalid.`,"It should be a number, an array or a function."].join(`
42
+ `)),()=>{})}function un(t){return oo(t,"spacing",8,"spacing")}function no(t,o){return typeof o=="string"||o==null?o:t(o)}function $l(t,o){return n=>t.reduce((i,s)=>(i[s]=no(o,n),i),{})}function Al(t,o,n,i){if(!o.includes(n))return null;const s=El(n),d=$l(s,i),c=t[n];return At(t,c,d)}function Ni(t,o){const n=un(t.theme);return Object.keys(t).map(i=>Al(t,o,i,n)).reduce(to,{})}function Oe(t){return Ni(t,Eo)}Oe.propTypes=process.env.NODE_ENV!=="production"?Eo.reduce((t,o)=>(t[o]=Yt,t),{}):{};Oe.filterProps=Eo;function $e(t){return Ni(t,Oo)}$e.propTypes=process.env.NODE_ENV!=="production"?Oo.reduce((t,o)=>(t[o]=Yt,t),{}):{};$e.filterProps=Oo;process.env.NODE_ENV!=="production"&&Ol.reduce((t,o)=>(t[o]=Yt,t),{});function Li(t=8,o=un({spacing:t})){if(t.mui)return t;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(d=>{const c=o(d);return typeof c=="number"?`${c}px`:c}).join(" "));return n.mui=!0,n}function $o(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(d=>{i[d]=s}),i),{}),n=i=>Object.keys(i).reduce((s,d)=>o[d]?to(s,o[d](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=t.reduce((i,s)=>i.concat(s.filterProps),[]),n}function tt(t){return typeof t!="number"?t:`${t}px solid`}function rt(t,o){return Ae({prop:t,themeKey:"borders",transform:o})}const _l=rt("border",tt),Ml=rt("borderTop",tt),Rl=rt("borderRight",tt),Wl=rt("borderBottom",tt),Pl=rt("borderLeft",tt),Nl=rt("borderColor"),Ll=rt("borderTopColor"),Fl=rt("borderRightColor"),Vl=rt("borderBottomColor"),Hl=rt("borderLeftColor"),Ul=rt("outline",tt),Yl=rt("outlineColor"),Ao=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=oo(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:no(o,i)});return At(t,t.borderRadius,n)}return null};Ao.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Yt}:{};Ao.filterProps=["borderRadius"];$o(_l,Ml,Rl,Wl,Pl,Nl,Ll,Fl,Vl,Hl,Ao,Ul,Yl);const _o=t=>{if(t.gap!==void 0&&t.gap!==null){const o=oo(t.theme,"spacing",8,"gap"),n=i=>({gap:no(o,i)});return At(t,t.gap,n)}return null};_o.propTypes=process.env.NODE_ENV!=="production"?{gap:Yt}:{};_o.filterProps=["gap"];const Mo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=oo(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:no(o,i)});return At(t,t.columnGap,n)}return null};Mo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Yt}:{};Mo.filterProps=["columnGap"];const Ro=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=oo(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:no(o,i)});return At(t,t.rowGap,n)}return null};Ro.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Yt}:{};Ro.filterProps=["rowGap"];const Gl=Ae({prop:"gridColumn"}),ql=Ae({prop:"gridRow"}),Jl=Ae({prop:"gridAutoFlow"}),Kl=Ae({prop:"gridAutoColumns"}),Xl=Ae({prop:"gridAutoRows"}),Zl=Ae({prop:"gridTemplateColumns"}),Ql=Ae({prop:"gridTemplateRows"}),ec=Ae({prop:"gridTemplateAreas"}),tc=Ae({prop:"gridArea"});$o(_o,Mo,Ro,Gl,ql,Jl,Kl,Xl,Zl,Ql,ec,tc);function Or(t,o){return o==="grey"?o:t}const rc=Ae({prop:"color",themeKey:"palette",transform:Or}),oc=Ae({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:Or}),nc=Ae({prop:"backgroundColor",themeKey:"palette",transform:Or});$o(rc,oc,nc);function qe(t){return t<=1&&t!==0?`${t*100}%`:t}const ic=Ae({prop:"width",transform:qe}),pn=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,d,c,l,u;const i=((c=(d=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:d.values)==null?void 0:c[n])||Bo[n];return i?((u=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:qe(n)}};return At(t,t.maxWidth,o)}return null};pn.filterProps=["maxWidth"];const sc=Ae({prop:"minWidth",transform:qe}),ac=Ae({prop:"height",transform:qe}),lc=Ae({prop:"maxHeight",transform:qe}),cc=Ae({prop:"minHeight",transform:qe});Ae({prop:"size",cssProperty:"width",transform:qe});Ae({prop:"size",cssProperty:"height",transform:qe});const dc=Ae({prop:"boxSizing"});$o(ic,pn,sc,ac,lc,cc,dc);const Wo={border:{themeKey:"borders",transform:tt},borderTop:{themeKey:"borders",transform:tt},borderRight:{themeKey:"borders",transform:tt},borderBottom:{themeKey:"borders",transform:tt},borderLeft:{themeKey:"borders",transform:tt},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:tt},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Ao},color:{themeKey:"palette",transform:Or},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:Or},backgroundColor:{themeKey:"palette",transform:Or},p:{style:$e},pt:{style:$e},pr:{style:$e},pb:{style:$e},pl:{style:$e},px:{style:$e},py:{style:$e},padding:{style:$e},paddingTop:{style:$e},paddingRight:{style:$e},paddingBottom:{style:$e},paddingLeft:{style:$e},paddingX:{style:$e},paddingY:{style:$e},paddingInline:{style:$e},paddingInlineStart:{style:$e},paddingInlineEnd:{style:$e},paddingBlock:{style:$e},paddingBlockStart:{style:$e},paddingBlockEnd:{style:$e},m:{style:Oe},mt:{style:Oe},mr:{style:Oe},mb:{style:Oe},ml:{style:Oe},mx:{style:Oe},my:{style:Oe},margin:{style:Oe},marginTop:{style:Oe},marginRight:{style:Oe},marginBottom:{style:Oe},marginLeft:{style:Oe},marginX:{style:Oe},marginY:{style:Oe},marginInline:{style:Oe},marginInlineStart:{style:Oe},marginInlineEnd:{style:Oe},marginBlock:{style:Oe},marginBlockStart:{style:Oe},marginBlockEnd:{style:Oe},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:_o},rowGap:{style:Ro},columnGap:{style:Mo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:qe},maxWidth:{style:pn},minWidth:{transform:qe},height:{transform:qe},maxHeight:{transform:qe},minHeight:{transform:qe},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 uc(...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 pc(t,o){return typeof t=="function"?t(o):t}function xc(){function t(n,i,s,d){const c={[n]:i,theme:s},l=d[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=Do(s,x)||{};return b?b(c):At(c,i,D=>{let v=wo(m,h,D);return D===v&&typeof D=="string"&&(v=wo(m,h,`${n}${D==="default"?"":Pi(D)}`,D)),u===!1?v:{[u]:v}})}function o(n){const{sx:i,theme:s={},nested:d}=n||{};if(!i)return null;const c=s.unstable_sxConfig??Wo;function l(u){let x=u;if(typeof u=="function")x=u(s);else if(typeof u!="object")return u;if(!x)return null;const h=Il(s.breakpoints),b=Object.keys(h);let m=h;return Object.keys(x).forEach(y=>{const D=pc(x[y],s);if(D!=null)if(typeof D=="object")if(c[y])m=to(m,t(y,D,s,c));else{const v=At({theme:s},D,C=>({[y]:C}));uc(v,D)?m[y]=o({sx:D,theme:s,nested:!0}):m=to(m,v)}else m=to(m,t(y,D,s,c))}),!d&&s.modularCssLayers?{"@layer sx":Yn(s,qn(b,m))}:Yn(s,qn(b,m))}return Array.isArray(i)?i.map(l):l(i)}return o}const Po=xc();Po.filterProps=["sx"];function mc(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 Fi(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:d={},...c}=t,l=Sl(n),u=Li(s);let x=Ke({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...kl,...d}},c);return x=wl(x),x.applyStyles=mc,x=o.reduce((h,b)=>Ke(h,b),x),x.unstable_sxConfig={...Wo,...c==null?void 0:c.unstable_sxConfig},x.unstable_sx=function(b){return Po({sx:b,theme:this})},x}function hc(t){return Object.keys(t).length===0}function fc(t=null){const o=To.useContext(_s.ThemeContext);return!o||hc(o)?t:o}const gc=Fi();function yc(t=gc){return fc(t)}const Kn=t=>t,bc=()=>{let t=Kn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Kn}}},vc=bc(),Sc={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 jc(t,o,n="Mui"){const i=Sc[o];return i?`${n}-${i}`:`${vc.generate(t)}-${o}`}function Cc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function xn(t,o=0,n=1){return process.env.NODE_ENV!=="production"&&(t<o||t>n)&&console.error(`MUI: The value provided ${t} is out of range [${o}, ${n}].`),Cc(t,o,n)}function wc(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 Ut(t){if(t.type)return t;if(t.charAt(0)==="#")return Ut(wc(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().`:lr(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.`:lr(10,s))}else i=i.split(",");return i=i.map(d=>parseFloat(d)),{type:n,values:i,colorSpace:s}}const kc=t=>{const o=Ut(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Zr=(t,o)=>{try{return kc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function No(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((s,d)=>d<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 Vi(t){t=Ut(t);const{values:o}=t,n=o[0],i=o[1]/100,s=o[2]/100,d=i*Math.min(s,1-s),c=(x,h=(x+n/30)%12)=>s-d*Math.max(Math.min(h-3,9-h,1),-1);let l="rgb";const u=[Math.round(c(0)*255),Math.round(c(8)*255),Math.round(c(4)*255)];return t.type==="hsla"&&(l+="a",u.push(o[3])),No({type:l,values:u})}function rn(t){t=Ut(t);let o=t.type==="hsl"||t.type==="hsla"?Ut(Vi(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 Xn(t,o){const n=rn(t),i=rn(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function T(t,o){return t=Ut(t),o=xn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,No(t)}function ir(t,o,n){try{return T(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Lo(t,o){if(t=Ut(t),o=xn(o),t.type.includes("hsl"))t.values[2]*=1-o;else if(t.type.includes("rgb")||t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]*=1-o;return No(t)}function je(t,o,n){try{return Lo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Fo(t,o){if(t=Ut(t),o=xn(o),t.type.includes("hsl"))t.values[2]+=(100-t.values[2])*o;else if(t.type.includes("rgb"))for(let n=0;n<3;n+=1)t.values[n]+=(255-t.values[n])*o;else if(t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]+=(1-t.values[n])*o;return No(t)}function Ce(t,o,n){try{return Fo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Tc(t,o=.15){return rn(t)>.5?Lo(t,o):Fo(t,o)}function mo(t,o,n){try{return Tc(t,o)}catch{return t}}function Ic(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 Zn=(t,o,n,i=[])=>{let s=t;o.forEach((d,c)=>{c===o.length-1?Array.isArray(s)?s[Number(d)]=n:s&&typeof s=="object"&&(s[d]=n):s&&typeof s=="object"&&(s[d]||(s[d]=i.includes(d)?[]:{}),s=s[d])})},zc=(t,o,n)=>{function i(s,d=[],c=[]){Object.entries(s).forEach(([l,u])=>{(!n||n&&!n([...d,l]))&&u!=null&&(typeof u=="object"&&Object.keys(u).length>0?i(u,[...d,l],Array.isArray(u)?[...c,l]:c):o([...d,l],u,c))})}i(t)},Bc=(t,o)=>typeof o=="number"?["lineHeight","fontWeight","opacity","zIndex"].some(i=>t.includes(i))||t[t.length-1].toLowerCase().includes("opacity")?o:`${o}px`:o;function Zo(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},d={},c={};return zc(t,(l,u,x)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const h=`--${n?`${n}-`:""}${l.join("-")}`,b=Bc(l,u);Object.assign(s,{[h]:b}),Zn(d,l,`var(${h})`,x),Zn(c,l,`var(${h}, ${b})`,x)}},l=>l[0]==="vars"),{css:s,vars:d,varsWithDefaults:c}}function Dc(t,o={}){const{getSelector:n=S,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:d}=o,{colorSchemes:c={},components:l,defaultColorScheme:u="light",...x}=t,{vars:h,css:b,varsWithDefaults:m}=Zo(x,o);let y=m;const D={},{[u]:v,...C}=c;if(Object.entries(C||{}).forEach(([k,j])=>{const{vars:a,css:B,varsWithDefaults:R}=Zo(j,o);y=Ke(y,R),D[k]={css:B,vars:a}}),v){const{css:k,vars:j,varsWithDefaults:a}=Zo(v,o);y=Ke(y,a),D[u]={css:k,vars:j}}function S(k,j){var B,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"]`),k){if(a==="media")return t.defaultColorScheme===k?":root":{[`@media (prefers-color-scheme: ${((R=(B=c[k])==null?void 0:B.palette)==null?void 0:R.mode)||k})`]:{":root":j}};if(a)return t.defaultColorScheme===k?`:root, ${a.replace("%s",String(k))}`:a.replace("%s",String(k))}return":root"}return{vars:y,generateThemeVars:()=>{let k={...h};return Object.entries(D).forEach(([,{vars:j}])=>{k=Ke(k,j)}),k},generateStyleSheets:()=>{var q,K;const k=[],j=t.defaultColorScheme||"light";function a(ee,g){Object.keys(g).length&&k.push(typeof ee=="string"?{[ee]:{...g}}:ee)}a(n(void 0,{...b}),b);const{[j]:B,...R}=D;if(B){const{css:ee}=B,g=(K=(q=c[j])==null?void 0:q.palette)==null?void 0:K.mode,M=!i&&g?{colorScheme:g,...ee}:{...ee};a(n(j,{...M}),M)}return Object.entries(R).forEach(([ee,{css:g}])=>{var V,Z;const M=(Z=(V=c[ee])==null?void 0:V.palette)==null?void 0:Z.mode,W=!i&&M?{colorScheme:M,...g}:{...g};a(n(ee,{...W}),W)}),d&&k.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)"}}),k}}}function Ec(t){return function(n){return t==="media"?(process.env.NODE_ENV!=="production"&&n!=="light"&&n!=="dark"&&console.error(`MUI: @media (prefers-color-scheme) supports only 'light' or 'dark', but receive '${n}'.`),`@media (prefers-color-scheme: ${n})`):t?t.startsWith("data-")&&!t.includes("%s")?`[${t}="${n}"] &`:t==="class"?`.${n} &`:t==="data"?`[data-${n}] &`:`${t.replace("%s",n)} &`:"&"}}const ro={black:"#000",white:"#fff"},Oc={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"},Tr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},Ir={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},qr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},zr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},Br={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},Dr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Hi(){return{text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:ro.white,default:ro.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}}}const Ui=Hi();function Yi(){return{text:{primary:ro.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:ro.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}}}const on=Yi();function Qn(t,o,n,i){const s=i.light||i,d=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Fo(t.main,s):o==="dark"&&(t.dark=Lo(t.main,d)))}function ei(t,o,n,i,s){const d=s.light||s,c=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 ${(d*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(c*100).toFixed(0)}%)`))}function $c(t="light"){return t==="dark"?{main:zr[200],light:zr[50],dark:zr[400]}:{main:zr[700],light:zr[400],dark:zr[800]}}function Ac(t="light"){return t==="dark"?{main:Tr[200],light:Tr[50],dark:Tr[400]}:{main:Tr[500],light:Tr[300],dark:Tr[700]}}function _c(t="light"){return t==="dark"?{main:Ir[500],light:Ir[300],dark:Ir[700]}:{main:Ir[700],light:Ir[400],dark:Ir[800]}}function Mc(t="light"){return t==="dark"?{main:Br[400],light:Br[300],dark:Br[700]}:{main:Br[700],light:Br[500],dark:Br[900]}}function Rc(t="light"){return t==="dark"?{main:Dr[400],light:Dr[300],dark:Dr[700]}:{main:Dr[800],light:Dr[500],dark:Dr[900]}}function Wc(t="light"){return t==="dark"?{main:qr[400],light:qr[300],dark:qr[700]}:{main:"#ed6c02",light:qr[500],dark:qr[900]}}function Pc(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function mn(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...d}=t,c=t.primary||$c(o),l=t.secondary||Ac(o),u=t.error||_c(o),x=t.info||Mc(o),h=t.success||Rc(o),b=t.warning||Wc(o);function m(C){if(s)return Pc(C);const S=Xn(C,on.text.primary)>=n?on.text.primary:Ui.text.primary;if(process.env.NODE_ENV!=="production"){const I=Xn(C,S);I<3&&console.error([`MUI: The contrast ratio of ${I}:1 for ${S} on ${C}`,"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:C,name:S,mainShade:I=500,lightShade:f=300,darkShade:k=700})=>{if(C={...C},!C.main&&C[I]&&(C.main=C[I]),!C.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.`:lr(11,S?` (${S})`:"",I));if(typeof C.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
47
+ \`color.main\` should be a string, but \`${JSON.stringify(C.main)}\` was provided instead.
48
48
 
49
49
  Did you intend to use one of the following approaches?
50
50
 
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
56
56
 
57
57
  const theme2 = createTheme({ palette: {
58
58
  primary: { main: green[500] },
59
- } });`: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
+ } });`:lr(12,S?` (${S})`:"",JSON.stringify(C.main)));return s?(ei(s,C,"light",f,i),ei(s,C,"dark",k,i)):(Qn(C,"light",f,i),Qn(C,"dark",k,i)),C.contrastText||(C.contrastText=m(C.main)),C};let D;return o==="light"?D=Hi():o==="dark"&&(D=Yi()),process.env.NODE_ENV!=="production"&&(D||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),Ke({common:{...ro},mode:o,primary:y({color:c,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:Oc,contrastThreshold:n,getContrastText:m,augmentColor:y,tonalOffset:i,...D},d)}function Nc(t){const o={};return Object.entries(t).forEach(i=>{const[s,d]=i;typeof d=="object"&&(o[s]=`${d.fontStyle?`${d.fontStyle} `:""}${d.fontVariant?`${d.fontVariant} `:""}${d.fontWeight?`${d.fontWeight} `:""}${d.fontStretch?`${d.fontStretch} `:""}${d.fontSize||""}${d.lineHeight?`/${d.lineHeight} `:""}${d.fontFamily||""}`)}),o}function Lc(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Fc(t){return Math.round(t*1e5)/1e5}const ti={textTransform:"uppercase"},ri='"Roboto", "Helvetica", "Arial", sans-serif';function Vc(t,o){const{fontFamily:n=ri,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:d=400,fontWeightMedium:c=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||(C=>`${C/u*m}rem`),D=(C,S,I,f,k)=>({fontFamily:n,fontWeight:C,fontSize:y(S),lineHeight:I,...n===ri?{letterSpacing:`${Fc(f/S)}em`}:{},...k,...x}),v={h1:D(s,96,1.167,-1.5),h2:D(s,60,1.2,-.5),h3:D(d,48,1.167,0),h4:D(d,34,1.235,.25),h5:D(d,24,1.334,0),h6:D(c,20,1.6,.15),subtitle1:D(d,16,1.75,.15),subtitle2:D(c,14,1.57,.1),body1:D(d,16,1.5,.15),body2:D(d,14,1.43,.15),button:D(c,14,1.75,.4,ti),caption:D(d,12,1.66,.4),overline:D(d,12,2.66,1,ti),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Ke({htmlFontSize:u,pxToRem:y,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:d,fontWeightMedium:c,fontWeightBold:l,...v},b,{clone:!1})}const Hc=.2,Uc=.14,Yc=.12;function Be(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Hc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Uc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Yc})`].join(",")}const Gc=["none",Be(0,2,1,-1,0,1,1,0,0,1,3,0),Be(0,3,1,-2,0,2,2,0,0,1,5,0),Be(0,3,3,-2,0,3,4,0,0,1,8,0),Be(0,2,4,-1,0,4,5,0,0,1,10,0),Be(0,3,5,-1,0,5,8,0,0,1,14,0),Be(0,3,5,-1,0,6,10,0,0,1,18,0),Be(0,4,5,-2,0,7,10,1,0,2,16,1),Be(0,5,5,-3,0,8,10,1,0,3,14,2),Be(0,5,6,-3,0,9,12,1,0,3,16,2),Be(0,6,6,-3,0,10,14,1,0,4,18,3),Be(0,6,7,-4,0,11,15,1,0,4,20,3),Be(0,7,8,-4,0,12,17,2,0,5,22,4),Be(0,7,8,-4,0,13,19,2,0,5,24,4),Be(0,7,9,-4,0,14,21,2,0,5,26,4),Be(0,8,9,-5,0,15,22,2,0,6,28,5),Be(0,8,10,-5,0,16,24,2,0,6,30,5),Be(0,8,11,-5,0,17,26,2,0,6,32,5),Be(0,9,11,-5,0,18,28,2,0,7,34,6),Be(0,9,12,-6,0,19,29,2,0,7,36,6),Be(0,10,13,-6,0,20,31,3,0,8,38,7),Be(0,10,13,-6,0,21,33,3,0,8,40,7),Be(0,10,14,-6,0,22,35,3,0,8,42,7),Be(0,11,14,-7,0,23,36,3,0,9,44,8),Be(0,11,15,-7,0,24,38,3,0,9,46,8)],qc={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)"},Jc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function oi(t){return`${Math.round(t)}ms`}function Kc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Xc(t){const o={...qc,...t.easing},n={...Jc,...t.duration};return{getAutoHeightDuration:Kc,create:(s=["all"],d={})=>{const{duration:c=n.standard,easing:l=o.easeInOut,delay:u=0,...x}=d;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(c)&&!h(c)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${c}.`),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 d!="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 c=="string"?c:oi(c)} ${l} ${typeof u=="string"?u:oi(u)}`).join(",")},...t,easing:o,duration:n}}const Zc={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function Qc(t){return Ht(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Gi(t={}){const o={...t};function n(i){const s=Object.entries(i);for(let d=0;d<s.length;d++){const[c,l]=s[d];!Qc(l)||c.startsWith("unstable_")?delete i[c]:Ht(l)&&(i[c]={...l},n(i[c]))}}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 ni(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const ed=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 td(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})`:T(o,ed(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${ni(n)})`:Fo(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${ni(n)})`:Lo(o,n)}})}function nn(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:d={},transitions:c={},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.":lr(20));const b=mn({...d,colorSpace:x}),m=Fi(t);let y=Ke(m,{mixins:Lc(m.breakpoints,i),palette:b,shadows:Gc.slice(),typography:Vc(b,l),transitions:Xc(c),zIndex:{...Zc}});if(y=Ke(y,h),y=o.reduce((D,v)=>Ke(D,v),y),process.env.NODE_ENV!=="production"){const D=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],v=(C,S)=>{let I;for(I in C){const f=C[I];if(D.includes(I)&&Object.keys(f).length>0){if(process.env.NODE_ENV!=="production"){const k=jc("",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(C,null,2),"",`Instead, you need to use the '&.${k}' syntax:`,JSON.stringify({root:{[`&.${k}`]:f}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
68
+ `))}C[I]={}}}};Object.keys(y.components).forEach(C=>{const S=y.components[C].styleOverrides;S&&C.startsWith("Mui")&&v(S,C)})}return y.unstable_sxConfig={...Wo,...h==null?void 0:h.unstable_sxConfig},y.unstable_sx=function(v){return Po({sx:v,theme:this})},y.toRuntimeSource=Gi,td(y),y}function rd(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 od=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=rd(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function qi(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Ji(t){return t==="dark"?od:[]}function nd(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...d}=t,c=mn({...o,colorSpace:s});return{palette:c,opacity:{...qi(c.mode),...n},overlays:i||Ji(c.mode),...d}}function id(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 sd=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],ad=t=>(o,n)=>{const i=t.rootSelector||":root",s=t.colorSchemeSelector;let d=s;if(s==="class"&&(d=".%s"),s==="data"&&(d="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(d=`[${s}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const c={};return sd(t.cssVarPrefix).forEach(l=>{c[l]=n[l],delete n[l]}),d==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:c}}:d?{[d.replace("%s",o)]:c,[`${i}, ${d.replace("%s",o)}`]:n}:{[i]:{...n,...c}}}if(d&&d!=="media")return`${i}, ${d.replace("%s",String(o))}`}else if(o){if(d==="media")return{[`@media (prefers-color-scheme: ${String(o)})`]:{[i]:n}};if(d)return d.replace("%s",String(o))}return i};function ld(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function N(t,o,n){!t[o]&&n&&(t[o]=n)}function Qr(t){return typeof t!="string"||!t.startsWith("hsl")?t:Vi(t)}function Et(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Zr(Qr(t[o]),`MUI: Can't create \`palette.${o}Channel\` because \`palette.${o}\` is not one of these formats: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().
69
+ To suppress this warning, you need to explicitly provide the \`palette.${o}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function cd(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const bt=t=>{try{return t()}catch{}},dd=(t="mui")=>Ic(t);function Qo(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const d=s==="dark"?"dark":"light";if(!i){o[s]=nd({...n,palette:{mode:d,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:c,...l}=nn({...i,palette:{mode:d,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:c,opacity:{...qi(d),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Ji(d)},l}function ud(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:d="mui",nativeColor:c=!1,shouldSkipGeneratingVar:l=id,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=dd(d),{[m]:D,light:v,dark:C,...S}=n,I={...S};let f=D;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.`:lr(21,m));let k;c&&(k="oklch");const j=Qo(k,I,f,h,m);v&&!I.light&&Qo(k,I,v,void 0,"light"),C&&!I.dark&&Qo(k,I,C,void 0,"dark");let a={defaultColorScheme:m,...j,cssVarPrefix:d,colorSchemeSelector:u,rootSelector:x,getCssVar:y,colorSchemes:I,font:{...Nc(j.typography),...j.font},spacing:cd(h.spacing)};Object.keys(a.colorSchemes).forEach(ee=>{const g=a.colorSchemes[ee].palette,M=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(k){let me;return V===ir&&(me=`transparent ${((1-xe)*100).toFixed(0)}%`),V===je&&(me=`#000 ${(xe*100).toFixed(0)}%`),V===Ce&&(me=`#fff ${(xe*100).toFixed(0)}%`),`color-mix(in ${k}, ${Z}, ${me})`}return V(Z,xe)}if(ld(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(je,g.error.light,.6)),N(g.Alert,"infoColor",W(je,g.info.light,.6)),N(g.Alert,"successColor",W(je,g.success.light,.6)),N(g.Alert,"warningColor",W(je,g.warning.light,.6)),N(g.Alert,"errorFilledBg",M("palette-error-main")),N(g.Alert,"infoFilledBg",M("palette-info-main")),N(g.Alert,"successFilledBg",M("palette-success-main")),N(g.Alert,"warningFilledBg",M("palette-warning-main")),N(g.Alert,"errorFilledColor",bt(()=>g.getContrastText(g.error.main))),N(g.Alert,"infoFilledColor",bt(()=>g.getContrastText(g.info.main))),N(g.Alert,"successFilledColor",bt(()=>g.getContrastText(g.success.main))),N(g.Alert,"warningFilledColor",bt(()=>g.getContrastText(g.warning.main))),N(g.Alert,"errorStandardBg",W(Ce,g.error.light,.9)),N(g.Alert,"infoStandardBg",W(Ce,g.info.light,.9)),N(g.Alert,"successStandardBg",W(Ce,g.success.light,.9)),N(g.Alert,"warningStandardBg",W(Ce,g.warning.light,.9)),N(g.Alert,"errorIconColor",M("palette-error-main")),N(g.Alert,"infoIconColor",M("palette-info-main")),N(g.Alert,"successIconColor",M("palette-success-main")),N(g.Alert,"warningIconColor",M("palette-warning-main")),N(g.AppBar,"defaultBg",M("palette-grey-100")),N(g.Avatar,"defaultBg",M("palette-grey-400")),N(g.Button,"inheritContainedBg",M("palette-grey-300")),N(g.Button,"inheritContainedHoverBg",M("palette-grey-A100")),N(g.Chip,"defaultBorder",M("palette-grey-400")),N(g.Chip,"defaultAvatarColor",M("palette-grey-700")),N(g.Chip,"defaultIconColor",M("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(Ce,g.primary.main,.62)),N(g.LinearProgress,"secondaryBg",W(Ce,g.secondary.main,.62)),N(g.LinearProgress,"errorBg",W(Ce,g.error.main,.62)),N(g.LinearProgress,"infoBg",W(Ce,g.info.main,.62)),N(g.LinearProgress,"successBg",W(Ce,g.success.main,.62)),N(g.LinearProgress,"warningBg",W(Ce,g.warning.main,.62)),N(g.Skeleton,"bg",k?W(ir,g.text.primary,.11):`rgba(${M("palette-text-primaryChannel")} / 0.11)`),N(g.Slider,"primaryTrack",W(Ce,g.primary.main,.62)),N(g.Slider,"secondaryTrack",W(Ce,g.secondary.main,.62)),N(g.Slider,"errorTrack",W(Ce,g.error.main,.62)),N(g.Slider,"infoTrack",W(Ce,g.info.main,.62)),N(g.Slider,"successTrack",W(Ce,g.success.main,.62)),N(g.Slider,"warningTrack",W(Ce,g.warning.main,.62));const V=k?W(je,g.background.default,.6825):mo(g.background.default,.8);N(g.SnackbarContent,"bg",V),N(g.SnackbarContent,"color",bt(()=>k?on.text.primary:g.getContrastText(V))),N(g.SpeedDialAction,"fabHoverBg",mo(g.background.paper,.15)),N(g.StepConnector,"border",M("palette-grey-400")),N(g.StepContent,"border",M("palette-grey-400")),N(g.Switch,"defaultColor",M("palette-common-white")),N(g.Switch,"defaultDisabledColor",M("palette-grey-100")),N(g.Switch,"primaryDisabledColor",W(Ce,g.primary.main,.62)),N(g.Switch,"secondaryDisabledColor",W(Ce,g.secondary.main,.62)),N(g.Switch,"errorDisabledColor",W(Ce,g.error.main,.62)),N(g.Switch,"infoDisabledColor",W(Ce,g.info.main,.62)),N(g.Switch,"successDisabledColor",W(Ce,g.success.main,.62)),N(g.Switch,"warningDisabledColor",W(Ce,g.warning.main,.62)),N(g.TableCell,"border",W(Ce,W(ir,g.divider,1),.88)),N(g.Tooltip,"bg",W(ir,g.grey[700],.92))}if(g.mode==="dark"){N(g.Alert,"errorColor",W(Ce,g.error.light,.6)),N(g.Alert,"infoColor",W(Ce,g.info.light,.6)),N(g.Alert,"successColor",W(Ce,g.success.light,.6)),N(g.Alert,"warningColor",W(Ce,g.warning.light,.6)),N(g.Alert,"errorFilledBg",M("palette-error-dark")),N(g.Alert,"infoFilledBg",M("palette-info-dark")),N(g.Alert,"successFilledBg",M("palette-success-dark")),N(g.Alert,"warningFilledBg",M("palette-warning-dark")),N(g.Alert,"errorFilledColor",bt(()=>g.getContrastText(g.error.dark))),N(g.Alert,"infoFilledColor",bt(()=>g.getContrastText(g.info.dark))),N(g.Alert,"successFilledColor",bt(()=>g.getContrastText(g.success.dark))),N(g.Alert,"warningFilledColor",bt(()=>g.getContrastText(g.warning.dark))),N(g.Alert,"errorStandardBg",W(je,g.error.light,.9)),N(g.Alert,"infoStandardBg",W(je,g.info.light,.9)),N(g.Alert,"successStandardBg",W(je,g.success.light,.9)),N(g.Alert,"warningStandardBg",W(je,g.warning.light,.9)),N(g.Alert,"errorIconColor",M("palette-error-main")),N(g.Alert,"infoIconColor",M("palette-info-main")),N(g.Alert,"successIconColor",M("palette-success-main")),N(g.Alert,"warningIconColor",M("palette-warning-main")),N(g.AppBar,"defaultBg",M("palette-grey-900")),N(g.AppBar,"darkBg",M("palette-background-paper")),N(g.AppBar,"darkColor",M("palette-text-primary")),N(g.Avatar,"defaultBg",M("palette-grey-600")),N(g.Button,"inheritContainedBg",M("palette-grey-800")),N(g.Button,"inheritContainedHoverBg",M("palette-grey-700")),N(g.Chip,"defaultBorder",M("palette-grey-700")),N(g.Chip,"defaultAvatarColor",M("palette-grey-300")),N(g.Chip,"defaultIconColor",M("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(je,g.primary.main,.5)),N(g.LinearProgress,"secondaryBg",W(je,g.secondary.main,.5)),N(g.LinearProgress,"errorBg",W(je,g.error.main,.5)),N(g.LinearProgress,"infoBg",W(je,g.info.main,.5)),N(g.LinearProgress,"successBg",W(je,g.success.main,.5)),N(g.LinearProgress,"warningBg",W(je,g.warning.main,.5)),N(g.Skeleton,"bg",k?W(ir,g.text.primary,.13):`rgba(${M("palette-text-primaryChannel")} / 0.13)`),N(g.Slider,"primaryTrack",W(je,g.primary.main,.5)),N(g.Slider,"secondaryTrack",W(je,g.secondary.main,.5)),N(g.Slider,"errorTrack",W(je,g.error.main,.5)),N(g.Slider,"infoTrack",W(je,g.info.main,.5)),N(g.Slider,"successTrack",W(je,g.success.main,.5)),N(g.Slider,"warningTrack",W(je,g.warning.main,.5));const V=k?W(Ce,g.background.default,.985):mo(g.background.default,.98);N(g.SnackbarContent,"bg",V),N(g.SnackbarContent,"color",bt(()=>k?Ui.text.primary:g.getContrastText(V))),N(g.SpeedDialAction,"fabHoverBg",mo(g.background.paper,.15)),N(g.StepConnector,"border",M("palette-grey-600")),N(g.StepContent,"border",M("palette-grey-600")),N(g.Switch,"defaultColor",M("palette-grey-300")),N(g.Switch,"defaultDisabledColor",M("palette-grey-600")),N(g.Switch,"primaryDisabledColor",W(je,g.primary.main,.55)),N(g.Switch,"secondaryDisabledColor",W(je,g.secondary.main,.55)),N(g.Switch,"errorDisabledColor",W(je,g.error.main,.55)),N(g.Switch,"infoDisabledColor",W(je,g.info.main,.55)),N(g.Switch,"successDisabledColor",W(je,g.success.main,.55)),N(g.Switch,"warningDisabledColor",W(je,g.warning.main,.55)),N(g.TableCell,"border",W(je,W(ir,g.divider,1),.68)),N(g.Tooltip,"bg",W(ir,g.grey[700],.92))}Et(g.background,"default"),Et(g.background,"paper"),Et(g.common,"background"),Et(g.common,"onBackground"),Et(g,"divider"),Object.keys(g).forEach(V=>{const Z=g[V];V!=="tonalOffset"&&Z&&typeof Z=="object"&&(Z.main&&N(g[V],"mainChannel",Zr(Qr(Z.main))),Z.light&&N(g[V],"lightChannel",Zr(Qr(Z.light))),Z.dark&&N(g[V],"darkChannel",Zr(Qr(Z.dark))),Z.contrastText&&N(g[V],"contrastTextChannel",Zr(Qr(Z.contrastText))),V==="text"&&(Et(g[V],"primary"),Et(g[V],"secondary")),V==="action"&&(Z.active&&Et(g[V],"active"),Z.selected&&Et(g[V],"selected")))})}),a=o.reduce((ee,g)=>Ke(ee,g),a);const B={prefix:d,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:ad(a),enableContrastVars:c},{vars:R,generateThemeVars:q,generateStyleSheets:K}=Dc(a,B);return a.vars=R,Object.entries(a.colorSchemes[a.defaultColorScheme]).forEach(([ee,g])=>{a[ee]=g}),a.generateThemeVars=q,a.generateStyleSheets=K,a.generateSpacing=function(){return Li(h.spacing,un(this))},a.getColorSchemeSelector=Ec(u),a.spacing=a.generateSpacing(),a.shouldSkipGeneratingVar=l,a.unstable_sxConfig={...Wo,...h==null?void 0:h.unstable_sxConfig},a.unstable_sx=function(g){return Po({sx:g,theme:this})},a.toRuntimeSource=Gi,a}function ii(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:mn({...n===!0?{}:n.palette,mode:o})})}function pd(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:d=n==null?void 0:n.mode,...c}=t,l=d||"light",u=s==null?void 0:s[l],x={...s,...n?{[l]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return nn(t,...o);let h=n;"palette"in t||x[l]&&(x[l]!==!0?h=x[l].palette:l==="dark"&&(h={mode:"dark"}));const b=nn({...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},ii(b,"dark",x.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:b.palette},ii(b,"light",x.light)),b}return!n&&!("light"in x)&&l==="light"&&(x.light=!0),ud({...c,colorSchemes:x,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const xd=pd();function _t(){const t=yc(xd);return process.env.NODE_ENV!=="production"&&To.useDebugValue(t),t[al]||t}async function md(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const s=new AbortController,d=setTimeout(()=>s.abort(),3e4);let c;try{c=await fetch(t,{headers:i,signal:s.signal})}catch(x){throw clearTimeout(d),(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(d)}if(c.status===401)throw new Error("Authentication failed (401) — check your API key");if(!c.ok)throw new Error(`API error ${c.status}: ${c.statusText}`);let l;try{l=await c.json()}catch{throw new Error("Response is not valid JSON")}let 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 hd(t,o){return o.map(n=>`${n.x}px ${n.y}px ${n.blur}px ${n.spread}px ${T(t.palette.common.black,n.opacity)}`).join(", ")}const fd={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 te(t,o){return hd(t,fd[o])}function Me(t){return`${Number(t.shape.borderRadius)*1.5}px`}function io(t){return`${Number(t.shape.borderRadius)}px`}function gd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[d,c]=p.useState(""),[l,u]=p.useState(!1),[x,h]=p.useState(""),[b,m]=p.useState(null),[y,D]=p.useState(null),[v,C]=p.useState(!1),[S,I]=p.useState(""),f=p.useRef(null),[k,j]=p.useState("json"),[a,B]=p.useState(""),[R,q]=p.useState(""),[K,ee]=p.useState(""),[g,M]=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 ie=10*1024*1024;if(P.size>ie){I("File size exceeds 10MB limit");return}try{const de=await P.text();let le;try{le=JSON.parse(de)}catch{I("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(le)){I("JSON must be an array of objects");return}if(le.length===0){I("No data rows found in JSON file");return}m(P),D(le)}catch{I("Network error — please try again")}},H=P=>{P.preventDefault();const ie=P.dataTransfer.files[0];ie&&A(ie)},se=async()=>{if(a.trim()){M("loading"),V("");try{const P=await md(a.trim(),R.trim()||void 0,K.trim()||void 0);xe(P.data),F(P.data.length),M("ready")}catch(P){V((P==null?void 0:P.message)||"Connection failed"),M("error")}}},G=()=>{if(!d.trim()){u(!0);return}const P=k==="api"?Z:i||y;P&&(n(d.trim(),x.trim(),P),re())},re=()=>{c(""),u(!1),h(""),m(null),D(null),I(""),j("json"),B(""),q(""),ee(""),M("idle"),V(""),xe(null),F(0),o()},ae=i||y,ne=l&&!d.trim();return d.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:re,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=>te(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:re,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:d,onChange:P=>{c(P.target.value),l&&P.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:ne,helperText:ne?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value: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:k==="json"?0:1,onChange:(P,ie)=>{j(ie===0?"json":"api"),M("idle"),V("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(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}})]}),k==="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=>T(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=>T(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:()=>C(!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=>T(P.palette.success.main,.04):S?P=>T(P.palette.error.main,.04):P=>T(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:y?P=>T(P.palette.success.main,.08):S?P=>T(P.palette.error.main,.08):P=>T(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 ie;return((ie=P.target.files)==null?void 0:ie[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=>T(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=>T(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=>T(P.palette.error.main,.08),border:1,borderColor:P=>T(P.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:S})})]})]})]})}),k==="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=>{B(P.target.value),M("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:R,onChange:P=>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:K,onChange:P=>ee(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!a.trim()||g==="loading",onClick:se,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=>T(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=>T(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:a})]})]}),g==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>T(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:re,variant:"text",sx:{color:"primary.main",fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>T(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:G,disabled:k==="json"&&!ae||k==="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:()=>C(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",e.jsx(r.IconButton,{onClick:()=>C(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(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:()=>C(!1),variant:"contained",sx:{fontSize:"0.875rem",borderRadius:P=>`${P.shape.borderRadius}px`,px:2.5,py:.625,minWidth:64},children:"Got it"})})]})]})}function Ki({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=>te(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=>te(n,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:n=>te(n,"hoverButton")},"&:active":{boxShadow:n=>te(n,"pressedButton"),transform:"translateY(1px)"}},children:"Got it"})})]}):null}function yd({onFileUpload:t,onError:o,isUploading:n}){const[i,s]=p.useState(!1),[d,c]=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}c(S.name);try{const f=await S.text();let k;try{k=JSON.parse(f)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(k)){o("JSON must be an array of objects");return}if(k.length===0){o("No data rows found in JSON file");return}t(k)}catch{o("Network error — please try again")}finally{c("")}},b=S=>{S.preventDefault(),s(!0)},m=S=>{S.preventDefault(),s(!1)},y=S=>{S.preventDefault(),s(!1);const I=S.dataTransfer.files[0];I&&h(I)},D=()=>{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)},C=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:D,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?S=>T(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..."}),d&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:d})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:S=>T(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:C,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(Ki,{isOpen:l,onClose:()=>u(!1)})]})}function bd({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=>T(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 vd({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=>T(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=>T(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 Xi({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=>T(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 Sd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:d,disabled:c}){const[l,u]=p.useState(!1),[x,h]=p.useState(!1),[b,m]=p.useState(-1),y=p.useRef(null),D=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]),C=p.useCallback(R=>{o(R),m(-1)},[o]),S=p.useCallback(R=>{var q;o(R),i(R),u(!1),(q=D.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=D.current)==null||q.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(l||u(!0),m(K=>K<n.length-1?K+1:K))):R.key==="ArrowUp"&&(R.preventDefault(),m(K=>K>0?K-1:-1))},[b,n,t,l,I,S]),k=p.useCallback(()=>{var R;o(""),(R=D.current)==null||R.focus()},[o]),j=p.useMemo(()=>n.filter(R=>R.isFavourite),[n]),a=p.useMemo(()=>n.filter(R=>!R.isFavourite),[n]),B=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:y,children:[e.jsx(r.TextField,{inputRef:D,size:"small",fullWidth:!0,value:t,onChange:R=>C(R.target.value),onFocus:v,onKeyDown:f,placeholder:"Search data...",disabled:c,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:R=>T(R.palette.text.primary,.3),transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:R=>T(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:k,edge:"end",sx:{mr:-.5},children:e.jsx(z.Close,{sx:{fontSize:16}})})}):null}}),B&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[j.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"}),j.map((R,q)=>e.jsx(si,{entry:R,isSelected:b===q,onClick:()=>I(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>d(R.query)},`fav-${R.query}`))]}),a.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[j.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,q)=>{const K=j.length+q;return e.jsx(si,{entry:R,isSelected:b===K,onClick:()=>I(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>d(R.query)},`recent-${R.query}`)})]})]})]})}const si=p.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:d}){const c=p.useCallback(u=>{u.stopPropagation(),s()},[s]),l=p.useCallback(u=>{u.stopPropagation(),d()},[d]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?u=>T(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>T(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:c,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 jd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:d,onToggleDefault:c,onToggleFavorite:l,onRestoreView:u,onPermanentDelete:x,isReadOnly:h,isAdmin:b=!1}){const m=_t(),[y,D]=p.useState(!1),[v,C]=p.useState(!1),[S,I]=p.useState({top:0,left:0}),[f,k]=p.useState(null),j=p.useRef(null),a=p.useRef(null),B=t.find(A=>A.id===o),R=B==null?void 0:B.isDefault,q=t.filter(A=>A.scope==="global"&&!A.isDeleted),K=t.filter(A=>A.scope!=="global"&&!A.isDeleted),ee=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&&a.current){const A=a.current.getBoundingClientRect();I({top:A.bottom+window.scrollY+8,left:A.right+window.scrollX-320})}},[y]),p.useEffect(()=>{const A=H=>{j.current&&!j.current.contains(H.target)&&a.current&&!a.current.contains(H.target)&&D(!1)};return y&&document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[y]);const M=A=>{if(n&&A!==o){k(A),D(!1);return}i(A),D(!1)},W=()=>{f&&(i(f),k(null))},V=()=>{k(null)},Z=(A,H=!1)=>{const se=A.scope==="global",G=!h&&(!se||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?T(m.palette.primary.main,.12):"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===A.id?T(m.palette.primary.main,.12):m.palette.action.hover}},children:[e.jsxs(r.Button,{onClick:()=>M(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:[G&&l&&e.jsx(r.IconButton,{onClick:re=>{re.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}})}),G&&c&&!A.isDefault&&e.jsx(r.IconButton,{onClick:re=>{re.stopPropagation(),c(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:a,onClick:()=>D(!y),size:"small",sx:{position:"relative",color:me?"warning.main":"text.secondary",bgcolor:me?T(m.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:me?T(m.palette.warning.main,.2):T(m.palette.text.primary,.06),color:me?"warning.dark":"text.primary"}},title:`View: ${(B==null?void 0:B.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&&yi.createPortal(e.jsxs(r.Box,{ref:j,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))]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(z.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),ee.map(A=>Z(A))]})]}),K.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"}),K.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:()=>C(!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:()=>{s(),D(!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:()=>{d(),D(!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:io(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 Cd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:d=!1,hasModifications:c=!1,position:l,onSortAscending:u,onSortDescending:x,onRemoveSort:h,onFilter:b,onClearFilter:m,onGroupByColumn:y,onHideColumn:D,onManageColumns:v,onManageViews:C,onResetLayout:S,onClose:I}){var ee,g;const f=_t(),k=f.palette,j=p.useRef(null);p.useEffect(()=>{if(!j.current)return;const M=j.current,W=M.getBoundingClientRect(),V=window.innerWidth,Z=window.innerHeight;W.right>V-8&&(M.style.left=`${V-W.width-8}px`),W.bottom>Z-8&&(M.style.top=`${Z-W.height-8}px`)},[l]),p.useEffect(()=>{const M=V=>{j.current&&!j.current.contains(V.target)&&I()},W=V=>{V.key==="Escape"&&I()};return document.addEventListener("mousedown",M),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",W)}},[I]);const a=p.useCallback(M=>()=>{M(),I()},[I]),B=(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",K=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return yi.createPortal(e.jsxs(r.Paper,{ref:j,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:io(f),overflow:"hidden",boxShadow:`0 4px 20px ${T(((ee=k.common)==null?void 0:ee.black)??"#000",.12)}, 0 1px 4px ${T(((g=k.common)==null?void 0:g.black)??"#000",.06)}`},children:[!d&&e.jsxs(r.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary"},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[e.jsx(r.Tooltip,{title:`Sort Ascending (${q})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:a(()=>u(t)),sx:{p:.625,borderRadius:"6px",color:B?"primary.main":"text.secondary",bgcolor:B?T(k.primary.main,.1):"transparent","&:hover":{bgcolor:T(k.primary.main,.08),color:"primary.main"}},children:e.jsx(z.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${K})`,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?T(k.primary.main,.1):"transparent","&:hover":{bgcolor:T(k.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:T(k.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&&!d&&e.jsxs(r.MenuItem,{onClick:a(()=>m(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:T(k.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"}})]})]}),!d&&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:a(()=>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:[!d&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(r.MenuItem,{onClick:a(()=>D(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:T(k.primary.main,.08),color:"primary.main"}},children:e.jsx(z.Settings,{sx:{fontSize:16}})})})]}),d&&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"}})]}),C&&e.jsxs(r.MenuItem,{onClick:a(C),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"}})]}),!d&&c&&S&&e.jsxs(r.MenuItem,{onClick:a(S),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:T(k.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 wd=176,ai="COLUMN_HEADER",kd=p.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:d,isReadOnly:c=!1,hasModifications:l=!1,width:u,onColumnClick:x,onMoveColumn:h,onColumnDragEnd:b,onResizeStart:m,onSortAscending:y,onSortDescending:D,onRemoveSort:v,onOpenFilterForColumn:C,onClearFiltersForColumn:S,onGroupByColumn:I,onHideColumn:f,onManageColumns:k,onManageViews:j,onResetLayout:a}){const B=p.useRef(null),[R,q]=p.useState(!1),[K,ee]=p.useState({x:0,y:0}),[{handlerId:g,isOver:M},W]=$t.useDrop({accept:ai,collect(G){return{handlerId:G.getHandlerId(),isOver:G.isOver()}},hover(G,re){var fe;if(!B.current)return;const ae=G.index,ne=n;if(ae===ne)return;const P=(fe=B.current)==null?void 0:fe.getBoundingClientRect(),ie=(P.right-P.left)/2,de=re.getClientOffset(),le=((de==null?void 0:de.x)??0)-P.left;ae<ne&&le<ie||ae>ne&&le>ie||(h(ae,ne),G.index=ne)}}),[{isDragging:V},Z]=$t.useDrag({type:ai,item:()=>({index:n,columnName:o.name}),collect:G=>({isDragging:G.isDragging()}),end:()=>{b==null||b()}});Z(W(B));const xe=p.useCallback(G=>{G.preventDefault(),G.stopPropagation(),ee({x:G.clientX,y:G.clientY}),q(!0)},[]),me=p.useCallback(()=>q(!1),[]),F=p.useCallback(()=>{x(o.name)},[x,o.name]),A=p.useCallback(G=>{G.stopPropagation(),C(o.name)},[C,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]),se=p.useCallback(()=>s?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,[s,A]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:B,"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:M?G=>T(G.palette.primary.main,.08):"action.hover",boxShadow:G=>`0 1px 0 ${T(G.palette.common.black,.08)}`,backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:G=>T(G.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${wd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Je(o.name),H(),se()]}),e.jsx(r.Box,{draggable:!1,onDragStart:G=>G.preventDefault(),sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:G=>{G.preventDefault(),G.stopPropagation(),m(G,o.name)},onClick:G=>G.stopPropagation(),children:e.jsx(r.Box,{draggable:!1,sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),M&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),R&&e.jsx(Cd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:d,isReadOnly:c,hasModifications:l,position:K,onSortAscending:y,onSortDescending:D,onRemoveSort:v,onFilter:C,onClearFilter:S,onGroupByColumn:I,onHideColumn:f,onManageColumns:k,onManageViews:j,onResetLayout:a,onClose:me})]})});function Td({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:s,onClearSelection:d,onBulkSetFavorites:c}){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 D=()=>{c&&c(x,!0)},v=()=>{c&&c(x,!1)},C=S=>{s(S),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:S=>T(S.palette.primary.main,.08),borderBottom:S=>`1px solid ${T(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:d,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=>T(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=>T(S.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:S=>T(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:()=>C("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),c&&y&&e.jsx(r.Button,{onClick:D,startIcon:e.jsx(z.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",borderColor:S=>T(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>T(S.palette.warning.main,.06)}},children:"Add to Favorites"}),c&&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=>T(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>T(S.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const Id={active:"success",completed:"success",approved:"success",success:"success",done:"success",contract:"info","in progress":"info","in review":"info",review:"info",pending:"info","on leave":"error","on hold":"warning",probation:"warning",cancelled:"error",rejected:"error",blocked:"error",inactive:"neutral","not started":"neutral",paused:"neutral"};function ko(t,o){const n=Id[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:T(i.main,t.palette.mode==="dark"?.24:.12),color:t.palette.mode==="dark"?i.light:i.dark}}function zd(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 Bd={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 Dd(t,o){const n=Bd[o];return n?t.palette[n.hue][n.shade]:t.palette.text.secondary}function Pe(t){return T(t.palette.primary.main,t.palette.mode==="dark"?.24:.12)}function Ed(t){const o=t.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:500,bgcolor:n=>ko(n,o).bg,color:n=>ko(n,o).color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function Od(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 Ed(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=n.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:d=>{const c=zd(d,s);return c?{color:c,fontWeight:600,fontSize:"0.8125rem"}:{fontSize:"0.8125rem"}},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function $d(t){const o=t.find(s=>{const d=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(d)})||t[0]||null,n=t.find(s=>{const d=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(d)&&s!==o})||null,i=t.filter(s=>s!==o&&s!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function Ad({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:s,isReadOnly:d,onToggleSelection:c,onToggleFavorite:l,onView:u,onEdit:x,onDuplicate:h,onDelete:b}){const[m,y]=p.useState(null),[D,v]=p.useState(!1),{primaryCol:C,idCol:S,bodyColumns:I}=p.useMemo(()=>$d(n),[n]),f=C?t[C.name]:null,k=S?t[S.name]:null,j=D||i||s||!!m;return e.jsxs(r.Box,{onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),onClick:()=>c(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":a=>T(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 ${T(a.palette.primary.main,.15)}, 0 2px 8px ${T(a.palette.common.black,.08)}`:D?a=>te(a,"cardHover"):a=>te(a,"cardRest"),transform:D&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:a=>T(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: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(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:Je(a.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:Od(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=>T(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:k?.85:0,userSelect:"none"},children:k?String(k):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:j?1:0,transition:"opacity 0.15s ease"},onClick:a=>a.stopPropagation(),children:[l&&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(),l(t)},sx:{width:28,height:28,color:s?"warning.main":"action.disabled","&:hover":{bgcolor:a=>T(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(),y(a.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:a=>T(a.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:a=>te(a,"popover")}},onClick:a=>a.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"})]}),!d&&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"})]}),!d&&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"})]}),!d&&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 _d({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=>te(s,"flatHover"),"&:hover":{bgcolor:s=>T(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:Ti(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=>T(s.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[t.rowCount," ",t.rowCount===1?"row":"rows"]}),Object.keys(t.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(t.aggregates).map(([s,d])=>ki(d)).filter(Boolean).join(" • ")})]})}function Md({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:s,isReadOnly:d,isGrouped:c,sortStack:l=[],onSort:u,onToggleRowSelection:x,onToggleRowFavorite:h,onToggleGroupCollapse:b,onViewRow:m,onEditRow:y,onDuplicateRow:D,onDeleteRow:v}){const C=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,{sx:{fontFamily:S=>S.typography.fontFamily},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=>T(f.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:f=>T(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:Je(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)=>c&&S.isGroupHeader?e.jsx(_d,{row:S,grouping:n,onToggleCollapse:b||(()=>{})},`group-${S.groupKey}`):e.jsx(Ad,{row:S,rowIndex:I,visibleColumns:o,isSelected:C.has(S==null?void 0:S.__urm_row_id__),isFavorite:s.has(S),isReadOnly:d,onToggleSelection:()=>x(S),onToggleFavorite:h,onView:m,onEdit:y,onDuplicate:D,onDelete:v},`card-${I}`))})]})}const li=[10,15,25,50,100];function Rd(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 Wd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:d}){var M;const l=_t().palette,u=Math.ceil(n/o),[x,h]=p.useState(String(t)),[b,m]=p.useState(null),[y,D]=p.useState(!1),v=p.useRef(null);p.useEffect(()=>{y||(h(String(t)),m(null))},[t,y]);const C=p.useCallback(()=>{const W=Rd(x,u);if(W){m(W);return}const V=parseInt(x.trim(),10);m(null),D(!1),V!==t&&s(V)},[x,u,t,s]),S=p.useCallback(W=>{var V;W.key==="Enter"?(W.preventDefault(),C()):W.key==="Escape"&&(h(String(t)),m(null),D(!1),(V=v.current)==null||V.blur())},[C,t]),I=p.useCallback(()=>{h(String(t)),m(null),D(!1)},[t]),f=p.useCallback(()=>{D(!0),m(null),setTimeout(()=>{var W;return(W=v.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...li))return null;const k=()=>{h(String(t)),m(null),D(!1)},j=()=>{k(),s(1)},a=()=>{k(),t>1&&s(t-1)},B=()=>{k(),t<u&&s(t+1)},R=()=>{k(),s(u)},q=(t-1)*o+1,K=Math.min(t*o,n),ee=`${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=>d(Number(W.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:li.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,"–",K," 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:T(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${T(((M=l.common)==null?void 0:M.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:T(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:ee,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":y?"primary.main":"divider",borderRadius:"4px",bgcolor:b?T(l.error.main,.04):y?T(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 ${T(l.error.main,.2)}`:`0 0 0 2px ${T(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:j,disabled:t===1,size:"small",title:"First page",sx:g,children:e.jsx(z.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:a,disabled:t===1,size:"small",title:"Previous page",sx:g,children:e.jsx(z.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:B,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 Pd(){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 Zi="urm_hint_seen_";function Nd(t){try{return localStorage.getItem(Zi+t)==="true"}catch{return!1}}function Ld(t){try{localStorage.setItem(Zi+t,"true")}catch{}}function ci(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 di(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 ui(t,o){var n,i;switch(t){case"number":return{bg:T(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:T(((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:T(o.secondary.main,.08),color:o.secondary.main};default:return{bg:T(o.text.secondary,.07),color:o.text.secondary}}}function Fd({open:t,onClose:o,row:n,schema:i,reportName:s}){var b,m;const d=_t(),c=d.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:Me(d),maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${T(((b=c.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${T(((m=c.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:T(c.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:T(c.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,D)=>{const v=n[y.name],C=ci(v,y.type),S=!C,I=ui(y.type,c),f=D===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:di(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:Je(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":C})]},y.name)})}),x.map(y=>{const D=n[y.name],v=ci(D,y.type),C=!v,S=ui(y.type,c);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:S.bg,color:S.color},children:di(y.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Je(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:T(c.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:C?"text.disabled":"text.primary",fontStyle:C?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:C?"No value":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 Vd({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=>te(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=>T(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=>T(s.palette.error.main,.1),border:s=>`1px solid ${T(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=>te(s,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"error.dark",boxShadow:s=>te(s,"hoverButton")},"&:active":{boxShadow:s=>te(s,"pressedButton"),transform:"translateY(1px)"}},children:"Delete record"})]})]})}function en(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:T(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:T(((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:T(o.secondary.main,.08),color:o.secondary.main};default:return{bg:T(o.text.secondary,.07),color:o.text.secondary}}}function Hd({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:d}){var C,S,I;const c=_t(),l=c.palette,[u,x]=p.useState({});if(p.useEffect(()=>{t&&i&&x({...i})},[t,i]),!i)return null;const h=s.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,k)=>{x(j=>({...j,[f]:k}))},D=()=>{const f={...u};h.forEach(k=>{const j=u[k.name];if(k.type==="number"){const a=Number(j);f[k.name]=isNaN(a)?i[k.name]:a}else k.type==="boolean"&&(f[k.name]=!!j)}),n(f),o()},v=h.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:Me(c),maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${T(((C=l.common)==null?void 0:C.black)??"#000",.14)}, 0 2px 8px ${T(((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:T(((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"}),d&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d," · ",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:T(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,k)=>{const j=u[f.name],a=pi(f.type,l),B=f.type==="boolean",R=!B&&k===b.filter(K=>K.type!=="boolean").length-1&&b.filter(K=>K.type!=="boolean").length%2!==0,q=B||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:a.bg,color:a.color},children:en(f.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Je(f.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:j?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!j,onChange:K=>y(f.name,K.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 ${T(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:T(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:a.bg,color:a.color},children:en(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:Je(f.name)})]}),e.jsx(r.TextField,{value:j??"",onChange:K=>y(f.name,K.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 k=i[f.name];let j="";try{j=k==null?"":JSON.stringify(k,null,2)}catch{j=String(k)}const a=pi(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:T(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:a.bg,color:a.color},children:en(f.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Je(f.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:T(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:j?"text.primary":"text.disabled",fontStyle:j?"normal":"italic",bgcolor:T(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:j||"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:D,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 Er=176,Ud={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Yd(t){const o=t.toLowerCase().trim();return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:500,bgcolor:n=>ko(n,o).bg,color:n=>ko(n,o).color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Gd(t){const o=t.toLowerCase().trim(),n=Ud[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function qd(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 Jd(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),s=o.findIndex(x=>x.name===t.name),d=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),c=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=s===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return d||c&&!l||u&&!l}function Kd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Xd(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),d=t.name.toLowerCase().replace(/[_\s-]/g,""),c=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(c)return Yd(s);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Gd(s);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(d)||/^[A-Z]{2,8}-\d{2,}$/.test(s);if(u)return qd(s);if(n&&!c&&!l&&!u)return Kd(s);if(t.type==="date"){const x=t.dateFormat??"iso",h=Zs(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 Zd({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:d="",isDirty:c=!1,isExporting:l=!1,columnVisibility:u={},columnOrder:x=[],columnWidths:h={},grouping:b=null,onSort:m,onSortAscending:y,onSortDescending:D,onOpenFilters:v,onOpenSort:C,onOpenFilterForColumn:S,onSelectView:I,onCreateView:f,onManageViews:k,onUpdateCurrentView:j,onSaveAsNewView:a,onToggleDefault:B,onToggleFavorite:R,onRestoreView:q,onPermanentDelete:K,isAdmin:ee=!1,onExport:g,onOpenColumns:M,onUpdateColumnWidth:W,onUpdateColumnOrder:V,onUpdateColumnVisibility:Z,onClearFiltersForColumn:xe,onResetLayout:me,onOpenGroup:F,onGroupByColumn:A,onToggleGroupCollapse:H,onOpenAuditHistory:se,onOpenScheduledReports:G,searchQuery:re,searchHistory:ae=[],onAddToSearchHistory:ne,onToggleSearchFavourite:P,onDeleteSearchHistory:ie,selectedRowIds:de=new Set,onSearchChange:le,onToggleRowSelection:fe,onToggleAllRows:J,onRangeSelection:Re,onClearSelection:He,onExportSelected:St,currentPage:Mt=1,pageSize:pr=15,totalRowsBeforePagination:Gt=o.length,onPageChange:pt,onPageSizeChange:Rt,isReadOnly:ze=!1,userRole:Xe,reportName:jt,onEditRow:ot,onDuplicateRow:Le,onDeleteRow:nt,favoriteRowIndices:Ct=[],resolvedFavoritesSet:Ze=new Set,showFavoritesOnly:it=!1,onToggleRowFavorite:We,onBulkSetFavorites:$r,showDevPanel:xr=!1,onOpenDevConfig:mr,onToggleFavoritesFilter:qt}){var so;const[st,Wt]=p.useState(null),[hr,wt]=p.useState(0),[fr,Ar]=p.useState(0),[Ue,Jt]=p.useState(null),Ie=((so=cr().dates)==null?void 0:so.displayFormat)??null,[Kt,_r]=p.useState(null),[at,L]=p.useState(null),[lt,ye]=p.useState(null),[Ye,Pt]=p.useState(!1),[Mr,xt]=p.useState(!1),[Xt,kt]=p.useState(null),[yr,br]=p.useState(""),[Rr,De]=p.useState(!1),[Q,ct]=p.useState(null),[Te,Zt]=p.useState(null),[be,Qe]=p.useState(null),[Qt,mt]=p.useState(null),[Fe,vr]=p.useState("list"),[Tt,dt]=p.useState(!1),[It,Wr]=p.useState(()=>!Nd("toolbar_search"));p.useRef(null);const er=p.useRef(null),tr=p.useRef(null),Nt=p.useCallback(()=>{Ld("toolbar_search"),Wr(!1)},[]);p.useEffect(()=>{if(!It)return;const O=setTimeout(Nt,2e3);return()=>clearTimeout(O)},[It,Nt]);const Sr=p.useMemo(()=>{const O=Ue??x;return O.length>0?O.map(X=>t.find(he=>he.name===X)).filter(X=>X!==void 0):t},[Ue,x,t]),Ne=p.useMemo(()=>Sr.filter(O=>u[O.name]!==!1),[Sr,u]),ht=p.useMemo(()=>t.filter(O=>u[O.name]===!1).length,[t,u]),zt=p.useMemo(()=>t.map(O=>O.name),[t]),Lt=p.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(zt),[x,zt]),Pr=p.useCallback((O,X)=>{O.preventDefault(),O.stopPropagation(),Wt(X),wt(O.clientX),Ar(h[X]||150)},[h]);p.useEffect(()=>{if(!st)return;const O=he=>{const Ve=he.clientX-hr,pe=Math.max(100,Math.min(600,fr+Ve));W==null||W(st,pe)},X=()=>{Wt(null)};return document.addEventListener("mousemove",O),document.addEventListener("mouseup",X),()=>{document.removeEventListener("mousemove",O),document.removeEventListener("mouseup",X)}},[st,hr,fr,W]);const Nr=p.useCallback(O=>O==null?"-":typeof O=="object"?JSON.stringify(O):typeof O=="boolean"?O?"true":"false":String(O),[]);p.useCallback(O=>{const X=n.find(he=>he.column===O);return X?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[X.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:X.priority})]}):null},[n]),p.useCallback(O=>i.some(he=>he.column===O)?e.jsx(r.IconButton,{size:"small",onClick:he=>{he.stopPropagation(),S==null||S(O)},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 Ft=p.useCallback(O=>{m&&m(O)},[m]),Lr=p.useCallback((O,X)=>{Jt(he=>{const pe=[...he??(x.length>0?x:t.map(Vo=>Vo.name))],[Dt]=pe.splice(O,1);return pe.splice(X,0,Dt),pe})},[x,t]),Fr=p.useCallback(()=>{Ue&&V&&V(Ue),Jt(null)},[Ue,V]),rr=p.useCallback(O=>{if(!m)return;const X=n.find(he=>he.column===O);(!X||X.direction!=="asc")&&m(O)},[m,n]),jr=p.useCallback(O=>{if(!m)return;const X=n.find(he=>he.column===O);X?X.direction==="asc"&&m(O):(m(O),setTimeout(()=>m(O),0))},[m,n]),Cr=p.useCallback(O=>{if(!m)return;const X=n.find(he=>he.column===O);X&&(X.direction==="asc"?(m(O),setTimeout(()=>m(O),0)):X.direction==="desc"&&m(O))},[m,n]),wr=p.useCallback(O=>{Z&&Z(O,!1)},[Z]),or=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],kr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(O=>O===!1),ue=(Mt-1)*pr,ce=o,Ee=p.useMemo(()=>{const O=new Set;return de.forEach(X=>{const he=X==null?void 0:X.__urm_row_id__;he!==void 0&&O.add(he)}),O},[de]);p.useEffect(()=>{const O=X=>{!J||!He||X.target instanceof HTMLInputElement||X.target instanceof HTMLTextAreaElement||((X.ctrlKey||X.metaKey)&&X.key==="a"&&(X.preventDefault(),J(!0,ce)),X.key==="Escape"&&(X.preventDefault(),He()))};return document.addEventListener("keydown",O),()=>document.removeEventListener("keydown",O)},[J,He,ce]);const ut=p.useCallback((O,X)=>{fe&&(X.shiftKey&&Kt!==null?(X.preventDefault(),Re&&Re(Kt,O,ce)):(fe(ce[O]),_r(O)))},[fe,Kt,Re,ce]);!p.useMemo(()=>ce.length>0&&Ee.size>0&&ce.every(O=>Ee.has(O==null?void 0:O.__urm_row_id__)),[ce,Ee])&&ce.some(O=>Ee.has(O==null?void 0:O.__urm_row_id__));const Bt=fe&&J,Vr=p.useCallback(O=>{var Ve;const X=O.groupLevel,he=X*24;return e.jsx(r.TableRow,{onClick:()=>H==null?void 0:H(O.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:`${he+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[O.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:Ti(X,((Ve=b==null?void 0:b.levels[X])==null?void 0:Ve.column)||"",O.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:pe=>T(pe.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[O.rowCount," ",O.rowCount===1?"row":"rows"]}),Object.keys(O.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(O.aggregates).map(([pe,Dt])=>ki(Dt)).filter(Boolean).join(" • ")})]})})},O.groupKey)},[Ne,Bt,b,H]),Vt=p.useCallback((O,X)=>{const he=Ee.has(O==null?void 0:O.__urm_row_id__),Ve=at===X;return e.jsxs(r.TableRow,{"data-row-index":X,onMouseEnter:()=>L(X),onMouseLeave:()=>L(null),onClick:pe=>{!fe||pe.target.closest("[data-row-action-btn]")||ut(X,pe)},onContextMenu:pe=>{pe.preventDefault(),pe.stopPropagation(),Qe({mouseX:pe.clientX,mouseY:pe.clientY,row:O,rowIndex:X})},sx:{height:34,cursor:"pointer",bgcolor:he?pe=>T(pe.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:he?pe=>T(pe.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Ne.map((pe,Dt)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...Dt===Ne.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(Er,180):Er}px`},children:Xd(pe,O[pe.name],Jd(pe,Ne),Ie)},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:Ve||Ze.has(O)?pe=>`linear-gradient(to right, transparent, ${he?T(pe.palette.warning.main,.12):pe.palette.background.paper} 32px)`:"transparent",opacity:Ve||Ze.has(O)?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(O)},title:Ze.has(O)?"Remove from favorites":"Add to favorites",sx:{color:Ze.has(O)?"warning.main":"text.secondary","&:hover":{bgcolor:pe=>T(pe.palette.warning.main,.08),color:"warning.main"}},children:Ze.has(O)?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(),Qe({anchorEl:pe.currentTarget,row:O,rowIndex:X})},sx:{color:"text.secondary",opacity:Ve?1:0,transition:"opacity 0.12s ease",pointerEvents:Ve?"auto":"none","&:hover":{bgcolor:pe=>T(pe.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(z.MoreVert,{sx:{fontSize:18}})})]})})]},X)},[de,ue,at,ut,Ne,h,Nr,ot,Le,nt,fe,We,Ze,ye,Pt,Qe]);return e.jsxs($t.DndProvider,{backend:sn.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[Bt&&St&&He&&e.jsx(Td,{selectedCount:Ee.size,selectedRowIds:de,resolvedFavoritesSet:Ze,viewMode:Fe,onExportSelected:St,onClearSelection:He,onBulkSetFavorites:$r}),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:[ze&&e.jsx(Pd,{}),le&&ne&&P&&ie&&e.jsx(r.Tooltip,{open:It,title:e.jsxs(r.Box,{sx:{p:.5},children:[e.jsx(r.Typography,{variant:"caption",sx:{display:"block",fontWeight:500,mb:.25},children:"💡 Search tip"}),e.jsx(r.Typography,{variant:"caption",children:"Type to search across all columns instantly"})]}),placement:"bottom-start",arrow:!0,PopperProps:{onClick:Nt},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(Sd,{value:re||"",onChange:O=>{It&&Nt(),le(O)},searchHistory:ae,onAddToHistory:ne,onToggleFavourite:P,onDeleteHistory:ie,disabled:ze})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>dt(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:O=>T(O.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(z.InfoOutlined,{sx:{fontSize:20}})})}),qt&&e.jsx(r.Tooltip,{title:it?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:qt,size:"small",disabled:ze,sx:{position:"relative",color:it?"warning.main":"text.secondary",bgcolor:it?O=>T(O.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:it?O=>T(O.palette.warning.main,.2):O=>T(O.palette.text.primary,.06),color:it?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[it?e.jsx(z.Star,{sx:{fontSize:20}}):e.jsx(z.StarBorder,{sx:{fontSize:20}}),it&&Ct.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:Ct.length})]})}),xr&&mr&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:mr,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:O=>T(O.palette.text.secondary,.3),"&:hover":{bgcolor:O=>T(O.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&&k&&j&&s.length>0&&e.jsx(jd,{views:s||[],activeViewId:d||"",isDirty:c,onSelectView:I,onCreateView:f,onManageViews:k,onToggleDefault:B,onToggleFavorite:R,onRestoreView:q,onPermanentDelete:K,isAdmin:ee,isReadOnly:ze}),!ze&&C&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:C,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?O=>Pe(O):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?O=>T(O.palette.primary.main,.2):O=>T(O.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})]})}),!ze&&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?O=>Pe(O):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?O=>T(O.palette.primary.main,.2):O=>T(O.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})]})}),!ze&&M&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:M,size:"small",sx:{position:"relative",color:ht>0||Lt?"primary.main":"text.secondary",bgcolor:ht>0||Lt?O=>Pe(O):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ht>0||Lt?O=>T(O.palette.primary.main,.2):O=>T(O.palette.text.primary,.06),color:ht>0||Lt?"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:"primary.contrastText",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:()=>vr("list"),sx:{borderRadius:1,color:Fe==="list"?"primary.main":"text.secondary",bgcolor:Fe==="list"?O=>Pe(O):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Fe==="list"?O=>T(O.palette.primary.main,.2):O=>T(O.palette.text.primary,.06),color:Fe==="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:()=>vr("grid"),sx:{borderRadius:1,color:Fe==="grid"?"primary.main":"text.secondary",bgcolor:Fe==="grid"?O=>Pe(O):"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Fe==="grid"?O=>T(O.palette.primary.main,.2):O=>T(O.palette.text.primary,.06),color:Fe==="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:O=>mt(O.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:O=>T(O.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(z.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!Qt,anchorEl:Qt,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"})]}),!ze&&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"})]}),se&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{se(),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"})]}),G&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{G(),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:[Fe==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Md,{data:ce,visibleColumns:Ne,grouping:b,selectedRowIds:de,resolvedFavoritesSet:Ze,isReadOnly:ze,isGrouped:!!or,sortStack:n,onSort:m,onToggleRowSelection:fe||(()=>{}),onToggleRowFavorite:We,onToggleGroupCollapse:H,onViewRow:O=>{ye(O),Pt(!0)},onEditRow:(O,X)=>{ct(O),Zt(X),De(!0)},onDuplicateRow:(O,X)=>Le==null?void 0:Le(O,X),onDeleteRow:(O,X)=>{kt(X);const he=Object.values(X).find(Ve=>Ve!=null&&Ve!=="");br(he?String(he):""),xt(!0)}})}),Fe==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:er,onScroll:O=>{tr.current&&(tr.current.scrollLeft=O.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((O,X)=>O+(h[X.name]||(X.type==="date"?180:Er)),We?76:40)}px`},children:[e.jsxs("colgroup",{children:[Ne.map(O=>e.jsx("col",{style:{width:`${h[O.name]||(O.type==="date"?180:Er)}px`}},O.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:[Ne.map((O,X)=>e.jsx(kd,{column:O,index:X,sortRule:n.find(he=>he.column===O.name),hasFilters:i.some(he=>he.column===O.name),isInSortStack:n.some(he=>he.column===O.name),isReadOnly:ze,hasModifications:kr,width:h[O.name],onColumnClick:Ft,onMoveColumn:Lr,onColumnDragEnd:Fr,onResizeStart:Pr,onSortAscending:y||rr,onSortDescending:D||jr,onRemoveSort:Cr,onOpenFilterForColumn:S||(()=>{}),onClearFiltersForColumn:xe||(()=>{}),onGroupByColumn:A,onHideColumn:wr,onManageColumns:M||(()=>{}),onManageViews:k,onResetLayout:me},O.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:tr,onScroll:O=>{er.current&&(er.current.scrollLeft=O.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:O=>O.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:O=>O.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((O,X)=>O+(h[X.name]||(X.type==="date"?180:Er)),We?76:40)}px`},children:[e.jsxs("colgroup",{children:[Ne.map(O=>e.jsx("col",{style:{width:`${h[O.name]||(O.type==="date"?180:Er)}px`}},O.name)),e.jsx("col",{style:{width:`${We?76:40}px`}})]}),e.jsx(r.TableBody,{children:ce.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"})})}):or?ce.map((O,X)=>O.isGroupHeader?Vr(O):Vt(O,X)):ce.map((O,X)=>Vt(O,X))})]})})]}),pt&&Rt&&e.jsx(Wd,{currentPage:Mt,pageSize:pr,totalRows:Gt,totalFields:t.length,onPageChange:pt,onPageSizeChange:Rt}),!(pt&&Rt)&&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 ",ce.length," ",ce.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!be,onClose:()=>Qe(null),anchorEl:(be==null?void 0:be.anchorEl)||null,anchorReference:be!=null&&be.anchorEl?"anchorEl":"anchorPosition",anchorPosition:be&&!be.anchorEl?{top:be.mouseY,left:be.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:be!=null&&be.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:()=>{be&&(ye(be.row),Pt(!0)),Qe(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:()=>{be&&(ct(be.row),Zt(be.rowIndex),De(!0)),Qe(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:()=>{be&&(Le==null||Le(be.rowIndex,be.row)),Qe(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(be){kt(be.row);const O=Object.values(be.row).find(X=>X!=null&&X!=="");br(O?String(O):""),xt(!0)}Qe(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(Fd,{open:Ye,onClose:()=>{Pt(!1),ye(null)},row:lt,schema:t,reportName:jt}),e.jsx(Hd,{open:Rr,onClose:()=>{De(!1),ct(null),Zt(null)},onSave:O=>{Te!==null&&(ot==null||ot(Te,O))},row:Q,schema:t,reportName:jt}),e.jsx(Vd,{open:Mr,onClose:()=>{xt(!1),kt(null)},onConfirm:()=>{Xt!==null&&(nt==null||nt(Xt))},rowPreview:yr}),e.jsx(Ki,{isOpen:Tt,onClose:()=>dt(!1)})]})}function dr({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=>T(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=>T(s.palette.primary.main,.06)},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"primary.main",fontSize:"0.875rem"},children:t.title})}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.6},children:t.description}),t.tips&&t.tips.length>0&&e.jsx(r.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:t.tips.map((s,d)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},d))}),o&&t.devNote&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:s=>T(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>T(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 ur={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 Qd({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:d,onReplaceFilters:c,onClose:l,focusColumn:u}){const[x,h]=p.useState(""),[b,m]=p.useState(""),[y,D]=p.useState(""),[v,C]=p.useState([]),S=cr();p.useEffect(()=>{C([...o])},[o]),p.useEffect(()=>{u&&h(u)},[u]);const I=p.useCallback(()=>{h(""),m(""),D("")},[]),f=p.useMemo(()=>t.filter(M=>M.type!=="mixed"&&M.type!=="null"&&M.type!=="array"&&M.type!=="object"),[t]),k=t.find(M=>M.name===x),j=p.useMemo(()=>{const M=k?On(k.type):[],W=S.filter.allowedOperators;return W.length>0?M.filter(V=>W.includes(V.value)):M},[k]),a=p.useCallback(()=>!(!x||!b||co(b)&&!y.trim()||v.length>=S.filter.maxConditions),[x,b,y,v,S]),B=p.useCallback(()=>{if(!a())return;const M={column:x,operator:b};if(co(b)){const V=k==null?void 0:k.type;M.value=V==="number"?Number(y):y}if(v.some(V=>V.column===M.column&&V.operator===M.operator&&V.value===M.value)){I();return}C([...v,M]),I()},[a,x,b,k,y,v,I]),R=p.useCallback(M=>{C(v.filter((W,V)=>V!==M))},[v]),q=p.useMemo(()=>v.length!==o.length?!0:JSON.stringify(v)!==JSON.stringify(o),[v,o]),K=p.useCallback(()=>{c(v),l()},[v,c,l]),ee=p.useCallback(()=>{C([...o]),I(),l()},[o,I,l]),g=p.useCallback(M=>{var xe;const W=t.find(me=>me.name===M.column);if(!W)return"";const Z=((xe=On(W.type).find(me=>me.value===M.operator))==null?void 0:xe.label)||M.operator;return co(M.operator)?`${M.column} ${Z.toLowerCase()} "${M.value}"`:`${M.column} ${Z.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:ee,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:M=>T(M.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:M=>M.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:M=>M.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:M=>Me(M),bgcolor:"background.paper",outline:"none",boxShadow:M=>te(M,"menu"),animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Filter columns"}),e.jsx(dr,{content:ur.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(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:M=>T(M.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:M=>T(M.palette.text.primary,.3)}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled: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:M=>{h(M.target.value),m(""),D("")},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(M=>e.jsxs(r.MenuItem,{value:M.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Pe(W),"&:hover":{bgcolor:W=>T(W.palette.primary.main,.2)}}},children:[Je(M.name)," (",M.type,")"]},M.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=>{m(M.target.value),D("")},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:j.map(M=>e.jsx(r.MenuItem,{value:M.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:W=>Pe(W),"&:hover":{bgcolor:W=>T(W.palette.primary.main,.2)}}},children:M.label},M.value))})]}),b&&co(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(k==null?void 0:k.type)==="number"?"number":"text",value:y,onChange:M=>D(M.target.value),label:"Value",placeholder:"Enter value...",sx:{"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:B,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:()=>{d(),l()},sx:{fontSize:"0.875rem",color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:v.map((M,W)=>e.jsx(r.Chip,{label:g(M),onDelete:()=>R(W),sx:{bgcolor:V=>Pe(V),color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:V=>`1px solid ${T(V.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:V=>T(V.palette.primary.main,.2),borderColor:V=>T(V.palette.primary.main,.5)},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},W))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"action.hover"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{fontSize:"0.875rem",color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:M=>`${M.shape.borderRadius}px`,transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:K,disabled:!q,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:M=>`${M.shape.borderRadius}px`,boxShadow:M=>te(M,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:M=>te(M,"hoverButton")},"&:active":{boxShadow:M=>te(M,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Apply filter"})]})]})})}const xi="SORT_RULE";function eu({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const d=p.useRef(null),[{handlerId:c},l]=$t.useDrop({accept:xi,collect(h){return{handlerId:h.getHandlerId()}},hover(h,b){var I;if(!d.current)return;const m=h.index,y=o;if(m===y)return;const D=(I=d.current)==null?void 0:I.getBoundingClientRect(),v=(D.bottom-D.top)/2,C=b.getClientOffset(),S=((C==null?void 0:C.y)??0)-D.top;m<y&&S<v||m>y&&S>v||(s(m,y),h.index=y)}}),[{isDragging:u},x]=$t.useDrag({type:xi,item:()=>({index:o}),collect:h=>({isDragging:h.isDragging()})});return x(l(d)),e.jsxs(r.Box,{ref:d,"data-handler-id":c,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity: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=>te(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 ${T(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=>T(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=>T(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=>T(h.palette.error.main,.08),transform:"scale(1.1)"}},children:e.jsx(z.Close,{sx:{fontSize:18}})})]})}function tu({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,d]=p.useState(""),[c,l]=p.useState([]);p.useEffect(()=>{l([...o])},[o]);const u=p.useMemo(()=>JSON.stringify(c)!==JSON.stringify(o),[c,o]),x=cr(),h=p.useCallback(()=>!(c.length>=x.sort.maxLevels||!s||c.some(f=>f.column===s)),[c,s]),b=p.useCallback(()=>{if(!h())return;const f=c.length+1,k={column:s,direction:"asc",priority:f};l([...c,k]),d("")},[h,s,c]),m=p.useCallback(f=>{const j=c.filter((a,B)=>B!==f).map((a,B)=>({...a,priority:B+1}));l(j)},[c]),y=p.useCallback((f,k)=>{const j=[...c];j[f]={...j[f],direction:k},l(j)},[c]),D=p.useCallback((f,k)=>{const j=[...c],[a]=j.splice(f,1);j.splice(k,0,a);const B=j.map((R,q)=>({...R,priority:q+1}));l(B)},[c]),v=p.useCallback(()=>{n([]),i()},[n,i]),C=p.useCallback(()=>{n(c),i()},[c,n,i]),S=p.useCallback(()=>{l([...o]),d(""),i()},[o,i]),I=t.filter(f=>!c.some(k=>k.column===f.name));return e.jsx($t.DndProvider,{backend:sn.HTML5Backend,children:e.jsx(r.Box,{onClick:S,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:f=>T(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=>Me(f),bgcolor:"background.paper",outline:"none",boxShadow:f=>te(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(dr,{content:ur.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=>T(f.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:f=>T(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:c.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:f=>d(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:k=>Pe(k),"&:hover":{bgcolor:k=>T(k.palette.primary.main,.2)}}},children:Je(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"}),c.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"]})]}),c.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",c.length,"/",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:c.map((f,k)=>e.jsx(eu,{rule:f,index:k,onToggleDirection:y,onRemove:m,onMove:D},`${f.column}-${k}`))})]})]}),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:C,variant:"contained",disabled:!u||c.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=>te(f,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:f=>te(f,"hoverButton")},"&:active":{boxShadow:f=>te(f,"pressedButton"),transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function ru({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:d,onRestoreView:c,onPermanentDelete:l,onPromoteToGlobal:u,isAdmin:x=!1,onClose:h}){var f,k;const b=_t(),m=b.palette,y=t.filter(j=>!j.isDeleted),D=t.filter(j=>j.isDeleted),v=y.filter(j=>j.scope==="global"),C=y.filter(j=>j.scope!=="global"),S=j=>{var K,ee,g,M,W;const a=j.scope==="global",B=j.id===o,R=x||!a,q=x&&!a;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:B?"primary.main":"divider",bgcolor:B?T(m.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:B?"primary.main":T(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(j.id),h()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:B?600:500,color:B?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.name}),j.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j.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:T(((K=m.info)==null?void 0:K.main)??m.primary.main,.1),color:((ee=m.info)==null?void 0:ee.main)??m.primary.main,border:`1px solid ${T(((g=m.info)==null?void 0:g.main)??m.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),j.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:T(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(j.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((M=m.info)==null?void 0:M.main)??m.primary.main,bgcolor:T(((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(j.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:T(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(),d(j.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:T(m.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})})]})]})},j.id)},I=j=>{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:T(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:j.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[c&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),c(j.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:T(((a=m.success)==null?void 0:a.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:B=>{B.stopPropagation(),l(j.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:T(m.error.main,.08)}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})]})]},j.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 ${T(((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:j=>`${j.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:((k=m.info)==null?void 0:k.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)})]}),C.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Personal Views"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:C.map(S)})]}),D.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:D.map(I)})]}),y.length===0&&D.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:j=>`${j.shape.borderRadius}px`,px:3},children:"Close"})})]})}const ho=50;function mi({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:d="",initialIsDefault:c=!1,atViewLimit:l=!1,maxViews:u=10}){const[x,h]=p.useState(s),[b,m]=p.useState(!1),[y,D]=p.useState(d),[v,C]=p.useState(c),S=()=>{if(!x.trim()){m(!0);return}if(x.trim().length>ho){m(!0);return}o(x.trim(),y.trim(),v),n()},I=k=>{k.key==="Enter"&&!k.shiftKey?S():k.key==="Escape"&&n()},f=()=>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:k=>Me(k),boxShadow:k=>te(k,"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:k=>{k.target.value.length<=ho&&h(k.target.value),b&&k.target.value.trim()&&m(!1)},onKeyDown:I,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:ho},error:b&&!x.trim(),helperText:b&&!x.trim()?"View name is required":`${x.length} / ${ho}`}),e.jsx(r.TextField,{label:"Description (optional)",value:y,onChange:k=>D(k.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),e.jsxs(r.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1},children:"This view will capture:"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[e.jsxs("li",{children:[t.filters.length," filter",t.filters.length!==1?"s":""]}),e.jsxs("li",{children:["Sorting: ",ua(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:v,onChange:k=>C(k.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:k=>`${k.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:k=>`${k.shape.borderRadius}px`,boxShadow:k=>te(k,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:k=>te(k,"hoverButton")},"&:active":{boxShadow:k=>te(k,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:i?"Save Changes":"Create Report View"})]})]})}function ou({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=>te(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=>te(i,"restButton"),transition:"all 0.2s ease","&:hover":{boxShadow:i=>te(i,"hoverButton")},"&:active":{boxShadow:i=>te(i,"pressedButton"),transform:"translateY(1px)"}},children:"Delete View"})]})]})}const go=100,yo=600,hi="COLUMN";function nu({column:t,index:o,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:d,moveColumn:c}){const l=p.useRef(null),[u,x]=p.useState(i.toString());p.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:h},b]=$t.useDrop({accept:hi,collect(I){return{handlerId:I.getHandlerId()}},hover(I,f){var K;if(!l.current)return;const k=I.index,j=o;if(k===j)return;const a=(K=l.current)==null?void 0:K.getBoundingClientRect(),B=(a.bottom-a.top)/2,R=f.getClientOffset(),q=((R==null?void 0:R.y)??0)-a.top;k<j&&q<B||k>j&&q>B||(c(k,j),I.index=j)}}),[{isDragging:m},y]=$t.useDrag({type:hi,item:()=>({index:o}),collect:I=>({isDragging:I.isDragging()})});y(b(l));const D=()=>{const I=parseInt(u);if(isNaN(I)){x(i.toString()),d(t.name,i);return}const f=Math.max(go,Math.min(yo,I));x(f.toString()),d(t.name,f)},v=I=>{if(I===""||/^\d+$/.test(I)){x(I);const f=parseInt(I);if(!isNaN(f)&&f>=go){const k=Math.min(yo,f);d(t.name,k)}}},C=I=>{I.key==="Enter"&&(I.preventDefault(),D(),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:Je(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:D,onKeyDown:C,placeholder:"150",size:"small",inputProps:{min:go,max:yo,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"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=>T(I.palette.success.main,.12):"action.selected",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function iu({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:d="",onUpdateColumnVisibility:c,onUpdateColumnOrder:l,onUpdateColumnWidth:u,onResetLayout:x,onSaveToCurrentView:h,onSaveToAllViews:b,onSelectView:m,onClose:y}){const[D,v]=p.useState(!1),[C,S]=p.useState(n),[I,f]=p.useState(i),[k,j]=p.useState("all"),[a,B]=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=[...C],[se]=H.splice(F,1);H.splice(A,0,se),S(H),l(H)},K=()=>{x(),v(!1)},g=C.map(F=>t.find(A=>A.name===F)).filter(F=>F!==void 0).filter(F=>{const A=o[F.name]??!0;return k==="active"?A:k==="hidden"?!A:!0}),M=Object.values(o).filter(F=>F).length,W=t.length,V=s.find(F=>F.id===d),Z=s.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),se=F.columnOrder??[],G=n??[],re=JSON.stringify(G)!==JSON.stringify(se)&&!(G.length===0&&se.length===0),ae=F.columnWidths??{},ne=JSON.stringify(I)!==JSON.stringify(ae);return H||re||ne},[V,o,n,I]);return e.jsx($t.DndProvider,{backend:sn.HTML5Backend,children:e.jsx(r.Box,{onClick:y,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:F=>T(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=>Me(F),bgcolor:"background.paper",outline:"none",boxShadow:F=>te(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(dr,{content:ur.columns,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5},children:[M," 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=>B(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:a,open:!!a,onClose:()=>B(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:F=>te(F,"small")}},children:Z.map(F=>e.jsx(r.MenuItem,{onClick:()=>{m(F.id),B(null)},selected:F.id===d,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:A=>Pe(A),"&:hover":{bgcolor:A=>T(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:k,onChange:(F,A)=>j(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=>T(F.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:F=>T(F.palette.text.primary,.3)}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"background.paper",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${go}px, max: ${yo}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: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(nu,{column:F,index:A,isVisible:o[F.name]??!0,width:I[F.name]||170,onToggleVisibility:c,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=>te(F,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:F=>te(F,"hoverButton")},"&:active":{boxShadow:F=>te(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=>te(F,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:F=>te(F,"hoverButton")},"&:active":{boxShadow:F=>te(F,"pressedButton"),transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"text.disabled"}},children:"Save to all views"})]})]}),D&&e.jsx(r.Box,{onClick:()=>v(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:F=>T(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=>io(F),bgcolor:"background.paper",boxShadow:F=>te(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:K,variant:"contained",sx:{fontSize:"0.875rem",bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:F=>`${F.shape.borderRadius}px`,boxShadow:F=>te(F,"pressedButton"),"&:hover":{bgcolor:"error.dark",boxShadow:F=>te(F,"hoverButton")},"&:active":{boxShadow:F=>te(F,"pressedButton"),transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function su({schema:t,grouping:o,onApply:n,onClose:i}){var a;const[s,d]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[c,l]=p.useState(""),[u,x]=p.useState(null),h=p.useMemo(()=>ia(t),[t]),b=p.useMemo(()=>h.filter(B=>!s.levels.some((R,q)=>R.column===B.name&&q!==u)),[h,s.levels,u]),m=cr(),y=s.levels.length<m.grouping.maxLevels&&b.length>0,D=p.useCallback(()=>{!y||!c||(d({...s,levels:[...s.levels,{column:c}],enabled:!0}),l(""))},[y,c,s]),v=p.useCallback(B=>{const R=s.levels.filter((q,K)=>K!==B);if(R.length===0){n(null),i();return}d({...s,levels:R,enabled:R.length>0})},[s,n,i]),C=p.useCallback(B=>{x(B),l(s.levels[B].column)},[s.levels]),S=p.useCallback(()=>{if(u===null||!c)return;const B=[...s.levels];B[u]={column:c},d({...s,levels:B}),x(null),l("")},[u,c,s]),I=p.useCallback(()=>{x(null),l("")},[]),f=p.useCallback((B,R)=>{const q=R==="up"?B-1:B+1;if(q<0||q>=s.levels.length)return;const K=[...s.levels],[ee]=K.splice(B,1);K.splice(q,0,ee),d({...s,levels:K})},[s]),k=p.useCallback(()=>{n(null),i()},[n,i]),j=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:B=>T(B.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:B=>B.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:B=>B.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:B=>Me(B),bgcolor:"background.paper",outline:"none",boxShadow:B=>te(B,"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(dr,{content:ur.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:B=>T(B.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:B=>T(B.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:c,onChange:B=>l(B.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(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"action.hover"},"&.Mui-selected":{bgcolor:R=>Pe(R),"&:hover":{bgcolor:R=>T(R.palette.primary.main,.2)}}},children:[Je(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsx(r.Button,{onClick:D,disabled:!y||!c,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:B=>`1px solid ${T(B.palette.warning.main,.5)}`,bgcolor:B=>T(B.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:c,onChange:B=>l(B.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:B=>Pe(B)}},children:[s.levels[u].column," (",(a=t.find(B=>B.name===s.levels[u].column))==null?void 0:a.type.toUpperCase(),")"]}),b.filter(B=>B.name!==s.levels[u].column).map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:R=>Pe(R)}},children:[Je(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:S,disabled:!c,variant:"contained",fullWidth:!0,size:"small",sx:{fontSize:"0.875rem",bgcolor:"warning.main",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"warning.dark",boxShadow:B=>te(B,"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:k,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((B,R)=>{const q=t.find(K=>K.name===B.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"action.hover",borderColor:"divider",boxShadow:K=>te(K,"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:K=>`0 1px 2px 0 ${T(K.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:B.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===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:()=>C(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:K=>T(K.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:B=>`${B.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:s.levels.length===0,sx:{fontSize:"0.875rem",bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:B=>`${B.shape.borderRadius}px`,boxShadow:B=>te(B,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:B=>te(B,"hoverButton")},"&:active":{boxShadow:B=>te(B,"pressedButton"),transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const au={filters:z.FilterList,sorting:z.UnfoldMore,visibility:z.Visibility,order:z.ViewColumn,widths:z.Straighten,grouping:z.Layers};function lu({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=>te(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 d=au[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(d,{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=>te(i,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:i=>te(i,"hoverButton")},"&:active":{boxShadow:i=>te(i,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})}function cu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:s,onCancel:d}){const[c,l]=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 ${T(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:d,variant:"text",size:"small",sx:{fontSize:"0.875rem",px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:u=>T(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=>te(u,"restButton")}},children:"Save as new view"})]})]})}),c&&e.jsx(lu,{changes:n,onClose:()=>l(!1)})]})}function du({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 fi=[{key:"1h",label:"Last 1 Hour",ms:3600*1e3},{key:"24h",label:"Last 24 Hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 Days",ms:10080*60*1e3},{key:"30d",label:"Last 30 Days",ms:720*60*60*1e3},{key:"all",label:"All Time",ms:null}];function uu(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 pu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function xu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var D,v,C,S;const i=_t(),s=i.palette,[d,c]=p.useState("1h"),[l,u]=p.useState(!1),x=[...t].sort((I,f)=>new Date(f.timestamp).getTime()-new Date(I.timestamp).getTime()),h=fi.find(I=>I.key===d),b=uu(t,h.ms),m=()=>u(!0),y=()=>{n&&(n(pu(t,h.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:T(((D=s.common)==null?void 0:D.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 ${T(((v=s.common)==null?void 0:v.black)??"#000",.14)}, 0 2px 8px ${T(((C=s.common)==null?void 0:C.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,borderBottom:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),e.jsx(dr,{content:ur.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:d,onChange:I=>c(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:T(s.text.primary,.3)}},children:fi.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:T(s.error.main,.5),"&:hover":{bgcolor:T(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:T(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:T(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 f=Dd(i,I.feature),{summary:k,detail:j}=wa(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:T(s.text.primary,.18)}},children:[e.jsx(r.Chip,{label:Ia(I.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:T(f,.1),color:f,border:`1px solid ${T(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:k}),j&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:j}),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:za(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:io(i),boxShadow:`0 8px 32px ${T(((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:T(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: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 mu({onSave:t,onClose:o}){const[n,i]=p.useState(""),[s,d]=p.useState(""),[c,l]=p.useState(""),[u,x]=p.useState([]),[h,b]=p.useState(""),[m,y]=p.useState(""),D=j=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(j),v=()=>{const j=c.trim();if(j){if(!D(j)){y("Please enter a valid email address");return}if(u.includes(j)){y("This email is already added");return}x([...u,j]),l(""),y("")}},C=j=>{x(u.filter(a=>a!==j))},S=j=>{j.key==="Enter"&&(j.preventDefault(),v())},I=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),s.trim(),u.length>0?u:void 0)},f=j=>{i(j),h&&b("")},k=j=>{l(j),m&&y("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:j=>T(j.palette.common.black,.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:j=>j.zIndex.modal,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:j=>j.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:j=>Me(j),bgcolor:"background.paper",outline:"none",boxShadow:j=>te(j,"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:j=>T(j.palette.text.primary,.2),borderRadius:4,"&:hover":{bgcolor:j=>T(j.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:j=>`1px solid ${T(j.palette.primary.main,.3)}`,bgcolor:j=>Pe(j),"& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),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:j=>f(j.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:j=>d(j.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:c,onChange:j=>k(j.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:j=>`${j.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(j=>e.jsx(r.Chip,{label:j,onDelete:()=>C(j),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"}}}},j))}),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:j=>`${j.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:j=>`${j.shape.borderRadius}px`,boxShadow:j=>te(j,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:j=>te(j,"hoverButton")},"&:active":{boxShadow:j=>te(j,"pressedButton"),transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function hu({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=>T(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 fu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:s}){const[d,c]=p.useState(null),l=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=>T(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=>te(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=>T(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=>te(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=>T(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=>te(u,"restButton"),transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:u=>te(u,"hoverButton")},"&:active":{boxShadow:u=>te(u,"pressedButton"),transform:"translateY(1px)"}},children:"Close"})})]})})}const Qi={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},gu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],yu=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function bu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=yu.some(l=>l.test(i.name));let d=!1;const c=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);c.length>0&&(d=c.filter(u=>gu.some(x=>x.test(u))).length/c.length>.6),(s||d)&&n.push(i.name)}return n}function hn(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),s=o.map(c=>{const l=n.map(x=>String(x[c]??"")).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((c,l)=>c+l,0)+1;return o.reduce((c,l)=>c+l.length+1,0)+s*t.length}function vu(t,o){const n=hn(t,o);return Math.ceil(n*3.5)}function Su(t,o){const n=hn(t,o);return Math.ceil(n*.7)}function ju(t,o,n){switch(t){case"csv":return hn(o,n);case"excel":return Su(o,n);case"json":return vu(o,n)}}function gi(t,o){return Math.ceil(t/o)}function Cu(t,o,n,i,s=Qi){const d=[],c=ju(t,o,n),l=o.length;if(l>s.maxRowsHard){const h=gi(l,s.maxRows);d.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${s.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${h} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:s.maxRowsHard})}else if(l>s.maxRows){const h=gi(l,s.maxRows);d.push({type:"row_count",severity:"warning",message:`Large export: ${l.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${h} smaller export${h>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:s.maxRows})}if(c>s.maxFileSizeHardBytes?d.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${eo(c)} exceeds the ${eo(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:c,limit:s.maxFileSizeHardBytes}):c>s.maxFileSizeBytes&&d.push({type:"file_size",severity:"warning",message:`Large file: estimated ${eo(c)}`,detail:`This exceeds the recommended ${eo(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:c,limit:s.maxFileSizeBytes}),t!=="excel"){const h=bu(i.filter(b=>n.includes(b.name)),o);if(h.length>0){const b=h.length>s.maxImageColumns;d.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=d.some(h=>h.severity==="error"),x=d.some(h=>h.severity==="warning");return{violations:d,hasBlockingViolation:u,hasWarning:x,estimatedBytes:c}}function eo(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function wu({violation:t}){const n=_t().palette,i=t.severity==="error",s=i?n.error.main:n.warning.main,d=T(i?n.error.main:n.warning.main,.06),c=i?T(n.error.main,.25):T(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:d,border:"1px solid",borderColor:c},children:[e.jsx(l,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:t.message}),t.detail&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:t.detail}),t.suggestedBatches&&t.suggestedBatches>1&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[e.jsx(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 ku({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:d,sampleRows:c=[],allRows:l=[],processedRows:u=[],onExport:x,onClose:h}){var M,W,V;const b=_t(),m=b.palette,y=cr(),[D,v]=p.useState(y.export.allowedFormats[0]||"csv"),[C,S]=p.useState("visible"),[I,f]=p.useState("visible"),k=C==="visible"?o:t,j=I==="visible"?i:s,a=p.useMemo(()=>C==="visible"?u.length>0?u:new Array(o):l.length>0?l:new Array(t),[C,o,t,u,l]),B=p.useMemo(()=>I==="all"?d.map(Z=>Z.name):d.map(Z=>Z.name).slice(0,i),[I,d,i]),R=p.useMemo(()=>Cu(D,a,B,d,Qi),[D,a,B,d]),q=()=>{R.hasBlockingViolation||(x({format:D,scope:C,columnScope:I}),h())},K={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},ee={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},g={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:h,sx:{position:"fixed",inset:0,bgcolor:T(((M=m.common)==null?void 0:M.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 ${T(((W=m.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${T(((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(dr,{content:ur.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:T(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(wu,{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:D,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:{...ee,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:{...ee,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:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Rows"}),e.jsxs(r.RadioGroup,{value:C,onChange: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:{...ee,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:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Columns"}),e.jsxs(r.RadioGroup,{value: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:{...ee,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 ",s," columns (including hidden)"]})]}),sx:ee})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Divider,{sx:{mb:2}}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[{label:"Format",value:K[D]},{label:"Rows to export",value:k.toLocaleString()},{label:"Columns to export",value:String(j)},{label:"Estimated file size",value:eo(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:T(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 ",K[D]]})]})]})})}function Tu({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 Iu({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 d=(()=>{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}})}}})(),c=Pa(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:d.severity,icon:d.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${d.severity}.main`},children:e.jsx(z.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${d.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:c}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class zu extends p.Component{constructor(n){super(n);Sn(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){ar.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=>T(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=>T(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 Bu({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 Jr({children:t,feature:o,onError:n}){return e.jsx(zu,{context:o,onError:(i,s)=>{n&&n(i)},fallback:e.jsx(Bu,{feature:o}),children:t})}const Du=[{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"}],Eu=[{value:"csv",label:"CSV",desc:"Comma-separated values"},{value:"excel",label:"Excel (.xlsx)",desc:"Native Excel format"},{value:"json",label:"JSON",desc:"Structured data with metadata"}];function Kr({children:t,active:o}){return e.jsx(r.Box,{hidden:!o,sx:{pt:2.5,pb:1,display:o?"flex":"none",flexDirection:"column",gap:2.5},children:t})}function Ou({open:t,onClose:o,config:n,onApply:i}){const[s,d]=p.useState(0),[c,l]=p.useState(n),u=()=>l(n),x=()=>l(Ge),h=()=>{i(c),o()},b={sort:C=>l(S=>({...S,sort:{...S.sort,...C}})),filter:C=>l(S=>({...S,filter:{...S.filter,...C}})),columns:C=>l(S=>({...S,columns:{...S.columns,...C}})),grouping:C=>l(S=>({...S,grouping:{...S.grouping,...C}})),export:C=>l(S=>({...S,export:{...S.export,...C}}))},m=C=>{const S=c.filter.allowedOperators,I=S.includes(C)?S.filter(f=>f!==C):[...S,C];I.length!==0&&b.filter({allowedOperators:I})},y=C=>{const S=c.export.allowedFormats,I=S.includes(C)?S.filter(f=>f!==C):[...S,C];I.length!==0&&b.export({allowedFormats:I})},D=[{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=C=>JSON.stringify(c[C])===JSON.stringify(Ge[C]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:C=>Me(C),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:C=>`0 8px 32px ${T(C.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:C=>T(C.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem"},children:"⚙️"}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle1",sx:{fontWeight:600,lineHeight:1.2},children:"Developer Configuration"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"Set runtime constraints · Ctrl+Shift+D"})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary"},children:e.jsx(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:(C,S)=>d(S),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:D.map((C,S)=>e.jsx(r.Tab,{label:C.label,icon:C.icon,iconPosition:"start"},S))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Kr,{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:c.sort.maxLevels,onChange:(C,S)=>b.sort({maxLevels:S}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(Kr,{active: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:c.filter.maxConditions,onChange:(C,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(C=>e.jsxs(r.Box,{sx:{mb:1.5},children:[e.jsx(r.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:C}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:Du.filter(S=>S.group===C).map(S=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:c.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))})]},C))]})]}),e.jsxs(Kr,{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:c.columns.maxVisible,onChange:(C,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:c.columns.minColumnWidth,onChange:(C,S)=>b.columns({minColumnWidth:S}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:C=>`${C}px`})]}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),e.jsx(r.Slider,{value:c.columns.maxColumnWidth,onChange:(C,S)=>b.columns({maxColumnWidth:S}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:C=>`${C}px`})]})]})]})]}),e.jsxs(Kr,{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(C=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:C}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:c.grouping.maxLevels===C?"primary.main":"divider",bgcolor:c.grouping.maxLevels===C?S=>T(S.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:S=>T(S.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:c.grouping.maxLevels===C?"primary.main":"text.secondary"},children:C}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][C-1]})]},C))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:c.grouping.allowNested,onChange:C=>b.grouping({allowNested:C.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow nested groups"})}),e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:c.grouping.allowCollapse,onChange:C=>b.grouping({allowCollapse:C.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),e.jsx(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),e.jsx(Kr,{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:Eu.map(C=>e.jsxs(r.Box,{onClick:()=>y(C.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:c.export.allowedFormats.includes(C.value)?"primary.main":"divider",bgcolor:c.export.allowedFormats.includes(C.value)?S=>T(S.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:c.export.allowedFormats.includes(C.value),onChange:()=>y(C.value),onClick:S=>S.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:C.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:C.desc})]})]},C.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:C=>T(C.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:C=>T(C.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{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 $u=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Au={1:"1st",2:"2nd",3:"3rd",4:"4th",5:"5th",6:"6th",7:"7th",8:"8th",9:"9th",10:"10th",11:"11th",12:"12th",13:"13th",14:"14th",15:"15th",16:"16th",17:"17th",18:"18th",19:"19th",20:"20th",21:"21st",22:"22nd",23:"23rd",24:"24th",25:"25th",26:"26th",27:"27th",28:"28th"};function bo(t,o,n,i,s=new Date){const[d,c]=o.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(d,c,0,0),t==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const u=n??1,x=l.getDay();let h=u-x;return h<0&&(h+=7),h===0&&l<=s&&(h=7),l.setDate(l.getDate()+h),l.toISOString()}if(t==="monthly"){const u=Math.min(i??1,28);return l.setDate(u),l<=s&&(l.setMonth(l.getMonth()+1),l.setDate(u)),l.toISOString()}return l.toISOString()}function _u(t){const o=es(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${$u[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Au[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function es(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Mu(t){const o=new Date(t).getTime()-Date.now();if(o<=0)return"now";const n=Math.floor(o/1e3),i=Math.floor(n/86400),s=Math.floor(n%86400/3600),d=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${d}m`:d>0?`in ${d}m`:"in less than a minute"}function Ru(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=es(`${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 ts(t){return`urm_schedules_${t}`}function rs(t){try{const o=localStorage.getItem(ts(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 os(t,o){try{localStorage.setItem(ts(t),JSON.stringify(o))}catch{}}const Wu=[{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"}],Pu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ns={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},sr={"& .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 Nu({initial:t=ns,isEditing:o=!1,onSave:n,onBack:i}){const[s,d]=p.useState(t),[c,l]=p.useState(!1),[u,x]=p.useState(!1),h=(y,D)=>d(v=>({...v,[y]:D})),b=s.email.trim().length>0&&!Pu.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:y=>T(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:s.name,onChange:y=>{h("name",y.target.value),c&&y.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:c&&!s.name.trim(),helperText:c&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:sr}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:sr,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:s.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"})]})]}),s.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:sr,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:s.dayOfWeek,label:"Day of week",onChange:y=>h("dayOfWeek",Number(y.target.value)),children:Wu.map(y=>e.jsx(r.MenuItem,{value:y.value,children:y.label},y.value))})]}),s.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:y=>h("dayOfMonth",Number(y.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:sr}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.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:sr}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:sr,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:s.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:s.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:s.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:sr}),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=>T(y.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 Lu({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:i=>io(i),boxShadow:i=>{var s;return`0 8px 32px ${T(((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=>T(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 Fu({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:s,onDelete:d}){const c=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:c?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:c?l=>T(l.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:c?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:c?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:c?l=>T(l.palette.success.main,.1):l=>T(l.palette.text.primary,.06),color:c?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:_u(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=>T(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=>T(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=>T(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[c&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",Mu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Ru(t.lastRunAt)," · ",t.runCount," run",t.runCount!==1?"s":""]}):e.jsx(r.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[e.jsx(r.Tooltip,{title:"Edit",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>s(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>T(l.palette.primary.main,.08)}},children:e.jsx(z.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:c?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:c?"warning.main":"success.main","&:hover":{bgcolor:c?l=>T(l.palette.warning.main,.08):l=>T(l.palette.success.main,.08)}},children:c?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=>T(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:()=>d(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>T(l.palette.error.main,.08)}},children:e.jsx(z.Delete,{sx:{fontSize:15}})})})]})]})]})}function Vu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[d,c]=p.useState([]),[l,u]=p.useState({type:"list"}),[x,h]=p.useState(0),[b,m]=p.useState(null);p.useEffect(()=>{t&&(c(rs(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const B=setInterval(()=>h(R=>R+1),3e4);return()=>clearInterval(B)},[t]);const y=p.useCallback(B=>{c(B),os(n,B)},[n]),D=B=>{const R=bo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth),q={id:`sched-${Date.now()}`,reportId:n,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:R,runCount:0};y([...d,q]),u({type:"list"})},v=B=>{if(l.type!=="edit")return;const R=l.schedule,q=bo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth);y(d.map(K=>K.id===R.id?{...R,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,nextRunAt:q}:K)),u({type:"list"})},C=B=>{y(d.map(R=>{if(R.id!==B)return R;const q=R.isActive?R.nextRunAt:bo(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:q}}))},S=B=>{s(B);const R=new Date().toISOString();y(d.map(q=>q.id===B.id?{...q,lastRunAt:R,runCount:q.runCount+1}:q))},I=B=>{const R=d.find(q=>q.id===B)??null;m(R)},f=()=>{b&&(y(d.filter(B=>B.id!==b.id)),m(null))},k=B=>({name:B.name,frequency:B.frequency,dayOfWeek:B.dayOfWeek??1,dayOfMonth:B.dayOfMonth??1,time:B.time,format:B.format,scope:B.scope,email:B.email??""}),j=l.type!=="list",a=d.filter(B=>B.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:j,PaperProps:{sx:{borderRadius:B=>Me(B),maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:B=>T(B.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(dr,{content:ur.schedule,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",sx:{lineHeight:1},children:["· ",i]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary","&:hover":{bgcolor:B=>T(B.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:[j&&e.jsx(Nu,{initial:l.type==="edit"?k(l.schedule):ns,isEditing:l.type==="edit",onSave:l.type==="edit"?v:D,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:d.length===0?"No schedules yet":`${a} of ${d.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"})]}),d.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(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:d.map(B=>e.jsx(Fu,{schedule:B,tick:x,onToggle:C,onRunNow:S,onEdit:R=>u({type:"edit",schedule:R}),onDelete:I},B.id))})]})]}),l.type==="list"&&e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.25,borderTop:"1px solid",borderColor:"divider",flexShrink:0,display:"flex",alignItems:"center",gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75,px:1.25,py:.75,borderRadius:"8px",bgcolor:B=>T(B.palette.warning.main,.06),border:"1px solid",borderColor:B=>T(B.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:B=>T(B.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Lu,{scheduleName:b.name,onConfirm:f,onCancel:()=>m(null)})]})}const Hu=6e4;function Uu({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:d,columnVisibility:c,columnOrder:l,filters:u,sortStack:x,onFired:h}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:d,columnVisibility:c,columnOrder:l,filters:u,sortStack:x,onFired:h});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:d,columnVisibility:c,columnOrder:l,filters:u,sortStack:x,onFired:h}});const m=p.useCallback(y=>{var B,R;const{reportName:D,uploadedData:v,processedData:C,schema:S,activeView:I,columnVisibility:f,columnOrder:k,filters:j,sortStack:a}=b.current;try{const q=y.scope==="all"?v:C,K=vo(q,S,j,a,I,f,k),ee=`${y.name}_scheduled`;switch(y.format){case"csv":So(K,ee,{scope:y.scope});break;case"excel":jo(K,ee,{scope:y.scope});break;case"json":Co(K,ee,{scope:y.scope});break}if(y.email){const g=encodeURIComponent(`Scheduled Report: ${y.name}`),M=encodeURIComponent(`Your scheduled report "${y.name}" has been generated.
90
90
 
91
- Report: ${B}
91
+ Report: ${D}
92
92
  Format: ${y.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:${y.email}?subject=${g}&body=${M}`,"_blank")}(R=(B=b.current).onFired)==null||R.call(B,y)}catch(q){ar.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 C=rs(v),S=new Date;let I=!1;const f=C.map(k=>{if(!k.isActive)return k;if(new Date(k.nextRunAt)<=S){m(k);const a=bo(k.frequency,k.time,k.dayOfWeek,k.dayOfMonth,S);return I=!0,{...k,lastRunAt:S.toISOString(),nextRunAt:a,runCount:k.runCount+1}}return k});I&&os(v,f)};y();const D=setInterval(y,Hu);return()=>clearInterval(D)},[t,m])}function is({reportEngine:t}){var jr,Cr,wr,or,kr;const{activeReport:o,paginatedData:n,processedData:i,tableMetrics:s,tableEngine:d,activeView:c,isDirty:l,currentTableState:u,viewChanges:x,showFilterPanel:h,setShowFilterPanel:b,filterFocusColumn:m,handleAddFilter:y,handleUpdateFilter:D,handleRemoveFilter:v,handleClearAllFilters:C,handleReplaceFilters:S,handleOpenFilterForColumn:I,handleCloseFilterPanel:f,handleClearFiltersForColumn:k,showSortPanel:j,setShowSortPanel:a,handleSort:B,handleUpdateSortStack:R,handleSortAscending:q,handleSortDescending:K,showManageViews:ee,setShowManageViews:g,showCreateViewModal:M,setShowCreateViewModal:W,showEditViewModal:V,setShowEditViewModal:Z,showDeleteConfirmation:xe,setShowDeleteConfirmation:me,editingView:F,deletingView:A,handleSelectView:H,handleCreateView:se,handleUpdateCurrentView:G,handleSaveColumnConfigToCurrentView:re,handleSaveColumnConfigToAllViews:ae,handleSaveAsNewView:ne,handleRevertChanges:P,handleToggleDefault:ie,handleToggleFavorite:de,handleSoftDelete:le,handleRestoreView:fe,handlePermanentDelete:J,handleEditView:Re,handleSaveEditView:He,handleConfirmDelete:St,handlePromoteToGlobal:Mt,showManageColumns:pr,setShowManageColumns:Gt,handleUpdateColumnVisibility:pt,handleUpdateColumnOrder:Rt,handleUpdateColumnWidth:ze,handleResetColumnLayout:Xe,showGroupPanel:jt,setShowGroupPanel:ot,handleGroup:Le,handleToggleGroupCollapse:nt,searchQuery:Ct,searchHistory:Ze,handleSearchChange:it,handleAddToSearchHistory:We,handleToggleSearchFavourite:$r,handleDeleteSearchHistory:xr,selectedRowIds:mr,handleToggleRowSelection:qt,handleToggleAllRows:st,handleRangeSelection:Wt,handleClearSelection:hr,handleUpdateSelectionAfterDelete:wt,currentPage:fr,pageSize:Ar,paginationEngine:Ue,handlePageChange:Jt,handlePageSizeChange:gr,isExporting:Ie,showExportModal:Kt,setShowExportModal:_r,showDirtyExportWarning:at,handleExport:L,handleExportWithConfig:lt,handleExportSelected:ye,handleExportAnyway:Ye,handleSaveAndExport:Pt,handleCancelExport:Mr,showAuditHistory:xt,setShowAuditHistory:Xt,showCreatePreset:kt,setShowCreatePreset:yr,showManagePresets:br,setShowManagePresets:Rr,activePreset:De,handleCreatePreset:Q,handleClearActivePreset:ct,handleOpenPresetById:Te,handleDeletePresetById:Zt,isViewerRole:be,userRole:Qe,featureLimitWarning:Qt,setFeatureLimitWarning:mt,reportError:Fe,setReportError:vr,handleError:Tt,updateReport:dt,showSnack:It,favoriteRowIndices:Wr,resolvedFavoritesSet:er,showFavoritesOnly:tr,handleToggleRowFavorite:Nt,handleBulkSetFavorites:Sr,handleToggleFavoritesFilter:Ne}=t,[ht,zt]=p.useState(!1);Uu({reportId:o==null?void 0:o.id,reportName:(o==null?void 0:o.name)||"Report",uploadedData:(o==null?void 0:o.uploadedData)||[],processedData:i||[],schema:(o==null?void 0:o.schema)||[],activeView:c,columnVisibility:(o==null?void 0:o.columnVisibility)||((jr=c==null?void 0:c.snapshot)==null?void 0:jr.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((Cr=c==null?void 0:c.snapshot)==null?void 0:Cr.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:ue=>{It(`Scheduled export "${ue.name}" completed`,"success")}});const Lt=p.useCallback((ue,ce)=>{if(!(o!=null&&o.uploadedData))return;const Ee=[...o.uploadedData];Ee[ue]=ce,dt(o.id,{uploadedData:Ee})},[o,dt]),Pr=p.useCallback(ue=>{if(!(o!=null&&o.uploadedData))return;const ce=o.uploadedData.indexOf(ue);if(ce===-1)return;const Ee=o.uploadedData.filter((et,Bt)=>Bt!==ce),ut=(o.favoriteRowIndices||[]).filter(et=>et!==ce).map(et=>et>ce?et-1:et);dt(o.id,{uploadedData:Ee,favoriteRowIndices:ut}),wt(ue)},[o,dt,wt]),Nr=p.useCallback((ue,ce)=>{if(!(o!=null&&o.uploadedData))return;const Ee=o.uploadedData.indexOf(ce),ut=Ee!==-1?Ee+1:ue+1,et=[...o.uploadedData];et.splice(ut,0,{...ce});const Vr=(o.favoriteRowIndices??[]).map(Vt=>Vt>=ut?Vt+1:Vt);dt(o.id,{uploadedData:et,favoriteRowIndices:Vr})},[o,dt]),Ft=cr(),{handleDevConfigChange:Lr}=zo(),[Fr,rr]=p.useState(!1);return p.useEffect(()=>{const ue=ce=>{ce.ctrlKey&&ce.shiftKey&&ce.key==="D"&&(ce.preventDefault(),rr(!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:[!be&&l&&c&&e.jsx(cu,{viewName:c.name,isDefaultView:c.isDefault,changes:x,onSaveToCurrentView:c.isDefault?void 0:G,onSaveAsNewView:ne,onCancel:P}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[Qt&&e.jsx(Tu,{warning:Qt,onDismiss:()=>mt(null)}),Fe&&e.jsx(Iu,{error:Fe,onDismiss:()=>vr(null)}),at&&e.jsx(du,{onExportAnyway:Ye,onSaveAndExport:Pt,onCancel:Mr}),e.jsx(Zd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:l,isExporting:Ie,columnVisibility:o.columnVisibility||(c==null?void 0:c.snapshot.columnVisibility),columnOrder:o.columnOrder||(c==null?void 0:c.snapshot.columnOrder),columnWidths:o.columnWidths||(c==null?void 0:c.snapshot.columnWidths),grouping:o.grouping,onSort:B,onSortAscending:q,onSortDescending:K,onOpenFilters:()=>b(!0),onOpenSort:()=>a(!0),onOpenFilterForColumn:I,onSelectView:H,onCreateView:()=>W(!0),onManageViews:()=>g(!0),onUpdateCurrentView:G,onSaveAsNewView:ne,onToggleDefault:ie,onToggleFavorite:de,onRestoreView:fe,onPermanentDelete:J,onExport:L,onOpenColumns:()=>Gt(!0),onUpdateColumnWidth:ze,onUpdateColumnOrder:Rt,onUpdateColumnVisibility:pt,onClearFiltersForColumn:k,onResetLayout:Xe,onOpenGroup:()=>ot(!0),onGroupByColumn:ue=>{Le({enabled:!0,column:ue,showCounts:!0})},onToggleGroupCollapse:nt,onOpenAuditHistory:()=>Xt(!0),onOpenScheduledReports:()=>zt(!0),searchQuery:Ct,searchHistory:Ze,onAddToSearchHistory:We,onToggleSearchFavourite:$r,onDeleteSearchHistory:xr,selectedRowIds:mr,onSearchChange:it,onToggleRowSelection:qt,onToggleAllRows:st,onRangeSelection:Wt,onClearSelection:hr,onExportSelected:ye,currentPage:(Ue==null?void 0:Ue.currentPage)||fr,pageSize:(Ue==null?void 0:Ue.pageSize)||Ar,onPageChange:Jt,onPageSizeChange:gr,totalRowsBeforePagination:(s==null?void 0:s.searchedRows)||i.length,isReadOnly:be,userRole:Qe,reportName:o.name,onEditRow:Lt,onDeleteRow:Pr,onDuplicateRow:Nr,favoriteRowIndices:Wr,resolvedFavoritesSet:er,showFavoritesOnly:tr,onToggleRowFavorite:Nt,onBulkSetFavorites:Sr,onToggleFavoritesFilter:Ne,showDevPanel:Ft.display.showDevPanel,onOpenDevConfig:()=>rr(!0)})]}),h&&e.jsx(Jr,{feature:"Filters",onError:ue=>{const ce=Ot("ui","filters",ue);Tt(ce)},children:e.jsx(Qd,{schema:o.schema,filters:o.filters??[],onAddFilter:y,onUpdateFilter:D,onRemoveFilter:v,onClearAll:C,onReplaceFilters:S,onClose:f,focusColumn:m})}),j&&e.jsx(Jr,{feature:"Sorting",onError:ue=>{const ce=Ot("ui","sorting",ue);Tt(ce)},children:e.jsx(tu,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:R,onClose:()=>a(!1)})}),ee&&e.jsx(Jr,{feature:"Views",onError:ue=>{const ce=Ot("ui","views",ue);Tt(ce)},children:e.jsx(ru,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:H,onCreateView:()=>{g(!1),W(!0)},onEditView:Re,onDeleteView:le,onRestoreView:fe,onPermanentDelete:J,onPromoteToGlobal:Mt,isAdmin:((wr=Ft.views)==null?void 0:wr.isAdmin)??!1,onClose:()=>g(!1)})}),M&&u&&(()=>{var Ee;const ue=(o.views??[]).filter(ut=>!ut.isDeleted).length,ce=((Ee=Ft.views)==null?void 0:Ee.maxViews)??10;return e.jsx(mi,{currentSnapshot:u,onSave:se,onClose:()=>W(!1),atViewLimit:ue>=ce,maxViews:ce})})(),V&&F&&e.jsx(mi,{currentSnapshot:F.snapshot,onSave:He,onClose:()=>{Z(!1)},isEditMode:!0,initialName:F.name,initialDescription:F.description,initialIsDefault:F.isDefault}),xe&&A&&e.jsx(ou,{viewName:A.name,onConfirm:St,onCancel:()=>{me(!1)}}),pr&&c&&e.jsx(iu,{schema:o.schema,columnVisibility:o.columnVisibility||c.snapshot.columnVisibility,columnOrder:o.columnOrder||c.snapshot.columnOrder,columnWidths:o.columnWidths||c.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:pt,onUpdateColumnOrder:Rt,onUpdateColumnWidth:ze,onResetLayout:Xe,onSelectView:ue=>{H(ue)},onSaveToCurrentView:ue=>{re(ue),Gt(!1)},onSaveToAllViews:ue=>{ae(ue),Gt(!1)},onClose:()=>Gt(!1)}),jt&&e.jsx(Jr,{feature:"Grouping",onError:ue=>{const ce=Ot("ui","grouping",ue);Tt(ce)},children:e.jsx(su,{schema:o.schema,grouping:o.grouping||null,onApply:Le,onClose:()=>ot(!1)})}),xt&&e.jsx(xu,{auditHistory:o.auditHistory||[],onClose:()=>Xt(!1)}),kt&&e.jsx(mu,{onSave:Q,onClose:()=>yr(!1)}),br&&e.jsx(fu,{presets:o.presets||[],reportId:o.id,onOpenPreset:Te,onDeletePreset:Zt,onClose:()=>Rr(!1)}),De&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(hu,{presetName:De.name,onClear:ct})}),Kt&&e.jsx(Jr,{feature:"Export",onError:ue=>{const ce=Ot("ui","export",ue);Tt(ce)},children:e.jsx(ku,{totalRows:(s==null?void 0:s.totalRows)||((or=o.uploadedData)==null?void 0:or.length)||0,visibleRows:(s==null?void 0:s.searchedRows)||i.length,visibleColumnsCount:((kr=d==null?void 0:d.columnEngine)==null?void 0:kr.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:lt,onClose:()=>{_r(!1)}})}),o&&e.jsx(Vu,{open:ht,onClose:()=>zt(!1),reportId:o.id,reportName:o.name,onRunNow:ue=>{const ce=ue.scope==="all"?o.uploadedData||[]:i||[],Ee=vo(ce,o.schema||[],o.filters||[],o.sortStack||[],c,o.columnVisibility,o.columnOrder);ue.format==="csv"&&So(Ee,ue.name),ue.format==="excel"&&jo(Ee,ue.name),ue.format==="json"&&Co(Ee,ue.name),It(`"${ue.name}" exported successfully`,"success")}}),e.jsx(Ou,{open:Fr,onClose:()=>rr(!1),config:Ft,onApply:Lr})]})}const Yu={error:"err",warning:"warn",info:"info",success:"suc"};function ss({open:t,message:o,severity:n,onClose:i,autoHideDurationMs:s}){var I,f;const d=r.useTheme(),c=d.tokens,l=(c==null?void 0:c.notifPosition)??"top-right",u=(c==null?void 0:c.notifStyle)??"toast",x=(c==null?void 0:c.notifAccent)??"severity",h=(c==null?void 0:c.notifAutoDismiss)??!0,b=(c==null?void 0:c.toastW)??252,m=l.startsWith("top")?"top":"bottom",y=l.endsWith("center")?"center":l.endsWith("left")?"left":"right",D=Yu[n],v=((I=c==null?void 0:c.status)==null?void 0:I[`${D}Soft`])??d.palette[n].light,C=((f=c==null?void 0:c.status)==null?void 0:f[`${D}Txt`])??d.palette[n].dark,S=x==="primary"?d.palette.primary.main:x==="mono"?d.palette.text.secondary:C;return e.jsx(r.Snackbar,{open:t,autoHideDuration:h?s??2e3:void 0,onClose:(k,j)=>{j!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:m,horizontal:y},children:e.jsx(r.Alert,{severity:n,icon:!1,onClose:h?void 0:i,sx:{width:b,alignItems:"flex-start",bgcolor:v,color:C,boxShadow:u==="inline"?"none":(c==null?void 0:c.cardShadow)??3,border:u==="inline"?"1px solid":u==="toast"?(c==null?void 0:c.cardBorder)??"1px solid":"none",borderColor:"divider",borderLeft:u==="banner"?`4px solid ${S}`:void 0,borderRadius:`${d.shape.borderRadius}px`},children:o})})}function as({hasExternalData:t=!1}){const o=zo(),{reports:n,activeReportId:i,activeReport:s,uploadState:d,hasSchemaConflicts:c,isModalOpen:l,setIsModalOpen:u,setActiveReportId:x,createReport:h,handleFileUpload:b,handleUploadError:m,handleRetry:y,handleConfirm:D,snack:v,handleSnackClose:C,snackDurationMs:S}=o,I=t&&d==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(sl,{onCreateReport:()=>u(!0),reports:n,activeReportId:i,onReportClick:x}),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(Xi,{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(is,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:d==="preview"&&s.schema&&s.uploadedData?e.jsx(bd,{schema:s.schema,onConfirm:D,hasConflicts:c}):s.uploadError?e.jsx(vd,{error:s.uploadError,onRetry:y}):e.jsx(yd,{onFileUpload:b,onError:m,isUploading:d==="uploading"})})}):null}),!t&&e.jsx(gd,{isOpen:l,onClose:()=>u(!1),onCreate:h}),e.jsx(ss,{open:v.open,message:v.message,severity:v.severity,onClose:C,autoHideDurationMs:S})]})}function Gu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(cn,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(as,{hasExternalData:!!(t||o)})})}function ls(){const t=zo(),{snack:o,handleSnackClose:n,snackDurationMs:i}=t;return e.jsxs(r.Box,{sx:{minHeight:"100vh"},children:[e.jsx(r.Box,{component:"main",children:t.activeReport?e.jsx(is,{reportEngine:t}):e.jsx(Xi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(ss,{open:o.open,message:o.message,severity:o.severity,onClose:n,autoHideDurationMs:i})]})}function qu({data:t,autoLoad:o=!0,config:n}){return e.jsx(cn,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(ls,{})})}exports.URMBuilder=Gu;exports.URMBuilderRaw=as;exports.URMProvider=cn;exports.URMViewer=qu;exports.URMViewerRaw=ls;exports.useURMContext=zo;