dts-universal-report-module 1.0.6 → 1.0.8

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 +6536 -6228
  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"),Ss=require("xlsx"),w=require("@mui/icons-material"),r=require("@mui/material"),ni=require("react-dom"),js=require("@emotion/react"),jt=require("react-dnd"),Yo=require("react-dnd-html5-backend");function ii(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 po=ii(p),Kr=ii(Ss),Cs=/^\d{4}-\d{2}-\d{2}$/,ws=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,ks=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ts=9783072e5,zs=41024448e5,Is=978307200,Es=4102444800;function Bs(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Ts&&t<=zs?"timestamp_ms":Number.isInteger(t)&&t>=Is&&t<=Es?"timestamp_s":"unknown":typeof t!="string"?"unknown":ws.test(t)||Cs.test(t)?"iso":ks.test(t.trim())?"locale_string":"unknown"}function Ds(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=Bs(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 Os(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 ln=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ms=["January","February","March","April","May","June","July","August","September","October","November","December"];function De(t){return String(t).padStart(2,"0")}function As(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),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":""}`:u<5?b=`${u} week${u!==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 $s(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}-${De(i+1)}-${De(s)}`;case"DD/MM/YYYY":return`${De(s)}/${De(i+1)}/${n}`;case"MM/DD/YYYY":return`${De(i+1)}/${De(s)}/${n}`;case"MMM DD, YYYY":return`${ln[i]} ${De(s)}, ${n}`;case"DD MMM YYYY":return`${De(s)} ${ln[i]} ${n}`;case"MMMM D, YYYY":return`${Ms[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${De(i+1)}-${De(s)} ${De(c)}:${De(d)}`;case"DD/MM/YYYY HH:mm":return`${De(s)}/${De(i+1)}/${n} ${De(c)}:${De(d)}`;case"MM/DD/YYYY HH:mm":return`${De(i+1)}/${De(s)}/${n} ${De(c)}:${De(d)}`;case"relative":return As(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Rs(t,o,n){if(!n||o==="unknown")return String(t);const i=Os(t,o);return!i||isNaN(i.getTime())?String(t):$s(i,n)}function _s(t){return t==null?"null":Array.isArray(t)?"array":typeof t=="object"?"object":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="string"?"string":"mixed"}function si(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const 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,si(d,c,n+1)):i[c]=d}return i}function no(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:si(o))}function Rr(t){if(!Array.isArray(t)||t.length===0)return[];const o=no(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(h=>{typeof h=="object"&&h!==null&&d in h&&(u++,l.add(_s(h[d])))});const m=u===o.length,f=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const h=Array.from(l).filter(g=>g!=="null");h.length===1&&(b=h[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=Ds(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Ws(t){return t.some(o=>o.hasConflict)}function Ve(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function cn(t){return t==null}function Ps(t){return(o,n,i)=>{const s=cn(o),c=cn(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 Ns(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=Ps(l.type)(s[d.column],c[d.column],d.direction);if(m!==0)return m}return 0})}function Fs(t){return t===null?"asc":t==="asc"?"desc":null}function Ls(t){return t==="string"||t==="boolean"}function Vs(t){return t.filter(o=>Ls(o.type))}function Hs(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 Us(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=ai(t,n.levels,o);return li(i,n.collapsedGroups||[])}function ai(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}`,h=i?`${i}|${b}`:b,g=Hs(f,n),z=s<o.length-1?ai(f,o,n,h,s+1):f,v={key:h,level:s,column:c,value:m,rowCount:f.length,aggregates:g,children:z};l.push(v)}),l}function li(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&&li(i.children,o,n)}else n.push(i);return n}function Ys(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function ci(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function di(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 ui(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 Eo(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 Gs(t,o,n,i,s,c,d,l){const u={},m=[],f={};n.forEach(g=>{u[g.name]=!0,m.push(g.name),f[g.name]=150});const h=ui(s||m,d||null,l||m);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:h,columnWidths:c||f,grouping:d||null}}function qs(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(f=>{m[f]=n(u[f])}),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 Js(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function Ks(t,o){var v,j,S;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const y=t.filters.length,T=o.filters.length;y>T?n.push({category:"filters",label:"Filters Added",description:`${y-T} new filter${y-T>1?"s":""} added`}):y<T?n.push({category:"filters",label:"Filters Removed",description:`${T-y} filter${T-y>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 y=t.sortStack.length,T=o.sortStack.length;y>T?n.push({category:"sorting",label:"Sorting Added",description:`${y-T} new sort rule${y-T>1?"s":""} added`}):y<T?n.push({category:"sorting",label:"Sorting Removed",description:`${T-y} sort rule${T-y>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 y=Object.values(t.columnVisibility).filter(a=>a).length,T=Object.values(o.columnVisibility).filter(a=>a).length;y>T?n.push({category:"visibility",label:"Columns Shown",description:`${y-T} column${y-T>1?"s":""} made visible`}):y<T?n.push({category:"visibility",label:"Columns Hidden",description:`${T-y} column${T-y>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),h=JSON.stringify(o.columnWidths);if(b!==h){const y=Object.keys(t.columnWidths).filter(T=>t.columnWidths[T]!==o.columnWidths[T]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${y} column width${y>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),z=JSON.stringify(o.grouping);if(g!==z){const y=(v=t.grouping)==null?void 0:v.enabled,T=(j=o.grouping)==null?void 0:j.enabled;if(y&&!T){const a=((S=t.grouping)==null?void 0:S.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${a} grouping level${a>1?"s":""} added`})}else!y&&T?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 dn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function un(t){return`[${t}]`}const Ht={warn(t,o,...n){dn()&&console.warn(un(t),o,...n)},error(t,o,...n){dn()&&console.error(un(t),o,...n)}},pi="urm_report_";function Xs(t,o){try{const n=`${pi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){Ht.error("urm:persistence","Failed to save report state",n)}}function Zs(t){try{const o=`${pi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return Ht.error("urm:persistence","Failed to load report state",o),null}}function xo(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(Qs(d)){const l=s.children,u=xo(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 Qs(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 Go(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 so(t,o,n,i,s,c,d){let l,u;c?(l={...c},u=d||o.map(f=>f.name)):s?(l={...s.snapshot.columnVisibility},u=d||[...s.snapshot.columnOrder]):(l={},u=[],o.forEach(f=>{l[f.name]=!0,u.push(f.name)}));const m=Object.entries(l).filter(([f,b])=>!b).map(([f,b])=>f);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:u,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:m,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function ao(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=xo(i);l=Go(b)}else l=i;const u=d.join(","),m=l.map(b=>d.map(h=>{const g=b[h];if(g==null)return"";const z=String(g);return z.includes(",")||z.includes('"')||z.includes(`
2
- `)?`"${z.replace(/"/g,'""')}"`:z}).join(",")),f=[u,...m].join(`
3
- `);xi(f,qo(o,"csv"),"text/csv;charset=utf-8;")}function lo(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=xo(i);l=Go(b)}else l=i;const u=[d,...l.map(b=>d.map(h=>b[h]??""))],m=Kr.utils.aoa_to_sheet(u),f=Kr.utils.book_new();Kr.utils.book_append_sheet(f,m,"Data"),Kr.writeFile(f,qo(o,"xlsx"))}function co(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:u,grouping:m}=t;let f;if(m&&m.enabled){const g=xo(i);f=Go(g)}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:u,exportConfig:n||{scope:"visible"}},data:f},h=JSON.stringify(b,null,2);xi(h,qo(o,"json"),"application/json;charset=utf-8;")}function xi(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 pn=10;function ea(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>pn&&(s=[...s].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,pn)),s}function ta(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ra(t,o){return t.filter(n=>n.query!==o)}function oa(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 na={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function ia(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function st(t,o){return na[o].includes(t)}function at(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 sa(t){return t==="viewer"}const xn=1e3;function No(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function ct(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return No(n)}const aa={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 Bo(t){if(!t||!t.column)return"a filter";const o=ct(t.column),n=aa[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function mn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${ct(n.column)}"`).join(", ")}`}function la(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: ${Bo(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Bo(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 "${ct(u==null?void 0:u.column)}"`,detail:`Previously filtered "${ct(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Bo(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?ct(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?ct(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: ${mn(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?ct(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${mn(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: "${ct(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${ct(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: "${ct(l)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return l&&u?{summary:`Switched to view "${u}"`,detail:`From "${l}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,m=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",f=(i==null?void 0:i.viewName)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:f?`${No(m)} · View: "${f}"`:No(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:da(o)}}}function ca(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function mi(t,o,n,i,s,c){return{id:ca(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:c}}function fi(t,o){const n=[o,...t];return n.length>xn?n.slice(0,xn):n}function da(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 ua(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function pa(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function xa(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 fn=100;function ma(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function fa(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=ui(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 ha(t,o,n,i){return{id:ma(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function ga(t,o){const n=t||[];if(n.length>=fn)throw new Error(`Maximum of ${fn} presets reached. Please delete old presets first.`);return[...n,o]}function ya(t,o){return(t||[]).filter(i=>i.id!==o)}function hn(t,o){if(t)return t.find(n=>n.id===o)}function ba(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function va(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 Sa(t,o){return{totalRows:t.length,totalColumns:o.length}}const ja={MAX_CACHE_ENTRIES:3};function Ca(t,o){let n=null;return function(...s){const c=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(c,o)}}class Xr{constructor(o=ja.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 wa{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 St(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:ka(t,o)};return process.env.NODE_ENV==="development"&&Ht.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),c}function ka(t,o){return t==="ui"||t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Ta(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 za(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 Ia(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 Ea(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 hi(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 gi(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 Ba(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}=hi(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}=gi(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 Da(t,o){return St("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function gn(t,o,n,i){const s=mi(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return fi(i||[],s)}function Oa(t){return t==null}function Ma(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Oa(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 Aa(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Ma(n[i.column],i)))}function yn(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 Zr(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function $a({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:Aa(t,o),[t,o])}}function Ra(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 _a({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Ra(t,n,o,i),[t,o,n,i])}}function Wa({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:Ns(t,n,o),[t,o,n])}}function Pa({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:Us(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 Na({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 Fa({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(m=>m.id===o),[t,o]),s=p.useMemo(()=>i?qs(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 La({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,z=g+n;return t.slice(g,z)},[t,o,s,n]),m=p.useCallback(g=>{const z=Math.max(1,Math.min(g,l));c(z)},[l]),f=p.useCallback(()=>{s<l&&c(s+1)},[s,l]),b=p.useCallback(()=>{s>1&&c(s-1)},[s]),h=p.useCallback(()=>{c(1)},[]);return{paginatedData:u,currentPage:s,totalPages:l,pageSize:n,totalRows:d,goToPage:m,nextPage:f,prevPage:b,resetPage:h,hasNextPage:s<l,hasPrevPage:s>1}}function Va(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:u,columnWidths:m,views:f,activeViewId:b,pagination:h}=t,g=p.useMemo(()=>({filters:i,sortStack:s,grouping:c,columnVisibility:l,columnOrder:u,columnWidths:m}),[i,s,c,l,u,m]),z=Fa({views:f,activeViewId:b,currentState:g}),v=Na({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:j}=$a({data:o,filters:i}),{sortedData:S}=Wa({data:j,sortStack:s,schema:n}),{groupedData:y,isGrouped:T}=Pa({data:S,grouping:c,schema:n}),{searchedData:a}=_a({data:y,searchQuery:d,schema:n,visibleColumns:v.visibleColumns}),k=La({data:a,enabled:(h==null?void 0:h.enabled)||!1,pageSize:(h==null?void 0:h.pageSize)||100,initialPage:(h==null?void 0:h.currentPage)||1}),D=h!=null&&h.enabled?k.paginatedData:a,O=p.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:S.length,groupedRows:T?y.length:S.length,searchedRows:a.length,visibleRows:D.length,hiddenColumns:v.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:T}),[o.length,j.length,S.length,y.length,a.length,D.length,v.hiddenCount,i.length,s.length,T]);return{data:D,filteredData:j,sortedData:S,groupedData:y,searchedData:a,viewEngine:z,columnEngine:v,paginationEngine:k,metrics:O,isGrouped:T,isPaginated:(h==null?void 0:h.enabled)||!1}}let Ha=0;function Ua(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Ha++,writable:!1,enumerable:!1,configurable:!1})}const bt="user-demo-001";function Ya(t={}){var rn,on,nn,sn,an;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:c,sharedReportId:d,config:l={}}=t,[u,m]=p.useState([]),[f,b]=p.useState(""),[h,g]=p.useState(!1),[z,v]=p.useState(!1),[j,S]=p.useState({message:"",severity:"info",open:!1}),y=(C,B="info")=>{S({message:C,severity:B,open:!0})},T=()=>S(C=>({...C,open:!1})),a=u.find(C=>C.id===f),[k,D]=p.useState("idle"),[O,R]=p.useState(!1),[U,J]=p.useState(!1),[ee,x]=p.useState(!1),[N,_]=p.useState(!1),[H,q]=p.useState(!1),[de,ue]=p.useState(!1),[re,M]=p.useState(void 0),[L,G]=p.useState(null),[oe,Q]=p.useState(null),[le,ne]=p.useState(!1),[P,te]=p.useState(!1),[ie,se]=p.useState(null),[je,Y]=p.useState(!1),[Oe,Ae]=p.useState(!1),[dt,br]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[kt,Tt]=p.useState(""),[qe,_e]=p.useState(new Set),[Me,zt]=p.useState(1),[ut,pt]=p.useState(15),[Je,It]=p.useState(!1),[qt,Ke]=p.useState(!1),[Xe,We]=p.useState(!1),[xt,Mt]=p.useState(null),[Jt,mt]=p.useState(!1),[Kt,vr]=p.useState(null),[Xt,Zt]=p.useState(null);p.useRef(new wa),p.useRef(new Xr),p.useRef(new Xr),p.useRef(new Xr),p.useRef(new Xr);const[Qt,er]=p.useState(null),Ze=p.useRef(null),Ce=p.useMemo(()=>a?ia(a.permissions,bt):"owner",[a]),At=sa(Ce),Sr=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:Sa(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),Qe=p.useCallback(()=>{a&&(Ze.current=za(a))},[a]),F=p.useCallback((C,B)=>{m($=>$.map(A=>A.id===C?{...A,...B}:A))},[]),et=p.useCallback(C=>{if(!a)return;er(C);const B=gn(a.id,bt,C,a.auditHistory||[]);F(a.id,{auditHistory:B}),y(C.message,"error"),C.recoverable&&Ze.current&&setTimeout(()=>{Ia(a,Ze.current,F),y("Previous state restored","success")},100)},[a,F]),pe=p.useCallback((C,B,$,A)=>{if(!a)return;const Z=mi(a.id,bt,C,B,$,A),X=a.auditHistory||[],be=fi(X,Z);setTimeout(()=>{F(a.id,{auditHistory:be})},0)},[a,F]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=Eo(a.schema);(()=>{try{const B=localStorage.getItem("urm_dev_config");return B?JSON.parse(B):null}catch{return null}})(),F(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,F]),p.useEffect(()=>{if(i&&n&&!z&&u.length===0){const C=no(i),B={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Rr(C),permissions:{owner:bt,editors:[],viewers:[]}};m([B]),b(B.id),v(!0),D("confirmed")}},[i,n,z,u.length,o,c]),p.useEffect(()=>{if(!s||z)return;let C=!1,B=null;const $=async()=>{try{D("uploading");let A;if(s.type==="api"){const X=await fetch(s.url,{headers:s.headers||{}});if(!X.ok)throw new Error(`HTTP ${X.status}: ${X.statusText}`);A=await X.json()}else A=await s.fetch();if(C)return;if(!Array.isArray(A))throw new Error("Data source must return an array of objects");const Z=Rr(A);if(z)m(X=>X.map(be=>be.id===f?{...be,uploadedData:A}:be)),D("confirmed");else{const X={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:no(A),schema:Rr(no(A)),permissions:{owner:bt,editors:[],viewers:[]}};m([X]),b(X.id),v(!0),D("confirmed")}}catch(A){C||(D("error"),a&&F(a.id,{uploadError:(A==null?void 0:A.message)||"Failed to load data from source"}))}};return $(),s.refreshInterval&&s.refreshInterval>0&&(B=setInterval($,s.refreshInterval)),()=>{C=!0,B&&clearInterval(B)}},[s,c,o]);const Pe=(rn=a==null?void 0:a.views)==null?void 0:rn.find(C=>C.id===a.activeViewId),Et=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(Ua),a.showFavoritesOnly?!a.favoriteRowIndices||a.favoriteRowIndices.length===0?[]:a.uploadedData.filter((C,B)=>a.favoriteRowIndices.includes(B)):a.uploadedData):[],[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),jr=p.useMemo(()=>{var B;if(!(a!=null&&a.uploadedData)||!((B=a==null?void 0:a.favoriteRowIndices)!=null&&B.length))return new Set;const C=new Set;return a.favoriteRowIndices.forEach($=>{const A=a.uploadedData[$];A!==void 0&&C.add(A)}),C},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),ot=Va({rawData:Et,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:kt||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Pe==null?void 0:Pe.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Pe==null?void 0:Pe.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Pe==null?void 0:Pe.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:ut,currentPage:Me}}),{data:tr=[],searchedData:ft=[],groupedData:$t=[],metrics:rr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Cr=!1,paginationEngine:ke}=ot||{},K=((on=ot.viewEngine)==null?void 0:on.activeView)||Pe,nt=((nn=ot.viewEngine)==null?void 0:nn.isDirty)||!1;p.useEffect(()=>{if(!(!K||!a)&&!a.columnOrder){const C=K.snapshot.columnOrder,B=Fr(C,K.snapshot.grouping);F(a.id,{columnOrder:B})}},[a==null?void 0:a.activeViewId]);const ye=p.useMemo(()=>!(a!=null&&a.schema)||!K?null:Gs(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,K.snapshot.columnOrder),[a==null?void 0:a.filters,a==null?void 0:a.sortStack,a==null?void 0:a.schema,a==null?void 0:a.columnVisibility,a==null?void 0:a.columnOrder,a==null?void 0:a.columnWidths,a==null?void 0:a.grouping,K]),or=p.useMemo(()=>!K||!ye||!nt?[]:Ks(ye,K.snapshot),[K,ye,nt]),fe=p.useCallback((C,B,$)=>{const A={id:`report-${Date.now()}`,name:C,description:B,schemaLocked:!1,permissions:{owner:bt,editors:[],viewers:[]}};if($&&Array.isArray($)&&$.length>0){const Z=Rr($),X=Eo(Z);A.uploadedData=$,A.schema=Z,A.schemaLocked=!0,A.views=[X],A.activeViewId=X.id,A.sortStack=X.snapshot.sortStack,A.filters=X.snapshot.filters,A.columnVisibility=X.snapshot.columnVisibility,A.columnOrder=X.snapshot.columnOrder,A.columnWidths=X.snapshot.columnWidths,A.grouping=X.snapshot.grouping}m(Z=>[...Z,A]),b(A.id),g(!1),D("confirmed")},[]),tt=p.useCallback(C=>{a&&(D("uploading"),setTimeout(()=>{const B=Rr(C);F(a.id,{uploadedData:C,schema:B,uploadError:void 0}),D("preview")},500))},[a,F]),wr=p.useCallback(C=>{a&&(F(a.id,{uploadError:C}),D("idle"))},[a,F]),it=p.useCallback(()=>{a&&(F(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),D("idle"))},[a,F]),Re=p.useCallback(()=>{a&&(F(a.id,{schemaLocked:!0}),D("confirmed"))},[a,F]),nr=p.useCallback(C=>{if(!a)return;if(!st("edit_sorting",Ce)){y(at("edit_sorting"),"error");return}const B=a.sortStack??[],$=B.find(A=>A.column===C);if($){const A=Fs($.direction);if(A===null){const Z=B.filter(X=>X.column!==C).map((X,be)=>({...X,priority:be+1}));F(a.id,{sortStack:Z.length>0?Z:void 0})}else{const Z=B.map(X=>X.column===C?{...X,direction:A}:X);F(a.id,{sortStack:Z})}}else{if(B.length>=3)return;const A={column:C,direction:"asc",priority:B.length+1};F(a.id,{sortStack:[...B,A]})}},[a,Ce,F]),kr=p.useCallback(C=>{if(a)if(a.schema){const{validRules:B,invalidColumns:$}=hi(C,a.schema);$.length>0&&y(`Removed invalid sort columns: ${$.join(", ")}`),Qe();try{F(a.id,{sortStack:B.length>0?B:void 0})}catch(A){const Z=St("processing","sorting",A);et(Z)}}else F(a.id,{sortStack:C.length>0?C:void 0})},[a,F,Qe,et]),Rt=p.useCallback(C=>{if(!a)return;const B=a.sortStack??[],$=B.find(A=>A.column===C);if(!($&&$.direction==="asc"))if($){const A=B.map(Z=>Z.column===C?{...Z,direction:"asc"}:Z);F(a.id,{sortStack:A})}else{if(B.length>=3)return;const A={column:C,direction:"asc",priority:B.length+1};F(a.id,{sortStack:[...B,A]})}},[a,F]),Tr=p.useCallback(C=>{if(!a)return;const B=a.sortStack??[],$=B.find(A=>A.column===C);if(!($&&$.direction==="desc"))if($){const A=B.map(Z=>Z.column===C?{...Z,direction:"desc"}:Z);F(a.id,{sortStack:A})}else{if(B.length>=3)return;const A={column:C,direction:"desc",priority:B.length+1};F(a.id,{sortStack:[...B,A]})}},[a,F]),ir=p.useCallback(C=>{var $;if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const B=($=a.schema)==null?void 0:$.find(A=>A.name===C.column);if(B&&C.value!==void 0){const A=Ea(B.type,C.operator,C.value);if(!A.isValid){y(A.errorMessage||"Invalid filter value","error");return}}Qe();try{const A=a.filters??[];pe("filters","filter_added",A,[...A,C]),F(a.id,{filters:[...A,C]})}catch(A){const Z=St("processing","filters",A);et(Z)}},[a,Ce,F,Qe,et,pe]),zr=p.useCallback((C,B)=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const $=a.filters??[],A=[...$];pe("filters","filter_updated",$[C],B),A[C]=B,F(a.id,{filters:A})},[a,Ce,F,pe]),_t=p.useCallback(C=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const B=a.filters??[],$=B.filter((A,Z)=>Z!==C);pe("filters","filter_removed",B[C],null),F(a.id,{filters:$.length>0?$:void 0})},[a,Ce,F,pe]),Ue=p.useCallback(()=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const C=a.filters??[];pe("filters","filter_cleared",C,null),F(a.id,{filters:void 0})},[a,Ce,F,pe]),Ne=p.useCallback(C=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const B=a.filters??[];pe("filters","filter_cleared",B,C),F(a.id,{filters:C.length>0?C:void 0})},[a,Ce,F,pe]),rt=p.useCallback(C=>{var Z;if(!a)return;const B=(Z=a.views)==null?void 0:Z.find(X=>X.id===C);if(!B)return;const $=B.snapshot.columnOrder,A=Fr($,B.snapshot.grouping);F(a.id,{filters:B.snapshot.filters.length>0?[...B.snapshot.filters]:void 0,sortStack:B.snapshot.sortStack.length>0?[...B.snapshot.sortStack]:void 0,columnVisibility:{...B.snapshot.columnVisibility},columnOrder:A,columnWidths:{...B.snapshot.columnWidths},grouping:B.snapshot.grouping,activeViewId:C}),_e(new Set),x(!1)},[a,F]),ht=p.useCallback((C,B,$)=>{if(!(a!=null&&a.schema)||!ye)return;const A={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:B||void 0,isDefault:$,isFavorite:!1,isDeleted:!1,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...ye}},Z=a.views??[],X=$?Z.map(be=>({...be,isDefault:!1})):Z;F(a.id,{views:[...X,A],activeViewId:A.id}),y(`"${C}" view created`,"success")},[a,ye,F]),Wt=p.useCallback(()=>{var B;if(!K||!ye||K.isDefault||!a)return;const C=(B=a.views)==null?void 0:B.map($=>$.id===K.id?{...$,snapshot:{...ye}}:$);F(a.id,{views:C}),y(`"${K.name}" view updated`,"success")},[K,ye,a,F]),Ir=p.useCallback(C=>{var A;if(!K||!ye||!a)return;const B=C??ye.columnWidths,$=(A=a.views)==null?void 0:A.map(Z=>Z.id===K.id?{...Z,snapshot:{...Z.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:B},updatedAt:Date.now()}:Z);F(a.id,{views:$,columnWidths:B}),y(`Column configuration saved to "${K.name}"`,"success")},[K,ye,a,F]),Er=p.useCallback(C=>{var X,be;if(!ye||!a||!K)return;const B=C??ye.columnWidths,$={...K,snapshot:{...K.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:B},updatedAt:Date.now()},A=(X=a.views)==null?void 0:X.map(Te=>Te.id===K.id?$:{...Te,snapshot:{...Te.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:B},updatedAt:Date.now()});F(a.id,{views:A,columnWidths:B});const Z=(((be=a.views)==null?void 0:be.length)||0)-1;y(`Column configuration saved to current view and ${Z} other view${Z===1?"":"s"}`,"success")},[ye,a,K,F]),Br=p.useCallback(()=>{_(!0)},[]),Dr=p.useCallback(()=>{if(!K||!a)return;const C=K.snapshot.columnOrder,B=Fr(C,K.snapshot.grouping);F(a.id,{filters:K.snapshot.filters.length>0?[...K.snapshot.filters]:void 0,sortStack:K.snapshot.sortStack.length>0?[...K.snapshot.sortStack]:void 0,columnVisibility:{...K.snapshot.columnVisibility},columnOrder:B,columnWidths:{...K.snapshot.columnWidths},grouping:K.snapshot.grouping}),y("Changes reverted to last saved state","success")},[K,a,F]),Or=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(A=>({...A,isDefault:A.id===C}));F(a.id,{views:B});const $=a.views.find(A=>A.id===C);$&&y(`"${$.name}" set as default view`,"success")},[a,F]),Mr=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(A=>A.id===C?{...A,isFavorite:!A.isFavorite,updatedAt:Date.now()}:A);F(a.id,{views:B});const $=a.views.find(A=>A.id===C);$&&!$.isFavorite?y(`"${$.name}" added to favorites`,"success"):$&&y(`"${$.name}" removed from favorites`,"info")},[a,F]),sr=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(X=>X.id===C?{...X,isDeleted:!0,updatedAt:Date.now()}:X),$=a.activeViewId===C,A=B.find(X=>X.isDefault&&!X.isDeleted);F(a.id,{views:B,activeViewId:$&&A?A.id:a.activeViewId,filters:$&&A?A.snapshot.filters.length>0?A.snapshot.filters:void 0:a.filters,sortStack:$&&A?A.snapshot.sortStack.length>0?A.snapshot.sortStack:void 0:a.sortStack});const Z=a.views.find(X=>X.id===C);Z&&y(`"${Z.name}" moved to Recently Deleted`,"info")},[a,F]),ar=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(A=>A.id===C?{...A,isDeleted:!1,updatedAt:Date.now()}:A);F(a.id,{views:B});const $=a.views.find(A=>A.id===C);$&&y(`"${$.name}" restored`,"success")},[a,F]),Ar=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.find(Te=>Te.id===C),$=a.views.filter(Te=>!Te.isDeleted||Te.id===C);if((B==null?void 0:B.isDefault)&&$.filter(Te=>Te.isDefault).length===1){y("Cannot delete the last default view","error");return}const Z=a.views.filter(Te=>Te.id!==C),X=a.activeViewId===C,be=Z.find(Te=>Te.isDefault&&!Te.isDeleted);F(a.id,{views:Z,activeViewId:X&&be?be.id:a.activeViewId,filters:X&&be?be.snapshot.filters.length>0?be.snapshot.filters:void 0:a.filters,sortStack:X&&be?be.snapshot.sortStack.length>0?be.snapshot.sortStack:void 0:a.sortStack}),B&&y(`"${B.name}" permanently deleted`,"success")},[a,F]),$r=p.useCallback(C=>{G(C),q(!0),x(!1)},[]),Be=p.useCallback((C,B)=>{if(!L||!(a!=null&&a.views))return;const $=a.views.map(A=>A.id===L?{...A,name:C,description:B||void 0}:A);F(a.id,{views:$}),G(null)},[L,a,F]),gt=p.useCallback(C=>{Q(C),ue(!0),x(!1)},[]),lr=p.useCallback(()=>{if(!oe||!(a!=null&&a.views))return;const C=a.views.filter(A=>A.id!==oe),B=a.activeViewId===oe,$=C.find(A=>A.isDefault);F(a.id,{views:C,activeViewId:B&&$?$.id:a.activeViewId,filters:B&&$?$.snapshot.filters.length>0?$.snapshot.filters:void 0:a.filters,sortStack:B&&$?$.snapshot.sortStack.length>0?$.snapshot.sortStack:void 0:a.sortStack}),Q(null),ue(!1)},[oe,a,F]);p.useEffect(()=>{ke!=null&&ke.resetPage?ke.resetPage():zt(1)},[a==null?void 0:a.filters,kt,a==null?void 0:a.activeViewId]),p.useEffect(()=>{ke&&ke.currentPage!==Me&&zt(ke.currentPage)},[ke==null?void 0:ke.currentPage]);const cr=p.useCallback(C=>{ke!=null&&ke.goToPage&&ke.goToPage(C),zt(C)},[ke]),yt=p.useCallback(C=>{const B=(Me-1)*ut,$=Math.floor(B/C)+1;pt(C),zt($)},[Me,ut]),dr=p.useCallback((C,B)=>{if(!a)return;if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}const A={...a.columnVisibility||(K==null?void 0:K.snapshot.columnVisibility)||{},[C]:B};F(a.id,{columnVisibility:A})},[a,K,Ce,F]),Pt=p.useCallback(C=>{if(a){if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}F(a.id,{columnOrder:C})}},[a,Ce,F]),Nt=p.useCallback((C,B)=>{if(!a)return;if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}const A={...a.columnWidths||(K==null?void 0:K.snapshot.columnWidths)||{},[C]:B};F(a.id,{columnWidths:A})},[a,K,Ce,F]),I=p.useCallback(C=>{if(!a)return;const $=(a.filters??[]).filter(A=>A.column!==C);F(a.id,{filters:$.length>0?$:void 0})},[a,F]),V=p.useCallback(()=>{if(!K||!(a!=null&&a.schema))return;const C={},B=[],$={};a.schema.forEach(A=>{C[A.name]=!0,B.push(A.name),$[A.name]=150}),F(a.id,{columnVisibility:C,columnOrder:B,columnWidths:$,filters:void 0,sortStack:void 0}),y("Reset to default layout - all filters and sorts cleared","success")},[K,a,F]),ae=p.useCallback(Ca(C=>{Tt(C)},300),[]),$e=p.useCallback(C=>{ae(C)},[ae]),ce=p.useCallback(C=>{if(!C.trim()||!a)return;const B=a.searchHistory||[],$=ea(B,C);F(a.id,{searchHistory:$})},[a,F]),Ft=p.useCallback(C=>{if(!a)return;const B=a.searchHistory||[],$=ta(B,C);F(a.id,{searchHistory:$})},[a,F]),Ji=p.useCallback(C=>{if(!a)return;const B=a.searchHistory||[],$=ra(B,C);F(a.id,{searchHistory:$})},[a,F]),Ki=p.useCallback(C=>{_e(B=>{const $=new Set(B);return $.has(C)?$.delete(C):$.add(C),$})},[]),Xi=p.useCallback((C,B)=>{_e($=>{const A=new Set($);for(const Z of B)C?A.add(Z):A.delete(Z);return A})},[]),Zi=p.useCallback((C,B,$)=>{_e(A=>{const Z=new Set(A),X=Math.min(C,B),be=Math.max(C,B);for(let Te=X;Te<=be;Te++)$[Te]!==void 0&&Z.add($[Te]);return Z})},[]),Qi=p.useCallback(()=>{_e(new Set)},[]),es=p.useCallback(C=>{_e(B=>{const $=new Set(B);return $.delete(C),$})},[]),ts=p.useCallback(C=>{if(!(a!=null&&a.uploadedData))return;const B=a.uploadedData.indexOf(C);if(B===-1)return;const $=a.favoriteRowIndices||[],Z=$.includes(B)?$.filter(X=>X!==B):[...$,B];F(a.id,{favoriteRowIndices:Z})},[a,F]),rs=p.useCallback((C,B)=>{if(!(a!=null&&a.uploadedData))return;const $=a.favoriteRowIndices||[],A=C.map(X=>a.uploadedData.indexOf(X)).filter(X=>X!==-1),Z=B?[...$,...A.filter(X=>!$.includes(X))]:$.filter(X=>!A.includes(X));F(a.id,{favoriteRowIndices:Z})},[a,F]),os=p.useCallback(()=>{if(!a)return;const C=a.favoriteRowIndices||[],B=!a.showFavoritesOnly;if(B&&C.length===0){y("No rows marked as favorite","warning");return}F(a.id,{showFavoritesOnly:B}),_e(new Set),y(B?`Showing ${C.length} favorite row${C.length===1?"":"s"}`:"Showing all data","info")},[a,F]),ns=p.useCallback(C=>{if(a){if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}if(C&&a.schema){const{validGrouping:B,invalidColumns:$}=gi(C,a.schema);$.length>0&&y(`Removed invalid grouping columns: ${$.join(", ")}`,"warning"),Qe();try{const A=a.grouping;B===null?pe("grouping","group_cleared",A,null):A?pe("grouping","group_reordered",A,B):pe("grouping","group_level_added",null,B);const Z=(K==null?void 0:K.snapshot.columnOrder)||a.columnOrder||[],X=Fr(Z,B);F(a.id,{grouping:B,columnOrder:X}),JSON.stringify(X)!==JSON.stringify(a.columnOrder)&&pe("columns","column_reordered",a.columnOrder,X),Ae(!1)}catch(A){const Z=St("processing","grouping",A);et(Z)}}else{const B=a.grouping;pe("grouping","group_cleared",B,null);const $=(K==null?void 0:K.snapshot.columnOrder)||a.columnOrder||[];F(a.id,{grouping:C,columnOrder:[...$]}),JSON.stringify($)!==JSON.stringify(a.columnOrder)&&pe("columns","column_reordered",a.columnOrder,$),Ae(!1)}}},[a,K,Ce,F,Qe,et,pe]),is=p.useCallback(C=>{if(!a)return;const B=a.grouping;if(!B)return;const $=Ys(B,C);F(a.id,{grouping:$})},[a,F]),ss=p.useCallback(()=>{mt(!0)},[]),ur=p.useCallback(C=>{a!=null&&a.schema&&(ne(!0),setTimeout(()=>{try{let B;C.scope==="visible"?B=ft:B=a.uploadedData||[];let $;C.columnScope==="all"?($={},a.schema.forEach(Te=>{$[Te.name]=!0})):$=a.columnVisibility||(K==null?void 0:K.snapshot.columnVisibility)||{};const A=a.columnOrder||(K==null?void 0:K.snapshot.columnOrder),Z=so(B,a.schema,a.filters??[],a.sortStack??[],K,$,A),X=a.name;let be;switch(C.format){case"csv":ao(Z,X,C),be="export_csv";break;case"excel":lo(Z,X,C),be="export_excel";break;case"json":co(Z,X,C),be="export_json";break}pe("export",be,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:B.length,viewName:(K==null?void 0:K.name)||"Default View"}),y(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(B){const $=Da(B,{onRetry:()=>ur(C)});y(`Export failed: ${$.message}`,{action:{label:"Retry",onClick:()=>ur(C)}});const A=gn(a.id,bt,$,a.auditHistory||[]);F(a.id,{auditHistory:A}),Ht.error("urm:report-engine","Export failed",B)}finally{ne(!1)}},500))},[a,K,ft,F,pe]),as=p.useCallback(C=>{if(a!=null&&a.schema){if(nt&&K&&!K.isDefault){se(C.format),te(!0),mt(!1);return}ur(C),mt(!1)}},[a,K,nt,ur]),Jr=p.useCallback(C=>{ur({format:C,scope:"visible",columnScope:"visible"})},[ur]),ls=p.useCallback(()=>{ie&&Jr(ie),te(!1),se(null)},[ie,Jr]),cs=p.useCallback(()=>{Wt(),ie&&Jr(ie),te(!1),se(null)},[Wt,ie,Jr]),ds=p.useCallback(()=>{te(!1),se(null)},[]),us=p.useCallback(C=>{!(a!=null&&a.schema)||qe.size===0||(ne(!0),setTimeout(()=>{try{const B=Array.from(qe),$=so(B,a.schema,a.filters??[],a.sortStack??[],K),A=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":ao($,A);break;case"excel":lo($,A);break;case"json":co($,A);break}y(`Exported ${B.length} selected rows`,"info")}catch(B){y("Export failed. Please try again.","error"),Ht.error("urm:report-engine","Bulk export failed",B)}finally{ne(!1)}},500))},[a,K,qe,$t]),ps=p.useCallback((C,B)=>{if(a)try{const $=fa(a),A=ha(C,B,bt,$),Z=ga(a.presets,A);F(a.id,{presets:Z}),pe("presets","preset_created",null,{presetId:A.id,name:A.name}),Ke(!1),y(`Preset "${C}" saved successfully`,"success")}catch($){y($ instanceof Error?$.message:"Failed to create preset","error")}},[a,F,pe]),xs=p.useCallback(()=>{Mt(null),y("Exited preset view","info")},[]),ms=p.useCallback(()=>{We(!0)},[]),fs=p.useCallback((C,B)=>{if(!a)return;const $=ya(a.presets,C);F(a.id,{presets:$}),pe("presets","preset_deleted",{presetId:C,name:B},null),xt===C&&Mt(null),y(`Preset "${B}" deleted`,"success")},[a,xt,F,pe]);p.useEffect(()=>{if(!d||u.length===0)return;const C=u.find(B=>B.id===d);C&&C.id!==f&&b(C.id)},[d,u,f]),p.useEffect(()=>{if(!a)return;const C=ba();if(C&&a.presets&&a.schemaLocked&&a.schema){const B=hn(a.presets,C);if(B){const{sanitizedConfig:$,warnings:A}=Ba(B.config,a.schema);A.length>0&&A.forEach(X=>y(X,"warning"));const Z=va($);F(a.id,Z),Mt(C),pe("presets","preset_applied",null,{presetId:B.id,name:B.name}),y(`Loaded preset: ${B.name}`,"info")}else y("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const hs=xt?hn(a==null?void 0:a.presets,xt):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&Xs(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=Zs(a.id);if(C&&C.views.length>0){const B=C.views.find($=>$.id===C.activeViewId);if(B)F(a.id,{views:C.views,activeViewId:C.activeViewId,filters:B.snapshot.filters.length>0?B.snapshot.filters:void 0,sortStack:B.snapshot.sortStack.length>0?B.snapshot.sortStack:void 0});else{const $=C.views.find(A=>A.isDefault)||Eo(a.schema);F(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 gs=p.useCallback(C=>{M(C),R(!0)},[]),ys=p.useCallback(()=>{R(!1),M(void 0)},[]),bs=(sn=a==null?void 0:a.views)==null?void 0:sn.find(C=>C.id===L),vs=(an=a==null?void 0:a.views)==null?void 0:an.find(C=>C.id===oe);return{reports:u,activeReport:a,activeReportId:f,setActiveReportId:b,isModalOpen:h,setIsModalOpen:g,createReport:fe,updateReport:F,uploadState:k,handleFileUpload:tt,handleUploadError:wr,handleRetry:it,handleConfirm:Re,paginatedData:tr,processedData:ft,displayData:$t,tableMetrics:rr,isGrouped:Cr,tableEngine:ot,activeView:K,isDirty:nt,currentTableState:ye,viewChanges:or,filters:a==null?void 0:a.filters,showFilterPanel:O,setShowFilterPanel:R,filterFocusColumn:re,handleAddFilter:ir,handleUpdateFilter:zr,handleRemoveFilter:_t,handleClearAllFilters:Ue,handleReplaceFilters:Ne,handleOpenFilterForColumn:gs,handleCloseFilterPanel:ys,handleClearFiltersForColumn:I,sortStack:a==null?void 0:a.sortStack,showSortPanel:U,setShowSortPanel:J,handleSort:nr,handleUpdateSortStack:kr,handleSortAscending:Rt,handleSortDescending:Tr,views:a==null?void 0:a.views,showManageViews:ee,setShowManageViews:x,showCreateViewModal:N,setShowCreateViewModal:_,showEditViewModal:H,setShowEditViewModal:q,showDeleteConfirmation:de,setShowDeleteConfirmation:ue,editingView:bs,deletingView:vs,editingViewId:L,deletingViewId:oe,handleSelectView:rt,handleCreateView:ht,handleUpdateCurrentView:Wt,handleSaveColumnConfigToCurrentView:Ir,handleSaveColumnConfigToAllViews:Er,handleSaveAsNewView:Br,handleRevertChanges:Dr,handleToggleDefault:Or,handleToggleFavorite:Mr,handleSoftDelete:sr,handleRestoreView:ar,handlePermanentDelete:Ar,handleEditView:$r,handleSaveEditView:Be,handleDeleteView:gt,handleConfirmDelete:lr,showManageColumns:je,setShowManageColumns:Y,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:dr,handleUpdateColumnOrder:Pt,handleUpdateColumnWidth:Nt,handleResetColumnLayout:V,showGroupPanel:Oe,setShowGroupPanel:Ae,grouping:a==null?void 0:a.grouping,groupingState:dt,handleGroup:ns,handleToggleGroupCollapse:is,searchQuery:kt,searchHistory:oa((a==null?void 0:a.searchHistory)||[]),handleSearchChange:$e,handleAddToSearchHistory:ce,handleToggleSearchFavourite:Ft,handleDeleteSearchHistory:Ji,selectedRowIds:qe,handleToggleRowSelection:Ki,handleToggleAllRows:Xi,handleRangeSelection:Zi,handleClearSelection:Qi,handleUpdateSelectionAfterDelete:es,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:jr,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:ts,handleBulkSetFavorites:rs,handleToggleFavoritesFilter:os,currentPage:Me,pageSize:ut,paginationEngine:ke,handlePageChange:cr,handlePageSizeChange:yt,isExporting:le,showExportModal:Jt,setShowExportModal:mt,showDirtyExportWarning:P,handleExport:ss,handleExportWithConfig:as,handleExportSelected:us,handleExportAnyway:ls,handleSaveAndExport:cs,handleCancelExport:ds,showAuditHistory:Je,setShowAuditHistory:It,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:qt,setShowCreatePreset:Ke,showManagePresets:Xe,setShowManagePresets:We,activePreset:hs,activePresetId:xt,handleOpenManagePresets:ms,handleCreatePreset:ps,handleClearActivePreset:xs,handleDeletePresetById:fs,userRole:Ce,isViewerRole:At,currentUserId:bt,featureLimitWarning:Xt,setFeatureLimitWarning:Zt,datasetMeta:Sr,reportError:Qt,setReportError:er,handleError:et,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?Ws(a.schema):!1,snack:j,handleSnackClose:T,showSnack:y}}const Fe={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}},yi="urm_dev_config";function Ga(){try{const t=localStorage.getItem(yi);if(!t)return Fe;const o=JSON.parse(t),n={sort:{...Fe.sort,...o.sort},filter:{...Fe.filter,...o.filter},columns:{...Fe.columns,...o.columns},grouping:{...Fe.grouping,...o.grouping},export:{...Fe.export,...o.export},views:{...Fe.views,...o.views},dates:{...Fe.dates,...o.dates},display:{...Fe.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Fe}}function qa(t){try{localStorage.setItem(yi,JSON.stringify(t))}catch{}}function Ja(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 bi=p.createContext(Fe);function yr(){return p.useContext(bi)}const vi=p.createContext(void 0);function Jo(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:c,mode:d="builder",autoLoad:l=!0,config:u,devConfig:m,showDevPanel:f=!1,sharedReportId:b}=t,g=Ya({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:s,sharedReportId:b,config:u}),[z,v]=p.useState(()=>Ga()),j=(()=>{const a=Ja(z,m,!!m);return{...a,display:{...a.display,showDevPanel:f||a.display.showDevPanel}}})(),S=p.useCallback(T=>{v(T),qa(T)},[]),y={...g,activeDevConfig:j,handleDevConfigChange:S};return e.jsx(bi.Provider,{value:j,children:e.jsx(vi.Provider,{value:y,children:o})})}function mo(){const t=p.useContext(vi);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function Ka({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 Ut(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 Xa="$$material";function Za(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Qr={exports:{}},eo={exports:{}},xe={};/** @license React v16.13.1
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),Ts=require("xlsx"),w=require("@mui/icons-material"),r=require("@mui/material"),ui=require("react-dom"),Is=require("@emotion/react"),kt=require("react-dnd"),Xo=require("react-dnd-html5-backend");function pi(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const go=pi(u),Qr=pi(Ts),Ve={sort:{maxLevels:5},filter:{maxConditions:3,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},xi="urm_dev_config";function zs(){try{const t=localStorage.getItem(xi);if(!t)return Ve;const o=JSON.parse(t),n={sort:{...Ve.sort,...o.sort},filter:{...Ve.filter,...o.filter},columns:{...Ve.columns,...o.columns},grouping:{...Ve.grouping,...o.grouping},export:{...Ve.export,...o.export},views:{...Ve.views,...o.views},dates:{...Ve.dates,...o.dates},display:{...Ve.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ve}}function Es(t){try{localStorage.setItem(xi,JSON.stringify(t))}catch{}}function Bs(t,o,n){if(!n||!o)return t;const i={sort:{...t.sort,...o.sort},filter:{...t.filter,...o.filter},columns:{...t.columns,...o.columns},grouping:{...t.grouping,...o.grouping},export:{...t.export,...o.export},views:{...t.views,...o.views},dates:{...t.dates,...o.dates},display:{...t.display,...o.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const mi=u.createContext(Ve);function Kt(){return u.useContext(mi)}const Ds=/^\d{4}-\d{2}-\d{2}$/,Os=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,As=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ms=9783072e5,_s=41024448e5,$s=978307200,Rs=4102444800;function Ws(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Ms&&t<=_s?"timestamp_ms":Number.isInteger(t)&&t>=$s&&t<=Rs?"timestamp_s":"unknown":typeof t!="string"?"unknown":Os.test(t)||Ds.test(t)?"iso":As.test(t.trim())?"locale_string":"unknown"}function Ps(t,o){const n=o.map(d=>d[t]).filter(d=>d!=null&&d!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const d of n){const l=Ws(d);i[l]++}const a=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/a>=c)return d;return"unknown"}function Ns(t,o){if(t==null||t==="")return null;try{switch(o){case"timestamp_ms":{const n=new Date(Number(t));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(t)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const mn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ls=["January","February","March","April","May","June","July","August","September","October","November","December"];function Ae(t){return String(t).padStart(2,"0")}function Fs(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,a=Math.floor(n/1e3),c=Math.floor(a/60),d=Math.floor(c/60),l=Math.floor(d/24),p=Math.floor(l/7),x=Math.floor(l/30),f=Math.floor(l/365);let b;return a<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:p<5?b=`${p} week${p!==1?"s":""}`:x<12?b=`${x} month${x!==1?"s":""}`:b=`${f} year${f!==1?"s":""}`,a<60?b:i?`${b} ago`:`in ${b}`}function Vs(t,o){const n=t.getFullYear(),i=t.getMonth(),a=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${Ae(i+1)}-${Ae(a)}`;case"DD/MM/YYYY":return`${Ae(a)}/${Ae(i+1)}/${n}`;case"MM/DD/YYYY":return`${Ae(i+1)}/${Ae(a)}/${n}`;case"MMM DD, YYYY":return`${mn[i]} ${Ae(a)}, ${n}`;case"DD MMM YYYY":return`${Ae(a)} ${mn[i]} ${n}`;case"MMMM D, YYYY":return`${Ls[i]} ${a}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Ae(i+1)}-${Ae(a)} ${Ae(c)}:${Ae(d)}`;case"DD/MM/YYYY HH:mm":return`${Ae(a)}/${Ae(i+1)}/${n} ${Ae(c)}:${Ae(d)}`;case"MM/DD/YYYY HH:mm":return`${Ae(i+1)}/${Ae(a)}/${n} ${Ae(c)}:${Ae(d)}`;case"relative":return Fs(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Hs(t,o,n){if(!n||o==="unknown")return String(t);const i=Ns(t,o);return!i||isNaN(i.getTime())?String(t):Vs(i,n)}function Us(t){return t==null?"null":Array.isArray(t)?"array":typeof t=="object"?"object":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="string"?"string":"mixed"}function fi(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const a of Object.keys(t)){const c=o?`${o}.${a}`:a,d=t[a];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,fi(d,c,n+1)):i[c]=d}return i}function ao(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:fi(o))}function Pr(t){if(!Array.isArray(t)||t.length===0)return[];const o=ao(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let p=0;o.forEach(m=>{typeof m=="object"&&m!==null&&d in m&&(p++,l.add(Us(m[d])))});const x=p===o.length,f=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const m=Array.from(l).filter(g=>g!=="null");m.length===1&&(b=m[0])}i.push({name:d,type:b,required:x,hasConflict:f})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Ps(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Ys(t){return t.some(o=>o.hasConflict)}function Ue(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function fn(t){return t==null}function Gs(t){return(o,n,i)=>{const a=fn(o),c=fn(n);if(a&&c)return 0;if(a)return 1;if(c)return-1;let d=0;switch(t){case"number":const l=Number(o),p=Number(n);d=l-p;break;case"boolean":d=(o?1:0)-(n?1:0);break;case"string":d=String(o).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(o).localeCompare(String(n));break}return i==="asc"?d:-d}}function qs(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((a,c)=>a.priority-c.priority);return[...t].sort((a,c)=>{for(const d of i){const l=o.find(f=>f.name===d.column);if(!l)continue;const x=Gs(l.type)(a[d.column],c[d.column],d.direction);if(x!==0)return x}return 0})}function Js(t){return t===null?"asc":t==="asc"?"desc":null}function Ks(t){return t==="string"||t==="boolean"}function Xs(t){return t.filter(o=>Ks(o.type))}function Zs(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const a=t.map(c=>c[i.name]).filter(c=>typeof c=="number");a.length>0&&(n[i.name]=a.reduce((c,d)=>c+d,0))}}),n}function Qs(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=hi(t,n.levels,o);return gi(i,n.collapsedGroups||[])}function hi(t,o,n,i="",a=0){if(a>=o.length)return t;const c=o[a].column,d=new Map;t.forEach(x=>{const f=x[c],b=f==null?"(empty)":String(f);d.has(b)||d.set(b,[]),d.get(b).push(x)});const l=[];return Array.from(d.keys()).sort().forEach(x=>{const f=d.get(x),b=`${c}:${x}`,m=i?`${i}|${b}`:b,g=Zs(f,n),z=a<o.length-1?hi(f,o,n,m,a+1):f,y={key:m,level:a,column:c,value:x,rowCount:f.length,aggregates:g,children:z};l.push(y)}),l}function gi(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const a=o.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:a}),!a&&i.children&&gi(i.children,o,n)}else n.push(i);return n}function ea(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(a=>a!==o):[...n,o];return{...t,collapsedGroups:i}}function yi(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function bi(t,o,n){return`${o}: ${n}`}function Hr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(a=>a.column),i=t.filter(a=>!n.includes(a));return[...n,...i]}function vi(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),a=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(a);let p=0;for(const x of n)d.has(x)?c.push(x):l.has(x)&&p<a.length?(c.push(a[p]),p++):l.has(x)||c.push(x);for(let x=p;x<a.length;x++)c.includes(a[x])||c.push(a[x]);return c}return[...t]}function $o(t){const o={},n=[],i={};return t.forEach(a=>{o[a.name]=!0,n.push(a.name),i[a.name]=170}),{id:"default-view",name:"Default View",description:"Unfiltered, unsorted baseline view",isDefault:!0,snapshot:{filters:[],sortStack:[],columnVisibility:o,columnOrder:n,columnWidths:i,grouping:null}}}function ta(t,o,n,i,a,c,d,l){const p={},x=[],f={};n.forEach(g=>{p[g.name]=!0,x.push(g.name),f[g.name]=170});const m=vi(a||x,d||null,l||x);return{filters:t||[],sortStack:o||[],columnVisibility:i||p,columnOrder:m,columnWidths:c||f,grouping:d||null}}function ra(t,o){const n=m=>{if(m==null)return m;if(Array.isArray(m))return m.map(g=>n(g));if(typeof m=="object"){const g={};return Object.keys(m).sort().forEach(z=>{g[z]=n(m[z])}),g}return m},i=m=>JSON.stringify(n(m));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack))return!0;const a=t.columnVisibility??{},c=o.columnVisibility??{};if(i(a)!==i(c))return!0;const d=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(d!==l)return!1;const p=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==p){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const m=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==m)return!0}const f=t.columnWidths??{},b=o.columnWidths??{};return i(f)!==i(b)||i(t.grouping)!==i(o.grouping)}function oa(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function na(t,o){var y,C,v;const n=[],i=JSON.stringify(t.filters),a=JSON.stringify(o.filters);if(i!==a){const k=t.filters.length,S=o.filters.length;k>S?n.push({category:"filters",label:"Filters Added",description:`${k-S} new filter${k-S>1?"s":""} added`}):k<S?n.push({category:"filters",label:"Filters Removed",description:`${S-k} filter${S-k>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const c=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(c!==d){const k=t.sortStack.length,S=o.sortStack.length;k>S?n.push({category:"sorting",label:"Sorting Added",description:`${k-S} new sort rule${k-S>1?"s":""} added`}):k<S?n.push({category:"sorting",label:"Sorting Removed",description:`${S-k} sort rule${S-k>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(t.columnVisibility),p=JSON.stringify(o.columnVisibility);if(l!==p){const k=Object.values(t.columnVisibility).filter(T=>T).length,S=Object.values(o.columnVisibility).filter(T=>T).length;k>S?n.push({category:"visibility",label:"Columns Shown",description:`${k-S} column${k-S>1?"s":""} made visible`}):k<S?n.push({category:"visibility",label:"Columns Hidden",description:`${S-k} column${S-k>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const x=JSON.stringify(t.columnOrder),f=JSON.stringify(o.columnOrder);x!==f&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),m=JSON.stringify(o.columnWidths);if(b!==m){const k=Object.keys(t.columnWidths).filter(S=>t.columnWidths[S]!==o.columnWidths[S]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${k} column width${k>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),z=JSON.stringify(o.grouping);if(g!==z){const k=(y=t.grouping)==null?void 0:y.enabled,S=(C=o.grouping)==null?void 0:C.enabled;if(k&&!S){const T=((v=t.grouping)==null?void 0:v.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${T} grouping level${T>1?"s":""} added`})}else!k&&S?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function hn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function gn(t){return`[${t}]`}const qt={warn(t,o,...n){hn()&&console.warn(gn(t),o,...n)},error(t,o,...n){hn()&&console.error(gn(t),o,...n)}},Si="urm_report_";function ia(t,o){try{const n=`${Si}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){qt.error("urm:persistence","Failed to save report state",n)}}function sa(t){try{const o=`${Si}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return qt.error("urm:persistence","Failed to load report state",o),null}}function yo(t,o,n=0){const i=[];for(const a of t){const c=o.includes(a.key);if(i.push({type:"group",key:a.key,level:n,column:a.column,value:a.value,rowCount:a.rowCount,aggregates:a.aggregates,collapsed:c}),!c&&a.children&&a.children.length>0){const d=a.children[0];if(aa(d)){const l=a.children,p=yo(l,o,n+1);i.push(...p)}else{const l=a.children;for(const p of l)i.push({type:"row",parentGroupKey:a.key,level:n+1,data:p})}}}return i}function aa(t){return t&&typeof t=="object"&&"key"in t&&"level"in t&&"column"in t&&"value"in t&&"rowCount"in t&&"aggregates"in t&&"children"in t}function Zo(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function Qo(t,o){const n=new Date,i=n.getFullYear(),a=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${a}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function po(t,o,n,i,a,c,d){let l,p;c?(l={...c},p=d||o.map(f=>f.name)):a?(l={...a.snapshot.columnVisibility},p=d||[...a.snapshot.columnOrder]):(l={},p=[],o.forEach(f=>{l[f.name]=!0,p.push(f.name)}));const x=Object.entries(l).filter(([f,b])=>!b).map(([f,b])=>f);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:p,grouping:(a==null?void 0:a.snapshot.grouping)??null,hiddenColumns:x,viewMeta:a?{id:a.id,name:a.name,isDefault:a.isDefault}:void 0}}function xo(t,o="export",n){const{data:i,columnOrder:a,grouping:c}=t,d=a.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=yo(i);l=Zo(b)}else l=i;const p=d.join(","),x=l.map(b=>d.map(m=>{const g=b[m];if(g==null)return"";const z=String(g);return z.includes(",")||z.includes('"')||z.includes(`
2
+ `)?`"${z.replace(/"/g,'""')}"`:z}).join(",")),f=[p,...x].join(`
3
+ `);ji(f,Qo(o,"csv"),"text/csv;charset=utf-8;")}function mo(t,o="export",n){const{data:i,columnOrder:a,grouping:c}=t,d=a.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=yo(i);l=Zo(b)}else l=i;const p=[d,...l.map(b=>d.map(m=>b[m]??""))],x=Qr.utils.aoa_to_sheet(p),f=Qr.utils.book_new();Qr.utils.book_append_sheet(f,x,"Data"),Qr.writeFile(f,Qo(o,"xlsx"))}function fo(t,o="export",n){const{data:i,appliedFilters:a,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:p,grouping:x}=t;let f;if(x&&x.enabled){const g=yo(i);f=Zo(g)}else f=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:a.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:x||{},hiddenColumns:l,columnOrder:p,exportConfig:n||{scope:"visible"}},data:f},m=JSON.stringify(b,null,2);ji(m,Qo(o,"json"),"application/json;charset=utf-8;")}function ji(t,o,n){const i=new Blob([t],{type:n}),a=URL.createObjectURL(i),c=document.createElement("a");c.href=a,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(a)}const yn=10;function la(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.query.toLowerCase()===n.toLowerCase());let a;return i!==-1?a=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:a=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],a.length>yn&&(a=[...a].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,yn)),a}function ca(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function da(t,o){return t.filter(n=>n.query!==o)}function ua(t){const o=t.filter(i=>i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed);return[...o,...n]}const pa={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function xa(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function ct(t,o){return pa[o].includes(t)}function dt(t){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data",promote_global_view:"promote views to global"}[t]||"perform this action"}.`}function ma(t){return t==="viewer"}const bn=1e3;function Go(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function xt(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Go(n)}const fa={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function Ro(t){if(!t||!t.column)return"a filter";const o=xt(t.column),n=fa[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function vn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${xt(n.column)}"`).join(", ")}`}function ha(t){var a,c,d;const{action:o,previousState:n,newState:i}=t;switch(o){case"filter_added":{const l=i&&Array.isArray(i)?i[i.length-1]:i;return{summary:`Filter added: ${Ro(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Ro(n)}`};case"filter_updated":{const l=n,p=i;return(l==null?void 0:l.column)!==(p==null?void 0:p.column)?{summary:`Filter changed on "${xt(p==null?void 0:p.column)}"`,detail:`Previously filtered "${xt(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Ro(p)}`}}case"filter_cleared":{const l=Array.isArray(n)?n.length:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?xt(i.column):"",p=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${p}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?xt(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${vn(i)}`};case"group_level_removed":{const l=n,p=(c=(a=l==null?void 0:l.levels)==null?void 0:a[0])!=null&&c.column?xt(l.levels[0].column):"";return{summary:p?`Group level removed: "${p}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${vn(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${xt(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${xt(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],p=Array.isArray(i)?i:[];return l.length>0&&p.length>0?{summary:"Column order changed",detail:`${p.length} column${p.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",p=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${xt(l)}"`:"Column resized",detail:p?`New width: ${p}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",p=(i==null?void 0:i.name)??"";return l&&p?{summary:`Switched to view "${p}"`,detail:`From "${l}"`}:p?{summary:`Switched to view "${p}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",p=i==null?void 0:i.rowCount,x=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",f=(i==null?void 0:i.viewName)??"",b=typeof p=="number"?` (${p.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:f?`${Go(x)} · View: "${f}"`:Go(x)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",p=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&p?{summary:`Theme changed from "${l}" to "${p}"`}:p?{summary:`Theme changed to "${p}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:ya(o)}}}function ga(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ci(t,o,n,i,a,c){return{id:ga(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:a,newState:c}}function wi(t,o){const n=[o,...t];return n.length>bn?n.slice(0,bn):n}function ya(t){return{filter_added:"Filter Added",filter_removed:"Filter Removed",filter_updated:"Filter Updated",filter_cleared:"All Filters Cleared",sort_level_added:"Sort Level Added",sort_level_removed:"Sort Level Removed",sort_reordered:"Sort Reordered",sort_cleared:"All Sorting Cleared",group_level_added:"Group Level Added",group_level_removed:"Group Level Removed",group_reordered:"Group Reordered",group_cleared:"All Grouping Cleared",column_hidden:"Column Hidden",column_shown:"Column Shown",column_reordered:"Columns Reordered",column_resized:"Column Resized",view_created:"View Created",view_updated:"View Updated",view_deleted:"View Deleted",view_set_default:"View Set as Default",view_switched:"View Switched",theme_changed:"Theme Changed",export_triggered:"Export Triggered",export_csv:"Exported as CSV",export_excel:"Exported as Excel",export_json:"Exported as JSON",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[t]||t}function ba(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function va(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function Sa(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),a=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return a<1?"Just now":a<60?`${a} minute${a>1?"s":""} ago`:c<24?`${c} hour${c>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const Sn=100;function ja(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ca(t){var c;const o=(c=t.views)==null?void 0:c.find(d=>d.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],a=vi(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:a,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function wa(t,o,n,i){return{id:ja(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function ka(t,o){const n=t||[];if(n.length>=Sn)throw new Error(`Maximum of ${Sn} presets reached. Please delete old presets first.`);return[...n,o]}function Ta(t,o){return(t||[]).filter(i=>i.id!==o)}function jn(t,o){if(t)return t.find(n=>n.id===o)}function Ia(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function za(t){const o=t.columnOrder,n=Hr(o,t.grouping);return{filters:t.filters.length>0?[...t.filters]:void 0,sortStack:t.sortStack.length>0?[...t.sortStack]:void 0,columnVisibility:{...t.columnVisibility},columnOrder:n,columnWidths:{...t.columnWidths},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Ea(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ba={MAX_CACHE_ENTRIES:3};function Da(t,o){let n=null;return function(...a){const c=()=>{n=null,t(...a)};n&&clearTimeout(n),n=setTimeout(c,o)}}class eo{constructor(o=Ba.MAX_CACHE_ENTRIES){this.cache=new Map,this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const a=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];a&&this.cache.delete(a)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Oa{constructor(){this.metrics=new Map}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),a=this.end(o);return{result:i,duration:a}}async measureAsync(o,n){this.start(o);const i=await n(),a=this.end(o);return{result:i,duration:a}}}function wt(t,o,n,i){const a=n instanceof Error?n.message:n,c={type:t,context:o,message:a,details:i,timestamp:Date.now(),recoverable:Aa(t,o)};return process.env.NODE_ENV==="development"&&qt.error("urm:error-handling","[Report Error]",{type:t,context:o,message:a,details:i}),c}function Aa(t,o){return t==="ui"?!0:o==="export"?!1:t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Ma(t){const n={filters:"There was an issue applying filters",sorting:"Sorting could not be applied",grouping:"Grouping configuration failed",columns:"Column configuration could not be updated",views:"View operation failed",presets:"Preset could not be applied",export:"Export failed",upload:"File upload failed",search:"Search operation failed"}[t.context]||"An error occurred";return t.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function _a(t){return{filters:t.filters?[...t.filters]:void 0,sortStack:t.sortStack?[...t.sortStack]:void 0,grouping:t.grouping?{...t.grouping}:void 0,columnVisibility:t.columnVisibility?{...t.columnVisibility}:void 0,columnOrder:t.columnOrder?[...t.columnOrder]:void 0,columnWidths:t.columnWidths?{...t.columnWidths}:void 0,activeViewId:t.activeViewId}}function $a(t,o,n){n(t.id,{filters:o.filters,sortStack:o.sortStack,grouping:o.grouping,columnVisibility:o.columnVisibility,columnOrder:o.columnOrder,columnWidths:o.columnWidths,activeViewId:o.activeViewId})}function Ra(t,o,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(o)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:t==="number"&&["gt","gte","lt","lte","equals"].includes(o)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:t==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function ki(t,o){const n=[],i=[],a=new Set(o.map(c=>c.name));return t.forEach(c=>{a.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function Ti(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],a=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):a.push(c.column)}),i.length===0?{validGrouping:null,invalidColumns:a}:{validGrouping:{...t,levels:i},invalidColumns:a}}function Wa(t,o){const n=[],i=new Set(o.map(c=>c.name)),a={...t};if(a.filters&&Array.isArray(a.filters)){const c=a.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});a.filters=c.length>0?c:void 0}if(a.sortStack&&Array.isArray(a.sortStack)){const{validRules:c,invalidColumns:d}=ki(a.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),a.sortStack=c.length>0?c:void 0}if(a.grouping){const{validGrouping:c,invalidColumns:d}=Ti(a.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),a.grouping=c}if(a.columnVisibility){const c={};Object.entries(a.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),a.columnVisibility=Object.keys(c).length>0?c:void 0}if(a.columnOrder&&Array.isArray(a.columnOrder)){const c=a.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});a.columnOrder=c.length>0?c:void 0}if(a.columnWidths){const c={};Object.entries(a.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),a.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:a,warnings:n}}function Pa(t,o){return wt("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function Cn(t,o,n,i){const a=Ci(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return wi(i||[],a)}function Na(t){return t==null}function La(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Na(t))return!1;switch(n){case"equals":return String(t)===String(i);case"contains":return String(t).toLowerCase().includes(String(i).toLowerCase());case"startsWith":return String(t).toLowerCase().startsWith(String(i).toLowerCase());case"endsWith":return String(t).toLowerCase().endsWith(String(i).toLowerCase());case"gt":return Number(t)>Number(i);case"lt":return Number(t)<Number(i);case"gte":return Number(t)>=Number(i);case"lte":return Number(t)<=Number(i);case"isTrue":return t===!0;case"isFalse":return t===!1;default:return!0}}function Fa(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>La(n[i.column],i)))}function wn(t){switch(t){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function to(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Va({data:t,filters:o}){return{filteredData:u.useMemo(()=>!o||o.length===0?t:Fa(t,o),[t,o])}}function Ha(t,o,n,i){if(!n||n.trim()==="")return t;const a=n.toLowerCase().trim(),c=o.filter(d=>i.includes(d.name));return t.filter(d=>c.some(l=>{const p=d[l.name];return p==null?!1:String(p).toLowerCase().includes(a)}))}function Ua({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:u.useMemo(()=>!o||o.trim()===""?t:Ha(t,n,o,i),[t,o,n,i])}}function Ya({data:t,sortStack:o,schema:n}){return{sortedData:u.useMemo(()=>!o||o.length===0?t:qs(t,n,o),[t,o,n])}}function Ga({data:t,grouping:o,schema:n}){const i=u.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:Qs(t,n,o),[t,o,n]),a=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:a}}function qa({schema:t,columnVisibility:o,columnOrder:n}){const i=u.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),a=u.useMemo(()=>Object.entries(o).filter(([l,p])=>!p).map(([l,p])=>l),[o]),c=u.useMemo(()=>n.map(l=>t.find(x=>x.name===l)||{name:l,type:"string"}),[n,t]),d=u.useMemo(()=>i.map(l=>t.find(x=>x.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:a,allColumns:c,visibleColumnSchemas:d,hiddenCount:a.length}}function Ja({views:t,activeViewId:o,currentState:n}){const i=u.useMemo(()=>t.find(x=>x.id===o),[t,o]),a=u.useMemo(()=>i?ra(n,i.snapshot):!1,[i,n]),c=u.useMemo(()=>t.find(x=>x.isDefault),[t]),d=u.useMemo(()=>t.filter(x=>!x.isDefault&&!x.isDeleted),[t]),l=u.useMemo(()=>t.filter(x=>x.isFavorite&&!x.isDeleted),[t]),p=u.useMemo(()=>t.filter(x=>x.isDeleted),[t]);return{activeView:i,isDirty:a,defaultView:c,customViews:d,favoriteViews:l,deletedViews:p,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function Ka({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[a,c]=u.useState(i),d=t.length,l=Math.ceil(d/n),p=u.useMemo(()=>{if(!o)return t;const g=(a-1)*n,z=g+n;return t.slice(g,z)},[t,o,a,n]),x=u.useCallback(g=>{const z=Math.max(1,Math.min(g,l));c(z)},[l]),f=u.useCallback(()=>{a<l&&c(a+1)},[a,l]),b=u.useCallback(()=>{a>1&&c(a-1)},[a]),m=u.useCallback(()=>{c(1)},[]);return{paginatedData:p,currentPage:a,totalPages:l,pageSize:n,totalRows:d,goToPage:x,nextPage:f,prevPage:b,resetPage:m,hasNextPage:a<l,hasPrevPage:a>1}}function Xa(t){const{rawData:o,schema:n,filters:i,sortStack:a,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:p,columnWidths:x,views:f,activeViewId:b,pagination:m}=t,g=u.useMemo(()=>({filters:i,sortStack:a,grouping:c,columnVisibility:l,columnOrder:p,columnWidths:x}),[i,a,c,l,p,x]),z=Ja({views:f,activeViewId:b,currentState:g}),y=qa({schema:n,columnVisibility:l,columnOrder:p}),{filteredData:C}=Va({data:o,filters:i}),{sortedData:v}=Ya({data:C,sortStack:a,schema:n}),{groupedData:k,isGrouped:S}=Ga({data:v,grouping:c,schema:n}),{searchedData:T}=Ua({data:k,searchQuery:d,schema:n,visibleColumns:y.visibleColumns}),s=Ka({data:T,enabled:(m==null?void 0:m.enabled)||!1,pageSize:(m==null?void 0:m.pageSize)||100,initialPage:(m==null?void 0:m.currentPage)||1}),M=m!=null&&m.enabled?s.paginatedData:T,B=u.useMemo(()=>({totalRows:o.length,filteredRows:C.length,sortedRows:v.length,groupedRows:S?k.length:v.length,searchedRows:T.length,visibleRows:M.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:a.length,isGrouped:S}),[o.length,C.length,v.length,k.length,T.length,M.length,y.hiddenCount,i.length,a.length,S]);return{data:M,filteredData:C,sortedData:v,groupedData:k,searchedData:T,viewEngine:z,columnEngine:y,paginationEngine:s,metrics:B,isGrouped:S,isPaginated:(m==null?void 0:m.enabled)||!1}}let Za=0;function Qa(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Za++,writable:!1,enumerable:!1,configurable:!1})}const ut="user-demo-001";function el(t={}){var ln,cn,dn,un,pn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:a,reportName:c,sharedReportId:d,config:l={}}=t,[p,x]=u.useState([]),f=Kt(),[b,m]=u.useState(""),[g,z]=u.useState(!1),[y,C]=u.useState(!1),[v,k]=u.useState({message:"",severity:"info",open:!1}),S=(j,E="info")=>{k({message:j,severity:E,open:!0})},T=()=>k(j=>({...j,open:!1})),s=p.find(j=>j.id===b),[M,B]=u.useState("idle"),[$,G]=u.useState(!1),[Z,ee]=u.useState(!1),[h,R]=u.useState(!1),[W,H]=u.useState(!1),[K,de]=u.useState(!1),[ue,te]=u.useState(!1),[A,V]=u.useState(void 0),[q,re]=u.useState(null),[Q,le]=u.useState(null),[oe,N]=u.useState(!1),[ne,ce]=u.useState(!1),[se,fe]=u.useState(null),[J,Me]=u.useState(!1),[Ne,et]=u.useState(!1),[Qt,gr]=u.useState({enabled:!1,levels:[],collapsedGroups:[]}),[$t,ot]=u.useState(""),[Le,Ee]=u.useState(new Set),[mt,nt]=u.useState(1),[tt,Ge]=u.useState(15),[ft,er]=u.useState(!1),[qe,Je]=u.useState(!1),[$e,tr]=u.useState(!1),[ht,zt]=u.useState(null),[rr,it]=u.useState(!1),[yr,br]=u.useState(null),[vr,Rt]=u.useState(null);u.useRef(new Oa),u.useRef(new eo),u.useRef(new eo),u.useRef(new eo),u.useRef(new eo);const[Sr,jr]=u.useState(null),Ke=u.useRef(null),be=u.useMemo(()=>s?xa(s.permissions,ut):"owner",[s]),Cr=ma(be),or=u.useMemo(()=>!(s!=null&&s.uploadedData)||!(s!=null&&s.schema)?{totalRows:0,totalColumns:0}:Ea(s.uploadedData,s.schema),[s==null?void 0:s.uploadedData,s==null?void 0:s.schema]),rt=u.useCallback(()=>{s&&(Ke.current=_a(s))},[s]),L=u.useCallback((j,E)=>{x(_=>_.map(O=>O.id===j?{...O,...E}:O))},[]),Fe=u.useCallback(j=>{if(!s)return;jr(j);const E=Cn(s.id,ut,j,s.auditHistory||[]);L(s.id,{auditHistory:E}),S(j.message,"error"),j.recoverable&&Ke.current&&setTimeout(()=>{$a(s,Ke.current,L),S("Previous state restored","success")},100)},[s,L]),ve=u.useCallback((j,E,_,O)=>{if(!s)return;const Y=Ci(s.id,ut,j,E,_,O),U=s.auditHistory||[],pe=wi(U,Y);setTimeout(()=>{L(s.id,{auditHistory:pe})},0)},[s,L]);u.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const j=$o(s.schema);(()=>{try{const E=localStorage.getItem("urm_dev_config");return E?JSON.parse(E):null}catch{return null}})(),L(s.id,{views:[j],activeViewId:j.id,filters:j.snapshot.filters,sortStack:j.snapshot.sortStack,columnVisibility:j.snapshot.columnVisibility,columnOrder:j.snapshot.columnOrder,columnWidths:j.snapshot.columnWidths,grouping:j.snapshot.grouping})}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id,L]),u.useEffect(()=>{if(i&&n&&!y&&p.length===0){const j=ao(i),E={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:j,schema:Pr(j),permissions:{owner:ut,editors:[],viewers:[]}};x([E]),m(E.id),C(!0),B("confirmed")}},[i,n,y,p.length,o,c]),u.useEffect(()=>{if(!a||y)return;let j=!1,E=null;const _=async()=>{try{B("uploading");let O;if(a.type==="api"){const U=await fetch(a.url,{headers:a.headers||{}});if(!U.ok)throw new Error(`HTTP ${U.status}: ${U.statusText}`);O=await U.json()}else O=await a.fetch();if(j)return;if(!Array.isArray(O))throw new Error("Data source must return an array of objects");const Y=Pr(O);if(y)x(U=>U.map(pe=>pe.id===b?{...pe,uploadedData:O}:pe)),B("confirmed");else{const U={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${a.type==="api"?a.url:"callback"}`,schemaLocked:!0,uploadedData:ao(O),schema:Pr(ao(O)),permissions:{owner:ut,editors:[],viewers:[]}};x([U]),m(U.id),C(!0),B("confirmed")}}catch(O){j||(B("error"),s&&L(s.id,{uploadError:(O==null?void 0:O.message)||"Failed to load data from source"}))}};return _(),a.refreshInterval&&a.refreshInterval>0&&(E=setInterval(_,a.refreshInterval)),()=>{j=!0,E&&clearInterval(E)}},[a,c,o]);const Re=(ln=s==null?void 0:s.views)==null?void 0:ln.find(j=>j.id===s.activeViewId),wr=u.useMemo(()=>s!=null&&s.uploadedData?(s.uploadedData.forEach(Qa),s.showFavoritesOnly?!s.favoriteRowIndices||s.favoriteRowIndices.length===0?[]:s.uploadedData.filter((j,E)=>s.favoriteRowIndices.includes(E)):s.uploadedData):[],[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),Wt=u.useMemo(()=>{var E;if(!(s!=null&&s.uploadedData)||!((E=s==null?void 0:s.favoriteRowIndices)!=null&&E.length))return new Set;const j=new Set;return s.favoriteRowIndices.forEach(_=>{const O=s.uploadedData[_];O!==void 0&&j.add(O)}),j},[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),gt=Xa({rawData:wr,schema:(s==null?void 0:s.schema)||[],filters:(s==null?void 0:s.filters)||[],sortStack:(s==null?void 0:s.sortStack)||[],grouping:(s==null?void 0:s.grouping)||null,searchQuery:$t||"",columnVisibility:(s==null?void 0:s.columnVisibility)||(Re==null?void 0:Re.snapshot.columnVisibility)||{},columnOrder:(s==null?void 0:s.columnOrder)||(Re==null?void 0:Re.snapshot.columnOrder)||[],columnWidths:(s==null?void 0:s.columnWidths)||(Re==null?void 0:Re.snapshot.columnWidths)||{},views:(s==null?void 0:s.views)||[],activeViewId:(s==null?void 0:s.activeViewId)||"",pagination:{enabled:!0,pageSize:tt,currentPage:mt}}),{data:Pt=[],searchedData:Nt=[],groupedData:Et=[],metrics:kr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Lt=!1,paginationEngine:Oe}=gt||{},X=((cn=gt.viewEngine)==null?void 0:cn.activeView)||Re,yt=((dn=gt.viewEngine)==null?void 0:dn.isDirty)||!1;u.useEffect(()=>{if(!(!X||!s)&&!s.columnOrder){const j=X.snapshot.columnOrder,E=Hr(j,X.snapshot.grouping);L(s.id,{columnOrder:E})}},[s==null?void 0:s.activeViewId]);const he=u.useMemo(()=>!(s!=null&&s.schema)||!X?null:ta(s.filters||[],s.sortStack||[],s.schema,s.columnVisibility,s.columnOrder,s.columnWidths,s.grouping,X.snapshot.columnOrder),[s==null?void 0:s.filters,s==null?void 0:s.sortStack,s==null?void 0:s.schema,s==null?void 0:s.columnVisibility,s==null?void 0:s.columnOrder,s==null?void 0:s.columnWidths,s==null?void 0:s.grouping,X]),Se=u.useMemo(()=>!X||!he||!yt?[]:na(he,X.snapshot),[X,he,yt]),Xe=u.useCallback((j,E,_)=>{const O={id:`report-${Date.now()}`,name:j,description:E,schemaLocked:!1,permissions:{owner:ut,editors:[],viewers:[]}};if(_&&Array.isArray(_)&&_.length>0){const Y=Pr(_),U=$o(Y);O.uploadedData=_,O.schema=Y,O.schemaLocked=!0,O.views=[U],O.activeViewId=U.id,O.sortStack=U.snapshot.sortStack,O.filters=U.snapshot.filters,O.columnVisibility=U.snapshot.columnVisibility,O.columnOrder=U.snapshot.columnOrder,O.columnWidths=U.snapshot.columnWidths,O.grouping=U.snapshot.grouping}x(Y=>[...Y,O]),m(O.id),z(!1),B("confirmed")},[]),Tr=u.useCallback(j=>{s&&(B("uploading"),setTimeout(()=>{const E=Pr(j);L(s.id,{uploadedData:j,schema:E,uploadError:void 0}),B("preview")},500))},[s,L]),bt=u.useCallback(j=>{s&&(L(s.id,{uploadError:j}),B("idle"))},[s,L]),We=u.useCallback(()=>{s&&(L(s.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),B("idle"))},[s,L]),nr=u.useCallback(()=>{s&&(L(s.id,{schemaLocked:!0}),B("confirmed"))},[s,L]),Ir=u.useCallback(j=>{if(!s)return;if(!ct("edit_sorting",be)){S(dt("edit_sorting"),"error");return}const E=s.sortStack??[],_=E.find(O=>O.column===j);if(_){const O=Js(_.direction);if(O===null){const Y=E.filter(U=>U.column!==j).map((U,pe)=>({...U,priority:pe+1}));L(s.id,{sortStack:Y.length>0?Y:void 0})}else{const Y=E.map(U=>U.column===j?{...U,direction:O}:U);L(s.id,{sortStack:Y})}}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:j,direction:"asc",priority:E.length+1};L(s.id,{sortStack:[...E,O]})}},[s,be,L]),ir=u.useCallback(j=>{if(s)if(s.schema){const{validRules:E,invalidColumns:_}=ki(j,s.schema);_.length>0&&S(`Removed invalid sort columns: ${_.join(", ")}`),rt();try{L(s.id,{sortStack:E.length>0?E:void 0})}catch(O){const Y=wt("processing","sorting",O);Fe(Y)}}else L(s.id,{sortStack:j.length>0?j:void 0})},[s,L,rt,Fe]),vt=u.useCallback(j=>{if(!s)return;const E=s.sortStack??[],_=E.find(O=>O.column===j);if(!(_&&_.direction==="asc"))if(_){const O=E.map(Y=>Y.column===j?{...Y,direction:"asc"}:Y);L(s.id,{sortStack:O})}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:j,direction:"asc",priority:E.length+1};L(s.id,{sortStack:[...E,O]})}},[s,L]),zr=u.useCallback(j=>{if(!s)return;const E=s.sortStack??[],_=E.find(O=>O.column===j);if(!(_&&_.direction==="desc"))if(_){const O=E.map(Y=>Y.column===j?{...Y,direction:"desc"}:Y);L(s.id,{sortStack:O})}else{if(E.length>=f.sort.maxLevels){S(`Sort limit reached — maximum ${f.sort.maxLevels} sort levels allowed. Remove an existing sort to add a new one.`,"warning");return}const O={column:j,direction:"desc",priority:E.length+1};L(s.id,{sortStack:[...E,O]})}},[s,L]),Bt=u.useCallback(j=>{var _;if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const E=(_=s.schema)==null?void 0:_.find(O=>O.name===j.column);if(E&&j.value!==void 0){const O=Ra(E.type,j.operator,j.value);if(!O.isValid){S(O.errorMessage||"Invalid filter value","error");return}}rt();try{const O=s.filters??[];ve("filters","filter_added",O,[...O,j]),L(s.id,{filters:[...O,j]})}catch(O){const Y=wt("processing","filters",O);Fe(Y)}},[s,be,L,rt,Fe,ve]),Ft=u.useCallback((j,E)=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const _=s.filters??[],O=[..._];ve("filters","filter_updated",_[j],E),O[j]=E,L(s.id,{filters:O})},[s,be,L,ve]),St=u.useCallback(j=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const E=s.filters??[],_=E.filter((O,Y)=>Y!==j);ve("filters","filter_removed",E[j],null),L(s.id,{filters:_.length>0?_:void 0})},[s,be,L,ve]),sr=u.useCallback(()=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const j=s.filters??[];ve("filters","filter_cleared",j,null),L(s.id,{filters:void 0})},[s,be,L,ve]),Be=u.useCallback(j=>{if(!s)return;if(!ct("edit_filters",be)){S(dt("edit_filters"),"error");return}const E=s.filters??[];ve("filters","filter_cleared",E,j),L(s.id,{filters:j.length>0?j:void 0})},[s,be,L,ve]),Pe=u.useCallback(j=>{var Y;if(!s)return;const E=(Y=s.views)==null?void 0:Y.find(U=>U.id===j);if(!E)return;const _=E.snapshot.columnOrder,O=Hr(_,E.snapshot.grouping);L(s.id,{filters:E.snapshot.filters.length>0?[...E.snapshot.filters]:void 0,sortStack:E.snapshot.sortStack.length>0?[...E.snapshot.sortStack]:void 0,columnVisibility:{...E.snapshot.columnVisibility},columnOrder:O,columnWidths:{...E.snapshot.columnWidths},grouping:E.snapshot.grouping,activeViewId:j}),Ee(new Set),R(!1)},[s,L]),Vt=u.useCallback((j,E,_)=>{var xn;if(!(s!=null&&s.schema)||!he)return;const O=s.views??[],Y=O.filter(_o=>!_o.isDeleted).length,U=((xn=f.views)==null?void 0:xn.maxViews)??10;if(Y>=U){S(`View limit reached — you can have at most ${U} saved views. Delete an existing view to create a new one.`,"error");return}const pe={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:j,description:E||void 0,isDefault:_,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:ut,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...he}},ke=_?O.map(_o=>({..._o,isDefault:!1})):O;L(s.id,{views:[...ke,pe],activeViewId:pe.id}),S(`"${j}" view created`,"success")},[s,he,L]),st=u.useCallback(()=>{var E;if(!X||!he||X.isDefault||!s)return;const j=(E=s.views)==null?void 0:E.map(_=>_.id===X.id?{..._,snapshot:{...he}}:_);L(s.id,{views:j}),S(`"${X.name}" view updated`,"success")},[X,he,s,L]),Er=u.useCallback(j=>{var O;if(!X||!he||!s)return;const E=j??he.columnWidths,_=(O=s.views)==null?void 0:O.map(Y=>Y.id===X.id?{...Y,snapshot:{...Y.snapshot,columnVisibility:he.columnVisibility,columnOrder:he.columnOrder,columnWidths:E},updatedAt:Date.now()}:Y);L(s.id,{views:_,columnWidths:E}),S(`Column configuration saved to "${X.name}"`,"success")},[X,he,s,L]),Br=u.useCallback(j=>{var U,pe;if(!he||!s||!X)return;const E=j??he.columnWidths,_={...X,snapshot:{...X.snapshot,columnVisibility:he.columnVisibility,columnOrder:he.columnOrder,columnWidths:E},updatedAt:Date.now()},O=(U=s.views)==null?void 0:U.map(ke=>ke.id===X.id?_:{...ke,snapshot:{...ke.snapshot,columnVisibility:he.columnVisibility,columnOrder:he.columnOrder,columnWidths:E},updatedAt:Date.now()});L(s.id,{views:O,columnWidths:E});const Y=(((pe=s.views)==null?void 0:pe.length)||0)-1;S(`Column configuration saved to current view and ${Y} other view${Y===1?"":"s"}`,"success")},[he,s,X,L]),Dr=u.useCallback(()=>{H(!0)},[]),Or=u.useCallback(()=>{if(!X||!s)return;const j=X.snapshot.columnOrder,E=Hr(j,X.snapshot.grouping);L(s.id,{filters:X.snapshot.filters.length>0?[...X.snapshot.filters]:void 0,sortStack:X.snapshot.sortStack.length>0?[...X.snapshot.sortStack]:void 0,columnVisibility:{...X.snapshot.columnVisibility},columnOrder:E,columnWidths:{...X.snapshot.columnWidths},grouping:X.snapshot.grouping}),S("Changes reverted to last saved state","success")},[X,s,L]),Ar=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(O=>({...O,isDefault:O.id===j}));L(s.id,{views:E});const _=s.views.find(O=>O.id===j);_&&S(`"${_.name}" set as default view`,"success")},[s,L]),Mr=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(O=>O.id===j?{...O,isFavorite:!O.isFavorite,updatedAt:Date.now()}:O);L(s.id,{views:E});const _=s.views.find(O=>O.id===j);_&&!_.isFavorite?S(`"${_.name}" added to favorites`,"success"):_&&S(`"${_.name}" removed from favorites`,"info")},[s,L]),ar=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(U=>U.id===j?{...U,isDeleted:!0,updatedAt:Date.now()}:U),_=s.activeViewId===j,O=E.find(U=>U.isDefault&&!U.isDeleted);L(s.id,{views:E,activeViewId:_&&O?O.id:s.activeViewId,filters:_&&O?O.snapshot.filters.length>0?O.snapshot.filters:void 0:s.filters,sortStack:_&&O?O.snapshot.sortStack.length>0?O.snapshot.sortStack:void 0:s.sortStack});const Y=s.views.find(U=>U.id===j);Y&&S(`"${Y.name}" moved to Recently Deleted`,"info")},[s,L]),_r=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.map(O=>O.id===j?{...O,isDeleted:!1,updatedAt:Date.now()}:O);L(s.id,{views:E});const _=s.views.find(O=>O.id===j);_&&S(`"${_.name}" restored`,"success")},[s,L]),lr=u.useCallback(j=>{if(!(s!=null&&s.views))return;const E=s.views.find(ke=>ke.id===j),_=s.views.filter(ke=>!ke.isDeleted||ke.id===j);if((E==null?void 0:E.isDefault)&&_.filter(ke=>ke.isDefault).length===1){S("Cannot delete the last default view","error");return}const Y=s.views.filter(ke=>ke.id!==j),U=s.activeViewId===j,pe=Y.find(ke=>ke.isDefault&&!ke.isDeleted);L(s.id,{views:Y,activeViewId:U&&pe?pe.id:s.activeViewId,filters:U&&pe?pe.snapshot.filters.length>0?pe.snapshot.filters:void 0:s.filters,sortStack:U&&pe?pe.snapshot.sortStack.length>0?pe.snapshot.sortStack:void 0:s.sortStack}),E&&S(`"${E.name}" permanently deleted`,"success")},[s,L]),$r=u.useCallback(j=>{re(j),de(!0),R(!1)},[]),Dt=u.useCallback((j,E)=>{if(!q||!(s!=null&&s.views))return;const _=s.views.map(O=>O.id===q?{...O,name:j,description:E||void 0}:O);L(s.id,{views:_}),re(null)},[q,s,L]),_e=u.useCallback(j=>{le(j),te(!0),R(!1)},[]),at=u.useCallback(()=>{if(!Q||!(s!=null&&s.views))return;const j=s.views.filter(O=>O.id!==Q),E=s.activeViewId===Q,_=j.find(O=>O.isDefault);L(s.id,{views:j,activeViewId:E&&_?_.id:s.activeViewId,filters:E&&_?_.snapshot.filters.length>0?_.snapshot.filters:void 0:s.filters,sortStack:E&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:s.sortStack}),le(null),te(!1)},[Q,s,L]),Ot=u.useCallback(j=>{var Y;if(!(s!=null&&s.views))return;if(!(((Y=f.views)==null?void 0:Y.isAdmin)??!1)){S("Only administrators can promote views to Global.","error");return}const _=s.views.find(U=>U.id===j);if(!_)return;if(_.scope==="global"){S(`"${_.name}" is already a Global View.`,"info");return}const O=s.views.map(U=>U.id===j?{...U,scope:"global",isDefault:!0,updatedAt:Date.now()}:U.scope==="global"&&U.isDefault?{...U,isDefault:!1}:U);L(s.id,{views:O}),S(`"${_.name}" promoted to Global View and set as default.`,"success")},[s,f,L]);u.useEffect(()=>{Oe!=null&&Oe.resetPage?Oe.resetPage():nt(1)},[s==null?void 0:s.filters,$t,s==null?void 0:s.activeViewId]),u.useEffect(()=>{Oe&&Oe.currentPage!==mt&&nt(Oe.currentPage)},[Oe==null?void 0:Oe.currentPage]);const Rr=u.useCallback(j=>{Oe!=null&&Oe.goToPage&&Oe.goToPage(j),nt(j)},[Oe]),jt=u.useCallback(j=>{const E=(mt-1)*tt,_=Math.floor(E/j)+1;Ge(j),nt(_)},[mt,tt]),cr=u.useCallback((j,E)=>{if(!s)return;if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}const O={...s.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{},[j]:E};L(s.id,{columnVisibility:O})},[s,X,be,L]),Ht=u.useCallback(j=>{if(s){if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}L(s.id,{columnOrder:j})}},[s,be,L]),Ut=u.useCallback((j,E)=>{if(!s)return;if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}const O={...s.columnWidths||(X==null?void 0:X.snapshot.columnWidths)||{},[j]:E};L(s.id,{columnWidths:O})},[s,X,be,L]),I=u.useCallback(j=>{if(!s)return;const _=(s.filters??[]).filter(O=>O.column!==j);L(s.id,{filters:_.length>0?_:void 0})},[s,L]),F=u.useCallback(()=>{if(!X||!(s!=null&&s.schema))return;const j={},E=[],_={};s.schema.forEach(O=>{j[O.name]=!0,E.push(O.name),_[O.name]=170}),L(s.id,{columnVisibility:j,columnOrder:E,columnWidths:_,filters:void 0,sortStack:void 0}),S("Reset to default layout - all filters and sorts cleared","success")},[X,s,L]),ie=u.useCallback(Da(j=>{ot(j)},300),[]),we=u.useCallback(j=>{ie(j)},[ie]),ae=u.useCallback(j=>{if(!j.trim()||!s)return;const E=s.searchHistory||[],_=la(E,j);L(s.id,{searchHistory:_})},[s,L]),lt=u.useCallback(j=>{if(!s)return;const E=s.searchHistory||[],_=ca(E,j);L(s.id,{searchHistory:_})},[s,L]),Mo=u.useCallback(j=>{if(!s)return;const E=s.searchHistory||[],_=da(E,j);L(s.id,{searchHistory:_})},[s,L]),Wr=u.useCallback(j=>{const E=j==null?void 0:j.__urm_row_id__;Ee(_=>{const O=new Set(_);if(E!==void 0){const Y=Array.from(O).find(U=>(U==null?void 0:U.__urm_row_id__)===E);Y!==void 0?O.delete(Y):O.add(j)}else{const Y=JSON.stringify(j),U=Array.from(O).find(pe=>JSON.stringify(pe)===Y);U!==void 0?O.delete(U):O.add(j)}return O})},[]),rs=u.useCallback((j,E)=>{Ee(_=>{const O=new Set(_);for(const Y of E)j?O.add(Y):O.delete(Y);return O})},[]),os=u.useCallback((j,E,_)=>{Ee(O=>{const Y=new Set(O),U=Math.min(j,E),pe=Math.max(j,E);for(let ke=U;ke<=pe;ke++)_[ke]!==void 0&&Y.add(_[ke]);return Y})},[]),ns=u.useCallback(()=>{Ee(new Set)},[]),is=u.useCallback(j=>{const E=j==null?void 0:j.__urm_row_id__;Ee(_=>{const O=new Set(_);if(E!==void 0){const Y=Array.from(O).find(U=>(U==null?void 0:U.__urm_row_id__)===E);Y!==void 0&&O.delete(Y)}else O.delete(j);return O})},[]),ss=u.useCallback(j=>{if(!(s!=null&&s.uploadedData))return;const E=s.uploadedData.indexOf(j);if(E===-1)return;const _=s.favoriteRowIndices||[],Y=_.includes(E)?_.filter(U=>U!==E):[..._,E];L(s.id,{favoriteRowIndices:Y})},[s,L]),as=u.useCallback((j,E)=>{if(!(s!=null&&s.uploadedData))return;const _=s.favoriteRowIndices||[],O=j.map(U=>s.uploadedData.indexOf(U)).filter(U=>U!==-1),Y=E?[..._,...O.filter(U=>!_.includes(U))]:_.filter(U=>!O.includes(U));L(s.id,{favoriteRowIndices:Y})},[s,L]),ls=u.useCallback(()=>{if(!s)return;const j=s.favoriteRowIndices||[],E=!s.showFavoritesOnly;if(E&&j.length===0){S("No rows marked as favorite","warning");return}if(L(s.id,{showFavoritesOnly:E}),E&&Le.size>0){const _=new Set(j.map(Y=>{var U,pe;return(pe=(U=s.uploadedData)==null?void 0:U[Y])==null?void 0:pe.__urm_row_id__}).filter(Y=>Y!==void 0)),O=new Set(Array.from(Le).filter(Y=>(Y==null?void 0:Y.__urm_row_id__)!==void 0&&_.has(Y.__urm_row_id__)));Ee(O)}S(E?`Showing ${j.length} favorite row${j.length===1?"":"s"}`:"Showing all data","info")},[s,L,Le]),cs=u.useCallback(j=>{if(s){if(!ct("edit_columns",be)){S(dt("edit_columns"),"error");return}if(j&&s.schema){const{validGrouping:E,invalidColumns:_}=Ti(j,s.schema);_.length>0&&S(`Removed invalid grouping columns: ${_.join(", ")}`,"warning"),rt();try{const O=s.grouping;E===null?ve("grouping","group_cleared",O,null):O?ve("grouping","group_reordered",O,E):ve("grouping","group_level_added",null,E);const Y=(X==null?void 0:X.snapshot.columnOrder)||s.columnOrder||[],U=Hr(Y,E);L(s.id,{grouping:E,columnOrder:U}),JSON.stringify(U)!==JSON.stringify(s.columnOrder)&&ve("columns","column_reordered",s.columnOrder,U),et(!1)}catch(O){const Y=wt("processing","grouping",O);Fe(Y)}}else{const E=s.grouping;ve("grouping","group_cleared",E,null);const _=(X==null?void 0:X.snapshot.columnOrder)||s.columnOrder||[];L(s.id,{grouping:j,columnOrder:[..._]}),JSON.stringify(_)!==JSON.stringify(s.columnOrder)&&ve("columns","column_reordered",s.columnOrder,_),et(!1)}}},[s,X,be,L,rt,Fe,ve]),ds=u.useCallback(j=>{if(!s)return;const E=s.grouping;if(!E)return;const _=ea(E,j);L(s.id,{grouping:_})},[s,L]),us=u.useCallback(()=>{it(!0)},[]),dr=u.useCallback(j=>{s!=null&&s.schema&&(N(!0),setTimeout(()=>{try{let E;j.scope==="visible"?E=Nt:E=s.uploadedData||[];let _;j.columnScope==="all"?(_={},s.schema.forEach(ke=>{_[ke.name]=!0})):_=s.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{};const O=s.columnOrder||(X==null?void 0:X.snapshot.columnOrder),Y=po(E,s.schema,s.filters??[],s.sortStack??[],X,_,O),U=s.name;let pe;switch(j.format){case"csv":xo(Y,U,j),pe="export_csv";break;case"excel":mo(Y,U,j),pe="export_excel";break;case"json":fo(Y,U,j),pe="export_json";break}ve("export",pe,null,{format:j.format,scope:j.scope,columnScope:j.columnScope,rowCount:E.length,viewName:(X==null?void 0:X.name)||"Default View"}),S(`Export completed successfully (${j.format.toUpperCase()})`,"success")}catch(E){const _=Pa(E,{onRetry:()=>dr(j)});S(`Export failed: ${_.message}`,{action:{label:"Retry",onClick:()=>dr(j)}});const O=Cn(s.id,ut,_,s.auditHistory||[]);L(s.id,{auditHistory:O}),qt.error("urm:report-engine","Export failed",E)}finally{N(!1)}},500))},[s,X,Nt,L,ve]),ps=u.useCallback(j=>{if(s!=null&&s.schema){if(yt&&X&&!X.isDefault){fe(j.format),ce(!0),it(!1);return}dr(j),it(!1)}},[s,X,yt,dr]),Zr=u.useCallback(j=>{dr({format:j,scope:"visible",columnScope:"visible"})},[dr]),xs=u.useCallback(()=>{se&&Zr(se),ce(!1),fe(null)},[se,Zr]),ms=u.useCallback(()=>{st(),se&&Zr(se),ce(!1),fe(null)},[st,se,Zr]),fs=u.useCallback(()=>{ce(!1),fe(null)},[]),hs=u.useCallback(j=>{!(s!=null&&s.schema)||Le.size===0||(N(!0),setTimeout(()=>{try{const E=Array.from(Le),_=po(E,s.schema,s.filters??[],s.sortStack??[],X),O=`${s.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(j){case"csv":xo(_,O);break;case"excel":mo(_,O);break;case"json":fo(_,O);break}S(`Exported ${E.length} selected rows`,"info")}catch(E){S("Export failed. Please try again.","error"),qt.error("urm:report-engine","Bulk export failed",E)}finally{N(!1)}},500))},[s,X,Le,Et]),gs=u.useCallback((j,E)=>{if(s)try{const _=Ca(s),O=wa(j,E,ut,_),Y=ka(s.presets,O);L(s.id,{presets:Y}),ve("presets","preset_created",null,{presetId:O.id,name:O.name}),Je(!1),S(`Preset "${j}" saved successfully`,"success")}catch(_){S(_ instanceof Error?_.message:"Failed to create preset","error")}},[s,L,ve]),ys=u.useCallback(()=>{zt(null),S("Exited preset view","info")},[]),bs=u.useCallback(()=>{tr(!0)},[]),vs=u.useCallback((j,E)=>{if(!s)return;const _=Ta(s.presets,j);L(s.id,{presets:_}),ve("presets","preset_deleted",{presetId:j,name:E},null),ht===j&&zt(null),S(`Preset "${E}" deleted`,"success")},[s,ht,L,ve]);u.useEffect(()=>{if(!d||p.length===0)return;const j=p.find(E=>E.id===d);j&&j.id!==b&&m(j.id)},[d,p,b]),u.useEffect(()=>{if(!s)return;const j=Ia();if(j&&s.presets&&s.schemaLocked&&s.schema){const E=jn(s.presets,j);if(E){const{sanitizedConfig:_,warnings:O}=Wa(E.config,s.schema);O.length>0&&O.forEach(U=>S(U,"warning"));const Y=za(_);L(s.id,Y),zt(j),ve("presets","preset_applied",null,{presetId:E.id,name:E.name}),S(`Loaded preset: ${E.name}`,"info")}else S("Preset not found","info")}},[s==null?void 0:s.schemaLocked]);const Ss=ht?jn(s==null?void 0:s.presets,ht):void 0;u.useEffect(()=>{s!=null&&s.views&&s.views.length>0&&s.activeViewId&&ia(s.id,{views:s.views,activeViewId:s.activeViewId})},[s==null?void 0:s.views,s==null?void 0:s.activeViewId,s==null?void 0:s.id]),u.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const j=sa(s.id);if(j&&j.views.length>0){const E=j.views.find(_=>_.id===j.activeViewId);if(E)L(s.id,{views:j.views,activeViewId:j.activeViewId,filters:E.snapshot.filters.length>0?E.snapshot.filters:void 0,sortStack:E.snapshot.sortStack.length>0?E.snapshot.sortStack:void 0});else{const _=j.views.find(O=>O.isDefault)||$o(s.schema);L(s.id,{views:j.views,activeViewId:_.id,filters:_.snapshot.filters.length>0?_.snapshot.filters:void 0,sortStack:_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0})}}}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id]);const js=u.useCallback(j=>{var O;const E=(s==null?void 0:s.filters)??[],_=((O=f.filter)==null?void 0:O.maxConditions)??3;if(E.length>=_){S(`Filter limit reached — maximum ${_} filters allowed. Remove an existing filter before adding a new one.`,"warning");return}V(j),G(!0)},[s,f,S]),Cs=u.useCallback(()=>{G(!1),V(void 0)},[]),ws=(un=s==null?void 0:s.views)==null?void 0:un.find(j=>j.id===q),ks=(pn=s==null?void 0:s.views)==null?void 0:pn.find(j=>j.id===Q);return{reports:p,activeReport:s,activeReportId:b,setActiveReportId:m,isModalOpen:g,setIsModalOpen:z,createReport:Xe,updateReport:L,uploadState:M,handleFileUpload:Tr,handleUploadError:bt,handleRetry:We,handleConfirm:nr,paginatedData:Pt,processedData:Nt,displayData:Et,tableMetrics:kr,isGrouped:Lt,tableEngine:gt,activeView:X,isDirty:yt,currentTableState:he,viewChanges:Se,filters:s==null?void 0:s.filters,showFilterPanel:$,setShowFilterPanel:G,filterFocusColumn:A,handleAddFilter:Bt,handleUpdateFilter:Ft,handleRemoveFilter:St,handleClearAllFilters:sr,handleReplaceFilters:Be,handleOpenFilterForColumn:js,handleCloseFilterPanel:Cs,handleClearFiltersForColumn:I,sortStack:s==null?void 0:s.sortStack,showSortPanel:Z,setShowSortPanel:ee,handleSort:Ir,handleUpdateSortStack:ir,handleSortAscending:vt,handleSortDescending:zr,views:s==null?void 0:s.views,showManageViews:h,setShowManageViews:R,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:K,setShowEditViewModal:de,showDeleteConfirmation:ue,setShowDeleteConfirmation:te,editingView:ws,deletingView:ks,editingViewId:q,deletingViewId:Q,handleSelectView:Pe,handleCreateView:Vt,handleUpdateCurrentView:st,handleSaveColumnConfigToCurrentView:Er,handleSaveColumnConfigToAllViews:Br,handleSaveAsNewView:Dr,handleRevertChanges:Or,handleToggleDefault:Ar,handleToggleFavorite:Mr,handleSoftDelete:ar,handleRestoreView:_r,handlePermanentDelete:lr,handleEditView:$r,handleSaveEditView:Dt,handleDeleteView:_e,handleConfirmDelete:at,handlePromoteToGlobal:Ot,showManageColumns:J,setShowManageColumns:Me,columnVisibility:s==null?void 0:s.columnVisibility,columnOrder:s==null?void 0:s.columnOrder,columnWidths:s==null?void 0:s.columnWidths,handleUpdateColumnVisibility:cr,handleUpdateColumnOrder:Ht,handleUpdateColumnWidth:Ut,handleResetColumnLayout:F,showGroupPanel:Ne,setShowGroupPanel:et,grouping:s==null?void 0:s.grouping,groupingState:Qt,handleGroup:cs,handleToggleGroupCollapse:ds,searchQuery:$t,searchHistory:ua((s==null?void 0:s.searchHistory)||[]),handleSearchChange:we,handleAddToSearchHistory:ae,handleToggleSearchFavourite:lt,handleDeleteSearchHistory:Mo,selectedRowIds:Le,handleToggleRowSelection:Wr,handleToggleAllRows:rs,handleRangeSelection:os,handleClearSelection:ns,handleUpdateSelectionAfterDelete:is,favoriteRowIndices:(s==null?void 0:s.favoriteRowIndices)||[],resolvedFavoritesSet:Wt,showFavoritesOnly:(s==null?void 0:s.showFavoritesOnly)||!1,handleToggleRowFavorite:ss,handleBulkSetFavorites:as,handleToggleFavoritesFilter:ls,currentPage:mt,pageSize:tt,paginationEngine:Oe,handlePageChange:Rr,handlePageSizeChange:jt,isExporting:oe,showExportModal:rr,setShowExportModal:it,showDirtyExportWarning:ne,handleExport:us,handleExportWithConfig:ps,handleExportSelected:hs,handleExportAnyway:xs,handleSaveAndExport:ms,handleCancelExport:fs,showAuditHistory:ft,setShowAuditHistory:er,auditHistory:s==null?void 0:s.auditHistory,showCreatePreset:qe,setShowCreatePreset:Je,showManagePresets:$e,setShowManagePresets:tr,activePreset:Ss,activePresetId:ht,handleOpenManagePresets:bs,handleCreatePreset:gs,handleClearActivePreset:ys,handleDeletePresetById:vs,userRole:be,isViewerRole:Cr,currentUserId:ut,featureLimitWarning:vr,setFeatureLimitWarning:Rt,datasetMeta:or,reportError:Sr,setReportError:jr,handleError:Fe,schema:s==null?void 0:s.schema,hasSchemaConflicts:s!=null&&s.schema?Ys(s.schema):!1,snack:v,handleSnackClose:T,showSnack:S}}const Ii=u.createContext(void 0);function en(t){const{children:o,initialData:n,data:i,reportName:a,dataSource:c,mode:d="builder",autoLoad:l=!0,config:p,devConfig:x,showDevPanel:f=!1,sharedReportId:b}=t,g=el({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:a,sharedReportId:b,config:p}),[z,y]=u.useState(()=>zs()),C=(()=>{const T=Bs(z,x,!!x);return{...T,display:{...T.display,showDevPanel:f||T.display.showDevPanel}}})(),v=u.useCallback(S=>{y(S),Es(S)},[]),k={...g,activeDevConfig:C,handleDevConfigChange:v};return e.jsx(mi.Provider,{value:C,children:e.jsx(Ii.Provider,{value:k,children:o})})}function bo(){const t=u.useContext(Ii);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function tl({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const a=o.find(c=>c.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(w.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",color:"text.primary",letterSpacing:"-0.01em",cursor:o.length>0&&a?"pointer":"default","&:hover":o.length>0&&a?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),a&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(a.id),children:a.name}),e.jsx(r.Tooltip,{title:a.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(w.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:e.jsx(r.Button,{variant:"contained",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Jt(t,...o){const n=new URL(`https://mui.com/production-error/?code=${t}`);return o.forEach(i=>n.searchParams.append("args[]",i)),`Minified MUI error #${t}; visit ${n} for the full message.`}const rl="$$material";function ol(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ro={exports:{}},oo={exports:{}},xe={};/** @license React v16.13.1
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 bn;function Qa(){if(bn)return xe;bn=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,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,h=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,z=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,y=t?Symbol.for("react.scope"):60119;function T(k){if(typeof k=="object"&&k!==null){var D=k.$$typeof;switch(D){case o:switch(k=k.type,k){case u:case m:case i:case c:case s:case b:return k;default:switch(k=k&&k.$$typeof,k){case l:case f:case z:case g:case d:return k;default:return D}}case n:return D}}}function a(k){return T(k)===m}return xe.AsyncMode=u,xe.ConcurrentMode=m,xe.ContextConsumer=l,xe.ContextProvider=d,xe.Element=o,xe.ForwardRef=f,xe.Fragment=i,xe.Lazy=z,xe.Memo=g,xe.Portal=n,xe.Profiler=c,xe.StrictMode=s,xe.Suspense=b,xe.isAsyncMode=function(k){return a(k)||T(k)===u},xe.isConcurrentMode=a,xe.isContextConsumer=function(k){return T(k)===l},xe.isContextProvider=function(k){return T(k)===d},xe.isElement=function(k){return typeof k=="object"&&k!==null&&k.$$typeof===o},xe.isForwardRef=function(k){return T(k)===f},xe.isFragment=function(k){return T(k)===i},xe.isLazy=function(k){return T(k)===z},xe.isMemo=function(k){return T(k)===g},xe.isPortal=function(k){return T(k)===n},xe.isProfiler=function(k){return T(k)===c},xe.isStrictMode=function(k){return T(k)===s},xe.isSuspense=function(k){return T(k)===b},xe.isValidElementType=function(k){return typeof k=="string"||typeof k=="function"||k===i||k===m||k===c||k===s||k===b||k===h||typeof k=="object"&&k!==null&&(k.$$typeof===z||k.$$typeof===g||k.$$typeof===d||k.$$typeof===l||k.$$typeof===f||k.$$typeof===j||k.$$typeof===S||k.$$typeof===y||k.$$typeof===v)},xe.typeOf=T,xe}var me={};/** @license React v16.13.1
10
+ */var kn;function nl(){if(kn)return xe;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,a=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,p=t?Symbol.for("react.async_mode"):60111,x=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,m=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,z=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,C=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,k=t?Symbol.for("react.scope"):60119;function S(s){if(typeof s=="object"&&s!==null){var M=s.$$typeof;switch(M){case o:switch(s=s.type,s){case p:case x:case i:case c:case a:case b:return s;default:switch(s=s&&s.$$typeof,s){case l:case f:case z:case g:case d:return s;default:return M}}case n:return M}}}function T(s){return S(s)===x}return xe.AsyncMode=p,xe.ConcurrentMode=x,xe.ContextConsumer=l,xe.ContextProvider=d,xe.Element=o,xe.ForwardRef=f,xe.Fragment=i,xe.Lazy=z,xe.Memo=g,xe.Portal=n,xe.Profiler=c,xe.StrictMode=a,xe.Suspense=b,xe.isAsyncMode=function(s){return T(s)||S(s)===p},xe.isConcurrentMode=T,xe.isContextConsumer=function(s){return S(s)===l},xe.isContextProvider=function(s){return S(s)===d},xe.isElement=function(s){return typeof s=="object"&&s!==null&&s.$$typeof===o},xe.isForwardRef=function(s){return S(s)===f},xe.isFragment=function(s){return S(s)===i},xe.isLazy=function(s){return S(s)===z},xe.isMemo=function(s){return S(s)===g},xe.isPortal=function(s){return S(s)===n},xe.isProfiler=function(s){return S(s)===c},xe.isStrictMode=function(s){return S(s)===a},xe.isSuspense=function(s){return S(s)===b},xe.isValidElementType=function(s){return typeof s=="string"||typeof s=="function"||s===i||s===x||s===c||s===a||s===b||s===m||typeof s=="object"&&s!==null&&(s.$$typeof===z||s.$$typeof===g||s.$$typeof===d||s.$$typeof===l||s.$$typeof===f||s.$$typeof===C||s.$$typeof===v||s.$$typeof===k||s.$$typeof===y)},xe.typeOf=S,xe}var me={};/** @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 vn;function el(){return vn||(vn=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,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,h=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,z=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,y=t?Symbol.for("react.scope"):60119;function T(Y){return typeof Y=="string"||typeof Y=="function"||Y===i||Y===m||Y===c||Y===s||Y===b||Y===h||typeof Y=="object"&&Y!==null&&(Y.$$typeof===z||Y.$$typeof===g||Y.$$typeof===d||Y.$$typeof===l||Y.$$typeof===f||Y.$$typeof===j||Y.$$typeof===S||Y.$$typeof===y||Y.$$typeof===v)}function a(Y){if(typeof Y=="object"&&Y!==null){var Oe=Y.$$typeof;switch(Oe){case o:var Ae=Y.type;switch(Ae){case u:case m:case i:case c:case s:case b:return Ae;default:var dt=Ae&&Ae.$$typeof;switch(dt){case l:case f:case z:case g:case d:return dt;default:return Oe}}case n:return Oe}}}var k=u,D=m,O=l,R=d,U=o,J=f,ee=i,x=z,N=g,_=n,H=c,q=s,de=b,ue=!1;function re(Y){return ue||(ue=!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.")),M(Y)||a(Y)===u}function M(Y){return a(Y)===m}function L(Y){return a(Y)===l}function G(Y){return a(Y)===d}function oe(Y){return typeof Y=="object"&&Y!==null&&Y.$$typeof===o}function Q(Y){return a(Y)===f}function le(Y){return a(Y)===i}function ne(Y){return a(Y)===z}function P(Y){return a(Y)===g}function te(Y){return a(Y)===n}function ie(Y){return a(Y)===c}function se(Y){return a(Y)===s}function je(Y){return a(Y)===b}me.AsyncMode=k,me.ConcurrentMode=D,me.ContextConsumer=O,me.ContextProvider=R,me.Element=U,me.ForwardRef=J,me.Fragment=ee,me.Lazy=x,me.Memo=N,me.Portal=_,me.Profiler=H,me.StrictMode=q,me.Suspense=de,me.isAsyncMode=re,me.isConcurrentMode=M,me.isContextConsumer=L,me.isContextProvider=G,me.isElement=oe,me.isForwardRef=Q,me.isFragment=le,me.isLazy=ne,me.isMemo=P,me.isPortal=te,me.isProfiler=ie,me.isStrictMode=se,me.isSuspense=je,me.isValidElementType=T,me.typeOf=a})()),me}var Sn;function Si(){return Sn||(Sn=1,process.env.NODE_ENV==="production"?eo.exports=Qa():eo.exports=el()),eo.exports}/*
17
+ */var Tn;function il(){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,a=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,p=t?Symbol.for("react.async_mode"):60111,x=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,m=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,z=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,C=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===x||J===c||J===a||J===b||J===m||typeof J=="object"&&J!==null&&(J.$$typeof===z||J.$$typeof===g||J.$$typeof===d||J.$$typeof===l||J.$$typeof===f||J.$$typeof===C||J.$$typeof===v||J.$$typeof===k||J.$$typeof===y)}function T(J){if(typeof J=="object"&&J!==null){var Me=J.$$typeof;switch(Me){case o:var Ne=J.type;switch(Ne){case p:case x:case i:case c:case a:case b:return Ne;default:var et=Ne&&Ne.$$typeof;switch(et){case l:case f:case z:case g:case d:return et;default:return Me}}case n:return Me}}}var s=p,M=x,B=l,$=d,G=o,Z=f,ee=i,h=z,R=g,W=n,H=c,K=a,de=b,ue=!1;function te(J){return ue||(ue=!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)===x}function V(J){return T(J)===l}function q(J){return T(J)===d}function re(J){return typeof J=="object"&&J!==null&&J.$$typeof===o}function Q(J){return T(J)===f}function le(J){return T(J)===i}function oe(J){return T(J)===z}function N(J){return T(J)===g}function ne(J){return T(J)===n}function ce(J){return T(J)===c}function se(J){return T(J)===a}function fe(J){return T(J)===b}me.AsyncMode=s,me.ConcurrentMode=M,me.ContextConsumer=B,me.ContextProvider=$,me.Element=G,me.ForwardRef=Z,me.Fragment=ee,me.Lazy=h,me.Memo=R,me.Portal=W,me.Profiler=H,me.StrictMode=K,me.Suspense=de,me.isAsyncMode=te,me.isConcurrentMode=A,me.isContextConsumer=V,me.isContextProvider=q,me.isElement=re,me.isForwardRef=Q,me.isFragment=le,me.isLazy=oe,me.isMemo=N,me.isPortal=ne,me.isProfiler=ce,me.isStrictMode=se,me.isSuspense=fe,me.isValidElementType=S,me.typeOf=T})()),me}var In;function zi(){return In||(In=1,process.env.NODE_ENV==="production"?oo.exports=nl():oo.exports=il()),oo.exports}/*
18
18
  object-assign
19
19
  (c) Sindre Sorhus
20
20
  @license MIT
21
- */var Do,jn;function tl(){if(jn)return Do;jn=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(f){return d[f]});if(u.join("")!=="0123456789")return!1;var m={};return"abcdefghijklmnopqrst".split("").forEach(function(f){m[f]=f}),Object.keys(Object.assign({},m)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return Do=s()?Object.assign:function(c,d){for(var l,u=i(c),m,f=1;f<arguments.length;f++){l=Object(arguments[f]);for(var b in l)o.call(l,b)&&(u[b]=l[b]);if(t){m=t(l);for(var h=0;h<m.length;h++)n.call(l,m[h])&&(u[m[h]]=l[m[h]])}}return u},Do}var Oo,Cn;function Ko(){if(Cn)return Oo;Cn=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Oo=t,Oo}var Mo,wn;function ji(){return wn||(wn=1,Mo=Function.call.bind(Object.prototype.hasOwnProperty)),Mo}var Ao,kn;function rl(){if(kn)return Ao;kn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=Ko(),n={},i=ji();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 f in c)if(i(c,f)){var b;try{if(typeof c[f]!="function"){var h=Error((u||"React class")+": "+l+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof c[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}b=c[f](d,f,u,l,null,o)}catch(z){b=z}if(b&&!(b instanceof Error)&&t((u||"React class")+": type specification of "+l+" `"+f+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof b+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),b instanceof Error&&!(b.message in n)){n[b.message]=!0;var g=m?m():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Ao=s,Ao}var $o,Tn;function ol(){if(Tn)return $o;Tn=1;var t=Si(),o=tl(),n=Ko(),i=ji(),s=rl(),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 $o=function(l,u){var m=typeof Symbol=="function"&&Symbol.iterator,f="@@iterator";function b(M){var L=M&&(m&&M[m]||M[f]);if(typeof L=="function")return L}var h="<<anonymous>>",g={array:S("array"),bigint:S("bigint"),bool:S("boolean"),func:S("function"),number:S("number"),object:S("object"),string:S("string"),symbol:S("symbol"),any:y(),arrayOf:T,element:a(),elementType:k(),instanceOf:D,node:J(),objectOf:R,oneOf:O,oneOfType:U,shape:x,exact:N};function z(M,L){return M===L?M!==0||1/M===1/L:M!==M&&L!==L}function v(M,L){this.message=M,this.data=L&&typeof L=="object"?L:{},this.stack=""}v.prototype=Error.prototype;function j(M){if(process.env.NODE_ENV!=="production")var L={},G=0;function oe(le,ne,P,te,ie,se,je){if(te=te||h,se=se||P,je!==n){if(u){var Y=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 Y.name="Invariant Violation",Y}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var Oe=te+":"+P;!L[Oe]&&G<3&&(c("You are manually calling a React.PropTypes validation function for the `"+se+"` prop on `"+te+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),L[Oe]=!0,G++)}}return ne[P]==null?le?ne[P]===null?new v("The "+ie+" `"+se+"` is marked as required "+("in `"+te+"`, but its value is `null`.")):new v("The "+ie+" `"+se+"` is marked as required in "+("`"+te+"`, but its value is `undefined`.")):null:M(ne,P,te,ie,se)}var Q=oe.bind(null,!1);return Q.isRequired=oe.bind(null,!0),Q}function S(M){function L(G,oe,Q,le,ne,P){var te=G[oe],ie=q(te);if(ie!==M){var se=de(te);return new v("Invalid "+le+" `"+ne+"` of type "+("`"+se+"` supplied to `"+Q+"`, expected ")+("`"+M+"`."),{expectedType:M})}return null}return j(L)}function y(){return j(d)}function T(M){function L(G,oe,Q,le,ne){if(typeof M!="function")return new v("Property `"+ne+"` of component `"+Q+"` has invalid PropType notation inside arrayOf.");var P=G[oe];if(!Array.isArray(P)){var te=q(P);return new v("Invalid "+le+" `"+ne+"` of type "+("`"+te+"` supplied to `"+Q+"`, expected an array."))}for(var ie=0;ie<P.length;ie++){var se=M(P,ie,Q,le,ne+"["+ie+"]",n);if(se instanceof Error)return se}return null}return j(L)}function a(){function M(L,G,oe,Q,le){var ne=L[G];if(!l(ne)){var P=q(ne);return new v("Invalid "+Q+" `"+le+"` of type "+("`"+P+"` supplied to `"+oe+"`, expected a single ReactElement."))}return null}return j(M)}function k(){function M(L,G,oe,Q,le){var ne=L[G];if(!t.isValidElementType(ne)){var P=q(ne);return new v("Invalid "+Q+" `"+le+"` of type "+("`"+P+"` supplied to `"+oe+"`, expected a single ReactElement type."))}return null}return j(M)}function D(M){function L(G,oe,Q,le,ne){if(!(G[oe]instanceof M)){var P=M.name||h,te=re(G[oe]);return new v("Invalid "+le+" `"+ne+"` of type "+("`"+te+"` supplied to `"+Q+"`, expected ")+("instance of `"+P+"`."))}return null}return j(L)}function O(M){if(!Array.isArray(M))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 L(G,oe,Q,le,ne){for(var P=G[oe],te=0;te<M.length;te++)if(z(P,M[te]))return null;var ie=JSON.stringify(M,function(je,Y){var Oe=de(Y);return Oe==="symbol"?String(Y):Y});return new v("Invalid "+le+" `"+ne+"` of value `"+String(P)+"` "+("supplied to `"+Q+"`, expected one of "+ie+"."))}return j(L)}function R(M){function L(G,oe,Q,le,ne){if(typeof M!="function")return new v("Property `"+ne+"` of component `"+Q+"` has invalid PropType notation inside objectOf.");var P=G[oe],te=q(P);if(te!=="object")return new v("Invalid "+le+" `"+ne+"` of type "+("`"+te+"` supplied to `"+Q+"`, expected an object."));for(var ie in P)if(i(P,ie)){var se=M(P,ie,Q,le,ne+"."+ie,n);if(se instanceof Error)return se}return null}return j(L)}function U(M){if(!Array.isArray(M))return process.env.NODE_ENV!=="production"&&c("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var L=0;L<M.length;L++){var G=M[L];if(typeof G!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+ue(G)+" at index "+L+"."),d}function oe(Q,le,ne,P,te){for(var ie=[],se=0;se<M.length;se++){var je=M[se],Y=je(Q,le,ne,P,te,n);if(Y==null)return null;Y.data&&i(Y.data,"expectedType")&&ie.push(Y.data.expectedType)}var Oe=ie.length>0?", expected one of type ["+ie.join(", ")+"]":"";return new v("Invalid "+P+" `"+te+"` supplied to "+("`"+ne+"`"+Oe+"."))}return j(oe)}function J(){function M(L,G,oe,Q,le){return _(L[G])?null:new v("Invalid "+Q+" `"+le+"` supplied to "+("`"+oe+"`, expected a ReactNode."))}return j(M)}function ee(M,L,G,oe,Q){return new v((M||"React class")+": "+L+" type `"+G+"."+oe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+Q+"`.")}function x(M){function L(G,oe,Q,le,ne){var P=G[oe],te=q(P);if(te!=="object")return new v("Invalid "+le+" `"+ne+"` of type `"+te+"` "+("supplied to `"+Q+"`, expected `object`."));for(var ie in M){var se=M[ie];if(typeof se!="function")return ee(Q,le,ne,ie,de(se));var je=se(P,ie,Q,le,ne+"."+ie,n);if(je)return je}return null}return j(L)}function N(M){function L(G,oe,Q,le,ne){var P=G[oe],te=q(P);if(te!=="object")return new v("Invalid "+le+" `"+ne+"` of type `"+te+"` "+("supplied to `"+Q+"`, expected `object`."));var ie=o({},G[oe],M);for(var se in ie){var je=M[se];if(i(M,se)&&typeof je!="function")return ee(Q,le,ne,se,de(je));if(!je)return new v("Invalid "+le+" `"+ne+"` key `"+se+"` supplied to `"+Q+"`.\nBad object: "+JSON.stringify(G[oe],null," ")+`
22
- Valid keys: `+JSON.stringify(Object.keys(M),null," "));var Y=je(P,se,Q,le,ne+"."+se,n);if(Y)return Y}return null}return j(L)}function _(M){switch(typeof M){case"number":case"string":case"undefined":return!0;case"boolean":return!M;case"object":if(Array.isArray(M))return M.every(_);if(M===null||l(M))return!0;var L=b(M);if(L){var G=L.call(M),oe;if(L!==M.entries){for(;!(oe=G.next()).done;)if(!_(oe.value))return!1}else for(;!(oe=G.next()).done;){var Q=oe.value;if(Q&&!_(Q[1]))return!1}}else return!1;return!0;default:return!1}}function H(M,L){return M==="symbol"?!0:L?L["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&L instanceof Symbol:!1}function q(M){var L=typeof M;return Array.isArray(M)?"array":M instanceof RegExp?"object":H(L,M)?"symbol":L}function de(M){if(typeof M>"u"||M===null)return""+M;var L=q(M);if(L==="object"){if(M instanceof Date)return"date";if(M instanceof RegExp)return"regexp"}return L}function ue(M){var L=de(M);switch(L){case"array":case"object":return"an "+L;case"boolean":case"date":case"regexp":return"a "+L;default:return L}}function re(M){return!M.constructor||!M.constructor.name?h:M.constructor.name}return g.checkPropTypes=s,g.resetWarningCache=s.resetWarningCache,g.PropTypes=g,g},$o}var Ro,zn;function nl(){if(zn)return Ro;zn=1;var t=Ko();function o(){}function n(){}return n.resetWarningCache=o,Ro=function(){function i(d,l,u,m,f,b){if(b!==t){var h=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 h.name="Invariant Violation",h}}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},Ro}var In;function il(){if(In)return Qr.exports;if(In=1,process.env.NODE_ENV!=="production"){var t=Si(),o=!0;Qr.exports=ol()(t.isElement,o)}else Qr.exports=nl()();return Qr.exports}var sl=il();const _r=Za(sl);var to={exports:{}},ve={};/**
21
+ */var Wo,zn;function sl(){if(zn)return Wo;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 a(){try{if(!Object.assign)return!1;var c=new String("abc");if(c[5]="de",Object.getOwnPropertyNames(c)[0]==="5")return!1;for(var d={},l=0;l<10;l++)d["_"+String.fromCharCode(l)]=l;var p=Object.getOwnPropertyNames(d).map(function(f){return d[f]});if(p.join("")!=="0123456789")return!1;var x={};return"abcdefghijklmnopqrst".split("").forEach(function(f){x[f]=f}),Object.keys(Object.assign({},x)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return Wo=a()?Object.assign:function(c,d){for(var l,p=i(c),x,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){x=t(l);for(var m=0;m<x.length;m++)n.call(l,x[m])&&(p[x[m]]=l[x[m]])}}return p},Wo}var Po,En;function tn(){if(En)return Po;En=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Po=t,Po}var No,Bn;function Ei(){return Bn||(Bn=1,No=Function.call.bind(Object.prototype.hasOwnProperty)),No}var Lo,Dn;function al(){if(Dn)return Lo;Dn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=tn(),n={},i=Ei();t=function(c){var d="Warning: "+c;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function a(c,d,l,p,x){if(process.env.NODE_ENV!=="production"){for(var f in c)if(i(c,f)){var b;try{if(typeof c[f]!="function"){var m=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 m.name="Invariant Violation",m}b=c[f](d,f,p,l,null,o)}catch(z){b=z}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=x?x():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return a.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Lo=a,Lo}var Fo,On;function ll(){if(On)return Fo;On=1;var t=zi(),o=sl(),n=tn(),i=Ei(),a=al(),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 Fo=function(l,p){var x=typeof Symbol=="function"&&Symbol.iterator,f="@@iterator";function b(A){var V=A&&(x&&A[x]||A[f]);if(typeof V=="function")return V}var m="<<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:s(),instanceOf:M,node:Z(),objectOf:$,oneOf:B,oneOfType:G,shape:h,exact:R};function z(A,V){return A===V?A!==0||1/A===1/V:A!==A&&V!==V}function y(A,V){this.message=A,this.data=V&&typeof V=="object"?V:{},this.stack=""}y.prototype=Error.prototype;function C(A){if(process.env.NODE_ENV!=="production")var V={},q=0;function re(le,oe,N,ne,ce,se,fe){if(ne=ne||m,se=se||N,fe!==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 Me=ne+":"+N;!V[Me]&&q<3&&(c("You are manually calling a React.PropTypes validation function for the `"+se+"` 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."),V[Me]=!0,q++)}}return oe[N]==null?le?oe[N]===null?new y("The "+ce+" `"+se+"` is marked as required "+("in `"+ne+"`, but its value is `null`.")):new y("The "+ce+" `"+se+"` is marked as required in "+("`"+ne+"`, but its value is `undefined`.")):null:A(oe,N,ne,ce,se)}var Q=re.bind(null,!1);return Q.isRequired=re.bind(null,!0),Q}function v(A){function V(q,re,Q,le,oe,N){var ne=q[re],ce=K(ne);if(ce!==A){var se=de(ne);return new y("Invalid "+le+" `"+oe+"` of type "+("`"+se+"` supplied to `"+Q+"`, expected ")+("`"+A+"`."),{expectedType:A})}return null}return C(V)}function k(){return C(d)}function S(A){function V(q,re,Q,le,oe){if(typeof A!="function")return new y("Property `"+oe+"` of component `"+Q+"` has invalid PropType notation inside arrayOf.");var N=q[re];if(!Array.isArray(N)){var ne=K(N);return new y("Invalid "+le+" `"+oe+"` of type "+("`"+ne+"` supplied to `"+Q+"`, expected an array."))}for(var ce=0;ce<N.length;ce++){var se=A(N,ce,Q,le,oe+"["+ce+"]",n);if(se instanceof Error)return se}return null}return C(V)}function T(){function A(V,q,re,Q,le){var oe=V[q];if(!l(oe)){var N=K(oe);return new y("Invalid "+Q+" `"+le+"` of type "+("`"+N+"` supplied to `"+re+"`, expected a single ReactElement."))}return null}return C(A)}function s(){function A(V,q,re,Q,le){var oe=V[q];if(!t.isValidElementType(oe)){var N=K(oe);return new y("Invalid "+Q+" `"+le+"` of type "+("`"+N+"` supplied to `"+re+"`, expected a single ReactElement type."))}return null}return C(A)}function M(A){function V(q,re,Q,le,oe){if(!(q[re]instanceof A)){var N=A.name||m,ne=te(q[re]);return new y("Invalid "+le+" `"+oe+"` of type "+("`"+ne+"` supplied to `"+Q+"`, expected ")+("instance of `"+N+"`."))}return null}return C(V)}function B(A){if(!Array.isArray(A))return process.env.NODE_ENV!=="production"&&(arguments.length>1?c("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):c("Invalid argument supplied to oneOf, expected an array.")),d;function V(q,re,Q,le,oe){for(var N=q[re],ne=0;ne<A.length;ne++)if(z(N,A[ne]))return null;var ce=JSON.stringify(A,function(fe,J){var Me=de(J);return Me==="symbol"?String(J):J});return new y("Invalid "+le+" `"+oe+"` of value `"+String(N)+"` "+("supplied to `"+Q+"`, expected one of "+ce+"."))}return C(V)}function $(A){function V(q,re,Q,le,oe){if(typeof A!="function")return new y("Property `"+oe+"` of component `"+Q+"` has invalid PropType notation inside objectOf.");var N=q[re],ne=K(N);if(ne!=="object")return new y("Invalid "+le+" `"+oe+"` of type "+("`"+ne+"` supplied to `"+Q+"`, expected an object."));for(var ce in N)if(i(N,ce)){var se=A(N,ce,Q,le,oe+"."+ce,n);if(se instanceof Error)return se}return null}return C(V)}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 V=0;V<A.length;V++){var q=A[V];if(typeof q!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+ue(q)+" at index "+V+"."),d}function re(Q,le,oe,N,ne){for(var ce=[],se=0;se<A.length;se++){var fe=A[se],J=fe(Q,le,oe,N,ne,n);if(J==null)return null;J.data&&i(J.data,"expectedType")&&ce.push(J.data.expectedType)}var Me=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new y("Invalid "+N+" `"+ne+"` supplied to "+("`"+oe+"`"+Me+"."))}return C(re)}function Z(){function A(V,q,re,Q,le){return W(V[q])?null:new y("Invalid "+Q+" `"+le+"` supplied to "+("`"+re+"`, expected a ReactNode."))}return C(A)}function ee(A,V,q,re,Q){return new y((A||"React class")+": "+V+" type `"+q+"."+re+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+Q+"`.")}function h(A){function V(q,re,Q,le,oe){var N=q[re],ne=K(N);if(ne!=="object")return new y("Invalid "+le+" `"+oe+"` of type `"+ne+"` "+("supplied to `"+Q+"`, expected `object`."));for(var ce in A){var se=A[ce];if(typeof se!="function")return ee(Q,le,oe,ce,de(se));var fe=se(N,ce,Q,le,oe+"."+ce,n);if(fe)return fe}return null}return C(V)}function R(A){function V(q,re,Q,le,oe){var N=q[re],ne=K(N);if(ne!=="object")return new y("Invalid "+le+" `"+oe+"` of type `"+ne+"` "+("supplied to `"+Q+"`, expected `object`."));var ce=o({},q[re],A);for(var se in ce){var fe=A[se];if(i(A,se)&&typeof fe!="function")return ee(Q,le,oe,se,de(fe));if(!fe)return new y("Invalid "+le+" `"+oe+"` key `"+se+"` supplied to `"+Q+"`.\nBad object: "+JSON.stringify(q[re],null," ")+`
22
+ Valid keys: `+JSON.stringify(Object.keys(A),null," "));var J=fe(N,se,Q,le,oe+"."+se,n);if(J)return J}return null}return C(V)}function W(A){switch(typeof A){case"number":case"string":case"undefined":return!0;case"boolean":return!A;case"object":if(Array.isArray(A))return A.every(W);if(A===null||l(A))return!0;var V=b(A);if(V){var q=V.call(A),re;if(V!==A.entries){for(;!(re=q.next()).done;)if(!W(re.value))return!1}else for(;!(re=q.next()).done;){var Q=re.value;if(Q&&!W(Q[1]))return!1}}else return!1;return!0;default:return!1}}function H(A,V){return A==="symbol"?!0:V?V["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&V instanceof Symbol:!1}function K(A){var V=typeof A;return Array.isArray(A)?"array":A instanceof RegExp?"object":H(V,A)?"symbol":V}function de(A){if(typeof A>"u"||A===null)return""+A;var V=K(A);if(V==="object"){if(A instanceof Date)return"date";if(A instanceof RegExp)return"regexp"}return V}function ue(A){var V=de(A);switch(V){case"array":case"object":return"an "+V;case"boolean":case"date":case"regexp":return"a "+V;default:return V}}function te(A){return!A.constructor||!A.constructor.name?m:A.constructor.name}return g.checkPropTypes=a,g.resetWarningCache=a.resetWarningCache,g.PropTypes=g,g},Fo}var Vo,An;function cl(){if(An)return Vo;An=1;var t=tn();function o(){}function n(){}return n.resetWarningCache=o,Vo=function(){function i(d,l,p,x,f,b){if(b!==t){var m=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw m.name="Invariant Violation",m}}i.isRequired=i;function a(){return i}var c={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:a,element:i,elementType:i,instanceOf:a,node:i,objectOf:a,oneOf:a,oneOfType:a,shape:a,exact:a,checkPropTypes:n,resetWarningCache:o};return c.PropTypes=c,c},Vo}var Mn;function dl(){if(Mn)return ro.exports;if(Mn=1,process.env.NODE_ENV!=="production"){var t=zi(),o=!0;ro.exports=ll()(t.isElement,o)}else ro.exports=cl()();return ro.exports}var ul=dl();const Nr=ol(ul);var no={exports:{}},je={};/**
23
23
  * @license React
24
24
  * react-is.production.js
25
25
  *
@@ -27,7 +27,7 @@ Valid keys: `+JSON.stringify(Object.keys(M),null," "));var Y=je(P,se,Q,le,ne+".
27
27
  *
28
28
  * This source code is licensed under the MIT license found in the
29
29
  * LICENSE file in the root directory of this source tree.
30
- */var En;function al(){if(En)return ve;En=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"),f=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),h=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function z(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case t:switch(v=v.type,v){case n:case s:case i:case u:case m:case h:return v;default:switch(v=v&&v.$$typeof,v){case d:case l:case b:case f:return v;case c:return v;default:return j}}case o:return j}}}return ve.ContextConsumer=c,ve.ContextProvider=d,ve.Element=t,ve.ForwardRef=l,ve.Fragment=n,ve.Lazy=b,ve.Memo=f,ve.Portal=o,ve.Profiler=s,ve.StrictMode=i,ve.Suspense=u,ve.SuspenseList=m,ve.isContextConsumer=function(v){return z(v)===c},ve.isContextProvider=function(v){return z(v)===d},ve.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===t},ve.isForwardRef=function(v){return z(v)===l},ve.isFragment=function(v){return z(v)===n},ve.isLazy=function(v){return z(v)===b},ve.isMemo=function(v){return z(v)===f},ve.isPortal=function(v){return z(v)===o},ve.isProfiler=function(v){return z(v)===s},ve.isStrictMode=function(v){return z(v)===i},ve.isSuspense=function(v){return z(v)===u},ve.isSuspenseList=function(v){return z(v)===m},ve.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===n||v===s||v===i||v===u||v===m||typeof v=="object"&&v!==null&&(v.$$typeof===b||v.$$typeof===f||v.$$typeof===d||v.$$typeof===c||v.$$typeof===l||v.$$typeof===g||v.getModuleId!==void 0)},ve.typeOf=z,ve}var Se={};/**
30
+ */var _n;function pl(){if(_n)return je;_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"),a=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"),x=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),m=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function z(y){if(typeof y=="object"&&y!==null){var C=y.$$typeof;switch(C){case t:switch(y=y.type,y){case n:case a:case i:case p:case x:case m: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 C}}case o:return C}}}return je.ContextConsumer=c,je.ContextProvider=d,je.Element=t,je.ForwardRef=l,je.Fragment=n,je.Lazy=b,je.Memo=f,je.Portal=o,je.Profiler=a,je.StrictMode=i,je.Suspense=p,je.SuspenseList=x,je.isContextConsumer=function(y){return z(y)===c},je.isContextProvider=function(y){return z(y)===d},je.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},je.isForwardRef=function(y){return z(y)===l},je.isFragment=function(y){return z(y)===n},je.isLazy=function(y){return z(y)===b},je.isMemo=function(y){return z(y)===f},je.isPortal=function(y){return z(y)===o},je.isProfiler=function(y){return z(y)===a},je.isStrictMode=function(y){return z(y)===i},je.isSuspense=function(y){return z(y)===p},je.isSuspenseList=function(y){return z(y)===x},je.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===a||y===i||y===p||y===x||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)},je.typeOf=z,je}var Ce={};/**
31
31
  * @license React
32
32
  * react-is.development.js
33
33
  *
@@ -35,16 +35,16 @@ Valid keys: `+JSON.stringify(Object.keys(M),null," "));var Y=je(P,se,Q,le,ne+".
35
35
  *
36
36
  * This source code is licensed under the MIT license found in the
37
37
  * LICENSE file in the root directory of this source tree.
38
- */var Bn;function ll(){return Bn||(Bn=1,process.env.NODE_ENV!=="production"&&(function(){function t(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case o:switch(v=v.type,v){case i:case c:case s:case m:case f:case g:return v;default:switch(v=v&&v.$$typeof,v){case l:case u:case h:case b:return v;case d:return v;default:return j}}case n:return j}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),z=Symbol.for("react.client.reference");Se.ContextConsumer=d,Se.ContextProvider=l,Se.Element=o,Se.ForwardRef=u,Se.Fragment=i,Se.Lazy=h,Se.Memo=b,Se.Portal=n,Se.Profiler=c,Se.StrictMode=s,Se.Suspense=m,Se.SuspenseList=f,Se.isContextConsumer=function(v){return t(v)===d},Se.isContextProvider=function(v){return t(v)===l},Se.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===o},Se.isForwardRef=function(v){return t(v)===u},Se.isFragment=function(v){return t(v)===i},Se.isLazy=function(v){return t(v)===h},Se.isMemo=function(v){return t(v)===b},Se.isPortal=function(v){return t(v)===n},Se.isProfiler=function(v){return t(v)===c},Se.isStrictMode=function(v){return t(v)===s},Se.isSuspense=function(v){return t(v)===m},Se.isSuspenseList=function(v){return t(v)===f},Se.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===i||v===c||v===s||v===m||v===f||typeof v=="object"&&v!==null&&(v.$$typeof===h||v.$$typeof===b||v.$$typeof===l||v.$$typeof===d||v.$$typeof===u||v.$$typeof===z||v.getModuleId!==void 0)},Se.typeOf=t})()),Se}var Dn;function cl(){return Dn||(Dn=1,process.env.NODE_ENV==="production"?to.exports=al():to.exports=ll()),to.exports}var Ci=cl();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 wi(t){if(po.isValidElement(t)||Ci.isValidElementType(t)||!Bt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=wi(t[n])}),o}function He(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Bt(t)&&Bt(o)&&Object.keys(o).forEach(s=>{po.isValidElement(o[s])||Ci.isValidElementType(o[s])?i[s]=o[s]:Bt(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Bt(t[s])?i[s]=He(t[s],o[s],n):n.clone?i[s]=Bt(o[s])?wi(o[s]):o[s]:i[s]=o[s]}),i}const dl=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 ul(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=t,c=dl(o),d=Object.keys(c);function l(h){return`@media (min-width:${typeof o[h]=="number"?o[h]:h}${n})`}function u(h){return`@media (max-width:${(typeof o[h]=="number"?o[h]:h)-i/100}${n})`}function m(h,g){const z=d.indexOf(g);return`@media (min-width:${typeof o[h]=="number"?o[h]:h}${n}) and (max-width:${(z!==-1&&typeof o[d[z]]=="number"?o[d[z]]:g)-i/100}${n})`}function f(h){return d.indexOf(h)+1<d.length?m(h,d[d.indexOf(h)+1]):l(h)}function b(h){const g=d.indexOf(h);return g===0?l(d[1]):g===d.length-1?u(d[g]):m(h,d[d.indexOf(h)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:u,between:m,only:f,not:b,unit:n,...s}}function On(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 pl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function xl(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 ml(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 fl={borderRadius:4},Ot=process.env.NODE_ENV!=="production"?_r.oneOfType([_r.number,_r.string,_r.object,_r.array]):{};function Ur(t,o){return o?He(t,o,{clone:!1}):t}const fo={xs:0,sm:600,md:900,lg:1200,xl:1536},Mn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${fo[t]}px)`},hl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:fo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function Ct(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Mn;return o.reduce((d,l,u)=>(d[c.up(c.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Mn;return Object.keys(o).reduce((d,l)=>{if(pl(c.keys,l)){const u=xl(i.containerQueries?i:hl,l);u&&(d[u]=n(o[l],l))}else if(Object.keys(c.values||fo).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 gl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const c=t.up(s);return i[c]={},i},{}))||{}}function An(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function ki(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":Ut(7));return t.charAt(0).toUpperCase()+t.slice(1)}function ho(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 uo(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=ho(t,n)||i,o&&(s=o(s,i,t)),s}function Ee(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=ho(u,i)||{};return Ct(d,l,b=>{let h=uo(m,s,b);return b===h&&typeof b=="string"&&(h=uo(m,s,`${o}${b==="default"?"":ki(b)}`,b)),n===!1?h:{[n]:h}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Ot}:{},c.filterProps=[o],c}function yl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const bl={m:"margin",p:"padding"},vl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},$n={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},Sl=yl(t=>{if(t.length>2)if($n[t])t=$n[t];else return[t];const[o,n]=t.split(""),i=bl[o],s=vl[n]||"";return Array.isArray(s)?s.map(c=>i+c):[i+s]}),go=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],yo=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],jl=[...go,...yo];function Gr(t,o,n,i){const s=ho(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 $n;function xl(){return $n||($n=1,process.env.NODE_ENV!=="production"&&(function(){function t(y){if(typeof y=="object"&&y!==null){var C=y.$$typeof;switch(C){case o:switch(y=y.type,y){case i:case c:case a:case x:case f:case g:return y;default:switch(y=y&&y.$$typeof,y){case l:case p:case m:case b:return y;case d:return y;default:return C}}case n:return C}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),z=Symbol.for("react.client.reference");Ce.ContextConsumer=d,Ce.ContextProvider=l,Ce.Element=o,Ce.ForwardRef=p,Ce.Fragment=i,Ce.Lazy=m,Ce.Memo=b,Ce.Portal=n,Ce.Profiler=c,Ce.StrictMode=a,Ce.Suspense=x,Ce.SuspenseList=f,Ce.isContextConsumer=function(y){return t(y)===d},Ce.isContextProvider=function(y){return t(y)===l},Ce.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===o},Ce.isForwardRef=function(y){return t(y)===p},Ce.isFragment=function(y){return t(y)===i},Ce.isLazy=function(y){return t(y)===m},Ce.isMemo=function(y){return t(y)===b},Ce.isPortal=function(y){return t(y)===n},Ce.isProfiler=function(y){return t(y)===c},Ce.isStrictMode=function(y){return t(y)===a},Ce.isSuspense=function(y){return t(y)===x},Ce.isSuspenseList=function(y){return t(y)===f},Ce.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===i||y===c||y===a||y===x||y===f||typeof y=="object"&&y!==null&&(y.$$typeof===m||y.$$typeof===b||y.$$typeof===l||y.$$typeof===d||y.$$typeof===p||y.$$typeof===z||y.getModuleId!==void 0)},Ce.typeOf=t})()),Ce}var Rn;function ml(){return Rn||(Rn=1,process.env.NODE_ENV==="production"?no.exports=pl():no.exports=xl()),no.exports}var Bi=ml();function At(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 Di(t){if(go.isValidElement(t)||Bi.isValidElementType(t)||!At(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Di(t[n])}),o}function Ye(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return At(t)&&At(o)&&Object.keys(o).forEach(a=>{go.isValidElement(o[a])||Bi.isValidElementType(o[a])?i[a]=o[a]:At(o[a])&&Object.prototype.hasOwnProperty.call(t,a)&&At(t[a])?i[a]=Ye(t[a],o[a],n):n.clone?i[a]=At(o[a])?Di(o[a]):o[a]:i[a]=o[a]}),i}const fl=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 hl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...a}=t,c=fl(o),d=Object.keys(c);function l(m){return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n})`}function p(m){return`@media (max-width:${(typeof o[m]=="number"?o[m]:m)-i/100}${n})`}function x(m,g){const z=d.indexOf(g);return`@media (min-width:${typeof o[m]=="number"?o[m]:m}${n}) and (max-width:${(z!==-1&&typeof o[d[z]]=="number"?o[d[z]]:g)-i/100}${n})`}function f(m){return d.indexOf(m)+1<d.length?x(m,d[d.indexOf(m)+1]):l(m)}function b(m){const g=d.indexOf(m);return g===0?l(d[1]):g===d.length-1?p(d[g]):x(m,d[d.indexOf(m)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:p,between:x,only:f,not:b,unit:n,...a}}function Wn(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,a)=>{var d,l;const c=/min-width:\s*([0-9.]+)/;return+(((d=i.match(c))==null?void 0:d[1])||0)-+(((l=a.match(c))==null?void 0:l[1])||0)});return n.length?n.reduce((i,a)=>{const c=o[a];return delete i[a],i[a]=c,i},{...o}):o}function gl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function yl(t,o){const n=o.match(/^@([^/]+)?\/?(.+)?$/);if(!n){if(process.env.NODE_ENV!=="production")throw new Error(`MUI: The provided shorthand ${`(${o})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
39
+ For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,a]=n,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(a).up(c)}function bl(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={},a=c=>(n(i,c),i);return n(a),{...t,containerQueries:a}}const vl={borderRadius:4},_t=process.env.NODE_ENV!=="production"?Nr.oneOfType([Nr.number,Nr.string,Nr.object,Nr.array]):{};function qr(t,o){return o?Ye(t,o,{clone:!1}):t}const vo={xs:0,sm:600,md:900,lg:1200,xl:1536},Pn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${vo[t]}px)`},Sl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:vo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function Tt(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Pn;return o.reduce((d,l,p)=>(d[c.up(c.keys[p])]=n(o[p]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Pn;return Object.keys(o).reduce((d,l)=>{if(gl(c.keys,l)){const p=yl(i.containerQueries?i:Sl,l);p&&(d[p]=n(o[l],l))}else if(Object.keys(c.values||vo).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 jl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,a)=>{const c=t.up(a);return i[c]={},i},{}))||{}}function Nn(t,o){return t.reduce((n,i)=>{const a=n[i];return(!a||Object.keys(a).length===0)&&delete n[i],n},o)}function Oi(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":Jt(7));return t.charAt(0).toUpperCase()+t.slice(1)}function So(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((a,c)=>a&&a[c]?a[c]:null,t);if(i!=null)return i}return o.split(".").reduce((i,a)=>i&&i[a]!=null?i[a]:null,t)}function ho(t,o,n,i=n){let a;return typeof t=="function"?a=t(n):Array.isArray(t)?a=t[n]||i:a=So(t,n)||i,o&&(a=o(a,i,t)),a}function De(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:a}=t,c=d=>{if(d[o]==null)return null;const l=d[o],p=d.theme,x=So(p,i)||{};return Tt(d,l,b=>{let m=ho(x,a,b);return b===m&&typeof b=="string"&&(m=ho(x,a,`${o}${b==="default"?"":Oi(b)}`,b)),n===!1?m:{[n]:m}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:_t}:{},c.filterProps=[o],c}function Cl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const wl={m:"margin",p:"padding"},kl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Ln={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},Tl=Cl(t=>{if(t.length>2)if(Ln[t])t=Ln[t];else return[t];const[o,n]=t.split(""),i=wl[o],a=kl[n]||"";return Array.isArray(a)?a.map(c=>i+c):[i+a]}),jo=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],Co=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Il=[...jo,...Co];function Kr(t,o,n,i){const a=So(t,o,!0)??n;return typeof a=="number"||typeof a=="string"?c=>typeof c=="string"?c:(process.env.NODE_ENV!=="production"&&typeof c!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${c}.`),typeof a=="string"?a.startsWith("var(")&&c===0?0:a.startsWith("var(")&&c===1?a:`calc(${c} * ${a})`:a*c):Array.isArray(a)?c=>{if(typeof c=="string")return c;const d=Math.abs(c);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>a.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(a)}.`,`${d} > ${a.length-1}, you need to add the missing values.`].join(`
40
40
  `)):console.error([`MUI: The \`theme.${o}\` array type cannot be combined with non integer values.You should either use an integer value that can be used as index, or define the \`theme.${o}\` as a number.`].join(`
41
- `)));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 Xo(t){return Gr(t,"spacing",8,"spacing")}function qr(t,o){return typeof o=="string"||o==null?o:t(o)}function Cl(t,o){return n=>t.reduce((i,s)=>(i[s]=qr(o,n),i),{})}function wl(t,o,n,i){if(!o.includes(n))return null;const s=Sl(n),c=Cl(s,i),d=t[n];return Ct(t,d,c)}function Ti(t,o){const n=Xo(t.theme);return Object.keys(t).map(i=>wl(t,o,i,n)).reduce(Ur,{})}function ze(t){return Ti(t,go)}ze.propTypes=process.env.NODE_ENV!=="production"?go.reduce((t,o)=>(t[o]=Ot,t),{}):{};ze.filterProps=go;function Ie(t){return Ti(t,yo)}Ie.propTypes=process.env.NODE_ENV!=="production"?yo.reduce((t,o)=>(t[o]=Ot,t),{}):{};Ie.filterProps=yo;process.env.NODE_ENV!=="production"&&jl.reduce((t,o)=>(t[o]=Ot,t),{});function zi(t=8,o=Xo({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]?Ur(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 Ye(t){return typeof t!="number"?t:`${t}px solid`}function Ge(t,o){return Ee({prop:t,themeKey:"borders",transform:o})}const kl=Ge("border",Ye),Tl=Ge("borderTop",Ye),zl=Ge("borderRight",Ye),Il=Ge("borderBottom",Ye),El=Ge("borderLeft",Ye),Bl=Ge("borderColor"),Dl=Ge("borderTopColor"),Ol=Ge("borderRightColor"),Ml=Ge("borderBottomColor"),Al=Ge("borderLeftColor"),$l=Ge("outline",Ye),Rl=Ge("outlineColor"),vo=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=Gr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:qr(o,i)});return Ct(t,t.borderRadius,n)}return null};vo.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Ot}:{};vo.filterProps=["borderRadius"];bo(kl,Tl,zl,Il,El,Bl,Dl,Ol,Ml,Al,vo,$l,Rl);const So=t=>{if(t.gap!==void 0&&t.gap!==null){const o=Gr(t.theme,"spacing",8,"gap"),n=i=>({gap:qr(o,i)});return Ct(t,t.gap,n)}return null};So.propTypes=process.env.NODE_ENV!=="production"?{gap:Ot}:{};So.filterProps=["gap"];const jo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=Gr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:qr(o,i)});return Ct(t,t.columnGap,n)}return null};jo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Ot}:{};jo.filterProps=["columnGap"];const Co=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=Gr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:qr(o,i)});return Ct(t,t.rowGap,n)}return null};Co.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Ot}:{};Co.filterProps=["rowGap"];const _l=Ee({prop:"gridColumn"}),Wl=Ee({prop:"gridRow"}),Pl=Ee({prop:"gridAutoFlow"}),Nl=Ee({prop:"gridAutoColumns"}),Fl=Ee({prop:"gridAutoRows"}),Ll=Ee({prop:"gridTemplateColumns"}),Vl=Ee({prop:"gridTemplateRows"}),Hl=Ee({prop:"gridTemplateAreas"}),Ul=Ee({prop:"gridArea"});bo(So,jo,Co,_l,Wl,Pl,Nl,Fl,Ll,Vl,Hl,Ul);function gr(t,o){return o==="grey"?o:t}const Yl=Ee({prop:"color",themeKey:"palette",transform:gr}),Gl=Ee({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:gr}),ql=Ee({prop:"backgroundColor",themeKey:"palette",transform:gr});bo(Yl,Gl,ql);function Le(t){return t<=1&&t!==0?`${t*100}%`:t}const Jl=Ee({prop:"width",transform:Le}),Zo=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])||fo[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:Le(n)}};return Ct(t,t.maxWidth,o)}return null};Zo.filterProps=["maxWidth"];const Kl=Ee({prop:"minWidth",transform:Le}),Xl=Ee({prop:"height",transform:Le}),Zl=Ee({prop:"maxHeight",transform:Le}),Ql=Ee({prop:"minHeight",transform:Le});Ee({prop:"size",cssProperty:"width",transform:Le});Ee({prop:"size",cssProperty:"height",transform:Le});const ec=Ee({prop:"boxSizing"});bo(Jl,Zo,Kl,Xl,Zl,Ql,ec);const wo={border:{themeKey:"borders",transform:Ye},borderTop:{themeKey:"borders",transform:Ye},borderRight:{themeKey:"borders",transform:Ye},borderBottom:{themeKey:"borders",transform:Ye},borderLeft:{themeKey:"borders",transform:Ye},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Ye},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:vo},color:{themeKey:"palette",transform:gr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:gr},backgroundColor:{themeKey:"palette",transform:gr},p:{style:Ie},pt:{style:Ie},pr:{style:Ie},pb:{style:Ie},pl:{style:Ie},px:{style:Ie},py:{style:Ie},padding:{style:Ie},paddingTop:{style:Ie},paddingRight:{style:Ie},paddingBottom:{style:Ie},paddingLeft:{style:Ie},paddingX:{style:Ie},paddingY:{style:Ie},paddingInline:{style:Ie},paddingInlineStart:{style:Ie},paddingInlineEnd:{style:Ie},paddingBlock:{style:Ie},paddingBlockStart:{style:Ie},paddingBlockEnd:{style:Ie},m:{style:ze},mt:{style:ze},mr:{style:ze},mb:{style:ze},ml:{style:ze},mx:{style:ze},my:{style:ze},margin:{style:ze},marginTop:{style:ze},marginRight:{style:ze},marginBottom:{style:ze},marginLeft:{style:ze},marginX:{style:ze},marginY:{style:ze},marginInline:{style:ze},marginInlineStart:{style:ze},marginInlineEnd:{style:ze},marginBlock:{style:ze},marginBlockStart:{style:ze},marginBlockEnd:{style:ze},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:So},rowGap:{style:Co},columnGap:{style:jo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Le},maxWidth:{style:Zo},minWidth:{transform:Le},height:{transform:Le},maxHeight:{transform:Le},minHeight:{transform:Le},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 tc(...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 rc(t,o){return typeof t=="function"?t(o):t}function oc(){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:f,style:b}=l;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const h=ho(s,m)||{};return b?b(d):Ct(d,i,z=>{let v=uo(h,f,z);return z===v&&typeof z=="string"&&(v=uo(h,f,`${n}${z==="default"?"":ki(z)}`,z)),u===!1?v:{[u]:v}})}function o(n){const{sx:i,theme:s={},nested:c}=n||{};if(!i)return null;const d=s.unstable_sxConfig??wo;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 f=gl(s.breakpoints),b=Object.keys(f);let h=f;return Object.keys(m).forEach(g=>{const z=rc(m[g],s);if(z!=null)if(typeof z=="object")if(d[g])h=Ur(h,t(g,z,s,d));else{const v=Ct({theme:s},z,j=>({[g]:j}));tc(v,z)?h[g]=o({sx:z,theme:s,nested:!0}):h=Ur(h,v)}else h=Ur(h,t(g,z,s,d))}),!c&&s.modularCssLayers?{"@layer sx":On(s,An(b,h))}:On(s,An(b,h))}return Array.isArray(i)?i.map(l):l(i)}return o}const ko=oc();ko.filterProps=["sx"];function nc(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 Ii(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:c={},...d}=t,l=ul(n),u=zi(s);let m=He({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...fl,...c}},d);return m=ml(m),m.applyStyles=nc,m=o.reduce((f,b)=>He(f,b),m),m.unstable_sxConfig={...wo,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(b){return ko({sx:b,theme:this})},m}function ic(t){return Object.keys(t).length===0}function sc(t=null){const o=po.useContext(js.ThemeContext);return!o||ic(o)?t:o}const ac=Ii();function lc(t=ac){return sc(t)}const Rn=t=>t,cc=()=>{let t=Rn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Rn}}},dc=cc(),uc={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 pc(t,o,n="Mui"){const i=uc[o];return i?`${n}-${i}`:`${dc.generate(t)}-${o}`}function xc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function Qo(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}].`),xc(t,o,n)}function mc(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(mc(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().`:Ut(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.`:Ut(10,s))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:s}}const fc=t=>{const o=Dt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Lr=(t,o)=>{try{return fc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function To(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 Ei(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,f=(m+n/30)%12)=>s-c*Math.max(Math.min(f-3,9-f,1),-1);let l="rgb";const u=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return t.type==="hsla"&&(l+="a",u.push(o[3])),To({type:l,values:u})}function Fo(t){t=Dt(t);let o=t.type==="hsl"||t.type==="hsla"?Dt(Ei(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 _n(t,o){const n=Fo(t),i=Fo(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function E(t,o){return t=Dt(t),o=Qo(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,To(t)}function Lt(t,o,n){try{return E(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function zo(t,o){if(t=Dt(t),o=Qo(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 To(t)}function he(t,o,n){try{return zo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Io(t,o){if(t=Dt(t),o=Qo(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 To(t)}function ge(t,o,n){try{return Io(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function hc(t,o=.15){return Fo(t)>.5?zo(t,o):Io(t,o)}function ro(t,o,n){try{return hc(t,o)}catch{return t}}function gc(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 Wn=(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])})},yc=(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)},bc=(t,o)=>typeof o=="number"?["lineHeight","fontWeight","opacity","zIndex"].some(i=>t.includes(i))||t[t.length-1].toLowerCase().includes("opacity")?o:`${o}px`:o;function _o(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},c={},d={};return yc(t,(l,u,m)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const f=`--${n?`${n}-`:""}${l.join("-")}`,b=bc(l,u);Object.assign(s,{[f]:b}),Wn(c,l,`var(${f})`,m),Wn(d,l,`var(${f}, ${b})`,m)}},l=>l[0]==="vars"),{css:s,vars:c,varsWithDefaults:d}}function vc(t,o={}){const{getSelector:n=S,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:u="light",...m}=t,{vars:f,css:b,varsWithDefaults:h}=_o(m,o);let g=h;const z={},{[u]:v,...j}=d;if(Object.entries(j||{}).forEach(([a,k])=>{const{vars:D,css:O,varsWithDefaults:R}=_o(k,o);g=He(g,R),z[a]={css:O,vars:D}}),v){const{css:a,vars:k,varsWithDefaults:D}=_o(v,o);g=He(g,D),z[u]={css:a,vars:k}}function S(a,k){var O,R;let D=s;if(s==="class"&&(D=".%s"),s==="data"&&(D="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(D=`[${s}="%s"]`),a){if(D==="media")return t.defaultColorScheme===a?":root":{[`@media (prefers-color-scheme: ${((R=(O=d[a])==null?void 0:O.palette)==null?void 0:R.mode)||a})`]:{":root":k}};if(D)return t.defaultColorScheme===a?`:root, ${D.replace("%s",String(a))}`:D.replace("%s",String(a))}return":root"}return{vars:g,generateThemeVars:()=>{let a={...f};return Object.entries(z).forEach(([,{vars:k}])=>{a=He(a,k)}),a},generateStyleSheets:()=>{var U,J;const a=[],k=t.defaultColorScheme||"light";function D(ee,x){Object.keys(x).length&&a.push(typeof ee=="string"?{[ee]:{...x}}:ee)}D(n(void 0,{...b}),b);const{[k]:O,...R}=z;if(O){const{css:ee}=O,x=(J=(U=d[k])==null?void 0:U.palette)==null?void 0:J.mode,N=!i&&x?{colorScheme:x,...ee}:{...ee};D(n(k,{...N}),N)}return Object.entries(R).forEach(([ee,{css:x}])=>{var H,q;const N=(q=(H=d[ee])==null?void 0:H.palette)==null?void 0:q.mode,_=!i&&N?{colorScheme:N,...x}:{...x};D(n(ee,{..._}),_)}),c&&a.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)"}}),a}}}function Sc(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 Yr={black:"#000",white:"#fff"},jc={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"},pr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},xr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Wr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},mr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},fr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},hr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Bi(){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:Yr.white,default:Yr.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 Di=Bi();function Oi(){return{text:{primary:Yr.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:Yr.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 Lo=Oi();function Pn(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=Io(t.main,s):o==="dark"&&(t.dark=zo(t.main,c)))}function Nn(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 Cc(t="light"){return t==="dark"?{main:mr[200],light:mr[50],dark:mr[400]}:{main:mr[700],light:mr[400],dark:mr[800]}}function wc(t="light"){return t==="dark"?{main:pr[200],light:pr[50],dark:pr[400]}:{main:pr[500],light:pr[300],dark:pr[700]}}function kc(t="light"){return t==="dark"?{main:xr[500],light:xr[300],dark:xr[700]}:{main:xr[700],light:xr[400],dark:xr[800]}}function Tc(t="light"){return t==="dark"?{main:fr[400],light:fr[300],dark:fr[700]}:{main:fr[700],light:fr[500],dark:fr[900]}}function zc(t="light"){return t==="dark"?{main:hr[400],light:hr[300],dark:hr[700]}:{main:hr[800],light:hr[500],dark:hr[900]}}function Ic(t="light"){return t==="dark"?{main:Wr[400],light:Wr[300],dark:Wr[700]}:{main:"#ed6c02",light:Wr[500],dark:Wr[900]}}function Ec(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function en(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...c}=t,d=t.primary||Cc(o),l=t.secondary||wc(o),u=t.error||kc(o),m=t.info||Tc(o),f=t.success||zc(o),b=t.warning||Ic(o);function h(j){if(s)return Ec(j);const S=_n(j,Lo.text.primary)>=n?Lo.text.primary:Di.text.primary;if(process.env.NODE_ENV!=="production"){const y=_n(j,S);y<3&&console.error([`MUI: The contrast ratio of ${y}:1 for ${S} on ${j}`,"falls below the WCAG recommended absolute minimum contrast ratio of 3:1.","https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast"].join(`
45
- `))}return S}const g=({color:j,name:S,mainShade:y=500,lightShade:T=300,darkShade:a=700})=>{if(j={...j},!j.main&&j[y]&&(j.main=j[y]),!j.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
46
- The color object needs to have a \`main\` property or a \`${y}\` property.`:Ut(11,S?` (${S})`:"",y));if(typeof j.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
47
- \`color.main\` should be a string, but \`${JSON.stringify(j.main)}\` was provided instead.
41
+ `)));const l=a[d];return c>=0?l:typeof l=="number"?-l:typeof l=="string"&&l.startsWith("var(")?`calc(-1 * ${l})`:`-${l}`}:typeof a=="function"?a:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${o}\` value (${a}) is invalid.`,"It should be a number, an array or a function."].join(`
42
+ `)),()=>{})}function rn(t){return Kr(t,"spacing",8,"spacing")}function Xr(t,o){return typeof o=="string"||o==null?o:t(o)}function zl(t,o){return n=>t.reduce((i,a)=>(i[a]=Xr(o,n),i),{})}function El(t,o,n,i){if(!o.includes(n))return null;const a=Tl(n),c=zl(a,i),d=t[n];return Tt(t,d,c)}function Ai(t,o){const n=rn(t.theme);return Object.keys(t).map(i=>El(t,o,i,n)).reduce(qr,{})}function Ie(t){return Ai(t,jo)}Ie.propTypes=process.env.NODE_ENV!=="production"?jo.reduce((t,o)=>(t[o]=_t,t),{}):{};Ie.filterProps=jo;function ze(t){return Ai(t,Co)}ze.propTypes=process.env.NODE_ENV!=="production"?Co.reduce((t,o)=>(t[o]=_t,t),{}):{};ze.filterProps=Co;process.env.NODE_ENV!=="production"&&Il.reduce((t,o)=>(t[o]=_t,t),{});function Mi(t=8,o=rn({spacing:t})){if(t.mui)return t;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(c=>{const d=o(c);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function wo(...t){const o=t.reduce((i,a)=>(a.filterProps.forEach(c=>{i[c]=a}),i),{}),n=i=>Object.keys(i).reduce((a,c)=>o[c]?qr(a,o[c](i)):a,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,a)=>Object.assign(i,a.propTypes),{}):{},n.filterProps=t.reduce((i,a)=>i.concat(a.filterProps),[]),n}function Ze(t){return typeof t!="number"?t:`${t}px solid`}function Qe(t,o){return De({prop:t,themeKey:"borders",transform:o})}const Bl=Qe("border",Ze),Dl=Qe("borderTop",Ze),Ol=Qe("borderRight",Ze),Al=Qe("borderBottom",Ze),Ml=Qe("borderLeft",Ze),_l=Qe("borderColor"),$l=Qe("borderTopColor"),Rl=Qe("borderRightColor"),Wl=Qe("borderBottomColor"),Pl=Qe("borderLeftColor"),Nl=Qe("outline",Ze),Ll=Qe("outlineColor"),ko=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=Kr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Xr(o,i)});return Tt(t,t.borderRadius,n)}return null};ko.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:_t}:{};ko.filterProps=["borderRadius"];wo(Bl,Dl,Ol,Al,Ml,_l,$l,Rl,Wl,Pl,ko,Nl,Ll);const To=t=>{if(t.gap!==void 0&&t.gap!==null){const o=Kr(t.theme,"spacing",8,"gap"),n=i=>({gap:Xr(o,i)});return Tt(t,t.gap,n)}return null};To.propTypes=process.env.NODE_ENV!=="production"?{gap:_t}:{};To.filterProps=["gap"];const Io=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=Kr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Xr(o,i)});return Tt(t,t.columnGap,n)}return null};Io.propTypes=process.env.NODE_ENV!=="production"?{columnGap:_t}:{};Io.filterProps=["columnGap"];const zo=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=Kr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Xr(o,i)});return Tt(t,t.rowGap,n)}return null};zo.propTypes=process.env.NODE_ENV!=="production"?{rowGap:_t}:{};zo.filterProps=["rowGap"];const Fl=De({prop:"gridColumn"}),Vl=De({prop:"gridRow"}),Hl=De({prop:"gridAutoFlow"}),Ul=De({prop:"gridAutoColumns"}),Yl=De({prop:"gridAutoRows"}),Gl=De({prop:"gridTemplateColumns"}),ql=De({prop:"gridTemplateRows"}),Jl=De({prop:"gridTemplateAreas"}),Kl=De({prop:"gridArea"});wo(To,Io,zo,Fl,Vl,Hl,Ul,Yl,Gl,ql,Jl,Kl);function hr(t,o){return o==="grey"?o:t}const Xl=De({prop:"color",themeKey:"palette",transform:hr}),Zl=De({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:hr}),Ql=De({prop:"backgroundColor",themeKey:"palette",transform:hr});wo(Xl,Zl,Ql);function He(t){return t<=1&&t!==0?`${t*100}%`:t}const ec=De({prop:"width",transform:He}),on=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var a,c,d,l,p;const i=((d=(c=(a=t.theme)==null?void 0:a.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||vo[n];return i?((p=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:p.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:He(n)}};return Tt(t,t.maxWidth,o)}return null};on.filterProps=["maxWidth"];const tc=De({prop:"minWidth",transform:He}),rc=De({prop:"height",transform:He}),oc=De({prop:"maxHeight",transform:He}),nc=De({prop:"minHeight",transform:He});De({prop:"size",cssProperty:"width",transform:He});De({prop:"size",cssProperty:"height",transform:He});const ic=De({prop:"boxSizing"});wo(ec,on,tc,rc,oc,nc,ic);const Eo={border:{themeKey:"borders",transform:Ze},borderTop:{themeKey:"borders",transform:Ze},borderRight:{themeKey:"borders",transform:Ze},borderBottom:{themeKey:"borders",transform:Ze},borderLeft:{themeKey:"borders",transform:Ze},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Ze},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:ko},color:{themeKey:"palette",transform:hr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:hr},backgroundColor:{themeKey:"palette",transform:hr},p:{style:ze},pt:{style:ze},pr:{style:ze},pb:{style:ze},pl:{style:ze},px:{style:ze},py:{style:ze},padding:{style:ze},paddingTop:{style:ze},paddingRight:{style:ze},paddingBottom:{style:ze},paddingLeft:{style:ze},paddingX:{style:ze},paddingY:{style:ze},paddingInline:{style:ze},paddingInlineStart:{style:ze},paddingInlineEnd:{style:ze},paddingBlock:{style:ze},paddingBlockStart:{style:ze},paddingBlockEnd:{style:ze},m:{style:Ie},mt:{style:Ie},mr:{style:Ie},mb:{style:Ie},ml:{style:Ie},mx:{style:Ie},my:{style:Ie},margin:{style:Ie},marginTop:{style:Ie},marginRight:{style:Ie},marginBottom:{style:Ie},marginLeft:{style:Ie},marginX:{style:Ie},marginY:{style:Ie},marginInline:{style:Ie},marginInlineStart:{style:Ie},marginInlineEnd:{style:Ie},marginBlock:{style:Ie},marginBlockStart:{style:Ie},marginBlockEnd:{style:Ie},displayPrint:{cssProperty:!1,transform:t=>({"@media print":{display:t}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:To},rowGap:{style:zo},columnGap:{style:Io},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:He},maxWidth:{style:on},minWidth:{transform:He},height:{transform:He},maxHeight:{transform:He},minHeight:{transform:He},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function sc(...t){const o=t.reduce((i,a)=>i.concat(Object.keys(a)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function ac(t,o){return typeof t=="function"?t(o):t}function lc(){function t(n,i,a,c){const d={[n]:i,theme:a},l=c[n];if(!l)return{[n]:i};const{cssProperty:p=n,themeKey:x,transform:f,style:b}=l;if(i==null)return null;if(x==="typography"&&i==="inherit")return{[n]:i};const m=So(a,x)||{};return b?b(d):Tt(d,i,z=>{let y=ho(m,f,z);return z===y&&typeof z=="string"&&(y=ho(m,f,`${n}${z==="default"?"":Oi(z)}`,z)),p===!1?y:{[p]:y}})}function o(n){const{sx:i,theme:a={},nested:c}=n||{};if(!i)return null;const d=a.unstable_sxConfig??Eo;function l(p){let x=p;if(typeof p=="function")x=p(a);else if(typeof p!="object")return p;if(!x)return null;const f=jl(a.breakpoints),b=Object.keys(f);let m=f;return Object.keys(x).forEach(g=>{const z=ac(x[g],a);if(z!=null)if(typeof z=="object")if(d[g])m=qr(m,t(g,z,a,d));else{const y=Tt({theme:a},z,C=>({[g]:C}));sc(y,z)?m[g]=o({sx:z,theme:a,nested:!0}):m=qr(m,y)}else m=qr(m,t(g,z,a,d))}),!c&&a.modularCssLayers?{"@layer sx":Wn(a,Nn(b,m))}:Wn(a,Nn(b,m))}return Array.isArray(i)?i.map(l):l(i)}return o}const Bo=lc();Bo.filterProps=["sx"];function cc(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let a=n.getColorSchemeSelector(t);return a==="&"?o:((a.includes("data-")||a.includes("."))&&(a=`*:where(${a.replace(/\s*&$/,"")}) &`),{[a]:o})}return n.palette.mode===t?o:{}}function _i(t={},...o){const{breakpoints:n={},palette:i={},spacing:a,shape:c={},...d}=t,l=hl(n),p=Mi(a);let x=Ye({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:p,shape:{...vl,...c}},d);return x=bl(x),x.applyStyles=cc,x=o.reduce((f,b)=>Ye(f,b),x),x.unstable_sxConfig={...Eo,...d==null?void 0:d.unstable_sxConfig},x.unstable_sx=function(b){return Bo({sx:b,theme:this})},x}function dc(t){return Object.keys(t).length===0}function uc(t=null){const o=go.useContext(Is.ThemeContext);return!o||dc(o)?t:o}const pc=_i();function xc(t=pc){return uc(t)}const Fn=t=>t,mc=()=>{let t=Fn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Fn}}},fc=mc(),hc={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function gc(t,o,n="Mui"){const i=hc[o];return i?`${n}-${i}`:`${fc.generate(t)}-${o}`}function yc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function nn(t,o=0,n=1){return process.env.NODE_ENV!=="production"&&(t<o||t>n)&&console.error(`MUI: The value provided ${t} is out of range [${o}, ${n}].`),yc(t,o,n)}function bc(t){t=t.slice(1);const o=new RegExp(`.{1,${t.length>=6?2:1}}`,"g");let n=t.match(o);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&t.length!==t.trim().length&&console.error(`MUI: The color: "${t}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,a)=>a<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Mt(t){if(t.type)return t;if(t.charAt(0)==="#")return Mt(bc(t));const o=t.indexOf("("),n=t.substring(0,o);if(!["rgb","rgba","hsl","hsla","color"].includes(n))throw new Error(process.env.NODE_ENV!=="production"?`MUI: Unsupported \`${t}\` color.
43
+ The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().`:Jt(9,t));let i=t.substring(o+1,t.length-1),a;if(n==="color"){if(i=i.split(" "),a=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),!["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].includes(a))throw new Error(process.env.NODE_ENV!=="production"?`MUI: unsupported \`${a}\` color space.
44
+ The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:Jt(10,a))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:a}}const vc=t=>{const o=Mt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Ur=(t,o)=>{try{return vc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function Do(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((a,c)=>c<3?parseInt(a,10):a):o.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),o.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${o}(${i})`}function $i(t){t=Mt(t);const{values:o}=t,n=o[0],i=o[1]/100,a=o[2]/100,c=i*Math.min(a,1-a),d=(x,f=(x+n/30)%12)=>a-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])),Do({type:l,values:p})}function qo(t){t=Mt(t);let o=t.type==="hsl"||t.type==="hsla"?Mt($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=qo(t),i=qo(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function D(t,o){return t=Mt(t),o=nn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,Do(t)}function Yt(t,o,n){try{return D(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Oo(t,o){if(t=Mt(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 Do(t)}function ge(t,o,n){try{return Oo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Ao(t,o){if(t=Mt(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 Do(t)}function ye(t,o,n){try{return Ao(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Sc(t,o=.15){return qo(t)>.5?Oo(t,o):Ao(t,o)}function io(t,o,n){try{return Sc(t,o)}catch{return t}}function jc(t=""){function o(...i){if(!i.length)return"";const a=i[0];return typeof a=="string"&&!a.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)?`, var(--${t?`${t}-`:""}${a}${o(...i.slice(1))})`:`, ${a}`}return(i,...a)=>`var(--${t?`${t}-`:""}${i}${o(...a)})`}const Hn=(t,o,n,i=[])=>{let a=t;o.forEach((c,d)=>{d===o.length-1?Array.isArray(a)?a[Number(c)]=n:a&&typeof a=="object"&&(a[c]=n):a&&typeof a=="object"&&(a[c]||(a[c]=i.includes(c)?[]:{}),a=a[c])})},Cc=(t,o,n)=>{function i(a,c=[],d=[]){Object.entries(a).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)},wc=(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 Ho(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},a={},c={},d={};return Cc(t,(l,p,x)=>{if((typeof p=="string"||typeof p=="number")&&(!i||!i(l,p))){const f=`--${n?`${n}-`:""}${l.join("-")}`,b=wc(l,p);Object.assign(a,{[f]:b}),Hn(c,l,`var(${f})`,x),Hn(d,l,`var(${f}, ${b})`,x)}},l=>l[0]==="vars"),{css:a,vars:c,varsWithDefaults:d}}function kc(t,o={}){const{getSelector:n=v,disableCssColorScheme:i,colorSchemeSelector:a,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:p="light",...x}=t,{vars:f,css:b,varsWithDefaults:m}=Ho(x,o);let g=m;const z={},{[p]:y,...C}=d;if(Object.entries(C||{}).forEach(([T,s])=>{const{vars:M,css:B,varsWithDefaults:$}=Ho(s,o);g=Ye(g,$),z[T]={css:B,vars:M}}),y){const{css:T,vars:s,varsWithDefaults:M}=Ho(y,o);g=Ye(g,M),z[p]={css:T,vars:s}}function v(T,s){var B,$;let M=a;if(a==="class"&&(M=".%s"),a==="data"&&(M="[data-%s]"),a!=null&&a.startsWith("data-")&&!a.includes("%s")&&(M=`[${a}="%s"]`),T){if(M==="media")return t.defaultColorScheme===T?":root":{[`@media (prefers-color-scheme: ${(($=(B=d[T])==null?void 0:B.palette)==null?void 0:$.mode)||T})`]:{":root":s}};if(M)return t.defaultColorScheme===T?`:root, ${M.replace("%s",String(T))}`:M.replace("%s",String(T))}return":root"}return{vars:g,generateThemeVars:()=>{let T={...f};return Object.entries(z).forEach(([,{vars:s}])=>{T=Ye(T,s)}),T},generateStyleSheets:()=>{var G,Z;const T=[],s=t.defaultColorScheme||"light";function M(ee,h){Object.keys(h).length&&T.push(typeof ee=="string"?{[ee]:{...h}}:ee)}M(n(void 0,{...b}),b);const{[s]:B,...$}=z;if(B){const{css:ee}=B,h=(Z=(G=d[s])==null?void 0:G.palette)==null?void 0:Z.mode,R=!i&&h?{colorScheme:h,...ee}:{...ee};M(n(s,{...R}),R)}return Object.entries($).forEach(([ee,{css:h}])=>{var H,K;const R=(K=(H=d[ee])==null?void 0:H.palette)==null?void 0:K.mode,W=!i&&R?{colorScheme:R,...h}:{...h};M(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 Tc(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 Jr={black:"#000",white:"#fff"},Ic={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"},ur={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},pr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Lr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},xr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},mr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},fr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Ri(){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:Jr.white,default:Jr.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=Ri();function Pi(){return{text:{primary:Jr.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:Jr.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 Jo=Pi();function Un(t,o,n,i){const a=i.light||i,c=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Ao(t.main,a):o==="dark"&&(t.dark=Oo(t.main,c)))}function Yn(t,o,n,i,a){const c=a.light||a,d=a.dark||a*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(c*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function zc(t="light"){return t==="dark"?{main:xr[200],light:xr[50],dark:xr[400]}:{main:xr[700],light:xr[400],dark:xr[800]}}function Ec(t="light"){return t==="dark"?{main:ur[200],light:ur[50],dark:ur[400]}:{main:ur[500],light:ur[300],dark:ur[700]}}function Bc(t="light"){return t==="dark"?{main:pr[500],light:pr[300],dark:pr[700]}:{main:pr[700],light:pr[400],dark:pr[800]}}function Dc(t="light"){return t==="dark"?{main:mr[400],light:mr[300],dark:mr[700]}:{main:mr[700],light:mr[500],dark:mr[900]}}function Oc(t="light"){return t==="dark"?{main:fr[400],light:fr[300],dark:fr[700]}:{main:fr[800],light:fr[500],dark:fr[900]}}function Ac(t="light"){return t==="dark"?{main:Lr[400],light:Lr[300],dark:Lr[700]}:{main:"#ed6c02",light:Lr[500],dark:Lr[900]}}function Mc(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:a,...c}=t,d=t.primary||zc(o),l=t.secondary||Ec(o),p=t.error||Bc(o),x=t.info||Dc(o),f=t.success||Oc(o),b=t.warning||Ac(o);function m(C){if(a)return Mc(C);const v=Vn(C,Jo.text.primary)>=n?Jo.text.primary:Wi.text.primary;if(process.env.NODE_ENV!=="production"){const k=Vn(C,v);k<3&&console.error([`MUI: The contrast ratio of ${k}:1 for ${v} on ${C}`,"falls below the WCAG recommended absolute minimum contrast ratio of 3:1.","https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast"].join(`
45
+ `))}return v}const g=({color:C,name:v,mainShade:k=500,lightShade:S=300,darkShade:T=700})=>{if(C={...C},!C.main&&C[k]&&(C.main=C[k]),!C.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.`:Jt(11,v?` (${v})`:"",k));if(typeof C.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(C.main)}\` was provided instead.
48
48
 
49
49
  Did you intend to use one of the following approaches?
50
50
 
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
56
56
 
57
57
  const theme2 = createTheme({ palette: {
58
58
  primary: { main: green[500] },
59
- } });`:Ut(12,S?` (${S})`:"",JSON.stringify(j.main)));return s?(Nn(s,j,"light",T,i),Nn(s,j,"dark",a,i)):(Pn(j,"light",T,i),Pn(j,"dark",a,i)),j.contrastText||(j.contrastText=h(j.main)),j};let z;return o==="light"?z=Bi():o==="dark"&&(z=Oi()),process.env.NODE_ENV!=="production"&&(z||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),He({common:{...Yr},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:u,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:m,name:"info"}),success:g({color:f,name:"success"}),grey:jc,contrastThreshold:n,getContrastText:h,augmentColor:g,tonalOffset:i,...z},c)}function Bc(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 Dc(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Oc(t){return Math.round(t*1e5)/1e5}const Fn={textTransform:"uppercase"},Ln='"Roboto", "Helvetica", "Arial", sans-serif';function Mc(t,o){const{fontFamily:n=Ln,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:u=16,allVariants:m,pxToRem:f,...b}=typeof o=="function"?o(t):o;process.env.NODE_ENV!=="production"&&(typeof i!="number"&&console.error("MUI: `fontSize` is required to be a number."),typeof u!="number"&&console.error("MUI: `htmlFontSize` is required to be a number."));const h=i/14,g=f||(j=>`${j/u*h}rem`),z=(j,S,y,T,a)=>({fontFamily:n,fontWeight:j,fontSize:g(S),lineHeight:y,...n===Ln?{letterSpacing:`${Oc(T/S)}em`}:{},...a,...m}),v={h1:z(s,96,1.167,-1.5),h2:z(s,60,1.2,-.5),h3:z(c,48,1.167,0),h4:z(c,34,1.235,.25),h5:z(c,24,1.334,0),h6:z(d,20,1.6,.15),subtitle1:z(c,16,1.75,.15),subtitle2:z(d,14,1.57,.1),body1:z(c,16,1.5,.15),body2:z(c,14,1.43,.15),button:z(d,14,1.75,.4,Fn),caption:z(c,12,1.66,.4),overline:z(c,12,2.66,1,Fn),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return He({htmlFontSize:u,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...v},b,{clone:!1})}const Ac=.2,$c=.14,Rc=.12;function we(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Ac})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${$c})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Rc})`].join(",")}const _c=["none",we(0,2,1,-1,0,1,1,0,0,1,3,0),we(0,3,1,-2,0,2,2,0,0,1,5,0),we(0,3,3,-2,0,3,4,0,0,1,8,0),we(0,2,4,-1,0,4,5,0,0,1,10,0),we(0,3,5,-1,0,5,8,0,0,1,14,0),we(0,3,5,-1,0,6,10,0,0,1,18,0),we(0,4,5,-2,0,7,10,1,0,2,16,1),we(0,5,5,-3,0,8,10,1,0,3,14,2),we(0,5,6,-3,0,9,12,1,0,3,16,2),we(0,6,6,-3,0,10,14,1,0,4,18,3),we(0,6,7,-4,0,11,15,1,0,4,20,3),we(0,7,8,-4,0,12,17,2,0,5,22,4),we(0,7,8,-4,0,13,19,2,0,5,24,4),we(0,7,9,-4,0,14,21,2,0,5,26,4),we(0,8,9,-5,0,15,22,2,0,6,28,5),we(0,8,10,-5,0,16,24,2,0,6,30,5),we(0,8,11,-5,0,17,26,2,0,6,32,5),we(0,9,11,-5,0,18,28,2,0,7,34,6),we(0,9,12,-6,0,19,29,2,0,7,36,6),we(0,10,13,-6,0,20,31,3,0,8,38,7),we(0,10,13,-6,0,21,33,3,0,8,40,7),we(0,10,14,-6,0,22,35,3,0,8,42,7),we(0,11,14,-7,0,23,36,3,0,9,44,8),we(0,11,15,-7,0,24,38,3,0,9,46,8)],Wc={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)"},Pc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function Vn(t){return`${Math.round(t)}ms`}function Nc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Fc(t){const o={...Wc,...t.easing},n={...Pc,...t.duration};return{getAutoHeightDuration:Nc,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 f=h=>typeof h=="string",b=h=>!Number.isNaN(parseFloat(h));!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(u)&&!f(u)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof c!="object"&&console.error(["MUI: Secong argument of transition.create must be an object.","Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join(`
60
- `)),Object.keys(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(f=>`${f} ${typeof d=="string"?d:Vn(d)} ${l} ${typeof u=="string"?u:Vn(u)}`).join(",")},...t,easing:o,duration:n}}const Lc={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function Vc(t){return Bt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Mi(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];!Vc(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
+ } });`:Jt(12,v?` (${v})`:"",JSON.stringify(C.main)));return a?(Yn(a,C,"light",S,i),Yn(a,C,"dark",T,i)):(Un(C,"light",S,i),Un(C,"dark",T,i)),C.contrastText||(C.contrastText=m(C.main)),C};let z;return o==="light"?z=Ri():o==="dark"&&(z=Pi()),process.env.NODE_ENV!=="production"&&(z||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),Ye({common:{...Jr},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:x,name:"info"}),success:g({color:f,name:"success"}),grey:Ic,contrastThreshold:n,getContrastText:m,augmentColor:g,tonalOffset:i,...z},c)}function _c(t){const o={};return Object.entries(t).forEach(i=>{const[a,c]=i;typeof c=="object"&&(o[a]=`${c.fontStyle?`${c.fontStyle} `:""}${c.fontVariant?`${c.fontVariant} `:""}${c.fontWeight?`${c.fontWeight} `:""}${c.fontStretch?`${c.fontStretch} `:""}${c.fontSize||""}${c.lineHeight?`/${c.lineHeight} `:""}${c.fontFamily||""}`)}),o}function $c(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Rc(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:a=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:p=16,allVariants:x,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 m=i/14,g=f||(C=>`${C/p*m}rem`),z=(C,v,k,S,T)=>({fontFamily:n,fontWeight:C,fontSize:g(v),lineHeight:k,...n===qn?{letterSpacing:`${Rc(S/v)}em`}:{},...T,...x}),y={h1:z(a,96,1.167,-1.5),h2:z(a,60,1.2,-.5),h3:z(c,48,1.167,0),h4:z(c,34,1.235,.25),h5:z(c,24,1.334,0),h6:z(d,20,1.6,.15),subtitle1:z(c,16,1.75,.15),subtitle2:z(d,14,1.57,.1),body1:z(c,16,1.5,.15),body2:z(c,14,1.43,.15),button:z(d,14,1.75,.4,Gn),caption:z(c,12,1.66,.4),overline:z(c,12,2.66,1,Gn),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return Ye({htmlFontSize:p,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:a,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...y},b,{clone:!1})}const Pc=.2,Nc=.14,Lc=.12;function Te(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Pc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Nc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Lc})`].join(",")}const Fc=["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)],Vc={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)"},Hc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function Jn(t){return`${Math.round(t)}ms`}function Uc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Yc(t){const o={...Vc,...t.easing},n={...Hc,...t.duration};return{getAutoHeightDuration:Uc,create:(a=["all"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:p=0,...x}=c;if(process.env.NODE_ENV!=="production"){const f=m=>typeof m=="string",b=m=>!Number.isNaN(parseFloat(m));!f(a)&&!Array.isArray(a)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!f(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),f(l)||console.error('MUI: Argument "easing" must be a string.'),!b(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(x).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(x).join(",")}].`)}return(Array.isArray(a)?a:[a]).map(f=>`${f} ${typeof d=="string"?d:Jn(d)} ${l} ${typeof p=="string"?p:Jn(p)}`).join(",")},...t,easing:o,duration:n}}const Gc={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function qc(t){return At(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Ni(t={}){const o={...t};function n(i){const a=Object.entries(i);for(let c=0;c<a.length;c++){const[d,l]=a[c];!qc(l)||d.startsWith("unstable_")?delete i[d]:At(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 Hn(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const Hc=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 Uc(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,Hc(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${Hn(n)})`:Io(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${Hn(n)})`:zo(o,n)}})}function Vo(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:c={},transitions:d={},typography:l={},shape:u,colorSpace:m,...f}=t;if(t.vars&&t.generateThemeVars===void 0)throw new Error(process.env.NODE_ENV!=="production"?"MUI: `vars` is a private field used for CSS variables support.\nPlease use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.":Ut(20));const b=en({...c,colorSpace:m}),h=Ii(t);let g=He(h,{mixins:Dc(h.breakpoints,i),palette:b,shadows:_c.slice(),typography:Mc(b,l),transitions:Fc(d),zIndex:{...Lc}});if(g=He(g,f),g=o.reduce((z,v)=>He(z,v),g),process.env.NODE_ENV!=="production"){const z=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],v=(j,S)=>{let y;for(y in j){const T=j[y];if(z.includes(y)&&Object.keys(T).length>0){if(process.env.NODE_ENV!=="production"){const a=pc("",y);console.error([`MUI: The \`${S}\` component increases the CSS specificity of the \`${y}\` internal state.`,"You can not override it like this: ",JSON.stringify(j,null,2),"",`Instead, you need to use the '&.${a}' syntax:`,JSON.stringify({root:{[`&.${a}`]:T}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
68
- `))}j[y]={}}}};Object.keys(g.components).forEach(j=>{const S=g.components[j].styleOverrides;S&&j.startsWith("Mui")&&v(S,j)})}return g.unstable_sxConfig={...wo,...f==null?void 0:f.unstable_sxConfig},g.unstable_sx=function(v){return ko({sx:v,theme:this})},g.toRuntimeSource=Mi,Uc(g),g}function Yc(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 Gc=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=Yc(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ai(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function $i(t){return t==="dark"?Gc:[]}function qc(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...c}=t,d=en({...o,colorSpace:s});return{palette:d,opacity:{...Ai(d.mode),...n},overlays:i||$i(d.mode),...c}}function Jc(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 Kc=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],Xc=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 Kc(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 Zc(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function W(t,o,n){!t[o]&&n&&(t[o]=n)}function Vr(t){return typeof t!="string"||!t.startsWith("hsl")?t:Ei(t)}function vt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Lr(Vr(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 Qc(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const lt=t=>{try{return t()}catch{}},ed=(t="mui")=>gc(t);function Wo(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const c=s==="dark"?"dark":"light";if(!i){o[s]=qc({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=Vo({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:d,opacity:{...Ai(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||$i(c)},l}function td(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=Jc,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...f}=t,b=Object.keys(n)[0],h=i||(n.light&&b!=="light"?"light":b),g=ed(c),{[h]:z,light:v,dark:j,...S}=n,y={...S};let T=z;if((h==="dark"&&!("dark"in n)||h==="light"&&!("light"in n))&&(T=!0),!T)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${h}\` option is either missing or invalid.`:Ut(21,h));let a;d&&(a="oklch");const k=Wo(a,y,T,f,h);v&&!y.light&&Wo(a,y,v,void 0,"light"),j&&!y.dark&&Wo(a,y,j,void 0,"dark");let D={defaultColorScheme:h,...k,cssVarPrefix:c,colorSchemeSelector:u,rootSelector:m,getCssVar:g,colorSchemes:y,font:{...Bc(k.typography),...k.font},spacing:Qc(f.spacing)};Object.keys(D.colorSchemes).forEach(ee=>{const x=D.colorSchemes[ee].palette,N=H=>{const q=H.split("-"),de=q[1],ue=q[2];return g(H,x[de][ue])};x.mode==="light"&&(W(x.common,"background","#fff"),W(x.common,"onBackground","#000")),x.mode==="dark"&&(W(x.common,"background","#000"),W(x.common,"onBackground","#fff"));function _(H,q,de){if(a){let ue;return H===Lt&&(ue=`transparent ${((1-de)*100).toFixed(0)}%`),H===he&&(ue=`#000 ${(de*100).toFixed(0)}%`),H===ge&&(ue=`#fff ${(de*100).toFixed(0)}%`),`color-mix(in ${a}, ${q}, ${ue})`}return H(q,de)}if(Zc(x,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),x.mode==="light"){W(x.Alert,"errorColor",_(he,x.error.light,.6)),W(x.Alert,"infoColor",_(he,x.info.light,.6)),W(x.Alert,"successColor",_(he,x.success.light,.6)),W(x.Alert,"warningColor",_(he,x.warning.light,.6)),W(x.Alert,"errorFilledBg",N("palette-error-main")),W(x.Alert,"infoFilledBg",N("palette-info-main")),W(x.Alert,"successFilledBg",N("palette-success-main")),W(x.Alert,"warningFilledBg",N("palette-warning-main")),W(x.Alert,"errorFilledColor",lt(()=>x.getContrastText(x.error.main))),W(x.Alert,"infoFilledColor",lt(()=>x.getContrastText(x.info.main))),W(x.Alert,"successFilledColor",lt(()=>x.getContrastText(x.success.main))),W(x.Alert,"warningFilledColor",lt(()=>x.getContrastText(x.warning.main))),W(x.Alert,"errorStandardBg",_(ge,x.error.light,.9)),W(x.Alert,"infoStandardBg",_(ge,x.info.light,.9)),W(x.Alert,"successStandardBg",_(ge,x.success.light,.9)),W(x.Alert,"warningStandardBg",_(ge,x.warning.light,.9)),W(x.Alert,"errorIconColor",N("palette-error-main")),W(x.Alert,"infoIconColor",N("palette-info-main")),W(x.Alert,"successIconColor",N("palette-success-main")),W(x.Alert,"warningIconColor",N("palette-warning-main")),W(x.AppBar,"defaultBg",N("palette-grey-100")),W(x.Avatar,"defaultBg",N("palette-grey-400")),W(x.Button,"inheritContainedBg",N("palette-grey-300")),W(x.Button,"inheritContainedHoverBg",N("palette-grey-A100")),W(x.Chip,"defaultBorder",N("palette-grey-400")),W(x.Chip,"defaultAvatarColor",N("palette-grey-700")),W(x.Chip,"defaultIconColor",N("palette-grey-700")),W(x.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),W(x.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),W(x.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),W(x.LinearProgress,"primaryBg",_(ge,x.primary.main,.62)),W(x.LinearProgress,"secondaryBg",_(ge,x.secondary.main,.62)),W(x.LinearProgress,"errorBg",_(ge,x.error.main,.62)),W(x.LinearProgress,"infoBg",_(ge,x.info.main,.62)),W(x.LinearProgress,"successBg",_(ge,x.success.main,.62)),W(x.LinearProgress,"warningBg",_(ge,x.warning.main,.62)),W(x.Skeleton,"bg",a?_(Lt,x.text.primary,.11):`rgba(${N("palette-text-primaryChannel")} / 0.11)`),W(x.Slider,"primaryTrack",_(ge,x.primary.main,.62)),W(x.Slider,"secondaryTrack",_(ge,x.secondary.main,.62)),W(x.Slider,"errorTrack",_(ge,x.error.main,.62)),W(x.Slider,"infoTrack",_(ge,x.info.main,.62)),W(x.Slider,"successTrack",_(ge,x.success.main,.62)),W(x.Slider,"warningTrack",_(ge,x.warning.main,.62));const H=a?_(he,x.background.default,.6825):ro(x.background.default,.8);W(x.SnackbarContent,"bg",H),W(x.SnackbarContent,"color",lt(()=>a?Lo.text.primary:x.getContrastText(H))),W(x.SpeedDialAction,"fabHoverBg",ro(x.background.paper,.15)),W(x.StepConnector,"border",N("palette-grey-400")),W(x.StepContent,"border",N("palette-grey-400")),W(x.Switch,"defaultColor",N("palette-common-white")),W(x.Switch,"defaultDisabledColor",N("palette-grey-100")),W(x.Switch,"primaryDisabledColor",_(ge,x.primary.main,.62)),W(x.Switch,"secondaryDisabledColor",_(ge,x.secondary.main,.62)),W(x.Switch,"errorDisabledColor",_(ge,x.error.main,.62)),W(x.Switch,"infoDisabledColor",_(ge,x.info.main,.62)),W(x.Switch,"successDisabledColor",_(ge,x.success.main,.62)),W(x.Switch,"warningDisabledColor",_(ge,x.warning.main,.62)),W(x.TableCell,"border",_(ge,_(Lt,x.divider,1),.88)),W(x.Tooltip,"bg",_(Lt,x.grey[700],.92))}if(x.mode==="dark"){W(x.Alert,"errorColor",_(ge,x.error.light,.6)),W(x.Alert,"infoColor",_(ge,x.info.light,.6)),W(x.Alert,"successColor",_(ge,x.success.light,.6)),W(x.Alert,"warningColor",_(ge,x.warning.light,.6)),W(x.Alert,"errorFilledBg",N("palette-error-dark")),W(x.Alert,"infoFilledBg",N("palette-info-dark")),W(x.Alert,"successFilledBg",N("palette-success-dark")),W(x.Alert,"warningFilledBg",N("palette-warning-dark")),W(x.Alert,"errorFilledColor",lt(()=>x.getContrastText(x.error.dark))),W(x.Alert,"infoFilledColor",lt(()=>x.getContrastText(x.info.dark))),W(x.Alert,"successFilledColor",lt(()=>x.getContrastText(x.success.dark))),W(x.Alert,"warningFilledColor",lt(()=>x.getContrastText(x.warning.dark))),W(x.Alert,"errorStandardBg",_(he,x.error.light,.9)),W(x.Alert,"infoStandardBg",_(he,x.info.light,.9)),W(x.Alert,"successStandardBg",_(he,x.success.light,.9)),W(x.Alert,"warningStandardBg",_(he,x.warning.light,.9)),W(x.Alert,"errorIconColor",N("palette-error-main")),W(x.Alert,"infoIconColor",N("palette-info-main")),W(x.Alert,"successIconColor",N("palette-success-main")),W(x.Alert,"warningIconColor",N("palette-warning-main")),W(x.AppBar,"defaultBg",N("palette-grey-900")),W(x.AppBar,"darkBg",N("palette-background-paper")),W(x.AppBar,"darkColor",N("palette-text-primary")),W(x.Avatar,"defaultBg",N("palette-grey-600")),W(x.Button,"inheritContainedBg",N("palette-grey-800")),W(x.Button,"inheritContainedHoverBg",N("palette-grey-700")),W(x.Chip,"defaultBorder",N("palette-grey-700")),W(x.Chip,"defaultAvatarColor",N("palette-grey-300")),W(x.Chip,"defaultIconColor",N("palette-grey-300")),W(x.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),W(x.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),W(x.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),W(x.LinearProgress,"primaryBg",_(he,x.primary.main,.5)),W(x.LinearProgress,"secondaryBg",_(he,x.secondary.main,.5)),W(x.LinearProgress,"errorBg",_(he,x.error.main,.5)),W(x.LinearProgress,"infoBg",_(he,x.info.main,.5)),W(x.LinearProgress,"successBg",_(he,x.success.main,.5)),W(x.LinearProgress,"warningBg",_(he,x.warning.main,.5)),W(x.Skeleton,"bg",a?_(Lt,x.text.primary,.13):`rgba(${N("palette-text-primaryChannel")} / 0.13)`),W(x.Slider,"primaryTrack",_(he,x.primary.main,.5)),W(x.Slider,"secondaryTrack",_(he,x.secondary.main,.5)),W(x.Slider,"errorTrack",_(he,x.error.main,.5)),W(x.Slider,"infoTrack",_(he,x.info.main,.5)),W(x.Slider,"successTrack",_(he,x.success.main,.5)),W(x.Slider,"warningTrack",_(he,x.warning.main,.5));const H=a?_(ge,x.background.default,.985):ro(x.background.default,.98);W(x.SnackbarContent,"bg",H),W(x.SnackbarContent,"color",lt(()=>a?Di.text.primary:x.getContrastText(H))),W(x.SpeedDialAction,"fabHoverBg",ro(x.background.paper,.15)),W(x.StepConnector,"border",N("palette-grey-600")),W(x.StepContent,"border",N("palette-grey-600")),W(x.Switch,"defaultColor",N("palette-grey-300")),W(x.Switch,"defaultDisabledColor",N("palette-grey-600")),W(x.Switch,"primaryDisabledColor",_(he,x.primary.main,.55)),W(x.Switch,"secondaryDisabledColor",_(he,x.secondary.main,.55)),W(x.Switch,"errorDisabledColor",_(he,x.error.main,.55)),W(x.Switch,"infoDisabledColor",_(he,x.info.main,.55)),W(x.Switch,"successDisabledColor",_(he,x.success.main,.55)),W(x.Switch,"warningDisabledColor",_(he,x.warning.main,.55)),W(x.TableCell,"border",_(he,_(Lt,x.divider,1),.68)),W(x.Tooltip,"bg",_(Lt,x.grey[700],.92))}vt(x.background,"default"),vt(x.background,"paper"),vt(x.common,"background"),vt(x.common,"onBackground"),vt(x,"divider"),Object.keys(x).forEach(H=>{const q=x[H];H!=="tonalOffset"&&q&&typeof q=="object"&&(q.main&&W(x[H],"mainChannel",Lr(Vr(q.main))),q.light&&W(x[H],"lightChannel",Lr(Vr(q.light))),q.dark&&W(x[H],"darkChannel",Lr(Vr(q.dark))),q.contrastText&&W(x[H],"contrastTextChannel",Lr(Vr(q.contrastText))),H==="text"&&(vt(x[H],"primary"),vt(x[H],"secondary")),H==="action"&&(q.active&&vt(x[H],"active"),q.selected&&vt(x[H],"selected")))})}),D=o.reduce((ee,x)=>He(ee,x),D);const O={prefix:c,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:Xc(D),enableContrastVars:d},{vars:R,generateThemeVars:U,generateStyleSheets:J}=vc(D,O);return D.vars=R,Object.entries(D.colorSchemes[D.defaultColorScheme]).forEach(([ee,x])=>{D[ee]=x}),D.generateThemeVars=U,D.generateStyleSheets=J,D.generateSpacing=function(){return zi(f.spacing,Xo(this))},D.getColorSchemeSelector=Sc(u),D.spacing=D.generateSpacing(),D.shouldSkipGeneratingVar=l,D.unstable_sxConfig={...wo,...f==null?void 0:f.unstable_sxConfig},D.unstable_sx=function(x){return ko({sx:x,theme:this})},D.toRuntimeSource=Mi,D}function Un(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:en({...n===!0?{}:n.palette,mode:o})})}function rd(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 Vo(t,...o);let f=n;"palette"in t||m[l]&&(m[l]!==!0?f=m[l].palette:l==="dark"&&(f={mode:"dark"}));const b=Vo({...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},Un(b,"dark",m.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:b.palette},Un(b,"light",m.light)),b}return!n&&!("light"in m)&&l==="light"&&(m.light=!0),td({...d,colorSchemes:m,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const od=rd();function wt(){const t=lc(od);return process.env.NODE_ENV!=="production"&&po.useDebugValue(t),t[Xa]||t}async function nd(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 f=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(f)u=l[f];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:u,source:t,fetchedAt:new Date().toISOString()}}function id({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[c,d]=p.useState(""),[l,u]=p.useState(!1),[m,f]=p.useState(""),[b,h]=p.useState(null),[g,z]=p.useState(null),[v,j]=p.useState(!1),[S,y]=p.useState(""),T=p.useRef(null),[a,k]=p.useState("json"),[D,O]=p.useState(""),[R,U]=p.useState(""),[J,ee]=p.useState(""),[x,N]=p.useState("idle"),[_,H]=p.useState(""),[q,de]=p.useState(null),[ue,re]=p.useState(0),M=async P=>{if(y(""),!P.name.endsWith(".json")){y("Only .json files are allowed");return}const te=10*1024*1024;if(P.size>te){y("File size exceeds 10MB limit");return}try{const ie=await P.text();let se;try{se=JSON.parse(ie)}catch{y("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(se)){y("JSON must be an array of objects");return}if(se.length===0){y("No data rows found in JSON file");return}h(P),z(se)}catch{y("Network error — please try again")}},L=P=>{P.preventDefault();const te=P.dataTransfer.files[0];te&&M(te)},G=async()=>{if(D.trim()){N("loading"),H("");try{const P=await nd(D.trim(),R.trim()||void 0,J.trim()||void 0);de(P.data),re(P.data.length),N("ready")}catch(P){H((P==null?void 0:P.message)||"Connection failed"),N("error")}}},oe=()=>{if(!c.trim()){u(!0);return}const P=a==="api"?q:i||g;P&&(n(c.trim(),m.trim(),P),Q())},Q=()=>{d(""),u(!1),f(""),h(null),z(null),y(""),k("json"),O(""),U(""),ee(""),N("idle"),H(""),de(null),re(0),o()},le=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:P=>{d(P.target.value),l&&P.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:ne,helperText:ne?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:m,onChange:P=>f(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:a==="json"?0:1,onChange:(P,te)=>{k(te===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(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}})]}),a==="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(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:L,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=T.current)==null?void 0:P.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":S?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?P=>E(P.palette.success.main,.04):S?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):S?P=>E(P.palette.error.main,.08):P=>E(P.palette.primary.main,.08),borderColor:g?"success.dark":S?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:T,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var te;return((te=P.target.files)==null?void 0:te[0])&&M(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(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:P=>E(P.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"}),S&&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:S})})]})]})]})}),a==="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:D,onChange:P=>{O(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:R,onChange:P=>U(P.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:J,onChange:P=>ee(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!D.trim()||x==="loading",onClick:G,startIcon:x==="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: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(w.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[ue.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:D})]})]}),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(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:_})]})]})]})]})}),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:P=>E(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:oe,disabled:a==="json"&&!le||a==="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:v,onClose:()=>j(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",e.jsx(r.IconButton,{onClick:()=>j(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
67
+ export default theme;`}function Kn(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const Jc=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 Kc(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})`:D(o,Jc(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${Kn(n)})`:Ao(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${Kn(n)})`:Oo(o,n)}})}function Ko(t={},...o){const{breakpoints:n,mixins:i={},spacing:a,palette:c={},transitions:d={},typography:l={},shape:p,colorSpace:x,...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.":Jt(20));const b=sn({...c,colorSpace:x}),m=_i(t);let g=Ye(m,{mixins:$c(m.breakpoints,i),palette:b,shadows:Fc.slice(),typography:Wc(b,l),transitions:Yc(d),zIndex:{...Gc}});if(g=Ye(g,f),g=o.reduce((z,y)=>Ye(z,y),g),process.env.NODE_ENV!=="production"){const z=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],y=(C,v)=>{let k;for(k in C){const S=C[k];if(z.includes(k)&&Object.keys(S).length>0){if(process.env.NODE_ENV!=="production"){const T=gc("",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(C,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
+ `))}C[k]={}}}};Object.keys(g.components).forEach(C=>{const v=g.components[C].styleOverrides;v&&C.startsWith("Mui")&&y(v,C)})}return g.unstable_sxConfig={...Eo,...f==null?void 0:f.unstable_sxConfig},g.unstable_sx=function(y){return Bo({sx:y,theme:this})},g.toRuntimeSource=Ni,Kc(g),g}function Xc(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 Zc=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=Xc(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Li(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Fi(t){return t==="dark"?Zc:[]}function Qc(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:a,...c}=t,d=sn({...o,colorSpace:a});return{palette:d,opacity:{...Li(d.mode),...n},overlays:i||Fi(d.mode),...c}}function ed(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 td=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],rd=t=>(o,n)=>{const i=t.rootSelector||":root",a=t.colorSchemeSelector;let c=a;if(a==="class"&&(c=".%s"),a==="data"&&(c="[data-%s]"),a!=null&&a.startsWith("data-")&&!a.includes("%s")&&(c=`[${a}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return td(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 od(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function P(t,o,n){!t[o]&&n&&(t[o]=n)}function Yr(t){return typeof t!="string"||!t.startsWith("hsl")?t:$i(t)}function Ct(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Ur(Yr(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 nd(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const pt=t=>{try{return t()}catch{}},id=(t="mui")=>jc(t);function Uo(t,o,n,i,a){if(!n)return;n=n===!0?{}:n;const c=a==="dark"?"dark":"light";if(!i){o[a]=Qc({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=Ko({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[a]={...n,palette:d,opacity:{...Li(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Fi(c)},l}function sd(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:a=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=ed,colorSchemeSelector:p=n.light&&n.dark?"media":void 0,rootSelector:x=":root",...f}=t,b=Object.keys(n)[0],m=i||(n.light&&b!=="light"?"light":b),g=id(c),{[m]:z,light:y,dark:C,...v}=n,k={...v};let S=z;if((m==="dark"&&!("dark"in n)||m==="light"&&!("light"in n))&&(S=!0),!S)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${m}\` option is either missing or invalid.`:Jt(21,m));let T;d&&(T="oklch");const s=Uo(T,k,S,f,m);y&&!k.light&&Uo(T,k,y,void 0,"light"),C&&!k.dark&&Uo(T,k,C,void 0,"dark");let M={defaultColorScheme:m,...s,cssVarPrefix:c,colorSchemeSelector:p,rootSelector:x,getCssVar:g,colorSchemes:k,font:{..._c(s.typography),...s.font},spacing:nd(f.spacing)};Object.keys(M.colorSchemes).forEach(ee=>{const h=M.colorSchemes[ee].palette,R=H=>{const K=H.split("-"),de=K[1],ue=K[2];return g(H,h[de][ue])};h.mode==="light"&&(P(h.common,"background","#fff"),P(h.common,"onBackground","#000")),h.mode==="dark"&&(P(h.common,"background","#000"),P(h.common,"onBackground","#fff"));function W(H,K,de){if(T){let ue;return H===Yt&&(ue=`transparent ${((1-de)*100).toFixed(0)}%`),H===ge&&(ue=`#000 ${(de*100).toFixed(0)}%`),H===ye&&(ue=`#fff ${(de*100).toFixed(0)}%`),`color-mix(in ${T}, ${K}, ${ue})`}return H(K,de)}if(od(h,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),h.mode==="light"){P(h.Alert,"errorColor",W(ge,h.error.light,.6)),P(h.Alert,"infoColor",W(ge,h.info.light,.6)),P(h.Alert,"successColor",W(ge,h.success.light,.6)),P(h.Alert,"warningColor",W(ge,h.warning.light,.6)),P(h.Alert,"errorFilledBg",R("palette-error-main")),P(h.Alert,"infoFilledBg",R("palette-info-main")),P(h.Alert,"successFilledBg",R("palette-success-main")),P(h.Alert,"warningFilledBg",R("palette-warning-main")),P(h.Alert,"errorFilledColor",pt(()=>h.getContrastText(h.error.main))),P(h.Alert,"infoFilledColor",pt(()=>h.getContrastText(h.info.main))),P(h.Alert,"successFilledColor",pt(()=>h.getContrastText(h.success.main))),P(h.Alert,"warningFilledColor",pt(()=>h.getContrastText(h.warning.main))),P(h.Alert,"errorStandardBg",W(ye,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(ye,h.info.light,.9)),P(h.Alert,"successStandardBg",W(ye,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(ye,h.warning.light,.9)),P(h.Alert,"errorIconColor",R("palette-error-main")),P(h.Alert,"infoIconColor",R("palette-info-main")),P(h.Alert,"successIconColor",R("palette-success-main")),P(h.Alert,"warningIconColor",R("palette-warning-main")),P(h.AppBar,"defaultBg",R("palette-grey-100")),P(h.Avatar,"defaultBg",R("palette-grey-400")),P(h.Button,"inheritContainedBg",R("palette-grey-300")),P(h.Button,"inheritContainedHoverBg",R("palette-grey-A100")),P(h.Chip,"defaultBorder",R("palette-grey-400")),P(h.Chip,"defaultAvatarColor",R("palette-grey-700")),P(h.Chip,"defaultIconColor",R("palette-grey-700")),P(h.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),P(h.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),P(h.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),P(h.LinearProgress,"primaryBg",W(ye,h.primary.main,.62)),P(h.LinearProgress,"secondaryBg",W(ye,h.secondary.main,.62)),P(h.LinearProgress,"errorBg",W(ye,h.error.main,.62)),P(h.LinearProgress,"infoBg",W(ye,h.info.main,.62)),P(h.LinearProgress,"successBg",W(ye,h.success.main,.62)),P(h.LinearProgress,"warningBg",W(ye,h.warning.main,.62)),P(h.Skeleton,"bg",T?W(Yt,h.text.primary,.11):`rgba(${R("palette-text-primaryChannel")} / 0.11)`),P(h.Slider,"primaryTrack",W(ye,h.primary.main,.62)),P(h.Slider,"secondaryTrack",W(ye,h.secondary.main,.62)),P(h.Slider,"errorTrack",W(ye,h.error.main,.62)),P(h.Slider,"infoTrack",W(ye,h.info.main,.62)),P(h.Slider,"successTrack",W(ye,h.success.main,.62)),P(h.Slider,"warningTrack",W(ye,h.warning.main,.62));const H=T?W(ge,h.background.default,.6825):io(h.background.default,.8);P(h.SnackbarContent,"bg",H),P(h.SnackbarContent,"color",pt(()=>T?Jo.text.primary:h.getContrastText(H))),P(h.SpeedDialAction,"fabHoverBg",io(h.background.paper,.15)),P(h.StepConnector,"border",R("palette-grey-400")),P(h.StepContent,"border",R("palette-grey-400")),P(h.Switch,"defaultColor",R("palette-common-white")),P(h.Switch,"defaultDisabledColor",R("palette-grey-100")),P(h.Switch,"primaryDisabledColor",W(ye,h.primary.main,.62)),P(h.Switch,"secondaryDisabledColor",W(ye,h.secondary.main,.62)),P(h.Switch,"errorDisabledColor",W(ye,h.error.main,.62)),P(h.Switch,"infoDisabledColor",W(ye,h.info.main,.62)),P(h.Switch,"successDisabledColor",W(ye,h.success.main,.62)),P(h.Switch,"warningDisabledColor",W(ye,h.warning.main,.62)),P(h.TableCell,"border",W(ye,W(Yt,h.divider,1),.88)),P(h.Tooltip,"bg",W(Yt,h.grey[700],.92))}if(h.mode==="dark"){P(h.Alert,"errorColor",W(ye,h.error.light,.6)),P(h.Alert,"infoColor",W(ye,h.info.light,.6)),P(h.Alert,"successColor",W(ye,h.success.light,.6)),P(h.Alert,"warningColor",W(ye,h.warning.light,.6)),P(h.Alert,"errorFilledBg",R("palette-error-dark")),P(h.Alert,"infoFilledBg",R("palette-info-dark")),P(h.Alert,"successFilledBg",R("palette-success-dark")),P(h.Alert,"warningFilledBg",R("palette-warning-dark")),P(h.Alert,"errorFilledColor",pt(()=>h.getContrastText(h.error.dark))),P(h.Alert,"infoFilledColor",pt(()=>h.getContrastText(h.info.dark))),P(h.Alert,"successFilledColor",pt(()=>h.getContrastText(h.success.dark))),P(h.Alert,"warningFilledColor",pt(()=>h.getContrastText(h.warning.dark))),P(h.Alert,"errorStandardBg",W(ge,h.error.light,.9)),P(h.Alert,"infoStandardBg",W(ge,h.info.light,.9)),P(h.Alert,"successStandardBg",W(ge,h.success.light,.9)),P(h.Alert,"warningStandardBg",W(ge,h.warning.light,.9)),P(h.Alert,"errorIconColor",R("palette-error-main")),P(h.Alert,"infoIconColor",R("palette-info-main")),P(h.Alert,"successIconColor",R("palette-success-main")),P(h.Alert,"warningIconColor",R("palette-warning-main")),P(h.AppBar,"defaultBg",R("palette-grey-900")),P(h.AppBar,"darkBg",R("palette-background-paper")),P(h.AppBar,"darkColor",R("palette-text-primary")),P(h.Avatar,"defaultBg",R("palette-grey-600")),P(h.Button,"inheritContainedBg",R("palette-grey-800")),P(h.Button,"inheritContainedHoverBg",R("palette-grey-700")),P(h.Chip,"defaultBorder",R("palette-grey-700")),P(h.Chip,"defaultAvatarColor",R("palette-grey-300")),P(h.Chip,"defaultIconColor",R("palette-grey-300")),P(h.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),P(h.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),P(h.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),P(h.LinearProgress,"primaryBg",W(ge,h.primary.main,.5)),P(h.LinearProgress,"secondaryBg",W(ge,h.secondary.main,.5)),P(h.LinearProgress,"errorBg",W(ge,h.error.main,.5)),P(h.LinearProgress,"infoBg",W(ge,h.info.main,.5)),P(h.LinearProgress,"successBg",W(ge,h.success.main,.5)),P(h.LinearProgress,"warningBg",W(ge,h.warning.main,.5)),P(h.Skeleton,"bg",T?W(Yt,h.text.primary,.13):`rgba(${R("palette-text-primaryChannel")} / 0.13)`),P(h.Slider,"primaryTrack",W(ge,h.primary.main,.5)),P(h.Slider,"secondaryTrack",W(ge,h.secondary.main,.5)),P(h.Slider,"errorTrack",W(ge,h.error.main,.5)),P(h.Slider,"infoTrack",W(ge,h.info.main,.5)),P(h.Slider,"successTrack",W(ge,h.success.main,.5)),P(h.Slider,"warningTrack",W(ge,h.warning.main,.5));const H=T?W(ye,h.background.default,.985):io(h.background.default,.98);P(h.SnackbarContent,"bg",H),P(h.SnackbarContent,"color",pt(()=>T?Wi.text.primary:h.getContrastText(H))),P(h.SpeedDialAction,"fabHoverBg",io(h.background.paper,.15)),P(h.StepConnector,"border",R("palette-grey-600")),P(h.StepContent,"border",R("palette-grey-600")),P(h.Switch,"defaultColor",R("palette-grey-300")),P(h.Switch,"defaultDisabledColor",R("palette-grey-600")),P(h.Switch,"primaryDisabledColor",W(ge,h.primary.main,.55)),P(h.Switch,"secondaryDisabledColor",W(ge,h.secondary.main,.55)),P(h.Switch,"errorDisabledColor",W(ge,h.error.main,.55)),P(h.Switch,"infoDisabledColor",W(ge,h.info.main,.55)),P(h.Switch,"successDisabledColor",W(ge,h.success.main,.55)),P(h.Switch,"warningDisabledColor",W(ge,h.warning.main,.55)),P(h.TableCell,"border",W(ge,W(Yt,h.divider,1),.68)),P(h.Tooltip,"bg",W(Yt,h.grey[700],.92))}Ct(h.background,"default"),Ct(h.background,"paper"),Ct(h.common,"background"),Ct(h.common,"onBackground"),Ct(h,"divider"),Object.keys(h).forEach(H=>{const K=h[H];H!=="tonalOffset"&&K&&typeof K=="object"&&(K.main&&P(h[H],"mainChannel",Ur(Yr(K.main))),K.light&&P(h[H],"lightChannel",Ur(Yr(K.light))),K.dark&&P(h[H],"darkChannel",Ur(Yr(K.dark))),K.contrastText&&P(h[H],"contrastTextChannel",Ur(Yr(K.contrastText))),H==="text"&&(Ct(h[H],"primary"),Ct(h[H],"secondary")),H==="action"&&(K.active&&Ct(h[H],"active"),K.selected&&Ct(h[H],"selected")))})}),M=o.reduce((ee,h)=>Ye(ee,h),M);const B={prefix:c,disableCssColorScheme:a,shouldSkipGeneratingVar:l,getSelector:rd(M),enableContrastVars:d},{vars:$,generateThemeVars:G,generateStyleSheets:Z}=kc(M,B);return M.vars=$,Object.entries(M.colorSchemes[M.defaultColorScheme]).forEach(([ee,h])=>{M[ee]=h}),M.generateThemeVars=G,M.generateStyleSheets=Z,M.generateSpacing=function(){return Mi(f.spacing,rn(this))},M.getColorSchemeSelector=Tc(p),M.spacing=M.generateSpacing(),M.shouldSkipGeneratingVar=l,M.unstable_sxConfig={...Eo,...f==null?void 0:f.unstable_sxConfig},M.unstable_sx=function(h){return Bo({sx:h,theme:this})},M.toRuntimeSource=Ni,M}function Xn(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:sn({...n===!0?{}:n.palette,mode:o})})}function ad(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:a=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",p=a==null?void 0:a[l],x={...a,...n?{[l]:{...typeof p!="boolean"&&p,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return Ko(t,...o);let f=n;"palette"in t||x[l]&&(x[l]!==!0?f=x[l].palette:l==="dark"&&(f={mode:"dark"}));const b=Ko({...t,palette:f},...o);return b.defaultColorScheme=l,b.colorSchemes=x,b.palette.mode==="light"&&(b.colorSchemes.light={...x.light!==!0&&x.light,palette:b.palette},Xn(b,"dark",x.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...x.dark!==!0&&x.dark,palette:b.palette},Xn(b,"light",x.light)),b}return!n&&!("light"in x)&&l==="light"&&(x.light=!0),sd({...d,colorSchemes:x,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const ld=ad();function It(){const t=xc(ld);return process.env.NODE_ENV!=="production"&&go.useDebugValue(t),t[rl]||t}async function cd(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const a=new AbortController,c=setTimeout(()=>a.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:a.signal})}catch(x){throw clearTimeout(c),(x==null?void 0:x.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(c)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let l;try{l=await d.json()}catch{throw new Error("Response is not valid JSON")}let p;if(Array.isArray(l))p=l;else if(n&&l[n]&&Array.isArray(l[n]))p=l[n];else{const f=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(f)p=l[f];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:p,source:t,fetchedAt:new Date().toISOString()}}function dd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:a}){const[c,d]=u.useState(""),[l,p]=u.useState(!1),[x,f]=u.useState(""),[b,m]=u.useState(null),[g,z]=u.useState(null),[y,C]=u.useState(!1),[v,k]=u.useState(""),S=u.useRef(null),[T,s]=u.useState("json"),[M,B]=u.useState(""),[$,G]=u.useState(""),[Z,ee]=u.useState(""),[h,R]=u.useState("idle"),[W,H]=u.useState(""),[K,de]=u.useState(null),[ue,te]=u.useState(0),A=async N=>{if(k(""),!N.name.endsWith(".json")){k("Only .json files are allowed");return}const ne=10*1024*1024;if(N.size>ne){k("File size exceeds 10MB limit");return}try{const ce=await N.text();let se;try{se=JSON.parse(ce)}catch{k("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(se)){k("JSON must be an array of objects");return}if(se.length===0){k("No data rows found in JSON file");return}m(N),z(se)}catch{k("Network error — please try again")}},V=N=>{N.preventDefault();const ne=N.dataTransfer.files[0];ne&&A(ne)},q=async()=>{if(M.trim()){R("loading"),H("");try{const N=await cd(M.trim(),$.trim()||void 0,Z.trim()||void 0);de(N.data),te(N.data.length),R("ready")}catch(N){H((N==null?void 0:N.message)||"Connection failed"),R("error")}}},re=()=>{if(!c.trim()){p(!0);return}const N=T==="api"?K:i||g;N&&(n(c.trim(),x.trim(),N),Q())},Q=()=>{d(""),p(!1),f(""),m(null),z(null),k(""),s("json"),B(""),G(""),ee(""),R("idle"),H(""),de(null),te(0),o()},le=i||g,oe=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:Q,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:Q,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[e.jsx(r.TextField,{label:"Report name",required:!0,fullWidth:!0,value:c,onChange:N=>{d(N.target.value),l&&N.target.value.trim()&&p(!1)},placeholder:"Enter report name",autoFocus:!0,error:oe,helperText:oe?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:x,onChange:N=>f(N.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsxs(r.Tabs,{value:T==="json"?0:1,onChange:(N,ne)=>{s(ne===0?"json":"api"),R("idle"),H("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(w.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}}),e.jsx(r.Tab,{label:"Connect API",icon:e.jsx(w.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),T==="json"&&e.jsx(r.Box,{children:i?e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:N=>D(N.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:N=>D(N.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:a||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>C(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:V,onDragOver:N=>N.preventDefault(),onPaste:N=>N.preventDefault(),onClick:()=>{var N;return(N=S.current)==null?void 0:N.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":v?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?N=>D(N.palette.success.main,.04):v?N=>D(N.palette.error.main,.04):N=>D(N.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?N=>D(N.palette.success.main,.08):v?N=>D(N.palette.error.main,.08):N=>D(N.palette.primary.main,.08),borderColor:g?"success.dark":v?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:S,type:"file",accept:".json",sx:{display:"none"},onChange:N=>{var ne;return((ne=N.target.files)==null?void 0:ne[0])&&A(N.target.files[0])}}),g?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:N=>D(N.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(w.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:b==null?void 0:b.name}),e.jsx(r.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):e.jsxs(r.Box,{children:[e.jsx(r.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:N=>D(N.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(w.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),v&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:N=>D(N.palette.error.main,.08),border:1,borderColor:N=>D(N.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:v})})]})]})]})}),T==="api"&&e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx(r.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:M,onChange:N=>{B(N.target.value),R("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:$,onChange:N=>G(N.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(w.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:Z,onChange:N=>ee(N.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!M.trim()||h==="loading",onClick:q,startIcon:h==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(w.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:N=>D(N.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:h==="loading"?"Connecting...":"Test Connection & Load Data"}),h==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:N=>D(N.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[ue.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:M})]})]}),h==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:N=>D(N.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:W})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:Q,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:N=>D(N.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:re,disabled:T==="json"&&!le||T==="api"&&h!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:y,onClose:()=>C(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",e.jsx(r.IconButton,{onClick:()=>C(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
70
70
  {
71
71
  "id": 1,
72
72
  "customerName": "John Smith",
@@ -76,7 +76,7 @@ To suppress this warning, you need to explicitly provide the \`palette.${o}Chann
76
76
  "memberSince": "2024-01-15",
77
77
  "status": "active"
78
78
  }
79
- ]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>j(!1),variant:"contained",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 Ri({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:`[
79
+ ]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>C(!1),variant:"contained",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 Vi({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 sd({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),f=async S=>{if(!S.name.endsWith(".json")){o("Only .json files are allowed");return}const y=10*1024*1024;if(S.size>y){o("File size exceeds 10MB limit");return}d(S.name);try{const T=await S.text();let a;try{a=JSON.parse(T)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(a)){o("JSON must be an array of objects");return}if(a.length===0){o("No data rows found in JSON file");return}t(a)}catch{o("Network error — please try again")}finally{d("")}},b=S=>{S.preventDefault(),s(!0)},h=S=>{S.preventDefault(),s(!1)},g=S=>{S.preventDefault(),s(!1);const y=S.dataTransfer.files[0];y&&f(y)},z=()=>{var S;(S=m.current)==null||S.click()},v=S=>{var T;const y=(T=S.target.files)==null?void 0:T[0];y&&f(y)},j=S=>{S.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:h,onDrop:g,onPaste:S=>S.preventDefault(),onClick:z,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?S=>E(S.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[e.jsx(r.Box,{component:"input",ref:m,type:"file",accept:".json",onChange:v,sx:{display:"none"}}),n?e.jsxs(e.Fragment,{children:[e.jsx(r.CircularProgress,{size:32,sx:{mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:.5},children:"Uploading..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:S=>E(S.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(Ri,{isOpen:l,onClose:()=>u(!1)})]})}function ad({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(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 ld({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(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 _i({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(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 cd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:c,disabled:d}){const[l,u]=p.useState(!1),[m,f]=p.useState(!1),[b,h]=p.useState(-1),g=p.useRef(null),z=p.useRef(null);p.useEffect(()=>{function R(U){g.current&&!g.current.contains(U.target)&&(u(!1),f(!1))}return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]);const v=p.useCallback(()=>{f(!0),h(-1),n.length>0&&u(!0)},[n.length]),j=p.useCallback(R=>{o(R),h(-1)},[o]),S=p.useCallback(R=>{var U;o(R),i(R),u(!1),(U=z.current)==null||U.blur()},[o,i]),y=p.useCallback(R=>{h(-1),S(R)},[S]),T=p.useCallback(R=>{var U;R.key==="Enter"?b>=0&&b<n.length?(R.preventDefault(),y(n[b].query)):t.trim()&&S(t.trim()):R.key==="Escape"?(u(!1),h(-1),(U=z.current)==null||U.blur()):R.key==="ArrowDown"?(R.preventDefault(),n.length>0&&(l||u(!0),h(J=>J<n.length-1?J+1:J))):R.key==="ArrowUp"&&(R.preventDefault(),h(J=>J>0?J-1:-1))},[b,n,t,l,y,S]),a=p.useCallback(()=>{var R;o(""),(R=z.current)==null||R.focus()},[o]),k=p.useMemo(()=>n.filter(R=>R.isFavourite),[n]),D=p.useMemo(()=>n.filter(R=>!R.isFavourite),[n]),O=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:z,size:"small",fullWidth:!0,value:t,onChange:R=>j(R.target.value),onFocus:v,onKeyDown:T,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"common.white",height:"36px","& fieldset":{borderColor:"divider",transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:"divider"},"&.Mui-focused":{bgcolor:"common.white"},"&.Mui-focused fieldset":{borderColor:"#2932e5",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px"}},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:a,edge:"end",sx:{mr:-.5},children:e.jsx(w.Close,{sx:{fontSize:16}})})}):null}}),O&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[k.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"}),k.map((R,U)=>e.jsx(Yn,{entry:R,isSelected:b===U,onClick:()=>y(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>c(R.query)},`fav-${R.query}`))]}),D.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[k.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"}),D.map((R,U)=>{const J=k.length+U;return e.jsx(Yn,{entry:R,isSelected:b===J,onClick:()=>y(R.query),onToggleFavourite:()=>s(R.query),onDelete:()=>c(R.query)},`recent-${R.query}`)})]})]})]})}const Yn=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(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 dd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:u,onPermanentDelete:m,isReadOnly:f,isAdmin:b=!1}){const h=wt(),[g,z]=p.useState(!1),[v,j]=p.useState(!1),[S,y]=p.useState({top:0,left:0}),[T,a]=p.useState(null),k=p.useRef(null),D=p.useRef(null),O=t.find(M=>M.id===o),R=O==null?void 0:O.isDefault,U=t.filter(M=>M.scope==="global"&&!M.isDeleted),J=t.filter(M=>M.scope!=="global"&&!M.isDeleted),ee=t.filter(M=>M.isFavorite&&!M.isDeleted).sort((M,L)=>(L.updatedAt||0)-(M.updatedAt||0)),x=t.filter(M=>M.isDeleted);p.useEffect(()=>{if(g&&D.current){const M=D.current.getBoundingClientRect();y({top:M.bottom+window.scrollY+8,left:M.right+window.scrollX-320})}},[g]),p.useEffect(()=>{const M=L=>{k.current&&!k.current.contains(L.target)&&D.current&&!D.current.contains(L.target)&&z(!1)};return g&&document.addEventListener("mousedown",M),()=>{document.removeEventListener("mousedown",M)}},[g]);const N=M=>{if(n&&M!==o){a(M),z(!1);return}i(M),z(!1)},_=()=>{T&&(i(T),a(null))},H=()=>{a(null)},q=(M,L=!1)=>{const G=M.scope==="global",oe=!f&&(!G||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===M.id?h.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===M.id?h.palette.primary.light+"20":h.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>N(M.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===M.id&&e.jsx(w.Check,{sx:{fontSize:16,flexShrink:0}}),o!==M.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===M.id?h.palette.primary.dark:h.palette.text.primary,fontWeight:o===M.id?500:400},children:M.name}),L&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:h.palette.text.secondary,backgroundColor:h.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:[oe&&l&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),l(M.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:h.palette.grey[200]}},title:M.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(w.Star,{sx:{fontSize:16}})}),oe&&d&&!M.isDefault&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),d(M.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:h.palette.grey[200]}},title:"Set as default",children:e.jsx(w.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},M.id)},de=M=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:h.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:h.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:M.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[u&&e.jsx(r.IconButton,{onClick:L=>{L.stopPropagation(),u(M.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:h.palette.grey[200]}},title:"Restore view",children:e.jsx(w.Undo,{sx:{fontSize:16,color:"success.main"}})}),m&&e.jsx(r.IconButton,{onClick:L=>{L.stopPropagation(),m(M.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:h.palette.grey[200]}},title:"Delete permanently",children:e.jsx(w.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},M.id),ue=n||!R,re=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:D,onClick:()=>z(!g),size:"small",sx:{position:"relative",color:ue?"warning.main":"text.secondary",bgcolor:ue?E(h.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ue?E(h.palette.warning.main,.2):E(h.palette.text.primary,.06),color:ue?"warning.dark":"text.primary"}},title:`View: ${(O==null?void 0:O.name)||"Default View"}`,children:[e.jsx(w.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&&ni.createPortal(e.jsxs(r.Box,{ref:k,sx:{position:"fixed",width:"320px",backgroundColor:h.palette.background.paper,border:`1px solid ${h.palette.divider}`,borderRadius:1,boxShadow:h.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:S.top,left:S.left},children:[U.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:h.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),U.map(M=>q(M,M.isDefault))]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${h.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:h.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(M=>q(M))]})]}),J.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${h.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:h.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),J.map(M=>q(M))]})]}),x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${h.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>j(!v),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:h.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:h.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",x.length,")"]}),e.jsx(w.ChevronRight,{sx:{fontSize:16}})]}),v&&e.jsx(r.Box,{sx:{backgroundColor:h.palette.grey[50]},children:x.map(M=>de(M))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${h.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{s(),z(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:h.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:h.palette.grey[50]}},children:[e.jsx(w.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),z(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:h.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:h.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:T!==null,onClose:H,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(w.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:H,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:_,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function ud({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:u,onSortDescending:m,onRemoveSort:f,onFilter:b,onClearFilter:h,onGroupByColumn:g,onHideColumn:z,onManageColumns:v,onManageViews:j,onResetLayout:S,onClose:y}){var ee,x;const a=wt().palette,k=p.useRef(null);p.useEffect(()=>{if(!k.current)return;const N=k.current,_=N.getBoundingClientRect(),H=window.innerWidth,q=window.innerHeight;_.right>H-8&&(N.style.left=`${H-_.width-8}px`),_.bottom>q-8&&(N.style.top=`${q-_.height-8}px`)},[l]),p.useEffect(()=>{const N=H=>{k.current&&!k.current.contains(H.target)&&y()},_=H=>{H.key==="Escape"&&y()};return document.addEventListener("mousedown",N),document.addEventListener("keydown",_),()=>{document.removeEventListener("mousedown",N),document.removeEventListener("keydown",_)}},[y]);const D=p.useCallback(N=>()=>{N(),y()},[y]),O=(n==null?void 0:n.direction)==="asc",R=(n==null?void 0:n.direction)==="desc",U=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",J=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return ni.createPortal(e.jsxs(r.Paper,{ref:k,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(((ee=a.common)==null?void 0:ee.black)??"#000",.12)}, 0 1px 4px ${E(((x=a.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 (${U})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:D(()=>u(t)),sx:{p:.625,borderRadius:"6px",color:O?"primary.main":"text.secondary",bgcolor:O?E(a.primary.main,.1):"transparent","&:hover":{bgcolor:E(a.primary.main,.08),color:"primary.main"}},children:e.jsx(w.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${J})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:D(()=>m(t)),sx:{p:.625,borderRadius:"6px",color:R?"primary.main":"text.secondary",bgcolor:R?E(a.primary.main,.1):"transparent","&:hover":{bgcolor:E(a.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:D(()=>f(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(a.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:D(()=>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:D(()=>h(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(a.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:D(()=>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:D(()=>z(t)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),e.jsx(r.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:D(v),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(a.primary.main,.08),color:"primary.main"}},children:e.jsx(w.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:D(v),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:D(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&&S&&e.jsxs(r.MenuItem,{onClick:D(S),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(a.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 pd=150,Gn="COLUMN_HEADER",xd=p.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:u,onColumnClick:m,onMoveColumn:f,onResizeStart:b,onSortAscending:h,onSortDescending:g,onRemoveSort:z,onOpenFilterForColumn:v,onClearFiltersForColumn:j,onGroupByColumn:S,onHideColumn:y,onManageColumns:T,onManageViews:a,onResetLayout:k}){const D=p.useRef(null),[O,R]=p.useState(!1),[U,J]=p.useState({x:0,y:0}),[{handlerId:ee,isOver:x},N]=jt.useDrop({accept:Gn,collect(G){return{handlerId:G.getHandlerId(),isOver:G.isOver()}},hover(G,oe){var se;if(!D.current)return;const Q=G.index,le=n;if(Q===le)return;const ne=(se=D.current)==null?void 0:se.getBoundingClientRect(),P=(ne.right-ne.left)/2,te=oe.getClientOffset(),ie=((te==null?void 0:te.x)??0)-ne.left;Q<le&&ie<P||Q>le&&ie>P||(f(Q,le),G.index=le)}}),[{isDragging:_},H]=jt.useDrag({type:Gn,item:()=>({index:n,columnName:o.name}),collect:G=>({isDragging:G.isDragging()})});H(N(D));const q=p.useCallback(G=>{G.preventDefault(),G.stopPropagation(),J({x:G.clientX,y:G.clientY}),R(!0)},[]),de=p.useCallback(()=>R(!1),[]),ue=p.useCallback(()=>{m(o.name)},[m,o.name]),re=p.useCallback(G=>{G.stopPropagation(),v(o.name)},[v,o.name]),M=p.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]),L=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:D,"data-handler-id":ee,"data-column-index":n,onClick:ue,onContextMenu:q,sx:{position:"sticky",top:0,zIndex:5,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"hidden",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:_?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:x?G=>E(G.palette.primary.main,.08):"action.hover",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`:`${pd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center"},children:[Ve(o.name),M(),L()]}),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"}})]}),O&&e.jsx(ud,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:c,isReadOnly:d,hasModifications:l,position:U,onSortAscending:h,onSortDescending:g,onRemoveSort:z,onFilter:v,onClearFilter:j,onGroupByColumn:S,onHideColumn:y,onManageColumns:T,onManageViews:a,onResetLayout:k,onClose:de})]})});function md({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]),f=p.useMemo(()=>m.filter(S=>n.has(S)),[m,n]),b=p.useMemo(()=>m.filter(S=>!n.has(S)),[m,n]),h=f.length>0,g=b.length>0;if(t===0)return null;const z=()=>{d&&d(m,!0)},v=()=>{d&&d(m,!1)},j=S=>{s(S),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:S=>E(S.palette.primary.main,.08),borderBottom:S=>`1px solid ${E(S.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(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:S=>E(S.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:S=>u(S.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:S=>E(S.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:S=>E(S.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:l,open:!!l,onClose:()=>u(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:180,borderRadius:1.5}},children:[e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>j("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:z,startIcon:e.jsx(w.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:S=>E(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>E(S.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&h&&e.jsx(r.Button,{onClick:v,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:S=>E(S.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:S=>E(S.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const fd={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"}},hd={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function gd(t){const o=t.toLowerCase().trim(),n=fd[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 yd(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 gd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=hd[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 bd(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 vd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:s,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:u,onEdit:m,onDuplicate:f,onDelete:b}){const[h,g]=p.useState(null),[z,v]=p.useState(!1),{primaryCol:j,idCol:S,bodyColumns:y}=p.useMemo(()=>bd(n),[n]),T=j?t[j.name]:null,a=S?t[S.name]:null,k=z||i||s||!!h;return e.jsxs(r.Box,{onMouseEnter:()=>v(!0),onMouseLeave:()=>v(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":D=>E(D.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?D=>`0 0 0 3px ${E(D.palette.primary.main,.15)}, 0 2px 8px ${E(D.palette.common.black,.08)}`:z?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:z&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:D=>E(D.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:T!=null&&T!==""?String(T):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:[y.map(D=>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:Ve(D.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:yd(D,t[D.name])})]},D.name)),y.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:D=>E(D.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:a?.85:0,userSelect:"none"},children:a?String(a):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:k?1:0,transition:"opacity 0.15s ease"},onClick:D=>D.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:D=>{D.stopPropagation(),l(t)},sx:{width:28,height:28,color:s?"#fbbc04":"action.disabled","&:hover":{bgcolor:D=>E(D.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:D=>{D.stopPropagation(),g(D.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:D=>E(D.palette.text.primary,.08)}},children:e.jsx(w.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!h,anchorEl:h,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:D=>D.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(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 Sd({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(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:di(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])=>ci(c)).filter(Boolean).join(" • ")})]})}function jd({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:s,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:u,onToggleRowSelection:m,onToggleRowFavorite:f,onToggleGroupCollapse:b,onViewRow:h,onEditRow:g,onDuplicateRow:z,onDeleteRow:v}){const j=p.useMemo(()=>{const S=new Set;return i.forEach(y=>{const T=y==null?void 0:y.__urm_row_id__;T!==void 0&&S.add(T)}),S},[i]);return t.length===0?e.jsx(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):e.jsxs(r.Box,{children:[u&&o.length>0&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,px:2,py:1,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper",flexWrap:"wrap"},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontWeight:500,mr:.5,whiteSpace:"nowrap"},children:"Sort by:"}),o.map(S=>{const y=l.find(T=>T.column===S.name);return e.jsxs(r.Box,{onClick:()=>u(S.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:y?"primary.main":"divider",bgcolor:y?T=>E(T.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:T=>E(T.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:y?600:400,color:y?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ve(S.name)}),y?y.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"}})]},S.name)})]}),e.jsx(r.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(272px, 1fr))",gap:1.5,alignContent:"start"},children:t.map((S,y)=>d&&S.isGroupHeader?e.jsx(Sd,{row:S,grouping:n,onToggleCollapse:b||(()=>{})},`group-${S.groupKey}`):e.jsx(vd,{row:S,rowIndex:y,visibleColumns:o,isSelected:j.has(S==null?void 0:S.__urm_row_id__),isFavorite:s.has(S),isReadOnly:c,onToggleSelection:()=>m(S),onToggleFavorite:f,onView:h,onEdit:g,onDuplicate:z,onDelete:v},`card-${y}`))})]})}const qn=[10,15,25,50,100];function Cd(t,o){const n=t.trim();if(n==="")return"Page number is required";if(!/^-?\d+$/.test(n))return"Must be a number";const i=parseInt(n,10);return i<1?"Page number must be at least 1":i>o?"Entered page number is out of range":null}function wd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:c}){var N;const l=wt().palette,u=Math.ceil(n/o),[m,f]=p.useState(String(t)),[b,h]=p.useState(null),[g,z]=p.useState(!1),v=p.useRef(null);p.useEffect(()=>{g||(f(String(t)),h(null))},[t,g]);const j=p.useCallback(()=>{const _=Cd(m,u);if(_){h(_);return}const H=parseInt(m.trim(),10);h(null),z(!1),H!==t&&s(H)},[m,u,t,s]),S=p.useCallback(_=>{var H;_.key==="Enter"?(_.preventDefault(),j()):_.key==="Escape"&&(f(String(t)),h(null),z(!1),(H=v.current)==null||H.blur())},[j,t]),y=p.useCallback(()=>{f(String(t)),h(null),z(!1)},[t]),T=p.useCallback(()=>{z(!0),h(null),setTimeout(()=>{var _;return(_=v.current)==null?void 0:_.select()},0)},[]);if(n<=Math.min(...qn))return null;const a=()=>{f(String(t)),h(null),z(!1)},k=()=>{a(),s(1)},D=()=>{a(),t>1&&s(t-1)},O=()=>{a(),t<u&&s(t+1)},R=()=>{a(),s(u)},U=(t-1)*o+1,J=Math.min(t*o,n),ee=`${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:_=>c(Number(_.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:qn.map(_=>e.jsx(r.MenuItem,{value:_,sx:{fontSize:"0.8125rem"},children:_},_))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[U,"–",J," 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:v,value:m,onChange:_=>{f(_.target.value),b&&h(null)},onKeyDown:S,onFocus:T,onBlur:y,inputProps:{"aria-label":`Page number, 1 to ${u}`,style:{textAlign:"center",padding:"2px 0",width:ee,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":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:k,disabled:t===1,size:"small",title:"First page",sx:x,children:e.jsx(w.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:D,disabled:t===1,size:"small",title:"Previous page",sx:x,children:e.jsx(w.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:O,disabled:t===u,size:"small",title:"Next page",sx:x,children:e.jsx(w.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:R,disabled:t===u,size:"small",title:"Last page",sx:x,children:e.jsx(w.LastPage,{sx:{fontSize:20}})})]})]})]})}function kd(){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 Wi="urm_hint_seen_";function Td(t){try{return localStorage.getItem(Wi+t)==="true"}catch{return!1}}function zd(t){try{localStorage.setItem(Wi+t,"true")}catch{}}function Jn(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 Kn(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 Xn(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 Id({open:t,onClose:o,row:n,schema:i,reportName:s}){var b,h;const d=wt().palette;if(!n)return null;const l=i.filter(g=>g.name in n),u=l.filter(g=>g.type!=="object"&&g.type!=="array"),m=l.filter(g=>g.type==="object"||g.type==="array"),f=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${E(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${E(((h=d.common)==null?void 0:h.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(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: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,z)=>{const v=n[g.name],j=Jn(v,g.type),S=!j,y=Xn(g.type,d),T=z===u.length-1&&u.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:T?"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:y.bg,color:y.color,flexShrink:0},children:Kn(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:Ve(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:S?400:500,color:S?"text.disabled":"text.primary",fontStyle:S?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:S?"No value":j})]},g.name)})}),m.map(g=>{const z=n[g.name],v=Jn(z,g.type),j=!v,S=Xn(g.type,d);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:S.bg,color:S.color},children:Kn(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ve(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:S.bg,color:S.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:E(d.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:j?"text.disabled":"text.primary",fontStyle:j?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:j?"No value":v})]},g.name)}),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 Ed({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 Po(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 Zn(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 Bd({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:c}){var j,S,y;const l=wt().palette,[u,m]=p.useState({});if(p.useEffect(()=>{t&&i&&m({...i})},[t,i]),!i)return null;const f=s.filter(T=>T.name in i),b=f.filter(T=>T.type!=="object"&&T.type!=="array"),h=f.filter(T=>T.type==="object"||T.type==="array"),g=(T,a)=>{m(k=>({...k,[T]:a}))},z=()=>{const T={...u};f.forEach(a=>{const k=u[a.name];if(a.type==="number"){const D=Number(k);T[a.name]=isNaN(D)?i[a.name]:D}else a.type==="boolean"&&(T[a.name]=!!k)}),n(T),o()},v=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 ${E(((j=l.common)==null?void 0:j.black)??"#000",.14)}, 0 2px 8px ${E(((S=l.common)==null?void 0:S.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:E(((y=l.warning)==null?void 0:y.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," · ",v," ",v===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.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((T,a)=>{const k=u[T.name],D=Zn(T.type,l),O=T.type==="boolean",R=!O&&a===b.filter(J=>J.type!=="boolean").length-1&&b.filter(J=>J.type!=="boolean").length%2!==0,U=O||R;return T.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:D.bg,color:D.color},children:Po(T.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ve(T.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:k?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!k,onChange:J=>g(T.name,J.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},T.name):e.jsxs(r.Box,{sx:{gridColumn:U?"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:D.bg,color:D.color},children:Po(T.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:Ve(T.name)})]}),e.jsx(r.TextField,{value:k??"",onChange:J=>g(T.name,J.target.value),type:T.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${T.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:T.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},T.name)})})]}),h.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:h.map(T=>{const a=i[T.name];let k="";try{k=a==null?"":JSON.stringify(a,null,2)}catch{k=String(a)}const D=Zn(T.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:D.bg,color:D.color},children:Po(T.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ve(T.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:k?"text.primary":"text.disabled",fontStyle:k?"normal":"italic",bgcolor:E(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:k||"No value"})]},T.name)})})]}),f.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(w.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:z,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const Dd=160,Od={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"}},Md={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Ad(t){const o=t.toLowerCase().trim(),n=Od[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 $d(t){const o=t.toLowerCase().trim(),n=Md[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Rd(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 _d(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 Wd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Pd(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 Ad(s);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return $d(s);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(s);if(u)return Rd(s);if(n&&!d&&!l&&!u)return Wd(s);if(t.type==="date"){const m=t.dateFormat??"iso",f=Rs(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 Nd({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:u={},columnOrder:m=[],columnWidths:f={},grouping:b=null,onSort:h,onSortAscending:g,onSortDescending:z,onOpenFilters:v,onOpenSort:j,onOpenFilterForColumn:S,onSelectView:y,onCreateView:T,onManageViews:a,onUpdateCurrentView:k,onSaveAsNewView:D,onToggleDefault:O,onToggleFavorite:R,onRestoreView:U,onPermanentDelete:J,isAdmin:ee=!1,onExport:x,onOpenColumns:N,onUpdateColumnWidth:_,onUpdateColumnOrder:H,onUpdateColumnVisibility:q,onClearFiltersForColumn:de,onResetLayout:ue,onOpenGroup:re,onGroupByColumn:M,onToggleGroupCollapse:L,onOpenAuditHistory:G,onOpenScheduledReports:oe,searchQuery:Q,searchHistory:le=[],onAddToSearchHistory:ne,onToggleSearchFavourite:P,onDeleteSearchHistory:te,selectedRowIds:ie=new Set,onSearchChange:se,onToggleRowSelection:je,onToggleAllRows:Y,onRangeSelection:Oe,onClearSelection:Ae,onExportSelected:dt,currentPage:br=1,pageSize:kt=15,totalRowsBeforePagination:Tt=o.length,onPageChange:qe,onPageSizeChange:_e,isReadOnly:Me=!1,userRole:zt,reportName:ut,onEditRow:pt,onDuplicateRow:Je,onDeleteRow:It,favoriteRowIndices:qt=[],resolvedFavoritesSet:Ke=new Set,showFavoritesOnly:Xe=!1,onToggleRowFavorite:We,onBulkSetFavorites:xt,showDevPanel:Mt=!1,onOpenDevConfig:Jt,onToggleFavoritesFilter:mt}){var Nt;const[Kt,vr]=p.useState(null),[Xt,Zt]=p.useState(0),[Qt,er]=p.useState(0),Ce=((Nt=yr().dates)==null?void 0:Nt.displayFormat)??null,[At,Sr]=p.useState(null),[Qe,F]=p.useState(null),[et,pe]=p.useState(null),[Pe,Et]=p.useState(!1),[jr,ot]=p.useState(!1),[tr,ft]=p.useState(null),[$t,rr]=p.useState(""),[Cr,ke]=p.useState(!1),[K,nt]=p.useState(null),[ye,or]=p.useState(null),[fe,tt]=p.useState(null),[wr,it]=p.useState(null),[Re,nr]=p.useState("list"),[kr,Rt]=p.useState(!1),[Tr,ir]=p.useState(()=>!Td("toolbar_search"));p.useRef(null);const zr=p.useCallback(()=>{zd("toolbar_search"),ir(!1)},[]),_t=p.useMemo(()=>m.length>0?m.map(I=>t.find(V=>V.name===I)).filter(I=>I!==void 0):t,[m,t]),Ue=p.useMemo(()=>_t.filter(I=>u[I.name]!==!1),[_t,u]),Ne=p.useMemo(()=>t.filter(I=>u[I.name]===!1).length,[t,u]),rt=p.useMemo(()=>t.map(I=>I.name),[t]),ht=p.useMemo(()=>JSON.stringify(m)!==JSON.stringify(rt),[m,rt]),Wt=p.useCallback((I,V)=>{I.preventDefault(),I.stopPropagation(),vr(V),Zt(I.clientX),er(f[V]||150)},[f]);p.useEffect(()=>{if(!Kt)return;const I=ae=>{const $e=ae.clientX-Xt,ce=Math.max(100,Qt+$e);_==null||_(Kt,ce)},V=()=>{vr(null)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",V),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",V)}},[Kt,Xt,Qt,_]);const Ir=p.useCallback(I=>I==null?"-":typeof I=="object"?JSON.stringify(I):typeof I=="boolean"?I?"true":"false":String(I),[]);p.useCallback(I=>{const V=n.find(ae=>ae.column===I);return V?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[V.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:V.priority})]}):null},[n]),p.useCallback(I=>i.some(ae=>ae.column===I)?e.jsx(r.IconButton,{size:"small",onClick:ae=>{ae.stopPropagation(),S==null||S(I)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(w.FilterList,{sx:{fontSize:14}})}):null,[i,S]);const Er=p.useCallback(I=>{h&&h(I)},[h]),Br=p.useCallback((I,V)=>{if(!H)return;const ae=[...m.length>0?m:t.map(ce=>ce.name)],[$e]=ae.splice(I,1);ae.splice(V,0,$e),H(ae)},[H,m,t]),Dr=p.useCallback(I=>{if(!h)return;const V=n.find(ae=>ae.column===I);(!V||V.direction!=="asc")&&h(I)},[h,n]),Or=p.useCallback(I=>{if(!h)return;const V=n.find(ae=>ae.column===I);V?V.direction==="asc"&&h(I):(h(I),setTimeout(()=>h(I),0))},[h,n]),Mr=p.useCallback(I=>{if(!h)return;const V=n.find(ae=>ae.column===I);V&&(V.direction==="asc"?(h(I),setTimeout(()=>h(I),0)):V.direction==="desc"&&h(I))},[h,n]),sr=p.useCallback(I=>{q&&q(I,!1)},[q]),ar=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Ar=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(I=>I===!1),$r=(br-1)*kt,Be=o,gt=p.useMemo(()=>{const I=new Set;return ie.forEach(V=>{const ae=V==null?void 0:V.__urm_row_id__;ae!==void 0&&I.add(ae)}),I},[ie]);p.useEffect(()=>{const I=V=>{!Y||!Ae||V.target instanceof HTMLInputElement||V.target instanceof HTMLTextAreaElement||((V.ctrlKey||V.metaKey)&&V.key==="a"&&(V.preventDefault(),Y(!0,Be)),V.key==="Escape"&&(V.preventDefault(),Ae()))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[Y,Ae,Be]);const lr=p.useCallback((I,V)=>{je&&(V.shiftKey&&At!==null?(V.preventDefault(),Oe&&Oe(At,I,Be)):(je(Be[I]),Sr(I)))},[je,At,Oe,Be]);!p.useMemo(()=>Be.length>0&&gt.size>0&&Be.every(I=>gt.has(I==null?void 0:I.__urm_row_id__)),[Be,gt])&&Be.some(I=>gt.has(I==null?void 0:I.__urm_row_id__));const yt=je&&Y,dr=p.useCallback(I=>{var $e;const V=I.groupLevel,ae=V*24;return e.jsx(r.TableRow,{onClick:()=>L==null?void 0:L(I.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Ue.length+(yt?1:0),sx:{pl:`${ae+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[I.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:di(V,(($e=b==null?void 0:b.levels[V])==null?void 0:$e.column)||"",I.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:ce=>E(ce.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[I.rowCount," ",I.rowCount===1?"row":"rows"]}),Object.keys(I.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(I.aggregates).map(([ce,Ft])=>ci(Ft)).filter(Boolean).join(" • ")})]})})},I.groupKey)},[Ue,yt,b,L]),Pt=p.useCallback((I,V)=>{const ae=gt.has(I==null?void 0:I.__urm_row_id__),$e=Qe===V;return e.jsxs(r.TableRow,{"data-row-index":V,onMouseEnter:()=>F(V),onMouseLeave:()=>F(null),onClick:ce=>{!je||ce.target.closest("[data-row-action]")||lr(V,ce)},onContextMenu:ce=>{ce.preventDefault(),ce.stopPropagation(),tt({mouseX:ce.clientX,mouseY:ce.clientY,row:I,rowIndex:V})},sx:{height:34,cursor:"pointer",bgcolor:ae?ce=>E(ce.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:ae?ce=>E(ce.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Ue.map((ce,Ft)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"none",minWidth:f[ce.name]?`${f[ce.name]}px`:`${Dd}px`},children:Pd(ce,I[ce.name],_d(ce,Ue),Ce)},ce.name)),e.jsxs(r.TableCell,{"data-row-action":"true",onClick:ce=>ce.stopPropagation(),sx:{position:"sticky",right:0,width:We?76:40,minWidth:We?76:40,maxWidth:We?76:40,p:0,border:"none",bgcolor:"transparent",opacity:$e?1:0,transition:"opacity 0.12s ease",zIndex:2,verticalAlign:"middle",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:.25},children:[We&&e.jsx(r.IconButton,{size:"small",onClick:ce=>{ce.stopPropagation(),ce.preventDefault(),We(I)},title:Ke.has(I)?"Remove from favorites":"Add to favorites",sx:{color:Ke.has(I)?"warning.main":"text.secondary","&:hover":{bgcolor:ce=>E(ce.palette.warning.main,.08),color:"warning.main"}},children:Ke.has(I)?e.jsx(w.Star,{sx:{fontSize:18}}):e.jsx(w.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:ce=>{ce.stopPropagation(),ce.preventDefault(),tt({anchorEl:ce.currentTarget,row:I,rowIndex:V})},sx:{color:"text.secondary","&:hover":{bgcolor:ce=>E(ce.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(w.MoreVert,{sx:{fontSize:18}})})]})]},V)},[ie,$r,Qe,lr,Ue,f,Ir,pt,Je,It,je,We,Ke,pe,Et,tt]);return e.jsxs(jt.DndProvider,{backend:Yo.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[yt&&dt&&Ae&&e.jsx(md,{selectedCount:ie.size,selectedRowIds:ie,resolvedFavoritesSet:Ke,viewMode:Re,onExportSelected:dt,onClearSelection:Ae,onBulkSetFavorites:xt}),e.jsxs(r.Box,{sx:{position:"sticky",top:0,zIndex:10,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",px:2,py:0,height:56,display:"flex",alignItems:"center",gap:1},children:[Me&&e.jsx(kd,{}),se&&ne&&P&&te&&e.jsx(r.Tooltip,{open:Tr,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:zr},componentsProps:{tooltip:{sx:{bgcolor:"primary.main","& .MuiTooltip-arrow":{color:"primary.main"},maxWidth:220,cursor:"pointer",userSelect:"none"}}},children:e.jsx(r.Box,{component:"span",children:e.jsx(cd,{value:Q||"",onChange:se,searchHistory:le,onAddToHistory:ne,onToggleFavourite:P,onDeleteHistory:te,disabled:Me})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>Rt(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:I=>E(I.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})})}),mt&&e.jsx(r.Tooltip,{title:Xe?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:mt,size:"small",disabled:Me,sx:{position:"relative",color:Xe?"warning.main":"text.secondary",bgcolor:Xe?I=>E(I.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Xe?I=>E(I.palette.warning.main,.2):I=>E(I.palette.text.primary,.06),color:Xe?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[Xe?e.jsx(w.Star,{sx:{fontSize:20}}):e.jsx(w.StarBorder,{sx:{fontSize:20}}),Xe&&qt.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:qt.length})]})}),Mt&&Jt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:Jt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:I=>E(I.palette.text.secondary,.3),"&:hover":{bgcolor:I=>E(I.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(w.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),y&&T&&a&&k&&s.length>0&&e.jsx(dd,{views:s||[],activeViewId:c||"",isDirty:d,onSelectView:y,onCreateView:T,onManageViews:a,onToggleDefault:O,onToggleFavorite:R,onRestoreView:U,onPermanentDelete:J,isAdmin:ee,isReadOnly:Me}),!Me&&j&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:j,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?I=>E(I.palette.primary.main,.2):I=>E(I.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Me&&v&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:v,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?I=>E(I.palette.primary.main,.2):I=>E(I.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Me&&N&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:N,size:"small",sx:{position:"relative",color:Ne>0||ht?"primary.main":"text.secondary",bgcolor:Ne>0||ht?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Ne>0||ht?I=>E(I.palette.primary.main,.2):I=>E(I.palette.text.primary,.06),color:Ne>0||ht?"primary.main":"text.primary"}},children:[e.jsx(w.ViewColumn,{sx:{fontSize:20}}),Ne>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:Ne})]})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"List view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>nr("list"),sx:{borderRadius:1,color:Re==="list"?"primary.main":"text.secondary",bgcolor:Re==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Re==="list"?I=>E(I.palette.primary.main,.2):I=>E(I.palette.text.primary,.06),color:Re==="list"?"primary.main":"text.primary"}},children:e.jsx(w.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>nr("grid"),sx:{borderRadius:1,color:Re==="grid"?"primary.main":"text.secondary",bgcolor:Re==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Re==="grid"?I=>E(I.palette.primary.main,.2):I=>E(I.palette.text.primary,.06),color:Re==="grid"?"primary.main":"text.primary"}},children:e.jsx(w.GridView,{sx:{fontSize:20}})})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"Settings",children:e.jsx(r.IconButton,{onClick:I=>it(I.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:I=>E(I.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!wr,anchorEl:wr,onClose:()=>it(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(),it(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"})]}),!Me&&re&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{re(),it(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"})]}),G&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{G(),it(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"})]}),oe&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{oe(),it(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",overflow:"hidden",flex:1,display:"flex",flexDirection:"column"},children:[Re==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(jd,{data:Be,visibleColumns:Ue,grouping:b,selectedRowIds:ie,resolvedFavoritesSet:Ke,isReadOnly:Me,isGrouped:!!ar,sortStack:n,onSort:h,onToggleRowSelection:je||(()=>{}),onToggleRowFavorite:We,onToggleGroupCollapse:L,onViewRow:I=>{pe(I),Et(!0)},onEditRow:(I,V)=>{nt(I),or(V),ke(!0)},onDuplicateRow:(I,V)=>Je==null?void 0:Je(I,V),onDeleteRow:(I,V)=>{ft(V);const ae=Object.values(V).find($e=>$e!=null&&$e!=="");rr(ae?String(ae):""),ot(!0)}})}),Re==="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:I=>I.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:I=>I.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",width:"100%",minWidth:"100%"},stickyHeader:!0,children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Ue.map((I,V)=>e.jsx(xd,{column:I,index:V,sortRule:n.find(ae=>ae.column===I.name),hasFilters:i.some(ae=>ae.column===I.name),isInSortStack:n.some(ae=>ae.column===I.name),isReadOnly:Me,hasModifications:Ar,width:f[I.name],onColumnClick:Er,onMoveColumn:Br,onResizeStart:Wt,onSortAscending:g||Dr,onSortDescending:z||Or,onRemoveSort:Mr,onOpenFilterForColumn:S||(()=>{}),onClearFiltersForColumn:de||(()=>{}),onGroupByColumn:M,onHideColumn:sr,onManageColumns:N||(()=>{}),onManageViews:a,onResetLayout:ue},I.name)),e.jsx(r.TableCell,{sx:{position:"sticky",top:0,right:0,width:We?76:40,minWidth:We?76:40,p:0,border:"none",bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider",zIndex:6}})]})}),e.jsx(r.TableBody,{children:Be.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Ue.length+(yt?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):ar?Be.map((I,V)=>I.isGroupHeader?dr(I):Pt(I,V)):Be.map((I,V)=>Pt(I,V))})]})}),qe&&_e&&e.jsx(wd,{currentPage:br,pageSize:kt,totalRows:Tt,totalFields:t.length,onPageChange:qe,onPageSizeChange:_e}),!(qe&&_e)&&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 ",Be.length," ",Be.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!fe,onClose:()=>tt(null),anchorEl:(fe==null?void 0:fe.anchorEl)||null,anchorReference:fe!=null&&fe.anchorEl?"anchorEl":"anchorPosition",anchorPosition:fe&&!fe.anchorEl?{top:fe.mouseY,left:fe.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:fe!=null&&fe.anchorEl?{vertical:"top",horizontal:"right"}:{vertical:"top",horizontal:"left"},PaperProps:{sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3}},children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{fe&&(pe(fe.row),Et(!0)),tt(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:()=>{fe&&(nt(fe.row),or(fe.rowIndex),ke(!0)),tt(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:()=>{fe&&(Je==null||Je(fe.rowIndex,fe.row)),tt(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(fe){ft(fe.row);const I=Object.values(fe.row).find(V=>V!=null&&V!=="");rr(I?String(I):""),ot(!0)}tt(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(Id,{open:Pe,onClose:()=>{Et(!1),pe(null)},row:et,schema:t,reportName:ut}),e.jsx(Bd,{open:Cr,onClose:()=>{ke(!1),nt(null),or(null)},onSave:I=>{ye!==null&&(pt==null||pt(ye,I))},row:K,schema:t,reportName:ut}),e.jsx(Ed,{open:jr,onClose:()=>{ot(!1),ft(null)},onConfirm:()=>{tr!==null&&(It==null||It(tr))},rowPreview:$t}),e.jsx(Ri,{isOpen:kr,onClose:()=>Rt(!1)})]})}function Yt({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(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=>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 Gt={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 Fd({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:c,onClose:d,focusColumn:l}){const[u,m]=p.useState(""),[f,b]=p.useState(""),[h,g]=p.useState(""),[z,v]=p.useState([]),j=yr();p.useEffect(()=>{v([...o])},[o]),p.useEffect(()=>{l&&m(l)},[l]);const S=p.useCallback(()=>{m(""),b(""),g("")},[]),y=p.useMemo(()=>t.filter(x=>x.type!=="mixed"&&x.type!=="null"&&x.type!=="array"&&x.type!=="object"),[t]),T=t.find(x=>x.name===u),a=p.useMemo(()=>{const x=T?yn(T.type):[],N=j.filter.allowedOperators;return N.length>0?x.filter(_=>N.includes(_.value)):x},[T]),k=p.useCallback(()=>!(!u||!f||Zr(f)&&!h.trim()||z.length>=j.filter.maxConditions),[u,f,h,z,j]),D=p.useCallback(()=>{if(!k())return;const x={column:u,operator:f};if(Zr(f)){const _=T==null?void 0:T.type;x.value=_==="number"?Number(h):h}if(z.some(_=>_.column===x.column&&_.operator===x.operator&&_.value===x.value)){S();return}v([...z,x]),S()},[k,u,f,T,h,z,S]),O=p.useCallback(x=>{v(z.filter((N,_)=>_!==x))},[z]),R=p.useMemo(()=>z.length!==o.length?!0:JSON.stringify(z)!==JSON.stringify(o),[z,o]),U=p.useCallback(()=>{c(),z.forEach(x=>n(x)),d()},[z,n,c,d]),J=p.useCallback(()=>{v([...o]),S(),d()},[o,S,d]),ee=p.useCallback(x=>{var q;const N=t.find(de=>de.name===x.column);if(!N)return"";const H=((q=yn(N.type).find(de=>de.value===x.operator))==null?void 0:q.label)||x.operator;return Zr(x.operator)?`${x.column} ${H.toLowerCase()} "${x.value}"`:`${x.column} ${H.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:J,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(Yt,{content:Gt.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:J,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"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,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:y.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:[Ve(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:f,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:a.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))})]}),f&&Zr(f)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(T==null?void 0:T.type)==="number"?"number":"text",value:h,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:D,disabled:!k(),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"})]}),z.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 (",z.length,")"]}),e.jsx(r.Button,{onClick:()=>v([]),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:z.map((x,N)=>e.jsx(r.Chip,{label:ee(x),onDelete:()=>O(N),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:_=>`1px solid ${E(_.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:_=>E(_.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:J,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:U,disabled:!R,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 Qn="SORT_RULE";function Ld({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const c=p.useRef(null),[{handlerId:d},l]=jt.useDrop({accept:Qn,collect(f){return{handlerId:f.getHandlerId()}},hover(f,b){var y;if(!c.current)return;const h=f.index,g=o;if(h===g)return;const z=(y=c.current)==null?void 0:y.getBoundingClientRect(),v=(z.bottom-z.top)/2,j=b.getClientOffset(),S=((j==null?void 0:j.y)??0)-z.top;h<g&&S<v||h>g&&S>v||(s(h,g),f.index=g)}}),[{isDragging:u},m]=jt.useDrag({type:Qn,item:()=>({index:o}),collect:f=>({isDragging:f.isDragging()})});return m(l(c)),e.jsxs(r.Box,{ref:c,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"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=>E(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=>E(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 Vd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,c]=p.useState(""),[d,l]=p.useState([]);p.useEffect(()=>{l([...o])},[o]);const u=yr(),m=p.useCallback(()=>!(d.length>=u.sort.maxLevels||!s||d.some(y=>y.column===s)),[d,s]),f=p.useCallback(()=>{if(!m())return;const y=d.length+1,T={column:s,direction:"asc",priority:y};l([...d,T]),c("")},[m,s,d]),b=p.useCallback(y=>{const a=d.filter((k,D)=>D!==y).map((k,D)=>({...k,priority:D+1}));l(a)},[d]),h=p.useCallback((y,T)=>{const a=[...d];a[y]={...a[y],direction:T},l(a)},[d]),g=p.useCallback((y,T)=>{const a=[...d],[k]=a.splice(y,1);a.splice(T,0,k);const D=a.map((O,R)=>({...O,priority:R+1}));l(D)},[d]),z=p.useCallback(()=>{l([])},[]),v=p.useCallback(()=>{n(d),i()},[d,n,i]),j=p.useCallback(()=>{l([...o]),c(""),i()},[o,i]),S=t.filter(y=>!d.some(T=>T.column===y.name));return e.jsx(jt.DndProvider,{backend:Yo.HTML5Backend,children:e.jsx(r.Box,{onClick:j,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:y=>y.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"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(Yt,{content:Gt.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:j,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"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>=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:y=>c(y.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:S.map(y=>e.jsx(r.MenuItem,{value:y.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:T=>E(T.palette.primary.main,.2)}}},children:Ve(y.name)},y.name))})]}),e.jsx(r.Button,{onClick:f,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:z,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((y,T)=>e.jsx(Ld,{rule:y,index:T,onToggleDirection:h,onRemove:b,onMove:g},`${y.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:j,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:v,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 Hd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:u,isAdmin:m=!1,onClose:f}){var T,a;const h=wt().palette,g=t.filter(k=>!k.isDeleted),z=t.filter(k=>k.isDeleted),v=g.filter(k=>k.scope==="global"),j=g.filter(k=>k.scope!=="global"),S=k=>{var J,ee,x,N,_;const D=k.scope==="global",O=k.id===o,R=m||!D,U=m&&!D;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:O?"primary.main":"divider",bgcolor:O?E(h.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:O?"primary.main":E(h.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(k.id),f()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:O?600:500,color:O?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.name}),k.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[D&&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:E(((J=h.info)==null?void 0:J.main)??h.primary.main,.1),color:((ee=h.info)==null?void 0:ee.main)??h.primary.main,border:`1px solid ${E(((x=h.info)==null?void 0:x.main)??h.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),k.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:E(h.text.secondary,.08),color:"text.secondary","& .MuiChip-label":{px:.75}}})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[U&&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(k.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((N=h.info)==null?void 0:N.main)??h.primary.main,bgcolor:E(((_=h.info)==null?void 0:_.main)??h.primary.main,.08)}},children:e.jsx(w.Language,{sx:{fontSize:16}})})}),R&&e.jsx(r.Tooltip,{title:D&&!m?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:D&&!m,onClick:H=>{H.stopPropagation(),s(k.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:E(h.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:D&&!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:D&&!m,onClick:H=>{H.stopPropagation(),c(k.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:E(h.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})})]})]})},k.id)},y=k=>{var D;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(h.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:k.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:O=>{O.stopPropagation(),d(k.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:E(((D=h.success)==null?void 0:D.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:O=>{O.stopPropagation(),l(k.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:E(h.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]},k.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 ${E(((T=h.common)==null?void 0:T.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"})}),v.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1},children:[e.jsx(w.Language,{sx:{fontSize:14,color:((a=h.info)==null?void 0:a.main)??h.primary.main}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Global Views"}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:"— visible to all users"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:v.map(S)})]}),j.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Personal Views"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:j.map(S)})]}),z.length>0&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.disabled",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Recently Deleted"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:z.map(y)})]}),g.length===0&&z.length===0&&e.jsx(r.Box,{sx:{py:4,textAlign:"center",color:"text.disabled"},children:e.jsx(r.Typography,{variant:"body2",children:"No views created yet"})})]}),e.jsx(r.DialogActions,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:f,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const oo=50;function ei({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:u=10}){const[m,f]=p.useState(s),[b,h]=p.useState(!1),[g,z]=p.useState(c),[v,j]=p.useState(d),S=()=>{if(!m.trim()){h(!0);return}if(m.trim().length>oo){h(!0);return}o(m.trim(),g.trim(),v),n()},y=a=>{a.key==="Enter"&&!a.shiftKey?S():a.key==="Escape"&&n()},T=()=>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:[T(),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 ",u," saved views. Delete an existing view before creating a new one."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:m,onChange:a=>{a.target.value.length<=oo&&f(a.target.value),b&&a.target.value.trim()&&h(!1)},onKeyDown:y,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:oo},error:b&&!m.trim(),helperText:b&&!m.trim()?"View name is required":`${m.length} / ${oo}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:a=>z(a.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: ",Js(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:v,onChange:a=>j(a.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:S,variant:"contained",disabled:l&&!i,startIcon:e.jsx(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 Ud({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 Ho=80,Uo=600,ti="COLUMN";function Yd({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:f},b]=jt.useDrop({accept:ti,collect(y){return{handlerId:y.getHandlerId()}},hover(y,T){var J;if(!l.current)return;const a=y.index,k=o;if(a===k)return;const D=(J=l.current)==null?void 0:J.getBoundingClientRect(),O=(D.bottom-D.top)/2,R=T.getClientOffset(),U=((R==null?void 0:R.y)??0)-D.top;a<k&&U<O||a>k&&U>O||(d(a,k),y.index=k)}}),[{isDragging:h},g]=jt.useDrag({type:ti,item:()=>({index:o}),collect:y=>({isDragging:y.isDragging()})});g(b(l));const z=()=>{const y=parseInt(u);if(isNaN(y)){m(i.toString()),c(t.name,i);return}const T=Math.max(Ho,Math.min(Uo,y));m(T.toString()),c(t.name,T)},v=y=>{if(y===""||/^\d+$/.test(y)){m(y);const T=parseInt(y);if(!isNaN(T)&&T>=Ho){const a=Math.min(Uo,T);c(t.name,a)}}},j=y=>{y.key==="Enter"&&(y.preventDefault(),z(),y.target.blur())},S=y=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[y]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":f,sx:{opacity:h?.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(w.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ve(t.name)})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsx(r.Chip,{label:t.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${S(t.type)}15`,color:S(t.type),border:`1px solid ${S(t.type)}30`,"& .MuiChip-label":{px:1}}})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.TextField,{type:"text",value:u,onChange:y=>v(y.target.value),onBlur:z,onKeyDown:j,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(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 Gd({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:u,onResetLayout:m,onSaveToCurrentView:f,onSaveToAllViews:b,onSelectView:h,onClose:g}){const[z,v]=p.useState(!1),[j,S]=p.useState(n),[y,T]=p.useState(i),[a,k]=p.useState("all"),[D,O]=p.useState(null);p.useEffect(()=>{S(n)},[n]),p.useEffect(()=>{T(i)},[i]);const R=(re,M)=>{T(L=>({...L,[re]:M}))},U=(re,M)=>{const L=[...j],[G]=L.splice(re,1);L.splice(M,0,G),S(L),l(L)},J=()=>{m(),v(!1)},x=j.map(re=>t.find(M=>M.name===re)).filter(re=>re!==void 0).filter(re=>{const M=o[re.name]??!0;return a==="active"?M:a==="hidden"?!M:!0}),N=Object.values(o).filter(re=>re).length,_=t.length,H=s.find(re=>re.id===c),q=s.filter(re=>!re.isDeleted),de=q.length>1,ue=p.useMemo(()=>{if(!H)return!1;const re=H.snapshot,M=JSON.stringify(o)!==JSON.stringify(re.columnVisibility),L=JSON.stringify(n)!==JSON.stringify(re.columnOrder),G=JSON.stringify(y)!==JSON.stringify(re.columnWidths);return M||L||G},[H,o,n,y]);return e.jsx(jt.DndProvider,{backend:Yo.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(Yt,{content:Gt.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 ",_," columns visible • Drag to reorder"]})]}),q.length>0&&h&&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=>O(re.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(H==null?void 0:H.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:D,open:!!D,onClose:()=>O(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:q.map(re=>e.jsx(r.MenuItem,{onClick:()=>{h(re.id),O(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:M=>E(M.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(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:a,onChange:(re,M)=>k(M),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: ${Ho}px, max: ${Uo}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: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,M)=>e.jsx(Yd,{column:re,index:M,isVisible:o[re.name]??!0,width:y[re.name]||150,onToggleVisibility:d,onWidthChange:R,moveColumn:U},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:()=>v(!0),disabled:!ue,variant:"outlined",startIcon:e.jsx(w.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[f&&e.jsx(r.Button,{onClick:()=>{f(y),g()},disabled:!ue,variant:"contained",startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&de&&e.jsx(r.Button,{onClick:()=>{b(y),g()},disabled:!ue||!de,variant:"contained",startIcon:e.jsx(w.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),z&&e.jsx(r.Box,{onClick:()=>v(!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:()=>v(!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:J,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 qd({schema:t,grouping:o,onApply:n,onClose:i}){var D;const[s,c]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=p.useState(""),[u,m]=p.useState(null),f=p.useMemo(()=>Vs(t),[t]),b=p.useMemo(()=>f.filter(O=>!s.levels.some((R,U)=>R.column===O.name&&U!==u)),[f,s.levels,u]),h=yr(),g=s.levels.length<h.grouping.maxLevels&&b.length>0,z=p.useCallback(()=>{!g||!d||(c({...s,levels:[...s.levels,{column:d}],enabled:!0}),l(""))},[g,d,s]),v=p.useCallback(O=>{const R=s.levels.filter((U,J)=>J!==O);if(R.length===0){n(null),i();return}c({...s,levels:R,enabled:R.length>0})},[s,n,i]),j=p.useCallback(O=>{m(O),l(s.levels[O].column)},[s.levels]),S=p.useCallback(()=>{if(u===null||!d)return;const O=[...s.levels];O[u]={column:d},c({...s,levels:O}),m(null),l("")},[u,d,s]),y=p.useCallback(()=>{m(null),l("")},[]),T=p.useCallback((O,R)=>{const U=R==="up"?O-1:O+1;if(U<0||U>=s.levels.length)return;const J=[...s.levels],[ee]=J.splice(O,1);J.splice(U,0,ee),c({...s,levels:J})},[s]),a=p.useCallback(()=>{n(null),i()},[n,i]),k=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:O=>O.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(Yt,{content:Gt.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:[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:O=>l(O.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(O=>e.jsxs(r.MenuItem,{value:O.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:R=>E(R.palette.primary.main,.2)}}},children:[Ve(O.name)," (",O.type.toUpperCase(),")"]},O.name))]})}),e.jsx(r.Button,{onClick:z,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),s.levels.length>=h.grouping.maxLevels&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),f.length===0&&e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),u!==null&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px",border:"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:O=>l(O.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," (",(D=t.find(O=>O.name===s.levels[u].column))==null?void 0:D.type.toUpperCase(),")"]}),b.filter(O=>O.name!==s.levels[u].column).map(O=>e.jsxs(r.MenuItem,{value:O.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[Ve(O.name)," (",O.type.toUpperCase(),")"]},O.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:S,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"#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:y,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:a,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((O,R)=>{const U=t.find(J=>J.name===O.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:O.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:U==null?void 0:U.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>T(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:()=>T(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:()=>v(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:k,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 Jd={filters:w.FilterList,sorting:w.UnfoldMore,visibility:w.Visibility,order:w.ViewColumn,widths:w.Straighten,grouping:w.Layers};function Kd({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=Jd[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 Xd({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(Kd,{changes:n,onClose:()=>l(!1)})]})}function Zd({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 ri=[{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 Qd(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 eu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function tu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var z,v,j,S;const s=wt().palette,[c,d]=p.useState("1h"),[l,u]=p.useState(!1),m=[...t].sort((y,T)=>new Date(T.timestamp).getTime()-new Date(y.timestamp).getTime()),f=ri.find(y=>y.key===c),b=Qd(t,f.ms),h=()=>u(!0),g=()=>{n&&(n(eu(t,f.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:E(((z=s.common)==null?void 0:z.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:y=>y.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(((v=s.common)==null?void 0:v.black)??"#000",.14)}, 0 2px 8px ${E(((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(Yt,{content:Gt.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:y=>d(y.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:ri.map(y=>e.jsx(r.MenuItem,{value:y.key,sx:{fontSize:"0.8125rem"},children:y.label},y.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:h,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(w.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(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(y=>{const T=pa(y.feature),{summary:a,detail:k}=la(y);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:ua(y.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:E(T,.1),color:T,border:`1px solid ${E(T,.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:a}),k&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:k}),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:xa(y.timestamp)})]}),y.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:y.user})]})]})]})]},y.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${E(((S=s.common)==null?void 0:S.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:E(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:()=>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(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 ru({onSave:t,onClose:o}){const[n,i]=p.useState(""),[s,c]=p.useState(""),[d,l]=p.useState(""),[u,m]=p.useState([]),[f,b]=p.useState(""),[h,g]=p.useState(""),z=k=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k),v=()=>{const k=d.trim();if(k){if(!z(k)){g("Please enter a valid email address");return}if(u.includes(k)){g("This email is already added");return}m([...u,k]),l(""),g("")}},j=k=>{m(u.filter(D=>D!==k))},S=k=>{k.key==="Enter"&&(k.preventDefault(),v())},y=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),s.trim(),u.length>0?u:void 0)},T=k=>{i(k),f&&b("")},a=k=>{l(k),h&&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:k=>k.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"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:k=>`1px solid ${E(k.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:k=>T(k.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!f,helperText:f,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"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:k=>c(k.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"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:k=>a(k.target.value),onKeyPress:S,placeholder:"Enter email address",error:!!h,helperText:h,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:v,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"})]}),u.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:u.map(k=>e.jsx(r.Chip,{label:k,onDelete:()=>j(k),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"}}}},k))}),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:y,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 ou({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=>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 nu({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(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(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(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"})})]},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 Pi={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},iu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],su=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function au(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=su.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=>iu.some(m=>m.test(u))).length/d.length>.6),(s||c)&&n.push(i.name)}return n}function tn(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,f)=>m+f.length,0);return Math.ceil(u/l.length)+1}).reduce((d,l)=>d+l,0)+1;return o.reduce((d,l)=>d+l.length+1,0)+s*t.length}function lu(t,o){const n=tn(t,o);return Math.ceil(n*3.5)}function cu(t,o){const n=tn(t,o);return Math.ceil(n*.7)}function du(t,o,n){switch(t){case"csv":return tn(o,n);case"excel":return cu(o,n);case"json":return lu(o,n)}}function oi(t,o){return Math.ceil(t/o)}function uu(t,o,n,i,s=Pi){const c=[],d=du(t,o,n),l=o.length;if(l>s.maxRowsHard){const f=oi(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=oi(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 ${Hr(d)} exceeds the ${Hr(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:d,limit:s.maxFileSizeHardBytes}):d>s.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Hr(d)}`,detail:`This exceeds the recommended ${Hr(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:s.maxFileSizeBytes}),t!=="excel"){const f=au(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(h=>`"${h.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 u=c.some(f=>f.severity==="error"),m=c.some(f=>f.severity==="warning");return{violations:c,hasBlockingViolation:u,hasWarning:m,estimatedBytes:d}}function Hr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function pu({violation:t}){const n=wt().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?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 xu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:c,sampleRows:d=[],allRows:l=[],processedRows:u=[],onExport:m,onClose:f}){var N,_,H;const h=wt().palette,g=yr(),[z,v]=p.useState(g.export.allowedFormats[0]||"csv"),[j,S]=p.useState("visible"),[y,T]=p.useState("visible"),a=j==="visible"?o:t,k=y==="visible"?i:s,D=p.useMemo(()=>j==="visible"?u.length>0?u:new Array(o):l.length>0?l:new Array(t),[j,o,t,u,l]),O=p.useMemo(()=>y==="all"?c.map(q=>q.name):c.map(q=>q.name).slice(0,i),[y,c,i]),R=p.useMemo(()=>uu(z,D,O,c,Pi),[z,D,O,c]),U=()=>{R.hasBlockingViolation||(m({format:z,scope:j,columnScope:y}),f())},J={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"}},x={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:f,sx:{position:"fixed",inset:0,bgcolor:E(((N=h.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:q=>q.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(((_=h.common)==null?void 0:_.black)??"#000",.14)}, 0 2px 8px ${E(((H=h.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(Yt,{content:Gt.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:E(h.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((q,de)=>e.jsx(pu,{violation:q},de))}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Format"}),e.jsxs(r.RadioGroup,{value:z,onChange:q=>v(q.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:{...ee,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:{...ee,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: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:q=>S(q.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:{...ee,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: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:y,onChange:q=>T(q.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:{...ee,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: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:J[z]},{label:"Rows to export",value:a.toLocaleString()},{label:"Columns to export",value:String(k)},{label:"Estimated file size",value:Hr(R.estimatedBytes),highlight:R.hasBlockingViolation?"error.main":R.hasWarning?"warning.main":void 0}].map(({label:q,value:de,highlight:ue})=>e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary"},children:q}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:ue??"text.primary"},children:de})]},q))})]})]}),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(h.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:U,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 ",J[z]]})]})]})})}function mu({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 fu({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(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=Ta(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 hu 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){Ht.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(w.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:i=>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(w.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Pr({children:t,feature:o,onError:n}){return e.jsx(hu,{context:o,onError:(i,s)=>{n&&n(i)},fallback:e.jsxs(r.Alert,{severity:"warning",sx:{m:1},icon:e.jsx(w.Warning,{sx:{fontSize:20}}),children:[e.jsxs(r.AlertTitle,{children:[o," temporarily unavailable"]}),"Other features continue to work normally"]}),children:t})}const gu=[{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"}],yu=[{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 Nr({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 bu({open:t,onClose:o,config:n,onApply:i}){const[s,c]=p.useState(0),[d,l]=p.useState(n),u=()=>l(n),m=()=>l(Fe),f=()=>{i(d),o()},b={sort:j=>l(S=>({...S,sort:{...S.sort,...j}})),filter:j=>l(S=>({...S,filter:{...S.filter,...j}})),columns:j=>l(S=>({...S,columns:{...S.columns,...j}})),grouping:j=>l(S=>({...S,grouping:{...S.grouping,...j}})),export:j=>l(S=>({...S,export:{...S.export,...j}}))},h=j=>{const S=d.filter.allowedOperators,y=S.includes(j)?S.filter(T=>T!==j):[...S,j];y.length!==0&&b.filter({allowedOperators:y})},g=j=>{const S=d.export.allowedFormats,y=S.includes(j)?S.filter(T=>T!==j):[...S,j];y.length!==0&&b.export({allowedFormats:y})},z=[{label:"Sort",icon:e.jsx(w.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(w.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(w.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(w.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(w.Download,{sx:{fontSize:17}})}],v=j=>JSON.stringify(d[j])===JSON.stringify(Fe[j]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.2)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:j=>E(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,S)=>c(S),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:z.map((j,S)=>e.jsx(r.Tab,{label:j.label,icon:j.icon,iconPosition:"start"},S))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Nr,{active:s===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!v("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:d.sort.maxLevels,onChange:(j,S)=>b.sort({maxLevels:S}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(Nr,{active:s===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!v("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:d.filter.maxConditions,onChange:(j,S)=>b.filter({maxConditions:S}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(j=>e.jsxs(r.Box,{sx:{mb:1.5},children:[e.jsx(r.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:j}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:gu.filter(S=>S.group===j).map(S=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(S.value),onChange:()=>h(S.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:S.label}),sx:{mr:1.5}},S.value))})]},j))]})]}),e.jsxs(Nr,{active:s===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!v("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:d.columns.maxVisible,onChange:(j,S)=>b.columns({maxVisible:S}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:d.columns.minColumnWidth,onChange:(j,S)=>b.columns({minColumnWidth:S}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),e.jsx(r.Slider,{value:d.columns.maxColumnWidth,onChange:(j,S)=>b.columns({maxColumnWidth:S}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]})]})]})]}),e.jsxs(Nr,{active:s===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!v("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(j=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:j}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===j?"primary.main":"divider",bgcolor:d.grouping.maxLevels===j?S=>E(S.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:S=>E(S.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:d.grouping.maxLevels===j?"primary.main":"text.secondary"},children:j}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][j-1]})]},j))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowNested,onChange:j=>b.grouping({allowNested:j.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow nested groups"})}),e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowCollapse,onChange:j=>b.grouping({allowCollapse:j.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),e.jsx(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),e.jsx(Nr,{active:s===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!v("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),e.jsx(r.FormGroup,{sx:{gap:1},children:yu.map(j=>e.jsxs(r.Box,{onClick:()=>g(j.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:d.export.allowedFormats.includes(j.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(j.value)?S=>E(S.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(j.value),onChange:()=>g(j.value),onClick:S=>S.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:j.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:j.desc})]})]},j.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:j=>E(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=>E(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 vu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Su={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 io(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 f=u-m;return f<0&&(f+=7),f===0&&l<=s&&(f=7),l.setDate(l.getDate()+f),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 ju(t){const o=Ni(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${vu[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Su[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Ni(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Cu(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 wu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=Ni(`${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 Fi(t){return`urm_schedules_${t}`}function Li(t){try{const o=localStorage.getItem(Fi(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 Vi(t,o){try{localStorage.setItem(Fi(t),JSON.stringify(o))}catch{}}const ku=[{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"}],Tu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Hi={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Vt={"& .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 zu({initial:t=Hi,isEditing:o=!1,onSave:n,onBack:i}){const[s,c]=p.useState(t),[d,l]=p.useState(!1),[u,m]=p.useState(!1),f=(g,z)=>c(v=>({...v,[g]:z})),b=s.email.trim().length>0&&!Tu.test(s.email.trim()),h=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(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:Vt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Vt,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:Vt,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:ku.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:Vt}),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:Vt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Vt,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:u&&b,helperText:u&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Vt}),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=>E(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>h&&n(s),disabled:!h,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 Iu({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(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 Eu({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:ju(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(w.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: ",Cu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",wu(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(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=>E(l.palette.warning.main,.08):l=>E(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=>E(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=>E(l.palette.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]})]})}function Bu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[c,d]=p.useState([]),[l,u]=p.useState({type:"list"}),[m,f]=p.useState(0),[b,h]=p.useState(null);p.useEffect(()=>{t&&(d(Li(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const O=setInterval(()=>f(R=>R+1),3e4);return()=>clearInterval(O)},[t]);const g=p.useCallback(O=>{d(O),Vi(n,O)},[n]),z=O=>{const R=io(O.frequency,O.time,O.dayOfWeek,O.dayOfMonth),U={id:`sched-${Date.now()}`,reportId:n,name:O.name.trim(),frequency:O.frequency,dayOfWeek:O.frequency==="weekly"?O.dayOfWeek:void 0,dayOfMonth:O.frequency==="monthly"?O.dayOfMonth:void 0,time:O.time,format:O.format,scope:O.scope,email:O.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:R,runCount:0};g([...c,U]),u({type:"list"})},v=O=>{if(l.type!=="edit")return;const R=l.schedule,U=io(O.frequency,O.time,O.dayOfWeek,O.dayOfMonth);g(c.map(J=>J.id===R.id?{...R,name:O.name.trim(),frequency:O.frequency,dayOfWeek:O.frequency==="weekly"?O.dayOfWeek:void 0,dayOfMonth:O.frequency==="monthly"?O.dayOfMonth:void 0,time:O.time,format:O.format,scope:O.scope,email:O.email.trim()||void 0,nextRunAt:U}:J)),u({type:"list"})},j=O=>{g(c.map(R=>{if(R.id!==O)return R;const U=R.isActive?R.nextRunAt:io(R.frequency,R.time,R.dayOfWeek,R.dayOfMonth);return{...R,isActive:!R.isActive,nextRunAt:U}}))},S=O=>{s(O);const R=new Date().toISOString();g(c.map(U=>U.id===O.id?{...U,lastRunAt:R,runCount:U.runCount+1}:U))},y=O=>{const R=c.find(U=>U.id===O)??null;h(R)},T=()=>{b&&(g(c.filter(O=>O.id!==b.id)),h(null))},a=O=>({name:O.name,frequency:O.frequency,dayOfWeek:O.dayOfWeek??1,dayOfMonth:O.dayOfMonth??1,time:O.time,format:O.format,scope:O.scope,email:O.email??""}),k=l.type!=="list",D=c.filter(O=>O.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:k,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:O=>E(O.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(Yt,{content:Gt.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:O=>E(O.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:[k&&e.jsx(zu,{initial:l.type==="edit"?a(l.schedule):Hi,isEditing:l.type==="edit",onSave:l.type==="edit"?v:z,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":`${D} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(w.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(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(O=>e.jsx(Eu,{schedule:O,tick:m,onToggle:j,onRunNow:S,onEdit:R=>u({type:"edit",schedule:R}),onDelete:y},O.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:O=>E(O.palette.warning.main,.06),border:"1px solid",borderColor:O=>E(O.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:O=>E(O.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Iu,{scheduleName:b.name,onConfirm:T,onCancel:()=>h(null)})]})}const Du=6e4;function Ou({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:f}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:f});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:f}});const h=p.useCallback(g=>{var O,R;const{reportName:z,uploadedData:v,processedData:j,schema:S,activeView:y,columnVisibility:T,columnOrder:a,filters:k,sortStack:D}=b.current;try{const U=g.scope==="all"?v:j,J=so(U,S,k,D,y,T,a),ee=`${g.name}_scheduled`;switch(g.format){case"csv":ao(J,ee,{scope:g.scope});break;case"excel":lo(J,ee,{scope:g.scope});break;case"json":co(J,ee,{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 ud({onFileUpload:t,onError:o,isUploading:n}){const[i,a]=u.useState(!1),[c,d]=u.useState(""),[l,p]=u.useState(!1),x=u.useRef(null),f=async v=>{if(!v.name.endsWith(".json")){o("Only .json files are allowed");return}const k=10*1024*1024;if(v.size>k){o("File size exceeds 10MB limit");return}d(v.name);try{const S=await v.text();let T;try{T=JSON.parse(S)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(T)){o("JSON must be an array of objects");return}if(T.length===0){o("No data rows found in JSON file");return}t(T)}catch{o("Network error — please try again")}finally{d("")}},b=v=>{v.preventDefault(),a(!0)},m=v=>{v.preventDefault(),a(!1)},g=v=>{v.preventDefault(),a(!1);const k=v.dataTransfer.files[0];k&&f(k)},z=()=>{var v;(v=x.current)==null||v.click()},y=v=>{var S;const k=(S=v.target.files)==null?void 0:S[0];k&&f(k)},C=v=>{v.stopPropagation(),p(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:m,onDrop:g,onPaste:v=>v.preventDefault(),onClick:z,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?v=>D(v.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[e.jsx(r.Box,{component:"input",ref:x,type:"file",accept:".json",onChange:y,sx:{display:"none"}}),n?e.jsxs(e.Fragment,{children:[e.jsx(r.CircularProgress,{size:32,sx:{mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:.5},children:"Uploading..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:v=>D(v.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.UploadFile,{sx:{fontSize:32,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:1.5},children:[e.jsx(r.Button,{variant:"contained",sx:{fontWeight:500},children:"Upload Data (JSON)"}),e.jsx(r.IconButton,{onClick:C,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:e.jsx(w.InfoOutlined,{sx:{fontSize:16}})})]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",maxWidth:500},children:"Upload structured JSON data to generate your report."}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1},children:"Click to browse or drag and drop a JSON file here"})]})]}),e.jsx(Vi,{isOpen:l,onClose:()=>p(!1)})]})}function pd({schema:t,onConfirm:o,hasConflicts:n}){return e.jsxs(r.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[e.jsxs(r.Box,{sx:{mb:2},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontWeight:600,mb:.5},children:"Schema Preview"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&e.jsxs(r.Alert,{severity:"warning",sx:{mb:2},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),e.jsx(r.TableContainer,{sx:{mb:3},children:e.jsxs(r.Table,{children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{bgcolor:"action.hover"},children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),e.jsx(r.TableBody,{children:t.map(i=>e.jsxs(r.TableRow,{sx:{bgcolor:i.hasConflict?a=>D(a.palette.warning.main,.12):"transparent"},children:[e.jsxs(r.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&e.jsx(r.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(w.Lock,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Schema will be locked for this report"})]}),e.jsx(r.Button,{variant:"contained",onClick:o,disabled:n,sx:{fontWeight:500},children:"Generate Table"})]})]})}function xd({error:t,onRetry:o}){return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderColor:"error.light",bgcolor:n=>D(n.palette.error.main,.12),borderRadius:1,px:2,py:6},children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:n=>D(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.ErrorOutline,{color:"error",sx:{fontSize:32}})}),e.jsx(r.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:600,mb:1},children:"Upload Failed"}),e.jsx(r.Typography,{variant:"body2",color:"error.main",sx:{textAlign:"center",maxWidth:500,mb:3},children:t}),e.jsx(r.Button,{variant:"contained",color:"error",startIcon:e.jsx(w.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Hi({title:t,description:o,showIcon:n=!0}){return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",px:3,py:8},children:[n&&e.jsx(r.Box,{sx:{width:80,height:80,borderRadius:"50%",bgcolor:i=>D(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(w.Description,{sx:{fontSize:36,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:500,mb:1,color:"text.primary",fontSize:"1.125rem"},children:t}),e.jsx(r.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:"0.875rem",lineHeight:1.5},children:o})]})}function md({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:a,onDeleteHistory:c,disabled:d}){const[l,p]=u.useState(!1),[x,f]=u.useState(!1),[b,m]=u.useState(-1),g=u.useRef(null),z=u.useRef(null);u.useEffect(()=>{function $(G){g.current&&!g.current.contains(G.target)&&(p(!1),f(!1))}return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[]);const y=u.useCallback(()=>{f(!0),m(-1),n.length>0&&p(!0)},[n.length]),C=u.useCallback($=>{o($),m(-1)},[o]),v=u.useCallback($=>{var G;o($),i($),p(!1),(G=z.current)==null||G.blur()},[o,i]),k=u.useCallback($=>{m(-1),v($)},[v]),S=u.useCallback($=>{var G;$.key==="Enter"?b>=0&&b<n.length?($.preventDefault(),k(n[b].query)):t.trim()&&v(t.trim()):$.key==="Escape"?(p(!1),m(-1),(G=z.current)==null||G.blur()):$.key==="ArrowDown"?($.preventDefault(),n.length>0&&(l||p(!0),m(Z=>Z<n.length-1?Z+1:Z))):$.key==="ArrowUp"&&($.preventDefault(),m(Z=>Z>0?Z-1:-1))},[b,n,t,l,k,v]),T=u.useCallback(()=>{var $;o(""),($=z.current)==null||$.focus()},[o]),s=u.useMemo(()=>n.filter($=>$.isFavourite),[n]),M=u.useMemo(()=>n.filter($=>!$.isFavourite),[n]),B=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:z,size:"small",fullWidth:!0,value:t,onChange:$=>C($.target.value),onFocus:y,onKeyDown:S,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.30)`,transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.50)`},"&.Mui-focused":{bgcolor:"background.paper"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px",color:"text.primary"}},InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",sx:{ml:.5},children:e.jsx(w.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:T,edge:"end",sx:{mr:-.5},children:e.jsx(w.Close,{sx:{fontSize:16}})})}):null}}),B&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[s.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),s.map(($,G)=>e.jsx(Zn,{entry:$,isSelected:b===G,onClick:()=>k($.query),onToggleFavourite:()=>a($.query),onDelete:()=>c($.query)},`fav-${$.query}`))]}),M.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[s.length>0&&e.jsx(r.Divider,{}),e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),M.map(($,G)=>{const Z=s.length+G;return e.jsx(Zn,{entry:$,isSelected:b===Z,onClick:()=>k($.query),onToggleFavourite:()=>a($.query),onDelete:()=>c($.query)},`recent-${$.query}`)})]})]})]})}const Zn=u.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:a,onDelete:c}){const d=u.useCallback(p=>{p.stopPropagation(),a()},[a]),l=u.useCallback(p=>{p.stopPropagation(),c()},[c]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?p=>D(p.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?p=>D(p.palette.primary.main,.12):"action.hover"}},children:[e.jsx(r.Box,{sx:{flex:1,minWidth:0},onClick:i,children:e.jsx(r.Typography,{variant:"body2",noWrap:!0,children:o.query})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[e.jsx(r.IconButton,{size:"small",onClick:d,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(w.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(w.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),e.jsx(r.IconButton,{size:"small",onClick:l,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:e.jsx(w.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function fd({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:a,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:p,onPermanentDelete:x,isReadOnly:f,isAdmin:b=!1}){const m=It(),[g,z]=u.useState(!1),[y,C]=u.useState(!1),[v,k]=u.useState({top:0,left:0}),[S,T]=u.useState(null),s=u.useRef(null),M=u.useRef(null),B=t.find(A=>A.id===o),$=B==null?void 0:B.isDefault,G=t.filter(A=>A.scope==="global"&&!A.isDeleted),Z=t.filter(A=>A.scope!=="global"&&!A.isDeleted),ee=t.filter(A=>A.isFavorite&&!A.isDeleted).sort((A,V)=>(V.updatedAt||0)-(A.updatedAt||0)),h=t.filter(A=>A.isDeleted);u.useEffect(()=>{if(g&&M.current){const A=M.current.getBoundingClientRect();k({top:A.bottom+window.scrollY+8,left:A.right+window.scrollX-320})}},[g]),u.useEffect(()=>{const A=V=>{s.current&&!s.current.contains(V.target)&&M.current&&!M.current.contains(V.target)&&z(!1)};return g&&document.addEventListener("mousedown",A),()=>{document.removeEventListener("mousedown",A)}},[g]);const R=A=>{if(n&&A!==o){T(A),z(!1);return}i(A),z(!1)},W=()=>{S&&(i(S),T(null))},H=()=>{T(null)},K=(A,V=!1)=>{const q=A.scope==="global",re=!f&&(!q||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===A.id?m.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===A.id?m.palette.primary.light+"20":m.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>R(A.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,textTransform:"none",justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===A.id&&e.jsx(w.Check,{sx:{fontSize:16,flexShrink:0}}),o!==A.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===A.id?m.palette.primary.dark:m.palette.text.primary,fontWeight:o===A.id?500:400},children:A.name}),V&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[re&&l&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),l(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:A.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(w.Star,{sx:{fontSize:16}})}),re&&d&&!A.isDefault&&e.jsx(r.IconButton,{onClick:Q=>{Q.stopPropagation(),d(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Set as default",children:e.jsx(w.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},A.id)},de=A=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:m.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:m.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:A.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[p&&e.jsx(r.IconButton,{onClick:V=>{V.stopPropagation(),p(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Restore view",children:e.jsx(w.Undo,{sx:{fontSize:16,color:"success.main"}})}),x&&e.jsx(r.IconButton,{onClick:V=>{V.stopPropagation(),x(A.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Delete permanently",children:e.jsx(w.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},A.id),ue=n||!$,te=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:M,onClick:()=>z(!g),size:"small",sx:{position:"relative",color:ue?"warning.main":"text.secondary",bgcolor:ue?D(m.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ue?D(m.palette.warning.main,.2):D(m.palette.text.primary,.06),color:ue?"warning.dark":"text.primary"}},title:`View: ${(B==null?void 0:B.name)||"Default View"}`,children:[e.jsx(w.Visibility,{sx:{fontSize:20}}),te&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),g&&ui.createPortal(e.jsxs(r.Box,{ref:s,sx:{position:"fixed",width:"320px",backgroundColor:m.palette.background.paper,border:`1px solid ${m.palette.divider}`,borderRadius:1,boxShadow:m.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:v.top,left:v.left},children:[G.length>0&&e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),G.map(A=>K(A,A.isDefault))]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(w.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),ee.map(A=>K(A))]})]}),Z.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),Z.map(A=>K(A))]})]}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>C(!y),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",h.length,")"]}),e.jsx(w.ChevronRight,{sx:{fontSize:16}})]}),y&&e.jsx(r.Box,{sx:{backgroundColor:m.palette.grey[50]},children:h.map(A=>de(A))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{a(),z(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsx(w.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),z(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsx(w.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:S!==null,onClose:H,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(w.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:H,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function hd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:a,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:p,onSortDescending:x,onRemoveSort:f,onFilter:b,onClearFilter:m,onGroupByColumn:g,onHideColumn:z,onManageColumns:y,onManageViews:C,onResetLayout:v,onClose:k}){var ee,h;const T=It().palette,s=u.useRef(null);u.useEffect(()=>{if(!s.current)return;const R=s.current,W=R.getBoundingClientRect(),H=window.innerWidth,K=window.innerHeight;W.right>H-8&&(R.style.left=`${H-W.width-8}px`),W.bottom>K-8&&(R.style.top=`${K-W.height-8}px`)},[l]),u.useEffect(()=>{const R=H=>{s.current&&!s.current.contains(H.target)&&k()},W=H=>{H.key==="Escape"&&k()};return document.addEventListener("mousedown",R),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",R),document.removeEventListener("keydown",W)}},[k]);const M=u.useCallback(R=>()=>{R(),k()},[k]),B=(n==null?void 0:n.direction)==="asc",$=(n==null?void 0:n.direction)==="desc",G=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",Z=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return ui.createPortal(e.jsxs(r.Paper,{ref:s,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:1400,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",boxShadow:`0 4px 20px ${D(((ee=T.common)==null?void 0:ee.black)??"#000",.12)}, 0 1px 4px ${D(((h=T.common)==null?void 0:h.black)??"#000",.06)}`},children:[!c&&e.jsxs(r.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary"},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[e.jsx(r.Tooltip,{title:`Sort Ascending (${G})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:M(()=>p(t)),sx:{p:.625,borderRadius:"6px",color:B?"primary.main":"text.secondary",bgcolor:B?D(T.primary.main,.1):"transparent","&:hover":{bgcolor:D(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${Z})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:M(()=>x(t)),sx:{p:.625,borderRadius:"6px",color:$?"primary.main":"text.secondary",bgcolor:$?D(T.primary.main,.1):"transparent","&:hover":{bgcolor:D(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.ArrowDownward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:!a,onClick:M(()=>f(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(T.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(w.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:M(()=>b(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.FilterList,{sx:{fontSize:16,color:i?"primary.main":"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Filter by Column",primaryTypographyProps:{fontSize:"0.8125rem",fontWeight:i?600:400,color:i?"primary.main":"text.primary"}})]}),i&&!c&&e.jsxs(r.MenuItem,{onClick:M(()=>m(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(T.warning.main,.06),"& .MuiListItemText-primary":{color:"warning.main"},"& .MuiListItemIcon-root svg":{color:"warning.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&g&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.25}}),e.jsx(r.MenuList,{dense:!0,sx:{py:.5},children:e.jsxs(r.MenuItem,{onClick:M(()=>g(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.GroupWorkOutlined,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Group By Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]})})]}),e.jsx(r.Divider,{sx:{my:.25}}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[!c&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(r.MenuItem,{onClick:M(()=>z(t)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),e.jsx(r.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:M(y),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:D(T.primary.main,.08),color:"primary.main"}},children:e.jsx(w.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:M(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),C&&e.jsxs(r.MenuItem,{onClick:M(C),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!c&&d&&v&&e.jsxs(r.MenuItem,{onClick:M(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:D(T.error.main,.05),"& .MuiListItemText-primary":{color:"error.main"},"& .MuiListItemIcon-root svg":{color:"error.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(w.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const gd=176,Qn="COLUMN_HEADER",yd=u.memo(function({column:o,index:n,sortRule:i,hasFilters:a,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:p,onColumnClick:x,onMoveColumn:f,onResizeStart:b,onSortAscending:m,onSortDescending:g,onRemoveSort:z,onOpenFilterForColumn:y,onClearFiltersForColumn:C,onGroupByColumn:v,onHideColumn:k,onManageColumns:S,onManageViews:T,onResetLayout:s}){const M=u.useRef(null),[B,$]=u.useState(!1),[G,Z]=u.useState({x:0,y:0}),[{handlerId:ee,isOver:h},R]=kt.useDrop({accept:Qn,collect(q){return{handlerId:q.getHandlerId(),isOver:q.isOver()}},hover(q,re){var se;if(!M.current)return;const Q=q.index,le=n;if(Q===le)return;const oe=(se=M.current)==null?void 0:se.getBoundingClientRect(),N=(oe.right-oe.left)/2,ne=re.getClientOffset(),ce=((ne==null?void 0:ne.x)??0)-oe.left;Q<le&&ce<N||Q>le&&ce>N||(f(Q,le),q.index=le)}}),[{isDragging:W},H]=kt.useDrag({type:Qn,item:()=>({index:n,columnName:o.name}),collect:q=>({isDragging:q.isDragging()})});H(R(M));const K=u.useCallback(q=>{q.preventDefault(),q.stopPropagation(),Z({x:q.clientX,y:q.clientY}),$(!0)},[]),de=u.useCallback(()=>$(!1),[]),ue=u.useCallback(()=>{x(o.name)},[x,o.name]),te=u.useCallback(q=>{q.stopPropagation(),y(o.name)},[y,o.name]),A=u.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(w.ArrowDownward,{sx:{fontSize:13,color:"primary.main"}}),e.jsx(r.Box,{sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"0.6rem",fontWeight:700,borderRadius:"50%",lineHeight:1},children:i.priority})]}):null,[i]),V=u.useCallback(()=>a?e.jsx(w.FilterList,{onClick:te,title:"Active filter on this column — click to edit",sx:{ml:.5,fontSize:13,color:"primary.main",cursor:"pointer",flexShrink:0,"&:hover":{transform:"scale(1.15)"},transition:"transform 0.12s ease"}}):null,[a,te]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:M,"data-handler-id":ee,"data-column-index":n,onClick:ue,onContextMenu:K,sx:{zIndex:5,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"visible",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:W?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:h?q=>D(q.palette.primary.main,.08):"action.hover",boxShadow:"0 1px 0 rgba(0,0,0,0.08)",backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:q=>D(q.palette.primary.main,.1),color:"primary.dark"},width:p?`${p}px`:`${gd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",overflow:"hidden",maxWidth:"100%",pr:"12px"},children:[Ue(o.name),A(),V()]}),e.jsx(r.Box,{sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:20,display:"flex",alignItems:"center",justifyContent:"center","&:hover > div":{opacity:1}},onMouseDown:q=>{q.preventDefault(),q.stopPropagation(),b(q,o.name)},onClick:q=>q.stopPropagation(),children:e.jsx(r.Box,{sx:{width:2,height:"50%",borderRadius:1,opacity:0,bgcolor:"primary.main",transition:"opacity 0.15s ease",pointerEvents:"none"}})}),h&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),B&&e.jsx(hd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:a,isInSortStack:c,isReadOnly:d,hasModifications:l,position:G,onSortAscending:m,onSortDescending:g,onRemoveSort:z,onFilter:y,onClearFilter:C,onGroupByColumn:v,onHideColumn:k,onManageColumns:S,onManageViews:T,onResetLayout:s,onClose:de})]})});function bd({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:a,onClearSelection:c,onBulkSetFavorites:d}){const[l,p]=u.useState(null),x=u.useMemo(()=>Array.from(o),[o]),f=u.useMemo(()=>x.filter(v=>n.has(v)),[x,n]),b=u.useMemo(()=>x.filter(v=>!n.has(v)),[x,n]),m=f.length>0,g=b.length>0;if(t===0)return null;const z=()=>{d&&d(x,!0)},y=()=>{d&&d(x,!1)},C=v=>{a(v),p(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:v=>D(v.palette.primary.main,.08),borderBottom:v=>`1px solid ${D(v.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(w.Close,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:v=>D(v.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:v=>p(v.currentTarget),startIcon:e.jsx(w.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>D(v.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:v=>D(v.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:l,open:!!l,onClose:()=>p(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:180,borderRadius:1.5}},children:[e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>C("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:z,startIcon:e.jsx(w.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>D(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>D(v.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&m&&e.jsx(r.Button,{onClick:y,startIcon:e.jsx(w.Star,{sx:{fontSize:16,color:"#fbbc04"}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>D(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>D(v.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const vd={active:{bg:"#e6f4ea",color:"#137333"},completed:{bg:"#e6f4ea",color:"#137333"},approved:{bg:"#e6f4ea",color:"#137333"},success:{bg:"#e6f4ea",color:"#137333"},done:{bg:"#e6f4ea",color:"#137333"},contract:{bg:"#e8eaf6",color:"#3949ab"},"in progress":{bg:"#e8eaf6",color:"#3949ab"},"in review":{bg:"#e8eaf6",color:"#3949ab"},review:{bg:"#e8eaf6",color:"#3949ab"},pending:{bg:"#e8eaf6",color:"#3949ab"},"on leave":{bg:"#fce8e6",color:"#c5221f"},"on hold":{bg:"#fff8e1",color:"#e65100"},probation:{bg:"#fff8e1",color:"#e65100"},cancelled:{bg:"#fce8e6",color:"#c5221f"},rejected:{bg:"#fce8e6",color:"#c5221f"},blocked:{bg:"#fce8e6",color:"#c5221f"},inactive:{bg:"#f1f3f4",color:"text.secondary"},"not started":{bg:"#f1f3f4",color:"text.secondary"},paused:{bg:"#f1f3f4",color:"text.secondary"}},Sd={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function jd(t){const o=t.toLowerCase().trim(),n=vd[o]||{bg:"#f1f3f4",color:"text.secondary"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function Cd(t,o){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontSize:"0.8125rem"},children:"—"});const n=String(o),i=t.name.toLowerCase();if(/\b(status|state|stage)\b/.test(i))return jd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const a=Sd[n.toLowerCase().trim()];return a?e.jsx(r.Box,{component:"span",sx:{color:a,fontWeight:600,fontSize:"0.8125rem"},children:n}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function wd(t){const o=t.find(a=>{const c=a.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(c)})||t[0]||null,n=t.find(a=>{const c=a.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(c)&&a!==o})||null,i=t.filter(a=>a!==o&&a!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function kd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:a,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:p,onEdit:x,onDuplicate:f,onDelete:b}){const[m,g]=u.useState(null),[z,y]=u.useState(!1),{primaryCol:C,idCol:v,bodyColumns:k}=u.useMemo(()=>wd(n),[n]),S=C?t[C.name]:null,T=v?t[v.name]:null,s=z||i||a||!!m;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":M=>D(M.palette.divider,.8),borderWidth:i?2:1,borderRadius:"12px",cursor:"pointer",transition:"box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease",overflow:"hidden",minHeight:180,boxShadow:i?M=>`0 0 0 3px ${D(M.palette.primary.main,.15)}, 0 2px 8px ${D(M.palette.common.black,.08)}`:z?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:z&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:M=>D(M.palette.primary.main,.03)}},children:[e.jsx(r.Box,{sx:{px:2,pt:2,pb:1.5},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,fontSize:"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:S!=null&&S!==""?String(S):e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})}),e.jsx(r.Box,{sx:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}),e.jsxs(r.Box,{sx:{px:2,py:1.5,flex:1,display:"flex",flexDirection:"column",gap:1},children:[k.map(M=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minHeight:22},children:[e.jsx(r.Typography,{sx:{color:"text.secondary",fontWeight:500,fontSize:"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",minWidth:68,flexShrink:0,lineHeight:1},children:Ue(M.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:Cd(M,t[M.name])})]},M.name)),k.length===0&&e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic"},children:"No additional fields visible"})]}),e.jsxs(r.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:M=>D(M.palette.action.hover,.1),minHeight:40},children:[e.jsx(r.Typography,{sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.75rem",fontWeight:400,letterSpacing:"0.04em",opacity:T?.85:0,userSelect:"none"},children:T?String(T):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:s?1:0,transition:"opacity 0.15s ease"},onClick:M=>M.stopPropagation(),children:[l&&e.jsx(r.Tooltip,{title:a?"Remove from favorites":"Add to favorites",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),l(t)},sx:{width:28,height:28,color:a?"#fbbc04":"action.disabled","&:hover":{bgcolor:M=>D(M.palette.warning.main,.1),color:"#fbbc04"}},children:a?e.jsx(w.Star,{sx:{fontSize:17}}):e.jsx(w.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),g(M.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:M=>D(M.palette.text.primary,.08)}},children:e.jsx(w.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!m,anchorEl:m,onClose:()=>g(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:"0 4px 20px rgba(60,64,67,0.15), 0 1px 6px rgba(60,64,67,0.1)"}},onClick:M=>M.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{p(t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{x(t,o),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(w.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{b(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(w.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function Td({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:a=>D(a.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:bi(t.groupLevel,((i=o==null?void 0:o.levels[t.groupLevel])==null?void 0:i.column)||"",t.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:a=>D(a.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[t.rowCount," ",t.rowCount===1?"row":"rows"]}),Object.keys(t.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(t.aggregates).map(([a,c])=>yi(c)).filter(Boolean).join(" • ")})]})}function Id({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:a,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:p,onToggleRowSelection:x,onToggleRowFavorite:f,onToggleGroupCollapse:b,onViewRow:m,onEditRow:g,onDuplicateRow:z,onDeleteRow:y}){const C=u.useMemo(()=>{const v=new Set;return i.forEach(k=>{const S=k==null?void 0:k.__urm_row_id__;S!==void 0&&v.add(S)}),v},[i]);return t.length===0?e.jsx(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):e.jsxs(r.Box,{children:[p&&o.length>0&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,px:2,py:1,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper",flexWrap:"wrap"},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontWeight:500,mr:.5,whiteSpace:"nowrap"},children:"Sort by:"}),o.map(v=>{const k=l.find(S=>S.column===v.name);return e.jsxs(r.Box,{onClick:()=>p(v.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:k?"primary.main":"divider",bgcolor:k?S=>D(S.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:S=>D(S.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:k?600:400,color:k?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ue(v.name)}),k?k.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(w.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(w.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},v.name)})]}),e.jsx(r.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(272px, 1fr))",gap:1.5,alignContent:"start"},children:t.map((v,k)=>d&&v.isGroupHeader?e.jsx(Td,{row:v,grouping:n,onToggleCollapse:b||(()=>{})},`group-${v.groupKey}`):e.jsx(kd,{row:v,rowIndex:k,visibleColumns:o,isSelected:C.has(v==null?void 0:v.__urm_row_id__),isFavorite:a.has(v),isReadOnly:c,onToggleSelection:()=>x(v),onToggleFavorite:f,onView:m,onEdit:g,onDuplicate:z,onDelete:y},`card-${k}`))})]})}const ei=[10,15,25,50,100];function zd(t,o){const n=t.trim();if(n==="")return"Page number is required";if(!/^-?\d+$/.test(n))return"Must be a number";const i=parseInt(n,10);return i<1?"Page number must be at least 1":i>o?"Entered page number is out of range":null}function Ed({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:a,onPageSizeChange:c}){var R;const l=It().palette,p=Math.ceil(n/o),[x,f]=u.useState(String(t)),[b,m]=u.useState(null),[g,z]=u.useState(!1),y=u.useRef(null);u.useEffect(()=>{g||(f(String(t)),m(null))},[t,g]);const C=u.useCallback(()=>{const W=zd(x,p);if(W){m(W);return}const H=parseInt(x.trim(),10);m(null),z(!1),H!==t&&a(H)},[x,p,t,a]),v=u.useCallback(W=>{var H;W.key==="Enter"?(W.preventDefault(),C()):W.key==="Escape"&&(f(String(t)),m(null),z(!1),(H=y.current)==null||H.blur())},[C,t]),k=u.useCallback(()=>{f(String(t)),m(null),z(!1)},[t]),S=u.useCallback(()=>{z(!0),m(null),setTimeout(()=>{var W;return(W=y.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ei))return null;const T=()=>{f(String(t)),m(null),z(!1)},s=()=>{T(),a(1)},M=()=>{T(),t>1&&a(t-1)},B=()=>{T(),t<p&&a(t+1)},$=()=>{T(),a(p)},G=(t-1)*o+1,Z=Math.min(t*o,n),ee=`${Math.max(2,String(p).length+.5)}ch`,h={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:3,px:2,py:1,borderTop:"1px solid",borderColor:"divider",bgcolor:"background.paper",minHeight:48},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),e.jsx(r.Select,{value:o,onChange:W=>c(Number(W.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:ei.map(W=>e.jsx(r.MenuItem,{value:W,sx:{fontSize:"0.8125rem"},children:W},W))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[G,"–",Z," of ",n]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),e.jsxs(r.Box,{sx:{position:"relative"},children:[b&&e.jsx(r.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:D(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${D(((R=l.common)==null?void 0:R.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:D(l.error.main,.4)}},children:e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:b})}),e.jsx(r.InputBase,{inputRef:y,value:x,onChange:W=>{f(W.target.value),b&&m(null)},onKeyDown:v,onFocus:S,onBlur:k,inputProps:{"aria-label":`Page number, 1 to ${p}`,style:{textAlign:"center",padding:"2px 0",width:ee,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":g?"primary.main":"divider",borderRadius:"4px",bgcolor:b?D(l.error.main,.04):g?D(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:b?"error.main":"text.secondary"},"&:focus-within":{boxShadow:b?`0 0 0 2px ${D(l.error.main,.2)}`:`0 0 0 2px ${D(l.primary.main,.2)}`}}})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",p]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{onClick:s,disabled:t===1,size:"small",title:"First page",sx:h,children:e.jsx(w.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:M,disabled:t===1,size:"small",title:"Previous page",sx:h,children:e.jsx(w.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:B,disabled:t===p,size:"small",title:"Next page",sx:h,children:e.jsx(w.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:$,disabled:t===p,size:"small",title:"Last page",sx:h,children:e.jsx(w.LastPage,{sx:{fontSize:20}})})]})]})]})}function Bd(){return e.jsx(r.Chip,{icon:e.jsx(w.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const Ui="urm_hint_seen_";function Dd(t){try{return localStorage.getItem(Ui+t)==="true"}catch{return!1}}function Od(t){try{localStorage.setItem(Ui+t,"true")}catch{}}function ti(t,o){if(t==null||t==="")return"";if(o==="boolean")return t?"True":"False";if(o==="object"||o==="array")try{return JSON.stringify(t,null,2)}catch{return String(t)}return String(t)}function ri(t){const o={fontSize:11};switch(t){case"number":return e.jsx(w.Numbers,{sx:o});case"boolean":return e.jsx(w.CheckBox,{sx:o});case"array":return e.jsx(w.DataArray,{sx:o});case"object":return e.jsx(w.DataObject,{sx:o});default:return e.jsx(w.TextFields,{sx:o})}}function oi(t,o){var n,i;switch(t){case"number":return{bg:D(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:D(((n=o.success)==null?void 0:n.main)??"#2e7d32",.08),color:((i=o.success)==null?void 0:i.main)??"#2e7d32"};case"array":case"object":return{bg:D(o.secondary.main,.08),color:o.secondary.main};default:return{bg:D(o.text.secondary,.07),color:o.text.secondary}}}function Ad({open:t,onClose:o,row:n,schema:i,reportName:a}){var b,m;const d=It().palette;if(!n)return null;const l=i.filter(g=>g.name in n),p=l.filter(g=>g.type!=="object"&&g.type!=="array"),x=l.filter(g=>g.type==="object"||g.type==="array"),f=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${D(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${D(((m=d.common)==null?void 0:m.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:D(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"View Record"}),a&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[a," · ",f," ",f===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:D(d.text.primary,.015)},children:[p.length>0&&e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"1px",bgcolor:"divider",m:2,mb:x.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:p.map((g,z)=>{const y=n[g.name],C=ti(y,g.type),v=!C,k=oi(g.type,d),S=z===p.length-1&&p.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:S?"span 2":"span 1",display:"flex",flexDirection:"column",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:k.bg,color:k.color,flexShrink:0},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ue(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:v?400:500,color:v?"text.disabled":"text.primary",fontStyle:v?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:v?"No value":C})]},g.name)})}),x.map(g=>{const z=n[g.name],y=ti(z,g.type),C=!y,v=oi(g.type,d);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:v.bg,color:v.color},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ue(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:v.bg,color:v.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:D(d.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:C?"text.disabled":"text.primary",fontStyle:C?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:C?"No value":y})]},g.name)}),l.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(w.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:3,py:.75,borderRadius:"8px",minWidth:80},children:"Close"})})]})}function Md({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:"#fce8e6",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:[i?`"${i}"`:"This record"," will be permanently removed."]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:"#fce8e6",border:"1px solid #f28b82"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"error.main",fontWeight:500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(w.DeleteForever,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Yo(t){const o={fontSize:11};switch(t){case"number":return e.jsx(w.Numbers,{sx:o});case"boolean":return e.jsx(w.CheckBox,{sx:o});case"array":return e.jsx(w.DataArray,{sx:o});case"object":return e.jsx(w.DataObject,{sx:o});default:return e.jsx(w.TextFields,{sx:o})}}function ni(t,o){var n,i;switch(t){case"number":return{bg:D(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:D(((n=o.success)==null?void 0:n.main)??"#2e7d32",.08),color:((i=o.success)==null?void 0:i.main)??"#2e7d32"};case"array":case"object":return{bg:D(o.secondary.main,.08),color:o.secondary.main};default:return{bg:D(o.text.secondary,.07),color:o.text.secondary}}}function _d({open:t,onClose:o,onSave:n,row:i,schema:a,reportName:c}){var C,v,k;const l=It().palette,[p,x]=u.useState({});if(u.useEffect(()=>{t&&i&&x({...i})},[t,i]),!i)return null;const f=a.filter(S=>S.name in i),b=f.filter(S=>S.type!=="object"&&S.type!=="array"),m=f.filter(S=>S.type==="object"||S.type==="array"),g=(S,T)=>{x(s=>({...s,[S]:T}))},z=()=>{const S={...p};f.forEach(T=>{const s=p[T.name];if(T.type==="number"){const M=Number(s);S[T.name]=isNaN(M)?i[T.name]:M}else T.type==="boolean"&&(S[T.name]=!!s)}),n(S),o()},y=f.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${D(((C=l.common)==null?void 0:C.black)??"#000",.14)}, 0 2px 8px ${D(((v=l.common)==null?void 0:v.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:D(((k=l.warning)==null?void 0:k.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),c&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c," · ",y," ",y===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:D(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[b.length>0&&e.jsxs(r.Box,{children:[b.length>1&&e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em",mb:1.25},children:"Fields"}),e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1.5},children:b.map((S,T)=>{const s=p[S.name],M=ni(S.type,l),B=S.type==="boolean",$=!B&&T===b.filter(Z=>Z.type!=="boolean").length-1&&b.filter(Z=>Z.type!=="boolean").length%2!==0,G=B||$;return S.type==="boolean"?e.jsxs(r.Box,{sx:{gridColumn:"span 2",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",px:2,py:1.5,display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,transition:"border-color 0.15s","&:hover":{borderColor:"primary.main"}},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.25},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:M.bg,color:M.color},children:Yo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ue(S.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:s?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!s,onChange:Z=>g(S.name,Z.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},S.name):e.jsxs(r.Box,{sx:{gridColumn:G?"span 2":"span 1",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",transition:"border-color 0.15s","&:focus-within":{borderColor:"primary.main",boxShadow:`0 0 0 2px ${D(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:D(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:M.bg,color:M.color},children:Yo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ue(S.name)})]}),e.jsx(r.TextField,{value:s??"",onChange:Z=>g(S.name,Z.target.value),type:S.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${S.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:S.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},S.name)})})]}),m.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em"},children:"Read-only Fields"}),e.jsx(r.Tooltip,{title:"Object and array fields cannot be edited directly",arrow:!0,children:e.jsx(w.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:m.map(S=>{const T=i[S.name];let s="";try{s=T==null?"":JSON.stringify(T,null,2)}catch{s=String(T)}const M=ni(S.type,l);return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",opacity:.8},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:D(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:M.bg,color:M.color},children:Yo(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ue(S.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:D(l.text.secondary,.07),color:"text.secondary",border:"none"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:s?"text.primary":"text.disabled",fontStyle:s?"normal":"italic",bgcolor:D(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:s||"No value"})]},S.name)})})]}),f.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(w.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:z,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const ii=170,$d={active:{bg:"success.lighter",color:"success.dark"},completed:{bg:"success.lighter",color:"success.dark"},approved:{bg:"success.lighter",color:"success.dark"},success:{bg:"success.lighter",color:"success.dark"},done:{bg:"success.lighter",color:"success.dark"},contract:{bg:"primary.lighter",color:"primary.main"},"in progress":{bg:"primary.lighter",color:"primary.main"},"in review":{bg:"primary.lighter",color:"primary.main"},review:{bg:"primary.lighter",color:"primary.main"},pending:{bg:"primary.lighter",color:"primary.main"},"on leave":{bg:"error.lighter",color:"error.dark"},"on hold":{bg:"warning.lighter",color:"warning.dark"},probation:{bg:"warning.lighter",color:"warning.dark"},cancelled:{bg:"error.lighter",color:"error.dark"},rejected:{bg:"error.lighter",color:"error.dark"},blocked:{bg:"error.lighter",color:"error.dark"},inactive:{bg:"action.selected",color:"text.secondary"},"not started":{bg:"action.selected",color:"text.secondary"},paused:{bg:"action.selected",color:"text.secondary"},good:{bg:"success.lighter",color:"success.dark"},excellent:{bg:"success.lighter",color:"success.dark"},average:{bg:"warning.lighter",color:"warning.dark"},moderate:{bg:"warning.lighter",color:"warning.dark"},poor:{bg:"error.lighter",color:"error.dark"},bad:{bg:"error.lighter",color:"error.dark"},critical:{bg:"error.lighter",color:"error.dark"},open:{bg:"primary.lighter",color:"primary.main"},closed:{bg:"action.selected",color:"text.secondary"},verified:{bg:"success.lighter",color:"success.dark"},unverified:{bg:"warning.lighter",color:"warning.dark"}},Rd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Wd(t){const o=t.toLowerCase().trim(),n=$d[o]||{bg:"grey.100",color:"grey.600"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Pd(t){const o=t.toLowerCase().trim(),n=Rd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Nd(t){return e.jsx(r.Box,{component:"span",sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.8125rem",fontWeight:400,letterSpacing:"0.04em"},children:t})}function Ld(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),a=o.findIndex(x=>x.name===t.name),c=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),d=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),l=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),p=a===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||p&&!l}function Fd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Vd(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const a=String(o),c=t.name.toLowerCase().replace(/[_\s-]/g,""),d=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(d)return Wd(a);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Pd(a);const p=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(a);if(p)return Nd(a);if(n&&!d&&!l&&!p)return Fd(a);if(t.type==="date"){const x=t.dateFormat??"iso",f=Hs(o,x,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:f})}if(t.type==="number"&&typeof o=="number")return o.toLocaleString();if(typeof o=="boolean")return o?"Yes":"No";if(Array.isArray(o)){if(o.length===0)return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"[ ]"});const x=o.slice(0,3).map(f=>typeof f=="object"?JSON.stringify(f):String(f)).join(", ");return e.jsxs(r.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[x,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const x=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:x,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:x.length>40?x.slice(0,40)+"…":x})}return a}function Hd({schema:t,data:o,sortStack:n=[],filters:i=[],views:a=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:p={},columnOrder:x=[],columnWidths:f={},grouping:b=null,onSort:m,onSortAscending:g,onSortDescending:z,onOpenFilters:y,onOpenSort:C,onOpenFilterForColumn:v,onSelectView:k,onCreateView:S,onManageViews:T,onUpdateCurrentView:s,onSaveAsNewView:M,onToggleDefault:B,onToggleFavorite:$,onRestoreView:G,onPermanentDelete:Z,isAdmin:ee=!1,onExport:h,onOpenColumns:R,onUpdateColumnWidth:W,onUpdateColumnOrder:H,onUpdateColumnVisibility:K,onClearFiltersForColumn:de,onResetLayout:ue,onOpenGroup:te,onGroupByColumn:A,onToggleGroupCollapse:V,onOpenAuditHistory:q,onOpenScheduledReports:re,searchQuery:Q,searchHistory:le=[],onAddToSearchHistory:oe,onToggleSearchFavourite:N,onDeleteSearchHistory:ne,selectedRowIds:ce=new Set,onSearchChange:se,onToggleRowSelection:fe,onToggleAllRows:J,onRangeSelection:Me,onClearSelection:Ne,onExportSelected:et,currentPage:Qt=1,pageSize:gr=15,totalRowsBeforePagination:$t=o.length,onPageChange:ot,onPageSizeChange:Le,isReadOnly:Ee=!1,userRole:mt,reportName:nt,onEditRow:tt,onDuplicateRow:Ge,onDeleteRow:ft,favoriteRowIndices:er=[],resolvedFavoritesSet:qe=new Set,showFavoritesOnly:Je=!1,onToggleRowFavorite:$e,onBulkSetFavorites:tr,showDevPanel:ht=!1,onOpenDevConfig:zt,onToggleFavoritesFilter:rr}){var Ut;const[it,yr]=u.useState(null),[br,vr]=u.useState(0),[Rt,Sr]=u.useState(0),Ke=((Ut=Kt().dates)==null?void 0:Ut.displayFormat)??null,[be,Cr]=u.useState(null),[or,rt]=u.useState(null),[L,Fe]=u.useState(null),[ve,Re]=u.useState(!1),[wr,Wt]=u.useState(!1),[gt,Pt]=u.useState(null),[Nt,Et]=u.useState(""),[kr,Lt]=u.useState(!1),[Oe,X]=u.useState(null),[yt,he]=u.useState(null),[Se,Xe]=u.useState(null),[Tr,bt]=u.useState(null),[We,nr]=u.useState("list"),[Ir,ir]=u.useState(!1),[vt,zr]=u.useState(()=>!Dd("toolbar_search"));u.useRef(null);const Bt=u.useRef(null),Ft=u.useRef(null),St=u.useCallback(()=>{Od("toolbar_search"),zr(!1)},[]);u.useEffect(()=>{if(!vt)return;const I=setTimeout(St,2e3);return()=>clearTimeout(I)},[vt,St]);const sr=u.useMemo(()=>x.length>0?x.map(I=>t.find(F=>F.name===I)).filter(I=>I!==void 0):t,[x,t]),Be=u.useMemo(()=>sr.filter(I=>p[I.name]!==!1),[sr,p]),Pe=u.useMemo(()=>t.filter(I=>p[I.name]===!1).length,[t,p]),Vt=u.useMemo(()=>t.map(I=>I.name),[t]),st=u.useMemo(()=>x.length===0?!1:JSON.stringify(x)!==JSON.stringify(Vt),[x,Vt]),Er=u.useCallback((I,F)=>{I.preventDefault(),I.stopPropagation(),yr(F),vr(I.clientX),Sr(f[F]||150)},[f]);u.useEffect(()=>{if(!it)return;const I=ie=>{const we=ie.clientX-br,ae=Math.max(100,Math.min(600,Rt+we));W==null||W(it,ae)},F=()=>{yr(null)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",F),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",F)}},[it,br,Rt,W]);const Br=u.useCallback(I=>I==null?"-":typeof I=="object"?JSON.stringify(I):typeof I=="boolean"?I?"true":"false":String(I),[]);u.useCallback(I=>{const F=n.find(ie=>ie.column===I);return F?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[F.direction==="asc"?e.jsx(w.ArrowUpward,{sx:{fontSize:14}}):e.jsx(w.ArrowDownward,{sx:{fontSize:14}}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"caption.fontSize",fontWeight:"bold",borderRadius:"50%"},children:F.priority})]}):null},[n]),u.useCallback(I=>i.some(ie=>ie.column===I)?e.jsx(r.IconButton,{size:"small",onClick:ie=>{ie.stopPropagation(),v==null||v(I)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(w.FilterList,{sx:{fontSize:14}})}):null,[i,v]);const Dr=u.useCallback(I=>{m&&m(I)},[m]),Or=u.useCallback((I,F)=>{if(!H)return;const ie=[...x.length>0?x:t.map(ae=>ae.name)],[we]=ie.splice(I,1);ie.splice(F,0,we),H(ie)},[H,x,t]),Ar=u.useCallback(I=>{if(!m)return;const F=n.find(ie=>ie.column===I);(!F||F.direction!=="asc")&&m(I)},[m,n]),Mr=u.useCallback(I=>{if(!m)return;const F=n.find(ie=>ie.column===I);F?F.direction==="asc"&&m(I):(m(I),setTimeout(()=>m(I),0))},[m,n]),ar=u.useCallback(I=>{if(!m)return;const F=n.find(ie=>ie.column===I);F&&(F.direction==="asc"?(m(I),setTimeout(()=>m(I),0)):F.direction==="desc"&&m(I))},[m,n]),_r=u.useCallback(I=>{K&&K(I,!1)},[K]),lr=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],$r=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(p).some(I=>I===!1),Dt=(Qt-1)*gr,_e=o,at=u.useMemo(()=>{const I=new Set;return ce.forEach(F=>{const ie=F==null?void 0:F.__urm_row_id__;ie!==void 0&&I.add(ie)}),I},[ce]);u.useEffect(()=>{const I=F=>{!J||!Ne||F.target instanceof HTMLInputElement||F.target instanceof HTMLTextAreaElement||((F.ctrlKey||F.metaKey)&&F.key==="a"&&(F.preventDefault(),J(!0,_e)),F.key==="Escape"&&(F.preventDefault(),Ne()))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[J,Ne,_e]);const Ot=u.useCallback((I,F)=>{fe&&(F.shiftKey&&be!==null?(F.preventDefault(),Me&&Me(be,I,_e)):(fe(_e[I]),Cr(I)))},[fe,be,Me,_e]);!u.useMemo(()=>_e.length>0&&at.size>0&&_e.every(I=>at.has(I==null?void 0:I.__urm_row_id__)),[_e,at])&&_e.some(I=>at.has(I==null?void 0:I.__urm_row_id__));const jt=fe&&J,cr=u.useCallback(I=>{var we;const F=I.groupLevel,ie=F*24;return e.jsx(r.TableRow,{onClick:()=>V==null?void 0:V(I.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Be.length+(jt?1:0),sx:{pl:`${ie+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[I.isCollapsed?e.jsx(w.ChevronRight,{sx:{fontSize:16}}):e.jsx(w.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:bi(F,((we=b==null?void 0:b.levels[F])==null?void 0:we.column)||"",I.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:ae=>D(ae.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[I.rowCount," ",I.rowCount===1?"row":"rows"]}),Object.keys(I.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(I.aggregates).map(([ae,lt])=>yi(lt)).filter(Boolean).join(" • ")})]})})},I.groupKey)},[Be,jt,b,V]),Ht=u.useCallback((I,F)=>{const ie=at.has(I==null?void 0:I.__urm_row_id__),we=or===F;return e.jsxs(r.TableRow,{"data-row-index":F,onMouseEnter:()=>rt(F),onMouseLeave:()=>rt(null),onClick:ae=>{!fe||ae.target.closest("[data-row-action-btn]")||Ot(F,ae)},onContextMenu:ae=>{ae.preventDefault(),ae.stopPropagation(),Xe({mouseX:ae.clientX,mouseY:ae.clientY,row:I,rowIndex:F})},sx:{height:34,cursor:"pointer",bgcolor:ie?ae=>D(ae.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:ie?ae=>D(ae.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Be.map((ae,lt)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:2,textAlign:"left",...lt===Be.length-1&&{pr:`${$e?56:20}px`},fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:f[ae.name]?`${f[ae.name]}px`:`${ae.type==="date"?Math.max(ii,180):ii}px`},children:Vd(ae,I[ae.name],Ld(ae,Be),Ke)},ae.name)),e.jsx(r.TableCell,{"data-row-action":"true",sx:{position:"sticky",right:0,width:$e?56:20,minWidth:$e?56:20,maxWidth:$e?56:20,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",background:we||qe.has(I)?ae=>`linear-gradient(to right, transparent, ${ie?`rgba(${ae.palette.mode==="dark","237,108,2"},0.12)`:ae.palette.background.paper} 32px)`:"transparent",opacity:we||qe.has(I)?1:0,transition:"opacity 0.12s ease, background 0.12s ease",zIndex:10,verticalAlign:"middle"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:[$e&&e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ae=>{ae.stopPropagation(),ae.preventDefault(),$e(I)},title:qe.has(I)?"Remove from favorites":"Add to favorites",sx:{color:qe.has(I)?"warning.main":"text.secondary","&:hover":{bgcolor:ae=>D(ae.palette.warning.main,.08),color:"warning.main"}},children:qe.has(I)?e.jsx(w.Star,{sx:{fontSize:18}}):e.jsx(w.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{"data-row-action-btn":"true",size:"small",onClick:ae=>{ae.stopPropagation(),ae.preventDefault(),Xe({anchorEl:ae.currentTarget,row:I,rowIndex:F})},sx:{color:"text.secondary",opacity:we?1:0,transition:"opacity 0.12s ease",pointerEvents:we?"auto":"none","&:hover":{bgcolor:ae=>D(ae.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(w.MoreVert,{sx:{fontSize:18}})})]})})]},F)},[ce,Dt,or,Ot,Be,f,Br,tt,Ge,ft,fe,$e,qe,Fe,Re,Xe]);return e.jsxs(kt.DndProvider,{backend:Xo.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[jt&&et&&Ne&&e.jsx(bd,{selectedCount:at.size,selectedRowIds:ce,resolvedFavoritesSet:qe,viewMode:We,onExportSelected:et,onClearSelection:Ne,onBulkSetFavorites:tr}),e.jsxs(r.Box,{sx:{position:"sticky",top:0,zIndex:10,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",px:2,py:0,height:56,display:"flex",alignItems:"center",gap:1},children:[Ee&&e.jsx(Bd,{}),se&&oe&&N&&ne&&e.jsx(r.Tooltip,{open:vt,title:e.jsxs(r.Box,{sx:{p:.5},children:[e.jsx(r.Typography,{variant:"caption",sx:{display:"block",fontWeight:500,mb:.25},children:"💡 Search tip"}),e.jsx(r.Typography,{variant:"caption",children:"Type to search across all columns instantly"})]}),placement:"bottom-start",arrow:!0,PopperProps:{onClick:St},componentsProps:{tooltip:{sx:{bgcolor:"primary.main","& .MuiTooltip-arrow":{color:"primary.main"},maxWidth:220,cursor:"pointer",userSelect:"none"}}},children:e.jsx(r.Box,{component:"span",children:e.jsx(md,{value:Q||"",onChange:I=>{vt&&St(),se(I)},searchHistory:le,onAddToHistory:oe,onToggleFavourite:N,onDeleteHistory:ne,disabled:Ee})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>ir(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:I=>D(I.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})})}),rr&&e.jsx(r.Tooltip,{title:Je?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:rr,size:"small",disabled:Ee,sx:{position:"relative",color:Je?"warning.main":"text.secondary",bgcolor:Je?I=>D(I.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Je?I=>D(I.palette.warning.main,.2):I=>D(I.palette.text.primary,.06),color:Je?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[Je?e.jsx(w.Star,{sx:{fontSize:20}}):e.jsx(w.StarBorder,{sx:{fontSize:20}}),Je&&er.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"warning.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:er.length})]})}),ht&&zt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:zt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:I=>D(I.palette.text.secondary,.3),"&:hover":{bgcolor:I=>D(I.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(w.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),k&&S&&T&&s&&a.length>0&&e.jsx(fd,{views:a||[],activeViewId:c||"",isDirty:d,onSelectView:k,onCreateView:S,onManageViews:T,onToggleDefault:B,onToggleFavorite:$,onRestoreView:G,onPermanentDelete:Z,isAdmin:ee,isReadOnly:Ee}),!Ee&&C&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:C,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Ee&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(w.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Ee&&R&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:R,size:"small",sx:{position:"relative",color:Pe>0||st?"primary.main":"text.secondary",bgcolor:Pe>0||st?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Pe>0||st?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:Pe>0||st?"primary.main":"text.primary"}},children:[e.jsx(w.ViewColumn,{sx:{fontSize:20}}),Pe>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:Pe})]})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"List view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>nr("list"),sx:{borderRadius:1,color:We==="list"?"primary.main":"text.secondary",bgcolor:We==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:We==="list"?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:We==="list"?"primary.main":"text.primary"}},children:e.jsx(w.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>nr("grid"),sx:{borderRadius:1,color:We==="grid"?"primary.main":"text.secondary",bgcolor:We==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:We==="grid"?I=>D(I.palette.primary.main,.2):I=>D(I.palette.text.primary,.06),color:We==="grid"?"primary.main":"text.primary"}},children:e.jsx(w.GridView,{sx:{fontSize:20}})})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"Settings",children:e.jsx(r.IconButton,{onClick:I=>bt(I.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:I=>D(I.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(w.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!Tr,anchorEl:Tr,onClose:()=>bt(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:200,py:.5,borderRadius:1.5,boxShadow:3}},children:[h&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(),bt(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Ee&&te&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{te(),bt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),q&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{q(),bt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),re&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{re(),bt(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Scheduled Reports"})]})]}),e.jsxs(r.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[We==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Id,{data:_e,visibleColumns:Be,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:qe,isReadOnly:Ee,isGrouped:!!lr,sortStack:n,onSort:m,onToggleRowSelection:fe||(()=>{}),onToggleRowFavorite:$e,onToggleGroupCollapse:V,onViewRow:I=>{Fe(I),Re(!0)},onEditRow:(I,F)=>{X(I),he(F),Lt(!0)},onDuplicateRow:(I,F)=>Ge==null?void 0:Ge(I,F),onDeleteRow:(I,F)=>{Pt(F);const ie=Object.values(F).find(we=>we!=null&&we!=="");Et(ie?String(ie):""),Wt(!0)}})}),We==="list"&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.jsx(r.Box,{ref:Bt,onScroll:I=>{Ft.current&&(Ft.current.scrollLeft=I.target.scrollLeft)},sx:{overflowX:"auto",overflowY:"hidden",flexShrink:0,scrollbarWidth:"none","&::-webkit-scrollbar":{display:"none"}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",width:"100%",minWidth:`${Be.reduce((I,F)=>I+(f[F.name]||170),$e?56:20)}px`},children:[e.jsxs("colgroup",{children:[Be.map(I=>e.jsx("col",{style:{width:`${f[I.name]||170}px`}},I.name)),e.jsx("col",{style:{width:`${$e?56:20}px`}})]}),e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Be.map((I,F)=>e.jsx(yd,{column:I,index:F,sortRule:n.find(ie=>ie.column===I.name),hasFilters:i.some(ie=>ie.column===I.name),isInSortStack:n.some(ie=>ie.column===I.name),isReadOnly:Ee,hasModifications:$r,width:f[I.name],onColumnClick:Dr,onMoveColumn:Or,onResizeStart:Er,onSortAscending:g||Ar,onSortDescending:z||Mr,onRemoveSort:ar,onOpenFilterForColumn:v||(()=>{}),onClearFiltersForColumn:de||(()=>{}),onGroupByColumn:A,onHideColumn:_r,onManageColumns:R||(()=>{}),onManageViews:T,onResetLayout:ue},I.name)),e.jsx(r.TableCell,{sx:{width:$e?56:20,minWidth:$e?56:20,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover"}})]})})]})}),e.jsx(r.Box,{ref:Ft,onScroll:I=>{Bt.current&&(Bt.current.scrollLeft=I.target.scrollLeft)},sx:{flex:1,overflowY:"auto",overflowX:"auto",minHeight:0,bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:I=>I.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:I=>I.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",width:"100%",minWidth:`${Be.reduce((I,F)=>I+(f[F.name]||170),$e?56:20)}px`},children:[e.jsxs("colgroup",{children:[Be.map(I=>e.jsx("col",{style:{width:`${f[I.name]||170}px`}},I.name)),e.jsx("col",{style:{width:`${$e?56:20}px`}})]}),e.jsx(r.TableBody,{children:_e.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Be.length+(jt?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):lr?_e.map((I,F)=>I.isGroupHeader?cr(I):Ht(I,F)):_e.map((I,F)=>Ht(I,F))})]})})]}),ot&&Le&&e.jsx(Ed,{currentPage:Qt,pageSize:gr,totalRows:$t,totalFields:t.length,onPageChange:ot,onPageSizeChange:Le}),!(ot&&Le)&&e.jsx(r.Box,{sx:{px:3,py:1.5,bgcolor:"action.hover",borderTop:1,borderColor:"divider"},children:e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Showing ",_e.length," ",_e.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!Se,onClose:()=>Xe(null),anchorEl:(Se==null?void 0:Se.anchorEl)||null,anchorReference:Se!=null&&Se.anchorEl?"anchorEl":"anchorPosition",anchorPosition:Se&&!Se.anchorEl?{top:Se.mouseY,left:Se.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:Se!=null&&Se.anchorEl?{vertical:"top",horizontal:"right"}:{vertical:"top",horizontal:"left"},PaperProps:{sx:{minWidth:170,py:.5,borderRadius:1.5,boxShadow:3}},children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Se&&(Fe(Se.row),Re(!0)),Xe(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Se&&(X(Se.row),he(Se.rowIndex),Lt(!0)),Xe(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{Se&&(Ge==null||Ge(Se.rowIndex,Se.row)),Xe(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(w.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{if(Se){Pt(Se.row);const I=Object.values(Se.row).find(F=>F!=null&&F!=="");Et(I?String(I):""),Wt(!0)}Xe(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(w.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Ad,{open:ve,onClose:()=>{Re(!1),Fe(null)},row:L,schema:t,reportName:nt}),e.jsx(_d,{open:kr,onClose:()=>{Lt(!1),X(null),he(null)},onSave:I=>{yt!==null&&(tt==null||tt(yt,I))},row:Oe,schema:t,reportName:nt}),e.jsx(Md,{open:wr,onClose:()=>{Wt(!1),Pt(null)},onConfirm:()=>{gt!==null&&(ft==null||ft(gt))},rowPreview:Nt}),e.jsx(Vi,{isOpen:Ir,onClose:()=>ir(!1)})]})}function Xt({content:t,isDev:o=!1}){const[n,i]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:a=>i(a.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:a=>D(a.palette.primary.main,.08)}},children:e.jsx(w.InfoOutlined,{sx:{fontSize:15}})}),e.jsxs(r.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:{width:280,borderRadius:"10px",boxShadow:4,p:0,overflow:"hidden"}},children:[e.jsx(r.Box,{sx:{px:2,py:1.5,bgcolor:a=>D(a.palette.primary.main,.06)},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"primary.main",fontSize:"0.875rem"},children:t.title})}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.6},children:t.description}),t.tips&&t.tips.length>0&&e.jsx(r.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:t.tips.map((a,c)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:a},c))}),o&&t.devNote&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:a=>D(a.palette.warning.main,.08),border:"1px solid",borderColor:a=>D(a.palette.warning.main,.2)},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:500,display:"block",mb:.25},children:"Dev note"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.5},children:t.devNote})]})]})]})]})]})}const Zt={filter:{title:"Filter columns",description:"Narrow down rows by setting conditions on any column. Only rows matching all active filters are shown.",tips:["Add multiple conditions to combine filters (AND logic)",'Use "Contains" for partial text matches','Use "Is empty" to find missing values',"Clear all filters to return to the full dataset"],devNote:"Max filter conditions controlled by DevConfig → Filter → maxConditions. Allowed operators also configurable."},sort:{title:"Sort columns",description:"Order rows by one or more columns. Drag levels to set sort priority — the first level is applied first.",tips:["Add multiple sort levels for multi-column sorting","Drag the ⋮⋮ handle to reorder sort priority","Each level can be ascending (A→Z, 0→9) or descending"],devNote:"Max sort levels controlled by DevConfig → Sort → maxLevels."},grouping:{title:"Group data",description:"Organize rows into collapsible groups by one or more column values. Each unique value becomes a group header.",tips:["Add up to 3 nesting levels for hierarchical grouping","Click a group header to collapse or expand it","Aggregates (count) are shown on each group header","Combine grouping with filters and sort for focused views"],devNote:"Max group levels controlled by DevConfig → Grouping → maxLevels. allowNested and allowCollapse also configurable."},columns:{title:"Manage columns",description:"Control which columns are visible, their display order, and their widths.",tips:["Drag rows to reorder columns","Toggle the eye icon to show or hide a column","Drag the resize handle in the table header to resize","Reset to restore default visibility and order"],devNote:"Max visible columns and width range controlled by DevConfig → Columns."},export:{title:"Export data",description:"Download the report data as a file. Choose between CSV, Excel, or JSON format.",tips:["CSV: universal format, opens in any spreadsheet app","Excel: formatted .xlsx file with native Excel support","JSON: structured data including metadata","Export visible rows only (after filters) or all rows"],devNote:"Allowed export formats controlled by DevConfig → Export → allowedFormats."},schedule:{title:"Scheduled reports",description:"Set up automatic exports that run at a specified time — daily, weekly, or monthly.",tips:["The browser tab must remain open for the schedule to fire","Each schedule triggers a file download automatically","Add an email address to open a notification in your mail app","Pause a schedule without deleting it"],devNote:"Schedules are stored in localStorage per-report. Key: urm_schedules_{reportId}."},auditHistory:{title:"Audit history",description:"A full log of all changes made to this report — filters applied, sorts changed, views saved, exports triggered, and more.",tips:["Each entry shows the action, timestamp, and who performed it","Use audit history to trace back unexpected changes"],devNote:"Audit entries are stored per-report in IndexedDB via the persistence layer."}};function Ud({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:a,onClearAll:c,onReplaceFilters:d,onClose:l,focusColumn:p}){const[x,f]=u.useState(""),[b,m]=u.useState(""),[g,z]=u.useState(""),[y,C]=u.useState([]),v=Kt();u.useEffect(()=>{C([...o])},[o]),u.useEffect(()=>{p&&f(p)},[p]);const k=u.useCallback(()=>{f(""),m(""),z("")},[]),S=u.useMemo(()=>t.filter(R=>R.type!=="mixed"&&R.type!=="null"&&R.type!=="array"&&R.type!=="object"),[t]),T=t.find(R=>R.name===x),s=u.useMemo(()=>{const R=T?wn(T.type):[],W=v.filter.allowedOperators;return W.length>0?R.filter(H=>W.includes(H.value)):R},[T]),M=u.useCallback(()=>!(!x||!b||to(b)&&!g.trim()||y.length>=v.filter.maxConditions),[x,b,g,y,v]),B=u.useCallback(()=>{if(!M())return;const R={column:x,operator:b};if(to(b)){const H=T==null?void 0:T.type;R.value=H==="number"?Number(g):g}if(y.some(H=>H.column===R.column&&H.operator===R.operator&&H.value===R.value)){k();return}C([...y,R]),k()},[M,x,b,T,g,y,k]),$=u.useCallback(R=>{C(y.filter((W,H)=>H!==R))},[y]),G=u.useMemo(()=>y.length!==o.length?!0:JSON.stringify(y)!==JSON.stringify(o),[y,o]),Z=u.useCallback(()=>{d(y),l()},[y,d,l]),ee=u.useCallback(()=>{C([...o]),k(),l()},[o,k,l]),h=u.useCallback(R=>{var de;const W=t.find(ue=>ue.name===R.column);if(!W)return"";const K=((de=wn(W.type).find(ue=>ue.value===R.operator))==null?void 0:de.label)||R.operator;return to(R.operator)?`${R.column} ${K.toLowerCase()} "${R.value}"`:`${R.column} ${K.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:ee,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:R=>R.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Filter columns"}),e.jsx(Xt,{content:Zt.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:y.length>=v.filter.maxConditions,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Column"}),e.jsx(r.Select,{value:x,onChange:R=>{f(R.target.value),m(""),z("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:S.map(R=>e.jsxs(r.MenuItem,{value:R.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:W=>D(W.palette.primary.main,.2)}}},children:[Ue(R.name)," (",R.type,")"]},R.name))})]}),x&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Operator"}),e.jsx(r.Select,{value:b,onChange:R=>{m(R.target.value),z("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:s.map(R=>e.jsx(r.MenuItem,{value:R.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:W=>D(W.palette.primary.main,.2)}}},children:R.label},R.value))})]}),b&&to(b)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(T==null?void 0:T.type)==="number"?"number":"text",value:g,onChange:R=>z(R.target.value),label:"Value",placeholder:"Enter value...",sx:{"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:B,disabled:!M(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add another filter"}),y.length>=v.filter.maxConditions&&e.jsxs(r.Typography,{variant:"caption",sx:{display:"block",mt:.75,color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Filter limit reached — maximum ",v.filter.maxConditions," filters allowed. Remove an existing filter to add a new one."]})]}),y.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Active filters (",y.length,")"]}),e.jsx(r.Button,{onClick:()=>{c(),l()},sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"error.dark",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:y.map((R,W)=>e.jsx(r.Chip,{label:h(R),onDelete:()=>$(W),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:H=>`1px solid ${D(H.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:H=>D(H.palette.primary.main,.2),borderColor:"#aecbfa"},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},W))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Z,disabled:!G,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"grey.300",color:"grey.500"}},children:"Apply filter"})]})]})})}const si="SORT_RULE";function Yd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:a}){const c=u.useRef(null),[{handlerId:d},l]=kt.useDrop({accept:si,collect(f){return{handlerId:f.getHandlerId()}},hover(f,b){var k;if(!c.current)return;const m=f.index,g=o;if(m===g)return;const z=(k=c.current)==null?void 0:k.getBoundingClientRect(),y=(z.bottom-z.top)/2,C=b.getClientOffset(),v=((C==null?void 0:C.y)??0)-z.top;m<g&&v<y||m>g&&v>y||(a(m,g),f.index=g)}}),[{isDragging:p},x]=kt.useDrag({type:si,item:()=>({index:o}),collect:f=>({isDragging:f.isDragging()})});return x(l(c)),e.jsxs(r.Box,{ref:c,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:p?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)",transform:"translateY(-1px)"}},children:[e.jsx(r.Chip,{label:t.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)","& .MuiChip-label":{px:0}}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:f=>n(o,f.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:f=>D(f.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:f=>D(f.palette.primary.main,.2)}}},children:"Descending"})]})}),e.jsx(r.IconButton,{onClick:()=>i(o),size:"small",sx:{p:.5,color:"text.secondary",transition:"all 0.2s ease","&:hover":{color:"error.main",bgcolor:"rgba(217, 48, 37, 0.08)",transform:"scale(1.1)"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]})}function Gd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[a,c]=u.useState(""),[d,l]=u.useState([]);u.useEffect(()=>{l([...o])},[o]);const p=u.useMemo(()=>JSON.stringify(d)!==JSON.stringify(o),[d,o]),x=Kt(),f=u.useCallback(()=>!(d.length>=x.sort.maxLevels||!a||d.some(S=>S.column===a)),[d,a]),b=u.useCallback(()=>{if(!f())return;const S=d.length+1,T={column:a,direction:"asc",priority:S};l([...d,T]),c("")},[f,a,d]),m=u.useCallback(S=>{const s=d.filter((M,B)=>B!==S).map((M,B)=>({...M,priority:B+1}));l(s)},[d]),g=u.useCallback((S,T)=>{const s=[...d];s[S]={...s[S],direction:T},l(s)},[d]),z=u.useCallback((S,T)=>{const s=[...d],[M]=s.splice(S,1);s.splice(T,0,M);const B=s.map(($,G)=>({...$,priority:G+1}));l(B)},[d]),y=u.useCallback(()=>{n([]),i()},[n,i]),C=u.useCallback(()=>{n(d),i()},[d,n,i]),v=u.useCallback(()=>{l([...o]),c(""),i()},[o,i]),k=t.filter(S=>!d.some(T=>T.column===S.name));return e.jsx(kt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:v,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:S=>S.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),e.jsx(Xt,{content:Zt.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:v,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:d.length>=x.sort.maxLevels,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Select column..."}),e.jsx(r.Select,{value:a,onChange:S=>c(S.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:k.map(S=>e.jsx(r.MenuItem,{value:S.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:T=>D(T.palette.primary.main,.2)}}},children:Ue(S.name)},S.name))})]}),e.jsx(r.Button,{onClick:b,disabled:!f(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),d.length>=x.sort.maxLevels&&e.jsxs(r.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",x.sort.maxLevels," sort levels allowed"]})]}),d.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",d.length,"/",x.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:y,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((S,T)=>e.jsx(Yd,{rule:S,index:T,onToggleDirection:g,onRemove:m,onMove:z},`${S.column}-${T}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:v,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:C,variant:"contained",disabled:!p||d.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function qd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:a,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:p,isAdmin:x=!1,onClose:f}){var S,T;const m=It().palette,g=t.filter(s=>!s.isDeleted),z=t.filter(s=>s.isDeleted),y=g.filter(s=>s.scope==="global"),C=g.filter(s=>s.scope!=="global"),v=s=>{var Z,ee,h,R,W;const M=s.scope==="global",B=s.id===o,$=x||!M,G=x&&!M;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:B?"primary.main":"divider",bgcolor:B?D(m.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:B?"primary.main":D(m.text.primary,.22)}},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.75,py:1.25,gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,minWidth:0,cursor:"pointer",display:"flex",alignItems:"center",gap:1},onClick:()=>{n(s.id),f()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:B?600:500,color:B?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.name}),s.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[M&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(w.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:D(((Z=m.info)==null?void 0:Z.main)??m.primary.main,.1),color:((ee=m.info)==null?void 0:ee.main)??m.primary.main,border:`1px solid ${D(((h=m.info)==null?void 0:h.main)??m.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),s.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:D(m.text.secondary,.08),color:"text.secondary","& .MuiChip-label":{px:.75}}})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[G&&p&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:H=>{H.stopPropagation(),p(s.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((R=m.info)==null?void 0:R.main)??m.primary.main,bgcolor:D(((W=m.info)==null?void 0:W.main)??m.primary.main,.08)}},children:e.jsx(w.Language,{sx:{fontSize:16}})})}),$&&e.jsx(r.Tooltip,{title:M&&!x?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:M&&!x,onClick:H=>{H.stopPropagation(),a(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:D(m.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:M&&!x?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:M&&!x,onClick:H=>{H.stopPropagation(),c(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:D(m.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})})]})]})},s.id)},k=s=>{var M;return e.jsxs(r.Paper,{variant:"outlined",sx:{px:1.75,py:1.25,borderRadius:"8px",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:D(m.text.primary,.02)},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",color:"text.disabled",textDecoration:"line-through",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[d&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),d(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:D(((M=m.success)==null?void 0:M.main)??"#2e7d32",.08)}},children:e.jsx(w.Undo,{sx:{fontSize:15}})})}),l&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),l(s.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:D(m.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]},s.id)};return e.jsxs(r.Dialog,{open:!0,onClose:f,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"14px",maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${D(((S=m.common)==null?void 0:S.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600},children:"Manage Views"}),x&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:"Admin mode — you can promote Personal Views to Global"})]}),e.jsx(r.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.Add,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",borderRadius:"7px",fontWeight:500},children:"Create New View"})}),y.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1},children:[e.jsx(w.Language,{sx:{fontSize:14,color:((T=m.info)==null?void 0:T.main)??m.primary.main}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Global Views"}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:"— visible to all users"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:y.map(v)})]}),C.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Personal Views"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:C.map(v)})]}),z.length>0&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.disabled",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Recently Deleted"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:z.map(k)})]}),g.length===0&&z.length===0&&e.jsx(r.Box,{sx:{py:4,textAlign:"center",color:"text.disabled"},children:e.jsx(r.Typography,{variant:"body2",children:"No views created yet"})})]}),e.jsx(r.DialogActions,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:f,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const so=50;function ai({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:a="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:p=10}){const[x,f]=u.useState(a),[b,m]=u.useState(!1),[g,z]=u.useState(c),[y,C]=u.useState(d),v=()=>{if(!x.trim()){m(!0);return}if(x.trim().length>so){m(!0);return}o(x.trim(),g.trim(),y),n()},k=T=>{T.key==="Enter"&&!T.shiftKey?v():T.key==="Escape"&&n()},S=()=>i&&a?`Update ${a} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[S(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",p," saved views. Delete an existing view before creating a new one."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:x,onChange:T=>{T.target.value.length<=so&&f(T.target.value),b&&T.target.value.trim()&&m(!1)},onKeyDown:k,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:so},error:b&&!x.trim(),helperText:b&&!x.trim()?"View name is required":`${x.length} / ${so}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:T=>z(T.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),e.jsxs(r.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1},children:"This view will capture:"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[e.jsxs("li",{children:[t.filters.length," filter",t.filters.length!==1?"s":""]}),e.jsxs("li",{children:["Sorting: ",oa(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:y,onChange:T=>C(T.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:v,variant:"contained",disabled:l&&!i,startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:i?"Save Changes":"Create Report View"})]})]})}function Jd({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["Delete View",e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,mt:1},children:[e.jsx(w.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete View"})]})]})}const lo=100,co=600,li="COLUMN";function Kd({column:t,index:o,isVisible:n,width:i,onToggleVisibility:a,onWidthChange:c,moveColumn:d}){const l=u.useRef(null),[p,x]=u.useState(i.toString());u.useEffect(()=>{x(i.toString())},[i]);const[{handlerId:f},b]=kt.useDrop({accept:li,collect(k){return{handlerId:k.getHandlerId()}},hover(k,S){var Z;if(!l.current)return;const T=k.index,s=o;if(T===s)return;const M=(Z=l.current)==null?void 0:Z.getBoundingClientRect(),B=(M.bottom-M.top)/2,$=S.getClientOffset(),G=(($==null?void 0:$.y)??0)-M.top;T<s&&G<B||T>s&&G>B||(d(T,s),k.index=s)}}),[{isDragging:m},g]=kt.useDrag({type:li,item:()=>({index:o}),collect:k=>({isDragging:k.isDragging()})});g(b(l));const z=()=>{const k=parseInt(p);if(isNaN(k)){x(i.toString()),c(t.name,i);return}const S=Math.max(lo,Math.min(co,k));x(S.toString()),c(t.name,S)},y=k=>{if(k===""||/^\d+$/.test(k)){x(k);const S=parseInt(k);if(!isNaN(S)&&S>=lo){const T=Math.min(co,S);c(t.name,T)}}},C=k=>{k.key==="Enter"&&(k.preventDefault(),z(),k.target.blur())},v=k=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[k]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":f,sx:{opacity:m?.4:1,bgcolor:n?"background.paper":"grey.50",transition:"opacity 0.15s ease","&:hover":{bgcolor:n?"grey.50":"grey.100"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(w.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ue(t.name)})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsx(r.Chip,{label:t.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${v(t.type)}15`,color:v(t.type),border:`1px solid ${v(t.type)}30`,"& .MuiChip-label":{px:1}}})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.TextField,{type:"number",value:p,onChange:k=>y(k.target.value),onBlur:z,onKeyDown:C,placeholder:"150",size:"small",inputProps:{min:lo,max:co,step:10},sx:{width:90,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"},"& input[type=number]::-webkit-inner-spin-button":{opacity:1},"& input[type=number]::-webkit-outer-spin-button":{opacity:1}}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"px"})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.IconButton,{onClick:()=>a(t.name,!n),title:n?"Hide column":"Show column",size:"small",sx:{p:.75,color:n?"primary.main":"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(w.Visibility,{sx:{fontSize:20}}):e.jsx(w.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?"#e6f4ea":"grey.100",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Xd({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:a=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:p,onResetLayout:x,onSaveToCurrentView:f,onSaveToAllViews:b,onSelectView:m,onClose:g}){const[z,y]=u.useState(!1),[C,v]=u.useState(n),[k,S]=u.useState(i),[T,s]=u.useState("all"),[M,B]=u.useState(null);u.useEffect(()=>{v(n)},[n]),u.useEffect(()=>{S(i)},[i]);const $=(te,A)=>{S(V=>({...V,[te]:A})),p==null||p(te,A)},G=(te,A)=>{const V=[...C],[q]=V.splice(te,1);V.splice(A,0,q),v(V),l(V)},Z=()=>{x(),y(!1)},h=C.map(te=>t.find(A=>A.name===te)).filter(te=>te!==void 0).filter(te=>{const A=o[te.name]??!0;return T==="active"?A:T==="hidden"?!A:!0}),R=Object.values(o).filter(te=>te).length,W=t.length,H=a.find(te=>te.id===c),K=a.filter(te=>!te.isDeleted),de=K.length>1,ue=u.useMemo(()=>{if(!H)return!1;const te=H.snapshot,A=te.columnVisibility??{},V=JSON.stringify(o)!==JSON.stringify(A),q=te.columnOrder??[],re=n??[],Q=JSON.stringify(re)!==JSON.stringify(q)&&!(re.length===0&&q.length===0),le=te.columnWidths??{},oe=JSON.stringify(k)!==JSON.stringify(le);return V||Q||oe},[H,o,n,k]);return e.jsx(kt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:te=>te.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2,pb:1.5,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsxs(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",e.jsx(Xt,{content:Zt.columns,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5},children:[R," of ",W," columns visible • Drag to reorder"]})]}),K.length>0&&m&&e.jsxs(r.Box,{sx:{ml:2},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",color:"text.secondary",mb:.75,display:"block",textTransform:"uppercase",fontWeight:600,letterSpacing:"0.1em"},children:"View:"}),e.jsx(r.Button,{onClick:te=>B(te.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(H==null?void 0:H.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:M,open:!!M,onClose:()=>B(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:K.map(te=>e.jsx(r.MenuItem,{onClick:()=>{m(te.id),B(null)},selected:te.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:A=>D(A.palette.primary.main,.2)}}},children:te.name},te.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:T,onChange:(te,A)=>s(A),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:"primary.main",height:3}},children:[e.jsx(r.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}})]})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${lo}px, max: ${co}px)`,arrow:!0,placement:"top",children:e.jsx(w.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:h.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:4,align:"center",sx:{py:6,borderBottom:"none"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):h.map((te,A)=>e.jsx(Kd,{column:te,index:A,isVisible:o[te.name]??!0,width:k[te.name]||170,onToggleVisibility:d,onWidthChange:$,moveColumn:G},te.name))})]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!0),disabled:!ue,variant:"outlined",startIcon:e.jsx(w.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[f&&e.jsx(r.Button,{onClick:()=>{f(k),g()},disabled:!ue,variant:"contained",startIcon:e.jsx(w.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&de&&e.jsx(r.Button,{onClick:()=>{b(k),g()},disabled:!ue||!de,variant:"contained",startIcon:e.jsx(w.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),z&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1400},children:e.jsxs(r.Paper,{onClick:te=>te.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:"12px",bgcolor:"background.paper",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,borderRadius:"4px","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Z,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function Zd({schema:t,grouping:o,onApply:n,onClose:i}){var M;const[a,c]=u.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=u.useState(""),[p,x]=u.useState(null),f=u.useMemo(()=>Xs(t),[t]),b=u.useMemo(()=>f.filter(B=>!a.levels.some(($,G)=>$.column===B.name&&G!==p)),[f,a.levels,p]),m=Kt(),g=a.levels.length<m.grouping.maxLevels&&b.length>0,z=u.useCallback(()=>{!g||!d||(c({...a,levels:[...a.levels,{column:d}],enabled:!0}),l(""))},[g,d,a]),y=u.useCallback(B=>{const $=a.levels.filter((G,Z)=>Z!==B);if($.length===0){n(null),i();return}c({...a,levels:$,enabled:$.length>0})},[a,n,i]),C=u.useCallback(B=>{x(B),l(a.levels[B].column)},[a.levels]),v=u.useCallback(()=>{if(p===null||!d)return;const B=[...a.levels];B[p]={column:d},c({...a,levels:B}),x(null),l("")},[p,d,a]),k=u.useCallback(()=>{x(null),l("")},[]),S=u.useCallback((B,$)=>{const G=$==="up"?B-1:B+1;if(G<0||G>=a.levels.length)return;const Z=[...a.levels],[ee]=Z.splice(B,1);Z.splice(G,0,ee),c({...a,levels:Z})},[a]),T=u.useCallback(()=>{n(null),i()},[n,i]),s=u.useCallback(()=>{a.levels.length===0?n(null):n({...a,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[a,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:B=>B.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),e.jsx(Xt,{content:Zt.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Stack,{spacing:2.5,children:[p===null&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:B=>l(B.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:$=>D($.palette.primary.main,.2)}}},children:[Ue(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsx(r.Button,{onClick:z,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),a.levels.length>=m.grouping.maxLevels&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),f.length===0&&e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),p!==null&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px",border:"1px solid #fdd663",bgcolor:"#fef7e0","& .MuiAlert-icon":{color:"#ea8600"}},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1.5,fontSize:"0.875rem",color:"text.primary"},children:["Edit Group Level ",p+1]}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:B=>l(B.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:a.levels[p].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[a.levels[p].column," (",(M=t.find(B=>B.name===a.levels[p].column))==null?void 0:M.type.toUpperCase(),")"]}),b.filter(B=>B.name!==a.levels[p].column).map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[Ue(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:v,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"#ea8600",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"#c96e00",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)"}},children:"Save"}),e.jsx(r.Button,{onClick:k,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),a.levels.length>0&&p===null&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),e.jsx(r.Button,{onClick:T,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:a.levels.map((B,$)=>{const G=t.find(Z=>Z.name===B.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1)"}},children:[e.jsx(r.Chip,{label:`L${$+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)"}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:B.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:G==null?void 0:G.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"up"),disabled:$===0,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(w.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"down"),disabled:$===a.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(w.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>C($),sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100",color:"primary.main"}},children:e.jsx(w.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y($),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(w.Delete,{sx:{fontSize:18}})})]})]},$)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:s,variant:"contained",disabled:a.levels.length===0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const Qd={filters:w.FilterList,sorting:w.UnfoldMore,visibility:w.Visibility,order:w.ViewColumn,widths:w.Straighten,grouping:w.Layers};function eu({changes:t,onClose:o}){const n=i=>({filters:"primary",sorting:"secondary",visibility:"success",order:"warning",widths:"info",grouping:"error"})[i]||"default";return e.jsxs(r.Dialog,{open:!0,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["View Changes Summary",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,children:t.length===0?e.jsx(r.Box,{sx:{textAlign:"center",py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No changes detected"})}):e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"The following modifications have been made to this view:"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:t.map((i,a)=>{const c=Qd[i.category];return e.jsxs(r.Paper,{elevation:0,sx:{display:"flex",gap:1.5,p:1.5,border:1,borderColor:"divider",borderRadius:1},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:1,bgcolor:`${n(i.category)}.lighter`,color:`${n(i.category)}.main`,flexShrink:0},children:e.jsx(c,{sx:{fontSize:16}})}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:i.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:i.description})]})]},a)})})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})}function tu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:a,onCancel:c}){const[d,l]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:"primary.lighter",borderBottom:p=>`1px solid ${D(p.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:"rgba(60, 64, 67, 0.08)",color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:a,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:"0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px rgba(60, 64, 67, 0.15)"}},children:"Save as new view"})]})]})}),d&&e.jsx(eu,{changes:n,onClose:()=>l(!1)})]})}function ru({onExportAnyway:t,onSaveAndExport:o,onCancel:n}){return e.jsx(r.Box,{sx:{mb:2,mx:3,mt:2},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(w.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,mb:.5},children:"You are exporting with unsaved view changes"}),e.jsx(r.Typography,{variant:"body2",sx:{mb:1.5},children:"Your current view has unsaved changes. Choose how to proceed:"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,variant:"contained",color:"primary",startIcon:e.jsx(w.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(w.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const ci=[{key:"1h",label:"Last 1 Hour",ms:3600*1e3},{key:"24h",label:"Last 24 Hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 Days",ms:10080*60*1e3},{key:"30d",label:"Last 30 Days",ms:720*60*60*1e3},{key:"all",label:"All Time",ms:null}];function ou(t,o){if(o===null)return t.length;const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()>=n).length}function nu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function iu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var z,y,C,v;const a=It().palette,[c,d]=u.useState("1h"),[l,p]=u.useState(!1),x=[...t].sort((k,S)=>new Date(S.timestamp).getTime()-new Date(k.timestamp).getTime()),f=ci.find(k=>k.key===c),b=ou(t,f.ms),m=()=>p(!0),g=()=>{n&&(n(nu(t,f.ms)),p(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:D(((z=a.common)==null?void 0:z.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:k=>k.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"16px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${D(((y=a.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${D(((C=a.common)==null?void 0:C.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,borderBottom:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),e.jsx(Xt,{content:Zt.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[x.length," event",x.length!==1?"s":""," recorded"]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Select,{value:c,onChange:k=>d(k.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:D(a.text.primary,.3)}},children:ci.map(k=>e.jsx(r.MenuItem,{value:k.key,sx:{fontSize:"0.8125rem"},children:k.label},k.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:m,sx:{textTransform:"none",fontSize:"0.75rem",fontWeight:500,borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:D(a.error.main,.5),"&:hover":{bgcolor:D(a.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:D(a.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D(a.text.primary,.14),borderRadius:3}},children:x.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(w.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",color:"text.secondary",fontWeight:500},children:"No audit events yet"}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:x.map(k=>{const S=va(k.feature),{summary:T,detail:s}=ha(k);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.25,px:1.5,py:1.25,borderRadius:"10px",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",transition:"border-color 0.15s","&:hover":{borderColor:D(a.text.primary,.18)}},children:[e.jsx(r.Chip,{label:ba(k.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:D(S,.1),color:S,border:`1px solid ${D(S,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:T}),s&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:s}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(w.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:Sa(k.timestamp)})]}),k.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(w.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:k.user})]})]})]})]},k.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>p(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${D(((v=a.common)==null?void 0:v.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:D(a.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["You are about to permanently remove"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:[b," audit record",b!==1?"s":""]})," ",f.key==="all"?"from all time":`from the ${f.label.toLowerCase()}`,". This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:()=>p(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",disableElevation:!0,startIcon:e.jsx(w.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function su({onSave:t,onClose:o}){const[n,i]=u.useState(""),[a,c]=u.useState(""),[d,l]=u.useState(""),[p,x]=u.useState([]),[f,b]=u.useState(""),[m,g]=u.useState(""),z=s=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s),y=()=>{const s=d.trim();if(s){if(!z(s)){g("Please enter a valid email address");return}if(p.includes(s)){g("This email is already added");return}x([...p,s]),l(""),g("")}},C=s=>{x(p.filter(M=>M!==s))},v=s=>{s.key==="Enter"&&(s.preventDefault(),y())},k=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),a.trim(),p.length>0?p:void 0)},S=s=>{i(s),f&&b("")},T=s=>{l(s),m&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:s=>s.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(w.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:s=>`1px solid ${D(s.palette.primary.main,.3)}`,bgcolor:"primary.lighter","& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.6},children:"Save the current report configuration and generate a shareable link that others can use to view the same filters, sorting, and column layout."}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),e.jsx(r.TextField,{required:!0,value:n,onChange:s=>S(s.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!f,helperText:f,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value:a,onChange:s=>c(s.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:d,onChange:s=>T(s.target.value),onKeyPress:v,placeholder:"Enter email address",error:!!m,helperText:m,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),e.jsx(r.Button,{onClick:y,variant:"outlined",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",px:2,py:1.25,minHeight:40,borderRadius:"4px",flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:"Add"})]}),p.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:p.map(s=>e.jsx(r.Chip,{label:s,onDelete:()=>C(s),deleteIcon:e.jsx(w.Delete,{sx:{fontSize:16}}),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},s))}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:p.length>0?`An email with the shareable link will be sent to ${p.length} recipient${p.length>1?"s":""}`:"Add email addresses to send the shareable link automatically"})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:k,variant:"contained",startIcon:e.jsx(w.Share,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function au({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(w.Link,{sx:{fontSize:14}}),label:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Preset:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600},children:t})]}),onDelete:o,deleteIcon:e.jsx(r.IconButton,{size:"small",title:"Exit preset view",sx:{p:0},children:e.jsx(w.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>D(n.palette.primary.main,.12),borderColor:"primary.light",border:1,fontSize:"body2.fontSize",fontWeight:500,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.main"}}}})}function lu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:a}){const[c,d]=u.useState(null),l=p=>new Date(p).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:a,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:p=>p.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"common.white",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[t.length," saved ",t.length===1?"preset":"presets"]})]}),e.jsx(r.IconButton,{onClick:a,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:"#bdc1c6"}}},children:t.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[e.jsx(w.Share,{sx:{fontSize:48,color:"divider",mb:2}}),e.jsx(r.Typography,{variant:"body1",sx:{fontSize:"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"#80868b",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:t.map(p=>e.jsxs(r.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"common.white",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary",mb:.5},children:p.name}),p.description&&e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:p.description})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[e.jsx(r.Chip,{label:`Created ${l(p.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}}),e.jsx(r.Chip,{label:`By ${p.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),e.jsx(r.Divider,{sx:{my:1.5,borderColor:"#f1f3f4"}}),e.jsx(r.Box,{sx:{display:"flex",gap:1},children:e.jsx(r.Button,{onClick:()=>i(p.id,p.name),variant:"outlined",size:"small",startIcon:e.jsx(w.Delete,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:"4px","&:hover":{borderColor:"error.main",bgcolor:"rgba(217, 48, 37, 0.04)"}},children:"Delete"})})]},p.id))})}),e.jsx(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:e.jsx(r.Button,{onClick:a,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})})}const Yi={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},cu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],du=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function uu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const a=du.some(l=>l.test(i.name));let c=!1;const d=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);d.length>0&&(c=d.filter(p=>cu.some(x=>x.test(p))).length/d.length>.6),(a||c)&&n.push(i.name)}return n}function an(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),a=o.map(d=>{const l=n.map(x=>String(x[d]??"")).filter(x=>x.length>0);if(l.length===0)return 5;const p=l.reduce((x,f)=>x+f.length,0);return Math.ceil(p/l.length)+1}).reduce((d,l)=>d+l,0)+1;return o.reduce((d,l)=>d+l.length+1,0)+a*t.length}function pu(t,o){const n=an(t,o);return Math.ceil(n*3.5)}function xu(t,o){const n=an(t,o);return Math.ceil(n*.7)}function mu(t,o,n){switch(t){case"csv":return an(o,n);case"excel":return xu(o,n);case"json":return pu(o,n)}}function di(t,o){return Math.ceil(t/o)}function fu(t,o,n,i,a=Yi){const c=[],d=mu(t,o,n),l=o.length;if(l>a.maxRowsHard){const f=di(l,a.maxRows);c.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${a.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${f} smaller exports of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:a.maxRowsHard})}else if(l>a.maxRows){const f=di(l,a.maxRows);c.push({type:"row_count",severity:"warning",message:`Large export: ${l.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${f} smaller export${f>1?"s":""} of ~${a.maxRows.toLocaleString()} rows each.`,suggestedBatches:f,value:l,limit:a.maxRows})}if(d>a.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Gr(d)} exceeds the ${Gr(a.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:d,limit:a.maxFileSizeHardBytes}):d>a.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Gr(d)}`,detail:`This exceeds the recommended ${Gr(a.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:a.maxFileSizeBytes}),t!=="excel"){const f=uu(i.filter(b=>n.includes(b.name)),o);if(f.length>0){const b=f.length>a.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${f.length>1?"s":""} detected: ${f.map(m=>`"${m.replace(/_/g," ")}"`).join(", ")}`,detail:b?`Exporting ${f.length} image columns may produce a very large file. Consider hiding these columns before exporting.`:"Image URL columns are included in the export as plain text links — not embedded images.",value:f.length,limit:a.maxImageColumns})}}const p=c.some(f=>f.severity==="error"),x=c.some(f=>f.severity==="warning");return{violations:c,hasBlockingViolation:p,hasWarning:x,estimatedBytes:d}}function Gr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function hu({violation:t}){const n=It().palette,i=t.severity==="error",a=i?n.error.main:n.warning.main,c=D(i?n.error.main:n.warning.main,.06),d=i?D(n.error.main,.25):D(n.warning.main,.3),l=i?w.ErrorOutline:w.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:c,border:"1px solid",borderColor:d},children:[e.jsx(l,{sx:{fontSize:17,color:a,flexShrink:0,mt:.125}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:t.message}),t.detail&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:t.detail}),t.suggestedBatches&&t.suggestedBatches>1&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[e.jsx(w.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function gu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:a,schema:c,sampleRows:d=[],allRows:l=[],processedRows:p=[],onExport:x,onClose:f}){var R,W,H;const m=It().palette,g=Kt(),[z,y]=u.useState(g.export.allowedFormats[0]||"csv"),[C,v]=u.useState("visible"),[k,S]=u.useState("visible"),T=C==="visible"?o:t,s=k==="visible"?i:a,M=u.useMemo(()=>C==="visible"?p.length>0?p:new Array(o):l.length>0?l:new Array(t),[C,o,t,p,l]),B=u.useMemo(()=>k==="all"?c.map(K=>K.name):c.map(K=>K.name).slice(0,i),[k,c,i]),$=u.useMemo(()=>fu(z,M,B,c,Yi),[z,M,B,c]),G=()=>{$.hasBlockingViolation||(x({format:z,scope:C,columnScope:k}),f())},Z={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},ee={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},h={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:f,sx:{position:"fixed",inset:0,bgcolor:D(((R=m.common)==null?void 0:R.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:K=>K.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 180px))",display:"flex",flexDirection:"column",borderRadius:"14px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${D(((W=m.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${D(((H=m.common)==null?void 0:H.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(Xt,{content:Zt.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:f,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflowY:"auto",px:3,py:2.5,display:"flex",flexDirection:"column",gap:2.5,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:D(m.text.primary,.15),borderRadius:3}},children:[$.violations.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:$.violations.map((K,de)=>e.jsx(hu,{violation:K},de))}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Format"}),e.jsxs(r.RadioGroup,{value:z,onChange:K=>y(K.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Comma-separated values, compatible with Excel"})]}),sx:{...ee,mb:.5}}),g.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Native Excel format with formatting support"})]}),sx:{...ee,mb:.5}}),g.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"JSON"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Structured data with metadata and filters"})]}),sx:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Rows"}),e.jsxs(r.RadioGroup,{value:C,onChange:K=>v(K.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",o.toLocaleString()," rows (filtered and searched)"]})]}),sx:{...ee,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",t.toLocaleString()," rows (complete original dataset)"]})]}),sx:ee})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Columns"}),e.jsxs(r.RadioGroup,{value:k,onChange:K=>S(K.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible columns only"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",i," visible column",i!==1?"s":""]})]}),sx:{...ee,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:h}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",a," columns (including hidden)"]})]}),sx:ee})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Divider,{sx:{mb:2}}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[{label:"Format",value:Z[z]},{label:"Rows to export",value:T.toLocaleString()},{label:"Columns to export",value:String(s)},{label:"Estimated file size",value:Gr($.estimatedBytes),highlight:$.hasBlockingViolation?"error.main":$.hasWarning?"warning.main":void 0}].map(({label:K,value:de,highlight:ue})=>e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary"},children:K}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:ue??"text.primary"},children:de})]},K))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:D(m.text.primary,.015)},children:[$.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(w.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"error.main",fontWeight:500},children:"Reduce rows or columns to enable download"})]}),e.jsx(r.Button,{onClick:f,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:G,disabled:$.hasBlockingViolation,variant:"contained",disableElevation:!0,startIcon:e.jsx(w.Download,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"8px"},children:["Download ",Z[z]]})]})]})})}function yu({warning:t,onDismiss:o}){return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(w.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:t.message}),e.jsxs(r.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",t.type==="filter"?"filters":t.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function bu({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){u.useEffect(()=>{if(n){const l=setTimeout(()=>{o()},i);return()=>clearTimeout(l)}},[n,i,o]);const c=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(w.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(w.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(w.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Ma(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:c.severity,icon:c.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${c.severity}.main`},children:e.jsx(w.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${c.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:d}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class vu extends u.Component{constructor(o){super(o),this.handleReset=()=>{this.setState({hasError:!1,error:null})},this.state={hasError:!1,error:null}}static getDerivedStateFromError(o){return{hasError:!0,error:o}}componentDidCatch(o,n){qt.error("urm:error-boundary","Caught unhandled component error",o,n),this.props.onError&&this.props.onError(o,n)}render(){var o,n;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsx(r.Paper,{sx:{bgcolor:i=>D(i.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:i=>D(i.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:170},children:(n=this.state.error)==null?void 0:n.stack}),e.jsx(r.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:e.jsx(w.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Su({feature:t}){const[o,n]=u.useState(!0);return u.useEffect(()=>{const i=setTimeout(()=>n(!1),5e3);return()=>clearTimeout(i)},[]),e.jsx(r.Collapse,{in:o,unmountOnExit:!0,children:e.jsxs(r.Alert,{severity:"warning",sx:{m:1},icon:e.jsx(w.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:()=>n(!1),"aria-label":"dismiss",sx:{color:"warning.dark"},children:e.jsx(w.Close,{sx:{fontSize:16}})}),children:[e.jsxs(r.AlertTitle,{children:[t," temporarily unavailable"]}),"Other features continue to work normally"]})})}function Fr({children:t,feature:o,onError:n}){return e.jsx(vu,{context:o,onError:(i,a)=>{n&&n(i)},fallback:e.jsx(Su,{feature:o}),children:t})}const ju=[{value:"equals",label:"Equals",group:"Text"},{value:"contains",label:"Contains",group:"Text"},{value:"startsWith",label:"Starts with",group:"Text"},{value:"endsWith",label:"Ends with",group:"Text"},{value:"gt",label:"Greater than (>)",group:"Numeric"},{value:"lt",label:"Less than (<)",group:"Numeric"},{value:"gte",label:"At least (≥)",group:"Numeric"},{value:"lte",label:"At most (≤)",group:"Numeric"},{value:"isTrue",label:"Is true",group:"Boolean"},{value:"isFalse",label:"Is false",group:"Boolean"},{value:"NULL",label:"Is empty (NULL)",group:"Null checks"},{value:"NOT_NULL",label:"Is not empty",group:"Null checks"}],Cu=[{value:"csv",label:"CSV",desc:"Comma-separated values"},{value:"excel",label:"Excel (.xlsx)",desc:"Native Excel format"},{value:"json",label:"JSON",desc:"Structured data with metadata"}];function Vr({children:t,active:o}){return e.jsx(r.Box,{hidden:!o,sx:{pt:2.5,pb:1,display:o?"flex":"none",flexDirection:"column",gap:2.5},children:t})}function wu({open:t,onClose:o,config:n,onApply:i}){const[a,c]=u.useState(0),[d,l]=u.useState(n),p=()=>l(n),x=()=>l(Ve),f=()=>{i(d),o()},b={sort:C=>l(v=>({...v,sort:{...v.sort,...C}})),filter:C=>l(v=>({...v,filter:{...v.filter,...C}})),columns:C=>l(v=>({...v,columns:{...v.columns,...C}})),grouping:C=>l(v=>({...v,grouping:{...v.grouping,...C}})),export:C=>l(v=>({...v,export:{...v.export,...C}}))},m=C=>{const v=d.filter.allowedOperators,k=v.includes(C)?v.filter(S=>S!==C):[...v,C];k.length!==0&&b.filter({allowedOperators:k})},g=C=>{const v=d.export.allowedFormats,k=v.includes(C)?v.filter(S=>S!==C):[...v,C];k.length!==0&&b.export({allowedFormats:k})},z=[{label:"Sort",icon:e.jsx(w.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(w.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(w.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(w.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(w.Download,{sx:{fontSize:17}})}],y=C=>JSON.stringify(d[C])===JSON.stringify(Ve[C]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:p},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.2)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:C=>D(C.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem"},children:"⚙️"}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle1",sx:{fontWeight:600,lineHeight:1.2},children:"Developer Configuration"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"Set runtime constraints · Ctrl+Shift+D"})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:a,onChange:(C,v)=>c(v),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:z.map((C,v)=>e.jsx(r.Tab,{label:C.label,icon:C.icon,iconPosition:"start"},v))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Vr,{active:a===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!y("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:d.sort.maxLevels,onChange:(C,v)=>b.sort({maxLevels:v}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(Vr,{active:a===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!y("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:d.filter.maxConditions,onChange:(C,v)=>b.filter({maxConditions:v}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(C=>e.jsxs(r.Box,{sx:{mb:1.5},children:[e.jsx(r.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:C}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:ju.filter(v=>v.group===C).map(v=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(v.value),onChange:()=>m(v.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:v.label}),sx:{mr:1.5}},v.value))})]},C))]})]}),e.jsxs(Vr,{active:a===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!y("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:d.columns.maxVisible,onChange:(C,v)=>b.columns({maxVisible:v}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:d.columns.minColumnWidth,onChange:(C,v)=>b.columns({minColumnWidth:v}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:C=>`${C}px`})]}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),e.jsx(r.Slider,{value:d.columns.maxColumnWidth,onChange:(C,v)=>b.columns({maxColumnWidth:v}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:C=>`${C}px`})]})]})]})]}),e.jsxs(Vr,{active:a===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!y("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(C=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:C}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===C?"primary.main":"divider",bgcolor:d.grouping.maxLevels===C?v=>D(v.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:v=>D(v.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:d.grouping.maxLevels===C?"primary.main":"text.secondary"},children:C}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][C-1]})]},C))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowNested,onChange:C=>b.grouping({allowNested:C.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow nested groups"})}),e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowCollapse,onChange:C=>b.grouping({allowCollapse:C.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),e.jsx(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),e.jsx(Vr,{active:a===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!y("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),e.jsx(r.FormGroup,{sx:{gap:1},children:Cu.map(C=>e.jsxs(r.Box,{onClick:()=>g(C.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:d.export.allowedFormats.includes(C.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(C.value)?v=>D(v.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(C.value),onChange:()=>g(C.value),onClick:v=>v.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:C.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:C.desc})]})]},C.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:C=>D(C.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(w.RestartAlt,{sx:{fontSize:18}}),onClick:x,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:C=>D(C.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:f,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const ku=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Tu={1:"1st",2:"2nd",3:"3rd",4:"4th",5:"5th",6:"6th",7:"7th",8:"8th",9:"9th",10:"10th",11:"11th",12:"12th",13:"13th",14:"14th",15:"15th",16:"16th",17:"17th",18:"18th",19:"19th",20:"20th",21:"21st",22:"22nd",23:"23rd",24:"24th",25:"25th",26:"26th",27:"27th",28:"28th"};function uo(t,o,n,i,a=new Date){const[c,d]=o.split(":").map(Number),l=new Date(a);if(l.setSeconds(0,0),l.setHours(c,d,0,0),t==="daily")return l<=a&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const p=n??1,x=l.getDay();let f=p-x;return f<0&&(f+=7),f===0&&l<=a&&(f=7),l.setDate(l.getDate()+f),l.toISOString()}if(t==="monthly"){const p=Math.min(i??1,28);return l.setDate(p),l<=a&&(l.setMonth(l.getMonth()+1),l.setDate(p)),l.toISOString()}return l.toISOString()}function Iu(t){const o=Gi(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${ku[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Tu[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Gi(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function zu(t){const o=new Date(t).getTime()-Date.now();if(o<=0)return"now";const n=Math.floor(o/1e3),i=Math.floor(n/86400),a=Math.floor(n%86400/3600),c=Math.floor(n%3600/60);return i>0?`in ${i}d ${a}h`:a>0?`in ${a}h ${c}m`:c>0?`in ${c}m`:"in less than a minute"}function Eu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),a=Gi(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${a}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${a}`}function qi(t){return`urm_schedules_${t}`}function Ji(t){try{const o=localStorage.getItem(qi(t));return o?JSON.parse(o).map(i=>({...i,runCount:typeof i.runCount=="number"?i.runCount:0,isActive:typeof i.isActive=="boolean"?i.isActive:!0,createdAt:i.createdAt||new Date().toISOString()})):[]}catch{return[]}}function Ki(t,o){try{localStorage.setItem(qi(t),JSON.stringify(o))}catch{}}const Bu=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"}],Du=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Xi={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Gt={"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:"8px"},"& .MuiInputLabel-root":{fontSize:"0.875rem"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:.5},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}};function Ou({initial:t=Xi,isEditing:o=!1,onSave:n,onBack:i}){const[a,c]=u.useState(t),[d,l]=u.useState(!1),[p,x]=u.useState(!1),f=(g,z)=>c(y=>({...y,[g]:z})),b=a.email.trim().length>0&&!Du.test(a.email.trim()),m=a.name.trim().length>0&&/^\d{2}:\d{2}$/.test(a.time)&&(a.frequency!=="monthly"||a.dayOfMonth>=1&&a.dayOfMonth<=28)&&!b;return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[e.jsx(r.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:g=>D(g.palette.text.primary,.06)}},children:e.jsx(w.ArrowBack,{sx:{fontSize:18}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:o?"Edit schedule":"New schedule"})]}),e.jsx(r.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:a.name,onChange:g=>{f("name",g.target.value),d&&g.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!a.name.trim(),helperText:d&&!a.name.trim()?"Schedule name is required":`${a.name.length}/50`,sx:Gt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Gt,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:a.frequency,label:"Frequency",onChange:g=>f("frequency",g.target.value),children:[e.jsx(r.MenuItem,{value:"daily",children:"Daily"}),e.jsx(r.MenuItem,{value:"weekly",children:"Weekly"}),e.jsx(r.MenuItem,{value:"monthly",children:"Monthly"})]})]}),a.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Gt,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:a.dayOfWeek,label:"Day of week",onChange:g=>f("dayOfWeek",Number(g.target.value)),children:Bu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),a.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:a.dayOfMonth,onChange:g=>f("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:a.dayOfMonth<1||a.dayOfMonth>28,helperText:a.dayOfMonth<1||a.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Gt}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:a.time,onChange:g=>f("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Gt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Gt,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:a.format,label:"Export format",onChange:g=>f("format",g.target.value),children:[e.jsx(r.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),e.jsx(r.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),e.jsx(r.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),e.jsxs(r.RadioGroup,{row:!0,value:a.scope,onChange:g=>f("scope",g.target.value),sx:{gap:2},children:[e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"All rows"})}),e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:a.email,onChange:g=>f("email",g.target.value),onBlur:()=>x(!0),placeholder:"user@company.com",error:p&&b,helperText:p&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(w.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Gt}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(w.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>D(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>m&&n(a),disabled:!m,size:"small",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Au({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:i=>{var a;return`0 8px 32px ${D(((a=i.palette.common)==null?void 0:a.black)??"#000",.14)}`}}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:i=>D(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(w.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:"Delete"})]})]})}function Mu({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:a,onDelete:c}){const d=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:d?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:d?l=>D(l.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:d?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:d?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:d?l=>D(l.palette.success.main,.1):l=>D(l.palette.text.primary,.06),color:d?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:Iu(t)}),e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5,mb:1},children:[e.jsx(r.Chip,{label:t.format.toUpperCase(),size:"small",sx:{height:20,fontSize:"0.6875rem",fontWeight:500,bgcolor:l=>D(l.palette.primary.main,.08),color:"primary.main"}}),e.jsx(r.Chip,{label:t.scope==="all"?"All rows":"Filtered rows",size:"small",sx:{height:20,fontSize:"0.6875rem",bgcolor:l=>D(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(w.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>D(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[d&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",zu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Eu(t.lastRunAt)," · ",t.runCount," run",t.runCount!==1?"s":""]}):e.jsx(r.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[e.jsx(r.Tooltip,{title:"Edit",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>a(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>D(l.palette.primary.main,.08)}},children:e.jsx(w.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:d?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:d?"warning.main":"success.main","&:hover":{bgcolor:d?l=>D(l.palette.warning.main,.08):l=>D(l.palette.success.main,.08)}},children:d?e.jsx(w.Pause,{sx:{fontSize:15}}):e.jsx(w.PlayArrow,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Export now",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>i(t),sx:{color:"primary.main","&:hover":{bgcolor:l=>D(l.palette.primary.main,.08)}},children:e.jsx(w.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>c(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>D(l.palette.error.main,.08)}},children:e.jsx(w.Delete,{sx:{fontSize:15}})})})]})]})]})}function _u({open:t,onClose:o,reportId:n,reportName:i,onRunNow:a}){const[c,d]=u.useState([]),[l,p]=u.useState({type:"list"}),[x,f]=u.useState(0),[b,m]=u.useState(null);u.useEffect(()=>{t&&(d(Ji(n)),p({type:"list"}))},[t,n]),u.useEffect(()=>{if(!t)return;const B=setInterval(()=>f($=>$+1),3e4);return()=>clearInterval(B)},[t]);const g=u.useCallback(B=>{d(B),Ki(n,B)},[n]),z=B=>{const $=uo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth),G={id:`sched-${Date.now()}`,reportId:n,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:$,runCount:0};g([...c,G]),p({type:"list"})},y=B=>{if(l.type!=="edit")return;const $=l.schedule,G=uo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth);g(c.map(Z=>Z.id===$.id?{...$,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,nextRunAt:G}:Z)),p({type:"list"})},C=B=>{g(c.map($=>{if($.id!==B)return $;const G=$.isActive?$.nextRunAt:uo($.frequency,$.time,$.dayOfWeek,$.dayOfMonth);return{...$,isActive:!$.isActive,nextRunAt:G}}))},v=B=>{a(B);const $=new Date().toISOString();g(c.map(G=>G.id===B.id?{...G,lastRunAt:$,runCount:G.runCount+1}:G))},k=B=>{const $=c.find(G=>G.id===B)??null;m($)},S=()=>{b&&(g(c.filter(B=>B.id!==b.id)),m(null))},T=B=>({name:B.name,frequency:B.frequency,dayOfWeek:B.dayOfWeek??1,dayOfMonth:B.dayOfMonth??1,time:B.time,format:B.format,scope:B.scope,email:B.email??""}),s=l.type!=="list",M=c.filter(B=>B.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:s,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:B=>D(B.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.Schedule,{sx:{fontSize:17,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"baseline",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,lineHeight:1},children:"Scheduled Reports"}),e.jsx(Xt,{content:Zt.schedule,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",sx:{lineHeight:1},children:["· ",i]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary","&:hover":{bgcolor:B=>D(B.palette.text.primary,.06)}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[s&&e.jsx(Ou,{initial:l.type==="edit"?T(l.schedule):Xi,isEditing:l.type==="edit",onSave:l.type==="edit"?y:z,onBack:()=>p({type:"list"})}),l.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:c.length===0?"No schedules yet":`${M} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(w.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",disableElevation:!0,onClick:()=>p({type:"create"}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),c.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(w.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.secondary"},children:"No scheduled reports yet"}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map(B=>e.jsx(Mu,{schedule:B,tick:x,onToggle:C,onRunNow:v,onEdit:$=>p({type:"edit",schedule:$}),onDelete:k},B.id))})]})]}),l.type==="list"&&e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.25,borderTop:"1px solid",borderColor:"divider",flexShrink:0,display:"flex",alignItems:"center",gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75,px:1.25,py:.75,borderRadius:"8px",bgcolor:B=>D(B.palette.warning.main,.06),border:"1px solid",borderColor:B=>D(B.palette.warning.main,.2)},children:[e.jsx(w.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:B=>D(B.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Au,{scheduleName:b.name,onConfirm:S,onCancel:()=>m(null)})]})}const $u=6e4;function Ru({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:x,onFired:f}){const b=u.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:x,onFired:f});u.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:c,columnVisibility:d,columnOrder:l,filters:p,sortStack:x,onFired:f}});const m=u.useCallback(g=>{var B,$;const{reportName:z,uploadedData:y,processedData:C,schema:v,activeView:k,columnVisibility:S,columnOrder:T,filters:s,sortStack:M}=b.current;try{const G=g.scope==="all"?y:C,Z=po(G,v,s,M,k,S,T),ee=`${g.name}_scheduled`;switch(g.format){case"csv":xo(Z,ee,{scope:g.scope});break;case"excel":mo(Z,ee,{scope:g.scope});break;case"json":fo(Z,ee,{scope:g.scope});break}if(g.email){const h=encodeURIComponent(`Scheduled Report: ${g.name}`),R=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
90
90
 
91
91
  Report: ${z}
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")}(R=(O=b.current).onFired)==null||R.call(O,g)}catch(U){Ht.error("urm:scheduler",`Export failed for schedule: ${g.name}`,U)}},[]);p.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:v}=b.current;if(!v)return;const j=Li(v),S=new Date;let y=!1;const T=j.map(a=>{if(!a.isActive)return a;if(new Date(a.nextRunAt)<=S){h(a);const D=io(a.frequency,a.time,a.dayOfWeek,a.dayOfMonth,S);return y=!0,{...a,lastRunAt:S.toISOString(),nextRunAt:D,runCount:a.runCount+1}}return a});y&&Vi(v,T)};g();const z=setInterval(g,Du);return()=>clearInterval(z)},[t,h])}function Ui({reportEngine:t}){var yt,dr,Pt,Nt;const{activeReport:o,paginatedData:n,processedData:i,displayData:s,tableMetrics:c,tableEngine:d,activeView:l,isDirty:u,currentTableState:m,viewChanges:f,showFilterPanel:b,setShowFilterPanel:h,filterFocusColumn:g,handleAddFilter:z,handleUpdateFilter:v,handleRemoveFilter:j,handleClearAllFilters:S,handleReplaceFilters:y,handleOpenFilterForColumn:T,handleCloseFilterPanel:a,handleClearFiltersForColumn:k,showSortPanel:D,setShowSortPanel:O,handleSort:R,handleUpdateSortStack:U,handleSortAscending:J,handleSortDescending:ee,showManageViews:x,setShowManageViews:N,showCreateViewModal:_,setShowCreateViewModal:H,showEditViewModal:q,setShowEditViewModal:de,showDeleteConfirmation:ue,setShowDeleteConfirmation:re,editingView:M,deletingView:L,handleSelectView:G,handleCreateView:oe,handleUpdateCurrentView:Q,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:ne,handleSaveAsNewView:P,handleRevertChanges:te,handleToggleDefault:ie,handleToggleFavorite:se,handleSoftDelete:je,handleRestoreView:Y,handlePermanentDelete:Oe,handleEditView:Ae,handleSaveEditView:dt,handleConfirmDelete:br,showManageColumns:kt,setShowManageColumns:Tt,handleUpdateColumnVisibility:qe,handleUpdateColumnOrder:_e,handleUpdateColumnWidth:Me,handleResetColumnLayout:zt,showGroupPanel:ut,setShowGroupPanel:pt,handleGroup:Je,handleToggleGroupCollapse:It,searchQuery:qt,searchHistory:Ke,handleSearchChange:Xe,handleAddToSearchHistory:We,handleToggleSearchFavourite:xt,handleDeleteSearchHistory:Mt,selectedRowIds:Jt,handleToggleRowSelection:mt,handleToggleAllRows:Kt,handleRangeSelection:vr,handleClearSelection:Xt,handleUpdateSelectionAfterDelete:Zt,currentPage:Qt,pageSize:er,paginationEngine:Ze,handlePageChange:Ce,handlePageSizeChange:At,isExporting:Sr,showExportModal:Qe,setShowExportModal:F,showDirtyExportWarning:et,handleExport:pe,handleExportWithConfig:Pe,handleExportSelected:Et,handleExportAnyway:jr,handleSaveAndExport:ot,handleCancelExport:tr,showAuditHistory:ft,setShowAuditHistory:$t,showCreatePreset:rr,setShowCreatePreset:Cr,showManagePresets:ke,setShowManagePresets:K,generatedPreset:nt,activePreset:ye,handleOpenManagePresets:or,handleCreatePreset:fe,handleCopyPresetLink:tt,handleOpenPreset:wr,handleClearActivePreset:it,handleOpenPresetById:Re,handleCopyPresetLinkById:nr,handleDeletePresetById:kr,isViewerRole:Rt,userRole:Tr,featureLimitWarning:ir,setFeatureLimitWarning:zr,reportError:_t,setReportError:Ue,handleError:Ne,updateReport:rt,showSnack:ht,favoriteRowIndices:Wt,resolvedFavoritesSet:Ir,showFavoritesOnly:Er,handleToggleRowFavorite:Br,handleBulkSetFavorites:Dr,handleToggleFavoritesFilter:Or}=t,[Mr,sr]=p.useState(!1);Ou({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)||((yt=l==null?void 0:l.snapshot)==null?void 0:yt.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((dr=l==null?void 0:l.snapshot)==null?void 0:dr.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:I=>{ht(`Scheduled export "${I.name}" completed`,"success")}});const ar=p.useCallback((I,V)=>{if(!(o!=null&&o.uploadedData))return;const ae=[...o.uploadedData];ae[I]=V,rt(o.id,{uploadedData:ae})},[o,rt]),Ar=p.useCallback(I=>{if(!(o!=null&&o.uploadedData))return;const V=o.uploadedData.indexOf(I);if(V===-1)return;const ae=o.uploadedData.filter((ce,Ft)=>Ft!==V),$e=(o.favoriteRowIndices||[]).filter(ce=>ce!==V).map(ce=>ce>V?ce-1:ce);rt(o.id,{uploadedData:ae,favoriteRowIndices:$e}),Zt(I)},[o,rt,Zt]),$r=p.useCallback((I,V)=>{if(!(o!=null&&o.uploadedData))return;const ae=[...o.uploadedData];ae.splice(I+1,0,{...V}),rt(o.id,{uploadedData:ae})},[o,rt]),Be=yr(),{handleDevConfigChange:gt}=mo(),[lr,cr]=p.useState(!1);return p.useEffect(()=>{const I=V=>{V.ctrlKey&&V.shiftKey&&V.key==="D"&&(V.preventDefault(),cr(!0))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]),!o||!o.schemaLocked||!o.schema||!o.uploadedData||!o.views?null:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,overflow:"hidden",position:"relative"},children:[!Rt&&u&&l&&e.jsx(Xd,{viewName:l.name,isDefaultView:l.isDefault,changes:f,onSaveToCurrentView:l.isDefault?void 0:Q,onSaveAsNewView:P,onCancel:te}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative"},children:[ir&&e.jsx(mu,{warning:ir,onDismiss:()=>zr(null)}),_t&&e.jsx(fu,{error:_t,onDismiss:()=>Ue(null)}),et&&e.jsx(Zd,{onExportAnyway:jr,onSaveAndExport:ot,onCancel:tr}),e.jsx(Nd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:u,isExporting:Sr,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:J,onSortDescending:ee,onOpenFilters:()=>h(!0),onOpenSort:()=>O(!0),onOpenFilterForColumn:T,onSelectView:G,onCreateView:()=>H(!0),onManageViews:()=>N(!0),onUpdateCurrentView:Q,onSaveAsNewView:P,onToggleDefault:ie,onToggleFavorite:se,onRestoreView:Y,onPermanentDelete:Oe,onExport:pe,onOpenColumns:()=>Tt(!0),onUpdateColumnWidth:Me,onUpdateColumnOrder:_e,onUpdateColumnVisibility:qe,onClearFiltersForColumn:k,onResetLayout:zt,onOpenGroup:()=>pt(!0),onToggleGroupCollapse:It,onOpenAuditHistory:()=>$t(!0),onOpenScheduledReports:()=>sr(!0),searchQuery:qt,searchHistory:Ke,onAddToSearchHistory:We,onToggleSearchFavourite:xt,onDeleteSearchHistory:Mt,selectedRowIds:Jt,onSearchChange:Xe,onToggleRowSelection:mt,onToggleAllRows:Kt,onRangeSelection:vr,onClearSelection:Xt,onExportSelected:Et,currentPage:(Ze==null?void 0:Ze.currentPage)||Qt,pageSize:(Ze==null?void 0:Ze.pageSize)||er,onPageChange:Ce,onPageSizeChange:At,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:Rt,userRole:Tr,reportName:o.name,onEditRow:ar,onDeleteRow:Ar,onDuplicateRow:$r,favoriteRowIndices:Wt,resolvedFavoritesSet:Ir,showFavoritesOnly:Er,onToggleRowFavorite:Br,onBulkSetFavorites:Dr,onToggleFavoritesFilter:Or,showDevPanel:Be.display.showDevPanel,onOpenDevConfig:()=>cr(!0)})]}),b&&e.jsx(Pr,{feature:"Filters",onError:I=>{const V=St("ui","filters",I);Ne(V)},children:e.jsx(Fd,{schema:o.schema,filters:o.filters??[],onAddFilter:z,onUpdateFilter:v,onRemoveFilter:j,onClearAll:S,onReplaceFilters:y,onClose:a,focusColumn:g})}),D&&e.jsx(Pr,{feature:"Sorting",onError:I=>{const V=St("ui","sorting",I);Ne(V)},children:e.jsx(Vd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:U,onClose:()=>O(!1)})}),x&&e.jsx(Pr,{feature:"Views",onError:I=>{const V=St("ui","views",I);Ne(V)},children:e.jsx(Hd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:G,onCreateView:()=>{N(!1),H(!0)},onEditView:Ae,onDeleteView:je,onRestoreView:Y,onPermanentDelete:Oe,onClose:()=>N(!1)})}),_&&m&&e.jsx(ei,{currentSnapshot:m,onSave:oe,onClose:()=>H(!1)}),q&&M&&e.jsx(ei,{currentSnapshot:M.snapshot,onSave:dt,onClose:()=>{de(!1)},isEditMode:!0,initialName:M.name,initialDescription:M.description,initialIsDefault:M.isDefault}),ue&&L&&e.jsx(Ud,{viewName:L.name,onConfirm:br,onCancel:()=>{re(!1)}}),kt&&l&&e.jsx(Gd,{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:qe,onUpdateColumnOrder:_e,onUpdateColumnWidth:Me,onResetLayout:zt,onSelectView:I=>{G(I)},onSaveToCurrentView:I=>{le(I),Tt(!1)},onSaveToAllViews:I=>{ne(I),Tt(!1)},onClose:()=>Tt(!1)}),ut&&e.jsx(Pr,{feature:"Grouping",onError:I=>{const V=St("ui","grouping",I);Ne(V)},children:e.jsx(qd,{schema:o.schema,grouping:o.grouping||null,onApply:Je,onClose:()=>pt(!1)})}),ft&&e.jsx(tu,{auditHistory:o.auditHistory||[],onClose:()=>$t(!1)}),rr&&e.jsx(ru,{onSave:fe,onClose:()=>Cr(!1)}),ke&&e.jsx(nu,{presets:o.presets||[],reportId:o.id,onOpenPreset:Re,onCopyLink:nr,onDeletePreset:kr,onClose:()=>K(!1)}),ye&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(ou,{presetName:ye.name,onClear:it})}),Qe&&e.jsx(Pr,{feature:"Export",onError:I=>{const V=St("ui","export",I);Ne(V)},children:e.jsx(xu,{totalRows:(c==null?void 0:c.totalRows)||((Pt=o.uploadedData)==null?void 0:Pt.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Nt=d==null?void 0:d.columnEngine)==null?void 0:Nt.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(c==null?void 0:c.isGrouped)||!1,onExport:Pe,onClose:()=>{F(!1)}})}),o&&e.jsx(Bu,{open:Mr,onClose:()=>sr(!1),reportId:o.id,reportName:o.name,onRunNow:I=>{const V=I.scope==="all"?o.uploadedData||[]:i||[],ae=so(V,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);I.format==="csv"&&ao(ae,I.name),I.format==="excel"&&lo(ae,I.name),I.format==="json"&&co(ae,I.name),ht(`"${I.name}" exported successfully`,"success")}}),e.jsx(bu,{open:lr,onClose:()=>cr(!1),config:Be,onApply:gt})]})}function Yi({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 Gi({hasExternalData:t=!1}){const o=mo(),{reports:n,activeReportId:i,activeReport:s,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:u,setIsModalOpen:m,setActiveReportId:f,createReport:b,handleFileUpload:h,handleUploadError:g,handleRetry:z,handleConfirm:v,snack:j,handleSnackClose:S}=o,y=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(Ka,{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:y?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(_i,{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(Ui,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&s.schema&&s.uploadedData?e.jsx(ad,{schema:s.schema,onConfirm:v,hasConflicts:l}):s.uploadError?e.jsx(ld,{error:s.uploadError,onRetry:z}):e.jsx(sd,{onFileUpload:h,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(id,{isOpen:u,onClose:()=>m(!1),onCreate:b}),e.jsx(Yi,{open:j.open,message:j.message,severity:j.severity,onClose:S})]})}function Mu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(Jo,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(Gi,{hasExternalData:!!(t||o)})})}function qi(){const t=mo(),{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(Ui,{reportEngine:t}):e.jsx(_i,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(Yi,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Au({data:t,autoLoad:o=!0,config:n}){return e.jsx(Jo,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(qi,{})})}exports.URMBuilder=Mu;exports.URMBuilderRaw=Gi;exports.URMProvider=Jo;exports.URMViewer=Au;exports.URMViewerRaw=qi;exports.useURMContext=mo;
95
+ The file has been downloaded to your device.`);window.open(`mailto:${g.email}?subject=${h}&body=${R}`,"_blank")}($=(B=b.current).onFired)==null||$.call(B,g)}catch(G){qt.error("urm:scheduler",`Export failed for schedule: ${g.name}`,G)}},[]);u.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:y}=b.current;if(!y)return;const C=Ji(y),v=new Date;let k=!1;const S=C.map(T=>{if(!T.isActive)return T;if(new Date(T.nextRunAt)<=v){m(T);const M=uo(T.frequency,T.time,T.dayOfWeek,T.dayOfMonth,v);return k=!0,{...T,lastRunAt:v.toISOString(),nextRunAt:M,runCount:T.runCount+1}}return T});k&&Ki(y,S)};g();const z=setInterval(g,$u);return()=>clearInterval(z)},[t,m])}function Zi({reportEngine:t}){var Rr,jt,cr,Ht,Ut;const{activeReport:o,paginatedData:n,processedData:i,displayData:a,tableMetrics:c,tableEngine:d,activeView:l,isDirty:p,currentTableState:x,viewChanges:f,showFilterPanel:b,setShowFilterPanel:m,filterFocusColumn:g,handleAddFilter:z,handleUpdateFilter:y,handleRemoveFilter:C,handleClearAllFilters:v,handleReplaceFilters:k,handleOpenFilterForColumn:S,handleCloseFilterPanel:T,handleClearFiltersForColumn:s,showSortPanel:M,setShowSortPanel:B,handleSort:$,handleUpdateSortStack:G,handleSortAscending:Z,handleSortDescending:ee,showManageViews:h,setShowManageViews:R,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:K,setShowEditViewModal:de,showDeleteConfirmation:ue,setShowDeleteConfirmation:te,editingView:A,deletingView:V,handleSelectView:q,handleCreateView:re,handleUpdateCurrentView:Q,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:oe,handleSaveAsNewView:N,handleRevertChanges:ne,handleToggleDefault:ce,handleToggleFavorite:se,handleSoftDelete:fe,handleRestoreView:J,handlePermanentDelete:Me,handleEditView:Ne,handleSaveEditView:et,handleConfirmDelete:Qt,handlePromoteToGlobal:gr,showManageColumns:$t,setShowManageColumns:ot,handleUpdateColumnVisibility:Le,handleUpdateColumnOrder:Ee,handleUpdateColumnWidth:mt,handleResetColumnLayout:nt,showGroupPanel:tt,setShowGroupPanel:Ge,handleGroup:ft,handleToggleGroupCollapse:er,searchQuery:qe,searchHistory:Je,handleSearchChange:$e,handleAddToSearchHistory:tr,handleToggleSearchFavourite:ht,handleDeleteSearchHistory:zt,selectedRowIds:rr,handleToggleRowSelection:it,handleToggleAllRows:yr,handleRangeSelection:br,handleClearSelection:vr,handleUpdateSelectionAfterDelete:Rt,currentPage:Sr,pageSize:jr,paginationEngine:Ke,handlePageChange:be,handlePageSizeChange:Cr,isExporting:or,showExportModal:rt,setShowExportModal:L,showDirtyExportWarning:Fe,handleExport:ve,handleExportWithConfig:Re,handleExportSelected:wr,handleExportAnyway:Wt,handleSaveAndExport:gt,handleCancelExport:Pt,showAuditHistory:Nt,setShowAuditHistory:Et,showCreatePreset:kr,setShowCreatePreset:Lt,showManagePresets:Oe,setShowManagePresets:X,generatedPreset:yt,activePreset:he,handleOpenManagePresets:Se,handleCreatePreset:Xe,handleCopyPresetLink:Tr,handleOpenPreset:bt,handleClearActivePreset:We,handleOpenPresetById:nr,handleCopyPresetLinkById:Ir,handleDeletePresetById:ir,isViewerRole:vt,userRole:zr,featureLimitWarning:Bt,setFeatureLimitWarning:Ft,reportError:St,setReportError:sr,handleError:Be,updateReport:Pe,showSnack:Vt,favoriteRowIndices:st,resolvedFavoritesSet:Er,showFavoritesOnly:Br,handleToggleRowFavorite:Dr,handleBulkSetFavorites:Or,handleToggleFavoritesFilter:Ar}=t,[Mr,ar]=u.useState(!1);Ru({reportId:o==null?void 0:o.id,reportName:(o==null?void 0:o.name)||"Report",uploadedData:(o==null?void 0:o.uploadedData)||[],processedData:i||[],schema:(o==null?void 0:o.schema)||[],activeView:l,columnVisibility:(o==null?void 0:o.columnVisibility)||((Rr=l==null?void 0:l.snapshot)==null?void 0:Rr.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((jt=l==null?void 0:l.snapshot)==null?void 0:jt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:I=>{Vt(`Scheduled export "${I.name}" completed`,"success")}});const _r=u.useCallback((I,F)=>{if(!(o!=null&&o.uploadedData))return;const ie=[...o.uploadedData];ie[I]=F,Pe(o.id,{uploadedData:ie})},[o,Pe]),lr=u.useCallback(I=>{if(!(o!=null&&o.uploadedData))return;const F=o.uploadedData.indexOf(I);if(F===-1)return;const ie=o.uploadedData.filter((ae,lt)=>lt!==F),we=(o.favoriteRowIndices||[]).filter(ae=>ae!==F).map(ae=>ae>F?ae-1:ae);Pe(o.id,{uploadedData:ie,favoriteRowIndices:we}),Rt(I)},[o,Pe,Rt]),$r=u.useCallback((I,F)=>{if(!(o!=null&&o.uploadedData))return;const ie=o.uploadedData.indexOf(F),we=ie!==-1?ie+1:I+1,ae=[...o.uploadedData];ae.splice(we,0,{...F});const Mo=(o.favoriteRowIndices??[]).map(Wr=>Wr>=we?Wr+1:Wr);Pe(o.id,{uploadedData:ae,favoriteRowIndices:Mo})},[o,Pe]),Dt=Kt(),{handleDevConfigChange:_e}=bo(),[at,Ot]=u.useState(!1);return u.useEffect(()=>{const I=F=>{F.ctrlKey&&F.shiftKey&&F.key==="D"&&(F.preventDefault(),Ot(!0))};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]),!o||!o.schemaLocked||!o.schema||!o.uploadedData||!o.views?null:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative"},children:[!vt&&p&&l&&e.jsx(tu,{viewName:l.name,isDefaultView:l.isDefault,changes:f,onSaveToCurrentView:l.isDefault?void 0:Q,onSaveAsNewView:N,onCancel:ne}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,display:"flex",flexDirection:"column",position:"relative"},children:[Bt&&e.jsx(yu,{warning:Bt,onDismiss:()=>Ft(null)}),St&&e.jsx(bu,{error:St,onDismiss:()=>sr(null)}),Fe&&e.jsx(ru,{onExportAnyway:Wt,onSaveAndExport:gt,onCancel:Pt}),e.jsx(Hd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:p,isExporting:or,columnVisibility:o.columnVisibility||(l==null?void 0:l.snapshot.columnVisibility),columnOrder:o.columnOrder||(l==null?void 0:l.snapshot.columnOrder),columnWidths:o.columnWidths||(l==null?void 0:l.snapshot.columnWidths),grouping:o.grouping,onSort:$,onSortAscending:Z,onSortDescending:ee,onOpenFilters:()=>m(!0),onOpenSort:()=>B(!0),onOpenFilterForColumn:S,onSelectView:q,onCreateView:()=>H(!0),onManageViews:()=>R(!0),onUpdateCurrentView:Q,onSaveAsNewView:N,onToggleDefault:ce,onToggleFavorite:se,onRestoreView:J,onPermanentDelete:Me,onExport:ve,onOpenColumns:()=>ot(!0),onUpdateColumnWidth:mt,onUpdateColumnOrder:Ee,onUpdateColumnVisibility:Le,onClearFiltersForColumn:s,onResetLayout:nt,onOpenGroup:()=>Ge(!0),onGroupByColumn:I=>{ft({enabled:!0,column:I,showCounts:!0})},onToggleGroupCollapse:er,onOpenAuditHistory:()=>Et(!0),onOpenScheduledReports:()=>ar(!0),searchQuery:qe,searchHistory:Je,onAddToSearchHistory:tr,onToggleSearchFavourite:ht,onDeleteSearchHistory:zt,selectedRowIds:rr,onSearchChange:$e,onToggleRowSelection:it,onToggleAllRows:yr,onRangeSelection:br,onClearSelection:vr,onExportSelected:wr,currentPage:(Ke==null?void 0:Ke.currentPage)||Sr,pageSize:(Ke==null?void 0:Ke.pageSize)||jr,onPageChange:be,onPageSizeChange:Cr,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:vt,userRole:zr,reportName:o.name,onEditRow:_r,onDeleteRow:lr,onDuplicateRow:$r,favoriteRowIndices:st,resolvedFavoritesSet:Er,showFavoritesOnly:Br,onToggleRowFavorite:Dr,onBulkSetFavorites:Or,onToggleFavoritesFilter:Ar,showDevPanel:Dt.display.showDevPanel,onOpenDevConfig:()=>Ot(!0)})]}),b&&e.jsx(Fr,{feature:"Filters",onError:I=>{const F=wt("ui","filters",I);Be(F)},children:e.jsx(Ud,{schema:o.schema,filters:o.filters??[],onAddFilter:z,onUpdateFilter:y,onRemoveFilter:C,onClearAll:v,onReplaceFilters:k,onClose:T,focusColumn:g})}),M&&e.jsx(Fr,{feature:"Sorting",onError:I=>{const F=wt("ui","sorting",I);Be(F)},children:e.jsx(Gd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:G,onClose:()=>B(!1)})}),h&&e.jsx(Fr,{feature:"Views",onError:I=>{const F=wt("ui","views",I);Be(F)},children:e.jsx(qd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:q,onCreateView:()=>{R(!1),H(!0)},onEditView:Ne,onDeleteView:fe,onRestoreView:J,onPermanentDelete:Me,onPromoteToGlobal:gr,isAdmin:((cr=Dt.views)==null?void 0:cr.isAdmin)??!1,onClose:()=>R(!1)})}),W&&x&&(()=>{var ie;const I=(o.views??[]).filter(we=>!we.isDeleted).length,F=((ie=Dt.views)==null?void 0:ie.maxViews)??10;return e.jsx(ai,{currentSnapshot:x,onSave:re,onClose:()=>H(!1),atViewLimit:I>=F,maxViews:F})})(),K&&A&&e.jsx(ai,{currentSnapshot:A.snapshot,onSave:et,onClose:()=>{de(!1)},isEditMode:!0,initialName:A.name,initialDescription:A.description,initialIsDefault:A.isDefault}),ue&&V&&e.jsx(Jd,{viewName:V.name,onConfirm:Qt,onCancel:()=>{te(!1)}}),$t&&l&&e.jsx(Xd,{schema:o.schema,columnVisibility:o.columnVisibility||l.snapshot.columnVisibility,columnOrder:o.columnOrder||l.snapshot.columnOrder,columnWidths:o.columnWidths||l.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:Le,onUpdateColumnOrder:Ee,onUpdateColumnWidth:mt,onResetLayout:nt,onSelectView:I=>{q(I)},onSaveToCurrentView:I=>{le(I),ot(!1)},onSaveToAllViews:I=>{oe(I),ot(!1)},onClose:()=>ot(!1)}),tt&&e.jsx(Fr,{feature:"Grouping",onError:I=>{const F=wt("ui","grouping",I);Be(F)},children:e.jsx(Zd,{schema:o.schema,grouping:o.grouping||null,onApply:ft,onClose:()=>Ge(!1)})}),Nt&&e.jsx(iu,{auditHistory:o.auditHistory||[],onClose:()=>Et(!1)}),kr&&e.jsx(su,{onSave:Xe,onClose:()=>Lt(!1)}),Oe&&e.jsx(lu,{presets:o.presets||[],reportId:o.id,onOpenPreset:nr,onCopyLink:Ir,onDeletePreset:ir,onClose:()=>X(!1)}),he&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(au,{presetName:he.name,onClear:We})}),rt&&e.jsx(Fr,{feature:"Export",onError:I=>{const F=wt("ui","export",I);Be(F)},children:e.jsx(gu,{totalRows:(c==null?void 0:c.totalRows)||((Ht=o.uploadedData)==null?void 0:Ht.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Ut=d==null?void 0:d.columnEngine)==null?void 0:Ut.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(c==null?void 0:c.isGrouped)||!1,schema:o.schema,allRows:o.uploadedData||[],processedRows:i||[],onExport:Re,onClose:()=>{L(!1)}})}),o&&e.jsx(_u,{open:Mr,onClose:()=>ar(!1),reportId:o.id,reportName:o.name,onRunNow:I=>{const F=I.scope==="all"?o.uploadedData||[]:i||[],ie=po(F,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);I.format==="csv"&&xo(ie,I.name),I.format==="excel"&&mo(ie,I.name),I.format==="json"&&fo(ie,I.name),Vt(`"${I.name}" exported successfully`,"success")}}),e.jsx(wu,{open:at,onClose:()=>Ot(!1),config:Dt,onApply:_e})]})}function Qi({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(a,c)=>{c!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(r.Alert,{severity:n,variant:"filled",sx:{width:"100%",boxShadow:3},children:o})})}function es({hasExternalData:t=!1}){const o=bo(),{reports:n,activeReportId:i,activeReport:a,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:p,setIsModalOpen:x,setActiveReportId:f,createReport:b,handleFileUpload:m,handleUploadError:g,handleRetry:z,handleConfirm:y,snack:C,handleSnackClose:v}=o,k=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(tl,{onCreateReport:()=>x(!0),reports:n,activeReportId:i,onReportClick:f}),e.jsx(r.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:k?e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[e.jsx(r.CircularProgress,{size:40,thickness:3}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{minWidth:260,textAlign:"center"},children:"Fetching API data — please wait..."})]}):n.length===0?e.jsx(Hi,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):a?e.jsx(e.Fragment,{children:a.schemaLocked&&a.schema&&a.uploadedData&&a.views?e.jsx(Zi,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&a.schema&&a.uploadedData?e.jsx(pd,{schema:a.schema,onConfirm:y,hasConflicts:l}):a.uploadError?e.jsx(xd,{error:a.uploadError,onRetry:z}):e.jsx(ud,{onFileUpload:m,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(dd,{isOpen:p,onClose:()=>x(!1),onCreate:b}),e.jsx(Qi,{open:C.open,message:C.message,severity:C.severity,onClose:v})]})}function Wu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:a}={}){return e.jsx(en,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:a,children:e.jsx(es,{hasExternalData:!!(t||o)})})}function ts(){const t=bo(),{snack:o,handleSnackClose:n}=t;return e.jsxs(r.Box,{sx:{minHeight:"100vh"},children:[e.jsx(r.Box,{component:"main",children:t.activeReport?e.jsx(Zi,{reportEngine:t}):e.jsx(Hi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(Qi,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Pu({data:t,autoLoad:o=!0,config:n}){return e.jsx(en,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(ts,{})})}exports.URMBuilder=Wu;exports.URMBuilderRaw=es;exports.URMProvider=en;exports.URMViewer=Pu;exports.URMViewerRaw=ts;exports.useURMContext=bo;