dts-universal-report-module 1.0.7 → 1.0.9

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 +5707 -5462
  2. package/dist/index.js +25 -25
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,25 +1,25 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),ks=require("xlsx"),k=require("@mui/icons-material"),r=require("@mui/material"),di=require("react-dom"),Ts=require("@emotion/react"),wt=require("react-dnd"),Xo=require("react-dnd-html5-backend");function ui(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 fo=ui(p),Qr=ui(ks),Ue={sort:{maxLevels:5},filter:{maxConditions:10,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}},pi="urm_dev_config";function Is(){try{const t=localStorage.getItem(pi);if(!t)return Ue;const o=JSON.parse(t),n={sort:{...Ue.sort,...o.sort},filter:{...Ue.filter,...o.filter},columns:{...Ue.columns,...o.columns},grouping:{...Ue.grouping,...o.grouping},export:{...Ue.export,...o.export},views:{...Ue.views,...o.views},dates:{...Ue.dates,...o.dates},display:{...Ue.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ue}}function zs(t){try{localStorage.setItem(pi,JSON.stringify(t))}catch{}}function Es(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 xi=p.createContext(Ue);function Gt(){return p.useContext(xi)}const Bs=/^\d{4}-\d{2}-\d{2}$/,Ds=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Os=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,As=9783072e5,Ms=41024448e5,_s=978307200,$s=4102444800;function Ws(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=As&&t<=Ms?"timestamp_ms":Number.isInteger(t)&&t>=_s&&t<=$s?"timestamp_s":"unknown":typeof t!="string"?"unknown":Ds.test(t)||Bs.test(t)?"iso":Os.test(t.trim())?"locale_string":"unknown"}function Rs(t,o){const n=o.map(d=>d[t]).filter(d=>d!=null&&d!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const d of n){const l=Ws(d);i[l]++}const s=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/s>=c)return d;return"unknown"}function Ps(t,o){if(t==null||t==="")return null;try{switch(o){case"timestamp_ms":{const n=new Date(Number(t));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(t)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const mn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ns=["January","February","March","April","May","June","July","August","September","October","November","December"];function Oe(t){return String(t).padStart(2,"0")}function Ls(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),c=Math.floor(s/60),d=Math.floor(c/60),l=Math.floor(d/24),u=Math.floor(l/7),m=Math.floor(l/30),h=Math.floor(l/365);let b;return s<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:u<5?b=`${u} week${u!==1?"s":""}`:m<12?b=`${m} month${m!==1?"s":""}`:b=`${h} year${h!==1?"s":""}`,s<60?b:i?`${b} ago`:`in ${b}`}function Fs(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${Oe(i+1)}-${Oe(s)}`;case"DD/MM/YYYY":return`${Oe(s)}/${Oe(i+1)}/${n}`;case"MM/DD/YYYY":return`${Oe(i+1)}/${Oe(s)}/${n}`;case"MMM DD, YYYY":return`${mn[i]} ${Oe(s)}, ${n}`;case"DD MMM YYYY":return`${Oe(s)} ${mn[i]} ${n}`;case"MMMM D, YYYY":return`${Ns[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Oe(i+1)}-${Oe(s)} ${Oe(c)}:${Oe(d)}`;case"DD/MM/YYYY HH:mm":return`${Oe(s)}/${Oe(i+1)}/${n} ${Oe(c)}:${Oe(d)}`;case"MM/DD/YYYY HH:mm":return`${Oe(i+1)}/${Oe(s)}/${n} ${Oe(c)}:${Oe(d)}`;case"relative":return Ls(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Vs(t,o,n){if(!n||o==="unknown")return String(t);const i=Ps(t,o);return!i||isNaN(i.getTime())?String(t):Fs(i,n)}function Hs(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 mi(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const c=o?`${o}.${s}`:s,d=t[s];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,mi(d,c,n+1)):i[c]=d}return i}function ao(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:mi(o))}function Wr(t){if(!Array.isArray(t)||t.length===0)return[];const o=ao(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let u=0;o.forEach(f=>{typeof f=="object"&&f!==null&&d in f&&(u++,l.add(Hs(f[d])))});const m=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 f=Array.from(l).filter(g=>g!=="null");f.length===1&&(b=f[0])}i.push({name:d,type:b,required:m,hasConflict:h})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Rs(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Us(t){return t.some(o=>o.hasConflict)}function Ge(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function fn(t){return t==null}function Ys(t){return(o,n,i)=>{const s=fn(o),c=fn(n);if(s&&c)return 0;if(s)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 Gs(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,c)=>s.priority-c.priority);return[...t].sort((s,c)=>{for(const d of i){const l=o.find(h=>h.name===d.column);if(!l)continue;const m=Ys(l.type)(s[d.column],c[d.column],d.direction);if(m!==0)return m}return 0})}function qs(t){return t===null?"asc":t==="asc"?"desc":null}function Js(t){return t==="string"||t==="boolean"}function Ks(t){return t.filter(o=>Js(o.type))}function Xs(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(c=>c[i.name]).filter(c=>typeof c=="number");s.length>0&&(n[i.name]=s.reduce((c,d)=>c+d,0))}}),n}function Zs(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=fi(t,n.levels,o);return hi(i,n.collapsedGroups||[])}function fi(t,o,n,i="",s=0){if(s>=o.length)return t;const c=o[s].column,d=new Map;t.forEach(m=>{const h=m[c],b=h==null?"(empty)":String(h);d.has(b)||d.set(b,[]),d.get(b).push(m)});const l=[];return Array.from(d.keys()).sort().forEach(m=>{const h=d.get(m),b=`${c}:${m}`,f=i?`${i}|${b}`:b,g=Xs(h,n),T=s<o.length-1?fi(h,o,n,f,s+1):h,y={key:f,level:s,column:c,value:m,rowCount:h.length,aggregates:g,children:T};l.push(y)}),l}function hi(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&&hi(i.children,o,n)}else n.push(i);return n}function Qs(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function gi(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function yi(t,o,n){return`${o}: ${n}`}function Fr(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 bi(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),s=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(s);let u=0;for(const m of n)d.has(m)?c.push(m):l.has(m)&&u<s.length?(c.push(s[u]),u++):l.has(m)||c.push(m);for(let m=u;m<s.length;m++)c.includes(s[m])||c.push(s[m]);return c}return[...t]}function Mo(t){const o={},n=[],i={};return t.forEach(s=>{o[s.name]=!0,n.push(s.name),i[s.name]=150}),{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 ea(t,o,n,i,s,c,d,l){const u={},m=[],h={};n.forEach(g=>{u[g.name]=!0,m.push(g.name),h[g.name]=150});const f=bi(s||m,d||null,l||m);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:f,columnWidths:c||h,grouping:d||null}}function ta(t,o){const n=u=>{if(u==null)return u;if(Array.isArray(u))return u.map(m=>n(m));if(typeof u=="object"){const m={};return Object.keys(u).sort().forEach(h=>{m[h]=n(u[h])}),m}return u},i=u=>JSON.stringify(n(u));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack)||i(t.columnVisibility)!==i(o.columnVisibility))return!0;const s=[...t.columnOrder||[]].sort().join(","),c=[...o.columnOrder||[]].sort().join(",");if(s!==c)return!1;const d=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==d){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const u=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==u)return!0}return i(t.columnWidths)!==i(o.columnWidths)||i(t.grouping)!==i(o.grouping)}function ra(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function oa(t,o){var y,w,v;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const j=t.filters.length,S=o.filters.length;j>S?n.push({category:"filters",label:"Filters Added",description:`${j-S} new filter${j-S>1?"s":""} added`}):j<S?n.push({category:"filters",label:"Filters Removed",description:`${S-j} filter${S-j>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 j=t.sortStack.length,S=o.sortStack.length;j>S?n.push({category:"sorting",label:"Sorting Added",description:`${j-S} new sort rule${j-S>1?"s":""} added`}):j<S?n.push({category:"sorting",label:"Sorting Removed",description:`${S-j} sort rule${S-j>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 j=Object.values(t.columnVisibility).filter(I=>I).length,S=Object.values(o.columnVisibility).filter(I=>I).length;j>S?n.push({category:"visibility",label:"Columns Shown",description:`${j-S} column${j-S>1?"s":""} made visible`}):j<S?n.push({category:"visibility",label:"Columns Hidden",description:`${S-j} column${S-j>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const m=JSON.stringify(t.columnOrder),h=JSON.stringify(o.columnOrder);m!==h&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),f=JSON.stringify(o.columnWidths);if(b!==f){const j=Object.keys(t.columnWidths).filter(S=>t.columnWidths[S]!==o.columnWidths[S]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${j} column width${j>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),T=JSON.stringify(o.grouping);if(g!==T){const j=(y=t.grouping)==null?void 0:y.enabled,S=(w=o.grouping)==null?void 0:w.enabled;if(j&&!S){const I=((v=t.grouping)==null?void 0:v.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${I} grouping level${I>1?"s":""} added`})}else!j&&S?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function hn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function gn(t){return`[${t}]`}const Ut={warn(t,o,...n){hn()&&console.warn(gn(t),o,...n)},error(t,o,...n){hn()&&console.error(gn(t),o,...n)}},vi="urm_report_";function na(t,o){try{const n=`${vi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){Ut.error("urm:persistence","Failed to save report state",n)}}function ia(t){try{const o=`${vi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return Ut.error("urm:persistence","Failed to load report state",o),null}}function ho(t,o,n=0){const i=[];for(const s of t){const c=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:c}),!c&&s.children&&s.children.length>0){const d=s.children[0];if(sa(d)){const l=s.children,u=ho(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 sa(t){return t&&typeof t=="object"&&"key"in t&&"level"in t&&"column"in t&&"value"in t&&"rowCount"in t&&"aggregates"in t&&"children"in t}function Zo(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function Qo(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${s}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function co(t,o,n,i,s,c,d){let l,u;c?(l={...c},u=d||o.map(h=>h.name)):s?(l={...s.snapshot.columnVisibility},u=d||[...s.snapshot.columnOrder]):(l={},u=[],o.forEach(h=>{l[h.name]=!0,u.push(h.name)}));const m=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:m,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function uo(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=ho(i);l=Zo(b)}else l=i;const u=d.join(","),m=l.map(b=>d.map(f=>{const g=b[f];if(g==null)return"";const T=String(g);return T.includes(",")||T.includes('"')||T.includes(`
2
- `)?`"${T.replace(/"/g,'""')}"`:T}).join(",")),h=[u,...m].join(`
3
- `);Si(h,Qo(o,"csv"),"text/csv;charset=utf-8;")}function po(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=ho(i);l=Zo(b)}else l=i;const u=[d,...l.map(b=>d.map(f=>b[f]??""))],m=Qr.utils.aoa_to_sheet(u),h=Qr.utils.book_new();Qr.utils.book_append_sheet(h,m,"Data"),Qr.writeFile(h,Qo(o,"xlsx"))}function xo(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:u,grouping:m}=t;let h;if(m&&m.enabled){const g=ho(i);h=Zo(g)}else h=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:s.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:m||{},hiddenColumns:l,columnOrder:u,exportConfig:n||{scope:"visible"}},data:h},f=JSON.stringify(b,null,2);Si(f,Qo(o,"json"),"application/json;charset=utf-8;")}function Si(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),c=document.createElement("a");c.href=s,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s)}const yn=10;function aa(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.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>yn&&(s=[...s].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,yn)),s}function la(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ca(t,o){return t.filter(n=>n.query!==o)}function da(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 ua={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 pa(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function pt(t,o){return ua[o].includes(t)}function xt(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 xa(t){return t==="viewer"}const bn=1e3;function Uo(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function ht(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Uo(n)}const ma={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 _o(t){if(!t||!t.column)return"a filter";const o=ht(t.column),n=ma[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function vn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${ht(n.column)}"`).join(", ")}`}function fa(t){var s,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: ${_o(l)}`}}case"filter_removed":return{summary:`Filter removed: ${_o(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 "${ht(u==null?void 0:u.column)}"`,detail:`Previously filtered "${ht(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${_o(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?ht(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?ht(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${vn(i)}`};case"group_level_removed":{const l=n,u=(c=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&c.column?ht(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${vn(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${ht(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${ht(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: "${ht(l)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return l&&u?{summary:`Switched to view "${u}"`,detail:`From "${l}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,m=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",h=(i==null?void 0:i.viewName)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:h?`${Uo(m)} · View: "${h}"`:Uo(m)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&u?{summary:`Theme changed from "${l}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:ga(o)}}}function ha(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function ji(t,o,n,i,s,c){return{id:ha(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:c}}function Ci(t,o){const n=[o,...t];return n.length>bn?n.slice(0,bn):n}function ga(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 ya(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function ba(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function va(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:c<24?`${c} hour${c>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const Sn=100;function Sa(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function ja(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||[],s=bi(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 Ca(t,o,n,i){return{id:Sa(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function wa(t,o){const n=t||[];if(n.length>=Sn)throw new Error(`Maximum of ${Sn} presets reached. Please delete old presets first.`);return[...n,o]}function ka(t,o){return(t||[]).filter(i=>i.id!==o)}function jn(t,o){if(t)return t.find(n=>n.id===o)}function Ta(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Ia(t){const o=t.columnOrder,n=Fr(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 za(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ea={MAX_CACHE_ENTRIES:3};function Ba(t,o){let n=null;return function(...s){const c=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(c,o)}}class eo{constructor(o=Ea.MAX_CACHE_ENTRIES){this.cache=new Map,this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const s=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];s&&this.cache.delete(s)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Da{constructor(){this.metrics=new Map}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),s=this.end(o);return{result:i,duration:s}}async measureAsync(o,n){this.start(o);const i=await n(),s=this.end(o);return{result:i,duration:s}}}function Ct(t,o,n,i){const s=n instanceof Error?n.message:n,c={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:Oa(t,o)};return process.env.NODE_ENV==="development"&&Ut.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),c}function Oa(t,o){return t==="ui"||t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Aa(t){const n={filters:"There was an issue applying filters",sorting:"Sorting could not be applied",grouping:"Grouping configuration failed",columns:"Column configuration could not be updated",views:"View operation failed",presets:"Preset could not be applied",export:"Export failed",upload:"File upload failed",search:"Search operation failed"}[t.context]||"An error occurred";return t.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function Ma(t){return{filters:t.filters?[...t.filters]:void 0,sortStack:t.sortStack?[...t.sortStack]:void 0,grouping:t.grouping?{...t.grouping}:void 0,columnVisibility:t.columnVisibility?{...t.columnVisibility}:void 0,columnOrder:t.columnOrder?[...t.columnOrder]:void 0,columnWidths:t.columnWidths?{...t.columnWidths}:void 0,activeViewId:t.activeViewId}}function _a(t,o,n){n(t.id,{filters:o.filters,sortStack:o.sortStack,grouping:o.grouping,columnVisibility:o.columnVisibility,columnOrder:o.columnOrder,columnWidths:o.columnWidths,activeViewId:o.activeViewId})}function $a(t,o,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(o)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:t==="number"&&["gt","gte","lt","lte","equals"].includes(o)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:t==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function wi(t,o){const n=[],i=[],s=new Set(o.map(c=>c.name));return t.forEach(c=>{s.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function ki(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],s=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):s.push(c.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...t,levels:i},invalidColumns:s}}function Wa(t,o){const n=[],i=new Set(o.map(c=>c.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const c=s.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});s.filters=c.length>0?c:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:c,invalidColumns:d}=wi(s.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),s.sortStack=c.length>0?c:void 0}if(s.grouping){const{validGrouping:c,invalidColumns:d}=ki(s.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),s.grouping=c}if(s.columnVisibility){const c={};Object.entries(s.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),s.columnVisibility=Object.keys(c).length>0?c:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const c=s.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});s.columnOrder=c.length>0?c:void 0}if(s.columnWidths){const c={};Object.entries(s.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),s.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:s,warnings:n}}function Ra(t,o){return Ct("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function Cn(t,o,n,i){const s=ji(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Ci(i||[],s)}function Pa(t){return t==null}function Na(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Pa(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 La(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Na(n[i.column],i)))}function wn(t){switch(t){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function to(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Fa({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:La(t,o),[t,o])}}function Va(t,o,n,i){if(!n||n.trim()==="")return t;const s=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(s)}))}function Ha({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Va(t,n,o,i),[t,o,n,i])}}function Ua({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:Gs(t,n,o),[t,o,n])}}function Ya({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:Zs(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 Ga({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]),c=p.useMemo(()=>n.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[n,t]),d=p.useMemo(()=>i.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:c,visibleColumnSchemas:d,hiddenCount:s.length}}function qa({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(m=>m.id===o),[t,o]),s=p.useMemo(()=>i?ta(n,i.snapshot):!1,[i,n]),c=p.useMemo(()=>t.find(m=>m.isDefault),[t]),d=p.useMemo(()=>t.filter(m=>!m.isDefault&&!m.isDeleted),[t]),l=p.useMemo(()=>t.filter(m=>m.isFavorite&&!m.isDeleted),[t]),u=p.useMemo(()=>t.filter(m=>m.isDeleted),[t]);return{activeView:i,isDirty:s,defaultView:c,customViews:d,favoriteViews:l,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function Ja({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,c]=p.useState(i),d=t.length,l=Math.ceil(d/n),u=p.useMemo(()=>{if(!o)return t;const g=(s-1)*n,T=g+n;return t.slice(g,T)},[t,o,s,n]),m=p.useCallback(g=>{const T=Math.max(1,Math.min(g,l));c(T)},[l]),h=p.useCallback(()=>{s<l&&c(s+1)},[s,l]),b=p.useCallback(()=>{s>1&&c(s-1)},[s]),f=p.useCallback(()=>{c(1)},[]);return{paginatedData:u,currentPage:s,totalPages:l,pageSize:n,totalRows:d,goToPage:m,nextPage:h,prevPage:b,resetPage:f,hasNextPage:s<l,hasPrevPage:s>1}}function Ka(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:u,columnWidths:m,views:h,activeViewId:b,pagination:f}=t,g=p.useMemo(()=>({filters:i,sortStack:s,grouping:c,columnVisibility:l,columnOrder:u,columnWidths:m}),[i,s,c,l,u,m]),T=qa({views:h,activeViewId:b,currentState:g}),y=Ga({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:w}=Fa({data:o,filters:i}),{sortedData:v}=Ua({data:w,sortStack:s,schema:n}),{groupedData:j,isGrouped:S}=Ya({data:v,grouping:c,schema:n}),{searchedData:I}=Ha({data:j,searchQuery:d,schema:n,visibleColumns:y.visibleColumns}),a=Ja({data:I,enabled:(f==null?void 0:f.enabled)||!1,pageSize:(f==null?void 0:f.pageSize)||100,initialPage:(f==null?void 0:f.currentPage)||1}),A=f!=null&&f.enabled?a.paginatedData:I,B=p.useMemo(()=>({totalRows:o.length,filteredRows:w.length,sortedRows:v.length,groupedRows:S?j.length:v.length,searchedRows:I.length,visibleRows:A.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:S}),[o.length,w.length,v.length,j.length,I.length,A.length,y.hiddenCount,i.length,s.length,S]);return{data:A,filteredData:w,sortedData:v,groupedData:j,searchedData:I,viewEngine:T,columnEngine:y,paginationEngine:a,metrics:B,isGrouped:S,isPaginated:(f==null?void 0:f.enabled)||!1}}let Xa=0;function Za(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Xa++,writable:!1,enumerable:!1,configurable:!1})}const mt="user-demo-001";function Qa(t={}){var ln,cn,dn,un,pn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:c,sharedReportId:d,config:l={}}=t,[u,m]=p.useState([]),h=Gt(),[b,f]=p.useState(""),[g,T]=p.useState(!1),[y,w]=p.useState(!1),[v,j]=p.useState({message:"",severity:"info",open:!1}),S=(C,z="info")=>{j({message:C,severity:z,open:!0})},I=()=>j(C=>({...C,open:!1})),a=u.find(C=>C.id===b),[A,B]=p.useState("idle"),[$,Y]=p.useState(!1),[Q,te]=p.useState(!1),[x,N]=p.useState(!1),[W,H]=p.useState(!1),[J,ue]=p.useState(!1),[pe,re]=p.useState(!1),[O,F]=p.useState(void 0),[G,se]=p.useState(null),[ee,le]=p.useState(null),[ae,P]=p.useState(!1),[ne,ce]=p.useState(!1),[ie,he]=p.useState(null),[q,Ae]=p.useState(!1),[We,tt]=p.useState(!1),[Kt,hr]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[At,it]=p.useState(""),[Re,Ee]=p.useState(new Set),[gt,st]=p.useState(1),[rt,Je]=p.useState(15),[It,Xt]=p.useState(!1),[at,Ke]=p.useState(!1),[Pe,Zt]=p.useState(!1),[yt,zt]=p.useState(null),[Qt,lt]=p.useState(!1),[gr,yr]=p.useState(null),[br,Mt]=p.useState(null);p.useRef(new Da),p.useRef(new eo),p.useRef(new eo),p.useRef(new eo),p.useRef(new eo);const[vr,Sr]=p.useState(null),Xe=p.useRef(null),ve=p.useMemo(()=>a?pa(a.permissions,mt):"owner",[a]),jr=xa(ve),er=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:za(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),ot=p.useCallback(()=>{a&&(Xe.current=Ma(a))},[a]),L=p.useCallback((C,z)=>{m(_=>_.map(D=>D.id===C?{...D,...z}:D))},[]),Ne=p.useCallback(C=>{if(!a)return;Sr(C);const z=Cn(a.id,mt,C,a.auditHistory||[]);L(a.id,{auditHistory:z}),S(C.message,"error"),C.recoverable&&Xe.current&&setTimeout(()=>{_a(a,Xe.current,L),S("Previous state restored","success")},100)},[a,L]),Se=p.useCallback((C,z,_,D)=>{if(!a)return;const U=ji(a.id,mt,C,z,_,D),V=a.auditHistory||[],xe=Ci(V,U);setTimeout(()=>{L(a.id,{auditHistory:xe})},0)},[a,L]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=Mo(a.schema);(()=>{try{const z=localStorage.getItem("urm_dev_config");return z?JSON.parse(z):null}catch{return null}})(),L(a.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})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,L]),p.useEffect(()=>{if(i&&n&&!y&&u.length===0){const C=ao(i),z={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Wr(C),permissions:{owner:mt,editors:[],viewers:[]}};m([z]),f(z.id),w(!0),B("confirmed")}},[i,n,y,u.length,o,c]),p.useEffect(()=>{if(!s||y)return;let C=!1,z=null;const _=async()=>{try{B("uploading");let D;if(s.type==="api"){const V=await fetch(s.url,{headers:s.headers||{}});if(!V.ok)throw new Error(`HTTP ${V.status}: ${V.statusText}`);D=await V.json()}else D=await s.fetch();if(C)return;if(!Array.isArray(D))throw new Error("Data source must return an array of objects");const U=Wr(D);if(y)m(V=>V.map(xe=>xe.id===b?{...xe,uploadedData:D}:xe)),B("confirmed");else{const V={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:ao(D),schema:Wr(ao(D)),permissions:{owner:mt,editors:[],viewers:[]}};m([V]),f(V.id),w(!0),B("confirmed")}}catch(D){C||(B("error"),a&&L(a.id,{uploadError:(D==null?void 0:D.message)||"Failed to load data from source"}))}};return _(),s.refreshInterval&&s.refreshInterval>0&&(z=setInterval(_,s.refreshInterval)),()=>{C=!0,z&&clearInterval(z)}},[s,c,o]);const _e=(ln=a==null?void 0:a.views)==null?void 0:ln.find(C=>C.id===a.activeViewId),Cr=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(Za),a.showFavoritesOnly?!a.favoriteRowIndices||a.favoriteRowIndices.length===0?[]:a.uploadedData.filter((C,z)=>a.favoriteRowIndices.includes(z)):a.uploadedData):[],[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),_t=p.useMemo(()=>{var z;if(!(a!=null&&a.uploadedData)||!((z=a==null?void 0:a.favoriteRowIndices)!=null&&z.length))return new Set;const C=new Set;return a.favoriteRowIndices.forEach(_=>{const D=a.uploadedData[_];D!==void 0&&C.add(D)}),C},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),bt=Ka({rawData:Cr,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:At||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(_e==null?void 0:_e.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(_e==null?void 0:_e.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(_e==null?void 0:_e.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:rt,currentPage:gt}}),{data:$t=[],searchedData:Wt=[],groupedData:Et=[],metrics:wr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Rt=!1,paginationEngine:De}=bt||{},X=((cn=bt.viewEngine)==null?void 0:cn.activeView)||_e,vt=((dn=bt.viewEngine)==null?void 0:dn.isDirty)||!1;p.useEffect(()=>{if(!(!X||!a)&&!a.columnOrder){const C=X.snapshot.columnOrder,z=Fr(C,X.snapshot.grouping);L(a.id,{columnOrder:z})}},[a==null?void 0:a.activeViewId]);const ge=p.useMemo(()=>!(a!=null&&a.schema)||!X?null:ea(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,X.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,X]),je=p.useMemo(()=>!X||!ge||!vt?[]:oa(ge,X.snapshot),[X,ge,vt]),Ze=p.useCallback((C,z,_)=>{const D={id:`report-${Date.now()}`,name:C,description:z,schemaLocked:!1,permissions:{owner:mt,editors:[],viewers:[]}};if(_&&Array.isArray(_)&&_.length>0){const U=Wr(_),V=Mo(U);D.uploadedData=_,D.schema=U,D.schemaLocked=!0,D.views=[V],D.activeViewId=V.id,D.sortStack=V.snapshot.sortStack,D.filters=V.snapshot.filters,D.columnVisibility=V.snapshot.columnVisibility,D.columnOrder=V.snapshot.columnOrder,D.columnWidths=V.snapshot.columnWidths,D.grouping=V.snapshot.grouping}m(U=>[...U,D]),f(D.id),T(!1),B("confirmed")},[]),kr=p.useCallback(C=>{a&&(B("uploading"),setTimeout(()=>{const z=Wr(C);L(a.id,{uploadedData:C,schema:z,uploadError:void 0}),B("preview")},500))},[a,L]),St=p.useCallback(C=>{a&&(L(a.id,{uploadError:C}),B("idle"))},[a,L]),$e=p.useCallback(()=>{a&&(L(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),B("idle"))},[a,L]),tr=p.useCallback(()=>{a&&(L(a.id,{schemaLocked:!0}),B("confirmed"))},[a,L]),Tr=p.useCallback(C=>{if(!a)return;if(!pt("edit_sorting",ve)){S(xt("edit_sorting"),"error");return}const z=a.sortStack??[],_=z.find(D=>D.column===C);if(_){const D=qs(_.direction);if(D===null){const U=z.filter(V=>V.column!==C).map((V,xe)=>({...V,priority:xe+1}));L(a.id,{sortStack:U.length>0?U:void 0})}else{const U=z.map(V=>V.column===C?{...V,direction:D}:V);L(a.id,{sortStack:U})}}else{if(z.length>=h.sort.maxLevels)return;const D={column:C,direction:"asc",priority:z.length+1};L(a.id,{sortStack:[...z,D]})}},[a,ve,L]),rr=p.useCallback(C=>{if(a)if(a.schema){const{validRules:z,invalidColumns:_}=wi(C,a.schema);_.length>0&&S(`Removed invalid sort columns: ${_.join(", ")}`),ot();try{L(a.id,{sortStack:z.length>0?z:void 0})}catch(D){const U=Ct("processing","sorting",D);Ne(U)}}else L(a.id,{sortStack:C.length>0?C:void 0})},[a,L,ot,Ne]),or=p.useCallback(C=>{if(!a)return;const z=a.sortStack??[],_=z.find(D=>D.column===C);if(!(_&&_.direction==="asc"))if(_){const D=z.map(U=>U.column===C?{...U,direction:"asc"}:U);L(a.id,{sortStack:D})}else{if(z.length>=h.sort.maxLevels)return;const D={column:C,direction:"asc",priority:z.length+1};L(a.id,{sortStack:[...z,D]})}},[a,L]),Ir=p.useCallback(C=>{if(!a)return;const z=a.sortStack??[],_=z.find(D=>D.column===C);if(!(_&&_.direction==="desc"))if(_){const D=z.map(U=>U.column===C?{...U,direction:"desc"}:U);L(a.id,{sortStack:D})}else{if(z.length>=h.sort.maxLevels)return;const D={column:C,direction:"desc",priority:z.length+1};L(a.id,{sortStack:[...z,D]})}},[a,L]),nr=p.useCallback(C=>{var _;if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const z=(_=a.schema)==null?void 0:_.find(D=>D.name===C.column);if(z&&C.value!==void 0){const D=$a(z.type,C.operator,C.value);if(!D.isValid){S(D.errorMessage||"Invalid filter value","error");return}}ot();try{const D=a.filters??[];Se("filters","filter_added",D,[...D,C]),L(a.id,{filters:[...D,C]})}catch(D){const U=Ct("processing","filters",D);Ne(U)}},[a,ve,L,ot,Ne,Se]),ir=p.useCallback((C,z)=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const _=a.filters??[],D=[..._];Se("filters","filter_updated",_[C],z),D[C]=z,L(a.id,{filters:D})},[a,ve,L,Se]),Le=p.useCallback(C=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const z=a.filters??[],_=z.filter((D,U)=>U!==C);Se("filters","filter_removed",z[C],null),L(a.id,{filters:_.length>0?_:void 0})},[a,ve,L,Se]),ct=p.useCallback(()=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const C=a.filters??[];Se("filters","filter_cleared",C,null),L(a.id,{filters:void 0})},[a,ve,L,Se]),dt=p.useCallback(C=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const z=a.filters??[];Se("filters","filter_cleared",z,C),L(a.id,{filters:C.length>0?C:void 0})},[a,ve,L,Se]),Fe=p.useCallback(C=>{var U;if(!a)return;const z=(U=a.views)==null?void 0:U.find(V=>V.id===C);if(!z)return;const _=z.snapshot.columnOrder,D=Fr(_,z.snapshot.grouping);L(a.id,{filters:z.snapshot.filters.length>0?[...z.snapshot.filters]:void 0,sortStack:z.snapshot.sortStack.length>0?[...z.snapshot.sortStack]:void 0,columnVisibility:{...z.snapshot.columnVisibility},columnOrder:D,columnWidths:{...z.snapshot.columnWidths},grouping:z.snapshot.grouping,activeViewId:C}),Ee(new Set),N(!1)},[a,L]),sr=p.useCallback((C,z,_)=>{var xn;if(!(a!=null&&a.schema)||!ge)return;const D=a.views??[],U=D.filter(Ao=>!Ao.isDeleted).length,V=((xn=h.views)==null?void 0:xn.maxViews)??10;if(U>=V){S(`View limit reached — you can have at most ${V} saved views. Delete an existing view to create a new one.`,"error");return}const xe={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:z||void 0,isDefault:_,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:mt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...ge}},ke=_?D.map(Ao=>({...Ao,isDefault:!1})):D;L(a.id,{views:[...ke,xe],activeViewId:xe.id}),S(`"${C}" view created`,"success")},[a,ge,L]),Pt=p.useCallback(()=>{var z;if(!X||!ge||X.isDefault||!a)return;const C=(z=a.views)==null?void 0:z.map(_=>_.id===X.id?{..._,snapshot:{...ge}}:_);L(a.id,{views:C}),S(`"${X.name}" view updated`,"success")},[X,ge,a,L]),zr=p.useCallback(C=>{var D;if(!X||!ge||!a)return;const z=C??ge.columnWidths,_=(D=a.views)==null?void 0:D.map(U=>U.id===X.id?{...U,snapshot:{...U.snapshot,columnVisibility:ge.columnVisibility,columnOrder:ge.columnOrder,columnWidths:z},updatedAt:Date.now()}:U);L(a.id,{views:_,columnWidths:z}),S(`Column configuration saved to "${X.name}"`,"success")},[X,ge,a,L]),Er=p.useCallback(C=>{var V,xe;if(!ge||!a||!X)return;const z=C??ge.columnWidths,_={...X,snapshot:{...X.snapshot,columnVisibility:ge.columnVisibility,columnOrder:ge.columnOrder,columnWidths:z},updatedAt:Date.now()},D=(V=a.views)==null?void 0:V.map(ke=>ke.id===X.id?_:{...ke,snapshot:{...ke.snapshot,columnVisibility:ge.columnVisibility,columnOrder:ge.columnOrder,columnWidths:z},updatedAt:Date.now()});L(a.id,{views:D,columnWidths:z});const U=(((xe=a.views)==null?void 0:xe.length)||0)-1;S(`Column configuration saved to current view and ${U} other view${U===1?"":"s"}`,"success")},[ge,a,X,L]),Br=p.useCallback(()=>{H(!0)},[]),Dr=p.useCallback(()=>{if(!X||!a)return;const C=X.snapshot.columnOrder,z=Fr(C,X.snapshot.grouping);L(a.id,{filters:X.snapshot.filters.length>0?[...X.snapshot.filters]:void 0,sortStack:X.snapshot.sortStack.length>0?[...X.snapshot.sortStack]:void 0,columnVisibility:{...X.snapshot.columnVisibility},columnOrder:z,columnWidths:{...X.snapshot.columnWidths},grouping:X.snapshot.grouping}),S("Changes reverted to last saved state","success")},[X,a,L]),Or=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(D=>({...D,isDefault:D.id===C}));L(a.id,{views:z});const _=a.views.find(D=>D.id===C);_&&S(`"${_.name}" set as default view`,"success")},[a,L]),Ar=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(D=>D.id===C?{...D,isFavorite:!D.isFavorite,updatedAt:Date.now()}:D);L(a.id,{views:z});const _=a.views.find(D=>D.id===C);_&&!_.isFavorite?S(`"${_.name}" added to favorites`,"success"):_&&S(`"${_.name}" removed from favorites`,"info")},[a,L]),Nt=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(V=>V.id===C?{...V,isDeleted:!0,updatedAt:Date.now()}:V),_=a.activeViewId===C,D=z.find(V=>V.isDefault&&!V.isDeleted);L(a.id,{views:z,activeViewId:_&&D?D.id:a.activeViewId,filters:_&&D?D.snapshot.filters.length>0?D.snapshot.filters:void 0:a.filters,sortStack:_&&D?D.snapshot.sortStack.length>0?D.snapshot.sortStack:void 0:a.sortStack});const U=a.views.find(V=>V.id===C);U&&S(`"${U.name}" moved to Recently Deleted`,"info")},[a,L]),Mr=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(D=>D.id===C?{...D,isDeleted:!1,updatedAt:Date.now()}:D);L(a.id,{views:z});const _=a.views.find(D=>D.id===C);_&&S(`"${_.name}" restored`,"success")},[a,L]),_r=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.find(ke=>ke.id===C),_=a.views.filter(ke=>!ke.isDeleted||ke.id===C);if((z==null?void 0:z.isDefault)&&_.filter(ke=>ke.isDefault).length===1){S("Cannot delete the last default view","error");return}const U=a.views.filter(ke=>ke.id!==C),V=a.activeViewId===C,xe=U.find(ke=>ke.isDefault&&!ke.isDeleted);L(a.id,{views:U,activeViewId:V&&xe?xe.id:a.activeViewId,filters:V&&xe?xe.snapshot.filters.length>0?xe.snapshot.filters:void 0:a.filters,sortStack:V&&xe?xe.snapshot.sortStack.length>0?xe.snapshot.sortStack:void 0:a.sortStack}),z&&S(`"${z.name}" permanently deleted`,"success")},[a,L]),Me=p.useCallback(C=>{se(C),ue(!0),N(!1)},[]),Ve=p.useCallback((C,z)=>{if(!G||!(a!=null&&a.views))return;const _=a.views.map(D=>D.id===G?{...D,name:C,description:z||void 0}:D);L(a.id,{views:_}),se(null)},[G,a,L]),ar=p.useCallback(C=>{le(C),re(!0),N(!1)},[]),Kr=p.useCallback(()=>{if(!ee||!(a!=null&&a.views))return;const C=a.views.filter(D=>D.id!==ee),z=a.activeViewId===ee,_=C.find(D=>D.isDefault);L(a.id,{views:C,activeViewId:z&&_?_.id:a.activeViewId,filters:z&&_?_.snapshot.filters.length>0?_.snapshot.filters:void 0:a.filters,sortStack:z&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:a.sortStack}),le(null),re(!1)},[ee,a,L]),ut=p.useCallback(C=>{var U;if(!(a!=null&&a.views))return;if(!(((U=h.views)==null?void 0:U.isAdmin)??!1)){S("Only administrators can promote views to Global.","error");return}const _=a.views.find(V=>V.id===C);if(!_)return;if(_.scope==="global"){S(`"${_.name}" is already a Global View.`,"info");return}const D=a.views.map(V=>V.id===C?{...V,scope:"global",isDefault:!0,updatedAt:Date.now()}:V.scope==="global"&&V.isDefault?{...V,isDefault:!1}:V);L(a.id,{views:D}),S(`"${_.name}" promoted to Global View and set as default.`,"success")},[a,h,L]);p.useEffect(()=>{De!=null&&De.resetPage?De.resetPage():st(1)},[a==null?void 0:a.filters,At,a==null?void 0:a.activeViewId]),p.useEffect(()=>{De&&De.currentPage!==gt&&st(De.currentPage)},[De==null?void 0:De.currentPage]);const lr=p.useCallback(C=>{De!=null&&De.goToPage&&De.goToPage(C),st(C)},[De]),Lt=p.useCallback(C=>{const z=(gt-1)*rt,_=Math.floor(z/C)+1;Je(C),st(_)},[gt,rt]),Ft=p.useCallback((C,z)=>{if(!a)return;if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}const D={...a.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{},[C]:z};L(a.id,{columnVisibility:D})},[a,X,ve,L]),M=p.useCallback(C=>{if(a){if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}L(a.id,{columnOrder:C})}},[a,ve,L]),Z=p.useCallback((C,z)=>{if(!a)return;if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}const D={...a.columnWidths||(X==null?void 0:X.snapshot.columnWidths)||{},[C]:z};L(a.id,{columnWidths:D})},[a,X,ve,L]),K=p.useCallback(C=>{if(!a)return;const _=(a.filters??[]).filter(D=>D.column!==C);L(a.id,{filters:_.length>0?_:void 0})},[a,L]),de=p.useCallback(()=>{if(!X||!(a!=null&&a.schema))return;const C={},z=[],_={};a.schema.forEach(D=>{C[D.name]=!0,z.push(D.name),_[D.name]=150}),L(a.id,{columnVisibility:C,columnOrder:z,columnWidths:_,filters:void 0,sortStack:void 0}),S("Reset to default layout - all filters and sorts cleared","success")},[X,a,L]),oe=p.useCallback(Ba(C=>{it(C)},300),[]),He=p.useCallback(C=>{oe(C)},[oe]),nt=p.useCallback(C=>{if(!C.trim()||!a)return;const z=a.searchHistory||[],_=aa(z,C);L(a.id,{searchHistory:_})},[a,L]),Xr=p.useCallback(C=>{if(!a)return;const z=a.searchHistory||[],_=la(z,C);L(a.id,{searchHistory:_})},[a,L]),Oo=p.useCallback(C=>{if(!a)return;const z=a.searchHistory||[],_=ca(z,C);L(a.id,{searchHistory:_})},[a,L]),$r=p.useCallback(C=>{const z=C==null?void 0:C.__urm_row_id__;Ee(_=>{const D=new Set(_);if(z!==void 0){const U=Array.from(D).find(V=>(V==null?void 0:V.__urm_row_id__)===z);U!==void 0?D.delete(U):D.add(C)}else D.has(C)?D.delete(C):D.add(C);return D})},[]),ts=p.useCallback((C,z)=>{Ee(_=>{const D=new Set(_);for(const U of z)C?D.add(U):D.delete(U);return D})},[]),rs=p.useCallback((C,z,_)=>{Ee(D=>{const U=new Set(D),V=Math.min(C,z),xe=Math.max(C,z);for(let ke=V;ke<=xe;ke++)_[ke]!==void 0&&U.add(_[ke]);return U})},[]),os=p.useCallback(()=>{Ee(new Set)},[]),ns=p.useCallback(C=>{const z=C==null?void 0:C.__urm_row_id__;Ee(_=>{const D=new Set(_);if(z!==void 0){const U=Array.from(D).find(V=>(V==null?void 0:V.__urm_row_id__)===z);U!==void 0&&D.delete(U)}else D.delete(C);return D})},[]),is=p.useCallback(C=>{if(!(a!=null&&a.uploadedData))return;const z=a.uploadedData.indexOf(C);if(z===-1)return;const _=a.favoriteRowIndices||[],U=_.includes(z)?_.filter(V=>V!==z):[..._,z];L(a.id,{favoriteRowIndices:U})},[a,L]),ss=p.useCallback((C,z)=>{if(!(a!=null&&a.uploadedData))return;const _=a.favoriteRowIndices||[],D=C.map(V=>a.uploadedData.indexOf(V)).filter(V=>V!==-1),U=z?[..._,...D.filter(V=>!_.includes(V))]:_.filter(V=>!D.includes(V));L(a.id,{favoriteRowIndices:U})},[a,L]),as=p.useCallback(()=>{if(!a)return;const C=a.favoriteRowIndices||[],z=!a.showFavoritesOnly;if(z&&C.length===0){S("No rows marked as favorite","warning");return}if(L(a.id,{showFavoritesOnly:z}),z&&Re.size>0){const _=new Set(C.map(U=>{var V,xe;return(xe=(V=a.uploadedData)==null?void 0:V[U])==null?void 0:xe.__urm_row_id__}).filter(U=>U!==void 0)),D=new Set(Array.from(Re).filter(U=>(U==null?void 0:U.__urm_row_id__)!==void 0&&_.has(U.__urm_row_id__)));Ee(D)}S(z?`Showing ${C.length} favorite row${C.length===1?"":"s"}`:"Showing all data","info")},[a,L,Re]),ls=p.useCallback(C=>{if(a){if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}if(C&&a.schema){const{validGrouping:z,invalidColumns:_}=ki(C,a.schema);_.length>0&&S(`Removed invalid grouping columns: ${_.join(", ")}`,"warning"),ot();try{const D=a.grouping;z===null?Se("grouping","group_cleared",D,null):D?Se("grouping","group_reordered",D,z):Se("grouping","group_level_added",null,z);const U=(X==null?void 0:X.snapshot.columnOrder)||a.columnOrder||[],V=Fr(U,z);L(a.id,{grouping:z,columnOrder:V}),JSON.stringify(V)!==JSON.stringify(a.columnOrder)&&Se("columns","column_reordered",a.columnOrder,V),tt(!1)}catch(D){const U=Ct("processing","grouping",D);Ne(U)}}else{const z=a.grouping;Se("grouping","group_cleared",z,null);const _=(X==null?void 0:X.snapshot.columnOrder)||a.columnOrder||[];L(a.id,{grouping:C,columnOrder:[..._]}),JSON.stringify(_)!==JSON.stringify(a.columnOrder)&&Se("columns","column_reordered",a.columnOrder,_),tt(!1)}}},[a,X,ve,L,ot,Ne,Se]),cs=p.useCallback(C=>{if(!a)return;const z=a.grouping;if(!z)return;const _=Qs(z,C);L(a.id,{grouping:_})},[a,L]),ds=p.useCallback(()=>{lt(!0)},[]),cr=p.useCallback(C=>{a!=null&&a.schema&&(P(!0),setTimeout(()=>{try{let z;C.scope==="visible"?z=Wt:z=a.uploadedData||[];let _;C.columnScope==="all"?(_={},a.schema.forEach(ke=>{_[ke.name]=!0})):_=a.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{};const D=a.columnOrder||(X==null?void 0:X.snapshot.columnOrder),U=co(z,a.schema,a.filters??[],a.sortStack??[],X,_,D),V=a.name;let xe;switch(C.format){case"csv":uo(U,V,C),xe="export_csv";break;case"excel":po(U,V,C),xe="export_excel";break;case"json":xo(U,V,C),xe="export_json";break}Se("export",xe,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:z.length,viewName:(X==null?void 0:X.name)||"Default View"}),S(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(z){const _=Ra(z,{onRetry:()=>cr(C)});S(`Export failed: ${_.message}`,{action:{label:"Retry",onClick:()=>cr(C)}});const D=Cn(a.id,mt,_,a.auditHistory||[]);L(a.id,{auditHistory:D}),Ut.error("urm:report-engine","Export failed",z)}finally{P(!1)}},500))},[a,X,Wt,L,Se]),us=p.useCallback(C=>{if(a!=null&&a.schema){if(vt&&X&&!X.isDefault){he(C.format),ce(!0),lt(!1);return}cr(C),lt(!1)}},[a,X,vt,cr]),Zr=p.useCallback(C=>{cr({format:C,scope:"visible",columnScope:"visible"})},[cr]),ps=p.useCallback(()=>{ie&&Zr(ie),ce(!1),he(null)},[ie,Zr]),xs=p.useCallback(()=>{Pt(),ie&&Zr(ie),ce(!1),he(null)},[Pt,ie,Zr]),ms=p.useCallback(()=>{ce(!1),he(null)},[]),fs=p.useCallback(C=>{!(a!=null&&a.schema)||Re.size===0||(P(!0),setTimeout(()=>{try{const z=Array.from(Re),_=co(z,a.schema,a.filters??[],a.sortStack??[],X),D=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":uo(_,D);break;case"excel":po(_,D);break;case"json":xo(_,D);break}S(`Exported ${z.length} selected rows`,"info")}catch(z){S("Export failed. Please try again.","error"),Ut.error("urm:report-engine","Bulk export failed",z)}finally{P(!1)}},500))},[a,X,Re,Et]),hs=p.useCallback((C,z)=>{if(a)try{const _=ja(a),D=Ca(C,z,mt,_),U=wa(a.presets,D);L(a.id,{presets:U}),Se("presets","preset_created",null,{presetId:D.id,name:D.name}),Ke(!1),S(`Preset "${C}" saved successfully`,"success")}catch(_){S(_ instanceof Error?_.message:"Failed to create preset","error")}},[a,L,Se]),gs=p.useCallback(()=>{zt(null),S("Exited preset view","info")},[]),ys=p.useCallback(()=>{Zt(!0)},[]),bs=p.useCallback((C,z)=>{if(!a)return;const _=ka(a.presets,C);L(a.id,{presets:_}),Se("presets","preset_deleted",{presetId:C,name:z},null),yt===C&&zt(null),S(`Preset "${z}" deleted`,"success")},[a,yt,L,Se]);p.useEffect(()=>{if(!d||u.length===0)return;const C=u.find(z=>z.id===d);C&&C.id!==b&&f(C.id)},[d,u,b]),p.useEffect(()=>{if(!a)return;const C=Ta();if(C&&a.presets&&a.schemaLocked&&a.schema){const z=jn(a.presets,C);if(z){const{sanitizedConfig:_,warnings:D}=Wa(z.config,a.schema);D.length>0&&D.forEach(V=>S(V,"warning"));const U=Ia(_);L(a.id,U),zt(C),Se("presets","preset_applied",null,{presetId:z.id,name:z.name}),S(`Loaded preset: ${z.name}`,"info")}else S("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const vs=yt?jn(a==null?void 0:a.presets,yt):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&na(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 C=ia(a.id);if(C&&C.views.length>0){const z=C.views.find(_=>_.id===C.activeViewId);if(z)L(a.id,{views:C.views,activeViewId:C.activeViewId,filters:z.snapshot.filters.length>0?z.snapshot.filters:void 0,sortStack:z.snapshot.sortStack.length>0?z.snapshot.sortStack:void 0});else{const _=C.views.find(D=>D.isDefault)||Mo(a.schema);L(a.id,{views:C.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 Ss=p.useCallback(C=>{F(C),Y(!0)},[]),js=p.useCallback(()=>{Y(!1),F(void 0)},[]),Cs=(un=a==null?void 0:a.views)==null?void 0:un.find(C=>C.id===G),ws=(pn=a==null?void 0:a.views)==null?void 0:pn.find(C=>C.id===ee);return{reports:u,activeReport:a,activeReportId:b,setActiveReportId:f,isModalOpen:g,setIsModalOpen:T,createReport:Ze,updateReport:L,uploadState:A,handleFileUpload:kr,handleUploadError:St,handleRetry:$e,handleConfirm:tr,paginatedData:$t,processedData:Wt,displayData:Et,tableMetrics:wr,isGrouped:Rt,tableEngine:bt,activeView:X,isDirty:vt,currentTableState:ge,viewChanges:je,filters:a==null?void 0:a.filters,showFilterPanel:$,setShowFilterPanel:Y,filterFocusColumn:O,handleAddFilter:nr,handleUpdateFilter:ir,handleRemoveFilter:Le,handleClearAllFilters:ct,handleReplaceFilters:dt,handleOpenFilterForColumn:Ss,handleCloseFilterPanel:js,handleClearFiltersForColumn:K,sortStack:a==null?void 0:a.sortStack,showSortPanel:Q,setShowSortPanel:te,handleSort:Tr,handleUpdateSortStack:rr,handleSortAscending:or,handleSortDescending:Ir,views:a==null?void 0:a.views,showManageViews:x,setShowManageViews:N,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:J,setShowEditViewModal:ue,showDeleteConfirmation:pe,setShowDeleteConfirmation:re,editingView:Cs,deletingView:ws,editingViewId:G,deletingViewId:ee,handleSelectView:Fe,handleCreateView:sr,handleUpdateCurrentView:Pt,handleSaveColumnConfigToCurrentView:zr,handleSaveColumnConfigToAllViews:Er,handleSaveAsNewView:Br,handleRevertChanges:Dr,handleToggleDefault:Or,handleToggleFavorite:Ar,handleSoftDelete:Nt,handleRestoreView:Mr,handlePermanentDelete:_r,handleEditView:Me,handleSaveEditView:Ve,handleDeleteView:ar,handleConfirmDelete:Kr,handlePromoteToGlobal:ut,showManageColumns:q,setShowManageColumns:Ae,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:Ft,handleUpdateColumnOrder:M,handleUpdateColumnWidth:Z,handleResetColumnLayout:de,showGroupPanel:We,setShowGroupPanel:tt,grouping:a==null?void 0:a.grouping,groupingState:Kt,handleGroup:ls,handleToggleGroupCollapse:cs,searchQuery:At,searchHistory:da((a==null?void 0:a.searchHistory)||[]),handleSearchChange:He,handleAddToSearchHistory:nt,handleToggleSearchFavourite:Xr,handleDeleteSearchHistory:Oo,selectedRowIds:Re,handleToggleRowSelection:$r,handleToggleAllRows:ts,handleRangeSelection:rs,handleClearSelection:os,handleUpdateSelectionAfterDelete:ns,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:_t,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:is,handleBulkSetFavorites:ss,handleToggleFavoritesFilter:as,currentPage:gt,pageSize:rt,paginationEngine:De,handlePageChange:lr,handlePageSizeChange:Lt,isExporting:ae,showExportModal:Qt,setShowExportModal:lt,showDirtyExportWarning:ne,handleExport:ds,handleExportWithConfig:us,handleExportSelected:fs,handleExportAnyway:ps,handleSaveAndExport:xs,handleCancelExport:ms,showAuditHistory:It,setShowAuditHistory:Xt,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:at,setShowCreatePreset:Ke,showManagePresets:Pe,setShowManagePresets:Zt,activePreset:vs,activePresetId:yt,handleOpenManagePresets:ys,handleCreatePreset:hs,handleClearActivePreset:gs,handleDeletePresetById:bs,userRole:ve,isViewerRole:jr,currentUserId:mt,featureLimitWarning:br,setFeatureLimitWarning:Mt,datasetMeta:er,reportError:vr,setReportError:Sr,handleError:Ne,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?Us(a.schema):!1,snack:v,handleSnackClose:I,showSnack:S}}const Ti=p.createContext(void 0);function en(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:c,mode:d="builder",autoLoad:l=!0,config:u,devConfig:m,showDevPanel:h=!1,sharedReportId:b}=t,g=Qa({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:s,sharedReportId:b,config:u}),[T,y]=p.useState(()=>Is()),w=(()=>{const I=Es(T,m,!!m);return{...I,display:{...I.display,showDevPanel:h||I.display.showDevPanel}}})(),v=p.useCallback(S=>{y(S),zs(S)},[]),j={...g,activeDevConfig:w,handleDevConfigChange:v};return e.jsx(xi.Provider,{value:w,children:e.jsx(Ti.Provider,{value:j,children:o})})}function go(){const t=p.useContext(Ti);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function el({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const s=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(k.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(k.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(k.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Yt(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 tl="$$material";function rl(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ro={exports:{}},oo={exports:{}},me={};/** @license React v16.13.1
1
+ "use strict";var Es=Object.defineProperty;var Bs=(t,o,n)=>o in t?Es(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n;var Vr=(t,o,n)=>Bs(t,typeof o!="symbol"?o+"":o,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),Ds=require("xlsx"),w=require("@mui/icons-material"),r=require("@mui/material"),mi=require("react-dom"),Os=require("@emotion/react"),Bt=require("react-dnd"),rn=require("react-dnd-html5-backend");function fi(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 Co=fi(u),io=fi(Ds),Ye={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}},hi="urm_dev_config";function As(){try{const t=localStorage.getItem(hi);if(!t)return Ye;const o=JSON.parse(t),n={sort:{...Ye.sort,...o.sort},filter:{...Ye.filter,...o.filter},columns:{...Ye.columns,...o.columns},grouping:{...Ye.grouping,...o.grouping},export:{...Ye.export,...o.export},views:{...Ye.views,...o.views},dates:{...Ye.dates,...o.dates},display:{...Ye.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ye}}function _s(t){try{localStorage.setItem(hi,JSON.stringify(t))}catch{}}function Ms(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 gi=u.createContext(Ye);function tr(){return u.useContext(gi)}const $s=/^\d{4}-\d{2}-\d{2}$/,Rs=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Ws=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ps=9783072e5,Ns=41024448e5,Ls=978307200,Fs=4102444800;function Vs(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Ps&&t<=Ns?"timestamp_ms":Number.isInteger(t)&&t>=Ls&&t<=Fs?"timestamp_s":"unknown":typeof t!="string"?"unknown":Rs.test(t)||$s.test(t)?"iso":Ws.test(t.trim())?"locale_string":"unknown"}function Hs(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=Vs(d);i[l]++}const s=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/s>=c)return d;return"unknown"}function Us(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 yn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ys=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ae(t){return String(t).padStart(2,"0")}function Gs(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),c=Math.floor(s/60),d=Math.floor(c/60),l=Math.floor(d/24),p=Math.floor(l/7),m=Math.floor(l/30),f=Math.floor(l/365);let b;return s<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:p<5?b=`${p} week${p!==1?"s":""}`:m<12?b=`${m} month${m!==1?"s":""}`:b=`${f} year${f!==1?"s":""}`,s<60?b:i?`${b} ago`:`in ${b}`}function qs(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${Ae(i+1)}-${Ae(s)}`;case"DD/MM/YYYY":return`${Ae(s)}/${Ae(i+1)}/${n}`;case"MM/DD/YYYY":return`${Ae(i+1)}/${Ae(s)}/${n}`;case"MMM DD, YYYY":return`${yn[i]} ${Ae(s)}, ${n}`;case"DD MMM YYYY":return`${Ae(s)} ${yn[i]} ${n}`;case"MMMM D, YYYY":return`${Ys[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Ae(i+1)}-${Ae(s)} ${Ae(c)}:${Ae(d)}`;case"DD/MM/YYYY HH:mm":return`${Ae(s)}/${Ae(i+1)}/${n} ${Ae(c)}:${Ae(d)}`;case"MM/DD/YYYY HH:mm":return`${Ae(i+1)}/${Ae(s)}/${n} ${Ae(c)}:${Ae(d)}`;case"relative":return Gs(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Js(t,o,n){if(!n||o==="unknown")return String(t);const i=Us(t,o);return!i||isNaN(i.getTime())?String(t):qs(i,n)}function Ks(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 yi(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const c=o?`${o}.${s}`:s,d=t[s];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,yi(d,c,n+1)):i[c]=d}return i}function mo(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:yi(o))}function Hr(t){if(!Array.isArray(t)||t.length===0)return[];const o=mo(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let p=0;o.forEach(x=>{typeof x=="object"&&x!==null&&d in x&&(p++,l.add(Ks(x[d])))});const m=p===o.length,f=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const x=Array.from(l).filter(g=>g!=="null");x.length===1&&(b=x[0])}i.push({name:d,type:b,required:m,hasConflict:f})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Hs(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Xs(t){return t.some(o=>o.hasConflict)}function qe(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function bn(t){return t==null}function Zs(t){return(o,n,i)=>{const s=bn(o),c=bn(n);if(s&&c)return 0;if(s)return 1;if(c)return-1;let d=0;switch(t){case"number":const l=Number(o),p=Number(n);d=l-p;break;case"boolean":d=(o?1:0)-(n?1:0);break;case"string":d=String(o).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(o).localeCompare(String(n));break}return i==="asc"?d:-d}}function Qs(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,c)=>s.priority-c.priority);return[...t].sort((s,c)=>{for(const d of i){const l=o.find(f=>f.name===d.column);if(!l)continue;const m=Zs(l.type)(s[d.column],c[d.column],d.direction);if(m!==0)return m}return 0})}function ea(t){return t===null?"asc":t==="asc"?"desc":null}function ta(t){return t==="string"||t==="boolean"}function ra(t){return t.filter(o=>ta(o.type))}function oa(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(c=>c[i.name]).filter(c=>typeof c=="number");s.length>0&&(n[i.name]=s.reduce((c,d)=>c+d,0))}}),n}function na(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=bi(t,n.levels,o);return vi(i,n.collapsedGroups||[])}function bi(t,o,n,i="",s=0){if(s>=o.length)return t;const c=o[s].column,d=new Map;t.forEach(m=>{const f=m[c],b=f==null?"(empty)":String(f);d.has(b)||d.set(b,[]),d.get(b).push(m)});const l=[];return Array.from(d.keys()).sort().forEach(m=>{const f=d.get(m),b=`${c}:${m}`,x=i?`${i}|${b}`:b,g=oa(f,n),I=s<o.length-1?bi(f,o,n,x,s+1):f,y={key:x,level:s,column:c,value:m,rowCount:f.length,aggregates:g,children:I};l.push(y)}),l}function vi(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&&vi(i.children,o,n)}else n.push(i);return n}function ia(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function Si(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function ji(t,o,n){return`${o}: ${n}`}function Jr(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 Ci(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),s=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(s);let p=0;for(const m of n)d.has(m)?c.push(m):l.has(m)&&p<s.length?(c.push(s[p]),p++):l.has(m)||c.push(m);for(let m=p;m<s.length;m++)c.includes(s[m])||c.push(s[m]);return c}return[...t]}function Lo(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 sa(t,o,n,i,s,c,d,l){const p={},m=[],f={};n.forEach(g=>{p[g.name]=!0,m.push(g.name),f[g.name]=170});const x=Ci(s||m,d||null,l||m);return{filters:t||[],sortStack:o||[],columnVisibility:i||p,columnOrder:x,columnWidths:c||f,grouping:d||null}}function aa(t,o){const n=x=>{if(x==null)return x;if(Array.isArray(x))return x.map(g=>n(g));if(typeof x=="object"){const g={};return Object.keys(x).sort().forEach(I=>{g[I]=n(x[I])}),g}return x},i=x=>JSON.stringify(n(x));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack))return!0;const s=t.columnVisibility??{},c=o.columnVisibility??{};if(i(s)!==i(c))return!0;const d=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(d!==l)return!1;const p=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==p){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const x=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==x)return!0}const f=t.columnWidths??{},b=o.columnWidths??{};return i(f)!==i(b)||i(t.grouping)!==i(o.grouping)}function la(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function ca(t,o){var y,j,v;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const k=t.filters.length,S=o.filters.length;k>S?n.push({category:"filters",label:"Filters Added",description:`${k-S} new filter${k-S>1?"s":""} added`}):k<S?n.push({category:"filters",label:"Filters Removed",description:`${S-k} filter${S-k>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const c=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(c!==d){const k=t.sortStack.length,S=o.sortStack.length;k>S?n.push({category:"sorting",label:"Sorting Added",description:`${k-S} new sort rule${k-S>1?"s":""} added`}):k<S?n.push({category:"sorting",label:"Sorting Removed",description:`${S-k} sort rule${S-k>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(t.columnVisibility),p=JSON.stringify(o.columnVisibility);if(l!==p){const k=Object.values(t.columnVisibility).filter(T=>T).length,S=Object.values(o.columnVisibility).filter(T=>T).length;k>S?n.push({category:"visibility",label:"Columns Shown",description:`${k-S} column${k-S>1?"s":""} made visible`}):k<S?n.push({category:"visibility",label:"Columns Hidden",description:`${S-k} column${S-k>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const m=JSON.stringify(t.columnOrder),f=JSON.stringify(o.columnOrder);m!==f&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),x=JSON.stringify(o.columnWidths);if(b!==x){const k=Object.keys(t.columnWidths).filter(S=>t.columnWidths[S]!==o.columnWidths[S]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${k} column width${k>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),I=JSON.stringify(o.grouping);if(g!==I){const k=(y=t.grouping)==null?void 0:y.enabled,S=(j=o.grouping)==null?void 0:j.enabled;if(k&&!S){const T=((v=t.grouping)==null?void 0:v.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${T} grouping level${T>1?"s":""} added`})}else!k&&S?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function vn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function Sn(t){return`[${t}]`}const Qt={warn(t,o,...n){vn()&&console.warn(Sn(t),o,...n)},error(t,o,...n){vn()&&console.error(Sn(t),o,...n)}},wi="urm_report_";function da(t,o){try{const n=`${wi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){Qt.error("urm:persistence","Failed to save report state",n)}}function ua(t){try{const o=`${wi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return Qt.error("urm:persistence","Failed to load report state",o),null}}function wo(t,o,n=0){const i=[];for(const s of t){const c=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:c}),!c&&s.children&&s.children.length>0){const d=s.children[0];if(pa(d)){const l=s.children,p=wo(l,o,n+1);i.push(...p)}else{const l=s.children;for(const p of l)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:p})}}}return i}function pa(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 on(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function nn(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${s}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function yo(t,o,n,i,s,c,d){let l,p;c?(l={...c},p=d||o.map(f=>f.name)):s?(l={...s.snapshot.columnVisibility},p=d||[...s.snapshot.columnOrder]):(l={},p=[],o.forEach(f=>{l[f.name]=!0,p.push(f.name)}));const m=Object.entries(l).filter(([f,b])=>!b).map(([f,b])=>f);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:p,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:m,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function bo(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=c.collapsedGroups??[],x=wo(i,b);l=on(x)}else l=i;const p=d.join(","),m=l.map(b=>d.map(x=>{const g=b[x];if(g==null)return"";const I=String(g);return I.includes(",")||I.includes('"')||I.includes(`
2
+ `)?`"${I.replace(/"/g,'""')}"`:I}).join(",")),f=[p,...m].join(`
3
+ `);ki(f,nn(o,"csv"),"text/csv;charset=utf-8;")}function vo(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=c.collapsedGroups??[],x=wo(i,b);l=on(x)}else l=i;const p=[d,...l.map(b=>d.map(x=>b[x]??""))],m=io.utils.aoa_to_sheet(p),f=io.utils.book_new();io.utils.book_append_sheet(f,m,"Data"),io.writeFile(f,nn(o,"xlsx"))}function So(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:p,grouping:m}=t;let f;if(m&&m.enabled){const g=m.collapsedGroups??[],I=wo(i,g);f=on(I)}else f=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:s.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:m||{},hiddenColumns:l,columnOrder:p,exportConfig:n||{scope:"visible"}},data:f},x=JSON.stringify(b,null,2);ki(x,nn(o,"json"),"application/json;charset=utf-8;")}function ki(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),c=document.createElement("a");c.href=s,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s)}const jn=10;function xa(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.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>jn&&(s=[...s].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,jn)),s}function ma(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function fa(t,o){return t.filter(n=>n.query!==o)}function ha(t){const o=t.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...o,...n]}const ga={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 ya(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function mt(t,o){return ga[o].includes(t)}function ft(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 ba(t){return t==="viewer"}const Cn=1e3;function Zo(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function yt(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Zo(n)}const va={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function Fo(t){if(!t||!t.column)return"a filter";const o=yt(t.column),n=va[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function wn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${yt(n.column)}"`).join(", ")}`}function Sa(t){var s,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: ${Fo(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Fo(n)}`};case"filter_updated":{const l=n,p=i;return(l==null?void 0:l.column)!==(p==null?void 0:p.column)?{summary:`Filter changed on "${yt(p==null?void 0:p.column)}"`,detail:`Previously filtered "${yt(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Fo(p)}`}}case"filter_cleared":{const l=Array.isArray(n)?n.length:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?yt(i.column):"",p=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${p}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?yt(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: ${wn(i)}`};case"group_level_removed":{const l=n,p=(c=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&c.column?yt(l.levels[0].column):"";return{summary:p?`Group level removed: "${p}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${wn(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: "${yt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${yt(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],p=Array.isArray(i)?i:[];return l.length>0&&p.length>0?{summary:"Column order changed",detail:`${p.length} column${p.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",p=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${yt(l)}"`:"Column resized",detail:p?`New width: ${p}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",p=(i==null?void 0:i.name)??"";return l&&p?{summary:`Switched to view "${p}"`,detail:`From "${l}"`}:p?{summary:`Switched to view "${p}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",p=i==null?void 0:i.rowCount,m=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",f=(i==null?void 0:i.viewName)??"",b=typeof p=="number"?` (${p.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:f?`${Zo(m)} · View: "${f}"`:Zo(m)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",p=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&p?{summary:`Theme changed from "${l}" to "${p}"`}:p?{summary:`Theme changed to "${p}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:Ca(o)}}}function ja(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ti(t,o,n,i,s,c){return{id:ja(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:c}}function Ii(t,o){const n=[o,...t];return n.length>Cn?n.slice(0,Cn):n}function Ca(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 wa(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function ka(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function Ta(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>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 kn=100;function Ia(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function za(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||[],s=Ci(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:Ia(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function Ba(t,o){const n=t||[];if(n.length>=kn)throw new Error(`Maximum of ${kn} presets reached. Please delete old presets first.`);return[...n,o]}function Da(t,o){return(t||[]).filter(i=>i.id!==o)}function Tn(t,o){if(t)return t.find(n=>n.id===o)}function Oa(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Aa(t){const o=t.columnOrder,n=Jr(o,t.grouping);return{filters:t.filters.length>0?[...t.filters]:void 0,sortStack:t.sortStack.length>0?[...t.sortStack]:void 0,columnVisibility:{...t.columnVisibility},columnOrder:n,columnWidths:{...t.columnWidths},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function _a(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ma={MAX_CACHE_ENTRIES:3};function $a(t,o){let n=null;return function(...s){const c=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(c,o)}}class so{constructor(o=Ma.MAX_CACHE_ENTRIES){Vr(this,"cache",new Map);Vr(this,"maxEntries");this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const s=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];s&&this.cache.delete(s)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Ra{constructor(){Vr(this,"metrics",new Map)}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),s=this.end(o);return{result:i,duration:s}}async measureAsync(o,n){this.start(o);const i=await n(),s=this.end(o);return{result:i,duration:s}}}function Et(t,o,n,i){const s=n instanceof Error?n.message:n,c={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:Wa(t,o)};return process.env.NODE_ENV==="development"&&Qt.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),c}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 zi(t,o){const n=[],i=[],s=new Set(o.map(c=>c.name));return t.forEach(c=>{s.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function Ei(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],s=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):s.push(c.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(c=>c.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const c=s.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});s.filters=c.length>0?c:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:c,invalidColumns:d}=zi(s.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),s.sortStack=c.length>0?c:void 0}if(s.grouping){const{validGrouping:c,invalidColumns:d}=Ei(s.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),s.grouping=c}if(s.columnVisibility){const c={};Object.entries(s.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),s.columnVisibility=Object.keys(c).length>0?c:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const c=s.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});s.columnOrder=c.length>0?c:void 0}if(s.columnWidths){const c={};Object.entries(s.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),s.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:s,warnings:n}}function Ha(t,o){return Et("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function In(t,o,n,i){const s=Ti(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Ii(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 zn(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 ao(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function qa({data:t,filters:o}){return{filteredData:u.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(),c=o.filter(d=>i.includes(d.name));return t.filter(d=>c.some(l=>{const p=d[l.name];return p==null?!1:String(p).toLowerCase().includes(s)}))}function Ka({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:u.useMemo(()=>!o||o.trim()===""?t:Ja(t,n,o,i),[t,o,n,i])}}function Xa({data:t,sortStack:o,schema:n}){return{sortedData:u.useMemo(()=>!o||o.length===0?t:Qs(t,n,o),[t,o,n])}}function Za({data:t,grouping:o,schema:n}){const i=u.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:na(t,n,o),[t,o,n]),s=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function Qa({schema:t,columnVisibility:o,columnOrder:n}){const i=u.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),s=u.useMemo(()=>Object.entries(o).filter(([l,p])=>!p).map(([l,p])=>l),[o]),c=u.useMemo(()=>n.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[n,t]),d=u.useMemo(()=>i.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:c,visibleColumnSchemas:d,hiddenCount:s.length}}function el({views:t,activeViewId:o,currentState:n}){const i=u.useMemo(()=>t.find(m=>m.id===o),[t,o]),s=u.useMemo(()=>i?aa(n,i.snapshot):!1,[i,n]),c=u.useMemo(()=>t.find(m=>m.isDefault),[t]),d=u.useMemo(()=>t.filter(m=>!m.isDefault&&!m.isDeleted),[t]),l=u.useMemo(()=>t.filter(m=>m.isFavorite&&!m.isDeleted),[t]),p=u.useMemo(()=>t.filter(m=>m.isDeleted),[t]);return{activeView:i,isDirty:s,defaultView:c,customViews:d,favoriteViews:l,deletedViews:p,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function tl({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,c]=u.useState(i),d=t.length,l=Math.ceil(d/n),p=u.useMemo(()=>{if(!o)return t;const g=(s-1)*n,I=g+n;return t.slice(g,I)},[t,o,s,n]),m=u.useCallback(g=>{const I=Math.max(1,Math.min(g,l));c(I)},[l]),f=u.useCallback(()=>{s<l&&c(s+1)},[s,l]),b=u.useCallback(()=>{s>1&&c(s-1)},[s]),x=u.useCallback(()=>{c(1)},[]);return{paginatedData:p,currentPage:s,totalPages:l,pageSize:n,totalRows:d,goToPage:m,nextPage:f,prevPage:b,resetPage:x,hasNextPage:s<l,hasPrevPage:s>1}}function rl(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:p,columnWidths:m,views:f,activeViewId:b,pagination:x}=t,g=u.useMemo(()=>({filters:i,sortStack:s,grouping:c,columnVisibility:l,columnOrder:p,columnWidths:m}),[i,s,c,l,p,m]),I=el({views:f,activeViewId:b,currentState:g}),y=Qa({schema:n,columnVisibility:l,columnOrder:p}),{filteredData:j}=qa({data:o,filters:i}),{sortedData:v}=Xa({data:j,sortStack:s,schema:n}),{groupedData:k,isGrouped:S}=Za({data:v,grouping:c,schema:n}),{searchedData:T}=Ka({data:k,searchQuery:d,schema:n,visibleColumns:y.visibleColumns}),a=tl({data:T,enabled:(x==null?void 0:x.enabled)||!1,pageSize:(x==null?void 0:x.pageSize)||100,initialPage:(x==null?void 0:x.currentPage)||1}),_=x!=null&&x.enabled?a.paginatedData:T,z=u.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:v.length,groupedRows:S?k.length:v.length,searchedRows:T.length,visibleRows:_.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:S}),[o.length,j.length,v.length,k.length,T.length,_.length,y.hiddenCount,i.length,s.length,S]);return{data:_,filteredData:j,sortedData:v,groupedData:k,searchedData:T,viewEngine:I,columnEngine:y,paginationEngine:a,metrics:z,isGrouped:S,isPaginated:(x==null?void 0:x.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 ht="user-demo-001";function il(t={}){var xn,mn,fn,hn,gn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:c,sharedReportId:d,config:l={}}=t,[p,m]=u.useState([]),f=tr(),[b,x]=u.useState(""),[g,I]=u.useState(!1),[y,j]=u.useState(!1),[v,k]=u.useState({message:"",severity:"info",open:!1}),S=(C,E="info")=>{k({message:C,severity:E,open:!0})},T=()=>k(C=>({...C,open:!1})),a=p.find(C=>C.id===b),[_,z]=u.useState("idle"),[R,G]=u.useState(!1),[Z,ee]=u.useState(!1),[h,$]=u.useState(!1),[W,V]=u.useState(!1),[K,pe]=u.useState(!1),[xe,oe]=u.useState(!1),[A,F]=u.useState(void 0),[re,q]=u.useState(null),[Q,ae]=u.useState(null),[ne,N]=u.useState(!1),[ie,le]=u.useState(!1),[se,he]=u.useState(null),[J,_e]=u.useState(!1),[Ve,rt]=u.useState(!1),[nr,wr]=u.useState({enabled:!1,levels:[],collapsedGroups:[]}),[Nt,ct]=u.useState(""),[Ne,ze]=u.useState(new Set),[At,bt]=u.useState(null),[Ke,Fe]=u.useState(1),[Xe,ir]=u.useState(15),[Ze,ot]=u.useState(!1),[Re,sr]=u.useState(!1),[kr,Lt]=u.useState(!1),[dt,vt]=u.useState(null),[ar,St]=u.useState(!1),[oo,lr]=u.useState(null),[Tr,jt]=u.useState(null);u.useRef(new Ra),u.useRef(new so),u.useRef(new so),u.useRef(new so),u.useRef(new so);const[nt,Ir]=u.useState(null),Ft=u.useRef(null),Se=u.useMemo(()=>a?ya(a.permissions,ht):"owner",[a]),zr=ba(Se),cr=u.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:_a(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),it=u.useCallback(()=>{a&&(Ft.current=Na(a))},[a]),L=u.useCallback((C,E)=>{m(M=>M.map(O=>O.id===C?{...O,...E}:O))},[]),He=u.useCallback(C=>{if(!a)return;Ir(C);const E=In(a.id,ht,C,a.auditHistory||[]);L(a.id,{auditHistory:E}),S(C.message,"error"),C.recoverable&&Ft.current&&setTimeout(()=>{La(a,Ft.current,L),S("Previous state restored","success")},100)},[a,L]),je=u.useCallback((C,E,M,O)=>{if(!a)return;const Y=Ti(a.id,ht,C,E,M,O),H=a.auditHistory||[],te=Ii(H,Y);setTimeout(()=>{L(a.id,{auditHistory:te})},0)},[a,L]);u.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=Lo(a.schema);(()=>{try{const E=localStorage.getItem("urm_dev_config");return E?JSON.parse(E):null}catch{return null}})(),L(a.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})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,L]),u.useEffect(()=>{if(i&&n&&!y&&p.length===0){const C=mo(i),E={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Hr(C),permissions:{owner:ht,editors:[],viewers:[]}};m([E]),x(E.id),j(!0),z("confirmed")}},[i,n,y,p.length,o,c]),u.useEffect(()=>{if(!s||y)return;let C=!1,E=null;const M=async()=>{try{z("uploading");let O;if(s.type==="api"){const H=await fetch(s.url,{headers:s.headers||{}});if(!H.ok)throw new Error(`HTTP ${H.status}: ${H.statusText}`);O=await H.json()}else O=await s.fetch();if(C)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const Y=Hr(O);if(y)m(H=>H.map(te=>te.id===b?{...te,uploadedData:O}:te)),z("confirmed");else{const H={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:mo(O),schema:Hr(mo(O)),permissions:{owner:ht,editors:[],viewers:[]}};m([H]),x(H.id),j(!0),z("confirmed")}}catch(O){C||(z("error"),a&&L(a.id,{uploadError:(O==null?void 0:O.message)||"Failed to load data from source"}))}};return M(),s.refreshInterval&&s.refreshInterval>0&&(E=setInterval(M,s.refreshInterval)),()=>{C=!0,E&&clearInterval(E)}},[s,c,o]);const Le=(xn=a==null?void 0:a.views)==null?void 0:xn.find(C=>C.id===a.activeViewId),Er=u.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(nl),a.showFavoritesOnly?!a.favoriteRowIndices||a.favoriteRowIndices.length===0?[]:a.uploadedData.filter((C,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]),Vt=u.useMemo(()=>{var E;if(!(a!=null&&a.uploadedData)||!((E=a==null?void 0:a.favoriteRowIndices)!=null&&E.length))return new Set;const C=new Set;return a.favoriteRowIndices.forEach(M=>{const O=a.uploadedData[M];O!==void 0&&C.add(O)}),C},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),Ct=rl({rawData:Er,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:Nt||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Le==null?void 0:Le.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Le==null?void 0:Le.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Le==null?void 0:Le.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:Xe,currentPage:Ke}}),{data:_t=[],searchedData:Ht=[],groupedData:Ut=[],metrics:Br={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Yt=!1,paginationEngine:Me}=Ct||{},X=((mn=Ct.viewEngine)==null?void 0:mn.activeView)||Le,wt=((fn=Ct.viewEngine)==null?void 0:fn.isDirty)||!1;u.useEffect(()=>{if(!(!X||!a)&&!a.columnOrder){const C=X.snapshot.columnOrder,E=Jr(C,X.snapshot.grouping);L(a.id,{columnOrder:E})}},[a==null?void 0:a.activeViewId]);const Ce=u.useMemo(()=>!(a!=null&&a.schema)||!X?null:sa(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,X.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,X]),we=u.useMemo(()=>!X||!Ce||!wt?[]:ca(Ce,X.snapshot),[X,Ce,wt]),st=u.useCallback((C,E,M)=>{const O={id:`report-${Date.now()}`,name:C,description:E,schemaLocked:!1,permissions:{owner:ht,editors:[],viewers:[]}};if(M&&Array.isArray(M)&&M.length>0){const Y=Hr(M),H=Lo(Y);O.uploadedData=M,O.schema=Y,O.schemaLocked=!0,O.views=[H],O.activeViewId=H.id,O.sortStack=H.snapshot.sortStack,O.filters=H.snapshot.filters,O.columnVisibility=H.snapshot.columnVisibility,O.columnOrder=H.snapshot.columnOrder,O.columnWidths=H.snapshot.columnWidths,O.grouping=H.snapshot.grouping}m(Y=>[...Y,O]),x(O.id),I(!1),z("confirmed")},[]),dr=u.useCallback(C=>{a&&(z("uploading"),setTimeout(()=>{const E=Hr(C);L(a.id,{uploadedData:C,schema:E,uploadError:void 0}),z("preview")},500))},[a,L]),ut=u.useCallback(C=>{a&&(L(a.id,{uploadError:C}),z("idle"))},[a,L]),Ue=u.useCallback(()=>{a&&(L(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),z("idle"))},[a,L]),ur=u.useCallback(()=>{a&&(L(a.id,{schemaLocked:!0}),z("confirmed"))},[a,L]),pr=u.useCallback(C=>{if(!a)return;if(!mt("edit_sorting",Se)){S(ft("edit_sorting"),"error");return}const E=a.sortStack??[],M=E.find(O=>O.column===C);if(M){const O=ea(M.direction);if(O===null){const Y=E.filter(H=>H.column!==C).map((H,te)=>({...H,priority:te+1}));L(a.id,{sortStack:Y.length>0?Y:void 0})}else{const Y=O,H=E.map(te=>te.column===C?{...te,direction:Y}:te);L(a.id,{sortStack:H})}}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:C,direction:"asc",priority:E.length+1};L(a.id,{sortStack:[...E,O]})}},[a,Se,L]),xr=u.useCallback(C=>{if(a)if(a.schema){const{validRules:E,invalidColumns:M}=zi(C,a.schema);M.length>0&&S(`Removed invalid sort columns: ${M.join(", ")}`),it();try{L(a.id,{sortStack:E.length>0?E:void 0})}catch(O){const Y=Et("processing","sorting",O);He(Y)}}else L(a.id,{sortStack:C.length>0?C:void 0})},[a,L,it,He]),kt=u.useCallback(C=>{if(!a)return;const E=a.sortStack??[],M=E.find(O=>O.column===C);if(!(M&&M.direction==="asc"))if(M){const O=E.map(Y=>Y.column===C?{...Y,direction:"asc"}:Y);L(a.id,{sortStack:O})}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:C,direction:"asc",priority:E.length+1};L(a.id,{sortStack:[...E,O]})}},[a,L]),Dr=u.useCallback(C=>{if(!a)return;const E=a.sortStack??[],M=E.find(O=>O.column===C);if(!(M&&M.direction==="desc"))if(M){const O=E.map(Y=>Y.column===C?{...Y,direction:"desc"}:Y);L(a.id,{sortStack:O})}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:C,direction:"desc",priority:E.length+1};L(a.id,{sortStack:[...E,O]})}},[a,L]),Mt=u.useCallback(C=>{var M;if(!a)return;if(!mt("edit_filters",Se)){S(ft("edit_filters"),"error");return}const E=(M=a.schema)==null?void 0:M.find(O=>O.name===C.column);if(E&&C.value!==void 0){const O=Fa(E.type,C.operator,C.value);if(!O.isValid){S(O.errorMessage||"Invalid filter value","error");return}}it();try{const O=a.filters??[];je("filters","filter_added",O,[...O,C]),L(a.id,{filters:[...O,C]})}catch(O){const Y=Et("processing","filters",O);He(Y)}},[a,Se,L,it,He,je]),Gt=u.useCallback((C,E)=>{if(!a)return;if(!mt("edit_filters",Se)){S(ft("edit_filters"),"error");return}const M=a.filters??[],O=[...M];je("filters","filter_updated",M[C],E),O[C]=E,L(a.id,{filters:O})},[a,Se,L,je]),Qe=u.useCallback(C=>{if(!a)return;if(!mt("edit_filters",Se)){S(ft("edit_filters"),"error");return}const E=a.filters??[],M=E.filter((O,Y)=>Y!==C);je("filters","filter_removed",E[C],null),L(a.id,{filters:M.length>0?M:void 0})},[a,Se,L,je]),at=u.useCallback(()=>{if(!a)return;if(!mt("edit_filters",Se)){S(ft("edit_filters"),"error");return}const C=a.filters??[];je("filters","filter_cleared",C,null),L(a.id,{filters:void 0})},[a,Se,L,je]),We=u.useCallback(C=>{if(!a)return;if(!mt("edit_filters",Se)){S(ft("edit_filters"),"error");return}const E=a.filters??[];je("filters","filter_cleared",E,C),L(a.id,{filters:C.length>0?C:void 0})},[a,Se,L,je]),pt=u.useCallback(C=>{var Y;if(!a)return;const E=(Y=a.views)==null?void 0:Y.find(H=>H.id===C);if(!E)return;const M=E.snapshot.columnOrder,O=Jr(M,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:O,columnWidths:{...E.snapshot.columnWidths},grouping:E.snapshot.grouping,activeViewId:C}),ze(new Set),$(!1)},[a,L]),mr=u.useCallback((C,E,M)=>{var Kt;if(!(a!=null&&a.schema)||!Ce)return;const O=a.views??[],Y=O.filter(Fr=>!Fr.isDeleted).length,H=((Kt=f.views)==null?void 0:Kt.maxViews)??10;if(Y>=H){S(`View limit reached — you can have at most ${H} saved views. Delete an existing view to create a new one.`,"error");return}const te={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:E||void 0,isDefault:M,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:ht,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...Ce}},fe=M?O.map(Fr=>({...Fr,isDefault:!1})):O;L(a.id,{views:[...fe,te],activeViewId:te.id}),S(`"${C}" view created`,"success")},[a,Ce,L]),xt=u.useCallback(()=>{var E;if(!X||!Ce||X.isDefault||!a)return;const C=(E=a.views)==null?void 0:E.map(M=>M.id===X.id?{...M,snapshot:{...Ce}}:M);L(a.id,{views:C}),S(`"${X.name}" view updated`,"success")},[X,Ce,a,L]),Or=u.useCallback(C=>{var O;if(!X||!Ce||!a)return;const E=C??Ce.columnWidths,M=(O=a.views)==null?void 0:O.map(Y=>Y.id===X.id?{...Y,snapshot:{...Y.snapshot,columnVisibility:Ce.columnVisibility,columnOrder:Ce.columnOrder,columnWidths:E},updatedAt:Date.now()}:Y);L(a.id,{views:M,columnWidths:E}),S(`Column configuration saved to "${X.name}"`,"success")},[X,Ce,a,L]),Ar=u.useCallback(C=>{var H,te;if(!Ce||!a||!X)return;const E=C??Ce.columnWidths,M={...X,snapshot:{...X.snapshot,columnVisibility:Ce.columnVisibility,columnOrder:Ce.columnOrder,columnWidths:E},updatedAt:Date.now()},O=(H=a.views)==null?void 0:H.map(fe=>fe.id===X.id?M:{...fe,snapshot:{...fe.snapshot,columnVisibility:Ce.columnVisibility,columnOrder:Ce.columnOrder,columnWidths:E},updatedAt:Date.now()});L(a.id,{views:O,columnWidths:E});const Y=(((te=a.views)==null?void 0:te.length)||0)-1;S(`Column configuration saved to current view and ${Y} other view${Y===1?"":"s"}`,"success")},[Ce,a,X,L]),_r=u.useCallback(()=>{V(!0)},[]),Mr=u.useCallback(()=>{if(!X||!a)return;const C=X.snapshot.columnOrder,E=Jr(C,X.snapshot.grouping);L(a.id,{filters:X.snapshot.filters.length>0?[...X.snapshot.filters]:void 0,sortStack:X.snapshot.sortStack.length>0?[...X.snapshot.sortStack]:void 0,columnVisibility:{...X.snapshot.columnVisibility},columnOrder:E,columnWidths:{...X.snapshot.columnWidths},grouping:X.snapshot.grouping}),S("Changes reverted to last saved state","success")},[X,a,L]),fr=u.useCallback(C=>{if(!(a!=null&&a.views))return;const E=a.views.map(O=>({...O,isDefault:O.id===C}));L(a.id,{views:E});const M=a.views.find(O=>O.id===C);M&&S(`"${M.name}" set as default view`,"success")},[a,L]),$r=u.useCallback(C=>{if(!(a!=null&&a.views))return;const E=a.views.map(O=>O.id===C?{...O,isFavorite:!O.isFavorite,updatedAt:Date.now()}:O);L(a.id,{views:E});const M=a.views.find(O=>O.id===C);M&&!M.isFavorite?S(`"${M.name}" added to favorites`,"success"):M&&S(`"${M.name}" removed from favorites`,"info")},[a,L]),Rr=u.useCallback(C=>{if(!(a!=null&&a.views))return;const E=a.views.map(H=>H.id===C?{...H,isDeleted:!0,updatedAt:Date.now()}:H),M=a.activeViewId===C,O=E.find(H=>H.isDefault&&!H.isDeleted);L(a.id,{views:E,activeViewId:M&&O?O.id:a.activeViewId,filters:M&&O?O.snapshot.filters.length>0?O.snapshot.filters:void 0:a.filters,sortStack:M&&O?O.snapshot.sortStack.length>0?O.snapshot.sortStack:void 0:a.sortStack});const Y=a.views.find(H=>H.id===C);Y&&S(`"${Y.name}" moved to Recently Deleted`,"info")},[a,L]),Wr=u.useCallback(C=>{if(!(a!=null&&a.views))return;const E=a.views.map(O=>O.id===C?{...O,isDeleted:!1,updatedAt:Date.now()}:O);L(a.id,{views:E});const M=a.views.find(O=>O.id===C);M&&S(`"${M.name}" restored`,"success")},[a,L]),$t=u.useCallback(C=>{if(!(a!=null&&a.views))return;const E=a.views.find(fe=>fe.id===C),M=a.views.filter(fe=>!fe.isDeleted||fe.id===C);if((E==null?void 0:E.isDefault)&&M.filter(fe=>fe.isDefault).length===1){S("Cannot delete the last default view","error");return}const Y=a.views.filter(fe=>fe.id!==C),H=a.activeViewId===C,te=Y.find(fe=>fe.isDefault&&!fe.isDeleted);L(a.id,{views:Y,activeViewId:H&&te?te.id:a.activeViewId,filters:H&&te?te.snapshot.filters.length>0?te.snapshot.filters:void 0:a.filters,sortStack:H&&te?te.snapshot.sortStack.length>0?te.snapshot.sortStack:void 0:a.sortStack}),E&&S(`"${E.name}" permanently deleted`,"success")},[a,L]),hr=u.useCallback(C=>{q(C),pe(!0),$(!1)},[]),Pr=u.useCallback((C,E)=>{if(!re||!(a!=null&&a.views))return;const M=a.views.map(O=>O.id===re?{...O,name:C,description:E||void 0}:O);L(a.id,{views:M}),q(null)},[re,a,L]),qt=u.useCallback(C=>{ae(C),oe(!0),$(!1)},[]),Oe=u.useCallback(()=>{if(!Q||!(a!=null&&a.views))return;const C=a.views.filter(O=>O.id!==Q),E=a.activeViewId===Q,M=C.find(O=>O.isDefault);L(a.id,{views:C,activeViewId:E&&M?M.id:a.activeViewId,filters:E&&M?M.snapshot.filters.length>0?M.snapshot.filters:void 0:a.filters,sortStack:E&&M?M.snapshot.sortStack.length>0?M.snapshot.sortStack:void 0:a.sortStack}),ae(null),oe(!1)},[Q,a,L]),lt=u.useCallback(C=>{var Y;if(!(a!=null&&a.views))return;if(!(((Y=f.views)==null?void 0:Y.isAdmin)??!1)){S("Only administrators can promote views to Global.","error");return}const M=a.views.find(H=>H.id===C);if(!M)return;if(M.scope==="global"){S(`"${M.name}" is already a Global View.`,"info");return}const O=a.views.map(H=>H.id===C?{...H,scope:"global",isDefault:!0,updatedAt:Date.now()}:H.scope==="global"&&H.isDefault?{...H,isDefault:!1}:H);L(a.id,{views:O}),S(`"${M.name}" promoted to Global View and set as default.`,"success")},[a,f,L]);u.useEffect(()=>{Me!=null&&Me.resetPage?Me.resetPage():Fe(1)},[a==null?void 0:a.filters,Nt,a==null?void 0:a.activeViewId]),u.useEffect(()=>{Me&&Me.currentPage!==Ke&&Fe(Me.currentPage)},[Me==null?void 0:Me.currentPage]);const Jt=u.useCallback(C=>{Me!=null&&Me.goToPage&&Me.goToPage(C),Fe(C)},[Me]),Nr=u.useCallback(C=>{const E=(Ke-1)*Xe,M=Math.floor(E/C)+1;ir(C),Fe(M)},[Ke,Xe]),Tt=u.useCallback((C,E)=>{if(!a)return;if(!mt("edit_columns",Se)){S(ft("edit_columns"),"error");return}const O={...a.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{},[C]:E};L(a.id,{columnVisibility:O})},[a,X,Se,L]),de=u.useCallback(C=>{if(a){if(!mt("edit_columns",Se)){S(ft("edit_columns"),"error");return}L(a.id,{columnOrder:C})}},[a,Se,L]),me=u.useCallback((C,E)=>{if(!a)return;if(!mt("edit_columns",Se)){S(ft("edit_columns"),"error");return}const O={...a.columnWidths||(X==null?void 0:X.snapshot.columnWidths)||{},[C]:E};L(a.id,{columnWidths:O})},[a,X,Se,L]),$e=u.useCallback(C=>{if(!a)return;const M=(a.filters??[]).filter(O=>O.column!==C);L(a.id,{filters:M.length>0?M:void 0})},[a,L]),D=u.useCallback(()=>{if(!X||!(a!=null&&a.schema))return;const C={},E=[],M={};a.schema.forEach(O=>{C[O.name]=!0,E.push(O.name),M[O.name]=170}),L(a.id,{columnVisibility:C,columnOrder:E,columnWidths:M,filters:void 0,sortStack:void 0}),S("Reset to default layout - all filters and sorts cleared","success")},[X,a,L]),U=u.useCallback($a(C=>{ct(C)},300),[]),ue=u.useCallback(C=>{U(C)},[U]),Pe=u.useCallback(C=>{if(!C.trim()||!a)return;const E=a.searchHistory||[],M=xa(E,C);L(a.id,{searchHistory:M})},[a,L]),ce=u.useCallback(C=>{if(!a)return;const E=a.searchHistory||[],M=ma(E,C);L(a.id,{searchHistory:M})},[a,L]),It=u.useCallback(C=>{if(!a)return;const E=a.searchHistory||[],M=fa(E,C);L(a.id,{searchHistory:M})},[a,L]),No=u.useCallback(C=>{const E=C==null?void 0:C.__urm_row_id__;ze(M=>{const O=new Set(M);if(E!==void 0){const Y=Array.from(O).find(H=>(H==null?void 0:H.__urm_row_id__)===E);Y!==void 0?O.delete(Y):O.add(C)}else{const Y=JSON.stringify(C),H=Array.from(O).find(te=>JSON.stringify(te)===Y);H!==void 0?O.delete(H):O.add(C)}return O})},[]),is=u.useCallback((C,E)=>{ze(M=>{const O=new Set(M);for(const Y of E)C?O.add(Y):O.delete(Y);return O})},[]),ss=u.useCallback((C,E,M)=>{ze(O=>{const Y=new Set(O),H=Math.min(C,E),te=Math.max(C,E);for(let fe=H;fe<=te;fe++)M[fe]!==void 0&&Y.add(M[fe]);return Y})},[]),as=u.useCallback(()=>{ze(new Set),bt(null)},[]),ls=u.useCallback(C=>{const E=C==null?void 0:C.__urm_row_id__;ze(M=>{const O=new Set(M);if(E!==void 0){const Y=Array.from(O).find(H=>(H==null?void 0:H.__urm_row_id__)===E);Y!==void 0&&O.delete(Y)}else O.delete(C);return O})},[]),cs=u.useCallback(C=>{if(!(a!=null&&a.uploadedData))return;const E=a.uploadedData.indexOf(C);if(E===-1)return;const M=a.favoriteRowIndices||[],Y=M.includes(E)?M.filter(H=>H!==E):[...M,E];L(a.id,{favoriteRowIndices:Y})},[a,L]),ds=u.useCallback((C,E)=>{if(!(a!=null&&a.uploadedData))return;const M=a.favoriteRowIndices||[],O=C.map(H=>a.uploadedData.indexOf(H)).filter(H=>H!==-1),Y=E?[...M,...O.filter(H=>!M.includes(H))]:M.filter(H=>!O.includes(H));L(a.id,{favoriteRowIndices:Y})},[a,L]),us=u.useCallback(()=>{if(!a)return;const C=a.favoriteRowIndices||[],E=!a.showFavoritesOnly;if(E&&C.length===0){S("No rows marked as favorite","warning");return}if(L(a.id,{showFavoritesOnly:E}),E){if(bt(new Set(Ne)),Ne.size>0){const M=new Set(C.map(Y=>{var H,te;return(te=(H=a.uploadedData)==null?void 0:H[Y])==null?void 0:te.__urm_row_id__}).filter(Y=>Y!==void 0)),O=new Set(Array.from(Ne).filter(Y=>(Y==null?void 0:Y.__urm_row_id__)!==void 0&&M.has(Y.__urm_row_id__)));ze(O)}S(`Showing ${C.length} favorite row${C.length===1?"":"s"}`,"info")}else{if(At!==null){const M=new Set(Array.from(Ne).map(te=>te==null?void 0:te.__urm_row_id__).filter(Boolean)),O=new Set(Array.from(At).map(te=>te==null?void 0:te.__urm_row_id__).filter(Boolean)),Y=new Set(C.map(te=>{var fe,Kt;return(Kt=(fe=a.uploadedData)==null?void 0:fe[te])==null?void 0:Kt.__urm_row_id__}).filter(te=>te!==void 0)),H=new Set;Array.from(At).forEach(te=>{const fe=te==null?void 0:te.__urm_row_id__;if(fe===void 0)return;const Kt=Y.has(fe),Fr=M.has(fe);Kt&&!Fr||H.add(te)}),Array.from(Ne).forEach(te=>{const fe=te==null?void 0:te.__urm_row_id__;fe!==void 0&&(O.has(fe)||H.add(te))}),ze(H),bt(null)}S("Showing all data","info")}},[a,L,Ne,At]),ps=u.useCallback(C=>{if(a){if(!mt("edit_columns",Se)){S(ft("edit_columns"),"error");return}if(C&&a.schema){const{validGrouping:E,invalidColumns:M}=Ei(C,a.schema);M.length>0&&S(`Removed invalid grouping columns: ${M.join(", ")}`,"warning"),it();try{const O=a.grouping;E===null?je("grouping","group_cleared",O,null):O?je("grouping","group_reordered",O,E):je("grouping","group_level_added",null,E);const Y=(X==null?void 0:X.snapshot.columnOrder)||a.columnOrder||[],H=Jr(Y,E);L(a.id,{grouping:E,columnOrder:H}),JSON.stringify(H)!==JSON.stringify(a.columnOrder)&&je("columns","column_reordered",a.columnOrder,H),rt(!1)}catch(O){const Y=Et("processing","grouping",O);He(Y)}}else{const E=a.grouping;je("grouping","group_cleared",E,null);const M=(X==null?void 0:X.snapshot.columnOrder)||a.columnOrder||[];L(a.id,{grouping:C,columnOrder:[...M]}),JSON.stringify(M)!==JSON.stringify(a.columnOrder)&&je("columns","column_reordered",a.columnOrder,M),rt(!1)}}},[a,X,Se,L,it,He,je]),xs=u.useCallback(C=>{if(!a)return;const E=a.grouping;if(!E)return;const M=ia(E,C);L(a.id,{grouping:M})},[a,L]),ms=u.useCallback(()=>{St(!0)},[]),Lr=u.useCallback(C=>{a!=null&&a.schema&&(N(!0),setTimeout(()=>{try{let E;C.scope==="visible"?E=Ht:E=a.uploadedData||[];let M;C.columnScope==="all"?(M={},(a.schema??[]).forEach(fe=>{M[fe.name]=!0})):M=a.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{};const O=a.columnOrder||(X==null?void 0:X.snapshot.columnOrder),Y=yo(E,a.schema,a.filters??[],a.sortStack??[],X,M,O),H=a.name;let te;switch(C.format){case"csv":bo(Y,H,C),te="export_csv";break;case"excel":vo(Y,H,C),te="export_excel";break;case"json":So(Y,H,C),te="export_json";break}je("export",te,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:E.length,viewName:(X==null?void 0:X.name)||"Default View"}),S(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(E){const M=Ha(E,{onRetry:()=>Lr(C)});S(`Export failed: ${M.message}. Click Export to retry.`,"error");const O=In(a.id,ht,M,a.auditHistory||[]);L(a.id,{auditHistory:O}),Qt.error("urm:report-engine","Export failed",E)}finally{N(!1)}},500))},[a,X,Ht,L,je]),fs=u.useCallback(C=>{if(a!=null&&a.schema){if(wt&&X&&!X.isDefault){he(C.format),le(!0),St(!1);return}Lr(C),St(!1)}},[a,X,wt,Lr]),no=u.useCallback(C=>{Lr({format:C,scope:"visible",columnScope:"visible"})},[Lr]),hs=u.useCallback(()=>{se&&no(se),le(!1),he(null)},[se,no]),gs=u.useCallback(()=>{xt(),se&&no(se),le(!1),he(null)},[xt,se,no]),ys=u.useCallback(()=>{le(!1),he(null)},[]),bs=u.useCallback(C=>{!(a!=null&&a.schema)||Ne.size===0||(N(!0),setTimeout(()=>{try{const E=Array.from(Ne),M=yo(E,a.schema,a.filters??[],a.sortStack??[],X),O=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":bo(M,O);break;case"excel":vo(M,O);break;case"json":So(M,O);break}S(`Exported ${E.length} selected rows`,"info")}catch(E){S("Export failed. Please try again.","error"),Qt.error("urm:report-engine","Bulk export failed",E)}finally{N(!1)}},500))},[a,X,Ne,Ut]),vs=u.useCallback((C,E)=>{if(a)try{const M=za(a),O=Ea(C,E,ht,M),Y=Ba(a.presets,O);L(a.id,{presets:Y}),je("presets","preset_created",null,{presetId:O.id,name:O.name}),sr(!1),S(`Preset "${C}" saved successfully`,"success")}catch(M){S(M instanceof Error?M.message:"Failed to create preset","error")}},[a,L,je]),Ss=u.useCallback(()=>{vt(null),S("Exited preset view","info")},[]),js=u.useCallback(()=>{Lt(!0)},[]),Cs=u.useCallback((C,E)=>{if(!a)return;const M=Da(a.presets,C);L(a.id,{presets:M}),je("presets","preset_deleted",{presetId:C,name:E},null),dt===C&&vt(null),S(`Preset "${E}" deleted`,"success")},[a,dt,L,je]);u.useEffect(()=>{if(!d||p.length===0)return;const C=p.find(E=>E.id===d);C&&C.id!==b&&x(C.id)},[d,p,b]),u.useEffect(()=>{if(!a)return;const C=Oa();if(C&&a.presets&&a.schemaLocked&&a.schema){const E=Tn(a.presets,C);if(E){const{sanitizedConfig:M,warnings:O}=Va(E.config,a.schema);O.length>0&&O.forEach(H=>S(H,"warning"));const Y=Aa(M);L(a.id,Y),vt(C),je("presets","preset_applied",null,{presetId:E.id,name:E.name}),S(`Loaded preset: ${E.name}`,"info")}else S("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const ws=dt?Tn(a==null?void 0:a.presets,dt):void 0;u.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&da(a.id,{views:a.views,activeViewId:a.activeViewId})},[a==null?void 0:a.views,a==null?void 0:a.activeViewId,a==null?void 0:a.id]),u.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=ua(a.id);if(C&&C.views.length>0){const E=C.views.find(M=>M.id===C.activeViewId);if(E)L(a.id,{views:C.views,activeViewId:C.activeViewId,filters:E.snapshot.filters.length>0?E.snapshot.filters:void 0,sortStack:E.snapshot.sortStack.length>0?E.snapshot.sortStack:void 0});else{const M=C.views.find(O=>O.isDefault)||Lo(a.schema);L(a.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})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const ks=u.useCallback(C=>{var O;const E=(a==null?void 0:a.filters)??[],M=((O=f.filter)==null?void 0:O.maxConditions)??3;if(E.length>=M){S(`Filter limit reached — maximum ${M} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}F(C),G(!0)},[a,f,S]),Ts=u.useCallback(()=>{G(!1),F(void 0)},[]),Is=(hn=a==null?void 0:a.views)==null?void 0:hn.find(C=>C.id===re),zs=(gn=a==null?void 0:a.views)==null?void 0:gn.find(C=>C.id===Q);return{reports:p,activeReport:a,activeReportId:b,setActiveReportId:x,isModalOpen:g,setIsModalOpen:I,createReport:st,updateReport:L,uploadState:_,handleFileUpload:dr,handleUploadError:ut,handleRetry:Ue,handleConfirm:ur,paginatedData:_t,processedData:Ht,displayData:Ut,tableMetrics:Br,isGrouped:Yt,tableEngine:Ct,activeView:X,isDirty:wt,currentTableState:Ce,viewChanges:we,filters:a==null?void 0:a.filters,showFilterPanel:R,setShowFilterPanel:G,filterFocusColumn:A,handleAddFilter:Mt,handleUpdateFilter:Gt,handleRemoveFilter:Qe,handleClearAllFilters:at,handleReplaceFilters:We,handleOpenFilterForColumn:ks,handleCloseFilterPanel:Ts,handleClearFiltersForColumn:$e,sortStack:a==null?void 0:a.sortStack,showSortPanel:Z,setShowSortPanel:ee,handleSort:pr,handleUpdateSortStack:xr,handleSortAscending:kt,handleSortDescending:Dr,views:a==null?void 0:a.views,showManageViews:h,setShowManageViews:$,showCreateViewModal:W,setShowCreateViewModal:V,showEditViewModal:K,setShowEditViewModal:pe,showDeleteConfirmation:xe,setShowDeleteConfirmation:oe,editingView:Is,deletingView:zs,editingViewId:re,deletingViewId:Q,handleSelectView:pt,handleCreateView:mr,handleUpdateCurrentView:xt,handleSaveColumnConfigToCurrentView:Or,handleSaveColumnConfigToAllViews:Ar,handleSaveAsNewView:_r,handleRevertChanges:Mr,handleToggleDefault:fr,handleToggleFavorite:$r,handleSoftDelete:Rr,handleRestoreView:Wr,handlePermanentDelete:$t,handleEditView:hr,handleSaveEditView:Pr,handleDeleteView:qt,handleConfirmDelete:Oe,handlePromoteToGlobal:lt,showManageColumns:J,setShowManageColumns:_e,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:Tt,handleUpdateColumnOrder:de,handleUpdateColumnWidth:me,handleResetColumnLayout:D,showGroupPanel:Ve,setShowGroupPanel:rt,grouping:a==null?void 0:a.grouping,groupingState:nr,handleGroup:ps,handleToggleGroupCollapse:xs,searchQuery:Nt,searchHistory:ha((a==null?void 0:a.searchHistory)||[]),handleSearchChange:ue,handleAddToSearchHistory:Pe,handleToggleSearchFavourite:ce,handleDeleteSearchHistory:It,selectedRowIds:Ne,handleToggleRowSelection:No,handleToggleAllRows:is,handleRangeSelection:ss,handleClearSelection:as,handleUpdateSelectionAfterDelete:ls,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:Vt,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:cs,handleBulkSetFavorites:ds,handleToggleFavoritesFilter:us,currentPage:Ke,pageSize:Xe,paginationEngine:Me,handlePageChange:Jt,handlePageSizeChange:Nr,isExporting:ne,showExportModal:ar,setShowExportModal:St,showDirtyExportWarning:ie,handleExport:ms,handleExportWithConfig:fs,handleExportSelected:bs,handleExportAnyway:hs,handleSaveAndExport:gs,handleCancelExport:ys,showAuditHistory:Ze,setShowAuditHistory:ot,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:Re,setShowCreatePreset:sr,showManagePresets:kr,setShowManagePresets:Lt,activePreset:ws,activePresetId:dt,handleOpenManagePresets:js,handleCreatePreset:vs,handleClearActivePreset:Ss,handleDeletePresetById:Cs,userRole:Se,isViewerRole:zr,currentUserId:ht,featureLimitWarning:Tr,setFeatureLimitWarning:jt,datasetMeta:cr,reportError:nt,setReportError:Ir,handleError:He,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?Xs(a.schema):!1,snack:v,handleSnackClose:T,showSnack:S}}const Bi=u.createContext(void 0);function sn(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:c,mode:d="builder",autoLoad:l=!0,config:p,devConfig:m,showDevPanel:f=!1,sharedReportId:b}=t,g=il({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:s,sharedReportId:b,config:p}),[I,y]=u.useState(()=>As()),j=(()=>{const T=Ms(I,m,!!m);return{...T,display:{...T.display,showDevPanel:f||T.display.showDevPanel}}})(),v=u.useCallback(S=>{y(S),_s(S)},[]),k={...g,activeDevConfig:j,handleDevConfigChange:v};return e.jsx(gi.Provider,{value:j,children:e.jsx(Bi.Provider,{value:k,children:o})})}function ko(){const t=u.useContext(Bi);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(c=>c.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(w.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",color:"text.primary",letterSpacing:"-0.01em",cursor:o.length>0&&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(w.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:e.jsx(r.Button,{variant:"contained",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function er(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 lo={exports:{}},co={exports:{}},ge={};/** @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 kn;function ol(){if(kn)return me;kn=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,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,f=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,T=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,w=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,j=t?Symbol.for("react.scope"):60119;function S(a){if(typeof a=="object"&&a!==null){var A=a.$$typeof;switch(A){case o:switch(a=a.type,a){case u:case m:case i:case c:case s:case b:return a;default:switch(a=a&&a.$$typeof,a){case l:case h:case T:case g:case d:return a;default:return A}}case n:return A}}}function I(a){return S(a)===m}return me.AsyncMode=u,me.ConcurrentMode=m,me.ContextConsumer=l,me.ContextProvider=d,me.Element=o,me.ForwardRef=h,me.Fragment=i,me.Lazy=T,me.Memo=g,me.Portal=n,me.Profiler=c,me.StrictMode=s,me.Suspense=b,me.isAsyncMode=function(a){return I(a)||S(a)===u},me.isConcurrentMode=I,me.isContextConsumer=function(a){return S(a)===l},me.isContextProvider=function(a){return S(a)===d},me.isElement=function(a){return typeof a=="object"&&a!==null&&a.$$typeof===o},me.isForwardRef=function(a){return S(a)===h},me.isFragment=function(a){return S(a)===i},me.isLazy=function(a){return S(a)===T},me.isMemo=function(a){return S(a)===g},me.isPortal=function(a){return S(a)===n},me.isProfiler=function(a){return S(a)===c},me.isStrictMode=function(a){return S(a)===s},me.isSuspense=function(a){return S(a)===b},me.isValidElementType=function(a){return typeof a=="string"||typeof a=="function"||a===i||a===m||a===c||a===s||a===b||a===f||typeof a=="object"&&a!==null&&(a.$$typeof===T||a.$$typeof===g||a.$$typeof===d||a.$$typeof===l||a.$$typeof===h||a.$$typeof===w||a.$$typeof===v||a.$$typeof===j||a.$$typeof===y)},me.typeOf=S,me}var fe={};/** @license React v16.13.1
10
+ */var En;function cl(){if(En)return ge;En=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,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,p=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,x=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,I=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,k=t?Symbol.for("react.scope"):60119;function S(a){if(typeof a=="object"&&a!==null){var _=a.$$typeof;switch(_){case o:switch(a=a.type,a){case p:case m:case i:case c:case s:case b:return a;default:switch(a=a&&a.$$typeof,a){case l:case f:case I:case g:case d:return a;default:return _}}case n:return _}}}function T(a){return S(a)===m}return ge.AsyncMode=p,ge.ConcurrentMode=m,ge.ContextConsumer=l,ge.ContextProvider=d,ge.Element=o,ge.ForwardRef=f,ge.Fragment=i,ge.Lazy=I,ge.Memo=g,ge.Portal=n,ge.Profiler=c,ge.StrictMode=s,ge.Suspense=b,ge.isAsyncMode=function(a){return T(a)||S(a)===p},ge.isConcurrentMode=T,ge.isContextConsumer=function(a){return S(a)===l},ge.isContextProvider=function(a){return S(a)===d},ge.isElement=function(a){return typeof a=="object"&&a!==null&&a.$$typeof===o},ge.isForwardRef=function(a){return S(a)===f},ge.isFragment=function(a){return S(a)===i},ge.isLazy=function(a){return S(a)===I},ge.isMemo=function(a){return S(a)===g},ge.isPortal=function(a){return S(a)===n},ge.isProfiler=function(a){return S(a)===c},ge.isStrictMode=function(a){return S(a)===s},ge.isSuspense=function(a){return S(a)===b},ge.isValidElementType=function(a){return typeof a=="string"||typeof a=="function"||a===i||a===m||a===c||a===s||a===b||a===x||typeof a=="object"&&a!==null&&(a.$$typeof===I||a.$$typeof===g||a.$$typeof===d||a.$$typeof===l||a.$$typeof===f||a.$$typeof===j||a.$$typeof===v||a.$$typeof===k||a.$$typeof===y)},ge.typeOf=S,ge}var ye={};/** @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 Tn;function nl(){return Tn||(Tn=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,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,f=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,T=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,w=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,j=t?Symbol.for("react.scope"):60119;function S(q){return typeof q=="string"||typeof q=="function"||q===i||q===m||q===c||q===s||q===b||q===f||typeof q=="object"&&q!==null&&(q.$$typeof===T||q.$$typeof===g||q.$$typeof===d||q.$$typeof===l||q.$$typeof===h||q.$$typeof===w||q.$$typeof===v||q.$$typeof===j||q.$$typeof===y)}function I(q){if(typeof q=="object"&&q!==null){var Ae=q.$$typeof;switch(Ae){case o:var We=q.type;switch(We){case u:case m:case i:case c:case s:case b:return We;default:var tt=We&&We.$$typeof;switch(tt){case l:case h:case T:case g:case d:return tt;default:return Ae}}case n:return Ae}}}var a=u,A=m,B=l,$=d,Y=o,Q=h,te=i,x=T,N=g,W=n,H=c,J=s,ue=b,pe=!1;function re(q){return pe||(pe=!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.")),O(q)||I(q)===u}function O(q){return I(q)===m}function F(q){return I(q)===l}function G(q){return I(q)===d}function se(q){return typeof q=="object"&&q!==null&&q.$$typeof===o}function ee(q){return I(q)===h}function le(q){return I(q)===i}function ae(q){return I(q)===T}function P(q){return I(q)===g}function ne(q){return I(q)===n}function ce(q){return I(q)===c}function ie(q){return I(q)===s}function he(q){return I(q)===b}fe.AsyncMode=a,fe.ConcurrentMode=A,fe.ContextConsumer=B,fe.ContextProvider=$,fe.Element=Y,fe.ForwardRef=Q,fe.Fragment=te,fe.Lazy=x,fe.Memo=N,fe.Portal=W,fe.Profiler=H,fe.StrictMode=J,fe.Suspense=ue,fe.isAsyncMode=re,fe.isConcurrentMode=O,fe.isContextConsumer=F,fe.isContextProvider=G,fe.isElement=se,fe.isForwardRef=ee,fe.isFragment=le,fe.isLazy=ae,fe.isMemo=P,fe.isPortal=ne,fe.isProfiler=ce,fe.isStrictMode=ie,fe.isSuspense=he,fe.isValidElementType=S,fe.typeOf=I})()),fe}var In;function Ii(){return In||(In=1,process.env.NODE_ENV==="production"?oo.exports=ol():oo.exports=nl()),oo.exports}/*
17
+ */var Bn;function dl(){return Bn||(Bn=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,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,p=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,x=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,I=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,k=t?Symbol.for("react.scope"):60119;function S(J){return typeof J=="string"||typeof J=="function"||J===i||J===m||J===c||J===s||J===b||J===x||typeof J=="object"&&J!==null&&(J.$$typeof===I||J.$$typeof===g||J.$$typeof===d||J.$$typeof===l||J.$$typeof===f||J.$$typeof===j||J.$$typeof===v||J.$$typeof===k||J.$$typeof===y)}function T(J){if(typeof J=="object"&&J!==null){var _e=J.$$typeof;switch(_e){case o:var Ve=J.type;switch(Ve){case p:case m:case i:case c:case s:case b:return Ve;default:var rt=Ve&&Ve.$$typeof;switch(rt){case l:case f:case I:case g:case d:return rt;default:return _e}}case n:return _e}}}var a=p,_=m,z=l,R=d,G=o,Z=f,ee=i,h=I,$=g,W=n,V=c,K=s,pe=b,xe=!1;function oe(J){return xe||(xe=!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)||T(J)===p}function A(J){return T(J)===m}function F(J){return T(J)===l}function re(J){return T(J)===d}function q(J){return typeof J=="object"&&J!==null&&J.$$typeof===o}function Q(J){return T(J)===f}function ae(J){return T(J)===i}function ne(J){return T(J)===I}function N(J){return T(J)===g}function ie(J){return T(J)===n}function le(J){return T(J)===c}function se(J){return T(J)===s}function he(J){return T(J)===b}ye.AsyncMode=a,ye.ConcurrentMode=_,ye.ContextConsumer=z,ye.ContextProvider=R,ye.Element=G,ye.ForwardRef=Z,ye.Fragment=ee,ye.Lazy=h,ye.Memo=$,ye.Portal=W,ye.Profiler=V,ye.StrictMode=K,ye.Suspense=pe,ye.isAsyncMode=oe,ye.isConcurrentMode=A,ye.isContextConsumer=F,ye.isContextProvider=re,ye.isElement=q,ye.isForwardRef=Q,ye.isFragment=ae,ye.isLazy=ne,ye.isMemo=N,ye.isPortal=ie,ye.isProfiler=le,ye.isStrictMode=se,ye.isSuspense=he,ye.isValidElementType=S,ye.typeOf=T})()),ye}var Dn;function Di(){return Dn||(Dn=1,process.env.NODE_ENV==="production"?co.exports=cl():co.exports=dl()),co.exports}/*
18
18
  object-assign
19
19
  (c) Sindre Sorhus
20
20
  @license MIT
21
- */var $o,zn;function il(){if(zn)return $o;zn=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 s(){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 m={};return"abcdefghijklmnopqrst".split("").forEach(function(h){m[h]=h}),Object.keys(Object.assign({},m)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return $o=s()?Object.assign:function(c,d){for(var l,u=i(c),m,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){m=t(l);for(var f=0;f<m.length;f++)n.call(l,m[f])&&(u[m[f]]=l[m[f]])}}return u},$o}var Wo,En;function tn(){if(En)return Wo;En=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Wo=t,Wo}var Ro,Bn;function zi(){return Bn||(Bn=1,Ro=Function.call.bind(Object.prototype.hasOwnProperty)),Ro}var Po,Dn;function sl(){if(Dn)return Po;Dn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=tn(),n={},i=zi();t=function(c){var d="Warning: "+c;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function s(c,d,l,u,m){if(process.env.NODE_ENV!=="production"){for(var h in c)if(i(c,h)){var b;try{if(typeof c[h]!="function"){var f=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 f.name="Invariant Violation",f}b=c[h](d,h,u,l,null,o)}catch(T){b=T}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 g=m?m():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Po=s,Po}var No,On;function al(){if(On)return No;On=1;var t=Ii(),o=il(),n=tn(),i=zi(),s=sl(),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 No=function(l,u){var m=typeof Symbol=="function"&&Symbol.iterator,h="@@iterator";function b(O){var F=O&&(m&&O[m]||O[h]);if(typeof F=="function")return F}var f="<<anonymous>>",g={array:v("array"),bigint:v("bigint"),bool:v("boolean"),func:v("function"),number:v("number"),object:v("object"),string:v("string"),symbol:v("symbol"),any:j(),arrayOf:S,element:I(),elementType:a(),instanceOf:A,node:Q(),objectOf:$,oneOf:B,oneOfType:Y,shape:x,exact:N};function T(O,F){return O===F?O!==0||1/O===1/F:O!==O&&F!==F}function y(O,F){this.message=O,this.data=F&&typeof F=="object"?F:{},this.stack=""}y.prototype=Error.prototype;function w(O){if(process.env.NODE_ENV!=="production")var F={},G=0;function se(le,ae,P,ne,ce,ie,he){if(ne=ne||f,ie=ie||P,he!==n){if(u){var q=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw q.name="Invariant Violation",q}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var Ae=ne+":"+P;!F[Ae]&&G<3&&(c("You are manually calling a React.PropTypes validation function for the `"+ie+"` prop on `"+ne+"`. 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."),F[Ae]=!0,G++)}}return ae[P]==null?le?ae[P]===null?new y("The "+ce+" `"+ie+"` is marked as required "+("in `"+ne+"`, but its value is `null`.")):new y("The "+ce+" `"+ie+"` is marked as required in "+("`"+ne+"`, but its value is `undefined`.")):null:O(ae,P,ne,ce,ie)}var ee=se.bind(null,!1);return ee.isRequired=se.bind(null,!0),ee}function v(O){function F(G,se,ee,le,ae,P){var ne=G[se],ce=J(ne);if(ce!==O){var ie=ue(ne);return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ie+"` supplied to `"+ee+"`, expected ")+("`"+O+"`."),{expectedType:O})}return null}return w(F)}function j(){return w(d)}function S(O){function F(G,se,ee,le,ae){if(typeof O!="function")return new y("Property `"+ae+"` of component `"+ee+"` has invalid PropType notation inside arrayOf.");var P=G[se];if(!Array.isArray(P)){var ne=J(P);return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ne+"` supplied to `"+ee+"`, expected an array."))}for(var ce=0;ce<P.length;ce++){var ie=O(P,ce,ee,le,ae+"["+ce+"]",n);if(ie instanceof Error)return ie}return null}return w(F)}function I(){function O(F,G,se,ee,le){var ae=F[G];if(!l(ae)){var P=J(ae);return new y("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+se+"`, expected a single ReactElement."))}return null}return w(O)}function a(){function O(F,G,se,ee,le){var ae=F[G];if(!t.isValidElementType(ae)){var P=J(ae);return new y("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+se+"`, expected a single ReactElement type."))}return null}return w(O)}function A(O){function F(G,se,ee,le,ae){if(!(G[se]instanceof O)){var P=O.name||f,ne=re(G[se]);return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ne+"` supplied to `"+ee+"`, expected ")+("instance of `"+P+"`."))}return null}return w(F)}function B(O){if(!Array.isArray(O))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 F(G,se,ee,le,ae){for(var P=G[se],ne=0;ne<O.length;ne++)if(T(P,O[ne]))return null;var ce=JSON.stringify(O,function(he,q){var Ae=ue(q);return Ae==="symbol"?String(q):q});return new y("Invalid "+le+" `"+ae+"` of value `"+String(P)+"` "+("supplied to `"+ee+"`, expected one of "+ce+"."))}return w(F)}function $(O){function F(G,se,ee,le,ae){if(typeof O!="function")return new y("Property `"+ae+"` of component `"+ee+"` has invalid PropType notation inside objectOf.");var P=G[se],ne=J(P);if(ne!=="object")return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ne+"` supplied to `"+ee+"`, expected an object."));for(var ce in P)if(i(P,ce)){var ie=O(P,ce,ee,le,ae+"."+ce,n);if(ie instanceof Error)return ie}return null}return w(F)}function Y(O){if(!Array.isArray(O))return process.env.NODE_ENV!=="production"&&c("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var F=0;F<O.length;F++){var G=O[F];if(typeof G!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+pe(G)+" at index "+F+"."),d}function se(ee,le,ae,P,ne){for(var ce=[],ie=0;ie<O.length;ie++){var he=O[ie],q=he(ee,le,ae,P,ne,n);if(q==null)return null;q.data&&i(q.data,"expectedType")&&ce.push(q.data.expectedType)}var Ae=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new y("Invalid "+P+" `"+ne+"` supplied to "+("`"+ae+"`"+Ae+"."))}return w(se)}function Q(){function O(F,G,se,ee,le){return W(F[G])?null:new y("Invalid "+ee+" `"+le+"` supplied to "+("`"+se+"`, expected a ReactNode."))}return w(O)}function te(O,F,G,se,ee){return new y((O||"React class")+": "+F+" type `"+G+"."+se+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ee+"`.")}function x(O){function F(G,se,ee,le,ae){var P=G[se],ne=J(P);if(ne!=="object")return new y("Invalid "+le+" `"+ae+"` of type `"+ne+"` "+("supplied to `"+ee+"`, expected `object`."));for(var ce in O){var ie=O[ce];if(typeof ie!="function")return te(ee,le,ae,ce,ue(ie));var he=ie(P,ce,ee,le,ae+"."+ce,n);if(he)return he}return null}return w(F)}function N(O){function F(G,se,ee,le,ae){var P=G[se],ne=J(P);if(ne!=="object")return new y("Invalid "+le+" `"+ae+"` of type `"+ne+"` "+("supplied to `"+ee+"`, expected `object`."));var ce=o({},G[se],O);for(var ie in ce){var he=O[ie];if(i(O,ie)&&typeof he!="function")return te(ee,le,ae,ie,ue(he));if(!he)return new y("Invalid "+le+" `"+ae+"` key `"+ie+"` supplied to `"+ee+"`.\nBad object: "+JSON.stringify(G[se],null," ")+`
22
- Valid keys: `+JSON.stringify(Object.keys(O),null," "));var q=he(P,ie,ee,le,ae+"."+ie,n);if(q)return q}return null}return w(F)}function W(O){switch(typeof O){case"number":case"string":case"undefined":return!0;case"boolean":return!O;case"object":if(Array.isArray(O))return O.every(W);if(O===null||l(O))return!0;var F=b(O);if(F){var G=F.call(O),se;if(F!==O.entries){for(;!(se=G.next()).done;)if(!W(se.value))return!1}else for(;!(se=G.next()).done;){var ee=se.value;if(ee&&!W(ee[1]))return!1}}else return!1;return!0;default:return!1}}function H(O,F){return O==="symbol"?!0:F?F["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&F instanceof Symbol:!1}function J(O){var F=typeof O;return Array.isArray(O)?"array":O instanceof RegExp?"object":H(F,O)?"symbol":F}function ue(O){if(typeof O>"u"||O===null)return""+O;var F=J(O);if(F==="object"){if(O instanceof Date)return"date";if(O instanceof RegExp)return"regexp"}return F}function pe(O){var F=ue(O);switch(F){case"array":case"object":return"an "+F;case"boolean":case"date":case"regexp":return"a "+F;default:return F}}function re(O){return!O.constructor||!O.constructor.name?f:O.constructor.name}return g.checkPropTypes=s,g.resetWarningCache=s.resetWarningCache,g.PropTypes=g,g},No}var Lo,An;function ll(){if(An)return Lo;An=1;var t=tn();function o(){}function n(){}return n.resetWarningCache=o,Lo=function(){function i(d,l,u,m,h,b){if(b!==t){var f=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 f.name="Invariant Violation",f}}i.isRequired=i;function s(){return i}var c={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 c.PropTypes=c,c},Lo}var Mn;function cl(){if(Mn)return ro.exports;if(Mn=1,process.env.NODE_ENV!=="production"){var t=Ii(),o=!0;ro.exports=al()(t.isElement,o)}else ro.exports=ll()();return ro.exports}var dl=cl();const Rr=rl(dl);var no={exports:{}},Ce={};/**
21
+ */var Vo,On;function ul(){if(On)return Vo;On=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 s(){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 p=Object.getOwnPropertyNames(d).map(function(f){return d[f]});if(p.join("")!=="0123456789")return!1;var m={};return"abcdefghijklmnopqrst".split("").forEach(function(f){m[f]=f}),Object.keys(Object.assign({},m)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return Vo=s()?Object.assign:function(c,d){for(var l,p=i(c),m,f=1;f<arguments.length;f++){l=Object(arguments[f]);for(var b in l)o.call(l,b)&&(p[b]=l[b]);if(t){m=t(l);for(var x=0;x<m.length;x++)n.call(l,m[x])&&(p[m[x]]=l[m[x]])}}return p},Vo}var Ho,An;function an(){if(An)return Ho;An=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Ho=t,Ho}var Uo,_n;function Oi(){return _n||(_n=1,Uo=Function.call.bind(Object.prototype.hasOwnProperty)),Uo}var Yo,Mn;function pl(){if(Mn)return Yo;Mn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=an(),n={},i=Oi();t=function(c){var d="Warning: "+c;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function s(c,d,l,p,m){if(process.env.NODE_ENV!=="production"){for(var f in c)if(i(c,f)){var b;try{if(typeof c[f]!="function"){var x=Error((p||"React class")+": "+l+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof c[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw x.name="Invariant Violation",x}b=c[f](d,f,p,l,null,o)}catch(I){b=I}if(b&&!(b instanceof Error)&&t((p||"React class")+": type specification of "+l+" `"+f+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof b+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),b instanceof Error&&!(b.message in n)){n[b.message]=!0;var g=m?m():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Yo=s,Yo}var Go,$n;function xl(){if($n)return Go;$n=1;var t=Di(),o=ul(),n=an(),i=Oi(),s=pl(),c=function(){};process.env.NODE_ENV!=="production"&&(c=function(l){var p="Warning: "+l;typeof console<"u"&&console.error(p);try{throw new Error(p)}catch{}});function d(){return null}return Go=function(l,p){var m=typeof Symbol=="function"&&Symbol.iterator,f="@@iterator";function b(A){var F=A&&(m&&A[m]||A[f]);if(typeof F=="function")return F}var x="<<anonymous>>",g={array:v("array"),bigint:v("bigint"),bool:v("boolean"),func:v("function"),number:v("number"),object:v("object"),string:v("string"),symbol:v("symbol"),any:k(),arrayOf:S,element:T(),elementType:a(),instanceOf:_,node:Z(),objectOf:R,oneOf:z,oneOfType:G,shape:h,exact:$};function I(A,F){return A===F?A!==0||1/A===1/F:A!==A&&F!==F}function y(A,F){this.message=A,this.data=F&&typeof F=="object"?F:{},this.stack=""}y.prototype=Error.prototype;function j(A){if(process.env.NODE_ENV!=="production")var F={},re=0;function q(ae,ne,N,ie,le,se,he){if(ie=ie||x,se=se||N,he!==n){if(p){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 _e=ie+":"+N;!F[_e]&&re<3&&(c("You are manually calling a React.PropTypes validation function for the `"+se+"` 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."),F[_e]=!0,re++)}}return ne[N]==null?ae?ne[N]===null?new y("The "+le+" `"+se+"` is marked as required "+("in `"+ie+"`, but its value is `null`.")):new y("The "+le+" `"+se+"` is marked as required in "+("`"+ie+"`, but its value is `undefined`.")):null:A(ne,N,ie,le,se)}var Q=q.bind(null,!1);return Q.isRequired=q.bind(null,!0),Q}function v(A){function F(re,q,Q,ae,ne,N){var ie=re[q],le=K(ie);if(le!==A){var se=pe(ie);return new y("Invalid "+ae+" `"+ne+"` of type "+("`"+se+"` supplied to `"+Q+"`, expected ")+("`"+A+"`."),{expectedType:A})}return null}return j(F)}function k(){return j(d)}function S(A){function F(re,q,Q,ae,ne){if(typeof A!="function")return new y("Property `"+ne+"` of component `"+Q+"` has invalid PropType notation inside arrayOf.");var N=re[q];if(!Array.isArray(N)){var ie=K(N);return new y("Invalid "+ae+" `"+ne+"` of type "+("`"+ie+"` supplied to `"+Q+"`, expected an array."))}for(var le=0;le<N.length;le++){var se=A(N,le,Q,ae,ne+"["+le+"]",n);if(se instanceof Error)return se}return null}return j(F)}function T(){function A(F,re,q,Q,ae){var ne=F[re];if(!l(ne)){var N=K(ne);return new y("Invalid "+Q+" `"+ae+"` of type "+("`"+N+"` supplied to `"+q+"`, expected a single ReactElement."))}return null}return j(A)}function a(){function A(F,re,q,Q,ae){var ne=F[re];if(!t.isValidElementType(ne)){var N=K(ne);return new y("Invalid "+Q+" `"+ae+"` of type "+("`"+N+"` supplied to `"+q+"`, expected a single ReactElement type."))}return null}return j(A)}function _(A){function F(re,q,Q,ae,ne){if(!(re[q]instanceof A)){var N=A.name||x,ie=oe(re[q]);return new y("Invalid "+ae+" `"+ne+"` of type "+("`"+ie+"` supplied to `"+Q+"`, expected ")+("instance of `"+N+"`."))}return null}return j(F)}function z(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 F(re,q,Q,ae,ne){for(var N=re[q],ie=0;ie<A.length;ie++)if(I(N,A[ie]))return null;var le=JSON.stringify(A,function(he,J){var _e=pe(J);return _e==="symbol"?String(J):J});return new y("Invalid "+ae+" `"+ne+"` of value `"+String(N)+"` "+("supplied to `"+Q+"`, expected one of "+le+"."))}return j(F)}function R(A){function F(re,q,Q,ae,ne){if(typeof A!="function")return new y("Property `"+ne+"` of component `"+Q+"` has invalid PropType notation inside objectOf.");var N=re[q],ie=K(N);if(ie!=="object")return new y("Invalid "+ae+" `"+ne+"` of type "+("`"+ie+"` supplied to `"+Q+"`, expected an object."));for(var le in N)if(i(N,le)){var se=A(N,le,Q,ae,ne+"."+le,n);if(se instanceof Error)return se}return null}return j(F)}function G(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 F=0;F<A.length;F++){var re=A[F];if(typeof re!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+xe(re)+" at index "+F+"."),d}function q(Q,ae,ne,N,ie){for(var le=[],se=0;se<A.length;se++){var he=A[se],J=he(Q,ae,ne,N,ie,n);if(J==null)return null;J.data&&i(J.data,"expectedType")&&le.push(J.data.expectedType)}var _e=le.length>0?", expected one of type ["+le.join(", ")+"]":"";return new y("Invalid "+N+" `"+ie+"` supplied to "+("`"+ne+"`"+_e+"."))}return j(q)}function Z(){function A(F,re,q,Q,ae){return W(F[re])?null:new y("Invalid "+Q+" `"+ae+"` supplied to "+("`"+q+"`, expected a ReactNode."))}return j(A)}function ee(A,F,re,q,Q){return new y((A||"React class")+": "+F+" type `"+re+"."+q+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+Q+"`.")}function h(A){function F(re,q,Q,ae,ne){var N=re[q],ie=K(N);if(ie!=="object")return new y("Invalid "+ae+" `"+ne+"` of type `"+ie+"` "+("supplied to `"+Q+"`, expected `object`."));for(var le in A){var se=A[le];if(typeof se!="function")return ee(Q,ae,ne,le,pe(se));var he=se(N,le,Q,ae,ne+"."+le,n);if(he)return he}return null}return j(F)}function $(A){function F(re,q,Q,ae,ne){var N=re[q],ie=K(N);if(ie!=="object")return new y("Invalid "+ae+" `"+ne+"` of type `"+ie+"` "+("supplied to `"+Q+"`, expected `object`."));var le=o({},re[q],A);for(var se in le){var he=A[se];if(i(A,se)&&typeof he!="function")return ee(Q,ae,ne,se,pe(he));if(!he)return new y("Invalid "+ae+" `"+ne+"` key `"+se+"` supplied to `"+Q+"`.\nBad object: "+JSON.stringify(re[q],null," ")+`
22
+ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var J=he(N,se,Q,ae,ne+"."+se,n);if(J)return J}return null}return j(F)}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 F=b(A);if(F){var re=F.call(A),q;if(F!==A.entries){for(;!(q=re.next()).done;)if(!W(q.value))return!1}else for(;!(q=re.next()).done;){var Q=q.value;if(Q&&!W(Q[1]))return!1}}else return!1;return!0;default:return!1}}function V(A,F){return A==="symbol"?!0:F?F["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&F instanceof Symbol:!1}function K(A){var F=typeof A;return Array.isArray(A)?"array":A instanceof RegExp?"object":V(F,A)?"symbol":F}function pe(A){if(typeof A>"u"||A===null)return""+A;var F=K(A);if(F==="object"){if(A instanceof Date)return"date";if(A instanceof RegExp)return"regexp"}return F}function xe(A){var F=pe(A);switch(F){case"array":case"object":return"an "+F;case"boolean":case"date":case"regexp":return"a "+F;default:return F}}function oe(A){return!A.constructor||!A.constructor.name?x:A.constructor.name}return g.checkPropTypes=s,g.resetWarningCache=s.resetWarningCache,g.PropTypes=g,g},Go}var qo,Rn;function ml(){if(Rn)return qo;Rn=1;var t=an();function o(){}function n(){}return n.resetWarningCache=o,qo=function(){function i(d,l,p,m,f,b){if(b!==t){var x=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw x.name="Invariant Violation",x}}i.isRequired=i;function s(){return i}var c={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 c.PropTypes=c,c},qo}var Wn;function fl(){if(Wn)return lo.exports;if(Wn=1,process.env.NODE_ENV!=="production"){var t=Di(),o=!0;lo.exports=xl()(t.isElement,o)}else lo.exports=ml()();return lo.exports}var hl=fl();const Ur=ll(hl);var uo={exports:{}},ke={};/**
23
23
  * @license React
24
24
  * react-is.production.js
25
25
  *
@@ -27,7 +27,7 @@ Valid keys: `+JSON.stringify(Object.keys(O),null," "));var q=he(P,ie,ee,le,ae+"
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 _n;function ul(){if(_n)return Ce;_n=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"),c=Symbol.for("react.consumer"),d=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),f=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function T(y){if(typeof y=="object"&&y!==null){var w=y.$$typeof;switch(w){case t:switch(y=y.type,y){case n:case s:case i:case u:case m:case f:return y;default:switch(y=y&&y.$$typeof,y){case d:case l:case b:case h:return y;case c:return y;default:return w}}case o:return w}}}return Ce.ContextConsumer=c,Ce.ContextProvider=d,Ce.Element=t,Ce.ForwardRef=l,Ce.Fragment=n,Ce.Lazy=b,Ce.Memo=h,Ce.Portal=o,Ce.Profiler=s,Ce.StrictMode=i,Ce.Suspense=u,Ce.SuspenseList=m,Ce.isContextConsumer=function(y){return T(y)===c},Ce.isContextProvider=function(y){return T(y)===d},Ce.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},Ce.isForwardRef=function(y){return T(y)===l},Ce.isFragment=function(y){return T(y)===n},Ce.isLazy=function(y){return T(y)===b},Ce.isMemo=function(y){return T(y)===h},Ce.isPortal=function(y){return T(y)===o},Ce.isProfiler=function(y){return T(y)===s},Ce.isStrictMode=function(y){return T(y)===i},Ce.isSuspense=function(y){return T(y)===u},Ce.isSuspenseList=function(y){return T(y)===m},Ce.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===s||y===i||y===u||y===m||typeof y=="object"&&y!==null&&(y.$$typeof===b||y.$$typeof===h||y.$$typeof===d||y.$$typeof===c||y.$$typeof===l||y.$$typeof===g||y.getModuleId!==void 0)},Ce.typeOf=T,Ce}var we={};/**
30
+ */var Pn;function gl(){if(Pn)return ke;Pn=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"),c=Symbol.for("react.consumer"),d=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),x=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function I(y){if(typeof y=="object"&&y!==null){var j=y.$$typeof;switch(j){case t:switch(y=y.type,y){case n:case s:case i:case p:case m:case x:return y;default:switch(y=y&&y.$$typeof,y){case d:case l:case b:case f:return y;case c:return y;default:return j}}case o:return j}}}return ke.ContextConsumer=c,ke.ContextProvider=d,ke.Element=t,ke.ForwardRef=l,ke.Fragment=n,ke.Lazy=b,ke.Memo=f,ke.Portal=o,ke.Profiler=s,ke.StrictMode=i,ke.Suspense=p,ke.SuspenseList=m,ke.isContextConsumer=function(y){return I(y)===c},ke.isContextProvider=function(y){return I(y)===d},ke.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},ke.isForwardRef=function(y){return I(y)===l},ke.isFragment=function(y){return I(y)===n},ke.isLazy=function(y){return I(y)===b},ke.isMemo=function(y){return I(y)===f},ke.isPortal=function(y){return I(y)===o},ke.isProfiler=function(y){return I(y)===s},ke.isStrictMode=function(y){return I(y)===i},ke.isSuspense=function(y){return I(y)===p},ke.isSuspenseList=function(y){return I(y)===m},ke.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===s||y===i||y===p||y===m||typeof y=="object"&&y!==null&&(y.$$typeof===b||y.$$typeof===f||y.$$typeof===d||y.$$typeof===c||y.$$typeof===l||y.$$typeof===g||y.getModuleId!==void 0)},ke.typeOf=I,ke}var Te={};/**
31
31
  * @license React
32
32
  * react-is.development.js
33
33
  *
@@ -35,16 +35,16 @@ Valid keys: `+JSON.stringify(Object.keys(O),null," "));var q=he(P,ie,ee,le,ae+"
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 $n;function pl(){return $n||($n=1,process.env.NODE_ENV!=="production"&&(function(){function t(y){if(typeof y=="object"&&y!==null){var w=y.$$typeof;switch(w){case o:switch(y=y.type,y){case i:case c:case s:case m:case h:case g:return y;default:switch(y=y&&y.$$typeof,y){case l:case u:case f:case b:return y;case d:return y;default:return w}}case n:return w}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),T=Symbol.for("react.client.reference");we.ContextConsumer=d,we.ContextProvider=l,we.Element=o,we.ForwardRef=u,we.Fragment=i,we.Lazy=f,we.Memo=b,we.Portal=n,we.Profiler=c,we.StrictMode=s,we.Suspense=m,we.SuspenseList=h,we.isContextConsumer=function(y){return t(y)===d},we.isContextProvider=function(y){return t(y)===l},we.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===o},we.isForwardRef=function(y){return t(y)===u},we.isFragment=function(y){return t(y)===i},we.isLazy=function(y){return t(y)===f},we.isMemo=function(y){return t(y)===b},we.isPortal=function(y){return t(y)===n},we.isProfiler=function(y){return t(y)===c},we.isStrictMode=function(y){return t(y)===s},we.isSuspense=function(y){return t(y)===m},we.isSuspenseList=function(y){return t(y)===h},we.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===i||y===c||y===s||y===m||y===h||typeof y=="object"&&y!==null&&(y.$$typeof===f||y.$$typeof===b||y.$$typeof===l||y.$$typeof===d||y.$$typeof===u||y.$$typeof===T||y.getModuleId!==void 0)},we.typeOf=t})()),we}var Wn;function xl(){return Wn||(Wn=1,process.env.NODE_ENV==="production"?no.exports=ul():no.exports=pl()),no.exports}var Ei=xl();function Bt(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 Bi(t){if(fo.isValidElement(t)||Ei.isValidElementType(t)||!Bt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Bi(t[n])}),o}function qe(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Bt(t)&&Bt(o)&&Object.keys(o).forEach(s=>{fo.isValidElement(o[s])||Ei.isValidElementType(o[s])?i[s]=o[s]:Bt(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Bt(t[s])?i[s]=qe(t[s],o[s],n):n.clone?i[s]=Bt(o[s])?Bi(o[s]):o[s]:i[s]=o[s]}),i}const ml=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 fl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=t,c=ml(o),d=Object.keys(c);function l(f){return`@media (min-width:${typeof o[f]=="number"?o[f]:f}${n})`}function u(f){return`@media (max-width:${(typeof o[f]=="number"?o[f]:f)-i/100}${n})`}function m(f,g){const T=d.indexOf(g);return`@media (min-width:${typeof o[f]=="number"?o[f]:f}${n}) and (max-width:${(T!==-1&&typeof o[d[T]]=="number"?o[d[T]]:g)-i/100}${n})`}function h(f){return d.indexOf(f)+1<d.length?m(f,d[d.indexOf(f)+1]):l(f)}function b(f){const g=d.indexOf(f);return g===0?l(d[1]):g===d.length-1?u(d[g]):m(f,d[d.indexOf(f)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:u,between:m,only:h,not:b,unit:n,...s}}function Rn(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,s)=>{var d,l;const c=/min-width:\s*([0-9.]+)/;return+(((d=i.match(c))==null?void 0:d[1])||0)-+(((l=s.match(c))==null?void 0:l[1])||0)});return n.length?n.reduce((i,s)=>{const c=o[s];return delete i[s],i[s]=c,i},{...o}):o}function hl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function gl(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,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(s).up(c)}function yl(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={},s=c=>(n(i,c),i);return n(s),{...t,containerQueries:s}}const bl={borderRadius:4},Ot=process.env.NODE_ENV!=="production"?Rr.oneOfType([Rr.number,Rr.string,Rr.object,Rr.array]):{};function Yr(t,o){return o?qe(t,o,{clone:!1}):t}const yo={xs:0,sm:600,md:900,lg:1200,xl:1536},Pn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${yo[t]}px)`},vl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:yo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function kt(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Pn;return o.reduce((d,l,u)=>(d[c.up(c.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Pn;return Object.keys(o).reduce((d,l)=>{if(hl(c.keys,l)){const u=gl(i.containerQueries?i:vl,l);u&&(d[u]=n(o[l],l))}else if(Object.keys(c.values||yo).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 Sl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const c=t.up(s);return i[c]={},i},{}))||{}}function Nn(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function Di(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":Yt(7));return t.charAt(0).toUpperCase()+t.slice(1)}function bo(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((s,c)=>s&&s[c]?s[c]:null,t);if(i!=null)return i}return o.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,t)}function mo(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=bo(t,n)||i,o&&(s=o(s,i,t)),s}function Be(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:s}=t,c=d=>{if(d[o]==null)return null;const l=d[o],u=d.theme,m=bo(u,i)||{};return kt(d,l,b=>{let f=mo(m,s,b);return b===f&&typeof b=="string"&&(f=mo(m,s,`${o}${b==="default"?"":Di(b)}`,b)),n===!1?f:{[n]:f}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Ot}:{},c.filterProps=[o],c}function jl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const Cl={m:"margin",p:"padding"},wl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Ln={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},kl=jl(t=>{if(t.length>2)if(Ln[t])t=Ln[t];else return[t];const[o,n]=t.split(""),i=Cl[o],s=wl[n]||"";return Array.isArray(s)?s.map(c=>i+c):[i+s]}),vo=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],So=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Tl=[...vo,...So];function qr(t,o,n,i){const s=bo(t,o,!0)??n;return typeof s=="number"||typeof s=="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 s=="string"?s.startsWith("var(")&&c===0?0:s.startsWith("var(")&&c===1?s:`calc(${c} * ${s})`:s*c):Array.isArray(s)?c=>{if(typeof c=="string")return c;const d=Math.abs(c);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>s.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${d} > ${s.length-1}, you need to add the missing values.`].join(`
38
+ */var Nn;function yl(){return Nn||(Nn=1,process.env.NODE_ENV!=="production"&&(function(){function t(y){if(typeof y=="object"&&y!==null){var j=y.$$typeof;switch(j){case o:switch(y=y.type,y){case i:case c:case s:case m:case f:case g:return y;default:switch(y=y&&y.$$typeof,y){case l:case p:case x:case b:return y;case d:return y;default:return j}}case n:return j}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),I=Symbol.for("react.client.reference");Te.ContextConsumer=d,Te.ContextProvider=l,Te.Element=o,Te.ForwardRef=p,Te.Fragment=i,Te.Lazy=x,Te.Memo=b,Te.Portal=n,Te.Profiler=c,Te.StrictMode=s,Te.Suspense=m,Te.SuspenseList=f,Te.isContextConsumer=function(y){return t(y)===d},Te.isContextProvider=function(y){return t(y)===l},Te.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===o},Te.isForwardRef=function(y){return t(y)===p},Te.isFragment=function(y){return t(y)===i},Te.isLazy=function(y){return t(y)===x},Te.isMemo=function(y){return t(y)===b},Te.isPortal=function(y){return t(y)===n},Te.isProfiler=function(y){return t(y)===c},Te.isStrictMode=function(y){return t(y)===s},Te.isSuspense=function(y){return t(y)===m},Te.isSuspenseList=function(y){return t(y)===f},Te.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===i||y===c||y===s||y===m||y===f||typeof y=="object"&&y!==null&&(y.$$typeof===x||y.$$typeof===b||y.$$typeof===l||y.$$typeof===d||y.$$typeof===p||y.$$typeof===I||y.getModuleId!==void 0)},Te.typeOf=t})()),Te}var Ln;function bl(){return Ln||(Ln=1,process.env.NODE_ENV==="production"?uo.exports=gl():uo.exports=yl()),uo.exports}var Ai=bl();function Rt(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 _i(t){if(Co.isValidElement(t)||Ai.isValidElementType(t)||!Rt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=_i(t[n])}),o}function Je(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Rt(t)&&Rt(o)&&Object.keys(o).forEach(s=>{Co.isValidElement(o[s])||Ai.isValidElementType(o[s])?i[s]=o[s]:Rt(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Rt(t[s])?i[s]=Je(t[s],o[s],n):n.clone?i[s]=Rt(o[s])?_i(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,c=vl(o),d=Object.keys(c);function l(x){return`@media (min-width:${typeof o[x]=="number"?o[x]:x}${n})`}function p(x){return`@media (max-width:${(typeof o[x]=="number"?o[x]:x)-i/100}${n})`}function m(x,g){const I=d.indexOf(g);return`@media (min-width:${typeof o[x]=="number"?o[x]:x}${n}) and (max-width:${(I!==-1&&typeof o[d[I]]=="number"?o[d[I]]:g)-i/100}${n})`}function f(x){return d.indexOf(x)+1<d.length?m(x,d[d.indexOf(x)+1]):l(x)}function b(x){const g=d.indexOf(x);return g===0?l(d[1]):g===d.length-1?p(d[g]):m(x,d[d.indexOf(x)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:p,between:m,only:f,not:b,unit:n,...s}}function Fn(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,s)=>{var d,l;const c=/min-width:\s*([0-9.]+)/;return+(((d=i.match(c))==null?void 0:d[1])||0)-+(((l=s.match(c))==null?void 0:l[1])||0)});return n.length?n.reduce((i,s)=>{const c=o[s];return delete i[s],i[s]=c,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,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(s).up(c)}function wl(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 p=o(t.breakpoints.not(...l),d);return p.includes("not all and")?p.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):p}}const i={},s=c=>(n(i,c),i);return n(s),{...t,containerQueries:s}}const kl={borderRadius:4},Pt=process.env.NODE_ENV!=="production"?Ur.oneOfType([Ur.number,Ur.string,Ur.object,Ur.array]):{};function Qr(t,o){return o?Je(t,o,{clone:!1}):t}const To={xs:0,sm:600,md:900,lg:1200,xl:1536},Vn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${To[t]}px)`},Tl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:To[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function Dt(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Vn;return o.reduce((d,l,p)=>(d[c.up(c.keys[p])]=n(o[p]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Vn;return Object.keys(o).reduce((d,l)=>{if(jl(c.keys,l)){const p=Cl(i.containerQueries?i:Tl,l);p&&(d[p]=n(o[l],l))}else if(Object.keys(c.values||To).includes(l)){const p=c.up(l);d[p]=n(o[l],l)}else{const p=l;d[p]=o[p]}return d},{})}return n(o)}function Il(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const c=t.up(s);return i[c]={},i},{}))||{}}function Hn(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function Mi(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":er(7));return t.charAt(0).toUpperCase()+t.slice(1)}function Io(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((s,c)=>s&&s[c]?s[c]:null,t);if(i!=null)return i}return o.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,t)}function jo(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=Io(t,n)||i,o&&(s=o(s,i,t)),s}function De(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:s}=t,c=d=>{if(d[o]==null)return null;const l=d[o],p=d.theme,m=Io(p,i)||{};return Dt(d,l,b=>{let x=jo(m,s,b);return b===x&&typeof b=="string"&&(x=jo(m,s,`${o}${b==="default"?"":Mi(b)}`,b)),n===!1?x:{[n]:x}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Pt}:{},c.filterProps=[o],c}function zl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const El={m:"margin",p:"padding"},Bl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Un={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},Dl=zl(t=>{if(t.length>2)if(Un[t])t=Un[t];else return[t];const[o,n]=t.split(""),i=El[o],s=Bl[n]||"";return Array.isArray(s)?s.map(c=>i+c):[i+s]}),zo=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],Eo=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Ol=[...zo,...Eo];function to(t,o,n,i){const s=Io(t,o,!0)??n;return typeof s=="number"||typeof s=="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 s=="string"?s.startsWith("var(")&&c===0?0:s.startsWith("var(")&&c===1?s:`calc(${c} * ${s})`:s*c):Array.isArray(s)?c=>{if(typeof c=="string")return c;const d=Math.abs(c);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>s.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${d} > ${s.length-1}, you need to add the missing values.`].join(`
40
40
  `)):console.error([`MUI: The \`theme.${o}\` array type cannot be combined with non integer values.You should either use an integer value that can be used as index, or define the \`theme.${o}\` as a number.`].join(`
41
41
  `)));const l=s[d];return c>=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 rn(t){return qr(t,"spacing",8,"spacing")}function Jr(t,o){return typeof o=="string"||o==null?o:t(o)}function Il(t,o){return n=>t.reduce((i,s)=>(i[s]=Jr(o,n),i),{})}function zl(t,o,n,i){if(!o.includes(n))return null;const s=kl(n),c=Il(s,i),d=t[n];return kt(t,d,c)}function Oi(t,o){const n=rn(t.theme);return Object.keys(t).map(i=>zl(t,o,i,n)).reduce(Yr,{})}function Ie(t){return Oi(t,vo)}Ie.propTypes=process.env.NODE_ENV!=="production"?vo.reduce((t,o)=>(t[o]=Ot,t),{}):{};Ie.filterProps=vo;function ze(t){return Oi(t,So)}ze.propTypes=process.env.NODE_ENV!=="production"?So.reduce((t,o)=>(t[o]=Ot,t),{}):{};ze.filterProps=So;process.env.NODE_ENV!=="production"&&Tl.reduce((t,o)=>(t[o]=Ot,t),{});function Ai(t=8,o=rn({spacing:t})){if(t.mui)return t;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(c=>{const d=o(c);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function jo(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(c=>{i[c]=s}),i),{}),n=i=>Object.keys(i).reduce((s,c)=>o[c]?Yr(s,o[c](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=t.reduce((i,s)=>i.concat(s.filterProps),[]),n}function Qe(t){return typeof t!="number"?t:`${t}px solid`}function et(t,o){return Be({prop:t,themeKey:"borders",transform:o})}const El=et("border",Qe),Bl=et("borderTop",Qe),Dl=et("borderRight",Qe),Ol=et("borderBottom",Qe),Al=et("borderLeft",Qe),Ml=et("borderColor"),_l=et("borderTopColor"),$l=et("borderRightColor"),Wl=et("borderBottomColor"),Rl=et("borderLeftColor"),Pl=et("outline",Qe),Nl=et("outlineColor"),Co=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=qr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Jr(o,i)});return kt(t,t.borderRadius,n)}return null};Co.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Ot}:{};Co.filterProps=["borderRadius"];jo(El,Bl,Dl,Ol,Al,Ml,_l,$l,Wl,Rl,Co,Pl,Nl);const wo=t=>{if(t.gap!==void 0&&t.gap!==null){const o=qr(t.theme,"spacing",8,"gap"),n=i=>({gap:Jr(o,i)});return kt(t,t.gap,n)}return null};wo.propTypes=process.env.NODE_ENV!=="production"?{gap:Ot}:{};wo.filterProps=["gap"];const ko=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=qr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Jr(o,i)});return kt(t,t.columnGap,n)}return null};ko.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Ot}:{};ko.filterProps=["columnGap"];const To=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=qr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Jr(o,i)});return kt(t,t.rowGap,n)}return null};To.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Ot}:{};To.filterProps=["rowGap"];const Ll=Be({prop:"gridColumn"}),Fl=Be({prop:"gridRow"}),Vl=Be({prop:"gridAutoFlow"}),Hl=Be({prop:"gridAutoColumns"}),Ul=Be({prop:"gridAutoRows"}),Yl=Be({prop:"gridTemplateColumns"}),Gl=Be({prop:"gridTemplateRows"}),ql=Be({prop:"gridTemplateAreas"}),Jl=Be({prop:"gridArea"});jo(wo,ko,To,Ll,Fl,Vl,Hl,Ul,Yl,Gl,ql,Jl);function fr(t,o){return o==="grey"?o:t}const Kl=Be({prop:"color",themeKey:"palette",transform:fr}),Xl=Be({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:fr}),Zl=Be({prop:"backgroundColor",themeKey:"palette",transform:fr});jo(Kl,Xl,Zl);function Ye(t){return t<=1&&t!==0?`${t*100}%`:t}const Ql=Be({prop:"width",transform:Ye}),on=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,c,d,l,u;const i=((d=(c=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||yo[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:Ye(n)}};return kt(t,t.maxWidth,o)}return null};on.filterProps=["maxWidth"];const ec=Be({prop:"minWidth",transform:Ye}),tc=Be({prop:"height",transform:Ye}),rc=Be({prop:"maxHeight",transform:Ye}),oc=Be({prop:"minHeight",transform:Ye});Be({prop:"size",cssProperty:"width",transform:Ye});Be({prop:"size",cssProperty:"height",transform:Ye});const nc=Be({prop:"boxSizing"});jo(Ql,on,ec,tc,rc,oc,nc);const Io={border:{themeKey:"borders",transform:Qe},borderTop:{themeKey:"borders",transform:Qe},borderRight:{themeKey:"borders",transform:Qe},borderBottom:{themeKey:"borders",transform:Qe},borderLeft:{themeKey:"borders",transform:Qe},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Qe},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Co},color:{themeKey:"palette",transform:fr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:fr},backgroundColor:{themeKey:"palette",transform:fr},p:{style:ze},pt:{style:ze},pr:{style:ze},pb:{style:ze},pl:{style:ze},px:{style:ze},py:{style:ze},padding:{style:ze},paddingTop:{style:ze},paddingRight:{style:ze},paddingBottom:{style:ze},paddingLeft:{style:ze},paddingX:{style:ze},paddingY:{style:ze},paddingInline:{style:ze},paddingInlineStart:{style:ze},paddingInlineEnd:{style:ze},paddingBlock:{style:ze},paddingBlockStart:{style:ze},paddingBlockEnd:{style:ze},m:{style:Ie},mt:{style:Ie},mr:{style:Ie},mb:{style:Ie},ml:{style:Ie},mx:{style:Ie},my:{style:Ie},margin:{style:Ie},marginTop:{style:Ie},marginRight:{style:Ie},marginBottom:{style:Ie},marginLeft:{style:Ie},marginX:{style:Ie},marginY:{style:Ie},marginInline:{style:Ie},marginInlineStart:{style:Ie},marginInlineEnd:{style:Ie},marginBlock:{style:Ie},marginBlockStart:{style:Ie},marginBlockEnd:{style:Ie},displayPrint:{cssProperty:!1,transform:t=>({"@media print":{display:t}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:wo},rowGap:{style:To},columnGap:{style:ko},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ye},maxWidth:{style:on},minWidth:{transform:Ye},height:{transform:Ye},maxHeight:{transform:Ye},minHeight:{transform:Ye},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function ic(...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 sc(t,o){return typeof t=="function"?t(o):t}function ac(){function t(n,i,s,c){const d={[n]:i,theme:s},l=c[n];if(!l)return{[n]:i};const{cssProperty:u=n,themeKey:m,transform:h,style:b}=l;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const f=bo(s,m)||{};return b?b(d):kt(d,i,T=>{let y=mo(f,h,T);return T===y&&typeof T=="string"&&(y=mo(f,h,`${n}${T==="default"?"":Di(T)}`,T)),u===!1?y:{[u]:y}})}function o(n){const{sx:i,theme:s={},nested:c}=n||{};if(!i)return null;const d=s.unstable_sxConfig??Io;function l(u){let m=u;if(typeof u=="function")m=u(s);else if(typeof u!="object")return u;if(!m)return null;const h=Sl(s.breakpoints),b=Object.keys(h);let f=h;return Object.keys(m).forEach(g=>{const T=sc(m[g],s);if(T!=null)if(typeof T=="object")if(d[g])f=Yr(f,t(g,T,s,d));else{const y=kt({theme:s},T,w=>({[g]:w}));ic(y,T)?f[g]=o({sx:T,theme:s,nested:!0}):f=Yr(f,y)}else f=Yr(f,t(g,T,s,d))}),!c&&s.modularCssLayers?{"@layer sx":Rn(s,Nn(b,f))}:Rn(s,Nn(b,f))}return Array.isArray(i)?i.map(l):l(i)}return o}const zo=ac();zo.filterProps=["sx"];function lc(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 Mi(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:c={},...d}=t,l=fl(n),u=Ai(s);let m=qe({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...bl,...c}},d);return m=yl(m),m.applyStyles=lc,m=o.reduce((h,b)=>qe(h,b),m),m.unstable_sxConfig={...Io,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(b){return zo({sx:b,theme:this})},m}function cc(t){return Object.keys(t).length===0}function dc(t=null){const o=fo.useContext(Ts.ThemeContext);return!o||cc(o)?t:o}const uc=Mi();function pc(t=uc){return dc(t)}const Fn=t=>t,xc=()=>{let t=Fn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Fn}}},mc=xc(),fc={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function hc(t,o,n="Mui"){const i=fc[o];return i?`${n}-${i}`:`${mc.generate(t)}-${o}`}function gc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function nn(t,o=0,n=1){return process.env.NODE_ENV!=="production"&&(t<o||t>n)&&console.error(`MUI: The value provided ${t} is out of range [${o}, ${n}].`),gc(t,o,n)}function yc(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 Dt(t){if(t.type)return t;if(t.charAt(0)==="#")return Dt(yc(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().`:Yt(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.`:Yt(10,s))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:s}}const bc=t=>{const o=Dt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Vr=(t,o)=>{try{return bc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function Eo(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((s,c)=>c<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 _i(t){t=Dt(t);const{values:o}=t,n=o[0],i=o[1]/100,s=o[2]/100,c=i*Math.min(s,1-s),d=(m,h=(m+n/30)%12)=>s-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])),Eo({type:l,values:u})}function Yo(t){t=Dt(t);let o=t.type==="hsl"||t.type==="hsla"?Dt(_i(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 Vn(t,o){const n=Yo(t),i=Yo(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function E(t,o){return t=Dt(t),o=nn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,Eo(t)}function Vt(t,o,n){try{return E(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Bo(t,o){if(t=Dt(t),o=nn(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 Eo(t)}function ye(t,o,n){try{return Bo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Do(t,o){if(t=Dt(t),o=nn(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 Eo(t)}function be(t,o,n){try{return Do(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function vc(t,o=.15){return Yo(t)>.5?Bo(t,o):Do(t,o)}function io(t,o,n){try{return vc(t,o)}catch{return t}}function Sc(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 Hn=(t,o,n,i=[])=>{let s=t;o.forEach((c,d)=>{d===o.length-1?Array.isArray(s)?s[Number(c)]=n:s&&typeof s=="object"&&(s[c]=n):s&&typeof s=="object"&&(s[c]||(s[c]=i.includes(c)?[]:{}),s=s[c])})},jc=(t,o,n)=>{function i(s,c=[],d=[]){Object.entries(s).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)},Cc=(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 Fo(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},c={},d={};return jc(t,(l,u,m)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const h=`--${n?`${n}-`:""}${l.join("-")}`,b=Cc(l,u);Object.assign(s,{[h]:b}),Hn(c,l,`var(${h})`,m),Hn(d,l,`var(${h}, ${b})`,m)}},l=>l[0]==="vars"),{css:s,vars:c,varsWithDefaults:d}}function wc(t,o={}){const{getSelector:n=v,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:u="light",...m}=t,{vars:h,css:b,varsWithDefaults:f}=Fo(m,o);let g=f;const T={},{[u]:y,...w}=d;if(Object.entries(w||{}).forEach(([I,a])=>{const{vars:A,css:B,varsWithDefaults:$}=Fo(a,o);g=qe(g,$),T[I]={css:B,vars:A}}),y){const{css:I,vars:a,varsWithDefaults:A}=Fo(y,o);g=qe(g,A),T[u]={css:I,vars:a}}function v(I,a){var B,$;let A=s;if(s==="class"&&(A=".%s"),s==="data"&&(A="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(A=`[${s}="%s"]`),I){if(A==="media")return t.defaultColorScheme===I?":root":{[`@media (prefers-color-scheme: ${(($=(B=d[I])==null?void 0:B.palette)==null?void 0:$.mode)||I})`]:{":root":a}};if(A)return t.defaultColorScheme===I?`:root, ${A.replace("%s",String(I))}`:A.replace("%s",String(I))}return":root"}return{vars:g,generateThemeVars:()=>{let I={...h};return Object.entries(T).forEach(([,{vars:a}])=>{I=qe(I,a)}),I},generateStyleSheets:()=>{var Y,Q;const I=[],a=t.defaultColorScheme||"light";function A(te,x){Object.keys(x).length&&I.push(typeof te=="string"?{[te]:{...x}}:te)}A(n(void 0,{...b}),b);const{[a]:B,...$}=T;if(B){const{css:te}=B,x=(Q=(Y=d[a])==null?void 0:Y.palette)==null?void 0:Q.mode,N=!i&&x?{colorScheme:x,...te}:{...te};A(n(a,{...N}),N)}return Object.entries($).forEach(([te,{css:x}])=>{var H,J;const N=(J=(H=d[te])==null?void 0:H.palette)==null?void 0:J.mode,W=!i&&N?{colorScheme:N,...x}:{...x};A(n(te,{...W}),W)}),c&&I.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)"}}),I}}}function kc(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 Gr={black:"#000",white:"#fff"},Tc={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"},dr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},ur={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Pr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},pr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},xr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},mr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function $i(){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:Gr.white,default:Gr.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 Wi=$i();function Ri(){return{text:{primary:Gr.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:Gr.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 Go=Ri();function Un(t,o,n,i){const s=i.light||i,c=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Do(t.main,s):o==="dark"&&(t.dark=Bo(t.main,c)))}function Yn(t,o,n,i,s){const c=s.light||s,d=s.dark||s*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(c*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function Ic(t="light"){return t==="dark"?{main:pr[200],light:pr[50],dark:pr[400]}:{main:pr[700],light:pr[400],dark:pr[800]}}function zc(t="light"){return t==="dark"?{main:dr[200],light:dr[50],dark:dr[400]}:{main:dr[500],light:dr[300],dark:dr[700]}}function Ec(t="light"){return t==="dark"?{main:ur[500],light:ur[300],dark:ur[700]}:{main:ur[700],light:ur[400],dark:ur[800]}}function Bc(t="light"){return t==="dark"?{main:xr[400],light:xr[300],dark:xr[700]}:{main:xr[700],light:xr[500],dark:xr[900]}}function Dc(t="light"){return t==="dark"?{main:mr[400],light:mr[300],dark:mr[700]}:{main:mr[800],light:mr[500],dark:mr[900]}}function Oc(t="light"){return t==="dark"?{main:Pr[400],light:Pr[300],dark:Pr[700]}:{main:"#ed6c02",light:Pr[500],dark:Pr[900]}}function Ac(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function sn(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...c}=t,d=t.primary||Ic(o),l=t.secondary||zc(o),u=t.error||Ec(o),m=t.info||Bc(o),h=t.success||Dc(o),b=t.warning||Oc(o);function f(w){if(s)return Ac(w);const v=Vn(w,Go.text.primary)>=n?Go.text.primary:Wi.text.primary;if(process.env.NODE_ENV!=="production"){const j=Vn(w,v);j<3&&console.error([`MUI: The contrast ratio of ${j}:1 for ${v} on ${w}`,"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 v}const g=({color:w,name:v,mainShade:j=500,lightShade:S=300,darkShade:I=700})=>{if(w={...w},!w.main&&w[j]&&(w.main=w[j]),!w.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${v?` (${v})`:""} provided to augmentColor(color) is invalid.
46
- The color object needs to have a \`main\` property or a \`${j}\` property.`:Yt(11,v?` (${v})`:"",j));if(typeof w.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${v?` (${v})`:""} provided to augmentColor(color) is invalid.
47
- \`color.main\` should be a string, but \`${JSON.stringify(w.main)}\` was provided instead.
42
+ `)),()=>{})}function ln(t){return to(t,"spacing",8,"spacing")}function ro(t,o){return typeof o=="string"||o==null?o:t(o)}function Al(t,o){return n=>t.reduce((i,s)=>(i[s]=ro(o,n),i),{})}function _l(t,o,n,i){if(!o.includes(n))return null;const s=Dl(n),c=Al(s,i),d=t[n];return Dt(t,d,c)}function $i(t,o){const n=ln(t.theme);return Object.keys(t).map(i=>_l(t,o,i,n)).reduce(Qr,{})}function Ee(t){return $i(t,zo)}Ee.propTypes=process.env.NODE_ENV!=="production"?zo.reduce((t,o)=>(t[o]=Pt,t),{}):{};Ee.filterProps=zo;function Be(t){return $i(t,Eo)}Be.propTypes=process.env.NODE_ENV!=="production"?Eo.reduce((t,o)=>(t[o]=Pt,t),{}):{};Be.filterProps=Eo;process.env.NODE_ENV!=="production"&&Ol.reduce((t,o)=>(t[o]=Pt,t),{});function Ri(t=8,o=ln({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 Bo(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(c=>{i[c]=s}),i),{}),n=i=>Object.keys(i).reduce((s,c)=>o[c]?Qr(s,o[c](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 et(t){return typeof t!="number"?t:`${t}px solid`}function tt(t,o){return De({prop:t,themeKey:"borders",transform:o})}const Ml=tt("border",et),$l=tt("borderTop",et),Rl=tt("borderRight",et),Wl=tt("borderBottom",et),Pl=tt("borderLeft",et),Nl=tt("borderColor"),Ll=tt("borderTopColor"),Fl=tt("borderRightColor"),Vl=tt("borderBottomColor"),Hl=tt("borderLeftColor"),Ul=tt("outline",et),Yl=tt("outlineColor"),Do=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=to(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:ro(o,i)});return Dt(t,t.borderRadius,n)}return null};Do.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Pt}:{};Do.filterProps=["borderRadius"];Bo(Ml,$l,Rl,Wl,Pl,Nl,Ll,Fl,Vl,Hl,Do,Ul,Yl);const Oo=t=>{if(t.gap!==void 0&&t.gap!==null){const o=to(t.theme,"spacing",8,"gap"),n=i=>({gap:ro(o,i)});return Dt(t,t.gap,n)}return null};Oo.propTypes=process.env.NODE_ENV!=="production"?{gap:Pt}:{};Oo.filterProps=["gap"];const Ao=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=to(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:ro(o,i)});return Dt(t,t.columnGap,n)}return null};Ao.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Pt}:{};Ao.filterProps=["columnGap"];const _o=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=to(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:ro(o,i)});return Dt(t,t.rowGap,n)}return null};_o.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Pt}:{};_o.filterProps=["rowGap"];const Gl=De({prop:"gridColumn"}),ql=De({prop:"gridRow"}),Jl=De({prop:"gridAutoFlow"}),Kl=De({prop:"gridAutoColumns"}),Xl=De({prop:"gridAutoRows"}),Zl=De({prop:"gridTemplateColumns"}),Ql=De({prop:"gridTemplateRows"}),ec=De({prop:"gridTemplateAreas"}),tc=De({prop:"gridArea"});Bo(Oo,Ao,_o,Gl,ql,Jl,Kl,Xl,Zl,Ql,ec,tc);function Cr(t,o){return o==="grey"?o:t}const rc=De({prop:"color",themeKey:"palette",transform:Cr}),oc=De({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:Cr}),nc=De({prop:"backgroundColor",themeKey:"palette",transform:Cr});Bo(rc,oc,nc);function Ge(t){return t<=1&&t!==0?`${t*100}%`:t}const ic=De({prop:"width",transform:Ge}),cn=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,c,d,l,p;const i=((d=(c=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||To[n];return i?((p=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:p.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Ge(n)}};return Dt(t,t.maxWidth,o)}return null};cn.filterProps=["maxWidth"];const sc=De({prop:"minWidth",transform:Ge}),ac=De({prop:"height",transform:Ge}),lc=De({prop:"maxHeight",transform:Ge}),cc=De({prop:"minHeight",transform:Ge});De({prop:"size",cssProperty:"width",transform:Ge});De({prop:"size",cssProperty:"height",transform:Ge});const dc=De({prop:"boxSizing"});Bo(ic,cn,sc,ac,lc,cc,dc);const Mo={border:{themeKey:"borders",transform:et},borderTop:{themeKey:"borders",transform:et},borderRight:{themeKey:"borders",transform:et},borderBottom:{themeKey:"borders",transform:et},borderLeft:{themeKey:"borders",transform:et},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:et},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Do},color:{themeKey:"palette",transform:Cr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:Cr},backgroundColor:{themeKey:"palette",transform:Cr},p:{style:Be},pt:{style:Be},pr:{style:Be},pb:{style:Be},pl:{style:Be},px:{style:Be},py:{style:Be},padding:{style:Be},paddingTop:{style:Be},paddingRight:{style:Be},paddingBottom:{style:Be},paddingLeft:{style:Be},paddingX:{style:Be},paddingY:{style:Be},paddingInline:{style:Be},paddingInlineStart:{style:Be},paddingInlineEnd:{style:Be},paddingBlock:{style:Be},paddingBlockStart:{style:Be},paddingBlockEnd:{style:Be},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:Oo},rowGap:{style:_o},columnGap:{style:Ao},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ge},maxWidth:{style:cn},minWidth:{transform:Ge},height:{transform:Ge},maxHeight:{transform:Ge},minHeight:{transform:Ge},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,c){const d={[n]:i,theme:s},l=c[n];if(!l)return{[n]:i};const{cssProperty:p=n,themeKey:m,transform:f,style:b}=l;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const x=Io(s,m)||{};return b?b(d):Dt(d,i,I=>{let y=jo(x,f,I);return I===y&&typeof I=="string"&&(y=jo(x,f,`${n}${I==="default"?"":Mi(I)}`,I)),p===!1?y:{[p]:y}})}function o(n){const{sx:i,theme:s={},nested:c}=n||{};if(!i)return null;const d=s.unstable_sxConfig??Mo;function l(p){let m=p;if(typeof p=="function")m=p(s);else if(typeof p!="object")return p;if(!m)return null;const f=Il(s.breakpoints),b=Object.keys(f);let x=f;return Object.keys(m).forEach(g=>{const I=pc(m[g],s);if(I!=null)if(typeof I=="object")if(d[g])x=Qr(x,t(g,I,s,d));else{const y=Dt({theme:s},I,j=>({[g]:j}));uc(y,I)?x[g]=o({sx:I,theme:s,nested:!0}):x=Qr(x,y)}else x=Qr(x,t(g,I,s,d))}),!c&&s.modularCssLayers?{"@layer sx":Fn(s,Hn(b,x))}:Fn(s,Hn(b,x))}return Array.isArray(i)?i.map(l):l(i)}return o}const $o=xc();$o.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 Wi(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:c={},...d}=t,l=Sl(n),p=Ri(s);let m=Je({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:p,shape:{...kl,...c}},d);return m=wl(m),m.applyStyles=mc,m=o.reduce((f,b)=>Je(f,b),m),m.unstable_sxConfig={...Mo,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(b){return $o({sx:b,theme:this})},m}function fc(t){return Object.keys(t).length===0}function hc(t=null){const o=Co.useContext(Os.ThemeContext);return!o||fc(o)?t:o}const gc=Wi();function yc(t=gc){return hc(t)}const Yn=t=>t,bc=()=>{let t=Yn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Yn}}},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 dn(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 Wt(t){if(t.type)return t;if(t.charAt(0)==="#")return Wt(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().`:er(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.`:er(10,s))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:s}}const kc=t=>{const o=Wt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Kr=(t,o)=>{try{return kc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function Ro(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((s,c)=>c<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 Pi(t){t=Wt(t);const{values:o}=t,n=o[0],i=o[1]/100,s=o[2]/100,c=i*Math.min(s,1-s),d=(m,f=(m+n/30)%12)=>s-c*Math.max(Math.min(f-3,9-f,1),-1);let l="rgb";const p=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return t.type==="hsla"&&(l+="a",p.push(o[3])),Ro({type:l,values:p})}function Qo(t){t=Wt(t);let o=t.type==="hsl"||t.type==="hsla"?Wt(Pi(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 Gn(t,o){const n=Qo(t),i=Qo(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function B(t,o){return t=Wt(t),o=dn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,Ro(t)}function Xt(t,o,n){try{return B(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Wo(t,o){if(t=Wt(t),o=dn(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 Ro(t)}function be(t,o,n){try{return Wo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Po(t,o){if(t=Wt(t),o=dn(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 Ro(t)}function ve(t,o,n){try{return Po(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Tc(t,o=.15){return Qo(t)>.5?Wo(t,o):Po(t,o)}function po(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 qn=(t,o,n,i=[])=>{let s=t;o.forEach((c,d)=>{d===o.length-1?Array.isArray(s)?s[Number(c)]=n:s&&typeof s=="object"&&(s[c]=n):s&&typeof s=="object"&&(s[c]||(s[c]=i.includes(c)?[]:{}),s=s[c])})},zc=(t,o,n)=>{function i(s,c=[],d=[]){Object.entries(s).forEach(([l,p])=>{(!n||n&&!n([...c,l]))&&p!=null&&(typeof p=="object"&&Object.keys(p).length>0?i(p,[...c,l],Array.isArray(p)?[...d,l]:d):o([...c,l],p,d))})}i(t)},Ec=(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 Jo(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},c={},d={};return zc(t,(l,p,m)=>{if((typeof p=="string"||typeof p=="number")&&(!i||!i(l,p))){const f=`--${n?`${n}-`:""}${l.join("-")}`,b=Ec(l,p);Object.assign(s,{[f]:b}),qn(c,l,`var(${f})`,m),qn(d,l,`var(${f}, ${b})`,m)}},l=>l[0]==="vars"),{css:s,vars:c,varsWithDefaults:d}}function Bc(t,o={}){const{getSelector:n=v,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:p="light",...m}=t,{vars:f,css:b,varsWithDefaults:x}=Jo(m,o);let g=x;const I={},{[p]:y,...j}=d;if(Object.entries(j||{}).forEach(([T,a])=>{const{vars:_,css:z,varsWithDefaults:R}=Jo(a,o);g=Je(g,R),I[T]={css:z,vars:_}}),y){const{css:T,vars:a,varsWithDefaults:_}=Jo(y,o);g=Je(g,_),I[p]={css:T,vars:a}}function v(T,a){var z,R;let _=s;if(s==="class"&&(_=".%s"),s==="data"&&(_="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(_=`[${s}="%s"]`),T){if(_==="media")return t.defaultColorScheme===T?":root":{[`@media (prefers-color-scheme: ${((R=(z=d[T])==null?void 0:z.palette)==null?void 0:R.mode)||T})`]:{":root":a}};if(_)return t.defaultColorScheme===T?`:root, ${_.replace("%s",String(T))}`:_.replace("%s",String(T))}return":root"}return{vars:g,generateThemeVars:()=>{let T={...f};return Object.entries(I).forEach(([,{vars:a}])=>{T=Je(T,a)}),T},generateStyleSheets:()=>{var G,Z;const T=[],a=t.defaultColorScheme||"light";function _(ee,h){Object.keys(h).length&&T.push(typeof ee=="string"?{[ee]:{...h}}:ee)}_(n(void 0,{...b}),b);const{[a]:z,...R}=I;if(z){const{css:ee}=z,h=(Z=(G=d[a])==null?void 0:G.palette)==null?void 0:Z.mode,$=!i&&h?{colorScheme:h,...ee}:{...ee};_(n(a,{...$}),$)}return Object.entries(R).forEach(([ee,{css:h}])=>{var V,K;const $=(K=(V=d[ee])==null?void 0:V.palette)==null?void 0:K.mode,W=!i&&$?{colorScheme:$,...h}:{...h};_(n(ee,{...W}),W)}),c&&T.push({":root":{"--__l-threshold":"0.7","--__l":"clamp(0, (l / var(--__l-threshold) - 1) * -infinity, 1)","--__a":"clamp(0.87, (l / var(--__l-threshold) - 1) * -infinity, 1)"}}),T}}}function Dc(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 eo={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"},gr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},yr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Yr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},br={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},vr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},Sr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Ni(){return{text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:eo.white,default:eo.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}}}const Li=Ni();function Fi(){return{text:{primary:eo.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:eo.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}}}const en=Fi();function Jn(t,o,n,i){const s=i.light||i,c=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Po(t.main,s):o==="dark"&&(t.dark=Wo(t.main,c)))}function Kn(t,o,n,i,s){const c=s.light||s,d=s.dark||s*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(c*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function Ac(t="light"){return t==="dark"?{main:br[200],light:br[50],dark:br[400]}:{main:br[700],light:br[400],dark:br[800]}}function _c(t="light"){return t==="dark"?{main:gr[200],light:gr[50],dark:gr[400]}:{main:gr[500],light:gr[300],dark:gr[700]}}function Mc(t="light"){return t==="dark"?{main:yr[500],light:yr[300],dark:yr[700]}:{main:yr[700],light:yr[400],dark:yr[800]}}function $c(t="light"){return t==="dark"?{main:vr[400],light:vr[300],dark:vr[700]}:{main:vr[700],light:vr[500],dark:vr[900]}}function Rc(t="light"){return t==="dark"?{main:Sr[400],light:Sr[300],dark:Sr[700]}:{main:Sr[800],light:Sr[500],dark:Sr[900]}}function Wc(t="light"){return t==="dark"?{main:Yr[400],light:Yr[300],dark:Yr[700]}:{main:"#ed6c02",light:Yr[500],dark:Yr[900]}}function Pc(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function un(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...c}=t,d=t.primary||Ac(o),l=t.secondary||_c(o),p=t.error||Mc(o),m=t.info||$c(o),f=t.success||Rc(o),b=t.warning||Wc(o);function x(j){if(s)return Pc(j);const v=Gn(j,en.text.primary)>=n?en.text.primary:Li.text.primary;if(process.env.NODE_ENV!=="production"){const k=Gn(j,v);k<3&&console.error([`MUI: The contrast ratio of ${k}:1 for ${v} 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 v}const g=({color:j,name:v,mainShade:k=500,lightShade:S=300,darkShade:T=700})=>{if(j={...j},!j.main&&j[k]&&(j.main=j[k]),!j.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${v?` (${v})`:""} provided to augmentColor(color) is invalid.
46
+ The color object needs to have a \`main\` property or a \`${k}\` property.`:er(11,v?` (${v})`:"",k));if(typeof j.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${v?` (${v})`:""} provided to augmentColor(color) is invalid.
47
+ \`color.main\` should be a string, but \`${JSON.stringify(j.main)}\` was provided instead.
48
48
 
49
49
  Did you intend to use one of the following approaches?
50
50
 
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
56
56
 
57
57
  const theme2 = createTheme({ palette: {
58
58
  primary: { main: green[500] },
59
- } });`:Yt(12,v?` (${v})`:"",JSON.stringify(w.main)));return s?(Yn(s,w,"light",S,i),Yn(s,w,"dark",I,i)):(Un(w,"light",S,i),Un(w,"dark",I,i)),w.contrastText||(w.contrastText=f(w.main)),w};let T;return o==="light"?T=$i():o==="dark"&&(T=Ri()),process.env.NODE_ENV!=="production"&&(T||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),qe({common:{...Gr},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:u,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:m,name:"info"}),success:g({color:h,name:"success"}),grey:Tc,contrastThreshold:n,getContrastText:f,augmentColor:g,tonalOffset:i,...T},c)}function Mc(t){const o={};return Object.entries(t).forEach(i=>{const[s,c]=i;typeof c=="object"&&(o[s]=`${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 _c(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function $c(t){return Math.round(t*1e5)/1e5}const Gn={textTransform:"uppercase"},qn='"Roboto", "Helvetica", "Arial", sans-serif';function Wc(t,o){const{fontFamily:n=qn,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:u=16,allVariants:m,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 f=i/14,g=h||(w=>`${w/u*f}rem`),T=(w,v,j,S,I)=>({fontFamily:n,fontWeight:w,fontSize:g(v),lineHeight:j,...n===qn?{letterSpacing:`${$c(S/v)}em`}:{},...I,...m}),y={h1:T(s,96,1.167,-1.5),h2:T(s,60,1.2,-.5),h3:T(c,48,1.167,0),h4:T(c,34,1.235,.25),h5:T(c,24,1.334,0),h6:T(d,20,1.6,.15),subtitle1:T(c,16,1.75,.15),subtitle2:T(d,14,1.57,.1),body1:T(c,16,1.5,.15),body2:T(c,14,1.43,.15),button:T(d,14,1.75,.4,Gn),caption:T(c,12,1.66,.4),overline:T(c,12,2.66,1,Gn),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return qe({htmlFontSize:u,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...y},b,{clone:!1})}const Rc=.2,Pc=.14,Nc=.12;function Te(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Rc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Pc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Nc})`].join(",")}const Lc=["none",Te(0,2,1,-1,0,1,1,0,0,1,3,0),Te(0,3,1,-2,0,2,2,0,0,1,5,0),Te(0,3,3,-2,0,3,4,0,0,1,8,0),Te(0,2,4,-1,0,4,5,0,0,1,10,0),Te(0,3,5,-1,0,5,8,0,0,1,14,0),Te(0,3,5,-1,0,6,10,0,0,1,18,0),Te(0,4,5,-2,0,7,10,1,0,2,16,1),Te(0,5,5,-3,0,8,10,1,0,3,14,2),Te(0,5,6,-3,0,9,12,1,0,3,16,2),Te(0,6,6,-3,0,10,14,1,0,4,18,3),Te(0,6,7,-4,0,11,15,1,0,4,20,3),Te(0,7,8,-4,0,12,17,2,0,5,22,4),Te(0,7,8,-4,0,13,19,2,0,5,24,4),Te(0,7,9,-4,0,14,21,2,0,5,26,4),Te(0,8,9,-5,0,15,22,2,0,6,28,5),Te(0,8,10,-5,0,16,24,2,0,6,30,5),Te(0,8,11,-5,0,17,26,2,0,6,32,5),Te(0,9,11,-5,0,18,28,2,0,7,34,6),Te(0,9,12,-6,0,19,29,2,0,7,36,6),Te(0,10,13,-6,0,20,31,3,0,8,38,7),Te(0,10,13,-6,0,21,33,3,0,8,40,7),Te(0,10,14,-6,0,22,35,3,0,8,42,7),Te(0,11,14,-7,0,23,36,3,0,9,44,8),Te(0,11,15,-7,0,24,38,3,0,9,46,8)],Fc={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)"},Vc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function Jn(t){return`${Math.round(t)}ms`}function Hc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Uc(t){const o={...Fc,...t.easing},n={...Vc,...t.duration};return{getAutoHeightDuration:Hc,create:(s=["all"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:u=0,...m}=c;if(process.env.NODE_ENV!=="production"){const h=f=>typeof f=="string",b=f=>!Number.isNaN(parseFloat(f));!h(s)&&!Array.isArray(s)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!h(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),h(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(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(h=>`${h} ${typeof d=="string"?d:Jn(d)} ${l} ${typeof u=="string"?u:Jn(u)}`).join(",")},...t,easing:o,duration:n}}const Yc={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function Gc(t){return Bt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Pi(t={}){const o={...t};function n(i){const s=Object.entries(i);for(let c=0;c<s.length;c++){const[d,l]=s[c];!Gc(l)||d.startsWith("unstable_")?delete i[d]:Bt(l)&&(i[d]={...l},n(i[d]))}}return n(o),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
59
+ } });`:er(12,v?` (${v})`:"",JSON.stringify(j.main)));return s?(Kn(s,j,"light",S,i),Kn(s,j,"dark",T,i)):(Jn(j,"light",S,i),Jn(j,"dark",T,i)),j.contrastText||(j.contrastText=x(j.main)),j};let I;return o==="light"?I=Ni():o==="dark"&&(I=Fi()),process.env.NODE_ENV!=="production"&&(I||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),Je({common:{...eo},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:p,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:m,name:"info"}),success:g({color:f,name:"success"}),grey:Oc,contrastThreshold:n,getContrastText:x,augmentColor:g,tonalOffset:i,...I},c)}function Nc(t){const o={};return Object.entries(t).forEach(i=>{const[s,c]=i;typeof c=="object"&&(o[s]=`${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 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 Xn={textTransform:"uppercase"},Zn='"Roboto", "Helvetica", "Arial", sans-serif';function Vc(t,o){const{fontFamily:n=Zn,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:p=16,allVariants:m,pxToRem:f,...b}=typeof o=="function"?o(t):o;process.env.NODE_ENV!=="production"&&(typeof i!="number"&&console.error("MUI: `fontSize` is required to be a number."),typeof p!="number"&&console.error("MUI: `htmlFontSize` is required to be a number."));const x=i/14,g=f||(j=>`${j/p*x}rem`),I=(j,v,k,S,T)=>({fontFamily:n,fontWeight:j,fontSize:g(v),lineHeight:k,...n===Zn?{letterSpacing:`${Fc(S/v)}em`}:{},...T,...m}),y={h1:I(s,96,1.167,-1.5),h2:I(s,60,1.2,-.5),h3:I(c,48,1.167,0),h4:I(c,34,1.235,.25),h5:I(c,24,1.334,0),h6:I(d,20,1.6,.15),subtitle1:I(c,16,1.75,.15),subtitle2:I(d,14,1.57,.1),body1:I(c,16,1.5,.15),body2:I(c,14,1.43,.15),button:I(d,14,1.75,.4,Xn),caption:I(c,12,1.66,.4),overline:I(c,12,2.66,1,Xn),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Je({htmlFontSize:p,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...y},b,{clone:!1})}const Hc=.2,Uc=.14,Yc=.12;function Ie(...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",Ie(0,2,1,-1,0,1,1,0,0,1,3,0),Ie(0,3,1,-2,0,2,2,0,0,1,5,0),Ie(0,3,3,-2,0,3,4,0,0,1,8,0),Ie(0,2,4,-1,0,4,5,0,0,1,10,0),Ie(0,3,5,-1,0,5,8,0,0,1,14,0),Ie(0,3,5,-1,0,6,10,0,0,1,18,0),Ie(0,4,5,-2,0,7,10,1,0,2,16,1),Ie(0,5,5,-3,0,8,10,1,0,3,14,2),Ie(0,5,6,-3,0,9,12,1,0,3,16,2),Ie(0,6,6,-3,0,10,14,1,0,4,18,3),Ie(0,6,7,-4,0,11,15,1,0,4,20,3),Ie(0,7,8,-4,0,12,17,2,0,5,22,4),Ie(0,7,8,-4,0,13,19,2,0,5,24,4),Ie(0,7,9,-4,0,14,21,2,0,5,26,4),Ie(0,8,9,-5,0,15,22,2,0,6,28,5),Ie(0,8,10,-5,0,16,24,2,0,6,30,5),Ie(0,8,11,-5,0,17,26,2,0,6,32,5),Ie(0,9,11,-5,0,18,28,2,0,7,34,6),Ie(0,9,12,-6,0,19,29,2,0,7,36,6),Ie(0,10,13,-6,0,20,31,3,0,8,38,7),Ie(0,10,13,-6,0,21,33,3,0,8,40,7),Ie(0,10,14,-6,0,22,35,3,0,8,42,7),Ie(0,11,14,-7,0,23,36,3,0,9,44,8),Ie(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 Qn(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"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:p=0,...m}=c;if(process.env.NODE_ENV!=="production"){const f=x=>typeof x=="string",b=x=>!Number.isNaN(parseFloat(x));!f(s)&&!Array.isArray(s)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!f(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),f(l)||console.error('MUI: Argument "easing" must be a string.'),!b(p)&&!f(p)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof c!="object"&&console.error(["MUI: Secong argument of transition.create must be an object.","Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join(`
60
+ `)),Object.keys(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(f=>`${f} ${typeof d=="string"?d:Qn(d)} ${l} ${typeof p=="string"?p:Qn(p)}`).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 Rt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Vi(t={}){const o={...t};function n(i){const s=Object.entries(i);for(let c=0;c<s.length;c++){const[d,l]=s[c];!Qc(l)||d.startsWith("unstable_")?delete i[d]:Rt(l)&&(i[d]={...l},n(i[d]))}}return n(o),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
61
61
 
62
62
  const theme = ${JSON.stringify(o,null,2)};
63
63
 
64
64
  theme.breakpoints = createBreakpoints(theme.breakpoints || {});
65
65
  theme.transitions = createTransitions(theme.transitions || {});
66
66
 
67
- export default theme;`}function Kn(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const qc=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 Jc(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})`:E(o,qc(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${Kn(n)})`:Do(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${Kn(n)})`:Bo(o,n)}})}function qo(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:c={},transitions:d={},typography:l={},shape:u,colorSpace:m,...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.":Yt(20));const b=sn({...c,colorSpace:m}),f=Mi(t);let g=qe(f,{mixins:_c(f.breakpoints,i),palette:b,shadows:Lc.slice(),typography:Wc(b,l),transitions:Uc(d),zIndex:{...Yc}});if(g=qe(g,h),g=o.reduce((T,y)=>qe(T,y),g),process.env.NODE_ENV!=="production"){const T=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],y=(w,v)=>{let j;for(j in w){const S=w[j];if(T.includes(j)&&Object.keys(S).length>0){if(process.env.NODE_ENV!=="production"){const I=hc("",j);console.error([`MUI: The \`${v}\` component increases the CSS specificity of the \`${j}\` internal state.`,"You can not override it like this: ",JSON.stringify(w,null,2),"",`Instead, you need to use the '&.${I}' syntax:`,JSON.stringify({root:{[`&.${I}`]:S}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
68
- `))}w[j]={}}}};Object.keys(g.components).forEach(w=>{const v=g.components[w].styleOverrides;v&&w.startsWith("Mui")&&y(v,w)})}return g.unstable_sxConfig={...Io,...h==null?void 0:h.unstable_sxConfig},g.unstable_sx=function(y){return zo({sx:y,theme:this})},g.toRuntimeSource=Pi,Jc(g),g}function Kc(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 Xc=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=Kc(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ni(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Li(t){return t==="dark"?Xc:[]}function Zc(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...c}=t,d=sn({...o,colorSpace:s});return{palette:d,opacity:{...Ni(d.mode),...n},overlays:i||Li(d.mode),...c}}function Qc(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 ed=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],td=t=>(o,n)=>{const i=t.rootSelector||":root",s=t.colorSchemeSelector;let c=s;if(s==="class"&&(c=".%s"),s==="data"&&(c="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(c=`[${s}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return ed(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 rd(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function R(t,o,n){!t[o]&&n&&(t[o]=n)}function Hr(t){return typeof t!="string"||!t.startsWith("hsl")?t:_i(t)}function jt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Vr(Hr(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 od(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const ft=t=>{try{return t()}catch{}},nd=(t="mui")=>Sc(t);function Vo(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const c=s==="dark"?"dark":"light";if(!i){o[s]=Zc({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=qo({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:d,opacity:{...Ni(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Li(c)},l}function id(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=Qc,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...h}=t,b=Object.keys(n)[0],f=i||(n.light&&b!=="light"?"light":b),g=nd(c),{[f]:T,light:y,dark:w,...v}=n,j={...v};let S=T;if((f==="dark"&&!("dark"in n)||f==="light"&&!("light"in n))&&(S=!0),!S)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${f}\` option is either missing or invalid.`:Yt(21,f));let I;d&&(I="oklch");const a=Vo(I,j,S,h,f);y&&!j.light&&Vo(I,j,y,void 0,"light"),w&&!j.dark&&Vo(I,j,w,void 0,"dark");let A={defaultColorScheme:f,...a,cssVarPrefix:c,colorSchemeSelector:u,rootSelector:m,getCssVar:g,colorSchemes:j,font:{...Mc(a.typography),...a.font},spacing:od(h.spacing)};Object.keys(A.colorSchemes).forEach(te=>{const x=A.colorSchemes[te].palette,N=H=>{const J=H.split("-"),ue=J[1],pe=J[2];return g(H,x[ue][pe])};x.mode==="light"&&(R(x.common,"background","#fff"),R(x.common,"onBackground","#000")),x.mode==="dark"&&(R(x.common,"background","#000"),R(x.common,"onBackground","#fff"));function W(H,J,ue){if(I){let pe;return H===Vt&&(pe=`transparent ${((1-ue)*100).toFixed(0)}%`),H===ye&&(pe=`#000 ${(ue*100).toFixed(0)}%`),H===be&&(pe=`#fff ${(ue*100).toFixed(0)}%`),`color-mix(in ${I}, ${J}, ${pe})`}return H(J,ue)}if(rd(x,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),x.mode==="light"){R(x.Alert,"errorColor",W(ye,x.error.light,.6)),R(x.Alert,"infoColor",W(ye,x.info.light,.6)),R(x.Alert,"successColor",W(ye,x.success.light,.6)),R(x.Alert,"warningColor",W(ye,x.warning.light,.6)),R(x.Alert,"errorFilledBg",N("palette-error-main")),R(x.Alert,"infoFilledBg",N("palette-info-main")),R(x.Alert,"successFilledBg",N("palette-success-main")),R(x.Alert,"warningFilledBg",N("palette-warning-main")),R(x.Alert,"errorFilledColor",ft(()=>x.getContrastText(x.error.main))),R(x.Alert,"infoFilledColor",ft(()=>x.getContrastText(x.info.main))),R(x.Alert,"successFilledColor",ft(()=>x.getContrastText(x.success.main))),R(x.Alert,"warningFilledColor",ft(()=>x.getContrastText(x.warning.main))),R(x.Alert,"errorStandardBg",W(be,x.error.light,.9)),R(x.Alert,"infoStandardBg",W(be,x.info.light,.9)),R(x.Alert,"successStandardBg",W(be,x.success.light,.9)),R(x.Alert,"warningStandardBg",W(be,x.warning.light,.9)),R(x.Alert,"errorIconColor",N("palette-error-main")),R(x.Alert,"infoIconColor",N("palette-info-main")),R(x.Alert,"successIconColor",N("palette-success-main")),R(x.Alert,"warningIconColor",N("palette-warning-main")),R(x.AppBar,"defaultBg",N("palette-grey-100")),R(x.Avatar,"defaultBg",N("palette-grey-400")),R(x.Button,"inheritContainedBg",N("palette-grey-300")),R(x.Button,"inheritContainedHoverBg",N("palette-grey-A100")),R(x.Chip,"defaultBorder",N("palette-grey-400")),R(x.Chip,"defaultAvatarColor",N("palette-grey-700")),R(x.Chip,"defaultIconColor",N("palette-grey-700")),R(x.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),R(x.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),R(x.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),R(x.LinearProgress,"primaryBg",W(be,x.primary.main,.62)),R(x.LinearProgress,"secondaryBg",W(be,x.secondary.main,.62)),R(x.LinearProgress,"errorBg",W(be,x.error.main,.62)),R(x.LinearProgress,"infoBg",W(be,x.info.main,.62)),R(x.LinearProgress,"successBg",W(be,x.success.main,.62)),R(x.LinearProgress,"warningBg",W(be,x.warning.main,.62)),R(x.Skeleton,"bg",I?W(Vt,x.text.primary,.11):`rgba(${N("palette-text-primaryChannel")} / 0.11)`),R(x.Slider,"primaryTrack",W(be,x.primary.main,.62)),R(x.Slider,"secondaryTrack",W(be,x.secondary.main,.62)),R(x.Slider,"errorTrack",W(be,x.error.main,.62)),R(x.Slider,"infoTrack",W(be,x.info.main,.62)),R(x.Slider,"successTrack",W(be,x.success.main,.62)),R(x.Slider,"warningTrack",W(be,x.warning.main,.62));const H=I?W(ye,x.background.default,.6825):io(x.background.default,.8);R(x.SnackbarContent,"bg",H),R(x.SnackbarContent,"color",ft(()=>I?Go.text.primary:x.getContrastText(H))),R(x.SpeedDialAction,"fabHoverBg",io(x.background.paper,.15)),R(x.StepConnector,"border",N("palette-grey-400")),R(x.StepContent,"border",N("palette-grey-400")),R(x.Switch,"defaultColor",N("palette-common-white")),R(x.Switch,"defaultDisabledColor",N("palette-grey-100")),R(x.Switch,"primaryDisabledColor",W(be,x.primary.main,.62)),R(x.Switch,"secondaryDisabledColor",W(be,x.secondary.main,.62)),R(x.Switch,"errorDisabledColor",W(be,x.error.main,.62)),R(x.Switch,"infoDisabledColor",W(be,x.info.main,.62)),R(x.Switch,"successDisabledColor",W(be,x.success.main,.62)),R(x.Switch,"warningDisabledColor",W(be,x.warning.main,.62)),R(x.TableCell,"border",W(be,W(Vt,x.divider,1),.88)),R(x.Tooltip,"bg",W(Vt,x.grey[700],.92))}if(x.mode==="dark"){R(x.Alert,"errorColor",W(be,x.error.light,.6)),R(x.Alert,"infoColor",W(be,x.info.light,.6)),R(x.Alert,"successColor",W(be,x.success.light,.6)),R(x.Alert,"warningColor",W(be,x.warning.light,.6)),R(x.Alert,"errorFilledBg",N("palette-error-dark")),R(x.Alert,"infoFilledBg",N("palette-info-dark")),R(x.Alert,"successFilledBg",N("palette-success-dark")),R(x.Alert,"warningFilledBg",N("palette-warning-dark")),R(x.Alert,"errorFilledColor",ft(()=>x.getContrastText(x.error.dark))),R(x.Alert,"infoFilledColor",ft(()=>x.getContrastText(x.info.dark))),R(x.Alert,"successFilledColor",ft(()=>x.getContrastText(x.success.dark))),R(x.Alert,"warningFilledColor",ft(()=>x.getContrastText(x.warning.dark))),R(x.Alert,"errorStandardBg",W(ye,x.error.light,.9)),R(x.Alert,"infoStandardBg",W(ye,x.info.light,.9)),R(x.Alert,"successStandardBg",W(ye,x.success.light,.9)),R(x.Alert,"warningStandardBg",W(ye,x.warning.light,.9)),R(x.Alert,"errorIconColor",N("palette-error-main")),R(x.Alert,"infoIconColor",N("palette-info-main")),R(x.Alert,"successIconColor",N("palette-success-main")),R(x.Alert,"warningIconColor",N("palette-warning-main")),R(x.AppBar,"defaultBg",N("palette-grey-900")),R(x.AppBar,"darkBg",N("palette-background-paper")),R(x.AppBar,"darkColor",N("palette-text-primary")),R(x.Avatar,"defaultBg",N("palette-grey-600")),R(x.Button,"inheritContainedBg",N("palette-grey-800")),R(x.Button,"inheritContainedHoverBg",N("palette-grey-700")),R(x.Chip,"defaultBorder",N("palette-grey-700")),R(x.Chip,"defaultAvatarColor",N("palette-grey-300")),R(x.Chip,"defaultIconColor",N("palette-grey-300")),R(x.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),R(x.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),R(x.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),R(x.LinearProgress,"primaryBg",W(ye,x.primary.main,.5)),R(x.LinearProgress,"secondaryBg",W(ye,x.secondary.main,.5)),R(x.LinearProgress,"errorBg",W(ye,x.error.main,.5)),R(x.LinearProgress,"infoBg",W(ye,x.info.main,.5)),R(x.LinearProgress,"successBg",W(ye,x.success.main,.5)),R(x.LinearProgress,"warningBg",W(ye,x.warning.main,.5)),R(x.Skeleton,"bg",I?W(Vt,x.text.primary,.13):`rgba(${N("palette-text-primaryChannel")} / 0.13)`),R(x.Slider,"primaryTrack",W(ye,x.primary.main,.5)),R(x.Slider,"secondaryTrack",W(ye,x.secondary.main,.5)),R(x.Slider,"errorTrack",W(ye,x.error.main,.5)),R(x.Slider,"infoTrack",W(ye,x.info.main,.5)),R(x.Slider,"successTrack",W(ye,x.success.main,.5)),R(x.Slider,"warningTrack",W(ye,x.warning.main,.5));const H=I?W(be,x.background.default,.985):io(x.background.default,.98);R(x.SnackbarContent,"bg",H),R(x.SnackbarContent,"color",ft(()=>I?Wi.text.primary:x.getContrastText(H))),R(x.SpeedDialAction,"fabHoverBg",io(x.background.paper,.15)),R(x.StepConnector,"border",N("palette-grey-600")),R(x.StepContent,"border",N("palette-grey-600")),R(x.Switch,"defaultColor",N("palette-grey-300")),R(x.Switch,"defaultDisabledColor",N("palette-grey-600")),R(x.Switch,"primaryDisabledColor",W(ye,x.primary.main,.55)),R(x.Switch,"secondaryDisabledColor",W(ye,x.secondary.main,.55)),R(x.Switch,"errorDisabledColor",W(ye,x.error.main,.55)),R(x.Switch,"infoDisabledColor",W(ye,x.info.main,.55)),R(x.Switch,"successDisabledColor",W(ye,x.success.main,.55)),R(x.Switch,"warningDisabledColor",W(ye,x.warning.main,.55)),R(x.TableCell,"border",W(ye,W(Vt,x.divider,1),.68)),R(x.Tooltip,"bg",W(Vt,x.grey[700],.92))}jt(x.background,"default"),jt(x.background,"paper"),jt(x.common,"background"),jt(x.common,"onBackground"),jt(x,"divider"),Object.keys(x).forEach(H=>{const J=x[H];H!=="tonalOffset"&&J&&typeof J=="object"&&(J.main&&R(x[H],"mainChannel",Vr(Hr(J.main))),J.light&&R(x[H],"lightChannel",Vr(Hr(J.light))),J.dark&&R(x[H],"darkChannel",Vr(Hr(J.dark))),J.contrastText&&R(x[H],"contrastTextChannel",Vr(Hr(J.contrastText))),H==="text"&&(jt(x[H],"primary"),jt(x[H],"secondary")),H==="action"&&(J.active&&jt(x[H],"active"),J.selected&&jt(x[H],"selected")))})}),A=o.reduce((te,x)=>qe(te,x),A);const B={prefix:c,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:td(A),enableContrastVars:d},{vars:$,generateThemeVars:Y,generateStyleSheets:Q}=wc(A,B);return A.vars=$,Object.entries(A.colorSchemes[A.defaultColorScheme]).forEach(([te,x])=>{A[te]=x}),A.generateThemeVars=Y,A.generateStyleSheets=Q,A.generateSpacing=function(){return Ai(h.spacing,rn(this))},A.getColorSchemeSelector=kc(u),A.spacing=A.generateSpacing(),A.shouldSkipGeneratingVar=l,A.unstable_sxConfig={...Io,...h==null?void 0:h.unstable_sxConfig},A.unstable_sx=function(x){return zo({sx:x,theme:this})},A.toRuntimeSource=Pi,A}function Xn(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:sn({...n===!0?{}:n.palette,mode:o})})}function sd(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",u=s==null?void 0:s[l],m={...s,...n?{[l]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return qo(t,...o);let h=n;"palette"in t||m[l]&&(m[l]!==!0?h=m[l].palette:l==="dark"&&(h={mode:"dark"}));const b=qo({...t,palette:h},...o);return b.defaultColorScheme=l,b.colorSchemes=m,b.palette.mode==="light"&&(b.colorSchemes.light={...m.light!==!0&&m.light,palette:b.palette},Xn(b,"dark",m.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:b.palette},Xn(b,"light",m.light)),b}return!n&&!("light"in m)&&l==="light"&&(m.light=!0),id({...d,colorSchemes:m,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const ad=sd();function Tt(){const t=pc(ad);return process.env.NODE_ENV!=="production"&&fo.useDebugValue(t),t[tl]||t}async function ld(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,c=setTimeout(()=>s.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:s.signal})}catch(m){throw clearTimeout(c),(m==null?void 0:m.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(c)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let l;try{l=await d.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(l))u=l;else if(n&&l[n]&&Array.isArray(l[n]))u=l[n];else{const 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 cd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[c,d]=p.useState(""),[l,u]=p.useState(!1),[m,h]=p.useState(""),[b,f]=p.useState(null),[g,T]=p.useState(null),[y,w]=p.useState(!1),[v,j]=p.useState(""),S=p.useRef(null),[I,a]=p.useState("json"),[A,B]=p.useState(""),[$,Y]=p.useState(""),[Q,te]=p.useState(""),[x,N]=p.useState("idle"),[W,H]=p.useState(""),[J,ue]=p.useState(null),[pe,re]=p.useState(0),O=async P=>{if(j(""),!P.name.endsWith(".json")){j("Only .json files are allowed");return}const ne=10*1024*1024;if(P.size>ne){j("File size exceeds 10MB limit");return}try{const ce=await P.text();let ie;try{ie=JSON.parse(ce)}catch{j("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ie)){j("JSON must be an array of objects");return}if(ie.length===0){j("No data rows found in JSON file");return}f(P),T(ie)}catch{j("Network error — please try again")}},F=P=>{P.preventDefault();const ne=P.dataTransfer.files[0];ne&&O(ne)},G=async()=>{if(A.trim()){N("loading"),H("");try{const P=await ld(A.trim(),$.trim()||void 0,Q.trim()||void 0);ue(P.data),re(P.data.length),N("ready")}catch(P){H((P==null?void 0:P.message)||"Connection failed"),N("error")}}},se=()=>{if(!c.trim()){u(!0);return}const P=I==="api"?J:i||g;P&&(n(c.trim(),m.trim(),P),ee())},ee=()=>{d(""),u(!1),h(""),f(null),T(null),j(""),a("json"),B(""),Y(""),te(""),N("idle"),H(""),ue(null),re(0),o()},le=i||g,ae=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:ee,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.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:ae,helperText:ae?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:m,onChange: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:I==="json"?0:1,onChange:(P,ne)=>{a(ne===0?"json":"api"),N("idle"),H("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(k.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(k.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),I==="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=>E(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=>E(P.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.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:()=>w(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:F,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=S.current)==null?void 0:P.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":v?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?P=>E(P.palette.success.main,.04):v?P=>E(P.palette.error.main,.04):P=>E(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?P=>E(P.palette.success.main,.08):v?P=>E(P.palette.error.main,.08):P=>E(P.palette.primary.main,.08),borderColor:g?"success.dark":v?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:S,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var ne;return((ne=P.target.files)==null?void 0:ne[0])&&O(P.target.files[0])}}),g?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:P=>E(P.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(k.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=>E(P.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(k.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),v&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:P=>E(P.palette.error.main,.08),border:1,borderColor:P=>E(P.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:v})})]})]})]})}),I==="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),N("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:$,onChange:P=>Y(P.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(k.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:Q,onChange:P=>te(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!A.trim()||x==="loading",onClick:G,startIcon:x==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(k.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:P=>E(P.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:x==="loading"?"Connecting...":"Test Connection & Load Data"}),x==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:P=>E(P.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(k.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:[pe.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})]})]}),x==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>E(P.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(k.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:W})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>E(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:se,disabled:I==="json"&&!le||I==="api"&&x!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:y,onClose:()=>w(!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:()=>w(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.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 ei(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})`:B(o,ed(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${ei(n)})`:Po(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${ei(n)})`:Wo(o,n)}})}function tn(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:c={},transitions:d={},typography:l={},shape:p,colorSpace:m,...f}=t;if(t.vars&&t.generateThemeVars===void 0)throw new Error(process.env.NODE_ENV!=="production"?"MUI: `vars` is a private field used for CSS variables support.\nPlease use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.":er(20));const b=un({...c,colorSpace:m}),x=Wi(t);let g=Je(x,{mixins:Lc(x.breakpoints,i),palette:b,shadows:Gc.slice(),typography:Vc(b,l),transitions:Xc(d),zIndex:{...Zc}});if(g=Je(g,f),g=o.reduce((I,y)=>Je(I,y),g),process.env.NODE_ENV!=="production"){const I=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],y=(j,v)=>{let k;for(k in j){const S=j[k];if(I.includes(k)&&Object.keys(S).length>0){if(process.env.NODE_ENV!=="production"){const T=jc("",k);console.error([`MUI: The \`${v}\` component increases the CSS specificity of the \`${k}\` internal state.`,"You can not override it like this: ",JSON.stringify(j,null,2),"",`Instead, you need to use the '&.${T}' syntax:`,JSON.stringify({root:{[`&.${T}`]:S}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
68
+ `))}j[k]={}}}};Object.keys(g.components).forEach(j=>{const v=g.components[j].styleOverrides;v&&j.startsWith("Mui")&&y(v,j)})}return g.unstable_sxConfig={...Mo,...f==null?void 0:f.unstable_sxConfig},g.unstable_sx=function(y){return $o({sx:y,theme:this})},g.toRuntimeSource=Vi,td(g),g}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 Hi(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Ui(t){return t==="dark"?od:[]}function nd(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...c}=t,d=un({...o,colorSpace:s});return{palette:d,opacity:{...Hi(d.mode),...n},overlays:i||Ui(d.mode),...c}}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 c=s;if(s==="class"&&(c=".%s"),s==="data"&&(c="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(c=`[${s}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return sd(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 ld(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function P(t,o,n){!t[o]&&n&&(t[o]=n)}function Xr(t){return typeof t!="string"||!t.startsWith("hsl")?t:Pi(t)}function zt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Kr(Xr(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 gt=t=>{try{return t()}catch{}},dd=(t="mui")=>Ic(t);function Ko(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const c=s==="dark"?"dark":"light";if(!i){o[s]=nd({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=tn({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:d,opacity:{...Hi(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Ui(c)},l}function ud(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=id,colorSchemeSelector:p=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...f}=t,b=Object.keys(n)[0],x=i||(n.light&&b!=="light"?"light":b),g=dd(c),{[x]:I,light:y,dark:j,...v}=n,k={...v};let S=I;if((x==="dark"&&!("dark"in n)||x==="light"&&!("light"in n))&&(S=!0),!S)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${x}\` option is either missing or invalid.`:er(21,x));let T;d&&(T="oklch");const a=Ko(T,k,S,f,x);y&&!k.light&&Ko(T,k,y,void 0,"light"),j&&!k.dark&&Ko(T,k,j,void 0,"dark");let _={defaultColorScheme:x,...a,cssVarPrefix:c,colorSchemeSelector:p,rootSelector:m,getCssVar:g,colorSchemes:k,font:{...Nc(a.typography),...a.font},spacing:cd(f.spacing)};Object.keys(_.colorSchemes).forEach(ee=>{const h=_.colorSchemes[ee].palette,$=V=>{const K=V.split("-"),pe=K[1],xe=K[2];return g(V,h[pe][xe])};h.mode==="light"&&(P(h.common,"background","#fff"),P(h.common,"onBackground","#000")),h.mode==="dark"&&(P(h.common,"background","#000"),P(h.common,"onBackground","#fff"));function W(V,K,pe){if(T){let xe;return V===Xt&&(xe=`transparent ${((1-pe)*100).toFixed(0)}%`),V===be&&(xe=`#000 ${(pe*100).toFixed(0)}%`),V===ve&&(xe=`#fff ${(pe*100).toFixed(0)}%`),`color-mix(in ${T}, ${K}, ${xe})`}return V(K,pe)}if(ld(h,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),h.mode==="light"){P(h.Alert,"errorColor",W(be,h.error.light,.6)),P(h.Alert,"infoColor",W(be,h.info.light,.6)),P(h.Alert,"successColor",W(be,h.success.light,.6)),P(h.Alert,"warningColor",W(be,h.warning.light,.6)),P(h.Alert,"errorFilledBg",$("palette-error-main")),P(h.Alert,"infoFilledBg",$("palette-info-main")),P(h.Alert,"successFilledBg",$("palette-success-main")),P(h.Alert,"warningFilledBg",$("palette-warning-main")),P(h.Alert,"errorFilledColor",gt(()=>h.getContrastText(h.error.main))),P(h.Alert,"infoFilledColor",gt(()=>h.getContrastText(h.info.main))),P(h.Alert,"successFilledColor",gt(()=>h.getContrastText(h.success.main))),P(h.Alert,"warningFilledColor",gt(()=>h.getContrastText(h.warning.main))),P(h.Alert,"errorStandardBg",W(ve,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(ve,h.info.light,.9)),P(h.Alert,"successStandardBg",W(ve,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(ve,h.warning.light,.9)),P(h.Alert,"errorIconColor",$("palette-error-main")),P(h.Alert,"infoIconColor",$("palette-info-main")),P(h.Alert,"successIconColor",$("palette-success-main")),P(h.Alert,"warningIconColor",$("palette-warning-main")),P(h.AppBar,"defaultBg",$("palette-grey-100")),P(h.Avatar,"defaultBg",$("palette-grey-400")),P(h.Button,"inheritContainedBg",$("palette-grey-300")),P(h.Button,"inheritContainedHoverBg",$("palette-grey-A100")),P(h.Chip,"defaultBorder",$("palette-grey-400")),P(h.Chip,"defaultAvatarColor",$("palette-grey-700")),P(h.Chip,"defaultIconColor",$("palette-grey-700")),P(h.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),P(h.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),P(h.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),P(h.LinearProgress,"primaryBg",W(ve,h.primary.main,.62)),P(h.LinearProgress,"secondaryBg",W(ve,h.secondary.main,.62)),P(h.LinearProgress,"errorBg",W(ve,h.error.main,.62)),P(h.LinearProgress,"infoBg",W(ve,h.info.main,.62)),P(h.LinearProgress,"successBg",W(ve,h.success.main,.62)),P(h.LinearProgress,"warningBg",W(ve,h.warning.main,.62)),P(h.Skeleton,"bg",T?W(Xt,h.text.primary,.11):`rgba(${$("palette-text-primaryChannel")} / 0.11)`),P(h.Slider,"primaryTrack",W(ve,h.primary.main,.62)),P(h.Slider,"secondaryTrack",W(ve,h.secondary.main,.62)),P(h.Slider,"errorTrack",W(ve,h.error.main,.62)),P(h.Slider,"infoTrack",W(ve,h.info.main,.62)),P(h.Slider,"successTrack",W(ve,h.success.main,.62)),P(h.Slider,"warningTrack",W(ve,h.warning.main,.62));const V=T?W(be,h.background.default,.6825):po(h.background.default,.8);P(h.SnackbarContent,"bg",V),P(h.SnackbarContent,"color",gt(()=>T?en.text.primary:h.getContrastText(V))),P(h.SpeedDialAction,"fabHoverBg",po(h.background.paper,.15)),P(h.StepConnector,"border",$("palette-grey-400")),P(h.StepContent,"border",$("palette-grey-400")),P(h.Switch,"defaultColor",$("palette-common-white")),P(h.Switch,"defaultDisabledColor",$("palette-grey-100")),P(h.Switch,"primaryDisabledColor",W(ve,h.primary.main,.62)),P(h.Switch,"secondaryDisabledColor",W(ve,h.secondary.main,.62)),P(h.Switch,"errorDisabledColor",W(ve,h.error.main,.62)),P(h.Switch,"infoDisabledColor",W(ve,h.info.main,.62)),P(h.Switch,"successDisabledColor",W(ve,h.success.main,.62)),P(h.Switch,"warningDisabledColor",W(ve,h.warning.main,.62)),P(h.TableCell,"border",W(ve,W(Xt,h.divider,1),.88)),P(h.Tooltip,"bg",W(Xt,h.grey[700],.92))}if(h.mode==="dark"){P(h.Alert,"errorColor",W(ve,h.error.light,.6)),P(h.Alert,"infoColor",W(ve,h.info.light,.6)),P(h.Alert,"successColor",W(ve,h.success.light,.6)),P(h.Alert,"warningColor",W(ve,h.warning.light,.6)),P(h.Alert,"errorFilledBg",$("palette-error-dark")),P(h.Alert,"infoFilledBg",$("palette-info-dark")),P(h.Alert,"successFilledBg",$("palette-success-dark")),P(h.Alert,"warningFilledBg",$("palette-warning-dark")),P(h.Alert,"errorFilledColor",gt(()=>h.getContrastText(h.error.dark))),P(h.Alert,"infoFilledColor",gt(()=>h.getContrastText(h.info.dark))),P(h.Alert,"successFilledColor",gt(()=>h.getContrastText(h.success.dark))),P(h.Alert,"warningFilledColor",gt(()=>h.getContrastText(h.warning.dark))),P(h.Alert,"errorStandardBg",W(be,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(be,h.info.light,.9)),P(h.Alert,"successStandardBg",W(be,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(be,h.warning.light,.9)),P(h.Alert,"errorIconColor",$("palette-error-main")),P(h.Alert,"infoIconColor",$("palette-info-main")),P(h.Alert,"successIconColor",$("palette-success-main")),P(h.Alert,"warningIconColor",$("palette-warning-main")),P(h.AppBar,"defaultBg",$("palette-grey-900")),P(h.AppBar,"darkBg",$("palette-background-paper")),P(h.AppBar,"darkColor",$("palette-text-primary")),P(h.Avatar,"defaultBg",$("palette-grey-600")),P(h.Button,"inheritContainedBg",$("palette-grey-800")),P(h.Button,"inheritContainedHoverBg",$("palette-grey-700")),P(h.Chip,"defaultBorder",$("palette-grey-700")),P(h.Chip,"defaultAvatarColor",$("palette-grey-300")),P(h.Chip,"defaultIconColor",$("palette-grey-300")),P(h.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),P(h.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),P(h.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),P(h.LinearProgress,"primaryBg",W(be,h.primary.main,.5)),P(h.LinearProgress,"secondaryBg",W(be,h.secondary.main,.5)),P(h.LinearProgress,"errorBg",W(be,h.error.main,.5)),P(h.LinearProgress,"infoBg",W(be,h.info.main,.5)),P(h.LinearProgress,"successBg",W(be,h.success.main,.5)),P(h.LinearProgress,"warningBg",W(be,h.warning.main,.5)),P(h.Skeleton,"bg",T?W(Xt,h.text.primary,.13):`rgba(${$("palette-text-primaryChannel")} / 0.13)`),P(h.Slider,"primaryTrack",W(be,h.primary.main,.5)),P(h.Slider,"secondaryTrack",W(be,h.secondary.main,.5)),P(h.Slider,"errorTrack",W(be,h.error.main,.5)),P(h.Slider,"infoTrack",W(be,h.info.main,.5)),P(h.Slider,"successTrack",W(be,h.success.main,.5)),P(h.Slider,"warningTrack",W(be,h.warning.main,.5));const V=T?W(ve,h.background.default,.985):po(h.background.default,.98);P(h.SnackbarContent,"bg",V),P(h.SnackbarContent,"color",gt(()=>T?Li.text.primary:h.getContrastText(V))),P(h.SpeedDialAction,"fabHoverBg",po(h.background.paper,.15)),P(h.StepConnector,"border",$("palette-grey-600")),P(h.StepContent,"border",$("palette-grey-600")),P(h.Switch,"defaultColor",$("palette-grey-300")),P(h.Switch,"defaultDisabledColor",$("palette-grey-600")),P(h.Switch,"primaryDisabledColor",W(be,h.primary.main,.55)),P(h.Switch,"secondaryDisabledColor",W(be,h.secondary.main,.55)),P(h.Switch,"errorDisabledColor",W(be,h.error.main,.55)),P(h.Switch,"infoDisabledColor",W(be,h.info.main,.55)),P(h.Switch,"successDisabledColor",W(be,h.success.main,.55)),P(h.Switch,"warningDisabledColor",W(be,h.warning.main,.55)),P(h.TableCell,"border",W(be,W(Xt,h.divider,1),.68)),P(h.Tooltip,"bg",W(Xt,h.grey[700],.92))}zt(h.background,"default"),zt(h.background,"paper"),zt(h.common,"background"),zt(h.common,"onBackground"),zt(h,"divider"),Object.keys(h).forEach(V=>{const K=h[V];V!=="tonalOffset"&&K&&typeof K=="object"&&(K.main&&P(h[V],"mainChannel",Kr(Xr(K.main))),K.light&&P(h[V],"lightChannel",Kr(Xr(K.light))),K.dark&&P(h[V],"darkChannel",Kr(Xr(K.dark))),K.contrastText&&P(h[V],"contrastTextChannel",Kr(Xr(K.contrastText))),V==="text"&&(zt(h[V],"primary"),zt(h[V],"secondary")),V==="action"&&(K.active&&zt(h[V],"active"),K.selected&&zt(h[V],"selected")))})}),_=o.reduce((ee,h)=>Je(ee,h),_);const z={prefix:c,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:ad(_),enableContrastVars:d},{vars:R,generateThemeVars:G,generateStyleSheets:Z}=Bc(_,z);return _.vars=R,Object.entries(_.colorSchemes[_.defaultColorScheme]).forEach(([ee,h])=>{_[ee]=h}),_.generateThemeVars=G,_.generateStyleSheets=Z,_.generateSpacing=function(){return Ri(f.spacing,ln(this))},_.getColorSchemeSelector=Dc(p),_.spacing=_.generateSpacing(),_.shouldSkipGeneratingVar=l,_.unstable_sxConfig={...Mo,...f==null?void 0:f.unstable_sxConfig},_.unstable_sx=function(h){return $o({sx:h,theme:this})},_.toRuntimeSource=Vi,_}function ti(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:un({...n===!0?{}:n.palette,mode:o})})}function pd(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",p=s==null?void 0:s[l],m={...s,...n?{[l]:{...typeof p!="boolean"&&p,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return tn(t,...o);let f=n;"palette"in t||m[l]&&(m[l]!==!0?f=m[l].palette:l==="dark"&&(f={mode:"dark"}));const b=tn({...t,palette:f},...o);return b.defaultColorScheme=l,b.colorSchemes=m,b.palette.mode==="light"&&(b.colorSchemes.light={...m.light!==!0&&m.light,palette:b.palette},ti(b,"dark",m.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:b.palette},ti(b,"light",m.light)),b}return!n&&!("light"in m)&&l==="light"&&(m.light=!0),ud({...d,colorSchemes:m,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const xd=pd();function Ot(){const t=yc(xd);return process.env.NODE_ENV!=="production"&&Co.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,c=setTimeout(()=>s.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:s.signal})}catch(m){throw clearTimeout(c),(m==null?void 0:m.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(c)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let l;try{l=await d.json()}catch{throw new Error("Response is not valid JSON")}let p;if(Array.isArray(l))p=l;else if(n&&l[n]&&Array.isArray(l[n]))p=l[n];else{const f=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(f)p=l[f];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:p,source:t,fetchedAt:new Date().toISOString()}}function fd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[c,d]=u.useState(""),[l,p]=u.useState(!1),[m,f]=u.useState(""),[b,x]=u.useState(null),[g,I]=u.useState(null),[y,j]=u.useState(!1),[v,k]=u.useState(""),S=u.useRef(null),[T,a]=u.useState("json"),[_,z]=u.useState(""),[R,G]=u.useState(""),[Z,ee]=u.useState(""),[h,$]=u.useState("idle"),[W,V]=u.useState(""),[K,pe]=u.useState(null),[xe,oe]=u.useState(0),A=async N=>{if(k(""),!N.name.endsWith(".json")){k("Only .json files are allowed");return}const ie=10*1024*1024;if(N.size>ie){k("File size exceeds 10MB limit");return}try{const le=await N.text();let se;try{se=JSON.parse(le)}catch{k("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(se)){k("JSON must be an array of objects");return}if(se.length===0){k("No data rows found in JSON file");return}x(N),I(se)}catch{k("Network error — please try again")}},F=N=>{N.preventDefault();const ie=N.dataTransfer.files[0];ie&&A(ie)},re=async()=>{if(_.trim()){$("loading"),V("");try{const N=await md(_.trim(),R.trim()||void 0,Z.trim()||void 0);pe(N.data),oe(N.data.length),$("ready")}catch(N){V((N==null?void 0:N.message)||"Connection failed"),$("error")}}},q=()=>{if(!c.trim()){p(!0);return}const N=T==="api"?K:i||g;N&&(n(c.trim(),m.trim(),N),Q())},Q=()=>{d(""),p(!1),f(""),x(null),I(null),k(""),a("json"),z(""),G(""),ee(""),$("idle"),V(""),pe(null),oe(0),o()},ae=i||g,ne=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:Q,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:Q,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[e.jsx(r.TextField,{label:"Report name",required:!0,fullWidth:!0,value:c,onChange:N=>{d(N.target.value),l&&N.target.value.trim()&&p(!1)},placeholder:"Enter report name",autoFocus:!0,error: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:m,onChange:N=>f(N.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsxs(r.Tabs,{value:T==="json"?0:1,onChange:(N,ie)=>{a(ie===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(w.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}}),e.jsx(r.Tab,{label:"Connect API",icon:e.jsx(w.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),T==="json"&&e.jsx(r.Box,{children:i?e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:N=>B(N.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:N=>B(N.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:F,onDragOver:N=>N.preventDefault(),onPaste:N=>N.preventDefault(),onClick:()=>{var N;return(N=S.current)==null?void 0:N.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":v?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?N=>B(N.palette.success.main,.04):v?N=>B(N.palette.error.main,.04):N=>B(N.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?N=>B(N.palette.success.main,.08):v?N=>B(N.palette.error.main,.08):N=>B(N.palette.primary.main,.08),borderColor:g?"success.dark":v?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:S,type:"file",accept:".json",sx:{display:"none"},onChange:N=>{var ie;return((ie=N.target.files)==null?void 0:ie[0])&&A(N.target.files[0])}}),g?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:N=>B(N.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(w.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:b==null?void 0:b.name}),e.jsx(r.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):e.jsxs(r.Box,{children:[e.jsx(r.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:N=>B(N.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(w.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),v&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:N=>B(N.palette.error.main,.08),border:1,borderColor:N=>B(N.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:v})})]})]})]})}),T==="api"&&e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx(r.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:_,onChange:N=>{z(N.target.value),$("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:R,onChange:N=>G(N.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(w.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:Z,onChange:N=>ee(N.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!_.trim()||h==="loading",onClick:re,startIcon:h==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(w.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:N=>B(N.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:h==="loading"?"Connecting...":"Test Connection & Load Data"}),h==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:N=>B(N.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[xe.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:_})]})]}),h==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:N=>B(N.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:W})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:Q,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:N=>B(N.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:q,disabled:T==="json"&&!ae||T==="api"&&h!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:y,onClose:()=>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(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
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:()=>w(!1),variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2}},children:"Got it"})})]})]})}function Fi({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,sx:{overflowY:"auto",flex:1},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:3,py:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Expected JSON Structure"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["The uploaded JSON must be an ",e.jsx("strong",{children:"array of objects"}),". Each object represents a single row in your report, and the keys of each object become the column names."]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Example JSON"}),e.jsx(r.Paper,{elevation:0,sx:{p:2,bgcolor:"action.hover",border:1,borderColor:"divider",borderRadius:1,overflowX:"auto"},children:e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",fontFamily:"monospace",m:0},children:`[
79
+ ]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>j(!1),variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2}},children:"Got it"})})]})]})}function Yi({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",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(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,sx:{overflowY:"auto",flex:1},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:3,py:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Expected JSON Structure"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["The uploaded JSON must be an ",e.jsx("strong",{children:"array of objects"}),". Each object represents a single row in your report, and the keys of each object become the column names."]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Example JSON"}),e.jsx(r.Paper,{elevation:0,sx:{p:2,bgcolor:"action.hover",border:1,borderColor:"divider",borderRadius:1,overflowX:"auto"},children:e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",fontFamily:"monospace",m:0},children:`[
80
80
  {
81
81
  "Active Sessions": 33,
82
82
  "Active State": true,
@@ -86,10 +86,10 @@ To suppress this warning, you need to explicitly provide the \`palette.${o}Chann
86
86
  "Region": "Europe",
87
87
  "Subscription Type": "Basic"
88
88
  }
89
- ]`})})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Supported Column Types"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"The system automatically detects column types from your data:"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Number:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Numeric values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"33"}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"42.5"}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Boolean:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["True/false values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"true"}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"false"}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"String:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Text values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Europe"'}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Analytics Pro"'}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Date:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["ISO date strings (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"2024-08-22"'}),")"]})]})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Notes"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2.5,"& li":{fontSize:"body2.fontSize",color:"text.secondary",mb:.5}},children:[e.jsx("li",{children:"Each object in the array represents one row in the report."}),e.jsx("li",{children:"The keys of the JSON objects become report columns."}),e.jsx("li",{children:"All objects should have consistent keys for proper column detection."}),e.jsx("li",{children:"Column names are case-sensitive and preserve spacing."})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"#ffffff",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Got it"})})]}):null}function dd({onFileUpload:t,onError:o,isUploading:n}){const[i,s]=p.useState(!1),[c,d]=p.useState(""),[l,u]=p.useState(!1),m=p.useRef(null),h=async v=>{if(!v.name.endsWith(".json")){o("Only .json files are allowed");return}const j=10*1024*1024;if(v.size>j){o("File size exceeds 10MB limit");return}d(v.name);try{const S=await v.text();let I;try{I=JSON.parse(S)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(I)){o("JSON must be an array of objects");return}if(I.length===0){o("No data rows found in JSON file");return}t(I)}catch{o("Network error — please try again")}finally{d("")}},b=v=>{v.preventDefault(),s(!0)},f=v=>{v.preventDefault(),s(!1)},g=v=>{v.preventDefault(),s(!1);const j=v.dataTransfer.files[0];j&&h(j)},T=()=>{var v;(v=m.current)==null||v.click()},y=v=>{var S;const j=(S=v.target.files)==null?void 0:S[0];j&&h(j)},w=v=>{v.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:f,onDrop:g,onPaste:v=>v.preventDefault(),onClick:T,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?v=>E(v.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[e.jsx(r.Box,{component:"input",ref:m,type:"file",accept:".json",onChange:y,sx:{display:"none"}}),n?e.jsxs(e.Fragment,{children:[e.jsx(r.CircularProgress,{size:32,sx:{mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:.5},children:"Uploading..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:v=>E(v.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.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:w,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:e.jsx(k.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(Fi,{isOpen:l,onClose:()=>u(!1)})]})}function ud({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=>E(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(k.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 pd({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=>E(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=>E(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.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(k.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Vi({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=>E(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(k.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 xd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:c,disabled:d}){const[l,u]=p.useState(!1),[m,h]=p.useState(!1),[b,f]=p.useState(-1),g=p.useRef(null),T=p.useRef(null);p.useEffect(()=>{function $(Y){g.current&&!g.current.contains(Y.target)&&(u(!1),h(!1))}return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[]);const y=p.useCallback(()=>{h(!0),f(-1),n.length>0&&u(!0)},[n.length]),w=p.useCallback($=>{o($),f(-1)},[o]),v=p.useCallback($=>{var Y;o($),i($),u(!1),(Y=T.current)==null||Y.blur()},[o,i]),j=p.useCallback($=>{f(-1),v($)},[v]),S=p.useCallback($=>{var Y;$.key==="Enter"?b>=0&&b<n.length?($.preventDefault(),j(n[b].query)):t.trim()&&v(t.trim()):$.key==="Escape"?(u(!1),f(-1),(Y=T.current)==null||Y.blur()):$.key==="ArrowDown"?($.preventDefault(),n.length>0&&(l||u(!0),f(Q=>Q<n.length-1?Q+1:Q))):$.key==="ArrowUp"&&($.preventDefault(),f(Q=>Q>0?Q-1:-1))},[b,n,t,l,j,v]),I=p.useCallback(()=>{var $;o(""),($=T.current)==null||$.focus()},[o]),a=p.useMemo(()=>n.filter($=>$.isFavourite),[n]),A=p.useMemo(()=>n.filter($=>!$.isFavourite),[n]),B=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:T,size:"small",fullWidth:!0,value:t,onChange:$=>w($.target.value),onFocus:y,onKeyDown:S,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.30)`,transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.50)`},"&.Mui-focused":{bgcolor:"background.paper"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px",color:"text.primary"}},InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",sx:{ml:.5},children:e.jsx(k.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:I,edge:"end",sx:{mr:-.5},children:e.jsx(k.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:[a.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),a.map(($,Y)=>e.jsx(Zn,{entry:$,isSelected:b===Y,onClick:()=>j($.query),onToggleFavourite:()=>s($.query),onDelete:()=>c($.query)},`fav-${$.query}`))]}),A.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[a.length>0&&e.jsx(r.Divider,{}),e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),A.map(($,Y)=>{const Q=a.length+Y;return e.jsx(Zn,{entry:$,isSelected:b===Q,onClick:()=>j($.query),onToggleFavourite:()=>s($.query),onDelete:()=>c($.query)},`recent-${$.query}`)})]})]})]})}const Zn=p.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:c}){const d=p.useCallback(u=>{u.stopPropagation(),s()},[s]),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=>E(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>E(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(k.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(k.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(k.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function md({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:u,onPermanentDelete:m,isReadOnly:h,isAdmin:b=!1}){const f=Tt(),[g,T]=p.useState(!1),[y,w]=p.useState(!1),[v,j]=p.useState({top:0,left:0}),[S,I]=p.useState(null),a=p.useRef(null),A=p.useRef(null),B=t.find(O=>O.id===o),$=B==null?void 0:B.isDefault,Y=t.filter(O=>O.scope==="global"&&!O.isDeleted),Q=t.filter(O=>O.scope!=="global"&&!O.isDeleted),te=t.filter(O=>O.isFavorite&&!O.isDeleted).sort((O,F)=>(F.updatedAt||0)-(O.updatedAt||0)),x=t.filter(O=>O.isDeleted);p.useEffect(()=>{if(g&&A.current){const O=A.current.getBoundingClientRect();j({top:O.bottom+window.scrollY+8,left:O.right+window.scrollX-320})}},[g]),p.useEffect(()=>{const O=F=>{a.current&&!a.current.contains(F.target)&&A.current&&!A.current.contains(F.target)&&T(!1)};return g&&document.addEventListener("mousedown",O),()=>{document.removeEventListener("mousedown",O)}},[g]);const N=O=>{if(n&&O!==o){I(O),T(!1);return}i(O),T(!1)},W=()=>{S&&(i(S),I(null))},H=()=>{I(null)},J=(O,F=!1)=>{const G=O.scope==="global",se=!h&&(!G||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===O.id?f.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===O.id?f.palette.primary.light+"20":f.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>N(O.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,textTransform:"none",justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===O.id&&e.jsx(k.Check,{sx:{fontSize:16,flexShrink:0}}),o!==O.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===O.id?f.palette.primary.dark:f.palette.text.primary,fontWeight:o===O.id?500:400},children:O.name}),F&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:f.palette.text.secondary,backgroundColor:f.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[se&&l&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),l(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:O.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(k.Star,{sx:{fontSize:16}})}),se&&d&&!O.isDefault&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),d(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:"Set as default",children:e.jsx(k.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},O.id)},ue=O=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:f.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:f.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:O.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[u&&e.jsx(r.IconButton,{onClick:F=>{F.stopPropagation(),u(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:"Restore view",children:e.jsx(k.Undo,{sx:{fontSize:16,color:"success.main"}})}),m&&e.jsx(r.IconButton,{onClick:F=>{F.stopPropagation(),m(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:"Delete permanently",children:e.jsx(k.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},O.id),pe=n||!$,re=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:A,onClick:()=>T(!g),size:"small",sx:{position:"relative",color:pe?"warning.main":"text.secondary",bgcolor:pe?E(f.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:pe?E(f.palette.warning.main,.2):E(f.palette.text.primary,.06),color:pe?"warning.dark":"text.primary"}},title:`View: ${(B==null?void 0:B.name)||"Default View"}`,children:[e.jsx(k.Visibility,{sx:{fontSize:20}}),re&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),g&&di.createPortal(e.jsxs(r.Box,{ref:a,sx:{position:"fixed",width:"320px",backgroundColor:f.palette.background.paper,border:`1px solid ${f.palette.divider}`,borderRadius:1,boxShadow:f.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:v.top,left:v.left},children:[Y.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:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),Y.map(O=>J(O,O.isDefault))]}),te.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.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:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(k.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),te.map(O=>J(O))]})]}),Q.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.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:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),Q.map(O=>J(O))]})]}),x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>w(!y),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",x.length,")"]}),e.jsx(k.ChevronRight,{sx:{fontSize:16}})]}),y&&e.jsx(r.Box,{sx:{backgroundColor:f.palette.grey[50]},children:x.map(O=>ue(O))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{s(),T(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:f.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[50]}},children:[e.jsx(k.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),T(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:f.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[50]}},children:[e.jsx(k.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:S!==null,onClose:H,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(k.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:H,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function fd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:u,onSortDescending:m,onRemoveSort:h,onFilter:b,onClearFilter:f,onGroupByColumn:g,onHideColumn:T,onManageColumns:y,onManageViews:w,onResetLayout:v,onClose:j}){var te,x;const I=Tt().palette,a=p.useRef(null);p.useEffect(()=>{if(!a.current)return;const N=a.current,W=N.getBoundingClientRect(),H=window.innerWidth,J=window.innerHeight;W.right>H-8&&(N.style.left=`${H-W.width-8}px`),W.bottom>J-8&&(N.style.top=`${J-W.height-8}px`)},[l]),p.useEffect(()=>{const N=H=>{a.current&&!a.current.contains(H.target)&&j()},W=H=>{H.key==="Escape"&&j()};return document.addEventListener("mousedown",N),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",N),document.removeEventListener("keydown",W)}},[j]);const A=p.useCallback(N=>()=>{N(),j()},[j]),B=(n==null?void 0:n.direction)==="asc",$=(n==null?void 0:n.direction)==="desc",Y=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",Q=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return di.createPortal(e.jsxs(r.Paper,{ref:a,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:1400,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",boxShadow:`0 4px 20px ${E(((te=I.common)==null?void 0:te.black)??"#000",.12)}, 0 1px 4px ${E(((x=I.common)==null?void 0:x.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 (${Y})`,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?E(I.primary.main,.1):"transparent","&:hover":{bgcolor:E(I.primary.main,.08),color:"primary.main"}},children:e.jsx(k.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${Q})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(()=>m(t)),sx:{p:.625,borderRadius:"6px",color:$?"primary.main":"text.secondary",bgcolor:$?E(I.primary.main,.1):"transparent","&:hover":{bgcolor:E(I.primary.main,.08),color:"primary.main"}},children:e.jsx(k.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:E(I.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(k.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(k.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:A(()=>f(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(I.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(k.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&g&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.25}}),e.jsx(r.MenuList,{dense:!0,sx:{py:.5},children:e.jsxs(r.MenuItem,{onClick:A(()=>g(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.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:A(()=>T(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(k.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(y),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(I.primary.main,.08),color:"primary.main"}},children:e.jsx(k.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:A(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),w&&e.jsxs(r.MenuItem,{onClick:A(w),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!c&&d&&v&&e.jsxs(r.MenuItem,{onClick:A(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(I.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(k.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const hd=150,Qn="COLUMN_HEADER",gd=p.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:u,onColumnClick:m,onMoveColumn:h,onResizeStart:b,onSortAscending:f,onSortDescending:g,onRemoveSort:T,onOpenFilterForColumn:y,onClearFiltersForColumn:w,onGroupByColumn:v,onHideColumn:j,onManageColumns:S,onManageViews:I,onResetLayout:a}){const A=p.useRef(null),[B,$]=p.useState(!1),[Y,Q]=p.useState({x:0,y:0}),[{handlerId:te,isOver:x},N]=wt.useDrop({accept:Qn,collect(G){return{handlerId:G.getHandlerId(),isOver:G.isOver()}},hover(G,se){var ie;if(!A.current)return;const ee=G.index,le=n;if(ee===le)return;const ae=(ie=A.current)==null?void 0:ie.getBoundingClientRect(),P=(ae.right-ae.left)/2,ne=se.getClientOffset(),ce=((ne==null?void 0:ne.x)??0)-ae.left;ee<le&&ce<P||ee>le&&ce>P||(h(ee,le),G.index=le)}}),[{isDragging:W},H]=wt.useDrag({type:Qn,item:()=>({index:n,columnName:o.name}),collect:G=>({isDragging:G.isDragging()})});H(N(A));const J=p.useCallback(G=>{G.preventDefault(),G.stopPropagation(),Q({x:G.clientX,y:G.clientY}),$(!0)},[]),ue=p.useCallback(()=>$(!1),[]),pe=p.useCallback(()=>{m(o.name)},[m,o.name]),re=p.useCallback(G=>{G.stopPropagation(),y(o.name)},[y,o.name]),O=p.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(k.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(k.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]),F=p.useCallback(()=>s?e.jsx(r.Box,{onClick:re,title:"Active filters on this column",sx:{ml:.75,width:7,height:7,borderRadius:"50%",bgcolor:"primary.main",cursor:"pointer",flexShrink:0,"&:hover":{transform:"scale(1.25)"},transition:"transform 0.12s ease"}}):null,[s,re]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:A,"data-handler-id":te,"data-column-index":n,onClick:pe,onContextMenu:J,sx:{position:"sticky",top:0,zIndex:50,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"hidden",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:W?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:x?G=>E(G.palette.primary.main,.08):"action.hover",boxShadow:"0 1px 0 rgba(0,0,0,0.08)",backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:G=>E(G.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${hd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center"},children:[Ge(o.name),O(),F()]}),e.jsx(r.Box,{sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:10,"&:hover":{bgcolor:"primary.light"}},onMouseDown:G=>{G.stopPropagation(),b(G,o.name)},onClick:G=>G.stopPropagation()}),x&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),B&&e.jsx(fd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:c,isReadOnly:d,hasModifications:l,position:Y,onSortAscending:f,onSortDescending:g,onRemoveSort:T,onFilter:y,onClearFilter:w,onGroupByColumn:v,onHideColumn:j,onManageColumns:S,onManageViews:I,onResetLayout:a,onClose:ue})]})});function yd({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:s,onClearSelection:c,onBulkSetFavorites:d}){const[l,u]=p.useState(null),m=p.useMemo(()=>Array.from(o),[o]),h=p.useMemo(()=>m.filter(v=>n.has(v)),[m,n]),b=p.useMemo(()=>m.filter(v=>!n.has(v)),[m,n]),f=h.length>0,g=b.length>0;if(t===0)return null;const T=()=>{d&&d(m,!0)},y=()=>{d&&d(m,!1)},w=v=>{s(v),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:v=>E(v.palette.primary.main,.08),borderBottom:v=>`1px solid ${E(v.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(k.Close,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:v=>E(v.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:v=>u(v.currentTarget),startIcon:e.jsx(k.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>E(v.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:v=>E(v.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:()=>w("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>w("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>w("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:T,startIcon:e.jsx(k.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>E(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>E(v.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&f&&e.jsx(r.Button,{onClick:y,startIcon:e.jsx(k.Star,{sx:{fontSize:16,color:"#fbbc04"}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>E(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>E(v.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const bd={active:{bg:"#e6f4ea",color:"#137333"},completed:{bg:"#e6f4ea",color:"#137333"},approved:{bg:"#e6f4ea",color:"#137333"},success:{bg:"#e6f4ea",color:"#137333"},done:{bg:"#e6f4ea",color:"#137333"},contract:{bg:"#e8eaf6",color:"#3949ab"},"in progress":{bg:"#e8eaf6",color:"#3949ab"},"in review":{bg:"#e8eaf6",color:"#3949ab"},review:{bg:"#e8eaf6",color:"#3949ab"},pending:{bg:"#e8eaf6",color:"#3949ab"},"on leave":{bg:"#fce8e6",color:"#c5221f"},"on hold":{bg:"#fff8e1",color:"#e65100"},probation:{bg:"#fff8e1",color:"#e65100"},cancelled:{bg:"#fce8e6",color:"#c5221f"},rejected:{bg:"#fce8e6",color:"#c5221f"},blocked:{bg:"#fce8e6",color:"#c5221f"},inactive:{bg:"#f1f3f4",color:"text.secondary"},"not started":{bg:"#f1f3f4",color:"text.secondary"},paused:{bg:"#f1f3f4",color:"text.secondary"}},vd={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function Sd(t){const o=t.toLowerCase().trim(),n=bd[o]||{bg:"#f1f3f4",color:"text.secondary"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function jd(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 Sd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=vd[n.toLowerCase().trim()];return s?e.jsx(r.Box,{component:"span",sx:{color:s,fontWeight:600,fontSize:"0.8125rem"},children:n}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function Cd(t){const o=t.find(s=>{const c=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(c)})||t[0]||null,n=t.find(s=>{const c=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(c)&&s!==o})||null,i=t.filter(s=>s!==o&&s!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function wd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:s,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:u,onEdit:m,onDuplicate:h,onDelete:b}){const[f,g]=p.useState(null),[T,y]=p.useState(!1),{primaryCol:w,idCol:v,bodyColumns:j}=p.useMemo(()=>Cd(n),[n]),S=w?t[w.name]:null,I=v?t[v.name]:null,a=T||i||s||!!f;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":A=>E(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 ${E(A.palette.primary.main,.15)}, 0 2px 8px ${E(A.palette.common.black,.08)}`:T?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:T&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:A=>E(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:S!=null&&S!==""?String(S):e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})}),e.jsx(r.Box,{sx:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}),e.jsxs(r.Box,{sx:{px:2,py:1.5,flex:1,display:"flex",flexDirection:"column",gap:1},children:[j.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:Ge(A.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:jd(A,t[A.name])})]},A.name)),j.length===0&&e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic"},children:"No additional fields visible"})]}),e.jsxs(r.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:A=>E(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:I?.85:0,userSelect:"none"},children:I?String(I):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:a?1:0,transition:"opacity 0.15s ease"},onClick:A=>A.stopPropagation(),children:[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?"#fbbc04":"action.disabled","&:hover":{bgcolor:A=>E(A.palette.warning.main,.1),color:"#fbbc04"}},children:s?e.jsx(k.Star,{sx:{fontSize:17}}):e.jsx(k.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:A=>{A.stopPropagation(),g(A.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:A=>E(A.palette.text.primary,.08)}},children:e.jsx(k.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!f,anchorEl:f,onClose:()=>g(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:"0 4px 20px rgba(60,64,67,0.15), 0 1px 6px rgba(60,64,67,0.1)"}},onClick:A=>A.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{u(t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(k.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{m(t,o),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(k.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),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(k.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{b(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(k.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function kd({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:s=>E(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(k.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(k.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:yi(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=>E(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,c])=>gi(c)).filter(Boolean).join(" • ")})]})}function Td({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:s,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:u,onToggleRowSelection:m,onToggleRowFavorite:h,onToggleGroupCollapse:b,onViewRow:f,onEditRow:g,onDuplicateRow:T,onDeleteRow:y}){const w=p.useMemo(()=>{const v=new Set;return i.forEach(j=>{const S=j==null?void 0:j.__urm_row_id__;S!==void 0&&v.add(S)}),v},[i]);return t.length===0?e.jsx(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):e.jsxs(r.Box,{children:[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(v=>{const j=l.find(S=>S.column===v.name);return e.jsxs(r.Box,{onClick:()=>u(v.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:j?"primary.main":"divider",bgcolor:j?S=>E(S.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:S=>E(S.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:j?600:400,color:j?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ge(v.name)}),j?j.direction==="asc"?e.jsx(k.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(k.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(k.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},v.name)})]}),e.jsx(r.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(272px, 1fr))",gap:1.5,alignContent:"start"},children:t.map((v,j)=>d&&v.isGroupHeader?e.jsx(kd,{row:v,grouping:n,onToggleCollapse:b||(()=>{})},`group-${v.groupKey}`):e.jsx(wd,{row:v,rowIndex:j,visibleColumns:o,isSelected:w.has(v==null?void 0:v.__urm_row_id__),isFavorite:s.has(v),isReadOnly:c,onToggleSelection:()=>m(v),onToggleFavorite:h,onView:f,onEdit:g,onDuplicate:T,onDelete:y},`card-${j}`))})]})}const ei=[10,15,25,50,100];function Id(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 zd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:c}){var N;const l=Tt().palette,u=Math.ceil(n/o),[m,h]=p.useState(String(t)),[b,f]=p.useState(null),[g,T]=p.useState(!1),y=p.useRef(null);p.useEffect(()=>{g||(h(String(t)),f(null))},[t,g]);const w=p.useCallback(()=>{const W=Id(m,u);if(W){f(W);return}const H=parseInt(m.trim(),10);f(null),T(!1),H!==t&&s(H)},[m,u,t,s]),v=p.useCallback(W=>{var H;W.key==="Enter"?(W.preventDefault(),w()):W.key==="Escape"&&(h(String(t)),f(null),T(!1),(H=y.current)==null||H.blur())},[w,t]),j=p.useCallback(()=>{h(String(t)),f(null),T(!1)},[t]),S=p.useCallback(()=>{T(!0),f(null),setTimeout(()=>{var W;return(W=y.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ei))return null;const I=()=>{h(String(t)),f(null),T(!1)},a=()=>{I(),s(1)},A=()=>{I(),t>1&&s(t-1)},B=()=>{I(),t<u&&s(t+1)},$=()=>{I(),s(u)},Y=(t-1)*o+1,Q=Math.min(t*o,n),te=`${Math.max(2,String(u).length+.5)}ch`,x={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:3,px:2,py:1,borderTop:"1px solid",borderColor:"divider",bgcolor:"background.paper",minHeight:48},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),e.jsx(r.Select,{value:o,onChange:W=>c(Number(W.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:ei.map(W=>e.jsx(r.MenuItem,{value:W,sx:{fontSize:"0.8125rem"},children:W},W))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[Y,"–",Q," of ",n]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),e.jsxs(r.Box,{sx:{position:"relative"},children:[b&&e.jsx(r.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:E(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${E(((N=l.common)==null?void 0:N.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:E(l.error.main,.4)}},children:e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:b})}),e.jsx(r.InputBase,{inputRef:y,value:m,onChange:W=>{h(W.target.value),b&&f(null)},onKeyDown:v,onFocus:S,onBlur:j,inputProps:{"aria-label":`Page number, 1 to ${u}`,style:{textAlign:"center",padding:"2px 0",width:te,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":g?"primary.main":"divider",borderRadius:"4px",bgcolor:b?E(l.error.main,.04):g?E(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 ${E(l.error.main,.2)}`:`0 0 0 2px ${E(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:a,disabled:t===1,size:"small",title:"First page",sx:x,children:e.jsx(k.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:A,disabled:t===1,size:"small",title:"Previous page",sx:x,children:e.jsx(k.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:B,disabled:t===u,size:"small",title:"Next page",sx:x,children:e.jsx(k.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:$,disabled:t===u,size:"small",title:"Last page",sx:x,children:e.jsx(k.LastPage,{sx:{fontSize:20}})})]})]})]})}function Ed(){return e.jsx(r.Chip,{icon:e.jsx(k.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const Hi="urm_hint_seen_";function Bd(t){try{return localStorage.getItem(Hi+t)==="true"}catch{return!1}}function Dd(t){try{localStorage.setItem(Hi+t,"true")}catch{}}function ti(t,o){if(t==null||t==="")return"";if(o==="boolean")return t?"True":"False";if(o==="object"||o==="array")try{return JSON.stringify(t,null,2)}catch{return String(t)}return String(t)}function ri(t){const o={fontSize:11};switch(t){case"number":return e.jsx(k.Numbers,{sx:o});case"boolean":return e.jsx(k.CheckBox,{sx:o});case"array":return e.jsx(k.DataArray,{sx:o});case"object":return e.jsx(k.DataObject,{sx:o});default:return e.jsx(k.TextFields,{sx:o})}}function oi(t,o){var n,i;switch(t){case"number":return{bg:E(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:E(((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:E(o.secondary.main,.08),color:o.secondary.main};default:return{bg:E(o.text.secondary,.07),color:o.text.secondary}}}function Od({open:t,onClose:o,row:n,schema:i,reportName:s}){var b,f;const d=Tt().palette;if(!n)return null;const l=i.filter(g=>g.name in n),u=l.filter(g=>g.type!=="object"&&g.type!=="array"),m=l.filter(g=>g.type==="object"||g.type==="array"),h=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${E(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${E(((f=d.common)==null?void 0:f.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:E(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.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(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:E(d.text.primary,.015)},children:[u.length>0&&e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"1px",bgcolor:"divider",m:2,mb:m.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:u.map((g,T)=>{const y=n[g.name],w=ti(y,g.type),v=!w,j=oi(g.type,d),S=T===u.length-1&&u.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:S?"span 2":"span 1",display:"flex",flexDirection:"column",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:j.bg,color:j.color,flexShrink:0},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ge(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:v?400:500,color:v?"text.disabled":"text.primary",fontStyle:v?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:v?"No value":w})]},g.name)})}),m.map(g=>{const T=n[g.name],y=ti(T,g.type),w=!y,v=oi(g.type,d);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:v.bg,color:v.color},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ge(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:v.bg,color:v.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:E(d.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:w?"text.disabled":"text.primary",fontStyle:w?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:w?"No value":y})]},g.name)}),l.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(k.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:3,py:.75,borderRadius:"8px",minWidth:80},children:"Close"})})]})}function Ad({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:"#fce8e6",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:[i?`"${i}"`:"This record"," will be permanently removed."]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:"#fce8e6",border:"1px solid #f28b82"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"error.main",fontWeight:500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(k.DeleteForever,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Ho(t){const o={fontSize:11};switch(t){case"number":return e.jsx(k.Numbers,{sx:o});case"boolean":return e.jsx(k.CheckBox,{sx:o});case"array":return e.jsx(k.DataArray,{sx:o});case"object":return e.jsx(k.DataObject,{sx:o});default:return e.jsx(k.TextFields,{sx:o})}}function ni(t,o){var n,i;switch(t){case"number":return{bg:E(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:E(((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:E(o.secondary.main,.08),color:o.secondary.main};default:return{bg:E(o.text.secondary,.07),color:o.text.secondary}}}function Md({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:c}){var w,v,j;const l=Tt().palette,[u,m]=p.useState({});if(p.useEffect(()=>{t&&i&&m({...i})},[t,i]),!i)return null;const h=s.filter(S=>S.name in i),b=h.filter(S=>S.type!=="object"&&S.type!=="array"),f=h.filter(S=>S.type==="object"||S.type==="array"),g=(S,I)=>{m(a=>({...a,[S]:I}))},T=()=>{const S={...u};h.forEach(I=>{const a=u[I.name];if(I.type==="number"){const A=Number(a);S[I.name]=isNaN(A)?i[I.name]:A}else I.type==="boolean"&&(S[I.name]=!!a)}),n(S),o()},y=h.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${E(((w=l.common)==null?void 0:w.black)??"#000",.14)}, 0 2px 8px ${E(((v=l.common)==null?void 0:v.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:E(((j=l.warning)==null?void 0:j.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),c&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c," · ",y," ",y===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:E(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[b.length>0&&e.jsxs(r.Box,{children:[b.length>1&&e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em",mb:1.25},children:"Fields"}),e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1.5},children:b.map((S,I)=>{const a=u[S.name],A=ni(S.type,l),B=S.type==="boolean",$=!B&&I===b.filter(Q=>Q.type!=="boolean").length-1&&b.filter(Q=>Q.type!=="boolean").length%2!==0,Y=B||$;return S.type==="boolean"?e.jsxs(r.Box,{sx:{gridColumn:"span 2",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",px:2,py:1.5,display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,transition:"border-color 0.15s","&:hover":{borderColor:"primary.main"}},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.25},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:Ho(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ge(S.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:a?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!a,onChange:Q=>g(S.name,Q.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},S.name):e.jsxs(r.Box,{sx:{gridColumn:Y?"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 ${E(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:E(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:Ho(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ge(S.name)})]}),e.jsx(r.TextField,{value:a??"",onChange:Q=>g(S.name,Q.target.value),type:S.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${S.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:S.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},S.name)})})]}),f.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(k.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:f.map(S=>{const I=i[S.name];let a="";try{a=I==null?"":JSON.stringify(I,null,2)}catch{a=String(I)}const A=ni(S.type,l);return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",opacity:.8},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:E(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:Ho(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ge(S.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:E(l.text.secondary,.07),color:"text.secondary",border:"none"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:a?"text.primary":"text.disabled",fontStyle:a?"normal":"italic",bgcolor:E(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:a||"No value"})]},S.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(k.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:T,variant:"contained",disableElevation:!0,startIcon:e.jsx(k.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const _d=160,$d={active:{bg:"success.lighter",color:"success.dark"},completed:{bg:"success.lighter",color:"success.dark"},approved:{bg:"success.lighter",color:"success.dark"},success:{bg:"success.lighter",color:"success.dark"},done:{bg:"success.lighter",color:"success.dark"},contract:{bg:"primary.lighter",color:"primary.main"},"in progress":{bg:"primary.lighter",color:"primary.main"},"in review":{bg:"primary.lighter",color:"primary.main"},review:{bg:"primary.lighter",color:"primary.main"},pending:{bg:"primary.lighter",color:"primary.main"},"on leave":{bg:"error.lighter",color:"error.dark"},"on hold":{bg:"warning.lighter",color:"warning.dark"},probation:{bg:"warning.lighter",color:"warning.dark"},cancelled:{bg:"error.lighter",color:"error.dark"},rejected:{bg:"error.lighter",color:"error.dark"},blocked:{bg:"error.lighter",color:"error.dark"},inactive:{bg:"action.selected",color:"text.secondary"},"not started":{bg:"action.selected",color:"text.secondary"},paused:{bg:"action.selected",color:"text.secondary"}},Wd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Rd(t){const o=t.toLowerCase().trim(),n=$d[o]||{bg:"grey.100",color:"grey.600"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Pd(t){const o=t.toLowerCase().trim(),n=Wd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Nd(t){return e.jsx(r.Box,{component:"span",sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.8125rem",fontWeight:400,letterSpacing:"0.04em"},children:t})}function Ld(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),s=o.findIndex(m=>m.name===t.name),c=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),d=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),l=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),u=s===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||u&&!l}function Fd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Vd(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const s=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 Rd(s);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Pd(s);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(s);if(u)return Nd(s);if(n&&!d&&!l&&!u)return Fd(s);if(t.type==="date"){const m=t.dateFormat??"iso",h=Vs(o,m,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:"grey.400"},children:"[ ]"});const m=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:[m,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const m=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:m,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:m.length>40?m.slice(0,40)+"…":m})}return s}function Hd({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:u={},columnOrder:m=[],columnWidths:h={},grouping:b=null,onSort:f,onSortAscending:g,onSortDescending:T,onOpenFilters:y,onOpenSort:w,onOpenFilterForColumn:v,onSelectView:j,onCreateView:S,onManageViews:I,onUpdateCurrentView:a,onSaveAsNewView:A,onToggleDefault:B,onToggleFavorite:$,onRestoreView:Y,onPermanentDelete:Q,isAdmin:te=!1,onExport:x,onOpenColumns:N,onUpdateColumnWidth:W,onUpdateColumnOrder:H,onUpdateColumnVisibility:J,onClearFiltersForColumn:ue,onResetLayout:pe,onOpenGroup:re,onGroupByColumn:O,onToggleGroupCollapse:F,onOpenAuditHistory:G,onOpenScheduledReports:se,searchQuery:ee,searchHistory:le=[],onAddToSearchHistory:ae,onToggleSearchFavourite:P,onDeleteSearchHistory:ne,selectedRowIds:ce=new Set,onSearchChange:ie,onToggleRowSelection:he,onToggleAllRows:q,onRangeSelection:Ae,onClearSelection:We,onExportSelected:tt,currentPage:Kt=1,pageSize:hr=15,totalRowsBeforePagination:At=o.length,onPageChange:it,onPageSizeChange:Re,isReadOnly:Ee=!1,userRole:gt,reportName:st,onEditRow:rt,onDuplicateRow:Je,onDeleteRow:It,favoriteRowIndices:Xt=[],resolvedFavoritesSet:at=new Set,showFavoritesOnly:Ke=!1,onToggleRowFavorite:Pe,onBulkSetFavorites:Zt,showDevPanel:yt=!1,onOpenDevConfig:zt,onToggleFavoritesFilter:Qt}){var Ft;const[lt,gr]=p.useState(null),[yr,br]=p.useState(0),[Mt,vr]=p.useState(0),Xe=((Ft=Gt().dates)==null?void 0:Ft.displayFormat)??null,[ve,jr]=p.useState(null),[er,ot]=p.useState(null),[L,Ne]=p.useState(null),[Se,_e]=p.useState(!1),[Cr,_t]=p.useState(!1),[bt,$t]=p.useState(null),[Wt,Et]=p.useState(""),[wr,Rt]=p.useState(!1),[De,X]=p.useState(null),[vt,ge]=p.useState(null),[je,Ze]=p.useState(null),[kr,St]=p.useState(null),[$e,tr]=p.useState("list"),[Tr,rr]=p.useState(!1),[or,Ir]=p.useState(()=>!Bd("toolbar_search"));p.useRef(null);const nr=p.useCallback(()=>{Dd("toolbar_search"),Ir(!1)},[]),ir=p.useMemo(()=>m.length>0?m.map(M=>t.find(Z=>Z.name===M)).filter(M=>M!==void 0):t,[m,t]),Le=p.useMemo(()=>ir.filter(M=>u[M.name]!==!1),[ir,u]),ct=p.useMemo(()=>t.filter(M=>u[M.name]===!1).length,[t,u]),dt=p.useMemo(()=>t.map(M=>M.name),[t]),Fe=p.useMemo(()=>JSON.stringify(m)!==JSON.stringify(dt),[m,dt]),sr=p.useCallback((M,Z)=>{M.preventDefault(),M.stopPropagation(),gr(Z),br(M.clientX),vr(h[Z]||150)},[h]);p.useEffect(()=>{if(!lt)return;const M=K=>{const de=K.clientX-yr,oe=Math.max(100,Mt+de);W==null||W(lt,oe)},Z=()=>{gr(null)};return document.addEventListener("mousemove",M),document.addEventListener("mouseup",Z),()=>{document.removeEventListener("mousemove",M),document.removeEventListener("mouseup",Z)}},[lt,yr,Mt,W]);const Pt=p.useCallback(M=>M==null?"-":typeof M=="object"?JSON.stringify(M):typeof M=="boolean"?M?"true":"false":String(M),[]);p.useCallback(M=>{const Z=n.find(K=>K.column===M);return Z?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[Z.direction==="asc"?e.jsx(k.ArrowUpward,{sx:{fontSize:14}}):e.jsx(k.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:Z.priority})]}):null},[n]),p.useCallback(M=>i.some(K=>K.column===M)?e.jsx(r.IconButton,{size:"small",onClick:K=>{K.stopPropagation(),v==null||v(M)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(k.FilterList,{sx:{fontSize:14}})}):null,[i,v]);const zr=p.useCallback(M=>{f&&f(M)},[f]),Er=p.useCallback((M,Z)=>{if(!H)return;const K=[...m.length>0?m:t.map(oe=>oe.name)],[de]=K.splice(M,1);K.splice(Z,0,de),H(K)},[H,m,t]),Br=p.useCallback(M=>{if(!f)return;const Z=n.find(K=>K.column===M);(!Z||Z.direction!=="asc")&&f(M)},[f,n]),Dr=p.useCallback(M=>{if(!f)return;const Z=n.find(K=>K.column===M);Z?Z.direction==="asc"&&f(M):(f(M),setTimeout(()=>f(M),0))},[f,n]),Or=p.useCallback(M=>{if(!f)return;const Z=n.find(K=>K.column===M);Z&&(Z.direction==="asc"?(f(M),setTimeout(()=>f(M),0)):Z.direction==="desc"&&f(M))},[f,n]),Ar=p.useCallback(M=>{J&&J(M,!1)},[J]),Nt=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Mr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(M=>M===!1),_r=(Kt-1)*hr,Me=o,Ve=p.useMemo(()=>{const M=new Set;return ce.forEach(Z=>{const K=Z==null?void 0:Z.__urm_row_id__;K!==void 0&&M.add(K)}),M},[ce]);p.useEffect(()=>{const M=Z=>{!q||!We||Z.target instanceof HTMLInputElement||Z.target instanceof HTMLTextAreaElement||((Z.ctrlKey||Z.metaKey)&&Z.key==="a"&&(Z.preventDefault(),q(!0,Me)),Z.key==="Escape"&&(Z.preventDefault(),We()))};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[q,We,Me]);const ar=p.useCallback((M,Z)=>{he&&(Z.shiftKey&&ve!==null?(Z.preventDefault(),Ae&&Ae(ve,M,Me)):(he(Me[M]),jr(M)))},[he,ve,Ae,Me]);!p.useMemo(()=>Me.length>0&&Ve.size>0&&Me.every(M=>Ve.has(M==null?void 0:M.__urm_row_id__)),[Me,Ve])&&Me.some(M=>Ve.has(M==null?void 0:M.__urm_row_id__));const ut=he&&q,lr=p.useCallback(M=>{var de;const Z=M.groupLevel,K=Z*24;return e.jsx(r.TableRow,{onClick:()=>F==null?void 0:F(M.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Le.length+(ut?1:0),sx:{pl:`${K+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[M.isCollapsed?e.jsx(k.ChevronRight,{sx:{fontSize:16}}):e.jsx(k.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:yi(Z,((de=b==null?void 0:b.levels[Z])==null?void 0:de.column)||"",M.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:oe=>E(oe.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[M.rowCount," ",M.rowCount===1?"row":"rows"]}),Object.keys(M.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(M.aggregates).map(([oe,He])=>gi(He)).filter(Boolean).join(" • ")})]})})},M.groupKey)},[Le,ut,b,F]),Lt=p.useCallback((M,Z)=>{const K=Ve.has(M==null?void 0:M.__urm_row_id__),de=er===Z;return e.jsxs(r.TableRow,{"data-row-index":Z,onMouseEnter:()=>ot(Z),onMouseLeave:()=>ot(null),onClick:oe=>{!he||oe.target.closest("[data-row-action]")||ar(Z,oe)},onContextMenu:oe=>{oe.preventDefault(),oe.stopPropagation(),Ze({mouseX:oe.clientX,mouseY:oe.clientY,row:M,rowIndex:Z})},sx:{height:34,cursor:"pointer",bgcolor:K?oe=>E(oe.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:K?oe=>E(oe.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Le.map((oe,He)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:He===Le.length-1?`${(Pe?76:40)+16}px`:2,fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:h[oe.name]?`${h[oe.name]}px`:`${_d}px`},children:Vd(oe,M[oe.name],Ld(oe,Le),Xe)},oe.name)),e.jsx(r.TableCell,{"data-row-action":"true",onClick:oe=>oe.stopPropagation(),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",opacity:de?1:0,transition:"opacity 0.12s ease",bgcolor:"background.paper",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,{size:"small",onClick:oe=>{oe.stopPropagation(),oe.preventDefault(),Pe(M)},title:at.has(M)?"Remove from favorites":"Add to favorites",sx:{color:at.has(M)?"warning.main":"text.secondary","&:hover":{bgcolor:oe=>E(oe.palette.warning.main,.08),color:"warning.main"}},children:at.has(M)?e.jsx(k.Star,{sx:{fontSize:18}}):e.jsx(k.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:oe=>{oe.stopPropagation(),oe.preventDefault(),Ze({anchorEl:oe.currentTarget,row:M,rowIndex:Z})},sx:{color:"text.secondary","&:hover":{bgcolor:oe=>E(oe.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(k.MoreVert,{sx:{fontSize:18}})})]})})]},Z)},[ce,_r,er,ar,Le,h,Pt,rt,Je,It,he,Pe,at,Ne,_e,Ze]);return e.jsxs(wt.DndProvider,{backend:Xo.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[ut&&tt&&We&&e.jsx(yd,{selectedCount:Ve.size,selectedRowIds:ce,resolvedFavoritesSet:at,viewMode:$e,onExportSelected:tt,onClearSelection:We,onBulkSetFavorites:Zt}),e.jsxs(r.Box,{sx:{position:"sticky",top:0,zIndex:10,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",px:2,py:0,height:56,display:"flex",alignItems:"center",gap:1},children:[Ee&&e.jsx(Ed,{}),ie&&ae&&P&&ne&&e.jsx(r.Tooltip,{open:or,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:nr},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(xd,{value:ee||"",onChange:ie,searchHistory:le,onAddToHistory:ae,onToggleFavourite:P,onDeleteHistory:ne,disabled:Ee})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>rr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:M=>E(M.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(k.InfoOutlined,{sx:{fontSize:20}})})}),Qt&&e.jsx(r.Tooltip,{title:Ke?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:Qt,size:"small",disabled:Ee,sx:{position:"relative",color:Ke?"warning.main":"text.secondary",bgcolor:Ke?M=>E(M.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Ke?M=>E(M.palette.warning.main,.2):M=>E(M.palette.text.primary,.06),color:Ke?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[Ke?e.jsx(k.Star,{sx:{fontSize:20}}):e.jsx(k.StarBorder,{sx:{fontSize:20}}),Ke&&Xt.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:Xt.length})]})}),yt&&zt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:zt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:M=>E(M.palette.text.secondary,.3),"&:hover":{bgcolor:M=>E(M.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(k.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),j&&S&&I&&a&&s.length>0&&e.jsx(md,{views:s||[],activeViewId:c||"",isDirty:d,onSelectView:j,onCreateView:S,onManageViews:I,onToggleDefault:B,onToggleFavorite:$,onRestoreView:Y,onPermanentDelete:Q,isAdmin:te,isReadOnly:Ee}),!Ee&&w&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:w,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(k.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Ee&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(k.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Ee&&N&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:N,size:"small",sx:{position:"relative",color:ct>0||Fe?"primary.main":"text.secondary",bgcolor:ct>0||Fe?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ct>0||Fe?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:ct>0||Fe?"primary.main":"text.primary"}},children:[e.jsx(k.ViewColumn,{sx:{fontSize:20}}),ct>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:ct})]})}),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:()=>tr("list"),sx:{borderRadius:1,color:$e==="list"?"primary.main":"text.secondary",bgcolor:$e==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:$e==="list"?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:$e==="list"?"primary.main":"text.primary"}},children:e.jsx(k.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>tr("grid"),sx:{borderRadius:1,color:$e==="grid"?"primary.main":"text.secondary",bgcolor:$e==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:$e==="grid"?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:$e==="grid"?"primary.main":"text.primary"}},children:e.jsx(k.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:M=>St(M.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:M=>E(M.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(k.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!kr,anchorEl:kr,onClose:()=>St(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:[x&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{x(),St(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Ee&&re&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{re(),St(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),G&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{G(),St(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),se&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{se(),St(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.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:[$e==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Td,{data:Me,visibleColumns:Le,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:at,isReadOnly:Ee,isGrouped:!!Nt,sortStack:n,onSort:f,onToggleRowSelection:he||(()=>{}),onToggleRowFavorite:Pe,onToggleGroupCollapse:F,onViewRow:M=>{Ne(M),_e(!0)},onEditRow:(M,Z)=>{X(M),ge(Z),Rt(!0)},onDuplicateRow:(M,Z)=>Je==null?void 0:Je(M,Z),onDeleteRow:(M,Z)=>{$t(Z);const K=Object.values(Z).find(de=>de!=null&&de!=="");Et(K?String(K):""),_t(!0)}})}),$e==="list"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"auto",position:"relative",bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:M=>M.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:M=>M.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",width:"100%",minWidth:"100%"},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Le.map((M,Z)=>e.jsx(gd,{column:M,index:Z,sortRule:n.find(K=>K.column===M.name),hasFilters:i.some(K=>K.column===M.name),isInSortStack:n.some(K=>K.column===M.name),isReadOnly:Ee,hasModifications:Mr,width:h[M.name],onColumnClick:zr,onMoveColumn:Er,onResizeStart:sr,onSortAscending:g||Br,onSortDescending:T||Dr,onRemoveSort:Or,onOpenFilterForColumn:v||(()=>{}),onClearFiltersForColumn:ue||(()=>{}),onGroupByColumn:O,onHideColumn:Ar,onManageColumns:N||(()=>{}),onManageViews:I,onResetLayout:pe},M.name)),e.jsx(r.TableCell,{sx:{position:"sticky",top:0,right:0,width:Pe?76:40,minWidth:Pe?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover",zIndex:25}})]})}),e.jsx(r.TableBody,{children:Me.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Le.length+(ut?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):Nt?Me.map((M,Z)=>M.isGroupHeader?lr(M):Lt(M,Z)):Me.map((M,Z)=>Lt(M,Z))})]})}),it&&Re&&e.jsx(zd,{currentPage:Kt,pageSize:hr,totalRows:At,totalFields:t.length,onPageChange:it,onPageSizeChange:Re}),!(it&&Re)&&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 ",Me.length," ",Me.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!je,onClose:()=>Ze(null),anchorEl:(je==null?void 0:je.anchorEl)||null,anchorReference:je!=null&&je.anchorEl?"anchorEl":"anchorPosition",anchorPosition:je&&!je.anchorEl?{top:je.mouseY,left:je.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:je!=null&&je.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:()=>{je&&(Ne(je.row),_e(!0)),Ze(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{je&&(X(je.row),ge(je.rowIndex),Rt(!0)),Ze(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{je&&(Je==null||Je(je.rowIndex,je.row)),Ze(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.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(je){$t(je.row);const M=Object.values(je.row).find(Z=>Z!=null&&Z!=="");Et(M?String(M):""),_t(!0)}Ze(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(k.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Od,{open:Se,onClose:()=>{_e(!1),Ne(null)},row:L,schema:t,reportName:st}),e.jsx(Md,{open:wr,onClose:()=>{Rt(!1),X(null),ge(null)},onSave:M=>{vt!==null&&(rt==null||rt(vt,M))},row:De,schema:t,reportName:st}),e.jsx(Ad,{open:Cr,onClose:()=>{_t(!1),$t(null)},onConfirm:()=>{bt!==null&&(It==null||It(bt))},rowPreview:Wt}),e.jsx(Fi,{isOpen:Tr,onClose:()=>rr(!1)})]})}function qt({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=>E(s.palette.primary.main,.08)}},children:e.jsx(k.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=>E(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,c)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},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:s=>E(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>E(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 Jt={filter:{title:"Filter columns",description:"Narrow down rows by setting conditions on any column. Only rows matching all active filters are shown.",tips:["Add multiple conditions to combine filters (AND logic)",'Use "Contains" for partial text matches','Use "Is empty" to find missing values',"Clear all filters to return to the full dataset"],devNote:"Max filter conditions controlled by DevConfig → Filter → maxConditions. Allowed operators also configurable."},sort:{title:"Sort columns",description:"Order rows by one or more columns. Drag levels to set sort priority — the first level is applied first.",tips:["Add multiple sort levels for multi-column sorting","Drag the ⋮⋮ handle to reorder sort priority","Each level can be ascending (A→Z, 0→9) or descending"],devNote:"Max sort levels controlled by DevConfig → Sort → maxLevels."},grouping:{title:"Group data",description:"Organize rows into collapsible groups by one or more column values. Each unique value becomes a group header.",tips:["Add up to 3 nesting levels for hierarchical grouping","Click a group header to collapse or expand it","Aggregates (count) are shown on each group header","Combine grouping with filters and sort for focused views"],devNote:"Max group levels controlled by DevConfig → Grouping → maxLevels. allowNested and allowCollapse also configurable."},columns:{title:"Manage columns",description:"Control which columns are visible, their display order, and their widths.",tips:["Drag rows to reorder columns","Toggle the eye icon to show or hide a column","Drag the resize handle in the table header to resize","Reset to restore default visibility and order"],devNote:"Max visible columns and width range controlled by DevConfig → Columns."},export:{title:"Export data",description:"Download the report data as a file. Choose between CSV, Excel, or JSON format.",tips:["CSV: universal format, opens in any spreadsheet app","Excel: formatted .xlsx file with native Excel support","JSON: structured data including metadata","Export visible rows only (after filters) or all rows"],devNote:"Allowed export formats controlled by DevConfig → Export → allowedFormats."},schedule:{title:"Scheduled reports",description:"Set up automatic exports that run at a specified time — daily, weekly, or monthly.",tips:["The browser tab must remain open for the schedule to fire","Each schedule triggers a file download automatically","Add an email address to open a notification in your mail app","Pause a schedule without deleting it"],devNote:"Schedules are stored in localStorage per-report. Key: urm_schedules_{reportId}."},auditHistory:{title:"Audit history",description:"A full log of all changes made to this report — filters applied, sorts changed, views saved, exports triggered, and more.",tips:["Each entry shows the action, timestamp, and who performed it","Use audit history to trace back unexpected changes"],devNote:"Audit entries are stored per-report in IndexedDB via the persistence layer."}};function Ud({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:c,onClose:d,focusColumn:l}){const[u,m]=p.useState(""),[h,b]=p.useState(""),[f,g]=p.useState(""),[T,y]=p.useState([]),w=Gt();p.useEffect(()=>{y([...o])},[o]),p.useEffect(()=>{l&&m(l)},[l]);const v=p.useCallback(()=>{m(""),b(""),g("")},[]),j=p.useMemo(()=>t.filter(x=>x.type!=="mixed"&&x.type!=="null"&&x.type!=="array"&&x.type!=="object"),[t]),S=t.find(x=>x.name===u),I=p.useMemo(()=>{const x=S?wn(S.type):[],N=w.filter.allowedOperators;return N.length>0?x.filter(W=>N.includes(W.value)):x},[S]),a=p.useCallback(()=>!(!u||!h||to(h)&&!f.trim()||T.length>=w.filter.maxConditions),[u,h,f,T,w]),A=p.useCallback(()=>{if(!a())return;const x={column:u,operator:h};if(to(h)){const W=S==null?void 0:S.type;x.value=W==="number"?Number(f):f}if(T.some(W=>W.column===x.column&&W.operator===x.operator&&W.value===x.value)){v();return}y([...T,x]),v()},[a,u,h,S,f,T,v]),B=p.useCallback(x=>{y(T.filter((N,W)=>W!==x))},[T]),$=p.useMemo(()=>T.length!==o.length?!0:JSON.stringify(T)!==JSON.stringify(o),[T,o]),Y=p.useCallback(()=>{c(),T.forEach(x=>n(x)),d()},[T,n,c,d]),Q=p.useCallback(()=>{y([...o]),v(),d()},[o,v,d]),te=p.useCallback(x=>{var J;const N=t.find(ue=>ue.name===x.column);if(!N)return"";const H=((J=wn(N.type).find(ue=>ue.value===x.operator))==null?void 0:J.label)||x.operator;return to(x.operator)?`${x.column} ${H.toLowerCase()} "${x.value}"`:`${x.column} ${H.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:Q,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:x=>x.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Filter columns"}),e.jsx(qt,{content:Jt.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:Q,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Column"}),e.jsx(r.Select,{value:u,onChange:x=>{m(x.target.value),b(""),g("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:j.map(x=>e.jsxs(r.MenuItem,{value:x.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:N=>E(N.palette.primary.main,.2)}}},children:[Ge(x.name)," (",x.type,")"]},x.name))})]}),u&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Operator"}),e.jsx(r.Select,{value:h,onChange:x=>{b(x.target.value),g("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:I.map(x=>e.jsx(r.MenuItem,{value:x.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:N=>E(N.palette.primary.main,.2)}}},children:x.label},x.value))})]}),h&&to(h)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(S==null?void 0:S.type)==="number"?"number":"text",value:f,onChange:x=>g(x.target.value),label:"Value",placeholder:"Enter value...",sx:{"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:A,disabled:!a(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add another filter"})]}),T.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 (",T.length,")"]}),e.jsx(r.Button,{onClick:()=>y([]),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:T.map((x,N)=>e.jsx(r.Chip,{label:te(x),onDelete:()=>B(N),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:W=>`1px solid ${E(W.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:W=>E(W.palette.primary.main,.2),borderColor:"#aecbfa"},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},N))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:Q,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Y,disabled:!$,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"grey.300",color:"grey.500"}},children:"Apply filter"})]})]})})}const ii="SORT_RULE";function Yd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const c=p.useRef(null),[{handlerId:d},l]=wt.useDrop({accept:ii,collect(h){return{handlerId:h.getHandlerId()}},hover(h,b){var j;if(!c.current)return;const f=h.index,g=o;if(f===g)return;const T=(j=c.current)==null?void 0:j.getBoundingClientRect(),y=(T.bottom-T.top)/2,w=b.getClientOffset(),v=((w==null?void 0:w.y)??0)-T.top;f<g&&v<y||f>g&&v>y||(s(f,g),h.index=g)}}),[{isDragging:u},m]=wt.useDrag({type:ii,item:()=>({index:o}),collect:h=>({isDragging:h.isDragging()})});return m(l(c)),e.jsxs(r.Box,{ref:c,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)",transform:"translateY(-1px)"}},children:[e.jsx(r.Chip,{label:t.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)","& .MuiChip-label":{px:0}}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:h=>n(o,h.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:h=>E(h.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:h=>E(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:"rgba(217, 48, 37, 0.08)",transform:"scale(1.1)"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]})}function Gd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,c]=p.useState(""),[d,l]=p.useState([]);p.useEffect(()=>{l([...o])},[o]);const u=Gt(),m=p.useCallback(()=>!(d.length>=u.sort.maxLevels||!s||d.some(j=>j.column===s)),[d,s]),h=p.useCallback(()=>{if(!m())return;const j=d.length+1,S={column:s,direction:"asc",priority:j};l([...d,S]),c("")},[m,s,d]),b=p.useCallback(j=>{const I=d.filter((a,A)=>A!==j).map((a,A)=>({...a,priority:A+1}));l(I)},[d]),f=p.useCallback((j,S)=>{const I=[...d];I[j]={...I[j],direction:S},l(I)},[d]),g=p.useCallback((j,S)=>{const I=[...d],[a]=I.splice(j,1);I.splice(S,0,a);const A=I.map((B,$)=>({...B,priority:$+1}));l(A)},[d]),T=p.useCallback(()=>{l([])},[]),y=p.useCallback(()=>{n(d),i()},[d,n,i]),w=p.useCallback(()=>{l([...o]),c(""),i()},[o,i]),v=t.filter(j=>!d.some(S=>S.column===j.name));return e.jsx(wt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:w,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:j=>j.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),e.jsx(qt,{content:Jt.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:w,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:d.length>=u.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:j=>c(j.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:v.map(j=>e.jsx(r.MenuItem,{value:j.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:S=>E(S.palette.primary.main,.2)}}},children:Ge(j.name)},j.name))})]}),e.jsx(r.Button,{onClick:h,disabled:!m(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),d.length>=u.sort.maxLevels&&e.jsxs(r.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",u.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,"/",u.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:T,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((j,S)=>e.jsx(Yd,{rule:j,index:S,onToggleDirection:f,onRemove:b,onMove:g},`${j.column}-${S}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:w,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:y,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function qd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:u,isAdmin:m=!1,onClose:h}){var S,I;const f=Tt().palette,g=t.filter(a=>!a.isDeleted),T=t.filter(a=>a.isDeleted),y=g.filter(a=>a.scope==="global"),w=g.filter(a=>a.scope!=="global"),v=a=>{var Q,te,x,N,W;const A=a.scope==="global",B=a.id===o,$=m||!A,Y=m&&!A;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:B?"primary.main":"divider",bgcolor:B?E(f.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:B?"primary.main":E(f.text.primary,.22)}},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.75,py:1.25,gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,minWidth:0,cursor:"pointer",display:"flex",alignItems:"center",gap:1},onClick:()=>{n(a.id),h()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:B?600:500,color:B?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),a.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[A&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(k.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:E(((Q=f.info)==null?void 0:Q.main)??f.primary.main,.1),color:((te=f.info)==null?void 0:te.main)??f.primary.main,border:`1px solid ${E(((x=f.info)==null?void 0:x.main)??f.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),a.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:E(f.text.secondary,.08),color:"text.secondary","& .MuiChip-label":{px:.75}}})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[Y&&u&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:H=>{H.stopPropagation(),u(a.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((N=f.info)==null?void 0:N.main)??f.primary.main,bgcolor:E(((W=f.info)==null?void 0:W.main)??f.primary.main,.08)}},children:e.jsx(k.Language,{sx:{fontSize:16}})})}),$&&e.jsx(r.Tooltip,{title:A&&!m?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:A&&!m,onClick:H=>{H.stopPropagation(),s(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:E(f.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(k.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:A&&!m?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:A&&!m,onClick:H=>{H.stopPropagation(),c(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:E(f.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})})]})]})},a.id)},j=a=>{var A;return e.jsxs(r.Paper,{variant:"outlined",sx:{px:1.75,py:1.25,borderRadius:"8px",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:E(f.text.primary,.02)},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",color:"text.disabled",textDecoration:"line-through",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[d&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),d(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:E(((A=f.success)==null?void 0:A.main)??"#2e7d32",.08)}},children:e.jsx(k.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(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:E(f.error.main,.08)}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})]})]},a.id)};return e.jsxs(r.Dialog,{open:!0,onClose:h,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"14px",maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${E(((S=f.common)==null?void 0:S.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600},children:"Manage Views"}),m&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:"Admin mode — you can promote Personal Views to Global"})]}),e.jsx(r.IconButton,{onClick:h,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",disableElevation:!0,startIcon:e.jsx(k.Add,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",borderRadius:"7px",fontWeight:500},children:"Create New View"})}),y.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1},children:[e.jsx(k.Language,{sx:{fontSize:14,color:((I=f.info)==null?void 0:I.main)??f.primary.main}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Global Views"}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:"— visible to all users"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:y.map(v)})]}),w.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:w.map(v)})]}),T.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:T.map(j)})]}),g.length===0&&T.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",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const so=50;function si({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:u=10}){const[m,h]=p.useState(s),[b,f]=p.useState(!1),[g,T]=p.useState(c),[y,w]=p.useState(d),v=()=>{if(!m.trim()){f(!0);return}if(m.trim().length>so){f(!0);return}o(m.trim(),g.trim(),y),n()},j=I=>{I.key==="Enter"&&!I.shiftKey?v():I.key==="Escape"&&n()},S=()=>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:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[S(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",u," saved views. Delete an existing view before creating a new one."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:m,onChange:I=>{I.target.value.length<=so&&h(I.target.value),b&&I.target.value.trim()&&f(!1)},onKeyDown:j,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:so},error:b&&!m.trim(),helperText:b&&!m.trim()?"View name is required":`${m.length} / ${so}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:I=>T(I.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: ",ra(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:y,onChange:I=>w(I.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:v,variant:"contained",disabled:l&&!i,startIcon:e.jsx(k.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:i?"Save Changes":"Create Report View"})]})]})}function Jd({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["Delete View",e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.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(k.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete View"})]})]})}const Jo=80,Ko=600,ai="COLUMN";function Kd({column:t,index:o,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:c,moveColumn:d}){const l=p.useRef(null),[u,m]=p.useState(i.toString());p.useEffect(()=>{m(i.toString())},[i]);const[{handlerId:h},b]=wt.useDrop({accept:ai,collect(j){return{handlerId:j.getHandlerId()}},hover(j,S){var Q;if(!l.current)return;const I=j.index,a=o;if(I===a)return;const A=(Q=l.current)==null?void 0:Q.getBoundingClientRect(),B=(A.bottom-A.top)/2,$=S.getClientOffset(),Y=(($==null?void 0:$.y)??0)-A.top;I<a&&Y<B||I>a&&Y>B||(d(I,a),j.index=a)}}),[{isDragging:f},g]=wt.useDrag({type:ai,item:()=>({index:o}),collect:j=>({isDragging:j.isDragging()})});g(b(l));const T=()=>{const j=parseInt(u);if(isNaN(j)){m(i.toString()),c(t.name,i);return}const S=Math.max(Jo,Math.min(Ko,j));m(S.toString()),c(t.name,S)},y=j=>{if(j===""||/^\d+$/.test(j)){m(j);const S=parseInt(j);if(!isNaN(S)&&S>=Jo){const I=Math.min(Ko,S);c(t.name,I)}}},w=j=>{j.key==="Enter"&&(j.preventDefault(),T(),j.target.blur())},v=j=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[j]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":h,sx:{opacity:f?.4:1,bgcolor:n?"background.paper":"grey.50",transition:"all 0.2s ease","&:hover":{bgcolor:n?"grey.50":"grey.100"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(k.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ge(t.name)})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsx(r.Chip,{label:t.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${v(t.type)}15`,color:v(t.type),border:`1px solid ${v(t.type)}30`,"& .MuiChip-label":{px:1}}})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.TextField,{type:"text",value:u,onChange:j=>y(j.target.value),onBlur:T,onKeyDown:w,placeholder:"150",size:"small",sx:{width:80,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"}}}),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:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(k.Visibility,{sx:{fontSize:20}}):e.jsx(k.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?"#e6f4ea":"grey.100",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Xd({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:u,onResetLayout:m,onSaveToCurrentView:h,onSaveToAllViews:b,onSelectView:f,onClose:g}){const[T,y]=p.useState(!1),[w,v]=p.useState(n),[j,S]=p.useState(i),[I,a]=p.useState("all"),[A,B]=p.useState(null);p.useEffect(()=>{v(n)},[n]),p.useEffect(()=>{S(i)},[i]);const $=(re,O)=>{S(F=>({...F,[re]:O}))},Y=(re,O)=>{const F=[...w],[G]=F.splice(re,1);F.splice(O,0,G),v(F),l(F)},Q=()=>{m(),y(!1)},x=w.map(re=>t.find(O=>O.name===re)).filter(re=>re!==void 0).filter(re=>{const O=o[re.name]??!0;return I==="active"?O:I==="hidden"?!O:!0}),N=Object.values(o).filter(re=>re).length,W=t.length,H=s.find(re=>re.id===c),J=s.filter(re=>!re.isDeleted),ue=J.length>1,pe=p.useMemo(()=>{if(!H)return!1;const re=H.snapshot,O=JSON.stringify(o)!==JSON.stringify(re.columnVisibility),F=JSON.stringify(n)!==JSON.stringify(re.columnOrder),G=JSON.stringify(j)!==JSON.stringify(re.columnWidths);return O||F||G},[H,o,n,j]);return e.jsx(wt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:re=>re.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2,pb:1.5,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsxs(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",e.jsx(qt,{content:Jt.columns,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5},children:[N," of ",W," columns visible • Drag to reorder"]})]}),J.length>0&&f&&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:re=>B(re.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(k.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(H==null?void 0:H.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:A,open:!!A,onClose:()=>B(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:J.map(re=>e.jsx(r.MenuItem,{onClick:()=>{f(re.id),B(null)},selected:re.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:O=>E(O.palette.primary.main,.2)}}},children:re.name},re.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:I,onChange:(re,O)=>a(O),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:"primary.main",height:3}},children:[e.jsx(r.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}})]})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${Jo}px, max: ${Ko}px)`,arrow:!0,placement:"top",children:e.jsx(k.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:x.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"})})}):x.map((re,O)=>e.jsx(Kd,{column:re,index:O,isVisible:o[re.name]??!0,width:j[re.name]||150,onToggleVisibility:d,onWidthChange:$,moveColumn:Y},re.name))})]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!0),disabled:!pe,variant:"outlined",startIcon:e.jsx(k.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[h&&e.jsx(r.Button,{onClick:()=>{h(j),g()},disabled:!pe,variant:"contained",startIcon:e.jsx(k.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&ue&&e.jsx(r.Button,{onClick:()=>{b(j),g()},disabled:!pe||!ue,variant:"contained",startIcon:e.jsx(k.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),T&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1400},children:e.jsxs(r.Paper,{onClick:re=>re.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:"12px",bgcolor:"background.paper",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,borderRadius:"4px","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Q,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function Zd({schema:t,grouping:o,onApply:n,onClose:i}){var A;const[s,c]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=p.useState(""),[u,m]=p.useState(null),h=p.useMemo(()=>Ks(t),[t]),b=p.useMemo(()=>h.filter(B=>!s.levels.some(($,Y)=>$.column===B.name&&Y!==u)),[h,s.levels,u]),f=Gt(),g=s.levels.length<f.grouping.maxLevels&&b.length>0,T=p.useCallback(()=>{!g||!d||(c({...s,levels:[...s.levels,{column:d}],enabled:!0}),l(""))},[g,d,s]),y=p.useCallback(B=>{const $=s.levels.filter((Y,Q)=>Q!==B);if($.length===0){n(null),i();return}c({...s,levels:$,enabled:$.length>0})},[s,n,i]),w=p.useCallback(B=>{m(B),l(s.levels[B].column)},[s.levels]),v=p.useCallback(()=>{if(u===null||!d)return;const B=[...s.levels];B[u]={column:d},c({...s,levels:B}),m(null),l("")},[u,d,s]),j=p.useCallback(()=>{m(null),l("")},[]),S=p.useCallback((B,$)=>{const Y=$==="up"?B-1:B+1;if(Y<0||Y>=s.levels.length)return;const Q=[...s.levels],[te]=Q.splice(B,1);Q.splice(Y,0,te),c({...s,levels:Q})},[s]),I=p.useCallback(()=>{n(null),i()},[n,i]),a=p.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[s,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:B=>B.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),e.jsx(qt,{content:Jt.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Stack,{spacing:2.5,children:[u===null&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:B=>l(B.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:$=>E($.palette.primary.main,.2)}}},children:[Ge(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsx(r.Button,{onClick:T,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(k.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),s.levels.length>=f.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:"1px solid #fdd663",bgcolor:"#fef7e0","& .MuiAlert-icon":{color:"#ea8600"}},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1.5,fontSize:"0.875rem",color:"text.primary"},children:["Edit Group Level ",u+1]}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:B=>l(B.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:s.levels[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},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:"primary.lighter"}},children:[Ge(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:v,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"#ea8600",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"#c96e00",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)"}},children:"Save"}),e.jsx(r.Button,{onClick:j,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),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:I,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:s.levels.map((B,$)=>{const Y=t.find(Q=>Q.name===B.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1)"}},children:[e.jsx(r.Chip,{label:`L${$+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)"}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:B.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:Y==null?void 0:Y.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"up"),disabled:$===0,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(k.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"down"),disabled:$===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(k.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>w($),sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100",color:"primary.main"}},children:e.jsx(k.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y($),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(k.Delete,{sx:{fontSize:18}})})]})]},$)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:a,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const Qd={filters:k.FilterList,sorting:k.UnfoldMore,visibility:k.Visibility,order:k.ViewColumn,widths:k.Straighten,grouping:k.Layers};function eu({changes:t,onClose:o}){const n=i=>({filters:"primary",sorting:"secondary",visibility:"success",order:"warning",widths:"info",grouping:"error"})[i]||"default";return e.jsxs(r.Dialog,{open:!0,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["View Changes Summary",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.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 c=Qd[i.category];return e.jsxs(r.Paper,{elevation:0,sx:{display:"flex",gap:1.5,p:1.5,border:1,borderColor:"divider",borderRadius:1},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:1,bgcolor:`${n(i.category)}.lighter`,color:`${n(i.category)}.main`,flexShrink:0},children:e.jsx(c,{sx:{fontSize:16}})}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:i.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:i.description})]})]},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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})}function tu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:s,onCancel:c}){const[d,l]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:"primary.lighter",borderBottom:u=>`1px solid ${E(u.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:"rgba(60, 64, 67, 0.08)",color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:s,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:"0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px rgba(60, 64, 67, 0.15)"}},children:"Save as new view"})]})]})}),d&&e.jsx(eu,{changes:n,onClose:()=>l(!1)})]})}function ru({onExportAnyway:t,onSaveAndExport:o,onCancel:n}){return e.jsx(r.Box,{sx:{mb:2,mx:3,mt:2},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(k.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(k.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(k.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const li=[{key:"1h",label:"Last 1 Hour",ms:3600*1e3},{key:"24h",label:"Last 24 Hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 Days",ms:10080*60*1e3},{key:"30d",label:"Last 30 Days",ms:720*60*60*1e3},{key:"all",label:"All Time",ms:null}];function ou(t,o){if(o===null)return t.length;const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()>=n).length}function nu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function iu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var T,y,w,v;const s=Tt().palette,[c,d]=p.useState("1h"),[l,u]=p.useState(!1),m=[...t].sort((j,S)=>new Date(S.timestamp).getTime()-new Date(j.timestamp).getTime()),h=li.find(j=>j.key===c),b=ou(t,h.ms),f=()=>u(!0),g=()=>{n&&(n(nu(t,h.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:E(((T=s.common)==null?void 0:T.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:j=>j.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"16px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${E(((y=s.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${E(((w=s.common)==null?void 0:w.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(qt,{content:Jt.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[m.length," event",m.length!==1?"s":""," recorded"]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Select,{value:c,onChange:j=>d(j.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:E(s.text.primary,.3)}},children:li.map(j=>e.jsx(r.MenuItem,{value:j.key,sx:{fontSize:"0.8125rem"},children:j.label},j.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(k.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:f,sx:{textTransform:"none",fontSize:"0.75rem",fontWeight:500,borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:E(s.error.main,.5),"&:hover":{bgcolor:E(s.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:E(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:E(s.text.primary,.14),borderRadius:3}},children:m.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(k.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",color:"text.secondary",fontWeight:500},children:"No audit events yet"}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:m.map(j=>{const S=ba(j.feature),{summary:I,detail:a}=fa(j);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:E(s.text.primary,.18)}},children:[e.jsx(r.Chip,{label:ya(j.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:E(S,.1),color:S,border:`1px solid ${E(S,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:I}),a&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:a}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(k.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:va(j.timestamp)})]}),j.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(k.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:j.user})]})]})]})]},j.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${E(((v=s.common)==null?void 0:v.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:E(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.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:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",disableElevation:!0,startIcon:e.jsx(k.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function su({onSave:t,onClose:o}){const[n,i]=p.useState(""),[s,c]=p.useState(""),[d,l]=p.useState(""),[u,m]=p.useState([]),[h,b]=p.useState(""),[f,g]=p.useState(""),T=a=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a),y=()=>{const a=d.trim();if(a){if(!T(a)){g("Please enter a valid email address");return}if(u.includes(a)){g("This email is already added");return}m([...u,a]),l(""),g("")}},w=a=>{m(u.filter(A=>A!==a))},v=a=>{a.key==="Enter"&&(a.preventDefault(),y())},j=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),s.trim(),u.length>0?u:void 0)},S=a=>{i(a),h&&b("")},I=a=>{l(a),f&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:a=>a.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(k.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:a=>`1px solid ${E(a.palette.primary.main,.3)}`,bgcolor:"primary.lighter","& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.6},children:"Save the current report configuration and generate a shareable link that others can use to view the same filters, sorting, and column layout."}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),e.jsx(r.TextField,{required:!0,value:n,onChange:a=>S(a.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!h,helperText:h,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value:s,onChange:a=>c(a.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:d,onChange:a=>I(a.target.value),onKeyPress:v,placeholder:"Enter email address",error:!!f,helperText:f,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(k.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),e.jsx(r.Button,{onClick:y,variant:"outlined",startIcon:e.jsx(k.Add,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",px:2,py:1.25,minHeight:40,borderRadius:"4px",flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:"Add"})]}),u.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:u.map(a=>e.jsx(r.Chip,{label:a,onDelete:()=>w(a),deleteIcon:e.jsx(k.Delete,{sx:{fontSize:16}}),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},a))}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:u.length>0?`An email with the shareable link will be sent to ${u.length} recipient${u.length>1?"s":""}`:"Add email addresses to send the shareable link automatically"})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:j,variant:"contained",startIcon:e.jsx(k.Share,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function au({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(k.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(k.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>E(n.palette.primary.main,.12),borderColor:"primary.light",border:1,fontSize:"body2.fontSize",fontWeight:500,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.main"}}}})}function lu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:s}){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:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:u=>u.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"common.white",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[t.length," saved ",t.length===1?"preset":"presets"]})]}),e.jsx(r.IconButton,{onClick:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:"#bdc1c6"}}},children:t.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[e.jsx(k.Share,{sx:{fontSize:48,color:"divider",mb:2}}),e.jsx(r.Typography,{variant:"body1",sx:{fontSize:"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"#80868b",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:t.map(u=>e.jsxs(r.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"common.white",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary",mb:.5},children: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:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}}),e.jsx(r.Chip,{label:`By ${u.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),e.jsx(r.Divider,{sx:{my:1.5,borderColor:"#f1f3f4"}}),e.jsx(r.Box,{sx:{display:"flex",gap:1},children:e.jsx(r.Button,{onClick:()=>i(u.id,u.name),variant:"outlined",size:"small",startIcon:e.jsx(k.Delete,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:"4px","&:hover":{borderColor:"error.main",bgcolor:"rgba(217, 48, 37, 0.04)"}},children:"Delete"})})]},u.id))})}),e.jsx(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:e.jsx(r.Button,{onClick:s,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})})}const Ui={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},cu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],du=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function uu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=du.some(l=>l.test(i.name));let c=!1;const d=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);d.length>0&&(c=d.filter(u=>cu.some(m=>m.test(u))).length/d.length>.6),(s||c)&&n.push(i.name)}return n}function an(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),s=o.map(d=>{const l=n.map(m=>String(m[d]??"")).filter(m=>m.length>0);if(l.length===0)return 5;const u=l.reduce((m,h)=>m+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)+s*t.length}function pu(t,o){const n=an(t,o);return Math.ceil(n*3.5)}function xu(t,o){const n=an(t,o);return Math.ceil(n*.7)}function mu(t,o,n){switch(t){case"csv":return an(o,n);case"excel":return xu(o,n);case"json":return pu(o,n)}}function ci(t,o){return Math.ceil(t/o)}function fu(t,o,n,i,s=Ui){const c=[],d=mu(t,o,n),l=o.length;if(l>s.maxRowsHard){const h=ci(l,s.maxRows);c.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=ci(l,s.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 ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:s.maxRows})}if(d>s.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Ur(d)} exceeds the ${Ur(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:d,limit:s.maxFileSizeHardBytes}):d>s.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Ur(d)}`,detail:`This exceeds the recommended ${Ur(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:s.maxFileSizeBytes}),t!=="excel"){const h=uu(i.filter(b=>n.includes(b.name)),o);if(h.length>0){const b=h.length>s.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${h.length>1?"s":""} detected: ${h.map(f=>`"${f.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=c.some(h=>h.severity==="error"),m=c.some(h=>h.severity==="warning");return{violations:c,hasBlockingViolation:u,hasWarning:m,estimatedBytes:d}}function Ur(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function hu({violation:t}){const n=Tt().palette,i=t.severity==="error",s=i?n.error.main:n.warning.main,c=E(i?n.error.main:n.warning.main,.06),d=i?E(n.error.main,.25):E(n.warning.main,.3),l=i?k.ErrorOutline:k.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: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(k.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function gu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:c,sampleRows:d=[],allRows:l=[],processedRows:u=[],onExport:m,onClose:h}){var N,W,H;const f=Tt().palette,g=Gt(),[T,y]=p.useState(g.export.allowedFormats[0]||"csv"),[w,v]=p.useState("visible"),[j,S]=p.useState("visible"),I=w==="visible"?o:t,a=j==="visible"?i:s,A=p.useMemo(()=>w==="visible"?u.length>0?u:new Array(o):l.length>0?l:new Array(t),[w,o,t,u,l]),B=p.useMemo(()=>j==="all"?c.map(J=>J.name):c.map(J=>J.name).slice(0,i),[j,c,i]),$=p.useMemo(()=>fu(T,A,B,c,Ui),[T,A,B,c]),Y=()=>{$.hasBlockingViolation||(m({format:T,scope:w,columnScope:j}),h())},Q={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},te={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},x={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:h,sx:{position:"fixed",inset:0,bgcolor:E(((N=f.common)==null?void 0:N.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:J=>J.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"14px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${E(((W=f.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${E(((H=f.common)==null?void 0:H.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(qt,{content:Jt.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(k.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:E(f.text.primary,.15),borderRadius:3}},children:[$.violations.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:$.violations.map((J,ue)=>e.jsx(hu,{violation:J},ue))}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Format"}),e.jsxs(r.RadioGroup,{value:T,onChange:J=>y(J.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Comma-separated values, compatible with Excel"})]}),sx:{...te,mb:.5}}),g.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Native Excel format with formatting support"})]}),sx:{...te,mb:.5}}),g.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:x}),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:w,onChange:J=>v(J.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:x}),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:x}),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:j,onChange:J=>S(J.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:x}),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:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",s," columns (including hidden)"]})]}),sx:te})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Divider,{sx:{mb:2}}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[{label:"Format",value:Q[T]},{label:"Rows to export",value:I.toLocaleString()},{label:"Columns to export",value:String(a)},{label:"Estimated file size",value:Ur($.estimatedBytes),highlight:$.hasBlockingViolation?"error.main":$.hasWarning?"warning.main":void 0}].map(({label:J,value:ue,highlight:pe})=>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:J}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:pe??"text.primary"},children:ue})]},J))})]})]}),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:E(f.text.primary,.015)},children:[$.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(k.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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:Y,disabled:$.hasBlockingViolation,variant:"contained",disableElevation:!0,startIcon:e.jsx(k.Download,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"8px"},children:["Download ",Q[T]]})]})]})})}function yu({warning:t,onDismiss:o}){return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(k.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:t.message}),e.jsxs(r.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",t.type==="filter"?"filters":t.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function bu({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){p.useEffect(()=>{if(n){const l=setTimeout(()=>{o()},i);return()=>clearTimeout(l)}},[n,i,o]);const c=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(k.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(k.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Aa(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(k.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${c.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:d}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class vu extends p.Component{constructor(o){super(o),this.handleReset=()=>{this.setState({hasError:!1,error:null})},this.state={hasError:!1,error:null}}static getDerivedStateFromError(o){return{hasError:!0,error:o}}componentDidCatch(o,n){Ut.error("urm:error-boundary","Caught unhandled component error",o,n),this.props.onError&&this.props.onError(o,n)}render(){var o,n;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsx(r.Paper,{sx:{bgcolor:i=>E(i.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(k.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:i=>E(i.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:160},children:(n=this.state.error)==null?void 0:n.stack}),e.jsx(r.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:e.jsx(k.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Nr({children:t,feature:o,onError:n}){return e.jsx(vu,{context:o,onError:(i,s)=>{n&&n(i)},fallback:e.jsxs(r.Alert,{severity:"warning",sx:{m:1},icon:e.jsx(k.Warning,{sx:{fontSize:20}}),children:[e.jsxs(r.AlertTitle,{children:[o," temporarily unavailable"]}),"Other features continue to work normally"]}),children:t})}const Su=[{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"}],ju=[{value:"csv",label:"CSV",desc:"Comma-separated values"},{value:"excel",label:"Excel (.xlsx)",desc:"Native Excel format"},{value:"json",label:"JSON",desc:"Structured data with metadata"}];function Lr({children:t,active:o}){return e.jsx(r.Box,{hidden:!o,sx:{pt:2.5,pb:1,display:o?"flex":"none",flexDirection:"column",gap:2.5},children:t})}function Cu({open:t,onClose:o,config:n,onApply:i}){const[s,c]=p.useState(0),[d,l]=p.useState(n),u=()=>l(n),m=()=>l(Ue),h=()=>{i(d),o()},b={sort:w=>l(v=>({...v,sort:{...v.sort,...w}})),filter:w=>l(v=>({...v,filter:{...v.filter,...w}})),columns:w=>l(v=>({...v,columns:{...v.columns,...w}})),grouping:w=>l(v=>({...v,grouping:{...v.grouping,...w}})),export:w=>l(v=>({...v,export:{...v.export,...w}}))},f=w=>{const v=d.filter.allowedOperators,j=v.includes(w)?v.filter(S=>S!==w):[...v,w];j.length!==0&&b.filter({allowedOperators:j})},g=w=>{const v=d.export.allowedFormats,j=v.includes(w)?v.filter(S=>S!==w):[...v,w];j.length!==0&&b.export({allowedFormats:j})},T=[{label:"Sort",icon:e.jsx(k.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(k.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(k.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(k.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(k.Download,{sx:{fontSize:17}})}],y=w=>JSON.stringify(d[w])===JSON.stringify(Ue[w]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.2)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:w=>E(w.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(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:s,onChange:(w,v)=>c(v),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:T.map((w,v)=>e.jsx(r.Tab,{label:w.label,icon:w.icon,iconPosition:"start"},v))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Lr,{active:s===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!y("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:d.sort.maxLevels,onChange:(w,v)=>b.sort({maxLevels:v}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(Lr,{active:s===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!y("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:d.filter.maxConditions,onChange:(w,v)=>b.filter({maxConditions:v}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(w=>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:w}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:Su.filter(v=>v.group===w).map(v=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(v.value),onChange:()=>f(v.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:v.label}),sx:{mr:1.5}},v.value))})]},w))]})]}),e.jsxs(Lr,{active:s===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!y("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:d.columns.maxVisible,onChange:(w,v)=>b.columns({maxVisible:v}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:d.columns.minColumnWidth,onChange:(w,v)=>b.columns({minColumnWidth:v}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:w=>`${w}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:(w,v)=>b.columns({maxColumnWidth:v}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:w=>`${w}px`})]})]})]})]}),e.jsxs(Lr,{active:s===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!y("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(w=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:w}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===w?"primary.main":"divider",bgcolor:d.grouping.maxLevels===w?v=>E(v.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:v=>E(v.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:d.grouping.maxLevels===w?"primary.main":"text.secondary"},children:w}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][w-1]})]},w))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowNested,onChange:w=>b.grouping({allowNested:w.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:w=>b.grouping({allowCollapse:w.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),e.jsx(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),e.jsx(Lr,{active:s===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!y("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),e.jsx(r.FormGroup,{sx:{gap:1},children:ju.map(w=>e.jsxs(r.Box,{onClick:()=>g(w.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(w.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(w.value)?v=>E(v.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(w.value),onChange:()=>g(w.value),onClick:v=>v.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:w.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:w.desc})]})]},w.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:w=>E(w.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(k.RestartAlt,{sx:{fontSize:18}}),onClick:m,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:w=>E(w.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:h,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const wu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ku={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 lo(t,o,n,i,s=new Date){const[c,d]=o.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(c,d,0,0),t==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const u=n??1,m=l.getDay();let h=u-m;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 Tu(t){const o=Yi(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${wu[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${ku[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Yi(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Iu(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),c=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${c}m`:c>0?`in ${c}m`:"in less than a minute"}function zu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=Yi(`${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 Gi(t){return`urm_schedules_${t}`}function qi(t){try{const o=localStorage.getItem(Gi(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 Ji(t,o){try{localStorage.setItem(Gi(t),JSON.stringify(o))}catch{}}const Eu=[{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"}],Bu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Ki={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Ht={"& .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 Du({initial:t=Ki,isEditing:o=!1,onSave:n,onBack:i}){const[s,c]=p.useState(t),[d,l]=p.useState(!1),[u,m]=p.useState(!1),h=(g,T)=>c(y=>({...y,[g]:T})),b=s.email.trim().length>0&&!Bu.test(s.email.trim()),f=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.dayOfMonth<=28)&&!b;return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[e.jsx(r.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:g=>E(g.palette.text.primary,.06)}},children:e.jsx(k.ArrowBack,{sx:{fontSize:18}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:o?"Edit schedule":"New schedule"})]}),e.jsx(r.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:g=>{h("name",g.target.value),d&&g.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!s.name.trim(),helperText:d&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:Ht}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Ht,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:s.frequency,label:"Frequency",onChange:g=>h("frequency",g.target.value),children:[e.jsx(r.MenuItem,{value:"daily",children:"Daily"}),e.jsx(r.MenuItem,{value:"weekly",children:"Weekly"}),e.jsx(r.MenuItem,{value:"monthly",children:"Monthly"})]})]}),s.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Ht,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:s.dayOfWeek,label:"Day of week",onChange:g=>h("dayOfWeek",Number(g.target.value)),children:Eu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),s.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:g=>h("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:s.dayOfMonth<1||s.dayOfMonth>28,helperText:s.dayOfMonth<1||s.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Ht}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:g=>h("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Ht}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Ht,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:s.format,label:"Export format",onChange:g=>h("format",g.target.value),children:[e.jsx(r.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),e.jsx(r.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),e.jsx(r.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),e.jsxs(r.RadioGroup,{row:!0,value:s.scope,onChange:g=>h("scope",g.target.value),sx:{gap:2},children:[e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"All rows"})}),e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:s.email,onChange:g=>h("email",g.target.value),onBlur:()=>m(!0),placeholder:"user@company.com",error:u&&b,helperText:u&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(k.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Ht}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(k.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>E(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>f&&n(s),disabled:!f,size:"small",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Ou({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:i=>{var s;return`0 8px 32px ${E(((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=>E(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:"Delete"})]})]})}function Au({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:s,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=>E(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=>E(l.palette.success.main,.1):l=>E(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:Tu(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=>E(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=>E(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(k.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>E(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),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: ",Iu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",zu(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=>E(l.palette.primary.main,.08)}},children:e.jsx(k.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=>E(l.palette.warning.main,.08):l=>E(l.palette.success.main,.08)}},children:d?e.jsx(k.Pause,{sx:{fontSize:15}}):e.jsx(k.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=>E(l.palette.primary.main,.08)}},children:e.jsx(k.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=>E(l.palette.error.main,.08)}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})]})]})]})}function Mu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[c,d]=p.useState([]),[l,u]=p.useState({type:"list"}),[m,h]=p.useState(0),[b,f]=p.useState(null);p.useEffect(()=>{t&&(d(qi(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const B=setInterval(()=>h($=>$+1),3e4);return()=>clearInterval(B)},[t]);const g=p.useCallback(B=>{d(B),Ji(n,B)},[n]),T=B=>{const $=lo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth),Y={id:`sched-${Date.now()}`,reportId:n,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:$,runCount:0};g([...c,Y]),u({type:"list"})},y=B=>{if(l.type!=="edit")return;const $=l.schedule,Y=lo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth);g(c.map(Q=>Q.id===$.id?{...$,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,nextRunAt:Y}:Q)),u({type:"list"})},w=B=>{g(c.map($=>{if($.id!==B)return $;const Y=$.isActive?$.nextRunAt:lo($.frequency,$.time,$.dayOfWeek,$.dayOfMonth);return{...$,isActive:!$.isActive,nextRunAt:Y}}))},v=B=>{s(B);const $=new Date().toISOString();g(c.map(Y=>Y.id===B.id?{...Y,lastRunAt:$,runCount:Y.runCount+1}:Y))},j=B=>{const $=c.find(Y=>Y.id===B)??null;f($)},S=()=>{b&&(g(c.filter(B=>B.id!==b.id)),f(null))},I=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??""}),a=l.type!=="list",A=c.filter(B=>B.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:a,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:B=>E(B.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.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(qt,{content:Jt.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=>E(B.palette.text.primary,.06)}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[a&&e.jsx(Du,{initial:l.type==="edit"?I(l.schedule):Ki,isEditing:l.type==="edit",onSave:l.type==="edit"?y:T,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":`${A} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(k.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",disableElevation:!0,onClick:()=>u({type:"create"}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),c.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(k.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.secondary"},children:"No scheduled reports yet"}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map(B=>e.jsx(Au,{schedule:B,tick:m,onToggle:w,onRunNow:v,onEdit:$=>u({type:"edit",schedule:$}),onDelete:j},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=>E(B.palette.warning.main,.06),border:"1px solid",borderColor:B=>E(B.palette.warning.main,.2)},children:[e.jsx(k.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:B=>E(B.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Ou,{scheduleName:b.name,onConfirm:S,onCancel:()=>f(null)})]})}const _u=6e4;function $u({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:h}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:h});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:h}});const f=p.useCallback(g=>{var B,$;const{reportName:T,uploadedData:y,processedData:w,schema:v,activeView:j,columnVisibility:S,columnOrder:I,filters:a,sortStack:A}=b.current;try{const Y=g.scope==="all"?y:w,Q=co(Y,v,a,A,j,S,I),te=`${g.name}_scheduled`;switch(g.format){case"csv":uo(Q,te,{scope:g.scope});break;case"excel":po(Q,te,{scope:g.scope});break;case"json":xo(Q,te,{scope:g.scope});break}if(g.email){const x=encodeURIComponent(`Scheduled Report: ${g.name}`),N=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
89
+ ]`})})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Supported Column Types"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:1.5},children:"The system automatically detects column types from your data:"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Number:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Numeric values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"33"}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"42.5"}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Boolean:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["True/false values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"true"}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:"false"}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"String:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Text values (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Europe"'}),","," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"Analytics Pro"'}),")"]})]}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,minWidth:80},children:"Date:"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["ISO date strings (e.g.,"," ",e.jsx(r.Box,{component:"code",sx:{bgcolor:"action.hover",px:.5,borderRadius:.5,fontFamily:"monospace",fontSize:"caption.fontSize"},children:'"2024-08-22"'}),")"]})]})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Notes"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2.5,"& li":{fontSize:"body2.fontSize",color:"text.secondary",mb:.5}},children:[e.jsx("li",{children:"Each object in the array represents one row in the report."}),e.jsx("li",{children:"The keys of the JSON objects become report columns."}),e.jsx("li",{children:"All objects should have consistent keys for proper column detection."}),e.jsx("li",{children:"Column names are case-sensitive and preserve spacing."})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"#ffffff",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Got it"})})]}):null}function hd({onFileUpload:t,onError:o,isUploading:n}){const[i,s]=u.useState(!1),[c,d]=u.useState(""),[l,p]=u.useState(!1),m=u.useRef(null),f=async v=>{if(!v.name.endsWith(".json")){o("Only .json files are allowed");return}const k=10*1024*1024;if(v.size>k){o("File size exceeds 10MB limit");return}d(v.name);try{const S=await v.text();let T;try{T=JSON.parse(S)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(T)){o("JSON must be an array of objects");return}if(T.length===0){o("No data rows found in JSON file");return}t(T)}catch{o("Network error — please try again")}finally{d("")}},b=v=>{v.preventDefault(),s(!0)},x=v=>{v.preventDefault(),s(!1)},g=v=>{v.preventDefault(),s(!1);const k=v.dataTransfer.files[0];k&&f(k)},I=()=>{var v;(v=m.current)==null||v.click()},y=v=>{var S;const k=(S=v.target.files)==null?void 0:S[0];k&&f(k)},j=v=>{v.stopPropagation(),p(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:x,onDrop:g,onPaste:v=>v.preventDefault(),onClick:I,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?v=>B(v.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[e.jsx(r.Box,{component:"input",ref:m,type:"file",accept:".json",onChange:y,sx:{display:"none"}}),n?e.jsxs(e.Fragment,{children:[e.jsx(r.CircularProgress,{size:32,sx:{mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:.5},children:"Uploading..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:v=>B(v.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.UploadFile,{sx:{fontSize:32,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:1.5},children:[e.jsx(r.Button,{variant:"contained",sx:{fontWeight:500},children:"Upload Data (JSON)"}),e.jsx(r.IconButton,{onClick:j,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:e.jsx(w.InfoOutlined,{sx:{fontSize:16}})})]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",maxWidth:500},children:"Upload structured JSON data to generate your report."}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1},children:"Click to browse or drag and drop a JSON file here"})]})]}),e.jsx(Yi,{isOpen:l,onClose:()=>p(!1)})]})}function gd({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=>B(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(w.Lock,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Schema will be locked for this report"})]}),e.jsx(r.Button,{variant:"contained",onClick:o,disabled:n,sx:{fontWeight:500},children:"Generate Table"})]})]})}function yd({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=>B(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=>B(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.ErrorOutline,{color:"error",sx:{fontSize:32}})}),e.jsx(r.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:600,mb:1},children:"Upload Failed"}),e.jsx(r.Typography,{variant:"body2",color:"error.main",sx:{textAlign:"center",maxWidth:500,mb:3},children:t}),e.jsx(r.Button,{variant:"contained",color:"error",startIcon:e.jsx(w.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Gi({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=>B(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(w.Description,{sx:{fontSize:36,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:500,mb:1,color:"text.primary",fontSize:"1.125rem"},children:t}),e.jsx(r.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:"0.875rem",lineHeight:1.5},children:o})]})}function bd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:c,disabled:d}){const[l,p]=u.useState(!1),[m,f]=u.useState(!1),[b,x]=u.useState(-1),g=u.useRef(null),I=u.useRef(null);u.useEffect(()=>{function R(G){g.current&&!g.current.contains(G.target)&&(p(!1),f(!1))}return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);const y=u.useCallback(()=>{f(!0),x(-1),n.length>0&&p(!0)},[n.length]),j=u.useCallback(R=>{o(R),x(-1)},[o]),v=u.useCallback(R=>{var G;o(R),i(R),p(!1),(G=I.current)==null||G.blur()},[o,i]),k=u.useCallback(R=>{x(-1),v(R)},[v]),S=u.useCallback(R=>{var G;R.key==="Enter"?b>=0&&b<n.length?(R.preventDefault(),k(n[b].query)):t.trim()&&v(t.trim()):R.key==="Escape"?(p(!1),x(-1),(G=I.current)==null||G.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(l||p(!0),x(Z=>Z<n.length-1?Z+1:Z))):R.key==="ArrowUp"&&(R.preventDefault(),x(Z=>Z>0?Z-1:-1))},[b,n,t,l,k,v]),T=u.useCallback(()=>{var R;o(""),(R=I.current)==null||R.focus()},[o]),a=u.useMemo(()=>n.filter(R=>R.isFavourite),[n]),_=u.useMemo(()=>n.filter(R=>!R.isFavourite),[n]),z=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:I,size:"small",fullWidth:!0,value:t,onChange:R=>j(R.target.value),onFocus:y,onKeyDown:S,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:R=>`rgba(${R.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.30)`,transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:R=>`rgba(${R.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.50)`},"&.Mui-focused":{bgcolor:"background.paper"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px",color:"text.primary"}},InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",sx:{ml:.5},children:e.jsx(w.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:T,edge:"end",sx:{mr:-.5},children:e.jsx(w.Close,{sx:{fontSize:16}})})}):null}}),z&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[a.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),a.map((R,G)=>e.jsx(ri,{entry:R,isSelected:b===G,onClick:()=>k(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>c(R.query)},`fav-${R.query}`))]}),_.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[a.length>0&&e.jsx(r.Divider,{}),e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),_.map((R,G)=>{const Z=a.length+G;return e.jsx(ri,{entry:R,isSelected:b===Z,onClick:()=>k(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>c(R.query)},`recent-${R.query}`)})]})]})]})}const ri=u.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:c}){const d=u.useCallback(p=>{p.stopPropagation(),s()},[s]),l=u.useCallback(p=>{p.stopPropagation(),c()},[c]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?p=>B(p.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?p=>B(p.palette.primary.main,.12):"action.hover"}},children:[e.jsx(r.Box,{sx:{flex:1,minWidth:0},onClick:i,children:e.jsx(r.Typography,{variant:"body2",noWrap:!0,children:o.query})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[e.jsx(r.IconButton,{size:"small",onClick:d,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(w.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(w.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),e.jsx(r.IconButton,{size:"small",onClick:l,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:e.jsx(w.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function vd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:p,onPermanentDelete:m,isReadOnly:f,isAdmin:b=!1}){const x=Ot(),[g,I]=u.useState(!1),[y,j]=u.useState(!1),[v,k]=u.useState({top:0,left:0}),[S,T]=u.useState(null),a=u.useRef(null),_=u.useRef(null),z=t.find(A=>A.id===o),R=z==null?void 0:z.isDefault,G=t.filter(A=>A.scope==="global"&&!A.isDeleted),Z=t.filter(A=>A.scope!=="global"&&!A.isDeleted),ee=t.filter(A=>A.isFavorite&&!A.isDeleted).sort((A,F)=>(F.updatedAt||0)-(A.updatedAt||0)),h=t.filter(A=>A.isDeleted);u.useEffect(()=>{if(g&&_.current){const A=_.current.getBoundingClientRect();k({top:A.bottom+window.scrollY+8,left:A.right+window.scrollX-320})}},[g]),u.useEffect(()=>{const A=F=>{a.current&&!a.current.contains(F.target)&&_.current&&!_.current.contains(F.target)&&I(!1)};return g&&document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[g]);const $=A=>{if(n&&A!==o){T(A),I(!1);return}i(A),I(!1)},W=()=>{S&&(i(S),T(null))},V=()=>{T(null)},K=(A,F=!1)=>{const re=A.scope==="global",q=!f&&(!re||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===A.id?x.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===A.id?x.palette.primary.light+"20":x.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>$(A.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,textTransform:"none",justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===A.id&&e.jsx(w.Check,{sx:{fontSize:16,flexShrink:0}}),o!==A.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===A.id?x.palette.primary.dark:x.palette.text.primary,fontWeight:o===A.id?500:400},children:A.name}),F&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:x.palette.text.secondary,backgroundColor:x.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[q&&l&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),l(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:A.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(w.Star,{sx:{fontSize:16}})}),q&&d&&!A.isDefault&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),d(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:"Set as default",children:e.jsx(w.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},A.id)},pe=A=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:x.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:x.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:A.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[p&&e.jsx(r.IconButton,{onClick:F=>{F.stopPropagation(),p(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:"Restore view",children:e.jsx(w.Undo,{sx:{fontSize:16,color:"success.main"}})}),m&&e.jsx(r.IconButton,{onClick:F=>{F.stopPropagation(),m(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[200]}},title:"Delete permanently",children:e.jsx(w.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},A.id),xe=n||!R,oe=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:_,onClick:()=>I(!g),size:"small",sx:{position:"relative",color:xe?"warning.main":"text.secondary",bgcolor:xe?B(x.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:xe?B(x.palette.warning.main,.2):B(x.palette.text.primary,.06),color:xe?"warning.dark":"text.primary"}},title:`View: ${(z==null?void 0:z.name)||"Default View"}`,children:[e.jsx(w.Visibility,{sx:{fontSize:20}}),oe&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),g&&mi.createPortal(e.jsxs(r.Box,{ref:a,sx:{position:"fixed",width:"320px",backgroundColor:x.palette.background.paper,border:`1px solid ${x.palette.divider}`,borderRadius:1,boxShadow:x.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:v.top,left:v.left},children:[G.length>0&&e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),G.map(A=>K(A,A.isDefault))]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(w.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),ee.map(A=>K(A))]})]}),Z.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),Z.map(A=>K(A))]})]}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>j(!y),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:x.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",h.length,")"]}),e.jsx(w.ChevronRight,{sx:{fontSize:16}})]}),y&&e.jsx(r.Box,{sx:{backgroundColor:x.palette.grey[50]},children:h.map(A=>pe(A))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${x.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{s(),I(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:x.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[50]}},children:[e.jsx(w.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),I(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:x.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:x.palette.grey[50]}},children:[e.jsx(w.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:S!==null,onClose:V,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(w.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:V,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function Sd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:p,onSortDescending:m,onRemoveSort:f,onFilter:b,onClearFilter:x,onGroupByColumn:g,onHideColumn:I,onManageColumns:y,onManageViews:j,onResetLayout:v,onClose:k}){var ee,h;const T=Ot().palette,a=u.useRef(null);u.useEffect(()=>{if(!a.current)return;const $=a.current,W=$.getBoundingClientRect(),V=window.innerWidth,K=window.innerHeight;W.right>V-8&&($.style.left=`${V-W.width-8}px`),W.bottom>K-8&&($.style.top=`${K-W.height-8}px`)},[l]),u.useEffect(()=>{const $=V=>{a.current&&!a.current.contains(V.target)&&k()},W=V=>{V.key==="Escape"&&k()};return document.addEventListener("mousedown",$),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",$),document.removeEventListener("keydown",W)}},[k]);const _=u.useCallback($=>()=>{$(),k()},[k]),z=(n==null?void 0:n.direction)==="asc",R=(n==null?void 0:n.direction)==="desc",G=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",Z=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return mi.createPortal(e.jsxs(r.Paper,{ref:a,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:1400,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",boxShadow:`0 4px 20px ${B(((ee=T.common)==null?void 0:ee.black)??"#000",.12)}, 0 1px 4px ${B(((h=T.common)==null?void 0:h.black)??"#000",.06)}`},children:[!c&&e.jsxs(r.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary"},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[e.jsx(r.Tooltip,{title:`Sort Ascending (${G})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:_(()=>p(t)),sx:{p:.625,borderRadius:"6px",color:z?"primary.main":"text.secondary",bgcolor:z?B(T.primary.main,.1):"transparent","&:hover":{bgcolor:B(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${Z})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:_(()=>m(t)),sx:{p:.625,borderRadius:"6px",color:R?"primary.main":"text.secondary",bgcolor:R?B(T.primary.main,.1):"transparent","&:hover":{bgcolor:B(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.ArrowDownward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:!s,onClick:_(()=>f(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:B(T.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(w.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:_(()=>b(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.FilterList,{sx:{fontSize:16,color:i?"primary.main":"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Filter by Column",primaryTypographyProps:{fontSize:"0.8125rem",fontWeight:i?600:400,color:i?"primary.main":"text.primary"}})]}),i&&!c&&e.jsxs(r.MenuItem,{onClick:_(()=>x(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:B(T.warning.main,.06),"& .MuiListItemText-primary":{color:"warning.main"},"& .MuiListItemIcon-root svg":{color:"warning.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&g&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.25}}),e.jsx(r.MenuList,{dense:!0,sx:{py:.5},children:e.jsxs(r.MenuItem,{onClick:_(()=>g(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.GroupWorkOutlined,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Group By Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]})})]}),e.jsx(r.Divider,{sx:{my:.25}}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[!c&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(r.MenuItem,{onClick:_(()=>I(t)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),e.jsx(r.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:_(y),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:B(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:_(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.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(w.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!c&&d&&v&&e.jsxs(r.MenuItem,{onClick:_(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:B(T.error.main,.05),"& .MuiListItemText-primary":{color:"error.main"},"& .MuiListItemIcon-root svg":{color:"error.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const jd=176,oi="COLUMN_HEADER",Cd=u.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:p,onColumnClick:m,onMoveColumn:f,onColumnDragEnd:b,onResizeStart:x,onSortAscending:g,onSortDescending:I,onRemoveSort:y,onOpenFilterForColumn:j,onClearFiltersForColumn:v,onGroupByColumn:k,onHideColumn:S,onManageColumns:T,onManageViews:a,onResetLayout:_}){const z=u.useRef(null),[R,G]=u.useState(!1),[Z,ee]=u.useState({x:0,y:0}),[{handlerId:h,isOver:$},W]=Bt.useDrop({accept:oi,collect(q){return{handlerId:q.getHandlerId(),isOver:q.isOver()}},hover(q,Q){var he;if(!z.current)return;const ae=q.index,ne=n;if(ae===ne)return;const N=(he=z.current)==null?void 0:he.getBoundingClientRect(),ie=(N.right-N.left)/2,le=Q.getClientOffset(),se=((le==null?void 0:le.x)??0)-N.left;ae<ne&&se<ie||ae>ne&&se>ie||(f(ae,ne),q.index=ne)}}),[{isDragging:V},K]=Bt.useDrag({type:oi,item:()=>({index:n,columnName:o.name}),collect:q=>({isDragging:q.isDragging()}),end:()=>{b==null||b()}});K(W(z));const pe=u.useCallback(q=>{q.preventDefault(),q.stopPropagation(),ee({x:q.clientX,y:q.clientY}),G(!0)},[]),xe=u.useCallback(()=>G(!1),[]),oe=u.useCallback(()=>{m(o.name)},[m,o.name]),A=u.useCallback(q=>{q.stopPropagation(),j(o.name)},[j,o.name]),F=u.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(w.ArrowDownward,{sx:{fontSize:13,color:"primary.main"}}),e.jsx(r.Box,{sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"0.6rem",fontWeight:700,borderRadius:"50%",lineHeight:1},children:i.priority})]}):null,[i]),re=u.useCallback(()=>s?e.jsx(w.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:z,"data-handler-id":h,"data-column-index":n,onClick:oe,onContextMenu:pe,sx:{position:"sticky",top:0,zIndex:5,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"visible",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:V?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:$?q=>B(q.palette.primary.main,.08):"action.hover",boxShadow:"0 1px 0 rgba(0,0,0,0.08)",backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:q=>B(q.palette.primary.main,.1),color:"primary.dark"},width:p?`${p}px`:`${jd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[qe(o.name),F(),re()]}),e.jsx(r.Box,{draggable:!1,onDragStart:q=>q.preventDefault(),sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),x(q,o.name)},onClick:q=>q.stopPropagation(),children:e.jsx(r.Box,{draggable:!1,sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),$&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),R&&e.jsx(Sd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:c,isReadOnly:d,hasModifications:l,position:Z,onSortAscending:g,onSortDescending:I,onRemoveSort:y,onFilter:j,onClearFilter:v,onGroupByColumn:k,onHideColumn:S,onManageColumns:T,onManageViews:a,onResetLayout:_,onClose:xe})]})});function wd({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:s,onClearSelection:c,onBulkSetFavorites:d}){const[l,p]=u.useState(null),m=u.useMemo(()=>Array.from(o),[o]),f=u.useMemo(()=>m.filter(v=>n.has(v)),[m,n]),b=u.useMemo(()=>m.filter(v=>!n.has(v)),[m,n]),x=f.length>0,g=b.length>0;if(t===0)return null;const I=()=>{d&&d(m,!0)},y=()=>{d&&d(m,!1)},j=v=>{s(v),p(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:v=>B(v.palette.primary.main,.08),borderBottom:v=>`1px solid ${B(v.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(w.Close,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:v=>B(v.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:v=>p(v.currentTarget),startIcon:e.jsx(w.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>B(v.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:v=>B(v.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:l,open:!!l,onClose:()=>p(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:180,borderRadius:1.5}},children:[e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:I,startIcon:e.jsx(w.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>B(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>B(v.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&x&&e.jsx(r.Button,{onClick:y,startIcon:e.jsx(w.Star,{sx:{fontSize:16,color:"#fbbc04"}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>B(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>B(v.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const kd={active:{bg:"#e6f4ea",color:"#137333"},completed:{bg:"#e6f4ea",color:"#137333"},approved:{bg:"#e6f4ea",color:"#137333"},success:{bg:"#e6f4ea",color:"#137333"},done:{bg:"#e6f4ea",color:"#137333"},contract:{bg:"#e8eaf6",color:"#3949ab"},"in progress":{bg:"#e8eaf6",color:"#3949ab"},"in review":{bg:"#e8eaf6",color:"#3949ab"},review:{bg:"#e8eaf6",color:"#3949ab"},pending:{bg:"#e8eaf6",color:"#3949ab"},"on leave":{bg:"#fce8e6",color:"#c5221f"},"on hold":{bg:"#fff8e1",color:"#e65100"},probation:{bg:"#fff8e1",color:"#e65100"},cancelled:{bg:"#fce8e6",color:"#c5221f"},rejected:{bg:"#fce8e6",color:"#c5221f"},blocked:{bg:"#fce8e6",color:"#c5221f"},inactive:{bg:"#f1f3f4",color:"text.secondary"},"not started":{bg:"#f1f3f4",color:"text.secondary"},paused:{bg:"#f1f3f4",color:"text.secondary"}},Td={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function Id(t){const o=t.toLowerCase().trim(),n=kd[o]||{bg:"#f1f3f4",color:"text.secondary"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function zd(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 Id(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=Td[n.toLowerCase().trim()];return s?e.jsx(r.Box,{component:"span",sx:{color:s,fontWeight:600,fontSize:"0.8125rem"},children:n}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function Ed(t){const o=t.find(s=>{const c=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(c)})||t[0]||null,n=t.find(s=>{const c=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(c)&&s!==o})||null,i=t.filter(s=>s!==o&&s!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function Bd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:s,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:p,onEdit:m,onDuplicate:f,onDelete:b}){const[x,g]=u.useState(null),[I,y]=u.useState(!1),{primaryCol:j,idCol:v,bodyColumns:k}=u.useMemo(()=>Ed(n),[n]),S=j?t[j.name]:null,T=v?t[v.name]:null,a=I||i||s||!!x;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":_=>B(_.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 ${B(_.palette.primary.main,.15)}, 0 2px 8px ${B(_.palette.common.black,.08)}`:I?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:I&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:_=>B(_.palette.primary.main,.03)}},children:[e.jsx(r.Box,{sx:{px:2,pt:2,pb:1.5},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,fontSize:"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:S!=null&&S!==""?String(S):e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})}),e.jsx(r.Box,{sx:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}),e.jsxs(r.Box,{sx:{px:2,py:1.5,flex:1,display:"flex",flexDirection:"column",gap:1},children:[k.map(_=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minHeight:22},children:[e.jsx(r.Typography,{sx:{color:"text.secondary",fontWeight:500,fontSize:"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",minWidth:68,flexShrink:0,lineHeight:1},children:qe(_.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:zd(_,t[_.name])})]},_.name)),k.length===0&&e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic"},children:"No additional fields visible"})]}),e.jsxs(r.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:_=>B(_.palette.action.hover,.1),minHeight:40},children:[e.jsx(r.Typography,{sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.75rem",fontWeight:400,letterSpacing:"0.04em",opacity:T?.85:0,userSelect:"none"},children:T?String(T):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:a?1:0,transition:"opacity 0.15s ease"},onClick:_=>_.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:_=>{_.stopPropagation(),l(t)},sx:{width:28,height:28,color:s?"#fbbc04":"action.disabled","&:hover":{bgcolor:_=>B(_.palette.warning.main,.1),color:"#fbbc04"}},children:s?e.jsx(w.Star,{sx:{fontSize:17}}):e.jsx(w.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:_=>{_.stopPropagation(),g(_.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:_=>B(_.palette.text.primary,.08)}},children:e.jsx(w.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!x,anchorEl:x,onClose:()=>g(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:"0 4px 20px rgba(60,64,67,0.15), 0 1px 6px rgba(60,64,67,0.1)"}},onClick:_=>_.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{p(t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{m(t,o),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{b(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(w.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Dd({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:s=>B(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:ji(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=>B(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,c])=>Si(c)).filter(Boolean).join(" • ")})]})}function Od({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:s,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:p,onToggleRowSelection:m,onToggleRowFavorite:f,onToggleGroupCollapse:b,onViewRow:x,onEditRow:g,onDuplicateRow:I,onDeleteRow:y}){const j=u.useMemo(()=>{const v=new Set;return i.forEach(k=>{const S=k==null?void 0:k.__urm_row_id__;S!==void 0&&v.add(S)}),v},[i]);return t.length===0?e.jsx(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):e.jsxs(r.Box,{children:[p&&o.length>0&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,px:2,py:1,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper",flexWrap:"wrap"},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontWeight:500,mr:.5,whiteSpace:"nowrap"},children:"Sort by:"}),o.map(v=>{const k=l.find(S=>S.column===v.name);return e.jsxs(r.Box,{onClick:()=>p(v.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:k?"primary.main":"divider",bgcolor:k?S=>B(S.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:S=>B(S.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:k?600:400,color:k?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:qe(v.name)}),k?k.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(w.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(w.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},v.name)})]}),e.jsx(r.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(272px, 1fr))",gap:1.5,alignContent:"start"},children:t.map((v,k)=>d&&v.isGroupHeader?e.jsx(Dd,{row:v,grouping:n,onToggleCollapse:b||(()=>{})},`group-${v.groupKey}`):e.jsx(Bd,{row:v,rowIndex:k,visibleColumns:o,isSelected:j.has(v==null?void 0:v.__urm_row_id__),isFavorite:s.has(v),isReadOnly:c,onToggleSelection:()=>m(v),onToggleFavorite:f,onView:x,onEdit:g,onDuplicate:I,onDelete:y},`card-${k}`))})]})}const ni=[10,15,25,50,100];function Ad(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 _d({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:c}){var $;const l=Ot().palette,p=Math.ceil(n/o),[m,f]=u.useState(String(t)),[b,x]=u.useState(null),[g,I]=u.useState(!1),y=u.useRef(null);u.useEffect(()=>{g||(f(String(t)),x(null))},[t,g]);const j=u.useCallback(()=>{const W=Ad(m,p);if(W){x(W);return}const V=parseInt(m.trim(),10);x(null),I(!1),V!==t&&s(V)},[m,p,t,s]),v=u.useCallback(W=>{var V;W.key==="Enter"?(W.preventDefault(),j()):W.key==="Escape"&&(f(String(t)),x(null),I(!1),(V=y.current)==null||V.blur())},[j,t]),k=u.useCallback(()=>{f(String(t)),x(null),I(!1)},[t]),S=u.useCallback(()=>{I(!0),x(null),setTimeout(()=>{var W;return(W=y.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ni))return null;const T=()=>{f(String(t)),x(null),I(!1)},a=()=>{T(),s(1)},_=()=>{T(),t>1&&s(t-1)},z=()=>{T(),t<p&&s(t+1)},R=()=>{T(),s(p)},G=(t-1)*o+1,Z=Math.min(t*o,n),ee=`${Math.max(2,String(p).length+.5)}ch`,h={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:3,px:2,py:1,borderTop:"1px solid",borderColor:"divider",bgcolor:"background.paper",minHeight:48},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),e.jsx(r.Select,{value:o,onChange:W=>c(Number(W.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:ni.map(W=>e.jsx(r.MenuItem,{value:W,sx:{fontSize:"0.8125rem"},children:W},W))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[G,"–",Z," of ",n]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),e.jsxs(r.Box,{sx:{position:"relative"},children:[b&&e.jsx(r.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:B(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${B((($=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:B(l.error.main,.4)}},children:e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:b})}),e.jsx(r.InputBase,{inputRef:y,value:m,onChange:W=>{f(W.target.value),b&&x(null)},onKeyDown:v,onFocus:S,onBlur:k,inputProps:{"aria-label":`Page number, 1 to ${p}`,style:{textAlign:"center",padding:"2px 0",width:ee,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":g?"primary.main":"divider",borderRadius:"4px",bgcolor:b?B(l.error.main,.04):g?B(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 ${B(l.error.main,.2)}`:`0 0 0 2px ${B(l.primary.main,.2)}`}}})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",p]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{onClick:a,disabled:t===1,size:"small",title:"First page",sx:h,children:e.jsx(w.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:_,disabled:t===1,size:"small",title:"Previous page",sx:h,children:e.jsx(w.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:z,disabled:t===p,size:"small",title:"Next page",sx:h,children:e.jsx(w.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:R,disabled:t===p,size:"small",title:"Last page",sx:h,children:e.jsx(w.LastPage,{sx:{fontSize:20}})})]})]})]})}function Md(){return e.jsx(r.Chip,{icon:e.jsx(w.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const qi="urm_hint_seen_";function $d(t){try{return localStorage.getItem(qi+t)==="true"}catch{return!1}}function Rd(t){try{localStorage.setItem(qi+t,"true")}catch{}}function ii(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 si(t){const o={fontSize:11};switch(t){case"number":return e.jsx(w.Numbers,{sx:o});case"boolean":return e.jsx(w.CheckBox,{sx:o});case"array":return e.jsx(w.DataArray,{sx:o});case"object":return e.jsx(w.DataObject,{sx:o});default:return e.jsx(w.TextFields,{sx:o})}}function ai(t,o){var n,i;switch(t){case"number":return{bg:B(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:B(((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:B(o.secondary.main,.08),color:o.secondary.main};default:return{bg:B(o.text.secondary,.07),color:o.text.secondary}}}function Wd({open:t,onClose:o,row:n,schema:i,reportName:s}){var b,x;const d=Ot().palette;if(!n)return null;const l=i.filter(g=>g.name in n),p=l.filter(g=>g.type!=="object"&&g.type!=="array"),m=l.filter(g=>g.type==="object"||g.type==="array"),f=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${B(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${B(((x=d.common)==null?void 0:x.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:B(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"View Record"}),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," · ",f," ",f===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:B(d.text.primary,.015)},children:[p.length>0&&e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"1px",bgcolor:"divider",m:2,mb:m.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:p.map((g,I)=>{const y=n[g.name],j=ii(y,g.type),v=!j,k=ai(g.type,d),S=I===p.length-1&&p.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:S?"span 2":"span 1",display:"flex",flexDirection:"column",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:k.bg,color:k.color,flexShrink:0},children:si(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:qe(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:v?400:500,color:v?"text.disabled":"text.primary",fontStyle:v?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:v?"No value":j})]},g.name)})}),m.map(g=>{const I=n[g.name],y=ii(I,g.type),j=!y,v=ai(g.type,d);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:v.bg,color:v.color},children:si(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:qe(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:v.bg,color:v.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:B(d.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:j?"text.disabled":"text.primary",fontStyle:j?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:j?"No value":y})]},g.name)}),l.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(w.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:3,py:.75,borderRadius:"8px",minWidth:80},children:"Close"})})]})}function Pd({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:"#fce8e6",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:[i?`"${i}"`:"This record"," will be permanently removed."]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:"#fce8e6",border:"1px solid #f28b82"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"error.main",fontWeight:500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(w.DeleteForever,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Xo(t){const o={fontSize:11};switch(t){case"number":return e.jsx(w.Numbers,{sx:o});case"boolean":return e.jsx(w.CheckBox,{sx:o});case"array":return e.jsx(w.DataArray,{sx:o});case"object":return e.jsx(w.DataObject,{sx:o});default:return e.jsx(w.TextFields,{sx:o})}}function li(t,o){var n,i;switch(t){case"number":return{bg:B(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:B(((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:B(o.secondary.main,.08),color:o.secondary.main};default:return{bg:B(o.text.secondary,.07),color:o.text.secondary}}}function Nd({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:c}){var j,v,k;const l=Ot().palette,[p,m]=u.useState({});if(u.useEffect(()=>{t&&i&&m({...i})},[t,i]),!i)return null;const f=s.filter(S=>S.name in i),b=f.filter(S=>S.type!=="object"&&S.type!=="array"),x=f.filter(S=>S.type==="object"||S.type==="array"),g=(S,T)=>{m(a=>({...a,[S]:T}))},I=()=>{const S={...p};f.forEach(T=>{const a=p[T.name];if(T.type==="number"){const _=Number(a);S[T.name]=isNaN(_)?i[T.name]:_}else T.type==="boolean"&&(S[T.name]=!!a)}),n(S),o()},y=f.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${B(((j=l.common)==null?void 0:j.black)??"#000",.14)}, 0 2px 8px ${B(((v=l.common)==null?void 0:v.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:B(((k=l.warning)==null?void 0:k.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),c&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c," · ",y," ",y===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:B(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[b.length>0&&e.jsxs(r.Box,{children:[b.length>1&&e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em",mb:1.25},children:"Fields"}),e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1.5},children:b.map((S,T)=>{const a=p[S.name],_=li(S.type,l),z=S.type==="boolean",R=!z&&T===b.filter(Z=>Z.type!=="boolean").length-1&&b.filter(Z=>Z.type!=="boolean").length%2!==0,G=z||R;return S.type==="boolean"?e.jsxs(r.Box,{sx:{gridColumn:"span 2",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",px:2,py:1.5,display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,transition:"border-color 0.15s","&:hover":{borderColor:"primary.main"}},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.25},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:_.bg,color:_.color},children:Xo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:qe(S.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:a?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!a,onChange:Z=>g(S.name,Z.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},S.name):e.jsxs(r.Box,{sx:{gridColumn:G?"span 2":"span 1",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",transition:"border-color 0.15s","&:focus-within":{borderColor:"primary.main",boxShadow:`0 0 0 2px ${B(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:B(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:Xo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:qe(S.name)})]}),e.jsx(r.TextField,{value:a??"",onChange:Z=>g(S.name,Z.target.value),type:S.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${S.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:S.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},S.name)})})]}),x.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em"},children:"Read-only Fields"}),e.jsx(r.Tooltip,{title:"Object and array fields cannot be edited directly",arrow:!0,children:e.jsx(w.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:x.map(S=>{const T=i[S.name];let a="";try{a=T==null?"":JSON.stringify(T,null,2)}catch{a=String(T)}const _=li(S.type,l);return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",opacity:.8},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:B(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:Xo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:qe(S.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:B(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:a?"text.primary":"text.disabled",fontStyle:a?"normal":"italic",bgcolor:B(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:a||"No value"})]},S.name)})})]}),f.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(w.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:I,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const jr=176,Ld={active:{bg:"success.lighter",color:"success.dark"},completed:{bg:"success.lighter",color:"success.dark"},approved:{bg:"success.lighter",color:"success.dark"},success:{bg:"success.lighter",color:"success.dark"},done:{bg:"success.lighter",color:"success.dark"},contract:{bg:"primary.lighter",color:"primary.main"},"in progress":{bg:"primary.lighter",color:"primary.main"},"in review":{bg:"primary.lighter",color:"primary.main"},review:{bg:"primary.lighter",color:"primary.main"},pending:{bg:"primary.lighter",color:"primary.main"},"on leave":{bg:"error.lighter",color:"error.dark"},"on hold":{bg:"warning.lighter",color:"warning.dark"},probation:{bg:"warning.lighter",color:"warning.dark"},cancelled:{bg:"error.lighter",color:"error.dark"},rejected:{bg:"error.lighter",color:"error.dark"},blocked:{bg:"error.lighter",color:"error.dark"},inactive:{bg:"action.selected",color:"text.secondary"},"not started":{bg:"action.selected",color:"text.secondary"},paused:{bg:"action.selected",color:"text.secondary"},good:{bg:"success.lighter",color:"success.dark"},excellent:{bg:"success.lighter",color:"success.dark"},average:{bg:"warning.lighter",color:"warning.dark"},moderate:{bg:"warning.lighter",color:"warning.dark"},poor:{bg:"error.lighter",color:"error.dark"},bad:{bg:"error.lighter",color:"error.dark"},critical:{bg:"error.lighter",color:"error.dark"},open:{bg:"primary.lighter",color:"primary.main"},closed:{bg:"action.selected",color:"text.secondary"},verified:{bg:"success.lighter",color:"success.dark"},unverified:{bg:"warning.lighter",color:"warning.dark"}},Fd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Vd(t){const o=t.toLowerCase().trim(),n=Ld[o]||{bg:"grey.100",color:"grey.600"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Hd(t){const o=t.toLowerCase().trim(),n=Fd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Ud(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 Yd(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),s=o.findIndex(m=>m.name===t.name),c=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),d=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),l=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),p=s===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||p&&!l}function Gd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function qd(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const s=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 Vd(s);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Hd(s);const p=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(s);if(p)return Ud(s);if(n&&!d&&!l&&!p)return Gd(s);if(t.type==="date"){const m=t.dateFormat??"iso",f=Js(o,m,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:f})}if(t.type==="number"&&typeof o=="number")return o.toLocaleString();if(typeof o=="boolean")return o?"Yes":"No";if(Array.isArray(o)){if(o.length===0)return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"[ ]"});const m=o.slice(0,3).map(f=>typeof f=="object"?JSON.stringify(f):String(f)).join(", ");return e.jsxs(r.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[m,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const m=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:m,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:m.length>40?m.slice(0,40)+"…":m})}return s}function Jd({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:p={},columnOrder:m=[],columnWidths:f={},grouping:b=null,onSort:x,onSortAscending:g,onSortDescending:I,onOpenFilters:y,onOpenSort:j,onOpenFilterForColumn:v,onSelectView:k,onCreateView:S,onManageViews:T,onUpdateCurrentView:a,onSaveAsNewView:_,onToggleDefault:z,onToggleFavorite:R,onRestoreView:G,onPermanentDelete:Z,isAdmin:ee=!1,onExport:h,onOpenColumns:$,onUpdateColumnWidth:W,onUpdateColumnOrder:V,onUpdateColumnVisibility:K,onClearFiltersForColumn:pe,onResetLayout:xe,onOpenGroup:oe,onGroupByColumn:A,onToggleGroupCollapse:F,onOpenAuditHistory:re,onOpenScheduledReports:q,searchQuery:Q,searchHistory:ae=[],onAddToSearchHistory:ne,onToggleSearchFavourite:N,onDeleteSearchHistory:ie,selectedRowIds:le=new Set,onSearchChange:se,onToggleRowSelection:he,onToggleAllRows:J,onRangeSelection:_e,onClearSelection:Ve,onExportSelected:rt,currentPage:nr=1,pageSize:wr=15,totalRowsBeforePagination:Nt=o.length,onPageChange:ct,onPageSizeChange:Ne,isReadOnly:ze=!1,userRole:At,reportName:bt,onEditRow:Ke,onDuplicateRow:Fe,onDeleteRow:Xe,favoriteRowIndices:ir=[],resolvedFavoritesSet:Ze=new Set,showFavoritesOnly:ot=!1,onToggleRowFavorite:Re,onBulkSetFavorites:sr,showDevPanel:kr=!1,onOpenDevConfig:Lt,onToggleFavoritesFilter:dt}){var $e;const[vt,ar]=u.useState(null),[St,oo]=u.useState(0),[lr,Tr]=u.useState(0),[jt,nt]=u.useState(null),Ft=(($e=tr().dates)==null?void 0:$e.displayFormat)??null,[Se,zr]=u.useState(null),[cr,it]=u.useState(null),[L,He]=u.useState(null),[je,Le]=u.useState(!1),[Er,Vt]=u.useState(!1),[Ct,_t]=u.useState(null),[Ht,Ut]=u.useState(""),[Br,Yt]=u.useState(!1),[Me,X]=u.useState(null),[wt,Ce]=u.useState(null),[we,st]=u.useState(null),[dr,ut]=u.useState(null),[Ue,ur]=u.useState("list"),[pr,xr]=u.useState(!1),[kt,Dr]=u.useState(()=>!$d("toolbar_search"));u.useRef(null);const Mt=u.useRef(null),Gt=u.useRef(null),Qe=u.useCallback(()=>{Rd("toolbar_search"),Dr(!1)},[]);u.useEffect(()=>{if(!kt)return;const D=setTimeout(Qe,2e3);return()=>clearTimeout(D)},[kt,Qe]);const at=u.useMemo(()=>{const D=jt??m;return D.length>0?D.map(U=>t.find(ue=>ue.name===U)).filter(U=>U!==void 0):t},[jt,m,t]),We=u.useMemo(()=>at.filter(D=>p[D.name]!==!1),[at,p]),pt=u.useMemo(()=>t.filter(D=>p[D.name]===!1).length,[t,p]),mr=u.useMemo(()=>t.map(D=>D.name),[t]),xt=u.useMemo(()=>m.length===0?!1:JSON.stringify(m)!==JSON.stringify(mr),[m,mr]),Or=u.useCallback((D,U)=>{D.preventDefault(),D.stopPropagation(),ar(U),oo(D.clientX),Tr(f[U]||150)},[f]);u.useEffect(()=>{if(!vt)return;const D=ue=>{const Pe=ue.clientX-St,ce=Math.max(100,Math.min(600,lr+Pe));W==null||W(vt,ce)},U=()=>{ar(null)};return document.addEventListener("mousemove",D),document.addEventListener("mouseup",U),()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",U)}},[vt,St,lr,W]);const Ar=u.useCallback(D=>D==null?"-":typeof D=="object"?JSON.stringify(D):typeof D=="boolean"?D?"true":"false":String(D),[]);u.useCallback(D=>{const U=n.find(ue=>ue.column===D);return U?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[U.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:14}}):e.jsx(w.ArrowDownward,{sx:{fontSize:14}}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"caption.fontSize",fontWeight:"bold",borderRadius:"50%"},children:U.priority})]}):null},[n]),u.useCallback(D=>i.some(ue=>ue.column===D)?e.jsx(r.IconButton,{size:"small",onClick:ue=>{ue.stopPropagation(),v==null||v(D)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(w.FilterList,{sx:{fontSize:14}})}):null,[i,v]);const _r=u.useCallback(D=>{x&&x(D)},[x]),Mr=u.useCallback((D,U)=>{nt(ue=>{const ce=[...ue??(m.length>0?m:t.map(No=>No.name))],[It]=ce.splice(D,1);return ce.splice(U,0,It),ce})},[m,t]),fr=u.useCallback(()=>{jt&&V&&V(jt),nt(null)},[jt,V]),$r=u.useCallback(D=>{if(!x)return;const U=n.find(ue=>ue.column===D);(!U||U.direction!=="asc")&&x(D)},[x,n]),Rr=u.useCallback(D=>{if(!x)return;const U=n.find(ue=>ue.column===D);U?U.direction==="asc"&&x(D):(x(D),setTimeout(()=>x(D),0))},[x,n]),Wr=u.useCallback(D=>{if(!x)return;const U=n.find(ue=>ue.column===D);U&&(U.direction==="asc"?(x(D),setTimeout(()=>x(D),0)):U.direction==="desc"&&x(D))},[x,n]),$t=u.useCallback(D=>{K&&K(D,!1)},[K]),hr=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Pr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(p).some(D=>D===!1),qt=(nr-1)*wr,Oe=o,lt=u.useMemo(()=>{const D=new Set;return le.forEach(U=>{const ue=U==null?void 0:U.__urm_row_id__;ue!==void 0&&D.add(ue)}),D},[le]);u.useEffect(()=>{const D=U=>{!J||!Ve||U.target instanceof HTMLInputElement||U.target instanceof HTMLTextAreaElement||((U.ctrlKey||U.metaKey)&&U.key==="a"&&(U.preventDefault(),J(!0,Oe)),U.key==="Escape"&&(U.preventDefault(),Ve()))};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[J,Ve,Oe]);const Jt=u.useCallback((D,U)=>{he&&(U.shiftKey&&Se!==null?(U.preventDefault(),_e&&_e(Se,D,Oe)):(he(Oe[D]),zr(D)))},[he,Se,_e,Oe]);!u.useMemo(()=>Oe.length>0&&lt.size>0&&Oe.every(D=>lt.has(D==null?void 0:D.__urm_row_id__)),[Oe,lt])&&Oe.some(D=>lt.has(D==null?void 0:D.__urm_row_id__));const Tt=he&&J,de=u.useCallback(D=>{var Pe;const U=D.groupLevel,ue=U*24;return e.jsx(r.TableRow,{onClick:()=>F==null?void 0:F(D.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:We.length+(Tt?1:0),sx:{pl:`${ue+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[D.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:ji(U,((Pe=b==null?void 0:b.levels[U])==null?void 0:Pe.column)||"",D.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:ce=>B(ce.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[D.rowCount," ",D.rowCount===1?"row":"rows"]}),Object.keys(D.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(D.aggregates).map(([ce,It])=>Si(It)).filter(Boolean).join(" • ")})]})})},D.groupKey)},[We,Tt,b,F]),me=u.useCallback((D,U)=>{const ue=lt.has(D==null?void 0:D.__urm_row_id__),Pe=cr===U;return e.jsxs(r.TableRow,{"data-row-index":U,onMouseEnter:()=>it(U),onMouseLeave:()=>it(null),onClick:ce=>{!he||ce.target.closest("[data-row-action-btn]")||Jt(U,ce)},onContextMenu:ce=>{ce.preventDefault(),ce.stopPropagation(),st({mouseX:ce.clientX,mouseY:ce.clientY,row:D,rowIndex:U})},sx:{height:34,cursor:"pointer",bgcolor:ue?ce=>B(ce.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:ue?ce=>B(ce.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[We.map((ce,It)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...It===We.length-1&&{pr:`${Re?76:40}px`},fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:f[ce.name]?`${f[ce.name]}px`:`${ce.type==="date"?Math.max(jr,180):jr}px`},children:qd(ce,D[ce.name],Yd(ce,We),Ft)},ce.name)),e.jsx(r.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:Re?76:40,minWidth:Re?76:40,maxWidth:Re?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:Pe||Ze.has(D)?ce=>`linear-gradient(to right, transparent, ${ue?`rgba(${ce.palette.mode==="dark","237,108,2"},0.12)`:ce.palette.background.paper} 32px)`:"transparent",opacity:Pe||Ze.has(D)?1:0,transition:"opacity 0.12s ease, background 0.12s ease",zIndex:10,verticalAlign:"middle"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:[Re&&e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ce=>{ce.stopPropagation(),ce.preventDefault(),Re(D)},title:Ze.has(D)?"Remove from favorites":"Add to favorites",sx:{color:Ze.has(D)?"warning.main":"text.secondary","&:hover":{bgcolor:ce=>B(ce.palette.warning.main,.08),color:"warning.main"}},children:Ze.has(D)?e.jsx(w.Star,{sx:{fontSize:18}}):e.jsx(w.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ce=>{ce.stopPropagation(),ce.preventDefault(),st({anchorEl:ce.currentTarget,row:D,rowIndex:U})},sx:{color:"text.secondary",opacity:Pe?1:0,transition:"opacity 0.12s ease",pointerEvents:Pe?"auto":"none","&:hover":{bgcolor:ce=>B(ce.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(w.MoreVert,{sx:{fontSize:18}})})]})})]},U)},[le,qt,cr,Jt,We,f,Ar,Ke,Fe,Xe,he,Re,Ze,He,Le,st]);return e.jsxs(Bt.DndProvider,{backend:rn.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[Tt&&rt&&Ve&&e.jsx(wd,{selectedCount:lt.size,selectedRowIds:le,resolvedFavoritesSet:Ze,viewMode:Ue,onExportSelected:rt,onClearSelection:Ve,onBulkSetFavorites:sr}),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(Md,{}),se&&ne&&N&&ie&&e.jsx(r.Tooltip,{open:kt,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:Qe},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(bd,{value:Q||"",onChange:D=>{kt&&Qe(),se(D)},searchHistory:ae,onAddToHistory:ne,onToggleFavourite:N,onDeleteHistory:ie,disabled:ze})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>xr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:D=>B(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})})}),dt&&e.jsx(r.Tooltip,{title:ot?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:dt,size:"small",disabled:ze,sx:{position:"relative",color:ot?"warning.main":"text.secondary",bgcolor:ot?D=>B(D.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ot?D=>B(D.palette.warning.main,.2):D=>B(D.palette.text.primary,.06),color:ot?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[ot?e.jsx(w.Star,{sx:{fontSize:20}}):e.jsx(w.StarBorder,{sx:{fontSize:20}}),ot&&ir.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:ir.length})]})}),kr&&Lt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:Lt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:D=>B(D.palette.text.secondary,.3),"&:hover":{bgcolor:D=>B(D.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(w.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),k&&S&&T&&a&&s.length>0&&e.jsx(vd,{views:s||[],activeViewId:c||"",isDirty:d,onSelectView:k,onCreateView:S,onManageViews:T,onToggleDefault:z,onToggleFavorite:R,onRestoreView:G,onPermanentDelete:Z,isAdmin:ee,isReadOnly:ze}),!ze&&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?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?D=>B(D.palette.primary.main,.2):D=>B(D.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!ze&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?D=>B(D.palette.primary.main,.2):D=>B(D.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!ze&&$&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:$,size:"small",sx:{position:"relative",color:pt>0||xt?"primary.main":"text.secondary",bgcolor:pt>0||xt?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:pt>0||xt?D=>B(D.palette.primary.main,.2):D=>B(D.palette.text.primary,.06),color:pt>0||xt?"primary.main":"text.primary"}},children:[e.jsx(w.ViewColumn,{sx:{fontSize:20}}),pt>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:pt})]})}),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:()=>ur("list"),sx:{borderRadius:1,color:Ue==="list"?"primary.main":"text.secondary",bgcolor:Ue==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ue==="list"?D=>B(D.palette.primary.main,.2):D=>B(D.palette.text.primary,.06),color:Ue==="list"?"primary.main":"text.primary"}},children:e.jsx(w.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>ur("grid"),sx:{borderRadius:1,color:Ue==="grid"?"primary.main":"text.secondary",bgcolor:Ue==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ue==="grid"?D=>B(D.palette.primary.main,.2):D=>B(D.palette.text.primary,.06),color:Ue==="grid"?"primary.main":"text.primary"}},children:e.jsx(w.GridView,{sx:{fontSize:20}})})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"Settings",children:e.jsx(r.IconButton,{onClick:D=>ut(D.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:D=>B(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!dr,anchorEl:dr,onClose:()=>ut(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:200,py:.5,borderRadius:1.5,boxShadow:3}},children:[h&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(),ut(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!ze&&oe&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{oe(),ut(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),re&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{re(),ut(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),q&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{q(),ut(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Scheduled Reports"})]})]}),e.jsxs(r.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[Ue==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Od,{data:Oe,visibleColumns:We,grouping:b,selectedRowIds:le,resolvedFavoritesSet:Ze,isReadOnly:ze,isGrouped:!!hr,sortStack:n,onSort:x,onToggleRowSelection:he||(()=>{}),onToggleRowFavorite:Re,onToggleGroupCollapse:F,onViewRow:D=>{He(D),Le(!0)},onEditRow:(D,U)=>{X(D),Ce(U),Yt(!0)},onDuplicateRow:(D,U)=>Fe==null?void 0:Fe(D,U),onDeleteRow:(D,U)=>{_t(U);const ue=Object.values(U).find(Pe=>Pe!=null&&Pe!=="");Ut(ue?String(ue):""),Vt(!0)}})}),Ue==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Mt,onScroll:D=>{Gt.current&&(Gt.current.scrollLeft=D.target.scrollLeft)},sx:{overflowX:"auto",overflowY:"hidden",flexShrink:0,scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${We.reduce((D,U)=>D+(f[U.name]||(U.type==="date"?180:jr)),Re?76:40)}px`},children:[e.jsxs("colgroup",{children:[We.map(D=>e.jsx("col",{style:{width:`${f[D.name]||(D.type==="date"?180:jr)}px`}},D.name)),e.jsx("col",{style:{width:`${Re?76:40}px`}})]}),e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[We.map((D,U)=>e.jsx(Cd,{column:D,index:U,sortRule:n.find(ue=>ue.column===D.name),hasFilters:i.some(ue=>ue.column===D.name),isInSortStack:n.some(ue=>ue.column===D.name),isReadOnly:ze,hasModifications:Pr,width:f[D.name],onColumnClick:_r,onMoveColumn:Mr,onColumnDragEnd:fr,onResizeStart:Or,onSortAscending:g||$r,onSortDescending:I||Rr,onRemoveSort:Wr,onOpenFilterForColumn:v||(()=>{}),onClearFiltersForColumn:pe||(()=>{}),onGroupByColumn:A,onHideColumn:$t,onManageColumns:$||(()=>{}),onManageViews:T,onResetLayout:xe},D.name)),e.jsx(r.TableCell,{sx:{width:Re?76:40,minWidth:Re?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),e.jsx(r.Box,{ref:Gt,onScroll:D=>{Mt.current&&(Mt.current.scrollLeft=D.target.scrollLeft)},sx:{flex:1,overflowY:"auto",overflowX:"auto",minHeight:0,bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",borderSpacing:0,width:"100%",minWidth:`${We.reduce((D,U)=>D+(f[U.name]||(U.type==="date"?180:jr)),Re?76:40)}px`},children:[e.jsxs("colgroup",{children:[We.map(D=>e.jsx("col",{style:{width:`${f[D.name]||(D.type==="date"?180:jr)}px`}},D.name)),e.jsx("col",{style:{width:`${Re?76:40}px`}})]}),e.jsx(r.TableBody,{children:Oe.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:We.length+(Tt?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):hr?Oe.map((D,U)=>D.isGroupHeader?de(D):me(D,U)):Oe.map((D,U)=>me(D,U))})]})})]}),ct&&Ne&&e.jsx(_d,{currentPage:nr,pageSize:wr,totalRows:Nt,totalFields:t.length,onPageChange:ct,onPageSizeChange:Ne}),!(ct&&Ne)&&e.jsx(r.Box,{sx:{px:3,py:1.5,bgcolor:"action.hover",borderTop:1,borderColor:"divider"},children:e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Showing ",Oe.length," ",Oe.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!we,onClose:()=>st(null),anchorEl:(we==null?void 0:we.anchorEl)||null,anchorReference:we!=null&&we.anchorEl?"anchorEl":"anchorPosition",anchorPosition:we&&!we.anchorEl?{top:we.mouseY,left:we.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:we!=null&&we.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:()=>{we&&(He(we.row),Le(!0)),st(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{we&&(X(we.row),Ce(we.rowIndex),Yt(!0)),st(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{we&&(Fe==null||Fe(we.rowIndex,we.row)),st(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{if(we){_t(we.row);const D=Object.values(we.row).find(U=>U!=null&&U!=="");Ut(D?String(D):""),Vt(!0)}st(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(w.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Wd,{open:je,onClose:()=>{Le(!1),He(null)},row:L,schema:t,reportName:bt}),e.jsx(Nd,{open:Br,onClose:()=>{Yt(!1),X(null),Ce(null)},onSave:D=>{wt!==null&&(Ke==null||Ke(wt,D))},row:Me,schema:t,reportName:bt}),e.jsx(Pd,{open:Er,onClose:()=>{Vt(!1),_t(null)},onConfirm:()=>{Ct!==null&&(Xe==null||Xe(Ct))},rowPreview:Ht}),e.jsx(Yi,{isOpen:pr,onClose:()=>xr(!1)})]})}function rr({content:t,isDev:o=!1}){const[n,i]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:s=>i(s.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:s=>B(s.palette.primary.main,.08)}},children:e.jsx(w.InfoOutlined,{sx:{fontSize:15}})}),e.jsxs(r.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:{width:280,borderRadius:"10px",boxShadow:4,p:0,overflow:"hidden"}},children:[e.jsx(r.Box,{sx:{px:2,py:1.5,bgcolor:s=>B(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,c)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},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:s=>B(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>B(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 or={filter:{title:"Filter columns",description:"Narrow down rows by setting conditions on any column. Only rows matching all active filters are shown.",tips:["Add multiple conditions to combine filters (AND logic)",'Use "Contains" for partial text matches','Use "Is empty" to find missing values',"Clear all filters to return to the full dataset"],devNote:"Max filter conditions controlled by DevConfig → Filter → maxConditions. Allowed operators also configurable."},sort:{title:"Sort columns",description:"Order rows by one or more columns. Drag levels to set sort priority — the first level is applied first.",tips:["Add multiple sort levels for multi-column sorting","Drag the ⋮⋮ handle to reorder sort priority","Each level can be ascending (A→Z, 0→9) or descending"],devNote:"Max sort levels controlled by DevConfig → Sort → maxLevels."},grouping:{title:"Group data",description:"Organize rows into collapsible groups by one or more column values. Each unique value becomes a group header.",tips:["Add up to 3 nesting levels for hierarchical grouping","Click a group header to collapse or expand it","Aggregates (count) are shown on each group header","Combine grouping with filters and sort for focused views"],devNote:"Max group levels controlled by DevConfig → Grouping → maxLevels. allowNested and allowCollapse also configurable."},columns:{title:"Manage columns",description:"Control which columns are visible, their display order, and their widths.",tips:["Drag rows to reorder columns","Toggle the eye icon to show or hide a column","Drag the resize handle in the table header to resize","Reset to restore default visibility and order"],devNote:"Max visible columns and width range controlled by DevConfig → Columns."},export:{title:"Export data",description:"Download the report data as a file. Choose between CSV, Excel, or JSON format.",tips:["CSV: universal format, opens in any spreadsheet app","Excel: formatted .xlsx file with native Excel support","JSON: structured data including metadata","Export visible rows only (after filters) or all rows"],devNote:"Allowed export formats controlled by DevConfig → Export → allowedFormats."},schedule:{title:"Scheduled reports",description:"Set up automatic exports that run at a specified time — daily, weekly, or monthly.",tips:["The browser tab must remain open for the schedule to fire","Each schedule triggers a file download automatically","Add an email address to open a notification in your mail app","Pause a schedule without deleting it"],devNote:"Schedules are stored in localStorage per-report. Key: urm_schedules_{reportId}."},auditHistory:{title:"Audit history",description:"A full log of all changes made to this report — filters applied, sorts changed, views saved, exports triggered, and more.",tips:["Each entry shows the action, timestamp, and who performed it","Use audit history to trace back unexpected changes"],devNote:"Audit entries are stored per-report in IndexedDB via the persistence layer."}};function Kd({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:c,onReplaceFilters:d,onClose:l,focusColumn:p}){const[m,f]=u.useState(""),[b,x]=u.useState(""),[g,I]=u.useState(""),[y,j]=u.useState([]),v=tr();u.useEffect(()=>{j([...o])},[o]),u.useEffect(()=>{p&&f(p)},[p]);const k=u.useCallback(()=>{f(""),x(""),I("")},[]),S=u.useMemo(()=>t.filter($=>$.type!=="mixed"&&$.type!=="null"&&$.type!=="array"&&$.type!=="object"),[t]),T=t.find($=>$.name===m),a=u.useMemo(()=>{const $=T?zn(T.type):[],W=v.filter.allowedOperators;return W.length>0?$.filter(V=>W.includes(V.value)):$},[T]),_=u.useCallback(()=>!(!m||!b||ao(b)&&!g.trim()||y.length>=v.filter.maxConditions),[m,b,g,y,v]),z=u.useCallback(()=>{if(!_())return;const $={column:m,operator:b};if(ao(b)){const V=T==null?void 0:T.type;$.value=V==="number"?Number(g):g}if(y.some(V=>V.column===$.column&&V.operator===$.operator&&V.value===$.value)){k();return}j([...y,$]),k()},[_,m,b,T,g,y,k]),R=u.useCallback($=>{j(y.filter((W,V)=>V!==$))},[y]),G=u.useMemo(()=>y.length!==o.length?!0:JSON.stringify(y)!==JSON.stringify(o),[y,o]),Z=u.useCallback(()=>{d(y),l()},[y,d,l]),ee=u.useCallback(()=>{j([...o]),k(),l()},[o,k,l]),h=u.useCallback($=>{var pe;const W=t.find(xe=>xe.name===$.column);if(!W)return"";const K=((pe=zn(W.type).find(xe=>xe.value===$.operator))==null?void 0:pe.label)||$.operator;return ao($.operator)?`${$.column} ${K.toLowerCase()} "${$.value}"`:`${$.column} ${K.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:ee,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:$=>$.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Filter columns"}),e.jsx(rr,{content:or.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:y.length>=v.filter.maxConditions,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Column"}),e.jsx(r.Select,{value:m,onChange:$=>{f($.target.value),x(""),I("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:S.map($=>e.jsxs(r.MenuItem,{value:$.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:W=>B(W.palette.primary.main,.2)}}},children:[qe($.name)," (",$.type,")"]},$.name))})]}),m&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Operator"}),e.jsx(r.Select,{value:b,onChange:$=>{x($.target.value),I("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:a.map($=>e.jsx(r.MenuItem,{value:$.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:W=>B(W.palette.primary.main,.2)}}},children:$.label},$.value))})]}),b&&ao(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(T==null?void 0:T.type)==="number"?"number":"text",value:g,onChange:$=>I($.target.value),label:"Value",placeholder:"Enter value...",sx:{"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:z,disabled:!_(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add another filter"}),y.length>=v.filter.maxConditions&&e.jsxs(r.Typography,{variant:"caption",sx:{display:"block",mt:.75,color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Filter limit reached — maximum ",v.filter.maxConditions," filters allowed. Remove an existing filter to add a new one."]})]}),y.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Active filters (",y.length,")"]}),e.jsx(r.Button,{onClick:()=>{c(),l()},sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:y.map(($,W)=>e.jsx(r.Chip,{label:h($),onDelete:()=>R(W),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:V=>`1px solid ${B(V.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:V=>B(V.palette.primary.main,.2),borderColor:"#aecbfa"},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},W))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Z,disabled:!G,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"grey.300",color:"grey.500"}},children:"Apply filter"})]})]})})}const ci="SORT_RULE";function Xd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const c=u.useRef(null),[{handlerId:d},l]=Bt.useDrop({accept:ci,collect(f){return{handlerId:f.getHandlerId()}},hover(f,b){var k;if(!c.current)return;const x=f.index,g=o;if(x===g)return;const I=(k=c.current)==null?void 0:k.getBoundingClientRect(),y=(I.bottom-I.top)/2,j=b.getClientOffset(),v=((j==null?void 0:j.y)??0)-I.top;x<g&&v<y||x>g&&v>y||(s(x,g),f.index=g)}}),[{isDragging:p},m]=Bt.useDrag({type:ci,item:()=>({index:o}),collect:f=>({isDragging:f.isDragging()})});return m(l(c)),e.jsxs(r.Box,{ref:c,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:p?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)",transform:"translateY(-1px)"}},children:[e.jsx(r.Chip,{label:t.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)","& .MuiChip-label":{px:0}}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:f=>n(o,f.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:f=>B(f.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:f=>B(f.palette.primary.main,.2)}}},children:"Descending"})]})}),e.jsx(r.IconButton,{onClick:()=>i(o),size:"small",sx:{p:.5,color:"text.secondary",transition:"all 0.2s ease","&:hover":{color:"error.main",bgcolor:"rgba(217, 48, 37, 0.08)",transform:"scale(1.1)"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]})}function Zd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,c]=u.useState(""),[d,l]=u.useState([]);u.useEffect(()=>{l([...o])},[o]);const p=u.useMemo(()=>JSON.stringify(d)!==JSON.stringify(o),[d,o]),m=tr(),f=u.useCallback(()=>!(d.length>=m.sort.maxLevels||!s||d.some(S=>S.column===s)),[d,s]),b=u.useCallback(()=>{if(!f())return;const S=d.length+1,T={column:s,direction:"asc",priority:S};l([...d,T]),c("")},[f,s,d]),x=u.useCallback(S=>{const a=d.filter((_,z)=>z!==S).map((_,z)=>({..._,priority:z+1}));l(a)},[d]),g=u.useCallback((S,T)=>{const a=[...d];a[S]={...a[S],direction:T},l(a)},[d]),I=u.useCallback((S,T)=>{const a=[...d],[_]=a.splice(S,1);a.splice(T,0,_);const z=a.map((R,G)=>({...R,priority:G+1}));l(z)},[d]),y=u.useCallback(()=>{n([]),i()},[n,i]),j=u.useCallback(()=>{n(d),i()},[d,n,i]),v=u.useCallback(()=>{l([...o]),c(""),i()},[o,i]),k=t.filter(S=>!d.some(T=>T.column===S.name));return e.jsx(Bt.DndProvider,{backend:rn.HTML5Backend,children:e.jsx(r.Box,{onClick:v,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:S=>S.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),e.jsx(rr,{content:or.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:v,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:d.length>=m.sort.maxLevels,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Select column..."}),e.jsx(r.Select,{value:s,onChange:S=>c(S.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:k.map(S=>e.jsx(r.MenuItem,{value:S.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:T=>B(T.palette.primary.main,.2)}}},children:qe(S.name)},S.name))})]}),e.jsx(r.Button,{onClick:b,disabled:!f(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),d.length>=m.sort.maxLevels&&e.jsxs(r.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",m.sort.maxLevels," sort levels allowed"]})]}),d.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",d.length,"/",m.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:y,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((S,T)=>e.jsx(Xd,{rule:S,index:T,onToggleDirection:g,onRemove:x,onMove:I},`${S.column}-${T}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:v,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:j,variant:"contained",disabled:!p||d.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function Qd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:p,isAdmin:m=!1,onClose:f}){var S,T;const x=Ot().palette,g=t.filter(a=>!a.isDeleted),I=t.filter(a=>a.isDeleted),y=g.filter(a=>a.scope==="global"),j=g.filter(a=>a.scope!=="global"),v=a=>{var Z,ee,h,$,W;const _=a.scope==="global",z=a.id===o,R=m||!_,G=m&&!_;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:z?"primary.main":"divider",bgcolor:z?B(x.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:z?"primary.main":B(x.text.primary,.22)}},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.75,py:1.25,gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,minWidth:0,cursor:"pointer",display:"flex",alignItems:"center",gap:1},onClick:()=>{n(a.id),f()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:z?600:500,color:z?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),a.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[_&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(w.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:B(((Z=x.info)==null?void 0:Z.main)??x.primary.main,.1),color:((ee=x.info)==null?void 0:ee.main)??x.primary.main,border:`1px solid ${B(((h=x.info)==null?void 0:h.main)??x.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),a.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:B(x.text.secondary,.08),color:"text.secondary","& .MuiChip-label":{px:.75}}})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[G&&p&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:V=>{V.stopPropagation(),p(a.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:(($=x.info)==null?void 0:$.main)??x.primary.main,bgcolor:B(((W=x.info)==null?void 0:W.main)??x.primary.main,.08)}},children:e.jsx(w.Language,{sx:{fontSize:16}})})}),R&&e.jsx(r.Tooltip,{title:_&&!m?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:_&&!m,onClick:V=>{V.stopPropagation(),s(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:B(x.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:_&&!m?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:_&&!m,onClick:V=>{V.stopPropagation(),c(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:B(x.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})})]})]})},a.id)},k=a=>{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:B(x.text.primary,.02)},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",color:"text.disabled",textDecoration:"line-through",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[d&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:z=>{z.stopPropagation(),d(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:B(((_=x.success)==null?void 0:_.main)??"#2e7d32",.08)}},children:e.jsx(w.Undo,{sx:{fontSize:15}})})}),l&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:z=>{z.stopPropagation(),l(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:B(x.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]},a.id)};return e.jsxs(r.Dialog,{open:!0,onClose:f,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"14px",maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${B(((S=x.common)==null?void 0:S.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600},children:"Manage Views"}),m&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:"Admin mode — you can promote Personal Views to Global"})]}),e.jsx(r.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.Add,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",borderRadius:"7px",fontWeight:500},children:"Create New View"})}),y.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1},children:[e.jsx(w.Language,{sx:{fontSize:14,color:((T=x.info)==null?void 0:T.main)??x.primary.main}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Global Views"}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:"— visible to all users"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:y.map(v)})]}),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(v)})]}),I.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:I.map(k)})]}),g.length===0&&I.length===0&&e.jsx(r.Box,{sx:{py:4,textAlign:"center",color:"text.disabled"},children:e.jsx(r.Typography,{variant:"body2",children:"No views created yet"})})]}),e.jsx(r.DialogActions,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:f,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const xo=50;function di({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:p=10}){const[m,f]=u.useState(s),[b,x]=u.useState(!1),[g,I]=u.useState(c),[y,j]=u.useState(d),v=()=>{if(!m.trim()){x(!0);return}if(m.trim().length>xo){x(!0);return}o(m.trim(),g.trim(),y),n()},k=T=>{T.key==="Enter"&&!T.shiftKey?v():T.key==="Escape"&&n()},S=()=>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:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[S(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",p," saved views. Delete an existing view before creating a new one."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:m,onChange:T=>{T.target.value.length<=xo&&f(T.target.value),b&&T.target.value.trim()&&x(!1)},onKeyDown:k,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:xo},error:b&&!m.trim(),helperText:b&&!m.trim()?"View name is required":`${m.length} / ${xo}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:T=>I(T.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),e.jsxs(r.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1},children:"This view will capture:"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[e.jsxs("li",{children:[t.filters.length," filter",t.filters.length!==1?"s":""]}),e.jsxs("li",{children:["Sorting: ",la(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:y,onChange:T=>j(T.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:v,variant:"contained",disabled:l&&!i,startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:i?"Save Changes":"Create Report View"})]})]})}function eu({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["Delete View",e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,mt:1},children:[e.jsx(w.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete View"})]})]})}const fo=100,ho=600,ui="COLUMN";function tu({column:t,index:o,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:c,moveColumn:d}){const l=u.useRef(null),[p,m]=u.useState(i.toString());u.useEffect(()=>{m(i.toString())},[i]);const[{handlerId:f},b]=Bt.useDrop({accept:ui,collect(k){return{handlerId:k.getHandlerId()}},hover(k,S){var Z;if(!l.current)return;const T=k.index,a=o;if(T===a)return;const _=(Z=l.current)==null?void 0:Z.getBoundingClientRect(),z=(_.bottom-_.top)/2,R=S.getClientOffset(),G=((R==null?void 0:R.y)??0)-_.top;T<a&&G<z||T>a&&G>z||(d(T,a),k.index=a)}}),[{isDragging:x},g]=Bt.useDrag({type:ui,item:()=>({index:o}),collect:k=>({isDragging:k.isDragging()})});g(b(l));const I=()=>{const k=parseInt(p);if(isNaN(k)){m(i.toString()),c(t.name,i);return}const S=Math.max(fo,Math.min(ho,k));m(S.toString()),c(t.name,S)},y=k=>{if(k===""||/^\d+$/.test(k)){m(k);const S=parseInt(k);if(!isNaN(S)&&S>=fo){const T=Math.min(ho,S);c(t.name,T)}}},j=k=>{k.key==="Enter"&&(k.preventDefault(),I(),k.target.blur())},v=k=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[k]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":f,sx:{opacity:x?.4:1,bgcolor:n?"background.paper":"grey.50",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"grey.50":"grey.100"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(w.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:qe(t.name)})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsx(r.Chip,{label:t.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${v(t.type)}15`,color:v(t.type),border:`1px solid ${v(t.type)}30`,"& .MuiChip-label":{px:1}}})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.TextField,{type:"number",value:p,onChange:k=>y(k.target.value),onBlur:I,onKeyDown:j,placeholder:"150",size:"small",inputProps:{min:fo,max:ho,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"},"& input[type=number]::-webkit-inner-spin-button":{opacity:1},"& input[type=number]::-webkit-outer-spin-button":{opacity:1}}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"px"})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.IconButton,{onClick:()=>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:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(w.Visibility,{sx:{fontSize:20}}):e.jsx(w.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?"#e6f4ea":"grey.100",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function ru({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:p,onResetLayout:m,onSaveToCurrentView:f,onSaveToAllViews:b,onSelectView:x,onClose:g}){const[I,y]=u.useState(!1),[j,v]=u.useState(n),[k,S]=u.useState(i),[T,a]=u.useState("all"),[_,z]=u.useState(null);u.useEffect(()=>{v(n)},[n]),u.useEffect(()=>{S(i)},[i]);const R=(oe,A)=>{S(F=>({...F,[oe]:A})),p==null||p(oe,A)},G=(oe,A)=>{const F=[...j],[re]=F.splice(oe,1);F.splice(A,0,re),v(F),l(F)},Z=()=>{m(),y(!1)},h=j.map(oe=>t.find(A=>A.name===oe)).filter(oe=>oe!==void 0).filter(oe=>{const A=o[oe.name]??!0;return T==="active"?A:T==="hidden"?!A:!0}),$=Object.values(o).filter(oe=>oe).length,W=t.length,V=s.find(oe=>oe.id===c),K=s.filter(oe=>!oe.isDeleted),pe=K.length>1,xe=u.useMemo(()=>{if(!V)return!1;const oe=V.snapshot,A=oe.columnVisibility??{},F=JSON.stringify(o)!==JSON.stringify(A),re=oe.columnOrder??[],q=n??[],Q=JSON.stringify(q)!==JSON.stringify(re)&&!(q.length===0&&re.length===0),ae=oe.columnWidths??{},ne=JSON.stringify(k)!==JSON.stringify(ae);return F||Q||ne},[V,o,n,k]);return e.jsx(Bt.DndProvider,{backend:rn.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:oe=>oe.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2,pb:1.5,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsxs(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",e.jsx(rr,{content:or.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"]})]}),K.length>0&&x&&e.jsxs(r.Box,{sx:{ml:2},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",color:"text.secondary",mb:.75,display:"block",textTransform:"uppercase",fontWeight:600,letterSpacing:"0.1em"},children:"View:"}),e.jsx(r.Button,{onClick:oe=>z(oe.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(V==null?void 0:V.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:_,open:!!_,onClose:()=>z(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:K.map(oe=>e.jsx(r.MenuItem,{onClick:()=>{x(oe.id),z(null)},selected:oe.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:A=>B(A.palette.primary.main,.2)}}},children:oe.name},oe.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:T,onChange:(oe,A)=>a(A),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:"primary.main",height:3}},children:[e.jsx(r.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}})]})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${fo}px, max: ${ho}px)`,arrow:!0,placement:"top",children:e.jsx(w.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:h.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:4,align:"center",sx:{py:6,borderBottom:"none"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):h.map((oe,A)=>e.jsx(tu,{column:oe,index:A,isVisible:o[oe.name]??!0,width:k[oe.name]||170,onToggleVisibility:d,onWidthChange:R,moveColumn:G},oe.name))})]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!0),disabled:!xe,variant:"outlined",startIcon:e.jsx(w.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[f&&e.jsx(r.Button,{onClick:()=>{f(k),g()},disabled:!xe,variant:"contained",startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&pe&&e.jsx(r.Button,{onClick:()=>{b(k),g()},disabled:!xe||!pe,variant:"contained",startIcon:e.jsx(w.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),I&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1400},children:e.jsxs(r.Paper,{onClick:oe=>oe.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:"12px",bgcolor:"background.paper",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,borderRadius:"4px","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Z,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function ou({schema:t,grouping:o,onApply:n,onClose:i}){var _;const[s,c]=u.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=u.useState(""),[p,m]=u.useState(null),f=u.useMemo(()=>ra(t),[t]),b=u.useMemo(()=>f.filter(z=>!s.levels.some((R,G)=>R.column===z.name&&G!==p)),[f,s.levels,p]),x=tr(),g=s.levels.length<x.grouping.maxLevels&&b.length>0,I=u.useCallback(()=>{!g||!d||(c({...s,levels:[...s.levels,{column:d}],enabled:!0}),l(""))},[g,d,s]),y=u.useCallback(z=>{const R=s.levels.filter((G,Z)=>Z!==z);if(R.length===0){n(null),i();return}c({...s,levels:R,enabled:R.length>0})},[s,n,i]),j=u.useCallback(z=>{m(z),l(s.levels[z].column)},[s.levels]),v=u.useCallback(()=>{if(p===null||!d)return;const z=[...s.levels];z[p]={column:d},c({...s,levels:z}),m(null),l("")},[p,d,s]),k=u.useCallback(()=>{m(null),l("")},[]),S=u.useCallback((z,R)=>{const G=R==="up"?z-1:z+1;if(G<0||G>=s.levels.length)return;const Z=[...s.levels],[ee]=Z.splice(z,1);Z.splice(G,0,ee),c({...s,levels:Z})},[s]),T=u.useCallback(()=>{n(null),i()},[n,i]),a=u.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[s,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:z=>z.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),e.jsx(rr,{content:or.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Stack,{spacing:2.5,children:[p===null&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:z=>l(z.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(z=>e.jsxs(r.MenuItem,{value:z.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:R=>B(R.palette.primary.main,.2)}}},children:[qe(z.name)," (",z.type.toUpperCase(),")"]},z.name))]})}),e.jsx(r.Button,{onClick:I,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),s.levels.length>=x.grouping.maxLevels&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),f.length===0&&e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),p!==null&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px",border:"1px solid #fdd663",bgcolor:"#fef7e0","& .MuiAlert-icon":{color:"#ea8600"}},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1.5,fontSize:"0.875rem",color:"text.primary"},children:["Edit Group Level ",p+1]}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:z=>l(z.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:s.levels[p].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[s.levels[p].column," (",(_=t.find(z=>z.name===s.levels[p].column))==null?void 0:_.type.toUpperCase(),")"]}),b.filter(z=>z.name!==s.levels[p].column).map(z=>e.jsxs(r.MenuItem,{value:z.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[qe(z.name)," (",z.type.toUpperCase(),")"]},z.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:v,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"#ea8600",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"#c96e00",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)"}},children:"Save"}),e.jsx(r.Button,{onClick:k,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),s.levels.length>0&&p===null&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),e.jsx(r.Button,{onClick:T,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:s.levels.map((z,R)=>{const G=t.find(Z=>Z.name===z.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1)"}},children:[e.jsx(r.Chip,{label:`L${R+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)"}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:z.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:G==null?void 0:G.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>S(R,"up"),disabled:R===0,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(w.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>S(R,"down"),disabled:R===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(R),sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100",color:"primary.main"}},children:e.jsx(w.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y(R),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(w.Delete,{sx:{fontSize:18}})})]})]},R)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:a,variant:"contained",disabled:s.levels.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const nu={filters:w.FilterList,sorting:w.UnfoldMore,visibility:w.Visibility,order:w.ViewColumn,widths:w.Straighten,grouping:w.Layers};function iu({changes:t,onClose:o}){const n=i=>({filters:"primary",sorting:"secondary",visibility:"success",order:"warning",widths:"info",grouping:"error"})[i]||"default";return e.jsxs(r.Dialog,{open:!0,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["View Changes Summary",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,children:t.length===0?e.jsx(r.Box,{sx:{textAlign:"center",py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No changes detected"})}):e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"The following modifications have been made to this view:"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:t.map((i,s)=>{const c=nu[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})]})]},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:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})}function su({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:s,onCancel:c}){const[d,l]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:"primary.lighter",borderBottom:p=>`1px solid ${B(p.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:"rgba(60, 64, 67, 0.08)",color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:s,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:"0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px rgba(60, 64, 67, 0.15)"}},children:"Save as new view"})]})]})}),d&&e.jsx(iu,{changes:n,onClose:()=>l(!1)})]})}function au({onExportAnyway:t,onSaveAndExport:o,onCancel:n}){return e.jsx(r.Box,{sx:{mb:2,mx:3,mt:2},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(w.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,mb:.5},children:"You are exporting with unsaved view changes"}),e.jsx(r.Typography,{variant:"body2",sx:{mb:1.5},children:"Your current view has unsaved changes. Choose how to proceed:"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,variant:"contained",color:"primary",startIcon:e.jsx(w.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(w.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const pi=[{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 lu(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 cu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function du({auditHistory:t,onClose:o,onClearAuditHistory:n}){var I,y,j,v;const s=Ot().palette,[c,d]=u.useState("1h"),[l,p]=u.useState(!1),m=[...t].sort((k,S)=>new Date(S.timestamp).getTime()-new Date(k.timestamp).getTime()),f=pi.find(k=>k.key===c),b=lu(t,f.ms),x=()=>p(!0),g=()=>{n&&(n(cu(t,f.ms)),p(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:B(((I=s.common)==null?void 0:I.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:k=>k.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"16px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${B(((y=s.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${B(((j=s.common)==null?void 0:j.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,borderBottom:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),e.jsx(rr,{content:or.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[m.length," event",m.length!==1?"s":""," recorded"]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Select,{value:c,onChange:k=>d(k.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:B(s.text.primary,.3)}},children:pi.map(k=>e.jsx(r.MenuItem,{value:k.key,sx:{fontSize:"0.8125rem"},children:k.label},k.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:x,sx:{textTransform:"none",fontSize:"0.75rem",fontWeight:500,borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:B(s.error.main,.5),"&:hover":{bgcolor:B(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(w.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:B(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:B(s.text.primary,.14),borderRadius:3}},children:m.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(w.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",color:"text.secondary",fontWeight:500},children:"No audit events yet"}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:m.map(k=>{const S=ka(k.feature),{summary:T,detail:a}=Sa(k);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.25,px:1.5,py:1.25,borderRadius:"10px",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",transition:"border-color 0.15s","&:hover":{borderColor:B(s.text.primary,.18)}},children:[e.jsx(r.Chip,{label:wa(k.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:B(S,.1),color:S,border:`1px solid ${B(S,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:T}),a&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:a}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(w.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:Ta(k.timestamp)})]}),k.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(w.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:k.user})]})]})]})]},k.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>p(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${B(((v=s.common)==null?void 0:v.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:B(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["You are about to permanently remove"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:[b," audit record",b!==1?"s":""]})," ",f.key==="all"?"from all time":`from the ${f.label.toLowerCase()}`,". This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:()=>p(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",disableElevation:!0,startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function uu({onSave:t,onClose:o}){const[n,i]=u.useState(""),[s,c]=u.useState(""),[d,l]=u.useState(""),[p,m]=u.useState([]),[f,b]=u.useState(""),[x,g]=u.useState(""),I=a=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a),y=()=>{const a=d.trim();if(a){if(!I(a)){g("Please enter a valid email address");return}if(p.includes(a)){g("This email is already added");return}m([...p,a]),l(""),g("")}},j=a=>{m(p.filter(_=>_!==a))},v=a=>{a.key==="Enter"&&(a.preventDefault(),y())},k=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),s.trim(),p.length>0?p:void 0)},S=a=>{i(a),f&&b("")},T=a=>{l(a),x&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:a=>a.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(w.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:a=>`1px solid ${B(a.palette.primary.main,.3)}`,bgcolor:"primary.lighter","& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.6},children:"Save the current report configuration and generate a shareable link that others can use to view the same filters, sorting, and column layout."}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),e.jsx(r.TextField,{required:!0,value:n,onChange:a=>S(a.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!f,helperText:f,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value:s,onChange:a=>c(a.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:d,onChange:a=>T(a.target.value),onKeyPress:v,placeholder:"Enter email address",error:!!x,helperText:x,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),e.jsx(r.Button,{onClick:y,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",px:2,py:1.25,minHeight:40,borderRadius:"4px",flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:"Add"})]}),p.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:p.map(a=>e.jsx(r.Chip,{label:a,onDelete:()=>j(a),deleteIcon:e.jsx(w.Delete,{sx:{fontSize:16}}),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},a))}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:p.length>0?`An email with the shareable link will be sent to ${p.length} recipient${p.length>1?"s":""}`:"Add email addresses to send the shareable link automatically"})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:k,variant:"contained",startIcon:e.jsx(w.Share,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function pu({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(w.Link,{sx:{fontSize:14}}),label:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Preset:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600},children:t})]}),onDelete:o,deleteIcon:e.jsx(r.IconButton,{size:"small",title:"Exit preset view",sx:{p:0},children:e.jsx(w.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>B(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 xu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:s}){const[c,d]=u.useState(null),l=p=>new Date(p).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:p=>p.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"common.white",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[t.length," saved ",t.length===1?"preset":"presets"]})]}),e.jsx(r.IconButton,{onClick:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:"#bdc1c6"}}},children:t.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[e.jsx(w.Share,{sx:{fontSize:48,color:"divider",mb:2}}),e.jsx(r.Typography,{variant:"body1",sx:{fontSize:"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"#80868b",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:t.map(p=>e.jsxs(r.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"common.white",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary",mb:.5},children:p.name}),p.description&&e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:p.description})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[e.jsx(r.Chip,{label:`Created ${l(p.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}}),e.jsx(r.Chip,{label:`By ${p.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),e.jsx(r.Divider,{sx:{my:1.5,borderColor:"#f1f3f4"}}),e.jsx(r.Box,{sx:{display:"flex",gap:1},children:e.jsx(r.Button,{onClick:()=>i(p.id,p.name),variant:"outlined",size:"small",startIcon:e.jsx(w.Delete,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:"4px","&:hover":{borderColor:"error.main",bgcolor:"rgba(217, 48, 37, 0.04)"}},children:"Delete"})})]},p.id))})}),e.jsx(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:e.jsx(r.Button,{onClick:s,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})})}const Ji={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},mu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],fu=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function hu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=fu.some(l=>l.test(i.name));let c=!1;const d=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);d.length>0&&(c=d.filter(p=>mu.some(m=>m.test(p))).length/d.length>.6),(s||c)&&n.push(i.name)}return n}function pn(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),s=o.map(d=>{const l=n.map(m=>String(m[d]??"")).filter(m=>m.length>0);if(l.length===0)return 5;const p=l.reduce((m,f)=>m+f.length,0);return Math.ceil(p/l.length)+1}).reduce((d,l)=>d+l,0)+1;return o.reduce((d,l)=>d+l.length+1,0)+s*t.length}function gu(t,o){const n=pn(t,o);return Math.ceil(n*3.5)}function yu(t,o){const n=pn(t,o);return Math.ceil(n*.7)}function bu(t,o,n){switch(t){case"csv":return pn(o,n);case"excel":return yu(o,n);case"json":return gu(o,n)}}function xi(t,o){return Math.ceil(t/o)}function vu(t,o,n,i,s=Ji){const c=[],d=bu(t,o,n),l=o.length;if(l>s.maxRowsHard){const f=xi(l,s.maxRows);c.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 ${f} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:s.maxRowsHard})}else if(l>s.maxRows){const f=xi(l,s.maxRows);c.push({type:"row_count",severity:"warning",message:`Large export: ${l.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${f} smaller export${f>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:s.maxRows})}if(d>s.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Zr(d)} exceeds the ${Zr(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:d,limit:s.maxFileSizeHardBytes}):d>s.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Zr(d)}`,detail:`This exceeds the recommended ${Zr(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:s.maxFileSizeBytes}),t!=="excel"){const f=hu(i.filter(b=>n.includes(b.name)),o);if(f.length>0){const b=f.length>s.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${f.length>1?"s":""} detected: ${f.map(x=>`"${x.replace(/_/g," ")}"`).join(", ")}`,detail:b?`Exporting ${f.length} image columns may produce a very large file. Consider hiding these columns before exporting.`:"Image URL columns are included in the export as plain text links — not embedded images.",value:f.length,limit:s.maxImageColumns})}}const p=c.some(f=>f.severity==="error"),m=c.some(f=>f.severity==="warning");return{violations:c,hasBlockingViolation:p,hasWarning:m,estimatedBytes:d}}function Zr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Su({violation:t}){const n=Ot().palette,i=t.severity==="error",s=i?n.error.main:n.warning.main,c=B(i?n.error.main:n.warning.main,.06),d=i?B(n.error.main,.25):B(n.warning.main,.3),l=i?w.ErrorOutline:w.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:c,border:"1px solid",borderColor:d},children:[e.jsx(l,{sx:{fontSize:17,color: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(w.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function ju({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:c,sampleRows:d=[],allRows:l=[],processedRows:p=[],onExport:m,onClose:f}){var $,W,V;const x=Ot().palette,g=tr(),[I,y]=u.useState(g.export.allowedFormats[0]||"csv"),[j,v]=u.useState("visible"),[k,S]=u.useState("visible"),T=j==="visible"?o:t,a=k==="visible"?i:s,_=u.useMemo(()=>j==="visible"?p.length>0?p:new Array(o):l.length>0?l:new Array(t),[j,o,t,p,l]),z=u.useMemo(()=>k==="all"?c.map(K=>K.name):c.map(K=>K.name).slice(0,i),[k,c,i]),R=u.useMemo(()=>vu(I,_,z,c,Ji),[I,_,z,c]),G=()=>{R.hasBlockingViolation||(m({format:I,scope:j,columnScope:k}),f())},Z={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},ee={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},h={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:f,sx:{position:"fixed",inset:0,bgcolor:B((($=x.common)==null?void 0:$.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:K=>K.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:"14px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${B(((W=x.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${B(((V=x.common)==null?void 0:V.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(rr,{content:or.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflowY:"auto",px:3,py:2.5,display:"flex",flexDirection:"column",gap:2.5,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:B(x.text.primary,.15),borderRadius:3}},children:[R.violations.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:R.violations.map((K,pe)=>e.jsx(Su,{violation:K},pe))}),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:I,onChange:K=>y(K.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Comma-separated values, compatible with Excel"})]}),sx:{...ee,mb:.5}}),g.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Native Excel format with formatting support"})]}),sx:{...ee,mb:.5}}),g.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"JSON"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Structured data with metadata and filters"})]}),sx:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Rows"}),e.jsxs(r.RadioGroup,{value:j,onChange:K=>v(K.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",o.toLocaleString()," rows (filtered and searched)"]})]}),sx:{...ee,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",t.toLocaleString()," rows (complete original dataset)"]})]}),sx:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Columns"}),e.jsxs(r.RadioGroup,{value:k,onChange:K=>S(K.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible columns only"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",i," visible column",i!==1?"s":""]})]}),sx:{...ee,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",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:Z[I]},{label:"Rows to export",value:T.toLocaleString()},{label:"Columns to export",value:String(a)},{label:"Estimated file size",value:Zr(R.estimatedBytes),highlight:R.hasBlockingViolation?"error.main":R.hasWarning?"warning.main":void 0}].map(({label:K,value:pe,highlight:xe})=>e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary"},children:K}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:xe??"text.primary"},children:pe})]},K))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:B(x.text.primary,.015)},children:[R.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(w.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"error.main",fontWeight:500},children:"Reduce rows or columns to enable download"})]}),e.jsx(r.Button,{onClick:f,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:G,disabled:R.hasBlockingViolation,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.Download,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"8px"},children:["Download ",Z[I]]})]})]})})}function Cu({warning:t,onDismiss:o}){return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(w.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:t.message}),e.jsxs(r.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",t.type==="filter"?"filters":t.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function wu({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){u.useEffect(()=>{if(n){const l=setTimeout(()=>{o()},i);return()=>clearTimeout(l)}},[n,i,o]);const c=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(w.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Pa(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:c.severity,icon:c.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${c.severity}.main`},children:e.jsx(w.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${c.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:d}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class ku extends u.Component{constructor(n){super(n);Vr(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){Qt.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=>B(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(w.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((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=>B(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(w.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Tu({feature:t}){const[o,n]=u.useState(!0);return u.useEffect(()=>{const i=setTimeout(()=>n(!1),5e3);return()=>clearTimeout(i)},[]),e.jsx(r.Collapse,{in:o,unmountOnExit:!0,children:e.jsxs(r.Alert,{severity:"warning",sx:{m:1},icon:e.jsx(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(w.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Gr({children:t,feature:o,onError:n}){return e.jsx(ku,{context:o,onError:(i,s)=>{n&&n(i)},fallback:e.jsx(Tu,{feature:o}),children:t})}const Iu=[{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"}],zu=[{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 qr({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 Eu({open:t,onClose:o,config:n,onApply:i}){const[s,c]=u.useState(0),[d,l]=u.useState(n),p=()=>l(n),m=()=>l(Ye),f=()=>{i(d),o()},b={sort:j=>l(v=>({...v,sort:{...v.sort,...j}})),filter:j=>l(v=>({...v,filter:{...v.filter,...j}})),columns:j=>l(v=>({...v,columns:{...v.columns,...j}})),grouping:j=>l(v=>({...v,grouping:{...v.grouping,...j}})),export:j=>l(v=>({...v,export:{...v.export,...j}}))},x=j=>{const v=d.filter.allowedOperators,k=v.includes(j)?v.filter(S=>S!==j):[...v,j];k.length!==0&&b.filter({allowedOperators:k})},g=j=>{const v=d.export.allowedFormats,k=v.includes(j)?v.filter(S=>S!==j):[...v,j];k.length!==0&&b.export({allowedFormats:k})},I=[{label:"Sort",icon:e.jsx(w.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(w.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(w.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(w.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(w.Download,{sx:{fontSize:17}})}],y=j=>JSON.stringify(d[j])===JSON.stringify(Ye[j]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:p},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.2)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:j=>B(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(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:s,onChange:(j,v)=>c(v),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:I.map((j,v)=>e.jsx(r.Tab,{label:j.label,icon:j.icon,iconPosition:"start"},v))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(qr,{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"}),!y("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:d.sort.maxLevels,onChange:(j,v)=>b.sort({maxLevels:v}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(qr,{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"}),!y("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:d.filter.maxConditions,onChange:(j,v)=>b.filter({maxConditions:v}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(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:Iu.filter(v=>v.group===j).map(v=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(v.value),onChange:()=>x(v.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:v.label}),sx:{mr:1.5}},v.value))})]},j))]})]}),e.jsxs(qr,{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"}),!y("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:d.columns.maxVisible,onChange:(j,v)=>b.columns({maxVisible:v}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:d.columns.minColumnWidth,onChange:(j,v)=>b.columns({minColumnWidth:v}),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,v)=>b.columns({maxColumnWidth:v}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]})]})]})]}),e.jsxs(qr,{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"}),!y("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(j=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:j}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===j?"primary.main":"divider",bgcolor:d.grouping.maxLevels===j?v=>B(v.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:v=>B(v.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(qr,{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"}),!y("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),e.jsx(r.FormGroup,{sx:{gap:1},children:zu.map(j=>e.jsxs(r.Box,{onClick:()=>g(j.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:d.export.allowedFormats.includes(j.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(j.value)?v=>B(v.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(j.value),onChange:()=>g(j.value),onClick:v=>v.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=>B(j.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(w.RestartAlt,{sx:{fontSize:18}}),onClick:m,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:j=>B(j.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:f,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Bu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Du={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 go(t,o,n,i,s=new Date){const[c,d]=o.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(c,d,0,0),t==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const p=n??1,m=l.getDay();let f=p-m;return f<0&&(f+=7),f===0&&l<=s&&(f=7),l.setDate(l.getDate()+f),l.toISOString()}if(t==="monthly"){const p=Math.min(i??1,28);return l.setDate(p),l<=s&&(l.setMonth(l.getMonth()+1),l.setDate(p)),l.toISOString()}return l.toISOString()}function Ou(t){const o=Ki(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${Bu[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Du[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Ki(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Au(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),c=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${c}m`:c>0?`in ${c}m`:"in less than a minute"}function _u(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=Ki(`${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 Xi(t){return`urm_schedules_${t}`}function Zi(t){try{const o=localStorage.getItem(Xi(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 Qi(t,o){try{localStorage.setItem(Xi(t),JSON.stringify(o))}catch{}}const Mu=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"}],$u=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,es={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Zt={"& .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 Ru({initial:t=es,isEditing:o=!1,onSave:n,onBack:i}){const[s,c]=u.useState(t),[d,l]=u.useState(!1),[p,m]=u.useState(!1),f=(g,I)=>c(y=>({...y,[g]:I})),b=s.email.trim().length>0&&!$u.test(s.email.trim()),x=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.dayOfMonth<=28)&&!b;return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[e.jsx(r.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:g=>B(g.palette.text.primary,.06)}},children:e.jsx(w.ArrowBack,{sx:{fontSize:18}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:o?"Edit schedule":"New schedule"})]}),e.jsx(r.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:g=>{f("name",g.target.value),d&&g.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!s.name.trim(),helperText:d&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:Zt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Zt,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:s.frequency,label:"Frequency",onChange:g=>f("frequency",g.target.value),children:[e.jsx(r.MenuItem,{value:"daily",children:"Daily"}),e.jsx(r.MenuItem,{value:"weekly",children:"Weekly"}),e.jsx(r.MenuItem,{value:"monthly",children:"Monthly"})]})]}),s.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Zt,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:s.dayOfWeek,label:"Day of week",onChange:g=>f("dayOfWeek",Number(g.target.value)),children:Mu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),s.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:g=>f("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:s.dayOfMonth<1||s.dayOfMonth>28,helperText:s.dayOfMonth<1||s.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Zt}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:g=>f("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Zt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Zt,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:s.format,label:"Export format",onChange:g=>f("format",g.target.value),children:[e.jsx(r.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),e.jsx(r.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),e.jsx(r.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),e.jsxs(r.RadioGroup,{row:!0,value:s.scope,onChange:g=>f("scope",g.target.value),sx:{gap:2},children:[e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"All rows"})}),e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:s.email,onChange:g=>f("email",g.target.value),onBlur:()=>m(!0),placeholder:"user@company.com",error:p&&b,helperText:p&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Zt}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(w.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>B(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>x&&n(s),disabled:!x,size:"small",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Wu({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:i=>{var s;return`0 8px 32px ${B(((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=>B(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:"Delete"})]})]})}function Pu({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:s,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=>B(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=>B(l.palette.success.main,.1):l=>B(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:Ou(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=>B(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=>B(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(w.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>B(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: ",Au(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",_u(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=>B(l.palette.primary.main,.08)}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:d?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:d?"warning.main":"success.main","&:hover":{bgcolor:d?l=>B(l.palette.warning.main,.08):l=>B(l.palette.success.main,.08)}},children:d?e.jsx(w.Pause,{sx:{fontSize:15}}):e.jsx(w.PlayArrow,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Export now",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>i(t),sx:{color:"primary.main","&:hover":{bgcolor:l=>B(l.palette.primary.main,.08)}},children:e.jsx(w.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>c(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>B(l.palette.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]})]})}function Nu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[c,d]=u.useState([]),[l,p]=u.useState({type:"list"}),[m,f]=u.useState(0),[b,x]=u.useState(null);u.useEffect(()=>{t&&(d(Zi(n)),p({type:"list"}))},[t,n]),u.useEffect(()=>{if(!t)return;const z=setInterval(()=>f(R=>R+1),3e4);return()=>clearInterval(z)},[t]);const g=u.useCallback(z=>{d(z),Qi(n,z)},[n]),I=z=>{const R=go(z.frequency,z.time,z.dayOfWeek,z.dayOfMonth),G={id:`sched-${Date.now()}`,reportId:n,name:z.name.trim(),frequency:z.frequency,dayOfWeek:z.frequency==="weekly"?z.dayOfWeek:void 0,dayOfMonth:z.frequency==="monthly"?z.dayOfMonth:void 0,time:z.time,format:z.format,scope:z.scope,email:z.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:R,runCount:0};g([...c,G]),p({type:"list"})},y=z=>{if(l.type!=="edit")return;const R=l.schedule,G=go(z.frequency,z.time,z.dayOfWeek,z.dayOfMonth);g(c.map(Z=>Z.id===R.id?{...R,name:z.name.trim(),frequency:z.frequency,dayOfWeek:z.frequency==="weekly"?z.dayOfWeek:void 0,dayOfMonth:z.frequency==="monthly"?z.dayOfMonth:void 0,time:z.time,format:z.format,scope:z.scope,email:z.email.trim()||void 0,nextRunAt:G}:Z)),p({type:"list"})},j=z=>{g(c.map(R=>{if(R.id!==z)return R;const G=R.isActive?R.nextRunAt:go(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:G}}))},v=z=>{s(z);const R=new Date().toISOString();g(c.map(G=>G.id===z.id?{...G,lastRunAt:R,runCount:G.runCount+1}:G))},k=z=>{const R=c.find(G=>G.id===z)??null;x(R)},S=()=>{b&&(g(c.filter(z=>z.id!==b.id)),x(null))},T=z=>({name:z.name,frequency:z.frequency,dayOfWeek:z.dayOfWeek??1,dayOfMonth:z.dayOfMonth??1,time:z.time,format:z.format,scope:z.scope,email:z.email??""}),a=l.type!=="list",_=c.filter(z=>z.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:a,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:z=>B(z.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.Schedule,{sx:{fontSize:17,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"baseline",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,lineHeight:1},children:"Scheduled Reports"}),e.jsx(rr,{content:or.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:z=>B(z.palette.text.primary,.06)}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[a&&e.jsx(Ru,{initial:l.type==="edit"?T(l.schedule):es,isEditing:l.type==="edit",onSave:l.type==="edit"?y:I,onBack:()=>p({type:"list"})}),l.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:c.length===0?"No schedules yet":`${_} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(w.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",disableElevation:!0,onClick:()=>p({type:"create"}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),c.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(w.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.secondary"},children:"No scheduled reports yet"}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map(z=>e.jsx(Pu,{schedule:z,tick:m,onToggle:j,onRunNow:v,onEdit:R=>p({type:"edit",schedule:R}),onDelete:k},z.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:z=>B(z.palette.warning.main,.06),border:"1px solid",borderColor:z=>B(z.palette.warning.main,.2)},children:[e.jsx(w.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:z=>B(z.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Wu,{scheduleName:b.name,onConfirm:S,onCancel:()=>x(null)})]})}const Lu=6e4;function Fu({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:m,onFired:f}){const b=u.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:m,onFired:f});u.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:m,onFired:f}});const x=u.useCallback(g=>{var z,R;const{reportName:I,uploadedData:y,processedData:j,schema:v,activeView:k,columnVisibility:S,columnOrder:T,filters:a,sortStack:_}=b.current;try{const G=g.scope==="all"?y:j,Z=yo(G,v,a,_,k,S,T),ee=`${g.name}_scheduled`;switch(g.format){case"csv":bo(Z,ee,{scope:g.scope});break;case"excel":vo(Z,ee,{scope:g.scope});break;case"json":So(Z,ee,{scope:g.scope});break}if(g.email){const h=encodeURIComponent(`Scheduled Report: ${g.name}`),$=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
90
90
 
91
- Report: ${T}
91
+ Report: ${I}
92
92
  Format: ${g.format.toUpperCase()}
93
93
  Generated: ${new Date().toLocaleString()}
94
94
 
95
- The file has been downloaded to your device.`);window.open(`mailto:${g.email}?subject=${x}&body=${N}`,"_blank")}($=(B=b.current).onFired)==null||$.call(B,g)}catch(Y){Ut.error("urm:scheduler",`Export failed for schedule: ${g.name}`,Y)}},[]);p.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:y}=b.current;if(!y)return;const w=qi(y),v=new Date;let j=!1;const S=w.map(I=>{if(!I.isActive)return I;if(new Date(I.nextRunAt)<=v){f(I);const A=lo(I.frequency,I.time,I.dayOfWeek,I.dayOfMonth,v);return j=!0,{...I,lastRunAt:v.toISOString(),nextRunAt:A,runCount:I.runCount+1}}return I});j&&Ji(y,S)};g();const T=setInterval(g,_u);return()=>clearInterval(T)},[t,f])}function Xi({reportEngine:t}){var lr,Lt,Ft,M,Z;const{activeReport:o,paginatedData:n,processedData:i,displayData:s,tableMetrics:c,tableEngine:d,activeView:l,isDirty:u,currentTableState:m,viewChanges:h,showFilterPanel:b,setShowFilterPanel:f,filterFocusColumn:g,handleAddFilter:T,handleUpdateFilter:y,handleRemoveFilter:w,handleClearAllFilters:v,handleReplaceFilters:j,handleOpenFilterForColumn:S,handleCloseFilterPanel:I,handleClearFiltersForColumn:a,showSortPanel:A,setShowSortPanel:B,handleSort:$,handleUpdateSortStack:Y,handleSortAscending:Q,handleSortDescending:te,showManageViews:x,setShowManageViews:N,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:J,setShowEditViewModal:ue,showDeleteConfirmation:pe,setShowDeleteConfirmation:re,editingView:O,deletingView:F,handleSelectView:G,handleCreateView:se,handleUpdateCurrentView:ee,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:ae,handleSaveAsNewView:P,handleRevertChanges:ne,handleToggleDefault:ce,handleToggleFavorite:ie,handleSoftDelete:he,handleRestoreView:q,handlePermanentDelete:Ae,handleEditView:We,handleSaveEditView:tt,handleConfirmDelete:Kt,handlePromoteToGlobal:hr,showManageColumns:At,setShowManageColumns:it,handleUpdateColumnVisibility:Re,handleUpdateColumnOrder:Ee,handleUpdateColumnWidth:gt,handleResetColumnLayout:st,showGroupPanel:rt,setShowGroupPanel:Je,handleGroup:It,handleToggleGroupCollapse:Xt,searchQuery:at,searchHistory:Ke,handleSearchChange:Pe,handleAddToSearchHistory:Zt,handleToggleSearchFavourite:yt,handleDeleteSearchHistory:zt,selectedRowIds:Qt,handleToggleRowSelection:lt,handleToggleAllRows:gr,handleRangeSelection:yr,handleClearSelection:br,handleUpdateSelectionAfterDelete:Mt,currentPage:vr,pageSize:Sr,paginationEngine:Xe,handlePageChange:ve,handlePageSizeChange:jr,isExporting:er,showExportModal:ot,setShowExportModal:L,showDirtyExportWarning:Ne,handleExport:Se,handleExportWithConfig:_e,handleExportSelected:Cr,handleExportAnyway:_t,handleSaveAndExport:bt,handleCancelExport:$t,showAuditHistory:Wt,setShowAuditHistory:Et,showCreatePreset:wr,setShowCreatePreset:Rt,showManagePresets:De,setShowManagePresets:X,generatedPreset:vt,activePreset:ge,handleOpenManagePresets:je,handleCreatePreset:Ze,handleCopyPresetLink:kr,handleOpenPreset:St,handleClearActivePreset:$e,handleOpenPresetById:tr,handleCopyPresetLinkById:Tr,handleDeletePresetById:rr,isViewerRole:or,userRole:Ir,featureLimitWarning:nr,setFeatureLimitWarning:ir,reportError:Le,setReportError:ct,handleError:dt,updateReport:Fe,showSnack:sr,favoriteRowIndices:Pt,resolvedFavoritesSet:zr,showFavoritesOnly:Er,handleToggleRowFavorite:Br,handleBulkSetFavorites:Dr,handleToggleFavoritesFilter:Or}=t,[Ar,Nt]=p.useState(!1);$u({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)||((lr=l==null?void 0:l.snapshot)==null?void 0:lr.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((Lt=l==null?void 0:l.snapshot)==null?void 0:Lt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:K=>{sr(`Scheduled export "${K.name}" completed`,"success")}});const Mr=p.useCallback((K,de)=>{if(!(o!=null&&o.uploadedData))return;const oe=[...o.uploadedData];oe[K]=de,Fe(o.id,{uploadedData:oe})},[o,Fe]),_r=p.useCallback(K=>{if(!(o!=null&&o.uploadedData))return;const de=o.uploadedData.indexOf(K);if(de===-1)return;const oe=o.uploadedData.filter((nt,Xr)=>Xr!==de),He=(o.favoriteRowIndices||[]).filter(nt=>nt!==de).map(nt=>nt>de?nt-1:nt);Fe(o.id,{uploadedData:oe,favoriteRowIndices:He}),Mt(K)},[o,Fe,Mt]),Me=p.useCallback((K,de)=>{if(!(o!=null&&o.uploadedData))return;const oe=o.uploadedData.indexOf(de),He=oe!==-1?oe+1:K+1,nt=[...o.uploadedData];nt.splice(He,0,{...de});const Oo=(o.favoriteRowIndices??[]).map($r=>$r>=He?$r+1:$r);Fe(o.id,{uploadedData:nt,favoriteRowIndices:Oo})},[o,Fe]),Ve=Gt(),{handleDevConfigChange:ar}=go(),[Kr,ut]=p.useState(!1);return p.useEffect(()=>{const K=de=>{de.ctrlKey&&de.shiftKey&&de.key==="D"&&(de.preventDefault(),ut(!0))};return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},[]),!o||!o.schemaLocked||!o.schema||!o.uploadedData||!o.views?null:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,overflow:"hidden",position:"relative"},children:[!or&&u&&l&&e.jsx(tu,{viewName:l.name,isDefaultView:l.isDefault,changes:h,onSaveToCurrentView:l.isDefault?void 0:ee,onSaveAsNewView:P,onCancel:ne}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative"},children:[nr&&e.jsx(yu,{warning:nr,onDismiss:()=>ir(null)}),Le&&e.jsx(bu,{error:Le,onDismiss:()=>ct(null)}),Ne&&e.jsx(ru,{onExportAnyway:_t,onSaveAndExport:bt,onCancel:$t}),e.jsx(Hd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:u,isExporting:er,columnVisibility:o.columnVisibility||(l==null?void 0:l.snapshot.columnVisibility),columnOrder:o.columnOrder||(l==null?void 0:l.snapshot.columnOrder),columnWidths:o.columnWidths||(l==null?void 0:l.snapshot.columnWidths),grouping:o.grouping,onSort:$,onSortAscending:Q,onSortDescending:te,onOpenFilters:()=>f(!0),onOpenSort:()=>B(!0),onOpenFilterForColumn:S,onSelectView:G,onCreateView:()=>H(!0),onManageViews:()=>N(!0),onUpdateCurrentView:ee,onSaveAsNewView:P,onToggleDefault:ce,onToggleFavorite:ie,onRestoreView:q,onPermanentDelete:Ae,onExport:Se,onOpenColumns:()=>it(!0),onUpdateColumnWidth:gt,onUpdateColumnOrder:Ee,onUpdateColumnVisibility:Re,onClearFiltersForColumn:a,onResetLayout:st,onOpenGroup:()=>Je(!0),onToggleGroupCollapse:Xt,onOpenAuditHistory:()=>Et(!0),onOpenScheduledReports:()=>Nt(!0),searchQuery:at,searchHistory:Ke,onAddToSearchHistory:Zt,onToggleSearchFavourite:yt,onDeleteSearchHistory:zt,selectedRowIds:Qt,onSearchChange:Pe,onToggleRowSelection:lt,onToggleAllRows:gr,onRangeSelection:yr,onClearSelection:br,onExportSelected:Cr,currentPage:(Xe==null?void 0:Xe.currentPage)||vr,pageSize:(Xe==null?void 0:Xe.pageSize)||Sr,onPageChange:ve,onPageSizeChange:jr,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:or,userRole:Ir,reportName:o.name,onEditRow:Mr,onDeleteRow:_r,onDuplicateRow:Me,favoriteRowIndices:Pt,resolvedFavoritesSet:zr,showFavoritesOnly:Er,onToggleRowFavorite:Br,onBulkSetFavorites:Dr,onToggleFavoritesFilter:Or,showDevPanel:Ve.display.showDevPanel,onOpenDevConfig:()=>ut(!0)})]}),b&&e.jsx(Nr,{feature:"Filters",onError:K=>{const de=Ct("ui","filters",K);dt(de)},children:e.jsx(Ud,{schema:o.schema,filters:o.filters??[],onAddFilter:T,onUpdateFilter:y,onRemoveFilter:w,onClearAll:v,onReplaceFilters:j,onClose:I,focusColumn:g})}),A&&e.jsx(Nr,{feature:"Sorting",onError:K=>{const de=Ct("ui","sorting",K);dt(de)},children:e.jsx(Gd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:Y,onClose:()=>B(!1)})}),x&&e.jsx(Nr,{feature:"Views",onError:K=>{const de=Ct("ui","views",K);dt(de)},children:e.jsx(qd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:G,onCreateView:()=>{N(!1),H(!0)},onEditView:We,onDeleteView:he,onRestoreView:q,onPermanentDelete:Ae,onPromoteToGlobal:hr,isAdmin:((Ft=Ve.views)==null?void 0:Ft.isAdmin)??!1,onClose:()=>N(!1)})}),W&&m&&(()=>{var oe;const K=(o.views??[]).filter(He=>!He.isDeleted).length,de=((oe=Ve.views)==null?void 0:oe.maxViews)??10;return e.jsx(si,{currentSnapshot:m,onSave:se,onClose:()=>H(!1),atViewLimit:K>=de,maxViews:de})})(),J&&O&&e.jsx(si,{currentSnapshot:O.snapshot,onSave:tt,onClose:()=>{ue(!1)},isEditMode:!0,initialName:O.name,initialDescription:O.description,initialIsDefault:O.isDefault}),pe&&F&&e.jsx(Jd,{viewName:F.name,onConfirm:Kt,onCancel:()=>{re(!1)}}),At&&l&&e.jsx(Xd,{schema:o.schema,columnVisibility:o.columnVisibility||l.snapshot.columnVisibility,columnOrder:o.columnOrder||l.snapshot.columnOrder,columnWidths:o.columnWidths||l.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:Re,onUpdateColumnOrder:Ee,onUpdateColumnWidth:gt,onResetLayout:st,onSelectView:K=>{G(K)},onSaveToCurrentView:K=>{le(K),it(!1)},onSaveToAllViews:K=>{ae(K),it(!1)},onClose:()=>it(!1)}),rt&&e.jsx(Nr,{feature:"Grouping",onError:K=>{const de=Ct("ui","grouping",K);dt(de)},children:e.jsx(Zd,{schema:o.schema,grouping:o.grouping||null,onApply:It,onClose:()=>Je(!1)})}),Wt&&e.jsx(iu,{auditHistory:o.auditHistory||[],onClose:()=>Et(!1)}),wr&&e.jsx(su,{onSave:Ze,onClose:()=>Rt(!1)}),De&&e.jsx(lu,{presets:o.presets||[],reportId:o.id,onOpenPreset:tr,onCopyLink:Tr,onDeletePreset:rr,onClose:()=>X(!1)}),ge&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(au,{presetName:ge.name,onClear:$e})}),ot&&e.jsx(Nr,{feature:"Export",onError:K=>{const de=Ct("ui","export",K);dt(de)},children:e.jsx(gu,{totalRows:(c==null?void 0:c.totalRows)||((M=o.uploadedData)==null?void 0:M.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Z=d==null?void 0:d.columnEngine)==null?void 0:Z.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(c==null?void 0:c.isGrouped)||!1,onExport:_e,onClose:()=>{L(!1)}})}),o&&e.jsx(Mu,{open:Ar,onClose:()=>Nt(!1),reportId:o.id,reportName:o.name,onRunNow:K=>{const de=K.scope==="all"?o.uploadedData||[]:i||[],oe=co(de,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);K.format==="csv"&&uo(oe,K.name),K.format==="excel"&&po(oe,K.name),K.format==="json"&&xo(oe,K.name),sr(`"${K.name}" exported successfully`,"success")}}),e.jsx(Cu,{open:Kr,onClose:()=>ut(!1),config:Ve,onApply:ar})]})}function Zi({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(s,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 Qi({hasExternalData:t=!1}){const o=go(),{reports:n,activeReportId:i,activeReport:s,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:u,setIsModalOpen:m,setActiveReportId:h,createReport:b,handleFileUpload:f,handleUploadError:g,handleRetry:T,handleConfirm:y,snack:w,handleSnackClose:v}=o,j=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(el,{onCreateReport:()=>m(!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:j?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(Vi,{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(Xi,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&s.schema&&s.uploadedData?e.jsx(ud,{schema:s.schema,onConfirm:y,hasConflicts:l}):s.uploadError?e.jsx(pd,{error:s.uploadError,onRetry:T}):e.jsx(dd,{onFileUpload:f,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(cd,{isOpen:u,onClose:()=>m(!1),onCreate:b}),e.jsx(Zi,{open:w.open,message:w.message,severity:w.severity,onClose:v})]})}function Wu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(en,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(Qi,{hasExternalData:!!(t||o)})})}function es(){const t=go(),{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(Xi,{reportEngine:t}):e.jsx(Vi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(Zi,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Ru({data:t,autoLoad:o=!0,config:n}){return e.jsx(en,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(es,{})})}exports.URMBuilder=Wu;exports.URMBuilderRaw=Qi;exports.URMProvider=en;exports.URMViewer=Ru;exports.URMViewerRaw=es;exports.useURMContext=go;
95
+ The file has been downloaded to your device.`);window.open(`mailto:${g.email}?subject=${h}&body=${$}`,"_blank")}(R=(z=b.current).onFired)==null||R.call(z,g)}catch(G){Qt.error("urm:scheduler",`Export failed for schedule: ${g.name}`,G)}},[]);u.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:y}=b.current;if(!y)return;const j=Zi(y),v=new Date;let k=!1;const S=j.map(T=>{if(!T.isActive)return T;if(new Date(T.nextRunAt)<=v){x(T);const _=go(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth,v);return k=!0,{...T,lastRunAt:v.toISOString(),nextRunAt:_,runCount:T.runCount+1}}return T});k&&Qi(y,S)};g();const I=setInterval(g,Lu);return()=>clearInterval(I)},[t,x])}function ts({reportEngine:t}){var Oe,lt,Jt,Nr,Tt;const{activeReport:o,paginatedData:n,processedData:i,displayData:s,tableMetrics:c,tableEngine:d,activeView:l,isDirty:p,currentTableState:m,viewChanges:f,showFilterPanel:b,setShowFilterPanel:x,filterFocusColumn:g,handleAddFilter:I,handleUpdateFilter:y,handleRemoveFilter:j,handleClearAllFilters:v,handleReplaceFilters:k,handleOpenFilterForColumn:S,handleCloseFilterPanel:T,handleClearFiltersForColumn:a,showSortPanel:_,setShowSortPanel:z,handleSort:R,handleUpdateSortStack:G,handleSortAscending:Z,handleSortDescending:ee,showManageViews:h,setShowManageViews:$,showCreateViewModal:W,setShowCreateViewModal:V,showEditViewModal:K,setShowEditViewModal:pe,showDeleteConfirmation:xe,setShowDeleteConfirmation:oe,editingView:A,deletingView:F,handleSelectView:re,handleCreateView:q,handleUpdateCurrentView:Q,handleSaveColumnConfigToCurrentView:ae,handleSaveColumnConfigToAllViews:ne,handleSaveAsNewView:N,handleRevertChanges:ie,handleToggleDefault:le,handleToggleFavorite:se,handleSoftDelete:he,handleRestoreView:J,handlePermanentDelete:_e,handleEditView:Ve,handleSaveEditView:rt,handleConfirmDelete:nr,handlePromoteToGlobal:wr,showManageColumns:Nt,setShowManageColumns:ct,handleUpdateColumnVisibility:Ne,handleUpdateColumnOrder:ze,handleUpdateColumnWidth:At,handleResetColumnLayout:bt,showGroupPanel:Ke,setShowGroupPanel:Fe,handleGroup:Xe,handleToggleGroupCollapse:ir,searchQuery:Ze,searchHistory:ot,handleSearchChange:Re,handleAddToSearchHistory:sr,handleToggleSearchFavourite:kr,handleDeleteSearchHistory:Lt,selectedRowIds:dt,handleToggleRowSelection:vt,handleToggleAllRows:ar,handleRangeSelection:St,handleClearSelection:oo,handleUpdateSelectionAfterDelete:lr,currentPage:Tr,pageSize:jt,paginationEngine:nt,handlePageChange:Ir,handlePageSizeChange:Ft,isExporting:Se,showExportModal:zr,setShowExportModal:cr,showDirtyExportWarning:it,handleExport:L,handleExportWithConfig:He,handleExportSelected:je,handleExportAnyway:Le,handleSaveAndExport:Er,handleCancelExport:Vt,showAuditHistory:Ct,setShowAuditHistory:_t,showCreatePreset:Ht,setShowCreatePreset:Ut,showManagePresets:Br,setShowManagePresets:Yt,generatedPreset:Me,activePreset:X,handleOpenManagePresets:wt,handleCreatePreset:Ce,handleCopyPresetLink:we,handleOpenPreset:st,handleClearActivePreset:dr,handleOpenPresetById:ut,handleCopyPresetLinkById:Ue,handleDeletePresetById:ur,isViewerRole:pr,userRole:xr,featureLimitWarning:kt,setFeatureLimitWarning:Dr,reportError:Mt,setReportError:Gt,handleError:Qe,updateReport:at,showSnack:We,favoriteRowIndices:pt,resolvedFavoritesSet:mr,showFavoritesOnly:xt,handleToggleRowFavorite:Or,handleBulkSetFavorites:Ar,handleToggleFavoritesFilter:_r}=t,[Mr,fr]=u.useState(!1);Fu({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)||((Oe=l==null?void 0:l.snapshot)==null?void 0:Oe.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((lt=l==null?void 0:l.snapshot)==null?void 0:lt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:de=>{We(`Scheduled export "${de.name}" completed`,"success")}});const $r=u.useCallback((de,me)=>{if(!(o!=null&&o.uploadedData))return;const $e=[...o.uploadedData];$e[de]=me,at(o.id,{uploadedData:$e})},[o,at]),Rr=u.useCallback(de=>{if(!(o!=null&&o.uploadedData))return;const me=o.uploadedData.indexOf(de);if(me===-1)return;const $e=o.uploadedData.filter((U,ue)=>ue!==me),D=(o.favoriteRowIndices||[]).filter(U=>U!==me).map(U=>U>me?U-1:U);at(o.id,{uploadedData:$e,favoriteRowIndices:D}),lr(de)},[o,at,lr]),Wr=u.useCallback((de,me)=>{if(!(o!=null&&o.uploadedData))return;const $e=o.uploadedData.indexOf(me),D=$e!==-1?$e+1:de+1,U=[...o.uploadedData];U.splice(D,0,{...me});const Pe=(o.favoriteRowIndices??[]).map(ce=>ce>=D?ce+1:ce);at(o.id,{uploadedData:U,favoriteRowIndices:Pe})},[o,at]),$t=tr(),{handleDevConfigChange:hr}=ko(),[Pr,qt]=u.useState(!1);return u.useEffect(()=>{const de=me=>{me.ctrlKey&&me.shiftKey&&me.key==="D"&&(me.preventDefault(),qt(!0))};return document.addEventListener("keydown",de),()=>document.removeEventListener("keydown",de)},[]),!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:[!pr&&p&&l&&e.jsx(su,{viewName:l.name,isDefaultView:l.isDefault,changes:f,onSaveToCurrentView:l.isDefault?void 0:Q,onSaveAsNewView:N,onCancel:ie}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[kt&&e.jsx(Cu,{warning:kt,onDismiss:()=>Dr(null)}),Mt&&e.jsx(wu,{error:Mt,onDismiss:()=>Gt(null)}),it&&e.jsx(au,{onExportAnyway:Le,onSaveAndExport:Er,onCancel:Vt}),e.jsx(Jd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:p,isExporting:Se,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:Z,onSortDescending:ee,onOpenFilters:()=>x(!0),onOpenSort:()=>z(!0),onOpenFilterForColumn:S,onSelectView:re,onCreateView:()=>V(!0),onManageViews:()=>$(!0),onUpdateCurrentView:Q,onSaveAsNewView:N,onToggleDefault:le,onToggleFavorite:se,onRestoreView:J,onPermanentDelete:_e,onExport:L,onOpenColumns:()=>ct(!0),onUpdateColumnWidth:At,onUpdateColumnOrder:ze,onUpdateColumnVisibility:Ne,onClearFiltersForColumn:a,onResetLayout:bt,onOpenGroup:()=>Fe(!0),onGroupByColumn:de=>{Xe({enabled:!0,column:de,showCounts:!0})},onToggleGroupCollapse:ir,onOpenAuditHistory:()=>_t(!0),onOpenScheduledReports:()=>fr(!0),searchQuery:Ze,searchHistory:ot,onAddToSearchHistory:sr,onToggleSearchFavourite:kr,onDeleteSearchHistory:Lt,selectedRowIds:dt,onSearchChange:Re,onToggleRowSelection:vt,onToggleAllRows:ar,onRangeSelection:St,onClearSelection:oo,onExportSelected:je,currentPage:(nt==null?void 0:nt.currentPage)||Tr,pageSize:(nt==null?void 0:nt.pageSize)||jt,onPageChange:Ir,onPageSizeChange:Ft,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:pr,userRole:xr,reportName:o.name,onEditRow:$r,onDeleteRow:Rr,onDuplicateRow:Wr,favoriteRowIndices:pt,resolvedFavoritesSet:mr,showFavoritesOnly:xt,onToggleRowFavorite:Or,onBulkSetFavorites:Ar,onToggleFavoritesFilter:_r,showDevPanel:$t.display.showDevPanel,onOpenDevConfig:()=>qt(!0)})]}),b&&e.jsx(Gr,{feature:"Filters",onError:de=>{const me=Et("ui","filters",de);Qe(me)},children:e.jsx(Kd,{schema:o.schema,filters:o.filters??[],onAddFilter:I,onUpdateFilter:y,onRemoveFilter:j,onClearAll:v,onReplaceFilters:k,onClose:T,focusColumn:g})}),_&&e.jsx(Gr,{feature:"Sorting",onError:de=>{const me=Et("ui","sorting",de);Qe(me)},children:e.jsx(Zd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:G,onClose:()=>z(!1)})}),h&&e.jsx(Gr,{feature:"Views",onError:de=>{const me=Et("ui","views",de);Qe(me)},children:e.jsx(Qd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:re,onCreateView:()=>{$(!1),V(!0)},onEditView:Ve,onDeleteView:he,onRestoreView:J,onPermanentDelete:_e,onPromoteToGlobal:wr,isAdmin:((Jt=$t.views)==null?void 0:Jt.isAdmin)??!1,onClose:()=>$(!1)})}),W&&m&&(()=>{var $e;const de=(o.views??[]).filter(D=>!D.isDeleted).length,me=(($e=$t.views)==null?void 0:$e.maxViews)??10;return e.jsx(di,{currentSnapshot:m,onSave:q,onClose:()=>V(!1),atViewLimit:de>=me,maxViews:me})})(),K&&A&&e.jsx(di,{currentSnapshot:A.snapshot,onSave:rt,onClose:()=>{pe(!1)},isEditMode:!0,initialName:A.name,initialDescription:A.description,initialIsDefault:A.isDefault}),xe&&F&&e.jsx(eu,{viewName:F.name,onConfirm:nr,onCancel:()=>{oe(!1)}}),Nt&&l&&e.jsx(ru,{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:Ne,onUpdateColumnOrder:ze,onUpdateColumnWidth:At,onResetLayout:bt,onSelectView:de=>{re(de)},onSaveToCurrentView:de=>{ae(de),ct(!1)},onSaveToAllViews:de=>{ne(de),ct(!1)},onClose:()=>ct(!1)}),Ke&&e.jsx(Gr,{feature:"Grouping",onError:de=>{const me=Et("ui","grouping",de);Qe(me)},children:e.jsx(ou,{schema:o.schema,grouping:o.grouping||null,onApply:Xe,onClose:()=>Fe(!1)})}),Ct&&e.jsx(du,{auditHistory:o.auditHistory||[],onClose:()=>_t(!1)}),Ht&&e.jsx(uu,{onSave:Ce,onClose:()=>Ut(!1)}),Br&&e.jsx(xu,{presets:o.presets||[],reportId:o.id,onOpenPreset:ut,onDeletePreset:ur,onClose:()=>Yt(!1)}),X&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(pu,{presetName:X.name,onClear:dr})}),zr&&e.jsx(Gr,{feature:"Export",onError:de=>{const me=Et("ui","export",de);Qe(me)},children:e.jsx(ju,{totalRows:(c==null?void 0:c.totalRows)||((Nr=o.uploadedData)==null?void 0:Nr.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Tt=d==null?void 0:d.columnEngine)==null?void 0:Tt.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:He,onClose:()=>{cr(!1)}})}),o&&e.jsx(Nu,{open:Mr,onClose:()=>fr(!1),reportId:o.id,reportName:o.name,onRunNow:de=>{const me=de.scope==="all"?o.uploadedData||[]:i||[],$e=yo(me,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);de.format==="csv"&&bo($e,de.name),de.format==="excel"&&vo($e,de.name),de.format==="json"&&So($e,de.name),We(`"${de.name}" exported successfully`,"success")}}),e.jsx(Eu,{open:Pr,onClose:()=>qt(!1),config:$t,onApply:hr})]})}function rs({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(s,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 os({hasExternalData:t=!1}){const o=ko(),{reports:n,activeReportId:i,activeReport:s,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:p,setIsModalOpen:m,setActiveReportId:f,createReport:b,handleFileUpload:x,handleUploadError:g,handleRetry:I,handleConfirm:y,snack:j,handleSnackClose:v}=o,k=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(sl,{onCreateReport:()=>m(!0),reports:n,activeReportId:i,onReportClick:f}),e.jsx(r.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:k?e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[e.jsx(r.CircularProgress,{size:40,thickness:3}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{minWidth:260,textAlign:"center"},children:"Fetching API data — please wait..."})]}):n.length===0?e.jsx(Gi,{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(ts,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&s.schema&&s.uploadedData?e.jsx(gd,{schema:s.schema,onConfirm:y,hasConflicts:l}):s.uploadError?e.jsx(yd,{error:s.uploadError,onRetry:I}):e.jsx(hd,{onFileUpload:x,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(fd,{isOpen:p,onClose:()=>m(!1),onCreate:b}),e.jsx(rs,{open:j.open,message:j.message,severity:j.severity,onClose:v})]})}function Vu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(sn,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(os,{hasExternalData:!!(t||o)})})}function ns(){const t=ko(),{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(ts,{reportEngine:t}):e.jsx(Gi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(rs,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Hu({data:t,autoLoad:o=!0,config:n}){return e.jsx(sn,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(ns,{})})}exports.URMBuilder=Vu;exports.URMBuilderRaw=os;exports.URMProvider=sn;exports.URMViewer=Hu;exports.URMViewerRaw=ns;exports.useURMContext=ko;